[Bug inline-asm/33171] GCC outputs invalid assembly when using -O2

pinskia at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Fri Aug 24 09:02:00 GMT 2007



------- Comment #3 from pinskia at gcc dot gnu dot org  2007-08-24 09:02 -------
No, the inline-asm is just wrong, you need to use a different thing for
including non indexed load/stores.

The inline-asm function should be written as:
static inline unsigned long
load_acquire(volatile unsigned long *addr)
{
  unsigned long result;

  __asm__ __volatile__ (
    "lwz%X1 %0,%1\n"
    "cmpw cr7,%0,%0\n"
    "bne- cr7,1f\n"
    "1: isync\n"
    : "=r" (result)
    : "m"(*addr) : "memory", "cc");
  return result;
}

Though I will make a mention this is not really atomic at all.  You need to use
lwarx/stwcx to be atomic.  Also lwsync should be used instead of isync (IIRC).


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33171



More information about the Gcc-bugs mailing list