Signed-off-by: Zebediah Figura z.figura12@gmail.com --- include/winnt.h | 52 +++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 32 deletions(-)
diff --git a/include/winnt.h b/include/winnt.h index 7bbe0185139..1bb29836a3d 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -6898,6 +6898,9 @@ static inline BOOLEAN BitScanReverse(DWORD *index, DWORD mask)
#pragma intrinsic(_InterlockedCompareExchange) #pragma intrinsic(_InterlockedCompareExchange64) +#ifdef _WIN64 +#pragma intrinsic(_InterlockedCompareExchange128) +#endif #pragma intrinsic(_InterlockedExchange) #pragma intrinsic(_InterlockedExchangeAdd) #pragma intrinsic(_InterlockedIncrement) @@ -6905,6 +6908,9 @@ static inline BOOLEAN BitScanReverse(DWORD *index, DWORD mask)
long _InterlockedCompareExchange(long volatile*,long,long); long long _InterlockedCompareExchange64(long long volatile*,long long,long long); +#ifdef _WIN64 +unsigned char _InterlockedCompareExchange128(volatile __int64 *, __int64, __int64, __int64 *); +#endif long _InterlockedDecrement(long volatile*); long _InterlockedExchange(long volatile*,long); long _InterlockedExchangeAdd(long volatile*,long); @@ -6920,6 +6926,13 @@ static FORCEINLINE LONGLONG WINAPI InterlockedCompareExchange64( LONGLONG volati return _InterlockedCompareExchange64( (long long volatile *)dest, compare, xchg ); }
+#ifdef _WIN64 +static FORCEINLINE unsigned char WINAPI InterlockedCompareExchange128( volatile __int64 *dest, __int64 xchg_high, __int64 xchg_low, __int64 *compare ) +{ + return _InterlockedCompareExchange128( dest, xchg_high, xchg_low, compare ); +} +#endif + static FORCEINLINE LONG WINAPI InterlockedExchange( LONG volatile *dest, LONG val ) { return _InterlockedExchange( (long volatile *)dest, val ); @@ -6982,6 +6995,13 @@ static FORCEINLINE LONGLONG WINAPI InterlockedCompareExchange64( LONGLONG volati return __sync_val_compare_and_swap( dest, compare, xchg ); }
+#ifdef _WIN64 +static FORCEINLINE unsigned char WINAPI InterlockedCompareExchange128( volatile __int64 *dest, __int64 xchg_high, __int64 xchg_low, __int64 *compare ) +{ + return __sync_bool_compare_and_swap( (__int128 *)dest, *(__int128 *)compare, ((__int128)xchg_high << 64) | xchg_low ); +} +#endif + static FORCEINLINE LONG WINAPI InterlockedExchange( LONG volatile *dest, LONG val ) { LONG ret; @@ -7024,38 +7044,6 @@ static FORCEINLINE void * WINAPI InterlockedExchangePointer( void *volatile *des
#endif /* __GNUC__ */
-#ifdef _WIN64 - -#if defined(_MSC_VER) - -#define InterlockedCompareExchange128 _InterlockedCompareExchange128 -unsigned char _InterlockedCompareExchange128(volatile __int64 *dest, __int64 xchg_high, __int64 xchg_low, __int64 *compare); -#pragma intrinsic(_InterlockedCompareExchange128) - -#elif defined(__x86_64__) - -static inline unsigned char InterlockedCompareExchange128(__int64 *dest, __int64 xchg_high, __int64 xchg_low, __int64 *compare) -{ - unsigned char ret; - __asm__ __volatile__( "lock cmpxchg16b %0; setz %b2" - : "=m" (dest[0]), "=m" (dest[1]), "=r" (ret), - "=a" (compare[0]), "=d" (compare[1]) - : "m" (dest[0]), "m" (dest[1]), "3" (compare[0]), "4" (compare[1]), - "c" (xchg_high), "b" (xchg_low) ); - return ret; -} - -#elif defined(__GNUC__) - -static inline unsigned char InterlockedCompareExchange128(__int64 *dest, __int64 xchg_high, __int64 xchg_low, __int64 *compare) -{ - return __sync_bool_compare_and_swap( (__int128 *)dest, *(__int128 *)compare, ((__int128)xchg_high << 64) | xchg_low ); -} - -#endif - -#endif /* _WIN64 */ - #ifdef __cplusplus } #endif
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- include/winnt.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/include/winnt.h b/include/winnt.h index 1bb29836a3d..78379996abd 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -7005,7 +7005,9 @@ static FORCEINLINE unsigned char WINAPI InterlockedCompareExchange128( volatile static FORCEINLINE LONG WINAPI InterlockedExchange( LONG volatile *dest, LONG val ) { LONG ret; -#if defined(__i386__) || defined(__x86_64__) +#if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7))) + ret = __atomic_exchange_n( dest, val, __ATOMIC_SEQ_CST ); +#elif defined(__i386__) || defined(__x86_64__) __asm__ __volatile__( "lock; xchgl %0,(%1)" : "=r" (ret) :"r" (dest), "0" (val) : "memory" ); #else @@ -7032,7 +7034,9 @@ static FORCEINLINE LONG WINAPI InterlockedDecrement( LONG volatile *dest ) static FORCEINLINE void * WINAPI InterlockedExchangePointer( void *volatile *dest, void *val ) { void *ret; -#ifdef __x86_64__ +#if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7))) + ret = __atomic_exchange_n( dest, val, __ATOMIC_SEQ_CST ); +#elif defined(__x86_64__) __asm__ __volatile__( "lock; xchgq %0,(%1)" : "=r" (ret) :"r" (dest), "0" (val) : "memory" ); #elif defined(__i386__) __asm__ __volatile__( "lock; xchgl %0,(%1)" : "=r" (ret) :"r" (dest), "0" (val) : "memory" );
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/msvcrt/lock.c | 9 --------- include/winnt.h | 12 ++++++++++++ 2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/dlls/msvcrt/lock.c b/dlls/msvcrt/lock.c index b6b5d4b78db..c10445becda 100644 --- a/dlls/msvcrt/lock.c +++ b/dlls/msvcrt/lock.c @@ -1157,15 +1157,6 @@ static inline void spin_wait_for_next_rwl(rwl_queue *q) SpinWait_dtor(&sw); }
-/* Remove when proper InterlockedOr implementation is added to wine */ -static LONG InterlockedOr(LONG *d, LONG v) -{ - LONG l; - while (~(l = *d) & v) - if (InterlockedCompareExchange(d, l|v, l) == l) break; - return l; -} - static LONG InterlockedAnd(LONG *d, LONG v) { LONG l = *d, old; diff --git a/include/winnt.h b/include/winnt.h index 78379996abd..db3c91b3d0f 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -6905,6 +6905,7 @@ static inline BOOLEAN BitScanReverse(DWORD *index, DWORD mask) #pragma intrinsic(_InterlockedExchangeAdd) #pragma intrinsic(_InterlockedIncrement) #pragma intrinsic(_InterlockedDecrement) +#pragma intrinsic(_InterlockedOr)
long _InterlockedCompareExchange(long volatile*,long,long); long long _InterlockedCompareExchange64(long long volatile*,long long,long long); @@ -6915,6 +6916,7 @@ long _InterlockedDecrement(long volatile*); long _InterlockedExchange(long volatile*,long); long _InterlockedExchangeAdd(long volatile*,long); long _InterlockedIncrement(long volatile*); +long _InterlockedOr(long volatile *,long);
static FORCEINLINE LONG WINAPI InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare ) { @@ -6953,6 +6955,11 @@ static FORCEINLINE LONG WINAPI InterlockedDecrement( LONG volatile *dest ) return _InterlockedDecrement( (long volatile *)dest ); }
+static FORCEINLINE LONG WINAPI InterlockedOr( LONG volatile *dest, LONG val ) +{ + return _InterlockedOr( (long volatile *)dest, val ); +} + #ifndef __i386__
#pragma intrinsic(_InterlockedCompareExchangePointer) @@ -7046,6 +7053,11 @@ static FORCEINLINE void * WINAPI InterlockedExchangePointer( void *volatile *des return ret; }
+static FORCEINLINE LONG WINAPI InterlockedOr( LONG volatile *dest, LONG incr ) +{ + return __sync_fetch_and_or( dest, incr ); +} + #endif /* __GNUC__ */
#ifdef __cplusplus
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- include/winnt.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-)
diff --git a/include/winnt.h b/include/winnt.h index db3c91b3d0f..e65df6203cd 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -6983,7 +6983,50 @@ static FORCEINLINE void * WINAPI InterlockedExchangePointer( void *volatile *des return (void *)_InterlockedExchange( (long volatile*)dest, (long)val ); }
-#endif +#endif /* __i386__ */ + +#ifdef __i386__ + +static FORCEINLINE void MemoryBarrier(void) +{ + LONG dummy; + InterlockedOr(&dummy, 0); +} + +#elif defined(__x86_64__) + +#pragma intrinsic(__faststorefence) + +void __faststorefence(void); + +static FORCEINLINE void MemoryBarrier(void) +{ + __faststorefence(); +} + +#elif defined(__arm__) + +#pragma intrinsic(__dmb) + +void __dmb(void); + +static FORCEINLINE void MemoryBarrier(void) +{ + __dmb(_ARM_BARRIER_SY); +} + +#elif defined(__aarch64__) + +#pragma intrinsic(__dmb) + +void __dmb(void); + +static FORCEINLINE void MemoryBarrier(void) +{ + __dmb(_ARM64_BARRIER_SY); +} + +#endif /* __i386__ */
#elif defined(__GNUC__)
@@ -7058,6 +7101,11 @@ static FORCEINLINE LONG WINAPI InterlockedOr( LONG volatile *dest, LONG incr ) return __sync_fetch_and_or( dest, incr ); }
+static FORCEINLINE void MemoryBarrier(void) +{ + __sync_synchronize(); +} + #endif /* __GNUC__ */
#ifdef __cplusplus
Zebediah Figura z.figura12@gmail.com writes:
Signed-off-by: Zebediah Figura z.figura12@gmail.com
include/winnt.h | 52 +++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 32 deletions(-)
This breaks the non-PE build:
/usr/bin/ld: dlls/ntdll/rtl.o: in function `InterlockedCompareExchange128': /home/julliard/wine/build/obj-clang64/../wine/include/winnt.h:7001: undefined reference to `__sync_val_compare_and_swap_16' /usr/bin/ld: /home/julliard/wine/build/obj-clang64/../wine/include/winnt.h:7001: undefined reference to `__sync_val_compare_and_swap_16' /usr/bin/ld: /home/julliard/wine/build/obj-clang64/../wine/include/winnt.h:7001: undefined reference to `__sync_val_compare_and_swap_16' /usr/bin/ld: /home/julliard/wine/build/obj-clang64/../wine/include/winnt.h:7001: undefined reference to `__sync_val_compare_and_swap_16' /usr/bin/ld: /home/julliard/wine/build/obj-clang64/../wine/include/winnt.h:7001: undefined reference to `__sync_val_compare_and_swap_16' clang: error: linker command failed with exit code 1 (use -v to see invocation)