Page 267 - ARM 64 Bit Assembly Language
P. 267
256 Chapter 8
is N max = 2 − 2 −f 1 , and the smallest positive value for the divisor is D min = 2 −f 2 .There-
i 1
fore, the maximum quotient is given by:
i 1
2 − 2 −f 1
Q max = = 2 i 1 +f 2 − 2 f 1 −f 2 .
2 −f 2
Taking the limit of the previous equation,
lim Q max = 2 i 1 +f 2 ,
f 1 −f 2 →−∞
provides the following bound on how many bits are required in the integer part of the quo-
tient:
Q max < 2 i 1 +f 2 .
Therefore, in the worst case, the quotient will require i 1 + f 2 integer bits. For example, if we
divide a U(3,5), a = 111.11111 = 7.96875 10 ,byaU(5,3), b = 00000.001 = 0.125 10 ,weend
up with a U(6,2)q = 111111.11 = 63.75 10 .
The same thought process can be used to determine the results for signed division as well as
mixed division between signed and unsigned numbers. The results can be reduced to the fol-
lowing three rules:
Unsigned Division
The result of dividing an unsigned fixed point number U(i 1 ,f 1 ) by an unsigned number
U(i 2 ,f 2 ) is a U(i 1 + f 2 ,f 1 − f 2 ) number.
Mixed Division
The result of dividing two fixed point numbers where one of them is signed and the
other is unsigned is an S(i 1 + f 2 ,f 1 − f 2 ) number.
Signed Division
The result of dividing two signed fixed point numbers is an S(i 1 + f 2 + 1,f 1 − f 2 )
number.
Consider the results when a U(2,3), a = 00000.001 = 0.125 10 is divided by a U(4,1),
b = 1000.0 = 8.0 10 . The quotient is q = 0.000001, which requires six bits in the fractional
part. However, if we simply perform the division, then according to the rules shown above,
the result will be a U(8,−2). This indicates that the result would have to be shifted two bits to
the left to restore it to an integer, and the result is only accurate to within ±4.
When f 2 >f 1 , blindly applying the rules will sometimes result in a negative fractional part.
To avoid this, the dividend can be shifted left so that it has at least as many fractional bits as
the divisor. This leads to the following rule: If f 2 >f 1 then convert the divisor to an S(i 1 ,x),
where x ≥ f 2 , then apply the appropriate rule. For example, dividing an S(5,2) by a U(3,12)
wouldresultinanS(17,−10). But shifting the S(5,2) 16 bits to the left will result in an
S(5,18), and dividing that by a U(3,12) will result in an S(17,6).