Sub topic 7
Ripple-carry versus carry-lookahead addition
Prerequisites and scope
This chapter assumes you can build a full adder from gates, read Boolean expressions in sum-of-products form, and count gate delays along a path. The full adder was covered in the chapter on half adders, full adders and subtractors. Here we ask how fast an n-bit adder is, and how to make it faster.
The ripple-carry adder
A ripple-carry adder (RCA) chains n full adders. The carry-out of stage i feeds the carry-in of stage i+1. Stage 0 receives the carry-in C0 of the whole adder.
module rca4(input [3:0] a, input [3:0] b, input cin,
output [3:0] sum, output cout);
wire [4:0] c;
assign c[0] = cin;
genvar i;
generate
for (i = 0; i < 4; i = i + 1) begin : stage
assign sum[i] = a[i] ^ b[i] ^ c[i];
assign c[i+1] = (a[i] & b[i]) | (c[i] & (a[i] ^ b[i]));
end
endgenerate
assign cout = c[4];
endmoduleThe design is small and regular, but stage i cannot produce a correct sum until its carry-in has arrived. A carry that starts at stage 0 must pass through every stage before the last sum bit is final.
Delay of a ripple-carry adder
The worst case is a carry that travels the whole chain. Let tc be the delay from carry-in to carry-out of one full adder, and ts the delay from carry-in to sum. Then:
- Delay to the final carry-out is about n × t_c.
- Delay to the last sum bit is about (n − 1) × tc + ts.
GATE questions usually simplify this by counting gate delays. In the form c[i+1] = gi + pi·c_i, each stage adds one AND and one OR, which is 2 gate delays per carry. So the carry out of an n-bit RCA arrives after about 2n gate delays once the p and g signals are ready. The delay grows linearly with n.
Generate and propagate
The carry-lookahead adder (CLA) removes the chain by computing carries directly from the inputs. It starts from two signals per bit:
- Generate: Gi = Ai · B_i. This stage creates a carry no matter what arrives.
- Propagate: Pi = Ai ⊕ B_i. This stage passes an incoming carry through.
The carry and sum for each bit become:
- C(i+1) = Gi + Pi · Ci
- Si = Pi ⊕ C_i
Some books define Pi = Ai + Bi (OR). The carry equation still holds, but the sum then needs Pi as XOR. Use XOR when you want one signal for both purposes.
Expanding the carries
Substituting each carry into the next removes the dependence on earlier carries. For a 4-bit adder:
- 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 in the G, P and C0 signals. All four can be computed in parallel.
Delay of a carry-lookahead adder
Count levels of gates, assuming gates with enough inputs (unlimited fan-in):
- P and G generation: 1 level (XOR or AND).
- Carry computation: 2 levels (AND, then OR).
- Sum: 1 level (XOR).
The total is about 4 gate delays, independent of n in the ideal model. The RCA with 2 delays per stage needs 8 gate delays for 4 bits just for the carry, so the gain grows with n.
| Property | Ripple-carry | Carry-lookahead |
|---|---|---|
| Carry delay | About 2n gate delays | Constant in the ideal model |
| Gate count | Grows linearly | Grows faster, with wider gates |
| Regularity | Very regular | Irregular lookahead logic |
| Fan-in needed | 2 or 3 | Grows with bit position |
Why the ideal model breaks down
Real gates have limited fan-in. C4 above needs a 5-input AND and a 5-input OR. For 32 bits, the last carry would need a 33-input gate. Fan-out also grows, because each P and G feeds many product terms. Practical designs therefore:
- Build lookahead for groups of 4 bits.
- Combine groups with a second lookahead level.
Group generate and propagate
For a 4-bit group, define:
- Group propagate: P* = P3·P2·P1·P0
- Group generate: G* = G3 + P3·G2 + P3·P2·G1 + P3·P2·P1·G0
Then the group's carry-out is C4 = G + P·C0. A second-level lookahead unit uses the P and G of each group to compute the carries between groups. A 16-bit adder then uses four 4-bit CLA blocks plus one lookahead unit. This delay grows roughly with the number of levels, which is logarithmic in n, rather than with n.
Worked example
Add A = 1011 and B = 0110 with C0 = 0.
- G = A·B bitwise: G3..G0 = 0, 0, 1, 0. Check: bit 0: 1·0 = 0. Bit 1: 1·1 = 1. Bit 2: 0·1 = 0. Bit 3: 1·0 = 0. So G3..G0 = 0010.
- P = A⊕B: 1101.
- 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.
- Sums: S0 = P0⊕C0 = 1. S1 = P1⊕C1 = 0. S2 = P2⊕C2 = 0. S3 = P3⊕C3 = 0.
The result is C4 S = 1 0001, which is 17. Check: 11 + 6 = 17.
A hardware CLA computes C1 to C4 in parallel from the expanded formulas. The sequential substitution above only checks the values.
Common errors
- Using P = A + B in the sum equation. The sum needs P = A ⊕ B. With OR, A=B=1 gives P=1 and a wrong sum.
- Counting the sum delay as zero. The final XOR adds one gate delay after the carries.
- Assuming CLA delay is truly constant. It is constant only with unlimited fan-in.
- Forgetting C0 in the last product term of each expansion.
- Mixing up the gate-delay model with the full-adder-delay model. Read the question for what a "unit delay" means.
Exercise
A 4-bit ripple-carry adder uses full adders where each carry stage (AND then OR) takes 2 gate delays, and the final sum XOR takes 1 more. Inputs P and G are ready at time 0. At what time is S3 final, and what is C4's time? Compare with a one-level CLA that needs 2 gate delays for any carry after P and G are ready, plus 1 for the sum.
Show answer
In the ripple chain C1 arrives at 2, C2 at 4, C3 at 6, C4 at 8. S3 = P3 xor C3 is ready at 6 + 1 = 7. In the CLA, all carries arrive at 2, so S3 is ready at 3 and C4 at 2. If P and G generation costs 1 level for both adders, add 1 to every figure.
Exercise
Write C3 for a CLA in terms of G, P and C0, and say how many product terms and what largest AND fan-in it needs.
Show answer
C3 = G2 + P2·G1 + P2·P1·G0 + P2·P1·P0·C0. It has 4 product terms. The largest AND gate has 4 inputs (P2, P1, P0, C0), and the OR gate has 4 inputs.
Exercise
Why does the carry-lookahead adder become impractical beyond a few bits if built as a single level, and what is the usual fix?
Show answer
Carry Ci needs an AND with i+1 inputs and an OR with i+1 inputs, and every P and G fans out to many terms. Real gates have limited fan-in and fan-out. The fix is to build 4-bit lookahead blocks that output group generate and propagate, and combine them with a second lookahead level.