This is the mail archive of the 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]
Other format: [Raw text]

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);
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


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