# 融合乘加

融合乘加（FMA）是一种浮点运算，它计算 \( a \times b + c \) 时如同具有无界范围与精度，只对目标格式舍入一次。它与先乘后加不同——后者在加上加数之前先对乘积舍入，因此分开的乘法和加法会产生两次舍入步骤，而FMA只产生一次。<sup>[1](https://dms-discourse-static.s3.dualstack.us-east-1.amazonaws.com/original/3X/b/7/b7b9c1edaf4019395d2b8315620948e240bf3f8f.pdf)</sup> 该运算在IEEE 754浮点运算标准中定义，该标准在2008年修订版中将其加入，并在2019年修订版中作为fusedMultiplyAdd保留。<sup>[2](https://docs.nvidia.com/cuda/archive/12.4.1/pdf/Floating_Point_on_NVIDIA_GPU.pdf)</sup><sup> • </sup><sup>[1](https://dms-discourse-static.s3.dualstack.us-east-1.amazonaws.com/original/3X/b/7/b7b9c1edaf4019395d2b8315620948e240bf3f8f.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | fusedMultiplyAdd(x, y, z) 计算 \( (x \times y) + z \)，如同具有无界范围与精度，只舍入一次；下溢、上溢或不精确只能由那一次舍入产生<sup>[1](https://dms-discourse-static.s3.dualstack.us-east-1.amazonaws.com/original/3X/b/7/b7b9c1edaf4019395d2b8315620948e240bf3f8f.pdf)</sup> |
| 标准化 | 2008年修订版加入IEEE 754；2019年修订版将其作为必需的通用计算运算保留<sup>[2](https://docs.nvidia.com/cuda/archive/12.4.1/pdf/Floating_Point_on_NVIDIA_GPU.pdf)</sup><sup> • </sup><sup>[1](https://dms-discourse-static.s3.dualstack.us-east-1.amazonaws.com/original/3X/b/7/b7b9c1edaf4019395d2b8315620948e240bf3f8f.pdf)</sup> |
| 首次硬件实现 | IBM RS/6000，1990年；其浮点单元将累加 \( D = (A \times B) + C \) 作为两周期流水线执行，仅有一个舍入误差<sup>[3](https://patents.google.com/patent/CN109032563B/en)</sup><sup> • </sup><sup>[4](https://research.ibm.com/publications/second-generation-risc-floating-point-with-multiply-add-fused)</sup> |
| C库接口 | C99定义了fma、fmaf和fmal，分别用于double、float和long double；FP_FAST_FMA* 宏表示该函数的求值快于表达式 x * y + z<sup>[5](https://cppreference.sh.karlosoft.com/en/c/numeric/math/fma.html)</sup> |
| 精度收益 | 在NVIDIA的十进制示例中，计算 x = 1.0008 时的 \( x^2 - 1 \)，保留四位小数，分开舍入的误差为0.00064，而FMA的误差为0.00004<sup>[6](https://docs.nvidia.com/cuda/archive/13.1.0/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup> |
| 编译器控制 | GCC默认将表达式收缩为FMA（-ffp-contract=fast）；-ffp-contract=off 禁用此行为<sup>[7](https://gcc.gnu.org/onlinedocs/gcc-7.5.0/gcc/Optimize-Options.html)</sup> |
| 数值线性代数用途 | FMA减小舍入误差界中的误差常数，混合精度块FMA是矩阵乘法和LU分解的张量核心算法的基础<sup>[8](https://eprints.maths.manchester.ac.uk/2833/)</sup><sup> • </sup><sup>[9](https://epubs.siam.org/doi/abs/10.1137/19M1289546)</sup> |

## 工作原理

不使用FMA时，计算 \( a \times b + c \) 需要两次舍入步骤，一次用于乘法，一次用于加法，每一步都可能丢失信息。由于FMA只舍入一次，它产生更精确的结果。<sup>[6](https://docs.nvidia.com/cuda/archive/13.1.0/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup> NVIDIA的编程指南用一个总共五位精度的十进制示例说明了这一效果：对于 \( x = 1.0008 \)，\( x^2 - 1 \) 的精确值为 \( 1.60064 \times 10^{-4} \)。FMA返回 \( 1.6006 \times 10^{-4} \)，误差为0.00004；而分别对乘法和加法舍入则返回 \( 1.6000 \times 10^{-4} \)，误差为0.00064。<sup>[6](https://docs.nvidia.com/cuda/archive/13.1.0/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup>

单次舍入的影响不止于精度。FMA对NaN传播的影响可能与两次独立运算不同，而且各实现并不统一：当存在多个NaN操作数时，不同目标可能倾向于产生一个quiet NaN或传播某个操作数的payload，IEEE 754并未严格规定确定性的payload选择顺序。<sup>[6](https://docs.nvidia.com/cuda/archive/13.1.0/cuda-programming-guide/05-appendices/mathematical-functions.html)</sup> 由于中间乘积被交付给一个足以精确容纳它的目标，使用FMA的系统仍然符合IEEE 754，尽管该标准最初并未预见到这一运算。<sup>[10](https://grouper.ieee.org/groups/msc/ANSI_IEEE-Std-754-2019/background/addendum.html)</sup>

## 历史

IBM开创了浮点乘加融合技术，于1990年在其RS/6000工作站级机器上将其付诸实践，作为加速浮点计算的一种方式。<sup>[3](https://patents.google.com/patent/CN109032563B/en)</sup> RS/6000的浮点单元是一个统一的乘加融合单元，将累加运算作为不可分割的操作执行，既降低了链式浮点运算的延迟，也减少了舍入误差。1990年2月发布的首批RS/6000产品配备单个浮点单元，每周期可发射一次复合乘加运算，延迟仅两个周期，因此峰值MFLOPS速率等于MHz速率的两倍；Model 530是一台25 MHz工作站，峰值达到50 MFLOPS。<sup>[11](https://www.redbooks.ibm.com/redbooks/pdfs/sg247071.pdf)</sup>

该运算随2008年修订版进入IEEE 754标准，该修订版于2008年8月29日发布，取代了1985年版标准；当前版本为IEEE 754-2019。<sup>[12](https://standards.ieee.org/ieee/754/4211/)</sup><sup> • </sup><sup>[1](https://dms-discourse-static.s3.dualstack.us-east-1.amazonaws.com/original/3X/b/7/b7b9c1edaf4019395d2b8315620948e240bf3f8f.pdf)</sup>

## 软件接口

C99提供了函数fma、fmaf和fmal，它们计算 \( (x \times y) + z \) 时如同具有无限精度，只对结果类型舍入一次。<sup>[5](https://cppreference.sh.karlosoft.com/en/c/numeric/math/fma.html)</sup> 如果实现定义了FP_FAST_FMA、FP_FAST_FMAF或FP_FAST_FMAL，则相应函数除了更精确之外，求值也快于表达式 x * y + z；许多实现即使未定义这些宏也使用硬件指令。<sup>[5](https://cppreference.sh.karlosoft.com/en/c/numeric/math/fma.html)</sup> 由于其无限的中间精度，fma可作为其他正确舍入运算的构建模块，例如sqrt，以及在CPU不直接提供时的除法。<sup>[5](https://cppreference.sh.karlosoft.com/en/c/numeric/math/fma.html)</sup>

编译器也可以从源表达式自动生成FMA指令，这种变换称为浮点表达式收缩。在GCC中，默认是 -ffp-contract=fast，当目标具有原生支持时形成融合乘加运算；-ffp-contract=off 禁用收缩，C编译指示 STDC FP_CONTRACT off 也会抑制它。<sup>[7](https://gcc.gnu.org/onlinedocs/gcc-7.5.0/gcc/Optimize-Options.html)</sup><sup> • </sup><sup>[5](https://cppreference.sh.karlosoft.com/en/c/numeric/math/fma.html)</sup> 收缩会改变数值结果，因为融合形式不对中间乘积舍入，这可能破坏依赖于精确IEEE 754行为或跨系统可复现性的代码。<sup>[13](https://gcc.gnu.org/onlinedocs/gcc-14.3.0/gcc.pdf)</sup><sup> • </sup><sup>[10](https://grouper.ieee.org/groups/msc/ANSI_IEEE-Std-754-2019/background/addendum.html)</sup>

## 精度与误差分析

FMA是数值线性代数中舍入误差分析的核心。曼彻斯特大学应用数学Richardson讲席教授Nicholas J. Higham指出，融合乘加运算——无论是标量级别还是混合精度块形式——是减小线性代数算法舍入误差界中误差常数的架构特性之一，与扩展精度寄存器和分块算法并列。<sup>[8](https://eprints.maths.manchester.ac.uk/2833/)</sup>

FMA还支持无误差和补偿技术。Boldo和Muller提出了一种涉及12次运算的算法，用于近似浮点输入下 \( \texttt{fma}(a,b,c) \) 的误差，以及一种更昂贵但能精确确定误差的方法。<sup>[14](https://link.springer.com/article/10.1007/s13160-026-00816-8)</sup> 在IEEE 754模型下，FMA结果满足 \( \texttt{fma}(a,b,c) - (ab+c) = \delta \)，其中 \( |\delta| \le u_2 |ab+c| \)，\( u_2 \) 是单位舍入类型的常数。<sup>[14](https://link.springer.com/article/10.1007/s13160-026-00816-8)</sup> Kahan计算2×2行列式的方法使用FMA精确求值乘积，而基于FMA的复数乘法补偿算法保证极小的分量相对误差，而非FMA算法在灾难性抵消下可能极不精确。<sup>[15](https://www.johndcook.com/blog/2020/05/31/kahan-determinant/)</sup><sup> • </sup><sup>[16](https://perso.ens-lyon.fr/jean-michel.muller/mcom3123.pdf)</sup>

这一运算是一把双刃剑。IEEE 754大部分架构的缔造者William Kahan观察到，经验不足的程序员或编译器笨拙地使用融合乘加可能导致问题。<sup>[17](https://ndl.ethernet.edu.et/bitstream/123456789/53742/1/Jean-Michel%20Muller.pdf)</sup> 融合乘加还可能破坏无误差变换中使用的分裂过程，尽管它可以以非可移植的方式用于执行无需分裂的多精度乘法。<sup>[10](https://grouper.ieee.org/groups/msc/ANSI_IEEE-Std-754-2019/background/addendum.html)</sup>

## 应用

**矩阵乘法与高精度算术。** 芝浦工业大学的Katsuhisa Ozaki和名古屋工业大学的Toru Koizumi提出了利用FMA运算的精确矩阵乘法算法，其计算成本低于传统高精度方法如pair算术和双字算术。他们的方法精度略低于这些替代方案，但速度提高约两到三倍，在配备专用浮点加法器单元的CPU上尤其有效。<sup>[14](https://link.springer.com/article/10.1007/s13160-026-00816-8)</sup>

**张量核心。** 以矩阵参数执行FMA运算的计算单元（某些厂商称为张量单元）本质上是混合精度的。Pierre Blanchard、Nicholas J. Higham、Florent Lopez、Theo Mary和Srikara Pranesh开发了一种混合精度块FMA，它推广了标量FMA和现有张量单元，并对矩阵乘法和LU分解内核进行了舍入误差分析。在NVIDIA V100 GPU上，他们的TC32变体（对张量核心输出使用更高精度）比TC16变体精确得多，而精度提升几乎不带来性能损失。<sup>[9](https://epubs.siam.org/doi/abs/10.1137/19M1289546)</sup>

**信号处理。** FMA架构还重塑了经典算法：Linzer和Feig的基2、基4、分裂基和基8 FFT算法在2的幂长度上计算离散傅里叶变换时，比传统Cooley-Tukey算法使用更少的乘加，在RS/6000上的基4实现显示出可观的执行时间节省，且数值行为略好。<sup>[18](https://research.ibm.com/publications/implementation-of-efficient-fft-algorithms-on-fused-multiply-add-architectures)</sup>

## References

1. [IEEE Std 754-2019, IEEE Standard for Floating-Point Arithmetic](https://dms-discourse-static.s3.dualstack.us-east-1.amazonaws.com/original/3X/b/7/b7b9c1edaf4019395d2b8315620948e240bf3f8f.pdf)
2. [Floating Point and IEEE 754, CUDA Toolkit Documentation (12.4)](https://docs.nvidia.com/cuda/archive/12.4.1/pdf/Floating_Point_on_NVIDIA_GPU.pdf)
3. [CN109032563B: A method and device for accelerating bridge fusion multiply-add, Google Patents](https://patents.google.com/patent/CN109032563B/en)
4. [Second-Generation RISC Floating Point with Multiply-Add Fused, IBM Research](https://research.ibm.com/publications/second-generation-risc-floating-point-with-multiply-add-fused)
5. [fma, fmaf, fmal, cppreference.com](https://cppreference.sh.karlosoft.com/en/c/numeric/math/fma.html)
6. [5.5. Floating-Point Computation, CUDA Programming Guide (13.1)](https://docs.nvidia.com/cuda/archive/13.1.0/cuda-programming-guide/05-appendices/mathematical-functions.html)
7. [Optimize Options, Using the GNU Compiler Collection (GCC)](https://gcc.gnu.org/onlinedocs/gcc-7.5.0/gcc/Optimize-Options.html)
8. [Nicholas J. Higham (2021), Numerical Stability of Algorithms at Extreme Scale and Low Precisions, MIMS Preprint](https://eprints.maths.manchester.ac.uk/2833/)
9. [Blanchard, Higham, Lopez, Mary, Pranesh, Mixed Precision Block Fused Multiply-Add: Error Analysis and Application to GPU Tensor Cores, SIAM J. Sci. Comput.](https://epubs.siam.org/doi/abs/10.1137/19M1289546)
10. [Differences Among IEEE 754 Implementations, IEEE 754 working group background material](https://grouper.ieee.org/groups/msc/ANSI_IEEE-Std-754-2019/background/addendum.html)
11. [IBM Redbook SG24-7071, RS/6000 processor history](https://www.redbooks.ibm.com/redbooks/pdfs/sg247071.pdf)
12. [IEEE SA, IEEE 754-2008 standard page](https://standards.ieee.org/ieee/754/4211/)
13. [Using the GNU Compiler Collection (GCC), GCC 14.3 manual](https://gcc.gnu.org/onlinedocs/gcc-14.3.0/gcc.pdf)
14. [Ozaki and Koizumi, Fast and accurate algorithms for matrix multiplication using fused multiply-add and their rounding error analysis, Japan J. Ind. Appl. Math. 43, 59 (2026)](https://link.springer.com/article/10.1007/s13160-026-00816-8)
15. [Kahan's method for computing a 2x2 determinant with FMA, John D. Cook](https://www.johndcook.com/blog/2020/05/31/kahan-determinant/)
16. [Error bounds on complex floating-point multiplication with an FMA, Muller et al., Math. Comp.](https://perso.ens-lyon.fr/jean-michel.muller/mcom3123.pdf)
17. [Jean-Michel Muller, Handbook of Floating-Point Arithmetic, Chapter 2 (FMA section)](https://ndl.ethernet.edu.et/bitstream/123456789/53742/1/Jean-Michel%20Muller.pdf)
18. [Linzer and Feig, Implementation of Efficient FFT Algorithms on Fused Multiply-Add Architectures, IEEE TSP (1993), IBM Research](https://research.ibm.com/publications/implementation-of-efficient-fft-algorithms-on-fused-multiply-add-architectures)

---
*Initially written Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Arithmetic and number systems › Computational arithmetic › Floating-point and mixed-precision arithmetic

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/fused-multiply-add

English original: https://www.edgepedia.org/fused-multiply-add
