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;
434434#define zig_minInt_u(w, bits) zig_intLimit(u, w, min, bits)
435435#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) \
438438 static inline Type zig_##operation(Type lhs, RhsType rhs) { \
439439 return lhs operator rhs; \
440440 }
441#define zig_int_basic_operator(Type, operation, operator) \
442 zig_int_operator(Type, Type, operation, operator)
443#define zig_int_shift_operator(Type, operation, operator) \
444 zig_int_operator(Type, uint8_t, operation, operator)
441#define zig_basic_operator(Type, operation, operator) \
442 zig_operator(Type, Type, operation, operator)
443#define zig_shift_operator(Type, operation, operator) \
444 zig_operator(Type, uint8_t, operation, operator)
445445#define zig_int_helpers(w) \
446 zig_int_basic_operator(uint##w##_t, and_u##w, &) \
447 zig_int_basic_operator( int##w##_t, and_i##w, &) \
448 zig_int_basic_operator(uint##w##_t, or_u##w, |) \
449 zig_int_basic_operator( int##w##_t, or_i##w, |) \
450 zig_int_basic_operator(uint##w##_t, xor_u##w, ^) \
451 zig_int_basic_operator( int##w##_t, xor_i##w, ^) \
452 zig_int_shift_operator(uint##w##_t, shl_u##w, <<) \
453 zig_int_shift_operator( int##w##_t, shl_i##w, <<) \
454 zig_int_shift_operator(uint##w##_t, shr_u##w, >>) \
446 zig_basic_operator(uint##w##_t, and_u##w, &) \
447 zig_basic_operator( int##w##_t, and_i##w, &) \
448 zig_basic_operator(uint##w##_t, or_u##w, |) \
449 zig_basic_operator( int##w##_t, or_i##w, |) \
450 zig_basic_operator(uint##w##_t, xor_u##w, ^) \
451 zig_basic_operator( int##w##_t, xor_i##w, ^) \
452 zig_shift_operator(uint##w##_t, shl_u##w, <<) \
453 zig_shift_operator( int##w##_t, shl_i##w, <<) \
454 zig_shift_operator(uint##w##_t, shr_u##w, >>) \
455455\
456456 static inline int##w##_t zig_shr_i##w(int##w##_t lhs, uint8_t rhs) { \
457457 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;
476476 ? val | zig_minInt_i(w, bits) : val & zig_maxInt_i(w, bits); \
477477 } \
478478\
479 zig_int_basic_operator(uint##w##_t, div_floor_u##w, /) \
479 zig_basic_operator(uint##w##_t, div_floor_u##w, /) \
480480\
481481 static inline int##w##_t zig_div_floor_i##w(int##w##_t lhs, int##w##_t rhs) { \
482482 return lhs / rhs - (((lhs ^ rhs) & (lhs % rhs)) < INT##w##_C(0)); \
483483 } \
484484\
485 zig_int_basic_operator(uint##w##_t, mod_u##w, %) \
485 zig_basic_operator(uint##w##_t, mod_u##w, %) \
486486\
487487 static inline int##w##_t zig_mod_i##w(int##w##_t lhs, int##w##_t rhs) { \
488488 int##w##_t rem = lhs % rhs; \
......@@ -1153,8 +1153,8 @@ typedef signed __int128 zig_i128;
11531153#define zig_lo_u128(val) ((uint64_t)((val) >> 0))
11541154#define zig_hi_i128(val) (( int64_t)((val) >> 64))
11551155#define zig_lo_i128(val) ((uint64_t)((val) >> 0))
1156#define zig_bitcast_u128(val) ((zig_u128)(val))
1157#define zig_bitcast_i128(val) ((zig_i128)(val))
1156#define zig_bitCast_u128(val) ((zig_u128)(val))
1157#define zig_bitCast_i128(val) ((zig_i128)(val))
11581158#define zig_cmp_int128(Type) \
11591159 static inline int32_t zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \
11601160 return (lhs > rhs) - (lhs < rhs); \
......@@ -1188,8 +1188,8 @@ typedef struct { zig_align(16) int64_t hi; uint64_t lo; } zig_i128;
11881188#define zig_lo_u128(val) ((val).lo)
11891189#define zig_hi_i128(val) ((val).hi)
11901190#define zig_lo_i128(val) ((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)
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)
11931193#define zig_cmp_int128(Type) \
11941194 static inline int32_t zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \
11951195 return (lhs.hi == rhs.hi) \
......@@ -1363,7 +1363,7 @@ static zig_i128 zig_mul_i128(zig_i128 lhs, zig_i128 rhs) {
13631363}
13641364
13651365static 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)));
13671367}
13681368
13691369zig_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) {
14311431}
14321432
14331433static 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);
14351435}
14361436
14371437static 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) {
14391439}
14401440
14411441static 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);
14431443}
14441444
14451445static 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) {
14471447}
14481448
14491449static 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);
14511451}
14521452
14531453static 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) {
14551455}
14561456
14571457static 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);
14591459}
14601460
14611461#if zig_has_int128
......@@ -1590,7 +1590,7 @@ static inline bool zig_shlo_u128(zig_u128 *res, zig_u128 lhs, uint8_t rhs, uint8
15901590
15911591static inline bool zig_shlo_i128(zig_i128 *res, zig_i128 lhs, uint8_t rhs, uint8_t bits) {
15921592 *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)));
15941594 return zig_cmp_i128(zig_and_i128(lhs, mask), zig_make_i128(0, 0)) != INT32_C(0) &&
15951595 zig_cmp_i128(zig_and_i128(lhs, mask), mask) != INT32_C(0);
15961596}
......@@ -1604,7 +1604,7 @@ static inline zig_u128 zig_shls_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) {
16041604
16051605static inline zig_i128 zig_shls_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) {
16061606 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;
16081608 return zig_cmp_i128(lhs, zig_make_i128(0, 0)) < INT32_C(0) ? zig_minInt_i(128, bits) : zig_maxInt_i(128, bits);
16091609}
16101610
......@@ -1648,7 +1648,7 @@ static inline uint8_t zig_clz_u128(zig_u128 val, uint8_t bits) {
16481648}
16491649
16501650static 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);
16521652}
16531653
16541654static 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) {
16571657}
16581658
16591659static 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);
16611661}
16621662
16631663static 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) {
16661666}
16671667
16681668static 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);
16701670}
16711671
16721672static 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) {
16811681}
16821682
16831683static 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));
16851685}
16861686
16871687static 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) {
16911691}
16921692
16931693static 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));
16951695}
16961696
16971697/* ========================== Big Integer Support =========================== */
......@@ -2957,24 +2957,20 @@ long double __cdecl nanl(char const* input);
29572957#endif
29582958
29592959#if (zig_has_builtin(nan) && zig_has_builtin(nans) && zig_has_builtin(inf)) || defined(zig_gnuc)
2960#define zig_has_float_builtins 1
2961#define zig_make_special_f16(sign, name, arg, repr) sign zig_make_f16(__builtin_##name, )(arg)
2962#define zig_make_special_f32(sign, name, arg, repr) sign zig_make_f32(__builtin_##name, )(arg)
2963#define zig_make_special_f64(sign, name, arg, repr) sign zig_make_f64(__builtin_##name, )(arg)
2964#define zig_make_special_f80(sign, name, arg, repr) sign zig_make_f80(__builtin_##name, )(arg)
2960#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_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)
29652964#define zig_make_special_f128(sign, name, arg, repr) sign zig_make_f128(__builtin_##name, )(arg)
29662965#else
2967#define zig_has_float_builtins 0
2968#define zig_make_special_f16(sign, name, arg, repr) zig_float_from_repr_f16(repr)
2969#define zig_make_special_f32(sign, name, arg, repr) zig_float_from_repr_f32(repr)
2970#define zig_make_special_f64(sign, name, arg, repr) zig_float_from_repr_f64(repr)
2971#define zig_make_special_f80(sign, name, arg, repr) zig_float_from_repr_f80(repr)
2972#define zig_make_special_f128(sign, name, arg, repr) zig_float_from_repr_f128(repr)
2966#define zig_make_special_f16(sign, name, arg, repr) zig_bitCast_f16 (repr)
2967#define zig_make_special_f32(sign, name, arg, repr) zig_bitCast_f32 (repr)
2968#define zig_make_special_f64(sign, name, arg, repr) zig_bitCast_f64 (repr)
2969#define zig_make_special_f80(sign, name, arg, repr) zig_bitCast_f80 (repr)
2970#define zig_make_special_f128(sign, name, arg, repr) zig_bitCast_f128(repr)
29732971#endif
29742972
29752973#define zig_has_f16 1
2976#define zig_bitSizeOf_f16 16
2977typedef uint16_t zig_repr_f16;
29782974#define zig_libc_name_f16(name) __##name##h
29792975#define zig_init_special_f16(sign, name, arg, repr) zig_make_special_f16(sign, name, arg, repr)
29802976#if FLT_MANT_DIG == 11
......@@ -2995,7 +2991,8 @@ typedef __fp16 zig_f16;
29952991#else
29962992#undef zig_has_f16
29972993#define zig_has_f16 0
2998typedef zig_repr_f16 zig_f16;
2994#define zig_repr_f16 u16
2995typedef uint16_t zig_f16;
29992996#define zig_make_f16(fp, repr) repr
30002997#undef zig_make_special_f16
30012998#define zig_make_special_f16(sign, name, arg, repr) repr
......@@ -3003,14 +3000,12 @@ typedef zig_repr_f16 zig_f16;
30033000#define zig_init_special_f16(sign, name, arg, repr) repr
30043001#endif
30053002#if __APPLE__ && (defined(__i386__) || defined(__x86_64__))
3006typedef zig_repr_f16 zig_compiler_rt_f16;
3003typedef uint16_t zig_compiler_rt_f16;
30073004#else
30083005typedef zig_f16 zig_compiler_rt_f16;
30093006#endif
30103007
30113008#define zig_has_f32 1
3012#define zig_bitSizeOf_f32 32
3013typedef uint32_t zig_repr_f32;
30143009#define zig_libc_name_f32(name) name##f
30153010#if _MSC_VER
30163011#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;
30323027#else
30333028#undef zig_has_f32
30343029#define zig_has_f32 0
3035typedef zig_repr_f32 zig_f32;
3030#define zig_repr_f32 u32
3031ypedef uint32_t zig_f32;
30363032#define zig_make_f32(fp, repr) repr
30373033#undef zig_make_special_f32
30383034#define zig_make_special_f32(sign, name, arg, repr) repr
......@@ -3041,8 +3037,6 @@ typedef zig_repr_f32 zig_f32;
30413037#endif
30423038
30433039#define zig_has_f64 1
3044#define zig_bitSizeOf_f64 64
3045typedef uint64_t zig_repr_f64;
30463040#define zig_libc_name_f64(name) name
30473041#if _MSC_VER
30483042#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;
30673061#else
30683062#undef zig_has_f64
30693063#define zig_has_f64 0
3070typedef zig_repr_f64 zig_f64;
3064#define zig_repr_f64 u64
3065typedef uint64_t zig_f64;
30713066#define zig_make_f64(fp, repr) repr
30723067#undef zig_make_special_f64
30733068#define zig_make_special_f64(sign, name, arg, repr) repr
......@@ -3076,8 +3071,6 @@ typedef zig_repr_f64 zig_f64;
30763071#endif
30773072
30783073#define zig_has_f80 1
3079#define zig_bitSizeOf_f80 80
3080typedef zig_u128 zig_repr_f80;
30813074#define zig_libc_name_f80(name) __##name##x
30823075#define zig_init_special_f80(sign, name, arg, repr) zig_make_special_f80(sign, name, arg, repr)
30833076#if FLT_MANT_DIG == 64
......@@ -3101,7 +3094,8 @@ typedef __float80 zig_f80;
31013094#else
31023095#undef zig_has_f80
31033096#define zig_has_f80 0
3104typedef zig_repr_f80 zig_f80;
3097#define zig_repr_f80 u128
3098typedef zig_u128 zig_f80;
31053099#define zig_make_f80(fp, repr) repr
31063100#undef zig_make_special_f80
31073101#define zig_make_special_f80(sign, name, arg, repr) repr
......@@ -3110,8 +3104,6 @@ typedef zig_repr_f80 zig_f80;
31103104#endif
31113105
31123106#define zig_has_f128 1
3113#define zig_bitSizeOf_f128 128
3114typedef zig_u128 zig_repr_f128;
31153107#define zig_libc_name_f128(name) name##q
31163108#define zig_init_special_f128(sign, name, arg, repr) zig_make_special_f128(sign, name, arg, repr)
31173109#if FLT_MANT_DIG == 113
......@@ -3140,14 +3132,18 @@ typedef __float128 zig_f128;
31403132#undef zig_make_special_f128
31413133#undef zig_init_special_f128
31423134#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;
31443139#define zig_make_f128_zig_make_u128(hi, lo) (zig_f128){ lo, hi }
31453140#define zig_make_f128_zig_init_u128 zig_make_f128_zig_make_u128
31463141#define zig_make_f128(fp, repr) zig_make_f128_##repr
31473142#define zig_make_special_f128(sign, name, arg, repr) zig_make_f128_##repr
31483143#define zig_init_special_f128(sign, name, arg, repr) zig_make_f128_##repr
31493144#else
3150typedef zig_repr_f128 zig_f128;
3145#define zig_repr_f128 u128
3146typedef zig_u128 zig_f128;
31513147#define zig_make_f128(fp, repr) repr
31523148#define zig_make_special_f128(sign, name, arg, repr) repr
31533149#define zig_init_special_f128(sign, name, arg, repr) repr
......@@ -3156,48 +3152,26 @@ typedef zig_repr_f128 zig_f128;
31563152
31573153#if !_MSC_VER && defined(ZIG_TARGET_ABI_MSVC)
31583154/* Emulate msvc abi on a gnu compiler */
3159#define zig_bitSizeOf_c_longdouble 64
3160typedef zig_repr_f64 zig_repr_c_longdouble;
31613155typedef zig_f64 zig_c_longdouble;
31623156#elif _MSC_VER && !defined(ZIG_TARGET_ABI_MSVC)
31633157/* Emulate gnu abi on an msvc compiler */
3164#define zig_bitSizeOf_c_longdouble 128
3165typedef zig_repr_f128 zig_repr_c_longdouble;
31663158typedef zig_f128 zig_c_longdouble;
31673159#else
3168#if LDBL_MANT_DIG == 11
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
3160/* Target and compiler abi match */
31843161typedef long double zig_c_longdouble;
31853162#endif
31863163
3187#if !zig_has_float_builtins
3188#define zig_float_from_repr(Type) \
3189 static inline zig_##Type zig_float_from_repr_##Type(zig_repr_##Type repr) { \
3164#define zig_bitCast_float(Type, ReprType) \
3165 static inline zig_##Type zig_bitCast_##Type(ReprType repr) { \
31903166 zig_##Type result; \
31913167 memcpy(&result, &repr, sizeof(result)); \
31923168 return result; \
31933169 }
3194
3195zig_float_from_repr(f16)
3196zig_float_from_repr(f32)
3197zig_float_from_repr(f64)
3198zig_float_from_repr(f80)
3199zig_float_from_repr(f128)
3200#endif
3170zig_bitCast_float(f16, uint16_t)
3171zig_bitCast_float(f32, uint32_t)
3172zig_bitCast_float(f64, uint64_t)
3173zig_bitCast_float(f80, zig_u128)
3174zig_bitCast_float(f128, zig_u128)
32013175
32023176#define zig_cast_f16 (zig_f16)
32033177#define zig_cast_f32 (zig_f32)
......@@ -3246,17 +3220,18 @@ zig_convert_builtin(zig_f128, zig_f128, extend, zig_f32,
32463220zig_convert_builtin(zig_f128, zig_f128, extend, zig_f64, zig_f64, 2)
32473221zig_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))
3250#define zig_float_negate_builtin_1(w, r, c, sb) -arg
3251#define zig_float_negate_builtin(w, r, c, sb) \
3223#define zig_float_negate_builtin_0(w, c, sb) \
3224 zig_expand_concat(zig_xor_, zig_repr_f##w)(arg, zig_make_f##w(-0x0.0p0, c sb))
3225#define zig_float_negate_builtin_1(w, c, sb) -arg
3226#define zig_float_negate_builtin(w, c, sb) \
32523227 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); \
32543229 }
3255zig_float_negate_builtin(16, 16, , UINT16_C(1) << 15 )
3256zig_float_negate_builtin(32, 32, , UINT32_C(1) << 31 )
3257zig_float_negate_builtin(64, 64, , UINT64_C(1) << 63 )
3258zig_float_negate_builtin(80, 128, 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)))
3230zig_float_negate_builtin(16, , UINT16_C(1) << 15 )
3231zig_float_negate_builtin(32, , UINT32_C(1) << 31 )
3232zig_float_negate_builtin(64, , UINT64_C(1) << 63 )
3233zig_float_negate_builtin(80, zig_make_u128, (UINT64_C(1) << 15, UINT64_C(0)))
3234zig_float_negate_builtin(128, zig_make_u128, (UINT64_C(1) << 63, UINT64_C(0)))
32603235
32613236#define zig_float_less_builtin_0(Type, operation) \
32623237 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 {
35233523 try writer.writeAll("zig_shr_");
35243524 try f.object.dg.renderTypeForBuiltinFnName(writer, scalar_ty);
35253525 if (c_bits == 128) {
3526 try writer.print("(zig_bitcast_i{d}(", .{c_bits});
3526 try writer.print("(zig_bitCast_i{d}(", .{c_bits});
35273527 } else {
35283528 try writer.print("((int{d}_t)", .{c_bits});
35293529 }
35303530 try writer.print("zig_shl_u{d}(", .{c_bits});
35313531 if (c_bits == 128) {
3532 try writer.print("zig_bitcast_u{d}(", .{c_bits});
3532 try writer.print("zig_bitCast_u{d}(", .{c_bits});
35333533 } else {
35343534 try writer.print("(uint{d}_t)", .{c_bits});
35353535 }
......@@ -4484,7 +4484,7 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {
44844484 }
44854485 try writer.writeAll(" = ");
44864486 if (need_bitcasts) {
4487 try writer.writeAll("zig_bitcast_");
4487 try writer.writeAll("zig_bitCast_");
44884488 try f.object.dg.renderCTypeForBuiltinFnName(writer, wrap_cty.?.toUnsigned());
44894489 try writer.writeByte('(');
44904490 }
......@@ -4496,7 +4496,7 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {
44964496 try f.object.dg.renderTypeForBuiltinFnName(writer, info_ty);
44974497 try writer.writeByte('(');
44984498 if (need_bitcasts) {
4499 try writer.writeAll("zig_bitcast_");
4499 try writer.writeAll("zig_bitCast_");
45004500 try f.object.dg.renderCTypeForBuiltinFnName(writer, wrap_cty.?);
45014501 try writer.writeByte('(');
45024502 }