Subject: FPU test on RedHat7.1

From: Carsten Langgaard <[email-masked]>
Date: Thu, 22 Nov 2001 16:37:11 +0100

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-masked]
|\  /|||___)(___   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);

}

---

From: "H . J . Lu" <[email-masked]>
Date: Thu, 22 Nov 2001 10:39:30 -0800

> g++ -o fpu_test fpu_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.

---

From: Carsten Langgaard <[email-masked]>
Date: Fri, 23 Nov 2001 15:54:31 +0100

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

/* @(#)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;
}

---

From: "H . J . Lu" <[email-masked]>
Date: Sat, 24 Nov 2001 11:25:47 -0800

> I have attached the glibc-2.2.2 remainder file, which seems to work

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.

---

From: Carsten Langgaard <[email-masked]>
Date: Mon, 26 Nov 2001 10:22:40 +0100

> and expects -1.9958403095e+292. However, on mips, I got -inf. Could you

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.

>
> Thanks.
>
> H.J.
>
>   ------------------------------------------------------------------------
>
>    ieee.cName: ieee.c
>          Type: Plain Text (text/plain)