Professional Documents
Culture Documents
John Morris
Chung-Ang University The University of Auckland
Multipliers
Long multiplication
x x x x x x x x x
x x x x x x x
x x x x x
x x x x x x x
x x x
multiplicand In binary, the partial products multiplier are trivial if multiplier bit = 1, copy the partial multiplicand products else 0 Use an and gate! product
Multipliers
Long multiplication
a3 b3 x x
a2 b2 x x
a1 a0 b1 b0 x x x
b0 b1 b2 b3
x x x x x x x x x x x x x
In binary, the partial products are trivial if multiplier bit = 1, copy the multiplicand else 0 Use an and gate! a3 a2 a1 a0
b0
b0
FA
FA
FA
FA b1
FA
FA
FA
FA b2
FA
FA
FA
FA
p1
p0
product bits
FOR j IN 0 TO n-1 GENERATE -- For each row FOR j IN 0 TO n-1 GENERATE - Generate a row pjk : full_adder PORT MAP( ); END GENERATE; This part is straight-forward! END GENERATE;
but you need to fill in the PORT MAP using internal signals!
FA
FA
FA
FA
b1 FA
FA
FA
FA
FA
FA
FA
FA
p1
p0
product bits
Multipliers - Tree
Chris Wallace discovered a way to build fast multipliers by reducing the number of carry propagations and thus the delay All the partial product bits can be generated directly from the operand bits A full adder adds 3 input bits to produce a 2 bit result Use it to add the bits in columns Produce pairs of first level sums Combine bits in these sums vertically again
Multipliers - Tree
Summing the partial products
In the standard binary representations, one bit is used to represent each binary digit (0 or 1) of a number However, we can use other representation schemes If we use more than one bit to represent each digit of an operand, then we have a redundant system Were using more bits than the minimum log2n needed to represent a number of magnitude, n. These redundant number systems generally have the ability to avoid carry propagation
This may be exploited in the addition of sequences of numbers Carries are transferred to the following addition Concept similar to that used in carry-save multiplier where carries are transferred to the following partial product addition
Booth Recoding
A binary number can be re-coded according to Booths scheme to reduce the number of partial products in a multiplier Original idea Early computers: shift much faster than add Observe than when there is a 0 in the multiplier, you can skip the addition and just shift the multiplicand In a synchronous computer, this doesnt help in the worst case, you still have to perform an add for each digit of the multiplier (all or most of them are 1s) but in an asynchronous computer, the ability to skip some additions reduces the average completion time Booth observed that when there is a long sequence of 1s, eg digits j through (down to) k are 1s, then 2j + 2j+1 + +2k-1 + 2k = 2j+1 2k
Booth Recoding
A binary number can be re-coded according to Booths scheme to reduce the number of partial products in a multiplier Booth recoding Booth observed that when there is a long sequence of 1s, eg digits j through (down to) k are 1s, then 2j + 2j+1 + +2k-1 + 2k = 2j+1 2k Thus the sequence of additions can be replaced by
An addition of the multiplicand shifted by j+1 positions and A subtraction of the multiplicand shifted by k positions
Booth Recoding
Booths scheme Radix-2 Booth recoding
xj
0 0 1 1
xj-1
0 1 0 1
yj
0 1 -1 0
Note
No 1s End of a string of 1s - add Start of a string of 1s - subtract Middle of a string of 1s - skip
For each position, j, inspect xj and xj-1 to determine the bits (2 needed!) of yj Example x: 1 0 0 1 1 1 0 1 1 0 1 0 1 1 1 y: -1 0 1 0 0 -1 1 0 -1 1 -1 1 0 0 -1 In practice, this scheme is no use in a synchronous machine,
Worst case: sequence of alternating 0 1 More additions than necessary!
0 (0) 0
Multiplier bits
Operation
00
01 10 11
none
+A +2A (shift A) +3A (precompute A+2A?)
No carries at all?
Residue Number Systems
Residue Arithmetic
Residue Number Systems A verse by the Chinese scholar, Sun Tsu, over 1500 years ago posed this problem
What number has remainders 2, 3 and 2 when divided by the numbers 7, 5 and 3, respectively?
This is probably the first documented use of number representations using multiple residues In a residue number system, a number, x, is represented by the list of its residues (remainders) with respect to k relatively prime moduli, mk-1, mk-2, , m0 Thus x is represented by (xk-1, xk-2, , x0) where xi = x mod mi So the puzzle may be re-written What is the decimal representation of (2,3,2) in RNS(7,5,3)?
Any RNS can be viewed as a weighted representation In RNS(8,7,5,3), the weights are: 105 120 336 280 Thus (1,2,4,0) represents (105 1 + 120 2 336 4 + 280 0)840 = (1689)840 = 9
so
-21 = (8-5,0,5-1,0) = (3,0,4,0) = 510 = -110 = 410 = 410 Addition or subtraction is performed on each digit ( 5 , 5 , 0 , 2 )RNS ( 7 , 6 , 4 , 2 )RNS ( (5+7)=48, (5+6)=47, 4 , (2+2)=13)RNS ( 4 , 4 , 4 , 1 )RNS
Multiplication is also achieved by operations on each digit ( 5 , 5 , 0 , 2 )RNS = 510 ( 7 , 6 , 4 , 2 )RNS = -110 ( (5x7)=38, (5x6)=27, 0 , (2x2)=13)RNS = -510 ( 3 , 2 , 0 , 1 )RNS = -510
Include powers of smaller primes before primes, starting with RNS(3,2), M = 6 Note that 22 is smaller than the next prime, 5, so move to RNS(22,3), M = 12 (trying to minimize the size of the largest modulus) After including 5 and 7, note that 23 and 32 are smaller than 11: RNS(32,23,7,5), M = 2,520 Add 11 RNS(11,32,23,7,5), M = 27,720 Add 13 RNS(13,11,32,23,7,5), M = 360,360
You can actually do somewhat better than this! Reference: B. Parhami, Computer Arithmetic: Algorithms and Hardware Designs, Oxford University Press, 2000
j
0 1 2
2j
1 2 4
2 j 7
1 2 4
2 j 5
1 2 4
2 j 3
1 2 1
3
4 5 6
8
16 32 64
1
2 4 1
3
1 2 4
2
1 2 1
7
8 9
128
256 512
2
4 1
3
1 2
2
1 2
j
0 1 2
2j
1 2 4
2 j 7
1 2 4
2 j 5
1 2 4
2 j 3
1 2 1
3
4 5 6
8
16 32 64
1
2 4 1
3
1 2 4
2
1 2 1 Note that the additions are done in a modular adder! Worst case:
7
8 9
128
256 512
2
4 1
3
1 2
2
1 2
Sk-1i=0 mi
words a reasonable number!