10-9 Unsigned Division by Divisors 1

Given a word size W 1 and a divisor d, 1 d < 2W, we wish to find the least integer m and integer p such that

Equation 22

graphics/10icon131.gif

 

with 0 m < 2W + 1 and p W.

In the unsigned case, the magic number M is given by

graphics/10icon132.gif

 

Because (22) must hold for graphics/10icon133.gif

Equation 23

graphics/10icon134.gif

 

As in the signed case, let nc be the largest value of n such that rem(nc, d) = d - 1. It can be calculated from graphics/10icon135.gifThen

Equation 24a

graphics/10icon136.gif

 

and

Equation 24b

graphics/10icon137.gif

 

These imply that nc 2W - 1.

Because (22) must hold for n = nc,

graphics/10icon138.gif

 

or

graphics/10icon139.gif

 

Combining this with (23) gives

Equation 25

graphics/10icon140.gif

 

Because m is to be the least integer satisfying (25), it is the next integer greater than or equal to 2p/d梩hat is,

Equation 26

graphics/10icon141.gif

 

Combining this with the right half of (25) and simplifying gives

Equation 27

graphics/10icon142.gif

 

The Algorithm (Unsigned)

Thus, the algorithm is to find by trial and error the least p W satisfying (27). Then m is calculated from (26). This is the smallest possible value of m satisfying (22) with p W. As in the signed case, if (27) is true for some value of p, then it is true for all larger values of p. The proof is essentially the same as that of Theorem DC1, except Theorem D5(b) is used instead of Theorem D5(a).

Proof That the Algorithm Is Feasible (Unsigned)

We must show that (27) always has a solution and that 0 m < 2W + 1.

Because for any nonnegative integer x there is a power of 2 greater than x and less than or equal to 2x + 1, from (27),

graphics/10icon143.gif

 

Because 0 rem(2p - 1, d) d - 1,

Equation 28

graphics/10icon144.gif

 

Because nc, d 2W - 1, this becomes

graphics/10icon145.gif

 

or

Equation 29

graphics/10icon146.gif

 

Thus, (27) always has a solution.

If p is not forced to equal W, then from (25) and (28),

graphics/10icon147.gif

 

If p is forced to equal W, then from (25),

graphics/10icon148.gif

 

Because 1 d 2W - 1 and nc 2W - 1,

graphics/10icon149.gif

 

Hence in either case m is within limits for the code schema illustrated by the "unsigned divide by 7" example.

Proof That the Product Is Correct (Unsigned)

We must show that if p and m are calculated from (27) and (26), then (22) is satisfied.

Equation (26) and inequality (27) are easily seen to imply (25). Inequality (25) is nearly the same as (4), and the remainder of the proof is nearly identical to that for signed division with n 0.