What is Fused multiply-add?
An operation computing a × b + c in one instruction, rounding only once at the end without rounding the intermediate product. It is faster and more accurate than separate multiply and add and is heavily used in matrix computation.
Field: Computer Arithmetic
Japanese name: FMA(融合積和演算)
One rounding instead of two
Multiplying two p-bit significands produces an exact product of up to 2p bits. A separate multiply instruction rounds that product to p bits, and the following add rounds again. An FMA (fused multiply-add) unit keeps the full-width product, aligns c against it, adds, and rounds only once, so the result is the exact value of a × b + c correctly rounded. IEEE 754 standardized this operation, C provides it as the fma function, and most CPU and GPU instruction sets include it, for example fmadd.s and fmadd.d in RISC-V's F and D extensions.
Where FMA pays off
Dot products, matrix multiplication and convolution are long chains of multiply-accumulate steps, so FMA both halves the instruction count and improves accuracy. Polynomial evaluation by Horner's method has the form r = r × x + c at every step, a perfect fit. Iterative division and square-root algorithms rely on FMA to compute residuals accurately. A neat trick: if p is the rounded product of a and b, then fma(a, b, -p) gives the exact rounding error of that product, a building block for extended-precision arithmetic. Peak floating-point performance figures conventionally count each FMA as two operations.
Reproducibility pitfalls
Because FMA rounds differently, enabling it can change the last bits of results compared with separate multiply and add. Compilers may contract a * b + c into an FMA automatically, depending on language rules and flags (in GCC and Clang, -ffp-contract controls this), so the same source can give slightly different answers on different targets or optimization levels. FMA can also break expected symmetries: computing a * a - b * b as fma(a, a, -(b * b)) when a equals b returns the rounding error of b * b rather than exactly zero.
FMA vs. a multiply-accumulate in integers
Integer multiply-accumulate instructions also compute a × b + c, but integer arithmetic has no rounding, so fusing them only saves time and registers. The accuracy argument is specific to floating point. In digital signal processors and AI accelerators, wide accumulators play a similar role: products of narrow values are summed in a wider register so precision is not lost at every step, and only the final total is rounded or scaled down.
Try it: questions about Fused multiply-add
- AOnly one rounding, so it is more accurate and faster
- BThe product is always made an integer before adding, so no error occurs at all
- CThe addition is skipped and only the multiplication is done, halving the work
Show answer and explanation
Answer: A. Only one rounding, so it is more accurate and faster
Separate multiply and add instructions round a × b and then round again after adding c, two roundings in all. FMA keeps the unrounded product internally, adds c and rounds just once, so the error is smaller. Being one instruction, it is also faster, and it is used heavily in matrix products, polynomial evaluation and AI. It neither makes the product an integer nor skips the addition. Because the rounding count differs, results can differ slightly from separate operations.
FAQ
Why do my floating-point results change when FMA is enabled?
FMA rounds a × b + c once instead of twice, so its result can differ in the last bits from separate multiply and add. The FMA result is usually the more accurate one, but it is not bit-identical.
Is an FMA counted as one or two FLOPs?
Conventionally two, one multiply and one add, which is why peak throughput figures for hardware with FMA units are twice the number of FMA instructions per second.
What does the fma function do in C?
fma(x, y, z) from math.h returns x × y + z computed as if with infinite precision and rounded once to the result type. On hardware without an FMA instruction it is emulated in software and can be slow.
Books on Computer Arithmetic Ad
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.
Back to the glossary