authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-19 03:32:47-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-19 09:37:52-07:00
log17e3fcc3a5accb31b9ea15f64bd9e968245000c2
treef55dbabfa350662f74d42deeda046d42e4802ff3
parentd65318847ff4f8eb9d6655b27bf769ea94c2c3d7

compiler_rt: fight off `@as` invasion

Importantly, fixes incorrectly annotated types in `__aeabi_?2h`.

56 files changed, 325 insertions(+), 358 deletions(-)

lib/compiler_rt/addf3.zig+7-8
......@@ -9,7 +9,6 @@ const normalize = common.normalize;
99pub inline fn addf3(comptime T: type, a: T, b: T) T {
1010 const bits = @typeInfo(T).Float.bits;
1111 const Z = std.meta.Int(.unsigned, bits);
12 const S = std.meta.Int(.unsigned, bits - @clz(@as(Z, bits) - 1));
1312
1413 const typeWidth = bits;
1514 const significandBits = math.floatMantissaBits(T);
......@@ -26,12 +25,12 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
2625 const absMask = signBit - 1;
2726 const qnanRep = @as(Z, @bitCast(math.nan(T))) | quietBit;
2827
29 var aRep = @as(Z, @bitCast(a));
30 var bRep = @as(Z, @bitCast(b));
28 var aRep: Z = @bitCast(a);
29 var bRep: Z = @bitCast(b);
3130 const aAbs = aRep & absMask;
3231 const bAbs = bRep & absMask;
3332
34 const infRep = @as(Z, @bitCast(math.inf(T)));
33 const infRep: Z = @bitCast(math.inf(T));
3534
3635 // Detect if a or b is zero, infinity, or NaN.
3736 if (aAbs -% @as(Z, 1) >= infRep - @as(Z, 1) or
......@@ -104,8 +103,8 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
104103 const @"align": u32 = @intCast(aExponent - bExponent);
105104 if (@"align" != 0) {
106105 if (@"align" < typeWidth) {
107 const sticky = if (bSignificand << @as(S, @intCast(typeWidth - @"align")) != 0) @as(Z, 1) else 0;
108 bSignificand = (bSignificand >> @as(S, @truncate(@"align"))) | sticky;
106 const sticky = if (bSignificand << @intCast(typeWidth - @"align") != 0) @as(Z, 1) else 0;
107 bSignificand = (bSignificand >> @truncate(@"align")) | sticky;
109108 } else {
110109 bSignificand = 1; // sticky; b is known to be non-zero.
111110 }
......@@ -119,7 +118,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
119118 // and adjust the exponent:
120119 if (aSignificand < integerBit << 3) {
121120 const shift = @as(i32, @intCast(@clz(aSignificand))) - @as(i32, @intCast(@clz(integerBit << 3)));
122 aSignificand <<= @as(S, @intCast(shift));
121 aSignificand <<= @intCast(shift);
123122 aExponent -= shift;
124123 }
125124 } else { // addition
......@@ -140,7 +139,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
140139 if (aExponent <= 0) {
141140 // Result is denormal; the exponent and round/sticky bits are zero.
142141 // All we need to do is shift the significand and apply the correct sign.
143 aSignificand >>= @as(S, @intCast(4 - aExponent));
142 aSignificand >>= @intCast(4 - aExponent);
144143 return @bitCast(resultSign | aSignificand);
145144 }
146145
lib/compiler_rt/ceil.zig+1-1
......@@ -43,7 +43,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 {
4343 if (e >= 23) {
4444 return x;
4545 } else if (e >= 0) {
46 m = @as(u32, 0x007FFFFF) >> @as(u5, @intCast(e));
46 m = @as(u32, 0x007FFFFF) >> @intCast(e);
4747 if (u & m == 0) {
4848 return x;
4949 }
lib/compiler_rt/clear_cache.zig+2-2
......@@ -102,7 +102,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void {
102102 // If CTR_EL0.IDC is set, data cache cleaning to the point of unification
103103 // is not required for instruction to data coherence.
104104 if (((ctr_el0 >> 28) & 0x1) == 0x0) {
105 const dcache_line_size: usize = @as(usize, 4) << @as(u6, @intCast((ctr_el0 >> 16) & 15));
105 const dcache_line_size = @as(usize, 4) << @intCast((ctr_el0 >> 16) & 15);
106106 addr = start & ~(dcache_line_size - 1);
107107 while (addr < end) : (addr += dcache_line_size) {
108108 asm volatile ("dc cvau, %[addr]"
......@@ -115,7 +115,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void {
115115 // If CTR_EL0.DIC is set, instruction cache invalidation to the point of
116116 // unification is not required for instruction to data coherence.
117117 if (((ctr_el0 >> 29) & 0x1) == 0x0) {
118 const icache_line_size: usize = @as(usize, 4) << @as(u6, @intCast((ctr_el0 >> 0) & 15));
118 const icache_line_size = @as(usize, 4) << @intCast((ctr_el0 >> 0) & 15);
119119 addr = start & ~(icache_line_size - 1);
120120 while (addr < end) : (addr += icache_line_size) {
121121 asm volatile ("ic ivau, %[addr]"
lib/compiler_rt/common.zig+8-8
......@@ -102,14 +102,14 @@ pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
102102 u16 => {
103103 // 16x16 --> 32 bit multiply
104104 const product = @as(u32, a) * @as(u32, b);
105 hi.* = @as(u16, @intCast(product >> 16));
106 lo.* = @as(u16, @truncate(product));
105 hi.* = @intCast(product >> 16);
106 lo.* = @truncate(product);
107107 },
108108 u32 => {
109109 // 32x32 --> 64 bit multiply
110110 const product = @as(u64, a) * @as(u64, b);
111 hi.* = @as(u32, @truncate(product >> 32));
112 lo.* = @as(u32, @truncate(product));
111 hi.* = @truncate(product >> 32);
112 lo.* = @truncate(product);
113113 },
114114 u64 => {
115115 const S = struct {
......@@ -136,9 +136,9 @@ pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
136136 hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi;
137137 },
138138 u128 => {
139 const Word_LoMask = @as(u64, 0x00000000ffffffff);
140 const Word_HiMask = @as(u64, 0xffffffff00000000);
141 const Word_FullMask = @as(u64, 0xffffffffffffffff);
139 const Word_LoMask: u64 = 0x00000000ffffffff;
140 const Word_HiMask: u64 = 0xffffffff00000000;
141 const Word_FullMask: u64 = 0xffffffffffffffff;
142142 const S = struct {
143143 fn Word_1(x: u128) u64 {
144144 return @as(u32, @truncate(x >> 96));
......@@ -229,7 +229,7 @@ pub inline fn fneg(a: anytype) @TypeOf(a) {
229229 } });
230230 const sign_bit_mask = @as(U, 1) << (bits - 1);
231231 const negated = @as(U, @bitCast(a)) ^ sign_bit_mask;
232 return @as(F, @bitCast(negated));
232 return @bitCast(negated);
233233}
234234
235235/// Allows to access underlying bits as two equally sized lower and higher
lib/compiler_rt/cos.zig+1-1
......@@ -25,7 +25,7 @@ comptime {
2525
2626pub fn __cosh(a: f16) callconv(.C) f16 {
2727 // TODO: more efficient implementation
28 return @as(f16, @floatCast(cosf(a)));
28 return @floatCast(cosf(a));
2929}
3030
3131pub fn cosf(x: f32) callconv(.C) f32 {
lib/compiler_rt/count0bits.zig+1-6
......@@ -203,12 +203,7 @@ pub fn __ctzti2(a: i128) callconv(.C) i32 {
203203}
204204
205205inline fn ffsXi2(comptime T: type, a: T) i32 {
206 var x = switch (@bitSizeOf(T)) {
207 32 => @as(u32, @bitCast(a)),
208 64 => @as(u64, @bitCast(a)),
209 128 => @as(u128, @bitCast(a)),
210 else => unreachable,
211 };
206 var x: std.meta.Int(.unsigned, @typeInfo(T).Int.bits) = @bitCast(a);
212207 var n: T = 1;
213208 // adapted from Number of trailing zeroes (see ctzXi2)
214209 var mask: @TypeOf(x) = std.math.maxInt(@TypeOf(x));
lib/compiler_rt/divti3.zig+2-2
......@@ -21,7 +21,7 @@ pub fn __divti3(a: i128, b: i128) callconv(.C) i128 {
2121const v128 = @Vector(2, u64);
2222
2323fn __divti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
24 return @as(v128, @bitCast(div(@as(i128, @bitCast(a)), @as(i128, @bitCast(b)))));
24 return @bitCast(div(@bitCast(a), @bitCast(b)));
2525}
2626
2727inline fn div(a: i128, b: i128) i128 {
......@@ -31,7 +31,7 @@ inline fn div(a: i128, b: i128) i128 {
3131 const an = (a ^ s_a) -% s_a;
3232 const bn = (b ^ s_b) -% s_b;
3333
34 const r = udivmod(u128, @as(u128, @bitCast(an)), @as(u128, @bitCast(bn)), null);
34 const r = udivmod(u128, @bitCast(an), @bitCast(bn), null);
3535 const s = s_a ^ s_b;
3636 return (@as(i128, @bitCast(r)) ^ s) -% s;
3737}
lib/compiler_rt/divxf3.zig+6-6
......@@ -164,8 +164,8 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
164164 // exponent accordingly.
165165 var quotient: u64 = if (quotient128 < (integerBit << 1)) b: {
166166 quotientExponent -= 1;
167 break :b @as(u64, @intCast(quotient128));
168 } else @as(u64, @intCast(quotient128 >> 1));
167 break :b @intCast(quotient128);
168 } else @intCast(quotient128 >> 1);
169169
170170 // We are going to compute a residual of the form
171171 //
......@@ -182,18 +182,18 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
182182 const writtenExponent = quotientExponent + exponentBias;
183183 if (writtenExponent >= maxExponent) {
184184 // If we have overflowed the exponent, return infinity.
185 return @as(T, @bitCast(infRep | quotientSign));
185 return @bitCast(infRep | quotientSign);
186186 } else if (writtenExponent < 1) {
187187 if (writtenExponent == 0) {
188188 // Check whether the rounded result is normal.
189189 if (residual > (bSignificand >> 1)) { // round
190190 if (quotient == (integerBit - 1)) // If the rounded result is normal, return it
191 return @as(T, @bitCast(@as(Z, @bitCast(std.math.floatMin(T))) | quotientSign));
191 return @bitCast(@as(Z, @bitCast(std.math.floatMin(T))) | quotientSign);
192192 }
193193 }
194194 // Flush denormals to zero. In the future, it would be nice to add
195195 // code to round them correctly.
196 return @as(T, @bitCast(quotientSign));
196 return @bitCast(quotientSign);
197197 } else {
198198 const round = @intFromBool(residual > (bSignificand >> 1));
199199 // Insert the exponent
......@@ -201,7 +201,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
201201 // Round
202202 absResult +%= round;
203203 // Insert the sign and return
204 return @as(T, @bitCast(absResult | quotientSign | integerBit));
204 return @bitCast(absResult | quotientSign | integerBit);
205205 }
206206}
207207
lib/compiler_rt/emutls.zig+6-6
......@@ -52,19 +52,19 @@ const simple_allocator = struct {
5252 abort();
5353 }
5454
55 return @as([*]u8, @ptrCast(aligned_ptr));
55 return @ptrCast(aligned_ptr);
5656 }
5757
5858 /// Resize a slice.
5959 pub fn reallocSlice(comptime T: type, slice: []T, len: usize) []T {
60 var c_ptr: *anyopaque = @as(*anyopaque, @ptrCast(slice.ptr));
60 var c_ptr: *anyopaque = @ptrCast(slice.ptr);
6161 var new_array: [*]T = @ptrCast(@alignCast(std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort()));
6262 return new_array[0..len];
6363 }
6464
6565 /// Free a memory chunk allocated with simple_allocator.
6666 pub fn free(ptr: anytype) void {
67 std.c.free(@as(*anyopaque, @ptrCast(ptr)));
67 std.c.free(@ptrCast(ptr));
6868 }
6969};
7070
......@@ -138,7 +138,7 @@ const ObjectArray = struct {
138138 @memset(data[0..size], 0);
139139 }
140140
141 self.slots[index] = @as(*anyopaque, @ptrCast(data));
141 self.slots[index] = @ptrCast(data);
142142 }
143143
144144 return self.slots[index].?;
......@@ -178,7 +178,7 @@ const current_thread_storage = struct {
178178
179179 /// Set casted thread specific value.
180180 fn setspecific(new: ?*ObjectArray) void {
181 if (std.c.pthread_setspecific(current_thread_storage.key, @as(*anyopaque, @ptrCast(new))) != 0) {
181 if (std.c.pthread_setspecific(current_thread_storage.key, @ptrCast(new)) != 0) {
182182 abort();
183183 }
184184 }
......@@ -278,7 +278,7 @@ const emutls_control = extern struct {
278278 .size = @sizeOf(T),
279279 .alignment = @alignOf(T),
280280 .object = .{ .index = 0 },
281 .default_value = @as(?*const anyopaque, @ptrCast(default_value)),
281 .default_value = @ptrCast(default_value),
282282 };
283283 }
284284
lib/compiler_rt/exp.zig+3-3
......@@ -27,7 +27,7 @@ comptime {
2727
2828pub fn __exph(a: f16) callconv(.C) f16 {
2929 // TODO: more efficient implementation
30 return @as(f16, @floatCast(expf(a)));
30 return @floatCast(expf(a));
3131}
3232
3333pub fn expf(x_: f32) callconv(.C) f32 {
......@@ -74,7 +74,7 @@ pub fn expf(x_: f32) callconv(.C) f32 {
7474 if (hx > 0x3EB17218) {
7575 // |x| > 1.5 * ln2
7676 if (hx > 0x3F851592) {
77 k = @intFromFloat(invln2 * x + half[@as(usize, @intCast(sign))]);
77 k = @intFromFloat(invln2 * x + half[@intCast(sign)]);
7878 } else {
7979 k = 1 - sign - sign;
8080 }
......@@ -157,7 +157,7 @@ pub fn exp(x_: f64) callconv(.C) f64 {
157157 if (hx > 0x3FD62E42) {
158158 // |x| >= 1.5 * ln2
159159 if (hx > 0x3FF0A2B2) {
160 k = @intFromFloat(invln2 * x + half[@as(usize, @intCast(sign))]);
160 k = @intFromFloat(invln2 * x + half[@intCast(sign)]);
161161 } else {
162162 k = 1 - sign - sign;
163163 }
lib/compiler_rt/exp2.zig+4-4
......@@ -27,7 +27,7 @@ comptime {
2727
2828pub fn __exp2h(x: f16) callconv(.C) f16 {
2929 // TODO: more efficient implementation
30 return @as(f16, @floatCast(exp2f(x)));
30 return @floatCast(exp2f(x));
3131}
3232
3333pub fn exp2f(x: f32) callconv(.C) f32 {
......@@ -81,7 +81,7 @@ pub fn exp2f(x: f32) callconv(.C) f32 {
8181 uf -= redux;
8282
8383 const z: f64 = x - uf;
84 var r: f64 = exp2ft[@as(usize, @intCast(i_0))];
84 var r: f64 = exp2ft[@intCast(i_0)];
8585 const t: f64 = r * z;
8686 r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4);
8787 return @floatCast(r * uk);
......@@ -149,8 +149,8 @@ pub fn exp2(x: f64) callconv(.C) f64 {
149149
150150 // r = exp2(y) = exp2t[i_0] * p(z - eps[i])
151151 var z: f64 = x - uf;
152 const t: f64 = exp2dt[@as(usize, @intCast(2 * i_0))];
153 z -= exp2dt[@as(usize, @intCast(2 * i_0 + 1))];
152 const t: f64 = exp2dt[@intCast(2 * i_0)];
153 z -= exp2dt[@intCast(2 * i_0 + 1)];
154154 const r: f64 = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5))));
155155
156156 return math.scalbn(r, ik);
lib/compiler_rt/extendf.zig+6-11
......@@ -9,7 +9,6 @@ pub inline fn extendf(
99 const dst_rep_t = std.meta.Int(.unsigned, @typeInfo(dst_t).Float.bits);
1010 const srcSigBits = std.math.floatMantissaBits(src_t);
1111 const dstSigBits = std.math.floatMantissaBits(dst_t);
12 const DstShift = std.math.Log2Int(dst_rep_t);
1312
1413 // Various constants whose values follow from the type parameters.
1514 // Any reasonable optimizer will fold and propagate all of these.
......@@ -56,9 +55,8 @@ pub inline fn extendf(
5655 // a is denormal.
5756 // renormalize the significand and clear the leading bit, then insert
5857 // the correct adjusted exponent in the destination type.
59 const scale: u32 = @clz(aAbs) -
60 @clz(@as(src_rep_t, srcMinNormal));
61 absResult = @as(dst_rep_t, aAbs) << @as(DstShift, @intCast(dstSigBits - srcSigBits + scale));
58 const scale: u32 = @clz(aAbs) - @clz(@as(src_rep_t, srcMinNormal));
59 absResult = @as(dst_rep_t, aAbs) << @intCast(dstSigBits - srcSigBits + scale);
6260 absResult ^= dstMinNormal;
6361 const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1;
6462 absResult |= @as(dst_rep_t, @intCast(resultExponent)) << dstSigBits;
......@@ -69,7 +67,7 @@ pub inline fn extendf(
6967
7068 // Apply the signbit to (dst_t)abs(a).
7169 const result: dst_rep_t align(@alignOf(dst_t)) = absResult | @as(dst_rep_t, sign) << (dstBits - srcBits);
72 return @as(dst_t, @bitCast(result));
70 return @bitCast(result);
7371}
7472
7573pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeInfo(src_t).Float.bits)) f80 {
......@@ -92,8 +90,6 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI
9290 const src_qnan = 1 << (src_sig_bits - 1);
9391 const src_nan_code = src_qnan - 1;
9492
95 const SrcShift = std.math.Log2Int(src_rep_t);
96
9793 var dst: std.math.F80 = undefined;
9894
9995 // Break a into a sign and representation of the absolute value
......@@ -121,12 +117,11 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI
121117 // a is denormal.
122118 // renormalize the significand and clear the leading bit, then insert
123119 // the correct adjusted exponent in the destination type.
124 const scale: u16 = @clz(a_abs) -
125 @clz(@as(src_rep_t, src_min_normal));
120 const scale: u16 = @clz(a_abs) - @clz(@as(src_rep_t, src_min_normal));
126121
127 dst.fraction = @as(u64, a_abs) << @as(u6, @intCast(dst_sig_bits - src_sig_bits + scale));
122 dst.fraction = @as(u64, a_abs) << @intCast(dst_sig_bits - src_sig_bits + scale);
128123 dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers
129 dst.exp = @truncate(a_abs >> @as(SrcShift, @intCast(src_sig_bits - scale)));
124 dst.exp = @truncate(a_abs >> @intCast(src_sig_bits - scale));
130125 dst.exp ^= 1;
131126 dst.exp |= dst_exp_bias - src_exp_bias - scale + 1;
132127 } else {
lib/compiler_rt/extendxftf2.zig+2-2
......@@ -39,12 +39,12 @@ fn __extendxftf2(a: f80) callconv(.C) f128 {
3939 // renormalize the significand and clear the leading bit and integer part,
4040 // then insert the correct adjusted exponent in the destination type.
4141 const scale: u32 = @clz(a_rep.fraction);
42 abs_result = @as(u128, a_rep.fraction) << @as(u7, @intCast(dst_sig_bits - src_sig_bits + scale + 1));
42 abs_result = @as(u128, a_rep.fraction) << @intCast(dst_sig_bits - src_sig_bits + scale + 1);
4343 abs_result ^= dst_min_normal;
4444 abs_result |= @as(u128, scale + 1) << dst_sig_bits;
4545 }
4646
4747 // Apply the signbit to (dst_t)abs(a).
4848 const result: u128 align(@alignOf(f128)) = abs_result | @as(u128, sign) << (dst_bits - 16);
49 return @as(f128, @bitCast(result));
49 return @bitCast(result);
5050}
lib/compiler_rt/fabs.zig+2-2
......@@ -51,7 +51,7 @@ pub fn fabsl(x: c_longdouble) callconv(.C) c_longdouble {
5151inline fn generic_fabs(x: anytype) @TypeOf(x) {
5252 const T = @TypeOf(x);
5353 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
54 const float_bits = @as(TBits, @bitCast(x));
54 const float_bits: TBits = @bitCast(x);
5555 const remove_sign = ~@as(TBits, 0) >> 1;
56 return @as(T, @bitCast(float_bits & remove_sign));
56 return @bitCast(float_bits & remove_sign);
5757}
lib/compiler_rt/fixdfti.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __fixdfti(a: f64) callconv(.C) i128 {
1919const v2u64 = @Vector(2, u64);
2020
2121fn __fixdfti_windows_x86_64(a: f64) callconv(.C) v2u64 {
22 return @as(v2u64, @bitCast(intFromFloat(i128, a)));
22 return @bitCast(intFromFloat(i128, a));
2323}
lib/compiler_rt/fixhfti.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __fixhfti(a: f16) callconv(.C) i128 {
1919const v2u64 = @Vector(2, u64);
2020
2121fn __fixhfti_windows_x86_64(a: f16) callconv(.C) v2u64 {
22 return @as(v2u64, @bitCast(intFromFloat(i128, a)));
22 return @bitCast(intFromFloat(i128, a));
2323}
lib/compiler_rt/fixsfti.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __fixsfti(a: f32) callconv(.C) i128 {
1919const v2u64 = @Vector(2, u64);
2020
2121fn __fixsfti_windows_x86_64(a: f32) callconv(.C) v2u64 {
22 return @as(v2u64, @bitCast(intFromFloat(i128, a)));
22 return @bitCast(intFromFloat(i128, a));
2323}
lib/compiler_rt/fixtfti.zig+1-1
......@@ -21,5 +21,5 @@ pub fn __fixtfti(a: f128) callconv(.C) i128 {
2121const v2u64 = @Vector(2, u64);
2222
2323fn __fixtfti_windows_x86_64(a: f128) callconv(.C) v2u64 {
24 return @as(v2u64, @bitCast(intFromFloat(i128, a)));
24 return @bitCast(intFromFloat(i128, a));
2525}
lib/compiler_rt/fixunsdfti.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __fixunsdfti(a: f64) callconv(.C) u128 {
1919const v2u64 = @Vector(2, u64);
2020
2121fn __fixunsdfti_windows_x86_64(a: f64) callconv(.C) v2u64 {
22 return @as(v2u64, @bitCast(intFromFloat(u128, a)));
22 return @bitCast(intFromFloat(u128, a));
2323}
lib/compiler_rt/fixunshfti.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __fixunshfti(a: f16) callconv(.C) u128 {
1919const v2u64 = @Vector(2, u64);
2020
2121fn __fixunshfti_windows_x86_64(a: f16) callconv(.C) v2u64 {
22 return @as(v2u64, @bitCast(intFromFloat(u128, a)));
22 return @bitCast(intFromFloat(u128, a));
2323}
lib/compiler_rt/fixunssfti.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __fixunssfti(a: f32) callconv(.C) u128 {
1919const v2u64 = @Vector(2, u64);
2020
2121fn __fixunssfti_windows_x86_64(a: f32) callconv(.C) v2u64 {
22 return @as(v2u64, @bitCast(intFromFloat(u128, a)));
22 return @bitCast(intFromFloat(u128, a));
2323}
lib/compiler_rt/fixunstfti.zig+1-1
......@@ -21,5 +21,5 @@ pub fn __fixunstfti(a: f128) callconv(.C) u128 {
2121const v2u64 = @Vector(2, u64);
2222
2323fn __fixunstfti_windows_x86_64(a: f128) callconv(.C) v2u64 {
24 return @as(v2u64, @bitCast(intFromFloat(u128, a)));
24 return @bitCast(intFromFloat(u128, a));
2525}
lib/compiler_rt/fixunsxfti.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __fixunsxfti(a: f80) callconv(.C) u128 {
1919const v2u64 = @Vector(2, u64);
2020
2121fn __fixunsxfti_windows_x86_64(a: f80) callconv(.C) v2u64 {
22 return @as(v2u64, @bitCast(intFromFloat(u128, a)));
22 return @bitCast(intFromFloat(u128, a));
2323}
lib/compiler_rt/fixxfti.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __fixxfti(a: f80) callconv(.C) i128 {
1919const v2u64 = @Vector(2, u64);
2020
2121fn __fixxfti_windows_x86_64(a: f80) callconv(.C) v2u64 {
22 return @as(v2u64, @bitCast(intFromFloat(i128, a)));
22 return @bitCast(intFromFloat(i128, a));
2323}
lib/compiler_rt/float_from_int.zig+4-4
......@@ -28,10 +28,10 @@ pub fn floatFromInt(comptime T: type, x: anytype) T {
2828 const shift_amt = fractional_bits - @as(math.Log2Int(uT), @intCast(exp));
2929
3030 // Shift up result to line up with the significand - no rounding required
31 result = (@as(uT, @intCast(abs_val)) << shift_amt);
31 result = @as(uT, @intCast(abs_val)) << shift_amt;
3232 result ^= implicit_bit; // Remove implicit integer bit
3333 } else {
34 var shift_amt = @as(math.Log2Int(Z), @intCast(exp - fractional_bits));
34 var shift_amt: math.Log2Int(Z) = @intCast(exp - fractional_bits);
3535 const exact_tie: bool = @ctz(abs_val) == shift_amt - 1;
3636
3737 // Shift down result and remove implicit integer bit
......@@ -43,14 +43,14 @@ pub fn floatFromInt(comptime T: type, x: anytype) T {
4343
4444 // Compute exponent
4545 if ((int_bits > max_exp) and (exp > max_exp)) // If exponent too large, overflow to infinity
46 return @as(T, @bitCast(sign_bit | @as(uT, @bitCast(inf))));
46 return @bitCast(sign_bit | @as(uT, @bitCast(inf)));
4747
4848 result += (@as(uT, exp) + exp_bias) << math.floatMantissaBits(T);
4949
5050 // If the result included a carry, we need to restore the explicit integer bit
5151 if (T == f80) result |= 1 << fractional_bits;
5252
53 return @as(T, @bitCast(sign_bit | result));
53 return @bitCast(sign_bit | result);
5454}
5555
5656test {
lib/compiler_rt/float_from_int_test.zig+22-22
......@@ -43,7 +43,7 @@ test "floatsisf" {
4343 try test__floatsisf(1, 0x3f800000);
4444 try test__floatsisf(-1, 0xbf800000);
4545 try test__floatsisf(0x7FFFFFFF, 0x4f000000);
46 try test__floatsisf(@as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 0xcf000000);
46 try test__floatsisf(@bitCast(@as(u32, @intCast(0x80000000))), 0xcf000000);
4747}
4848
4949test "floatunsisf" {
......@@ -72,10 +72,10 @@ test "floatdisf" {
7272 try test__floatdisf(-2, -2.0);
7373 try test__floatdisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
7474 try test__floatdisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
75 try test__floatdisf(@as(i64, @bitCast(@as(u64, 0x8000008000000000))), -0x1.FFFFFEp+62);
76 try test__floatdisf(@as(i64, @bitCast(@as(u64, 0x8000010000000000))), -0x1.FFFFFCp+62);
77 try test__floatdisf(@as(i64, @bitCast(@as(u64, 0x8000000000000000))), -0x1.000000p+63);
78 try test__floatdisf(@as(i64, @bitCast(@as(u64, 0x8000000000000001))), -0x1.000000p+63);
75 try test__floatdisf(@bitCast(@as(u64, 0x8000008000000000)), -0x1.FFFFFEp+62);
76 try test__floatdisf(@bitCast(@as(u64, 0x8000010000000000)), -0x1.FFFFFCp+62);
77 try test__floatdisf(@bitCast(@as(u64, 0x8000000000000000)), -0x1.000000p+63);
78 try test__floatdisf(@bitCast(@as(u64, 0x8000000000000001)), -0x1.000000p+63);
7979 try test__floatdisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
8080 try test__floatdisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
8181 try test__floatdisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
......@@ -228,7 +228,7 @@ test "floatuntisf" {
228228 try test__floatuntisf(make_uti(0x0000000000001FED, 0xCBE0000000000000), 0x1.FEDCBEp+76);
229229
230230 // Test overflow to infinity
231 try test__floatuntisf(@as(u128, math.maxInt(u128)), @as(f32, @bitCast(math.inf(f32))));
231 try test__floatuntisf(math.maxInt(u128), @bitCast(math.inf(f32)));
232232}
233233
234234fn test_one_floatsidf(a: i32, expected: u64) !void {
......@@ -246,15 +246,15 @@ test "floatsidf" {
246246 try test_one_floatsidf(1, 0x3ff0000000000000);
247247 try test_one_floatsidf(-1, 0xbff0000000000000);
248248 try test_one_floatsidf(0x7FFFFFFF, 0x41dfffffffc00000);
249 try test_one_floatsidf(@as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 0xc1e0000000000000);
249 try test_one_floatsidf(@bitCast(@as(u32, @intCast(0x80000000))), 0xc1e0000000000000);
250250}
251251
252252test "floatunsidf" {
253253 try test_one_floatunsidf(0, 0x0000000000000000);
254254 try test_one_floatunsidf(1, 0x3ff0000000000000);
255255 try test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000);
256 try test_one_floatunsidf(@as(u32, @intCast(0x80000000)), 0x41e0000000000000);
257 try test_one_floatunsidf(@as(u32, @intCast(0xFFFFFFFF)), 0x41efffffffe00000);
256 try test_one_floatunsidf(@intCast(0x80000000), 0x41e0000000000000);
257 try test_one_floatunsidf(@intCast(0xFFFFFFFF), 0x41efffffffe00000);
258258}
259259
260260fn test__floatdidf(a: i64, expected: f64) !void {
......@@ -279,12 +279,12 @@ test "floatdidf" {
279279 try test__floatdidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
280280 try test__floatdidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
281281 try test__floatdidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
282 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000008000000000)))), -0x1.FFFFFEp+62);
283 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000000000000800)))), -0x1.FFFFFFFFFFFFEp+62);
284 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000010000000000)))), -0x1.FFFFFCp+62);
285 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000000000001000)))), -0x1.FFFFFFFFFFFFCp+62);
286 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000000000000000)))), -0x1.000000p+63);
287 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000000000000001)))), -0x1.000000p+63); // 0x8000000000000001
282 try test__floatdidf(@bitCast(@as(u64, @intCast(0x8000008000000000))), -0x1.FFFFFEp+62);
283 try test__floatdidf(@bitCast(@as(u64, @intCast(0x8000000000000800))), -0x1.FFFFFFFFFFFFEp+62);
284 try test__floatdidf(@bitCast(@as(u64, @intCast(0x8000010000000000))), -0x1.FFFFFCp+62);
285 try test__floatdidf(@bitCast(@as(u64, @intCast(0x8000000000001000))), -0x1.FFFFFFFFFFFFCp+62);
286 try test__floatdidf(@bitCast(@as(u64, @intCast(0x8000000000000000))), -0x1.000000p+63);
287 try test__floatdidf(@bitCast(@as(u64, @intCast(0x8000000000000001))), -0x1.000000p+63); // 0x8000000000000001
288288 try test__floatdidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
289289 try test__floatdidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
290290 try test__floatdidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
......@@ -513,8 +513,8 @@ test "floatsitf" {
513513 try test__floatsitf(0x7FFFFFFF, 0x401dfffffffc00000000000000000000);
514514 try test__floatsitf(0x12345678, 0x401b2345678000000000000000000000);
515515 try test__floatsitf(-0x12345678, 0xc01b2345678000000000000000000000);
516 try test__floatsitf(@as(i32, @bitCast(@as(u32, @intCast(0xffffffff)))), 0xbfff0000000000000000000000000000);
517 try test__floatsitf(@as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 0xc01e0000000000000000000000000000);
516 try test__floatsitf(@bitCast(@as(u32, @intCast(0xffffffff))), 0xbfff0000000000000000000000000000);
517 try test__floatsitf(@bitCast(@as(u32, @intCast(0x80000000))), 0xc01e0000000000000000000000000000);
518518}
519519
520520fn test__floatunsitf(a: u32, expected_hi: u64, expected_lo: u64) !void {
......@@ -575,10 +575,10 @@ test "floatditf" {
575575 try test__floatditf(0x2, make_tf(0x4000000000000000, 0x0));
576576 try test__floatditf(0x1, make_tf(0x3fff000000000000, 0x0));
577577 try test__floatditf(0x0, make_tf(0x0, 0x0));
578 try test__floatditf(@as(i64, @bitCast(@as(u64, 0xffffffffffffffff))), make_tf(0xbfff000000000000, 0x0));
579 try test__floatditf(@as(i64, @bitCast(@as(u64, 0xfffffffffffffffe))), make_tf(0xc000000000000000, 0x0));
578 try test__floatditf(@bitCast(@as(u64, 0xffffffffffffffff)), make_tf(0xbfff000000000000, 0x0));
579 try test__floatditf(@bitCast(@as(u64, 0xfffffffffffffffe)), make_tf(0xc000000000000000, 0x0));
580580 try test__floatditf(-0x123456789abcdef1, make_tf(0xc03b23456789abcd, 0xef10000000000000));
581 try test__floatditf(@as(i64, @bitCast(@as(u64, 0x8000000000000000))), make_tf(0xc03e000000000000, 0x0));
581 try test__floatditf(@bitCast(@as(u64, 0x8000000000000000)), make_tf(0xc03e000000000000, 0x0));
582582}
583583
584584test "floatunditf" {
......@@ -773,7 +773,7 @@ fn make_ti(high: u64, low: u64) i128 {
773773 var result: u128 = high;
774774 result <<= 64;
775775 result |= low;
776 return @as(i128, @bitCast(result));
776 return @bitCast(result);
777777}
778778
779779fn make_uti(high: u64, low: u64) u128 {
......@@ -787,7 +787,7 @@ fn make_tf(high: u64, low: u64) f128 {
787787 var result: u128 = high;
788788 result <<= 64;
789789 result |= low;
790 return @as(f128, @bitCast(result));
790 return @bitCast(result);
791791}
792792
793793test "conversion to f16" {
lib/compiler_rt/floor.zig+7-7
......@@ -40,7 +40,7 @@ pub fn __floorh(x: f16) callconv(.C) f16 {
4040 }
4141
4242 if (e >= 0) {
43 m = @as(u16, 1023) >> @as(u4, @intCast(e));
43 m = @as(u16, 1023) >> @intCast(e);
4444 if (u & m == 0) {
4545 return x;
4646 }
......@@ -48,7 +48,7 @@ pub fn __floorh(x: f16) callconv(.C) f16 {
4848 if (u >> 15 != 0) {
4949 u += m;
5050 }
51 return @as(f16, @bitCast(u & ~m));
51 return @bitCast(u & ~m);
5252 } else {
5353 math.doNotOptimizeAway(x + 0x1.0p120);
5454 if (u >> 15 == 0) {
......@@ -60,7 +60,7 @@ pub fn __floorh(x: f16) callconv(.C) f16 {
6060}
6161
6262pub fn floorf(x: f32) callconv(.C) f32 {
63 var u = @as(u32, @bitCast(x));
63 var u: u32 = @bitCast(x);
6464 const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;
6565 var m: u32 = undefined;
6666
......@@ -74,7 +74,7 @@ pub fn floorf(x: f32) callconv(.C) f32 {
7474 }
7575
7676 if (e >= 0) {
77 m = @as(u32, 0x007FFFFF) >> @as(u5, @intCast(e));
77 m = @as(u32, 0x007FFFFF) >> @intCast(e);
7878 if (u & m == 0) {
7979 return x;
8080 }
......@@ -82,7 +82,7 @@ pub fn floorf(x: f32) callconv(.C) f32 {
8282 if (u >> 31 != 0) {
8383 u += m;
8484 }
85 return @as(f32, @bitCast(u & ~m));
85 return @bitCast(u & ~m);
8686 } else {
8787 math.doNotOptimizeAway(x + 0x1.0p120);
8888 if (u >> 31 == 0) {
......@@ -96,7 +96,7 @@ pub fn floorf(x: f32) callconv(.C) f32 {
9696pub fn floor(x: f64) callconv(.C) f64 {
9797 const f64_toint = 1.0 / math.floatEps(f64);
9898
99 const u = @as(u64, @bitCast(x));
99 const u: u64 = @bitCast(x);
100100 const e = (u >> 52) & 0x7FF;
101101 var y: f64 = undefined;
102102
......@@ -126,7 +126,7 @@ pub fn floor(x: f64) callconv(.C) f64 {
126126
127127pub fn __floorx(x: f80) callconv(.C) f80 {
128128 // TODO: more efficient implementation
129 return @as(f80, @floatCast(floorq(x)));
129 return @floatCast(floorq(x));
130130}
131131
132132pub fn floorq(x: f128) callconv(.C) f128 {
lib/compiler_rt/fma.zig+16-16
......@@ -28,7 +28,7 @@ comptime {
2828
2929pub fn __fmah(x: f16, y: f16, z: f16) callconv(.C) f16 {
3030 // TODO: more efficient implementation
31 return @as(f16, @floatCast(fmaf(x, y, z)));
31 return @floatCast(fmaf(x, y, z));
3232}
3333
3434pub fn fmaf(x: f32, y: f32, z: f32) callconv(.C) f32 {
......@@ -38,10 +38,10 @@ pub fn fmaf(x: f32, y: f32, z: f32) callconv(.C) f32 {
3838 const e = (u >> 52) & 0x7FF;
3939
4040 if ((u & 0x1FFFFFFF) != 0x10000000 or e == 0x7FF or (xy_z - xy == z and xy_z - z == xy)) {
41 return @as(f32, @floatCast(xy_z));
41 return @floatCast(xy_z);
4242 } else {
4343 // TODO: Handle inexact case with double-rounding
44 return @as(f32, @floatCast(xy_z));
44 return @floatCast(xy_z);
4545 }
4646}
4747
......@@ -95,7 +95,7 @@ pub fn fma(x: f64, y: f64, z: f64) callconv(.C) f64 {
9595
9696pub fn __fmax(a: f80, b: f80, c: f80) callconv(.C) f80 {
9797 // TODO: more efficient implementation
98 return @as(f80, @floatCast(fmaq(a, b, c)));
98 return @floatCast(fmaq(a, b, c));
9999}
100100
101101/// Fused multiply-add: Compute x * y + z with a single rounding error.
......@@ -201,12 +201,12 @@ fn dd_mul(a: f64, b: f64) dd {
201201fn add_adjusted(a: f64, b: f64) f64 {
202202 var sum = dd_add(a, b);
203203 if (sum.lo != 0) {
204 var uhii = @as(u64, @bitCast(sum.hi));
204 var uhii: u64 = @bitCast(sum.hi);
205205 if (uhii & 1 == 0) {
206206 // hibits += copysign(1.0, sum.hi, sum.lo)
207 const uloi = @as(u64, @bitCast(sum.lo));
207 const uloi: u64 = @bitCast(sum.lo);
208208 uhii += 1 - ((uhii ^ uloi) >> 62);
209 sum.hi = @as(f64, @bitCast(uhii));
209 sum.hi = @bitCast(uhii);
210210 }
211211 }
212212 return sum.hi;
......@@ -215,12 +215,12 @@ fn add_adjusted(a: f64, b: f64) f64 {
215215fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {
216216 var sum = dd_add(a, b);
217217 if (sum.lo != 0) {
218 var uhii = @as(u64, @bitCast(sum.hi));
218 var uhii: u64 = @bitCast(sum.hi);
219219 const bits_lost = -@as(i32, @intCast((uhii >> 52) & 0x7FF)) - scale + 1;
220220 if ((bits_lost != 1) == (uhii & 1 != 0)) {
221 const uloi = @as(u64, @bitCast(sum.lo));
221 const uloi: u64 = @bitCast(sum.lo);
222222 uhii += 1 - (((uhii ^ uloi) >> 62) & 2);
223 sum.hi = @as(f64, @bitCast(uhii));
223 sum.hi = @bitCast(uhii);
224224 }
225225 }
226226 return math.scalbn(sum.hi, scale);
......@@ -257,12 +257,12 @@ fn dd_add128(a: f128, b: f128) dd128 {
257257fn add_adjusted128(a: f128, b: f128) f128 {
258258 var sum = dd_add128(a, b);
259259 if (sum.lo != 0) {
260 var uhii = @as(u128, @bitCast(sum.hi));
260 var uhii: u128 = @bitCast(sum.hi);
261261 if (uhii & 1 == 0) {
262262 // hibits += copysign(1.0, sum.hi, sum.lo)
263 const uloi = @as(u128, @bitCast(sum.lo));
263 const uloi: u128 = @bitCast(sum.lo);
264264 uhii += 1 - ((uhii ^ uloi) >> 126);
265 sum.hi = @as(f128, @bitCast(uhii));
265 sum.hi = @bitCast(uhii);
266266 }
267267 }
268268 return sum.hi;
......@@ -282,12 +282,12 @@ fn add_and_denorm128(a: f128, b: f128, scale: i32) f128 {
282282 // If we are losing only one bit to denormalization, however, we must
283283 // break the ties manually.
284284 if (sum.lo != 0) {
285 var uhii = @as(u128, @bitCast(sum.hi));
285 var uhii: u128 = @bitCast(sum.hi);
286286 const bits_lost = -@as(i32, @intCast((uhii >> 112) & 0x7FFF)) - scale + 1;
287287 if ((bits_lost != 1) == (uhii & 1 != 0)) {
288 const uloi = @as(u128, @bitCast(sum.lo));
288 const uloi: u128 = @bitCast(sum.lo);
289289 uhii += 1 - (((uhii ^ uloi) >> 126) & 2);
290 sum.hi = @as(f128, @bitCast(uhii));
290 sum.hi = @bitCast(uhii);
291291 }
292292 }
293293 return math.scalbn(sum.hi, scale);
lib/compiler_rt/fmod.zig+12-13
......@@ -82,8 +82,8 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
8282
8383 var highA: u64 = 0;
8484 var highB: u64 = 0;
85 var lowA: u64 = @as(u64, @truncate(aRep));
86 var lowB: u64 = @as(u64, @truncate(bRep));
85 var lowA: u64 = @truncate(aRep);
86 var lowB: u64 = @truncate(bRep);
8787
8888 while (expA > expB) : (expA -= 1) {
8989 var high = highA -% highB;
......@@ -125,7 +125,7 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
125125 if (expA < -fractionalBits) {
126126 return @bitCast(signA);
127127 } else if (expA <= 0) {
128 return @bitCast((lowA >> @as(math.Log2Int(u64), @intCast(1 - expA))) | signA);
128 return @bitCast((lowA >> @intCast(1 - expA)) | signA);
129129 } else {
130130 return @bitCast(lowA | (@as(Z, @as(u16, @intCast(expA))) << significandBits) | signA);
131131 }
......@@ -136,10 +136,10 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
136136pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
137137 var amod = a;
138138 var bmod = b;
139 const aPtr_u64 = @as([*]u64, @ptrCast(&amod));
140 const bPtr_u64 = @as([*]u64, @ptrCast(&bmod));
141 const aPtr_u16 = @as([*]u16, @ptrCast(&amod));
142 const bPtr_u16 = @as([*]u16, @ptrCast(&bmod));
139 const aPtr_u64: [*]u64 = @ptrCast(&amod);
140 const bPtr_u64: [*]u64 = @ptrCast(&bmod);
141 const aPtr_u16: [*]u16 = @ptrCast(&amod);
142 const bPtr_u16: [*]u16 = @ptrCast(&bmod);
143143
144144 const exp_and_sign_index = comptime switch (builtin.target.cpu.arch.endian()) {
145145 .Little => 7,
......@@ -173,8 +173,8 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
173173 }
174174
175175 // Remove the sign from both
176 aPtr_u16[exp_and_sign_index] = @as(u16, @bitCast(@as(i16, @intCast(expA))));
177 bPtr_u16[exp_and_sign_index] = @as(u16, @bitCast(@as(i16, @intCast(expB))));
176 aPtr_u16[exp_and_sign_index] = @bitCast(@as(i16, @intCast(expA)));
177 bPtr_u16[exp_and_sign_index] = @bitCast(@as(i16, @intCast(expB)));
178178 if (amod <= bmod) {
179179 if (amod == bmod) {
180180 return 0 * a;
......@@ -264,7 +264,6 @@ pub fn fmodl(a: c_longdouble, b: c_longdouble) callconv(.C) c_longdouble {
264264inline fn generic_fmod(comptime T: type, x: T, y: T) T {
265265 const bits = @typeInfo(T).Float.bits;
266266 const uint = std.meta.Int(.unsigned, bits);
267 const log2uint = math.Log2Int(uint);
268267 comptime assert(T == f32 or T == f64);
269268 const digits = if (T == f32) 23 else 52;
270269 const exp_bits = if (T == f32) 9 else 12;
......@@ -293,7 +292,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {
293292 ex -= 1;
294293 i <<= 1;
295294 }) {}
296 ux <<= @as(log2uint, @intCast(@as(u32, @bitCast(-ex + 1))));
295 ux <<= @intCast(@as(u32, @bitCast(-ex + 1)));
297296 } else {
298297 ux &= math.maxInt(uint) >> exp_bits;
299298 ux |= 1 << digits;
......@@ -304,7 +303,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {
304303 ey -= 1;
305304 i <<= 1;
306305 }) {}
307 uy <<= @as(log2uint, @intCast(@as(u32, @bitCast(-ey + 1))));
306 uy <<= @intCast(@as(u32, @bitCast(-ey + 1)));
308307 } else {
309308 uy &= math.maxInt(uint) >> exp_bits;
310309 uy |= 1 << digits;
......@@ -336,7 +335,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {
336335 ux -%= 1 << digits;
337336 ux |= @as(uint, @as(u32, @bitCast(ex))) << digits;
338337 } else {
339 ux >>= @as(log2uint, @intCast(@as(u32, @bitCast(-ex + 1))));
338 ux >>= @intCast(@as(u32, @bitCast(-ex + 1)));
340339 }
341340 if (T == f32) {
342341 ux |= sx;
lib/compiler_rt/int.zig+33-33
......@@ -52,8 +52,8 @@ test "test_divmodti4" {
5252 [_]i128{ -7, 5, -1, -2 },
5353 [_]i128{ 19, 5, 3, 4 },
5454 [_]i128{ 19, -5, -3, 4 },
55 [_]i128{ @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 8, @as(i128, @bitCast(@as(u128, 0xf0000000000000000000000000000000))), 0 },
56 [_]i128{ @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000007))), 8, @as(i128, @bitCast(@as(u128, 0xf0000000000000000000000000000001))), -1 },
55 [_]i128{ @bitCast(@as(u128, 0x80000000000000000000000000000000)), 8, @bitCast(@as(u128, 0xf0000000000000000000000000000000)), 0 },
56 [_]i128{ @bitCast(@as(u128, 0x80000000000000000000000000000007)), 8, @bitCast(@as(u128, 0xf0000000000000000000000000000001)), -1 },
5757 };
5858
5959 for (cases) |case| {
......@@ -85,8 +85,8 @@ test "test_divmoddi4" {
8585 [_]i64{ -7, 5, -1, -2 },
8686 [_]i64{ 19, 5, 3, 4 },
8787 [_]i64{ 19, -5, -3, 4 },
88 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 8, @as(i64, @bitCast(@as(u64, 0xf000000000000000))), 0 },
89 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000007))), 8, @as(i64, @bitCast(@as(u64, 0xf000000000000001))), -1 },
88 [_]i64{ @bitCast(@as(u64, 0x8000000000000000)), 8, @bitCast(@as(u64, 0xf000000000000000)), 0 },
89 [_]i64{ @bitCast(@as(u64, 0x8000000000000007)), 8, @bitCast(@as(u64, 0xf000000000000001)), -1 },
9090 };
9191
9292 for (cases) |case| {
......@@ -110,14 +110,14 @@ test "test_udivmoddi4" {
110110
111111pub fn __divdi3(a: i64, b: i64) callconv(.C) i64 {
112112 // Set aside the sign of the quotient.
113 const sign = @as(u64, @bitCast((a ^ b) >> 63));
113 const sign: u64 = @bitCast((a ^ b) >> 63);
114114 // Take absolute value of a and b via abs(x) = (x^(x >> 63)) - (x >> 63).
115115 const abs_a = (a ^ (a >> 63)) -% (a >> 63);
116116 const abs_b = (b ^ (b >> 63)) -% (b >> 63);
117117 // Unsigned division
118 const res = __udivmoddi4(@as(u64, @bitCast(abs_a)), @as(u64, @bitCast(abs_b)), null);
118 const res = __udivmoddi4(@bitCast(abs_a), @bitCast(abs_b), null);
119119 // Apply sign of quotient to result and return.
120 return @as(i64, @bitCast((res ^ sign) -% sign));
120 return @bitCast((res ^ sign) -% sign);
121121}
122122
123123test "test_divdi3" {
......@@ -151,7 +151,7 @@ pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 {
151151 const abs_b = (b ^ (b >> 63)) -% (b >> 63);
152152 // Unsigned division
153153 var r: u64 = undefined;
154 _ = __udivmoddi4(@as(u64, @bitCast(abs_a)), @as(u64, @bitCast(abs_b)), &r);
154 _ = __udivmoddi4(@bitCast(abs_a), @bitCast(abs_b), &r);
155155 // Apply the sign of the dividend and return.
156156 return (@as(i64, @bitCast(r)) ^ (a >> 63)) -% (a >> 63);
157157}
......@@ -165,12 +165,12 @@ test "test_moddi3" {
165165 [_]i64{ -5, 3, -2 },
166166 [_]i64{ -5, -3, -2 },
167167
168 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1, 0 },
169 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), -1, 0 },
170 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 2, 0 },
171 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), -2, 0 },
172 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 3, -2 },
173 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), -3, -2 },
168 [_]i64{ @bitCast(@as(u64, 0x8000000000000000)), 1, 0 },
169 [_]i64{ @bitCast(@as(u64, 0x8000000000000000)), -1, 0 },
170 [_]i64{ @bitCast(@as(u64, 0x8000000000000000)), 2, 0 },
171 [_]i64{ @bitCast(@as(u64, 0x8000000000000000)), -2, 0 },
172 [_]i64{ @bitCast(@as(u64, 0x8000000000000000)), 3, -2 },
173 [_]i64{ @bitCast(@as(u64, 0x8000000000000000)), -3, -2 },
174174 };
175175
176176 for (cases) |case| {
......@@ -225,8 +225,8 @@ test "test_divmodsi4" {
225225 [_]i32{ 19, 5, 3, 4 },
226226 [_]i32{ 19, -5, -3, 4 },
227227
228 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), 8, @as(i32, @bitCast(@as(u32, 0xf0000000))), 0 },
229 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000007))), 8, @as(i32, @bitCast(@as(u32, 0xf0000001))), -1 },
228 [_]i32{ @bitCast(@as(u32, 0x80000000)), 8, @bitCast(@as(u32, 0xf0000000)), 0 },
229 [_]i32{ @bitCast(@as(u32, 0x80000007)), 8, @bitCast(@as(u32, 0xf0000001)), -1 },
230230 };
231231
232232 for (cases) |case| {
......@@ -242,7 +242,7 @@ fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) !void {
242242
243243pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {
244244 const d = __udivsi3(a, b);
245 rem.* = @as(u32, @bitCast(@as(i32, @bitCast(a)) -% (@as(i32, @bitCast(d)) * @as(i32, @bitCast(b)))));
245 rem.* = @bitCast(@as(i32, @bitCast(a)) -% (@as(i32, @bitCast(d)) * @as(i32, @bitCast(b))));
246246 return d;
247247}
248248
......@@ -256,14 +256,14 @@ fn __aeabi_idiv(n: i32, d: i32) callconv(.AAPCS) i32 {
256256
257257inline fn div_i32(n: i32, d: i32) i32 {
258258 // Set aside the sign of the quotient.
259 const sign = @as(u32, @bitCast((n ^ d) >> 31));
259 const sign: u32 = @bitCast((n ^ d) >> 31);
260260 // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
261261 const abs_n = (n ^ (n >> 31)) -% (n >> 31);
262262 const abs_d = (d ^ (d >> 31)) -% (d >> 31);
263263 // abs(a) / abs(b)
264264 const res = @as(u32, @bitCast(abs_n)) / @as(u32, @bitCast(abs_d));
265265 // Apply sign of quotient to result and return.
266 return @as(i32, @bitCast((res ^ sign) -% sign));
266 return @bitCast((res ^ sign) -% sign);
267267}
268268
269269test "test_divsi3" {
......@@ -275,10 +275,10 @@ test "test_divsi3" {
275275 [_]i32{ -2, 1, -2 },
276276 [_]i32{ -2, -1, 2 },
277277
278 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), 1, @as(i32, @bitCast(@as(u32, 0x80000000))) },
279 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), -1, @as(i32, @bitCast(@as(u32, 0x80000000))) },
280 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), -2, 0x40000000 },
281 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), 2, @as(i32, @bitCast(@as(u32, 0xC0000000))) },
278 [_]i32{ @bitCast(@as(u32, 0x80000000)), 1, @bitCast(@as(u32, 0x80000000)) },
279 [_]i32{ @bitCast(@as(u32, 0x80000000)), -1, @bitCast(@as(u32, 0x80000000)) },
280 [_]i32{ @bitCast(@as(u32, 0x80000000)), -2, 0x40000000 },
281 [_]i32{ @bitCast(@as(u32, 0x80000000)), 2, @bitCast(@as(u32, 0xC0000000)) },
282282 };
283283
284284 for (cases) |case| {
......@@ -317,12 +317,12 @@ inline fn div_u32(n: u32, d: u32) u32 {
317317 sr += 1;
318318 // 1 <= sr <= n_uword_bits - 1
319319 // Not a special case
320 var q: u32 = n << @as(u5, @intCast(n_uword_bits - sr));
321 var r: u32 = n >> @as(u5, @intCast(sr));
320 var q: u32 = n << @intCast(n_uword_bits - sr);
321 var r: u32 = n >> @intCast(sr);
322322 var carry: u32 = 0;
323323 while (sr > 0) : (sr -= 1) {
324324 // r:q = ((r:q) << 1) | carry
325 r = (r << 1) | (q >> @as(u5, @intCast(n_uword_bits - 1)));
325 r = (r << 1) | (q >> @intCast(n_uword_bits - 1));
326326 q = (q << 1) | carry;
327327 // carry = 0;
328328 // if (r.all >= d.all)
......@@ -330,8 +330,8 @@ inline fn div_u32(n: u32, d: u32) u32 {
330330 // r.all -= d.all;
331331 // carry = 1;
332332 // }
333 const s = @as(i32, @bitCast(d -% r -% 1)) >> @as(u5, @intCast(n_uword_bits - 1));
334 carry = @as(u32, @intCast(s & 1));
333 const s = @as(i32, @bitCast(d -% r -% 1)) >> @intCast(n_uword_bits - 1);
334 carry = @intCast(s & 1);
335335 r -= d & @as(u32, @bitCast(s));
336336 }
337337 q = (q << 1) | carry;
......@@ -496,11 +496,11 @@ test "test_modsi3" {
496496 [_]i32{ 5, -3, 2 },
497497 [_]i32{ -5, 3, -2 },
498498 [_]i32{ -5, -3, -2 },
499 [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 1, 0x0 },
500 [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 2, 0x0 },
501 [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), -2, 0x0 },
502 [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 3, -2 },
503 [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), -3, -2 },
499 [_]i32{ @bitCast(@as(u32, @intCast(0x80000000))), 1, 0x0 },
500 [_]i32{ @bitCast(@as(u32, @intCast(0x80000000))), 2, 0x0 },
501 [_]i32{ @bitCast(@as(u32, @intCast(0x80000000))), -2, 0x0 },
502 [_]i32{ @bitCast(@as(u32, @intCast(0x80000000))), 3, -2 },
503 [_]i32{ @bitCast(@as(u32, @intCast(0x80000000))), -3, -2 },
504504 };
505505
506506 for (cases) |case| {
lib/compiler_rt/int_from_float.zig+3-3
......@@ -17,7 +17,7 @@ pub inline fn intFromFloat(comptime I: type, a: anytype) I {
1717 const sig_mask = (@as(rep_t, 1) << sig_bits) - 1;
1818
1919 // Break a into sign, exponent, significand
20 const a_rep: rep_t = @as(rep_t, @bitCast(a));
20 const a_rep: rep_t = @bitCast(a);
2121 const negative = (a_rep >> (float_bits - 1)) != 0;
2222 const exponent = @as(i32, @intCast((a_rep << 1) >> (sig_bits + 1))) - exp_bias;
2323 const significand: rep_t = (a_rep & sig_mask) | implicit_bit;
......@@ -40,9 +40,9 @@ pub inline fn intFromFloat(comptime I: type, a: anytype) I {
4040 // Otherwise, shift left.
4141 var result: I = undefined;
4242 if (exponent < fractional_bits) {
43 result = @as(I, @intCast(significand >> @as(Log2Int(rep_t), @intCast(fractional_bits - exponent))));
43 result = @intCast(significand >> @intCast(fractional_bits - exponent));
4444 } else {
45 result = @as(I, @intCast(significand)) << @as(Log2Int(I), @intCast(exponent - fractional_bits));
45 result = @as(I, @intCast(significand)) << @intCast(exponent - fractional_bits);
4646 }
4747
4848 if ((@typeInfo(I).Int.signedness == .signed) and negative)
lib/compiler_rt/log10.zig+6-6
......@@ -28,7 +28,7 @@ comptime {
2828
2929pub fn __log10h(a: f16) callconv(.C) f16 {
3030 // TODO: more efficient implementation
31 return @as(f16, @floatCast(log10f(a)));
31 return @floatCast(log10f(a));
3232}
3333
3434pub fn log10f(x_: f32) callconv(.C) f32 {
......@@ -42,7 +42,7 @@ pub fn log10f(x_: f32) callconv(.C) f32 {
4242 const Lg4: f32 = 0xf89e26.0p-26;
4343
4444 var x = x_;
45 var u = @as(u32, @bitCast(x));
45 var u: u32 = @bitCast(x);
4646 var ix = u;
4747 var k: i32 = 0;
4848
......@@ -59,7 +59,7 @@ pub fn log10f(x_: f32) callconv(.C) f32 {
5959
6060 k -= 25;
6161 x *= 0x1.0p25;
62 ix = @as(u32, @bitCast(x));
62 ix = @bitCast(x);
6363 } else if (ix >= 0x7F800000) {
6464 return x;
6565 } else if (ix == 0x3F800000) {
......@@ -70,7 +70,7 @@ pub fn log10f(x_: f32) callconv(.C) f32 {
7070 ix += 0x3F800000 - 0x3F3504F3;
7171 k += @as(i32, @intCast(ix >> 23)) - 0x7F;
7272 ix = (ix & 0x007FFFFF) + 0x3F3504F3;
73 x = @as(f32, @bitCast(ix));
73 x = @bitCast(ix);
7474
7575 const f = x - 1.0;
7676 const s = f / (2.0 + f);
......@@ -168,12 +168,12 @@ pub fn log10(x_: f64) callconv(.C) f64 {
168168
169169pub fn __log10x(a: f80) callconv(.C) f80 {
170170 // TODO: more efficient implementation
171 return @as(f80, @floatCast(log10q(a)));
171 return @floatCast(log10q(a));
172172}
173173
174174pub fn log10q(a: f128) callconv(.C) f128 {
175175 // TODO: more correct implementation
176 return log10(@as(f64, @floatCast(a)));
176 return log10(@floatCast(a));
177177}
178178
179179pub fn log10l(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/modti3_test.zig+1-1
......@@ -33,5 +33,5 @@ fn make_ti(high: u64, low: u64) i128 {
3333 var result: u128 = high;
3434 result <<= 64;
3535 result |= low;
36 return @as(i128, @bitCast(result));
36 return @bitCast(result);
3737}
lib/compiler_rt/mulf3.zig+18-19
......@@ -29,16 +29,16 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
2929
3030 const absMask = signBit - 1;
3131 const qnanRep = @as(Z, @bitCast(math.nan(T))) | quietBit;
32 const infRep = @as(Z, @bitCast(math.inf(T)));
33 const minNormalRep = @as(Z, @bitCast(math.floatMin(T)));
32 const infRep: Z = @bitCast(math.inf(T));
33 const minNormalRep: Z = @bitCast(math.floatMin(T));
3434
3535 const ZExp = if (typeWidth >= 32) u32 else Z;
36 const aExponent = @as(ZExp, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
37 const bExponent = @as(ZExp, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
36 const aExponent: ZExp = @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent);
37 const bExponent: ZExp = @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent);
3838 const productSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
3939
40 var aSignificand: ZSignificand = @as(ZSignificand, @intCast(@as(Z, @bitCast(a)) & significandMask));
41 var bSignificand: ZSignificand = @as(ZSignificand, @intCast(@as(Z, @bitCast(b)) & significandMask));
40 var aSignificand: ZSignificand = @intCast(@as(Z, @bitCast(a)) & significandMask);
41 var bSignificand: ZSignificand = @intCast(@as(Z, @bitCast(b)) & significandMask);
4242 var scale: i32 = 0;
4343
4444 // Detect if a or b is zero, denormal, infinity, or NaN.
......@@ -47,9 +47,9 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
4747 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
4848
4949 // NaN * anything = qNaN
50 if (aAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(a)) | quietBit));
50 if (aAbs > infRep) return @bitCast(@as(Z, @bitCast(a)) | quietBit);
5151 // anything * NaN = qNaN
52 if (bAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(b)) | quietBit));
52 if (bAbs > infRep) return @bitCast(@as(Z, @bitCast(b)) | quietBit);
5353
5454 if (aAbs == infRep) {
5555 // infinity * non-zero = +/- infinity
......@@ -110,7 +110,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
110110 }
111111
112112 // If we have overflowed the type, return +/- infinity.
113 if (productExponent >= maxExponent) return @as(T, @bitCast(infRep | productSign));
113 if (productExponent >= maxExponent) return @bitCast(infRep | productSign);
114114
115115 var result: Z = undefined;
116116 if (productExponent <= 0) {
......@@ -120,8 +120,8 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
120120 // a zero of the appropriate sign. Mathematically there is no need to
121121 // handle this case separately, but we make it a special case to
122122 // simplify the shift logic.
123 const shift: u32 = @as(u32, @truncate(@as(Z, 1) -% @as(u32, @bitCast(productExponent))));
124 if (shift >= ZSignificandBits) return @as(T, @bitCast(productSign));
123 const shift: u32 = @truncate(@as(Z, 1) -% @as(u32, @bitCast(productExponent)));
124 if (shift >= ZSignificandBits) return @bitCast(productSign);
125125
126126 // Otherwise, shift the significand of the result so that the round
127127 // bit is the high bit of productLo.
......@@ -156,7 +156,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
156156 // Insert the sign of the result:
157157 result |= productSign;
158158
159 return @as(T, @bitCast(result));
159 return @bitCast(result);
160160}
161161
162162/// Returns `true` if the right shift is inexact (i.e. any bit shifted out is non-zero)
......@@ -165,15 +165,14 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
165165fn wideShrWithTruncation(comptime Z: type, hi: *Z, lo: *Z, count: u32) bool {
166166 @setRuntimeSafety(builtin.is_test);
167167 const typeWidth = @typeInfo(Z).Int.bits;
168 const S = math.Log2Int(Z);
169168 var inexact = false;
170169 if (count < typeWidth) {
171 inexact = (lo.* << @as(S, @intCast(typeWidth -% count))) != 0;
172 lo.* = (hi.* << @as(S, @intCast(typeWidth -% count))) | (lo.* >> @as(S, @intCast(count)));
173 hi.* = hi.* >> @as(S, @intCast(count));
170 inexact = (lo.* << @intCast(typeWidth -% count)) != 0;
171 lo.* = (hi.* << @intCast(typeWidth -% count)) | (lo.* >> @intCast(count));
172 hi.* = hi.* >> @intCast(count);
174173 } else if (count < 2 * typeWidth) {
175 inexact = (hi.* << @as(S, @intCast(2 * typeWidth -% count)) | lo.*) != 0;
176 lo.* = hi.* >> @as(S, @intCast(count -% typeWidth));
174 inexact = (hi.* << @intCast(2 * typeWidth -% count) | lo.*) != 0;
175 lo.* = hi.* >> @intCast(count -% typeWidth);
177176 hi.* = 0;
178177 } else {
179178 inexact = (hi.* | lo.*) != 0;
......@@ -188,7 +187,7 @@ fn normalize(comptime T: type, significand: *PowerOfTwoSignificandZ(T)) i32 {
188187 const integerBit = @as(Z, 1) << math.floatFractionalBits(T);
189188
190189 const shift = @clz(significand.*) - @clz(integerBit);
191 significand.* <<= @as(math.Log2Int(Z), @intCast(shift));
190 significand.* <<= @intCast(shift);
192191 return @as(i32, 1) - shift;
193192}
194193
lib/compiler_rt/parity.zig+2-7
......@@ -26,12 +26,7 @@ pub fn __parityti2(a: i128) callconv(.C) i32 {
2626}
2727
2828inline fn parityXi2(comptime T: type, a: T) i32 {
29 var x = switch (@bitSizeOf(T)) {
30 32 => @as(u32, @bitCast(a)),
31 64 => @as(u64, @bitCast(a)),
32 128 => @as(u128, @bitCast(a)),
33 else => unreachable,
34 };
29 var x: std.meta.Int(.unsigned, @typeInfo(T).Int.bits) = @bitCast(a);
3530 // Bit Twiddling Hacks: Compute parity in parallel
3631 comptime var shift: u8 = @bitSizeOf(T) / 2;
3732 inline while (shift > 2) {
......@@ -39,7 +34,7 @@ inline fn parityXi2(comptime T: type, a: T) i32 {
3934 shift = shift >> 1;
4035 }
4136 x &= 0xf;
42 return (@as(u16, @intCast(0x6996)) >> @as(u4, @intCast(x))) & 1; // optimization for >>2 and >>1
37 return (@as(u16, 0x6996) >> @intCast(x)) & 1; // optimization for >>2 and >>1
4338}
4439
4540test {
lib/compiler_rt/paritydi2_test.zig+5-5
......@@ -3,13 +3,13 @@ const parity = @import("parity.zig");
33const testing = std.testing;
44
55fn paritydi2Naive(a: i64) i32 {
6 var x = @as(u64, @bitCast(a));
6 var x: u64 = @bitCast(a);
77 var has_parity: bool = false;
88 while (x > 0) {
99 has_parity = !has_parity;
1010 x = x & (x - 1);
1111 }
12 return @as(i32, @intCast(@intFromBool(has_parity)));
12 return @intCast(@intFromBool(has_parity));
1313}
1414
1515fn test__paritydi2(a: i64) !void {
......@@ -22,9 +22,9 @@ test "paritydi2" {
2222 try test__paritydi2(0);
2323 try test__paritydi2(1);
2424 try test__paritydi2(2);
25 try test__paritydi2(@as(i64, @bitCast(@as(u64, 0xffffffff_fffffffd))));
26 try test__paritydi2(@as(i64, @bitCast(@as(u64, 0xffffffff_fffffffe))));
27 try test__paritydi2(@as(i64, @bitCast(@as(u64, 0xffffffff_ffffffff))));
25 try test__paritydi2(@bitCast(@as(u64, 0xffffffff_fffffffd)));
26 try test__paritydi2(@bitCast(@as(u64, 0xffffffff_fffffffe)));
27 try test__paritydi2(@bitCast(@as(u64, 0xffffffff_ffffffff)));
2828
2929 const RndGen = std.rand.DefaultPrng;
3030 var rnd = RndGen.init(42);
lib/compiler_rt/paritysi2_test.zig+5-5
......@@ -3,13 +3,13 @@ const parity = @import("parity.zig");
33const testing = std.testing;
44
55fn paritysi2Naive(a: i32) i32 {
6 var x = @as(u32, @bitCast(a));
6 var x: u32 = @bitCast(a);
77 var has_parity: bool = false;
88 while (x > 0) {
99 has_parity = !has_parity;
1010 x = x & (x - 1);
1111 }
12 return @as(i32, @intCast(@intFromBool(has_parity)));
12 return @intCast(@intFromBool(has_parity));
1313}
1414
1515fn test__paritysi2(a: i32) !void {
......@@ -22,9 +22,9 @@ test "paritysi2" {
2222 try test__paritysi2(0);
2323 try test__paritysi2(1);
2424 try test__paritysi2(2);
25 try test__paritysi2(@as(i32, @bitCast(@as(u32, 0xfffffffd))));
26 try test__paritysi2(@as(i32, @bitCast(@as(u32, 0xfffffffe))));
27 try test__paritysi2(@as(i32, @bitCast(@as(u32, 0xffffffff))));
25 try test__paritysi2(@bitCast(@as(u32, 0xfffffffd)));
26 try test__paritysi2(@bitCast(@as(u32, 0xfffffffe)));
27 try test__paritysi2(@bitCast(@as(u32, 0xffffffff)));
2828
2929 const RndGen = std.rand.DefaultPrng;
3030 var rnd = RndGen.init(42);
lib/compiler_rt/parityti2_test.zig+4-4
......@@ -9,7 +9,7 @@ fn parityti2Naive(a: i128) i32 {
99 has_parity = !has_parity;
1010 x = x & (x - 1);
1111 }
12 return @as(i32, @intCast(@intFromBool(has_parity)));
12 return @intCast(@intFromBool(has_parity));
1313}
1414
1515fn test__parityti2(a: i128) !void {
......@@ -22,9 +22,9 @@ test "parityti2" {
2222 try test__parityti2(0);
2323 try test__parityti2(1);
2424 try test__parityti2(2);
25 try test__parityti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffd))));
26 try test__parityti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffe))));
27 try test__parityti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_ffffffff))));
25 try test__parityti2(@bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffd)));
26 try test__parityti2(@bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffe)));
27 try test__parityti2(@bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_ffffffff)));
2828
2929 const RndGen = std.rand.DefaultPrng;
3030 var rnd = RndGen.init(42);
lib/compiler_rt/popcount.zig+2-2
......@@ -37,7 +37,7 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 {
3737 i128 => u128,
3838 else => unreachable,
3939 };
40 var x = @as(UT, @bitCast(a));
40 var x: UT = @bitCast(a);
4141 x -= (x >> 1) & (~@as(UT, 0) / 3); // 0x55...55, aggregate duos
4242 x = ((x >> 2) & (~@as(UT, 0) / 5)) // 0x33...33, aggregate nibbles
4343 + (x & (~@as(UT, 0) / 5));
......@@ -46,7 +46,7 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 {
4646 // 8 most significant bits of x + (x<<8) + (x<<16) + ..
4747 x *%= ~@as(UT, 0) / 255; // 0x01...01
4848 x >>= (@bitSizeOf(ST) - 8);
49 return @as(i32, @intCast(x));
49 return @intCast(x);
5050}
5151
5252test {
lib/compiler_rt/rem_pio2.zig+6-10
......@@ -25,10 +25,6 @@ const pio2_3 = 2.02226624871116645580e-21; // 0x3BA3198A, 0x2E000000
2525// pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3)
2626const pio2_3t = 8.47842766036889956997e-32; // 0x397B839A, 0x252049C1
2727
28fn U(x: anytype) usize {
29 return @as(usize, @intCast(x));
30}
31
3228fn medium(ix: u32, x: f64, y: *[2]f64) i32 {
3329 var w: f64 = undefined;
3430 var t: f64 = undefined;
......@@ -41,7 +37,7 @@ fn medium(ix: u32, x: f64, y: *[2]f64) i32 {
4137
4238 // rint(x/(pi/2))
4339 @"fn" = x * invpio2 + toint - toint;
44 n = @as(i32, @intFromFloat(@"fn"));
40 n = @intFromFloat(@"fn");
4541 r = x - @"fn" * pio2_1;
4642 w = @"fn" * pio2_1t; // 1st round, good to 85 bits
4743 // Matters with directed rounding.
......@@ -174,16 +170,16 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 {
174170 ui = @bitCast(x);
175171 ui &= std.math.maxInt(u64) >> 12;
176172 ui |= @as(u64, 0x3ff + 23) << 52;
177 z = @as(f64, @bitCast(ui));
173 z = @bitCast(ui);
178174
179175 i = 0;
180176 while (i < 2) : (i += 1) {
181 tx[U(i)] = @as(f64, @floatFromInt(@as(i32, @intFromFloat(z))));
182 z = (z - tx[U(i)]) * 0x1p24;
177 tx[@intCast(i)] = @floatFromInt(@as(i32, @intFromFloat(z)));
178 z = (z - tx[@intCast(i)]) * 0x1p24;
183179 }
184 tx[U(i)] = z;
180 tx[@intCast(i)] = z;
185181 // skip zero terms, first term is non-zero
186 while (tx[U(i)] == 0.0) {
182 while (tx[@intCast(i)] == 0.0) {
187183 i -= 1;
188184 }
189185 n = rem_pio2_large(tx[0..], ty[0..], @as(i32, @intCast((ix >> 20))) - (0x3ff + 23), i + 1, 1);
lib/compiler_rt/rem_pio2_large.zig+38-42
......@@ -149,10 +149,6 @@ const PIo2 = [_]f64{
149149 2.16741683877804819444e-51, // 0x3569F31D, 0x00000000
150150};
151151
152fn U(x: anytype) usize {
153 return @as(usize, @intCast(x));
154}
155
156152/// Returns the last three digits of N with y = x - N*pi/2 so that |y| < pi/2.
157153///
158154/// The method is to compute the integer (mod 8) and fraction parts of
......@@ -295,7 +291,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
295291 i += 1;
296292 j += 1;
297293 }) {
298 f[U(i)] = if (j < 0) 0.0 else @as(f64, @floatFromInt(ipio2[U(j)]));
294 f[@intCast(i)] = if (j < 0) 0.0 else @floatFromInt(ipio2[@intCast(j)]);
299295 }
300296
301297 // compute q[0],q[1],...q[jk]
......@@ -304,9 +300,9 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
304300 j = 0;
305301 fw = 0;
306302 while (j <= jx) : (j += 1) {
307 fw += x[U(j)] * f[U(jx + i - j)];
303 fw += x[@intCast(j)] * f[@intCast(jx + i - j)];
308304 }
309 q[U(i)] = fw;
305 q[@intCast(i)] = fw;
310306 }
311307
312308 jz = jk;
......@@ -317,29 +313,29 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
317313 // distill q[] into iq[] reversingly
318314 i = 0;
319315 j = jz;
320 z = q[U(jz)];
316 z = q[@intCast(jz)];
321317 while (j > 0) : ({
322318 i += 1;
323319 j -= 1;
324320 }) {
325321 fw = @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z)));
326 iq[U(i)] = @as(i32, @intFromFloat(z - 0x1p24 * fw));
327 z = q[U(j - 1)] + fw;
322 iq[@intCast(i)] = @intFromFloat(z - 0x1p24 * fw);
323 z = q[@intCast(j - 1)] + fw;
328324 }
329325
330326 // compute n
331327 z = math.scalbn(z, q0); // actual value of z
332328 z -= 8.0 * @floor(z * 0.125); // trim off integer >= 8
333329 n = @intFromFloat(z);
334 z -= @as(f64, @floatFromInt(n));
330 z -= @floatFromInt(n);
335331 ih = 0;
336332 if (q0 > 0) { // need iq[jz-1] to determine n
337 i = iq[U(jz - 1)] >> @as(u5, @intCast(24 - q0));
333 i = iq[@intCast(jz - 1)] >> @intCast(24 - q0);
338334 n += i;
339 iq[U(jz - 1)] -= i << @as(u5, @intCast(24 - q0));
340 ih = iq[U(jz - 1)] >> @as(u5, @intCast(23 - q0));
335 iq[@intCast(jz - 1)] -= i << @intCast(24 - q0);
336 ih = iq[@intCast(jz - 1)] >> @intCast(23 - q0);
341337 } else if (q0 == 0) {
342 ih = iq[U(jz - 1)] >> 23;
338 ih = iq[@intCast(jz - 1)] >> 23;
343339 } else if (z >= 0.5) {
344340 ih = 2;
345341 }
......@@ -349,20 +345,20 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
349345 carry = 0;
350346 i = 0;
351347 while (i < jz) : (i += 1) { // compute 1-q
352 j = iq[U(i)];
348 j = iq[@intCast(i)];
353349 if (carry == 0) {
354350 if (j != 0) {
355351 carry = 1;
356 iq[U(i)] = 0x1000000 - j;
352 iq[@intCast(i)] = 0x1000000 - j;
357353 }
358354 } else {
359 iq[U(i)] = 0xffffff - j;
355 iq[@intCast(i)] = 0xffffff - j;
360356 }
361357 }
362358 if (q0 > 0) { // rare case: chance is 1 in 12
363359 switch (q0) {
364 1 => iq[U(jz - 1)] &= 0x7fffff,
365 2 => iq[U(jz - 1)] &= 0x3fffff,
360 1 => iq[@intCast(jz - 1)] &= 0x7fffff,
361 2 => iq[@intCast(jz - 1)] &= 0x3fffff,
366362 else => unreachable,
367363 }
368364 }
......@@ -379,24 +375,24 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
379375 j = 0;
380376 i = jz - 1;
381377 while (i >= jk) : (i -= 1) {
382 j |= iq[U(i)];
378 j |= iq[@intCast(i)];
383379 }
384380
385381 if (j == 0) { // need recomputation
386382 k = 1;
387 while (iq[U(jk - k)] == 0) : (k += 1) {
383 while (iq[@intCast(jk - k)] == 0) : (k += 1) {
388384 // k = no. of terms needed
389385 }
390386
391387 i = jz + 1;
392388 while (i <= jz + k) : (i += 1) { // add q[jz+1] to q[jz+k]
393 f[U(jx + i)] = @as(f64, @floatFromInt(ipio2[U(jv + i)]));
389 f[@intCast(jx + i)] = @floatFromInt(ipio2[@intCast(jv + i)]);
394390 j = 0;
395391 fw = 0;
396392 while (j <= jx) : (j += 1) {
397 fw += x[U(j)] * f[U(jx + i - j)];
393 fw += x[@intCast(j)] * f[@intCast(jx + i - j)];
398394 }
399 q[U(i)] = fw;
395 q[@intCast(i)] = fw;
400396 }
401397 jz += k;
402398 continue :recompute; // mimic goto recompute
......@@ -407,7 +403,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
407403 if (z == 0.0) {
408404 jz -= 1;
409405 q0 -= 24;
410 while (iq[U(jz)] == 0) {
406 while (iq[@intCast(jz)] == 0) {
411407 jz -= 1;
412408 q0 -= 24;
413409 }
......@@ -415,12 +411,12 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
415411 z = math.scalbn(z, -q0);
416412 if (z >= 0x1p24) {
417413 fw = @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z)));
418 iq[U(jz)] = @as(i32, @intFromFloat(z - 0x1p24 * fw));
414 iq[@intCast(jz)] = @intFromFloat(z - 0x1p24 * fw);
419415 jz += 1;
420416 q0 += 24;
421 iq[U(jz)] = @as(i32, @intFromFloat(fw));
417 iq[@intCast(jz)] = @intFromFloat(fw);
422418 } else {
423 iq[U(jz)] = @as(i32, @intFromFloat(z));
419 iq[@intCast(jz)] = @intFromFloat(z);
424420 }
425421 }
426422
......@@ -428,7 +424,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
428424 fw = math.scalbn(@as(f64, 1.0), q0);
429425 i = jz;
430426 while (i >= 0) : (i -= 1) {
431 q[U(i)] = fw * @as(f64, @floatFromInt(iq[U(i)]));
427 q[@intCast(i)] = fw * @as(f64, @floatFromInt(iq[@intCast(i)]));
432428 fw *= 0x1p-24;
433429 }
434430
......@@ -438,9 +434,9 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
438434 fw = 0;
439435 k = 0;
440436 while (k <= jp and k <= jz - i) : (k += 1) {
441 fw += PIo2[U(k)] * q[U(i + k)];
437 fw += PIo2[@intCast(k)] * q[@intCast(i + k)];
442438 }
443 fq[U(jz - i)] = fw;
439 fq[@intCast(jz - i)] = fw;
444440 }
445441
446442 // compress fq[] into y[]
......@@ -449,7 +445,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
449445 fw = 0.0;
450446 i = jz;
451447 while (i >= 0) : (i -= 1) {
452 fw += fq[U(i)];
448 fw += fq[@intCast(i)];
453449 }
454450 y[0] = if (ih == 0) fw else -fw;
455451 },
......@@ -458,7 +454,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
458454 fw = 0.0;
459455 i = jz;
460456 while (i >= 0) : (i -= 1) {
461 fw += fq[U(i)];
457 fw += fq[@intCast(i)];
462458 }
463459 // TODO: drop excess precision here once double_t is used
464460 fw = fw;
......@@ -466,27 +462,27 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
466462 fw = fq[0] - fw;
467463 i = 1;
468464 while (i <= jz) : (i += 1) {
469 fw += fq[U(i)];
465 fw += fq[@intCast(i)];
470466 }
471467 y[1] = if (ih == 0) fw else -fw;
472468 },
473469 3 => { // painful
474470 i = jz;
475471 while (i > 0) : (i -= 1) {
476 fw = fq[U(i - 1)] + fq[U(i)];
477 fq[U(i)] += fq[U(i - 1)] - fw;
478 fq[U(i - 1)] = fw;
472 fw = fq[@intCast(i - 1)] + fq[@intCast(i)];
473 fq[@intCast(i)] += fq[@intCast(i - 1)] - fw;
474 fq[@intCast(i - 1)] = fw;
479475 }
480476 i = jz;
481477 while (i > 1) : (i -= 1) {
482 fw = fq[U(i - 1)] + fq[U(i)];
483 fq[U(i)] += fq[U(i - 1)] - fw;
484 fq[U(i - 1)] = fw;
478 fw = fq[@intCast(i - 1)] + fq[@intCast(i)];
479 fq[@intCast(i)] += fq[@intCast(i - 1)] - fw;
480 fq[@intCast(i - 1)] = fw;
485481 }
486482 fw = 0;
487483 i = jz;
488484 while (i >= 2) : (i -= 1) {
489 fw += fq[U(i)];
485 fw += fq[@intCast(i)];
490486 }
491487 if (ih == 0) {
492488 y[0] = fq[0];
lib/compiler_rt/shift.zig+12-18
......@@ -30,20 +30,19 @@ comptime {
3030// Precondition: 0 <= b < bits_in_dword
3131inline fn ashlXi3(comptime T: type, a: T, b: i32) T {
3232 const word_t = common.HalveInt(T, false);
33 const S = Log2Int(word_t.HalfT);
3433
3534 const input = word_t{ .all = a };
3635 var output: word_t = undefined;
3736
3837 if (b >= word_t.bits) {
3938 output.s.low = 0;
40 output.s.high = input.s.low << @as(S, @intCast(b - word_t.bits));
39 output.s.high = input.s.low << @intCast(b - word_t.bits);
4140 } else if (b == 0) {
4241 return a;
4342 } else {
44 output.s.low = input.s.low << @as(S, @intCast(b));
45 output.s.high = input.s.high << @as(S, @intCast(b));
46 output.s.high |= input.s.low >> @as(S, @intCast(word_t.bits - b));
43 output.s.low = input.s.low << @intCast(b);
44 output.s.high = input.s.high << @intCast(b);
45 output.s.high |= input.s.low >> @intCast(word_t.bits - b);
4746 }
4847
4948 return output.all;
......@@ -53,24 +52,20 @@ inline fn ashlXi3(comptime T: type, a: T, b: i32) T {
5352// Precondition: 0 <= b < T.bit_count
5453inline fn ashrXi3(comptime T: type, a: T, b: i32) T {
5554 const word_t = common.HalveInt(T, true);
56 const S = Log2Int(word_t.HalfT);
5755
5856 const input = word_t{ .all = a };
5957 var output: word_t = undefined;
6058
6159 if (b >= word_t.bits) {
6260 output.s.high = input.s.high >> (word_t.bits - 1);
63 output.s.low = input.s.high >> @as(S, @intCast(b - word_t.bits));
61 output.s.low = input.s.high >> @intCast(b - word_t.bits);
6462 } else if (b == 0) {
6563 return a;
6664 } else {
67 output.s.high = input.s.high >> @as(S, @intCast(b));
68 output.s.low = input.s.high << @as(S, @intCast(word_t.bits - b));
65 output.s.high = input.s.high >> @intCast(b);
66 output.s.low = input.s.high << @intCast(word_t.bits - b);
6967 // Avoid sign-extension here
70 output.s.low |= @as(
71 word_t.HalfT,
72 @bitCast(@as(word_t.HalfTU, @bitCast(input.s.low)) >> @as(S, @intCast(b))),
73 );
68 output.s.low |= @bitCast(@as(word_t.HalfTU, @bitCast(input.s.low)) >> @intCast(b));
7469 }
7570
7671 return output.all;
......@@ -80,20 +75,19 @@ inline fn ashrXi3(comptime T: type, a: T, b: i32) T {
8075// Precondition: 0 <= b < T.bit_count
8176inline fn lshrXi3(comptime T: type, a: T, b: i32) T {
8277 const word_t = common.HalveInt(T, false);
83 const S = Log2Int(word_t.HalfT);
8478
8579 const input = word_t{ .all = a };
8680 var output: word_t = undefined;
8781
8882 if (b >= word_t.bits) {
8983 output.s.high = 0;
90 output.s.low = input.s.high >> @as(S, @intCast(b - word_t.bits));
84 output.s.low = input.s.high >> @intCast(b - word_t.bits);
9185 } else if (b == 0) {
9286 return a;
9387 } else {
94 output.s.high = input.s.high >> @as(S, @intCast(b));
95 output.s.low = input.s.high << @as(S, @intCast(word_t.bits - b));
96 output.s.low |= input.s.low >> @as(S, @intCast(b));
88 output.s.high = input.s.high >> @intCast(b);
89 output.s.low = input.s.high << @intCast(word_t.bits - b);
90 output.s.low |= input.s.low >> @intCast(b);
9791 }
9892
9993 return output.all;
lib/compiler_rt/sin.zig+6-6
......@@ -31,7 +31,7 @@ comptime {
3131
3232pub fn __sinh(x: f16) callconv(.C) f16 {
3333 // TODO: more efficient implementation
34 return @as(f16, @floatCast(sinf(x)));
34 return @floatCast(sinf(x));
3535}
3636
3737pub fn sinf(x: f32) callconv(.C) f32 {
......@@ -41,7 +41,7 @@ pub fn sinf(x: f32) callconv(.C) f32 {
4141 const s3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2
4242 const s4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18
4343
44 var ix = @as(u32, @bitCast(x));
44 var ix: u32 = @bitCast(x);
4545 const sign = ix >> 31 != 0;
4646 ix &= 0x7fffffff;
4747
......@@ -120,12 +120,12 @@ pub fn sin(x: f64) callconv(.C) f64 {
120120
121121pub fn __sinx(x: f80) callconv(.C) f80 {
122122 // TODO: more efficient implementation
123 return @as(f80, @floatCast(sinq(x)));
123 return @floatCast(sinq(x));
124124}
125125
126126pub fn sinq(x: f128) callconv(.C) f128 {
127127 // TODO: more correct implementation
128 return sin(@as(f64, @floatCast(x)));
128 return sin(@floatCast(x));
129129}
130130
131131pub fn sinl(x: c_longdouble) callconv(.C) c_longdouble {
......@@ -180,11 +180,11 @@ test "sin64.special" {
180180}
181181
182182test "sin32 #9901" {
183 const float = @as(f32, @bitCast(@as(u32, 0b11100011111111110000000000000000)));
183 const float: f32 = @bitCast(@as(u32, 0b11100011111111110000000000000000));
184184 _ = sinf(float);
185185}
186186
187187test "sin64 #9901" {
188 const float = @as(f64, @bitCast(@as(u64, 0b1111111101000001000000001111110111111111100000000000000000000001)));
188 const float: f64 = @bitCast(@as(u64, 0b1111111101000001000000001111110111111111100000000000000000000001));
189189 _ = sin(float);
190190}
lib/compiler_rt/sqrt.zig+13-13
......@@ -20,13 +20,13 @@ comptime {
2020
2121pub fn __sqrth(x: f16) callconv(.C) f16 {
2222 // TODO: more efficient implementation
23 return @as(f16, @floatCast(sqrtf(x)));
23 return @floatCast(sqrtf(x));
2424}
2525
2626pub fn sqrtf(x: f32) callconv(.C) f32 {
2727 const tiny: f32 = 1.0e-30;
28 const sign: i32 = @as(i32, @bitCast(@as(u32, 0x80000000)));
29 var ix: i32 = @as(i32, @bitCast(x));
28 const sign: i32 = @bitCast(@as(u32, 0x80000000));
29 var ix: i32 = @bitCast(x);
3030
3131 if ((ix & 0x7F800000) == 0x7F800000) {
3232 return x * x + x; // sqrt(nan) = nan, sqrt(+inf) = +inf, sqrt(-inf) = nan
......@@ -96,7 +96,7 @@ pub fn sqrtf(x: f32) callconv(.C) f32 {
9696
9797 ix = (q >> 1) + 0x3f000000;
9898 ix += m << 23;
99 return @as(f32, @bitCast(ix));
99 return @bitCast(ix);
100100}
101101
102102/// NOTE: The original code is full of implicit signed -> unsigned assumptions and u32 wraparound
......@@ -105,10 +105,10 @@ pub fn sqrtf(x: f32) callconv(.C) f32 {
105105pub fn sqrt(x: f64) callconv(.C) f64 {
106106 const tiny: f64 = 1.0e-300;
107107 const sign: u32 = 0x80000000;
108 const u = @as(u64, @bitCast(x));
108 const u: u64 = @bitCast(x);
109109
110 var ix0 = @as(u32, @intCast(u >> 32));
111 var ix1 = @as(u32, @intCast(u & 0xFFFFFFFF));
110 var ix0: u32 = @intCast(u >> 32);
111 var ix1: u32 = @intCast(u & 0xFFFFFFFF);
112112
113113 // sqrt(nan) = nan, sqrt(+inf) = +inf, sqrt(-inf) = nan
114114 if (ix0 & 0x7FF00000 == 0x7FF00000) {
......@@ -140,8 +140,8 @@ pub fn sqrt(x: f64) callconv(.C) f64 {
140140 ix0 <<= 1;
141141 }
142142 m -= @as(i32, @intCast(i)) - 1;
143 ix0 |= ix1 >> @as(u5, @intCast(32 - i));
144 ix1 <<= @as(u5, @intCast(i));
143 ix0 |= ix1 >> @intCast(32 - i);
144 ix1 <<= @intCast(i);
145145 }
146146
147147 // unbias exponent
......@@ -225,21 +225,21 @@ pub fn sqrt(x: f64) callconv(.C) f64 {
225225
226226 // NOTE: musl here appears to rely on signed twos-complement wraparound. +% has the same
227227 // behaviour at least.
228 var iix0 = @as(i32, @intCast(ix0));
228 var iix0: i32 = @intCast(ix0);
229229 iix0 = iix0 +% (m << 20);
230230
231231 const uz = (@as(u64, @intCast(iix0)) << 32) | ix1;
232 return @as(f64, @bitCast(uz));
232 return @bitCast(uz);
233233}
234234
235235pub fn __sqrtx(x: f80) callconv(.C) f80 {
236236 // TODO: more efficient implementation
237 return @as(f80, @floatCast(sqrtq(x)));
237 return @floatCast(sqrtq(x));
238238}
239239
240240pub fn sqrtq(x: f128) callconv(.C) f128 {
241241 // TODO: more correct implementation
242 return sqrt(@as(f64, @floatCast(x)));
242 return sqrt(@floatCast(x));
243243}
244244
245245pub fn sqrtl(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/tan.zig+2-2
......@@ -106,12 +106,12 @@ pub fn tan(x: f64) callconv(.C) f64 {
106106
107107pub fn __tanx(x: f80) callconv(.C) f80 {
108108 // TODO: more efficient implementation
109 return @as(f80, @floatCast(tanq(x)));
109 return @floatCast(tanq(x));
110110}
111111
112112pub fn tanq(x: f128) callconv(.C) f128 {
113113 // TODO: more correct implementation
114 return tan(@as(f64, @floatCast(x)));
114 return tan(@floatCast(x));
115115}
116116
117117pub fn tanl(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/trig.zig+5-5
......@@ -70,7 +70,7 @@ pub fn __cosdf(x: f64) f32 {
7070 const z = x * x;
7171 const w = z * z;
7272 const r = C2 + z * C3;
73 return @as(f32, @floatCast(((1.0 + z * C0) + w * C1) + (w * z) * r));
73 return @floatCast(((1.0 + z * C0) + w * C1) + (w * z) * r);
7474}
7575
7676/// kernel sin function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854
......@@ -131,7 +131,7 @@ pub fn __sindf(x: f64) f32 {
131131 const w = z * z;
132132 const r = S3 + z * S4;
133133 const s = z * x;
134 return @as(f32, @floatCast((x + s * (S1 + z * S2)) + s * w * r));
134 return @floatCast((x + s * (S1 + z * S2)) + s * w * r);
135135}
136136
137137/// kernel tan function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854
......@@ -231,11 +231,11 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 {
231231 }
232232 // -1.0/(x+r) has up to 2ulp error, so compute it accurately
233233 w0 = w;
234 w0 = @as(f64, @bitCast(@as(u64, @bitCast(w0)) & 0xffffffff00000000));
234 w0 = @bitCast(@as(u64, @bitCast(w0)) & 0xffffffff00000000);
235235 v = r - (w0 - x); // w0+v = r+x
236236 a = -1.0 / w;
237237 a0 = a;
238 a0 = @as(f64, @bitCast(@as(u64, @bitCast(a0)) & 0xffffffff00000000));
238 a0 = @bitCast(@as(u64, @bitCast(a0)) & 0xffffffff00000000);
239239 return a0 + a * (1.0 + a0 * w0 + a0 * v);
240240}
241241
......@@ -269,5 +269,5 @@ pub fn __tandf(x: f64, odd: bool) f32 {
269269 const s = z * x;
270270 const u = T[0] + z * T[1];
271271 const r0 = (x + s * u) + (s * w) * (t + w * r);
272 return @as(f32, @floatCast(if (odd) -1.0 / r0 else r0));
272 return @floatCast(if (odd) -1.0 / r0 else r0);
273273}
lib/compiler_rt/trunc.zig+6-6
......@@ -42,7 +42,7 @@ pub fn truncf(x: f32) callconv(.C) f32 {
4242 e = 1;
4343 }
4444
45 m = @as(u32, math.maxInt(u32)) >> @as(u5, @intCast(e));
45 m = @as(u32, math.maxInt(u32)) >> @intCast(e);
4646 if (u & m == 0) {
4747 return x;
4848 } else {
......@@ -63,7 +63,7 @@ pub fn trunc(x: f64) callconv(.C) f64 {
6363 e = 1;
6464 }
6565
66 m = @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(e));
66 m = @as(u64, math.maxInt(u64)) >> @intCast(e);
6767 if (u & m == 0) {
6868 return x;
6969 } else {
......@@ -74,11 +74,11 @@ pub fn trunc(x: f64) callconv(.C) f64 {
7474
7575pub fn __truncx(x: f80) callconv(.C) f80 {
7676 // TODO: more efficient implementation
77 return @as(f80, @floatCast(truncq(x)));
77 return @floatCast(truncq(x));
7878}
7979
8080pub fn truncq(x: f128) callconv(.C) f128 {
81 const u = @as(u128, @bitCast(x));
81 const u: u128 = @bitCast(x);
8282 var e = @as(i32, @intCast(((u >> 112) & 0x7FFF))) - 0x3FFF + 16;
8383 var m: u128 = undefined;
8484
......@@ -89,12 +89,12 @@ pub fn truncq(x: f128) callconv(.C) f128 {
8989 e = 1;
9090 }
9191
92 m = @as(u128, math.maxInt(u128)) >> @as(u7, @intCast(e));
92 m = @as(u128, math.maxInt(u128)) >> @intCast(e);
9393 if (u & m == 0) {
9494 return x;
9595 } else {
9696 math.doNotOptimizeAway(x + 0x1p120);
97 return @as(f128, @bitCast(u & ~m));
97 return @bitCast(u & ~m);
9898 }
9999}
100100
lib/compiler_rt/truncdfhf2.zig+2-2
......@@ -12,9 +12,9 @@ comptime {
1212}
1313
1414pub fn __truncdfhf2(a: f64) callconv(.C) common.F16T(f64) {
15 return @as(common.F16T(f64), @bitCast(truncf(f16, f64, a)));
15 return @bitCast(truncf(f16, f64, a));
1616}
1717
1818fn __aeabi_d2h(a: f64) callconv(.AAPCS) u16 {
19 return @as(common.F16T(f64), @bitCast(truncf(f16, f64, a)));
19 return @bitCast(truncf(f16, f64, a));
2020}
lib/compiler_rt/truncf.zig+14-15
......@@ -5,7 +5,6 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
55 const dst_rep_t = std.meta.Int(.unsigned, @typeInfo(dst_t).Float.bits);
66 const srcSigBits = std.math.floatMantissaBits(src_t);
77 const dstSigBits = std.math.floatMantissaBits(dst_t);
8 const SrcShift = std.math.Log2Int(src_rep_t);
98
109 // Various constants whose values follow from the type parameters.
1110 // Any reasonable optimizer will fold and propagate all of these.
......@@ -38,7 +37,7 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
3837 const dstNaNCode = dstQNaN - 1;
3938
4039 // Break a into a sign and representation of the absolute value
41 const aRep: src_rep_t = @as(src_rep_t, @bitCast(a));
40 const aRep: src_rep_t = @bitCast(a);
4241 const aAbs: src_rep_t = aRep & srcAbsMask;
4342 const sign: src_rep_t = aRep & srcSignMask;
4443 var absResult: dst_rep_t = undefined;
......@@ -47,7 +46,7 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
4746 // The exponent of a is within the range of normal numbers in the
4847 // destination format. We can convert by simply right-shifting with
4948 // rounding and adjusting the exponent.
50 absResult = @as(dst_rep_t, @truncate(aAbs >> (srcSigBits - dstSigBits)));
49 absResult = @truncate(aAbs >> (srcSigBits - dstSigBits));
5150 absResult -%= @as(dst_rep_t, srcExpBias - dstExpBias) << dstSigBits;
5251
5352 const roundBits: src_rep_t = aAbs & roundMask;
......@@ -64,7 +63,7 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
6463 // bit and inserting the (truncated) trailing NaN field.
6564 absResult = @as(dst_rep_t, @intCast(dstInfExp)) << dstSigBits;
6665 absResult |= dstQNaN;
67 absResult |= @as(dst_rep_t, @intCast(((aAbs & srcNaNCode) >> (srcSigBits - dstSigBits)) & dstNaNCode));
66 absResult |= @intCast(((aAbs & srcNaNCode) >> (srcSigBits - dstSigBits)) & dstNaNCode);
6867 } else if (aAbs >= overflow) {
6968 // a overflows to infinity.
7069 absResult = @as(dst_rep_t, @intCast(dstInfExp)) << dstSigBits;
......@@ -81,9 +80,9 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
8180 if (shift > srcSigBits) {
8281 absResult = 0;
8382 } else {
84 const sticky: src_rep_t = @intFromBool(significand << @as(SrcShift, @intCast(srcBits - shift)) != 0);
85 const denormalizedSignificand: src_rep_t = significand >> @as(SrcShift, @intCast(shift)) | sticky;
86 absResult = @as(dst_rep_t, @intCast(denormalizedSignificand >> (srcSigBits - dstSigBits)));
83 const sticky: src_rep_t = @intFromBool(significand << @intCast(srcBits - shift) != 0);
84 const denormalizedSignificand: src_rep_t = significand >> @intCast(shift) | sticky;
85 absResult = @intCast(denormalizedSignificand >> (srcSigBits - dstSigBits));
8786 const roundBits: src_rep_t = denormalizedSignificand & roundMask;
8887 if (roundBits > halfway) {
8988 // Round to nearest
......@@ -96,8 +95,8 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
9695 }
9796
9897 const result: dst_rep_t align(@alignOf(dst_t)) = absResult |
99 @as(dst_rep_t, @truncate(sign >> @as(SrcShift, @intCast(srcBits - dstBits))));
100 return @as(dst_t, @bitCast(result));
98 @as(dst_rep_t, @truncate(sign >> @intCast(srcBits - dstBits)));
99 return @bitCast(result);
101100}
102101
103102pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
......@@ -133,7 +132,7 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
133132 // destination format. We can convert by simply right-shifting with
134133 // rounding and adjusting the exponent.
135134 abs_result = @as(dst_rep_t, a_rep.exp) << dst_sig_bits;
136 abs_result |= @as(dst_rep_t, @truncate(a_rep.fraction >> (src_sig_bits - dst_sig_bits)));
135 abs_result |= @truncate(a_rep.fraction >> (src_sig_bits - dst_sig_bits));
137136 abs_result -%= @as(dst_rep_t, src_exp_bias - dst_exp_bias) << dst_sig_bits;
138137
139138 const round_bits = a_rep.fraction & round_mask;
......@@ -150,7 +149,7 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
150149 // bit and inserting the (truncated) trailing NaN field.
151150 abs_result = @as(dst_rep_t, @intCast(dst_inf_exp)) << dst_sig_bits;
152151 abs_result |= dst_qnan;
153 abs_result |= @as(dst_rep_t, @intCast((a_rep.fraction >> (src_sig_bits - dst_sig_bits)) & dst_nan_mask));
152 abs_result |= @intCast((a_rep.fraction >> (src_sig_bits - dst_sig_bits)) & dst_nan_mask);
154153 } else if (a_rep.exp >= overflow) {
155154 // a overflows to infinity.
156155 abs_result = @as(dst_rep_t, @intCast(dst_inf_exp)) << dst_sig_bits;
......@@ -164,9 +163,9 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
164163 if (shift > src_sig_bits) {
165164 abs_result = 0;
166165 } else {
167 const sticky = @intFromBool(a_rep.fraction << @as(u6, @intCast(shift)) != 0);
168 const denormalized_significand = a_rep.fraction >> @as(u6, @intCast(shift)) | sticky;
169 abs_result = @as(dst_rep_t, @intCast(denormalized_significand >> (src_sig_bits - dst_sig_bits)));
166 const sticky = @intFromBool(a_rep.fraction << @intCast(shift) != 0);
167 const denormalized_significand = a_rep.fraction >> @intCast(shift) | sticky;
168 abs_result = @intCast(denormalized_significand >> (src_sig_bits - dst_sig_bits));
170169 const round_bits = denormalized_significand & round_mask;
171170 if (round_bits > halfway) {
172171 // Round to nearest
......@@ -179,7 +178,7 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
179178 }
180179
181180 const result align(@alignOf(dst_t)) = abs_result | @as(dst_rep_t, sign) << dst_bits - 16;
182 return @as(dst_t, @bitCast(result));
181 return @bitCast(result);
183182}
184183
185184test {
lib/compiler_rt/truncsfhf2.zig+3-3
......@@ -13,13 +13,13 @@ comptime {
1313}
1414
1515pub fn __truncsfhf2(a: f32) callconv(.C) common.F16T(f32) {
16 return @as(common.F16T(f32), @bitCast(truncf(f16, f32, a)));
16 return @bitCast(truncf(f16, f32, a));
1717}
1818
1919fn __gnu_f2h_ieee(a: f32) callconv(.C) common.F16T(f32) {
20 return @as(common.F16T(f32), @bitCast(truncf(f16, f32, a)));
20 return @bitCast(truncf(f16, f32, a));
2121}
2222
2323fn __aeabi_f2h(a: f32) callconv(.AAPCS) u16 {
24 return @as(common.F16T(f32), @bitCast(truncf(f16, f32, a)));
24 return @bitCast(truncf(f16, f32, a));
2525}
lib/compiler_rt/trunctfhf2.zig+1-1
......@@ -8,5 +8,5 @@ comptime {
88}
99
1010pub fn __trunctfhf2(a: f128) callconv(.C) common.F16T(f128) {
11 return @as(common.F16T(f128), @bitCast(truncf(f16, f128, a)));
11 return @bitCast(truncf(f16, f128, a));
1212}
lib/compiler_rt/truncxfhf2.zig+1-1
......@@ -8,5 +8,5 @@ comptime {
88}
99
1010fn __truncxfhf2(a: f80) callconv(.C) common.F16T(f80) {
11 return @as(common.F16T(f80), @bitCast(trunc_f80(f16, a)));
11 return @bitCast(trunc_f80(f16, a));
1212}
lib/compiler_rt/udivmod.zig+11-11
......@@ -21,11 +21,11 @@ fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T {
2121 var un64: T = undefined;
2222 var un10: T = undefined;
2323
24 const s = @as(Log2Int(T), @intCast(@clz(v)));
24 const s: Log2Int(T) = @intCast(@clz(v));
2525 if (s > 0) {
2626 // Normalize divisor
2727 v <<= s;
28 un64 = (_u1 << s) | (_u0 >> @as(Log2Int(T), @intCast((@bitSizeOf(T) - @as(T, @intCast(s))))));
28 un64 = (_u1 << s) | (_u0 >> @intCast((@bitSizeOf(T) - @as(T, @intCast(s)))));
2929 un10 = _u0 << s;
3030 } else {
3131 // Avoid undefined behavior of (u0 >> @bitSizeOf(T))
......@@ -101,8 +101,8 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
101101 return 0;
102102 }
103103
104 var a = @as([2]HalfT, @bitCast(a_));
105 var b = @as([2]HalfT, @bitCast(b_));
104 var a: [2]HalfT = @bitCast(a_);
105 var b: [2]HalfT = @bitCast(b_);
106106 var q: [2]HalfT = undefined;
107107 var r: [2]HalfT = undefined;
108108
......@@ -119,16 +119,16 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
119119 q[lo] = divwide(HalfT, a[hi] % b[lo], a[lo], b[lo], &r[lo]);
120120 }
121121 if (maybe_rem) |rem| {
122 rem.* = @as(T, @bitCast(r));
122 rem.* = @bitCast(r);
123123 }
124 return @as(T, @bitCast(q));
124 return @bitCast(q);
125125 }
126126
127127 // 0 <= shift <= 63
128128 var shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]);
129 var af = @as(T, @bitCast(a));
129 var af: T = @bitCast(a);
130130 var bf = @as(T, @bitCast(b)) << shift;
131 q = @as([2]HalfT, @bitCast(@as(T, 0)));
131 q = @bitCast(@as(T, 0));
132132
133133 for (0..shift + 1) |_| {
134134 q[lo] <<= 1;
......@@ -138,12 +138,12 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
138138 // q[lo] |= 1;
139139 // }
140140 const s = @as(SignedT, @bitCast(bf -% af -% 1)) >> (@bitSizeOf(T) - 1);
141 q[lo] |= @as(HalfT, @intCast(s & 1));
141 q[lo] |= @intCast(s & 1);
142142 af -= bf & @as(T, @bitCast(s));
143143 bf >>= 1;
144144 }
145145 if (maybe_rem) |rem| {
146 rem.* = @as(T, @bitCast(af));
146 rem.* = @bitCast(af);
147147 }
148 return @as(T, @bitCast(q));
148 return @bitCast(q);
149149}
lib/compiler_rt/udivmodti4.zig+1-1
......@@ -20,7 +20,7 @@ pub fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) callconv(.C) u128 {
2020const v2u64 = @Vector(2, u64);
2121
2222fn __udivmodti4_windows_x86_64(a: v2u64, b: v2u64, maybe_rem: ?*u128) callconv(.C) v2u64 {
23 return @as(v2u64, @bitCast(udivmod(u128, @as(u128, @bitCast(a)), @as(u128, @bitCast(b)), maybe_rem)));
23 return @bitCast(udivmod(u128, @bitCast(a), @bitCast(b), maybe_rem));
2424}
2525
2626test {
lib/compiler_rt/udivti3.zig+1-1
......@@ -20,5 +20,5 @@ pub fn __udivti3(a: u128, b: u128) callconv(.C) u128 {
2020const v2u64 = @Vector(2, u64);
2121
2222fn __udivti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {
23 return @as(v2u64, @bitCast(udivmod(u128, @as(u128, @bitCast(a)), @as(u128, @bitCast(b)), null)));
23 return @bitCast(udivmod(u128, @bitCast(a), @bitCast(b), null));
2424}
lib/compiler_rt/umodti3.zig+2-2
......@@ -23,6 +23,6 @@ const v2u64 = @Vector(2, u64);
2323
2424fn __umodti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {
2525 var r: u128 = undefined;
26 _ = udivmod(u128, @as(u128, @bitCast(a)), @as(u128, @bitCast(b)), &r);
27 return @as(v2u64, @bitCast(r));
26 _ = udivmod(u128, @bitCast(a), @bitCast(b), &r);
27 return @bitCast(r);
2828}