]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
builtins.def (BUILT_IN_CABS, [...]): New builtins representing ISO C99's cabs, cabsf...
authorRoger Sayle <roger@eyesopen.com>
Tue, 3 Jun 2003 11:27:23 +0000 (11:27 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Tue, 3 Jun 2003 11:27:23 +0000 (11:27 +0000)
* 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

gcc/ChangeLog
gcc/builtins.c
gcc/builtins.def
gcc/doc/extend.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/builtins-16.c [new file with mode: 0644]

index 28fad05757acf945edf3a65709eaf96c1d33a63e..c68e593a20a0459ba3b0b6a021d6721a88eae44b 100644 (file)
@@ -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.
index 557e397945ce9c23b15aee37e3e030cdbb30e8c4..53a1744fe724a257b8cf79b2e351a6c9dd79ec9e 100644 (file)
@@ -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);
+}
+
 \f
 /* 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:
index 1a09d6fd26b17371a62d4637cbeaef7d990797d7..5f814bbf9f5a11597d42aa1b59271da871a016db 100644 (file)
@@ -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
index a95d3637d837ba7df18f9446a8d7bfeee41eb4f7..c4152ef009225edb9f3cce7e138e3a7fd5ab278e 100644 (file)
@@ -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},
index 5ab4e9a780709640a83598cbfe8da7e799a28d54..a7da74f4c8c0098e62c9ee8077f67092a6b57270 100644 (file)
@@ -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 (file)
index 0000000..e7ffe93
--- /dev/null
@@ -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);
+}
+