http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46080
Summary: incorrect precision of sqrtf builtin for x87
arithmetic (-mfpmath=387)
Product: gcc
Version: 4.4.5
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
AssignedTo: [email protected]
ReportedBy: [email protected]
With -mfpmath=387 (tested on a x86_64 platform), the first sqrtf is computed in
double precision instead of single. On
#include <stdio.h>
#include <math.h>
float x = (float) M_PI;
int main(void)
{
printf ("%.60f\n", sqrtf(x));
printf ("%.60f\n", sqrtf(x));
printf ("%.60f\n", sqrtf(x));
return 0;
}
I get with various gcc versions (including gcc version 4.6.0 20101009
(experimental) [trunk revision 165234] (Debian 20101009-1)):
$ gcc -Wall -mfpmath=387 bug.c -o bug -lm -O0; ./bug
1.772453875567026715387441981874871999025344848632812500000000
1.772453904151916503906250000000000000000000000000000000000000
1.772453904151916503906250000000000000000000000000000000000000
The bug is also present with -O1 when the sqrtf calls are grouped in a single
printf and disappears if the builtin is disabled with -fno-builtin-sqrtf.
For the first sqrtf, the asm code shows a fsqrt followed by a "call sqrtf"
under some condition, but the condition is not satisfied. The other occurrences
just have a "call sqrtf", which is correct.