[PATCH 4.5 4/N]: Integrate GCC with the complex math library MPC (testsuite)

Kaveh R. GHAZI ghazi@caip.rutgers.edu
Sun Mar 15 16:33:00 GMT 2009


This is the testsuite part of the MPC integration.

I wrote a new "effective target" check to see if MPC is available to avoid
spurious fails on people who don't have the library.  Some of the other
effective target checks for optional stuff look for a gcc driver -f flag
to determine if the feature is available.  There's no such externally
visible feature of MPC.  (Well, maybe the version output of gcc -v.)
Anyway, I had to resort to compiling a constant fold, but it seems bad to
do that.  I.e. if MPC is available and the constant fold crashes for
whatever reason, I think the test will assume MPC does not exist.  Not
what you want.  But I couldn't figure out another way, so I picked the
simplest fold I could think of.  It can be updated later if a better
mechanism is found.

The builtin-math-5.c test checks for cases where folding should not occur,
those kind of tests should pass regardless of whether you have MPC so I
don't use the effective target check there.  I expect to write more cases
for this as time allows.

The builtin-math-6.c test must have MPC, so that one uses the target
check.  This one will be expanded as more functions are added to MPC and
utilized in GCC.

Tested in conjunction with all the previous MPC patches on
x86_64-unknown-linux-gnu with and without MPC, no regressions.  Also, I
get PASS/UNSUPPORTED respectively for builtin-math-6.c and PASS/PASS for
builtin-math-5.c.

Okay for mainline?

BTW, I mean "Okay for *4.5* mainline?", and similarly for all previous MPC
patches, in case that wasn't clear. :-)

		Thanks,
		--Kaveh


2009-03-14  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* gcc.dg/torture/builtin-math-5.c: New.
	* gcc.dg/torture/builtin-math-6.c: New.
	* lib/target-supports.exp (check_effective_target_mpc): New.

diff -rup orig/egcc-SVN20090314/gcc/testsuite/gcc.dg/torture/builtin-math-5.c egcc-SVN20090314/gcc/testsuite/gcc.dg/torture/builtin-math-5.c
--- orig/egcc-SVN20090314/gcc/testsuite/gcc.dg/torture/builtin-math-5.c	2009-03-15 17:23:50.000000000 +0100
+++ egcc-SVN20090314/gcc/testsuite/gcc.dg/torture/builtin-math-5.c	2009-03-15 17:22:35.000000000 +0100
@@ -0,0 +1,46 @@
+/* Copyright (C) 2009  Free Software Foundation.
+
+   Test things that should block GCC from optimizing compile-time
+   constants passed to a builtin complex transcendental functions.
+
+   Origin: Kaveh R. Ghazi,  January 28, 2009.  */
+
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-original" } */
+
+extern void foof (_Complex float);
+extern void foo (_Complex double);
+extern void fool (_Complex long double);
+
+#define TESTIT(FUNC, ARG) do { \
+  foof (__builtin_##FUNC##f (ARG##F)); \
+  foo (__builtin_##FUNC (ARG)); \
+  fool (__builtin_##FUNC##l (ARG##L)); \
+} while (0)
+
+void bar()
+{
+  /* An argument of NaN is not evaluated at compile-time.  */
+#ifndef __SPU__
+  foof (__builtin_csqrtf (__builtin_nanf("")));
+#endif
+  foo (__builtin_csqrt (__builtin_nan("")));
+  fool (__builtin_csqrtl (__builtin_nanl("")));
+
+  /* An argument of Inf/-Inf is not evaluated at compile-time.  */
+#ifndef __SPU__
+  foof (__builtin_csqrtf (__builtin_inff()));
+#endif
+  foo (__builtin_csqrt (__builtin_inf()));
+  fool (__builtin_csqrtl (__builtin_infl()));
+#ifndef __SPU__
+  foof (__builtin_csqrtf (-__builtin_inff()));
+#endif
+  foo (__builtin_csqrt (-__builtin_inf()));
+  fool (__builtin_csqrtl (-__builtin_infl()));
+}
+
+/* { dg-final { scan-tree-dump-times "csqrtf" 3 "original" } } */
+/* { dg-final { scan-tree-dump-times "csqrt " 3 "original" } } */
+/* { dg-final { scan-tree-dump-times "csqrtl" 3 "original" } } */
+/* { dg-final { cleanup-tree-dump "original" } } */
diff -rup orig/egcc-SVN20090314/gcc/testsuite/gcc.dg/torture/builtin-math-6.c egcc-SVN20090314/gcc/testsuite/gcc.dg/torture/builtin-math-6.c
--- orig/egcc-SVN20090314/gcc/testsuite/gcc.dg/torture/builtin-math-6.c	2009-03-15 17:23:53.000000000 +0100
+++ egcc-SVN20090314/gcc/testsuite/gcc.dg/torture/builtin-math-6.c	2009-03-15 17:22:08.000000000 +0100
@@ -0,0 +1,151 @@
+/* Copyright (C) 2009  Free Software Foundation.
+
+   Verify that folding of built-in complex math functions with
+   constant arguments is correctly performed by the compiler.
+
+   Origin: Kaveh R. Ghazi,  January 28, 2009.  */
+
+/* { dg-do link } */
+/* { dg-require-effective-target mpc } */
+
+/* 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.  */
+#define CKSGN_F(X,Y) \
+  (__builtin_copysignf(1.0F,(X)) != __builtin_copysignf(1.0F,(Y)))
+#define CKSGN(X,Y) \
+  (__builtin_copysign(1.0,(X)) != __builtin_copysign(1.0,(Y)))
+#define CKSGN_L(X,Y) \
+  (__builtin_copysignl(1.0L,(X)) != __builtin_copysignl(1.0L,(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))) \
+      link_error(__LINE__); \
+  if (__builtin_##FUNC(ARG) != (RES) \
+    || CKSGN(__real__ __builtin_##FUNC(ARG), __real__ (RES)) \
+    || CKSGN(__imag__ __builtin_##FUNC(ARG), __imag__ (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))) \
+      link_error(__LINE__); \
+  } while (0)
+
+/* 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))) \
+    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))) \
+    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))) \
+    link_error(__LINE__); \
+  } while (0)
+
+int main (void)
+{
+  TESTIT_COMPLEX (csin, 0.0F, 0.0F);
+  TESTIT_COMPLEX (csin, -0.0F, -0.0F);
+  TESTIT_COMPLEX (csin, __builtin_conjf(0.0F), __builtin_conjf(0.0F));
+  TESTIT_COMPLEX (csin, __builtin_conjf(-0.0F), __builtin_conjf(-0.0F));
+
+  TESTIT_COMPLEX_R (csin, 3.45678F + 2.34567FI, -1.633059F - 4.917448FI);
+  TESTIT_COMPLEX_R (csin, 3.45678F - 2.34567FI, -1.633059F + 4.917448FI);
+  TESTIT_COMPLEX_R (csin, -3.45678F + 2.34567FI, 1.633059F - 4.917448FI);
+  TESTIT_COMPLEX_R (csin, -3.45678F - 2.34567FI, 1.633059F + 4.917448FI);
+
+  TESTIT_COMPLEX (ccos, 0.0F, __builtin_conjf(1.0F));
+  TESTIT_COMPLEX (ccos, -0.0F, 1.0F);
+  TESTIT_COMPLEX (ccos, __builtin_conjf(0.0F), 1.0F);
+  TESTIT_COMPLEX (ccos, __builtin_conjf(-0.0F), __builtin_conjf(1.0F));
+
+  TESTIT_COMPLEX_R (ccos, 3.45678F + 2.34567FI, -5.008512F + 1.603367FI);
+  TESTIT_COMPLEX_R (ccos, 3.45678F - 2.34567FI, -5.008512F - 1.603367FI);
+  TESTIT_COMPLEX_R (ccos, -3.45678F + 2.34567FI, -5.008512F - 1.603367FI);
+  TESTIT_COMPLEX_R (ccos, -3.45678F - 2.34567FI, -5.008512F + 1.603367FI);
+
+  TESTIT_COMPLEX (ctan, 0.0F, 0.0F);
+  TESTIT_COMPLEX (ctan, -0.0F, -0.0F);
+  TESTIT_COMPLEX (ctan, __builtin_conjf(0.0F), __builtin_conjf(0.0F));
+  TESTIT_COMPLEX (ctan, __builtin_conjf(-0.0F), __builtin_conjf(-0.0F));
+
+  TESTIT_COMPLEX_R (ctan, 3.45678F + 2.34567FI, 0.010657F + 0.985230FI);
+  TESTIT_COMPLEX_R (ctan, 3.45678F - 2.34567FI, 0.010657F - 0.985230FI);
+  TESTIT_COMPLEX_R (ctan, -3.45678F + 2.34567FI, -0.010657F + 0.985230FI);
+  TESTIT_COMPLEX_R (ctan, -3.45678F - 2.34567FI, -0.010657F - 0.985230FI);
+
+  TESTIT_COMPLEX (csinh, 0.0F, 0.0F);
+  TESTIT_COMPLEX (csinh, -0.0F, -0.0F);
+  TESTIT_COMPLEX (csinh, __builtin_conjf(0.0F), __builtin_conjf(0.0F));
+  TESTIT_COMPLEX (csinh, __builtin_conjf(-0.0F), __builtin_conjf(-0.0F));
+
+  TESTIT_COMPLEX_R (csinh, 3.45678F + 2.34567FI, -11.083178F + 11.341487FI);
+  TESTIT_COMPLEX_R (csinh, 3.45678F - 2.34567FI, -11.083178F - 11.341487FI);
+  TESTIT_COMPLEX_R (csinh, -3.45678F + 2.34567FI, 11.083178F + 11.341487FI);
+  TESTIT_COMPLEX_R (csinh, -3.45678F - 2.34567FI, 11.083178F - 11.341487FI);
+
+  TESTIT_COMPLEX (ccosh, 0.0F, 1.0F);
+  TESTIT_COMPLEX (ccosh, -0.0F, __builtin_conjf(1.0F));
+  TESTIT_COMPLEX (ccosh, __builtin_conjf(0.0F), __builtin_conjf(1.0F));
+  TESTIT_COMPLEX (ccosh, __builtin_conjf(-0.0F), 1.0F);
+
+  TESTIT_COMPLEX_R (ccosh, 3.45678F + 2.34567FI, -11.105238F + 11.318958FI);
+  TESTIT_COMPLEX_R (ccosh, 3.45678F - 2.34567FI, -11.105238F - 11.318958FI);
+  TESTIT_COMPLEX_R (ccosh, -3.45678F + 2.34567FI, -11.105238F - 11.318958FI);
+  TESTIT_COMPLEX_R (ccosh, -3.45678F - 2.34567FI, -11.105238F + 11.318958FI);
+
+  TESTIT_COMPLEX (ctanh, 0.0F, 0.0F);
+  TESTIT_COMPLEX (ctanh, -0.0F, -0.0F);
+  TESTIT_COMPLEX (ctanh, __builtin_conjf(0.0F), __builtin_conjf(0.0F));
+  TESTIT_COMPLEX (ctanh, __builtin_conjf(-0.0F), __builtin_conjf(-0.0F));
+
+  TESTIT_COMPLEX_R (ctanh, 3.45678F + 2.34567FI, 1.000040F - 0.001988FI);
+  TESTIT_COMPLEX_R (ctanh, 3.45678F - 2.34567FI, 1.000040F + 0.001988FI);
+  TESTIT_COMPLEX_R (ctanh, -3.45678F + 2.34567FI, -1.000040F - 0.001988FI);
+  TESTIT_COMPLEX_R (ctanh, -3.45678F - 2.34567FI, -1.000040F + 0.001988FI);
+
+  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_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 + 2.545394FI);
+  TESTIT_COMPLEX_R (clog, -3.45678F - 2.34567FI, 1.429713F - 2.545394FI);
+
+  TESTIT_COMPLEX (csqrt, 0.0F, 0.0F);
+  TESTIT_COMPLEX (csqrt, -0.0F, 0.0F);
+  TESTIT_COMPLEX (csqrt, __builtin_conjf(0.0F), __builtin_conjf(0.0F));
+  TESTIT_COMPLEX (csqrt, __builtin_conjf(-0.0F), __builtin_conjf(0.0F));
+
+  TESTIT_COMPLEX_R (csqrt, 3.45678F + 2.34567FI, 1.953750F + 0.600299FI);
+  TESTIT_COMPLEX_R (csqrt, 3.45678F - 2.34567FI, 1.953750F - 0.600299FI);
+  TESTIT_COMPLEX_R (csqrt, -3.45678F + 2.34567FI, 0.600299F + 1.953750FI);
+  TESTIT_COMPLEX_R (csqrt, -3.45678F - 2.34567FI, 0.600299F - 1.953750FI);
+
+  return 0;
+}
diff -rup orig/egcc-SVN20090314/gcc/testsuite/lib/target-supports.exp egcc-SVN20090314/gcc/testsuite/lib/target-supports.exp
--- orig/egcc-SVN20090314/gcc/testsuite/lib/target-supports.exp	2009-03-04 02:00:38.000000000 +0100
+++ egcc-SVN20090314/gcc/testsuite/lib/target-supports.exp	2009-03-15 17:22:08.000000000 +0100
@@ -2846,3 +2846,16 @@ proc check_effective_target_correct_iso_
 	#endif
     }]
 }
+
+# Return 1 if the MPC library is integrated with GCC, 0 otherwise.
+
+proc check_effective_target_mpc { } {
+    return [check_no_compiler_messages mpc executable {
+	extern void link_error(void);
+	int main ()
+	{
+	  if (__builtin_csin(0) != 0)
+	    link_error();
+	}
+    }]
+}



More information about the Gcc-patches mailing list