Author: lupus
Date: 2005-04-13 12:45:34 -0400 (Wed, 13 Apr 2005)
New Revision: 42927

Modified:
   trunk/mono/mono/io-layer/ChangeLog
   trunk/mono/mono/io-layer/atomic.h
Log:


Wed Apr 13 13:12:33 EDT 2005 Paolo Molaro <[EMAIL PROTECTED]>

        * atomic.h: applied patch from [EMAIL PROTECTED] (David Waite)
        to fix InterlockedExchangeAdd.
        Fixed a few other functions, including InterlockedCompareExchange()
        which was miscompiled by gcc with optimizations enabled.



Modified: trunk/mono/mono/io-layer/ChangeLog
===================================================================
--- trunk/mono/mono/io-layer/ChangeLog  2005-04-13 16:44:39 UTC (rev 42926)
+++ trunk/mono/mono/io-layer/ChangeLog  2005-04-13 16:45:34 UTC (rev 42927)
@@ -1,3 +1,11 @@
+
+Wed Apr 13 13:12:33 EDT 2005 Paolo Molaro <[EMAIL PROTECTED]>
+
+       * atomic.h: applied patch from [EMAIL PROTECTED] (David Waite)
+       to fix InterlockedExchangeAdd.
+       Fixed a few other functions, including InterlockedCompareExchange()
+       which was miscompiled by gcc with optimizations enabled.
+
 2005-04-13  Dick Porter  <[EMAIL PROTECTED]>
 
        * io.c (share_check): 

Modified: trunk/mono/mono/io-layer/atomic.h
===================================================================
--- trunk/mono/mono/io-layer/atomic.h   2005-04-13 16:44:39 UTC (rev 42926)
+++ trunk/mono/mono/io-layer/atomic.h   2005-04-13 16:45:34 UTC (rev 42927)
@@ -420,31 +420,31 @@
 
 static inline gint32 InterlockedIncrement(volatile gint32 *val)
 {
-       gint32 tmp = 0;
+       gint32 result = 0, tmp;
 
        __asm__ __volatile__ ("\n1:\n\t"
                              "lwarx  %0, 0, %2\n\t"
                              "addi   %1, %0, 1\n\t"
                               "stwcx. %1, 0, %2\n\t"
                              "bne-   1b"
-                             : "=&b" (tmp): "r" (tmp), "r" (val): "cc", 
"memory");
-       return tmp + 1;
+                             : "=&b" (result), "=&b" (tmp): "r" (val): "cc", 
"memory");
+       return result + 1;
 }
 
 static inline gint32 InterlockedDecrement(volatile gint32 *val)
 {
-       gint32 tmp = 0;
+       gint32 result = 0, tmp;
 
        __asm__ __volatile__ ("\n1:\n\t"
                              "lwarx  %0, 0, %2\n\t"
                              "addi   %1, %0, -1\n\t"
                               "stwcx. %1, 0, %2\n\t"
                              "bne-   1b"
-                             : "=&b" (tmp) : "r" (tmp), "r" (val): "cc", 
"memory");
-       return tmp - 1;
+                             : "=&b" (result), "=&b" (tmp): "r" (val): "cc", 
"memory");
+       return result - 1;
 }
 
-#define InterlockedCompareExchangePointer InterlockedCompareExchange
+#define InterlockedCompareExchangePointer(dest,exch,comp) 
InterlockedCompareExchange((volatile gint32 *)(dest), (gint32)(exch), 
(gint32)(comp))
 
 static inline gint32 InterlockedCompareExchange(volatile gint32 *dest,
                                                gint32 exch, gint32 comp) {
@@ -452,13 +452,13 @@
 
        __asm__ __volatile__ ("\n1:\n\t"
                             "lwarx   %0, 0, %1\n\t"
-                            "cmpw    %2, %3\n\t" 
+                            "cmpw    %0, %2\n\t" 
                             "bne-    2f\n\t"
-                            "stwcx.  %4, 0, %1\n\t"
+                            "stwcx.  %3, 0, %1\n\t"
                             "bne-    1b\n"
                             "2:"
-                            : "=r" (tmp)
-                            : "r" (dest), "0" (tmp) ,"r" (comp), "r" (exch): 
"cc", "memory");
+                            : "=&r" (tmp)
+                            : "b" (dest), "r" (comp), "r" (exch): "cc", 
"memory");
        return(tmp);
 }
 
@@ -473,20 +473,19 @@
                              : "=r" (tmp) : "0" (tmp), "b" (dest), "r" (exch): 
"cc", "memory");
        return(tmp);
 }
-#define InterlockedExchangePointer InterlockedExchange
+#define InterlockedExchangePointer(dest,exch) InterlockedExchange((volatile 
gint32 *)(dest), (gint32)(exch))
 
 static inline gint32 InterlockedExchangeAdd(volatile gint32 *dest, gint32 add)
 {
-       gint32 tmp = 0;
-
-       __asm__ __volatile__ ("\n1:\n\t"
-                             "lwarx  %0, 0, %2\n\t"
-                             "add    %1, %3, %4\n\t"
-                             "stwcx. %1, 0, %2\n\t"
-                             "bne    1b"
-                             : "=r" (tmp), "=r" (add)
-                             : "r" (dest), "0" (tmp), "1" (add) : "cc", 
"memory");
-       return(tmp);
+        gint32 result, tmp;
+        __asm__ __volatile__ ("\n1:\n\t"
+                              "lwarx  %0, 0, %2\n\t"
+                              "add    %1, %0, %3\n\t"
+                              "stwcx. %1, 0, %2\n\t"
+                              "bne    1b"
+                              : "=&r" (result), "=&r" (tmp)
+                              : "r" (dest), "r" (add) : "cc", "memory");
+        return(result);
 }
 
 #elif defined(__arm__)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to