From ea1addb6b13a0c1fd02869eb71cbfa434c10cf47 Mon Sep 17 00:00:00 2001 From: ghazi Date: Tue, 16 Jun 2009 04:30:46 +0000 Subject: [PATCH] * gcc.dg/torture/builtin-math-6.c: Robustify and fix clog cases. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@148511 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/testsuite/ChangeLog | 4 ++ gcc/testsuite/gcc.dg/torture/builtin-math-6.c | 78 ++++++++++++++++----------- 2 files changed, 51 insertions(+), 31 deletions(-) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b1587fe..62874a7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2009-06-16 Kaveh R. Ghazi + + * gcc.dg/torture/builtin-math-6.c: Robustify and fix clog cases. + 2009-06-15 Jakub Jelinek * gcc.dg/builtin-object-size-7.c: New test. diff --git a/gcc/testsuite/gcc.dg/torture/builtin-math-6.c b/gcc/testsuite/gcc.dg/torture/builtin-math-6.c index 636381f..7fd1f72 100644 --- a/gcc/testsuite/gcc.dg/torture/builtin-math-6.c +++ b/gcc/testsuite/gcc.dg/torture/builtin-math-6.c @@ -11,57 +11,73 @@ /* All references to link_error should go away at compile-time. */ extern void link_error(int); -/* Return TRUE if the sign of X != sign of Y. This is important when - comparing signed zeros. */ +/* Return TRUE if the signs of floating point values X and Y are not + equal. This is important when comparing signed zeros. */ #define CKSGN_F(X,Y) \ - (__builtin_copysignf(1.0F,(X)) != __builtin_copysignf(1.0F,(Y))) + (__builtin_copysignf(1,(X)) != __builtin_copysignf(1,(Y))) #define CKSGN(X,Y) \ - (__builtin_copysign(1.0,(X)) != __builtin_copysign(1.0,(Y))) + (__builtin_copysign(1,(X)) != __builtin_copysign(1,(Y))) #define CKSGN_L(X,Y) \ - (__builtin_copysignl(1.0L,(X)) != __builtin_copysignl(1.0L,(Y))) + (__builtin_copysignl(1,(X)) != __builtin_copysignl(1,(Y))) + +/* Return TRUE if signs of the real parts, and the signs of the + imaginary parts, of X and Y are not equal. */ +#define COMPLEX_CKSGN_F(X,Y) \ + (CKSGN_F(__real__ (X), __real__ (Y)) || CKSGN_F (__imag__ (X), __imag__ (Y))) +#define COMPLEX_CKSGN(X,Y) \ + (CKSGN(__real__ (X), __real__ (Y)) || CKSGN (__imag__ (X), __imag__ (Y))) +#define COMPLEX_CKSGN_L(X,Y) \ + (CKSGN_L(__real__ (X), __real__ (Y)) || CKSGN_L (__imag__ (X), __imag__ (Y))) /* For complex numbers, test that FUNC(ARG) == (RES). */ #define TESTIT_COMPLEX(FUNC, ARG, RES) do { \ if (__builtin_##FUNC##f(ARG) != (RES) \ - || CKSGN_F(__real__ __builtin_##FUNC##f(ARG), __real__ (RES)) \ - || CKSGN_F(__imag__ __builtin_##FUNC##f(ARG), __imag__ (RES))) \ + || COMPLEX_CKSGN_F(__builtin_##FUNC##f(ARG), (RES))) \ link_error(__LINE__); \ if (__builtin_##FUNC(ARG) != (RES) \ - || CKSGN(__real__ __builtin_##FUNC(ARG), __real__ (RES)) \ - || CKSGN(__imag__ __builtin_##FUNC(ARG), __imag__ (RES))) \ + || COMPLEX_CKSGN(__builtin_##FUNC(ARG), (RES))) \ link_error(__LINE__); \ if (__builtin_##FUNC##l(ARG) != (RES) \ - || CKSGN_L(__real__ __builtin_##FUNC##l(ARG), __real__ (RES)) \ - || CKSGN_L(__imag__ __builtin_##FUNC##l(ARG), __imag__ (RES))) \ + || COMPLEX_CKSGN_L(__builtin_##FUNC##l(ARG), (RES))) \ link_error(__LINE__); \ } while (0) +/* Return TRUE if X differs from EXPECTED by more than 1%. If + EXPECTED is zero, then any difference may return TRUE. We don't + worry about signed zeros. */ +#define DIFF1PCT_F(X,EXPECTED) \ + (__builtin_fabsf((X)-(EXPECTED)) * 100 > __builtin_fabsf(EXPECTED)) +#define DIFF1PCT(X,EXPECTED) \ + (__builtin_fabs((X)-(EXPECTED)) * 100 > __builtin_fabs(EXPECTED)) +#define DIFF1PCT_L(X,EXPECTED) \ + (__builtin_fabsl((X)-(EXPECTED)) * 100 > __builtin_fabsl(EXPECTED)) + +/* Return TRUE if complex value X differs from EXPECTED by more than + 1% in either the real or imaginary parts. */ +#define COMPLEX_DIFF1PCT_F(X,EXPECTED) \ + (DIFF1PCT_F(__real__ (X), __real__ (EXPECTED)) \ + || DIFF1PCT_F(__imag__ (X), __imag__ (EXPECTED))) +#define COMPLEX_DIFF1PCT(X,EXPECTED) \ + (DIFF1PCT(__real__ (X), __real__ (EXPECTED)) \ + || DIFF1PCT(__imag__ (X), __imag__ (EXPECTED))) +#define COMPLEX_DIFF1PCT_L(X,EXPECTED) \ + (DIFF1PCT_L(__real__ (X), __real__ (EXPECTED)) \ + || DIFF1PCT_L(__imag__ (X), __imag__ (EXPECTED))) + /* Range test, for complex numbers check that FUNC(ARG) is within 1% of RES. This is NOT a test for accuracy to the last-bit, we're merely checking that we get relatively sane results. I.e. the GCC builtin is hooked up to the correct MPC function call. We first check the magnitude and then the sign. */ #define TESTIT_COMPLEX_R(FUNC, ARG, RES) do { \ - if (__builtin_fabsf(__real__ __builtin_##FUNC##f(ARG)) < __builtin_fabsf(__real__ (RES)) * 0.99F \ - || __builtin_fabsf(__real__ __builtin_##FUNC##f(ARG)) > __builtin_fabsf(__real__ (RES)) * 1.01F \ - || __builtin_fabsf(__imag__ __builtin_##FUNC##f(ARG)) < __builtin_fabsf(__imag__ (RES)) * 0.99F \ - || __builtin_fabsf(__imag__ __builtin_##FUNC##f(ARG)) > __builtin_fabsf(__imag__ (RES)) * 1.01F \ - || CKSGN_F(__real__ __builtin_##FUNC##f(ARG), __real__ (RES)) \ - || CKSGN_F(__imag__ __builtin_##FUNC##f(ARG), __imag__ (RES))) \ + if (COMPLEX_DIFF1PCT_F (__builtin_##FUNC##f(ARG), (RES)) \ + || COMPLEX_CKSGN_F(__builtin_##FUNC##f(ARG), (RES))) \ link_error(__LINE__); \ - if (__builtin_fabs(__real__ __builtin_##FUNC(ARG)) < __builtin_fabs(__real__ (RES)) * 0.99F \ - || __builtin_fabs(__real__ __builtin_##FUNC(ARG)) > __builtin_fabs(__real__ (RES)) * 1.01F \ - || __builtin_fabs(__imag__ __builtin_##FUNC(ARG)) < __builtin_fabs(__imag__ (RES)) * 0.99F \ - || __builtin_fabs(__imag__ __builtin_##FUNC(ARG)) > __builtin_fabs(__imag__ (RES)) * 1.01F \ - || CKSGN(__real__ __builtin_##FUNC(ARG), __real__ (RES)) \ - || CKSGN(__imag__ __builtin_##FUNC(ARG), __imag__ (RES))) \ + if (COMPLEX_DIFF1PCT (__builtin_##FUNC(ARG), (RES)) \ + || COMPLEX_CKSGN(__builtin_##FUNC(ARG), (RES))) \ link_error(__LINE__); \ - if (__builtin_fabsl(__real__ __builtin_##FUNC##l(ARG)) < __builtin_fabsl(__real__ (RES)) * 0.99F \ - || __builtin_fabsl(__real__ __builtin_##FUNC##l(ARG)) > __builtin_fabsl(__real__ (RES)) * 1.01F \ - || __builtin_fabsl(__imag__ __builtin_##FUNC##l(ARG)) < __builtin_fabsl(__imag__ (RES)) * 0.99F \ - || __builtin_fabsl(__imag__ __builtin_##FUNC##l(ARG)) > __builtin_fabsl(__imag__ (RES)) * 1.01F \ - || CKSGN_L(__real__ __builtin_##FUNC##l(ARG), __real__ (RES)) \ - || CKSGN_L(__imag__ __builtin_##FUNC##l(ARG), __imag__ (RES))) \ + if (COMPLEX_DIFF1PCT (__builtin_##FUNC(ARG), (RES)) \ + || COMPLEX_CKSGN(__builtin_##FUNC(ARG), (RES))) \ link_error(__LINE__); \ } while (0) @@ -129,8 +145,8 @@ int main (void) TESTIT_COMPLEX (clog, 1.0F, 0.0F); TESTIT_COMPLEX_R (clog, -1.0F, 3.141593FI); - TESTIT_COMPLEX (clog, __builtin_conjf(1.0F), 0.0F); - TESTIT_COMPLEX_R (clog, __builtin_conjf(-1.0F), 3.141593FI); + TESTIT_COMPLEX (clog, __builtin_conjf(1.0F), __builtin_conjf(0.0F)); /* Fails with mpc-0.6. */ + TESTIT_COMPLEX_R (clog, __builtin_conjf(-1.0F), __builtin_conjf(3.141593FI)); /* Fails with mpc-0.6. */ TESTIT_COMPLEX_R (clog, 3.45678F + 2.34567FI, 1.429713F + 0.596199FI); TESTIT_COMPLEX_R (clog, 3.45678F - 2.34567FI, 1.429713F - 0.596199FI); -- 2.7.4