authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-04-21 19:08:43-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-04-21 23:08:48-04:00
log5feb27c126bd25e6cdc93c390d90c4450076e75c
treebfd9230f2d456cfb433944feabeb9a3dbfe29962
parentd56c6c77913a6d560b7d3ebd6283cbf71d5a0222

zig.h: fix float negation


2 files changed, 78 insertions(+), 103 deletions(-)

lib/zig.h+74-99
...@@ -434,24 +434,24 @@ typedef ptrdiff_t intptr_t;...@@ -434,24 +434,24 @@ typedef ptrdiff_t intptr_t;
434#define zig_minInt_u(w, bits) zig_intLimit(u, w, min, bits)434#define zig_minInt_u(w, bits) zig_intLimit(u, w, min, bits)
435#define zig_maxInt_u(w, bits) zig_intLimit(u, w, max, bits)435#define zig_maxInt_u(w, bits) zig_intLimit(u, w, max, bits)
436436
437#define zig_int_operator(Type, RhsType, operation, operator) \437#define zig_operator(Type, RhsType, operation, operator) \
438 static inline Type zig_##operation(Type lhs, RhsType rhs) { \438 static inline Type zig_##operation(Type lhs, RhsType rhs) { \
439 return lhs operator rhs; \439 return lhs operator rhs; \
440 }440 }
441#define zig_int_basic_operator(Type, operation, operator) \441#define zig_basic_operator(Type, operation, operator) \
442 zig_int_operator(Type, Type, operation, operator)442 zig_operator(Type, Type, operation, operator)
443#define zig_int_shift_operator(Type, operation, operator) \443#define zig_shift_operator(Type, operation, operator) \
444 zig_int_operator(Type, uint8_t, operation, operator)444 zig_operator(Type, uint8_t, operation, operator)
445#define zig_int_helpers(w) \445#define zig_int_helpers(w) \
446 zig_int_basic_operator(uint##w##_t, and_u##w, &) \446 zig_basic_operator(uint##w##_t, and_u##w, &) \
447 zig_int_basic_operator( int##w##_t, and_i##w, &) \447 zig_basic_operator( int##w##_t, and_i##w, &) \
448 zig_int_basic_operator(uint##w##_t, or_u##w, |) \448 zig_basic_operator(uint##w##_t, or_u##w, |) \
449 zig_int_basic_operator( int##w##_t, or_i##w, |) \449 zig_basic_operator( int##w##_t, or_i##w, |) \
450 zig_int_basic_operator(uint##w##_t, xor_u##w, ^) \450 zig_basic_operator(uint##w##_t, xor_u##w, ^) \
451 zig_int_basic_operator( int##w##_t, xor_i##w, ^) \451 zig_basic_operator( int##w##_t, xor_i##w, ^) \
452 zig_int_shift_operator(uint##w##_t, shl_u##w, <<) \452 zig_shift_operator(uint##w##_t, shl_u##w, <<) \
453 zig_int_shift_operator( int##w##_t, shl_i##w, <<) \453 zig_shift_operator( int##w##_t, shl_i##w, <<) \
454 zig_int_shift_operator(uint##w##_t, shr_u##w, >>) \454 zig_shift_operator(uint##w##_t, shr_u##w, >>) \
455\455\
456 static inline int##w##_t zig_shr_i##w(int##w##_t lhs, uint8_t rhs) { \456 static inline int##w##_t zig_shr_i##w(int##w##_t lhs, uint8_t rhs) { \
457 int##w##_t sign_mask = lhs < INT##w##_C(0) ? -INT##w##_C(1) : INT##w##_C(0); \457 int##w##_t sign_mask = lhs < INT##w##_C(0) ? -INT##w##_C(1) : INT##w##_C(0); \
...@@ -476,13 +476,13 @@ typedef ptrdiff_t intptr_t;...@@ -476,13 +476,13 @@ typedef ptrdiff_t intptr_t;
476 ? val | zig_minInt_i(w, bits) : val & zig_maxInt_i(w, bits); \476 ? val | zig_minInt_i(w, bits) : val & zig_maxInt_i(w, bits); \
477 } \477 } \
478\478\
479 zig_int_basic_operator(uint##w##_t, div_floor_u##w, /) \479 zig_basic_operator(uint##w##_t, div_floor_u##w, /) \
480\480\
481 static inline int##w##_t zig_div_floor_i##w(int##w##_t lhs, int##w##_t rhs) { \481 static inline int##w##_t zig_div_floor_i##w(int##w##_t lhs, int##w##_t rhs) { \
482 return lhs / rhs - (((lhs ^ rhs) & (lhs % rhs)) < INT##w##_C(0)); \482 return lhs / rhs - (((lhs ^ rhs) & (lhs % rhs)) < INT##w##_C(0)); \
483 } \483 } \
484\484\
485 zig_int_basic_operator(uint##w##_t, mod_u##w, %) \485 zig_basic_operator(uint##w##_t, mod_u##w, %) \
486\486\
487 static inline int##w##_t zig_mod_i##w(int##w##_t lhs, int##w##_t rhs) { \487 static inline int##w##_t zig_mod_i##w(int##w##_t lhs, int##w##_t rhs) { \
488 int##w##_t rem = lhs % rhs; \488 int##w##_t rem = lhs % rhs; \
...@@ -1153,8 +1153,8 @@ typedef signed __int128 zig_i128;...@@ -1153,8 +1153,8 @@ typedef signed __int128 zig_i128;
1153#define zig_lo_u128(val) ((uint64_t)((val) >> 0))1153#define zig_lo_u128(val) ((uint64_t)((val) >> 0))
1154#define zig_hi_i128(val) (( int64_t)((val) >> 64))1154#define zig_hi_i128(val) (( int64_t)((val) >> 64))
1155#define zig_lo_i128(val) ((uint64_t)((val) >> 0))1155#define zig_lo_i128(val) ((uint64_t)((val) >> 0))
1156#define zig_bitcast_u128(val) ((zig_u128)(val))1156#define zig_bitCast_u128(val) ((zig_u128)(val))
1157#define zig_bitcast_i128(val) ((zig_i128)(val))1157#define zig_bitCast_i128(val) ((zig_i128)(val))
1158#define zig_cmp_int128(Type) \1158#define zig_cmp_int128(Type) \
1159 static inline int32_t zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \1159 static inline int32_t zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \
1160 return (lhs > rhs) - (lhs < rhs); \1160 return (lhs > rhs) - (lhs < rhs); \
...@@ -1188,8 +1188,8 @@ typedef struct { zig_align(16) int64_t hi; uint64_t lo; } zig_i128;...@@ -1188,8 +1188,8 @@ typedef struct { zig_align(16) int64_t hi; uint64_t lo; } zig_i128;
1188#define zig_lo_u128(val) ((val).lo)1188#define zig_lo_u128(val) ((val).lo)
1189#define zig_hi_i128(val) ((val).hi)1189#define zig_hi_i128(val) ((val).hi)
1190#define zig_lo_i128(val) ((val).lo)1190#define zig_lo_i128(val) ((val).lo)
1191#define zig_bitcast_u128(val) zig_make_u128((uint64_t)(val).hi, (val).lo)1191#define zig_bitCast_u128(val) zig_make_u128((uint64_t)(val).hi, (val).lo)
1192#define zig_bitcast_i128(val) zig_make_i128(( int64_t)(val).hi, (val).lo)1192#define zig_bitCast_i128(val) zig_make_i128(( int64_t)(val).hi, (val).lo)
1193#define zig_cmp_int128(Type) \1193#define zig_cmp_int128(Type) \
1194 static inline int32_t zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \1194 static inline int32_t zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \
1195 return (lhs.hi == rhs.hi) \1195 return (lhs.hi == rhs.hi) \
...@@ -1363,7 +1363,7 @@ static zig_i128 zig_mul_i128(zig_i128 lhs, zig_i128 rhs) {...@@ -1363,7 +1363,7 @@ static zig_i128 zig_mul_i128(zig_i128 lhs, zig_i128 rhs) {
1363}1363}
13641364
1365static zig_u128 zig_mul_u128(zig_u128 lhs, zig_u128 rhs) {1365static zig_u128 zig_mul_u128(zig_u128 lhs, zig_u128 rhs) {
1366 return zig_bitcast_u128(zig_mul_i128(zig_bitcast_i128(lhs), zig_bitcast_i128(rhs)));1366 return zig_bitCast_u128(zig_mul_i128(zig_bitCast_i128(lhs), zig_bitCast_i128(rhs)));
1367}1367}
13681368
1369zig_extern zig_u128 __udivti3(zig_u128 lhs, zig_u128 rhs);1369zig_extern zig_u128 __udivti3(zig_u128 lhs, zig_u128 rhs);
...@@ -1431,7 +1431,7 @@ static inline zig_u128 zig_shlw_u128(zig_u128 lhs, uint8_t rhs, uint8_t bits) {...@@ -1431,7 +1431,7 @@ static inline zig_u128 zig_shlw_u128(zig_u128 lhs, uint8_t rhs, uint8_t bits) {
1431}1431}
14321432
1433static inline zig_i128 zig_shlw_i128(zig_i128 lhs, uint8_t rhs, uint8_t bits) {1433static inline zig_i128 zig_shlw_i128(zig_i128 lhs, uint8_t rhs, uint8_t bits) {
1434 return zig_wrap_i128(zig_bitcast_i128(zig_shl_u128(zig_bitcast_u128(lhs), rhs)), bits);1434 return zig_wrap_i128(zig_bitCast_i128(zig_shl_u128(zig_bitCast_u128(lhs), rhs)), bits);
1435}1435}
14361436
1437static inline zig_u128 zig_addw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) {1437static inline zig_u128 zig_addw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) {
...@@ -1439,7 +1439,7 @@ static inline zig_u128 zig_addw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) {...@@ -1439,7 +1439,7 @@ static inline zig_u128 zig_addw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) {
1439}1439}
14401440
1441static inline zig_i128 zig_addw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) {1441static inline zig_i128 zig_addw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) {
1442 return zig_wrap_i128(zig_bitcast_i128(zig_add_u128(zig_bitcast_u128(lhs), zig_bitcast_u128(rhs))), bits);1442 return zig_wrap_i128(zig_bitCast_i128(zig_add_u128(zig_bitCast_u128(lhs), zig_bitCast_u128(rhs))), bits);
1443}1443}
14441444
1445static inline zig_u128 zig_subw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) {1445static inline zig_u128 zig_subw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) {
...@@ -1447,7 +1447,7 @@ static inline zig_u128 zig_subw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) {...@@ -1447,7 +1447,7 @@ static inline zig_u128 zig_subw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) {
1447}1447}
14481448
1449static inline zig_i128 zig_subw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) {1449static inline zig_i128 zig_subw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) {
1450 return zig_wrap_i128(zig_bitcast_i128(zig_sub_u128(zig_bitcast_u128(lhs), zig_bitcast_u128(rhs))), bits);1450 return zig_wrap_i128(zig_bitCast_i128(zig_sub_u128(zig_bitCast_u128(lhs), zig_bitCast_u128(rhs))), bits);
1451}1451}
14521452
1453static inline zig_u128 zig_mulw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) {1453static inline zig_u128 zig_mulw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) {
...@@ -1455,7 +1455,7 @@ static inline zig_u128 zig_mulw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) {...@@ -1455,7 +1455,7 @@ static inline zig_u128 zig_mulw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) {
1455}1455}
14561456
1457static inline zig_i128 zig_mulw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) {1457static inline zig_i128 zig_mulw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) {
1458 return zig_wrap_i128(zig_bitcast_i128(zig_mul_u128(zig_bitcast_u128(lhs), zig_bitcast_u128(rhs))), bits);1458 return zig_wrap_i128(zig_bitCast_i128(zig_mul_u128(zig_bitCast_u128(lhs), zig_bitCast_u128(rhs))), bits);
1459}1459}
14601460
1461#if zig_has_int1281461#if zig_has_int128
...@@ -1590,7 +1590,7 @@ static inline bool zig_shlo_u128(zig_u128 *res, zig_u128 lhs, uint8_t rhs, uint8...@@ -1590,7 +1590,7 @@ static inline bool zig_shlo_u128(zig_u128 *res, zig_u128 lhs, uint8_t rhs, uint8
15901590
1591static inline bool zig_shlo_i128(zig_i128 *res, zig_i128 lhs, uint8_t rhs, uint8_t bits) {1591static inline bool zig_shlo_i128(zig_i128 *res, zig_i128 lhs, uint8_t rhs, uint8_t bits) {
1592 *res = zig_shlw_i128(lhs, rhs, bits);1592 *res = zig_shlw_i128(lhs, rhs, bits);
1593 zig_i128 mask = zig_bitcast_i128(zig_shl_u128(zig_maxInt_u128, bits - rhs - UINT8_C(1)));1593 zig_i128 mask = zig_bitCast_i128(zig_shl_u128(zig_maxInt_u128, bits - rhs - UINT8_C(1)));
1594 return zig_cmp_i128(zig_and_i128(lhs, mask), zig_make_i128(0, 0)) != INT32_C(0) &&1594 return zig_cmp_i128(zig_and_i128(lhs, mask), zig_make_i128(0, 0)) != INT32_C(0) &&
1595 zig_cmp_i128(zig_and_i128(lhs, mask), mask) != INT32_C(0);1595 zig_cmp_i128(zig_and_i128(lhs, mask), mask) != INT32_C(0);
1596}1596}
...@@ -1604,7 +1604,7 @@ static inline zig_u128 zig_shls_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) {...@@ -1604,7 +1604,7 @@ static inline zig_u128 zig_shls_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) {
16041604
1605static inline zig_i128 zig_shls_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) {1605static inline zig_i128 zig_shls_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) {
1606 zig_i128 res;1606 zig_i128 res;
1607 if (zig_cmp_u128(zig_bitcast_u128(rhs), zig_make_u128(0, bits)) < INT32_C(0) && !zig_shlo_i128(&res, lhs, (uint8_t)zig_lo_i128(rhs), bits)) return res;1607 if (zig_cmp_u128(zig_bitCast_u128(rhs), zig_make_u128(0, bits)) < INT32_C(0) && !zig_shlo_i128(&res, lhs, (uint8_t)zig_lo_i128(rhs), bits)) return res;
1608 return zig_cmp_i128(lhs, zig_make_i128(0, 0)) < INT32_C(0) ? zig_minInt_i(128, bits) : zig_maxInt_i(128, bits);1608 return zig_cmp_i128(lhs, zig_make_i128(0, 0)) < INT32_C(0) ? zig_minInt_i(128, bits) : zig_maxInt_i(128, bits);
1609}1609}
16101610
...@@ -1648,7 +1648,7 @@ static inline uint8_t zig_clz_u128(zig_u128 val, uint8_t bits) {...@@ -1648,7 +1648,7 @@ static inline uint8_t zig_clz_u128(zig_u128 val, uint8_t bits) {
1648}1648}
16491649
1650static inline uint8_t zig_clz_i128(zig_i128 val, uint8_t bits) {1650static inline uint8_t zig_clz_i128(zig_i128 val, uint8_t bits) {
1651 return zig_clz_u128(zig_bitcast_u128(val), bits);1651 return zig_clz_u128(zig_bitCast_u128(val), bits);
1652}1652}
16531653
1654static inline uint8_t zig_ctz_u128(zig_u128 val, uint8_t bits) {1654static inline uint8_t zig_ctz_u128(zig_u128 val, uint8_t bits) {
...@@ -1657,7 +1657,7 @@ static inline uint8_t zig_ctz_u128(zig_u128 val, uint8_t bits) {...@@ -1657,7 +1657,7 @@ static inline uint8_t zig_ctz_u128(zig_u128 val, uint8_t bits) {
1657}1657}
16581658
1659static inline uint8_t zig_ctz_i128(zig_i128 val, uint8_t bits) {1659static inline uint8_t zig_ctz_i128(zig_i128 val, uint8_t bits) {
1660 return zig_ctz_u128(zig_bitcast_u128(val), bits);1660 return zig_ctz_u128(zig_bitCast_u128(val), bits);
1661}1661}
16621662
1663static inline uint8_t zig_popcount_u128(zig_u128 val, uint8_t bits) {1663static inline uint8_t zig_popcount_u128(zig_u128 val, uint8_t bits) {
...@@ -1666,7 +1666,7 @@ static inline uint8_t zig_popcount_u128(zig_u128 val, uint8_t bits) {...@@ -1666,7 +1666,7 @@ static inline uint8_t zig_popcount_u128(zig_u128 val, uint8_t bits) {
1666}1666}
16671667
1668static inline uint8_t zig_popcount_i128(zig_i128 val, uint8_t bits) {1668static inline uint8_t zig_popcount_i128(zig_i128 val, uint8_t bits) {
1669 return zig_popcount_u128(zig_bitcast_u128(val), bits);1669 return zig_popcount_u128(zig_bitCast_u128(val), bits);
1670}1670}
16711671
1672static inline zig_u128 zig_byte_swap_u128(zig_u128 val, uint8_t bits) {1672static inline zig_u128 zig_byte_swap_u128(zig_u128 val, uint8_t bits) {
...@@ -1681,7 +1681,7 @@ static inline zig_u128 zig_byte_swap_u128(zig_u128 val, uint8_t bits) {...@@ -1681,7 +1681,7 @@ static inline zig_u128 zig_byte_swap_u128(zig_u128 val, uint8_t bits) {
1681}1681}
16821682
1683static inline zig_i128 zig_byte_swap_i128(zig_i128 val, uint8_t bits) {1683static inline zig_i128 zig_byte_swap_i128(zig_i128 val, uint8_t bits) {
1684 return zig_bitcast_i128(zig_byte_swap_u128(zig_bitcast_u128(val), bits));1684 return zig_bitCast_i128(zig_byte_swap_u128(zig_bitCast_u128(val), bits));
1685}1685}
16861686
1687static inline zig_u128 zig_bit_reverse_u128(zig_u128 val, uint8_t bits) {1687static inline zig_u128 zig_bit_reverse_u128(zig_u128 val, uint8_t bits) {
...@@ -1691,7 +1691,7 @@ static inline zig_u128 zig_bit_reverse_u128(zig_u128 val, uint8_t bits) {...@@ -1691,7 +1691,7 @@ static inline zig_u128 zig_bit_reverse_u128(zig_u128 val, uint8_t bits) {
1691}1691}
16921692
1693static inline zig_i128 zig_bit_reverse_i128(zig_i128 val, uint8_t bits) {1693static inline zig_i128 zig_bit_reverse_i128(zig_i128 val, uint8_t bits) {
1694 return zig_bitcast_i128(zig_bit_reverse_u128(zig_bitcast_u128(val), bits));1694 return zig_bitCast_i128(zig_bit_reverse_u128(zig_bitCast_u128(val), bits));
1695}1695}
16961696
1697/* ========================== Big Integer Support =========================== */1697/* ========================== Big Integer Support =========================== */
...@@ -2957,24 +2957,20 @@ long double __cdecl nanl(char const* input);...@@ -2957,24 +2957,20 @@ long double __cdecl nanl(char const* input);
2957#endif2957#endif
29582958
2959#if (zig_has_builtin(nan) && zig_has_builtin(nans) && zig_has_builtin(inf)) || defined(zig_gnuc)2959#if (zig_has_builtin(nan) && zig_has_builtin(nans) && zig_has_builtin(inf)) || defined(zig_gnuc)
2960#define zig_has_float_builtins 12960#define zig_make_special_f16(sign, name, arg, repr) sign zig_make_f16 (__builtin_##name, )(arg)
2961#define zig_make_special_f16(sign, name, arg, repr) sign zig_make_f16(__builtin_##name, )(arg)2961#define zig_make_special_f32(sign, name, arg, repr) sign zig_make_f32 (__builtin_##name, )(arg)
2962#define zig_make_special_f32(sign, name, arg, repr) sign zig_make_f32(__builtin_##name, )(arg)2962#define zig_make_special_f64(sign, name, arg, repr) sign zig_make_f64 (__builtin_##name, )(arg)
2963#define zig_make_special_f64(sign, name, arg, repr) sign zig_make_f64(__builtin_##name, )(arg)2963#define zig_make_special_f80(sign, name, arg, repr) sign zig_make_f80 (__builtin_##name, )(arg)
2964#define zig_make_special_f80(sign, name, arg, repr) sign zig_make_f80(__builtin_##name, )(arg)
2965#define zig_make_special_f128(sign, name, arg, repr) sign zig_make_f128(__builtin_##name, )(arg)2964#define zig_make_special_f128(sign, name, arg, repr) sign zig_make_f128(__builtin_##name, )(arg)
2966#else2965#else
2967#define zig_has_float_builtins 02966#define zig_make_special_f16(sign, name, arg, repr) zig_bitCast_f16 (repr)
2968#define zig_make_special_f16(sign, name, arg, repr) zig_float_from_repr_f16(repr)2967#define zig_make_special_f32(sign, name, arg, repr) zig_bitCast_f32 (repr)
2969#define zig_make_special_f32(sign, name, arg, repr) zig_float_from_repr_f32(repr)2968#define zig_make_special_f64(sign, name, arg, repr) zig_bitCast_f64 (repr)
2970#define zig_make_special_f64(sign, name, arg, repr) zig_float_from_repr_f64(repr)2969#define zig_make_special_f80(sign, name, arg, repr) zig_bitCast_f80 (repr)
2971#define zig_make_special_f80(sign, name, arg, repr) zig_float_from_repr_f80(repr)2970#define zig_make_special_f128(sign, name, arg, repr) zig_bitCast_f128(repr)
2972#define zig_make_special_f128(sign, name, arg, repr) zig_float_from_repr_f128(repr)
2973#endif2971#endif
29742972
2975#define zig_has_f16 12973#define zig_has_f16 1
2976#define zig_bitSizeOf_f16 16
2977typedef uint16_t zig_repr_f16;
2978#define zig_libc_name_f16(name) __##name##h2974#define zig_libc_name_f16(name) __##name##h
2979#define zig_init_special_f16(sign, name, arg, repr) zig_make_special_f16(sign, name, arg, repr)2975#define zig_init_special_f16(sign, name, arg, repr) zig_make_special_f16(sign, name, arg, repr)
2980#if FLT_MANT_DIG == 112976#if FLT_MANT_DIG == 11
...@@ -2995,7 +2991,8 @@ typedef __fp16 zig_f16;...@@ -2995,7 +2991,8 @@ typedef __fp16 zig_f16;
2995#else2991#else
2996#undef zig_has_f162992#undef zig_has_f16
2997#define zig_has_f16 02993#define zig_has_f16 0
2998typedef zig_repr_f16 zig_f16;2994#define zig_repr_f16 u16
2995typedef uint16_t zig_f16;
2999#define zig_make_f16(fp, repr) repr2996#define zig_make_f16(fp, repr) repr
3000#undef zig_make_special_f162997#undef zig_make_special_f16
3001#define zig_make_special_f16(sign, name, arg, repr) repr2998#define zig_make_special_f16(sign, name, arg, repr) repr
...@@ -3003,14 +3000,12 @@ typedef zig_repr_f16 zig_f16;...@@ -3003,14 +3000,12 @@ typedef zig_repr_f16 zig_f16;
3003#define zig_init_special_f16(sign, name, arg, repr) repr3000#define zig_init_special_f16(sign, name, arg, repr) repr
3004#endif3001#endif
3005#if __APPLE__ && (defined(__i386__) || defined(__x86_64__))3002#if __APPLE__ && (defined(__i386__) || defined(__x86_64__))
3006typedef zig_repr_f16 zig_compiler_rt_f16;3003typedef uint16_t zig_compiler_rt_f16;
3007#else3004#else
3008typedef zig_f16 zig_compiler_rt_f16;3005typedef zig_f16 zig_compiler_rt_f16;
3009#endif3006#endif
30103007
3011#define zig_has_f32 13008#define zig_has_f32 1
3012#define zig_bitSizeOf_f32 32
3013typedef uint32_t zig_repr_f32;
3014#define zig_libc_name_f32(name) name##f3009#define zig_libc_name_f32(name) name##f
3015#if _MSC_VER3010#if _MSC_VER
3016#define zig_init_special_f32(sign, name, arg, repr) sign zig_make_f32(zig_msvc_flt_##name, )3011#define zig_init_special_f32(sign, name, arg, repr) sign zig_make_f32(zig_msvc_flt_##name, )
...@@ -3032,7 +3027,8 @@ typedef _Float32 zig_f32;...@@ -3032,7 +3027,8 @@ typedef _Float32 zig_f32;
3032#else3027#else
3033#undef zig_has_f323028#undef zig_has_f32
3034#define zig_has_f32 03029#define zig_has_f32 0
3035typedef zig_repr_f32 zig_f32;3030#define zig_repr_f32 u32
3031ypedef uint32_t zig_f32;
3036#define zig_make_f32(fp, repr) repr3032#define zig_make_f32(fp, repr) repr
3037#undef zig_make_special_f323033#undef zig_make_special_f32
3038#define zig_make_special_f32(sign, name, arg, repr) repr3034#define zig_make_special_f32(sign, name, arg, repr) repr
...@@ -3041,8 +3037,6 @@ typedef zig_repr_f32 zig_f32;...@@ -3041,8 +3037,6 @@ typedef zig_repr_f32 zig_f32;
3041#endif3037#endif
30423038
3043#define zig_has_f64 13039#define zig_has_f64 1
3044#define zig_bitSizeOf_f64 64
3045typedef uint64_t zig_repr_f64;
3046#define zig_libc_name_f64(name) name3040#define zig_libc_name_f64(name) name
3047#if _MSC_VER3041#if _MSC_VER
3048#define zig_init_special_f64(sign, name, arg, repr) sign zig_make_f64(zig_msvc_flt_##name, )3042#define zig_init_special_f64(sign, name, arg, repr) sign zig_make_f64(zig_msvc_flt_##name, )
...@@ -3067,7 +3061,8 @@ typedef _Float32x zig_f64;...@@ -3067,7 +3061,8 @@ typedef _Float32x zig_f64;
3067#else3061#else
3068#undef zig_has_f643062#undef zig_has_f64
3069#define zig_has_f64 03063#define zig_has_f64 0
3070typedef zig_repr_f64 zig_f64;3064#define zig_repr_f64 u64
3065typedef uint64_t zig_f64;
3071#define zig_make_f64(fp, repr) repr3066#define zig_make_f64(fp, repr) repr
3072#undef zig_make_special_f643067#undef zig_make_special_f64
3073#define zig_make_special_f64(sign, name, arg, repr) repr3068#define zig_make_special_f64(sign, name, arg, repr) repr
...@@ -3076,8 +3071,6 @@ typedef zig_repr_f64 zig_f64;...@@ -3076,8 +3071,6 @@ typedef zig_repr_f64 zig_f64;
3076#endif3071#endif
30773072
3078#define zig_has_f80 13073#define zig_has_f80 1
3079#define zig_bitSizeOf_f80 80
3080typedef zig_u128 zig_repr_f80;
3081#define zig_libc_name_f80(name) __##name##x3074#define zig_libc_name_f80(name) __##name##x
3082#define zig_init_special_f80(sign, name, arg, repr) zig_make_special_f80(sign, name, arg, repr)3075#define zig_init_special_f80(sign, name, arg, repr) zig_make_special_f80(sign, name, arg, repr)
3083#if FLT_MANT_DIG == 643076#if FLT_MANT_DIG == 64
...@@ -3101,7 +3094,8 @@ typedef __float80 zig_f80;...@@ -3101,7 +3094,8 @@ typedef __float80 zig_f80;
3101#else3094#else
3102#undef zig_has_f803095#undef zig_has_f80
3103#define zig_has_f80 03096#define zig_has_f80 0
3104typedef zig_repr_f80 zig_f80;3097#define zig_repr_f80 u128
3098typedef zig_u128 zig_f80;
3105#define zig_make_f80(fp, repr) repr3099#define zig_make_f80(fp, repr) repr
3106#undef zig_make_special_f803100#undef zig_make_special_f80
3107#define zig_make_special_f80(sign, name, arg, repr) repr3101#define zig_make_special_f80(sign, name, arg, repr) repr
...@@ -3110,8 +3104,6 @@ typedef zig_repr_f80 zig_f80;...@@ -3110,8 +3104,6 @@ typedef zig_repr_f80 zig_f80;
3110#endif3104#endif
31113105
3112#define zig_has_f128 13106#define zig_has_f128 1
3113#define zig_bitSizeOf_f128 128
3114typedef zig_u128 zig_repr_f128;
3115#define zig_libc_name_f128(name) name##q3107#define zig_libc_name_f128(name) name##q
3116#define zig_init_special_f128(sign, name, arg, repr) zig_make_special_f128(sign, name, arg, repr)3108#define zig_init_special_f128(sign, name, arg, repr) zig_make_special_f128(sign, name, arg, repr)
3117#if FLT_MANT_DIG == 1133109#if FLT_MANT_DIG == 113
...@@ -3140,14 +3132,18 @@ typedef __float128 zig_f128;...@@ -3140,14 +3132,18 @@ typedef __float128 zig_f128;
3140#undef zig_make_special_f1283132#undef zig_make_special_f128
3141#undef zig_init_special_f1283133#undef zig_init_special_f128
3142#if __APPLE__ || defined(__aarch64__)3134#if __APPLE__ || defined(__aarch64__)
3143typedef __attribute__((__vector_size__(16))) uint64_t zig_f128;3135typedef __attribute__((__vector_size__(2 * sizeof(uint64_t)))) uint64_t zig_v2u64;
3136zig_basic_operator(zig_v2u64, xor_v2u64, ^)
3137#define zig_repr_f128 v2u64
3138typedef zig_v2u64 zig_f128;
3144#define zig_make_f128_zig_make_u128(hi, lo) (zig_f128){ lo, hi }3139#define zig_make_f128_zig_make_u128(hi, lo) (zig_f128){ lo, hi }
3145#define zig_make_f128_zig_init_u128 zig_make_f128_zig_make_u1283140#define zig_make_f128_zig_init_u128 zig_make_f128_zig_make_u128
3146#define zig_make_f128(fp, repr) zig_make_f128_##repr3141#define zig_make_f128(fp, repr) zig_make_f128_##repr
3147#define zig_make_special_f128(sign, name, arg, repr) zig_make_f128_##repr3142#define zig_make_special_f128(sign, name, arg, repr) zig_make_f128_##repr
3148#define zig_init_special_f128(sign, name, arg, repr) zig_make_f128_##repr3143#define zig_init_special_f128(sign, name, arg, repr) zig_make_f128_##repr
3149#else3144#else
3150typedef zig_repr_f128 zig_f128;3145#define zig_repr_f128 u128
3146typedef zig_u128 zig_f128;
3151#define zig_make_f128(fp, repr) repr3147#define zig_make_f128(fp, repr) repr
3152#define zig_make_special_f128(sign, name, arg, repr) repr3148#define zig_make_special_f128(sign, name, arg, repr) repr
3153#define zig_init_special_f128(sign, name, arg, repr) repr3149#define zig_init_special_f128(sign, name, arg, repr) repr
...@@ -3156,48 +3152,26 @@ typedef zig_repr_f128 zig_f128;...@@ -3156,48 +3152,26 @@ typedef zig_repr_f128 zig_f128;
31563152
3157#if !_MSC_VER && defined(ZIG_TARGET_ABI_MSVC)3153#if !_MSC_VER && defined(ZIG_TARGET_ABI_MSVC)
3158/* Emulate msvc abi on a gnu compiler */3154/* Emulate msvc abi on a gnu compiler */
3159#define zig_bitSizeOf_c_longdouble 64
3160typedef zig_repr_f64 zig_repr_c_longdouble;
3161typedef zig_f64 zig_c_longdouble;3155typedef zig_f64 zig_c_longdouble;
3162#elif _MSC_VER && !defined(ZIG_TARGET_ABI_MSVC)3156#elif _MSC_VER && !defined(ZIG_TARGET_ABI_MSVC)
3163/* Emulate gnu abi on an msvc compiler */3157/* Emulate gnu abi on an msvc compiler */
3164#define zig_bitSizeOf_c_longdouble 128
3165typedef zig_repr_f128 zig_repr_c_longdouble;
3166typedef zig_f128 zig_c_longdouble;3158typedef zig_f128 zig_c_longdouble;
3167#else3159#else
3168#if LDBL_MANT_DIG == 113160/* Target and compiler abi match */
3169#define zig_bitSizeOf_c_longdouble 16
3170typedef zig_repr_f16 zig_repr_c_longdouble;
3171#elif LDBL_MANT_DIG == 24
3172#define zig_bitSizeOf_c_longdouble 32
3173typedef zig_repr_f32 zig_repr_c_longdouble;
3174#elif LDBL_MANT_DIG == 53
3175#define zig_bitSizeOf_c_longdouble 64
3176typedef zig_repr_f64 zig_repr_c_longdouble;
3177#elif LDBL_MANT_DIG == 64
3178#define zig_bitSizeOf_c_longdouble 80
3179typedef zig_repr_f80 zig_repr_c_longdouble;
3180#elif LDBL_MANT_DIG == 113
3181#define zig_bitSizeOf_c_longdouble 128
3182typedef zig_repr_f128 zig_repr_c_longdouble;
3183#endif
3184typedef long double zig_c_longdouble;3161typedef long double zig_c_longdouble;
3185#endif3162#endif
31863163
3187#if !zig_has_float_builtins3164#define zig_bitCast_float(Type, ReprType) \
3188#define zig_float_from_repr(Type) \3165 static inline zig_##Type zig_bitCast_##Type(ReprType repr) { \
3189 static inline zig_##Type zig_float_from_repr_##Type(zig_repr_##Type repr) { \
3190 zig_##Type result; \3166 zig_##Type result; \
3191 memcpy(&result, &repr, sizeof(result)); \3167 memcpy(&result, &repr, sizeof(result)); \
3192 return result; \3168 return result; \
3193 }3169 }
31943170zig_bitCast_float(f16, uint16_t)
3195zig_float_from_repr(f16)3171zig_bitCast_float(f32, uint32_t)
3196zig_float_from_repr(f32)3172zig_bitCast_float(f64, uint64_t)
3197zig_float_from_repr(f64)3173zig_bitCast_float(f80, zig_u128)
3198zig_float_from_repr(f80)3174zig_bitCast_float(f128, zig_u128)
3199zig_float_from_repr(f128)
3200#endif
32013175
3202#define zig_cast_f16 (zig_f16)3176#define zig_cast_f16 (zig_f16)
3203#define zig_cast_f32 (zig_f32)3177#define zig_cast_f32 (zig_f32)
...@@ -3246,17 +3220,18 @@ zig_convert_builtin(zig_f128, zig_f128, extend, zig_f32,...@@ -3246,17 +3220,18 @@ zig_convert_builtin(zig_f128, zig_f128, extend, zig_f32,
3246zig_convert_builtin(zig_f128, zig_f128, extend, zig_f64, zig_f64, 2)3220zig_convert_builtin(zig_f128, zig_f128, extend, zig_f64, zig_f64, 2)
3247zig_convert_builtin(zig_f128, zig_f128, extend, zig_f80, zig_f80, 2)3221zig_convert_builtin(zig_f128, zig_f128, extend, zig_f80, zig_f80, 2)
32483222
3249#define zig_float_negate_builtin_0(w, r, c, sb) zig_xor_u##r(arg, zig_make_f##w(-0x0.0p0, c sb))3223#define zig_float_negate_builtin_0(w, c, sb) \
3250#define zig_float_negate_builtin_1(w, r, c, sb) -arg3224 zig_expand_concat(zig_xor_, zig_repr_f##w)(arg, zig_make_f##w(-0x0.0p0, c sb))
3251#define zig_float_negate_builtin(w, r, c, sb) \3225#define zig_float_negate_builtin_1(w, c, sb) -arg
3226#define zig_float_negate_builtin(w, c, sb) \
3252 static inline zig_f##w zig_neg_f##w(zig_f##w arg) { \3227 static inline zig_f##w zig_neg_f##w(zig_f##w arg) { \
3253 return zig_expand_concat(zig_float_negate_builtin_, zig_has_f##w)(w, r, c, sb); \3228 return zig_expand_concat(zig_float_negate_builtin_, zig_has_f##w)(w, c, sb); \
3254 }3229 }
3255zig_float_negate_builtin(16, 16, , UINT16_C(1) << 15 )3230zig_float_negate_builtin(16, , UINT16_C(1) << 15 )
3256zig_float_negate_builtin(32, 32, , UINT32_C(1) << 31 )3231zig_float_negate_builtin(32, , UINT32_C(1) << 31 )
3257zig_float_negate_builtin(64, 64, , UINT64_C(1) << 63 )3232zig_float_negate_builtin(64, , UINT64_C(1) << 63 )
3258zig_float_negate_builtin(80, 128, zig_make_u128, (UINT64_C(1) << 15, UINT64_C(0)))3233zig_float_negate_builtin(80, zig_make_u128, (UINT64_C(1) << 15, UINT64_C(0)))
3259zig_float_negate_builtin(128, 128, zig_make_u128, (UINT64_C(1) << 63, UINT64_C(0)))3234zig_float_negate_builtin(128, zig_make_u128, (UINT64_C(1) << 63, UINT64_C(0)))
32603235
3261#define zig_float_less_builtin_0(Type, operation) \3236#define zig_float_less_builtin_0(Type, operation) \
3262 zig_extern int32_t zig_expand_concat(zig_expand_concat(__##operation, \3237 zig_extern int32_t zig_expand_concat(zig_expand_concat(__##operation, \
src/codegen/c.zig+4-4
...@@ -3523,13 +3523,13 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3523,13 +3523,13 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue {
3523 try writer.writeAll("zig_shr_");3523 try writer.writeAll("zig_shr_");
3524 try f.object.dg.renderTypeForBuiltinFnName(writer, scalar_ty);3524 try f.object.dg.renderTypeForBuiltinFnName(writer, scalar_ty);
3525 if (c_bits == 128) {3525 if (c_bits == 128) {
3526 try writer.print("(zig_bitcast_i{d}(", .{c_bits});3526 try writer.print("(zig_bitCast_i{d}(", .{c_bits});
3527 } else {3527 } else {
3528 try writer.print("((int{d}_t)", .{c_bits});3528 try writer.print("((int{d}_t)", .{c_bits});
3529 }3529 }
3530 try writer.print("zig_shl_u{d}(", .{c_bits});3530 try writer.print("zig_shl_u{d}(", .{c_bits});
3531 if (c_bits == 128) {3531 if (c_bits == 128) {
3532 try writer.print("zig_bitcast_u{d}(", .{c_bits});3532 try writer.print("zig_bitCast_u{d}(", .{c_bits});
3533 } else {3533 } else {
3534 try writer.print("(uint{d}_t)", .{c_bits});3534 try writer.print("(uint{d}_t)", .{c_bits});
3535 }3535 }
...@@ -4484,7 +4484,7 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4484,7 +4484,7 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {
4484 }4484 }
4485 try writer.writeAll(" = ");4485 try writer.writeAll(" = ");
4486 if (need_bitcasts) {4486 if (need_bitcasts) {
4487 try writer.writeAll("zig_bitcast_");4487 try writer.writeAll("zig_bitCast_");
4488 try f.object.dg.renderCTypeForBuiltinFnName(writer, wrap_cty.?.toUnsigned());4488 try f.object.dg.renderCTypeForBuiltinFnName(writer, wrap_cty.?.toUnsigned());
4489 try writer.writeByte('(');4489 try writer.writeByte('(');
4490 }4490 }
...@@ -4496,7 +4496,7 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4496,7 +4496,7 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {
4496 try f.object.dg.renderTypeForBuiltinFnName(writer, info_ty);4496 try f.object.dg.renderTypeForBuiltinFnName(writer, info_ty);
4497 try writer.writeByte('(');4497 try writer.writeByte('(');
4498 if (need_bitcasts) {4498 if (need_bitcasts) {
4499 try writer.writeAll("zig_bitcast_");4499 try writer.writeAll("zig_bitCast_");
4500 try f.object.dg.renderCTypeForBuiltinFnName(writer, wrap_cty.?);4500 try f.object.dg.renderCTypeForBuiltinFnName(writer, wrap_cty.?);
4501 try writer.writeByte('(');4501 try writer.writeByte('(');
4502 }4502 }