about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThomas Schwinge <thomas@codesourcery.com>2013-02-28 22:30:18 +0100
committerThomas Schwinge <thomas@codesourcery.com>2013-03-15 19:10:20 +0100
commit777b0332c0598ebba46685b41ea5846640751c19 (patch)
treee778f11d315ede62106259a283e621f05d18a500
parent64d063b80005674a856ae4fee638a739137f6775 (diff)
downloadglibc-777b0332c0598ebba46685b41ea5846640751c19.tar.gz
glibc-777b0332c0598ebba46685b41ea5846640751c19.tar.xz
glibc-777b0332c0598ebba46685b41ea5846640751c19.zip
Use GCC's builtins for generating NaNs.
-rw-r--r--ChangeLog16
-rw-r--r--math/basic-test.c31
-rw-r--r--math/libm-test.inc6
-rw-r--r--sysdeps/powerpc/fpu/test-powerpc-snan.c64
4 files changed, 44 insertions, 73 deletions
diff --git a/ChangeLog b/ChangeLog
index 553da36738..6f751d4607 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2013-03-15  Thomas Schwinge  <thomas@codesourcery.com>
 
+	* math/basic-test.c (TEST_FUNC): Replace NANFUNC argument with
+	SUFFIX.  Initialize qNaN_var with __builtin_nan family of
+	functions.
+	(TEST_TRUNC): Add SUFFIX argument.  Initialize qNaN_var with
+	__builtin_nan family of functions.
+	* math/libm-test.inc (initialize): Initialize qnan_value with
+	__builtin_nan family of functions.
+	* sysdeps/powerpc/fpu/test-powerpc-snan.c (SNANf, SNAN, SNANl):
+	Remove variables.
+	(init_signaling_nan, snan_float, snan_double, snan_ldouble):
+	Remove functions.
+	(TEST_FUNC): Add SUFFIX argument.  Move sNaN_var into static
+	storage class.  Initialize qNaN_var and sNaN_var with
+	__builtin_nan and __builtin_nans families of functions,
+	respectively.
+
 	* math/libm-test.inc (acosh_test): Also test with qNaN input.
 	(sqrt_test): Remove duplicate test with qNaN input.
 	(lrint_test, llrint_test, lround_test, llround_test, rint_test)
diff --git a/math/basic-test.c b/math/basic-test.c
index 218c9699fb..ffead2ec0f 100644
--- a/math/basic-test.c
+++ b/math/basic-test.c
@@ -32,7 +32,7 @@ check (const char *testname, int result)
   }
 }
 
-#define TEST_FUNC(NAME, FLOAT, NANFUNC, EPSILON, HUGEVAL)		      \
+#define TEST_FUNC(NAME, FLOAT, SUFFIX, EPSILON, HUGEVAL)		      \
 static void								      \
 NAME (void)								      \
 {									      \
@@ -43,7 +43,7 @@ NAME (void)								      \
 									      \
   zero_var = 0.0;							      \
   one_var = 1.0;							      \
-  qNaN_var = zero_var / zero_var;					      \
+  qNaN_var = __builtin_nan ## SUFFIX ("");				      \
   Inf_var = one_var / zero_var;						      \
 									      \
   (void) &zero_var;							      \
@@ -80,11 +80,12 @@ NAME (void)								      \
   /*									      \
      And again with the value returned by the `nan' function.		      \
    */									      \
-  check (#FLOAT " isnan (nan (\"\"))", isnan (NANFUNC ("")));		      \
-  check (#FLOAT " isnan (-nan (\"\"))", isnan (-NANFUNC ("")));		      \
-  check (#FLOAT " !isinf (nan (\"\"))", !(isinf (NANFUNC (""))));	      \
-  check (#FLOAT " !isinf (-nan (\"\"))", !(isinf (-NANFUNC (""))));	      \
-  check (#FLOAT " nan (\"\") != nan (\"\")", NANFUNC ("") != NANFUNC (""));   \
+  check (#FLOAT " isnan (nan (\"\"))", isnan (nan ## SUFFIX ("")));	      \
+  check (#FLOAT " isnan (-nan (\"\"))", isnan (-nan ## SUFFIX ("")));	      \
+  check (#FLOAT " !isinf (nan (\"\"))", !(isinf (nan ## SUFFIX (""))));	      \
+  check (#FLOAT " !isinf (-nan (\"\"))", !(isinf (-nan ## SUFFIX (""))));     \
+  check (#FLOAT " nan (\"\") != nan (\"\")",				      \
+	 nan ## SUFFIX ("") != nan ## SUFFIX (""));			      \
 									      \
   /* test if EPSILON is ok */						      \
   x1 = 1.0;								      \
@@ -102,7 +103,7 @@ NAME (void)								      \
   check (#FLOAT " isinf (-HUGE_VALx) == -1", isinf (x1) == -1);		      \
 }
 
-#define TEST_TRUNC(NAME, FLOAT, DOUBLE) \
+#define TEST_TRUNC(NAME, FLOAT, DOUBLE, SUFFIX)				      \
 void									      \
 NAME (void)								      \
 {									      \
@@ -111,7 +112,7 @@ NAME (void)								      \
 									      \
   zero_var = 0.0;							      \
   one_var = 1.0;							      \
-  qNaN_var = zero_var / zero_var;					      \
+  qNaN_var = __builtin_nan ## SUFFIX ("");				      \
   Inf_var = one_var / zero_var;						      \
 									      \
   (void) &qNaN_var;							      \
@@ -123,13 +124,13 @@ NAME (void)								      \
   check (" "#FLOAT" x = ("#FLOAT") ("#DOUBLE") Inf", isinf (x2) != 0);	      \
 }
 
-TEST_FUNC (float_test, float, nanf, FLT_EPSILON, HUGE_VALF)
-TEST_FUNC (double_test, double, nan, DBL_EPSILON, HUGE_VAL)
-TEST_TRUNC (truncdfsf_test, float, double)
+TEST_FUNC (float_test, float, f, FLT_EPSILON, HUGE_VALF)
+TEST_FUNC (double_test, double, , DBL_EPSILON, HUGE_VAL)
+TEST_TRUNC (truncdfsf_test, float, double, )
 #ifndef NO_LONG_DOUBLE
-TEST_FUNC (ldouble_test, long double, nanl, LDBL_EPSILON, HUGE_VALL)
-TEST_TRUNC (trunctfsf_test, float, long double)
-TEST_TRUNC (trunctfdf_test, double, long double)
+TEST_FUNC (ldouble_test, long double, l, LDBL_EPSILON, HUGE_VALL)
+TEST_TRUNC (trunctfsf_test, float, long double, l)
+TEST_TRUNC (trunctfdf_test, double, long double, l)
 #endif
 
 int
diff --git a/math/libm-test.inc b/math/libm-test.inc
index ffb781f2b7..00e3d6e7ef 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -10626,10 +10626,10 @@ static void
 initialize (void)
 {
   fpstack_test ("start *init*");
-  plus_zero = 0.0;
-  qnan_value = plus_zero / plus_zero;	/* Suppress GCC warning */
 
-  minus_zero = FUNC(copysign) (0.0, -1.0);
+  plus_zero = 0.0;
+  qnan_value = FUNC (__builtin_nan) ("");
+  minus_zero = FUNC (copysign) (0.0, -1.0);
   plus_infty = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF,
 		       HUGE_VALL, HUGE_VAL, HUGE_VALF);
   minus_infty = CHOOSE (-HUGE_VALL, -HUGE_VAL, -HUGE_VALF,
diff --git a/sysdeps/powerpc/fpu/test-powerpc-snan.c b/sysdeps/powerpc/fpu/test-powerpc-snan.c
index f8b5595d8c..6ec9414e79 100644
--- a/sysdeps/powerpc/fpu/test-powerpc-snan.c
+++ b/sysdeps/powerpc/fpu/test-powerpc-snan.c
@@ -34,56 +34,10 @@ char *dest_address;
 double	value = 123.456;
 double	zero = 0.0;
 
-float SNANf;
-double SNAN;
-long double SNANl;
-
 static sigjmp_buf sigfpe_buf;
 
-void
-init_signaling_nan (void)
-{
-    union {
-	double _ld16;
-	double _d8;
-	unsigned int _ui4[4];
-	float _f4;
-    } nan_temp;
-    
-    nan_temp._ui4[0] = 0x7fa00000;
-    SNANf = nan_temp._f4;
-
-    nan_temp._ui4[0] = 0x7ff40000;
-    nan_temp._ui4[1] = 0x00000000;
-    SNAN = nan_temp._d8;
-
-    nan_temp._ui4[0] = 0x7ff40000;
-    nan_temp._ui4[1] = 0x00000000;
-    nan_temp._ui4[2] = 0x00000000;
-    nan_temp._ui4[3] = 0x00000000;
-    SNANl = nan_temp._ld16;
-}
-
-static float
-snan_float (void)
-{
-  return SNANf;
-}
-
-static double
-snan_double (void)
-{
-  return SNAN;
-}
-
 typedef long double ldouble;
 
-static ldouble
-snan_ldouble (void)
-{
-  return SNANl;
-}
-
 
 void
 myFPsighandler(int signal,
@@ -130,19 +84,21 @@ check (const char *testname, int result)
   }
 }
 
-#define TEST_FUNC(NAME, FLOAT) \
+#define TEST_FUNC(NAME, FLOAT, SUFFIX)					      \
 static void								      \
 NAME (void)								      \
 {									      \
   /* Variables are declared volatile to forbid some compiler		      \
      optimizations.  */							      \
-  volatile FLOAT Inf_var, qNaN_var, zero_var, one_var, sNaN_var;	      \
+  volatile FLOAT Inf_var, qNaN_var, zero_var, one_var;			      \
+  /* A sNaN is only guaranteed to be representable in variables with */	      \
+  /* static (or thread-local) storage duration.  */			      \
+  static volatile FLOAT sNaN_var = __builtin_nans ## SUFFIX ("");	      \
   fenv_t saved_fenv;							      \
 									      \
   zero_var = 0.0;							      \
   one_var = 1.0;							      \
-  qNaN_var = zero_var / zero_var;					      \
-  sNaN_var = snan_##FLOAT ();						      \
+  qNaN_var = __builtin_nan ## SUFFIX ("");				      \
   Inf_var = one_var / zero_var;						      \
 									      \
   (void) &zero_var;							      \
@@ -358,17 +314,15 @@ NAME (void)								      \
   remove_sigaction_FP();						      \
 }
 
-TEST_FUNC (float_test, float)
-TEST_FUNC (double_test, double)
+TEST_FUNC (float_test, float, f)
+TEST_FUNC (double_test, double, )
 #ifndef NO_LONG_DOUBLE
-TEST_FUNC (ldouble_test, ldouble)
+TEST_FUNC (ldouble_test, ldouble, l)
 #endif
 
 static int
 do_test (void)
 {
-  init_signaling_nan();
-
   float_test();
   double_test();
 #ifndef NO_LONG_DOUBLE