| ... | ... | @@ -196,7 +196,7 @@ typedef char bool; |
| 196 | 196 | #define memory_order_acq_rel 4 |
| 197 | 197 | #define memory_order_seq_cst 5 |
| 198 | 198 | #define zig_atomic(type) type |
| 199 | | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) zig_expand_concat(zig_msvc_cmpxchg_, type)(obj, expected, desired) |
| 199 | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) zig_expand_concat(zig_msvc_cmpxchg_, type)(obj, &(expected), desired) |
| 200 | 200 | #define zig_cmpxchg_weak(obj, expected, desired, succ, fail, type) zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) |
| 201 | 201 | #define zig_atomicrmw_xchg(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_xchg_, type)(obj, arg) |
| 202 | 202 | #define zig_atomicrmw_add(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_add_, type)(obj, arg) |
| ... | ... | @@ -2096,12 +2096,18 @@ zig_float_builtins(c_longdouble) |
| 2096 | 2096 | #if _MSC_VER && (_M_IX86 || _M_X64) |
| 2097 | 2097 | #include <intrin.h> |
| 2098 | 2098 | |
| 2099 | | // TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, load 64 bit without interlocked on x64 |
| 2100 | | // TODO: Fix obviously broken nand / min / max, these don't exist on msvc _InterlockedNand |
| 2099 | // TODO: zig_msvc_atomic_load should just load 32 bit without interlocked on x86, and just load 64 bit without interlocked on x64 |
| 2100 | // TODO: Fix obviously broken nand / min / max, these don't exist on msvc |
| 2101 | 2101 | |
| 2102 | 2102 | #define zig_msvc_atomics(type, suffix) \ |
| 2103 | | static inline bool zig_msvc_cmpxchg_##type(zig_##type volatile* obj, zig_##type expected, zig_##type desired) { \ |
| 2104 | | return _InterlockedCompareExchange##suffix(obj, desired, expected) == expected; \ |
| 2103 | static inline bool zig_msvc_cmpxchg_##type(zig_##type volatile* obj, zig_##type* expected, zig_##type desired) { \ |
| 2104 | zig_##type comparand = *expected; \ |
| 2105 | zig_##type initial = _InterlockedCompareExchange##suffix(obj, desired, comparand); \ |
| 2106 | bool exchanged = initial == comparand; \ |
| 2107 | if (!exchanged) { \ |
| 2108 | *expected = initial; \ |
| 2109 | } \ |
| 2110 | return exchanged; \ |
| 2105 | 2111 | } \ |
| 2106 | 2112 | static inline zig_##type zig_msvc_atomicrmw_xchg_##type(zig_##type volatile* obj, zig_##type value) { \ |
| 2107 | 2113 | return _InterlockedExchange##suffix(obj, value); \ |
| ... | ... | @@ -2146,12 +2152,24 @@ zig_msvc_atomics(i32, ) |
| 2146 | 2152 | zig_msvc_atomics(u64, 64) |
| 2147 | 2153 | zig_msvc_atomics(i64, 64) |
| 2148 | 2154 | |
| 2149 | | static inline bool zig_msvc_cmpxchg_p32(void** obj, void* expected, void* desired) { |
| 2150 | | return _InterlockedCompareExchangePointer(obj, desired, expected) == expected; |
| 2155 | static inline bool zig_msvc_cmpxchg_p32(void** obj, void** expected, void* desired) { |
| 2156 | void* comparand = *expected; |
| 2157 | void* initial = _InterlockedCompareExchangePointer(obj, desired, comparand); |
| 2158 | bool exchanged = initial == comparand; |
| 2159 | if (!exchanged) { |
| 2160 | *expected = initial; |
| 2161 | } |
| 2162 | return exchanged; |
| 2151 | 2163 | } |
| 2152 | 2164 | |
| 2153 | | static inline bool zig_msvc_cmpxchg_p64(void** obj, void* expected, void* desired) { |
| 2154 | | return _InterlockedCompareExchangePointer(obj, desired, expected) == expected; |
| 2165 | static inline bool zig_msvc_cmpxchg_p64(void** obj, void** expected, void* desired) { |
| 2166 | void* comparand = *expected; |
| 2167 | void* initial = _InterlockedCompareExchangePointer(obj, desired, comparand); |
| 2168 | bool exchanged = initial == comparand; |
| 2169 | if (!exchanged) { |
| 2170 | *expected = initial; |
| 2171 | } |
| 2172 | return exchanged; |
| 2155 | 2173 | } |
| 2156 | 2174 | |
| 2157 | 2175 | #if _M_IX86 |
| ... | ... | @@ -2180,13 +2198,11 @@ static inline void* zig_msvc_atomic_load_p64(void** obj) { |
| 2180 | 2198 | } |
| 2181 | 2199 | #endif |
| 2182 | 2200 | |
| 2183 | | static inline bool zig_msvc_cmpxchg_u128(zig_u128 volatile* obj, zig_u128 expected, zig_u128 desired) { |
| 2184 | | zig_u128 comparand_result = desired; |
| 2185 | | return _InterlockedCompareExchange128((zig_i64 volatile*)obj, expected.hi, expected.lo, (zig_i64*)&comparand_result); |
| 2201 | static inline bool zig_msvc_cmpxchg_u128(zig_u128 volatile* obj, zig_u128* expected, zig_u128 desired) { |
| 2202 | return _InterlockedCompareExchange128((zig_i64 volatile*)obj, desired.hi, desired.lo, (zig_i64*)expected); |
| 2186 | 2203 | } |
| 2187 | 2204 | |
| 2188 | | static inline bool zig_msvc_cmpxchg_i128(zig_i128 volatile* obj, zig_i128 expected, zig_i128 desired) { |
| 2189 | | zig_i128 comparand_result = desired; |
| 2190 | | return _InterlockedCompareExchange128((zig_i64 volatile*)obj, expected.hi, expected.lo, (zig_u64*)&comparand_result); |
| 2205 | static inline bool zig_msvc_cmpxchg_i128(zig_i128 volatile* obj, zig_i128* expected, zig_i128 desired) { |
| 2206 | return _InterlockedCompareExchange128((zig_i64 volatile*)obj, desired.hi, desired.lo, (zig_u64*)expected); |
| 2191 | 2207 | } |
| 2192 | 2208 | #endif |