DSD Lectures 13 14
DSD Lectures 13 14
Lectures 13 & 14
Shift/Add Multiplication Algorithms
Shift
Multiplier x
Shift
Multiplica nd a
0 p(j+1) = (p(j) + xj a 2k) 2–1
x
0
Mux 1
k
|–––add–––| j
|––shift right––|
xj a k
Adder
cout
k
Hardware realization of the sequential multiplication algorithm
with left shifts and additions.
Shift
Multiplier x
Shift
xk -j-1 2k Multiplica nd a
0
0 1
Mux
xk -j-1a k
2k-bit adder
cout
2k
Signed Multiplication:Booth’s Recoding
Table: Radix-2 Booth’s recoding
–––––––––––––––––––––––––––––––––––––
xi xi–1 yi Explanation
–––––––––––––––––––––––––––––––––––––
0 0 0 No string of 1s in sight
0 1 1 End of string of 1s in x
1 0 -
1Beginning of string of 1s in x
1 1 0 Continuation of string of 1s in x
–––––––––––––––––––––––––––––––––––––
Example
1 0 0 1 1 1 0 1 1 0 1 0 1 1 1 0 Operand x
(1) -1 0 1 0 0 -1 1 0 -1 1 -1 1 0 0 -1 0 Recoded version y
Justification
2j + 2j–1 + . . . + 2i+1 + 2i = 2j+1 – 2i
Example Multiplication with Booth’s Recoding
Check:
• ============================ –
10 –11
• a 1 0 1 1 0 = 110
• x 1 0 1 0 1 Multiplier = 64 + 32 +
• y -
1 1 -1 1 -1 Booth-recoded 8+4+2
–––––––––– • ============================
xi–1 yi •
i p(0) 0 0 0 0 0
–––––––––– • +y0a 0 1 0 1 0
0 0 0
• –––––––––––––––––––––––––––––
0 1 1
• 2p(1) 0 0 1 0 1 0
1 0 -
1
1 1 0 • p(1) 0 0 1 0 1 0
–––––––––– • +y1a 1 0 1 1 0
• –––––––––––––––––––––––––––––
• 2p(2) 1 1 1 0 1 1 0
• p(2) 1 1 1 0 1 1 0
• +y2a 0 1 0 1 0
• –––––––––––––––––––––––––––––
• 2p(3) 0 0 0 1 1 1 1 0
• p(3) 0 0 0 1 1 1 1 0
• +y a 1 0 1 1 0
Multiplication by Constants
Software aspects:
Optimizing compilers replace multiplications by shifts/adds/subs
Produce efficient code using as few registers as possible
Find the best code by a time/space-efficient algorithm
Three methods used :
Factorization
Recoding
Binary Expansion
Multiplication Using Binary Expansion
R2 R1 shift-left 1
R3 R2 + R1
R6 R3 shift-left 1
R7 R6 + R1
R112 R7 shift-left 4
R113 R112 + R1
Shorter sequence using shift-and-add instructions
R3 R1 shift-left 1 + R1
R7 R3 shift-left 1 + R1
R113 R7 shift-left 4 + R1
Multiplication via Factorization
R8 R1 shift-left 3
R7 R8 – R1
R112 R7 shift-left 4
R119 R112 + R7
R8 R1 shift-left 3
R7 R8 – R1
R112 R7 shift-left 4
R113 R112 + R1