第77部分- Linux x86 64位汇编 优化编译器代码

第77部分- Linux x86 64位汇编 优化编译器代码-O1/-O2/-O3

仅仅使用汇编语言代码替换C或者C++不会必然使得程序执行的更好,因为编译器已经把所有高级语言代码都转化成了汇编语言。

这里的关键是编写比编译器生成的代码更好的汇编语言。当然也可以使用若干优化技巧来指示编译器生成汇编语言代码。我们需要了解如何从编译器生成代码,如何使用各种优化级别,以及利用了什么优化技术。

编译器的-O选项提供了GNU编译器的优化步骤。共有3个级别

-O:提供基础的级别的优化

-O2:提供更加高级的代码优化

-O3:提供最高级别的优化

O1优化

-O1支持如下的优化选项。

                  -fauto-inc-dec

                   -fbranch-count-reg

                   -fcombine-stack-adjustments

                   -fcompare-elim

                   -fcprop-registers

                   -fdce

                   -fdefer-pop

                   -fdelayed-branch

                   -fdse

                   -fforward-propagate

                   -fguess-branch-probability

                   -fif-conversion2

                   -fif-conversion

                   -finline-functions-called-once

                   -fipa-pure-const

                   -fipa-profile

                   -fipa-reference

                   -fmerge-constants

                   -fmove-loop-invariants

                   -freorder-blocks

                   -fshrink-wrap

                   -fshrink-wrap-separate

                   -fsplit-wide-types

                   -fssa-backprop

                   -fssa-phiopt

                   -ftree-bit-ccp

                   -ftree-ccp

                   -ftree-ch

                   -ftree-coalesce-vars

                   -ftree-copy-prop

                   -ftree-dce

                   -ftree-dominator-opts

                   -ftree-dse

                   -ftree-forwprop

                   -ftree-fre

                   -ftree-phiprop

                   -ftree-sink

                   -ftree-slsr

                   -ftree-sra

                   -ftree-pta

                   -ftree-ter

                   -funit-at-a-time

O2优化

-O2优化结合了第一个O1优化的所有优化技术,再加上了很多其他技术。

-fthread-jumps
                   -falign-functions -falign-jumps
                   -falign-loops -falign-labels
                   -fcaller-saves
                   -fcrossjumping
                   -fcse-follow-jumps -fcse-skip-blocks
                   -fdelete-null-pointer-checks
                   -fdevirtualize -fdevirtualize-speculatively
                   -fexpensive-optimizations
                   -fgcse -fgcse-lm
                   -fhoist-adjacent-loads
                   -finline-small-functions
                   -findirect-inlining
                   -fipa-cp
                   -fipa-bit-cp
                   -fipa-vrp
                   -fipa-sra
                   -fipa-icf
                   -fisolate-erroneous-paths-dereference
                   -flra-remat
                   -foptimize-sibling-calls
                   -foptimize-strlen
                   -fpartial-inlining
                   -fpeephole2
                   -freorder-blocks-algorithm=stc
                   -freorder-blocks-and-partition -freorder-functions
                   -frerun-cse-after-loop
                   -fsched-interblock -fsched-spec
                   -fschedule-insns -fschedule-insns2
                   -fstore-merging
                   -fstrict-aliasing -fstrict-overflow
                   -ftree-builtin-call-dce
                   -ftree-switch-conversion -ftree-tail-merge
                   -fcode-hoisting
                   -ftree-pre
                   -ftree-vrp
                   -fipa-ra

O3优化

O3选项访问编译器提供的最高级别。整合了O1和O2,还提供了非常专门的附加优化技术。

-finline-functions
-funswitch-loops
-fpredictive-commoning
-fgcse-after-reload
-ftree-loop-vectorize
-ftree-loop-distribute-patterns
-fsplit-paths
-ftree-slp-vectorize
-fvect-cost-model
-ftree-partial-pre
-fpeel-loops
-fipa-cp-clone

这些大家可以在

《Using the GNU Compiler Collection》中查看到。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值