Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder...

28
Carry Lookahead Adders 1 Carry Lookahead Adders Ivor Page 1 5.1 Simplest Carry-Lookahead System Recall the following equations from the section on Adder Circuits: g i = x i y i p i = x i y i t i = a i = x i + y i The transfer signal t i can be used in preference to p i since it is easier and quicker to generate. Although we will use the signal t i in practice, we shall use p i in the following since it makes the derivation easier to understand. 1 University of Texas at Dallas

Transcript of Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder...

Page 1: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 1

Carry Lookahead Adders

Ivor Page1

5.1 Simplest Carry-Lookahead System

Recall the following equations from the section on Adder Circuits:

gi = xiyi

pi = xi ⊕ yi

ti = ai = xi + yi

The transfer signal ti can be used in preference to pi since it is easierand quicker to generate. Although we will use the signal ti in practice,we shall use pi in the following since it makes the derivation easier tounderstand.

1University of Texas at Dallas

Page 2: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 2

The carry-lookahead system is obtained by unwinding the recurrencerelation for ci+1:

ci = gi−1 + ci−1pi−1

= gi−1 + (gi−2 + ci−2pi−2)pi−1

= gi−1 + gi−2pi−1 + ci−2pi−2pi−1

...

= gi−1 + gi−2pi−1 + gi−3pi−2pi−1 + gi−4pi−3pi−2pi−1 + ci−4pi−4pi−3pi−2pi−1

We could continue unrolling until the entire adder length is covered,i.e. until we reach cin, but the fan-in of the gates grows linearly withthe number of stages covered by them. Fan-in much greater than 4is impractical for single CMOS gates because of poor noise immunity,poor rise and fall times, and therefore poor delay.

Page 3: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 3

For most implementations, we stop at carry-lookahead blocks of size 4.Recall, in the following, ti can be used in place of pi.

c4 = g3 + g2p3 + g1p2p3 + g0p1p2p3 + c0p0p1p2p3

c3 = g2 + g1p2 + g0p1p2 + c0p0p1p2

c2 = g1 + g0p1 + c0p0p1

c1 = g0 + c0p0

Figure 1 shows a complete 4-bit CLA adder. On the right of the drawingare the logic diagrams of the two blocks that generate the p, t and sumsignals. Each lower block combines the ci signal with ti and gi to givethe sum output.

zi = xi ⊕ yi ⊕ ci = pi ⊕ ci = giti ⊕ ci

Page 4: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 4

x1 y1

z1

t1 g1

x0 y0

z0

t0 g0

x2 y2

z2

t2 g2

x3 y3

z3

t3 g3

cin

c0 = cinc1c2c3

cout = c4 CLA-4

x y x y

g g t

c t g

z

Figure 1: Four bit Carry-Lookahead Adder

Page 5: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 5

If implemented strictly as implied, the delay through the carry-lookaheadblock will be just 2D, but note that the AND gate in two of the equa-tions has a fan-in of 4, and there are OR gates with fan-ins of 2,3,4, and5. Fortunately we don’t need the carry-out signal c4. If CLA blockslarger than size 4 are needed, then the 2 levels of the CLA become 4levels or more in order to preserve the fain-in of 4. We shall need twoadditional signals, the block propagate signal P and the block gener-ate signal G. Think of these as the result of combining 4 neighboringbits of the adder into one HEX digit. Each HEX digit can generate orpropagate a carry.

G = g3 + g2p3 + g1p2p3 + g0p1p2p3

P = p3p2p1p0

These block propagate and generate signals can be combined in groupsof four by using a second level CLA-4 block. The process of addinglevels continues in this fashion. For a k bit adder there will be �log4 k�levels.

Page 6: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 6

Figure 2 shows a 32-bit adder using 3 levels of CLA blocks. Most ofthe detail has been excluded to make the carry paths more clear.

cla-4 cla-4 cla-4 cla-4cla-4 cla-4 cla-4 cla-4

cla-4cla-4

cla-2

cin

Figure 2: 32 Bit CLA adder using CLA-4 blocks

Page 7: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 7

The inputs to each CLA block in the first level are four sets of p and gsignals and a carry-in. The CLA blocks produce group propagate andgenerate signals, P and G that are passed down the tree, plus threecarry signals that are passed back up the tree. The lowest level P andG signals are not used. If a carry-out from the entire adder is needed,it can be produced by Anding the lowest level CLA’s P signal with thecarry in.

A 64-bit adder is obtained by making the lowest level CLA unit a CLA-4block and replicating the upper levels.

Page 8: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 8

The delay through the adder using CLA-m units comprises:

• time to produce the pi, gi signals, approx 2D for Nand gates

• propagation through h = logm k levels of CLAs on the way downthe tree, approximately 2hD for Nand gates

• propagation through h−1 levels of CLAs on the way up the tree,approximately 2(h − 1)D for Nand gates

• final production of sum signals, approximately 3D for Nand gates

The total delay is then approximately 5D+(4h−2)D = 5D+(4logm k−2)D. For a 64-bit adder with CLA-4 blocks the time is 15D, and fora 256-bit with CLA-4 blocks, the time is 19D. We have achieved log-time addition. Contrast the delay of the CLA adder with the worstcase delay for the ripple-carry adder, (2k + 1)D.

Page 9: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 9

Consider the circuit cost of ripple-carry and CLA adders. In the originalNAND version of the ripple-carry adder there are 2k half adders plus kinter-stage OR gates. The total number of gate inputs is 2k×8+k×2 =18k. In CMOS, each input represents 2 transistors, so the total numberof transistors is 36k. As we saw, there are full-adder circuits requiringonly 28 transistors, and some requiring only 10 transistors, but buffergates would be needed in the latter case.

For a 64 bit adder, the number of transistors would be 2,304 for the half-adder NAND version, 1,792 for the 28T version, and only 896 transistorsfor the 10T version, assuming two 2 transistor inverters are used as eachinter-stage buffer.

In a 64-bit adder using CLA-4 units, there are 21 CLA-4 blocks eachwith 45 gate inputs, making a total of 945 gate inputs. The ti and gi

signals require 7 gate inputs per stage, and the final sum circuit requiresa further 10 gate inputs, making a total of 1088 gate inputs, for a grandtotal of 4066 transistors. This is a 77% increase over the number oftransistors needed in the NAND version employing half-adders.

Page 10: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 10

The reduction in delay is from 129D to 15D, a reduction of more than8 times.

In a 256-bit adder, the full NAND version based on half-adders requires9,216 transistors, while the adder based on CLA-4 units requires 16,354transistors. Again, only a 77% increase. The delay reduces from 513Dto 19D, a reduction of 27 times.

In general, the number of CLA-m units required in a k bit adder is:

=logm k∑

i=1

k

mi

=k

m+

k

m2+ · · ·+ 1

=k

(m − 1)

(1−

(1

m

)logm k)

=(k − 1)

(m − 1)

Page 11: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 11

When using CLA-4 blocks, the total number of transistors needed isthen 90(k − 1)/3+ 34k = 64k − 30. For the NAND based circuit usinghalf-adders, the number of transisitors needed is 36k. The increaseabout 1.78 times.

5.1.1 Summary

Type Normalized Number ofDelay Transistors

Ripple-Carry (2k + 1)D 36kwith Half-AddersCLA-4 Based 5D + (4log4 k − 2)D 64k − 30

Page 12: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 12

5.2 Ling Adder

The Ling design propagates hi = ci + ci−1 instead of ci. We derive theequations for the signals in simple steps.

ci−1pi−1 = ci−1pi−1 + gi−1pi−1 + pi−1ci−1pi−1

This seems a pretty strange equation. We have the term ci−1pi−1 ap-pearing three times and the remaining term gi−1pi−1 is zero. If werewrite the RHS as A + B + AC, where B = 0, we can see that theRHS simplifies to A, so the equation is correct.

ci−1pi−1 = ci−1pi−1 + (gi−1 + pi−1ci−1)pi−1

= (ci−1 + ci)pi−1

= hipi−1

This result is needed below:

Page 13: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 13

ci = gi−1 + ci−1pi−1

= higi−1 + hipi−1

= hi(gi−1 + pi−1)

= hiti−1

In the second line above, higi−1 is substituted for gi−1. This substitutionis clearly correct for gi−1 = 0. When gi−1 = 1, hi = 1 since ci = 1. Thesecond term in that line comes from the result above.

And finally,

hi = ci + ci−1

= (gi−1 + ci−1pi−1) + ci−1

= gi−1 + ci−1

= gi−1 + hi−1ti−2

Page 14: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 14

The significance of this result is seen when this equation is unrolled:

hi = gi−1 + hi−1ti−2

= gi−1 + ti−2(gi−2 + hi−2ti−3)

= gi−1 + gi−2 + hi−2ti−2ti−3

= gi−1 + gi−2 + gi−3ti−3ti−2 + hi−3ti−4ti−3ti−2

= gi−1 + gi−2 + gi−3ti−2 + gi−4ti−3ti−2 + hi−4ti−4ti−3ti−2

The term hi requires only 14 gate inputs, as compared with to 19 forthe previous CLA-4 design’s c4 signal. Similar savings accrue for theother CLA signals.

Page 15: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 15

5.3 Parallel Prefix Computation

A parallel prefix computation can be defined with any associative op-erator. Here is an example using integers and the + operator.

Given: x0 x1 x2 · · · xk−1

Find: s0 = s1 = s2 = · · · sk−1 =x0 x0 + x1 x0 + x1 + x2 · · · x0 + x1 + · · ·+ xk−1

There are many ways to use the divide and conquer approach to com-pute these sums in parallel. The first scheme is illustrated in Fig-ure 3. Two prefix sum units each operate on 1/2 of the inputs. Thefirst unit operates on inputs x0, x1, · · · , xk/2−1 and produces the answerss0, s1, · · · , sk/2−1. The second unit is identical to the first, and operateson inputs xk/2, xk/2+1, · · · , xk−1. It produces partial sums pk/2, pk/2+1, · · · , pk−1.The sk/2−1 output from the first unit must be added to each of these par-tal sums to form the remaining sum outputs: sk/2 = pk/2+sk/2−1, sk/2+1 =pk/2+1 + sk/2−1, · · · sk−1 = pk−1 + sk/2−1.

Page 16: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 16

Prefix Sums k/2

x0xk/2-1

Prefix Sums k/2

xk/2xk-1

+ +

s0sk/2-1sk/2sk-1

Figure 3: First Scheme for Prefix Sum Calculation

The delay through the entire network is characterized by the recurrence:

D(k) = D(k/2) + 1 = log2 k

This states that repeated application of this particular divide and con-quer strategy leads to log2 k levels of adders.

Page 17: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 17

The cost of the network is similarly characterized and gives the numberof adders:

C(k) = 2C(k/2) + k/2 = (k/2)log2 k

The second divide and conquer method computes sums of pairs of in-puts, x0 +x1, x2 +x3, · · · , xk−2 + xk−1. These sums can again be addedin pairs, and so on, The results of these computations at various levelscan be added to form all the prefix sums needed. For example,

s6 = x0 + x1 + x2 + x3 + x4 + x5 + x6

= [(x0 + x1) + (x2 + x3)] + (x4 + x5) + x6

Figure 4 shows three levels of prefix sum computation (in blue rectan-gles) with the direct results shown in black and the additional addersand results shown in mauve.

Page 18: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 18

x0x1x2x3x4x5x6x7

++++

+

+

+

s0s1s3s7

+

s2

++

s4s5

+

s6

Figure 4: Second Scheme for Prefix Sum Calculation

The delay through this network is given by:

D(k) = D(k/2) + 2 = 2log2 k − 2

Page 19: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 19

The cost of the second scheme is given by the recurrence:

C(k) = C(k/2) + k − 1 = 2k − 2− log2 k

The first design is faster, log2 k levels as opposed to 2log2 k − 2 butit is also much more expensive, (k/2)log2 k adders as opposed to 2k −2− log2 k adders. The first design also has huge fan-out for the outputsk/2−1. That output must be added to k/2 partial sums from the secondprefix sum unit.

There are many variations on this theme.

Figure 5 shows the Brent Kung parallel prefix network for 16 inputs.Its delay is 2log2 k − 2 levels and its cost is 2k − 2− log2 k cells.

Page 20: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 20

x0x1x2x3x4x5x6x7x8x15

s0s1s2s15

Figure 5: Brent-Kung Parallel Prefix Network for k = 16

Page 21: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 21

Figure 6 shows the Kogge Stone parallel prefix network for 16 inputs.Its delay is log2 k levels and its cost is klog2 k − k + 1 cells. It hasoptimal speed for a parallel prefix network.

These ideas and those from other parallel prefix networks can be com-bined to form compromises between speed and cost, as discussed in thetext.

Page 22: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 22

x0x1x2x15

s15 s0s1

Figure 6: Kogge-Stone Parallel Prefix Network for k = 16

Page 23: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 23

The following table summarizes the results. L is the delay through onenetwork level and C is the cost of one adder cell.

5.3.1 Summary of Results for Prefix Sum Networks

Delay in Cost k = 32 k = 64Type levels in cells Delay Cost Delay CostScheme 1 log2 k (k/2)log2 k 5L 80C 6L 192CScheme 2 2log2 k − 2 2k − 2− log2 k 8L 57C 10L 120CBrent Kung 2log2 k − 2 2k − 2− log2 k 8L 57C 10L 120CKogge Stone log2 k klog2 k − k + 1 5L 129C 6L 321C

Kogge Stone has the clear speed advantage. Its cost is considerablyhigher than that of Brent Kung. See the comparison at the end of thismodule with the CLA-4 based adder.

Page 24: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 24

5.4 Carry Generation using a Parallel Prefix Com-

putation

We have been considering networks that compute the prefix sums of avector of integers. In the networks presented, all the cells were adders.Our task in carry generation is to compute carries as prefix computa-tions. To do so, we define a carry function, c, and replace the addercells in the prefix sum networks with units that compute this function.

Consider two contiguous regions of the input digits, say digit positions[i, j − 1] and [j, h] i < j < h. Denote P and G signals for the tworegions by g′ = g[i,j−1], p′ = p[i,j−1], and g′′ = g[j,h], p′′ = p[j,h], andgroup them as follows: (g′, p′) and (g′′, p′′). Then the P and G signalsfor the combined region are

g = g′′ + g′p′′

p = p′p′′

Page 25: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 25

Define the carry operator, c to combine the two regions:

(g, p) = (g′, p′)c(g′′, p′′)

Observe that ci+1 = g[0,i] if cin = 0. A carry-in to the adder can beconsidered a carry generated by stage -1, so we set p−1 = 0, gi−1 = cin

and compute g[−1,i] for all i.

The problem is,

given: (g0, p0) (g1, p1) · · · (gk−2, pk−2) (gk−1, pk−1)Find: (g[0,0], p[0,0]) (g[0,1], p[0,1]) · · · (g[0,k−2], p[0,k−2]) (g[0,k−1], p[0,k−1])

The desired signal pairs can be found by evaluating all the prefixes of:

(g0, p0)c(g1, p1)c · · · c(gk−2, pk−2)c(gk−1, pk−1)

Page 26: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 26

The carry operator c is associative, meaning the order of evaluationdoes not affect the result:

[(g′, p′)c(g′′, p′′)]c(g′′′, p′′′) = (g′, p′)c[(g′′, p′′)c(g′′′, p′′′)]

The operator c is not commutative, meaning, in general,

(g′, p′)c(g′′, p′′) �= (g′′, p′′)c(g′, p′)

Although we can change the order of evaluation of the carry signals,we cannot rearrange the left-to-right positioning of the inputs to the cfunctional units. All of the networks discussed for prefix sums preservethis order, and so all of them are suitable for carry generation.

Page 27: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 27

5.4.1 Summary of Results for all Adders Discussed

Using Nand gates, the time to generate the p and g signals is 2D andthe c function also has delay 2D. The final sums can be generated intime 3D. The c function requires 7 inputs. With these assumptions inmind, the following table summarizes the adder times and transistorcounts for all adders discussed. The transistor counts are presented asthe number of transistors for p, g and final sum generation, plus thethose for the carry network.

k = 32 k = 64Type Delay Transistors Delay TransistorsRipple Carry 33D 1152 129D 2304CLA-4 Based 15D 1088 + 930 15D 2176 + 1890First Prefix Scheme 10D 1088 + 1120 11D 2176 + 2688Second Prefix Scheme 13D 1088 + 798 15D 2176 + 1680Brent Kung 13D 1088 + 798 15D 2176 + 1680Kogge Stone 10D 1088 + 1806 11D 2176 + 4494

Page 28: Carry Lookahead Adders Ivor Pageivor/ce6305/m4.pdfWe could continue unrolling until the entire adder length is covered, i.e. untilwereachcin,butthefan-inofthegatesgrowslinearlywith

Carry Lookahead Adders 28

The Kogge-Stone 64 bit adder has 2.9 times the number of transistorsneeded in the ripple-carry design, but the speed advantage is a factor of11.7. In comparison, the CLA-4 based 64 bit adder requires 61% fewertransistors that the Kogge-Stone version, but is 36% slower.

The values in the table are strictly for Nand implememtations. Thedelay in calculating p, g, and final sum signals has been assumed to be5D. Note that this is a large fraction of the total delay for the fastestadders and it is very likely that clever CMOS circuit designs could sub-stantially reduce this value. A much more careful analysis would alsotake into account the fan-in and fan-out of the gates throughout thesenetworks, and would account for the lengths and types of connectionsin the VLSI layout. Such analysis is beyond the scope of this course.

In some modern applications low power consumption is also important.Very careful attention must then be paid to reducing the number oftransistors and equalizing signal paths so as to prevent unnecessarytransitions of gate outputs. We shall study these techniques in a sepa-rate module.