【linux】gcc编译选项:-fomit-frame-pointer,-fno-tree-vectorize,-fno-strict-aliasing以及ARM相关选项

发布时间 2023-07-19 20:03:33作者: DoubleLi

Date: 2018.9.8


1、参考

https://www.cnblogs.com/islandscape/p/3444122.html
https://blog.csdn.net/chdhust/article/details/8462414
https://gcc.gnu.org/onlinedocs/gcc-6.2.0/gcc.pdf

https://blog.csdn.net/u012927281/article/details/50999138
https://blog.csdn.net/softee/article/details/52241328
https://www.linuxidc.com/Linux/2013-03/81246.htm

2、gcc选项-fomit-frame-pointer

gcc文档中对该选项的解释如下:
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.
解读:开启该选项,主要是用于去掉所有函数SFP(Stack Frame Pointer)的,即在函数调用时不保存栈帧指针SFP,代价是不能通过backtrace进行调试根据堆栈信息了。通过去掉SFP,可以提高程序运行速度,达到优化程序的目的。
另外一个类似选项-fomit-leaf-frame-pointer:用于去掉子函数leaf function的SFP。
该选项属于优化选项,在指定-O选项时,也会开启该选项。

3、gcc选项-fno-tree-vectorize

gcc -O3级优化已包括 “-ftree-vectorize” 选项对程序进行自动向量化,关闭向量化的选项是-fno-tree-vectorize。使用-ftree-vectorizer-verbose=n选项可以显示自动向量化的结果,其中n的取值范围为0到9。自动矢量化技术简单讲就是一次处理多个数据SIMD,比如x86 sse/mmx,arm neon技术。

更多解读可以参考:
https://stackoverflow.com/questions/35916358/tree-vectorization-gcc-optimization-flag
https://www.gnu.org/software/gcc/projects/tree-ssa/vectorization.html
https://monoinfinito.wordpress.com/series/vectorization-in-gcc/

4、gcc选项-fno-strict-aliasing

开启fstrict-aliasing选项,允许编译器对所编译的语言采用严格的别名规则。

5、ARM相关gcc选项

‘-m’选项是专门为ARM架构定义的。
常用选项如下:

-mabi=name: 产生特定ABI的代码,可用name为atpcs,aapcs,apcs-gnu等。
-mthumb-interwork: 产生支持在ARM和Thumb指令集之间调用的代码。
-mfloat-abi=name: 指定浮点型abi使用的类型,可用name为:soft,hard和softfp。
-march=name: 指定目标平台ARM架构名称,gcc通过这个名字来确定在生成汇编代码时使用的指令。比如armv7,armv7-1,armv8-a等。
-mtune=name: 指定了GCC调整代码性能的目标ARM处理器的名称,比如arm7,cortex-a7等。
-mcpu=name: 指定目标平台ARM处理器的名称。gcc可以通过该名称确定目标平台ARM架构(等效于-march)和用于调整性能的目标ARM处理器类型(等效于-mtune)。
-mfpu=name: 用于指定哪种浮点硬件在目标平台可用,比如vfp,neon,neon-vpfv4,neon-fp-armv8等

THE END!