fast-math

Do denormal flags like Denormals-Are-Zero (DAZ) affect comparisons for equality?

允我心安 提交于 2021-02-08 19:42:57
问题 If I have 2 denormal floating point numbers with different bit patterns and compare them for equality, can the result be affected by the Denormals-Are-Zero flag, the Flush-to-Zero flag, or other flags on commonly used processors? Or do these flags only affect computation and not equality checks? 回答1: DAZ (Denormals Are Zero) affects reading input, so DAZ affects compares . All denormals are literally treated as -0.0 or +0.0 , according to their sign. FTZ (Flush To Zero) affects only writing

Do denormal flags like Denormals-Are-Zero (DAZ) affect comparisons for equality?

被刻印的时光 ゝ 提交于 2021-02-08 19:42:39
问题 If I have 2 denormal floating point numbers with different bit patterns and compare them for equality, can the result be affected by the Denormals-Are-Zero flag, the Flush-to-Zero flag, or other flags on commonly used processors? Or do these flags only affect computation and not equality checks? 回答1: DAZ (Denormals Are Zero) affects reading input, so DAZ affects compares . All denormals are literally treated as -0.0 or +0.0 , according to their sign. FTZ (Flush To Zero) affects only writing

Good sentinel value for double if prefer to use -ffast-math

前提是你 提交于 2021-02-07 11:58:38
问题 Since the gcc option -ffast-math effectively disables NaN and -/+inf , I'm looking for maybe the next best option for representing NaN in my performance-critical math code. Ideally the sentinel value if operated on (add, mul, div, sub, etc..) would yield the sentinel value as NaN would do but I doubt this would be possible since I think NaN is the only value that accomplishes this. -0.0 might not be a good fit as it's also disabled in -ffast-math and could prevent certain optimizations like

Can I make my compiler use fast-math on a per-function basis?

点点圈 提交于 2020-05-13 04:19:58
问题 Suppose I have template <bool UsesFastMath> void foo(float* data, size_t length); and I want to compile one instantiation with -ffast-math ( --use-fast-math for nvcc), and the other instantiation without it. This can be achieved by instantiating each of the variants in a separate translation unit, and compiling each of them with a different command-line - with and without the switch. My question is whether it's possible to indicate to popular compilers (*) to apply or not apply -ffast-math

Can I make my compiler use fast-math on a per-function basis?

与世无争的帅哥 提交于 2020-05-13 04:13:09
问题 Suppose I have template <bool UsesFastMath> void foo(float* data, size_t length); and I want to compile one instantiation with -ffast-math ( --use-fast-math for nvcc), and the other instantiation without it. This can be achieved by instantiating each of the variants in a separate translation unit, and compiling each of them with a different command-line - with and without the switch. My question is whether it's possible to indicate to popular compilers (*) to apply or not apply -ffast-math

Can I make my compiler use fast-math on a per-function basis?

大憨熊 提交于 2020-05-13 04:11:49
问题 Suppose I have template <bool UsesFastMath> void foo(float* data, size_t length); and I want to compile one instantiation with -ffast-math ( --use-fast-math for nvcc), and the other instantiation without it. This can be achieved by instantiating each of the variants in a separate translation unit, and compiling each of them with a different command-line - with and without the switch. My question is whether it's possible to indicate to popular compilers (*) to apply or not apply -ffast-math

gcc -Ofast - complete list of limitations

安稳与你 提交于 2020-05-11 06:50:19
问题 I'm using -Ofast gcc option in my program cause latency requirements. I wrote simple test program: #include <iostream> #include <math.h> static double quiet_NaN = std::numeric_limits<double>::quiet_NaN(); int main() { double newValue = 130000; double curValue = quiet_NaN; printf("newValue = %f\n", newValue); printf("curValue = %f\n", curValue); printf("isnan(newValue) = %d\n", isnan(newValue)); printf("isnan(curValue) = %d\n", isnan(curValue)); printf("newValue == curValue %d\n", (newValue ==

Dynamic -ffast-math

天涯浪子 提交于 2020-01-13 09:48:07
问题 Is it possible to selectively turn -ffast-math on/off during runtime? For example, creating classes FastMath and AccurateMath with the common base class Math, so that one would be able to use both implementations during runtime? Ditto for flashing subnormals to zero, etc. In particular, I don't know whether compiling with -ffast-math would emit an instruction that would, once executed, affect all numerical computations in the thread (for example, setting a flag to flush subnormals to zero).

Why doesn't GCC optimize a*a*a*a*a*a to (a*a*a)*(a*a*a)?

限于喜欢 提交于 2019-12-21 06:45:22
问题 I am doing some numerical optimization on a scientific application. One thing I noticed is that GCC will optimize the call pow(a,2) by compiling it into a*a , but the call pow(a,6) is not optimized and will actually call the library function pow , which greatly slows down the performance. (In contrast, Intel C++ Compiler, executable icc , will eliminate the library call for pow(a,6) .) What I am curious about is that when I replaced pow(a,6) with a*a*a*a*a*a using GCC 4.5.1 and options " -O3

std::isinf does not work with -ffast-math. how to check for infinity

雨燕双飞 提交于 2019-12-18 16:56:30
问题 Sample code: #include <iostream> #include <cmath> #include <stdint.h> using namespace std; static bool my_isnan(double val) { union { double f; uint64_t x; } u = { val }; return (u.x << 1) > 0x7ff0000000000000u; } int main() { cout << std::isinf(std::log(0.0)) << endl; cout << std::isnan(std::sqrt(-1.0)) << endl; cout << my_isnan(std::sqrt(-1.0)) << endl; cout << __isnan(std::sqrt(-1.0)) << endl; return 0; } Online compiler. With -ffast-math , that code prints "0, 0, 1, 1" -- without, it