forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

EE-GCC and __restrict

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development
View previous topic :: View next topic  
Author Message
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Tue Feb 07, 2006 9:22 am    Post subject: EE-GCC and __restrict Reply with quote

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:

static inline sillyCopy(int* __restrict dest, const int* __restrict src, int size)
{
 for (int i = 0; i < size; ++i)
 {
  dest[i+0] = src[i+0];
  dest[i+1] = src[i+1];
  dest[i+2] = src[i+0];
  dest[i+3] = src[i+1];
 }
}

int* data;
int* data2;

void main()
{
 sillyCopy(data2,data,200);
}

(compile with: ee-gcc -O2 -S -std=c99 -o out.s in.c)


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:

--- gcc-3.2.2-base/gcc/integrate.c   2003-02-03 21:56:29.000000000 +0100
+++ gcc-3.2.2/gcc/integrate.c   2006-02-06 18:10:07.000000000 +0100
@@ -358,12 +358,18 @@
   /* Copy the declaration.  */
   if (TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL)
     {
+      tree type;
+      type = TREE_TYPE(decl);
+
       /* For a parameter, we must make an equivalent VAR_DECL, not a
     new PARM_DECL.  */
       copy = build_decl (VAR_DECL, DECL_NAME (decl), TREE_TYPE (decl));
       TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (decl);
       TREE_READONLY (copy) = TREE_READONLY (decl);
       TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (decl);
+
+      if (TYPE_RESTRICT(type))
+        DECL_POINTER_ALIAS_SET (copy) = -2;
     }
   else
     {


This simple fix doesn't work on the PSP-toolchain however, since restricted pointers seems to be broken 4.0.2.
_________________
GE Dominator
Back to top
View user's profile Send private message
evilo



Joined: 22 Apr 2004
Posts: 230

PostPosted: Wed Aug 23, 2006 11:01 pm    Post subject: Reply with quote

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

seems to be a very nice optimisation when using inline !
_________________
http://psxdev.info/evilo/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group