The idea: eight units in a row
Adding two floats is harder than multiplying them. The binary points must line up first, and after the add the result may have lost its leading 1 or gained a new one. A hardware adder does this with a fixed chain of units. Each unit does one job, and each job is one step of the textbook algorithm. The page drives the single-precision instruction add.s $f0, $f2, $f4 through that chain and lights up the unit at work.
Pick A, the operation and B in the menus and press Compute, or run a demo. The float format and the eight-step checklist are on Number Systems: Two's Complement, Fixed Point and IEEE 754. Multiplication, with its own use of the guard, round and sticky bits, is on Floating-Point Multiplication. This page is about the hardware between those two: which unit does what, and why.
Units 1–3: check, compare, swap
Unit 1, the special-case check, looks for an exponent field of 255 (∞ or NaN) and for zeros. Those cases skip the rest of the chain (see below). For sub.s the sign bit of B is flipped first, and then the same adder runs.
Unit 2, the exponent subtractor, computes d = eA − eB. The bias cancels in a difference, so the fields are subtracted as they are. The sign of the difference says which number is bigger.
Unit 3, the swap mux, sends the bigger magnitude to the top path and the smaller one to the shifter. This saves hardware: only one shifter is needed, and a subtraction is always big − small, which is never negative. The result simply takes the sign of the bigger operand.
Unit 4: align, and keep G, R and S
The barrel shifter moves the smaller significand d places to the right in one step (how it is built from mux layers is on Arithmetic Circuits). Now both numbers have the same exponent. The bits that fall off the end are not thrown away. The datapath is 27 bits wide: the 24 bits of the significand, then the guard bit G, the round bit R, and the sticky bit S. S is the OR of every bit that fell past R. If d is 27 or more, the whole small number lands in S. Demo: 1.5 + 0.09375 is the simple case: 0.09375 = 1.12 × 2−4, so d = 127 − 123 = 4, the shift drops only zeros, and 1.1 + 0.00011 = 1.100112 = 1.59375 (3FCC0000) exactly.
Demo: 1.0 + 2−24 and Demo: 1.0 + (2−24 + 2−47) show why S matters. In both, d = 24 and the leading 1 of the small number lands in G. Without S, both would look like an exact tie and stay at 1.0. With S, the second one is G R S = 1 0 1, more than half, and it rounds up to 3F800001, which is what infinite precision would give.
Unit 5: add or subtract
The significand adder is an ordinary 27-bit integer adder with a carry out (a fast one, as on Arithmetic Circuits). If the two signs are the same it adds; if they differ, it subtracts the small row from the big row, G, R and S included. The sticky bit takes part as an ordinary bit: it stands for "a little more than nothing", which is enough to get the borrow right.
Units 6–7: carry out, or count the leading zeros
After the add, the result may not start with 1. any more. There are two cases.
- Carry out (only after an add): the sum is 2 or more. The normalize shifter shifts right once and the exponent goes up by 1. The bit that falls off is ORed into S. Demo: 1.00000036 + 1.0: 1.0…011 + 1.0…000 = 10.0…011, shifted to 1.0…01 with G R S = 1 0 0 and exponent 128. That is a tie with an odd last bit, so it rounds up to
40000002. If the exponent reaches 255 here, the sum has overflowed (Demo: 1.5·2127 + 1.5·2127 → +∞,7F800000). - Cancellation (only after a subtract): the top bits cancel and the first 1 moves down. The leading-zero counter (LZC) counts the zeros in front of it, and the normalizer shifts left by that count while the exponent goes down by the same amount.
Demo: 1.0 − 0.9999999 is the extreme case. 0.9999999 is stored as 1 − 2−23 = 0.99999988 (3F7FFFFE). With d = 1, the difference is 0.000…001: the LZC counts 23 zeros, the normalizer shifts left 23 places, and the exponent goes from 127 to 104. The result 2−23 = 1.1920929 × 10−7 (34000000) is the exact difference of the two stored numbers. Yet the decimal answer is 10−7, so the result is 19 % off. This is catastrophic cancellation: the subtraction made no error, but it threw away the 23 bits that agreed and kept the tiny error that was already in 0.9999999.
When d ≤ 1, a long left shift is possible. But then the alignment cut off at most one bit, which sits in G, and any left shift brings it back, so a cancelled result is exact. When d ≥ 2, the difference is at least 1/2, and the left shift is at most one place. Then G moves into the last kept place, and R becomes the new G. Demo: 1.0 − 1.25·2−24 shows it: after the shift G R S = 1 0 1, the difference is 0.111…1|011, the LZC is 1, and after the left shift G R S = 1 1 0. The result rounds up to 3F7FFFFF = 0.99999994. This is why there is a guard bit and a round bit.
Unit 8: round to nearest even
The rounder uses the default rule, round to nearest, ties to even. It adds 1 at the last kept bit when G = 1 and (R = 1 or S = 1 or the last kept bit is 1). Otherwise it just drops G, R and S. If the +1 carries all the way (1.11…1 + 1 = 10.00…0), the significand is shifted right once more and the exponent goes up by 1. The full G R S table, and a demo of that last carry, are on Floating-Point Multiplication: the adder and the multiplier share the same rounder.
Special cases
The special-case check sends these straight to the result:
| Inputs | Result | Why |
|---|---|---|
| ∞ − ∞, or ∞ + (−∞) | NaN 7FC00000 | no value makes sense; the invalid flag is set (Demo: ∞ − ∞ = NaN) |
| ±∞ + finite | ±∞ | infinity absorbs any finite number |
| NaN + anything | NaN | NaN spreads through every operation |
| x + 0 | x | nothing to add |
| x − x | +0 | found by the adder (all bits cancel); +0 in round to nearest |
Overflow is found later, at the normalizer or the rounder, when the exponent reaches 255. Try 1.5 − 1.5 in the menus to see x − x reach the adder and give +0.
In MIPS and in real FPUs
add.s and sub.s run this chain on coprocessor 1 registers; add.d does the same with 53-bit significands. A real FPU pipelines the chain over 3 or 4 clock cycles. Fast designs also run two paths side by side: a "close" path for a subtract with d ≤ 1 (a possibly long left shift) and a "far" path for d ≥ 2 (a long right shift, then at most one place of normalizing). Each path then has only one long shifter. Many designs also predict the leading zeros while the adder is still working, so the LZC does not add a full step.
See also Floating-Point Multiplication: IEEE 754 mul.s, Normalizing and Rounding for the other half of an FPU, and Number Systems: Two's Complement, Fixed Point and IEEE 754 for the float format and the four rounding modes.
See also Arithmetic Circuits: Fast Adders, Comparators, Shifters, Multiplier for the gates inside the significand adder and the barrel shifter, and Float Formats: FP32, FP16, BF16 and FP8 for the same fields in shorter formats.
What the page leaves out
- Denormal operands. The model handles them (exponent 1, hidden bit 0), but the menus offer none.
- The other three rounding modes, and the exception flags beyond a mention (inexact, overflow, underflow, invalid).
- NaN payloads: real chips differ in which NaN they return (x86 returns a negative quiet NaN, ARM and RISC-V return
7FC00000). - Pipelining, the close/far split and leading-zero prediction are described, not drawn.
- Double precision and the fused multiply-add, which adds a × b + c with one rounding.
On the mind map
References
Patterson and Hennessy, Computer Organization and Design: The Hardware/Software Interface (MIPS edition), Chapter 3: Arithmetic for Computers (Section 3.5, Floating Point: floating-point addition, its hardware, and accurate arithmetic with guard, round and sticky bits)
IEEE 754-2019, Standard for Floating-Point Arithmetic
David Goldberg, What Every Computer Scientist Should Know About Floating-Point Arithmetic