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.

The fields of A and B go through a special-case check, then an exponent subtractor that gives d and a swap mux that puts the bigger magnitude on the left; the smaller significand goes through a barrel shifter that keeps G, R and S; a significand adder adds or subtracts; a leading-zero counter and a normalize shifter fix the position while the exponent is adjusted; a rounder rounds to nearest even; then sign, exponent and fraction are packed
The adder datapath: compare, swap, align, add, count zeros, normalize, round, pack.

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.

Two additions to 1.0, both with d = 24. Adding 2 to the minus 24 puts a 1 in G with R and S zero: an exact tie, and 1.0 stays. Adding 2 to the minus 24 plus 2 to the minus 47 also puts 1 in G, but the 2 to the minus 47 bit fell past R into S, so S = 1 and the sum rounds up to 1.00000012
The two sums differ only in a bit far past the end; the sticky bit remembers it and changes the answer.

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.
1.0 minus 0.9999999, which is stored as 1 minus 2 to the minus 23: after a shift of 1 the difference is 0.000 ... 001 with 23 leading zeros; the normalizer shifts it left 23 places and the exponent drops from 127 to 104, giving 2 to the minus 23 = 1.1920929e-7
Catastrophic cancellation: 23 of 24 bits cancel, the LZC finds the one that is left, and the left shift brings it to the front.

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:

InputsResultWhy
∞ − ∞, or ∞ + (−∞)NaN 7FC00000no value makes sense; the invalid flag is set (Demo: ∞ − ∞ = NaN)
±∞ + finite±∞infinity absorbs any finite number
NaN + anythingNaNNaN spreads through every operation
x + 0xnothing to add
x − x+0found 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

This page on the Computer Architecture mind map · 76 pages in 7 branches · open it to see the whole map and test yourself in recall mode.