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]

Patch to create builtin bzero


	 This patch creates a new builtin bzero.  It operates by
adding a "zero" parameter and calling builtin memset.  This patch
depends on http://gcc.gnu.org/ml/gcc-patches/2000-03/msg00746.html

Bootstrapped on i686-pc-linux-gnu and sparc-sun-solaris2.7, no regressions.
Okay to install?

		--Kaveh


2000-03-21  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* builtins.c (expand_builtin_bzero): New function.
	(expand_builtin): Handle bzero.

	* builtins.def: Add BUILT_IN_BZERO.

	* c-common.c (c_common_nodes_and_builtins): Provide builtin
	prototype & function for bzero.

diff -rup orig/egcs-CVS20000321/gcc/builtins.c egcs-CVS20000321/gcc/builtins.c
--- orig/egcs-CVS20000321/gcc/builtins.c	Tue Mar 21 22:21:51 2000
+++ egcs-CVS20000321/gcc/builtins.c	Tue Mar 21 22:26:57 2000
@@ -97,6 +97,7 @@ static rtx expand_builtin_strncmp	PARAMS
 static rtx expand_builtin_memcpy	PARAMS ((tree));
 static rtx expand_builtin_strcpy	PARAMS ((tree));
 static rtx expand_builtin_memset	PARAMS ((tree));
+static rtx expand_builtin_bzero		PARAMS ((tree));
 static rtx expand_builtin_strlen	PARAMS ((tree, rtx,
 						 enum machine_mode));
 static rtx expand_builtin_alloca	PARAMS ((tree, rtx));
@@ -1575,6 +1576,38 @@ expand_builtin_memset (exp)
     }
 }
 
+/* Expand expression EXP, which is a call to the bzero builtin.  Return 0
+   if we failed the caller should emit a normal call.  */
+static rtx
+expand_builtin_bzero (exp)
+     tree exp;
+{
+  tree arglist = TREE_OPERAND (exp, 1);
+  
+  if (arglist == 0
+      /* Arg could be non-pointer if user redeclared this fcn wrong.  */
+      || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
+      || TREE_CHAIN (arglist) == 0
+      || (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist))))
+	  != INTEGER_TYPE))
+    return 0;
+  else
+    {
+      tree val = build_tree_list (NULL_TREE, integer_zero_node);
+      rtx result;
+      
+      /* Insert a zero parameter to convert bzero(x,y) -> memset(x,0,y).  */
+      TREE_CHAIN (val) = TREE_CHAIN (arglist);
+      TREE_CHAIN (arglist) = val;
+      result = expand_builtin_memset(exp);
+      
+      /* If the above call fails, delete the zero parameter.  */
+      if (result == 0)
+	TREE_CHAIN (arglist) = TREE_CHAIN (TREE_CHAIN (arglist));
+      return result;
+    }
+}
+
 #ifdef HAVE_cmpstrsi
 /* Expand expression EXP, which is a call to the memcmp or the strcmp builtin.
    ARGLIST is the argument list for this call.  Return 0 if we failed and the
@@ -2396,6 +2429,7 @@ expand_builtin (exp, target, subtarget, 
       && (fcode == BUILT_IN_SIN || fcode == BUILT_IN_COS
 	  || fcode == BUILT_IN_FSQRT || fcode == BUILT_IN_MEMSET
 	  || fcode == BUILT_IN_MEMCPY || fcode == BUILT_IN_MEMCMP
+	  || fcode == BUILT_IN_BZERO
 	  || fcode == BUILT_IN_STRLEN || fcode == BUILT_IN_STRCPY
 	  || fcode == BUILT_IN_STRCMP || fcode == BUILT_IN_STRNCMP
 	  || fcode == BUILT_IN_FFS))
@@ -2534,6 +2568,12 @@ expand_builtin (exp, target, subtarget, 
 	return target;
       break;
 
+    case BUILT_IN_BZERO:
+      target = expand_builtin_bzero (exp);
+      if (target)
+	return target;
+      break;
+      
 /* These comparison functions need an instruction that returns an actual
    index.  An ordinary compare that just sets the condition codes
    is not enough.  */
diff -rup orig/egcs-CVS20000321/gcc/builtins.def egcs-CVS20000321/gcc/builtins.def
--- orig/egcs-CVS20000321/gcc/builtins.def	Tue Mar 21 22:21:51 2000
+++ egcs-CVS20000321/gcc/builtins.def	Tue Mar 21 22:22:23 2000
@@ -33,6 +33,7 @@ DEF_BUILTIN(BUILT_IN_FREM)
 DEF_BUILTIN(BUILT_IN_MEMCPY)
 DEF_BUILTIN(BUILT_IN_MEMCMP)
 DEF_BUILTIN(BUILT_IN_MEMSET)
+DEF_BUILTIN(BUILT_IN_BZERO)
 DEF_BUILTIN(BUILT_IN_STRCPY)
 DEF_BUILTIN(BUILT_IN_STRCMP)
 DEF_BUILTIN(BUILT_IN_STRNCMP)
diff -rup orig/egcs-CVS20000321/gcc/c-common.c egcs-CVS20000321/gcc/c-common.c
--- orig/egcs-CVS20000321/gcc/c-common.c	Tue Mar 21 22:21:51 2000
+++ egcs-CVS20000321/gcc/c-common.c	Tue Mar 21 22:39:48 2000
@@ -3464,7 +3464,7 @@ c_common_nodes_and_builtins (cplus_mode,
 {
   tree temp;
   tree memcpy_ftype, memset_ftype, strlen_ftype;
-  tree strncmp_ftype;
+  tree strncmp_ftype, bzero_ftype;
   tree endlink, int_endlink, double_endlink, unsigned_endlink;
   tree sizetype_endlink;
   tree ptr_ftype, ptr_ftype_unsigned;
@@ -3602,6 +3602,12 @@ c_common_nodes_and_builtins (cplus_mode,
 							    sizetype,
 							    endlink))));
 
+  /* Prototype for bzero.  */
+  bzero_ftype
+    = build_function_type (void_type_node,
+			   tree_cons (NULL_TREE, traditional_ptr_type_node,
+				      traditional_len_endlink));
+
   builtin_function ("__builtin_constant_p", default_function_type,
 		    BUILT_IN_CONSTANT_P, BUILT_IN_NORMAL, NULL_PTR);
 
@@ -3615,6 +3621,8 @@ c_common_nodes_and_builtins (cplus_mode,
 		    BUILT_IN_ALLOCA, BUILT_IN_NORMAL, "alloca");
   builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS,
 		    BUILT_IN_NORMAL, NULL_PTR);
+  builtin_function ("__builtin_bzero", bzero_ftype, BUILT_IN_BZERO,
+		    BUILT_IN_NORMAL, "bzero");
   /* Define alloca, ffs as builtins.
      Declare _exit just to mark it as volatile.  */
   if (! no_builtins && ! no_nonansi_builtins)
@@ -3634,6 +3642,12 @@ c_common_nodes_and_builtins (cplus_mode,
       TREE_THIS_VOLATILE (temp) = 1;
       TREE_SIDE_EFFECTS (temp) = 1;
       /* Suppress error if redefined as a non-function.  */
+      DECL_BUILT_IN_NONANSI (temp) = 1;
+
+      /* In C mode, don't conflict with system prototype variations.  */
+      temp = builtin_function ("bzero",
+			       cplus_mode ? bzero_ftype : void_ftype_any,
+			       BUILT_IN_BZERO, BUILT_IN_NORMAL, NULL_PTR);
       DECL_BUILT_IN_NONANSI (temp) = 1;
     }
 

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