builtins.def: Define new builtin functions exp...
authorRoger Sayle <roger@eyesopen.com>
Sat, 3 Aug 2002 23:21:31 +0000 (23:21 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Sat, 3 Aug 2002 23:21:31 +0000 (23:21 +0000)
* builtins.def: Define new builtin functions exp, expf, expl,
log, logf and logl (and their __builtin_* variants).
* optabs.h (enum optab_index): Add new OTI_exp and OTI_log.
Define exp_optab and log_optab.
* optabs.c (init_optans): Initialize exp_optab and log_optab.
* genopinit.c (optabs): Implement exp_optab and log_optab
using exp?f2 and log?f2 patterns.
* builtins.c (expand_builtin_mathfn): Handle BUILT_IN_EXP*
and BUILT_IN_LOG* using exp_optab and log_optab respectively.
(expand_builtin): Ignore the new builtins (and all cos and
sin variants) when not optimizing.  Expand new builtins via
expand_builtin_mathfn when flag_unsafe_math_optimizations.

* doc/extend.texi: Document new exp and log builtins.
* doc/md.texi: Document new exp?f2 and log?f2 patterns
(and previously undocumented cos?f2 and sin?f2 patterns).

From-SVN: r56010

gcc/ChangeLog
gcc/builtins.c
gcc/builtins.def
gcc/doc/extend.texi
gcc/doc/md.texi
gcc/genopinit.c
gcc/optabs.c
gcc/optabs.h

index 96046ec70c4568fe15486e70689f28f4456e34bc..53245bad17ef24866e9bcc00ccba341e6510b71f 100644 (file)
@@ -1,3 +1,22 @@
+2002-08-03  Roger Sayle  <roger@eyesopen.com>
+
+       * builtins.def: Define new builtin functions exp, expf, expl,
+       log, logf and logl (and their __builtin_* variants).
+       * optabs.h (enum optab_index): Add new OTI_exp and OTI_log.
+       Define exp_optab and log_optab.
+       * optabs.c (init_optans): Initialize exp_optab and log_optab.
+       * genopinit.c (optabs): Implement exp_optab and log_optab
+       using exp?f2 and log?f2 patterns.
+       * builtins.c (expand_builtin_mathfn): Handle BUILT_IN_EXP*
+       and BUILT_IN_LOG* using exp_optab and log_optab respectively.
+       (expand_builtin): Ignore the new builtins (and all cos and
+       sin variants) when not optimizing.  Expand new builtins via
+       expand_builtin_mathfn when flag_unsafe_math_optimizations.
+
+       * doc/extend.texi: Document new exp and log builtins.
+       * doc/md.texi: Document new exp?f2 and log?f2 patterns
+       (and previously undocumented cos?f2 and sin?f2 patterns).
+
 2002-08-03  Jason Merrill  <jason@redhat.com>
 
        * explow.c (int_expr_size): New fn.
index 9c52cced939241eafeb594613736f02ffa0c4ae9..1dde0a034eed888ef4a887714848ffe0d4678460 100644 (file)
@@ -1525,7 +1525,15 @@ expand_builtin_mathfn (exp, target, subtarget)
     case BUILT_IN_SQRTF:
     case BUILT_IN_SQRTL:
       builtin_optab = sqrt_optab; break;
-     default:
+    case BUILT_IN_EXP:
+    case BUILT_IN_EXPF:
+    case BUILT_IN_EXPL:
+      builtin_optab = exp_optab; break;
+    case BUILT_IN_LOG:
+    case BUILT_IN_LOGF:
+    case BUILT_IN_LOGL:
+      builtin_optab = log_optab; break;
+    default:
       abort ();
     }
 
@@ -3689,11 +3697,18 @@ expand_builtin (exp, target, subtarget, mode, ignore)
   if (!optimize && !CALLED_AS_BUILT_IN (fndecl))
     switch (fcode)
       {
-      case BUILT_IN_SIN:
-      case BUILT_IN_COS:
       case BUILT_IN_SQRT:
       case BUILT_IN_SQRTF:
       case BUILT_IN_SQRTL:
+      case BUILT_IN_SIN:
+      case BUILT_IN_SINF:
+      case BUILT_IN_SINL:
+      case BUILT_IN_COS:
+      case BUILT_IN_COSF:
+      case BUILT_IN_COSL:
+      case BUILT_IN_EXP:
+      case BUILT_IN_EXPF:
+      case BUILT_IN_EXPL:
       case BUILT_IN_MEMSET:
       case BUILT_IN_MEMCPY:
       case BUILT_IN_MEMCMP:
@@ -3764,6 +3779,12 @@ expand_builtin (exp, target, subtarget, mode, ignore)
     case BUILT_IN_COS:
     case BUILT_IN_COSF:
     case BUILT_IN_COSL:
+    case BUILT_IN_EXP:
+    case BUILT_IN_EXPF:
+    case BUILT_IN_EXPL:
+    case BUILT_IN_LOG:
+    case BUILT_IN_LOGF:
+    case BUILT_IN_LOGL:
       /* Treat these like sqrt only if unsafe math optimizations are allowed,
         because of possible accuracy problems.  */
       if (! flag_unsafe_math_optimizations)
index 7be8fe14eb652a76b10883fc2d1c1fd64cf9143c..978b4a70d55b2e78525ee47d110c1212e6185913 100644 (file)
@@ -324,6 +324,20 @@ DEF_LIB_BUILTIN(BUILT_IN_COS,
                BT_FN_DOUBLE_DOUBLE,
                flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST
                                               : ATTR_PURE_NOTHROW_LIST)
+DEF_LIB_BUILTIN(BUILT_IN_EXP,
+               "__builtin_exp",
+               BT_FN_DOUBLE_DOUBLE,
+               flag_errno_math ? ATTR_NOTHROW_LIST
+                               : (flag_unsafe_math_optimizations
+                                  ? ATTR_CONST_NOTHROW_LIST
+                                  : ATTR_PURE_NOTHROW_LIST))
+DEF_LIB_BUILTIN(BUILT_IN_LOG,
+               "__builtin_log",
+               BT_FN_DOUBLE_DOUBLE,
+               flag_errno_math ? ATTR_NOTHROW_LIST
+                               : (flag_unsafe_math_optimizations
+                                  ? ATTR_CONST_NOTHROW_LIST
+                                  : ATTR_PURE_NOTHROW_LIST))
 DEF_LIB_BUILTIN(BUILT_IN_SQRTF,
                "__builtin_sqrtf",
                BT_FN_FLOAT_FLOAT,
@@ -341,6 +355,20 @@ DEF_LIB_BUILTIN(BUILT_IN_COSF,
                BT_FN_FLOAT_FLOAT,
                flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST
                                               : ATTR_PURE_NOTHROW_LIST)
+DEF_LIB_BUILTIN(BUILT_IN_EXPF,
+               "__builtin_expf",
+               BT_FN_FLOAT_FLOAT,
+               flag_errno_math ? ATTR_NOTHROW_LIST
+                               : (flag_unsafe_math_optimizations
+                                  ? ATTR_CONST_NOTHROW_LIST
+                                  : ATTR_PURE_NOTHROW_LIST))
+DEF_LIB_BUILTIN(BUILT_IN_LOGF,
+               "__builtin_logf",
+               BT_FN_FLOAT_FLOAT,
+               flag_errno_math ? ATTR_NOTHROW_LIST
+                               : (flag_unsafe_math_optimizations
+                                  ? ATTR_CONST_NOTHROW_LIST
+                                  : ATTR_PURE_NOTHROW_LIST))
 DEF_LIB_BUILTIN(BUILT_IN_SQRTL,
                "__builtin_sqrtl",
                BT_FN_LONG_DOUBLE_LONG_DOUBLE,
@@ -358,6 +386,20 @@ DEF_LIB_BUILTIN(BUILT_IN_COSL,
                BT_FN_LONG_DOUBLE_LONG_DOUBLE,
                flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST
                                               : ATTR_PURE_NOTHROW_LIST)
+DEF_LIB_BUILTIN(BUILT_IN_EXPL,
+               "__builtin_expl",
+               BT_FN_LONG_DOUBLE_LONG_DOUBLE,
+               flag_errno_math ? ATTR_NOTHROW_LIST
+                               : (flag_unsafe_math_optimizations
+                                  ? ATTR_CONST_NOTHROW_LIST
+                                  : ATTR_PURE_NOTHROW_LIST))
+DEF_LIB_BUILTIN(BUILT_IN_LOGL,
+               "__builtin_logl",
+               BT_FN_LONG_DOUBLE_LONG_DOUBLE,
+               flag_errno_math ? ATTR_NOTHROW_LIST
+                               : (flag_unsafe_math_optimizations
+                                  ? ATTR_CONST_NOTHROW_LIST
+                                  : ATTR_PURE_NOTHROW_LIST))
 
 DEF_UNUSED_BUILTIN(BUILT_IN_GETEXP)
 DEF_UNUSED_BUILTIN(BUILT_IN_GETMAN)
index 70afc3b8ffab58c188b4aa689b462a49360989b8..4814b35e69fd6a3b6a1f055f22077ffbf85fadb2 100644 (file)
@@ -4500,6 +4500,9 @@ v4si f (v4si a, v4si b, v4si c)
 @findex exit
 @findex _exit
 @findex _Exit
+@findex exp
+@findex expf
+@findex expl
 @findex fabs
 @findex fabsf
 @findex fabsl
@@ -4512,6 +4515,9 @@ v4si f (v4si a, v4si b, v4si c)
 @findex index
 @findex labs
 @findex llabs
+@findex log
+@findex logf
+@findex logl
 @findex memcmp
 @findex memcpy
 @findex memset
@@ -4577,13 +4583,15 @@ The ISO C99 functions @code{conj}, @code{conjf}, @code{conjl},
 @code{cimagl}, @code{llabs} and @code{imaxabs} are handled as built-in
 functions except in strict ISO C90 mode.  There are also built-in
 versions of the ISO C99 functions @code{cosf}, @code{cosl},
-@code{fabsf}, @code{fabsl}, @code{sinf}, @code{sinl}, @code{sqrtf}, and
+@code{expf}, @code{expl}, @code{fabsf}, @code{fabsl},
+@code{logf}, @code{logl}, @code{sinf}, @code{sinl}, @code{sqrtf}, and
 @code{sqrtl}, that are recognized in any mode since ISO C90 reserves
 these names for the purpose to which ISO C99 puts them.  All these
 functions have corresponding versions prefixed with @code{__builtin_}.
 
-The ISO C90 functions @code{abs}, @code{cos}, @code{fabs},
-@code{fprintf}, @code{fputs}, @code{labs}, @code{memcmp}, @code{memcpy},
+The ISO C90 functions @code{abs}, @code{cos}, @code{exp}, @code{fabs},
+@code{fprintf}, @code{fputs}, @code{labs}, @code{log},
+@code{memcmp}, @code{memcpy},
 @code{memset}, @code{printf}, @code{sin}, @code{sqrt}, @code{strcat},
 @code{strchr}, @code{strcmp}, @code{strcpy}, @code{strcspn},
 @code{strlen}, @code{strncat}, @code{strncmp}, @code{strncpy},
index 09353374c623d295364894ed0f418743a9f929ff..ceac9fd780b552b86c14fb8f1844d05dc3fc547a 100644 (file)
@@ -2523,7 +2523,45 @@ Store the absolute value of operand 1 into operand 0.
 Store the square root of operand 1 into operand 0.
 
 The @code{sqrt} built-in function of C always uses the mode which
-corresponds to the C data type @code{double}.
+corresponds to the C data type @code{double} and the @code{sqrtf}
+built-in function uses the mode which corresponds to the C data
+type @code{float}.
+
+@cindex @code{cos@var{m}2} instruction pattern
+@item @samp{cos@var{m}2}
+Store the cosine of operand 1 into operand 0.
+
+The @code{cos} built-in function of C always uses the mode which
+corresponds to the C data type @code{double} and the @code{cosf}
+built-in function uses the mode which corresponds to the C data
+type @code{float}.
+
+@cindex @code{sin@var{m}2} instruction pattern
+@item @samp{sin@var{m}2}
+Store the sine of operand 1 into operand 0.
+
+The @code{sin} built-in function of C always uses the mode which
+corresponds to the C data type @code{double} and the @code{sinf}
+built-in function uses the mode which corresponds to the C data
+type @code{float}.
+
+@cindex @code{exp@var{m}2} instruction pattern
+@item @samp{exp@var{m}2}
+Store the exponential of operand 1 into operand 0.
+
+The @code{exp} built-in function of C always uses the mode which
+corresponds to the C data type @code{double} and the @code{expf}
+built-in function uses the mode which corresponds to the C data
+type @code{float}.
+
+@cindex @code{log@var{m}2} instruction pattern
+@item @samp{log@var{m}2}
+Store the natural logarithm of operand 1 into operand 0.
+
+The @code{log} built-in function of C always uses the mode which
+corresponds to the C data type @code{double} and the @code{logf}
+built-in function uses the mode which corresponds to the C data
+type @code{float}.
 
 @cindex @code{ffs@var{m}2} instruction pattern
 @item @samp{ffs@var{m}2}
index 384a06601d81eb0ea3e7b600130463d891d6eab3..ef4242a64cd4c3fe18b630e1ad3fb90e99896452 100644 (file)
@@ -114,6 +114,8 @@ static const char * const optabs[] =
   "sqrt_optab->handlers[$A].insn_code = CODE_FOR_$(sqrt$a2$)",
   "sin_optab->handlers[$A].insn_code = CODE_FOR_$(sin$a2$)",
   "cos_optab->handlers[$A].insn_code = CODE_FOR_$(cos$a2$)",
+  "exp_optab->handlers[$A].insn_code = CODE_FOR_$(exp$a2$)",
+  "log_optab->handlers[$A].insn_code = CODE_FOR_$(log$a2$)",
   "strlen_optab->handlers[$A].insn_code = CODE_FOR_$(strlen$a$)",
   "one_cmpl_optab->handlers[$A].insn_code = CODE_FOR_$(one_cmpl$a2$)",
   "ffs_optab->handlers[$A].insn_code = CODE_FOR_$(ffs$a2$)",
index 1e4af105f4fb83bab88956c08e36a36ad66e7680..3f17034f0d51de25866143fdc1e9e5ff27f80fd0 100644 (file)
@@ -5193,6 +5193,8 @@ init_optabs ()
   sqrt_optab = init_optab (SQRT);
   sin_optab = init_optab (UNKNOWN);
   cos_optab = init_optab (UNKNOWN);
+  exp_optab = init_optab (UNKNOWN);
+  log_optab = init_optab (UNKNOWN);
   strlen_optab = init_optab (UNKNOWN);
   cbranch_optab = init_optab (UNKNOWN);
   cmov_optab = init_optab (UNKNOWN);
index 08dbec1e80a4b2c34b333de43e2ec4f31fde417d..fd80d826720289e0663101e2ae67412b330add41 100644 (file)
@@ -131,6 +131,10 @@ enum optab_index
   OTI_sin,
   /* Cosine */
   OTI_cos,
+  /* Exponential */
+  OTI_exp,
+  /* Natural Logarithm */
+  OTI_log,
 
   /* Compare insn; two operands.  */
   OTI_cmp,
@@ -198,6 +202,8 @@ extern GTY(()) optab optab_table[OTI_MAX];
 #define sqrt_optab (optab_table[OTI_sqrt])
 #define sin_optab (optab_table[OTI_sin])
 #define cos_optab (optab_table[OTI_cos])
+#define exp_optab (optab_table[OTI_exp])
+#define log_optab (optab_table[OTI_log])
 
 #define cmp_optab (optab_table[OTI_cmp])
 #define ucmp_optab (optab_table[OTI_ucmp])