美文网首页
CH8.5 编译器参数优化

CH8.5 编译器参数优化

作者: 磊宝万岁 | 来源:发表于2019-05-12 15:31 被阅读0次

编译器优化

1. 关闭运行时类型检查(turnoff RTTI)

When /GR is on, the compiler defines the _CPPRTTI preprocessor macro. By default, /GR is on. /GR- disables run-time type information.Use /GR if the compiler cannot statically resolve an object type in your code. You usually need the /GR option when your code uses dynamic_cast Operator or typeid. However, /GR increases the size of the .rdata sections of your image. If your code does not use dynamic_cast or typeid, /GR- may produce a smaller image.

#icc 默认是开启RTTI的, 关闭选项:
icc xxx -fno-riit
2. 开启fast floating point calculatinos 或者关闭 strict floating point calculations(如果在精度要求范围内)
gcc/icc xxx -fp-mode fast[=1/2]

默认的fast模式开启的是1,即fat=1, fast=2 能够使程序的浮点运算更快但是要损失更多的精度。
-fp-model precise 会关闭所有会有损计算精度的优化。如果精度要求不高的话关闭此选项。
其他的fp-model选项如下:

参数 描述
precise Disables optimizations that are not value-safe on floating-point data.
fast=[1/2] Enables more aggressive optimizations on floating-point data
consistent Enables consistent, reproducible results for different optimization levels or between different processors of the same architecture.
strict Enables precise and except, disables contractions, and enables pragma stdc fenv_access.
source Rounds intermediate results to source-defined precision.
double Rounds intermediate results to 53-bit (double) precision.
extended Rounds intermediate results to 64-bit (extended) precision.
[no-]except (Linux* and macOS) or except[-] (Windows ) Determines whether strict floating-point exception semantics are honored.

[注意:]上述是man icc的结果, 貌似linux gcc上没找到-fp-mode fast这么个选项??貌似-ffast-math就是-fp-mode fast=2; 默认是-fp-mode fast=1

3. 开启function level linking

remove unreferenced functions
去掉没有被引用的函数。

#windows:
/Gy
#Linux:
-ffunction-sections
4. 开启assume no pointer aliasing(如果你能确保没有pointer aliasing的话)
#windows:
/Oa
#linux

除了在编译的时候声明之外,还可以在代码中这么声明一个pointer来表明该指针不会被aliasing:
在变量名前添加 __restrict 或者 __restrict __;

5. 不要开启 "frame pointer" (确保没有使用exception)

关闭frame pointer会是程序变快,而且会空出一个寄存器来。参考

gcc manual 是这么说的:

-fomit-frame-pointer
Don't keep the frame pointer in a register for functions that don't need one. This avoids the instructions to save, set up and restore frame pointers; it also makes an extra register available in many functions. It also makes debugging impossible on some machines.
On some machines, such as the VAX, this flag has no effect, because the standard calling sequence automatically handles the frame pointer and nothing is saved by pretending it doesn't exist. The machine-description macro "FRAME_POINTER_REQUIRED" controls whether a target machine supports this flag.
The default setting (when not optimizing for size) for 32-bit GNU/Linux x86 and 32-bit Darwin x86 targets is -fomit-frame-pointer. You can configure GCC with the --enable-frame-pointer configure option to change the default. Enabled at levels -O, -O2, -O3, -Os.

开启方法:

-fomit-frame-pointer

看不懂到底是默认开了还是没开,反正当时候为了保险自己手动加上试试, 记得看看结果对不对

相关文章

  • CH8.5 编译器参数优化

    编译器优化 1. 关闭运行时类型检查(turnoff RTTI) When /GR is on, the comp...

  • xcode 常见设置

    xcode Built Setting里的参数1、Optimization Level 编译器优化程度 None:...

  • LLVM

    一、编译器 性能优化:启动优化、界面优化、架构优化 编译型语言:OC(编译器是clang)、C(编译器可以直接执行...

  • Linux 下如何绕过编译器优化

    本文首次发表在 Linux 下如何绕过编译器优化 有同学在群里聊到编译器优化的事情,很多时候期望编译器默认做优化,...

  • JMM造成指令重排的原因

    1、编译器优化 2、Processor 优化(流水线) 3、MESI缓存优化

  • iOS逆向之OC反汇编(上)

    本文主要讲解编译器的优化以及指针的汇编 编译器优化 设置 可在项目的BuildSetting->Optimizat...

  • 内联函数(Inline Function)

    场景:如果开启了编译器优化(Release模式默认会开启优化),编译器自动将某些函数变成内联函数 调用方式如下: ...

  • 编译器优化部分代码

    我们简单写一些代码看编译器优化前后的对比。编译器没有优化时 在Build Setting 搜索optimizati...

  • iOS的性能优化

    1、ipa包体积优化 1.1 编译配置优化:编译器代码层面优化Optimize Level;Bitcode(较难...

  • 后端开发需要了解的mysql优化方向

    优化思维导图 参数优化注意事项 参数优化分为 动态参数配置 和 配置文件的配置,建议在启动mysql之前配置好优化...

网友评论

      本文标题:CH8.5 编译器参数优化

      本文链接:https://www.haomeiwen.com/subject/mspcaqtx.html