Faster remainder by direct computation: Applications to compilers and software libraries

@article{Lemire2019FasterRB,
title={Faster remainder by direct computation: Applications to compilers and software libraries},
author={D. Lemire and Owen Kaser and N. Kurz},
journal={Software: Practice and Experience},
year={2019},
volume={49},
pages={953 - 970}
}

On common processors, integer multiplication is many times faster than integer division. Dividing a numerator n by a divisor d is mathematically equivalent to multiplication by the inverse of the divisor (n/d=n∗1/d). If the divisor is known in advance, or if repeated integer divisions will be performed with the same divisor, it can be beneficial to substitute a less costly multiplication for an expensive division. Currently, the remainder of the division by a constant is computed from the… CONTINUE READING