This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[3.4-BIB] Add trunc/round/floor/ceil/rint builtins II
Hi,
here is patch with updates for the C99 standard. OK now?
Tue Nov 5 19:12:19 PST 2002 Jan Hubicka <jh@suse.cz>
* builtins.c (expand_builtin_mathfn): Handle floor/ceil/trunc/round/rint
(expand_builtin): Likewise.
* builtins.def: Add
__builtin_floor, __builtin_floorf, __builtin_floorl
__builtin_ceil, __builtin_ceilf, __builtin_ceill
__builtin_round, __builtin_roundf, __builtin_roundl
__builtin_trunc, __builtin_truncf, __builtin_truncl
__builtin_rint, __builtin_rintf, __builtin_rintl.
* genopinit.c (optabs): Initialize the new optabs.
* optab.c (init_optabs): Likewise.
* optabs.h (optab_index): Add OTI_floor, OTI_ceil, OTI_trunc,
OTI_round, OTI_rint.
(floor_optab, ceil_optab, trunc_optab, round_optab, rint_optab): New.
* doc/md.texi: Document new named patterns.
* doc/extend.texi (builtin functions) Document
floor, floorf, floorl, ceil, ceilf,
ceill, round, roundf, roundl, trunc,
truncf, truncl, rint, rintf, rintl.
Index: builtins.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/builtins.c,v
retrieving revision 1.159.2.1
diff -c -3 -p -r1.159.2.1 builtins.c
*** builtins.c 16 Oct 2002 16:07:05 -0000 1.159.2.1
--- builtins.c 6 Nov 2002 21:49:02 -0000
*************** expand_builtin_mathfn (exp, target, subt
*** 1483,1488 ****
--- 1483,1489 ----
tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
tree arglist = TREE_OPERAND (exp, 1);
enum machine_mode argmode;
+ bool errno_set = true;
if (!validate_arglist (arglist, REAL_TYPE, VOID_TYPE))
return 0;
*************** expand_builtin_mathfn (exp, target, subt
*** 1533,1538 ****
--- 1534,1559 ----
case BUILT_IN_LOGF:
case BUILT_IN_LOGL:
builtin_optab = log_optab; break;
+ case BUILT_IN_FLOOR:
+ case BUILT_IN_FLOORF:
+ case BUILT_IN_FLOORL:
+ errno_set = false ; builtin_optab = floor_optab; break;
+ case BUILT_IN_CEIL:
+ case BUILT_IN_CEILF:
+ case BUILT_IN_CEILL:
+ errno_set = false ; builtin_optab = ceil_optab; break;
+ case BUILT_IN_TRUNC:
+ case BUILT_IN_TRUNCF:
+ case BUILT_IN_TRUNCL:
+ errno_set = false ; builtin_optab = trunc_optab; break;
+ case BUILT_IN_ROUND:
+ case BUILT_IN_ROUNDF:
+ case BUILT_IN_ROUNDL:
+ errno_set = false ; builtin_optab = round_optab; break;
+ case BUILT_IN_RINT:
+ case BUILT_IN_RINTF:
+ case BUILT_IN_RINTL:
+ errno_set = false ; builtin_optab = rint_optab; break;
default:
abort ();
}
*************** expand_builtin_mathfn (exp, target, subt
*** 1553,1559 ****
/* If errno must be maintained, we must set it to EDOM for NaN results. */
! if (flag_errno_math && HONOR_NANS (argmode))
{
rtx lab1;
--- 1574,1580 ----
/* If errno must be maintained, we must set it to EDOM for NaN results. */
! if (flag_errno_math && errno_set && HONOR_NANS (argmode))
{
rtx lab1;
*************** expand_builtin (exp, target, subtarget,
*** 3743,3748 ****
--- 3764,3784 ----
case BUILT_IN_FPUTC_UNLOCKED:
case BUILT_IN_FPUTS_UNLOCKED:
case BUILT_IN_FWRITE_UNLOCKED:
+ case BUILT_IN_FLOOR:
+ case BUILT_IN_FLOORF:
+ case BUILT_IN_FLOORL:
+ case BUILT_IN_CEIL:
+ case BUILT_IN_CEILF:
+ case BUILT_IN_CEILL:
+ case BUILT_IN_TRUNC:
+ case BUILT_IN_TRUNCF:
+ case BUILT_IN_TRUNCL:
+ case BUILT_IN_ROUND:
+ case BUILT_IN_ROUNDF:
+ case BUILT_IN_ROUNDL:
+ case BUILT_IN_RINT:
+ case BUILT_IN_RINTF:
+ case BUILT_IN_RINTL:
return expand_call (exp, target, ignore);
default:
*************** expand_builtin (exp, target, subtarget,
*** 3793,3798 ****
--- 3829,3849 ----
case BUILT_IN_SQRT:
case BUILT_IN_SQRTF:
case BUILT_IN_SQRTL:
+ case BUILT_IN_FLOOR:
+ case BUILT_IN_FLOORF:
+ case BUILT_IN_FLOORL:
+ case BUILT_IN_CEIL:
+ case BUILT_IN_CEILF:
+ case BUILT_IN_CEILL:
+ case BUILT_IN_TRUNC:
+ case BUILT_IN_TRUNCF:
+ case BUILT_IN_TRUNCL:
+ case BUILT_IN_ROUND:
+ case BUILT_IN_ROUNDF:
+ case BUILT_IN_ROUNDL:
+ case BUILT_IN_RINT:
+ case BUILT_IN_RINTF:
+ case BUILT_IN_RINTL:
target = expand_builtin_mathfn (exp, target, subtarget);
if (target)
return target;
Index: builtins.def
===================================================================
RCS file: /cvs/gcc/egcs/gcc/builtins.def,v
retrieving revision 1.34.2.1
diff -c -3 -p -r1.34.2.1 builtins.def
*** builtins.def 16 Oct 2002 16:07:06 -0000 1.34.2.1
--- builtins.def 6 Nov 2002 21:49:02 -0000
*************** DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_FABSL,
*** 169,174 ****
--- 169,224 ----
"__builtin_fabsl",
BT_FN_LONG_DOUBLE_LONG_DOUBLE)
+ DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_FLOOR,
+ "__builtin_floor",
+ BT_FN_DOUBLE_DOUBLE)
+ DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_FLOORF,
+ "__builtin_floorf",
+ BT_FN_FLOAT_FLOAT)
+ DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_FLOORL,
+ "__builtin_floorl",
+ BT_FN_LONG_DOUBLE_LONG_DOUBLE)
+
+ DEF_C99_BUILTIN(BUILT_IN_CEIL,
+ "__builtin_ceil",
+ BT_FN_DOUBLE_DOUBLE)
+ DEF_C99_BUILTIN(BUILT_IN_CEILF,
+ "__builtin_ceilf",
+ BT_FN_FLOAT_FLOAT)
+ DEF_C99_BUILTIN(BUILT_IN_CEILL,
+ "__builtin_ceill",
+ BT_FN_LONG_DOUBLE_LONG_DOUBLE)
+
+ DEF_C99_BUILTIN(BUILT_IN_ROUND,
+ "__builtin_round",
+ BT_FN_DOUBLE_DOUBLE)
+ DEF_C99_BUILTIN(BUILT_IN_ROUNDF,
+ "__builtin_roundf",
+ BT_FN_FLOAT_FLOAT)
+ DEF_C99_BUILTIN(BUILT_IN_ROUNDL,
+ "__builtin_roundl",
+ BT_FN_LONG_DOUBLE_LONG_DOUBLE)
+
+ DEF_C99_BUILTIN(BUILT_IN_TRUNC,
+ "__builtin_trunc",
+ BT_FN_DOUBLE_DOUBLE)
+ DEF_C99_BUILTIN(BUILT_IN_TRUNCF,
+ "__builtin_truncf",
+ BT_FN_FLOAT_FLOAT)
+ DEF_C99_BUILTIN(BUILT_IN_TRUNCL,
+ "__builtin_truncl",
+ BT_FN_LONG_DOUBLE_LONG_DOUBLE)
+
+ DEF_C99_BUILTIN(BUILT_IN_RINT,
+ "__builtin_rint",
+ BT_FN_DOUBLE_DOUBLE)
+ DEF_C99_BUILTIN(BUILT_IN_RINTF,
+ "__builtin_rintf",
+ BT_FN_FLOAT_FLOAT)
+ DEF_C99_BUILTIN(BUILT_IN_RINTL,
+ "__builtin_rintl",
+ BT_FN_LONG_DOUBLE_LONG_DOUBLE)
+
DEF_C99_BUILTIN(BUILT_IN_LLABS,
"__builtin_llabs",
BT_FN_LONGLONG_LONGLONG)
Index: genopinit.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/genopinit.c,v
retrieving revision 1.53
diff -c -3 -p -r1.53 genopinit.c
*** genopinit.c 3 Aug 2002 23:21:30 -0000 1.53
--- genopinit.c 6 Nov 2002 21:49:10 -0000
*************** static const char * const optabs[] =
*** 112,117 ****
--- 112,122 ----
abs_optab->handlers[(int) $A].insn_code = CODE_FOR_$(abs$F$a2$)",
"absv_optab->handlers[(int) $A].insn_code = CODE_FOR_$(absv$I$a2$)",
"sqrt_optab->handlers[$A].insn_code = CODE_FOR_$(sqrt$a2$)",
+ "floor_optab->handlers[$A].insn_code = CODE_FOR_$(floor$a2$)",
+ "ceil_optab->handlers[$A].insn_code = CODE_FOR_$(ceil$a2$)",
+ "round_optab->handlers[$A].insn_code = CODE_FOR_$(round$a2$)",
+ "trunc_optab->handlers[$A].insn_code = CODE_FOR_$(trunc$a2$)",
+ "rint_optab->handlers[$A].insn_code = CODE_FOR_$(rint$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$)",
Index: optabs.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/optabs.c,v
retrieving revision 1.143.2.2
diff -c -3 -p -r1.143.2.2 optabs.c
*** optabs.c 30 Oct 2002 22:08:18 -0000 1.143.2.2
--- optabs.c 6 Nov 2002 21:49:11 -0000
*************** init_optabs ()
*** 5173,5178 ****
--- 5173,5183 ----
one_cmpl_optab = init_optab (NOT);
ffs_optab = init_optab (FFS);
sqrt_optab = init_optab (SQRT);
+ floor_optab = init_optab (UNKNOWN);
+ ceil_optab = init_optab (UNKNOWN);
+ round_optab = init_optab (UNKNOWN);
+ trunc_optab = init_optab (UNKNOWN);
+ rint_optab = init_optab (UNKNOWN);
sin_optab = init_optab (UNKNOWN);
cos_optab = init_optab (UNKNOWN);
exp_optab = init_optab (UNKNOWN);
Index: optabs.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/optabs.h,v
retrieving revision 1.7
diff -c -3 -p -r1.7 optabs.h
*** optabs.h 3 Aug 2002 23:21:30 -0000 1.7
--- optabs.h 6 Nov 2002 21:49:11 -0000
*************** enum optab_index
*** 135,140 ****
--- 135,146 ----
OTI_exp,
/* Natural Logarithm */
OTI_log,
+ /* Rounding functions */
+ OTI_floor,
+ OTI_ceil,
+ OTI_trunc,
+ OTI_round,
+ OTI_rint,
/* Compare insn; two operands. */
OTI_cmp,
*************** extern GTY(()) optab optab_table[OTI_MAX
*** 204,209 ****
--- 210,220 ----
#define cos_optab (optab_table[OTI_cos])
#define exp_optab (optab_table[OTI_exp])
#define log_optab (optab_table[OTI_log])
+ #define floor_optab (optab_table[OTI_floor])
+ #define ceil_optab (optab_table[OTI_ceil])
+ #define trunc_optab (optab_table[OTI_trunc])
+ #define round_optab (optab_table[OTI_round])
+ #define rint_optab (optab_table[OTI_rint])
#define cmp_optab (optab_table[OTI_cmp])
#define ucmp_optab (optab_table[OTI_ucmp])
Index: doc/extend.texi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/doc/extend.texi,v
retrieving revision 1.95.2.2
diff -c -3 -p -r1.95.2.2 extend.texi
*** doc/extend.texi 23 Oct 2002 15:48:54 -0000 1.95.2.2
--- doc/extend.texi 6 Nov 2002 21:49:23 -0000
*************** v4si f (v4si a, v4si b, v4si c)
*** 4568,4573 ****
--- 4568,4588 ----
@findex strrchr
@findex strspn
@findex strstr
+ @findex floor
+ @findex floorf
+ @findex floorl
+ @findex ceil
+ @findex ceilf
+ @findex ceill
+ @findex round
+ @findex roundf
+ @findex roundl
+ @findex trunc
+ @findex truncf
+ @findex truncl
+ @findex rint
+ @findex rintf
+ @findex rintl
GCC provides a large number of built-in functions other than the ones
mentioned above. Some of these are for internal use in the processing
*************** built-in functions. All these functions
*** 4603,4630 ****
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}, @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{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{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},
@code{strpbrk}, @code{strrchr}, @code{strspn}, and @code{strstr} are all
! recognized as built-in functions unless @option{-fno-builtin} is
! specified (or @option{-fno-builtin-@var{function}} is specified for an
! individual function). All of these functions have corresponding
! versions prefixed with @code{__builtin_}.
GCC provides built-in versions of the ISO C99 floating point comparison
macros that avoid raising exceptions for unordered operands. They have
--- 4618,4646 ----
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},
! @code{llabs}, @code{imaxabs}, @code{ceil}, @code{round}, @code{train},
! @code{rint}, @code{ceilf}, @code{roundf}, @code{rintf}, @code{ceill},
! @code{roundl}, @code{truncl} and @code{rintl} 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{expf}, @code{expl}, @code{fabsf},
! @code{fabsl}, @code{logf}, @code{logl}, @code{sinf}, @code{sinl}, @code{sqrtf},
! @code{sqrtl}, @code{floorl}, @code{floorf} and @code{floor} 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{exp}, @code{fabs},
! @code{fprintf}, @code{fputs}, @code{labs}, @code{log}, @code{floor},
! @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},
@code{strpbrk}, @code{strrchr}, @code{strspn}, and @code{strstr} are all
! recognized as built-in functions unless @option{-fno-builtin} is specified (or
! @option{-fno-builtin-@var{function}} is specified for an individual function).
! All of these functions have corresponding versions prefixed with
! @code{__builtin_}.
GCC provides built-in versions of the ISO C99 floating point comparison
macros that avoid raising exceptions for unordered operands. They have
Index: doc/md.texi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/doc/md.texi,v
retrieving revision 1.46.2.1
diff -c -3 -p -r1.46.2.1 md.texi
*** doc/md.texi 16 Oct 2002 16:08:36 -0000 1.46.2.1
--- doc/md.texi 6 Nov 2002 21:49:24 -0000
*************** corresponds to the C data type @code{dou
*** 2563,2568 ****
--- 2563,2613 ----
built-in function uses the mode which corresponds to the C data
type @code{float}.
+ @cindex @code{floor@var{m}2} instruction pattern
+ @item @samp{floor@var{m}2}
+ Store the largest integral value not greater than argument.
+
+ The @code{floor} built-in function of C always uses the mode which
+ corresponds to the C data type @code{double} and the @code{floorf}
+ built-in function uses the mode which corresponds to the C data
+ type @code{float}.
+
+ @cindex @code{trunc@var{m}2} instruction pattern
+ @item @samp{trunc@var{m}2}
+ Store the argument rounded to integer towards zero.
+
+ The @code{trunc} built-in function of C always uses the mode which
+ corresponds to the C data type @code{double} and the @code{truncf}
+ built-in function uses the mode which corresponds to the C data
+ type @code{float}.
+
+ @cindex @code{round@var{m}2} instruction pattern
+ @item @samp{round@var{m}2}
+ Store the argument rounded to integer away from zero.
+
+ The @code{round} built-in function of C always uses the mode which
+ corresponds to the C data type @code{double} and the @code{roundf}
+ built-in function uses the mode which corresponds to the C data
+ type @code{float}.
+
+ @cindex @code{ceil@var{m}2} instruction pattern
+ @item @samp{ceil@var{m}2}
+ Store the argument rounded to integer away from zero.
+
+ The @code{ceil} built-in function of C always uses the mode which
+ corresponds to the C data type @code{double} and the @code{ceilf}
+ built-in function uses the mode which corresponds to the C data
+ type @code{float}.
+
+ @cindex @code{rint@var{m}2} instruction pattern
+ @item @samp{rint@var{m}2}
+ Store the argument rounded to nearest integer.
+
+ The @code{rint} built-in function of C always uses the mode which
+ corresponds to the C data type @code{double} and the @code{rintf}
+ 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}
Store into operand 0 one plus the index of the least significant 1-bit