Faster remainders when the divisor is a constant: beating compilers and libdivide
Daniel Lemire
FEBRUARY 8, 2019
Not all instructions on modern processors cost the same. Additions and subtractions are cheaper than multiplications which are themselves cheaper than divisions. For this reason, compilers frequently replace division instructions by multiplications. Roughly speaking, it works in this manner. Suppose that you want to divide a variable n by a constant d.
Let's personalize your content