TECH Signal 392
New fast modulus techniques compute day-of-the-week in a single multiplication plus two cycles
New fast modulus techniques convert a day-count to a day-of-the-week using a three-instruction sequence that outperforms existing solutions on AMD Ryzen 9 and Apple M4 Pro processors.
These optimizations matter for high-performance date libraries, database engines, and compiler authors. The techniques also generalize to other modulus operations like x % 24 and x % 60, which are applicable to timekeeping.
Written by elseif from the cluster below · every claim links back to a sourceThe three things worth knowing
The new algorithms achieve a latency of a single multiplication plus two cycles for computing the weekday.
Weekday can be computed in ISO format ([1‥7]) with the exact same instructions as Unix format ([0‥6]) by tweaking constants.
The fast modulus techniques generalize to x % (2^N - 1) and other divisors such as x % 24 and x % 60.
THE CLUSTER