Date: Sun, 02 Jul 2000 17:35:30 -0700 From: Peter Wemm <peter@netplex.com.au> To: John Polstra <jdp@polstra.com> Cc: hackers@FreeBSD.ORG Subject: Re: GCC extended asm experts please look at this Message-ID: <20000703003530.9B6AB1CD7@overcee.netplex.com.au> In-Reply-To: Message from John Polstra <jdp@polstra.com> of "Sun, 02 Jul 2000 15:01:04 PDT." <XFMail.000702150104.jdp@polstra.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000703003530.9B6AB1CD7>