gcc 的 ffast-math 实际上是做什么的? [英] What does gcc's ffast-math actually do?
问题描述
我了解 gcc 的 --ffast-math
标志可以大大提高浮点运算的速度,并且超出了 IEEE 标准,但我似乎无法找到有关真正发生的事情的信息在.任何人都可以解释一些细节,也许可以给出一个清晰的例子,说明如果标志打开或关闭,某些事情会发生什么变化?
I understand gcc's --ffast-math
flag can greatly increase speed for float ops, and goes outside of IEEE standards, but I can't seem to find information on what is really happening when it's on. Can anyone please explain some of the details and maybe give a clear example of how something would change if the flag was on or off?
我确实尝试过挖掘 S.O.对于类似的问题,但找不到任何解释 ffast-math 工作原理的内容.
I did try digging through S.O. for similar questions but couldn't find anything explaining the workings of ffast-math.
推荐答案
正如您提到的,它允许进行不严格遵守 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.
这篇关于gcc 的 ffast-math 实际上是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!