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).
Try this:
Putting uniquely-named functions in first.c and second.c. This should do the trick. There is rarely any "global" impact of a compiler optimization. If one does exist, linking will likely fail due to the conflict.
I tried a small sample without problem.
Here's an example.
first.c
second.c
compilation
Check the difference between first.s and second.s and you'll find this:
changes to this:
Both functions are called, and both return the expected result.