Skip to content

Commit

Permalink
Use MSVC intrinsics, instead of Win32 calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
Apprentice-Alchemist committed Mar 5, 2022
1 parent 66a56ac commit b10cebb
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions include/hx/StdLibs.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ int _hx_atomic_dec(::cpp::Pointer<cpp::AtomicInt> inPtr );
#define HX_GCC_ATOMICS
#elif defined(_MSC_VER)
#define HX_MSVC_ATOMICS
#include <winnt.h>
#include <intrin.h>
#else // Nearly everyone uses GCC, Clang or MSVC, right?
#error "Neither GCC, clang or MSVC is being used. Please contribute the relevant atomic instrinsics for your compiler."
#endif
Expand All @@ -322,39 +322,39 @@ inline int _hx_atomic_add(int *a, int b) {
#if defined(HX_GCC_ATOMICS)
return __atomic_fetch_add(a, b, __ATOMIC_SEQ_CST);
#elif defined(HX_MSVC_ATOMICS)
return InterlockedExchangeAdd((LONG volatile *)a, b);
return _InterlockedExchangeAdd((long volatile *)a, b);
#endif
}

inline int _hx_atomic_sub(int *a, int b) {
#if defined(HX_GCC_ATOMICS)
return __atomic_fetch_sub(a, b, __ATOMIC_SEQ_CST);
#elif defined(HX_MSVC_ATOMICS)
return InterlockedExchangeAdd((LONG volatile *)a, -b);
return _InterlockedExchangeAdd((long volatile *)a, -b);
#endif
}

inline int _hx_atomic_and(int *a, int b) {
#if defined(HX_GCC_ATOMICS)
return __atomic_fetch_and(a, b, __ATOMIC_SEQ_CST);
#elif defined(HX_MSVC_ATOMICS)
return InterlockedAnd((LONG volatile *)a, b);
return _InterlockedAnd((long volatile *)a, b);
#endif
}

inline int _hx_atomic_or(int *a, int b) {
#if defined(HX_GCC_ATOMICS)
return __atomic_fetch_or(a, b, __ATOMIC_SEQ_CST);
#elif defined(HX_MSVC_ATOMICS)
return InterlockedOr((LONG volatile *)a, b);
return _InterlockedOr((long volatile *)a, b);
#endif
}

inline int _hx_atomic_xor(int *a, int b) {
#if defined(HX_GCC_ATOMICS)
return __atomic_fetch_xor(a, b, __ATOMIC_SEQ_CST);
#elif defined(HX_MSVC_ATOMICS)
return InterlockedXor((LONG volatile *)a, b);
return _InterlockedXor((long volatile *)a, b);
#endif
}

Expand All @@ -365,7 +365,7 @@ inline int _hx_atomic_compare_exchange(int *a, int expected,
__atomic_compare_exchange(a, &_expected, &replacement, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
return _expected;
#elif defined(HX_MSVC_ATOMICS)
return InterlockedCompareExchange((LONG volatile *)a, replacement, expected);
return _InterlockedCompareExchange((long volatile *)a, replacement, expected);
#endif
}

Expand All @@ -375,7 +375,7 @@ inline int _hx_atomic_exchange(int *a, int replacement) {
__atomic_exchange(a, &replacement, &ret, __ATOMIC_SEQ_CST);
return ret;
#elif defined(HX_MSVC_ATOMICS)
return InterlockedExchange((LONG volatile *)a, replacement);
return _InterlockedExchange((long volatile *)a, replacement);
#endif
}

Expand All @@ -385,7 +385,7 @@ inline int _hx_atomic_load(int *a) {
__atomic_load(a, &ret, __ATOMIC_SEQ_CST);
return ret;
#elif defined(HX_MSVC_ATOMICS)
return InterlockedXor((LONG volatile *)a, 0);
return _InterlockedXor((long volatile *)a, 0);
#endif
}

Expand All @@ -394,7 +394,7 @@ inline int _hx_atomic_store(int *a, int value) {
__atomic_store(a, &value, __ATOMIC_SEQ_CST);
return value;
#elif defined(HX_MSVC_ATOMICS)
InterlockedExchange((LONG volatile *)a, value);
_InterlockedExchange((long volatile *)a, value);
return value;
#endif
}
Expand Down

0 comments on commit b10cebb

Please sign in to comment.