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 bits, and a parallel-prefix (Kogge–Stone) adder.
- Ripple grows linearly, carry-select as , prefix as 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?
About eight times: = 6 prefix levels plus about 2 more for the bit-level generate/propagate signals and the final sum, 8 gate delays against 64. The price is area and wiring: a Kogge–Stone adder has = 321 prefix cells for 64 bits, many with long wires. Brent–Kung adders use far fewer cells (120) at nearly twice the depth (11 levels).
Name it
Generate and propagate
For bit i, (this bit creates a carry) and (this bit passes an incoming carry along). Then and . 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 followed by another gives . Any tree that computes every prefix gives every carry at once.
| Adder | Levels | Prefix cells |
|---|---|---|
| ripple | N | N − 1 |
| Kogge–Stone | ||
| Brent–Kung | ||
| Sklansky | , 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 , smallest at , giving . 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 to ), 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: .
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
- Ripple.
- Kogge–Stone delay. 6 prefix levels plus 2 make 8 levels:
- Kogge–Stone cells.
- Brent–Kung. It takes prefix levels (13 in total, 390 ps) and
- 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
- Add. which reads as −8.
- 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.
- Check the carries. The carry into bit 3 is 1 and the carry out of bit 3 is 0. They differ, so V = 1.
- 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
- Delay with k blocks. It is about smallest near .
- Whole blocks. Blocks of 8 () or 4 () both give which at 30 ps is 360 ps.
- Against ripple. Ripple carry takes 32 units, 960 ps.
- 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°.
Step 2
What block count minimizes it?
Step 3
What is the minimum delay?
Explain why
Why can a parallel-prefix adder compute all the carries in logarithmic time?
Each carry depends on every bit below it, which seems to force a chain. But the rule for combining two adjacent blocks of bits, a block's generate and propagate signals followed by another's, is associative: it doesn't matter how the bits are grouped, as long as the order is kept. Associative operations can be evaluated by a tree instead of a chain: first combine pairs of bits, then pairs of pairs, doubling the span at every level. After levels every bit position knows whether a carry reaches it, and all the carries are available at once. The cost is the extra combining cells and wires the tree needs.
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.