public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* GCC restrict between 'this' and another pointer
@ 2003-12-01 20:04 Wilson Snyder
  0 siblings, 0 replies; only message in thread
From: Wilson Snyder @ 2003-12-01 20:04 UTC (permalink / raw)
  To: gcc-help


/*

I'm working on improving the speed of a public domain translator I wrote
(for simulating circuits).  From profiling, the generated code is loosing a
lot due to load/store pressure.  Looking at the assember, it ueems that the
compiler is presuming pointer aliasing, and has about 2 times more mov's
then necessary.

So, can someone please tell me how to get rid of aliasing in the below
snippit?  I'm using:
	  .ident	"GCC: (GNU) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)"

There's member routine(s) that operate on this*, and on a number of global
structures referenced though a set of remote pointers.  None of the
pointers ever point to the same thing.  When solved, I'd expect
the code to look like the second function better() below.

Again, this is machine generated code, so the solution doesn't have to be
pretty, but can't involve copying the data (as the Rmt structure actually
has thousands of elements).

Thanks!

*/

struct Rmt {
    long remoteb;
};
Rmt* __restrict__ rmtp;

struct Lru {
    void better();
    void bad();
    long locala;
};

//--------------------

static inline void BIT(int bit, long& lhs,long rhs) {
    lhs = lhs | rhs<<(bit);
}

void Lru::bad() __restrict__ {
    // This is the version with all the extra mov's
    // The assignment below doesn't help...
    Rmt* __restrict__ rmtx = rmtp;
    //	 movl	      8(%ebp), %ebx
    BIT(1, locala, (rmtx->remoteb));
    //	   movl	   rmtp, %ecx
    //	   movl	   (%ecx), %eax
    //	   sall	   $1, %eax
    //	   orl	   (%ebx), %eax
    //	   movl	   %eax, (%ebx)
    BIT(2, locala, (rmtx->remoteb));
    //	   movl	   (%ecx), %edx
    //	   sall	   $2, %edx
    //	   orl	   %eax, %edx
    //	   movl	   %edx, (%ebx)
    BIT(3, locala, (rmtx->remoteb));
    //	   movl	   (%ecx), %eax
    //	   sall	   $3, %eax
    //	   orl	   %edx, %eax
    //	   movl	   %eax, (%ebx)
}

void Lru::better() {
    // Here's an example which removes the extra mov's
    // It's not a practical solution my program however
    long localb = rmtp->remoteb;
    //	 movl	8(%ebp), %ebx
    //	 movl	rmtp, %eax
    //	 movl	(%eax), %eax
    BIT(1, locala, localb);
    //	   leal	   (%eax,%eax), %edx
    //	   orl	   (%ebx), %edx
    BIT(2, locala, localb);
    //	   leal	   0(,%eax,4), %ecx
    //	   orl	   %edx, %ecx
    BIT(3, locala, localb);
    //	   sall	   $3, %eax
    //	   orl	   %ecx, %eax
    //	   movl	   %eax, (%ebx)
}

//###################################################################
// Local Variables:
// compile-command: "g++ -O1 -S restrict.cpp && cat restrict.s "
// End:

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-12-01 20:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-01 20:04 GCC restrict between 'this' and another pointer Wilson Snyder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).