The Intel C++ compiler provides two options for controlling floating point:
-fp-speculation (fast/safe/strict/off)
-fp-model (precise/fast/strict and source/double/extended)
I think I understand what fp-model does. But what is fp-speculation and how does it relate to fp-model? I have yet to find any intel doc which explains this!
-fp-modelinfluences how floating-point computations are carried out, and can change the numeric result (by licensing unsafe optimizations or by changing the precision at which intermediate results are evaluated).-fp-speculationdoes not change the numerical results, but can effect what floating-point flags are raised by an operation (or what traps are taken if floating-point traps are enabled). 99.99% of programmers don’t need care about these things, so you can probably run with the default and not worry about it.Here’s a concrete example; suppose you have the following function:
sqrtis, relatively speaking, slow. It would be nice to hoist the computation ofsqrt(x)like this:By doing this, we allow the computation of
sqrtto proceed simultaneously with other computations, reducing the latency of our function. However, there’s a problem; ifxis negative, thensqrt(x)raises the invalid flag. In the original program, this could never happen, becausesqrt(x)was only computed ifxwas non-negative. In the modified program,sqrt(x)is computed unconditionally. Thus, ifxis negative, the modified program raises the invalid flag, whereas the original program did not.The
-fp-speculationflag gives you a way to tell the compiler whether or not you care about these cases, so it knows whether or not it is licensed to make such transformations.