Use GCC's builtins for generating NaNs.

This commit is contained in:
Thomas Schwinge 2013-02-28 22:30:18 +01:00
parent 64d063b800
commit 777b0332c0
4 changed files with 44 additions and 73 deletions

View File

@ -1,5 +1,21 @@
2013-03-15 Thomas Schwinge <thomas@codesourcery.com> 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. * math/libm-test.inc (acosh_test): Also test with qNaN input.
(sqrt_test): Remove duplicate test with qNaN input. (sqrt_test): Remove duplicate test with qNaN input.
(lrint_test, llrint_test, lround_test, llround_test, rint_test) (lrint_test, llrint_test, lround_test, llround_test, rint_test)

View File

@ -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 \ static void \
NAME (void) \ NAME (void) \
{ \ { \
@ -43,7 +43,7 @@ NAME (void) \
\ \
zero_var = 0.0; \ zero_var = 0.0; \
one_var = 1.0; \ one_var = 1.0; \
qNaN_var = zero_var / zero_var; \ qNaN_var = __builtin_nan ## SUFFIX (""); \
Inf_var = one_var / zero_var; \ Inf_var = one_var / zero_var; \
\ \
(void) &zero_var; \ (void) &zero_var; \
@ -80,11 +80,12 @@ NAME (void) \
/* \ /* \
And again with the value returned by the `nan' function. \ And again with the value returned by the `nan' function. \
*/ \ */ \
check (#FLOAT " isnan (nan (\"\"))", isnan (NANFUNC (""))); \ check (#FLOAT " isnan (nan (\"\"))", isnan (nan ## SUFFIX (""))); \
check (#FLOAT " isnan (-nan (\"\"))", isnan (-NANFUNC (""))); \ check (#FLOAT " isnan (-nan (\"\"))", isnan (-nan ## SUFFIX (""))); \
check (#FLOAT " !isinf (nan (\"\"))", !(isinf (NANFUNC ("")))); \ check (#FLOAT " !isinf (nan (\"\"))", !(isinf (nan ## SUFFIX ("")))); \
check (#FLOAT " !isinf (-nan (\"\"))", !(isinf (-NANFUNC ("")))); \ check (#FLOAT " !isinf (-nan (\"\"))", !(isinf (-nan ## SUFFIX ("")))); \
check (#FLOAT " nan (\"\") != nan (\"\")", NANFUNC ("") != NANFUNC ("")); \ check (#FLOAT " nan (\"\") != nan (\"\")", \
nan ## SUFFIX ("") != nan ## SUFFIX ("")); \
\ \
/* test if EPSILON is ok */ \ /* test if EPSILON is ok */ \
x1 = 1.0; \ x1 = 1.0; \
@ -102,7 +103,7 @@ NAME (void) \
check (#FLOAT " isinf (-HUGE_VALx) == -1", isinf (x1) == -1); \ check (#FLOAT " isinf (-HUGE_VALx) == -1", isinf (x1) == -1); \
} }
#define TEST_TRUNC(NAME, FLOAT, DOUBLE) \ #define TEST_TRUNC(NAME, FLOAT, DOUBLE, SUFFIX) \
void \ void \
NAME (void) \ NAME (void) \
{ \ { \
@ -111,7 +112,7 @@ NAME (void) \
\ \
zero_var = 0.0; \ zero_var = 0.0; \
one_var = 1.0; \ one_var = 1.0; \
qNaN_var = zero_var / zero_var; \ qNaN_var = __builtin_nan ## SUFFIX (""); \
Inf_var = one_var / zero_var; \ Inf_var = one_var / zero_var; \
\ \
(void) &qNaN_var; \ (void) &qNaN_var; \
@ -123,13 +124,13 @@ NAME (void) \
check (" "#FLOAT" x = ("#FLOAT") ("#DOUBLE") Inf", isinf (x2) != 0); \ check (" "#FLOAT" x = ("#FLOAT") ("#DOUBLE") Inf", isinf (x2) != 0); \
} }
TEST_FUNC (float_test, float, nanf, FLT_EPSILON, HUGE_VALF) TEST_FUNC (float_test, float, f, FLT_EPSILON, HUGE_VALF)
TEST_FUNC (double_test, double, nan, DBL_EPSILON, HUGE_VAL) TEST_FUNC (double_test, double, , DBL_EPSILON, HUGE_VAL)
TEST_TRUNC (truncdfsf_test, float, double) TEST_TRUNC (truncdfsf_test, float, double, )
#ifndef NO_LONG_DOUBLE #ifndef NO_LONG_DOUBLE
TEST_FUNC (ldouble_test, long double, nanl, LDBL_EPSILON, HUGE_VALL) TEST_FUNC (ldouble_test, long double, l, LDBL_EPSILON, HUGE_VALL)
TEST_TRUNC (trunctfsf_test, float, long double) TEST_TRUNC (trunctfsf_test, float, long double, l)
TEST_TRUNC (trunctfdf_test, double, long double) TEST_TRUNC (trunctfdf_test, double, long double, l)
#endif #endif
int int

View File

@ -10626,10 +10626,10 @@ static void
initialize (void) initialize (void)
{ {
fpstack_test ("start *init*"); 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, plus_infty = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF,
HUGE_VALL, HUGE_VAL, HUGE_VALF); HUGE_VALL, HUGE_VAL, HUGE_VALF);
minus_infty = CHOOSE (-HUGE_VALL, -HUGE_VAL, -HUGE_VALF, minus_infty = CHOOSE (-HUGE_VALL, -HUGE_VAL, -HUGE_VALF,

View File

@ -34,56 +34,10 @@ char *dest_address;
double value = 123.456; double value = 123.456;
double zero = 0.0; double zero = 0.0;
float SNANf;
double SNAN;
long double SNANl;
static sigjmp_buf sigfpe_buf; 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; typedef long double ldouble;
static ldouble
snan_ldouble (void)
{
return SNANl;
}
void void
myFPsighandler(int signal, 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 \ static void \
NAME (void) \ NAME (void) \
{ \ { \
/* Variables are declared volatile to forbid some compiler \ /* Variables are declared volatile to forbid some compiler \
optimizations. */ \ 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; \ fenv_t saved_fenv; \
\ \
zero_var = 0.0; \ zero_var = 0.0; \
one_var = 1.0; \ one_var = 1.0; \
qNaN_var = zero_var / zero_var; \ qNaN_var = __builtin_nan ## SUFFIX (""); \
sNaN_var = snan_##FLOAT (); \
Inf_var = one_var / zero_var; \ Inf_var = one_var / zero_var; \
\ \
(void) &zero_var; \ (void) &zero_var; \
@ -358,17 +314,15 @@ NAME (void) \
remove_sigaction_FP(); \ remove_sigaction_FP(); \
} }
TEST_FUNC (float_test, float) TEST_FUNC (float_test, float, f)
TEST_FUNC (double_test, double) TEST_FUNC (double_test, double, )
#ifndef NO_LONG_DOUBLE #ifndef NO_LONG_DOUBLE
TEST_FUNC (ldouble_test, ldouble) TEST_FUNC (ldouble_test, ldouble, l)
#endif #endif
static int static int
do_test (void) do_test (void)
{ {
init_signaling_nan();
float_test(); float_test();
double_test(); double_test();
#ifndef NO_LONG_DOUBLE #ifndef NO_LONG_DOUBLE