Page 265 - ARM 64 Bit Assembly Language
P. 265
254 Chapter 8
Listing 8.1 Examples of fixed point multiplication in AArch64 assembly.
1 // Multiply two S(10,5) numbers and produce an S(10,5) result.
2 smull x0,w1,w2 // x=a*b->S(21,10)
3 asr x0,x0,#5 // shift back to S(10,5)
4
5 // Multiply two U(12,4) numbers and produce a U(22,6) result.
6 umull x3,w4,w5 // x=a*b->U(24,8)
7 lsr x3,x3,#2 // shift back to U(22,6)
8
9 // Multiply two S(16,15) numbers and produce an S(16,15) result.
10 smull x0,w2,w3 // x=a*b->S(33,30)
11 asr x0,x0,#15 // shift back to S(16,15)
12
13 // Multiply two U(10,22) numbers and produce a U(10,22) result.
14 umull x0,w2,w3 // x=a*b->U(20,44)
15 lsr x0,x0,#22 // shift back to U(10,22)
Unsigned Multiplication
The result of multiplying two unsigned numbers U(i 1 ,f 1 ) and U(i 2 ,f 2 ) is a U(i 1 +
i 2 ,f 1 + f 2 ) number.
Mixed Multiplication
The result of multiplying a signed number S(i 1 ,f 1 ) and an unsigned number U(i 2 ,f 2 ) is
an S(i 1 + i 2 ,f 1 + f 2 ) number.
Signed Multiplication
The result of multiplying two signed numbers S(i 1 ,f 1 ) and S(i 2 ,f 2 ) is an S(i 1 + i 2 +
1,f 1 + f 2 ) number.
Note that this rule works for integers as well as fixed-point numbers, since integers are really
fixed point numbers with f = 0. If the programmer desires a particular format for the result,
then the multiply is followed by an appropriate shift.
Listing 8.1 gives some examples of fixed point multiplication using the ARM multiply in-
structions. In each case, the result is shifted to produce the desired format. It is the respon-
sibility of the programmer to know what type of fixed point number is produced after each
multiplication and to adjust the result by shifting if necessary.
8.4.3 Fixed point division
The rule for determining the format of the result of division is more complicated than the one
for multiplication. We will first consider only unsigned division of a dividend with format
U(i 1 ,f 1 ) by a divisor with format U(i 2 ,f 2 ).