| ... | @@ -146,22 +146,25 @@ typedef char bool; | ... | @@ -146,22 +146,25 @@ typedef char bool; |
| 146 | #define zig_wasm_memory_grow(index, delta) zig_unimplemented() | 146 | #define zig_wasm_memory_grow(index, delta) zig_unimplemented() |
| 147 | #endif | 147 | #endif |
| 148 | | 148 | |
| | 149 | #define zig_concat(lhs, rhs) lhs##rhs |
| | 150 | #define zig_expand_concat(lhs, rhs) zig_concat(lhs, rhs) |
| | 151 | |
| 149 | #if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__) | 152 | #if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__) |
| 150 | #include <stdatomic.h> | 153 | #include <stdatomic.h> |
| 151 | #define zig_atomic(type) _Atomic(type) | 154 | #define zig_atomic(type) _Atomic(type) |
| 152 | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail) atomic_compare_exchange_strong_explicit(obj, &(expected), desired, succ, fail) | 155 | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) atomic_compare_exchange_strong_explicit(obj, &(expected), desired, succ, fail) |
| 153 | #define zig_cmpxchg_weak(obj, expected, desired, succ, fail) atomic_compare_exchange_weak_explicit (obj, &(expected), desired, succ, fail) | 156 | #define zig_cmpxchg_weak(obj, expected, desired, succ, fail, type) atomic_compare_exchange_weak_explicit (obj, &(expected), desired, succ, fail) |
| 154 | #define zig_atomicrmw_xchg(obj, arg, order) atomic_exchange_explicit (obj, arg, order) | 157 | #define zig_atomicrmw_xchg(obj, arg, order, type) atomic_exchange_explicit (obj, arg, order) |
| 155 | #define zig_atomicrmw_add(obj, arg, order) atomic_fetch_add_explicit (obj, arg, order) | 158 | #define zig_atomicrmw_add(obj, arg, order, type) atomic_fetch_add_explicit (obj, arg, order) |
| 156 | #define zig_atomicrmw_sub(obj, arg, order) atomic_fetch_sub_explicit (obj, arg, order) | 159 | #define zig_atomicrmw_sub(obj, arg, order, type) atomic_fetch_sub_explicit (obj, arg, order) |
| 157 | #define zig_atomicrmw_or(obj, arg, order) atomic_fetch_or_explicit (obj, arg, order) | 160 | #define zig_atomicrmw_or(obj, arg, order, type) atomic_fetch_or_explicit (obj, arg, order) |
| 158 | #define zig_atomicrmw_xor(obj, arg, order) atomic_fetch_xor_explicit (obj, arg, order) | 161 | #define zig_atomicrmw_xor(obj, arg, order, type) atomic_fetch_xor_explicit (obj, arg, order) |
| 159 | #define zig_atomicrmw_and(obj, arg, order) atomic_fetch_and_explicit (obj, arg, order) | 162 | #define zig_atomicrmw_and(obj, arg, order, type) atomic_fetch_and_explicit (obj, arg, order) |
| 160 | #define zig_atomicrmw_nand(obj, arg, order) __atomic_fetch_nand (obj, arg, order) | 163 | #define zig_atomicrmw_nand(obj, arg, order, type) __atomic_fetch_nand (obj, arg, order) |
| 161 | #define zig_atomicrmw_min(obj, arg, order) __atomic_fetch_min (obj, arg, order) | 164 | #define zig_atomicrmw_min(obj, arg, order, type) __atomic_fetch_min (obj, arg, order) |
| 162 | #define zig_atomicrmw_max(obj, arg, order) __atomic_fetch_max (obj, arg, order) | 165 | #define zig_atomicrmw_max(obj, arg, order, type) __atomic_fetch_max (obj, arg, order) |
| 163 | #define zig_atomic_store(obj, arg, order) atomic_store_explicit (obj, arg, order) | 166 | #define zig_atomic_store(obj, arg, order, type) atomic_store_explicit (obj, arg, order) |
| 164 | #define zig_atomic_load(obj, order) atomic_load_explicit (obj, order) | 167 | #define zig_atomic_load(obj, order, type) atomic_load_explicit (obj, order) |
| 165 | #define zig_fence(order) atomic_thread_fence(order) | 168 | #define zig_fence(order) atomic_thread_fence(order) |
| 166 | #elif defined(__GNUC__) | 169 | #elif defined(__GNUC__) |
| 167 | #define memory_order_relaxed __ATOMIC_RELAXED | 170 | #define memory_order_relaxed __ATOMIC_RELAXED |
| ... | @@ -171,20 +174,44 @@ typedef char bool; | ... | @@ -171,20 +174,44 @@ typedef char bool; |
| 171 | #define memory_order_acq_rel __ATOMIC_ACQ_REL | 174 | #define memory_order_acq_rel __ATOMIC_ACQ_REL |
| 172 | #define memory_order_seq_cst __ATOMIC_SEQ_CST | 175 | #define memory_order_seq_cst __ATOMIC_SEQ_CST |
| 173 | #define zig_atomic(type) type | 176 | #define zig_atomic(type) type |
| 174 | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail) __atomic_compare_exchange_n(obj, &(expected), desired, false, succ, fail) | 177 | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail, types) __atomic_compare_exchange_n(obj, &(expected), desired, false, succ, fail) |
| 175 | #define zig_cmpxchg_weak(obj, expected, desired, succ, fail) __atomic_compare_exchange_n(obj, &(expected), desired, true , succ, fail) | 178 | #define zig_cmpxchg_weak(obj, expected, desired, succ, fail, types) __atomic_compare_exchange_n(obj, &(expected), desired, true , succ, fail) |
| 176 | #define zig_atomicrmw_xchg(obj, arg, order) __atomic_exchange_n(obj, arg, order) | 179 | #define zig_atomicrmw_xchg(obj, arg, order, type) __atomic_exchange_n(obj, arg, order) |
| 177 | #define zig_atomicrmw_add(obj, arg, order) __atomic_fetch_add (obj, arg, order) | 180 | #define zig_atomicrmw_add(obj, arg, order, type) __atomic_fetch_add (obj, arg, order) |
| 178 | #define zig_atomicrmw_sub(obj, arg, order) __atomic_fetch_sub (obj, arg, order) | 181 | #define zig_atomicrmw_sub(obj, arg, order, type) __atomic_fetch_sub (obj, arg, order) |
| 179 | #define zig_atomicrmw_or(obj, arg, order) __atomic_fetch_or (obj, arg, order) | 182 | #define zig_atomicrmw_or(obj, arg, order, type) __atomic_fetch_or (obj, arg, order) |
| 180 | #define zig_atomicrmw_xor(obj, arg, order) __atomic_fetch_xor (obj, arg, order) | 183 | #define zig_atomicrmw_xor(obj, arg, order, type) __atomic_fetch_xor (obj, arg, order) |
| 181 | #define zig_atomicrmw_and(obj, arg, order) __atomic_fetch_and (obj, arg, order) | 184 | #define zig_atomicrmw_and(obj, arg, order, type) __atomic_fetch_and (obj, arg, order) |
| 182 | #define zig_atomicrmw_nand(obj, arg, order) __atomic_fetch_nand(obj, arg, order) | 185 | #define zig_atomicrmw_nand(obj, arg, order, type) __atomic_fetch_nand(obj, arg, order) |
| 183 | #define zig_atomicrmw_min(obj, arg, order) __atomic_fetch_min (obj, arg, order) | 186 | #define zig_atomicrmw_min(obj, arg, order, type) __atomic_fetch_min (obj, arg, order) |
| 184 | #define zig_atomicrmw_max(obj, arg, order) __atomic_fetch_max (obj, arg, order) | 187 | #define zig_atomicrmw_max(obj, arg, order, type) __atomic_fetch_max (obj, arg, order) |
| 185 | #define zig_atomic_store(obj, arg, order) __atomic_store_n (obj, arg, order) | 188 | #define zig_atomic_store(obj, arg, order, type) __atomic_store_n (obj, arg, order) |
| 186 | #define zig_atomic_load(obj, order) __atomic_load_n (obj, order) | 189 | #define zig_atomic_load(obj, order, type) __atomic_load_n (obj, order) |
| 187 | #define zig_fence(order) __atomic_thread_fence(order) | 190 | #define zig_fence(order) __atomic_thread_fence(order) |
| | 191 | #elif _MSC_VER && (_M_IX86 || _M_X64) |
| | 192 | #include <intrin.h> |
| | 193 | #define memory_order_relaxed 0 |
| | 194 | #define memory_order_consume 1 |
| | 195 | #define memory_order_acquire 2 |
| | 196 | #define memory_order_release 3 |
| | 197 | #define memory_order_acq_rel 4 |
| | 198 | #define memory_order_seq_cst 5 |
| | 199 | #define zig_atomic(type) type |
| | 200 | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) zig_expand_concat(zig_msvc_cmpxchg_, type)(obj, expected, desired) |
| | 201 | #define zig_cmpxchg_weak(obj, expected, desired, succ, fail, type) zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) |
| | 202 | #define zig_atomicrmw_xchg(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_xchg_, type)(obj, arg) |
| | 203 | #define zig_atomicrmw_add(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_add_, type)(obj, arg) |
| | 204 | #define zig_atomicrmw_sub(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_sub_, type)(obj, arg) |
| | 205 | #define zig_atomicrmw_or(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_or_, type)(obj, arg) |
| | 206 | #define zig_atomicrmw_xor(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_xor_, type)(obj, arg) |
| | 207 | #define zig_atomicrmw_and(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_and_, type)(obj, arg) |
| | 208 | #define zig_atomicrmw_nand(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_nand_, type)(obj, arg) |
| | 209 | #define zig_atomicrmw_min(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_min_, type)(obj, arg) |
| | 210 | #define zig_atomicrmw_max(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_max_, type)(obj, arg) |
| | 211 | #define zig_atomic_store(obj, arg, order, type) zig_expand_concat(zig_msvc_atomic_store_, type)(obj, arg) |
| | 212 | #define zig_atomic_load(obj, order, type) zig_expand_concat(zig_msvc_atomic_load_, type)(obj) |
| | 213 | #define zig_fence(order) __faststorefence() |
| | 214 | // TODO: _MSC_VER && (_M_ARM || _M_ARM64) |
| 188 | #else | 215 | #else |
| 189 | #define memory_order_relaxed 0 | 216 | #define memory_order_relaxed 0 |
| 190 | #define memory_order_consume 1 | 217 | #define memory_order_consume 1 |
| ... | @@ -193,19 +220,19 @@ typedef char bool; | ... | @@ -193,19 +220,19 @@ typedef char bool; |
| 193 | #define memory_order_acq_rel 4 | 220 | #define memory_order_acq_rel 4 |
| 194 | #define memory_order_seq_cst 5 | 221 | #define memory_order_seq_cst 5 |
| 195 | #define zig_atomic(type) type | 222 | #define zig_atomic(type) type |
| 196 | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail) zig_unimplemented() | 223 | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) zig_unimplemented() |
| 197 | #define zig_cmpxchg_weak(obj, expected, desired, succ, fail) zig_unimplemented() | 224 | #define zig_cmpxchg_weak(obj, expected, desired, succ, fail, type) zig_unimplemented() |
| 198 | #define zig_atomicrmw_xchg(obj, arg, order) zig_unimplemented() | 225 | #define zig_atomicrmw_xchg(obj, arg, order, type) zig_unimplemented() |
| 199 | #define zig_atomicrmw_add(obj, arg, order) zig_unimplemented() | 226 | #define zig_atomicrmw_add(obj, arg, order, type) zig_unimplemented() |
| 200 | #define zig_atomicrmw_sub(obj, arg, order) zig_unimplemented() | 227 | #define zig_atomicrmw_sub(obj, arg, order, type) zig_unimplemented() |
| 201 | #define zig_atomicrmw_or(obj, arg, order) zig_unimplemented() | 228 | #define zig_atomicrmw_or(obj, arg, order, type) zig_unimplemented() |
| 202 | #define zig_atomicrmw_xor(obj, arg, order) zig_unimplemented() | 229 | #define zig_atomicrmw_xor(obj, arg, order, type) zig_unimplemented() |
| 203 | #define zig_atomicrmw_and(obj, arg, order) zig_unimplemented() | 230 | #define zig_atomicrmw_and(obj, arg, order, type) zig_unimplemented() |
| 204 | #define zig_atomicrmw_nand(obj, arg, order) zig_unimplemented() | 231 | #define zig_atomicrmw_nand(obj, arg, order, type) zig_unimplemented() |
| 205 | #define zig_atomicrmw_min(obj, arg, order) zig_unimplemented() | 232 | #define zig_atomicrmw_min(obj, arg, order, type) zig_unimplemented() |
| 206 | #define zig_atomicrmw_max(obj, arg, order) zig_unimplemented() | 233 | #define zig_atomicrmw_max(obj, arg, order, type) zig_unimplemented() |
| 207 | #define zig_atomic_store(obj, arg, order) zig_unimplemented() | 234 | #define zig_atomic_store(obj, arg, order, type) zig_unimplemented() |
| 208 | #define zig_atomic_load(obj, order) zig_unimplemented() | 235 | #define zig_atomic_load(obj, order, type) zig_unimplemented() |
| 209 | #define zig_fence(order) zig_unimplemented() | 236 | #define zig_fence(order) zig_unimplemented() |
| 210 | #endif | 237 | #endif |
| 211 | | 238 | |
| ... | @@ -219,9 +246,6 @@ typedef char bool; | ... | @@ -219,9 +246,6 @@ typedef char bool; |
| 219 | #define zig_noreturn void | 246 | #define zig_noreturn void |
| 220 | #endif | 247 | #endif |
| 221 | | 248 | |
| 222 | #define zig_concat(lhs, rhs) lhs##rhs | | |
| 223 | #define zig_expand_concat(lhs, rhs) zig_concat(lhs, rhs) | | |
| 224 | | | |
| 225 | #define zig_bitSizeOf(T) (CHAR_BIT * sizeof(T)) | 249 | #define zig_bitSizeOf(T) (CHAR_BIT * sizeof(T)) |
| 226 | | 250 | |
| 227 | typedef uintptr_t zig_usize; | 251 | typedef uintptr_t zig_usize; |
| ... | @@ -1917,6 +1941,18 @@ typedef zig_i128 zig_c_longdouble; | ... | @@ -1917,6 +1941,18 @@ typedef zig_i128 zig_c_longdouble; |
| 1917 | #define zig_as_special_constant_c_longdouble(sign, name, arg, repr) repr | 1941 | #define zig_as_special_constant_c_longdouble(sign, name, arg, repr) repr |
| 1918 | #endif | 1942 | #endif |
| 1919 | | 1943 | |
| | 1944 | #if zig_bitSizeOf_c_longdouble == 16 |
| | 1945 | #define zig_compiler_rt_abbrev_c_longdouble zig_compiler_rt_abbrev_f16 |
| | 1946 | #elif zig_bitSizeOf_c_longdouble == 32 |
| | 1947 | #define zig_compiler_rt_abbrev_c_longdouble zig_compiler_rt_abbrev_f32 |
| | 1948 | #elif zig_bitSizeOf_c_longdouble == 64 |
| | 1949 | #define zig_compiler_rt_abbrev_c_longdouble zig_compiler_rt_abbrev_f64 |
| | 1950 | #elif zig_bitSizeOf_c_longdouble == 80 |
| | 1951 | #define zig_compiler_rt_abbrev_c_longdouble zig_compiler_rt_abbrev_f80 |
| | 1952 | #elif zig_bitSizeOf_c_longdouble == 128 |
| | 1953 | #define zig_compiler_rt_abbrev_c_longdouble zig_compiler_rt_abbrev_f128 |
| | 1954 | #endif |
| | 1955 | |
| 1920 | #define zig_cast_f16 (zig_f16) | 1956 | #define zig_cast_f16 (zig_f16) |
| 1921 | #define zig_cast_f32 (zig_f32) | 1957 | #define zig_cast_f32 (zig_f32) |
| 1922 | #define zig_cast_f64 (zig_f64) | 1958 | #define zig_cast_f64 (zig_f64) |
| ... | @@ -2054,3 +2090,101 @@ zig_float_builtins(f64) | ... | @@ -2054,3 +2090,101 @@ zig_float_builtins(f64) |
| 2054 | zig_float_builtins(f80) | 2090 | zig_float_builtins(f80) |
| 2055 | zig_float_builtins(f128) | 2091 | zig_float_builtins(f128) |
| 2056 | zig_float_builtins(c_longdouble) | 2092 | zig_float_builtins(c_longdouble) |
| | 2093 | |
| | 2094 | #if _MSC_VER && (_M_IX86 || _M_X64) |
| | 2095 | #include <intrin.h> |
| | 2096 | |
| | 2097 | // TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, load 64 bit without interlocked on x64 |
| | 2098 | // TODO: Fix obviously broken nand / min / max, these don't exist on msvc _InterlockedNand |
| | 2099 | |
| | 2100 | #define zig_msvc_atomics(type, suffix) \ |
| | 2101 | static inline bool zig_msvc_cmpxchg_##type(zig_##type volatile* obj, zig_##type expected, zig_##type desired) { \ |
| | 2102 | return _InterlockedCompareExchange##suffix(obj, desired, expected) == expected; \ |
| | 2103 | } \ |
| | 2104 | static inline zig_##type zig_msvc_atomicrmw_xchg_##type(zig_##type volatile* obj, zig_##type value) { \ |
| | 2105 | return _InterlockedExchange##suffix(obj, value); \ |
| | 2106 | } \ |
| | 2107 | static inline zig_##type zig_msvc_atomicrmw_add_##type(zig_##type volatile* obj, zig_##type value) { \ |
| | 2108 | return _InterlockedExchangeAdd##suffix(obj, value); \ |
| | 2109 | } \ |
| | 2110 | static inline zig_##type zig_msvc_atomicrmw_sub_##type(zig_##type volatile* obj, zig_##type value) { \ |
| | 2111 | return _InterlockedExchangeAdd##suffix(obj, -value); \ |
| | 2112 | } \ |
| | 2113 | static inline zig_##type zig_msvc_atomicrmw_or_##type(zig_##type volatile* obj, zig_##type value) { \ |
| | 2114 | return _InterlockedOr##suffix(obj, value); \ |
| | 2115 | } \ |
| | 2116 | static inline zig_##type zig_msvc_atomicrmw_xor_##type(zig_##type volatile* obj, zig_##type value) { \ |
| | 2117 | return _InterlockedXor##suffix(obj, value); \ |
| | 2118 | } \ |
| | 2119 | static inline zig_##type zig_msvc_atomicrmw_and_##type(zig_##type volatile* obj, zig_##type value) { \ |
| | 2120 | return _InterlockedAnd##suffix(obj, value); \ |
| | 2121 | } \ |
| | 2122 | static inline zig_##type zig_msvc_atomicrmw_nand_##type(zig_##type volatile* obj, zig_##type value) { \ |
| | 2123 | return 0; \ |
| | 2124 | } \ |
| | 2125 | static inline zig_##type zig_msvc_atomicrmw_min_##type(zig_##type volatile* obj, zig_##type value) { \ |
| | 2126 | return 0; \ |
| | 2127 | } \ |
| | 2128 | static inline zig_##type zig_msvc_atomicrmw_max_##type(zig_##type volatile* obj, zig_##type value) { \ |
| | 2129 | return 0; \ |
| | 2130 | } \ |
| | 2131 | static inline void zig_msvc_atomic_store_##type(zig_##type volatile* obj, zig_##type value) { \ |
| | 2132 | _InterlockedExchange##suffix(obj, value); \ |
| | 2133 | } \ |
| | 2134 | static inline zig_##type zig_msvc_atomic_load_##type(zig_##type volatile* obj) { \ |
| | 2135 | return _InterlockedOr##suffix(obj, 0); \ |
| | 2136 | } |
| | 2137 | |
| | 2138 | zig_msvc_atomics(u8, 8) |
| | 2139 | zig_msvc_atomics(i8, 8) |
| | 2140 | zig_msvc_atomics(u16, 16) |
| | 2141 | zig_msvc_atomics(i16, 16) |
| | 2142 | zig_msvc_atomics(u32, ) |
| | 2143 | zig_msvc_atomics(i32, ) |
| | 2144 | zig_msvc_atomics(u64, 64) |
| | 2145 | zig_msvc_atomics(i64, 64) |
| | 2146 | |
| | 2147 | static inline bool zig_msvc_cmpxchg_p32(void** obj, void* expected, void* desired) { |
| | 2148 | return _InterlockedCompareExchangePointer(obj, desired, expected) == expected; |
| | 2149 | } |
| | 2150 | |
| | 2151 | static inline bool zig_msvc_cmpxchg_p64(void** obj, void* expected, void* desired) { |
| | 2152 | return _InterlockedCompareExchangePointer(obj, desired, expected) == expected; |
| | 2153 | } |
| | 2154 | |
| | 2155 | #if _M_IX86 |
| | 2156 | static inline void* zig_msvc_atomicrmw_xchg_p32(void** obj, zig_u32* arg) { |
| | 2157 | return _InterlockedExchangePointer(obj, arg); |
| | 2158 | } |
| | 2159 | |
| | 2160 | static inline void zig_msvc_atomic_store_p32(void** obj, zig_u32* arg) { |
| | 2161 | _InterlockedExchangePointer(obj, arg); |
| | 2162 | } |
| | 2163 | |
| | 2164 | static inline void* zig_msvc_atomic_load_p32(void** obj, zig_u32* arg) { |
| | 2165 | return (void*)_InterlockedOr((void*)obj, 0); |
| | 2166 | } |
| | 2167 | #else |
| | 2168 | static inline void* zig_msvc_atomicrmw_xchg__p64(void** obj, zig_u64* arg) { |
| | 2169 | return _InterlockedExchangePointer(obj, arg); |
| | 2170 | } |
| | 2171 | |
| | 2172 | static inline void zig_msvc_atomic_store_p64(void** obj, zig_u64* arg) { |
| | 2173 | _InterlockedExchangePointer(obj, arg); |
| | 2174 | } |
| | 2175 | |
| | 2176 | static inline void* zig_msvc_atomic_load_p64(void** obj) { |
| | 2177 | return (void*)_InterlockedOr64((void*)obj, 0); |
| | 2178 | } |
| | 2179 | #endif |
| | 2180 | |
| | 2181 | static inline bool zig_msvc_cmpxchg_u128(zig_u128 volatile* obj, zig_u128 expected, zig_u128 desired) { |
| | 2182 | zig_u128 comparand_result = desired; |
| | 2183 | return _InterlockedCompareExchange128((zig_i64 volatile*)obj, expected.hi, expected.lo, (zig_i64*)&comparand_result); |
| | 2184 | } |
| | 2185 | |
| | 2186 | static inline bool zig_msvc_cmpxchg_i128(zig_i128 volatile* obj, zig_i128 expected, zig_i128 desired) { |
| | 2187 | zig_i128 comparand_result = desired; |
| | 2188 | return _InterlockedCompareExchange128((zig_i64 volatile*)obj, expected.hi, expected.lo, (zig_u64*)&comparand_result); |
| | 2189 | } |
| | 2190 | #endif |