Commit dee6f575 by Kaveh R. Ghazi Committed by Kaveh Ghazi

builtin-math-6.c: Robustify and fix clog cases.

	* gcc.dg/torture/builtin-math-6.c: Robustify and fix clog cases.

From-SVN: r148511
parent 9a3fb03e
2009-06-16 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* gcc.dg/torture/builtin-math-6.c: Robustify and fix clog cases.
2009-06-15 Jakub Jelinek <jakub@redhat.com> 2009-06-15 Jakub Jelinek <jakub@redhat.com>
* gcc.dg/builtin-object-size-7.c: New test. * gcc.dg/builtin-object-size-7.c: New test.
......
...@@ -11,57 +11,73 @@ ...@@ -11,57 +11,73 @@
/* All references to link_error should go away at compile-time. */ /* All references to link_error should go away at compile-time. */
extern void link_error(int); extern void link_error(int);
/* Return TRUE if the sign of X != sign of Y. This is important when /* Return TRUE if the signs of floating point values X and Y are not
comparing signed zeros. */ equal. This is important when comparing signed zeros. */
#define CKSGN_F(X,Y) \ #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) \ #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) \ #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). */ /* For complex numbers, test that FUNC(ARG) == (RES). */
#define TESTIT_COMPLEX(FUNC, ARG, RES) do { \ #define TESTIT_COMPLEX(FUNC, ARG, RES) do { \
if (__builtin_##FUNC##f(ARG) != (RES) \ if (__builtin_##FUNC##f(ARG) != (RES) \
|| CKSGN_F(__real__ __builtin_##FUNC##f(ARG), __real__ (RES)) \ || COMPLEX_CKSGN_F(__builtin_##FUNC##f(ARG), (RES))) \
|| CKSGN_F(__imag__ __builtin_##FUNC##f(ARG), __imag__ (RES))) \
link_error(__LINE__); \ link_error(__LINE__); \
if (__builtin_##FUNC(ARG) != (RES) \ if (__builtin_##FUNC(ARG) != (RES) \
|| CKSGN(__real__ __builtin_##FUNC(ARG), __real__ (RES)) \ || COMPLEX_CKSGN(__builtin_##FUNC(ARG), (RES))) \
|| CKSGN(__imag__ __builtin_##FUNC(ARG), __imag__ (RES))) \
link_error(__LINE__); \ link_error(__LINE__); \
if (__builtin_##FUNC##l(ARG) != (RES) \ if (__builtin_##FUNC##l(ARG) != (RES) \
|| CKSGN_L(__real__ __builtin_##FUNC##l(ARG), __real__ (RES)) \ || COMPLEX_CKSGN_L(__builtin_##FUNC##l(ARG), (RES))) \
|| CKSGN_L(__imag__ __builtin_##FUNC##l(ARG), __imag__ (RES))) \
link_error(__LINE__); \ link_error(__LINE__); \
} while (0) } 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% /* 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 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 merely checking that we get relatively sane results. I.e. the GCC
builtin is hooked up to the correct MPC function call. We first builtin is hooked up to the correct MPC function call. We first
check the magnitude and then the sign. */ check the magnitude and then the sign. */
#define TESTIT_COMPLEX_R(FUNC, ARG, RES) do { \ #define TESTIT_COMPLEX_R(FUNC, ARG, RES) do { \
if (__builtin_fabsf(__real__ __builtin_##FUNC##f(ARG)) < __builtin_fabsf(__real__ (RES)) * 0.99F \ if (COMPLEX_DIFF1PCT_F (__builtin_##FUNC##f(ARG), (RES)) \
|| __builtin_fabsf(__real__ __builtin_##FUNC##f(ARG)) > __builtin_fabsf(__real__ (RES)) * 1.01F \ || COMPLEX_CKSGN_F(__builtin_##FUNC##f(ARG), (RES))) \
|| __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))) \
link_error(__LINE__); \ link_error(__LINE__); \
if (__builtin_fabs(__real__ __builtin_##FUNC(ARG)) < __builtin_fabs(__real__ (RES)) * 0.99F \ if (COMPLEX_DIFF1PCT (__builtin_##FUNC(ARG), (RES)) \
|| __builtin_fabs(__real__ __builtin_##FUNC(ARG)) > __builtin_fabs(__real__ (RES)) * 1.01F \ || COMPLEX_CKSGN(__builtin_##FUNC(ARG), (RES))) \
|| __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))) \
link_error(__LINE__); \ link_error(__LINE__); \
if (__builtin_fabsl(__real__ __builtin_##FUNC##l(ARG)) < __builtin_fabsl(__real__ (RES)) * 0.99F \ if (COMPLEX_DIFF1PCT (__builtin_##FUNC(ARG), (RES)) \
|| __builtin_fabsl(__real__ __builtin_##FUNC##l(ARG)) > __builtin_fabsl(__real__ (RES)) * 1.01F \ || COMPLEX_CKSGN(__builtin_##FUNC(ARG), (RES))) \
|| __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))) \
link_error(__LINE__); \ link_error(__LINE__); \
} while (0) } while (0)
...@@ -129,8 +145,8 @@ int main (void) ...@@ -129,8 +145,8 @@ int main (void)
TESTIT_COMPLEX (clog, 1.0F, 0.0F); TESTIT_COMPLEX (clog, 1.0F, 0.0F);
TESTIT_COMPLEX_R (clog, -1.0F, 3.141593FI); TESTIT_COMPLEX_R (clog, -1.0F, 3.141593FI);
TESTIT_COMPLEX (clog, __builtin_conjf(1.0F), 0.0F); TESTIT_COMPLEX (clog, __builtin_conjf(1.0F), __builtin_conjf(0.0F)); /* Fails with mpc-0.6. */
TESTIT_COMPLEX_R (clog, __builtin_conjf(-1.0F), 3.141593FI); 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);
TESTIT_COMPLEX_R (clog, 3.45678F - 2.34567FI, 1.429713F - 0.596199FI); TESTIT_COMPLEX_R (clog, 3.45678F - 2.34567FI, 1.429713F - 0.596199FI);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment