Adding in Hardware: Ripple-Carry Adders
A full adder adds one column: two bits plus the carry coming in, giving a sum bit and a carry out. Chain of them and you can add -bit numbers, but each column has to wait for the carry from the one before it, so the time grows in a straight line with .
What the symbols mean
- Bit i of A
One input bit of column i.
- Bit i of B
The other input bit.
- Carry in
The carry coming from column i − 1 (c₀ is the adder's carry-in, usually 0).
- Sum bit
Bit i of the answer.
What the symbols mean
- Carry out
1 when at least two of the three inputs are 1; it feeds column i + 1.
What the symbols mean
- Carry out of the top
The carry flag for unsigned overflow.
Explanation
An adder is simply the grade-school addition algorithm built out of logic gates. You add column by column from the right, and each column produces one digit of the answer and maybe a carry for the next column; a full adder is the little circuit that does one column for bits. The two formulas are that column's rules. (the sum bit) is 1 when an odd number of the three inputs , , are 1, which is exactly what XOR () computes. (the carry out) is 1 when at least two of them are. In these formulas, letters written side by side mean AND and means OR, as in Boolean algebra. That's the whole circuit; the interesting part is how long it takes.
One column. A column adds three bits, so its total is 0, 1, 2 or 3, and that takes two bits to write: total .
| total | |||||
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 | 1 |
| 0 | 1 | 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 2 | 1 | 0 |
| 1 | 0 | 0 | 1 | 0 | 1 |
| 1 | 0 | 1 | 2 | 1 | 0 |
| 1 | 1 | 0 | 2 | 1 | 0 |
| 1 | 1 | 1 | 3 | 1 | 1 |
Read the rules off the table. is the low bit of the total: 1 for totals 1 and 3, that is, for an odd number of 1s, which is the XOR of all three. The carry is 1 for totals 2 and 3, and there are two ways to get there: both and are 1 (the column makes a carry by itself: ), or exactly one of them is 1 and a carry came in (). OR those together and you have the carry formula. A half adder is the same thing with no carry coming in: and .
Chain them: the ripple-carry adder. To add -bit numbers, line up full adders and wire each carry out into the next column's carry in. Why does that add correctly? Each column promises . Multiply column 's promise by and add them all up:
Notice the two carry sums are almost the same list, . The left one starts with an extra and the right one ends with an extra ; everything in between cancels (the sum telescopes). What's left is
That's the sum mod plus a carry out, exactly what the overflow lesson said an adder produces. And since it's arithmetic mod , the same circuit adds signed and unsigned numbers alike.
The delay grows like . Gates aren't instant; each takes some picoseconds to settle. All full adders start working at once, but column 's outputs aren't final until its carry-in is final, and that carry waits on column , which waits on column , and so on. In the worst case, like , a carry starts at bit 0 and ripples all the way to the top. Each column adds about two gate delays to the carry's trip (an AND, then an OR), so an -bit ripple-carry adder needs about gate delays: , in big-O terms.
For 64 bits that's about 128 gate delays. At roughly 15 ps per gate that's 1.9 ns, while a 4 GHz clock ticks every 0.25 ns. An add has to finish within a cycle, so a 64-bit ripple adder would hold the clock below about 520 MHz. That's why fast processors don't ripple; the next lesson, carry-lookahead, fixes it. There's an animation further down that slows a ripple down so you can watch it.
A common mistake. It's tempting to think all the columns of an adder finish at the same time, since each column's formulas use only a couple of gates. They do all start at once, but a column's answer is only final once its carry-in is, and until then its sum wire shows a wrong value. The circuit is parallel in its gates and serial in its carries, and the clock has to wait for the longest carry chain any inputs could make.
See it
Worked examples
Add () on a 4-bit ripple-carry adder, column by column.
- 1
Start at the right with no carry coming in, . Column 0 has and .
Each full adder's carry path takes 2 gate delays, and one gate delay is 20 ps. How long does a 32-bit ripple-carry adder take in the worst case, and what's the fastest clock it allows if an add must finish within one cycle?
- 1
The worst case is a carry that starts in column 0 and ripples through all 32 columns.
Practice
Type your answer and check it. Solve them all to complete the lesson.
A full adder gets , and carry in . What are its sum bit and its carry out? Enter the sum, then the carry.
Which 8-bit addition makes a carry ripple through all 8 columns?
An 8-bit adder adds and with carry-in . Using , what are the stored sum and the carry out ? Enter both.
A 64-bit ripple-carry adder is built from gates with a 12 ps delay, and each column adds 2 gate delays to the carry path. What is the worst-case carry delay, in picoseconds?
A processor runs at 3 GHz, and the adder may use at most 60% of a clock cycle. Each column of a ripple-carry adder adds 2 gate delays of 10 ps. How many bits wide can the ripple adder be?
Why is the carry formula the same as the majority function ?
In a 16-bit ripple-carry adder, each column adds 2 gate delays to the carry path, and turning a column's carry-in into its final sum bit takes 1 more gate delay (the XOR). In the worst case, after how many gate delays is the top sum bit final?
The hardest one here. Get it, and you've got this lesson.
A designer speeds up a 64-bit adder by cutting it into equal blocks. The lowest block ripples normally ( gate delays); every other block is built twice, once assuming carry-in 0 and once assuming 1, both rippling at the same time, and as each real block carry arrives a selector picks the right copy in 2 gate delays. So the delay is . Which makes smallest, and what is that smallest delay? Enter , then .
Where it's used
Ripple-carry adders are still the right choice where speed doesn't matter and area does: tiny microcontrollers, low-power sensor chips, and the bit-serial adders inside some signal-processing hardware. Everywhere a carry chain limits the clock, from CPUs to the counters in FPGA designs, engineers count gate delays exactly like this to decide how wide a ripple chain can be.