This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: i386 rounding modes and workaround solution
- To: Han-Kwang Nienhuys <h dot nienhuys at amolf dot nl>
- Subject: Re: i386 rounding modes and workaround solution
- From: Jan Hubicka <jh at suse dot cz>
- Date: Mon, 10 Sep 2001 16:53:20 +0200
- Cc: gcc at gcc dot gnu dot org
- References: <20010910164752.A3429@vd5.amolf.nl>
> I recently found out that
>
> 1. converting float or double to int in gcc or g++ on an x86 platform
> is incredebly slow
This is considerably faster in the development branch. Gcc now avoids
the redundant control word stores (but still does fldcw, that is resonably
cheap) and an memory mismatch stall is elliminated.
>
> 2. the functions floor(), ceil() in glibc math.h are incredibly slow as
> well.
:(
>
> Point 1 is documented somewhere on a 'known deficiencies list' for
> gcc; I didn't find much about point 2 on the web. This issue has
> appeared several times on gnu mailing list, but without a practical
> solution.
The conclusion is that if you want fast converison and you don't worry
about rounding, you can use rint, implemented as inline assembly doing
fist directly.
We can add this pattern to the gcc itself to allow scheduling for better
performance.
>
> The cause is that the program code must change the rounding mode of
> the floating-point unit with the FLDCW instruction, which is very
> slow. Note that the libc function double rint(double) defined in
> <math.h> is supposed to round according to current rounding mode, but
> is - in my version of glibc (2.2.0) implemented as a function call
> instead of an inline function, which is not very efficient either.
Thats bad, but glibc issue, so you need to ask there.
> I am not very experienced in assembler, nor do I read this list. Send
> any comments directly to my email address.
The code looks OK, except that if you want to use it in header, the declarations
should be "extern inline" (see gcc manual for the description).
Honza