authorgravatar for zach@raineri.softwareZachary Raineri <zach@raineri.software> 2023-07-24 05:34:16-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-24 10:23:51-07:00
logd82b35901035a325ca7afd38b28ff2386f90ae84
tree1a370e979308a3406ea42e55f16299d48ba19700
parent77b96231a6bc195cc482d05599e8c20ee01645a6

Use builtin inference over @as where possible


72 files changed, 390 insertions(+), 391 deletions(-)

lib/compiler_rt/addf3.zig+11-11
......@@ -38,14 +38,14 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
3838 bAbs -% @as(Z, 1) >= infRep - @as(Z, 1))
3939 {
4040 // NaN + anything = qNaN
41 if (aAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(a)) | quietBit));
41 if (aAbs > infRep) return @bitCast(@as(Z, @bitCast(a)) | quietBit);
4242 // anything + NaN = qNaN
43 if (bAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(b)) | quietBit));
43 if (bAbs > infRep) return @bitCast(@as(Z, @bitCast(b)) | quietBit);
4444
4545 if (aAbs == infRep) {
4646 // +/-infinity + -/+infinity = qNaN
4747 if ((@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) == signBit) {
48 return @as(T, @bitCast(qnanRep));
48 return @bitCast(qnanRep);
4949 }
5050 // +/-infinity + anything remaining = +/- infinity
5151 else {
......@@ -60,7 +60,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
6060 if (aAbs == 0) {
6161 // but we need to get the sign right for zero + zero
6262 if (bAbs == 0) {
63 return @as(T, @bitCast(@as(Z, @bitCast(a)) & @as(Z, @bitCast(b))));
63 return @bitCast(@as(Z, @bitCast(a)) & @as(Z, @bitCast(b)));
6464 } else {
6565 return b;
6666 }
......@@ -78,8 +78,8 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
7878 }
7979
8080 // Extract the exponent and significand from the (possibly swapped) a and b.
81 var aExponent = @as(i32, @intCast((aRep >> significandBits) & maxExponent));
82 var bExponent = @as(i32, @intCast((bRep >> significandBits) & maxExponent));
81 var aExponent: i32 = @intCast((aRep >> significandBits) & maxExponent);
82 var bExponent: i32 = @intCast((bRep >> significandBits) & maxExponent);
8383 var aSignificand = aRep & significandMask;
8484 var bSignificand = bRep & significandMask;
8585
......@@ -101,7 +101,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
101101
102102 // Shift the significand of b by the difference in exponents, with a sticky
103103 // bottom bit to get rounding correct.
104 const @"align" = @as(u32, @intCast(aExponent - bExponent));
104 const @"align": u32 = @intCast(aExponent - bExponent);
105105 if (@"align" != 0) {
106106 if (@"align" < typeWidth) {
107107 const sticky = if (bSignificand << @as(S, @intCast(typeWidth - @"align")) != 0) @as(Z, 1) else 0;
......@@ -113,7 +113,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
113113 if (subtraction) {
114114 aSignificand -= bSignificand;
115115 // If a == -b, return +zero.
116 if (aSignificand == 0) return @as(T, @bitCast(@as(Z, 0)));
116 if (aSignificand == 0) return @bitCast(@as(Z, 0));
117117
118118 // If partial cancellation occured, we need to left-shift the result
119119 // and adjust the exponent:
......@@ -135,13 +135,13 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
135135 }
136136
137137 // If we have overflowed the type, return +/- infinity:
138 if (aExponent >= maxExponent) return @as(T, @bitCast(infRep | resultSign));
138 if (aExponent >= maxExponent) return @bitCast(infRep | resultSign);
139139
140140 if (aExponent <= 0) {
141141 // Result is denormal; the exponent and round/sticky bits are zero.
142142 // All we need to do is shift the significand and apply the correct sign.
143143 aSignificand >>= @as(S, @intCast(4 - aExponent));
144 return @as(T, @bitCast(resultSign | aSignificand));
144 return @bitCast(resultSign | aSignificand);
145145 }
146146
147147 // Low three bits are round, guard, and sticky.
......@@ -164,7 +164,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
164164 if ((result >> significandBits) != 0) result |= integerBit;
165165 }
166166
167 return @as(T, @bitCast(result));
167 return @bitCast(result);
168168}
169169
170170test {
lib/compiler_rt/addf3_test.zig+9-9
......@@ -5,7 +5,7 @@
55
66const std = @import("std");
77const math = std.math;
8const qnan128 = @as(f128, @bitCast(@as(u128, 0x7fff800000000000) << 64));
8const qnan128: f128 = @bitCast(@as(u128, 0x7fff800000000000) << 64);
99
1010const __addtf3 = @import("addtf3.zig").__addtf3;
1111const __addxf3 = @import("addxf3.zig").__addxf3;
......@@ -14,9 +14,9 @@ const __subtf3 = @import("subtf3.zig").__subtf3;
1414fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
1515 const x = __addtf3(a, b);
1616
17 const rep = @as(u128, @bitCast(x));
18 const hi = @as(u64, @intCast(rep >> 64));
19 const lo = @as(u64, @truncate(rep));
17 const rep: u128 = @bitCast(x);
18 const hi: u64 = @intCast(rep >> 64);
19 const lo: u64 = @truncate(rep);
2020
2121 if (hi == expected_hi and lo == expected_lo) {
2222 return;
......@@ -53,9 +53,9 @@ test "addtf3" {
5353fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
5454 const x = __subtf3(a, b);
5555
56 const rep = @as(u128, @bitCast(x));
57 const hi = @as(u64, @intCast(rep >> 64));
58 const lo = @as(u64, @truncate(rep));
56 const rep: u128 = @bitCast(x);
57 const hi: u64 = @intCast(rep >> 64);
58 const lo: u64 = @truncate(rep);
5959
6060 if (hi == expected_hi and lo == expected_lo) {
6161 return;
......@@ -87,11 +87,11 @@ test "subtf3" {
8787 try test__subtf3(0x1.ee9d7c52354a6936ab8d7654321fp-1, 0x1.234567829a3bcdef5678ade36734p+5, 0xc0041b8af1915166, 0xa44a7bca780a166c);
8888}
8989
90const qnan80 = @as(f80, @bitCast(@as(u80, @bitCast(math.nan(f80))) | (1 << (math.floatFractionalBits(f80) - 1))));
90const qnan80: f80 = @bitCast(@as(u80, @bitCast(math.nan(f80))) | (1 << (math.floatFractionalBits(f80) - 1)));
9191
9292fn test__addxf3(a: f80, b: f80, expected: u80) !void {
9393 const x = __addxf3(a, b);
94 const rep = @as(u80, @bitCast(x));
94 const rep: u80 = @bitCast(x);
9595
9696 if (rep == expected)
9797 return;
lib/compiler_rt/arm.zig+1-1
......@@ -192,6 +192,6 @@ pub fn __aeabi_ldivmod() callconv(.Naked) void {
192192}
193193
194194pub fn __aeabi_drsub(a: f64, b: f64) callconv(.AAPCS) f64 {
195 const neg_a = @as(f64, @bitCast(@as(u64, @bitCast(a)) ^ (@as(u64, 1) << 63)));
195 const neg_a: f64 = @bitCast(@as(u64, @bitCast(a)) ^ (@as(u64, 1) << 63));
196196 return b + neg_a;
197197}
lib/compiler_rt/ceil.zig+6-6
......@@ -27,11 +27,11 @@ comptime {
2727
2828pub fn __ceilh(x: f16) callconv(.C) f16 {
2929 // TODO: more efficient implementation
30 return @as(f16, @floatCast(ceilf(x)));
30 return @floatCast(ceilf(x));
3131}
3232
3333pub fn ceilf(x: f32) callconv(.C) f32 {
34 var u = @as(u32, @bitCast(x));
34 var u: u32 = @bitCast(x);
3535 var e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;
3636 var m: u32 = undefined;
3737
......@@ -52,7 +52,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 {
5252 u += m;
5353 }
5454 u &= ~m;
55 return @as(f32, @bitCast(u));
55 return @bitCast(u);
5656 } else {
5757 math.doNotOptimizeAway(x + 0x1.0p120);
5858 if (u >> 31 != 0) {
......@@ -66,7 +66,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 {
6666pub fn ceil(x: f64) callconv(.C) f64 {
6767 const f64_toint = 1.0 / math.floatEps(f64);
6868
69 const u = @as(u64, @bitCast(x));
69 const u: u64 = @bitCast(x);
7070 const e = (u >> 52) & 0x7FF;
7171 var y: f64 = undefined;
7272
......@@ -96,13 +96,13 @@ pub fn ceil(x: f64) callconv(.C) f64 {
9696
9797pub fn __ceilx(x: f80) callconv(.C) f80 {
9898 // TODO: more efficient implementation
99 return @as(f80, @floatCast(ceilq(x)));
99 return @floatCast(ceilq(x));
100100}
101101
102102pub fn ceilq(x: f128) callconv(.C) f128 {
103103 const f128_toint = 1.0 / math.floatEps(f128);
104104
105 const u = @as(u128, @bitCast(x));
105 const u: u128 = @bitCast(x);
106106 const e = (u >> 112) & 0x7FFF;
107107 var y: f128 = undefined;
108108
lib/compiler_rt/clzdi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const clz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__clzdi2(a: u64, expected: i64) !void {
5 var x = @as(i64, @bitCast(a));
5 var x: i64 = @bitCast(a);
66 var result = clz.__clzdi2(x);
77 try testing.expectEqual(expected, result);
88}
lib/compiler_rt/clzsi2_test.zig+1-1
......@@ -5,7 +5,7 @@ const testing = @import("std").testing;
55fn test__clzsi2(a: u32, expected: i32) !void {
66 const nakedClzsi2 = clz.__clzsi2;
77 const actualClzsi2 = @as(*const fn (a: i32) callconv(.C) i32, @ptrCast(&nakedClzsi2));
8 const x = @as(i32, @bitCast(a));
8 const x: i32 = @bitCast(a);
99 const result = actualClzsi2(x);
1010 try testing.expectEqual(expected, result);
1111}
lib/compiler_rt/clzti2_test.zig+1-1
......@@ -2,7 +2,7 @@ const clz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__clzti2(a: u128, expected: i64) !void {
5 var x = @as(i128, @bitCast(a));
5 var x: i128 = @bitCast(a);
66 var result = clz.__clzti2(x);
77 try testing.expectEqual(expected, result);
88}
lib/compiler_rt/cos.zig+3-3
......@@ -35,7 +35,7 @@ pub fn cosf(x: f32) callconv(.C) f32 {
3535 const c3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2
3636 const c4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18
3737
38 var ix = @as(u32, @bitCast(x));
38 var ix: u32 = @bitCast(x);
3939 const sign = ix >> 31 != 0;
4040 ix &= 0x7fffffff;
4141
......@@ -116,12 +116,12 @@ pub fn cos(x: f64) callconv(.C) f64 {
116116
117117pub fn __cosx(a: f80) callconv(.C) f80 {
118118 // TODO: more efficient implementation
119 return @as(f80, @floatCast(cosq(a)));
119 return @floatCast(cosq(a));
120120}
121121
122122pub fn cosq(a: f128) callconv(.C) f128 {
123123 // TODO: more correct implementation
124 return cos(@as(f64, @floatCast(a)));
124 return cos(@floatCast(a));
125125}
126126
127127pub fn cosl(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/count0bits.zig+3-3
......@@ -49,7 +49,7 @@ inline fn clzXi2(comptime T: type, a: T) i32 {
4949 x = y;
5050 }
5151 }
52 return @as(i32, @intCast(n - @as(T, @bitCast(x))));
52 return @intCast(n - @as(T, @bitCast(x)));
5353}
5454
5555fn __clzsi2_thumb1() callconv(.Naked) void {
......@@ -187,7 +187,7 @@ inline fn ctzXi2(comptime T: type, a: T) i32 {
187187 x = x >> shift;
188188 }
189189 }
190 return @as(i32, @intCast(n - @as(T, @bitCast((x & 1)))));
190 return @intCast(n - @as(T, @bitCast((x & 1))));
191191}
192192
193193pub fn __ctzsi2(a: i32) callconv(.C) i32 {
......@@ -224,7 +224,7 @@ inline fn ffsXi2(comptime T: type, a: T) i32 {
224224 }
225225 }
226226 // return ctz + 1
227 return @as(i32, @intCast(n - @as(T, @bitCast((x & 1))))) + @as(i32, 1);
227 return @as(i32, @intCast(n - @as(T, @bitCast((x & 1))))) + 1;
228228}
229229
230230pub fn __ffssi2(a: i32) callconv(.C) i32 {
lib/compiler_rt/ctzdi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const ctz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ctzdi2(a: u64, expected: i32) !void {
5 var x = @as(i64, @bitCast(a));
5 var x: i64 = @bitCast(a);
66 var result = ctz.__ctzdi2(x);
77 try testing.expectEqual(expected, result);
88}
lib/compiler_rt/ctzsi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const ctz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ctzsi2(a: u32, expected: i32) !void {
5 var x = @as(i32, @bitCast(a));
5 var x: i32 = @bitCast(a);
66 var result = ctz.__ctzsi2(x);
77 try testing.expectEqual(expected, result);
88}
lib/compiler_rt/ctzti2_test.zig+1-1
......@@ -2,7 +2,7 @@ const ctz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ctzti2(a: u128, expected: i32) !void {
5 var x = @as(i128, @bitCast(a));
5 var x: i128 = @bitCast(a);
66 var result = ctz.__ctzti2(x);
77 try testing.expectEqual(expected, result);
88}
lib/compiler_rt/divdf3.zig+24-24
......@@ -49,8 +49,8 @@ inline fn div(a: f64, b: f64) f64 {
4949 const qnanRep = exponentMask | quietBit;
5050 const infRep = @as(Z, @bitCast(std.math.inf(f64)));
5151
52 const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
53 const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
52 const aExponent: u32 = @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent);
53 const bExponent: u32 = @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent);
5454 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
5555
5656 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;
......@@ -63,36 +63,36 @@ inline fn div(a: f64, b: f64) f64 {
6363 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
6464
6565 // NaN / anything = qNaN
66 if (aAbs > infRep) return @as(f64, @bitCast(@as(Z, @bitCast(a)) | quietBit));
66 if (aAbs > infRep) return @bitCast(@as(Z, @bitCast(a)) | quietBit);
6767 // anything / NaN = qNaN
68 if (bAbs > infRep) return @as(f64, @bitCast(@as(Z, @bitCast(b)) | quietBit));
68 if (bAbs > infRep) return @bitCast(@as(Z, @bitCast(b)) | quietBit);
6969
7070 if (aAbs == infRep) {
7171 // infinity / infinity = NaN
7272 if (bAbs == infRep) {
73 return @as(f64, @bitCast(qnanRep));
73 return @bitCast(qnanRep);
7474 }
7575 // infinity / anything else = +/- infinity
7676 else {
77 return @as(f64, @bitCast(aAbs | quotientSign));
77 return @bitCast(aAbs | quotientSign);
7878 }
7979 }
8080
8181 // anything else / infinity = +/- 0
82 if (bAbs == infRep) return @as(f64, @bitCast(quotientSign));
82 if (bAbs == infRep) return @bitCast(quotientSign);
8383
8484 if (aAbs == 0) {
8585 // zero / zero = NaN
8686 if (bAbs == 0) {
87 return @as(f64, @bitCast(qnanRep));
87 return @bitCast(qnanRep);
8888 }
8989 // zero / anything else = +/- zero
9090 else {
91 return @as(f64, @bitCast(quotientSign));
91 return @bitCast(quotientSign);
9292 }
9393 }
9494 // anything else / zero = +/- infinity
95 if (bAbs == 0) return @as(f64, @bitCast(infRep | quotientSign));
95 if (bAbs == 0) return @bitCast(infRep | quotientSign);
9696
9797 // one or both of a or b is denormal, the other (if applicable) is a
9898 // normal number. Renormalize one or both of a and b, and set scale to
......@@ -112,7 +112,7 @@ inline fn div(a: f64, b: f64) f64 {
112112 // [1, 2.0) and get a Q32 approximate reciprocal using a small minimax
113113 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
114114 // is accurate to about 3.5 binary digits.
115 const q31b: u32 = @as(u32, @truncate(bSignificand >> 21));
115 const q31b: u32 = @truncate(bSignificand >> 21);
116116 var recip32 = @as(u32, 0x7504f333) -% q31b;
117117
118118 // Now refine the reciprocal estimate using a Newton-Raphson iteration:
......@@ -123,12 +123,12 @@ inline fn div(a: f64, b: f64) f64 {
123123 // with each iteration, so after three iterations, we have about 28 binary
124124 // digits of accuracy.
125125 var correction32: u32 = undefined;
126 correction32 = @as(u32, @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1));
127 recip32 = @as(u32, @truncate(@as(u64, recip32) *% correction32 >> 31));
128 correction32 = @as(u32, @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1));
129 recip32 = @as(u32, @truncate(@as(u64, recip32) *% correction32 >> 31));
130 correction32 = @as(u32, @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1));
131 recip32 = @as(u32, @truncate(@as(u64, recip32) *% correction32 >> 31));
126 correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1);
127 recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31);
128 correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1);
129 recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31);
130 correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1);
131 recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31);
132132
133133 // recip32 might have overflowed to exactly zero in the preceding
134134 // computation if the high word of b is exactly 1.0. This would sabotage
......@@ -138,12 +138,12 @@ inline fn div(a: f64, b: f64) f64 {
138138
139139 // We need to perform one more iteration to get us to 56 binary digits;
140140 // The last iteration needs to happen with extra precision.
141 const q63blo: u32 = @as(u32, @truncate(bSignificand << 11));
141 const q63blo: u32 = @truncate(bSignificand << 11);
142142 var correction: u64 = undefined;
143143 var reciprocal: u64 = undefined;
144144 correction = ~(@as(u64, recip32) *% q31b +% (@as(u64, recip32) *% q63blo >> 32)) +% 1;
145 const cHi = @as(u32, @truncate(correction >> 32));
146 const cLo = @as(u32, @truncate(correction));
145 const cHi: u32 = @truncate(correction >> 32);
146 const cLo: u32 = @truncate(correction);
147147 reciprocal = @as(u64, recip32) *% cHi +% (@as(u64, recip32) *% cLo >> 32);
148148
149149 // We already adjusted the 32-bit estimate, now we need to adjust the final
......@@ -195,7 +195,7 @@ inline fn div(a: f64, b: f64) f64 {
195195
196196 if (writtenExponent >= maxExponent) {
197197 // If we have overflowed the exponent, return infinity.
198 return @as(f64, @bitCast(infRep | quotientSign));
198 return @bitCast(infRep | quotientSign);
199199 } else if (writtenExponent < 1) {
200200 if (writtenExponent == 0) {
201201 // Check whether the rounded result is normal.
......@@ -206,12 +206,12 @@ inline fn div(a: f64, b: f64) f64 {
206206 absResult += round;
207207 if ((absResult & ~significandMask) != 0) {
208208 // The rounded result is normal; return it.
209 return @as(f64, @bitCast(absResult | quotientSign));
209 return @bitCast(absResult | quotientSign);
210210 }
211211 }
212212 // Flush denormals to zero. In the future, it would be nice to add
213213 // code to round them correctly.
214 return @as(f64, @bitCast(quotientSign));
214 return @bitCast(quotientSign);
215215 } else {
216216 const round = @intFromBool((residual << 1) > bSignificand);
217217 // Clear the implicit bit
......@@ -221,7 +221,7 @@ inline fn div(a: f64, b: f64) f64 {
221221 // Round
222222 absResult +%= round;
223223 // Insert the sign and return
224 return @as(f64, @bitCast(absResult | quotientSign));
224 return @bitCast(absResult | quotientSign);
225225 }
226226}
227227
lib/compiler_rt/divdf3_test.zig+1-1
......@@ -6,7 +6,7 @@ const __divdf3 = @import("divdf3.zig").__divdf3;
66const testing = @import("std").testing;
77
88fn compareResultD(result: f64, expected: u64) bool {
9 const rep = @as(u64, @bitCast(result));
9 const rep: u64 = @bitCast(result);
1010
1111 if (rep == expected) {
1212 return true;
lib/compiler_rt/divhf3.zig+1-1
......@@ -7,5 +7,5 @@ comptime {
77
88pub fn __divhf3(a: f16, b: f16) callconv(.C) f16 {
99 // TODO: more efficient implementation
10 return @as(f16, @floatCast(divsf3.__divsf3(a, b)));
10 return @floatCast(divsf3.__divsf3(a, b));
1111}
lib/compiler_rt/divsf3.zig+22-22
......@@ -44,10 +44,10 @@ inline fn div(a: f32, b: f32) f32 {
4444 const absMask = signBit - 1;
4545 const exponentMask = absMask ^ significandMask;
4646 const qnanRep = exponentMask | quietBit;
47 const infRep = @as(Z, @bitCast(std.math.inf(f32)));
47 const infRep: Z = @bitCast(std.math.inf(f32));
4848
49 const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
50 const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
49 const aExponent: u32 = @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent);
50 const bExponent: u32 = @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent);
5151 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
5252
5353 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;
......@@ -60,36 +60,36 @@ inline fn div(a: f32, b: f32) f32 {
6060 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
6161
6262 // NaN / anything = qNaN
63 if (aAbs > infRep) return @as(f32, @bitCast(@as(Z, @bitCast(a)) | quietBit));
63 if (aAbs > infRep) return @bitCast(@as(Z, @bitCast(a)) | quietBit);
6464 // anything / NaN = qNaN
65 if (bAbs > infRep) return @as(f32, @bitCast(@as(Z, @bitCast(b)) | quietBit));
65 if (bAbs > infRep) return @bitCast(@as(Z, @bitCast(b)) | quietBit);
6666
6767 if (aAbs == infRep) {
6868 // infinity / infinity = NaN
6969 if (bAbs == infRep) {
70 return @as(f32, @bitCast(qnanRep));
70 return @bitCast(qnanRep);
7171 }
7272 // infinity / anything else = +/- infinity
7373 else {
74 return @as(f32, @bitCast(aAbs | quotientSign));
74 return @bitCast(aAbs | quotientSign);
7575 }
7676 }
7777
7878 // anything else / infinity = +/- 0
79 if (bAbs == infRep) return @as(f32, @bitCast(quotientSign));
79 if (bAbs == infRep) return @bitCast(quotientSign);
8080
8181 if (aAbs == 0) {
8282 // zero / zero = NaN
8383 if (bAbs == 0) {
84 return @as(f32, @bitCast(qnanRep));
84 return @bitCast(qnanRep);
8585 }
8686 // zero / anything else = +/- zero
8787 else {
88 return @as(f32, @bitCast(quotientSign));
88 return @bitCast(quotientSign);
8989 }
9090 }
9191 // anything else / zero = +/- infinity
92 if (bAbs == 0) return @as(f32, @bitCast(infRep | quotientSign));
92 if (bAbs == 0) return @bitCast(infRep | quotientSign);
9393
9494 // one or both of a or b is denormal, the other (if applicable) is a
9595 // normal number. Renormalize one or both of a and b, and set scale to
......@@ -120,12 +120,12 @@ inline fn div(a: f32, b: f32) f32 {
120120 // with each iteration, so after three iterations, we have about 28 binary
121121 // digits of accuracy.
122122 var correction: u32 = undefined;
123 correction = @as(u32, @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1));
124 reciprocal = @as(u32, @truncate(@as(u64, reciprocal) *% correction >> 31));
125 correction = @as(u32, @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1));
126 reciprocal = @as(u32, @truncate(@as(u64, reciprocal) *% correction >> 31));
127 correction = @as(u32, @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1));
128 reciprocal = @as(u32, @truncate(@as(u64, reciprocal) *% correction >> 31));
123 correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
124 reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31);
125 correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
126 reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31);
127 correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
128 reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31);
129129
130130 // Exhaustive testing shows that the error in reciprocal after three steps
131131 // is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our
......@@ -147,7 +147,7 @@ inline fn div(a: f32, b: f32) f32 {
147147 // is the error in the reciprocal of b scaled by the maximum
148148 // possible value of a. As a consequence of this error bound,
149149 // either q or nextafter(q) is the correctly rounded
150 var quotient: Z = @as(u32, @truncate(@as(u64, reciprocal) *% (aSignificand << 1) >> 32));
150 var quotient: Z = @truncate(@as(u64, reciprocal) *% (aSignificand << 1) >> 32);
151151
152152 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
153153 // In either case, we are going to compute a residual of the form
......@@ -175,7 +175,7 @@ inline fn div(a: f32, b: f32) f32 {
175175
176176 if (writtenExponent >= maxExponent) {
177177 // If we have overflowed the exponent, return infinity.
178 return @as(f32, @bitCast(infRep | quotientSign));
178 return @bitCast(infRep | quotientSign);
179179 } else if (writtenExponent < 1) {
180180 if (writtenExponent == 0) {
181181 // Check whether the rounded result is normal.
......@@ -186,12 +186,12 @@ inline fn div(a: f32, b: f32) f32 {
186186 absResult += round;
187187 if ((absResult & ~significandMask) > 0) {
188188 // The rounded result is normal; return it.
189 return @as(f32, @bitCast(absResult | quotientSign));
189 return @bitCast(absResult | quotientSign);
190190 }
191191 }
192192 // Flush denormals to zero. In the future, it would be nice to add
193193 // code to round them correctly.
194 return @as(f32, @bitCast(quotientSign));
194 return @bitCast(quotientSign);
195195 } else {
196196 const round = @intFromBool((residual << 1) > bSignificand);
197197 // Clear the implicit bit
......@@ -201,7 +201,7 @@ inline fn div(a: f32, b: f32) f32 {
201201 // Round
202202 absResult +%= round;
203203 // Insert the sign and return
204 return @as(f32, @bitCast(absResult | quotientSign));
204 return @bitCast(absResult | quotientSign);
205205 }
206206}
207207
lib/compiler_rt/divsf3_test.zig+1-1
......@@ -6,7 +6,7 @@ const __divsf3 = @import("divsf3.zig").__divsf3;
66const testing = @import("std").testing;
77
88fn compareResultF(result: f32, expected: u32) bool {
9 const rep = @as(u32, @bitCast(result));
9 const rep: u32 = @bitCast(result);
1010
1111 if (rep == expected) {
1212 return true;
lib/compiler_rt/divtf3.zig+29-29
......@@ -41,10 +41,10 @@ inline fn div(a: f128, b: f128) f128 {
4141 const absMask = signBit - 1;
4242 const exponentMask = absMask ^ significandMask;
4343 const qnanRep = exponentMask | quietBit;
44 const infRep = @as(Z, @bitCast(std.math.inf(f128)));
44 const infRep: Z = @bitCast(std.math.inf(f128));
4545
46 const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
47 const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
46 const aExponent: u32 = @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent);
47 const bExponent: u32 = @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent);
4848 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
4949
5050 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;
......@@ -57,36 +57,36 @@ inline fn div(a: f128, b: f128) f128 {
5757 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
5858
5959 // NaN / anything = qNaN
60 if (aAbs > infRep) return @as(f128, @bitCast(@as(Z, @bitCast(a)) | quietBit));
60 if (aAbs > infRep) return @bitCast(@as(Z, @bitCast(a)) | quietBit);
6161 // anything / NaN = qNaN
62 if (bAbs > infRep) return @as(f128, @bitCast(@as(Z, @bitCast(b)) | quietBit));
62 if (bAbs > infRep) return @bitCast(@as(Z, @bitCast(b)) | quietBit);
6363
6464 if (aAbs == infRep) {
6565 // infinity / infinity = NaN
6666 if (bAbs == infRep) {
67 return @as(f128, @bitCast(qnanRep));
67 return @bitCast(qnanRep);
6868 }
6969 // infinity / anything else = +/- infinity
7070 else {
71 return @as(f128, @bitCast(aAbs | quotientSign));
71 return @bitCast(aAbs | quotientSign);
7272 }
7373 }
7474
7575 // anything else / infinity = +/- 0
76 if (bAbs == infRep) return @as(f128, @bitCast(quotientSign));
76 if (bAbs == infRep) return @bitCast(quotientSign);
7777
7878 if (aAbs == 0) {
7979 // zero / zero = NaN
8080 if (bAbs == 0) {
81 return @as(f128, @bitCast(qnanRep));
81 return @bitCast(qnanRep);
8282 }
8383 // zero / anything else = +/- zero
8484 else {
85 return @as(f128, @bitCast(quotientSign));
85 return @bitCast(quotientSign);
8686 }
8787 }
8888 // anything else / zero = +/- infinity
89 if (bAbs == 0) return @as(f128, @bitCast(infRep | quotientSign));
89 if (bAbs == 0) return @bitCast(infRep | quotientSign);
9090
9191 // one or both of a or b is denormal, the other (if applicable) is a
9292 // normal number. Renormalize one or both of a and b, and set scale to
......@@ -106,7 +106,7 @@ inline fn div(a: f128, b: f128) f128 {
106106 // [1, 2.0) and get a Q64 approximate reciprocal using a small minimax
107107 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
108108 // is accurate to about 3.5 binary digits.
109 const q63b = @as(u64, @truncate(bSignificand >> 49));
109 const q63b: u64 = @truncate(bSignificand >> 49);
110110 var recip64 = @as(u64, 0x7504f333F9DE6484) -% q63b;
111111 // 0x7504f333F9DE6484 / 2^64 + 1 = 3/4 + 1/sqrt(2)
112112
......@@ -117,16 +117,16 @@ inline fn div(a: f128, b: f128) f128 {
117117 // This doubles the number of correct binary digits in the approximation
118118 // with each iteration.
119119 var correction64: u64 = undefined;
120 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
121 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
122 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
123 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
124 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
125 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
126 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
127 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
128 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
129 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
120 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
121 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
122 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
123 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
124 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
125 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
126 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
127 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
128 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
129 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
130130
131131 // The reciprocal may have overflowed to zero if the upper half of b is
132132 // exactly 1.0. This would sabatoge the full-width final stage of the
......@@ -135,7 +135,7 @@ inline fn div(a: f128, b: f128) f128 {
135135
136136 // We need to perform one more iteration to get us to 112 binary digits;
137137 // The last iteration needs to happen with extra precision.
138 const q127blo: u64 = @as(u64, @truncate(bSignificand << 15));
138 const q127blo: u64 = @truncate(bSignificand << 15);
139139 var correction: u128 = undefined;
140140 var reciprocal: u128 = undefined;
141141
......@@ -151,8 +151,8 @@ inline fn div(a: f128, b: f128) f128 {
151151
152152 correction = -%(r64q63 + (r64q127 >> 64));
153153
154 const cHi = @as(u64, @truncate(correction >> 64));
155 const cLo = @as(u64, @truncate(correction));
154 const cHi: u64 = @truncate(correction >> 64);
155 const cLo: u64 = @truncate(correction);
156156
157157 wideMultiply(u128, recip64, cHi, &dummy, &r64cH);
158158 wideMultiply(u128, recip64, cLo, &dummy, &r64cL);
......@@ -210,7 +210,7 @@ inline fn div(a: f128, b: f128) f128 {
210210
211211 if (writtenExponent >= maxExponent) {
212212 // If we have overflowed the exponent, return infinity.
213 return @as(f128, @bitCast(infRep | quotientSign));
213 return @bitCast(infRep | quotientSign);
214214 } else if (writtenExponent < 1) {
215215 if (writtenExponent == 0) {
216216 // Check whether the rounded result is normal.
......@@ -221,12 +221,12 @@ inline fn div(a: f128, b: f128) f128 {
221221 absResult += round;
222222 if ((absResult & ~significandMask) > 0) {
223223 // The rounded result is normal; return it.
224 return @as(f128, @bitCast(absResult | quotientSign));
224 return @bitCast(absResult | quotientSign);
225225 }
226226 }
227227 // Flush denormals to zero. In the future, it would be nice to add
228228 // code to round them correctly.
229 return @as(f128, @bitCast(quotientSign));
229 return @bitCast(quotientSign);
230230 } else {
231231 const round = @intFromBool((residual << 1) >= bSignificand);
232232 // Clear the implicit bit
......@@ -236,7 +236,7 @@ inline fn div(a: f128, b: f128) f128 {
236236 // Round
237237 absResult +%= round;
238238 // Insert the sign and return
239 return @as(f128, @bitCast(absResult | quotientSign));
239 return @bitCast(absResult | quotientSign);
240240 }
241241}
242242
lib/compiler_rt/divtf3_test.zig+3-3
......@@ -5,9 +5,9 @@ const testing = std.testing;
55const __divtf3 = @import("divtf3.zig").__divtf3;
66
77fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
8 const rep = @as(u128, @bitCast(result));
9 const hi = @as(u64, @truncate(rep >> 64));
10 const lo = @as(u64, @truncate(rep));
8 const rep: u128 = @bitCast(result);
9 const hi: u64 = @truncate(rep >> 64);
10 const lo: u64 = @truncate(rep);
1111
1212 if (hi == expectedHi and lo == expectedLo) {
1313 return true;
lib/compiler_rt/divxf3.zig+24-24
......@@ -30,10 +30,10 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
3030
3131 const absMask = signBit - 1;
3232 const qnanRep = @as(Z, @bitCast(std.math.nan(T))) | quietBit;
33 const infRep = @as(Z, @bitCast(std.math.inf(T)));
33 const infRep: Z = @bitCast(std.math.inf(T));
3434
35 const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
36 const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
35 const aExponent: u32 = @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent);
36 const bExponent: u32 = @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent);
3737 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
3838
3939 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;
......@@ -46,36 +46,36 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
4646 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
4747
4848 // NaN / anything = qNaN
49 if (aAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(a)) | quietBit));
49 if (aAbs > infRep) return @bitCast(@as(Z, @bitCast(a)) | quietBit);
5050 // anything / NaN = qNaN
51 if (bAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(b)) | quietBit));
51 if (bAbs > infRep) return @bitCast(@as(Z, @bitCast(b)) | quietBit);
5252
5353 if (aAbs == infRep) {
5454 // infinity / infinity = NaN
5555 if (bAbs == infRep) {
56 return @as(T, @bitCast(qnanRep));
56 return @bitCast(qnanRep);
5757 }
5858 // infinity / anything else = +/- infinity
5959 else {
60 return @as(T, @bitCast(aAbs | quotientSign));
60 return @bitCast(aAbs | quotientSign);
6161 }
6262 }
6363
6464 // anything else / infinity = +/- 0
65 if (bAbs == infRep) return @as(T, @bitCast(quotientSign));
65 if (bAbs == infRep) return @bitCast(quotientSign);
6666
6767 if (aAbs == 0) {
6868 // zero / zero = NaN
6969 if (bAbs == 0) {
70 return @as(T, @bitCast(qnanRep));
70 return @bitCast(qnanRep);
7171 }
7272 // zero / anything else = +/- zero
7373 else {
74 return @as(T, @bitCast(quotientSign));
74 return @bitCast(quotientSign);
7575 }
7676 }
7777 // anything else / zero = +/- infinity
78 if (bAbs == 0) return @as(T, @bitCast(infRep | quotientSign));
78 if (bAbs == 0) return @bitCast(infRep | quotientSign);
7979
8080 // one or both of a or b is denormal, the other (if applicable) is a
8181 // normal number. Renormalize one or both of a and b, and set scale to
......@@ -89,7 +89,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
8989 // [1, 2.0) and get a Q64 approximate reciprocal using a small minimax
9090 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
9191 // is accurate to about 3.5 binary digits.
92 const q63b = @as(u64, @intCast(bSignificand));
92 const q63b: u64 = @intCast(bSignificand);
9393 var recip64 = @as(u64, 0x7504f333F9DE6484) -% q63b;
9494 // 0x7504f333F9DE6484 / 2^64 + 1 = 3/4 + 1/sqrt(2)
9595
......@@ -100,16 +100,16 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
100100 // This doubles the number of correct binary digits in the approximation
101101 // with each iteration.
102102 var correction64: u64 = undefined;
103 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
104 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
105 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
106 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
107 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
108 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
109 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
110 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
111 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
112 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
103 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
104 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
105 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
106 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
107 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
108 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
109 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
110 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
111 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
112 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
113113
114114 // The reciprocal may have overflowed to zero if the upper half of b is
115115 // exactly 1.0. This would sabatoge the full-width final stage of the
......@@ -128,8 +128,8 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
128128
129129 correction = -%correction;
130130
131 const cHi = @as(u64, @truncate(correction >> 64));
132 const cLo = @as(u64, @truncate(correction));
131 const cHi: u64 = @truncate(correction >> 64);
132 const cLo: u64 = @truncate(correction);
133133
134134 var r64cH: u128 = undefined;
135135 var r64cL: u128 = undefined;
lib/compiler_rt/divxf3_test.zig+3-3
......@@ -5,7 +5,7 @@ const testing = std.testing;
55const __divxf3 = @import("divxf3.zig").__divxf3;
66
77fn compareResult(result: f80, expected: u80) bool {
8 const rep = @as(u80, @bitCast(result));
8 const rep: u80 = @bitCast(result);
99
1010 if (rep == expected) return true;
1111 // test other possible NaN representations (signal NaN)
......@@ -25,9 +25,9 @@ fn test__divxf3(a: f80, b: f80) !void {
2525 const x = __divxf3(a, b);
2626
2727 // Next float (assuming normal, non-zero result)
28 const x_plus_eps = @as(f80, @bitCast((@as(u80, @bitCast(x)) + 1) | integerBit));
28 const x_plus_eps: f80 = @bitCast((@as(u80, @bitCast(x)) + 1) | integerBit);
2929 // Prev float (assuming normal, non-zero result)
30 const x_minus_eps = @as(f80, @bitCast((@as(u80, @bitCast(x)) - 1) | integerBit));
30 const x_minus_eps: f80 = @bitCast((@as(u80, @bitCast(x)) - 1) | integerBit);
3131
3232 // Make sure result is more accurate than the adjacent floats
3333 const err_x = @fabs(@mulAdd(f80, x, b, -a));
lib/compiler_rt/emutls.zig+1-1
......@@ -125,7 +125,7 @@ const ObjectArray = struct {
125125 if (self.slots[index] == null) {
126126 // initialize the slot
127127 const size = control.size;
128 const alignment = @as(u29, @truncate(control.alignment));
128 const alignment: u29 = @truncate(control.alignment);
129129
130130 var data = simple_allocator.advancedAlloc(alignment, size);
131131 errdefer simple_allocator.free(data);
lib/compiler_rt/exp.zig+10-10
......@@ -39,8 +39,8 @@ pub fn expf(x_: f32) callconv(.C) f32 {
3939 const P2 = -2.7667332906e-3;
4040
4141 var x = x_;
42 var hx = @as(u32, @bitCast(x));
43 const sign = @as(i32, @intCast(hx >> 31));
42 var hx: u32 = @bitCast(x);
43 const sign: i32 = @intCast(hx >> 31);
4444 hx &= 0x7FFFFFFF;
4545
4646 if (math.isNan(x)) {
......@@ -74,12 +74,12 @@ pub fn expf(x_: f32) callconv(.C) f32 {
7474 if (hx > 0x3EB17218) {
7575 // |x| > 1.5 * ln2
7676 if (hx > 0x3F851592) {
77 k = @as(i32, @intFromFloat(invln2 * x + half[@as(usize, @intCast(sign))]));
77 k = @intFromFloat(invln2 * x + half[@as(usize, @intCast(sign))]);
7878 } else {
7979 k = 1 - sign - sign;
8080 }
8181
82 const fk = @as(f32, @floatFromInt(k));
82 const fk: f32 = @floatFromInt(k);
8383 hi = x - fk * ln2hi;
8484 lo = fk * ln2lo;
8585 x = hi - lo;
......@@ -117,9 +117,9 @@ pub fn exp(x_: f64) callconv(.C) f64 {
117117 const P5: f64 = 4.13813679705723846039e-08;
118118
119119 var x = x_;
120 var ux = @as(u64, @bitCast(x));
120 var ux: u64 = @bitCast(x);
121121 var hx = ux >> 32;
122 const sign = @as(i32, @intCast(hx >> 31));
122 const sign: i32 = @intCast(hx >> 31);
123123 hx &= 0x7FFFFFFF;
124124
125125 if (math.isNan(x)) {
......@@ -157,12 +157,12 @@ pub fn exp(x_: f64) callconv(.C) f64 {
157157 if (hx > 0x3FD62E42) {
158158 // |x| >= 1.5 * ln2
159159 if (hx > 0x3FF0A2B2) {
160 k = @as(i32, @intFromFloat(invln2 * x + half[@as(usize, @intCast(sign))]));
160 k = @intFromFloat(invln2 * x + half[@as(usize, @intCast(sign))]);
161161 } else {
162162 k = 1 - sign - sign;
163163 }
164164
165 const dk = @as(f64, @floatFromInt(k));
165 const dk: f64 = @floatFromInt(k);
166166 hi = x - dk * ln2hi;
167167 lo = dk * ln2lo;
168168 x = hi - lo;
......@@ -191,12 +191,12 @@ pub fn exp(x_: f64) callconv(.C) f64 {
191191
192192pub fn __expx(a: f80) callconv(.C) f80 {
193193 // TODO: more efficient implementation
194 return @as(f80, @floatCast(expq(a)));
194 return @floatCast(expq(a));
195195}
196196
197197pub fn expq(a: f128) callconv(.C) f128 {
198198 // TODO: more correct implementation
199 return exp(@as(f64, @floatCast(a)));
199 return exp(@floatCast(a));
200200}
201201
202202pub fn expl(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/exp2.zig+10-10
......@@ -31,14 +31,14 @@ pub fn __exp2h(x: f16) callconv(.C) f16 {
3131}
3232
3333pub fn exp2f(x: f32) callconv(.C) f32 {
34 const tblsiz = @as(u32, @intCast(exp2ft.len));
34 const tblsiz: u32 = @intCast(exp2ft.len);
3535 const redux: f32 = 0x1.8p23 / @as(f32, @floatFromInt(tblsiz));
3636 const P1: f32 = 0x1.62e430p-1;
3737 const P2: f32 = 0x1.ebfbe0p-3;
3838 const P3: f32 = 0x1.c6b348p-5;
3939 const P4: f32 = 0x1.3b2c9cp-7;
4040
41 var u = @as(u32, @bitCast(x));
41 var u: u32 = @bitCast(x);
4242 const ix = u & 0x7FFFFFFF;
4343
4444 // |x| > 126
......@@ -72,11 +72,11 @@ pub fn exp2f(x: f32) callconv(.C) f32 {
7272 // intended result but should confirm how GCC/Clang handle this to ensure.
7373
7474 var uf = x + redux;
75 var i_0 = @as(u32, @bitCast(uf));
75 var i_0: u32 = @bitCast(uf);
7676 i_0 +%= tblsiz / 2;
7777
7878 const k = i_0 / tblsiz;
79 const uk = @as(f64, @bitCast(@as(u64, 0x3FF + k) << 52));
79 const uk: f64 = @bitCast(@as(u64, 0x3FF + k) << 52);
8080 i_0 &= tblsiz - 1;
8181 uf -= redux;
8282
......@@ -84,11 +84,11 @@ pub fn exp2f(x: f32) callconv(.C) f32 {
8484 var r: f64 = exp2ft[@as(usize, @intCast(i_0))];
8585 const t: f64 = r * z;
8686 r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4);
87 return @as(f32, @floatCast(r * uk));
87 return @floatCast(r * uk);
8888}
8989
9090pub fn exp2(x: f64) callconv(.C) f64 {
91 const tblsiz: u32 = @as(u32, @intCast(exp2dt.len / 2));
91 const tblsiz: u32 = @intCast(exp2dt.len / 2);
9292 const redux: f64 = 0x1.8p52 / @as(f64, @floatFromInt(tblsiz));
9393 const P1: f64 = 0x1.62e42fefa39efp-1;
9494 const P2: f64 = 0x1.ebfbdff82c575p-3;
......@@ -96,7 +96,7 @@ pub fn exp2(x: f64) callconv(.C) f64 {
9696 const P4: f64 = 0x1.3b2ab88f70400p-7;
9797 const P5: f64 = 0x1.5d88003875c74p-10;
9898
99 const ux = @as(u64, @bitCast(x));
99 const ux: u64 = @bitCast(x);
100100 const ix = @as(u32, @intCast(ux >> 32)) & 0x7FFFFFFF;
101101
102102 // TODO: This should be handled beneath.
......@@ -139,7 +139,7 @@ pub fn exp2(x: f64) callconv(.C) f64 {
139139 // reduce x
140140 var uf: f64 = x + redux;
141141 // NOTE: musl performs an implicit 64-bit to 32-bit u32 truncation here
142 var i_0: u32 = @as(u32, @truncate(@as(u64, @bitCast(uf))));
142 var i_0: u32 = @truncate(@as(u64, @bitCast(uf)));
143143 i_0 +%= tblsiz / 2;
144144
145145 const k: u32 = i_0 / tblsiz * tblsiz;
......@@ -158,12 +158,12 @@ pub fn exp2(x: f64) callconv(.C) f64 {
158158
159159pub fn __exp2x(x: f80) callconv(.C) f80 {
160160 // TODO: more efficient implementation
161 return @as(f80, @floatCast(exp2q(x)));
161 return @floatCast(exp2q(x));
162162}
163163
164164pub fn exp2q(x: f128) callconv(.C) f128 {
165165 // TODO: more correct implementation
166 return exp2(@as(f64, @floatCast(x)));
166 return exp2(@floatCast(x));
167167}
168168
169169pub fn exp2l(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/extendf.zig+3-3
......@@ -33,7 +33,7 @@ pub inline fn extendf(
3333 const dstMinNormal: dst_rep_t = @as(dst_rep_t, 1) << dstSigBits;
3434
3535 // Break a into a sign and representation of the absolute value
36 const aRep: src_rep_t = @as(src_rep_t, @bitCast(a));
36 const aRep: src_rep_t = @bitCast(a);
3737 const aAbs: src_rep_t = aRep & srcAbsMask;
3838 const sign: src_rep_t = aRep & srcSignMask;
3939 var absResult: dst_rep_t = undefined;
......@@ -104,7 +104,7 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI
104104 // a is a normal number.
105105 // Extend to the destination type by shifting the significand and
106106 // exponent into the proper position and rebiasing the exponent.
107 dst.exp = @as(u16, @intCast(a_abs >> src_sig_bits));
107 dst.exp = @intCast(a_abs >> src_sig_bits);
108108 dst.exp += dst_exp_bias - src_exp_bias;
109109 dst.fraction = @as(u64, a_abs) << (dst_sig_bits - src_sig_bits);
110110 dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers
......@@ -126,7 +126,7 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI
126126
127127 dst.fraction = @as(u64, a_abs) << @as(u6, @intCast(dst_sig_bits - src_sig_bits + scale));
128128 dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers
129 dst.exp = @as(u16, @truncate(a_abs >> @as(SrcShift, @intCast(src_sig_bits - scale))));
129 dst.exp = @truncate(a_abs >> @as(SrcShift, @intCast(src_sig_bits - scale)));
130130 dst.exp ^= 1;
131131 dst.exp |= dst_exp_bias - src_exp_bias - scale + 1;
132132 } else {
lib/compiler_rt/extendf_test.zig+17-17
......@@ -11,7 +11,7 @@ const F16T = @import("./common.zig").F16T;
1111fn test__extenddfxf2(a: f64, expected: u80) !void {
1212 const x = __extenddfxf2(a);
1313
14 const rep = @as(u80, @bitCast(x));
14 const rep: u80 = @bitCast(x);
1515 if (rep == expected)
1616 return;
1717
......@@ -25,9 +25,9 @@ fn test__extenddfxf2(a: f64, expected: u80) !void {
2525fn test__extenddftf2(a: f64, expected_hi: u64, expected_lo: u64) !void {
2626 const x = __extenddftf2(a);
2727
28 const rep = @as(u128, @bitCast(x));
29 const hi = @as(u64, @intCast(rep >> 64));
30 const lo = @as(u64, @truncate(rep));
28 const rep: u128 = @bitCast(x);
29 const hi: u64 = @intCast(rep >> 64);
30 const lo: u64 = @truncate(rep);
3131
3232 if (hi == expected_hi and lo == expected_lo)
3333 return;
......@@ -46,7 +46,7 @@ fn test__extenddftf2(a: f64, expected_hi: u64, expected_lo: u64) !void {
4646
4747fn test__extendhfsf2(a: u16, expected: u32) !void {
4848 const x = __extendhfsf2(@as(F16T(f32), @bitCast(a)));
49 const rep = @as(u32, @bitCast(x));
49 const rep: u32 = @bitCast(x);
5050
5151 if (rep == expected) {
5252 if (rep & 0x7fffffff > 0x7f800000) {
......@@ -63,9 +63,9 @@ fn test__extendhfsf2(a: u16, expected: u32) !void {
6363fn test__extendsftf2(a: f32, expected_hi: u64, expected_lo: u64) !void {
6464 const x = __extendsftf2(a);
6565
66 const rep = @as(u128, @bitCast(x));
67 const hi = @as(u64, @intCast(rep >> 64));
68 const lo = @as(u64, @truncate(rep));
66 const rep: u128 = @bitCast(x);
67 const hi: u64 = @intCast(rep >> 64);
68 const lo: u64 = @truncate(rep);
6969
7070 if (hi == expected_hi and lo == expected_lo)
7171 return;
......@@ -184,35 +184,35 @@ test "extendsftf2" {
184184}
185185
186186fn makeQNaN64() f64 {
187 return @as(f64, @bitCast(@as(u64, 0x7ff8000000000000)));
187 return @bitCast(@as(u64, 0x7ff8000000000000));
188188}
189189
190190fn makeInf64() f64 {
191 return @as(f64, @bitCast(@as(u64, 0x7ff0000000000000)));
191 return @bitCast(@as(u64, 0x7ff0000000000000));
192192}
193193
194194fn makeNaN64(rand: u64) f64 {
195 return @as(f64, @bitCast(0x7ff0000000000000 | (rand & 0xfffffffffffff)));
195 return @bitCast(0x7ff0000000000000 | (rand & 0xfffffffffffff));
196196}
197197
198198fn makeQNaN32() f32 {
199 return @as(f32, @bitCast(@as(u32, 0x7fc00000)));
199 return @bitCast(@as(u32, 0x7fc00000));
200200}
201201
202202fn makeNaN32(rand: u32) f32 {
203 return @as(f32, @bitCast(0x7f800000 | (rand & 0x7fffff)));
203 return @bitCast(0x7f800000 | (rand & 0x7fffff));
204204}
205205
206206fn makeInf32() f32 {
207 return @as(f32, @bitCast(@as(u32, 0x7f800000)));
207 return @bitCast(@as(u32, 0x7f800000));
208208}
209209
210210fn test__extendhftf2(a: u16, expected_hi: u64, expected_lo: u64) !void {
211211 const x = __extendhftf2(@as(F16T(f128), @bitCast(a)));
212212
213 const rep = @as(u128, @bitCast(x));
214 const hi = @as(u64, @intCast(rep >> 64));
215 const lo = @as(u64, @truncate(rep));
213 const rep: u128 = @bitCast(x);
214 const hi: u64 = @intCast(rep >> 64);
215 const lo: u64 = @truncate(rep);
216216
217217 if (hi == expected_hi and lo == expected_lo)
218218 return;
lib/compiler_rt/float_from_int_test.zig+6-6
......@@ -520,9 +520,9 @@ test "floatsitf" {
520520fn test__floatunsitf(a: u32, expected_hi: u64, expected_lo: u64) !void {
521521 const x = __floatunsitf(a);
522522
523 const x_repr = @as(u128, @bitCast(x));
524 const x_hi = @as(u64, @intCast(x_repr >> 64));
525 const x_lo = @as(u64, @truncate(x_repr));
523 const x_repr: u128 = @bitCast(x);
524 const x_hi: u64 = @intCast(x_repr >> 64);
525 const x_lo: u64 = @truncate(x_repr);
526526
527527 if (x_hi == expected_hi and x_lo == expected_lo) {
528528 return;
......@@ -552,9 +552,9 @@ fn test__floatditf(a: i64, expected: f128) !void {
552552fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) !void {
553553 const x = __floatunditf(a);
554554
555 const x_repr = @as(u128, @bitCast(x));
556 const x_hi = @as(u64, @intCast(x_repr >> 64));
557 const x_lo = @as(u64, @truncate(x_repr));
555 const x_repr: u128 = @bitCast(x);
556 const x_hi: u64 = @intCast(x_repr >> 64);
557 const x_lo: u64 = @truncate(x_repr);
558558
559559 if (x_hi == expected_hi and x_lo == expected_lo) {
560560 return;
lib/compiler_rt/floor.zig+2-2
......@@ -26,7 +26,7 @@ comptime {
2626}
2727
2828pub fn __floorh(x: f16) callconv(.C) f16 {
29 var u = @as(u16, @bitCast(x));
29 var u: u16 = @bitCast(x);
3030 const e = @as(i16, @intCast((u >> 10) & 31)) - 15;
3131 var m: u16 = undefined;
3232
......@@ -132,7 +132,7 @@ pub fn __floorx(x: f80) callconv(.C) f80 {
132132pub fn floorq(x: f128) callconv(.C) f128 {
133133 const f128_toint = 1.0 / math.floatEps(f128);
134134
135 const u = @as(u128, @bitCast(x));
135 const u: u128 = @bitCast(x);
136136 const e = (u >> 112) & 0x7FFF;
137137 var y: f128 = undefined;
138138
lib/compiler_rt/fmod.zig+15-15
......@@ -22,7 +22,7 @@ comptime {
2222
2323pub fn __fmodh(x: f16, y: f16) callconv(.C) f16 {
2424 // TODO: more efficient implementation
25 return @as(f16, @floatCast(fmodf(x, y)));
25 return @floatCast(fmodf(x, y));
2626}
2727
2828pub fn fmodf(x: f32, y: f32) callconv(.C) f32 {
......@@ -46,12 +46,12 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
4646 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
4747 const maxExponent = ((1 << exponentBits) - 1);
4848
49 var aRep = @as(Z, @bitCast(a));
50 var bRep = @as(Z, @bitCast(b));
49 var aRep: Z = @bitCast(a);
50 var bRep: Z = @bitCast(b);
5151
5252 const signA = aRep & signBit;
53 var expA = @as(i32, @intCast((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
54 var expB = @as(i32, @intCast((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
53 var expA: i32 = @intCast((@as(Z, @bitCast(a)) >> significandBits) & maxExponent);
54 var expB: i32 = @intCast((@as(Z, @bitCast(b)) >> significandBits) & maxExponent);
5555
5656 // There are 3 cases where the answer is undefined, check for:
5757 // - fmodx(val, 0)
......@@ -123,11 +123,11 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
123123
124124 // Combine the exponent with the sign and significand, normalize if happened to be denormalized
125125 if (expA < -fractionalBits) {
126 return @as(T, @bitCast(signA));
126 return @bitCast(signA);
127127 } else if (expA <= 0) {
128 return @as(T, @bitCast((lowA >> @as(math.Log2Int(u64), @intCast(1 - expA))) | signA));
128 return @bitCast((lowA >> @as(math.Log2Int(u64), @intCast(1 - expA))) | signA);
129129 } else {
130 return @as(T, @bitCast(lowA | (@as(Z, @as(u16, @intCast(expA))) << significandBits) | signA));
130 return @bitCast(lowA | (@as(Z, @as(u16, @intCast(expA))) << significandBits) | signA);
131131 }
132132}
133133
......@@ -155,8 +155,8 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
155155 };
156156
157157 const signA = aPtr_u16[exp_and_sign_index] & 0x8000;
158 var expA = @as(i32, @intCast((aPtr_u16[exp_and_sign_index] & 0x7fff)));
159 var expB = @as(i32, @intCast((bPtr_u16[exp_and_sign_index] & 0x7fff)));
158 var expA: i32 = @intCast((aPtr_u16[exp_and_sign_index] & 0x7fff));
159 var expB: i32 = @intCast((bPtr_u16[exp_and_sign_index] & 0x7fff));
160160
161161 // There are 3 cases where the answer is undefined, check for:
162162 // - fmodq(val, 0)
......@@ -270,10 +270,10 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {
270270 const exp_bits = if (T == f32) 9 else 12;
271271 const bits_minus_1 = bits - 1;
272272 const mask = if (T == f32) 0xff else 0x7ff;
273 var ux = @as(uint, @bitCast(x));
274 var uy = @as(uint, @bitCast(y));
275 var ex = @as(i32, @intCast((ux >> digits) & mask));
276 var ey = @as(i32, @intCast((uy >> digits) & mask));
273 var ux: uint = @bitCast(x);
274 var uy: uint = @bitCast(y);
275 var ex: i32 = @intCast((ux >> digits) & mask);
276 var ey: i32 = @intCast((uy >> digits) & mask);
277277 const sx = if (T == f32) @as(u32, @intCast(ux & 0x80000000)) else @as(i32, @intCast(ux >> bits_minus_1));
278278 var i: uint = undefined;
279279
......@@ -343,7 +343,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {
343343 } else {
344344 ux |= @as(uint, @intCast(sx)) << bits_minus_1;
345345 }
346 return @as(T, @bitCast(ux));
346 return @bitCast(ux);
347347}
348348
349349test "fmodf" {
lib/compiler_rt/log.zig+12-12
......@@ -27,7 +27,7 @@ comptime {
2727
2828pub fn __logh(a: f16) callconv(.C) f16 {
2929 // TODO: more efficient implementation
30 return @as(f16, @floatCast(logf(a)));
30 return @floatCast(logf(a));
3131}
3232
3333pub fn logf(x_: f32) callconv(.C) f32 {
......@@ -39,7 +39,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {
3939 const Lg4: f32 = 0xf89e26.0p-26;
4040
4141 var x = x_;
42 var ix = @as(u32, @bitCast(x));
42 var ix: u32 = @bitCast(x);
4343 var k: i32 = 0;
4444
4545 // x < 2^(-126)
......@@ -56,7 +56,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {
5656 // subnormal, scale x
5757 k -= 25;
5858 x *= 0x1.0p25;
59 ix = @as(u32, @bitCast(x));
59 ix = @bitCast(x);
6060 } else if (ix >= 0x7F800000) {
6161 return x;
6262 } else if (ix == 0x3F800000) {
......@@ -67,7 +67,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {
6767 ix += 0x3F800000 - 0x3F3504F3;
6868 k += @as(i32, @intCast(ix >> 23)) - 0x7F;
6969 ix = (ix & 0x007FFFFF) + 0x3F3504F3;
70 x = @as(f32, @bitCast(ix));
70 x = @bitCast(ix);
7171
7272 const f = x - 1.0;
7373 const s = f / (2.0 + f);
......@@ -77,7 +77,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {
7777 const t2 = z * (Lg1 + w * Lg3);
7878 const R = t2 + t1;
7979 const hfsq = 0.5 * f * f;
80 const dk = @as(f32, @floatFromInt(k));
80 const dk: f32 = @floatFromInt(k);
8181
8282 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
8383}
......@@ -94,8 +94,8 @@ pub fn log(x_: f64) callconv(.C) f64 {
9494 const Lg7: f64 = 1.479819860511658591e-01;
9595
9696 var x = x_;
97 var ix = @as(u64, @bitCast(x));
98 var hx = @as(u32, @intCast(ix >> 32));
97 var ix: u64 = @bitCast(x);
98 var hx: u32 = @intCast(ix >> 32);
9999 var k: i32 = 0;
100100
101101 if (hx < 0x00100000 or hx >> 31 != 0) {
......@@ -111,7 +111,7 @@ pub fn log(x_: f64) callconv(.C) f64 {
111111 // subnormal, scale x
112112 k -= 54;
113113 x *= 0x1.0p54;
114 hx = @as(u32, @intCast(@as(u64, @bitCast(ix)) >> 32));
114 hx = @intCast(@as(u64, @bitCast(ix)) >> 32);
115115 } else if (hx >= 0x7FF00000) {
116116 return x;
117117 } else if (hx == 0x3FF00000 and ix << 32 == 0) {
......@@ -123,7 +123,7 @@ pub fn log(x_: f64) callconv(.C) f64 {
123123 k += @as(i32, @intCast(hx >> 20)) - 0x3FF;
124124 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
125125 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
126 x = @as(f64, @bitCast(ix));
126 x = @bitCast(ix);
127127
128128 const f = x - 1.0;
129129 const hfsq = 0.5 * f * f;
......@@ -133,19 +133,19 @@ pub fn log(x_: f64) callconv(.C) f64 {
133133 const t1 = w * (Lg2 + w * (Lg4 + w * Lg6));
134134 const t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));
135135 const R = t2 + t1;
136 const dk = @as(f64, @floatFromInt(k));
136 const dk: f64 = @floatFromInt(k);
137137
138138 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
139139}
140140
141141pub fn __logx(a: f80) callconv(.C) f80 {
142142 // TODO: more efficient implementation
143 return @as(f80, @floatCast(logq(a)));
143 return @floatCast(logq(a));
144144}
145145
146146pub fn logq(a: f128) callconv(.C) f128 {
147147 // TODO: more correct implementation
148 return log(@as(f64, @floatCast(a)));
148 return log(@floatCast(a));
149149}
150150
151151pub fn logl(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/log10.zig+10-10
......@@ -82,11 +82,11 @@ pub fn log10f(x_: f32) callconv(.C) f32 {
8282 const hfsq = 0.5 * f * f;
8383
8484 var hi = f - hfsq;
85 u = @as(u32, @bitCast(hi));
85 u = @bitCast(hi);
8686 u &= 0xFFFFF000;
87 hi = @as(f32, @bitCast(u));
87 hi = @bitCast(u);
8888 const lo = f - hi - hfsq + s * (hfsq + R);
89 const dk = @as(f32, @floatFromInt(k));
89 const dk: f32 = @floatFromInt(k);
9090
9191 return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi;
9292}
......@@ -105,8 +105,8 @@ pub fn log10(x_: f64) callconv(.C) f64 {
105105 const Lg7: f64 = 1.479819860511658591e-01;
106106
107107 var x = x_;
108 var ix = @as(u64, @bitCast(x));
109 var hx = @as(u32, @intCast(ix >> 32));
108 var ix: u64 = @bitCast(x);
109 var hx: u32 = @intCast(ix >> 32);
110110 var k: i32 = 0;
111111
112112 if (hx < 0x00100000 or hx >> 31 != 0) {
......@@ -122,7 +122,7 @@ pub fn log10(x_: f64) callconv(.C) f64 {
122122 // subnormal, scale x
123123 k -= 54;
124124 x *= 0x1.0p54;
125 hx = @as(u32, @intCast(@as(u64, @bitCast(x)) >> 32));
125 hx = @intCast(@as(u64, @bitCast(x)) >> 32);
126126 } else if (hx >= 0x7FF00000) {
127127 return x;
128128 } else if (hx == 0x3FF00000 and ix << 32 == 0) {
......@@ -134,7 +134,7 @@ pub fn log10(x_: f64) callconv(.C) f64 {
134134 k += @as(i32, @intCast(hx >> 20)) - 0x3FF;
135135 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
136136 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
137 x = @as(f64, @bitCast(ix));
137 x = @bitCast(ix);
138138
139139 const f = x - 1.0;
140140 const hfsq = 0.5 * f * f;
......@@ -147,14 +147,14 @@ pub fn log10(x_: f64) callconv(.C) f64 {
147147
148148 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
149149 var hi = f - hfsq;
150 var hii = @as(u64, @bitCast(hi));
150 var hii: u64 = @bitCast(hi);
151151 hii &= @as(u64, maxInt(u64)) << 32;
152 hi = @as(f64, @bitCast(hii));
152 hi = @bitCast(hii);
153153 const lo = f - hi - hfsq + s * (hfsq + R);
154154
155155 // val_hi + val_lo ~ log10(1 + f) + k * log10(2)
156156 var val_hi = hi * ivln10hi;
157 const dk = @as(f64, @floatFromInt(k));
157 const dk: f64 = @floatFromInt(k);
158158 const y = dk * log10_2hi;
159159 var val_lo = dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi;
160160
lib/compiler_rt/log2.zig+14-14
......@@ -28,7 +28,7 @@ comptime {
2828
2929pub fn __log2h(a: f16) callconv(.C) f16 {
3030 // TODO: more efficient implementation
31 return @as(f16, @floatCast(log2f(a)));
31 return @floatCast(log2f(a));
3232}
3333
3434pub fn log2f(x_: f32) callconv(.C) f32 {
......@@ -40,7 +40,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 {
4040 const Lg4: f32 = 0xf89e26.0p-26;
4141
4242 var x = x_;
43 var u = @as(u32, @bitCast(x));
43 var u: u32 = @bitCast(x);
4444 var ix = u;
4545 var k: i32 = 0;
4646
......@@ -57,7 +57,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 {
5757
5858 k -= 25;
5959 x *= 0x1.0p25;
60 ix = @as(u32, @bitCast(x));
60 ix = @bitCast(x);
6161 } else if (ix >= 0x7F800000) {
6262 return x;
6363 } else if (ix == 0x3F800000) {
......@@ -68,7 +68,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 {
6868 ix += 0x3F800000 - 0x3F3504F3;
6969 k += @as(i32, @intCast(ix >> 23)) - 0x7F;
7070 ix = (ix & 0x007FFFFF) + 0x3F3504F3;
71 x = @as(f32, @bitCast(ix));
71 x = @bitCast(ix);
7272
7373 const f = x - 1.0;
7474 const s = f / (2.0 + f);
......@@ -80,9 +80,9 @@ pub fn log2f(x_: f32) callconv(.C) f32 {
8080 const hfsq = 0.5 * f * f;
8181
8282 var hi = f - hfsq;
83 u = @as(u32, @bitCast(hi));
83 u = @bitCast(hi);
8484 u &= 0xFFFFF000;
85 hi = @as(f32, @bitCast(u));
85 hi = @bitCast(u);
8686 const lo = f - hi - hfsq + s * (hfsq + R);
8787 return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + @as(f32, @floatFromInt(k));
8888}
......@@ -99,8 +99,8 @@ pub fn log2(x_: f64) callconv(.C) f64 {
9999 const Lg7: f64 = 1.479819860511658591e-01;
100100
101101 var x = x_;
102 var ix = @as(u64, @bitCast(x));
103 var hx = @as(u32, @intCast(ix >> 32));
102 var ix: u64 = @bitCast(x);
103 var hx: u32 = @intCast(ix >> 32);
104104 var k: i32 = 0;
105105
106106 if (hx < 0x00100000 or hx >> 31 != 0) {
......@@ -116,7 +116,7 @@ pub fn log2(x_: f64) callconv(.C) f64 {
116116 // subnormal, scale x
117117 k -= 54;
118118 x *= 0x1.0p54;
119 hx = @as(u32, @intCast(@as(u64, @bitCast(x)) >> 32));
119 hx = @intCast(@as(u64, @bitCast(x)) >> 32);
120120 } else if (hx >= 0x7FF00000) {
121121 return x;
122122 } else if (hx == 0x3FF00000 and ix << 32 == 0) {
......@@ -128,7 +128,7 @@ pub fn log2(x_: f64) callconv(.C) f64 {
128128 k += @as(i32, @intCast(hx >> 20)) - 0x3FF;
129129 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
130130 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
131 x = @as(f64, @bitCast(ix));
131 x = @bitCast(ix);
132132
133133 const f = x - 1.0;
134134 const hfsq = 0.5 * f * f;
......@@ -143,14 +143,14 @@ pub fn log2(x_: f64) callconv(.C) f64 {
143143 var hi = f - hfsq;
144144 var hii = @as(u64, @bitCast(hi));
145145 hii &= @as(u64, maxInt(u64)) << 32;
146 hi = @as(f64, @bitCast(hii));
146 hi = @bitCast(hii);
147147 const lo = f - hi - hfsq + s * (hfsq + R);
148148
149149 var val_hi = hi * ivln2hi;
150150 var val_lo = (lo + hi) * ivln2lo + lo * ivln2hi;
151151
152152 // spadd(val_hi, val_lo, y)
153 const y = @as(f64, @floatFromInt(k));
153 const y: f64 = @floatFromInt(k);
154154 const ww = y + val_hi;
155155 val_lo += (y - ww) + val_hi;
156156 val_hi = ww;
......@@ -160,12 +160,12 @@ pub fn log2(x_: f64) callconv(.C) f64 {
160160
161161pub fn __log2x(a: f80) callconv(.C) f80 {
162162 // TODO: more efficient implementation
163 return @as(f80, @floatCast(log2q(a)));
163 return @floatCast(log2q(a));
164164}
165165
166166pub fn log2q(a: f128) callconv(.C) f128 {
167167 // TODO: more correct implementation
168 return log2(@as(f64, @floatCast(a)));
168 return log2(@floatCast(a));
169169}
170170
171171pub fn log2l(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/modti3.zig+1-1
......@@ -24,7 +24,7 @@ pub fn __modti3(a: i128, b: i128) callconv(.C) i128 {
2424const v2u64 = @Vector(2, u64);
2525
2626fn __modti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {
27 return @as(v2u64, @bitCast(mod(@as(i128, @bitCast(a)), @as(i128, @bitCast(b)))));
27 return @bitCast(mod(@as(i128, @bitCast(a)), @as(i128, @bitCast(b))));
2828}
2929
3030inline fn mod(a: i128, b: i128) i128 {
lib/compiler_rt/mulXi3.zig+4-4
......@@ -21,8 +21,8 @@ comptime {
2121}
2222
2323pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
24 var ua = @as(u32, @bitCast(a));
25 var ub = @as(u32, @bitCast(b));
24 var ua: u32 = @bitCast(a);
25 var ub: u32 = @bitCast(b);
2626 var r: u32 = 0;
2727
2828 while (ua > 0) {
......@@ -31,7 +31,7 @@ pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
3131 ub <<= 1;
3232 }
3333
34 return @as(i32, @bitCast(r));
34 return @bitCast(r);
3535}
3636
3737pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 {
......@@ -93,7 +93,7 @@ pub fn __multi3(a: i128, b: i128) callconv(.C) i128 {
9393const v2u64 = @Vector(2, u64);
9494
9595fn __multi3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {
96 return @as(v2u64, @bitCast(mulX(i128, @as(i128, @bitCast(a)), @as(i128, @bitCast(b)))));
96 return @bitCast(mulX(i128, @as(i128, @bitCast(a)), @as(i128, @bitCast(b))));
9797}
9898
9999test {
lib/compiler_rt/mulf3.zig+6-6
......@@ -54,27 +54,27 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
5454 if (aAbs == infRep) {
5555 // infinity * non-zero = +/- infinity
5656 if (bAbs != 0) {
57 return @as(T, @bitCast(aAbs | productSign));
57 return @bitCast(aAbs | productSign);
5858 } else {
5959 // infinity * zero = NaN
60 return @as(T, @bitCast(qnanRep));
60 return @bitCast(qnanRep);
6161 }
6262 }
6363
6464 if (bAbs == infRep) {
6565 //? non-zero * infinity = +/- infinity
6666 if (aAbs != 0) {
67 return @as(T, @bitCast(bAbs | productSign));
67 return @bitCast(bAbs | productSign);
6868 } else {
6969 // zero * infinity = NaN
70 return @as(T, @bitCast(qnanRep));
70 return @bitCast(qnanRep);
7171 }
7272 }
7373
7474 // zero * anything = +/- zero
75 if (aAbs == 0) return @as(T, @bitCast(productSign));
75 if (aAbs == 0) return @bitCast(productSign);
7676 // anything * zero = +/- zero
77 if (bAbs == 0) return @as(T, @bitCast(productSign));
77 if (bAbs == 0) return @bitCast(productSign);
7878
7979 // one or both of a or b is denormal, the other (if applicable) is a
8080 // normal number. Renormalize one or both of a and b, and set scale to
lib/compiler_rt/mulf3_test.zig+8-9
......@@ -4,8 +4,8 @@
44
55const std = @import("std");
66const math = std.math;
7const qnan128 = @as(f128, @bitCast(@as(u128, 0x7fff800000000000) << 64));
8const inf128 = @as(f128, @bitCast(@as(u128, 0x7fff000000000000) << 64));
7const qnan128: f128 = @bitCast(@as(u128, 0x7fff800000000000) << 64);
8const inf128: f128 = @bitCast(@as(u128, 0x7fff000000000000) << 64);
99
1010const __multf3 = @import("multf3.zig").__multf3;
1111const __mulxf3 = @import("mulxf3.zig").__mulxf3;
......@@ -16,9 +16,9 @@ const __mulsf3 = @import("mulsf3.zig").__mulsf3;
1616// use two 64-bit integers intead of one 128-bit integer
1717// because 128-bit integer constant can't be assigned directly
1818fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
19 const rep = @as(u128, @bitCast(result));
20 const hi = @as(u64, @intCast(rep >> 64));
21 const lo = @as(u64, @truncate(rep));
19 const rep: u128 = @bitCast(result);
20 const hi: u64 = @intCast(rep >> 64);
21 const lo: u64 = @truncate(rep);
2222
2323 if (hi == expectedHi and lo == expectedLo) {
2424 return true;
......@@ -45,8 +45,7 @@ fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
4545
4646fn makeNaN128(rand: u64) f128 {
4747 const int_result = @as(u128, 0x7fff000000000000 | (rand & 0xffffffffffff)) << 64;
48 const float_result = @as(f128, @bitCast(int_result));
49 return float_result;
48 return @bitCast(int_result);
5049}
5150test "multf3" {
5251 // qNaN * any = qNaN
......@@ -108,11 +107,11 @@ test "multf3" {
108107 try test__multf3(2.0, math.floatTrueMin(f128), 0x0000_0000_0000_0000, 0x0000_0000_0000_0002);
109108}
110109
111const qnan80 = @as(f80, @bitCast(@as(u80, @bitCast(math.nan(f80))) | (1 << (math.floatFractionalBits(f80) - 1))));
110const qnan80: f80 = @bitCast(@as(u80, @bitCast(math.nan(f80))) | (1 << (math.floatFractionalBits(f80) - 1)));
112111
113112fn test__mulxf3(a: f80, b: f80, expected: u80) !void {
114113 const x = __mulxf3(a, b);
115 const rep = @as(u80, @bitCast(x));
114 const rep: u80 = @bitCast(x);
116115
117116 if (rep == expected)
118117 return;
lib/compiler_rt/parityti2_test.zig+1-1
......@@ -3,7 +3,7 @@ const parity = @import("parity.zig");
33const testing = std.testing;
44
55fn parityti2Naive(a: i128) i32 {
6 var x = @as(u128, @bitCast(a));
6 var x: u128 = @bitCast(a);
77 var has_parity: bool = false;
88 while (x > 0) {
99 has_parity = !has_parity;
lib/compiler_rt/rem_pio2.zig+8-8
......@@ -57,17 +57,17 @@ fn medium(ix: u32, x: f64, y: *[2]f64) i32 {
5757 w = @"fn" * pio2_1t;
5858 }
5959 y[0] = r - w;
60 ui = @as(u64, @bitCast(y[0]));
61 ey = @as(i32, @intCast((ui >> 52) & 0x7ff));
62 ex = @as(i32, @intCast(ix >> 20));
60 ui = @bitCast(y[0]);
61 ey = @intCast((ui >> 52) & 0x7ff);
62 ex = @intCast(ix >> 20);
6363 if (ex - ey > 16) { // 2nd round, good to 118 bits
6464 t = r;
6565 w = @"fn" * pio2_2;
6666 r = t - w;
6767 w = @"fn" * pio2_2t - ((t - r) - w);
6868 y[0] = r - w;
69 ui = @as(u64, @bitCast(y[0]));
70 ey = @as(i32, @intCast((ui >> 52) & 0x7ff));
69 ui = @bitCast(y[0]);
70 ey = @intCast((ui >> 52) & 0x7ff);
7171 if (ex - ey > 49) { // 3rd round, good to 151 bits, covers all cases
7272 t = r;
7373 w = @"fn" * pio2_3;
......@@ -95,9 +95,9 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 {
9595 var i: i32 = undefined;
9696 var ui: u64 = undefined;
9797
98 ui = @as(u64, @bitCast(x));
98 ui = @bitCast(x);
9999 sign = ui >> 63 != 0;
100 ix = @as(u32, @truncate((ui >> 32) & 0x7fffffff));
100 ix = @truncate((ui >> 32) & 0x7fffffff);
101101 if (ix <= 0x400f6a7a) { // |x| ~<= 5pi/4
102102 if ((ix & 0xfffff) == 0x921fb) { // |x| ~= pi/2 or 2pi/2
103103 return medium(ix, x, y);
......@@ -171,7 +171,7 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 {
171171 return 0;
172172 }
173173 // set z = scalbn(|x|,-ilogb(x)+23)
174 ui = @as(u64, @bitCast(x));
174 ui = @bitCast(x);
175175 ui &= std.math.maxInt(u64) >> 12;
176176 ui |= @as(u64, 0x3ff + 23) << 52;
177177 z = @as(f64, @bitCast(ui));
lib/compiler_rt/rem_pio2_large.zig+3-3
......@@ -322,7 +322,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
322322 i += 1;
323323 j -= 1;
324324 }) {
325 fw = @as(f64, @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z))));
325 fw = @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z)));
326326 iq[U(i)] = @as(i32, @intFromFloat(z - 0x1p24 * fw));
327327 z = q[U(j - 1)] + fw;
328328 }
......@@ -330,7 +330,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
330330 // compute n
331331 z = math.scalbn(z, q0); // actual value of z
332332 z -= 8.0 * @floor(z * 0.125); // trim off integer >= 8
333 n = @as(i32, @intFromFloat(z));
333 n = @intFromFloat(z);
334334 z -= @as(f64, @floatFromInt(n));
335335 ih = 0;
336336 if (q0 > 0) { // need iq[jz-1] to determine n
......@@ -414,7 +414,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
414414 } else { // break z into 24-bit if necessary
415415 z = math.scalbn(z, -q0);
416416 if (z >= 0x1p24) {
417 fw = @as(f64, @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z))));
417 fw = @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z)));
418418 iq[U(jz)] = @as(i32, @intFromFloat(z - 0x1p24 * fw));
419419 jz += 1;
420420 q0 += 24;
lib/compiler_rt/rem_pio2f.zig+2-2
......@@ -30,14 +30,14 @@ pub fn rem_pio2f(x: f32, y: *f64) i32 {
3030 var e0: u32 = undefined;
3131 var ui: u32 = undefined;
3232
33 ui = @as(u32, @bitCast(x));
33 ui = @bitCast(x);
3434 ix = ui & 0x7fffffff;
3535
3636 // 25+53 bit pi is good enough for medium size
3737 if (ix < 0x4dc90fdb) { // |x| ~< 2^28*(pi/2), medium size
3838 // Use a specialized rint() to get fn.
3939 @"fn" = @as(f64, @floatCast(x)) * invpio2 + toint - toint;
40 n = @as(i32, @intFromFloat(@"fn"));
40 n = @intFromFloat(@"fn");
4141 y.* = x - @"fn" * pio2_1 - @"fn" * pio2_1t;
4242 // Matters with directed rounding.
4343 if (y.* < -pio4) {
lib/compiler_rt/round.zig+5-5
......@@ -27,14 +27,14 @@ comptime {
2727
2828pub fn __roundh(x: f16) callconv(.C) f16 {
2929 // TODO: more efficient implementation
30 return @as(f16, @floatCast(roundf(x)));
30 return @floatCast(roundf(x));
3131}
3232
3333pub fn roundf(x_: f32) callconv(.C) f32 {
3434 const f32_toint = 1.0 / math.floatEps(f32);
3535
3636 var x = x_;
37 const u = @as(u32, @bitCast(x));
37 const u: u32 = @bitCast(x);
3838 const e = (u >> 23) & 0xFF;
3939 var y: f32 = undefined;
4040
......@@ -69,7 +69,7 @@ pub fn round(x_: f64) callconv(.C) f64 {
6969 const f64_toint = 1.0 / math.floatEps(f64);
7070
7171 var x = x_;
72 const u = @as(u64, @bitCast(x));
72 const u: u64 = @bitCast(x);
7373 const e = (u >> 52) & 0x7FF;
7474 var y: f64 = undefined;
7575
......@@ -102,14 +102,14 @@ pub fn round(x_: f64) callconv(.C) f64 {
102102
103103pub fn __roundx(x: f80) callconv(.C) f80 {
104104 // TODO: more efficient implementation
105 return @as(f80, @floatCast(roundq(x)));
105 return @floatCast(roundq(x));
106106}
107107
108108pub fn roundq(x_: f128) callconv(.C) f128 {
109109 const f128_toint = 1.0 / math.floatEps(f128);
110110
111111 var x = x_;
112 const u = @as(u128, @bitCast(x));
112 const u: u128 = @bitCast(x);
113113 const e = (u >> 112) & 0x7FFF;
114114 var y: f128 = undefined;
115115
lib/compiler_rt/sincos.zig+1-1
......@@ -218,7 +218,7 @@ inline fn sincos_generic(comptime F: type, x: F, r_sin: *F, r_cos: *F) void {
218218 const bits = @typeInfo(F).Float.bits;
219219 const I = std.meta.Int(.unsigned, bits);
220220 const ix = @as(I, @bitCast(x)) & (math.maxInt(I) >> 1);
221 const se = @as(u16, @truncate(ix >> (bits - 16)));
221 const se: u16 = @truncate(ix >> (bits - 16));
222222
223223 if (se == 0x7fff) {
224224 const result = x - x;
lib/compiler_rt/sqrt.zig+1-1
......@@ -125,7 +125,7 @@ pub fn sqrt(x: f64) callconv(.C) f64 {
125125 }
126126
127127 // normalize x
128 var m = @as(i32, @intCast(ix0 >> 20));
128 var m: i32 = @intCast(ix0 >> 20);
129129 if (m == 0) {
130130 // subnormal
131131 while (ix0 == 0) {
lib/compiler_rt/tan.zig+2-2
......@@ -33,7 +33,7 @@ comptime {
3333
3434pub fn __tanh(x: f16) callconv(.C) f16 {
3535 // TODO: more efficient implementation
36 return @as(f16, @floatCast(tanf(x)));
36 return @floatCast(tanf(x));
3737}
3838
3939pub fn tanf(x: f32) callconv(.C) f32 {
......@@ -43,7 +43,7 @@ pub fn tanf(x: f32) callconv(.C) f32 {
4343 const t3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2
4444 const t4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18
4545
46 var ix = @as(u32, @bitCast(x));
46 var ix: u32 = @bitCast(x);
4747 const sign = ix >> 31 != 0;
4848 ix &= 0x7fffffff;
4949
lib/compiler_rt/trig.zig+1-1
......@@ -199,7 +199,7 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 {
199199 var hx: u32 = undefined;
200200 var sign: bool = undefined;
201201
202 hx = @as(u32, @intCast(@as(u64, @bitCast(x)) >> 32));
202 hx = @intCast(@as(u64, @bitCast(x)) >> 32);
203203 const big = (hx & 0x7fffffff) >= 0x3FE59428; // |x| >= 0.6744
204204 if (big) {
205205 sign = hx >> 31 != 0;
lib/compiler_rt/trunc.zig+5-5
......@@ -27,11 +27,11 @@ comptime {
2727
2828pub fn __trunch(x: f16) callconv(.C) f16 {
2929 // TODO: more efficient implementation
30 return @as(f16, @floatCast(truncf(x)));
30 return @floatCast(truncf(x));
3131}
3232
3333pub fn truncf(x: f32) callconv(.C) f32 {
34 const u = @as(u32, @bitCast(x));
34 const u: u32 = @bitCast(x);
3535 var e = @as(i32, @intCast(((u >> 23) & 0xFF))) - 0x7F + 9;
3636 var m: u32 = undefined;
3737
......@@ -47,12 +47,12 @@ pub fn truncf(x: f32) callconv(.C) f32 {
4747 return x;
4848 } else {
4949 math.doNotOptimizeAway(x + 0x1p120);
50 return @as(f32, @bitCast(u & ~m));
50 return @bitCast(u & ~m);
5151 }
5252}
5353
5454pub fn trunc(x: f64) callconv(.C) f64 {
55 const u = @as(u64, @bitCast(x));
55 const u: u64 = @bitCast(x);
5656 var e = @as(i32, @intCast(((u >> 52) & 0x7FF))) - 0x3FF + 12;
5757 var m: u64 = undefined;
5858
......@@ -68,7 +68,7 @@ pub fn trunc(x: f64) callconv(.C) f64 {
6868 return x;
6969 } else {
7070 math.doNotOptimizeAway(x + 0x1p120);
71 return @as(f64, @bitCast(u & ~m));
71 return @bitCast(u & ~m);
7272 }
7373}
7474
lib/compiler_rt/truncf.zig+2-2
......@@ -72,8 +72,8 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
7272 // a underflows on conversion to the destination type or is an exact
7373 // zero. The result may be a denormal or zero. Extract the exponent
7474 // to get the shift amount for the denormalization.
75 const aExp = @as(u32, @intCast(aAbs >> srcSigBits));
76 const shift = @as(u32, @intCast(srcExpBias - dstExpBias - aExp + 1));
75 const aExp: u32 = @intCast(aAbs >> srcSigBits);
76 const shift: u32 = @intCast(srcExpBias - dstExpBias - aExp + 1);
7777
7878 const significand: src_rep_t = (aRep & srcSignificandMask) | srcMinNormal;
7979
lib/compiler_rt/truncf_test.zig+20-20
......@@ -10,7 +10,7 @@ const __trunctfdf2 = @import("trunctfdf2.zig").__trunctfdf2;
1010const __trunctfxf2 = @import("trunctfxf2.zig").__trunctfxf2;
1111
1212fn test__truncsfhf2(a: u32, expected: u16) !void {
13 const actual = @as(u16, @bitCast(__truncsfhf2(@as(f32, @bitCast(a)))));
13 const actual: u16 = @bitCast(__truncsfhf2(@bitCast(a)));
1414
1515 if (actual == expected) {
1616 return;
......@@ -73,7 +73,7 @@ test "truncsfhf2" {
7373}
7474
7575fn test__truncdfhf2(a: f64, expected: u16) void {
76 const rep = @as(u16, @bitCast(__truncdfhf2(a)));
76 const rep: u16 = @bitCast(__truncdfhf2(a));
7777
7878 if (rep == expected) {
7979 return;
......@@ -89,7 +89,7 @@ fn test__truncdfhf2(a: f64, expected: u16) void {
8989}
9090
9191fn test__truncdfhf2_raw(a: u64, expected: u16) void {
92 const actual = @as(u16, @bitCast(__truncdfhf2(@as(f64, @bitCast(a)))));
92 const actual: u16 = @bitCast(__truncdfhf2(@bitCast(a)));
9393
9494 if (actual == expected) {
9595 return;
......@@ -141,7 +141,7 @@ test "truncdfhf2" {
141141fn test__trunctfsf2(a: f128, expected: u32) void {
142142 const x = __trunctfsf2(a);
143143
144 const rep = @as(u32, @bitCast(x));
144 const rep: u32 = @bitCast(x);
145145 if (rep == expected) {
146146 return;
147147 }
......@@ -157,11 +157,11 @@ fn test__trunctfsf2(a: f128, expected: u32) void {
157157
158158test "trunctfsf2" {
159159 // qnan
160 test__trunctfsf2(@as(f128, @bitCast(@as(u128, 0x7fff800000000000 << 64))), 0x7fc00000);
160 test__trunctfsf2(@bitCast(@as(u128, 0x7fff800000000000 << 64)), 0x7fc00000);
161161 // nan
162 test__trunctfsf2(@as(f128, @bitCast(@as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64))), 0x7fc08000);
162 test__trunctfsf2(@bitCast(@as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7fc08000);
163163 // inf
164 test__trunctfsf2(@as(f128, @bitCast(@as(u128, 0x7fff000000000000 << 64))), 0x7f800000);
164 test__trunctfsf2(@bitCast(@as(u128, 0x7fff000000000000 << 64)), 0x7f800000);
165165 // zero
166166 test__trunctfsf2(0.0, 0x0);
167167
......@@ -174,7 +174,7 @@ test "trunctfsf2" {
174174fn test__trunctfdf2(a: f128, expected: u64) void {
175175 const x = __trunctfdf2(a);
176176
177 const rep = @as(u64, @bitCast(x));
177 const rep: u64 = @bitCast(x);
178178 if (rep == expected) {
179179 return;
180180 }
......@@ -190,11 +190,11 @@ fn test__trunctfdf2(a: f128, expected: u64) void {
190190
191191test "trunctfdf2" {
192192 // qnan
193 test__trunctfdf2(@as(f128, @bitCast(@as(u128, 0x7fff800000000000 << 64))), 0x7ff8000000000000);
193 test__trunctfdf2(@bitCast(@as(u128, 0x7fff800000000000 << 64)), 0x7ff8000000000000);
194194 // nan
195 test__trunctfdf2(@as(f128, @bitCast(@as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64))), 0x7ff8100000000000);
195 test__trunctfdf2(@bitCast(@as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7ff8100000000000);
196196 // inf
197 test__trunctfdf2(@as(f128, @bitCast(@as(u128, 0x7fff000000000000 << 64))), 0x7ff0000000000000);
197 test__trunctfdf2(@bitCast(@as(u128, 0x7fff000000000000 << 64)), 0x7ff0000000000000);
198198 // zero
199199 test__trunctfdf2(0.0, 0x0);
200200
......@@ -207,7 +207,7 @@ test "trunctfdf2" {
207207fn test__truncdfsf2(a: f64, expected: u32) void {
208208 const x = __truncdfsf2(a);
209209
210 const rep = @as(u32, @bitCast(x));
210 const rep: u32 = @bitCast(x);
211211 if (rep == expected) {
212212 return;
213213 }
......@@ -225,11 +225,11 @@ fn test__truncdfsf2(a: f64, expected: u32) void {
225225
226226test "truncdfsf2" {
227227 // nan & qnan
228 test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0x7ff8000000000000))), 0x7fc00000);
229 test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0x7ff0000000000001))), 0x7fc00000);
228 test__truncdfsf2(@bitCast(@as(u64, 0x7ff8000000000000)), 0x7fc00000);
229 test__truncdfsf2(@bitCast(@as(u64, 0x7ff0000000000001)), 0x7fc00000);
230230 // inf
231 test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0x7ff0000000000000))), 0x7f800000);
232 test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0xfff0000000000000))), 0xff800000);
231 test__truncdfsf2(@bitCast(@as(u64, 0x7ff0000000000000)), 0x7f800000);
232 test__truncdfsf2(@bitCast(@as(u64, 0xfff0000000000000)), 0xff800000);
233233
234234 test__truncdfsf2(0.0, 0x0);
235235 test__truncdfsf2(1.0, 0x3f800000);
......@@ -242,7 +242,7 @@ test "truncdfsf2" {
242242fn test__trunctfhf2(a: f128, expected: u16) void {
243243 const x = __trunctfhf2(a);
244244
245 const rep = @as(u16, @bitCast(x));
245 const rep: u16 = @bitCast(x);
246246 if (rep == expected) {
247247 return;
248248 }
......@@ -254,11 +254,11 @@ fn test__trunctfhf2(a: f128, expected: u16) void {
254254
255255test "trunctfhf2" {
256256 // qNaN
257 test__trunctfhf2(@as(f128, @bitCast(@as(u128, 0x7fff8000000000000000000000000000))), 0x7e00);
257 test__trunctfhf2(@bitCast(@as(u128, 0x7fff8000000000000000000000000000)), 0x7e00);
258258 // NaN
259 test__trunctfhf2(@as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000001))), 0x7e00);
259 test__trunctfhf2(@bitCast(@as(u128, 0x7fff0000000000000000000000000001)), 0x7e00);
260260 // inf
261 test__trunctfhf2(@as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000000))), 0x7c00);
261 test__trunctfhf2(@bitCast(@as(u128, 0x7fff0000000000000000000000000000)), 0x7c00);
262262 test__trunctfhf2(-@as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000000))), 0xfc00);
263263 // zero
264264 test__trunctfhf2(0.0, 0x0);
lib/compiler_rt/trunctfxf2.zig+1-1
......@@ -44,7 +44,7 @@ pub fn __trunctfxf2(a: f128) callconv(.C) f80 {
4444 // destination format. We can convert by simply right-shifting with
4545 // rounding, adding the explicit integer bit, and adjusting the exponent
4646 res.fraction = @as(u64, @truncate(a_abs >> (src_sig_bits - dst_sig_bits))) | integer_bit;
47 res.exp = @as(u16, @truncate(a_abs >> src_sig_bits));
47 res.exp = @truncate(a_abs >> src_sig_bits);
4848
4949 const round_bits = a_abs & round_mask;
5050 if (round_bits > halfway) {
lib/std/Build.zig+1-1
......@@ -1850,7 +1850,7 @@ pub fn hex64(x: u64) [16]u8 {
18501850 var result: [16]u8 = undefined;
18511851 var i: usize = 0;
18521852 while (i < 8) : (i += 1) {
1853 const byte = @as(u8, @truncate(x >> @as(u6, @intCast(8 * i))));
1853 const byte: u8 = @truncate(x >> @as(u6, @intCast(8 * i)));
18541854 result[i * 2 + 0] = hex_charset[byte >> 4];
18551855 result[i * 2 + 1] = hex_charset[byte & 15];
18561856 }
lib/std/crypto/25519/edwards25519.zig+1-1
......@@ -206,7 +206,7 @@ pub const Edwards25519 = struct {
206206 var q = Edwards25519.identityElement;
207207 var pos: usize = 252;
208208 while (true) : (pos -= 4) {
209 const slot = @as(u4, @truncate((s[pos >> 3] >> @as(u3, @truncate(pos)))));
209 const slot: u4 = @truncate((s[pos >> 3] >> @as(u3, @truncate(pos))));
210210 if (vartime) {
211211 if (slot != 0) {
212212 q = q.add(pc[slot]);
lib/std/crypto/aes_ocb.zig+1-1
......@@ -90,7 +90,7 @@ fn AesOcb(comptime Aes: anytype) type {
9090 nx[16 - nonce_length - 1] = 1;
9191 nx[nx.len - nonce_length ..].* = npub;
9292
93 const bottom = @as(u6, @truncate(nx[15]));
93 const bottom: u6 = @truncate(nx[15]);
9494 nx[15] &= 0xc0;
9595 var ktop_: Block = undefined;
9696 aes_enc_ctx.encrypt(&ktop_, &nx);
lib/std/crypto/ff.zig+5-5
......@@ -508,18 +508,18 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
508508 var need_sub = false;
509509 var i: usize = t_bits - 1;
510510 while (true) : (i -= 1) {
511 var carry = @as(u1, @truncate(math.shr(Limb, y, i)));
511 var carry: u1 = @truncate(math.shr(Limb, y, i));
512512 var borrow: u1 = 0;
513513 for (0..self.limbs_count()) |j| {
514514 const l = ct.select(need_sub, d_limbs[j], x_limbs[j]);
515515 var res = (l << 1) + carry;
516516 x_limbs[j] = @as(TLimb, @truncate(res));
517 carry = @as(u1, @truncate(res >> t_bits));
517 carry = @truncate(res >> t_bits);
518518
519519 res = x_limbs[j] -% m_limbs[j] -% borrow;
520520 d_limbs[j] = @as(TLimb, @truncate(res));
521521
522 borrow = @as(u1, @truncate(res >> t_bits));
522 borrow = @truncate(res >> t_bits);
523523 }
524524 need_sub = ct.eql(carry, borrow);
525525 if (i == 0) break;
......@@ -531,7 +531,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
531531 pub fn add(self: Self, x: Fe, y: Fe) Fe {
532532 var out = x;
533533 const overflow = out.v.addWithOverflow(y.v);
534 const underflow = @as(u1, @bitCast(ct.limbsCmpLt(out.v, self.v)));
534 const underflow: u1 = @bitCast(ct.limbsCmpLt(out.v, self.v));
535535 const need_sub = ct.eql(overflow, underflow);
536536 _ = out.v.conditionalSubWithOverflow(need_sub, self.v);
537537 return out;
......@@ -540,7 +540,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
540540 /// Subtracts two field elements (mod m).
541541 pub fn sub(self: Self, x: Fe, y: Fe) Fe {
542542 var out = x;
543 const underflow = @as(bool, @bitCast(out.v.subWithOverflow(y.v)));
543 const underflow: bool = @bitCast(out.v.subWithOverflow(y.v));
544544 _ = out.v.conditionalAddWithOverflow(underflow, self.v);
545545 return out;
546546 }
lib/std/crypto/isap.zig+1-1
......@@ -67,7 +67,7 @@ pub const IsapA128A = struct {
6767 var i: usize = 0;
6868 while (i < y.len * 8 - 1) : (i += 1) {
6969 const cur_byte_pos = i / 8;
70 const cur_bit_pos = @as(u3, @truncate(7 - (i % 8)));
70 const cur_bit_pos: u3 = @truncate(7 - (i % 8));
7171 const cur_bit = ((y[cur_byte_pos] >> cur_bit_pos) & 1) << 7;
7272 isap.st.addByte(cur_bit, 0);
7373 isap.st.permuteR(1);
lib/std/crypto/kyber_d00.zig+2-2
......@@ -638,7 +638,7 @@ fn montReduce(x: i32) i16 {
638638 // Note that x q' might be as big as 2³² and could overflow the int32
639639 // multiplication in the last line. However for any int32s a and b,
640640 // we have int32(int64(a)*int64(b)) = int32(a*b) and so the result is ok.
641 const m = @as(i16, @truncate(@as(i32, @truncate(x *% qInv))));
641 const m: i16 = @truncate(@as(i32, @truncate(x *% qInv)));
642642
643643 // Note that x - m q is divisible by R; indeed modulo R we have
644644 //
......@@ -652,7 +652,7 @@ fn montReduce(x: i32) i16 {
652652 // and as both 2¹⁵ q ≤ m q, x < 2¹⁵ q, we have
653653 // 2¹⁶ q ≤ x - m q < 2¹⁶ and so q ≤ (x - m q) / R < q as desired.
654654 const yR = x - @as(i32, m) * @as(i32, Q);
655 return @as(i16, @bitCast(@as(u16, @truncate(@as(u32, @bitCast(yR)) >> 16))));
655 return @bitCast(@as(u16, @truncate(@as(u32, @bitCast(yR)) >> 16)));
656656}
657657
658658test "Test montReduce" {
lib/std/hash/crc.zig+1-1
......@@ -142,7 +142,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type {
142142 var crc = tables[0][i];
143143 var j: usize = 1;
144144 while (j < 8) : (j += 1) {
145 const index = @as(u8, @truncate(crc));
145 const index: u8 = @truncate(crc);
146146 crc = tables[0][index] ^ (crc >> 8);
147147 tables[j][i] = crc;
148148 }
lib/std/hash/murmur.zig+2-2
......@@ -14,7 +14,7 @@ pub const Murmur2_32 = struct {
1414
1515 pub fn hashWithSeed(str: []const u8, seed: u32) u32 {
1616 const m: u32 = 0x5bd1e995;
17 const len = @as(u32, @truncate(str.len));
17 const len: u32 = @truncate(str.len);
1818 var h1: u32 = seed ^ len;
1919 for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| {
2020 var k1: u32 = v;
......@@ -178,7 +178,7 @@ pub const Murmur3_32 = struct {
178178 pub fn hashWithSeed(str: []const u8, seed: u32) u32 {
179179 const c1: u32 = 0xcc9e2d51;
180180 const c2: u32 = 0x1b873593;
181 const len = @as(u32, @truncate(str.len));
181 const len: u32 = @truncate(str.len);
182182 var h1: u32 = seed;
183183 for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| {
184184 var k1: u32 = v;
lib/std/hash_map.zig+3-3
......@@ -899,7 +899,7 @@ pub fn HashMapUnmanaged(
899899 }
900900
901901 fn capacityForSize(size: Size) Size {
902 var new_cap = @as(u32, @truncate((@as(u64, size) * 100) / max_load_percentage + 1));
902 var new_cap: u32 = @truncate((@as(u64, size) * 100) / max_load_percentage + 1);
903903 new_cap = math.ceilPowerOfTwo(u32, new_cap) catch unreachable;
904904 return new_cap;
905905 }
......@@ -1480,7 +1480,7 @@ pub fn HashMapUnmanaged(
14801480 const new_cap = capacityForSize(self.size);
14811481 try other.allocate(allocator, new_cap);
14821482 other.initMetadatas();
1483 other.available = @as(u32, @truncate((new_cap * max_load_percentage) / 100));
1483 other.available = @truncate((new_cap * max_load_percentage) / 100);
14841484
14851485 var i: Size = 0;
14861486 var metadata = self.metadata.?;
......@@ -1515,7 +1515,7 @@ pub fn HashMapUnmanaged(
15151515 defer map.deinit(allocator);
15161516 try map.allocate(allocator, new_cap);
15171517 map.initMetadatas();
1518 map.available = @as(u32, @truncate((new_cap * max_load_percentage) / 100));
1518 map.available = @truncate((new_cap * max_load_percentage) / 100);
15191519
15201520 if (self.size != 0) {
15211521 const old_capacity = self.capacity();
lib/std/leb128.zig+8-8
......@@ -10,8 +10,8 @@ pub fn readULEB128(comptime T: type, reader: anytype) !T {
1010
1111 const max_group = (@typeInfo(U).Int.bits + 6) / 7;
1212
13 var value = @as(U, 0);
14 var group = @as(ShiftT, 0);
13 var value: U = 0;
14 var group: ShiftT = 0;
1515
1616 while (group < max_group) : (group += 1) {
1717 const byte = try reader.readByte();
......@@ -37,10 +37,10 @@ pub fn readULEB128(comptime T: type, reader: anytype) !T {
3737pub fn writeULEB128(writer: anytype, uint_value: anytype) !void {
3838 const T = @TypeOf(uint_value);
3939 const U = if (@typeInfo(T).Int.bits < 8) u8 else T;
40 var value = @as(U, @intCast(uint_value));
40 var value: U = @intCast(uint_value);
4141
4242 while (true) {
43 const byte = @as(u8, @truncate(value & 0x7f));
43 const byte: u8 = @truncate(value & 0x7f);
4444 value >>= 7;
4545 if (value == 0) {
4646 try writer.writeByte(byte);
......@@ -115,11 +115,11 @@ pub fn writeILEB128(writer: anytype, int_value: anytype) !void {
115115 const S = if (@typeInfo(T).Int.bits < 8) i8 else T;
116116 const U = std.meta.Int(.unsigned, @typeInfo(S).Int.bits);
117117
118 var value = @as(S, @intCast(int_value));
118 var value: S = @intCast(int_value);
119119
120120 while (true) {
121 const uvalue = @as(U, @bitCast(value));
122 const byte = @as(u8, @truncate(uvalue));
121 const uvalue: U = @bitCast(value);
122 const byte: u8 = @truncate(uvalue);
123123 value >>= 6;
124124 if (value == -1 or value == 0) {
125125 try writer.writeByte(byte & 0x7F);
......@@ -141,7 +141,7 @@ pub fn writeILEB128(writer: anytype, int_value: anytype) !void {
141141pub fn writeUnsignedFixed(comptime l: usize, ptr: *[l]u8, int: std.meta.Int(.unsigned, l * 7)) void {
142142 const T = @TypeOf(int);
143143 const U = if (@typeInfo(T).Int.bits < 8) u8 else T;
144 var value = @as(U, @intCast(int));
144 var value: U = @intCast(int);
145145
146146 comptime var i = 0;
147147 inline while (i < (l - 1)) : (i += 1) {
lib/std/math/atanh.zig+2-2
......@@ -55,11 +55,11 @@ fn atanh_32(x: f32) f32 {
5555}
5656
5757fn atanh_64(x: f64) f64 {
58 const u = @as(u64, @bitCast(x));
58 const u: u64 = @bitCast(x);
5959 const e = (u >> 52) & 0x7FF;
6060 const s = u >> 63;
6161
62 var y = @as(f64, @bitCast(u & (maxInt(u64) >> 1))); // |x|
62 var y: f64 = @bitCast(u & (maxInt(u64) >> 1)); // |x|
6363
6464 if (y == 1.0) {
6565 return math.copysign(math.inf(f64), x);
lib/std/math/complex/cosh.zig+8-8
......@@ -26,10 +26,10 @@ fn cosh32(z: Complex(f32)) Complex(f32) {
2626 const x = z.re;
2727 const y = z.im;
2828
29 const hx = @as(u32, @bitCast(x));
29 const hx: u32 = @bitCast(x);
3030 const ix = hx & 0x7fffffff;
3131
32 const hy = @as(u32, @bitCast(y));
32 const hy: u32 = @bitCast(y);
3333 const iy = hy & 0x7fffffff;
3434
3535 if (ix < 0x7f800000 and iy < 0x7f800000) {
......@@ -89,14 +89,14 @@ fn cosh64(z: Complex(f64)) Complex(f64) {
8989 const x = z.re;
9090 const y = z.im;
9191
92 const fx = @as(u64, @bitCast(x));
93 const hx = @as(u32, @intCast(fx >> 32));
94 const lx = @as(u32, @truncate(fx));
92 const fx: u64 = @bitCast(x);
93 const hx: u32 = @intCast(fx >> 32);
94 const lx: u32 = @truncate(fx);
9595 const ix = hx & 0x7fffffff;
9696
97 const fy = @as(u64, @bitCast(y));
98 const hy = @as(u32, @intCast(fy >> 32));
99 const ly = @as(u32, @truncate(fy));
97 const fy: u64 = @bitCast(y);
98 const hy: u32 = @intCast(fy >> 32);
99 const ly: u32 = @truncate(fy);
100100 const iy = hy & 0x7fffffff;
101101
102102 // nearly non-exceptional case where x, y are finite
lib/std/math/complex/exp.zig+6-6
......@@ -75,18 +75,18 @@ fn exp64(z: Complex(f64)) Complex(f64) {
7575 const x = z.re;
7676 const y = z.im;
7777
78 const fy = @as(u64, @bitCast(y));
79 const hy = @as(u32, @intCast((fy >> 32) & 0x7fffffff));
80 const ly = @as(u32, @truncate(fy));
78 const fy: u64 = @bitCast(y);
79 const hy: u32 = @intCast((fy >> 32) & 0x7fffffff);
80 const ly: u32 = @truncate(fy);
8181
8282 // cexp(x + i0) = exp(x) + i0
8383 if (hy | ly == 0) {
8484 return Complex(f64).init(@exp(x), y);
8585 }
8686
87 const fx = @as(u64, @bitCast(x));
88 const hx = @as(u32, @intCast(fx >> 32));
89 const lx = @as(u32, @truncate(fx));
87 const fx: u64 = @bitCast(x);
88 const hx: u32 = @intCast(fx >> 32);
89 const lx: u32 = @truncate(fx);
9090
9191 // cexp(0 + iy) = cos(y) + isin(y)
9292 if ((hx & 0x7fffffff) | lx == 0) {
lib/std/math/complex/sinh.zig+6-6
......@@ -89,14 +89,14 @@ fn sinh64(z: Complex(f64)) Complex(f64) {
8989 const x = z.re;
9090 const y = z.im;
9191
92 const fx = @as(u64, @bitCast(x));
93 const hx = @as(u32, @intCast(fx >> 32));
94 const lx = @as(u32, @truncate(fx));
92 const fx: u64 = @bitCast(x);
93 const hx: u32 = @intCast(fx >> 32);
94 const lx: u32 = @truncate(fx);
9595 const ix = hx & 0x7fffffff;
9696
97 const fy = @as(u64, @bitCast(y));
98 const hy = @as(u32, @intCast(fy >> 32));
99 const ly = @as(u32, @truncate(fy));
97 const fy: u64 = @bitCast(y);
98 const hy: u32 = @intCast(fy >> 32);
99 const ly: u32 = @truncate(fy);
100100 const iy = hy & 0x7fffffff;
101101
102102 if (ix < 0x7ff00000 and iy < 0x7ff00000) {
lib/std/math/complex/tanh.zig+4-4
......@@ -62,11 +62,11 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
6262 const x = z.re;
6363 const y = z.im;
6464
65 const fx = @as(u64, @bitCast(x));
65 const fx: u64 = @bitCast(x);
6666 // TODO: zig should allow this conversion implicitly because it can notice that the value necessarily
6767 // fits in range.
68 const hx = @as(u32, @intCast(fx >> 32));
69 const lx = @as(u32, @truncate(fx));
68 const hx: u32 = @intCast(fx >> 32);
69 const lx: u32 = @truncate(fx);
7070 const ix = hx & 0x7fffffff;
7171
7272 if (ix >= 0x7ff00000) {
......@@ -75,7 +75,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
7575 return Complex(f64).init(x, r);
7676 }
7777
78 const xx = @as(f64, @bitCast((@as(u64, hx - 0x40000000) << 32) | lx));
78 const xx: f64 = @bitCast((@as(u64, hx - 0x40000000) << 32) | lx);
7979 const r = if (math.isInf(y)) y else @sin(y) * @cos(y);
8080 return Complex(f64).init(xx, math.copysign(@as(f64, 0.0), r));
8181 }
lib/std/math/modf.zig+3-3
......@@ -37,7 +37,7 @@ pub fn modf(x: anytype) modf_result(@TypeOf(x)) {
3737fn modf32(x: f32) modf32_result {
3838 var result: modf32_result = undefined;
3939
40 const u = @as(u32, @bitCast(x));
40 const u: u32 = @bitCast(x);
4141 const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;
4242 const us = u & 0x80000000;
4343
......@@ -73,7 +73,7 @@ fn modf32(x: f32) modf32_result {
7373 return result;
7474 }
7575
76 const uf = @as(f32, @bitCast(u & ~mask));
76 const uf: f32 = @bitCast(u & ~mask);
7777 result.ipart = uf;
7878 result.fpart = x - uf;
7979 return result;
......@@ -82,7 +82,7 @@ fn modf32(x: f32) modf32_result {
8282fn modf64(x: f64) modf64_result {
8383 var result: modf64_result = undefined;
8484
85 const u = @as(u64, @bitCast(x));
85 const u: u64 = @bitCast(x);
8686 const e = @as(i32, @intCast((u >> 52) & 0x7FF)) - 0x3FF;
8787 const us = u & (1 << 63);
8888
lib/std/os/linux.zig+7-7
......@@ -176,21 +176,21 @@ const require_aligned_register_pair =
176176// Split a 64bit value into a {LSB,MSB} pair.
177177// The LE/BE variants specify the endianness to assume.
178178fn splitValueLE64(val: i64) [2]u32 {
179 const u = @as(u64, @bitCast(val));
179 const u: u64 = @bitCast(val);
180180 return [2]u32{
181181 @as(u32, @truncate(u)),
182182 @as(u32, @truncate(u >> 32)),
183183 };
184184}
185185fn splitValueBE64(val: i64) [2]u32 {
186 const u = @as(u64, @bitCast(val));
186 const u: u64 = @bitCast(val);
187187 return [2]u32{
188188 @as(u32, @truncate(u >> 32)),
189189 @as(u32, @truncate(u)),
190190 };
191191}
192192fn splitValue64(val: i64) [2]u32 {
193 const u = @as(u64, @bitCast(val));
193 const u: u64 = @bitCast(val);
194194 switch (native_endian) {
195195 .Little => return [2]u32{
196196 @as(u32, @truncate(u)),
......@@ -467,7 +467,7 @@ pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
467467}
468468
469469pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: i64) usize {
470 const offset_u = @as(u64, @bitCast(offset));
470 const offset_u: u64 = @bitCast(offset);
471471 return syscall5(
472472 .preadv,
473473 @as(usize, @bitCast(@as(isize, fd))),
......@@ -482,7 +482,7 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: i64) usize {
482482}
483483
484484pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: i64, flags: kernel_rwf) usize {
485 const offset_u = @as(u64, @bitCast(offset));
485 const offset_u: u64 = @bitCast(offset);
486486 return syscall6(
487487 .preadv2,
488488 @as(usize, @bitCast(@as(isize, fd))),
......@@ -504,7 +504,7 @@ pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {
504504}
505505
506506pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64) usize {
507 const offset_u = @as(u64, @bitCast(offset));
507 const offset_u: u64 = @bitCast(offset);
508508 return syscall5(
509509 .pwritev,
510510 @as(usize, @bitCast(@as(isize, fd))),
......@@ -517,7 +517,7 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64) us
517517}
518518
519519pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64, flags: kernel_rwf) usize {
520 const offset_u = @as(u64, @bitCast(offset));
520 const offset_u: u64 = @bitCast(offset);
521521 return syscall6(
522522 .pwritev2,
523523 @as(usize, @bitCast(@as(isize, fd))),
lib/std/os/linux/io_uring.zig+4-4
......@@ -1507,7 +1507,7 @@ pub fn io_uring_prep_renameat(
15071507 0,
15081508 @intFromPtr(new_path),
15091509 );
1510 sqe.len = @as(u32, @bitCast(new_dir_fd));
1510 sqe.len = @bitCast(new_dir_fd);
15111511 sqe.rw_flags = flags;
15121512}
15131513
......@@ -1562,7 +1562,7 @@ pub fn io_uring_prep_linkat(
15621562 0,
15631563 @intFromPtr(new_path),
15641564 );
1565 sqe.len = @as(u32, @bitCast(new_dir_fd));
1565 sqe.len = @bitCast(new_dir_fd);
15661566 sqe.rw_flags = flags;
15671567}
15681568
......@@ -1576,7 +1576,7 @@ pub fn io_uring_prep_provide_buffers(
15761576) void {
15771577 const ptr = @intFromPtr(buffers);
15781578 io_uring_prep_rw(.PROVIDE_BUFFERS, sqe, @as(i32, @intCast(num)), ptr, buffer_len, buffer_id);
1579 sqe.buf_index = @as(u16, @intCast(group_id));
1579 sqe.buf_index = @intCast(group_id);
15801580}
15811581
15821582pub fn io_uring_prep_remove_buffers(
......@@ -1585,7 +1585,7 @@ pub fn io_uring_prep_remove_buffers(
15851585 group_id: usize,
15861586) void {
15871587 io_uring_prep_rw(.REMOVE_BUFFERS, sqe, @as(i32, @intCast(num)), 0, 0, 0);
1588 sqe.buf_index = @as(u16, @intCast(group_id));
1588 sqe.buf_index = @intCast(group_id);
15891589}
15901590
15911591test "structs/offsets/entries" {
lib/std/os/windows.zig+1-1
......@@ -1918,7 +1918,7 @@ pub fn fileTimeToNanoSeconds(ft: FILETIME) i128 {
19181918
19191919/// Converts a number of nanoseconds since the POSIX epoch to a Windows FILETIME.
19201920pub fn nanoSecondsToFileTime(ns: i128) FILETIME {
1921 const adjusted = @as(u64, @bitCast(toSysTime(ns)));
1921 const adjusted: u64 = @bitCast(toSysTime(ns));
19221922 return FILETIME{
19231923 .dwHighDateTime = @as(u32, @truncate(adjusted >> 32)),
19241924 .dwLowDateTime = @as(u32, @truncate(adjusted)),
lib/std/os/windows/user32.zig+1-1
......@@ -1275,7 +1275,7 @@ pub const WS_EX_LAYERED = 0x00080000;
12751275pub const WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE;
12761276pub const WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
12771277
1278pub const CW_USEDEFAULT = @as(i32, @bitCast(@as(u32, 0x80000000)));
1278pub const CW_USEDEFAULT: i32 = @bitCast(@as(u32, 0x80000000));
12791279
12801280pub extern "user32" fn CreateWindowExA(dwExStyle: DWORD, lpClassName: [*:0]const u8, lpWindowName: [*:0]const u8, dwStyle: DWORD, X: i32, Y: i32, nWidth: i32, nHeight: i32, hWindParent: ?HWND, hMenu: ?HMENU, hInstance: HINSTANCE, lpParam: ?LPVOID) callconv(WINAPI) ?HWND;
12811281pub fn createWindowExA(dwExStyle: u32, lpClassName: [*:0]const u8, lpWindowName: [*:0]const u8, dwStyle: u32, X: i32, Y: i32, nWidth: i32, nHeight: i32, hWindParent: ?HWND, hMenu: ?HMENU, hInstance: HINSTANCE, lpParam: ?*anyopaque) !HWND {
lib/std/rand/Pcg.zig+2-2
......@@ -29,8 +29,8 @@ fn next(self: *Pcg) u32 {
2929 const l = self.s;
3030 self.s = l *% default_multiplier +% (self.i | 1);
3131
32 const xor_s = @as(u32, @truncate(((l >> 18) ^ l) >> 27));
33 const rot = @as(u32, @intCast(l >> 59));
32 const xor_s: u32 = @truncate(((l >> 18) ^ l) >> 27);
33 const rot: u32 = @intCast(l >> 59);
3434
3535 return (xor_s >> @as(u5, @intCast(rot))) | (xor_s << @as(u5, @intCast((0 -% rot) & 31)));
3636}
lib/std/zig/c_builtins.zig+2-2
......@@ -206,8 +206,8 @@ pub inline fn __builtin_expect(expr: c_long, c: c_long) c_long {
206206/// If tagp is empty, the function returns a NaN whose significand is zero.
207207pub inline fn __builtin_nanf(tagp: []const u8) f32 {
208208 const parsed = std.fmt.parseUnsigned(c_ulong, tagp, 0) catch 0;
209 const bits = @as(u23, @truncate(parsed)); // single-precision float trailing significand is 23 bits
210 return @as(f32, @bitCast(@as(u32, bits) | std.math.qnan_u32));
209 const bits: u23 = @truncate(parsed); // single-precision float trailing significand is 23 bits
210 return @bitCast(@as(u32, bits) | std.math.qnan_u32);
211211}
212212
213213pub inline fn __builtin_huge_valf() f32 {
lib/std/zig/system/arm.zig+1-1
......@@ -183,7 +183,7 @@ pub const aarch64 = struct {
183183 blk: {
184184 if (info.implementer == 0x41) {
185185 // ARM Ltd.
186 const special_bits = @as(u4, @truncate(info.part >> 8));
186 const special_bits: u4 = @truncate(info.part >> 8);
187187 if (special_bits == 0x0 or special_bits == 0x7) {
188188 // TODO Variant and arch encoded differently.
189189 break :blk;