c - Dynamic -ffast-math -


is possible selectively turn -ffast-math on/off during runtime? example, creating classes fastmath , accuratemath common base class math, 1 able use both implementations during runtime? ditto flashing subnormals zero, etc.

in particular, don't know whether compiling -ffast-math emit instruction would, once executed, affect numerical computations in thread (for example, setting flag flush subnormals zero).

try this:

gcc -ffast-math -c first.c gcc -c second.c gcc -o dyn_fast_math first.o second.o 

putting uniquely-named functions in first.c , second.c. should trick. there "global" impact of compiler optimization. if 1 exist, linking fail due conflict.

i tried small sample without problem.

here's example.

first.c

extern double second();  double  first () {     double  dbl;      dbl = 1.0;     dbl /= 10.0;      return  dbl; }  int main () {     printf("first = %f\n", first());     printf("second = %f\n", second());      return  0; } 

second.c

double  second () {     double  ddbl;      ddbl = 1.0;     ddbl /= 10.0;      return  ddbl; } 

compilation

gcc -s first.c gcc -c first.s gcc -ffast-math -s second.c gcc -ffast-math -c second.s gcc -o prog first.o second.o 

check difference between first.s , second.s , you'll find this:

movapd  %xmm1, %xmm2 divsd   %xmm0, %xmm2 movapd  %xmm2, %xmm0 

changes this:

mulsd   %xmm1, %xmm0 

both functions called, , both return expected result.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -