Page 268 - ARM 64 Bit Assembly Language
P. 268
Non-integral mathematics 257
8.4.3.2 Maintaining precision
Recall that integer division produces a result and a remainder. In order to maintain precision,
it is necessary to perform the integer division operation in such a way that all of the significant
bits are in the result and only insignificant bits are left in the remainder. The easiest way to
accomplish this is by shifting the dividend to the left before the division is performed.
To find a rule for determining the shift necessary to maintain full precision in the quotient,
consider the worst case. The minimum positive value of the dividend is N min = 2 −f 1 and the
largest positive value for the divisor is D min = 2 − 2 −f 2 . Therefore, the minimum positive
i 2
quotient is given by:
2 −f 1
Q min =
i
2 2 − 2 −f 2
1
f
2 1
= i +f
2 2 2
f
2 2
2 f 2
=
f
2 1 +i 2 +f 2
1
=
f
2 1 +i 2
= 2 −(i 2 +f 1 )
Therefore, in the worst case, the quotient will require i 2 + f 1 fractional bits to maintain preci-
sion. However, fewer bits can be reserved if full precision is not required.
Recall that the least significant bit of the quotient will be 2 −(i 2 +f 1 ) . Shifting the dividend left
by i 2 +f 2 bits will convert it into a U(i 1 ,i 2 +f 1 +f 2 ). Using the rule above, when it is divided
by a U(i 2 ,f 2 ), the result is a U(i 1 +f 2 ,i 2 +f 1 ). This is the minimum size which is guaranteed
to preserve all bits of precision. The general method for performing fixed point division while
maintaining maximum precision is as follows:
1. shift the dividend left by i 2 + f 2 then
2. perform integer division.
Theresultwill beaU(i 1 + f 2 ,i 2 + f 1 ) for unsigned division, or an S(i 1 + f 2 + 1,i 2 + f 1 ) for
signed division. The result for mixed division is left as an exercise for the student.
8.4.4 Division by a constant
Section 7.3.3 introduced the idea of converting division by a constant into multiplication by
the reciprocal of that constant. In that section it was shown that by pre-multiplying the recip-
rocal by a power of two (a shift operation), then dividing the final result by the same power of