[PATCH] data prefetch support and __builtin_prefetch (take 2)

Janis Johnson janis187@us.ibm.com
Wed Dec 5 17:27:00 GMT 2001


Here's a patch that I'm currently bootstrapping and testing that changes
__builtin_prefetch so that arguments 1 and 2 are optional and default to
zero. allowing current uses of this function on ARM systems to continue
to work.  I'm posting it now hoping it will save some time by letting
Richard Earnshaw to see it early in his day.  I'll send mail tomorrow
about the results of my bootstrap and testing efforts.

2001-12-05  Janis Johnson  <janis187@us.ibm.com>

	* builtin-types.def (BT_FN_VOID_PTR_VAR): New.
	* builtins.def (BUILT_IN_PREFETCH): Change arguments.
	* builtins.c (expand_builtin_prefetch): Two arguments are now
	  optional and default to zero.
	* doc/extend.texi (__builtin_prefetch): Update documentation.
	* doc/md.texi (prefetch): Add documentation.

	* gcc.c-torture/execute/builtin-prefetch-1.c: Add checks for
	  variable argument list.

Index: gcc/builtin-types.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtin-types.def,v
retrieving revision 1.3
diff -u -p -r1.3 builtin-types.def
--- builtin-types.def	2001/12/04 00:49:10	1.3
+++ builtin-types.def	2001/12/05 23:23:46
@@ -167,6 +167,8 @@ DEF_FUNCTION_TYPE_VAR_0 (BT_FN_PTR_VAR, 
 
 DEF_FUNCTION_TYPE_VAR_1 (BT_FN_VOID_VALIST_REF_VAR, 
 			 BT_VOID, BT_VALIST_REF)
+DEF_FUNCTION_TYPE_VAR_1 (BT_FN_VOID_PTR_VAR,
+			 BT_VOID, BT_PTR)
 DEF_FUNCTION_TYPE_VAR_1 (BT_FN_INT_CONST_STRING_VAR,
 	                 BT_INT, BT_CONST_STRING)
 
Index: gcc/builtins.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.def,v
retrieving revision 1.24
diff -u -p -r1.24 builtins.def
--- builtins.def	2001/12/04 00:49:50	1.24
+++ builtins.def	2001/12/05 23:23:57
@@ -338,7 +338,7 @@ DEF_GCC_BUILTIN(BUILT_IN_TRAP,
 		BT_FN_VOID)
 DEF_GCC_BUILTIN(BUILT_IN_PREFETCH,
 		"__builtin_prefetch",
-		BT_FN_VOID_PTR_INT_INT)
+		BT_FN_VOID_PTR_VAR)
 
 /* Stdio builtins.  */
 DEF_FALLBACK_BUILTIN(BUILT_IN_PUTCHAR,
Index: gcc/builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.130
diff -u -p -r1.130 builtins.c
--- builtins.c	2001/12/05 22:37:25	1.130
+++ builtins.c	2001/12/05 23:24:13
@@ -727,9 +727,21 @@ expand_builtin_prefetch (arglist)
   tree arg0, arg1, arg2;
   rtx op0, op1, op2;
 
+  if (!validate_arglist (arglist, POINTER_TYPE, 0))
+    return;
+
   arg0 = TREE_VALUE (arglist);
-  arg1 = TREE_VALUE (TREE_CHAIN (arglist));
-  arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
+  /* Arguments 1 and 2 are optional and default to zero.  */
+  if (TREE_CHAIN (arglist))
+    {
+      arg1 = TREE_VALUE (TREE_CHAIN (arglist));
+      if (TREE_CHAIN (TREE_CHAIN (arglist)))
+        arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
+      else
+	arg2 = integer_zero_node;
+    }
+  else
+      arg1 = arg2 = integer_zero_node;
 
   /* Argument 0 is an address.  */
   op0 = expand_expr (arg0, NULL_RTX, Pmode, EXPAND_NORMAL);
Index: gcc/doc/extend.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/extend.texi,v
retrieving revision 1.40
diff -u -p -r1.40 extend.texi
--- extend.texi	2001/12/05 22:37:31	1.40
+++ extend.texi	2001/12/05 23:24:28
@@ -4442,7 +4442,7 @@ if (__builtin_expect (ptr != NULL, 1))
 when testing pointer or floating-point values.
 @end deftypefn
 
-@deftypefn {Built-in Function} void __builtin_prefetch (void *@var{addr}, int @var{rw}, int @var{locality})
+@deftypefn {Built-in Function} void __builtin_prefetch (void *@var{addr}, ...)
 This function is used to minimize cache-miss latency by moving data into
 a cache before it is accessed.
 You can insert calls to @code{__builtin_prefetch} into code for which
@@ -4452,6 +4452,8 @@ If the prefetch is done early enough bef
 be in the cache by the time it is accessed.
 
 The value of @var{addr} is the address of the memory to prefetch.
+There are two optional arguments, @var{rw} and @var{locality}, whose
+values default to zero.
 The value of @var{rw} is a compile-time constant one or zero; one
 means that the prefetch is preparing for a write to the memory address.
 The value @var{locality} must be a compile-time constant integer between
Index: gcc/doc/md.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/md.texi,v
retrieving revision 1.27
diff -u -p -r1.27 md.texi
--- md.texi	2001/11/14 20:17:08	1.27
+++ md.texi	2001/12/05 23:24:42
@@ -3015,6 +3015,22 @@ A typical @code{conditional_trap} patter
   "@dots{}")
 @end smallexample
 
+@cindex @code{prefetch} instruction pattern
+@item @samp{prefetch}
+
+This pattern, if defined, emits code for a non-faulting data prefetch
+instruction.  Operand 0 is the address of the memory to prefetch.  Operand 1
+is a constant 1 if the prefetch is preparing for a write to the memory
+address, or a constant 0 otherwise.  Operand 2 is the expected degree of
+temporal locality of the data and is a value between 0 and 3, inclusive; 0
+means that the data has no temporal locality, so it need not be left in the
+cache after the access; 3 means that the data has a high degree of temporal
+locality and should be left in all levels of cache possible;  1 and 2 mean,
+respectively, a low or moderate degree of temporal locality.
+
+Targets that do not support write prefetches or locality hints can ignore
+the values of operands 1 and 2.
+
 @cindex @code{cycle_display} instruction pattern
 @item @samp{cycle_display}
 
Index: gcc/testsuite/gcc.c-torture/execute/builtin-prefetch-1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.c-torture/execute/builtin-prefetch-1.c,v
retrieving revision 1.1
diff -u -p -r1.1 builtin-prefetch-1.c
--- builtin-prefetch-1.c	2001/12/04 00:54:21	1.1
+++ builtin-prefetch-1.c	2001/12/05 23:24:53
@@ -49,11 +49,21 @@ good_expr (int *p)
   __builtin_prefetch (p, 1 + 0, 1 + 2);
 }
 
+void
+good_vararg (int *p)
+{
+  __builtin_prefetch (p, 0, 0);
+  __builtin_prefetch (p, 0);
+  __builtin_prefetch (p, 1);
+  __builtin_prefetch (p);
+}
+
 int
 main ()
 {
   good_const (arr);
   good_enum (arr);
   good_expr (arr);
+  good_vararg (arr);
   exit (0);
 }



More information about the Gcc-patches mailing list