Page 221 - ARM 64 Bit Assembly Language
P. 221
Integer mathematics 209
01100101
× 01011010
01100101
01100101
01100101
01100101
10001100011110
Then shift the result right by 11 bits. 10001100011101 2 shifted right 11 10 bits is: 100 2 = 4 10 .
If the modulus is required, it can be calculated as 101 mod 23 = 101 − (4 × 23) = 9, which
once again requires multiplication by a constant.
In the previous example the shift amount of 11 bits provided the best precision possible. But
how was that number chosen? The shift amount, n, can be directly computed as
n = p + log c − 1, (7.5)
2
where p is the desired number of bits of precision. The value of m can then be computed as
n
2 + 1 c> 0,
c
m = n (7.6)
2 otherwise.
c
For example, to divide by the constant 33, with 16 bits of precision, we compute n as
n = 16 + log 33 − 1 = 16 + 5.044394 − 1 = 16 + 5 − 1 = 20,
2
and then we compute m as
2 20
m = + 1 = 31776.030303 ≈ 31776 = 7C20 16 .
33
Therefore, multiplying a 16 bit number by 7C20 16 and then shifting right 20 bits is equivalent
to dividing by 33.
Example 17. Division by constant 193.
To divide by a constant 193, with 32 bits of precision, the multiplier is computed using
Eq. (7.5)and Eq.(7.6) with p = 32 as follows:
2 32+7−1 2 38
m = + 1 = + 1 = 1424237860.81 ≈ 1424237860 = 54E42524 16 .
193 193
The shift amount, n, is 38 bits.