This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH]: PR middle-end/29335 use MPFR for cabs, and fold complex sign ops


On Thu, 25 Jan 2007, Kaveh R. GHAZI wrote:

> On Tue, 23 Jan 2007, Richard Guenther wrote:
>
> > > Okay for mainline?
> >
> > This is ok if you are sufficiently sure about the negate_mathfn_p and
> > fold_strip_sign_ops change.  I think you should add/change the comments
> > before these functions to document the property they guarantee for
> > complex valued functions.

Here's another portion I feel sure about.  I broke out the even/odd
function additions and added a comment in the ccos/ccosh section.  The
negate_mathfn_p already has such a comment at the top describing odd
functions.

I added cproj as an extra to the odd functions, and tweeked the testcases
slightly.

Tested on sparc-sun-solaris2.10, and installed.

		--Kaveh


2007-01-25  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* builtins.c (fold_builtin_1): Treat ccos and ccosh as 'even'
	functions.

	* fold-const.c (negate_mathfn_p): Treat casin, casinh, catan,
	catanh, cproj, csin, csinh, ctan and ctanh as 'odd' functions.

testsuite:
	* gcc.dg/builtins-20.c: Add more cases.
	* gcc.dg/torture/builtin-symmetric-1.c: Likewise.

diff -rup orig/egcc-SVN20070124/gcc/builtins.c egcc-SVN20070124/gcc/builtins.c
--- orig/egcc-SVN20070124/gcc/builtins.c	2007-01-24 23:36:34.000000000 -0500
+++ egcc-SVN20070124/gcc/builtins.c	2007-01-25 10:38:12.713609352 -0500
@@ -9344,6 +9344,18 @@ fold_builtin_1 (tree fndecl, tree arglis
 					TREE_VALUE (arglist)));
       break;

+    CASE_FLT_FN (BUILT_IN_CCOS):
+    CASE_FLT_FN (BUILT_IN_CCOSH):
+      /* These functions are "even", i.e. f(x) == f(-x).  */
+      if (validate_arglist (arglist, COMPLEX_TYPE, VOID_TYPE))
+        {
+	  tree narg = fold_strip_sign_ops (TREE_VALUE (arglist));
+	  if (narg)
+	    return build_function_call_expr (fndecl,
+					     build_tree_list (NULL_TREE, narg));
+	}
+      break;
+
     CASE_FLT_FN (BUILT_IN_CABS):
       return fold_builtin_cabs (arglist, type, fndecl);

diff -rup orig/egcc-SVN20070124/gcc/fold-const.c egcc-SVN20070124/gcc/fold-const.c
--- orig/egcc-SVN20070124/gcc/fold-const.c	2007-01-18 20:02:47.000000000 -0500
+++ egcc-SVN20070124/gcc/fold-const.c	2007-01-25 10:36:46.978179574 -0500
@@ -913,7 +913,16 @@ negate_mathfn_p (enum built_in_function
     CASE_FLT_FN (BUILT_IN_ASINH):
     CASE_FLT_FN (BUILT_IN_ATAN):
     CASE_FLT_FN (BUILT_IN_ATANH):
+    CASE_FLT_FN (BUILT_IN_CASIN):
+    CASE_FLT_FN (BUILT_IN_CASINH):
+    CASE_FLT_FN (BUILT_IN_CATAN):
+    CASE_FLT_FN (BUILT_IN_CATANH):
     CASE_FLT_FN (BUILT_IN_CBRT):
+    CASE_FLT_FN (BUILT_IN_CPROJ):
+    CASE_FLT_FN (BUILT_IN_CSIN):
+    CASE_FLT_FN (BUILT_IN_CSINH):
+    CASE_FLT_FN (BUILT_IN_CTAN):
+    CASE_FLT_FN (BUILT_IN_CTANH):
     CASE_FLT_FN (BUILT_IN_ERF):
     CASE_FLT_FN (BUILT_IN_LLROUND):
     CASE_FLT_FN (BUILT_IN_LROUND):
diff -rup orig/egcc-SVN20070124/gcc/testsuite/gcc.dg/builtins-20.c egcc-SVN20070124/gcc/testsuite/gcc.dg/builtins-20.c
--- orig/egcc-SVN20070124/gcc/testsuite/gcc.dg/builtins-20.c	2007-01-24 23:36:31.000000000 -0500
+++ egcc-SVN20070124/gcc/testsuite/gcc.dg/builtins-20.c	2007-01-25 11:23:28.738780858 -0500
@@ -23,6 +23,8 @@ extern double fmax (double, double);
 extern double hypot (double, double);
 extern double pure (double) __attribute__ ((__pure__));
 extern double carg (__complex__ double);
+extern __complex__ double ccos (__complex__ double);
+extern __complex__ double ctan (__complex__ double);
 extern float cosf (float);
 extern float sinf (float);
 extern float tanf (float);
@@ -34,6 +36,8 @@ extern float fmaxf (float, float);
 extern float hypotf (float, float);
 extern float puref (float) __attribute__ ((__pure__));
 extern float cargf (__complex__ float);
+extern __complex__ float ccosf (__complex__ float);
+extern __complex__ float ctanf (__complex__ float);
 extern long double cosl (long double);
 extern long double sinl (long double);
 extern long double tanl (long double);
@@ -45,6 +49,8 @@ extern long double fmaxl (long double, l
 extern long double hypotl (long double, long double);
 extern long double purel (long double) __attribute__ ((__pure__));
 extern long double cargl (__complex__ long double);
+extern __complex__ long double ccosl (__complex__ long double);
+extern __complex__ long double ctanl (__complex__ long double);

 extern void link_error(void);

@@ -193,10 +199,49 @@ void test2(double x, double y)
     link_error ();
 }

-void test3(__complex__ double z)
+void test3(__complex__ double x, __complex__ double y, int i)
 {
-  if (carg(z) != atan2(__imag__ z, __real__ z))
+  if (carg(x) != atan2(__imag__ x, __real__ x))
     link_error ();
+
+  if (ccos(x) != ccos(-x))
+    link_error();
+
+  if (ccos(ctan(x)) != ccos(ctan(-x)))
+    link_error();
+
+  if (ctan(x-y) != -ctan(y-x))
+    link_error();
+
+  if (ccos(x/y) != ccos(-x/y))
+    link_error();
+
+  if (ccos(x/y) != ccos(x/-y))
+    link_error();
+
+  if (ccos(x/ctan(y)) != ccos(-x/ctan(-y)))
+    link_error();
+
+  if (ccos(x*y) != ccos(-x*y))
+    link_error();
+
+  if (ccos(x*y) != ccos(x*-y))
+    link_error();
+
+  if (ccos(ctan(x)*y) != ccos(ctan(-x)*-y))
+    link_error();
+
+  if (ccos(ctan(x/y)) != ccos(-ctan(x/-y)))
+    link_error();
+
+  if (ccos(i ? x : y) != ccos(i ? -x : y))
+    link_error();
+
+  if (ccos(i ? x : y) != ccos(i ? x : -y))
+    link_error();
+
+  if (ccos(i ? x : ctan(y/x)) != ccos(i ? -x : -ctan(-y/x)))
+    link_error();
 }

 void test1f(float x)
@@ -346,10 +391,49 @@ void test2f(float x, float y)
     link_error ();
 }

-void test3f(__complex__ float z)
+void test3f(__complex__ float x, __complex__ float y, int i)
 {
-  if (cargf(z) != atan2f(__imag__ z, __real__ z))
+  if (cargf(x) != atan2f(__imag__ x, __real__ x))
     link_error ();
+
+  if (ccosf(x) != ccosf(-x))
+    link_error();
+
+  if (ccosf(ctanf(x)) != ccosf(ctanf(-x)))
+    link_error();
+
+  if (ctanf(x-y) != -ctanf(y-x))
+    link_error();
+
+  if (ccosf(x/y) != ccosf(-x/y))
+    link_error();
+
+  if (ccosf(x/y) != ccosf(x/-y))
+    link_error();
+
+  if (ccosf(x/ctanf(y)) != ccosf(-x/ctanf(-y)))
+    link_error();
+
+  if (ccosf(x*y) != ccosf(-x*y))
+    link_error();
+
+  if (ccosf(x*y) != ccosf(x*-y))
+    link_error();
+
+  if (ccosf(ctanf(x)*y) != ccosf(ctanf(-x)*-y))
+    link_error();
+
+  if (ccosf(ctanf(x/y)) != ccosf(-ctanf(x/-y)))
+    link_error();
+
+  if (ccosf(i ? x : y) != ccosf(i ? -x : y))
+    link_error();
+
+  if (ccosf(i ? x : y) != ccosf(i ? x : -y))
+    link_error();
+
+  if (ccosf(i ? x : ctanf(y/x)) != ccosf(i ? -x : -ctanf(-y/x)))
+    link_error();
 }

 void test1l(long double x)
@@ -499,10 +583,49 @@ void test2l(long double x, long double y
     link_error ();
 }

-void test3l(__complex__ long double z)
+void test3l(__complex__ long double x, __complex__ long double y, int i)
 {
-  if (cargl(z) != atan2l(__imag__ z, __real__ z))
+  if (cargl(x) != atan2l(__imag__ x, __real__ x))
     link_error ();
+
+  if (ccosl(x) != ccosl(-x))
+    link_error();
+
+  if (ccosl(ctanl(x)) != ccosl(ctanl(-x)))
+    link_error();
+
+  if (ctanl(x-y) != -ctanl(y-x))
+    link_error();
+
+  if (ccosl(x/y) != ccosl(-x/y))
+    link_error();
+
+  if (ccosl(x/y) != ccosl(x/-y))
+    link_error();
+
+  if (ccosl(x/ctanl(y)) != ccosl(-x/ctanl(-y)))
+    link_error();
+
+  if (ccosl(x*y) != ccosl(-x*y))
+    link_error();
+
+  if (ccosl(x*y) != ccosl(x*-y))
+    link_error();
+
+  if (ccosl(ctanl(x)*y) != ccosl(ctanl(-x)*-y))
+    link_error();
+
+  if (ccosl(ctanl(x/y)) != ccosl(-ctanl(x/-y)))
+    link_error();
+
+  if (ccosl(i ? x : y) != ccosl(i ? -x : y))
+    link_error();
+
+  if (ccosl(i ? x : y) != ccosl(i ? x : -y))
+    link_error();
+
+  if (ccosl(i ? x : ctanl(y/x)) != ccosl(i ? -x : -ctanl(-y/x)))
+    link_error();
 }

 int main()
diff -rup orig/egcc-SVN20070124/gcc/testsuite/gcc.dg/torture/builtin-symmetric-1.c egcc-SVN20070124/gcc/testsuite/gcc.dg/torture/builtin-symmetric-1.c
--- orig/egcc-SVN20070124/gcc/testsuite/gcc.dg/torture/builtin-symmetric-1.c	2006-11-12 20:01:31.000000000 -0500
+++ egcc-SVN20070124/gcc/testsuite/gcc.dg/torture/builtin-symmetric-1.c	2007-01-25 10:37:09.113192348 -0500
@@ -21,6 +21,16 @@ extern void link_error(int);
     link_error(__LINE__); \
   } while (0)

+/* Test that FUNC(-ARG) == FUNC(ARG), where ARG has a complex type.  */
+#define TESTIT_EVEN_C(FUNC) do { \
+  if (__builtin_##FUNC##f(-cxf) != __builtin_##FUNC##f(cxf)) \
+    link_error(__LINE__); \
+  if (__builtin_##FUNC(-cx) != __builtin_##FUNC(cx)) \
+    link_error(__LINE__); \
+  if (__builtin_##FUNC##l(-cxl) != __builtin_##FUNC##l(cxl)) \
+    link_error(__LINE__); \
+  } while (0)
+
 /* Test that FUNC(-VAR) == FUNC(VAR), where VAR has an int type.  */
 #define TESTIT_EVEN_I(FUNC,VAR) do { \
   if (__builtin_##FUNC(-VAR) != __builtin_##FUNC(VAR)) \
@@ -37,13 +47,28 @@ extern void link_error(int);
     link_error(__LINE__); \
   } while (0)

+/* Test that -FUNC(ARG) == FUNC(-ARG), where ARG has a complex type.  */
+#define TESTIT_ODD_C(FUNC) do { \
+  if (-__builtin_##FUNC##f(-cxf) != __builtin_##FUNC##f(cxf)) \
+    link_error(__LINE__); \
+  if (-__builtin_##FUNC(-cx) != __builtin_##FUNC(cx)) \
+    link_error(__LINE__); \
+  if (-__builtin_##FUNC##l(-cxl) != __builtin_##FUNC##l(cxl)) \
+    link_error(__LINE__); \
+  } while (0)
+
 void foo (float xf, double x, long double xl,
+	  __complex__ float cxf, __complex__ double cx, __complex__ long double cxl,
 	  int i, long l, long long ll, __INTMAX_TYPE__ im)
 {
   TESTIT_EVEN(cos);
   TESTIT_EVEN(cosh);
   TESTIT_EVEN(fabs);

+  TESTIT_EVEN_C(ccos);
+  TESTIT_EVEN_C(ccosh);
+  TESTIT_EVEN_C(cabs);
+
   TESTIT_EVEN_I(abs, i);
   TESTIT_EVEN_I(imaxabs, im);
   TESTIT_EVEN_I(labs, l);
@@ -67,10 +92,20 @@ void foo (float xf, double x, long doubl
   TESTIT_ODD(tan);
   TESTIT_ODD(tanh);
   TESTIT_ODD(trunc);
+
+  TESTIT_ODD_C(casin);
+  TESTIT_ODD_C(casinh);
+  TESTIT_ODD_C(catan);
+  TESTIT_ODD_C(catanh);
+  TESTIT_ODD_C(cproj);
+  TESTIT_ODD_C(csin);
+  TESTIT_ODD_C(csinh);
+  TESTIT_ODD_C(ctan);
+  TESTIT_ODD_C(ctanh);
 }

 int main()
 {
-  foo (1,1,1,1,1,1,1);
+  foo (1,1,1,1,1,1,1,1,1,1);
   return 0;
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]