Skip to content

Commit

Permalink
Merge pull request #95 from turbolent/94-gate-atomics
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored Feb 4, 2024
2 parents 2a0ecfc + 6c5bad1 commit bd75c9b
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions w2c2/w2c2_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,14 @@ typedef struct wasmModuleInstance {
struct wasmModuleInstance* (*newChild)(struct wasmModuleInstance* self);
} wasmModuleInstance;

#if defined(_MSC_VER)

#ifdef _MSC_VER
#define WASM_ATOMICS_MSVC
#elif defined(__GNUC__) && (defined(__clang__) || GCC_VERSION >= 40700)
#define WASM_ATOMICS_GCC
#endif

#ifdef WASM_ATOMICS_MSVC

#include <intrin.h>

Expand All @@ -1118,7 +1125,7 @@ typedef struct wasmModuleInstance {

#define atomic_fence() _ReadWriteBarrier()

#else
#elif defined(WASM_ATOMICS_GCC)

/* Use gcc/clang/icc intrinsics */
#define atomic_load_U8(a) __atomic_load_n((U8*)(a), __ATOMIC_SEQ_CST)
Expand All @@ -1135,7 +1142,7 @@ typedef struct wasmModuleInstance {

#endif

#if defined(_MSC_VER)
#ifdef WASM_ATOMICS_MSVC

#include <intrin.h>

Expand Down Expand Up @@ -1178,7 +1185,7 @@ typedef struct wasmModuleInstance {
#define atomic_compare_exchange_U64(a, expected_ptr, desired) \
_InterlockedCompareExchange64(a, desired, *(expected_ptr))

#else
#elif defined(WASM_ATOMICS_GCC)

/* Use gcc/clang/icc intrinsics */

Expand Down Expand Up @@ -1228,6 +1235,8 @@ typedef struct wasmModuleInstance {

#endif

#if defined(WASM_ATOMICS_MSVC) || defined(WASM_ATOMICS_GCC)

#if WASM_ENDIAN == WASM_LITTLE_ENDIAN

#define DEFINE_ATOMIC_LOAD(name, t1, t2) \
Expand Down Expand Up @@ -1428,6 +1437,8 @@ DEFINE_ATOMIC_RMW_CMPXCHG(i64_atomic_rmw32_cmpxchg_u, 32, U64)
DEFINE_ATOMIC_RMW_CMPXCHG(i64_atomic_rmw_cmpxchg, 64, U64)
#endif

#endif /* WASM_ATOMICS_MSVC || WASM_ATOMICS_GCC */

U32
wasmMemoryAtomicWait(
wasmMemory* mem,
Expand Down

0 comments on commit bd75c9b

Please sign in to comment.