S311 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

S3 · Lesson 11 · Floating-point units

Alignment, normalization, rounding and fused multiply-add in hardware

An integer adder is one carry chain. A floating-point adder is a small pipeline: compare the exponents, shift the smaller significand into alignment, add or subtract, find where the leading one landed, shift it back into place, and round, all while tracking the bits that fell off the end so the rounding is exactly what IEEE 754 prescribes. That's why a floating-point add takes three to five cycles where an integer add takes one, and why every one of those steps is a hardware design problem.

  • The sawtooth is the spacing between adjacent floating-point numbers divided by the number itself, in units of the machine epsilon 21−p, for a significand of p bits (24 for single, 53 for double, 11 for half).
  • It stays between half an epsilon and one epsilon at every magnitude, 2−p to 21−p: each power of two starts a new binade with the same number of values. The bits set the size of the unit (see the readout); the shape never changes.
  • That bounded relative spacing is what floating point buys; rounding to nearest makes each result's relative error at most 2−p.

Predict

A floating-point adder adds 12 = 1.5 × 2³ and 1.25 = 1.25 × 2⁰. What does the alignment step do, and what significand and exponent come out?

Name it

The adder's steps

  1. Compare and swap: subtract the exponents; the difference d is the alignment shift, and the larger operand goes on top.
  2. Align: shift the smaller significand right by d with a barrel shifter, keeping three extra bits: guard, round and sticky (the OR of every bit shifted out below the round bit).
  3. Add or subtract the significands.
  4. Normalize: an addition can carry out (shift right one); a subtraction of close values can cancel many leading bits (shift left by the leading-zero count, which a leading-zero anticipator predicts in parallel with the subtraction).
  5. Round to nearest, ties to even: round up if the bits below the kept significand exceed half an ULP, or equal half and the kept LSB is 1.

Costs

  • A barrel shifter for shifts up to S on n bits takes ⌈log2⁡(S+1)⌉ levels of n multiplexers.
  • A multiplier for p-bit significands forms p2 partial-product bits (576 for single, 2809 for double).
  • Fused multiply-add computes ab+c with one rounding instead of two: more accurate, and the core of every dot product and matrix unit.

Rounding error

With p significand bits, rounding to nearest has a relative error of at most u=2−p. A number in [2e,2e+1) has an ULP of 2e−p+1.

Worked example

In single precision, what are 1 + 2⁻²⁴ and 1 + 1.5 × 2⁻²⁴?

Show the solution
  1. Spacing near 1. Single-precision numbers near 1 are spaced 2−23 apart.
  2. The first sum. 1+2−24 sits exactly halfway between 1 and 1+2−23: guard 1, round and sticky 0, a tie. Since 1's last bit is 0, it rounds to 1.0.
  3. The second sum. 1+1.5×2−24 is past halfway (guard and round both 1), so it rounds up: 1+2−23=1.00000012

Answer 1+2−24 rounds to 1.0, and 1+1.5×2−24 rounds to 1+2−23=1.00000012.

Worked example

Subtract 1.0 from the single-precision number nearest 1.0000001. How far must the result be normalized?

Show the solution
  1. The stored number. The nearest single to 1.0000001 is 1+2−23.
  2. Subtract. (1+2−23)−1=2−23 exactly.
  3. Normalize. The subtraction cancels 23 leading bits, so the normalizer shifts left 23 places and subtracts 23 from the exponent.
  4. What the result holds. It is exact, but it carries only the one significant bit the inputs had: cancellation exposes earlier rounding.

Answer the result, 2−23, must be shifted left 23 places.

Worked example

How large is a single-precision FMA's multiplier array, and how wide is the exact product it adds to c?

Show the solution
  1. The array. Two 24-bit significands make 242=576 partial-product bits, and a 48-bit exact product.
  2. The addition. The FMA aligns c against all 48 bits before one final rounding, so its adder and shifter are about three times as wide as a plain adder's. That is part of why an FMA takes 4 or more cycles.

Answer a 576-bit partial-product array, and a 48-bit exact product.

Check

A floating-point adder adds 1.5 × 2^5 and 1.25 × 2^4.

(a)

How far is the smaller significand shifted?

(b)

What significand comes out after normalization?

(c)

And what exponent?

Check

A barrel shifter moves a 27-bit significand right by any amount from 0 to 27.

(a)

How many multiplexer levels does it need?

(b)

How many 2-to-1 multiplexers?

Check

A floating-point format has a 24-bit significand (hidden bit included).

(a)

How many partial-product bits does its multiplier form?

(b)

What is its unit roundoff?

Check

Why does IEEE 754 round ties to even rather than always up?

Check

Match each part of a floating-point adder to its job.

  1. Athe OR of every bit shifted out below the round bit
  2. Bpredicts the normalization shift while the subtraction runs
  3. Ccarry-save adder tree
  4. Daligns the smaller significand to the larger exponent
  5. Ethe first bit below the kept significand

Check

A binary floating-point format has p significand bits; x lies in [2e,2e+1).

Step 1

What is the ULP at x?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Check

Write fadd(a, b): add two positive, normal single-precision numbers given as 32-bit integer bit patterns, returning the bit pattern of the correctly rounded sum (round to nearest, ties to even). Keep guard, round and sticky bits during alignment.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why does a floating-point addition take several cycles when an integer addition of the same width takes one?

Practice

Keep practicing

6 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.