GCC floating point usage

Richard Earnshaw rearnsha@arm.com
Wed Feb 26 17:41:00 GMT 2003


> Richard Earnshaw <rearnsha@arm.com> writes:
> 
> > I missed the start of the *BSD discussion, but if it's anything like the 
> > one that Mike is referring to that occurred on this list, then the issue 
> > is to discourage (severly) the first use of the floating point registers 
> > when there are no floating point operations in a function; otherwise we 
> > might pay a very large penalty in the kernel for the very first use and 
> > fairly large penalties after each context switch if the kernel switches 
> > the FP context on a lazy basis.
> 
> I'd like to remind everyone that the patch Mike refers to deals with a
> slightly different situation, viz. where use of floating point in an
> unanticipated context causes a correctness failure, not just a
> performance penalty.  Which means...

If correct code requires not using FP regs, then no this won't work.

> 
> > It seems to me that the best solution to this would be to have a new cost 
> > metric that expressed this discouragement directly, maybe 
> > CLASS_FIRST_USE_COST(class) which could then be set to a large value to 
> > express what really happens.  Once the threshold has been crossed the 
> > register allocator would then be free to use the registers as it would 
> > normally.
> 
> ... that, while this is an interesting idea, I'm not convinced it
> would provide a sufficiently ironclad guarantee that floating point
> instructions will _never_ be emitted unless floating point operations
> appear in the same function.  Discouragement is not good enough.
> 
> (Maybe there's a notion of "infinite cost" or something that could be
> applied -- I don't know a whole lot about register classes and costs.)

It would be very useful if the compiler had a flag that in effect meant 
"this code is floating-point free", perhaps -fno-float.  Code with this 
attribute can then (at least on ARM) be linked into both hard- and 
soft-float applications.

The compiler would need to fault any attempt by the user to use 
floating-point data, even in integer registers.

R.



More information about the Gcc-patches mailing list