Commit 5df5e2ed26
lib/zig.h
@@ -809,15 +809,13 @@ static inline bool zig_addo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8
#endif
}
-zig_extern int32_t __addosi4(int32_t lhs, int32_t rhs, int *overflow);
static inline bool zig_addo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) {
#if zig_has_builtin(add_overflow) || defined(zig_gcc)
int32_t full_res;
bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
#else
- int overflow_int;
- int32_t full_res = __addosi4(lhs, rhs, &overflow_int);
- bool overflow = overflow_int != 0;
+ int32_t full_res = (int32_t)((uint32_t)lhs + (uint32_t)rhs);
+ bool overflow = ((full_res ^ lhs) & (full_res ^ rhs)) < 0;
#endif
*res = zig_wrap_i32(full_res, bits);
return overflow || full_res < zig_minInt_i(32, bits) || full_res > zig_maxInt_i(32, bits);
@@ -835,15 +833,13 @@ static inline bool zig_addo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8
#endif
}
-zig_extern int64_t __addodi4(int64_t lhs, int64_t rhs, int *overflow);
static inline bool zig_addo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) {
#if zig_has_builtin(add_overflow) || defined(zig_gcc)
int64_t full_res;
bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
#else
- int overflow_int;
- int64_t full_res = __addodi4(lhs, rhs, &overflow_int);
- bool overflow = overflow_int != 0;
+ int64_t full_res = (int64_t)((uint64_t)lhs + (uint64_t)rhs);
+ bool overflow = ((full_res ^ lhs) & (full_res ^ rhs)) < 0;
#endif
*res = zig_wrap_i64(full_res, bits);
return overflow || full_res < zig_minInt_i(64, bits) || full_res > zig_maxInt_i(64, bits);
@@ -917,15 +913,13 @@ static inline bool zig_subo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8
#endif
}
-zig_extern int32_t __subosi4(int32_t lhs, int32_t rhs, int *overflow);
static inline bool zig_subo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) {
#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
int32_t full_res;
bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
#else
- int overflow_int;
- int32_t full_res = __subosi4(lhs, rhs, &overflow_int);
- bool overflow = overflow_int != 0;
+ int32_t full_res = (int32_t)((uint32_t)lhs - (uint32_t)rhs);
+ bool overflow = ((lhs ^ rhs) & (full_res ^ lhs)) < 0;
#endif
*res = zig_wrap_i32(full_res, bits);
return overflow || full_res < zig_minInt_i(32, bits) || full_res > zig_maxInt_i(32, bits);
@@ -943,15 +937,13 @@ static inline bool zig_subo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8
#endif
}
-zig_extern int64_t __subodi4(int64_t lhs, int64_t rhs, int *overflow);
static inline bool zig_subo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) {
#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
int64_t full_res;
bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
#else
- int overflow_int;
- int64_t full_res = __subodi4(lhs, rhs, &overflow_int);
- bool overflow = overflow_int != 0;
+ int64_t full_res = (int64_t)((uint64_t)lhs - (uint64_t)rhs);
+ bool overflow = ((lhs ^ rhs) & (full_res ^ lhs)) < 0;
#endif
*res = zig_wrap_i64(full_res, bits);
return overflow || full_res < zig_minInt_i(64, bits) || full_res > zig_maxInt_i(64, bits);
@@ -1755,15 +1747,13 @@ static inline bool zig_addo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, uint
#endif
}
-zig_extern zig_i128 __addoti4(zig_i128 lhs, zig_i128 rhs, int *overflow);
static inline bool zig_addo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) {
#if zig_has_builtin(add_overflow)
zig_i128 full_res;
bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
#else
- int overflow_int;
- zig_i128 full_res = __addoti4(lhs, rhs, &overflow_int);
- bool overflow = overflow_int != 0;
+ zig_i128 full_res = (zig_i128)((zig_u128)lhs + (zig_u128)rhs);
+ bool overflow = ((full_res ^ lhs) & (full_res ^ rhs)) < 0;
#endif
*res = zig_wrap_i128(full_res, bits);
return overflow || full_res < zig_minInt_i(128, bits) || full_res > zig_maxInt_i(128, bits);
@@ -1781,15 +1771,13 @@ static inline bool zig_subo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, uint
#endif
}
-zig_extern zig_i128 __suboti4(zig_i128 lhs, zig_i128 rhs, int *overflow);
static inline bool zig_subo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) {
#if zig_has_builtin(sub_overflow)
zig_i128 full_res;
bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
#else
- int overflow_int;
- zig_i128 full_res = __suboti4(lhs, rhs, &overflow_int);
- bool overflow = overflow_int != 0;
+ zig_i128 full_res = (zig_i128)((zig_u128)lhs - (zig_u128)rhs);
+ bool overflow = ((lhs ^ rhs) & (full_res ^ lhs)) < 0;
#endif
*res = zig_wrap_i128(full_res, bits);
return overflow || full_res < zig_minInt_i(128, bits) || full_res > zig_maxInt_i(128, bits);
stage1/zig.h
@@ -40,6 +40,8 @@
#elif defined(__mips__)
#define zig_mips32
#define zig_mips
+#elif defined(__or1k__)
+#define zig_or1k
#elif defined(__powerpc64__)
#define zig_powerpc64
#define zig_powerpc
@@ -72,6 +74,9 @@
#elif defined (__x86_64__) || (defined(zig_msvc) && defined(_M_X64))
#define zig_x86_64
#define zig_x86
+#elif defined(__I86__)
+#define zig_x86_16
+#define zig_x86
#endif
#if defined(zig_msvc) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
@@ -82,9 +87,7 @@
#define zig_big_endian 1
#endif
-#if defined(_AIX)
-#define zig_aix
-#elif defined(__MACH__)
+#if defined(__MACH__)
#define zig_darwin
#elif defined(__DragonFly__)
#define zig_dragonfly
@@ -114,20 +117,14 @@
#define zig_wasi
#elif defined(_WIN32)
#define zig_windows
-#elif defined(__MVS__)
-#define zig_zos
#endif
#if defined(zig_windows)
#define zig_coff
#elif defined(__ELF__)
#define zig_elf
-#elif defined(zig_zos)
-#define zig_goff
#elif defined(zig_darwin)
#define zig_macho
-#elif defined(zig_aix)
-#define zig_xcoff
#endif
#define zig_concat(lhs, rhs) lhs##rhs
@@ -390,12 +387,16 @@
#define zig_trap() __asm__ volatile(".word 0x0")
#elif defined(zig_mips)
#define zig_trap() __asm__ volatile(".word 0x3d")
+#elif defined(zig_or1k)
+#define zig_trap() __asm__ volatile("l.cust8")
#elif defined(zig_riscv)
#define zig_trap() __asm__ volatile("unimp")
#elif defined(zig_s390x)
#define zig_trap() __asm__ volatile("j 0x2")
#elif defined(zig_sparc)
#define zig_trap() __asm__ volatile("illtrap")
+#elif defined(zig_x86_16)
+#define zig_trap() __asm__ volatile("int $0x3")
#elif defined(zig_x86)
#define zig_trap() __asm__ volatile("ud2")
#else
@@ -422,6 +423,8 @@
#define zig_breakpoint() __asm__ volatile("break 0x0")
#elif defined(zig_mips)
#define zig_breakpoint() __asm__ volatile("break")
+#elif defined(zig_or1k)
+#define zig_breakpoint() __asm__ volatile("l.trap 0x0")
#elif defined(zig_powerpc)
#define zig_breakpoint() __asm__ volatile("trap")
#elif defined(zig_riscv)
@@ -804,15 +807,13 @@ static inline bool zig_addo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8
#endif
}
-zig_extern int32_t __addosi4(int32_t lhs, int32_t rhs, int *overflow);
static inline bool zig_addo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) {
#if zig_has_builtin(add_overflow) || defined(zig_gcc)
int32_t full_res;
bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
#else
- int overflow_int;
- int32_t full_res = __addosi4(lhs, rhs, &overflow_int);
- bool overflow = overflow_int != 0;
+ int32_t full_res = (int32_t)((uint32_t)lhs + (uint32_t)rhs);
+ bool overflow = ((full_res ^ lhs) & (full_res ^ rhs)) < 0;
#endif
*res = zig_wrap_i32(full_res, bits);
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
#endif
}
-zig_extern int64_t __addodi4(int64_t lhs, int64_t rhs, int *overflow);
static inline bool zig_addo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) {
#if zig_has_builtin(add_overflow) || defined(zig_gcc)
int64_t full_res;
bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
#else
- int overflow_int;
- int64_t full_res = __addodi4(lhs, rhs, &overflow_int);
- bool overflow = overflow_int != 0;
+ int64_t full_res = (int64_t)((uint64_t)lhs + (uint64_t)rhs);
+ bool overflow = ((full_res ^ lhs) & (full_res ^ rhs)) < 0;
#endif
*res = zig_wrap_i64(full_res, bits);
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
#endif
}
-zig_extern int32_t __subosi4(int32_t lhs, int32_t rhs, int *overflow);
static inline bool zig_subo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) {
#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
int32_t full_res;
bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
#else
- int overflow_int;
- int32_t full_res = __subosi4(lhs, rhs, &overflow_int);
- bool overflow = overflow_int != 0;
+ int32_t full_res = (int32_t)((uint32_t)lhs - (uint32_t)rhs);
+ bool overflow = ((lhs ^ rhs) & (full_res ^ lhs)) < 0;
#endif
*res = zig_wrap_i32(full_res, bits);
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
#endif
}
-zig_extern int64_t __subodi4(int64_t lhs, int64_t rhs, int *overflow);
static inline bool zig_subo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) {
#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
int64_t full_res;
bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
#else
- int overflow_int;
- int64_t full_res = __subodi4(lhs, rhs, &overflow_int);
- bool overflow = overflow_int != 0;
+ int64_t full_res = (int64_t)((uint64_t)lhs - (uint64_t)rhs);
+ bool overflow = ((lhs ^ rhs) & (full_res ^ lhs)) < 0;
#endif
*res = zig_wrap_i64(full_res, bits);
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
#endif
}
-zig_extern zig_i128 __addoti4(zig_i128 lhs, zig_i128 rhs, int *overflow);
static inline bool zig_addo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) {
#if zig_has_builtin(add_overflow)
zig_i128 full_res;
bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
#else
- int overflow_int;
- zig_i128 full_res = __addoti4(lhs, rhs, &overflow_int);
- bool overflow = overflow_int != 0;
+ zig_i128 full_res = (zig_i128)((zig_u128)lhs + (zig_u128)rhs);
+ bool overflow = ((full_res ^ lhs) & (full_res ^ rhs)) < 0;
#endif
*res = zig_wrap_i128(full_res, bits);
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
#endif
}
-zig_extern zig_i128 __suboti4(zig_i128 lhs, zig_i128 rhs, int *overflow);
static inline bool zig_subo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) {
#if zig_has_builtin(sub_overflow)
zig_i128 full_res;
bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
#else
- int overflow_int;
- zig_i128 full_res = __suboti4(lhs, rhs, &overflow_int);
- bool overflow = overflow_int != 0;
+ zig_i128 full_res = (zig_i128)((zig_u128)lhs - (zig_u128)rhs);
+ bool overflow = ((lhs ^ rhs) & (full_res ^ lhs)) < 0;
#endif
*res = zig_wrap_i128(full_res, bits);
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) {
#endif
}
-#elif defined(zig_x86)
+#elif defined(zig_x86) && !defined(zig_x86_16)
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) {
#if defined(zig_msvc)