Computer Arithmetic

the guard, round, and sticky bits

When the FPU shifts a significand right to line up exponents, bits fall off the bottom edge of the register. If you just let them vanish you would have already lost information before you even decide how to round — like throwing away your change before checking whether it adds up to enough to round the bill up. To round correctly you must remember a little about what was shifted out. The guard, round, and sticky bits are three extra low-order bits the hardware keeps for exactly this purpose.

They sit just below the least significant kept bit. The guard bit is the first bit shifted out, the round bit is the second, and the sticky bit is the logical OR of every bit shifted out after that — it is 1 if any discarded bit was 1, and it 'sticks' at 1 once set. Together these three summarize the discarded tail precisely enough for correct round-to-nearest-even. The decision: if guard is 0, round down (the tail is less than half a unit). If guard is 1 and either the round or sticky bit is 1, the tail is more than half, so round up. If guard is 1 but round and sticky are both 0, the discarded part is exactly half — a tie — so apply round-to-even by looking at the last kept bit. Crucially you do not need to keep the whole tail; the sticky bit compresses all of it into one 'was anything nonzero down there?' flag.

These three tiny bits are the difference between a floating-point unit that rounds exactly as IEEE-754 requires and one that is subtly, persistently wrong. A common misconception is that you can simply truncate the extra bits or keep only the guard bit; without the sticky bit the hardware cannot tell a true halfway tie from a value just over half, and would round many results the wrong way. They are a small, elegant example of keeping just enough state to make a correctness guarantee.

After aligning, the discarded tail is 1 then 0 then 0 then 1. Guard=1, round=0, sticky=OR(0,1)=1. Since guard=1 and sticky=1 the tail exceeds half, so round up. Had the tail been 1,0,0,0 then guard=1, round=0, sticky=0 — an exact tie, decided by round-to-even.

Sticky = OR of everything below the round bit, compressing the whole tail into one bit.

Truncating, or keeping only a guard bit, is not enough: without the sticky bit you cannot distinguish an exact halfway tie from a value just past half, and rounding goes wrong. The sticky bit's job is precisely to remember 'was anything nonzero shifted out?'.

Also called
GRS bitsguard/round/stickyGRS 位元