Sub topic 10
Ripple-carry and carry-lookahead adders
This chapter assumes you know two's complement representation, basic gates (AND, OR, XOR), and how a full adder works. It covers how n-bit adders are built, where their delay comes from, and how carry-lookahead removes the main bottleneck. GATE questions on this topic ask for delay counts in gate delays and for carry expressions.
The full adder as a building block
A full adder adds bits a, b and a carry-in c. It produces a sum bit and a carry-out:
- sum = a XOR b XOR c
- carry-out = a·b + c·(a XOR b)
Two quantities describe each bit position independently of the carry-in:
- Generate: G = a·b. This position creates a carry by itself.
- Propagate: P = a XOR b. This position passes an incoming carry onward.
With these, carry-out = G + P·c, and sum = P XOR c. Every adder design in this chapter is built on these two signals.
Some textbooks define propagate as a OR b. The carry equation still holds with that definition, but the sum then needs the XOR separately. State which definition you are using when you answer a question.
Ripple-carry adder
A ripple-carry adder chains n full adders. The carry-out of stage i feeds the carry-in of stage i+1.
Stage i cannot finish until the carry from stage i-1 arrives. The carry therefore travels through all stages in sequence.
Delay of a ripple-carry adder
Assume each full adder takes a fixed time to turn its carry-in into a carry-out. A common GATE model counts gate delays: the carry path through one full adder is AND then OR, which is 2 gate delays.
- Carry into the last stage: about 2(n-1) gate delays after the inputs settle (plus the first stage).
- Final carry-out C_n: about 2n gate delays.
- The sum of the top bit adds one XOR after its carry arrives.
The delay grows linearly with n. A 64-bit ripple adder is about 16 times slower than a 4-bit one, which is why wide ALUs avoid it.
Carry-lookahead adder
A carry-lookahead adder (CLA) computes every carry directly from the inputs, without waiting for the previous stage. Expand the recurrence c{i+1} = Gi + Pi·ci:
- c1 = G0 + P0·c0
- c2 = G1 + P1·G0 + P1·P0·c0
- c3 = G2 + P2·G1 + P2·P1·G0 + P2·P1·P0·c0
- c4 = G3 + P3·G2 + P3·P2·G1 + P3·P2·P1·G0 + P3·P2·P1·P0·c0
Each carry is a two-level AND-OR expression of the G, P and c0 values. All carries are computed in parallel.
Delay of a carry-lookahead adder
Count gate delays with unlimited fan-in gates:
- G and P generation: 1 gate delay (an AND and an XOR).
- Carry computation: 2 gate delays (AND level, then OR level).
- Sum computation: 1 gate delay (an XOR of P and the carry).
The total is about 4 gate delays, independent of n in the ideal model.
| Property | Ripple-carry | Carry-lookahead |
|---|---|---|
| Carry computation | Sequential | Parallel |
| Delay for n bits | Proportional to n | Constant in the ideal model |
| Hardware cost | Low | Higher |
| Wiring complexity | Simple | Complex |
The fan-in limit
The ideal model fails for large n. The expression for c_n has n+1 product terms, and the largest term has n+1 inputs. Real gates have limited fan-in, often 4. You cannot build a 64-bit single-level lookahead.
Block (group) carry-lookahead
The usual fix is to build lookahead in groups, typically 4 bits per group. Each group produces two group signals:
- Group generate: G* = G3 + P3·G2 + P3·P2·G1 + P3·P2·P1·G0
- Group propagate: P* = P3·P2·P1·P0
A group carries out if it generates a carry, or if it propagates the carry-in: Cout = G + P·Cin.
The group signals feed a second-level lookahead unit. That unit computes the carries between groups in parallel. A 16-bit adder then uses four 4-bit groups and one second-level unit. A 64-bit adder uses three levels.
With group size k, the number of levels is about log_k(n). Delay grows with the logarithm of n instead of linearly.
A simpler hybrid also appears in exam questions: ripple-carry between 4-bit CLA blocks. The carry then ripples across blocks, and the delay is proportional to the number of blocks.
Worked example: computing carries
Add a = 1011 and b = 0110 with c0 = 0. Bit 0 is the least significant bit.
- a = 1011, so a0=1, a1=1, a2=0, a3=1.
- b = 0110, so b0=0, b1=1, b2=1, b3=0.
Compute G = a·b and P = a XOR b per bit:
| Bit | a | b | G | P |
|---|---|---|---|---|
| 0 | 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 |
| 2 | 0 | 1 | 0 | 1 |
| 3 | 1 | 0 | 0 | 1 |
Now the carries:
- c1 = G0 + P0·c0 = 0 + 1·0 = 0
- c2 = G1 + P1·c1 = 1 + 0 = 1
- c3 = G2 + P2·c2 = 0 + 1·1 = 1
- c4 = G3 + P3·c3 = 0 + 1·1 = 1
Sum bits are P XOR carry-in: s0 = 1⊕0 = 1, s1 = 0⊕0 = 0, s2 = 1⊕1 = 0, s3 = 1⊕1 = 0. The result is 0001 with carry-out 1. Check: 11 + 6 = 17 = 10001 in binary. Correct.
The code below computes the same result with a carry-lookahead formulation and checks it against ordinary addition.
def cla_add(a, b, n, c0=0):
"""Add two n-bit numbers using generate/propagate signals.
Returns (sum, carry_out)."""
g = [((a >> i) & 1) & ((b >> i) & 1) for i in range(n)]
p = [((a >> i) & 1) ^ ((b >> i) & 1) for i in range(n)]
c = [c0]
for i in range(n):
c.append(g[i] | (p[i] & c[i]))
s = 0
for i in range(n):
s |= (p[i] ^ c[i]) << i
return s, c[n]
for a in range(16):
for b in range(16):
s, cout = cla_add(a, b, 4)
assert s + (cout << 4) == a + b
print(cla_add(0b1011, 0b0110, 4)) # (1, 1)The loop here computes carries one after another, as software must. Hardware expands the recurrence so all carries appear at once.
Common errors
- Counting a CLA as exactly 1 gate delay for carries. Carry computation is an AND level plus an OR level, so 2 gate delays.
- Forgetting the G and P generation step and the final sum XOR when asked for total adder delay.
- Applying the ideal constant-delay result to a wide adder when the question states a fan-in limit.
- Mixing up G and P in group lookahead. G needs the OR of terms. P is a single AND.
- Treating carry-out as an overflow signal. Overflow for signed numbers is the XOR of the carry into and out of the top bit, a topic for the status flags chapter.
Exercises
Exercise
A 16-bit ripple-carry adder is built from full adders, where the carry path through each full adder takes 2 gate delays. How long does the final carry-out take to appear after the inputs and the carry-in are available?
Show answer
The carry passes through 16 stages at 2 gate delays each, so 16 × 2 = 32 gate delays.
Exercise
For a 4-bit group, write the group generate G and group propagate P in terms of the bit-level G and P signals, and write the carry out of the group.
Show answer
G = G3 + P3·G2 + P3·P2·G1 + P3·P2·P1·G0. P = P3·P2·P1·P0. The carry out is Cout = G + P·Cin.
Exercise
A 32-bit adder is built from eight 4-bit CLA blocks with the carry rippling from block to block. Each block takes 4 gate delays to produce its group carry-out from its carry-in. Compared with a pure 32-bit ripple-carry adder at 2 gate delays per stage, what is the approximate carry-out delay of each design, ignoring the initial G and P generation?
Show answer
The pure ripple design takes 32 × 2 = 64 gate delays. The blocked design takes 8 × 4 = 32 gate delays, so it is about twice as fast.