gcc的快速数学实际上做了什么? [英] What does gcc's ffast-math actually do?

查看:330
本文介绍了gcc的快速数学实际上做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道gcc的 - ffast-math 标志可以大大提高浮点操作的速度,并超出IEEE标准,但我似乎无法找到关于当它开始时真的发生了什么。任何人都可以请解释一些细节,也许给一个明确的例子,如果国旗是打开还是关闭,会发生什么样的变化?

我曾尝试通过S.O.对于类似的问题,但找不到解释ffast数学运算的任何东西。



例如:

pre $ code > x = x * x * x * x * x * x * x * x;

  x * = x; 
x * = x;
x * = x;由于浮点运算不是关联的,所以操作的排序和因式分解会影响结果,这是由于以下原因造成的:

四舍五入。因此,这种优化不是在严格的FP行为下完成的。



编辑:我没有真正检查GCC是否确实做了这个特定的优化。但是这个想法是一样的。


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?

I did try digging through S.O. for similar questions but couldn't find anything explaining the workings of ffast-math.

解决方案

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

An example is this:

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

to

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

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.

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

这篇关于gcc的快速数学实际上做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆