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]

[PATCH] Tidy up builtins.def and add fmod built-in.



This patch was orginally an attempt to just tidy up the built-in
function definitions in builtins.def.  The intention was to remove
the special cases, defining abort, abs, exit, _exit, _Exit, fabs,
fabsf, fabsl and labs using the same mechanisms as the other built-ins.
This allows use to get rid of DEF_LIB_ALWAYS_BUILTIN.

I then went the extra step and also removed DEF_UNUSED_BUILTIN.
Unfortunately, a bootstrap revealed that some of "unused built-ins"
were used more than others :>.  The Java front-end uses the enum
value BUILT_IN_FMOD to define a fmod(3) function for the java
front-end.

The obvious solution is to provide fmod, fmodf and fmodl mathematical
functions in the generic code, and then tweak the java front-end to use
this new built-in.  This also gets us one step closer to implementing
it via optabs, and then having it inlined on x86 using "fprem1".
This should help the performance of Java's "drem" bytecode on IA-32 :>

The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", all languages except Ada and treelang, and a complete
"make -k check" with no new regressions.

Ok for mainline?


2003-02-22  Roger Sayle  <roger at eyesopen dot com>

	* builtins.def (DEF_LIB_ALWAYS_BUILTIN, DEF_UNUSED_BUILTIN): Delete.
	(abs, labs, fabs, fabsf, fabsl, abort, exit, _exit, _Exit):  Use
	the appropriate macro to define built-in function.
	(fmod,fmodf,fmodl): New built-in functions.

	* doc/extend.texi (fmod,fmodf,fmodl): Document new built-ins.

	* java/decl.c (java_init_decl_processing): Get soft_fmod_node from
	built_in_decls[BUILT_IN_FMOD] rather than define it ourselves.


Index: builtins.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.def,v
retrieving revision 1.43
diff -c -3 -p -r1.43 builtins.def
*** builtins.def	7 Feb 2003 22:37:53 -0000	1.43
--- builtins.def	22 Feb 2003 22:51:30 -0000
*************** Software Foundation, 59 Temple Place - S
*** 99,111 ****
    DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, TYPE,	\
  	       true, true, false, ATTRS, true)

- /* Like DEF_LIB_BUILTIN, except that a call to the builtin should
-    never fall back to the library version.  */
- #undef DEF_LIB_ALWAYS_BUILTIN
- #define DEF_LIB_ALWAYS_BUILTIN(ENUM, NAME, TYPE)	\
-   DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, TYPE,	\
-     	       true, false, true, ATTR_CONST_NOTHROW_LIST, true)
-
  /* Like DEF_LIB_BUILTIN, except that the function is not one that is
     specified by ANSI/ISO C.  So, when we're being fully conformant we
     ignore the version of these builtins that does not begin with
--- 99,104 ----
*************** Software Foundation, 59 Temple Place - S
*** 146,157 ****
    DEF_BUILTIN (ENUM, NAME, BUILT_IN_FRONTEND, TYPE, TYPE,	\
  	       true, true, true, ATTRS, true)

- /* A built-in that is not currently used.  */
- #undef DEF_UNUSED_BUILTIN
- #define DEF_UNUSED_BUILTIN(X)					\
-   DEF_BUILTIN (X, (const char *) NULL, NOT_BUILT_IN, BT_LAST,	\
- 	       BT_LAST, false, false, false, ATTR_NOTHROW_LIST, false)
-
  /* If SMALL_STACK is defined, then `alloca' is only defined in its
     `__builtin' form.  */
  #if SMALL_STACK
--- 139,144 ----
*************** DEF_EXT_LIB_BUILTIN(BUILT_IN_ALLOCA,
*** 166,187 ****
  		    ATTR_MALLOC_NOTHROW_LIST)
  #endif

! DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_ABS,
! 		       "__builtin_abs",
! 		       BT_FN_INT_INT)
! DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_LABS,
! 		       "__builtin_labs",
! 		       BT_FN_LONG_LONG)
!
! DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_FABS,
! 		       "__builtin_fabs",
! 		       BT_FN_DOUBLE_DOUBLE)
! DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_FABSF,
  		       "__builtin_fabsf",
! 		       BT_FN_FLOAT_FLOAT)
! DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_FABSL,
  		       "__builtin_fabsl",
! 		       BT_FN_LONG_DOUBLE_LONG_DOUBLE)

  DEF_LIB_BUILTIN(BUILT_IN_FLOOR,
                  "__builtin_floor",
--- 153,179 ----
  		    ATTR_MALLOC_NOTHROW_LIST)
  #endif

! DEF_LIB_BUILTIN(BUILT_IN_ABS,
! 		"__builtin_abs",
! 		BT_FN_INT_INT,
! 		ATTR_CONST_NOTHROW_LIST)
! DEF_LIB_BUILTIN(BUILT_IN_LABS,
! 		"__builtin_labs",
! 		BT_FN_LONG_LONG,
! 		ATTR_CONST_NOTHROW_LIST)
!
! DEF_LIB_BUILTIN(BUILT_IN_FABS,
! 		"__builtin_fabs",
! 		BT_FN_DOUBLE_DOUBLE,
! 		ATTR_CONST_NOTHROW_LIST)
! DEF_C99_C90RES_BUILTIN(BUILT_IN_FABSF,
  		       "__builtin_fabsf",
! 		       BT_FN_FLOAT_FLOAT,
! 		       ATTR_CONST_NOTHROW_LIST)
! DEF_C99_C90RES_BUILTIN(BUILT_IN_FABSL,
  		       "__builtin_fabsl",
! 		       BT_FN_LONG_DOUBLE_LONG_DOUBLE,
! 		       ATTR_CONST_NOTHROW_LIST)

  DEF_LIB_BUILTIN(BUILT_IN_FLOOR,
                  "__builtin_floor",
*************** DEF_C99_BUILTIN(BUILT_IN_CIMAGL,
*** 293,305 ****
  		BT_FN_LONG_DOUBLE_COMPLEX_LONG_DOUBLE,
  		ATTR_CONST_NOTHROW_LIST)

- DEF_UNUSED_BUILTIN(BUILT_IN_DIV)
- DEF_UNUSED_BUILTIN(BUILT_IN_LDIV)
- DEF_UNUSED_BUILTIN(BUILT_IN_FFLOOR)
- DEF_UNUSED_BUILTIN(BUILT_IN_FCEIL)
- DEF_UNUSED_BUILTIN(BUILT_IN_FMOD)
- DEF_UNUSED_BUILTIN(BUILT_IN_FREM)
-
  /* The system prototypes for `bzero' and `bcmp' functions have many
     variations, so don't specify parameters to avoid conflicts.  The
     expand_* functions check the argument types anyway.  */
--- 285,290 ----
*************** DEF_LIB_BUILTIN(BUILT_IN_ATAN2,
*** 501,506 ****
--- 486,498 ----
  				: (flag_unsafe_math_optimizations
  				   ? ATTR_CONST_NOTHROW_LIST
  				   : ATTR_PURE_NOTHROW_LIST))
+ DEF_LIB_BUILTIN(BUILT_IN_FMOD,
+ 		"__builtin_fmod",
+ 		BT_FN_DOUBLE_DOUBLE_DOUBLE,
+ 		flag_errno_math ? ATTR_NOTHROW_LIST
+ 				: (flag_unsafe_math_optimizations
+ 				   ? ATTR_CONST_NOTHROW_LIST
+ 				   : ATTR_PURE_NOTHROW_LIST))
  DEF_C99_C90RES_BUILTIN(BUILT_IN_SQRTF,
  		       "__builtin_sqrtf",
  		       BT_FN_FLOAT_FLOAT,
*************** DEF_C99_C90RES_BUILTIN(BUILT_IN_ATAN2F,
*** 546,551 ****
--- 538,550 ----
  				       : (flag_unsafe_math_optimizations
  					  ? ATTR_CONST_NOTHROW_LIST
  					  : ATTR_PURE_NOTHROW_LIST))
+ DEF_C99_C90RES_BUILTIN(BUILT_IN_FMODF,
+ 		       "__builtin_fmodf",
+ 		       BT_FN_FLOAT_FLOAT_FLOAT,
+ 		       flag_errno_math ? ATTR_NOTHROW_LIST
+ 				       : (flag_unsafe_math_optimizations
+ 					  ? ATTR_CONST_NOTHROW_LIST
+ 					  : ATTR_PURE_NOTHROW_LIST))
  DEF_C99_C90RES_BUILTIN(BUILT_IN_SQRTL,
  		       "__builtin_sqrtl",
  		       BT_FN_LONG_DOUBLE_LONG_DOUBLE,
*************** DEF_C99_C90RES_BUILTIN(BUILT_IN_ATAN2L,
*** 591,596 ****
--- 590,602 ----
  				       : (flag_unsafe_math_optimizations
  					  ? ATTR_CONST_NOTHROW_LIST
  					  : ATTR_PURE_NOTHROW_LIST))
+ DEF_C99_C90RES_BUILTIN(BUILT_IN_FMODL,
+ 		       "__builtin_fmodl",
+ 		       BT_FN_LONG_DOUBLE_LONG_DOUBLE_LONG_DOUBLE,
+ 		       flag_errno_math ? ATTR_NOTHROW_LIST
+ 				       : (flag_unsafe_math_optimizations
+ 					  ? ATTR_CONST_NOTHROW_LIST
+ 					  : ATTR_PURE_NOTHROW_LIST))

  DEF_GCC_BUILTIN(BUILT_IN_INF,
  		"__builtin_inf",
*************** DEF_GCC_BUILTIN(BUILT_IN_EXPECT,
*** 857,898 ****
  		BT_FN_LONG_LONG_LONG,
  		ATTR_NULL)

- /* C++ extensions */
- DEF_UNUSED_BUILTIN(BUILT_IN_NEW)
- DEF_UNUSED_BUILTIN(BUILT_IN_VEC_NEW)
- DEF_UNUSED_BUILTIN(BUILT_IN_DELETE)
- DEF_UNUSED_BUILTIN(BUILT_IN_VEC_DELETE)
-
  /* Declare abort, exit, _exit and _Exit */
! DEF_BUILTIN (BUILT_IN_ABORT,
! 	     "__builtin_abort",
! 	     NOT_BUILT_IN,
! 	     BT_FN_VOID,
! 	     BT_FN_VOID,
! 	     1, 0, 0,
! 	     ATTR_NORETURN_NOTHROW_LIST, true)
!
! DEF_BUILTIN (BUILT_IN_EXIT,
! 	     "__builtin_exit",
! 	     NOT_BUILT_IN,
! 	     BT_FN_VOID_INT,
! 	     BT_FN_VOID_INT,
! 	     1, 0, 0,
! 	     ATTR_NORETURN_NOTHROW_LIST, true)
!
! DEF_BUILTIN (BUILT_IN__EXIT,
! 	     "__builtin__exit",
! 	     NOT_BUILT_IN,
! 	     BT_FN_VOID_INT,
! 	     BT_FN_VOID_INT,
! 	     1, 0, 1,
! 	     ATTR_NORETURN_NOTHROW_LIST, false)
!
! DEF_BUILTIN (BUILT_IN__EXIT2,
! 	     "__builtin__Exit",
! 	     NOT_BUILT_IN,
! 	     BT_FN_VOID_INT,
! 	     BT_FN_VOID_INT,
! 	     1, 0, !flag_isoc99,
! 	     ATTR_NORETURN_NOTHROW_LIST, false)

--- 863,883 ----
  		BT_FN_LONG_LONG_LONG,
  		ATTR_NULL)

  /* Declare abort, exit, _exit and _Exit */
! DEF_LIB_BUILTIN(BUILT_IN_ABORT,
! 		 "__builtin_abort",
! 		BT_FN_VOID,
! 		ATTR_NORETURN_NOTHROW_LIST)
! DEF_LIB_BUILTIN(BUILT_IN_EXIT,
! 		"__builtin_exit",
! 		BT_FN_VOID_INT,
! 		ATTR_NORETURN_NOTHROW_LIST)
! DEF_EXT_LIB_BUILTIN(BUILT_IN__EXIT,
! 		    "__builtin__exit",
! 		    BT_FN_VOID_INT,
! 		    ATTR_NORETURN_NOTHROW_LIST)
! DEF_C99_BUILTIN(BUILT_IN__EXIT2,
! 		"__builtin__Exit",
! 		BT_FN_VOID_INT,
! 		ATTR_NORETURN_NOTHROW_LIST)

Index: java/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/decl.c,v
retrieving revision 1.150
diff -c -3 -p -r1.150 decl.c
*** java/decl.c	12 Feb 2003 23:39:50 -0000	1.150
--- java/decl.c	22 Feb 2003 22:51:30 -0000
*************** java_init_decl_processing (void)
*** 885,906 ****
  			build_function_type (ptr_type_node, t),
  			0, NOT_BUILT_IN, NULL, NULL_TREE);

-   t = tree_cons (NULL_TREE, double_type_node,
- 		 tree_cons (NULL_TREE, double_type_node, endlink));
-   soft_fmod_node
-     = builtin_function ("__builtin_fmod",
- 			build_function_type (double_type_node, t),
- 			BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmod", NULL_TREE);
-
- #if 0
-   t = tree_cons (NULL_TREE, float_type_node,
- 		 tree_cons (NULL_TREE, float_type_node, endlink));
-   soft_fmodf_node
-     = builtin_function ("__builtin_fmodf",
- 			build_function_type (float_type_node, t),
- 			BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmodf", NULL_TREE);
- #endif
-
    soft_idiv_node
      = builtin_function ("_Jv_divI",
  			build_function_type (int_type_node, t),
--- 885,890 ----
*************** java_init_decl_processing (void)
*** 928,935 ****
    lang_eh_runtime_type = prepare_eh_table_type;

    init_jcf_parse ();
!
    initialize_builtins ();
  }


--- 912,924 ----
    lang_eh_runtime_type = prepare_eh_table_type;

    init_jcf_parse ();
!
    initialize_builtins ();
+
+   soft_fmod_node = built_in_decls[BUILT_IN_FMOD];
+ #if 0
+   soft_fmodf_node = built_in_decls[BUILT_IN_FMODF];
+ #endif
  }


Index: doc/extend.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/extend.texi,v
retrieving revision 1.121
diff -c -3 -p -r1.121 extend.texi
*** doc/extend.texi	18 Feb 2003 10:51:57 -0000	1.121
--- doc/extend.texi	22 Feb 2003 22:51:32 -0000
***************
*** 1,4 ****
! @c Copyright (C) 1988,1989,1992,1993,1994,1996,1998,1999,2000,2001,2002,2003 Free Software Foundation, Inc.
  @c This is part of the GCC manual.
  @c For copying conditions, see the file gcc.texi.

--- 1,5 ----
! @c Copyright (C) 1988,1989,1992,1993,1994,1996,1998,1999,2000,2001,2002,
! @c 2003 Free Software Foundation, Inc.
  @c This is part of the GCC manual.
  @c For copying conditions, see the file gcc.texi.

*************** v4si f (v4si a, v4si b, v4si c)
*** 4537,4542 ****
--- 4538,4546 ----
  @findex atan2l
  @findex bcmp
  @findex bzero
+ @findex ceil
+ @findex ceilf
+ @findex ceill
  @findex cimag
  @findex cimagf
  @findex cimagl
*************** v4si f (v4si a, v4si b, v4si c)
*** 4559,4564 ****
--- 4563,4574 ----
  @findex fabsf
  @findex fabsl
  @findex ffs
+ @findex floor
+ @findex floorf
+ @findex floorl
+ @findex fmod
+ @findex fmodf
+ @findex fmodl
  @findex fprintf
  @findex fprintf_unlocked
  @findex fputs
*************** v4si f (v4si a, v4si b, v4si c)
*** 4573,4584 ****
--- 4583,4600 ----
  @findex memcmp
  @findex memcpy
  @findex memset
+ @findex nearbyint
+ @findex nearbyintf
+ @findex nearbyintl
  @findex pow
  @findex powf
  @findex powl
  @findex printf
  @findex printf_unlocked
  @findex rindex
+ @findex round
+ @findex roundf
+ @findex roundl
  @findex sin
  @findex sinf
  @findex sinl
*************** v4si f (v4si a, v4si b, v4si c)
*** 4598,4618 ****
  @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 nearbyint
- @findex nearbyintf
- @findex nearbyintl

  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
--- 4614,4622 ----
*************** be emitted.
*** 4633,4671 ****

  @opindex ansi
  @opindex std
! The functions @code{abort}, @code{exit}, @code{_Exit} and @code{_exit}
! are recognized and presumed not to return, but otherwise are not built
! in.  @code{_exit} is not recognized in strict ISO C mode (@option{-ansi},
! @option{-std=c89} or @option{-std=c99}).  @code{_Exit} is not recognized in
! strict C89 mode (@option{-ansi} or @option{-std=c89}).  All these functions
! have corresponding versions prefixed with @code{__builtin_}, which may be
! used even in strict C89 mode.
!
! Outside strict ISO C mode, the functions @code{alloca}, @code{bcmp},
! @code{bzero}, @code{index}, @code{rindex}, @code{ffs}, @code{fputs_unlocked},
! @code{printf_unlocked} and @code{fprintf_unlocked} may be handled as
! built-in functions.  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},
  @code{llabs}, @code{imaxabs}, @code{round}, @code{roundf}, @code{roundl},
  @code{trunc}, @code{truncf}, @code{truncl}, @code{nearbyint},
  @code{nearbyintf} and @code{nearbyintl} are handled as built-in functions
! except in strict ISO C90 mode.

  There are also built-in versions of the ISO C99 functions @code{atan2f},
  @code{atan2l}, @code{ceilf}, @code{ceill}, @code{cosf}, @code{cosl},
  @code{expf}, @code{expl}, @code{fabsf}, @code{fabsl}, @code{floorf},
! @code{floorl}, @code{logf}, @code{logl}, @code{powf}, @code{powl},
  @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{atan2}, @code{ceil}, @code{cos},
! @code{exp}, @code{fabs}, @code{floor},
  @code{fprintf}, @code{fputs}, @code{labs}, @code{log},
  @code{memcmp}, @code{memcpy}, @code{memset}, @code{pow}, @code{printf},
  @code{sin}, @code{sqrt}, @code{strcat}, @code{strchr}, @code{strcmp},
--- 4637,4672 ----

  @opindex ansi
  @opindex std
! Outside strict ISO C mode (@option{-ansi}, @option{-std=c89} or
! @option{-std=c99}), the functions @code{alloca}, @code{bcmp},
! @code{bzero}, @code{_exit}, @code{ffs}, @code{fprintf_unlocked},
! @code{fputs_unlocked}, @code{index}, @code{printf_unlocked},
! and @code{rindex} may be handled as built-in functions.
! 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},
+ @code{_Exit},
  @code{llabs}, @code{imaxabs}, @code{round}, @code{roundf}, @code{roundl},
  @code{trunc}, @code{truncf}, @code{truncl}, @code{nearbyint},
  @code{nearbyintf} and @code{nearbyintl} are handled as built-in functions
! except in strict ISO C90 mode (@option{-ansi} or @option{-std=c89}).

  There are also built-in versions of the ISO C99 functions @code{atan2f},
  @code{atan2l}, @code{ceilf}, @code{ceill}, @code{cosf}, @code{cosl},
  @code{expf}, @code{expl}, @code{fabsf}, @code{fabsl}, @code{floorf},
! @code{floorl}, @code{fmodf}, @code{fmodl},
! @code{logf}, @code{logl}, @code{powf}, @code{powl},
  @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{abort}, @code{abs}, @code{atan2}, @code{ceil},
! @code{cos}, @code{exit},
! @code{exp}, @code{fabs}, @code{floor}, @code{fmod},
  @code{fprintf}, @code{fputs}, @code{labs}, @code{log},
  @code{memcmp}, @code{memcpy}, @code{memset}, @code{pow}, @code{printf},
  @code{sin}, @code{sqrt}, @code{strcat}, @code{strchr}, @code{strcmp},

Roger
--
Roger Sayle,                         E-mail: roger at eyesopen dot com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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