[vox-tech] gcc questions: inline and -ffast-math
Josh Parsons
jbparsons at ucdavis.edu
Mon Jan 17 09:20:49 PST 2005
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.
> Second question: Is there any point in declaring functions as inline:
> if I use the -O3 or -finline-functions gcc options?
Yes, because you might have a better idea than gcc's built-in heuristics
which of your functions is called frequently enough to justify inlining.
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.
--
Josh Parsons
Philosophy Department
1238 Social Sciences and Humanities Bldg.
University of California
Davis, CA 95616-8673
USA
Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
More information about the vox-tech
mailing list