Docsity

Lecture Notes on Addition - Processor Design | CS 3220, Study notes of Computer Science

Toggle sidebar
bg1
Addition Notes
Prof. Loh
CS3220 - Processor Design - Fall 2008
October 23, 2008
1 Addition
1.1 The Full Adder: 1-bit addition
In elementary school base 10 addition, we align the two numbers we want to add (the operands) and then proceed one
column at a time, carrying over digits as necessary:
carry: 1 1
x: 12345
y:+38172
z: 50517
To add binary numbers by hand, we can do the same thing:
carry: 1 1 1
x: 00101
y:+10111
z: 11100
Notice that each column itakes three inputs xi,yiand the carry from the previous column (ci), and generates two
outputs ziand the carry to the next column (ci+1). The initial carry in (c0) is zero. The full adder is a circuit that
computes ziand ci+1 given xi,yiand ci. This is the truth table for the full adder:
xiyicici+1 zi
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
The block diagram for the full adder is shown in Figure 1.
1.2 Ripple Carry Adder
The Ripple Carry Adder (RCA) is the simplest adder. It mimics the “elementary school” approach of adding numbers
by forming a straight chain of full adders, connecting the carry-out of one stage to the carry-in of the next. The block
diagram for the RCA is shown in Figure 2. The carry out of one stage is fed into the carry in of the next stage. The
initial carry in is set to zero, and the last carry out is ignored (or it can be used to detect arithmetic overflow). The gate
delay is O(n)because the carry must sequentially “ripple” through all nfull adders. For the straight layout, the area
required is O(n)and the wire delay is O(n).
1
pf3
pf4
pf5
pf8

Partial preview of the text

Download Lecture Notes on Addition - Processor Design | CS 3220 and more Study notes Computer Science in PDF only on Docsity!

Addition Notes

Prof. Loh

CS3220 - Processor Design - Fall 2008

October 23, 2008

1 Addition

1.1 The Full Adder: 1-bit addition

In elementary school base 10 addition, we align the two numbers we want to add (the operands) and then proceed one column at a time, carrying over digits as necessary:

carry: 1 1 x: 1 2 3 4 5 y: + 3 8 1 7 2 z: 5 0 5 1 7

To add binary numbers by hand, we can do the same thing:

carry: 1 1 1 x: 0 0 1 0 1 y: + 1 0 1 1 1 z: 1 1 1 0 0

Notice that each column i takes three inputs xi,yi and the carry from the previous column (ci), and generates two outputs zi and the carry to the next column (ci+1). The initial carry in (c 0 ) is zero. The full adder is a circuit that computes zi and ci+1 given xi, yi and ci. This is the truth table for the full adder:

xi yi ci ci+1 zi 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1

The block diagram for the full adder is shown in Figure 1.

1.2 Ripple Carry Adder

The Ripple Carry Adder (RCA) is the simplest adder. It mimics the “elementary school” approach of adding numbers by forming a straight chain of full adders, connecting the carry-out of one stage to the carry-in of the next. The block diagram for the RCA is shown in Figure 2. The carry out of one stage is fed into the carry in of the next stage. The initial carry in is set to zero, and the last carry out is ignored (or it can be used to detect arithmetic overflow). The gate delay is O(n) because the carry must sequentially “ripple” through all n full adders. For the straight layout, the area required is O(n) and the wire delay is O(n).

FA

x y

cout s

cin

Figure 1: The full adder block diagram.

0

FA

x 6 y 6

s 6

c 6 FA

x 5 y 5

s 5

c 5 FA

x 4 y 4

s 4

c 4 FA

x 3 y 3

s 3

c 3 FA

x 2 y 2

s 2

c 2 FA

x 1 y 1

s 1

c 1 FA

x 7 y 7

s 7

c 7 FA

x 0 y 0

s 0

c 0 c 8

Figure 2: The ripple carry adder (RCA).

1.3 Carry Skip Adder

The last bit (most significant bit) of the RCA must wait for the carry information to make its way through all previous n − 1 stages before it (the last stage) may proceed. To reduce this delay, we introduce the concept of the propagate signal. Our goal is to identify situations where the carry information can be “short cutted”. Let’s take a look at one bit’s worth of addition (not necessarily the first bit!):

x y cout 0 0 0 ← always 0, regardless of cin 0 1

← cout always equals cin 1 1 1 ← always 1, regardless of cin

In the first and last case, it doesn’t matter what the value of the incoming carry is. The middle two cases are more interesting because these are the cases where the circuit will have to generate a signal based on the carry in. Fortunately, the signal generated is simply the same as the carry in. For example, if x 4 = 0 and y 4 = 1, then c 5 = c 4. This effect can be “chained”: if x 4 = 0, x 3 = 1 and y 4 = 1, y 3 = 0, then c 5 = c 4 = c 3. In this case, if we detect that both stages 3 and 4 should simply pass on (or propagate ) the earlier carry in, then the carry logic for bits 3 and 4 can be completely circumvented. Figure 3 shows how the carry logic can be “skipped”. To compute if bit i may propagate its carry, it simply has to check for the case that only one of its inputs (x and y) is a one. This can be easily computed with an xor, and this signal is called the propagate signal (Pi). If both Pi and Pi+1 are one, then the carry in for these two blocks is passed directly on to the next stage. The delay of two levels of carry logic has been converted into a single multiplexer delay. Therefore, the overall number of gate delays has been approximately halved. The key insight here is that although we can not compute all of the carry in bits at the same time (since they are dependent on each other), we can compute in parallel whether a certain bit will end up propagating the carry bit or not. This is possible because Pi depends only on xi and yi, both of which are immediately available. The number of bits to put into a “skip block” is denoted by k. The circuit just discussed would be a carry skip adder with k = 2. Figure 4 shows a carry skip adder for n = 16 (the number of bits) and k = 4. Let us trace the worst case gate delay for the circuit. First, a carry signal may be generated by the very first block of k bits. This requires

P 15 P 14 P 13 P 12 P 11 P 10 P 9 P 8 P 7 P 6 P 5 P 4 P 3 P 2 P 1 P 0

P GK 15

Figure 5: A tree of PGK operators to compute P GK 15.

The Lookahead Carry Adder (LCA) extends the propagate signal beyond a simple propagate/don’t propagate to a three valued signal. The possible values of this new propagate signal are propagate (P), generate (G), and kill (K). The meaning of generate is that regardless of the incoming carry bit, we will “generate” a carry bit (carry out is 1). The meaning of kill is the opposite, in that the incoming carry bit is “killed” and forced to zero. To generate the Pi’s, we use the following table:

x y P 0 0 K 0 1 P 1 0 P 1 1 G

Each block of bits will generate a PGK signal. For two adjacent blocks, the circuit combines the two PGK signals to output a PGK signal for the combined block. This is computed as follows:

P GKl P GKr P GKout = P GKl ⊗ P GKr K X K P K K P P P P G G G X G

X denotes “don’t care” or any input. P GKl is the PGK signal for the left block (more significant), and P GKr is the PGK signal for the right block (less significant). The ⊗ is the associative PGK combining operator. If P GKl is K, then the combined PGK signal must also be K. This is due to the fact that when a kill signal is generated, it is independent of any earlier carries. Similarly for the case of P GKl = G. If P GKl is P, then the circuit should propagate the PGK signal from the right block. A tree of PGK operators is shown in Figure 5. If P GK 15 = K, then it means that regardless of what the carry in for the whole block of 16 bits is, the carry out will be zero. On the other hand, if P GK 15 = P , then the carry in can bypass the entire 16-bit block. The PGK tree computes the signal P GKi in dlg ie ⊗-delays. What we want is n signals, from P GK 0 all the way up to P GKn− 1. We could simply use n trees, each computing one of the P GKi’s. This is not a good solution because it unnecessarily uses up a lot of space.

P GKn− 1 P GKn− 2 P GKn− 3 P GK 2 P GK 1 P GK 0

Pn− 1 Pn− 2 Pn− 3 P 2 P 1 P 0

Figure 6: A linear chain of ⊗ operators to compute all of the P GKi signals.

Observe again that what we want to compute is:

P GK 0 = P 0 P GK 1 = P 1 ⊗ P 0 P GK 2 = P 2 ⊗ P 1 ⊗ P 0 .. . P GKn− 1 = Pn− 1 ⊗ Pn− 2 ⊗ · · · ⊗ P 1 ⊗ P 0

or

P GKj =

⊗^ j

i=

Pn

There is a very regular structure. The PGK equations can instead be written recursively as follows:

P GKi =

P 0 if i = 0 Pi ⊗ P GKi− 1 otherwise

One simple way to compute all of the P GKi’s is to directly implement this recursive formula in hardware. This is shown in Figure 6. The problem with this approach is that it takes O(n) gate delays to get P GKn− 1 , which does us no good. Let us return to the PGK-tree in Figure 5. We will use the subtree that combines P 0 through P 3 as an example. Remember that the full adder in bit position i actually wants the signal from one position earlier, i − 1. So bit position 1 wants P GK 0 , which is simply P 0. We can pass this signal directly to position 1, as illustrated in Figure 7. Position 2 wants P GK 1 , which is conveniently the output of the right subtree. Lastly, position 3 want P GK 2 , which can be computed by combining P 2 with the output of the right subtree. Let us consider the next subtree covering bit positions 4 through 7. Position 4 wants P GK 3 , which (similar to P GK 1 ) is simply the value produced by the subtree to the right. Figure 8 illustrates this. The computation for bit position 5 is similar to position 3. Bit position 6 is more interesting. We do not want to simply take P GK 4 and combine it with P 5. Such an approach will ultimately lead to a linear chain of ⊗’s. To compute P GK 5 , observe that we already have P GK 4 , 5 as well as P GK 3 = P GK 0 , 3 from the other subtrees (let P GKj,k =

⊗k i=j Pn). Also note that P GK 3 is already being passed down the tree for the subtree covering bit positions 4 and 5. The signals cross paths at the parent of the 4,5 subtree and the 6,7 subtree. At this point, we can combine P GK 0 , 3 with P GK 4 , 5 to obtain P GK 5. Once we have this signal, computing P GK 6 is the same as computing P GK 1 or P GK 3. The reason why this works is that we can compute different “sections” of the P GK signals separately and in parallel. This is due to the fact that the ⊗ operator is associative. The general node is shown in Figure 9. The node

P GKin = K

P 7 P 6 P 5 P 4 P 3 P 2 P 1 P 0

P GK 7

P GK 6 , 7 P GK 4 , 5 P GK 2 , 3 P GK 0 , 1

P GK 4 , 7 P GK^0 ,^3

c 7 c 6 c 5 c 4 c 3 c 2 c 1 c 0

C C C C C C C C

Figure 10: A parallel prefix circuit for n = 8.

contains one gate for computing the “upward” signal (the subterms of the prefix), and one gate for computing the “downward” signals (combining the subterms). Although Figure 8 is a little messy, you should be able to identify these two gates and the corresponding wires for the parent of the 4,5 subtree and the 6,7 subtree. The full tree for n = 8 is shown in Figure 10. The initial signal into the tree is K, since there is no carry in from before bit position zero. Since the PGK signals are two bit values, they must be converted back into a single bit carry at the leaves. The circuit that performs this is the box labeled C in Figure 10. Assuming an encoding of K = 00, P = 01, G = 11, then the conversion simply involves dropping the least significant bit of the PGK signal. The computation is called a “prefix” computation, because each P GKi is a prefix of the final PGK signal Pn− 1 ⊗ ... ⊗ P 1 ⊗ P 0. The circuit presented is called a parallel prefix tree because it computes all of the prefixes in parallel. The gate delay through the prefix tree is (2 lg n − 1) · τ (⊗) (the signal starting from P 0 goes through lg n − 1 gates on its way up the tree, and then at the root, it starts back down the tree, passing through lg n gates before it reaches the leftmost leaf. The only other computations are the initial computation for the Pi’s and then the final full adder. The total gate delay is thus O(lg n). This is a very big gain over our previous O(n) and O(

n) implementations. This binary-tree-based adder is called the Brent-Kung adder. The parallel prefix circuit can actually be used to compute the prefixes of any associative operator. For instance, if we have −→x = {xn− 1 , ..., x 1 , x 0 }, the prefix sums for −→x is defined as

Xi =

∑^ i

n=

xn

By replacing the ⊗ operator in Figure 10 with an addition operator, the same circuit can be used to compute the n different Xi’s. It is sometimes the case in circuit layouts that the gate delay may be reduced by using more gates in parallel, more wires, and more area. Figure 11 shows an alternative circuit to compute a parallel prefix that has only lg n (as opposed to 2 lg n − 1 ) gate delays, but uses about twice as many gates. Asymptotically, both have O(lg n) gate delays, but when designing real circuits, a few gates more or less can make a difference. The area requirements for this layout is

x 7 x 6 x 5 x 4 x 3 x 2 x 1 x 0

x 0 , 7 x 0 , 6 x 0 , 5 x 0 , 4 x 0 , 3 x 0 , 2 x 0 , 1 x 0 , 0

Figure 11: A different parallel prefix circuit with only lg n ⊗ delays in the critical path.

x 7 x 6 x 5 x 4 x 3 x 2 x 1 x 0

x 0 , 7 x 0 , 6 x 0 , 5 x 0 , 4 x 0 , 3 x 0 , 2 x 0 , 1 x 0 , 0

Figure 12: Another parallel prefix circuit with only lg n ⊗ delays in the critical path.

O(n^2 ), and the wire delay is O(n). Note that the fan-out for successive layers increases. The fan-out is the number inputs that a gate’s output must drive. For example, the last gate for x 0 , 3 must drive the inputs for four other gates. The fan-out increases with the number of total inputs (n), and although it doesn’t impact the number of gates, the additional loading can eventually slow down the speed of the overall circuit. This is circuit is called the Sklansky adder. Figure 12 shows another variant that also has lg n gate delay, but in this case the fan-out for all gates is limited to two. (The wires in the first (rightmost) few columns will need some repeaters to keep the fan-out down to two, but this does not increase the worst-case gate delay. The difference between this circuit and the previous one is that this circuit uses even more total gates. This is the Kogge-Stone adder.