[commit: ghc] master: Fix the definition of cas() on x86 (#8219) (84dff71)

git at git.haskell.org git at git.haskell.org
Mon Sep 23 15:12:38 CEST 2013


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/84dff71075b915938e2457f5bff2d127eac3b3cc/ghc

>---------------------------------------------------------------

commit 84dff71075b915938e2457f5bff2d127eac3b3cc
Author: Patrick Palka <patrick at parcs.ath.cx>
Date:   Sat Sep 21 13:27:13 2013 -0400

    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.


>---------------------------------------------------------------

84dff71075b915938e2457f5bff2d127eac3b3cc
 includes/stg/SMP.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/includes/stg/SMP.h b/includes/stg/SMP.h
index 07ea522..471e8f9 100644
--- a/includes/stg/SMP.h
+++ b/includes/stg/SMP.h
@@ -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




More information about the ghc-commits mailing list