[Bug optimization/13958] New: Conversion from unsigned to double is painfully slow on P4
reichelt at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Sun Feb 1 14:11:00 GMT 2004
Conversion from unsigned to double is painfully slow on P4.
(I don't know whether other x86 architectures are affected as well.)
Just consider the following program:
==================================================
unsigned a[2]={1,2};
inline unsigned foo1(int i) { return a[i]; }
inline int foo2(int i) { return a[i]; }
int main()
{
double x=0;
int i;
for ( i=0; i<100000000; ++i )
x+=foo1(i%2);
return (int)x;
}
==================================================
Compiled with "-O2" the program executes in about 2s on a 3 GHz P4.
If I use "foo2" instead of "foo1" in the argument of "x+=",
the execution time drops by a factor of 10 to 0.2s!
This happens with all versions since gcc 2.95.x.
Looking at the assembler it seems that we convert the unsigned to a
long long variable which is then converted to a double:
xorl %edx, %edx
pushl %edx
pushl %eax
fildll (%esp)
Maybe even using only "fildl" and adding the double constant 2^32 later
to the result if the highest bit of the operand was set might be faster.
Btw, such conversions are quite common in numerical codes that deal
with uniform grids: the array index can be used as a coordinate (usually
after some trivial scaling). Given that the indices used in libstdc++
are usually of the type size_t the slow conversion can have quite a
negative performance impact.
--
Summary: Conversion from unsigned to double is painfully slow on
P4
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Keywords: pessimizes-code
Severity: normal
Priority: P2
Component: optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: reichelt at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13958
More information about the Gcc-bugs
mailing list