From owner-freebsd-hackers Sun Jul 2 17:35:43 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from overcee.netplex.com.au (peter1.corp.yahoo.com [208.48.107.4]) by hub.freebsd.org (Postfix) with ESMTP id 10F2737C240 for ; Sun, 2 Jul 2000 17:35:31 -0700 (PDT) (envelope-from peter@netplex.com.au) Received: from netplex.com.au (localhost [127.0.0.1]) by overcee.netplex.com.au (Postfix) with ESMTP id 9B6AB1CD7; Sun, 2 Jul 2000 17:35:30 -0700 (PDT) (envelope-from peter@netplex.com.au) X-Mailer: exmh version 2.1.1 10/15/1999 To: John Polstra Cc: hackers@FreeBSD.ORG Subject: Re: GCC extended asm experts please look at this In-Reply-To: Message from John Polstra of "Sun, 02 Jul 2000 15:01:04 PDT." Date: Sun, 02 Jul 2000 17:35:30 -0700 From: Peter Wemm Message-Id: <20000703003530.9B6AB1CD7@overcee.netplex.com.au> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG John Polstra wrote: > I _thought_ I was an expert in gcc's extended asm feature, but I > can't figure out why this won't compile when optmization is > disabled: > > ============================================================================= == > #define xchgl(v, m) ({ \ > int __result; \ > __asm __volatile ("xchgl %0, %1" \ > : "=r"(__result), "=m"(m) \ > : "0"(v), "1"(m)); \ > (__result); }) > > void > lock80386_acquire(volatile int *lock) > { > while (xchgl(1, *lock) != 0) > while (*lock != 0) > ; > } > ============================================================================= == > > It compiles and works fine with -O or higher; but without -O gcc > says: > > locktest.c: In function `lock80386_acquire': > locktest.c:11: inconsistent operand constraints in an `asm' > > This happens with both gcc-2.95.2 (the version in -current) and with > the much older gcc-2.7.2.3. > > I believe the code is correct according to the documentation in the > gcc info pages. I tried changing several things anyway to make it > more conservative, but I haven't been able to make it compile > without optimization. If I change it to use a static inline function, it seems to work and will generate identical code (with -O): static inline int xchgl(int v, volatile int *m) { int __result; __asm __volatile ("xchgl %0, %1" : "=r"(__result), "=m"(*m) : "0"(v), "1"(*m)); return __result; } void lock80386_acquire(volatile int *lock) { while (xchgl(1, lock) != 0) while (*lock != 0) ; } It appears to generate valid code without -O, but I am not 100% sure. It is very inefficient without -O. (Beware the different indirection of "m") Cheers, -Peter -- Peter Wemm - peter@FreeBSD.org; peter@yahoo-inc.com; peter@netplex.com.au "All of this is for nothing if we don't go to the stars" - JMS/B5 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message