Why your computer's math might change depending on its hardware

Why your computer's math might change depending on its hardware
Image: Intellect (generated)

In short: A single calculation can yield different results on two different computers. This isn't a glitch; it is the result of FMA, an instruction set that merges multiplication and addition into one step. While it improves speed and precision, it creates a fundamental rift in how software behaves across different CPUs.

The Fused Multiply-Add (FMA) instruction performs the operation d = round(±a * b ± c). Unlike standard separate instructions where the product of 'a * b' is rounded before being added to 'c', FMA keeps the intermediate result exact and only rounds once at the very end. This single rounding step typically produces a more accurate result than two sequential operations, which would involve two distinct rounding errors.

However, this precision comes with a compatibility headache known as the split between FMA3 and FMA4. These are incompatible variants of the same operation. FMA3 uses three operands (where one is overwritten), while FMA4 uses four distinct registers. This divide occurred in 2008 when Intel changed its design plans; AMD, unable to pivot without risking production schedules, kept the original four-operand specification. Consequently, an FMA3 instruction will be flagged as an invalid opcode on a processor that only supports FMA4.

For developers, this creates a reproducibility crisis. Because modern compilers like GCC and Clang often 'contract' expressions into FMA instructions by default, the same source code can produce different numerical outputs depending on whether the target CPU supports FMA or how the compiler handles it. For example, a calculation that results in zero using standard rounding might result in a non-zero value when using FMA. To ensure identical results across all systems, Intel recommends explicitly disabling FMA instructions.

The hardware implementation also hides secrets from the user. The exact intermediate value of an FMA operation exists only inside the processor and cannot be inspected by software. Furthermore, while both variants support six operations, they differ in encoding and memory access: FMA3 allows only the third operand to be in memory, whereas FMA4 allows either of the last two sources to reside in memory.

Opens the Intellect+ feed with this card first. Swipe up for the next one.

Sources

To cite this card, link to https://intellectplus.co.uk/app/science-fma-instruction-set.

How we source, check and correct cards: Editorial standards.

General information, not professional advice. Spotted an error? Flag the card or see corrections and complaints.

Intellect Plus is a visual educational discovery platform for exploring fascinating facts and ideas. Brain Food, Not Brain Rot. What is Intellect Plus?

Related

Finding something worth knowing…