This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH]: (middle-end) fold complex "arc" functions using MPC
- From: "Kaveh R. GHAZI" <ghazi at caip dot rutgers dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 29 Sep 2009 22:34:37 -0400 (EDT)
- Subject: [PATCH]: (middle-end) fold complex "arc" functions using MPC
This is the patch for handling complex "arc" functions using MPC. We'll
have support for these functions in mpc-0.8. I plan to flesh out the
testcase a bit more, but that can happen during stage3. I want this part,
which adds functionality, submitted before the deadline for stage1
submissions closes.
Tested on x86_64-unknown-linux-gnu, no regressions.
Okay for mainline?
Thanks,
--Kaveh
2009-09-29 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* builtins.c (fold_builtin_1): Support complex "arc" functions.
* real.h (HAVE_mpc_arc): Define.
testsuite:
* gcc.dg/torture/builtin-math-6.c: Test complex "arc" functions.
* lib/target-supports.exp (check_effective_target_mpc_arc): New.
diff -rup orig/egcc-SVN20090929/gcc/builtins.c egcc-SVN20090929/gcc/builtins.c
--- orig/egcc-SVN20090929/gcc/builtins.c 2009-09-29 02:00:27.000000000 +0200
+++ egcc-SVN20090929/gcc/builtins.c 2009-09-29 17:05:28.000000000 +0200
@@ -10051,7 +10051,45 @@ fold_builtin_1 (location_t loc, tree fnd
&& TREE_CODE (TREE_TYPE (TREE_TYPE (arg0))) == REAL_TYPE)
return do_mpc_arg1 (arg0, type, mpc_sqrt);
break;
-#endif
+
+#ifdef HAVE_mpc_arc
+ CASE_FLT_FN (BUILT_IN_CASIN):
+ if (validate_arg (arg0, COMPLEX_TYPE)
+ && TREE_CODE (TREE_TYPE (TREE_TYPE (arg0))) == REAL_TYPE)
+ return do_mpc_arg1 (arg0, type, mpc_asin);
+ break;
+
+ CASE_FLT_FN (BUILT_IN_CACOS):
+ if (validate_arg (arg0, COMPLEX_TYPE)
+ && TREE_CODE (TREE_TYPE (TREE_TYPE (arg0))) == REAL_TYPE)
+ return do_mpc_arg1 (arg0, type, mpc_acos);
+ break;
+
+ CASE_FLT_FN (BUILT_IN_CATAN):
+ if (validate_arg (arg0, COMPLEX_TYPE)
+ && TREE_CODE (TREE_TYPE (TREE_TYPE (arg0))) == REAL_TYPE)
+ return do_mpc_arg1 (arg0, type, mpc_atan);
+ break;
+
+ CASE_FLT_FN (BUILT_IN_CASINH):
+ if (validate_arg (arg0, COMPLEX_TYPE)
+ && TREE_CODE (TREE_TYPE (TREE_TYPE (arg0))) == REAL_TYPE)
+ return do_mpc_arg1 (arg0, type, mpc_asinh);
+ break;
+
+ CASE_FLT_FN (BUILT_IN_CACOSH):
+ if (validate_arg (arg0, COMPLEX_TYPE)
+ && TREE_CODE (TREE_TYPE (TREE_TYPE (arg0))) == REAL_TYPE)
+ return do_mpc_arg1 (arg0, type, mpc_acosh);
+ break;
+
+ CASE_FLT_FN (BUILT_IN_CATANH):
+ if (validate_arg (arg0, COMPLEX_TYPE)
+ && TREE_CODE (TREE_TYPE (TREE_TYPE (arg0))) == REAL_TYPE)
+ return do_mpc_arg1 (arg0, type, mpc_atanh);
+ break;
+#endif /* HAVE_mpc_arc */
+#endif /* HAVE_mpc */
CASE_FLT_FN (BUILT_IN_CABS):
return fold_builtin_cabs (loc, arg0, type, fndecl);
diff -rup orig/egcc-SVN20090929/gcc/real.h egcc-SVN20090929/gcc/real.h
--- orig/egcc-SVN20090929/gcc/real.h 2009-09-20 17:53:00.000000000 +0200
+++ egcc-SVN20090929/gcc/real.h 2009-09-29 17:01:19.000000000 +0200
@@ -32,6 +32,9 @@ extern tree do_mpc_arg2 (tree, tree, tre
# if MPC_VERSION >= MPC_VERSION_NUM(0,6,1)
# define HAVE_mpc_pow
# endif
+# if MPC_VERSION >= MPC_VERSION_NUM(0,7,1)
+# define HAVE_mpc_arc
+# endif
#endif
#endif
#include "machmode.h"
diff -rup orig/egcc-SVN20090929/gcc/testsuite/gcc.dg/torture/builtin-math-6.c egcc-SVN20090929/gcc/testsuite/gcc.dg/torture/builtin-math-6.c
--- orig/egcc-SVN20090929/gcc/testsuite/gcc.dg/torture/builtin-math-6.c 2009-08-25 02:01:20.000000000 +0200
+++ egcc-SVN20090929/gcc/testsuite/gcc.dg/torture/builtin-math-6.c 2009-09-29 18:25:47.000000000 +0200
@@ -7,6 +7,7 @@
/* { dg-do link } */
/* { dg-require-effective-target mpc_pow } */
+/* { dg-require-effective-target mpc_arc } */
/* All references to link_error should go away at compile-time. The
first number is the line number and the second is the value number
@@ -180,9 +181,30 @@ extern void link_error(int, int);
int main (void)
{
+ TESTIT_COMPLEX (1, cacos, 1, 0);
+ TESTIT_COMPLEX_R (1, cacos, -1, 3.141593F);
+ TESTIT_COMPLEX (1, cacos, CONJ(1), 0);
+ TESTIT_COMPLEX_R (1, cacos, CONJ(-1), 3.141593F);
+
+ TESTIT_COMPLEX_ALLNEG (casin, 0,
+ 0, -CONJ(0), CONJ(0), -0.F);
+
+ TESTIT_COMPLEX_ALLNEG (catan, 0,
+ 0, -CONJ(0), CONJ(0), -0.F);
+
+ TESTIT_COMPLEX (1, cacosh, 1, 0);
+ TESTIT_COMPLEX_R (1, cacosh, -1, 3.141593FI);
+ TESTIT_COMPLEX (1, cacosh, CONJ(1), CONJ(0));
+ TESTIT_COMPLEX_R (1, cacosh, CONJ(-1), 3.141593FI);
+
+ TESTIT_COMPLEX_ALLNEG (casinh, 0,
+ 0, -CONJ(0), CONJ(0), -0.F);
+
+ TESTIT_COMPLEX_ALLNEG (catanh, 0,
+ 0, -CONJ(0), CONJ(0), -0.F);
+
TESTIT_COMPLEX_ALLNEG (csin, 0,
- 0, -0.F,
- CONJ(0), CONJ(-0.F));
+ 0, -0.F, CONJ(0), CONJ(-0.F));
TESTIT_COMPLEX_R_ALLNEG (csin, 3.45678F + 2.34567FI,
-1.633059F - 4.917448FI, 1.633059F - 4.917448FI,
-1.633059F + 4.917448FI, 1.633059F + 4.917448FI);
@@ -219,8 +241,8 @@ int main (void)
TESTIT_COMPLEX (1, clog, 1, 0);
TESTIT_COMPLEX_R (1, clog, -1, 3.141593FI);
- TESTIT_COMPLEX (1, clog, CONJ(1), CONJ(0)); /* Fails with mpc-0.6. */
- TESTIT_COMPLEX_R (1, clog, CONJ(-1), CONJ(3.141593FI)); /* Fails with mpc-0.6. */
+ TESTIT_COMPLEX (1, clog, CONJ(1), CONJ(0));
+ TESTIT_COMPLEX_R (1, clog, CONJ(-1), CONJ(3.141593FI));
TESTIT_COMPLEX_R_ALLNEG (clog, 3.45678F + 2.34567FI,
1.429713F + 0.596199FI, 1.429713F + 2.545394FI,
1.429713F - 0.596199FI, 1.429713F - 2.545394FI);
diff -rup orig/egcc-SVN20090929/gcc/testsuite/lib/target-supports.exp egcc-SVN20090929/gcc/testsuite/lib/target-supports.exp
--- orig/egcc-SVN20090929/gcc/testsuite/lib/target-supports.exp 2009-09-29 02:00:23.000000000 +0200
+++ egcc-SVN20090929/gcc/testsuite/lib/target-supports.exp 2009-09-29 17:22:28.000000000 +0200
@@ -3119,6 +3119,29 @@ proc check_effective_target_mpc_pow { }
}]
}
+# Return 1 if the MPC library with "arc" functions is integrated with GCC, 0 otherwise.
+
+proc check_effective_target_mpc_arc { } {
+ return [check_no_compiler_messages mpc_arc executable {
+ extern void link_error(void);
+ int main ()
+ {
+ if (__builtin_cacos(1) != 0)
+ link_error();
+ if (__builtin_casin(0) != 0)
+ link_error();
+ if (__builtin_catan(0) != 0)
+ link_error();
+ if (__builtin_cacosh(1) != 0)
+ link_error();
+ if (__builtin_casinh(0) != 0)
+ link_error();
+ if (__builtin_catanh(0) != 0)
+ link_error();
+ }
+ }]
+}
+
# Return 1 if the language for the compiler under test is C.
proc check_effective_target_c { } {