且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

gcc 的 ffast-math 实际上是做什么的?

更新时间:2022-11-27 23:09:43

正如您提到的,它允许进行不严格遵守 IEEE 合规性的优化.

As you mentioned, it allows optimizations that do not preserve strict IEEE compliance.

一个例子是:

x = x*x*x*x*x*x*x*x;

x *= x;
x *= x;
x *= x;

因为浮点运算是不结合的,所以运算的排序和因式分解会因为四舍五入而影响结果.因此,这种优化不是在严格的 FP 行为下完成的.

Because floating-point arithmetic is not associative, the ordering and factoring of the operations will affect results due to round-off. Therefore, this optimization is not done under strict FP behavior.

我还没有真正检查过 GCC 是否真的进行了这种特定的优化.但想法是一样的.

I haven't actually checked to see if GCC actually does this particular optimization. But the idea is the same.