4040#elif defined(__mips__ )
4141#define zig_mips32
4242#define zig_mips
43+ #elif defined(__or1k__ )
44+ #define zig_or1k
4345#elif defined(__powerpc64__ )
4446#define zig_powerpc64
4547#define zig_powerpc
7274#elif defined (__x86_64__ ) || (defined(zig_msvc ) && defined(_M_X64 ))
7375#define zig_x86_64
7476#define zig_x86
77+ #elif defined(__I86__ )
78+ #define zig_x86_16
79+ #define zig_x86
7580#endif
7681
7782#if defined(zig_msvc ) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
8287#define zig_big_endian 1
8388#endif
8489
85- #if defined(_AIX )
86- #define zig_aix
87- #elif defined(__MACH__ )
90+ #if defined(__MACH__ )
8891#define zig_darwin
8992#elif defined(__DragonFly__ )
9093#define zig_dragonfly
114117#define zig_wasi
115118#elif defined(_WIN32 )
116119#define zig_windows
117- #elif defined(__MVS__ )
118- #define zig_zos
119120#endif
120121
121122#if defined(zig_windows )
122123#define zig_coff
123124#elif defined(__ELF__ )
124125#define zig_elf
125- #elif defined(zig_zos )
126- #define zig_goff
127126#elif defined(zig_darwin )
128127#define zig_macho
129- #elif defined(zig_aix )
130- #define zig_xcoff
131128#endif
132129
133130#define zig_concat (lhs , rhs ) lhs##rhs
390387#define zig_trap () __asm__ volatile(".word 0x0")
391388#elif defined(zig_mips )
392389#define zig_trap () __asm__ volatile(".word 0x3d")
390+ #elif defined(zig_or1k )
391+ #define zig_trap () __asm__ volatile("l.cust8")
393392#elif defined(zig_riscv )
394393#define zig_trap () __asm__ volatile("unimp")
395394#elif defined(zig_s390x )
396395#define zig_trap () __asm__ volatile("j 0x2")
397396#elif defined(zig_sparc )
398397#define zig_trap () __asm__ volatile("illtrap")
398+ #elif defined(zig_x86_16 )
399+ #define zig_trap () __asm__ volatile("int $0x3")
399400#elif defined(zig_x86 )
400401#define zig_trap () __asm__ volatile("ud2")
401402#else
422423#define zig_breakpoint () __asm__ volatile("break 0x0")
423424#elif defined(zig_mips )
424425#define zig_breakpoint () __asm__ volatile("break")
426+ #elif defined(zig_or1k )
427+ #define zig_breakpoint () __asm__ volatile("l.trap 0x0")
425428#elif defined(zig_powerpc )
426429#define zig_breakpoint () __asm__ volatile("trap")
427430#elif defined(zig_riscv )
@@ -804,15 +807,13 @@ static inline bool zig_addo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8
804807#endif
805808}
806809
807- zig_extern int32_t __addosi4 (int32_t lhs , int32_t rhs , int * overflow );
808810static inline bool zig_addo_i32 (int32_t * res , int32_t lhs , int32_t rhs , uint8_t bits ) {
809811#if zig_has_builtin (add_overflow ) || defined(zig_gcc )
810812 int32_t full_res ;
811813 bool overflow = __builtin_add_overflow (lhs , rhs , & full_res );
812814#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 ;
816817#endif
817818 * res = zig_wrap_i32 (full_res , bits );
818819 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
830831#endif
831832}
832833
833- zig_extern int64_t __addodi4 (int64_t lhs , int64_t rhs , int * overflow );
834834static inline bool zig_addo_i64 (int64_t * res , int64_t lhs , int64_t rhs , uint8_t bits ) {
835835#if zig_has_builtin (add_overflow ) || defined(zig_gcc )
836836 int64_t full_res ;
837837 bool overflow = __builtin_add_overflow (lhs , rhs , & full_res );
838838#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 ;
842841#endif
843842 * res = zig_wrap_i64 (full_res , bits );
844843 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
912911#endif
913912}
914913
915- zig_extern int32_t __subosi4 (int32_t lhs , int32_t rhs , int * overflow );
916914static inline bool zig_subo_i32 (int32_t * res , int32_t lhs , int32_t rhs , uint8_t bits ) {
917915#if zig_has_builtin (sub_overflow ) || defined(zig_gcc )
918916 int32_t full_res ;
919917 bool overflow = __builtin_sub_overflow (lhs , rhs , & full_res );
920918#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 ;
924921#endif
925922 * res = zig_wrap_i32 (full_res , bits );
926923 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
938935#endif
939936}
940937
941- zig_extern int64_t __subodi4 (int64_t lhs , int64_t rhs , int * overflow );
942938static inline bool zig_subo_i64 (int64_t * res , int64_t lhs , int64_t rhs , uint8_t bits ) {
943939#if zig_has_builtin (sub_overflow ) || defined(zig_gcc )
944940 int64_t full_res ;
945941 bool overflow = __builtin_sub_overflow (lhs , rhs , & full_res );
946942#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 ;
950945#endif
951946 * res = zig_wrap_i64 (full_res , bits );
952947 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
17501745#endif
17511746}
17521747
1753- zig_extern zig_i128 __addoti4 (zig_i128 lhs , zig_i128 rhs , int * overflow );
17541748static inline bool zig_addo_i128 (zig_i128 * res , zig_i128 lhs , zig_i128 rhs , uint8_t bits ) {
17551749#if zig_has_builtin (add_overflow )
17561750 zig_i128 full_res ;
17571751 bool overflow = __builtin_add_overflow (lhs , rhs , & full_res );
17581752#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 ;
17621755#endif
17631756 * res = zig_wrap_i128 (full_res , bits );
17641757 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
17761769#endif
17771770}
17781771
1779- zig_extern zig_i128 __suboti4 (zig_i128 lhs , zig_i128 rhs , int * overflow );
17801772static inline bool zig_subo_i128 (zig_i128 * res , zig_i128 lhs , zig_i128 rhs , uint8_t bits ) {
17811773#if zig_has_builtin (sub_overflow )
17821774 zig_i128 full_res ;
17831775 bool overflow = __builtin_sub_overflow (lhs , rhs , & full_res );
17841776#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 ;
17881779#endif
17891780 * res = zig_wrap_i128 (full_res , bits );
17901781 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) {
42134204#endif
42144205}
42154206
4216- #elif defined(zig_x86 )
4207+ #elif defined(zig_x86 ) && !defined( zig_x86_16 )
42174208
42184209static inline void zig_x86_cpuid (uint32_t leaf_id , uint32_t subid , uint32_t * eax , uint32_t * ebx , uint32_t * ecx , uint32_t * edx ) {
42194210#if defined(zig_msvc )
0 commit comments