FPU test on RedHat7.1
The attached tests fails on my RedHat7.1 system, but works fine on my old HardHat5.1.
Anyone got any idea.
compile:
g++ -o fpu_test fpu_test.cc
/Carsten
--
_ _ ____ ___ Carsten Langgaard Mailto:[email protected] |\ /|||___)(___ MIPS Denmark Direct: +45 4486 5527 | \/ ||| ____) Lautrupvang 4B Switch: +45 4486 5555 TECHNOLOGIES 2750 Ballerup Fax...: +45 4486 5556 Denmark http://www.mips.com
#include <math.h>
#include <stdio.h>
int main( int argc,char * argv[ ] )
{
double res;
union {
unsigned long long l;
double d;
} op1, op2;
op1.l = 0x7fefffffffffffff;
op2.l = 0x0000000000000001;
printf("%llx %llx\n", op1.l, op2.l);
res = remainder(op1.d, op2.d);
printf("%llx\n", res);}
Quoted 7 lines · Carsten Langgaard
The attached tests fails on my RedHat7.1 system, but works fine on my old HardHat5.1.
Anyone got any idea.compile:
g++ -ofpu_testfpu_test.cc
Many FPU related tests in the current glibc from CVS failed on MIPS. I am planning to look into them. But I need to find time and docs on MIPS FPU.
H.J.
The file sysdeps/ieee754/dbl-64/e_remainder.c seems to have changed since glibc-2.2.2.
I have attached the glibc-2.2.2 remainder file, which seems to work better.
/Carsten
Quoted 9 lines · H . J . Lu
Quoted 7 lines · Carsten Langgaard
The attached tests fails on my RedHat7.1 system, but works fine on my old HardHat5.1.
Anyone got any idea.compile:
g++ -ofpu_testfpu_test.cc
Quoted 5 lines
Many FPU related tests in the current glibc from CVS failed on MIPS. I am planning to look into them. But I need to find time and docs on MIPS FPU.
H.J.
--
_ _ ____ ___ Carsten Langgaard Mailto:[email protected] |\ /|||___)(___ MIPS Denmark Direct: +45 4486 5527 | \/ ||| ____) Lautrupvang 4B Switch: +45 4486 5555 TECHNOLOGIES 2750 Ballerup Fax...: +45 4486 5556 Denmark http://www.mips.com
/* @(#)e_remainder.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. *
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ==================================================== */
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: e_remainder.c,v 1.8 1995/05/10 20:46:05 jtc Exp $"; #endif
/* __ieee754_remainder(x,p)
* Return :
* returns x REM p = x - [x/p]*p as if in infinite
* precise arithmetic, where [x/p] is the (infinite bit)
* integer nearest x/p (in half way case choose the even one).
* Method :
* Based on fmod() return x-[x/p]chopped*p exactlp.
*/
#include "math.h"
#include "math_private.h"
#ifdef __STDC__
static const double zero = 0.0;
#else
static double zero = 0.0;
#endif
#ifdef __STDC__
double __ieee754_remainder(double x, double p)
#else
double __ieee754_remainder(x,p)
double x,p;
#endif
{
int32_t hx,hp;
u_int32_t sx,lx,lp;
double p_half;
EXTRACT_WORDS(hx,lx,x);
EXTRACT_WORDS(hp,lp,p);
sx = hx&0x80000000;
hp &= 0x7fffffff;
hx &= 0x7fffffff;
/* purge off exception values */
if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */
if((hx>=0x7ff00000)|| /* x not finite */
((hp>=0x7ff00000)&& /* p is NaN */
(((hp-0x7ff00000)|lp)!=0)))
return (x*p)/(x*p);
if (hp<=0x7fdfffff) x = __ieee754_fmod(x,p+p); /* now x < 2p */
if (((hx-hp)|(lx-lp))==0) return zero*x;
x = fabs(x);
p = fabs(p);
if (hp<0x00200000) {
if(x+x>p) {
x-=p;
if(x+x>=p) x -= p;
}
} else {
p_half = 0.5*p;
if(x>p_half) {
x-=p;
if(x>=p_half) x -= p;
}
}
GET_HIGH_WORD(hx,x);
SET_HIGH_WORD(x,hx^sx);
return x;
}Quoted 5 lines · Carsten Langgaard
The file
sysdeps/ieee754/dbl-64/e_remainder.cseems to have changed since glibc-2.2.2.
I have attached the glibc-2.2.2 remainder file, which seems to work better.
I believe it is a MIPS FPU related issue. glibc tries to do
1.7976931348623157e+308 - 8.5720688574901386e+301 * 2097152
and expects -1.9958403095e+292. However, on mips, I got -inf. Could you please look into it?
Thanks.
H.J.
#include <stdio.h>
int main( int argc,char * argv[ ] )
{
double res, d;
union {
unsigned long long l;
double d;
} op1, op2;
op1.l = 0x7fefffffffffffffLL;
op2.l = 0x7ea0000000000000LL;
d = 2097152;
res = op1.d - d * op2.d;
printf("%llx\n", res);
printf("%20.10e\n", res);}
Quoted 7 lines · H . J . Lu
Quoted 5 lines · Carsten Langgaard
The file
sysdeps/ieee754/dbl-64/e_remainder.cseems to have changed since glibc-2.2.2.
I have attached the glibc-2.2.2 remainder file, which seems to work better.
Quoted 6 lines
I believe it is a MIPS FPU related issue. glibc tries to do
1.7976931348623157e+308 - 8.5720688574901386e+301 * 2097152
and expects -1.9958403095e+292. However, on mips, I got -inf. Could you please look into it?
I believe this is ok, 8.5720688574901386e+301 * 2097152 is greater than 1.7976931348623157e+308 (which is the highest floating point number you can represent).
So 1.7976931348623157e+308 - 8.5720688574901386e+301 * 2097152 do give -Inf on (I guess) all other architectures than i386, which have a double extended (80 bit / 64 bit mantisse) precision.
I have tried the same calculation on a Sun (Sparc) and it also gives -Inf. So I guess the problem is in the e_remainder function.
Quoted 9 lines
Thanks.
H.J.
------------------------------------------------------------------------
ieee.cName:
ieee.c
Type: Plain Text (text/plain)
--
_ _ ____ ___ Carsten Langgaard Mailto:[email protected] |\ /|||___)(___ MIPS Denmark Direct: +45 4486 5527 | \/ ||| ____) Lautrupvang 4B Switch: +45 4486 5555 TECHNOLOGIES 2750 Ballerup Fax...: +45 4486 5556 Denmark http://www.mips.com