S38 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

S3 · Lesson 8 · Adders and the carry problem

Ripple, lookahead, prefix and carry-select adders, and overflow

Addition is the most common operation in a datapath, and its difficulty is one bit: the carry. In a ripple-carry adder the carry walks from the least significant bit to the most, one stage at a time, so a 64-bit add takes 64 gate delays. Every fast adder is a trick for computing carries in parallel. Lookahead and prefix adders compute every carry in logarithmic time with a tree of generate and propagate signals; carry-select adders compute both possible answers early and pick one. Each trades area and wiring for delay, and choosing among them is a classic piece of datapath design.

  • Worst-case delay, in gate delays, against adder width for three designs: ripple carry (one delay per bit), carry-select with equal blocks of N bits, and a parallel-prefix (Kogge–Stone) adder.
  • Ripple grows linearly, carry-select as 2N, prefix as log2⁡N plus two levels for the generate/propagate inputs and the sum XOR.
  • At 8 bits they're close; at 64 bits the prefix adder is about eight times faster than ripple.

Predict

A 64-bit ripple-carry adder takes 1.9 ns. Roughly how fast is a 64-bit parallel-prefix adder in the same gates?

Name it

Generate and propagate

For bit i, gi=aibi (this bit creates a carry) and pi=ai⊕bi (this bit passes an incoming carry along). Then ci+1=gi+pici and si=pi⊕ci. The ripple adder evaluates that recurrence one bit at a time: delay proportional to N.

Prefix adders

Group generate and propagate signals combine associatively: a block (G,P) followed by another (G′,P′) gives (G′+P′G,P′P). Any tree that computes every prefix (Gi:0,Pi:0) gives every carry at once.

AdderLevelsPrefix cells
rippleNN − 1
Kogge–Stonelog2⁡NNlog2⁡N−N+1
Brent–Kung2log2⁡N−12N−2−log2⁡N
Sklanskylog2⁡NN2log2⁡N, with high fan-out

Add about two levels for the bitwise g/p and the final sum.

Carry-select and carry-skip

A carry-select adder splits N bits into k blocks, computes each block's sum for both carry-in values, and picks with multiplexers as the real carry arrives: delay about Nk+k, smallest at k=N, giving 2N. A carry-skip adder lets a carry jump a block whose bits all propagate.

FPGAs

FPGAs have dedicated carry chains: ripple adders whose per-bit carry delay is tens of picoseconds, so a 32-bit add is fast enough without a prefix structure.

Overflow

In N-bit two's complement (range −2N−1 to 2N−1−1), an addition overflows when both operands have the same sign and the sum's sign differs, equivalently when the carry into the top bit differs from the carry out of it: V=cN−1⊕cN.

Worked example

Compare a 64-bit ripple adder and a Kogge–Stone adder at 30 ps per level, and count the Kogge–Stone and Brent–Kung prefix cells.

Show the solution
  1. Ripple. t=64×30ps=1.92ns
  2. Kogge–Stone delay. 6 prefix levels plus 2 make 8 levels: t=8×30ps=240ps
  3. Kogge–Stone cells. N=64×6−64+1=321
  4. Brent–Kung. It takes 2×6−1=11 prefix levels (13 in total, 390 ps) and N=128−2−6=120cells
  5. Which to use. In a CPU's critical path the Kogge–Stone wins; in a low-power accumulator the Brent–Kung or even ripple wins.

Answer ripple takes 1.92 ns and Kogge–Stone 240 ps with 321 prefix cells; Brent–Kung takes 390 ps with 120 cells.

Worked example

Add 4-bit two's complement numbers 0111 (7) and 0001 (1). Does it overflow?

Show the solution
  1. Add. 0111+0001=1000 which reads as −8.
  2. Check the signs. Both operands are positive but the sum's sign bit is 1, so it overflowed: the true answer 8 is outside −8 to 7.
  3. Check the carries. The carry into bit 3 is 1 and the carry out of bit 3 is 0. They differ, so V = 1.
  4. Saturating instead. Saturating arithmetic (lesson 10) would clamp the result to 0111.

Answer yes, it overflows: the sum 1000 reads as −8, and V = 1.

Worked example

A 32-bit carry-select adder costs one unit of delay per bit in a block and one per multiplexer stage. What block size is best, and how does it compare with a ripple adder at 30 ps per unit?

Show the solution
  1. Delay with k blocks. It is about t≈32k+k smallest near k=32=5.7.
  2. Whole blocks. Blocks of 8 (k=4) or 4 (k=8) both give 324+4=12units which at 30 ps is 360 ps.
  3. Against ripple. Ripple carry takes 32 units, 960 ps.
  4. The cost. About twice the adder area, since every block but the first is built twice.

Answer blocks of 4 or 8 bits, giving 12 units (360 ps) against 960 ps for ripple, at about twice the area.

Check

A 32-bit ripple-carry adder has 20 ps of carry delay per bit. What's its worst-case carry delay?

Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.

Check

How many prefix levels does a 64-bit Kogge–Stone adder have?

Check

How many prefix cells does a 32-bit Kogge–Stone adder have?

Check

How many prefix levels does a 32-bit Brent–Kung adder have?

Check

A 32-bit carry-select adder uses 4 equal blocks. In units of one bit's carry delay (and one multiplexer per block), what's its delay?

Check

What's the largest number a 12-bit two's complement register holds?

Check

A, B and S are the sign bits of two addends and their sum. Write the overflow flag.

Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.

Check

Compare prefix adders for 32 bits.

(a)

How many prefix levels does Kogge–Stone take?

(b)

How many prefix cells?

(c)

How many levels does Brent–Kung take?

(d)

And how many cells?

Check

A carry-select adder of N bits is split into k equal blocks; its delay is about N/k + k units.

Step 1

What is its delay?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

Why can a parallel-prefix adder compute all the carries in logarithmic time?

Practice

Keep practicing

10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.