July 2002
Intermediate to advanced
320 pages
8h 15m
English
Unsigned division by a power of 2 is of course implemented by a single shift right logical instruction, and remainder by and immediate.
It might seem that handling other divisors will be simple: Just use the results for signed division with d > 0, omitting the two instructions that add 1 if the quotient is negative. We will see, however, that some of the details are actually more complicated in the case of unsigned division.
For a non-power of 2, let us first consider unsigned division by 3 on a 32-bit machine. Because the dividend n can now be as large as 232 − 1, the multiplier (232 + 2)/3 is inadequate, because the error term 2n/3 · 232 (see “divide by 3” example above) can exceed 1/3. However, ...
Read now
Unlock full access