| ... | @@ -9,6 +9,7 @@ | ... | @@ -9,6 +9,7 @@ |
| 9 | #define zig_clang | 9 | #define zig_clang |
| 10 | #define zig_gnuc | 10 | #define zig_gnuc |
| 11 | #elif defined(__GNUC__) | 11 | #elif defined(__GNUC__) |
| | 12 | #define zig_gcc |
| 12 | #define zig_gnuc | 13 | #define zig_gnuc |
| 13 | #elif defined(__IBMC__) | 14 | #elif defined(__IBMC__) |
| 14 | #define zig_xlc | 15 | #define zig_xlc |
| ... | @@ -171,7 +172,7 @@ | ... | @@ -171,7 +172,7 @@ |
| 171 | #define zig_callconv(c) __attribute__((c)) | 172 | #define zig_callconv(c) __attribute__((c)) |
| 172 | #endif | 173 | #endif |
| 173 | | 174 | |
| 174 | #if zig_has_attribute(naked) || defined(zig_gnuc) | 175 | #if zig_has_attribute(naked) || defined(zig_gcc) |
| 175 | #define zig_naked_decl __attribute__((naked)) | 176 | #define zig_naked_decl __attribute__((naked)) |
| 176 | #define zig_naked __attribute__((naked)) | 177 | #define zig_naked __attribute__((naked)) |
| 177 | #elif defined(zig_msvc) | 178 | #elif defined(zig_msvc) |
| ... | @@ -265,7 +266,7 @@ | ... | @@ -265,7 +266,7 @@ |
| 265 | #define zig_linksection_fn zig_linksection | 266 | #define zig_linksection_fn zig_linksection |
| 266 | #endif | 267 | #endif |
| 267 | | 268 | |
| 268 | #if zig_has_builtin(unreachable) || defined(zig_gnuc) || defined(zig_tinyc) | 269 | #if zig_has_builtin(unreachable) || defined(zig_gcc) || defined(zig_tinyc) |
| 269 | #define zig_unreachable() __builtin_unreachable() | 270 | #define zig_unreachable() __builtin_unreachable() |
| 270 | #elif defined(zig_msvc) | 271 | #elif defined(zig_msvc) |
| 271 | #define zig_unreachable() __assume(0) | 272 | #define zig_unreachable() __assume(0) |
| ... | @@ -293,11 +294,11 @@ | ... | @@ -293,11 +294,11 @@ |
| 293 | #endif /* zig_macho */ | 294 | #endif /* zig_macho */ |
| 294 | #endif /* zig_msvc */ | 295 | #endif /* zig_msvc */ |
| 295 | | 296 | |
| 296 | #if (zig_has_attribute(alias) || defined(zig_tinyc)) && !defined(zig_macho) | 297 | #if defined(zig_msvc) |
| 297 | #define zig_export(symbol, name) __attribute__((alias(symbol))) | | |
| 298 | #elif defined(zig_msvc) | | |
| 299 | #define zig_export(symbol, name) ; \ | 298 | #define zig_export(symbol, name) ; \ |
| 300 | __pragma(comment(linker, "/alternatename:" zig_mangle_c(name) "=" zig_mangle_c(symbol))) | 299 | __pragma(comment(linker, "/alternatename:" zig_mangle_c(name) "=" zig_mangle_c(symbol))) |
| | 300 | #elif (zig_has_attribute(alias) || defined(zig_tinyc)) && !defined(zig_macho) |
| | 301 | #define zig_export(symbol, name) __attribute__((alias(symbol))) |
| 301 | #else | 302 | #else |
| 302 | #define zig_export(symbol, name) ; \ | 303 | #define zig_export(symbol, name) ; \ |
| 303 | __asm(zig_mangle_c(name) " = " zig_mangle_c(symbol)) | 304 | __asm(zig_mangle_c(name) " = " zig_mangle_c(symbol)) |
| ... | @@ -321,7 +322,7 @@ | ... | @@ -321,7 +322,7 @@ |
| 321 | #if defined(zig_msvc) | 322 | #if defined(zig_msvc) |
| 322 | #define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args;\ | 323 | #define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args;\ |
| 323 | __pragma(comment(linker, "/alternatename:" zig_mangle_c(#fn_name) "=" zig_mangle_c(#libc_name))); | 324 | __pragma(comment(linker, "/alternatename:" zig_mangle_c(#fn_name) "=" zig_mangle_c(#libc_name))); |
| 324 | #define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_import(Type, fn_name, sig_args, call_args) | 325 | #define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_import(Type, fn_name, libc_name, sig_args, call_args) |
| 325 | #else /* zig_msvc */ | 326 | #else /* zig_msvc */ |
| 326 | #define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args __asm(zig_mangle_c(#libc_name)); | 327 | #define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args __asm(zig_mangle_c(#libc_name)); |
| 327 | #define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type libc_name sig_args; \ | 328 | #define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type libc_name sig_args; \ |
| ... | @@ -331,7 +332,7 @@ | ... | @@ -331,7 +332,7 @@ |
| 331 | #define zig_expand_import_0(Type, fn_name, libc_name, sig_args, call_args) zig_import(Type, fn_name, libc_name, sig_args, call_args) | 332 | #define zig_expand_import_0(Type, fn_name, libc_name, sig_args, call_args) zig_import(Type, fn_name, libc_name, sig_args, call_args) |
| 332 | #define zig_expand_import_1(Type, fn_name, libc_name, sig_args, call_args) zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) | 333 | #define zig_expand_import_1(Type, fn_name, libc_name, sig_args, call_args) zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) |
| 333 | | 334 | |
| 334 | #if zig_has_attribute(weak) || defined(zig_gnuc) || defined(zig_tinyc) | 335 | #if zig_has_attribute(weak) || defined(zig_gcc) || defined(zig_tinyc) |
| 335 | #define zig_weak_linkage __attribute__((weak)) | 336 | #define zig_weak_linkage __attribute__((weak)) |
| 336 | #define zig_weak_linkage_fn __attribute__((weak)) | 337 | #define zig_weak_linkage_fn __attribute__((weak)) |
| 337 | #elif defined(zig_msvc) | 338 | #elif defined(zig_msvc) |
| ... | @@ -418,7 +419,7 @@ | ... | @@ -418,7 +419,7 @@ |
| 418 | #define zig_breakpoint() zig_breakpoint_unavailable | 419 | #define zig_breakpoint() zig_breakpoint_unavailable |
| 419 | #endif | 420 | #endif |
| 420 | | 421 | |
| 421 | #if zig_has_builtin(return_address) || defined(zig_gnuc) || defined(zig_tinyc) | 422 | #if zig_has_builtin(return_address) || defined(zig_gcc) || defined(zig_tinyc) |
| 422 | #define zig_return_address() __builtin_extract_return_addr(__builtin_return_address(0)) | 423 | #define zig_return_address() __builtin_extract_return_addr(__builtin_return_address(0)) |
| 423 | #elif defined(zig_msvc) | 424 | #elif defined(zig_msvc) |
| 424 | #define zig_return_address() _ReturnAddress() | 425 | #define zig_return_address() _ReturnAddress() |
| ... | @@ -426,7 +427,7 @@ | ... | @@ -426,7 +427,7 @@ |
| 426 | #define zig_return_address() 0 | 427 | #define zig_return_address() 0 |
| 427 | #endif | 428 | #endif |
| 428 | | 429 | |
| 429 | #if zig_has_builtin(frame_address) || defined(zig_gnuc) || defined(zig_tinyc) | 430 | #if zig_has_builtin(frame_address) || defined(zig_gcc) || defined(zig_tinyc) |
| 430 | #define zig_frame_address() __builtin_frame_address(0) | 431 | #define zig_frame_address() __builtin_frame_address(0) |
| 431 | #elif defined(zig_msvc) | 432 | #elif defined(zig_msvc) |
| 432 | #define zig_frame_address() _AddressOfReturnAddress() | 433 | #define zig_frame_address() _AddressOfReturnAddress() |
| ... | @@ -434,7 +435,7 @@ | ... | @@ -434,7 +435,7 @@ |
| 434 | #define zig_frame_address() 0 | 435 | #define zig_frame_address() 0 |
| 435 | #endif | 436 | #endif |
| 436 | | 437 | |
| 437 | #if zig_has_builtin(prefetch) || defined(zig_gnuc) | 438 | #if zig_has_builtin(prefetch) || defined(zig_gcc) |
| 438 | #define zig_prefetch(addr, rw, locality) __builtin_prefetch(addr, rw, locality) | 439 | #define zig_prefetch(addr, rw, locality) __builtin_prefetch(addr, rw, locality) |
| 439 | #else | 440 | #else |
| 440 | #define zig_prefetch(addr, rw, locality) | 441 | #define zig_prefetch(addr, rw, locality) |
| ... | @@ -452,7 +453,7 @@ | ... | @@ -452,7 +453,7 @@ |
| 452 | #define zig_noreturn [[noreturn]] | 453 | #define zig_noreturn [[noreturn]] |
| 453 | #elif __STDC_VERSION__ >= 201112L | 454 | #elif __STDC_VERSION__ >= 201112L |
| 454 | #define zig_noreturn _Noreturn | 455 | #define zig_noreturn _Noreturn |
| 455 | #elif zig_has_attribute(noreturn) || defined(zig_gnuc) || defined(zig_tinyc) | 456 | #elif zig_has_attribute(noreturn) || defined(zig_gcc) || defined(zig_tinyc) |
| 456 | #define zig_noreturn __attribute__((noreturn)) | 457 | #define zig_noreturn __attribute__((noreturn)) |
| 457 | #elif defined(zig_msvc) | 458 | #elif defined(zig_msvc) |
| 458 | #define zig_noreturn __declspec(noreturn) | 459 | #define zig_noreturn __declspec(noreturn) |
| ... | @@ -650,7 +651,7 @@ typedef ptrdiff_t intptr_t; | ... | @@ -650,7 +651,7 @@ typedef ptrdiff_t intptr_t; |
| 650 | zig_operator(Type, Type, operation, operator) | 651 | zig_operator(Type, Type, operation, operator) |
| 651 | #define zig_shift_operator(Type, operation, operator) \ | 652 | #define zig_shift_operator(Type, operation, operator) \ |
| 652 | zig_operator(Type, uint8_t, operation, operator) | 653 | zig_operator(Type, uint8_t, operation, operator) |
| 653 | #define zig_int_helpers(w) \ | 654 | #define zig_int_helpers(w, PromotedUnsigned) \ |
| 654 | zig_basic_operator(uint##w##_t, and_u##w, &) \ | 655 | zig_basic_operator(uint##w##_t, and_u##w, &) \ |
| 655 | zig_basic_operator( int##w##_t, and_i##w, &) \ | 656 | zig_basic_operator( int##w##_t, and_i##w, &) \ |
| 656 | zig_basic_operator(uint##w##_t, or_u##w, |) \ | 657 | zig_basic_operator(uint##w##_t, or_u##w, |) \ |
| ... | @@ -726,19 +727,51 @@ typedef ptrdiff_t intptr_t; | ... | @@ -726,19 +727,51 @@ typedef ptrdiff_t intptr_t; |
| 726 | } \ | 727 | } \ |
| 727 | \ | 728 | \ |
| 728 | static inline uint##w##_t zig_mulw_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ | 729 | static inline uint##w##_t zig_mulw_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ |
| 729 | return zig_wrap_u##w(lhs * rhs, bits); \ | 730 | return zig_wrap_u##w((PromotedUnsigned)lhs * rhs, bits); \ |
| 730 | } \ | 731 | } \ |
| 731 | \ | 732 | \ |
| 732 | static inline int##w##_t zig_mulw_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ | 733 | static inline int##w##_t zig_mulw_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ |
| 733 | return zig_wrap_i##w((int##w##_t)((uint##w##_t)lhs * (uint##w##_t)rhs), bits); \ | 734 | return zig_wrap_i##w((int##w##_t)((uint##w##_t)lhs * (uint##w##_t)rhs), bits); \ |
| 734 | } | 735 | } |
| 735 | zig_int_helpers(8) | 736 | #if UINT8_MAX <= UINT_MAX |
| 736 | zig_int_helpers(16) | 737 | zig_int_helpers(8, unsigned int) |
| 737 | zig_int_helpers(32) | 738 | #elif UINT8_MAX <= ULONG_MAX |
| 738 | zig_int_helpers(64) | 739 | zig_int_helpers(8, unsigned long) |
| | 740 | #elif UINT8_MAX <= ULLONG_MAX |
| | 741 | zig_int_helpers(8, unsigned long long) |
| | 742 | #else |
| | 743 | zig_int_helpers(8, uint8_t) |
| | 744 | #endif |
| | 745 | #if UINT16_MAX <= UINT_MAX |
| | 746 | zig_int_helpers(16, unsigned int) |
| | 747 | #elif UINT16_MAX <= ULONG_MAX |
| | 748 | zig_int_helpers(16, unsigned long) |
| | 749 | #elif UINT16_MAX <= ULLONG_MAX |
| | 750 | zig_int_helpers(16, unsigned long long) |
| | 751 | #else |
| | 752 | zig_int_helpers(16, uint16_t) |
| | 753 | #endif |
| | 754 | #if UINT32_MAX <= UINT_MAX |
| | 755 | zig_int_helpers(32, unsigned int) |
| | 756 | #elif UINT32_MAX <= ULONG_MAX |
| | 757 | zig_int_helpers(32, unsigned long) |
| | 758 | #elif UINT32_MAX <= ULLONG_MAX |
| | 759 | zig_int_helpers(32, unsigned long long) |
| | 760 | #else |
| | 761 | zig_int_helpers(32, uint32_t) |
| | 762 | #endif |
| | 763 | #if UINT64_MAX <= UINT_MAX |
| | 764 | zig_int_helpers(64, unsigned int) |
| | 765 | #elif UINT64_MAX <= ULONG_MAX |
| | 766 | zig_int_helpers(64, unsigned long) |
| | 767 | #elif UINT64_MAX <= ULLONG_MAX |
| | 768 | zig_int_helpers(64, unsigned long long) |
| | 769 | #else |
| | 770 | zig_int_helpers(64, uint64_t) |
| | 771 | #endif |
| 739 | | 772 | |
| 740 | static inline bool zig_addo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) { | 773 | static inline bool zig_addo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) { |
| 741 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 774 | #if zig_has_builtin(add_overflow) || defined(zig_gcc) |
| 742 | uint32_t full_res; | 775 | uint32_t full_res; |
| 743 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 776 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 744 | *res = zig_wrap_u32(full_res, bits); | 777 | *res = zig_wrap_u32(full_res, bits); |
| ... | @@ -751,7 +784,7 @@ static inline bool zig_addo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8 | ... | @@ -751,7 +784,7 @@ static inline bool zig_addo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8 |
| 751 | | 784 | |
| 752 | zig_extern int32_t __addosi4(int32_t lhs, int32_t rhs, int *overflow); | 785 | zig_extern int32_t __addosi4(int32_t lhs, int32_t rhs, int *overflow); |
| 753 | static inline bool zig_addo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) { | 786 | static inline bool zig_addo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) { |
| 754 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 787 | #if zig_has_builtin(add_overflow) || defined(zig_gcc) |
| 755 | int32_t full_res; | 788 | int32_t full_res; |
| 756 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 789 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 757 | #else | 790 | #else |
| ... | @@ -764,7 +797,7 @@ static inline bool zig_addo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t | ... | @@ -764,7 +797,7 @@ static inline bool zig_addo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t |
| 764 | } | 797 | } |
| 765 | | 798 | |
| 766 | static inline bool zig_addo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) { | 799 | static inline bool zig_addo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) { |
| 767 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 800 | #if zig_has_builtin(add_overflow) || defined(zig_gcc) |
| 768 | uint64_t full_res; | 801 | uint64_t full_res; |
| 769 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 802 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 770 | *res = zig_wrap_u64(full_res, bits); | 803 | *res = zig_wrap_u64(full_res, bits); |
| ... | @@ -777,7 +810,7 @@ static inline bool zig_addo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8 | ... | @@ -777,7 +810,7 @@ static inline bool zig_addo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8 |
| 777 | | 810 | |
| 778 | zig_extern int64_t __addodi4(int64_t lhs, int64_t rhs, int *overflow); | 811 | zig_extern int64_t __addodi4(int64_t lhs, int64_t rhs, int *overflow); |
| 779 | static inline bool zig_addo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) { | 812 | static inline bool zig_addo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) { |
| 780 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 813 | #if zig_has_builtin(add_overflow) || defined(zig_gcc) |
| 781 | int64_t full_res; | 814 | int64_t full_res; |
| 782 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 815 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 783 | #else | 816 | #else |
| ... | @@ -790,7 +823,7 @@ static inline bool zig_addo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t | ... | @@ -790,7 +823,7 @@ static inline bool zig_addo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t |
| 790 | } | 823 | } |
| 791 | | 824 | |
| 792 | static inline bool zig_addo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t bits) { | 825 | static inline bool zig_addo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t bits) { |
| 793 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 826 | #if zig_has_builtin(add_overflow) || defined(zig_gcc) |
| 794 | uint8_t full_res; | 827 | uint8_t full_res; |
| 795 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 828 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 796 | *res = zig_wrap_u8(full_res, bits); | 829 | *res = zig_wrap_u8(full_res, bits); |
| ... | @@ -804,7 +837,7 @@ static inline bool zig_addo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t b | ... | @@ -804,7 +837,7 @@ static inline bool zig_addo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t b |
| 804 | } | 837 | } |
| 805 | | 838 | |
| 806 | static inline bool zig_addo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits) { | 839 | static inline bool zig_addo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits) { |
| 807 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 840 | #if zig_has_builtin(add_overflow) || defined(zig_gcc) |
| 808 | int8_t full_res; | 841 | int8_t full_res; |
| 809 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 842 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 810 | *res = zig_wrap_i8(full_res, bits); | 843 | *res = zig_wrap_i8(full_res, bits); |
| ... | @@ -818,7 +851,7 @@ static inline bool zig_addo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits | ... | @@ -818,7 +851,7 @@ static inline bool zig_addo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits |
| 818 | } | 851 | } |
| 819 | | 852 | |
| 820 | static inline bool zig_addo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8_t bits) { | 853 | static inline bool zig_addo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8_t bits) { |
| 821 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 854 | #if zig_has_builtin(add_overflow) || defined(zig_gcc) |
| 822 | uint16_t full_res; | 855 | uint16_t full_res; |
| 823 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 856 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 824 | *res = zig_wrap_u16(full_res, bits); | 857 | *res = zig_wrap_u16(full_res, bits); |
| ... | @@ -832,7 +865,7 @@ static inline bool zig_addo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8 | ... | @@ -832,7 +865,7 @@ static inline bool zig_addo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8 |
| 832 | } | 865 | } |
| 833 | | 866 | |
| 834 | static inline bool zig_addo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t bits) { | 867 | static inline bool zig_addo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t bits) { |
| 835 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 868 | #if zig_has_builtin(add_overflow) || defined(zig_gcc) |
| 836 | int16_t full_res; | 869 | int16_t full_res; |
| 837 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 870 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 838 | *res = zig_wrap_i16(full_res, bits); | 871 | *res = zig_wrap_i16(full_res, bits); |
| ... | @@ -846,7 +879,7 @@ static inline bool zig_addo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t | ... | @@ -846,7 +879,7 @@ static inline bool zig_addo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t |
| 846 | } | 879 | } |
| 847 | | 880 | |
| 848 | static inline bool zig_subo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) { | 881 | static inline bool zig_subo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) { |
| 849 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) | 882 | #if zig_has_builtin(sub_overflow) || defined(zig_gcc) |
| 850 | uint32_t full_res; | 883 | uint32_t full_res; |
| 851 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 884 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 852 | *res = zig_wrap_u32(full_res, bits); | 885 | *res = zig_wrap_u32(full_res, bits); |
| ... | @@ -859,7 +892,7 @@ static inline bool zig_subo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8 | ... | @@ -859,7 +892,7 @@ static inline bool zig_subo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8 |
| 859 | | 892 | |
| 860 | zig_extern int32_t __subosi4(int32_t lhs, int32_t rhs, int *overflow); | 893 | zig_extern int32_t __subosi4(int32_t lhs, int32_t rhs, int *overflow); |
| 861 | static inline bool zig_subo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) { | 894 | static inline bool zig_subo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) { |
| 862 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) | 895 | #if zig_has_builtin(sub_overflow) || defined(zig_gcc) |
| 863 | int32_t full_res; | 896 | int32_t full_res; |
| 864 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 897 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 865 | #else | 898 | #else |
| ... | @@ -872,7 +905,7 @@ static inline bool zig_subo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t | ... | @@ -872,7 +905,7 @@ static inline bool zig_subo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t |
| 872 | } | 905 | } |
| 873 | | 906 | |
| 874 | static inline bool zig_subo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) { | 907 | static inline bool zig_subo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) { |
| 875 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) | 908 | #if zig_has_builtin(sub_overflow) || defined(zig_gcc) |
| 876 | uint64_t full_res; | 909 | uint64_t full_res; |
| 877 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 910 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 878 | *res = zig_wrap_u64(full_res, bits); | 911 | *res = zig_wrap_u64(full_res, bits); |
| ... | @@ -885,7 +918,7 @@ static inline bool zig_subo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8 | ... | @@ -885,7 +918,7 @@ static inline bool zig_subo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8 |
| 885 | | 918 | |
| 886 | zig_extern int64_t __subodi4(int64_t lhs, int64_t rhs, int *overflow); | 919 | zig_extern int64_t __subodi4(int64_t lhs, int64_t rhs, int *overflow); |
| 887 | static inline bool zig_subo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) { | 920 | static inline bool zig_subo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) { |
| 888 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) | 921 | #if zig_has_builtin(sub_overflow) || defined(zig_gcc) |
| 889 | int64_t full_res; | 922 | int64_t full_res; |
| 890 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 923 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 891 | #else | 924 | #else |
| ... | @@ -898,7 +931,7 @@ static inline bool zig_subo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t | ... | @@ -898,7 +931,7 @@ static inline bool zig_subo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t |
| 898 | } | 931 | } |
| 899 | | 932 | |
| 900 | static inline bool zig_subo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t bits) { | 933 | static inline bool zig_subo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t bits) { |
| 901 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) | 934 | #if zig_has_builtin(sub_overflow) || defined(zig_gcc) |
| 902 | uint8_t full_res; | 935 | uint8_t full_res; |
| 903 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 936 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 904 | *res = zig_wrap_u8(full_res, bits); | 937 | *res = zig_wrap_u8(full_res, bits); |
| ... | @@ -912,7 +945,7 @@ static inline bool zig_subo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t b | ... | @@ -912,7 +945,7 @@ static inline bool zig_subo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t b |
| 912 | } | 945 | } |
| 913 | | 946 | |
| 914 | static inline bool zig_subo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits) { | 947 | static inline bool zig_subo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits) { |
| 915 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) | 948 | #if zig_has_builtin(sub_overflow) || defined(zig_gcc) |
| 916 | int8_t full_res; | 949 | int8_t full_res; |
| 917 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 950 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 918 | *res = zig_wrap_i8(full_res, bits); | 951 | *res = zig_wrap_i8(full_res, bits); |
| ... | @@ -926,7 +959,7 @@ static inline bool zig_subo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits | ... | @@ -926,7 +959,7 @@ static inline bool zig_subo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits |
| 926 | } | 959 | } |
| 927 | | 960 | |
| 928 | static inline bool zig_subo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8_t bits) { | 961 | static inline bool zig_subo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8_t bits) { |
| 929 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) | 962 | #if zig_has_builtin(sub_overflow) || defined(zig_gcc) |
| 930 | uint16_t full_res; | 963 | uint16_t full_res; |
| 931 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 964 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 932 | *res = zig_wrap_u16(full_res, bits); | 965 | *res = zig_wrap_u16(full_res, bits); |
| ... | @@ -940,7 +973,7 @@ static inline bool zig_subo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8 | ... | @@ -940,7 +973,7 @@ static inline bool zig_subo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8 |
| 940 | } | 973 | } |
| 941 | | 974 | |
| 942 | static inline bool zig_subo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t bits) { | 975 | static inline bool zig_subo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t bits) { |
| 943 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) | 976 | #if zig_has_builtin(sub_overflow) || defined(zig_gcc) |
| 944 | int16_t full_res; | 977 | int16_t full_res; |
| 945 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 978 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 946 | *res = zig_wrap_i16(full_res, bits); | 979 | *res = zig_wrap_i16(full_res, bits); |
| ... | @@ -954,7 +987,7 @@ static inline bool zig_subo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t | ... | @@ -954,7 +987,7 @@ static inline bool zig_subo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t |
| 954 | } | 987 | } |
| 955 | | 988 | |
| 956 | static inline bool zig_mulo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) { | 989 | static inline bool zig_mulo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) { |
| 957 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) | 990 | #if zig_has_builtin(mul_overflow) || defined(zig_gcc) |
| 958 | uint32_t full_res; | 991 | uint32_t full_res; |
| 959 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 992 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 960 | *res = zig_wrap_u32(full_res, bits); | 993 | *res = zig_wrap_u32(full_res, bits); |
| ... | @@ -967,7 +1000,7 @@ static inline bool zig_mulo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8 | ... | @@ -967,7 +1000,7 @@ static inline bool zig_mulo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8 |
| 967 | | 1000 | |
| 968 | zig_extern int32_t __mulosi4(int32_t lhs, int32_t rhs, int *overflow); | 1001 | zig_extern int32_t __mulosi4(int32_t lhs, int32_t rhs, int *overflow); |
| 969 | static inline bool zig_mulo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) { | 1002 | static inline bool zig_mulo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) { |
| 970 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) | 1003 | #if zig_has_builtin(mul_overflow) || defined(zig_gcc) |
| 971 | int32_t full_res; | 1004 | int32_t full_res; |
| 972 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 1005 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 973 | #else | 1006 | #else |
| ... | @@ -980,7 +1013,7 @@ static inline bool zig_mulo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t | ... | @@ -980,7 +1013,7 @@ static inline bool zig_mulo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t |
| 980 | } | 1013 | } |
| 981 | | 1014 | |
| 982 | static inline bool zig_mulo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) { | 1015 | static inline bool zig_mulo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) { |
| 983 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) | 1016 | #if zig_has_builtin(mul_overflow) || defined(zig_gcc) |
| 984 | uint64_t full_res; | 1017 | uint64_t full_res; |
| 985 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 1018 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 986 | *res = zig_wrap_u64(full_res, bits); | 1019 | *res = zig_wrap_u64(full_res, bits); |
| ... | @@ -993,7 +1026,7 @@ static inline bool zig_mulo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8 | ... | @@ -993,7 +1026,7 @@ static inline bool zig_mulo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8 |
| 993 | | 1026 | |
| 994 | zig_extern int64_t __mulodi4(int64_t lhs, int64_t rhs, int *overflow); | 1027 | zig_extern int64_t __mulodi4(int64_t lhs, int64_t rhs, int *overflow); |
| 995 | static inline bool zig_mulo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) { | 1028 | static inline bool zig_mulo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) { |
| 996 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) | 1029 | #if zig_has_builtin(mul_overflow) || defined(zig_gcc) |
| 997 | int64_t full_res; | 1030 | int64_t full_res; |
| 998 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 1031 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 999 | #else | 1032 | #else |
| ... | @@ -1006,7 +1039,7 @@ static inline bool zig_mulo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t | ... | @@ -1006,7 +1039,7 @@ static inline bool zig_mulo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t |
| 1006 | } | 1039 | } |
| 1007 | | 1040 | |
| 1008 | static inline bool zig_mulo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t bits) { | 1041 | static inline bool zig_mulo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t bits) { |
| 1009 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) | 1042 | #if zig_has_builtin(mul_overflow) || defined(zig_gcc) |
| 1010 | uint8_t full_res; | 1043 | uint8_t full_res; |
| 1011 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 1044 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 1012 | *res = zig_wrap_u8(full_res, bits); | 1045 | *res = zig_wrap_u8(full_res, bits); |
| ... | @@ -1020,7 +1053,7 @@ static inline bool zig_mulo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t b | ... | @@ -1020,7 +1053,7 @@ static inline bool zig_mulo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t b |
| 1020 | } | 1053 | } |
| 1021 | | 1054 | |
| 1022 | static inline bool zig_mulo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits) { | 1055 | static inline bool zig_mulo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits) { |
| 1023 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) | 1056 | #if zig_has_builtin(mul_overflow) || defined(zig_gcc) |
| 1024 | int8_t full_res; | 1057 | int8_t full_res; |
| 1025 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 1058 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 1026 | *res = zig_wrap_i8(full_res, bits); | 1059 | *res = zig_wrap_i8(full_res, bits); |
| ... | @@ -1034,7 +1067,7 @@ static inline bool zig_mulo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits | ... | @@ -1034,7 +1067,7 @@ static inline bool zig_mulo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits |
| 1034 | } | 1067 | } |
| 1035 | | 1068 | |
| 1036 | static inline bool zig_mulo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8_t bits) { | 1069 | static inline bool zig_mulo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8_t bits) { |
| 1037 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) | 1070 | #if zig_has_builtin(mul_overflow) || defined(zig_gcc) |
| 1038 | uint16_t full_res; | 1071 | uint16_t full_res; |
| 1039 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 1072 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 1040 | *res = zig_wrap_u16(full_res, bits); | 1073 | *res = zig_wrap_u16(full_res, bits); |
| ... | @@ -1048,7 +1081,7 @@ static inline bool zig_mulo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8 | ... | @@ -1048,7 +1081,7 @@ static inline bool zig_mulo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8 |
| 1048 | } | 1081 | } |
| 1049 | | 1082 | |
| 1050 | static inline bool zig_mulo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t bits) { | 1083 | static inline bool zig_mulo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t bits) { |
| 1051 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) | 1084 | #if zig_has_builtin(mul_overflow) || defined(zig_gcc) |
| 1052 | int16_t full_res; | 1085 | int16_t full_res; |
| 1053 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 1086 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 1054 | *res = zig_wrap_i16(full_res, bits); | 1087 | *res = zig_wrap_i16(full_res, bits); |
| ... | @@ -1157,7 +1190,7 @@ static inline int8_t zig_byte_swap_i8(int8_t val, uint8_t bits) { | ... | @@ -1157,7 +1190,7 @@ static inline int8_t zig_byte_swap_i8(int8_t val, uint8_t bits) { |
| 1157 | | 1190 | |
| 1158 | static inline uint16_t zig_byte_swap_u16(uint16_t val, uint8_t bits) { | 1191 | static inline uint16_t zig_byte_swap_u16(uint16_t val, uint8_t bits) { |
| 1159 | uint16_t full_res; | 1192 | uint16_t full_res; |
| 1160 | #if zig_has_builtin(bswap16) || defined(zig_gnuc) | 1193 | #if zig_has_builtin(bswap16) || defined(zig_gcc) |
| 1161 | full_res = __builtin_bswap16(val); | 1194 | full_res = __builtin_bswap16(val); |
| 1162 | #else | 1195 | #else |
| 1163 | full_res = (uint16_t)zig_byte_swap_u8((uint8_t)(val >> 0), 8) << 8 | | 1196 | full_res = (uint16_t)zig_byte_swap_u8((uint8_t)(val >> 0), 8) << 8 | |
| ... | @@ -1172,7 +1205,7 @@ static inline int16_t zig_byte_swap_i16(int16_t val, uint8_t bits) { | ... | @@ -1172,7 +1205,7 @@ static inline int16_t zig_byte_swap_i16(int16_t val, uint8_t bits) { |
| 1172 | | 1205 | |
| 1173 | static inline uint32_t zig_byte_swap_u32(uint32_t val, uint8_t bits) { | 1206 | static inline uint32_t zig_byte_swap_u32(uint32_t val, uint8_t bits) { |
| 1174 | uint32_t full_res; | 1207 | uint32_t full_res; |
| 1175 | #if zig_has_builtin(bswap32) || defined(zig_gnuc) | 1208 | #if zig_has_builtin(bswap32) || defined(zig_gcc) |
| 1176 | full_res = __builtin_bswap32(val); | 1209 | full_res = __builtin_bswap32(val); |
| 1177 | #else | 1210 | #else |
| 1178 | full_res = (uint32_t)zig_byte_swap_u16((uint16_t)(val >> 0), 16) << 16 | | 1211 | full_res = (uint32_t)zig_byte_swap_u16((uint16_t)(val >> 0), 16) << 16 | |
| ... | @@ -1187,7 +1220,7 @@ static inline int32_t zig_byte_swap_i32(int32_t val, uint8_t bits) { | ... | @@ -1187,7 +1220,7 @@ static inline int32_t zig_byte_swap_i32(int32_t val, uint8_t bits) { |
| 1187 | | 1220 | |
| 1188 | static inline uint64_t zig_byte_swap_u64(uint64_t val, uint8_t bits) { | 1221 | static inline uint64_t zig_byte_swap_u64(uint64_t val, uint8_t bits) { |
| 1189 | uint64_t full_res; | 1222 | uint64_t full_res; |
| 1190 | #if zig_has_builtin(bswap64) || defined(zig_gnuc) | 1223 | #if zig_has_builtin(bswap64) || defined(zig_gcc) |
| 1191 | full_res = __builtin_bswap64(val); | 1224 | full_res = __builtin_bswap64(val); |
| 1192 | #else | 1225 | #else |
| 1193 | full_res = (uint64_t)zig_byte_swap_u32((uint32_t)(val >> 0), 32) << 32 | | 1226 | full_res = (uint64_t)zig_byte_swap_u32((uint32_t)(val >> 0), 32) << 32 | |
| ... | @@ -1267,7 +1300,7 @@ static inline int64_t zig_bit_reverse_i64(int64_t val, uint8_t bits) { | ... | @@ -1267,7 +1300,7 @@ static inline int64_t zig_bit_reverse_i64(int64_t val, uint8_t bits) { |
| 1267 | static inline uint8_t zig_popcount_i##w(int##w##_t val, uint8_t bits) { \ | 1300 | static inline uint8_t zig_popcount_i##w(int##w##_t val, uint8_t bits) { \ |
| 1268 | return zig_popcount_u##w((uint##w##_t)val, bits); \ | 1301 | return zig_popcount_u##w((uint##w##_t)val, bits); \ |
| 1269 | } | 1302 | } |
| 1270 | #if zig_has_builtin(popcount) || defined(zig_gnuc) || defined(zig_tinyc) | 1303 | #if zig_has_builtin(popcount) || defined(zig_gcc) || defined(zig_tinyc) |
| 1271 | #define zig_builtin_popcount(w) \ | 1304 | #define zig_builtin_popcount(w) \ |
| 1272 | static inline uint8_t zig_popcount_u##w(uint##w##_t val, uint8_t bits) { \ | 1305 | static inline uint8_t zig_popcount_u##w(uint##w##_t val, uint8_t bits) { \ |
| 1273 | (void)bits; \ | 1306 | (void)bits; \ |
| ... | @@ -1296,7 +1329,7 @@ zig_builtin_popcount(64) | ... | @@ -1296,7 +1329,7 @@ zig_builtin_popcount(64) |
| 1296 | static inline uint8_t zig_ctz_i##w(int##w##_t val, uint8_t bits) { \ | 1329 | static inline uint8_t zig_ctz_i##w(int##w##_t val, uint8_t bits) { \ |
| 1297 | return zig_ctz_u##w((uint##w##_t)val, bits); \ | 1330 | return zig_ctz_u##w((uint##w##_t)val, bits); \ |
| 1298 | } | 1331 | } |
| 1299 | #if zig_has_builtin(ctz) || defined(zig_gnuc) || defined(zig_tinyc) | 1332 | #if zig_has_builtin(ctz) || defined(zig_gcc) || defined(zig_tinyc) |
| 1300 | #define zig_builtin_ctz(w) \ | 1333 | #define zig_builtin_ctz(w) \ |
| 1301 | static inline uint8_t zig_ctz_u##w(uint##w##_t val, uint8_t bits) { \ | 1334 | static inline uint8_t zig_ctz_u##w(uint##w##_t val, uint8_t bits) { \ |
| 1302 | if (val == 0) return bits; \ | 1335 | if (val == 0) return bits; \ |
| ... | @@ -1321,7 +1354,7 @@ zig_builtin_ctz(64) | ... | @@ -1321,7 +1354,7 @@ zig_builtin_ctz(64) |
| 1321 | static inline uint8_t zig_clz_i##w(int##w##_t val, uint8_t bits) { \ | 1354 | static inline uint8_t zig_clz_i##w(int##w##_t val, uint8_t bits) { \ |
| 1322 | return zig_clz_u##w((uint##w##_t)val, bits); \ | 1355 | return zig_clz_u##w((uint##w##_t)val, bits); \ |
| 1323 | } | 1356 | } |
| 1324 | #if zig_has_builtin(clz) || defined(zig_gnuc) || defined(zig_tinyc) | 1357 | #if zig_has_builtin(clz) || defined(zig_gcc) || defined(zig_tinyc) |
| 1325 | #define zig_builtin_clz(w) \ | 1358 | #define zig_builtin_clz(w) \ |
| 1326 | static inline uint8_t zig_clz_u##w(uint##w##_t val, uint8_t bits) { \ | 1359 | static inline uint8_t zig_clz_u##w(uint##w##_t val, uint8_t bits) { \ |
| 1327 | if (val == 0) return bits; \ | 1360 | if (val == 0) return bits; \ |
| ... | @@ -3176,7 +3209,7 @@ long double __cdecl nanl(char const* input); | ... | @@ -3176,7 +3209,7 @@ long double __cdecl nanl(char const* input); |
| 3176 | #define __builtin_infl() zig_msvc_flt_infl | 3209 | #define __builtin_infl() zig_msvc_flt_infl |
| 3177 | #endif | 3210 | #endif |
| 3178 | | 3211 | |
| 3179 | #if (zig_has_builtin(nan) && zig_has_builtin(nans) && zig_has_builtin(inf)) || defined(zig_gnuc) | 3212 | #if (zig_has_builtin(nan) && zig_has_builtin(nans) && zig_has_builtin(inf)) || defined(zig_gcc) |
| 3180 | #define zig_make_special_f16(sign, name, arg, repr) sign zig_make_f16 (__builtin_##name, )(arg) | 3213 | #define zig_make_special_f16(sign, name, arg, repr) sign zig_make_f16 (__builtin_##name, )(arg) |
| 3181 | #define zig_make_special_f32(sign, name, arg, repr) sign zig_make_f32 (__builtin_##name, )(arg) | 3214 | #define zig_make_special_f32(sign, name, arg, repr) sign zig_make_f32 (__builtin_##name, )(arg) |
| 3182 | #define zig_make_special_f64(sign, name, arg, repr) sign zig_make_f64 (__builtin_##name, )(arg) | 3215 | #define zig_make_special_f64(sign, name, arg, repr) sign zig_make_f64 (__builtin_##name, )(arg) |
| ... | @@ -3202,7 +3235,7 @@ typedef double zig_f16; | ... | @@ -3202,7 +3235,7 @@ typedef double zig_f16; |
| 3202 | #elif LDBL_MANT_DIG == 11 | 3235 | #elif LDBL_MANT_DIG == 11 |
| 3203 | typedef long double zig_f16; | 3236 | typedef long double zig_f16; |
| 3204 | #define zig_make_f16(fp, repr) fp##l | 3237 | #define zig_make_f16(fp, repr) fp##l |
| 3205 | #elif FLT16_MANT_DIG == 11 && (zig_has_builtin(inff16) || defined(zig_gnuc)) | 3238 | #elif FLT16_MANT_DIG == 11 && (zig_has_builtin(inff16) || defined(zig_gcc)) |
| 3206 | typedef _Float16 zig_f16; | 3239 | typedef _Float16 zig_f16; |
| 3207 | #define zig_make_f16(fp, repr) fp##f16 | 3240 | #define zig_make_f16(fp, repr) fp##f16 |
| 3208 | #elif defined(__SIZEOF_FP16__) | 3241 | #elif defined(__SIZEOF_FP16__) |
| ... | @@ -3324,7 +3357,7 @@ typedef zig_u128 zig_f80; | ... | @@ -3324,7 +3357,7 @@ typedef zig_u128 zig_f80; |
| 3324 | #define zig_init_special_f80(sign, name, arg, repr) repr | 3357 | #define zig_init_special_f80(sign, name, arg, repr) repr |
| 3325 | #endif | 3358 | #endif |
| 3326 | | 3359 | |
| 3327 | #if !defined(zig_clang) && defined(zig_gnuc) && defined(zig_x86) | 3360 | #if defined(zig_gcc) && defined(zig_x86) |
| 3328 | #define zig_f128_has_miscompilations 1 | 3361 | #define zig_f128_has_miscompilations 1 |
| 3329 | #else | 3362 | #else |
| 3330 | #define zig_f128_has_miscompilations 0 | 3363 | #define zig_f128_has_miscompilations 0 |
| ... | @@ -3729,7 +3762,11 @@ zig_float_builtins(64) | ... | @@ -3729,7 +3762,11 @@ zig_float_builtins(64) |
| 3729 | res = zig_atomicrmw_expected; \ | 3762 | res = zig_atomicrmw_expected; \ |
| 3730 | } while (0) | 3763 | } while (0) |
| 3731 | | 3764 | |
| 3732 | #if (__STDC_VERSION__ >= 201112L || (zig_has_include(<stdatomic.h>) && !defined(zig_msvc))) && !defined(__STDC_NO_ATOMICS__) | 3765 | #if (__STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)) || (zig_has_include(<stdatomic.h>) && !defined(zig_msvc)) |
| | 3766 | #define zig_c11_atomics |
| | 3767 | #endif |
| | 3768 | |
| | 3769 | #if defined(zig_c11_atomics) |
| 3733 | #include <stdatomic.h> | 3770 | #include <stdatomic.h> |
| 3734 | typedef enum memory_order zig_memory_order; | 3771 | typedef enum memory_order zig_memory_order; |
| 3735 | #define zig_memory_order_relaxed memory_order_relaxed | 3772 | #define zig_memory_order_relaxed memory_order_relaxed |
| ... | @@ -3765,9 +3802,9 @@ typedef int zig_memory_order; | ... | @@ -3765,9 +3802,9 @@ typedef int zig_memory_order; |
| 3765 | #define zig_memory_order_acq_rel __ATOMIC_ACQ_REL | 3802 | #define zig_memory_order_acq_rel __ATOMIC_ACQ_REL |
| 3766 | #define zig_memory_order_seq_cst __ATOMIC_SEQ_CST | 3803 | #define zig_memory_order_seq_cst __ATOMIC_SEQ_CST |
| 3767 | #define zig_atomic(Type) Type | 3804 | #define zig_atomic(Type) Type |
| 3768 | #define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, &(expected), &(desired), false, succ, fail) | 3805 | #define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, (ReprType *)&(expected), (ReprType *)&(desired), false, succ, fail) |
| 3769 | #define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, &(expected), &(desired), true, succ, fail) | 3806 | #define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, (ReprType *)&(expected), (ReprType *)&(desired), true, succ, fail) |
| 3770 | #define zig_atomicrmw_xchg(res, obj, arg, order, Type, ReprType) __atomic_exchange(obj, &(arg), &(res), order) | 3807 | #define zig_atomicrmw_xchg(res, obj, arg, order, Type, ReprType) __atomic_exchange(obj, (ReprType *)&(arg), &(res), order) |
| 3771 | #define zig_atomicrmw_add(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_add (obj, arg, order) | 3808 | #define zig_atomicrmw_add(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_add (obj, arg, order) |
| 3772 | #define zig_atomicrmw_sub(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_sub (obj, arg, order) | 3809 | #define zig_atomicrmw_sub(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_sub (obj, arg, order) |
| 3773 | #define zig_atomicrmw_or(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_or (obj, arg, order) | 3810 | #define zig_atomicrmw_or(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_or (obj, arg, order) |
| ... | @@ -3776,7 +3813,7 @@ typedef int zig_memory_order; | ... | @@ -3776,7 +3813,7 @@ typedef int zig_memory_order; |
| 3776 | #define zig_atomicrmw_nand(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_nand(obj, arg, order) | 3813 | #define zig_atomicrmw_nand(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_nand(obj, arg, order) |
| 3777 | #define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_min (obj, arg, order) | 3814 | #define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_min (obj, arg, order) |
| 3778 | #define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_max (obj, arg, order) | 3815 | #define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_max (obj, arg, order) |
| 3779 | #define zig_atomic_store( obj, arg, order, Type, ReprType) __atomic_store (obj, &(arg), order) | 3816 | #define zig_atomic_store( obj, arg, order, Type, ReprType) __atomic_store (obj, (ReprType *)&(arg), order) |
| 3780 | #define zig_atomic_load(res, obj, order, Type, ReprType) __atomic_load (obj, &(res), order) | 3817 | #define zig_atomic_load(res, obj, order, Type, ReprType) __atomic_load (obj, &(res), order) |
| 3781 | #undef zig_atomicrmw_xchg_float | 3818 | #undef zig_atomicrmw_xchg_float |
| 3782 | #define zig_atomicrmw_xchg_float zig_atomicrmw_xchg | 3819 | #define zig_atomicrmw_xchg_float zig_atomicrmw_xchg |
| ... | @@ -3823,7 +3860,7 @@ typedef int zig_memory_order; | ... | @@ -3823,7 +3860,7 @@ typedef int zig_memory_order; |
| 3823 | #define zig_atomic_load(res, obj, order, Type, ReprType) zig_atomics_unavailable | 3860 | #define zig_atomic_load(res, obj, order, Type, ReprType) zig_atomics_unavailable |
| 3824 | #endif | 3861 | #endif |
| 3825 | | 3862 | |
| 3826 | #if defined(zig_msvc) && defined(zig_x86) | 3863 | #if !defined(zig_c11_atomics) && defined(zig_msvc) && defined(zig_x86) |
| 3827 | | 3864 | |
| 3828 | /* TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 */ | 3865 | /* TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 */ |
| 3829 | | 3866 | |
| ... | @@ -4069,7 +4106,7 @@ static inline void zig_msvc_atomic_store_i128(zig_i128 volatile* obj, zig_i128 a | ... | @@ -4069,7 +4106,7 @@ static inline void zig_msvc_atomic_store_i128(zig_i128 volatile* obj, zig_i128 a |
| 4069 | | 4106 | |
| 4070 | #endif /* zig_x86_32 */ | 4107 | #endif /* zig_x86_32 */ |
| 4071 | | 4108 | |
| 4072 | #endif /* zig_msvc && zig_x86 */ | 4109 | #endif /* !zig_c11_atomics && zig_msvc && zig_x86 */ |
| 4073 | | 4110 | |
| 4074 | /* ======================== Special Case Intrinsics ========================= */ | 4111 | /* ======================== Special Case Intrinsics ========================= */ |
| 4075 | | 4112 | |