Enable GCC atomics on x86 and amd64.
authorAlex Rønne Petersen <alexrp@xamarin.com>
Fri, 19 Jul 2013 01:20:14 +0000 (03:20 +0200)
committerAlex Rønne Petersen <alexrp@xamarin.com>
Sat, 20 Jul 2013 01:03:55 +0000 (03:03 +0200)
configure.in
mono/utils/atomic.h
mono/utils/mono-membar.h

index 240445e06ccd5ba727c9485dfeb75d134e886cae..70d780f5ea2443506e702368c60b432ec80468f9 100644 (file)
@@ -2761,6 +2761,15 @@ SPARC64)
        ;;
 esac
 
+dnl Use GCC atomic ops if they work on the target.
+if test x$GCC = "xyes"; then
+       case $TARGET in
+       X86 | AMD64)
+               AC_DEFINE(USE_GCC_ATOMIC_OPS, 1, [...])
+               ;;
+       esac
+fi
+
 if test "x$target_mach" = "xyes"; then
    if test "x$TARGET" = "xARM"; then
          AC_DEFINE(TARGET_IOS,1,[The JIT/AOT targets iOS])
index 94681c5daa7f6b575123dd3bddee276c99397e74..b89ad18dd089564974d459732cde5e51b6af3c7f 100644 (file)
@@ -116,111 +116,6 @@ static inline gint32 InterlockedExchangeAdd(volatile gint32 *val, gint32 add)
        return atomic_add_32_nv((uint32_t*)val, add) - add;
 }
 
-#elif defined(__i386__) || defined(__x86_64__)
-
-/*
- * NB: The *Pointer() functions here assume that
- * sizeof(pointer)==sizeof(gint32)
- *
- * NB2: These asm functions assume 486+ (some of the opcodes dont
- * exist on 386).  If this becomes an issue, we can get configure to
- * fall back to the non-atomic C versions of these calls.
- */
-
-static inline gint32 InterlockedCompareExchange(volatile gint32 *dest,
-                                               gint32 exch, gint32 comp)
-{
-       gint32 old;
-
-       __asm__ __volatile__ ("lock; cmpxchgl %2, %0"
-                             : "=m" (*dest), "=a" (old)
-                             : "r" (exch), "m" (*dest), "a" (comp));   
-       return(old);
-}
-
-static inline gpointer InterlockedCompareExchangePointer(volatile gpointer *dest, gpointer exch, gpointer comp)
-{
-       gpointer old;
-
-       __asm__ __volatile__ ("lock; "
-#if defined(__x86_64__)  && !defined(__native_client__)
-                             "cmpxchgq"
-#else
-                             "cmpxchgl"
-#endif
-                             " %2, %0"
-                             : "=m" (*dest), "=a" (old)
-                             : "r" (exch), "m" (*dest), "a" (comp));   
-
-       return(old);
-}
-
-static inline gint32 InterlockedIncrement(volatile gint32 *val)
-{
-       gint32 tmp;
-       
-       __asm__ __volatile__ ("lock; xaddl %0, %1"
-                             : "=r" (tmp), "=m" (*val)
-                             : "0" (1), "m" (*val));
-
-       return(tmp+1);
-}
-
-static inline gint32 InterlockedDecrement(volatile gint32 *val)
-{
-       gint32 tmp;
-       
-       __asm__ __volatile__ ("lock; xaddl %0, %1"
-                             : "=r" (tmp), "=m" (*val)
-                             : "0" (-1), "m" (*val));
-
-       return(tmp-1);
-}
-
-/*
- * See
- * http://msdn.microsoft.com/msdnmag/issues/0700/Win32/
- * for the reasons for using cmpxchg and a loop here.
- */
-static inline gint32 InterlockedExchange(volatile gint32 *val, gint32 new_val)
-{
-       gint32 ret;
-
-       __asm__ __volatile__ ("1:; lock; cmpxchgl %2, %0; jne 1b"
-                             : "=m" (*val), "=a" (ret)
-                             : "r" (new_val), "m" (*val), "a" (*val));
-       return(ret);
-}
-
-static inline gpointer InterlockedExchangePointer(volatile gpointer *val,
-                                                 gpointer new_val)
-{
-       gpointer ret;
-       
-       __asm__ __volatile__ ("1:; lock; "
-#if defined(__x86_64__)  && !defined(__native_client__)
-                             "cmpxchgq"
-#else
-                             "cmpxchgl"
-#endif
-                             " %2, %0; jne 1b"
-                             : "=m" (*val), "=a" (ret)
-                             : "r" (new_val), "m" (*val), "a" (*val));
-
-       return(ret);
-}
-
-static inline gint32 InterlockedExchangeAdd(volatile gint32 *val, gint32 add)
-{
-       gint32 ret;
-       
-       __asm__ __volatile__ ("lock; xaddl %0, %1"
-                             : "=r" (ret), "=m" (*val)
-                             : "0" (add), "m" (*val));
-       
-       return(ret);
-}
-
 #elif (defined(sparc) || defined (__sparc__)) && defined(__GNUC__)
 
 G_GNUC_UNUSED 
index 651fa24804dafa4fd614e9558fc0bfabea7b8ba8..dba12456794a9c5084d51ed2cd06f403a815cab1 100644 (file)
@@ -42,36 +42,6 @@ static inline void mono_memory_read_barrier (void)
        mono_memory_barrier ();
 }
 
-static inline void mono_memory_write_barrier (void)
-{
-       mono_memory_barrier ();
-}
-#elif defined(__x86_64__) || defined(TARGET_AMD64)
-static inline void mono_memory_barrier (void)
-{
-       __asm__ __volatile__ ("mfence" : : : "memory");
-}
-
-static inline void mono_memory_read_barrier (void)
-{
-       __asm__ __volatile__ ("lfence" : : : "memory");
-}
-
-static inline void mono_memory_write_barrier (void)
-{
-       __asm__ __volatile__ ("sfence" : : : "memory");
-}
-#elif defined(__i386__) || defined(TARGET_X86)
-static inline void mono_memory_barrier (void)
-{
-       __asm__ __volatile__ ("lock; addl $0,0(%%esp)" : : : "memory");
-}
-
-static inline void mono_memory_read_barrier (void)
-{
-       mono_memory_barrier ();
-}
-
 static inline void mono_memory_write_barrier (void)
 {
        mono_memory_barrier ();