linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* asm inline
@ 2002-11-29 16:08 Samuel Rydh
  2002-11-29 16:21 ` Gabriel Paubert
  2002-11-29 16:30 ` Benjamin Herrenschmidt
  0 siblings, 2 replies; 20+ messages in thread
From: Samuel Rydh @ 2002-11-29 16:08 UTC (permalink / raw)
  To: linuxppc-dev


I just noticed that gcc 3.1 doesn't like the following:

static __inline__ void st_le32( ulong *addr, ulong val )
{
        __asm__ __volatile__( "stwbrx %1,0,%2"
				: "=m" (*addr)
				: "r" (val), "r" (addr) );
}

The compiler misses the fact that *addr is modified and will happily
turn the following

	st_le32( &b, 1UL << i );
	testing( b )

into something like

	addi	r31,r1,28
	...
	lwz	r3,28(r1)	; loading b
	stwbrx	r9,0,r31
	bl	testing

The real world example looked like this:

    int i,b;
    for( i=0; i<=30; i++ ) {
        st_le32( &b, 1UL<<i );
        printf("dbg:  %d %08lx b=%08lx\n", i, pic.reg[r_flag], b );
        if( pic.reg[r_flag] & b )
            break;
    }

Adding "memory" to the clobber list seems to be the only way to make
gcc do the right thing :-(.

/Samuel


Btw. I'm using gcc 3.1 cross compiled for x86.

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2002-12-02 19:17 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-29 16:08 asm inline Samuel Rydh
2002-11-29 16:21 ` Gabriel Paubert
2002-11-29 17:49   ` Samuel Rydh
2002-12-02 11:17     ` Franz Sirl
2002-12-02 13:11       ` Samuel Rydh
2002-12-02 13:35         ` Andreas Schwab
2002-12-02 14:14           ` Kevin B. Hendricks
2002-12-02 14:29             ` Andreas Schwab
2002-12-02 14:37               ` Kevin B. Hendricks
2002-12-02 14:51                 ` Franz Sirl
2002-12-02 15:08                   ` Kevin B. Hendricks
2002-12-02 15:11                   ` Kevin B. Hendricks
2002-12-02 15:35                     ` Franz Sirl
2002-12-02 15:45                       ` Kevin B. Hendricks
2002-12-02 15:12         ` Franz Sirl
2002-12-02 17:00           ` Samuel Rydh
2002-12-02 17:53             ` Gabriel Paubert
2002-12-02 19:17               ` Samuel Rydh
2002-11-29 16:30 ` Benjamin Herrenschmidt
2002-12-02 14:29   ` Gabriel Paubert

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 NNTP newsgroup(s).