This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
fabs() intrinsic totally broken in P4, as of 2002-02-11
- From: "Tom Womack" <tom at womack dot net>
- To: <gcc at gcc dot gnu dot org>
- Cc: "Jan Hubicka" <jh at suse dot cz>
- Date: Sat, 16 Feb 2002 10:08:30 -0000
- Subject: fabs() intrinsic totally broken in P4, as of 2002-02-11
I found this out after half an hour spent staring at some code which had
suddenly broken when compiled with -march=pentium4.
Consider the program
#include <math.h>
#include <stdio.h>
int main(void)
{
double a,b,c;
double d,e,f;
scanf("%lf %lf %lf",&a,&b,&c);
d=fabs(a);e=fabs(b);f=fabs(c);
printf("%f %f %f %f %f %f\n",a,b,c,d,e,f);
return 0;
}
When compiled with -O2 -march=pentium4, the resulting executable takes "-1 2
-3" to "3 3 3". The assembly output carefully loads a, b and c into
xmm5, xmm4 and xmm3 respectively with movsd commands, loads
the magic constant 0x8000000000000000 into xmm0 from the constants
table, and then does
andnpd %xmm3,%xmm0; sets xmm0 to fabs(xmm3)
but then does *nothing* with xmm4 and xmm5, and stores *xmm0* in d, e and f
before the printf call.
ANDN is not a commutative operation, so this strategy would in any case
require lots of reloads of the magic constant; I don't quite see why the
compiler doesn't use the complement of the magic constant and normal AND
instructions.
Tom