Can any one help in making me understand what does -ffast-math option does when compiled with gcc. I see a difference of 20 sec in my programs execution time when executed with -O3 and -ffast-math compared to only use of -O3
在与gcc一起编译时,可以帮助我理解什么是-ffast-math选项。使用-O3和-ffast-math执行程序时,我发现与只使用-O3相比,程序执行时间有20秒的差异
1 个解决方案
#1
13
Why not read the gcc man page, it's your friend as well as mine. Here's what it told me:
为什么不读一下gcc手册页呢,它既是我的朋友,也是你的朋友。这是它告诉我的:
Sets -fno-math-errno, -funsafe-math-optimizations, -ffinite-math-only, -fno-rounding-math, -fno-signaling-nans and -fcx-limited-range.
设置-fno-math-errno, - funmath优化,-ffinite-math, -fno- round- math, -fno-signaling-nans和-fcx-limited-range。
So it doesn't do anything interesting by itself, but is just a shorthand to several more interesting compiler options. What do the individual flags do?
它本身并没有什么有趣的东西,它只是一些更有趣的编译器选项的简写。各个标志是做什么的?
-
fno-math-errno
makes single-instruction math operations not setERRNO
- fno-math-errno使单指令数学运算不设置ERRNO。
-
funsafe-math-optimizations
allows math optimizations that assume valid arguments and can violate ANSI and IEEE standards (caution, not actually fun and safe) - 最安全的数学优化允许数学优化假设有效的参数,并且可以违反ANSI和IEEE标准(谨慎,而不是真正的有趣和安全)
-
ffinite-math-only
, likewise, allows math optimizations that assume that any floating point values are neither infinite norNaN
- 同样,ffinite-math-only允许进行数学优化,假设任何浮点值都不是无限的,也不是NaN
-
fno-rounding-math
andfno-signaling-nans
are actually on by default. Their oppositesfrounding-math
andfsignaling-nans
disable some potentially unsafe/unportable optimizations. - fno- round- math和fno-signaling-nans实际上在默认情况下是打开的。它们的对立面——数学和fsignalnans禁用了一些潜在的不安全/不可移植的优化。
-
fcx-limited-range
allows the compiler to not do certain complex number arithmetic checks. Not likely to impact your program unless you're actually working with complex numbers! - fcx-limit -range允许编译器不执行某些复数算术检查。不太可能影响你的程序,除非你真的在用复数!
In short, it allows the compiler to optimize your program at the cost of losing standard compliance and some safety.
简而言之,它允许编译器以失去标准遵从性和一些安全性为代价来优化您的程序。
#1
13
Why not read the gcc man page, it's your friend as well as mine. Here's what it told me:
为什么不读一下gcc手册页呢,它既是我的朋友,也是你的朋友。这是它告诉我的:
Sets -fno-math-errno, -funsafe-math-optimizations, -ffinite-math-only, -fno-rounding-math, -fno-signaling-nans and -fcx-limited-range.
设置-fno-math-errno, - funmath优化,-ffinite-math, -fno- round- math, -fno-signaling-nans和-fcx-limited-range。
So it doesn't do anything interesting by itself, but is just a shorthand to several more interesting compiler options. What do the individual flags do?
它本身并没有什么有趣的东西,它只是一些更有趣的编译器选项的简写。各个标志是做什么的?
-
fno-math-errno
makes single-instruction math operations not setERRNO
- fno-math-errno使单指令数学运算不设置ERRNO。
-
funsafe-math-optimizations
allows math optimizations that assume valid arguments and can violate ANSI and IEEE standards (caution, not actually fun and safe) - 最安全的数学优化允许数学优化假设有效的参数,并且可以违反ANSI和IEEE标准(谨慎,而不是真正的有趣和安全)
-
ffinite-math-only
, likewise, allows math optimizations that assume that any floating point values are neither infinite norNaN
- 同样,ffinite-math-only允许进行数学优化,假设任何浮点值都不是无限的,也不是NaN
-
fno-rounding-math
andfno-signaling-nans
are actually on by default. Their oppositesfrounding-math
andfsignaling-nans
disable some potentially unsafe/unportable optimizations. - fno- round- math和fno-signaling-nans实际上在默认情况下是打开的。它们的对立面——数学和fsignalnans禁用了一些潜在的不安全/不可移植的优化。
-
fcx-limited-range
allows the compiler to not do certain complex number arithmetic checks. Not likely to impact your program unless you're actually working with complex numbers! - fcx-limit -range允许编译器不执行某些复数算术检查。不太可能影响你的程序,除非你真的在用复数!
In short, it allows the compiler to optimize your program at the cost of losing standard compliance and some safety.
简而言之,它允许编译器以失去标准遵从性和一些安全性为代价来优化您的程序。