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 - [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED]
"All of this is for nothing if we don't go to the stars" - JMS/B5
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message