EE-GCC and __restrict

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

EE-GCC and __restrict

Post by chp »

This patch will enable __restrict to work on functions that are inlined. A simple example on code that will build into more proper code is the following:

Code: Select all

static inline sillyCopy(int* __restrict dest, const int* __restrict src, int size)
{
 for &#40;int i = 0; i < size; ++i&#41;
 &#123;
  dest&#91;i+0&#93; = src&#91;i+0&#93;;
  dest&#91;i+1&#93; = src&#91;i+1&#93;;
  dest&#91;i+2&#93; = src&#91;i+0&#93;;
  dest&#91;i+3&#93; = src&#91;i+1&#93;;
 &#125; 
&#125;

int* data;
int* data2;

void main&#40;&#41;
&#123;
 sillyCopy&#40;data2,data,200&#41;;
&#125;

&#40;compile with&#58; ee-gcc -O2 -S -std=c99 -o out.s in.c&#41;
Without the patch, it will consider the parameters to be aliased and read data for every operation. With the patch, it will properly consider the parameters as not being aliased against each other and only fetch data twice for every four writes.

Oh, and the patch in question. This patch is derived from looking on why the cell-toolchain managed to inline code that normal GCC didn't.

Code: Select all

--- gcc-3.2.2-base/gcc/integrate.c	2003-02-03 21&#58;56&#58;29.000000000 +0100
+++ gcc-3.2.2/gcc/integrate.c	2006-02-06 18&#58;10&#58;07.000000000 +0100
@@ -358,12 +358,18 @@
   /* Copy the declaration.  */
   if &#40;TREE_CODE &#40;decl&#41; == PARM_DECL || TREE_CODE &#40;decl&#41; == RESULT_DECL&#41;
     &#123;
+      tree type;
+      type = TREE_TYPE&#40;decl&#41;;
+
       /* For a parameter, we must make an equivalent VAR_DECL, not a
 	 new PARM_DECL.  */
       copy = build_decl &#40;VAR_DECL, DECL_NAME &#40;decl&#41;, TREE_TYPE &#40;decl&#41;&#41;;
       TREE_ADDRESSABLE &#40;copy&#41; = TREE_ADDRESSABLE &#40;decl&#41;;
       TREE_READONLY &#40;copy&#41; = TREE_READONLY &#40;decl&#41;;
       TREE_THIS_VOLATILE &#40;copy&#41; = TREE_THIS_VOLATILE &#40;decl&#41;;
+
+      if &#40;TYPE_RESTRICT&#40;type&#41;&#41;
+        DECL_POINTER_ALIAS_SET &#40;copy&#41; = -2;
     &#125;
   else
     &#123;
This simple fix doesn't work on the PSP-toolchain however, since restricted pointers seems to be broken 4.0.2.
GE Dominator
User avatar
evilo
Posts: 230
Joined: Thu Apr 22, 2004 8:40 pm
Contact:

Post by evilo »

Opoo, is this patch been integrated into the PS2 toolchain ?

seems to be a very nice optimisation when using inline !
Post Reply