division by invariant integers using multiplication
Integer division remains expensive on today's processors as the cost of integer multiplication declines. We present code sequences for division by arbitrary nonzero integer constants and run-time invariants using integer multiplication. The algorithms assume a two's complement architecture. Most also require that the upper half of an integer product be quickly accessible. We treat unsigned division, signed division where the quotient rounds towards zero, signed division where the quotient rounds towards -? , and division where the result is known a priori to be exact. We give some implementation results using the C compiler GCC.
invariance processor code sequence algorithm access compilation timing