我只是阅读 gcc 手册来找出两者之间的区别-O3
and -Ofast
.
For -O3
-O3
Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the following optimization flags:
-fgcse-after-reload
-fipa-cp-clone
-floop-interchange
-floop-unroll-and-jam
-fpeel-loops
-fpredictive-commoning
-fsplit-paths
-ftree-loop-distribute-patterns
-ftree-loop-distribution
-ftree-loop-vectorize
-ftree-partial-pre
-ftree-slp-vectorize
-funswitch-loops
-fvect-cost-model
-fversion-loops-for-strides
的同时-Ofast
-Ofast
Disregard strict standards compliance. -Ofast enables all -O3 optimizations. It also enables optimizations that are not valid for
all standard-compliant programs. It turns on -ffast-math,
-fallow-store-data-races and the Fortran-specific -fstack-arrays, unless -fmax-stack-var-size is specified, and -fno-protect-parens
因此我想知道是否可能-Ofast
由于某种原因不如-O3
,因此我应该坚持-O3
那时的大多数时候。
您能澄清一下使用它们时的“实际差异”吗?而如果-Ofast
实际上安全吗?
Ofast
实现违反 C 标准浮点语义要求的优化。特别是在-Ofast
(aka -ffast-math
)它会自由地重新排序浮点计算(默认情况下是禁止的,因为一般来说a + (b + c) != (a + b) + c != a + (c + b)
对于浮标)。
Whether -Ofast
在特定情况下是否安全取决于算法,但是usually大多数非科学应用程序都可以很好地使用它。例如,大多数游戏引擎都是用-ffast-math
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)