-ffast-math + Mesa

Vladimir A. Pavlov pv4 at bk.ru
Sun Sep 3 11:29:30 PDT 2006

AFAIK the main difference between enabling and disabling -ffast-math is 
that if you, for example, call sin() function (or cos(), or tan(), ...) 
in your program the compiler generates a corresponding libc function 
call. In the opposite case (enabled -ffast-math) the compiler inserts 
the assembler instruction (of course, if a given processor supports it) 
rather then function call.

As you understand the result appears sooner in the latter case and 
(theoretically) any 3d program would work faster if compiled with 

On the other hand, the processor instructions know nothing about POSIX 
and other standards so the program compiled with the option cannot rely 
on any standards and especially cannot rely on errno value. That's why 
it isn't recommended to compile the toolchain with -ffast-math.

Besides, if the program contains _only_ the functions that can be 
translated into assembler instructions you need not to link your 
executable with libm.

For example, look at the following:

$ cat >a.c <<EOF
#include <math.h>
#include <errno.h>

int main ()
        volatile double s = sqrt (-1);
        printf ("%d\n", errno);
$ cc a.c -lm
$ ./a.out
$ cc -ffast-math a.c
$ ./a.out
$ uname -p
AMD Athlon(tm) XP 2500+

Nothing but perfection

More information about the hlfs-dev mailing list