[vox-tech] gcc questions: inline and -ffast-math

Peter Jay Salzman p at dirac.org
Mon Jan 17 10:47:02 PST 2005


Hi Josh,

Thanks for such an in-depth answer!


On Mon 17 Jan 05,  9:20 AM, Josh Parsons <jbparsons at ucdavis.edu> said:
> On Mon, 2005-01-17 at 10:45 -0500, Peter Jay Salzman wrote:
> 
> > Given that, I'm interested in the -ffast-math gcc option....
> > OTOH, I need the code to stop if anything becomes "NaN" or "inf".  One "NaN"
> > or "inf" makes the whole calculation garbage, and that could be a waste of 2
> > weeks of computer time.
> 
> -ffast-math turns on a bunch of other optimization and code-gen options,
> some of which you do *not* want.  From the manual:
> 
> "Sets `-fno-math-errno', `-funsafe-math-optimizations', `-fno-trapping-
> math', `-ffinite-math-only', `-fno-rounding-math' and `-fno-signaling-
> nans'."
> 
> Of these, -ffinite-math-only and -funsafe-math-optimizations allow the
> compiler to assume that results and arguments are never NaN or inf.
> 
> In some cases an ISO C compiler is required to generate code that
> prevents an FPE signal being raised.  This sometimes happens where a
> floating point op is represented in C by a library function such as sqrt
> ().  Here, to be conformant with the standard, gcc has to arrange to
> catch any floating point exception and set errno, at a cost in speed. 
> 
> -fno-math-errno prevents this. So you would probably want to use that.
 
Just to make sure I understand:

You're saying that I want to enable -fno-math-errno because I don't care
about or use errno; all the numerical problems that might crop up are being
caught via SIGFPE and reported via siginfo_t info->si_code, and thus, any
extra code that gcc inserts to handle errno is wasted code?

So it sounds like I'd like to replace

   -ffast-math

with:

   -fno-math-errno -fno-trapping-math -fno-rounding-math -fno-signaling-nans

Do you know what a "user visible trap" is?  Is that like an assertion?


> Some more ideas for wringing extra speed out of gcc:  a) I hope you're
> going to run this thing through a profiler.  b) If you're using a PC,
> then -fomit-frame-pointer and judicious use of gcc's regparm function
> attribute could help. c) You can arrange for functions that aren't being
> inlined to be subjected to CSE optimization by using the const and pure
> function attributes.

Holy cow.  You've just given me *hours* of Googling material!   :-P

Pete

-- 
The mathematics of physics has become ever more abstract, rather than more
complicated.  The mind of God appears to be abstract but not complicated.
He also appears to like group theory.  --  Tony Zee's "Fearful Symmetry"

GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E  70A9 A3B9 1945 67EA 951D


More information about the vox-tech mailing list