This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[3.4-BIB] Add trunc/round/floor/ceil/rint builtins


Hi,
this if the first change that adds the new builtins.
Later I would like to add lrint and frinds too together with code simplifying
rint to lrint and so on.  I've found several occurences of these in mesa,
crystal space and other 3d internal loops.
Just first step :)

Honza

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.
	* md.texi: Document new named patterns.

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 10:12:28 -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 10:12:28 -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_LIB_ALWAYS_BUILTIN(BUILT_IN_CEIL,
+ 		       "__builtin_ceil",
+ 		       BT_FN_DOUBLE_DOUBLE)
+ DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_CEILF,
+ 		       "__builtin_ceilf",
+ 		       BT_FN_FLOAT_FLOAT)
+ DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_CEILL,
+ 		       "__builtin_ceill",
+ 		       BT_FN_LONG_DOUBLE_LONG_DOUBLE)
+ 
+ DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_ROUND,
+ 		       "__builtin_round",
+ 		       BT_FN_DOUBLE_DOUBLE)
+ DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_ROUNDF,
+ 		       "__builtin_roundf",
+ 		       BT_FN_FLOAT_FLOAT)
+ DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_ROUNDL,
+ 		       "__builtin_roundl",
+ 		       BT_FN_LONG_DOUBLE_LONG_DOUBLE)
+ 
+ DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_TRUNC,
+ 		       "__builtin_trunc",
+ 		       BT_FN_DOUBLE_DOUBLE)
+ DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_TRUNCF,
+ 		       "__builtin_truncf",
+ 		       BT_FN_FLOAT_FLOAT)
+ DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_TRUNCL,
+ 		       "__builtin_truncl",
+ 		       BT_FN_LONG_DOUBLE_LONG_DOUBLE)
+ 
+ DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_RINT,
+ 		       "__builtin_rint",
+ 		       BT_FN_DOUBLE_DOUBLE)
+ DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_RINTF,
+ 		       "__builtin_rintf",
+ 		       BT_FN_FLOAT_FLOAT)
+ DEF_LIB_ALWAYS_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 10:12:34 -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 10:12:35 -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 10:12:35 -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/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 10:12:45 -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 operandUILT_IN_SINL, BUILT_IN_NORMAL, "sinl", NULL_TREE);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]