Author: hbelusca
Date: Sun Jun 8 22:28:35 2014
New Revision: 63572
URL: http://svn.reactos.org/svn/reactos?rev=63572&view=rev
Log:
[CRT/INTRIN_X86]
Add InterlockedExchange8/16 for GCC. Reviewed by Timo.
Modified:
trunk/reactos/include/crt/mingw32/intrin_x86.h
Modified: trunk/reactos/include/crt/mingw32/intrin_x86.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/crt/mingw32/intrin_x86.h?rev=63572&r1=63571&r2=63572&view=diff
==============================================================================
--- trunk/reactos/include/crt/mingw32/intrin_x86.h [iso-8859-1] (original)
+++ trunk/reactos/include/crt/mingw32/intrin_x86.h [iso-8859-1] Sun Jun 8
22:28:35 2014
@@ -150,6 +150,8 @@
__INTRIN_INLINE short _InterlockedCompareExchange16(volatile short * const
Destination, const short Exchange, const short Comperand);
__INTRIN_INLINE long _InterlockedCompareExchange(volatile long * const
Destination, const long Exchange, const long Comperand);
__INTRIN_INLINE void * _InterlockedCompareExchangePointer(void * volatile *
const Destination, void * const Exchange, void * const Comperand);
+__INTRIN_INLINE char _InterlockedExchange8(volatile char * const Target, const
char Value);
+__INTRIN_INLINE short _InterlockedExchange16(volatile short * const Target,
const short Value);
__INTRIN_INLINE long _InterlockedExchange(volatile long * const Target, const
long Value);
__INTRIN_INLINE void * _InterlockedExchangePointer(void * volatile * const
Target, void * const Value);
__INTRIN_INLINE long _InterlockedExchangeAdd16(volatile short * const Addend,
const short Value);
@@ -199,25 +201,39 @@
return (void *)__sync_val_compare_and_swap(Destination, Comperand,
Exchange);
}
-__INTRIN_INLINE long _InterlockedExchange(volatile long * const Target, const
long Value)
+__INTRIN_INLINE char _InterlockedExchange8(volatile char * const Target, const
char Value)
{
/* NOTE: __sync_lock_test_and_set would be an acquire barrier, so we
force a full barrier */
__sync_synchronize();
return __sync_lock_test_and_set(Target, Value);
}
-#if defined(_M_AMD64)
-__INTRIN_INLINE long long _InterlockedExchange64(volatile long long * const
Target, const long long Value)
+__INTRIN_INLINE short _InterlockedExchange16(volatile short * const Target,
const short Value)
{
/* NOTE: __sync_lock_test_and_set would be an acquire barrier, so we
force a full barrier */
__sync_synchronize();
return __sync_lock_test_and_set(Target, Value);
}
+
+__INTRIN_INLINE long _InterlockedExchange(volatile long * const Target, const
long Value)
+{
+ /* NOTE: __sync_lock_test_and_set would be an acquire barrier, so we
force a full barrier */
+ __sync_synchronize();
+ return __sync_lock_test_and_set(Target, Value);
+}
+
+#if defined(_M_AMD64)
+__INTRIN_INLINE long long _InterlockedExchange64(volatile long long * const
Target, const long long Value)
+{
+ /* NOTE: __sync_lock_test_and_set would be an acquire barrier, so we
force a full barrier */
+ __sync_synchronize();
+ return __sync_lock_test_and_set(Target, Value);
+}
#endif
__INTRIN_INLINE void * _InterlockedExchangePointer(void * volatile * const
Target, void * const Value)
{
- /* NOTE: ditto */
+ /* NOTE: __sync_lock_test_and_set would be an acquire barrier, so we
force a full barrier */
__sync_synchronize();
return (void *)__sync_lock_test_and_set(Target, Value);
}
@@ -347,6 +363,8 @@
__INTRIN_INLINE short _InterlockedCompareExchange16(volatile short * const
Destination, const short Exchange, const short Comperand);
__INTRIN_INLINE long _InterlockedCompareExchange(volatile long * const
Destination, const long Exchange, const long Comperand);
__INTRIN_INLINE void * _InterlockedCompareExchangePointer(void * volatile *
const Destination, void * const Exchange, void * const Comperand);
+__INTRIN_INLINE char _InterlockedExchange8(volatile char * const Target, const
char Value);
+__INTRIN_INLINE short _InterlockedExchange16(volatile short * const Target,
const short Value);
__INTRIN_INLINE long _InterlockedExchange(volatile long * const Target, const
long Value);
__INTRIN_INLINE void * _InterlockedExchangePointer(void * volatile * const
Target, void * const Value);
__INTRIN_INLINE long _InterlockedExchangeAdd16(volatile short * const Addend,
const short Value);
@@ -394,6 +412,20 @@
{
void * retval = (void *)Comperand;
__asm__("lock; cmpxchgl %k[Exchange], %[Destination]" : [retval] "=a"
(retval) : "[retval]" (retval), [Destination] "m" (*Destination), [Exchange]
"q" (Exchange) : "memory");
+ return retval;
+}
+
+__INTRIN_INLINE char _InterlockedExchange8(volatile char * const Target, const
char Value)
+{
+ char retval = Value;
+ __asm__("xchgb %[retval], %[Target]" : [retval] "+r" (retval) :
[Target] "m" (*Target) : "memory");
+ return retval;
+}
+
+__INTRIN_INLINE short _InterlockedExchange16(volatile short * const Target,
const short Value)
+{
+ short retval = Value;
+ __asm__("xchgw %[retval], %[Target]" : [retval] "+r" (retval) :
[Target] "m" (*Target) : "memory");
return retval;
}