I like to run my code with floating point exceptions enabled. I do this under Linux using:
feenableexcept( FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW );
So far so good.
The issue I am having, is that sometimes the compiler (I use clang8) decides to use SIMD instructions to do a scalar division. Fine, if that is faster, even for a single scalar, why not.
But the result is that an unused lane in the SIMD register can contain a zero.
And when the SIMD division is executed, a floating point exception is thrown.
Does that mean that floating point exceptions cannot be used at all if you allow the compiler to use sse/avx extensions?
In my case, this line of C code:
float a0, min, a, d;
...
a0 = (min - a) / (d);
...is exectuted as:
divps %xmm2,%xmm3
Which then throws a:
Thread 1 "noisetuner" received signal SIGFPE, Arithmetic exception.
-ftrapping-math
to make FP exceptions a visible side-effect? (Note that GCC's version of that option is on by default, but is actually broken: it fails to stop GCC from doing some optimizations that change the number or type of of FP exceptions, possibly including from 0 to non-zero IIRC.) – Yorick-ftrapping-math
but it doesn't fix it. To stop the FPE, I have to supply-mno-mmx -mno-sse
arguments. – Cowberrydivps
and not adivss
? Can you provide a minimal reproducible example? – Autoharp