GCC 双精度浮点运算的特殊优化选项
您知道哪些 GCC 优化标志最适合构建应用程序,该应用程序使用双浮点并实时计算大量内容,并且使用 -lm。目标硬件是两个带有 Linux 板载的 Dual-Xeon。提前致谢!
Do you know which of the GCC optimization flags are the most appropriate to build an application, which uses double floating point and calculates a lot in real-time and it uses -lm. A target hardware is two Dual-Xeons with Linux on-board. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“Dual-Xeon”并不是您所针对的处理器的精确规格 - “Xeon”更多的是一个营销品牌名称,而不是特定型号。 “Xeon”甚至不会告诉您您的目标是 IA32 还是 x86-64 架构。
这很重要,因为通过针对特定的 CPU 系列可以显着改进优化。 GCC 文档中描述了许多选项;特别是,从
-march
开始为特定指令集生成代码。如果您的目标不是 x86-64,则使用
-mfpmath=sse
(如果您的 CPU 类型支持)将 SSE 指令用于浮点,而不是 387(此选项是 x86- 上的默认选项) 64)。同样,-malign-double
可以提供加速(但仅在 x86-64 上默认)。此外,如果您在分析时在
libmath
中使用的函数显示为热点,那么使用更具体的优化标志重新编译该库可能会有所帮助。"Dual-Xeon" is not a precise specification of the processors you're targetting - "Xeon" is more a marketing brand name than a specific model. "Xeon" doesn't even tell you if you're targetting the IA32 or x86-64 architecture.
This is important, because the optimisation can be significantly improved by targetting a specific CPU family. There are many options described in the GCC documentation; in particular, start with
-march
to generate code for a particular instruction set.If you are not targetting x86-64, then use
-mfpmath=sse
(if supported by your CPU type) to use SSE instructions for floating point, rather than 387 (this option is the default on x86-64). Likewise,-malign-double
can give a speedup (but is only default on x86-64).Also, if the functions you use in
libmath
are shown as a hotspot when you profile, then recompiling that library with more specific optimisation flags may be of benefit.根据它是否安全且适合您的给定应用程序,您可以考虑
-ffast-math
。不过,在使用它之前,请阅读手册页上的警告。我从经验中知道,它可以对运行数值模拟的程序产生很大的影响。当然,您必须进行一些健全性检查以确保输出没有改变。
Depending on whether it is safe and appropriate for your given application you could consider
-ffast-math
. Please read the warnings on the man page for this before using it though.I know from experience that it can make quite a difference with programs running numerical simulations. Of course you have to do some sanity checks to make sure the output is not altered.