Commit 84dff710 authored by parcs's avatar parcs
Browse files

Fix the definition of cas() on x86 (#8219)

*p is both read and written to by the cmpxchg instruction, and therefore
should be given the '+' constraint modifier.

(In GCC's extended ASM language, '+' means that the operand is both read
and written to whereas '=' means that it is only written to.)

Otherwise, the compiler is allowed to rewrite something like

SpinLock lock;
initSpinLock(&lock);       /* sets lock = 1 */
ACQUIRE_SPIN_LOCK(&lock);

into

SpinLock lock;
ACQUIRE_SPIN_LOCK(&lock);

because according to the asm statement, the previous value of 'lock' is
not important.
parent 93a04b49
......@@ -173,7 +173,7 @@ cas(StgVolatilePtr p, StgWord o, StgWord n)
#if i386_HOST_ARCH || x86_64_HOST_ARCH
__asm__ __volatile__ (
"lock\ncmpxchg %3,%1"
:"=a"(o), "=m" (*(volatile unsigned int *)p)
:"=a"(o), "+m" (*(volatile unsigned int *)p)
:"0" (o), "r" (n));
return o;
#elif powerpc_HOST_ARCH
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment