reciprocal multiplication
How compilers divide by a fixed number without a divide instruction - multiply by a carefully chosen big number and keep the top bits.
For a constant divisor d, x / d is computed as the high half of x * M followed by a shift, with M about 2^(n+s) / d chosen so the result is exact for every n-bit x; signed division adds a correction for negative x.
Examples
Clang divides an unsigned 32-bit
xby 10 by multiplying by0xCCCCCCCDand shifting the 64-bit product right by 35.
See also