i386 rounding modes and workaround solution
Tim Prince
tprince@computer.org
Mon Sep 10 08:24:00 GMT 2001
----- Original Message -----
From: "Han-Kwang Nienhuys" <h.nienhuys@amolf.nl>
To: <gcc@gcc.gnu.org>
Sent: Monday, September 10, 2001 7:47 AM
Subject: i386 rounding modes and workaround solution
> 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 a gross over-simplification, considering that the
conclusion depends so much on which compiler version, which
options, and which CPU model you have. gcc-3.1 has important
improvements. I have not seen an explanation as to why these
operations were made slower in the gcc-3.0 series.
>
> 2. the functions floor(), ceil() in glibc math.h are incredibly
slow as
> well.
>
.....>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.
Check your <bits/mathinline.h> for the conditions under which it
in-lines. If it doesn't do what you wish, modify it, but don't
complain to the gcc list, where most of us have little or no
influence over glibc (or newlib, for that matter).
>
> In a program for numerical calculations, almost all time was
spent in
> a code line similar to
>
> int index = (int) floor(x*inverse_step);
>
> I was able to increase the speed of this program by a factor
4.2 using
> the functions defined below.
If you are familiar with current P4 models, you will be aware
that using more than 2 values of the fldcw mask will degrade
performance seriously. Which processors do you consider as
belonging to the x86 family?
> I am not very experienced in assembler, nor do I read this
list. Send
> any comments directly to my email address.
>
> Han-Kwang Nienhuys
> FOM Institute voor Atomic and Molecular Physics, Amsterdam, The
Netherlands
> http://www.amolf.nl/
>
> ================== start of code ===================
More information about the Gcc
mailing list