use*_*759 7 gcc compilation compiler-optimization
我只是通读 gcc 手册以找出-O3
和之间的区别-Ofast
。
为了 -O3
-O3
Run Code Online (Sandbox Code Playgroud)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
Run Code Online (Sandbox Code Playgroud)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)
对于浮点数)。
-Ofast
在特定情况下是否安全取决于算法,但通常大多数非科学应用程序都能很好地使用它。例如,大多数游戏引擎都是用-ffast-math
.
归档时间: |
|
查看次数: |
1682 次 |
最近记录: |