[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MiNT] GCC Fast Math



Hello.

I have discovered a "new" GCC compilation option: -ffast-math
The documentation is here:
http://gcc.gnu.org/onlinedocs/gcc-4.5.2/gcc/Optimize-Options.html#index-ffast_002dmath-811

Normally, the math functions like sqrt(), sin()... are implemented inside libm.a. They do their job and handle correctly the error cases by setting errno, etc.

The -ffast-math option inlines for example sqrt() to a single FPU instruction, without any library call. The drawback is that errno is not set, so it is a violation of the C standard. However most programs are OK with that, including POV-Ray.

The job is math-68881.h was similar. But instead of relying on GCC's internals (like -ffast-math), magic is done through inline assembler. GCC is not optimal on register usage when transferring data from C to inline assembler. As a result, the code produced by -ffast-math is a bit better.

So I have totally disabled the usage of math-68881.h in math.h. Using explicitly -ffast-math should do a better job.

I have built several versions of POV-Ray using -m68020-60, and thanks to Jean-François Lemaire and Guillaume Tello, I got some bench results from a CT60/100 MHz. Surprisingly, the performance is almost the same on all versions. Maybe the overhead of a function call is insignificant compared to the execution time of an FPU instruction ? Well, now gprof is fixed, we could do some profiling to understand things better :-)

Anyway, those math options don't seem to affect the speed significantly, so don't bother with them.

NB: I'm going to send my math-68881.h patch for C99 to GCC people, and I will also ask them if that file can really be useful for someone nowadays.

--
Vincent Rivière