| ... | ... | @@ -253,97 +253,6 @@ typedef char bool; |
| 253 | 253 | #define zig_concat(lhs, rhs) lhs##rhs |
| 254 | 254 | #define zig_expand_concat(lhs, rhs) zig_concat(lhs, rhs) |
| 255 | 255 | |
| 256 | | #if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__) |
| 257 | | #include <stdatomic.h> |
| 258 | | #define zig_atomic(type) _Atomic(type) |
| 259 | | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) atomic_compare_exchange_strong_explicit(obj, &(expected), desired, succ, fail) |
| 260 | | #define zig_cmpxchg_weak(obj, expected, desired, succ, fail, type) atomic_compare_exchange_weak_explicit (obj, &(expected), desired, succ, fail) |
| 261 | | #define zig_atomicrmw_xchg(obj, arg, order, type) atomic_exchange_explicit (obj, arg, order) |
| 262 | | #define zig_atomicrmw_add(obj, arg, order, type) atomic_fetch_add_explicit (obj, arg, order) |
| 263 | | #define zig_atomicrmw_sub(obj, arg, order, type) atomic_fetch_sub_explicit (obj, arg, order) |
| 264 | | #define zig_atomicrmw_or(obj, arg, order, type) atomic_fetch_or_explicit (obj, arg, order) |
| 265 | | #define zig_atomicrmw_xor(obj, arg, order, type) atomic_fetch_xor_explicit (obj, arg, order) |
| 266 | | #define zig_atomicrmw_and(obj, arg, order, type) atomic_fetch_and_explicit (obj, arg, order) |
| 267 | | #define zig_atomicrmw_nand(obj, arg, order, type) __atomic_fetch_nand (obj, arg, order) |
| 268 | | #define zig_atomicrmw_min(obj, arg, order, type) __atomic_fetch_min (obj, arg, order) |
| 269 | | #define zig_atomicrmw_max(obj, arg, order, type) __atomic_fetch_max (obj, arg, order) |
| 270 | | #define zig_atomic_store(obj, arg, order, type) atomic_store_explicit (obj, arg, order) |
| 271 | | #define zig_atomic_load(obj, order, type) atomic_load_explicit (obj, order) |
| 272 | | #define zig_fence(order) atomic_thread_fence(order) |
| 273 | | #elif defined(__GNUC__) |
| 274 | | #define memory_order_relaxed __ATOMIC_RELAXED |
| 275 | | #define memory_order_consume __ATOMIC_CONSUME |
| 276 | | #define memory_order_acquire __ATOMIC_ACQUIRE |
| 277 | | #define memory_order_release __ATOMIC_RELEASE |
| 278 | | #define memory_order_acq_rel __ATOMIC_ACQ_REL |
| 279 | | #define memory_order_seq_cst __ATOMIC_SEQ_CST |
| 280 | | #define zig_atomic(type) type |
| 281 | | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) __atomic_compare_exchange_n(obj, &(expected), desired, false, succ, fail) |
| 282 | | #define zig_cmpxchg_weak(obj, expected, desired, succ, fail, type) __atomic_compare_exchange_n(obj, &(expected), desired, true , succ, fail) |
| 283 | | #define zig_atomicrmw_xchg(obj, arg, order, type) __atomic_exchange_n(obj, arg, order) |
| 284 | | #define zig_atomicrmw_add(obj, arg, order, type) __atomic_fetch_add (obj, arg, order) |
| 285 | | #define zig_atomicrmw_sub(obj, arg, order, type) __atomic_fetch_sub (obj, arg, order) |
| 286 | | #define zig_atomicrmw_or(obj, arg, order, type) __atomic_fetch_or (obj, arg, order) |
| 287 | | #define zig_atomicrmw_xor(obj, arg, order, type) __atomic_fetch_xor (obj, arg, order) |
| 288 | | #define zig_atomicrmw_and(obj, arg, order, type) __atomic_fetch_and (obj, arg, order) |
| 289 | | #define zig_atomicrmw_nand(obj, arg, order, type) __atomic_fetch_nand(obj, arg, order) |
| 290 | | #define zig_atomicrmw_min(obj, arg, order, type) __atomic_fetch_min (obj, arg, order) |
| 291 | | #define zig_atomicrmw_max(obj, arg, order, type) __atomic_fetch_max (obj, arg, order) |
| 292 | | #define zig_atomic_store(obj, arg, order, type) __atomic_store_n (obj, arg, order) |
| 293 | | #define zig_atomic_load(obj, order, type) __atomic_load_n (obj, order) |
| 294 | | #define zig_fence(order) __atomic_thread_fence(order) |
| 295 | | #elif _MSC_VER && (_M_IX86 || _M_X64) |
| 296 | | #define memory_order_relaxed 0 |
| 297 | | #define memory_order_consume 1 |
| 298 | | #define memory_order_acquire 2 |
| 299 | | #define memory_order_release 3 |
| 300 | | #define memory_order_acq_rel 4 |
| 301 | | #define memory_order_seq_cst 5 |
| 302 | | #define zig_atomic(type) type |
| 303 | | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) zig_expand_concat(zig_msvc_cmpxchg_, type)(obj, &(expected), desired) |
| 304 | | #define zig_cmpxchg_weak(obj, expected, desired, succ, fail, type) zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) |
| 305 | | #define zig_atomicrmw_xchg(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_xchg_, type)(obj, arg) |
| 306 | | #define zig_atomicrmw_add(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_add_, type)(obj, arg) |
| 307 | | #define zig_atomicrmw_sub(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_sub_, type)(obj, arg) |
| 308 | | #define zig_atomicrmw_or(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_or_, type)(obj, arg) |
| 309 | | #define zig_atomicrmw_xor(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_xor_, type)(obj, arg) |
| 310 | | #define zig_atomicrmw_and(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_and_, type)(obj, arg) |
| 311 | | #define zig_atomicrmw_nand(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_nand_, type)(obj, arg) |
| 312 | | #define zig_atomicrmw_min(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_min_, type)(obj, arg) |
| 313 | | #define zig_atomicrmw_max(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_max_, type)(obj, arg) |
| 314 | | #define zig_atomic_store(obj, arg, order, type) zig_expand_concat(zig_msvc_atomic_store_, type)(obj, arg) |
| 315 | | #define zig_atomic_load(obj, order, type) zig_expand_concat(zig_msvc_atomic_load_, type)(obj) |
| 316 | | #if _M_X64 |
| 317 | | #define zig_fence(order) __faststorefence() |
| 318 | | #else |
| 319 | | #define zig_fence(order) zig_msvc_atomic_barrier() |
| 320 | | #endif |
| 321 | | |
| 322 | | // TODO: _MSC_VER && (_M_ARM || _M_ARM64) |
| 323 | | #else |
| 324 | | #define memory_order_relaxed 0 |
| 325 | | #define memory_order_consume 1 |
| 326 | | #define memory_order_acquire 2 |
| 327 | | #define memory_order_release 3 |
| 328 | | #define memory_order_acq_rel 4 |
| 329 | | #define memory_order_seq_cst 5 |
| 330 | | #define zig_atomic(type) type |
| 331 | | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) zig_unimplemented() |
| 332 | | #define zig_cmpxchg_weak(obj, expected, desired, succ, fail, type) zig_unimplemented() |
| 333 | | #define zig_atomicrmw_xchg(obj, arg, order, type) zig_unimplemented() |
| 334 | | #define zig_atomicrmw_add(obj, arg, order, type) zig_unimplemented() |
| 335 | | #define zig_atomicrmw_sub(obj, arg, order, type) zig_unimplemented() |
| 336 | | #define zig_atomicrmw_or(obj, arg, order, type) zig_unimplemented() |
| 337 | | #define zig_atomicrmw_xor(obj, arg, order, type) zig_unimplemented() |
| 338 | | #define zig_atomicrmw_and(obj, arg, order, type) zig_unimplemented() |
| 339 | | #define zig_atomicrmw_nand(obj, arg, order, type) zig_unimplemented() |
| 340 | | #define zig_atomicrmw_min(obj, arg, order, type) zig_unimplemented() |
| 341 | | #define zig_atomicrmw_max(obj, arg, order, type) zig_unimplemented() |
| 342 | | #define zig_atomic_store(obj, arg, order, type) zig_unimplemented() |
| 343 | | #define zig_atomic_load(obj, order, type) zig_unimplemented() |
| 344 | | #define zig_fence(order) zig_unimplemented() |
| 345 | | #endif |
| 346 | | |
| 347 | 256 | #if __STDC_VERSION__ >= 201112L |
| 348 | 257 | #define zig_noreturn _Noreturn |
| 349 | 258 | #elif zig_has_attribute(noreturn) || defined(zig_gnuc) |
| ... | ... | @@ -502,15 +411,6 @@ typedef ptrdiff_t intptr_t; |
| 502 | 411 | |
| 503 | 412 | #endif |
| 504 | 413 | |
| 505 | | #define zig_make_small_i8(val) INT8_C(val) |
| 506 | | #define zig_make_small_u8(val) UINT8_C(val) |
| 507 | | #define zig_make_small_i16(val) INT16_C(val) |
| 508 | | #define zig_make_small_u16(val) UINT16_C(val) |
| 509 | | #define zig_make_small_i32(val) INT32_C(val) |
| 510 | | #define zig_make_small_u32(val) UINT32_C(val) |
| 511 | | #define zig_make_small_i64(val) INT64_C(val) |
| 512 | | #define zig_make_small_u64(val) UINT64_C(val) |
| 513 | | |
| 514 | 414 | #define zig_minInt_i8 INT8_MIN |
| 515 | 415 | #define zig_maxInt_i8 INT8_MAX |
| 516 | 416 | #define zig_minInt_u8 UINT8_C(0) |
| ... | ... | @@ -534,24 +434,24 @@ typedef ptrdiff_t intptr_t; |
| 534 | 434 | #define zig_minInt_u(w, bits) zig_intLimit(u, w, min, bits) |
| 535 | 435 | #define zig_maxInt_u(w, bits) zig_intLimit(u, w, max, bits) |
| 536 | 436 | |
| 537 | | #define zig_int_operator(Type, RhsType, operation, operator) \ |
| 437 | #define zig_operator(Type, RhsType, operation, operator) \ |
| 538 | 438 | static inline Type zig_##operation(Type lhs, RhsType rhs) { \ |
| 539 | 439 | return lhs operator rhs; \ |
| 540 | 440 | } |
| 541 | | #define zig_int_basic_operator(Type, operation, operator) \ |
| 542 | | zig_int_operator(Type, Type, operation, operator) |
| 543 | | #define zig_int_shift_operator(Type, operation, operator) \ |
| 544 | | zig_int_operator(Type, uint8_t, operation, operator) |
| 441 | #define zig_basic_operator(Type, operation, operator) \ |
| 442 | zig_operator(Type, Type, operation, operator) |
| 443 | #define zig_shift_operator(Type, operation, operator) \ |
| 444 | zig_operator(Type, uint8_t, operation, operator) |
| 545 | 445 | #define zig_int_helpers(w) \ |
| 546 | | zig_int_basic_operator(uint##w##_t, and_u##w, &) \ |
| 547 | | zig_int_basic_operator( int##w##_t, and_i##w, &) \ |
| 548 | | zig_int_basic_operator(uint##w##_t, or_u##w, |) \ |
| 549 | | zig_int_basic_operator( int##w##_t, or_i##w, |) \ |
| 550 | | zig_int_basic_operator(uint##w##_t, xor_u##w, ^) \ |
| 551 | | zig_int_basic_operator( int##w##_t, xor_i##w, ^) \ |
| 552 | | zig_int_shift_operator(uint##w##_t, shl_u##w, <<) \ |
| 553 | | zig_int_shift_operator( int##w##_t, shl_i##w, <<) \ |
| 554 | | zig_int_shift_operator(uint##w##_t, shr_u##w, >>) \ |
| 446 | zig_basic_operator(uint##w##_t, and_u##w, &) \ |
| 447 | zig_basic_operator( int##w##_t, and_i##w, &) \ |
| 448 | zig_basic_operator(uint##w##_t, or_u##w, |) \ |
| 449 | zig_basic_operator( int##w##_t, or_i##w, |) \ |
| 450 | zig_basic_operator(uint##w##_t, xor_u##w, ^) \ |
| 451 | zig_basic_operator( int##w##_t, xor_i##w, ^) \ |
| 452 | zig_shift_operator(uint##w##_t, shl_u##w, <<) \ |
| 453 | zig_shift_operator( int##w##_t, shl_i##w, <<) \ |
| 454 | zig_shift_operator(uint##w##_t, shr_u##w, >>) \ |
| 555 | 455 | \ |
| 556 | 456 | static inline int##w##_t zig_shr_i##w(int##w##_t lhs, uint8_t rhs) { \ |
| 557 | 457 | int##w##_t sign_mask = lhs < INT##w##_C(0) ? -INT##w##_C(1) : INT##w##_C(0); \ |
| ... | ... | @@ -576,13 +476,13 @@ typedef ptrdiff_t intptr_t; |
| 576 | 476 | ? val | zig_minInt_i(w, bits) : val & zig_maxInt_i(w, bits); \ |
| 577 | 477 | } \ |
| 578 | 478 | \ |
| 579 | | zig_int_basic_operator(uint##w##_t, div_floor_u##w, /) \ |
| 479 | zig_basic_operator(uint##w##_t, div_floor_u##w, /) \ |
| 580 | 480 | \ |
| 581 | 481 | static inline int##w##_t zig_div_floor_i##w(int##w##_t lhs, int##w##_t rhs) { \ |
| 582 | 482 | return lhs / rhs - (((lhs ^ rhs) & (lhs % rhs)) < INT##w##_C(0)); \ |
| 583 | 483 | } \ |
| 584 | 484 | \ |
| 585 | | zig_int_basic_operator(uint##w##_t, mod_u##w, %) \ |
| 485 | zig_basic_operator(uint##w##_t, mod_u##w, %) \ |
| 586 | 486 | \ |
| 587 | 487 | static inline int##w##_t zig_mod_i##w(int##w##_t lhs, int##w##_t rhs) { \ |
| 588 | 488 | int##w##_t rem = lhs % rhs; \ |
| ... | ... | @@ -1253,8 +1153,8 @@ typedef signed __int128 zig_i128; |
| 1253 | 1153 | #define zig_lo_u128(val) ((uint64_t)((val) >> 0)) |
| 1254 | 1154 | #define zig_hi_i128(val) (( int64_t)((val) >> 64)) |
| 1255 | 1155 | #define zig_lo_i128(val) ((uint64_t)((val) >> 0)) |
| 1256 | | #define zig_bitcast_u128(val) ((zig_u128)(val)) |
| 1257 | | #define zig_bitcast_i128(val) ((zig_i128)(val)) |
| 1156 | #define zig_bitCast_u128(val) ((zig_u128)(val)) |
| 1157 | #define zig_bitCast_i128(val) ((zig_i128)(val)) |
| 1258 | 1158 | #define zig_cmp_int128(Type) \ |
| 1259 | 1159 | static inline int32_t zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \ |
| 1260 | 1160 | return (lhs > rhs) - (lhs < rhs); \ |
| ... | ... | @@ -1288,8 +1188,8 @@ typedef struct { zig_align(16) int64_t hi; uint64_t lo; } zig_i128; |
| 1288 | 1188 | #define zig_lo_u128(val) ((val).lo) |
| 1289 | 1189 | #define zig_hi_i128(val) ((val).hi) |
| 1290 | 1190 | #define zig_lo_i128(val) ((val).lo) |
| 1291 | | #define zig_bitcast_u128(val) zig_make_u128((uint64_t)(val).hi, (val).lo) |
| 1292 | | #define zig_bitcast_i128(val) zig_make_i128(( int64_t)(val).hi, (val).lo) |
| 1191 | #define zig_bitCast_u128(val) zig_make_u128((uint64_t)(val).hi, (val).lo) |
| 1192 | #define zig_bitCast_i128(val) zig_make_i128(( int64_t)(val).hi, (val).lo) |
| 1293 | 1193 | #define zig_cmp_int128(Type) \ |
| 1294 | 1194 | static inline int32_t zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \ |
| 1295 | 1195 | return (lhs.hi == rhs.hi) \ |
| ... | ... | @@ -1303,9 +1203,6 @@ typedef struct { zig_align(16) int64_t hi; uint64_t lo; } zig_i128; |
| 1303 | 1203 | |
| 1304 | 1204 | #endif /* zig_has_int128 */ |
| 1305 | 1205 | |
| 1306 | | #define zig_make_small_u128(val) zig_make_u128(0, val) |
| 1307 | | #define zig_make_small_i128(val) zig_make_i128((val) < 0 ? -INT64_C(1) : INT64_C(0), val) |
| 1308 | | |
| 1309 | 1206 | #define zig_minInt_u128 zig_make_u128(zig_minInt_u64, zig_minInt_u64) |
| 1310 | 1207 | #define zig_maxInt_u128 zig_make_u128(zig_maxInt_u64, zig_maxInt_u64) |
| 1311 | 1208 | #define zig_minInt_i128 zig_make_i128(zig_minInt_i64, zig_minInt_u64) |
| ... | ... | @@ -1466,18 +1363,18 @@ static zig_i128 zig_mul_i128(zig_i128 lhs, zig_i128 rhs) { |
| 1466 | 1363 | } |
| 1467 | 1364 | |
| 1468 | 1365 | static zig_u128 zig_mul_u128(zig_u128 lhs, zig_u128 rhs) { |
| 1469 | | return zig_bitcast_u128(zig_mul_i128(zig_bitcast_i128(lhs), zig_bitcast_i128(rhs))); |
| 1366 | return zig_bitCast_u128(zig_mul_i128(zig_bitCast_i128(lhs), zig_bitCast_i128(rhs))); |
| 1470 | 1367 | } |
| 1471 | 1368 | |
| 1472 | 1369 | zig_extern zig_u128 __udivti3(zig_u128 lhs, zig_u128 rhs); |
| 1473 | 1370 | static zig_u128 zig_div_trunc_u128(zig_u128 lhs, zig_u128 rhs) { |
| 1474 | 1371 | return __udivti3(lhs, rhs); |
| 1475 | | }; |
| 1372 | } |
| 1476 | 1373 | |
| 1477 | 1374 | zig_extern zig_i128 __divti3(zig_i128 lhs, zig_i128 rhs); |
| 1478 | 1375 | static zig_i128 zig_div_trunc_i128(zig_i128 lhs, zig_i128 rhs) { |
| 1479 | 1376 | return __divti3(lhs, rhs); |
| 1480 | | }; |
| 1377 | } |
| 1481 | 1378 | |
| 1482 | 1379 | zig_extern zig_u128 __umodti3(zig_u128 lhs, zig_u128 rhs); |
| 1483 | 1380 | static zig_u128 zig_rem_u128(zig_u128 lhs, zig_u128 rhs) { |
| ... | ... | @@ -1503,10 +1400,6 @@ static inline zig_i128 zig_div_floor_i128(zig_i128 lhs, zig_i128 rhs) { |
| 1503 | 1400 | #define zig_div_floor_u128 zig_div_trunc_u128 |
| 1504 | 1401 | #define zig_mod_u128 zig_rem_u128 |
| 1505 | 1402 | |
| 1506 | | static inline zig_u128 zig_nand_u128(zig_u128 lhs, zig_u128 rhs) { |
| 1507 | | return zig_not_u128(zig_and_u128(lhs, rhs), 128); |
| 1508 | | } |
| 1509 | | |
| 1510 | 1403 | static inline zig_u128 zig_min_u128(zig_u128 lhs, zig_u128 rhs) { |
| 1511 | 1404 | return zig_cmp_u128(lhs, rhs) < INT32_C(0) ? lhs : rhs; |
| 1512 | 1405 | } |
| ... | ... | @@ -1538,7 +1431,7 @@ static inline zig_u128 zig_shlw_u128(zig_u128 lhs, uint8_t rhs, uint8_t bits) { |
| 1538 | 1431 | } |
| 1539 | 1432 | |
| 1540 | 1433 | static inline zig_i128 zig_shlw_i128(zig_i128 lhs, uint8_t rhs, uint8_t bits) { |
| 1541 | | return zig_wrap_i128(zig_bitcast_i128(zig_shl_u128(zig_bitcast_u128(lhs), rhs)), bits); |
| 1434 | return zig_wrap_i128(zig_bitCast_i128(zig_shl_u128(zig_bitCast_u128(lhs), rhs)), bits); |
| 1542 | 1435 | } |
| 1543 | 1436 | |
| 1544 | 1437 | static inline zig_u128 zig_addw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| ... | ... | @@ -1546,7 +1439,7 @@ static inline zig_u128 zig_addw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1546 | 1439 | } |
| 1547 | 1440 | |
| 1548 | 1441 | static inline zig_i128 zig_addw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1549 | | return zig_wrap_i128(zig_bitcast_i128(zig_add_u128(zig_bitcast_u128(lhs), zig_bitcast_u128(rhs))), bits); |
| 1442 | return zig_wrap_i128(zig_bitCast_i128(zig_add_u128(zig_bitCast_u128(lhs), zig_bitCast_u128(rhs))), bits); |
| 1550 | 1443 | } |
| 1551 | 1444 | |
| 1552 | 1445 | static inline zig_u128 zig_subw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| ... | ... | @@ -1554,7 +1447,7 @@ static inline zig_u128 zig_subw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1554 | 1447 | } |
| 1555 | 1448 | |
| 1556 | 1449 | static inline zig_i128 zig_subw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1557 | | return zig_wrap_i128(zig_bitcast_i128(zig_sub_u128(zig_bitcast_u128(lhs), zig_bitcast_u128(rhs))), bits); |
| 1450 | return zig_wrap_i128(zig_bitCast_i128(zig_sub_u128(zig_bitCast_u128(lhs), zig_bitCast_u128(rhs))), bits); |
| 1558 | 1451 | } |
| 1559 | 1452 | |
| 1560 | 1453 | static inline zig_u128 zig_mulw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| ... | ... | @@ -1562,7 +1455,7 @@ static inline zig_u128 zig_mulw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1562 | 1455 | } |
| 1563 | 1456 | |
| 1564 | 1457 | static inline zig_i128 zig_mulw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1565 | | return zig_wrap_i128(zig_bitcast_i128(zig_mul_u128(zig_bitcast_u128(lhs), zig_bitcast_u128(rhs))), bits); |
| 1458 | return zig_wrap_i128(zig_bitCast_i128(zig_mul_u128(zig_bitCast_u128(lhs), zig_bitCast_u128(rhs))), bits); |
| 1566 | 1459 | } |
| 1567 | 1460 | |
| 1568 | 1461 | #if zig_has_int128 |
| ... | ... | @@ -1697,7 +1590,7 @@ static inline bool zig_shlo_u128(zig_u128 *res, zig_u128 lhs, uint8_t rhs, uint8 |
| 1697 | 1590 | |
| 1698 | 1591 | static inline bool zig_shlo_i128(zig_i128 *res, zig_i128 lhs, uint8_t rhs, uint8_t bits) { |
| 1699 | 1592 | *res = zig_shlw_i128(lhs, rhs, bits); |
| 1700 | | zig_i128 mask = zig_bitcast_i128(zig_shl_u128(zig_maxInt_u128, bits - rhs - UINT8_C(1))); |
| 1593 | zig_i128 mask = zig_bitCast_i128(zig_shl_u128(zig_maxInt_u128, bits - rhs - UINT8_C(1))); |
| 1701 | 1594 | return zig_cmp_i128(zig_and_i128(lhs, mask), zig_make_i128(0, 0)) != INT32_C(0) && |
| 1702 | 1595 | zig_cmp_i128(zig_and_i128(lhs, mask), mask) != INT32_C(0); |
| 1703 | 1596 | } |
| ... | ... | @@ -1711,7 +1604,7 @@ static inline zig_u128 zig_shls_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1711 | 1604 | |
| 1712 | 1605 | static inline zig_i128 zig_shls_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1713 | 1606 | zig_i128 res; |
| 1714 | | if (zig_cmp_u128(zig_bitcast_u128(rhs), zig_make_u128(0, bits)) < INT32_C(0) && !zig_shlo_i128(&res, lhs, (uint8_t)zig_lo_i128(rhs), bits)) return res; |
| 1607 | if (zig_cmp_u128(zig_bitCast_u128(rhs), zig_make_u128(0, bits)) < INT32_C(0) && !zig_shlo_i128(&res, lhs, (uint8_t)zig_lo_i128(rhs), bits)) return res; |
| 1715 | 1608 | return zig_cmp_i128(lhs, zig_make_i128(0, 0)) < INT32_C(0) ? zig_minInt_i(128, bits) : zig_maxInt_i(128, bits); |
| 1716 | 1609 | } |
| 1717 | 1610 | |
| ... | ... | @@ -1755,7 +1648,7 @@ static inline uint8_t zig_clz_u128(zig_u128 val, uint8_t bits) { |
| 1755 | 1648 | } |
| 1756 | 1649 | |
| 1757 | 1650 | static inline uint8_t zig_clz_i128(zig_i128 val, uint8_t bits) { |
| 1758 | | return zig_clz_u128(zig_bitcast_u128(val), bits); |
| 1651 | return zig_clz_u128(zig_bitCast_u128(val), bits); |
| 1759 | 1652 | } |
| 1760 | 1653 | |
| 1761 | 1654 | static inline uint8_t zig_ctz_u128(zig_u128 val, uint8_t bits) { |
| ... | ... | @@ -1764,7 +1657,7 @@ static inline uint8_t zig_ctz_u128(zig_u128 val, uint8_t bits) { |
| 1764 | 1657 | } |
| 1765 | 1658 | |
| 1766 | 1659 | static inline uint8_t zig_ctz_i128(zig_i128 val, uint8_t bits) { |
| 1767 | | return zig_ctz_u128(zig_bitcast_u128(val), bits); |
| 1660 | return zig_ctz_u128(zig_bitCast_u128(val), bits); |
| 1768 | 1661 | } |
| 1769 | 1662 | |
| 1770 | 1663 | static inline uint8_t zig_popcount_u128(zig_u128 val, uint8_t bits) { |
| ... | ... | @@ -1773,7 +1666,7 @@ static inline uint8_t zig_popcount_u128(zig_u128 val, uint8_t bits) { |
| 1773 | 1666 | } |
| 1774 | 1667 | |
| 1775 | 1668 | static inline uint8_t zig_popcount_i128(zig_i128 val, uint8_t bits) { |
| 1776 | | return zig_popcount_u128(zig_bitcast_u128(val), bits); |
| 1669 | return zig_popcount_u128(zig_bitCast_u128(val), bits); |
| 1777 | 1670 | } |
| 1778 | 1671 | |
| 1779 | 1672 | static inline zig_u128 zig_byte_swap_u128(zig_u128 val, uint8_t bits) { |
| ... | ... | @@ -1788,7 +1681,7 @@ static inline zig_u128 zig_byte_swap_u128(zig_u128 val, uint8_t bits) { |
| 1788 | 1681 | } |
| 1789 | 1682 | |
| 1790 | 1683 | static inline zig_i128 zig_byte_swap_i128(zig_i128 val, uint8_t bits) { |
| 1791 | | return zig_bitcast_i128(zig_byte_swap_u128(zig_bitcast_u128(val), bits)); |
| 1684 | return zig_bitCast_i128(zig_byte_swap_u128(zig_bitCast_u128(val), bits)); |
| 1792 | 1685 | } |
| 1793 | 1686 | |
| 1794 | 1687 | static inline zig_u128 zig_bit_reverse_u128(zig_u128 val, uint8_t bits) { |
| ... | ... | @@ -1798,7 +1691,7 @@ static inline zig_u128 zig_bit_reverse_u128(zig_u128 val, uint8_t bits) { |
| 1798 | 1691 | } |
| 1799 | 1692 | |
| 1800 | 1693 | static inline zig_i128 zig_bit_reverse_i128(zig_i128 val, uint8_t bits) { |
| 1801 | | return zig_bitcast_i128(zig_bit_reverse_u128(zig_bitcast_u128(val), bits)); |
| 1694 | return zig_bitCast_i128(zig_bit_reverse_u128(zig_bitCast_u128(val), bits)); |
| 1802 | 1695 | } |
| 1803 | 1696 | |
| 1804 | 1697 | /* ========================== Big Integer Support =========================== */ |
| ... | ... | @@ -1972,6 +1865,243 @@ static inline int32_t zig_cmp_big(const void *lhs, const void *rhs, bool is_sign |
| 1972 | 1865 | return 0; |
| 1973 | 1866 | } |
| 1974 | 1867 | |
| 1868 | static inline void zig_and_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { |
| 1869 | uint8_t *res_bytes = res; |
| 1870 | const uint8_t *lhs_bytes = lhs; |
| 1871 | const uint8_t *rhs_bytes = rhs; |
| 1872 | uint16_t byte_offset = 0; |
| 1873 | uint16_t remaining_bytes = zig_int_bytes(bits); |
| 1874 | (void)is_signed; |
| 1875 | |
| 1876 | while (remaining_bytes >= 128 / CHAR_BIT) { |
| 1877 | zig_u128 res_limb; |
| 1878 | zig_u128 lhs_limb; |
| 1879 | zig_u128 rhs_limb; |
| 1880 | |
| 1881 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); |
| 1882 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); |
| 1883 | res_limb = zig_and_u128(lhs_limb, rhs_limb); |
| 1884 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); |
| 1885 | |
| 1886 | remaining_bytes -= 128 / CHAR_BIT; |
| 1887 | byte_offset += 128 / CHAR_BIT; |
| 1888 | } |
| 1889 | |
| 1890 | while (remaining_bytes >= 64 / CHAR_BIT) { |
| 1891 | uint64_t res_limb; |
| 1892 | uint64_t lhs_limb; |
| 1893 | uint64_t rhs_limb; |
| 1894 | |
| 1895 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); |
| 1896 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); |
| 1897 | res_limb = zig_and_u64(lhs_limb, rhs_limb); |
| 1898 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); |
| 1899 | |
| 1900 | remaining_bytes -= 64 / CHAR_BIT; |
| 1901 | byte_offset += 64 / CHAR_BIT; |
| 1902 | } |
| 1903 | |
| 1904 | while (remaining_bytes >= 32 / CHAR_BIT) { |
| 1905 | uint32_t res_limb; |
| 1906 | uint32_t lhs_limb; |
| 1907 | uint32_t rhs_limb; |
| 1908 | |
| 1909 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); |
| 1910 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); |
| 1911 | res_limb = zig_and_u32(lhs_limb, rhs_limb); |
| 1912 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); |
| 1913 | |
| 1914 | remaining_bytes -= 32 / CHAR_BIT; |
| 1915 | byte_offset += 32 / CHAR_BIT; |
| 1916 | } |
| 1917 | |
| 1918 | while (remaining_bytes >= 16 / CHAR_BIT) { |
| 1919 | uint16_t res_limb; |
| 1920 | uint16_t lhs_limb; |
| 1921 | uint16_t rhs_limb; |
| 1922 | |
| 1923 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); |
| 1924 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); |
| 1925 | res_limb = zig_and_u16(lhs_limb, rhs_limb); |
| 1926 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); |
| 1927 | |
| 1928 | remaining_bytes -= 16 / CHAR_BIT; |
| 1929 | byte_offset += 16 / CHAR_BIT; |
| 1930 | } |
| 1931 | |
| 1932 | while (remaining_bytes >= 8 / CHAR_BIT) { |
| 1933 | uint8_t res_limb; |
| 1934 | uint8_t lhs_limb; |
| 1935 | uint8_t rhs_limb; |
| 1936 | |
| 1937 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); |
| 1938 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); |
| 1939 | res_limb = zig_and_u8(lhs_limb, rhs_limb); |
| 1940 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); |
| 1941 | |
| 1942 | remaining_bytes -= 8 / CHAR_BIT; |
| 1943 | byte_offset += 8 / CHAR_BIT; |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | static inline void zig_or_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { |
| 1948 | uint8_t *res_bytes = res; |
| 1949 | const uint8_t *lhs_bytes = lhs; |
| 1950 | const uint8_t *rhs_bytes = rhs; |
| 1951 | uint16_t byte_offset = 0; |
| 1952 | uint16_t remaining_bytes = zig_int_bytes(bits); |
| 1953 | (void)is_signed; |
| 1954 | |
| 1955 | while (remaining_bytes >= 128 / CHAR_BIT) { |
| 1956 | zig_u128 res_limb; |
| 1957 | zig_u128 lhs_limb; |
| 1958 | zig_u128 rhs_limb; |
| 1959 | |
| 1960 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); |
| 1961 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); |
| 1962 | res_limb = zig_or_u128(lhs_limb, rhs_limb); |
| 1963 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); |
| 1964 | |
| 1965 | remaining_bytes -= 128 / CHAR_BIT; |
| 1966 | byte_offset += 128 / CHAR_BIT; |
| 1967 | } |
| 1968 | |
| 1969 | while (remaining_bytes >= 64 / CHAR_BIT) { |
| 1970 | uint64_t res_limb; |
| 1971 | uint64_t lhs_limb; |
| 1972 | uint64_t rhs_limb; |
| 1973 | |
| 1974 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); |
| 1975 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); |
| 1976 | res_limb = zig_or_u64(lhs_limb, rhs_limb); |
| 1977 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); |
| 1978 | |
| 1979 | remaining_bytes -= 64 / CHAR_BIT; |
| 1980 | byte_offset += 64 / CHAR_BIT; |
| 1981 | } |
| 1982 | |
| 1983 | while (remaining_bytes >= 32 / CHAR_BIT) { |
| 1984 | uint32_t res_limb; |
| 1985 | uint32_t lhs_limb; |
| 1986 | uint32_t rhs_limb; |
| 1987 | |
| 1988 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); |
| 1989 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); |
| 1990 | res_limb = zig_or_u32(lhs_limb, rhs_limb); |
| 1991 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); |
| 1992 | |
| 1993 | remaining_bytes -= 32 / CHAR_BIT; |
| 1994 | byte_offset += 32 / CHAR_BIT; |
| 1995 | } |
| 1996 | |
| 1997 | while (remaining_bytes >= 16 / CHAR_BIT) { |
| 1998 | uint16_t res_limb; |
| 1999 | uint16_t lhs_limb; |
| 2000 | uint16_t rhs_limb; |
| 2001 | |
| 2002 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); |
| 2003 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); |
| 2004 | res_limb = zig_or_u16(lhs_limb, rhs_limb); |
| 2005 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); |
| 2006 | |
| 2007 | remaining_bytes -= 16 / CHAR_BIT; |
| 2008 | byte_offset += 16 / CHAR_BIT; |
| 2009 | } |
| 2010 | |
| 2011 | while (remaining_bytes >= 8 / CHAR_BIT) { |
| 2012 | uint8_t res_limb; |
| 2013 | uint8_t lhs_limb; |
| 2014 | uint8_t rhs_limb; |
| 2015 | |
| 2016 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); |
| 2017 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); |
| 2018 | res_limb = zig_or_u8(lhs_limb, rhs_limb); |
| 2019 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); |
| 2020 | |
| 2021 | remaining_bytes -= 8 / CHAR_BIT; |
| 2022 | byte_offset += 8 / CHAR_BIT; |
| 2023 | } |
| 2024 | } |
| 2025 | |
| 2026 | static inline void zig_xor_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { |
| 2027 | uint8_t *res_bytes = res; |
| 2028 | const uint8_t *lhs_bytes = lhs; |
| 2029 | const uint8_t *rhs_bytes = rhs; |
| 2030 | uint16_t byte_offset = 0; |
| 2031 | uint16_t remaining_bytes = zig_int_bytes(bits); |
| 2032 | (void)is_signed; |
| 2033 | |
| 2034 | while (remaining_bytes >= 128 / CHAR_BIT) { |
| 2035 | zig_u128 res_limb; |
| 2036 | zig_u128 lhs_limb; |
| 2037 | zig_u128 rhs_limb; |
| 2038 | |
| 2039 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); |
| 2040 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); |
| 2041 | res_limb = zig_xor_u128(lhs_limb, rhs_limb); |
| 2042 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); |
| 2043 | |
| 2044 | remaining_bytes -= 128 / CHAR_BIT; |
| 2045 | byte_offset += 128 / CHAR_BIT; |
| 2046 | } |
| 2047 | |
| 2048 | while (remaining_bytes >= 64 / CHAR_BIT) { |
| 2049 | uint64_t res_limb; |
| 2050 | uint64_t lhs_limb; |
| 2051 | uint64_t rhs_limb; |
| 2052 | |
| 2053 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); |
| 2054 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); |
| 2055 | res_limb = zig_xor_u64(lhs_limb, rhs_limb); |
| 2056 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); |
| 2057 | |
| 2058 | remaining_bytes -= 64 / CHAR_BIT; |
| 2059 | byte_offset += 64 / CHAR_BIT; |
| 2060 | } |
| 2061 | |
| 2062 | while (remaining_bytes >= 32 / CHAR_BIT) { |
| 2063 | uint32_t res_limb; |
| 2064 | uint32_t lhs_limb; |
| 2065 | uint32_t rhs_limb; |
| 2066 | |
| 2067 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); |
| 2068 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); |
| 2069 | res_limb = zig_xor_u32(lhs_limb, rhs_limb); |
| 2070 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); |
| 2071 | |
| 2072 | remaining_bytes -= 32 / CHAR_BIT; |
| 2073 | byte_offset += 32 / CHAR_BIT; |
| 2074 | } |
| 2075 | |
| 2076 | while (remaining_bytes >= 16 / CHAR_BIT) { |
| 2077 | uint16_t res_limb; |
| 2078 | uint16_t lhs_limb; |
| 2079 | uint16_t rhs_limb; |
| 2080 | |
| 2081 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); |
| 2082 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); |
| 2083 | res_limb = zig_xor_u16(lhs_limb, rhs_limb); |
| 2084 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); |
| 2085 | |
| 2086 | remaining_bytes -= 16 / CHAR_BIT; |
| 2087 | byte_offset += 16 / CHAR_BIT; |
| 2088 | } |
| 2089 | |
| 2090 | while (remaining_bytes >= 8 / CHAR_BIT) { |
| 2091 | uint8_t res_limb; |
| 2092 | uint8_t lhs_limb; |
| 2093 | uint8_t rhs_limb; |
| 2094 | |
| 2095 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); |
| 2096 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); |
| 2097 | res_limb = zig_xor_u8(lhs_limb, rhs_limb); |
| 2098 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); |
| 2099 | |
| 2100 | remaining_bytes -= 8 / CHAR_BIT; |
| 2101 | byte_offset += 8 / CHAR_BIT; |
| 2102 | } |
| 2103 | } |
| 2104 | |
| 1975 | 2105 | static inline bool zig_addo_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { |
| 1976 | 2106 | uint8_t *res_bytes = res; |
| 1977 | 2107 | const uint8_t *lhs_bytes = lhs; |
| ... | ... | @@ -2827,24 +2957,20 @@ long double __cdecl nanl(char const* input); |
| 2827 | 2957 | #endif |
| 2828 | 2958 | |
| 2829 | 2959 | #if (zig_has_builtin(nan) && zig_has_builtin(nans) && zig_has_builtin(inf)) || defined(zig_gnuc) |
| 2830 | | #define zig_has_float_builtins 1 |
| 2831 | | #define zig_make_special_f16(sign, name, arg, repr) sign zig_make_f16(__builtin_##name, )(arg) |
| 2832 | | #define zig_make_special_f32(sign, name, arg, repr) sign zig_make_f32(__builtin_##name, )(arg) |
| 2833 | | #define zig_make_special_f64(sign, name, arg, repr) sign zig_make_f64(__builtin_##name, )(arg) |
| 2834 | | #define zig_make_special_f80(sign, name, arg, repr) sign zig_make_f80(__builtin_##name, )(arg) |
| 2960 | #define zig_make_special_f16(sign, name, arg, repr) sign zig_make_f16 (__builtin_##name, )(arg) |
| 2961 | #define zig_make_special_f32(sign, name, arg, repr) sign zig_make_f32 (__builtin_##name, )(arg) |
| 2962 | #define zig_make_special_f64(sign, name, arg, repr) sign zig_make_f64 (__builtin_##name, )(arg) |
| 2963 | #define zig_make_special_f80(sign, name, arg, repr) sign zig_make_f80 (__builtin_##name, )(arg) |
| 2835 | 2964 | #define zig_make_special_f128(sign, name, arg, repr) sign zig_make_f128(__builtin_##name, )(arg) |
| 2836 | 2965 | #else |
| 2837 | | #define zig_has_float_builtins 0 |
| 2838 | | #define zig_make_special_f16(sign, name, arg, repr) zig_float_from_repr_f16(repr) |
| 2839 | | #define zig_make_special_f32(sign, name, arg, repr) zig_float_from_repr_f32(repr) |
| 2840 | | #define zig_make_special_f64(sign, name, arg, repr) zig_float_from_repr_f64(repr) |
| 2841 | | #define zig_make_special_f80(sign, name, arg, repr) zig_float_from_repr_f80(repr) |
| 2842 | | #define zig_make_special_f128(sign, name, arg, repr) zig_float_from_repr_f128(repr) |
| 2966 | #define zig_make_special_f16(sign, name, arg, repr) zig_bitCast_f16 (repr) |
| 2967 | #define zig_make_special_f32(sign, name, arg, repr) zig_bitCast_f32 (repr) |
| 2968 | #define zig_make_special_f64(sign, name, arg, repr) zig_bitCast_f64 (repr) |
| 2969 | #define zig_make_special_f80(sign, name, arg, repr) zig_bitCast_f80 (repr) |
| 2970 | #define zig_make_special_f128(sign, name, arg, repr) zig_bitCast_f128(repr) |
| 2843 | 2971 | #endif |
| 2844 | 2972 | |
| 2845 | 2973 | #define zig_has_f16 1 |
| 2846 | | #define zig_bitSizeOf_f16 16 |
| 2847 | | typedef uint16_t zig_repr_f16; |
| 2848 | 2974 | #define zig_libc_name_f16(name) __##name##h |
| 2849 | 2975 | #define zig_init_special_f16(sign, name, arg, repr) zig_make_special_f16(sign, name, arg, repr) |
| 2850 | 2976 | #if FLT_MANT_DIG == 11 |
| ... | ... | @@ -2854,10 +2980,6 @@ typedef float zig_f16; |
| 2854 | 2980 | typedef double zig_f16; |
| 2855 | 2981 | #define zig_make_f16(fp, repr) fp |
| 2856 | 2982 | #elif LDBL_MANT_DIG == 11 |
| 2857 | | #define zig_bitSizeOf_c_longdouble 16 |
| 2858 | | #ifndef ZIG_TARGET_ABI_MSVC |
| 2859 | | typedef zig_repr_f16 zig_repr_c_longdouble; |
| 2860 | | #endif |
| 2861 | 2983 | typedef long double zig_f16; |
| 2862 | 2984 | #define zig_make_f16(fp, repr) fp##l |
| 2863 | 2985 | #elif FLT16_MANT_DIG == 11 && (zig_has_builtin(inff16) || defined(zig_gnuc)) |
| ... | ... | @@ -2869,8 +2991,8 @@ typedef __fp16 zig_f16; |
| 2869 | 2991 | #else |
| 2870 | 2992 | #undef zig_has_f16 |
| 2871 | 2993 | #define zig_has_f16 0 |
| 2872 | | #define zig_bitSizeOf_repr_f16 16 |
| 2873 | | typedef zig_repr_f16 zig_f16; |
| 2994 | #define zig_repr_f16 u16 |
| 2995 | typedef uint16_t zig_f16; |
| 2874 | 2996 | #define zig_make_f16(fp, repr) repr |
| 2875 | 2997 | #undef zig_make_special_f16 |
| 2876 | 2998 | #define zig_make_special_f16(sign, name, arg, repr) repr |
| ... | ... | @@ -2878,15 +3000,12 @@ typedef zig_repr_f16 zig_f16; |
| 2878 | 3000 | #define zig_init_special_f16(sign, name, arg, repr) repr |
| 2879 | 3001 | #endif |
| 2880 | 3002 | #if __APPLE__ && (defined(__i386__) || defined(__x86_64__)) |
| 2881 | | typedef zig_repr_f16 zig_compiler_rt_f16; |
| 3003 | typedef uint16_t zig_compiler_rt_f16; |
| 2882 | 3004 | #else |
| 2883 | 3005 | typedef zig_f16 zig_compiler_rt_f16; |
| 2884 | 3006 | #endif |
| 2885 | | #define zig_compiler_rt_abbrev_zig_compiler_rt_f16 zig_compiler_rt_abbrev_zig_f16 |
| 2886 | 3007 | |
| 2887 | 3008 | #define zig_has_f32 1 |
| 2888 | | #define zig_bitSizeOf_f32 32 |
| 2889 | | typedef uint32_t zig_repr_f32; |
| 2890 | 3009 | #define zig_libc_name_f32(name) name##f |
| 2891 | 3010 | #if _MSC_VER |
| 2892 | 3011 | #define zig_init_special_f32(sign, name, arg, repr) sign zig_make_f32(zig_msvc_flt_##name, ) |
| ... | ... | @@ -2900,10 +3019,6 @@ typedef float zig_f32; |
| 2900 | 3019 | typedef double zig_f32; |
| 2901 | 3020 | #define zig_make_f32(fp, repr) fp |
| 2902 | 3021 | #elif LDBL_MANT_DIG == 24 |
| 2903 | | #define zig_bitSizeOf_c_longdouble 32 |
| 2904 | | #ifndef ZIG_TARGET_ABI_MSVC |
| 2905 | | typedef zig_repr_f32 zig_repr_c_longdouble; |
| 2906 | | #endif |
| 2907 | 3022 | typedef long double zig_f32; |
| 2908 | 3023 | #define zig_make_f32(fp, repr) fp##l |
| 2909 | 3024 | #elif FLT32_MANT_DIG == 24 |
| ... | ... | @@ -2912,8 +3027,8 @@ typedef _Float32 zig_f32; |
| 2912 | 3027 | #else |
| 2913 | 3028 | #undef zig_has_f32 |
| 2914 | 3029 | #define zig_has_f32 0 |
| 2915 | | #define zig_bitSizeOf_repr_f32 32 |
| 2916 | | typedef zig_repr_f32 zig_f32; |
| 3030 | #define zig_repr_f32 u32 |
| 3031 | ypedef uint32_t zig_f32; |
| 2917 | 3032 | #define zig_make_f32(fp, repr) repr |
| 2918 | 3033 | #undef zig_make_special_f32 |
| 2919 | 3034 | #define zig_make_special_f32(sign, name, arg, repr) repr |
| ... | ... | @@ -2922,20 +3037,12 @@ typedef zig_repr_f32 zig_f32; |
| 2922 | 3037 | #endif |
| 2923 | 3038 | |
| 2924 | 3039 | #define zig_has_f64 1 |
| 2925 | | #define zig_bitSizeOf_f64 64 |
| 2926 | | typedef uint64_t zig_repr_f64; |
| 2927 | 3040 | #define zig_libc_name_f64(name) name |
| 2928 | 3041 | #if _MSC_VER |
| 2929 | | #ifdef ZIG_TARGET_ABI_MSVC |
| 2930 | | #define zig_bitSizeOf_c_longdouble 64 |
| 2931 | | #ifndef ZIG_TARGET_ABI_MSVC |
| 2932 | | typedef zig_repr_f64 zig_repr_c_longdouble; |
| 2933 | | #endif |
| 2934 | | #endif |
| 2935 | 3042 | #define zig_init_special_f64(sign, name, arg, repr) sign zig_make_f64(zig_msvc_flt_##name, ) |
| 2936 | | #else /* _MSC_VER */ |
| 3043 | #else |
| 2937 | 3044 | #define zig_init_special_f64(sign, name, arg, repr) zig_make_special_f64(sign, name, arg, repr) |
| 2938 | | #endif /* _MSC_VER */ |
| 3045 | #endif |
| 2939 | 3046 | #if FLT_MANT_DIG == 53 |
| 2940 | 3047 | typedef float zig_f64; |
| 2941 | 3048 | #define zig_make_f64(fp, repr) fp##f |
| ... | ... | @@ -2943,10 +3050,6 @@ typedef float zig_f64; |
| 2943 | 3050 | typedef double zig_f64; |
| 2944 | 3051 | #define zig_make_f64(fp, repr) fp |
| 2945 | 3052 | #elif LDBL_MANT_DIG == 53 |
| 2946 | | #define zig_bitSizeOf_c_longdouble 64 |
| 2947 | | #ifndef ZIG_TARGET_ABI_MSVC |
| 2948 | | typedef zig_repr_f64 zig_repr_c_longdouble; |
| 2949 | | #endif |
| 2950 | 3053 | typedef long double zig_f64; |
| 2951 | 3054 | #define zig_make_f64(fp, repr) fp##l |
| 2952 | 3055 | #elif FLT64_MANT_DIG == 53 |
| ... | ... | @@ -2958,8 +3061,8 @@ typedef _Float32x zig_f64; |
| 2958 | 3061 | #else |
| 2959 | 3062 | #undef zig_has_f64 |
| 2960 | 3063 | #define zig_has_f64 0 |
| 2961 | | #define zig_bitSizeOf_repr_f64 64 |
| 2962 | | typedef zig_repr_f64 zig_f64; |
| 3064 | #define zig_repr_f64 u64 |
| 3065 | typedef uint64_t zig_f64; |
| 2963 | 3066 | #define zig_make_f64(fp, repr) repr |
| 2964 | 3067 | #undef zig_make_special_f64 |
| 2965 | 3068 | #define zig_make_special_f64(sign, name, arg, repr) repr |
| ... | ... | @@ -2968,8 +3071,6 @@ typedef zig_repr_f64 zig_f64; |
| 2968 | 3071 | #endif |
| 2969 | 3072 | |
| 2970 | 3073 | #define zig_has_f80 1 |
| 2971 | | #define zig_bitSizeOf_f80 80 |
| 2972 | | typedef zig_u128 zig_repr_f80; |
| 2973 | 3074 | #define zig_libc_name_f80(name) __##name##x |
| 2974 | 3075 | #define zig_init_special_f80(sign, name, arg, repr) zig_make_special_f80(sign, name, arg, repr) |
| 2975 | 3076 | #if FLT_MANT_DIG == 64 |
| ... | ... | @@ -2979,10 +3080,6 @@ typedef float zig_f80; |
| 2979 | 3080 | typedef double zig_f80; |
| 2980 | 3081 | #define zig_make_f80(fp, repr) fp |
| 2981 | 3082 | #elif LDBL_MANT_DIG == 64 |
| 2982 | | #define zig_bitSizeOf_c_longdouble 80 |
| 2983 | | #ifndef ZIG_TARGET_ABI_MSVC |
| 2984 | | typedef zig_repr_f80 zig_repr_c_longdouble; |
| 2985 | | #endif |
| 2986 | 3083 | typedef long double zig_f80; |
| 2987 | 3084 | #define zig_make_f80(fp, repr) fp##l |
| 2988 | 3085 | #elif FLT80_MANT_DIG == 64 |
| ... | ... | @@ -2997,8 +3094,8 @@ typedef __float80 zig_f80; |
| 2997 | 3094 | #else |
| 2998 | 3095 | #undef zig_has_f80 |
| 2999 | 3096 | #define zig_has_f80 0 |
| 3000 | | #define zig_bitSizeOf_repr_f80 128 |
| 3001 | | typedef zig_repr_f80 zig_f80; |
| 3097 | #define zig_repr_f80 u128 |
| 3098 | typedef zig_u128 zig_f80; |
| 3002 | 3099 | #define zig_make_f80(fp, repr) repr |
| 3003 | 3100 | #undef zig_make_special_f80 |
| 3004 | 3101 | #define zig_make_special_f80(sign, name, arg, repr) repr |
| ... | ... | @@ -3007,8 +3104,6 @@ typedef zig_repr_f80 zig_f80; |
| 3007 | 3104 | #endif |
| 3008 | 3105 | |
| 3009 | 3106 | #define zig_has_f128 1 |
| 3010 | | #define zig_bitSizeOf_f128 128 |
| 3011 | | typedef zig_u128 zig_repr_f128; |
| 3012 | 3107 | #define zig_libc_name_f128(name) name##q |
| 3013 | 3108 | #define zig_init_special_f128(sign, name, arg, repr) zig_make_special_f128(sign, name, arg, repr) |
| 3014 | 3109 | #if FLT_MANT_DIG == 113 |
| ... | ... | @@ -3018,10 +3113,6 @@ typedef float zig_f128; |
| 3018 | 3113 | typedef double zig_f128; |
| 3019 | 3114 | #define zig_make_f128(fp, repr) fp |
| 3020 | 3115 | #elif LDBL_MANT_DIG == 113 |
| 3021 | | #define zig_bitSizeOf_c_longdouble 128 |
| 3022 | | #ifndef ZIG_TARGET_ABI_MSVC |
| 3023 | | typedef zig_repr_f128 zig_repr_c_longdouble; |
| 3024 | | #endif |
| 3025 | 3116 | typedef long double zig_f128; |
| 3026 | 3117 | #define zig_make_f128(fp, repr) fp##l |
| 3027 | 3118 | #elif FLT128_MANT_DIG == 113 |
| ... | ... | @@ -3038,50 +3129,49 @@ typedef __float128 zig_f128; |
| 3038 | 3129 | #else |
| 3039 | 3130 | #undef zig_has_f128 |
| 3040 | 3131 | #define zig_has_f128 0 |
| 3041 | | #define zig_bitSizeOf_repr_f128 128 |
| 3042 | | typedef zig_repr_f128 zig_f128; |
| 3043 | | #define zig_make_f128(fp, repr) repr |
| 3044 | 3132 | #undef zig_make_special_f128 |
| 3045 | | #define zig_make_special_f128(sign, name, arg, repr) repr |
| 3046 | 3133 | #undef zig_init_special_f128 |
| 3134 | #if __APPLE__ || defined(__aarch64__) |
| 3135 | typedef __attribute__((__vector_size__(2 * sizeof(uint64_t)))) uint64_t zig_v2u64; |
| 3136 | zig_basic_operator(zig_v2u64, xor_v2u64, ^) |
| 3137 | #define zig_repr_f128 v2u64 |
| 3138 | typedef zig_v2u64 zig_f128; |
| 3139 | #define zig_make_f128_zig_make_u128(hi, lo) (zig_f128){ lo, hi } |
| 3140 | #define zig_make_f128_zig_init_u128 zig_make_f128_zig_make_u128 |
| 3141 | #define zig_make_f128(fp, repr) zig_make_f128_##repr |
| 3142 | #define zig_make_special_f128(sign, name, arg, repr) zig_make_f128_##repr |
| 3143 | #define zig_init_special_f128(sign, name, arg, repr) zig_make_f128_##repr |
| 3144 | #else |
| 3145 | #define zig_repr_f128 u128 |
| 3146 | typedef zig_u128 zig_f128; |
| 3147 | #define zig_make_f128(fp, repr) repr |
| 3148 | #define zig_make_special_f128(sign, name, arg, repr) repr |
| 3047 | 3149 | #define zig_init_special_f128(sign, name, arg, repr) repr |
| 3048 | 3150 | #endif |
| 3151 | #endif |
| 3049 | 3152 | |
| 3050 | | #ifdef zig_bitSizeOf_c_longdouble |
| 3051 | | |
| 3052 | | #define zig_has_c_longdouble 1 |
| 3053 | | #ifdef ZIG_TARGET_ABI_MSVC |
| 3054 | | #undef zig_bitSizeOf_c_longdouble |
| 3055 | | #define zig_bitSizeOf_c_longdouble 64 |
| 3153 | #if !_MSC_VER && defined(ZIG_TARGET_ABI_MSVC) |
| 3154 | /* Emulate msvc abi on a gnu compiler */ |
| 3056 | 3155 | typedef zig_f64 zig_c_longdouble; |
| 3057 | | typedef zig_repr_f64 zig_repr_c_longdouble; |
| 3156 | #elif _MSC_VER && !defined(ZIG_TARGET_ABI_MSVC) |
| 3157 | /* Emulate gnu abi on an msvc compiler */ |
| 3158 | typedef zig_f128 zig_c_longdouble; |
| 3058 | 3159 | #else |
| 3160 | /* Target and compiler abi match */ |
| 3059 | 3161 | typedef long double zig_c_longdouble; |
| 3060 | 3162 | #endif |
| 3061 | 3163 | |
| 3062 | | #else /* zig_bitSizeOf_c_longdouble */ |
| 3063 | | |
| 3064 | | #define zig_has_c_longdouble 0 |
| 3065 | | #define zig_bitSizeOf_repr_c_longdouble 128 |
| 3066 | | typedef zig_f128 zig_c_longdouble; |
| 3067 | | typedef zig_repr_f128 zig_repr_c_longdouble; |
| 3068 | | |
| 3069 | | #endif /* zig_bitSizeOf_c_longdouble */ |
| 3070 | | |
| 3071 | | #if !zig_has_float_builtins |
| 3072 | | #define zig_float_from_repr(Type) \ |
| 3073 | | static inline zig_##Type zig_float_from_repr_##Type(zig_repr_##Type repr) { \ |
| 3164 | #define zig_bitCast_float(Type, ReprType) \ |
| 3165 | static inline zig_##Type zig_bitCast_##Type(ReprType repr) { \ |
| 3074 | 3166 | zig_##Type result; \ |
| 3075 | 3167 | memcpy(&result, &repr, sizeof(result)); \ |
| 3076 | 3168 | return result; \ |
| 3077 | 3169 | } |
| 3078 | | |
| 3079 | | zig_float_from_repr(f16) |
| 3080 | | zig_float_from_repr(f32) |
| 3081 | | zig_float_from_repr(f64) |
| 3082 | | zig_float_from_repr(f80) |
| 3083 | | zig_float_from_repr(f128) |
| 3084 | | #endif |
| 3170 | zig_bitCast_float(f16, uint16_t) |
| 3171 | zig_bitCast_float(f32, uint32_t) |
| 3172 | zig_bitCast_float(f64, uint64_t) |
| 3173 | zig_bitCast_float(f80, zig_u128) |
| 3174 | zig_bitCast_float(f128, zig_u128) |
| 3085 | 3175 | |
| 3086 | 3176 | #define zig_cast_f16 (zig_f16) |
| 3087 | 3177 | #define zig_cast_f32 (zig_f32) |
| ... | ... | @@ -3095,44 +3185,53 @@ zig_float_from_repr(f128) |
| 3095 | 3185 | #define zig_cast_f128 (zig_f128) |
| 3096 | 3186 | #endif |
| 3097 | 3187 | |
| 3098 | | #define zig_convert_builtin(ResType, operation, ArgType, version) \ |
| 3099 | | zig_extern ResType zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \ |
| 3100 | | zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType), version)(ArgType); |
| 3101 | | zig_convert_builtin(zig_compiler_rt_f16, trunc, zig_f32, 2) |
| 3102 | | zig_convert_builtin(zig_compiler_rt_f16, trunc, zig_f64, 2) |
| 3103 | | zig_convert_builtin(zig_f16, trunc, zig_f80, 2) |
| 3104 | | zig_convert_builtin(zig_f16, trunc, zig_f128, 2) |
| 3105 | | zig_convert_builtin(zig_f32, extend, zig_compiler_rt_f16, 2) |
| 3106 | | zig_convert_builtin(zig_f32, trunc, zig_f64, 2) |
| 3107 | | zig_convert_builtin(zig_f32, trunc, zig_f80, 2) |
| 3108 | | zig_convert_builtin(zig_f32, trunc, zig_f128, 2) |
| 3109 | | zig_convert_builtin(zig_f64, extend, zig_compiler_rt_f16, 2) |
| 3110 | | zig_convert_builtin(zig_f64, extend, zig_f32, 2) |
| 3111 | | zig_convert_builtin(zig_f64, trunc, zig_f80, 2) |
| 3112 | | zig_convert_builtin(zig_f64, trunc, zig_f128, 2) |
| 3113 | | zig_convert_builtin(zig_f80, extend, zig_f16, 2) |
| 3114 | | zig_convert_builtin(zig_f80, extend, zig_f32, 2) |
| 3115 | | zig_convert_builtin(zig_f80, extend, zig_f64, 2) |
| 3116 | | zig_convert_builtin(zig_f80, trunc, zig_f128, 2) |
| 3117 | | zig_convert_builtin(zig_f128, extend, zig_f16, 2) |
| 3118 | | zig_convert_builtin(zig_f128, extend, zig_f32, 2) |
| 3119 | | zig_convert_builtin(zig_f128, extend, zig_f64, 2) |
| 3120 | | zig_convert_builtin(zig_f128, extend, zig_f80, 2) |
| 3121 | | |
| 3122 | | #define zig_float_negate_builtin_0(w) \ |
| 3123 | | static inline zig_f##w zig_neg_f##w(zig_f##w arg) { \ |
| 3124 | | return zig_expand_concat(zig_xor_u, zig_bitSizeOf_repr_f##w)( \ |
| 3125 | | arg, \ |
| 3126 | | zig_expand_concat(zig_shl_u, zig_bitSizeOf_repr_f##w)( \ |
| 3127 | | zig_expand_concat(zig_make_small_u, zig_bitSizeOf_repr_f##w)(1), \ |
| 3128 | | UINT8_C(w - 1) \ |
| 3129 | | ) \ |
| 3130 | | ); \ |
| 3131 | | } |
| 3132 | | #define zig_float_negate_builtin_1(w) \ |
| 3188 | #define zig_convert_builtin(ExternResType, ResType, operation, ExternArgType, ArgType, version) \ |
| 3189 | zig_extern ExternResType zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \ |
| 3190 | zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType), version)(ExternArgType); \ |
| 3191 | static inline ResType zig_expand_concat(zig_expand_concat(zig_##operation, \ |
| 3192 | zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType)(ArgType arg) { \ |
| 3193 | ResType res; \ |
| 3194 | ExternResType extern_res; \ |
| 3195 | ExternArgType extern_arg; \ |
| 3196 | memcpy(&extern_arg, &arg, sizeof(extern_arg)); \ |
| 3197 | extern_res = zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \ |
| 3198 | zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType), version)(extern_arg); \ |
| 3199 | memcpy(&res, &extern_res, sizeof(res)); \ |
| 3200 | return extern_res; \ |
| 3201 | } |
| 3202 | zig_convert_builtin(zig_compiler_rt_f16, zig_f16, trunc, zig_f32, zig_f32, 2) |
| 3203 | zig_convert_builtin(zig_compiler_rt_f16, zig_f16, trunc, zig_f64, zig_f64, 2) |
| 3204 | zig_convert_builtin(zig_f16, zig_f16, trunc, zig_f80, zig_f80, 2) |
| 3205 | zig_convert_builtin(zig_f16, zig_f16, trunc, zig_f128, zig_f128, 2) |
| 3206 | zig_convert_builtin(zig_f32, zig_f32, extend, zig_compiler_rt_f16, zig_f16, 2) |
| 3207 | zig_convert_builtin(zig_f32, zig_f32, trunc, zig_f64, zig_f64, 2) |
| 3208 | zig_convert_builtin(zig_f32, zig_f32, trunc, zig_f80, zig_f80, 2) |
| 3209 | zig_convert_builtin(zig_f32, zig_f32, trunc, zig_f128, zig_f128, 2) |
| 3210 | zig_convert_builtin(zig_f64, zig_f64, extend, zig_compiler_rt_f16, zig_f16, 2) |
| 3211 | zig_convert_builtin(zig_f64, zig_f64, extend, zig_f32, zig_f32, 2) |
| 3212 | zig_convert_builtin(zig_f64, zig_f64, trunc, zig_f80, zig_f80, 2) |
| 3213 | zig_convert_builtin(zig_f64, zig_f64, trunc, zig_f128, zig_f128, 2) |
| 3214 | zig_convert_builtin(zig_f80, zig_f80, extend, zig_f16, zig_f16, 2) |
| 3215 | zig_convert_builtin(zig_f80, zig_f80, extend, zig_f32, zig_f32, 2) |
| 3216 | zig_convert_builtin(zig_f80, zig_f80, extend, zig_f64, zig_f64, 2) |
| 3217 | zig_convert_builtin(zig_f80, zig_f80, trunc, zig_f128, zig_f128, 2) |
| 3218 | zig_convert_builtin(zig_f128, zig_f128, extend, zig_f16, zig_f16, 2) |
| 3219 | zig_convert_builtin(zig_f128, zig_f128, extend, zig_f32, zig_f32, 2) |
| 3220 | zig_convert_builtin(zig_f128, zig_f128, extend, zig_f64, zig_f64, 2) |
| 3221 | zig_convert_builtin(zig_f128, zig_f128, extend, zig_f80, zig_f80, 2) |
| 3222 | |
| 3223 | #define zig_float_negate_builtin_0(w, c, sb) \ |
| 3224 | zig_expand_concat(zig_xor_, zig_repr_f##w)(arg, zig_make_f##w(-0x0.0p0, c sb)) |
| 3225 | #define zig_float_negate_builtin_1(w, c, sb) -arg |
| 3226 | #define zig_float_negate_builtin(w, c, sb) \ |
| 3133 | 3227 | static inline zig_f##w zig_neg_f##w(zig_f##w arg) { \ |
| 3134 | | return -arg; \ |
| 3228 | return zig_expand_concat(zig_float_negate_builtin_, zig_has_f##w)(w, c, sb); \ |
| 3135 | 3229 | } |
| 3230 | zig_float_negate_builtin(16, , UINT16_C(1) << 15 ) |
| 3231 | zig_float_negate_builtin(32, , UINT32_C(1) << 31 ) |
| 3232 | zig_float_negate_builtin(64, , UINT64_C(1) << 63 ) |
| 3233 | zig_float_negate_builtin(80, zig_make_u128, (UINT64_C(1) << 15, UINT64_C(0))) |
| 3234 | zig_float_negate_builtin(128, zig_make_u128, (UINT64_C(1) << 63, UINT64_C(0))) |
| 3136 | 3235 | |
| 3137 | 3236 | #define zig_float_less_builtin_0(Type, operation) \ |
| 3138 | 3237 | zig_extern int32_t zig_expand_concat(zig_expand_concat(__##operation, \ |
| ... | ... | @@ -3164,19 +3263,18 @@ zig_convert_builtin(zig_f128, extend, zig_f80, 2) |
| 3164 | 3263 | } |
| 3165 | 3264 | |
| 3166 | 3265 | #define zig_float_builtins(w) \ |
| 3167 | | zig_convert_builtin( int32_t, fix, zig_f##w, ) \ |
| 3168 | | zig_convert_builtin(uint32_t, fixuns, zig_f##w, ) \ |
| 3169 | | zig_convert_builtin( int64_t, fix, zig_f##w, ) \ |
| 3170 | | zig_convert_builtin(uint64_t, fixuns, zig_f##w, ) \ |
| 3171 | | zig_convert_builtin(zig_i128, fix, zig_f##w, ) \ |
| 3172 | | zig_convert_builtin(zig_u128, fixuns, zig_f##w, ) \ |
| 3173 | | zig_convert_builtin(zig_f##w, float, int32_t, ) \ |
| 3174 | | zig_convert_builtin(zig_f##w, floatun, uint32_t, ) \ |
| 3175 | | zig_convert_builtin(zig_f##w, float, int64_t, ) \ |
| 3176 | | zig_convert_builtin(zig_f##w, floatun, uint64_t, ) \ |
| 3177 | | zig_convert_builtin(zig_f##w, float, zig_i128, ) \ |
| 3178 | | zig_convert_builtin(zig_f##w, floatun, zig_u128, ) \ |
| 3179 | | zig_expand_concat(zig_float_negate_builtin_, zig_has_f##w)(w) \ |
| 3266 | zig_convert_builtin( int32_t, int32_t, fix, zig_f##w, zig_f##w, ) \ |
| 3267 | zig_convert_builtin(uint32_t, uint32_t, fixuns, zig_f##w, zig_f##w, ) \ |
| 3268 | zig_convert_builtin( int64_t, int64_t, fix, zig_f##w, zig_f##w, ) \ |
| 3269 | zig_convert_builtin(uint64_t, uint64_t, fixuns, zig_f##w, zig_f##w, ) \ |
| 3270 | zig_convert_builtin(zig_i128, zig_i128, fix, zig_f##w, zig_f##w, ) \ |
| 3271 | zig_convert_builtin(zig_u128, zig_u128, fixuns, zig_f##w, zig_f##w, ) \ |
| 3272 | zig_convert_builtin(zig_f##w, zig_f##w, float, int32_t, int32_t, ) \ |
| 3273 | zig_convert_builtin(zig_f##w, zig_f##w, floatun, uint32_t, uint32_t, ) \ |
| 3274 | zig_convert_builtin(zig_f##w, zig_f##w, float, int64_t, int64_t, ) \ |
| 3275 | zig_convert_builtin(zig_f##w, zig_f##w, floatun, uint64_t, uint64_t, ) \ |
| 3276 | zig_convert_builtin(zig_f##w, zig_f##w, float, zig_i128, zig_i128, ) \ |
| 3277 | zig_convert_builtin(zig_f##w, zig_f##w, floatun, zig_u128, zig_u128, ) \ |
| 3180 | 3278 | zig_expand_concat(zig_float_less_builtin_, zig_has_f##w)(f##w, cmp) \ |
| 3181 | 3279 | zig_expand_concat(zig_float_less_builtin_, zig_has_f##w)(f##w, ne) \ |
| 3182 | 3280 | zig_expand_concat(zig_float_less_builtin_, zig_has_f##w)(f##w, eq) \ |
| ... | ... | @@ -3224,9 +3322,238 @@ zig_float_builtins(64) |
| 3224 | 3322 | zig_float_builtins(80) |
| 3225 | 3323 | zig_float_builtins(128) |
| 3226 | 3324 | |
| 3325 | /* ============================ Atomics Support ============================= */ |
| 3326 | |
| 3327 | /* Note that atomics should be implemented as macros because most |
| 3328 | compilers silently discard runtime atomic order information. */ |
| 3329 | |
| 3330 | /* Define fallback implementations first that can later be undef'd on compilers with builtin support. */ |
| 3331 | /* Note that zig_atomicrmw_expected is needed to handle aliasing between res and arg. */ |
| 3332 | #define zig_atomicrmw_xchg_float(res, obj, arg, order, Type, ReprType) do { \ |
| 3333 | zig_##Type zig_atomicrmw_expected; \ |
| 3334 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ |
| 3335 | while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, arg, order, memory_order_relaxed, Type, ReprType)); \ |
| 3336 | res = zig_atomicrmw_expected; \ |
| 3337 | } while (0) |
| 3338 | #define zig_atomicrmw_add_float(res, obj, arg, order, Type, ReprType) do { \ |
| 3339 | zig_##Type zig_atomicrmw_expected; \ |
| 3340 | zig_##Type zig_atomicrmw_desired; \ |
| 3341 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ |
| 3342 | do { \ |
| 3343 | zig_atomicrmw_desired = zig_add_##Type(zig_atomicrmw_expected, arg); \ |
| 3344 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ |
| 3345 | res = zig_atomicrmw_expected; \ |
| 3346 | } while (0) |
| 3347 | #define zig_atomicrmw_sub_float(res, obj, arg, order, Type, ReprType) do { \ |
| 3348 | zig_##Type zig_atomicrmw_expected; \ |
| 3349 | zig_##Type zig_atomicrmw_desired; \ |
| 3350 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ |
| 3351 | do { \ |
| 3352 | zig_atomicrmw_desired = zig_sub_##Type(zig_atomicrmw_expected, arg); \ |
| 3353 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ |
| 3354 | res = zig_atomicrmw_expected; \ |
| 3355 | } while (0) |
| 3356 | #define zig_atomicrmw_min_float(res, obj, arg, order, Type, ReprType) do { \ |
| 3357 | zig_##Type zig_atomicrmw_expected; \ |
| 3358 | zig_##Type zig_atomicrmw_desired; \ |
| 3359 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ |
| 3360 | do { \ |
| 3361 | zig_atomicrmw_desired = zig_libc_name_##Type(fmin)(zig_atomicrmw_expected, arg); \ |
| 3362 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ |
| 3363 | res = zig_atomicrmw_expected; \ |
| 3364 | } while (0) |
| 3365 | #define zig_atomicrmw_max_float(res, obj, arg, order, Type, ReprType) do { \ |
| 3366 | zig_##Type zig_atomicrmw_expected; \ |
| 3367 | zig_##Type zig_atomicrmw_desired; \ |
| 3368 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ |
| 3369 | do { \ |
| 3370 | zig_atomicrmw_desired = zig_libc_name_##Type(fmax)(zig_atomicrmw_expected, arg); \ |
| 3371 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ |
| 3372 | res = zig_atomicrmw_expected; \ |
| 3373 | } while (0) |
| 3374 | |
| 3375 | #define zig_atomicrmw_xchg_int128(res, obj, arg, order, Type, ReprType) do { \ |
| 3376 | zig_##Type zig_atomicrmw_expected; \ |
| 3377 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ |
| 3378 | while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, arg, order, memory_order_relaxed, Type, ReprType)); \ |
| 3379 | res = zig_atomicrmw_expected; \ |
| 3380 | } while (0) |
| 3381 | #define zig_atomicrmw_add_int128(res, obj, arg, order, Type, ReprType) do { \ |
| 3382 | zig_##Type zig_atomicrmw_expected; \ |
| 3383 | zig_##Type zig_atomicrmw_desired; \ |
| 3384 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ |
| 3385 | do { \ |
| 3386 | zig_atomicrmw_desired = zig_add_##Type(zig_atomicrmw_expected, arg); \ |
| 3387 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ |
| 3388 | res = zig_atomicrmw_expected; \ |
| 3389 | } while (0) |
| 3390 | #define zig_atomicrmw_sub_int128(res, obj, arg, order, Type, ReprType) do { \ |
| 3391 | zig_##Type zig_atomicrmw_expected; \ |
| 3392 | zig_##Type zig_atomicrmw_desired; \ |
| 3393 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ |
| 3394 | do { \ |
| 3395 | zig_atomicrmw_desired = zig_sub_##Type(zig_atomicrmw_expected, arg); \ |
| 3396 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ |
| 3397 | res = zig_atomicrmw_expected; \ |
| 3398 | } while (0) |
| 3399 | #define zig_atomicrmw_and_int128(res, obj, arg, order, Type, ReprType) do { \ |
| 3400 | zig_##Type zig_atomicrmw_expected; \ |
| 3401 | zig_##Type zig_atomicrmw_desired; \ |
| 3402 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ |
| 3403 | do { \ |
| 3404 | zig_atomicrmw_desired = zig_and_##Type(zig_atomicrmw_expected, arg); \ |
| 3405 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ |
| 3406 | res = zig_atomicrmw_expected; \ |
| 3407 | } while (0) |
| 3408 | #define zig_atomicrmw_nand_int128(res, obj, arg, order, Type, ReprType) do { \ |
| 3409 | zig_##Type zig_atomicrmw_expected; \ |
| 3410 | zig_##Type zig_atomicrmw_desired; \ |
| 3411 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ |
| 3412 | do { \ |
| 3413 | zig_atomicrmw_desired = zig_not_##Type(zig_and_##Type(zig_atomicrmw_expected, arg), 128); \ |
| 3414 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ |
| 3415 | res = zig_atomicrmw_expected; \ |
| 3416 | } while (0) |
| 3417 | #define zig_atomicrmw_or_int128(res, obj, arg, order, Type, ReprType) do { \ |
| 3418 | zig_##Type zig_atomicrmw_expected; \ |
| 3419 | zig_##Type zig_atomicrmw_desired; \ |
| 3420 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ |
| 3421 | do { \ |
| 3422 | zig_atomicrmw_desired = zig_or_##Type(zig_atomicrmw_expected, arg); \ |
| 3423 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ |
| 3424 | res = zig_atomicrmw_expected; \ |
| 3425 | } while (0) |
| 3426 | #define zig_atomicrmw_xor_int128(res, obj, arg, order, Type, ReprType) do { \ |
| 3427 | zig_##Type zig_atomicrmw_expected; \ |
| 3428 | zig_##Type zig_atomicrmw_desired; \ |
| 3429 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ |
| 3430 | do { \ |
| 3431 | zig_atomicrmw_desired = zig_xor_##Type(zig_atomicrmw_expected, arg); \ |
| 3432 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ |
| 3433 | res = zig_atomicrmw_expected; \ |
| 3434 | } while (0) |
| 3435 | #define zig_atomicrmw_min_int128(res, obj, arg, order, Type, ReprType) do { \ |
| 3436 | zig_##Type zig_atomicrmw_expected; \ |
| 3437 | zig_##Type zig_atomicrmw_desired; \ |
| 3438 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ |
| 3439 | do { \ |
| 3440 | zig_atomicrmw_desired = zig_min_##Type(zig_atomicrmw_expected, arg); \ |
| 3441 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ |
| 3442 | res = zig_atomicrmw_expected; \ |
| 3443 | } while (0) |
| 3444 | #define zig_atomicrmw_max_int128(res, obj, arg, order, Type, ReprType) do { \ |
| 3445 | zig_##Type zig_atomicrmw_expected; \ |
| 3446 | zig_##Type zig_atomicrmw_desired; \ |
| 3447 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ |
| 3448 | do { \ |
| 3449 | zig_atomicrmw_desired = zig_max_##Type(zig_atomicrmw_expected, arg); \ |
| 3450 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ |
| 3451 | res = zig_atomicrmw_expected; \ |
| 3452 | } while (0) |
| 3453 | |
| 3454 | #if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__) |
| 3455 | #include <stdatomic.h> |
| 3456 | typedef enum memory_order zig_memory_order; |
| 3457 | #define zig_atomic(Type) _Atomic(Type) |
| 3458 | #define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) atomic_compare_exchange_strong_explicit(obj, &(expected), desired, succ, fail) |
| 3459 | #define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) atomic_compare_exchange_weak_explicit (obj, &(expected), desired, succ, fail) |
| 3460 | #define zig_atomicrmw_xchg(res, obj, arg, order, Type, ReprType) res = atomic_exchange_explicit (obj, arg, order) |
| 3461 | #define zig_atomicrmw_add(res, obj, arg, order, Type, ReprType) res = atomic_fetch_add_explicit (obj, arg, order) |
| 3462 | #define zig_atomicrmw_sub(res, obj, arg, order, Type, ReprType) res = atomic_fetch_sub_explicit (obj, arg, order) |
| 3463 | #define zig_atomicrmw_or(res, obj, arg, order, Type, ReprType) res = atomic_fetch_or_explicit (obj, arg, order) |
| 3464 | #define zig_atomicrmw_xor(res, obj, arg, order, Type, ReprType) res = atomic_fetch_xor_explicit (obj, arg, order) |
| 3465 | #define zig_atomicrmw_and(res, obj, arg, order, Type, ReprType) res = atomic_fetch_and_explicit (obj, arg, order) |
| 3466 | #define zig_atomicrmw_nand(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_nand(obj, arg, order) |
| 3467 | #define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_min (obj, arg, order) |
| 3468 | #define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_max (obj, arg, order) |
| 3469 | #define zig_atomic_store( obj, arg, order, Type, ReprType) atomic_store_explicit (obj, arg, order) |
| 3470 | #define zig_atomic_load(res, obj, order, Type, ReprType) res = atomic_load_explicit (obj, order) |
| 3471 | #undef zig_atomicrmw_xchg_float |
| 3472 | #define zig_atomicrmw_xchg_float zig_atomicrmw_xchg |
| 3473 | #undef zig_atomicrmw_add_float |
| 3474 | #define zig_atomicrmw_add_float zig_atomicrmw_add |
| 3475 | #undef zig_atomicrmw_sub_float |
| 3476 | #define zig_atomicrmw_sub_float zig_atomicrmw_sub |
| 3477 | #define zig_fence(order) atomic_thread_fence(order) |
| 3478 | #elif defined(__GNUC__) |
| 3479 | typedef int zig_memory_order; |
| 3480 | #define memory_order_relaxed __ATOMIC_RELAXED |
| 3481 | #define memory_order_consume __ATOMIC_CONSUME |
| 3482 | #define memory_order_acquire __ATOMIC_ACQUIRE |
| 3483 | #define memory_order_release __ATOMIC_RELEASE |
| 3484 | #define memory_order_acq_rel __ATOMIC_ACQ_REL |
| 3485 | #define memory_order_seq_cst __ATOMIC_SEQ_CST |
| 3486 | #define zig_atomic(Type) Type |
| 3487 | #define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, &(expected), &(desired), false, succ, fail) |
| 3488 | #define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, &(expected), &(desired), true, succ, fail) |
| 3489 | #define zig_atomicrmw_xchg(res, obj, arg, order, Type, ReprType) __atomic_exchange(obj, &(arg), &(res), order) |
| 3490 | #define zig_atomicrmw_add(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_add (obj, arg, order) |
| 3491 | #define zig_atomicrmw_sub(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_sub (obj, arg, order) |
| 3492 | #define zig_atomicrmw_or(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_or (obj, arg, order) |
| 3493 | #define zig_atomicrmw_xor(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_xor (obj, arg, order) |
| 3494 | #define zig_atomicrmw_and(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_and (obj, arg, order) |
| 3495 | #define zig_atomicrmw_nand(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_nand(obj, arg, order) |
| 3496 | #define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_min (obj, arg, order) |
| 3497 | #define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_max (obj, arg, order) |
| 3498 | #define zig_atomic_store( obj, arg, order, Type, ReprType) __atomic_store (obj, &(arg), order) |
| 3499 | #define zig_atomic_load(res, obj, order, Type, ReprType) __atomic_load (obj, &(res), order) |
| 3500 | #undef zig_atomicrmw_xchg_float |
| 3501 | #define zig_atomicrmw_xchg_float zig_atomicrmw_xchg |
| 3502 | #define zig_fence(order) __atomic_thread_fence(order) |
| 3503 | #elif _MSC_VER && (_M_IX86 || _M_X64) |
| 3504 | #define memory_order_relaxed 0 |
| 3505 | #define memory_order_consume 1 |
| 3506 | #define memory_order_acquire 2 |
| 3507 | #define memory_order_release 3 |
| 3508 | #define memory_order_acq_rel 4 |
| 3509 | #define memory_order_seq_cst 5 |
| 3510 | #define zig_atomic(Type) Type |
| 3511 | #define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) zig_msvc_cmpxchg_##Type(obj, &(expected), desired) |
| 3512 | #define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) zig_cmpxchg_strong(obj, expected, desired, succ, fail, Type, ReprType) |
| 3513 | #define zig_atomicrmw_xchg(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_xchg_##Type(obj, arg) |
| 3514 | #define zig_atomicrmw_add(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_add_ ##Type(obj, arg) |
| 3515 | #define zig_atomicrmw_sub(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_sub_ ##Type(obj, arg) |
| 3516 | #define zig_atomicrmw_or(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_or_ ##Type(obj, arg) |
| 3517 | #define zig_atomicrmw_xor(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_xor_ ##Type(obj, arg) |
| 3518 | #define zig_atomicrmw_and(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_and_ ##Type(obj, arg) |
| 3519 | #define zig_atomicrmw_nand(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_nand_##Type(obj, arg) |
| 3520 | #define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_min_ ##Type(obj, arg) |
| 3521 | #define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_max_ ##Type(obj, arg) |
| 3522 | #define zig_atomic_store( obj, arg, order, Type, ReprType) zig_msvc_atomic_store_ ##Type(obj, arg) |
| 3523 | #define zig_atomic_load(res, obj, order, Type, ReprType) res = zig_msvc_atomic_load_ ##Type(obj) |
| 3524 | #if _M_X64 |
| 3525 | #define zig_fence(order) __faststorefence() |
| 3526 | #else |
| 3527 | #define zig_fence(order) zig_msvc_atomic_barrier() |
| 3528 | #endif |
| 3529 | /* TODO: _MSC_VER && (_M_ARM || _M_ARM64) */ |
| 3530 | #else |
| 3531 | #define memory_order_relaxed 0 |
| 3532 | #define memory_order_consume 1 |
| 3533 | #define memory_order_acquire 2 |
| 3534 | #define memory_order_release 3 |
| 3535 | #define memory_order_acq_rel 4 |
| 3536 | #define memory_order_seq_cst 5 |
| 3537 | #define zig_atomic(Type) Type |
| 3538 | #define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) zig_atomics_unavailable |
| 3539 | #define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) zig_atomics_unavailable |
| 3540 | #define zig_atomicrmw_xchg(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable |
| 3541 | #define zig_atomicrmw_add(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable |
| 3542 | #define zig_atomicrmw_sub(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable |
| 3543 | #define zig_atomicrmw_or(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable |
| 3544 | #define zig_atomicrmw_xor(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable |
| 3545 | #define zig_atomicrmw_and(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable |
| 3546 | #define zig_atomicrmw_nand(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable |
| 3547 | #define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable |
| 3548 | #define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable |
| 3549 | #define zig_atomic_store( obj, arg, order, Type, ReprType) zig_atomics_unavailable |
| 3550 | #define zig_atomic_load(res, obj, order, Type, ReprType) zig_atomics_unavailable |
| 3551 | #define zig_fence(order) zig_fence_unavailable |
| 3552 | #endif |
| 3553 | |
| 3227 | 3554 | #if _MSC_VER && (_M_IX86 || _M_X64) |
| 3228 | 3555 | |
| 3229 | | // TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 |
| 3556 | /* TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 */ |
| 3230 | 3557 | |
| 3231 | 3558 | #define zig_msvc_atomics(ZigType, Type, SigType, suffix) \ |
| 3232 | 3559 | static inline bool zig_msvc_cmpxchg_##ZigType(Type volatile* obj, Type* expected, Type desired) { \ |
| ... | ... | @@ -3316,51 +3643,30 @@ zig_msvc_atomics(u64, uint64_t, __int64, 64) |
| 3316 | 3643 | zig_msvc_atomics(i64, int64_t, __int64, 64) |
| 3317 | 3644 | #endif |
| 3318 | 3645 | |
| 3319 | | #define zig_msvc_flt_atomics(Type, ReprType, suffix) \ |
| 3646 | #define zig_msvc_flt_atomics(Type, SigType, suffix) \ |
| 3320 | 3647 | static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \ |
| 3321 | | ReprType exchange; \ |
| 3322 | | ReprType comparand; \ |
| 3323 | | ReprType initial; \ |
| 3648 | SigType exchange; \ |
| 3649 | SigType comparand; \ |
| 3650 | SigType initial; \ |
| 3324 | 3651 | bool success; \ |
| 3325 | 3652 | memcpy(&comparand, expected, sizeof(comparand)); \ |
| 3326 | 3653 | memcpy(&exchange, &desired, sizeof(exchange)); \ |
| 3327 | | initial = _InterlockedCompareExchange##suffix((ReprType volatile*)obj, exchange, comparand); \ |
| 3654 | initial = _InterlockedCompareExchange##suffix((SigType volatile*)obj, exchange, comparand); \ |
| 3328 | 3655 | success = initial == comparand; \ |
| 3329 | 3656 | if (!success) memcpy(expected, &initial, sizeof(*expected)); \ |
| 3330 | 3657 | return success; \ |
| 3331 | 3658 | } \ |
| 3332 | | static inline zig_##Type zig_msvc_atomicrmw_xchg_##Type(zig_##Type volatile* obj, zig_##Type value) { \ |
| 3333 | | ReprType repr; \ |
| 3334 | | ReprType initial; \ |
| 3659 | static inline void zig_msvc_atomic_store_##Type(zig_##Type volatile* obj, zig_##Type arg) { \ |
| 3660 | SigType value; \ |
| 3661 | memcpy(&value, &arg, sizeof(value)); \ |
| 3662 | (void)_InterlockedExchange##suffix((SigType volatile*)obj, value); \ |
| 3663 | } \ |
| 3664 | static inline zig_##Type zig_msvc_atomic_load_##Type(zig_##Type volatile* obj) { \ |
| 3335 | 3665 | zig_##Type result; \ |
| 3336 | | memcpy(&repr, &value, sizeof(repr)); \ |
| 3337 | | initial = _InterlockedExchange##suffix((ReprType volatile*)obj, repr); \ |
| 3666 | SigType initial = _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)0); \ |
| 3338 | 3667 | memcpy(&result, &initial, sizeof(result)); \ |
| 3339 | 3668 | return result; \ |
| 3340 | | } \ |
| 3341 | | static inline zig_##Type zig_msvc_atomicrmw_add_##Type(zig_##Type volatile* obj, zig_##Type value) { \ |
| 3342 | | ReprType repr; \ |
| 3343 | | zig_##Type expected; \ |
| 3344 | | zig_##Type desired; \ |
| 3345 | | repr = *(ReprType volatile*)obj; \ |
| 3346 | | memcpy(&expected, &repr, sizeof(expected)); \ |
| 3347 | | do { \ |
| 3348 | | desired = expected + value; \ |
| 3349 | | } while (!zig_msvc_cmpxchg_##Type(obj, &expected, desired)); \ |
| 3350 | | return expected; \ |
| 3351 | | } \ |
| 3352 | | static inline zig_##Type zig_msvc_atomicrmw_sub_##Type(zig_##Type volatile* obj, zig_##Type value) { \ |
| 3353 | | ReprType repr; \ |
| 3354 | | zig_##Type expected; \ |
| 3355 | | zig_##Type desired; \ |
| 3356 | | repr = *(ReprType volatile*)obj; \ |
| 3357 | | memcpy(&expected, &repr, sizeof(expected)); \ |
| 3358 | | do { \ |
| 3359 | | desired = expected - value; \ |
| 3360 | | } while (!zig_msvc_cmpxchg_##Type(obj, &expected, desired)); \ |
| 3361 | | return expected; \ |
| 3362 | 3669 | } |
| 3363 | | |
| 3364 | 3670 | zig_msvc_flt_atomics(f32, long, ) |
| 3365 | 3671 | #if _M_X64 |
| 3366 | 3672 | zig_msvc_flt_atomics(f64, int64_t, 64) |
| ... | ... | @@ -3421,42 +3727,6 @@ static inline bool zig_msvc_cmpxchg_u128(zig_u128 volatile* obj, zig_u128* expec |
| 3421 | 3727 | static inline bool zig_msvc_cmpxchg_i128(zig_i128 volatile* obj, zig_i128* expected, zig_i128 desired) { |
| 3422 | 3728 | return _InterlockedCompareExchange128((__int64 volatile*)obj, (__int64)zig_hi_i128(desired), (__int64)zig_lo_i128(desired), (__int64*)expected); |
| 3423 | 3729 | } |
| 3424 | | |
| 3425 | | #define zig_msvc_atomics_128xchg(Type) \ |
| 3426 | | static inline zig_##Type zig_msvc_atomicrmw_xchg_##Type(zig_##Type volatile* obj, zig_##Type value) { \ |
| 3427 | | bool success = false; \ |
| 3428 | | zig_##Type prev; \ |
| 3429 | | while (!success) { \ |
| 3430 | | prev = *obj; \ |
| 3431 | | success = zig_msvc_cmpxchg_##Type(obj, &prev, value); \ |
| 3432 | | } \ |
| 3433 | | return prev; \ |
| 3434 | | } |
| 3435 | | |
| 3436 | | zig_msvc_atomics_128xchg(u128) |
| 3437 | | zig_msvc_atomics_128xchg(i128) |
| 3438 | | |
| 3439 | | #define zig_msvc_atomics_128op(Type, operation) \ |
| 3440 | | static inline zig_##Type zig_msvc_atomicrmw_##operation##_##Type(zig_##Type volatile* obj, zig_##Type value) { \ |
| 3441 | | bool success = false; \ |
| 3442 | | zig_##Type new; \ |
| 3443 | | zig_##Type prev; \ |
| 3444 | | while (!success) { \ |
| 3445 | | prev = *obj; \ |
| 3446 | | new = zig_##operation##_##Type(prev, value); \ |
| 3447 | | success = zig_msvc_cmpxchg_##Type(obj, &prev, new); \ |
| 3448 | | } \ |
| 3449 | | return prev; \ |
| 3450 | | } |
| 3451 | | |
| 3452 | | zig_msvc_atomics_128op(u128, add) |
| 3453 | | zig_msvc_atomics_128op(u128, sub) |
| 3454 | | zig_msvc_atomics_128op(u128, or) |
| 3455 | | zig_msvc_atomics_128op(u128, xor) |
| 3456 | | zig_msvc_atomics_128op(u128, and) |
| 3457 | | zig_msvc_atomics_128op(u128, nand) |
| 3458 | | zig_msvc_atomics_128op(u128, min) |
| 3459 | | zig_msvc_atomics_128op(u128, max) |
| 3460 | 3730 | #endif /* _M_IX86 */ |
| 3461 | 3731 | |
| 3462 | 3732 | #endif /* _MSC_VER && (_M_IX86 || _M_X64) */ |