| ... | ... | @@ -2202,6 +2202,46 @@ zig_msvc_atomics(i32, ) |
| 2202 | 2202 | zig_msvc_atomics(u64, 64) |
| 2203 | 2203 | zig_msvc_atomics(i64, 64) |
| 2204 | 2204 | |
| 2205 | #define zig_msvc_flt_atomics(Type, ReprType, suffix) \ |
| 2206 | static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \ |
| 2207 | zig_##ReprType comparand = *((zig_##ReprType*)expected); \ |
| 2208 | zig_##ReprType initial = _InterlockedCompareExchange##suffix((zig_##ReprType volatile*)obj, *((zig_##ReprType*)&desired), comparand); \ |
| 2209 | bool exchanged = initial == comparand; \ |
| 2210 | if (!exchanged) { \ |
| 2211 | *expected = *((zig_##Type*)&initial); \ |
| 2212 | } \ |
| 2213 | return exchanged; \ |
| 2214 | } \ |
| 2215 | static inline zig_##Type zig_msvc_atomicrmw_xchg_##Type(zig_##Type volatile* obj, zig_##Type value) { \ |
| 2216 | zig_##ReprType initial = _InterlockedExchange##suffix((zig_##ReprType volatile*)obj, *((zig_##ReprType*)&value)); \ |
| 2217 | return *((zig_##Type*)&initial); \ |
| 2218 | } \ |
| 2219 | static inline zig_##Type zig_msvc_atomicrmw_add_##Type(zig_##Type volatile* obj, zig_##Type value) { \ |
| 2220 | bool success = false; \ |
| 2221 | zig_##ReprType new; \ |
| 2222 | zig_##Type prev; \ |
| 2223 | while (!success) { \ |
| 2224 | prev = *obj; \ |
| 2225 | new = prev + value; \ |
| 2226 | success = zig_msvc_cmpxchg_##Type(obj, &prev, *((zig_##ReprType*)&new)); \ |
| 2227 | } \ |
| 2228 | return prev; \ |
| 2229 | } \ |
| 2230 | static inline zig_##Type zig_msvc_atomicrmw_sub_##Type(zig_##Type volatile* obj, zig_##Type value) { \ |
| 2231 | bool success = false; \ |
| 2232 | zig_##ReprType new; \ |
| 2233 | zig_##Type prev; \ |
| 2234 | while (!success) { \ |
| 2235 | prev = *obj; \ |
| 2236 | new = prev - value; \ |
| 2237 | success = zig_msvc_cmpxchg_##Type(obj, &prev, *((zig_##ReprType*)&new)); \ |
| 2238 | } \ |
| 2239 | return prev; \ |
| 2240 | } |
| 2241 | |
| 2242 | zig_msvc_flt_atomics(f32, u32, ) |
| 2243 | zig_msvc_flt_atomics(f64, u64, 32) |
| 2244 | |
| 2205 | 2245 | #if _M_IX86 |
| 2206 | 2246 | static inline void* zig_msvc_atomicrmw_xchg_p32(void** obj, zig_u32* arg) { |
| 2207 | 2247 | return _InterlockedExchangePointer(obj, arg); |