c – 为什么GCC在明确表示会减慢程序时会在O2O3上启用优化?

c – 为什么GCC在明确表示会减慢程序时会在O2O3上启用优化?,第1张

概述引自 https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html: -falign-labels -falign-labels=n Align all branch targets to a power-of-two boundary, skipping up to n bytes like -falign-functions. This op 引自 https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html:

-falign-labels

-falign-labels=n

Align all branch targets to a power-of-two boundary,skip@R_404_6817@ up to n bytes like -falign-functions. This option can easily
make code slower,because it must insert dummy operations for when the
branch target is reached in the usual flow of the code.

-fno-align-labels and -falign-labels=1 are equivalent and mean that labels are not aligned.

If -falign-loops or -falign-jumps are applicable and are greater than
this value,then their values are used instead.

If n is not specifIEd or is zero,use a machine-dependent default
which is very likely to be ‘1’,meaning no alignment.

Enabled at levels -O2,-O3.

考虑这个标志会使它失去更多意义……有引发代码缓存未命中的后果,甚至启用意味着何时参数采用数值(1 ..)?

@R_403_6120@ 它没有这么说.它说可以轻松地使代码变慢.这意味着,在某些情况下,它可以使代码变慢.在其他情况下,它可以使代码更快.

对齐会导致代码运行速度变慢:

>增加代码大小,因此代码不在缓存中的可能性更高.
>添加了nop *** 作减慢了代码

对齐可能导致更快地运行代码:分支预测,指令获取和上帝知道什么.

在单个if的情况下,很难说哪个效果更强.这取决于条件.

但是,对于循环,通常代码变得更快.为什么?因为慢因子只发生一次,但循环的每个循环都会更快地执行.

(我的海湾合作委员会似乎将标签与8对齐)

总结

以上是内存溢出为你收集整理的c – 为什么GCC在明确表示会减慢程序时会在O2 / O3上启用优化?全部内容,希望文章能够帮你解决c – 为什么GCC在明确表示会减慢程序时会在O2 / O3上启用优化?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1240528.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存