| ... | ... | @@ -40,6 +40,8 @@ |
| 40 | 40 | #elif defined(__mips__) |
| 41 | 41 | #define zig_mips32 |
| 42 | 42 | #define zig_mips |
| 43 | #elif defined(__or1k__) |
| 44 | #define zig_or1k |
| 43 | 45 | #elif defined(__powerpc64__) |
| 44 | 46 | #define zig_powerpc64 |
| 45 | 47 | #define zig_powerpc |
| ... | ... | @@ -72,6 +74,9 @@ |
| 72 | 74 | #elif defined (__x86_64__) || (defined(zig_msvc) && defined(_M_X64)) |
| 73 | 75 | #define zig_x86_64 |
| 74 | 76 | #define zig_x86 |
| 77 | #elif defined(__I86__) |
| 78 | #define zig_x86_16 |
| 79 | #define zig_x86 |
| 75 | 80 | #endif |
| 76 | 81 | |
| 77 | 82 | #if defined(zig_msvc) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
| ... | ... | @@ -82,9 +87,7 @@ |
| 82 | 87 | #define zig_big_endian 1 |
| 83 | 88 | #endif |
| 84 | 89 | |
| 85 | | #if defined(_AIX) |
| 86 | | #define zig_aix |
| 87 | | #elif defined(__MACH__) |
| 90 | #if defined(__MACH__) |
| 88 | 91 | #define zig_darwin |
| 89 | 92 | #elif defined(__DragonFly__) |
| 90 | 93 | #define zig_dragonfly |
| ... | ... | @@ -114,20 +117,14 @@ |
| 114 | 117 | #define zig_wasi |
| 115 | 118 | #elif defined(_WIN32) |
| 116 | 119 | #define zig_windows |
| 117 | | #elif defined(__MVS__) |
| 118 | | #define zig_zos |
| 119 | 120 | #endif |
| 120 | 121 | |
| 121 | 122 | #if defined(zig_windows) |
| 122 | 123 | #define zig_coff |
| 123 | 124 | #elif defined(__ELF__) |
| 124 | 125 | #define zig_elf |
| 125 | | #elif defined(zig_zos) |
| 126 | | #define zig_goff |
| 127 | 126 | #elif defined(zig_darwin) |
| 128 | 127 | #define zig_macho |
| 129 | | #elif defined(zig_aix) |
| 130 | | #define zig_xcoff |
| 131 | 128 | #endif |
| 132 | 129 | |
| 133 | 130 | #define zig_concat(lhs, rhs) lhs##rhs |
| ... | ... | @@ -390,12 +387,16 @@ |
| 390 | 387 | #define zig_trap() __asm__ volatile(".word 0x0") |
| 391 | 388 | #elif defined(zig_mips) |
| 392 | 389 | #define zig_trap() __asm__ volatile(".word 0x3d") |
| 390 | #elif defined(zig_or1k) |
| 391 | #define zig_trap() __asm__ volatile("l.cust8") |
| 393 | 392 | #elif defined(zig_riscv) |
| 394 | 393 | #define zig_trap() __asm__ volatile("unimp") |
| 395 | 394 | #elif defined(zig_s390x) |
| 396 | 395 | #define zig_trap() __asm__ volatile("j 0x2") |
| 397 | 396 | #elif defined(zig_sparc) |
| 398 | 397 | #define zig_trap() __asm__ volatile("illtrap") |
| 398 | #elif defined(zig_x86_16) |
| 399 | #define zig_trap() __asm__ volatile("int $0x3") |
| 399 | 400 | #elif defined(zig_x86) |
| 400 | 401 | #define zig_trap() __asm__ volatile("ud2") |
| 401 | 402 | #else |
| ... | ... | @@ -422,6 +423,8 @@ |
| 422 | 423 | #define zig_breakpoint() __asm__ volatile("break 0x0") |
| 423 | 424 | #elif defined(zig_mips) |
| 424 | 425 | #define zig_breakpoint() __asm__ volatile("break") |
| 426 | #elif defined(zig_or1k) |
| 427 | #define zig_breakpoint() __asm__ volatile("l.trap 0x0") |
| 425 | 428 | #elif defined(zig_powerpc) |
| 426 | 429 | #define zig_breakpoint() __asm__ volatile("trap") |
| 427 | 430 | #elif defined(zig_riscv) |
| ... | ... | @@ -804,15 +807,13 @@ static inline bool zig_addo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8 |
| 804 | 807 | #endif |
| 805 | 808 | } |
| 806 | 809 | |
| 807 | | zig_extern int32_t __addosi4(int32_t lhs, int32_t rhs, int *overflow); |
| 808 | 810 | static inline bool zig_addo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) { |
| 809 | 811 | #if zig_has_builtin(add_overflow) || defined(zig_gcc) |
| 810 | 812 | int32_t full_res; |
| 811 | 813 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 812 | 814 | #else |
| 813 | | int overflow_int; |
| 814 | | int32_t full_res = __addosi4(lhs, rhs, &overflow_int); |
| 815 | | bool overflow = overflow_int != 0; |
| 815 | int32_t full_res = (int32_t)((uint32_t)lhs + (uint32_t)rhs); |
| 816 | bool overflow = ((full_res ^ lhs) & (full_res ^ rhs)) < 0; |
| 816 | 817 | #endif |
| 817 | 818 | *res = zig_wrap_i32(full_res, bits); |
| 818 | 819 | return overflow || full_res < zig_minInt_i(32, bits) || full_res > zig_maxInt_i(32, bits); |
| ... | ... | @@ -830,15 +831,13 @@ static inline bool zig_addo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8 |
| 830 | 831 | #endif |
| 831 | 832 | } |
| 832 | 833 | |
| 833 | | zig_extern int64_t __addodi4(int64_t lhs, int64_t rhs, int *overflow); |
| 834 | 834 | static inline bool zig_addo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) { |
| 835 | 835 | #if zig_has_builtin(add_overflow) || defined(zig_gcc) |
| 836 | 836 | int64_t full_res; |
| 837 | 837 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 838 | 838 | #else |
| 839 | | int overflow_int; |
| 840 | | int64_t full_res = __addodi4(lhs, rhs, &overflow_int); |
| 841 | | bool overflow = overflow_int != 0; |
| 839 | int64_t full_res = (int64_t)((uint64_t)lhs + (uint64_t)rhs); |
| 840 | bool overflow = ((full_res ^ lhs) & (full_res ^ rhs)) < 0; |
| 842 | 841 | #endif |
| 843 | 842 | *res = zig_wrap_i64(full_res, bits); |
| 844 | 843 | return overflow || full_res < zig_minInt_i(64, bits) || full_res > zig_maxInt_i(64, bits); |
| ... | ... | @@ -912,15 +911,13 @@ static inline bool zig_subo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8 |
| 912 | 911 | #endif |
| 913 | 912 | } |
| 914 | 913 | |
| 915 | | zig_extern int32_t __subosi4(int32_t lhs, int32_t rhs, int *overflow); |
| 916 | 914 | static inline bool zig_subo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) { |
| 917 | 915 | #if zig_has_builtin(sub_overflow) || defined(zig_gcc) |
| 918 | 916 | int32_t full_res; |
| 919 | 917 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 920 | 918 | #else |
| 921 | | int overflow_int; |
| 922 | | int32_t full_res = __subosi4(lhs, rhs, &overflow_int); |
| 923 | | bool overflow = overflow_int != 0; |
| 919 | int32_t full_res = (int32_t)((uint32_t)lhs - (uint32_t)rhs); |
| 920 | bool overflow = ((lhs ^ rhs) & (full_res ^ lhs)) < 0; |
| 924 | 921 | #endif |
| 925 | 922 | *res = zig_wrap_i32(full_res, bits); |
| 926 | 923 | return overflow || full_res < zig_minInt_i(32, bits) || full_res > zig_maxInt_i(32, bits); |
| ... | ... | @@ -938,15 +935,13 @@ static inline bool zig_subo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8 |
| 938 | 935 | #endif |
| 939 | 936 | } |
| 940 | 937 | |
| 941 | | zig_extern int64_t __subodi4(int64_t lhs, int64_t rhs, int *overflow); |
| 942 | 938 | static inline bool zig_subo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) { |
| 943 | 939 | #if zig_has_builtin(sub_overflow) || defined(zig_gcc) |
| 944 | 940 | int64_t full_res; |
| 945 | 941 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 946 | 942 | #else |
| 947 | | int overflow_int; |
| 948 | | int64_t full_res = __subodi4(lhs, rhs, &overflow_int); |
| 949 | | bool overflow = overflow_int != 0; |
| 943 | int64_t full_res = (int64_t)((uint64_t)lhs - (uint64_t)rhs); |
| 944 | bool overflow = ((lhs ^ rhs) & (full_res ^ lhs)) < 0; |
| 950 | 945 | #endif |
| 951 | 946 | *res = zig_wrap_i64(full_res, bits); |
| 952 | 947 | return overflow || full_res < zig_minInt_i(64, bits) || full_res > zig_maxInt_i(64, bits); |
| ... | ... | @@ -1750,15 +1745,13 @@ static inline bool zig_addo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, uint |
| 1750 | 1745 | #endif |
| 1751 | 1746 | } |
| 1752 | 1747 | |
| 1753 | | zig_extern zig_i128 __addoti4(zig_i128 lhs, zig_i128 rhs, int *overflow); |
| 1754 | 1748 | static inline bool zig_addo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1755 | 1749 | #if zig_has_builtin(add_overflow) |
| 1756 | 1750 | zig_i128 full_res; |
| 1757 | 1751 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 1758 | 1752 | #else |
| 1759 | | int overflow_int; |
| 1760 | | zig_i128 full_res = __addoti4(lhs, rhs, &overflow_int); |
| 1761 | | bool overflow = overflow_int != 0; |
| 1753 | zig_i128 full_res = (zig_i128)((zig_u128)lhs + (zig_u128)rhs); |
| 1754 | bool overflow = ((full_res ^ lhs) & (full_res ^ rhs)) < 0; |
| 1762 | 1755 | #endif |
| 1763 | 1756 | *res = zig_wrap_i128(full_res, bits); |
| 1764 | 1757 | return overflow || full_res < zig_minInt_i(128, bits) || full_res > zig_maxInt_i(128, bits); |
| ... | ... | @@ -1776,15 +1769,13 @@ static inline bool zig_subo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, uint |
| 1776 | 1769 | #endif |
| 1777 | 1770 | } |
| 1778 | 1771 | |
| 1779 | | zig_extern zig_i128 __suboti4(zig_i128 lhs, zig_i128 rhs, int *overflow); |
| 1780 | 1772 | static inline bool zig_subo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1781 | 1773 | #if zig_has_builtin(sub_overflow) |
| 1782 | 1774 | zig_i128 full_res; |
| 1783 | 1775 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 1784 | 1776 | #else |
| 1785 | | int overflow_int; |
| 1786 | | zig_i128 full_res = __suboti4(lhs, rhs, &overflow_int); |
| 1787 | | bool overflow = overflow_int != 0; |
| 1777 | zig_i128 full_res = (zig_i128)((zig_u128)lhs - (zig_u128)rhs); |
| 1778 | bool overflow = ((lhs ^ rhs) & (full_res ^ lhs)) < 0; |
| 1788 | 1779 | #endif |
| 1789 | 1780 | *res = zig_wrap_i128(full_res, bits); |
| 1790 | 1781 | return overflow || full_res < zig_minInt_i(128, bits) || full_res > zig_maxInt_i(128, bits); |
| ... | ... | @@ -4213,7 +4204,7 @@ static inline void zig_loongarch_cpucfg(uint32_t word, uint32_t* result) { |
| 4213 | 4204 | #endif |
| 4214 | 4205 | } |
| 4215 | 4206 | |
| 4216 | | #elif defined(zig_x86) |
| 4207 | #elif defined(zig_x86) && !defined(zig_x86_16) |
| 4217 | 4208 | |
| 4218 | 4209 | static inline void zig_x86_cpuid(uint32_t leaf_id, uint32_t subid, uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx) { |
| 4219 | 4210 | #if defined(zig_msvc) |