[ros-diffs] [sginsberg] 36126: - Patch by hackbunny: "64-bit __sync_val_compare_and_swap is, apparently, not inlined on x86. Go figure." "Add "lock" prefix to cmpxchg8b, just in case"

sginsberg at svn.reactos.org sginsberg at svn.reactos.org
Wed Sep 10 17:02:57 CEST 2008


Author: sginsberg
Date: Wed Sep 10 10:02:57 2008
New Revision: 36126

URL: http://svn.reactos.org/svn/reactos?rev=36126&view=rev
Log:
- Patch by hackbunny:
"64-bit __sync_val_compare_and_swap is, apparently, not inlined on x86. Go figure."
"Add "lock" prefix to cmpxchg8b, just in case"

Modified:
    trunk/reactos/include/psdk/intrin_x86.h

Modified: trunk/reactos/include/psdk/intrin_x86.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/intrin_x86.h?rev=36126&r1=36125&r2=36126&view=diff
==============================================================================
--- trunk/reactos/include/psdk/intrin_x86.h [iso-8859-1] (original)
+++ trunk/reactos/include/psdk/intrin_x86.h [iso-8859-1] Wed Sep 10 10:02:57 2008
@@ -104,11 +104,6 @@
 	return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
 }
 
-static __inline__ __attribute__((always_inline)) long long _InterlockedCompareExchange64(volatile long long * const Destination, const long long Exchange, const long long Comperand)
-{
-	return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
-}
-
 static __inline__ __attribute__((always_inline)) void * _InterlockedCompareExchangePointer(void * volatile * const Destination, void * const Exchange, void * const Comperand)
 {
 	return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
@@ -233,23 +228,6 @@
 {
 	long retval = Comperand;
 	__asm__("lock; cmpxchgl %k[Exchange], %[Destination]" : [retval] "+a" (retval) : [Destination] "m" (*Destination), [Exchange] "q" (Exchange): "memory");
-	return retval;
-}
-
-static __inline__ __attribute__((always_inline)) long long _InterlockedCompareExchange64(volatile long long * const Destination, const long long Exchange, const long long Comperand)
-{
-	long long retval = Comperand;
-
-	__asm__
-	(
-		"cmpxchg8b %[Destination]" :
-		[retval] "+A" (retval) :
-			[Destination] "m" (*Destination),
-			"b" ((unsigned long)((Exchange >>  0) & 0xFFFFFFFF)),
-			"c" ((unsigned long)((Exchange >> 32) & 0xFFFFFFFF)) :
-		"memory"
-	);
-
 	return retval;
 }
 
@@ -439,6 +417,34 @@
 	while(y != x);
 
 	return y;
+}
+
+#endif
+
+#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100 && defined(__x86_64__)
+
+static __inline__ __attribute__((always_inline)) long long _InterlockedCompareExchange64(volatile long long * const Destination, const long long Exchange, const long long Comperand)
+{
+	return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
+}
+
+#else
+
+static __inline__ __attribute__((always_inline)) long long _InterlockedCompareExchange64(volatile long long * const Destination, const long long Exchange, const long long Comperand)
+{
+	long long retval = Comperand;
+
+	__asm__
+	(
+		"lock; cmpxchg8b %[Destination]" :
+		[retval] "+A" (retval) :
+			[Destination] "m" (*Destination),
+			"b" ((unsigned long)((Exchange >>  0) & 0xFFFFFFFF)),
+			"c" ((unsigned long)((Exchange >> 32) & 0xFFFFFFFF)) :
+		"memory"
+	);
+
+	return retval;
 }
 
 #endif



More information about the Ros-diffs mailing list