| ... | ... | @@ -9,6 +9,7 @@ |
| 9 | 9 | #define zig_clang |
| 10 | 10 | #define zig_gnuc |
| 11 | 11 | #elif defined(__GNUC__) |
| 12 | #define zig_gcc |
| 12 | 13 | #define zig_gnuc |
| 13 | 14 | #elif defined(__IBMC__) |
| 14 | 15 | #define zig_xlc |
| ... | ... | @@ -171,7 +172,7 @@ |
| 171 | 172 | #define zig_callconv(c) __attribute__((c)) |
| 172 | 173 | #endif |
| 173 | 174 | |
| 174 | | #if zig_has_attribute(naked) || defined(zig_gnuc) |
| 175 | #if zig_has_attribute(naked) || defined(zig_gcc) |
| 175 | 176 | #define zig_naked_decl __attribute__((naked)) |
| 176 | 177 | #define zig_naked __attribute__((naked)) |
| 177 | 178 | #elif defined(zig_msvc) |
| ... | ... | @@ -265,7 +266,7 @@ |
| 265 | 266 | #define zig_linksection_fn zig_linksection |
| 266 | 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 | 270 | #define zig_unreachable() __builtin_unreachable() |
| 270 | 271 | #elif defined(zig_msvc) |
| 271 | 272 | #define zig_unreachable() __assume(0) |
| ... | ... | @@ -293,11 +294,11 @@ |
| 293 | 294 | #endif /* zig_macho */ |
| 294 | 295 | #endif /* zig_msvc */ |
| 295 | 296 | |
| 296 | | #if (zig_has_attribute(alias) || defined(zig_tinyc)) && !defined(zig_macho) |
| 297 | | #define zig_export(symbol, name) __attribute__((alias(symbol))) |
| 298 | | #elif defined(zig_msvc) |
| 297 | #if defined(zig_msvc) |
| 299 | 298 | #define zig_export(symbol, name) ; \ |
| 300 | 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 | 302 | #else |
| 302 | 303 | #define zig_export(symbol, name) ; \ |
| 303 | 304 | __asm(zig_mangle_c(name) " = " zig_mangle_c(symbol)) |
| ... | ... | @@ -321,7 +322,7 @@ |
| 321 | 322 | #if defined(zig_msvc) |
| 322 | 323 | #define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args;\ |
| 323 | 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 | 326 | #else /* zig_msvc */ |
| 326 | 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 | 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 | 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 | 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 | 336 | #define zig_weak_linkage __attribute__((weak)) |
| 336 | 337 | #define zig_weak_linkage_fn __attribute__((weak)) |
| 337 | 338 | #elif defined(zig_msvc) |
| ... | ... | @@ -418,7 +419,7 @@ |
| 418 | 419 | #define zig_breakpoint() zig_breakpoint_unavailable |
| 419 | 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 | 423 | #define zig_return_address() __builtin_extract_return_addr(__builtin_return_address(0)) |
| 423 | 424 | #elif defined(zig_msvc) |
| 424 | 425 | #define zig_return_address() _ReturnAddress() |
| ... | ... | @@ -426,7 +427,7 @@ |
| 426 | 427 | #define zig_return_address() 0 |
| 427 | 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 | 431 | #define zig_frame_address() __builtin_frame_address(0) |
| 431 | 432 | #elif defined(zig_msvc) |
| 432 | 433 | #define zig_frame_address() _AddressOfReturnAddress() |
| ... | ... | @@ -434,7 +435,7 @@ |
| 434 | 435 | #define zig_frame_address() 0 |
| 435 | 436 | #endif |
| 436 | 437 | |
| 437 | | #if zig_has_builtin(prefetch) || defined(zig_gnuc) |
| 438 | #if zig_has_builtin(prefetch) || defined(zig_gcc) |
| 438 | 439 | #define zig_prefetch(addr, rw, locality) __builtin_prefetch(addr, rw, locality) |
| 439 | 440 | #else |
| 440 | 441 | #define zig_prefetch(addr, rw, locality) |
| ... | ... | @@ -452,7 +453,7 @@ |
| 452 | 453 | #define zig_noreturn [[noreturn]] |
| 453 | 454 | #elif __STDC_VERSION__ >= 201112L |
| 454 | 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 | 457 | #define zig_noreturn __attribute__((noreturn)) |
| 457 | 458 | #elif defined(zig_msvc) |
| 458 | 459 | #define zig_noreturn __declspec(noreturn) |
| ... | ... | @@ -650,7 +651,7 @@ typedef ptrdiff_t intptr_t; |
| 650 | 651 | zig_operator(Type, Type, operation, operator) |
| 651 | 652 | #define zig_shift_operator(Type, operation, operator) \ |
| 652 | 653 | zig_operator(Type, uint8_t, operation, operator) |
| 653 | | #define zig_int_helpers(w) \ |
| 654 | #define zig_int_helpers(w, PromotedUnsigned) \ |
| 654 | 655 | zig_basic_operator(uint##w##_t, and_u##w, &) \ |
| 655 | 656 | zig_basic_operator( int##w##_t, and_i##w, &) \ |
| 656 | 657 | zig_basic_operator(uint##w##_t, or_u##w, |) \ |
| ... | ... | @@ -726,19 +727,51 @@ typedef ptrdiff_t intptr_t; |
| 726 | 727 | } \ |
| 727 | 728 | \ |
| 728 | 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 | 733 | static inline int##w##_t zig_mulw_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ |
| 733 | 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 | | zig_int_helpers(16) |
| 737 | | zig_int_helpers(32) |
| 738 | | zig_int_helpers(64) |
| 736 | #if UINT8_MAX <= UINT_MAX |
| 737 | zig_int_helpers(8, unsigned int) |
| 738 | #elif UINT8_MAX <= ULONG_MAX |
| 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 | 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 | 775 | uint32_t full_res; |
| 743 | 776 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 744 | 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 | 784 | |
| 752 | 785 | zig_extern int32_t __addosi4(int32_t lhs, int32_t rhs, int *overflow); |
| 753 | 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 | 788 | int32_t full_res; |
| 756 | 789 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 757 | 790 | #else |
| ... | ... | @@ -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 | 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 | 801 | uint64_t full_res; |
| 769 | 802 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 770 | 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 | 810 | |
| 778 | 811 | zig_extern int64_t __addodi4(int64_t lhs, int64_t rhs, int *overflow); |
| 779 | 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 | 814 | int64_t full_res; |
| 782 | 815 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 783 | 816 | #else |
| ... | ... | @@ -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 | 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 | 827 | uint8_t full_res; |
| 795 | 828 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 796 | 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 | 837 | } |
| 805 | 838 | |
| 806 | 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 | 841 | int8_t full_res; |
| 809 | 842 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 810 | 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 | 851 | } |
| 819 | 852 | |
| 820 | 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 | 855 | uint16_t full_res; |
| 823 | 856 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 824 | 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 | 865 | } |
| 833 | 866 | |
| 834 | 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 | 869 | int16_t full_res; |
| 837 | 870 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 838 | 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 | 879 | } |
| 847 | 880 | |
| 848 | 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 | 883 | uint32_t full_res; |
| 851 | 884 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 852 | 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 | 892 | |
| 860 | 893 | zig_extern int32_t __subosi4(int32_t lhs, int32_t rhs, int *overflow); |
| 861 | 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 | 896 | int32_t full_res; |
| 864 | 897 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 865 | 898 | #else |
| ... | ... | @@ -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 | 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 | 909 | uint64_t full_res; |
| 877 | 910 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 878 | 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 | 918 | |
| 886 | 919 | zig_extern int64_t __subodi4(int64_t lhs, int64_t rhs, int *overflow); |
| 887 | 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 | 922 | int64_t full_res; |
| 890 | 923 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 891 | 924 | #else |
| ... | ... | @@ -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 | 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 | 935 | uint8_t full_res; |
| 903 | 936 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 904 | 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 | 945 | } |
| 913 | 946 | |
| 914 | 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 | 949 | int8_t full_res; |
| 917 | 950 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 918 | 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 | 959 | } |
| 927 | 960 | |
| 928 | 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 | 963 | uint16_t full_res; |
| 931 | 964 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 932 | 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 | 973 | } |
| 941 | 974 | |
| 942 | 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 | 977 | int16_t full_res; |
| 945 | 978 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 946 | 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 | 987 | } |
| 955 | 988 | |
| 956 | 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 | 991 | uint32_t full_res; |
| 959 | 992 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 960 | 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 | 1000 | |
| 968 | 1001 | zig_extern int32_t __mulosi4(int32_t lhs, int32_t rhs, int *overflow); |
| 969 | 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 | 1004 | int32_t full_res; |
| 972 | 1005 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 973 | 1006 | #else |
| ... | ... | @@ -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 | 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 | 1017 | uint64_t full_res; |
| 985 | 1018 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 986 | 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 | 1026 | |
| 994 | 1027 | zig_extern int64_t __mulodi4(int64_t lhs, int64_t rhs, int *overflow); |
| 995 | 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 | 1030 | int64_t full_res; |
| 998 | 1031 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 999 | 1032 | #else |
| ... | ... | @@ -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 | 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 | 1043 | uint8_t full_res; |
| 1011 | 1044 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 1012 | 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 | 1053 | } |
| 1021 | 1054 | |
| 1022 | 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 | 1057 | int8_t full_res; |
| 1025 | 1058 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 1026 | 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 | 1067 | } |
| 1035 | 1068 | |
| 1036 | 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 | 1071 | uint16_t full_res; |
| 1039 | 1072 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 1040 | 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 | 1081 | } |
| 1049 | 1082 | |
| 1050 | 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 | 1085 | int16_t full_res; |
| 1053 | 1086 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 1054 | 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 | 1190 | |
| 1158 | 1191 | static inline uint16_t zig_byte_swap_u16(uint16_t val, uint8_t bits) { |
| 1159 | 1192 | uint16_t full_res; |
| 1160 | | #if zig_has_builtin(bswap16) || defined(zig_gnuc) |
| 1193 | #if zig_has_builtin(bswap16) || defined(zig_gcc) |
| 1161 | 1194 | full_res = __builtin_bswap16(val); |
| 1162 | 1195 | #else |
| 1163 | 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 | 1205 | |
| 1173 | 1206 | static inline uint32_t zig_byte_swap_u32(uint32_t val, uint8_t bits) { |
| 1174 | 1207 | uint32_t full_res; |
| 1175 | | #if zig_has_builtin(bswap32) || defined(zig_gnuc) |
| 1208 | #if zig_has_builtin(bswap32) || defined(zig_gcc) |
| 1176 | 1209 | full_res = __builtin_bswap32(val); |
| 1177 | 1210 | #else |
| 1178 | 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 | 1220 | |
| 1188 | 1221 | static inline uint64_t zig_byte_swap_u64(uint64_t val, uint8_t bits) { |
| 1189 | 1222 | uint64_t full_res; |
| 1190 | | #if zig_has_builtin(bswap64) || defined(zig_gnuc) |
| 1223 | #if zig_has_builtin(bswap64) || defined(zig_gcc) |
| 1191 | 1224 | full_res = __builtin_bswap64(val); |
| 1192 | 1225 | #else |
| 1193 | 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 | 1300 | static inline uint8_t zig_popcount_i##w(int##w##_t val, uint8_t bits) { \ |
| 1268 | 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 | 1304 | #define zig_builtin_popcount(w) \ |
| 1272 | 1305 | static inline uint8_t zig_popcount_u##w(uint##w##_t val, uint8_t bits) { \ |
| 1273 | 1306 | (void)bits; \ |
| ... | ... | @@ -1296,7 +1329,7 @@ zig_builtin_popcount(64) |
| 1296 | 1329 | static inline uint8_t zig_ctz_i##w(int##w##_t val, uint8_t bits) { \ |
| 1297 | 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 | 1333 | #define zig_builtin_ctz(w) \ |
| 1301 | 1334 | static inline uint8_t zig_ctz_u##w(uint##w##_t val, uint8_t bits) { \ |
| 1302 | 1335 | if (val == 0) return bits; \ |
| ... | ... | @@ -1321,7 +1354,7 @@ zig_builtin_ctz(64) |
| 1321 | 1354 | static inline uint8_t zig_clz_i##w(int##w##_t val, uint8_t bits) { \ |
| 1322 | 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 | 1358 | #define zig_builtin_clz(w) \ |
| 1326 | 1359 | static inline uint8_t zig_clz_u##w(uint##w##_t val, uint8_t bits) { \ |
| 1327 | 1360 | if (val == 0) return bits; \ |
| ... | ... | @@ -3176,7 +3209,7 @@ long double __cdecl nanl(char const* input); |
| 3176 | 3209 | #define __builtin_infl() zig_msvc_flt_infl |
| 3177 | 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 | 3213 | #define zig_make_special_f16(sign, name, arg, repr) sign zig_make_f16 (__builtin_##name, )(arg) |
| 3181 | 3214 | #define zig_make_special_f32(sign, name, arg, repr) sign zig_make_f32 (__builtin_##name, )(arg) |
| 3182 | 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 | 3235 | #elif LDBL_MANT_DIG == 11 |
| 3203 | 3236 | typedef long double zig_f16; |
| 3204 | 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 | 3239 | typedef _Float16 zig_f16; |
| 3207 | 3240 | #define zig_make_f16(fp, repr) fp##f16 |
| 3208 | 3241 | #elif defined(__SIZEOF_FP16__) |
| ... | ... | @@ -3324,7 +3357,7 @@ typedef zig_u128 zig_f80; |
| 3324 | 3357 | #define zig_init_special_f80(sign, name, arg, repr) repr |
| 3325 | 3358 | #endif |
| 3326 | 3359 | |
| 3327 | | #if !defined(zig_clang) && defined(zig_gnuc) && defined(zig_x86) |
| 3360 | #if defined(zig_gcc) && defined(zig_x86) |
| 3328 | 3361 | #define zig_f128_has_miscompilations 1 |
| 3329 | 3362 | #else |
| 3330 | 3363 | #define zig_f128_has_miscompilations 0 |
| ... | ... | @@ -3729,7 +3762,11 @@ zig_float_builtins(64) |
| 3729 | 3762 | res = zig_atomicrmw_expected; \ |
| 3730 | 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 | 3770 | #include <stdatomic.h> |
| 3734 | 3771 | typedef enum memory_order zig_memory_order; |
| 3735 | 3772 | #define zig_memory_order_relaxed memory_order_relaxed |
| ... | ... | @@ -3765,9 +3802,9 @@ typedef int zig_memory_order; |
| 3765 | 3802 | #define zig_memory_order_acq_rel __ATOMIC_ACQ_REL |
| 3766 | 3803 | #define zig_memory_order_seq_cst __ATOMIC_SEQ_CST |
| 3767 | 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) |
| 3769 | | #define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, &(expected), &(desired), true, succ, fail) |
| 3770 | | #define zig_atomicrmw_xchg(res, obj, arg, order, Type, ReprType) __atomic_exchange(obj, &(arg), &(res), order) |
| 3805 | #define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, (ReprType *)&(expected), (ReprType *)&(desired), false, 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) |
| 3807 | #define zig_atomicrmw_xchg(res, obj, arg, order, Type, ReprType) __atomic_exchange(obj, (ReprType *)&(arg), &(res), order) |
| 3771 | 3808 | #define zig_atomicrmw_add(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_add (obj, arg, order) |
| 3772 | 3809 | #define zig_atomicrmw_sub(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_sub (obj, arg, order) |
| 3773 | 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 | 3813 | #define zig_atomicrmw_nand(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_nand(obj, arg, order) |
| 3777 | 3814 | #define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_min (obj, arg, order) |
| 3778 | 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 | 3817 | #define zig_atomic_load(res, obj, order, Type, ReprType) __atomic_load (obj, &(res), order) |
| 3781 | 3818 | #undef zig_atomicrmw_xchg_float |
| 3782 | 3819 | #define zig_atomicrmw_xchg_float zig_atomicrmw_xchg |
| ... | ... | @@ -3823,7 +3860,7 @@ typedef int zig_memory_order; |
| 3823 | 3860 | #define zig_atomic_load(res, obj, order, Type, ReprType) zig_atomics_unavailable |
| 3824 | 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 | 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 | 4106 | |
| 4070 | 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 | 4111 | /* ======================== Special Case Intrinsics ========================= */ |
| 4075 | 4112 | |