diff options
author | Roger Sayle <roger@eyesopen.com> | 2003-06-03 11:27:23 +0000 |
---|---|---|
committer | Roger Sayle <sayle@gcc.gnu.org> | 2003-06-03 11:27:23 +0000 |
commit | 075ec276a051c77c1542992980d651f832e7140a (patch) | |
tree | 0ac72a6f0481c8c341e932108b5ac14e70debfbf | |
parent | ded9bf77e35ce9a22468a1f56595df0741e2f22a (diff) | |
download | gcc-075ec276a051c77c1542992980d651f832e7140a.zip gcc-075ec276a051c77c1542992980d651f832e7140a.tar.gz gcc-075ec276a051c77c1542992980d651f832e7140a.tar.bz2 |
builtins.def (BUILT_IN_CABS, [...]): New builtins representing ISO C99's cabs, cabsf and cabsl.
* builtins.def (BUILT_IN_CABS, BUILT_IN_CABSF, BUILT_IN_CABSL):
New builtins representing ISO C99's cabs, cabsf and cabsl.
* builtins.c (expand_builtin_fabs): New function.
(expand_builtin_cabs): New function.
(expand_builtin): Expand BUILT_IN_FABS{,F,L} and BUILT_IN_CABS{,F,L}
using expand_builtin_fabs and expand_builtin_cabs respectively.
* doc/extend.texi: Document new cabs, cabsf and cabsl builtins.
* gcc.dg/builtins-16.c: New test case.
From-SVN: r67368
-rw-r--r-- | gcc/ChangeLog | 11 | ||||
-rw-r--r-- | gcc/builtins.c | 73 | ||||
-rw-r--r-- | gcc/builtins.def | 12 | ||||
-rw-r--r-- | gcc/doc/extend.texi | 10 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/builtins-16.c | 28 |
6 files changed, 134 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 28fad05..c68e593 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2003-06-03 Roger Sayle <roger@eyesopen.com> + + * builtins.def (BUILT_IN_CABS, BUILT_IN_CABSF, BUILT_IN_CABSL): + New builtins representing ISO C99's cabs, cabsf and cabsl. + * builtins.c (expand_builtin_fabs): New function. + (expand_builtin_cabs): New function. + (expand_builtin): Expand BUILT_IN_FABS{,F,L} and BUILT_IN_CABS{,F,L} + using expand_builtin_fabs and expand_builtin_cabs respectively. + + * doc/extend.texi: Document new cabs, cabsf and cabsl builtins. + 2003-06-03 Aldy Hernandez <aldyh@redhat.com> * function.c (assign_parms): Split complex arguments. diff --git a/gcc/builtins.c b/gcc/builtins.c index 557e397..53a1744 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -169,6 +169,8 @@ static tree fold_builtin_nan PARAMS ((tree, tree, int)); static int validate_arglist PARAMS ((tree, ...)); static tree fold_trunc_transparent_mathfn PARAMS ((tree)); static bool readonly_data_expr PARAMS ((tree)); +static rtx expand_builtin_fabs PARAMS ((tree, rtx, rtx)); +static rtx expand_builtin_cabs PARAMS ((tree, rtx)); /* Return the alignment in bits of EXP, a pointer valued expression. But don't return more than MAX_ALIGN no matter what. @@ -4306,6 +4308,57 @@ expand_builtin_trap () emit_library_call (abort_libfunc, LCT_NORETURN, VOIDmode, 0); emit_barrier (); } + +/* Expand a call to fabs, fabsf or fabsl with arguments ARGLIST. + Return 0 if a normal call should be emitted rather than expanding + the function inline. If convenient, the result should be placed + in TARGET. SUBTARGET may be used as the target for computing + the operand. */ + +static rtx +expand_builtin_fabs (arglist, target, subtarget) + tree arglist; + rtx target, subtarget; +{ + enum machine_mode mode; + tree arg; + rtx op0; + + if (!validate_arglist (arglist, REAL_TYPE, VOID_TYPE)) + return 0; + + arg = TREE_VALUE (arglist); + mode = TYPE_MODE (TREE_TYPE (arg)); + op0 = expand_expr (arg, subtarget, VOIDmode, 0); + return expand_abs (mode, op0, target, 0, safe_from_p (target, arg, 1)); +} + +/* Expand a call to cabs, cabsf or cabsl with arguments ARGLIST. + Return 0 if a normal call should be emitted rather than expanding + the function inline. If convenient, the result should be placed + in target. */ + +static rtx +expand_builtin_cabs (arglist, target) + tree arglist; + rtx target; +{ + enum machine_mode mode; + tree arg; + rtx op0; + + if (arglist == 0 || TREE_CHAIN (arglist)) + return 0; + arg = TREE_VALUE (arglist); + if (TREE_CODE (TREE_TYPE (arg)) != COMPLEX_TYPE + || TREE_CODE (TREE_TYPE (TREE_TYPE (arg))) != REAL_TYPE) + return 0; + + mode = TYPE_MODE (TREE_TYPE (arg)); + op0 = expand_expr (arg, NULL_RTX, VOIDmode, 0); + return expand_complex_abs (mode, op0, target, 0); +} + /* Expand an expression EXP that calls a built-in function, with result going to TARGET if that's convenient @@ -4458,11 +4511,27 @@ expand_builtin (exp, target, subtarget, mode, ignore) case BUILT_IN_LABS: case BUILT_IN_LLABS: case BUILT_IN_IMAXABS: + /* build_function_call changes these into ABS_EXPR. */ + abort (); + case BUILT_IN_FABS: case BUILT_IN_FABSF: case BUILT_IN_FABSL: - /* build_function_call changes these into ABS_EXPR. */ - abort (); + target = expand_builtin_fabs (arglist, target, subtarget); + if (target) + return target; + break; + + case BUILT_IN_CABS: + case BUILT_IN_CABSF: + case BUILT_IN_CABSL: + if (flag_unsafe_math_optimizations) + { + target = expand_builtin_cabs (arglist, target); + if (target) + return target; + } + break; case BUILT_IN_CONJ: case BUILT_IN_CONJF: diff --git a/gcc/builtins.def b/gcc/builtins.def index 1a09d6f..5f814bb 100644 --- a/gcc/builtins.def +++ b/gcc/builtins.def @@ -285,6 +285,18 @@ DEF_C99_BUILTIN(BUILT_IN_CIMAGL, "__builtin_cimagl", BT_FN_LONG_DOUBLE_COMPLEX_LONG_DOUBLE, ATTR_CONST_NOTHROW_LIST) +DEF_C99_BUILTIN(BUILT_IN_CABS, + "__builtin_cabs", + BT_FN_DOUBLE_COMPLEX_DOUBLE, + ATTR_CONST_NOTHROW_LIST) +DEF_C99_BUILTIN(BUILT_IN_CABSF, + "__builtin_cabsf", + BT_FN_FLOAT_COMPLEX_FLOAT, + ATTR_CONST_NOTHROW_LIST) +DEF_C99_BUILTIN(BUILT_IN_CABSL, + "__builtin_cabsl", + BT_FN_LONG_DOUBLE_COMPLEX_LONG_DOUBLE, + ATTR_CONST_NOTHROW_LIST) /* The system prototypes for `bzero', 'bcopy' and `bcmp' functions have many variations, so don't specify parameters to avoid diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index a95d363..c4152ef 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -4598,6 +4598,9 @@ v4si f (v4si a, v4si b, v4si c) @findex atanl @findex bcmp @findex bzero +@findex cabs +@findex cabsf +@findex cabsl @findex calloc @findex ceil @findex ceilf @@ -4726,8 +4729,11 @@ All these functions have corresponding versions prefixed with @code{__builtin_}, which may be used even in strict C89 mode. -The ISO C99 functions @code{conj}, @code{conjf}, @code{conjl}, @code{creal}, -@code{crealf}, @code{creall}, @code{cimag}, @code{cimagf}, @code{cimagl}, +The ISO C99 functions +@code{cabs}, @code{cabsf}, @code{cabsl}, +@code{conj}, @code{conjf}, @code{conjl}, +@code{creal}, @code{crealf}, @code{creall}, +@code{cimag}, @code{cimagf}, @code{cimagl}, @code{_Exit}, @code{imaxabs}, @code{llabs}, @code{nearbyint}, @code{nearbyintf}, @code{nearbyintl}, @code{round}, @code{roundf}, @code{roundl}, @code{snprintf}, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5ab4e9a..a7da74f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2003-06-03 Roger Sayle <roger@eyesopen.com> + + * gcc.dg/builtins-16.c: New test case. + 2003-06-03 Jakub Jelinek <jakub@redhat.com> * gcc.c-torture/execute/builtins/string-4.c (main_test): Remove diff --git a/gcc/testsuite/gcc.dg/builtins-16.c b/gcc/testsuite/gcc.dg/builtins-16.c new file mode 100644 index 0000000..e7ffe93 --- /dev/null +++ b/gcc/testsuite/gcc.dg/builtins-16.c @@ -0,0 +1,28 @@ +/* Copyright (C) 2003 Free Software Foundation. + + Verify that all the __builtin_cabs? functions are recognized + by the compiler. Complex numbers are not supported with the + gcc.dg default "-pedantic-errors" option, so the dg-options + overrides this. + + Written by Roger Sayle, 1st June 2003. */ + +/* { dg-do compile } */ +/* { dg-options "-O -ansi" } */ +/* { dg-final { scan-assembler-not "__builtin_" } } */ + +double test(__complex__ double x) +{ + return __builtin_cabs (x); +} + +float testf(__complex__ float x) +{ + return __builtin_cabsf (x); +} + +long double testl(__complex__ long double x) +{ + return __builtin_cabsl (x); +} + |