This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Pow very slow on x86_64
- From: philippe marguinaud <pmarguinaud at yahoo dot com>
- To: libc-help at sourceware dot org
- Date: Tue, 27 Jan 2009 07:33:44 -0800 (PST)
- Subject: Pow very slow on x86_64
Hi all,
I have some trouble with pow on x86_64. Computing x^r with x close to 1. and r = 0.25 takes ages. The problem does not occur when compiling with -m32 and on x86. Here comes a piece of code:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define N 5000
int main (int argc, char * argv[])
{
double r;
double px[N], py[N];
const double x = 0.9999999999999953371E+00;
int i;
r = atof (argv[1]);
for (i = 0; i < N; i++)
px[i] = x;
printf ("x = %25.19e\nr = %25.19e\n", x, r );
for (i = 0; i < N; i++)
py[i] = pow (px[i], r);
printf ("y = %25.19e\n", py[0]);
return 0;
}
Compiled with:
cc -m64 -O3 -g main.c -o main.x -L /home/philou/tmp/glibc-2.5/build/math -lm
Takes:
time ./main.x 0.25
x = 9.9999999999999533706e-01
r = 2.5000000000000000000e-01
y = 9.9999999999999877875e-01
real 0m11.803s
user 0m11.799s
sys 0m0.002s
While when compiled with -m32:
x = 9.9999999999999533706e-01
r = 2.5000000000000000000e-01
y = 9.9999999999999888978e-01
real 0m0.004s
user 0m0.003s
sys 0m0.001s
Computing x^0.25 with sqrt(sqrt(x)) is also very fast on x86_64.
Something must be wrong with pow. I am using libm-2.5.so and gcc 4.4.0.
What people think ?
Regards,
Philippe