IT lexicon › Hardware › Lazy stacking

Lazy stacking

Hardware På svenska → Updated: 2026-11-03

The Cortex-M trick of reserving room for the floating-point registers on an interrupt but only saving them if the handler actually touches the FPU.

When Cortex-M4 gained a floating-point unit in 2010, it created a problem. The hardware stacks registers by itself on every exception, and with the FPU that adds S0–S15 plus the status register — the stack frame grows from 8 words to 26. Writing all of that every time would have eaten much of the architecture's celebrated interrupt latency, even though most handlers never go near a float.

The fix: reserve the space on the stack, but postpone the write. Only if the handler executes an FPU instruction does the processor pause and fill the reserved slot. The behaviour is controlled by the LSPEN bit in FPCCR and is on by default. The bill lands with RTOS ports, which have to check bit 4 of EXC_RETURN to learn whether a task used the FPU and whether S16–S31 must be saved on a context switch too — a classic source of bugs that only appear when two tasks crunch floats at the same time.

← Back to the lexicon