This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: fnstcw in simple math functions?


On Wed, Mar 15, 2000 at 02:39:51PM -0800, Michael Vance wrote:
> Why is gcc emitting fnstcw instructions for this simple code? This
> seems like a hopelessly conservative way of maintaining state. I tried
> -ffast-math and got the same results.
> 
> int enclosed_mul( int x, float y )
> {
>     x = static_cast<int>( x * y );
>     return x;
> }
...

This is because conversion from float to int is required to truncate,
but all other math operations are supposed to do round-to-nearest.

It might be interesting to see what kind of code we got if we
pretended that there was no way to put the 387 in truncate mode.  We'd
have to do more math, but fldcw/fnstcw is so slow that it'd probably
come out faster anyway.  Paging Jan Hubicka?

[I see glibc changes the control word in floor().  Bleah.]

zw

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]