§ 7.1. Formats and the Reference¶
Every unit of this chapter is checked against one bit-exact model, written in plain integer C++ before any gate was placed. This section states the number formats, the rules the units follow, and how the model itself is checked.
Formats¶
A binary floating-point number has a sign bit, E exponent bits and F fraction bits. Its precision is P = F + 1 bits, the hidden leading bit included.
| Format | E | F | P | Bias | Smallest normal | Largest finite | Smallest subnormal |
|---|---|---|---|---|---|---|---|
| FP16 (binary16) | 5 | 10 | 11 | 15 | 2⁻¹⁴ | 65,504 | 2⁻²⁴ |
| FP32 (binary32) | 8 | 23 | 24 | 127 | 2⁻¹²⁶ | ≈ 3.4 × 10³⁸ | 2⁻¹⁴⁹ |
| Exponent field | Fraction | Value |
|---|---|---|
| 0 | 0 | ±0 |
| 0 | not 0 | subnormal: 0.fraction × 2^(1 − bias) |
| 1 … 2^E − 2 | any | normal: 1.fraction × 2^(field − bias) |
| all ones | 0 | ±∞ |
| all ones | not 0 | NaN: quiet when the top fraction bit is 1, signalling when it is 0 |
These are the formats of Volta's GPUs. Every part of this chapter is generated from the two numbers E and F, so another format (BF16 is E8 F7) needs only a new instance and its checks, not new hardware code.
The rules¶
The units follow the F extension of RISC-V, the processor the CPU of this site runs, and IEEE 754-2019 where RISC-V says nothing more:
| Rule | What the units do |
|---|---|
| Rounding | Five modes, in RISC-V's encoding: 0 to nearest, ties to even (RNE); 1 toward zero (RTZ); 2 down, toward −∞ (RDN); 3 up, toward +∞ (RUP); 4 to nearest, ties away from zero (RMM). The reserved codes 5–7 round toward zero in a unit; the CPU rejects 5 and 6 in an instruction |
| Flags | Five sticky bits in RISC-V's fflags order: bit 0 inexact (NX), 1 underflow (UF), 2 overflow (OF), 3 divide by zero (DZ), 4 invalid (NV) |
| Underflow | Tininess is detected after rounding (as RISC-V and x86 do); the underflow flag is raised only when the tiny result is also inexact |
| NaN | Every NaN result is the canonical quiet NaN (sign 0, quiet bit 1, the rest 0); a signalling NaN operand raises invalid |
| ∞ × 0 + NaN | A fused multiply-add of ∞ × 0 raises invalid even when the addend is a quiet NaN (RISC-V; x86 does not) |
| Subnormals | Kept as inputs and outputs; there is no flush-to-zero mode |
| Min and max | RISC-V's FMIN/FMAX (IEEE minimumNumber/maximumNumber): a NaN operand gives the other operand, two NaNs the canonical NaN, −0 below +0 |
| To integer | Rounded by the mode; NaN and too-large values give the largest integer, too-negative values the smallest, with invalid only (no inexact) |
The reference¶
include/fp/FloatReference.hpp implements add, subtract, multiply, fused
multiply-add, divide, square root, the comparisons, min and max, classify,
and the conversions between the formats and to and from 32-bit integers,
for any E and F. It uses no host floating point. Every operation reduces
to one step: an exact value sign × magnitude × 2^exponent (an integer
magnitude below 2^127) rounded into the format, with its flags. A summand
far below the other is replaced by a tiny value of the same sign, which
rounds the same way; this keeps every intermediate inside 128 bits.
It also holds the model of Volta's tensor core
(7.8): voltaDotProduct, and exactDotProduct for comparison.
Checked against the host¶
FloatReferenceTest compares the reference with the x86-64 processor the
site is built on, compiled so that each host operation runs in the
rounding mode set at run time:
| Group | Host side | Cases (CTest run) |
|---|---|---|
| FP32 add, subtract, multiply, divide, square root | SSE single precision, four rounding modes | special values × special values, then random patterns biased toward cancellation, overflow and underflow |
| FP32 fused multiply-add | the FMA instruction | the same, with addends near −a × b |
| FP32 comparisons, int32 conversions | SSE compares and conversions | special and random values |
| FP16 conversions | every one of the 65,536 values to FP32 and back | exhaustive |
| FP16 arithmetic | exact in binary64/binary128, then one conversion in the rounding mode | random patterns |
| RMM | hand-made ties (no host mode rounds ties away) | 9 |
With two million random cases per group, 123,321,084 results were compared and none differed (2026-11-13). Two deliberate faults were caught: rounding every tie up instead of to even (2,023 differences at 20,000 cases), and never raising underflow (87,047). The only host differences are the two rules above where x86 and RISC-V disagree: ∞ × 0 + quiet NaN, and the host quieting a signalling FP16 NaN when it widens it.