authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-06-22 18:46:56+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-24 16:56:39-07:00
logf26dda21171e26f44aeec8c59a75bbb3331eeb2e
treec935248861ae2693b314f2c8bc78fe38d9961b6d
parent447ca4e3fff021f471b748187b53f0a4744ad0bc

all: migrate code to new cast builtin syntax

Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change

651 files changed, 9007 insertions(+), 9079 deletions(-)

lib/compiler_rt/addf3.zig+22-22
...@@ -24,28 +24,28 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {...@@ -24,28 +24,28 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
24 const significandMask = (@as(Z, 1) << significandBits) - 1;24 const significandMask = (@as(Z, 1) << significandBits) - 1;
2525
26 const absMask = signBit - 1;26 const absMask = signBit - 1;
27 const qnanRep = @bitCast(Z, math.nan(T)) | quietBit;27 const qnanRep = @as(Z, @bitCast(math.nan(T))) | quietBit;
2828
29 var aRep = @bitCast(Z, a);29 var aRep = @as(Z, @bitCast(a));
30 var bRep = @bitCast(Z, b);30 var bRep = @as(Z, @bitCast(b));
31 const aAbs = aRep & absMask;31 const aAbs = aRep & absMask;
32 const bAbs = bRep & absMask;32 const bAbs = bRep & absMask;
3333
34 const infRep = @bitCast(Z, math.inf(T));34 const infRep = @as(Z, @bitCast(math.inf(T)));
3535
36 // Detect if a or b is zero, infinity, or NaN.36 // Detect if a or b is zero, infinity, or NaN.
37 if (aAbs -% @as(Z, 1) >= infRep - @as(Z, 1) or37 if (aAbs -% @as(Z, 1) >= infRep - @as(Z, 1) or
38 bAbs -% @as(Z, 1) >= infRep - @as(Z, 1))38 bAbs -% @as(Z, 1) >= infRep - @as(Z, 1))
39 {39 {
40 // NaN + anything = qNaN40 // NaN + anything = qNaN
41 if (aAbs > infRep) return @bitCast(T, @bitCast(Z, a) | quietBit);41 if (aAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(a)) | quietBit));
42 // anything + NaN = qNaN42 // anything + NaN = qNaN
43 if (bAbs > infRep) return @bitCast(T, @bitCast(Z, b) | quietBit);43 if (bAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(b)) | quietBit));
4444
45 if (aAbs == infRep) {45 if (aAbs == infRep) {
46 // +/-infinity + -/+infinity = qNaN46 // +/-infinity + -/+infinity = qNaN
47 if ((@bitCast(Z, a) ^ @bitCast(Z, b)) == signBit) {47 if ((@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) == signBit) {
48 return @bitCast(T, qnanRep);48 return @as(T, @bitCast(qnanRep));
49 }49 }
50 // +/-infinity + anything remaining = +/- infinity50 // +/-infinity + anything remaining = +/- infinity
51 else {51 else {
...@@ -60,7 +60,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {...@@ -60,7 +60,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
60 if (aAbs == 0) {60 if (aAbs == 0) {
61 // but we need to get the sign right for zero + zero61 // but we need to get the sign right for zero + zero
62 if (bAbs == 0) {62 if (bAbs == 0) {
63 return @bitCast(T, @bitCast(Z, a) & @bitCast(Z, b));63 return @as(T, @bitCast(@as(Z, @bitCast(a)) & @as(Z, @bitCast(b))));
64 } else {64 } else {
65 return b;65 return b;
66 }66 }
...@@ -78,8 +78,8 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {...@@ -78,8 +78,8 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
78 }78 }
7979
80 // Extract the exponent and significand from the (possibly swapped) a and b.80 // Extract the exponent and significand from the (possibly swapped) a and b.
81 var aExponent = @intCast(i32, (aRep >> significandBits) & maxExponent);81 var aExponent = @as(i32, @intCast((aRep >> significandBits) & maxExponent));
82 var bExponent = @intCast(i32, (bRep >> significandBits) & maxExponent);82 var bExponent = @as(i32, @intCast((bRep >> significandBits) & maxExponent));
83 var aSignificand = aRep & significandMask;83 var aSignificand = aRep & significandMask;
84 var bSignificand = bRep & significandMask;84 var bSignificand = bRep & significandMask;
8585
...@@ -101,11 +101,11 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {...@@ -101,11 +101,11 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
101101
102 // Shift the significand of b by the difference in exponents, with a sticky102 // Shift the significand of b by the difference in exponents, with a sticky
103 // bottom bit to get rounding correct.103 // bottom bit to get rounding correct.
104 const @"align" = @intCast(u32, aExponent - bExponent);104 const @"align" = @as(u32, @intCast(aExponent - bExponent));
105 if (@"align" != 0) {105 if (@"align" != 0) {
106 if (@"align" < typeWidth) {106 if (@"align" < typeWidth) {
107 const sticky = if (bSignificand << @intCast(S, typeWidth - @"align") != 0) @as(Z, 1) else 0;107 const sticky = if (bSignificand << @as(S, @intCast(typeWidth - @"align")) != 0) @as(Z, 1) else 0;
108 bSignificand = (bSignificand >> @truncate(S, @"align")) | sticky;108 bSignificand = (bSignificand >> @as(S, @truncate(@"align"))) | sticky;
109 } else {109 } else {
110 bSignificand = 1; // sticky; b is known to be non-zero.110 bSignificand = 1; // sticky; b is known to be non-zero.
111 }111 }
...@@ -113,13 +113,13 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {...@@ -113,13 +113,13 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
113 if (subtraction) {113 if (subtraction) {
114 aSignificand -= bSignificand;114 aSignificand -= bSignificand;
115 // If a == -b, return +zero.115 // If a == -b, return +zero.
116 if (aSignificand == 0) return @bitCast(T, @as(Z, 0));116 if (aSignificand == 0) return @as(T, @bitCast(@as(Z, 0)));
117117
118 // If partial cancellation occured, we need to left-shift the result118 // If partial cancellation occured, we need to left-shift the result
119 // and adjust the exponent:119 // and adjust the exponent:
120 if (aSignificand < integerBit << 3) {120 if (aSignificand < integerBit << 3) {
121 const shift = @intCast(i32, @clz(aSignificand)) - @intCast(i32, @clz(integerBit << 3));121 const shift = @as(i32, @intCast(@clz(aSignificand))) - @as(i32, @intCast(@clz(integerBit << 3)));
122 aSignificand <<= @intCast(S, shift);122 aSignificand <<= @as(S, @intCast(shift));
123 aExponent -= shift;123 aExponent -= shift;
124 }124 }
125 } else { // addition125 } else { // addition
...@@ -135,13 +135,13 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {...@@ -135,13 +135,13 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
135 }135 }
136136
137 // If we have overflowed the type, return +/- infinity:137 // If we have overflowed the type, return +/- infinity:
138 if (aExponent >= maxExponent) return @bitCast(T, infRep | resultSign);138 if (aExponent >= maxExponent) return @as(T, @bitCast(infRep | resultSign));
139139
140 if (aExponent <= 0) {140 if (aExponent <= 0) {
141 // Result is denormal; the exponent and round/sticky bits are zero.141 // Result is denormal; the exponent and round/sticky bits are zero.
142 // All we need to do is shift the significand and apply the correct sign.142 // All we need to do is shift the significand and apply the correct sign.
143 aSignificand >>= @intCast(S, 4 - aExponent);143 aSignificand >>= @as(S, @intCast(4 - aExponent));
144 return @bitCast(T, resultSign | aSignificand);144 return @as(T, @bitCast(resultSign | aSignificand));
145 }145 }
146146
147 // Low three bits are round, guard, and sticky.147 // Low three bits are round, guard, and sticky.
...@@ -151,7 +151,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {...@@ -151,7 +151,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
151 var result = (aSignificand >> 3) & significandMask;151 var result = (aSignificand >> 3) & significandMask;
152152
153 // Insert the exponent and sign.153 // Insert the exponent and sign.
154 result |= @intCast(Z, aExponent) << significandBits;154 result |= @as(Z, @intCast(aExponent)) << significandBits;
155 result |= resultSign;155 result |= resultSign;
156156
157 // Final rounding. The result may overflow to infinity, but that is the157 // Final rounding. The result may overflow to infinity, but that is the
...@@ -164,7 +164,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {...@@ -164,7 +164,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
164 if ((result >> significandBits) != 0) result |= integerBit;164 if ((result >> significandBits) != 0) result |= integerBit;
165 }165 }
166166
167 return @bitCast(T, result);167 return @as(T, @bitCast(result));
168}168}
169169
170test {170test {
lib/compiler_rt/addf3_test.zig+23-23
...@@ -5,7 +5,7 @@...@@ -5,7 +5,7 @@
55
6const std = @import("std");6const std = @import("std");
7const math = std.math;7const math = std.math;
8const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64);8const qnan128 = @as(f128, @bitCast(@as(u128, 0x7fff800000000000) << 64));
99
10const __addtf3 = @import("addtf3.zig").__addtf3;10const __addtf3 = @import("addtf3.zig").__addtf3;
11const __addxf3 = @import("addxf3.zig").__addxf3;11const __addxf3 = @import("addxf3.zig").__addxf3;
...@@ -14,9 +14,9 @@ const __subtf3 = @import("subtf3.zig").__subtf3;...@@ -14,9 +14,9 @@ const __subtf3 = @import("subtf3.zig").__subtf3;
14fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {14fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
15 const x = __addtf3(a, b);15 const x = __addtf3(a, b);
1616
17 const rep = @bitCast(u128, x);17 const rep = @as(u128, @bitCast(x));
18 const hi = @intCast(u64, rep >> 64);18 const hi = @as(u64, @intCast(rep >> 64));
19 const lo = @truncate(u64, rep);19 const lo = @as(u64, @truncate(rep));
2020
21 if (hi == expected_hi and lo == expected_lo) {21 if (hi == expected_hi and lo == expected_lo) {
22 return;22 return;
...@@ -37,7 +37,7 @@ test "addtf3" {...@@ -37,7 +37,7 @@ test "addtf3" {
37 try test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);37 try test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
3838
39 // NaN + any = NaN39 // NaN + any = NaN
40 try test__addtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);40 try test__addtf3(@as(f128, @bitCast((@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000))), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
4141
42 // inf + inf = inf42 // inf + inf = inf
43 try test__addtf3(math.inf(f128), math.inf(f128), 0x7fff000000000000, 0x0);43 try test__addtf3(math.inf(f128), math.inf(f128), 0x7fff000000000000, 0x0);
...@@ -53,9 +53,9 @@ test "addtf3" {...@@ -53,9 +53,9 @@ test "addtf3" {
53fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {53fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
54 const x = __subtf3(a, b);54 const x = __subtf3(a, b);
5555
56 const rep = @bitCast(u128, x);56 const rep = @as(u128, @bitCast(x));
57 const hi = @intCast(u64, rep >> 64);57 const hi = @as(u64, @intCast(rep >> 64));
58 const lo = @truncate(u64, rep);58 const lo = @as(u64, @truncate(rep));
5959
60 if (hi == expected_hi and lo == expected_lo) {60 if (hi == expected_hi and lo == expected_lo) {
61 return;61 return;
...@@ -77,7 +77,7 @@ test "subtf3" {...@@ -77,7 +77,7 @@ test "subtf3" {
77 try test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);77 try test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
7878
79 // NaN + any = NaN79 // NaN + any = NaN
80 try test__subtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);80 try test__subtf3(@as(f128, @bitCast((@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000))), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
8181
82 // inf - any = inf82 // inf - any = inf
83 try test__subtf3(math.inf(f128), 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);83 try test__subtf3(math.inf(f128), 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);
...@@ -87,16 +87,16 @@ test "subtf3" {...@@ -87,16 +87,16 @@ test "subtf3" {
87 try test__subtf3(0x1.ee9d7c52354a6936ab8d7654321fp-1, 0x1.234567829a3bcdef5678ade36734p+5, 0xc0041b8af1915166, 0xa44a7bca780a166c);87 try test__subtf3(0x1.ee9d7c52354a6936ab8d7654321fp-1, 0x1.234567829a3bcdef5678ade36734p+5, 0xc0041b8af1915166, 0xa44a7bca780a166c);
88}88}
8989
90const qnan80 = @bitCast(f80, @bitCast(u80, math.nan(f80)) | (1 << (math.floatFractionalBits(f80) - 1)));90const qnan80 = @as(f80, @bitCast(@as(u80, @bitCast(math.nan(f80))) | (1 << (math.floatFractionalBits(f80) - 1))));
9191
92fn test__addxf3(a: f80, b: f80, expected: u80) !void {92fn test__addxf3(a: f80, b: f80, expected: u80) !void {
93 const x = __addxf3(a, b);93 const x = __addxf3(a, b);
94 const rep = @bitCast(u80, x);94 const rep = @as(u80, @bitCast(x));
9595
96 if (rep == expected)96 if (rep == expected)
97 return;97 return;
9898
99 if (math.isNan(@bitCast(f80, expected)) and math.isNan(x))99 if (math.isNan(@as(f80, @bitCast(expected))) and math.isNan(x))
100 return; // We don't currently test NaN payload propagation100 return; // We don't currently test NaN payload propagation
101101
102 return error.TestFailed;102 return error.TestFailed;
...@@ -104,33 +104,33 @@ fn test__addxf3(a: f80, b: f80, expected: u80) !void {...@@ -104,33 +104,33 @@ fn test__addxf3(a: f80, b: f80, expected: u80) !void {
104104
105test "addxf3" {105test "addxf3" {
106 // NaN + any = NaN106 // NaN + any = NaN
107 try test__addxf3(qnan80, 0x1.23456789abcdefp+5, @bitCast(u80, qnan80));107 try test__addxf3(qnan80, 0x1.23456789abcdefp+5, @as(u80, @bitCast(qnan80)));
108 try test__addxf3(@bitCast(f80, @as(u80, 0x7fff_8000_8000_3000_0000)), 0x1.23456789abcdefp+5, @bitCast(u80, qnan80));108 try test__addxf3(@as(f80, @bitCast(@as(u80, 0x7fff_8000_8000_3000_0000))), 0x1.23456789abcdefp+5, @as(u80, @bitCast(qnan80)));
109109
110 // any + NaN = NaN110 // any + NaN = NaN
111 try test__addxf3(0x1.23456789abcdefp+5, qnan80, @bitCast(u80, qnan80));111 try test__addxf3(0x1.23456789abcdefp+5, qnan80, @as(u80, @bitCast(qnan80)));
112 try test__addxf3(0x1.23456789abcdefp+5, @bitCast(f80, @as(u80, 0x7fff_8000_8000_3000_0000)), @bitCast(u80, qnan80));112 try test__addxf3(0x1.23456789abcdefp+5, @as(f80, @bitCast(@as(u80, 0x7fff_8000_8000_3000_0000))), @as(u80, @bitCast(qnan80)));
113113
114 // NaN + inf = NaN114 // NaN + inf = NaN
115 try test__addxf3(qnan80, math.inf(f80), @bitCast(u80, qnan80));115 try test__addxf3(qnan80, math.inf(f80), @as(u80, @bitCast(qnan80)));
116116
117 // inf + NaN = NaN117 // inf + NaN = NaN
118 try test__addxf3(math.inf(f80), qnan80, @bitCast(u80, qnan80));118 try test__addxf3(math.inf(f80), qnan80, @as(u80, @bitCast(qnan80)));
119119
120 // inf + inf = inf120 // inf + inf = inf
121 try test__addxf3(math.inf(f80), math.inf(f80), @bitCast(u80, math.inf(f80)));121 try test__addxf3(math.inf(f80), math.inf(f80), @as(u80, @bitCast(math.inf(f80))));
122122
123 // inf + -inf = NaN123 // inf + -inf = NaN
124 try test__addxf3(math.inf(f80), -math.inf(f80), @bitCast(u80, qnan80));124 try test__addxf3(math.inf(f80), -math.inf(f80), @as(u80, @bitCast(qnan80)));
125125
126 // -inf + inf = NaN126 // -inf + inf = NaN
127 try test__addxf3(-math.inf(f80), math.inf(f80), @bitCast(u80, qnan80));127 try test__addxf3(-math.inf(f80), math.inf(f80), @as(u80, @bitCast(qnan80)));
128128
129 // inf + any = inf129 // inf + any = inf
130 try test__addxf3(math.inf(f80), 0x1.2335653452436234723489432abcdefp+5, @bitCast(u80, math.inf(f80)));130 try test__addxf3(math.inf(f80), 0x1.2335653452436234723489432abcdefp+5, @as(u80, @bitCast(math.inf(f80))));
131131
132 // any + inf = inf132 // any + inf = inf
133 try test__addxf3(0x1.2335653452436234723489432abcdefp+5, math.inf(f80), @bitCast(u80, math.inf(f80)));133 try test__addxf3(0x1.2335653452436234723489432abcdefp+5, math.inf(f80), @as(u80, @bitCast(math.inf(f80))));
134134
135 // any + any135 // any + any
136 try test__addxf3(0x1.23456789abcdp+5, 0x1.dcba987654321p+5, 0x4005_BFFFFFFFFFFFC400);136 try test__addxf3(0x1.23456789abcdp+5, 0x1.dcba987654321p+5, 0x4005_BFFFFFFFFFFFC400);
lib/compiler_rt/arm.zig+1-1
...@@ -192,6 +192,6 @@ pub fn __aeabi_ldivmod() callconv(.Naked) void {...@@ -192,6 +192,6 @@ pub fn __aeabi_ldivmod() callconv(.Naked) void {
192}192}
193193
194pub fn __aeabi_drsub(a: f64, b: f64) callconv(.AAPCS) f64 {194pub fn __aeabi_drsub(a: f64, b: f64) callconv(.AAPCS) f64 {
195 const neg_a = @bitCast(f64, @bitCast(u64, a) ^ (@as(u64, 1) << 63));195 const neg_a = @as(f64, @bitCast(@as(u64, @bitCast(a)) ^ (@as(u64, 1) << 63)));
196 return b + neg_a;196 return b + neg_a;
197}197}
lib/compiler_rt/atomics.zig+3-3
...@@ -232,16 +232,16 @@ fn wideUpdate(comptime T: type, ptr: *T, val: T, update: anytype) T {...@@ -232,16 +232,16 @@ fn wideUpdate(comptime T: type, ptr: *T, val: T, update: anytype) T {
232232
233 const addr = @intFromPtr(ptr);233 const addr = @intFromPtr(ptr);
234 const wide_addr = addr & ~(@as(T, smallest_atomic_fetch_exch_size) - 1);234 const wide_addr = addr & ~(@as(T, smallest_atomic_fetch_exch_size) - 1);
235 const wide_ptr = @alignCast(smallest_atomic_fetch_exch_size, @ptrFromInt(*WideAtomic, wide_addr));235 const wide_ptr: *align(smallest_atomic_fetch_exch_size) WideAtomic = @alignCast(@as(*WideAtomic, @ptrFromInt(wide_addr)));
236236
237 const inner_offset = addr & (@as(T, smallest_atomic_fetch_exch_size) - 1);237 const inner_offset = addr & (@as(T, smallest_atomic_fetch_exch_size) - 1);
238 const inner_shift = @intCast(std.math.Log2Int(T), inner_offset * 8);238 const inner_shift = @as(std.math.Log2Int(T), @intCast(inner_offset * 8));
239239
240 const mask = @as(WideAtomic, std.math.maxInt(T)) << inner_shift;240 const mask = @as(WideAtomic, std.math.maxInt(T)) << inner_shift;
241241
242 var wide_old = @atomicLoad(WideAtomic, wide_ptr, .SeqCst);242 var wide_old = @atomicLoad(WideAtomic, wide_ptr, .SeqCst);
243 while (true) {243 while (true) {
244 const old = @truncate(T, (wide_old & mask) >> inner_shift);244 const old = @as(T, @truncate((wide_old & mask) >> inner_shift));
245 const new = update(val, old);245 const new = update(val, old);
246 const wide_new = wide_old & ~mask | (@as(WideAtomic, new) << inner_shift);246 const wide_new = wide_old & ~mask | (@as(WideAtomic, new) << inner_shift);
247 if (@cmpxchgWeak(WideAtomic, wide_ptr, wide_old, wide_new, .SeqCst, .SeqCst)) |new_wide_old| {247 if (@cmpxchgWeak(WideAtomic, wide_ptr, wide_old, wide_new, .SeqCst, .SeqCst)) |new_wide_old| {
lib/compiler_rt/aulldiv.zig+2-2
...@@ -21,9 +21,9 @@ pub fn _alldiv(a: i64, b: i64) callconv(.Stdcall) i64 {...@@ -21,9 +21,9 @@ pub fn _alldiv(a: i64, b: i64) callconv(.Stdcall) i64 {
21 const an = (a ^ s_a) -% s_a;21 const an = (a ^ s_a) -% s_a;
22 const bn = (b ^ s_b) -% s_b;22 const bn = (b ^ s_b) -% s_b;
2323
24 const r = @bitCast(u64, an) / @bitCast(u64, bn);24 const r = @as(u64, @bitCast(an)) / @as(u64, @bitCast(bn));
25 const s = s_a ^ s_b;25 const s = s_a ^ s_b;
26 return (@bitCast(i64, r) ^ s) -% s;26 return (@as(i64, @bitCast(r)) ^ s) -% s;
27}27}
2828
29pub fn _aulldiv() callconv(.Naked) void {29pub fn _aulldiv() callconv(.Naked) void {
lib/compiler_rt/aullrem.zig+2-2
...@@ -21,9 +21,9 @@ pub fn _allrem(a: i64, b: i64) callconv(.Stdcall) i64 {...@@ -21,9 +21,9 @@ pub fn _allrem(a: i64, b: i64) callconv(.Stdcall) i64 {
21 const an = (a ^ s_a) -% s_a;21 const an = (a ^ s_a) -% s_a;
22 const bn = (b ^ s_b) -% s_b;22 const bn = (b ^ s_b) -% s_b;
2323
24 const r = @bitCast(u64, an) % @bitCast(u64, bn);24 const r = @as(u64, @bitCast(an)) % @as(u64, @bitCast(bn));
25 const s = s_a ^ s_b;25 const s = s_a ^ s_b;
26 return (@bitCast(i64, r) ^ s) -% s;26 return (@as(i64, @bitCast(r)) ^ s) -% s;
27}27}
2828
29pub fn _aullrem() callconv(.Naked) void {29pub fn _aullrem() callconv(.Naked) void {
lib/compiler_rt/ceil.zig+8-8
...@@ -27,12 +27,12 @@ comptime {...@@ -27,12 +27,12 @@ comptime {
2727
28pub fn __ceilh(x: f16) callconv(.C) f16 {28pub fn __ceilh(x: f16) callconv(.C) f16 {
29 // TODO: more efficient implementation29 // TODO: more efficient implementation
30 return @floatCast(f16, ceilf(x));30 return @as(f16, @floatCast(ceilf(x)));
31}31}
3232
33pub fn ceilf(x: f32) callconv(.C) f32 {33pub fn ceilf(x: f32) callconv(.C) f32 {
34 var u = @bitCast(u32, x);34 var u = @as(u32, @bitCast(x));
35 var e = @intCast(i32, (u >> 23) & 0xFF) - 0x7F;35 var e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;
36 var m: u32 = undefined;36 var m: u32 = undefined;
3737
38 // TODO: Shouldn't need this explicit check.38 // TODO: Shouldn't need this explicit check.
...@@ -43,7 +43,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 {...@@ -43,7 +43,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 {
43 if (e >= 23) {43 if (e >= 23) {
44 return x;44 return x;
45 } else if (e >= 0) {45 } else if (e >= 0) {
46 m = @as(u32, 0x007FFFFF) >> @intCast(u5, e);46 m = @as(u32, 0x007FFFFF) >> @as(u5, @intCast(e));
47 if (u & m == 0) {47 if (u & m == 0) {
48 return x;48 return x;
49 }49 }
...@@ -52,7 +52,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 {...@@ -52,7 +52,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 {
52 u += m;52 u += m;
53 }53 }
54 u &= ~m;54 u &= ~m;
55 return @bitCast(f32, u);55 return @as(f32, @bitCast(u));
56 } else {56 } else {
57 math.doNotOptimizeAway(x + 0x1.0p120);57 math.doNotOptimizeAway(x + 0x1.0p120);
58 if (u >> 31 != 0) {58 if (u >> 31 != 0) {
...@@ -66,7 +66,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 {...@@ -66,7 +66,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 {
66pub fn ceil(x: f64) callconv(.C) f64 {66pub fn ceil(x: f64) callconv(.C) f64 {
67 const f64_toint = 1.0 / math.floatEps(f64);67 const f64_toint = 1.0 / math.floatEps(f64);
6868
69 const u = @bitCast(u64, x);69 const u = @as(u64, @bitCast(x));
70 const e = (u >> 52) & 0x7FF;70 const e = (u >> 52) & 0x7FF;
71 var y: f64 = undefined;71 var y: f64 = undefined;
7272
...@@ -96,13 +96,13 @@ pub fn ceil(x: f64) callconv(.C) f64 {...@@ -96,13 +96,13 @@ pub fn ceil(x: f64) callconv(.C) f64 {
9696
97pub fn __ceilx(x: f80) callconv(.C) f80 {97pub fn __ceilx(x: f80) callconv(.C) f80 {
98 // TODO: more efficient implementation98 // TODO: more efficient implementation
99 return @floatCast(f80, ceilq(x));99 return @as(f80, @floatCast(ceilq(x)));
100}100}
101101
102pub fn ceilq(x: f128) callconv(.C) f128 {102pub fn ceilq(x: f128) callconv(.C) f128 {
103 const f128_toint = 1.0 / math.floatEps(f128);103 const f128_toint = 1.0 / math.floatEps(f128);
104104
105 const u = @bitCast(u128, x);105 const u = @as(u128, @bitCast(x));
106 const e = (u >> 112) & 0x7FFF;106 const e = (u >> 112) & 0x7FFF;
107 var y: f128 = undefined;107 var y: f128 = undefined;
108108
lib/compiler_rt/clear_cache.zig+2-2
...@@ -102,7 +102,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void {...@@ -102,7 +102,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void {
102 // If CTR_EL0.IDC is set, data cache cleaning to the point of unification102 // If CTR_EL0.IDC is set, data cache cleaning to the point of unification
103 // is not required for instruction to data coherence.103 // is not required for instruction to data coherence.
104 if (((ctr_el0 >> 28) & 0x1) == 0x0) {104 if (((ctr_el0 >> 28) & 0x1) == 0x0) {
105 const dcache_line_size: usize = @as(usize, 4) << @intCast(u6, (ctr_el0 >> 16) & 15);105 const dcache_line_size: usize = @as(usize, 4) << @as(u6, @intCast((ctr_el0 >> 16) & 15));
106 addr = start & ~(dcache_line_size - 1);106 addr = start & ~(dcache_line_size - 1);
107 while (addr < end) : (addr += dcache_line_size) {107 while (addr < end) : (addr += dcache_line_size) {
108 asm volatile ("dc cvau, %[addr]"108 asm volatile ("dc cvau, %[addr]"
...@@ -115,7 +115,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void {...@@ -115,7 +115,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void {
115 // If CTR_EL0.DIC is set, instruction cache invalidation to the point of115 // If CTR_EL0.DIC is set, instruction cache invalidation to the point of
116 // unification is not required for instruction to data coherence.116 // unification is not required for instruction to data coherence.
117 if (((ctr_el0 >> 29) & 0x1) == 0x0) {117 if (((ctr_el0 >> 29) & 0x1) == 0x0) {
118 const icache_line_size: usize = @as(usize, 4) << @intCast(u6, (ctr_el0 >> 0) & 15);118 const icache_line_size: usize = @as(usize, 4) << @as(u6, @intCast((ctr_el0 >> 0) & 15));
119 addr = start & ~(icache_line_size - 1);119 addr = start & ~(icache_line_size - 1);
120 while (addr < end) : (addr += icache_line_size) {120 while (addr < end) : (addr += icache_line_size) {
121 asm volatile ("ic ivau, %[addr]"121 asm volatile ("ic ivau, %[addr]"
lib/compiler_rt/clzdi2_test.zig+1-1
...@@ -2,7 +2,7 @@ const clz = @import("count0bits.zig");...@@ -2,7 +2,7 @@ const clz = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__clzdi2(a: u64, expected: i64) !void {4fn test__clzdi2(a: u64, expected: i64) !void {
5 var x = @bitCast(i64, a);5 var x = @as(i64, @bitCast(a));
6 var result = clz.__clzdi2(x);6 var result = clz.__clzdi2(x);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
lib/compiler_rt/clzsi2_test.zig+2-2
...@@ -4,8 +4,8 @@ const testing = @import("std").testing;...@@ -4,8 +4,8 @@ const testing = @import("std").testing;
44
5fn test__clzsi2(a: u32, expected: i32) !void {5fn test__clzsi2(a: u32, expected: i32) !void {
6 const nakedClzsi2 = clz.__clzsi2;6 const nakedClzsi2 = clz.__clzsi2;
7 const actualClzsi2 = @ptrCast(*const fn (a: i32) callconv(.C) i32, &nakedClzsi2);7 const actualClzsi2 = @as(*const fn (a: i32) callconv(.C) i32, @ptrCast(&nakedClzsi2));
8 const x = @bitCast(i32, a);8 const x = @as(i32, @bitCast(a));
9 const result = actualClzsi2(x);9 const result = actualClzsi2(x);
10 try testing.expectEqual(expected, result);10 try testing.expectEqual(expected, result);
11}11}
lib/compiler_rt/clzti2_test.zig+1-1
...@@ -2,7 +2,7 @@ const clz = @import("count0bits.zig");...@@ -2,7 +2,7 @@ const clz = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__clzti2(a: u128, expected: i64) !void {4fn test__clzti2(a: u128, expected: i64) !void {
5 var x = @bitCast(i128, a);5 var x = @as(i128, @bitCast(a));
6 var result = clz.__clzti2(x);6 var result = clz.__clzti2(x);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
lib/compiler_rt/cmptf2.zig+6-6
...@@ -75,30 +75,30 @@ fn _Qp_cmp(a: *const f128, b: *const f128) callconv(.C) i32 {...@@ -75,30 +75,30 @@ fn _Qp_cmp(a: *const f128, b: *const f128) callconv(.C) i32 {
75}75}
7676
77fn _Qp_feq(a: *const f128, b: *const f128) callconv(.C) bool {77fn _Qp_feq(a: *const f128, b: *const f128) callconv(.C) bool {
78 return @enumFromInt(SparcFCMP, _Qp_cmp(a, b)) == .Equal;78 return @as(SparcFCMP, @enumFromInt(_Qp_cmp(a, b))) == .Equal;
79}79}
8080
81fn _Qp_fne(a: *const f128, b: *const f128) callconv(.C) bool {81fn _Qp_fne(a: *const f128, b: *const f128) callconv(.C) bool {
82 return @enumFromInt(SparcFCMP, _Qp_cmp(a, b)) != .Equal;82 return @as(SparcFCMP, @enumFromInt(_Qp_cmp(a, b))) != .Equal;
83}83}
8484
85fn _Qp_flt(a: *const f128, b: *const f128) callconv(.C) bool {85fn _Qp_flt(a: *const f128, b: *const f128) callconv(.C) bool {
86 return @enumFromInt(SparcFCMP, _Qp_cmp(a, b)) == .Less;86 return @as(SparcFCMP, @enumFromInt(_Qp_cmp(a, b))) == .Less;
87}87}
8888
89fn _Qp_fgt(a: *const f128, b: *const f128) callconv(.C) bool {89fn _Qp_fgt(a: *const f128, b: *const f128) callconv(.C) bool {
90 return @enumFromInt(SparcFCMP, _Qp_cmp(a, b)) == .Greater;90 return @as(SparcFCMP, @enumFromInt(_Qp_cmp(a, b))) == .Greater;
91}91}
9292
93fn _Qp_fge(a: *const f128, b: *const f128) callconv(.C) bool {93fn _Qp_fge(a: *const f128, b: *const f128) callconv(.C) bool {
94 return switch (@enumFromInt(SparcFCMP, _Qp_cmp(a, b))) {94 return switch (@as(SparcFCMP, @enumFromInt(_Qp_cmp(a, b)))) {
95 .Equal, .Greater => true,95 .Equal, .Greater => true,
96 .Less, .Unordered => false,96 .Less, .Unordered => false,
97 };97 };
98}98}
9999
100fn _Qp_fle(a: *const f128, b: *const f128) callconv(.C) bool {100fn _Qp_fle(a: *const f128, b: *const f128) callconv(.C) bool {
101 return switch (@enumFromInt(SparcFCMP, _Qp_cmp(a, b))) {101 return switch (@as(SparcFCMP, @enumFromInt(_Qp_cmp(a, b)))) {
102 .Equal, .Less => true,102 .Equal, .Less => true,
103 .Greater, .Unordered => false,103 .Greater, .Unordered => false,
104 };104 };
lib/compiler_rt/common.zig+13-13
...@@ -102,22 +102,22 @@ pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {...@@ -102,22 +102,22 @@ pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
102 u16 => {102 u16 => {
103 // 16x16 --> 32 bit multiply103 // 16x16 --> 32 bit multiply
104 const product = @as(u32, a) * @as(u32, b);104 const product = @as(u32, a) * @as(u32, b);
105 hi.* = @intCast(u16, product >> 16);105 hi.* = @as(u16, @intCast(product >> 16));
106 lo.* = @truncate(u16, product);106 lo.* = @as(u16, @truncate(product));
107 },107 },
108 u32 => {108 u32 => {
109 // 32x32 --> 64 bit multiply109 // 32x32 --> 64 bit multiply
110 const product = @as(u64, a) * @as(u64, b);110 const product = @as(u64, a) * @as(u64, b);
111 hi.* = @truncate(u32, product >> 32);111 hi.* = @as(u32, @truncate(product >> 32));
112 lo.* = @truncate(u32, product);112 lo.* = @as(u32, @truncate(product));
113 },113 },
114 u64 => {114 u64 => {
115 const S = struct {115 const S = struct {
116 fn loWord(x: u64) u64 {116 fn loWord(x: u64) u64 {
117 return @truncate(u32, x);117 return @as(u32, @truncate(x));
118 }118 }
119 fn hiWord(x: u64) u64 {119 fn hiWord(x: u64) u64 {
120 return @truncate(u32, x >> 32);120 return @as(u32, @truncate(x >> 32));
121 }121 }
122 };122 };
123 // 64x64 -> 128 wide multiply for platforms that don't have such an operation;123 // 64x64 -> 128 wide multiply for platforms that don't have such an operation;
...@@ -141,16 +141,16 @@ pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {...@@ -141,16 +141,16 @@ pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
141 const Word_FullMask = @as(u64, 0xffffffffffffffff);141 const Word_FullMask = @as(u64, 0xffffffffffffffff);
142 const S = struct {142 const S = struct {
143 fn Word_1(x: u128) u64 {143 fn Word_1(x: u128) u64 {
144 return @truncate(u32, x >> 96);144 return @as(u32, @truncate(x >> 96));
145 }145 }
146 fn Word_2(x: u128) u64 {146 fn Word_2(x: u128) u64 {
147 return @truncate(u32, x >> 64);147 return @as(u32, @truncate(x >> 64));
148 }148 }
149 fn Word_3(x: u128) u64 {149 fn Word_3(x: u128) u64 {
150 return @truncate(u32, x >> 32);150 return @as(u32, @truncate(x >> 32));
151 }151 }
152 fn Word_4(x: u128) u64 {152 fn Word_4(x: u128) u64 {
153 return @truncate(u32, x);153 return @as(u32, @truncate(x));
154 }154 }
155 };155 };
156 // 128x128 -> 256 wide multiply for platforms that don't have such an operation;156 // 128x128 -> 256 wide multiply for platforms that don't have such an operation;
...@@ -216,7 +216,7 @@ pub fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeIn...@@ -216,7 +216,7 @@ pub fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeIn
216 const integerBit = @as(Z, 1) << std.math.floatFractionalBits(T);216 const integerBit = @as(Z, 1) << std.math.floatFractionalBits(T);
217217
218 const shift = @clz(significand.*) - @clz(integerBit);218 const shift = @clz(significand.*) - @clz(integerBit);
219 significand.* <<= @intCast(std.math.Log2Int(Z), shift);219 significand.* <<= @as(std.math.Log2Int(Z), @intCast(shift));
220 return @as(i32, 1) - shift;220 return @as(i32, 1) - shift;
221}221}
222222
...@@ -228,8 +228,8 @@ pub inline fn fneg(a: anytype) @TypeOf(a) {...@@ -228,8 +228,8 @@ pub inline fn fneg(a: anytype) @TypeOf(a) {
228 .bits = bits,228 .bits = bits,
229 } });229 } });
230 const sign_bit_mask = @as(U, 1) << (bits - 1);230 const sign_bit_mask = @as(U, 1) << (bits - 1);
231 const negated = @bitCast(U, a) ^ sign_bit_mask;231 const negated = @as(U, @bitCast(a)) ^ sign_bit_mask;
232 return @bitCast(F, negated);232 return @as(F, @bitCast(negated));
233}233}
234234
235/// Allows to access underlying bits as two equally sized lower and higher235/// Allows to access underlying bits as two equally sized lower and higher
lib/compiler_rt/comparef.zig+9-9
...@@ -26,12 +26,12 @@ pub inline fn cmpf2(comptime T: type, comptime RT: type, a: T, b: T) RT {...@@ -26,12 +26,12 @@ pub inline fn cmpf2(comptime T: type, comptime RT: type, a: T, b: T) RT {
26 const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));26 const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
27 const absMask = signBit - 1;27 const absMask = signBit - 1;
28 const infT = comptime std.math.inf(T);28 const infT = comptime std.math.inf(T);
29 const infRep = @bitCast(rep_t, infT);29 const infRep = @as(rep_t, @bitCast(infT));
3030
31 const aInt = @bitCast(srep_t, a);31 const aInt = @as(srep_t, @bitCast(a));
32 const bInt = @bitCast(srep_t, b);32 const bInt = @as(srep_t, @bitCast(b));
33 const aAbs = @bitCast(rep_t, aInt) & absMask;33 const aAbs = @as(rep_t, @bitCast(aInt)) & absMask;
34 const bAbs = @bitCast(rep_t, bInt) & absMask;34 const bAbs = @as(rep_t, @bitCast(bInt)) & absMask;
3535
36 // If either a or b is NaN, they are unordered.36 // If either a or b is NaN, they are unordered.
37 if (aAbs > infRep or bAbs > infRep) return RT.Unordered;37 if (aAbs > infRep or bAbs > infRep) return RT.Unordered;
...@@ -81,7 +81,7 @@ pub inline fn cmp_f80(comptime RT: type, a: f80, b: f80) RT {...@@ -81,7 +81,7 @@ pub inline fn cmp_f80(comptime RT: type, a: f80, b: f80) RT {
81 return .Equal;81 return .Equal;
82 } else if (a_rep.exp & sign_bit != b_rep.exp & sign_bit) {82 } else if (a_rep.exp & sign_bit != b_rep.exp & sign_bit) {
83 // signs are different83 // signs are different
84 if (@bitCast(i16, a_rep.exp) < @bitCast(i16, b_rep.exp)) {84 if (@as(i16, @bitCast(a_rep.exp)) < @as(i16, @bitCast(b_rep.exp))) {
85 return .Less;85 return .Less;
86 } else {86 } else {
87 return .Greater;87 return .Greater;
...@@ -104,10 +104,10 @@ pub inline fn unordcmp(comptime T: type, a: T, b: T) i32 {...@@ -104,10 +104,10 @@ pub inline fn unordcmp(comptime T: type, a: T, b: T) i32 {
104 const exponentBits = std.math.floatExponentBits(T);104 const exponentBits = std.math.floatExponentBits(T);
105 const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));105 const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
106 const absMask = signBit - 1;106 const absMask = signBit - 1;
107 const infRep = @bitCast(rep_t, std.math.inf(T));107 const infRep = @as(rep_t, @bitCast(std.math.inf(T)));
108108
109 const aAbs: rep_t = @bitCast(rep_t, a) & absMask;109 const aAbs: rep_t = @as(rep_t, @bitCast(a)) & absMask;
110 const bAbs: rep_t = @bitCast(rep_t, b) & absMask;110 const bAbs: rep_t = @as(rep_t, @bitCast(b)) & absMask;
111111
112 return @intFromBool(aAbs > infRep or bAbs > infRep);112 return @intFromBool(aAbs > infRep or bAbs > infRep);
113}113}
lib/compiler_rt/cos.zig+5-5
...@@ -25,7 +25,7 @@ comptime {...@@ -25,7 +25,7 @@ comptime {
2525
26pub fn __cosh(a: f16) callconv(.C) f16 {26pub fn __cosh(a: f16) callconv(.C) f16 {
27 // TODO: more efficient implementation27 // TODO: more efficient implementation
28 return @floatCast(f16, cosf(a));28 return @as(f16, @floatCast(cosf(a)));
29}29}
3030
31pub fn cosf(x: f32) callconv(.C) f32 {31pub fn cosf(x: f32) callconv(.C) f32 {
...@@ -35,7 +35,7 @@ pub fn cosf(x: f32) callconv(.C) f32 {...@@ -35,7 +35,7 @@ pub fn cosf(x: f32) callconv(.C) f32 {
35 const c3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D235 const c3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2
36 const c4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D1836 const c4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18
3737
38 var ix = @bitCast(u32, x);38 var ix = @as(u32, @bitCast(x));
39 const sign = ix >> 31 != 0;39 const sign = ix >> 31 != 0;
40 ix &= 0x7fffffff;40 ix &= 0x7fffffff;
4141
...@@ -86,7 +86,7 @@ pub fn cosf(x: f32) callconv(.C) f32 {...@@ -86,7 +86,7 @@ pub fn cosf(x: f32) callconv(.C) f32 {
86}86}
8787
88pub fn cos(x: f64) callconv(.C) f64 {88pub fn cos(x: f64) callconv(.C) f64 {
89 var ix = @bitCast(u64, x) >> 32;89 var ix = @as(u64, @bitCast(x)) >> 32;
90 ix &= 0x7fffffff;90 ix &= 0x7fffffff;
9191
92 // |x| ~< pi/492 // |x| ~< pi/4
...@@ -116,12 +116,12 @@ pub fn cos(x: f64) callconv(.C) f64 {...@@ -116,12 +116,12 @@ pub fn cos(x: f64) callconv(.C) f64 {
116116
117pub fn __cosx(a: f80) callconv(.C) f80 {117pub fn __cosx(a: f80) callconv(.C) f80 {
118 // TODO: more efficient implementation118 // TODO: more efficient implementation
119 return @floatCast(f80, cosq(a));119 return @as(f80, @floatCast(cosq(a)));
120}120}
121121
122pub fn cosq(a: f128) callconv(.C) f128 {122pub fn cosq(a: f128) callconv(.C) f128 {
123 // TODO: more correct implementation123 // TODO: more correct implementation
124 return cos(@floatCast(f64, a));124 return cos(@as(f64, @floatCast(a)));
125}125}
126126
127pub fn cosl(x: c_longdouble) callconv(.C) c_longdouble {127pub fn cosl(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/count0bits.zig+12-12
...@@ -32,9 +32,9 @@ comptime {...@@ -32,9 +32,9 @@ comptime {
3232
33inline fn clzXi2(comptime T: type, a: T) i32 {33inline fn clzXi2(comptime T: type, a: T) i32 {
34 var x = switch (@bitSizeOf(T)) {34 var x = switch (@bitSizeOf(T)) {
35 32 => @bitCast(u32, a),35 32 => @as(u32, @bitCast(a)),
36 64 => @bitCast(u64, a),36 64 => @as(u64, @bitCast(a)),
37 128 => @bitCast(u128, a),37 128 => @as(u128, @bitCast(a)),
38 else => unreachable,38 else => unreachable,
39 };39 };
40 var n: T = @bitSizeOf(T);40 var n: T = @bitSizeOf(T);
...@@ -49,7 +49,7 @@ inline fn clzXi2(comptime T: type, a: T) i32 {...@@ -49,7 +49,7 @@ inline fn clzXi2(comptime T: type, a: T) i32 {
49 x = y;49 x = y;
50 }50 }
51 }51 }
52 return @intCast(i32, n - @bitCast(T, x));52 return @as(i32, @intCast(n - @as(T, @bitCast(x))));
53}53}
5454
55fn __clzsi2_thumb1() callconv(.Naked) void {55fn __clzsi2_thumb1() callconv(.Naked) void {
...@@ -169,9 +169,9 @@ pub fn __clzti2(a: i128) callconv(.C) i32 {...@@ -169,9 +169,9 @@ pub fn __clzti2(a: i128) callconv(.C) i32 {
169169
170inline fn ctzXi2(comptime T: type, a: T) i32 {170inline fn ctzXi2(comptime T: type, a: T) i32 {
171 var x = switch (@bitSizeOf(T)) {171 var x = switch (@bitSizeOf(T)) {
172 32 => @bitCast(u32, a),172 32 => @as(u32, @bitCast(a)),
173 64 => @bitCast(u64, a),173 64 => @as(u64, @bitCast(a)),
174 128 => @bitCast(u128, a),174 128 => @as(u128, @bitCast(a)),
175 else => unreachable,175 else => unreachable,
176 };176 };
177 var n: T = 1;177 var n: T = 1;
...@@ -187,7 +187,7 @@ inline fn ctzXi2(comptime T: type, a: T) i32 {...@@ -187,7 +187,7 @@ inline fn ctzXi2(comptime T: type, a: T) i32 {
187 x = x >> shift;187 x = x >> shift;
188 }188 }
189 }189 }
190 return @intCast(i32, n - @bitCast(T, (x & 1)));190 return @as(i32, @intCast(n - @as(T, @bitCast((x & 1)))));
191}191}
192192
193pub fn __ctzsi2(a: i32) callconv(.C) i32 {193pub fn __ctzsi2(a: i32) callconv(.C) i32 {
...@@ -204,9 +204,9 @@ pub fn __ctzti2(a: i128) callconv(.C) i32 {...@@ -204,9 +204,9 @@ pub fn __ctzti2(a: i128) callconv(.C) i32 {
204204
205inline fn ffsXi2(comptime T: type, a: T) i32 {205inline fn ffsXi2(comptime T: type, a: T) i32 {
206 var x = switch (@bitSizeOf(T)) {206 var x = switch (@bitSizeOf(T)) {
207 32 => @bitCast(u32, a),207 32 => @as(u32, @bitCast(a)),
208 64 => @bitCast(u64, a),208 64 => @as(u64, @bitCast(a)),
209 128 => @bitCast(u128, a),209 128 => @as(u128, @bitCast(a)),
210 else => unreachable,210 else => unreachable,
211 };211 };
212 var n: T = 1;212 var n: T = 1;
...@@ -224,7 +224,7 @@ inline fn ffsXi2(comptime T: type, a: T) i32 {...@@ -224,7 +224,7 @@ inline fn ffsXi2(comptime T: type, a: T) i32 {
224 }224 }
225 }225 }
226 // return ctz + 1226 // return ctz + 1
227 return @intCast(i32, n - @bitCast(T, (x & 1))) + @as(i32, 1);227 return @as(i32, @intCast(n - @as(T, @bitCast((x & 1))))) + @as(i32, 1);
228}228}
229229
230pub fn __ffssi2(a: i32) callconv(.C) i32 {230pub fn __ffssi2(a: i32) callconv(.C) i32 {
lib/compiler_rt/ctzdi2_test.zig+1-1
...@@ -2,7 +2,7 @@ const ctz = @import("count0bits.zig");...@@ -2,7 +2,7 @@ const ctz = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ctzdi2(a: u64, expected: i32) !void {4fn test__ctzdi2(a: u64, expected: i32) !void {
5 var x = @bitCast(i64, a);5 var x = @as(i64, @bitCast(a));
6 var result = ctz.__ctzdi2(x);6 var result = ctz.__ctzdi2(x);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
lib/compiler_rt/ctzsi2_test.zig+1-1
...@@ -2,7 +2,7 @@ const ctz = @import("count0bits.zig");...@@ -2,7 +2,7 @@ const ctz = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ctzsi2(a: u32, expected: i32) !void {4fn test__ctzsi2(a: u32, expected: i32) !void {
5 var x = @bitCast(i32, a);5 var x = @as(i32, @bitCast(a));
6 var result = ctz.__ctzsi2(x);6 var result = ctz.__ctzsi2(x);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
lib/compiler_rt/ctzti2_test.zig+1-1
...@@ -2,7 +2,7 @@ const ctz = @import("count0bits.zig");...@@ -2,7 +2,7 @@ const ctz = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ctzti2(a: u128, expected: i32) !void {4fn test__ctzti2(a: u128, expected: i32) !void {
5 var x = @bitCast(i128, a);5 var x = @as(i128, @bitCast(a));
6 var result = ctz.__ctzti2(x);6 var result = ctz.__ctzti2(x);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
lib/compiler_rt/divdf3.zig+32-32
...@@ -47,52 +47,52 @@ inline fn div(a: f64, b: f64) f64 {...@@ -47,52 +47,52 @@ inline fn div(a: f64, b: f64) f64 {
47 const absMask = signBit - 1;47 const absMask = signBit - 1;
48 const exponentMask = absMask ^ significandMask;48 const exponentMask = absMask ^ significandMask;
49 const qnanRep = exponentMask | quietBit;49 const qnanRep = exponentMask | quietBit;
50 const infRep = @bitCast(Z, std.math.inf(f64));50 const infRep = @as(Z, @bitCast(std.math.inf(f64)));
5151
52 const aExponent = @truncate(u32, (@bitCast(Z, a) >> significandBits) & maxExponent);52 const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
53 const bExponent = @truncate(u32, (@bitCast(Z, b) >> significandBits) & maxExponent);53 const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
54 const quotientSign: Z = (@bitCast(Z, a) ^ @bitCast(Z, b)) & signBit;54 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
5555
56 var aSignificand: Z = @bitCast(Z, a) & significandMask;56 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;
57 var bSignificand: Z = @bitCast(Z, b) & significandMask;57 var bSignificand: Z = @as(Z, @bitCast(b)) & significandMask;
58 var scale: i32 = 0;58 var scale: i32 = 0;
5959
60 // Detect if a or b is zero, denormal, infinity, or NaN.60 // Detect if a or b is zero, denormal, infinity, or NaN.
61 if (aExponent -% 1 >= maxExponent - 1 or bExponent -% 1 >= maxExponent - 1) {61 if (aExponent -% 1 >= maxExponent - 1 or bExponent -% 1 >= maxExponent - 1) {
62 const aAbs: Z = @bitCast(Z, a) & absMask;62 const aAbs: Z = @as(Z, @bitCast(a)) & absMask;
63 const bAbs: Z = @bitCast(Z, b) & absMask;63 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
6464
65 // NaN / anything = qNaN65 // NaN / anything = qNaN
66 if (aAbs > infRep) return @bitCast(f64, @bitCast(Z, a) | quietBit);66 if (aAbs > infRep) return @as(f64, @bitCast(@as(Z, @bitCast(a)) | quietBit));
67 // anything / NaN = qNaN67 // anything / NaN = qNaN
68 if (bAbs > infRep) return @bitCast(f64, @bitCast(Z, b) | quietBit);68 if (bAbs > infRep) return @as(f64, @bitCast(@as(Z, @bitCast(b)) | quietBit));
6969
70 if (aAbs == infRep) {70 if (aAbs == infRep) {
71 // infinity / infinity = NaN71 // infinity / infinity = NaN
72 if (bAbs == infRep) {72 if (bAbs == infRep) {
73 return @bitCast(f64, qnanRep);73 return @as(f64, @bitCast(qnanRep));
74 }74 }
75 // infinity / anything else = +/- infinity75 // infinity / anything else = +/- infinity
76 else {76 else {
77 return @bitCast(f64, aAbs | quotientSign);77 return @as(f64, @bitCast(aAbs | quotientSign));
78 }78 }
79 }79 }
8080
81 // anything else / infinity = +/- 081 // anything else / infinity = +/- 0
82 if (bAbs == infRep) return @bitCast(f64, quotientSign);82 if (bAbs == infRep) return @as(f64, @bitCast(quotientSign));
8383
84 if (aAbs == 0) {84 if (aAbs == 0) {
85 // zero / zero = NaN85 // zero / zero = NaN
86 if (bAbs == 0) {86 if (bAbs == 0) {
87 return @bitCast(f64, qnanRep);87 return @as(f64, @bitCast(qnanRep));
88 }88 }
89 // zero / anything else = +/- zero89 // zero / anything else = +/- zero
90 else {90 else {
91 return @bitCast(f64, quotientSign);91 return @as(f64, @bitCast(quotientSign));
92 }92 }
93 }93 }
94 // anything else / zero = +/- infinity94 // anything else / zero = +/- infinity
95 if (bAbs == 0) return @bitCast(f64, infRep | quotientSign);95 if (bAbs == 0) return @as(f64, @bitCast(infRep | quotientSign));
9696
97 // one or both of a or b is denormal, the other (if applicable) is a97 // one or both of a or b is denormal, the other (if applicable) is a
98 // normal number. Renormalize one or both of a and b, and set scale to98 // normal number. Renormalize one or both of a and b, and set scale to
...@@ -106,13 +106,13 @@ inline fn div(a: f64, b: f64) f64 {...@@ -106,13 +106,13 @@ inline fn div(a: f64, b: f64) f64 {
106 // won't hurt anything.)106 // won't hurt anything.)
107 aSignificand |= implicitBit;107 aSignificand |= implicitBit;
108 bSignificand |= implicitBit;108 bSignificand |= implicitBit;
109 var quotientExponent: i32 = @bitCast(i32, aExponent -% bExponent) +% scale;109 var quotientExponent: i32 = @as(i32, @bitCast(aExponent -% bExponent)) +% scale;
110110
111 // Align the significand of b as a Q31 fixed-point number in the range111 // Align the significand of b as a Q31 fixed-point number in the range
112 // [1, 2.0) and get a Q32 approximate reciprocal using a small minimax112 // [1, 2.0) and get a Q32 approximate reciprocal using a small minimax
113 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This113 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
114 // is accurate to about 3.5 binary digits.114 // is accurate to about 3.5 binary digits.
115 const q31b: u32 = @truncate(u32, bSignificand >> 21);115 const q31b: u32 = @as(u32, @truncate(bSignificand >> 21));
116 var recip32 = @as(u32, 0x7504f333) -% q31b;116 var recip32 = @as(u32, 0x7504f333) -% q31b;
117117
118 // Now refine the reciprocal estimate using a Newton-Raphson iteration:118 // Now refine the reciprocal estimate using a Newton-Raphson iteration:
...@@ -123,12 +123,12 @@ inline fn div(a: f64, b: f64) f64 {...@@ -123,12 +123,12 @@ inline fn div(a: f64, b: f64) f64 {
123 // with each iteration, so after three iterations, we have about 28 binary123 // with each iteration, so after three iterations, we have about 28 binary
124 // digits of accuracy.124 // digits of accuracy.
125 var correction32: u32 = undefined;125 var correction32: u32 = undefined;
126 correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1);126 correction32 = @as(u32, @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1));
127 recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31);127 recip32 = @as(u32, @truncate(@as(u64, recip32) *% correction32 >> 31));
128 correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1);128 correction32 = @as(u32, @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1));
129 recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31);129 recip32 = @as(u32, @truncate(@as(u64, recip32) *% correction32 >> 31));
130 correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1);130 correction32 = @as(u32, @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1));
131 recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31);131 recip32 = @as(u32, @truncate(@as(u64, recip32) *% correction32 >> 31));
132132
133 // recip32 might have overflowed to exactly zero in the preceding133 // recip32 might have overflowed to exactly zero in the preceding
134 // computation if the high word of b is exactly 1.0. This would sabotage134 // 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 {...@@ -138,12 +138,12 @@ inline fn div(a: f64, b: f64) f64 {
138138
139 // We need to perform one more iteration to get us to 56 binary digits;139 // We need to perform one more iteration to get us to 56 binary digits;
140 // The last iteration needs to happen with extra precision.140 // The last iteration needs to happen with extra precision.
141 const q63blo: u32 = @truncate(u32, bSignificand << 11);141 const q63blo: u32 = @as(u32, @truncate(bSignificand << 11));
142 var correction: u64 = undefined;142 var correction: u64 = undefined;
143 var reciprocal: u64 = undefined;143 var reciprocal: u64 = undefined;
144 correction = ~(@as(u64, recip32) *% q31b +% (@as(u64, recip32) *% q63blo >> 32)) +% 1;144 correction = ~(@as(u64, recip32) *% q31b +% (@as(u64, recip32) *% q63blo >> 32)) +% 1;
145 const cHi = @truncate(u32, correction >> 32);145 const cHi = @as(u32, @truncate(correction >> 32));
146 const cLo = @truncate(u32, correction);146 const cLo = @as(u32, @truncate(correction));
147 reciprocal = @as(u64, recip32) *% cHi +% (@as(u64, recip32) *% cLo >> 32);147 reciprocal = @as(u64, recip32) *% cHi +% (@as(u64, recip32) *% cLo >> 32);
148148
149 // We already adjusted the 32-bit estimate, now we need to adjust the final149 // 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 {...@@ -195,7 +195,7 @@ inline fn div(a: f64, b: f64) f64 {
195195
196 if (writtenExponent >= maxExponent) {196 if (writtenExponent >= maxExponent) {
197 // If we have overflowed the exponent, return infinity.197 // If we have overflowed the exponent, return infinity.
198 return @bitCast(f64, infRep | quotientSign);198 return @as(f64, @bitCast(infRep | quotientSign));
199 } else if (writtenExponent < 1) {199 } else if (writtenExponent < 1) {
200 if (writtenExponent == 0) {200 if (writtenExponent == 0) {
201 // Check whether the rounded result is normal.201 // Check whether the rounded result is normal.
...@@ -206,22 +206,22 @@ inline fn div(a: f64, b: f64) f64 {...@@ -206,22 +206,22 @@ inline fn div(a: f64, b: f64) f64 {
206 absResult += round;206 absResult += round;
207 if ((absResult & ~significandMask) != 0) {207 if ((absResult & ~significandMask) != 0) {
208 // The rounded result is normal; return it.208 // The rounded result is normal; return it.
209 return @bitCast(f64, absResult | quotientSign);209 return @as(f64, @bitCast(absResult | quotientSign));
210 }210 }
211 }211 }
212 // Flush denormals to zero. In the future, it would be nice to add212 // Flush denormals to zero. In the future, it would be nice to add
213 // code to round them correctly.213 // code to round them correctly.
214 return @bitCast(f64, quotientSign);214 return @as(f64, @bitCast(quotientSign));
215 } else {215 } else {
216 const round = @intFromBool((residual << 1) > bSignificand);216 const round = @intFromBool((residual << 1) > bSignificand);
217 // Clear the implicit bit217 // Clear the implicit bit
218 var absResult = quotient & significandMask;218 var absResult = quotient & significandMask;
219 // Insert the exponent219 // Insert the exponent
220 absResult |= @bitCast(Z, @as(SignedZ, writtenExponent)) << significandBits;220 absResult |= @as(Z, @bitCast(@as(SignedZ, writtenExponent))) << significandBits;
221 // Round221 // Round
222 absResult +%= round;222 absResult +%= round;
223 // Insert the sign and return223 // Insert the sign and return
224 return @bitCast(f64, absResult | quotientSign);224 return @as(f64, @bitCast(absResult | quotientSign));
225 }225 }
226}226}
227227
lib/compiler_rt/divdf3_test.zig+1-1
...@@ -6,7 +6,7 @@ const __divdf3 = @import("divdf3.zig").__divdf3;...@@ -6,7 +6,7 @@ const __divdf3 = @import("divdf3.zig").__divdf3;
6const testing = @import("std").testing;6const testing = @import("std").testing;
77
8fn compareResultD(result: f64, expected: u64) bool {8fn compareResultD(result: f64, expected: u64) bool {
9 const rep = @bitCast(u64, result);9 const rep = @as(u64, @bitCast(result));
1010
11 if (rep == expected) {11 if (rep == expected) {
12 return true;12 return true;
lib/compiler_rt/divhf3.zig+1-1
...@@ -7,5 +7,5 @@ comptime {...@@ -7,5 +7,5 @@ comptime {
77
8pub fn __divhf3(a: f16, b: f16) callconv(.C) f16 {8pub fn __divhf3(a: f16, b: f16) callconv(.C) f16 {
9 // TODO: more efficient implementation9 // TODO: more efficient implementation
10 return @floatCast(f16, divsf3.__divsf3(a, b));10 return @as(f16, @floatCast(divsf3.__divsf3(a, b)));
11}11}
lib/compiler_rt/divsf3.zig+29-29
...@@ -44,52 +44,52 @@ inline fn div(a: f32, b: f32) f32 {...@@ -44,52 +44,52 @@ inline fn div(a: f32, b: f32) f32 {
44 const absMask = signBit - 1;44 const absMask = signBit - 1;
45 const exponentMask = absMask ^ significandMask;45 const exponentMask = absMask ^ significandMask;
46 const qnanRep = exponentMask | quietBit;46 const qnanRep = exponentMask | quietBit;
47 const infRep = @bitCast(Z, std.math.inf(f32));47 const infRep = @as(Z, @bitCast(std.math.inf(f32)));
4848
49 const aExponent = @truncate(u32, (@bitCast(Z, a) >> significandBits) & maxExponent);49 const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
50 const bExponent = @truncate(u32, (@bitCast(Z, b) >> significandBits) & maxExponent);50 const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
51 const quotientSign: Z = (@bitCast(Z, a) ^ @bitCast(Z, b)) & signBit;51 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
5252
53 var aSignificand: Z = @bitCast(Z, a) & significandMask;53 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;
54 var bSignificand: Z = @bitCast(Z, b) & significandMask;54 var bSignificand: Z = @as(Z, @bitCast(b)) & significandMask;
55 var scale: i32 = 0;55 var scale: i32 = 0;
5656
57 // Detect if a or b is zero, denormal, infinity, or NaN.57 // Detect if a or b is zero, denormal, infinity, or NaN.
58 if (aExponent -% 1 >= maxExponent - 1 or bExponent -% 1 >= maxExponent - 1) {58 if (aExponent -% 1 >= maxExponent - 1 or bExponent -% 1 >= maxExponent - 1) {
59 const aAbs: Z = @bitCast(Z, a) & absMask;59 const aAbs: Z = @as(Z, @bitCast(a)) & absMask;
60 const bAbs: Z = @bitCast(Z, b) & absMask;60 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
6161
62 // NaN / anything = qNaN62 // NaN / anything = qNaN
63 if (aAbs > infRep) return @bitCast(f32, @bitCast(Z, a) | quietBit);63 if (aAbs > infRep) return @as(f32, @bitCast(@as(Z, @bitCast(a)) | quietBit));
64 // anything / NaN = qNaN64 // anything / NaN = qNaN
65 if (bAbs > infRep) return @bitCast(f32, @bitCast(Z, b) | quietBit);65 if (bAbs > infRep) return @as(f32, @bitCast(@as(Z, @bitCast(b)) | quietBit));
6666
67 if (aAbs == infRep) {67 if (aAbs == infRep) {
68 // infinity / infinity = NaN68 // infinity / infinity = NaN
69 if (bAbs == infRep) {69 if (bAbs == infRep) {
70 return @bitCast(f32, qnanRep);70 return @as(f32, @bitCast(qnanRep));
71 }71 }
72 // infinity / anything else = +/- infinity72 // infinity / anything else = +/- infinity
73 else {73 else {
74 return @bitCast(f32, aAbs | quotientSign);74 return @as(f32, @bitCast(aAbs | quotientSign));
75 }75 }
76 }76 }
7777
78 // anything else / infinity = +/- 078 // anything else / infinity = +/- 0
79 if (bAbs == infRep) return @bitCast(f32, quotientSign);79 if (bAbs == infRep) return @as(f32, @bitCast(quotientSign));
8080
81 if (aAbs == 0) {81 if (aAbs == 0) {
82 // zero / zero = NaN82 // zero / zero = NaN
83 if (bAbs == 0) {83 if (bAbs == 0) {
84 return @bitCast(f32, qnanRep);84 return @as(f32, @bitCast(qnanRep));
85 }85 }
86 // zero / anything else = +/- zero86 // zero / anything else = +/- zero
87 else {87 else {
88 return @bitCast(f32, quotientSign);88 return @as(f32, @bitCast(quotientSign));
89 }89 }
90 }90 }
91 // anything else / zero = +/- infinity91 // anything else / zero = +/- infinity
92 if (bAbs == 0) return @bitCast(f32, infRep | quotientSign);92 if (bAbs == 0) return @as(f32, @bitCast(infRep | quotientSign));
9393
94 // one or both of a or b is denormal, the other (if applicable) is a94 // one or both of a or b is denormal, the other (if applicable) is a
95 // normal number. Renormalize one or both of a and b, and set scale to95 // normal number. Renormalize one or both of a and b, and set scale to
...@@ -103,7 +103,7 @@ inline fn div(a: f32, b: f32) f32 {...@@ -103,7 +103,7 @@ inline fn div(a: f32, b: f32) f32 {
103 // won't hurt anything.)103 // won't hurt anything.)
104 aSignificand |= implicitBit;104 aSignificand |= implicitBit;
105 bSignificand |= implicitBit;105 bSignificand |= implicitBit;
106 var quotientExponent: i32 = @bitCast(i32, aExponent -% bExponent) +% scale;106 var quotientExponent: i32 = @as(i32, @bitCast(aExponent -% bExponent)) +% scale;
107107
108 // Align the significand of b as a Q31 fixed-point number in the range108 // Align the significand of b as a Q31 fixed-point number in the range
109 // [1, 2.0) and get a Q32 approximate reciprocal using a small minimax109 // [1, 2.0) and get a Q32 approximate reciprocal using a small minimax
...@@ -120,12 +120,12 @@ inline fn div(a: f32, b: f32) f32 {...@@ -120,12 +120,12 @@ inline fn div(a: f32, b: f32) f32 {
120 // with each iteration, so after three iterations, we have about 28 binary120 // with each iteration, so after three iterations, we have about 28 binary
121 // digits of accuracy.121 // digits of accuracy.
122 var correction: u32 = undefined;122 var correction: u32 = undefined;
123 correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1);123 correction = @as(u32, @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1));
124 reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31);124 reciprocal = @as(u32, @truncate(@as(u64, reciprocal) *% correction >> 31));
125 correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1);125 correction = @as(u32, @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1));
126 reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31);126 reciprocal = @as(u32, @truncate(@as(u64, reciprocal) *% correction >> 31));
127 correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1);127 correction = @as(u32, @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1));
128 reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31);128 reciprocal = @as(u32, @truncate(@as(u64, reciprocal) *% correction >> 31));
129129
130 // Exhaustive testing shows that the error in reciprocal after three steps130 // Exhaustive testing shows that the error in reciprocal after three steps
131 // is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our131 // 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 {...@@ -147,7 +147,7 @@ inline fn div(a: f32, b: f32) f32 {
147 // is the error in the reciprocal of b scaled by the maximum147 // is the error in the reciprocal of b scaled by the maximum
148 // possible value of a. As a consequence of this error bound,148 // possible value of a. As a consequence of this error bound,
149 // either q or nextafter(q) is the correctly rounded149 // either q or nextafter(q) is the correctly rounded
150 var quotient: Z = @truncate(u32, @as(u64, reciprocal) *% (aSignificand << 1) >> 32);150 var quotient: Z = @as(u32, @truncate(@as(u64, reciprocal) *% (aSignificand << 1) >> 32));
151151
152 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).152 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
153 // In either case, we are going to compute a residual of the form153 // 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 {...@@ -175,7 +175,7 @@ inline fn div(a: f32, b: f32) f32 {
175175
176 if (writtenExponent >= maxExponent) {176 if (writtenExponent >= maxExponent) {
177 // If we have overflowed the exponent, return infinity.177 // If we have overflowed the exponent, return infinity.
178 return @bitCast(f32, infRep | quotientSign);178 return @as(f32, @bitCast(infRep | quotientSign));
179 } else if (writtenExponent < 1) {179 } else if (writtenExponent < 1) {
180 if (writtenExponent == 0) {180 if (writtenExponent == 0) {
181 // Check whether the rounded result is normal.181 // Check whether the rounded result is normal.
...@@ -186,22 +186,22 @@ inline fn div(a: f32, b: f32) f32 {...@@ -186,22 +186,22 @@ inline fn div(a: f32, b: f32) f32 {
186 absResult += round;186 absResult += round;
187 if ((absResult & ~significandMask) > 0) {187 if ((absResult & ~significandMask) > 0) {
188 // The rounded result is normal; return it.188 // The rounded result is normal; return it.
189 return @bitCast(f32, absResult | quotientSign);189 return @as(f32, @bitCast(absResult | quotientSign));
190 }190 }
191 }191 }
192 // Flush denormals to zero. In the future, it would be nice to add192 // Flush denormals to zero. In the future, it would be nice to add
193 // code to round them correctly.193 // code to round them correctly.
194 return @bitCast(f32, quotientSign);194 return @as(f32, @bitCast(quotientSign));
195 } else {195 } else {
196 const round = @intFromBool((residual << 1) > bSignificand);196 const round = @intFromBool((residual << 1) > bSignificand);
197 // Clear the implicit bit197 // Clear the implicit bit
198 var absResult = quotient & significandMask;198 var absResult = quotient & significandMask;
199 // Insert the exponent199 // Insert the exponent
200 absResult |= @bitCast(Z, writtenExponent) << significandBits;200 absResult |= @as(Z, @bitCast(writtenExponent)) << significandBits;
201 // Round201 // Round
202 absResult +%= round;202 absResult +%= round;
203 // Insert the sign and return203 // Insert the sign and return
204 return @bitCast(f32, absResult | quotientSign);204 return @as(f32, @bitCast(absResult | quotientSign));
205 }205 }
206}206}
207207
lib/compiler_rt/divsf3_test.zig+1-1
...@@ -6,7 +6,7 @@ const __divsf3 = @import("divsf3.zig").__divsf3;...@@ -6,7 +6,7 @@ const __divsf3 = @import("divsf3.zig").__divsf3;
6const testing = @import("std").testing;6const testing = @import("std").testing;
77
8fn compareResultF(result: f32, expected: u32) bool {8fn compareResultF(result: f32, expected: u32) bool {
9 const rep = @bitCast(u32, result);9 const rep = @as(u32, @bitCast(result));
1010
11 if (rep == expected) {11 if (rep == expected) {
12 return true;12 return true;
lib/compiler_rt/divtf3.zig+36-36
...@@ -41,52 +41,52 @@ inline fn div(a: f128, b: f128) f128 {...@@ -41,52 +41,52 @@ inline fn div(a: f128, b: f128) f128 {
41 const absMask = signBit - 1;41 const absMask = signBit - 1;
42 const exponentMask = absMask ^ significandMask;42 const exponentMask = absMask ^ significandMask;
43 const qnanRep = exponentMask | quietBit;43 const qnanRep = exponentMask | quietBit;
44 const infRep = @bitCast(Z, std.math.inf(f128));44 const infRep = @as(Z, @bitCast(std.math.inf(f128)));
4545
46 const aExponent = @truncate(u32, (@bitCast(Z, a) >> significandBits) & maxExponent);46 const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
47 const bExponent = @truncate(u32, (@bitCast(Z, b) >> significandBits) & maxExponent);47 const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
48 const quotientSign: Z = (@bitCast(Z, a) ^ @bitCast(Z, b)) & signBit;48 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
4949
50 var aSignificand: Z = @bitCast(Z, a) & significandMask;50 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;
51 var bSignificand: Z = @bitCast(Z, b) & significandMask;51 var bSignificand: Z = @as(Z, @bitCast(b)) & significandMask;
52 var scale: i32 = 0;52 var scale: i32 = 0;
5353
54 // Detect if a or b is zero, denormal, infinity, or NaN.54 // Detect if a or b is zero, denormal, infinity, or NaN.
55 if (aExponent -% 1 >= maxExponent - 1 or bExponent -% 1 >= maxExponent - 1) {55 if (aExponent -% 1 >= maxExponent - 1 or bExponent -% 1 >= maxExponent - 1) {
56 const aAbs: Z = @bitCast(Z, a) & absMask;56 const aAbs: Z = @as(Z, @bitCast(a)) & absMask;
57 const bAbs: Z = @bitCast(Z, b) & absMask;57 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
5858
59 // NaN / anything = qNaN59 // NaN / anything = qNaN
60 if (aAbs > infRep) return @bitCast(f128, @bitCast(Z, a) | quietBit);60 if (aAbs > infRep) return @as(f128, @bitCast(@as(Z, @bitCast(a)) | quietBit));
61 // anything / NaN = qNaN61 // anything / NaN = qNaN
62 if (bAbs > infRep) return @bitCast(f128, @bitCast(Z, b) | quietBit);62 if (bAbs > infRep) return @as(f128, @bitCast(@as(Z, @bitCast(b)) | quietBit));
6363
64 if (aAbs == infRep) {64 if (aAbs == infRep) {
65 // infinity / infinity = NaN65 // infinity / infinity = NaN
66 if (bAbs == infRep) {66 if (bAbs == infRep) {
67 return @bitCast(f128, qnanRep);67 return @as(f128, @bitCast(qnanRep));
68 }68 }
69 // infinity / anything else = +/- infinity69 // infinity / anything else = +/- infinity
70 else {70 else {
71 return @bitCast(f128, aAbs | quotientSign);71 return @as(f128, @bitCast(aAbs | quotientSign));
72 }72 }
73 }73 }
7474
75 // anything else / infinity = +/- 075 // anything else / infinity = +/- 0
76 if (bAbs == infRep) return @bitCast(f128, quotientSign);76 if (bAbs == infRep) return @as(f128, @bitCast(quotientSign));
7777
78 if (aAbs == 0) {78 if (aAbs == 0) {
79 // zero / zero = NaN79 // zero / zero = NaN
80 if (bAbs == 0) {80 if (bAbs == 0) {
81 return @bitCast(f128, qnanRep);81 return @as(f128, @bitCast(qnanRep));
82 }82 }
83 // zero / anything else = +/- zero83 // zero / anything else = +/- zero
84 else {84 else {
85 return @bitCast(f128, quotientSign);85 return @as(f128, @bitCast(quotientSign));
86 }86 }
87 }87 }
88 // anything else / zero = +/- infinity88 // anything else / zero = +/- infinity
89 if (bAbs == 0) return @bitCast(f128, infRep | quotientSign);89 if (bAbs == 0) return @as(f128, @bitCast(infRep | quotientSign));
9090
91 // one or both of a or b is denormal, the other (if applicable) is a91 // one or both of a or b is denormal, the other (if applicable) is a
92 // normal number. Renormalize one or both of a and b, and set scale to92 // normal number. Renormalize one or both of a and b, and set scale to
...@@ -100,13 +100,13 @@ inline fn div(a: f128, b: f128) f128 {...@@ -100,13 +100,13 @@ inline fn div(a: f128, b: f128) f128 {
100 // won't hurt anything.100 // won't hurt anything.
101 aSignificand |= implicitBit;101 aSignificand |= implicitBit;
102 bSignificand |= implicitBit;102 bSignificand |= implicitBit;
103 var quotientExponent: i32 = @bitCast(i32, aExponent -% bExponent) +% scale;103 var quotientExponent: i32 = @as(i32, @bitCast(aExponent -% bExponent)) +% scale;
104104
105 // Align the significand of b as a Q63 fixed-point number in the range105 // Align the significand of b as a Q63 fixed-point number in the range
106 // [1, 2.0) and get a Q64 approximate reciprocal using a small minimax106 // [1, 2.0) and get a Q64 approximate reciprocal using a small minimax
107 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This107 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
108 // is accurate to about 3.5 binary digits.108 // is accurate to about 3.5 binary digits.
109 const q63b = @truncate(u64, bSignificand >> 49);109 const q63b = @as(u64, @truncate(bSignificand >> 49));
110 var recip64 = @as(u64, 0x7504f333F9DE6484) -% q63b;110 var recip64 = @as(u64, 0x7504f333F9DE6484) -% q63b;
111 // 0x7504f333F9DE6484 / 2^64 + 1 = 3/4 + 1/sqrt(2)111 // 0x7504f333F9DE6484 / 2^64 + 1 = 3/4 + 1/sqrt(2)
112112
...@@ -117,16 +117,16 @@ inline fn div(a: f128, b: f128) f128 {...@@ -117,16 +117,16 @@ inline fn div(a: f128, b: f128) f128 {
117 // This doubles the number of correct binary digits in the approximation117 // This doubles the number of correct binary digits in the approximation
118 // with each iteration.118 // with each iteration.
119 var correction64: u64 = undefined;119 var correction64: u64 = undefined;
120 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);120 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
121 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);121 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
122 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);122 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
123 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);123 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
124 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);124 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
125 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);125 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
126 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);126 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
127 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);127 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
128 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);128 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
129 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);129 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
130130
131 // The reciprocal may have overflowed to zero if the upper half of b is131 // The reciprocal may have overflowed to zero if the upper half of b is
132 // exactly 1.0. This would sabatoge the full-width final stage of the132 // 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 {...@@ -135,7 +135,7 @@ inline fn div(a: f128, b: f128) f128 {
135135
136 // We need to perform one more iteration to get us to 112 binary digits;136 // We need to perform one more iteration to get us to 112 binary digits;
137 // The last iteration needs to happen with extra precision.137 // The last iteration needs to happen with extra precision.
138 const q127blo: u64 = @truncate(u64, bSignificand << 15);138 const q127blo: u64 = @as(u64, @truncate(bSignificand << 15));
139 var correction: u128 = undefined;139 var correction: u128 = undefined;
140 var reciprocal: u128 = undefined;140 var reciprocal: u128 = undefined;
141141
...@@ -151,8 +151,8 @@ inline fn div(a: f128, b: f128) f128 {...@@ -151,8 +151,8 @@ inline fn div(a: f128, b: f128) f128 {
151151
152 correction = -%(r64q63 + (r64q127 >> 64));152 correction = -%(r64q63 + (r64q127 >> 64));
153153
154 const cHi = @truncate(u64, correction >> 64);154 const cHi = @as(u64, @truncate(correction >> 64));
155 const cLo = @truncate(u64, correction);155 const cLo = @as(u64, @truncate(correction));
156156
157 wideMultiply(u128, recip64, cHi, &dummy, &r64cH);157 wideMultiply(u128, recip64, cHi, &dummy, &r64cH);
158 wideMultiply(u128, recip64, cLo, &dummy, &r64cL);158 wideMultiply(u128, recip64, cLo, &dummy, &r64cL);
...@@ -210,7 +210,7 @@ inline fn div(a: f128, b: f128) f128 {...@@ -210,7 +210,7 @@ inline fn div(a: f128, b: f128) f128 {
210210
211 if (writtenExponent >= maxExponent) {211 if (writtenExponent >= maxExponent) {
212 // If we have overflowed the exponent, return infinity.212 // If we have overflowed the exponent, return infinity.
213 return @bitCast(f128, infRep | quotientSign);213 return @as(f128, @bitCast(infRep | quotientSign));
214 } else if (writtenExponent < 1) {214 } else if (writtenExponent < 1) {
215 if (writtenExponent == 0) {215 if (writtenExponent == 0) {
216 // Check whether the rounded result is normal.216 // Check whether the rounded result is normal.
...@@ -221,22 +221,22 @@ inline fn div(a: f128, b: f128) f128 {...@@ -221,22 +221,22 @@ inline fn div(a: f128, b: f128) f128 {
221 absResult += round;221 absResult += round;
222 if ((absResult & ~significandMask) > 0) {222 if ((absResult & ~significandMask) > 0) {
223 // The rounded result is normal; return it.223 // The rounded result is normal; return it.
224 return @bitCast(f128, absResult | quotientSign);224 return @as(f128, @bitCast(absResult | quotientSign));
225 }225 }
226 }226 }
227 // Flush denormals to zero. In the future, it would be nice to add227 // Flush denormals to zero. In the future, it would be nice to add
228 // code to round them correctly.228 // code to round them correctly.
229 return @bitCast(f128, quotientSign);229 return @as(f128, @bitCast(quotientSign));
230 } else {230 } else {
231 const round = @intFromBool((residual << 1) >= bSignificand);231 const round = @intFromBool((residual << 1) >= bSignificand);
232 // Clear the implicit bit232 // Clear the implicit bit
233 var absResult = quotient & significandMask;233 var absResult = quotient & significandMask;
234 // Insert the exponent234 // Insert the exponent
235 absResult |= @intCast(Z, writtenExponent) << significandBits;235 absResult |= @as(Z, @intCast(writtenExponent)) << significandBits;
236 // Round236 // Round
237 absResult +%= round;237 absResult +%= round;
238 // Insert the sign and return238 // Insert the sign and return
239 return @bitCast(f128, absResult | quotientSign);239 return @as(f128, @bitCast(absResult | quotientSign));
240 }240 }
241}241}
242242
lib/compiler_rt/divtf3_test.zig+3-3
...@@ -5,9 +5,9 @@ const testing = std.testing;...@@ -5,9 +5,9 @@ const testing = std.testing;
5const __divtf3 = @import("divtf3.zig").__divtf3;5const __divtf3 = @import("divtf3.zig").__divtf3;
66
7fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {7fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
8 const rep = @bitCast(u128, result);8 const rep = @as(u128, @bitCast(result));
9 const hi = @truncate(u64, rep >> 64);9 const hi = @as(u64, @truncate(rep >> 64));
10 const lo = @truncate(u64, rep);10 const lo = @as(u64, @truncate(rep));
1111
12 if (hi == expectedHi and lo == expectedLo) {12 if (hi == expectedHi and lo == expectedLo) {
13 return true;13 return true;
lib/compiler_rt/divti3.zig+3-3
...@@ -21,7 +21,7 @@ pub fn __divti3(a: i128, b: i128) callconv(.C) i128 {...@@ -21,7 +21,7 @@ pub fn __divti3(a: i128, b: i128) callconv(.C) i128 {
21const v128 = @Vector(2, u64);21const v128 = @Vector(2, u64);
2222
23fn __divti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {23fn __divti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
24 return @bitCast(v128, div(@bitCast(i128, a), @bitCast(i128, b)));24 return @as(v128, @bitCast(div(@as(i128, @bitCast(a)), @as(i128, @bitCast(b)))));
25}25}
2626
27inline fn div(a: i128, b: i128) i128 {27inline fn div(a: i128, b: i128) i128 {
...@@ -31,9 +31,9 @@ inline fn div(a: i128, b: i128) i128 {...@@ -31,9 +31,9 @@ inline fn div(a: i128, b: i128) i128 {
31 const an = (a ^ s_a) -% s_a;31 const an = (a ^ s_a) -% s_a;
32 const bn = (b ^ s_b) -% s_b;32 const bn = (b ^ s_b) -% s_b;
3333
34 const r = udivmod(u128, @bitCast(u128, an), @bitCast(u128, bn), null);34 const r = udivmod(u128, @as(u128, @bitCast(an)), @as(u128, @bitCast(bn)), null);
35 const s = s_a ^ s_b;35 const s = s_a ^ s_b;
36 return (@bitCast(i128, r) ^ s) -% s;36 return (@as(i128, @bitCast(r)) ^ s) -% s;
37}37}
3838
39test {39test {
lib/compiler_rt/divti3_test.zig+4-4
...@@ -14,8 +14,8 @@ test "divti3" {...@@ -14,8 +14,8 @@ test "divti3" {
14 try test__divti3(-2, 1, -2);14 try test__divti3(-2, 1, -2);
15 try test__divti3(-2, -1, 2);15 try test__divti3(-2, -1, 2);
1616
17 try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 1, @bitCast(i128, @as(u128, 0x8 << 124)));17 try test__divti3(@as(i128, @bitCast(@as(u128, 0x8 << 124))), 1, @as(i128, @bitCast(@as(u128, 0x8 << 124))));
18 try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -1, @bitCast(i128, @as(u128, 0x8 << 124)));18 try test__divti3(@as(i128, @bitCast(@as(u128, 0x8 << 124))), -1, @as(i128, @bitCast(@as(u128, 0x8 << 124))));
19 try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -2, @bitCast(i128, @as(u128, 0x4 << 124)));19 try test__divti3(@as(i128, @bitCast(@as(u128, 0x8 << 124))), -2, @as(i128, @bitCast(@as(u128, 0x4 << 124))));
20 try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 2, @bitCast(i128, @as(u128, 0xc << 124)));20 try test__divti3(@as(i128, @bitCast(@as(u128, 0x8 << 124))), 2, @as(i128, @bitCast(@as(u128, 0xc << 124))));
21}21}
lib/compiler_rt/divxf3.zig+38-38
...@@ -29,53 +29,53 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {...@@ -29,53 +29,53 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
29 const significandMask = (@as(Z, 1) << significandBits) - 1;29 const significandMask = (@as(Z, 1) << significandBits) - 1;
3030
31 const absMask = signBit - 1;31 const absMask = signBit - 1;
32 const qnanRep = @bitCast(Z, std.math.nan(T)) | quietBit;32 const qnanRep = @as(Z, @bitCast(std.math.nan(T))) | quietBit;
33 const infRep = @bitCast(Z, std.math.inf(T));33 const infRep = @as(Z, @bitCast(std.math.inf(T)));
3434
35 const aExponent = @truncate(u32, (@bitCast(Z, a) >> significandBits) & maxExponent);35 const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
36 const bExponent = @truncate(u32, (@bitCast(Z, b) >> significandBits) & maxExponent);36 const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
37 const quotientSign: Z = (@bitCast(Z, a) ^ @bitCast(Z, b)) & signBit;37 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
3838
39 var aSignificand: Z = @bitCast(Z, a) & significandMask;39 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;
40 var bSignificand: Z = @bitCast(Z, b) & significandMask;40 var bSignificand: Z = @as(Z, @bitCast(b)) & significandMask;
41 var scale: i32 = 0;41 var scale: i32 = 0;
4242
43 // Detect if a or b is zero, denormal, infinity, or NaN.43 // Detect if a or b is zero, denormal, infinity, or NaN.
44 if (aExponent -% 1 >= maxExponent - 1 or bExponent -% 1 >= maxExponent - 1) {44 if (aExponent -% 1 >= maxExponent - 1 or bExponent -% 1 >= maxExponent - 1) {
45 const aAbs: Z = @bitCast(Z, a) & absMask;45 const aAbs: Z = @as(Z, @bitCast(a)) & absMask;
46 const bAbs: Z = @bitCast(Z, b) & absMask;46 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
4747
48 // NaN / anything = qNaN48 // NaN / anything = qNaN
49 if (aAbs > infRep) return @bitCast(T, @bitCast(Z, a) | quietBit);49 if (aAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(a)) | quietBit));
50 // anything / NaN = qNaN50 // anything / NaN = qNaN
51 if (bAbs > infRep) return @bitCast(T, @bitCast(Z, b) | quietBit);51 if (bAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(b)) | quietBit));
5252
53 if (aAbs == infRep) {53 if (aAbs == infRep) {
54 // infinity / infinity = NaN54 // infinity / infinity = NaN
55 if (bAbs == infRep) {55 if (bAbs == infRep) {
56 return @bitCast(T, qnanRep);56 return @as(T, @bitCast(qnanRep));
57 }57 }
58 // infinity / anything else = +/- infinity58 // infinity / anything else = +/- infinity
59 else {59 else {
60 return @bitCast(T, aAbs | quotientSign);60 return @as(T, @bitCast(aAbs | quotientSign));
61 }61 }
62 }62 }
6363
64 // anything else / infinity = +/- 064 // anything else / infinity = +/- 0
65 if (bAbs == infRep) return @bitCast(T, quotientSign);65 if (bAbs == infRep) return @as(T, @bitCast(quotientSign));
6666
67 if (aAbs == 0) {67 if (aAbs == 0) {
68 // zero / zero = NaN68 // zero / zero = NaN
69 if (bAbs == 0) {69 if (bAbs == 0) {
70 return @bitCast(T, qnanRep);70 return @as(T, @bitCast(qnanRep));
71 }71 }
72 // zero / anything else = +/- zero72 // zero / anything else = +/- zero
73 else {73 else {
74 return @bitCast(T, quotientSign);74 return @as(T, @bitCast(quotientSign));
75 }75 }
76 }76 }
77 // anything else / zero = +/- infinity77 // anything else / zero = +/- infinity
78 if (bAbs == 0) return @bitCast(T, infRep | quotientSign);78 if (bAbs == 0) return @as(T, @bitCast(infRep | quotientSign));
7979
80 // one or both of a or b is denormal, the other (if applicable) is a80 // one or both of a or b is denormal, the other (if applicable) is a
81 // normal number. Renormalize one or both of a and b, and set scale to81 // normal number. Renormalize one or both of a and b, and set scale to
...@@ -83,13 +83,13 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {...@@ -83,13 +83,13 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
83 if (aAbs < integerBit) scale +%= normalize(T, &aSignificand);83 if (aAbs < integerBit) scale +%= normalize(T, &aSignificand);
84 if (bAbs < integerBit) scale -%= normalize(T, &bSignificand);84 if (bAbs < integerBit) scale -%= normalize(T, &bSignificand);
85 }85 }
86 var quotientExponent: i32 = @bitCast(i32, aExponent -% bExponent) +% scale;86 var quotientExponent: i32 = @as(i32, @bitCast(aExponent -% bExponent)) +% scale;
8787
88 // Align the significand of b as a Q63 fixed-point number in the range88 // Align the significand of b as a Q63 fixed-point number in the range
89 // [1, 2.0) and get a Q64 approximate reciprocal using a small minimax89 // [1, 2.0) and get a Q64 approximate reciprocal using a small minimax
90 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This90 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
91 // is accurate to about 3.5 binary digits.91 // is accurate to about 3.5 binary digits.
92 const q63b = @intCast(u64, bSignificand);92 const q63b = @as(u64, @intCast(bSignificand));
93 var recip64 = @as(u64, 0x7504f333F9DE6484) -% q63b;93 var recip64 = @as(u64, 0x7504f333F9DE6484) -% q63b;
94 // 0x7504f333F9DE6484 / 2^64 + 1 = 3/4 + 1/sqrt(2)94 // 0x7504f333F9DE6484 / 2^64 + 1 = 3/4 + 1/sqrt(2)
9595
...@@ -100,16 +100,16 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {...@@ -100,16 +100,16 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
100 // This doubles the number of correct binary digits in the approximation100 // This doubles the number of correct binary digits in the approximation
101 // with each iteration.101 // with each iteration.
102 var correction64: u64 = undefined;102 var correction64: u64 = undefined;
103 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);103 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
104 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);104 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
105 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);105 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
106 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);106 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
107 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);107 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
108 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);108 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
109 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);109 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
110 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);110 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
111 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);111 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
112 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);112 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
113113
114 // The reciprocal may have overflowed to zero if the upper half of b is114 // The reciprocal may have overflowed to zero if the upper half of b is
115 // exactly 1.0. This would sabatoge the full-width final stage of the115 // 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 {...@@ -128,8 +128,8 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
128128
129 correction = -%correction;129 correction = -%correction;
130130
131 const cHi = @truncate(u64, correction >> 64);131 const cHi = @as(u64, @truncate(correction >> 64));
132 const cLo = @truncate(u64, correction);132 const cLo = @as(u64, @truncate(correction));
133133
134 var r64cH: u128 = undefined;134 var r64cH: u128 = undefined;
135 var r64cL: u128 = undefined;135 var r64cL: u128 = undefined;
...@@ -164,8 +164,8 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {...@@ -164,8 +164,8 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
164 // exponent accordingly.164 // exponent accordingly.
165 var quotient: u64 = if (quotient128 < (integerBit << 1)) b: {165 var quotient: u64 = if (quotient128 < (integerBit << 1)) b: {
166 quotientExponent -= 1;166 quotientExponent -= 1;
167 break :b @intCast(u64, quotient128);167 break :b @as(u64, @intCast(quotient128));
168 } else @intCast(u64, quotient128 >> 1);168 } else @as(u64, @intCast(quotient128 >> 1));
169169
170 // We are going to compute a residual of the form170 // We are going to compute a residual of the form
171 //171 //
...@@ -182,26 +182,26 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {...@@ -182,26 +182,26 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
182 const writtenExponent = quotientExponent + exponentBias;182 const writtenExponent = quotientExponent + exponentBias;
183 if (writtenExponent >= maxExponent) {183 if (writtenExponent >= maxExponent) {
184 // If we have overflowed the exponent, return infinity.184 // If we have overflowed the exponent, return infinity.
185 return @bitCast(T, infRep | quotientSign);185 return @as(T, @bitCast(infRep | quotientSign));
186 } else if (writtenExponent < 1) {186 } else if (writtenExponent < 1) {
187 if (writtenExponent == 0) {187 if (writtenExponent == 0) {
188 // Check whether the rounded result is normal.188 // Check whether the rounded result is normal.
189 if (residual > (bSignificand >> 1)) { // round189 if (residual > (bSignificand >> 1)) { // round
190 if (quotient == (integerBit - 1)) // If the rounded result is normal, return it190 if (quotient == (integerBit - 1)) // If the rounded result is normal, return it
191 return @bitCast(T, @bitCast(Z, std.math.floatMin(T)) | quotientSign);191 return @as(T, @bitCast(@as(Z, @bitCast(std.math.floatMin(T))) | quotientSign));
192 }192 }
193 }193 }
194 // Flush denormals to zero. In the future, it would be nice to add194 // Flush denormals to zero. In the future, it would be nice to add
195 // code to round them correctly.195 // code to round them correctly.
196 return @bitCast(T, quotientSign);196 return @as(T, @bitCast(quotientSign));
197 } else {197 } else {
198 const round = @intFromBool(residual > (bSignificand >> 1));198 const round = @intFromBool(residual > (bSignificand >> 1));
199 // Insert the exponent199 // Insert the exponent
200 var absResult = quotient | (@intCast(Z, writtenExponent) << significandBits);200 var absResult = quotient | (@as(Z, @intCast(writtenExponent)) << significandBits);
201 // Round201 // Round
202 absResult +%= round;202 absResult +%= round;
203 // Insert the sign and return203 // Insert the sign and return
204 return @bitCast(T, absResult | quotientSign | integerBit);204 return @as(T, @bitCast(absResult | quotientSign | integerBit));
205 }205 }
206}206}
207207
lib/compiler_rt/divxf3_test.zig+4-4
...@@ -5,11 +5,11 @@ const testing = std.testing;...@@ -5,11 +5,11 @@ const testing = std.testing;
5const __divxf3 = @import("divxf3.zig").__divxf3;5const __divxf3 = @import("divxf3.zig").__divxf3;
66
7fn compareResult(result: f80, expected: u80) bool {7fn compareResult(result: f80, expected: u80) bool {
8 const rep = @bitCast(u80, result);8 const rep = @as(u80, @bitCast(result));
99
10 if (rep == expected) return true;10 if (rep == expected) return true;
11 // test other possible NaN representations (signal NaN)11 // test other possible NaN representations (signal NaN)
12 if (math.isNan(result) and math.isNan(@bitCast(f80, expected))) return true;12 if (math.isNan(result) and math.isNan(@as(f80, @bitCast(expected)))) return true;
1313
14 return false;14 return false;
15}15}
...@@ -25,9 +25,9 @@ fn test__divxf3(a: f80, b: f80) !void {...@@ -25,9 +25,9 @@ fn test__divxf3(a: f80, b: f80) !void {
25 const x = __divxf3(a, b);25 const x = __divxf3(a, b);
2626
27 // Next float (assuming normal, non-zero result)27 // Next float (assuming normal, non-zero result)
28 const x_plus_eps = @bitCast(f80, (@bitCast(u80, x) + 1) | integerBit);28 const x_plus_eps = @as(f80, @bitCast((@as(u80, @bitCast(x)) + 1) | integerBit));
29 // Prev float (assuming normal, non-zero result)29 // Prev float (assuming normal, non-zero result)
30 const x_minus_eps = @bitCast(f80, (@bitCast(u80, x) - 1) | integerBit);30 const x_minus_eps = @as(f80, @bitCast((@as(u80, @bitCast(x)) - 1) | integerBit));
3131
32 // Make sure result is more accurate than the adjacent floats32 // Make sure result is more accurate than the adjacent floats
33 const err_x = @fabs(@mulAdd(f80, x, b, -a));33 const err_x = @fabs(@mulAdd(f80, x, b, -a));
lib/compiler_rt/emutls.zig+19-38
...@@ -33,18 +33,14 @@ pub fn __emutls_get_address(control: *emutls_control) callconv(.C) *anyopaque {...@@ -33,18 +33,14 @@ pub fn __emutls_get_address(control: *emutls_control) callconv(.C) *anyopaque {
33const simple_allocator = struct {33const simple_allocator = struct {
34 /// Allocate a memory chunk for requested type. Return a pointer on the data.34 /// Allocate a memory chunk for requested type. Return a pointer on the data.
35 pub fn alloc(comptime T: type) *T {35 pub fn alloc(comptime T: type) *T {
36 return @ptrCast(*T, @alignCast(36 return @ptrCast(@alignCast(advancedAlloc(@alignOf(T), @sizeOf(T))));
37 @alignOf(T),
38 advancedAlloc(@alignOf(T), @sizeOf(T)),
39 ));
40 }37 }
4138
42 /// Allocate a slice of T, with len elements.39 /// Allocate a slice of T, with len elements.
43 pub fn allocSlice(comptime T: type, len: usize) []T {40 pub fn allocSlice(comptime T: type, len: usize) []T {
44 return @ptrCast([*]T, @alignCast(41 return @as([*]T, @ptrCast(@alignCast(
45 @alignOf(T),
46 advancedAlloc(@alignOf(T), @sizeOf(T) * len),42 advancedAlloc(@alignOf(T), @sizeOf(T) * len),
47 ))[0 .. len - 1];43 )))[0 .. len - 1];
48 }44 }
4945
50 /// Allocate a memory chunk.46 /// Allocate a memory chunk.
...@@ -56,22 +52,19 @@ const simple_allocator = struct {...@@ -56,22 +52,19 @@ const simple_allocator = struct {
56 abort();52 abort();
57 }53 }
5854
59 return @ptrCast([*]u8, aligned_ptr);55 return @as([*]u8, @ptrCast(aligned_ptr));
60 }56 }
6157
62 /// Resize a slice.58 /// Resize a slice.
63 pub fn reallocSlice(comptime T: type, slice: []T, len: usize) []T {59 pub fn reallocSlice(comptime T: type, slice: []T, len: usize) []T {
64 var c_ptr: *anyopaque = @ptrCast(*anyopaque, slice.ptr);60 var c_ptr: *anyopaque = @as(*anyopaque, @ptrCast(slice.ptr));
65 var new_array: [*]T = @ptrCast([*]T, @alignCast(61 var new_array: [*]T = @ptrCast(@alignCast(std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort()));
66 @alignOf(T),
67 std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort(),
68 ));
69 return new_array[0..len];62 return new_array[0..len];
70 }63 }
7164
72 /// Free a memory chunk allocated with simple_allocator.65 /// Free a memory chunk allocated with simple_allocator.
73 pub fn free(ptr: anytype) void {66 pub fn free(ptr: anytype) void {
74 std.c.free(@ptrCast(*anyopaque, ptr));67 std.c.free(@as(*anyopaque, @ptrCast(ptr)));
75 }68 }
76};69};
7770
...@@ -132,20 +125,20 @@ const ObjectArray = struct {...@@ -132,20 +125,20 @@ const ObjectArray = struct {
132 if (self.slots[index] == null) {125 if (self.slots[index] == null) {
133 // initialize the slot126 // initialize the slot
134 const size = control.size;127 const size = control.size;
135 const alignment = @truncate(u29, control.alignment);128 const alignment = @as(u29, @truncate(control.alignment));
136129
137 var data = simple_allocator.advancedAlloc(alignment, size);130 var data = simple_allocator.advancedAlloc(alignment, size);
138 errdefer simple_allocator.free(data);131 errdefer simple_allocator.free(data);
139132
140 if (control.default_value) |value| {133 if (control.default_value) |value| {
141 // default value: copy the content to newly allocated object.134 // default value: copy the content to newly allocated object.
142 @memcpy(data[0..size], @ptrCast([*]const u8, value));135 @memcpy(data[0..size], @as([*]const u8, @ptrCast(value)));
143 } else {136 } else {
144 // no default: return zeroed memory.137 // no default: return zeroed memory.
145 @memset(data[0..size], 0);138 @memset(data[0..size], 0);
146 }139 }
147140
148 self.slots[index] = @ptrCast(*anyopaque, data);141 self.slots[index] = @as(*anyopaque, @ptrCast(data));
149 }142 }
150143
151 return self.slots[index].?;144 return self.slots[index].?;
...@@ -180,18 +173,12 @@ const current_thread_storage = struct {...@@ -180,18 +173,12 @@ const current_thread_storage = struct {
180173
181 /// Return casted thread specific value.174 /// Return casted thread specific value.
182 fn getspecific() ?*ObjectArray {175 fn getspecific() ?*ObjectArray {
183 return @ptrCast(176 return @ptrCast(@alignCast(std.c.pthread_getspecific(current_thread_storage.key)));
184 ?*ObjectArray,
185 @alignCast(
186 @alignOf(ObjectArray),
187 std.c.pthread_getspecific(current_thread_storage.key),
188 ),
189 );
190 }177 }
191178
192 /// Set casted thread specific value.179 /// Set casted thread specific value.
193 fn setspecific(new: ?*ObjectArray) void {180 fn setspecific(new: ?*ObjectArray) void {
194 if (std.c.pthread_setspecific(current_thread_storage.key, @ptrCast(*anyopaque, new)) != 0) {181 if (std.c.pthread_setspecific(current_thread_storage.key, @as(*anyopaque, @ptrCast(new))) != 0) {
195 abort();182 abort();
196 }183 }
197 }184 }
...@@ -205,10 +192,7 @@ const current_thread_storage = struct {...@@ -205,10 +192,7 @@ const current_thread_storage = struct {
205192
206 /// Invoked by pthread specific destructor. the passed argument is the ObjectArray pointer.193 /// Invoked by pthread specific destructor. the passed argument is the ObjectArray pointer.
207 fn deinit(arrayPtr: *anyopaque) callconv(.C) void {194 fn deinit(arrayPtr: *anyopaque) callconv(.C) void {
208 var array = @ptrCast(195 var array: *ObjectArray = @ptrCast(@alignCast(arrayPtr));
209 *ObjectArray,
210 @alignCast(@alignOf(ObjectArray), arrayPtr),
211 );
212 array.deinit();196 array.deinit();
213 }197 }
214};198};
...@@ -294,7 +278,7 @@ const emutls_control = extern struct {...@@ -294,7 +278,7 @@ const emutls_control = extern struct {
294 .size = @sizeOf(T),278 .size = @sizeOf(T),
295 .alignment = @alignOf(T),279 .alignment = @alignOf(T),
296 .object = .{ .index = 0 },280 .object = .{ .index = 0 },
297 .default_value = @ptrCast(?*const anyopaque, default_value),281 .default_value = @as(?*const anyopaque, @ptrCast(default_value)),
298 };282 };
299 }283 }
300284
...@@ -313,10 +297,7 @@ const emutls_control = extern struct {...@@ -313,10 +297,7 @@ const emutls_control = extern struct {
313 pub fn get_typed_pointer(self: *emutls_control, comptime T: type) *T {297 pub fn get_typed_pointer(self: *emutls_control, comptime T: type) *T {
314 assert(self.size == @sizeOf(T));298 assert(self.size == @sizeOf(T));
315 assert(self.alignment == @alignOf(T));299 assert(self.alignment == @alignOf(T));
316 return @ptrCast(300 return @ptrCast(@alignCast(self.getPointer()));
317 *T,
318 @alignCast(@alignOf(T), self.getPointer()),
319 );
320 }301 }
321};302};
322303
...@@ -343,7 +324,7 @@ test "__emutls_get_address zeroed" {...@@ -343,7 +324,7 @@ test "__emutls_get_address zeroed" {
343 try expect(ctl.object.index == 0);324 try expect(ctl.object.index == 0);
344325
345 // retrieve a variable from ctl326 // retrieve a variable from ctl
346 var x = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));327 var x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
347 try expect(ctl.object.index != 0); // index has been allocated for this ctl328 try expect(ctl.object.index != 0); // index has been allocated for this ctl
348 try expect(x.* == 0); // storage has been zeroed329 try expect(x.* == 0); // storage has been zeroed
349330
...@@ -351,7 +332,7 @@ test "__emutls_get_address zeroed" {...@@ -351,7 +332,7 @@ test "__emutls_get_address zeroed" {
351 x.* = 1234;332 x.* = 1234;
352333
353 // retrieve a variable from ctl (same ctl)334 // retrieve a variable from ctl (same ctl)
354 var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));335 var y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
355336
356 try expect(y.* == 1234); // same content that x.*337 try expect(y.* == 1234); // same content that x.*
357 try expect(x == y); // same pointer338 try expect(x == y); // same pointer
...@@ -364,7 +345,7 @@ test "__emutls_get_address with default_value" {...@@ -364,7 +345,7 @@ test "__emutls_get_address with default_value" {
364 var ctl = emutls_control.init(usize, &value);345 var ctl = emutls_control.init(usize, &value);
365 try expect(ctl.object.index == 0);346 try expect(ctl.object.index == 0);
366347
367 var x: *usize = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));348 var x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
368 try expect(ctl.object.index != 0);349 try expect(ctl.object.index != 0);
369 try expect(x.* == 5678); // storage initialized with default value350 try expect(x.* == 5678); // storage initialized with default value
370351
...@@ -373,7 +354,7 @@ test "__emutls_get_address with default_value" {...@@ -373,7 +354,7 @@ test "__emutls_get_address with default_value" {
373354
374 try expect(value == 5678); // the default value didn't change355 try expect(value == 5678); // the default value didn't change
375356
376 var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));357 var y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
377 try expect(y.* == 9012); // the modified storage persists358 try expect(y.* == 9012); // the modified storage persists
378}359}
379360
lib/compiler_rt/exp.zig+11-11
...@@ -27,7 +27,7 @@ comptime {...@@ -27,7 +27,7 @@ comptime {
2727
28pub fn __exph(a: f16) callconv(.C) f16 {28pub fn __exph(a: f16) callconv(.C) f16 {
29 // TODO: more efficient implementation29 // TODO: more efficient implementation
30 return @floatCast(f16, expf(a));30 return @as(f16, @floatCast(expf(a)));
31}31}
3232
33pub fn expf(x_: f32) callconv(.C) f32 {33pub fn expf(x_: f32) callconv(.C) f32 {
...@@ -39,8 +39,8 @@ pub fn expf(x_: f32) callconv(.C) f32 {...@@ -39,8 +39,8 @@ pub fn expf(x_: f32) callconv(.C) f32 {
39 const P2 = -2.7667332906e-3;39 const P2 = -2.7667332906e-3;
4040
41 var x = x_;41 var x = x_;
42 var hx = @bitCast(u32, x);42 var hx = @as(u32, @bitCast(x));
43 const sign = @intCast(i32, hx >> 31);43 const sign = @as(i32, @intCast(hx >> 31));
44 hx &= 0x7FFFFFFF;44 hx &= 0x7FFFFFFF;
4545
46 if (math.isNan(x)) {46 if (math.isNan(x)) {
...@@ -74,12 +74,12 @@ pub fn expf(x_: f32) callconv(.C) f32 {...@@ -74,12 +74,12 @@ pub fn expf(x_: f32) callconv(.C) f32 {
74 if (hx > 0x3EB17218) {74 if (hx > 0x3EB17218) {
75 // |x| > 1.5 * ln275 // |x| > 1.5 * ln2
76 if (hx > 0x3F851592) {76 if (hx > 0x3F851592) {
77 k = @intFromFloat(i32, invln2 * x + half[@intCast(usize, sign)]);77 k = @as(i32, @intFromFloat(invln2 * x + half[@as(usize, @intCast(sign))]));
78 } else {78 } else {
79 k = 1 - sign - sign;79 k = 1 - sign - sign;
80 }80 }
8181
82 const fk = @floatFromInt(f32, k);82 const fk = @as(f32, @floatFromInt(k));
83 hi = x - fk * ln2hi;83 hi = x - fk * ln2hi;
84 lo = fk * ln2lo;84 lo = fk * ln2lo;
85 x = hi - lo;85 x = hi - lo;
...@@ -117,9 +117,9 @@ pub fn exp(x_: f64) callconv(.C) f64 {...@@ -117,9 +117,9 @@ pub fn exp(x_: f64) callconv(.C) f64 {
117 const P5: f64 = 4.13813679705723846039e-08;117 const P5: f64 = 4.13813679705723846039e-08;
118118
119 var x = x_;119 var x = x_;
120 var ux = @bitCast(u64, x);120 var ux = @as(u64, @bitCast(x));
121 var hx = ux >> 32;121 var hx = ux >> 32;
122 const sign = @intCast(i32, hx >> 31);122 const sign = @as(i32, @intCast(hx >> 31));
123 hx &= 0x7FFFFFFF;123 hx &= 0x7FFFFFFF;
124124
125 if (math.isNan(x)) {125 if (math.isNan(x)) {
...@@ -157,12 +157,12 @@ pub fn exp(x_: f64) callconv(.C) f64 {...@@ -157,12 +157,12 @@ pub fn exp(x_: f64) callconv(.C) f64 {
157 if (hx > 0x3FD62E42) {157 if (hx > 0x3FD62E42) {
158 // |x| >= 1.5 * ln2158 // |x| >= 1.5 * ln2
159 if (hx > 0x3FF0A2B2) {159 if (hx > 0x3FF0A2B2) {
160 k = @intFromFloat(i32, invln2 * x + half[@intCast(usize, sign)]);160 k = @as(i32, @intFromFloat(invln2 * x + half[@as(usize, @intCast(sign))]));
161 } else {161 } else {
162 k = 1 - sign - sign;162 k = 1 - sign - sign;
163 }163 }
164164
165 const dk = @floatFromInt(f64, k);165 const dk = @as(f64, @floatFromInt(k));
166 hi = x - dk * ln2hi;166 hi = x - dk * ln2hi;
167 lo = dk * ln2lo;167 lo = dk * ln2lo;
168 x = hi - lo;168 x = hi - lo;
...@@ -191,12 +191,12 @@ pub fn exp(x_: f64) callconv(.C) f64 {...@@ -191,12 +191,12 @@ pub fn exp(x_: f64) callconv(.C) f64 {
191191
192pub fn __expx(a: f80) callconv(.C) f80 {192pub fn __expx(a: f80) callconv(.C) f80 {
193 // TODO: more efficient implementation193 // TODO: more efficient implementation
194 return @floatCast(f80, expq(a));194 return @as(f80, @floatCast(expq(a)));
195}195}
196196
197pub fn expq(a: f128) callconv(.C) f128 {197pub fn expq(a: f128) callconv(.C) f128 {
198 // TODO: more correct implementation198 // TODO: more correct implementation
199 return exp(@floatCast(f64, a));199 return exp(@as(f64, @floatCast(a)));
200}200}
201201
202pub fn expl(x: c_longdouble) callconv(.C) c_longdouble {202pub fn expl(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/exp2.zig+19-19
...@@ -27,18 +27,18 @@ comptime {...@@ -27,18 +27,18 @@ comptime {
2727
28pub fn __exp2h(x: f16) callconv(.C) f16 {28pub fn __exp2h(x: f16) callconv(.C) f16 {
29 // TODO: more efficient implementation29 // TODO: more efficient implementation
30 return @floatCast(f16, exp2f(x));30 return @as(f16, @floatCast(exp2f(x)));
31}31}
3232
33pub fn exp2f(x: f32) callconv(.C) f32 {33pub fn exp2f(x: f32) callconv(.C) f32 {
34 const tblsiz = @intCast(u32, exp2ft.len);34 const tblsiz = @as(u32, @intCast(exp2ft.len));
35 const redux: f32 = 0x1.8p23 / @floatFromInt(f32, tblsiz);35 const redux: f32 = 0x1.8p23 / @as(f32, @floatFromInt(tblsiz));
36 const P1: f32 = 0x1.62e430p-1;36 const P1: f32 = 0x1.62e430p-1;
37 const P2: f32 = 0x1.ebfbe0p-3;37 const P2: f32 = 0x1.ebfbe0p-3;
38 const P3: f32 = 0x1.c6b348p-5;38 const P3: f32 = 0x1.c6b348p-5;
39 const P4: f32 = 0x1.3b2c9cp-7;39 const P4: f32 = 0x1.3b2c9cp-7;
4040
41 var u = @bitCast(u32, x);41 var u = @as(u32, @bitCast(x));
42 const ix = u & 0x7FFFFFFF;42 const ix = u & 0x7FFFFFFF;
4343
44 // |x| > 12644 // |x| > 126
...@@ -72,32 +72,32 @@ pub fn exp2f(x: f32) callconv(.C) f32 {...@@ -72,32 +72,32 @@ pub fn exp2f(x: f32) callconv(.C) f32 {
72 // intended result but should confirm how GCC/Clang handle this to ensure.72 // intended result but should confirm how GCC/Clang handle this to ensure.
7373
74 var uf = x + redux;74 var uf = x + redux;
75 var i_0 = @bitCast(u32, uf);75 var i_0 = @as(u32, @bitCast(uf));
76 i_0 +%= tblsiz / 2;76 i_0 +%= tblsiz / 2;
7777
78 const k = i_0 / tblsiz;78 const k = i_0 / tblsiz;
79 const uk = @bitCast(f64, @as(u64, 0x3FF + k) << 52);79 const uk = @as(f64, @bitCast(@as(u64, 0x3FF + k) << 52));
80 i_0 &= tblsiz - 1;80 i_0 &= tblsiz - 1;
81 uf -= redux;81 uf -= redux;
8282
83 const z: f64 = x - uf;83 const z: f64 = x - uf;
84 var r: f64 = exp2ft[@intCast(usize, i_0)];84 var r: f64 = exp2ft[@as(usize, @intCast(i_0))];
85 const t: f64 = r * z;85 const t: f64 = r * z;
86 r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4);86 r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4);
87 return @floatCast(f32, r * uk);87 return @as(f32, @floatCast(r * uk));
88}88}
8989
90pub fn exp2(x: f64) callconv(.C) f64 {90pub fn exp2(x: f64) callconv(.C) f64 {
91 const tblsiz: u32 = @intCast(u32, exp2dt.len / 2);91 const tblsiz: u32 = @as(u32, @intCast(exp2dt.len / 2));
92 const redux: f64 = 0x1.8p52 / @floatFromInt(f64, tblsiz);92 const redux: f64 = 0x1.8p52 / @as(f64, @floatFromInt(tblsiz));
93 const P1: f64 = 0x1.62e42fefa39efp-1;93 const P1: f64 = 0x1.62e42fefa39efp-1;
94 const P2: f64 = 0x1.ebfbdff82c575p-3;94 const P2: f64 = 0x1.ebfbdff82c575p-3;
95 const P3: f64 = 0x1.c6b08d704a0a6p-5;95 const P3: f64 = 0x1.c6b08d704a0a6p-5;
96 const P4: f64 = 0x1.3b2ab88f70400p-7;96 const P4: f64 = 0x1.3b2ab88f70400p-7;
97 const P5: f64 = 0x1.5d88003875c74p-10;97 const P5: f64 = 0x1.5d88003875c74p-10;
9898
99 const ux = @bitCast(u64, x);99 const ux = @as(u64, @bitCast(x));
100 const ix = @intCast(u32, ux >> 32) & 0x7FFFFFFF;100 const ix = @as(u32, @intCast(ux >> 32)) & 0x7FFFFFFF;
101101
102 // TODO: This should be handled beneath.102 // TODO: This should be handled beneath.
103 if (math.isNan(x)) {103 if (math.isNan(x)) {
...@@ -119,7 +119,7 @@ pub fn exp2(x: f64) callconv(.C) f64 {...@@ -119,7 +119,7 @@ pub fn exp2(x: f64) callconv(.C) f64 {
119 if (ux >> 63 != 0) {119 if (ux >> 63 != 0) {
120 // underflow120 // underflow
121 if (x <= -1075 or x - 0x1.0p52 + 0x1.0p52 != x) {121 if (x <= -1075 or x - 0x1.0p52 + 0x1.0p52 != x) {
122 math.doNotOptimizeAway(@floatCast(f32, -0x1.0p-149 / x));122 math.doNotOptimizeAway(@as(f32, @floatCast(-0x1.0p-149 / x)));
123 }123 }
124 if (x <= -1075) {124 if (x <= -1075) {
125 return 0;125 return 0;
...@@ -139,18 +139,18 @@ pub fn exp2(x: f64) callconv(.C) f64 {...@@ -139,18 +139,18 @@ pub fn exp2(x: f64) callconv(.C) f64 {
139 // reduce x139 // reduce x
140 var uf: f64 = x + redux;140 var uf: f64 = x + redux;
141 // NOTE: musl performs an implicit 64-bit to 32-bit u32 truncation here141 // NOTE: musl performs an implicit 64-bit to 32-bit u32 truncation here
142 var i_0: u32 = @truncate(u32, @bitCast(u64, uf));142 var i_0: u32 = @as(u32, @truncate(@as(u64, @bitCast(uf))));
143 i_0 +%= tblsiz / 2;143 i_0 +%= tblsiz / 2;
144144
145 const k: u32 = i_0 / tblsiz * tblsiz;145 const k: u32 = i_0 / tblsiz * tblsiz;
146 const ik: i32 = @divTrunc(@bitCast(i32, k), tblsiz);146 const ik: i32 = @divTrunc(@as(i32, @bitCast(k)), tblsiz);
147 i_0 %= tblsiz;147 i_0 %= tblsiz;
148 uf -= redux;148 uf -= redux;
149149
150 // r = exp2(y) = exp2t[i_0] * p(z - eps[i])150 // r = exp2(y) = exp2t[i_0] * p(z - eps[i])
151 var z: f64 = x - uf;151 var z: f64 = x - uf;
152 const t: f64 = exp2dt[@intCast(usize, 2 * i_0)];152 const t: f64 = exp2dt[@as(usize, @intCast(2 * i_0))];
153 z -= exp2dt[@intCast(usize, 2 * i_0 + 1)];153 z -= exp2dt[@as(usize, @intCast(2 * i_0 + 1))];
154 const r: f64 = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5))));154 const r: f64 = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5))));
155155
156 return math.scalbn(r, ik);156 return math.scalbn(r, ik);
...@@ -158,12 +158,12 @@ pub fn exp2(x: f64) callconv(.C) f64 {...@@ -158,12 +158,12 @@ pub fn exp2(x: f64) callconv(.C) f64 {
158158
159pub fn __exp2x(x: f80) callconv(.C) f80 {159pub fn __exp2x(x: f80) callconv(.C) f80 {
160 // TODO: more efficient implementation160 // TODO: more efficient implementation
161 return @floatCast(f80, exp2q(x));161 return @as(f80, @floatCast(exp2q(x)));
162}162}
163163
164pub fn exp2q(x: f128) callconv(.C) f128 {164pub fn exp2q(x: f128) callconv(.C) f128 {
165 // TODO: more correct implementation165 // TODO: more correct implementation
166 return exp2(@floatCast(f64, x));166 return exp2(@as(f64, @floatCast(x)));
167}167}
168168
169pub fn exp2l(x: c_longdouble) callconv(.C) c_longdouble {169pub fn exp2l(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/extenddftf2.zig+2-2
...@@ -13,9 +13,9 @@ comptime {...@@ -13,9 +13,9 @@ comptime {
13}13}
1414
15pub fn __extenddftf2(a: f64) callconv(.C) f128 {15pub fn __extenddftf2(a: f64) callconv(.C) f128 {
16 return extendf(f128, f64, @bitCast(u64, a));16 return extendf(f128, f64, @as(u64, @bitCast(a)));
17}17}
1818
19fn _Qp_dtoq(c: *f128, a: f64) callconv(.C) void {19fn _Qp_dtoq(c: *f128, a: f64) callconv(.C) void {
20 c.* = extendf(f128, f64, @bitCast(u64, a));20 c.* = extendf(f128, f64, @as(u64, @bitCast(a)));
21}21}
lib/compiler_rt/extenddfxf2.zig+1-1
...@@ -8,5 +8,5 @@ comptime {...@@ -8,5 +8,5 @@ comptime {
8}8}
99
10pub fn __extenddfxf2(a: f64) callconv(.C) f80 {10pub fn __extenddfxf2(a: f64) callconv(.C) f80 {
11 return extend_f80(f64, @bitCast(u64, a));11 return extend_f80(f64, @as(u64, @bitCast(a)));
12}12}
lib/compiler_rt/extendf.zig+7-7
...@@ -33,7 +33,7 @@ pub inline fn extendf(...@@ -33,7 +33,7 @@ pub inline fn extendf(
33 const dstMinNormal: dst_rep_t = @as(dst_rep_t, 1) << dstSigBits;33 const dstMinNormal: dst_rep_t = @as(dst_rep_t, 1) << dstSigBits;
3434
35 // Break a into a sign and representation of the absolute value35 // Break a into a sign and representation of the absolute value
36 const aRep: src_rep_t = @bitCast(src_rep_t, a);36 const aRep: src_rep_t = @as(src_rep_t, @bitCast(a));
37 const aAbs: src_rep_t = aRep & srcAbsMask;37 const aAbs: src_rep_t = aRep & srcAbsMask;
38 const sign: src_rep_t = aRep & srcSignMask;38 const sign: src_rep_t = aRep & srcSignMask;
39 var absResult: dst_rep_t = undefined;39 var absResult: dst_rep_t = undefined;
...@@ -58,10 +58,10 @@ pub inline fn extendf(...@@ -58,10 +58,10 @@ pub inline fn extendf(
58 // the correct adjusted exponent in the destination type.58 // the correct adjusted exponent in the destination type.
59 const scale: u32 = @clz(aAbs) -59 const scale: u32 = @clz(aAbs) -
60 @clz(@as(src_rep_t, srcMinNormal));60 @clz(@as(src_rep_t, srcMinNormal));
61 absResult = @as(dst_rep_t, aAbs) << @intCast(DstShift, dstSigBits - srcSigBits + scale);61 absResult = @as(dst_rep_t, aAbs) << @as(DstShift, @intCast(dstSigBits - srcSigBits + scale));
62 absResult ^= dstMinNormal;62 absResult ^= dstMinNormal;
63 const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1;63 const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1;
64 absResult |= @intCast(dst_rep_t, resultExponent) << dstSigBits;64 absResult |= @as(dst_rep_t, @intCast(resultExponent)) << dstSigBits;
65 } else {65 } else {
66 // a is zero.66 // a is zero.
67 absResult = 0;67 absResult = 0;
...@@ -69,7 +69,7 @@ pub inline fn extendf(...@@ -69,7 +69,7 @@ pub inline fn extendf(
6969
70 // Apply the signbit to (dst_t)abs(a).70 // Apply the signbit to (dst_t)abs(a).
71 const result: dst_rep_t align(@alignOf(dst_t)) = absResult | @as(dst_rep_t, sign) << (dstBits - srcBits);71 const result: dst_rep_t align(@alignOf(dst_t)) = absResult | @as(dst_rep_t, sign) << (dstBits - srcBits);
72 return @bitCast(dst_t, result);72 return @as(dst_t, @bitCast(result));
73}73}
7474
75pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeInfo(src_t).Float.bits)) f80 {75pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeInfo(src_t).Float.bits)) f80 {
...@@ -104,7 +104,7 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI...@@ -104,7 +104,7 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI
104 // a is a normal number.104 // a is a normal number.
105 // Extend to the destination type by shifting the significand and105 // Extend to the destination type by shifting the significand and
106 // exponent into the proper position and rebiasing the exponent.106 // exponent into the proper position and rebiasing the exponent.
107 dst.exp = @intCast(u16, a_abs >> src_sig_bits);107 dst.exp = @as(u16, @intCast(a_abs >> src_sig_bits));
108 dst.exp += dst_exp_bias - src_exp_bias;108 dst.exp += dst_exp_bias - src_exp_bias;
109 dst.fraction = @as(u64, a_abs) << (dst_sig_bits - src_sig_bits);109 dst.fraction = @as(u64, a_abs) << (dst_sig_bits - src_sig_bits);
110 dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers110 dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers
...@@ -124,9 +124,9 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI...@@ -124,9 +124,9 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI
124 const scale: u16 = @clz(a_abs) -124 const scale: u16 = @clz(a_abs) -
125 @clz(@as(src_rep_t, src_min_normal));125 @clz(@as(src_rep_t, src_min_normal));
126126
127 dst.fraction = @as(u64, a_abs) << @intCast(u6, dst_sig_bits - src_sig_bits + scale);127 dst.fraction = @as(u64, a_abs) << @as(u6, @intCast(dst_sig_bits - src_sig_bits + scale));
128 dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers128 dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers
129 dst.exp = @truncate(u16, a_abs >> @intCast(SrcShift, src_sig_bits - scale));129 dst.exp = @as(u16, @truncate(a_abs >> @as(SrcShift, @intCast(src_sig_bits - scale))));
130 dst.exp ^= 1;130 dst.exp ^= 1;
131 dst.exp |= dst_exp_bias - src_exp_bias - scale + 1;131 dst.exp |= dst_exp_bias - src_exp_bias - scale + 1;
132 } else {132 } else {
lib/compiler_rt/extendf_test.zig+21-21
...@@ -11,12 +11,12 @@ const F16T = @import("./common.zig").F16T;...@@ -11,12 +11,12 @@ const F16T = @import("./common.zig").F16T;
11fn test__extenddfxf2(a: f64, expected: u80) !void {11fn test__extenddfxf2(a: f64, expected: u80) !void {
12 const x = __extenddfxf2(a);12 const x = __extenddfxf2(a);
1313
14 const rep = @bitCast(u80, x);14 const rep = @as(u80, @bitCast(x));
15 if (rep == expected)15 if (rep == expected)
16 return;16 return;
1717
18 // test other possible NaN representation(signal NaN)18 // test other possible NaN representation(signal NaN)
19 if (math.isNan(@bitCast(f80, expected)) and math.isNan(x))19 if (math.isNan(@as(f80, @bitCast(expected))) and math.isNan(x))
20 return;20 return;
2121
22 @panic("__extenddfxf2 test failure");22 @panic("__extenddfxf2 test failure");
...@@ -25,9 +25,9 @@ fn test__extenddfxf2(a: f64, expected: u80) !void {...@@ -25,9 +25,9 @@ fn test__extenddfxf2(a: f64, expected: u80) !void {
25fn test__extenddftf2(a: f64, expected_hi: u64, expected_lo: u64) !void {25fn test__extenddftf2(a: f64, expected_hi: u64, expected_lo: u64) !void {
26 const x = __extenddftf2(a);26 const x = __extenddftf2(a);
2727
28 const rep = @bitCast(u128, x);28 const rep = @as(u128, @bitCast(x));
29 const hi = @intCast(u64, rep >> 64);29 const hi = @as(u64, @intCast(rep >> 64));
30 const lo = @truncate(u64, rep);30 const lo = @as(u64, @truncate(rep));
3131
32 if (hi == expected_hi and lo == expected_lo)32 if (hi == expected_hi and lo == expected_lo)
33 return;33 return;
...@@ -45,14 +45,14 @@ fn test__extenddftf2(a: f64, expected_hi: u64, expected_lo: u64) !void {...@@ -45,14 +45,14 @@ fn test__extenddftf2(a: f64, expected_hi: u64, expected_lo: u64) !void {
45}45}
4646
47fn test__extendhfsf2(a: u16, expected: u32) !void {47fn test__extendhfsf2(a: u16, expected: u32) !void {
48 const x = __extendhfsf2(@bitCast(F16T(f32), a));48 const x = __extendhfsf2(@as(F16T(f32), @bitCast(a)));
49 const rep = @bitCast(u32, x);49 const rep = @as(u32, @bitCast(x));
5050
51 if (rep == expected) {51 if (rep == expected) {
52 if (rep & 0x7fffffff > 0x7f800000) {52 if (rep & 0x7fffffff > 0x7f800000) {
53 return; // NaN is always unequal.53 return; // NaN is always unequal.
54 }54 }
55 if (x == @bitCast(f32, expected)) {55 if (x == @as(f32, @bitCast(expected))) {
56 return;56 return;
57 }57 }
58 }58 }
...@@ -63,9 +63,9 @@ fn test__extendhfsf2(a: u16, expected: u32) !void {...@@ -63,9 +63,9 @@ fn test__extendhfsf2(a: u16, expected: u32) !void {
63fn test__extendsftf2(a: f32, expected_hi: u64, expected_lo: u64) !void {63fn test__extendsftf2(a: f32, expected_hi: u64, expected_lo: u64) !void {
64 const x = __extendsftf2(a);64 const x = __extendsftf2(a);
6565
66 const rep = @bitCast(u128, x);66 const rep = @as(u128, @bitCast(x));
67 const hi = @intCast(u64, rep >> 64);67 const hi = @as(u64, @intCast(rep >> 64));
68 const lo = @truncate(u64, rep);68 const lo = @as(u64, @truncate(rep));
6969
70 if (hi == expected_hi and lo == expected_lo)70 if (hi == expected_hi and lo == expected_lo)
71 return;71 return;
...@@ -184,35 +184,35 @@ test "extendsftf2" {...@@ -184,35 +184,35 @@ test "extendsftf2" {
184}184}
185185
186fn makeQNaN64() f64 {186fn makeQNaN64() f64 {
187 return @bitCast(f64, @as(u64, 0x7ff8000000000000));187 return @as(f64, @bitCast(@as(u64, 0x7ff8000000000000)));
188}188}
189189
190fn makeInf64() f64 {190fn makeInf64() f64 {
191 return @bitCast(f64, @as(u64, 0x7ff0000000000000));191 return @as(f64, @bitCast(@as(u64, 0x7ff0000000000000)));
192}192}
193193
194fn makeNaN64(rand: u64) f64 {194fn makeNaN64(rand: u64) f64 {
195 return @bitCast(f64, 0x7ff0000000000000 | (rand & 0xfffffffffffff));195 return @as(f64, @bitCast(0x7ff0000000000000 | (rand & 0xfffffffffffff)));
196}196}
197197
198fn makeQNaN32() f32 {198fn makeQNaN32() f32 {
199 return @bitCast(f32, @as(u32, 0x7fc00000));199 return @as(f32, @bitCast(@as(u32, 0x7fc00000)));
200}200}
201201
202fn makeNaN32(rand: u32) f32 {202fn makeNaN32(rand: u32) f32 {
203 return @bitCast(f32, 0x7f800000 | (rand & 0x7fffff));203 return @as(f32, @bitCast(0x7f800000 | (rand & 0x7fffff)));
204}204}
205205
206fn makeInf32() f32 {206fn makeInf32() f32 {
207 return @bitCast(f32, @as(u32, 0x7f800000));207 return @as(f32, @bitCast(@as(u32, 0x7f800000)));
208}208}
209209
210fn test__extendhftf2(a: u16, expected_hi: u64, expected_lo: u64) !void {210fn test__extendhftf2(a: u16, expected_hi: u64, expected_lo: u64) !void {
211 const x = __extendhftf2(@bitCast(F16T(f128), a));211 const x = __extendhftf2(@as(F16T(f128), @bitCast(a)));
212212
213 const rep = @bitCast(u128, x);213 const rep = @as(u128, @bitCast(x));
214 const hi = @intCast(u64, rep >> 64);214 const hi = @as(u64, @intCast(rep >> 64));
215 const lo = @truncate(u64, rep);215 const lo = @as(u64, @truncate(rep));
216216
217 if (hi == expected_hi and lo == expected_lo)217 if (hi == expected_hi and lo == expected_lo)
218 return;218 return;
lib/compiler_rt/extendhfdf2.zig+1-1
...@@ -8,5 +8,5 @@ comptime {...@@ -8,5 +8,5 @@ comptime {
8}8}
99
10pub fn __extendhfdf2(a: common.F16T(f64)) callconv(.C) f64 {10pub fn __extendhfdf2(a: common.F16T(f64)) callconv(.C) f64 {
11 return extendf(f64, f16, @bitCast(u16, a));11 return extendf(f64, f16, @as(u16, @bitCast(a)));
12}12}
lib/compiler_rt/extendhfsf2.zig+3-3
...@@ -13,13 +13,13 @@ comptime {...@@ -13,13 +13,13 @@ comptime {
13}13}
1414
15pub fn __extendhfsf2(a: common.F16T(f32)) callconv(.C) f32 {15pub fn __extendhfsf2(a: common.F16T(f32)) callconv(.C) f32 {
16 return extendf(f32, f16, @bitCast(u16, a));16 return extendf(f32, f16, @as(u16, @bitCast(a)));
17}17}
1818
19fn __gnu_h2f_ieee(a: common.F16T(f32)) callconv(.C) f32 {19fn __gnu_h2f_ieee(a: common.F16T(f32)) callconv(.C) f32 {
20 return extendf(f32, f16, @bitCast(u16, a));20 return extendf(f32, f16, @as(u16, @bitCast(a)));
21}21}
2222
23fn __aeabi_h2f(a: u16) callconv(.AAPCS) f32 {23fn __aeabi_h2f(a: u16) callconv(.AAPCS) f32 {
24 return extendf(f32, f16, @bitCast(u16, a));24 return extendf(f32, f16, @as(u16, @bitCast(a)));
25}25}
lib/compiler_rt/extendhftf2.zig+1-1
...@@ -8,5 +8,5 @@ comptime {...@@ -8,5 +8,5 @@ comptime {
8}8}
99
10pub fn __extendhftf2(a: common.F16T(f128)) callconv(.C) f128 {10pub fn __extendhftf2(a: common.F16T(f128)) callconv(.C) f128 {
11 return extendf(f128, f16, @bitCast(u16, a));11 return extendf(f128, f16, @as(u16, @bitCast(a)));
12}12}
lib/compiler_rt/extendhfxf2.zig+1-1
...@@ -8,5 +8,5 @@ comptime {...@@ -8,5 +8,5 @@ comptime {
8}8}
99
10fn __extendhfxf2(a: common.F16T(f80)) callconv(.C) f80 {10fn __extendhfxf2(a: common.F16T(f80)) callconv(.C) f80 {
11 return extend_f80(f16, @bitCast(u16, a));11 return extend_f80(f16, @as(u16, @bitCast(a)));
12}12}
lib/compiler_rt/extendsfdf2.zig+2-2
...@@ -12,9 +12,9 @@ comptime {...@@ -12,9 +12,9 @@ comptime {
12}12}
1313
14fn __extendsfdf2(a: f32) callconv(.C) f64 {14fn __extendsfdf2(a: f32) callconv(.C) f64 {
15 return extendf(f64, f32, @bitCast(u32, a));15 return extendf(f64, f32, @as(u32, @bitCast(a)));
16}16}
1717
18fn __aeabi_f2d(a: f32) callconv(.AAPCS) f64 {18fn __aeabi_f2d(a: f32) callconv(.AAPCS) f64 {
19 return extendf(f64, f32, @bitCast(u32, a));19 return extendf(f64, f32, @as(u32, @bitCast(a)));
20}20}
lib/compiler_rt/extendsftf2.zig+2-2
...@@ -13,9 +13,9 @@ comptime {...@@ -13,9 +13,9 @@ comptime {
13}13}
1414
15pub fn __extendsftf2(a: f32) callconv(.C) f128 {15pub fn __extendsftf2(a: f32) callconv(.C) f128 {
16 return extendf(f128, f32, @bitCast(u32, a));16 return extendf(f128, f32, @as(u32, @bitCast(a)));
17}17}
1818
19fn _Qp_stoq(c: *f128, a: f32) callconv(.C) void {19fn _Qp_stoq(c: *f128, a: f32) callconv(.C) void {
20 c.* = extendf(f128, f32, @bitCast(u32, a));20 c.* = extendf(f128, f32, @as(u32, @bitCast(a)));
21}21}
lib/compiler_rt/extendsfxf2.zig+1-1
...@@ -8,5 +8,5 @@ comptime {...@@ -8,5 +8,5 @@ comptime {
8}8}
99
10fn __extendsfxf2(a: f32) callconv(.C) f80 {10fn __extendsfxf2(a: f32) callconv(.C) f80 {
11 return extend_f80(f32, @bitCast(u32, a));11 return extend_f80(f32, @as(u32, @bitCast(a)));
12}12}
lib/compiler_rt/extendxftf2.zig+2-2
...@@ -39,12 +39,12 @@ fn __extendxftf2(a: f80) callconv(.C) f128 {...@@ -39,12 +39,12 @@ fn __extendxftf2(a: f80) callconv(.C) f128 {
39 // renormalize the significand and clear the leading bit and integer part,39 // renormalize the significand and clear the leading bit and integer part,
40 // then insert the correct adjusted exponent in the destination type.40 // then insert the correct adjusted exponent in the destination type.
41 const scale: u32 = @clz(a_rep.fraction);41 const scale: u32 = @clz(a_rep.fraction);
42 abs_result = @as(u128, a_rep.fraction) << @intCast(u7, dst_sig_bits - src_sig_bits + scale + 1);42 abs_result = @as(u128, a_rep.fraction) << @as(u7, @intCast(dst_sig_bits - src_sig_bits + scale + 1));
43 abs_result ^= dst_min_normal;43 abs_result ^= dst_min_normal;
44 abs_result |= @as(u128, scale + 1) << dst_sig_bits;44 abs_result |= @as(u128, scale + 1) << dst_sig_bits;
45 }45 }
4646
47 // Apply the signbit to (dst_t)abs(a).47 // Apply the signbit to (dst_t)abs(a).
48 const result: u128 align(@alignOf(f128)) = abs_result | @as(u128, sign) << (dst_bits - 16);48 const result: u128 align(@alignOf(f128)) = abs_result | @as(u128, sign) << (dst_bits - 16);
49 return @bitCast(f128, result);49 return @as(f128, @bitCast(result));
50}50}
lib/compiler_rt/fabs.zig+2-2
...@@ -51,7 +51,7 @@ pub fn fabsl(x: c_longdouble) callconv(.C) c_longdouble {...@@ -51,7 +51,7 @@ pub fn fabsl(x: c_longdouble) callconv(.C) c_longdouble {
51inline fn generic_fabs(x: anytype) @TypeOf(x) {51inline fn generic_fabs(x: anytype) @TypeOf(x) {
52 const T = @TypeOf(x);52 const T = @TypeOf(x);
53 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);53 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
54 const float_bits = @bitCast(TBits, x);54 const float_bits = @as(TBits, @bitCast(x));
55 const remove_sign = ~@as(TBits, 0) >> 1;55 const remove_sign = ~@as(TBits, 0) >> 1;
56 return @bitCast(T, float_bits & remove_sign);56 return @as(T, @bitCast(float_bits & remove_sign));
57}57}
lib/compiler_rt/ffsdi2_test.zig+1-1
...@@ -2,7 +2,7 @@ const ffs = @import("count0bits.zig");...@@ -2,7 +2,7 @@ const ffs = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ffsdi2(a: u64, expected: i32) !void {4fn test__ffsdi2(a: u64, expected: i32) !void {
5 var x = @bitCast(i64, a);5 var x = @as(i64, @bitCast(a));
6 var result = ffs.__ffsdi2(x);6 var result = ffs.__ffsdi2(x);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
lib/compiler_rt/ffssi2_test.zig+1-1
...@@ -2,7 +2,7 @@ const ffs = @import("count0bits.zig");...@@ -2,7 +2,7 @@ const ffs = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ffssi2(a: u32, expected: i32) !void {4fn test__ffssi2(a: u32, expected: i32) !void {
5 var x = @bitCast(i32, a);5 var x = @as(i32, @bitCast(a));
6 var result = ffs.__ffssi2(x);6 var result = ffs.__ffssi2(x);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
lib/compiler_rt/ffsti2_test.zig+1-1
...@@ -2,7 +2,7 @@ const ffs = @import("count0bits.zig");...@@ -2,7 +2,7 @@ const ffs = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ffsti2(a: u128, expected: i32) !void {4fn test__ffsti2(a: u128, expected: i32) !void {
5 var x = @bitCast(i128, a);5 var x = @as(i128, @bitCast(a));
6 var result = ffs.__ffsti2(x);6 var result = ffs.__ffsti2(x);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
lib/compiler_rt/fixdfti.zig+1-1
...@@ -19,5 +19,5 @@ pub fn __fixdfti(a: f64) callconv(.C) i128 {...@@ -19,5 +19,5 @@ pub fn __fixdfti(a: f64) callconv(.C) i128 {
19const v2u64 = @Vector(2, u64);19const v2u64 = @Vector(2, u64);
2020
21fn __fixdfti_windows_x86_64(a: f64) callconv(.C) v2u64 {21fn __fixdfti_windows_x86_64(a: f64) callconv(.C) v2u64 {
22 return @bitCast(v2u64, intFromFloat(i128, a));22 return @as(v2u64, @bitCast(intFromFloat(i128, a)));
23}23}
lib/compiler_rt/fixhfti.zig+1-1
...@@ -19,5 +19,5 @@ pub fn __fixhfti(a: f16) callconv(.C) i128 {...@@ -19,5 +19,5 @@ pub fn __fixhfti(a: f16) callconv(.C) i128 {
19const v2u64 = @Vector(2, u64);19const v2u64 = @Vector(2, u64);
2020
21fn __fixhfti_windows_x86_64(a: f16) callconv(.C) v2u64 {21fn __fixhfti_windows_x86_64(a: f16) callconv(.C) v2u64 {
22 return @bitCast(v2u64, intFromFloat(i128, a));22 return @as(v2u64, @bitCast(intFromFloat(i128, a)));
23}23}
lib/compiler_rt/fixsfti.zig+1-1
...@@ -19,5 +19,5 @@ pub fn __fixsfti(a: f32) callconv(.C) i128 {...@@ -19,5 +19,5 @@ pub fn __fixsfti(a: f32) callconv(.C) i128 {
19const v2u64 = @Vector(2, u64);19const v2u64 = @Vector(2, u64);
2020
21fn __fixsfti_windows_x86_64(a: f32) callconv(.C) v2u64 {21fn __fixsfti_windows_x86_64(a: f32) callconv(.C) v2u64 {
22 return @bitCast(v2u64, intFromFloat(i128, a));22 return @as(v2u64, @bitCast(intFromFloat(i128, a)));
23}23}
lib/compiler_rt/fixtfti.zig+1-1
...@@ -21,5 +21,5 @@ pub fn __fixtfti(a: f128) callconv(.C) i128 {...@@ -21,5 +21,5 @@ pub fn __fixtfti(a: f128) callconv(.C) i128 {
21const v2u64 = @Vector(2, u64);21const v2u64 = @Vector(2, u64);
2222
23fn __fixtfti_windows_x86_64(a: f128) callconv(.C) v2u64 {23fn __fixtfti_windows_x86_64(a: f128) callconv(.C) v2u64 {
24 return @bitCast(v2u64, intFromFloat(i128, a));24 return @as(v2u64, @bitCast(intFromFloat(i128, a)));
25}25}
lib/compiler_rt/fixunsdfti.zig+1-1
...@@ -19,5 +19,5 @@ pub fn __fixunsdfti(a: f64) callconv(.C) u128 {...@@ -19,5 +19,5 @@ pub fn __fixunsdfti(a: f64) callconv(.C) u128 {
19const v2u64 = @Vector(2, u64);19const v2u64 = @Vector(2, u64);
2020
21fn __fixunsdfti_windows_x86_64(a: f64) callconv(.C) v2u64 {21fn __fixunsdfti_windows_x86_64(a: f64) callconv(.C) v2u64 {
22 return @bitCast(v2u64, intFromFloat(u128, a));22 return @as(v2u64, @bitCast(intFromFloat(u128, a)));
23}23}
lib/compiler_rt/fixunshfti.zig+1-1
...@@ -19,5 +19,5 @@ pub fn __fixunshfti(a: f16) callconv(.C) u128 {...@@ -19,5 +19,5 @@ pub fn __fixunshfti(a: f16) callconv(.C) u128 {
19const v2u64 = @Vector(2, u64);19const v2u64 = @Vector(2, u64);
2020
21fn __fixunshfti_windows_x86_64(a: f16) callconv(.C) v2u64 {21fn __fixunshfti_windows_x86_64(a: f16) callconv(.C) v2u64 {
22 return @bitCast(v2u64, intFromFloat(u128, a));22 return @as(v2u64, @bitCast(intFromFloat(u128, a)));
23}23}
lib/compiler_rt/fixunssfti.zig+1-1
...@@ -19,5 +19,5 @@ pub fn __fixunssfti(a: f32) callconv(.C) u128 {...@@ -19,5 +19,5 @@ pub fn __fixunssfti(a: f32) callconv(.C) u128 {
19const v2u64 = @Vector(2, u64);19const v2u64 = @Vector(2, u64);
2020
21fn __fixunssfti_windows_x86_64(a: f32) callconv(.C) v2u64 {21fn __fixunssfti_windows_x86_64(a: f32) callconv(.C) v2u64 {
22 return @bitCast(v2u64, intFromFloat(u128, a));22 return @as(v2u64, @bitCast(intFromFloat(u128, a)));
23}23}
lib/compiler_rt/fixunstfti.zig+1-1
...@@ -21,5 +21,5 @@ pub fn __fixunstfti(a: f128) callconv(.C) u128 {...@@ -21,5 +21,5 @@ pub fn __fixunstfti(a: f128) callconv(.C) u128 {
21const v2u64 = @Vector(2, u64);21const v2u64 = @Vector(2, u64);
2222
23fn __fixunstfti_windows_x86_64(a: f128) callconv(.C) v2u64 {23fn __fixunstfti_windows_x86_64(a: f128) callconv(.C) v2u64 {
24 return @bitCast(v2u64, intFromFloat(u128, a));24 return @as(v2u64, @bitCast(intFromFloat(u128, a)));
25}25}
lib/compiler_rt/fixunsxfti.zig+1-1
...@@ -19,5 +19,5 @@ pub fn __fixunsxfti(a: f80) callconv(.C) u128 {...@@ -19,5 +19,5 @@ pub fn __fixunsxfti(a: f80) callconv(.C) u128 {
19const v2u64 = @Vector(2, u64);19const v2u64 = @Vector(2, u64);
2020
21fn __fixunsxfti_windows_x86_64(a: f80) callconv(.C) v2u64 {21fn __fixunsxfti_windows_x86_64(a: f80) callconv(.C) v2u64 {
22 return @bitCast(v2u64, intFromFloat(u128, a));22 return @as(v2u64, @bitCast(intFromFloat(u128, a)));
23}23}
lib/compiler_rt/fixxfti.zig+1-1
...@@ -19,5 +19,5 @@ pub fn __fixxfti(a: f80) callconv(.C) i128 {...@@ -19,5 +19,5 @@ pub fn __fixxfti(a: f80) callconv(.C) i128 {
19const v2u64 = @Vector(2, u64);19const v2u64 = @Vector(2, u64);
2020
21fn __fixxfti_windows_x86_64(a: f80) callconv(.C) v2u64 {21fn __fixxfti_windows_x86_64(a: f80) callconv(.C) v2u64 {
22 return @bitCast(v2u64, intFromFloat(i128, a));22 return @as(v2u64, @bitCast(intFromFloat(i128, a)));
23}23}
lib/compiler_rt/float_from_int.zig+6-6
...@@ -25,17 +25,17 @@ pub fn floatFromInt(comptime T: type, x: anytype) T {...@@ -25,17 +25,17 @@ pub fn floatFromInt(comptime T: type, x: anytype) T {
25 // Compute significand25 // Compute significand
26 var exp = int_bits - @clz(abs_val) - 1;26 var exp = int_bits - @clz(abs_val) - 1;
27 if (int_bits <= fractional_bits or exp <= fractional_bits) {27 if (int_bits <= fractional_bits or exp <= fractional_bits) {
28 const shift_amt = fractional_bits - @intCast(math.Log2Int(uT), exp);28 const shift_amt = fractional_bits - @as(math.Log2Int(uT), @intCast(exp));
2929
30 // Shift up result to line up with the significand - no rounding required30 // Shift up result to line up with the significand - no rounding required
31 result = (@intCast(uT, abs_val) << shift_amt);31 result = (@as(uT, @intCast(abs_val)) << shift_amt);
32 result ^= implicit_bit; // Remove implicit integer bit32 result ^= implicit_bit; // Remove implicit integer bit
33 } else {33 } else {
34 var shift_amt = @intCast(math.Log2Int(Z), exp - fractional_bits);34 var shift_amt = @as(math.Log2Int(Z), @intCast(exp - fractional_bits));
35 const exact_tie: bool = @ctz(abs_val) == shift_amt - 1;35 const exact_tie: bool = @ctz(abs_val) == shift_amt - 1;
3636
37 // Shift down result and remove implicit integer bit37 // Shift down result and remove implicit integer bit
38 result = @intCast(uT, (abs_val >> (shift_amt - 1))) ^ (implicit_bit << 1);38 result = @as(uT, @intCast((abs_val >> (shift_amt - 1)))) ^ (implicit_bit << 1);
3939
40 // Round result, including round-to-even for exact ties40 // Round result, including round-to-even for exact ties
41 result = ((result + 1) >> 1) & ~@as(uT, @intFromBool(exact_tie));41 result = ((result + 1) >> 1) & ~@as(uT, @intFromBool(exact_tie));
...@@ -43,14 +43,14 @@ pub fn floatFromInt(comptime T: type, x: anytype) T {...@@ -43,14 +43,14 @@ pub fn floatFromInt(comptime T: type, x: anytype) T {
4343
44 // Compute exponent44 // Compute exponent
45 if ((int_bits > max_exp) and (exp > max_exp)) // If exponent too large, overflow to infinity45 if ((int_bits > max_exp) and (exp > max_exp)) // If exponent too large, overflow to infinity
46 return @bitCast(T, sign_bit | @bitCast(uT, inf));46 return @as(T, @bitCast(sign_bit | @as(uT, @bitCast(inf))));
4747
48 result += (@as(uT, exp) + exp_bias) << math.floatMantissaBits(T);48 result += (@as(uT, exp) + exp_bias) << math.floatMantissaBits(T);
4949
50 // If the result included a carry, we need to restore the explicit integer bit50 // If the result included a carry, we need to restore the explicit integer bit
51 if (T == f80) result |= 1 << fractional_bits;51 if (T == f80) result |= 1 << fractional_bits;
5252
53 return @bitCast(T, sign_bit | result);53 return @as(T, @bitCast(sign_bit | result));
54}54}
5555
56test {56test {
lib/compiler_rt/float_from_int_test.zig+48-48
...@@ -30,12 +30,12 @@ const __floatuntitf = @import("floatuntitf.zig").__floatuntitf;...@@ -30,12 +30,12 @@ const __floatuntitf = @import("floatuntitf.zig").__floatuntitf;
3030
31fn test__floatsisf(a: i32, expected: u32) !void {31fn test__floatsisf(a: i32, expected: u32) !void {
32 const r = __floatsisf(a);32 const r = __floatsisf(a);
33 try std.testing.expect(@bitCast(u32, r) == expected);33 try std.testing.expect(@as(u32, @bitCast(r)) == expected);
34}34}
3535
36fn test_one_floatunsisf(a: u32, expected: u32) !void {36fn test_one_floatunsisf(a: u32, expected: u32) !void {
37 const r = __floatunsisf(a);37 const r = __floatunsisf(a);
38 try std.testing.expect(@bitCast(u32, r) == expected);38 try std.testing.expect(@as(u32, @bitCast(r)) == expected);
39}39}
4040
41test "floatsisf" {41test "floatsisf" {
...@@ -43,7 +43,7 @@ test "floatsisf" {...@@ -43,7 +43,7 @@ test "floatsisf" {
43 try test__floatsisf(1, 0x3f800000);43 try test__floatsisf(1, 0x3f800000);
44 try test__floatsisf(-1, 0xbf800000);44 try test__floatsisf(-1, 0xbf800000);
45 try test__floatsisf(0x7FFFFFFF, 0x4f000000);45 try test__floatsisf(0x7FFFFFFF, 0x4f000000);
46 try test__floatsisf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xcf000000);46 try test__floatsisf(@as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 0xcf000000);
47}47}
4848
49test "floatunsisf" {49test "floatunsisf" {
...@@ -72,10 +72,10 @@ test "floatdisf" {...@@ -72,10 +72,10 @@ test "floatdisf" {
72 try test__floatdisf(-2, -2.0);72 try test__floatdisf(-2, -2.0);
73 try test__floatdisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);73 try test__floatdisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
74 try test__floatdisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);74 try test__floatdisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
75 try test__floatdisf(@bitCast(i64, @as(u64, 0x8000008000000000)), -0x1.FFFFFEp+62);75 try test__floatdisf(@as(i64, @bitCast(@as(u64, 0x8000008000000000))), -0x1.FFFFFEp+62);
76 try test__floatdisf(@bitCast(i64, @as(u64, 0x8000010000000000)), -0x1.FFFFFCp+62);76 try test__floatdisf(@as(i64, @bitCast(@as(u64, 0x8000010000000000))), -0x1.FFFFFCp+62);
77 try test__floatdisf(@bitCast(i64, @as(u64, 0x8000000000000000)), -0x1.000000p+63);77 try test__floatdisf(@as(i64, @bitCast(@as(u64, 0x8000000000000000))), -0x1.000000p+63);
78 try test__floatdisf(@bitCast(i64, @as(u64, 0x8000000000000001)), -0x1.000000p+63);78 try test__floatdisf(@as(i64, @bitCast(@as(u64, 0x8000000000000001))), -0x1.000000p+63);
79 try test__floatdisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);79 try test__floatdisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
80 try test__floatdisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);80 try test__floatdisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
81 try test__floatdisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);81 try test__floatdisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
...@@ -228,17 +228,17 @@ test "floatuntisf" {...@@ -228,17 +228,17 @@ test "floatuntisf" {
228 try test__floatuntisf(make_uti(0x0000000000001FED, 0xCBE0000000000000), 0x1.FEDCBEp+76);228 try test__floatuntisf(make_uti(0x0000000000001FED, 0xCBE0000000000000), 0x1.FEDCBEp+76);
229229
230 // Test overflow to infinity230 // Test overflow to infinity
231 try test__floatuntisf(@as(u128, math.maxInt(u128)), @bitCast(f32, math.inf(f32)));231 try test__floatuntisf(@as(u128, math.maxInt(u128)), @as(f32, @bitCast(math.inf(f32))));
232}232}
233233
234fn test_one_floatsidf(a: i32, expected: u64) !void {234fn test_one_floatsidf(a: i32, expected: u64) !void {
235 const r = __floatsidf(a);235 const r = __floatsidf(a);
236 try std.testing.expect(@bitCast(u64, r) == expected);236 try std.testing.expect(@as(u64, @bitCast(r)) == expected);
237}237}
238238
239fn test_one_floatunsidf(a: u32, expected: u64) !void {239fn test_one_floatunsidf(a: u32, expected: u64) !void {
240 const r = __floatunsidf(a);240 const r = __floatunsidf(a);
241 try std.testing.expect(@bitCast(u64, r) == expected);241 try std.testing.expect(@as(u64, @bitCast(r)) == expected);
242}242}
243243
244test "floatsidf" {244test "floatsidf" {
...@@ -246,15 +246,15 @@ test "floatsidf" {...@@ -246,15 +246,15 @@ test "floatsidf" {
246 try test_one_floatsidf(1, 0x3ff0000000000000);246 try test_one_floatsidf(1, 0x3ff0000000000000);
247 try test_one_floatsidf(-1, 0xbff0000000000000);247 try test_one_floatsidf(-1, 0xbff0000000000000);
248 try test_one_floatsidf(0x7FFFFFFF, 0x41dfffffffc00000);248 try test_one_floatsidf(0x7FFFFFFF, 0x41dfffffffc00000);
249 try test_one_floatsidf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc1e0000000000000);249 try test_one_floatsidf(@as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 0xc1e0000000000000);
250}250}
251251
252test "floatunsidf" {252test "floatunsidf" {
253 try test_one_floatunsidf(0, 0x0000000000000000);253 try test_one_floatunsidf(0, 0x0000000000000000);
254 try test_one_floatunsidf(1, 0x3ff0000000000000);254 try test_one_floatunsidf(1, 0x3ff0000000000000);
255 try test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000);255 try test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000);
256 try test_one_floatunsidf(@intCast(u32, 0x80000000), 0x41e0000000000000);256 try test_one_floatunsidf(@as(u32, @intCast(0x80000000)), 0x41e0000000000000);
257 try test_one_floatunsidf(@intCast(u32, 0xFFFFFFFF), 0x41efffffffe00000);257 try test_one_floatunsidf(@as(u32, @intCast(0xFFFFFFFF)), 0x41efffffffe00000);
258}258}
259259
260fn test__floatdidf(a: i64, expected: f64) !void {260fn test__floatdidf(a: i64, expected: f64) !void {
...@@ -279,12 +279,12 @@ test "floatdidf" {...@@ -279,12 +279,12 @@ test "floatdidf" {
279 try test__floatdidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);279 try test__floatdidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
280 try test__floatdidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);280 try test__floatdidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
281 try test__floatdidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);281 try test__floatdidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
282 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000008000000000)), -0x1.FFFFFEp+62);282 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000008000000000)))), -0x1.FFFFFEp+62);
283 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000800)), -0x1.FFFFFFFFFFFFEp+62);283 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000000000000800)))), -0x1.FFFFFFFFFFFFEp+62);
284 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000010000000000)), -0x1.FFFFFCp+62);284 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000010000000000)))), -0x1.FFFFFCp+62);
285 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000001000)), -0x1.FFFFFFFFFFFFCp+62);285 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000000000001000)))), -0x1.FFFFFFFFFFFFCp+62);
286 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000000)), -0x1.000000p+63);286 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000000000000000)))), -0x1.000000p+63);
287 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000001)), -0x1.000000p+63); // 0x8000000000000001287 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000000000000001)))), -0x1.000000p+63); // 0x8000000000000001
288 try test__floatdidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);288 try test__floatdidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
289 try test__floatdidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);289 try test__floatdidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
290 try test__floatdidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);290 try test__floatdidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
...@@ -505,7 +505,7 @@ test "floatuntidf" {...@@ -505,7 +505,7 @@ test "floatuntidf" {
505505
506fn test__floatsitf(a: i32, expected: u128) !void {506fn test__floatsitf(a: i32, expected: u128) !void {
507 const r = __floatsitf(a);507 const r = __floatsitf(a);
508 try std.testing.expect(@bitCast(u128, r) == expected);508 try std.testing.expect(@as(u128, @bitCast(r)) == expected);
509}509}
510510
511test "floatsitf" {511test "floatsitf" {
...@@ -513,16 +513,16 @@ test "floatsitf" {...@@ -513,16 +513,16 @@ test "floatsitf" {
513 try test__floatsitf(0x7FFFFFFF, 0x401dfffffffc00000000000000000000);513 try test__floatsitf(0x7FFFFFFF, 0x401dfffffffc00000000000000000000);
514 try test__floatsitf(0x12345678, 0x401b2345678000000000000000000000);514 try test__floatsitf(0x12345678, 0x401b2345678000000000000000000000);
515 try test__floatsitf(-0x12345678, 0xc01b2345678000000000000000000000);515 try test__floatsitf(-0x12345678, 0xc01b2345678000000000000000000000);
516 try test__floatsitf(@bitCast(i32, @intCast(u32, 0xffffffff)), 0xbfff0000000000000000000000000000);516 try test__floatsitf(@as(i32, @bitCast(@as(u32, @intCast(0xffffffff)))), 0xbfff0000000000000000000000000000);
517 try test__floatsitf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc01e0000000000000000000000000000);517 try test__floatsitf(@as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 0xc01e0000000000000000000000000000);
518}518}
519519
520fn test__floatunsitf(a: u32, expected_hi: u64, expected_lo: u64) !void {520fn test__floatunsitf(a: u32, expected_hi: u64, expected_lo: u64) !void {
521 const x = __floatunsitf(a);521 const x = __floatunsitf(a);
522522
523 const x_repr = @bitCast(u128, x);523 const x_repr = @as(u128, @bitCast(x));
524 const x_hi = @intCast(u64, x_repr >> 64);524 const x_hi = @as(u64, @intCast(x_repr >> 64));
525 const x_lo = @truncate(u64, x_repr);525 const x_lo = @as(u64, @truncate(x_repr));
526526
527 if (x_hi == expected_hi and x_lo == expected_lo) {527 if (x_hi == expected_hi and x_lo == expected_lo) {
528 return;528 return;
...@@ -552,9 +552,9 @@ fn test__floatditf(a: i64, expected: f128) !void {...@@ -552,9 +552,9 @@ fn test__floatditf(a: i64, expected: f128) !void {
552fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) !void {552fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) !void {
553 const x = __floatunditf(a);553 const x = __floatunditf(a);
554554
555 const x_repr = @bitCast(u128, x);555 const x_repr = @as(u128, @bitCast(x));
556 const x_hi = @intCast(u64, x_repr >> 64);556 const x_hi = @as(u64, @intCast(x_repr >> 64));
557 const x_lo = @truncate(u64, x_repr);557 const x_lo = @as(u64, @truncate(x_repr));
558558
559 if (x_hi == expected_hi and x_lo == expected_lo) {559 if (x_hi == expected_hi and x_lo == expected_lo) {
560 return;560 return;
...@@ -575,10 +575,10 @@ test "floatditf" {...@@ -575,10 +575,10 @@ test "floatditf" {
575 try test__floatditf(0x2, make_tf(0x4000000000000000, 0x0));575 try test__floatditf(0x2, make_tf(0x4000000000000000, 0x0));
576 try test__floatditf(0x1, make_tf(0x3fff000000000000, 0x0));576 try test__floatditf(0x1, make_tf(0x3fff000000000000, 0x0));
577 try test__floatditf(0x0, make_tf(0x0, 0x0));577 try test__floatditf(0x0, make_tf(0x0, 0x0));
578 try test__floatditf(@bitCast(i64, @as(u64, 0xffffffffffffffff)), make_tf(0xbfff000000000000, 0x0));578 try test__floatditf(@as(i64, @bitCast(@as(u64, 0xffffffffffffffff))), make_tf(0xbfff000000000000, 0x0));
579 try test__floatditf(@bitCast(i64, @as(u64, 0xfffffffffffffffe)), make_tf(0xc000000000000000, 0x0));579 try test__floatditf(@as(i64, @bitCast(@as(u64, 0xfffffffffffffffe))), make_tf(0xc000000000000000, 0x0));
580 try test__floatditf(-0x123456789abcdef1, make_tf(0xc03b23456789abcd, 0xef10000000000000));580 try test__floatditf(-0x123456789abcdef1, make_tf(0xc03b23456789abcd, 0xef10000000000000));
581 try test__floatditf(@bitCast(i64, @as(u64, 0x8000000000000000)), make_tf(0xc03e000000000000, 0x0));581 try test__floatditf(@as(i64, @bitCast(@as(u64, 0x8000000000000000))), make_tf(0xc03e000000000000, 0x0));
582}582}
583583
584test "floatunditf" {584test "floatunditf" {
...@@ -773,7 +773,7 @@ fn make_ti(high: u64, low: u64) i128 {...@@ -773,7 +773,7 @@ fn make_ti(high: u64, low: u64) i128 {
773 var result: u128 = high;773 var result: u128 = high;
774 result <<= 64;774 result <<= 64;
775 result |= low;775 result |= low;
776 return @bitCast(i128, result);776 return @as(i128, @bitCast(result));
777}777}
778778
779fn make_uti(high: u64, low: u64) u128 {779fn make_uti(high: u64, low: u64) u128 {
...@@ -787,7 +787,7 @@ fn make_tf(high: u64, low: u64) f128 {...@@ -787,7 +787,7 @@ fn make_tf(high: u64, low: u64) f128 {
787 var result: u128 = high;787 var result: u128 = high;
788 result <<= 64;788 result <<= 64;
789 result |= low;789 result |= low;
790 return @bitCast(f128, result);790 return @as(f128, @bitCast(result));
791}791}
792792
793test "conversion to f16" {793test "conversion to f16" {
...@@ -815,22 +815,22 @@ test "conversion to f80" {...@@ -815,22 +815,22 @@ test "conversion to f80" {
815 const floatFromInt = @import("./float_from_int.zig").floatFromInt;815 const floatFromInt = @import("./float_from_int.zig").floatFromInt;
816816
817 try testing.expect(floatFromInt(f80, @as(i80, -12)) == -12);817 try testing.expect(floatFromInt(f80, @as(i80, -12)) == -12);
818 try testing.expect(@intFromFloat(u80, floatFromInt(f80, @as(u64, math.maxInt(u64)) + 0)) == math.maxInt(u64) + 0);818 try testing.expect(@as(u80, @intFromFloat(floatFromInt(f80, @as(u64, math.maxInt(u64)) + 0))) == math.maxInt(u64) + 0);
819 try testing.expect(@intFromFloat(u80, floatFromInt(f80, @as(u80, math.maxInt(u64)) + 1)) == math.maxInt(u64) + 1);819 try testing.expect(@as(u80, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u64)) + 1))) == math.maxInt(u64) + 1);
820820
821 try testing.expect(floatFromInt(f80, @as(u32, 0)) == 0.0);821 try testing.expect(floatFromInt(f80, @as(u32, 0)) == 0.0);
822 try testing.expect(floatFromInt(f80, @as(u32, 1)) == 1.0);822 try testing.expect(floatFromInt(f80, @as(u32, 1)) == 1.0);
823 try testing.expect(@intFromFloat(u128, floatFromInt(f80, @as(u32, math.maxInt(u24)) + 0)) == math.maxInt(u24));823 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u32, math.maxInt(u24)) + 0))) == math.maxInt(u24));
824 try testing.expect(@intFromFloat(u128, floatFromInt(f80, @as(u80, math.maxInt(u64)) + 0)) == math.maxInt(u64));824 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u64)) + 0))) == math.maxInt(u64));
825 try testing.expect(@intFromFloat(u128, floatFromInt(f80, @as(u80, math.maxInt(u64)) + 1)) == math.maxInt(u64) + 1); // Exact825 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u64)) + 1))) == math.maxInt(u64) + 1); // Exact
826 try testing.expect(@intFromFloat(u128, floatFromInt(f80, @as(u80, math.maxInt(u64)) + 2)) == math.maxInt(u64) + 1); // Rounds down826 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u64)) + 2))) == math.maxInt(u64) + 1); // Rounds down
827 try testing.expect(@intFromFloat(u128, floatFromInt(f80, @as(u80, math.maxInt(u64)) + 3)) == math.maxInt(u64) + 3); // Tie - Exact827 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u64)) + 3))) == math.maxInt(u64) + 3); // Tie - Exact
828 try testing.expect(@intFromFloat(u128, floatFromInt(f80, @as(u80, math.maxInt(u64)) + 4)) == math.maxInt(u64) + 5); // Rounds up828 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u64)) + 4))) == math.maxInt(u64) + 5); // Rounds up
829829
830 try testing.expect(@intFromFloat(u128, floatFromInt(f80, @as(u80, math.maxInt(u65)) + 0)) == math.maxInt(u65) + 1); // Rounds up830 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u65)) + 0))) == math.maxInt(u65) + 1); // Rounds up
831 try testing.expect(@intFromFloat(u128, floatFromInt(f80, @as(u80, math.maxInt(u65)) + 1)) == math.maxInt(u65) + 1); // Exact831 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u65)) + 1))) == math.maxInt(u65) + 1); // Exact
832 try testing.expect(@intFromFloat(u128, floatFromInt(f80, @as(u80, math.maxInt(u65)) + 2)) == math.maxInt(u65) + 1); // Rounds down832 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u65)) + 2))) == math.maxInt(u65) + 1); // Rounds down
833 try testing.expect(@intFromFloat(u128, floatFromInt(f80, @as(u80, math.maxInt(u65)) + 3)) == math.maxInt(u65) + 1); // Tie - Rounds down833 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u65)) + 3))) == math.maxInt(u65) + 1); // Tie - Rounds down
834 try testing.expect(@intFromFloat(u128, floatFromInt(f80, @as(u80, math.maxInt(u65)) + 4)) == math.maxInt(u65) + 5); // Rounds up834 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u65)) + 4))) == math.maxInt(u65) + 5); // Rounds up
835 try testing.expect(@intFromFloat(u128, floatFromInt(f80, @as(u80, math.maxInt(u65)) + 5)) == math.maxInt(u65) + 5); // Exact835 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u65)) + 5))) == math.maxInt(u65) + 5); // Exact
836}836}
lib/compiler_rt/floattidf.zig+1-1
...@@ -17,5 +17,5 @@ pub fn __floattidf(a: i128) callconv(.C) f64 {...@@ -17,5 +17,5 @@ pub fn __floattidf(a: i128) callconv(.C) f64 {
17}17}
1818
19fn __floattidf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f64 {19fn __floattidf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f64 {
20 return floatFromInt(f64, @bitCast(i128, a));20 return floatFromInt(f64, @as(i128, @bitCast(a)));
21}21}
lib/compiler_rt/floattihf.zig+1-1
...@@ -17,5 +17,5 @@ pub fn __floattihf(a: i128) callconv(.C) f16 {...@@ -17,5 +17,5 @@ pub fn __floattihf(a: i128) callconv(.C) f16 {
17}17}
1818
19fn __floattihf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f16 {19fn __floattihf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f16 {
20 return floatFromInt(f16, @bitCast(i128, a));20 return floatFromInt(f16, @as(i128, @bitCast(a)));
21}21}
lib/compiler_rt/floattisf.zig+1-1
...@@ -17,5 +17,5 @@ pub fn __floattisf(a: i128) callconv(.C) f32 {...@@ -17,5 +17,5 @@ pub fn __floattisf(a: i128) callconv(.C) f32 {
17}17}
1818
19fn __floattisf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f32 {19fn __floattisf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f32 {
20 return floatFromInt(f32, @bitCast(i128, a));20 return floatFromInt(f32, @as(i128, @bitCast(a)));
21}21}
lib/compiler_rt/floattitf.zig+1-1
...@@ -19,5 +19,5 @@ pub fn __floattitf(a: i128) callconv(.C) f128 {...@@ -19,5 +19,5 @@ pub fn __floattitf(a: i128) callconv(.C) f128 {
19}19}
2020
21fn __floattitf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f128 {21fn __floattitf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f128 {
22 return floatFromInt(f128, @bitCast(i128, a));22 return floatFromInt(f128, @as(i128, @bitCast(a)));
23}23}
lib/compiler_rt/floattixf.zig+1-1
...@@ -17,5 +17,5 @@ pub fn __floattixf(a: i128) callconv(.C) f80 {...@@ -17,5 +17,5 @@ pub fn __floattixf(a: i128) callconv(.C) f80 {
17}17}
1818
19fn __floattixf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f80 {19fn __floattixf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f80 {
20 return floatFromInt(f80, @bitCast(i128, a));20 return floatFromInt(f80, @as(i128, @bitCast(a)));
21}21}
lib/compiler_rt/floatuntidf.zig+1-1
...@@ -17,5 +17,5 @@ pub fn __floatuntidf(a: u128) callconv(.C) f64 {...@@ -17,5 +17,5 @@ pub fn __floatuntidf(a: u128) callconv(.C) f64 {
17}17}
1818
19fn __floatuntidf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f64 {19fn __floatuntidf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f64 {
20 return floatFromInt(f64, @bitCast(u128, a));20 return floatFromInt(f64, @as(u128, @bitCast(a)));
21}21}
lib/compiler_rt/floatuntihf.zig+1-1
...@@ -17,5 +17,5 @@ pub fn __floatuntihf(a: u128) callconv(.C) f16 {...@@ -17,5 +17,5 @@ pub fn __floatuntihf(a: u128) callconv(.C) f16 {
17}17}
1818
19fn __floatuntihf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f16 {19fn __floatuntihf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f16 {
20 return floatFromInt(f16, @bitCast(u128, a));20 return floatFromInt(f16, @as(u128, @bitCast(a)));
21}21}
lib/compiler_rt/floatuntisf.zig+1-1
...@@ -17,5 +17,5 @@ pub fn __floatuntisf(a: u128) callconv(.C) f32 {...@@ -17,5 +17,5 @@ pub fn __floatuntisf(a: u128) callconv(.C) f32 {
17}17}
1818
19fn __floatuntisf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f32 {19fn __floatuntisf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f32 {
20 return floatFromInt(f32, @bitCast(u128, a));20 return floatFromInt(f32, @as(u128, @bitCast(a)));
21}21}
lib/compiler_rt/floatuntitf.zig+1-1
...@@ -19,5 +19,5 @@ pub fn __floatuntitf(a: u128) callconv(.C) f128 {...@@ -19,5 +19,5 @@ pub fn __floatuntitf(a: u128) callconv(.C) f128 {
19}19}
2020
21fn __floatuntitf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f128 {21fn __floatuntitf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f128 {
22 return floatFromInt(f128, @bitCast(u128, a));22 return floatFromInt(f128, @as(u128, @bitCast(a)));
23}23}
lib/compiler_rt/floatuntixf.zig+1-1
...@@ -17,5 +17,5 @@ pub fn __floatuntixf(a: u128) callconv(.C) f80 {...@@ -17,5 +17,5 @@ pub fn __floatuntixf(a: u128) callconv(.C) f80 {
17}17}
1818
19fn __floatuntixf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f80 {19fn __floatuntixf_windows_x86_64(a: @Vector(2, u64)) callconv(.C) f80 {
20 return floatFromInt(f80, @bitCast(u128, a));20 return floatFromInt(f80, @as(u128, @bitCast(a)));
21}21}
lib/compiler_rt/floor.zig+11-11
...@@ -26,8 +26,8 @@ comptime {...@@ -26,8 +26,8 @@ comptime {
26}26}
2727
28pub fn __floorh(x: f16) callconv(.C) f16 {28pub fn __floorh(x: f16) callconv(.C) f16 {
29 var u = @bitCast(u16, x);29 var u = @as(u16, @bitCast(x));
30 const e = @intCast(i16, (u >> 10) & 31) - 15;30 const e = @as(i16, @intCast((u >> 10) & 31)) - 15;
31 var m: u16 = undefined;31 var m: u16 = undefined;
3232
33 // TODO: Shouldn't need this explicit check.33 // TODO: Shouldn't need this explicit check.
...@@ -40,7 +40,7 @@ pub fn __floorh(x: f16) callconv(.C) f16 {...@@ -40,7 +40,7 @@ pub fn __floorh(x: f16) callconv(.C) f16 {
40 }40 }
4141
42 if (e >= 0) {42 if (e >= 0) {
43 m = @as(u16, 1023) >> @intCast(u4, e);43 m = @as(u16, 1023) >> @as(u4, @intCast(e));
44 if (u & m == 0) {44 if (u & m == 0) {
45 return x;45 return x;
46 }46 }
...@@ -48,7 +48,7 @@ pub fn __floorh(x: f16) callconv(.C) f16 {...@@ -48,7 +48,7 @@ pub fn __floorh(x: f16) callconv(.C) f16 {
48 if (u >> 15 != 0) {48 if (u >> 15 != 0) {
49 u += m;49 u += m;
50 }50 }
51 return @bitCast(f16, u & ~m);51 return @as(f16, @bitCast(u & ~m));
52 } else {52 } else {
53 math.doNotOptimizeAway(x + 0x1.0p120);53 math.doNotOptimizeAway(x + 0x1.0p120);
54 if (u >> 15 == 0) {54 if (u >> 15 == 0) {
...@@ -60,8 +60,8 @@ pub fn __floorh(x: f16) callconv(.C) f16 {...@@ -60,8 +60,8 @@ pub fn __floorh(x: f16) callconv(.C) f16 {
60}60}
6161
62pub fn floorf(x: f32) callconv(.C) f32 {62pub fn floorf(x: f32) callconv(.C) f32 {
63 var u = @bitCast(u32, x);63 var u = @as(u32, @bitCast(x));
64 const e = @intCast(i32, (u >> 23) & 0xFF) - 0x7F;64 const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;
65 var m: u32 = undefined;65 var m: u32 = undefined;
6666
67 // TODO: Shouldn't need this explicit check.67 // TODO: Shouldn't need this explicit check.
...@@ -74,7 +74,7 @@ pub fn floorf(x: f32) callconv(.C) f32 {...@@ -74,7 +74,7 @@ pub fn floorf(x: f32) callconv(.C) f32 {
74 }74 }
7575
76 if (e >= 0) {76 if (e >= 0) {
77 m = @as(u32, 0x007FFFFF) >> @intCast(u5, e);77 m = @as(u32, 0x007FFFFF) >> @as(u5, @intCast(e));
78 if (u & m == 0) {78 if (u & m == 0) {
79 return x;79 return x;
80 }80 }
...@@ -82,7 +82,7 @@ pub fn floorf(x: f32) callconv(.C) f32 {...@@ -82,7 +82,7 @@ pub fn floorf(x: f32) callconv(.C) f32 {
82 if (u >> 31 != 0) {82 if (u >> 31 != 0) {
83 u += m;83 u += m;
84 }84 }
85 return @bitCast(f32, u & ~m);85 return @as(f32, @bitCast(u & ~m));
86 } else {86 } else {
87 math.doNotOptimizeAway(x + 0x1.0p120);87 math.doNotOptimizeAway(x + 0x1.0p120);
88 if (u >> 31 == 0) {88 if (u >> 31 == 0) {
...@@ -96,7 +96,7 @@ pub fn floorf(x: f32) callconv(.C) f32 {...@@ -96,7 +96,7 @@ pub fn floorf(x: f32) callconv(.C) f32 {
96pub fn floor(x: f64) callconv(.C) f64 {96pub fn floor(x: f64) callconv(.C) f64 {
97 const f64_toint = 1.0 / math.floatEps(f64);97 const f64_toint = 1.0 / math.floatEps(f64);
9898
99 const u = @bitCast(u64, x);99 const u = @as(u64, @bitCast(x));
100 const e = (u >> 52) & 0x7FF;100 const e = (u >> 52) & 0x7FF;
101 var y: f64 = undefined;101 var y: f64 = undefined;
102102
...@@ -126,13 +126,13 @@ pub fn floor(x: f64) callconv(.C) f64 {...@@ -126,13 +126,13 @@ pub fn floor(x: f64) callconv(.C) f64 {
126126
127pub fn __floorx(x: f80) callconv(.C) f80 {127pub fn __floorx(x: f80) callconv(.C) f80 {
128 // TODO: more efficient implementation128 // TODO: more efficient implementation
129 return @floatCast(f80, floorq(x));129 return @as(f80, @floatCast(floorq(x)));
130}130}
131131
132pub fn floorq(x: f128) callconv(.C) f128 {132pub fn floorq(x: f128) callconv(.C) f128 {
133 const f128_toint = 1.0 / math.floatEps(f128);133 const f128_toint = 1.0 / math.floatEps(f128);
134134
135 const u = @bitCast(u128, x);135 const u = @as(u128, @bitCast(x));
136 const e = (u >> 112) & 0x7FFF;136 const e = (u >> 112) & 0x7FFF;
137 var y: f128 = undefined;137 var y: f128 = undefined;
138138
lib/compiler_rt/fma.zig+19-19
...@@ -28,20 +28,20 @@ comptime {...@@ -28,20 +28,20 @@ comptime {
2828
29pub fn __fmah(x: f16, y: f16, z: f16) callconv(.C) f16 {29pub fn __fmah(x: f16, y: f16, z: f16) callconv(.C) f16 {
30 // TODO: more efficient implementation30 // TODO: more efficient implementation
31 return @floatCast(f16, fmaf(x, y, z));31 return @as(f16, @floatCast(fmaf(x, y, z)));
32}32}
3333
34pub fn fmaf(x: f32, y: f32, z: f32) callconv(.C) f32 {34pub fn fmaf(x: f32, y: f32, z: f32) callconv(.C) f32 {
35 const xy = @as(f64, x) * y;35 const xy = @as(f64, x) * y;
36 const xy_z = xy + z;36 const xy_z = xy + z;
37 const u = @bitCast(u64, xy_z);37 const u = @as(u64, @bitCast(xy_z));
38 const e = (u >> 52) & 0x7FF;38 const e = (u >> 52) & 0x7FF;
3939
40 if ((u & 0x1FFFFFFF) != 0x10000000 or e == 0x7FF or (xy_z - xy == z and xy_z - z == xy)) {40 if ((u & 0x1FFFFFFF) != 0x10000000 or e == 0x7FF or (xy_z - xy == z and xy_z - z == xy)) {
41 return @floatCast(f32, xy_z);41 return @as(f32, @floatCast(xy_z));
42 } else {42 } else {
43 // TODO: Handle inexact case with double-rounding43 // TODO: Handle inexact case with double-rounding
44 return @floatCast(f32, xy_z);44 return @as(f32, @floatCast(xy_z));
45 }45 }
46}46}
4747
...@@ -95,7 +95,7 @@ pub fn fma(x: f64, y: f64, z: f64) callconv(.C) f64 {...@@ -95,7 +95,7 @@ pub fn fma(x: f64, y: f64, z: f64) callconv(.C) f64 {
9595
96pub fn __fmax(a: f80, b: f80, c: f80) callconv(.C) f80 {96pub fn __fmax(a: f80, b: f80, c: f80) callconv(.C) f80 {
97 // TODO: more efficient implementation97 // TODO: more efficient implementation
98 return @floatCast(f80, fmaq(a, b, c));98 return @as(f80, @floatCast(fmaq(a, b, c)));
99}99}
100100
101/// Fused multiply-add: Compute x * y + z with a single rounding error.101/// Fused multiply-add: Compute x * y + z with a single rounding error.
...@@ -201,12 +201,12 @@ fn dd_mul(a: f64, b: f64) dd {...@@ -201,12 +201,12 @@ fn dd_mul(a: f64, b: f64) dd {
201fn add_adjusted(a: f64, b: f64) f64 {201fn add_adjusted(a: f64, b: f64) f64 {
202 var sum = dd_add(a, b);202 var sum = dd_add(a, b);
203 if (sum.lo != 0) {203 if (sum.lo != 0) {
204 var uhii = @bitCast(u64, sum.hi);204 var uhii = @as(u64, @bitCast(sum.hi));
205 if (uhii & 1 == 0) {205 if (uhii & 1 == 0) {
206 // hibits += copysign(1.0, sum.hi, sum.lo)206 // hibits += copysign(1.0, sum.hi, sum.lo)
207 const uloi = @bitCast(u64, sum.lo);207 const uloi = @as(u64, @bitCast(sum.lo));
208 uhii += 1 - ((uhii ^ uloi) >> 62);208 uhii += 1 - ((uhii ^ uloi) >> 62);
209 sum.hi = @bitCast(f64, uhii);209 sum.hi = @as(f64, @bitCast(uhii));
210 }210 }
211 }211 }
212 return sum.hi;212 return sum.hi;
...@@ -215,12 +215,12 @@ fn add_adjusted(a: f64, b: f64) f64 {...@@ -215,12 +215,12 @@ fn add_adjusted(a: f64, b: f64) f64 {
215fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {215fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {
216 var sum = dd_add(a, b);216 var sum = dd_add(a, b);
217 if (sum.lo != 0) {217 if (sum.lo != 0) {
218 var uhii = @bitCast(u64, sum.hi);218 var uhii = @as(u64, @bitCast(sum.hi));
219 const bits_lost = -@intCast(i32, (uhii >> 52) & 0x7FF) - scale + 1;219 const bits_lost = -@as(i32, @intCast((uhii >> 52) & 0x7FF)) - scale + 1;
220 if ((bits_lost != 1) == (uhii & 1 != 0)) {220 if ((bits_lost != 1) == (uhii & 1 != 0)) {
221 const uloi = @bitCast(u64, sum.lo);221 const uloi = @as(u64, @bitCast(sum.lo));
222 uhii += 1 - (((uhii ^ uloi) >> 62) & 2);222 uhii += 1 - (((uhii ^ uloi) >> 62) & 2);
223 sum.hi = @bitCast(f64, uhii);223 sum.hi = @as(f64, @bitCast(uhii));
224 }224 }
225 }225 }
226 return math.scalbn(sum.hi, scale);226 return math.scalbn(sum.hi, scale);
...@@ -257,12 +257,12 @@ fn dd_add128(a: f128, b: f128) dd128 {...@@ -257,12 +257,12 @@ fn dd_add128(a: f128, b: f128) dd128 {
257fn add_adjusted128(a: f128, b: f128) f128 {257fn add_adjusted128(a: f128, b: f128) f128 {
258 var sum = dd_add128(a, b);258 var sum = dd_add128(a, b);
259 if (sum.lo != 0) {259 if (sum.lo != 0) {
260 var uhii = @bitCast(u128, sum.hi);260 var uhii = @as(u128, @bitCast(sum.hi));
261 if (uhii & 1 == 0) {261 if (uhii & 1 == 0) {
262 // hibits += copysign(1.0, sum.hi, sum.lo)262 // hibits += copysign(1.0, sum.hi, sum.lo)
263 const uloi = @bitCast(u128, sum.lo);263 const uloi = @as(u128, @bitCast(sum.lo));
264 uhii += 1 - ((uhii ^ uloi) >> 126);264 uhii += 1 - ((uhii ^ uloi) >> 126);
265 sum.hi = @bitCast(f128, uhii);265 sum.hi = @as(f128, @bitCast(uhii));
266 }266 }
267 }267 }
268 return sum.hi;268 return sum.hi;
...@@ -282,12 +282,12 @@ fn add_and_denorm128(a: f128, b: f128, scale: i32) f128 {...@@ -282,12 +282,12 @@ fn add_and_denorm128(a: f128, b: f128, scale: i32) f128 {
282 // If we are losing only one bit to denormalization, however, we must282 // If we are losing only one bit to denormalization, however, we must
283 // break the ties manually.283 // break the ties manually.
284 if (sum.lo != 0) {284 if (sum.lo != 0) {
285 var uhii = @bitCast(u128, sum.hi);285 var uhii = @as(u128, @bitCast(sum.hi));
286 const bits_lost = -@intCast(i32, (uhii >> 112) & 0x7FFF) - scale + 1;286 const bits_lost = -@as(i32, @intCast((uhii >> 112) & 0x7FFF)) - scale + 1;
287 if ((bits_lost != 1) == (uhii & 1 != 0)) {287 if ((bits_lost != 1) == (uhii & 1 != 0)) {
288 const uloi = @bitCast(u128, sum.lo);288 const uloi = @as(u128, @bitCast(sum.lo));
289 uhii += 1 - (((uhii ^ uloi) >> 126) & 2);289 uhii += 1 - (((uhii ^ uloi) >> 126) & 2);
290 sum.hi = @bitCast(f128, uhii);290 sum.hi = @as(f128, @bitCast(uhii));
291 }291 }
292 }292 }
293 return math.scalbn(sum.hi, scale);293 return math.scalbn(sum.hi, scale);
lib/compiler_rt/fmod.zig+32-32
...@@ -22,7 +22,7 @@ comptime {...@@ -22,7 +22,7 @@ comptime {
2222
23pub fn __fmodh(x: f16, y: f16) callconv(.C) f16 {23pub fn __fmodh(x: f16, y: f16) callconv(.C) f16 {
24 // TODO: more efficient implementation24 // TODO: more efficient implementation
25 return @floatCast(f16, fmodf(x, y));25 return @as(f16, @floatCast(fmodf(x, y)));
26}26}
2727
28pub fn fmodf(x: f32, y: f32) callconv(.C) f32 {28pub fn fmodf(x: f32, y: f32) callconv(.C) f32 {
...@@ -46,12 +46,12 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {...@@ -46,12 +46,12 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
46 const signBit = (@as(Z, 1) << (significandBits + exponentBits));46 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
47 const maxExponent = ((1 << exponentBits) - 1);47 const maxExponent = ((1 << exponentBits) - 1);
4848
49 var aRep = @bitCast(Z, a);49 var aRep = @as(Z, @bitCast(a));
50 var bRep = @bitCast(Z, b);50 var bRep = @as(Z, @bitCast(b));
5151
52 const signA = aRep & signBit;52 const signA = aRep & signBit;
53 var expA = @intCast(i32, (@bitCast(Z, a) >> significandBits) & maxExponent);53 var expA = @as(i32, @intCast((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
54 var expB = @intCast(i32, (@bitCast(Z, b) >> significandBits) & maxExponent);54 var expB = @as(i32, @intCast((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
5555
56 // There are 3 cases where the answer is undefined, check for:56 // There are 3 cases where the answer is undefined, check for:
57 // - fmodx(val, 0)57 // - fmodx(val, 0)
...@@ -82,8 +82,8 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {...@@ -82,8 +82,8 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
8282
83 var highA: u64 = 0;83 var highA: u64 = 0;
84 var highB: u64 = 0;84 var highB: u64 = 0;
85 var lowA: u64 = @truncate(u64, aRep);85 var lowA: u64 = @as(u64, @truncate(aRep));
86 var lowB: u64 = @truncate(u64, bRep);86 var lowB: u64 = @as(u64, @truncate(bRep));
8787
88 while (expA > expB) : (expA -= 1) {88 while (expA > expB) : (expA -= 1) {
89 var high = highA -% highB;89 var high = highA -% highB;
...@@ -123,11 +123,11 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {...@@ -123,11 +123,11 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
123123
124 // Combine the exponent with the sign and significand, normalize if happened to be denormalized124 // Combine the exponent with the sign and significand, normalize if happened to be denormalized
125 if (expA < -fractionalBits) {125 if (expA < -fractionalBits) {
126 return @bitCast(T, signA);126 return @as(T, @bitCast(signA));
127 } else if (expA <= 0) {127 } else if (expA <= 0) {
128 return @bitCast(T, (lowA >> @intCast(math.Log2Int(u64), 1 - expA)) | signA);128 return @as(T, @bitCast((lowA >> @as(math.Log2Int(u64), @intCast(1 - expA))) | signA));
129 } else {129 } else {
130 return @bitCast(T, lowA | (@as(Z, @intCast(u16, expA)) << significandBits) | signA);130 return @as(T, @bitCast(lowA | (@as(Z, @as(u16, @intCast(expA))) << significandBits) | signA));
131 }131 }
132}132}
133133
...@@ -136,10 +136,10 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {...@@ -136,10 +136,10 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
136pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {136pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
137 var amod = a;137 var amod = a;
138 var bmod = b;138 var bmod = b;
139 const aPtr_u64 = @ptrCast([*]u64, &amod);139 const aPtr_u64 = @as([*]u64, @ptrCast(&amod));
140 const bPtr_u64 = @ptrCast([*]u64, &bmod);140 const bPtr_u64 = @as([*]u64, @ptrCast(&bmod));
141 const aPtr_u16 = @ptrCast([*]u16, &amod);141 const aPtr_u16 = @as([*]u16, @ptrCast(&amod));
142 const bPtr_u16 = @ptrCast([*]u16, &bmod);142 const bPtr_u16 = @as([*]u16, @ptrCast(&bmod));
143143
144 const exp_and_sign_index = comptime switch (builtin.target.cpu.arch.endian()) {144 const exp_and_sign_index = comptime switch (builtin.target.cpu.arch.endian()) {
145 .Little => 7,145 .Little => 7,
...@@ -155,8 +155,8 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {...@@ -155,8 +155,8 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
155 };155 };
156156
157 const signA = aPtr_u16[exp_and_sign_index] & 0x8000;157 const signA = aPtr_u16[exp_and_sign_index] & 0x8000;
158 var expA = @intCast(i32, (aPtr_u16[exp_and_sign_index] & 0x7fff));158 var expA = @as(i32, @intCast((aPtr_u16[exp_and_sign_index] & 0x7fff)));
159 var expB = @intCast(i32, (bPtr_u16[exp_and_sign_index] & 0x7fff));159 var expB = @as(i32, @intCast((bPtr_u16[exp_and_sign_index] & 0x7fff)));
160160
161 // There are 3 cases where the answer is undefined, check for:161 // There are 3 cases where the answer is undefined, check for:
162 // - fmodq(val, 0)162 // - fmodq(val, 0)
...@@ -173,8 +173,8 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {...@@ -173,8 +173,8 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
173 }173 }
174174
175 // Remove the sign from both175 // Remove the sign from both
176 aPtr_u16[exp_and_sign_index] = @bitCast(u16, @intCast(i16, expA));176 aPtr_u16[exp_and_sign_index] = @as(u16, @bitCast(@as(i16, @intCast(expA))));
177 bPtr_u16[exp_and_sign_index] = @bitCast(u16, @intCast(i16, expB));177 bPtr_u16[exp_and_sign_index] = @as(u16, @bitCast(@as(i16, @intCast(expB))));
178 if (amod <= bmod) {178 if (amod <= bmod) {
179 if (amod == bmod) {179 if (amod == bmod) {
180 return 0 * a;180 return 0 * a;
...@@ -241,10 +241,10 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {...@@ -241,10 +241,10 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
241241
242 // Combine the exponent with the sign, normalize if happend to be denormalized242 // Combine the exponent with the sign, normalize if happend to be denormalized
243 if (expA <= 0) {243 if (expA <= 0) {
244 aPtr_u16[exp_and_sign_index] = @truncate(u16, @bitCast(u32, (expA +% 120))) | signA;244 aPtr_u16[exp_and_sign_index] = @as(u16, @truncate(@as(u32, @bitCast((expA +% 120))))) | signA;
245 amod *= 0x1p-120;245 amod *= 0x1p-120;
246 } else {246 } else {
247 aPtr_u16[exp_and_sign_index] = @truncate(u16, @bitCast(u32, expA)) | signA;247 aPtr_u16[exp_and_sign_index] = @as(u16, @truncate(@as(u32, @bitCast(expA)))) | signA;
248 }248 }
249249
250 return amod;250 return amod;
...@@ -270,14 +270,14 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {...@@ -270,14 +270,14 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {
270 const exp_bits = if (T == f32) 9 else 12;270 const exp_bits = if (T == f32) 9 else 12;
271 const bits_minus_1 = bits - 1;271 const bits_minus_1 = bits - 1;
272 const mask = if (T == f32) 0xff else 0x7ff;272 const mask = if (T == f32) 0xff else 0x7ff;
273 var ux = @bitCast(uint, x);273 var ux = @as(uint, @bitCast(x));
274 var uy = @bitCast(uint, y);274 var uy = @as(uint, @bitCast(y));
275 var ex = @intCast(i32, (ux >> digits) & mask);275 var ex = @as(i32, @intCast((ux >> digits) & mask));
276 var ey = @intCast(i32, (uy >> digits) & mask);276 var ey = @as(i32, @intCast((uy >> digits) & mask));
277 const sx = if (T == f32) @intCast(u32, ux & 0x80000000) else @intCast(i32, ux >> bits_minus_1);277 const sx = if (T == f32) @as(u32, @intCast(ux & 0x80000000)) else @as(i32, @intCast(ux >> bits_minus_1));
278 var i: uint = undefined;278 var i: uint = undefined;
279279
280 if (uy << 1 == 0 or math.isNan(@bitCast(T, uy)) or ex == mask)280 if (uy << 1 == 0 or math.isNan(@as(T, @bitCast(uy))) or ex == mask)
281 return (x * y) / (x * y);281 return (x * y) / (x * y);
282282
283 if (ux << 1 <= uy << 1) {283 if (ux << 1 <= uy << 1) {
...@@ -293,7 +293,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {...@@ -293,7 +293,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {
293 ex -= 1;293 ex -= 1;
294 i <<= 1;294 i <<= 1;
295 }) {}295 }) {}
296 ux <<= @intCast(log2uint, @bitCast(u32, -ex + 1));296 ux <<= @as(log2uint, @intCast(@as(u32, @bitCast(-ex + 1))));
297 } else {297 } else {
298 ux &= math.maxInt(uint) >> exp_bits;298 ux &= math.maxInt(uint) >> exp_bits;
299 ux |= 1 << digits;299 ux |= 1 << digits;
...@@ -304,7 +304,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {...@@ -304,7 +304,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {
304 ey -= 1;304 ey -= 1;
305 i <<= 1;305 i <<= 1;
306 }) {}306 }) {}
307 uy <<= @intCast(log2uint, @bitCast(u32, -ey + 1));307 uy <<= @as(log2uint, @intCast(@as(u32, @bitCast(-ey + 1))));
308 } else {308 } else {
309 uy &= math.maxInt(uint) >> exp_bits;309 uy &= math.maxInt(uint) >> exp_bits;
310 uy |= 1 << digits;310 uy |= 1 << digits;
...@@ -334,16 +334,16 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {...@@ -334,16 +334,16 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {
334 // scale result up334 // scale result up
335 if (ex > 0) {335 if (ex > 0) {
336 ux -%= 1 << digits;336 ux -%= 1 << digits;
337 ux |= @as(uint, @bitCast(u32, ex)) << digits;337 ux |= @as(uint, @as(u32, @bitCast(ex))) << digits;
338 } else {338 } else {
339 ux >>= @intCast(log2uint, @bitCast(u32, -ex + 1));339 ux >>= @as(log2uint, @intCast(@as(u32, @bitCast(-ex + 1))));
340 }340 }
341 if (T == f32) {341 if (T == f32) {
342 ux |= sx;342 ux |= sx;
343 } else {343 } else {
344 ux |= @intCast(uint, sx) << bits_minus_1;344 ux |= @as(uint, @intCast(sx)) << bits_minus_1;
345 }345 }
346 return @bitCast(T, ux);346 return @as(T, @bitCast(ux));
347}347}
348348
349test "fmodf" {349test "fmodf" {
lib/compiler_rt/int.zig+41-41
...@@ -52,8 +52,8 @@ test "test_divmodti4" {...@@ -52,8 +52,8 @@ test "test_divmodti4" {
52 [_]i128{ -7, 5, -1, -2 },52 [_]i128{ -7, 5, -1, -2 },
53 [_]i128{ 19, 5, 3, 4 },53 [_]i128{ 19, 5, 3, 4 },
54 [_]i128{ 19, -5, -3, 4 },54 [_]i128{ 19, -5, -3, 4 },
55 [_]i128{ @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 8, @bitCast(i128, @as(u128, 0xf0000000000000000000000000000000)), 0 },55 [_]i128{ @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 8, @as(i128, @bitCast(@as(u128, 0xf0000000000000000000000000000000))), 0 },
56 [_]i128{ @bitCast(i128, @as(u128, 0x80000000000000000000000000000007)), 8, @bitCast(i128, @as(u128, 0xf0000000000000000000000000000001)), -1 },56 [_]i128{ @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000007))), 8, @as(i128, @bitCast(@as(u128, 0xf0000000000000000000000000000001))), -1 },
57 };57 };
5858
59 for (cases) |case| {59 for (cases) |case| {
...@@ -85,8 +85,8 @@ test "test_divmoddi4" {...@@ -85,8 +85,8 @@ test "test_divmoddi4" {
85 [_]i64{ -7, 5, -1, -2 },85 [_]i64{ -7, 5, -1, -2 },
86 [_]i64{ 19, 5, 3, 4 },86 [_]i64{ 19, 5, 3, 4 },
87 [_]i64{ 19, -5, -3, 4 },87 [_]i64{ 19, -5, -3, 4 },
88 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 8, @bitCast(i64, @as(u64, 0xf000000000000000)), 0 },88 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 8, @as(i64, @bitCast(@as(u64, 0xf000000000000000))), 0 },
89 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000007)), 8, @bitCast(i64, @as(u64, 0xf000000000000001)), -1 },89 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000007))), 8, @as(i64, @bitCast(@as(u64, 0xf000000000000001))), -1 },
90 };90 };
9191
92 for (cases) |case| {92 for (cases) |case| {
...@@ -110,14 +110,14 @@ test "test_udivmoddi4" {...@@ -110,14 +110,14 @@ test "test_udivmoddi4" {
110110
111pub fn __divdi3(a: i64, b: i64) callconv(.C) i64 {111pub fn __divdi3(a: i64, b: i64) callconv(.C) i64 {
112 // Set aside the sign of the quotient.112 // Set aside the sign of the quotient.
113 const sign = @bitCast(u64, (a ^ b) >> 63);113 const sign = @as(u64, @bitCast((a ^ b) >> 63));
114 // Take absolute value of a and b via abs(x) = (x^(x >> 63)) - (x >> 63).114 // Take absolute value of a and b via abs(x) = (x^(x >> 63)) - (x >> 63).
115 const abs_a = (a ^ (a >> 63)) -% (a >> 63);115 const abs_a = (a ^ (a >> 63)) -% (a >> 63);
116 const abs_b = (b ^ (b >> 63)) -% (b >> 63);116 const abs_b = (b ^ (b >> 63)) -% (b >> 63);
117 // Unsigned division117 // Unsigned division
118 const res = __udivmoddi4(@bitCast(u64, abs_a), @bitCast(u64, abs_b), null);118 const res = __udivmoddi4(@as(u64, @bitCast(abs_a)), @as(u64, @bitCast(abs_b)), null);
119 // Apply sign of quotient to result and return.119 // Apply sign of quotient to result and return.
120 return @bitCast(i64, (res ^ sign) -% sign);120 return @as(i64, @bitCast((res ^ sign) -% sign));
121}121}
122122
123test "test_divdi3" {123test "test_divdi3" {
...@@ -129,10 +129,10 @@ test "test_divdi3" {...@@ -129,10 +129,10 @@ test "test_divdi3" {
129 [_]i64{ -2, 1, -2 },129 [_]i64{ -2, 1, -2 },
130 [_]i64{ -2, -1, 2 },130 [_]i64{ -2, -1, 2 },
131131
132 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)) },132 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1, @as(i64, @bitCast(@as(u64, 0x8000000000000000))) },
133 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)) },133 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), -1, @as(i64, @bitCast(@as(u64, 0x8000000000000000))) },
134 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -2, 0x4000000000000000 },134 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), -2, 0x4000000000000000 },
135 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0xC000000000000000)) },135 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 2, @as(i64, @bitCast(@as(u64, 0xC000000000000000))) },
136 };136 };
137137
138 for (cases) |case| {138 for (cases) |case| {
...@@ -151,9 +151,9 @@ pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 {...@@ -151,9 +151,9 @@ pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 {
151 const abs_b = (b ^ (b >> 63)) -% (b >> 63);151 const abs_b = (b ^ (b >> 63)) -% (b >> 63);
152 // Unsigned division152 // Unsigned division
153 var r: u64 = undefined;153 var r: u64 = undefined;
154 _ = __udivmoddi4(@bitCast(u64, abs_a), @bitCast(u64, abs_b), &r);154 _ = __udivmoddi4(@as(u64, @bitCast(abs_a)), @as(u64, @bitCast(abs_b)), &r);
155 // Apply the sign of the dividend and return.155 // Apply the sign of the dividend and return.
156 return (@bitCast(i64, r) ^ (a >> 63)) -% (a >> 63);156 return (@as(i64, @bitCast(r)) ^ (a >> 63)) -% (a >> 63);
157}157}
158158
159test "test_moddi3" {159test "test_moddi3" {
...@@ -165,12 +165,12 @@ test "test_moddi3" {...@@ -165,12 +165,12 @@ test "test_moddi3" {
165 [_]i64{ -5, 3, -2 },165 [_]i64{ -5, 3, -2 },
166 [_]i64{ -5, -3, -2 },166 [_]i64{ -5, -3, -2 },
167167
168 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 1, 0 },168 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1, 0 },
169 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -1, 0 },169 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), -1, 0 },
170 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 2, 0 },170 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 2, 0 },
171 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -2, 0 },171 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), -2, 0 },
172 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 3, -2 },172 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 3, -2 },
173 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -3, -2 },173 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), -3, -2 },
174 };174 };
175175
176 for (cases) |case| {176 for (cases) |case| {
...@@ -225,8 +225,8 @@ test "test_divmodsi4" {...@@ -225,8 +225,8 @@ test "test_divmodsi4" {
225 [_]i32{ 19, 5, 3, 4 },225 [_]i32{ 19, 5, 3, 4 },
226 [_]i32{ 19, -5, -3, 4 },226 [_]i32{ 19, -5, -3, 4 },
227227
228 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 8, @bitCast(i32, @as(u32, 0xf0000000)), 0 },228 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), 8, @as(i32, @bitCast(@as(u32, 0xf0000000))), 0 },
229 [_]i32{ @bitCast(i32, @as(u32, 0x80000007)), 8, @bitCast(i32, @as(u32, 0xf0000001)), -1 },229 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000007))), 8, @as(i32, @bitCast(@as(u32, 0xf0000001))), -1 },
230 };230 };
231231
232 for (cases) |case| {232 for (cases) |case| {
...@@ -242,7 +242,7 @@ fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) !void {...@@ -242,7 +242,7 @@ fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) !void {
242242
243pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {243pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {
244 const d = __udivsi3(a, b);244 const d = __udivsi3(a, b);
245 rem.* = @bitCast(u32, @bitCast(i32, a) -% (@bitCast(i32, d) * @bitCast(i32, b)));245 rem.* = @as(u32, @bitCast(@as(i32, @bitCast(a)) -% (@as(i32, @bitCast(d)) * @as(i32, @bitCast(b)))));
246 return d;246 return d;
247}247}
248248
...@@ -256,14 +256,14 @@ fn __aeabi_idiv(n: i32, d: i32) callconv(.AAPCS) i32 {...@@ -256,14 +256,14 @@ fn __aeabi_idiv(n: i32, d: i32) callconv(.AAPCS) i32 {
256256
257inline fn div_i32(n: i32, d: i32) i32 {257inline fn div_i32(n: i32, d: i32) i32 {
258 // Set aside the sign of the quotient.258 // Set aside the sign of the quotient.
259 const sign = @bitCast(u32, (n ^ d) >> 31);259 const sign = @as(u32, @bitCast((n ^ d) >> 31));
260 // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).260 // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
261 const abs_n = (n ^ (n >> 31)) -% (n >> 31);261 const abs_n = (n ^ (n >> 31)) -% (n >> 31);
262 const abs_d = (d ^ (d >> 31)) -% (d >> 31);262 const abs_d = (d ^ (d >> 31)) -% (d >> 31);
263 // abs(a) / abs(b)263 // abs(a) / abs(b)
264 const res = @bitCast(u32, abs_n) / @bitCast(u32, abs_d);264 const res = @as(u32, @bitCast(abs_n)) / @as(u32, @bitCast(abs_d));
265 // Apply sign of quotient to result and return.265 // Apply sign of quotient to result and return.
266 return @bitCast(i32, (res ^ sign) -% sign);266 return @as(i32, @bitCast((res ^ sign) -% sign));
267}267}
268268
269test "test_divsi3" {269test "test_divsi3" {
...@@ -275,10 +275,10 @@ test "test_divsi3" {...@@ -275,10 +275,10 @@ test "test_divsi3" {
275 [_]i32{ -2, 1, -2 },275 [_]i32{ -2, 1, -2 },
276 [_]i32{ -2, -1, 2 },276 [_]i32{ -2, -1, 2 },
277277
278 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 1, @bitCast(i32, @as(u32, 0x80000000)) },278 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), 1, @as(i32, @bitCast(@as(u32, 0x80000000))) },
279 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), -1, @bitCast(i32, @as(u32, 0x80000000)) },279 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), -1, @as(i32, @bitCast(@as(u32, 0x80000000))) },
280 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), -2, 0x40000000 },280 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), -2, 0x40000000 },
281 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 2, @bitCast(i32, @as(u32, 0xC0000000)) },281 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), 2, @as(i32, @bitCast(@as(u32, 0xC0000000))) },
282 };282 };
283283
284 for (cases) |case| {284 for (cases) |case| {
...@@ -304,7 +304,7 @@ inline fn div_u32(n: u32, d: u32) u32 {...@@ -304,7 +304,7 @@ inline fn div_u32(n: u32, d: u32) u32 {
304 // special cases304 // special cases
305 if (d == 0) return 0; // ?!305 if (d == 0) return 0; // ?!
306 if (n == 0) return 0;306 if (n == 0) return 0;
307 var sr = @bitCast(c_uint, @as(c_int, @clz(d)) - @as(c_int, @clz(n)));307 var sr = @as(c_uint, @bitCast(@as(c_int, @clz(d)) - @as(c_int, @clz(n))));
308 // 0 <= sr <= n_uword_bits - 1 or sr large308 // 0 <= sr <= n_uword_bits - 1 or sr large
309 if (sr > n_uword_bits - 1) {309 if (sr > n_uword_bits - 1) {
310 // d > r310 // d > r
...@@ -317,12 +317,12 @@ inline fn div_u32(n: u32, d: u32) u32 {...@@ -317,12 +317,12 @@ inline fn div_u32(n: u32, d: u32) u32 {
317 sr += 1;317 sr += 1;
318 // 1 <= sr <= n_uword_bits - 1318 // 1 <= sr <= n_uword_bits - 1
319 // Not a special case319 // Not a special case
320 var q: u32 = n << @intCast(u5, n_uword_bits - sr);320 var q: u32 = n << @as(u5, @intCast(n_uword_bits - sr));
321 var r: u32 = n >> @intCast(u5, sr);321 var r: u32 = n >> @as(u5, @intCast(sr));
322 var carry: u32 = 0;322 var carry: u32 = 0;
323 while (sr > 0) : (sr -= 1) {323 while (sr > 0) : (sr -= 1) {
324 // r:q = ((r:q) << 1) | carry324 // r:q = ((r:q) << 1) | carry
325 r = (r << 1) | (q >> @intCast(u5, n_uword_bits - 1));325 r = (r << 1) | (q >> @as(u5, @intCast(n_uword_bits - 1)));
326 q = (q << 1) | carry;326 q = (q << 1) | carry;
327 // carry = 0;327 // carry = 0;
328 // if (r.all >= d.all)328 // if (r.all >= d.all)
...@@ -330,9 +330,9 @@ inline fn div_u32(n: u32, d: u32) u32 {...@@ -330,9 +330,9 @@ inline fn div_u32(n: u32, d: u32) u32 {
330 // r.all -= d.all;330 // r.all -= d.all;
331 // carry = 1;331 // carry = 1;
332 // }332 // }
333 const s = @bitCast(i32, d -% r -% 1) >> @intCast(u5, n_uword_bits - 1);333 const s = @as(i32, @bitCast(d -% r -% 1)) >> @as(u5, @intCast(n_uword_bits - 1));
334 carry = @intCast(u32, s & 1);334 carry = @as(u32, @intCast(s & 1));
335 r -= d & @bitCast(u32, s);335 r -= d & @as(u32, @bitCast(s));
336 }336 }
337 q = (q << 1) | carry;337 q = (q << 1) | carry;
338 return q;338 return q;
...@@ -496,11 +496,11 @@ test "test_modsi3" {...@@ -496,11 +496,11 @@ test "test_modsi3" {
496 [_]i32{ 5, -3, 2 },496 [_]i32{ 5, -3, 2 },
497 [_]i32{ -5, 3, -2 },497 [_]i32{ -5, 3, -2 },
498 [_]i32{ -5, -3, -2 },498 [_]i32{ -5, -3, -2 },
499 [_]i32{ @bitCast(i32, @intCast(u32, 0x80000000)), 1, 0x0 },499 [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 1, 0x0 },
500 [_]i32{ @bitCast(i32, @intCast(u32, 0x80000000)), 2, 0x0 },500 [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 2, 0x0 },
501 [_]i32{ @bitCast(i32, @intCast(u32, 0x80000000)), -2, 0x0 },501 [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), -2, 0x0 },
502 [_]i32{ @bitCast(i32, @intCast(u32, 0x80000000)), 3, -2 },502 [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 3, -2 },
503 [_]i32{ @bitCast(i32, @intCast(u32, 0x80000000)), -3, -2 },503 [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), -3, -2 },
504 };504 };
505505
506 for (cases) |case| {506 for (cases) |case| {
lib/compiler_rt/int_from_float.zig+6-6
...@@ -17,9 +17,9 @@ pub inline fn intFromFloat(comptime I: type, a: anytype) I {...@@ -17,9 +17,9 @@ pub inline fn intFromFloat(comptime I: type, a: anytype) I {
17 const sig_mask = (@as(rep_t, 1) << sig_bits) - 1;17 const sig_mask = (@as(rep_t, 1) << sig_bits) - 1;
1818
19 // Break a into sign, exponent, significand19 // Break a into sign, exponent, significand
20 const a_rep: rep_t = @bitCast(rep_t, a);20 const a_rep: rep_t = @as(rep_t, @bitCast(a));
21 const negative = (a_rep >> (float_bits - 1)) != 0;21 const negative = (a_rep >> (float_bits - 1)) != 0;
22 const exponent = @intCast(i32, (a_rep << 1) >> (sig_bits + 1)) - exp_bias;22 const exponent = @as(i32, @intCast((a_rep << 1) >> (sig_bits + 1))) - exp_bias;
23 const significand: rep_t = (a_rep & sig_mask) | implicit_bit;23 const significand: rep_t = (a_rep & sig_mask) | implicit_bit;
2424
25 // If the exponent is negative, the result rounds to zero.25 // If the exponent is negative, the result rounds to zero.
...@@ -29,9 +29,9 @@ pub inline fn intFromFloat(comptime I: type, a: anytype) I {...@@ -29,9 +29,9 @@ pub inline fn intFromFloat(comptime I: type, a: anytype) I {
29 switch (@typeInfo(I).Int.signedness) {29 switch (@typeInfo(I).Int.signedness) {
30 .unsigned => {30 .unsigned => {
31 if (negative) return 0;31 if (negative) return 0;
32 if (@intCast(c_uint, exponent) >= @min(int_bits, max_exp)) return math.maxInt(I);32 if (@as(c_uint, @intCast(exponent)) >= @min(int_bits, max_exp)) return math.maxInt(I);
33 },33 },
34 .signed => if (@intCast(c_uint, exponent) >= @min(int_bits - 1, max_exp)) {34 .signed => if (@as(c_uint, @intCast(exponent)) >= @min(int_bits - 1, max_exp)) {
35 return if (negative) math.minInt(I) else math.maxInt(I);35 return if (negative) math.minInt(I) else math.maxInt(I);
36 },36 },
37 }37 }
...@@ -40,9 +40,9 @@ pub inline fn intFromFloat(comptime I: type, a: anytype) I {...@@ -40,9 +40,9 @@ pub inline fn intFromFloat(comptime I: type, a: anytype) I {
40 // Otherwise, shift left.40 // Otherwise, shift left.
41 var result: I = undefined;41 var result: I = undefined;
42 if (exponent < fractional_bits) {42 if (exponent < fractional_bits) {
43 result = @intCast(I, significand >> @intCast(Log2Int(rep_t), fractional_bits - exponent));43 result = @as(I, @intCast(significand >> @as(Log2Int(rep_t), @intCast(fractional_bits - exponent))));
44 } else {44 } else {
45 result = @intCast(I, significand) << @intCast(Log2Int(I), exponent - fractional_bits);45 result = @as(I, @intCast(significand)) << @as(Log2Int(I), @intCast(exponent - fractional_bits));
46 }46 }
4747
48 if ((@typeInfo(I).Int.signedness == .signed) and negative)48 if ((@typeInfo(I).Int.signedness == .signed) and negative)
lib/compiler_rt/log.zig+14-14
...@@ -27,7 +27,7 @@ comptime {...@@ -27,7 +27,7 @@ comptime {
2727
28pub fn __logh(a: f16) callconv(.C) f16 {28pub fn __logh(a: f16) callconv(.C) f16 {
29 // TODO: more efficient implementation29 // TODO: more efficient implementation
30 return @floatCast(f16, logf(a));30 return @as(f16, @floatCast(logf(a)));
31}31}
3232
33pub fn logf(x_: f32) callconv(.C) f32 {33pub fn logf(x_: f32) callconv(.C) f32 {
...@@ -39,7 +39,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {...@@ -39,7 +39,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {
39 const Lg4: f32 = 0xf89e26.0p-26;39 const Lg4: f32 = 0xf89e26.0p-26;
4040
41 var x = x_;41 var x = x_;
42 var ix = @bitCast(u32, x);42 var ix = @as(u32, @bitCast(x));
43 var k: i32 = 0;43 var k: i32 = 0;
4444
45 // x < 2^(-126)45 // x < 2^(-126)
...@@ -56,7 +56,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {...@@ -56,7 +56,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {
56 // subnormal, scale x56 // subnormal, scale x
57 k -= 25;57 k -= 25;
58 x *= 0x1.0p25;58 x *= 0x1.0p25;
59 ix = @bitCast(u32, x);59 ix = @as(u32, @bitCast(x));
60 } else if (ix >= 0x7F800000) {60 } else if (ix >= 0x7F800000) {
61 return x;61 return x;
62 } else if (ix == 0x3F800000) {62 } else if (ix == 0x3F800000) {
...@@ -65,9 +65,9 @@ pub fn logf(x_: f32) callconv(.C) f32 {...@@ -65,9 +65,9 @@ pub fn logf(x_: f32) callconv(.C) f32 {
6565
66 // x into [sqrt(2) / 2, sqrt(2)]66 // x into [sqrt(2) / 2, sqrt(2)]
67 ix += 0x3F800000 - 0x3F3504F3;67 ix += 0x3F800000 - 0x3F3504F3;
68 k += @intCast(i32, ix >> 23) - 0x7F;68 k += @as(i32, @intCast(ix >> 23)) - 0x7F;
69 ix = (ix & 0x007FFFFF) + 0x3F3504F3;69 ix = (ix & 0x007FFFFF) + 0x3F3504F3;
70 x = @bitCast(f32, ix);70 x = @as(f32, @bitCast(ix));
7171
72 const f = x - 1.0;72 const f = x - 1.0;
73 const s = f / (2.0 + f);73 const s = f / (2.0 + f);
...@@ -77,7 +77,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {...@@ -77,7 +77,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {
77 const t2 = z * (Lg1 + w * Lg3);77 const t2 = z * (Lg1 + w * Lg3);
78 const R = t2 + t1;78 const R = t2 + t1;
79 const hfsq = 0.5 * f * f;79 const hfsq = 0.5 * f * f;
80 const dk = @floatFromInt(f32, k);80 const dk = @as(f32, @floatFromInt(k));
8181
82 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;82 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
83}83}
...@@ -94,8 +94,8 @@ pub fn log(x_: f64) callconv(.C) f64 {...@@ -94,8 +94,8 @@ pub fn log(x_: f64) callconv(.C) f64 {
94 const Lg7: f64 = 1.479819860511658591e-01;94 const Lg7: f64 = 1.479819860511658591e-01;
9595
96 var x = x_;96 var x = x_;
97 var ix = @bitCast(u64, x);97 var ix = @as(u64, @bitCast(x));
98 var hx = @intCast(u32, ix >> 32);98 var hx = @as(u32, @intCast(ix >> 32));
99 var k: i32 = 0;99 var k: i32 = 0;
100100
101 if (hx < 0x00100000 or hx >> 31 != 0) {101 if (hx < 0x00100000 or hx >> 31 != 0) {
...@@ -111,7 +111,7 @@ pub fn log(x_: f64) callconv(.C) f64 {...@@ -111,7 +111,7 @@ pub fn log(x_: f64) callconv(.C) f64 {
111 // subnormal, scale x111 // subnormal, scale x
112 k -= 54;112 k -= 54;
113 x *= 0x1.0p54;113 x *= 0x1.0p54;
114 hx = @intCast(u32, @bitCast(u64, ix) >> 32);114 hx = @as(u32, @intCast(@as(u64, @bitCast(ix)) >> 32));
115 } else if (hx >= 0x7FF00000) {115 } else if (hx >= 0x7FF00000) {
116 return x;116 return x;
117 } else if (hx == 0x3FF00000 and ix << 32 == 0) {117 } else if (hx == 0x3FF00000 and ix << 32 == 0) {
...@@ -120,10 +120,10 @@ pub fn log(x_: f64) callconv(.C) f64 {...@@ -120,10 +120,10 @@ pub fn log(x_: f64) callconv(.C) f64 {
120120
121 // x into [sqrt(2) / 2, sqrt(2)]121 // x into [sqrt(2) / 2, sqrt(2)]
122 hx += 0x3FF00000 - 0x3FE6A09E;122 hx += 0x3FF00000 - 0x3FE6A09E;
123 k += @intCast(i32, hx >> 20) - 0x3FF;123 k += @as(i32, @intCast(hx >> 20)) - 0x3FF;
124 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;124 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
125 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);125 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
126 x = @bitCast(f64, ix);126 x = @as(f64, @bitCast(ix));
127127
128 const f = x - 1.0;128 const f = x - 1.0;
129 const hfsq = 0.5 * f * f;129 const hfsq = 0.5 * f * f;
...@@ -133,19 +133,19 @@ pub fn log(x_: f64) callconv(.C) f64 {...@@ -133,19 +133,19 @@ pub fn log(x_: f64) callconv(.C) f64 {
133 const t1 = w * (Lg2 + w * (Lg4 + w * Lg6));133 const t1 = w * (Lg2 + w * (Lg4 + w * Lg6));
134 const t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));134 const t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));
135 const R = t2 + t1;135 const R = t2 + t1;
136 const dk = @floatFromInt(f64, k);136 const dk = @as(f64, @floatFromInt(k));
137137
138 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;138 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
139}139}
140140
141pub fn __logx(a: f80) callconv(.C) f80 {141pub fn __logx(a: f80) callconv(.C) f80 {
142 // TODO: more efficient implementation142 // TODO: more efficient implementation
143 return @floatCast(f80, logq(a));143 return @as(f80, @floatCast(logq(a)));
144}144}
145145
146pub fn logq(a: f128) callconv(.C) f128 {146pub fn logq(a: f128) callconv(.C) f128 {
147 // TODO: more correct implementation147 // TODO: more correct implementation
148 return log(@floatCast(f64, a));148 return log(@as(f64, @floatCast(a)));
149}149}
150150
151pub fn logl(x: c_longdouble) callconv(.C) c_longdouble {151pub fn logl(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/log10.zig+18-18
...@@ -28,7 +28,7 @@ comptime {...@@ -28,7 +28,7 @@ comptime {
2828
29pub fn __log10h(a: f16) callconv(.C) f16 {29pub fn __log10h(a: f16) callconv(.C) f16 {
30 // TODO: more efficient implementation30 // TODO: more efficient implementation
31 return @floatCast(f16, log10f(a));31 return @as(f16, @floatCast(log10f(a)));
32}32}
3333
34pub fn log10f(x_: f32) callconv(.C) f32 {34pub fn log10f(x_: f32) callconv(.C) f32 {
...@@ -42,7 +42,7 @@ pub fn log10f(x_: f32) callconv(.C) f32 {...@@ -42,7 +42,7 @@ pub fn log10f(x_: f32) callconv(.C) f32 {
42 const Lg4: f32 = 0xf89e26.0p-26;42 const Lg4: f32 = 0xf89e26.0p-26;
4343
44 var x = x_;44 var x = x_;
45 var u = @bitCast(u32, x);45 var u = @as(u32, @bitCast(x));
46 var ix = u;46 var ix = u;
47 var k: i32 = 0;47 var k: i32 = 0;
4848
...@@ -59,7 +59,7 @@ pub fn log10f(x_: f32) callconv(.C) f32 {...@@ -59,7 +59,7 @@ pub fn log10f(x_: f32) callconv(.C) f32 {
5959
60 k -= 25;60 k -= 25;
61 x *= 0x1.0p25;61 x *= 0x1.0p25;
62 ix = @bitCast(u32, x);62 ix = @as(u32, @bitCast(x));
63 } else if (ix >= 0x7F800000) {63 } else if (ix >= 0x7F800000) {
64 return x;64 return x;
65 } else if (ix == 0x3F800000) {65 } else if (ix == 0x3F800000) {
...@@ -68,9 +68,9 @@ pub fn log10f(x_: f32) callconv(.C) f32 {...@@ -68,9 +68,9 @@ pub fn log10f(x_: f32) callconv(.C) f32 {
6868
69 // x into [sqrt(2) / 2, sqrt(2)]69 // x into [sqrt(2) / 2, sqrt(2)]
70 ix += 0x3F800000 - 0x3F3504F3;70 ix += 0x3F800000 - 0x3F3504F3;
71 k += @intCast(i32, ix >> 23) - 0x7F;71 k += @as(i32, @intCast(ix >> 23)) - 0x7F;
72 ix = (ix & 0x007FFFFF) + 0x3F3504F3;72 ix = (ix & 0x007FFFFF) + 0x3F3504F3;
73 x = @bitCast(f32, ix);73 x = @as(f32, @bitCast(ix));
7474
75 const f = x - 1.0;75 const f = x - 1.0;
76 const s = f / (2.0 + f);76 const s = f / (2.0 + f);
...@@ -82,11 +82,11 @@ pub fn log10f(x_: f32) callconv(.C) f32 {...@@ -82,11 +82,11 @@ pub fn log10f(x_: f32) callconv(.C) f32 {
82 const hfsq = 0.5 * f * f;82 const hfsq = 0.5 * f * f;
8383
84 var hi = f - hfsq;84 var hi = f - hfsq;
85 u = @bitCast(u32, hi);85 u = @as(u32, @bitCast(hi));
86 u &= 0xFFFFF000;86 u &= 0xFFFFF000;
87 hi = @bitCast(f32, u);87 hi = @as(f32, @bitCast(u));
88 const lo = f - hi - hfsq + s * (hfsq + R);88 const lo = f - hi - hfsq + s * (hfsq + R);
89 const dk = @floatFromInt(f32, k);89 const dk = @as(f32, @floatFromInt(k));
9090
91 return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi;91 return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi;
92}92}
...@@ -105,8 +105,8 @@ pub fn log10(x_: f64) callconv(.C) f64 {...@@ -105,8 +105,8 @@ pub fn log10(x_: f64) callconv(.C) f64 {
105 const Lg7: f64 = 1.479819860511658591e-01;105 const Lg7: f64 = 1.479819860511658591e-01;
106106
107 var x = x_;107 var x = x_;
108 var ix = @bitCast(u64, x);108 var ix = @as(u64, @bitCast(x));
109 var hx = @intCast(u32, ix >> 32);109 var hx = @as(u32, @intCast(ix >> 32));
110 var k: i32 = 0;110 var k: i32 = 0;
111111
112 if (hx < 0x00100000 or hx >> 31 != 0) {112 if (hx < 0x00100000 or hx >> 31 != 0) {
...@@ -122,7 +122,7 @@ pub fn log10(x_: f64) callconv(.C) f64 {...@@ -122,7 +122,7 @@ pub fn log10(x_: f64) callconv(.C) f64 {
122 // subnormal, scale x122 // subnormal, scale x
123 k -= 54;123 k -= 54;
124 x *= 0x1.0p54;124 x *= 0x1.0p54;
125 hx = @intCast(u32, @bitCast(u64, x) >> 32);125 hx = @as(u32, @intCast(@as(u64, @bitCast(x)) >> 32));
126 } else if (hx >= 0x7FF00000) {126 } else if (hx >= 0x7FF00000) {
127 return x;127 return x;
128 } else if (hx == 0x3FF00000 and ix << 32 == 0) {128 } else if (hx == 0x3FF00000 and ix << 32 == 0) {
...@@ -131,10 +131,10 @@ pub fn log10(x_: f64) callconv(.C) f64 {...@@ -131,10 +131,10 @@ pub fn log10(x_: f64) callconv(.C) f64 {
131131
132 // x into [sqrt(2) / 2, sqrt(2)]132 // x into [sqrt(2) / 2, sqrt(2)]
133 hx += 0x3FF00000 - 0x3FE6A09E;133 hx += 0x3FF00000 - 0x3FE6A09E;
134 k += @intCast(i32, hx >> 20) - 0x3FF;134 k += @as(i32, @intCast(hx >> 20)) - 0x3FF;
135 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;135 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
136 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);136 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
137 x = @bitCast(f64, ix);137 x = @as(f64, @bitCast(ix));
138138
139 const f = x - 1.0;139 const f = x - 1.0;
140 const hfsq = 0.5 * f * f;140 const hfsq = 0.5 * f * f;
...@@ -147,14 +147,14 @@ pub fn log10(x_: f64) callconv(.C) f64 {...@@ -147,14 +147,14 @@ pub fn log10(x_: f64) callconv(.C) f64 {
147147
148 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)148 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
149 var hi = f - hfsq;149 var hi = f - hfsq;
150 var hii = @bitCast(u64, hi);150 var hii = @as(u64, @bitCast(hi));
151 hii &= @as(u64, maxInt(u64)) << 32;151 hii &= @as(u64, maxInt(u64)) << 32;
152 hi = @bitCast(f64, hii);152 hi = @as(f64, @bitCast(hii));
153 const lo = f - hi - hfsq + s * (hfsq + R);153 const lo = f - hi - hfsq + s * (hfsq + R);
154154
155 // val_hi + val_lo ~ log10(1 + f) + k * log10(2)155 // val_hi + val_lo ~ log10(1 + f) + k * log10(2)
156 var val_hi = hi * ivln10hi;156 var val_hi = hi * ivln10hi;
157 const dk = @floatFromInt(f64, k);157 const dk = @as(f64, @floatFromInt(k));
158 const y = dk * log10_2hi;158 const y = dk * log10_2hi;
159 var val_lo = dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi;159 var val_lo = dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi;
160160
...@@ -168,12 +168,12 @@ pub fn log10(x_: f64) callconv(.C) f64 {...@@ -168,12 +168,12 @@ pub fn log10(x_: f64) callconv(.C) f64 {
168168
169pub fn __log10x(a: f80) callconv(.C) f80 {169pub fn __log10x(a: f80) callconv(.C) f80 {
170 // TODO: more efficient implementation170 // TODO: more efficient implementation
171 return @floatCast(f80, log10q(a));171 return @as(f80, @floatCast(log10q(a)));
172}172}
173173
174pub fn log10q(a: f128) callconv(.C) f128 {174pub fn log10q(a: f128) callconv(.C) f128 {
175 // TODO: more correct implementation175 // TODO: more correct implementation
176 return log10(@floatCast(f64, a));176 return log10(@as(f64, @floatCast(a)));
177}177}
178178
179pub fn log10l(x: c_longdouble) callconv(.C) c_longdouble {179pub fn log10l(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/log2.zig+18-18
...@@ -28,7 +28,7 @@ comptime {...@@ -28,7 +28,7 @@ comptime {
2828
29pub fn __log2h(a: f16) callconv(.C) f16 {29pub fn __log2h(a: f16) callconv(.C) f16 {
30 // TODO: more efficient implementation30 // TODO: more efficient implementation
31 return @floatCast(f16, log2f(a));31 return @as(f16, @floatCast(log2f(a)));
32}32}
3333
34pub fn log2f(x_: f32) callconv(.C) f32 {34pub fn log2f(x_: f32) callconv(.C) f32 {
...@@ -40,7 +40,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 {...@@ -40,7 +40,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 {
40 const Lg4: f32 = 0xf89e26.0p-26;40 const Lg4: f32 = 0xf89e26.0p-26;
4141
42 var x = x_;42 var x = x_;
43 var u = @bitCast(u32, x);43 var u = @as(u32, @bitCast(x));
44 var ix = u;44 var ix = u;
45 var k: i32 = 0;45 var k: i32 = 0;
4646
...@@ -57,7 +57,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 {...@@ -57,7 +57,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 {
5757
58 k -= 25;58 k -= 25;
59 x *= 0x1.0p25;59 x *= 0x1.0p25;
60 ix = @bitCast(u32, x);60 ix = @as(u32, @bitCast(x));
61 } else if (ix >= 0x7F800000) {61 } else if (ix >= 0x7F800000) {
62 return x;62 return x;
63 } else if (ix == 0x3F800000) {63 } else if (ix == 0x3F800000) {
...@@ -66,9 +66,9 @@ pub fn log2f(x_: f32) callconv(.C) f32 {...@@ -66,9 +66,9 @@ pub fn log2f(x_: f32) callconv(.C) f32 {
6666
67 // x into [sqrt(2) / 2, sqrt(2)]67 // x into [sqrt(2) / 2, sqrt(2)]
68 ix += 0x3F800000 - 0x3F3504F3;68 ix += 0x3F800000 - 0x3F3504F3;
69 k += @intCast(i32, ix >> 23) - 0x7F;69 k += @as(i32, @intCast(ix >> 23)) - 0x7F;
70 ix = (ix & 0x007FFFFF) + 0x3F3504F3;70 ix = (ix & 0x007FFFFF) + 0x3F3504F3;
71 x = @bitCast(f32, ix);71 x = @as(f32, @bitCast(ix));
7272
73 const f = x - 1.0;73 const f = x - 1.0;
74 const s = f / (2.0 + f);74 const s = f / (2.0 + f);
...@@ -80,11 +80,11 @@ pub fn log2f(x_: f32) callconv(.C) f32 {...@@ -80,11 +80,11 @@ pub fn log2f(x_: f32) callconv(.C) f32 {
80 const hfsq = 0.5 * f * f;80 const hfsq = 0.5 * f * f;
8181
82 var hi = f - hfsq;82 var hi = f - hfsq;
83 u = @bitCast(u32, hi);83 u = @as(u32, @bitCast(hi));
84 u &= 0xFFFFF000;84 u &= 0xFFFFF000;
85 hi = @bitCast(f32, u);85 hi = @as(f32, @bitCast(u));
86 const lo = f - hi - hfsq + s * (hfsq + R);86 const lo = f - hi - hfsq + s * (hfsq + R);
87 return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + @floatFromInt(f32, k);87 return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + @as(f32, @floatFromInt(k));
88}88}
8989
90pub fn log2(x_: f64) callconv(.C) f64 {90pub fn log2(x_: f64) callconv(.C) f64 {
...@@ -99,8 +99,8 @@ pub fn log2(x_: f64) callconv(.C) f64 {...@@ -99,8 +99,8 @@ pub fn log2(x_: f64) callconv(.C) f64 {
99 const Lg7: f64 = 1.479819860511658591e-01;99 const Lg7: f64 = 1.479819860511658591e-01;
100100
101 var x = x_;101 var x = x_;
102 var ix = @bitCast(u64, x);102 var ix = @as(u64, @bitCast(x));
103 var hx = @intCast(u32, ix >> 32);103 var hx = @as(u32, @intCast(ix >> 32));
104 var k: i32 = 0;104 var k: i32 = 0;
105105
106 if (hx < 0x00100000 or hx >> 31 != 0) {106 if (hx < 0x00100000 or hx >> 31 != 0) {
...@@ -116,7 +116,7 @@ pub fn log2(x_: f64) callconv(.C) f64 {...@@ -116,7 +116,7 @@ pub fn log2(x_: f64) callconv(.C) f64 {
116 // subnormal, scale x116 // subnormal, scale x
117 k -= 54;117 k -= 54;
118 x *= 0x1.0p54;118 x *= 0x1.0p54;
119 hx = @intCast(u32, @bitCast(u64, x) >> 32);119 hx = @as(u32, @intCast(@as(u64, @bitCast(x)) >> 32));
120 } else if (hx >= 0x7FF00000) {120 } else if (hx >= 0x7FF00000) {
121 return x;121 return x;
122 } else if (hx == 0x3FF00000 and ix << 32 == 0) {122 } else if (hx == 0x3FF00000 and ix << 32 == 0) {
...@@ -125,10 +125,10 @@ pub fn log2(x_: f64) callconv(.C) f64 {...@@ -125,10 +125,10 @@ pub fn log2(x_: f64) callconv(.C) f64 {
125125
126 // x into [sqrt(2) / 2, sqrt(2)]126 // x into [sqrt(2) / 2, sqrt(2)]
127 hx += 0x3FF00000 - 0x3FE6A09E;127 hx += 0x3FF00000 - 0x3FE6A09E;
128 k += @intCast(i32, hx >> 20) - 0x3FF;128 k += @as(i32, @intCast(hx >> 20)) - 0x3FF;
129 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;129 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
130 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);130 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
131 x = @bitCast(f64, ix);131 x = @as(f64, @bitCast(ix));
132132
133 const f = x - 1.0;133 const f = x - 1.0;
134 const hfsq = 0.5 * f * f;134 const hfsq = 0.5 * f * f;
...@@ -141,16 +141,16 @@ pub fn log2(x_: f64) callconv(.C) f64 {...@@ -141,16 +141,16 @@ pub fn log2(x_: f64) callconv(.C) f64 {
141141
142 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)142 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
143 var hi = f - hfsq;143 var hi = f - hfsq;
144 var hii = @bitCast(u64, hi);144 var hii = @as(u64, @bitCast(hi));
145 hii &= @as(u64, maxInt(u64)) << 32;145 hii &= @as(u64, maxInt(u64)) << 32;
146 hi = @bitCast(f64, hii);146 hi = @as(f64, @bitCast(hii));
147 const lo = f - hi - hfsq + s * (hfsq + R);147 const lo = f - hi - hfsq + s * (hfsq + R);
148148
149 var val_hi = hi * ivln2hi;149 var val_hi = hi * ivln2hi;
150 var val_lo = (lo + hi) * ivln2lo + lo * ivln2hi;150 var val_lo = (lo + hi) * ivln2lo + lo * ivln2hi;
151151
152 // spadd(val_hi, val_lo, y)152 // spadd(val_hi, val_lo, y)
153 const y = @floatFromInt(f64, k);153 const y = @as(f64, @floatFromInt(k));
154 const ww = y + val_hi;154 const ww = y + val_hi;
155 val_lo += (y - ww) + val_hi;155 val_lo += (y - ww) + val_hi;
156 val_hi = ww;156 val_hi = ww;
...@@ -160,12 +160,12 @@ pub fn log2(x_: f64) callconv(.C) f64 {...@@ -160,12 +160,12 @@ pub fn log2(x_: f64) callconv(.C) f64 {
160160
161pub fn __log2x(a: f80) callconv(.C) f80 {161pub fn __log2x(a: f80) callconv(.C) f80 {
162 // TODO: more efficient implementation162 // TODO: more efficient implementation
163 return @floatCast(f80, log2q(a));163 return @as(f80, @floatCast(log2q(a)));
164}164}
165165
166pub fn log2q(a: f128) callconv(.C) f128 {166pub fn log2q(a: f128) callconv(.C) f128 {
167 // TODO: more correct implementation167 // TODO: more correct implementation
168 return log2(@floatCast(f64, a));168 return log2(@as(f64, @floatCast(a)));
169}169}
170170
171pub fn log2l(x: c_longdouble) callconv(.C) c_longdouble {171pub fn log2l(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/modti3.zig+3-3
...@@ -24,7 +24,7 @@ pub fn __modti3(a: i128, b: i128) callconv(.C) i128 {...@@ -24,7 +24,7 @@ pub fn __modti3(a: i128, b: i128) callconv(.C) i128 {
24const v2u64 = @Vector(2, u64);24const v2u64 = @Vector(2, u64);
2525
26fn __modti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {26fn __modti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {
27 return @bitCast(v2u64, mod(@bitCast(i128, a), @bitCast(i128, b)));27 return @as(v2u64, @bitCast(mod(@as(i128, @bitCast(a)), @as(i128, @bitCast(b)))));
28}28}
2929
30inline fn mod(a: i128, b: i128) i128 {30inline fn mod(a: i128, b: i128) i128 {
...@@ -35,8 +35,8 @@ inline fn mod(a: i128, b: i128) i128 {...@@ -35,8 +35,8 @@ inline fn mod(a: i128, b: i128) i128 {
35 const bn = (b ^ s_b) -% s_b; // negate if s == -135 const bn = (b ^ s_b) -% s_b; // negate if s == -1
3636
37 var r: u128 = undefined;37 var r: u128 = undefined;
38 _ = udivmod(u128, @bitCast(u128, an), @bitCast(u128, bn), &r);38 _ = udivmod(u128, @as(u128, @bitCast(an)), @as(u128, @bitCast(bn)), &r);
39 return (@bitCast(i128, r) ^ s_a) -% s_a; // negate if s == -139 return (@as(i128, @bitCast(r)) ^ s_a) -% s_a; // negate if s == -1
40}40}
4141
42test {42test {
lib/compiler_rt/modti3_test.zig+1-1
...@@ -33,5 +33,5 @@ fn make_ti(high: u64, low: u64) i128 {...@@ -33,5 +33,5 @@ fn make_ti(high: u64, low: u64) i128 {
33 var result: u128 = high;33 var result: u128 = high;
34 result <<= 64;34 result <<= 64;
35 result |= low;35 result |= low;
36 return @bitCast(i128, result);36 return @as(i128, @bitCast(result));
37}37}
lib/compiler_rt/mulXi3.zig+4-4
...@@ -21,8 +21,8 @@ comptime {...@@ -21,8 +21,8 @@ comptime {
21}21}
2222
23pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {23pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
24 var ua = @bitCast(u32, a);24 var ua = @as(u32, @bitCast(a));
25 var ub = @bitCast(u32, b);25 var ub = @as(u32, @bitCast(b));
26 var r: u32 = 0;26 var r: u32 = 0;
2727
28 while (ua > 0) {28 while (ua > 0) {
...@@ -31,7 +31,7 @@ pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {...@@ -31,7 +31,7 @@ pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
31 ub <<= 1;31 ub <<= 1;
32 }32 }
3333
34 return @bitCast(i32, r);34 return @as(i32, @bitCast(r));
35}35}
3636
37pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 {37pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 {
...@@ -93,7 +93,7 @@ pub fn __multi3(a: i128, b: i128) callconv(.C) i128 {...@@ -93,7 +93,7 @@ pub fn __multi3(a: i128, b: i128) callconv(.C) i128 {
93const v2u64 = @Vector(2, u64);93const v2u64 = @Vector(2, u64);
9494
95fn __multi3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {95fn __multi3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {
96 return @bitCast(v2u64, mulX(i128, @bitCast(i128, a), @bitCast(i128, b)));96 return @as(v2u64, @bitCast(mulX(i128, @as(i128, @bitCast(a)), @as(i128, @bitCast(b)))));
97}97}
9898
99test {99test {
lib/compiler_rt/mulXi3_test.zig+8-8
...@@ -46,14 +46,14 @@ test "mulsi3" {...@@ -46,14 +46,14 @@ test "mulsi3" {
46 try test_one_mulsi3(-46340, 46340, -2147395600);46 try test_one_mulsi3(-46340, 46340, -2147395600);
47 try test_one_mulsi3(46340, -46340, -2147395600);47 try test_one_mulsi3(46340, -46340, -2147395600);
48 try test_one_mulsi3(-46340, -46340, 2147395600);48 try test_one_mulsi3(-46340, -46340, 2147395600);
49 try test_one_mulsi3(4194303, 8192, @truncate(i32, 34359730176));49 try test_one_mulsi3(4194303, 8192, @as(i32, @truncate(34359730176)));
50 try test_one_mulsi3(-4194303, 8192, @truncate(i32, -34359730176));50 try test_one_mulsi3(-4194303, 8192, @as(i32, @truncate(-34359730176)));
51 try test_one_mulsi3(4194303, -8192, @truncate(i32, -34359730176));51 try test_one_mulsi3(4194303, -8192, @as(i32, @truncate(-34359730176)));
52 try test_one_mulsi3(-4194303, -8192, @truncate(i32, 34359730176));52 try test_one_mulsi3(-4194303, -8192, @as(i32, @truncate(34359730176)));
53 try test_one_mulsi3(8192, 4194303, @truncate(i32, 34359730176));53 try test_one_mulsi3(8192, 4194303, @as(i32, @truncate(34359730176)));
54 try test_one_mulsi3(-8192, 4194303, @truncate(i32, -34359730176));54 try test_one_mulsi3(-8192, 4194303, @as(i32, @truncate(-34359730176)));
55 try test_one_mulsi3(8192, -4194303, @truncate(i32, -34359730176));55 try test_one_mulsi3(8192, -4194303, @as(i32, @truncate(-34359730176)));
56 try test_one_mulsi3(-8192, -4194303, @truncate(i32, 34359730176));56 try test_one_mulsi3(-8192, -4194303, @as(i32, @truncate(34359730176)));
57}57}
5858
59test "muldi3" {59test "muldi3" {
lib/compiler_rt/mulf3.zig+30-30
...@@ -28,53 +28,53 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {...@@ -28,53 +28,53 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
28 const significandMask = (@as(Z, 1) << significandBits) - 1;28 const significandMask = (@as(Z, 1) << significandBits) - 1;
2929
30 const absMask = signBit - 1;30 const absMask = signBit - 1;
31 const qnanRep = @bitCast(Z, math.nan(T)) | quietBit;31 const qnanRep = @as(Z, @bitCast(math.nan(T))) | quietBit;
32 const infRep = @bitCast(Z, math.inf(T));32 const infRep = @as(Z, @bitCast(math.inf(T)));
33 const minNormalRep = @bitCast(Z, math.floatMin(T));33 const minNormalRep = @as(Z, @bitCast(math.floatMin(T)));
3434
35 const ZExp = if (typeWidth >= 32) u32 else Z;35 const ZExp = if (typeWidth >= 32) u32 else Z;
36 const aExponent = @truncate(ZExp, (@bitCast(Z, a) >> significandBits) & maxExponent);36 const aExponent = @as(ZExp, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
37 const bExponent = @truncate(ZExp, (@bitCast(Z, b) >> significandBits) & maxExponent);37 const bExponent = @as(ZExp, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
38 const productSign: Z = (@bitCast(Z, a) ^ @bitCast(Z, b)) & signBit;38 const productSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
3939
40 var aSignificand: ZSignificand = @intCast(ZSignificand, @bitCast(Z, a) & significandMask);40 var aSignificand: ZSignificand = @as(ZSignificand, @intCast(@as(Z, @bitCast(a)) & significandMask));
41 var bSignificand: ZSignificand = @intCast(ZSignificand, @bitCast(Z, b) & significandMask);41 var bSignificand: ZSignificand = @as(ZSignificand, @intCast(@as(Z, @bitCast(b)) & significandMask));
42 var scale: i32 = 0;42 var scale: i32 = 0;
4343
44 // Detect if a or b is zero, denormal, infinity, or NaN.44 // Detect if a or b is zero, denormal, infinity, or NaN.
45 if (aExponent -% 1 >= maxExponent - 1 or bExponent -% 1 >= maxExponent - 1) {45 if (aExponent -% 1 >= maxExponent - 1 or bExponent -% 1 >= maxExponent - 1) {
46 const aAbs: Z = @bitCast(Z, a) & absMask;46 const aAbs: Z = @as(Z, @bitCast(a)) & absMask;
47 const bAbs: Z = @bitCast(Z, b) & absMask;47 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
4848
49 // NaN * anything = qNaN49 // NaN * anything = qNaN
50 if (aAbs > infRep) return @bitCast(T, @bitCast(Z, a) | quietBit);50 if (aAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(a)) | quietBit));
51 // anything * NaN = qNaN51 // anything * NaN = qNaN
52 if (bAbs > infRep) return @bitCast(T, @bitCast(Z, b) | quietBit);52 if (bAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(b)) | quietBit));
5353
54 if (aAbs == infRep) {54 if (aAbs == infRep) {
55 // infinity * non-zero = +/- infinity55 // infinity * non-zero = +/- infinity
56 if (bAbs != 0) {56 if (bAbs != 0) {
57 return @bitCast(T, aAbs | productSign);57 return @as(T, @bitCast(aAbs | productSign));
58 } else {58 } else {
59 // infinity * zero = NaN59 // infinity * zero = NaN
60 return @bitCast(T, qnanRep);60 return @as(T, @bitCast(qnanRep));
61 }61 }
62 }62 }
6363
64 if (bAbs == infRep) {64 if (bAbs == infRep) {
65 //? non-zero * infinity = +/- infinity65 //? non-zero * infinity = +/- infinity
66 if (aAbs != 0) {66 if (aAbs != 0) {
67 return @bitCast(T, bAbs | productSign);67 return @as(T, @bitCast(bAbs | productSign));
68 } else {68 } else {
69 // zero * infinity = NaN69 // zero * infinity = NaN
70 return @bitCast(T, qnanRep);70 return @as(T, @bitCast(qnanRep));
71 }71 }
72 }72 }
7373
74 // zero * anything = +/- zero74 // zero * anything = +/- zero
75 if (aAbs == 0) return @bitCast(T, productSign);75 if (aAbs == 0) return @as(T, @bitCast(productSign));
76 // anything * zero = +/- zero76 // anything * zero = +/- zero
77 if (bAbs == 0) return @bitCast(T, productSign);77 if (bAbs == 0) return @as(T, @bitCast(productSign));
7878
79 // one or both of a or b is denormal, the other (if applicable) is a79 // one or both of a or b is denormal, the other (if applicable) is a
80 // normal number. Renormalize one or both of a and b, and set scale to80 // normal number. Renormalize one or both of a and b, and set scale to
...@@ -99,7 +99,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {...@@ -99,7 +99,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
99 const left_align_shift = ZSignificandBits - fractionalBits - 1;99 const left_align_shift = ZSignificandBits - fractionalBits - 1;
100 common.wideMultiply(ZSignificand, aSignificand, bSignificand << left_align_shift, &productHi, &productLo);100 common.wideMultiply(ZSignificand, aSignificand, bSignificand << left_align_shift, &productHi, &productLo);
101101
102 var productExponent: i32 = @intCast(i32, aExponent + bExponent) - exponentBias + scale;102 var productExponent: i32 = @as(i32, @intCast(aExponent + bExponent)) - exponentBias + scale;
103103
104 // Normalize the significand, adjust exponent if needed.104 // Normalize the significand, adjust exponent if needed.
105 if ((productHi & integerBit) != 0) {105 if ((productHi & integerBit) != 0) {
...@@ -110,7 +110,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {...@@ -110,7 +110,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
110 }110 }
111111
112 // If we have overflowed the type, return +/- infinity.112 // If we have overflowed the type, return +/- infinity.
113 if (productExponent >= maxExponent) return @bitCast(T, infRep | productSign);113 if (productExponent >= maxExponent) return @as(T, @bitCast(infRep | productSign));
114114
115 var result: Z = undefined;115 var result: Z = undefined;
116 if (productExponent <= 0) {116 if (productExponent <= 0) {
...@@ -120,8 +120,8 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {...@@ -120,8 +120,8 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
120 // a zero of the appropriate sign. Mathematically there is no need to120 // a zero of the appropriate sign. Mathematically there is no need to
121 // handle this case separately, but we make it a special case to121 // handle this case separately, but we make it a special case to
122 // simplify the shift logic.122 // simplify the shift logic.
123 const shift: u32 = @truncate(u32, @as(Z, 1) -% @bitCast(u32, productExponent));123 const shift: u32 = @as(u32, @truncate(@as(Z, 1) -% @as(u32, @bitCast(productExponent))));
124 if (shift >= ZSignificandBits) return @bitCast(T, productSign);124 if (shift >= ZSignificandBits) return @as(T, @bitCast(productSign));
125125
126 // Otherwise, shift the significand of the result so that the round126 // Otherwise, shift the significand of the result so that the round
127 // bit is the high bit of productLo.127 // bit is the high bit of productLo.
...@@ -135,7 +135,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {...@@ -135,7 +135,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
135 } else {135 } else {
136 // Result is normal before rounding; insert the exponent.136 // Result is normal before rounding; insert the exponent.
137 result = productHi & significandMask;137 result = productHi & significandMask;
138 result |= @intCast(Z, productExponent) << significandBits;138 result |= @as(Z, @intCast(productExponent)) << significandBits;
139 }139 }
140140
141 // Final rounding. The final result may overflow to infinity, or underflow141 // Final rounding. The final result may overflow to infinity, or underflow
...@@ -156,7 +156,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {...@@ -156,7 +156,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
156 // Insert the sign of the result:156 // Insert the sign of the result:
157 result |= productSign;157 result |= productSign;
158158
159 return @bitCast(T, result);159 return @as(T, @bitCast(result));
160}160}
161161
162/// Returns `true` if the right shift is inexact (i.e. any bit shifted out is non-zero)162/// Returns `true` if the right shift is inexact (i.e. any bit shifted out is non-zero)
...@@ -168,12 +168,12 @@ fn wideShrWithTruncation(comptime Z: type, hi: *Z, lo: *Z, count: u32) bool {...@@ -168,12 +168,12 @@ fn wideShrWithTruncation(comptime Z: type, hi: *Z, lo: *Z, count: u32) bool {
168 const S = math.Log2Int(Z);168 const S = math.Log2Int(Z);
169 var inexact = false;169 var inexact = false;
170 if (count < typeWidth) {170 if (count < typeWidth) {
171 inexact = (lo.* << @intCast(S, typeWidth -% count)) != 0;171 inexact = (lo.* << @as(S, @intCast(typeWidth -% count))) != 0;
172 lo.* = (hi.* << @intCast(S, typeWidth -% count)) | (lo.* >> @intCast(S, count));172 lo.* = (hi.* << @as(S, @intCast(typeWidth -% count))) | (lo.* >> @as(S, @intCast(count)));
173 hi.* = hi.* >> @intCast(S, count);173 hi.* = hi.* >> @as(S, @intCast(count));
174 } else if (count < 2 * typeWidth) {174 } else if (count < 2 * typeWidth) {
175 inexact = (hi.* << @intCast(S, 2 * typeWidth -% count) | lo.*) != 0;175 inexact = (hi.* << @as(S, @intCast(2 * typeWidth -% count)) | lo.*) != 0;
176 lo.* = hi.* >> @intCast(S, count -% typeWidth);176 lo.* = hi.* >> @as(S, @intCast(count -% typeWidth));
177 hi.* = 0;177 hi.* = 0;
178 } else {178 } else {
179 inexact = (hi.* | lo.*) != 0;179 inexact = (hi.* | lo.*) != 0;
...@@ -188,7 +188,7 @@ fn normalize(comptime T: type, significand: *PowerOfTwoSignificandZ(T)) i32 {...@@ -188,7 +188,7 @@ fn normalize(comptime T: type, significand: *PowerOfTwoSignificandZ(T)) i32 {
188 const integerBit = @as(Z, 1) << math.floatFractionalBits(T);188 const integerBit = @as(Z, 1) << math.floatFractionalBits(T);
189189
190 const shift = @clz(significand.*) - @clz(integerBit);190 const shift = @clz(significand.*) - @clz(integerBit);
191 significand.* <<= @intCast(math.Log2Int(Z), shift);191 significand.* <<= @as(math.Log2Int(Z), @intCast(shift));
192 return @as(i32, 1) - shift;192 return @as(i32, 1) - shift;
193}193}
194194
lib/compiler_rt/mulf3_test.zig+26-26
...@@ -4,8 +4,8 @@...@@ -4,8 +4,8 @@
44
5const std = @import("std");5const std = @import("std");
6const math = std.math;6const math = std.math;
7const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64);7const qnan128 = @as(f128, @bitCast(@as(u128, 0x7fff800000000000) << 64));
8const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64);8const inf128 = @as(f128, @bitCast(@as(u128, 0x7fff000000000000) << 64));
99
10const __multf3 = @import("multf3.zig").__multf3;10const __multf3 = @import("multf3.zig").__multf3;
11const __mulxf3 = @import("mulxf3.zig").__mulxf3;11const __mulxf3 = @import("mulxf3.zig").__mulxf3;
...@@ -16,9 +16,9 @@ const __mulsf3 = @import("mulsf3.zig").__mulsf3;...@@ -16,9 +16,9 @@ const __mulsf3 = @import("mulsf3.zig").__mulsf3;
16// use two 64-bit integers intead of one 128-bit integer16// use two 64-bit integers intead of one 128-bit integer
17// because 128-bit integer constant can't be assigned directly17// because 128-bit integer constant can't be assigned directly
18fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {18fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
19 const rep = @bitCast(u128, result);19 const rep = @as(u128, @bitCast(result));
20 const hi = @intCast(u64, rep >> 64);20 const hi = @as(u64, @intCast(rep >> 64));
21 const lo = @truncate(u64, rep);21 const lo = @as(u64, @truncate(rep));
2222
23 if (hi == expectedHi and lo == expectedLo) {23 if (hi == expectedHi and lo == expectedLo) {
24 return true;24 return true;
...@@ -45,7 +45,7 @@ fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {...@@ -45,7 +45,7 @@ fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
4545
46fn makeNaN128(rand: u64) f128 {46fn makeNaN128(rand: u64) f128 {
47 const int_result = @as(u128, 0x7fff000000000000 | (rand & 0xffffffffffff)) << 64;47 const int_result = @as(u128, 0x7fff000000000000 | (rand & 0xffffffffffff)) << 64;
48 const float_result = @bitCast(f128, int_result);48 const float_result = @as(f128, @bitCast(int_result));
49 return float_result;49 return float_result;
50}50}
51test "multf3" {51test "multf3" {
...@@ -60,15 +60,15 @@ test "multf3" {...@@ -60,15 +60,15 @@ test "multf3" {
6060
61 // any * any61 // any * any
62 try test__multf3(62 try test__multf3(
63 @bitCast(f128, @as(u128, 0x40042eab345678439abcdefea5678234)),63 @as(f128, @bitCast(@as(u128, 0x40042eab345678439abcdefea5678234))),
64 @bitCast(f128, @as(u128, 0x3ffeedcb34a235253948765432134675)),64 @as(f128, @bitCast(@as(u128, 0x3ffeedcb34a235253948765432134675))),
65 0x400423e7f9e3c9fc,65 0x400423e7f9e3c9fc,
66 0xd906c2c2a85777c4,66 0xd906c2c2a85777c4,
67 );67 );
6868
69 try test__multf3(69 try test__multf3(
70 @bitCast(f128, @as(u128, 0x3fcd353e45674d89abacc3a2ebf3ff50)),70 @as(f128, @bitCast(@as(u128, 0x3fcd353e45674d89abacc3a2ebf3ff50))),
71 @bitCast(f128, @as(u128, 0x3ff6ed8764648369535adf4be3214568)),71 @as(f128, @bitCast(@as(u128, 0x3ff6ed8764648369535adf4be3214568))),
72 0x3fc52a163c6223fc,72 0x3fc52a163c6223fc,
73 0xc94c4bf0430768b4,73 0xc94c4bf0430768b4,
74 );74 );
...@@ -81,8 +81,8 @@ test "multf3" {...@@ -81,8 +81,8 @@ test "multf3" {
81 );81 );
8282
83 try test__multf3(83 try test__multf3(
84 @bitCast(f128, @as(u128, 0x3f154356473c82a9fabf2d22ace345df)),84 @as(f128, @bitCast(@as(u128, 0x3f154356473c82a9fabf2d22ace345df))),
85 @bitCast(f128, @as(u128, 0x3e38eda98765476743ab21da23d45679)),85 @as(f128, @bitCast(@as(u128, 0x3e38eda98765476743ab21da23d45679))),
86 0x3d4f37c1a3137cae,86 0x3d4f37c1a3137cae,
87 0xfc6807048bc2836a,87 0xfc6807048bc2836a,
88 );88 );
...@@ -108,16 +108,16 @@ test "multf3" {...@@ -108,16 +108,16 @@ test "multf3" {
108 try test__multf3(2.0, math.floatTrueMin(f128), 0x0000_0000_0000_0000, 0x0000_0000_0000_0002);108 try test__multf3(2.0, math.floatTrueMin(f128), 0x0000_0000_0000_0000, 0x0000_0000_0000_0002);
109}109}
110110
111const qnan80 = @bitCast(f80, @bitCast(u80, math.nan(f80)) | (1 << (math.floatFractionalBits(f80) - 1)));111const qnan80 = @as(f80, @bitCast(@as(u80, @bitCast(math.nan(f80))) | (1 << (math.floatFractionalBits(f80) - 1))));
112112
113fn test__mulxf3(a: f80, b: f80, expected: u80) !void {113fn test__mulxf3(a: f80, b: f80, expected: u80) !void {
114 const x = __mulxf3(a, b);114 const x = __mulxf3(a, b);
115 const rep = @bitCast(u80, x);115 const rep = @as(u80, @bitCast(x));
116116
117 if (rep == expected)117 if (rep == expected)
118 return;118 return;
119119
120 if (math.isNan(@bitCast(f80, expected)) and math.isNan(x))120 if (math.isNan(@as(f80, @bitCast(expected))) and math.isNan(x))
121 return; // We don't currently test NaN payload propagation121 return; // We don't currently test NaN payload propagation
122122
123 return error.TestFailed;123 return error.TestFailed;
...@@ -125,33 +125,33 @@ fn test__mulxf3(a: f80, b: f80, expected: u80) !void {...@@ -125,33 +125,33 @@ fn test__mulxf3(a: f80, b: f80, expected: u80) !void {
125125
126test "mulxf3" {126test "mulxf3" {
127 // NaN * any = NaN127 // NaN * any = NaN
128 try test__mulxf3(qnan80, 0x1.23456789abcdefp+5, @bitCast(u80, qnan80));128 try test__mulxf3(qnan80, 0x1.23456789abcdefp+5, @as(u80, @bitCast(qnan80)));
129 try test__mulxf3(@bitCast(f80, @as(u80, 0x7fff_8000_8000_3000_0000)), 0x1.23456789abcdefp+5, @bitCast(u80, qnan80));129 try test__mulxf3(@as(f80, @bitCast(@as(u80, 0x7fff_8000_8000_3000_0000))), 0x1.23456789abcdefp+5, @as(u80, @bitCast(qnan80)));
130130
131 // any * NaN = NaN131 // any * NaN = NaN
132 try test__mulxf3(0x1.23456789abcdefp+5, qnan80, @bitCast(u80, qnan80));132 try test__mulxf3(0x1.23456789abcdefp+5, qnan80, @as(u80, @bitCast(qnan80)));
133 try test__mulxf3(0x1.23456789abcdefp+5, @bitCast(f80, @as(u80, 0x7fff_8000_8000_3000_0000)), @bitCast(u80, qnan80));133 try test__mulxf3(0x1.23456789abcdefp+5, @as(f80, @bitCast(@as(u80, 0x7fff_8000_8000_3000_0000))), @as(u80, @bitCast(qnan80)));
134134
135 // NaN * inf = NaN135 // NaN * inf = NaN
136 try test__mulxf3(qnan80, math.inf(f80), @bitCast(u80, qnan80));136 try test__mulxf3(qnan80, math.inf(f80), @as(u80, @bitCast(qnan80)));
137137
138 // inf * NaN = NaN138 // inf * NaN = NaN
139 try test__mulxf3(math.inf(f80), qnan80, @bitCast(u80, qnan80));139 try test__mulxf3(math.inf(f80), qnan80, @as(u80, @bitCast(qnan80)));
140140
141 // inf * inf = inf141 // inf * inf = inf
142 try test__mulxf3(math.inf(f80), math.inf(f80), @bitCast(u80, math.inf(f80)));142 try test__mulxf3(math.inf(f80), math.inf(f80), @as(u80, @bitCast(math.inf(f80))));
143143
144 // inf * -inf = -inf144 // inf * -inf = -inf
145 try test__mulxf3(math.inf(f80), -math.inf(f80), @bitCast(u80, -math.inf(f80)));145 try test__mulxf3(math.inf(f80), -math.inf(f80), @as(u80, @bitCast(-math.inf(f80))));
146146
147 // -inf + inf = -inf147 // -inf + inf = -inf
148 try test__mulxf3(-math.inf(f80), math.inf(f80), @bitCast(u80, -math.inf(f80)));148 try test__mulxf3(-math.inf(f80), math.inf(f80), @as(u80, @bitCast(-math.inf(f80))));
149149
150 // inf * any = inf150 // inf * any = inf
151 try test__mulxf3(math.inf(f80), 0x1.2335653452436234723489432abcdefp+5, @bitCast(u80, math.inf(f80)));151 try test__mulxf3(math.inf(f80), 0x1.2335653452436234723489432abcdefp+5, @as(u80, @bitCast(math.inf(f80))));
152152
153 // any * inf = inf153 // any * inf = inf
154 try test__mulxf3(0x1.2335653452436234723489432abcdefp+5, math.inf(f80), @bitCast(u80, math.inf(f80)));154 try test__mulxf3(0x1.2335653452436234723489432abcdefp+5, math.inf(f80), @as(u80, @bitCast(math.inf(f80))));
155155
156 // any * any156 // any * any
157 try test__mulxf3(0x1.0p+0, 0x1.dcba987654321p+5, 0x4004_ee5d_4c3b_2a19_0800);157 try test__mulxf3(0x1.0p+0, 0x1.dcba987654321p+5, 0x4004_ee5d_4c3b_2a19_0800);
lib/compiler_rt/mulo.zig+1-1
...@@ -45,7 +45,7 @@ inline fn muloXi4_genericFast(comptime ST: type, a: ST, b: ST, overflow: *c_int)...@@ -45,7 +45,7 @@ inline fn muloXi4_genericFast(comptime ST: type, a: ST, b: ST, overflow: *c_int)
45 //invariant: -2^{bitwidth(EST)} < res < 2^{bitwidth(EST)-1}45 //invariant: -2^{bitwidth(EST)} < res < 2^{bitwidth(EST)-1}
46 if (res < min or max < res)46 if (res < min or max < res)
47 overflow.* = 1;47 overflow.* = 1;
48 return @truncate(ST, res);48 return @as(ST, @truncate(res));
49}49}
5050
51pub fn __mulosi4(a: i32, b: i32, overflow: *c_int) callconv(.C) i32 {51pub fn __mulosi4(a: i32, b: i32, overflow: *c_int) callconv(.C) i32 {
lib/compiler_rt/mulodi4_test.zig+24-24
...@@ -54,34 +54,34 @@ test "mulodi4" {...@@ -54,34 +54,34 @@ test "mulodi4" {
5454
55 try test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1);55 try test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1);
56 try test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1);56 try test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1);
57 try test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);57 try test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @as(i64, @bitCast(@as(u64, 0x8000000000000001))), 0);
58 try test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);58 try test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @as(i64, @bitCast(@as(u64, 0x8000000000000001))), 0);
59 try test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0);59 try test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0);
60 try test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0);60 try test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0);
61 try test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0);61 try test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0);
62 try test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0);62 try test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0);
63 try test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);63 try test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @as(i64, @bitCast(@as(u64, 0x8000000000000001))), 1);
64 try test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);64 try test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @as(i64, @bitCast(@as(u64, 0x8000000000000001))), 1);
6565
66 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);66 try test__mulodi4(@as(i64, @bitCast(@as(u64, 0x8000000000000000))), -2, @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1);
67 try test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);67 try test__mulodi4(-2, @as(i64, @bitCast(@as(u64, 0x8000000000000000))), @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1);
68 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);68 try test__mulodi4(@as(i64, @bitCast(@as(u64, 0x8000000000000000))), -1, @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1);
69 try test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);69 try test__mulodi4(-1, @as(i64, @bitCast(@as(u64, 0x8000000000000000))), @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1);
70 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0, 0);70 try test__mulodi4(@as(i64, @bitCast(@as(u64, 0x8000000000000000))), 0, 0, 0);
71 try test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0);71 try test__mulodi4(0, @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 0, 0);
72 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)), 0);72 try test__mulodi4(@as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1, @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 0);
73 try test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 0);73 try test__mulodi4(1, @as(i64, @bitCast(@as(u64, 0x8000000000000000))), @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 0);
74 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);74 try test__mulodi4(@as(i64, @bitCast(@as(u64, 0x8000000000000000))), 2, @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1);
75 try test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);75 try test__mulodi4(2, @as(i64, @bitCast(@as(u64, 0x8000000000000000))), @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1);
7676
77 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);77 try test__mulodi4(@as(i64, @bitCast(@as(u64, 0x8000000000000001))), -2, @as(i64, @bitCast(@as(u64, 0x8000000000000001))), 1);
78 try test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 1);78 try test__mulodi4(-2, @as(i64, @bitCast(@as(u64, 0x8000000000000001))), @as(i64, @bitCast(@as(u64, 0x8000000000000001))), 1);
79 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0);79 try test__mulodi4(@as(i64, @bitCast(@as(u64, 0x8000000000000001))), -1, 0x7FFFFFFFFFFFFFFF, 0);
80 try test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0);80 try test__mulodi4(-1, @as(i64, @bitCast(@as(u64, 0x8000000000000001))), 0x7FFFFFFFFFFFFFFF, 0);
81 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0, 0);81 try test__mulodi4(@as(i64, @bitCast(@as(u64, 0x8000000000000001))), 0, 0, 0);
82 try test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0);82 try test__mulodi4(0, @as(i64, @bitCast(@as(u64, 0x8000000000000001))), 0, 0);
83 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);83 try test__mulodi4(@as(i64, @bitCast(@as(u64, 0x8000000000000001))), 1, @as(i64, @bitCast(@as(u64, 0x8000000000000001))), 0);
84 try test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 0);84 try test__mulodi4(1, @as(i64, @bitCast(@as(u64, 0x8000000000000001))), @as(i64, @bitCast(@as(u64, 0x8000000000000001))), 0);
85 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);85 try test__mulodi4(@as(i64, @bitCast(@as(u64, 0x8000000000000001))), 2, @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1);
86 try test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);86 try test__mulodi4(2, @as(i64, @bitCast(@as(u64, 0x8000000000000001))), @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1);
87}87}
lib/compiler_rt/mulosi4_test.zig+26-26
...@@ -37,36 +37,36 @@ test "mulosi4" {...@@ -37,36 +37,36 @@ test "mulosi4" {
37 try test__mulosi4(1, -0x1234567, -0x1234567, 0);37 try test__mulosi4(1, -0x1234567, -0x1234567, 0);
38 try test__mulosi4(-0x1234567, 1, -0x1234567, 0);38 try test__mulosi4(-0x1234567, 1, -0x1234567, 0);
3939
40 try test__mulosi4(0x7FFFFFFF, -2, @bitCast(i32, @as(u32, 0x80000001)), 1);40 try test__mulosi4(0x7FFFFFFF, -2, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
41 try test__mulosi4(-2, 0x7FFFFFFF, @bitCast(i32, @as(u32, 0x80000001)), 1);41 try test__mulosi4(-2, 0x7FFFFFFF, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
42 try test__mulosi4(0x7FFFFFFF, -1, @bitCast(i32, @as(u32, 0x80000001)), 0);42 try test__mulosi4(0x7FFFFFFF, -1, @as(i32, @bitCast(@as(u32, 0x80000001))), 0);
43 try test__mulosi4(-1, 0x7FFFFFFF, @bitCast(i32, @as(u32, 0x80000001)), 0);43 try test__mulosi4(-1, 0x7FFFFFFF, @as(i32, @bitCast(@as(u32, 0x80000001))), 0);
44 try test__mulosi4(0x7FFFFFFF, 0, 0, 0);44 try test__mulosi4(0x7FFFFFFF, 0, 0, 0);
45 try test__mulosi4(0, 0x7FFFFFFF, 0, 0);45 try test__mulosi4(0, 0x7FFFFFFF, 0, 0);
46 try test__mulosi4(0x7FFFFFFF, 1, 0x7FFFFFFF, 0);46 try test__mulosi4(0x7FFFFFFF, 1, 0x7FFFFFFF, 0);
47 try test__mulosi4(1, 0x7FFFFFFF, 0x7FFFFFFF, 0);47 try test__mulosi4(1, 0x7FFFFFFF, 0x7FFFFFFF, 0);
48 try test__mulosi4(0x7FFFFFFF, 2, @bitCast(i32, @as(u32, 0x80000001)), 1);48 try test__mulosi4(0x7FFFFFFF, 2, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
49 try test__mulosi4(2, 0x7FFFFFFF, @bitCast(i32, @as(u32, 0x80000001)), 1);49 try test__mulosi4(2, 0x7FFFFFFF, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
5050
51 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000000)), -2, @bitCast(i32, @as(u32, 0x80000000)), 1);51 try test__mulosi4(@as(i32, @bitCast(@as(u32, 0x80000000))), -2, @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
52 try test__mulosi4(-2, @bitCast(i32, @as(u32, 0x80000000)), @bitCast(i32, @as(u32, 0x80000000)), 1);52 try test__mulosi4(-2, @as(i32, @bitCast(@as(u32, 0x80000000))), @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
53 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000000)), -1, @bitCast(i32, @as(u32, 0x80000000)), 1);53 try test__mulosi4(@as(i32, @bitCast(@as(u32, 0x80000000))), -1, @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
54 try test__mulosi4(-1, @bitCast(i32, @as(u32, 0x80000000)), @bitCast(i32, @as(u32, 0x80000000)), 1);54 try test__mulosi4(-1, @as(i32, @bitCast(@as(u32, 0x80000000))), @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
55 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000000)), 0, 0, 0);55 try test__mulosi4(@as(i32, @bitCast(@as(u32, 0x80000000))), 0, 0, 0);
56 try test__mulosi4(0, @bitCast(i32, @as(u32, 0x80000000)), 0, 0);56 try test__mulosi4(0, @as(i32, @bitCast(@as(u32, 0x80000000))), 0, 0);
57 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000000)), 1, @bitCast(i32, @as(u32, 0x80000000)), 0);57 try test__mulosi4(@as(i32, @bitCast(@as(u32, 0x80000000))), 1, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
58 try test__mulosi4(1, @bitCast(i32, @as(u32, 0x80000000)), @bitCast(i32, @as(u32, 0x80000000)), 0);58 try test__mulosi4(1, @as(i32, @bitCast(@as(u32, 0x80000000))), @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
59 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000000)), 2, @bitCast(i32, @as(u32, 0x80000000)), 1);59 try test__mulosi4(@as(i32, @bitCast(@as(u32, 0x80000000))), 2, @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
60 try test__mulosi4(2, @bitCast(i32, @as(u32, 0x80000000)), @bitCast(i32, @as(u32, 0x80000000)), 1);60 try test__mulosi4(2, @as(i32, @bitCast(@as(u32, 0x80000000))), @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
6161
62 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000001)), -2, @bitCast(i32, @as(u32, 0x80000001)), 1);62 try test__mulosi4(@as(i32, @bitCast(@as(u32, 0x80000001))), -2, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
63 try test__mulosi4(-2, @bitCast(i32, @as(u32, 0x80000001)), @bitCast(i32, @as(u32, 0x80000001)), 1);63 try test__mulosi4(-2, @as(i32, @bitCast(@as(u32, 0x80000001))), @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
64 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000001)), -1, 0x7FFFFFFF, 0);64 try test__mulosi4(@as(i32, @bitCast(@as(u32, 0x80000001))), -1, 0x7FFFFFFF, 0);
65 try test__mulosi4(-1, @bitCast(i32, @as(u32, 0x80000001)), 0x7FFFFFFF, 0);65 try test__mulosi4(-1, @as(i32, @bitCast(@as(u32, 0x80000001))), 0x7FFFFFFF, 0);
66 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000001)), 0, 0, 0);66 try test__mulosi4(@as(i32, @bitCast(@as(u32, 0x80000001))), 0, 0, 0);
67 try test__mulosi4(0, @bitCast(i32, @as(u32, 0x80000001)), 0, 0);67 try test__mulosi4(0, @as(i32, @bitCast(@as(u32, 0x80000001))), 0, 0);
68 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000001)), 1, @bitCast(i32, @as(u32, 0x80000001)), 0);68 try test__mulosi4(@as(i32, @bitCast(@as(u32, 0x80000001))), 1, @as(i32, @bitCast(@as(u32, 0x80000001))), 0);
69 try test__mulosi4(1, @bitCast(i32, @as(u32, 0x80000001)), @bitCast(i32, @as(u32, 0x80000001)), 0);69 try test__mulosi4(1, @as(i32, @bitCast(@as(u32, 0x80000001))), @as(i32, @bitCast(@as(u32, 0x80000001))), 0);
70 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000001)), 2, @bitCast(i32, @as(u32, 0x80000000)), 1);70 try test__mulosi4(@as(i32, @bitCast(@as(u32, 0x80000001))), 2, @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
71 try test__mulosi4(2, @bitCast(i32, @as(u32, 0x80000001)), @bitCast(i32, @as(u32, 0x80000000)), 1);71 try test__mulosi4(2, @as(i32, @bitCast(@as(u32, 0x80000001))), @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
72}72}
lib/compiler_rt/muloti4_test.zig+31-31
...@@ -52,38 +52,38 @@ test "muloti4" {...@@ -52,38 +52,38 @@ test "muloti4" {
52 try test__muloti4(2097152, -4398046511103, -9223372036852678656, 0);52 try test__muloti4(2097152, -4398046511103, -9223372036852678656, 0);
53 try test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0);53 try test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0);
5454
55 try test__muloti4(@bitCast(i128, @as(u128, 0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, @as(u128, 0x000000000000000000B504F333F9DE5B)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0);55 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x00000000000000B504F333F9DE5BE000))), @as(i128, @bitCast(@as(u128, 0x000000000000000000B504F333F9DE5B))), @as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFF328DF915DA296E8A000))), 0);
56 try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);56 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), -2, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 1);
57 try test__muloti4(-2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);57 try test__muloti4(-2, @as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 1);
5858
59 try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);59 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), -1, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 0);
60 try test__muloti4(-1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);60 try test__muloti4(-1, @as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 0);
61 try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0);61 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), 0, 0, 0);
62 try test__muloti4(0, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0);62 try test__muloti4(0, @as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), 0, 0);
63 try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);63 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), 1, @as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), 0);
64 try test__muloti4(1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);64 try test__muloti4(1, @as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), @as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), 0);
65 try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);65 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), 2, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 1);
66 try test__muloti4(2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);66 try test__muloti4(2, @as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 1);
6767
68 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);68 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), -2, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 1);
69 try test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);69 try test__muloti4(-2, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 1);
70 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);70 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), -1, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 1);
71 try test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);71 try test__muloti4(-1, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 1);
72 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0, 0);72 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 0, 0, 0);
73 try test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0);73 try test__muloti4(0, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 0, 0);
74 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);74 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 1, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 0);
75 try test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);75 try test__muloti4(1, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 0);
76 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);76 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 2, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 1);
77 try test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);77 try test__muloti4(2, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 1);
7878
79 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);79 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), -2, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 1);
80 try test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);80 try test__muloti4(-2, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 1);
81 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);81 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), -1, @as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), 0);
82 try test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);82 try test__muloti4(-1, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), @as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), 0);
83 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0, 0);83 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 0, 0, 0);
84 try test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0);84 try test__muloti4(0, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 0, 0);
85 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);85 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 1, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 0);
86 try test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);86 try test__muloti4(1, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 0);
87 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);87 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 2, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 1);
88 try test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);88 try test__muloti4(2, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 1);
89}89}
lib/compiler_rt/negv.zig+1-1
...@@ -33,7 +33,7 @@ inline fn negvXi(comptime ST: type, a: ST) ST {...@@ -33,7 +33,7 @@ inline fn negvXi(comptime ST: type, a: ST) ST {
33 else => unreachable,33 else => unreachable,
34 };34 };
35 const N: UT = @bitSizeOf(ST);35 const N: UT = @bitSizeOf(ST);
36 const min: ST = @bitCast(ST, (@as(UT, 1) << (N - 1)));36 const min: ST = @as(ST, @bitCast((@as(UT, 1) << (N - 1))));
37 if (a == min)37 if (a == min)
38 @panic("compiler_rt negv: overflow");38 @panic("compiler_rt negv: overflow");
39 return -a;39 return -a;
lib/compiler_rt/parity.zig+4-4
...@@ -27,9 +27,9 @@ pub fn __parityti2(a: i128) callconv(.C) i32 {...@@ -27,9 +27,9 @@ pub fn __parityti2(a: i128) callconv(.C) i32 {
2727
28inline fn parityXi2(comptime T: type, a: T) i32 {28inline fn parityXi2(comptime T: type, a: T) i32 {
29 var x = switch (@bitSizeOf(T)) {29 var x = switch (@bitSizeOf(T)) {
30 32 => @bitCast(u32, a),30 32 => @as(u32, @bitCast(a)),
31 64 => @bitCast(u64, a),31 64 => @as(u64, @bitCast(a)),
32 128 => @bitCast(u128, a),32 128 => @as(u128, @bitCast(a)),
33 else => unreachable,33 else => unreachable,
34 };34 };
35 // Bit Twiddling Hacks: Compute parity in parallel35 // Bit Twiddling Hacks: Compute parity in parallel
...@@ -39,7 +39,7 @@ inline fn parityXi2(comptime T: type, a: T) i32 {...@@ -39,7 +39,7 @@ inline fn parityXi2(comptime T: type, a: T) i32 {
39 shift = shift >> 1;39 shift = shift >> 1;
40 }40 }
41 x &= 0xf;41 x &= 0xf;
42 return (@intCast(u16, 0x6996) >> @intCast(u4, x)) & 1; // optimization for >>2 and >>142 return (@as(u16, @intCast(0x6996)) >> @as(u4, @intCast(x))) & 1; // optimization for >>2 and >>1
43}43}
4444
45test {45test {
lib/compiler_rt/paritydi2_test.zig+5-5
...@@ -3,13 +3,13 @@ const parity = @import("parity.zig");...@@ -3,13 +3,13 @@ const parity = @import("parity.zig");
3const testing = std.testing;3const testing = std.testing;
44
5fn paritydi2Naive(a: i64) i32 {5fn paritydi2Naive(a: i64) i32 {
6 var x = @bitCast(u64, a);6 var x = @as(u64, @bitCast(a));
7 var has_parity: bool = false;7 var has_parity: bool = false;
8 while (x > 0) {8 while (x > 0) {
9 has_parity = !has_parity;9 has_parity = !has_parity;
10 x = x & (x - 1);10 x = x & (x - 1);
11 }11 }
12 return @intCast(i32, @intFromBool(has_parity));12 return @as(i32, @intCast(@intFromBool(has_parity)));
13}13}
1414
15fn test__paritydi2(a: i64) !void {15fn test__paritydi2(a: i64) !void {
...@@ -22,9 +22,9 @@ test "paritydi2" {...@@ -22,9 +22,9 @@ test "paritydi2" {
22 try test__paritydi2(0);22 try test__paritydi2(0);
23 try test__paritydi2(1);23 try test__paritydi2(1);
24 try test__paritydi2(2);24 try test__paritydi2(2);
25 try test__paritydi2(@bitCast(i64, @as(u64, 0xffffffff_fffffffd)));25 try test__paritydi2(@as(i64, @bitCast(@as(u64, 0xffffffff_fffffffd))));
26 try test__paritydi2(@bitCast(i64, @as(u64, 0xffffffff_fffffffe)));26 try test__paritydi2(@as(i64, @bitCast(@as(u64, 0xffffffff_fffffffe))));
27 try test__paritydi2(@bitCast(i64, @as(u64, 0xffffffff_ffffffff)));27 try test__paritydi2(@as(i64, @bitCast(@as(u64, 0xffffffff_ffffffff))));
2828
29 const RndGen = std.rand.DefaultPrng;29 const RndGen = std.rand.DefaultPrng;
30 var rnd = RndGen.init(42);30 var rnd = RndGen.init(42);
lib/compiler_rt/paritysi2_test.zig+5-5
...@@ -3,13 +3,13 @@ const parity = @import("parity.zig");...@@ -3,13 +3,13 @@ const parity = @import("parity.zig");
3const testing = std.testing;3const testing = std.testing;
44
5fn paritysi2Naive(a: i32) i32 {5fn paritysi2Naive(a: i32) i32 {
6 var x = @bitCast(u32, a);6 var x = @as(u32, @bitCast(a));
7 var has_parity: bool = false;7 var has_parity: bool = false;
8 while (x > 0) {8 while (x > 0) {
9 has_parity = !has_parity;9 has_parity = !has_parity;
10 x = x & (x - 1);10 x = x & (x - 1);
11 }11 }
12 return @intCast(i32, @intFromBool(has_parity));12 return @as(i32, @intCast(@intFromBool(has_parity)));
13}13}
1414
15fn test__paritysi2(a: i32) !void {15fn test__paritysi2(a: i32) !void {
...@@ -22,9 +22,9 @@ test "paritysi2" {...@@ -22,9 +22,9 @@ test "paritysi2" {
22 try test__paritysi2(0);22 try test__paritysi2(0);
23 try test__paritysi2(1);23 try test__paritysi2(1);
24 try test__paritysi2(2);24 try test__paritysi2(2);
25 try test__paritysi2(@bitCast(i32, @as(u32, 0xfffffffd)));25 try test__paritysi2(@as(i32, @bitCast(@as(u32, 0xfffffffd))));
26 try test__paritysi2(@bitCast(i32, @as(u32, 0xfffffffe)));26 try test__paritysi2(@as(i32, @bitCast(@as(u32, 0xfffffffe))));
27 try test__paritysi2(@bitCast(i32, @as(u32, 0xffffffff)));27 try test__paritysi2(@as(i32, @bitCast(@as(u32, 0xffffffff))));
2828
29 const RndGen = std.rand.DefaultPrng;29 const RndGen = std.rand.DefaultPrng;
30 var rnd = RndGen.init(42);30 var rnd = RndGen.init(42);
lib/compiler_rt/parityti2_test.zig+5-5
...@@ -3,13 +3,13 @@ const parity = @import("parity.zig");...@@ -3,13 +3,13 @@ const parity = @import("parity.zig");
3const testing = std.testing;3const testing = std.testing;
44
5fn parityti2Naive(a: i128) i32 {5fn parityti2Naive(a: i128) i32 {
6 var x = @bitCast(u128, a);6 var x = @as(u128, @bitCast(a));
7 var has_parity: bool = false;7 var has_parity: bool = false;
8 while (x > 0) {8 while (x > 0) {
9 has_parity = !has_parity;9 has_parity = !has_parity;
10 x = x & (x - 1);10 x = x & (x - 1);
11 }11 }
12 return @intCast(i32, @intFromBool(has_parity));12 return @as(i32, @intCast(@intFromBool(has_parity)));
13}13}
1414
15fn test__parityti2(a: i128) !void {15fn test__parityti2(a: i128) !void {
...@@ -22,9 +22,9 @@ test "parityti2" {...@@ -22,9 +22,9 @@ test "parityti2" {
22 try test__parityti2(0);22 try test__parityti2(0);
23 try test__parityti2(1);23 try test__parityti2(1);
24 try test__parityti2(2);24 try test__parityti2(2);
25 try test__parityti2(@bitCast(i128, @as(u128, 0xffffffff_ffffffff_ffffffff_fffffffd)));25 try test__parityti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffd))));
26 try test__parityti2(@bitCast(i128, @as(u128, 0xffffffff_ffffffff_ffffffff_fffffffe)));26 try test__parityti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffe))));
27 try test__parityti2(@bitCast(i128, @as(u128, 0xffffffff_ffffffff_ffffffff_ffffffff)));27 try test__parityti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_ffffffff))));
2828
29 const RndGen = std.rand.DefaultPrng;29 const RndGen = std.rand.DefaultPrng;
30 var rnd = RndGen.init(42);30 var rnd = RndGen.init(42);
lib/compiler_rt/popcount.zig+2-2
...@@ -37,7 +37,7 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 {...@@ -37,7 +37,7 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 {
37 i128 => u128,37 i128 => u128,
38 else => unreachable,38 else => unreachable,
39 };39 };
40 var x = @bitCast(UT, a);40 var x = @as(UT, @bitCast(a));
41 x -= (x >> 1) & (~@as(UT, 0) / 3); // 0x55...55, aggregate duos41 x -= (x >> 1) & (~@as(UT, 0) / 3); // 0x55...55, aggregate duos
42 x = ((x >> 2) & (~@as(UT, 0) / 5)) // 0x33...33, aggregate nibbles42 x = ((x >> 2) & (~@as(UT, 0) / 5)) // 0x33...33, aggregate nibbles
43 + (x & (~@as(UT, 0) / 5));43 + (x & (~@as(UT, 0) / 5));
...@@ -46,7 +46,7 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 {...@@ -46,7 +46,7 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 {
46 // 8 most significant bits of x + (x<<8) + (x<<16) + ..46 // 8 most significant bits of x + (x<<8) + (x<<16) + ..
47 x *%= ~@as(UT, 0) / 255; // 0x01...0147 x *%= ~@as(UT, 0) / 255; // 0x01...01
48 x >>= (@bitSizeOf(ST) - 8);48 x >>= (@bitSizeOf(ST) - 8);
49 return @intCast(i32, x);49 return @as(i32, @intCast(x));
50}50}
5151
52test {52test {
lib/compiler_rt/popcountdi2_test.zig+5-5
...@@ -5,8 +5,8 @@ const testing = std.testing;...@@ -5,8 +5,8 @@ const testing = std.testing;
5fn popcountdi2Naive(a: i64) i32 {5fn popcountdi2Naive(a: i64) i32 {
6 var x = a;6 var x = a;
7 var r: i32 = 0;7 var r: i32 = 0;
8 while (x != 0) : (x = @bitCast(i64, @bitCast(u64, x) >> 1)) {8 while (x != 0) : (x = @as(i64, @bitCast(@as(u64, @bitCast(x)) >> 1))) {
9 r += @intCast(i32, x & 1);9 r += @as(i32, @intCast(x & 1));
10 }10 }
11 return r;11 return r;
12}12}
...@@ -21,9 +21,9 @@ test "popcountdi2" {...@@ -21,9 +21,9 @@ test "popcountdi2" {
21 try test__popcountdi2(0);21 try test__popcountdi2(0);
22 try test__popcountdi2(1);22 try test__popcountdi2(1);
23 try test__popcountdi2(2);23 try test__popcountdi2(2);
24 try test__popcountdi2(@bitCast(i64, @as(u64, 0xffffffff_fffffffd)));24 try test__popcountdi2(@as(i64, @bitCast(@as(u64, 0xffffffff_fffffffd))));
25 try test__popcountdi2(@bitCast(i64, @as(u64, 0xffffffff_fffffffe)));25 try test__popcountdi2(@as(i64, @bitCast(@as(u64, 0xffffffff_fffffffe))));
26 try test__popcountdi2(@bitCast(i64, @as(u64, 0xffffffff_ffffffff)));26 try test__popcountdi2(@as(i64, @bitCast(@as(u64, 0xffffffff_ffffffff))));
2727
28 const RndGen = std.rand.DefaultPrng;28 const RndGen = std.rand.DefaultPrng;
29 var rnd = RndGen.init(42);29 var rnd = RndGen.init(42);
lib/compiler_rt/popcountsi2_test.zig+5-5
...@@ -5,8 +5,8 @@ const testing = std.testing;...@@ -5,8 +5,8 @@ const testing = std.testing;
5fn popcountsi2Naive(a: i32) i32 {5fn popcountsi2Naive(a: i32) i32 {
6 var x = a;6 var x = a;
7 var r: i32 = 0;7 var r: i32 = 0;
8 while (x != 0) : (x = @bitCast(i32, @bitCast(u32, x) >> 1)) {8 while (x != 0) : (x = @as(i32, @bitCast(@as(u32, @bitCast(x)) >> 1))) {
9 r += @intCast(i32, x & 1);9 r += @as(i32, @intCast(x & 1));
10 }10 }
11 return r;11 return r;
12}12}
...@@ -21,9 +21,9 @@ test "popcountsi2" {...@@ -21,9 +21,9 @@ test "popcountsi2" {
21 try test__popcountsi2(0);21 try test__popcountsi2(0);
22 try test__popcountsi2(1);22 try test__popcountsi2(1);
23 try test__popcountsi2(2);23 try test__popcountsi2(2);
24 try test__popcountsi2(@bitCast(i32, @as(u32, 0xfffffffd)));24 try test__popcountsi2(@as(i32, @bitCast(@as(u32, 0xfffffffd))));
25 try test__popcountsi2(@bitCast(i32, @as(u32, 0xfffffffe)));25 try test__popcountsi2(@as(i32, @bitCast(@as(u32, 0xfffffffe))));
26 try test__popcountsi2(@bitCast(i32, @as(u32, 0xffffffff)));26 try test__popcountsi2(@as(i32, @bitCast(@as(u32, 0xffffffff))));
2727
28 const RndGen = std.rand.DefaultPrng;28 const RndGen = std.rand.DefaultPrng;
29 var rnd = RndGen.init(42);29 var rnd = RndGen.init(42);
lib/compiler_rt/popcountti2_test.zig+5-5
...@@ -5,8 +5,8 @@ const testing = std.testing;...@@ -5,8 +5,8 @@ const testing = std.testing;
5fn popcountti2Naive(a: i128) i32 {5fn popcountti2Naive(a: i128) i32 {
6 var x = a;6 var x = a;
7 var r: i32 = 0;7 var r: i32 = 0;
8 while (x != 0) : (x = @bitCast(i128, @bitCast(u128, x) >> 1)) {8 while (x != 0) : (x = @as(i128, @bitCast(@as(u128, @bitCast(x)) >> 1))) {
9 r += @intCast(i32, x & 1);9 r += @as(i32, @intCast(x & 1));
10 }10 }
11 return r;11 return r;
12}12}
...@@ -21,9 +21,9 @@ test "popcountti2" {...@@ -21,9 +21,9 @@ test "popcountti2" {
21 try test__popcountti2(0);21 try test__popcountti2(0);
22 try test__popcountti2(1);22 try test__popcountti2(1);
23 try test__popcountti2(2);23 try test__popcountti2(2);
24 try test__popcountti2(@bitCast(i128, @as(u128, 0xffffffff_ffffffff_ffffffff_fffffffd)));24 try test__popcountti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffd))));
25 try test__popcountti2(@bitCast(i128, @as(u128, 0xffffffff_ffffffff_ffffffff_fffffffe)));25 try test__popcountti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffe))));
26 try test__popcountti2(@bitCast(i128, @as(u128, 0xffffffff_ffffffff_ffffffff_ffffffff)));26 try test__popcountti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_ffffffff))));
2727
28 const RndGen = std.rand.DefaultPrng;28 const RndGen = std.rand.DefaultPrng;
29 var rnd = RndGen.init(42);29 var rnd = RndGen.init(42);
lib/compiler_rt/powiXf2.zig+1-1
...@@ -25,7 +25,7 @@ inline fn powiXf2(comptime FT: type, a: FT, b: i32) FT {...@@ -25,7 +25,7 @@ inline fn powiXf2(comptime FT: type, a: FT, b: i32) FT {
25 const is_recip: bool = b < 0;25 const is_recip: bool = b < 0;
26 var r: FT = 1.0;26 var r: FT = 1.0;
27 while (true) {27 while (true) {
28 if (@bitCast(u32, x_b) & @as(u32, 1) != 0) {28 if (@as(u32, @bitCast(x_b)) & @as(u32, 1) != 0) {
29 r *= x_a;29 r *= x_a;
30 }30 }
31 x_b = @divTrunc(x_b, @as(i32, 2));31 x_b = @divTrunc(x_b, @as(i32, 2));
lib/compiler_rt/powiXf2_test.zig+124-124
...@@ -49,76 +49,76 @@ test "powihf2" {...@@ -49,76 +49,76 @@ test "powihf2" {
49 try test__powihf2(0, 2, 0);49 try test__powihf2(0, 2, 0);
50 try test__powihf2(0, 3, 0);50 try test__powihf2(0, 3, 0);
51 try test__powihf2(0, 4, 0);51 try test__powihf2(0, 4, 0);
52 try test__powihf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);52 try test__powihf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
53 try test__powihf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 0);53 try test__powihf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 0);
5454
55 try test__powihf2(-0.0, 1, -0.0);55 try test__powihf2(-0.0, 1, -0.0);
56 try test__powihf2(-0.0, 2, 0);56 try test__powihf2(-0.0, 2, 0);
57 try test__powihf2(-0.0, 3, -0.0);57 try test__powihf2(-0.0, 3, -0.0);
58 try test__powihf2(-0.0, 4, 0);58 try test__powihf2(-0.0, 4, 0);
59 try test__powihf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);59 try test__powihf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
60 try test__powihf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -0.0);60 try test__powihf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -0.0);
6161
62 try test__powihf2(1, 1, 1);62 try test__powihf2(1, 1, 1);
63 try test__powihf2(1, 2, 1);63 try test__powihf2(1, 2, 1);
64 try test__powihf2(1, 3, 1);64 try test__powihf2(1, 3, 1);
65 try test__powihf2(1, 4, 1);65 try test__powihf2(1, 4, 1);
66 try test__powihf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 1);66 try test__powihf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 1);
67 try test__powihf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 1);67 try test__powihf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 1);
6868
69 try test__powihf2(inf_f16, 1, inf_f16);69 try test__powihf2(inf_f16, 1, inf_f16);
70 try test__powihf2(inf_f16, 2, inf_f16);70 try test__powihf2(inf_f16, 2, inf_f16);
71 try test__powihf2(inf_f16, 3, inf_f16);71 try test__powihf2(inf_f16, 3, inf_f16);
72 try test__powihf2(inf_f16, 4, inf_f16);72 try test__powihf2(inf_f16, 4, inf_f16);
73 try test__powihf2(inf_f16, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f16);73 try test__powihf2(inf_f16, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f16);
74 try test__powihf2(inf_f16, @bitCast(i32, @as(u32, 0x7FFFFFFF)), inf_f16);74 try test__powihf2(inf_f16, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), inf_f16);
7575
76 try test__powihf2(-inf_f16, 1, -inf_f16);76 try test__powihf2(-inf_f16, 1, -inf_f16);
77 try test__powihf2(-inf_f16, 2, inf_f16);77 try test__powihf2(-inf_f16, 2, inf_f16);
78 try test__powihf2(-inf_f16, 3, -inf_f16);78 try test__powihf2(-inf_f16, 3, -inf_f16);
79 try test__powihf2(-inf_f16, 4, inf_f16);79 try test__powihf2(-inf_f16, 4, inf_f16);
80 try test__powihf2(-inf_f16, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f16);80 try test__powihf2(-inf_f16, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f16);
81 try test__powihf2(-inf_f16, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -inf_f16);81 try test__powihf2(-inf_f16, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -inf_f16);
82 //82 //
83 try test__powihf2(0, -1, inf_f16);83 try test__powihf2(0, -1, inf_f16);
84 try test__powihf2(0, -2, inf_f16);84 try test__powihf2(0, -2, inf_f16);
85 try test__powihf2(0, -3, inf_f16);85 try test__powihf2(0, -3, inf_f16);
86 try test__powihf2(0, -4, inf_f16);86 try test__powihf2(0, -4, inf_f16);
87 try test__powihf2(0, @bitCast(i32, @as(u32, 0x80000002)), inf_f16); // 0 ^ anything = +inf87 try test__powihf2(0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f16); // 0 ^ anything = +inf
88 try test__powihf2(0, @bitCast(i32, @as(u32, 0x80000001)), inf_f16);88 try test__powihf2(0, @as(i32, @bitCast(@as(u32, 0x80000001))), inf_f16);
89 try test__powihf2(0, @bitCast(i32, @as(u32, 0x80000000)), inf_f16);89 try test__powihf2(0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f16);
9090
91 try test__powihf2(-0.0, -1, -inf_f16);91 try test__powihf2(-0.0, -1, -inf_f16);
92 try test__powihf2(-0.0, -2, inf_f16);92 try test__powihf2(-0.0, -2, inf_f16);
93 try test__powihf2(-0.0, -3, -inf_f16);93 try test__powihf2(-0.0, -3, -inf_f16);
94 try test__powihf2(-0.0, -4, inf_f16);94 try test__powihf2(-0.0, -4, inf_f16);
95 try test__powihf2(-0.0, @bitCast(i32, @as(u32, 0x80000002)), inf_f16); // -0 ^ anything even = +inf95 try test__powihf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f16); // -0 ^ anything even = +inf
96 try test__powihf2(-0.0, @bitCast(i32, @as(u32, 0x80000001)), -inf_f16); // -0 ^ anything odd = -inf96 try test__powihf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000001))), -inf_f16); // -0 ^ anything odd = -inf
97 try test__powihf2(-0.0, @bitCast(i32, @as(u32, 0x80000000)), inf_f16);97 try test__powihf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f16);
9898
99 try test__powihf2(1, -1, 1);99 try test__powihf2(1, -1, 1);
100 try test__powihf2(1, -2, 1);100 try test__powihf2(1, -2, 1);
101 try test__powihf2(1, -3, 1);101 try test__powihf2(1, -3, 1);
102 try test__powihf2(1, -4, 1);102 try test__powihf2(1, -4, 1);
103 try test__powihf2(1, @bitCast(i32, @as(u32, 0x80000002)), 1); // 1.0 ^ anything = 1103 try test__powihf2(1, @as(i32, @bitCast(@as(u32, 0x80000002))), 1); // 1.0 ^ anything = 1
104 try test__powihf2(1, @bitCast(i32, @as(u32, 0x80000001)), 1);104 try test__powihf2(1, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
105 try test__powihf2(1, @bitCast(i32, @as(u32, 0x80000000)), 1);105 try test__powihf2(1, @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
106106
107 try test__powihf2(inf_f16, -1, 0);107 try test__powihf2(inf_f16, -1, 0);
108 try test__powihf2(inf_f16, -2, 0);108 try test__powihf2(inf_f16, -2, 0);
109 try test__powihf2(inf_f16, -3, 0);109 try test__powihf2(inf_f16, -3, 0);
110 try test__powihf2(inf_f16, -4, 0);110 try test__powihf2(inf_f16, -4, 0);
111 try test__powihf2(inf_f16, @bitCast(i32, @as(u32, 0x80000002)), 0);111 try test__powihf2(inf_f16, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
112 try test__powihf2(inf_f16, @bitCast(i32, @as(u32, 0x80000001)), 0);112 try test__powihf2(inf_f16, @as(i32, @bitCast(@as(u32, 0x80000001))), 0);
113 try test__powihf2(inf_f16, @bitCast(i32, @as(u32, 0x80000000)), 0);113 try test__powihf2(inf_f16, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
114 //114 //
115 try test__powihf2(-inf_f16, -1, -0.0);115 try test__powihf2(-inf_f16, -1, -0.0);
116 try test__powihf2(-inf_f16, -2, 0);116 try test__powihf2(-inf_f16, -2, 0);
117 try test__powihf2(-inf_f16, -3, -0.0);117 try test__powihf2(-inf_f16, -3, -0.0);
118 try test__powihf2(-inf_f16, -4, 0);118 try test__powihf2(-inf_f16, -4, 0);
119 try test__powihf2(-inf_f16, @bitCast(i32, @as(u32, 0x80000002)), 0);119 try test__powihf2(-inf_f16, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
120 try test__powihf2(-inf_f16, @bitCast(i32, @as(u32, 0x80000001)), -0.0);120 try test__powihf2(-inf_f16, @as(i32, @bitCast(@as(u32, 0x80000001))), -0.0);
121 try test__powihf2(-inf_f16, @bitCast(i32, @as(u32, 0x80000000)), 0);121 try test__powihf2(-inf_f16, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
122122
123 try test__powihf2(2, 10, 1024.0);123 try test__powihf2(2, 10, 1024.0);
124 try test__powihf2(-2, 10, 1024.0);124 try test__powihf2(-2, 10, 1024.0);
...@@ -158,76 +158,76 @@ test "powisf2" {...@@ -158,76 +158,76 @@ test "powisf2" {
158 try test__powisf2(0, 2, 0);158 try test__powisf2(0, 2, 0);
159 try test__powisf2(0, 3, 0);159 try test__powisf2(0, 3, 0);
160 try test__powisf2(0, 4, 0);160 try test__powisf2(0, 4, 0);
161 try test__powisf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);161 try test__powisf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
162 try test__powisf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 0);162 try test__powisf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 0);
163163
164 try test__powisf2(-0.0, 1, -0.0);164 try test__powisf2(-0.0, 1, -0.0);
165 try test__powisf2(-0.0, 2, 0);165 try test__powisf2(-0.0, 2, 0);
166 try test__powisf2(-0.0, 3, -0.0);166 try test__powisf2(-0.0, 3, -0.0);
167 try test__powisf2(-0.0, 4, 0);167 try test__powisf2(-0.0, 4, 0);
168 try test__powisf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);168 try test__powisf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
169 try test__powisf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -0.0);169 try test__powisf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -0.0);
170170
171 try test__powisf2(1, 1, 1);171 try test__powisf2(1, 1, 1);
172 try test__powisf2(1, 2, 1);172 try test__powisf2(1, 2, 1);
173 try test__powisf2(1, 3, 1);173 try test__powisf2(1, 3, 1);
174 try test__powisf2(1, 4, 1);174 try test__powisf2(1, 4, 1);
175 try test__powisf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 1);175 try test__powisf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 1);
176 try test__powisf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 1);176 try test__powisf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 1);
177177
178 try test__powisf2(inf_f32, 1, inf_f32);178 try test__powisf2(inf_f32, 1, inf_f32);
179 try test__powisf2(inf_f32, 2, inf_f32);179 try test__powisf2(inf_f32, 2, inf_f32);
180 try test__powisf2(inf_f32, 3, inf_f32);180 try test__powisf2(inf_f32, 3, inf_f32);
181 try test__powisf2(inf_f32, 4, inf_f32);181 try test__powisf2(inf_f32, 4, inf_f32);
182 try test__powisf2(inf_f32, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f32);182 try test__powisf2(inf_f32, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f32);
183 try test__powisf2(inf_f32, @bitCast(i32, @as(u32, 0x7FFFFFFF)), inf_f32);183 try test__powisf2(inf_f32, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), inf_f32);
184184
185 try test__powisf2(-inf_f32, 1, -inf_f32);185 try test__powisf2(-inf_f32, 1, -inf_f32);
186 try test__powisf2(-inf_f32, 2, inf_f32);186 try test__powisf2(-inf_f32, 2, inf_f32);
187 try test__powisf2(-inf_f32, 3, -inf_f32);187 try test__powisf2(-inf_f32, 3, -inf_f32);
188 try test__powisf2(-inf_f32, 4, inf_f32);188 try test__powisf2(-inf_f32, 4, inf_f32);
189 try test__powisf2(-inf_f32, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f32);189 try test__powisf2(-inf_f32, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f32);
190 try test__powisf2(-inf_f32, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -inf_f32);190 try test__powisf2(-inf_f32, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -inf_f32);
191191
192 try test__powisf2(0, -1, inf_f32);192 try test__powisf2(0, -1, inf_f32);
193 try test__powisf2(0, -2, inf_f32);193 try test__powisf2(0, -2, inf_f32);
194 try test__powisf2(0, -3, inf_f32);194 try test__powisf2(0, -3, inf_f32);
195 try test__powisf2(0, -4, inf_f32);195 try test__powisf2(0, -4, inf_f32);
196 try test__powisf2(0, @bitCast(i32, @as(u32, 0x80000002)), inf_f32);196 try test__powisf2(0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f32);
197 try test__powisf2(0, @bitCast(i32, @as(u32, 0x80000001)), inf_f32);197 try test__powisf2(0, @as(i32, @bitCast(@as(u32, 0x80000001))), inf_f32);
198 try test__powisf2(0, @bitCast(i32, @as(u32, 0x80000000)), inf_f32);198 try test__powisf2(0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f32);
199199
200 try test__powisf2(-0.0, -1, -inf_f32);200 try test__powisf2(-0.0, -1, -inf_f32);
201 try test__powisf2(-0.0, -2, inf_f32);201 try test__powisf2(-0.0, -2, inf_f32);
202 try test__powisf2(-0.0, -3, -inf_f32);202 try test__powisf2(-0.0, -3, -inf_f32);
203 try test__powisf2(-0.0, -4, inf_f32);203 try test__powisf2(-0.0, -4, inf_f32);
204 try test__powisf2(-0.0, @bitCast(i32, @as(u32, 0x80000002)), inf_f32);204 try test__powisf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f32);
205 try test__powisf2(-0.0, @bitCast(i32, @as(u32, 0x80000001)), -inf_f32);205 try test__powisf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000001))), -inf_f32);
206 try test__powisf2(-0.0, @bitCast(i32, @as(u32, 0x80000000)), inf_f32);206 try test__powisf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f32);
207207
208 try test__powisf2(1, -1, 1);208 try test__powisf2(1, -1, 1);
209 try test__powisf2(1, -2, 1);209 try test__powisf2(1, -2, 1);
210 try test__powisf2(1, -3, 1);210 try test__powisf2(1, -3, 1);
211 try test__powisf2(1, -4, 1);211 try test__powisf2(1, -4, 1);
212 try test__powisf2(1, @bitCast(i32, @as(u32, 0x80000002)), 1);212 try test__powisf2(1, @as(i32, @bitCast(@as(u32, 0x80000002))), 1);
213 try test__powisf2(1, @bitCast(i32, @as(u32, 0x80000001)), 1);213 try test__powisf2(1, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
214 try test__powisf2(1, @bitCast(i32, @as(u32, 0x80000000)), 1);214 try test__powisf2(1, @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
215215
216 try test__powisf2(inf_f32, -1, 0);216 try test__powisf2(inf_f32, -1, 0);
217 try test__powisf2(inf_f32, -2, 0);217 try test__powisf2(inf_f32, -2, 0);
218 try test__powisf2(inf_f32, -3, 0);218 try test__powisf2(inf_f32, -3, 0);
219 try test__powisf2(inf_f32, -4, 0);219 try test__powisf2(inf_f32, -4, 0);
220 try test__powisf2(inf_f32, @bitCast(i32, @as(u32, 0x80000002)), 0);220 try test__powisf2(inf_f32, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
221 try test__powisf2(inf_f32, @bitCast(i32, @as(u32, 0x80000001)), 0);221 try test__powisf2(inf_f32, @as(i32, @bitCast(@as(u32, 0x80000001))), 0);
222 try test__powisf2(inf_f32, @bitCast(i32, @as(u32, 0x80000000)), 0);222 try test__powisf2(inf_f32, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
223223
224 try test__powisf2(-inf_f32, -1, -0.0);224 try test__powisf2(-inf_f32, -1, -0.0);
225 try test__powisf2(-inf_f32, -2, 0);225 try test__powisf2(-inf_f32, -2, 0);
226 try test__powisf2(-inf_f32, -3, -0.0);226 try test__powisf2(-inf_f32, -3, -0.0);
227 try test__powisf2(-inf_f32, -4, 0);227 try test__powisf2(-inf_f32, -4, 0);
228 try test__powisf2(-inf_f32, @bitCast(i32, @as(u32, 0x80000002)), 0);228 try test__powisf2(-inf_f32, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
229 try test__powisf2(-inf_f32, @bitCast(i32, @as(u32, 0x80000001)), -0.0);229 try test__powisf2(-inf_f32, @as(i32, @bitCast(@as(u32, 0x80000001))), -0.0);
230 try test__powisf2(-inf_f32, @bitCast(i32, @as(u32, 0x80000000)), 0);230 try test__powisf2(-inf_f32, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
231231
232 try test__powisf2(2.0, 10, 1024.0);232 try test__powisf2(2.0, 10, 1024.0);
233 try test__powisf2(-2, 10, 1024.0);233 try test__powisf2(-2, 10, 1024.0);
...@@ -263,76 +263,76 @@ test "powidf2" {...@@ -263,76 +263,76 @@ test "powidf2" {
263 try test__powidf2(0, 2, 0);263 try test__powidf2(0, 2, 0);
264 try test__powidf2(0, 3, 0);264 try test__powidf2(0, 3, 0);
265 try test__powidf2(0, 4, 0);265 try test__powidf2(0, 4, 0);
266 try test__powidf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);266 try test__powidf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
267 try test__powidf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 0);267 try test__powidf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 0);
268268
269 try test__powidf2(-0.0, 1, -0.0);269 try test__powidf2(-0.0, 1, -0.0);
270 try test__powidf2(-0.0, 2, 0);270 try test__powidf2(-0.0, 2, 0);
271 try test__powidf2(-0.0, 3, -0.0);271 try test__powidf2(-0.0, 3, -0.0);
272 try test__powidf2(-0.0, 4, 0);272 try test__powidf2(-0.0, 4, 0);
273 try test__powidf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);273 try test__powidf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
274 try test__powidf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -0.0);274 try test__powidf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -0.0);
275275
276 try test__powidf2(1, 1, 1);276 try test__powidf2(1, 1, 1);
277 try test__powidf2(1, 2, 1);277 try test__powidf2(1, 2, 1);
278 try test__powidf2(1, 3, 1);278 try test__powidf2(1, 3, 1);
279 try test__powidf2(1, 4, 1);279 try test__powidf2(1, 4, 1);
280 try test__powidf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 1);280 try test__powidf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 1);
281 try test__powidf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 1);281 try test__powidf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 1);
282282
283 try test__powidf2(inf_f64, 1, inf_f64);283 try test__powidf2(inf_f64, 1, inf_f64);
284 try test__powidf2(inf_f64, 2, inf_f64);284 try test__powidf2(inf_f64, 2, inf_f64);
285 try test__powidf2(inf_f64, 3, inf_f64);285 try test__powidf2(inf_f64, 3, inf_f64);
286 try test__powidf2(inf_f64, 4, inf_f64);286 try test__powidf2(inf_f64, 4, inf_f64);
287 try test__powidf2(inf_f64, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f64);287 try test__powidf2(inf_f64, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f64);
288 try test__powidf2(inf_f64, @bitCast(i32, @as(u32, 0x7FFFFFFF)), inf_f64);288 try test__powidf2(inf_f64, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), inf_f64);
289289
290 try test__powidf2(-inf_f64, 1, -inf_f64);290 try test__powidf2(-inf_f64, 1, -inf_f64);
291 try test__powidf2(-inf_f64, 2, inf_f64);291 try test__powidf2(-inf_f64, 2, inf_f64);
292 try test__powidf2(-inf_f64, 3, -inf_f64);292 try test__powidf2(-inf_f64, 3, -inf_f64);
293 try test__powidf2(-inf_f64, 4, inf_f64);293 try test__powidf2(-inf_f64, 4, inf_f64);
294 try test__powidf2(-inf_f64, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f64);294 try test__powidf2(-inf_f64, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f64);
295 try test__powidf2(-inf_f64, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -inf_f64);295 try test__powidf2(-inf_f64, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -inf_f64);
296296
297 try test__powidf2(0, -1, inf_f64);297 try test__powidf2(0, -1, inf_f64);
298 try test__powidf2(0, -2, inf_f64);298 try test__powidf2(0, -2, inf_f64);
299 try test__powidf2(0, -3, inf_f64);299 try test__powidf2(0, -3, inf_f64);
300 try test__powidf2(0, -4, inf_f64);300 try test__powidf2(0, -4, inf_f64);
301 try test__powidf2(0, @bitCast(i32, @as(u32, 0x80000002)), inf_f64);301 try test__powidf2(0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f64);
302 try test__powidf2(0, @bitCast(i32, @as(u32, 0x80000001)), inf_f64);302 try test__powidf2(0, @as(i32, @bitCast(@as(u32, 0x80000001))), inf_f64);
303 try test__powidf2(0, @bitCast(i32, @as(u32, 0x80000000)), inf_f64);303 try test__powidf2(0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f64);
304304
305 try test__powidf2(-0.0, -1, -inf_f64);305 try test__powidf2(-0.0, -1, -inf_f64);
306 try test__powidf2(-0.0, -2, inf_f64);306 try test__powidf2(-0.0, -2, inf_f64);
307 try test__powidf2(-0.0, -3, -inf_f64);307 try test__powidf2(-0.0, -3, -inf_f64);
308 try test__powidf2(-0.0, -4, inf_f64);308 try test__powidf2(-0.0, -4, inf_f64);
309 try test__powidf2(-0.0, @bitCast(i32, @as(u32, 0x80000002)), inf_f64);309 try test__powidf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f64);
310 try test__powidf2(-0.0, @bitCast(i32, @as(u32, 0x80000001)), -inf_f64);310 try test__powidf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000001))), -inf_f64);
311 try test__powidf2(-0.0, @bitCast(i32, @as(u32, 0x80000000)), inf_f64);311 try test__powidf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f64);
312312
313 try test__powidf2(1, -1, 1);313 try test__powidf2(1, -1, 1);
314 try test__powidf2(1, -2, 1);314 try test__powidf2(1, -2, 1);
315 try test__powidf2(1, -3, 1);315 try test__powidf2(1, -3, 1);
316 try test__powidf2(1, -4, 1);316 try test__powidf2(1, -4, 1);
317 try test__powidf2(1, @bitCast(i32, @as(u32, 0x80000002)), 1);317 try test__powidf2(1, @as(i32, @bitCast(@as(u32, 0x80000002))), 1);
318 try test__powidf2(1, @bitCast(i32, @as(u32, 0x80000001)), 1);318 try test__powidf2(1, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
319 try test__powidf2(1, @bitCast(i32, @as(u32, 0x80000000)), 1);319 try test__powidf2(1, @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
320320
321 try test__powidf2(inf_f64, -1, 0);321 try test__powidf2(inf_f64, -1, 0);
322 try test__powidf2(inf_f64, -2, 0);322 try test__powidf2(inf_f64, -2, 0);
323 try test__powidf2(inf_f64, -3, 0);323 try test__powidf2(inf_f64, -3, 0);
324 try test__powidf2(inf_f64, -4, 0);324 try test__powidf2(inf_f64, -4, 0);
325 try test__powidf2(inf_f64, @bitCast(i32, @as(u32, 0x80000002)), 0);325 try test__powidf2(inf_f64, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
326 try test__powidf2(inf_f64, @bitCast(i32, @as(u32, 0x80000001)), 0);326 try test__powidf2(inf_f64, @as(i32, @bitCast(@as(u32, 0x80000001))), 0);
327 try test__powidf2(inf_f64, @bitCast(i32, @as(u32, 0x80000000)), 0);327 try test__powidf2(inf_f64, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
328328
329 try test__powidf2(-inf_f64, -1, -0.0);329 try test__powidf2(-inf_f64, -1, -0.0);
330 try test__powidf2(-inf_f64, -2, 0);330 try test__powidf2(-inf_f64, -2, 0);
331 try test__powidf2(-inf_f64, -3, -0.0);331 try test__powidf2(-inf_f64, -3, -0.0);
332 try test__powidf2(-inf_f64, -4, 0);332 try test__powidf2(-inf_f64, -4, 0);
333 try test__powidf2(-inf_f64, @bitCast(i32, @as(u32, 0x80000002)), 0);333 try test__powidf2(-inf_f64, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
334 try test__powidf2(-inf_f64, @bitCast(i32, @as(u32, 0x80000001)), -0.0);334 try test__powidf2(-inf_f64, @as(i32, @bitCast(@as(u32, 0x80000001))), -0.0);
335 try test__powidf2(-inf_f64, @bitCast(i32, @as(u32, 0x80000000)), 0);335 try test__powidf2(-inf_f64, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
336336
337 try test__powidf2(2, 10, 1024.0);337 try test__powidf2(2, 10, 1024.0);
338 try test__powidf2(-2, 10, 1024.0);338 try test__powidf2(-2, 10, 1024.0);
...@@ -368,76 +368,76 @@ test "powitf2" {...@@ -368,76 +368,76 @@ test "powitf2" {
368 try test__powitf2(0, 2, 0);368 try test__powitf2(0, 2, 0);
369 try test__powitf2(0, 3, 0);369 try test__powitf2(0, 3, 0);
370 try test__powitf2(0, 4, 0);370 try test__powitf2(0, 4, 0);
371 try test__powitf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);371 try test__powitf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
372 try test__powitf2(0, 0x7FFFFFFF, 0);372 try test__powitf2(0, 0x7FFFFFFF, 0);
373373
374 try test__powitf2(-0.0, 1, -0.0);374 try test__powitf2(-0.0, 1, -0.0);
375 try test__powitf2(-0.0, 2, 0);375 try test__powitf2(-0.0, 2, 0);
376 try test__powitf2(-0.0, 3, -0.0);376 try test__powitf2(-0.0, 3, -0.0);
377 try test__powitf2(-0.0, 4, 0);377 try test__powitf2(-0.0, 4, 0);
378 try test__powitf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);378 try test__powitf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
379 try test__powitf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -0.0);379 try test__powitf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -0.0);
380380
381 try test__powitf2(1, 1, 1);381 try test__powitf2(1, 1, 1);
382 try test__powitf2(1, 2, 1);382 try test__powitf2(1, 2, 1);
383 try test__powitf2(1, 3, 1);383 try test__powitf2(1, 3, 1);
384 try test__powitf2(1, 4, 1);384 try test__powitf2(1, 4, 1);
385 try test__powitf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 1);385 try test__powitf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 1);
386 try test__powitf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 1);386 try test__powitf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 1);
387387
388 try test__powitf2(inf_f128, 1, inf_f128);388 try test__powitf2(inf_f128, 1, inf_f128);
389 try test__powitf2(inf_f128, 2, inf_f128);389 try test__powitf2(inf_f128, 2, inf_f128);
390 try test__powitf2(inf_f128, 3, inf_f128);390 try test__powitf2(inf_f128, 3, inf_f128);
391 try test__powitf2(inf_f128, 4, inf_f128);391 try test__powitf2(inf_f128, 4, inf_f128);
392 try test__powitf2(inf_f128, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f128);392 try test__powitf2(inf_f128, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f128);
393 try test__powitf2(inf_f128, @bitCast(i32, @as(u32, 0x7FFFFFFF)), inf_f128);393 try test__powitf2(inf_f128, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), inf_f128);
394394
395 try test__powitf2(-inf_f128, 1, -inf_f128);395 try test__powitf2(-inf_f128, 1, -inf_f128);
396 try test__powitf2(-inf_f128, 2, inf_f128);396 try test__powitf2(-inf_f128, 2, inf_f128);
397 try test__powitf2(-inf_f128, 3, -inf_f128);397 try test__powitf2(-inf_f128, 3, -inf_f128);
398 try test__powitf2(-inf_f128, 4, inf_f128);398 try test__powitf2(-inf_f128, 4, inf_f128);
399 try test__powitf2(-inf_f128, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f128);399 try test__powitf2(-inf_f128, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f128);
400 try test__powitf2(-inf_f128, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -inf_f128);400 try test__powitf2(-inf_f128, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -inf_f128);
401401
402 try test__powitf2(0, -1, inf_f128);402 try test__powitf2(0, -1, inf_f128);
403 try test__powitf2(0, -2, inf_f128);403 try test__powitf2(0, -2, inf_f128);
404 try test__powitf2(0, -3, inf_f128);404 try test__powitf2(0, -3, inf_f128);
405 try test__powitf2(0, -4, inf_f128);405 try test__powitf2(0, -4, inf_f128);
406 try test__powitf2(0, @bitCast(i32, @as(u32, 0x80000002)), inf_f128);406 try test__powitf2(0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f128);
407 try test__powitf2(0, @bitCast(i32, @as(u32, 0x80000001)), inf_f128);407 try test__powitf2(0, @as(i32, @bitCast(@as(u32, 0x80000001))), inf_f128);
408 try test__powitf2(0, @bitCast(i32, @as(u32, 0x80000000)), inf_f128);408 try test__powitf2(0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f128);
409409
410 try test__powitf2(-0.0, -1, -inf_f128);410 try test__powitf2(-0.0, -1, -inf_f128);
411 try test__powitf2(-0.0, -2, inf_f128);411 try test__powitf2(-0.0, -2, inf_f128);
412 try test__powitf2(-0.0, -3, -inf_f128);412 try test__powitf2(-0.0, -3, -inf_f128);
413 try test__powitf2(-0.0, -4, inf_f128);413 try test__powitf2(-0.0, -4, inf_f128);
414 try test__powitf2(-0.0, @bitCast(i32, @as(u32, 0x80000002)), inf_f128);414 try test__powitf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f128);
415 try test__powitf2(-0.0, @bitCast(i32, @as(u32, 0x80000001)), -inf_f128);415 try test__powitf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000001))), -inf_f128);
416 try test__powitf2(-0.0, @bitCast(i32, @as(u32, 0x80000000)), inf_f128);416 try test__powitf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f128);
417417
418 try test__powitf2(1, -1, 1);418 try test__powitf2(1, -1, 1);
419 try test__powitf2(1, -2, 1);419 try test__powitf2(1, -2, 1);
420 try test__powitf2(1, -3, 1);420 try test__powitf2(1, -3, 1);
421 try test__powitf2(1, -4, 1);421 try test__powitf2(1, -4, 1);
422 try test__powitf2(1, @bitCast(i32, @as(u32, 0x80000002)), 1);422 try test__powitf2(1, @as(i32, @bitCast(@as(u32, 0x80000002))), 1);
423 try test__powitf2(1, @bitCast(i32, @as(u32, 0x80000001)), 1);423 try test__powitf2(1, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
424 try test__powitf2(1, @bitCast(i32, @as(u32, 0x80000000)), 1);424 try test__powitf2(1, @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
425425
426 try test__powitf2(inf_f128, -1, 0);426 try test__powitf2(inf_f128, -1, 0);
427 try test__powitf2(inf_f128, -2, 0);427 try test__powitf2(inf_f128, -2, 0);
428 try test__powitf2(inf_f128, -3, 0);428 try test__powitf2(inf_f128, -3, 0);
429 try test__powitf2(inf_f128, -4, 0);429 try test__powitf2(inf_f128, -4, 0);
430 try test__powitf2(inf_f128, @bitCast(i32, @as(u32, 0x80000002)), 0);430 try test__powitf2(inf_f128, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
431 try test__powitf2(inf_f128, @bitCast(i32, @as(u32, 0x80000001)), 0);431 try test__powitf2(inf_f128, @as(i32, @bitCast(@as(u32, 0x80000001))), 0);
432 try test__powitf2(inf_f128, @bitCast(i32, @as(u32, 0x80000000)), 0);432 try test__powitf2(inf_f128, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
433433
434 try test__powitf2(-inf_f128, -1, -0.0);434 try test__powitf2(-inf_f128, -1, -0.0);
435 try test__powitf2(-inf_f128, -2, 0);435 try test__powitf2(-inf_f128, -2, 0);
436 try test__powitf2(-inf_f128, -3, -0.0);436 try test__powitf2(-inf_f128, -3, -0.0);
437 try test__powitf2(-inf_f128, -4, 0);437 try test__powitf2(-inf_f128, -4, 0);
438 try test__powitf2(-inf_f128, @bitCast(i32, @as(u32, 0x80000002)), 0);438 try test__powitf2(-inf_f128, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
439 try test__powitf2(-inf_f128, @bitCast(i32, @as(u32, 0x80000001)), -0.0);439 try test__powitf2(-inf_f128, @as(i32, @bitCast(@as(u32, 0x80000001))), -0.0);
440 try test__powitf2(-inf_f128, @bitCast(i32, @as(u32, 0x80000000)), 0);440 try test__powitf2(-inf_f128, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
441441
442 try test__powitf2(2, 10, 1024.0);442 try test__powitf2(2, 10, 1024.0);
443 try test__powitf2(-2, 10, 1024.0);443 try test__powitf2(-2, 10, 1024.0);
...@@ -473,76 +473,76 @@ test "powixf2" {...@@ -473,76 +473,76 @@ test "powixf2" {
473 try test__powixf2(0, 2, 0);473 try test__powixf2(0, 2, 0);
474 try test__powixf2(0, 3, 0);474 try test__powixf2(0, 3, 0);
475 try test__powixf2(0, 4, 0);475 try test__powixf2(0, 4, 0);
476 try test__powixf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);476 try test__powixf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
477 try test__powixf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 0);477 try test__powixf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 0);
478478
479 try test__powixf2(-0.0, 1, -0.0);479 try test__powixf2(-0.0, 1, -0.0);
480 try test__powixf2(-0.0, 2, 0);480 try test__powixf2(-0.0, 2, 0);
481 try test__powixf2(-0.0, 3, -0.0);481 try test__powixf2(-0.0, 3, -0.0);
482 try test__powixf2(-0.0, 4, 0);482 try test__powixf2(-0.0, 4, 0);
483 try test__powixf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);483 try test__powixf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
484 try test__powixf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -0.0);484 try test__powixf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -0.0);
485485
486 try test__powixf2(1, 1, 1);486 try test__powixf2(1, 1, 1);
487 try test__powixf2(1, 2, 1);487 try test__powixf2(1, 2, 1);
488 try test__powixf2(1, 3, 1);488 try test__powixf2(1, 3, 1);
489 try test__powixf2(1, 4, 1);489 try test__powixf2(1, 4, 1);
490 try test__powixf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 1);490 try test__powixf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 1);
491 try test__powixf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 1);491 try test__powixf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 1);
492492
493 try test__powixf2(inf_f80, 1, inf_f80);493 try test__powixf2(inf_f80, 1, inf_f80);
494 try test__powixf2(inf_f80, 2, inf_f80);494 try test__powixf2(inf_f80, 2, inf_f80);
495 try test__powixf2(inf_f80, 3, inf_f80);495 try test__powixf2(inf_f80, 3, inf_f80);
496 try test__powixf2(inf_f80, 4, inf_f80);496 try test__powixf2(inf_f80, 4, inf_f80);
497 try test__powixf2(inf_f80, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f80);497 try test__powixf2(inf_f80, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f80);
498 try test__powixf2(inf_f80, @bitCast(i32, @as(u32, 0x7FFFFFFF)), inf_f80);498 try test__powixf2(inf_f80, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), inf_f80);
499499
500 try test__powixf2(-inf_f80, 1, -inf_f80);500 try test__powixf2(-inf_f80, 1, -inf_f80);
501 try test__powixf2(-inf_f80, 2, inf_f80);501 try test__powixf2(-inf_f80, 2, inf_f80);
502 try test__powixf2(-inf_f80, 3, -inf_f80);502 try test__powixf2(-inf_f80, 3, -inf_f80);
503 try test__powixf2(-inf_f80, 4, inf_f80);503 try test__powixf2(-inf_f80, 4, inf_f80);
504 try test__powixf2(-inf_f80, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f80);504 try test__powixf2(-inf_f80, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f80);
505 try test__powixf2(-inf_f80, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -inf_f80);505 try test__powixf2(-inf_f80, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -inf_f80);
506506
507 try test__powixf2(0, -1, inf_f80);507 try test__powixf2(0, -1, inf_f80);
508 try test__powixf2(0, -2, inf_f80);508 try test__powixf2(0, -2, inf_f80);
509 try test__powixf2(0, -3, inf_f80);509 try test__powixf2(0, -3, inf_f80);
510 try test__powixf2(0, -4, inf_f80);510 try test__powixf2(0, -4, inf_f80);
511 try test__powixf2(0, @bitCast(i32, @as(u32, 0x80000002)), inf_f80);511 try test__powixf2(0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f80);
512 try test__powixf2(0, @bitCast(i32, @as(u32, 0x80000001)), inf_f80);512 try test__powixf2(0, @as(i32, @bitCast(@as(u32, 0x80000001))), inf_f80);
513 try test__powixf2(0, @bitCast(i32, @as(u32, 0x80000000)), inf_f80);513 try test__powixf2(0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f80);
514514
515 try test__powixf2(-0.0, -1, -inf_f80);515 try test__powixf2(-0.0, -1, -inf_f80);
516 try test__powixf2(-0.0, -2, inf_f80);516 try test__powixf2(-0.0, -2, inf_f80);
517 try test__powixf2(-0.0, -3, -inf_f80);517 try test__powixf2(-0.0, -3, -inf_f80);
518 try test__powixf2(-0.0, -4, inf_f80);518 try test__powixf2(-0.0, -4, inf_f80);
519 try test__powixf2(-0.0, @bitCast(i32, @as(u32, 0x80000002)), inf_f80);519 try test__powixf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f80);
520 try test__powixf2(-0.0, @bitCast(i32, @as(u32, 0x80000001)), -inf_f80);520 try test__powixf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000001))), -inf_f80);
521 try test__powixf2(-0.0, @bitCast(i32, @as(u32, 0x80000000)), inf_f80);521 try test__powixf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f80);
522522
523 try test__powixf2(1, -1, 1);523 try test__powixf2(1, -1, 1);
524 try test__powixf2(1, -2, 1);524 try test__powixf2(1, -2, 1);
525 try test__powixf2(1, -3, 1);525 try test__powixf2(1, -3, 1);
526 try test__powixf2(1, -4, 1);526 try test__powixf2(1, -4, 1);
527 try test__powixf2(1, @bitCast(i32, @as(u32, 0x80000002)), 1);527 try test__powixf2(1, @as(i32, @bitCast(@as(u32, 0x80000002))), 1);
528 try test__powixf2(1, @bitCast(i32, @as(u32, 0x80000001)), 1);528 try test__powixf2(1, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
529 try test__powixf2(1, @bitCast(i32, @as(u32, 0x80000000)), 1);529 try test__powixf2(1, @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
530530
531 try test__powixf2(inf_f80, -1, 0);531 try test__powixf2(inf_f80, -1, 0);
532 try test__powixf2(inf_f80, -2, 0);532 try test__powixf2(inf_f80, -2, 0);
533 try test__powixf2(inf_f80, -3, 0);533 try test__powixf2(inf_f80, -3, 0);
534 try test__powixf2(inf_f80, -4, 0);534 try test__powixf2(inf_f80, -4, 0);
535 try test__powixf2(inf_f80, @bitCast(i32, @as(u32, 0x80000002)), 0);535 try test__powixf2(inf_f80, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
536 try test__powixf2(inf_f80, @bitCast(i32, @as(u32, 0x80000001)), 0);536 try test__powixf2(inf_f80, @as(i32, @bitCast(@as(u32, 0x80000001))), 0);
537 try test__powixf2(inf_f80, @bitCast(i32, @as(u32, 0x80000000)), 0);537 try test__powixf2(inf_f80, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
538538
539 try test__powixf2(-inf_f80, -1, -0.0);539 try test__powixf2(-inf_f80, -1, -0.0);
540 try test__powixf2(-inf_f80, -2, 0);540 try test__powixf2(-inf_f80, -2, 0);
541 try test__powixf2(-inf_f80, -3, -0.0);541 try test__powixf2(-inf_f80, -3, -0.0);
542 try test__powixf2(-inf_f80, -4, 0);542 try test__powixf2(-inf_f80, -4, 0);
543 try test__powixf2(-inf_f80, @bitCast(i32, @as(u32, 0x80000002)), 0);543 try test__powixf2(-inf_f80, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
544 try test__powixf2(-inf_f80, @bitCast(i32, @as(u32, 0x80000001)), -0.0);544 try test__powixf2(-inf_f80, @as(i32, @bitCast(@as(u32, 0x80000001))), -0.0);
545 try test__powixf2(-inf_f80, @bitCast(i32, @as(u32, 0x80000000)), 0);545 try test__powixf2(-inf_f80, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
546546
547 try test__powixf2(2, 10, 1024.0);547 try test__powixf2(2, 10, 1024.0);
548 try test__powixf2(-2, 10, 1024.0);548 try test__powixf2(-2, 10, 1024.0);
lib/compiler_rt/rem_pio2.zig+13-13
...@@ -26,7 +26,7 @@ const pio2_3 = 2.02226624871116645580e-21; // 0x3BA3198A, 0x2E000000...@@ -26,7 +26,7 @@ const pio2_3 = 2.02226624871116645580e-21; // 0x3BA3198A, 0x2E000000
26const pio2_3t = 8.47842766036889956997e-32; // 0x397B839A, 0x252049C126const pio2_3t = 8.47842766036889956997e-32; // 0x397B839A, 0x252049C1
2727
28fn U(x: anytype) usize {28fn U(x: anytype) usize {
29 return @intCast(usize, x);29 return @as(usize, @intCast(x));
30}30}
3131
32fn medium(ix: u32, x: f64, y: *[2]f64) i32 {32fn medium(ix: u32, x: f64, y: *[2]f64) i32 {
...@@ -41,7 +41,7 @@ fn medium(ix: u32, x: f64, y: *[2]f64) i32 {...@@ -41,7 +41,7 @@ fn medium(ix: u32, x: f64, y: *[2]f64) i32 {
4141
42 // rint(x/(pi/2))42 // rint(x/(pi/2))
43 @"fn" = x * invpio2 + toint - toint;43 @"fn" = x * invpio2 + toint - toint;
44 n = @intFromFloat(i32, @"fn");44 n = @as(i32, @intFromFloat(@"fn"));
45 r = x - @"fn" * pio2_1;45 r = x - @"fn" * pio2_1;
46 w = @"fn" * pio2_1t; // 1st round, good to 85 bits46 w = @"fn" * pio2_1t; // 1st round, good to 85 bits
47 // Matters with directed rounding.47 // Matters with directed rounding.
...@@ -57,17 +57,17 @@ fn medium(ix: u32, x: f64, y: *[2]f64) i32 {...@@ -57,17 +57,17 @@ fn medium(ix: u32, x: f64, y: *[2]f64) i32 {
57 w = @"fn" * pio2_1t;57 w = @"fn" * pio2_1t;
58 }58 }
59 y[0] = r - w;59 y[0] = r - w;
60 ui = @bitCast(u64, y[0]);60 ui = @as(u64, @bitCast(y[0]));
61 ey = @intCast(i32, (ui >> 52) & 0x7ff);61 ey = @as(i32, @intCast((ui >> 52) & 0x7ff));
62 ex = @intCast(i32, ix >> 20);62 ex = @as(i32, @intCast(ix >> 20));
63 if (ex - ey > 16) { // 2nd round, good to 118 bits63 if (ex - ey > 16) { // 2nd round, good to 118 bits
64 t = r;64 t = r;
65 w = @"fn" * pio2_2;65 w = @"fn" * pio2_2;
66 r = t - w;66 r = t - w;
67 w = @"fn" * pio2_2t - ((t - r) - w);67 w = @"fn" * pio2_2t - ((t - r) - w);
68 y[0] = r - w;68 y[0] = r - w;
69 ui = @bitCast(u64, y[0]);69 ui = @as(u64, @bitCast(y[0]));
70 ey = @intCast(i32, (ui >> 52) & 0x7ff);70 ey = @as(i32, @intCast((ui >> 52) & 0x7ff));
71 if (ex - ey > 49) { // 3rd round, good to 151 bits, covers all cases71 if (ex - ey > 49) { // 3rd round, good to 151 bits, covers all cases
72 t = r;72 t = r;
73 w = @"fn" * pio2_3;73 w = @"fn" * pio2_3;
...@@ -95,9 +95,9 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 {...@@ -95,9 +95,9 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 {
95 var i: i32 = undefined;95 var i: i32 = undefined;
96 var ui: u64 = undefined;96 var ui: u64 = undefined;
9797
98 ui = @bitCast(u64, x);98 ui = @as(u64, @bitCast(x));
99 sign = ui >> 63 != 0;99 sign = ui >> 63 != 0;
100 ix = @truncate(u32, (ui >> 32) & 0x7fffffff);100 ix = @as(u32, @truncate((ui >> 32) & 0x7fffffff));
101 if (ix <= 0x400f6a7a) { // |x| ~<= 5pi/4101 if (ix <= 0x400f6a7a) { // |x| ~<= 5pi/4
102 if ((ix & 0xfffff) == 0x921fb) { // |x| ~= pi/2 or 2pi/2102 if ((ix & 0xfffff) == 0x921fb) { // |x| ~= pi/2 or 2pi/2
103 return medium(ix, x, y);103 return medium(ix, x, y);
...@@ -171,14 +171,14 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 {...@@ -171,14 +171,14 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 {
171 return 0;171 return 0;
172 }172 }
173 // set z = scalbn(|x|,-ilogb(x)+23)173 // set z = scalbn(|x|,-ilogb(x)+23)
174 ui = @bitCast(u64, x);174 ui = @as(u64, @bitCast(x));
175 ui &= std.math.maxInt(u64) >> 12;175 ui &= std.math.maxInt(u64) >> 12;
176 ui |= @as(u64, 0x3ff + 23) << 52;176 ui |= @as(u64, 0x3ff + 23) << 52;
177 z = @bitCast(f64, ui);177 z = @as(f64, @bitCast(ui));
178178
179 i = 0;179 i = 0;
180 while (i < 2) : (i += 1) {180 while (i < 2) : (i += 1) {
181 tx[U(i)] = @floatFromInt(f64, @intFromFloat(i32, z));181 tx[U(i)] = @as(f64, @floatFromInt(@as(i32, @intFromFloat(z))));
182 z = (z - tx[U(i)]) * 0x1p24;182 z = (z - tx[U(i)]) * 0x1p24;
183 }183 }
184 tx[U(i)] = z;184 tx[U(i)] = z;
...@@ -186,7 +186,7 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 {...@@ -186,7 +186,7 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 {
186 while (tx[U(i)] == 0.0) {186 while (tx[U(i)] == 0.0) {
187 i -= 1;187 i -= 1;
188 }188 }
189 n = rem_pio2_large(tx[0..], ty[0..], @intCast(i32, (ix >> 20)) - (0x3ff + 23), i + 1, 1);189 n = rem_pio2_large(tx[0..], ty[0..], @as(i32, @intCast((ix >> 20))) - (0x3ff + 23), i + 1, 1);
190 if (sign) {190 if (sign) {
191 y[0] = -ty[0];191 y[0] = -ty[0];
192 y[1] = -ty[1];192 y[1] = -ty[1];
lib/compiler_rt/rem_pio2_large.zig+15-15
...@@ -150,7 +150,7 @@ const PIo2 = [_]f64{...@@ -150,7 +150,7 @@ const PIo2 = [_]f64{
150};150};
151151
152fn U(x: anytype) usize {152fn U(x: anytype) usize {
153 return @intCast(usize, x);153 return @as(usize, @intCast(x));
154}154}
155155
156/// Returns the last three digits of N with y = x - N*pi/2 so that |y| < pi/2.156/// Returns the last three digits of N with y = x - N*pi/2 so that |y| < pi/2.
...@@ -295,7 +295,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {...@@ -295,7 +295,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
295 i += 1;295 i += 1;
296 j += 1;296 j += 1;
297 }) {297 }) {
298 f[U(i)] = if (j < 0) 0.0 else @floatFromInt(f64, ipio2[U(j)]);298 f[U(i)] = if (j < 0) 0.0 else @as(f64, @floatFromInt(ipio2[U(j)]));
299 }299 }
300300
301 // compute q[0],q[1],...q[jk]301 // compute q[0],q[1],...q[jk]
...@@ -322,22 +322,22 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {...@@ -322,22 +322,22 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
322 i += 1;322 i += 1;
323 j -= 1;323 j -= 1;
324 }) {324 }) {
325 fw = @floatFromInt(f64, @intFromFloat(i32, 0x1p-24 * z));325 fw = @as(f64, @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z))));
326 iq[U(i)] = @intFromFloat(i32, z - 0x1p24 * fw);326 iq[U(i)] = @as(i32, @intFromFloat(z - 0x1p24 * fw));
327 z = q[U(j - 1)] + fw;327 z = q[U(j - 1)] + fw;
328 }328 }
329329
330 // compute n330 // compute n
331 z = math.scalbn(z, q0); // actual value of z331 z = math.scalbn(z, q0); // actual value of z
332 z -= 8.0 * @floor(z * 0.125); // trim off integer >= 8332 z -= 8.0 * @floor(z * 0.125); // trim off integer >= 8
333 n = @intFromFloat(i32, z);333 n = @as(i32, @intFromFloat(z));
334 z -= @floatFromInt(f64, n);334 z -= @as(f64, @floatFromInt(n));
335 ih = 0;335 ih = 0;
336 if (q0 > 0) { // need iq[jz-1] to determine n336 if (q0 > 0) { // need iq[jz-1] to determine n
337 i = iq[U(jz - 1)] >> @intCast(u5, 24 - q0);337 i = iq[U(jz - 1)] >> @as(u5, @intCast(24 - q0));
338 n += i;338 n += i;
339 iq[U(jz - 1)] -= i << @intCast(u5, 24 - q0);339 iq[U(jz - 1)] -= i << @as(u5, @intCast(24 - q0));
340 ih = iq[U(jz - 1)] >> @intCast(u5, 23 - q0);340 ih = iq[U(jz - 1)] >> @as(u5, @intCast(23 - q0));
341 } else if (q0 == 0) {341 } else if (q0 == 0) {
342 ih = iq[U(jz - 1)] >> 23;342 ih = iq[U(jz - 1)] >> 23;
343 } else if (z >= 0.5) {343 } else if (z >= 0.5) {
...@@ -390,7 +390,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {...@@ -390,7 +390,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
390390
391 i = jz + 1;391 i = jz + 1;
392 while (i <= jz + k) : (i += 1) { // add q[jz+1] to q[jz+k]392 while (i <= jz + k) : (i += 1) { // add q[jz+1] to q[jz+k]
393 f[U(jx + i)] = @floatFromInt(f64, ipio2[U(jv + i)]);393 f[U(jx + i)] = @as(f64, @floatFromInt(ipio2[U(jv + i)]));
394 j = 0;394 j = 0;
395 fw = 0;395 fw = 0;
396 while (j <= jx) : (j += 1) {396 while (j <= jx) : (j += 1) {
...@@ -414,13 +414,13 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {...@@ -414,13 +414,13 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
414 } else { // break z into 24-bit if necessary414 } else { // break z into 24-bit if necessary
415 z = math.scalbn(z, -q0);415 z = math.scalbn(z, -q0);
416 if (z >= 0x1p24) {416 if (z >= 0x1p24) {
417 fw = @floatFromInt(f64, @intFromFloat(i32, 0x1p-24 * z));417 fw = @as(f64, @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z))));
418 iq[U(jz)] = @intFromFloat(i32, z - 0x1p24 * fw);418 iq[U(jz)] = @as(i32, @intFromFloat(z - 0x1p24 * fw));
419 jz += 1;419 jz += 1;
420 q0 += 24;420 q0 += 24;
421 iq[U(jz)] = @intFromFloat(i32, fw);421 iq[U(jz)] = @as(i32, @intFromFloat(fw));
422 } else {422 } else {
423 iq[U(jz)] = @intFromFloat(i32, z);423 iq[U(jz)] = @as(i32, @intFromFloat(z));
424 }424 }
425 }425 }
426426
...@@ -428,7 +428,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {...@@ -428,7 +428,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
428 fw = math.scalbn(@as(f64, 1.0), q0);428 fw = math.scalbn(@as(f64, 1.0), q0);
429 i = jz;429 i = jz;
430 while (i >= 0) : (i -= 1) {430 while (i >= 0) : (i -= 1) {
431 q[U(i)] = fw * @floatFromInt(f64, iq[U(i)]);431 q[U(i)] = fw * @as(f64, @floatFromInt(iq[U(i)]));
432 fw *= 0x1p-24;432 fw *= 0x1p-24;
433 }433 }
434434
lib/compiler_rt/rem_pio2f.zig+5-5
...@@ -30,14 +30,14 @@ pub fn rem_pio2f(x: f32, y: *f64) i32 {...@@ -30,14 +30,14 @@ pub fn rem_pio2f(x: f32, y: *f64) i32 {
30 var e0: u32 = undefined;30 var e0: u32 = undefined;
31 var ui: u32 = undefined;31 var ui: u32 = undefined;
3232
33 ui = @bitCast(u32, x);33 ui = @as(u32, @bitCast(x));
34 ix = ui & 0x7fffffff;34 ix = ui & 0x7fffffff;
3535
36 // 25+53 bit pi is good enough for medium size36 // 25+53 bit pi is good enough for medium size
37 if (ix < 0x4dc90fdb) { // |x| ~< 2^28*(pi/2), medium size37 if (ix < 0x4dc90fdb) { // |x| ~< 2^28*(pi/2), medium size
38 // Use a specialized rint() to get fn.38 // Use a specialized rint() to get fn.
39 @"fn" = @floatCast(f64, x) * invpio2 + toint - toint;39 @"fn" = @as(f64, @floatCast(x)) * invpio2 + toint - toint;
40 n = @intFromFloat(i32, @"fn");40 n = @as(i32, @intFromFloat(@"fn"));
41 y.* = x - @"fn" * pio2_1 - @"fn" * pio2_1t;41 y.* = x - @"fn" * pio2_1 - @"fn" * pio2_1t;
42 // Matters with directed rounding.42 // Matters with directed rounding.
43 if (y.* < -pio4) {43 if (y.* < -pio4) {
...@@ -59,8 +59,8 @@ pub fn rem_pio2f(x: f32, y: *f64) i32 {...@@ -59,8 +59,8 @@ pub fn rem_pio2f(x: f32, y: *f64) i32 {
59 sign = ui >> 31 != 0;59 sign = ui >> 31 != 0;
60 e0 = (ix >> 23) - (0x7f + 23); // e0 = ilogb(|x|)-23, positive60 e0 = (ix >> 23) - (0x7f + 23); // e0 = ilogb(|x|)-23, positive
61 ui = ix - (e0 << 23);61 ui = ix - (e0 << 23);
62 tx[0] = @bitCast(f32, ui);62 tx[0] = @as(f32, @bitCast(ui));
63 n = rem_pio2_large(&tx, &ty, @intCast(i32, e0), 1, 0);63 n = rem_pio2_large(&tx, &ty, @as(i32, @intCast(e0)), 1, 0);
64 if (sign) {64 if (sign) {
65 y.* = -ty[0];65 y.* = -ty[0];
66 return -n;66 return -n;
lib/compiler_rt/round.zig+8-8
...@@ -27,14 +27,14 @@ comptime {...@@ -27,14 +27,14 @@ comptime {
2727
28pub fn __roundh(x: f16) callconv(.C) f16 {28pub fn __roundh(x: f16) callconv(.C) f16 {
29 // TODO: more efficient implementation29 // TODO: more efficient implementation
30 return @floatCast(f16, roundf(x));30 return @as(f16, @floatCast(roundf(x)));
31}31}
3232
33pub fn roundf(x_: f32) callconv(.C) f32 {33pub fn roundf(x_: f32) callconv(.C) f32 {
34 const f32_toint = 1.0 / math.floatEps(f32);34 const f32_toint = 1.0 / math.floatEps(f32);
3535
36 var x = x_;36 var x = x_;
37 const u = @bitCast(u32, x);37 const u = @as(u32, @bitCast(x));
38 const e = (u >> 23) & 0xFF;38 const e = (u >> 23) & 0xFF;
39 var y: f32 = undefined;39 var y: f32 = undefined;
4040
...@@ -46,7 +46,7 @@ pub fn roundf(x_: f32) callconv(.C) f32 {...@@ -46,7 +46,7 @@ pub fn roundf(x_: f32) callconv(.C) f32 {
46 }46 }
47 if (e < 0x7F - 1) {47 if (e < 0x7F - 1) {
48 math.doNotOptimizeAway(x + f32_toint);48 math.doNotOptimizeAway(x + f32_toint);
49 return 0 * @bitCast(f32, u);49 return 0 * @as(f32, @bitCast(u));
50 }50 }
5151
52 y = x + f32_toint - f32_toint - x;52 y = x + f32_toint - f32_toint - x;
...@@ -69,7 +69,7 @@ pub fn round(x_: f64) callconv(.C) f64 {...@@ -69,7 +69,7 @@ pub fn round(x_: f64) callconv(.C) f64 {
69 const f64_toint = 1.0 / math.floatEps(f64);69 const f64_toint = 1.0 / math.floatEps(f64);
7070
71 var x = x_;71 var x = x_;
72 const u = @bitCast(u64, x);72 const u = @as(u64, @bitCast(x));
73 const e = (u >> 52) & 0x7FF;73 const e = (u >> 52) & 0x7FF;
74 var y: f64 = undefined;74 var y: f64 = undefined;
7575
...@@ -81,7 +81,7 @@ pub fn round(x_: f64) callconv(.C) f64 {...@@ -81,7 +81,7 @@ pub fn round(x_: f64) callconv(.C) f64 {
81 }81 }
82 if (e < 0x3ff - 1) {82 if (e < 0x3ff - 1) {
83 math.doNotOptimizeAway(x + f64_toint);83 math.doNotOptimizeAway(x + f64_toint);
84 return 0 * @bitCast(f64, u);84 return 0 * @as(f64, @bitCast(u));
85 }85 }
8686
87 y = x + f64_toint - f64_toint - x;87 y = x + f64_toint - f64_toint - x;
...@@ -102,14 +102,14 @@ pub fn round(x_: f64) callconv(.C) f64 {...@@ -102,14 +102,14 @@ pub fn round(x_: f64) callconv(.C) f64 {
102102
103pub fn __roundx(x: f80) callconv(.C) f80 {103pub fn __roundx(x: f80) callconv(.C) f80 {
104 // TODO: more efficient implementation104 // TODO: more efficient implementation
105 return @floatCast(f80, roundq(x));105 return @as(f80, @floatCast(roundq(x)));
106}106}
107107
108pub fn roundq(x_: f128) callconv(.C) f128 {108pub fn roundq(x_: f128) callconv(.C) f128 {
109 const f128_toint = 1.0 / math.floatEps(f128);109 const f128_toint = 1.0 / math.floatEps(f128);
110110
111 var x = x_;111 var x = x_;
112 const u = @bitCast(u128, x);112 const u = @as(u128, @bitCast(x));
113 const e = (u >> 112) & 0x7FFF;113 const e = (u >> 112) & 0x7FFF;
114 var y: f128 = undefined;114 var y: f128 = undefined;
115115
...@@ -121,7 +121,7 @@ pub fn roundq(x_: f128) callconv(.C) f128 {...@@ -121,7 +121,7 @@ pub fn roundq(x_: f128) callconv(.C) f128 {
121 }121 }
122 if (e < 0x3FFF - 1) {122 if (e < 0x3FFF - 1) {
123 math.doNotOptimizeAway(x + f128_toint);123 math.doNotOptimizeAway(x + f128_toint);
124 return 0 * @bitCast(f128, u);124 return 0 * @as(f128, @bitCast(u));
125 }125 }
126126
127 y = x + f128_toint - f128_toint - x;127 y = x + f128_toint - f128_toint - x;
lib/compiler_rt/shift.zig+13-13
...@@ -37,13 +37,13 @@ inline fn ashlXi3(comptime T: type, a: T, b: i32) T {...@@ -37,13 +37,13 @@ inline fn ashlXi3(comptime T: type, a: T, b: i32) T {
3737
38 if (b >= word_t.bits) {38 if (b >= word_t.bits) {
39 output.s.low = 0;39 output.s.low = 0;
40 output.s.high = input.s.low << @intCast(S, b - word_t.bits);40 output.s.high = input.s.low << @as(S, @intCast(b - word_t.bits));
41 } else if (b == 0) {41 } else if (b == 0) {
42 return a;42 return a;
43 } else {43 } else {
44 output.s.low = input.s.low << @intCast(S, b);44 output.s.low = input.s.low << @as(S, @intCast(b));
45 output.s.high = input.s.high << @intCast(S, b);45 output.s.high = input.s.high << @as(S, @intCast(b));
46 output.s.high |= input.s.low >> @intCast(S, word_t.bits - b);46 output.s.high |= input.s.low >> @as(S, @intCast(word_t.bits - b));
47 }47 }
4848
49 return output.all;49 return output.all;
...@@ -60,16 +60,16 @@ inline fn ashrXi3(comptime T: type, a: T, b: i32) T {...@@ -60,16 +60,16 @@ inline fn ashrXi3(comptime T: type, a: T, b: i32) T {
6060
61 if (b >= word_t.bits) {61 if (b >= word_t.bits) {
62 output.s.high = input.s.high >> (word_t.bits - 1);62 output.s.high = input.s.high >> (word_t.bits - 1);
63 output.s.low = input.s.high >> @intCast(S, b - word_t.bits);63 output.s.low = input.s.high >> @as(S, @intCast(b - word_t.bits));
64 } else if (b == 0) {64 } else if (b == 0) {
65 return a;65 return a;
66 } else {66 } else {
67 output.s.high = input.s.high >> @intCast(S, b);67 output.s.high = input.s.high >> @as(S, @intCast(b));
68 output.s.low = input.s.high << @intCast(S, word_t.bits - b);68 output.s.low = input.s.high << @as(S, @intCast(word_t.bits - b));
69 // Avoid sign-extension here69 // Avoid sign-extension here
70 output.s.low |= @bitCast(70 output.s.low |= @as(
71 word_t.HalfT,71 word_t.HalfT,
72 @bitCast(word_t.HalfTU, input.s.low) >> @intCast(S, b),72 @bitCast(@as(word_t.HalfTU, @bitCast(input.s.low)) >> @as(S, @intCast(b))),
73 );73 );
74 }74 }
7575
...@@ -87,13 +87,13 @@ inline fn lshrXi3(comptime T: type, a: T, b: i32) T {...@@ -87,13 +87,13 @@ inline fn lshrXi3(comptime T: type, a: T, b: i32) T {
8787
88 if (b >= word_t.bits) {88 if (b >= word_t.bits) {
89 output.s.high = 0;89 output.s.high = 0;
90 output.s.low = input.s.high >> @intCast(S, b - word_t.bits);90 output.s.low = input.s.high >> @as(S, @intCast(b - word_t.bits));
91 } else if (b == 0) {91 } else if (b == 0) {
92 return a;92 return a;
93 } else {93 } else {
94 output.s.high = input.s.high >> @intCast(S, b);94 output.s.high = input.s.high >> @as(S, @intCast(b));
95 output.s.low = input.s.high << @intCast(S, word_t.bits - b);95 output.s.low = input.s.high << @as(S, @intCast(word_t.bits - b));
96 output.s.low |= input.s.low >> @intCast(S, b);96 output.s.low |= input.s.low >> @as(S, @intCast(b));
97 }97 }
9898
99 return output.all;99 return output.all;
lib/compiler_rt/shift_test.zig+289-289
...@@ -18,346 +18,346 @@ const __lshrti3 = shift.__lshrti3;...@@ -18,346 +18,346 @@ const __lshrti3 = shift.__lshrti3;
1818
19fn test__ashlsi3(a: i32, b: i32, expected: u32) !void {19fn test__ashlsi3(a: i32, b: i32, expected: u32) !void {
20 const x = __ashlsi3(a, b);20 const x = __ashlsi3(a, b);
21 try testing.expectEqual(expected, @bitCast(u32, x));21 try testing.expectEqual(expected, @as(u32, @bitCast(x)));
22}22}
23fn test__ashldi3(a: i64, b: i32, expected: u64) !void {23fn test__ashldi3(a: i64, b: i32, expected: u64) !void {
24 const x = __ashldi3(a, b);24 const x = __ashldi3(a, b);
25 try testing.expectEqual(expected, @bitCast(u64, x));25 try testing.expectEqual(expected, @as(u64, @bitCast(x)));
26}26}
27fn test__ashlti3(a: i128, b: i32, expected: u128) !void {27fn test__ashlti3(a: i128, b: i32, expected: u128) !void {
28 const x = __ashlti3(a, b);28 const x = __ashlti3(a, b);
29 try testing.expectEqual(expected, @bitCast(u128, x));29 try testing.expectEqual(expected, @as(u128, @bitCast(x)));
30}30}
3131
32test "ashlsi3" {32test "ashlsi3" {
33 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 0, 0x12ABCDEF);33 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 0, 0x12ABCDEF);
34 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 1, 0x25579BDE);34 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 1, 0x25579BDE);
35 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 2, 0x4AAF37BC);35 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 2, 0x4AAF37BC);
36 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 3, 0x955E6F78);36 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 3, 0x955E6F78);
37 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 4, 0x2ABCDEF0);37 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 4, 0x2ABCDEF0);
3838
39 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 28, 0xF0000000);39 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 28, 0xF0000000);
40 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 29, 0xE0000000);40 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 29, 0xE0000000);
41 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 30, 0xC0000000);41 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 30, 0xC0000000);
42 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 31, 0x80000000);42 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 31, 0x80000000);
43}43}
4444
45test "ashldi3" {45test "ashldi3" {
46 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);46 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 0, 0x123456789ABCDEF);
47 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x2468ACF13579BDE);47 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 1, 0x2468ACF13579BDE);
48 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37BC);48 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 2, 0x48D159E26AF37BC);
49 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x91A2B3C4D5E6F78);49 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 3, 0x91A2B3C4D5E6F78);
50 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDEF0);50 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 4, 0x123456789ABCDEF0);
5151
52 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x789ABCDEF0000000);52 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 28, 0x789ABCDEF0000000);
53 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0xF13579BDE0000000);53 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 29, 0xF13579BDE0000000);
54 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0xE26AF37BC0000000);54 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 30, 0xE26AF37BC0000000);
55 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0xC4D5E6F780000000);55 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 31, 0xC4D5E6F780000000);
5656
57 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x89ABCDEF00000000);57 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 32, 0x89ABCDEF00000000);
5858
59 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x13579BDE00000000);59 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 33, 0x13579BDE00000000);
60 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x26AF37BC00000000);60 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 34, 0x26AF37BC00000000);
61 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x4D5E6F7800000000);61 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 35, 0x4D5E6F7800000000);
62 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x9ABCDEF000000000);62 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 36, 0x9ABCDEF000000000);
6363
64 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0xF000000000000000);64 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 60, 0xF000000000000000);
65 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0xE000000000000000);65 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 61, 0xE000000000000000);
66 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0xC000000000000000);66 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 62, 0xC000000000000000);
67 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0x8000000000000000);67 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 63, 0x8000000000000000);
68}68}
6969
70test "ashlti3" {70test "ashlti3" {
71 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, 0xFEDCBA9876543215FEDCBA9876543215);71 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 0, 0xFEDCBA9876543215FEDCBA9876543215);
72 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, 0xFDB97530ECA8642BFDB97530ECA8642A);72 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 1, 0xFDB97530ECA8642BFDB97530ECA8642A);
73 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, 0xFB72EA61D950C857FB72EA61D950C854);73 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 2, 0xFB72EA61D950C857FB72EA61D950C854);
74 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, 0xF6E5D4C3B2A190AFF6E5D4C3B2A190A8);74 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 3, 0xF6E5D4C3B2A190AFF6E5D4C3B2A190A8);
75 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, 0xEDCBA9876543215FEDCBA98765432150);75 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 4, 0xEDCBA9876543215FEDCBA98765432150);
76 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, 0x876543215FEDCBA98765432150000000);76 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 28, 0x876543215FEDCBA98765432150000000);
77 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, 0x0ECA8642BFDB97530ECA8642A0000000);77 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 29, 0x0ECA8642BFDB97530ECA8642A0000000);
78 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, 0x1D950C857FB72EA61D950C8540000000);78 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 30, 0x1D950C857FB72EA61D950C8540000000);
79 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, 0x3B2A190AFF6E5D4C3B2A190A80000000);79 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 31, 0x3B2A190AFF6E5D4C3B2A190A80000000);
80 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, 0x76543215FEDCBA987654321500000000);80 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 32, 0x76543215FEDCBA987654321500000000);
81 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, 0xECA8642BFDB97530ECA8642A00000000);81 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 33, 0xECA8642BFDB97530ECA8642A00000000);
82 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, 0xD950C857FB72EA61D950C85400000000);82 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 34, 0xD950C857FB72EA61D950C85400000000);
83 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, 0xB2A190AFF6E5D4C3B2A190A800000000);83 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 35, 0xB2A190AFF6E5D4C3B2A190A800000000);
84 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, 0x6543215FEDCBA9876543215000000000);84 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 36, 0x6543215FEDCBA9876543215000000000);
85 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, 0x5FEDCBA9876543215000000000000000);85 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 60, 0x5FEDCBA9876543215000000000000000);
86 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, 0xBFDB97530ECA8642A000000000000000);86 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 61, 0xBFDB97530ECA8642A000000000000000);
87 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, 0x7FB72EA61D950C854000000000000000);87 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 62, 0x7FB72EA61D950C854000000000000000);
88 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, 0xFF6E5D4C3B2A190A8000000000000000);88 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 63, 0xFF6E5D4C3B2A190A8000000000000000);
89 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, 0xFEDCBA98765432150000000000000000);89 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 64, 0xFEDCBA98765432150000000000000000);
90 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, 0xFDB97530ECA8642A0000000000000000);90 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 65, 0xFDB97530ECA8642A0000000000000000);
91 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, 0xFB72EA61D950C8540000000000000000);91 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 66, 0xFB72EA61D950C8540000000000000000);
92 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, 0xF6E5D4C3B2A190A80000000000000000);92 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 67, 0xF6E5D4C3B2A190A80000000000000000);
93 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, 0xEDCBA987654321500000000000000000);93 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 68, 0xEDCBA987654321500000000000000000);
94 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, 0x87654321500000000000000000000000);94 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 92, 0x87654321500000000000000000000000);
95 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, 0x0ECA8642A00000000000000000000000);95 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 93, 0x0ECA8642A00000000000000000000000);
96 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, 0x1D950C85400000000000000000000000);96 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 94, 0x1D950C85400000000000000000000000);
97 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, 0x3B2A190A800000000000000000000000);97 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 95, 0x3B2A190A800000000000000000000000);
98 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, 0x76543215000000000000000000000000);98 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 96, 0x76543215000000000000000000000000);
99 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, 0xECA8642A000000000000000000000000);99 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 97, 0xECA8642A000000000000000000000000);
100 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, 0xD950C854000000000000000000000000);100 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 98, 0xD950C854000000000000000000000000);
101 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, 0xB2A190A8000000000000000000000000);101 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 99, 0xB2A190A8000000000000000000000000);
102 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, 0x65432150000000000000000000000000);102 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 100, 0x65432150000000000000000000000000);
103 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, 0x50000000000000000000000000000000);103 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 124, 0x50000000000000000000000000000000);
104 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, 0xA0000000000000000000000000000000);104 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 125, 0xA0000000000000000000000000000000);
105 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, 0x40000000000000000000000000000000);105 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 126, 0x40000000000000000000000000000000);
106 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, 0x80000000000000000000000000000000);106 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 127, 0x80000000000000000000000000000000);
107}107}
108108
109fn test__ashrsi3(a: i32, b: i32, expected: u32) !void {109fn test__ashrsi3(a: i32, b: i32, expected: u32) !void {
110 const x = __ashrsi3(a, b);110 const x = __ashrsi3(a, b);
111 try testing.expectEqual(expected, @bitCast(u32, x));111 try testing.expectEqual(expected, @as(u32, @bitCast(x)));
112}112}
113fn test__ashrdi3(a: i64, b: i32, expected: u64) !void {113fn test__ashrdi3(a: i64, b: i32, expected: u64) !void {
114 const x = __ashrdi3(a, b);114 const x = __ashrdi3(a, b);
115 try testing.expectEqual(expected, @bitCast(u64, x));115 try testing.expectEqual(expected, @as(u64, @bitCast(x)));
116}116}
117fn test__ashrti3(a: i128, b: i32, expected: u128) !void {117fn test__ashrti3(a: i128, b: i32, expected: u128) !void {
118 const x = __ashrti3(a, b);118 const x = __ashrti3(a, b);
119 try testing.expectEqual(expected, @bitCast(u128, x));119 try testing.expectEqual(expected, @as(u128, @bitCast(x)));
120}120}
121121
122test "ashrsi3" {122test "ashrsi3" {
123 try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 0, 0xFEDBCA98);123 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 0, 0xFEDBCA98);
124 try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 1, 0xFF6DE54C);124 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 1, 0xFF6DE54C);
125 try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 2, 0xFFB6F2A6);125 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 2, 0xFFB6F2A6);
126 try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 3, 0xFFDB7953);126 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 3, 0xFFDB7953);
127 try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 4, 0xFFEDBCA9);127 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 4, 0xFFEDBCA9);
128128
129 try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 28, 0xFFFFFFFF);129 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 28, 0xFFFFFFFF);
130 try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 31, 0xFFFFFFFF);130 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 31, 0xFFFFFFFF);
131131
132 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 0, 0x8CEF8CEF);132 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 0, 0x8CEF8CEF);
133 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 1, 0xC677C677);133 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 1, 0xC677C677);
134 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 2, 0xE33BE33B);134 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 2, 0xE33BE33B);
135 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 3, 0xF19DF19D);135 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 3, 0xF19DF19D);
136 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 4, 0xF8CEF8CE);136 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 4, 0xF8CEF8CE);
137137
138 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 28, 0xFFFFFFF8);138 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 28, 0xFFFFFFF8);
139 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 29, 0xFFFFFFFC);139 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 29, 0xFFFFFFFC);
140 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 30, 0xFFFFFFFE);140 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 30, 0xFFFFFFFE);
141 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 31, 0xFFFFFFFF);141 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 31, 0xFFFFFFFF);
142}142}
143143
144test "ashrdi3" {144test "ashrdi3" {
145 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);145 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 0, 0x123456789ABCDEF);
146 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);146 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 1, 0x91A2B3C4D5E6F7);
147 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);147 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 2, 0x48D159E26AF37B);
148 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);148 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 3, 0x2468ACF13579BD);
149 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);149 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 4, 0x123456789ABCDE);
150150
151 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);151 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 28, 0x12345678);
152 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);152 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 29, 0x91A2B3C);
153 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);153 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 30, 0x48D159E);
154 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);154 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 31, 0x2468ACF);
155155
156 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);156 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 32, 0x1234567);
157157
158 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);158 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 33, 0x91A2B3);
159 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);159 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 34, 0x48D159);
160 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);160 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 35, 0x2468AC);
161 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);161 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 36, 0x123456);
162162
163 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);163 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 60, 0);
164 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);164 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 61, 0);
165 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);165 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 62, 0);
166 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);166 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 63, 0);
167167
168 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);168 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 0, 0xFEDCBA9876543210);
169 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0xFF6E5D4C3B2A1908);169 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 1, 0xFF6E5D4C3B2A1908);
170 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0xFFB72EA61D950C84);170 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 2, 0xFFB72EA61D950C84);
171 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0xFFDB97530ECA8642);171 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 3, 0xFFDB97530ECA8642);
172 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFFEDCBA987654321);172 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 4, 0xFFEDCBA987654321);
173173
174 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFFFFFFFFEDCBA987);174 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 28, 0xFFFFFFFFEDCBA987);
175 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0xFFFFFFFFF6E5D4C3);175 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 29, 0xFFFFFFFFF6E5D4C3);
176 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0xFFFFFFFFFB72EA61);176 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 30, 0xFFFFFFFFFB72EA61);
177 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0xFFFFFFFFFDB97530);177 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 31, 0xFFFFFFFFFDB97530);
178178
179 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFFFFFFFFFEDCBA98);179 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 32, 0xFFFFFFFFFEDCBA98);
180180
181 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0xFFFFFFFFFF6E5D4C);181 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 33, 0xFFFFFFFFFF6E5D4C);
182 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0xFFFFFFFFFFB72EA6);182 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 34, 0xFFFFFFFFFFB72EA6);
183 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0xFFFFFFFFFFDB9753);183 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 35, 0xFFFFFFFFFFDB9753);
184 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFFFFFFFFFFEDCBA9);184 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 36, 0xFFFFFFFFFFEDCBA9);
185185
186 try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xFFFFFFFFFFFFFFFA);186 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xAEDCBA9876543210))), 60, 0xFFFFFFFFFFFFFFFA);
187 try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0xFFFFFFFFFFFFFFFD);187 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xAEDCBA9876543210))), 61, 0xFFFFFFFFFFFFFFFD);
188 try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0xFFFFFFFFFFFFFFFE);188 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xAEDCBA9876543210))), 62, 0xFFFFFFFFFFFFFFFE);
189 try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0xFFFFFFFFFFFFFFFF);189 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xAEDCBA9876543210))), 63, 0xFFFFFFFFFFFFFFFF);
190}190}
191191
192test "ashrti3" {192test "ashrti3" {
193 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, 0xFEDCBA9876543215FEDCBA9876543215);193 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 0, 0xFEDCBA9876543215FEDCBA9876543215);
194 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, 0xFF6E5D4C3B2A190AFF6E5D4C3B2A190A);194 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 1, 0xFF6E5D4C3B2A190AFF6E5D4C3B2A190A);
195 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, 0xFFB72EA61D950C857FB72EA61D950C85);195 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 2, 0xFFB72EA61D950C857FB72EA61D950C85);
196 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, 0xFFDB97530ECA8642BFDB97530ECA8642);196 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 3, 0xFFDB97530ECA8642BFDB97530ECA8642);
197 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, 0xFFEDCBA9876543215FEDCBA987654321);197 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 4, 0xFFEDCBA9876543215FEDCBA987654321);
198198
199 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, 0xFFFFFFFFEDCBA9876543215FEDCBA987);199 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 28, 0xFFFFFFFFEDCBA9876543215FEDCBA987);
200 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, 0xFFFFFFFFF6E5D4C3B2A190AFF6E5D4C3);200 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 29, 0xFFFFFFFFF6E5D4C3B2A190AFF6E5D4C3);
201 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, 0xFFFFFFFFFB72EA61D950C857FB72EA61);201 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 30, 0xFFFFFFFFFB72EA61D950C857FB72EA61);
202 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, 0xFFFFFFFFFDB97530ECA8642BFDB97530);202 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 31, 0xFFFFFFFFFDB97530ECA8642BFDB97530);
203203
204 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, 0xFFFFFFFFFEDCBA9876543215FEDCBA98);204 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 32, 0xFFFFFFFFFEDCBA9876543215FEDCBA98);
205205
206 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, 0xFFFFFFFFFF6E5D4C3B2A190AFF6E5D4C);206 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 33, 0xFFFFFFFFFF6E5D4C3B2A190AFF6E5D4C);
207 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, 0xFFFFFFFFFFB72EA61D950C857FB72EA6);207 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 34, 0xFFFFFFFFFFB72EA61D950C857FB72EA6);
208 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, 0xFFFFFFFFFFDB97530ECA8642BFDB9753);208 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 35, 0xFFFFFFFFFFDB97530ECA8642BFDB9753);
209 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, 0xFFFFFFFFFFEDCBA9876543215FEDCBA9);209 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 36, 0xFFFFFFFFFFEDCBA9876543215FEDCBA9);
210210
211 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, 0xFFFFFFFFFFFFFFFFEDCBA9876543215F);211 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 60, 0xFFFFFFFFFFFFFFFFEDCBA9876543215F);
212 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, 0xFFFFFFFFFFFFFFFFF6E5D4C3B2A190AF);212 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 61, 0xFFFFFFFFFFFFFFFFF6E5D4C3B2A190AF);
213 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, 0xFFFFFFFFFFFFFFFFFB72EA61D950C857);213 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 62, 0xFFFFFFFFFFFFFFFFFB72EA61D950C857);
214 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, 0xFFFFFFFFFFFFFFFFFDB97530ECA8642B);214 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 63, 0xFFFFFFFFFFFFFFFFFDB97530ECA8642B);
215215
216 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, 0xFFFFFFFFFFFFFFFFFEDCBA9876543215);216 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 64, 0xFFFFFFFFFFFFFFFFFEDCBA9876543215);
217217
218 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, 0xFFFFFFFFFFFFFFFFFF6E5D4C3B2A190A);218 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 65, 0xFFFFFFFFFFFFFFFFFF6E5D4C3B2A190A);
219 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, 0xFFFFFFFFFFFFFFFFFFB72EA61D950C85);219 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 66, 0xFFFFFFFFFFFFFFFFFFB72EA61D950C85);
220 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, 0xFFFFFFFFFFFFFFFFFFDB97530ECA8642);220 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 67, 0xFFFFFFFFFFFFFFFFFFDB97530ECA8642);
221 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, 0xFFFFFFFFFFFFFFFFFFEDCBA987654321);221 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 68, 0xFFFFFFFFFFFFFFFFFFEDCBA987654321);
222222
223 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, 0xFFFFFFFFFFFFFFFFFFFFFFFFEDCBA987);223 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 92, 0xFFFFFFFFFFFFFFFFFFFFFFFFEDCBA987);
224 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, 0xFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C3);224 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 93, 0xFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C3);
225 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, 0xFFFFFFFFFFFFFFFFFFFFFFFFFB72EA61);225 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 94, 0xFFFFFFFFFFFFFFFFFFFFFFFFFB72EA61);
226 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, 0xFFFFFFFFFFFFFFFFFFFFFFFFFDB97530);226 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 95, 0xFFFFFFFFFFFFFFFFFFFFFFFFFDB97530);
227227
228 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA98);228 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA98);
229229
230 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, 0xFFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C);230 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 97, 0xFFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C);
231 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFB72EA6);231 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 98, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFB72EA6);
232 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFDB9753);232 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 99, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFDB9753);
233 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA9);233 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 100, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA9);
234234
235 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);235 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 124, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
236 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);236 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 125, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
237 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);237 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 126, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
238 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);238 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 127, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
239}239}
240240
241fn test__lshrsi3(a: i32, b: i32, expected: u32) !void {241fn test__lshrsi3(a: i32, b: i32, expected: u32) !void {
242 const x = __lshrsi3(a, b);242 const x = __lshrsi3(a, b);
243 try testing.expectEqual(expected, @bitCast(u32, x));243 try testing.expectEqual(expected, @as(u32, @bitCast(x)));
244}244}
245fn test__lshrdi3(a: i64, b: i32, expected: u64) !void {245fn test__lshrdi3(a: i64, b: i32, expected: u64) !void {
246 const x = __lshrdi3(a, b);246 const x = __lshrdi3(a, b);
247 try testing.expectEqual(expected, @bitCast(u64, x));247 try testing.expectEqual(expected, @as(u64, @bitCast(x)));
248}248}
249fn test__lshrti3(a: i128, b: i32, expected: u128) !void {249fn test__lshrti3(a: i128, b: i32, expected: u128) !void {
250 const x = __lshrti3(a, b);250 const x = __lshrti3(a, b);
251 try testing.expectEqual(expected, @bitCast(u128, x));251 try testing.expectEqual(expected, @as(u128, @bitCast(x)));
252}252}
253253
254test "lshrsi3" {254test "lshrsi3" {
255 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 0, 0xFEDBCA98);255 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 0, 0xFEDBCA98);
256 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 1, 0x7F6DE54C);256 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 1, 0x7F6DE54C);
257 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 2, 0x3FB6F2A6);257 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 2, 0x3FB6F2A6);
258 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 3, 0x1FDB7953);258 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 3, 0x1FDB7953);
259 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 4, 0xFEDBCA9);259 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 4, 0xFEDBCA9);
260260
261 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 28, 0xF);261 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 28, 0xF);
262 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 29, 0x7);262 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 29, 0x7);
263 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 30, 0x3);263 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 30, 0x3);
264 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 31, 0x1);264 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 31, 0x1);
265265
266 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 0, 0x8CEF8CEF);266 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 0, 0x8CEF8CEF);
267 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 1, 0x4677C677);267 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 1, 0x4677C677);
268 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 2, 0x233BE33B);268 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 2, 0x233BE33B);
269 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 3, 0x119DF19D);269 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 3, 0x119DF19D);
270 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 4, 0x8CEF8CE);270 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 4, 0x8CEF8CE);
271271
272 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 28, 0x8);272 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 28, 0x8);
273 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 29, 0x4);273 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 29, 0x4);
274 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 30, 0x2);274 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 30, 0x2);
275 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 31, 0x1);275 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 31, 0x1);
276}276}
277277
278test "lshrdi3" {278test "lshrdi3" {
279 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);279 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 0, 0x123456789ABCDEF);
280 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);280 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 1, 0x91A2B3C4D5E6F7);
281 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);281 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 2, 0x48D159E26AF37B);
282 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);282 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 3, 0x2468ACF13579BD);
283 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);283 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 4, 0x123456789ABCDE);
284284
285 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);285 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 28, 0x12345678);
286 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);286 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 29, 0x91A2B3C);
287 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);287 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 30, 0x48D159E);
288 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);288 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 31, 0x2468ACF);
289289
290 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);290 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 32, 0x1234567);
291291
292 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);292 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 33, 0x91A2B3);
293 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);293 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 34, 0x48D159);
294 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);294 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 35, 0x2468AC);
295 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);295 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 36, 0x123456);
296296
297 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);297 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 60, 0);
298 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);298 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 61, 0);
299 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);299 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 62, 0);
300 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);300 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 63, 0);
301301
302 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);302 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 0, 0xFEDCBA9876543210);
303 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0x7F6E5D4C3B2A1908);303 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 1, 0x7F6E5D4C3B2A1908);
304 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0x3FB72EA61D950C84);304 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 2, 0x3FB72EA61D950C84);
305 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0x1FDB97530ECA8642);305 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 3, 0x1FDB97530ECA8642);
306 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFEDCBA987654321);306 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 4, 0xFEDCBA987654321);
307307
308 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFEDCBA987);308 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 28, 0xFEDCBA987);
309 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0x7F6E5D4C3);309 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 29, 0x7F6E5D4C3);
310 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0x3FB72EA61);310 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 30, 0x3FB72EA61);
311 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0x1FDB97530);311 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 31, 0x1FDB97530);
312312
313 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFEDCBA98);313 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 32, 0xFEDCBA98);
314314
315 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0x7F6E5D4C);315 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 33, 0x7F6E5D4C);
316 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0x3FB72EA6);316 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 34, 0x3FB72EA6);
317 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0x1FDB9753);317 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 35, 0x1FDB9753);
318 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFEDCBA9);318 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 36, 0xFEDCBA9);
319319
320 try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xA);320 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xAEDCBA9876543210))), 60, 0xA);
321 try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0x5);321 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xAEDCBA9876543210))), 61, 0x5);
322 try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0x2);322 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xAEDCBA9876543210))), 62, 0x2);
323 try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0x1);323 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xAEDCBA9876543210))), 63, 0x1);
324}324}
325325
326test "lshrti3" {326test "lshrti3" {
327 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 0, 0xFEDCBA9876543215FEDCBA987654321F);327 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 0, 0xFEDCBA9876543215FEDCBA987654321F);
328 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 1, 0x7F6E5D4C3B2A190AFF6E5D4C3B2A190F);328 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 1, 0x7F6E5D4C3B2A190AFF6E5D4C3B2A190F);
329 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 2, 0x3FB72EA61D950C857FB72EA61D950C87);329 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 2, 0x3FB72EA61D950C857FB72EA61D950C87);
330 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 3, 0x1FDB97530ECA8642BFDB97530ECA8643);330 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 3, 0x1FDB97530ECA8642BFDB97530ECA8643);
331 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 4, 0xFEDCBA9876543215FEDCBA987654321);331 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 4, 0xFEDCBA9876543215FEDCBA987654321);
332 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 28, 0xFEDCBA9876543215FEDCBA987);332 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 28, 0xFEDCBA9876543215FEDCBA987);
333 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 29, 0x7F6E5D4C3B2A190AFF6E5D4C3);333 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 29, 0x7F6E5D4C3B2A190AFF6E5D4C3);
334 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 30, 0x3FB72EA61D950C857FB72EA61);334 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 30, 0x3FB72EA61D950C857FB72EA61);
335 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 31, 0x1FDB97530ECA8642BFDB97530);335 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 31, 0x1FDB97530ECA8642BFDB97530);
336 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 32, 0xFEDCBA9876543215FEDCBA98);336 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 32, 0xFEDCBA9876543215FEDCBA98);
337 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 33, 0x7F6E5D4C3B2A190AFF6E5D4C);337 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 33, 0x7F6E5D4C3B2A190AFF6E5D4C);
338 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 34, 0x3FB72EA61D950C857FB72EA6);338 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 34, 0x3FB72EA61D950C857FB72EA6);
339 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 35, 0x1FDB97530ECA8642BFDB9753);339 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 35, 0x1FDB97530ECA8642BFDB9753);
340 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 36, 0xFEDCBA9876543215FEDCBA9);340 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 36, 0xFEDCBA9876543215FEDCBA9);
341 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 60, 0xFEDCBA9876543215F);341 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 60, 0xFEDCBA9876543215F);
342 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 61, 0x7F6E5D4C3B2A190AF);342 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 61, 0x7F6E5D4C3B2A190AF);
343 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 62, 0x3FB72EA61D950C857);343 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 62, 0x3FB72EA61D950C857);
344 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 63, 0x1FDB97530ECA8642B);344 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 63, 0x1FDB97530ECA8642B);
345 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 64, 0xFEDCBA9876543215);345 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 64, 0xFEDCBA9876543215);
346 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 65, 0x7F6E5D4C3B2A190A);346 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 65, 0x7F6E5D4C3B2A190A);
347 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 66, 0x3FB72EA61D950C85);347 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 66, 0x3FB72EA61D950C85);
348 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 67, 0x1FDB97530ECA8642);348 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 67, 0x1FDB97530ECA8642);
349 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 68, 0xFEDCBA987654321);349 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 68, 0xFEDCBA987654321);
350 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 92, 0xFEDCBA987);350 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 92, 0xFEDCBA987);
351 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 93, 0x7F6E5D4C3);351 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 93, 0x7F6E5D4C3);
352 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 94, 0x3FB72EA61);352 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 94, 0x3FB72EA61);
353 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 95, 0x1FDB97530);353 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 95, 0x1FDB97530);
354 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 96, 0xFEDCBA98);354 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 96, 0xFEDCBA98);
355 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 97, 0x7F6E5D4C);355 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 97, 0x7F6E5D4C);
356 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 98, 0x3FB72EA6);356 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 98, 0x3FB72EA6);
357 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 99, 0x1FDB9753);357 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 99, 0x1FDB9753);
358 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 100, 0xFEDCBA9);358 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 100, 0xFEDCBA9);
359 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 124, 0xF);359 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 124, 0xF);
360 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 125, 0x7);360 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 125, 0x7);
361 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 126, 0x3);361 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 126, 0x3);
362 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 127, 0x1);362 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 127, 0x1);
363}363}
lib/compiler_rt/sin.zig+7-7
...@@ -31,7 +31,7 @@ comptime {...@@ -31,7 +31,7 @@ comptime {
3131
32pub fn __sinh(x: f16) callconv(.C) f16 {32pub fn __sinh(x: f16) callconv(.C) f16 {
33 // TODO: more efficient implementation33 // TODO: more efficient implementation
34 return @floatCast(f16, sinf(x));34 return @as(f16, @floatCast(sinf(x)));
35}35}
3636
37pub fn sinf(x: f32) callconv(.C) f32 {37pub fn sinf(x: f32) callconv(.C) f32 {
...@@ -41,7 +41,7 @@ pub fn sinf(x: f32) callconv(.C) f32 {...@@ -41,7 +41,7 @@ pub fn sinf(x: f32) callconv(.C) f32 {
41 const s3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D241 const s3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2
42 const s4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D1842 const s4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18
4343
44 var ix = @bitCast(u32, x);44 var ix = @as(u32, @bitCast(x));
45 const sign = ix >> 31 != 0;45 const sign = ix >> 31 != 0;
46 ix &= 0x7fffffff;46 ix &= 0x7fffffff;
4747
...@@ -90,7 +90,7 @@ pub fn sinf(x: f32) callconv(.C) f32 {...@@ -90,7 +90,7 @@ pub fn sinf(x: f32) callconv(.C) f32 {
90}90}
9191
92pub fn sin(x: f64) callconv(.C) f64 {92pub fn sin(x: f64) callconv(.C) f64 {
93 var ix = @bitCast(u64, x) >> 32;93 var ix = @as(u64, @bitCast(x)) >> 32;
94 ix &= 0x7fffffff;94 ix &= 0x7fffffff;
9595
96 // |x| ~< pi/496 // |x| ~< pi/4
...@@ -120,12 +120,12 @@ pub fn sin(x: f64) callconv(.C) f64 {...@@ -120,12 +120,12 @@ pub fn sin(x: f64) callconv(.C) f64 {
120120
121pub fn __sinx(x: f80) callconv(.C) f80 {121pub fn __sinx(x: f80) callconv(.C) f80 {
122 // TODO: more efficient implementation122 // TODO: more efficient implementation
123 return @floatCast(f80, sinq(x));123 return @as(f80, @floatCast(sinq(x)));
124}124}
125125
126pub fn sinq(x: f128) callconv(.C) f128 {126pub fn sinq(x: f128) callconv(.C) f128 {
127 // TODO: more correct implementation127 // TODO: more correct implementation
128 return sin(@floatCast(f64, x));128 return sin(@as(f64, @floatCast(x)));
129}129}
130130
131pub fn sinl(x: c_longdouble) callconv(.C) c_longdouble {131pub fn sinl(x: c_longdouble) callconv(.C) c_longdouble {
...@@ -180,11 +180,11 @@ test "sin64.special" {...@@ -180,11 +180,11 @@ test "sin64.special" {
180}180}
181181
182test "sin32 #9901" {182test "sin32 #9901" {
183 const float = @bitCast(f32, @as(u32, 0b11100011111111110000000000000000));183 const float = @as(f32, @bitCast(@as(u32, 0b11100011111111110000000000000000)));
184 _ = sinf(float);184 _ = sinf(float);
185}185}
186186
187test "sin64 #9901" {187test "sin64 #9901" {
188 const float = @bitCast(f64, @as(u64, 0b1111111101000001000000001111110111111111100000000000000000000001));188 const float = @as(f64, @bitCast(@as(u64, 0b1111111101000001000000001111110111111111100000000000000000000001)));
189 _ = sin(float);189 _ = sin(float);
190}190}
lib/compiler_rt/sincos.zig+10-10
...@@ -26,8 +26,8 @@ pub fn __sincosh(x: f16, r_sin: *f16, r_cos: *f16) callconv(.C) void {...@@ -26,8 +26,8 @@ pub fn __sincosh(x: f16, r_sin: *f16, r_cos: *f16) callconv(.C) void {
26 var big_sin: f32 = undefined;26 var big_sin: f32 = undefined;
27 var big_cos: f32 = undefined;27 var big_cos: f32 = undefined;
28 sincosf(x, &big_sin, &big_cos);28 sincosf(x, &big_sin, &big_cos);
29 r_sin.* = @floatCast(f16, big_sin);29 r_sin.* = @as(f16, @floatCast(big_sin));
30 r_cos.* = @floatCast(f16, big_cos);30 r_cos.* = @as(f16, @floatCast(big_cos));
31}31}
3232
33pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.C) void {33pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.C) void {
...@@ -36,7 +36,7 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.C) void {...@@ -36,7 +36,7 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.C) void {
36 const sc3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D236 const sc3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2
37 const sc4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D1837 const sc4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18
3838
39 const pre_ix = @bitCast(u32, x);39 const pre_ix = @as(u32, @bitCast(x));
40 const sign = pre_ix >> 31 != 0;40 const sign = pre_ix >> 31 != 0;
41 const ix = pre_ix & 0x7fffffff;41 const ix = pre_ix & 0x7fffffff;
4242
...@@ -126,7 +126,7 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.C) void {...@@ -126,7 +126,7 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.C) void {
126}126}
127127
128pub fn sincos(x: f64, r_sin: *f64, r_cos: *f64) callconv(.C) void {128pub fn sincos(x: f64, r_sin: *f64, r_cos: *f64) callconv(.C) void {
129 const ix = @truncate(u32, @bitCast(u64, x) >> 32) & 0x7fffffff;129 const ix = @as(u32, @truncate(@as(u64, @bitCast(x)) >> 32)) & 0x7fffffff;
130130
131 // |x| ~< pi/4131 // |x| ~< pi/4
132 if (ix <= 0x3fe921fb) {132 if (ix <= 0x3fe921fb) {
...@@ -182,8 +182,8 @@ pub fn __sincosx(x: f80, r_sin: *f80, r_cos: *f80) callconv(.C) void {...@@ -182,8 +182,8 @@ pub fn __sincosx(x: f80, r_sin: *f80, r_cos: *f80) callconv(.C) void {
182 var big_sin: f128 = undefined;182 var big_sin: f128 = undefined;
183 var big_cos: f128 = undefined;183 var big_cos: f128 = undefined;
184 sincosq(x, &big_sin, &big_cos);184 sincosq(x, &big_sin, &big_cos);
185 r_sin.* = @floatCast(f80, big_sin);185 r_sin.* = @as(f80, @floatCast(big_sin));
186 r_cos.* = @floatCast(f80, big_cos);186 r_cos.* = @as(f80, @floatCast(big_cos));
187}187}
188188
189pub fn sincosq(x: f128, r_sin: *f128, r_cos: *f128) callconv(.C) void {189pub fn sincosq(x: f128, r_sin: *f128, r_cos: *f128) callconv(.C) void {
...@@ -191,7 +191,7 @@ pub fn sincosq(x: f128, r_sin: *f128, r_cos: *f128) callconv(.C) void {...@@ -191,7 +191,7 @@ pub fn sincosq(x: f128, r_sin: *f128, r_cos: *f128) callconv(.C) void {
191 //return sincos_generic(f128, x, r_sin, r_cos);191 //return sincos_generic(f128, x, r_sin, r_cos);
192 var small_sin: f64 = undefined;192 var small_sin: f64 = undefined;
193 var small_cos: f64 = undefined;193 var small_cos: f64 = undefined;
194 sincos(@floatCast(f64, x), &small_sin, &small_cos);194 sincos(@as(f64, @floatCast(x)), &small_sin, &small_cos);
195 r_sin.* = small_sin;195 r_sin.* = small_sin;
196 r_cos.* = small_cos;196 r_cos.* = small_cos;
197}197}
...@@ -217,8 +217,8 @@ inline fn sincos_generic(comptime F: type, x: F, r_sin: *F, r_cos: *F) void {...@@ -217,8 +217,8 @@ inline fn sincos_generic(comptime F: type, x: F, r_sin: *F, r_cos: *F) void {
217 const sc1pio4: F = 1.0 * math.pi / 4.0;217 const sc1pio4: F = 1.0 * math.pi / 4.0;
218 const bits = @typeInfo(F).Float.bits;218 const bits = @typeInfo(F).Float.bits;
219 const I = std.meta.Int(.unsigned, bits);219 const I = std.meta.Int(.unsigned, bits);
220 const ix = @bitCast(I, x) & (math.maxInt(I) >> 1);220 const ix = @as(I, @bitCast(x)) & (math.maxInt(I) >> 1);
221 const se = @truncate(u16, ix >> (bits - 16));221 const se = @as(u16, @truncate(ix >> (bits - 16)));
222222
223 if (se == 0x7fff) {223 if (se == 0x7fff) {
224 const result = x - x;224 const result = x - x;
...@@ -227,7 +227,7 @@ inline fn sincos_generic(comptime F: type, x: F, r_sin: *F, r_cos: *F) void {...@@ -227,7 +227,7 @@ inline fn sincos_generic(comptime F: type, x: F, r_sin: *F, r_cos: *F) void {
227 return;227 return;
228 }228 }
229229
230 if (@bitCast(F, ix) < sc1pio4) {230 if (@as(F, @bitCast(ix)) < sc1pio4) {
231 if (se < 0x3fff - math.floatFractionalBits(F) - 1) {231 if (se < 0x3fff - math.floatFractionalBits(F) - 1) {
232 // raise underflow if subnormal232 // raise underflow if subnormal
233 if (se == 0) {233 if (se == 0) {
lib/compiler_rt/sqrt.zig+16-16
...@@ -20,13 +20,13 @@ comptime {...@@ -20,13 +20,13 @@ comptime {
2020
21pub fn __sqrth(x: f16) callconv(.C) f16 {21pub fn __sqrth(x: f16) callconv(.C) f16 {
22 // TODO: more efficient implementation22 // TODO: more efficient implementation
23 return @floatCast(f16, sqrtf(x));23 return @as(f16, @floatCast(sqrtf(x)));
24}24}
2525
26pub fn sqrtf(x: f32) callconv(.C) f32 {26pub fn sqrtf(x: f32) callconv(.C) f32 {
27 const tiny: f32 = 1.0e-30;27 const tiny: f32 = 1.0e-30;
28 const sign: i32 = @bitCast(i32, @as(u32, 0x80000000));28 const sign: i32 = @as(i32, @bitCast(@as(u32, 0x80000000)));
29 var ix: i32 = @bitCast(i32, x);29 var ix: i32 = @as(i32, @bitCast(x));
3030
31 if ((ix & 0x7F800000) == 0x7F800000) {31 if ((ix & 0x7F800000) == 0x7F800000) {
32 return x * x + x; // sqrt(nan) = nan, sqrt(+inf) = +inf, sqrt(-inf) = snan32 return x * x + x; // sqrt(nan) = nan, sqrt(+inf) = +inf, sqrt(-inf) = snan
...@@ -96,7 +96,7 @@ pub fn sqrtf(x: f32) callconv(.C) f32 {...@@ -96,7 +96,7 @@ pub fn sqrtf(x: f32) callconv(.C) f32 {
9696
97 ix = (q >> 1) + 0x3f000000;97 ix = (q >> 1) + 0x3f000000;
98 ix += m << 23;98 ix += m << 23;
99 return @bitCast(f32, ix);99 return @as(f32, @bitCast(ix));
100}100}
101101
102/// NOTE: The original code is full of implicit signed -> unsigned assumptions and u32 wraparound102/// NOTE: The original code is full of implicit signed -> unsigned assumptions and u32 wraparound
...@@ -105,10 +105,10 @@ pub fn sqrtf(x: f32) callconv(.C) f32 {...@@ -105,10 +105,10 @@ pub fn sqrtf(x: f32) callconv(.C) f32 {
105pub fn sqrt(x: f64) callconv(.C) f64 {105pub fn sqrt(x: f64) callconv(.C) f64 {
106 const tiny: f64 = 1.0e-300;106 const tiny: f64 = 1.0e-300;
107 const sign: u32 = 0x80000000;107 const sign: u32 = 0x80000000;
108 const u = @bitCast(u64, x);108 const u = @as(u64, @bitCast(x));
109109
110 var ix0 = @intCast(u32, u >> 32);110 var ix0 = @as(u32, @intCast(u >> 32));
111 var ix1 = @intCast(u32, u & 0xFFFFFFFF);111 var ix1 = @as(u32, @intCast(u & 0xFFFFFFFF));
112112
113 // sqrt(nan) = nan, sqrt(+inf) = +inf, sqrt(-inf) = nan113 // sqrt(nan) = nan, sqrt(+inf) = +inf, sqrt(-inf) = nan
114 if (ix0 & 0x7FF00000 == 0x7FF00000) {114 if (ix0 & 0x7FF00000 == 0x7FF00000) {
...@@ -125,7 +125,7 @@ pub fn sqrt(x: f64) callconv(.C) f64 {...@@ -125,7 +125,7 @@ pub fn sqrt(x: f64) callconv(.C) f64 {
125 }125 }
126126
127 // normalize x127 // normalize x
128 var m = @intCast(i32, ix0 >> 20);128 var m = @as(i32, @intCast(ix0 >> 20));
129 if (m == 0) {129 if (m == 0) {
130 // subnormal130 // subnormal
131 while (ix0 == 0) {131 while (ix0 == 0) {
...@@ -139,9 +139,9 @@ pub fn sqrt(x: f64) callconv(.C) f64 {...@@ -139,9 +139,9 @@ pub fn sqrt(x: f64) callconv(.C) f64 {
139 while (ix0 & 0x00100000 == 0) : (i += 1) {139 while (ix0 & 0x00100000 == 0) : (i += 1) {
140 ix0 <<= 1;140 ix0 <<= 1;
141 }141 }
142 m -= @intCast(i32, i) - 1;142 m -= @as(i32, @intCast(i)) - 1;
143 ix0 |= ix1 >> @intCast(u5, 32 - i);143 ix0 |= ix1 >> @as(u5, @intCast(32 - i));
144 ix1 <<= @intCast(u5, i);144 ix1 <<= @as(u5, @intCast(i));
145 }145 }
146146
147 // unbias exponent147 // unbias exponent
...@@ -225,21 +225,21 @@ pub fn sqrt(x: f64) callconv(.C) f64 {...@@ -225,21 +225,21 @@ pub fn sqrt(x: f64) callconv(.C) f64 {
225225
226 // NOTE: musl here appears to rely on signed twos-complement wraparound. +% has the same226 // NOTE: musl here appears to rely on signed twos-complement wraparound. +% has the same
227 // behaviour at least.227 // behaviour at least.
228 var iix0 = @intCast(i32, ix0);228 var iix0 = @as(i32, @intCast(ix0));
229 iix0 = iix0 +% (m << 20);229 iix0 = iix0 +% (m << 20);
230230
231 const uz = (@intCast(u64, iix0) << 32) | ix1;231 const uz = (@as(u64, @intCast(iix0)) << 32) | ix1;
232 return @bitCast(f64, uz);232 return @as(f64, @bitCast(uz));
233}233}
234234
235pub fn __sqrtx(x: f80) callconv(.C) f80 {235pub fn __sqrtx(x: f80) callconv(.C) f80 {
236 // TODO: more efficient implementation236 // TODO: more efficient implementation
237 return @floatCast(f80, sqrtq(x));237 return @as(f80, @floatCast(sqrtq(x)));
238}238}
239239
240pub fn sqrtq(x: f128) callconv(.C) f128 {240pub fn sqrtq(x: f128) callconv(.C) f128 {
241 // TODO: more correct implementation241 // TODO: more correct implementation
242 return sqrt(@floatCast(f64, x));242 return sqrt(@as(f64, @floatCast(x)));
243}243}
244244
245pub fn sqrtl(x: c_longdouble) callconv(.C) c_longdouble {245pub fn sqrtl(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/subdf3.zig+2-2
...@@ -11,11 +11,11 @@ comptime {...@@ -11,11 +11,11 @@ comptime {
11}11}
1212
13fn __subdf3(a: f64, b: f64) callconv(.C) f64 {13fn __subdf3(a: f64, b: f64) callconv(.C) f64 {
14 const neg_b = @bitCast(f64, @bitCast(u64, b) ^ (@as(u64, 1) << 63));14 const neg_b = @as(f64, @bitCast(@as(u64, @bitCast(b)) ^ (@as(u64, 1) << 63)));
15 return a + neg_b;15 return a + neg_b;
16}16}
1717
18fn __aeabi_dsub(a: f64, b: f64) callconv(.AAPCS) f64 {18fn __aeabi_dsub(a: f64, b: f64) callconv(.AAPCS) f64 {
19 const neg_b = @bitCast(f64, @bitCast(u64, b) ^ (@as(u64, 1) << 63));19 const neg_b = @as(f64, @bitCast(@as(u64, @bitCast(b)) ^ (@as(u64, 1) << 63)));
20 return a + neg_b;20 return a + neg_b;
21}21}
lib/compiler_rt/subhf3.zig+1-1
...@@ -7,6 +7,6 @@ comptime {...@@ -7,6 +7,6 @@ comptime {
7}7}
88
9fn __subhf3(a: f16, b: f16) callconv(.C) f16 {9fn __subhf3(a: f16, b: f16) callconv(.C) f16 {
10 const neg_b = @bitCast(f16, @bitCast(u16, b) ^ (@as(u16, 1) << 15));10 const neg_b = @as(f16, @bitCast(@as(u16, @bitCast(b)) ^ (@as(u16, 1) << 15)));
11 return a + neg_b;11 return a + neg_b;
12}12}
lib/compiler_rt/subsf3.zig+2-2
...@@ -11,11 +11,11 @@ comptime {...@@ -11,11 +11,11 @@ comptime {
11}11}
1212
13fn __subsf3(a: f32, b: f32) callconv(.C) f32 {13fn __subsf3(a: f32, b: f32) callconv(.C) f32 {
14 const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (@as(u32, 1) << 31));14 const neg_b = @as(f32, @bitCast(@as(u32, @bitCast(b)) ^ (@as(u32, 1) << 31)));
15 return a + neg_b;15 return a + neg_b;
16}16}
1717
18fn __aeabi_fsub(a: f32, b: f32) callconv(.AAPCS) f32 {18fn __aeabi_fsub(a: f32, b: f32) callconv(.AAPCS) f32 {
19 const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (@as(u32, 1) << 31));19 const neg_b = @as(f32, @bitCast(@as(u32, @bitCast(b)) ^ (@as(u32, 1) << 31)));
20 return a + neg_b;20 return a + neg_b;
21}21}
lib/compiler_rt/subtf3.zig+1-1
...@@ -20,6 +20,6 @@ fn _Qp_sub(c: *f128, a: *const f128, b: *const f128) callconv(.C) void {...@@ -20,6 +20,6 @@ fn _Qp_sub(c: *f128, a: *const f128, b: *const f128) callconv(.C) void {
20}20}
2121
22inline fn sub(a: f128, b: f128) f128 {22inline fn sub(a: f128, b: f128) f128 {
23 const neg_b = @bitCast(f128, @bitCast(u128, b) ^ (@as(u128, 1) << 127));23 const neg_b = @as(f128, @bitCast(@as(u128, @bitCast(b)) ^ (@as(u128, 1) << 127)));
24 return a + neg_b;24 return a + neg_b;
25}25}
lib/compiler_rt/tan.zig+5-5
...@@ -33,7 +33,7 @@ comptime {...@@ -33,7 +33,7 @@ comptime {
3333
34pub fn __tanh(x: f16) callconv(.C) f16 {34pub fn __tanh(x: f16) callconv(.C) f16 {
35 // TODO: more efficient implementation35 // TODO: more efficient implementation
36 return @floatCast(f16, tanf(x));36 return @as(f16, @floatCast(tanf(x)));
37}37}
3838
39pub fn tanf(x: f32) callconv(.C) f32 {39pub fn tanf(x: f32) callconv(.C) f32 {
...@@ -43,7 +43,7 @@ pub fn tanf(x: f32) callconv(.C) f32 {...@@ -43,7 +43,7 @@ pub fn tanf(x: f32) callconv(.C) f32 {
43 const t3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D243 const t3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2
44 const t4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D1844 const t4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18
4545
46 var ix = @bitCast(u32, x);46 var ix = @as(u32, @bitCast(x));
47 const sign = ix >> 31 != 0;47 const sign = ix >> 31 != 0;
48 ix &= 0x7fffffff;48 ix &= 0x7fffffff;
4949
...@@ -81,7 +81,7 @@ pub fn tanf(x: f32) callconv(.C) f32 {...@@ -81,7 +81,7 @@ pub fn tanf(x: f32) callconv(.C) f32 {
81}81}
8282
83pub fn tan(x: f64) callconv(.C) f64 {83pub fn tan(x: f64) callconv(.C) f64 {
84 var ix = @bitCast(u64, x) >> 32;84 var ix = @as(u64, @bitCast(x)) >> 32;
85 ix &= 0x7fffffff;85 ix &= 0x7fffffff;
8686
87 // |x| ~< pi/487 // |x| ~< pi/4
...@@ -106,12 +106,12 @@ pub fn tan(x: f64) callconv(.C) f64 {...@@ -106,12 +106,12 @@ pub fn tan(x: f64) callconv(.C) f64 {
106106
107pub fn __tanx(x: f80) callconv(.C) f80 {107pub fn __tanx(x: f80) callconv(.C) f80 {
108 // TODO: more efficient implementation108 // TODO: more efficient implementation
109 return @floatCast(f80, tanq(x));109 return @as(f80, @floatCast(tanq(x)));
110}110}
111111
112pub fn tanq(x: f128) callconv(.C) f128 {112pub fn tanq(x: f128) callconv(.C) f128 {
113 // TODO: more correct implementation113 // TODO: more correct implementation
114 return tan(@floatCast(f64, x));114 return tan(@as(f64, @floatCast(x)));
115}115}
116116
117pub fn tanl(x: c_longdouble) callconv(.C) c_longdouble {117pub fn tanl(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/trig.zig+7-7
...@@ -70,7 +70,7 @@ pub fn __cosdf(x: f64) f32 {...@@ -70,7 +70,7 @@ pub fn __cosdf(x: f64) f32 {
70 const z = x * x;70 const z = x * x;
71 const w = z * z;71 const w = z * z;
72 const r = C2 + z * C3;72 const r = C2 + z * C3;
73 return @floatCast(f32, ((1.0 + z * C0) + w * C1) + (w * z) * r);73 return @as(f32, @floatCast(((1.0 + z * C0) + w * C1) + (w * z) * r));
74}74}
7575
76/// kernel sin function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.785476/// kernel sin function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854
...@@ -131,7 +131,7 @@ pub fn __sindf(x: f64) f32 {...@@ -131,7 +131,7 @@ pub fn __sindf(x: f64) f32 {
131 const w = z * z;131 const w = z * z;
132 const r = S3 + z * S4;132 const r = S3 + z * S4;
133 const s = z * x;133 const s = z * x;
134 return @floatCast(f32, (x + s * (S1 + z * S2)) + s * w * r);134 return @as(f32, @floatCast((x + s * (S1 + z * S2)) + s * w * r));
135}135}
136136
137/// kernel tan function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854137/// kernel tan function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854
...@@ -199,7 +199,7 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 {...@@ -199,7 +199,7 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 {
199 var hx: u32 = undefined;199 var hx: u32 = undefined;
200 var sign: bool = undefined;200 var sign: bool = undefined;
201201
202 hx = @intCast(u32, @bitCast(u64, x) >> 32);202 hx = @as(u32, @intCast(@as(u64, @bitCast(x)) >> 32));
203 const big = (hx & 0x7fffffff) >= 0x3FE59428; // |x| >= 0.6744203 const big = (hx & 0x7fffffff) >= 0x3FE59428; // |x| >= 0.6744
204 if (big) {204 if (big) {
205 sign = hx >> 31 != 0;205 sign = hx >> 31 != 0;
...@@ -222,7 +222,7 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 {...@@ -222,7 +222,7 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 {
222 r = y + z * (s * (r + v) + y) + s * T[0];222 r = y + z * (s * (r + v) + y) + s * T[0];
223 w = x + r;223 w = x + r;
224 if (big) {224 if (big) {
225 s = 1 - 2 * @floatFromInt(f64, @intFromBool(odd));225 s = 1 - 2 * @as(f64, @floatFromInt(@intFromBool(odd)));
226 v = s - 2.0 * (x + (r - w * w / (w + s)));226 v = s - 2.0 * (x + (r - w * w / (w + s)));
227 return if (sign) -v else v;227 return if (sign) -v else v;
228 }228 }
...@@ -231,11 +231,11 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 {...@@ -231,11 +231,11 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 {
231 }231 }
232 // -1.0/(x+r) has up to 2ulp error, so compute it accurately232 // -1.0/(x+r) has up to 2ulp error, so compute it accurately
233 w0 = w;233 w0 = w;
234 w0 = @bitCast(f64, @bitCast(u64, w0) & 0xffffffff00000000);234 w0 = @as(f64, @bitCast(@as(u64, @bitCast(w0)) & 0xffffffff00000000));
235 v = r - (w0 - x); // w0+v = r+x235 v = r - (w0 - x); // w0+v = r+x
236 a = -1.0 / w;236 a = -1.0 / w;
237 a0 = a;237 a0 = a;
238 a0 = @bitCast(f64, @bitCast(u64, a0) & 0xffffffff00000000);238 a0 = @as(f64, @bitCast(@as(u64, @bitCast(a0)) & 0xffffffff00000000));
239 return a0 + a * (1.0 + a0 * w0 + a0 * v);239 return a0 + a * (1.0 + a0 * w0 + a0 * v);
240}240}
241241
...@@ -269,5 +269,5 @@ pub fn __tandf(x: f64, odd: bool) f32 {...@@ -269,5 +269,5 @@ pub fn __tandf(x: f64, odd: bool) f32 {
269 const s = z * x;269 const s = z * x;
270 const u = T[0] + z * T[1];270 const u = T[0] + z * T[1];
271 const r0 = (x + s * u) + (s * w) * (t + w * r);271 const r0 = (x + s * u) + (s * w) * (t + w * r);
272 return @floatCast(f32, if (odd) -1.0 / r0 else r0);272 return @as(f32, @floatCast(if (odd) -1.0 / r0 else r0));
273}273}
lib/compiler_rt/trunc.zig+14-14
...@@ -27,12 +27,12 @@ comptime {...@@ -27,12 +27,12 @@ comptime {
2727
28pub fn __trunch(x: f16) callconv(.C) f16 {28pub fn __trunch(x: f16) callconv(.C) f16 {
29 // TODO: more efficient implementation29 // TODO: more efficient implementation
30 return @floatCast(f16, truncf(x));30 return @as(f16, @floatCast(truncf(x)));
31}31}
3232
33pub fn truncf(x: f32) callconv(.C) f32 {33pub fn truncf(x: f32) callconv(.C) f32 {
34 const u = @bitCast(u32, x);34 const u = @as(u32, @bitCast(x));
35 var e = @intCast(i32, ((u >> 23) & 0xFF)) - 0x7F + 9;35 var e = @as(i32, @intCast(((u >> 23) & 0xFF))) - 0x7F + 9;
36 var m: u32 = undefined;36 var m: u32 = undefined;
3737
38 if (e >= 23 + 9) {38 if (e >= 23 + 9) {
...@@ -42,18 +42,18 @@ pub fn truncf(x: f32) callconv(.C) f32 {...@@ -42,18 +42,18 @@ pub fn truncf(x: f32) callconv(.C) f32 {
42 e = 1;42 e = 1;
43 }43 }
4444
45 m = @as(u32, math.maxInt(u32)) >> @intCast(u5, e);45 m = @as(u32, math.maxInt(u32)) >> @as(u5, @intCast(e));
46 if (u & m == 0) {46 if (u & m == 0) {
47 return x;47 return x;
48 } else {48 } else {
49 math.doNotOptimizeAway(x + 0x1p120);49 math.doNotOptimizeAway(x + 0x1p120);
50 return @bitCast(f32, u & ~m);50 return @as(f32, @bitCast(u & ~m));
51 }51 }
52}52}
5353
54pub fn trunc(x: f64) callconv(.C) f64 {54pub fn trunc(x: f64) callconv(.C) f64 {
55 const u = @bitCast(u64, x);55 const u = @as(u64, @bitCast(x));
56 var e = @intCast(i32, ((u >> 52) & 0x7FF)) - 0x3FF + 12;56 var e = @as(i32, @intCast(((u >> 52) & 0x7FF))) - 0x3FF + 12;
57 var m: u64 = undefined;57 var m: u64 = undefined;
5858
59 if (e >= 52 + 12) {59 if (e >= 52 + 12) {
...@@ -63,23 +63,23 @@ pub fn trunc(x: f64) callconv(.C) f64 {...@@ -63,23 +63,23 @@ pub fn trunc(x: f64) callconv(.C) f64 {
63 e = 1;63 e = 1;
64 }64 }
6565
66 m = @as(u64, math.maxInt(u64)) >> @intCast(u6, e);66 m = @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(e));
67 if (u & m == 0) {67 if (u & m == 0) {
68 return x;68 return x;
69 } else {69 } else {
70 math.doNotOptimizeAway(x + 0x1p120);70 math.doNotOptimizeAway(x + 0x1p120);
71 return @bitCast(f64, u & ~m);71 return @as(f64, @bitCast(u & ~m));
72 }72 }
73}73}
7474
75pub fn __truncx(x: f80) callconv(.C) f80 {75pub fn __truncx(x: f80) callconv(.C) f80 {
76 // TODO: more efficient implementation76 // TODO: more efficient implementation
77 return @floatCast(f80, truncq(x));77 return @as(f80, @floatCast(truncq(x)));
78}78}
7979
80pub fn truncq(x: f128) callconv(.C) f128 {80pub fn truncq(x: f128) callconv(.C) f128 {
81 const u = @bitCast(u128, x);81 const u = @as(u128, @bitCast(x));
82 var e = @intCast(i32, ((u >> 112) & 0x7FFF)) - 0x3FFF + 16;82 var e = @as(i32, @intCast(((u >> 112) & 0x7FFF))) - 0x3FFF + 16;
83 var m: u128 = undefined;83 var m: u128 = undefined;
8484
85 if (e >= 112 + 16) {85 if (e >= 112 + 16) {
...@@ -89,12 +89,12 @@ pub fn truncq(x: f128) callconv(.C) f128 {...@@ -89,12 +89,12 @@ pub fn truncq(x: f128) callconv(.C) f128 {
89 e = 1;89 e = 1;
90 }90 }
9191
92 m = @as(u128, math.maxInt(u128)) >> @intCast(u7, e);92 m = @as(u128, math.maxInt(u128)) >> @as(u7, @intCast(e));
93 if (u & m == 0) {93 if (u & m == 0) {
94 return x;94 return x;
95 } else {95 } else {
96 math.doNotOptimizeAway(x + 0x1p120);96 math.doNotOptimizeAway(x + 0x1p120);
97 return @bitCast(f128, u & ~m);97 return @as(f128, @bitCast(u & ~m));
98 }98 }
99}99}
100100
lib/compiler_rt/truncdfhf2.zig+2-2
...@@ -12,9 +12,9 @@ comptime {...@@ -12,9 +12,9 @@ comptime {
12}12}
1313
14pub fn __truncdfhf2(a: f64) callconv(.C) common.F16T(f64) {14pub fn __truncdfhf2(a: f64) callconv(.C) common.F16T(f64) {
15 return @bitCast(common.F16T(f64), truncf(f16, f64, a));15 return @as(common.F16T(f64), @bitCast(truncf(f16, f64, a)));
16}16}
1717
18fn __aeabi_d2h(a: f64) callconv(.AAPCS) u16 {18fn __aeabi_d2h(a: f64) callconv(.AAPCS) u16 {
19 return @bitCast(common.F16T(f64), truncf(f16, f64, a));19 return @as(common.F16T(f64), @bitCast(truncf(f16, f64, a)));
20}20}
lib/compiler_rt/truncf.zig+20-20
...@@ -38,7 +38,7 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t...@@ -38,7 +38,7 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
38 const dstNaNCode = dstQNaN - 1;38 const dstNaNCode = dstQNaN - 1;
3939
40 // Break a into a sign and representation of the absolute value40 // Break a into a sign and representation of the absolute value
41 const aRep: src_rep_t = @bitCast(src_rep_t, a);41 const aRep: src_rep_t = @as(src_rep_t, @bitCast(a));
42 const aAbs: src_rep_t = aRep & srcAbsMask;42 const aAbs: src_rep_t = aRep & srcAbsMask;
43 const sign: src_rep_t = aRep & srcSignMask;43 const sign: src_rep_t = aRep & srcSignMask;
44 var absResult: dst_rep_t = undefined;44 var absResult: dst_rep_t = undefined;
...@@ -47,7 +47,7 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t...@@ -47,7 +47,7 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
47 // The exponent of a is within the range of normal numbers in the47 // The exponent of a is within the range of normal numbers in the
48 // destination format. We can convert by simply right-shifting with48 // destination format. We can convert by simply right-shifting with
49 // rounding and adjusting the exponent.49 // rounding and adjusting the exponent.
50 absResult = @truncate(dst_rep_t, aAbs >> (srcSigBits - dstSigBits));50 absResult = @as(dst_rep_t, @truncate(aAbs >> (srcSigBits - dstSigBits)));
51 absResult -%= @as(dst_rep_t, srcExpBias - dstExpBias) << dstSigBits;51 absResult -%= @as(dst_rep_t, srcExpBias - dstExpBias) << dstSigBits;
5252
53 const roundBits: src_rep_t = aAbs & roundMask;53 const roundBits: src_rep_t = aAbs & roundMask;
...@@ -62,18 +62,18 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t...@@ -62,18 +62,18 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
62 // a is NaN.62 // a is NaN.
63 // Conjure the result by beginning with infinity, setting the qNaN63 // Conjure the result by beginning with infinity, setting the qNaN
64 // bit and inserting the (truncated) trailing NaN field.64 // bit and inserting the (truncated) trailing NaN field.
65 absResult = @intCast(dst_rep_t, dstInfExp) << dstSigBits;65 absResult = @as(dst_rep_t, @intCast(dstInfExp)) << dstSigBits;
66 absResult |= dstQNaN;66 absResult |= dstQNaN;
67 absResult |= @intCast(dst_rep_t, ((aAbs & srcNaNCode) >> (srcSigBits - dstSigBits)) & dstNaNCode);67 absResult |= @as(dst_rep_t, @intCast(((aAbs & srcNaNCode) >> (srcSigBits - dstSigBits)) & dstNaNCode));
68 } else if (aAbs >= overflow) {68 } else if (aAbs >= overflow) {
69 // a overflows to infinity.69 // a overflows to infinity.
70 absResult = @intCast(dst_rep_t, dstInfExp) << dstSigBits;70 absResult = @as(dst_rep_t, @intCast(dstInfExp)) << dstSigBits;
71 } else {71 } else {
72 // a underflows on conversion to the destination type or is an exact72 // a underflows on conversion to the destination type or is an exact
73 // zero. The result may be a denormal or zero. Extract the exponent73 // zero. The result may be a denormal or zero. Extract the exponent
74 // to get the shift amount for the denormalization.74 // to get the shift amount for the denormalization.
75 const aExp = @intCast(u32, aAbs >> srcSigBits);75 const aExp = @as(u32, @intCast(aAbs >> srcSigBits));
76 const shift = @intCast(u32, srcExpBias - dstExpBias - aExp + 1);76 const shift = @as(u32, @intCast(srcExpBias - dstExpBias - aExp + 1));
7777
78 const significand: src_rep_t = (aRep & srcSignificandMask) | srcMinNormal;78 const significand: src_rep_t = (aRep & srcSignificandMask) | srcMinNormal;
7979
...@@ -81,9 +81,9 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t...@@ -81,9 +81,9 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
81 if (shift > srcSigBits) {81 if (shift > srcSigBits) {
82 absResult = 0;82 absResult = 0;
83 } else {83 } else {
84 const sticky: src_rep_t = @intFromBool(significand << @intCast(SrcShift, srcBits - shift) != 0);84 const sticky: src_rep_t = @intFromBool(significand << @as(SrcShift, @intCast(srcBits - shift)) != 0);
85 const denormalizedSignificand: src_rep_t = significand >> @intCast(SrcShift, shift) | sticky;85 const denormalizedSignificand: src_rep_t = significand >> @as(SrcShift, @intCast(shift)) | sticky;
86 absResult = @intCast(dst_rep_t, denormalizedSignificand >> (srcSigBits - dstSigBits));86 absResult = @as(dst_rep_t, @intCast(denormalizedSignificand >> (srcSigBits - dstSigBits)));
87 const roundBits: src_rep_t = denormalizedSignificand & roundMask;87 const roundBits: src_rep_t = denormalizedSignificand & roundMask;
88 if (roundBits > halfway) {88 if (roundBits > halfway) {
89 // Round to nearest89 // Round to nearest
...@@ -96,8 +96,8 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t...@@ -96,8 +96,8 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
96 }96 }
9797
98 const result: dst_rep_t align(@alignOf(dst_t)) = absResult |98 const result: dst_rep_t align(@alignOf(dst_t)) = absResult |
99 @truncate(dst_rep_t, sign >> @intCast(SrcShift, srcBits - dstBits));99 @as(dst_rep_t, @truncate(sign >> @as(SrcShift, @intCast(srcBits - dstBits))));
100 return @bitCast(dst_t, result);100 return @as(dst_t, @bitCast(result));
101}101}
102102
103pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {103pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
...@@ -133,7 +133,7 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {...@@ -133,7 +133,7 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
133 // destination format. We can convert by simply right-shifting with133 // destination format. We can convert by simply right-shifting with
134 // rounding and adjusting the exponent.134 // rounding and adjusting the exponent.
135 abs_result = @as(dst_rep_t, a_rep.exp) << dst_sig_bits;135 abs_result = @as(dst_rep_t, a_rep.exp) << dst_sig_bits;
136 abs_result |= @truncate(dst_rep_t, a_rep.fraction >> (src_sig_bits - dst_sig_bits));136 abs_result |= @as(dst_rep_t, @truncate(a_rep.fraction >> (src_sig_bits - dst_sig_bits)));
137 abs_result -%= @as(dst_rep_t, src_exp_bias - dst_exp_bias) << dst_sig_bits;137 abs_result -%= @as(dst_rep_t, src_exp_bias - dst_exp_bias) << dst_sig_bits;
138138
139 const round_bits = a_rep.fraction & round_mask;139 const round_bits = a_rep.fraction & round_mask;
...@@ -148,12 +148,12 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {...@@ -148,12 +148,12 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
148 // a is NaN.148 // a is NaN.
149 // Conjure the result by beginning with infinity, setting the qNaN149 // Conjure the result by beginning with infinity, setting the qNaN
150 // bit and inserting the (truncated) trailing NaN field.150 // bit and inserting the (truncated) trailing NaN field.
151 abs_result = @intCast(dst_rep_t, dst_inf_exp) << dst_sig_bits;151 abs_result = @as(dst_rep_t, @intCast(dst_inf_exp)) << dst_sig_bits;
152 abs_result |= dst_qnan;152 abs_result |= dst_qnan;
153 abs_result |= @intCast(dst_rep_t, (a_rep.fraction >> (src_sig_bits - dst_sig_bits)) & dst_nan_mask);153 abs_result |= @as(dst_rep_t, @intCast((a_rep.fraction >> (src_sig_bits - dst_sig_bits)) & dst_nan_mask));
154 } else if (a_rep.exp >= overflow) {154 } else if (a_rep.exp >= overflow) {
155 // a overflows to infinity.155 // a overflows to infinity.
156 abs_result = @intCast(dst_rep_t, dst_inf_exp) << dst_sig_bits;156 abs_result = @as(dst_rep_t, @intCast(dst_inf_exp)) << dst_sig_bits;
157 } else {157 } else {
158 // a underflows on conversion to the destination type or is an exact158 // a underflows on conversion to the destination type or is an exact
159 // zero. The result may be a denormal or zero. Extract the exponent159 // zero. The result may be a denormal or zero. Extract the exponent
...@@ -164,9 +164,9 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {...@@ -164,9 +164,9 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
164 if (shift > src_sig_bits) {164 if (shift > src_sig_bits) {
165 abs_result = 0;165 abs_result = 0;
166 } else {166 } else {
167 const sticky = @intFromBool(a_rep.fraction << @intCast(u6, shift) != 0);167 const sticky = @intFromBool(a_rep.fraction << @as(u6, @intCast(shift)) != 0);
168 const denormalized_significand = a_rep.fraction >> @intCast(u6, shift) | sticky;168 const denormalized_significand = a_rep.fraction >> @as(u6, @intCast(shift)) | sticky;
169 abs_result = @intCast(dst_rep_t, denormalized_significand >> (src_sig_bits - dst_sig_bits));169 abs_result = @as(dst_rep_t, @intCast(denormalized_significand >> (src_sig_bits - dst_sig_bits)));
170 const round_bits = denormalized_significand & round_mask;170 const round_bits = denormalized_significand & round_mask;
171 if (round_bits > halfway) {171 if (round_bits > halfway) {
172 // Round to nearest172 // Round to nearest
...@@ -179,7 +179,7 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {...@@ -179,7 +179,7 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
179 }179 }
180180
181 const result align(@alignOf(dst_t)) = abs_result | @as(dst_rep_t, sign) << dst_bits - 16;181 const result align(@alignOf(dst_t)) = abs_result | @as(dst_rep_t, sign) << dst_bits - 16;
182 return @bitCast(dst_t, result);182 return @as(dst_t, @bitCast(result));
183}183}
184184
185test {185test {
lib/compiler_rt/truncf_test.zig+21-21
...@@ -10,7 +10,7 @@ const __trunctfdf2 = @import("trunctfdf2.zig").__trunctfdf2;...@@ -10,7 +10,7 @@ const __trunctfdf2 = @import("trunctfdf2.zig").__trunctfdf2;
10const __trunctfxf2 = @import("trunctfxf2.zig").__trunctfxf2;10const __trunctfxf2 = @import("trunctfxf2.zig").__trunctfxf2;
1111
12fn test__truncsfhf2(a: u32, expected: u16) !void {12fn test__truncsfhf2(a: u32, expected: u16) !void {
13 const actual = @bitCast(u16, __truncsfhf2(@bitCast(f32, a)));13 const actual = @as(u16, @bitCast(__truncsfhf2(@as(f32, @bitCast(a)))));
1414
15 if (actual == expected) {15 if (actual == expected) {
16 return;16 return;
...@@ -73,7 +73,7 @@ test "truncsfhf2" {...@@ -73,7 +73,7 @@ test "truncsfhf2" {
73}73}
7474
75fn test__truncdfhf2(a: f64, expected: u16) void {75fn test__truncdfhf2(a: f64, expected: u16) void {
76 const rep = @bitCast(u16, __truncdfhf2(a));76 const rep = @as(u16, @bitCast(__truncdfhf2(a)));
7777
78 if (rep == expected) {78 if (rep == expected) {
79 return;79 return;
...@@ -89,7 +89,7 @@ fn test__truncdfhf2(a: f64, expected: u16) void {...@@ -89,7 +89,7 @@ fn test__truncdfhf2(a: f64, expected: u16) void {
89}89}
9090
91fn test__truncdfhf2_raw(a: u64, expected: u16) void {91fn test__truncdfhf2_raw(a: u64, expected: u16) void {
92 const actual = @bitCast(u16, __truncdfhf2(@bitCast(f64, a)));92 const actual = @as(u16, @bitCast(__truncdfhf2(@as(f64, @bitCast(a)))));
9393
94 if (actual == expected) {94 if (actual == expected) {
95 return;95 return;
...@@ -141,7 +141,7 @@ test "truncdfhf2" {...@@ -141,7 +141,7 @@ test "truncdfhf2" {
141fn test__trunctfsf2(a: f128, expected: u32) void {141fn test__trunctfsf2(a: f128, expected: u32) void {
142 const x = __trunctfsf2(a);142 const x = __trunctfsf2(a);
143143
144 const rep = @bitCast(u32, x);144 const rep = @as(u32, @bitCast(x));
145 if (rep == expected) {145 if (rep == expected) {
146 return;146 return;
147 }147 }
...@@ -157,11 +157,11 @@ fn test__trunctfsf2(a: f128, expected: u32) void {...@@ -157,11 +157,11 @@ fn test__trunctfsf2(a: f128, expected: u32) void {
157157
158test "trunctfsf2" {158test "trunctfsf2" {
159 // qnan159 // qnan
160 test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7fc00000);160 test__trunctfsf2(@as(f128, @bitCast(@as(u128, 0x7fff800000000000 << 64))), 0x7fc00000);
161 // nan161 // nan
162 test__trunctfsf2(@bitCast(f128, @as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7fc08000);162 test__trunctfsf2(@as(f128, @bitCast(@as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64))), 0x7fc08000);
163 // inf163 // inf
164 test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff000000000000 << 64)), 0x7f800000);164 test__trunctfsf2(@as(f128, @bitCast(@as(u128, 0x7fff000000000000 << 64))), 0x7f800000);
165 // zero165 // zero
166 test__trunctfsf2(0.0, 0x0);166 test__trunctfsf2(0.0, 0x0);
167167
...@@ -174,7 +174,7 @@ test "trunctfsf2" {...@@ -174,7 +174,7 @@ test "trunctfsf2" {
174fn test__trunctfdf2(a: f128, expected: u64) void {174fn test__trunctfdf2(a: f128, expected: u64) void {
175 const x = __trunctfdf2(a);175 const x = __trunctfdf2(a);
176176
177 const rep = @bitCast(u64, x);177 const rep = @as(u64, @bitCast(x));
178 if (rep == expected) {178 if (rep == expected) {
179 return;179 return;
180 }180 }
...@@ -190,11 +190,11 @@ fn test__trunctfdf2(a: f128, expected: u64) void {...@@ -190,11 +190,11 @@ fn test__trunctfdf2(a: f128, expected: u64) void {
190190
191test "trunctfdf2" {191test "trunctfdf2" {
192 // qnan192 // qnan
193 test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7ff8000000000000);193 test__trunctfdf2(@as(f128, @bitCast(@as(u128, 0x7fff800000000000 << 64))), 0x7ff8000000000000);
194 // nan194 // nan
195 test__trunctfdf2(@bitCast(f128, @as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7ff8100000000000);195 test__trunctfdf2(@as(f128, @bitCast(@as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64))), 0x7ff8100000000000);
196 // inf196 // inf
197 test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff000000000000 << 64)), 0x7ff0000000000000);197 test__trunctfdf2(@as(f128, @bitCast(@as(u128, 0x7fff000000000000 << 64))), 0x7ff0000000000000);
198 // zero198 // zero
199 test__trunctfdf2(0.0, 0x0);199 test__trunctfdf2(0.0, 0x0);
200200
...@@ -207,7 +207,7 @@ test "trunctfdf2" {...@@ -207,7 +207,7 @@ test "trunctfdf2" {
207fn test__truncdfsf2(a: f64, expected: u32) void {207fn test__truncdfsf2(a: f64, expected: u32) void {
208 const x = __truncdfsf2(a);208 const x = __truncdfsf2(a);
209209
210 const rep = @bitCast(u32, x);210 const rep = @as(u32, @bitCast(x));
211 if (rep == expected) {211 if (rep == expected) {
212 return;212 return;
213 }213 }
...@@ -225,11 +225,11 @@ fn test__truncdfsf2(a: f64, expected: u32) void {...@@ -225,11 +225,11 @@ fn test__truncdfsf2(a: f64, expected: u32) void {
225225
226test "truncdfsf2" {226test "truncdfsf2" {
227 // nan & qnan227 // nan & qnan
228 test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff8000000000000)), 0x7fc00000);228 test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0x7ff8000000000000))), 0x7fc00000);
229 test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff0000000000001)), 0x7fc00000);229 test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0x7ff0000000000001))), 0x7fc00000);
230 // inf230 // inf
231 test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff0000000000000)), 0x7f800000);231 test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0x7ff0000000000000))), 0x7f800000);
232 test__truncdfsf2(@bitCast(f64, @as(u64, 0xfff0000000000000)), 0xff800000);232 test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0xfff0000000000000))), 0xff800000);
233233
234 test__truncdfsf2(0.0, 0x0);234 test__truncdfsf2(0.0, 0x0);
235 test__truncdfsf2(1.0, 0x3f800000);235 test__truncdfsf2(1.0, 0x3f800000);
...@@ -242,7 +242,7 @@ test "truncdfsf2" {...@@ -242,7 +242,7 @@ test "truncdfsf2" {
242fn test__trunctfhf2(a: f128, expected: u16) void {242fn test__trunctfhf2(a: f128, expected: u16) void {
243 const x = __trunctfhf2(a);243 const x = __trunctfhf2(a);
244244
245 const rep = @bitCast(u16, x);245 const rep = @as(u16, @bitCast(x));
246 if (rep == expected) {246 if (rep == expected) {
247 return;247 return;
248 }248 }
...@@ -254,12 +254,12 @@ fn test__trunctfhf2(a: f128, expected: u16) void {...@@ -254,12 +254,12 @@ fn test__trunctfhf2(a: f128, expected: u16) void {
254254
255test "trunctfhf2" {255test "trunctfhf2" {
256 // qNaN256 // qNaN
257 test__trunctfhf2(@bitCast(f128, @as(u128, 0x7fff8000000000000000000000000000)), 0x7e00);257 test__trunctfhf2(@as(f128, @bitCast(@as(u128, 0x7fff8000000000000000000000000000))), 0x7e00);
258 // NaN258 // NaN
259 test__trunctfhf2(@bitCast(f128, @as(u128, 0x7fff0000000000000000000000000001)), 0x7e00);259 test__trunctfhf2(@as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000001))), 0x7e00);
260 // inf260 // inf
261 test__trunctfhf2(@bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000)), 0x7c00);261 test__trunctfhf2(@as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000000))), 0x7c00);
262 test__trunctfhf2(-@bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000)), 0xfc00);262 test__trunctfhf2(-@as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000000))), 0xfc00);
263 // zero263 // zero
264 test__trunctfhf2(0.0, 0x0);264 test__trunctfhf2(0.0, 0x0);
265 test__trunctfhf2(-0.0, 0x8000);265 test__trunctfhf2(-0.0, 0x8000);
lib/compiler_rt/truncsfhf2.zig+3-3
...@@ -13,13 +13,13 @@ comptime {...@@ -13,13 +13,13 @@ comptime {
13}13}
1414
15pub fn __truncsfhf2(a: f32) callconv(.C) common.F16T(f32) {15pub fn __truncsfhf2(a: f32) callconv(.C) common.F16T(f32) {
16 return @bitCast(common.F16T(f32), truncf(f16, f32, a));16 return @as(common.F16T(f32), @bitCast(truncf(f16, f32, a)));
17}17}
1818
19fn __gnu_f2h_ieee(a: f32) callconv(.C) common.F16T(f32) {19fn __gnu_f2h_ieee(a: f32) callconv(.C) common.F16T(f32) {
20 return @bitCast(common.F16T(f32), truncf(f16, f32, a));20 return @as(common.F16T(f32), @bitCast(truncf(f16, f32, a)));
21}21}
2222
23fn __aeabi_f2h(a: f32) callconv(.AAPCS) u16 {23fn __aeabi_f2h(a: f32) callconv(.AAPCS) u16 {
24 return @bitCast(common.F16T(f32), truncf(f16, f32, a));24 return @as(common.F16T(f32), @bitCast(truncf(f16, f32, a)));
25}25}
lib/compiler_rt/trunctfhf2.zig+1-1
...@@ -8,5 +8,5 @@ comptime {...@@ -8,5 +8,5 @@ comptime {
8}8}
99
10pub fn __trunctfhf2(a: f128) callconv(.C) common.F16T(f128) {10pub fn __trunctfhf2(a: f128) callconv(.C) common.F16T(f128) {
11 return @bitCast(common.F16T(f128), truncf(f16, f128, a));11 return @as(common.F16T(f128), @bitCast(truncf(f16, f128, a)));
12}12}
lib/compiler_rt/trunctfxf2.zig+4-4
...@@ -25,7 +25,7 @@ pub fn __trunctfxf2(a: f128) callconv(.C) f80 {...@@ -25,7 +25,7 @@ pub fn __trunctfxf2(a: f128) callconv(.C) f80 {
25 const halfway = 1 << (src_sig_bits - dst_sig_bits - 1);25 const halfway = 1 << (src_sig_bits - dst_sig_bits - 1);
2626
27 // Break a into a sign and representation of the absolute value27 // Break a into a sign and representation of the absolute value
28 const a_rep = @bitCast(u128, a);28 const a_rep = @as(u128, @bitCast(a));
29 const a_abs = a_rep & src_abs_mask;29 const a_abs = a_rep & src_abs_mask;
30 const sign: u16 = if (a_rep & src_sign_mask != 0) 0x8000 else 0;30 const sign: u16 = if (a_rep & src_sign_mask != 0) 0x8000 else 0;
31 const integer_bit = 1 << 63;31 const integer_bit = 1 << 63;
...@@ -38,13 +38,13 @@ pub fn __trunctfxf2(a: f128) callconv(.C) f80 {...@@ -38,13 +38,13 @@ pub fn __trunctfxf2(a: f128) callconv(.C) f80 {
38 // bit and inserting the (truncated) trailing NaN field.38 // bit and inserting the (truncated) trailing NaN field.
39 res.exp = 0x7fff;39 res.exp = 0x7fff;
40 res.fraction = 0x8000000000000000;40 res.fraction = 0x8000000000000000;
41 res.fraction |= @truncate(u64, a_abs >> (src_sig_bits - dst_sig_bits));41 res.fraction |= @as(u64, @truncate(a_abs >> (src_sig_bits - dst_sig_bits)));
42 } else {42 } else {
43 // The exponent of a is within the range of normal numbers in the43 // The exponent of a is within the range of normal numbers in the
44 // destination format. We can convert by simply right-shifting with44 // destination format. We can convert by simply right-shifting with
45 // rounding, adding the explicit integer bit, and adjusting the exponent45 // rounding, adding the explicit integer bit, and adjusting the exponent
46 res.fraction = @truncate(u64, a_abs >> (src_sig_bits - dst_sig_bits)) | integer_bit;46 res.fraction = @as(u64, @truncate(a_abs >> (src_sig_bits - dst_sig_bits))) | integer_bit;
47 res.exp = @truncate(u16, a_abs >> src_sig_bits);47 res.exp = @as(u16, @truncate(a_abs >> src_sig_bits));
4848
49 const round_bits = a_abs & round_mask;49 const round_bits = a_abs & round_mask;
50 if (round_bits > halfway) {50 if (round_bits > halfway) {
lib/compiler_rt/truncxfhf2.zig+1-1
...@@ -8,5 +8,5 @@ comptime {...@@ -8,5 +8,5 @@ comptime {
8}8}
99
10fn __truncxfhf2(a: f80) callconv(.C) common.F16T(f80) {10fn __truncxfhf2(a: f80) callconv(.C) common.F16T(f80) {
11 return @bitCast(common.F16T(f80), trunc_f80(f16, a));11 return @as(common.F16T(f80), @bitCast(trunc_f80(f16, a)));
12}12}
lib/compiler_rt/udivmod.zig+14-14
...@@ -21,11 +21,11 @@ fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T {...@@ -21,11 +21,11 @@ fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T {
21 var un64: T = undefined;21 var un64: T = undefined;
22 var un10: T = undefined;22 var un10: T = undefined;
2323
24 const s = @intCast(Log2Int(T), @clz(v));24 const s = @as(Log2Int(T), @intCast(@clz(v)));
25 if (s > 0) {25 if (s > 0) {
26 // Normalize divisor26 // Normalize divisor
27 v <<= s;27 v <<= s;
28 un64 = (_u1 << s) | (_u0 >> @intCast(Log2Int(T), (@bitSizeOf(T) - @intCast(T, s))));28 un64 = (_u1 << s) | (_u0 >> @as(Log2Int(T), @intCast((@bitSizeOf(T) - @as(T, @intCast(s))))));
29 un10 = _u0 << s;29 un10 = _u0 << s;
30 } else {30 } else {
31 // Avoid undefined behavior of (u0 >> @bitSizeOf(T))31 // Avoid undefined behavior of (u0 >> @bitSizeOf(T))
...@@ -101,8 +101,8 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {...@@ -101,8 +101,8 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
101 return 0;101 return 0;
102 }102 }
103103
104 var a = @bitCast([2]HalfT, a_);104 var a = @as([2]HalfT, @bitCast(a_));
105 var b = @bitCast([2]HalfT, b_);105 var b = @as([2]HalfT, @bitCast(b_));
106 var q: [2]HalfT = undefined;106 var q: [2]HalfT = undefined;
107 var r: [2]HalfT = undefined;107 var r: [2]HalfT = undefined;
108108
...@@ -119,16 +119,16 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {...@@ -119,16 +119,16 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
119 q[lo] = divwide(HalfT, a[hi] % b[lo], a[lo], b[lo], &r[lo]);119 q[lo] = divwide(HalfT, a[hi] % b[lo], a[lo], b[lo], &r[lo]);
120 }120 }
121 if (maybe_rem) |rem| {121 if (maybe_rem) |rem| {
122 rem.* = @bitCast(T, r);122 rem.* = @as(T, @bitCast(r));
123 }123 }
124 return @bitCast(T, q);124 return @as(T, @bitCast(q));
125 }125 }
126126
127 // 0 <= shift <= 63127 // 0 <= shift <= 63
128 var shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]);128 var shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]);
129 var af = @bitCast(T, a);129 var af = @as(T, @bitCast(a));
130 var bf = @bitCast(T, b) << shift;130 var bf = @as(T, @bitCast(b)) << shift;
131 q = @bitCast([2]HalfT, @as(T, 0));131 q = @as([2]HalfT, @bitCast(@as(T, 0)));
132132
133 for (0..shift + 1) |_| {133 for (0..shift + 1) |_| {
134 q[lo] <<= 1;134 q[lo] <<= 1;
...@@ -137,13 +137,13 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {...@@ -137,13 +137,13 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
137 // af -= bf;137 // af -= bf;
138 // q[lo] |= 1;138 // q[lo] |= 1;
139 // }139 // }
140 const s = @bitCast(SignedT, bf -% af -% 1) >> (@bitSizeOf(T) - 1);140 const s = @as(SignedT, @bitCast(bf -% af -% 1)) >> (@bitSizeOf(T) - 1);
141 q[lo] |= @intCast(HalfT, s & 1);141 q[lo] |= @as(HalfT, @intCast(s & 1));
142 af -= bf & @bitCast(T, s);142 af -= bf & @as(T, @bitCast(s));
143 bf >>= 1;143 bf >>= 1;
144 }144 }
145 if (maybe_rem) |rem| {145 if (maybe_rem) |rem| {
146 rem.* = @bitCast(T, af);146 rem.* = @as(T, @bitCast(af));
147 }147 }
148 return @bitCast(T, q);148 return @as(T, @bitCast(q));
149}149}
lib/compiler_rt/udivmodei4.zig+7-7
...@@ -83,23 +83,23 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {...@@ -83,23 +83,23 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
83 i = 0;83 i = 0;
84 while (i <= n) : (i += 1) {84 while (i <= n) : (i += 1) {
85 const p = qhat * limb(&vn, i);85 const p = qhat * limb(&vn, i);
86 const t = limb(&un, i + j) - carry - @truncate(u32, p);86 const t = limb(&un, i + j) - carry - @as(u32, @truncate(p));
87 limb_set(&un, i + j, @truncate(u32, @bitCast(u64, t)));87 limb_set(&un, i + j, @as(u32, @truncate(@as(u64, @bitCast(t)))));
88 carry = @intCast(i64, p >> 32) - @intCast(i64, t >> 32);88 carry = @as(i64, @intCast(p >> 32)) - @as(i64, @intCast(t >> 32));
89 }89 }
90 const t = limb(&un, j + n + 1) -% carry;90 const t = limb(&un, j + n + 1) -% carry;
91 limb_set(&un, j + n + 1, @truncate(u32, @bitCast(u64, t)));91 limb_set(&un, j + n + 1, @as(u32, @truncate(@as(u64, @bitCast(t)))));
92 if (q) |q_| limb_set(q_, j, @truncate(u32, qhat));92 if (q) |q_| limb_set(q_, j, @as(u32, @truncate(qhat)));
93 if (t < 0) {93 if (t < 0) {
94 if (q) |q_| limb_set(q_, j, limb(q_, j) - 1);94 if (q) |q_| limb_set(q_, j, limb(q_, j) - 1);
95 var carry2: u64 = 0;95 var carry2: u64 = 0;
96 i = 0;96 i = 0;
97 while (i <= n) : (i += 1) {97 while (i <= n) : (i += 1) {
98 const t2 = @as(u64, limb(&un, i + j)) + @as(u64, limb(&vn, i)) + carry2;98 const t2 = @as(u64, limb(&un, i + j)) + @as(u64, limb(&vn, i)) + carry2;
99 limb_set(&un, i + j, @truncate(u32, t2));99 limb_set(&un, i + j, @as(u32, @truncate(t2)));
100 carry2 = t2 >> 32;100 carry2 = t2 >> 32;
101 }101 }
102 limb_set(&un, j + n + 1, @truncate(u32, limb(&un, j + n + 1) + carry2));102 limb_set(&un, j + n + 1, @as(u32, @truncate(limb(&un, j + n + 1) + carry2)));
103 }103 }
104 if (j == 0) break;104 if (j == 0) break;
105 }105 }
lib/compiler_rt/udivmodti4.zig+1-1
...@@ -20,7 +20,7 @@ pub fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) callconv(.C) u128 {...@@ -20,7 +20,7 @@ pub fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) callconv(.C) u128 {
20const v2u64 = @Vector(2, u64);20const v2u64 = @Vector(2, u64);
2121
22fn __udivmodti4_windows_x86_64(a: v2u64, b: v2u64, maybe_rem: ?*u128) callconv(.C) v2u64 {22fn __udivmodti4_windows_x86_64(a: v2u64, b: v2u64, maybe_rem: ?*u128) callconv(.C) v2u64 {
23 return @bitCast(v2u64, udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), maybe_rem));23 return @as(v2u64, @bitCast(udivmod(u128, @as(u128, @bitCast(a)), @as(u128, @bitCast(b)), maybe_rem)));
24}24}
2525
26test {26test {
lib/compiler_rt/udivti3.zig+1-1
...@@ -20,5 +20,5 @@ pub fn __udivti3(a: u128, b: u128) callconv(.C) u128 {...@@ -20,5 +20,5 @@ pub fn __udivti3(a: u128, b: u128) callconv(.C) u128 {
20const v2u64 = @Vector(2, u64);20const v2u64 = @Vector(2, u64);
2121
22fn __udivti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {22fn __udivti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {
23 return @bitCast(v2u64, udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), null));23 return @as(v2u64, @bitCast(udivmod(u128, @as(u128, @bitCast(a)), @as(u128, @bitCast(b)), null)));
24}24}
lib/compiler_rt/umodti3.zig+2-2
...@@ -23,6 +23,6 @@ const v2u64 = @Vector(2, u64);...@@ -23,6 +23,6 @@ const v2u64 = @Vector(2, u64);
2323
24fn __umodti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {24fn __umodti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {
25 var r: u128 = undefined;25 var r: u128 = undefined;
26 _ = udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), &r);26 _ = udivmod(u128, @as(u128, @bitCast(a)), @as(u128, @bitCast(b)), &r);
27 return @bitCast(v2u64, r);27 return @as(v2u64, @bitCast(r));
28}28}
lib/ssp.zig+1-1
...@@ -46,7 +46,7 @@ export var __stack_chk_guard: usize = blk: {...@@ -46,7 +46,7 @@ export var __stack_chk_guard: usize = blk: {
46 var buf = [1]u8{0} ** @sizeOf(usize);46 var buf = [1]u8{0} ** @sizeOf(usize);
47 buf[@sizeOf(usize) - 1] = 255;47 buf[@sizeOf(usize) - 1] = 255;
48 buf[@sizeOf(usize) - 2] = '\n';48 buf[@sizeOf(usize) - 2] = '\n';
49 break :blk @bitCast(usize, buf);49 break :blk @as(usize, @bitCast(buf));
50};50};
5151
52export fn __strcpy_chk(dest: [*:0]u8, src: [*:0]const u8, dest_n: usize) callconv(.C) [*:0]u8 {52export fn __strcpy_chk(dest: [*:0]u8, src: [*:0]const u8, dest_n: usize) callconv(.C) [*:0]u8 {
lib/std/Build.zig+6-6
...@@ -1111,7 +1111,7 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros...@@ -1111,7 +1111,7 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros
1111 var populated_cpu_features = whitelist_cpu.model.features;1111 var populated_cpu_features = whitelist_cpu.model.features;
1112 populated_cpu_features.populateDependencies(all_features);1112 populated_cpu_features.populateDependencies(all_features);
1113 for (all_features, 0..) |feature, i_usize| {1113 for (all_features, 0..) |feature, i_usize| {
1114 const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize);1114 const i = @as(std.Target.Cpu.Feature.Set.Index, @intCast(i_usize));
1115 const in_cpu_set = populated_cpu_features.isEnabled(i);1115 const in_cpu_set = populated_cpu_features.isEnabled(i);
1116 if (in_cpu_set) {1116 if (in_cpu_set) {
1117 log.err("{s} ", .{feature.name});1117 log.err("{s} ", .{feature.name});
...@@ -1119,7 +1119,7 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros...@@ -1119,7 +1119,7 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros
1119 }1119 }
1120 log.err(" Remove: ", .{});1120 log.err(" Remove: ", .{});
1121 for (all_features, 0..) |feature, i_usize| {1121 for (all_features, 0..) |feature, i_usize| {
1122 const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize);1122 const i = @as(std.Target.Cpu.Feature.Set.Index, @intCast(i_usize));
1123 const in_cpu_set = populated_cpu_features.isEnabled(i);1123 const in_cpu_set = populated_cpu_features.isEnabled(i);
1124 const in_actual_set = selected_cpu.features.isEnabled(i);1124 const in_actual_set = selected_cpu.features.isEnabled(i);
1125 if (in_actual_set and !in_cpu_set) {1125 if (in_actual_set and !in_cpu_set) {
...@@ -1442,13 +1442,13 @@ pub fn execAllowFail(...@@ -1442,13 +1442,13 @@ pub fn execAllowFail(
1442 switch (term) {1442 switch (term) {
1443 .Exited => |code| {1443 .Exited => |code| {
1444 if (code != 0) {1444 if (code != 0) {
1445 out_code.* = @truncate(u8, code);1445 out_code.* = @as(u8, @truncate(code));
1446 return error.ExitCodeFailure;1446 return error.ExitCodeFailure;
1447 }1447 }
1448 return stdout;1448 return stdout;
1449 },1449 },
1450 .Signal, .Stopped, .Unknown => |code| {1450 .Signal, .Stopped, .Unknown => |code| {
1451 out_code.* = @truncate(u8, code);1451 out_code.* = @as(u8, @truncate(code));
1452 return error.ProcessTerminated;1452 return error.ProcessTerminated;
1453 },1453 },
1454 }1454 }
...@@ -1815,7 +1815,7 @@ pub fn serializeCpu(allocator: Allocator, cpu: std.Target.Cpu) ![]const u8 {...@@ -1815,7 +1815,7 @@ pub fn serializeCpu(allocator: Allocator, cpu: std.Target.Cpu) ![]const u8 {
1815 try mcpu_buffer.appendSlice(cpu.model.name);1815 try mcpu_buffer.appendSlice(cpu.model.name);
18161816
1817 for (all_features, 0..) |feature, i_usize| {1817 for (all_features, 0..) |feature, i_usize| {
1818 const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize);1818 const i = @as(std.Target.Cpu.Feature.Set.Index, @intCast(i_usize));
1819 const in_cpu_set = populated_cpu_features.isEnabled(i);1819 const in_cpu_set = populated_cpu_features.isEnabled(i);
1820 const in_actual_set = cpu.features.isEnabled(i);1820 const in_actual_set = cpu.features.isEnabled(i);
1821 if (in_cpu_set and !in_actual_set) {1821 if (in_cpu_set and !in_actual_set) {
...@@ -1852,7 +1852,7 @@ pub fn hex64(x: u64) [16]u8 {...@@ -1852,7 +1852,7 @@ pub fn hex64(x: u64) [16]u8 {
1852 var result: [16]u8 = undefined;1852 var result: [16]u8 = undefined;
1853 var i: usize = 0;1853 var i: usize = 0;
1854 while (i < 8) : (i += 1) {1854 while (i < 8) : (i += 1) {
1855 const byte = @truncate(u8, x >> @intCast(u6, 8 * i));1855 const byte = @as(u8, @truncate(x >> @as(u6, @intCast(8 * i))));
1856 result[i * 2 + 0] = hex_charset[byte >> 4];1856 result[i * 2 + 0] = hex_charset[byte >> 4];
1857 result[i * 2 + 1] = hex_charset[byte & 15];1857 result[i * 2 + 1] = hex_charset[byte & 15];
1858 }1858 }
lib/std/Build/Cache.zig+2-2
...@@ -128,7 +128,7 @@ fn findPrefixResolved(cache: *const Cache, resolved_path: []u8) !PrefixedPath {...@@ -128,7 +128,7 @@ fn findPrefixResolved(cache: *const Cache, resolved_path: []u8) !PrefixedPath {
128 const sub_path = try gpa.dupe(u8, resolved_path[p.len + 1 ..]);128 const sub_path = try gpa.dupe(u8, resolved_path[p.len + 1 ..]);
129 gpa.free(resolved_path);129 gpa.free(resolved_path);
130 return PrefixedPath{130 return PrefixedPath{
131 .prefix = @intCast(u8, i),131 .prefix = @as(u8, @intCast(i)),
132 .sub_path = sub_path,132 .sub_path = sub_path,
133 };133 };
134 }134 }
...@@ -653,7 +653,7 @@ pub const Manifest = struct {...@@ -653,7 +653,7 @@ pub const Manifest = struct {
653 return error.FileTooBig;653 return error.FileTooBig;
654 }654 }
655655
656 const contents = try self.cache.gpa.alloc(u8, @intCast(usize, ch_file.stat.size));656 const contents = try self.cache.gpa.alloc(u8, @as(usize, @intCast(ch_file.stat.size)));
657 errdefer self.cache.gpa.free(contents);657 errdefer self.cache.gpa.free(contents);
658658
659 // Hash while reading from disk, to keep the contents in the cpu cache while659 // Hash while reading from disk, to keep the contents in the cpu cache while
lib/std/Build/Step.zig+2-2
...@@ -355,7 +355,7 @@ pub fn evalZigProcess(...@@ -355,7 +355,7 @@ pub fn evalZigProcess(
355 },355 },
356 .error_bundle => {356 .error_bundle => {
357 const EbHdr = std.zig.Server.Message.ErrorBundle;357 const EbHdr = std.zig.Server.Message.ErrorBundle;
358 const eb_hdr = @ptrCast(*align(1) const EbHdr, body);358 const eb_hdr = @as(*align(1) const EbHdr, @ptrCast(body));
359 const extra_bytes =359 const extra_bytes =
360 body[@sizeOf(EbHdr)..][0 .. @sizeOf(u32) * eb_hdr.extra_len];360 body[@sizeOf(EbHdr)..][0 .. @sizeOf(u32) * eb_hdr.extra_len];
361 const string_bytes =361 const string_bytes =
...@@ -377,7 +377,7 @@ pub fn evalZigProcess(...@@ -377,7 +377,7 @@ pub fn evalZigProcess(
377 },377 },
378 .emit_bin_path => {378 .emit_bin_path => {
379 const EbpHdr = std.zig.Server.Message.EmitBinPath;379 const EbpHdr = std.zig.Server.Message.EmitBinPath;
380 const ebp_hdr = @ptrCast(*align(1) const EbpHdr, body);380 const ebp_hdr = @as(*align(1) const EbpHdr, @ptrCast(body));
381 s.result_cached = ebp_hdr.flags.cache_hit;381 s.result_cached = ebp_hdr.flags.cache_hit;
382 result = try arena.dupe(u8, body[@sizeOf(EbpHdr)..]);382 result = try arena.dupe(u8, body[@sizeOf(EbpHdr)..]);
383 },383 },
lib/std/Build/Step/CheckObject.zig+7-7
...@@ -449,9 +449,9 @@ const MachODumper = struct {...@@ -449,9 +449,9 @@ const MachODumper = struct {
449 },449 },
450 .SYMTAB => if (opts.dump_symtab) {450 .SYMTAB => if (opts.dump_symtab) {
451 const lc = cmd.cast(macho.symtab_command).?;451 const lc = cmd.cast(macho.symtab_command).?;
452 symtab = @ptrCast(452 symtab = @as(
453 [*]const macho.nlist_64,453 [*]const macho.nlist_64,
454 @alignCast(@alignOf(macho.nlist_64), &bytes[lc.symoff]),454 @ptrCast(@alignCast(&bytes[lc.symoff])),
455 )[0..lc.nsyms];455 )[0..lc.nsyms];
456 strtab = bytes[lc.stroff..][0..lc.strsize];456 strtab = bytes[lc.stroff..][0..lc.strsize];
457 },457 },
...@@ -474,7 +474,7 @@ const MachODumper = struct {...@@ -474,7 +474,7 @@ const MachODumper = struct {
474 try writer.print("{s}\n", .{symtab_label});474 try writer.print("{s}\n", .{symtab_label});
475 for (symtab) |sym| {475 for (symtab) |sym| {
476 if (sym.stab()) continue;476 if (sym.stab()) continue;
477 const sym_name = mem.sliceTo(@ptrCast([*:0]const u8, strtab.ptr + sym.n_strx), 0);477 const sym_name = mem.sliceTo(@as([*:0]const u8, @ptrCast(strtab.ptr + sym.n_strx)), 0);
478 if (sym.sect()) {478 if (sym.sect()) {
479 const sect = sections.items[sym.n_sect - 1];479 const sect = sections.items[sym.n_sect - 1];
480 try writer.print("{x} ({s},{s})", .{480 try writer.print("{x} ({s},{s})", .{
...@@ -487,7 +487,7 @@ const MachODumper = struct {...@@ -487,7 +487,7 @@ const MachODumper = struct {
487 }487 }
488 try writer.print(" {s}\n", .{sym_name});488 try writer.print(" {s}\n", .{sym_name});
489 } else if (sym.undf()) {489 } else if (sym.undf()) {
490 const ordinal = @divTrunc(@bitCast(i16, sym.n_desc), macho.N_SYMBOL_RESOLVER);490 const ordinal = @divTrunc(@as(i16, @bitCast(sym.n_desc)), macho.N_SYMBOL_RESOLVER);
491 const import_name = blk: {491 const import_name = blk: {
492 if (ordinal <= 0) {492 if (ordinal <= 0) {
493 if (ordinal == macho.BIND_SPECIAL_DYLIB_SELF)493 if (ordinal == macho.BIND_SPECIAL_DYLIB_SELF)
...@@ -498,7 +498,7 @@ const MachODumper = struct {...@@ -498,7 +498,7 @@ const MachODumper = struct {
498 break :blk "flat lookup";498 break :blk "flat lookup";
499 unreachable;499 unreachable;
500 }500 }
501 const full_path = imports.items[@bitCast(u16, ordinal) - 1];501 const full_path = imports.items[@as(u16, @bitCast(ordinal)) - 1];
502 const basename = fs.path.basename(full_path);502 const basename = fs.path.basename(full_path);
503 assert(basename.len > 0);503 assert(basename.len > 0);
504 const ext = mem.lastIndexOfScalar(u8, basename, '.') orelse basename.len;504 const ext = mem.lastIndexOfScalar(u8, basename, '.') orelse basename.len;
...@@ -950,8 +950,8 @@ const WasmDumper = struct {...@@ -950,8 +950,8 @@ const WasmDumper = struct {
950 switch (opcode) {950 switch (opcode) {
951 .i32_const => try writer.print("i32.const {x}\n", .{try std.leb.readILEB128(i32, reader)}),951 .i32_const => try writer.print("i32.const {x}\n", .{try std.leb.readILEB128(i32, reader)}),
952 .i64_const => try writer.print("i64.const {x}\n", .{try std.leb.readILEB128(i64, reader)}),952 .i64_const => try writer.print("i64.const {x}\n", .{try std.leb.readILEB128(i64, reader)}),
953 .f32_const => try writer.print("f32.const {x}\n", .{@bitCast(f32, try reader.readIntLittle(u32))}),953 .f32_const => try writer.print("f32.const {x}\n", .{@as(f32, @bitCast(try reader.readIntLittle(u32)))}),
954 .f64_const => try writer.print("f64.const {x}\n", .{@bitCast(f64, try reader.readIntLittle(u64))}),954 .f64_const => try writer.print("f64.const {x}\n", .{@as(f64, @bitCast(try reader.readIntLittle(u64)))}),
955 .global_get => try writer.print("global.get {x}\n", .{try std.leb.readULEB128(u32, reader)}),955 .global_get => try writer.print("global.get {x}\n", .{try std.leb.readULEB128(u32, reader)}),
956 else => unreachable,956 else => unreachable,
957 }957 }
lib/std/Build/Step/Compile.zig+3-3
...@@ -321,7 +321,7 @@ pub const BuildId = union(enum) {...@@ -321,7 +321,7 @@ pub const BuildId = union(enum) {
321 pub fn initHexString(bytes: []const u8) BuildId {321 pub fn initHexString(bytes: []const u8) BuildId {
322 var result: BuildId = .{ .hexstring = .{322 var result: BuildId = .{ .hexstring = .{
323 .bytes = undefined,323 .bytes = undefined,
324 .len = @intCast(u8, bytes.len),324 .len = @as(u8, @intCast(bytes.len)),
325 } };325 } };
326 @memcpy(result.hexstring.bytes[0..bytes.len], bytes);326 @memcpy(result.hexstring.bytes[0..bytes.len], bytes);
327 return result;327 return result;
...@@ -342,7 +342,7 @@ pub const BuildId = union(enum) {...@@ -342,7 +342,7 @@ pub const BuildId = union(enum) {
342 } else if (mem.startsWith(u8, text, "0x")) {342 } else if (mem.startsWith(u8, text, "0x")) {
343 var result: BuildId = .{ .hexstring = undefined };343 var result: BuildId = .{ .hexstring = undefined };
344 const slice = try std.fmt.hexToBytes(&result.hexstring.bytes, text[2..]);344 const slice = try std.fmt.hexToBytes(&result.hexstring.bytes, text[2..]);
345 result.hexstring.len = @intCast(u8, slice.len);345 result.hexstring.len = @as(u8, @intCast(slice.len));
346 return result;346 return result;
347 }347 }
348 return error.InvalidBuildIdStyle;348 return error.InvalidBuildIdStyle;
...@@ -2059,7 +2059,7 @@ fn findVcpkgRoot(allocator: Allocator) !?[]const u8 {...@@ -2059,7 +2059,7 @@ fn findVcpkgRoot(allocator: Allocator) !?[]const u8 {
2059 const file = fs.cwd().openFile(path_file, .{}) catch return null;2059 const file = fs.cwd().openFile(path_file, .{}) catch return null;
2060 defer file.close();2060 defer file.close();
20612061
2062 const size = @intCast(usize, try file.getEndPos());2062 const size = @as(usize, @intCast(try file.getEndPos()));
2063 const vcpkg_path = try allocator.alloc(u8, size);2063 const vcpkg_path = try allocator.alloc(u8, size);
2064 const size_read = try file.read(vcpkg_path);2064 const size_read = try file.read(vcpkg_path);
2065 std.debug.assert(size == size_read);2065 std.debug.assert(size == size_read);
lib/std/Build/Step/Run.zig+2-2
...@@ -998,7 +998,7 @@ fn evalZigTest(...@@ -998,7 +998,7 @@ fn evalZigTest(
998 },998 },
999 .test_metadata => {999 .test_metadata => {
1000 const TmHdr = std.zig.Server.Message.TestMetadata;1000 const TmHdr = std.zig.Server.Message.TestMetadata;
1001 const tm_hdr = @ptrCast(*align(1) const TmHdr, body);1001 const tm_hdr = @as(*align(1) const TmHdr, @ptrCast(body));
1002 test_count = tm_hdr.tests_len;1002 test_count = tm_hdr.tests_len;
10031003
1004 const names_bytes = body[@sizeOf(TmHdr)..][0 .. test_count * @sizeOf(u32)];1004 const names_bytes = body[@sizeOf(TmHdr)..][0 .. test_count * @sizeOf(u32)];
...@@ -1034,7 +1034,7 @@ fn evalZigTest(...@@ -1034,7 +1034,7 @@ fn evalZigTest(
1034 const md = metadata.?;1034 const md = metadata.?;
10351035
1036 const TrHdr = std.zig.Server.Message.TestResults;1036 const TrHdr = std.zig.Server.Message.TestResults;
1037 const tr_hdr = @ptrCast(*align(1) const TrHdr, body);1037 const tr_hdr = @as(*align(1) const TrHdr, @ptrCast(body));
1038 fail_count += @intFromBool(tr_hdr.flags.fail);1038 fail_count += @intFromBool(tr_hdr.flags.fail);
1039 skip_count += @intFromBool(tr_hdr.flags.skip);1039 skip_count += @intFromBool(tr_hdr.flags.skip);
1040 leak_count += @intFromBool(tr_hdr.flags.leak);1040 leak_count += @intFromBool(tr_hdr.flags.leak);
lib/std/Progress.zig+2-2
...@@ -232,14 +232,14 @@ fn clearWithHeldLock(p: *Progress, end_ptr: *usize) void {...@@ -232,14 +232,14 @@ fn clearWithHeldLock(p: *Progress, end_ptr: *usize) void {
232 }232 }
233233
234 var cursor_pos = windows.COORD{234 var cursor_pos = windows.COORD{
235 .X = info.dwCursorPosition.X - @intCast(windows.SHORT, p.columns_written),235 .X = info.dwCursorPosition.X - @as(windows.SHORT, @intCast(p.columns_written)),
236 .Y = info.dwCursorPosition.Y,236 .Y = info.dwCursorPosition.Y,
237 };237 };
238238
239 if (cursor_pos.X < 0)239 if (cursor_pos.X < 0)
240 cursor_pos.X = 0;240 cursor_pos.X = 0;
241241
242 const fill_chars = @intCast(windows.DWORD, info.dwSize.X - cursor_pos.X);242 const fill_chars = @as(windows.DWORD, @intCast(info.dwSize.X - cursor_pos.X));
243243
244 var written: windows.DWORD = undefined;244 var written: windows.DWORD = undefined;
245 if (windows.kernel32.FillConsoleOutputAttribute(245 if (windows.kernel32.FillConsoleOutputAttribute(
lib/std/Thread.zig+21-21
...@@ -66,7 +66,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {...@@ -66,7 +66,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
66 if (self.getHandle() == std.c.pthread_self()) {66 if (self.getHandle() == std.c.pthread_self()) {
67 // Set the name of the calling thread (no thread id required).67 // Set the name of the calling thread (no thread id required).
68 const err = try os.prctl(.SET_NAME, .{@intFromPtr(name_with_terminator.ptr)});68 const err = try os.prctl(.SET_NAME, .{@intFromPtr(name_with_terminator.ptr)});
69 switch (@enumFromInt(os.E, err)) {69 switch (@as(os.E, @enumFromInt(err))) {
70 .SUCCESS => return,70 .SUCCESS => return,
71 else => |e| return os.unexpectedErrno(e),71 else => |e| return os.unexpectedErrno(e),
72 }72 }
...@@ -176,7 +176,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co...@@ -176,7 +176,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
176 if (self.getHandle() == std.c.pthread_self()) {176 if (self.getHandle() == std.c.pthread_self()) {
177 // Get the name of the calling thread (no thread id required).177 // Get the name of the calling thread (no thread id required).
178 const err = try os.prctl(.GET_NAME, .{@intFromPtr(buffer.ptr)});178 const err = try os.prctl(.GET_NAME, .{@intFromPtr(buffer.ptr)});
179 switch (@enumFromInt(os.E, err)) {179 switch (@as(os.E, @enumFromInt(err))) {
180 .SUCCESS => return std.mem.sliceTo(buffer, 0),180 .SUCCESS => return std.mem.sliceTo(buffer, 0),
181 else => |e| return os.unexpectedErrno(e),181 else => |e| return os.unexpectedErrno(e),
182 }182 }
...@@ -211,7 +211,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co...@@ -211,7 +211,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
211 null,211 null,
212 )) {212 )) {
213 .SUCCESS => {213 .SUCCESS => {
214 const string = @ptrCast(*const os.windows.UNICODE_STRING, &buf);214 const string = @as(*const os.windows.UNICODE_STRING, @ptrCast(&buf));
215 const len = try std.unicode.utf16leToUtf8(buffer, string.Buffer[0 .. string.Length / 2]);215 const len = try std.unicode.utf16leToUtf8(buffer, string.Buffer[0 .. string.Length / 2]);
216 return if (len > 0) buffer[0..len] else null;216 return if (len > 0) buffer[0..len] else null;
217 },217 },
...@@ -510,7 +510,7 @@ const WindowsThreadImpl = struct {...@@ -510,7 +510,7 @@ const WindowsThreadImpl = struct {
510 thread: ThreadCompletion,510 thread: ThreadCompletion,
511511
512 fn entryFn(raw_ptr: windows.PVOID) callconv(.C) windows.DWORD {512 fn entryFn(raw_ptr: windows.PVOID) callconv(.C) windows.DWORD {
513 const self = @ptrCast(*@This(), @alignCast(@alignOf(@This()), raw_ptr));513 const self: *@This() = @ptrCast(@alignCast(raw_ptr));
514 defer switch (self.thread.completion.swap(.completed, .SeqCst)) {514 defer switch (self.thread.completion.swap(.completed, .SeqCst)) {
515 .running => {},515 .running => {},
516 .completed => unreachable,516 .completed => unreachable,
...@@ -525,7 +525,7 @@ const WindowsThreadImpl = struct {...@@ -525,7 +525,7 @@ const WindowsThreadImpl = struct {
525 const alloc_ptr = windows.kernel32.HeapAlloc(heap_handle, 0, alloc_bytes) orelse return error.OutOfMemory;525 const alloc_ptr = windows.kernel32.HeapAlloc(heap_handle, 0, alloc_bytes) orelse return error.OutOfMemory;
526 errdefer assert(windows.kernel32.HeapFree(heap_handle, 0, alloc_ptr) != 0);526 errdefer assert(windows.kernel32.HeapFree(heap_handle, 0, alloc_ptr) != 0);
527527
528 const instance_bytes = @ptrCast([*]u8, alloc_ptr)[0..alloc_bytes];528 const instance_bytes = @as([*]u8, @ptrCast(alloc_ptr))[0..alloc_bytes];
529 var fba = std.heap.FixedBufferAllocator.init(instance_bytes);529 var fba = std.heap.FixedBufferAllocator.init(instance_bytes);
530 const instance = fba.allocator().create(Instance) catch unreachable;530 const instance = fba.allocator().create(Instance) catch unreachable;
531 instance.* = .{531 instance.* = .{
...@@ -547,7 +547,7 @@ const WindowsThreadImpl = struct {...@@ -547,7 +547,7 @@ const WindowsThreadImpl = struct {
547 null,547 null,
548 stack_size,548 stack_size,
549 Instance.entryFn,549 Instance.entryFn,
550 @ptrCast(*anyopaque, instance),550 @as(*anyopaque, @ptrCast(instance)),
551 0,551 0,
552 null,552 null,
553 ) orelse {553 ) orelse {
...@@ -596,19 +596,19 @@ const PosixThreadImpl = struct {...@@ -596,19 +596,19 @@ const PosixThreadImpl = struct {
596 return thread_id;596 return thread_id;
597 },597 },
598 .dragonfly => {598 .dragonfly => {
599 return @bitCast(u32, c.lwp_gettid());599 return @as(u32, @bitCast(c.lwp_gettid()));
600 },600 },
601 .netbsd => {601 .netbsd => {
602 return @bitCast(u32, c._lwp_self());602 return @as(u32, @bitCast(c._lwp_self()));
603 },603 },
604 .freebsd => {604 .freebsd => {
605 return @bitCast(u32, c.pthread_getthreadid_np());605 return @as(u32, @bitCast(c.pthread_getthreadid_np()));
606 },606 },
607 .openbsd => {607 .openbsd => {
608 return @bitCast(u32, c.getthrid());608 return @as(u32, @bitCast(c.getthrid()));
609 },609 },
610 .haiku => {610 .haiku => {
611 return @bitCast(u32, c.find_thread(null));611 return @as(u32, @bitCast(c.find_thread(null)));
612 },612 },
613 else => {613 else => {
614 return @intFromPtr(c.pthread_self());614 return @intFromPtr(c.pthread_self());
...@@ -629,7 +629,7 @@ const PosixThreadImpl = struct {...@@ -629,7 +629,7 @@ const PosixThreadImpl = struct {
629 error.NameTooLong, error.UnknownName => unreachable,629 error.NameTooLong, error.UnknownName => unreachable,
630 else => |e| return e,630 else => |e| return e,
631 };631 };
632 return @intCast(usize, count);632 return @as(usize, @intCast(count));
633 },633 },
634 .solaris => {634 .solaris => {
635 // The "proper" way to get the cpu count would be to query635 // The "proper" way to get the cpu count would be to query
...@@ -637,7 +637,7 @@ const PosixThreadImpl = struct {...@@ -637,7 +637,7 @@ const PosixThreadImpl = struct {
637 // cpu.637 // cpu.
638 const rc = c.sysconf(os._SC.NPROCESSORS_ONLN);638 const rc = c.sysconf(os._SC.NPROCESSORS_ONLN);
639 return switch (os.errno(rc)) {639 return switch (os.errno(rc)) {
640 .SUCCESS => @intCast(usize, rc),640 .SUCCESS => @as(usize, @intCast(rc)),
641 else => |err| os.unexpectedErrno(err),641 else => |err| os.unexpectedErrno(err),
642 };642 };
643 },643 },
...@@ -645,7 +645,7 @@ const PosixThreadImpl = struct {...@@ -645,7 +645,7 @@ const PosixThreadImpl = struct {
645 var system_info: os.system.system_info = undefined;645 var system_info: os.system.system_info = undefined;
646 const rc = os.system.get_system_info(&system_info); // always returns B_OK646 const rc = os.system.get_system_info(&system_info); // always returns B_OK
647 return switch (os.errno(rc)) {647 return switch (os.errno(rc)) {
648 .SUCCESS => @intCast(usize, system_info.cpu_count),648 .SUCCESS => @as(usize, @intCast(system_info.cpu_count)),
649 else => |err| os.unexpectedErrno(err),649 else => |err| os.unexpectedErrno(err),
650 };650 };
651 },651 },
...@@ -657,7 +657,7 @@ const PosixThreadImpl = struct {...@@ -657,7 +657,7 @@ const PosixThreadImpl = struct {
657 error.NameTooLong, error.UnknownName => unreachable,657 error.NameTooLong, error.UnknownName => unreachable,
658 else => |e| return e,658 else => |e| return e,
659 };659 };
660 return @intCast(usize, count);660 return @as(usize, @intCast(count));
661 },661 },
662 }662 }
663 }663 }
...@@ -675,7 +675,7 @@ const PosixThreadImpl = struct {...@@ -675,7 +675,7 @@ const PosixThreadImpl = struct {
675 return callFn(f, @as(Args, undefined));675 return callFn(f, @as(Args, undefined));
676 }676 }
677677
678 const args_ptr = @ptrCast(*Args, @alignCast(@alignOf(Args), raw_arg));678 const args_ptr: *Args = @ptrCast(@alignCast(raw_arg));
679 defer allocator.destroy(args_ptr);679 defer allocator.destroy(args_ptr);
680 return callFn(f, args_ptr.*);680 return callFn(f, args_ptr.*);
681 }681 }
...@@ -699,7 +699,7 @@ const PosixThreadImpl = struct {...@@ -699,7 +699,7 @@ const PosixThreadImpl = struct {
699 &handle,699 &handle,
700 &attr,700 &attr,
701 Instance.entryFn,701 Instance.entryFn,
702 if (@sizeOf(Args) > 1) @ptrCast(*anyopaque, args_ptr) else undefined,702 if (@sizeOf(Args) > 1) @as(*anyopaque, @ptrCast(args_ptr)) else undefined,
703 )) {703 )) {
704 .SUCCESS => return Impl{ .handle = handle },704 .SUCCESS => return Impl{ .handle = handle },
705 .AGAIN => return error.SystemResources,705 .AGAIN => return error.SystemResources,
...@@ -742,7 +742,7 @@ const LinuxThreadImpl = struct {...@@ -742,7 +742,7 @@ const LinuxThreadImpl = struct {
742742
743 fn getCurrentId() Id {743 fn getCurrentId() Id {
744 return tls_thread_id orelse {744 return tls_thread_id orelse {
745 const tid = @bitCast(u32, linux.gettid());745 const tid = @as(u32, @bitCast(linux.gettid()));
746 tls_thread_id = tid;746 tls_thread_id = tid;
747 return tid;747 return tid;
748 };748 };
...@@ -911,7 +911,7 @@ const LinuxThreadImpl = struct {...@@ -911,7 +911,7 @@ const LinuxThreadImpl = struct {
911 thread: ThreadCompletion,911 thread: ThreadCompletion,
912912
913 fn entryFn(raw_arg: usize) callconv(.C) u8 {913 fn entryFn(raw_arg: usize) callconv(.C) u8 {
914 const self = @ptrFromInt(*@This(), raw_arg);914 const self = @as(*@This(), @ptrFromInt(raw_arg));
915 defer switch (self.thread.completion.swap(.completed, .SeqCst)) {915 defer switch (self.thread.completion.swap(.completed, .SeqCst)) {
916 .running => {},916 .running => {},
917 .completed => unreachable,917 .completed => unreachable,
...@@ -969,7 +969,7 @@ const LinuxThreadImpl = struct {...@@ -969,7 +969,7 @@ const LinuxThreadImpl = struct {
969969
970 // map everything but the guard page as read/write970 // map everything but the guard page as read/write
971 os.mprotect(971 os.mprotect(
972 @alignCast(page_size, mapped[guard_offset..]),972 @alignCast(mapped[guard_offset..]),
973 os.PROT.READ | os.PROT.WRITE,973 os.PROT.READ | os.PROT.WRITE,
974 ) catch |err| switch (err) {974 ) catch |err| switch (err) {
975 error.AccessDenied => unreachable,975 error.AccessDenied => unreachable,
...@@ -994,7 +994,7 @@ const LinuxThreadImpl = struct {...@@ -994,7 +994,7 @@ const LinuxThreadImpl = struct {
994 };994 };
995 }995 }
996996
997 const instance = @ptrCast(*Instance, @alignCast(@alignOf(Instance), &mapped[instance_offset]));997 const instance: *Instance = @ptrCast(@alignCast(&mapped[instance_offset]));
998 instance.* = .{998 instance.* = .{
999 .fn_args = args,999 .fn_args = args,
1000 .thread = .{ .mapped = mapped },1000 .thread = .{ .mapped = mapped },
lib/std/Thread/Futex.zig+25-25
...@@ -128,14 +128,14 @@ const WindowsImpl = struct {...@@ -128,14 +128,14 @@ const WindowsImpl = struct {
128 // NTDLL functions work with time in units of 100 nanoseconds.128 // NTDLL functions work with time in units of 100 nanoseconds.
129 // Positive values are absolute deadlines while negative values are relative durations.129 // Positive values are absolute deadlines while negative values are relative durations.
130 if (timeout) |delay| {130 if (timeout) |delay| {
131 timeout_value = @intCast(os.windows.LARGE_INTEGER, delay / 100);131 timeout_value = @as(os.windows.LARGE_INTEGER, @intCast(delay / 100));
132 timeout_value = -timeout_value;132 timeout_value = -timeout_value;
133 timeout_ptr = &timeout_value;133 timeout_ptr = &timeout_value;
134 }134 }
135135
136 const rc = os.windows.ntdll.RtlWaitOnAddress(136 const rc = os.windows.ntdll.RtlWaitOnAddress(
137 @ptrCast(?*const anyopaque, ptr),137 @as(?*const anyopaque, @ptrCast(ptr)),
138 @ptrCast(?*const anyopaque, &expect),138 @as(?*const anyopaque, @ptrCast(&expect)),
139 @sizeOf(@TypeOf(expect)),139 @sizeOf(@TypeOf(expect)),
140 timeout_ptr,140 timeout_ptr,
141 );141 );
...@@ -151,7 +151,7 @@ const WindowsImpl = struct {...@@ -151,7 +151,7 @@ const WindowsImpl = struct {
151 }151 }
152152
153 fn wake(ptr: *const Atomic(u32), max_waiters: u32) void {153 fn wake(ptr: *const Atomic(u32), max_waiters: u32) void {
154 const address = @ptrCast(?*const anyopaque, ptr);154 const address = @as(?*const anyopaque, @ptrCast(ptr));
155 assert(max_waiters != 0);155 assert(max_waiters != 0);
156156
157 switch (max_waiters) {157 switch (max_waiters) {
...@@ -186,7 +186,7 @@ const DarwinImpl = struct {...@@ -186,7 +186,7 @@ const DarwinImpl = struct {
186 // true so that we we know to ignore the ETIMEDOUT result.186 // true so that we we know to ignore the ETIMEDOUT result.
187 var timeout_overflowed = false;187 var timeout_overflowed = false;
188188
189 const addr = @ptrCast(*const anyopaque, ptr);189 const addr = @as(*const anyopaque, @ptrCast(ptr));
190 const flags = os.darwin.UL_COMPARE_AND_WAIT | os.darwin.ULF_NO_ERRNO;190 const flags = os.darwin.UL_COMPARE_AND_WAIT | os.darwin.ULF_NO_ERRNO;
191 const status = blk: {191 const status = blk: {
192 if (supports_ulock_wait2) {192 if (supports_ulock_wait2) {
...@@ -202,7 +202,7 @@ const DarwinImpl = struct {...@@ -202,7 +202,7 @@ const DarwinImpl = struct {
202 };202 };
203203
204 if (status >= 0) return;204 if (status >= 0) return;
205 switch (@enumFromInt(std.os.E, -status)) {205 switch (@as(std.os.E, @enumFromInt(-status))) {
206 // Wait was interrupted by the OS or other spurious signalling.206 // Wait was interrupted by the OS or other spurious signalling.
207 .INTR => {},207 .INTR => {},
208 // Address of the futex was paged out. This is unlikely, but possible in theory, and208 // Address of the futex was paged out. This is unlikely, but possible in theory, and
...@@ -225,11 +225,11 @@ const DarwinImpl = struct {...@@ -225,11 +225,11 @@ const DarwinImpl = struct {
225 }225 }
226226
227 while (true) {227 while (true) {
228 const addr = @ptrCast(*const anyopaque, ptr);228 const addr = @as(*const anyopaque, @ptrCast(ptr));
229 const status = os.darwin.__ulock_wake(flags, addr, 0);229 const status = os.darwin.__ulock_wake(flags, addr, 0);
230230
231 if (status >= 0) return;231 if (status >= 0) return;
232 switch (@enumFromInt(std.os.E, -status)) {232 switch (@as(std.os.E, @enumFromInt(-status))) {
233 .INTR => continue, // spurious wake()233 .INTR => continue, // spurious wake()
234 .FAULT => unreachable, // __ulock_wake doesn't generate EFAULT according to darwin pthread_cond_t234 .FAULT => unreachable, // __ulock_wake doesn't generate EFAULT according to darwin pthread_cond_t
235 .NOENT => return, // nothing was woken up235 .NOENT => return, // nothing was woken up
...@@ -245,14 +245,14 @@ const LinuxImpl = struct {...@@ -245,14 +245,14 @@ const LinuxImpl = struct {
245 fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{Timeout}!void {245 fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{Timeout}!void {
246 var ts: os.timespec = undefined;246 var ts: os.timespec = undefined;
247 if (timeout) |timeout_ns| {247 if (timeout) |timeout_ns| {
248 ts.tv_sec = @intCast(@TypeOf(ts.tv_sec), timeout_ns / std.time.ns_per_s);248 ts.tv_sec = @as(@TypeOf(ts.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
249 ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), timeout_ns % std.time.ns_per_s);249 ts.tv_nsec = @as(@TypeOf(ts.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
250 }250 }
251251
252 const rc = os.linux.futex_wait(252 const rc = os.linux.futex_wait(
253 @ptrCast(*const i32, &ptr.value),253 @as(*const i32, @ptrCast(&ptr.value)),
254 os.linux.FUTEX.PRIVATE_FLAG | os.linux.FUTEX.WAIT,254 os.linux.FUTEX.PRIVATE_FLAG | os.linux.FUTEX.WAIT,
255 @bitCast(i32, expect),255 @as(i32, @bitCast(expect)),
256 if (timeout != null) &ts else null,256 if (timeout != null) &ts else null,
257 );257 );
258258
...@@ -272,7 +272,7 @@ const LinuxImpl = struct {...@@ -272,7 +272,7 @@ const LinuxImpl = struct {
272272
273 fn wake(ptr: *const Atomic(u32), max_waiters: u32) void {273 fn wake(ptr: *const Atomic(u32), max_waiters: u32) void {
274 const rc = os.linux.futex_wake(274 const rc = os.linux.futex_wake(
275 @ptrCast(*const i32, &ptr.value),275 @as(*const i32, @ptrCast(&ptr.value)),
276 os.linux.FUTEX.PRIVATE_FLAG | os.linux.FUTEX.WAKE,276 os.linux.FUTEX.PRIVATE_FLAG | os.linux.FUTEX.WAKE,
277 std.math.cast(i32, max_waiters) orelse std.math.maxInt(i32),277 std.math.cast(i32, max_waiters) orelse std.math.maxInt(i32),
278 );278 );
...@@ -299,8 +299,8 @@ const FreebsdImpl = struct {...@@ -299,8 +299,8 @@ const FreebsdImpl = struct {
299299
300 tm._flags = 0; // use relative time not UMTX_ABSTIME300 tm._flags = 0; // use relative time not UMTX_ABSTIME
301 tm._clockid = os.CLOCK.MONOTONIC;301 tm._clockid = os.CLOCK.MONOTONIC;
302 tm._timeout.tv_sec = @intCast(@TypeOf(tm._timeout.tv_sec), timeout_ns / std.time.ns_per_s);302 tm._timeout.tv_sec = @as(@TypeOf(tm._timeout.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
303 tm._timeout.tv_nsec = @intCast(@TypeOf(tm._timeout.tv_nsec), timeout_ns % std.time.ns_per_s);303 tm._timeout.tv_nsec = @as(@TypeOf(tm._timeout.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
304 }304 }
305305
306 const rc = os.freebsd._umtx_op(306 const rc = os.freebsd._umtx_op(
...@@ -347,14 +347,14 @@ const OpenbsdImpl = struct {...@@ -347,14 +347,14 @@ const OpenbsdImpl = struct {
347 fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{Timeout}!void {347 fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{Timeout}!void {
348 var ts: os.timespec = undefined;348 var ts: os.timespec = undefined;
349 if (timeout) |timeout_ns| {349 if (timeout) |timeout_ns| {
350 ts.tv_sec = @intCast(@TypeOf(ts.tv_sec), timeout_ns / std.time.ns_per_s);350 ts.tv_sec = @as(@TypeOf(ts.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
351 ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), timeout_ns % std.time.ns_per_s);351 ts.tv_nsec = @as(@TypeOf(ts.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
352 }352 }
353353
354 const rc = os.openbsd.futex(354 const rc = os.openbsd.futex(
355 @ptrCast(*const volatile u32, &ptr.value),355 @as(*const volatile u32, @ptrCast(&ptr.value)),
356 os.openbsd.FUTEX_WAIT | os.openbsd.FUTEX_PRIVATE_FLAG,356 os.openbsd.FUTEX_WAIT | os.openbsd.FUTEX_PRIVATE_FLAG,
357 @bitCast(c_int, expect),357 @as(c_int, @bitCast(expect)),
358 if (timeout != null) &ts else null,358 if (timeout != null) &ts else null,
359 null, // FUTEX_WAIT takes no requeue address359 null, // FUTEX_WAIT takes no requeue address
360 );360 );
...@@ -377,7 +377,7 @@ const OpenbsdImpl = struct {...@@ -377,7 +377,7 @@ const OpenbsdImpl = struct {
377377
378 fn wake(ptr: *const Atomic(u32), max_waiters: u32) void {378 fn wake(ptr: *const Atomic(u32), max_waiters: u32) void {
379 const rc = os.openbsd.futex(379 const rc = os.openbsd.futex(
380 @ptrCast(*const volatile u32, &ptr.value),380 @as(*const volatile u32, @ptrCast(&ptr.value)),
381 os.openbsd.FUTEX_WAKE | os.openbsd.FUTEX_PRIVATE_FLAG,381 os.openbsd.FUTEX_WAKE | os.openbsd.FUTEX_PRIVATE_FLAG,
382 std.math.cast(c_int, max_waiters) orelse std.math.maxInt(c_int),382 std.math.cast(c_int, max_waiters) orelse std.math.maxInt(c_int),
383 null, // FUTEX_WAKE takes no timeout ptr383 null, // FUTEX_WAKE takes no timeout ptr
...@@ -411,8 +411,8 @@ const DragonflyImpl = struct {...@@ -411,8 +411,8 @@ const DragonflyImpl = struct {
411 }411 }
412 }412 }
413413
414 const value = @bitCast(c_int, expect);414 const value = @as(c_int, @bitCast(expect));
415 const addr = @ptrCast(*const volatile c_int, &ptr.value);415 const addr = @as(*const volatile c_int, @ptrCast(&ptr.value));
416 const rc = os.dragonfly.umtx_sleep(addr, value, timeout_us);416 const rc = os.dragonfly.umtx_sleep(addr, value, timeout_us);
417417
418 switch (os.errno(rc)) {418 switch (os.errno(rc)) {
...@@ -441,7 +441,7 @@ const DragonflyImpl = struct {...@@ -441,7 +441,7 @@ const DragonflyImpl = struct {
441 // https://man.dragonflybsd.org/?command=umtx&section=2441 // https://man.dragonflybsd.org/?command=umtx&section=2
442 // > umtx_wakeup() will generally return 0 unless the address is bad.442 // > umtx_wakeup() will generally return 0 unless the address is bad.
443 // We are fine with the address being bad (e.g. for Semaphore.post() where Semaphore.wait() frees the Semaphore)443 // We are fine with the address being bad (e.g. for Semaphore.post() where Semaphore.wait() frees the Semaphore)
444 const addr = @ptrCast(*const volatile c_int, &ptr.value);444 const addr = @as(*const volatile c_int, @ptrCast(&ptr.value));
445 _ = os.dragonfly.umtx_wakeup(addr, to_wake);445 _ = os.dragonfly.umtx_wakeup(addr, to_wake);
446 }446 }
447};447};
...@@ -488,8 +488,8 @@ const PosixImpl = struct {...@@ -488,8 +488,8 @@ const PosixImpl = struct {
488 var ts: os.timespec = undefined;488 var ts: os.timespec = undefined;
489 if (timeout) |timeout_ns| {489 if (timeout) |timeout_ns| {
490 os.clock_gettime(os.CLOCK.REALTIME, &ts) catch unreachable;490 os.clock_gettime(os.CLOCK.REALTIME, &ts) catch unreachable;
491 ts.tv_sec +|= @intCast(@TypeOf(ts.tv_sec), timeout_ns / std.time.ns_per_s);491 ts.tv_sec +|= @as(@TypeOf(ts.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
492 ts.tv_nsec += @intCast(@TypeOf(ts.tv_nsec), timeout_ns % std.time.ns_per_s);492 ts.tv_nsec += @as(@TypeOf(ts.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
493493
494 if (ts.tv_nsec >= std.time.ns_per_s) {494 if (ts.tv_nsec >= std.time.ns_per_s) {
495 ts.tv_sec +|= 1;495 ts.tv_sec +|= 1;
lib/std/Thread/Mutex.zig+3-3
...@@ -242,12 +242,12 @@ const NonAtomicCounter = struct {...@@ -242,12 +242,12 @@ const NonAtomicCounter = struct {
242 value: [2]u64 = [_]u64{ 0, 0 },242 value: [2]u64 = [_]u64{ 0, 0 },
243243
244 fn get(self: NonAtomicCounter) u128 {244 fn get(self: NonAtomicCounter) u128 {
245 return @bitCast(u128, self.value);245 return @as(u128, @bitCast(self.value));
246 }246 }
247247
248 fn inc(self: *NonAtomicCounter) void {248 fn inc(self: *NonAtomicCounter) void {
249 for (@bitCast([2]u64, self.get() + 1), 0..) |v, i| {249 for (@as([2]u64, @bitCast(self.get() + 1)), 0..) |v, i| {
250 @ptrCast(*volatile u64, &self.value[i]).* = v;250 @as(*volatile u64, @ptrCast(&self.value[i])).* = v;
251 }251 }
252 }252 }
253};253};
lib/std/array_hash_map.zig+23-23
...@@ -49,7 +49,7 @@ pub fn eqlString(a: []const u8, b: []const u8) bool {...@@ -49,7 +49,7 @@ pub fn eqlString(a: []const u8, b: []const u8) bool {
49}49}
5050
51pub fn hashString(s: []const u8) u32 {51pub fn hashString(s: []const u8) u32 {
52 return @truncate(u32, std.hash.Wyhash.hash(0, s));52 return @as(u32, @truncate(std.hash.Wyhash.hash(0, s)));
53}53}
5454
55/// Insertion order is preserved.55/// Insertion order is preserved.
...@@ -617,7 +617,7 @@ pub fn ArrayHashMapUnmanaged(...@@ -617,7 +617,7 @@ pub fn ArrayHashMapUnmanaged(
617 return .{617 return .{
618 .keys = slice.items(.key).ptr,618 .keys = slice.items(.key).ptr,
619 .values = slice.items(.value).ptr,619 .values = slice.items(.value).ptr,
620 .len = @intCast(u32, slice.len),620 .len = @as(u32, @intCast(slice.len)),
621 };621 };
622 }622 }
623 pub const Iterator = struct {623 pub const Iterator = struct {
...@@ -1409,7 +1409,7 @@ pub fn ArrayHashMapUnmanaged(...@@ -1409,7 +1409,7 @@ pub fn ArrayHashMapUnmanaged(
1409 indexes: []Index(I),1409 indexes: []Index(I),
1410 ) void {1410 ) void {
1411 const slot = self.getSlotByIndex(old_entry_index, ctx, header, I, indexes);1411 const slot = self.getSlotByIndex(old_entry_index, ctx, header, I, indexes);
1412 indexes[slot].entry_index = @intCast(I, new_entry_index);1412 indexes[slot].entry_index = @as(I, @intCast(new_entry_index));
1413 }1413 }
14141414
1415 fn removeFromIndexByIndex(self: *Self, entry_index: usize, ctx: ByIndexContext, header: *IndexHeader) void {1415 fn removeFromIndexByIndex(self: *Self, entry_index: usize, ctx: ByIndexContext, header: *IndexHeader) void {
...@@ -1508,7 +1508,7 @@ pub fn ArrayHashMapUnmanaged(...@@ -1508,7 +1508,7 @@ pub fn ArrayHashMapUnmanaged(
1508 const new_index = self.entries.addOneAssumeCapacity();1508 const new_index = self.entries.addOneAssumeCapacity();
1509 indexes[slot] = .{1509 indexes[slot] = .{
1510 .distance_from_start_index = distance_from_start_index,1510 .distance_from_start_index = distance_from_start_index,
1511 .entry_index = @intCast(I, new_index),1511 .entry_index = @as(I, @intCast(new_index)),
1512 };1512 };
15131513
1514 // update the hash if applicable1514 // update the hash if applicable
...@@ -1549,7 +1549,7 @@ pub fn ArrayHashMapUnmanaged(...@@ -1549,7 +1549,7 @@ pub fn ArrayHashMapUnmanaged(
1549 const new_index = self.entries.addOneAssumeCapacity();1549 const new_index = self.entries.addOneAssumeCapacity();
1550 if (store_hash) hashes_array.ptr[new_index] = h;1550 if (store_hash) hashes_array.ptr[new_index] = h;
1551 indexes[slot] = .{1551 indexes[slot] = .{
1552 .entry_index = @intCast(I, new_index),1552 .entry_index = @as(I, @intCast(new_index)),
1553 .distance_from_start_index = distance_from_start_index,1553 .distance_from_start_index = distance_from_start_index,
1554 };1554 };
1555 distance_from_start_index = slot_data.distance_from_start_index;1555 distance_from_start_index = slot_data.distance_from_start_index;
...@@ -1639,7 +1639,7 @@ pub fn ArrayHashMapUnmanaged(...@@ -1639,7 +1639,7 @@ pub fn ArrayHashMapUnmanaged(
1639 const start_index = safeTruncate(usize, h);1639 const start_index = safeTruncate(usize, h);
1640 const end_index = start_index +% indexes.len;1640 const end_index = start_index +% indexes.len;
1641 var index = start_index;1641 var index = start_index;
1642 var entry_index = @intCast(I, i);1642 var entry_index = @as(I, @intCast(i));
1643 var distance_from_start_index: I = 0;1643 var distance_from_start_index: I = 0;
1644 while (index != end_index) : ({1644 while (index != end_index) : ({
1645 index +%= 1;1645 index +%= 1;
...@@ -1776,7 +1776,7 @@ fn capacityIndexSize(bit_index: u8) usize {...@@ -1776,7 +1776,7 @@ fn capacityIndexSize(bit_index: u8) usize {
1776fn safeTruncate(comptime T: type, val: anytype) T {1776fn safeTruncate(comptime T: type, val: anytype) T {
1777 if (@bitSizeOf(T) >= @bitSizeOf(@TypeOf(val)))1777 if (@bitSizeOf(T) >= @bitSizeOf(@TypeOf(val)))
1778 return val;1778 return val;
1779 return @truncate(T, val);1779 return @as(T, @truncate(val));
1780}1780}
17811781
1782/// A single entry in the lookup acceleration structure. These structs1782/// A single entry in the lookup acceleration structure. These structs
...@@ -1852,13 +1852,13 @@ const IndexHeader = struct {...@@ -1852,13 +1852,13 @@ const IndexHeader = struct {
1852 fn constrainIndex(header: IndexHeader, i: usize) usize {1852 fn constrainIndex(header: IndexHeader, i: usize) usize {
1853 // This is an optimization for modulo of power of two integers;1853 // This is an optimization for modulo of power of two integers;
1854 // it requires `indexes_len` to always be a power of two.1854 // it requires `indexes_len` to always be a power of two.
1855 return @intCast(usize, i & header.mask());1855 return @as(usize, @intCast(i & header.mask()));
1856 }1856 }
18571857
1858 /// Returns the attached array of indexes. I must match the type1858 /// Returns the attached array of indexes. I must match the type
1859 /// returned by capacityIndexType.1859 /// returned by capacityIndexType.
1860 fn indexes(header: *IndexHeader, comptime I: type) []Index(I) {1860 fn indexes(header: *IndexHeader, comptime I: type) []Index(I) {
1861 const start_ptr = @ptrCast([*]Index(I), @ptrCast([*]u8, header) + @sizeOf(IndexHeader));1861 const start_ptr: [*]Index(I) = @alignCast(@ptrCast(@as([*]u8, @ptrCast(header)) + @sizeOf(IndexHeader)));
1862 return start_ptr[0..header.length()];1862 return start_ptr[0..header.length()];
1863 }1863 }
18641864
...@@ -1871,15 +1871,15 @@ const IndexHeader = struct {...@@ -1871,15 +1871,15 @@ const IndexHeader = struct {
1871 return index_capacities[self.bit_index];1871 return index_capacities[self.bit_index];
1872 }1872 }
1873 fn length(self: IndexHeader) usize {1873 fn length(self: IndexHeader) usize {
1874 return @as(usize, 1) << @intCast(math.Log2Int(usize), self.bit_index);1874 return @as(usize, 1) << @as(math.Log2Int(usize), @intCast(self.bit_index));
1875 }1875 }
1876 fn mask(self: IndexHeader) u32 {1876 fn mask(self: IndexHeader) u32 {
1877 return @intCast(u32, self.length() - 1);1877 return @as(u32, @intCast(self.length() - 1));
1878 }1878 }
18791879
1880 fn findBitIndex(desired_capacity: usize) !u8 {1880 fn findBitIndex(desired_capacity: usize) !u8 {
1881 if (desired_capacity > max_capacity) return error.OutOfMemory;1881 if (desired_capacity > max_capacity) return error.OutOfMemory;
1882 var new_bit_index = @intCast(u8, std.math.log2_int_ceil(usize, desired_capacity));1882 var new_bit_index = @as(u8, @intCast(std.math.log2_int_ceil(usize, desired_capacity)));
1883 if (desired_capacity > index_capacities[new_bit_index]) new_bit_index += 1;1883 if (desired_capacity > index_capacities[new_bit_index]) new_bit_index += 1;
1884 if (new_bit_index < min_bit_index) new_bit_index = min_bit_index;1884 if (new_bit_index < min_bit_index) new_bit_index = min_bit_index;
1885 assert(desired_capacity <= index_capacities[new_bit_index]);1885 assert(desired_capacity <= index_capacities[new_bit_index]);
...@@ -1889,12 +1889,12 @@ const IndexHeader = struct {...@@ -1889,12 +1889,12 @@ const IndexHeader = struct {
1889 /// Allocates an index header, and fills the entryIndexes array with empty.1889 /// Allocates an index header, and fills the entryIndexes array with empty.
1890 /// The distance array contents are undefined.1890 /// The distance array contents are undefined.
1891 fn alloc(allocator: Allocator, new_bit_index: u8) !*IndexHeader {1891 fn alloc(allocator: Allocator, new_bit_index: u8) !*IndexHeader {
1892 const len = @as(usize, 1) << @intCast(math.Log2Int(usize), new_bit_index);1892 const len = @as(usize, 1) << @as(math.Log2Int(usize), @intCast(new_bit_index));
1893 const index_size = hash_map.capacityIndexSize(new_bit_index);1893 const index_size = hash_map.capacityIndexSize(new_bit_index);
1894 const nbytes = @sizeOf(IndexHeader) + index_size * len;1894 const nbytes = @sizeOf(IndexHeader) + index_size * len;
1895 const bytes = try allocator.alignedAlloc(u8, @alignOf(IndexHeader), nbytes);1895 const bytes = try allocator.alignedAlloc(u8, @alignOf(IndexHeader), nbytes);
1896 @memset(bytes[@sizeOf(IndexHeader)..], 0xff);1896 @memset(bytes[@sizeOf(IndexHeader)..], 0xff);
1897 const result = @ptrCast(*IndexHeader, bytes.ptr);1897 const result: *IndexHeader = @alignCast(@ptrCast(bytes.ptr));
1898 result.* = .{1898 result.* = .{
1899 .bit_index = new_bit_index,1899 .bit_index = new_bit_index,
1900 };1900 };
...@@ -1904,7 +1904,7 @@ const IndexHeader = struct {...@@ -1904,7 +1904,7 @@ const IndexHeader = struct {
1904 /// Releases the memory for a header and its associated arrays.1904 /// Releases the memory for a header and its associated arrays.
1905 fn free(header: *IndexHeader, allocator: Allocator) void {1905 fn free(header: *IndexHeader, allocator: Allocator) void {
1906 const index_size = hash_map.capacityIndexSize(header.bit_index);1906 const index_size = hash_map.capacityIndexSize(header.bit_index);
1907 const ptr = @ptrCast([*]align(@alignOf(IndexHeader)) u8, header);1907 const ptr: [*]align(@alignOf(IndexHeader)) u8 = @ptrCast(header);
1908 const slice = ptr[0 .. @sizeOf(IndexHeader) + header.length() * index_size];1908 const slice = ptr[0 .. @sizeOf(IndexHeader) + header.length() * index_size];
1909 allocator.free(slice);1909 allocator.free(slice);
1910 }1910 }
...@@ -1912,7 +1912,7 @@ const IndexHeader = struct {...@@ -1912,7 +1912,7 @@ const IndexHeader = struct {
1912 /// Puts an IndexHeader into the state that it would be in after being freshly allocated.1912 /// Puts an IndexHeader into the state that it would be in after being freshly allocated.
1913 fn reset(header: *IndexHeader) void {1913 fn reset(header: *IndexHeader) void {
1914 const index_size = hash_map.capacityIndexSize(header.bit_index);1914 const index_size = hash_map.capacityIndexSize(header.bit_index);
1915 const ptr = @ptrCast([*]align(@alignOf(IndexHeader)) u8, header);1915 const ptr: [*]align(@alignOf(IndexHeader)) u8 = @ptrCast(header);
1916 const nbytes = @sizeOf(IndexHeader) + header.length() * index_size;1916 const nbytes = @sizeOf(IndexHeader) + header.length() * index_size;
1917 @memset(ptr[@sizeOf(IndexHeader)..nbytes], 0xff);1917 @memset(ptr[@sizeOf(IndexHeader)..nbytes], 0xff);
1918 }1918 }
...@@ -2020,25 +2020,25 @@ test "iterator hash map" {...@@ -2020,25 +2020,25 @@ test "iterator hash map" {
20202020
2021 var count: usize = 0;2021 var count: usize = 0;
2022 while (it.next()) |entry| : (count += 1) {2022 while (it.next()) |entry| : (count += 1) {
2023 buffer[@intCast(usize, entry.key_ptr.*)] = entry.value_ptr.*;2023 buffer[@as(usize, @intCast(entry.key_ptr.*))] = entry.value_ptr.*;
2024 }2024 }
2025 try testing.expect(count == 3);2025 try testing.expect(count == 3);
2026 try testing.expect(it.next() == null);2026 try testing.expect(it.next() == null);
20272027
2028 for (buffer, 0..) |_, i| {2028 for (buffer, 0..) |_, i| {
2029 try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);2029 try testing.expect(buffer[@as(usize, @intCast(keys[i]))] == values[i]);
2030 }2030 }
20312031
2032 it.reset();2032 it.reset();
2033 count = 0;2033 count = 0;
2034 while (it.next()) |entry| {2034 while (it.next()) |entry| {
2035 buffer[@intCast(usize, entry.key_ptr.*)] = entry.value_ptr.*;2035 buffer[@as(usize, @intCast(entry.key_ptr.*))] = entry.value_ptr.*;
2036 count += 1;2036 count += 1;
2037 if (count >= 2) break;2037 if (count >= 2) break;
2038 }2038 }
20392039
2040 for (buffer[0..2], 0..) |_, i| {2040 for (buffer[0..2], 0..) |_, i| {
2041 try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);2041 try testing.expect(buffer[@as(usize, @intCast(keys[i]))] == values[i]);
2042 }2042 }
20432043
2044 it.reset();2044 it.reset();
...@@ -2336,11 +2336,11 @@ pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K)...@@ -2336,11 +2336,11 @@ pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K)
2336 fn hash(ctx: Context, key: K) u32 {2336 fn hash(ctx: Context, key: K) u32 {
2337 _ = ctx;2337 _ = ctx;
2338 if (comptime trait.hasUniqueRepresentation(K)) {2338 if (comptime trait.hasUniqueRepresentation(K)) {
2339 return @truncate(u32, Wyhash.hash(0, std.mem.asBytes(&key)));2339 return @as(u32, @truncate(Wyhash.hash(0, std.mem.asBytes(&key))));
2340 } else {2340 } else {
2341 var hasher = Wyhash.init(0);2341 var hasher = Wyhash.init(0);
2342 autoHash(&hasher, key);2342 autoHash(&hasher, key);
2343 return @truncate(u32, hasher.final());2343 return @as(u32, @truncate(hasher.final()));
2344 }2344 }
2345 }2345 }
2346 }.hash;2346 }.hash;
...@@ -2380,7 +2380,7 @@ pub fn getAutoHashStratFn(comptime K: type, comptime Context: type, comptime str...@@ -2380,7 +2380,7 @@ pub fn getAutoHashStratFn(comptime K: type, comptime Context: type, comptime str
2380 _ = ctx;2380 _ = ctx;
2381 var hasher = Wyhash.init(0);2381 var hasher = Wyhash.init(0);
2382 std.hash.autoHashStrat(&hasher, key, strategy);2382 std.hash.autoHashStrat(&hasher, key, strategy);
2383 return @truncate(u32, hasher.final());2383 return @as(u32, @truncate(hasher.final()));
2384 }2384 }
2385 }.hash;2385 }.hash;
2386}2386}
lib/std/array_list.zig+6-6
...@@ -1123,19 +1123,19 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {...@@ -1123,19 +1123,19 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
1123 {1123 {
1124 var i: usize = 0;1124 var i: usize = 0;
1125 while (i < 10) : (i += 1) {1125 while (i < 10) : (i += 1) {
1126 list.append(@intCast(i32, i + 1)) catch unreachable;1126 list.append(@as(i32, @intCast(i + 1))) catch unreachable;
1127 }1127 }
1128 }1128 }
11291129
1130 {1130 {
1131 var i: usize = 0;1131 var i: usize = 0;
1132 while (i < 10) : (i += 1) {1132 while (i < 10) : (i += 1) {
1133 try testing.expect(list.items[i] == @intCast(i32, i + 1));1133 try testing.expect(list.items[i] == @as(i32, @intCast(i + 1)));
1134 }1134 }
1135 }1135 }
11361136
1137 for (list.items, 0..) |v, i| {1137 for (list.items, 0..) |v, i| {
1138 try testing.expect(v == @intCast(i32, i + 1));1138 try testing.expect(v == @as(i32, @intCast(i + 1)));
1139 }1139 }
11401140
1141 try testing.expect(list.pop() == 10);1141 try testing.expect(list.pop() == 10);
...@@ -1173,19 +1173,19 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {...@@ -1173,19 +1173,19 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
1173 {1173 {
1174 var i: usize = 0;1174 var i: usize = 0;
1175 while (i < 10) : (i += 1) {1175 while (i < 10) : (i += 1) {
1176 list.append(a, @intCast(i32, i + 1)) catch unreachable;1176 list.append(a, @as(i32, @intCast(i + 1))) catch unreachable;
1177 }1177 }
1178 }1178 }
11791179
1180 {1180 {
1181 var i: usize = 0;1181 var i: usize = 0;
1182 while (i < 10) : (i += 1) {1182 while (i < 10) : (i += 1) {
1183 try testing.expect(list.items[i] == @intCast(i32, i + 1));1183 try testing.expect(list.items[i] == @as(i32, @intCast(i + 1)));
1184 }1184 }
1185 }1185 }
11861186
1187 for (list.items, 0..) |v, i| {1187 for (list.items, 0..) |v, i| {
1188 try testing.expect(v == @intCast(i32, i + 1));1188 try testing.expect(v == @as(i32, @intCast(i + 1)));
1189 }1189 }
11901190
1191 try testing.expect(list.pop() == 10);1191 try testing.expect(list.pop() == 10);
lib/std/atomic/Atomic.zig+10-10
...@@ -46,7 +46,7 @@ pub fn Atomic(comptime T: type) type {...@@ -46,7 +46,7 @@ pub fn Atomic(comptime T: type) type {
46 extern "c" fn __tsan_release(addr: *anyopaque) void;46 extern "c" fn __tsan_release(addr: *anyopaque) void;
47 };47 };
4848
49 const addr = @ptrCast(*anyopaque, self);49 const addr = @as(*anyopaque, @ptrCast(self));
50 return switch (ordering) {50 return switch (ordering) {
51 .Unordered, .Monotonic => @compileError(@tagName(ordering) ++ " only applies to atomic loads and stores"),51 .Unordered, .Monotonic => @compileError(@tagName(ordering) ++ " only applies to atomic loads and stores"),
52 .Acquire => tsan.__tsan_acquire(addr),52 .Acquire => tsan.__tsan_acquire(addr),
...@@ -307,7 +307,7 @@ pub fn Atomic(comptime T: type) type {...@@ -307,7 +307,7 @@ pub fn Atomic(comptime T: type) type {
307 // TODO: emit appropriate tsan fence if compiling with tsan307 // TODO: emit appropriate tsan fence if compiling with tsan
308 _ = ordering;308 _ = ordering;
309309
310 return @intCast(u1, old_bit);310 return @as(u1, @intCast(old_bit));
311 }311 }
312 });312 });
313 };313 };
...@@ -392,8 +392,8 @@ test "Atomic.swap" {...@@ -392,8 +392,8 @@ test "Atomic.swap" {
392 try testing.expectEqual(a.load(.SeqCst), true);392 try testing.expectEqual(a.load(.SeqCst), true);
393393
394 var b = Atomic(?*u8).init(null);394 var b = Atomic(?*u8).init(null);
395 try testing.expectEqual(b.swap(@ptrFromInt(?*u8, @alignOf(u8)), ordering), null);395 try testing.expectEqual(b.swap(@as(?*u8, @ptrFromInt(@alignOf(u8))), ordering), null);
396 try testing.expectEqual(b.load(.SeqCst), @ptrFromInt(?*u8, @alignOf(u8)));396 try testing.expectEqual(b.load(.SeqCst), @as(?*u8, @ptrFromInt(@alignOf(u8))));
397 }397 }
398}398}
399399
...@@ -544,7 +544,7 @@ test "Atomic.bitSet" {...@@ -544,7 +544,7 @@ test "Atomic.bitSet" {
544 var x = Atomic(Int).init(0);544 var x = Atomic(Int).init(0);
545545
546 for (0..@bitSizeOf(Int)) |bit_index| {546 for (0..@bitSizeOf(Int)) |bit_index| {
547 const bit = @intCast(std.math.Log2Int(Int), bit_index);547 const bit = @as(std.math.Log2Int(Int), @intCast(bit_index));
548 const mask = @as(Int, 1) << bit;548 const mask = @as(Int, 1) << bit;
549549
550 // setting the bit should change the bit550 // setting the bit should change the bit
...@@ -558,7 +558,7 @@ test "Atomic.bitSet" {...@@ -558,7 +558,7 @@ test "Atomic.bitSet" {
558558
559 // all the previous bits should have not changed (still be set)559 // all the previous bits should have not changed (still be set)
560 for (0..bit_index) |prev_bit_index| {560 for (0..bit_index) |prev_bit_index| {
561 const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index);561 const prev_bit = @as(std.math.Log2Int(Int), @intCast(prev_bit_index));
562 const prev_mask = @as(Int, 1) << prev_bit;562 const prev_mask = @as(Int, 1) << prev_bit;
563 try testing.expect(x.load(.SeqCst) & prev_mask != 0);563 try testing.expect(x.load(.SeqCst) & prev_mask != 0);
564 }564 }
...@@ -573,7 +573,7 @@ test "Atomic.bitReset" {...@@ -573,7 +573,7 @@ test "Atomic.bitReset" {
573 var x = Atomic(Int).init(0);573 var x = Atomic(Int).init(0);
574574
575 for (0..@bitSizeOf(Int)) |bit_index| {575 for (0..@bitSizeOf(Int)) |bit_index| {
576 const bit = @intCast(std.math.Log2Int(Int), bit_index);576 const bit = @as(std.math.Log2Int(Int), @intCast(bit_index));
577 const mask = @as(Int, 1) << bit;577 const mask = @as(Int, 1) << bit;
578 x.storeUnchecked(x.loadUnchecked() | mask);578 x.storeUnchecked(x.loadUnchecked() | mask);
579579
...@@ -588,7 +588,7 @@ test "Atomic.bitReset" {...@@ -588,7 +588,7 @@ test "Atomic.bitReset" {
588588
589 // all the previous bits should have not changed (still be reset)589 // all the previous bits should have not changed (still be reset)
590 for (0..bit_index) |prev_bit_index| {590 for (0..bit_index) |prev_bit_index| {
591 const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index);591 const prev_bit = @as(std.math.Log2Int(Int), @intCast(prev_bit_index));
592 const prev_mask = @as(Int, 1) << prev_bit;592 const prev_mask = @as(Int, 1) << prev_bit;
593 try testing.expect(x.load(.SeqCst) & prev_mask == 0);593 try testing.expect(x.load(.SeqCst) & prev_mask == 0);
594 }594 }
...@@ -603,7 +603,7 @@ test "Atomic.bitToggle" {...@@ -603,7 +603,7 @@ test "Atomic.bitToggle" {
603 var x = Atomic(Int).init(0);603 var x = Atomic(Int).init(0);
604604
605 for (0..@bitSizeOf(Int)) |bit_index| {605 for (0..@bitSizeOf(Int)) |bit_index| {
606 const bit = @intCast(std.math.Log2Int(Int), bit_index);606 const bit = @as(std.math.Log2Int(Int), @intCast(bit_index));
607 const mask = @as(Int, 1) << bit;607 const mask = @as(Int, 1) << bit;
608608
609 // toggling the bit should change the bit609 // toggling the bit should change the bit
...@@ -617,7 +617,7 @@ test "Atomic.bitToggle" {...@@ -617,7 +617,7 @@ test "Atomic.bitToggle" {
617617
618 // all the previous bits should have not changed (still be toggled back)618 // all the previous bits should have not changed (still be toggled back)
619 for (0..bit_index) |prev_bit_index| {619 for (0..bit_index) |prev_bit_index| {
620 const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index);620 const prev_bit = @as(std.math.Log2Int(Int), @intCast(prev_bit_index));
621 const prev_mask = @as(Int, 1) << prev_bit;621 const prev_mask = @as(Int, 1) << prev_bit;
622 try testing.expect(x.load(.SeqCst) & prev_mask == 0);622 try testing.expect(x.load(.SeqCst) & prev_mask == 0);
623 }623 }
lib/std/atomic/queue.zig+1-1
...@@ -248,7 +248,7 @@ fn startPuts(ctx: *Context) u8 {...@@ -248,7 +248,7 @@ fn startPuts(ctx: *Context) u8 {
248 const random = prng.random();248 const random = prng.random();
249 while (put_count != 0) : (put_count -= 1) {249 while (put_count != 0) : (put_count -= 1) {
250 std.time.sleep(1); // let the os scheduler be our fuzz250 std.time.sleep(1); // let the os scheduler be our fuzz
251 const x = @bitCast(i32, random.int(u32));251 const x = @as(i32, @bitCast(random.int(u32)));
252 const node = ctx.allocator.create(Queue(i32).Node) catch unreachable;252 const node = ctx.allocator.create(Queue(i32).Node) catch unreachable;
253 node.* = .{253 node.* = .{
254 .prev = undefined,254 .prev = undefined,
lib/std/atomic/stack.zig+1-1
...@@ -151,7 +151,7 @@ fn startPuts(ctx: *Context) u8 {...@@ -151,7 +151,7 @@ fn startPuts(ctx: *Context) u8 {
151 const random = prng.random();151 const random = prng.random();
152 while (put_count != 0) : (put_count -= 1) {152 while (put_count != 0) : (put_count -= 1) {
153 std.time.sleep(1); // let the os scheduler be our fuzz153 std.time.sleep(1); // let the os scheduler be our fuzz
154 const x = @bitCast(i32, random.int(u32));154 const x = @as(i32, @bitCast(random.int(u32)));
155 const node = ctx.allocator.create(Stack(i32).Node) catch unreachable;155 const node = ctx.allocator.create(Stack(i32).Node) catch unreachable;
156 node.* = Stack(i32).Node{156 node.* = Stack(i32).Node{
157 .next = undefined,157 .next = undefined,
lib/std/base64.zig+5-5
...@@ -108,12 +108,12 @@ pub const Base64Encoder = struct {...@@ -108,12 +108,12 @@ pub const Base64Encoder = struct {
108 acc_len += 8;108 acc_len += 8;
109 while (acc_len >= 6) {109 while (acc_len >= 6) {
110 acc_len -= 6;110 acc_len -= 6;
111 dest[out_idx] = encoder.alphabet_chars[@truncate(u6, (acc >> acc_len))];111 dest[out_idx] = encoder.alphabet_chars[@as(u6, @truncate((acc >> acc_len)))];
112 out_idx += 1;112 out_idx += 1;
113 }113 }
114 }114 }
115 if (acc_len > 0) {115 if (acc_len > 0) {
116 dest[out_idx] = encoder.alphabet_chars[@truncate(u6, (acc << 6 - acc_len))];116 dest[out_idx] = encoder.alphabet_chars[@as(u6, @truncate((acc << 6 - acc_len)))];
117 out_idx += 1;117 out_idx += 1;
118 }118 }
119 if (encoder.pad_char) |pad_char| {119 if (encoder.pad_char) |pad_char| {
...@@ -144,7 +144,7 @@ pub const Base64Decoder = struct {...@@ -144,7 +144,7 @@ pub const Base64Decoder = struct {
144 assert(!char_in_alphabet[c]);144 assert(!char_in_alphabet[c]);
145 assert(pad_char == null or c != pad_char.?);145 assert(pad_char == null or c != pad_char.?);
146146
147 result.char_to_index[c] = @intCast(u8, i);147 result.char_to_index[c] = @as(u8, @intCast(i));
148 char_in_alphabet[c] = true;148 char_in_alphabet[c] = true;
149 }149 }
150 return result;150 return result;
...@@ -196,7 +196,7 @@ pub const Base64Decoder = struct {...@@ -196,7 +196,7 @@ pub const Base64Decoder = struct {
196 acc_len += 6;196 acc_len += 6;
197 if (acc_len >= 8) {197 if (acc_len >= 8) {
198 acc_len -= 8;198 acc_len -= 8;
199 dest[dest_idx] = @truncate(u8, acc >> acc_len);199 dest[dest_idx] = @as(u8, @truncate(acc >> acc_len));
200 dest_idx += 1;200 dest_idx += 1;
201 }201 }
202 }202 }
...@@ -271,7 +271,7 @@ pub const Base64DecoderWithIgnore = struct {...@@ -271,7 +271,7 @@ pub const Base64DecoderWithIgnore = struct {
271 if (acc_len >= 8) {271 if (acc_len >= 8) {
272 if (dest_idx == dest.len) return error.NoSpaceLeft;272 if (dest_idx == dest.len) return error.NoSpaceLeft;
273 acc_len -= 8;273 acc_len -= 8;
274 dest[dest_idx] = @truncate(u8, acc >> acc_len);274 dest[dest_idx] = @as(u8, @truncate(acc >> acc_len));
275 dest_idx += 1;275 dest_idx += 1;
276 }276 }
277 }277 }
lib/std/bit_set.zig+21-21
...@@ -119,19 +119,19 @@ pub fn IntegerBitSet(comptime size: u16) type {...@@ -119,19 +119,19 @@ pub fn IntegerBitSet(comptime size: u16) type {
119 if (range.start == range.end) return;119 if (range.start == range.end) return;
120 if (MaskInt == u0) return;120 if (MaskInt == u0) return;
121121
122 const start_bit = @intCast(ShiftInt, range.start);122 const start_bit = @as(ShiftInt, @intCast(range.start));
123123
124 var mask = std.math.boolMask(MaskInt, true) << start_bit;124 var mask = std.math.boolMask(MaskInt, true) << start_bit;
125 if (range.end != bit_length) {125 if (range.end != bit_length) {
126 const end_bit = @intCast(ShiftInt, range.end);126 const end_bit = @as(ShiftInt, @intCast(range.end));
127 mask &= std.math.boolMask(MaskInt, true) >> @truncate(ShiftInt, @as(usize, @bitSizeOf(MaskInt)) - @as(usize, end_bit));127 mask &= std.math.boolMask(MaskInt, true) >> @as(ShiftInt, @truncate(@as(usize, @bitSizeOf(MaskInt)) - @as(usize, end_bit)));
128 }128 }
129 self.mask &= ~mask;129 self.mask &= ~mask;
130130
131 mask = std.math.boolMask(MaskInt, value) << start_bit;131 mask = std.math.boolMask(MaskInt, value) << start_bit;
132 if (range.end != bit_length) {132 if (range.end != bit_length) {
133 const end_bit = @intCast(ShiftInt, range.end);133 const end_bit = @as(ShiftInt, @intCast(range.end));
134 mask &= std.math.boolMask(MaskInt, value) >> @truncate(ShiftInt, @as(usize, @bitSizeOf(MaskInt)) - @as(usize, end_bit));134 mask &= std.math.boolMask(MaskInt, value) >> @as(ShiftInt, @truncate(@as(usize, @bitSizeOf(MaskInt)) - @as(usize, end_bit)));
135 }135 }
136 self.mask |= mask;136 self.mask |= mask;
137 }137 }
...@@ -292,7 +292,7 @@ pub fn IntegerBitSet(comptime size: u16) type {...@@ -292,7 +292,7 @@ pub fn IntegerBitSet(comptime size: u16) type {
292 .reverse => {292 .reverse => {
293 const leading_zeroes = @clz(self.bits_remain);293 const leading_zeroes = @clz(self.bits_remain);
294 const top_bit = (@bitSizeOf(MaskInt) - 1) - leading_zeroes;294 const top_bit = (@bitSizeOf(MaskInt) - 1) - leading_zeroes;
295 self.bits_remain &= (@as(MaskInt, 1) << @intCast(ShiftInt, top_bit)) - 1;295 self.bits_remain &= (@as(MaskInt, 1) << @as(ShiftInt, @intCast(top_bit))) - 1;
296 return top_bit;296 return top_bit;
297 },297 },
298 }298 }
...@@ -302,11 +302,11 @@ pub fn IntegerBitSet(comptime size: u16) type {...@@ -302,11 +302,11 @@ pub fn IntegerBitSet(comptime size: u16) type {
302302
303 fn maskBit(index: usize) MaskInt {303 fn maskBit(index: usize) MaskInt {
304 if (MaskInt == u0) return 0;304 if (MaskInt == u0) return 0;
305 return @as(MaskInt, 1) << @intCast(ShiftInt, index);305 return @as(MaskInt, 1) << @as(ShiftInt, @intCast(index));
306 }306 }
307 fn boolMaskBit(index: usize, value: bool) MaskInt {307 fn boolMaskBit(index: usize, value: bool) MaskInt {
308 if (MaskInt == u0) return 0;308 if (MaskInt == u0) return 0;
309 return @as(MaskInt, @intFromBool(value)) << @intCast(ShiftInt, index);309 return @as(MaskInt, @intFromBool(value)) << @as(ShiftInt, @intCast(index));
310 }310 }
311 };311 };
312}312}
...@@ -442,10 +442,10 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {...@@ -442,10 +442,10 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {
442 if (num_masks == 0) return;442 if (num_masks == 0) return;
443443
444 const start_mask_index = maskIndex(range.start);444 const start_mask_index = maskIndex(range.start);
445 const start_bit = @truncate(ShiftInt, range.start);445 const start_bit = @as(ShiftInt, @truncate(range.start));
446446
447 const end_mask_index = maskIndex(range.end);447 const end_mask_index = maskIndex(range.end);
448 const end_bit = @truncate(ShiftInt, range.end);448 const end_bit = @as(ShiftInt, @truncate(range.end));
449449
450 if (start_mask_index == end_mask_index) {450 if (start_mask_index == end_mask_index) {
451 var mask1 = std.math.boolMask(MaskInt, true) << start_bit;451 var mask1 = std.math.boolMask(MaskInt, true) << start_bit;
...@@ -634,13 +634,13 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {...@@ -634,13 +634,13 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {
634 }634 }
635635
636 fn maskBit(index: usize) MaskInt {636 fn maskBit(index: usize) MaskInt {
637 return @as(MaskInt, 1) << @truncate(ShiftInt, index);637 return @as(MaskInt, 1) << @as(ShiftInt, @truncate(index));
638 }638 }
639 fn maskIndex(index: usize) usize {639 fn maskIndex(index: usize) usize {
640 return index >> @bitSizeOf(ShiftInt);640 return index >> @bitSizeOf(ShiftInt);
641 }641 }
642 fn boolMaskBit(index: usize, value: bool) MaskInt {642 fn boolMaskBit(index: usize, value: bool) MaskInt {
643 return @as(MaskInt, @intFromBool(value)) << @intCast(ShiftInt, index);643 return @as(MaskInt, @intFromBool(value)) << @as(ShiftInt, @intCast(index));
644 }644 }
645 };645 };
646}646}
...@@ -731,7 +731,7 @@ pub const DynamicBitSetUnmanaged = struct {...@@ -731,7 +731,7 @@ pub const DynamicBitSetUnmanaged = struct {
731 // set the padding bits in the old last item to 1731 // set the padding bits in the old last item to 1
732 if (fill and old_masks > 0) {732 if (fill and old_masks > 0) {
733 const old_padding_bits = old_masks * @bitSizeOf(MaskInt) - old_len;733 const old_padding_bits = old_masks * @bitSizeOf(MaskInt) - old_len;
734 const old_mask = (~@as(MaskInt, 0)) >> @intCast(ShiftInt, old_padding_bits);734 const old_mask = (~@as(MaskInt, 0)) >> @as(ShiftInt, @intCast(old_padding_bits));
735 self.masks[old_masks - 1] |= ~old_mask;735 self.masks[old_masks - 1] |= ~old_mask;
736 }736 }
737737
...@@ -745,7 +745,7 @@ pub const DynamicBitSetUnmanaged = struct {...@@ -745,7 +745,7 @@ pub const DynamicBitSetUnmanaged = struct {
745 // Zero out the padding bits745 // Zero out the padding bits
746 if (new_len > 0) {746 if (new_len > 0) {
747 const padding_bits = new_masks * @bitSizeOf(MaskInt) - new_len;747 const padding_bits = new_masks * @bitSizeOf(MaskInt) - new_len;
748 const last_item_mask = (~@as(MaskInt, 0)) >> @intCast(ShiftInt, padding_bits);748 const last_item_mask = (~@as(MaskInt, 0)) >> @as(ShiftInt, @intCast(padding_bits));
749 self.masks[new_masks - 1] &= last_item_mask;749 self.masks[new_masks - 1] &= last_item_mask;
750 }750 }
751751
...@@ -816,10 +816,10 @@ pub const DynamicBitSetUnmanaged = struct {...@@ -816,10 +816,10 @@ pub const DynamicBitSetUnmanaged = struct {
816 if (range.start == range.end) return;816 if (range.start == range.end) return;
817817
818 const start_mask_index = maskIndex(range.start);818 const start_mask_index = maskIndex(range.start);
819 const start_bit = @truncate(ShiftInt, range.start);819 const start_bit = @as(ShiftInt, @truncate(range.start));
820820
821 const end_mask_index = maskIndex(range.end);821 const end_mask_index = maskIndex(range.end);
822 const end_bit = @truncate(ShiftInt, range.end);822 const end_bit = @as(ShiftInt, @truncate(range.end));
823823
824 if (start_mask_index == end_mask_index) {824 if (start_mask_index == end_mask_index) {
825 var mask1 = std.math.boolMask(MaskInt, true) << start_bit;825 var mask1 = std.math.boolMask(MaskInt, true) << start_bit;
...@@ -887,7 +887,7 @@ pub const DynamicBitSetUnmanaged = struct {...@@ -887,7 +887,7 @@ pub const DynamicBitSetUnmanaged = struct {
887 }887 }
888888
889 const padding_bits = num_masks * @bitSizeOf(MaskInt) - bit_length;889 const padding_bits = num_masks * @bitSizeOf(MaskInt) - bit_length;
890 const last_item_mask = (~@as(MaskInt, 0)) >> @intCast(ShiftInt, padding_bits);890 const last_item_mask = (~@as(MaskInt, 0)) >> @as(ShiftInt, @intCast(padding_bits));
891 self.masks[num_masks - 1] &= last_item_mask;891 self.masks[num_masks - 1] &= last_item_mask;
892 }892 }
893893
...@@ -996,7 +996,7 @@ pub const DynamicBitSetUnmanaged = struct {...@@ -996,7 +996,7 @@ pub const DynamicBitSetUnmanaged = struct {
996 pub fn iterator(self: *const Self, comptime options: IteratorOptions) Iterator(options) {996 pub fn iterator(self: *const Self, comptime options: IteratorOptions) Iterator(options) {
997 const num_masks = numMasks(self.bit_length);997 const num_masks = numMasks(self.bit_length);
998 const padding_bits = num_masks * @bitSizeOf(MaskInt) - self.bit_length;998 const padding_bits = num_masks * @bitSizeOf(MaskInt) - self.bit_length;
999 const last_item_mask = (~@as(MaskInt, 0)) >> @intCast(ShiftInt, padding_bits);999 const last_item_mask = (~@as(MaskInt, 0)) >> @as(ShiftInt, @intCast(padding_bits));
1000 return Iterator(options).init(self.masks[0..num_masks], last_item_mask);1000 return Iterator(options).init(self.masks[0..num_masks], last_item_mask);
1001 }1001 }
10021002
...@@ -1005,13 +1005,13 @@ pub const DynamicBitSetUnmanaged = struct {...@@ -1005,13 +1005,13 @@ pub const DynamicBitSetUnmanaged = struct {
1005 }1005 }
10061006
1007 fn maskBit(index: usize) MaskInt {1007 fn maskBit(index: usize) MaskInt {
1008 return @as(MaskInt, 1) << @truncate(ShiftInt, index);1008 return @as(MaskInt, 1) << @as(ShiftInt, @truncate(index));
1009 }1009 }
1010 fn maskIndex(index: usize) usize {1010 fn maskIndex(index: usize) usize {
1011 return index >> @bitSizeOf(ShiftInt);1011 return index >> @bitSizeOf(ShiftInt);
1012 }1012 }
1013 fn boolMaskBit(index: usize, value: bool) MaskInt {1013 fn boolMaskBit(index: usize, value: bool) MaskInt {
1014 return @as(MaskInt, @intFromBool(value)) << @intCast(ShiftInt, index);1014 return @as(MaskInt, @intFromBool(value)) << @as(ShiftInt, @intCast(index));
1015 }1015 }
1016 fn numMasks(bit_length: usize) usize {1016 fn numMasks(bit_length: usize) usize {
1017 return (bit_length + (@bitSizeOf(MaskInt) - 1)) / @bitSizeOf(MaskInt);1017 return (bit_length + (@bitSizeOf(MaskInt) - 1)) / @bitSizeOf(MaskInt);
...@@ -1255,7 +1255,7 @@ fn BitSetIterator(comptime MaskInt: type, comptime options: IteratorOptions) typ...@@ -1255,7 +1255,7 @@ fn BitSetIterator(comptime MaskInt: type, comptime options: IteratorOptions) typ
1255 .reverse => {1255 .reverse => {
1256 const leading_zeroes = @clz(self.bits_remain);1256 const leading_zeroes = @clz(self.bits_remain);
1257 const top_bit = (@bitSizeOf(MaskInt) - 1) - leading_zeroes;1257 const top_bit = (@bitSizeOf(MaskInt) - 1) - leading_zeroes;
1258 const no_top_bit_mask = (@as(MaskInt, 1) << @intCast(ShiftInt, top_bit)) - 1;1258 const no_top_bit_mask = (@as(MaskInt, 1) << @as(ShiftInt, @intCast(top_bit))) - 1;
1259 self.bits_remain &= no_top_bit_mask;1259 self.bits_remain &= no_top_bit_mask;
1260 return top_bit + self.bit_offset;1260 return top_bit + self.bit_offset;
1261 },1261 },
lib/std/bounded_array.zig+1-1
...@@ -394,7 +394,7 @@ test "BoundedArrayAligned" {...@@ -394,7 +394,7 @@ test "BoundedArrayAligned" {
394 try a.append(255);394 try a.append(255);
395 try a.append(255);395 try a.append(255);
396396
397 const b = @ptrCast(*const [2]u16, a.constSlice().ptr);397 const b = @as(*const [2]u16, @ptrCast(a.constSlice().ptr));
398 try testing.expectEqual(@as(u16, 0), b[0]);398 try testing.expectEqual(@as(u16, 0), b[0]);
399 try testing.expectEqual(@as(u16, 65535), b[1]);399 try testing.expectEqual(@as(u16, 65535), b[1]);
400}400}
lib/std/builtin.zig+1-1
...@@ -784,7 +784,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr...@@ -784,7 +784,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr
784784
785 exit_size.* = 256;785 exit_size.* = 256;
786786
787 return @ptrCast([*:0]u16, utf16.ptr);787 return @as([*:0]u16, @ptrCast(utf16.ptr));
788 }788 }
789 };789 };
790790
lib/std/c.zig+1-1
...@@ -113,7 +113,7 @@ pub usingnamespace switch (builtin.os.tag) {...@@ -113,7 +113,7 @@ pub usingnamespace switch (builtin.os.tag) {
113113
114pub fn getErrno(rc: anytype) c.E {114pub fn getErrno(rc: anytype) c.E {
115 if (rc == -1) {115 if (rc == -1) {
116 return @enumFromInt(c.E, c._errno().*);116 return @as(c.E, @enumFromInt(c._errno().*));
117 } else {117 } else {
118 return .SUCCESS;118 return .SUCCESS;
119 }119 }
lib/std/c/darwin.zig+34-34
...@@ -1177,10 +1177,10 @@ pub const sigset_t = u32;...@@ -1177,10 +1177,10 @@ pub const sigset_t = u32;
1177pub const empty_sigset: sigset_t = 0;1177pub const empty_sigset: sigset_t = 0;
11781178
1179pub const SIG = struct {1179pub const SIG = struct {
1180 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));1180 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
1181 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);1181 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
1182 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);1182 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
1183 pub const HOLD = @ptrFromInt(?Sigaction.handler_fn, 5);1183 pub const HOLD = @as(?Sigaction.handler_fn, @ptrFromInt(5));
11841184
1185 /// block specified signal set1185 /// block specified signal set
1186 pub const _BLOCK = 1;1186 pub const _BLOCK = 1;
...@@ -1411,7 +1411,7 @@ pub const MAP = struct {...@@ -1411,7 +1411,7 @@ pub const MAP = struct {
1411 pub const NOCACHE = 0x0400;1411 pub const NOCACHE = 0x0400;
1412 /// don't reserve needed swap area1412 /// don't reserve needed swap area
1413 pub const NORESERVE = 0x0040;1413 pub const NORESERVE = 0x0040;
1414 pub const FAILED = @ptrFromInt(*anyopaque, maxInt(usize));1414 pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
1415};1415};
14161416
1417pub const MSF = struct {1417pub const MSF = struct {
...@@ -1879,7 +1879,7 @@ pub const W = struct {...@@ -1879,7 +1879,7 @@ pub const W = struct {
1879 pub const UNTRACED = 0x00000002;1879 pub const UNTRACED = 0x00000002;
18801880
1881 pub fn EXITSTATUS(x: u32) u8 {1881 pub fn EXITSTATUS(x: u32) u8 {
1882 return @intCast(u8, x >> 8);1882 return @as(u8, @intCast(x >> 8));
1883 }1883 }
1884 pub fn TERMSIG(x: u32) u32 {1884 pub fn TERMSIG(x: u32) u32 {
1885 return status(x);1885 return status(x);
...@@ -2463,7 +2463,7 @@ pub const KernE = enum(u32) {...@@ -2463,7 +2463,7 @@ pub const KernE = enum(u32) {
2463pub const mach_msg_return_t = kern_return_t;2463pub const mach_msg_return_t = kern_return_t;
24642464
2465pub fn getMachMsgError(err: mach_msg_return_t) MachMsgE {2465pub fn getMachMsgError(err: mach_msg_return_t) MachMsgE {
2466 return @enumFromInt(MachMsgE, @truncate(u32, @intCast(usize, err)));2466 return @as(MachMsgE, @enumFromInt(@as(u32, @truncate(@as(usize, @intCast(err))))));
2467}2467}
24682468
2469/// All special error code bits defined below.2469/// All special error code bits defined below.
...@@ -2665,10 +2665,10 @@ pub const RTLD = struct {...@@ -2665,10 +2665,10 @@ pub const RTLD = struct {
2665 pub const NODELETE = 0x80;2665 pub const NODELETE = 0x80;
2666 pub const FIRST = 0x100;2666 pub const FIRST = 0x100;
26672667
2668 pub const NEXT = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -1)));2668 pub const NEXT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))));
2669 pub const DEFAULT = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -2)));2669 pub const DEFAULT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -2)))));
2670 pub const SELF = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -3)));2670 pub const SELF = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))));
2671 pub const MAIN_ONLY = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -5)));2671 pub const MAIN_ONLY = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -5)))));
2672};2672};
26732673
2674pub const F = struct {2674pub const F = struct {
...@@ -3238,14 +3238,14 @@ pub const PosixSpawn = struct {...@@ -3238,14 +3238,14 @@ pub const PosixSpawn = struct {
3238 pub fn get(self: Attr) Error!u16 {3238 pub fn get(self: Attr) Error!u16 {
3239 var flags: c_short = undefined;3239 var flags: c_short = undefined;
3240 switch (errno(posix_spawnattr_getflags(&self.attr, &flags))) {3240 switch (errno(posix_spawnattr_getflags(&self.attr, &flags))) {
3241 .SUCCESS => return @bitCast(u16, flags),3241 .SUCCESS => return @as(u16, @bitCast(flags)),
3242 .INVAL => unreachable,3242 .INVAL => unreachable,
3243 else => |err| return unexpectedErrno(err),3243 else => |err| return unexpectedErrno(err),
3244 }3244 }
3245 }3245 }
32463246
3247 pub fn set(self: *Attr, flags: u16) Error!void {3247 pub fn set(self: *Attr, flags: u16) Error!void {
3248 switch (errno(posix_spawnattr_setflags(&self.attr, @bitCast(c_short, flags)))) {3248 switch (errno(posix_spawnattr_setflags(&self.attr, @as(c_short, @bitCast(flags))))) {
3249 .SUCCESS => return,3249 .SUCCESS => return,
3250 .INVAL => unreachable,3250 .INVAL => unreachable,
3251 else => |err| return unexpectedErrno(err),3251 else => |err| return unexpectedErrno(err),
...@@ -3281,7 +3281,7 @@ pub const PosixSpawn = struct {...@@ -3281,7 +3281,7 @@ pub const PosixSpawn = struct {
3281 }3281 }
32823282
3283 pub fn openZ(self: *Actions, fd: fd_t, path: [*:0]const u8, flags: u32, mode: mode_t) Error!void {3283 pub fn openZ(self: *Actions, fd: fd_t, path: [*:0]const u8, flags: u32, mode: mode_t) Error!void {
3284 switch (errno(posix_spawn_file_actions_addopen(&self.actions, fd, path, @bitCast(c_int, flags), mode))) {3284 switch (errno(posix_spawn_file_actions_addopen(&self.actions, fd, path, @as(c_int, @bitCast(flags)), mode))) {
3285 .SUCCESS => return,3285 .SUCCESS => return,
3286 .BADF => return error.InvalidFileDescriptor,3286 .BADF => return error.InvalidFileDescriptor,
3287 .NOMEM => return error.SystemResources,3287 .NOMEM => return error.SystemResources,
...@@ -3402,11 +3402,11 @@ pub const PosixSpawn = struct {...@@ -3402,11 +3402,11 @@ pub const PosixSpawn = struct {
3402 pub fn waitpid(pid: pid_t, flags: u32) Error!std.os.WaitPidResult {3402 pub fn waitpid(pid: pid_t, flags: u32) Error!std.os.WaitPidResult {
3403 var status: c_int = undefined;3403 var status: c_int = undefined;
3404 while (true) {3404 while (true) {
3405 const rc = waitpid(pid, &status, @intCast(c_int, flags));3405 const rc = waitpid(pid, &status, @as(c_int, @intCast(flags)));
3406 switch (errno(rc)) {3406 switch (errno(rc)) {
3407 .SUCCESS => return std.os.WaitPidResult{3407 .SUCCESS => return std.os.WaitPidResult{
3408 .pid = @intCast(pid_t, rc),3408 .pid = @as(pid_t, @intCast(rc)),
3409 .status = @bitCast(u32, status),3409 .status = @as(u32, @bitCast(status)),
3410 },3410 },
3411 .INTR => continue,3411 .INTR => continue,
3412 .CHILD => return error.ChildExecFailed,3412 .CHILD => return error.ChildExecFailed,
...@@ -3418,7 +3418,7 @@ pub const PosixSpawn = struct {...@@ -3418,7 +3418,7 @@ pub const PosixSpawn = struct {
3418};3418};
34193419
3420pub fn getKernError(err: kern_return_t) KernE {3420pub fn getKernError(err: kern_return_t) KernE {
3421 return @enumFromInt(KernE, @truncate(u32, @intCast(usize, err)));3421 return @as(KernE, @enumFromInt(@as(u32, @truncate(@as(usize, @intCast(err))))));
3422}3422}
34233423
3424pub fn unexpectedKernError(err: KernE) std.os.UnexpectedError {3424pub fn unexpectedKernError(err: KernE) std.os.UnexpectedError {
...@@ -3585,9 +3585,9 @@ pub const MachTask = extern struct {...@@ -3585,9 +3585,9 @@ pub const MachTask = extern struct {
3585 .top => VM_REGION_TOP_INFO,3585 .top => VM_REGION_TOP_INFO,
3586 },3586 },
3587 switch (tag) {3587 switch (tag) {
3588 .basic => @ptrCast(vm_region_info_t, &info.info.basic),3588 .basic => @as(vm_region_info_t, @ptrCast(&info.info.basic)),
3589 .extended => @ptrCast(vm_region_info_t, &info.info.extended),3589 .extended => @as(vm_region_info_t, @ptrCast(&info.info.extended)),
3590 .top => @ptrCast(vm_region_info_t, &info.info.top),3590 .top => @as(vm_region_info_t, @ptrCast(&info.info.top)),
3591 },3591 },
3592 &count,3592 &count,
3593 &objname,3593 &objname,
...@@ -3640,8 +3640,8 @@ pub const MachTask = extern struct {...@@ -3640,8 +3640,8 @@ pub const MachTask = extern struct {
3640 &base_len,3640 &base_len,
3641 &nesting,3641 &nesting,
3642 switch (tag) {3642 switch (tag) {
3643 .short => @ptrCast(vm_region_recurse_info_t, &info.info.short),3643 .short => @as(vm_region_recurse_info_t, @ptrCast(&info.info.short)),
3644 .full => @ptrCast(vm_region_recurse_info_t, &info.info.full),3644 .full => @as(vm_region_recurse_info_t, @ptrCast(&info.info.full)),
3645 },3645 },
3646 &count,3646 &count,
3647 ))) {3647 ))) {
...@@ -3701,7 +3701,7 @@ pub const MachTask = extern struct {...@@ -3701,7 +3701,7 @@ pub const MachTask = extern struct {
3701 task.port,3701 task.port,
3702 curr_addr,3702 curr_addr,
3703 @intFromPtr(out_buf.ptr),3703 @intFromPtr(out_buf.ptr),
3704 @intCast(mach_msg_type_number_t, curr_size),3704 @as(mach_msg_type_number_t, @intCast(curr_size)),
3705 ))) {3705 ))) {
3706 .SUCCESS => {},3706 .SUCCESS => {},
3707 .FAILURE => return error.PermissionDenied,3707 .FAILURE => return error.PermissionDenied,
...@@ -3752,7 +3752,7 @@ pub const MachTask = extern struct {...@@ -3752,7 +3752,7 @@ pub const MachTask = extern struct {
3752 else => |err| return unexpectedKernError(err),3752 else => |err| return unexpectedKernError(err),
3753 }3753 }
37543754
3755 @memcpy(out_buf[0..curr_bytes_read], @ptrFromInt([*]const u8, vm_memory));3755 @memcpy(out_buf[0..curr_bytes_read], @as([*]const u8, @ptrFromInt(vm_memory)));
3756 _ = vm_deallocate(mach_task_self(), vm_memory, curr_bytes_read);3756 _ = vm_deallocate(mach_task_self(), vm_memory, curr_bytes_read);
37573757
3758 out_buf = out_buf[curr_bytes_read..];3758 out_buf = out_buf[curr_bytes_read..];
...@@ -3782,10 +3782,10 @@ pub const MachTask = extern struct {...@@ -3782,10 +3782,10 @@ pub const MachTask = extern struct {
3782 switch (getKernError(task_info(3782 switch (getKernError(task_info(
3783 task.port,3783 task.port,
3784 TASK_VM_INFO,3784 TASK_VM_INFO,
3785 @ptrCast(task_info_t, &vm_info),3785 @as(task_info_t, @ptrCast(&vm_info)),
3786 &info_count,3786 &info_count,
3787 ))) {3787 ))) {
3788 .SUCCESS => return @intCast(usize, vm_info.page_size),3788 .SUCCESS => return @as(usize, @intCast(vm_info.page_size)),
3789 else => {},3789 else => {},
3790 }3790 }
3791 }3791 }
...@@ -3802,7 +3802,7 @@ pub const MachTask = extern struct {...@@ -3802,7 +3802,7 @@ pub const MachTask = extern struct {
3802 switch (getKernError(task_info(3802 switch (getKernError(task_info(
3803 task.port,3803 task.port,
3804 MACH_TASK_BASIC_INFO,3804 MACH_TASK_BASIC_INFO,
3805 @ptrCast(task_info_t, &info),3805 @as(task_info_t, @ptrCast(&info)),
3806 &count,3806 &count,
3807 ))) {3807 ))) {
3808 .SUCCESS => return info,3808 .SUCCESS => return info,
...@@ -3832,7 +3832,7 @@ pub const MachTask = extern struct {...@@ -3832,7 +3832,7 @@ pub const MachTask = extern struct {
3832 _ = vm_deallocate(3832 _ = vm_deallocate(
3833 self_task.port,3833 self_task.port,
3834 @intFromPtr(list.buf.ptr),3834 @intFromPtr(list.buf.ptr),
3835 @intCast(vm_size_t, list.buf.len * @sizeOf(mach_port_t)),3835 @as(vm_size_t, @intCast(list.buf.len * @sizeOf(mach_port_t))),
3836 );3836 );
3837 }3837 }
3838 };3838 };
...@@ -3841,7 +3841,7 @@ pub const MachTask = extern struct {...@@ -3841,7 +3841,7 @@ pub const MachTask = extern struct {
3841 var thread_list: mach_port_array_t = undefined;3841 var thread_list: mach_port_array_t = undefined;
3842 var thread_count: mach_msg_type_number_t = undefined;3842 var thread_count: mach_msg_type_number_t = undefined;
3843 switch (getKernError(task_threads(task.port, &thread_list, &thread_count))) {3843 switch (getKernError(task_threads(task.port, &thread_list, &thread_count))) {
3844 .SUCCESS => return ThreadList{ .buf = @ptrCast([*]MachThread, thread_list)[0..thread_count] },3844 .SUCCESS => return ThreadList{ .buf = @as([*]MachThread, @ptrCast(thread_list))[0..thread_count] },
3845 else => |err| return unexpectedKernError(err),3845 else => |err| return unexpectedKernError(err),
3846 }3846 }
3847 }3847 }
...@@ -3860,7 +3860,7 @@ pub const MachThread = extern struct {...@@ -3860,7 +3860,7 @@ pub const MachThread = extern struct {
3860 switch (getKernError(thread_info(3860 switch (getKernError(thread_info(
3861 thread.port,3861 thread.port,
3862 THREAD_BASIC_INFO,3862 THREAD_BASIC_INFO,
3863 @ptrCast(thread_info_t, &info),3863 @as(thread_info_t, @ptrCast(&info)),
3864 &count,3864 &count,
3865 ))) {3865 ))) {
3866 .SUCCESS => return info,3866 .SUCCESS => return info,
...@@ -3874,7 +3874,7 @@ pub const MachThread = extern struct {...@@ -3874,7 +3874,7 @@ pub const MachThread = extern struct {
3874 switch (getKernError(thread_info(3874 switch (getKernError(thread_info(
3875 thread.port,3875 thread.port,
3876 THREAD_IDENTIFIER_INFO,3876 THREAD_IDENTIFIER_INFO,
3877 @ptrCast(thread_info_t, &info),3877 @as(thread_info_t, @ptrCast(&info)),
3878 &count,3878 &count,
3879 ))) {3879 ))) {
3880 .SUCCESS => return info,3880 .SUCCESS => return info,
...@@ -3962,7 +3962,7 @@ pub const thread_affinity_policy_t = [*]thread_affinity_policy;...@@ -3962,7 +3962,7 @@ pub const thread_affinity_policy_t = [*]thread_affinity_policy;
39623962
3963pub const THREAD_AFFINITY = struct {3963pub const THREAD_AFFINITY = struct {
3964 pub const POLICY = 0;3964 pub const POLICY = 0;
3965 pub const POLICY_COUNT = @intCast(mach_msg_type_number_t, @sizeOf(thread_affinity_policy_data_t) / @sizeOf(integer_t));3965 pub const POLICY_COUNT = @as(mach_msg_type_number_t, @intCast(@sizeOf(thread_affinity_policy_data_t) / @sizeOf(integer_t)));
3966};3966};
39673967
3968/// cpu affinity api3968/// cpu affinity api
...@@ -4041,7 +4041,7 @@ pub const host_preferred_user_arch_data_t = host_preferred_user_arch;...@@ -4041,7 +4041,7 @@ pub const host_preferred_user_arch_data_t = host_preferred_user_arch;
4041pub const host_preferred_user_arch_t = *host_preferred_user_arch;4041pub const host_preferred_user_arch_t = *host_preferred_user_arch;
40424042
4043fn HostCount(comptime HT: type) mach_msg_type_number_t {4043fn HostCount(comptime HT: type) mach_msg_type_number_t {
4044 return @intCast(mach_msg_type_number_t, @sizeOf(HT) / @sizeOf(integer_t));4044 return @as(mach_msg_type_number_t, @intCast(@sizeOf(HT) / @sizeOf(integer_t)));
4045}4045}
40464046
4047pub const HOST = struct {4047pub const HOST = struct {
lib/std/c/dragonfly.zig+10-10
...@@ -172,7 +172,7 @@ pub const PROT = struct {...@@ -172,7 +172,7 @@ pub const PROT = struct {
172172
173pub const MAP = struct {173pub const MAP = struct {
174 pub const FILE = 0;174 pub const FILE = 0;
175 pub const FAILED = @ptrFromInt(*anyopaque, maxInt(usize));175 pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
176 pub const ANONYMOUS = ANON;176 pub const ANONYMOUS = ANON;
177 pub const COPY = PRIVATE;177 pub const COPY = PRIVATE;
178 pub const SHARED = 1;178 pub const SHARED = 1;
...@@ -208,7 +208,7 @@ pub const W = struct {...@@ -208,7 +208,7 @@ pub const W = struct {
208 pub const TRAPPED = 0x0020;208 pub const TRAPPED = 0x0020;
209209
210 pub fn EXITSTATUS(s: u32) u8 {210 pub fn EXITSTATUS(s: u32) u8 {
211 return @intCast(u8, (s & 0xff00) >> 8);211 return @as(u8, @intCast((s & 0xff00) >> 8));
212 }212 }
213 pub fn TERMSIG(s: u32) u32 {213 pub fn TERMSIG(s: u32) u32 {
214 return s & 0x7f;214 return s & 0x7f;
...@@ -220,7 +220,7 @@ pub const W = struct {...@@ -220,7 +220,7 @@ pub const W = struct {
220 return TERMSIG(s) == 0;220 return TERMSIG(s) == 0;
221 }221 }
222 pub fn IFSTOPPED(s: u32) bool {222 pub fn IFSTOPPED(s: u32) bool {
223 return @truncate(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;223 return @as(u16, @truncate((((s & 0xffff) *% 0x10001) >> 8))) > 0x7f00;
224 }224 }
225 pub fn IFSIGNALED(s: u32) bool {225 pub fn IFSIGNALED(s: u32) bool {
226 return (s & 0xffff) -% 1 < 0xff;226 return (s & 0xffff) -% 1 < 0xff;
...@@ -620,9 +620,9 @@ pub const S = struct {...@@ -620,9 +620,9 @@ pub const S = struct {
620pub const BADSIG = SIG.ERR;620pub const BADSIG = SIG.ERR;
621621
622pub const SIG = struct {622pub const SIG = struct {
623 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);623 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
624 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);624 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
625 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));625 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
626626
627 pub const BLOCK = 1;627 pub const BLOCK = 1;
628 pub const UNBLOCK = 2;628 pub const UNBLOCK = 2;
...@@ -871,10 +871,10 @@ pub const RTLD = struct {...@@ -871,10 +871,10 @@ pub const RTLD = struct {
871 pub const NODELETE = 0x01000;871 pub const NODELETE = 0x01000;
872 pub const NOLOAD = 0x02000;872 pub const NOLOAD = 0x02000;
873873
874 pub const NEXT = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -1)));874 pub const NEXT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))));
875 pub const DEFAULT = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -2)));875 pub const DEFAULT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -2)))));
876 pub const SELF = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -3)));876 pub const SELF = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))));
877 pub const ALL = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -4)));877 pub const ALL = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -4)))));
878};878};
879879
880pub const dl_phdr_info = extern struct {880pub const dl_phdr_info = extern struct {
lib/std/c/freebsd.zig+11-11
...@@ -20,11 +20,11 @@ fn __BIT_COUNT(bits: []const c_long) c_long {...@@ -20,11 +20,11 @@ fn __BIT_COUNT(bits: []const c_long) c_long {
2020
21fn __BIT_MASK(s: usize) c_long {21fn __BIT_MASK(s: usize) c_long {
22 var x = s % CPU_SETSIZE;22 var x = s % CPU_SETSIZE;
23 return @bitCast(c_long, @intCast(c_ulong, 1) << @intCast(u6, x));23 return @as(c_long, @bitCast(@as(c_ulong, @intCast(1)) << @as(u6, @intCast(x))));
24}24}
2525
26pub fn CPU_COUNT(set: cpuset_t) c_int {26pub fn CPU_COUNT(set: cpuset_t) c_int {
27 return @intCast(c_int, __BIT_COUNT(set.__bits[0..]));27 return @as(c_int, @intCast(__BIT_COUNT(set.__bits[0..])));
28}28}
2929
30pub fn CPU_ZERO(set: *cpuset_t) void {30pub fn CPU_ZERO(set: *cpuset_t) void {
...@@ -529,7 +529,7 @@ pub const cap_rights_t = extern struct {...@@ -529,7 +529,7 @@ pub const cap_rights_t = extern struct {
529529
530pub const CAP = struct {530pub const CAP = struct {
531 pub fn RIGHT(idx: u6, bit: u64) u64 {531 pub fn RIGHT(idx: u6, bit: u64) u64 {
532 return (@intCast(u64, 1) << (57 + idx)) | bit;532 return (@as(u64, @intCast(1)) << (57 + idx)) | bit;
533 }533 }
534 pub const READ = CAP.RIGHT(0, 0x0000000000000001);534 pub const READ = CAP.RIGHT(0, 0x0000000000000001);
535 pub const WRITE = CAP.RIGHT(0, 0x0000000000000002);535 pub const WRITE = CAP.RIGHT(0, 0x0000000000000002);
...@@ -961,7 +961,7 @@ pub const CLOCK = struct {...@@ -961,7 +961,7 @@ pub const CLOCK = struct {
961};961};
962962
963pub const MAP = struct {963pub const MAP = struct {
964 pub const FAILED = @ptrFromInt(*anyopaque, maxInt(usize));964 pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
965 pub const SHARED = 0x0001;965 pub const SHARED = 0x0001;
966 pub const PRIVATE = 0x0002;966 pub const PRIVATE = 0x0002;
967 pub const FIXED = 0x0010;967 pub const FIXED = 0x0010;
...@@ -1013,7 +1013,7 @@ pub const W = struct {...@@ -1013,7 +1013,7 @@ pub const W = struct {
1013 pub const TRAPPED = 32;1013 pub const TRAPPED = 32;
10141014
1015 pub fn EXITSTATUS(s: u32) u8 {1015 pub fn EXITSTATUS(s: u32) u8 {
1016 return @intCast(u8, (s & 0xff00) >> 8);1016 return @as(u8, @intCast((s & 0xff00) >> 8));
1017 }1017 }
1018 pub fn TERMSIG(s: u32) u32 {1018 pub fn TERMSIG(s: u32) u32 {
1019 return s & 0x7f;1019 return s & 0x7f;
...@@ -1025,7 +1025,7 @@ pub const W = struct {...@@ -1025,7 +1025,7 @@ pub const W = struct {
1025 return TERMSIG(s) == 0;1025 return TERMSIG(s) == 0;
1026 }1026 }
1027 pub fn IFSTOPPED(s: u32) bool {1027 pub fn IFSTOPPED(s: u32) bool {
1028 return @truncate(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;1028 return @as(u16, @truncate((((s & 0xffff) *% 0x10001) >> 8))) > 0x7f00;
1029 }1029 }
1030 pub fn IFSIGNALED(s: u32) bool {1030 pub fn IFSIGNALED(s: u32) bool {
1031 return (s & 0xffff) -% 1 < 0xff;1031 return (s & 0xffff) -% 1 < 0xff;
...@@ -1086,9 +1086,9 @@ pub const SIG = struct {...@@ -1086,9 +1086,9 @@ pub const SIG = struct {
1086 pub const UNBLOCK = 2;1086 pub const UNBLOCK = 2;
1087 pub const SETMASK = 3;1087 pub const SETMASK = 3;
10881088
1089 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);1089 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
1090 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);1090 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
1091 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));1091 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
10921092
1093 pub const WORDS = 4;1093 pub const WORDS = 4;
1094 pub const MAXSIG = 128;1094 pub const MAXSIG = 128;
...@@ -2626,7 +2626,7 @@ pub const domainset_t = extern struct {...@@ -2626,7 +2626,7 @@ pub const domainset_t = extern struct {
2626};2626};
26272627
2628pub fn DOMAINSET_COUNT(set: domainset_t) c_int {2628pub fn DOMAINSET_COUNT(set: domainset_t) c_int {
2629 return @intCast(c_int, __BIT_COUNT(set.__bits[0..]));2629 return @as(c_int, @intCast(__BIT_COUNT(set.__bits[0..])));
2630}2630}
26312631
2632pub const domainset = extern struct {2632pub const domainset = extern struct {
...@@ -2650,7 +2650,7 @@ const ioctl_cmd = enum(u32) {...@@ -2650,7 +2650,7 @@ const ioctl_cmd = enum(u32) {
2650};2650};
26512651
2652fn ioImpl(cmd: ioctl_cmd, op: u8, nr: u8, comptime IT: type) u32 {2652fn ioImpl(cmd: ioctl_cmd, op: u8, nr: u8, comptime IT: type) u32 {
2653 return @bitCast(u32, @intFromEnum(cmd) | @intCast(u32, @truncate(u8, @sizeOf(IT))) << 16 | @intCast(u32, op) << 8 | nr);2653 return @as(u32, @bitCast(@intFromEnum(cmd) | @as(u32, @intCast(@as(u8, @truncate(@sizeOf(IT))))) << 16 | @as(u32, @intCast(op)) << 8 | nr));
2654}2654}
26552655
2656pub fn IO(op: u8, nr: u8) u32 {2656pub fn IO(op: u8, nr: u8) u32 {
lib/std/c/haiku.zig+5-5
...@@ -414,7 +414,7 @@ pub const CLOCK = struct {...@@ -414,7 +414,7 @@ pub const CLOCK = struct {
414414
415pub const MAP = struct {415pub const MAP = struct {
416 /// mmap() error return code416 /// mmap() error return code
417 pub const FAILED = @ptrFromInt(*anyopaque, maxInt(usize));417 pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
418 /// changes are seen by others418 /// changes are seen by others
419 pub const SHARED = 0x01;419 pub const SHARED = 0x01;
420 /// changes are only seen by caller420 /// changes are only seen by caller
...@@ -443,7 +443,7 @@ pub const W = struct {...@@ -443,7 +443,7 @@ pub const W = struct {
443 pub const NOWAIT = 0x20;443 pub const NOWAIT = 0x20;
444444
445 pub fn EXITSTATUS(s: u32) u8 {445 pub fn EXITSTATUS(s: u32) u8 {
446 return @intCast(u8, s & 0xff);446 return @as(u8, @intCast(s & 0xff));
447 }447 }
448448
449 pub fn TERMSIG(s: u32) u32 {449 pub fn TERMSIG(s: u32) u32 {
...@@ -481,9 +481,9 @@ pub const SA = struct {...@@ -481,9 +481,9 @@ pub const SA = struct {
481};481};
482482
483pub const SIG = struct {483pub const SIG = struct {
484 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));484 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
485 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);485 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
486 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);486 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
487487
488 pub const HUP = 1;488 pub const HUP = 1;
489 pub const INT = 2;489 pub const INT = 2;
lib/std/c/linux.zig+1-1
...@@ -32,7 +32,7 @@ pub const MADV = linux.MADV;...@@ -32,7 +32,7 @@ pub const MADV = linux.MADV;
32pub const MAP = struct {32pub const MAP = struct {
33 pub usingnamespace linux.MAP;33 pub usingnamespace linux.MAP;
34 /// Only used by libc to communicate failure.34 /// Only used by libc to communicate failure.
35 pub const FAILED = @ptrFromInt(*anyopaque, maxInt(usize));35 pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
36};36};
37pub const MSF = linux.MSF;37pub const MSF = linux.MSF;
38pub const MMAP2_UNIT = linux.MMAP2_UNIT;38pub const MMAP2_UNIT = linux.MMAP2_UNIT;
lib/std/c/netbsd.zig+8-8
...@@ -172,9 +172,9 @@ pub const RTLD = struct {...@@ -172,9 +172,9 @@ pub const RTLD = struct {
172 pub const NODELETE = 0x01000;172 pub const NODELETE = 0x01000;
173 pub const NOLOAD = 0x02000;173 pub const NOLOAD = 0x02000;
174174
175 pub const NEXT = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -1)));175 pub const NEXT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))));
176 pub const DEFAULT = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -2)));176 pub const DEFAULT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -2)))));
177 pub const SELF = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -3)));177 pub const SELF = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))));
178};178};
179179
180pub const dl_phdr_info = extern struct {180pub const dl_phdr_info = extern struct {
...@@ -597,7 +597,7 @@ pub const CLOCK = struct {...@@ -597,7 +597,7 @@ pub const CLOCK = struct {
597};597};
598598
599pub const MAP = struct {599pub const MAP = struct {
600 pub const FAILED = @ptrFromInt(*anyopaque, maxInt(usize));600 pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
601 pub const SHARED = 0x0001;601 pub const SHARED = 0x0001;
602 pub const PRIVATE = 0x0002;602 pub const PRIVATE = 0x0002;
603 pub const REMAPDUP = 0x0004;603 pub const REMAPDUP = 0x0004;
...@@ -653,7 +653,7 @@ pub const W = struct {...@@ -653,7 +653,7 @@ pub const W = struct {
653 pub const TRAPPED = 0x00000040;653 pub const TRAPPED = 0x00000040;
654654
655 pub fn EXITSTATUS(s: u32) u8 {655 pub fn EXITSTATUS(s: u32) u8 {
656 return @intCast(u8, (s >> 8) & 0xff);656 return @as(u8, @intCast((s >> 8) & 0xff));
657 }657 }
658 pub fn TERMSIG(s: u32) u32 {658 pub fn TERMSIG(s: u32) u32 {
659 return s & 0x7f;659 return s & 0x7f;
...@@ -1106,9 +1106,9 @@ pub const winsize = extern struct {...@@ -1106,9 +1106,9 @@ pub const winsize = extern struct {
1106const NSIG = 32;1106const NSIG = 32;
11071107
1108pub const SIG = struct {1108pub const SIG = struct {
1109 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);1109 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
1110 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);1110 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
1111 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));1111 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
11121112
1113 pub const WORDS = 4;1113 pub const WORDS = 4;
1114 pub const MAXSIG = 128;1114 pub const MAXSIG = 128;
lib/std/c/openbsd.zig+7-7
...@@ -449,7 +449,7 @@ pub const CLOCK = struct {...@@ -449,7 +449,7 @@ pub const CLOCK = struct {
449};449};
450450
451pub const MAP = struct {451pub const MAP = struct {
452 pub const FAILED = @ptrFromInt(*anyopaque, maxInt(usize));452 pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
453 pub const SHARED = 0x0001;453 pub const SHARED = 0x0001;
454 pub const PRIVATE = 0x0002;454 pub const PRIVATE = 0x0002;
455 pub const FIXED = 0x0010;455 pub const FIXED = 0x0010;
...@@ -488,7 +488,7 @@ pub const W = struct {...@@ -488,7 +488,7 @@ pub const W = struct {
488 pub const CONTINUED = 8;488 pub const CONTINUED = 8;
489489
490 pub fn EXITSTATUS(s: u32) u8 {490 pub fn EXITSTATUS(s: u32) u8 {
491 return @intCast(u8, (s >> 8) & 0xff);491 return @as(u8, @intCast((s >> 8) & 0xff));
492 }492 }
493 pub fn TERMSIG(s: u32) u32 {493 pub fn TERMSIG(s: u32) u32 {
494 return (s & 0x7f);494 return (s & 0x7f);
...@@ -1000,11 +1000,11 @@ pub const winsize = extern struct {...@@ -1000,11 +1000,11 @@ pub const winsize = extern struct {
1000const NSIG = 33;1000const NSIG = 33;
10011001
1002pub const SIG = struct {1002pub const SIG = struct {
1003 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);1003 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
1004 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);1004 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
1005 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));1005 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
1006 pub const CATCH = @ptrFromInt(?Sigaction.handler_fn, 2);1006 pub const CATCH = @as(?Sigaction.handler_fn, @ptrFromInt(2));
1007 pub const HOLD = @ptrFromInt(?Sigaction.handler_fn, 3);1007 pub const HOLD = @as(?Sigaction.handler_fn, @ptrFromInt(3));
10081008
1009 pub const HUP = 1;1009 pub const HUP = 1;
1010 pub const INT = 2;1010 pub const INT = 2;
lib/std/c/solaris.zig+14-14
...@@ -111,10 +111,10 @@ pub const RTLD = struct {...@@ -111,10 +111,10 @@ pub const RTLD = struct {
111 pub const FIRST = 0x02000;111 pub const FIRST = 0x02000;
112 pub const CONFGEN = 0x10000;112 pub const CONFGEN = 0x10000;
113113
114 pub const NEXT = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -1)));114 pub const NEXT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))));
115 pub const DEFAULT = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -2)));115 pub const DEFAULT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -2)))));
116 pub const SELF = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -3)));116 pub const SELF = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))));
117 pub const PROBE = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -4)));117 pub const PROBE = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -4)))));
118};118};
119119
120pub const Flock = extern struct {120pub const Flock = extern struct {
...@@ -524,7 +524,7 @@ pub const CLOCK = struct {...@@ -524,7 +524,7 @@ pub const CLOCK = struct {
524};524};
525525
526pub const MAP = struct {526pub const MAP = struct {
527 pub const FAILED = @ptrFromInt(*anyopaque, maxInt(usize));527 pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
528 pub const SHARED = 0x0001;528 pub const SHARED = 0x0001;
529 pub const PRIVATE = 0x0002;529 pub const PRIVATE = 0x0002;
530 pub const TYPE = 0x000f;530 pub const TYPE = 0x000f;
...@@ -583,7 +583,7 @@ pub const W = struct {...@@ -583,7 +583,7 @@ pub const W = struct {
583 pub const NOWAIT = 0o200;583 pub const NOWAIT = 0o200;
584584
585 pub fn EXITSTATUS(s: u32) u8 {585 pub fn EXITSTATUS(s: u32) u8 {
586 return @intCast(u8, (s >> 8) & 0xff);586 return @as(u8, @intCast((s >> 8) & 0xff));
587 }587 }
588 pub fn TERMSIG(s: u32) u32 {588 pub fn TERMSIG(s: u32) u32 {
589 return s & 0x7f;589 return s & 0x7f;
...@@ -886,10 +886,10 @@ pub const winsize = extern struct {...@@ -886,10 +886,10 @@ pub const winsize = extern struct {
886const NSIG = 75;886const NSIG = 75;
887887
888pub const SIG = struct {888pub const SIG = struct {
889 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);889 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
890 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));890 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
891 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);891 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
892 pub const HOLD = @ptrFromInt(?Sigaction.handler_fn, 2);892 pub const HOLD = @as(?Sigaction.handler_fn, @ptrFromInt(2));
893893
894 pub const WORDS = 4;894 pub const WORDS = 4;
895 pub const MAXSIG = 75;895 pub const MAXSIG = 75;
...@@ -1441,7 +1441,7 @@ pub const AT = struct {...@@ -1441,7 +1441,7 @@ pub const AT = struct {
1441 /// Magic value that specify the use of the current working directory1441 /// Magic value that specify the use of the current working directory
1442 /// to determine the target of relative file paths in the openat() and1442 /// to determine the target of relative file paths in the openat() and
1443 /// similar syscalls.1443 /// similar syscalls.
1444 pub const FDCWD = @bitCast(fd_t, @as(u32, 0xffd19553));1444 pub const FDCWD = @as(fd_t, @bitCast(@as(u32, 0xffd19553)));
14451445
1446 /// Do not follow symbolic links1446 /// Do not follow symbolic links
1447 pub const SYMLINK_NOFOLLOW = 0x1000;1447 pub const SYMLINK_NOFOLLOW = 0x1000;
...@@ -1907,9 +1907,9 @@ const IoCtlCommand = enum(u32) {...@@ -1907,9 +1907,9 @@ const IoCtlCommand = enum(u32) {
1907};1907};
19081908
1909fn ioImpl(cmd: IoCtlCommand, io_type: u8, nr: u8, comptime IOT: type) i32 {1909fn ioImpl(cmd: IoCtlCommand, io_type: u8, nr: u8, comptime IOT: type) i32 {
1910 const size = @intCast(u32, @truncate(u8, @sizeOf(IOT))) << 16;1910 const size = @as(u32, @intCast(@as(u8, @truncate(@sizeOf(IOT))))) << 16;
1911 const t = @intCast(u32, io_type) << 8;1911 const t = @as(u32, @intCast(io_type)) << 8;
1912 return @bitCast(i32, @intFromEnum(cmd) | size | t | nr);1912 return @as(i32, @bitCast(@intFromEnum(cmd) | size | t | nr));
1913}1913}
19141914
1915pub fn IO(io_type: u8, nr: u8) i32 {1915pub fn IO(io_type: u8, nr: u8) i32 {
lib/std/child_process.zig+13-13
...@@ -93,7 +93,7 @@ pub const ChildProcess = struct {...@@ -93,7 +93,7 @@ pub const ChildProcess = struct {
93 switch (builtin.os.tag) {93 switch (builtin.os.tag) {
94 .linux => {94 .linux => {
95 if (rus.rusage) |ru| {95 if (rus.rusage) |ru| {
96 return @intCast(usize, ru.maxrss) * 1024;96 return @as(usize, @intCast(ru.maxrss)) * 1024;
97 } else {97 } else {
98 return null;98 return null;
99 }99 }
...@@ -108,7 +108,7 @@ pub const ChildProcess = struct {...@@ -108,7 +108,7 @@ pub const ChildProcess = struct {
108 .macos, .ios => {108 .macos, .ios => {
109 if (rus.rusage) |ru| {109 if (rus.rusage) |ru| {
110 // Darwin oddly reports in bytes instead of kilobytes.110 // Darwin oddly reports in bytes instead of kilobytes.
111 return @intCast(usize, ru.maxrss);111 return @as(usize, @intCast(ru.maxrss));
112 } else {112 } else {
113 return null;113 return null;
114 }114 }
...@@ -376,7 +376,7 @@ pub const ChildProcess = struct {...@@ -376,7 +376,7 @@ pub const ChildProcess = struct {
376 if (windows.kernel32.GetExitCodeProcess(self.id, &exit_code) == 0) {376 if (windows.kernel32.GetExitCodeProcess(self.id, &exit_code) == 0) {
377 break :x Term{ .Unknown = 0 };377 break :x Term{ .Unknown = 0 };
378 } else {378 } else {
379 break :x Term{ .Exited = @truncate(u8, exit_code) };379 break :x Term{ .Exited = @as(u8, @truncate(exit_code)) };
380 }380 }
381 });381 });
382382
...@@ -449,7 +449,7 @@ pub const ChildProcess = struct {...@@ -449,7 +449,7 @@ pub const ChildProcess = struct {
449 // has a value greater than 0449 // has a value greater than 0
450 if ((fd[0].revents & std.os.POLL.IN) != 0) {450 if ((fd[0].revents & std.os.POLL.IN) != 0) {
451 const err_int = try readIntFd(err_pipe[0]);451 const err_int = try readIntFd(err_pipe[0]);
452 return @errSetCast(SpawnError, @errorFromInt(err_int));452 return @as(SpawnError, @errSetCast(@errorFromInt(err_int)));
453 }453 }
454 } else {454 } else {
455 // Write maxInt(ErrInt) to the write end of the err_pipe. This is after455 // Write maxInt(ErrInt) to the write end of the err_pipe. This is after
...@@ -462,7 +462,7 @@ pub const ChildProcess = struct {...@@ -462,7 +462,7 @@ pub const ChildProcess = struct {
462 // Here we potentially return the fork child's error from the parent462 // Here we potentially return the fork child's error from the parent
463 // pid.463 // pid.
464 if (err_int != maxInt(ErrInt)) {464 if (err_int != maxInt(ErrInt)) {
465 return @errSetCast(SpawnError, @errorFromInt(err_int));465 return @as(SpawnError, @errSetCast(@errorFromInt(err_int)));
466 }466 }
467 }467 }
468 }468 }
...@@ -542,7 +542,7 @@ pub const ChildProcess = struct {...@@ -542,7 +542,7 @@ pub const ChildProcess = struct {
542 } else if (builtin.output_mode == .Exe) {542 } else if (builtin.output_mode == .Exe) {
543 // Then we have Zig start code and this works.543 // Then we have Zig start code and this works.
544 // TODO type-safety for null-termination of `os.environ`.544 // TODO type-safety for null-termination of `os.environ`.
545 break :m @ptrCast([*:null]const ?[*:0]const u8, os.environ.ptr);545 break :m @as([*:null]const ?[*:0]const u8, @ptrCast(os.environ.ptr));
546 } else {546 } else {
547 // TODO come up with a solution for this.547 // TODO come up with a solution for this.
548 @compileError("missing std lib enhancement: ChildProcess implementation has no way to collect the environment variables to forward to the child process");548 @compileError("missing std lib enhancement: ChildProcess implementation has no way to collect the environment variables to forward to the child process");
...@@ -605,7 +605,7 @@ pub const ChildProcess = struct {...@@ -605,7 +605,7 @@ pub const ChildProcess = struct {
605 }605 }
606606
607 // we are the parent607 // we are the parent
608 const pid = @intCast(i32, pid_result);608 const pid = @as(i32, @intCast(pid_result));
609 if (self.stdin_behavior == StdIo.Pipe) {609 if (self.stdin_behavior == StdIo.Pipe) {
610 self.stdin = File{ .handle = stdin_pipe[1] };610 self.stdin = File{ .handle = stdin_pipe[1] };
611 } else {611 } else {
...@@ -1015,11 +1015,11 @@ fn windowsCreateProcessPathExt(...@@ -1015,11 +1015,11 @@ fn windowsCreateProcessPathExt(
1015 else => return windows.unexpectedStatus(rc),1015 else => return windows.unexpectedStatus(rc),
1016 }1016 }
10171017
1018 const dir_info = @ptrCast(*windows.FILE_DIRECTORY_INFORMATION, &file_information_buf);1018 const dir_info = @as(*windows.FILE_DIRECTORY_INFORMATION, @ptrCast(&file_information_buf));
1019 if (dir_info.FileAttributes & windows.FILE_ATTRIBUTE_DIRECTORY != 0) {1019 if (dir_info.FileAttributes & windows.FILE_ATTRIBUTE_DIRECTORY != 0) {
1020 break :found_name null;1020 break :found_name null;
1021 }1021 }
1022 break :found_name @ptrCast([*]u16, &dir_info.FileName)[0 .. dir_info.FileNameLength / 2];1022 break :found_name @as([*]u16, @ptrCast(&dir_info.FileName))[0 .. dir_info.FileNameLength / 2];
1023 };1023 };
10241024
1025 const unappended_err = unappended: {1025 const unappended_err = unappended: {
...@@ -1104,7 +1104,7 @@ fn windowsCreateProcessPathExt(...@@ -1104,7 +1104,7 @@ fn windowsCreateProcessPathExt(
1104 else => return windows.unexpectedStatus(rc),1104 else => return windows.unexpectedStatus(rc),
1105 }1105 }
11061106
1107 const dir_info = @ptrCast(*windows.FILE_DIRECTORY_INFORMATION, &file_information_buf);1107 const dir_info = @as(*windows.FILE_DIRECTORY_INFORMATION, @ptrCast(&file_information_buf));
1108 // Skip directories1108 // Skip directories
1109 if (dir_info.FileAttributes & windows.FILE_ATTRIBUTE_DIRECTORY != 0) continue;1109 if (dir_info.FileAttributes & windows.FILE_ATTRIBUTE_DIRECTORY != 0) continue;
11101110
...@@ -1164,7 +1164,7 @@ fn windowsCreateProcess(app_name: [*:0]u16, cmd_line: [*:0]u16, envp_ptr: ?[*]u1...@@ -1164,7 +1164,7 @@ fn windowsCreateProcess(app_name: [*:0]u16, cmd_line: [*:0]u16, envp_ptr: ?[*]u1
1164 null,1164 null,
1165 windows.TRUE,1165 windows.TRUE,
1166 windows.CREATE_UNICODE_ENVIRONMENT,1166 windows.CREATE_UNICODE_ENVIRONMENT,
1167 @ptrCast(?*anyopaque, envp_ptr),1167 @as(?*anyopaque, @ptrCast(envp_ptr)),
1168 cwd_ptr,1168 cwd_ptr,
1169 lpStartupInfo,1169 lpStartupInfo,
1170 lpProcessInformation,1170 lpProcessInformation,
...@@ -1376,7 +1376,7 @@ fn writeIntFd(fd: i32, value: ErrInt) !void {...@@ -1376,7 +1376,7 @@ fn writeIntFd(fd: i32, value: ErrInt) !void {
1376 .capable_io_mode = .blocking,1376 .capable_io_mode = .blocking,
1377 .intended_io_mode = .blocking,1377 .intended_io_mode = .blocking,
1378 };1378 };
1379 file.writer().writeIntNative(u64, @intCast(u64, value)) catch return error.SystemResources;1379 file.writer().writeIntNative(u64, @as(u64, @intCast(value))) catch return error.SystemResources;
1380}1380}
13811381
1382fn readIntFd(fd: i32) !ErrInt {1382fn readIntFd(fd: i32) !ErrInt {
...@@ -1385,7 +1385,7 @@ fn readIntFd(fd: i32) !ErrInt {...@@ -1385,7 +1385,7 @@ fn readIntFd(fd: i32) !ErrInt {
1385 .capable_io_mode = .blocking,1385 .capable_io_mode = .blocking,
1386 .intended_io_mode = .blocking,1386 .intended_io_mode = .blocking,
1387 };1387 };
1388 return @intCast(ErrInt, file.reader().readIntNative(u64) catch return error.SystemResources);1388 return @as(ErrInt, @intCast(file.reader().readIntNative(u64) catch return error.SystemResources));
1389}1389}
13901390
1391/// Caller must free result.1391/// Caller must free result.
lib/std/coff.zig+16-16
...@@ -457,12 +457,12 @@ pub const ImportLookupEntry32 = struct {...@@ -457,12 +457,12 @@ pub const ImportLookupEntry32 = struct {
457457
458 pub fn getImportByName(raw: u32) ?ByName {458 pub fn getImportByName(raw: u32) ?ByName {
459 if (mask & raw != 0) return null;459 if (mask & raw != 0) return null;
460 return @bitCast(ByName, raw);460 return @as(ByName, @bitCast(raw));
461 }461 }
462462
463 pub fn getImportByOrdinal(raw: u32) ?ByOrdinal {463 pub fn getImportByOrdinal(raw: u32) ?ByOrdinal {
464 if (mask & raw == 0) return null;464 if (mask & raw == 0) return null;
465 return @bitCast(ByOrdinal, raw);465 return @as(ByOrdinal, @bitCast(raw));
466 }466 }
467};467};
468468
...@@ -483,12 +483,12 @@ pub const ImportLookupEntry64 = struct {...@@ -483,12 +483,12 @@ pub const ImportLookupEntry64 = struct {
483483
484 pub fn getImportByName(raw: u64) ?ByName {484 pub fn getImportByName(raw: u64) ?ByName {
485 if (mask & raw != 0) return null;485 if (mask & raw != 0) return null;
486 return @bitCast(ByName, raw);486 return @as(ByName, @bitCast(raw));
487 }487 }
488488
489 pub fn getImportByOrdinal(raw: u64) ?ByOrdinal {489 pub fn getImportByOrdinal(raw: u64) ?ByOrdinal {
490 if (mask & raw == 0) return null;490 if (mask & raw == 0) return null;
491 return @bitCast(ByOrdinal, raw);491 return @as(ByOrdinal, @bitCast(raw));
492 }492 }
493};493};
494494
...@@ -1146,25 +1146,25 @@ pub const Coff = struct {...@@ -1146,25 +1146,25 @@ pub const Coff = struct {
1146 }1146 }
11471147
1148 pub fn getCoffHeader(self: Coff) CoffHeader {1148 pub fn getCoffHeader(self: Coff) CoffHeader {
1149 return @ptrCast(*align(1) const CoffHeader, self.data[self.coff_header_offset..][0..@sizeOf(CoffHeader)]).*;1149 return @as(*align(1) const CoffHeader, @ptrCast(self.data[self.coff_header_offset..][0..@sizeOf(CoffHeader)])).*;
1150 }1150 }
11511151
1152 pub fn getOptionalHeader(self: Coff) OptionalHeader {1152 pub fn getOptionalHeader(self: Coff) OptionalHeader {
1153 assert(self.is_image);1153 assert(self.is_image);
1154 const offset = self.coff_header_offset + @sizeOf(CoffHeader);1154 const offset = self.coff_header_offset + @sizeOf(CoffHeader);
1155 return @ptrCast(*align(1) const OptionalHeader, self.data[offset..][0..@sizeOf(OptionalHeader)]).*;1155 return @as(*align(1) const OptionalHeader, @ptrCast(self.data[offset..][0..@sizeOf(OptionalHeader)])).*;
1156 }1156 }
11571157
1158 pub fn getOptionalHeader32(self: Coff) OptionalHeaderPE32 {1158 pub fn getOptionalHeader32(self: Coff) OptionalHeaderPE32 {
1159 assert(self.is_image);1159 assert(self.is_image);
1160 const offset = self.coff_header_offset + @sizeOf(CoffHeader);1160 const offset = self.coff_header_offset + @sizeOf(CoffHeader);
1161 return @ptrCast(*align(1) const OptionalHeaderPE32, self.data[offset..][0..@sizeOf(OptionalHeaderPE32)]).*;1161 return @as(*align(1) const OptionalHeaderPE32, @ptrCast(self.data[offset..][0..@sizeOf(OptionalHeaderPE32)])).*;
1162 }1162 }
11631163
1164 pub fn getOptionalHeader64(self: Coff) OptionalHeaderPE64 {1164 pub fn getOptionalHeader64(self: Coff) OptionalHeaderPE64 {
1165 assert(self.is_image);1165 assert(self.is_image);
1166 const offset = self.coff_header_offset + @sizeOf(CoffHeader);1166 const offset = self.coff_header_offset + @sizeOf(CoffHeader);
1167 return @ptrCast(*align(1) const OptionalHeaderPE64, self.data[offset..][0..@sizeOf(OptionalHeaderPE64)]).*;1167 return @as(*align(1) const OptionalHeaderPE64, @ptrCast(self.data[offset..][0..@sizeOf(OptionalHeaderPE64)])).*;
1168 }1168 }
11691169
1170 pub fn getImageBase(self: Coff) u64 {1170 pub fn getImageBase(self: Coff) u64 {
...@@ -1193,7 +1193,7 @@ pub const Coff = struct {...@@ -1193,7 +1193,7 @@ pub const Coff = struct {
1193 else => unreachable, // We assume we have validated the header already1193 else => unreachable, // We assume we have validated the header already
1194 };1194 };
1195 const offset = self.coff_header_offset + @sizeOf(CoffHeader) + size;1195 const offset = self.coff_header_offset + @sizeOf(CoffHeader) + size;
1196 return @ptrCast([*]align(1) const ImageDataDirectory, self.data[offset..])[0..self.getNumberOfDataDirectories()];1196 return @as([*]align(1) const ImageDataDirectory, @ptrCast(self.data[offset..]))[0..self.getNumberOfDataDirectories()];
1197 }1197 }
11981198
1199 pub fn getSymtab(self: *const Coff) ?Symtab {1199 pub fn getSymtab(self: *const Coff) ?Symtab {
...@@ -1217,7 +1217,7 @@ pub const Coff = struct {...@@ -1217,7 +1217,7 @@ pub const Coff = struct {
1217 pub fn getSectionHeaders(self: *const Coff) []align(1) const SectionHeader {1217 pub fn getSectionHeaders(self: *const Coff) []align(1) const SectionHeader {
1218 const coff_header = self.getCoffHeader();1218 const coff_header = self.getCoffHeader();
1219 const offset = self.coff_header_offset + @sizeOf(CoffHeader) + coff_header.size_of_optional_header;1219 const offset = self.coff_header_offset + @sizeOf(CoffHeader) + coff_header.size_of_optional_header;
1220 return @ptrCast([*]align(1) const SectionHeader, self.data.ptr + offset)[0..coff_header.number_of_sections];1220 return @as([*]align(1) const SectionHeader, @ptrCast(self.data.ptr + offset))[0..coff_header.number_of_sections];
1221 }1221 }
12221222
1223 pub fn getSectionHeadersAlloc(self: *const Coff, allocator: mem.Allocator) ![]SectionHeader {1223 pub fn getSectionHeadersAlloc(self: *const Coff, allocator: mem.Allocator) ![]SectionHeader {
...@@ -1303,9 +1303,9 @@ pub const Symtab = struct {...@@ -1303,9 +1303,9 @@ pub const Symtab = struct {
1303 return .{1303 return .{
1304 .name = raw[0..8].*,1304 .name = raw[0..8].*,
1305 .value = mem.readIntLittle(u32, raw[8..12]),1305 .value = mem.readIntLittle(u32, raw[8..12]),
1306 .section_number = @enumFromInt(SectionNumber, mem.readIntLittle(u16, raw[12..14])),1306 .section_number = @as(SectionNumber, @enumFromInt(mem.readIntLittle(u16, raw[12..14]))),
1307 .type = @bitCast(SymType, mem.readIntLittle(u16, raw[14..16])),1307 .type = @as(SymType, @bitCast(mem.readIntLittle(u16, raw[14..16]))),
1308 .storage_class = @enumFromInt(StorageClass, raw[16]),1308 .storage_class = @as(StorageClass, @enumFromInt(raw[16])),
1309 .number_of_aux_symbols = raw[17],1309 .number_of_aux_symbols = raw[17],
1310 };1310 };
1311 }1311 }
...@@ -1333,7 +1333,7 @@ pub const Symtab = struct {...@@ -1333,7 +1333,7 @@ pub const Symtab = struct {
1333 fn asWeakExtDef(raw: []const u8) WeakExternalDefinition {1333 fn asWeakExtDef(raw: []const u8) WeakExternalDefinition {
1334 return .{1334 return .{
1335 .tag_index = mem.readIntLittle(u32, raw[0..4]),1335 .tag_index = mem.readIntLittle(u32, raw[0..4]),
1336 .flag = @enumFromInt(WeakExternalFlag, mem.readIntLittle(u32, raw[4..8])),1336 .flag = @as(WeakExternalFlag, @enumFromInt(mem.readIntLittle(u32, raw[4..8]))),
1337 .unused = raw[8..18].*,1337 .unused = raw[8..18].*,
1338 };1338 };
1339 }1339 }
...@@ -1351,7 +1351,7 @@ pub const Symtab = struct {...@@ -1351,7 +1351,7 @@ pub const Symtab = struct {
1351 .number_of_linenumbers = mem.readIntLittle(u16, raw[6..8]),1351 .number_of_linenumbers = mem.readIntLittle(u16, raw[6..8]),
1352 .checksum = mem.readIntLittle(u32, raw[8..12]),1352 .checksum = mem.readIntLittle(u32, raw[8..12]),
1353 .number = mem.readIntLittle(u16, raw[12..14]),1353 .number = mem.readIntLittle(u16, raw[12..14]),
1354 .selection = @enumFromInt(ComdatSelection, raw[14]),1354 .selection = @as(ComdatSelection, @enumFromInt(raw[14])),
1355 .unused = raw[15..18].*,1355 .unused = raw[15..18].*,
1356 };1356 };
1357 }1357 }
...@@ -1384,6 +1384,6 @@ pub const Strtab = struct {...@@ -1384,6 +1384,6 @@ pub const Strtab = struct {
13841384
1385 pub fn get(self: Strtab, off: u32) []const u8 {1385 pub fn get(self: Strtab, off: u32) []const u8 {
1386 assert(off < self.buffer.len);1386 assert(off < self.buffer.len);
1387 return mem.sliceTo(@ptrCast([*:0]const u8, self.buffer.ptr + off), 0);1387 return mem.sliceTo(@as([*:0]const u8, @ptrCast(self.buffer.ptr + off)), 0);
1388 }1388 }
1389};1389};
lib/std/compress/deflate/bits_utils.zig+1-1
...@@ -3,7 +3,7 @@ const math = @import("std").math;...@@ -3,7 +3,7 @@ const math = @import("std").math;
3// Reverse bit-by-bit a N-bit code.3// Reverse bit-by-bit a N-bit code.
4pub fn bitReverse(comptime T: type, value: T, N: usize) T {4pub fn bitReverse(comptime T: type, value: T, N: usize) T {
5 const r = @bitReverse(value);5 const r = @bitReverse(value);
6 return r >> @intCast(math.Log2Int(T), @typeInfo(T).Int.bits - N);6 return r >> @as(math.Log2Int(T), @intCast(@typeInfo(T).Int.bits - N));
7}7}
88
9test "bitReverse" {9test "bitReverse" {
lib/std/compress/deflate/compressor.zig+19-19
...@@ -160,7 +160,7 @@ fn matchLen(a: []u8, b: []u8, max: u32) u32 {...@@ -160,7 +160,7 @@ fn matchLen(a: []u8, b: []u8, max: u32) u32 {
160 var bounded_b = b[0..max];160 var bounded_b = b[0..max];
161 for (bounded_a, 0..) |av, i| {161 for (bounded_a, 0..) |av, i| {
162 if (bounded_b[i] != av) {162 if (bounded_b[i] != av) {
163 return @intCast(u32, i);163 return @as(u32, @intCast(i));
164 }164 }
165 }165 }
166 return max;166 return max;
...@@ -313,14 +313,14 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -313,14 +313,14 @@ pub fn Compressor(comptime WriterType: anytype) type {
313 // the entire table onto the stack (https://golang.org/issue/18625).313 // the entire table onto the stack (https://golang.org/issue/18625).
314 for (self.hash_prev, 0..) |v, i| {314 for (self.hash_prev, 0..) |v, i| {
315 if (v > delta) {315 if (v > delta) {
316 self.hash_prev[i] = @intCast(u32, v - delta);316 self.hash_prev[i] = @as(u32, @intCast(v - delta));
317 } else {317 } else {
318 self.hash_prev[i] = 0;318 self.hash_prev[i] = 0;
319 }319 }
320 }320 }
321 for (self.hash_head, 0..) |v, i| {321 for (self.hash_head, 0..) |v, i| {
322 if (v > delta) {322 if (v > delta) {
323 self.hash_head[i] = @intCast(u32, v - delta);323 self.hash_head[i] = @as(u32, @intCast(v - delta));
324 } else {324 } else {
325 self.hash_head[i] = 0;325 self.hash_head[i] = 0;
326 }326 }
...@@ -329,7 +329,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -329,7 +329,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
329 }329 }
330 const n = std.compress.deflate.copy(self.window[self.window_end..], b);330 const n = std.compress.deflate.copy(self.window[self.window_end..], b);
331 self.window_end += n;331 self.window_end += n;
332 return @intCast(u32, n);332 return @as(u32, @intCast(n));
333 }333 }
334334
335 fn writeBlock(self: *Self, tokens: []token.Token, index: usize) !void {335 fn writeBlock(self: *Self, tokens: []token.Token, index: usize) !void {
...@@ -398,13 +398,13 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -398,13 +398,13 @@ pub fn Compressor(comptime WriterType: anytype) type {
398 // Our chain should point to the previous value.398 // Our chain should point to the previous value.
399 self.hash_prev[di & window_mask] = hh.*;399 self.hash_prev[di & window_mask] = hh.*;
400 // Set the head of the hash chain to us.400 // Set the head of the hash chain to us.
401 hh.* = @intCast(u32, di + self.hash_offset);401 hh.* = @as(u32, @intCast(di + self.hash_offset));
402 }402 }
403 self.hash = new_h;403 self.hash = new_h;
404 }404 }
405 // Update window information.405 // Update window information.
406 self.window_end = n;406 self.window_end = n;
407 self.index = @intCast(u32, n);407 self.index = @as(u32, @intCast(n));
408 }408 }
409409
410 const Match = struct {410 const Match = struct {
...@@ -471,11 +471,11 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -471,11 +471,11 @@ pub fn Compressor(comptime WriterType: anytype) type {
471 break;471 break;
472 }472 }
473473
474 if (@intCast(u32, self.hash_prev[i & window_mask]) < self.hash_offset) {474 if (@as(u32, @intCast(self.hash_prev[i & window_mask])) < self.hash_offset) {
475 break;475 break;
476 }476 }
477477
478 i = @intCast(u32, self.hash_prev[i & window_mask]) - self.hash_offset;478 i = @as(u32, @intCast(self.hash_prev[i & window_mask])) - self.hash_offset;
479 if (i < min_index) {479 if (i < min_index) {
480 break;480 break;
481 }481 }
...@@ -576,7 +576,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -576,7 +576,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
576 // Flush current output block if any.576 // Flush current output block if any.
577 if (self.byte_available) {577 if (self.byte_available) {
578 // There is still one pending token that needs to be flushed578 // There is still one pending token that needs to be flushed
579 self.tokens[self.tokens_count] = token.literalToken(@intCast(u32, self.window[self.index - 1]));579 self.tokens[self.tokens_count] = token.literalToken(@as(u32, @intCast(self.window[self.index - 1])));
580 self.tokens_count += 1;580 self.tokens_count += 1;
581 self.byte_available = false;581 self.byte_available = false;
582 }582 }
...@@ -591,9 +591,9 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -591,9 +591,9 @@ pub fn Compressor(comptime WriterType: anytype) type {
591 // Update the hash591 // Update the hash
592 self.hash = hash4(self.window[self.index .. self.index + min_match_length]);592 self.hash = hash4(self.window[self.index .. self.index + min_match_length]);
593 var hh = &self.hash_head[self.hash & hash_mask];593 var hh = &self.hash_head[self.hash & hash_mask];
594 self.chain_head = @intCast(u32, hh.*);594 self.chain_head = @as(u32, @intCast(hh.*));
595 self.hash_prev[self.index & window_mask] = @intCast(u32, self.chain_head);595 self.hash_prev[self.index & window_mask] = @as(u32, @intCast(self.chain_head));
596 hh.* = @intCast(u32, self.index + self.hash_offset);596 hh.* = @as(u32, @intCast(self.index + self.hash_offset));
597 }597 }
598 var prev_length = self.length;598 var prev_length = self.length;
599 var prev_offset = self.offset;599 var prev_offset = self.offset;
...@@ -614,7 +614,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -614,7 +614,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
614 self.index,614 self.index,
615 self.chain_head -| self.hash_offset,615 self.chain_head -| self.hash_offset,
616 min_match_length - 1,616 min_match_length - 1,
617 @intCast(u32, lookahead),617 @as(u32, @intCast(lookahead)),
618 );618 );
619 if (fmatch.ok) {619 if (fmatch.ok) {
620 self.length = fmatch.length;620 self.length = fmatch.length;
...@@ -631,12 +631,12 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -631,12 +631,12 @@ pub fn Compressor(comptime WriterType: anytype) type {
631 // There was a match at the previous step, and the current match is631 // There was a match at the previous step, and the current match is
632 // not better. Output the previous match.632 // not better. Output the previous match.
633 if (self.compression_level.fast_skip_hashshing != skip_never) {633 if (self.compression_level.fast_skip_hashshing != skip_never) {
634 self.tokens[self.tokens_count] = token.matchToken(@intCast(u32, self.length - base_match_length), @intCast(u32, self.offset - base_match_offset));634 self.tokens[self.tokens_count] = token.matchToken(@as(u32, @intCast(self.length - base_match_length)), @as(u32, @intCast(self.offset - base_match_offset)));
635 self.tokens_count += 1;635 self.tokens_count += 1;
636 } else {636 } else {
637 self.tokens[self.tokens_count] = token.matchToken(637 self.tokens[self.tokens_count] = token.matchToken(
638 @intCast(u32, prev_length - base_match_length),638 @as(u32, @intCast(prev_length - base_match_length)),
639 @intCast(u32, prev_offset -| base_match_offset),639 @as(u32, @intCast(prev_offset -| base_match_offset)),
640 );640 );
641 self.tokens_count += 1;641 self.tokens_count += 1;
642 }642 }
...@@ -661,7 +661,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -661,7 +661,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
661 var hh = &self.hash_head[self.hash & hash_mask];661 var hh = &self.hash_head[self.hash & hash_mask];
662 self.hash_prev[index & window_mask] = hh.*;662 self.hash_prev[index & window_mask] = hh.*;
663 // Set the head of the hash chain to us.663 // Set the head of the hash chain to us.
664 hh.* = @intCast(u32, index + self.hash_offset);664 hh.* = @as(u32, @intCast(index + self.hash_offset));
665 }665 }
666 }666 }
667 self.index = index;667 self.index = index;
...@@ -689,7 +689,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -689,7 +689,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
689 if (self.compression_level.fast_skip_hashshing != skip_never) {689 if (self.compression_level.fast_skip_hashshing != skip_never) {
690 i = self.index;690 i = self.index;
691 }691 }
692 self.tokens[self.tokens_count] = token.literalToken(@intCast(u32, self.window[i]));692 self.tokens[self.tokens_count] = token.literalToken(@as(u32, @intCast(self.window[i])));
693 self.tokens_count += 1;693 self.tokens_count += 1;
694 if (self.tokens_count == max_flate_block_tokens) {694 if (self.tokens_count == max_flate_block_tokens) {
695 try self.writeBlock(self.tokens[0..self.tokens_count], i + 1);695 try self.writeBlock(self.tokens[0..self.tokens_count], i + 1);
...@@ -707,7 +707,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -707,7 +707,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
707 fn fillStore(self: *Self, b: []const u8) u32 {707 fn fillStore(self: *Self, b: []const u8) u32 {
708 const n = std.compress.deflate.copy(self.window[self.window_end..], b);708 const n = std.compress.deflate.copy(self.window[self.window_end..], b);
709 self.window_end += n;709 self.window_end += n;
710 return @intCast(u32, n);710 return @as(u32, @intCast(n));
711 }711 }
712712
713 fn store(self: *Self) !void {713 fn store(self: *Self) !void {
lib/std/compress/deflate/compressor_test.zig+1-1
...@@ -172,7 +172,7 @@ test "deflate/inflate" {...@@ -172,7 +172,7 @@ test "deflate/inflate" {
172 defer testing.allocator.free(large_data_chunk);172 defer testing.allocator.free(large_data_chunk);
173 // fill with random data173 // fill with random data
174 for (large_data_chunk, 0..) |_, i| {174 for (large_data_chunk, 0..) |_, i| {
175 large_data_chunk[i] = @truncate(u8, i) *% @truncate(u8, i);175 large_data_chunk[i] = @as(u8, @truncate(i)) *% @as(u8, @truncate(i));
176 }176 }
177 try testToFromWithLimit(large_data_chunk, limits);177 try testToFromWithLimit(large_data_chunk, limits);
178}178}
lib/std/compress/deflate/decompressor.zig+43-43
...@@ -130,30 +130,30 @@ const HuffmanDecoder = struct {...@@ -130,30 +130,30 @@ const HuffmanDecoder = struct {
130 // Exception: To be compatible with zlib, we also need to130 // Exception: To be compatible with zlib, we also need to
131 // accept degenerate single-code codings. See also131 // accept degenerate single-code codings. See also
132 // TestDegenerateHuffmanCoding.132 // TestDegenerateHuffmanCoding.
133 if (code != @as(u32, 1) << @intCast(u5, max) and !(code == 1 and max == 1)) {133 if (code != @as(u32, 1) << @as(u5, @intCast(max)) and !(code == 1 and max == 1)) {
134 return false;134 return false;
135 }135 }
136136
137 self.min = min;137 self.min = min;
138 if (max > huffman_chunk_bits) {138 if (max > huffman_chunk_bits) {
139 var num_links = @as(u32, 1) << @intCast(u5, max - huffman_chunk_bits);139 var num_links = @as(u32, 1) << @as(u5, @intCast(max - huffman_chunk_bits));
140 self.link_mask = @intCast(u32, num_links - 1);140 self.link_mask = @as(u32, @intCast(num_links - 1));
141141
142 // create link tables142 // create link tables
143 var link = next_code[huffman_chunk_bits + 1] >> 1;143 var link = next_code[huffman_chunk_bits + 1] >> 1;
144 self.links = try self.allocator.alloc([]u16, huffman_num_chunks - link);144 self.links = try self.allocator.alloc([]u16, huffman_num_chunks - link);
145 self.sub_chunks = ArrayList(u32).init(self.allocator);145 self.sub_chunks = ArrayList(u32).init(self.allocator);
146 self.initialized = true;146 self.initialized = true;
147 var j = @intCast(u32, link);147 var j = @as(u32, @intCast(link));
148 while (j < huffman_num_chunks) : (j += 1) {148 while (j < huffman_num_chunks) : (j += 1) {
149 var reverse = @intCast(u32, bu.bitReverse(u16, @intCast(u16, j), 16));149 var reverse = @as(u32, @intCast(bu.bitReverse(u16, @as(u16, @intCast(j)), 16)));
150 reverse >>= @intCast(u32, 16 - huffman_chunk_bits);150 reverse >>= @as(u32, @intCast(16 - huffman_chunk_bits));
151 var off = j - @intCast(u32, link);151 var off = j - @as(u32, @intCast(link));
152 if (sanity) {152 if (sanity) {
153 // check we are not overwriting an existing chunk153 // check we are not overwriting an existing chunk
154 assert(self.chunks[reverse] == 0);154 assert(self.chunks[reverse] == 0);
155 }155 }
156 self.chunks[reverse] = @intCast(u16, off << huffman_value_shift | (huffman_chunk_bits + 1));156 self.chunks[reverse] = @as(u16, @intCast(off << huffman_value_shift | (huffman_chunk_bits + 1)));
157 self.links[off] = try self.allocator.alloc(u16, num_links);157 self.links[off] = try self.allocator.alloc(u16, num_links);
158 if (sanity) {158 if (sanity) {
159 // initialize to a known invalid chunk code (0) to see if we overwrite159 // initialize to a known invalid chunk code (0) to see if we overwrite
...@@ -170,12 +170,12 @@ const HuffmanDecoder = struct {...@@ -170,12 +170,12 @@ const HuffmanDecoder = struct {
170 }170 }
171 var ncode = next_code[n];171 var ncode = next_code[n];
172 next_code[n] += 1;172 next_code[n] += 1;
173 var chunk = @intCast(u16, (li << huffman_value_shift) | n);173 var chunk = @as(u16, @intCast((li << huffman_value_shift) | n));
174 var reverse = @intCast(u16, bu.bitReverse(u16, @intCast(u16, ncode), 16));174 var reverse = @as(u16, @intCast(bu.bitReverse(u16, @as(u16, @intCast(ncode)), 16)));
175 reverse >>= @intCast(u4, 16 - n);175 reverse >>= @as(u4, @intCast(16 - n));
176 if (n <= huffman_chunk_bits) {176 if (n <= huffman_chunk_bits) {
177 var off = reverse;177 var off = reverse;
178 while (off < self.chunks.len) : (off += @as(u16, 1) << @intCast(u4, n)) {178 while (off < self.chunks.len) : (off += @as(u16, 1) << @as(u4, @intCast(n))) {
179 // We should never need to overwrite179 // We should never need to overwrite
180 // an existing chunk. Also, 0 is180 // an existing chunk. Also, 0 is
181 // never a valid chunk, because the181 // never a valid chunk, because the
...@@ -198,12 +198,12 @@ const HuffmanDecoder = struct {...@@ -198,12 +198,12 @@ const HuffmanDecoder = struct {
198 var link_tab = self.links[value];198 var link_tab = self.links[value];
199 reverse >>= huffman_chunk_bits;199 reverse >>= huffman_chunk_bits;
200 var off = reverse;200 var off = reverse;
201 while (off < link_tab.len) : (off += @as(u16, 1) << @intCast(u4, n - huffman_chunk_bits)) {201 while (off < link_tab.len) : (off += @as(u16, 1) << @as(u4, @intCast(n - huffman_chunk_bits))) {
202 if (sanity) {202 if (sanity) {
203 // check we are not overwriting an existing chunk203 // check we are not overwriting an existing chunk
204 assert(link_tab[off] == 0);204 assert(link_tab[off] == 0);
205 }205 }
206 link_tab[off] = @intCast(u16, chunk);206 link_tab[off] = @as(u16, @intCast(chunk));
207 }207 }
208 }208 }
209 }209 }
...@@ -494,21 +494,21 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -494,21 +494,21 @@ pub fn Decompressor(comptime ReaderType: type) type {
494 while (self.nb < 5 + 5 + 4) {494 while (self.nb < 5 + 5 + 4) {
495 try self.moreBits();495 try self.moreBits();
496 }496 }
497 var nlit = @intCast(u32, self.b & 0x1F) + 257;497 var nlit = @as(u32, @intCast(self.b & 0x1F)) + 257;
498 if (nlit > max_num_lit) {498 if (nlit > max_num_lit) {
499 corrupt_input_error_offset = self.roffset;499 corrupt_input_error_offset = self.roffset;
500 self.err = InflateError.CorruptInput;500 self.err = InflateError.CorruptInput;
501 return InflateError.CorruptInput;501 return InflateError.CorruptInput;
502 }502 }
503 self.b >>= 5;503 self.b >>= 5;
504 var ndist = @intCast(u32, self.b & 0x1F) + 1;504 var ndist = @as(u32, @intCast(self.b & 0x1F)) + 1;
505 if (ndist > max_num_dist) {505 if (ndist > max_num_dist) {
506 corrupt_input_error_offset = self.roffset;506 corrupt_input_error_offset = self.roffset;
507 self.err = InflateError.CorruptInput;507 self.err = InflateError.CorruptInput;
508 return InflateError.CorruptInput;508 return InflateError.CorruptInput;
509 }509 }
510 self.b >>= 5;510 self.b >>= 5;
511 var nclen = @intCast(u32, self.b & 0xF) + 4;511 var nclen = @as(u32, @intCast(self.b & 0xF)) + 4;
512 // num_codes is 19, so nclen is always valid.512 // num_codes is 19, so nclen is always valid.
513 self.b >>= 4;513 self.b >>= 4;
514 self.nb -= 5 + 5 + 4;514 self.nb -= 5 + 5 + 4;
...@@ -519,7 +519,7 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -519,7 +519,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
519 while (self.nb < 3) {519 while (self.nb < 3) {
520 try self.moreBits();520 try self.moreBits();
521 }521 }
522 self.codebits[code_order[i]] = @intCast(u32, self.b & 0x7);522 self.codebits[code_order[i]] = @as(u32, @intCast(self.b & 0x7));
523 self.b >>= 3;523 self.b >>= 3;
524 self.nb -= 3;524 self.nb -= 3;
525 }525 }
...@@ -575,8 +575,8 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -575,8 +575,8 @@ pub fn Decompressor(comptime ReaderType: type) type {
575 while (self.nb < nb) {575 while (self.nb < nb) {
576 try self.moreBits();576 try self.moreBits();
577 }577 }
578 rep += @intCast(u32, self.b & (@as(u32, 1) << @intCast(u5, nb)) - 1);578 rep += @as(u32, @intCast(self.b & (@as(u32, 1) << @as(u5, @intCast(nb))) - 1));
579 self.b >>= @intCast(u5, nb);579 self.b >>= @as(u5, @intCast(nb));
580 self.nb -= nb;580 self.nb -= nb;
581 if (i + rep > n) {581 if (i + rep > n) {
582 corrupt_input_error_offset = self.roffset;582 corrupt_input_error_offset = self.roffset;
...@@ -623,7 +623,7 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -623,7 +623,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
623 var length: u32 = 0;623 var length: u32 = 0;
624 switch (v) {624 switch (v) {
625 0...255 => {625 0...255 => {
626 self.dict.writeByte(@intCast(u8, v));626 self.dict.writeByte(@as(u8, @intCast(v)));
627 if (self.dict.availWrite() == 0) {627 if (self.dict.availWrite() == 0) {
628 self.to_read = self.dict.readFlush();628 self.to_read = self.dict.readFlush();
629 self.step = huffmanBlock;629 self.step = huffmanBlock;
...@@ -676,8 +676,8 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -676,8 +676,8 @@ pub fn Decompressor(comptime ReaderType: type) type {
676 while (self.nb < n) {676 while (self.nb < n) {
677 try self.moreBits();677 try self.moreBits();
678 }678 }
679 length += @intCast(u32, self.b) & ((@as(u32, 1) << @intCast(u5, n)) - 1);679 length += @as(u32, @intCast(self.b)) & ((@as(u32, 1) << @as(u5, @intCast(n))) - 1);
680 self.b >>= @intCast(u5, n);680 self.b >>= @as(u5, @intCast(n));
681 self.nb -= n;681 self.nb -= n;
682 }682 }
683683
...@@ -686,9 +686,9 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -686,9 +686,9 @@ pub fn Decompressor(comptime ReaderType: type) type {
686 while (self.nb < 5) {686 while (self.nb < 5) {
687 try self.moreBits();687 try self.moreBits();
688 }688 }
689 dist = @intCast(689 dist = @as(
690 u32,690 u32,
691 bu.bitReverse(u8, @intCast(u8, (self.b & 0x1F) << 3), 8),691 @intCast(bu.bitReverse(u8, @as(u8, @intCast((self.b & 0x1F) << 3)), 8)),
692 );692 );
693 self.b >>= 5;693 self.b >>= 5;
694 self.nb -= 5;694 self.nb -= 5;
...@@ -699,16 +699,16 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -699,16 +699,16 @@ pub fn Decompressor(comptime ReaderType: type) type {
699 switch (dist) {699 switch (dist) {
700 0...3 => dist += 1,700 0...3 => dist += 1,
701 4...max_num_dist - 1 => { // 4...29701 4...max_num_dist - 1 => { // 4...29
702 var nb = @intCast(u32, dist - 2) >> 1;702 var nb = @as(u32, @intCast(dist - 2)) >> 1;
703 // have 1 bit in bottom of dist, need nb more.703 // have 1 bit in bottom of dist, need nb more.
704 var extra = (dist & 1) << @intCast(u5, nb);704 var extra = (dist & 1) << @as(u5, @intCast(nb));
705 while (self.nb < nb) {705 while (self.nb < nb) {
706 try self.moreBits();706 try self.moreBits();
707 }707 }
708 extra |= @intCast(u32, self.b & (@as(u32, 1) << @intCast(u5, nb)) - 1);708 extra |= @as(u32, @intCast(self.b & (@as(u32, 1) << @as(u5, @intCast(nb))) - 1));
709 self.b >>= @intCast(u5, nb);709 self.b >>= @as(u5, @intCast(nb));
710 self.nb -= nb;710 self.nb -= nb;
711 dist = (@as(u32, 1) << @intCast(u5, nb + 1)) + 1 + extra;711 dist = (@as(u32, 1) << @as(u5, @intCast(nb + 1))) + 1 + extra;
712 },712 },
713 else => {713 else => {
714 corrupt_input_error_offset = self.roffset;714 corrupt_input_error_offset = self.roffset;
...@@ -762,10 +762,10 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -762,10 +762,10 @@ pub fn Decompressor(comptime ReaderType: type) type {
762 self.err = InflateError.UnexpectedEndOfStream;762 self.err = InflateError.UnexpectedEndOfStream;
763 return InflateError.UnexpectedEndOfStream;763 return InflateError.UnexpectedEndOfStream;
764 };764 };
765 self.roffset += @intCast(u64, nr);765 self.roffset += @as(u64, @intCast(nr));
766 var n = @intCast(u32, self.buf[0]) | @intCast(u32, self.buf[1]) << 8;766 var n = @as(u32, @intCast(self.buf[0])) | @as(u32, @intCast(self.buf[1])) << 8;
767 var nn = @intCast(u32, self.buf[2]) | @intCast(u32, self.buf[3]) << 8;767 var nn = @as(u32, @intCast(self.buf[2])) | @as(u32, @intCast(self.buf[3])) << 8;
768 if (@intCast(u16, nn) != @truncate(u16, ~n)) {768 if (@as(u16, @intCast(nn)) != @as(u16, @truncate(~n))) {
769 corrupt_input_error_offset = self.roffset;769 corrupt_input_error_offset = self.roffset;
770 self.err = InflateError.CorruptInput;770 self.err = InflateError.CorruptInput;
771 return InflateError.CorruptInput;771 return InflateError.CorruptInput;
...@@ -793,9 +793,9 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -793,9 +793,9 @@ pub fn Decompressor(comptime ReaderType: type) type {
793 if (cnt < buf.len) {793 if (cnt < buf.len) {
794 self.err = InflateError.UnexpectedEndOfStream;794 self.err = InflateError.UnexpectedEndOfStream;
795 }795 }
796 self.roffset += @intCast(u64, cnt);796 self.roffset += @as(u64, @intCast(cnt));
797 self.copy_len -= @intCast(u32, cnt);797 self.copy_len -= @as(u32, @intCast(cnt));
798 self.dict.writeMark(@intCast(u32, cnt));798 self.dict.writeMark(@as(u32, @intCast(cnt)));
799 if (self.err != null) {799 if (self.err != null) {
800 return InflateError.UnexpectedEndOfStream;800 return InflateError.UnexpectedEndOfStream;
801 }801 }
...@@ -826,7 +826,7 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -826,7 +826,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
826 return InflateError.BadReaderState;826 return InflateError.BadReaderState;
827 };827 };
828 self.roffset += 1;828 self.roffset += 1;
829 self.b |= @as(u32, c) << @intCast(u5, self.nb);829 self.b |= @as(u32, c) << @as(u5, @intCast(self.nb));
830 self.nb += 8;830 self.nb += 8;
831 return;831 return;
832 }832 }
...@@ -854,14 +854,14 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -854,14 +854,14 @@ pub fn Decompressor(comptime ReaderType: type) type {
854 return InflateError.BadReaderState;854 return InflateError.BadReaderState;
855 };855 };
856 self.roffset += 1;856 self.roffset += 1;
857 b |= @intCast(u32, c) << @intCast(u5, nb & 31);857 b |= @as(u32, @intCast(c)) << @as(u5, @intCast(nb & 31));
858 nb += 8;858 nb += 8;
859 }859 }
860 var chunk = h.chunks[b & (huffman_num_chunks - 1)];860 var chunk = h.chunks[b & (huffman_num_chunks - 1)];
861 n = @intCast(u32, chunk & huffman_count_mask);861 n = @as(u32, @intCast(chunk & huffman_count_mask));
862 if (n > huffman_chunk_bits) {862 if (n > huffman_chunk_bits) {
863 chunk = h.links[chunk >> huffman_value_shift][(b >> huffman_chunk_bits) & h.link_mask];863 chunk = h.links[chunk >> huffman_value_shift][(b >> huffman_chunk_bits) & h.link_mask];
864 n = @intCast(u32, chunk & huffman_count_mask);864 n = @as(u32, @intCast(chunk & huffman_count_mask));
865 }865 }
866 if (n <= nb) {866 if (n <= nb) {
867 if (n == 0) {867 if (n == 0) {
...@@ -871,9 +871,9 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -871,9 +871,9 @@ pub fn Decompressor(comptime ReaderType: type) type {
871 self.err = InflateError.CorruptInput;871 self.err = InflateError.CorruptInput;
872 return InflateError.CorruptInput;872 return InflateError.CorruptInput;
873 }873 }
874 self.b = b >> @intCast(u5, n & 31);874 self.b = b >> @as(u5, @intCast(n & 31));
875 self.nb = nb - n;875 self.nb = nb - n;
876 return @intCast(u32, chunk >> huffman_value_shift);876 return @as(u32, @intCast(chunk >> huffman_value_shift));
877 }877 }
878 }878 }
879 }879 }
lib/std/compress/deflate/deflate_fast.zig+46-46
...@@ -30,23 +30,23 @@ const table_size = 1 << table_bits; // Size of the table....@@ -30,23 +30,23 @@ const table_size = 1 << table_bits; // Size of the table.
30const buffer_reset = math.maxInt(i32) - max_store_block_size * 2;30const buffer_reset = math.maxInt(i32) - max_store_block_size * 2;
3131
32fn load32(b: []u8, i: i32) u32 {32fn load32(b: []u8, i: i32) u32 {
33 var s = b[@intCast(usize, i) .. @intCast(usize, i) + 4];33 var s = b[@as(usize, @intCast(i)) .. @as(usize, @intCast(i)) + 4];
34 return @intCast(u32, s[0]) |34 return @as(u32, @intCast(s[0])) |
35 @intCast(u32, s[1]) << 8 |35 @as(u32, @intCast(s[1])) << 8 |
36 @intCast(u32, s[2]) << 16 |36 @as(u32, @intCast(s[2])) << 16 |
37 @intCast(u32, s[3]) << 24;37 @as(u32, @intCast(s[3])) << 24;
38}38}
3939
40fn load64(b: []u8, i: i32) u64 {40fn load64(b: []u8, i: i32) u64 {
41 var s = b[@intCast(usize, i)..@intCast(usize, i + 8)];41 var s = b[@as(usize, @intCast(i))..@as(usize, @intCast(i + 8))];
42 return @intCast(u64, s[0]) |42 return @as(u64, @intCast(s[0])) |
43 @intCast(u64, s[1]) << 8 |43 @as(u64, @intCast(s[1])) << 8 |
44 @intCast(u64, s[2]) << 16 |44 @as(u64, @intCast(s[2])) << 16 |
45 @intCast(u64, s[3]) << 24 |45 @as(u64, @intCast(s[3])) << 24 |
46 @intCast(u64, s[4]) << 32 |46 @as(u64, @intCast(s[4])) << 32 |
47 @intCast(u64, s[5]) << 40 |47 @as(u64, @intCast(s[5])) << 40 |
48 @intCast(u64, s[6]) << 48 |48 @as(u64, @intCast(s[6])) << 48 |
49 @intCast(u64, s[7]) << 56;49 @as(u64, @intCast(s[7])) << 56;
50}50}
5151
52fn hash(u: u32) u32 {52fn hash(u: u32) u32 {
...@@ -117,7 +117,7 @@ pub const DeflateFast = struct {...@@ -117,7 +117,7 @@ pub const DeflateFast = struct {
117 // s_limit is when to stop looking for offset/length copies. The input_margin117 // s_limit is when to stop looking for offset/length copies. The input_margin
118 // lets us use a fast path for emitLiteral in the main loop, while we are118 // lets us use a fast path for emitLiteral in the main loop, while we are
119 // looking for copies.119 // looking for copies.
120 var s_limit = @intCast(i32, src.len - input_margin);120 var s_limit = @as(i32, @intCast(src.len - input_margin));
121121
122 // next_emit is where in src the next emitLiteral should start from.122 // next_emit is where in src the next emitLiteral should start from.
123 var next_emit: i32 = 0;123 var next_emit: i32 = 0;
...@@ -170,7 +170,7 @@ pub const DeflateFast = struct {...@@ -170,7 +170,7 @@ pub const DeflateFast = struct {
170 // A 4-byte match has been found. We'll later see if more than 4 bytes170 // A 4-byte match has been found. We'll later see if more than 4 bytes
171 // match. But, prior to the match, src[next_emit..s] are unmatched. Emit171 // match. But, prior to the match, src[next_emit..s] are unmatched. Emit
172 // them as literal bytes.172 // them as literal bytes.
173 emitLiteral(dst, tokens_count, src[@intCast(usize, next_emit)..@intCast(usize, s)]);173 emitLiteral(dst, tokens_count, src[@as(usize, @intCast(next_emit))..@as(usize, @intCast(s))]);
174174
175 // Call emitCopy, and then see if another emitCopy could be our next175 // Call emitCopy, and then see if another emitCopy could be our next
176 // move. Repeat until we find no match for the input immediately after176 // move. Repeat until we find no match for the input immediately after
...@@ -192,8 +192,8 @@ pub const DeflateFast = struct {...@@ -192,8 +192,8 @@ pub const DeflateFast = struct {
192192
193 // matchToken is flate's equivalent of Snappy's emitCopy. (length,offset)193 // matchToken is flate's equivalent of Snappy's emitCopy. (length,offset)
194 dst[tokens_count.*] = token.matchToken(194 dst[tokens_count.*] = token.matchToken(
195 @intCast(u32, l + 4 - base_match_length),195 @as(u32, @intCast(l + 4 - base_match_length)),
196 @intCast(u32, s - t - base_match_offset),196 @as(u32, @intCast(s - t - base_match_offset)),
197 );197 );
198 tokens_count.* += 1;198 tokens_count.* += 1;
199 s += l;199 s += l;
...@@ -209,22 +209,22 @@ pub const DeflateFast = struct {...@@ -209,22 +209,22 @@ pub const DeflateFast = struct {
209 // are faster as one load64 call (with some shifts) instead of209 // are faster as one load64 call (with some shifts) instead of
210 // three load32 calls.210 // three load32 calls.
211 var x = load64(src, s - 1);211 var x = load64(src, s - 1);
212 var prev_hash = hash(@truncate(u32, x));212 var prev_hash = hash(@as(u32, @truncate(x)));
213 self.table[prev_hash & table_mask] = TableEntry{213 self.table[prev_hash & table_mask] = TableEntry{
214 .offset = self.cur + s - 1,214 .offset = self.cur + s - 1,
215 .val = @truncate(u32, x),215 .val = @as(u32, @truncate(x)),
216 };216 };
217 x >>= 8;217 x >>= 8;
218 var curr_hash = hash(@truncate(u32, x));218 var curr_hash = hash(@as(u32, @truncate(x)));
219 candidate = self.table[curr_hash & table_mask];219 candidate = self.table[curr_hash & table_mask];
220 self.table[curr_hash & table_mask] = TableEntry{220 self.table[curr_hash & table_mask] = TableEntry{
221 .offset = self.cur + s,221 .offset = self.cur + s,
222 .val = @truncate(u32, x),222 .val = @as(u32, @truncate(x)),
223 };223 };
224224
225 var offset = s - (candidate.offset - self.cur);225 var offset = s - (candidate.offset - self.cur);
226 if (offset > max_match_offset or @truncate(u32, x) != candidate.val) {226 if (offset > max_match_offset or @as(u32, @truncate(x)) != candidate.val) {
227 cv = @truncate(u32, x >> 8);227 cv = @as(u32, @truncate(x >> 8));
228 next_hash = hash(cv);228 next_hash = hash(cv);
229 s += 1;229 s += 1;
230 break;230 break;
...@@ -232,18 +232,18 @@ pub const DeflateFast = struct {...@@ -232,18 +232,18 @@ pub const DeflateFast = struct {
232 }232 }
233 }233 }
234234
235 if (@intCast(u32, next_emit) < src.len) {235 if (@as(u32, @intCast(next_emit)) < src.len) {
236 emitLiteral(dst, tokens_count, src[@intCast(usize, next_emit)..]);236 emitLiteral(dst, tokens_count, src[@as(usize, @intCast(next_emit))..]);
237 }237 }
238 self.cur += @intCast(i32, src.len);238 self.cur += @as(i32, @intCast(src.len));
239 self.prev_len = @intCast(u32, src.len);239 self.prev_len = @as(u32, @intCast(src.len));
240 @memcpy(self.prev[0..self.prev_len], src);240 @memcpy(self.prev[0..self.prev_len], src);
241 return;241 return;
242 }242 }
243243
244 fn emitLiteral(dst: []token.Token, tokens_count: *u16, lit: []u8) void {244 fn emitLiteral(dst: []token.Token, tokens_count: *u16, lit: []u8) void {
245 for (lit) |v| {245 for (lit) |v| {
246 dst[tokens_count.*] = token.literalToken(@intCast(u32, v));246 dst[tokens_count.*] = token.literalToken(@as(u32, @intCast(v)));
247 tokens_count.* += 1;247 tokens_count.* += 1;
248 }248 }
249 return;249 return;
...@@ -253,60 +253,60 @@ pub const DeflateFast = struct {...@@ -253,60 +253,60 @@ pub const DeflateFast = struct {
253 // t can be negative to indicate the match is starting in self.prev.253 // t can be negative to indicate the match is starting in self.prev.
254 // We assume that src[s-4 .. s] and src[t-4 .. t] already match.254 // We assume that src[s-4 .. s] and src[t-4 .. t] already match.
255 fn matchLen(self: *Self, s: i32, t: i32, src: []u8) i32 {255 fn matchLen(self: *Self, s: i32, t: i32, src: []u8) i32 {
256 var s1 = @intCast(u32, s) + max_match_length - 4;256 var s1 = @as(u32, @intCast(s)) + max_match_length - 4;
257 if (s1 > src.len) {257 if (s1 > src.len) {
258 s1 = @intCast(u32, src.len);258 s1 = @as(u32, @intCast(src.len));
259 }259 }
260260
261 // If we are inside the current block261 // If we are inside the current block
262 if (t >= 0) {262 if (t >= 0) {
263 var b = src[@intCast(usize, t)..];263 var b = src[@as(usize, @intCast(t))..];
264 var a = src[@intCast(usize, s)..@intCast(usize, s1)];264 var a = src[@as(usize, @intCast(s))..@as(usize, @intCast(s1))];
265 b = b[0..a.len];265 b = b[0..a.len];
266 // Extend the match to be as long as possible.266 // Extend the match to be as long as possible.
267 for (a, 0..) |_, i| {267 for (a, 0..) |_, i| {
268 if (a[i] != b[i]) {268 if (a[i] != b[i]) {
269 return @intCast(i32, i);269 return @as(i32, @intCast(i));
270 }270 }
271 }271 }
272 return @intCast(i32, a.len);272 return @as(i32, @intCast(a.len));
273 }273 }
274274
275 // We found a match in the previous block.275 // We found a match in the previous block.
276 var tp = @intCast(i32, self.prev_len) + t;276 var tp = @as(i32, @intCast(self.prev_len)) + t;
277 if (tp < 0) {277 if (tp < 0) {
278 return 0;278 return 0;
279 }279 }
280280
281 // Extend the match to be as long as possible.281 // Extend the match to be as long as possible.
282 var a = src[@intCast(usize, s)..@intCast(usize, s1)];282 var a = src[@as(usize, @intCast(s))..@as(usize, @intCast(s1))];
283 var b = self.prev[@intCast(usize, tp)..@intCast(usize, self.prev_len)];283 var b = self.prev[@as(usize, @intCast(tp))..@as(usize, @intCast(self.prev_len))];
284 if (b.len > a.len) {284 if (b.len > a.len) {
285 b = b[0..a.len];285 b = b[0..a.len];
286 }286 }
287 a = a[0..b.len];287 a = a[0..b.len];
288 for (b, 0..) |_, i| {288 for (b, 0..) |_, i| {
289 if (a[i] != b[i]) {289 if (a[i] != b[i]) {
290 return @intCast(i32, i);290 return @as(i32, @intCast(i));
291 }291 }
292 }292 }
293293
294 // If we reached our limit, we matched everything we are294 // If we reached our limit, we matched everything we are
295 // allowed to in the previous block and we return.295 // allowed to in the previous block and we return.
296 var n = @intCast(i32, b.len);296 var n = @as(i32, @intCast(b.len));
297 if (@intCast(u32, s + n) == s1) {297 if (@as(u32, @intCast(s + n)) == s1) {
298 return n;298 return n;
299 }299 }
300300
301 // Continue looking for more matches in the current block.301 // Continue looking for more matches in the current block.
302 a = src[@intCast(usize, s + n)..@intCast(usize, s1)];302 a = src[@as(usize, @intCast(s + n))..@as(usize, @intCast(s1))];
303 b = src[0..a.len];303 b = src[0..a.len];
304 for (a, 0..) |_, i| {304 for (a, 0..) |_, i| {
305 if (a[i] != b[i]) {305 if (a[i] != b[i]) {
306 return @intCast(i32, i) + n;306 return @as(i32, @intCast(i)) + n;
307 }307 }
308 }308 }
309 return @intCast(i32, a.len) + n;309 return @as(i32, @intCast(a.len)) + n;
310 }310 }
311311
312 // Reset resets the encoding history.312 // Reset resets the encoding history.
...@@ -574,7 +574,7 @@ test "best speed match 2/2" {...@@ -574,7 +574,7 @@ test "best speed match 2/2" {
574574
575 var e = DeflateFast{575 var e = DeflateFast{
576 .prev = previous,576 .prev = previous,
577 .prev_len = @intCast(u32, previous.len),577 .prev_len = @as(u32, @intCast(previous.len)),
578 .table = undefined,578 .table = undefined,
579 .allocator = undefined,579 .allocator = undefined,
580 .cur = 0,580 .cur = 0,
...@@ -617,7 +617,7 @@ test "best speed shift offsets" {...@@ -617,7 +617,7 @@ test "best speed shift offsets" {
617 try expect(want_first_tokens > want_second_tokens);617 try expect(want_first_tokens > want_second_tokens);
618618
619 // Forward the current indicator to before wraparound.619 // Forward the current indicator to before wraparound.
620 enc.cur = buffer_reset - @intCast(i32, test_data.len);620 enc.cur = buffer_reset - @as(i32, @intCast(test_data.len));
621621
622 // Part 1 before wrap, should match clean state.622 // Part 1 before wrap, should match clean state.
623 tokens_count = 0;623 tokens_count = 0;
lib/std/compress/deflate/deflate_fast_test.zig+4-4
...@@ -19,7 +19,7 @@ test "best speed" {...@@ -19,7 +19,7 @@ test "best speed" {
19 defer testing.allocator.free(abcabc);19 defer testing.allocator.free(abcabc);
2020
21 for (abcabc, 0..) |_, i| {21 for (abcabc, 0..) |_, i| {
22 abcabc[i] = @intCast(u8, i % 128);22 abcabc[i] = @as(u8, @intCast(i % 128));
23 }23 }
2424
25 var tc_01 = [_]u32{ 65536, 0 };25 var tc_01 = [_]u32{ 65536, 0 };
...@@ -119,16 +119,16 @@ test "best speed max match offset" {...@@ -119,16 +119,16 @@ test "best speed max match offset" {
119 // zeros1 is between 0 and 30 zeros.119 // zeros1 is between 0 and 30 zeros.
120 // The difference between the two abc's will be offset, which120 // The difference between the two abc's will be offset, which
121 // is max_match_offset plus or minus a small adjustment.121 // is max_match_offset plus or minus a small adjustment.
122 var src_len: usize = @intCast(usize, offset + @as(i32, abc.len) + @intCast(i32, extra));122 var src_len: usize = @as(usize, @intCast(offset + @as(i32, abc.len) + @as(i32, @intCast(extra))));
123 var src = try testing.allocator.alloc(u8, src_len);123 var src = try testing.allocator.alloc(u8, src_len);
124 defer testing.allocator.free(src);124 defer testing.allocator.free(src);
125125
126 @memcpy(src[0..abc.len], abc);126 @memcpy(src[0..abc.len], abc);
127 if (!do_match_before) {127 if (!do_match_before) {
128 const src_offset: usize = @intCast(usize, offset - @as(i32, xyz.len));128 const src_offset: usize = @as(usize, @intCast(offset - @as(i32, xyz.len)));
129 @memcpy(src[src_offset..][0..xyz.len], xyz);129 @memcpy(src[src_offset..][0..xyz.len], xyz);
130 }130 }
131 const src_offset: usize = @intCast(usize, offset);131 const src_offset: usize = @as(usize, @intCast(offset));
132 @memcpy(src[src_offset..][0..abc.len], abc);132 @memcpy(src[src_offset..][0..abc.len], abc);
133133
134 var compressed = ArrayList(u8).init(testing.allocator);134 var compressed = ArrayList(u8).init(testing.allocator);
lib/std/compress/deflate/dict_decoder.zig+10-10
...@@ -49,7 +49,7 @@ pub const DictDecoder = struct {...@@ -49,7 +49,7 @@ pub const DictDecoder = struct {
49 if (dict != null) {49 if (dict != null) {
50 const src = dict.?[dict.?.len -| self.hist.len..];50 const src = dict.?[dict.?.len -| self.hist.len..];
51 @memcpy(self.hist[0..src.len], src);51 @memcpy(self.hist[0..src.len], src);
52 self.wr_pos = @intCast(u32, dict.?.len);52 self.wr_pos = @as(u32, @intCast(dict.?.len));
53 }53 }
5454
55 if (self.wr_pos == self.hist.len) {55 if (self.wr_pos == self.hist.len) {
...@@ -66,7 +66,7 @@ pub const DictDecoder = struct {...@@ -66,7 +66,7 @@ pub const DictDecoder = struct {
66 // Reports the total amount of historical data in the dictionary.66 // Reports the total amount of historical data in the dictionary.
67 pub fn histSize(self: *Self) u32 {67 pub fn histSize(self: *Self) u32 {
68 if (self.full) {68 if (self.full) {
69 return @intCast(u32, self.hist.len);69 return @as(u32, @intCast(self.hist.len));
70 }70 }
71 return self.wr_pos;71 return self.wr_pos;
72 }72 }
...@@ -78,7 +78,7 @@ pub const DictDecoder = struct {...@@ -78,7 +78,7 @@ pub const DictDecoder = struct {
7878
79 // Reports the available amount of output buffer space.79 // Reports the available amount of output buffer space.
80 pub fn availWrite(self: *Self) u32 {80 pub fn availWrite(self: *Self) u32 {
81 return @intCast(u32, self.hist.len - self.wr_pos);81 return @as(u32, @intCast(self.hist.len - self.wr_pos));
82 }82 }
8383
84 // Returns a slice of the available buffer to write data to.84 // Returns a slice of the available buffer to write data to.
...@@ -110,10 +110,10 @@ pub const DictDecoder = struct {...@@ -110,10 +110,10 @@ pub const DictDecoder = struct {
110 fn copy(dst: []u8, src: []const u8) u32 {110 fn copy(dst: []u8, src: []const u8) u32 {
111 if (src.len > dst.len) {111 if (src.len > dst.len) {
112 mem.copyForwards(u8, dst, src[0..dst.len]);112 mem.copyForwards(u8, dst, src[0..dst.len]);
113 return @intCast(u32, dst.len);113 return @as(u32, @intCast(dst.len));
114 }114 }
115 mem.copyForwards(u8, dst[0..src.len], src);115 mem.copyForwards(u8, dst[0..src.len], src);
116 return @intCast(u32, src.len);116 return @as(u32, @intCast(src.len));
117 }117 }
118118
119 // Copies a string at a given (dist, length) to the output.119 // Copies a string at a given (dist, length) to the output.
...@@ -125,10 +125,10 @@ pub const DictDecoder = struct {...@@ -125,10 +125,10 @@ pub const DictDecoder = struct {
125 assert(0 < dist and dist <= self.histSize());125 assert(0 < dist and dist <= self.histSize());
126 var dst_base = self.wr_pos;126 var dst_base = self.wr_pos;
127 var dst_pos = dst_base;127 var dst_pos = dst_base;
128 var src_pos: i32 = @intCast(i32, dst_pos) - @intCast(i32, dist);128 var src_pos: i32 = @as(i32, @intCast(dst_pos)) - @as(i32, @intCast(dist));
129 var end_pos = dst_pos + length;129 var end_pos = dst_pos + length;
130 if (end_pos > self.hist.len) {130 if (end_pos > self.hist.len) {
131 end_pos = @intCast(u32, self.hist.len);131 end_pos = @as(u32, @intCast(self.hist.len));
132 }132 }
133133
134 // Copy non-overlapping section after destination position.134 // Copy non-overlapping section after destination position.
...@@ -139,8 +139,8 @@ pub const DictDecoder = struct {...@@ -139,8 +139,8 @@ pub const DictDecoder = struct {
139 // Thus, a backwards copy is performed here; that is, the exact bytes in139 // Thus, a backwards copy is performed here; that is, the exact bytes in
140 // the source prior to the copy is placed in the destination.140 // the source prior to the copy is placed in the destination.
141 if (src_pos < 0) {141 if (src_pos < 0) {
142 src_pos += @intCast(i32, self.hist.len);142 src_pos += @as(i32, @intCast(self.hist.len));
143 dst_pos += copy(self.hist[dst_pos..end_pos], self.hist[@intCast(usize, src_pos)..]);143 dst_pos += copy(self.hist[dst_pos..end_pos], self.hist[@as(usize, @intCast(src_pos))..]);
144 src_pos = 0;144 src_pos = 0;
145 }145 }
146146
...@@ -160,7 +160,7 @@ pub const DictDecoder = struct {...@@ -160,7 +160,7 @@ pub const DictDecoder = struct {
160 // dst_pos = end_pos;160 // dst_pos = end_pos;
161 //161 //
162 while (dst_pos < end_pos) {162 while (dst_pos < end_pos) {
163 dst_pos += copy(self.hist[dst_pos..end_pos], self.hist[@intCast(usize, src_pos)..dst_pos]);163 dst_pos += copy(self.hist[dst_pos..end_pos], self.hist[@as(usize, @intCast(src_pos))..dst_pos]);
164 }164 }
165165
166 self.wr_pos = dst_pos;166 self.wr_pos = dst_pos;
lib/std/compress/deflate/huffman_bit_writer.zig+55-55
...@@ -107,7 +107,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -107,7 +107,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
107 }107 }
108 var n = self.nbytes;108 var n = self.nbytes;
109 while (self.nbits != 0) {109 while (self.nbits != 0) {
110 self.bytes[n] = @truncate(u8, self.bits);110 self.bytes[n] = @as(u8, @truncate(self.bits));
111 self.bits >>= 8;111 self.bits >>= 8;
112 if (self.nbits > 8) { // Avoid underflow112 if (self.nbits > 8) { // Avoid underflow
113 self.nbits -= 8;113 self.nbits -= 8;
...@@ -132,7 +132,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -132,7 +132,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
132 if (self.err) {132 if (self.err) {
133 return;133 return;
134 }134 }
135 self.bits |= @intCast(u64, b) << @intCast(u6, self.nbits);135 self.bits |= @as(u64, @intCast(b)) << @as(u6, @intCast(self.nbits));
136 self.nbits += nb;136 self.nbits += nb;
137 if (self.nbits >= 48) {137 if (self.nbits >= 48) {
138 var bits = self.bits;138 var bits = self.bits;
...@@ -140,12 +140,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -140,12 +140,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
140 self.nbits -= 48;140 self.nbits -= 48;
141 var n = self.nbytes;141 var n = self.nbytes;
142 var bytes = self.bytes[n..][0..6];142 var bytes = self.bytes[n..][0..6];
143 bytes[0] = @truncate(u8, bits);143 bytes[0] = @as(u8, @truncate(bits));
144 bytes[1] = @truncate(u8, bits >> 8);144 bytes[1] = @as(u8, @truncate(bits >> 8));
145 bytes[2] = @truncate(u8, bits >> 16);145 bytes[2] = @as(u8, @truncate(bits >> 16));
146 bytes[3] = @truncate(u8, bits >> 24);146 bytes[3] = @as(u8, @truncate(bits >> 24));
147 bytes[4] = @truncate(u8, bits >> 32);147 bytes[4] = @as(u8, @truncate(bits >> 32));
148 bytes[5] = @truncate(u8, bits >> 40);148 bytes[5] = @as(u8, @truncate(bits >> 40));
149 n += 6;149 n += 6;
150 if (n >= buffer_flush_size) {150 if (n >= buffer_flush_size) {
151 try self.write(self.bytes[0..n]);151 try self.write(self.bytes[0..n]);
...@@ -165,7 +165,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -165,7 +165,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
165 return;165 return;
166 }166 }
167 while (self.nbits != 0) {167 while (self.nbits != 0) {
168 self.bytes[n] = @truncate(u8, self.bits);168 self.bytes[n] = @as(u8, @truncate(self.bits));
169 self.bits >>= 8;169 self.bits >>= 8;
170 self.nbits -= 8;170 self.nbits -= 8;
171 n += 1;171 n += 1;
...@@ -209,12 +209,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -209,12 +209,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
209 // Copy the concatenated code sizes to codegen. Put a marker at the end.209 // Copy the concatenated code sizes to codegen. Put a marker at the end.
210 var cgnl = codegen[0..num_literals];210 var cgnl = codegen[0..num_literals];
211 for (cgnl, 0..) |_, i| {211 for (cgnl, 0..) |_, i| {
212 cgnl[i] = @intCast(u8, lit_enc.codes[i].len);212 cgnl[i] = @as(u8, @intCast(lit_enc.codes[i].len));
213 }213 }
214214
215 cgnl = codegen[num_literals .. num_literals + num_offsets];215 cgnl = codegen[num_literals .. num_literals + num_offsets];
216 for (cgnl, 0..) |_, i| {216 for (cgnl, 0..) |_, i| {
217 cgnl[i] = @intCast(u8, off_enc.codes[i].len);217 cgnl[i] = @as(u8, @intCast(off_enc.codes[i].len));
218 }218 }
219 codegen[num_literals + num_offsets] = bad_code;219 codegen[num_literals + num_offsets] = bad_code;
220220
...@@ -243,7 +243,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -243,7 +243,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
243 }243 }
244 codegen[out_index] = 16;244 codegen[out_index] = 16;
245 out_index += 1;245 out_index += 1;
246 codegen[out_index] = @intCast(u8, n - 3);246 codegen[out_index] = @as(u8, @intCast(n - 3));
247 out_index += 1;247 out_index += 1;
248 self.codegen_freq[16] += 1;248 self.codegen_freq[16] += 1;
249 count -= n;249 count -= n;
...@@ -256,7 +256,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -256,7 +256,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
256 }256 }
257 codegen[out_index] = 18;257 codegen[out_index] = 18;
258 out_index += 1;258 out_index += 1;
259 codegen[out_index] = @intCast(u8, n - 11);259 codegen[out_index] = @as(u8, @intCast(n - 11));
260 out_index += 1;260 out_index += 1;
261 self.codegen_freq[18] += 1;261 self.codegen_freq[18] += 1;
262 count -= n;262 count -= n;
...@@ -265,7 +265,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -265,7 +265,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
265 // 3 <= count <= 10265 // 3 <= count <= 10
266 codegen[out_index] = 17;266 codegen[out_index] = 17;
267 out_index += 1;267 out_index += 1;
268 codegen[out_index] = @intCast(u8, count - 3);268 codegen[out_index] = @as(u8, @intCast(count - 3));
269 out_index += 1;269 out_index += 1;
270 self.codegen_freq[17] += 1;270 self.codegen_freq[17] += 1;
271 count = 0;271 count = 0;
...@@ -307,8 +307,8 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -307,8 +307,8 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
307 extra_bits;307 extra_bits;
308308
309 return DynamicSize{309 return DynamicSize{
310 .size = @intCast(u32, size),310 .size = @as(u32, @intCast(size)),
311 .num_codegens = @intCast(u32, num_codegens),311 .num_codegens = @as(u32, @intCast(num_codegens)),
312 };312 };
313 }313 }
314314
...@@ -328,7 +328,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -328,7 +328,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
328 return .{ .size = 0, .storable = false };328 return .{ .size = 0, .storable = false };
329 }329 }
330 if (in.?.len <= deflate_const.max_store_block_size) {330 if (in.?.len <= deflate_const.max_store_block_size) {
331 return .{ .size = @intCast(u32, (in.?.len + 5) * 8), .storable = true };331 return .{ .size = @as(u32, @intCast((in.?.len + 5) * 8)), .storable = true };
332 }332 }
333 return .{ .size = 0, .storable = false };333 return .{ .size = 0, .storable = false };
334 }334 }
...@@ -337,20 +337,20 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -337,20 +337,20 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
337 if (self.err) {337 if (self.err) {
338 return;338 return;
339 }339 }
340 self.bits |= @intCast(u64, c.code) << @intCast(u6, self.nbits);340 self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits));
341 self.nbits += @intCast(u32, c.len);341 self.nbits += @as(u32, @intCast(c.len));
342 if (self.nbits >= 48) {342 if (self.nbits >= 48) {
343 var bits = self.bits;343 var bits = self.bits;
344 self.bits >>= 48;344 self.bits >>= 48;
345 self.nbits -= 48;345 self.nbits -= 48;
346 var n = self.nbytes;346 var n = self.nbytes;
347 var bytes = self.bytes[n..][0..6];347 var bytes = self.bytes[n..][0..6];
348 bytes[0] = @truncate(u8, bits);348 bytes[0] = @as(u8, @truncate(bits));
349 bytes[1] = @truncate(u8, bits >> 8);349 bytes[1] = @as(u8, @truncate(bits >> 8));
350 bytes[2] = @truncate(u8, bits >> 16);350 bytes[2] = @as(u8, @truncate(bits >> 16));
351 bytes[3] = @truncate(u8, bits >> 24);351 bytes[3] = @as(u8, @truncate(bits >> 24));
352 bytes[4] = @truncate(u8, bits >> 32);352 bytes[4] = @as(u8, @truncate(bits >> 32));
353 bytes[5] = @truncate(u8, bits >> 40);353 bytes[5] = @as(u8, @truncate(bits >> 40));
354 n += 6;354 n += 6;
355 if (n >= buffer_flush_size) {355 if (n >= buffer_flush_size) {
356 try self.write(self.bytes[0..n]);356 try self.write(self.bytes[0..n]);
...@@ -381,36 +381,36 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -381,36 +381,36 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
381 first_bits = 5;381 first_bits = 5;
382 }382 }
383 try self.writeBits(first_bits, 3);383 try self.writeBits(first_bits, 3);
384 try self.writeBits(@intCast(u32, num_literals - 257), 5);384 try self.writeBits(@as(u32, @intCast(num_literals - 257)), 5);
385 try self.writeBits(@intCast(u32, num_offsets - 1), 5);385 try self.writeBits(@as(u32, @intCast(num_offsets - 1)), 5);
386 try self.writeBits(@intCast(u32, num_codegens - 4), 4);386 try self.writeBits(@as(u32, @intCast(num_codegens - 4)), 4);
387387
388 var i: u32 = 0;388 var i: u32 = 0;
389 while (i < num_codegens) : (i += 1) {389 while (i < num_codegens) : (i += 1) {
390 var value = @intCast(u32, self.codegen_encoding.codes[codegen_order[i]].len);390 var value = @as(u32, @intCast(self.codegen_encoding.codes[codegen_order[i]].len));
391 try self.writeBits(@intCast(u32, value), 3);391 try self.writeBits(@as(u32, @intCast(value)), 3);
392 }392 }
393393
394 i = 0;394 i = 0;
395 while (true) {395 while (true) {
396 var code_word: u32 = @intCast(u32, self.codegen[i]);396 var code_word: u32 = @as(u32, @intCast(self.codegen[i]));
397 i += 1;397 i += 1;
398 if (code_word == bad_code) {398 if (code_word == bad_code) {
399 break;399 break;
400 }400 }
401 try self.writeCode(self.codegen_encoding.codes[@intCast(u32, code_word)]);401 try self.writeCode(self.codegen_encoding.codes[@as(u32, @intCast(code_word))]);
402402
403 switch (code_word) {403 switch (code_word) {
404 16 => {404 16 => {
405 try self.writeBits(@intCast(u32, self.codegen[i]), 2);405 try self.writeBits(@as(u32, @intCast(self.codegen[i])), 2);
406 i += 1;406 i += 1;
407 },407 },
408 17 => {408 17 => {
409 try self.writeBits(@intCast(u32, self.codegen[i]), 3);409 try self.writeBits(@as(u32, @intCast(self.codegen[i])), 3);
410 i += 1;410 i += 1;
411 },411 },
412 18 => {412 18 => {
413 try self.writeBits(@intCast(u32, self.codegen[i]), 7);413 try self.writeBits(@as(u32, @intCast(self.codegen[i])), 7);
414 i += 1;414 i += 1;
415 },415 },
416 else => {},416 else => {},
...@@ -428,8 +428,8 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -428,8 +428,8 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
428 }428 }
429 try self.writeBits(flag, 3);429 try self.writeBits(flag, 3);
430 try self.flush();430 try self.flush();
431 try self.writeBits(@intCast(u32, length), 16);431 try self.writeBits(@as(u32, @intCast(length)), 16);
432 try self.writeBits(@intCast(u32, ~@intCast(u16, length)), 16);432 try self.writeBits(@as(u32, @intCast(~@as(u16, @intCast(length)))), 16);
433 }433 }
434434
435 fn writeFixedHeader(self: *Self, is_eof: bool) Error!void {435 fn writeFixedHeader(self: *Self, is_eof: bool) Error!void {
...@@ -476,14 +476,14 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -476,14 +476,14 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
476 var length_code: u32 = length_codes_start + 8;476 var length_code: u32 = length_codes_start + 8;
477 while (length_code < num_literals) : (length_code += 1) {477 while (length_code < num_literals) : (length_code += 1) {
478 // First eight length codes have extra size = 0.478 // First eight length codes have extra size = 0.
479 extra_bits += @intCast(u32, self.literal_freq[length_code]) *479 extra_bits += @as(u32, @intCast(self.literal_freq[length_code])) *
480 @intCast(u32, length_extra_bits[length_code - length_codes_start]);480 @as(u32, @intCast(length_extra_bits[length_code - length_codes_start]));
481 }481 }
482 var offset_code: u32 = 4;482 var offset_code: u32 = 4;
483 while (offset_code < num_offsets) : (offset_code += 1) {483 while (offset_code < num_offsets) : (offset_code += 1) {
484 // First four offset codes have extra size = 0.484 // First four offset codes have extra size = 0.
485 extra_bits += @intCast(u32, self.offset_freq[offset_code]) *485 extra_bits += @as(u32, @intCast(self.offset_freq[offset_code])) *
486 @intCast(u32, offset_extra_bits[offset_code]);486 @as(u32, @intCast(offset_extra_bits[offset_code]));
487 }487 }
488 }488 }
489489
...@@ -621,12 +621,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -621,12 +621,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
621 self.literal_freq[token.literal(deflate_const.end_block_marker)] += 1;621 self.literal_freq[token.literal(deflate_const.end_block_marker)] += 1;
622622
623 // get the number of literals623 // get the number of literals
624 num_literals = @intCast(u32, self.literal_freq.len);624 num_literals = @as(u32, @intCast(self.literal_freq.len));
625 while (self.literal_freq[num_literals - 1] == 0) {625 while (self.literal_freq[num_literals - 1] == 0) {
626 num_literals -= 1;626 num_literals -= 1;
627 }627 }
628 // get the number of offsets628 // get the number of offsets
629 num_offsets = @intCast(u32, self.offset_freq.len);629 num_offsets = @as(u32, @intCast(self.offset_freq.len));
630 while (num_offsets > 0 and self.offset_freq[num_offsets - 1] == 0) {630 while (num_offsets > 0 and self.offset_freq[num_offsets - 1] == 0) {
631 num_offsets -= 1;631 num_offsets -= 1;
632 }632 }
...@@ -664,18 +664,18 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -664,18 +664,18 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
664 var length = token.length(t);664 var length = token.length(t);
665 var length_code = token.lengthCode(length);665 var length_code = token.lengthCode(length);
666 try self.writeCode(le_codes[length_code + length_codes_start]);666 try self.writeCode(le_codes[length_code + length_codes_start]);
667 var extra_length_bits = @intCast(u32, length_extra_bits[length_code]);667 var extra_length_bits = @as(u32, @intCast(length_extra_bits[length_code]));
668 if (extra_length_bits > 0) {668 if (extra_length_bits > 0) {
669 var extra_length = @intCast(u32, length - length_base[length_code]);669 var extra_length = @as(u32, @intCast(length - length_base[length_code]));
670 try self.writeBits(extra_length, extra_length_bits);670 try self.writeBits(extra_length, extra_length_bits);
671 }671 }
672 // Write the offset672 // Write the offset
673 var offset = token.offset(t);673 var offset = token.offset(t);
674 var offset_code = token.offsetCode(offset);674 var offset_code = token.offsetCode(offset);
675 try self.writeCode(oe_codes[offset_code]);675 try self.writeCode(oe_codes[offset_code]);
676 var extra_offset_bits = @intCast(u32, offset_extra_bits[offset_code]);676 var extra_offset_bits = @as(u32, @intCast(offset_extra_bits[offset_code]));
677 if (extra_offset_bits > 0) {677 if (extra_offset_bits > 0) {
678 var extra_offset = @intCast(u32, offset - offset_base[offset_code]);678 var extra_offset = @as(u32, @intCast(offset - offset_base[offset_code]));
679 try self.writeBits(extra_offset, extra_offset_bits);679 try self.writeBits(extra_offset, extra_offset_bits);
680 }680 }
681 }681 }
...@@ -742,8 +742,8 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -742,8 +742,8 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
742 for (input) |t| {742 for (input) |t| {
743 // Bitwriting inlined, ~30% speedup743 // Bitwriting inlined, ~30% speedup
744 var c = encoding[t];744 var c = encoding[t];
745 self.bits |= @intCast(u64, c.code) << @intCast(u6, self.nbits);745 self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits));
746 self.nbits += @intCast(u32, c.len);746 self.nbits += @as(u32, @intCast(c.len));
747 if (self.nbits < 48) {747 if (self.nbits < 48) {
748 continue;748 continue;
749 }749 }
...@@ -752,12 +752,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -752,12 +752,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
752 self.bits >>= 48;752 self.bits >>= 48;
753 self.nbits -= 48;753 self.nbits -= 48;
754 var bytes = self.bytes[n..][0..6];754 var bytes = self.bytes[n..][0..6];
755 bytes[0] = @truncate(u8, bits);755 bytes[0] = @as(u8, @truncate(bits));
756 bytes[1] = @truncate(u8, bits >> 8);756 bytes[1] = @as(u8, @truncate(bits >> 8));
757 bytes[2] = @truncate(u8, bits >> 16);757 bytes[2] = @as(u8, @truncate(bits >> 16));
758 bytes[3] = @truncate(u8, bits >> 24);758 bytes[3] = @as(u8, @truncate(bits >> 24));
759 bytes[4] = @truncate(u8, bits >> 32);759 bytes[4] = @as(u8, @truncate(bits >> 32));
760 bytes[5] = @truncate(u8, bits >> 40);760 bytes[5] = @as(u8, @truncate(bits >> 40));
761 n += 6;761 n += 6;
762 if (n < buffer_flush_size) {762 if (n < buffer_flush_size) {
763 continue;763 continue;
lib/std/compress/deflate/huffman_code.zig+10-10
...@@ -73,7 +73,7 @@ pub const HuffmanEncoder = struct {...@@ -73,7 +73,7 @@ pub const HuffmanEncoder = struct {
73 // Set list to be the set of all non-zero literals and their frequencies73 // Set list to be the set of all non-zero literals and their frequencies
74 for (freq, 0..) |f, i| {74 for (freq, 0..) |f, i| {
75 if (f != 0) {75 if (f != 0) {
76 list[count] = LiteralNode{ .literal = @intCast(u16, i), .freq = f };76 list[count] = LiteralNode{ .literal = @as(u16, @intCast(i)), .freq = f };
77 count += 1;77 count += 1;
78 } else {78 } else {
79 list[count] = LiteralNode{ .literal = 0x00, .freq = 0 };79 list[count] = LiteralNode{ .literal = 0x00, .freq = 0 };
...@@ -88,7 +88,7 @@ pub const HuffmanEncoder = struct {...@@ -88,7 +88,7 @@ pub const HuffmanEncoder = struct {
88 // two or fewer literals, everything has bit length 1.88 // two or fewer literals, everything has bit length 1.
89 for (list, 0..) |node, i| {89 for (list, 0..) |node, i| {
90 // "list" is in order of increasing literal value.90 // "list" is in order of increasing literal value.
91 self.codes[node.literal].set(@intCast(u16, i), 1);91 self.codes[node.literal].set(@as(u16, @intCast(i)), 1);
92 }92 }
93 return;93 return;
94 }94 }
...@@ -105,7 +105,7 @@ pub const HuffmanEncoder = struct {...@@ -105,7 +105,7 @@ pub const HuffmanEncoder = struct {
105 var total: u32 = 0;105 var total: u32 = 0;
106 for (freq, 0..) |f, i| {106 for (freq, 0..) |f, i| {
107 if (f != 0) {107 if (f != 0) {
108 total += @intCast(u32, f) * @intCast(u32, self.codes[i].len);108 total += @as(u32, @intCast(f)) * @as(u32, @intCast(self.codes[i].len));
109 }109 }
110 }110 }
111 return total;111 return total;
...@@ -167,7 +167,7 @@ pub const HuffmanEncoder = struct {...@@ -167,7 +167,7 @@ pub const HuffmanEncoder = struct {
167 }167 }
168168
169 // We need a total of 2*n - 2 items at top level and have already generated 2.169 // We need a total of 2*n - 2 items at top level and have already generated 2.
170 levels[max_bits].needed = 2 * @intCast(u32, n) - 4;170 levels[max_bits].needed = 2 * @as(u32, @intCast(n)) - 4;
171171
172 {172 {
173 var level = max_bits;173 var level = max_bits;
...@@ -267,19 +267,19 @@ pub const HuffmanEncoder = struct {...@@ -267,19 +267,19 @@ pub const HuffmanEncoder = struct {
267 // are encoded using "bits" bits, and get the values267 // are encoded using "bits" bits, and get the values
268 // code, code + 1, .... The code values are268 // code, code + 1, .... The code values are
269 // assigned in literal order (not frequency order).269 // assigned in literal order (not frequency order).
270 var chunk = list[list.len - @intCast(u32, bits) ..];270 var chunk = list[list.len - @as(u32, @intCast(bits)) ..];
271271
272 self.lns = chunk;272 self.lns = chunk;
273 mem.sort(LiteralNode, self.lns, {}, byLiteral);273 mem.sort(LiteralNode, self.lns, {}, byLiteral);
274274
275 for (chunk) |node| {275 for (chunk) |node| {
276 self.codes[node.literal] = HuffCode{276 self.codes[node.literal] = HuffCode{
277 .code = bu.bitReverse(u16, code, @intCast(u5, n)),277 .code = bu.bitReverse(u16, code, @as(u5, @intCast(n))),
278 .len = @intCast(u16, n),278 .len = @as(u16, @intCast(n)),
279 };279 };
280 code += 1;280 code += 1;
281 }281 }
282 list = list[0 .. list.len - @intCast(u32, bits)];282 list = list[0 .. list.len - @as(u32, @intCast(bits))];
283 }283 }
284 }284 }
285};285};
...@@ -332,7 +332,7 @@ pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder {...@@ -332,7 +332,7 @@ pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder {
332 size = 8;332 size = 8;
333 },333 },
334 }334 }
335 codes[ch] = HuffCode{ .code = bu.bitReverse(u16, bits, @intCast(u5, size)), .len = size };335 codes[ch] = HuffCode{ .code = bu.bitReverse(u16, bits, @as(u5, @intCast(size))), .len = size };
336 }336 }
337 return h;337 return h;
338}338}
...@@ -341,7 +341,7 @@ pub fn generateFixedOffsetEncoding(allocator: Allocator) !HuffmanEncoder {...@@ -341,7 +341,7 @@ pub fn generateFixedOffsetEncoding(allocator: Allocator) !HuffmanEncoder {
341 var h = try newHuffmanEncoder(allocator, 30);341 var h = try newHuffmanEncoder(allocator, 30);
342 var codes = h.codes;342 var codes = h.codes;
343 for (codes, 0..) |_, ch| {343 for (codes, 0..) |_, ch| {
344 codes[ch] = HuffCode{ .code = bu.bitReverse(u16, @intCast(u16, ch), 5), .len = 5 };344 codes[ch] = HuffCode{ .code = bu.bitReverse(u16, @as(u16, @intCast(ch)), 5), .len = 5 };
345 }345 }
346 return h;346 return h;
347}347}
lib/std/compress/deflate/token.zig+5-5
...@@ -70,16 +70,16 @@ pub fn matchToken(xlength: u32, xoffset: u32) Token {...@@ -70,16 +70,16 @@ pub fn matchToken(xlength: u32, xoffset: u32) Token {
7070
71// Returns the literal of a literal token71// Returns the literal of a literal token
72pub fn literal(t: Token) u32 {72pub fn literal(t: Token) u32 {
73 return @intCast(u32, t - literal_type);73 return @as(u32, @intCast(t - literal_type));
74}74}
7575
76// Returns the extra offset of a match token76// Returns the extra offset of a match token
77pub fn offset(t: Token) u32 {77pub fn offset(t: Token) u32 {
78 return @intCast(u32, t) & offset_mask;78 return @as(u32, @intCast(t)) & offset_mask;
79}79}
8080
81pub fn length(t: Token) u32 {81pub fn length(t: Token) u32 {
82 return @intCast(u32, (t - match_type) >> length_shift);82 return @as(u32, @intCast((t - match_type) >> length_shift));
83}83}
8484
85pub fn lengthCode(len: u32) u32 {85pub fn lengthCode(len: u32) u32 {
...@@ -88,10 +88,10 @@ pub fn lengthCode(len: u32) u32 {...@@ -88,10 +88,10 @@ pub fn lengthCode(len: u32) u32 {
8888
89// Returns the offset code corresponding to a specific offset89// Returns the offset code corresponding to a specific offset
90pub fn offsetCode(off: u32) u32 {90pub fn offsetCode(off: u32) u32 {
91 if (off < @intCast(u32, offset_codes.len)) {91 if (off < @as(u32, @intCast(offset_codes.len))) {
92 return offset_codes[off];92 return offset_codes[off];
93 }93 }
94 if (off >> 7 < @intCast(u32, offset_codes.len)) {94 if (off >> 7 < @as(u32, @intCast(offset_codes.len))) {
95 return offset_codes[off >> 7] + 14;95 return offset_codes[off >> 7] + 14;
96 }96 }
97 return offset_codes[off >> 14] + 28;97 return offset_codes[off >> 14] + 28;
lib/std/compress/gzip.zig+1-1
...@@ -89,7 +89,7 @@ pub fn Decompress(comptime ReaderType: type) type {...@@ -89,7 +89,7 @@ pub fn Decompress(comptime ReaderType: type) type {
8989
90 if (FLG & FHCRC != 0) {90 if (FLG & FHCRC != 0) {
91 const hash = try source.readIntLittle(u16);91 const hash = try source.readIntLittle(u16);
92 if (hash != @truncate(u16, hasher.hasher.final()))92 if (hash != @as(u16, @truncate(hasher.hasher.final())))
93 return error.WrongChecksum;93 return error.WrongChecksum;
94 }94 }
9595
lib/std/compress/lzma/decode.zig+5-5
...@@ -52,11 +52,11 @@ pub const Params = struct {...@@ -52,11 +52,11 @@ pub const Params = struct {
52 return error.CorruptInput;52 return error.CorruptInput;
53 }53 }
5454
55 const lc = @intCast(u4, props % 9);55 const lc = @as(u4, @intCast(props % 9));
56 props /= 9;56 props /= 9;
57 const lp = @intCast(u3, props % 5);57 const lp = @as(u3, @intCast(props % 5));
58 props /= 5;58 props /= 5;
59 const pb = @intCast(u3, props);59 const pb = @as(u3, @intCast(props));
6060
61 const dict_size_provided = try reader.readIntLittle(u32);61 const dict_size_provided = try reader.readIntLittle(u32);
62 const dict_size = @max(0x1000, dict_size_provided);62 const dict_size = @max(0x1000, dict_size_provided);
...@@ -342,7 +342,7 @@ pub const DecoderState = struct {...@@ -342,7 +342,7 @@ pub const DecoderState = struct {
342 result = (result << 1) ^ @intFromBool(try decoder.decodeBit(reader, &probs[result], update));342 result = (result << 1) ^ @intFromBool(try decoder.decodeBit(reader, &probs[result], update));
343 }343 }
344344
345 return @truncate(u8, result - 0x100);345 return @as(u8, @truncate(result - 0x100));
346 }346 }
347347
348 fn decodeDistance(348 fn decodeDistance(
...@@ -358,7 +358,7 @@ pub const DecoderState = struct {...@@ -358,7 +358,7 @@ pub const DecoderState = struct {
358 if (pos_slot < 4)358 if (pos_slot < 4)
359 return pos_slot;359 return pos_slot;
360360
361 const num_direct_bits = @intCast(u5, (pos_slot >> 1) - 1);361 const num_direct_bits = @as(u5, @intCast((pos_slot >> 1) - 1));
362 var result = (2 ^ (pos_slot & 1)) << num_direct_bits;362 var result = (2 ^ (pos_slot & 1)) << num_direct_bits;
363363
364 if (pos_slot < 14) {364 if (pos_slot < 14) {
lib/std/compress/lzma2/decode.zig+3-3
...@@ -119,11 +119,11 @@ pub const Decoder = struct {...@@ -119,11 +119,11 @@ pub const Decoder = struct {
119 return error.CorruptInput;119 return error.CorruptInput;
120 }120 }
121121
122 const lc = @intCast(u4, props % 9);122 const lc = @as(u4, @intCast(props % 9));
123 props /= 9;123 props /= 9;
124 const lp = @intCast(u3, props % 5);124 const lp = @as(u3, @intCast(props % 5));
125 props /= 5;125 props /= 5;
126 const pb = @intCast(u3, props);126 const pb = @as(u3, @intCast(props));
127127
128 if (lc + lp > 4) {128 if (lc + lp > 4) {
129 return error.CorruptInput;129 return error.CorruptInput;
lib/std/compress/xz.zig+1-1
...@@ -18,7 +18,7 @@ fn readStreamFlags(reader: anytype, check: *Check) !void {...@@ -18,7 +18,7 @@ fn readStreamFlags(reader: anytype, check: *Check) !void {
18 if (reserved1 != 0)18 if (reserved1 != 0)
19 return error.CorruptInput;19 return error.CorruptInput;
2020
21 check.* = @enumFromInt(Check, try bit_reader.readBitsNoEof(u4, 4));21 check.* = @as(Check, @enumFromInt(try bit_reader.readBitsNoEof(u4, 4)));
2222
23 const reserved2 = try bit_reader.readBitsNoEof(u4, 4);23 const reserved2 = try bit_reader.readBitsNoEof(u4, 4);
24 if (reserved2 != 0)24 if (reserved2 != 0)
lib/std/compress/xz/block.zig+3-3
...@@ -108,7 +108,7 @@ pub fn Decoder(comptime ReaderType: type) type {...@@ -108,7 +108,7 @@ pub fn Decoder(comptime ReaderType: type) type {
108 has_unpacked_size: bool,108 has_unpacked_size: bool,
109 };109 };
110110
111 const flags = @bitCast(Flags, try header_reader.readByte());111 const flags = @as(Flags, @bitCast(try header_reader.readByte()));
112 const filter_count = @as(u3, flags.last_filter_index) + 1;112 const filter_count = @as(u3, flags.last_filter_index) + 1;
113 if (filter_count > 1)113 if (filter_count > 1)
114 return error.Unsupported;114 return error.Unsupported;
...@@ -124,9 +124,9 @@ pub fn Decoder(comptime ReaderType: type) type {...@@ -124,9 +124,9 @@ pub fn Decoder(comptime ReaderType: type) type {
124 _,124 _,
125 };125 };
126126
127 const filter_id = @enumFromInt(127 const filter_id = @as(
128 FilterId,128 FilterId,
129 try std.leb.readULEB128(u64, header_reader),129 @enumFromInt(try std.leb.readULEB128(u64, header_reader)),
130 );130 );
131131
132 if (@intFromEnum(filter_id) >= 0x4000_0000_0000_0000)132 if (@intFromEnum(filter_id) >= 0x4000_0000_0000_0000)
lib/std/compress/zlib.zig+3-3
...@@ -41,7 +41,7 @@ pub fn DecompressStream(comptime ReaderType: type) type {...@@ -41,7 +41,7 @@ pub fn DecompressStream(comptime ReaderType: type) type {
41 // verify the header checksum41 // verify the header checksum
42 if (header_u16 % 31 != 0)42 if (header_u16 % 31 != 0)
43 return error.BadHeader;43 return error.BadHeader;
44 const header = @bitCast(ZLibHeader, header_u16);44 const header = @as(ZLibHeader, @bitCast(header_u16));
4545
46 // The CM field must be 8 to indicate the use of DEFLATE46 // The CM field must be 8 to indicate the use of DEFLATE
47 if (header.compression_method != ZLibHeader.DEFLATE)47 if (header.compression_method != ZLibHeader.DEFLATE)
...@@ -130,9 +130,9 @@ pub fn CompressStream(comptime WriterType: type) type {...@@ -130,9 +130,9 @@ pub fn CompressStream(comptime WriterType: type) type {
130 .preset_dict = 0,130 .preset_dict = 0,
131 .checksum = 0,131 .checksum = 0,
132 };132 };
133 header.checksum = @truncate(u5, 31 - @bitCast(u16, header) % 31);133 header.checksum = @as(u5, @truncate(31 - @as(u16, @bitCast(header)) % 31));
134134
135 try dest.writeIntBig(u16, @bitCast(u16, header));135 try dest.writeIntBig(u16, @as(u16, @bitCast(header)));
136136
137 const compression_level: deflate.Compression = switch (options.level) {137 const compression_level: deflate.Compression = switch (options.level) {
138 .no_compression => .no_compression,138 .no_compression => .no_compression,
lib/std/compress/zstandard/decode/block.zig+7-7
...@@ -894,7 +894,7 @@ pub fn decodeBlockReader(...@@ -894,7 +894,7 @@ pub fn decodeBlockReader(
894/// Decode the header of a block.894/// Decode the header of a block.
895pub fn decodeBlockHeader(src: *const [3]u8) frame.Zstandard.Block.Header {895pub fn decodeBlockHeader(src: *const [3]u8) frame.Zstandard.Block.Header {
896 const last_block = src[0] & 1 == 1;896 const last_block = src[0] & 1 == 1;
897 const block_type = @enumFromInt(frame.Zstandard.Block.Type, (src[0] & 0b110) >> 1);897 const block_type = @as(frame.Zstandard.Block.Type, @enumFromInt((src[0] & 0b110) >> 1));
898 const block_size = ((src[0] & 0b11111000) >> 3) + (@as(u21, src[1]) << 5) + (@as(u21, src[2]) << 13);898 const block_size = ((src[0] & 0b11111000) >> 3) + (@as(u21, src[1]) << 5) + (@as(u21, src[2]) << 13);
899 return .{899 return .{
900 .last_block = last_block,900 .last_block = last_block,
...@@ -1008,7 +1008,7 @@ pub fn decodeLiteralsSection(...@@ -1008,7 +1008,7 @@ pub fn decodeLiteralsSection(
1008 try huffman.decodeHuffmanTree(counting_reader.reader(), buffer)1008 try huffman.decodeHuffmanTree(counting_reader.reader(), buffer)
1009 else1009 else
1010 null;1010 null;
1011 const huffman_tree_size = @intCast(usize, counting_reader.bytes_read);1011 const huffman_tree_size = @as(usize, @intCast(counting_reader.bytes_read));
1012 const total_streams_size = std.math.sub(usize, header.compressed_size.?, huffman_tree_size) catch1012 const total_streams_size = std.math.sub(usize, header.compressed_size.?, huffman_tree_size) catch
1013 return error.MalformedLiteralsSection;1013 return error.MalformedLiteralsSection;
10141014
...@@ -1058,8 +1058,8 @@ fn decodeStreams(size_format: u2, stream_data: []const u8) !LiteralsSection.Stre...@@ -1058,8 +1058,8 @@ fn decodeStreams(size_format: u2, stream_data: []const u8) !LiteralsSection.Stre
1058/// - `error.EndOfStream` if there are not enough bytes in `source`1058/// - `error.EndOfStream` if there are not enough bytes in `source`
1059pub fn decodeLiteralsHeader(source: anytype) !LiteralsSection.Header {1059pub fn decodeLiteralsHeader(source: anytype) !LiteralsSection.Header {
1060 const byte0 = try source.readByte();1060 const byte0 = try source.readByte();
1061 const block_type = @enumFromInt(LiteralsSection.BlockType, byte0 & 0b11);1061 const block_type = @as(LiteralsSection.BlockType, @enumFromInt(byte0 & 0b11));
1062 const size_format = @intCast(u2, (byte0 & 0b1100) >> 2);1062 const size_format = @as(u2, @intCast((byte0 & 0b1100) >> 2));
1063 var regenerated_size: u20 = undefined;1063 var regenerated_size: u20 = undefined;
1064 var compressed_size: ?u18 = null;1064 var compressed_size: ?u18 = null;
1065 switch (block_type) {1065 switch (block_type) {
...@@ -1132,9 +1132,9 @@ pub fn decodeSequencesHeader(...@@ -1132,9 +1132,9 @@ pub fn decodeSequencesHeader(
11321132
1133 const compression_modes = try source.readByte();1133 const compression_modes = try source.readByte();
11341134
1135 const matches_mode = @enumFromInt(SequencesSection.Header.Mode, (compression_modes & 0b00001100) >> 2);1135 const matches_mode = @as(SequencesSection.Header.Mode, @enumFromInt((compression_modes & 0b00001100) >> 2));
1136 const offsets_mode = @enumFromInt(SequencesSection.Header.Mode, (compression_modes & 0b00110000) >> 4);1136 const offsets_mode = @as(SequencesSection.Header.Mode, @enumFromInt((compression_modes & 0b00110000) >> 4));
1137 const literal_mode = @enumFromInt(SequencesSection.Header.Mode, (compression_modes & 0b11000000) >> 6);1137 const literal_mode = @as(SequencesSection.Header.Mode, @enumFromInt((compression_modes & 0b11000000) >> 6));
1138 if (compression_modes & 0b11 != 0) return error.ReservedBitSet;1138 if (compression_modes & 0b11 != 0) return error.ReservedBitSet;
11391139
1140 return SequencesSection.Header{1140 return SequencesSection.Header{
lib/std/compress/zstandard/decode/fse.zig+7-7
...@@ -69,7 +69,7 @@ pub fn decodeFseTable(...@@ -69,7 +69,7 @@ pub fn decodeFseTable(
69}69}
7070
71fn buildFseTable(values: []const u16, entries: []Table.Fse) !void {71fn buildFseTable(values: []const u16, entries: []Table.Fse) !void {
72 const total_probability = @intCast(u16, entries.len);72 const total_probability = @as(u16, @intCast(entries.len));
73 const accuracy_log = std.math.log2_int(u16, total_probability);73 const accuracy_log = std.math.log2_int(u16, total_probability);
74 assert(total_probability <= 1 << 9);74 assert(total_probability <= 1 << 9);
7575
...@@ -77,7 +77,7 @@ fn buildFseTable(values: []const u16, entries: []Table.Fse) !void {...@@ -77,7 +77,7 @@ fn buildFseTable(values: []const u16, entries: []Table.Fse) !void {
77 for (values, 0..) |value, i| {77 for (values, 0..) |value, i| {
78 if (value == 0) {78 if (value == 0) {
79 entries[entries.len - 1 - less_than_one_count] = Table.Fse{79 entries[entries.len - 1 - less_than_one_count] = Table.Fse{
80 .symbol = @intCast(u8, i),80 .symbol = @as(u8, @intCast(i)),
81 .baseline = 0,81 .baseline = 0,
82 .bits = accuracy_log,82 .bits = accuracy_log,
83 };83 };
...@@ -99,7 +99,7 @@ fn buildFseTable(values: []const u16, entries: []Table.Fse) !void {...@@ -99,7 +99,7 @@ fn buildFseTable(values: []const u16, entries: []Table.Fse) !void {
99 const share_size_log = std.math.log2_int(u16, share_size);99 const share_size_log = std.math.log2_int(u16, share_size);
100100
101 for (0..probability) |i| {101 for (0..probability) |i| {
102 temp_states[i] = @intCast(u16, position);102 temp_states[i] = @as(u16, @intCast(position));
103 position += (entries.len >> 1) + (entries.len >> 3) + 3;103 position += (entries.len >> 1) + (entries.len >> 3) + 3;
104 position &= entries.len - 1;104 position &= entries.len - 1;
105 while (position >= entries.len - less_than_one_count) {105 while (position >= entries.len - less_than_one_count) {
...@@ -110,13 +110,13 @@ fn buildFseTable(values: []const u16, entries: []Table.Fse) !void {...@@ -110,13 +110,13 @@ fn buildFseTable(values: []const u16, entries: []Table.Fse) !void {
110 std.mem.sort(u16, temp_states[0..probability], {}, std.sort.asc(u16));110 std.mem.sort(u16, temp_states[0..probability], {}, std.sort.asc(u16));
111 for (0..probability) |i| {111 for (0..probability) |i| {
112 entries[temp_states[i]] = if (i < double_state_count) Table.Fse{112 entries[temp_states[i]] = if (i < double_state_count) Table.Fse{
113 .symbol = @intCast(u8, symbol),113 .symbol = @as(u8, @intCast(symbol)),
114 .bits = share_size_log + 1,114 .bits = share_size_log + 1,
115 .baseline = single_state_count * share_size + @intCast(u16, i) * 2 * share_size,115 .baseline = single_state_count * share_size + @as(u16, @intCast(i)) * 2 * share_size,
116 } else Table.Fse{116 } else Table.Fse{
117 .symbol = @intCast(u8, symbol),117 .symbol = @as(u8, @intCast(symbol)),
118 .bits = share_size_log,118 .bits = share_size_log,
119 .baseline = (@intCast(u16, i) - double_state_count) * share_size,119 .baseline = (@as(u16, @intCast(i)) - double_state_count) * share_size,
120 };120 };
121 }121 }
122 }122 }
lib/std/compress/zstandard/decode/huffman.zig+5-5
...@@ -109,8 +109,8 @@ fn decodeDirectHuffmanTree(source: anytype, encoded_symbol_count: usize, weights...@@ -109,8 +109,8 @@ fn decodeDirectHuffmanTree(source: anytype, encoded_symbol_count: usize, weights
109 const weights_byte_count = (encoded_symbol_count + 1) / 2;109 const weights_byte_count = (encoded_symbol_count + 1) / 2;
110 for (0..weights_byte_count) |i| {110 for (0..weights_byte_count) |i| {
111 const byte = try source.readByte();111 const byte = try source.readByte();
112 weights[2 * i] = @intCast(u4, byte >> 4);112 weights[2 * i] = @as(u4, @intCast(byte >> 4));
113 weights[2 * i + 1] = @intCast(u4, byte & 0xF);113 weights[2 * i + 1] = @as(u4, @intCast(byte & 0xF));
114 }114 }
115 return encoded_symbol_count + 1;115 return encoded_symbol_count + 1;
116}116}
...@@ -118,7 +118,7 @@ fn decodeDirectHuffmanTree(source: anytype, encoded_symbol_count: usize, weights...@@ -118,7 +118,7 @@ fn decodeDirectHuffmanTree(source: anytype, encoded_symbol_count: usize, weights
118fn assignSymbols(weight_sorted_prefixed_symbols: []LiteralsSection.HuffmanTree.PrefixedSymbol, weights: [256]u4) usize {118fn assignSymbols(weight_sorted_prefixed_symbols: []LiteralsSection.HuffmanTree.PrefixedSymbol, weights: [256]u4) usize {
119 for (0..weight_sorted_prefixed_symbols.len) |i| {119 for (0..weight_sorted_prefixed_symbols.len) |i| {
120 weight_sorted_prefixed_symbols[i] = .{120 weight_sorted_prefixed_symbols[i] = .{
121 .symbol = @intCast(u8, i),121 .symbol = @as(u8, @intCast(i)),
122 .weight = undefined,122 .weight = undefined,
123 .prefix = undefined,123 .prefix = undefined,
124 };124 };
...@@ -167,7 +167,7 @@ fn buildHuffmanTree(weights: *[256]u4, symbol_count: usize) error{MalformedHuffm...@@ -167,7 +167,7 @@ fn buildHuffmanTree(weights: *[256]u4, symbol_count: usize) error{MalformedHuffm
167 weight_power_sum_big += (@as(u16, 1) << value) >> 1;167 weight_power_sum_big += (@as(u16, 1) << value) >> 1;
168 }168 }
169 if (weight_power_sum_big >= 1 << 11) return error.MalformedHuffmanTree;169 if (weight_power_sum_big >= 1 << 11) return error.MalformedHuffmanTree;
170 const weight_power_sum = @intCast(u16, weight_power_sum_big);170 const weight_power_sum = @as(u16, @intCast(weight_power_sum_big));
171171
172 // advance to next power of two (even if weight_power_sum is a power of 2)172 // advance to next power of two (even if weight_power_sum is a power of 2)
173 // TODO: is it valid to have weight_power_sum == 0?173 // TODO: is it valid to have weight_power_sum == 0?
...@@ -179,7 +179,7 @@ fn buildHuffmanTree(weights: *[256]u4, symbol_count: usize) error{MalformedHuffm...@@ -179,7 +179,7 @@ fn buildHuffmanTree(weights: *[256]u4, symbol_count: usize) error{MalformedHuffm
179 const prefixed_symbol_count = assignSymbols(weight_sorted_prefixed_symbols[0..symbol_count], weights.*);179 const prefixed_symbol_count = assignSymbols(weight_sorted_prefixed_symbols[0..symbol_count], weights.*);
180 const tree = LiteralsSection.HuffmanTree{180 const tree = LiteralsSection.HuffmanTree{
181 .max_bit_count = max_number_of_bits,181 .max_bit_count = max_number_of_bits,
182 .symbol_count_minus_one = @intCast(u8, prefixed_symbol_count - 1),182 .symbol_count_minus_one = @as(u8, @intCast(prefixed_symbol_count - 1)),
183 .nodes = weight_sorted_prefixed_symbols,183 .nodes = weight_sorted_prefixed_symbols,
184 };184 };
185 return tree;185 return tree;
lib/std/compress/zstandard/decompress.zig+4-4
...@@ -260,7 +260,7 @@ pub fn decodeFrameArrayList(...@@ -260,7 +260,7 @@ pub fn decodeFrameArrayList(
260/// Returns the frame checksum corresponding to the data fed into `hasher`260/// Returns the frame checksum corresponding to the data fed into `hasher`
261pub fn computeChecksum(hasher: *std.hash.XxHash64) u32 {261pub fn computeChecksum(hasher: *std.hash.XxHash64) u32 {
262 const hash = hasher.final();262 const hash = hasher.final();
263 return @intCast(u32, hash & 0xFFFFFFFF);263 return @as(u32, @intCast(hash & 0xFFFFFFFF));
264}264}
265265
266const FrameError = error{266const FrameError = error{
...@@ -398,7 +398,7 @@ pub const FrameContext = struct {...@@ -398,7 +398,7 @@ pub const FrameContext = struct {
398 const window_size = if (window_size_raw > window_size_max)398 const window_size = if (window_size_raw > window_size_max)
399 return error.WindowTooLarge399 return error.WindowTooLarge
400 else400 else
401 @intCast(usize, window_size_raw);401 @as(usize, @intCast(window_size_raw));
402402
403 const should_compute_checksum =403 const should_compute_checksum =
404 frame_header.descriptor.content_checksum_flag and verify_checksum;404 frame_header.descriptor.content_checksum_flag and verify_checksum;
...@@ -585,7 +585,7 @@ pub fn frameWindowSize(header: ZstandardHeader) ?u64 {...@@ -585,7 +585,7 @@ pub fn frameWindowSize(header: ZstandardHeader) ?u64 {
585 const exponent = (descriptor & 0b11111000) >> 3;585 const exponent = (descriptor & 0b11111000) >> 3;
586 const mantissa = descriptor & 0b00000111;586 const mantissa = descriptor & 0b00000111;
587 const window_log = 10 + exponent;587 const window_log = 10 + exponent;
588 const window_base = @as(u64, 1) << @intCast(u6, window_log);588 const window_base = @as(u64, 1) << @as(u6, @intCast(window_log));
589 const window_add = (window_base / 8) * mantissa;589 const window_add = (window_base / 8) * mantissa;
590 return window_base + window_add;590 return window_base + window_add;
591 } else return header.content_size;591 } else return header.content_size;
...@@ -599,7 +599,7 @@ pub fn frameWindowSize(header: ZstandardHeader) ?u64 {...@@ -599,7 +599,7 @@ pub fn frameWindowSize(header: ZstandardHeader) ?u64 {
599pub fn decodeZstandardHeader(599pub fn decodeZstandardHeader(
600 source: anytype,600 source: anytype,
601) (@TypeOf(source).Error || error{ EndOfStream, ReservedBitSet })!ZstandardHeader {601) (@TypeOf(source).Error || error{ EndOfStream, ReservedBitSet })!ZstandardHeader {
602 const descriptor = @bitCast(ZstandardHeader.Descriptor, try source.readByte());602 const descriptor = @as(ZstandardHeader.Descriptor, @bitCast(try source.readByte()));
603603
604 if (descriptor.reserved) return error.ReservedBitSet;604 if (descriptor.reserved) return error.ReservedBitSet;
605605
lib/std/crypto/25519/curve25519.zig+1-1
...@@ -54,7 +54,7 @@ pub const Curve25519 = struct {...@@ -54,7 +54,7 @@ pub const Curve25519 = struct {
54 var swap: u8 = 0;54 var swap: u8 = 0;
55 var pos: usize = bits - 1;55 var pos: usize = bits - 1;
56 while (true) : (pos -= 1) {56 while (true) : (pos -= 1) {
57 const bit = (s[pos >> 3] >> @truncate(u3, pos)) & 1;57 const bit = (s[pos >> 3] >> @as(u3, @truncate(pos))) & 1;
58 swap ^= bit;58 swap ^= bit;
59 Fe.cSwap2(&x2, &x3, &z2, &z3, swap);59 Fe.cSwap2(&x2, &x3, &z2, &z3, swap);
60 swap = bit;60 swap = bit;
lib/std/crypto/25519/edwards25519.zig+12-12
...@@ -162,8 +162,8 @@ pub const Edwards25519 = struct {...@@ -162,8 +162,8 @@ pub const Edwards25519 = struct {
162 const reduced = if ((s[s.len - 1] & 0x80) == 0) s else scalar.reduce(s);162 const reduced = if ((s[s.len - 1] & 0x80) == 0) s else scalar.reduce(s);
163 var e: [2 * 32]i8 = undefined;163 var e: [2 * 32]i8 = undefined;
164 for (reduced, 0..) |x, i| {164 for (reduced, 0..) |x, i| {
165 e[i * 2 + 0] = @as(i8, @truncate(u4, x));165 e[i * 2 + 0] = @as(i8, @as(u4, @truncate(x)));
166 e[i * 2 + 1] = @as(i8, @truncate(u4, x >> 4));166 e[i * 2 + 1] = @as(i8, @as(u4, @truncate(x >> 4)));
167 }167 }
168 // Now, e[0..63] is between 0 and 15, e[63] is between 0 and 7168 // Now, e[0..63] is between 0 and 15, e[63] is between 0 and 7
169 var carry: i8 = 0;169 var carry: i8 = 0;
...@@ -190,9 +190,9 @@ pub const Edwards25519 = struct {...@@ -190,9 +190,9 @@ pub const Edwards25519 = struct {
190 while (true) : (pos -= 1) {190 while (true) : (pos -= 1) {
191 const slot = e[pos];191 const slot = e[pos];
192 if (slot > 0) {192 if (slot > 0) {
193 q = q.add(pc[@intCast(usize, slot)]);193 q = q.add(pc[@as(usize, @intCast(slot))]);
194 } else if (slot < 0) {194 } else if (slot < 0) {
195 q = q.sub(pc[@intCast(usize, -slot)]);195 q = q.sub(pc[@as(usize, @intCast(-slot))]);
196 }196 }
197 if (pos == 0) break;197 if (pos == 0) break;
198 q = q.dbl().dbl().dbl().dbl();198 q = q.dbl().dbl().dbl().dbl();
...@@ -206,7 +206,7 @@ pub const Edwards25519 = struct {...@@ -206,7 +206,7 @@ pub const Edwards25519 = struct {
206 var q = Edwards25519.identityElement;206 var q = Edwards25519.identityElement;
207 var pos: usize = 252;207 var pos: usize = 252;
208 while (true) : (pos -= 4) {208 while (true) : (pos -= 4) {
209 const slot = @truncate(u4, (s[pos >> 3] >> @truncate(u3, pos)));209 const slot = @as(u4, @truncate((s[pos >> 3] >> @as(u3, @truncate(pos)))));
210 if (vartime) {210 if (vartime) {
211 if (slot != 0) {211 if (slot != 0) {
212 q = q.add(pc[slot]);212 q = q.add(pc[slot]);
...@@ -283,15 +283,15 @@ pub const Edwards25519 = struct {...@@ -283,15 +283,15 @@ pub const Edwards25519 = struct {
283 while (true) : (pos -= 1) {283 while (true) : (pos -= 1) {
284 const slot1 = e1[pos];284 const slot1 = e1[pos];
285 if (slot1 > 0) {285 if (slot1 > 0) {
286 q = q.add(pc1[@intCast(usize, slot1)]);286 q = q.add(pc1[@as(usize, @intCast(slot1))]);
287 } else if (slot1 < 0) {287 } else if (slot1 < 0) {
288 q = q.sub(pc1[@intCast(usize, -slot1)]);288 q = q.sub(pc1[@as(usize, @intCast(-slot1))]);
289 }289 }
290 const slot2 = e2[pos];290 const slot2 = e2[pos];
291 if (slot2 > 0) {291 if (slot2 > 0) {
292 q = q.add(pc2[@intCast(usize, slot2)]);292 q = q.add(pc2[@as(usize, @intCast(slot2))]);
293 } else if (slot2 < 0) {293 } else if (slot2 < 0) {
294 q = q.sub(pc2[@intCast(usize, -slot2)]);294 q = q.sub(pc2[@as(usize, @intCast(-slot2))]);
295 }295 }
296 if (pos == 0) break;296 if (pos == 0) break;
297 q = q.dbl().dbl().dbl().dbl();297 q = q.dbl().dbl().dbl().dbl();
...@@ -326,9 +326,9 @@ pub const Edwards25519 = struct {...@@ -326,9 +326,9 @@ pub const Edwards25519 = struct {
326 for (es, 0..) |e, i| {326 for (es, 0..) |e, i| {
327 const slot = e[pos];327 const slot = e[pos];
328 if (slot > 0) {328 if (slot > 0) {
329 q = q.add(pcs[i][@intCast(usize, slot)]);329 q = q.add(pcs[i][@as(usize, @intCast(slot))]);
330 } else if (slot < 0) {330 } else if (slot < 0) {
331 q = q.sub(pcs[i][@intCast(usize, -slot)]);331 q = q.sub(pcs[i][@as(usize, @intCast(-slot))]);
332 }332 }
333 }333 }
334 if (pos == 0) break;334 if (pos == 0) break;
...@@ -427,7 +427,7 @@ pub const Edwards25519 = struct {...@@ -427,7 +427,7 @@ pub const Edwards25519 = struct {
427 }427 }
428 const empty_block = [_]u8{0} ** H.block_length;428 const empty_block = [_]u8{0} ** H.block_length;
429 var t = [3]u8{ 0, n * h_l, 0 };429 var t = [3]u8{ 0, n * h_l, 0 };
430 var xctx_len_u8 = [1]u8{@intCast(u8, xctx.len)};430 var xctx_len_u8 = [1]u8{@as(u8, @intCast(xctx.len))};
431 var st = H.init(.{});431 var st = H.init(.{});
432 st.update(empty_block[0..]);432 st.update(empty_block[0..]);
433 st.update(s);433 st.update(s);
lib/std/crypto/25519/field.zig+11-11
...@@ -254,11 +254,11 @@ pub const Fe = struct {...@@ -254,11 +254,11 @@ pub const Fe = struct {
254 var rs: [5]u64 = undefined;254 var rs: [5]u64 = undefined;
255 comptime var i = 0;255 comptime var i = 0;
256 inline while (i < 4) : (i += 1) {256 inline while (i < 4) : (i += 1) {
257 rs[i] = @truncate(u64, r[i]) & MASK51;257 rs[i] = @as(u64, @truncate(r[i])) & MASK51;
258 r[i + 1] += @intCast(u64, r[i] >> 51);258 r[i + 1] += @as(u64, @intCast(r[i] >> 51));
259 }259 }
260 rs[4] = @truncate(u64, r[4]) & MASK51;260 rs[4] = @as(u64, @truncate(r[4])) & MASK51;
261 var carry = @intCast(u64, r[4] >> 51);261 var carry = @as(u64, @intCast(r[4] >> 51));
262 rs[0] += 19 * carry;262 rs[0] += 19 * carry;
263 carry = rs[0] >> 51;263 carry = rs[0] >> 51;
264 rs[0] &= MASK51;264 rs[0] &= MASK51;
...@@ -278,8 +278,8 @@ pub const Fe = struct {...@@ -278,8 +278,8 @@ pub const Fe = struct {
278 var r: [5]u128 = undefined;278 var r: [5]u128 = undefined;
279 comptime var i = 0;279 comptime var i = 0;
280 inline while (i < 5) : (i += 1) {280 inline while (i < 5) : (i += 1) {
281 ax[i] = @intCast(u128, a.limbs[i]);281 ax[i] = @as(u128, @intCast(a.limbs[i]));
282 bx[i] = @intCast(u128, b.limbs[i]);282 bx[i] = @as(u128, @intCast(b.limbs[i]));
283 }283 }
284 i = 1;284 i = 1;
285 inline while (i < 5) : (i += 1) {285 inline while (i < 5) : (i += 1) {
...@@ -299,7 +299,7 @@ pub const Fe = struct {...@@ -299,7 +299,7 @@ pub const Fe = struct {
299 var r: [5]u128 = undefined;299 var r: [5]u128 = undefined;
300 comptime var i = 0;300 comptime var i = 0;
301 inline while (i < 5) : (i += 1) {301 inline while (i < 5) : (i += 1) {
302 ax[i] = @intCast(u128, a.limbs[i]);302 ax[i] = @as(u128, @intCast(a.limbs[i]));
303 }303 }
304 const a0_2 = 2 * ax[0];304 const a0_2 = 2 * ax[0];
305 const a1_2 = 2 * ax[1];305 const a1_2 = 2 * ax[1];
...@@ -334,15 +334,15 @@ pub const Fe = struct {...@@ -334,15 +334,15 @@ pub const Fe = struct {
334334
335 /// Multiply a field element with a small (32-bit) integer335 /// Multiply a field element with a small (32-bit) integer
336 pub inline fn mul32(a: Fe, comptime n: u32) Fe {336 pub inline fn mul32(a: Fe, comptime n: u32) Fe {
337 const sn = @intCast(u128, n);337 const sn = @as(u128, @intCast(n));
338 var fe: Fe = undefined;338 var fe: Fe = undefined;
339 var x: u128 = 0;339 var x: u128 = 0;
340 comptime var i = 0;340 comptime var i = 0;
341 inline while (i < 5) : (i += 1) {341 inline while (i < 5) : (i += 1) {
342 x = a.limbs[i] * sn + (x >> 51);342 x = a.limbs[i] * sn + (x >> 51);
343 fe.limbs[i] = @truncate(u64, x) & MASK51;343 fe.limbs[i] = @as(u64, @truncate(x)) & MASK51;
344 }344 }
345 fe.limbs[0] += @intCast(u64, x >> 51) * 19;345 fe.limbs[0] += @as(u64, @intCast(x >> 51)) * 19;
346346
347 return fe;347 return fe;
348 }348 }
...@@ -402,7 +402,7 @@ pub const Fe = struct {...@@ -402,7 +402,7 @@ pub const Fe = struct {
402 const t2 = t.sqn(30).mul(t);402 const t2 = t.sqn(30).mul(t);
403 const t3 = t2.sqn(60).mul(t2);403 const t3 = t2.sqn(60).mul(t2);
404 const t4 = t3.sqn(120).mul(t3).sqn(10).mul(u).sqn(3).mul(_11).sq();404 const t4 = t3.sqn(120).mul(t3).sqn(10).mul(u).sqn(3).mul(_11).sq();
405 return @bitCast(bool, @truncate(u1, ~(t4.toBytes()[1] & 1)));405 return @as(bool, @bitCast(@as(u1, @truncate(~(t4.toBytes()[1] & 1)))));
406 }406 }
407407
408 fn uncheckedSqrt(x2: Fe) Fe {408 fn uncheckedSqrt(x2: Fe) Fe {
lib/std/crypto/25519/scalar.zig+37-37
...@@ -27,8 +27,8 @@ pub fn rejectNonCanonical(s: CompressedScalar) NonCanonicalError!void {...@@ -27,8 +27,8 @@ pub fn rejectNonCanonical(s: CompressedScalar) NonCanonicalError!void {
27 while (true) : (i -= 1) {27 while (true) : (i -= 1) {
28 const xs = @as(u16, s[i]);28 const xs = @as(u16, s[i]);
29 const xfield_order_s = @as(u16, field_order_s[i]);29 const xfield_order_s = @as(u16, field_order_s[i]);
30 c |= @intCast(u8, ((xs -% xfield_order_s) >> 8) & n);30 c |= @as(u8, @intCast(((xs -% xfield_order_s) >> 8) & n));
31 n &= @intCast(u8, ((xs ^ xfield_order_s) -% 1) >> 8);31 n &= @as(u8, @intCast(((xs ^ xfield_order_s) -% 1) >> 8));
32 if (i == 0) break;32 if (i == 0) break;
33 }33 }
34 if (c == 0) {34 if (c == 0) {
...@@ -89,7 +89,7 @@ pub fn neg(s: CompressedScalar) CompressedScalar {...@@ -89,7 +89,7 @@ pub fn neg(s: CompressedScalar) CompressedScalar {
89 var i: usize = 0;89 var i: usize = 0;
90 while (i < 64) : (i += 1) {90 while (i < 64) : (i += 1) {
91 carry = @as(u32, fs[i]) -% sx[i] -% @as(u32, carry);91 carry = @as(u32, fs[i]) -% sx[i] -% @as(u32, carry);
92 sx[i] = @truncate(u8, carry);92 sx[i] = @as(u8, @truncate(carry));
93 carry = (carry >> 8) & 1;93 carry = (carry >> 8) & 1;
94 }94 }
95 return reduce64(sx);95 return reduce64(sx);
...@@ -129,7 +129,7 @@ pub const Scalar = struct {...@@ -129,7 +129,7 @@ pub const Scalar = struct {
129 while (i < 4) : (i += 1) {129 while (i < 4) : (i += 1) {
130 mem.writeIntLittle(u64, bytes[i * 7 ..][0..8], expanded.limbs[i]);130 mem.writeIntLittle(u64, bytes[i * 7 ..][0..8], expanded.limbs[i]);
131 }131 }
132 mem.writeIntLittle(u32, bytes[i * 7 ..][0..4], @intCast(u32, expanded.limbs[i]));132 mem.writeIntLittle(u32, bytes[i * 7 ..][0..4], @as(u32, @intCast(expanded.limbs[i])));
133 return bytes;133 return bytes;
134 }134 }
135135
...@@ -234,42 +234,42 @@ pub const Scalar = struct {...@@ -234,42 +234,42 @@ pub const Scalar = struct {
234 const z80 = xy440;234 const z80 = xy440;
235235
236 const carry0 = z00 >> 56;236 const carry0 = z00 >> 56;
237 const t10 = @truncate(u64, z00) & 0xffffffffffffff;237 const t10 = @as(u64, @truncate(z00)) & 0xffffffffffffff;
238 const c00 = carry0;238 const c00 = carry0;
239 const t00 = t10;239 const t00 = t10;
240 const carry1 = (z10 + c00) >> 56;240 const carry1 = (z10 + c00) >> 56;
241 const t11 = @truncate(u64, (z10 + c00)) & 0xffffffffffffff;241 const t11 = @as(u64, @truncate((z10 + c00))) & 0xffffffffffffff;
242 const c10 = carry1;242 const c10 = carry1;
243 const t12 = t11;243 const t12 = t11;
244 const carry2 = (z20 + c10) >> 56;244 const carry2 = (z20 + c10) >> 56;
245 const t13 = @truncate(u64, (z20 + c10)) & 0xffffffffffffff;245 const t13 = @as(u64, @truncate((z20 + c10))) & 0xffffffffffffff;
246 const c20 = carry2;246 const c20 = carry2;
247 const t20 = t13;247 const t20 = t13;
248 const carry3 = (z30 + c20) >> 56;248 const carry3 = (z30 + c20) >> 56;
249 const t14 = @truncate(u64, (z30 + c20)) & 0xffffffffffffff;249 const t14 = @as(u64, @truncate((z30 + c20))) & 0xffffffffffffff;
250 const c30 = carry3;250 const c30 = carry3;
251 const t30 = t14;251 const t30 = t14;
252 const carry4 = (z40 + c30) >> 56;252 const carry4 = (z40 + c30) >> 56;
253 const t15 = @truncate(u64, (z40 + c30)) & 0xffffffffffffff;253 const t15 = @as(u64, @truncate((z40 + c30))) & 0xffffffffffffff;
254 const c40 = carry4;254 const c40 = carry4;
255 const t40 = t15;255 const t40 = t15;
256 const carry5 = (z50 + c40) >> 56;256 const carry5 = (z50 + c40) >> 56;
257 const t16 = @truncate(u64, (z50 + c40)) & 0xffffffffffffff;257 const t16 = @as(u64, @truncate((z50 + c40))) & 0xffffffffffffff;
258 const c50 = carry5;258 const c50 = carry5;
259 const t50 = t16;259 const t50 = t16;
260 const carry6 = (z60 + c50) >> 56;260 const carry6 = (z60 + c50) >> 56;
261 const t17 = @truncate(u64, (z60 + c50)) & 0xffffffffffffff;261 const t17 = @as(u64, @truncate((z60 + c50))) & 0xffffffffffffff;
262 const c60 = carry6;262 const c60 = carry6;
263 const t60 = t17;263 const t60 = t17;
264 const carry7 = (z70 + c60) >> 56;264 const carry7 = (z70 + c60) >> 56;
265 const t18 = @truncate(u64, (z70 + c60)) & 0xffffffffffffff;265 const t18 = @as(u64, @truncate((z70 + c60))) & 0xffffffffffffff;
266 const c70 = carry7;266 const c70 = carry7;
267 const t70 = t18;267 const t70 = t18;
268 const carry8 = (z80 + c70) >> 56;268 const carry8 = (z80 + c70) >> 56;
269 const t19 = @truncate(u64, (z80 + c70)) & 0xffffffffffffff;269 const t19 = @as(u64, @truncate((z80 + c70))) & 0xffffffffffffff;
270 const c80 = carry8;270 const c80 = carry8;
271 const t80 = t19;271 const t80 = t19;
272 const t90 = (@truncate(u64, c80));272 const t90 = (@as(u64, @truncate(c80)));
273 const r0 = t00;273 const r0 = t00;
274 const r1 = t12;274 const r1 = t12;
275 const r2 = t20;275 const r2 = t20;
...@@ -356,26 +356,26 @@ pub const Scalar = struct {...@@ -356,26 +356,26 @@ pub const Scalar = struct {
356 const carry12 = (z32 + c21) >> 56;356 const carry12 = (z32 + c21) >> 56;
357 const c31 = carry12;357 const c31 = carry12;
358 const carry13 = (z42 + c31) >> 56;358 const carry13 = (z42 + c31) >> 56;
359 const t24 = @truncate(u64, z42 + c31) & 0xffffffffffffff;359 const t24 = @as(u64, @truncate(z42 + c31)) & 0xffffffffffffff;
360 const c41 = carry13;360 const c41 = carry13;
361 const t41 = t24;361 const t41 = t24;
362 const carry14 = (z5 + c41) >> 56;362 const carry14 = (z5 + c41) >> 56;
363 const t25 = @truncate(u64, z5 + c41) & 0xffffffffffffff;363 const t25 = @as(u64, @truncate(z5 + c41)) & 0xffffffffffffff;
364 const c5 = carry14;364 const c5 = carry14;
365 const t5 = t25;365 const t5 = t25;
366 const carry15 = (z6 + c5) >> 56;366 const carry15 = (z6 + c5) >> 56;
367 const t26 = @truncate(u64, z6 + c5) & 0xffffffffffffff;367 const t26 = @as(u64, @truncate(z6 + c5)) & 0xffffffffffffff;
368 const c6 = carry15;368 const c6 = carry15;
369 const t6 = t26;369 const t6 = t26;
370 const carry16 = (z7 + c6) >> 56;370 const carry16 = (z7 + c6) >> 56;
371 const t27 = @truncate(u64, z7 + c6) & 0xffffffffffffff;371 const t27 = @as(u64, @truncate(z7 + c6)) & 0xffffffffffffff;
372 const c7 = carry16;372 const c7 = carry16;
373 const t7 = t27;373 const t7 = t27;
374 const carry17 = (z8 + c7) >> 56;374 const carry17 = (z8 + c7) >> 56;
375 const t28 = @truncate(u64, z8 + c7) & 0xffffffffffffff;375 const t28 = @as(u64, @truncate(z8 + c7)) & 0xffffffffffffff;
376 const c8 = carry17;376 const c8 = carry17;
377 const t8 = t28;377 const t8 = t28;
378 const t9 = @truncate(u64, c8);378 const t9 = @as(u64, @truncate(c8));
379379
380 const qmu4_ = t41;380 const qmu4_ = t41;
381 const qmu5_ = t5;381 const qmu5_ = t5;
...@@ -425,22 +425,22 @@ pub const Scalar = struct {...@@ -425,22 +425,22 @@ pub const Scalar = struct {
425 const xy31 = @as(u128, qdiv3) * @as(u128, m1);425 const xy31 = @as(u128, qdiv3) * @as(u128, m1);
426 const xy40 = @as(u128, qdiv4) * @as(u128, m0);426 const xy40 = @as(u128, qdiv4) * @as(u128, m0);
427 const carry18 = xy00 >> 56;427 const carry18 = xy00 >> 56;
428 const t29 = @truncate(u64, xy00) & 0xffffffffffffff;428 const t29 = @as(u64, @truncate(xy00)) & 0xffffffffffffff;
429 const c0 = carry18;429 const c0 = carry18;
430 const t01 = t29;430 const t01 = t29;
431 const carry19 = (xy01 + xy10 + c0) >> 56;431 const carry19 = (xy01 + xy10 + c0) >> 56;
432 const t31 = @truncate(u64, xy01 + xy10 + c0) & 0xffffffffffffff;432 const t31 = @as(u64, @truncate(xy01 + xy10 + c0)) & 0xffffffffffffff;
433 const c12 = carry19;433 const c12 = carry19;
434 const t110 = t31;434 const t110 = t31;
435 const carry20 = (xy02 + xy11 + xy20 + c12) >> 56;435 const carry20 = (xy02 + xy11 + xy20 + c12) >> 56;
436 const t32 = @truncate(u64, xy02 + xy11 + xy20 + c12) & 0xffffffffffffff;436 const t32 = @as(u64, @truncate(xy02 + xy11 + xy20 + c12)) & 0xffffffffffffff;
437 const c22 = carry20;437 const c22 = carry20;
438 const t210 = t32;438 const t210 = t32;
439 const carry = (xy03 + xy12 + xy21 + xy30 + c22) >> 56;439 const carry = (xy03 + xy12 + xy21 + xy30 + c22) >> 56;
440 const t33 = @truncate(u64, xy03 + xy12 + xy21 + xy30 + c22) & 0xffffffffffffff;440 const t33 = @as(u64, @truncate(xy03 + xy12 + xy21 + xy30 + c22)) & 0xffffffffffffff;
441 const c32 = carry;441 const c32 = carry;
442 const t34 = t33;442 const t34 = t33;
443 const t42 = @truncate(u64, xy04 + xy13 + xy22 + xy31 + xy40 + c32) & 0xffffffffff;443 const t42 = @as(u64, @truncate(xy04 + xy13 + xy22 + xy31 + xy40 + c32)) & 0xffffffffff;
444444
445 const qmul0 = t01;445 const qmul0 = t01;
446 const qmul1 = t110;446 const qmul1 = t110;
...@@ -498,7 +498,7 @@ pub const Scalar = struct {...@@ -498,7 +498,7 @@ pub const Scalar = struct {
498 const t = ((b << 56) + s4) -% (y41 + b3);498 const t = ((b << 56) + s4) -% (y41 + b3);
499 const b4 = b;499 const b4 = b;
500 const t4 = t;500 const t4 = t;
501 const mask = (b4 -% @intCast(u64, ((1))));501 const mask = (b4 -% @as(u64, @intCast(((1)))));
502 const z04 = s0 ^ (mask & (s0 ^ t0));502 const z04 = s0 ^ (mask & (s0 ^ t0));
503 const z14 = s1 ^ (mask & (s1 ^ t1));503 const z14 = s1 ^ (mask & (s1 ^ t1));
504 const z24 = s2 ^ (mask & (s2 ^ t2));504 const z24 = s2 ^ (mask & (s2 ^ t2));
...@@ -691,26 +691,26 @@ const ScalarDouble = struct {...@@ -691,26 +691,26 @@ const ScalarDouble = struct {
691 const carry3 = (z31 + c20) >> 56;691 const carry3 = (z31 + c20) >> 56;
692 const c30 = carry3;692 const c30 = carry3;
693 const carry4 = (z41 + c30) >> 56;693 const carry4 = (z41 + c30) >> 56;
694 const t103 = @as(u64, @truncate(u64, z41 + c30)) & 0xffffffffffffff;694 const t103 = @as(u64, @as(u64, @truncate(z41 + c30))) & 0xffffffffffffff;
695 const c40 = carry4;695 const c40 = carry4;
696 const t410 = t103;696 const t410 = t103;
697 const carry5 = (z5 + c40) >> 56;697 const carry5 = (z5 + c40) >> 56;
698 const t104 = @as(u64, @truncate(u64, z5 + c40)) & 0xffffffffffffff;698 const t104 = @as(u64, @as(u64, @truncate(z5 + c40))) & 0xffffffffffffff;
699 const c5 = carry5;699 const c5 = carry5;
700 const t51 = t104;700 const t51 = t104;
701 const carry6 = (z6 + c5) >> 56;701 const carry6 = (z6 + c5) >> 56;
702 const t105 = @as(u64, @truncate(u64, z6 + c5)) & 0xffffffffffffff;702 const t105 = @as(u64, @as(u64, @truncate(z6 + c5))) & 0xffffffffffffff;
703 const c6 = carry6;703 const c6 = carry6;
704 const t61 = t105;704 const t61 = t105;
705 const carry7 = (z7 + c6) >> 56;705 const carry7 = (z7 + c6) >> 56;
706 const t106 = @as(u64, @truncate(u64, z7 + c6)) & 0xffffffffffffff;706 const t106 = @as(u64, @as(u64, @truncate(z7 + c6))) & 0xffffffffffffff;
707 const c7 = carry7;707 const c7 = carry7;
708 const t71 = t106;708 const t71 = t106;
709 const carry8 = (z8 + c7) >> 56;709 const carry8 = (z8 + c7) >> 56;
710 const t107 = @as(u64, @truncate(u64, z8 + c7)) & 0xffffffffffffff;710 const t107 = @as(u64, @as(u64, @truncate(z8 + c7))) & 0xffffffffffffff;
711 const c8 = carry8;711 const c8 = carry8;
712 const t81 = t107;712 const t81 = t107;
713 const t91 = @as(u64, @truncate(u64, c8));713 const t91 = @as(u64, @as(u64, @truncate(c8)));
714714
715 const qmu4_ = t410;715 const qmu4_ = t410;
716 const qmu5_ = t51;716 const qmu5_ = t51;
...@@ -760,22 +760,22 @@ const ScalarDouble = struct {...@@ -760,22 +760,22 @@ const ScalarDouble = struct {
760 const xy31 = @as(u128, qdiv3) * @as(u128, m1);760 const xy31 = @as(u128, qdiv3) * @as(u128, m1);
761 const xy40 = @as(u128, qdiv4) * @as(u128, m0);761 const xy40 = @as(u128, qdiv4) * @as(u128, m0);
762 const carry9 = xy00 >> 56;762 const carry9 = xy00 >> 56;
763 const t108 = @truncate(u64, xy00) & 0xffffffffffffff;763 const t108 = @as(u64, @truncate(xy00)) & 0xffffffffffffff;
764 const c0 = carry9;764 const c0 = carry9;
765 const t010 = t108;765 const t010 = t108;
766 const carry10 = (xy01 + xy10 + c0) >> 56;766 const carry10 = (xy01 + xy10 + c0) >> 56;
767 const t109 = @truncate(u64, xy01 + xy10 + c0) & 0xffffffffffffff;767 const t109 = @as(u64, @truncate(xy01 + xy10 + c0)) & 0xffffffffffffff;
768 const c11 = carry10;768 const c11 = carry10;
769 const t110 = t109;769 const t110 = t109;
770 const carry11 = (xy02 + xy11 + xy20 + c11) >> 56;770 const carry11 = (xy02 + xy11 + xy20 + c11) >> 56;
771 const t1010 = @truncate(u64, xy02 + xy11 + xy20 + c11) & 0xffffffffffffff;771 const t1010 = @as(u64, @truncate(xy02 + xy11 + xy20 + c11)) & 0xffffffffffffff;
772 const c21 = carry11;772 const c21 = carry11;
773 const t210 = t1010;773 const t210 = t1010;
774 const carry = (xy03 + xy12 + xy21 + xy30 + c21) >> 56;774 const carry = (xy03 + xy12 + xy21 + xy30 + c21) >> 56;
775 const t1011 = @truncate(u64, xy03 + xy12 + xy21 + xy30 + c21) & 0xffffffffffffff;775 const t1011 = @as(u64, @truncate(xy03 + xy12 + xy21 + xy30 + c21)) & 0xffffffffffffff;
776 const c31 = carry;776 const c31 = carry;
777 const t310 = t1011;777 const t310 = t1011;
778 const t411 = @truncate(u64, xy04 + xy13 + xy22 + xy31 + xy40 + c31) & 0xffffffffff;778 const t411 = @as(u64, @truncate(xy04 + xy13 + xy22 + xy31 + xy40 + c31)) & 0xffffffffff;
779779
780 const qmul0 = t010;780 const qmul0 = t010;
781 const qmul1 = t110;781 const qmul1 = t110;
lib/std/crypto/Certificate.zig+11-11
...@@ -312,7 +312,7 @@ pub const Parsed = struct {...@@ -312,7 +312,7 @@ pub const Parsed = struct {
312 while (name_i < general_names.slice.end) {312 while (name_i < general_names.slice.end) {
313 const general_name = try der.Element.parse(subject_alt_name, name_i);313 const general_name = try der.Element.parse(subject_alt_name, name_i);
314 name_i = general_name.slice.end;314 name_i = general_name.slice.end;
315 switch (@enumFromInt(GeneralNameTag, @intFromEnum(general_name.identifier.tag))) {315 switch (@as(GeneralNameTag, @enumFromInt(@intFromEnum(general_name.identifier.tag)))) {
316 .dNSName => {316 .dNSName => {
317 const dns_name = subject_alt_name[general_name.slice.start..general_name.slice.end];317 const dns_name = subject_alt_name[general_name.slice.start..general_name.slice.end];
318 if (checkHostName(host_name, dns_name)) return;318 if (checkHostName(host_name, dns_name)) return;
...@@ -379,7 +379,7 @@ pub fn parse(cert: Certificate) ParseError!Parsed {...@@ -379,7 +379,7 @@ pub fn parse(cert: Certificate) ParseError!Parsed {
379 const tbs_certificate = try der.Element.parse(cert_bytes, certificate.slice.start);379 const tbs_certificate = try der.Element.parse(cert_bytes, certificate.slice.start);
380 const version_elem = try der.Element.parse(cert_bytes, tbs_certificate.slice.start);380 const version_elem = try der.Element.parse(cert_bytes, tbs_certificate.slice.start);
381 const version = try parseVersion(cert_bytes, version_elem);381 const version = try parseVersion(cert_bytes, version_elem);
382 const serial_number = if (@bitCast(u8, version_elem.identifier) == 0xa0)382 const serial_number = if (@as(u8, @bitCast(version_elem.identifier)) == 0xa0)
383 try der.Element.parse(cert_bytes, version_elem.slice.end)383 try der.Element.parse(cert_bytes, version_elem.slice.end)
384 else384 else
385 version_elem;385 version_elem;
...@@ -597,8 +597,8 @@ const Date = struct {...@@ -597,8 +597,8 @@ const Date = struct {
597 var month: u4 = 1;597 var month: u4 = 1;
598 while (month < date.month) : (month += 1) {598 while (month < date.month) : (month += 1) {
599 const days: u64 = std.time.epoch.getDaysInMonth(599 const days: u64 = std.time.epoch.getDaysInMonth(
600 @enumFromInt(std.time.epoch.YearLeapKind, @intFromBool(is_leap)),600 @as(std.time.epoch.YearLeapKind, @enumFromInt(@intFromBool(is_leap))),
601 @enumFromInt(std.time.epoch.Month, month),601 @as(std.time.epoch.Month, @enumFromInt(month)),
602 );602 );
603 sec += days * std.time.epoch.secs_per_day;603 sec += days * std.time.epoch.secs_per_day;
604 }604 }
...@@ -685,7 +685,7 @@ fn parseEnum(comptime E: type, bytes: []const u8, element: der.Element) ParseEnu...@@ -685,7 +685,7 @@ fn parseEnum(comptime E: type, bytes: []const u8, element: der.Element) ParseEnu
685pub const ParseVersionError = error{ UnsupportedCertificateVersion, CertificateFieldHasInvalidLength };685pub const ParseVersionError = error{ UnsupportedCertificateVersion, CertificateFieldHasInvalidLength };
686686
687pub fn parseVersion(bytes: []const u8, version_elem: der.Element) ParseVersionError!Version {687pub fn parseVersion(bytes: []const u8, version_elem: der.Element) ParseVersionError!Version {
688 if (@bitCast(u8, version_elem.identifier) != 0xa0)688 if (@as(u8, @bitCast(version_elem.identifier)) != 0xa0)
689 return .v1;689 return .v1;
690690
691 if (version_elem.slice.end - version_elem.slice.start != 3)691 if (version_elem.slice.end - version_elem.slice.start != 3)
...@@ -864,7 +864,7 @@ pub const der = struct {...@@ -864,7 +864,7 @@ pub const der = struct {
864864
865 pub fn parse(bytes: []const u8, index: u32) ParseElementError!Element {865 pub fn parse(bytes: []const u8, index: u32) ParseElementError!Element {
866 var i = index;866 var i = index;
867 const identifier = @bitCast(Identifier, bytes[i]);867 const identifier = @as(Identifier, @bitCast(bytes[i]));
868 i += 1;868 i += 1;
869 const size_byte = bytes[i];869 const size_byte = bytes[i];
870 i += 1;870 i += 1;
...@@ -878,7 +878,7 @@ pub const der = struct {...@@ -878,7 +878,7 @@ pub const der = struct {
878 };878 };
879 }879 }
880880
881 const len_size = @truncate(u7, size_byte);881 const len_size = @as(u7, @truncate(size_byte));
882 if (len_size > @sizeOf(u32)) {882 if (len_size > @sizeOf(u32)) {
883 return error.CertificateFieldHasInvalidLength;883 return error.CertificateFieldHasInvalidLength;
884 }884 }
...@@ -1042,10 +1042,10 @@ pub const rsa = struct {...@@ -1042,10 +1042,10 @@ pub const rsa = struct {
1042 var hashed: [Hash.digest_length]u8 = undefined;1042 var hashed: [Hash.digest_length]u8 = undefined;
10431043
1044 while (idx < len) {1044 while (idx < len) {
1045 c[0] = @intCast(u8, (counter >> 24) & 0xFF);1045 c[0] = @as(u8, @intCast((counter >> 24) & 0xFF));
1046 c[1] = @intCast(u8, (counter >> 16) & 0xFF);1046 c[1] = @as(u8, @intCast((counter >> 16) & 0xFF));
1047 c[2] = @intCast(u8, (counter >> 8) & 0xFF);1047 c[2] = @as(u8, @intCast((counter >> 8) & 0xFF));
1048 c[3] = @intCast(u8, counter & 0xFF);1048 c[3] = @as(u8, @intCast(counter & 0xFF));
10491049
1050 std.mem.copyForwards(u8, hash[seed.len..], &c);1050 std.mem.copyForwards(u8, hash[seed.len..], &c);
1051 Hash.hash(&hash, &hashed, .{});1051 Hash.hash(&hash, &hashed, .{});
lib/std/crypto/Certificate/Bundle.zig+3-3
...@@ -131,7 +131,7 @@ pub fn rescanWindows(cb: *Bundle, gpa: Allocator) RescanWindowsError!void {...@@ -131,7 +131,7 @@ pub fn rescanWindows(cb: *Bundle, gpa: Allocator) RescanWindowsError!void {
131131
132 var ctx = w.crypt32.CertEnumCertificatesInStore(store, null);132 var ctx = w.crypt32.CertEnumCertificatesInStore(store, null);
133 while (ctx) |context| : (ctx = w.crypt32.CertEnumCertificatesInStore(store, ctx)) {133 while (ctx) |context| : (ctx = w.crypt32.CertEnumCertificatesInStore(store, ctx)) {
134 const decoded_start = @intCast(u32, cb.bytes.items.len);134 const decoded_start = @as(u32, @intCast(cb.bytes.items.len));
135 const encoded_cert = context.pbCertEncoded[0..context.cbCertEncoded];135 const encoded_cert = context.pbCertEncoded[0..context.cbCertEncoded];
136 try cb.bytes.appendSlice(gpa, encoded_cert);136 try cb.bytes.appendSlice(gpa, encoded_cert);
137 try cb.parseCert(gpa, decoded_start, now_sec);137 try cb.parseCert(gpa, decoded_start, now_sec);
...@@ -213,7 +213,7 @@ pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file: fs.File) AddCertsFrom...@@ -213,7 +213,7 @@ pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file: fs.File) AddCertsFrom
213 const needed_capacity = std.math.cast(u32, decoded_size_upper_bound + size) orelse213 const needed_capacity = std.math.cast(u32, decoded_size_upper_bound + size) orelse
214 return error.CertificateAuthorityBundleTooBig;214 return error.CertificateAuthorityBundleTooBig;
215 try cb.bytes.ensureUnusedCapacity(gpa, needed_capacity);215 try cb.bytes.ensureUnusedCapacity(gpa, needed_capacity);
216 const end_reserved = @intCast(u32, cb.bytes.items.len + decoded_size_upper_bound);216 const end_reserved = @as(u32, @intCast(cb.bytes.items.len + decoded_size_upper_bound));
217 const buffer = cb.bytes.allocatedSlice()[end_reserved..];217 const buffer = cb.bytes.allocatedSlice()[end_reserved..];
218 const end_index = try file.readAll(buffer);218 const end_index = try file.readAll(buffer);
219 const encoded_bytes = buffer[0..end_index];219 const encoded_bytes = buffer[0..end_index];
...@@ -230,7 +230,7 @@ pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file: fs.File) AddCertsFrom...@@ -230,7 +230,7 @@ pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file: fs.File) AddCertsFrom
230 return error.MissingEndCertificateMarker;230 return error.MissingEndCertificateMarker;
231 start_index = cert_end + end_marker.len;231 start_index = cert_end + end_marker.len;
232 const encoded_cert = mem.trim(u8, encoded_bytes[cert_start..cert_end], " \t\r\n");232 const encoded_cert = mem.trim(u8, encoded_bytes[cert_start..cert_end], " \t\r\n");
233 const decoded_start = @intCast(u32, cb.bytes.items.len);233 const decoded_start = @as(u32, @intCast(cb.bytes.items.len));
234 const dest_buf = cb.bytes.allocatedSlice()[decoded_start..];234 const dest_buf = cb.bytes.allocatedSlice()[decoded_start..];
235 cb.bytes.items.len += try base64.decode(dest_buf, encoded_cert);235 cb.bytes.items.len += try base64.decode(dest_buf, encoded_cert);
236 try cb.parseCert(gpa, decoded_start, now_sec);236 try cb.parseCert(gpa, decoded_start, now_sec);
lib/std/crypto/Certificate/Bundle/macos.zig+3-3
...@@ -21,7 +21,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {...@@ -21,7 +21,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
21 const reader = stream.reader();21 const reader = stream.reader();
2222
23 const db_header = try reader.readStructBig(ApplDbHeader);23 const db_header = try reader.readStructBig(ApplDbHeader);
24 assert(mem.eql(u8, "kych", &@bitCast([4]u8, db_header.signature)));24 assert(mem.eql(u8, "kych", &@as([4]u8, @bitCast(db_header.signature))));
2525
26 try stream.seekTo(db_header.schema_offset);26 try stream.seekTo(db_header.schema_offset);
2727
...@@ -42,7 +42,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {...@@ -42,7 +42,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
4242
43 const table_header = try reader.readStructBig(TableHeader);43 const table_header = try reader.readStructBig(TableHeader);
4444
45 if (@enumFromInt(std.os.darwin.cssm.DB_RECORDTYPE, table_header.table_id) != .X509_CERTIFICATE) {45 if (@as(std.os.darwin.cssm.DB_RECORDTYPE, @enumFromInt(table_header.table_id)) != .X509_CERTIFICATE) {
46 continue;46 continue;
47 }47 }
4848
...@@ -61,7 +61,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {...@@ -61,7 +61,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
6161
62 try cb.bytes.ensureUnusedCapacity(gpa, cert_header.cert_size);62 try cb.bytes.ensureUnusedCapacity(gpa, cert_header.cert_size);
6363
64 const cert_start = @intCast(u32, cb.bytes.items.len);64 const cert_start = @as(u32, @intCast(cb.bytes.items.len));
65 const dest_buf = cb.bytes.allocatedSlice()[cert_start..];65 const dest_buf = cb.bytes.allocatedSlice()[cert_start..];
66 cb.bytes.items.len += try reader.readAtLeast(dest_buf, cert_header.cert_size);66 cb.bytes.items.len += try reader.readAtLeast(dest_buf, cert_header.cert_size);
6767
lib/std/crypto/aegis.zig+1-1
...@@ -625,7 +625,7 @@ test "Aegis MAC" {...@@ -625,7 +625,7 @@ test "Aegis MAC" {
625 const key = [_]u8{0x00} ** Aegis128LMac.key_length;625 const key = [_]u8{0x00} ** Aegis128LMac.key_length;
626 var msg: [64]u8 = undefined;626 var msg: [64]u8 = undefined;
627 for (&msg, 0..) |*m, i| {627 for (&msg, 0..) |*m, i| {
628 m.* = @truncate(u8, i);628 m.* = @as(u8, @truncate(i));
629 }629 }
630 const st_init = Aegis128LMac.init(&key);630 const st_init = Aegis128LMac.init(&key);
631 var st = st_init;631 var st = st_init;
lib/std/crypto/aes/soft.zig+51-51
...@@ -51,13 +51,13 @@ pub const Block = struct {...@@ -51,13 +51,13 @@ pub const Block = struct {
51 const s3 = block.repr[3];51 const s3 = block.repr[3];
5252
53 var x: [4]u32 = undefined;53 var x: [4]u32 = undefined;
54 x = table_lookup(&table_encrypt, @truncate(u8, s0), @truncate(u8, s1 >> 8), @truncate(u8, s2 >> 16), @truncate(u8, s3 >> 24));54 x = table_lookup(&table_encrypt, @as(u8, @truncate(s0)), @as(u8, @truncate(s1 >> 8)), @as(u8, @truncate(s2 >> 16)), @as(u8, @truncate(s3 >> 24)));
55 var t0 = x[0] ^ x[1] ^ x[2] ^ x[3];55 var t0 = x[0] ^ x[1] ^ x[2] ^ x[3];
56 x = table_lookup(&table_encrypt, @truncate(u8, s1), @truncate(u8, s2 >> 8), @truncate(u8, s3 >> 16), @truncate(u8, s0 >> 24));56 x = table_lookup(&table_encrypt, @as(u8, @truncate(s1)), @as(u8, @truncate(s2 >> 8)), @as(u8, @truncate(s3 >> 16)), @as(u8, @truncate(s0 >> 24)));
57 var t1 = x[0] ^ x[1] ^ x[2] ^ x[3];57 var t1 = x[0] ^ x[1] ^ x[2] ^ x[3];
58 x = table_lookup(&table_encrypt, @truncate(u8, s2), @truncate(u8, s3 >> 8), @truncate(u8, s0 >> 16), @truncate(u8, s1 >> 24));58 x = table_lookup(&table_encrypt, @as(u8, @truncate(s2)), @as(u8, @truncate(s3 >> 8)), @as(u8, @truncate(s0 >> 16)), @as(u8, @truncate(s1 >> 24)));
59 var t2 = x[0] ^ x[1] ^ x[2] ^ x[3];59 var t2 = x[0] ^ x[1] ^ x[2] ^ x[3];
60 x = table_lookup(&table_encrypt, @truncate(u8, s3), @truncate(u8, s0 >> 8), @truncate(u8, s1 >> 16), @truncate(u8, s2 >> 24));60 x = table_lookup(&table_encrypt, @as(u8, @truncate(s3)), @as(u8, @truncate(s0 >> 8)), @as(u8, @truncate(s1 >> 16)), @as(u8, @truncate(s2 >> 24)));
61 var t3 = x[0] ^ x[1] ^ x[2] ^ x[3];61 var t3 = x[0] ^ x[1] ^ x[2] ^ x[3];
6262
63 t0 ^= round_key.repr[0];63 t0 ^= round_key.repr[0];
...@@ -77,31 +77,31 @@ pub const Block = struct {...@@ -77,31 +77,31 @@ pub const Block = struct {
7777
78 var x: [4]u32 = undefined;78 var x: [4]u32 = undefined;
79 x = .{79 x = .{
80 table_encrypt[0][@truncate(u8, s0)],80 table_encrypt[0][@as(u8, @truncate(s0))],
81 table_encrypt[1][@truncate(u8, s1 >> 8)],81 table_encrypt[1][@as(u8, @truncate(s1 >> 8))],
82 table_encrypt[2][@truncate(u8, s2 >> 16)],82 table_encrypt[2][@as(u8, @truncate(s2 >> 16))],
83 table_encrypt[3][@truncate(u8, s3 >> 24)],83 table_encrypt[3][@as(u8, @truncate(s3 >> 24))],
84 };84 };
85 var t0 = x[0] ^ x[1] ^ x[2] ^ x[3];85 var t0 = x[0] ^ x[1] ^ x[2] ^ x[3];
86 x = .{86 x = .{
87 table_encrypt[0][@truncate(u8, s1)],87 table_encrypt[0][@as(u8, @truncate(s1))],
88 table_encrypt[1][@truncate(u8, s2 >> 8)],88 table_encrypt[1][@as(u8, @truncate(s2 >> 8))],
89 table_encrypt[2][@truncate(u8, s3 >> 16)],89 table_encrypt[2][@as(u8, @truncate(s3 >> 16))],
90 table_encrypt[3][@truncate(u8, s0 >> 24)],90 table_encrypt[3][@as(u8, @truncate(s0 >> 24))],
91 };91 };
92 var t1 = x[0] ^ x[1] ^ x[2] ^ x[3];92 var t1 = x[0] ^ x[1] ^ x[2] ^ x[3];
93 x = .{93 x = .{
94 table_encrypt[0][@truncate(u8, s2)],94 table_encrypt[0][@as(u8, @truncate(s2))],
95 table_encrypt[1][@truncate(u8, s3 >> 8)],95 table_encrypt[1][@as(u8, @truncate(s3 >> 8))],
96 table_encrypt[2][@truncate(u8, s0 >> 16)],96 table_encrypt[2][@as(u8, @truncate(s0 >> 16))],
97 table_encrypt[3][@truncate(u8, s1 >> 24)],97 table_encrypt[3][@as(u8, @truncate(s1 >> 24))],
98 };98 };
99 var t2 = x[0] ^ x[1] ^ x[2] ^ x[3];99 var t2 = x[0] ^ x[1] ^ x[2] ^ x[3];
100 x = .{100 x = .{
101 table_encrypt[0][@truncate(u8, s3)],101 table_encrypt[0][@as(u8, @truncate(s3))],
102 table_encrypt[1][@truncate(u8, s0 >> 8)],102 table_encrypt[1][@as(u8, @truncate(s0 >> 8))],
103 table_encrypt[2][@truncate(u8, s1 >> 16)],103 table_encrypt[2][@as(u8, @truncate(s1 >> 16))],
104 table_encrypt[3][@truncate(u8, s2 >> 24)],104 table_encrypt[3][@as(u8, @truncate(s2 >> 24))],
105 };105 };
106 var t3 = x[0] ^ x[1] ^ x[2] ^ x[3];106 var t3 = x[0] ^ x[1] ^ x[2] ^ x[3];
107107
...@@ -122,13 +122,13 @@ pub const Block = struct {...@@ -122,13 +122,13 @@ pub const Block = struct {
122122
123 // Last round uses s-box directly and XORs to produce output.123 // Last round uses s-box directly and XORs to produce output.
124 var x: [4]u8 = undefined;124 var x: [4]u8 = undefined;
125 x = sbox_lookup(&sbox_encrypt, @truncate(u8, s3 >> 24), @truncate(u8, s2 >> 16), @truncate(u8, s1 >> 8), @truncate(u8, s0));125 x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s3 >> 24)), @as(u8, @truncate(s2 >> 16)), @as(u8, @truncate(s1 >> 8)), @as(u8, @truncate(s0)));
126 var t0 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);126 var t0 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);
127 x = sbox_lookup(&sbox_encrypt, @truncate(u8, s0 >> 24), @truncate(u8, s3 >> 16), @truncate(u8, s2 >> 8), @truncate(u8, s1));127 x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s0 >> 24)), @as(u8, @truncate(s3 >> 16)), @as(u8, @truncate(s2 >> 8)), @as(u8, @truncate(s1)));
128 var t1 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);128 var t1 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);
129 x = sbox_lookup(&sbox_encrypt, @truncate(u8, s1 >> 24), @truncate(u8, s0 >> 16), @truncate(u8, s3 >> 8), @truncate(u8, s2));129 x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s1 >> 24)), @as(u8, @truncate(s0 >> 16)), @as(u8, @truncate(s3 >> 8)), @as(u8, @truncate(s2)));
130 var t2 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);130 var t2 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);
131 x = sbox_lookup(&sbox_encrypt, @truncate(u8, s2 >> 24), @truncate(u8, s1 >> 16), @truncate(u8, s0 >> 8), @truncate(u8, s3));131 x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s2 >> 24)), @as(u8, @truncate(s1 >> 16)), @as(u8, @truncate(s0 >> 8)), @as(u8, @truncate(s3)));
132 var t3 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);132 var t3 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);
133133
134 t0 ^= round_key.repr[0];134 t0 ^= round_key.repr[0];
...@@ -147,13 +147,13 @@ pub const Block = struct {...@@ -147,13 +147,13 @@ pub const Block = struct {
147 const s3 = block.repr[3];147 const s3 = block.repr[3];
148148
149 var x: [4]u32 = undefined;149 var x: [4]u32 = undefined;
150 x = table_lookup(&table_decrypt, @truncate(u8, s0), @truncate(u8, s3 >> 8), @truncate(u8, s2 >> 16), @truncate(u8, s1 >> 24));150 x = table_lookup(&table_decrypt, @as(u8, @truncate(s0)), @as(u8, @truncate(s3 >> 8)), @as(u8, @truncate(s2 >> 16)), @as(u8, @truncate(s1 >> 24)));
151 var t0 = x[0] ^ x[1] ^ x[2] ^ x[3];151 var t0 = x[0] ^ x[1] ^ x[2] ^ x[3];
152 x = table_lookup(&table_decrypt, @truncate(u8, s1), @truncate(u8, s0 >> 8), @truncate(u8, s3 >> 16), @truncate(u8, s2 >> 24));152 x = table_lookup(&table_decrypt, @as(u8, @truncate(s1)), @as(u8, @truncate(s0 >> 8)), @as(u8, @truncate(s3 >> 16)), @as(u8, @truncate(s2 >> 24)));
153 var t1 = x[0] ^ x[1] ^ x[2] ^ x[3];153 var t1 = x[0] ^ x[1] ^ x[2] ^ x[3];
154 x = table_lookup(&table_decrypt, @truncate(u8, s2), @truncate(u8, s1 >> 8), @truncate(u8, s0 >> 16), @truncate(u8, s3 >> 24));154 x = table_lookup(&table_decrypt, @as(u8, @truncate(s2)), @as(u8, @truncate(s1 >> 8)), @as(u8, @truncate(s0 >> 16)), @as(u8, @truncate(s3 >> 24)));
155 var t2 = x[0] ^ x[1] ^ x[2] ^ x[3];155 var t2 = x[0] ^ x[1] ^ x[2] ^ x[3];
156 x = table_lookup(&table_decrypt, @truncate(u8, s3), @truncate(u8, s2 >> 8), @truncate(u8, s1 >> 16), @truncate(u8, s0 >> 24));156 x = table_lookup(&table_decrypt, @as(u8, @truncate(s3)), @as(u8, @truncate(s2 >> 8)), @as(u8, @truncate(s1 >> 16)), @as(u8, @truncate(s0 >> 24)));
157 var t3 = x[0] ^ x[1] ^ x[2] ^ x[3];157 var t3 = x[0] ^ x[1] ^ x[2] ^ x[3];
158158
159 t0 ^= round_key.repr[0];159 t0 ^= round_key.repr[0];
...@@ -173,31 +173,31 @@ pub const Block = struct {...@@ -173,31 +173,31 @@ pub const Block = struct {
173173
174 var x: [4]u32 = undefined;174 var x: [4]u32 = undefined;
175 x = .{175 x = .{
176 table_decrypt[0][@truncate(u8, s0)],176 table_decrypt[0][@as(u8, @truncate(s0))],
177 table_decrypt[1][@truncate(u8, s3 >> 8)],177 table_decrypt[1][@as(u8, @truncate(s3 >> 8))],
178 table_decrypt[2][@truncate(u8, s2 >> 16)],178 table_decrypt[2][@as(u8, @truncate(s2 >> 16))],
179 table_decrypt[3][@truncate(u8, s1 >> 24)],179 table_decrypt[3][@as(u8, @truncate(s1 >> 24))],
180 };180 };
181 var t0 = x[0] ^ x[1] ^ x[2] ^ x[3];181 var t0 = x[0] ^ x[1] ^ x[2] ^ x[3];
182 x = .{182 x = .{
183 table_decrypt[0][@truncate(u8, s1)],183 table_decrypt[0][@as(u8, @truncate(s1))],
184 table_decrypt[1][@truncate(u8, s0 >> 8)],184 table_decrypt[1][@as(u8, @truncate(s0 >> 8))],
185 table_decrypt[2][@truncate(u8, s3 >> 16)],185 table_decrypt[2][@as(u8, @truncate(s3 >> 16))],
186 table_decrypt[3][@truncate(u8, s2 >> 24)],186 table_decrypt[3][@as(u8, @truncate(s2 >> 24))],
187 };187 };
188 var t1 = x[0] ^ x[1] ^ x[2] ^ x[3];188 var t1 = x[0] ^ x[1] ^ x[2] ^ x[3];
189 x = .{189 x = .{
190 table_decrypt[0][@truncate(u8, s2)],190 table_decrypt[0][@as(u8, @truncate(s2))],
191 table_decrypt[1][@truncate(u8, s1 >> 8)],191 table_decrypt[1][@as(u8, @truncate(s1 >> 8))],
192 table_decrypt[2][@truncate(u8, s0 >> 16)],192 table_decrypt[2][@as(u8, @truncate(s0 >> 16))],
193 table_decrypt[3][@truncate(u8, s3 >> 24)],193 table_decrypt[3][@as(u8, @truncate(s3 >> 24))],
194 };194 };
195 var t2 = x[0] ^ x[1] ^ x[2] ^ x[3];195 var t2 = x[0] ^ x[1] ^ x[2] ^ x[3];
196 x = .{196 x = .{
197 table_decrypt[0][@truncate(u8, s3)],197 table_decrypt[0][@as(u8, @truncate(s3))],
198 table_decrypt[1][@truncate(u8, s2 >> 8)],198 table_decrypt[1][@as(u8, @truncate(s2 >> 8))],
199 table_decrypt[2][@truncate(u8, s1 >> 16)],199 table_decrypt[2][@as(u8, @truncate(s1 >> 16))],
200 table_decrypt[3][@truncate(u8, s0 >> 24)],200 table_decrypt[3][@as(u8, @truncate(s0 >> 24))],
201 };201 };
202 var t3 = x[0] ^ x[1] ^ x[2] ^ x[3];202 var t3 = x[0] ^ x[1] ^ x[2] ^ x[3];
203203
...@@ -218,13 +218,13 @@ pub const Block = struct {...@@ -218,13 +218,13 @@ pub const Block = struct {
218218
219 // Last round uses s-box directly and XORs to produce output.219 // Last round uses s-box directly and XORs to produce output.
220 var x: [4]u8 = undefined;220 var x: [4]u8 = undefined;
221 x = sbox_lookup(&sbox_decrypt, @truncate(u8, s1 >> 24), @truncate(u8, s2 >> 16), @truncate(u8, s3 >> 8), @truncate(u8, s0));221 x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s1 >> 24)), @as(u8, @truncate(s2 >> 16)), @as(u8, @truncate(s3 >> 8)), @as(u8, @truncate(s0)));
222 var t0 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);222 var t0 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);
223 x = sbox_lookup(&sbox_decrypt, @truncate(u8, s2 >> 24), @truncate(u8, s3 >> 16), @truncate(u8, s0 >> 8), @truncate(u8, s1));223 x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s2 >> 24)), @as(u8, @truncate(s3 >> 16)), @as(u8, @truncate(s0 >> 8)), @as(u8, @truncate(s1)));
224 var t1 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);224 var t1 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);
225 x = sbox_lookup(&sbox_decrypt, @truncate(u8, s3 >> 24), @truncate(u8, s0 >> 16), @truncate(u8, s1 >> 8), @truncate(u8, s2));225 x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s3 >> 24)), @as(u8, @truncate(s0 >> 16)), @as(u8, @truncate(s1 >> 8)), @as(u8, @truncate(s2)));
226 var t2 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);226 var t2 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);
227 x = sbox_lookup(&sbox_decrypt, @truncate(u8, s0 >> 24), @truncate(u8, s1 >> 16), @truncate(u8, s2 >> 8), @truncate(u8, s3));227 x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s0 >> 24)), @as(u8, @truncate(s1 >> 16)), @as(u8, @truncate(s2 >> 8)), @as(u8, @truncate(s3)));
228 var t3 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);228 var t3 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);
229229
230 t0 ^= round_key.repr[0];230 t0 ^= round_key.repr[0];
...@@ -348,7 +348,7 @@ fn KeySchedule(comptime Aes: type) type {...@@ -348,7 +348,7 @@ fn KeySchedule(comptime Aes: type) type {
348 const subw = struct {348 const subw = struct {
349 // Apply sbox_encrypt to each byte in w.349 // Apply sbox_encrypt to each byte in w.
350 fn func(w: u32) u32 {350 fn func(w: u32) u32 {
351 const x = sbox_lookup(&sbox_key_schedule, @truncate(u8, w), @truncate(u8, w >> 8), @truncate(u8, w >> 16), @truncate(u8, w >> 24));351 const x = sbox_lookup(&sbox_key_schedule, @as(u8, @truncate(w)), @as(u8, @truncate(w >> 8)), @as(u8, @truncate(w >> 16)), @as(u8, @truncate(w >> 24)));
352 return @as(u32, x[3]) << 24 | @as(u32, x[2]) << 16 | @as(u32, x[1]) << 8 | @as(u32, x[0]);352 return @as(u32, x[3]) << 24 | @as(u32, x[2]) << 16 | @as(u32, x[1]) << 8 | @as(u32, x[0]);
353 }353 }
354 }.func;354 }.func;
...@@ -386,7 +386,7 @@ fn KeySchedule(comptime Aes: type) type {...@@ -386,7 +386,7 @@ fn KeySchedule(comptime Aes: type) type {
386 inline while (j < 4) : (j += 1) {386 inline while (j < 4) : (j += 1) {
387 var rk = round_keys[(ei + j) / 4].repr[(ei + j) % 4];387 var rk = round_keys[(ei + j) / 4].repr[(ei + j) % 4];
388 if (i > 0 and i + 4 < total_words) {388 if (i > 0 and i + 4 < total_words) {
389 const x = sbox_lookup(&sbox_key_schedule, @truncate(u8, rk >> 24), @truncate(u8, rk >> 16), @truncate(u8, rk >> 8), @truncate(u8, rk));389 const x = sbox_lookup(&sbox_key_schedule, @as(u8, @truncate(rk >> 24)), @as(u8, @truncate(rk >> 16)), @as(u8, @truncate(rk >> 8)), @as(u8, @truncate(rk)));
390 const y = table_lookup(&table_decrypt, x[3], x[2], x[1], x[0]);390 const y = table_lookup(&table_decrypt, x[3], x[2], x[1], x[0]);
391 rk = y[0] ^ y[1] ^ y[2] ^ y[3];391 rk = y[0] ^ y[1] ^ y[2] ^ y[3];
392 }392 }
...@@ -664,7 +664,7 @@ fn mul(a: u8, b: u8) u8 {...@@ -664,7 +664,7 @@ fn mul(a: u8, b: u8) u8 {
664 }664 }
665 }665 }
666666
667 return @truncate(u8, s);667 return @as(u8, @truncate(s));
668}668}
669669
670const cache_line_bytes = 64;670const cache_line_bytes = 64;
lib/std/crypto/aes_ocb.zig+4-4
...@@ -86,18 +86,18 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -86,18 +86,18 @@ fn AesOcb(comptime Aes: anytype) type {
8686
87 fn getOffset(aes_enc_ctx: EncryptCtx, npub: [nonce_length]u8) Block {87 fn getOffset(aes_enc_ctx: EncryptCtx, npub: [nonce_length]u8) Block {
88 var nx = [_]u8{0} ** 16;88 var nx = [_]u8{0} ** 16;
89 nx[0] = @intCast(u8, @truncate(u7, tag_length * 8) << 1);89 nx[0] = @as(u8, @intCast(@as(u7, @truncate(tag_length * 8)) << 1));
90 nx[16 - nonce_length - 1] = 1;90 nx[16 - nonce_length - 1] = 1;
91 nx[nx.len - nonce_length ..].* = npub;91 nx[nx.len - nonce_length ..].* = npub;
9292
93 const bottom = @truncate(u6, nx[15]);93 const bottom = @as(u6, @truncate(nx[15]));
94 nx[15] &= 0xc0;94 nx[15] &= 0xc0;
95 var ktop_: Block = undefined;95 var ktop_: Block = undefined;
96 aes_enc_ctx.encrypt(&ktop_, &nx);96 aes_enc_ctx.encrypt(&ktop_, &nx);
97 const ktop = mem.readIntBig(u128, &ktop_);97 const ktop = mem.readIntBig(u128, &ktop_);
98 var stretch = (@as(u192, ktop) << 64) | @as(u192, @truncate(u64, ktop >> 64) ^ @truncate(u64, ktop >> 56));98 var stretch = (@as(u192, ktop) << 64) | @as(u192, @as(u64, @truncate(ktop >> 64)) ^ @as(u64, @truncate(ktop >> 56)));
99 var offset: Block = undefined;99 var offset: Block = undefined;
100 mem.writeIntBig(u128, &offset, @truncate(u128, stretch >> (64 - @as(u7, bottom))));100 mem.writeIntBig(u128, &offset, @as(u128, @truncate(stretch >> (64 - @as(u7, bottom)))));
101 return offset;101 return offset;
102 }102 }
103103
lib/std/crypto/argon2.zig+11-11
...@@ -95,7 +95,7 @@ pub const Params = struct {...@@ -95,7 +95,7 @@ pub const Params = struct {
95 pub fn fromLimits(ops_limit: u32, mem_limit: usize) Self {95 pub fn fromLimits(ops_limit: u32, mem_limit: usize) Self {
96 const m = mem_limit / 1024;96 const m = mem_limit / 1024;
97 std.debug.assert(m <= max_int);97 std.debug.assert(m <= max_int);
98 return .{ .t = ops_limit, .m = @intCast(u32, m), .p = 1 };98 return .{ .t = ops_limit, .m = @as(u32, @intCast(m)), .p = 1 };
99 }99 }
100};100};
101101
...@@ -111,26 +111,26 @@ fn initHash(...@@ -111,26 +111,26 @@ fn initHash(
111 var tmp: [4]u8 = undefined;111 var tmp: [4]u8 = undefined;
112 var b2 = Blake2b512.init(.{});112 var b2 = Blake2b512.init(.{});
113 mem.writeIntLittle(u32, parameters[0..4], params.p);113 mem.writeIntLittle(u32, parameters[0..4], params.p);
114 mem.writeIntLittle(u32, parameters[4..8], @intCast(u32, dk_len));114 mem.writeIntLittle(u32, parameters[4..8], @as(u32, @intCast(dk_len)));
115 mem.writeIntLittle(u32, parameters[8..12], params.m);115 mem.writeIntLittle(u32, parameters[8..12], params.m);
116 mem.writeIntLittle(u32, parameters[12..16], params.t);116 mem.writeIntLittle(u32, parameters[12..16], params.t);
117 mem.writeIntLittle(u32, parameters[16..20], version);117 mem.writeIntLittle(u32, parameters[16..20], version);
118 mem.writeIntLittle(u32, parameters[20..24], @intFromEnum(mode));118 mem.writeIntLittle(u32, parameters[20..24], @intFromEnum(mode));
119 b2.update(&parameters);119 b2.update(&parameters);
120 mem.writeIntLittle(u32, &tmp, @intCast(u32, password.len));120 mem.writeIntLittle(u32, &tmp, @as(u32, @intCast(password.len)));
121 b2.update(&tmp);121 b2.update(&tmp);
122 b2.update(password);122 b2.update(password);
123 mem.writeIntLittle(u32, &tmp, @intCast(u32, salt.len));123 mem.writeIntLittle(u32, &tmp, @as(u32, @intCast(salt.len)));
124 b2.update(&tmp);124 b2.update(&tmp);
125 b2.update(salt);125 b2.update(salt);
126 const secret = params.secret orelse "";126 const secret = params.secret orelse "";
127 std.debug.assert(secret.len <= max_int);127 std.debug.assert(secret.len <= max_int);
128 mem.writeIntLittle(u32, &tmp, @intCast(u32, secret.len));128 mem.writeIntLittle(u32, &tmp, @as(u32, @intCast(secret.len)));
129 b2.update(&tmp);129 b2.update(&tmp);
130 b2.update(secret);130 b2.update(secret);
131 const ad = params.ad orelse "";131 const ad = params.ad orelse "";
132 std.debug.assert(ad.len <= max_int);132 std.debug.assert(ad.len <= max_int);
133 mem.writeIntLittle(u32, &tmp, @intCast(u32, ad.len));133 mem.writeIntLittle(u32, &tmp, @as(u32, @intCast(ad.len)));
134 b2.update(&tmp);134 b2.update(&tmp);
135 b2.update(ad);135 b2.update(ad);
136 b2.final(h0[0..Blake2b512.digest_length]);136 b2.final(h0[0..Blake2b512.digest_length]);
...@@ -140,7 +140,7 @@ fn initHash(...@@ -140,7 +140,7 @@ fn initHash(
140fn blake2bLong(out: []u8, in: []const u8) void {140fn blake2bLong(out: []u8, in: []const u8) void {
141 const H = Blake2b512;141 const H = Blake2b512;
142 var outlen_bytes: [4]u8 = undefined;142 var outlen_bytes: [4]u8 = undefined;
143 mem.writeIntLittle(u32, &outlen_bytes, @intCast(u32, out.len));143 mem.writeIntLittle(u32, &outlen_bytes, @as(u32, @intCast(out.len)));
144144
145 var out_buf: [H.digest_length]u8 = undefined;145 var out_buf: [H.digest_length]u8 = undefined;
146146
...@@ -391,7 +391,7 @@ fn Rp(a: usize, b: usize, c: usize, d: usize) QuarterRound {...@@ -391,7 +391,7 @@ fn Rp(a: usize, b: usize, c: usize, d: usize) QuarterRound {
391}391}
392392
393fn fBlaMka(x: u64, y: u64) u64 {393fn fBlaMka(x: u64, y: u64) u64 {
394 const xy = @as(u64, @truncate(u32, x)) * @as(u64, @truncate(u32, y));394 const xy = @as(u64, @as(u32, @truncate(x))) * @as(u64, @as(u32, @truncate(y)));
395 return x +% y +% 2 *% xy;395 return x +% y +% 2 *% xy;
396}396}
397397
...@@ -448,7 +448,7 @@ fn indexAlpha(...@@ -448,7 +448,7 @@ fn indexAlpha(
448 lane: u24,448 lane: u24,
449 index: u32,449 index: u32,
450) u32 {450) u32 {
451 var ref_lane = @intCast(u32, rand >> 32) % threads;451 var ref_lane = @as(u32, @intCast(rand >> 32)) % threads;
452 if (n == 0 and slice == 0) {452 if (n == 0 and slice == 0) {
453 ref_lane = lane;453 ref_lane = lane;
454 }454 }
...@@ -467,10 +467,10 @@ fn indexAlpha(...@@ -467,10 +467,10 @@ fn indexAlpha(
467 if (index == 0 or lane == ref_lane) {467 if (index == 0 or lane == ref_lane) {
468 m -= 1;468 m -= 1;
469 }469 }
470 var p = @as(u64, @truncate(u32, rand));470 var p = @as(u64, @as(u32, @truncate(rand)));
471 p = (p * p) >> 32;471 p = (p * p) >> 32;
472 p = (p * m) >> 32;472 p = (p * m) >> 32;
473 return ref_lane * lanes + @intCast(u32, ((s + m - (p + 1)) % lanes));473 return ref_lane * lanes + @as(u32, @intCast(((s + m - (p + 1)) % lanes)));
474}474}
475475
476/// Derives a key from the password, salt, and argon2 parameters.476/// Derives a key from the password, salt, and argon2 parameters.
lib/std/crypto/ascon.zig+2-2
...@@ -95,8 +95,8 @@ pub fn State(comptime endian: builtin.Endian) type {...@@ -95,8 +95,8 @@ pub fn State(comptime endian: builtin.Endian) type {
95 /// XOR a byte into the state at a given offset.95 /// XOR a byte into the state at a given offset.
96 pub fn addByte(self: *Self, byte: u8, offset: usize) void {96 pub fn addByte(self: *Self, byte: u8, offset: usize) void {
97 const z = switch (endian) {97 const z = switch (endian) {
98 .Big => 64 - 8 - 8 * @truncate(u6, offset % 8),98 .Big => 64 - 8 - 8 * @as(u6, @truncate(offset % 8)),
99 .Little => 8 * @truncate(u6, offset % 8),99 .Little => 8 * @as(u6, @truncate(offset % 8)),
100 };100 };
101 self.st[offset / 8] ^= @as(u64, byte) << z;101 self.st[offset / 8] ^= @as(u64, byte) << z;
102 }102 }
lib/std/crypto/bcrypt.zig+4-4
...@@ -376,10 +376,10 @@ pub const State = struct {...@@ -376,10 +376,10 @@ pub const State = struct {
376 const Halves = struct { l: u32, r: u32 };376 const Halves = struct { l: u32, r: u32 };
377377
378 fn halfRound(state: *const State, i: u32, j: u32, n: usize) u32 {378 fn halfRound(state: *const State, i: u32, j: u32, n: usize) u32 {
379 var r = state.sboxes[0][@truncate(u8, j >> 24)];379 var r = state.sboxes[0][@as(u8, @truncate(j >> 24))];
380 r +%= state.sboxes[1][@truncate(u8, j >> 16)];380 r +%= state.sboxes[1][@as(u8, @truncate(j >> 16))];
381 r ^= state.sboxes[2][@truncate(u8, j >> 8)];381 r ^= state.sboxes[2][@as(u8, @truncate(j >> 8))];
382 r +%= state.sboxes[3][@truncate(u8, j)];382 r +%= state.sboxes[3][@as(u8, @truncate(j))];
383 return i ^ r ^ state.subkeys[n];383 return i ^ r ^ state.subkeys[n];
384 }384 }
385385
lib/std/crypto/benchmark.zig+26-26
...@@ -54,8 +54,8 @@ pub fn benchmarkHash(comptime Hash: anytype, comptime bytes: comptime_int) !u64...@@ -54,8 +54,8 @@ pub fn benchmarkHash(comptime Hash: anytype, comptime bytes: comptime_int) !u64
5454
55 const end = timer.read();55 const end = timer.read();
5656
57 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;57 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
58 const throughput = @intFromFloat(u64, bytes / elapsed_s);58 const throughput = @as(u64, @intFromFloat(bytes / elapsed_s));
5959
60 return throughput;60 return throughput;
61}61}
...@@ -95,8 +95,8 @@ pub fn benchmarkMac(comptime Mac: anytype, comptime bytes: comptime_int) !u64 {...@@ -95,8 +95,8 @@ pub fn benchmarkMac(comptime Mac: anytype, comptime bytes: comptime_int) !u64 {
95 }95 }
96 const end = timer.read();96 const end = timer.read();
9797
98 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;98 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
99 const throughput = @intFromFloat(u64, bytes / elapsed_s);99 const throughput = @as(u64, @intFromFloat(bytes / elapsed_s));
100100
101 return throughput;101 return throughput;
102}102}
...@@ -125,8 +125,8 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c...@@ -125,8 +125,8 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c
125 }125 }
126 const end = timer.read();126 const end = timer.read();
127127
128 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;128 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
129 const throughput = @intFromFloat(u64, exchange_count / elapsed_s);129 const throughput = @as(u64, @intFromFloat(exchange_count / elapsed_s));
130130
131 return throughput;131 return throughput;
132}132}
...@@ -148,8 +148,8 @@ pub fn benchmarkSignature(comptime Signature: anytype, comptime signatures_count...@@ -148,8 +148,8 @@ pub fn benchmarkSignature(comptime Signature: anytype, comptime signatures_count
148 }148 }
149 const end = timer.read();149 const end = timer.read();
150150
151 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;151 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
152 const throughput = @intFromFloat(u64, signatures_count / elapsed_s);152 const throughput = @as(u64, @intFromFloat(signatures_count / elapsed_s));
153153
154 return throughput;154 return throughput;
155}155}
...@@ -172,8 +172,8 @@ pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime sign...@@ -172,8 +172,8 @@ pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime sign
172 }172 }
173 const end = timer.read();173 const end = timer.read();
174174
175 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;175 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
176 const throughput = @intFromFloat(u64, signatures_count / elapsed_s);176 const throughput = @as(u64, @intFromFloat(signatures_count / elapsed_s));
177177
178 return throughput;178 return throughput;
179}179}
...@@ -201,8 +201,8 @@ pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime...@@ -201,8 +201,8 @@ pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime
201 }201 }
202 const end = timer.read();202 const end = timer.read();
203203
204 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;204 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
205 const throughput = batch.len * @intFromFloat(u64, signatures_count / elapsed_s);205 const throughput = batch.len * @as(u64, @intFromFloat(signatures_count / elapsed_s));
206206
207 return throughput;207 return throughput;
208}208}
...@@ -227,8 +227,8 @@ pub fn benchmarkKem(comptime Kem: anytype, comptime kems_count: comptime_int) !u...@@ -227,8 +227,8 @@ pub fn benchmarkKem(comptime Kem: anytype, comptime kems_count: comptime_int) !u
227 }227 }
228 const end = timer.read();228 const end = timer.read();
229229
230 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;230 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
231 const throughput = @intFromFloat(u64, kems_count / elapsed_s);231 const throughput = @as(u64, @intFromFloat(kems_count / elapsed_s));
232232
233 return throughput;233 return throughput;
234}234}
...@@ -249,8 +249,8 @@ pub fn benchmarkKemDecaps(comptime Kem: anytype, comptime kems_count: comptime_i...@@ -249,8 +249,8 @@ pub fn benchmarkKemDecaps(comptime Kem: anytype, comptime kems_count: comptime_i
249 }249 }
250 const end = timer.read();250 const end = timer.read();
251251
252 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;252 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
253 const throughput = @intFromFloat(u64, kems_count / elapsed_s);253 const throughput = @as(u64, @intFromFloat(kems_count / elapsed_s));
254254
255 return throughput;255 return throughput;
256}256}
...@@ -267,8 +267,8 @@ pub fn benchmarkKemKeyGen(comptime Kem: anytype, comptime kems_count: comptime_i...@@ -267,8 +267,8 @@ pub fn benchmarkKemKeyGen(comptime Kem: anytype, comptime kems_count: comptime_i
267 }267 }
268 const end = timer.read();268 const end = timer.read();
269269
270 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;270 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
271 const throughput = @intFromFloat(u64, kems_count / elapsed_s);271 const throughput = @as(u64, @intFromFloat(kems_count / elapsed_s));
272272
273 return throughput;273 return throughput;
274}274}
...@@ -309,8 +309,8 @@ pub fn benchmarkAead(comptime Aead: anytype, comptime bytes: comptime_int) !u64...@@ -309,8 +309,8 @@ pub fn benchmarkAead(comptime Aead: anytype, comptime bytes: comptime_int) !u64
309 mem.doNotOptimizeAway(&in);309 mem.doNotOptimizeAway(&in);
310 const end = timer.read();310 const end = timer.read();
311311
312 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;312 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
313 const throughput = @intFromFloat(u64, 2 * bytes / elapsed_s);313 const throughput = @as(u64, @intFromFloat(2 * bytes / elapsed_s));
314314
315 return throughput;315 return throughput;
316}316}
...@@ -338,8 +338,8 @@ pub fn benchmarkAes(comptime Aes: anytype, comptime count: comptime_int) !u64 {...@@ -338,8 +338,8 @@ pub fn benchmarkAes(comptime Aes: anytype, comptime count: comptime_int) !u64 {
338 mem.doNotOptimizeAway(&in);338 mem.doNotOptimizeAway(&in);
339 const end = timer.read();339 const end = timer.read();
340340
341 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;341 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
342 const throughput = @intFromFloat(u64, count / elapsed_s);342 const throughput = @as(u64, @intFromFloat(count / elapsed_s));
343343
344 return throughput;344 return throughput;
345}345}
...@@ -367,8 +367,8 @@ pub fn benchmarkAes8(comptime Aes: anytype, comptime count: comptime_int) !u64 {...@@ -367,8 +367,8 @@ pub fn benchmarkAes8(comptime Aes: anytype, comptime count: comptime_int) !u64 {
367 mem.doNotOptimizeAway(&in);367 mem.doNotOptimizeAway(&in);
368 const end = timer.read();368 const end = timer.read();
369369
370 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;370 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
371 const throughput = @intFromFloat(u64, 8 * count / elapsed_s);371 const throughput = @as(u64, @intFromFloat(8 * count / elapsed_s));
372372
373 return throughput;373 return throughput;
374}374}
...@@ -406,7 +406,7 @@ fn benchmarkPwhash(...@@ -406,7 +406,7 @@ fn benchmarkPwhash(
406 const password = "testpass" ** 2;406 const password = "testpass" ** 2;
407 const opts = .{407 const opts = .{
408 .allocator = allocator,408 .allocator = allocator,
409 .params = @ptrCast(*const ty.Params, @alignCast(std.meta.alignment(ty.Params), params)).*,409 .params = @as(*const ty.Params, @ptrCast(@alignCast(params))).*,
410 .encoding = .phc,410 .encoding = .phc,
411 };411 };
412 var buf: [256]u8 = undefined;412 var buf: [256]u8 = undefined;
...@@ -422,7 +422,7 @@ fn benchmarkPwhash(...@@ -422,7 +422,7 @@ fn benchmarkPwhash(
422 }422 }
423 const end = timer.read();423 const end = timer.read();
424424
425 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;425 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
426 const throughput = elapsed_s / count;426 const throughput = elapsed_s / count;
427427
428 return throughput;428 return throughput;
lib/std/crypto/blake2.zig+9-9
...@@ -80,7 +80,7 @@ pub fn Blake2s(comptime out_bits: usize) type {...@@ -80,7 +80,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
8080
81 const key_len = if (options.key) |key| key.len else 0;81 const key_len = if (options.key) |key| key.len else 0;
82 // default parameters82 // default parameters
83 d.h[0] ^= 0x01010000 ^ @truncate(u32, key_len << 8) ^ @intCast(u32, options.expected_out_bits >> 3);83 d.h[0] ^= 0x01010000 ^ @as(u32, @truncate(key_len << 8)) ^ @as(u32, @intCast(options.expected_out_bits >> 3));
84 d.t = 0;84 d.t = 0;
85 d.buf_len = 0;85 d.buf_len = 0;
8686
...@@ -127,7 +127,7 @@ pub fn Blake2s(comptime out_bits: usize) type {...@@ -127,7 +127,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
127 // Copy any remainder for next pass.127 // Copy any remainder for next pass.
128 const b_slice = b[off..];128 const b_slice = b[off..];
129 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);129 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
130 d.buf_len += @intCast(u8, b_slice.len);130 d.buf_len += @as(u8, @intCast(b_slice.len));
131 }131 }
132132
133 pub fn final(d: *Self, out: *[digest_length]u8) void {133 pub fn final(d: *Self, out: *[digest_length]u8) void {
...@@ -135,7 +135,7 @@ pub fn Blake2s(comptime out_bits: usize) type {...@@ -135,7 +135,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
135 d.t += d.buf_len;135 d.t += d.buf_len;
136 d.round(d.buf[0..], true);136 d.round(d.buf[0..], true);
137 for (&d.h) |*x| x.* = mem.nativeToLittle(u32, x.*);137 for (&d.h) |*x| x.* = mem.nativeToLittle(u32, x.*);
138 out.* = @ptrCast(*[digest_length]u8, &d.h).*;138 out.* = @as(*[digest_length]u8, @ptrCast(&d.h)).*;
139 }139 }
140140
141 fn round(d: *Self, b: *const [64]u8, last: bool) void {141 fn round(d: *Self, b: *const [64]u8, last: bool) void {
...@@ -152,8 +152,8 @@ pub fn Blake2s(comptime out_bits: usize) type {...@@ -152,8 +152,8 @@ pub fn Blake2s(comptime out_bits: usize) type {
152 v[k + 8] = iv[k];152 v[k + 8] = iv[k];
153 }153 }
154154
155 v[12] ^= @truncate(u32, d.t);155 v[12] ^= @as(u32, @truncate(d.t));
156 v[13] ^= @intCast(u32, d.t >> 32);156 v[13] ^= @as(u32, @intCast(d.t >> 32));
157 if (last) v[14] = ~v[14];157 if (last) v[14] = ~v[14];
158158
159 const rounds = comptime [_]RoundParam{159 const rounds = comptime [_]RoundParam{
...@@ -563,7 +563,7 @@ pub fn Blake2b(comptime out_bits: usize) type {...@@ -563,7 +563,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
563 // Copy any remainder for next pass.563 // Copy any remainder for next pass.
564 const b_slice = b[off..];564 const b_slice = b[off..];
565 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);565 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
566 d.buf_len += @intCast(u8, b_slice.len);566 d.buf_len += @as(u8, @intCast(b_slice.len));
567 }567 }
568568
569 pub fn final(d: *Self, out: *[digest_length]u8) void {569 pub fn final(d: *Self, out: *[digest_length]u8) void {
...@@ -571,7 +571,7 @@ pub fn Blake2b(comptime out_bits: usize) type {...@@ -571,7 +571,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
571 d.t += d.buf_len;571 d.t += d.buf_len;
572 d.round(d.buf[0..], true);572 d.round(d.buf[0..], true);
573 for (&d.h) |*x| x.* = mem.nativeToLittle(u64, x.*);573 for (&d.h) |*x| x.* = mem.nativeToLittle(u64, x.*);
574 out.* = @ptrCast(*[digest_length]u8, &d.h).*;574 out.* = @as(*[digest_length]u8, @ptrCast(&d.h)).*;
575 }575 }
576576
577 fn round(d: *Self, b: *const [128]u8, last: bool) void {577 fn round(d: *Self, b: *const [128]u8, last: bool) void {
...@@ -588,8 +588,8 @@ pub fn Blake2b(comptime out_bits: usize) type {...@@ -588,8 +588,8 @@ pub fn Blake2b(comptime out_bits: usize) type {
588 v[k + 8] = iv[k];588 v[k + 8] = iv[k];
589 }589 }
590590
591 v[12] ^= @truncate(u64, d.t);591 v[12] ^= @as(u64, @truncate(d.t));
592 v[13] ^= @intCast(u64, d.t >> 64);592 v[13] ^= @as(u64, @intCast(d.t >> 64));
593 if (last) v[14] = ~v[14];593 if (last) v[14] = ~v[14];
594594
595 const rounds = comptime [_]RoundParam{595 const rounds = comptime [_]RoundParam{
lib/std/crypto/blake3.zig+7-7
...@@ -89,7 +89,7 @@ const CompressVectorized = struct {...@@ -89,7 +89,7 @@ const CompressVectorized = struct {
89 counter: u64,89 counter: u64,
90 flags: u8,90 flags: u8,
91 ) [16]u32 {91 ) [16]u32 {
92 const md = Lane{ @truncate(u32, counter), @truncate(u32, counter >> 32), block_len, @as(u32, flags) };92 const md = Lane{ @as(u32, @truncate(counter)), @as(u32, @truncate(counter >> 32)), block_len, @as(u32, flags) };
93 var rows = Rows{ chaining_value[0..4].*, chaining_value[4..8].*, IV[0..4].*, md };93 var rows = Rows{ chaining_value[0..4].*, chaining_value[4..8].*, IV[0..4].*, md };
9494
95 var m = Rows{ block_words[0..4].*, block_words[4..8].*, block_words[8..12].*, block_words[12..16].* };95 var m = Rows{ block_words[0..4].*, block_words[4..8].*, block_words[8..12].*, block_words[12..16].* };
...@@ -134,7 +134,7 @@ const CompressVectorized = struct {...@@ -134,7 +134,7 @@ const CompressVectorized = struct {
134 rows[2] ^= @Vector(4, u32){ chaining_value[0], chaining_value[1], chaining_value[2], chaining_value[3] };134 rows[2] ^= @Vector(4, u32){ chaining_value[0], chaining_value[1], chaining_value[2], chaining_value[3] };
135 rows[3] ^= @Vector(4, u32){ chaining_value[4], chaining_value[5], chaining_value[6], chaining_value[7] };135 rows[3] ^= @Vector(4, u32){ chaining_value[4], chaining_value[5], chaining_value[6], chaining_value[7] };
136136
137 return @bitCast([16]u32, rows);137 return @as([16]u32, @bitCast(rows));
138 }138 }
139};139};
140140
...@@ -184,8 +184,8 @@ const CompressGeneric = struct {...@@ -184,8 +184,8 @@ const CompressGeneric = struct {
184 IV[1],184 IV[1],
185 IV[2],185 IV[2],
186 IV[3],186 IV[3],
187 @truncate(u32, counter),187 @as(u32, @truncate(counter)),
188 @truncate(u32, counter >> 32),188 @as(u32, @truncate(counter >> 32)),
189 block_len,189 block_len,
190 flags,190 flags,
191 };191 };
...@@ -206,7 +206,7 @@ else...@@ -206,7 +206,7 @@ else
206 CompressGeneric.compress;206 CompressGeneric.compress;
207207
208fn first8Words(words: [16]u32) [8]u32 {208fn first8Words(words: [16]u32) [8]u32 {
209 return @ptrCast(*const [8]u32, &words).*;209 return @as(*const [8]u32, @ptrCast(&words)).*;
210}210}
211211
212fn wordsFromLittleEndianBytes(comptime count: usize, bytes: [count * 4]u8) [count]u32 {212fn wordsFromLittleEndianBytes(comptime count: usize, bytes: [count * 4]u8) [count]u32 {
...@@ -285,7 +285,7 @@ const ChunkState = struct {...@@ -285,7 +285,7 @@ const ChunkState = struct {
285 const want = BLOCK_LEN - self.block_len;285 const want = BLOCK_LEN - self.block_len;
286 const take = @min(want, input.len);286 const take = @min(want, input.len);
287 @memcpy(self.block[self.block_len..][0..take], input[0..take]);287 @memcpy(self.block[self.block_len..][0..take], input[0..take]);
288 self.block_len += @truncate(u8, take);288 self.block_len += @as(u8, @truncate(take));
289 return input[take..];289 return input[take..];
290 }290 }
291291
...@@ -658,7 +658,7 @@ fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) !void {...@@ -658,7 +658,7 @@ fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) !void {
658658
659 // Setup input pattern659 // Setup input pattern
660 var input_pattern: [251]u8 = undefined;660 var input_pattern: [251]u8 = undefined;
661 for (&input_pattern, 0..) |*e, i| e.* = @truncate(u8, i);661 for (&input_pattern, 0..) |*e, i| e.* = @as(u8, @truncate(i));
662662
663 // Write repeating input pattern to hasher663 // Write repeating input pattern to hasher
664 var input_counter = input_len;664 var input_counter = input_len;
lib/std/crypto/chacha20.zig+4-4
...@@ -587,8 +587,8 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type {...@@ -587,8 +587,8 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type {
587587
588 const k = keyToWords(key);588 const k = keyToWords(key);
589 var c: [4]u32 = undefined;589 var c: [4]u32 = undefined;
590 c[0] = @truncate(u32, counter);590 c[0] = @as(u32, @truncate(counter));
591 c[1] = @truncate(u32, counter >> 32);591 c[1] = @as(u32, @truncate(counter >> 32));
592 c[2] = mem.readIntLittle(u32, nonce[0..4]);592 c[2] = mem.readIntLittle(u32, nonce[0..4]);
593 c[3] = mem.readIntLittle(u32, nonce[4..8]);593 c[3] = mem.readIntLittle(u32, nonce[4..8]);
594 ChaChaImpl(rounds_nb).chacha20Xor(out, in, k, c, true);594 ChaChaImpl(rounds_nb).chacha20Xor(out, in, k, c, true);
...@@ -600,8 +600,8 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type {...@@ -600,8 +600,8 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type {
600600
601 const k = keyToWords(key);601 const k = keyToWords(key);
602 var c: [4]u32 = undefined;602 var c: [4]u32 = undefined;
603 c[0] = @truncate(u32, counter);603 c[0] = @as(u32, @truncate(counter));
604 c[1] = @truncate(u32, counter >> 32);604 c[1] = @as(u32, @truncate(counter >> 32));
605 c[2] = mem.readIntLittle(u32, nonce[0..4]);605 c[2] = mem.readIntLittle(u32, nonce[0..4]);
606 c[3] = mem.readIntLittle(u32, nonce[4..8]);606 c[3] = mem.readIntLittle(u32, nonce[4..8]);
607 ChaChaImpl(rounds_nb).chacha20Stream(out, k, c, true);607 ChaChaImpl(rounds_nb).chacha20Stream(out, k, c, true);
lib/std/crypto/ecdsa.zig+3-3
...@@ -122,9 +122,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {...@@ -122,9 +122,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
122 pub fn toDer(self: Signature, buf: *[der_encoded_max_length]u8) []u8 {122 pub fn toDer(self: Signature, buf: *[der_encoded_max_length]u8) []u8 {
123 var fb = io.fixedBufferStream(buf);123 var fb = io.fixedBufferStream(buf);
124 const w = fb.writer();124 const w = fb.writer();
125 const r_len = @intCast(u8, self.r.len + (self.r[0] >> 7));125 const r_len = @as(u8, @intCast(self.r.len + (self.r[0] >> 7)));
126 const s_len = @intCast(u8, self.s.len + (self.s[0] >> 7));126 const s_len = @as(u8, @intCast(self.s.len + (self.s[0] >> 7)));
127 const seq_len = @intCast(u8, 2 + r_len + 2 + s_len);127 const seq_len = @as(u8, @intCast(2 + r_len + 2 + s_len));
128 w.writeAll(&[_]u8{ 0x30, seq_len }) catch unreachable;128 w.writeAll(&[_]u8{ 0x30, seq_len }) catch unreachable;
129 w.writeAll(&[_]u8{ 0x02, r_len }) catch unreachable;129 w.writeAll(&[_]u8{ 0x02, r_len }) catch unreachable;
130 if (self.r[0] >> 7 != 0) {130 if (self.r[0] >> 7 != 0) {
lib/std/crypto/ff.zig+35-35
...@@ -100,7 +100,7 @@ pub fn Uint(comptime max_bits: comptime_int) type {...@@ -100,7 +100,7 @@ pub fn Uint(comptime max_bits: comptime_int) type {
100 var x = x_;100 var x = x_;
101 var out = Self.zero;101 var out = Self.zero;
102 for (0..out.limbs.capacity()) |i| {102 for (0..out.limbs.capacity()) |i| {
103 const t = if (@bitSizeOf(T) > t_bits) @truncate(TLimb, x) else x;103 const t = if (@bitSizeOf(T) > t_bits) @as(TLimb, @truncate(x)) else x;
104 out.limbs.set(i, t);104 out.limbs.set(i, t);
105 x = math.shr(T, x, t_bits);105 x = math.shr(T, x, t_bits);
106 }106 }
...@@ -143,9 +143,9 @@ pub fn Uint(comptime max_bits: comptime_int) type {...@@ -143,9 +143,9 @@ pub fn Uint(comptime max_bits: comptime_int) type {
143 var remaining_bits = t_bits;143 var remaining_bits = t_bits;
144 var limb = self.limbs.get(i);144 var limb = self.limbs.get(i);
145 while (remaining_bits >= 8) {145 while (remaining_bits >= 8) {
146 bytes[out_i] |= math.shl(u8, @truncate(u8, limb), shift);146 bytes[out_i] |= math.shl(u8, @as(u8, @truncate(limb)), shift);
147 const consumed = 8 - shift;147 const consumed = 8 - shift;
148 limb >>= @truncate(u4, consumed);148 limb >>= @as(u4, @truncate(consumed));
149 remaining_bits -= consumed;149 remaining_bits -= consumed;
150 shift = 0;150 shift = 0;
151 switch (endian) {151 switch (endian) {
...@@ -169,7 +169,7 @@ pub fn Uint(comptime max_bits: comptime_int) type {...@@ -169,7 +169,7 @@ pub fn Uint(comptime max_bits: comptime_int) type {
169 },169 },
170 }170 }
171 }171 }
172 bytes[out_i] |= @truncate(u8, limb);172 bytes[out_i] |= @as(u8, @truncate(limb));
173 shift = remaining_bits;173 shift = remaining_bits;
174 }174 }
175 }175 }
...@@ -190,7 +190,7 @@ pub fn Uint(comptime max_bits: comptime_int) type {...@@ -190,7 +190,7 @@ pub fn Uint(comptime max_bits: comptime_int) type {
190 shift += 8;190 shift += 8;
191 if (shift >= t_bits) {191 if (shift >= t_bits) {
192 shift -= t_bits;192 shift -= t_bits;
193 out.limbs.set(out_i, @truncate(TLimb, out.limbs.get(out_i)));193 out.limbs.set(out_i, @as(TLimb, @truncate(out.limbs.get(out_i))));
194 const overflow = math.shr(Limb, bi, 8 - shift);194 const overflow = math.shr(Limb, bi, 8 - shift);
195 out_i += 1;195 out_i += 1;
196 if (out_i >= out.limbs.len) {196 if (out_i >= out.limbs.len) {
...@@ -242,7 +242,7 @@ pub fn Uint(comptime max_bits: comptime_int) type {...@@ -242,7 +242,7 @@ pub fn Uint(comptime max_bits: comptime_int) type {
242242
243 /// Returns `true` if the integer is odd.243 /// Returns `true` if the integer is odd.
244 pub fn isOdd(x: Self) bool {244 pub fn isOdd(x: Self) bool {
245 return @bitCast(bool, @truncate(u1, x.limbs.get(0)));245 return @as(bool, @bitCast(@as(u1, @truncate(x.limbs.get(0)))));
246 }246 }
247247
248 /// Adds `y` to `x`, and returns `true` if the operation overflowed.248 /// Adds `y` to `x`, and returns `true` if the operation overflowed.
...@@ -273,8 +273,8 @@ pub fn Uint(comptime max_bits: comptime_int) type {...@@ -273,8 +273,8 @@ pub fn Uint(comptime max_bits: comptime_int) type {
273 var carry: u1 = 0;273 var carry: u1 = 0;
274 for (0..x.limbs_count()) |i| {274 for (0..x.limbs_count()) |i| {
275 const res = x_limbs[i] + y_limbs[i] + carry;275 const res = x_limbs[i] + y_limbs[i] + carry;
276 x_limbs[i] = ct.select(on, @truncate(TLimb, res), x_limbs[i]);276 x_limbs[i] = ct.select(on, @as(TLimb, @truncate(res)), x_limbs[i]);
277 carry = @truncate(u1, res >> t_bits);277 carry = @as(u1, @truncate(res >> t_bits));
278 }278 }
279 return carry;279 return carry;
280 }280 }
...@@ -288,8 +288,8 @@ pub fn Uint(comptime max_bits: comptime_int) type {...@@ -288,8 +288,8 @@ pub fn Uint(comptime max_bits: comptime_int) type {
288 var borrow: u1 = 0;288 var borrow: u1 = 0;
289 for (0..x.limbs_count()) |i| {289 for (0..x.limbs_count()) |i| {
290 const res = x_limbs[i] -% y_limbs[i] -% borrow;290 const res = x_limbs[i] -% y_limbs[i] -% borrow;
291 x_limbs[i] = ct.select(on, @truncate(TLimb, res), x_limbs[i]);291 x_limbs[i] = ct.select(on, @as(TLimb, @truncate(res)), x_limbs[i]);
292 borrow = @truncate(u1, res >> t_bits);292 borrow = @as(u1, @truncate(res >> t_bits));
293 }293 }
294 return borrow;294 return borrow;
295 }295 }
...@@ -432,7 +432,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {...@@ -432,7 +432,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
432 inline for (0..comptime math.log2_int(usize, t_bits)) |_| {432 inline for (0..comptime math.log2_int(usize, t_bits)) |_| {
433 y = y *% (2 -% lo *% y);433 y = y *% (2 -% lo *% y);
434 }434 }
435 const m0inv = (@as(Limb, 1) << t_bits) - (@truncate(TLimb, y));435 const m0inv = (@as(Limb, 1) << t_bits) - (@as(TLimb, @truncate(y)));
436436
437 const zero = Fe{ .v = FeUint.zero };437 const zero = Fe{ .v = FeUint.zero };
438438
...@@ -508,18 +508,18 @@ pub fn Modulus(comptime max_bits: comptime_int) type {...@@ -508,18 +508,18 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
508 var need_sub = false;508 var need_sub = false;
509 var i: usize = t_bits - 1;509 var i: usize = t_bits - 1;
510 while (true) : (i -= 1) {510 while (true) : (i -= 1) {
511 var carry = @truncate(u1, math.shr(Limb, y, i));511 var carry = @as(u1, @truncate(math.shr(Limb, y, i)));
512 var borrow: u1 = 0;512 var borrow: u1 = 0;
513 for (0..self.limbs_count()) |j| {513 for (0..self.limbs_count()) |j| {
514 const l = ct.select(need_sub, d_limbs[j], x_limbs[j]);514 const l = ct.select(need_sub, d_limbs[j], x_limbs[j]);
515 var res = (l << 1) + carry;515 var res = (l << 1) + carry;
516 x_limbs[j] = @truncate(TLimb, res);516 x_limbs[j] = @as(TLimb, @truncate(res));
517 carry = @truncate(u1, res >> t_bits);517 carry = @as(u1, @truncate(res >> t_bits));
518518
519 res = x_limbs[j] -% m_limbs[j] -% borrow;519 res = x_limbs[j] -% m_limbs[j] -% borrow;
520 d_limbs[j] = @truncate(TLimb, res);520 d_limbs[j] = @as(TLimb, @truncate(res));
521521
522 borrow = @truncate(u1, res >> t_bits);522 borrow = @as(u1, @truncate(res >> t_bits));
523 }523 }
524 need_sub = ct.eql(carry, borrow);524 need_sub = ct.eql(carry, borrow);
525 if (i == 0) break;525 if (i == 0) break;
...@@ -531,7 +531,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {...@@ -531,7 +531,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
531 pub fn add(self: Self, x: Fe, y: Fe) Fe {531 pub fn add(self: Self, x: Fe, y: Fe) Fe {
532 var out = x;532 var out = x;
533 const overflow = out.v.addWithOverflow(y.v);533 const overflow = out.v.addWithOverflow(y.v);
534 const underflow = @bitCast(u1, ct.limbsCmpLt(out.v, self.v));534 const underflow = @as(u1, @bitCast(ct.limbsCmpLt(out.v, self.v)));
535 const need_sub = ct.eql(overflow, underflow);535 const need_sub = ct.eql(overflow, underflow);
536 _ = out.v.conditionalSubWithOverflow(need_sub, self.v);536 _ = out.v.conditionalSubWithOverflow(need_sub, self.v);
537 return out;537 return out;
...@@ -540,7 +540,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {...@@ -540,7 +540,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
540 /// Subtracts two field elements (mod m).540 /// Subtracts two field elements (mod m).
541 pub fn sub(self: Self, x: Fe, y: Fe) Fe {541 pub fn sub(self: Self, x: Fe, y: Fe) Fe {
542 var out = x;542 var out = x;
543 const underflow = @bitCast(bool, out.v.subWithOverflow(y.v));543 const underflow = @as(bool, @bitCast(out.v.subWithOverflow(y.v)));
544 _ = out.v.conditionalAddWithOverflow(underflow, self.v);544 _ = out.v.conditionalAddWithOverflow(underflow, self.v);
545 return out;545 return out;
546 }546 }
...@@ -601,7 +601,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {...@@ -601,7 +601,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
601601
602 var wide = ct.mulWide(a_limbs[i], b_limbs[0]);602 var wide = ct.mulWide(a_limbs[i], b_limbs[0]);
603 var z_lo = @addWithOverflow(d_limbs[0], wide.lo);603 var z_lo = @addWithOverflow(d_limbs[0], wide.lo);
604 const f = @truncate(TLimb, z_lo[0] *% self.m0inv);604 const f = @as(TLimb, @truncate(z_lo[0] *% self.m0inv));
605 var z_hi = wide.hi +% z_lo[1];605 var z_hi = wide.hi +% z_lo[1];
606 wide = ct.mulWide(f, m_limbs[0]);606 wide = ct.mulWide(f, m_limbs[0]);
607 z_lo = @addWithOverflow(z_lo[0], wide.lo);607 z_lo = @addWithOverflow(z_lo[0], wide.lo);
...@@ -620,13 +620,13 @@ pub fn Modulus(comptime max_bits: comptime_int) type {...@@ -620,13 +620,13 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
620 z_lo = @addWithOverflow(z_lo[0], carry);620 z_lo = @addWithOverflow(z_lo[0], carry);
621 z_hi +%= z_lo[1];621 z_hi +%= z_lo[1];
622 if (j > 0) {622 if (j > 0) {
623 d_limbs[j - 1] = @truncate(TLimb, z_lo[0]);623 d_limbs[j - 1] = @as(TLimb, @truncate(z_lo[0]));
624 }624 }
625 carry = (z_hi << 1) | (z_lo[0] >> t_bits);625 carry = (z_hi << 1) | (z_lo[0] >> t_bits);
626 }626 }
627 const z = overflow + carry;627 const z = overflow + carry;
628 d_limbs[self.limbs_count() - 1] = @truncate(TLimb, z);628 d_limbs[self.limbs_count() - 1] = @as(TLimb, @truncate(z));
629 overflow = @truncate(u1, z >> t_bits);629 overflow = @as(u1, @truncate(z >> t_bits));
630 }630 }
631 return overflow;631 return overflow;
632 }632 }
...@@ -735,7 +735,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {...@@ -735,7 +735,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
735 t0 = pc[k - 1];735 t0 = pc[k - 1];
736 } else {736 } else {
737 for (pc, 0..) |t, i| {737 for (pc, 0..) |t, i| {
738 t0.v.cmov(ct.eql(k, @truncate(u8, i + 1)), t.v);738 t0.v.cmov(ct.eql(k, @as(u8, @truncate(i + 1))), t.v);
739 }739 }
740 }740 }
741 const t1 = self.montgomeryMul(out, t0);741 const t1 = self.montgomeryMul(out, t0);
...@@ -771,7 +771,7 @@ const ct_protected = struct {...@@ -771,7 +771,7 @@ const ct_protected = struct {
771 fn eql(x: anytype, y: @TypeOf(x)) bool {771 fn eql(x: anytype, y: @TypeOf(x)) bool {
772 const c1 = @subWithOverflow(x, y)[1];772 const c1 = @subWithOverflow(x, y)[1];
773 const c2 = @subWithOverflow(y, x)[1];773 const c2 = @subWithOverflow(y, x)[1];
774 return @bitCast(bool, 1 - (c1 | c2));774 return @as(bool, @bitCast(1 - (c1 | c2)));
775 }775 }
776776
777 // Compares two big integers in constant time, returning true if x < y.777 // Compares two big integers in constant time, returning true if x < y.
...@@ -782,28 +782,28 @@ const ct_protected = struct {...@@ -782,28 +782,28 @@ const ct_protected = struct {
782782
783 var c: u1 = 0;783 var c: u1 = 0;
784 for (0..x.limbs_count()) |i| {784 for (0..x.limbs_count()) |i| {
785 c = @truncate(u1, (x_limbs[i] -% y_limbs[i] -% c) >> t_bits);785 c = @as(u1, @truncate((x_limbs[i] -% y_limbs[i] -% c) >> t_bits));
786 }786 }
787 return @bitCast(bool, c);787 return @as(bool, @bitCast(c));
788 }788 }
789789
790 // Compares two big integers in constant time, returning true if x >= y.790 // Compares two big integers in constant time, returning true if x >= y.
791 fn limbsCmpGeq(x: anytype, y: @TypeOf(x)) bool {791 fn limbsCmpGeq(x: anytype, y: @TypeOf(x)) bool {
792 return @bitCast(bool, 1 - @intFromBool(ct.limbsCmpLt(x, y)));792 return @as(bool, @bitCast(1 - @intFromBool(ct.limbsCmpLt(x, y))));
793 }793 }
794794
795 // Multiplies two limbs and returns the result as a wide limb.795 // Multiplies two limbs and returns the result as a wide limb.
796 fn mulWide(x: Limb, y: Limb) WideLimb {796 fn mulWide(x: Limb, y: Limb) WideLimb {
797 const half_bits = @typeInfo(Limb).Int.bits / 2;797 const half_bits = @typeInfo(Limb).Int.bits / 2;
798 const Half = meta.Int(.unsigned, half_bits);798 const Half = meta.Int(.unsigned, half_bits);
799 const x0 = @truncate(Half, x);799 const x0 = @as(Half, @truncate(x));
800 const x1 = @truncate(Half, x >> half_bits);800 const x1 = @as(Half, @truncate(x >> half_bits));
801 const y0 = @truncate(Half, y);801 const y0 = @as(Half, @truncate(y));
802 const y1 = @truncate(Half, y >> half_bits);802 const y1 = @as(Half, @truncate(y >> half_bits));
803 const w0 = math.mulWide(Half, x0, y0);803 const w0 = math.mulWide(Half, x0, y0);
804 const t = math.mulWide(Half, x1, y0) + (w0 >> half_bits);804 const t = math.mulWide(Half, x1, y0) + (w0 >> half_bits);
805 var w1: Limb = @truncate(Half, t);805 var w1: Limb = @as(Half, @truncate(t));
806 const w2 = @truncate(Half, t >> half_bits);806 const w2 = @as(Half, @truncate(t >> half_bits));
807 w1 += math.mulWide(Half, x0, y1);807 w1 += math.mulWide(Half, x0, y1);
808 const hi = math.mulWide(Half, x1, y1) + w2 + (w1 >> half_bits);808 const hi = math.mulWide(Half, x1, y1) + w2 + (w1 >> half_bits);
809 const lo = x *% y;809 const lo = x *% y;
...@@ -847,8 +847,8 @@ const ct_unprotected = struct {...@@ -847,8 +847,8 @@ const ct_unprotected = struct {
847 fn mulWide(x: Limb, y: Limb) WideLimb {847 fn mulWide(x: Limb, y: Limb) WideLimb {
848 const wide = math.mulWide(Limb, x, y);848 const wide = math.mulWide(Limb, x, y);
849 return .{849 return .{
850 .hi = @truncate(Limb, wide >> @typeInfo(Limb).Int.bits),850 .hi = @as(Limb, @truncate(wide >> @typeInfo(Limb).Int.bits)),
851 .lo = @truncate(Limb, wide),851 .lo = @as(Limb, @truncate(wide)),
852 };852 };
853 }853 }
854};854};
lib/std/crypto/ghash_polyval.zig+31-31
...@@ -96,28 +96,28 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {...@@ -96,28 +96,28 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
96 const product = asm (96 const product = asm (
97 \\ vpclmulqdq $0x11, %[x], %[y], %[out]97 \\ vpclmulqdq $0x11, %[x], %[y], %[out]
98 : [out] "=x" (-> @Vector(2, u64)),98 : [out] "=x" (-> @Vector(2, u64)),
99 : [x] "x" (@bitCast(@Vector(2, u64), x)),99 : [x] "x" (@as(@Vector(2, u64), @bitCast(x))),
100 [y] "x" (@bitCast(@Vector(2, u64), y)),100 [y] "x" (@as(@Vector(2, u64), @bitCast(y))),
101 );101 );
102 return @bitCast(u128, product);102 return @as(u128, @bitCast(product));
103 },103 },
104 .lo => {104 .lo => {
105 const product = asm (105 const product = asm (
106 \\ vpclmulqdq $0x00, %[x], %[y], %[out]106 \\ vpclmulqdq $0x00, %[x], %[y], %[out]
107 : [out] "=x" (-> @Vector(2, u64)),107 : [out] "=x" (-> @Vector(2, u64)),
108 : [x] "x" (@bitCast(@Vector(2, u64), x)),108 : [x] "x" (@as(@Vector(2, u64), @bitCast(x))),
109 [y] "x" (@bitCast(@Vector(2, u64), y)),109 [y] "x" (@as(@Vector(2, u64), @bitCast(y))),
110 );110 );
111 return @bitCast(u128, product);111 return @as(u128, @bitCast(product));
112 },112 },
113 .hi_lo => {113 .hi_lo => {
114 const product = asm (114 const product = asm (
115 \\ vpclmulqdq $0x10, %[x], %[y], %[out]115 \\ vpclmulqdq $0x10, %[x], %[y], %[out]
116 : [out] "=x" (-> @Vector(2, u64)),116 : [out] "=x" (-> @Vector(2, u64)),
117 : [x] "x" (@bitCast(@Vector(2, u64), x)),117 : [x] "x" (@as(@Vector(2, u64), @bitCast(x))),
118 [y] "x" (@bitCast(@Vector(2, u64), y)),118 [y] "x" (@as(@Vector(2, u64), @bitCast(y))),
119 );119 );
120 return @bitCast(u128, product);120 return @as(u128, @bitCast(product));
121 },121 },
122 }122 }
123 }123 }
...@@ -129,28 +129,28 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {...@@ -129,28 +129,28 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
129 const product = asm (129 const product = asm (
130 \\ pmull2 %[out].1q, %[x].2d, %[y].2d130 \\ pmull2 %[out].1q, %[x].2d, %[y].2d
131 : [out] "=w" (-> @Vector(2, u64)),131 : [out] "=w" (-> @Vector(2, u64)),
132 : [x] "w" (@bitCast(@Vector(2, u64), x)),132 : [x] "w" (@as(@Vector(2, u64), @bitCast(x))),
133 [y] "w" (@bitCast(@Vector(2, u64), y)),133 [y] "w" (@as(@Vector(2, u64), @bitCast(y))),
134 );134 );
135 return @bitCast(u128, product);135 return @as(u128, @bitCast(product));
136 },136 },
137 .lo => {137 .lo => {
138 const product = asm (138 const product = asm (
139 \\ pmull %[out].1q, %[x].1d, %[y].1d139 \\ pmull %[out].1q, %[x].1d, %[y].1d
140 : [out] "=w" (-> @Vector(2, u64)),140 : [out] "=w" (-> @Vector(2, u64)),
141 : [x] "w" (@bitCast(@Vector(2, u64), x)),141 : [x] "w" (@as(@Vector(2, u64), @bitCast(x))),
142 [y] "w" (@bitCast(@Vector(2, u64), y)),142 [y] "w" (@as(@Vector(2, u64), @bitCast(y))),
143 );143 );
144 return @bitCast(u128, product);144 return @as(u128, @bitCast(product));
145 },145 },
146 .hi_lo => {146 .hi_lo => {
147 const product = asm (147 const product = asm (
148 \\ pmull %[out].1q, %[x].1d, %[y].1d148 \\ pmull %[out].1q, %[x].1d, %[y].1d
149 : [out] "=w" (-> @Vector(2, u64)),149 : [out] "=w" (-> @Vector(2, u64)),
150 : [x] "w" (@bitCast(@Vector(2, u64), x >> 64)),150 : [x] "w" (@as(@Vector(2, u64), @bitCast(x >> 64))),
151 [y] "w" (@bitCast(@Vector(2, u64), y)),151 [y] "w" (@as(@Vector(2, u64), @bitCast(y))),
152 );152 );
153 return @bitCast(u128, product);153 return @as(u128, @bitCast(product));
154 },154 },
155 }155 }
156 }156 }
...@@ -167,8 +167,8 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {...@@ -167,8 +167,8 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
167167
168 // Software carryless multiplication of two 64-bit integers using native 128-bit registers.168 // Software carryless multiplication of two 64-bit integers using native 128-bit registers.
169 fn clmulSoft128(x_: u128, y_: u128, comptime half: Selector) u128 {169 fn clmulSoft128(x_: u128, y_: u128, comptime half: Selector) u128 {
170 const x = @truncate(u64, if (half == .hi or half == .hi_lo) x_ >> 64 else x_);170 const x = @as(u64, @truncate(if (half == .hi or half == .hi_lo) x_ >> 64 else x_));
171 const y = @truncate(u64, if (half == .hi) y_ >> 64 else y_);171 const y = @as(u64, @truncate(if (half == .hi) y_ >> 64 else y_));
172172
173 const x0 = x & 0x1111111111111110;173 const x0 = x & 0x1111111111111110;
174 const x1 = x & 0x2222222222222220;174 const x1 = x & 0x2222222222222220;
...@@ -216,12 +216,12 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {...@@ -216,12 +216,12 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
216216
217 // Software carryless multiplication of two 128-bit integers using 64-bit registers.217 // Software carryless multiplication of two 128-bit integers using 64-bit registers.
218 fn clmulSoft128_64(x_: u128, y_: u128, comptime half: Selector) u128 {218 fn clmulSoft128_64(x_: u128, y_: u128, comptime half: Selector) u128 {
219 const a = @truncate(u64, if (half == .hi or half == .hi_lo) x_ >> 64 else x_);219 const a = @as(u64, @truncate(if (half == .hi or half == .hi_lo) x_ >> 64 else x_));
220 const b = @truncate(u64, if (half == .hi) y_ >> 64 else y_);220 const b = @as(u64, @truncate(if (half == .hi) y_ >> 64 else y_));
221 const a0 = @truncate(u32, a);221 const a0 = @as(u32, @truncate(a));
222 const a1 = @truncate(u32, a >> 32);222 const a1 = @as(u32, @truncate(a >> 32));
223 const b0 = @truncate(u32, b);223 const b0 = @as(u32, @truncate(b));
224 const b1 = @truncate(u32, b >> 32);224 const b1 = @as(u32, @truncate(b >> 32));
225 const lo = clmulSoft32(a0, b0);225 const lo = clmulSoft32(a0, b0);
226 const hi = clmulSoft32(a1, b1);226 const hi = clmulSoft32(a1, b1);
227 const mid = clmulSoft32(a0 ^ a1, b0 ^ b1) ^ lo ^ hi;227 const mid = clmulSoft32(a0 ^ a1, b0 ^ b1) ^ lo ^ hi;
...@@ -256,8 +256,8 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {...@@ -256,8 +256,8 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
256 // Multiply two 128-bit integers in GF(2^128).256 // Multiply two 128-bit integers in GF(2^128).
257 inline fn clmul128(x: u128, y: u128) I256 {257 inline fn clmul128(x: u128, y: u128) I256 {
258 if (mul_algorithm == .karatsuba) {258 if (mul_algorithm == .karatsuba) {
259 const x_hi = @truncate(u64, x >> 64);259 const x_hi = @as(u64, @truncate(x >> 64));
260 const y_hi = @truncate(u64, y >> 64);260 const y_hi = @as(u64, @truncate(y >> 64));
261 const r_lo = clmul(x, y, .lo);261 const r_lo = clmul(x, y, .lo);
262 const r_hi = clmul(x, y, .hi);262 const r_hi = clmul(x, y, .hi);
263 const r_mid = clmul(x ^ x_hi, y ^ y_hi, .lo) ^ r_lo ^ r_hi;263 const r_mid = clmul(x ^ x_hi, y ^ y_hi, .lo) ^ r_lo ^ r_hi;
...@@ -407,7 +407,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {...@@ -407,7 +407,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
407 st.pad();407 st.pad();
408 mem.writeInt(u128, out[0..16], st.acc, endian);408 mem.writeInt(u128, out[0..16], st.acc, endian);
409409
410 utils.secureZero(u8, @ptrCast([*]u8, st)[0..@sizeOf(Self)]);410 utils.secureZero(u8, @as([*]u8, @ptrCast(st))[0..@sizeOf(Self)]);
411 }411 }
412412
413 /// Compute the GHASH of a message.413 /// Compute the GHASH of a message.
...@@ -442,7 +442,7 @@ test "ghash2" {...@@ -442,7 +442,7 @@ test "ghash2" {
442 var key: [16]u8 = undefined;442 var key: [16]u8 = undefined;
443 var i: usize = 0;443 var i: usize = 0;
444 while (i < key.len) : (i += 1) {444 while (i < key.len) : (i += 1) {
445 key[i] = @intCast(u8, i * 15 + 1);445 key[i] = @as(u8, @intCast(i * 15 + 1));
446 }446 }
447 const tvs = [_]struct { len: usize, hash: [:0]const u8 }{447 const tvs = [_]struct { len: usize, hash: [:0]const u8 }{
448 .{ .len = 5263, .hash = "b9395f37c131cd403a327ccf82ec016a" },448 .{ .len = 5263, .hash = "b9395f37c131cd403a327ccf82ec016a" },
...@@ -461,7 +461,7 @@ test "ghash2" {...@@ -461,7 +461,7 @@ test "ghash2" {
461 var m: [tv.len]u8 = undefined;461 var m: [tv.len]u8 = undefined;
462 i = 0;462 i = 0;
463 while (i < m.len) : (i += 1) {463 while (i < m.len) : (i += 1) {
464 m[i] = @truncate(u8, i % 254 + 1);464 m[i] = @as(u8, @truncate(i % 254 + 1));
465 }465 }
466 var st = Ghash.init(&key);466 var st = Ghash.init(&key);
467 st.update(&m);467 st.update(&m);
lib/std/crypto/isap.zig+1-1
...@@ -67,7 +67,7 @@ pub const IsapA128A = struct {...@@ -67,7 +67,7 @@ pub const IsapA128A = struct {
67 var i: usize = 0;67 var i: usize = 0;
68 while (i < y.len * 8 - 1) : (i += 1) {68 while (i < y.len * 8 - 1) : (i += 1) {
69 const cur_byte_pos = i / 8;69 const cur_byte_pos = i / 8;
70 const cur_bit_pos = @truncate(u3, 7 - (i % 8));70 const cur_bit_pos = @as(u3, @truncate(7 - (i % 8)));
71 const cur_bit = ((y[cur_byte_pos] >> cur_bit_pos) & 1) << 7;71 const cur_bit = ((y[cur_byte_pos] >> cur_bit_pos) & 1) << 7;
72 isap.st.addByte(cur_bit, 0);72 isap.st.addByte(cur_bit, 0);
73 isap.st.permuteR(1);73 isap.st.permuteR(1);
lib/std/crypto/keccak_p.zig+2-2
...@@ -33,7 +33,7 @@ pub fn KeccakF(comptime f: u11) type {...@@ -33,7 +33,7 @@ pub fn KeccakF(comptime f: u11) type {
33 0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008,33 0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008,
34 };34 };
35 var rc: [max_rounds]T = undefined;35 var rc: [max_rounds]T = undefined;
36 for (&rc, RC64[0..max_rounds]) |*t, c| t.* = @truncate(T, c);36 for (&rc, RC64[0..max_rounds]) |*t, c| t.* = @as(T, @truncate(c));
37 break :rc rc;37 break :rc rc;
38 };38 };
3939
...@@ -75,7 +75,7 @@ pub fn KeccakF(comptime f: u11) type {...@@ -75,7 +75,7 @@ pub fn KeccakF(comptime f: u11) type {
7575
76 /// XOR a byte into the state at a given offset.76 /// XOR a byte into the state at a given offset.
77 pub fn addByte(self: *Self, byte: u8, offset: usize) void {77 pub fn addByte(self: *Self, byte: u8, offset: usize) void {
78 const z = @sizeOf(T) * @truncate(math.Log2Int(T), offset % @sizeOf(T));78 const z = @sizeOf(T) * @as(math.Log2Int(T), @truncate(offset % @sizeOf(T)));
79 self.st[offset / @sizeOf(T)] ^= @as(T, byte) << z;79 self.st[offset / @sizeOf(T)] ^= @as(T, byte) << z;
80 }80 }
8181
lib/std/crypto/kyber_d00.zig+36-36
...@@ -579,7 +579,7 @@ test "invNTTReductions bounds" {...@@ -579,7 +579,7 @@ test "invNTTReductions bounds" {
579 if (j < 0) {579 if (j < 0) {
580 break;580 break;
581 }581 }
582 xs[@intCast(usize, j)] = 1;582 xs[@as(usize, @intCast(j))] = 1;
583 }583 }
584 }584 }
585}585}
...@@ -615,7 +615,7 @@ fn invertMod(a: anytype, p: @TypeOf(a)) @TypeOf(a) {...@@ -615,7 +615,7 @@ fn invertMod(a: anytype, p: @TypeOf(a)) @TypeOf(a) {
615615
616// Reduce mod q for testing.616// Reduce mod q for testing.
617fn modQ32(x: i32) i16 {617fn modQ32(x: i32) i16 {
618 var y = @intCast(i16, @rem(x, @as(i32, Q)));618 var y = @as(i16, @intCast(@rem(x, @as(i32, Q))));
619 if (y < 0) {619 if (y < 0) {
620 y += Q;620 y += Q;
621 }621 }
...@@ -638,7 +638,7 @@ fn montReduce(x: i32) i16 {...@@ -638,7 +638,7 @@ fn montReduce(x: i32) i16 {
638 // Note that x q' might be as big as 2³² and could overflow the int32638 // Note that x q' might be as big as 2³² and could overflow the int32
639 // multiplication in the last line. However for any int32s a and b,639 // multiplication in the last line. However for any int32s a and b,
640 // we have int32(int64(a)*int64(b)) = int32(a*b) and so the result is ok.640 // we have int32(int64(a)*int64(b)) = int32(a*b) and so the result is ok.
641 const m = @truncate(i16, @truncate(i32, x *% qInv));641 const m = @as(i16, @truncate(@as(i32, @truncate(x *% qInv))));
642642
643 // Note that x - m q is divisible by R; indeed modulo R we have643 // Note that x - m q is divisible by R; indeed modulo R we have
644 //644 //
...@@ -652,7 +652,7 @@ fn montReduce(x: i32) i16 {...@@ -652,7 +652,7 @@ fn montReduce(x: i32) i16 {
652 // and as both 2¹⁵ q ≤ m q, x < 2¹⁵ q, we have652 // and as both 2¹⁵ q ≤ m q, x < 2¹⁵ q, we have
653 // 2¹⁶ q ≤ x - m q < 2¹⁶ and so q ≤ (x - m q) / R < q as desired.653 // 2¹⁶ q ≤ x - m q < 2¹⁶ and so q ≤ (x - m q) / R < q as desired.
654 const yR = x - @as(i32, m) * @as(i32, Q);654 const yR = x - @as(i32, m) * @as(i32, Q);
655 return @bitCast(i16, @truncate(u16, @bitCast(u32, yR) >> 16));655 return @as(i16, @bitCast(@as(u16, @truncate(@as(u32, @bitCast(yR)) >> 16))));
656}656}
657657
658test "Test montReduce" {658test "Test montReduce" {
...@@ -676,7 +676,7 @@ fn feToMont(x: i16) i16 {...@@ -676,7 +676,7 @@ fn feToMont(x: i16) i16 {
676test "Test feToMont" {676test "Test feToMont" {
677 var x: i32 = -(1 << 15);677 var x: i32 = -(1 << 15);
678 while (x < 1 << 15) : (x += 1) {678 while (x < 1 << 15) : (x += 1) {
679 const y = feToMont(@intCast(i16, x));679 const y = feToMont(@as(i16, @intCast(x)));
680 try testing.expectEqual(modQ32(@as(i32, y)), modQ32(x * r_mod_q));680 try testing.expectEqual(modQ32(@as(i32, y)), modQ32(x * r_mod_q));
681 }681 }
682}682}
...@@ -703,14 +703,14 @@ fn feBarrettReduce(x: i16) i16 {...@@ -703,14 +703,14 @@ fn feBarrettReduce(x: i16) i16 {
703 // To actually compute this, note that703 // To actually compute this, note that
704 //704 //
705 // ⌊x 20156/2²⁶⌋ = (20159 x) >> 26.705 // ⌊x 20156/2²⁶⌋ = (20159 x) >> 26.
706 return x -% @intCast(i16, (@as(i32, x) * 20159) >> 26) *% Q;706 return x -% @as(i16, @intCast((@as(i32, x) * 20159) >> 26)) *% Q;
707}707}
708708
709test "Test Barrett reduction" {709test "Test Barrett reduction" {
710 var x: i32 = -(1 << 15);710 var x: i32 = -(1 << 15);
711 while (x < 1 << 15) : (x += 1) {711 while (x < 1 << 15) : (x += 1) {
712 var y1 = feBarrettReduce(@intCast(i16, x));712 var y1 = feBarrettReduce(@as(i16, @intCast(x)));
713 const y2 = @mod(@intCast(i16, x), Q);713 const y2 = @mod(@as(i16, @intCast(x)), Q);
714 if (x < 0 and @rem(-x, Q) == 0) {714 if (x < 0 and @rem(-x, Q) == 0) {
715 y1 -= Q;715 y1 -= Q;
716 }716 }
...@@ -729,9 +729,9 @@ fn csubq(x: i16) i16 {...@@ -729,9 +729,9 @@ fn csubq(x: i16) i16 {
729test "Test csubq" {729test "Test csubq" {
730 var x: i32 = -29439;730 var x: i32 = -29439;
731 while (x < 1 << 15) : (x += 1) {731 while (x < 1 << 15) : (x += 1) {
732 const y1 = csubq(@intCast(i16, x));732 const y1 = csubq(@as(i16, @intCast(x)));
733 var y2 = @intCast(i16, x);733 var y2 = @as(i16, @intCast(x));
734 if (@intCast(i16, x) >= Q) {734 if (@as(i16, @intCast(x)) >= Q) {
735 y2 -= Q;735 y2 -= Q;
736 }736 }
737 try testing.expectEqual(y1, y2);737 try testing.expectEqual(y1, y2);
...@@ -762,7 +762,7 @@ fn computeZetas() [128]i16 {...@@ -762,7 +762,7 @@ fn computeZetas() [128]i16 {
762 @setEvalBranchQuota(10000);762 @setEvalBranchQuota(10000);
763 var ret: [128]i16 = undefined;763 var ret: [128]i16 = undefined;
764 for (&ret, 0..) |*r, i| {764 for (&ret, 0..) |*r, i| {
765 const t = @intCast(i16, mpow(@as(i32, zeta), @bitReverse(@intCast(u7, i)), Q));765 const t = @as(i16, @intCast(mpow(@as(i32, zeta), @bitReverse(@as(u7, @intCast(i))), Q)));
766 r.* = csubq(feBarrettReduce(feToMont(t)));766 r.* = csubq(feBarrettReduce(feToMont(t)));
767 }767 }
768 return ret;768 return ret;
...@@ -945,7 +945,7 @@ const Poly = struct {...@@ -945,7 +945,7 @@ const Poly = struct {
945 if (i < 0) {945 if (i < 0) {
946 break;946 break;
947 }947 }
948 p.cs[@intCast(usize, i)] = feBarrettReduce(p.cs[@intCast(usize, i)]);948 p.cs[@as(usize, @intCast(i))] = feBarrettReduce(p.cs[@as(usize, @intCast(i))]);
949 }949 }
950 }950 }
951951
...@@ -1020,8 +1020,8 @@ const Poly = struct {...@@ -1020,8 +1020,8 @@ const Poly = struct {
1020 // = ⌊(2ᵈ/q)x+½⌋ mod⁺ 2ᵈ1020 // = ⌊(2ᵈ/q)x+½⌋ mod⁺ 2ᵈ
1021 // = ⌊((x << d) + q/2) / q⌋ mod⁺ 2ᵈ1021 // = ⌊((x << d) + q/2) / q⌋ mod⁺ 2ᵈ
1022 // = DIV((x << d) + q/2, q) & ((1<<d) - 1)1022 // = DIV((x << d) + q/2, q) & ((1<<d) - 1)
1023 const t = @intCast(u32, p.cs[in_off + i]) << d;1023 const t = @as(u32, @intCast(p.cs[in_off + i])) << d;
1024 in[i] = @intCast(u16, @divFloor(t + q_over_2, Q) & two_d_min_1);1024 in[i] = @as(u16, @intCast(@divFloor(t + q_over_2, Q) & two_d_min_1));
1025 }1025 }
10261026
1027 // Now we pack the d-bit integers from `in' into out as bytes.1027 // Now we pack the d-bit integers from `in' into out as bytes.
...@@ -1032,7 +1032,7 @@ const Poly = struct {...@@ -1032,7 +1032,7 @@ const Poly = struct {
1032 comptime var todo: usize = 8;1032 comptime var todo: usize = 8;
1033 inline while (todo > 0) {1033 inline while (todo > 0) {
1034 const out_shift = comptime 8 - todo;1034 const out_shift = comptime 8 - todo;
1035 out[out_off + j] |= @truncate(u8, (in[i] >> in_shift) << out_shift);1035 out[out_off + j] |= @as(u8, @truncate((in[i] >> in_shift) << out_shift));
10361036
1037 const done = comptime @min(@min(d, todo), d - in_shift);1037 const done = comptime @min(@min(d, todo), d - in_shift);
1038 todo -= done;1038 todo -= done;
...@@ -1094,7 +1094,7 @@ const Poly = struct {...@@ -1094,7 +1094,7 @@ const Poly = struct {
1094 // = ⌊(qx + 2ᵈ⁻¹)/2ᵈ⌋1094 // = ⌊(qx + 2ᵈ⁻¹)/2ᵈ⌋
1095 // = (qx + (1<<(d-1))) >> d1095 // = (qx + (1<<(d-1))) >> d
1096 const qx = @as(u32, out) * @as(u32, Q);1096 const qx = @as(u32, out) * @as(u32, Q);
1097 ret.cs[out_off + i] = @intCast(i16, (qx + (1 << (d - 1))) >> d);1097 ret.cs[out_off + i] = @as(i16, @intCast((qx + (1 << (d - 1))) >> d));
1098 }1098 }
10991099
1100 in_off += in_batch_size;1100 in_off += in_batch_size;
...@@ -1209,8 +1209,8 @@ const Poly = struct {...@@ -1209,8 +1209,8 @@ const Poly = struct {
1209 // Extract each a and b separately and set coefficient in polynomial.1209 // Extract each a and b separately and set coefficient in polynomial.
1210 inline for (0..batch_count) |j| {1210 inline for (0..batch_count) |j| {
1211 const mask2 = comptime (1 << eta) - 1;1211 const mask2 = comptime (1 << eta) - 1;
1212 const a = @intCast(i16, (d >> (comptime (2 * j * eta))) & mask2);1212 const a = @as(i16, @intCast((d >> (comptime (2 * j * eta))) & mask2));
1213 const b = @intCast(i16, (d >> (comptime ((2 * j + 1) * eta))) & mask2);1213 const b = @as(i16, @intCast((d >> (comptime ((2 * j + 1) * eta))) & mask2));
1214 ret.cs[batch_count * i + j] = a - b;1214 ret.cs[batch_count * i + j] = a - b;
1215 }1215 }
1216 }1216 }
...@@ -1246,7 +1246,7 @@ const Poly = struct {...@@ -1246,7 +1246,7 @@ const Poly = struct {
12461246
1247 inline for (ts) |t| {1247 inline for (ts) |t| {
1248 if (t < Q) {1248 if (t < Q) {
1249 ret.cs[i] = @intCast(i16, t);1249 ret.cs[i] = @as(i16, @intCast(t));
1250 i += 1;1250 i += 1;
12511251
1252 if (i == N) {1252 if (i == N) {
...@@ -1266,11 +1266,11 @@ const Poly = struct {...@@ -1266,11 +1266,11 @@ const Poly = struct {
1266 fn toBytes(p: Poly) [bytes_length]u8 {1266 fn toBytes(p: Poly) [bytes_length]u8 {
1267 var ret: [bytes_length]u8 = undefined;1267 var ret: [bytes_length]u8 = undefined;
1268 for (0..comptime N / 2) |i| {1268 for (0..comptime N / 2) |i| {
1269 const t0 = @intCast(u16, p.cs[2 * i]);1269 const t0 = @as(u16, @intCast(p.cs[2 * i]));
1270 const t1 = @intCast(u16, p.cs[2 * i + 1]);1270 const t1 = @as(u16, @intCast(p.cs[2 * i + 1]));
1271 ret[3 * i] = @truncate(u8, t0);1271 ret[3 * i] = @as(u8, @truncate(t0));
1272 ret[3 * i + 1] = @truncate(u8, (t0 >> 8) | (t1 << 4));1272 ret[3 * i + 1] = @as(u8, @truncate((t0 >> 8) | (t1 << 4)));
1273 ret[3 * i + 2] = @truncate(u8, t1 >> 4);1273 ret[3 * i + 2] = @as(u8, @truncate(t1 >> 4));
1274 }1274 }
1275 return ret;1275 return ret;
1276 }1276 }
...@@ -1356,7 +1356,7 @@ fn Vec(comptime K: u8) type {...@@ -1356,7 +1356,7 @@ fn Vec(comptime K: u8) type {
1356 fn noise(comptime eta: u8, nonce: u8, seed: *const [32]u8) Self {1356 fn noise(comptime eta: u8, nonce: u8, seed: *const [32]u8) Self {
1357 var ret: Self = undefined;1357 var ret: Self = undefined;
1358 for (0..K) |i| {1358 for (0..K) |i| {
1359 ret.ps[i] = Poly.noise(eta, nonce + @intCast(u8, i), seed);1359 ret.ps[i] = Poly.noise(eta, nonce + @as(u8, @intCast(i)), seed);
1360 }1360 }
1361 return ret;1361 return ret;
1362 }1362 }
...@@ -1534,7 +1534,7 @@ test "Compression" {...@@ -1534,7 +1534,7 @@ test "Compression" {
1534test "noise" {1534test "noise" {
1535 var seed: [32]u8 = undefined;1535 var seed: [32]u8 = undefined;
1536 for (&seed, 0..) |*s, i| {1536 for (&seed, 0..) |*s, i| {
1537 s.* = @intCast(u8, i);1537 s.* = @as(u8, @intCast(i));
1538 }1538 }
1539 try testing.expectEqual(Poly.noise(3, 37, &seed).cs, .{1539 try testing.expectEqual(Poly.noise(3, 37, &seed).cs, .{
1540 0, 0, 1, -1, 0, 2, 0, -1, -1, 3, 0, 1, -2, -2, 0, 1, -2,1540 0, 0, 1, -1, 0, 2, 0, -1, -1, 3, 0, 1, -2, -2, 0, 1, -2,
...@@ -1580,7 +1580,7 @@ test "noise" {...@@ -1580,7 +1580,7 @@ test "noise" {
1580test "uniform sampling" {1580test "uniform sampling" {
1581 var seed: [32]u8 = undefined;1581 var seed: [32]u8 = undefined;
1582 for (&seed, 0..) |*s, i| {1582 for (&seed, 0..) |*s, i| {
1583 s.* = @intCast(u8, i);1583 s.* = @as(u8, @intCast(i));
1584 }1584 }
1585 try testing.expectEqual(Poly.uniform(seed, 1, 0).cs, .{1585 try testing.expectEqual(Poly.uniform(seed, 1, 0).cs, .{
1586 797, 993, 161, 6, 2608, 2385, 2096, 2661, 1676, 247, 2440,1586 797, 993, 161, 6, 2608, 2385, 2096, 2661, 1676, 247, 2440,
...@@ -1623,17 +1623,17 @@ test "Test inner PKE" {...@@ -1623,17 +1623,17 @@ test "Test inner PKE" {
1623 var seed: [32]u8 = undefined;1623 var seed: [32]u8 = undefined;
1624 var pt: [32]u8 = undefined;1624 var pt: [32]u8 = undefined;
1625 for (&seed, &pt, 0..) |*s, *p, i| {1625 for (&seed, &pt, 0..) |*s, *p, i| {
1626 s.* = @intCast(u8, i);1626 s.* = @as(u8, @intCast(i));
1627 p.* = @intCast(u8, i + 32);1627 p.* = @as(u8, @intCast(i + 32));
1628 }1628 }
1629 inline for (modes) |mode| {1629 inline for (modes) |mode| {
1630 for (0..100) |i| {1630 for (0..100) |i| {
1631 var pk: mode.InnerPk = undefined;1631 var pk: mode.InnerPk = undefined;
1632 var sk: mode.InnerSk = undefined;1632 var sk: mode.InnerSk = undefined;
1633 seed[0] = @intCast(u8, i);1633 seed[0] = @as(u8, @intCast(i));
1634 mode.innerKeyFromSeed(seed, &pk, &sk);1634 mode.innerKeyFromSeed(seed, &pk, &sk);
1635 for (0..10) |j| {1635 for (0..10) |j| {
1636 seed[1] = @intCast(u8, j);1636 seed[1] = @as(u8, @intCast(j));
1637 try testing.expectEqual(sk.decrypt(&pk.encrypt(&pt, &seed)), pt);1637 try testing.expectEqual(sk.decrypt(&pk.encrypt(&pt, &seed)), pt);
1638 }1638 }
1639 }1639 }
...@@ -1643,18 +1643,18 @@ test "Test inner PKE" {...@@ -1643,18 +1643,18 @@ test "Test inner PKE" {
1643test "Test happy flow" {1643test "Test happy flow" {
1644 var seed: [64]u8 = undefined;1644 var seed: [64]u8 = undefined;
1645 for (&seed, 0..) |*s, i| {1645 for (&seed, 0..) |*s, i| {
1646 s.* = @intCast(u8, i);1646 s.* = @as(u8, @intCast(i));
1647 }1647 }
1648 inline for (modes) |mode| {1648 inline for (modes) |mode| {
1649 for (0..100) |i| {1649 for (0..100) |i| {
1650 seed[0] = @intCast(u8, i);1650 seed[0] = @as(u8, @intCast(i));
1651 const kp = try mode.KeyPair.create(seed);1651 const kp = try mode.KeyPair.create(seed);
1652 const sk = try mode.SecretKey.fromBytes(&kp.secret_key.toBytes());1652 const sk = try mode.SecretKey.fromBytes(&kp.secret_key.toBytes());
1653 try testing.expectEqual(sk, kp.secret_key);1653 try testing.expectEqual(sk, kp.secret_key);
1654 const pk = try mode.PublicKey.fromBytes(&kp.public_key.toBytes());1654 const pk = try mode.PublicKey.fromBytes(&kp.public_key.toBytes());
1655 try testing.expectEqual(pk, kp.public_key);1655 try testing.expectEqual(pk, kp.public_key);
1656 for (0..10) |j| {1656 for (0..10) |j| {
1657 seed[1] = @intCast(u8, j);1657 seed[1] = @as(u8, @intCast(j));
1658 const e = pk.encaps(seed[0..32].*);1658 const e = pk.encaps(seed[0..32].*);
1659 try testing.expectEqual(e.shared_secret, try sk.decaps(&e.ciphertext));1659 try testing.expectEqual(e.shared_secret, try sk.decaps(&e.ciphertext));
1660 }1660 }
...@@ -1675,7 +1675,7 @@ test "NIST KAT test" {...@@ -1675,7 +1675,7 @@ test "NIST KAT test" {
1675 const mode = modeHash[0];1675 const mode = modeHash[0];
1676 var seed: [48]u8 = undefined;1676 var seed: [48]u8 = undefined;
1677 for (&seed, 0..) |*s, i| {1677 for (&seed, 0..) |*s, i| {
1678 s.* = @intCast(u8, i);1678 s.* = @as(u8, @intCast(i));
1679 }1679 }
1680 var f = sha2.Sha256.init(.{});1680 var f = sha2.Sha256.init(.{});
1681 const fw = f.writer();1681 const fw = f.writer();
lib/std/crypto/md5.zig+3-3
...@@ -80,7 +80,7 @@ pub const Md5 = struct {...@@ -80,7 +80,7 @@ pub const Md5 = struct {
80 // Copy any remainder for next pass.80 // Copy any remainder for next pass.
81 const b_slice = b[off..];81 const b_slice = b[off..];
82 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);82 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
83 d.buf_len += @intCast(u8, b_slice.len);83 d.buf_len += @as(u8, @intCast(b_slice.len));
8484
85 // Md5 uses the bottom 64-bits for length padding85 // Md5 uses the bottom 64-bits for length padding
86 d.total_len +%= b.len;86 d.total_len +%= b.len;
...@@ -103,9 +103,9 @@ pub const Md5 = struct {...@@ -103,9 +103,9 @@ pub const Md5 = struct {
103 // Append message length.103 // Append message length.
104 var i: usize = 1;104 var i: usize = 1;
105 var len = d.total_len >> 5;105 var len = d.total_len >> 5;
106 d.buf[56] = @intCast(u8, d.total_len & 0x1f) << 3;106 d.buf[56] = @as(u8, @intCast(d.total_len & 0x1f)) << 3;
107 while (i < 8) : (i += 1) {107 while (i < 8) : (i += 1) {
108 d.buf[56 + i] = @intCast(u8, len & 0xff);108 d.buf[56 + i] = @as(u8, @intCast(len & 0xff));
109 len >>= 8;109 len >>= 8;
110 }110 }
111111
lib/std/crypto/pbkdf2.zig+1-1
...@@ -74,7 +74,7 @@ pub fn pbkdf2(dk: []u8, password: []const u8, salt: []const u8, rounds: u32, com...@@ -74,7 +74,7 @@ pub fn pbkdf2(dk: []u8, password: []const u8, salt: []const u8, rounds: u32, com
74 // block74 // block
75 //75 //
7676
77 const blocks_count = @intCast(u32, std.math.divCeil(usize, dk_len, h_len) catch unreachable);77 const blocks_count = @as(u32, @intCast(std.math.divCeil(usize, dk_len, h_len) catch unreachable));
78 var r = dk_len % h_len;78 var r = dk_len % h_len;
79 if (r == 0) {79 if (r == 0) {
80 r = h_len;80 r = h_len;
lib/std/crypto/pcurves/common.zig+3-3
...@@ -120,7 +120,7 @@ pub fn Field(comptime params: FieldParams) type {...@@ -120,7 +120,7 @@ pub fn Field(comptime params: FieldParams) type {
120 /// Return true if the element is odd.120 /// Return true if the element is odd.
121 pub fn isOdd(fe: Fe) bool {121 pub fn isOdd(fe: Fe) bool {
122 const s = fe.toBytes(.Little);122 const s = fe.toBytes(.Little);
123 return @truncate(u1, s[0]) != 0;123 return @as(u1, @truncate(s[0])) != 0;
124 }124 }
125125
126 /// Conditonally replace a field element with `a` if `c` is positive.126 /// Conditonally replace a field element with `a` if `c` is positive.
...@@ -179,7 +179,7 @@ pub fn Field(comptime params: FieldParams) type {...@@ -179,7 +179,7 @@ pub fn Field(comptime params: FieldParams) type {
179 var x: T = n;179 var x: T = n;
180 var t = a;180 var t = a;
181 while (true) {181 while (true) {
182 if (@truncate(u1, x) != 0) fe = fe.mul(t);182 if (@as(u1, @truncate(x)) != 0) fe = fe.mul(t);
183 x >>= 1;183 x >>= 1;
184 if (x == 0) break;184 if (x == 0) break;
185 t = t.sq();185 t = t.sq();
...@@ -233,7 +233,7 @@ pub fn Field(comptime params: FieldParams) type {...@@ -233,7 +233,7 @@ pub fn Field(comptime params: FieldParams) type {
233 }233 }
234 var v_opp: Limbs = undefined;234 var v_opp: Limbs = undefined;
235 fiat.opp(&v_opp, v);235 fiat.opp(&v_opp, v);
236 fiat.selectznz(&v, @truncate(u1, f[f.len - 1] >> (@bitSizeOf(Word) - 1)), v, v_opp);236 fiat.selectznz(&v, @as(u1, @truncate(f[f.len - 1] >> (@bitSizeOf(Word) - 1))), v, v_opp);
237237
238 const precomp = blk: {238 const precomp = blk: {
239 var precomp: Limbs = undefined;239 var precomp: Limbs = undefined;
lib/std/crypto/pcurves/p256.zig+10-10
...@@ -318,7 +318,7 @@ pub const P256 = struct {...@@ -318,7 +318,7 @@ pub const P256 = struct {
318 var t = P256.identityElement;318 var t = P256.identityElement;
319 comptime var i: u8 = 1;319 comptime var i: u8 = 1;
320 inline while (i < pc.len) : (i += 1) {320 inline while (i < pc.len) : (i += 1) {
321 t.cMov(pc[i], @truncate(u1, (@as(usize, b ^ i) -% 1) >> 8));321 t.cMov(pc[i], @as(u1, @truncate((@as(usize, b ^ i) -% 1) >> 8)));
322 }322 }
323 return t;323 return t;
324 }324 }
...@@ -326,8 +326,8 @@ pub const P256 = struct {...@@ -326,8 +326,8 @@ pub const P256 = struct {
326 fn slide(s: [32]u8) [2 * 32 + 1]i8 {326 fn slide(s: [32]u8) [2 * 32 + 1]i8 {
327 var e: [2 * 32 + 1]i8 = undefined;327 var e: [2 * 32 + 1]i8 = undefined;
328 for (s, 0..) |x, i| {328 for (s, 0..) |x, i| {
329 e[i * 2 + 0] = @as(i8, @truncate(u4, x));329 e[i * 2 + 0] = @as(i8, @as(u4, @truncate(x)));
330 e[i * 2 + 1] = @as(i8, @truncate(u4, x >> 4));330 e[i * 2 + 1] = @as(i8, @as(u4, @truncate(x >> 4)));
331 }331 }
332 // Now, e[0..63] is between 0 and 15, e[63] is between 0 and 7332 // Now, e[0..63] is between 0 and 15, e[63] is between 0 and 7
333 var carry: i8 = 0;333 var carry: i8 = 0;
...@@ -351,9 +351,9 @@ pub const P256 = struct {...@@ -351,9 +351,9 @@ pub const P256 = struct {
351 while (true) : (pos -= 1) {351 while (true) : (pos -= 1) {
352 const slot = e[pos];352 const slot = e[pos];
353 if (slot > 0) {353 if (slot > 0) {
354 q = q.add(pc[@intCast(usize, slot)]);354 q = q.add(pc[@as(usize, @intCast(slot))]);
355 } else if (slot < 0) {355 } else if (slot < 0) {
356 q = q.sub(pc[@intCast(usize, -slot)]);356 q = q.sub(pc[@as(usize, @intCast(-slot))]);
357 }357 }
358 if (pos == 0) break;358 if (pos == 0) break;
359 q = q.dbl().dbl().dbl().dbl();359 q = q.dbl().dbl().dbl().dbl();
...@@ -366,7 +366,7 @@ pub const P256 = struct {...@@ -366,7 +366,7 @@ pub const P256 = struct {
366 var q = P256.identityElement;366 var q = P256.identityElement;
367 var pos: usize = 252;367 var pos: usize = 252;
368 while (true) : (pos -= 4) {368 while (true) : (pos -= 4) {
369 const slot = @truncate(u4, (s[pos >> 3] >> @truncate(u3, pos)));369 const slot = @as(u4, @truncate((s[pos >> 3] >> @as(u3, @truncate(pos)))));
370 if (vartime) {370 if (vartime) {
371 if (slot != 0) {371 if (slot != 0) {
372 q = q.add(pc[slot]);372 q = q.add(pc[slot]);
...@@ -445,15 +445,15 @@ pub const P256 = struct {...@@ -445,15 +445,15 @@ pub const P256 = struct {
445 while (true) : (pos -= 1) {445 while (true) : (pos -= 1) {
446 const slot1 = e1[pos];446 const slot1 = e1[pos];
447 if (slot1 > 0) {447 if (slot1 > 0) {
448 q = q.add(pc1[@intCast(usize, slot1)]);448 q = q.add(pc1[@as(usize, @intCast(slot1))]);
449 } else if (slot1 < 0) {449 } else if (slot1 < 0) {
450 q = q.sub(pc1[@intCast(usize, -slot1)]);450 q = q.sub(pc1[@as(usize, @intCast(-slot1))]);
451 }451 }
452 const slot2 = e2[pos];452 const slot2 = e2[pos];
453 if (slot2 > 0) {453 if (slot2 > 0) {
454 q = q.add(pc2[@intCast(usize, slot2)]);454 q = q.add(pc2[@as(usize, @intCast(slot2))]);
455 } else if (slot2 < 0) {455 } else if (slot2 < 0) {
456 q = q.sub(pc2[@intCast(usize, -slot2)]);456 q = q.sub(pc2[@as(usize, @intCast(-slot2))]);
457 }457 }
458 if (pos == 0) break;458 if (pos == 0) break;
459 q = q.dbl().dbl().dbl().dbl();459 q = q.dbl().dbl().dbl().dbl();
lib/std/crypto/pcurves/p256/p256_64.zig+36-36
...@@ -119,8 +119,8 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {...@@ -119,8 +119,8 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
119 @setRuntimeSafety(mode == .Debug);119 @setRuntimeSafety(mode == .Debug);
120120
121 const x = @as(u128, arg1) * @as(u128, arg2);121 const x = @as(u128, arg1) * @as(u128, arg2);
122 out1.* = @truncate(u64, x);122 out1.* = @as(u64, @truncate(x));
123 out2.* = @truncate(u64, x >> 64);123 out2.* = @as(u64, @truncate(x >> 64));
124}124}
125125
126/// The function cmovznzU64 is a single-word conditional move.126/// The function cmovznzU64 is a single-word conditional move.
...@@ -1355,62 +1355,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {...@@ -1355,62 +1355,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {
1355 const x2 = (arg1[2]);1355 const x2 = (arg1[2]);
1356 const x3 = (arg1[1]);1356 const x3 = (arg1[1]);
1357 const x4 = (arg1[0]);1357 const x4 = (arg1[0]);
1358 const x5 = @truncate(u8, (x4 & @as(u64, 0xff)));1358 const x5 = @as(u8, @truncate((x4 & @as(u64, 0xff))));
1359 const x6 = (x4 >> 8);1359 const x6 = (x4 >> 8);
1360 const x7 = @truncate(u8, (x6 & @as(u64, 0xff)));1360 const x7 = @as(u8, @truncate((x6 & @as(u64, 0xff))));
1361 const x8 = (x6 >> 8);1361 const x8 = (x6 >> 8);
1362 const x9 = @truncate(u8, (x8 & @as(u64, 0xff)));1362 const x9 = @as(u8, @truncate((x8 & @as(u64, 0xff))));
1363 const x10 = (x8 >> 8);1363 const x10 = (x8 >> 8);
1364 const x11 = @truncate(u8, (x10 & @as(u64, 0xff)));1364 const x11 = @as(u8, @truncate((x10 & @as(u64, 0xff))));
1365 const x12 = (x10 >> 8);1365 const x12 = (x10 >> 8);
1366 const x13 = @truncate(u8, (x12 & @as(u64, 0xff)));1366 const x13 = @as(u8, @truncate((x12 & @as(u64, 0xff))));
1367 const x14 = (x12 >> 8);1367 const x14 = (x12 >> 8);
1368 const x15 = @truncate(u8, (x14 & @as(u64, 0xff)));1368 const x15 = @as(u8, @truncate((x14 & @as(u64, 0xff))));
1369 const x16 = (x14 >> 8);1369 const x16 = (x14 >> 8);
1370 const x17 = @truncate(u8, (x16 & @as(u64, 0xff)));1370 const x17 = @as(u8, @truncate((x16 & @as(u64, 0xff))));
1371 const x18 = @truncate(u8, (x16 >> 8));1371 const x18 = @as(u8, @truncate((x16 >> 8)));
1372 const x19 = @truncate(u8, (x3 & @as(u64, 0xff)));1372 const x19 = @as(u8, @truncate((x3 & @as(u64, 0xff))));
1373 const x20 = (x3 >> 8);1373 const x20 = (x3 >> 8);
1374 const x21 = @truncate(u8, (x20 & @as(u64, 0xff)));1374 const x21 = @as(u8, @truncate((x20 & @as(u64, 0xff))));
1375 const x22 = (x20 >> 8);1375 const x22 = (x20 >> 8);
1376 const x23 = @truncate(u8, (x22 & @as(u64, 0xff)));1376 const x23 = @as(u8, @truncate((x22 & @as(u64, 0xff))));
1377 const x24 = (x22 >> 8);1377 const x24 = (x22 >> 8);
1378 const x25 = @truncate(u8, (x24 & @as(u64, 0xff)));1378 const x25 = @as(u8, @truncate((x24 & @as(u64, 0xff))));
1379 const x26 = (x24 >> 8);1379 const x26 = (x24 >> 8);
1380 const x27 = @truncate(u8, (x26 & @as(u64, 0xff)));1380 const x27 = @as(u8, @truncate((x26 & @as(u64, 0xff))));
1381 const x28 = (x26 >> 8);1381 const x28 = (x26 >> 8);
1382 const x29 = @truncate(u8, (x28 & @as(u64, 0xff)));1382 const x29 = @as(u8, @truncate((x28 & @as(u64, 0xff))));
1383 const x30 = (x28 >> 8);1383 const x30 = (x28 >> 8);
1384 const x31 = @truncate(u8, (x30 & @as(u64, 0xff)));1384 const x31 = @as(u8, @truncate((x30 & @as(u64, 0xff))));
1385 const x32 = @truncate(u8, (x30 >> 8));1385 const x32 = @as(u8, @truncate((x30 >> 8)));
1386 const x33 = @truncate(u8, (x2 & @as(u64, 0xff)));1386 const x33 = @as(u8, @truncate((x2 & @as(u64, 0xff))));
1387 const x34 = (x2 >> 8);1387 const x34 = (x2 >> 8);
1388 const x35 = @truncate(u8, (x34 & @as(u64, 0xff)));1388 const x35 = @as(u8, @truncate((x34 & @as(u64, 0xff))));
1389 const x36 = (x34 >> 8);1389 const x36 = (x34 >> 8);
1390 const x37 = @truncate(u8, (x36 & @as(u64, 0xff)));1390 const x37 = @as(u8, @truncate((x36 & @as(u64, 0xff))));
1391 const x38 = (x36 >> 8);1391 const x38 = (x36 >> 8);
1392 const x39 = @truncate(u8, (x38 & @as(u64, 0xff)));1392 const x39 = @as(u8, @truncate((x38 & @as(u64, 0xff))));
1393 const x40 = (x38 >> 8);1393 const x40 = (x38 >> 8);
1394 const x41 = @truncate(u8, (x40 & @as(u64, 0xff)));1394 const x41 = @as(u8, @truncate((x40 & @as(u64, 0xff))));
1395 const x42 = (x40 >> 8);1395 const x42 = (x40 >> 8);
1396 const x43 = @truncate(u8, (x42 & @as(u64, 0xff)));1396 const x43 = @as(u8, @truncate((x42 & @as(u64, 0xff))));
1397 const x44 = (x42 >> 8);1397 const x44 = (x42 >> 8);
1398 const x45 = @truncate(u8, (x44 & @as(u64, 0xff)));1398 const x45 = @as(u8, @truncate((x44 & @as(u64, 0xff))));
1399 const x46 = @truncate(u8, (x44 >> 8));1399 const x46 = @as(u8, @truncate((x44 >> 8)));
1400 const x47 = @truncate(u8, (x1 & @as(u64, 0xff)));1400 const x47 = @as(u8, @truncate((x1 & @as(u64, 0xff))));
1401 const x48 = (x1 >> 8);1401 const x48 = (x1 >> 8);
1402 const x49 = @truncate(u8, (x48 & @as(u64, 0xff)));1402 const x49 = @as(u8, @truncate((x48 & @as(u64, 0xff))));
1403 const x50 = (x48 >> 8);1403 const x50 = (x48 >> 8);
1404 const x51 = @truncate(u8, (x50 & @as(u64, 0xff)));1404 const x51 = @as(u8, @truncate((x50 & @as(u64, 0xff))));
1405 const x52 = (x50 >> 8);1405 const x52 = (x50 >> 8);
1406 const x53 = @truncate(u8, (x52 & @as(u64, 0xff)));1406 const x53 = @as(u8, @truncate((x52 & @as(u64, 0xff))));
1407 const x54 = (x52 >> 8);1407 const x54 = (x52 >> 8);
1408 const x55 = @truncate(u8, (x54 & @as(u64, 0xff)));1408 const x55 = @as(u8, @truncate((x54 & @as(u64, 0xff))));
1409 const x56 = (x54 >> 8);1409 const x56 = (x54 >> 8);
1410 const x57 = @truncate(u8, (x56 & @as(u64, 0xff)));1410 const x57 = @as(u8, @truncate((x56 & @as(u64, 0xff))));
1411 const x58 = (x56 >> 8);1411 const x58 = (x56 >> 8);
1412 const x59 = @truncate(u8, (x58 & @as(u64, 0xff)));1412 const x59 = @as(u8, @truncate((x58 & @as(u64, 0xff))));
1413 const x60 = @truncate(u8, (x58 >> 8));1413 const x60 = @as(u8, @truncate((x58 >> 8)));
1414 out1[0] = x5;1414 out1[0] = x5;
1415 out1[1] = x7;1415 out1[1] = x7;
1416 out1[2] = x9;1416 out1[2] = x9;
...@@ -1593,7 +1593,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1593,7 +1593,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1593 var x1: u64 = undefined;1593 var x1: u64 = undefined;
1594 var x2: u1 = undefined;1594 var x2: u1 = undefined;
1595 addcarryxU64(&x1, &x2, 0x0, (~arg1), @as(u64, 0x1));1595 addcarryxU64(&x1, &x2, 0x0, (~arg1), @as(u64, 0x1));
1596 const x3 = (@truncate(u1, (x1 >> 63)) & @truncate(u1, ((arg3[0]) & @as(u64, 0x1))));1596 const x3 = (@as(u1, @truncate((x1 >> 63))) & @as(u1, @truncate(((arg3[0]) & @as(u64, 0x1)))));
1597 var x4: u64 = undefined;1597 var x4: u64 = undefined;
1598 var x5: u1 = undefined;1598 var x5: u1 = undefined;
1599 addcarryxU64(&x4, &x5, 0x0, (~arg1), @as(u64, 0x1));1599 addcarryxU64(&x4, &x5, 0x0, (~arg1), @as(u64, 0x1));
...@@ -1707,7 +1707,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1707,7 +1707,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1707 cmovznzU64(&x72, x3, (arg5[2]), x66);1707 cmovznzU64(&x72, x3, (arg5[2]), x66);
1708 var x73: u64 = undefined;1708 var x73: u64 = undefined;
1709 cmovznzU64(&x73, x3, (arg5[3]), x68);1709 cmovznzU64(&x73, x3, (arg5[3]), x68);
1710 const x74 = @truncate(u1, (x22 & @as(u64, 0x1)));1710 const x74 = @as(u1, @truncate((x22 & @as(u64, 0x1))));
1711 var x75: u64 = undefined;1711 var x75: u64 = undefined;
1712 cmovznzU64(&x75, x74, @as(u64, 0x0), x7);1712 cmovznzU64(&x75, x74, @as(u64, 0x0), x7);
1713 var x76: u64 = undefined;1713 var x76: u64 = undefined;
lib/std/crypto/pcurves/p256/p256_scalar_64.zig+36-36
...@@ -119,8 +119,8 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {...@@ -119,8 +119,8 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
119 @setRuntimeSafety(mode == .Debug);119 @setRuntimeSafety(mode == .Debug);
120120
121 const x = @as(u128, arg1) * @as(u128, arg2);121 const x = @as(u128, arg1) * @as(u128, arg2);
122 out1.* = @truncate(u64, x);122 out1.* = @as(u64, @truncate(x));
123 out2.* = @truncate(u64, x >> 64);123 out2.* = @as(u64, @truncate(x >> 64));
124}124}
125125
126/// The function cmovznzU64 is a single-word conditional move.126/// The function cmovznzU64 is a single-word conditional move.
...@@ -1559,62 +1559,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {...@@ -1559,62 +1559,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {
1559 const x2 = (arg1[2]);1559 const x2 = (arg1[2]);
1560 const x3 = (arg1[1]);1560 const x3 = (arg1[1]);
1561 const x4 = (arg1[0]);1561 const x4 = (arg1[0]);
1562 const x5 = @truncate(u8, (x4 & @as(u64, 0xff)));1562 const x5 = @as(u8, @truncate((x4 & @as(u64, 0xff))));
1563 const x6 = (x4 >> 8);1563 const x6 = (x4 >> 8);
1564 const x7 = @truncate(u8, (x6 & @as(u64, 0xff)));1564 const x7 = @as(u8, @truncate((x6 & @as(u64, 0xff))));
1565 const x8 = (x6 >> 8);1565 const x8 = (x6 >> 8);
1566 const x9 = @truncate(u8, (x8 & @as(u64, 0xff)));1566 const x9 = @as(u8, @truncate((x8 & @as(u64, 0xff))));
1567 const x10 = (x8 >> 8);1567 const x10 = (x8 >> 8);
1568 const x11 = @truncate(u8, (x10 & @as(u64, 0xff)));1568 const x11 = @as(u8, @truncate((x10 & @as(u64, 0xff))));
1569 const x12 = (x10 >> 8);1569 const x12 = (x10 >> 8);
1570 const x13 = @truncate(u8, (x12 & @as(u64, 0xff)));1570 const x13 = @as(u8, @truncate((x12 & @as(u64, 0xff))));
1571 const x14 = (x12 >> 8);1571 const x14 = (x12 >> 8);
1572 const x15 = @truncate(u8, (x14 & @as(u64, 0xff)));1572 const x15 = @as(u8, @truncate((x14 & @as(u64, 0xff))));
1573 const x16 = (x14 >> 8);1573 const x16 = (x14 >> 8);
1574 const x17 = @truncate(u8, (x16 & @as(u64, 0xff)));1574 const x17 = @as(u8, @truncate((x16 & @as(u64, 0xff))));
1575 const x18 = @truncate(u8, (x16 >> 8));1575 const x18 = @as(u8, @truncate((x16 >> 8)));
1576 const x19 = @truncate(u8, (x3 & @as(u64, 0xff)));1576 const x19 = @as(u8, @truncate((x3 & @as(u64, 0xff))));
1577 const x20 = (x3 >> 8);1577 const x20 = (x3 >> 8);
1578 const x21 = @truncate(u8, (x20 & @as(u64, 0xff)));1578 const x21 = @as(u8, @truncate((x20 & @as(u64, 0xff))));
1579 const x22 = (x20 >> 8);1579 const x22 = (x20 >> 8);
1580 const x23 = @truncate(u8, (x22 & @as(u64, 0xff)));1580 const x23 = @as(u8, @truncate((x22 & @as(u64, 0xff))));
1581 const x24 = (x22 >> 8);1581 const x24 = (x22 >> 8);
1582 const x25 = @truncate(u8, (x24 & @as(u64, 0xff)));1582 const x25 = @as(u8, @truncate((x24 & @as(u64, 0xff))));
1583 const x26 = (x24 >> 8);1583 const x26 = (x24 >> 8);
1584 const x27 = @truncate(u8, (x26 & @as(u64, 0xff)));1584 const x27 = @as(u8, @truncate((x26 & @as(u64, 0xff))));
1585 const x28 = (x26 >> 8);1585 const x28 = (x26 >> 8);
1586 const x29 = @truncate(u8, (x28 & @as(u64, 0xff)));1586 const x29 = @as(u8, @truncate((x28 & @as(u64, 0xff))));
1587 const x30 = (x28 >> 8);1587 const x30 = (x28 >> 8);
1588 const x31 = @truncate(u8, (x30 & @as(u64, 0xff)));1588 const x31 = @as(u8, @truncate((x30 & @as(u64, 0xff))));
1589 const x32 = @truncate(u8, (x30 >> 8));1589 const x32 = @as(u8, @truncate((x30 >> 8)));
1590 const x33 = @truncate(u8, (x2 & @as(u64, 0xff)));1590 const x33 = @as(u8, @truncate((x2 & @as(u64, 0xff))));
1591 const x34 = (x2 >> 8);1591 const x34 = (x2 >> 8);
1592 const x35 = @truncate(u8, (x34 & @as(u64, 0xff)));1592 const x35 = @as(u8, @truncate((x34 & @as(u64, 0xff))));
1593 const x36 = (x34 >> 8);1593 const x36 = (x34 >> 8);
1594 const x37 = @truncate(u8, (x36 & @as(u64, 0xff)));1594 const x37 = @as(u8, @truncate((x36 & @as(u64, 0xff))));
1595 const x38 = (x36 >> 8);1595 const x38 = (x36 >> 8);
1596 const x39 = @truncate(u8, (x38 & @as(u64, 0xff)));1596 const x39 = @as(u8, @truncate((x38 & @as(u64, 0xff))));
1597 const x40 = (x38 >> 8);1597 const x40 = (x38 >> 8);
1598 const x41 = @truncate(u8, (x40 & @as(u64, 0xff)));1598 const x41 = @as(u8, @truncate((x40 & @as(u64, 0xff))));
1599 const x42 = (x40 >> 8);1599 const x42 = (x40 >> 8);
1600 const x43 = @truncate(u8, (x42 & @as(u64, 0xff)));1600 const x43 = @as(u8, @truncate((x42 & @as(u64, 0xff))));
1601 const x44 = (x42 >> 8);1601 const x44 = (x42 >> 8);
1602 const x45 = @truncate(u8, (x44 & @as(u64, 0xff)));1602 const x45 = @as(u8, @truncate((x44 & @as(u64, 0xff))));
1603 const x46 = @truncate(u8, (x44 >> 8));1603 const x46 = @as(u8, @truncate((x44 >> 8)));
1604 const x47 = @truncate(u8, (x1 & @as(u64, 0xff)));1604 const x47 = @as(u8, @truncate((x1 & @as(u64, 0xff))));
1605 const x48 = (x1 >> 8);1605 const x48 = (x1 >> 8);
1606 const x49 = @truncate(u8, (x48 & @as(u64, 0xff)));1606 const x49 = @as(u8, @truncate((x48 & @as(u64, 0xff))));
1607 const x50 = (x48 >> 8);1607 const x50 = (x48 >> 8);
1608 const x51 = @truncate(u8, (x50 & @as(u64, 0xff)));1608 const x51 = @as(u8, @truncate((x50 & @as(u64, 0xff))));
1609 const x52 = (x50 >> 8);1609 const x52 = (x50 >> 8);
1610 const x53 = @truncate(u8, (x52 & @as(u64, 0xff)));1610 const x53 = @as(u8, @truncate((x52 & @as(u64, 0xff))));
1611 const x54 = (x52 >> 8);1611 const x54 = (x52 >> 8);
1612 const x55 = @truncate(u8, (x54 & @as(u64, 0xff)));1612 const x55 = @as(u8, @truncate((x54 & @as(u64, 0xff))));
1613 const x56 = (x54 >> 8);1613 const x56 = (x54 >> 8);
1614 const x57 = @truncate(u8, (x56 & @as(u64, 0xff)));1614 const x57 = @as(u8, @truncate((x56 & @as(u64, 0xff))));
1615 const x58 = (x56 >> 8);1615 const x58 = (x56 >> 8);
1616 const x59 = @truncate(u8, (x58 & @as(u64, 0xff)));1616 const x59 = @as(u8, @truncate((x58 & @as(u64, 0xff))));
1617 const x60 = @truncate(u8, (x58 >> 8));1617 const x60 = @as(u8, @truncate((x58 >> 8)));
1618 out1[0] = x5;1618 out1[0] = x5;
1619 out1[1] = x7;1619 out1[1] = x7;
1620 out1[2] = x9;1620 out1[2] = x9;
...@@ -1797,7 +1797,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1797,7 +1797,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1797 var x1: u64 = undefined;1797 var x1: u64 = undefined;
1798 var x2: u1 = undefined;1798 var x2: u1 = undefined;
1799 addcarryxU64(&x1, &x2, 0x0, (~arg1), @as(u64, 0x1));1799 addcarryxU64(&x1, &x2, 0x0, (~arg1), @as(u64, 0x1));
1800 const x3 = @truncate(u1, (x1 >> 63)) & @truncate(u1, ((arg3[0]) & @as(u64, 0x1)));1800 const x3 = @as(u1, @truncate((x1 >> 63))) & @as(u1, @truncate(((arg3[0]) & @as(u64, 0x1))));
1801 var x4: u64 = undefined;1801 var x4: u64 = undefined;
1802 var x5: u1 = undefined;1802 var x5: u1 = undefined;
1803 addcarryxU64(&x4, &x5, 0x0, (~arg1), @as(u64, 0x1));1803 addcarryxU64(&x4, &x5, 0x0, (~arg1), @as(u64, 0x1));
...@@ -1911,7 +1911,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1911,7 +1911,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1911 cmovznzU64(&x72, x3, (arg5[2]), x66);1911 cmovznzU64(&x72, x3, (arg5[2]), x66);
1912 var x73: u64 = undefined;1912 var x73: u64 = undefined;
1913 cmovznzU64(&x73, x3, (arg5[3]), x68);1913 cmovznzU64(&x73, x3, (arg5[3]), x68);
1914 const x74 = @truncate(u1, (x22 & @as(u64, 0x1)));1914 const x74 = @as(u1, @truncate((x22 & @as(u64, 0x1))));
1915 var x75: u64 = undefined;1915 var x75: u64 = undefined;
1916 cmovznzU64(&x75, x74, @as(u64, 0x0), x7);1916 cmovznzU64(&x75, x74, @as(u64, 0x0), x7);
1917 var x76: u64 = undefined;1917 var x76: u64 = undefined;
lib/std/crypto/pcurves/p384.zig+10-10
...@@ -318,7 +318,7 @@ pub const P384 = struct {...@@ -318,7 +318,7 @@ pub const P384 = struct {
318 var t = P384.identityElement;318 var t = P384.identityElement;
319 comptime var i: u8 = 1;319 comptime var i: u8 = 1;
320 inline while (i < pc.len) : (i += 1) {320 inline while (i < pc.len) : (i += 1) {
321 t.cMov(pc[i], @truncate(u1, (@as(usize, b ^ i) -% 1) >> 8));321 t.cMov(pc[i], @as(u1, @truncate((@as(usize, b ^ i) -% 1) >> 8)));
322 }322 }
323 return t;323 return t;
324 }324 }
...@@ -326,8 +326,8 @@ pub const P384 = struct {...@@ -326,8 +326,8 @@ pub const P384 = struct {
326 fn slide(s: [48]u8) [2 * 48 + 1]i8 {326 fn slide(s: [48]u8) [2 * 48 + 1]i8 {
327 var e: [2 * 48 + 1]i8 = undefined;327 var e: [2 * 48 + 1]i8 = undefined;
328 for (s, 0..) |x, i| {328 for (s, 0..) |x, i| {
329 e[i * 2 + 0] = @as(i8, @truncate(u4, x));329 e[i * 2 + 0] = @as(i8, @as(u4, @truncate(x)));
330 e[i * 2 + 1] = @as(i8, @truncate(u4, x >> 4));330 e[i * 2 + 1] = @as(i8, @as(u4, @truncate(x >> 4)));
331 }331 }
332 // Now, e[0..63] is between 0 and 15, e[63] is between 0 and 7332 // Now, e[0..63] is between 0 and 15, e[63] is between 0 and 7
333 var carry: i8 = 0;333 var carry: i8 = 0;
...@@ -351,9 +351,9 @@ pub const P384 = struct {...@@ -351,9 +351,9 @@ pub const P384 = struct {
351 while (true) : (pos -= 1) {351 while (true) : (pos -= 1) {
352 const slot = e[pos];352 const slot = e[pos];
353 if (slot > 0) {353 if (slot > 0) {
354 q = q.add(pc[@intCast(usize, slot)]);354 q = q.add(pc[@as(usize, @intCast(slot))]);
355 } else if (slot < 0) {355 } else if (slot < 0) {
356 q = q.sub(pc[@intCast(usize, -slot)]);356 q = q.sub(pc[@as(usize, @intCast(-slot))]);
357 }357 }
358 if (pos == 0) break;358 if (pos == 0) break;
359 q = q.dbl().dbl().dbl().dbl();359 q = q.dbl().dbl().dbl().dbl();
...@@ -366,7 +366,7 @@ pub const P384 = struct {...@@ -366,7 +366,7 @@ pub const P384 = struct {
366 var q = P384.identityElement;366 var q = P384.identityElement;
367 var pos: usize = 380;367 var pos: usize = 380;
368 while (true) : (pos -= 4) {368 while (true) : (pos -= 4) {
369 const slot = @truncate(u4, (s[pos >> 3] >> @truncate(u3, pos)));369 const slot = @as(u4, @truncate((s[pos >> 3] >> @as(u3, @truncate(pos)))));
370 if (vartime) {370 if (vartime) {
371 if (slot != 0) {371 if (slot != 0) {
372 q = q.add(pc[slot]);372 q = q.add(pc[slot]);
...@@ -445,15 +445,15 @@ pub const P384 = struct {...@@ -445,15 +445,15 @@ pub const P384 = struct {
445 while (true) : (pos -= 1) {445 while (true) : (pos -= 1) {
446 const slot1 = e1[pos];446 const slot1 = e1[pos];
447 if (slot1 > 0) {447 if (slot1 > 0) {
448 q = q.add(pc1[@intCast(usize, slot1)]);448 q = q.add(pc1[@as(usize, @intCast(slot1))]);
449 } else if (slot1 < 0) {449 } else if (slot1 < 0) {
450 q = q.sub(pc1[@intCast(usize, -slot1)]);450 q = q.sub(pc1[@as(usize, @intCast(-slot1))]);
451 }451 }
452 const slot2 = e2[pos];452 const slot2 = e2[pos];
453 if (slot2 > 0) {453 if (slot2 > 0) {
454 q = q.add(pc2[@intCast(usize, slot2)]);454 q = q.add(pc2[@as(usize, @intCast(slot2))]);
455 } else if (slot2 < 0) {455 } else if (slot2 < 0) {
456 q = q.sub(pc2[@intCast(usize, -slot2)]);456 q = q.sub(pc2[@as(usize, @intCast(-slot2))]);
457 }457 }
458 if (pos == 0) break;458 if (pos == 0) break;
459 q = q.dbl().dbl().dbl().dbl();459 q = q.dbl().dbl().dbl().dbl();
lib/std/crypto/pcurves/p384/p384_64.zig+52-52
...@@ -88,8 +88,8 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {...@@ -88,8 +88,8 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
88 @setRuntimeSafety(mode == .Debug);88 @setRuntimeSafety(mode == .Debug);
8989
90 const x = @as(u128, arg1) * @as(u128, arg2);90 const x = @as(u128, arg1) * @as(u128, arg2);
91 out1.* = @truncate(u64, x);91 out1.* = @as(u64, @truncate(x));
92 out2.* = @truncate(u64, x >> 64);92 out2.* = @as(u64, @truncate(x >> 64));
93}93}
9494
95/// The function cmovznzU64 is a single-word conditional move.95/// The function cmovznzU64 is a single-word conditional move.
...@@ -2928,90 +2928,90 @@ pub fn toBytes(out1: *[48]u8, arg1: [6]u64) void {...@@ -2928,90 +2928,90 @@ pub fn toBytes(out1: *[48]u8, arg1: [6]u64) void {
2928 const x4 = (arg1[2]);2928 const x4 = (arg1[2]);
2929 const x5 = (arg1[1]);2929 const x5 = (arg1[1]);
2930 const x6 = (arg1[0]);2930 const x6 = (arg1[0]);
2931 const x7 = @truncate(u8, (x6 & 0xff));2931 const x7 = @as(u8, @truncate((x6 & 0xff)));
2932 const x8 = (x6 >> 8);2932 const x8 = (x6 >> 8);
2933 const x9 = @truncate(u8, (x8 & 0xff));2933 const x9 = @as(u8, @truncate((x8 & 0xff)));
2934 const x10 = (x8 >> 8);2934 const x10 = (x8 >> 8);
2935 const x11 = @truncate(u8, (x10 & 0xff));2935 const x11 = @as(u8, @truncate((x10 & 0xff)));
2936 const x12 = (x10 >> 8);2936 const x12 = (x10 >> 8);
2937 const x13 = @truncate(u8, (x12 & 0xff));2937 const x13 = @as(u8, @truncate((x12 & 0xff)));
2938 const x14 = (x12 >> 8);2938 const x14 = (x12 >> 8);
2939 const x15 = @truncate(u8, (x14 & 0xff));2939 const x15 = @as(u8, @truncate((x14 & 0xff)));
2940 const x16 = (x14 >> 8);2940 const x16 = (x14 >> 8);
2941 const x17 = @truncate(u8, (x16 & 0xff));2941 const x17 = @as(u8, @truncate((x16 & 0xff)));
2942 const x18 = (x16 >> 8);2942 const x18 = (x16 >> 8);
2943 const x19 = @truncate(u8, (x18 & 0xff));2943 const x19 = @as(u8, @truncate((x18 & 0xff)));
2944 const x20 = @truncate(u8, (x18 >> 8));2944 const x20 = @as(u8, @truncate((x18 >> 8)));
2945 const x21 = @truncate(u8, (x5 & 0xff));2945 const x21 = @as(u8, @truncate((x5 & 0xff)));
2946 const x22 = (x5 >> 8);2946 const x22 = (x5 >> 8);
2947 const x23 = @truncate(u8, (x22 & 0xff));2947 const x23 = @as(u8, @truncate((x22 & 0xff)));
2948 const x24 = (x22 >> 8);2948 const x24 = (x22 >> 8);
2949 const x25 = @truncate(u8, (x24 & 0xff));2949 const x25 = @as(u8, @truncate((x24 & 0xff)));
2950 const x26 = (x24 >> 8);2950 const x26 = (x24 >> 8);
2951 const x27 = @truncate(u8, (x26 & 0xff));2951 const x27 = @as(u8, @truncate((x26 & 0xff)));
2952 const x28 = (x26 >> 8);2952 const x28 = (x26 >> 8);
2953 const x29 = @truncate(u8, (x28 & 0xff));2953 const x29 = @as(u8, @truncate((x28 & 0xff)));
2954 const x30 = (x28 >> 8);2954 const x30 = (x28 >> 8);
2955 const x31 = @truncate(u8, (x30 & 0xff));2955 const x31 = @as(u8, @truncate((x30 & 0xff)));
2956 const x32 = (x30 >> 8);2956 const x32 = (x30 >> 8);
2957 const x33 = @truncate(u8, (x32 & 0xff));2957 const x33 = @as(u8, @truncate((x32 & 0xff)));
2958 const x34 = @truncate(u8, (x32 >> 8));2958 const x34 = @as(u8, @truncate((x32 >> 8)));
2959 const x35 = @truncate(u8, (x4 & 0xff));2959 const x35 = @as(u8, @truncate((x4 & 0xff)));
2960 const x36 = (x4 >> 8);2960 const x36 = (x4 >> 8);
2961 const x37 = @truncate(u8, (x36 & 0xff));2961 const x37 = @as(u8, @truncate((x36 & 0xff)));
2962 const x38 = (x36 >> 8);2962 const x38 = (x36 >> 8);
2963 const x39 = @truncate(u8, (x38 & 0xff));2963 const x39 = @as(u8, @truncate((x38 & 0xff)));
2964 const x40 = (x38 >> 8);2964 const x40 = (x38 >> 8);
2965 const x41 = @truncate(u8, (x40 & 0xff));2965 const x41 = @as(u8, @truncate((x40 & 0xff)));
2966 const x42 = (x40 >> 8);2966 const x42 = (x40 >> 8);
2967 const x43 = @truncate(u8, (x42 & 0xff));2967 const x43 = @as(u8, @truncate((x42 & 0xff)));
2968 const x44 = (x42 >> 8);2968 const x44 = (x42 >> 8);
2969 const x45 = @truncate(u8, (x44 & 0xff));2969 const x45 = @as(u8, @truncate((x44 & 0xff)));
2970 const x46 = (x44 >> 8);2970 const x46 = (x44 >> 8);
2971 const x47 = @truncate(u8, (x46 & 0xff));2971 const x47 = @as(u8, @truncate((x46 & 0xff)));
2972 const x48 = @truncate(u8, (x46 >> 8));2972 const x48 = @as(u8, @truncate((x46 >> 8)));
2973 const x49 = @truncate(u8, (x3 & 0xff));2973 const x49 = @as(u8, @truncate((x3 & 0xff)));
2974 const x50 = (x3 >> 8);2974 const x50 = (x3 >> 8);
2975 const x51 = @truncate(u8, (x50 & 0xff));2975 const x51 = @as(u8, @truncate((x50 & 0xff)));
2976 const x52 = (x50 >> 8);2976 const x52 = (x50 >> 8);
2977 const x53 = @truncate(u8, (x52 & 0xff));2977 const x53 = @as(u8, @truncate((x52 & 0xff)));
2978 const x54 = (x52 >> 8);2978 const x54 = (x52 >> 8);
2979 const x55 = @truncate(u8, (x54 & 0xff));2979 const x55 = @as(u8, @truncate((x54 & 0xff)));
2980 const x56 = (x54 >> 8);2980 const x56 = (x54 >> 8);
2981 const x57 = @truncate(u8, (x56 & 0xff));2981 const x57 = @as(u8, @truncate((x56 & 0xff)));
2982 const x58 = (x56 >> 8);2982 const x58 = (x56 >> 8);
2983 const x59 = @truncate(u8, (x58 & 0xff));2983 const x59 = @as(u8, @truncate((x58 & 0xff)));
2984 const x60 = (x58 >> 8);2984 const x60 = (x58 >> 8);
2985 const x61 = @truncate(u8, (x60 & 0xff));2985 const x61 = @as(u8, @truncate((x60 & 0xff)));
2986 const x62 = @truncate(u8, (x60 >> 8));2986 const x62 = @as(u8, @truncate((x60 >> 8)));
2987 const x63 = @truncate(u8, (x2 & 0xff));2987 const x63 = @as(u8, @truncate((x2 & 0xff)));
2988 const x64 = (x2 >> 8);2988 const x64 = (x2 >> 8);
2989 const x65 = @truncate(u8, (x64 & 0xff));2989 const x65 = @as(u8, @truncate((x64 & 0xff)));
2990 const x66 = (x64 >> 8);2990 const x66 = (x64 >> 8);
2991 const x67 = @truncate(u8, (x66 & 0xff));2991 const x67 = @as(u8, @truncate((x66 & 0xff)));
2992 const x68 = (x66 >> 8);2992 const x68 = (x66 >> 8);
2993 const x69 = @truncate(u8, (x68 & 0xff));2993 const x69 = @as(u8, @truncate((x68 & 0xff)));
2994 const x70 = (x68 >> 8);2994 const x70 = (x68 >> 8);
2995 const x71 = @truncate(u8, (x70 & 0xff));2995 const x71 = @as(u8, @truncate((x70 & 0xff)));
2996 const x72 = (x70 >> 8);2996 const x72 = (x70 >> 8);
2997 const x73 = @truncate(u8, (x72 & 0xff));2997 const x73 = @as(u8, @truncate((x72 & 0xff)));
2998 const x74 = (x72 >> 8);2998 const x74 = (x72 >> 8);
2999 const x75 = @truncate(u8, (x74 & 0xff));2999 const x75 = @as(u8, @truncate((x74 & 0xff)));
3000 const x76 = @truncate(u8, (x74 >> 8));3000 const x76 = @as(u8, @truncate((x74 >> 8)));
3001 const x77 = @truncate(u8, (x1 & 0xff));3001 const x77 = @as(u8, @truncate((x1 & 0xff)));
3002 const x78 = (x1 >> 8);3002 const x78 = (x1 >> 8);
3003 const x79 = @truncate(u8, (x78 & 0xff));3003 const x79 = @as(u8, @truncate((x78 & 0xff)));
3004 const x80 = (x78 >> 8);3004 const x80 = (x78 >> 8);
3005 const x81 = @truncate(u8, (x80 & 0xff));3005 const x81 = @as(u8, @truncate((x80 & 0xff)));
3006 const x82 = (x80 >> 8);3006 const x82 = (x80 >> 8);
3007 const x83 = @truncate(u8, (x82 & 0xff));3007 const x83 = @as(u8, @truncate((x82 & 0xff)));
3008 const x84 = (x82 >> 8);3008 const x84 = (x82 >> 8);
3009 const x85 = @truncate(u8, (x84 & 0xff));3009 const x85 = @as(u8, @truncate((x84 & 0xff)));
3010 const x86 = (x84 >> 8);3010 const x86 = (x84 >> 8);
3011 const x87 = @truncate(u8, (x86 & 0xff));3011 const x87 = @as(u8, @truncate((x86 & 0xff)));
3012 const x88 = (x86 >> 8);3012 const x88 = (x86 >> 8);
3013 const x89 = @truncate(u8, (x88 & 0xff));3013 const x89 = @as(u8, @truncate((x88 & 0xff)));
3014 const x90 = @truncate(u8, (x88 >> 8));3014 const x90 = @as(u8, @truncate((x88 >> 8)));
3015 out1[0] = x7;3015 out1[0] = x7;
3016 out1[1] = x9;3016 out1[1] = x9;
3017 out1[2] = x11;3017 out1[2] = x11;
...@@ -3246,7 +3246,7 @@ pub fn divstep(out1: *u64, out2: *[7]u64, out3: *[7]u64, out4: *[6]u64, out5: *[...@@ -3246,7 +3246,7 @@ pub fn divstep(out1: *u64, out2: *[7]u64, out3: *[7]u64, out4: *[6]u64, out5: *[
3246 var x1: u64 = undefined;3246 var x1: u64 = undefined;
3247 var x2: u1 = undefined;3247 var x2: u1 = undefined;
3248 addcarryxU64(&x1, &x2, 0x0, (~arg1), 0x1);3248 addcarryxU64(&x1, &x2, 0x0, (~arg1), 0x1);
3249 const x3 = (@truncate(u1, (x1 >> 63)) & @truncate(u1, ((arg3[0]) & 0x1)));3249 const x3 = (@as(u1, @truncate((x1 >> 63))) & @as(u1, @truncate(((arg3[0]) & 0x1))));
3250 var x4: u64 = undefined;3250 var x4: u64 = undefined;
3251 var x5: u1 = undefined;3251 var x5: u1 = undefined;
3252 addcarryxU64(&x4, &x5, 0x0, (~arg1), 0x1);3252 addcarryxU64(&x4, &x5, 0x0, (~arg1), 0x1);
...@@ -3408,7 +3408,7 @@ pub fn divstep(out1: *u64, out2: *[7]u64, out3: *[7]u64, out4: *[6]u64, out5: *[...@@ -3408,7 +3408,7 @@ pub fn divstep(out1: *u64, out2: *[7]u64, out3: *[7]u64, out4: *[6]u64, out5: *[
3408 cmovznzU64(&x102, x3, (arg5[4]), x94);3408 cmovznzU64(&x102, x3, (arg5[4]), x94);
3409 var x103: u64 = undefined;3409 var x103: u64 = undefined;
3410 cmovznzU64(&x103, x3, (arg5[5]), x96);3410 cmovznzU64(&x103, x3, (arg5[5]), x96);
3411 const x104 = @truncate(u1, (x28 & 0x1));3411 const x104 = @as(u1, @truncate((x28 & 0x1)));
3412 var x105: u64 = undefined;3412 var x105: u64 = undefined;
3413 cmovznzU64(&x105, x104, 0x0, x7);3413 cmovznzU64(&x105, x104, 0x0, x7);
3414 var x106: u64 = undefined;3414 var x106: u64 = undefined;
lib/std/crypto/pcurves/p384/p384_scalar_64.zig+52-52
...@@ -88,8 +88,8 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {...@@ -88,8 +88,8 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
88 @setRuntimeSafety(mode == .Debug);88 @setRuntimeSafety(mode == .Debug);
8989
90 const x = @as(u128, arg1) * @as(u128, arg2);90 const x = @as(u128, arg1) * @as(u128, arg2);
91 out1.* = @truncate(u64, x);91 out1.* = @as(u64, @truncate(x));
92 out2.* = @truncate(u64, x >> 64);92 out2.* = @as(u64, @truncate(x >> 64));
93}93}
9494
95/// The function cmovznzU64 is a single-word conditional move.95/// The function cmovznzU64 is a single-word conditional move.
...@@ -2982,90 +2982,90 @@ pub fn toBytes(out1: *[48]u8, arg1: [6]u64) void {...@@ -2982,90 +2982,90 @@ pub fn toBytes(out1: *[48]u8, arg1: [6]u64) void {
2982 const x4 = (arg1[2]);2982 const x4 = (arg1[2]);
2983 const x5 = (arg1[1]);2983 const x5 = (arg1[1]);
2984 const x6 = (arg1[0]);2984 const x6 = (arg1[0]);
2985 const x7 = @truncate(u8, (x6 & 0xff));2985 const x7 = @as(u8, @truncate((x6 & 0xff)));
2986 const x8 = (x6 >> 8);2986 const x8 = (x6 >> 8);
2987 const x9 = @truncate(u8, (x8 & 0xff));2987 const x9 = @as(u8, @truncate((x8 & 0xff)));
2988 const x10 = (x8 >> 8);2988 const x10 = (x8 >> 8);
2989 const x11 = @truncate(u8, (x10 & 0xff));2989 const x11 = @as(u8, @truncate((x10 & 0xff)));
2990 const x12 = (x10 >> 8);2990 const x12 = (x10 >> 8);
2991 const x13 = @truncate(u8, (x12 & 0xff));2991 const x13 = @as(u8, @truncate((x12 & 0xff)));
2992 const x14 = (x12 >> 8);2992 const x14 = (x12 >> 8);
2993 const x15 = @truncate(u8, (x14 & 0xff));2993 const x15 = @as(u8, @truncate((x14 & 0xff)));
2994 const x16 = (x14 >> 8);2994 const x16 = (x14 >> 8);
2995 const x17 = @truncate(u8, (x16 & 0xff));2995 const x17 = @as(u8, @truncate((x16 & 0xff)));
2996 const x18 = (x16 >> 8);2996 const x18 = (x16 >> 8);
2997 const x19 = @truncate(u8, (x18 & 0xff));2997 const x19 = @as(u8, @truncate((x18 & 0xff)));
2998 const x20 = @truncate(u8, (x18 >> 8));2998 const x20 = @as(u8, @truncate((x18 >> 8)));
2999 const x21 = @truncate(u8, (x5 & 0xff));2999 const x21 = @as(u8, @truncate((x5 & 0xff)));
3000 const x22 = (x5 >> 8);3000 const x22 = (x5 >> 8);
3001 const x23 = @truncate(u8, (x22 & 0xff));3001 const x23 = @as(u8, @truncate((x22 & 0xff)));
3002 const x24 = (x22 >> 8);3002 const x24 = (x22 >> 8);
3003 const x25 = @truncate(u8, (x24 & 0xff));3003 const x25 = @as(u8, @truncate((x24 & 0xff)));
3004 const x26 = (x24 >> 8);3004 const x26 = (x24 >> 8);
3005 const x27 = @truncate(u8, (x26 & 0xff));3005 const x27 = @as(u8, @truncate((x26 & 0xff)));
3006 const x28 = (x26 >> 8);3006 const x28 = (x26 >> 8);
3007 const x29 = @truncate(u8, (x28 & 0xff));3007 const x29 = @as(u8, @truncate((x28 & 0xff)));
3008 const x30 = (x28 >> 8);3008 const x30 = (x28 >> 8);
3009 const x31 = @truncate(u8, (x30 & 0xff));3009 const x31 = @as(u8, @truncate((x30 & 0xff)));
3010 const x32 = (x30 >> 8);3010 const x32 = (x30 >> 8);
3011 const x33 = @truncate(u8, (x32 & 0xff));3011 const x33 = @as(u8, @truncate((x32 & 0xff)));
3012 const x34 = @truncate(u8, (x32 >> 8));3012 const x34 = @as(u8, @truncate((x32 >> 8)));
3013 const x35 = @truncate(u8, (x4 & 0xff));3013 const x35 = @as(u8, @truncate((x4 & 0xff)));
3014 const x36 = (x4 >> 8);3014 const x36 = (x4 >> 8);
3015 const x37 = @truncate(u8, (x36 & 0xff));3015 const x37 = @as(u8, @truncate((x36 & 0xff)));
3016 const x38 = (x36 >> 8);3016 const x38 = (x36 >> 8);
3017 const x39 = @truncate(u8, (x38 & 0xff));3017 const x39 = @as(u8, @truncate((x38 & 0xff)));
3018 const x40 = (x38 >> 8);3018 const x40 = (x38 >> 8);
3019 const x41 = @truncate(u8, (x40 & 0xff));3019 const x41 = @as(u8, @truncate((x40 & 0xff)));
3020 const x42 = (x40 >> 8);3020 const x42 = (x40 >> 8);
3021 const x43 = @truncate(u8, (x42 & 0xff));3021 const x43 = @as(u8, @truncate((x42 & 0xff)));
3022 const x44 = (x42 >> 8);3022 const x44 = (x42 >> 8);
3023 const x45 = @truncate(u8, (x44 & 0xff));3023 const x45 = @as(u8, @truncate((x44 & 0xff)));
3024 const x46 = (x44 >> 8);3024 const x46 = (x44 >> 8);
3025 const x47 = @truncate(u8, (x46 & 0xff));3025 const x47 = @as(u8, @truncate((x46 & 0xff)));
3026 const x48 = @truncate(u8, (x46 >> 8));3026 const x48 = @as(u8, @truncate((x46 >> 8)));
3027 const x49 = @truncate(u8, (x3 & 0xff));3027 const x49 = @as(u8, @truncate((x3 & 0xff)));
3028 const x50 = (x3 >> 8);3028 const x50 = (x3 >> 8);
3029 const x51 = @truncate(u8, (x50 & 0xff));3029 const x51 = @as(u8, @truncate((x50 & 0xff)));
3030 const x52 = (x50 >> 8);3030 const x52 = (x50 >> 8);
3031 const x53 = @truncate(u8, (x52 & 0xff));3031 const x53 = @as(u8, @truncate((x52 & 0xff)));
3032 const x54 = (x52 >> 8);3032 const x54 = (x52 >> 8);
3033 const x55 = @truncate(u8, (x54 & 0xff));3033 const x55 = @as(u8, @truncate((x54 & 0xff)));
3034 const x56 = (x54 >> 8);3034 const x56 = (x54 >> 8);
3035 const x57 = @truncate(u8, (x56 & 0xff));3035 const x57 = @as(u8, @truncate((x56 & 0xff)));
3036 const x58 = (x56 >> 8);3036 const x58 = (x56 >> 8);
3037 const x59 = @truncate(u8, (x58 & 0xff));3037 const x59 = @as(u8, @truncate((x58 & 0xff)));
3038 const x60 = (x58 >> 8);3038 const x60 = (x58 >> 8);
3039 const x61 = @truncate(u8, (x60 & 0xff));3039 const x61 = @as(u8, @truncate((x60 & 0xff)));
3040 const x62 = @truncate(u8, (x60 >> 8));3040 const x62 = @as(u8, @truncate((x60 >> 8)));
3041 const x63 = @truncate(u8, (x2 & 0xff));3041 const x63 = @as(u8, @truncate((x2 & 0xff)));
3042 const x64 = (x2 >> 8);3042 const x64 = (x2 >> 8);
3043 const x65 = @truncate(u8, (x64 & 0xff));3043 const x65 = @as(u8, @truncate((x64 & 0xff)));
3044 const x66 = (x64 >> 8);3044 const x66 = (x64 >> 8);
3045 const x67 = @truncate(u8, (x66 & 0xff));3045 const x67 = @as(u8, @truncate((x66 & 0xff)));
3046 const x68 = (x66 >> 8);3046 const x68 = (x66 >> 8);
3047 const x69 = @truncate(u8, (x68 & 0xff));3047 const x69 = @as(u8, @truncate((x68 & 0xff)));
3048 const x70 = (x68 >> 8);3048 const x70 = (x68 >> 8);
3049 const x71 = @truncate(u8, (x70 & 0xff));3049 const x71 = @as(u8, @truncate((x70 & 0xff)));
3050 const x72 = (x70 >> 8);3050 const x72 = (x70 >> 8);
3051 const x73 = @truncate(u8, (x72 & 0xff));3051 const x73 = @as(u8, @truncate((x72 & 0xff)));
3052 const x74 = (x72 >> 8);3052 const x74 = (x72 >> 8);
3053 const x75 = @truncate(u8, (x74 & 0xff));3053 const x75 = @as(u8, @truncate((x74 & 0xff)));
3054 const x76 = @truncate(u8, (x74 >> 8));3054 const x76 = @as(u8, @truncate((x74 >> 8)));
3055 const x77 = @truncate(u8, (x1 & 0xff));3055 const x77 = @as(u8, @truncate((x1 & 0xff)));
3056 const x78 = (x1 >> 8);3056 const x78 = (x1 >> 8);
3057 const x79 = @truncate(u8, (x78 & 0xff));3057 const x79 = @as(u8, @truncate((x78 & 0xff)));
3058 const x80 = (x78 >> 8);3058 const x80 = (x78 >> 8);
3059 const x81 = @truncate(u8, (x80 & 0xff));3059 const x81 = @as(u8, @truncate((x80 & 0xff)));
3060 const x82 = (x80 >> 8);3060 const x82 = (x80 >> 8);
3061 const x83 = @truncate(u8, (x82 & 0xff));3061 const x83 = @as(u8, @truncate((x82 & 0xff)));
3062 const x84 = (x82 >> 8);3062 const x84 = (x82 >> 8);
3063 const x85 = @truncate(u8, (x84 & 0xff));3063 const x85 = @as(u8, @truncate((x84 & 0xff)));
3064 const x86 = (x84 >> 8);3064 const x86 = (x84 >> 8);
3065 const x87 = @truncate(u8, (x86 & 0xff));3065 const x87 = @as(u8, @truncate((x86 & 0xff)));
3066 const x88 = (x86 >> 8);3066 const x88 = (x86 >> 8);
3067 const x89 = @truncate(u8, (x88 & 0xff));3067 const x89 = @as(u8, @truncate((x88 & 0xff)));
3068 const x90 = @truncate(u8, (x88 >> 8));3068 const x90 = @as(u8, @truncate((x88 >> 8)));
3069 out1[0] = x7;3069 out1[0] = x7;
3070 out1[1] = x9;3070 out1[1] = x9;
3071 out1[2] = x11;3071 out1[2] = x11;
...@@ -3300,7 +3300,7 @@ pub fn divstep(out1: *u64, out2: *[7]u64, out3: *[7]u64, out4: *[6]u64, out5: *[...@@ -3300,7 +3300,7 @@ pub fn divstep(out1: *u64, out2: *[7]u64, out3: *[7]u64, out4: *[6]u64, out5: *[
3300 var x1: u64 = undefined;3300 var x1: u64 = undefined;
3301 var x2: u1 = undefined;3301 var x2: u1 = undefined;
3302 addcarryxU64(&x1, &x2, 0x0, (~arg1), 0x1);3302 addcarryxU64(&x1, &x2, 0x0, (~arg1), 0x1);
3303 const x3 = (@truncate(u1, (x1 >> 63)) & @truncate(u1, ((arg3[0]) & 0x1)));3303 const x3 = (@as(u1, @truncate((x1 >> 63))) & @as(u1, @truncate(((arg3[0]) & 0x1))));
3304 var x4: u64 = undefined;3304 var x4: u64 = undefined;
3305 var x5: u1 = undefined;3305 var x5: u1 = undefined;
3306 addcarryxU64(&x4, &x5, 0x0, (~arg1), 0x1);3306 addcarryxU64(&x4, &x5, 0x0, (~arg1), 0x1);
...@@ -3462,7 +3462,7 @@ pub fn divstep(out1: *u64, out2: *[7]u64, out3: *[7]u64, out4: *[6]u64, out5: *[...@@ -3462,7 +3462,7 @@ pub fn divstep(out1: *u64, out2: *[7]u64, out3: *[7]u64, out4: *[6]u64, out5: *[
3462 cmovznzU64(&x102, x3, (arg5[4]), x94);3462 cmovznzU64(&x102, x3, (arg5[4]), x94);
3463 var x103: u64 = undefined;3463 var x103: u64 = undefined;
3464 cmovznzU64(&x103, x3, (arg5[5]), x96);3464 cmovznzU64(&x103, x3, (arg5[5]), x96);
3465 const x104 = @truncate(u1, (x28 & 0x1));3465 const x104 = @as(u1, @truncate((x28 & 0x1)));
3466 var x105: u64 = undefined;3466 var x105: u64 = undefined;
3467 cmovznzU64(&x105, x104, 0x0, x7);3467 cmovznzU64(&x105, x104, 0x0, x7);
3468 var x106: u64 = undefined;3468 var x106: u64 = undefined;
lib/std/crypto/pcurves/secp256k1.zig+16-16
...@@ -67,8 +67,8 @@ pub const Secp256k1 = struct {...@@ -67,8 +67,8 @@ pub const Secp256k1 = struct {
67 const t1 = math.mulWide(u256, k, 21949224512762693861512883645436906316123769664773102907882521278123970637873);67 const t1 = math.mulWide(u256, k, 21949224512762693861512883645436906316123769664773102907882521278123970637873);
68 const t2 = math.mulWide(u256, k, 103246583619904461035481197785446227098457807945486720222659797044629401272177);68 const t2 = math.mulWide(u256, k, 103246583619904461035481197785446227098457807945486720222659797044629401272177);
6969
70 const c1 = @truncate(u128, t1 >> 384) + @truncate(u1, t1 >> 383);70 const c1 = @as(u128, @truncate(t1 >> 384)) + @as(u1, @truncate(t1 >> 383));
71 const c2 = @truncate(u128, t2 >> 384) + @truncate(u1, t2 >> 383);71 const c2 = @as(u128, @truncate(t2 >> 384)) + @as(u1, @truncate(t2 >> 383));
7272
73 var buf: [32]u8 = undefined;73 var buf: [32]u8 = undefined;
7474
...@@ -346,7 +346,7 @@ pub const Secp256k1 = struct {...@@ -346,7 +346,7 @@ pub const Secp256k1 = struct {
346 var t = Secp256k1.identityElement;346 var t = Secp256k1.identityElement;
347 comptime var i: u8 = 1;347 comptime var i: u8 = 1;
348 inline while (i < pc.len) : (i += 1) {348 inline while (i < pc.len) : (i += 1) {
349 t.cMov(pc[i], @truncate(u1, (@as(usize, b ^ i) -% 1) >> 8));349 t.cMov(pc[i], @as(u1, @truncate((@as(usize, b ^ i) -% 1) >> 8)));
350 }350 }
351 return t;351 return t;
352 }352 }
...@@ -354,8 +354,8 @@ pub const Secp256k1 = struct {...@@ -354,8 +354,8 @@ pub const Secp256k1 = struct {
354 fn slide(s: [32]u8) [2 * 32 + 1]i8 {354 fn slide(s: [32]u8) [2 * 32 + 1]i8 {
355 var e: [2 * 32 + 1]i8 = undefined;355 var e: [2 * 32 + 1]i8 = undefined;
356 for (s, 0..) |x, i| {356 for (s, 0..) |x, i| {
357 e[i * 2 + 0] = @as(i8, @truncate(u4, x));357 e[i * 2 + 0] = @as(i8, @as(u4, @truncate(x)));
358 e[i * 2 + 1] = @as(i8, @truncate(u4, x >> 4));358 e[i * 2 + 1] = @as(i8, @as(u4, @truncate(x >> 4)));
359 }359 }
360 // Now, e[0..63] is between 0 and 15, e[63] is between 0 and 7360 // Now, e[0..63] is between 0 and 15, e[63] is between 0 and 7
361 var carry: i8 = 0;361 var carry: i8 = 0;
...@@ -379,9 +379,9 @@ pub const Secp256k1 = struct {...@@ -379,9 +379,9 @@ pub const Secp256k1 = struct {
379 while (true) : (pos -= 1) {379 while (true) : (pos -= 1) {
380 const slot = e[pos];380 const slot = e[pos];
381 if (slot > 0) {381 if (slot > 0) {
382 q = q.add(pc[@intCast(usize, slot)]);382 q = q.add(pc[@as(usize, @intCast(slot))]);
383 } else if (slot < 0) {383 } else if (slot < 0) {
384 q = q.sub(pc[@intCast(usize, -slot)]);384 q = q.sub(pc[@as(usize, @intCast(-slot))]);
385 }385 }
386 if (pos == 0) break;386 if (pos == 0) break;
387 q = q.dbl().dbl().dbl().dbl();387 q = q.dbl().dbl().dbl().dbl();
...@@ -394,7 +394,7 @@ pub const Secp256k1 = struct {...@@ -394,7 +394,7 @@ pub const Secp256k1 = struct {
394 var q = Secp256k1.identityElement;394 var q = Secp256k1.identityElement;
395 var pos: usize = 252;395 var pos: usize = 252;
396 while (true) : (pos -= 4) {396 while (true) : (pos -= 4) {
397 const slot = @truncate(u4, (s[pos >> 3] >> @truncate(u3, pos)));397 const slot = @as(u4, @truncate((s[pos >> 3] >> @as(u3, @truncate(pos)))));
398 if (vartime) {398 if (vartime) {
399 if (slot != 0) {399 if (slot != 0) {
400 q = q.add(pc[slot]);400 q = q.add(pc[slot]);
...@@ -482,15 +482,15 @@ pub const Secp256k1 = struct {...@@ -482,15 +482,15 @@ pub const Secp256k1 = struct {
482 while (true) : (pos -= 1) {482 while (true) : (pos -= 1) {
483 const slot1 = e1[pos];483 const slot1 = e1[pos];
484 if (slot1 > 0) {484 if (slot1 > 0) {
485 q = q.add(pc1[@intCast(usize, slot1)]);485 q = q.add(pc1[@as(usize, @intCast(slot1))]);
486 } else if (slot1 < 0) {486 } else if (slot1 < 0) {
487 q = q.sub(pc1[@intCast(usize, -slot1)]);487 q = q.sub(pc1[@as(usize, @intCast(-slot1))]);
488 }488 }
489 const slot2 = e2[pos];489 const slot2 = e2[pos];
490 if (slot2 > 0) {490 if (slot2 > 0) {
491 q = q.add(pc2[@intCast(usize, slot2)]);491 q = q.add(pc2[@as(usize, @intCast(slot2))]);
492 } else if (slot2 < 0) {492 } else if (slot2 < 0) {
493 q = q.sub(pc2[@intCast(usize, -slot2)]);493 q = q.sub(pc2[@as(usize, @intCast(-slot2))]);
494 }494 }
495 if (pos == 0) break;495 if (pos == 0) break;
496 q = q.dbl().dbl().dbl().dbl();496 q = q.dbl().dbl().dbl().dbl();
...@@ -523,15 +523,15 @@ pub const Secp256k1 = struct {...@@ -523,15 +523,15 @@ pub const Secp256k1 = struct {
523 while (true) : (pos -= 1) {523 while (true) : (pos -= 1) {
524 const slot1 = e1[pos];524 const slot1 = e1[pos];
525 if (slot1 > 0) {525 if (slot1 > 0) {
526 q = q.add(pc1[@intCast(usize, slot1)]);526 q = q.add(pc1[@as(usize, @intCast(slot1))]);
527 } else if (slot1 < 0) {527 } else if (slot1 < 0) {
528 q = q.sub(pc1[@intCast(usize, -slot1)]);528 q = q.sub(pc1[@as(usize, @intCast(-slot1))]);
529 }529 }
530 const slot2 = e2[pos];530 const slot2 = e2[pos];
531 if (slot2 > 0) {531 if (slot2 > 0) {
532 q = q.add(pc2[@intCast(usize, slot2)]);532 q = q.add(pc2[@as(usize, @intCast(slot2))]);
533 } else if (slot2 < 0) {533 } else if (slot2 < 0) {
534 q = q.sub(pc2[@intCast(usize, -slot2)]);534 q = q.sub(pc2[@as(usize, @intCast(-slot2))]);
535 }535 }
536 if (pos == 0) break;536 if (pos == 0) break;
537 q = q.dbl().dbl().dbl().dbl();537 q = q.dbl().dbl().dbl().dbl();
lib/std/crypto/pcurves/secp256k1/secp256k1_64.zig+36-36
...@@ -88,8 +88,8 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {...@@ -88,8 +88,8 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
88 @setRuntimeSafety(mode == .Debug);88 @setRuntimeSafety(mode == .Debug);
8989
90 const x = @as(u128, arg1) * @as(u128, arg2);90 const x = @as(u128, arg1) * @as(u128, arg2);
91 out1.* = @truncate(u64, x);91 out1.* = @as(u64, @truncate(x));
92 out2.* = @truncate(u64, x >> 64);92 out2.* = @as(u64, @truncate(x >> 64));
93}93}
9494
95/// The function cmovznzU64 is a single-word conditional move.95/// The function cmovznzU64 is a single-word conditional move.
...@@ -1488,62 +1488,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {...@@ -1488,62 +1488,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {
1488 const x2 = (arg1[2]);1488 const x2 = (arg1[2]);
1489 const x3 = (arg1[1]);1489 const x3 = (arg1[1]);
1490 const x4 = (arg1[0]);1490 const x4 = (arg1[0]);
1491 const x5 = @truncate(u8, (x4 & 0xff));1491 const x5 = @as(u8, @truncate((x4 & 0xff)));
1492 const x6 = (x4 >> 8);1492 const x6 = (x4 >> 8);
1493 const x7 = @truncate(u8, (x6 & 0xff));1493 const x7 = @as(u8, @truncate((x6 & 0xff)));
1494 const x8 = (x6 >> 8);1494 const x8 = (x6 >> 8);
1495 const x9 = @truncate(u8, (x8 & 0xff));1495 const x9 = @as(u8, @truncate((x8 & 0xff)));
1496 const x10 = (x8 >> 8);1496 const x10 = (x8 >> 8);
1497 const x11 = @truncate(u8, (x10 & 0xff));1497 const x11 = @as(u8, @truncate((x10 & 0xff)));
1498 const x12 = (x10 >> 8);1498 const x12 = (x10 >> 8);
1499 const x13 = @truncate(u8, (x12 & 0xff));1499 const x13 = @as(u8, @truncate((x12 & 0xff)));
1500 const x14 = (x12 >> 8);1500 const x14 = (x12 >> 8);
1501 const x15 = @truncate(u8, (x14 & 0xff));1501 const x15 = @as(u8, @truncate((x14 & 0xff)));
1502 const x16 = (x14 >> 8);1502 const x16 = (x14 >> 8);
1503 const x17 = @truncate(u8, (x16 & 0xff));1503 const x17 = @as(u8, @truncate((x16 & 0xff)));
1504 const x18 = @truncate(u8, (x16 >> 8));1504 const x18 = @as(u8, @truncate((x16 >> 8)));
1505 const x19 = @truncate(u8, (x3 & 0xff));1505 const x19 = @as(u8, @truncate((x3 & 0xff)));
1506 const x20 = (x3 >> 8);1506 const x20 = (x3 >> 8);
1507 const x21 = @truncate(u8, (x20 & 0xff));1507 const x21 = @as(u8, @truncate((x20 & 0xff)));
1508 const x22 = (x20 >> 8);1508 const x22 = (x20 >> 8);
1509 const x23 = @truncate(u8, (x22 & 0xff));1509 const x23 = @as(u8, @truncate((x22 & 0xff)));
1510 const x24 = (x22 >> 8);1510 const x24 = (x22 >> 8);
1511 const x25 = @truncate(u8, (x24 & 0xff));1511 const x25 = @as(u8, @truncate((x24 & 0xff)));
1512 const x26 = (x24 >> 8);1512 const x26 = (x24 >> 8);
1513 const x27 = @truncate(u8, (x26 & 0xff));1513 const x27 = @as(u8, @truncate((x26 & 0xff)));
1514 const x28 = (x26 >> 8);1514 const x28 = (x26 >> 8);
1515 const x29 = @truncate(u8, (x28 & 0xff));1515 const x29 = @as(u8, @truncate((x28 & 0xff)));
1516 const x30 = (x28 >> 8);1516 const x30 = (x28 >> 8);
1517 const x31 = @truncate(u8, (x30 & 0xff));1517 const x31 = @as(u8, @truncate((x30 & 0xff)));
1518 const x32 = @truncate(u8, (x30 >> 8));1518 const x32 = @as(u8, @truncate((x30 >> 8)));
1519 const x33 = @truncate(u8, (x2 & 0xff));1519 const x33 = @as(u8, @truncate((x2 & 0xff)));
1520 const x34 = (x2 >> 8);1520 const x34 = (x2 >> 8);
1521 const x35 = @truncate(u8, (x34 & 0xff));1521 const x35 = @as(u8, @truncate((x34 & 0xff)));
1522 const x36 = (x34 >> 8);1522 const x36 = (x34 >> 8);
1523 const x37 = @truncate(u8, (x36 & 0xff));1523 const x37 = @as(u8, @truncate((x36 & 0xff)));
1524 const x38 = (x36 >> 8);1524 const x38 = (x36 >> 8);
1525 const x39 = @truncate(u8, (x38 & 0xff));1525 const x39 = @as(u8, @truncate((x38 & 0xff)));
1526 const x40 = (x38 >> 8);1526 const x40 = (x38 >> 8);
1527 const x41 = @truncate(u8, (x40 & 0xff));1527 const x41 = @as(u8, @truncate((x40 & 0xff)));
1528 const x42 = (x40 >> 8);1528 const x42 = (x40 >> 8);
1529 const x43 = @truncate(u8, (x42 & 0xff));1529 const x43 = @as(u8, @truncate((x42 & 0xff)));
1530 const x44 = (x42 >> 8);1530 const x44 = (x42 >> 8);
1531 const x45 = @truncate(u8, (x44 & 0xff));1531 const x45 = @as(u8, @truncate((x44 & 0xff)));
1532 const x46 = @truncate(u8, (x44 >> 8));1532 const x46 = @as(u8, @truncate((x44 >> 8)));
1533 const x47 = @truncate(u8, (x1 & 0xff));1533 const x47 = @as(u8, @truncate((x1 & 0xff)));
1534 const x48 = (x1 >> 8);1534 const x48 = (x1 >> 8);
1535 const x49 = @truncate(u8, (x48 & 0xff));1535 const x49 = @as(u8, @truncate((x48 & 0xff)));
1536 const x50 = (x48 >> 8);1536 const x50 = (x48 >> 8);
1537 const x51 = @truncate(u8, (x50 & 0xff));1537 const x51 = @as(u8, @truncate((x50 & 0xff)));
1538 const x52 = (x50 >> 8);1538 const x52 = (x50 >> 8);
1539 const x53 = @truncate(u8, (x52 & 0xff));1539 const x53 = @as(u8, @truncate((x52 & 0xff)));
1540 const x54 = (x52 >> 8);1540 const x54 = (x52 >> 8);
1541 const x55 = @truncate(u8, (x54 & 0xff));1541 const x55 = @as(u8, @truncate((x54 & 0xff)));
1542 const x56 = (x54 >> 8);1542 const x56 = (x54 >> 8);
1543 const x57 = @truncate(u8, (x56 & 0xff));1543 const x57 = @as(u8, @truncate((x56 & 0xff)));
1544 const x58 = (x56 >> 8);1544 const x58 = (x56 >> 8);
1545 const x59 = @truncate(u8, (x58 & 0xff));1545 const x59 = @as(u8, @truncate((x58 & 0xff)));
1546 const x60 = @truncate(u8, (x58 >> 8));1546 const x60 = @as(u8, @truncate((x58 >> 8)));
1547 out1[0] = x5;1547 out1[0] = x5;
1548 out1[1] = x7;1548 out1[1] = x7;
1549 out1[2] = x9;1549 out1[2] = x9;
...@@ -1726,7 +1726,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1726,7 +1726,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1726 var x1: u64 = undefined;1726 var x1: u64 = undefined;
1727 var x2: u1 = undefined;1727 var x2: u1 = undefined;
1728 addcarryxU64(&x1, &x2, 0x0, (~arg1), 0x1);1728 addcarryxU64(&x1, &x2, 0x0, (~arg1), 0x1);
1729 const x3 = (@truncate(u1, (x1 >> 63)) & @truncate(u1, ((arg3[0]) & 0x1)));1729 const x3 = (@as(u1, @truncate((x1 >> 63))) & @as(u1, @truncate(((arg3[0]) & 0x1))));
1730 var x4: u64 = undefined;1730 var x4: u64 = undefined;
1731 var x5: u1 = undefined;1731 var x5: u1 = undefined;
1732 addcarryxU64(&x4, &x5, 0x0, (~arg1), 0x1);1732 addcarryxU64(&x4, &x5, 0x0, (~arg1), 0x1);
...@@ -1840,7 +1840,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1840,7 +1840,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1840 cmovznzU64(&x72, x3, (arg5[2]), x66);1840 cmovznzU64(&x72, x3, (arg5[2]), x66);
1841 var x73: u64 = undefined;1841 var x73: u64 = undefined;
1842 cmovznzU64(&x73, x3, (arg5[3]), x68);1842 cmovznzU64(&x73, x3, (arg5[3]), x68);
1843 const x74 = @truncate(u1, (x22 & 0x1));1843 const x74 = @as(u1, @truncate((x22 & 0x1)));
1844 var x75: u64 = undefined;1844 var x75: u64 = undefined;
1845 cmovznzU64(&x75, x74, 0x0, x7);1845 cmovznzU64(&x75, x74, 0x0, x7);
1846 var x76: u64 = undefined;1846 var x76: u64 = undefined;
lib/std/crypto/pcurves/secp256k1/secp256k1_scalar_64.zig+36-36
...@@ -88,8 +88,8 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {...@@ -88,8 +88,8 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
88 @setRuntimeSafety(mode == .Debug);88 @setRuntimeSafety(mode == .Debug);
8989
90 const x = @as(u128, arg1) * @as(u128, arg2);90 const x = @as(u128, arg1) * @as(u128, arg2);
91 out1.* = @truncate(u64, x);91 out1.* = @as(u64, @truncate(x));
92 out2.* = @truncate(u64, x >> 64);92 out2.* = @as(u64, @truncate(x >> 64));
93}93}
9494
95/// The function cmovznzU64 is a single-word conditional move.95/// The function cmovznzU64 is a single-word conditional move.
...@@ -1548,62 +1548,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {...@@ -1548,62 +1548,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {
1548 const x2 = (arg1[2]);1548 const x2 = (arg1[2]);
1549 const x3 = (arg1[1]);1549 const x3 = (arg1[1]);
1550 const x4 = (arg1[0]);1550 const x4 = (arg1[0]);
1551 const x5 = @truncate(u8, (x4 & 0xff));1551 const x5 = @as(u8, @truncate((x4 & 0xff)));
1552 const x6 = (x4 >> 8);1552 const x6 = (x4 >> 8);
1553 const x7 = @truncate(u8, (x6 & 0xff));1553 const x7 = @as(u8, @truncate((x6 & 0xff)));
1554 const x8 = (x6 >> 8);1554 const x8 = (x6 >> 8);
1555 const x9 = @truncate(u8, (x8 & 0xff));1555 const x9 = @as(u8, @truncate((x8 & 0xff)));
1556 const x10 = (x8 >> 8);1556 const x10 = (x8 >> 8);
1557 const x11 = @truncate(u8, (x10 & 0xff));1557 const x11 = @as(u8, @truncate((x10 & 0xff)));
1558 const x12 = (x10 >> 8);1558 const x12 = (x10 >> 8);
1559 const x13 = @truncate(u8, (x12 & 0xff));1559 const x13 = @as(u8, @truncate((x12 & 0xff)));
1560 const x14 = (x12 >> 8);1560 const x14 = (x12 >> 8);
1561 const x15 = @truncate(u8, (x14 & 0xff));1561 const x15 = @as(u8, @truncate((x14 & 0xff)));
1562 const x16 = (x14 >> 8);1562 const x16 = (x14 >> 8);
1563 const x17 = @truncate(u8, (x16 & 0xff));1563 const x17 = @as(u8, @truncate((x16 & 0xff)));
1564 const x18 = @truncate(u8, (x16 >> 8));1564 const x18 = @as(u8, @truncate((x16 >> 8)));
1565 const x19 = @truncate(u8, (x3 & 0xff));1565 const x19 = @as(u8, @truncate((x3 & 0xff)));
1566 const x20 = (x3 >> 8);1566 const x20 = (x3 >> 8);
1567 const x21 = @truncate(u8, (x20 & 0xff));1567 const x21 = @as(u8, @truncate((x20 & 0xff)));
1568 const x22 = (x20 >> 8);1568 const x22 = (x20 >> 8);
1569 const x23 = @truncate(u8, (x22 & 0xff));1569 const x23 = @as(u8, @truncate((x22 & 0xff)));
1570 const x24 = (x22 >> 8);1570 const x24 = (x22 >> 8);
1571 const x25 = @truncate(u8, (x24 & 0xff));1571 const x25 = @as(u8, @truncate((x24 & 0xff)));
1572 const x26 = (x24 >> 8);1572 const x26 = (x24 >> 8);
1573 const x27 = @truncate(u8, (x26 & 0xff));1573 const x27 = @as(u8, @truncate((x26 & 0xff)));
1574 const x28 = (x26 >> 8);1574 const x28 = (x26 >> 8);
1575 const x29 = @truncate(u8, (x28 & 0xff));1575 const x29 = @as(u8, @truncate((x28 & 0xff)));
1576 const x30 = (x28 >> 8);1576 const x30 = (x28 >> 8);
1577 const x31 = @truncate(u8, (x30 & 0xff));1577 const x31 = @as(u8, @truncate((x30 & 0xff)));
1578 const x32 = @truncate(u8, (x30 >> 8));1578 const x32 = @as(u8, @truncate((x30 >> 8)));
1579 const x33 = @truncate(u8, (x2 & 0xff));1579 const x33 = @as(u8, @truncate((x2 & 0xff)));
1580 const x34 = (x2 >> 8);1580 const x34 = (x2 >> 8);
1581 const x35 = @truncate(u8, (x34 & 0xff));1581 const x35 = @as(u8, @truncate((x34 & 0xff)));
1582 const x36 = (x34 >> 8);1582 const x36 = (x34 >> 8);
1583 const x37 = @truncate(u8, (x36 & 0xff));1583 const x37 = @as(u8, @truncate((x36 & 0xff)));
1584 const x38 = (x36 >> 8);1584 const x38 = (x36 >> 8);
1585 const x39 = @truncate(u8, (x38 & 0xff));1585 const x39 = @as(u8, @truncate((x38 & 0xff)));
1586 const x40 = (x38 >> 8);1586 const x40 = (x38 >> 8);
1587 const x41 = @truncate(u8, (x40 & 0xff));1587 const x41 = @as(u8, @truncate((x40 & 0xff)));
1588 const x42 = (x40 >> 8);1588 const x42 = (x40 >> 8);
1589 const x43 = @truncate(u8, (x42 & 0xff));1589 const x43 = @as(u8, @truncate((x42 & 0xff)));
1590 const x44 = (x42 >> 8);1590 const x44 = (x42 >> 8);
1591 const x45 = @truncate(u8, (x44 & 0xff));1591 const x45 = @as(u8, @truncate((x44 & 0xff)));
1592 const x46 = @truncate(u8, (x44 >> 8));1592 const x46 = @as(u8, @truncate((x44 >> 8)));
1593 const x47 = @truncate(u8, (x1 & 0xff));1593 const x47 = @as(u8, @truncate((x1 & 0xff)));
1594 const x48 = (x1 >> 8);1594 const x48 = (x1 >> 8);
1595 const x49 = @truncate(u8, (x48 & 0xff));1595 const x49 = @as(u8, @truncate((x48 & 0xff)));
1596 const x50 = (x48 >> 8);1596 const x50 = (x48 >> 8);
1597 const x51 = @truncate(u8, (x50 & 0xff));1597 const x51 = @as(u8, @truncate((x50 & 0xff)));
1598 const x52 = (x50 >> 8);1598 const x52 = (x50 >> 8);
1599 const x53 = @truncate(u8, (x52 & 0xff));1599 const x53 = @as(u8, @truncate((x52 & 0xff)));
1600 const x54 = (x52 >> 8);1600 const x54 = (x52 >> 8);
1601 const x55 = @truncate(u8, (x54 & 0xff));1601 const x55 = @as(u8, @truncate((x54 & 0xff)));
1602 const x56 = (x54 >> 8);1602 const x56 = (x54 >> 8);
1603 const x57 = @truncate(u8, (x56 & 0xff));1603 const x57 = @as(u8, @truncate((x56 & 0xff)));
1604 const x58 = (x56 >> 8);1604 const x58 = (x56 >> 8);
1605 const x59 = @truncate(u8, (x58 & 0xff));1605 const x59 = @as(u8, @truncate((x58 & 0xff)));
1606 const x60 = @truncate(u8, (x58 >> 8));1606 const x60 = @as(u8, @truncate((x58 >> 8)));
1607 out1[0] = x5;1607 out1[0] = x5;
1608 out1[1] = x7;1608 out1[1] = x7;
1609 out1[2] = x9;1609 out1[2] = x9;
...@@ -1786,7 +1786,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1786,7 +1786,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1786 var x1: u64 = undefined;1786 var x1: u64 = undefined;
1787 var x2: u1 = undefined;1787 var x2: u1 = undefined;
1788 addcarryxU64(&x1, &x2, 0x0, (~arg1), 0x1);1788 addcarryxU64(&x1, &x2, 0x0, (~arg1), 0x1);
1789 const x3 = (@truncate(u1, (x1 >> 63)) & @truncate(u1, ((arg3[0]) & 0x1)));1789 const x3 = (@as(u1, @truncate((x1 >> 63))) & @as(u1, @truncate(((arg3[0]) & 0x1))));
1790 var x4: u64 = undefined;1790 var x4: u64 = undefined;
1791 var x5: u1 = undefined;1791 var x5: u1 = undefined;
1792 addcarryxU64(&x4, &x5, 0x0, (~arg1), 0x1);1792 addcarryxU64(&x4, &x5, 0x0, (~arg1), 0x1);
...@@ -1900,7 +1900,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1900,7 +1900,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1900 cmovznzU64(&x72, x3, (arg5[2]), x66);1900 cmovznzU64(&x72, x3, (arg5[2]), x66);
1901 var x73: u64 = undefined;1901 var x73: u64 = undefined;
1902 cmovznzU64(&x73, x3, (arg5[3]), x68);1902 cmovznzU64(&x73, x3, (arg5[3]), x68);
1903 const x74 = @truncate(u1, (x22 & 0x1));1903 const x74 = @as(u1, @truncate((x22 & 0x1)));
1904 var x75: u64 = undefined;1904 var x75: u64 = undefined;
1905 cmovznzU64(&x75, x74, 0x0, x7);1905 cmovznzU64(&x75, x74, 0x0, x7);
1906 var x76: u64 = undefined;1906 var x76: u64 = undefined;
lib/std/crypto/phc_encoding.zig+1-1
...@@ -193,7 +193,7 @@ pub fn serialize(params: anytype, str: []u8) Error![]const u8 {...@@ -193,7 +193,7 @@ pub fn serialize(params: anytype, str: []u8) Error![]const u8 {
193pub fn calcSize(params: anytype) usize {193pub fn calcSize(params: anytype) usize {
194 var buf = io.countingWriter(io.null_writer);194 var buf = io.countingWriter(io.null_writer);
195 serializeTo(params, buf.writer()) catch unreachable;195 serializeTo(params, buf.writer()) catch unreachable;
196 return @intCast(usize, buf.bytes_written);196 return @as(usize, @intCast(buf.bytes_written));
197}197}
198198
199fn serializeTo(params: anytype, out: anytype) !void {199fn serializeTo(params: anytype, out: anytype) !void {
lib/std/crypto/poly1305.zig+7-7
...@@ -76,12 +76,12 @@ pub const Poly1305 = struct {...@@ -76,12 +76,12 @@ pub const Poly1305 = struct {
76 const m1 = h1r0 +% h0r1;76 const m1 = h1r0 +% h0r1;
77 const m2 = h2r0 +% h1r1;77 const m2 = h2r0 +% h1r1;
7878
79 const t0 = @truncate(u64, m0);79 const t0 = @as(u64, @truncate(m0));
80 v = @addWithOverflow(@truncate(u64, m1), @truncate(u64, m0 >> 64));80 v = @addWithOverflow(@as(u64, @truncate(m1)), @as(u64, @truncate(m0 >> 64)));
81 const t1 = v[0];81 const t1 = v[0];
82 v = add(@truncate(u64, m2), @truncate(u64, m1 >> 64), v[1]);82 v = add(@as(u64, @truncate(m2)), @as(u64, @truncate(m1 >> 64)), v[1]);
83 const t2 = v[0];83 const t2 = v[0];
84 v = add(@truncate(u64, m3), @truncate(u64, m2 >> 64), v[1]);84 v = add(@as(u64, @truncate(m3)), @as(u64, @truncate(m2 >> 64)), v[1]);
85 const t3 = v[0];85 const t3 = v[0];
8686
87 // Partial reduction87 // Partial reduction
...@@ -98,9 +98,9 @@ pub const Poly1305 = struct {...@@ -98,9 +98,9 @@ pub const Poly1305 = struct {
98 h1 = v[0];98 h1 = v[0];
99 h2 +%= v[1];99 h2 +%= v[1];
100 const cc = (cclo | (@as(u128, cchi) << 64)) >> 2;100 const cc = (cclo | (@as(u128, cchi) << 64)) >> 2;
101 v = @addWithOverflow(h0, @truncate(u64, cc));101 v = @addWithOverflow(h0, @as(u64, @truncate(cc)));
102 h0 = v[0];102 h0 = v[0];
103 v = add(h1, @truncate(u64, cc >> 64), v[1]);103 v = add(h1, @as(u64, @truncate(cc >> 64)), v[1]);
104 h1 = v[0];104 h1 = v[0];
105 h2 +%= v[1];105 h2 +%= v[1];
106 }106 }
...@@ -185,7 +185,7 @@ pub const Poly1305 = struct {...@@ -185,7 +185,7 @@ pub const Poly1305 = struct {
185 mem.writeIntLittle(u64, out[0..8], st.h[0]);185 mem.writeIntLittle(u64, out[0..8], st.h[0]);
186 mem.writeIntLittle(u64, out[8..16], st.h[1]);186 mem.writeIntLittle(u64, out[8..16], st.h[1]);
187187
188 utils.secureZero(u8, @ptrCast([*]u8, st)[0..@sizeOf(Poly1305)]);188 utils.secureZero(u8, @as([*]u8, @ptrCast(st))[0..@sizeOf(Poly1305)]);
189 }189 }
190190
191 pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void {191 pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void {
lib/std/crypto/salsa20.zig+2-2
...@@ -337,8 +337,8 @@ pub fn Salsa(comptime rounds: comptime_int) type {...@@ -337,8 +337,8 @@ pub fn Salsa(comptime rounds: comptime_int) type {
337 var d: [4]u32 = undefined;337 var d: [4]u32 = undefined;
338 d[0] = mem.readIntLittle(u32, nonce[0..4]);338 d[0] = mem.readIntLittle(u32, nonce[0..4]);
339 d[1] = mem.readIntLittle(u32, nonce[4..8]);339 d[1] = mem.readIntLittle(u32, nonce[4..8]);
340 d[2] = @truncate(u32, counter);340 d[2] = @as(u32, @truncate(counter));
341 d[3] = @truncate(u32, counter >> 32);341 d[3] = @as(u32, @truncate(counter >> 32));
342 SalsaImpl(rounds).salsaXor(out, in, keyToWords(key), d);342 SalsaImpl(rounds).salsaXor(out, in, keyToWords(key), d);
343 }343 }
344 };344 };
lib/std/crypto/scrypt.zig+23-23
...@@ -73,11 +73,11 @@ fn salsaXor(tmp: *align(16) [16]u32, in: []align(16) const u32, out: []align(16)...@@ -73,11 +73,11 @@ fn salsaXor(tmp: *align(16) [16]u32, in: []align(16) const u32, out: []align(16)
73}73}
7474
75fn blockMix(tmp: *align(16) [16]u32, in: []align(16) const u32, out: []align(16) u32, r: u30) void {75fn blockMix(tmp: *align(16) [16]u32, in: []align(16) const u32, out: []align(16) u32, r: u30) void {
76 blockCopy(tmp, @alignCast(16, in[(2 * r - 1) * 16 ..]), 1);76 blockCopy(tmp, @alignCast(in[(2 * r - 1) * 16 ..]), 1);
77 var i: usize = 0;77 var i: usize = 0;
78 while (i < 2 * r) : (i += 2) {78 while (i < 2 * r) : (i += 2) {
79 salsaXor(tmp, @alignCast(16, in[i * 16 ..]), @alignCast(16, out[i * 8 ..]));79 salsaXor(tmp, @alignCast(in[i * 16 ..]), @alignCast(out[i * 8 ..]));
80 salsaXor(tmp, @alignCast(16, in[i * 16 + 16 ..]), @alignCast(16, out[i * 8 + r * 16 ..]));80 salsaXor(tmp, @alignCast(in[i * 16 + 16 ..]), @alignCast(out[i * 8 + r * 16 ..]));
81 }81 }
82}82}
8383
...@@ -87,8 +87,8 @@ fn integerify(b: []align(16) const u32, r: u30) u64 {...@@ -87,8 +87,8 @@ fn integerify(b: []align(16) const u32, r: u30) u64 {
87}87}
8888
89fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) u32) void {89fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) u32) void {
90 var x = @alignCast(16, xy[0 .. 32 * r]);90 var x: []align(16) u32 = @alignCast(xy[0 .. 32 * r]);
91 var y = @alignCast(16, xy[32 * r ..]);91 var y: []align(16) u32 = @alignCast(xy[32 * r ..]);
9292
93 for (x, 0..) |*v1, j| {93 for (x, 0..) |*v1, j| {
94 v1.* = mem.readIntSliceLittle(u32, b[4 * j ..]);94 v1.* = mem.readIntSliceLittle(u32, b[4 * j ..]);
...@@ -97,21 +97,21 @@ fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16)...@@ -97,21 +97,21 @@ fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16)
97 var tmp: [16]u32 align(16) = undefined;97 var tmp: [16]u32 align(16) = undefined;
98 var i: usize = 0;98 var i: usize = 0;
99 while (i < n) : (i += 2) {99 while (i < n) : (i += 2) {
100 blockCopy(@alignCast(16, v[i * (32 * r) ..]), x, 2 * r);100 blockCopy(@alignCast(v[i * (32 * r) ..]), x, 2 * r);
101 blockMix(&tmp, x, y, r);101 blockMix(&tmp, x, y, r);
102102
103 blockCopy(@alignCast(16, v[(i + 1) * (32 * r) ..]), y, 2 * r);103 blockCopy(@alignCast(v[(i + 1) * (32 * r) ..]), y, 2 * r);
104 blockMix(&tmp, y, x, r);104 blockMix(&tmp, y, x, r);
105 }105 }
106106
107 i = 0;107 i = 0;
108 while (i < n) : (i += 2) {108 while (i < n) : (i += 2) {
109 var j = @intCast(usize, integerify(x, r) & (n - 1));109 var j = @as(usize, @intCast(integerify(x, r) & (n - 1)));
110 blockXor(x, @alignCast(16, v[j * (32 * r) ..]), 2 * r);110 blockXor(x, @alignCast(v[j * (32 * r) ..]), 2 * r);
111 blockMix(&tmp, x, y, r);111 blockMix(&tmp, x, y, r);
112112
113 j = @intCast(usize, integerify(y, r) & (n - 1));113 j = @as(usize, @intCast(integerify(y, r) & (n - 1)));
114 blockXor(y, @alignCast(16, v[j * (32 * r) ..]), 2 * r);114 blockXor(y, @alignCast(v[j * (32 * r) ..]), 2 * r);
115 blockMix(&tmp, y, x, r);115 blockMix(&tmp, y, x, r);
116 }116 }
117117
...@@ -147,12 +147,12 @@ pub const Params = struct {...@@ -147,12 +147,12 @@ pub const Params = struct {
147 const r: u30 = 8;147 const r: u30 = 8;
148 if (ops < mem_limit / 32) {148 if (ops < mem_limit / 32) {
149 const max_n = ops / (r * 4);149 const max_n = ops / (r * 4);
150 return Self{ .r = r, .p = 1, .ln = @intCast(u6, math.log2(max_n)) };150 return Self{ .r = r, .p = 1, .ln = @as(u6, @intCast(math.log2(max_n))) };
151 } else {151 } else {
152 const max_n = mem_limit / (@intCast(usize, r) * 128);152 const max_n = mem_limit / (@as(usize, @intCast(r)) * 128);
153 const ln = @intCast(u6, math.log2(max_n));153 const ln = @as(u6, @intCast(math.log2(max_n)));
154 const max_rp = @min(0x3fffffff, (ops / 4) / (@as(u64, 1) << ln));154 const max_rp = @min(0x3fffffff, (ops / 4) / (@as(u64, 1) << ln));
155 return Self{ .r = r, .p = @intCast(u30, max_rp / @as(u64, r)), .ln = ln };155 return Self{ .r = r, .p = @as(u30, @intCast(max_rp / @as(u64, r))), .ln = ln };
156 }156 }
157 }157 }
158};158};
...@@ -185,7 +185,7 @@ pub fn kdf(...@@ -185,7 +185,7 @@ pub fn kdf(
185185
186 const n64 = @as(u64, 1) << params.ln;186 const n64 = @as(u64, 1) << params.ln;
187 if (n64 > max_size) return KdfError.WeakParameters;187 if (n64 > max_size) return KdfError.WeakParameters;
188 const n = @intCast(usize, n64);188 const n = @as(usize, @intCast(n64));
189 if (@as(u64, params.r) * @as(u64, params.p) >= 1 << 30 or189 if (@as(u64, params.r) * @as(u64, params.p) >= 1 << 30 or
190 params.r > max_int / 128 / @as(u64, params.p) or190 params.r > max_int / 128 / @as(u64, params.p) or
191 params.r > max_int / 256 or191 params.r > max_int / 256 or
...@@ -201,7 +201,7 @@ pub fn kdf(...@@ -201,7 +201,7 @@ pub fn kdf(
201 try pwhash.pbkdf2(dk, password, salt, 1, HmacSha256);201 try pwhash.pbkdf2(dk, password, salt, 1, HmacSha256);
202 var i: u32 = 0;202 var i: u32 = 0;
203 while (i < params.p) : (i += 1) {203 while (i < params.p) : (i += 1) {
204 smix(@alignCast(16, dk[i * 128 * params.r ..]), params.r, n, v, xy);204 smix(@alignCast(dk[i * 128 * params.r ..]), params.r, n, v, xy);
205 }205 }
206 try pwhash.pbkdf2(derived_key, password, dk, 1, HmacSha256);206 try pwhash.pbkdf2(derived_key, password, dk, 1, HmacSha256);
207}207}
...@@ -309,7 +309,7 @@ const crypt_format = struct {...@@ -309,7 +309,7 @@ const crypt_format = struct {
309 pub fn calcSize(params: anytype) usize {309 pub fn calcSize(params: anytype) usize {
310 var buf = io.countingWriter(io.null_writer);310 var buf = io.countingWriter(io.null_writer);
311 serializeTo(params, buf.writer()) catch unreachable;311 serializeTo(params, buf.writer()) catch unreachable;
312 return @intCast(usize, buf.bytes_written);312 return @as(usize, @intCast(buf.bytes_written));
313 }313 }
314314
315 fn serializeTo(params: anytype, out: anytype) !void {315 fn serializeTo(params: anytype, out: anytype) !void {
...@@ -343,7 +343,7 @@ const crypt_format = struct {...@@ -343,7 +343,7 @@ const crypt_format = struct {
343 fn intEncode(dst: []u8, src: anytype) void {343 fn intEncode(dst: []u8, src: anytype) void {
344 var n = src;344 var n = src;
345 for (dst) |*x| {345 for (dst) |*x| {
346 x.* = map64[@truncate(u6, n)];346 x.* = map64[@as(u6, @truncate(n))];
347 n = math.shr(@TypeOf(src), n, 6);347 n = math.shr(@TypeOf(src), n, 6);
348 }348 }
349 }349 }
...@@ -352,7 +352,7 @@ const crypt_format = struct {...@@ -352,7 +352,7 @@ const crypt_format = struct {
352 var v: T = 0;352 var v: T = 0;
353 for (src, 0..) |x, i| {353 for (src, 0..) |x, i| {
354 const vi = mem.indexOfScalar(u8, &map64, x) orelse return EncodingError.InvalidEncoding;354 const vi = mem.indexOfScalar(u8, &map64, x) orelse return EncodingError.InvalidEncoding;
355 v |= @intCast(T, vi) << @intCast(math.Log2Int(T), i * 6);355 v |= @as(T, @intCast(vi)) << @as(math.Log2Int(T), @intCast(i * 6));
356 }356 }
357 return v;357 return v;
358 }358 }
...@@ -366,10 +366,10 @@ const crypt_format = struct {...@@ -366,10 +366,10 @@ const crypt_format = struct {
366 const leftover = src[i * 4 ..];366 const leftover = src[i * 4 ..];
367 var v: u24 = 0;367 var v: u24 = 0;
368 for (leftover, 0..) |_, j| {368 for (leftover, 0..) |_, j| {
369 v |= @as(u24, try intDecode(u6, leftover[j..][0..1])) << @intCast(u5, j * 6);369 v |= @as(u24, try intDecode(u6, leftover[j..][0..1])) << @as(u5, @intCast(j * 6));
370 }370 }
371 for (dst[i * 3 ..], 0..) |*x, j| {371 for (dst[i * 3 ..], 0..) |*x, j| {
372 x.* = @truncate(u8, v >> @intCast(u5, j * 8));372 x.* = @as(u8, @truncate(v >> @as(u5, @intCast(j * 8))));
373 }373 }
374 }374 }
375375
...@@ -382,7 +382,7 @@ const crypt_format = struct {...@@ -382,7 +382,7 @@ const crypt_format = struct {
382 const leftover = src[i * 3 ..];382 const leftover = src[i * 3 ..];
383 var v: u24 = 0;383 var v: u24 = 0;
384 for (leftover, 0..) |x, j| {384 for (leftover, 0..) |x, j| {
385 v |= @as(u24, x) << @intCast(u5, j * 8);385 v |= @as(u24, x) << @as(u5, @intCast(j * 8));
386 }386 }
387 intEncode(dst[i * 4 ..], v);387 intEncode(dst[i * 4 ..], v);
388 }388 }
lib/std/crypto/sha1.zig+3-3
...@@ -75,7 +75,7 @@ pub const Sha1 = struct {...@@ -75,7 +75,7 @@ pub const Sha1 = struct {
7575
76 // Copy any remainder for next pass.76 // Copy any remainder for next pass.
77 @memcpy(d.buf[d.buf_len..][0 .. b.len - off], b[off..]);77 @memcpy(d.buf[d.buf_len..][0 .. b.len - off], b[off..]);
78 d.buf_len += @intCast(u8, b[off..].len);78 d.buf_len += @as(u8, @intCast(b[off..].len));
7979
80 d.total_len += b.len;80 d.total_len += b.len;
81 }81 }
...@@ -97,9 +97,9 @@ pub const Sha1 = struct {...@@ -97,9 +97,9 @@ pub const Sha1 = struct {
97 // Append message length.97 // Append message length.
98 var i: usize = 1;98 var i: usize = 1;
99 var len = d.total_len >> 5;99 var len = d.total_len >> 5;
100 d.buf[63] = @intCast(u8, d.total_len & 0x1f) << 3;100 d.buf[63] = @as(u8, @intCast(d.total_len & 0x1f)) << 3;
101 while (i < 8) : (i += 1) {101 while (i < 8) : (i += 1) {
102 d.buf[63 - i] = @intCast(u8, len & 0xff);102 d.buf[63 - i] = @as(u8, @intCast(len & 0xff));
103 len >>= 8;103 len >>= 8;
104 }104 }
105105
lib/std/crypto/sha2.zig+10-10
...@@ -132,7 +132,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -132,7 +132,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
132 // Copy any remainder for next pass.132 // Copy any remainder for next pass.
133 const b_slice = b[off..];133 const b_slice = b[off..];
134 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);134 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
135 d.buf_len += @intCast(u8, b[off..].len);135 d.buf_len += @as(u8, @intCast(b[off..].len));
136136
137 d.total_len += b.len;137 d.total_len += b.len;
138 }138 }
...@@ -159,9 +159,9 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -159,9 +159,9 @@ fn Sha2x32(comptime params: Sha2Params32) type {
159 // Append message length.159 // Append message length.
160 var i: usize = 1;160 var i: usize = 1;
161 var len = d.total_len >> 5;161 var len = d.total_len >> 5;
162 d.buf[63] = @intCast(u8, d.total_len & 0x1f) << 3;162 d.buf[63] = @as(u8, @intCast(d.total_len & 0x1f)) << 3;
163 while (i < 8) : (i += 1) {163 while (i < 8) : (i += 1) {
164 d.buf[63 - i] = @intCast(u8, len & 0xff);164 d.buf[63 - i] = @as(u8, @intCast(len & 0xff));
165 len >>= 8;165 len >>= 8;
166 }166 }
167167
...@@ -194,7 +194,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -194,7 +194,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
194194
195 fn round(d: *Self, b: *const [64]u8) void {195 fn round(d: *Self, b: *const [64]u8) void {
196 var s: [64]u32 align(16) = undefined;196 var s: [64]u32 align(16) = undefined;
197 for (@ptrCast(*align(1) const [16]u32, b), 0..) |*elem, i| {197 for (@as(*align(1) const [16]u32, @ptrCast(b)), 0..) |*elem, i| {
198 s[i] = mem.readIntBig(u32, mem.asBytes(elem));198 s[i] = mem.readIntBig(u32, mem.asBytes(elem));
199 }199 }
200200
...@@ -203,7 +203,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -203,7 +203,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
203 .aarch64 => if (builtin.zig_backend != .stage2_c and comptime std.Target.aarch64.featureSetHas(builtin.cpu.features, .sha2)) {203 .aarch64 => if (builtin.zig_backend != .stage2_c and comptime std.Target.aarch64.featureSetHas(builtin.cpu.features, .sha2)) {
204 var x: v4u32 = d.s[0..4].*;204 var x: v4u32 = d.s[0..4].*;
205 var y: v4u32 = d.s[4..8].*;205 var y: v4u32 = d.s[4..8].*;
206 const s_v = @ptrCast(*[16]v4u32, &s);206 const s_v = @as(*[16]v4u32, @ptrCast(&s));
207207
208 comptime var k: u8 = 0;208 comptime var k: u8 = 0;
209 inline while (k < 16) : (k += 1) {209 inline while (k < 16) : (k += 1) {
...@@ -241,7 +241,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -241,7 +241,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
241 .x86_64 => if (builtin.zig_backend != .stage2_c and comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sha)) {241 .x86_64 => if (builtin.zig_backend != .stage2_c and comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sha)) {
242 var x: v4u32 = [_]u32{ d.s[5], d.s[4], d.s[1], d.s[0] };242 var x: v4u32 = [_]u32{ d.s[5], d.s[4], d.s[1], d.s[0] };
243 var y: v4u32 = [_]u32{ d.s[7], d.s[6], d.s[3], d.s[2] };243 var y: v4u32 = [_]u32{ d.s[7], d.s[6], d.s[3], d.s[2] };
244 const s_v = @ptrCast(*[16]v4u32, &s);244 const s_v = @as(*[16]v4u32, @ptrCast(&s));
245245
246 comptime var k: u8 = 0;246 comptime var k: u8 = 0;
247 inline while (k < 16) : (k += 1) {247 inline while (k < 16) : (k += 1) {
...@@ -273,7 +273,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -273,7 +273,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
273 : [x] "=x" (-> v4u32),273 : [x] "=x" (-> v4u32),
274 : [_] "0" (x),274 : [_] "0" (x),
275 [y] "x" (y),275 [y] "x" (y),
276 [_] "{xmm0}" (@bitCast(v4u32, @bitCast(u128, w) >> 64)),276 [_] "{xmm0}" (@as(v4u32, @bitCast(@as(u128, @bitCast(w)) >> 64))),
277 );277 );
278 }278 }
279279
...@@ -624,7 +624,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {...@@ -624,7 +624,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
624 // Copy any remainder for next pass.624 // Copy any remainder for next pass.
625 const b_slice = b[off..];625 const b_slice = b[off..];
626 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);626 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
627 d.buf_len += @intCast(u8, b[off..].len);627 d.buf_len += @as(u8, @intCast(b[off..].len));
628628
629 d.total_len += b.len;629 d.total_len += b.len;
630 }630 }
...@@ -651,9 +651,9 @@ fn Sha2x64(comptime params: Sha2Params64) type {...@@ -651,9 +651,9 @@ fn Sha2x64(comptime params: Sha2Params64) type {
651 // Append message length.651 // Append message length.
652 var i: usize = 1;652 var i: usize = 1;
653 var len = d.total_len >> 5;653 var len = d.total_len >> 5;
654 d.buf[127] = @intCast(u8, d.total_len & 0x1f) << 3;654 d.buf[127] = @as(u8, @intCast(d.total_len & 0x1f)) << 3;
655 while (i < 16) : (i += 1) {655 while (i < 16) : (i += 1) {
656 d.buf[127 - i] = @intCast(u8, len & 0xff);656 d.buf[127 - i] = @as(u8, @intCast(len & 0xff));
657 len >>= 8;657 len >>= 8;
658 }658 }
659659
lib/std/crypto/siphash.zig+6-6
...@@ -83,13 +83,13 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round...@@ -83,13 +83,13 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round
83 @call(.always_inline, round, .{ self, blob });83 @call(.always_inline, round, .{ self, blob });
84 }84 }
8585
86 self.msg_len +%= @truncate(u8, b.len);86 self.msg_len +%= @as(u8, @truncate(b.len));
87 }87 }
8888
89 fn final(self: *Self, b: []const u8) T {89 fn final(self: *Self, b: []const u8) T {
90 std.debug.assert(b.len < 8);90 std.debug.assert(b.len < 8);
9191
92 self.msg_len +%= @truncate(u8, b.len);92 self.msg_len +%= @as(u8, @truncate(b.len));
9393
94 var buf = [_]u8{0} ** 8;94 var buf = [_]u8{0} ** 8;
95 @memcpy(buf[0..b.len], b);95 @memcpy(buf[0..b.len], b);
...@@ -202,7 +202,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)...@@ -202,7 +202,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
202202
203 const b_slice = b[off + aligned_len ..];203 const b_slice = b[off + aligned_len ..];
204 @memcpy(self.buf[self.buf_len..][0..b_slice.len], b_slice);204 @memcpy(self.buf[self.buf_len..][0..b_slice.len], b_slice);
205 self.buf_len += @intCast(u8, b_slice.len);205 self.buf_len += @as(u8, @intCast(b_slice.len));
206 }206 }
207207
208 pub fn peek(self: Self) [mac_length]u8 {208 pub fn peek(self: Self) [mac_length]u8 {
...@@ -329,7 +329,7 @@ test "siphash64-2-4 sanity" {...@@ -329,7 +329,7 @@ test "siphash64-2-4 sanity" {
329329
330 var buffer: [64]u8 = undefined;330 var buffer: [64]u8 = undefined;
331 for (vectors, 0..) |vector, i| {331 for (vectors, 0..) |vector, i| {
332 buffer[i] = @intCast(u8, i);332 buffer[i] = @as(u8, @intCast(i));
333333
334 var out: [siphash.mac_length]u8 = undefined;334 var out: [siphash.mac_length]u8 = undefined;
335 siphash.create(&out, buffer[0..i], test_key);335 siphash.create(&out, buffer[0..i], test_key);
...@@ -409,7 +409,7 @@ test "siphash128-2-4 sanity" {...@@ -409,7 +409,7 @@ test "siphash128-2-4 sanity" {
409409
410 var buffer: [64]u8 = undefined;410 var buffer: [64]u8 = undefined;
411 for (vectors, 0..) |vector, i| {411 for (vectors, 0..) |vector, i| {
412 buffer[i] = @intCast(u8, i);412 buffer[i] = @as(u8, @intCast(i));
413413
414 var out: [siphash.mac_length]u8 = undefined;414 var out: [siphash.mac_length]u8 = undefined;
415 siphash.create(&out, buffer[0..i], test_key[0..]);415 siphash.create(&out, buffer[0..i], test_key[0..]);
...@@ -420,7 +420,7 @@ test "siphash128-2-4 sanity" {...@@ -420,7 +420,7 @@ test "siphash128-2-4 sanity" {
420test "iterative non-divisible update" {420test "iterative non-divisible update" {
421 var buf: [1024]u8 = undefined;421 var buf: [1024]u8 = undefined;
422 for (&buf, 0..) |*e, i| {422 for (&buf, 0..) |*e, i| {
423 e.* = @truncate(u8, i);423 e.* = @as(u8, @truncate(i));
424 }424 }
425425
426 const key = "0x128dad08f12307";426 const key = "0x128dad08f12307";
lib/std/crypto/tlcsprng.zig+3-3
...@@ -102,7 +102,7 @@ fn tlsCsprngFill(_: *anyopaque, buffer: []u8) void {...@@ -102,7 +102,7 @@ fn tlsCsprngFill(_: *anyopaque, buffer: []u8) void {
102 wipe_mem = mem.asBytes(&S.buf);102 wipe_mem = mem.asBytes(&S.buf);
103 }103 }
104 }104 }
105 const ctx = @ptrCast(*Context, wipe_mem.ptr);105 const ctx = @as(*Context, @ptrCast(wipe_mem.ptr));
106106
107 switch (ctx.init_state) {107 switch (ctx.init_state) {
108 .uninitialized => {108 .uninitialized => {
...@@ -158,7 +158,7 @@ fn childAtForkHandler() callconv(.C) void {...@@ -158,7 +158,7 @@ fn childAtForkHandler() callconv(.C) void {
158}158}
159159
160fn fillWithCsprng(buffer: []u8) void {160fn fillWithCsprng(buffer: []u8) void {
161 const ctx = @ptrCast(*Context, wipe_mem.ptr);161 const ctx = @as(*Context, @ptrCast(wipe_mem.ptr));
162 return ctx.rng.fill(buffer);162 return ctx.rng.fill(buffer);
163}163}
164164
...@@ -174,7 +174,7 @@ fn initAndFill(buffer: []u8) void {...@@ -174,7 +174,7 @@ fn initAndFill(buffer: []u8) void {
174 // the `std.options.cryptoRandomSeed` function is provided.174 // the `std.options.cryptoRandomSeed` function is provided.
175 std.options.cryptoRandomSeed(&seed);175 std.options.cryptoRandomSeed(&seed);
176176
177 const ctx = @ptrCast(*Context, wipe_mem.ptr);177 const ctx = @as(*Context, @ptrCast(wipe_mem.ptr));
178 ctx.rng = Rng.init(seed);178 ctx.rng = Rng.init(seed);
179 std.crypto.utils.secureZero(u8, &seed);179 std.crypto.utils.secureZero(u8, &seed);
180180
lib/std/crypto/tls.zig+10-10
...@@ -371,12 +371,12 @@ pub fn hkdfExpandLabel(...@@ -371,12 +371,12 @@ pub fn hkdfExpandLabel(
371 const tls13 = "tls13 ";371 const tls13 = "tls13 ";
372 var buf: [2 + 1 + tls13.len + max_label_len + 1 + max_context_len]u8 = undefined;372 var buf: [2 + 1 + tls13.len + max_label_len + 1 + max_context_len]u8 = undefined;
373 mem.writeIntBig(u16, buf[0..2], len);373 mem.writeIntBig(u16, buf[0..2], len);
374 buf[2] = @intCast(u8, tls13.len + label.len);374 buf[2] = @as(u8, @intCast(tls13.len + label.len));
375 buf[3..][0..tls13.len].* = tls13.*;375 buf[3..][0..tls13.len].* = tls13.*;
376 var i: usize = 3 + tls13.len;376 var i: usize = 3 + tls13.len;
377 @memcpy(buf[i..][0..label.len], label);377 @memcpy(buf[i..][0..label.len], label);
378 i += label.len;378 i += label.len;
379 buf[i] = @intCast(u8, context.len);379 buf[i] = @as(u8, @intCast(context.len));
380 i += 1;380 i += 1;
381 @memcpy(buf[i..][0..context.len], context);381 @memcpy(buf[i..][0..context.len], context);
382 i += context.len;382 i += context.len;
...@@ -411,24 +411,24 @@ pub inline fn enum_array(comptime E: type, comptime tags: []const E) [2 + @sizeO...@@ -411,24 +411,24 @@ pub inline fn enum_array(comptime E: type, comptime tags: []const E) [2 + @sizeO
411 assert(@sizeOf(E) == 2);411 assert(@sizeOf(E) == 2);
412 var result: [tags.len * 2]u8 = undefined;412 var result: [tags.len * 2]u8 = undefined;
413 for (tags, 0..) |elem, i| {413 for (tags, 0..) |elem, i| {
414 result[i * 2] = @truncate(u8, @intFromEnum(elem) >> 8);414 result[i * 2] = @as(u8, @truncate(@intFromEnum(elem) >> 8));
415 result[i * 2 + 1] = @truncate(u8, @intFromEnum(elem));415 result[i * 2 + 1] = @as(u8, @truncate(@intFromEnum(elem)));
416 }416 }
417 return array(2, result);417 return array(2, result);
418}418}
419419
420pub inline fn int2(x: u16) [2]u8 {420pub inline fn int2(x: u16) [2]u8 {
421 return .{421 return .{
422 @truncate(u8, x >> 8),422 @as(u8, @truncate(x >> 8)),
423 @truncate(u8, x),423 @as(u8, @truncate(x)),
424 };424 };
425}425}
426426
427pub inline fn int3(x: u24) [3]u8 {427pub inline fn int3(x: u24) [3]u8 {
428 return .{428 return .{
429 @truncate(u8, x >> 16),429 @as(u8, @truncate(x >> 16)),
430 @truncate(u8, x >> 8),430 @as(u8, @truncate(x >> 8)),
431 @truncate(u8, x),431 @as(u8, @truncate(x)),
432 };432 };
433}433}
434434
...@@ -513,7 +513,7 @@ pub const Decoder = struct {...@@ -513,7 +513,7 @@ pub const Decoder = struct {
513 .Enum => |info| {513 .Enum => |info| {
514 const int = d.decode(info.tag_type);514 const int = d.decode(info.tag_type);
515 if (info.is_exhaustive) @compileError("exhaustive enum cannot be used");515 if (info.is_exhaustive) @compileError("exhaustive enum cannot be used");
516 return @enumFromInt(T, int);516 return @as(T, @enumFromInt(int));
517 },517 },
518 else => @compileError("unsupported type: " ++ @typeName(T)),518 else => @compileError("unsupported type: " ++ @typeName(T)),
519 }519 }
lib/std/crypto/tls/Client.zig+28-28
...@@ -140,7 +140,7 @@ pub fn InitError(comptime Stream: type) type {...@@ -140,7 +140,7 @@ pub fn InitError(comptime Stream: type) type {
140///140///
141/// `host` is only borrowed during this function call.141/// `host` is only borrowed during this function call.
142pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) InitError(@TypeOf(stream))!Client {142pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) InitError(@TypeOf(stream))!Client {
143 const host_len = @intCast(u16, host.len);143 const host_len = @as(u16, @intCast(host.len));
144144
145 var random_buffer: [128]u8 = undefined;145 var random_buffer: [128]u8 = undefined;
146 crypto.random.bytes(&random_buffer);146 crypto.random.bytes(&random_buffer);
...@@ -194,7 +194,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In...@@ -194,7 +194,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
194 int2(host_len);194 int2(host_len);
195195
196 const extensions_header =196 const extensions_header =
197 int2(@intCast(u16, extensions_payload.len + host_len)) ++197 int2(@as(u16, @intCast(extensions_payload.len + host_len))) ++
198 extensions_payload;198 extensions_payload;
199199
200 const legacy_compression_methods = 0x0100;200 const legacy_compression_methods = 0x0100;
...@@ -209,13 +209,13 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In...@@ -209,13 +209,13 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
209209
210 const out_handshake =210 const out_handshake =
211 [_]u8{@intFromEnum(tls.HandshakeType.client_hello)} ++211 [_]u8{@intFromEnum(tls.HandshakeType.client_hello)} ++
212 int3(@intCast(u24, client_hello.len + host_len)) ++212 int3(@as(u24, @intCast(client_hello.len + host_len))) ++
213 client_hello;213 client_hello;
214214
215 const plaintext_header = [_]u8{215 const plaintext_header = [_]u8{
216 @intFromEnum(tls.ContentType.handshake),216 @intFromEnum(tls.ContentType.handshake),
217 0x03, 0x01, // legacy_record_version217 0x03, 0x01, // legacy_record_version
218 } ++ int2(@intCast(u16, out_handshake.len + host_len)) ++ out_handshake;218 } ++ int2(@as(u16, @intCast(out_handshake.len + host_len))) ++ out_handshake;
219219
220 {220 {
221 var iovecs = [_]std.os.iovec_const{221 var iovecs = [_]std.os.iovec_const{
...@@ -457,7 +457,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In...@@ -457,7 +457,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
457 const auth_tag = record_decoder.array(P.AEAD.tag_length).*;457 const auth_tag = record_decoder.array(P.AEAD.tag_length).*;
458 const V = @Vector(P.AEAD.nonce_length, u8);458 const V = @Vector(P.AEAD.nonce_length, u8);
459 const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8);459 const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8);
460 const operand: V = pad ++ @bitCast([8]u8, big(read_seq));460 const operand: V = pad ++ @as([8]u8, @bitCast(big(read_seq)));
461 read_seq += 1;461 read_seq += 1;
462 const nonce = @as(V, p.server_handshake_iv) ^ operand;462 const nonce = @as(V, p.server_handshake_iv) ^ operand;
463 P.AEAD.decrypt(cleartext, ciphertext, auth_tag, record_header, nonce, p.server_handshake_key) catch463 P.AEAD.decrypt(cleartext, ciphertext, auth_tag, record_header, nonce, p.server_handshake_key) catch
...@@ -466,7 +466,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In...@@ -466,7 +466,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
466 },466 },
467 };467 };
468468
469 const inner_ct = @enumFromInt(tls.ContentType, cleartext[cleartext.len - 1]);469 const inner_ct = @as(tls.ContentType, @enumFromInt(cleartext[cleartext.len - 1]));
470 if (inner_ct != .handshake) return error.TlsUnexpectedMessage;470 if (inner_ct != .handshake) return error.TlsUnexpectedMessage;
471471
472 var ctd = tls.Decoder.fromTheirSlice(cleartext[0 .. cleartext.len - 1]);472 var ctd = tls.Decoder.fromTheirSlice(cleartext[0 .. cleartext.len - 1]);
...@@ -520,7 +520,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In...@@ -520,7 +520,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
520520
521 const subject_cert: Certificate = .{521 const subject_cert: Certificate = .{
522 .buffer = certd.buf,522 .buffer = certd.buf,
523 .index = @intCast(u32, certd.idx),523 .index = @as(u32, @intCast(certd.idx)),
524 };524 };
525 const subject = try subject_cert.parse();525 const subject = try subject_cert.parse();
526 if (cert_index == 0) {526 if (cert_index == 0) {
...@@ -534,7 +534,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In...@@ -534,7 +534,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
534 if (pub_key.len > main_cert_pub_key_buf.len)534 if (pub_key.len > main_cert_pub_key_buf.len)
535 return error.CertificatePublicKeyInvalid;535 return error.CertificatePublicKeyInvalid;
536 @memcpy(main_cert_pub_key_buf[0..pub_key.len], pub_key);536 @memcpy(main_cert_pub_key_buf[0..pub_key.len], pub_key);
537 main_cert_pub_key_len = @intCast(@TypeOf(main_cert_pub_key_len), pub_key.len);537 main_cert_pub_key_len = @as(@TypeOf(main_cert_pub_key_len), @intCast(pub_key.len));
538 } else {538 } else {
539 try prev_cert.verify(subject, now_sec);539 try prev_cert.verify(subject, now_sec);
540 }540 }
...@@ -679,7 +679,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In...@@ -679,7 +679,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
679 .write_seq = 0,679 .write_seq = 0,
680 .partial_cleartext_idx = 0,680 .partial_cleartext_idx = 0,
681 .partial_ciphertext_idx = 0,681 .partial_ciphertext_idx = 0,
682 .partial_ciphertext_end = @intCast(u15, leftover.len),682 .partial_ciphertext_end = @as(u15, @intCast(leftover.len)),
683 .received_close_notify = false,683 .received_close_notify = false,
684 .application_cipher = app_cipher,684 .application_cipher = app_cipher,
685 .partially_read_buffer = undefined,685 .partially_read_buffer = undefined,
...@@ -797,11 +797,11 @@ fn prepareCiphertextRecord(...@@ -797,11 +797,11 @@ fn prepareCiphertextRecord(
797 const overhead_len = tls.record_header_len + P.AEAD.tag_length + 1;797 const overhead_len = tls.record_header_len + P.AEAD.tag_length + 1;
798 const close_notify_alert_reserved = tls.close_notify_alert.len + overhead_len;798 const close_notify_alert_reserved = tls.close_notify_alert.len + overhead_len;
799 while (true) {799 while (true) {
800 const encrypted_content_len = @intCast(u16, @min(800 const encrypted_content_len = @as(u16, @intCast(@min(
801 @min(bytes.len - bytes_i, max_ciphertext_len - 1),801 @min(bytes.len - bytes_i, max_ciphertext_len - 1),
802 ciphertext_buf.len - close_notify_alert_reserved -802 ciphertext_buf.len - close_notify_alert_reserved -
803 overhead_len - ciphertext_end,803 overhead_len - ciphertext_end,
804 ));804 )));
805 if (encrypted_content_len == 0) return .{805 if (encrypted_content_len == 0) return .{
806 .iovec_end = iovec_end,806 .iovec_end = iovec_end,
807 .ciphertext_end = ciphertext_end,807 .ciphertext_end = ciphertext_end,
...@@ -826,7 +826,7 @@ fn prepareCiphertextRecord(...@@ -826,7 +826,7 @@ fn prepareCiphertextRecord(
826 const auth_tag = ciphertext_buf[ciphertext_end..][0..P.AEAD.tag_length];826 const auth_tag = ciphertext_buf[ciphertext_end..][0..P.AEAD.tag_length];
827 ciphertext_end += auth_tag.len;827 ciphertext_end += auth_tag.len;
828 const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8);828 const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8);
829 const operand: V = pad ++ @bitCast([8]u8, big(c.write_seq));829 const operand: V = pad ++ @as([8]u8, @bitCast(big(c.write_seq)));
830 c.write_seq += 1; // TODO send key_update on overflow830 c.write_seq += 1; // TODO send key_update on overflow
831 const nonce = @as(V, p.client_iv) ^ operand;831 const nonce = @as(V, p.client_iv) ^ operand;
832 P.AEAD.encrypt(ciphertext, auth_tag, cleartext, ad, nonce, p.client_key);832 P.AEAD.encrypt(ciphertext, auth_tag, cleartext, ad, nonce, p.client_key);
...@@ -920,7 +920,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)...@@ -920,7 +920,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
920 // Give away the buffered cleartext we have, if any.920 // Give away the buffered cleartext we have, if any.
921 const partial_cleartext = c.partially_read_buffer[c.partial_cleartext_idx..c.partial_ciphertext_idx];921 const partial_cleartext = c.partially_read_buffer[c.partial_cleartext_idx..c.partial_ciphertext_idx];
922 if (partial_cleartext.len > 0) {922 if (partial_cleartext.len > 0) {
923 const amt = @intCast(u15, vp.put(partial_cleartext));923 const amt = @as(u15, @intCast(vp.put(partial_cleartext)));
924 c.partial_cleartext_idx += amt;924 c.partial_cleartext_idx += amt;
925925
926 if (c.partial_cleartext_idx == c.partial_ciphertext_idx and926 if (c.partial_cleartext_idx == c.partial_ciphertext_idx and
...@@ -1037,7 +1037,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)...@@ -1037,7 +1037,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
1037 in = 0;1037 in = 0;
1038 continue;1038 continue;
1039 }1039 }
1040 const ct = @enumFromInt(tls.ContentType, frag[in]);1040 const ct = @as(tls.ContentType, @enumFromInt(frag[in]));
1041 in += 1;1041 in += 1;
1042 const legacy_version = mem.readIntBig(u16, frag[in..][0..2]);1042 const legacy_version = mem.readIntBig(u16, frag[in..][0..2]);
1043 in += 2;1043 in += 2;
...@@ -1070,8 +1070,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)...@@ -1070,8 +1070,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
1070 switch (ct) {1070 switch (ct) {
1071 .alert => {1071 .alert => {
1072 if (in + 2 > frag.len) return error.TlsDecodeError;1072 if (in + 2 > frag.len) return error.TlsDecodeError;
1073 const level = @enumFromInt(tls.AlertLevel, frag[in]);1073 const level = @as(tls.AlertLevel, @enumFromInt(frag[in]));
1074 const desc = @enumFromInt(tls.AlertDescription, frag[in + 1]);1074 const desc = @as(tls.AlertDescription, @enumFromInt(frag[in + 1]));
1075 _ = level;1075 _ = level;
10761076
1077 try desc.toError();1077 try desc.toError();
...@@ -1089,7 +1089,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)...@@ -1089,7 +1089,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
1089 in += ciphertext_len;1089 in += ciphertext_len;
1090 const auth_tag = frag[in..][0..P.AEAD.tag_length].*;1090 const auth_tag = frag[in..][0..P.AEAD.tag_length].*;
1091 const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8);1091 const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8);
1092 const operand: V = pad ++ @bitCast([8]u8, big(c.read_seq));1092 const operand: V = pad ++ @as([8]u8, @bitCast(big(c.read_seq)));
1093 const nonce: [P.AEAD.nonce_length]u8 = @as(V, p.server_iv) ^ operand;1093 const nonce: [P.AEAD.nonce_length]u8 = @as(V, p.server_iv) ^ operand;
1094 const out_buf = vp.peek();1094 const out_buf = vp.peek();
1095 const cleartext_buf = if (ciphertext.len <= out_buf.len)1095 const cleartext_buf = if (ciphertext.len <= out_buf.len)
...@@ -1105,11 +1105,11 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)...@@ -1105,11 +1105,11 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
11051105
1106 c.read_seq = try std.math.add(u64, c.read_seq, 1);1106 c.read_seq = try std.math.add(u64, c.read_seq, 1);
11071107
1108 const inner_ct = @enumFromInt(tls.ContentType, cleartext[cleartext.len - 1]);1108 const inner_ct = @as(tls.ContentType, @enumFromInt(cleartext[cleartext.len - 1]));
1109 switch (inner_ct) {1109 switch (inner_ct) {
1110 .alert => {1110 .alert => {
1111 const level = @enumFromInt(tls.AlertLevel, cleartext[0]);1111 const level = @as(tls.AlertLevel, @enumFromInt(cleartext[0]));
1112 const desc = @enumFromInt(tls.AlertDescription, cleartext[1]);1112 const desc = @as(tls.AlertDescription, @enumFromInt(cleartext[1]));
1113 if (desc == .close_notify) {1113 if (desc == .close_notify) {
1114 c.received_close_notify = true;1114 c.received_close_notify = true;
1115 c.partial_ciphertext_end = c.partial_ciphertext_idx;1115 c.partial_ciphertext_end = c.partial_ciphertext_idx;
...@@ -1124,7 +1124,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)...@@ -1124,7 +1124,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
1124 .handshake => {1124 .handshake => {
1125 var ct_i: usize = 0;1125 var ct_i: usize = 0;
1126 while (true) {1126 while (true) {
1127 const handshake_type = @enumFromInt(tls.HandshakeType, cleartext[ct_i]);1127 const handshake_type = @as(tls.HandshakeType, @enumFromInt(cleartext[ct_i]));
1128 ct_i += 1;1128 ct_i += 1;
1129 const handshake_len = mem.readIntBig(u24, cleartext[ct_i..][0..3]);1129 const handshake_len = mem.readIntBig(u24, cleartext[ct_i..][0..3]);
1130 ct_i += 3;1130 ct_i += 3;
...@@ -1148,7 +1148,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)...@@ -1148,7 +1148,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
1148 }1148 }
1149 c.read_seq = 0;1149 c.read_seq = 0;
11501150
1151 switch (@enumFromInt(tls.KeyUpdateRequest, handshake[0])) {1151 switch (@as(tls.KeyUpdateRequest, @enumFromInt(handshake[0]))) {
1152 .update_requested => {1152 .update_requested => {
1153 switch (c.application_cipher) {1153 switch (c.application_cipher) {
1154 inline else => |*p| {1154 inline else => |*p| {
...@@ -1186,13 +1186,13 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)...@@ -1186,13 +1186,13 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
1186 c.partially_read_buffer[c.partial_ciphertext_idx..][0..msg.len],1186 c.partially_read_buffer[c.partial_ciphertext_idx..][0..msg.len],
1187 msg,1187 msg,
1188 );1188 );
1189 c.partial_ciphertext_idx = @intCast(@TypeOf(c.partial_ciphertext_idx), c.partial_ciphertext_idx + msg.len);1189 c.partial_ciphertext_idx = @as(@TypeOf(c.partial_ciphertext_idx), @intCast(c.partial_ciphertext_idx + msg.len));
1190 } else {1190 } else {
1191 const amt = vp.put(msg);1191 const amt = vp.put(msg);
1192 if (amt < msg.len) {1192 if (amt < msg.len) {
1193 const rest = msg[amt..];1193 const rest = msg[amt..];
1194 c.partial_cleartext_idx = 0;1194 c.partial_cleartext_idx = 0;
1195 c.partial_ciphertext_idx = @intCast(@TypeOf(c.partial_ciphertext_idx), rest.len);1195 c.partial_ciphertext_idx = @as(@TypeOf(c.partial_ciphertext_idx), @intCast(rest.len));
1196 @memcpy(c.partially_read_buffer[0..rest.len], rest);1196 @memcpy(c.partially_read_buffer[0..rest.len], rest);
1197 }1197 }
1198 }1198 }
...@@ -1220,12 +1220,12 @@ fn finishRead(c: *Client, frag: []const u8, in: usize, out: usize) usize {...@@ -1220,12 +1220,12 @@ fn finishRead(c: *Client, frag: []const u8, in: usize, out: usize) usize {
1220 const saved_buf = frag[in..];1220 const saved_buf = frag[in..];
1221 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {1221 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {
1222 // There is cleartext at the beginning already which we need to preserve.1222 // There is cleartext at the beginning already which we need to preserve.
1223 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), c.partial_ciphertext_idx + saved_buf.len);1223 c.partial_ciphertext_end = @as(@TypeOf(c.partial_ciphertext_end), @intCast(c.partial_ciphertext_idx + saved_buf.len));
1224 @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx..][0..saved_buf.len], saved_buf);1224 @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx..][0..saved_buf.len], saved_buf);
1225 } else {1225 } else {
1226 c.partial_cleartext_idx = 0;1226 c.partial_cleartext_idx = 0;
1227 c.partial_ciphertext_idx = 0;1227 c.partial_ciphertext_idx = 0;
1228 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), saved_buf.len);1228 c.partial_ciphertext_end = @as(@TypeOf(c.partial_ciphertext_end), @intCast(saved_buf.len));
1229 @memcpy(c.partially_read_buffer[0..saved_buf.len], saved_buf);1229 @memcpy(c.partially_read_buffer[0..saved_buf.len], saved_buf);
1230 }1230 }
1231 return out;1231 return out;
...@@ -1235,14 +1235,14 @@ fn finishRead(c: *Client, frag: []const u8, in: usize, out: usize) usize {...@@ -1235,14 +1235,14 @@ fn finishRead(c: *Client, frag: []const u8, in: usize, out: usize) usize {
1235fn finishRead2(c: *Client, first: []const u8, frag1: []const u8, out: usize) usize {1235fn finishRead2(c: *Client, first: []const u8, frag1: []const u8, out: usize) usize {
1236 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {1236 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {
1237 // There is cleartext at the beginning already which we need to preserve.1237 // There is cleartext at the beginning already which we need to preserve.
1238 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), c.partial_ciphertext_idx + first.len + frag1.len);1238 c.partial_ciphertext_end = @as(@TypeOf(c.partial_ciphertext_end), @intCast(c.partial_ciphertext_idx + first.len + frag1.len));
1239 // TODO: eliminate this call to copyForwards1239 // TODO: eliminate this call to copyForwards
1240 std.mem.copyForwards(u8, c.partially_read_buffer[c.partial_ciphertext_idx..][0..first.len], first);1240 std.mem.copyForwards(u8, c.partially_read_buffer[c.partial_ciphertext_idx..][0..first.len], first);
1241 @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx + first.len ..][0..frag1.len], frag1);1241 @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx + first.len ..][0..frag1.len], frag1);
1242 } else {1242 } else {
1243 c.partial_cleartext_idx = 0;1243 c.partial_cleartext_idx = 0;
1244 c.partial_ciphertext_idx = 0;1244 c.partial_ciphertext_idx = 0;
1245 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), first.len + frag1.len);1245 c.partial_ciphertext_end = @as(@TypeOf(c.partial_ciphertext_end), @intCast(first.len + frag1.len));
1246 // TODO: eliminate this call to copyForwards1246 // TODO: eliminate this call to copyForwards
1247 std.mem.copyForwards(u8, c.partially_read_buffer[0..first.len], first);1247 std.mem.copyForwards(u8, c.partially_read_buffer[0..first.len], first);
1248 @memcpy(c.partially_read_buffer[first.len..][0..frag1.len], frag1);1248 @memcpy(c.partially_read_buffer[first.len..][0..frag1.len], frag1);
lib/std/crypto/utils.zig+8-8
...@@ -24,7 +24,7 @@ pub fn timingSafeEql(comptime T: type, a: T, b: T) bool {...@@ -24,7 +24,7 @@ pub fn timingSafeEql(comptime T: type, a: T, b: T) bool {
24 const s = @typeInfo(C).Int.bits;24 const s = @typeInfo(C).Int.bits;
25 const Cu = std.meta.Int(.unsigned, s);25 const Cu = std.meta.Int(.unsigned, s);
26 const Cext = std.meta.Int(.unsigned, s + 1);26 const Cext = std.meta.Int(.unsigned, s + 1);
27 return @bitCast(bool, @truncate(u1, (@as(Cext, @bitCast(Cu, acc)) -% 1) >> s));27 return @as(bool, @bitCast(@as(u1, @truncate((@as(Cext, @as(Cu, @bitCast(acc))) -% 1) >> s))));
28 },28 },
29 .Vector => |info| {29 .Vector => |info| {
30 const C = info.child;30 const C = info.child;
...@@ -35,7 +35,7 @@ pub fn timingSafeEql(comptime T: type, a: T, b: T) bool {...@@ -35,7 +35,7 @@ pub fn timingSafeEql(comptime T: type, a: T, b: T) bool {
35 const s = @typeInfo(C).Int.bits;35 const s = @typeInfo(C).Int.bits;
36 const Cu = std.meta.Int(.unsigned, s);36 const Cu = std.meta.Int(.unsigned, s);
37 const Cext = std.meta.Int(.unsigned, s + 1);37 const Cext = std.meta.Int(.unsigned, s + 1);
38 return @bitCast(bool, @truncate(u1, (@as(Cext, @bitCast(Cu, acc)) -% 1) >> s));38 return @as(bool, @bitCast(@as(u1, @truncate((@as(Cext, @as(Cu, @bitCast(acc))) -% 1) >> s))));
39 },39 },
40 else => {40 else => {
41 @compileError("Only arrays and vectors can be compared");41 @compileError("Only arrays and vectors can be compared");
...@@ -60,14 +60,14 @@ pub fn timingSafeCompare(comptime T: type, a: []const T, b: []const T, endian: E...@@ -60,14 +60,14 @@ pub fn timingSafeCompare(comptime T: type, a: []const T, b: []const T, endian: E
60 i -= 1;60 i -= 1;
61 const x1 = a[i];61 const x1 = a[i];
62 const x2 = b[i];62 const x2 = b[i];
63 gt |= @truncate(T, (@as(Cext, x2) -% @as(Cext, x1)) >> bits) & eq;63 gt |= @as(T, @truncate((@as(Cext, x2) -% @as(Cext, x1)) >> bits)) & eq;
64 eq &= @truncate(T, (@as(Cext, (x2 ^ x1)) -% 1) >> bits);64 eq &= @as(T, @truncate((@as(Cext, (x2 ^ x1)) -% 1) >> bits));
65 }65 }
66 } else {66 } else {
67 for (a, 0..) |x1, i| {67 for (a, 0..) |x1, i| {
68 const x2 = b[i];68 const x2 = b[i];
69 gt |= @truncate(T, (@as(Cext, x2) -% @as(Cext, x1)) >> bits) & eq;69 gt |= @as(T, @truncate((@as(Cext, x2) -% @as(Cext, x1)) >> bits)) & eq;
70 eq &= @truncate(T, (@as(Cext, (x2 ^ x1)) -% 1) >> bits);70 eq &= @as(T, @truncate((@as(Cext, (x2 ^ x1)) -% 1) >> bits));
71 }71 }
72 }72 }
73 if (gt != 0) {73 if (gt != 0) {
...@@ -102,7 +102,7 @@ pub fn timingSafeAdd(comptime T: type, a: []const T, b: []const T, result: []T,...@@ -102,7 +102,7 @@ pub fn timingSafeAdd(comptime T: type, a: []const T, b: []const T, result: []T,
102 carry = ov1[1] | ov2[1];102 carry = ov1[1] | ov2[1];
103 }103 }
104 }104 }
105 return @bitCast(bool, carry);105 return @as(bool, @bitCast(carry));
106}106}
107107
108/// Subtract two integers serialized as arrays of the same size, in constant time.108/// Subtract two integers serialized as arrays of the same size, in constant time.
...@@ -129,7 +129,7 @@ pub fn timingSafeSub(comptime T: type, a: []const T, b: []const T, result: []T,...@@ -129,7 +129,7 @@ pub fn timingSafeSub(comptime T: type, a: []const T, b: []const T, result: []T,
129 borrow = ov1[1] | ov2[1];129 borrow = ov1[1] | ov2[1];
130 }130 }
131 }131 }
132 return @bitCast(bool, borrow);132 return @as(bool, @bitCast(borrow));
133}133}
134134
135/// Sets a slice to zeroes.135/// Sets a slice to zeroes.
lib/std/cstr.zig+2-2
...@@ -89,12 +89,12 @@ pub const NullTerminated2DArray = struct {...@@ -89,12 +89,12 @@ pub const NullTerminated2DArray = struct {
89 return NullTerminated2DArray{89 return NullTerminated2DArray{
90 .allocator = allocator,90 .allocator = allocator,
91 .byte_count = byte_count,91 .byte_count = byte_count,
92 .ptr = @ptrCast(?[*:null]?[*:0]u8, buf.ptr),92 .ptr = @as(?[*:null]?[*:0]u8, @ptrCast(buf.ptr)),
93 };93 };
94 }94 }
9595
96 pub fn deinit(self: *NullTerminated2DArray) void {96 pub fn deinit(self: *NullTerminated2DArray) void {
97 const buf = @ptrCast([*]u8, self.ptr);97 const buf = @as([*]u8, @ptrCast(self.ptr));
98 self.allocator.free(buf[0..self.byte_count]);98 self.allocator.free(buf[0..self.byte_count]);
99 }99 }
100};100};
lib/std/debug.zig+53-63
...@@ -460,8 +460,8 @@ pub const StackIterator = struct {...@@ -460,8 +460,8 @@ pub const StackIterator = struct {
460 // We are unable to determine validity of memory for freestanding targets460 // We are unable to determine validity of memory for freestanding targets
461 if (native_os == .freestanding) return true;461 if (native_os == .freestanding) return true;
462462
463 const aligned_address = address & ~@intCast(usize, (mem.page_size - 1));463 const aligned_address = address & ~@as(usize, @intCast((mem.page_size - 1)));
464 const aligned_memory = @ptrFromInt([*]align(mem.page_size) u8, aligned_address)[0..mem.page_size];464 const aligned_memory = @as([*]align(mem.page_size) u8, @ptrFromInt(aligned_address))[0..mem.page_size];
465465
466 if (native_os != .windows) {466 if (native_os != .windows) {
467 if (native_os != .wasi) {467 if (native_os != .wasi) {
...@@ -511,7 +511,7 @@ pub const StackIterator = struct {...@@ -511,7 +511,7 @@ pub const StackIterator = struct {
511 if (fp == 0 or !mem.isAligned(fp, @alignOf(usize)) or !isValidMemory(fp))511 if (fp == 0 or !mem.isAligned(fp, @alignOf(usize)) or !isValidMemory(fp))
512 return null;512 return null;
513513
514 const new_fp = math.add(usize, @ptrFromInt(*const usize, fp).*, fp_bias) catch return null;514 const new_fp = math.add(usize, @as(*const usize, @ptrFromInt(fp)).*, fp_bias) catch return null;
515515
516 // Sanity check: the stack grows down thus all the parent frames must be516 // Sanity check: the stack grows down thus all the parent frames must be
517 // be at addresses that are greater (or equal) than the previous one.517 // be at addresses that are greater (or equal) than the previous one.
...@@ -520,9 +520,9 @@ pub const StackIterator = struct {...@@ -520,9 +520,9 @@ pub const StackIterator = struct {
520 if (new_fp != 0 and new_fp < self.fp)520 if (new_fp != 0 and new_fp < self.fp)
521 return null;521 return null;
522522
523 const new_pc = @ptrFromInt(523 const new_pc = @as(
524 *const usize,524 *const usize,
525 math.add(usize, fp, pc_offset) catch return null,525 @ptrFromInt(math.add(usize, fp, pc_offset) catch return null),
526 ).*;526 ).*;
527527
528 self.fp = new_fp;528 self.fp = new_fp;
...@@ -555,10 +555,10 @@ pub fn writeCurrentStackTrace(...@@ -555,10 +555,10 @@ pub fn writeCurrentStackTrace(
555pub noinline fn walkStackWindows(addresses: []usize) usize {555pub noinline fn walkStackWindows(addresses: []usize) usize {
556 if (builtin.cpu.arch == .x86) {556 if (builtin.cpu.arch == .x86) {
557 // RtlVirtualUnwind doesn't exist on x86557 // RtlVirtualUnwind doesn't exist on x86
558 return windows.ntdll.RtlCaptureStackBackTrace(0, addresses.len, @ptrCast(**anyopaque, addresses.ptr), null);558 return windows.ntdll.RtlCaptureStackBackTrace(0, addresses.len, @as(**anyopaque, @ptrCast(addresses.ptr)), null);
559 }559 }
560560
561 const tib = @ptrCast(*const windows.NT_TIB, &windows.teb().Reserved1);561 const tib = @as(*const windows.NT_TIB, @ptrCast(&windows.teb().Reserved1));
562562
563 var context: windows.CONTEXT = std.mem.zeroes(windows.CONTEXT);563 var context: windows.CONTEXT = std.mem.zeroes(windows.CONTEXT);
564 windows.ntdll.RtlCaptureContext(&context);564 windows.ntdll.RtlCaptureContext(&context);
...@@ -584,7 +584,7 @@ pub noinline fn walkStackWindows(addresses: []usize) usize {...@@ -584,7 +584,7 @@ pub noinline fn walkStackWindows(addresses: []usize) usize {
584 );584 );
585 } else {585 } else {
586 // leaf function586 // leaf function
587 context.setIp(@ptrFromInt(*u64, current_regs.sp).*);587 context.setIp(@as(*u64, @ptrFromInt(current_regs.sp)).*);
588 context.setSp(current_regs.sp + @sizeOf(usize));588 context.setSp(current_regs.sp + @sizeOf(usize));
589 }589 }
590590
...@@ -734,7 +734,7 @@ fn printLineInfo(...@@ -734,7 +734,7 @@ fn printLineInfo(
734 if (printLineFromFile(out_stream, li)) {734 if (printLineFromFile(out_stream, li)) {
735 if (li.column > 0) {735 if (li.column > 0) {
736 // The caret already takes one char736 // The caret already takes one char
737 const space_needed = @intCast(usize, li.column - 1);737 const space_needed = @as(usize, @intCast(li.column - 1));
738738
739 try out_stream.writeByteNTimes(' ', space_needed);739 try out_stream.writeByteNTimes(' ', space_needed);
740 try tty_config.setColor(out_stream, .green);740 try tty_config.setColor(out_stream, .green);
...@@ -883,7 +883,7 @@ fn chopSlice(ptr: []const u8, offset: u64, size: u64) error{Overflow}![]const u8...@@ -883,7 +883,7 @@ fn chopSlice(ptr: []const u8, offset: u64, size: u64) error{Overflow}![]const u8
883pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugInfo {883pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugInfo {
884 nosuspend {884 nosuspend {
885 const mapped_mem = try mapWholeFile(elf_file);885 const mapped_mem = try mapWholeFile(elf_file);
886 const hdr = @ptrCast(*const elf.Ehdr, &mapped_mem[0]);886 const hdr = @as(*const elf.Ehdr, @ptrCast(&mapped_mem[0]));
887 if (!mem.eql(u8, hdr.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic;887 if (!mem.eql(u8, hdr.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic;
888 if (hdr.e_ident[elf.EI_VERSION] != 1) return error.InvalidElfVersion;888 if (hdr.e_ident[elf.EI_VERSION] != 1) return error.InvalidElfVersion;
889889
...@@ -896,14 +896,13 @@ pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugIn...@@ -896,14 +896,13 @@ pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugIn
896896
897 const shoff = hdr.e_shoff;897 const shoff = hdr.e_shoff;
898 const str_section_off = shoff + @as(u64, hdr.e_shentsize) * @as(u64, hdr.e_shstrndx);898 const str_section_off = shoff + @as(u64, hdr.e_shentsize) * @as(u64, hdr.e_shstrndx);
899 const str_shdr = @ptrCast(899 const str_shdr: *const elf.Shdr = @ptrCast(@alignCast(
900 *const elf.Shdr,900 &mapped_mem[math.cast(usize, str_section_off) orelse return error.Overflow],
901 @alignCast(@alignOf(elf.Shdr), &mapped_mem[math.cast(usize, str_section_off) orelse return error.Overflow]),901 ));
902 );
903 const header_strings = mapped_mem[str_shdr.sh_offset .. str_shdr.sh_offset + str_shdr.sh_size];902 const header_strings = mapped_mem[str_shdr.sh_offset .. str_shdr.sh_offset + str_shdr.sh_size];
904 const shdrs = @ptrCast(903 const shdrs = @as(
905 [*]const elf.Shdr,904 [*]const elf.Shdr,
906 @alignCast(@alignOf(elf.Shdr), &mapped_mem[shoff]),905 @ptrCast(@alignCast(&mapped_mem[shoff])),
907 )[0..hdr.e_shnum];906 )[0..hdr.e_shnum];
908907
909 var opt_debug_info: ?[]const u8 = null;908 var opt_debug_info: ?[]const u8 = null;
...@@ -982,10 +981,7 @@ pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugIn...@@ -982,10 +981,7 @@ pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugIn
982fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugInfo {981fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugInfo {
983 const mapped_mem = try mapWholeFile(macho_file);982 const mapped_mem = try mapWholeFile(macho_file);
984983
985 const hdr = @ptrCast(984 const hdr: *const macho.mach_header_64 = @ptrCast(@alignCast(mapped_mem.ptr));
986 *const macho.mach_header_64,
987 @alignCast(@alignOf(macho.mach_header_64), mapped_mem.ptr),
988 );
989 if (hdr.magic != macho.MH_MAGIC_64)985 if (hdr.magic != macho.MH_MAGIC_64)
990 return error.InvalidDebugInfo;986 return error.InvalidDebugInfo;
991987
...@@ -998,9 +994,9 @@ fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugIn...@@ -998,9 +994,9 @@ fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugIn
998 else => {},994 else => {},
999 } else return error.MissingDebugInfo;995 } else return error.MissingDebugInfo;
1000996
1001 const syms = @ptrCast(997 const syms = @as(
1002 [*]const macho.nlist_64,998 [*]const macho.nlist_64,
1003 @alignCast(@alignOf(macho.nlist_64), &mapped_mem[symtab.symoff]),999 @ptrCast(@alignCast(&mapped_mem[symtab.symoff])),
1004 )[0..symtab.nsyms];1000 )[0..symtab.nsyms];
1005 const strings = mapped_mem[symtab.stroff..][0 .. symtab.strsize - 1 :0];1001 const strings = mapped_mem[symtab.stroff..][0 .. symtab.strsize - 1 :0];
10061002
...@@ -1055,7 +1051,7 @@ fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugIn...@@ -1055,7 +1051,7 @@ fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugIn
1055 },1051 },
1056 .fun_strx => {1052 .fun_strx => {
1057 state = .fun_size;1053 state = .fun_size;
1058 last_sym.size = @intCast(u32, sym.n_value);1054 last_sym.size = @as(u32, @intCast(sym.n_value));
1059 },1055 },
1060 else => return error.InvalidDebugInfo,1056 else => return error.InvalidDebugInfo,
1061 }1057 }
...@@ -1283,10 +1279,10 @@ pub const DebugInfo = struct {...@@ -1283,10 +1279,10 @@ pub const DebugInfo = struct {
12831279
1284 var it = macho.LoadCommandIterator{1280 var it = macho.LoadCommandIterator{
1285 .ncmds = header.ncmds,1281 .ncmds = header.ncmds,
1286 .buffer = @alignCast(@alignOf(u64), @ptrFromInt(1282 .buffer = @alignCast(@as(
1287 [*]u8,1283 [*]u8,
1288 @intFromPtr(header) + @sizeOf(macho.mach_header_64),1284 @ptrFromInt(@intFromPtr(header) + @sizeOf(macho.mach_header_64)),
1289 ))[0..header.sizeofcmds],1285 )[0..header.sizeofcmds]),
1290 };1286 };
1291 while (it.next()) |cmd| switch (cmd.cmd()) {1287 while (it.next()) |cmd| switch (cmd.cmd()) {
1292 .SEGMENT_64 => {1288 .SEGMENT_64 => {
...@@ -1332,7 +1328,7 @@ pub const DebugInfo = struct {...@@ -1332,7 +1328,7 @@ pub const DebugInfo = struct {
1332 return obj_di;1328 return obj_di;
1333 }1329 }
13341330
1335 const mapped_module = @ptrFromInt([*]const u8, module.base_address)[0..module.size];1331 const mapped_module = @as([*]const u8, @ptrFromInt(module.base_address))[0..module.size];
1336 const obj_di = try self.allocator.create(ModuleDebugInfo);1332 const obj_di = try self.allocator.create(ModuleDebugInfo);
1337 errdefer self.allocator.destroy(obj_di);1333 errdefer self.allocator.destroy(obj_di);
13381334
...@@ -1465,10 +1461,7 @@ pub const ModuleDebugInfo = switch (native_os) {...@@ -1465,10 +1461,7 @@ pub const ModuleDebugInfo = switch (native_os) {
1465 const o_file = try fs.cwd().openFile(o_file_path, .{ .intended_io_mode = .blocking });1461 const o_file = try fs.cwd().openFile(o_file_path, .{ .intended_io_mode = .blocking });
1466 const mapped_mem = try mapWholeFile(o_file);1462 const mapped_mem = try mapWholeFile(o_file);
14671463
1468 const hdr = @ptrCast(1464 const hdr: *const macho.mach_header_64 = @ptrCast(@alignCast(mapped_mem.ptr));
1469 *const macho.mach_header_64,
1470 @alignCast(@alignOf(macho.mach_header_64), mapped_mem.ptr),
1471 );
1472 if (hdr.magic != std.macho.MH_MAGIC_64)1465 if (hdr.magic != std.macho.MH_MAGIC_64)
1473 return error.InvalidDebugInfo;1466 return error.InvalidDebugInfo;
14741467
...@@ -1487,21 +1480,18 @@ pub const ModuleDebugInfo = switch (native_os) {...@@ -1487,21 +1480,18 @@ pub const ModuleDebugInfo = switch (native_os) {
1487 if (segcmd == null or symtabcmd == null) return error.MissingDebugInfo;1480 if (segcmd == null or symtabcmd == null) return error.MissingDebugInfo;
14881481
1489 // Parse symbols1482 // Parse symbols
1490 const strtab = @ptrCast(1483 const strtab = @as(
1491 [*]const u8,1484 [*]const u8,
1492 &mapped_mem[symtabcmd.?.stroff],1485 @ptrCast(&mapped_mem[symtabcmd.?.stroff]),
1493 )[0 .. symtabcmd.?.strsize - 1 :0];1486 )[0 .. symtabcmd.?.strsize - 1 :0];
1494 const symtab = @ptrCast(1487 const symtab = @as(
1495 [*]const macho.nlist_64,1488 [*]const macho.nlist_64,
1496 @alignCast(1489 @ptrCast(@alignCast(&mapped_mem[symtabcmd.?.symoff])),
1497 @alignOf(macho.nlist_64),
1498 &mapped_mem[symtabcmd.?.symoff],
1499 ),
1500 )[0..symtabcmd.?.nsyms];1490 )[0..symtabcmd.?.nsyms];
15011491
1502 // TODO handle tentative (common) symbols1492 // TODO handle tentative (common) symbols
1503 var addr_table = std.StringHashMap(u64).init(allocator);1493 var addr_table = std.StringHashMap(u64).init(allocator);
1504 try addr_table.ensureTotalCapacity(@intCast(u32, symtab.len));1494 try addr_table.ensureTotalCapacity(@as(u32, @intCast(symtab.len)));
1505 for (symtab) |sym| {1495 for (symtab) |sym| {
1506 if (sym.n_strx == 0) continue;1496 if (sym.n_strx == 0) continue;
1507 if (sym.undf() or sym.tentative() or sym.abs()) continue;1497 if (sym.undf() or sym.tentative() or sym.abs()) continue;
...@@ -1943,49 +1933,49 @@ fn dumpSegfaultInfoPosix(sig: i32, addr: usize, ctx_ptr: ?*const anyopaque) void...@@ -1943,49 +1933,49 @@ fn dumpSegfaultInfoPosix(sig: i32, addr: usize, ctx_ptr: ?*const anyopaque) void
19431933
1944 switch (native_arch) {1934 switch (native_arch) {
1945 .x86 => {1935 .x86 => {
1946 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));1936 const ctx: *const os.ucontext_t = @ptrCast(@alignCast(ctx_ptr));
1947 const ip = @intCast(usize, ctx.mcontext.gregs[os.REG.EIP]);1937 const ip = @as(usize, @intCast(ctx.mcontext.gregs[os.REG.EIP]));
1948 const bp = @intCast(usize, ctx.mcontext.gregs[os.REG.EBP]);1938 const bp = @as(usize, @intCast(ctx.mcontext.gregs[os.REG.EBP]));
1949 dumpStackTraceFromBase(bp, ip);1939 dumpStackTraceFromBase(bp, ip);
1950 },1940 },
1951 .x86_64 => {1941 .x86_64 => {
1952 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));1942 const ctx: *const os.ucontext_t = @ptrCast(@alignCast(ctx_ptr));
1953 const ip = switch (native_os) {1943 const ip = switch (native_os) {
1954 .linux, .netbsd, .solaris => @intCast(usize, ctx.mcontext.gregs[os.REG.RIP]),1944 .linux, .netbsd, .solaris => @as(usize, @intCast(ctx.mcontext.gregs[os.REG.RIP])),
1955 .freebsd => @intCast(usize, ctx.mcontext.rip),1945 .freebsd => @as(usize, @intCast(ctx.mcontext.rip)),
1956 .openbsd => @intCast(usize, ctx.sc_rip),1946 .openbsd => @as(usize, @intCast(ctx.sc_rip)),
1957 .macos => @intCast(usize, ctx.mcontext.ss.rip),1947 .macos => @as(usize, @intCast(ctx.mcontext.ss.rip)),
1958 else => unreachable,1948 else => unreachable,
1959 };1949 };
1960 const bp = switch (native_os) {1950 const bp = switch (native_os) {
1961 .linux, .netbsd, .solaris => @intCast(usize, ctx.mcontext.gregs[os.REG.RBP]),1951 .linux, .netbsd, .solaris => @as(usize, @intCast(ctx.mcontext.gregs[os.REG.RBP])),
1962 .openbsd => @intCast(usize, ctx.sc_rbp),1952 .openbsd => @as(usize, @intCast(ctx.sc_rbp)),
1963 .freebsd => @intCast(usize, ctx.mcontext.rbp),1953 .freebsd => @as(usize, @intCast(ctx.mcontext.rbp)),
1964 .macos => @intCast(usize, ctx.mcontext.ss.rbp),1954 .macos => @as(usize, @intCast(ctx.mcontext.ss.rbp)),
1965 else => unreachable,1955 else => unreachable,
1966 };1956 };
1967 dumpStackTraceFromBase(bp, ip);1957 dumpStackTraceFromBase(bp, ip);
1968 },1958 },
1969 .arm => {1959 .arm => {
1970 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));1960 const ctx: *const os.ucontext_t = @ptrCast(@alignCast(ctx_ptr));
1971 const ip = @intCast(usize, ctx.mcontext.arm_pc);1961 const ip = @as(usize, @intCast(ctx.mcontext.arm_pc));
1972 const bp = @intCast(usize, ctx.mcontext.arm_fp);1962 const bp = @as(usize, @intCast(ctx.mcontext.arm_fp));
1973 dumpStackTraceFromBase(bp, ip);1963 dumpStackTraceFromBase(bp, ip);
1974 },1964 },
1975 .aarch64 => {1965 .aarch64 => {
1976 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));1966 const ctx: *const os.ucontext_t = @ptrCast(@alignCast(ctx_ptr));
1977 const ip = switch (native_os) {1967 const ip = switch (native_os) {
1978 .macos => @intCast(usize, ctx.mcontext.ss.pc),1968 .macos => @as(usize, @intCast(ctx.mcontext.ss.pc)),
1979 .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.PC]),1969 .netbsd => @as(usize, @intCast(ctx.mcontext.gregs[os.REG.PC])),
1980 .freebsd => @intCast(usize, ctx.mcontext.gpregs.elr),1970 .freebsd => @as(usize, @intCast(ctx.mcontext.gpregs.elr)),
1981 else => @intCast(usize, ctx.mcontext.pc),1971 else => @as(usize, @intCast(ctx.mcontext.pc)),
1982 };1972 };
1983 // x29 is the ABI-designated frame pointer1973 // x29 is the ABI-designated frame pointer
1984 const bp = switch (native_os) {1974 const bp = switch (native_os) {
1985 .macos => @intCast(usize, ctx.mcontext.ss.fp),1975 .macos => @as(usize, @intCast(ctx.mcontext.ss.fp)),
1986 .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.FP]),1976 .netbsd => @as(usize, @intCast(ctx.mcontext.gregs[os.REG.FP])),
1987 .freebsd => @intCast(usize, ctx.mcontext.gpregs.x[os.REG.FP]),1977 .freebsd => @as(usize, @intCast(ctx.mcontext.gpregs.x[os.REG.FP])),
1988 else => @intCast(usize, ctx.mcontext.regs[29]),1978 else => @as(usize, @intCast(ctx.mcontext.regs[29])),
1989 };1979 };
1990 dumpStackTraceFromBase(bp, ip);1980 dumpStackTraceFromBase(bp, ip);
1991 },1981 },
lib/std/dwarf.zig+6-6
...@@ -462,7 +462,7 @@ const LineNumberProgram = struct {...@@ -462,7 +462,7 @@ const LineNumberProgram = struct {
462 });462 });
463463
464 return debug.LineInfo{464 return debug.LineInfo{
465 .line = if (self.prev_line >= 0) @intCast(u64, self.prev_line) else 0,465 .line = if (self.prev_line >= 0) @as(u64, @intCast(self.prev_line)) else 0,
466 .column = self.prev_column,466 .column = self.prev_column,
467 .file_name = file_name,467 .file_name = file_name,
468 };468 };
...@@ -533,7 +533,7 @@ fn parseFormValueConstant(in_stream: anytype, signed: bool, endian: std.builtin....@@ -533,7 +533,7 @@ fn parseFormValueConstant(in_stream: anytype, signed: bool, endian: std.builtin.
533 -1 => blk: {533 -1 => blk: {
534 if (signed) {534 if (signed) {
535 const x = try nosuspend leb.readILEB128(i64, in_stream);535 const x = try nosuspend leb.readILEB128(i64, in_stream);
536 break :blk @bitCast(u64, x);536 break :blk @as(u64, @bitCast(x));
537 } else {537 } else {
538 const x = try nosuspend leb.readULEB128(u64, in_stream);538 const x = try nosuspend leb.readULEB128(u64, in_stream);
539 break :blk x;539 break :blk x;
...@@ -939,12 +939,12 @@ pub const DwarfInfo = struct {...@@ -939,12 +939,12 @@ pub const DwarfInfo = struct {
939 .Const => |c| try c.asUnsignedLe(),939 .Const => |c| try c.asUnsignedLe(),
940 .RangeListOffset => |idx| off: {940 .RangeListOffset => |idx| off: {
941 if (compile_unit.is_64) {941 if (compile_unit.is_64) {
942 const offset_loc = @intCast(usize, compile_unit.rnglists_base + 8 * idx);942 const offset_loc = @as(usize, @intCast(compile_unit.rnglists_base + 8 * idx));
943 if (offset_loc + 8 > debug_ranges.len) return badDwarf();943 if (offset_loc + 8 > debug_ranges.len) return badDwarf();
944 const offset = mem.readInt(u64, debug_ranges[offset_loc..][0..8], di.endian);944 const offset = mem.readInt(u64, debug_ranges[offset_loc..][0..8], di.endian);
945 break :off compile_unit.rnglists_base + offset;945 break :off compile_unit.rnglists_base + offset;
946 } else {946 } else {
947 const offset_loc = @intCast(usize, compile_unit.rnglists_base + 4 * idx);947 const offset_loc = @as(usize, @intCast(compile_unit.rnglists_base + 4 * idx));
948 if (offset_loc + 4 > debug_ranges.len) return badDwarf();948 if (offset_loc + 4 > debug_ranges.len) return badDwarf();
949 const offset = mem.readInt(u32, debug_ranges[offset_loc..][0..4], di.endian);949 const offset = mem.readInt(u32, debug_ranges[offset_loc..][0..4], di.endian);
950 break :off compile_unit.rnglists_base + offset;950 break :off compile_unit.rnglists_base + offset;
...@@ -1134,7 +1134,7 @@ pub const DwarfInfo = struct {...@@ -1134,7 +1134,7 @@ pub const DwarfInfo = struct {
1134 ),1134 ),
1135 };1135 };
1136 if (attr.form_id == FORM.implicit_const) {1136 if (attr.form_id == FORM.implicit_const) {
1137 result.attrs.items[i].value.Const.payload = @bitCast(u64, attr.payload);1137 result.attrs.items[i].value.Const.payload = @as(u64, @bitCast(attr.payload));
1138 }1138 }
1139 }1139 }
1140 return result;1140 return result;
...@@ -1438,7 +1438,7 @@ pub const DwarfInfo = struct {...@@ -1438,7 +1438,7 @@ pub const DwarfInfo = struct {
1438 const addr_size = debug_addr[compile_unit.addr_base - 2];1438 const addr_size = debug_addr[compile_unit.addr_base - 2];
1439 const seg_size = debug_addr[compile_unit.addr_base - 1];1439 const seg_size = debug_addr[compile_unit.addr_base - 1];
14401440
1441 const byte_offset = @intCast(usize, compile_unit.addr_base + (addr_size + seg_size) * index);1441 const byte_offset = @as(usize, @intCast(compile_unit.addr_base + (addr_size + seg_size) * index));
1442 if (byte_offset + addr_size > debug_addr.len) return badDwarf();1442 if (byte_offset + addr_size > debug_addr.len) return badDwarf();
1443 return switch (addr_size) {1443 return switch (addr_size) {
1444 1 => debug_addr[byte_offset],1444 1 => debug_addr[byte_offset],
lib/std/dynamic_library.zig+21-21
...@@ -71,18 +71,18 @@ pub fn linkmap_iterator(phdrs: []elf.Phdr) !LinkMap.Iterator {...@@ -71,18 +71,18 @@ pub fn linkmap_iterator(phdrs: []elf.Phdr) !LinkMap.Iterator {
71 while (_DYNAMIC[i].d_tag != elf.DT_NULL) : (i += 1) {71 while (_DYNAMIC[i].d_tag != elf.DT_NULL) : (i += 1) {
72 switch (_DYNAMIC[i].d_tag) {72 switch (_DYNAMIC[i].d_tag) {
73 elf.DT_DEBUG => {73 elf.DT_DEBUG => {
74 const ptr = @ptrFromInt(?*RDebug, _DYNAMIC[i].d_val);74 const ptr = @as(?*RDebug, @ptrFromInt(_DYNAMIC[i].d_val));
75 if (ptr) |r_debug| {75 if (ptr) |r_debug| {
76 if (r_debug.r_version != 1) return error.InvalidExe;76 if (r_debug.r_version != 1) return error.InvalidExe;
77 break :init r_debug.r_map;77 break :init r_debug.r_map;
78 }78 }
79 },79 },
80 elf.DT_PLTGOT => {80 elf.DT_PLTGOT => {
81 const ptr = @ptrFromInt(?[*]usize, _DYNAMIC[i].d_val);81 const ptr = @as(?[*]usize, @ptrFromInt(_DYNAMIC[i].d_val));
82 if (ptr) |got_table| {82 if (ptr) |got_table| {
83 // The address to the link_map structure is stored in83 // The address to the link_map structure is stored in
84 // the second slot84 // the second slot
85 break :init @ptrFromInt(?*LinkMap, got_table[1]);85 break :init @as(?*LinkMap, @ptrFromInt(got_table[1]));
86 }86 }
87 },87 },
88 else => {},88 else => {},
...@@ -132,7 +132,7 @@ pub const ElfDynLib = struct {...@@ -132,7 +132,7 @@ pub const ElfDynLib = struct {
132 );132 );
133 defer os.munmap(file_bytes);133 defer os.munmap(file_bytes);
134134
135 const eh = @ptrCast(*elf.Ehdr, file_bytes.ptr);135 const eh = @as(*elf.Ehdr, @ptrCast(file_bytes.ptr));
136 if (!mem.eql(u8, eh.e_ident[0..4], elf.MAGIC)) return error.NotElfFile;136 if (!mem.eql(u8, eh.e_ident[0..4], elf.MAGIC)) return error.NotElfFile;
137 if (eh.e_type != elf.ET.DYN) return error.NotDynamicLibrary;137 if (eh.e_type != elf.ET.DYN) return error.NotDynamicLibrary;
138138
...@@ -149,10 +149,10 @@ pub const ElfDynLib = struct {...@@ -149,10 +149,10 @@ pub const ElfDynLib = struct {
149 i += 1;149 i += 1;
150 ph_addr += eh.e_phentsize;150 ph_addr += eh.e_phentsize;
151 }) {151 }) {
152 const ph = @ptrFromInt(*elf.Phdr, ph_addr);152 const ph = @as(*elf.Phdr, @ptrFromInt(ph_addr));
153 switch (ph.p_type) {153 switch (ph.p_type) {
154 elf.PT_LOAD => virt_addr_end = @max(virt_addr_end, ph.p_vaddr + ph.p_memsz),154 elf.PT_LOAD => virt_addr_end = @max(virt_addr_end, ph.p_vaddr + ph.p_memsz),
155 elf.PT_DYNAMIC => maybe_dynv = @ptrFromInt([*]usize, elf_addr + ph.p_offset),155 elf.PT_DYNAMIC => maybe_dynv = @as([*]usize, @ptrFromInt(elf_addr + ph.p_offset)),
156 else => {},156 else => {},
157 }157 }
158 }158 }
...@@ -180,7 +180,7 @@ pub const ElfDynLib = struct {...@@ -180,7 +180,7 @@ pub const ElfDynLib = struct {
180 i += 1;180 i += 1;
181 ph_addr += eh.e_phentsize;181 ph_addr += eh.e_phentsize;
182 }) {182 }) {
183 const ph = @ptrFromInt(*elf.Phdr, ph_addr);183 const ph = @as(*elf.Phdr, @ptrFromInt(ph_addr));
184 switch (ph.p_type) {184 switch (ph.p_type) {
185 elf.PT_LOAD => {185 elf.PT_LOAD => {
186 // The VirtAddr may not be page-aligned; in such case there will be186 // The VirtAddr may not be page-aligned; in such case there will be
...@@ -188,7 +188,7 @@ pub const ElfDynLib = struct {...@@ -188,7 +188,7 @@ pub const ElfDynLib = struct {
188 const aligned_addr = (base + ph.p_vaddr) & ~(@as(usize, mem.page_size) - 1);188 const aligned_addr = (base + ph.p_vaddr) & ~(@as(usize, mem.page_size) - 1);
189 const extra_bytes = (base + ph.p_vaddr) - aligned_addr;189 const extra_bytes = (base + ph.p_vaddr) - aligned_addr;
190 const extended_memsz = mem.alignForward(usize, ph.p_memsz + extra_bytes, mem.page_size);190 const extended_memsz = mem.alignForward(usize, ph.p_memsz + extra_bytes, mem.page_size);
191 const ptr = @ptrFromInt([*]align(mem.page_size) u8, aligned_addr);191 const ptr = @as([*]align(mem.page_size) u8, @ptrFromInt(aligned_addr));
192 const prot = elfToMmapProt(ph.p_flags);192 const prot = elfToMmapProt(ph.p_flags);
193 if ((ph.p_flags & elf.PF_W) == 0) {193 if ((ph.p_flags & elf.PF_W) == 0) {
194 // If it does not need write access, it can be mapped from the fd.194 // If it does not need write access, it can be mapped from the fd.
...@@ -228,11 +228,11 @@ pub const ElfDynLib = struct {...@@ -228,11 +228,11 @@ pub const ElfDynLib = struct {
228 while (dynv[i] != 0) : (i += 2) {228 while (dynv[i] != 0) : (i += 2) {
229 const p = base + dynv[i + 1];229 const p = base + dynv[i + 1];
230 switch (dynv[i]) {230 switch (dynv[i]) {
231 elf.DT_STRTAB => maybe_strings = @ptrFromInt([*:0]u8, p),231 elf.DT_STRTAB => maybe_strings = @as([*:0]u8, @ptrFromInt(p)),
232 elf.DT_SYMTAB => maybe_syms = @ptrFromInt([*]elf.Sym, p),232 elf.DT_SYMTAB => maybe_syms = @as([*]elf.Sym, @ptrFromInt(p)),
233 elf.DT_HASH => maybe_hashtab = @ptrFromInt([*]os.Elf_Symndx, p),233 elf.DT_HASH => maybe_hashtab = @as([*]os.Elf_Symndx, @ptrFromInt(p)),
234 elf.DT_VERSYM => maybe_versym = @ptrFromInt([*]u16, p),234 elf.DT_VERSYM => maybe_versym = @as([*]u16, @ptrFromInt(p)),
235 elf.DT_VERDEF => maybe_verdef = @ptrFromInt(*elf.Verdef, p),235 elf.DT_VERDEF => maybe_verdef = @as(*elf.Verdef, @ptrFromInt(p)),
236 else => {},236 else => {},
237 }237 }
238 }238 }
...@@ -261,7 +261,7 @@ pub const ElfDynLib = struct {...@@ -261,7 +261,7 @@ pub const ElfDynLib = struct {
261261
262 pub fn lookup(self: *ElfDynLib, comptime T: type, name: [:0]const u8) ?T {262 pub fn lookup(self: *ElfDynLib, comptime T: type, name: [:0]const u8) ?T {
263 if (self.lookupAddress("", name)) |symbol| {263 if (self.lookupAddress("", name)) |symbol| {
264 return @ptrFromInt(T, symbol);264 return @as(T, @ptrFromInt(symbol));
265 } else {265 } else {
266 return null;266 return null;
267 }267 }
...@@ -276,8 +276,8 @@ pub const ElfDynLib = struct {...@@ -276,8 +276,8 @@ pub const ElfDynLib = struct {
276276
277 var i: usize = 0;277 var i: usize = 0;
278 while (i < self.hashtab[1]) : (i += 1) {278 while (i < self.hashtab[1]) : (i += 1) {
279 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue;279 if (0 == (@as(u32, 1) << @as(u5, @intCast(self.syms[i].st_info & 0xf)) & OK_TYPES)) continue;
280 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue;280 if (0 == (@as(u32, 1) << @as(u5, @intCast(self.syms[i].st_info >> 4)) & OK_BINDS)) continue;
281 if (0 == self.syms[i].st_shndx) continue;281 if (0 == self.syms[i].st_shndx) continue;
282 if (!mem.eql(u8, name, mem.sliceTo(self.strings + self.syms[i].st_name, 0))) continue;282 if (!mem.eql(u8, name, mem.sliceTo(self.strings + self.syms[i].st_name, 0))) continue;
283 if (maybe_versym) |versym| {283 if (maybe_versym) |versym| {
...@@ -301,15 +301,15 @@ pub const ElfDynLib = struct {...@@ -301,15 +301,15 @@ pub const ElfDynLib = struct {
301301
302fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [*:0]u8) bool {302fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [*:0]u8) bool {
303 var def = def_arg;303 var def = def_arg;
304 const vsym = @bitCast(u32, vsym_arg) & 0x7fff;304 const vsym = @as(u32, @bitCast(vsym_arg)) & 0x7fff;
305 while (true) {305 while (true) {
306 if (0 == (def.vd_flags & elf.VER_FLG_BASE) and (def.vd_ndx & 0x7fff) == vsym)306 if (0 == (def.vd_flags & elf.VER_FLG_BASE) and (def.vd_ndx & 0x7fff) == vsym)
307 break;307 break;
308 if (def.vd_next == 0)308 if (def.vd_next == 0)
309 return false;309 return false;
310 def = @ptrFromInt(*elf.Verdef, @intFromPtr(def) + def.vd_next);310 def = @as(*elf.Verdef, @ptrFromInt(@intFromPtr(def) + def.vd_next));
311 }311 }
312 const aux = @ptrFromInt(*elf.Verdaux, @intFromPtr(def) + def.vd_aux);312 const aux = @as(*elf.Verdaux, @ptrFromInt(@intFromPtr(def) + def.vd_aux));
313 return mem.eql(u8, vername, mem.sliceTo(strings + aux.vda_name, 0));313 return mem.eql(u8, vername, mem.sliceTo(strings + aux.vda_name, 0));
314}314}
315315
...@@ -347,7 +347,7 @@ pub const WindowsDynLib = struct {...@@ -347,7 +347,7 @@ pub const WindowsDynLib = struct {
347347
348 pub fn lookup(self: *WindowsDynLib, comptime T: type, name: [:0]const u8) ?T {348 pub fn lookup(self: *WindowsDynLib, comptime T: type, name: [:0]const u8) ?T {
349 if (windows.kernel32.GetProcAddress(self.dll, name.ptr)) |addr| {349 if (windows.kernel32.GetProcAddress(self.dll, name.ptr)) |addr| {
350 return @ptrCast(T, @alignCast(@alignOf(@typeInfo(T).Pointer.child), addr));350 return @as(T, @ptrCast(@alignCast(addr)));
351 } else {351 } else {
352 return null;352 return null;
353 }353 }
...@@ -381,7 +381,7 @@ pub const DlDynlib = struct {...@@ -381,7 +381,7 @@ pub const DlDynlib = struct {
381 // dlsym (and other dl-functions) secretly take shadow parameter - return address on stack381 // dlsym (and other dl-functions) secretly take shadow parameter - return address on stack
382 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66826382 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66826
383 if (@call(.never_tail, system.dlsym, .{ self.handle, name.ptr })) |symbol| {383 if (@call(.never_tail, system.dlsym, .{ self.handle, name.ptr })) |symbol| {
384 return @ptrCast(T, @alignCast(@alignOf(@typeInfo(T).Pointer.child), symbol));384 return @as(T, @ptrCast(@alignCast(symbol)));
385 } else {385 } else {
386 return null;386 return null;
387 }387 }
lib/std/elf.zig+15-15
...@@ -434,8 +434,8 @@ pub const Header = struct {...@@ -434,8 +434,8 @@ pub const Header = struct {
434 }434 }
435435
436 pub fn parse(hdr_buf: *align(@alignOf(Elf64_Ehdr)) const [@sizeOf(Elf64_Ehdr)]u8) !Header {436 pub fn parse(hdr_buf: *align(@alignOf(Elf64_Ehdr)) const [@sizeOf(Elf64_Ehdr)]u8) !Header {
437 const hdr32 = @ptrCast(*const Elf32_Ehdr, hdr_buf);437 const hdr32 = @as(*const Elf32_Ehdr, @ptrCast(hdr_buf));
438 const hdr64 = @ptrCast(*const Elf64_Ehdr, hdr_buf);438 const hdr64 = @as(*const Elf64_Ehdr, @ptrCast(hdr_buf));
439 if (!mem.eql(u8, hdr32.e_ident[0..4], MAGIC)) return error.InvalidElfMagic;439 if (!mem.eql(u8, hdr32.e_ident[0..4], MAGIC)) return error.InvalidElfMagic;
440 if (hdr32.e_ident[EI_VERSION] != 1) return error.InvalidElfVersion;440 if (hdr32.e_ident[EI_VERSION] != 1) return error.InvalidElfVersion;
441441
...@@ -454,7 +454,7 @@ pub const Header = struct {...@@ -454,7 +454,7 @@ pub const Header = struct {
454454
455 const machine = if (need_bswap) blk: {455 const machine = if (need_bswap) blk: {
456 const value = @intFromEnum(hdr32.e_machine);456 const value = @intFromEnum(hdr32.e_machine);
457 break :blk @enumFromInt(EM, @byteSwap(value));457 break :blk @as(EM, @enumFromInt(@byteSwap(value)));
458 } else hdr32.e_machine;458 } else hdr32.e_machine;
459459
460 return @as(Header, .{460 return @as(Header, .{
...@@ -725,10 +725,10 @@ pub const Elf32_Sym = extern struct {...@@ -725,10 +725,10 @@ pub const Elf32_Sym = extern struct {
725 st_shndx: Elf32_Section,725 st_shndx: Elf32_Section,
726726
727 pub inline fn st_type(self: @This()) u4 {727 pub inline fn st_type(self: @This()) u4 {
728 return @truncate(u4, self.st_info);728 return @as(u4, @truncate(self.st_info));
729 }729 }
730 pub inline fn st_bind(self: @This()) u4 {730 pub inline fn st_bind(self: @This()) u4 {
731 return @truncate(u4, self.st_info >> 4);731 return @as(u4, @truncate(self.st_info >> 4));
732 }732 }
733};733};
734pub const Elf64_Sym = extern struct {734pub const Elf64_Sym = extern struct {
...@@ -740,10 +740,10 @@ pub const Elf64_Sym = extern struct {...@@ -740,10 +740,10 @@ pub const Elf64_Sym = extern struct {
740 st_size: Elf64_Xword,740 st_size: Elf64_Xword,
741741
742 pub inline fn st_type(self: @This()) u4 {742 pub inline fn st_type(self: @This()) u4 {
743 return @truncate(u4, self.st_info);743 return @as(u4, @truncate(self.st_info));
744 }744 }
745 pub inline fn st_bind(self: @This()) u4 {745 pub inline fn st_bind(self: @This()) u4 {
746 return @truncate(u4, self.st_info >> 4);746 return @as(u4, @truncate(self.st_info >> 4));
747 }747 }
748};748};
749pub const Elf32_Syminfo = extern struct {749pub const Elf32_Syminfo = extern struct {
...@@ -759,10 +759,10 @@ pub const Elf32_Rel = extern struct {...@@ -759,10 +759,10 @@ pub const Elf32_Rel = extern struct {
759 r_info: Elf32_Word,759 r_info: Elf32_Word,
760760
761 pub inline fn r_sym(self: @This()) u24 {761 pub inline fn r_sym(self: @This()) u24 {
762 return @truncate(u24, self.r_info >> 8);762 return @as(u24, @truncate(self.r_info >> 8));
763 }763 }
764 pub inline fn r_type(self: @This()) u8 {764 pub inline fn r_type(self: @This()) u8 {
765 return @truncate(u8, self.r_info);765 return @as(u8, @truncate(self.r_info));
766 }766 }
767};767};
768pub const Elf64_Rel = extern struct {768pub const Elf64_Rel = extern struct {
...@@ -770,10 +770,10 @@ pub const Elf64_Rel = extern struct {...@@ -770,10 +770,10 @@ pub const Elf64_Rel = extern struct {
770 r_info: Elf64_Xword,770 r_info: Elf64_Xword,
771771
772 pub inline fn r_sym(self: @This()) u32 {772 pub inline fn r_sym(self: @This()) u32 {
773 return @truncate(u32, self.r_info >> 32);773 return @as(u32, @truncate(self.r_info >> 32));
774 }774 }
775 pub inline fn r_type(self: @This()) u32 {775 pub inline fn r_type(self: @This()) u32 {
776 return @truncate(u32, self.r_info);776 return @as(u32, @truncate(self.r_info));
777 }777 }
778};778};
779pub const Elf32_Rela = extern struct {779pub const Elf32_Rela = extern struct {
...@@ -782,10 +782,10 @@ pub const Elf32_Rela = extern struct {...@@ -782,10 +782,10 @@ pub const Elf32_Rela = extern struct {
782 r_addend: Elf32_Sword,782 r_addend: Elf32_Sword,
783783
784 pub inline fn r_sym(self: @This()) u24 {784 pub inline fn r_sym(self: @This()) u24 {
785 return @truncate(u24, self.r_info >> 8);785 return @as(u24, @truncate(self.r_info >> 8));
786 }786 }
787 pub inline fn r_type(self: @This()) u8 {787 pub inline fn r_type(self: @This()) u8 {
788 return @truncate(u8, self.r_info);788 return @as(u8, @truncate(self.r_info));
789 }789 }
790};790};
791pub const Elf64_Rela = extern struct {791pub const Elf64_Rela = extern struct {
...@@ -794,10 +794,10 @@ pub const Elf64_Rela = extern struct {...@@ -794,10 +794,10 @@ pub const Elf64_Rela = extern struct {
794 r_addend: Elf64_Sxword,794 r_addend: Elf64_Sxword,
795795
796 pub inline fn r_sym(self: @This()) u32 {796 pub inline fn r_sym(self: @This()) u32 {
797 return @truncate(u32, self.r_info >> 32);797 return @as(u32, @truncate(self.r_info >> 32));
798 }798 }
799 pub inline fn r_type(self: @This()) u32 {799 pub inline fn r_type(self: @This()) u32 {
800 return @truncate(u32, self.r_info);800 return @as(u32, @truncate(self.r_info));
801 }801 }
802};802};
803pub const Elf32_Dyn = extern struct {803pub const Elf32_Dyn = extern struct {
lib/std/enums.zig+15-15
...@@ -16,7 +16,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def...@@ -16,7 +16,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def
16 fields = fields ++ &[_]StructField{.{16 fields = fields ++ &[_]StructField{.{
17 .name = field.name,17 .name = field.name,
18 .type = Data,18 .type = Data,
19 .default_value = if (field_default) |d| @ptrCast(?*const anyopaque, &d) else null,19 .default_value = if (field_default) |d| @as(?*const anyopaque, @ptrCast(&d)) else null,
20 .is_comptime = false,20 .is_comptime = false,
21 .alignment = if (@sizeOf(Data) > 0) @alignOf(Data) else 0,21 .alignment = if (@sizeOf(Data) > 0) @alignOf(Data) else 0,
22 }};22 }};
...@@ -61,7 +61,7 @@ test tagName {...@@ -61,7 +61,7 @@ test tagName {
61 const E = enum(u8) { a, b, _ };61 const E = enum(u8) { a, b, _ };
62 try testing.expect(tagName(E, .a) != null);62 try testing.expect(tagName(E, .a) != null);
63 try testing.expectEqualStrings("a", tagName(E, .a).?);63 try testing.expectEqualStrings("a", tagName(E, .a).?);
64 try testing.expect(tagName(E, @enumFromInt(E, 42)) == null);64 try testing.expect(tagName(E, @as(E, @enumFromInt(42))) == null);
65}65}
6666
67/// Determines the length of a direct-mapped enum array, indexed by67/// Determines the length of a direct-mapped enum array, indexed by
...@@ -156,7 +156,7 @@ pub fn directEnumArrayDefault(...@@ -156,7 +156,7 @@ pub fn directEnumArrayDefault(
156 var result: [len]Data = if (default) |d| [_]Data{d} ** len else undefined;156 var result: [len]Data = if (default) |d| [_]Data{d} ** len else undefined;
157 inline for (@typeInfo(@TypeOf(init_values)).Struct.fields) |f| {157 inline for (@typeInfo(@TypeOf(init_values)).Struct.fields) |f| {
158 const enum_value = @field(E, f.name);158 const enum_value = @field(E, f.name);
159 const index = @intCast(usize, @intFromEnum(enum_value));159 const index = @as(usize, @intCast(@intFromEnum(enum_value)));
160 result[index] = @field(init_values, f.name);160 result[index] = @field(init_values, f.name);
161 }161 }
162 return result;162 return result;
...@@ -341,7 +341,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {...@@ -341,7 +341,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
341 var self = initWithCount(0);341 var self = initWithCount(0);
342 inline for (@typeInfo(E).Enum.fields) |field| {342 inline for (@typeInfo(E).Enum.fields) |field| {
343 const c = @field(init_counts, field.name);343 const c = @field(init_counts, field.name);
344 const key = @enumFromInt(E, field.value);344 const key = @as(E, @enumFromInt(field.value));
345 self.counts.set(key, c);345 self.counts.set(key, c);
346 }346 }
347 return self;347 return self;
...@@ -412,7 +412,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {...@@ -412,7 +412,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
412 /// asserts operation will not overflow any key.412 /// asserts operation will not overflow any key.
413 pub fn addSetAssertSafe(self: *Self, other: Self) void {413 pub fn addSetAssertSafe(self: *Self, other: Self) void {
414 inline for (@typeInfo(E).Enum.fields) |field| {414 inline for (@typeInfo(E).Enum.fields) |field| {
415 const key = @enumFromInt(E, field.value);415 const key = @as(E, @enumFromInt(field.value));
416 self.addAssertSafe(key, other.getCount(key));416 self.addAssertSafe(key, other.getCount(key));
417 }417 }
418 }418 }
...@@ -420,7 +420,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {...@@ -420,7 +420,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
420 /// Increases the all key counts by given multiset.420 /// Increases the all key counts by given multiset.
421 pub fn addSet(self: *Self, other: Self) error{Overflow}!void {421 pub fn addSet(self: *Self, other: Self) error{Overflow}!void {
422 inline for (@typeInfo(E).Enum.fields) |field| {422 inline for (@typeInfo(E).Enum.fields) |field| {
423 const key = @enumFromInt(E, field.value);423 const key = @as(E, @enumFromInt(field.value));
424 try self.add(key, other.getCount(key));424 try self.add(key, other.getCount(key));
425 }425 }
426 }426 }
...@@ -430,7 +430,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {...@@ -430,7 +430,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
430 /// then that key will have a key count of zero.430 /// then that key will have a key count of zero.
431 pub fn removeSet(self: *Self, other: Self) void {431 pub fn removeSet(self: *Self, other: Self) void {
432 inline for (@typeInfo(E).Enum.fields) |field| {432 inline for (@typeInfo(E).Enum.fields) |field| {
433 const key = @enumFromInt(E, field.value);433 const key = @as(E, @enumFromInt(field.value));
434 self.remove(key, other.getCount(key));434 self.remove(key, other.getCount(key));
435 }435 }
436 }436 }
...@@ -439,7 +439,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {...@@ -439,7 +439,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
439 /// given multiset.439 /// given multiset.
440 pub fn eql(self: Self, other: Self) bool {440 pub fn eql(self: Self, other: Self) bool {
441 inline for (@typeInfo(E).Enum.fields) |field| {441 inline for (@typeInfo(E).Enum.fields) |field| {
442 const key = @enumFromInt(E, field.value);442 const key = @as(E, @enumFromInt(field.value));
443 if (self.getCount(key) != other.getCount(key)) {443 if (self.getCount(key) != other.getCount(key)) {
444 return false;444 return false;
445 }445 }
...@@ -451,7 +451,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {...@@ -451,7 +451,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
451 /// equal to the given multiset.451 /// equal to the given multiset.
452 pub fn subsetOf(self: Self, other: Self) bool {452 pub fn subsetOf(self: Self, other: Self) bool {
453 inline for (@typeInfo(E).Enum.fields) |field| {453 inline for (@typeInfo(E).Enum.fields) |field| {
454 const key = @enumFromInt(E, field.value);454 const key = @as(E, @enumFromInt(field.value));
455 if (self.getCount(key) > other.getCount(key)) {455 if (self.getCount(key) > other.getCount(key)) {
456 return false;456 return false;
457 }457 }
...@@ -463,7 +463,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {...@@ -463,7 +463,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
463 /// equal to the given multiset.463 /// equal to the given multiset.
464 pub fn supersetOf(self: Self, other: Self) bool {464 pub fn supersetOf(self: Self, other: Self) bool {
465 inline for (@typeInfo(E).Enum.fields) |field| {465 inline for (@typeInfo(E).Enum.fields) |field| {
466 const key = @enumFromInt(E, field.value);466 const key = @as(E, @enumFromInt(field.value));
467 if (self.getCount(key) < other.getCount(key)) {467 if (self.getCount(key) < other.getCount(key)) {
468 return false;468 return false;
469 }469 }
...@@ -1281,10 +1281,10 @@ test "std.enums.ensureIndexer" {...@@ -1281,10 +1281,10 @@ test "std.enums.ensureIndexer" {
1281 pub const Key = u32;1281 pub const Key = u32;
1282 pub const count: usize = 8;1282 pub const count: usize = 8;
1283 pub fn indexOf(k: Key) usize {1283 pub fn indexOf(k: Key) usize {
1284 return @intCast(usize, k);1284 return @as(usize, @intCast(k));
1285 }1285 }
1286 pub fn keyForIndex(index: usize) Key {1286 pub fn keyForIndex(index: usize) Key {
1287 return @intCast(Key, index);1287 return @as(Key, @intCast(index));
1288 }1288 }
1289 });1289 });
1290}1290}
...@@ -1323,14 +1323,14 @@ pub fn EnumIndexer(comptime E: type) type {...@@ -1323,14 +1323,14 @@ pub fn EnumIndexer(comptime E: type) type {
1323 pub const Key = E;1323 pub const Key = E;
1324 pub const count = fields_len;1324 pub const count = fields_len;
1325 pub fn indexOf(e: E) usize {1325 pub fn indexOf(e: E) usize {
1326 return @intCast(usize, @intFromEnum(e) - min);1326 return @as(usize, @intCast(@intFromEnum(e) - min));
1327 }1327 }
1328 pub fn keyForIndex(i: usize) E {1328 pub fn keyForIndex(i: usize) E {
1329 // TODO fix addition semantics. This calculation1329 // TODO fix addition semantics. This calculation
1330 // gives up some safety to avoid artificially limiting1330 // gives up some safety to avoid artificially limiting
1331 // the range of signed enum values to max_isize.1331 // the range of signed enum values to max_isize.
1332 const enum_value = if (min < 0) @bitCast(isize, i) +% min else i + min;1332 const enum_value = if (min < 0) @as(isize, @bitCast(i)) +% min else i + min;
1333 return @enumFromInt(E, @intCast(std.meta.Tag(E), enum_value));1333 return @as(E, @enumFromInt(@as(std.meta.Tag(E), @intCast(enum_value))));
1334 }1334 }
1335 };1335 };
1336 }1336 }
lib/std/event/lock.zig+3-3
...@@ -55,7 +55,7 @@ pub const Lock = struct {...@@ -55,7 +55,7 @@ pub const Lock = struct {
55 const head = switch (self.head) {55 const head = switch (self.head) {
56 UNLOCKED => unreachable,56 UNLOCKED => unreachable,
57 LOCKED => null,57 LOCKED => null,
58 else => @ptrFromInt(*Waiter, self.head),58 else => @as(*Waiter, @ptrFromInt(self.head)),
59 };59 };
6060
61 if (head) |h| {61 if (head) |h| {
...@@ -102,7 +102,7 @@ pub const Lock = struct {...@@ -102,7 +102,7 @@ pub const Lock = struct {
102 break :blk null;102 break :blk null;
103 },103 },
104 else => {104 else => {
105 const waiter = @ptrFromInt(*Waiter, self.lock.head);105 const waiter = @as(*Waiter, @ptrFromInt(self.lock.head));
106 self.lock.head = if (waiter.next == null) LOCKED else @intFromPtr(waiter.next);106 self.lock.head = if (waiter.next == null) LOCKED else @intFromPtr(waiter.next);
107 if (waiter.next) |next|107 if (waiter.next) |next|
108 next.tail = waiter.tail;108 next.tail = waiter.tail;
...@@ -130,7 +130,7 @@ test "std.event.Lock" {...@@ -130,7 +130,7 @@ test "std.event.Lock" {
130 var lock = Lock{};130 var lock = Lock{};
131 testLock(&lock);131 testLock(&lock);
132132
133 const expected_result = [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;133 const expected_result = [1]i32{3 * @as(i32, @intCast(shared_test_data.len))} ** shared_test_data.len;
134 try testing.expectEqualSlices(i32, &expected_result, &shared_test_data);134 try testing.expectEqualSlices(i32, &expected_result, &shared_test_data);
135}135}
136fn testLock(lock: *Lock) void {136fn testLock(lock: *Lock) void {
lib/std/event/loop.zig+6-6
...@@ -556,7 +556,7 @@ pub const Loop = struct {...@@ -556,7 +556,7 @@ pub const Loop = struct {
556 self.linuxWaitFd(fd, os.linux.EPOLL.ET | os.linux.EPOLL.ONESHOT | os.linux.EPOLL.IN);556 self.linuxWaitFd(fd, os.linux.EPOLL.ET | os.linux.EPOLL.ONESHOT | os.linux.EPOLL.IN);
557 },557 },
558 .macos, .ios, .tvos, .watchos, .freebsd, .netbsd, .dragonfly, .openbsd => {558 .macos, .ios, .tvos, .watchos, .freebsd, .netbsd, .dragonfly, .openbsd => {
559 self.bsdWaitKev(@intCast(usize, fd), os.system.EVFILT_READ, os.system.EV_ONESHOT);559 self.bsdWaitKev(@as(usize, @intCast(fd)), os.system.EVFILT_READ, os.system.EV_ONESHOT);
560 },560 },
561 else => @compileError("Unsupported OS"),561 else => @compileError("Unsupported OS"),
562 }562 }
...@@ -568,7 +568,7 @@ pub const Loop = struct {...@@ -568,7 +568,7 @@ pub const Loop = struct {
568 self.linuxWaitFd(fd, os.linux.EPOLL.ET | os.linux.EPOLL.ONESHOT | os.linux.EPOLL.OUT);568 self.linuxWaitFd(fd, os.linux.EPOLL.ET | os.linux.EPOLL.ONESHOT | os.linux.EPOLL.OUT);
569 },569 },
570 .macos, .ios, .tvos, .watchos, .freebsd, .netbsd, .dragonfly, .openbsd => {570 .macos, .ios, .tvos, .watchos, .freebsd, .netbsd, .dragonfly, .openbsd => {
571 self.bsdWaitKev(@intCast(usize, fd), os.system.EVFILT_WRITE, os.system.EV_ONESHOT);571 self.bsdWaitKev(@as(usize, @intCast(fd)), os.system.EVFILT_WRITE, os.system.EV_ONESHOT);
572 },572 },
573 else => @compileError("Unsupported OS"),573 else => @compileError("Unsupported OS"),
574 }574 }
...@@ -580,8 +580,8 @@ pub const Loop = struct {...@@ -580,8 +580,8 @@ pub const Loop = struct {
580 self.linuxWaitFd(fd, os.linux.EPOLL.ET | os.linux.EPOLL.ONESHOT | os.linux.EPOLL.OUT | os.linux.EPOLL.IN);580 self.linuxWaitFd(fd, os.linux.EPOLL.ET | os.linux.EPOLL.ONESHOT | os.linux.EPOLL.OUT | os.linux.EPOLL.IN);
581 },581 },
582 .macos, .ios, .tvos, .watchos, .freebsd, .netbsd, .dragonfly, .openbsd => {582 .macos, .ios, .tvos, .watchos, .freebsd, .netbsd, .dragonfly, .openbsd => {
583 self.bsdWaitKev(@intCast(usize, fd), os.system.EVFILT_READ, os.system.EV_ONESHOT);583 self.bsdWaitKev(@as(usize, @intCast(fd)), os.system.EVFILT_READ, os.system.EV_ONESHOT);
584 self.bsdWaitKev(@intCast(usize, fd), os.system.EVFILT_WRITE, os.system.EV_ONESHOT);584 self.bsdWaitKev(@as(usize, @intCast(fd)), os.system.EVFILT_WRITE, os.system.EV_ONESHOT);
585 },585 },
586 else => @compileError("Unsupported OS"),586 else => @compileError("Unsupported OS"),
587 }587 }
...@@ -1415,7 +1415,7 @@ pub const Loop = struct {...@@ -1415,7 +1415,7 @@ pub const Loop = struct {
1415 var events: [1]os.linux.epoll_event = undefined;1415 var events: [1]os.linux.epoll_event = undefined;
1416 const count = os.epoll_wait(self.os_data.epollfd, events[0..], -1);1416 const count = os.epoll_wait(self.os_data.epollfd, events[0..], -1);
1417 for (events[0..count]) |ev| {1417 for (events[0..count]) |ev| {
1418 const resume_node = @ptrFromInt(*ResumeNode, ev.data.ptr);1418 const resume_node = @as(*ResumeNode, @ptrFromInt(ev.data.ptr));
1419 const handle = resume_node.handle;1419 const handle = resume_node.handle;
1420 const resume_node_id = resume_node.id;1420 const resume_node_id = resume_node.id;
1421 switch (resume_node_id) {1421 switch (resume_node_id) {
...@@ -1439,7 +1439,7 @@ pub const Loop = struct {...@@ -1439,7 +1439,7 @@ pub const Loop = struct {
1439 const empty_kevs = &[0]os.Kevent{};1439 const empty_kevs = &[0]os.Kevent{};
1440 const count = os.kevent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;1440 const count = os.kevent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;
1441 for (eventlist[0..count]) |ev| {1441 for (eventlist[0..count]) |ev| {
1442 const resume_node = @ptrFromInt(*ResumeNode, ev.udata);1442 const resume_node = @as(*ResumeNode, @ptrFromInt(ev.udata));
1443 const handle = resume_node.handle;1443 const handle = resume_node.handle;
1444 const resume_node_id = resume_node.id;1444 const resume_node_id = resume_node.id;
1445 switch (resume_node_id) {1445 switch (resume_node_id) {
lib/std/event/rwlock.zig+4-4
...@@ -223,7 +223,7 @@ test "std.event.RwLock" {...@@ -223,7 +223,7 @@ test "std.event.RwLock" {
223223
224 _ = testLock(std.heap.page_allocator, &lock);224 _ = testLock(std.heap.page_allocator, &lock);
225225
226 const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;226 const expected_result = [1]i32{shared_it_count * @as(i32, @intCast(shared_test_data.len))} ** shared_test_data.len;
227 try testing.expectEqualSlices(i32, expected_result, shared_test_data);227 try testing.expectEqualSlices(i32, expected_result, shared_test_data);
228}228}
229fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void {229fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void {
...@@ -244,12 +244,12 @@ fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void {...@@ -244,12 +244,12 @@ fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void {
244 }244 }
245245
246 for (write_nodes) |*write_node| {246 for (write_nodes) |*write_node| {
247 const casted = @ptrCast(*const @Frame(writeRunner), write_node.data);247 const casted = @as(*const @Frame(writeRunner), @ptrCast(write_node.data));
248 await casted;248 await casted;
249 allocator.destroy(casted);249 allocator.destroy(casted);
250 }250 }
251 for (read_nodes) |*read_node| {251 for (read_nodes) |*read_node| {
252 const casted = @ptrCast(*const @Frame(readRunner), read_node.data);252 const casted = @as(*const @Frame(readRunner), @ptrCast(read_node.data));
253 await casted;253 await casted;
254 allocator.destroy(casted);254 allocator.destroy(casted);
255 }255 }
...@@ -287,6 +287,6 @@ fn readRunner(lock: *RwLock) callconv(.Async) void {...@@ -287,6 +287,6 @@ fn readRunner(lock: *RwLock) callconv(.Async) void {
287 defer handle.release();287 defer handle.release();
288288
289 try testing.expect(shared_test_index == 0);289 try testing.expect(shared_test_index == 0);
290 try testing.expect(shared_test_data[i] == @intCast(i32, shared_count));290 try testing.expect(shared_test_data[i] == @as(i32, @intCast(shared_count)));
291 }291 }
292}292}
lib/std/fmt.zig+35-35
...@@ -396,7 +396,7 @@ pub const ArgState = struct {...@@ -396,7 +396,7 @@ pub const ArgState = struct {
396 }396 }
397397
398 // Mark this argument as used398 // Mark this argument as used
399 self.used_args |= @as(ArgSetType, 1) << @intCast(u5, next_index);399 self.used_args |= @as(ArgSetType, 1) << @as(u5, @intCast(next_index));
400 return next_index;400 return next_index;
401 }401 }
402};402};
...@@ -1056,7 +1056,7 @@ pub fn formatFloatScientific(...@@ -1056,7 +1056,7 @@ pub fn formatFloatScientific(
1056 options: FormatOptions,1056 options: FormatOptions,
1057 writer: anytype,1057 writer: anytype,
1058) !void {1058) !void {
1059 var x = @floatCast(f64, value);1059 var x = @as(f64, @floatCast(value));
10601060
1061 // Errol doesn't handle these special cases.1061 // Errol doesn't handle these special cases.
1062 if (math.signbit(x)) {1062 if (math.signbit(x)) {
...@@ -1167,9 +1167,9 @@ pub fn formatFloatHexadecimal(...@@ -1167,9 +1167,9 @@ pub fn formatFloatHexadecimal(
1167 const exponent_mask = (1 << exponent_bits) - 1;1167 const exponent_mask = (1 << exponent_bits) - 1;
1168 const exponent_bias = (1 << (exponent_bits - 1)) - 1;1168 const exponent_bias = (1 << (exponent_bits - 1)) - 1;
11691169
1170 const as_bits = @bitCast(TU, value);1170 const as_bits = @as(TU, @bitCast(value));
1171 var mantissa = as_bits & mantissa_mask;1171 var mantissa = as_bits & mantissa_mask;
1172 var exponent: i32 = @truncate(u16, (as_bits >> mantissa_bits) & exponent_mask);1172 var exponent: i32 = @as(u16, @truncate((as_bits >> mantissa_bits) & exponent_mask));
11731173
1174 const is_denormal = exponent == 0 and mantissa != 0;1174 const is_denormal = exponent == 0 and mantissa != 0;
1175 const is_zero = exponent == 0 and mantissa == 0;1175 const is_zero = exponent == 0 and mantissa == 0;
...@@ -1218,7 +1218,7 @@ pub fn formatFloatHexadecimal(...@@ -1218,7 +1218,7 @@ pub fn formatFloatHexadecimal(
1218 // Drop the excess bits.1218 // Drop the excess bits.
1219 mantissa >>= 2;1219 mantissa >>= 2;
1220 // Restore the alignment.1220 // Restore the alignment.
1221 mantissa <<= @intCast(math.Log2Int(TU), (mantissa_digits - precision) * 4);1221 mantissa <<= @as(math.Log2Int(TU), @intCast((mantissa_digits - precision) * 4));
12221222
1223 const overflow = mantissa & (1 << 1 + mantissa_digits * 4) != 0;1223 const overflow = mantissa & (1 << 1 + mantissa_digits * 4) != 0;
1224 // Prefer a normalized result in case of overflow.1224 // Prefer a normalized result in case of overflow.
...@@ -1296,7 +1296,7 @@ pub fn formatFloatDecimal(...@@ -1296,7 +1296,7 @@ pub fn formatFloatDecimal(
1296 errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Decimal);1296 errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Decimal);
12971297
1298 // exp < 0 means the leading is always 0 as errol result is normalized.1298 // exp < 0 means the leading is always 0 as errol result is normalized.
1299 var num_digits_whole = if (float_decimal.exp > 0) @intCast(usize, float_decimal.exp) else 0;1299 var num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0;
13001300
1301 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.1301 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.
1302 var num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);1302 var num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);
...@@ -1325,7 +1325,7 @@ pub fn formatFloatDecimal(...@@ -1325,7 +1325,7 @@ pub fn formatFloatDecimal(
13251325
1326 // Zero-fill until we reach significant digits or run out of precision.1326 // Zero-fill until we reach significant digits or run out of precision.
1327 if (float_decimal.exp <= 0) {1327 if (float_decimal.exp <= 0) {
1328 const zero_digit_count = @intCast(usize, -float_decimal.exp);1328 const zero_digit_count = @as(usize, @intCast(-float_decimal.exp));
1329 const zeros_to_print = @min(zero_digit_count, precision);1329 const zeros_to_print = @min(zero_digit_count, precision);
13301330
1331 var i: usize = 0;1331 var i: usize = 0;
...@@ -1354,7 +1354,7 @@ pub fn formatFloatDecimal(...@@ -1354,7 +1354,7 @@ pub fn formatFloatDecimal(
1354 }1354 }
1355 } else {1355 } else {
1356 // exp < 0 means the leading is always 0 as errol result is normalized.1356 // exp < 0 means the leading is always 0 as errol result is normalized.
1357 var num_digits_whole = if (float_decimal.exp > 0) @intCast(usize, float_decimal.exp) else 0;1357 var num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0;
13581358
1359 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.1359 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.
1360 var num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);1360 var num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);
...@@ -1380,7 +1380,7 @@ pub fn formatFloatDecimal(...@@ -1380,7 +1380,7 @@ pub fn formatFloatDecimal(
13801380
1381 // Zero-fill until we reach significant digits or run out of precision.1381 // Zero-fill until we reach significant digits or run out of precision.
1382 if (float_decimal.exp < 0) {1382 if (float_decimal.exp < 0) {
1383 const zero_digit_count = @intCast(usize, -float_decimal.exp);1383 const zero_digit_count = @as(usize, @intCast(-float_decimal.exp));
13841384
1385 var i: usize = 0;1385 var i: usize = 0;
1386 while (i < zero_digit_count) : (i += 1) {1386 while (i < zero_digit_count) : (i += 1) {
...@@ -1423,21 +1423,21 @@ pub fn formatInt(...@@ -1423,21 +1423,21 @@ pub fn formatInt(
1423 if (base == 10) {1423 if (base == 10) {
1424 while (a >= 100) : (a = @divTrunc(a, 100)) {1424 while (a >= 100) : (a = @divTrunc(a, 100)) {
1425 index -= 2;1425 index -= 2;
1426 buf[index..][0..2].* = digits2(@intCast(usize, a % 100));1426 buf[index..][0..2].* = digits2(@as(usize, @intCast(a % 100)));
1427 }1427 }
14281428
1429 if (a < 10) {1429 if (a < 10) {
1430 index -= 1;1430 index -= 1;
1431 buf[index] = '0' + @intCast(u8, a);1431 buf[index] = '0' + @as(u8, @intCast(a));
1432 } else {1432 } else {
1433 index -= 2;1433 index -= 2;
1434 buf[index..][0..2].* = digits2(@intCast(usize, a));1434 buf[index..][0..2].* = digits2(@as(usize, @intCast(a)));
1435 }1435 }
1436 } else {1436 } else {
1437 while (true) {1437 while (true) {
1438 const digit = a % base;1438 const digit = a % base;
1439 index -= 1;1439 index -= 1;
1440 buf[index] = digitToChar(@intCast(u8, digit), case);1440 buf[index] = digitToChar(@as(u8, @intCast(digit)), case);
1441 a /= base;1441 a /= base;
1442 if (a == 0) break;1442 if (a == 0) break;
1443 }1443 }
...@@ -1595,10 +1595,10 @@ test "fmtDuration" {...@@ -1595,10 +1595,10 @@ test "fmtDuration" {
15951595
1596fn formatDurationSigned(ns: i64, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {1596fn formatDurationSigned(ns: i64, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
1597 if (ns < 0) {1597 if (ns < 0) {
1598 const data = FormatDurationData{ .ns = @intCast(u64, -ns), .negative = true };1598 const data = FormatDurationData{ .ns = @as(u64, @intCast(-ns)), .negative = true };
1599 try formatDuration(data, fmt, options, writer);1599 try formatDuration(data, fmt, options, writer);
1600 } else {1600 } else {
1601 const data = FormatDurationData{ .ns = @intCast(u64, ns) };1601 const data = FormatDurationData{ .ns = @as(u64, @intCast(ns)) };
1602 try formatDuration(data, fmt, options, writer);1602 try formatDuration(data, fmt, options, writer);
1603 }1603 }
1604}1604}
...@@ -1846,7 +1846,7 @@ fn parseWithSign(...@@ -1846,7 +1846,7 @@ fn parseWithSign(
1846 // The first digit of a negative number.1846 // The first digit of a negative number.
1847 // Consider parsing "-4" as an i3.1847 // Consider parsing "-4" as an i3.
1848 // This should work, but positive 4 overflows i3, so we can't cast the digit to T and subtract.1848 // This should work, but positive 4 overflows i3, so we can't cast the digit to T and subtract.
1849 x = math.cast(T, -@intCast(i8, digit)) orelse return error.Overflow;1849 x = math.cast(T, -@as(i8, @intCast(digit))) orelse return error.Overflow;
1850 continue;1850 continue;
1851 }1851 }
1852 x = try add(T, x, math.cast(T, digit) orelse return error.Overflow);1852 x = try add(T, x, math.cast(T, digit) orelse return error.Overflow);
...@@ -2099,7 +2099,7 @@ test "optional" {...@@ -2099,7 +2099,7 @@ test "optional" {
2099 try expectFmt("optional: null\n", "optional: {?}\n", .{value});2099 try expectFmt("optional: null\n", "optional: {?}\n", .{value});
2100 }2100 }
2101 {2101 {
2102 const value = @ptrFromInt(?*i32, 0xf000d000);2102 const value = @as(?*i32, @ptrFromInt(0xf000d000));
2103 try expectFmt("optional: *i32@f000d000\n", "optional: {*}\n", .{value});2103 try expectFmt("optional: *i32@f000d000\n", "optional: {*}\n", .{value});
2104 }2104 }
2105}2105}
...@@ -2218,7 +2218,7 @@ test "slice" {...@@ -2218,7 +2218,7 @@ test "slice" {
2218 }2218 }
2219 {2219 {
2220 var runtime_zero: usize = 0;2220 var runtime_zero: usize = 0;
2221 const value = @ptrFromInt([*]align(1) const []const u8, 0xdeadbeef)[runtime_zero..runtime_zero];2221 const value = @as([*]align(1) const []const u8, @ptrFromInt(0xdeadbeef))[runtime_zero..runtime_zero];
2222 try expectFmt("slice: []const u8@deadbeef\n", "slice: {*}\n", .{value});2222 try expectFmt("slice: []const u8@deadbeef\n", "slice: {*}\n", .{value});
2223 }2223 }
2224 {2224 {
...@@ -2248,17 +2248,17 @@ test "escape non-printable" {...@@ -2248,17 +2248,17 @@ test "escape non-printable" {
22482248
2249test "pointer" {2249test "pointer" {
2250 {2250 {
2251 const value = @ptrFromInt(*align(1) i32, 0xdeadbeef);2251 const value = @as(*align(1) i32, @ptrFromInt(0xdeadbeef));
2252 try expectFmt("pointer: i32@deadbeef\n", "pointer: {}\n", .{value});2252 try expectFmt("pointer: i32@deadbeef\n", "pointer: {}\n", .{value});
2253 try expectFmt("pointer: i32@deadbeef\n", "pointer: {*}\n", .{value});2253 try expectFmt("pointer: i32@deadbeef\n", "pointer: {*}\n", .{value});
2254 }2254 }
2255 const FnPtr = *align(1) const fn () void;2255 const FnPtr = *align(1) const fn () void;
2256 {2256 {
2257 const value = @ptrFromInt(FnPtr, 0xdeadbeef);2257 const value = @as(FnPtr, @ptrFromInt(0xdeadbeef));
2258 try expectFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value});2258 try expectFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value});
2259 }2259 }
2260 {2260 {
2261 const value = @ptrFromInt(FnPtr, 0xdeadbeef);2261 const value = @as(FnPtr, @ptrFromInt(0xdeadbeef));
2262 try expectFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value});2262 try expectFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value});
2263 }2263 }
2264}2264}
...@@ -2267,12 +2267,12 @@ test "cstr" {...@@ -2267,12 +2267,12 @@ test "cstr" {
2267 try expectFmt(2267 try expectFmt(
2268 "cstr: Test C\n",2268 "cstr: Test C\n",
2269 "cstr: {s}\n",2269 "cstr: {s}\n",
2270 .{@ptrCast([*c]const u8, "Test C")},2270 .{@as([*c]const u8, @ptrCast("Test C"))},
2271 );2271 );
2272 try expectFmt(2272 try expectFmt(
2273 "cstr: Test C\n",2273 "cstr: Test C\n",
2274 "cstr: {s:10}\n",2274 "cstr: {s:10}\n",
2275 .{@ptrCast([*c]const u8, "Test C")},2275 .{@as([*c]const u8, @ptrCast("Test C"))},
2276 );2276 );
2277}2277}
22782278
...@@ -2360,11 +2360,11 @@ test "non-exhaustive enum" {...@@ -2360,11 +2360,11 @@ test "non-exhaustive enum" {
2360 };2360 };
2361 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.One\n", "enum: {}\n", .{Enum.One});2361 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.One\n", "enum: {}\n", .{Enum.One});
2362 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.Two\n", "enum: {}\n", .{Enum.Two});2362 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.Two\n", "enum: {}\n", .{Enum.Two});
2363 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum(4660)\n", "enum: {}\n", .{@enumFromInt(Enum, 0x1234)});2363 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum(4660)\n", "enum: {}\n", .{@as(Enum, @enumFromInt(0x1234))});
2364 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.One\n", "enum: {x}\n", .{Enum.One});2364 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.One\n", "enum: {x}\n", .{Enum.One});
2365 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.Two\n", "enum: {x}\n", .{Enum.Two});2365 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.Two\n", "enum: {x}\n", .{Enum.Two});
2366 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.Two\n", "enum: {X}\n", .{Enum.Two});2366 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.Two\n", "enum: {X}\n", .{Enum.Two});
2367 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum(1234)\n", "enum: {x}\n", .{@enumFromInt(Enum, 0x1234)});2367 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum(1234)\n", "enum: {x}\n", .{@as(Enum, @enumFromInt(0x1234))});
2368}2368}
23692369
2370test "float.scientific" {2370test "float.scientific" {
...@@ -2376,11 +2376,11 @@ test "float.scientific" {...@@ -2376,11 +2376,11 @@ test "float.scientific" {
23762376
2377test "float.scientific.precision" {2377test "float.scientific.precision" {
2378 try expectFmt("f64: 1.40971e-42", "f64: {e:.5}", .{@as(f64, 1.409706e-42)});2378 try expectFmt("f64: 1.40971e-42", "f64: {e:.5}", .{@as(f64, 1.409706e-42)});
2379 try expectFmt("f64: 1.00000e-09", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 814313563)))});2379 try expectFmt("f64: 1.00000e-09", "f64: {e:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 814313563))))});
2380 try expectFmt("f64: 7.81250e-03", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1006632960)))});2380 try expectFmt("f64: 7.81250e-03", "f64: {e:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 1006632960))))});
2381 // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.2381 // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.
2382 // In fact, libc doesn't round a lot of 5 cases up when one past the precision point.2382 // In fact, libc doesn't round a lot of 5 cases up when one past the precision point.
2383 try expectFmt("f64: 1.00001e+05", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1203982400)))});2383 try expectFmt("f64: 1.00001e+05", "f64: {e:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 1203982400))))});
2384}2384}
23852385
2386test "float.special" {2386test "float.special" {
...@@ -2472,22 +2472,22 @@ test "float.decimal" {...@@ -2472,22 +2472,22 @@ test "float.decimal" {
2472}2472}
24732473
2474test "float.libc.sanity" {2474test "float.libc.sanity" {
2475 try expectFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 916964781)))});2475 try expectFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 916964781))))});
2476 try expectFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 925353389)))});2476 try expectFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 925353389))))});
2477 try expectFmt("f64: 0.10000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1036831278)))});2477 try expectFmt("f64: 0.10000", "f64: {d:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 1036831278))))});
2478 try expectFmt("f64: 1.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1065353133)))});2478 try expectFmt("f64: 1.00000", "f64: {d:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 1065353133))))});
2479 try expectFmt("f64: 10.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1092616192)))});2479 try expectFmt("f64: 10.00000", "f64: {d:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 1092616192))))});
24802480
2481 // libc differences2481 // libc differences
2482 //2482 //
2483 // This is 0.015625 exactly according to gdb. We thus round down,2483 // This is 0.015625 exactly according to gdb. We thus round down,
2484 // however glibc rounds up for some reason. This occurs for all2484 // however glibc rounds up for some reason. This occurs for all
2485 // floats of the form x.yyyy25 on a precision point.2485 // floats of the form x.yyyy25 on a precision point.
2486 try expectFmt("f64: 0.01563", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1015021568)))});2486 try expectFmt("f64: 0.01563", "f64: {d:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 1015021568))))});
2487 // errol3 rounds to ... 630 but libc rounds to ...632. Grisu32487 // errol3 rounds to ... 630 but libc rounds to ...632. Grisu3
2488 // also rounds to 630 so I'm inclined to believe libc is not2488 // also rounds to 630 so I'm inclined to believe libc is not
2489 // optimal here.2489 // optimal here.
2490 try expectFmt("f64: 18014400656965630.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1518338049)))});2490 try expectFmt("f64: 18014400656965630.00000", "f64: {d:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 1518338049))))});
2491}2491}
24922492
2493test "custom" {2493test "custom" {
lib/std/fmt/errol.zig+49-49
...@@ -29,11 +29,11 @@ pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: Ro...@@ -29,11 +29,11 @@ pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: Ro
29 switch (mode) {29 switch (mode) {
30 RoundMode.Decimal => {30 RoundMode.Decimal => {
31 if (float_decimal.exp >= 0) {31 if (float_decimal.exp >= 0) {
32 round_digit = precision + @intCast(usize, float_decimal.exp);32 round_digit = precision + @as(usize, @intCast(float_decimal.exp));
33 } else {33 } else {
34 // if a small negative exp, then adjust we need to offset by the number34 // if a small negative exp, then adjust we need to offset by the number
35 // of leading zeros that will occur.35 // of leading zeros that will occur.
36 const min_exp_required = @intCast(usize, -float_decimal.exp);36 const min_exp_required = @as(usize, @intCast(-float_decimal.exp));
37 if (precision > min_exp_required) {37 if (precision > min_exp_required) {
38 round_digit = precision - min_exp_required;38 round_digit = precision - min_exp_required;
39 }39 }
...@@ -59,7 +59,7 @@ pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: Ro...@@ -59,7 +59,7 @@ pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: Ro
59 float_decimal.exp += 1;59 float_decimal.exp += 1;
6060
61 // Re-size the buffer to use the reserved leading byte.61 // Re-size the buffer to use the reserved leading byte.
62 const one_before = @ptrFromInt([*]u8, @intFromPtr(&float_decimal.digits[0]) - 1);62 const one_before = @as([*]u8, @ptrFromInt(@intFromPtr(&float_decimal.digits[0]) - 1));
63 float_decimal.digits = one_before[0 .. float_decimal.digits.len + 1];63 float_decimal.digits = one_before[0 .. float_decimal.digits.len + 1];
64 float_decimal.digits[0] = '1';64 float_decimal.digits[0] = '1';
65 return;65 return;
...@@ -80,7 +80,7 @@ pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: Ro...@@ -80,7 +80,7 @@ pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: Ro
8080
81/// Corrected Errol3 double to ASCII conversion.81/// Corrected Errol3 double to ASCII conversion.
82pub fn errol3(value: f64, buffer: []u8) FloatDecimal {82pub fn errol3(value: f64, buffer: []u8) FloatDecimal {
83 const bits = @bitCast(u64, value);83 const bits = @as(u64, @bitCast(value));
84 const i = tableLowerBound(bits);84 const i = tableLowerBound(bits);
85 if (i < enum3.len and enum3[i] == bits) {85 if (i < enum3.len and enum3[i] == bits) {
86 const data = enum3_data[i];86 const data = enum3_data[i];
...@@ -113,16 +113,16 @@ fn errolSlow(val: f64, buffer: []u8) FloatDecimal {...@@ -113,16 +113,16 @@ fn errolSlow(val: f64, buffer: []u8) FloatDecimal {
113 // normalize the midpoint113 // normalize the midpoint
114114
115 const e = math.frexp(val).exponent;115 const e = math.frexp(val).exponent;
116 var exp = @intFromFloat(i16, @floor(307 + @floatFromInt(f64, e) * 0.30103));116 var exp = @as(i16, @intFromFloat(@floor(307 + @as(f64, @floatFromInt(e)) * 0.30103)));
117 if (exp < 20) {117 if (exp < 20) {
118 exp = 20;118 exp = 20;
119 } else if (@intCast(usize, exp) >= lookup_table.len) {119 } else if (@as(usize, @intCast(exp)) >= lookup_table.len) {
120 exp = @intCast(i16, lookup_table.len - 1);120 exp = @as(i16, @intCast(lookup_table.len - 1));
121 }121 }
122122
123 var mid = lookup_table[@intCast(usize, exp)];123 var mid = lookup_table[@as(usize, @intCast(exp))];
124 mid = hpProd(mid, val);124 mid = hpProd(mid, val);
125 const lten = lookup_table[@intCast(usize, exp)].val;125 const lten = lookup_table[@as(usize, @intCast(exp))].val;
126126
127 exp -= 307;127 exp -= 307;
128128
...@@ -171,25 +171,25 @@ fn errolSlow(val: f64, buffer: []u8) FloatDecimal {...@@ -171,25 +171,25 @@ fn errolSlow(val: f64, buffer: []u8) FloatDecimal {
171 var buf_index: usize = 0;171 var buf_index: usize = 0;
172 const bound = buffer.len - 1;172 const bound = buffer.len - 1;
173 while (buf_index < bound) {173 while (buf_index < bound) {
174 var hdig = @intFromFloat(u8, @floor(high.val));174 var hdig = @as(u8, @intFromFloat(@floor(high.val)));
175 if ((high.val == @floatFromInt(f64, hdig)) and (high.off < 0)) hdig -= 1;175 if ((high.val == @as(f64, @floatFromInt(hdig))) and (high.off < 0)) hdig -= 1;
176176
177 var ldig = @intFromFloat(u8, @floor(low.val));177 var ldig = @as(u8, @intFromFloat(@floor(low.val)));
178 if ((low.val == @floatFromInt(f64, ldig)) and (low.off < 0)) ldig -= 1;178 if ((low.val == @as(f64, @floatFromInt(ldig))) and (low.off < 0)) ldig -= 1;
179179
180 if (ldig != hdig) break;180 if (ldig != hdig) break;
181181
182 buffer[buf_index] = hdig + '0';182 buffer[buf_index] = hdig + '0';
183 buf_index += 1;183 buf_index += 1;
184 high.val -= @floatFromInt(f64, hdig);184 high.val -= @as(f64, @floatFromInt(hdig));
185 low.val -= @floatFromInt(f64, ldig);185 low.val -= @as(f64, @floatFromInt(ldig));
186 hpMul10(&high);186 hpMul10(&high);
187 hpMul10(&low);187 hpMul10(&low);
188 }188 }
189189
190 const tmp = (high.val + low.val) / 2.0;190 const tmp = (high.val + low.val) / 2.0;
191 var mdig = @intFromFloat(u8, @floor(tmp + 0.5));191 var mdig = @as(u8, @intFromFloat(@floor(tmp + 0.5)));
192 if ((@floatFromInt(f64, mdig) - tmp) == 0.5 and (mdig & 0x1) != 0) mdig -= 1;192 if ((@as(f64, @floatFromInt(mdig)) - tmp) == 0.5 and (mdig & 0x1) != 0) mdig -= 1;
193193
194 buffer[buf_index] = mdig + '0';194 buffer[buf_index] = mdig + '0';
195 buf_index += 1;195 buf_index += 1;
...@@ -248,9 +248,9 @@ fn split(val: f64, hi: *f64, lo: *f64) void {...@@ -248,9 +248,9 @@ fn split(val: f64, hi: *f64, lo: *f64) void {
248}248}
249249
250fn gethi(in: f64) f64 {250fn gethi(in: f64) f64 {
251 const bits = @bitCast(u64, in);251 const bits = @as(u64, @bitCast(in));
252 const new_bits = bits & 0xFFFFFFFFF8000000;252 const new_bits = bits & 0xFFFFFFFFF8000000;
253 return @bitCast(f64, new_bits);253 return @as(f64, @bitCast(new_bits));
254}254}
255255
256/// Normalize the number by factoring in the error.256/// Normalize the number by factoring in the error.
...@@ -303,21 +303,21 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {...@@ -303,21 +303,21 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
303303
304 assert((val > 9.007199254740992e15) and val < (3.40282366920938e38));304 assert((val > 9.007199254740992e15) and val < (3.40282366920938e38));
305305
306 var mid = @intFromFloat(u128, val);306 var mid = @as(u128, @intFromFloat(val));
307 var low: u128 = mid - fpeint((fpnext(val) - val) / 2.0);307 var low: u128 = mid - fpeint((fpnext(val) - val) / 2.0);
308 var high: u128 = mid + fpeint((val - fpprev(val)) / 2.0);308 var high: u128 = mid + fpeint((val - fpprev(val)) / 2.0);
309309
310 if (@bitCast(u64, val) & 0x1 != 0) {310 if (@as(u64, @bitCast(val)) & 0x1 != 0) {
311 high -= 1;311 high -= 1;
312 } else {312 } else {
313 low -= 1;313 low -= 1;
314 }314 }
315315
316 var l64 = @intCast(u64, low % pow19);316 var l64 = @as(u64, @intCast(low % pow19));
317 const lf = @intCast(u64, (low / pow19) % pow19);317 const lf = @as(u64, @intCast((low / pow19) % pow19));
318318
319 var h64 = @intCast(u64, high % pow19);319 var h64 = @as(u64, @intCast(high % pow19));
320 const hf = @intCast(u64, (high / pow19) % pow19);320 const hf = @as(u64, @intCast((high / pow19) % pow19));
321321
322 if (lf != hf) {322 if (lf != hf) {
323 l64 = lf;323 l64 = lf;
...@@ -333,7 +333,7 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {...@@ -333,7 +333,7 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
333 x *= 10;333 x *= 10;
334 }334 }
335 }335 }
336 const m64 = @truncate(u64, @divTrunc(mid, x));336 const m64 = @as(u64, @truncate(@divTrunc(mid, x)));
337337
338 if (lf != hf) mi += 19;338 if (lf != hf) mi += 19;
339339
...@@ -349,7 +349,7 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {...@@ -349,7 +349,7 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
349349
350 return FloatDecimal{350 return FloatDecimal{
351 .digits = buffer[0..buf_index],351 .digits = buffer[0..buf_index],
352 .exp = @intCast(i32, buf_index) + mi,352 .exp = @as(i32, @intCast(buf_index)) + mi,
353 };353 };
354}354}
355355
...@@ -360,33 +360,33 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {...@@ -360,33 +360,33 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
360fn errolFixed(val: f64, buffer: []u8) FloatDecimal {360fn errolFixed(val: f64, buffer: []u8) FloatDecimal {
361 assert((val >= 16.0) and (val < 9.007199254740992e15));361 assert((val >= 16.0) and (val < 9.007199254740992e15));
362362
363 const u = @intFromFloat(u64, val);363 const u = @as(u64, @intFromFloat(val));
364 const n = @floatFromInt(f64, u);364 const n = @as(f64, @floatFromInt(u));
365365
366 var mid = val - n;366 var mid = val - n;
367 var lo = ((fpprev(val) - n) + mid) / 2.0;367 var lo = ((fpprev(val) - n) + mid) / 2.0;
368 var hi = ((fpnext(val) - n) + mid) / 2.0;368 var hi = ((fpnext(val) - n) + mid) / 2.0;
369369
370 var buf_index = u64toa(u, buffer);370 var buf_index = u64toa(u, buffer);
371 var exp = @intCast(i32, buf_index);371 var exp = @as(i32, @intCast(buf_index));
372 var j = buf_index;372 var j = buf_index;
373 buffer[j] = 0;373 buffer[j] = 0;
374374
375 if (mid != 0.0) {375 if (mid != 0.0) {
376 while (mid != 0.0) {376 while (mid != 0.0) {
377 lo *= 10.0;377 lo *= 10.0;
378 const ldig = @intFromFloat(i32, lo);378 const ldig = @as(i32, @intFromFloat(lo));
379 lo -= @floatFromInt(f64, ldig);379 lo -= @as(f64, @floatFromInt(ldig));
380380
381 mid *= 10.0;381 mid *= 10.0;
382 const mdig = @intFromFloat(i32, mid);382 const mdig = @as(i32, @intFromFloat(mid));
383 mid -= @floatFromInt(f64, mdig);383 mid -= @as(f64, @floatFromInt(mdig));
384384
385 hi *= 10.0;385 hi *= 10.0;
386 const hdig = @intFromFloat(i32, hi);386 const hdig = @as(i32, @intFromFloat(hi));
387 hi -= @floatFromInt(f64, hdig);387 hi -= @as(f64, @floatFromInt(hdig));
388388
389 buffer[j] = @intCast(u8, mdig + '0');389 buffer[j] = @as(u8, @intCast(mdig + '0'));
390 j += 1;390 j += 1;
391391
392 if (hdig != ldig or j > 50) break;392 if (hdig != ldig or j > 50) break;
...@@ -413,11 +413,11 @@ fn errolFixed(val: f64, buffer: []u8) FloatDecimal {...@@ -413,11 +413,11 @@ fn errolFixed(val: f64, buffer: []u8) FloatDecimal {
413}413}
414414
415fn fpnext(val: f64) f64 {415fn fpnext(val: f64) f64 {
416 return @bitCast(f64, @bitCast(u64, val) +% 1);416 return @as(f64, @bitCast(@as(u64, @bitCast(val)) +% 1));
417}417}
418418
419fn fpprev(val: f64) f64 {419fn fpprev(val: f64) f64 {
420 return @bitCast(f64, @bitCast(u64, val) -% 1);420 return @as(f64, @bitCast(@as(u64, @bitCast(val)) -% 1));
421}421}
422422
423pub const c_digits_lut = [_]u8{423pub const c_digits_lut = [_]u8{
...@@ -453,7 +453,7 @@ fn u64toa(value_param: u64, buffer: []u8) usize {...@@ -453,7 +453,7 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
453 var buf_index: usize = 0;453 var buf_index: usize = 0;
454454
455 if (value < kTen8) {455 if (value < kTen8) {
456 const v = @intCast(u32, value);456 const v = @as(u32, @intCast(value));
457 if (v < 10000) {457 if (v < 10000) {
458 const d1: u32 = (v / 100) << 1;458 const d1: u32 = (v / 100) << 1;
459 const d2: u32 = (v % 100) << 1;459 const d2: u32 = (v % 100) << 1;
...@@ -508,8 +508,8 @@ fn u64toa(value_param: u64, buffer: []u8) usize {...@@ -508,8 +508,8 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
508 buf_index += 1;508 buf_index += 1;
509 }509 }
510 } else if (value < kTen16) {510 } else if (value < kTen16) {
511 const v0: u32 = @intCast(u32, value / kTen8);511 const v0: u32 = @as(u32, @intCast(value / kTen8));
512 const v1: u32 = @intCast(u32, value % kTen8);512 const v1: u32 = @as(u32, @intCast(value % kTen8));
513513
514 const b0: u32 = v0 / 10000;514 const b0: u32 = v0 / 10000;
515 const c0: u32 = v0 % 10000;515 const c0: u32 = v0 % 10000;
...@@ -579,11 +579,11 @@ fn u64toa(value_param: u64, buffer: []u8) usize {...@@ -579,11 +579,11 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
579 buffer[buf_index] = c_digits_lut[d8 + 1];579 buffer[buf_index] = c_digits_lut[d8 + 1];
580 buf_index += 1;580 buf_index += 1;
581 } else {581 } else {
582 const a = @intCast(u32, value / kTen16); // 1 to 1844582 const a = @as(u32, @intCast(value / kTen16)); // 1 to 1844
583 value %= kTen16;583 value %= kTen16;
584584
585 if (a < 10) {585 if (a < 10) {
586 buffer[buf_index] = '0' + @intCast(u8, a);586 buffer[buf_index] = '0' + @as(u8, @intCast(a));
587 buf_index += 1;587 buf_index += 1;
588 } else if (a < 100) {588 } else if (a < 100) {
589 const i: u32 = a << 1;589 const i: u32 = a << 1;
...@@ -592,7 +592,7 @@ fn u64toa(value_param: u64, buffer: []u8) usize {...@@ -592,7 +592,7 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
592 buffer[buf_index] = c_digits_lut[i + 1];592 buffer[buf_index] = c_digits_lut[i + 1];
593 buf_index += 1;593 buf_index += 1;
594 } else if (a < 1000) {594 } else if (a < 1000) {
595 buffer[buf_index] = '0' + @intCast(u8, a / 100);595 buffer[buf_index] = '0' + @as(u8, @intCast(a / 100));
596 buf_index += 1;596 buf_index += 1;
597597
598 const i: u32 = (a % 100) << 1;598 const i: u32 = (a % 100) << 1;
...@@ -613,8 +613,8 @@ fn u64toa(value_param: u64, buffer: []u8) usize {...@@ -613,8 +613,8 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
613 buf_index += 1;613 buf_index += 1;
614 }614 }
615615
616 const v0 = @intCast(u32, value / kTen8);616 const v0 = @as(u32, @intCast(value / kTen8));
617 const v1 = @intCast(u32, value % kTen8);617 const v1 = @as(u32, @intCast(value % kTen8));
618618
619 const b0: u32 = v0 / 10000;619 const b0: u32 = v0 / 10000;
620 const c0: u32 = v0 % 10000;620 const c0: u32 = v0 % 10000;
...@@ -672,10 +672,10 @@ fn u64toa(value_param: u64, buffer: []u8) usize {...@@ -672,10 +672,10 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
672}672}
673673
674fn fpeint(from: f64) u128 {674fn fpeint(from: f64) u128 {
675 const bits = @bitCast(u64, from);675 const bits = @as(u64, @bitCast(from));
676 assert((bits & ((1 << 52) - 1)) == 0);676 assert((bits & ((1 << 52) - 1)) == 0);
677677
678 return @as(u128, 1) << @truncate(u7, (bits >> 52) -% 1023);678 return @as(u128, 1) << @as(u7, @truncate((bits >> 52) -% 1023));
679}679}
680680
681/// Given two different integers with the same length in terms of the number681/// Given two different integers with the same length in terms of the number
lib/std/fmt/parse_float.zig+1-1
...@@ -78,7 +78,7 @@ test "fmt.parseFloat nan and inf" {...@@ -78,7 +78,7 @@ test "fmt.parseFloat nan and inf" {
78 inline for ([_]type{ f16, f32, f64, f128 }) |T| {78 inline for ([_]type{ f16, f32, f64, f128 }) |T| {
79 const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);79 const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
8080
81 try expectEqual(@bitCast(Z, try parseFloat(T, "nAn")), @bitCast(Z, std.math.nan(T)));81 try expectEqual(@as(Z, @bitCast(try parseFloat(T, "nAn"))), @as(Z, @bitCast(std.math.nan(T))));
82 try expectEqual(try parseFloat(T, "inF"), std.math.inf(T));82 try expectEqual(try parseFloat(T, "inF"), std.math.inf(T));
83 try expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T));83 try expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T));
84 }84 }
lib/std/fmt/parse_float/common.zig+5-5
...@@ -32,7 +32,7 @@ pub fn BiasedFp(comptime T: type) type {...@@ -32,7 +32,7 @@ pub fn BiasedFp(comptime T: type) type {
3232
33 pub fn toFloat(self: Self, comptime FloatT: type, negative: bool) FloatT {33 pub fn toFloat(self: Self, comptime FloatT: type, negative: bool) FloatT {
34 var word = self.f;34 var word = self.f;
35 word |= @intCast(MantissaT, self.e) << std.math.floatMantissaBits(FloatT);35 word |= @as(MantissaT, @intCast(self.e)) << std.math.floatMantissaBits(FloatT);
36 var f = floatFromUnsigned(FloatT, MantissaT, word);36 var f = floatFromUnsigned(FloatT, MantissaT, word);
37 if (negative) f = -f;37 if (negative) f = -f;
38 return f;38 return f;
...@@ -42,10 +42,10 @@ pub fn BiasedFp(comptime T: type) type {...@@ -42,10 +42,10 @@ pub fn BiasedFp(comptime T: type) type {
4242
43pub fn floatFromUnsigned(comptime T: type, comptime MantissaT: type, v: MantissaT) T {43pub fn floatFromUnsigned(comptime T: type, comptime MantissaT: type, v: MantissaT) T {
44 return switch (T) {44 return switch (T) {
45 f16 => @bitCast(f16, @truncate(u16, v)),45 f16 => @as(f16, @bitCast(@as(u16, @truncate(v)))),
46 f32 => @bitCast(f32, @truncate(u32, v)),46 f32 => @as(f32, @bitCast(@as(u32, @truncate(v)))),
47 f64 => @bitCast(f64, @truncate(u64, v)),47 f64 => @as(f64, @bitCast(@as(u64, @truncate(v)))),
48 f128 => @bitCast(f128, v),48 f128 => @as(f128, @bitCast(v)),
49 else => unreachable,49 else => unreachable,
50 };50 };
51}51}
lib/std/fmt/parse_float/convert_eisel_lemire.zig+8-8
...@@ -36,7 +36,7 @@ pub fn convertEiselLemire(comptime T: type, q: i64, w_: u64) ?BiasedFp(f64) {...@@ -36,7 +36,7 @@ pub fn convertEiselLemire(comptime T: type, q: i64, w_: u64) ?BiasedFp(f64) {
36 }36 }
3737
38 // Normalize our significant digits, so the most-significant bit is set.38 // Normalize our significant digits, so the most-significant bit is set.
39 const lz = @clz(@bitCast(u64, w));39 const lz = @clz(@as(u64, @bitCast(w)));
40 w = math.shl(u64, w, lz);40 w = math.shl(u64, w, lz);
4141
42 const r = computeProductApprox(q, w, float_info.mantissa_explicit_bits + 3);42 const r = computeProductApprox(q, w, float_info.mantissa_explicit_bits + 3);
...@@ -62,9 +62,9 @@ pub fn convertEiselLemire(comptime T: type, q: i64, w_: u64) ?BiasedFp(f64) {...@@ -62,9 +62,9 @@ pub fn convertEiselLemire(comptime T: type, q: i64, w_: u64) ?BiasedFp(f64) {
62 }62 }
63 }63 }
6464
65 const upper_bit = @intCast(i32, r.hi >> 63);65 const upper_bit = @as(i32, @intCast(r.hi >> 63));
66 var mantissa = math.shr(u64, r.hi, upper_bit + 64 - @intCast(i32, float_info.mantissa_explicit_bits) - 3);66 var mantissa = math.shr(u64, r.hi, upper_bit + 64 - @as(i32, @intCast(float_info.mantissa_explicit_bits)) - 3);
67 var power2 = power(@intCast(i32, q)) + upper_bit - @intCast(i32, lz) - float_info.minimum_exponent;67 var power2 = power(@as(i32, @intCast(q))) + upper_bit - @as(i32, @intCast(lz)) - float_info.minimum_exponent;
68 if (power2 <= 0) {68 if (power2 <= 0) {
69 if (-power2 + 1 >= 64) {69 if (-power2 + 1 >= 64) {
70 // Have more than 64 bits below the minimum exponent, must be 0.70 // Have more than 64 bits below the minimum exponent, must be 0.
...@@ -93,7 +93,7 @@ pub fn convertEiselLemire(comptime T: type, q: i64, w_: u64) ?BiasedFp(f64) {...@@ -93,7 +93,7 @@ pub fn convertEiselLemire(comptime T: type, q: i64, w_: u64) ?BiasedFp(f64) {
93 q >= float_info.min_exponent_round_to_even and93 q >= float_info.min_exponent_round_to_even and
94 q <= float_info.max_exponent_round_to_even and94 q <= float_info.max_exponent_round_to_even and
95 mantissa & 3 == 1 and95 mantissa & 3 == 1 and
96 math.shl(u64, mantissa, (upper_bit + 64 - @intCast(i32, float_info.mantissa_explicit_bits) - 3)) == r.hi)96 math.shl(u64, mantissa, (upper_bit + 64 - @as(i32, @intCast(float_info.mantissa_explicit_bits)) - 3)) == r.hi)
97 {97 {
98 // Zero the lowest bit, so we don't round up.98 // Zero the lowest bit, so we don't round up.
99 mantissa &= ~@as(u64, 1);99 mantissa &= ~@as(u64, 1);
...@@ -139,8 +139,8 @@ const U128 = struct {...@@ -139,8 +139,8 @@ const U128 = struct {
139 pub fn mul(a: u64, b: u64) U128 {139 pub fn mul(a: u64, b: u64) U128 {
140 const x = @as(u128, a) * b;140 const x = @as(u128, a) * b;
141 return .{141 return .{
142 .hi = @truncate(u64, x >> 64),142 .hi = @as(u64, @truncate(x >> 64)),
143 .lo = @truncate(u64, x),143 .lo = @as(u64, @truncate(x)),
144 };144 };
145 }145 }
146};146};
...@@ -161,7 +161,7 @@ fn computeProductApprox(q: i64, w: u64, comptime precision: usize) U128 {...@@ -161,7 +161,7 @@ fn computeProductApprox(q: i64, w: u64, comptime precision: usize) U128 {
161 // 5^q < 2^64, then the multiplication always provides an exact value.161 // 5^q < 2^64, then the multiplication always provides an exact value.
162 // That means whenever we need to round ties to even, we always have162 // That means whenever we need to round ties to even, we always have
163 // an exact value.163 // an exact value.
164 const index = @intCast(usize, q - @intCast(i64, eisel_lemire_smallest_power_of_five));164 const index = @as(usize, @intCast(q - @as(i64, @intCast(eisel_lemire_smallest_power_of_five))));
165 const pow5 = eisel_lemire_table_powers_of_five_128[index];165 const pow5 = eisel_lemire_table_powers_of_five_128[index];
166166
167 // Only need one multiplication as long as there is 1 zero but167 // Only need one multiplication as long as there is 1 zero but
lib/std/fmt/parse_float/convert_fast.zig+5-5
...@@ -108,19 +108,19 @@ pub fn convertFast(comptime T: type, n: Number(T)) ?T {...@@ -108,19 +108,19 @@ pub fn convertFast(comptime T: type, n: Number(T)) ?T {
108 var value: T = 0;108 var value: T = 0;
109 if (n.exponent <= info.max_exponent_fast_path) {109 if (n.exponent <= info.max_exponent_fast_path) {
110 // normal fast path110 // normal fast path
111 value = @floatFromInt(T, n.mantissa);111 value = @as(T, @floatFromInt(n.mantissa));
112 value = if (n.exponent < 0)112 value = if (n.exponent < 0)
113 value / fastPow10(T, @intCast(usize, -n.exponent))113 value / fastPow10(T, @as(usize, @intCast(-n.exponent)))
114 else114 else
115 value * fastPow10(T, @intCast(usize, n.exponent));115 value * fastPow10(T, @as(usize, @intCast(n.exponent)));
116 } else {116 } else {
117 // disguised fast path117 // disguised fast path
118 const shift = n.exponent - info.max_exponent_fast_path;118 const shift = n.exponent - info.max_exponent_fast_path;
119 const mantissa = math.mul(MantissaT, n.mantissa, fastIntPow10(MantissaT, @intCast(usize, shift))) catch return null;119 const mantissa = math.mul(MantissaT, n.mantissa, fastIntPow10(MantissaT, @as(usize, @intCast(shift)))) catch return null;
120 if (mantissa > info.max_mantissa_fast_path) {120 if (mantissa > info.max_mantissa_fast_path) {
121 return null;121 return null;
122 }122 }
123 value = @floatFromInt(T, mantissa) * fastPow10(T, info.max_exponent_fast_path);123 value = @as(T, @floatFromInt(mantissa)) * fastPow10(T, info.max_exponent_fast_path);
124 }124 }
125125
126 if (n.negative) {126 if (n.negative) {
lib/std/fmt/parse_float/convert_hex.zig+1-1
...@@ -81,7 +81,7 @@ pub fn convertHex(comptime T: type, n_: Number(T)) T {...@@ -81,7 +81,7 @@ pub fn convertHex(comptime T: type, n_: Number(T)) T {
81 }81 }
8282
83 var bits = n.mantissa & ((1 << mantissa_bits) - 1);83 var bits = n.mantissa & ((1 << mantissa_bits) - 1);
84 bits |= @intCast(MantissaT, (n.exponent - exp_bias) & ((1 << exp_bits) - 1)) << mantissa_bits;84 bits |= @as(MantissaT, @intCast((n.exponent - exp_bias) & ((1 << exp_bits) - 1))) << mantissa_bits;
85 if (n.negative) {85 if (n.negative) {
86 bits |= 1 << (mantissa_bits + exp_bits);86 bits |= 1 << (mantissa_bits + exp_bits);
87 }87 }
lib/std/fmt/parse_float/convert_slow.zig+6-6
...@@ -48,13 +48,13 @@ pub fn convertSlow(comptime T: type, s: []const u8) BiasedFp(T) {...@@ -48,13 +48,13 @@ pub fn convertSlow(comptime T: type, s: []const u8) BiasedFp(T) {
48 var exp2: i32 = 0;48 var exp2: i32 = 0;
49 // Shift right toward (1/2 .. 1]49 // Shift right toward (1/2 .. 1]
50 while (d.decimal_point > 0) {50 while (d.decimal_point > 0) {
51 const n = @intCast(usize, d.decimal_point);51 const n = @as(usize, @intCast(d.decimal_point));
52 const shift = getShift(n);52 const shift = getShift(n);
53 d.rightShift(shift);53 d.rightShift(shift);
54 if (d.decimal_point < -Decimal(T).decimal_point_range) {54 if (d.decimal_point < -Decimal(T).decimal_point_range) {
55 return BiasedFp(T).zero();55 return BiasedFp(T).zero();
56 }56 }
57 exp2 += @intCast(i32, shift);57 exp2 += @as(i32, @intCast(shift));
58 }58 }
59 // Shift left toward (1/2 .. 1]59 // Shift left toward (1/2 .. 1]
60 while (d.decimal_point <= 0) {60 while (d.decimal_point <= 0) {
...@@ -66,7 +66,7 @@ pub fn convertSlow(comptime T: type, s: []const u8) BiasedFp(T) {...@@ -66,7 +66,7 @@ pub fn convertSlow(comptime T: type, s: []const u8) BiasedFp(T) {
66 else => 1,66 else => 1,
67 };67 };
68 } else {68 } else {
69 const n = @intCast(usize, -d.decimal_point);69 const n = @as(usize, @intCast(-d.decimal_point));
70 break :blk getShift(n);70 break :blk getShift(n);
71 }71 }
72 };72 };
...@@ -74,17 +74,17 @@ pub fn convertSlow(comptime T: type, s: []const u8) BiasedFp(T) {...@@ -74,17 +74,17 @@ pub fn convertSlow(comptime T: type, s: []const u8) BiasedFp(T) {
74 if (d.decimal_point > Decimal(T).decimal_point_range) {74 if (d.decimal_point > Decimal(T).decimal_point_range) {
75 return BiasedFp(T).inf(T);75 return BiasedFp(T).inf(T);
76 }76 }
77 exp2 -= @intCast(i32, shift);77 exp2 -= @as(i32, @intCast(shift));
78 }78 }
79 // We are now in the range [1/2 .. 1] but the binary format uses [1 .. 2]79 // We are now in the range [1/2 .. 1] but the binary format uses [1 .. 2]
80 exp2 -= 1;80 exp2 -= 1;
81 while (min_exponent + 1 > exp2) {81 while (min_exponent + 1 > exp2) {
82 var n = @intCast(usize, (min_exponent + 1) - exp2);82 var n = @as(usize, @intCast((min_exponent + 1) - exp2));
83 if (n > max_shift) {83 if (n > max_shift) {
84 n = max_shift;84 n = max_shift;
85 }85 }
86 d.rightShift(n);86 d.rightShift(n);
87 exp2 += @intCast(i32, n);87 exp2 += @as(i32, @intCast(n));
88 }88 }
89 if (exp2 - min_exponent >= infinite_power) {89 if (exp2 - min_exponent >= infinite_power) {
90 return BiasedFp(T).inf(T);90 return BiasedFp(T).inf(T);
lib/std/fmt/parse_float/decimal.zig+10-10
...@@ -114,7 +114,7 @@ pub fn Decimal(comptime T: type) type {...@@ -114,7 +114,7 @@ pub fn Decimal(comptime T: type) type {
114 return math.maxInt(MantissaT);114 return math.maxInt(MantissaT);
115 }115 }
116116
117 const dp = @intCast(usize, self.decimal_point);117 const dp = @as(usize, @intCast(self.decimal_point));
118 var n: MantissaT = 0;118 var n: MantissaT = 0;
119119
120 var i: usize = 0;120 var i: usize = 0;
...@@ -155,7 +155,7 @@ pub fn Decimal(comptime T: type) type {...@@ -155,7 +155,7 @@ pub fn Decimal(comptime T: type) type {
155 const quotient = n / 10;155 const quotient = n / 10;
156 const remainder = n - (10 * quotient);156 const remainder = n - (10 * quotient);
157 if (write_index < max_digits) {157 if (write_index < max_digits) {
158 self.digits[write_index] = @intCast(u8, remainder);158 self.digits[write_index] = @as(u8, @intCast(remainder));
159 } else if (remainder > 0) {159 } else if (remainder > 0) {
160 self.truncated = true;160 self.truncated = true;
161 }161 }
...@@ -167,7 +167,7 @@ pub fn Decimal(comptime T: type) type {...@@ -167,7 +167,7 @@ pub fn Decimal(comptime T: type) type {
167 const quotient = n / 10;167 const quotient = n / 10;
168 const remainder = n - (10 * quotient);168 const remainder = n - (10 * quotient);
169 if (write_index < max_digits) {169 if (write_index < max_digits) {
170 self.digits[write_index] = @intCast(u8, remainder);170 self.digits[write_index] = @as(u8, @intCast(remainder));
171 } else if (remainder > 0) {171 } else if (remainder > 0) {
172 self.truncated = true;172 self.truncated = true;
173 }173 }
...@@ -178,7 +178,7 @@ pub fn Decimal(comptime T: type) type {...@@ -178,7 +178,7 @@ pub fn Decimal(comptime T: type) type {
178 if (self.num_digits > max_digits) {178 if (self.num_digits > max_digits) {
179 self.num_digits = max_digits;179 self.num_digits = max_digits;
180 }180 }
181 self.decimal_point += @intCast(i32, num_new_digits);181 self.decimal_point += @as(i32, @intCast(num_new_digits));
182 self.trim();182 self.trim();
183 }183 }
184184
...@@ -202,7 +202,7 @@ pub fn Decimal(comptime T: type) type {...@@ -202,7 +202,7 @@ pub fn Decimal(comptime T: type) type {
202 }202 }
203 }203 }
204204
205 self.decimal_point -= @intCast(i32, read_index) - 1;205 self.decimal_point -= @as(i32, @intCast(read_index)) - 1;
206 if (self.decimal_point < -decimal_point_range) {206 if (self.decimal_point < -decimal_point_range) {
207 self.num_digits = 0;207 self.num_digits = 0;
208 self.decimal_point = 0;208 self.decimal_point = 0;
...@@ -212,14 +212,14 @@ pub fn Decimal(comptime T: type) type {...@@ -212,14 +212,14 @@ pub fn Decimal(comptime T: type) type {
212212
213 const mask = math.shl(MantissaT, 1, shift) - 1;213 const mask = math.shl(MantissaT, 1, shift) - 1;
214 while (read_index < self.num_digits) {214 while (read_index < self.num_digits) {
215 const new_digit = @intCast(u8, math.shr(MantissaT, n, shift));215 const new_digit = @as(u8, @intCast(math.shr(MantissaT, n, shift)));
216 n = (10 * (n & mask)) + self.digits[read_index];216 n = (10 * (n & mask)) + self.digits[read_index];
217 read_index += 1;217 read_index += 1;
218 self.digits[write_index] = new_digit;218 self.digits[write_index] = new_digit;
219 write_index += 1;219 write_index += 1;
220 }220 }
221 while (n > 0) {221 while (n > 0) {
222 const new_digit = @intCast(u8, math.shr(MantissaT, n, shift));222 const new_digit = @as(u8, @intCast(math.shr(MantissaT, n, shift)));
223 n = 10 * (n & mask);223 n = 10 * (n & mask);
224 if (write_index < max_digits) {224 if (write_index < max_digits) {
225 self.digits[write_index] = new_digit;225 self.digits[write_index] = new_digit;
...@@ -268,7 +268,7 @@ pub fn Decimal(comptime T: type) type {...@@ -268,7 +268,7 @@ pub fn Decimal(comptime T: type) type {
268 while (stream.scanDigit(10)) |digit| {268 while (stream.scanDigit(10)) |digit| {
269 d.tryAddDigit(digit);269 d.tryAddDigit(digit);
270 }270 }
271 d.decimal_point = @intCast(i32, marker) - @intCast(i32, stream.offsetTrue());271 d.decimal_point = @as(i32, @intCast(marker)) - @as(i32, @intCast(stream.offsetTrue()));
272 }272 }
273 if (d.num_digits != 0) {273 if (d.num_digits != 0) {
274 // Ignore trailing zeros if any274 // Ignore trailing zeros if any
...@@ -284,9 +284,9 @@ pub fn Decimal(comptime T: type) type {...@@ -284,9 +284,9 @@ pub fn Decimal(comptime T: type) type {
284 i -= 1;284 i -= 1;
285 if (i == 0) break;285 if (i == 0) break;
286 }286 }
287 d.decimal_point += @intCast(i32, n_trailing_zeros);287 d.decimal_point += @as(i32, @intCast(n_trailing_zeros));
288 d.num_digits -= n_trailing_zeros;288 d.num_digits -= n_trailing_zeros;
289 d.decimal_point += @intCast(i32, d.num_digits);289 d.decimal_point += @as(i32, @intCast(d.num_digits));
290 if (d.num_digits > max_digits) {290 if (d.num_digits > max_digits) {
291 d.truncated = true;291 d.truncated = true;
292 d.num_digits = max_digits;292 d.num_digits = max_digits;
lib/std/fmt/parse_float/parse.zig+7-7
...@@ -21,7 +21,7 @@ fn parse8Digits(v_: u64) u64 {...@@ -21,7 +21,7 @@ fn parse8Digits(v_: u64) u64 {
21 v = (v * 10) + (v >> 8); // will not overflow, fits in 63 bits21 v = (v * 10) + (v >> 8); // will not overflow, fits in 63 bits
22 const v1 = (v & mask) *% mul1;22 const v1 = (v & mask) *% mul1;
23 const v2 = ((v >> 16) & mask) *% mul2;23 const v2 = ((v >> 16) & mask) *% mul2;
24 return @as(u64, @truncate(u32, (v1 +% v2) >> 32));24 return @as(u64, @as(u32, @truncate((v1 +% v2) >> 32)));
25}25}
2626
27/// Parse digits until a non-digit character is found.27/// Parse digits until a non-digit character is found.
...@@ -106,7 +106,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool...@@ -106,7 +106,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
106 var mantissa: MantissaT = 0;106 var mantissa: MantissaT = 0;
107 tryParseDigits(MantissaT, stream, &mantissa, info.base);107 tryParseDigits(MantissaT, stream, &mantissa, info.base);
108 var int_end = stream.offsetTrue();108 var int_end = stream.offsetTrue();
109 var n_digits = @intCast(isize, stream.offsetTrue());109 var n_digits = @as(isize, @intCast(stream.offsetTrue()));
110 // the base being 16 implies a 0x prefix, which shouldn't be included in the digit count110 // the base being 16 implies a 0x prefix, which shouldn't be included in the digit count
111 if (info.base == 16) n_digits -= 2;111 if (info.base == 16) n_digits -= 2;
112112
...@@ -117,8 +117,8 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool...@@ -117,8 +117,8 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
117 const marker = stream.offsetTrue();117 const marker = stream.offsetTrue();
118 tryParseDigits(MantissaT, stream, &mantissa, info.base);118 tryParseDigits(MantissaT, stream, &mantissa, info.base);
119 const n_after_dot = stream.offsetTrue() - marker;119 const n_after_dot = stream.offsetTrue() - marker;
120 exponent = -@intCast(i64, n_after_dot);120 exponent = -@as(i64, @intCast(n_after_dot));
121 n_digits += @intCast(isize, n_after_dot);121 n_digits += @as(isize, @intCast(n_after_dot));
122 }122 }
123123
124 // adjust required shift to offset mantissa for base-16 (2^4)124 // adjust required shift to offset mantissa for base-16 (2^4)
...@@ -163,7 +163,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool...@@ -163,7 +163,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
163 // '0' = '.' + 2163 // '0' = '.' + 2
164 const next = stream.firstUnchecked();164 const next = stream.firstUnchecked();
165 if (next != '_') {165 if (next != '_') {
166 n_digits -= @intCast(isize, next -| ('0' - 1));166 n_digits -= @as(isize, @intCast(next -| ('0' - 1)));
167 } else {167 } else {
168 stream.underscore_count += 1;168 stream.underscore_count += 1;
169 }169 }
...@@ -179,7 +179,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool...@@ -179,7 +179,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
179 exponent = blk: {179 exponent = blk: {
180 if (mantissa >= min_n_digit_int(MantissaT, info.max_mantissa_digits)) {180 if (mantissa >= min_n_digit_int(MantissaT, info.max_mantissa_digits)) {
181 // big int181 // big int
182 break :blk @intCast(i64, int_end) - @intCast(i64, stream.offsetTrue());182 break :blk @as(i64, @intCast(int_end)) - @as(i64, @intCast(stream.offsetTrue()));
183 } else {183 } else {
184 // the next byte must be present and be '.'184 // the next byte must be present and be '.'
185 // We know this is true because we had more than 19185 // We know this is true because we had more than 19
...@@ -190,7 +190,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool...@@ -190,7 +190,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
190 stream.advance(1);190 stream.advance(1);
191 var marker = stream.offsetTrue();191 var marker = stream.offsetTrue();
192 tryParseNDigits(MantissaT, stream, &mantissa, info.base, info.max_mantissa_digits);192 tryParseNDigits(MantissaT, stream, &mantissa, info.base, info.max_mantissa_digits);
193 break :blk @intCast(i64, marker) - @intCast(i64, stream.offsetTrue());193 break :blk @as(i64, @intCast(marker)) - @as(i64, @intCast(stream.offsetTrue()));
194 }194 }
195 };195 };
196 // add back the explicit part196 // add back the explicit part
lib/std/fs.zig+18-19
...@@ -373,13 +373,13 @@ pub const IterableDir = struct {...@@ -373,13 +373,13 @@ pub const IterableDir = struct {
373 }373 }
374 }374 }
375 self.index = 0;375 self.index = 0;
376 self.end_index = @intCast(usize, rc);376 self.end_index = @as(usize, @intCast(rc));
377 }377 }
378 const darwin_entry = @ptrCast(*align(1) os.system.dirent, &self.buf[self.index]);378 const darwin_entry = @as(*align(1) os.system.dirent, @ptrCast(&self.buf[self.index]));
379 const next_index = self.index + darwin_entry.reclen();379 const next_index = self.index + darwin_entry.reclen();
380 self.index = next_index;380 self.index = next_index;
381381
382 const name = @ptrCast([*]u8, &darwin_entry.d_name)[0..darwin_entry.d_namlen];382 const name = @as([*]u8, @ptrCast(&darwin_entry.d_name))[0..darwin_entry.d_namlen];
383383
384 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or (darwin_entry.d_ino == 0)) {384 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or (darwin_entry.d_ino == 0)) {
385 continue :start_over;385 continue :start_over;
...@@ -421,13 +421,13 @@ pub const IterableDir = struct {...@@ -421,13 +421,13 @@ pub const IterableDir = struct {
421 }421 }
422 if (rc == 0) return null;422 if (rc == 0) return null;
423 self.index = 0;423 self.index = 0;
424 self.end_index = @intCast(usize, rc);424 self.end_index = @as(usize, @intCast(rc));
425 }425 }
426 const entry = @ptrCast(*align(1) os.system.dirent, &self.buf[self.index]);426 const entry = @as(*align(1) os.system.dirent, @ptrCast(&self.buf[self.index]));
427 const next_index = self.index + entry.reclen();427 const next_index = self.index + entry.reclen();
428 self.index = next_index;428 self.index = next_index;
429429
430 const name = mem.sliceTo(@ptrCast([*:0]u8, &entry.d_name), 0);430 const name = mem.sliceTo(@as([*:0]u8, @ptrCast(&entry.d_name)), 0);
431 if (mem.eql(u8, name, ".") or mem.eql(u8, name, ".."))431 if (mem.eql(u8, name, ".") or mem.eql(u8, name, ".."))
432 continue :start_over;432 continue :start_over;
433433
...@@ -485,13 +485,13 @@ pub const IterableDir = struct {...@@ -485,13 +485,13 @@ pub const IterableDir = struct {
485 }485 }
486 if (rc == 0) return null;486 if (rc == 0) return null;
487 self.index = 0;487 self.index = 0;
488 self.end_index = @intCast(usize, rc);488 self.end_index = @as(usize, @intCast(rc));
489 }489 }
490 const bsd_entry = @ptrCast(*align(1) os.system.dirent, &self.buf[self.index]);490 const bsd_entry = @as(*align(1) os.system.dirent, @ptrCast(&self.buf[self.index]));
491 const next_index = self.index + bsd_entry.reclen();491 const next_index = self.index + bsd_entry.reclen();
492 self.index = next_index;492 self.index = next_index;
493493
494 const name = @ptrCast([*]u8, &bsd_entry.d_name)[0..bsd_entry.d_namlen];494 const name = @as([*]u8, @ptrCast(&bsd_entry.d_name))[0..bsd_entry.d_namlen];
495495
496 const skip_zero_fileno = switch (builtin.os.tag) {496 const skip_zero_fileno = switch (builtin.os.tag) {
497 // d_fileno=0 is used to mark invalid entries or deleted files.497 // d_fileno=0 is used to mark invalid entries or deleted files.
...@@ -567,12 +567,12 @@ pub const IterableDir = struct {...@@ -567,12 +567,12 @@ pub const IterableDir = struct {
567 }567 }
568 }568 }
569 self.index = 0;569 self.index = 0;
570 self.end_index = @intCast(usize, rc);570 self.end_index = @as(usize, @intCast(rc));
571 }571 }
572 const haiku_entry = @ptrCast(*align(1) os.system.dirent, &self.buf[self.index]);572 const haiku_entry = @as(*align(1) os.system.dirent, @ptrCast(&self.buf[self.index]));
573 const next_index = self.index + haiku_entry.reclen();573 const next_index = self.index + haiku_entry.reclen();
574 self.index = next_index;574 self.index = next_index;
575 const name = mem.sliceTo(@ptrCast([*:0]u8, &haiku_entry.d_name), 0);575 const name = mem.sliceTo(@as([*:0]u8, @ptrCast(&haiku_entry.d_name)), 0);
576576
577 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or (haiku_entry.d_ino == 0)) {577 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or (haiku_entry.d_ino == 0)) {
578 continue :start_over;578 continue :start_over;
...@@ -672,11 +672,11 @@ pub const IterableDir = struct {...@@ -672,11 +672,11 @@ pub const IterableDir = struct {
672 self.index = 0;672 self.index = 0;
673 self.end_index = rc;673 self.end_index = rc;
674 }674 }
675 const linux_entry = @ptrCast(*align(1) linux.dirent64, &self.buf[self.index]);675 const linux_entry = @as(*align(1) linux.dirent64, @ptrCast(&self.buf[self.index]));
676 const next_index = self.index + linux_entry.reclen();676 const next_index = self.index + linux_entry.reclen();
677 self.index = next_index;677 self.index = next_index;
678678
679 const name = mem.sliceTo(@ptrCast([*:0]u8, &linux_entry.d_name), 0);679 const name = mem.sliceTo(@as([*:0]u8, @ptrCast(&linux_entry.d_name)), 0);
680680
681 // skip . and .. entries681 // skip . and .. entries
682 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {682 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {
...@@ -750,15 +750,14 @@ pub const IterableDir = struct {...@@ -750,15 +750,14 @@ pub const IterableDir = struct {
750 }750 }
751 }751 }
752752
753 const aligned_ptr = @alignCast(@alignOf(w.FILE_BOTH_DIR_INFORMATION), &self.buf[self.index]);753 const dir_info: *w.FILE_BOTH_DIR_INFORMATION = @ptrCast(@alignCast(&self.buf[self.index]));
754 const dir_info = @ptrCast(*w.FILE_BOTH_DIR_INFORMATION, aligned_ptr);
755 if (dir_info.NextEntryOffset != 0) {754 if (dir_info.NextEntryOffset != 0) {
756 self.index += dir_info.NextEntryOffset;755 self.index += dir_info.NextEntryOffset;
757 } else {756 } else {
758 self.index = self.buf.len;757 self.index = self.buf.len;
759 }758 }
760759
761 const name_utf16le = @ptrCast([*]u16, &dir_info.FileName)[0 .. dir_info.FileNameLength / 2];760 const name_utf16le = @as([*]u16, @ptrCast(&dir_info.FileName))[0 .. dir_info.FileNameLength / 2];
762761
763 if (mem.eql(u16, name_utf16le, &[_]u16{'.'}) or mem.eql(u16, name_utf16le, &[_]u16{ '.', '.' }))762 if (mem.eql(u16, name_utf16le, &[_]u16{'.'}) or mem.eql(u16, name_utf16le, &[_]u16{ '.', '.' }))
764 continue;763 continue;
...@@ -835,7 +834,7 @@ pub const IterableDir = struct {...@@ -835,7 +834,7 @@ pub const IterableDir = struct {
835 self.index = 0;834 self.index = 0;
836 self.end_index = bufused;835 self.end_index = bufused;
837 }836 }
838 const entry = @ptrCast(*align(1) w.dirent_t, &self.buf[self.index]);837 const entry = @as(*align(1) w.dirent_t, @ptrCast(&self.buf[self.index]));
839 const entry_size = @sizeOf(w.dirent_t);838 const entry_size = @sizeOf(w.dirent_t);
840 const name_index = self.index + entry_size;839 const name_index = self.index + entry_size;
841 if (name_index + entry.d_namlen > self.end_index) {840 if (name_index + entry.d_namlen > self.end_index) {
...@@ -1789,7 +1788,7 @@ pub const Dir = struct {...@@ -1789,7 +1788,7 @@ pub const Dir = struct {
1789 .fd = undefined,1788 .fd = undefined,
1790 };1789 };
17911790
1792 const path_len_bytes = @intCast(u16, mem.sliceTo(sub_path_w, 0).len * 2);1791 const path_len_bytes = @as(u16, @intCast(mem.sliceTo(sub_path_w, 0).len * 2));
1793 var nt_name = w.UNICODE_STRING{1792 var nt_name = w.UNICODE_STRING{
1794 .Length = path_len_bytes,1793 .Length = path_len_bytes,
1795 .MaximumLength = path_len_bytes,1794 .MaximumLength = path_len_bytes,
lib/std/fs/file.zig+9-9
...@@ -368,7 +368,7 @@ pub const File = struct {...@@ -368,7 +368,7 @@ pub const File = struct {
368368
369 return Stat{369 return Stat{
370 .inode = st.ino,370 .inode = st.ino,
371 .size = @bitCast(u64, st.size),371 .size = @as(u64, @bitCast(st.size)),
372 .mode = st.mode,372 .mode = st.mode,
373 .kind = kind,373 .kind = kind,
374 .atime = @as(i128, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,374 .atime = @as(i128, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
...@@ -398,7 +398,7 @@ pub const File = struct {...@@ -398,7 +398,7 @@ pub const File = struct {
398 }398 }
399 return Stat{399 return Stat{
400 .inode = info.InternalInformation.IndexNumber,400 .inode = info.InternalInformation.IndexNumber,
401 .size = @bitCast(u64, info.StandardInformation.EndOfFile),401 .size = @as(u64, @bitCast(info.StandardInformation.EndOfFile)),
402 .mode = 0,402 .mode = 0,
403 .kind = if (info.StandardInformation.Directory == 0) .file else .directory,403 .kind = if (info.StandardInformation.Directory == 0) .file else .directory,
404 .atime = windows.fromSysTime(info.BasicInformation.LastAccessTime),404 .atime = windows.fromSysTime(info.BasicInformation.LastAccessTime),
...@@ -650,7 +650,7 @@ pub const File = struct {...@@ -650,7 +650,7 @@ pub const File = struct {
650650
651 /// Returns the size of the file651 /// Returns the size of the file
652 pub fn size(self: Self) u64 {652 pub fn size(self: Self) u64 {
653 return @intCast(u64, self.stat.size);653 return @as(u64, @intCast(self.stat.size));
654 }654 }
655655
656 /// Returns a `Permissions` struct, representing the permissions on the file656 /// Returns a `Permissions` struct, representing the permissions on the file
...@@ -855,7 +855,7 @@ pub const File = struct {...@@ -855,7 +855,7 @@ pub const File = struct {
855 if (info.BasicInformation.FileAttributes & windows.FILE_ATTRIBUTE_REPARSE_POINT != 0) {855 if (info.BasicInformation.FileAttributes & windows.FILE_ATTRIBUTE_REPARSE_POINT != 0) {
856 var reparse_buf: [windows.MAXIMUM_REPARSE_DATA_BUFFER_SIZE]u8 = undefined;856 var reparse_buf: [windows.MAXIMUM_REPARSE_DATA_BUFFER_SIZE]u8 = undefined;
857 try windows.DeviceIoControl(self.handle, windows.FSCTL_GET_REPARSE_POINT, null, reparse_buf[0..]);857 try windows.DeviceIoControl(self.handle, windows.FSCTL_GET_REPARSE_POINT, null, reparse_buf[0..]);
858 const reparse_struct = @ptrCast(*const windows.REPARSE_DATA_BUFFER, @alignCast(@alignOf(windows.REPARSE_DATA_BUFFER), &reparse_buf[0]));858 const reparse_struct: *const windows.REPARSE_DATA_BUFFER = @ptrCast(@alignCast(&reparse_buf[0]));
859 break :reparse_blk reparse_struct.ReparseTag;859 break :reparse_blk reparse_struct.ReparseTag;
860 }860 }
861 break :reparse_blk 0;861 break :reparse_blk 0;
...@@ -864,7 +864,7 @@ pub const File = struct {...@@ -864,7 +864,7 @@ pub const File = struct {
864 break :blk MetadataWindows{864 break :blk MetadataWindows{
865 .attributes = info.BasicInformation.FileAttributes,865 .attributes = info.BasicInformation.FileAttributes,
866 .reparse_tag = reparse_tag,866 .reparse_tag = reparse_tag,
867 ._size = @bitCast(u64, info.StandardInformation.EndOfFile),867 ._size = @as(u64, @bitCast(info.StandardInformation.EndOfFile)),
868 .access_time = windows.fromSysTime(info.BasicInformation.LastAccessTime),868 .access_time = windows.fromSysTime(info.BasicInformation.LastAccessTime),
869 .modified_time = windows.fromSysTime(info.BasicInformation.LastWriteTime),869 .modified_time = windows.fromSysTime(info.BasicInformation.LastWriteTime),
870 .creation_time = windows.fromSysTime(info.BasicInformation.CreationTime),870 .creation_time = windows.fromSysTime(info.BasicInformation.CreationTime),
...@@ -881,16 +881,16 @@ pub const File = struct {...@@ -881,16 +881,16 @@ pub const File = struct {
881 .NOSYS => {881 .NOSYS => {
882 const st = try os.fstat(self.handle);882 const st = try os.fstat(self.handle);
883883
884 stx.mode = @intCast(u16, st.mode);884 stx.mode = @as(u16, @intCast(st.mode));
885885
886 // Hacky conversion from timespec to statx_timestamp886 // Hacky conversion from timespec to statx_timestamp
887 stx.atime = std.mem.zeroes(os.linux.statx_timestamp);887 stx.atime = std.mem.zeroes(os.linux.statx_timestamp);
888 stx.atime.tv_sec = st.atim.tv_sec;888 stx.atime.tv_sec = st.atim.tv_sec;
889 stx.atime.tv_nsec = @intCast(u32, st.atim.tv_nsec); // Guaranteed to succeed (tv_nsec is always below 10^9)889 stx.atime.tv_nsec = @as(u32, @intCast(st.atim.tv_nsec)); // Guaranteed to succeed (tv_nsec is always below 10^9)
890890
891 stx.mtime = std.mem.zeroes(os.linux.statx_timestamp);891 stx.mtime = std.mem.zeroes(os.linux.statx_timestamp);
892 stx.mtime.tv_sec = st.mtim.tv_sec;892 stx.mtime.tv_sec = st.mtim.tv_sec;
893 stx.mtime.tv_nsec = @intCast(u32, st.mtim.tv_nsec);893 stx.mtime.tv_nsec = @as(u32, @intCast(st.mtim.tv_nsec));
894894
895 stx.mask = os.linux.STATX_BASIC_STATS | os.linux.STATX_MTIME;895 stx.mask = os.linux.STATX_BASIC_STATS | os.linux.STATX_MTIME;
896 },896 },
...@@ -1414,7 +1414,7 @@ pub const File = struct {...@@ -1414,7 +1414,7 @@ pub const File = struct {
1414 amt = try os.sendfile(out_fd, in_fd, offset + off, count - off, zero_iovec, trailers, flags);1414 amt = try os.sendfile(out_fd, in_fd, offset + off, count - off, zero_iovec, trailers, flags);
1415 off += amt;1415 off += amt;
1416 }1416 }
1417 amt = @intCast(usize, off - count);1417 amt = @as(usize, @intCast(off - count));
1418 }1418 }
1419 var i: usize = 0;1419 var i: usize = 0;
1420 while (i < trailers.len) {1420 while (i < trailers.len) {
lib/std/fs/get_app_data_dir.zig+1-1
...@@ -23,7 +23,7 @@ pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDi...@@ -23,7 +23,7 @@ pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDi
23 &dir_path_ptr,23 &dir_path_ptr,
24 )) {24 )) {
25 os.windows.S_OK => {25 os.windows.S_OK => {
26 defer os.windows.ole32.CoTaskMemFree(@ptrCast(*anyopaque, dir_path_ptr));26 defer os.windows.ole32.CoTaskMemFree(@as(*anyopaque, @ptrCast(dir_path_ptr)));
27 const global_dir = unicode.utf16leToUtf8Alloc(allocator, mem.sliceTo(dir_path_ptr, 0)) catch |err| switch (err) {27 const global_dir = unicode.utf16leToUtf8Alloc(allocator, mem.sliceTo(dir_path_ptr, 0)) catch |err| switch (err) {
28 error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,28 error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
29 error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,29 error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
lib/std/fs/wasi.zig+2-2
...@@ -17,7 +17,7 @@ pub const Preopens = struct {...@@ -17,7 +17,7 @@ pub const Preopens = struct {
17 pub fn find(p: Preopens, name: []const u8) ?os.fd_t {17 pub fn find(p: Preopens, name: []const u8) ?os.fd_t {
18 for (p.names, 0..) |elem_name, i| {18 for (p.names, 0..) |elem_name, i| {
19 if (mem.eql(u8, elem_name, name)) {19 if (mem.eql(u8, elem_name, name)) {
20 return @intCast(os.fd_t, i);20 return @as(os.fd_t, @intCast(i));
21 }21 }
22 }22 }
23 return null;23 return null;
...@@ -34,7 +34,7 @@ pub fn preopensAlloc(gpa: Allocator) Allocator.Error!Preopens {...@@ -34,7 +34,7 @@ pub fn preopensAlloc(gpa: Allocator) Allocator.Error!Preopens {
34 names.appendAssumeCapacity("stdout"); // 134 names.appendAssumeCapacity("stdout"); // 1
35 names.appendAssumeCapacity("stderr"); // 235 names.appendAssumeCapacity("stderr"); // 2
36 while (true) {36 while (true) {
37 const fd = @intCast(wasi.fd_t, names.items.len);37 const fd = @as(wasi.fd_t, @intCast(names.items.len));
38 var prestat: prestat_t = undefined;38 var prestat: prestat_t = undefined;
39 switch (wasi.fd_prestat_get(fd, &prestat)) {39 switch (wasi.fd_prestat_get(fd, &prestat)) {
40 .SUCCESS => {},40 .SUCCESS => {},
lib/std/fs/watch.zig+8-8
...@@ -279,7 +279,7 @@ pub fn Watch(comptime V: type) type {...@@ -279,7 +279,7 @@ pub fn Watch(comptime V: type) type {
279279
280 while (!put.cancelled) {280 while (!put.cancelled) {
281 kev.* = os.Kevent{281 kev.* = os.Kevent{
282 .ident = @intCast(usize, fd),282 .ident = @as(usize, @intCast(fd)),
283 .filter = os.EVFILT_VNODE,283 .filter = os.EVFILT_VNODE,
284 .flags = os.EV_ADD | os.EV_ENABLE | os.EV_CLEAR | os.EV_ONESHOT |284 .flags = os.EV_ADD | os.EV_ENABLE | os.EV_CLEAR | os.EV_ONESHOT |
285 os.NOTE_WRITE | os.NOTE_DELETE | os.NOTE_REVOKE,285 os.NOTE_WRITE | os.NOTE_DELETE | os.NOTE_REVOKE,
...@@ -487,14 +487,14 @@ pub fn Watch(comptime V: type) type {...@@ -487,14 +487,14 @@ pub fn Watch(comptime V: type) type {
487 var ptr: [*]u8 = &event_buf;487 var ptr: [*]u8 = &event_buf;
488 const end_ptr = ptr + bytes_transferred;488 const end_ptr = ptr + bytes_transferred;
489 while (@intFromPtr(ptr) < @intFromPtr(end_ptr)) {489 while (@intFromPtr(ptr) < @intFromPtr(end_ptr)) {
490 const ev = @ptrCast(*const windows.FILE_NOTIFY_INFORMATION, ptr);490 const ev = @as(*const windows.FILE_NOTIFY_INFORMATION, @ptrCast(ptr));
491 const emit = switch (ev.Action) {491 const emit = switch (ev.Action) {
492 windows.FILE_ACTION_REMOVED => WatchEventId.Delete,492 windows.FILE_ACTION_REMOVED => WatchEventId.Delete,
493 windows.FILE_ACTION_MODIFIED => .CloseWrite,493 windows.FILE_ACTION_MODIFIED => .CloseWrite,
494 else => null,494 else => null,
495 };495 };
496 if (emit) |id| {496 if (emit) |id| {
497 const basename_ptr = @ptrCast([*]u16, ptr + @sizeOf(windows.FILE_NOTIFY_INFORMATION));497 const basename_ptr = @as([*]u16, @ptrCast(ptr + @sizeOf(windows.FILE_NOTIFY_INFORMATION)));
498 const basename_utf16le = basename_ptr[0 .. ev.FileNameLength / 2];498 const basename_utf16le = basename_ptr[0 .. ev.FileNameLength / 2];
499 var basename_data: [std.fs.MAX_PATH_BYTES]u8 = undefined;499 var basename_data: [std.fs.MAX_PATH_BYTES]u8 = undefined;
500 const basename = basename_data[0 .. std.unicode.utf16leToUtf8(&basename_data, basename_utf16le) catch unreachable];500 const basename = basename_data[0 .. std.unicode.utf16leToUtf8(&basename_data, basename_utf16le) catch unreachable];
...@@ -510,7 +510,7 @@ pub fn Watch(comptime V: type) type {...@@ -510,7 +510,7 @@ pub fn Watch(comptime V: type) type {
510 }510 }
511511
512 if (ev.NextEntryOffset == 0) break;512 if (ev.NextEntryOffset == 0) break;
513 ptr = @alignCast(@alignOf(windows.FILE_NOTIFY_INFORMATION), ptr + ev.NextEntryOffset);513 ptr = @alignCast(ptr + ev.NextEntryOffset);
514 }514 }
515 }515 }
516 }516 }
...@@ -586,10 +586,10 @@ pub fn Watch(comptime V: type) type {...@@ -586,10 +586,10 @@ pub fn Watch(comptime V: type) type {
586 var ptr: [*]u8 = &event_buf;586 var ptr: [*]u8 = &event_buf;
587 const end_ptr = ptr + bytes_read;587 const end_ptr = ptr + bytes_read;
588 while (@intFromPtr(ptr) < @intFromPtr(end_ptr)) {588 while (@intFromPtr(ptr) < @intFromPtr(end_ptr)) {
589 const ev = @ptrCast(*const os.linux.inotify_event, ptr);589 const ev = @as(*const os.linux.inotify_event, @ptrCast(ptr));
590 if (ev.mask & os.linux.IN_CLOSE_WRITE == os.linux.IN_CLOSE_WRITE) {590 if (ev.mask & os.linux.IN_CLOSE_WRITE == os.linux.IN_CLOSE_WRITE) {
591 const basename_ptr = ptr + @sizeOf(os.linux.inotify_event);591 const basename_ptr = ptr + @sizeOf(os.linux.inotify_event);
592 const basename = std.mem.span(@ptrCast([*:0]u8, basename_ptr));592 const basename = std.mem.span(@as([*:0]u8, @ptrCast(basename_ptr)));
593593
594 const dir = &self.os_data.wd_table.get(ev.wd).?;594 const dir = &self.os_data.wd_table.get(ev.wd).?;
595 if (dir.file_table.getEntry(basename)) |file_value| {595 if (dir.file_table.getEntry(basename)) |file_value| {
...@@ -615,7 +615,7 @@ pub fn Watch(comptime V: type) type {...@@ -615,7 +615,7 @@ pub fn Watch(comptime V: type) type {
615 } else if (ev.mask & os.linux.IN_DELETE == os.linux.IN_DELETE) {615 } else if (ev.mask & os.linux.IN_DELETE == os.linux.IN_DELETE) {
616 // File or directory was removed or deleted616 // File or directory was removed or deleted
617 const basename_ptr = ptr + @sizeOf(os.linux.inotify_event);617 const basename_ptr = ptr + @sizeOf(os.linux.inotify_event);
618 const basename = std.mem.span(@ptrCast([*:0]u8, basename_ptr));618 const basename = std.mem.span(@as([*:0]u8, @ptrCast(basename_ptr)));
619619
620 const dir = &self.os_data.wd_table.get(ev.wd).?;620 const dir = &self.os_data.wd_table.get(ev.wd).?;
621 if (dir.file_table.getEntry(basename)) |file_value| {621 if (dir.file_table.getEntry(basename)) |file_value| {
...@@ -628,7 +628,7 @@ pub fn Watch(comptime V: type) type {...@@ -628,7 +628,7 @@ pub fn Watch(comptime V: type) type {
628 }628 }
629 }629 }
630630
631 ptr = @alignCast(@alignOf(os.linux.inotify_event), ptr + @sizeOf(os.linux.inotify_event) + ev.len);631 ptr = @alignCast(ptr + @sizeOf(os.linux.inotify_event) + ev.len);
632 }632 }
633 }633 }
634 }634 }
lib/std/hash/adler.zig+1-1
...@@ -118,7 +118,7 @@ test "adler32 very long with variation" {...@@ -118,7 +118,7 @@ test "adler32 very long with variation" {
118118
119 var i: usize = 0;119 var i: usize = 0;
120 while (i < result.len) : (i += 1) {120 while (i < result.len) : (i += 1) {
121 result[i] = @truncate(u8, i);121 result[i] = @as(u8, @truncate(i));
122 }122 }
123123
124 break :blk result;124 break :blk result;
lib/std/hash/auto_hash.zig+2-2
...@@ -92,10 +92,10 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {...@@ -92,10 +92,10 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
92 // Help the optimizer see that hashing an int is easy by inlining!92 // Help the optimizer see that hashing an int is easy by inlining!
93 // TODO Check if the situation is better after #561 is resolved.93 // TODO Check if the situation is better after #561 is resolved.
94 .Int => |int| switch (int.signedness) {94 .Int => |int| switch (int.signedness) {
95 .signed => hash(hasher, @bitCast(@Type(.{ .Int = .{95 .signed => hash(hasher, @as(@Type(.{ .Int = .{
96 .bits = int.bits,96 .bits = int.bits,
97 .signedness = .unsigned,97 .signedness = .unsigned,
98 } }), key), strat),98 } }), @bitCast(key)), strat),
99 .unsigned => {99 .unsigned => {
100 if (comptime meta.trait.hasUniqueRepresentation(Key)) {100 if (comptime meta.trait.hasUniqueRepresentation(Key)) {
101 @call(.always_inline, Hasher.update, .{ hasher, std.mem.asBytes(&key) });101 @call(.always_inline, Hasher.update, .{ hasher, std.mem.asBytes(&key) });
lib/std/hash/benchmark.zig+6-6
...@@ -122,13 +122,13 @@ pub fn benchmarkHash(comptime H: anytype, bytes: usize, allocator: std.mem.Alloc...@@ -122,13 +122,13 @@ pub fn benchmarkHash(comptime H: anytype, bytes: usize, allocator: std.mem.Alloc
122 for (0..blocks_count) |i| {122 for (0..blocks_count) |i| {
123 h.update(blocks[i * alignment ..][0..block_size]);123 h.update(blocks[i * alignment ..][0..block_size]);
124 }124 }
125 const final = if (H.has_crypto_api) @truncate(u64, h.finalInt()) else h.final();125 const final = if (H.has_crypto_api) @as(u64, @truncate(h.finalInt())) else h.final();
126 std.mem.doNotOptimizeAway(final);126 std.mem.doNotOptimizeAway(final);
127127
128 const end = timer.read();128 const end = timer.read();
129129
130 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;130 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
131 const throughput = @intFromFloat(u64, @floatFromInt(f64, bytes) / elapsed_s);131 const throughput = @as(u64, @intFromFloat(@as(f64, @floatFromInt(bytes)) / elapsed_s));
132132
133 return Result{133 return Result{
134 .hash = final,134 .hash = final,
...@@ -152,7 +152,7 @@ pub fn benchmarkHashSmallKeys(comptime H: anytype, key_size: usize, bytes: usize...@@ -152,7 +152,7 @@ pub fn benchmarkHashSmallKeys(comptime H: anytype, key_size: usize, bytes: usize
152 const final = blk: {152 const final = blk: {
153 if (H.init_u8s) |init| {153 if (H.init_u8s) |init| {
154 if (H.has_crypto_api) {154 if (H.has_crypto_api) {
155 break :blk @truncate(u64, H.ty.toInt(small_key, init[0..H.ty.key_length]));155 break :blk @as(u64, @truncate(H.ty.toInt(small_key, init[0..H.ty.key_length])));
156 } else {156 } else {
157 break :blk H.ty.hash(init, small_key);157 break :blk H.ty.hash(init, small_key);
158 }158 }
...@@ -166,8 +166,8 @@ pub fn benchmarkHashSmallKeys(comptime H: anytype, key_size: usize, bytes: usize...@@ -166,8 +166,8 @@ pub fn benchmarkHashSmallKeys(comptime H: anytype, key_size: usize, bytes: usize
166 }166 }
167 const end = timer.read();167 const end = timer.read();
168168
169 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;169 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
170 const throughput = @intFromFloat(u64, @floatFromInt(f64, bytes) / elapsed_s);170 const throughput = @as(u64, @intFromFloat(@as(f64, @floatFromInt(bytes)) / elapsed_s));
171171
172 std.mem.doNotOptimizeAway(sum);172 std.mem.doNotOptimizeAway(sum);
173173
lib/std/hash/cityhash.zig+13-13
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
22
3inline fn offsetPtr(ptr: [*]const u8, offset: usize) [*]const u8 {3inline fn offsetPtr(ptr: [*]const u8, offset: usize) [*]const u8 {
4 // ptr + offset doesn't work at comptime so we need this instead.4 // ptr + offset doesn't work at comptime so we need this instead.
5 return @ptrCast([*]const u8, &ptr[offset]);5 return @as([*]const u8, @ptrCast(&ptr[offset]));
6}6}
77
8fn fetch32(ptr: [*]const u8, offset: usize) u32 {8fn fetch32(ptr: [*]const u8, offset: usize) u32 {
...@@ -49,18 +49,18 @@ pub const CityHash32 = struct {...@@ -49,18 +49,18 @@ pub const CityHash32 = struct {
49 }49 }
5050
51 fn hash32Len0To4(str: []const u8) u32 {51 fn hash32Len0To4(str: []const u8) u32 {
52 const len: u32 = @truncate(u32, str.len);52 const len: u32 = @as(u32, @truncate(str.len));
53 var b: u32 = 0;53 var b: u32 = 0;
54 var c: u32 = 9;54 var c: u32 = 9;
55 for (str) |v| {55 for (str) |v| {
56 b = b *% c1 +% @bitCast(u32, @intCast(i32, @bitCast(i8, v)));56 b = b *% c1 +% @as(u32, @bitCast(@as(i32, @intCast(@as(i8, @bitCast(v))))));
57 c ^= b;57 c ^= b;
58 }58 }
59 return fmix(mur(b, mur(len, c)));59 return fmix(mur(b, mur(len, c)));
60 }60 }
6161
62 fn hash32Len5To12(str: []const u8) u32 {62 fn hash32Len5To12(str: []const u8) u32 {
63 var a: u32 = @truncate(u32, str.len);63 var a: u32 = @as(u32, @truncate(str.len));
64 var b: u32 = a *% 5;64 var b: u32 = a *% 5;
65 var c: u32 = 9;65 var c: u32 = 9;
66 const d: u32 = b;66 const d: u32 = b;
...@@ -73,7 +73,7 @@ pub const CityHash32 = struct {...@@ -73,7 +73,7 @@ pub const CityHash32 = struct {
73 }73 }
7474
75 fn hash32Len13To24(str: []const u8) u32 {75 fn hash32Len13To24(str: []const u8) u32 {
76 const len: u32 = @truncate(u32, str.len);76 const len: u32 = @as(u32, @truncate(str.len));
77 const a: u32 = fetch32(str.ptr, (str.len >> 1) - 4);77 const a: u32 = fetch32(str.ptr, (str.len >> 1) - 4);
78 const b: u32 = fetch32(str.ptr, 4);78 const b: u32 = fetch32(str.ptr, 4);
79 const c: u32 = fetch32(str.ptr, str.len - 8);79 const c: u32 = fetch32(str.ptr, str.len - 8);
...@@ -95,7 +95,7 @@ pub const CityHash32 = struct {...@@ -95,7 +95,7 @@ pub const CityHash32 = struct {
95 }95 }
96 }96 }
9797
98 const len: u32 = @truncate(u32, str.len);98 const len: u32 = @as(u32, @truncate(str.len));
99 var h: u32 = len;99 var h: u32 = len;
100 var g: u32 = c1 *% len;100 var g: u32 = c1 *% len;
101 var f: u32 = g;101 var f: u32 = g;
...@@ -220,9 +220,9 @@ pub const CityHash64 = struct {...@@ -220,9 +220,9 @@ pub const CityHash64 = struct {
220 const a: u8 = str[0];220 const a: u8 = str[0];
221 const b: u8 = str[str.len >> 1];221 const b: u8 = str[str.len >> 1];
222 const c: u8 = str[str.len - 1];222 const c: u8 = str[str.len - 1];
223 const y: u32 = @intCast(u32, a) +% (@intCast(u32, b) << 8);223 const y: u32 = @as(u32, @intCast(a)) +% (@as(u32, @intCast(b)) << 8);
224 const z: u32 = @truncate(u32, str.len) +% (@intCast(u32, c) << 2);224 const z: u32 = @as(u32, @truncate(str.len)) +% (@as(u32, @intCast(c)) << 2);
225 return shiftmix(@intCast(u64, y) *% k2 ^ @intCast(u64, z) *% k0) *% k2;225 return shiftmix(@as(u64, @intCast(y)) *% k2 ^ @as(u64, @intCast(z)) *% k0) *% k2;
226 }226 }
227 return k2;227 return k2;
228 }228 }
...@@ -309,7 +309,7 @@ pub const CityHash64 = struct {...@@ -309,7 +309,7 @@ pub const CityHash64 = struct {
309 var w: WeakPair = weakHashLen32WithSeeds(offsetPtr(str.ptr, str.len - 32), y +% k1, x);309 var w: WeakPair = weakHashLen32WithSeeds(offsetPtr(str.ptr, str.len - 32), y +% k1, x);
310310
311 x = x *% k1 +% fetch64(str.ptr, 0);311 x = x *% k1 +% fetch64(str.ptr, 0);
312 len = (len - 1) & ~@intCast(u64, 63);312 len = (len - 1) & ~@as(u64, @intCast(63));
313313
314 var ptr: [*]const u8 = str.ptr;314 var ptr: [*]const u8 = str.ptr;
315 while (true) {315 while (true) {
...@@ -353,19 +353,19 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {...@@ -353,19 +353,19 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {
353353
354 var i: u32 = 0;354 var i: u32 = 0;
355 while (i < 256) : (i += 1) {355 while (i < 256) : (i += 1) {
356 key[i] = @intCast(u8, i);356 key[i] = @as(u8, @intCast(i));
357357
358 var h: HashResult = hash_fn(key[0..i], 256 - i);358 var h: HashResult = hash_fn(key[0..i], 256 - i);
359359
360 // comptime can't really do reinterpret casting yet,360 // comptime can't really do reinterpret casting yet,
361 // so we need to write the bytes manually.361 // so we need to write the bytes manually.
362 for (hashes_bytes[i * @sizeOf(HashResult) ..][0..@sizeOf(HashResult)]) |*byte| {362 for (hashes_bytes[i * @sizeOf(HashResult) ..][0..@sizeOf(HashResult)]) |*byte| {
363 byte.* = @truncate(u8, h);363 byte.* = @as(u8, @truncate(h));
364 h = h >> 8;364 h = h >> 8;
365 }365 }
366 }366 }
367367
368 return @truncate(u32, hash_fn(&hashes_bytes, 0));368 return @as(u32, @truncate(hash_fn(&hashes_bytes, 0)));
369}369}
370370
371fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {371fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {
lib/std/hash/crc.zig+12-12
...@@ -65,7 +65,7 @@ pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {...@@ -65,7 +65,7 @@ pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {
65 }65 }
6666
67 inline fn tableEntry(index: I) I {67 inline fn tableEntry(index: I) I {
68 return lookup_table[@intCast(u8, index & 0xFF)];68 return lookup_table[@as(u8, @intCast(index & 0xFF))];
69 }69 }
7070
71 pub fn update(self: *Self, bytes: []const u8) void {71 pub fn update(self: *Self, bytes: []const u8) void {
...@@ -95,7 +95,7 @@ pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {...@@ -95,7 +95,7 @@ pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {
95 if (!algorithm.reflect_output) {95 if (!algorithm.reflect_output) {
96 c >>= @bitSizeOf(I) - @bitSizeOf(W);96 c >>= @bitSizeOf(I) - @bitSizeOf(W);
97 }97 }
98 return @intCast(W, c ^ algorithm.xor_output);98 return @as(W, @intCast(c ^ algorithm.xor_output));
99 }99 }
100100
101 pub fn hash(bytes: []const u8) W {101 pub fn hash(bytes: []const u8) W {
...@@ -125,7 +125,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type {...@@ -125,7 +125,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type {
125 var tables: [8][256]u32 = undefined;125 var tables: [8][256]u32 = undefined;
126126
127 for (&tables[0], 0..) |*e, i| {127 for (&tables[0], 0..) |*e, i| {
128 var crc = @intCast(u32, i);128 var crc = @as(u32, @intCast(i));
129 var j: usize = 0;129 var j: usize = 0;
130 while (j < 8) : (j += 1) {130 while (j < 8) : (j += 1) {
131 if (crc & 1 == 1) {131 if (crc & 1 == 1) {
...@@ -142,7 +142,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type {...@@ -142,7 +142,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type {
142 var crc = tables[0][i];142 var crc = tables[0][i];
143 var j: usize = 1;143 var j: usize = 1;
144 while (j < 8) : (j += 1) {144 while (j < 8) : (j += 1) {
145 const index = @truncate(u8, crc);145 const index = @as(u8, @truncate(crc));
146 crc = tables[0][index] ^ (crc >> 8);146 crc = tables[0][index] ^ (crc >> 8);
147 tables[j][i] = crc;147 tables[j][i] = crc;
148 }148 }
...@@ -170,14 +170,14 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type {...@@ -170,14 +170,14 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type {
170 lookup_tables[1][p[6]] ^170 lookup_tables[1][p[6]] ^
171 lookup_tables[2][p[5]] ^171 lookup_tables[2][p[5]] ^
172 lookup_tables[3][p[4]] ^172 lookup_tables[3][p[4]] ^
173 lookup_tables[4][@truncate(u8, self.crc >> 24)] ^173 lookup_tables[4][@as(u8, @truncate(self.crc >> 24))] ^
174 lookup_tables[5][@truncate(u8, self.crc >> 16)] ^174 lookup_tables[5][@as(u8, @truncate(self.crc >> 16))] ^
175 lookup_tables[6][@truncate(u8, self.crc >> 8)] ^175 lookup_tables[6][@as(u8, @truncate(self.crc >> 8))] ^
176 lookup_tables[7][@truncate(u8, self.crc >> 0)];176 lookup_tables[7][@as(u8, @truncate(self.crc >> 0))];
177 }177 }
178178
179 while (i < input.len) : (i += 1) {179 while (i < input.len) : (i += 1) {
180 const index = @truncate(u8, self.crc) ^ input[i];180 const index = @as(u8, @truncate(self.crc)) ^ input[i];
181 self.crc = (self.crc >> 8) ^ lookup_tables[0][index];181 self.crc = (self.crc >> 8) ^ lookup_tables[0][index];
182 }182 }
183 }183 }
...@@ -218,7 +218,7 @@ pub fn Crc32SmallWithPoly(comptime poly: Polynomial) type {...@@ -218,7 +218,7 @@ pub fn Crc32SmallWithPoly(comptime poly: Polynomial) type {
218 var table: [16]u32 = undefined;218 var table: [16]u32 = undefined;
219219
220 for (&table, 0..) |*e, i| {220 for (&table, 0..) |*e, i| {
221 var crc = @intCast(u32, i * 16);221 var crc = @as(u32, @intCast(i * 16));
222 var j: usize = 0;222 var j: usize = 0;
223 while (j < 8) : (j += 1) {223 while (j < 8) : (j += 1) {
224 if (crc & 1 == 1) {224 if (crc & 1 == 1) {
...@@ -241,8 +241,8 @@ pub fn Crc32SmallWithPoly(comptime poly: Polynomial) type {...@@ -241,8 +241,8 @@ pub fn Crc32SmallWithPoly(comptime poly: Polynomial) type {
241241
242 pub fn update(self: *Self, input: []const u8) void {242 pub fn update(self: *Self, input: []const u8) void {
243 for (input) |b| {243 for (input) |b| {
244 self.crc = lookup_table[@truncate(u4, self.crc ^ (b >> 0))] ^ (self.crc >> 4);244 self.crc = lookup_table[@as(u4, @truncate(self.crc ^ (b >> 0)))] ^ (self.crc >> 4);
245 self.crc = lookup_table[@truncate(u4, self.crc ^ (b >> 4))] ^ (self.crc >> 4);245 self.crc = lookup_table[@as(u4, @truncate(self.crc ^ (b >> 4)))] ^ (self.crc >> 4);
246 }246 }
247 }247 }
248248
lib/std/hash/murmur.zig+25-25
...@@ -14,9 +14,9 @@ pub const Murmur2_32 = struct {...@@ -14,9 +14,9 @@ pub const Murmur2_32 = struct {
1414
15 pub fn hashWithSeed(str: []const u8, seed: u32) u32 {15 pub fn hashWithSeed(str: []const u8, seed: u32) u32 {
16 const m: u32 = 0x5bd1e995;16 const m: u32 = 0x5bd1e995;
17 const len = @truncate(u32, str.len);17 const len = @as(u32, @truncate(str.len));
18 var h1: u32 = seed ^ len;18 var h1: u32 = seed ^ len;
19 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {19 for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| {
20 var k1: u32 = v;20 var k1: u32 = v;
21 if (native_endian == .Big)21 if (native_endian == .Big)
22 k1 = @byteSwap(k1);22 k1 = @byteSwap(k1);
...@@ -29,13 +29,13 @@ pub const Murmur2_32 = struct {...@@ -29,13 +29,13 @@ pub const Murmur2_32 = struct {
29 const offset = len & 0xfffffffc;29 const offset = len & 0xfffffffc;
30 const rest = len & 3;30 const rest = len & 3;
31 if (rest >= 3) {31 if (rest >= 3) {
32 h1 ^= @intCast(u32, str[offset + 2]) << 16;32 h1 ^= @as(u32, @intCast(str[offset + 2])) << 16;
33 }33 }
34 if (rest >= 2) {34 if (rest >= 2) {
35 h1 ^= @intCast(u32, str[offset + 1]) << 8;35 h1 ^= @as(u32, @intCast(str[offset + 1])) << 8;
36 }36 }
37 if (rest >= 1) {37 if (rest >= 1) {
38 h1 ^= @intCast(u32, str[offset + 0]);38 h1 ^= @as(u32, @intCast(str[offset + 0]));
39 h1 *%= m;39 h1 *%= m;
40 }40 }
41 h1 ^= h1 >> 13;41 h1 ^= h1 >> 13;
...@@ -73,12 +73,12 @@ pub const Murmur2_32 = struct {...@@ -73,12 +73,12 @@ pub const Murmur2_32 = struct {
73 const len: u32 = 8;73 const len: u32 = 8;
74 var h1: u32 = seed ^ len;74 var h1: u32 = seed ^ len;
75 var k1: u32 = undefined;75 var k1: u32 = undefined;
76 k1 = @truncate(u32, v) *% m;76 k1 = @as(u32, @truncate(v)) *% m;
77 k1 ^= k1 >> 24;77 k1 ^= k1 >> 24;
78 k1 *%= m;78 k1 *%= m;
79 h1 *%= m;79 h1 *%= m;
80 h1 ^= k1;80 h1 ^= k1;
81 k1 = @truncate(u32, v >> 32) *% m;81 k1 = @as(u32, @truncate(v >> 32)) *% m;
82 k1 ^= k1 >> 24;82 k1 ^= k1 >> 24;
83 k1 *%= m;83 k1 *%= m;
84 h1 *%= m;84 h1 *%= m;
...@@ -100,7 +100,7 @@ pub const Murmur2_64 = struct {...@@ -100,7 +100,7 @@ pub const Murmur2_64 = struct {
100 pub fn hashWithSeed(str: []const u8, seed: u64) u64 {100 pub fn hashWithSeed(str: []const u8, seed: u64) u64 {
101 const m: u64 = 0xc6a4a7935bd1e995;101 const m: u64 = 0xc6a4a7935bd1e995;
102 var h1: u64 = seed ^ (@as(u64, str.len) *% m);102 var h1: u64 = seed ^ (@as(u64, str.len) *% m);
103 for (@ptrCast([*]align(1) const u64, str.ptr)[0 .. str.len / 8]) |v| {103 for (@as([*]align(1) const u64, @ptrCast(str.ptr))[0 .. str.len / 8]) |v| {
104 var k1: u64 = v;104 var k1: u64 = v;
105 if (native_endian == .Big)105 if (native_endian == .Big)
106 k1 = @byteSwap(k1);106 k1 = @byteSwap(k1);
...@@ -114,7 +114,7 @@ pub const Murmur2_64 = struct {...@@ -114,7 +114,7 @@ pub const Murmur2_64 = struct {
114 const offset = str.len - rest;114 const offset = str.len - rest;
115 if (rest > 0) {115 if (rest > 0) {
116 var k1: u64 = 0;116 var k1: u64 = 0;
117 @memcpy(@ptrCast([*]u8, &k1)[0..rest], str[offset..]);117 @memcpy(@as([*]u8, @ptrCast(&k1))[0..rest], str[offset..]);
118 if (native_endian == .Big)118 if (native_endian == .Big)
119 k1 = @byteSwap(k1);119 k1 = @byteSwap(k1);
120 h1 ^= k1;120 h1 ^= k1;
...@@ -178,9 +178,9 @@ pub const Murmur3_32 = struct {...@@ -178,9 +178,9 @@ pub const Murmur3_32 = struct {
178 pub fn hashWithSeed(str: []const u8, seed: u32) u32 {178 pub fn hashWithSeed(str: []const u8, seed: u32) u32 {
179 const c1: u32 = 0xcc9e2d51;179 const c1: u32 = 0xcc9e2d51;
180 const c2: u32 = 0x1b873593;180 const c2: u32 = 0x1b873593;
181 const len = @truncate(u32, str.len);181 const len = @as(u32, @truncate(str.len));
182 var h1: u32 = seed;182 var h1: u32 = seed;
183 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {183 for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| {
184 var k1: u32 = v;184 var k1: u32 = v;
185 if (native_endian == .Big)185 if (native_endian == .Big)
186 k1 = @byteSwap(k1);186 k1 = @byteSwap(k1);
...@@ -197,13 +197,13 @@ pub const Murmur3_32 = struct {...@@ -197,13 +197,13 @@ pub const Murmur3_32 = struct {
197 const offset = len & 0xfffffffc;197 const offset = len & 0xfffffffc;
198 const rest = len & 3;198 const rest = len & 3;
199 if (rest == 3) {199 if (rest == 3) {
200 k1 ^= @intCast(u32, str[offset + 2]) << 16;200 k1 ^= @as(u32, @intCast(str[offset + 2])) << 16;
201 }201 }
202 if (rest >= 2) {202 if (rest >= 2) {
203 k1 ^= @intCast(u32, str[offset + 1]) << 8;203 k1 ^= @as(u32, @intCast(str[offset + 1])) << 8;
204 }204 }
205 if (rest >= 1) {205 if (rest >= 1) {
206 k1 ^= @intCast(u32, str[offset + 0]);206 k1 ^= @as(u32, @intCast(str[offset + 0]));
207 k1 *%= c1;207 k1 *%= c1;
208 k1 = rotl32(k1, 15);208 k1 = rotl32(k1, 15);
209 k1 *%= c2;209 k1 *%= c2;
...@@ -255,14 +255,14 @@ pub const Murmur3_32 = struct {...@@ -255,14 +255,14 @@ pub const Murmur3_32 = struct {
255 const len: u32 = 8;255 const len: u32 = 8;
256 var h1: u32 = seed;256 var h1: u32 = seed;
257 var k1: u32 = undefined;257 var k1: u32 = undefined;
258 k1 = @truncate(u32, v) *% c1;258 k1 = @as(u32, @truncate(v)) *% c1;
259 k1 = rotl32(k1, 15);259 k1 = rotl32(k1, 15);
260 k1 *%= c2;260 k1 *%= c2;
261 h1 ^= k1;261 h1 ^= k1;
262 h1 = rotl32(h1, 13);262 h1 = rotl32(h1, 13);
263 h1 *%= 5;263 h1 *%= 5;
264 h1 +%= 0xe6546b64;264 h1 +%= 0xe6546b64;
265 k1 = @truncate(u32, v >> 32) *% c1;265 k1 = @as(u32, @truncate(v >> 32)) *% c1;
266 k1 = rotl32(k1, 15);266 k1 = rotl32(k1, 15);
267 k1 *%= c2;267 k1 *%= c2;
268 h1 ^= k1;268 h1 ^= k1;
...@@ -286,15 +286,15 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {...@@ -286,15 +286,15 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {
286286
287 var i: u32 = 0;287 var i: u32 = 0;
288 while (i < 256) : (i += 1) {288 while (i < 256) : (i += 1) {
289 key[i] = @truncate(u8, i);289 key[i] = @as(u8, @truncate(i));
290290
291 var h = hash_fn(key[0..i], 256 - i);291 var h = hash_fn(key[0..i], 256 - i);
292 if (native_endian == .Big)292 if (native_endian == .Big)
293 h = @byteSwap(h);293 h = @byteSwap(h);
294 @memcpy(hashes[i * hashbytes ..][0..hashbytes], @ptrCast([*]u8, &h));294 @memcpy(hashes[i * hashbytes ..][0..hashbytes], @as([*]u8, @ptrCast(&h)));
295 }295 }
296296
297 return @truncate(u32, hash_fn(&hashes, 0));297 return @as(u32, @truncate(hash_fn(&hashes, 0)));
298}298}
299299
300test "murmur2_32" {300test "murmur2_32" {
...@@ -307,8 +307,8 @@ test "murmur2_32" {...@@ -307,8 +307,8 @@ test "murmur2_32" {
307 v0le = @byteSwap(v0le);307 v0le = @byteSwap(v0le);
308 v1le = @byteSwap(v1le);308 v1le = @byteSwap(v1le);
309 }309 }
310 try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0));310 try testing.expectEqual(Murmur2_32.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur2_32.hashUint32(v0));
311 try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1));311 try testing.expectEqual(Murmur2_32.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur2_32.hashUint64(v1));
312}312}
313313
314test "murmur2_64" {314test "murmur2_64" {
...@@ -321,8 +321,8 @@ test "murmur2_64" {...@@ -321,8 +321,8 @@ test "murmur2_64" {
321 v0le = @byteSwap(v0le);321 v0le = @byteSwap(v0le);
322 v1le = @byteSwap(v1le);322 v1le = @byteSwap(v1le);
323 }323 }
324 try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0));324 try testing.expectEqual(Murmur2_64.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur2_64.hashUint32(v0));
325 try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1));325 try testing.expectEqual(Murmur2_64.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur2_64.hashUint64(v1));
326}326}
327327
328test "murmur3_32" {328test "murmur3_32" {
...@@ -335,6 +335,6 @@ test "murmur3_32" {...@@ -335,6 +335,6 @@ test "murmur3_32" {
335 v0le = @byteSwap(v0le);335 v0le = @byteSwap(v0le);
336 v1le = @byteSwap(v1le);336 v1le = @byteSwap(v1le);
337 }337 }
338 try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0));338 try testing.expectEqual(Murmur3_32.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur3_32.hashUint32(v0));
339 try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur3_32.hashUint64(v1));339 try testing.expectEqual(Murmur3_32.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur3_32.hashUint64(v1));
340}340}
lib/std/hash/wyhash.zig+3-3
...@@ -132,8 +132,8 @@ pub const Wyhash = struct {...@@ -132,8 +132,8 @@ pub const Wyhash = struct {
132132
133 inline fn mum(a: *u64, b: *u64) void {133 inline fn mum(a: *u64, b: *u64) void {
134 const x = @as(u128, a.*) *% b.*;134 const x = @as(u128, a.*) *% b.*;
135 a.* = @truncate(u64, x);135 a.* = @as(u64, @truncate(x));
136 b.* = @truncate(u64, x >> 64);136 b.* = @as(u64, @truncate(x >> 64));
137 }137 }
138138
139 inline fn mix(a_: u64, b_: u64) u64 {139 inline fn mix(a_: u64, b_: u64) u64 {
...@@ -252,7 +252,7 @@ test "test ensure idempotent final call" {...@@ -252,7 +252,7 @@ test "test ensure idempotent final call" {
252test "iterative non-divisible update" {252test "iterative non-divisible update" {
253 var buf: [8192]u8 = undefined;253 var buf: [8192]u8 = undefined;
254 for (&buf, 0..) |*e, i| {254 for (&buf, 0..) |*e, i| {
255 e.* = @truncate(u8, i);255 e.* = @as(u8, @truncate(i));
256 }256 }
257257
258 const seed = 0x128dad08f;258 const seed = 0x128dad08f;
lib/std/hash/xxhash.zig+1-1
...@@ -212,7 +212,7 @@ pub const XxHash32 = struct {...@@ -212,7 +212,7 @@ pub const XxHash32 = struct {
212 rotl(u32, self.acc3, 12) +% rotl(u32, self.acc4, 18);212 rotl(u32, self.acc3, 12) +% rotl(u32, self.acc4, 18);
213 }213 }
214214
215 acc = acc +% @intCast(u32, self.byte_count) +% @intCast(u32, self.buf_len);215 acc = acc +% @as(u32, @intCast(self.byte_count)) +% @as(u32, @intCast(self.buf_len));
216216
217 var pos: usize = 0;217 var pos: usize = 0;
218 while (pos + 4 <= self.buf_len) : (pos += 4) {218 while (pos + 4 <= self.buf_len) : (pos += 4) {
lib/std/hash_map.zig+22-22
...@@ -101,7 +101,7 @@ pub const StringIndexContext = struct {...@@ -101,7 +101,7 @@ pub const StringIndexContext = struct {
101 }101 }
102102
103 pub fn hash(self: @This(), x: u32) u64 {103 pub fn hash(self: @This(), x: u32) u64 {
104 const x_slice = mem.sliceTo(@ptrCast([*:0]const u8, self.bytes.items.ptr) + x, 0);104 const x_slice = mem.sliceTo(@as([*:0]const u8, @ptrCast(self.bytes.items.ptr)) + x, 0);
105 return hashString(x_slice);105 return hashString(x_slice);
106 }106 }
107};107};
...@@ -110,7 +110,7 @@ pub const StringIndexAdapter = struct {...@@ -110,7 +110,7 @@ pub const StringIndexAdapter = struct {
110 bytes: *std.ArrayListUnmanaged(u8),110 bytes: *std.ArrayListUnmanaged(u8),
111111
112 pub fn eql(self: @This(), a_slice: []const u8, b: u32) bool {112 pub fn eql(self: @This(), a_slice: []const u8, b: u32) bool {
113 const b_slice = mem.sliceTo(@ptrCast([*:0]const u8, self.bytes.items.ptr) + b, 0);113 const b_slice = mem.sliceTo(@as([*:0]const u8, @ptrCast(self.bytes.items.ptr)) + b, 0);
114 return mem.eql(u8, a_slice, b_slice);114 return mem.eql(u8, a_slice, b_slice);
115 }115 }
116116
...@@ -777,25 +777,25 @@ pub fn HashMapUnmanaged(...@@ -777,25 +777,25 @@ pub fn HashMapUnmanaged(
777 fingerprint: FingerPrint = free,777 fingerprint: FingerPrint = free,
778 used: u1 = 0,778 used: u1 = 0,
779779
780 const slot_free = @bitCast(u8, Metadata{ .fingerprint = free });780 const slot_free = @as(u8, @bitCast(Metadata{ .fingerprint = free }));
781 const slot_tombstone = @bitCast(u8, Metadata{ .fingerprint = tombstone });781 const slot_tombstone = @as(u8, @bitCast(Metadata{ .fingerprint = tombstone }));
782782
783 pub fn isUsed(self: Metadata) bool {783 pub fn isUsed(self: Metadata) bool {
784 return self.used == 1;784 return self.used == 1;
785 }785 }
786786
787 pub fn isTombstone(self: Metadata) bool {787 pub fn isTombstone(self: Metadata) bool {
788 return @bitCast(u8, self) == slot_tombstone;788 return @as(u8, @bitCast(self)) == slot_tombstone;
789 }789 }
790790
791 pub fn isFree(self: Metadata) bool {791 pub fn isFree(self: Metadata) bool {
792 return @bitCast(u8, self) == slot_free;792 return @as(u8, @bitCast(self)) == slot_free;
793 }793 }
794794
795 pub fn takeFingerprint(hash: Hash) FingerPrint {795 pub fn takeFingerprint(hash: Hash) FingerPrint {
796 const hash_bits = @typeInfo(Hash).Int.bits;796 const hash_bits = @typeInfo(Hash).Int.bits;
797 const fp_bits = @typeInfo(FingerPrint).Int.bits;797 const fp_bits = @typeInfo(FingerPrint).Int.bits;
798 return @truncate(FingerPrint, hash >> (hash_bits - fp_bits));798 return @as(FingerPrint, @truncate(hash >> (hash_bits - fp_bits)));
799 }799 }
800800
801 pub fn fill(self: *Metadata, fp: FingerPrint) void {801 pub fn fill(self: *Metadata, fp: FingerPrint) void {
...@@ -899,7 +899,7 @@ pub fn HashMapUnmanaged(...@@ -899,7 +899,7 @@ pub fn HashMapUnmanaged(
899 }899 }
900900
901 fn capacityForSize(size: Size) Size {901 fn capacityForSize(size: Size) Size {
902 var new_cap = @truncate(u32, (@as(u64, size) * 100) / max_load_percentage + 1);902 var new_cap = @as(u32, @truncate((@as(u64, size) * 100) / max_load_percentage + 1));
903 new_cap = math.ceilPowerOfTwo(u32, new_cap) catch unreachable;903 new_cap = math.ceilPowerOfTwo(u32, new_cap) catch unreachable;
904 return new_cap;904 return new_cap;
905 }905 }
...@@ -927,7 +927,7 @@ pub fn HashMapUnmanaged(...@@ -927,7 +927,7 @@ pub fn HashMapUnmanaged(
927 if (self.metadata) |_| {927 if (self.metadata) |_| {
928 self.initMetadatas();928 self.initMetadatas();
929 self.size = 0;929 self.size = 0;
930 self.available = @truncate(u32, (self.capacity() * max_load_percentage) / 100);930 self.available = @as(u32, @truncate((self.capacity() * max_load_percentage) / 100));
931 }931 }
932 }932 }
933933
...@@ -942,7 +942,7 @@ pub fn HashMapUnmanaged(...@@ -942,7 +942,7 @@ pub fn HashMapUnmanaged(
942 }942 }
943943
944 fn header(self: *const Self) *Header {944 fn header(self: *const Self) *Header {
945 return @ptrCast(*Header, @ptrCast([*]Header, @alignCast(@alignOf(Header), self.metadata.?)) - 1);945 return @ptrCast(@as([*]Header, @ptrCast(@alignCast(self.metadata.?))) - 1);
946 }946 }
947947
948 fn keys(self: *const Self) [*]K {948 fn keys(self: *const Self) [*]K {
...@@ -1033,7 +1033,7 @@ pub fn HashMapUnmanaged(...@@ -1033,7 +1033,7 @@ pub fn HashMapUnmanaged(
10331033
1034 const hash = ctx.hash(key);1034 const hash = ctx.hash(key);
1035 const mask = self.capacity() - 1;1035 const mask = self.capacity() - 1;
1036 var idx = @truncate(usize, hash & mask);1036 var idx = @as(usize, @truncate(hash & mask));
10371037
1038 var metadata = self.metadata.? + idx;1038 var metadata = self.metadata.? + idx;
1039 while (metadata[0].isUsed()) {1039 while (metadata[0].isUsed()) {
...@@ -1147,7 +1147,7 @@ pub fn HashMapUnmanaged(...@@ -1147,7 +1147,7 @@ pub fn HashMapUnmanaged(
1147 const fingerprint = Metadata.takeFingerprint(hash);1147 const fingerprint = Metadata.takeFingerprint(hash);
1148 // Don't loop indefinitely when there are no empty slots.1148 // Don't loop indefinitely when there are no empty slots.
1149 var limit = self.capacity();1149 var limit = self.capacity();
1150 var idx = @truncate(usize, hash & mask);1150 var idx = @as(usize, @truncate(hash & mask));
11511151
1152 var metadata = self.metadata.? + idx;1152 var metadata = self.metadata.? + idx;
1153 while (!metadata[0].isFree() and limit != 0) {1153 while (!metadata[0].isFree() and limit != 0) {
...@@ -1325,7 +1325,7 @@ pub fn HashMapUnmanaged(...@@ -1325,7 +1325,7 @@ pub fn HashMapUnmanaged(
1325 const mask = self.capacity() - 1;1325 const mask = self.capacity() - 1;
1326 const fingerprint = Metadata.takeFingerprint(hash);1326 const fingerprint = Metadata.takeFingerprint(hash);
1327 var limit = self.capacity();1327 var limit = self.capacity();
1328 var idx = @truncate(usize, hash & mask);1328 var idx = @as(usize, @truncate(hash & mask));
13291329
1330 var first_tombstone_idx: usize = self.capacity(); // invalid index1330 var first_tombstone_idx: usize = self.capacity(); // invalid index
1331 var metadata = self.metadata.? + idx;1331 var metadata = self.metadata.? + idx;
...@@ -1450,7 +1450,7 @@ pub fn HashMapUnmanaged(...@@ -1450,7 +1450,7 @@ pub fn HashMapUnmanaged(
1450 }1450 }
14511451
1452 fn initMetadatas(self: *Self) void {1452 fn initMetadatas(self: *Self) void {
1453 @memset(@ptrCast([*]u8, self.metadata.?)[0 .. @sizeOf(Metadata) * self.capacity()], 0);1453 @memset(@as([*]u8, @ptrCast(self.metadata.?))[0 .. @sizeOf(Metadata) * self.capacity()], 0);
1454 }1454 }
14551455
1456 // This counts the number of occupied slots (not counting tombstones), which is1456 // This counts the number of occupied slots (not counting tombstones), which is
...@@ -1458,7 +1458,7 @@ pub fn HashMapUnmanaged(...@@ -1458,7 +1458,7 @@ pub fn HashMapUnmanaged(
1458 fn load(self: *const Self) Size {1458 fn load(self: *const Self) Size {
1459 const max_load = (self.capacity() * max_load_percentage) / 100;1459 const max_load = (self.capacity() * max_load_percentage) / 100;
1460 assert(max_load >= self.available);1460 assert(max_load >= self.available);
1461 return @truncate(Size, max_load - self.available);1461 return @as(Size, @truncate(max_load - self.available));
1462 }1462 }
14631463
1464 fn growIfNeeded(self: *Self, allocator: Allocator, new_count: Size, ctx: Context) Allocator.Error!void {1464 fn growIfNeeded(self: *Self, allocator: Allocator, new_count: Size, ctx: Context) Allocator.Error!void {
...@@ -1480,7 +1480,7 @@ pub fn HashMapUnmanaged(...@@ -1480,7 +1480,7 @@ pub fn HashMapUnmanaged(
1480 const new_cap = capacityForSize(self.size);1480 const new_cap = capacityForSize(self.size);
1481 try other.allocate(allocator, new_cap);1481 try other.allocate(allocator, new_cap);
1482 other.initMetadatas();1482 other.initMetadatas();
1483 other.available = @truncate(u32, (new_cap * max_load_percentage) / 100);1483 other.available = @as(u32, @truncate((new_cap * max_load_percentage) / 100));
14841484
1485 var i: Size = 0;1485 var i: Size = 0;
1486 var metadata = self.metadata.?;1486 var metadata = self.metadata.?;
...@@ -1515,7 +1515,7 @@ pub fn HashMapUnmanaged(...@@ -1515,7 +1515,7 @@ pub fn HashMapUnmanaged(
1515 defer map.deinit(allocator);1515 defer map.deinit(allocator);
1516 try map.allocate(allocator, new_cap);1516 try map.allocate(allocator, new_cap);
1517 map.initMetadatas();1517 map.initMetadatas();
1518 map.available = @truncate(u32, (new_cap * max_load_percentage) / 100);1518 map.available = @as(u32, @truncate((new_cap * max_load_percentage) / 100));
15191519
1520 if (self.size != 0) {1520 if (self.size != 0) {
1521 const old_capacity = self.capacity();1521 const old_capacity = self.capacity();
...@@ -1558,15 +1558,15 @@ pub fn HashMapUnmanaged(...@@ -1558,15 +1558,15 @@ pub fn HashMapUnmanaged(
15581558
1559 const metadata = ptr + @sizeOf(Header);1559 const metadata = ptr + @sizeOf(Header);
15601560
1561 const hdr = @ptrFromInt(*Header, ptr);1561 const hdr = @as(*Header, @ptrFromInt(ptr));
1562 if (@sizeOf([*]V) != 0) {1562 if (@sizeOf([*]V) != 0) {
1563 hdr.values = @ptrFromInt([*]V, ptr + vals_start);1563 hdr.values = @as([*]V, @ptrFromInt(ptr + vals_start));
1564 }1564 }
1565 if (@sizeOf([*]K) != 0) {1565 if (@sizeOf([*]K) != 0) {
1566 hdr.keys = @ptrFromInt([*]K, ptr + keys_start);1566 hdr.keys = @as([*]K, @ptrFromInt(ptr + keys_start));
1567 }1567 }
1568 hdr.capacity = new_capacity;1568 hdr.capacity = new_capacity;
1569 self.metadata = @ptrFromInt([*]Metadata, metadata);1569 self.metadata = @as([*]Metadata, @ptrFromInt(metadata));
1570 }1570 }
15711571
1572 fn deallocate(self: *Self, allocator: Allocator) void {1572 fn deallocate(self: *Self, allocator: Allocator) void {
...@@ -1589,7 +1589,7 @@ pub fn HashMapUnmanaged(...@@ -1589,7 +1589,7 @@ pub fn HashMapUnmanaged(
15891589
1590 const total_size = std.mem.alignForward(usize, vals_end, max_align);1590 const total_size = std.mem.alignForward(usize, vals_end, max_align);
15911591
1592 const slice = @ptrFromInt([*]align(max_align) u8, @intFromPtr(self.header()))[0..total_size];1592 const slice = @as([*]align(max_align) u8, @ptrFromInt(@intFromPtr(self.header())))[0..total_size];
1593 allocator.free(slice);1593 allocator.free(slice);
15941594
1595 self.metadata = null;1595 self.metadata = null;
lib/std/heap.zig+25-25
...@@ -61,11 +61,11 @@ const CAllocator = struct {...@@ -61,11 +61,11 @@ const CAllocator = struct {
61 pub const supports_posix_memalign = @hasDecl(c, "posix_memalign");61 pub const supports_posix_memalign = @hasDecl(c, "posix_memalign");
6262
63 fn getHeader(ptr: [*]u8) *[*]u8 {63 fn getHeader(ptr: [*]u8) *[*]u8 {
64 return @ptrFromInt(*[*]u8, @intFromPtr(ptr) - @sizeOf(usize));64 return @as(*[*]u8, @ptrFromInt(@intFromPtr(ptr) - @sizeOf(usize)));
65 }65 }
6666
67 fn alignedAlloc(len: usize, log2_align: u8) ?[*]u8 {67 fn alignedAlloc(len: usize, log2_align: u8) ?[*]u8 {
68 const alignment = @as(usize, 1) << @intCast(Allocator.Log2Align, log2_align);68 const alignment = @as(usize, 1) << @as(Allocator.Log2Align, @intCast(log2_align));
69 if (supports_posix_memalign) {69 if (supports_posix_memalign) {
70 // The posix_memalign only accepts alignment values that are a70 // The posix_memalign only accepts alignment values that are a
71 // multiple of the pointer size71 // multiple of the pointer size
...@@ -75,13 +75,13 @@ const CAllocator = struct {...@@ -75,13 +75,13 @@ const CAllocator = struct {
75 if (c.posix_memalign(&aligned_ptr, eff_alignment, len) != 0)75 if (c.posix_memalign(&aligned_ptr, eff_alignment, len) != 0)
76 return null;76 return null;
7777
78 return @ptrCast([*]u8, aligned_ptr);78 return @as([*]u8, @ptrCast(aligned_ptr));
79 }79 }
8080
81 // Thin wrapper around regular malloc, overallocate to account for81 // Thin wrapper around regular malloc, overallocate to account for
82 // alignment padding and store the original malloc()'ed pointer before82 // alignment padding and store the original malloc()'ed pointer before
83 // the aligned address.83 // the aligned address.
84 var unaligned_ptr = @ptrCast([*]u8, c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null);84 var unaligned_ptr = @as([*]u8, @ptrCast(c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null));
85 const unaligned_addr = @intFromPtr(unaligned_ptr);85 const unaligned_addr = @intFromPtr(unaligned_ptr);
86 const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), alignment);86 const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), alignment);
87 var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);87 var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
...@@ -195,7 +195,7 @@ fn rawCAlloc(...@@ -195,7 +195,7 @@ fn rawCAlloc(
195 // type in C that is size 8 and has 16 byte alignment, so the alignment may195 // type in C that is size 8 and has 16 byte alignment, so the alignment may
196 // be 8 bytes rather than 16. Similarly if only 1 byte is requested, malloc196 // be 8 bytes rather than 16. Similarly if only 1 byte is requested, malloc
197 // is allowed to return a 1-byte aligned pointer.197 // is allowed to return a 1-byte aligned pointer.
198 return @ptrCast(?[*]u8, c.malloc(len));198 return @as(?[*]u8, @ptrCast(c.malloc(len)));
199}199}
200200
201fn rawCResize(201fn rawCResize(
...@@ -283,7 +283,7 @@ pub const HeapAllocator = switch (builtin.os.tag) {...@@ -283,7 +283,7 @@ pub const HeapAllocator = switch (builtin.os.tag) {
283 }283 }
284284
285 fn getRecordPtr(buf: []u8) *align(1) usize {285 fn getRecordPtr(buf: []u8) *align(1) usize {
286 return @ptrFromInt(*align(1) usize, @intFromPtr(buf.ptr) + buf.len);286 return @as(*align(1) usize, @ptrFromInt(@intFromPtr(buf.ptr) + buf.len));
287 }287 }
288288
289 fn alloc(289 fn alloc(
...@@ -293,9 +293,9 @@ pub const HeapAllocator = switch (builtin.os.tag) {...@@ -293,9 +293,9 @@ pub const HeapAllocator = switch (builtin.os.tag) {
293 return_address: usize,293 return_address: usize,
294 ) ?[*]u8 {294 ) ?[*]u8 {
295 _ = return_address;295 _ = return_address;
296 const self = @ptrCast(*HeapAllocator, @alignCast(@alignOf(HeapAllocator), ctx));296 const self: *HeapAllocator = @ptrCast(@alignCast(ctx));
297297
298 const ptr_align = @as(usize, 1) << @intCast(Allocator.Log2Align, log2_ptr_align);298 const ptr_align = @as(usize, 1) << @as(Allocator.Log2Align, @intCast(log2_ptr_align));
299 const amt = n + ptr_align - 1 + @sizeOf(usize);299 const amt = n + ptr_align - 1 + @sizeOf(usize);
300 const optional_heap_handle = @atomicLoad(?HeapHandle, &self.heap_handle, .SeqCst);300 const optional_heap_handle = @atomicLoad(?HeapHandle, &self.heap_handle, .SeqCst);
301 const heap_handle = optional_heap_handle orelse blk: {301 const heap_handle = optional_heap_handle orelse blk: {
...@@ -308,7 +308,7 @@ pub const HeapAllocator = switch (builtin.os.tag) {...@@ -308,7 +308,7 @@ pub const HeapAllocator = switch (builtin.os.tag) {
308 const ptr = os.windows.kernel32.HeapAlloc(heap_handle, 0, amt) orelse return null;308 const ptr = os.windows.kernel32.HeapAlloc(heap_handle, 0, amt) orelse return null;
309 const root_addr = @intFromPtr(ptr);309 const root_addr = @intFromPtr(ptr);
310 const aligned_addr = mem.alignForward(usize, root_addr, ptr_align);310 const aligned_addr = mem.alignForward(usize, root_addr, ptr_align);
311 const buf = @ptrFromInt([*]u8, aligned_addr)[0..n];311 const buf = @as([*]u8, @ptrFromInt(aligned_addr))[0..n];
312 getRecordPtr(buf).* = root_addr;312 getRecordPtr(buf).* = root_addr;
313 return buf.ptr;313 return buf.ptr;
314 }314 }
...@@ -322,7 +322,7 @@ pub const HeapAllocator = switch (builtin.os.tag) {...@@ -322,7 +322,7 @@ pub const HeapAllocator = switch (builtin.os.tag) {
322 ) bool {322 ) bool {
323 _ = log2_buf_align;323 _ = log2_buf_align;
324 _ = return_address;324 _ = return_address;
325 const self = @ptrCast(*HeapAllocator, @alignCast(@alignOf(HeapAllocator), ctx));325 const self: *HeapAllocator = @ptrCast(@alignCast(ctx));
326326
327 const root_addr = getRecordPtr(buf).*;327 const root_addr = getRecordPtr(buf).*;
328 const align_offset = @intFromPtr(buf.ptr) - root_addr;328 const align_offset = @intFromPtr(buf.ptr) - root_addr;
...@@ -330,10 +330,10 @@ pub const HeapAllocator = switch (builtin.os.tag) {...@@ -330,10 +330,10 @@ pub const HeapAllocator = switch (builtin.os.tag) {
330 const new_ptr = os.windows.kernel32.HeapReAlloc(330 const new_ptr = os.windows.kernel32.HeapReAlloc(
331 self.heap_handle.?,331 self.heap_handle.?,
332 os.windows.HEAP_REALLOC_IN_PLACE_ONLY,332 os.windows.HEAP_REALLOC_IN_PLACE_ONLY,
333 @ptrFromInt(*anyopaque, root_addr),333 @as(*anyopaque, @ptrFromInt(root_addr)),
334 amt,334 amt,
335 ) orelse return false;335 ) orelse return false;
336 assert(new_ptr == @ptrFromInt(*anyopaque, root_addr));336 assert(new_ptr == @as(*anyopaque, @ptrFromInt(root_addr)));
337 getRecordPtr(buf.ptr[0..new_size]).* = root_addr;337 getRecordPtr(buf.ptr[0..new_size]).* = root_addr;
338 return true;338 return true;
339 }339 }
...@@ -346,8 +346,8 @@ pub const HeapAllocator = switch (builtin.os.tag) {...@@ -346,8 +346,8 @@ pub const HeapAllocator = switch (builtin.os.tag) {
346 ) void {346 ) void {
347 _ = log2_buf_align;347 _ = log2_buf_align;
348 _ = return_address;348 _ = return_address;
349 const self = @ptrCast(*HeapAllocator, @alignCast(@alignOf(HeapAllocator), ctx));349 const self: *HeapAllocator = @ptrCast(@alignCast(ctx));
350 os.windows.HeapFree(self.heap_handle.?, 0, @ptrFromInt(*anyopaque, getRecordPtr(buf).*));350 os.windows.HeapFree(self.heap_handle.?, 0, @as(*anyopaque, @ptrFromInt(getRecordPtr(buf).*)));
351 }351 }
352 },352 },
353 else => @compileError("Unsupported OS"),353 else => @compileError("Unsupported OS"),
...@@ -415,9 +415,9 @@ pub const FixedBufferAllocator = struct {...@@ -415,9 +415,9 @@ pub const FixedBufferAllocator = struct {
415 }415 }
416416
417 fn alloc(ctx: *anyopaque, n: usize, log2_ptr_align: u8, ra: usize) ?[*]u8 {417 fn alloc(ctx: *anyopaque, n: usize, log2_ptr_align: u8, ra: usize) ?[*]u8 {
418 const self = @ptrCast(*FixedBufferAllocator, @alignCast(@alignOf(FixedBufferAllocator), ctx));418 const self: *FixedBufferAllocator = @ptrCast(@alignCast(ctx));
419 _ = ra;419 _ = ra;
420 const ptr_align = @as(usize, 1) << @intCast(Allocator.Log2Align, log2_ptr_align);420 const ptr_align = @as(usize, 1) << @as(Allocator.Log2Align, @intCast(log2_ptr_align));
421 const adjust_off = mem.alignPointerOffset(self.buffer.ptr + self.end_index, ptr_align) orelse return null;421 const adjust_off = mem.alignPointerOffset(self.buffer.ptr + self.end_index, ptr_align) orelse return null;
422 const adjusted_index = self.end_index + adjust_off;422 const adjusted_index = self.end_index + adjust_off;
423 const new_end_index = adjusted_index + n;423 const new_end_index = adjusted_index + n;
...@@ -433,7 +433,7 @@ pub const FixedBufferAllocator = struct {...@@ -433,7 +433,7 @@ pub const FixedBufferAllocator = struct {
433 new_size: usize,433 new_size: usize,
434 return_address: usize,434 return_address: usize,
435 ) bool {435 ) bool {
436 const self = @ptrCast(*FixedBufferAllocator, @alignCast(@alignOf(FixedBufferAllocator), ctx));436 const self: *FixedBufferAllocator = @ptrCast(@alignCast(ctx));
437 _ = log2_buf_align;437 _ = log2_buf_align;
438 _ = return_address;438 _ = return_address;
439 assert(self.ownsSlice(buf)); // sanity check439 assert(self.ownsSlice(buf)); // sanity check
...@@ -462,7 +462,7 @@ pub const FixedBufferAllocator = struct {...@@ -462,7 +462,7 @@ pub const FixedBufferAllocator = struct {
462 log2_buf_align: u8,462 log2_buf_align: u8,
463 return_address: usize,463 return_address: usize,
464 ) void {464 ) void {
465 const self = @ptrCast(*FixedBufferAllocator, @alignCast(@alignOf(FixedBufferAllocator), ctx));465 const self: *FixedBufferAllocator = @ptrCast(@alignCast(ctx));
466 _ = log2_buf_align;466 _ = log2_buf_align;
467 _ = return_address;467 _ = return_address;
468 assert(self.ownsSlice(buf)); // sanity check468 assert(self.ownsSlice(buf)); // sanity check
...@@ -473,9 +473,9 @@ pub const FixedBufferAllocator = struct {...@@ -473,9 +473,9 @@ pub const FixedBufferAllocator = struct {
473 }473 }
474474
475 fn threadSafeAlloc(ctx: *anyopaque, n: usize, log2_ptr_align: u8, ra: usize) ?[*]u8 {475 fn threadSafeAlloc(ctx: *anyopaque, n: usize, log2_ptr_align: u8, ra: usize) ?[*]u8 {
476 const self = @ptrCast(*FixedBufferAllocator, @alignCast(@alignOf(FixedBufferAllocator), ctx));476 const self: *FixedBufferAllocator = @ptrCast(@alignCast(ctx));
477 _ = ra;477 _ = ra;
478 const ptr_align = @as(usize, 1) << @intCast(Allocator.Log2Align, log2_ptr_align);478 const ptr_align = @as(usize, 1) << @as(Allocator.Log2Align, @intCast(log2_ptr_align));
479 var end_index = @atomicLoad(usize, &self.end_index, .SeqCst);479 var end_index = @atomicLoad(usize, &self.end_index, .SeqCst);
480 while (true) {480 while (true) {
481 const adjust_off = mem.alignPointerOffset(self.buffer.ptr + end_index, ptr_align) orelse return null;481 const adjust_off = mem.alignPointerOffset(self.buffer.ptr + end_index, ptr_align) orelse return null;
...@@ -537,7 +537,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type {...@@ -537,7 +537,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type {
537 log2_ptr_align: u8,537 log2_ptr_align: u8,
538 ra: usize,538 ra: usize,
539 ) ?[*]u8 {539 ) ?[*]u8 {
540 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));540 const self: *Self = @ptrCast(@alignCast(ctx));
541 return FixedBufferAllocator.alloc(&self.fixed_buffer_allocator, len, log2_ptr_align, ra) orelse541 return FixedBufferAllocator.alloc(&self.fixed_buffer_allocator, len, log2_ptr_align, ra) orelse
542 return self.fallback_allocator.rawAlloc(len, log2_ptr_align, ra);542 return self.fallback_allocator.rawAlloc(len, log2_ptr_align, ra);
543 }543 }
...@@ -549,7 +549,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type {...@@ -549,7 +549,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type {
549 new_len: usize,549 new_len: usize,
550 ra: usize,550 ra: usize,
551 ) bool {551 ) bool {
552 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));552 const self: *Self = @ptrCast(@alignCast(ctx));
553 if (self.fixed_buffer_allocator.ownsPtr(buf.ptr)) {553 if (self.fixed_buffer_allocator.ownsPtr(buf.ptr)) {
554 return FixedBufferAllocator.resize(&self.fixed_buffer_allocator, buf, log2_buf_align, new_len, ra);554 return FixedBufferAllocator.resize(&self.fixed_buffer_allocator, buf, log2_buf_align, new_len, ra);
555 } else {555 } else {
...@@ -563,7 +563,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type {...@@ -563,7 +563,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type {
563 log2_buf_align: u8,563 log2_buf_align: u8,
564 ra: usize,564 ra: usize,
565 ) void {565 ) void {
566 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));566 const self: *Self = @ptrCast(@alignCast(ctx));
567 if (self.fixed_buffer_allocator.ownsPtr(buf.ptr)) {567 if (self.fixed_buffer_allocator.ownsPtr(buf.ptr)) {
568 return FixedBufferAllocator.free(&self.fixed_buffer_allocator, buf, log2_buf_align, ra);568 return FixedBufferAllocator.free(&self.fixed_buffer_allocator, buf, log2_buf_align, ra);
569 } else {569 } else {
...@@ -728,14 +728,14 @@ pub fn testAllocator(base_allocator: mem.Allocator) !void {...@@ -728,14 +728,14 @@ pub fn testAllocator(base_allocator: mem.Allocator) !void {
728 try testing.expect(slice.len == 100);728 try testing.expect(slice.len == 100);
729 for (slice, 0..) |*item, i| {729 for (slice, 0..) |*item, i| {
730 item.* = try allocator.create(i32);730 item.* = try allocator.create(i32);
731 item.*.* = @intCast(i32, i);731 item.*.* = @as(i32, @intCast(i));
732 }732 }
733733
734 slice = try allocator.realloc(slice, 20000);734 slice = try allocator.realloc(slice, 20000);
735 try testing.expect(slice.len == 20000);735 try testing.expect(slice.len == 20000);
736736
737 for (slice[0..100], 0..) |item, i| {737 for (slice[0..100], 0..) |item, i| {
738 try testing.expect(item.* == @intCast(i32, i));738 try testing.expect(item.* == @as(i32, @intCast(i)));
739 allocator.destroy(item);739 allocator.destroy(item);
740 }740 }
741741
lib/std/heap/PageAllocator.zig+6-7
...@@ -27,7 +27,7 @@ fn alloc(_: *anyopaque, n: usize, log2_align: u8, ra: usize) ?[*]u8 {...@@ -27,7 +27,7 @@ fn alloc(_: *anyopaque, n: usize, log2_align: u8, ra: usize) ?[*]u8 {
27 w.MEM_COMMIT | w.MEM_RESERVE,27 w.MEM_COMMIT | w.MEM_RESERVE,
28 w.PAGE_READWRITE,28 w.PAGE_READWRITE,
29 ) catch return null;29 ) catch return null;
30 return @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, addr));30 return @ptrCast(addr);
31 }31 }
3232
33 const hint = @atomicLoad(@TypeOf(std.heap.next_mmap_addr_hint), &std.heap.next_mmap_addr_hint, .Unordered);33 const hint = @atomicLoad(@TypeOf(std.heap.next_mmap_addr_hint), &std.heap.next_mmap_addr_hint, .Unordered);
...@@ -40,7 +40,7 @@ fn alloc(_: *anyopaque, n: usize, log2_align: u8, ra: usize) ?[*]u8 {...@@ -40,7 +40,7 @@ fn alloc(_: *anyopaque, n: usize, log2_align: u8, ra: usize) ?[*]u8 {
40 0,40 0,
41 ) catch return null;41 ) catch return null;
42 assert(mem.isAligned(@intFromPtr(slice.ptr), mem.page_size));42 assert(mem.isAligned(@intFromPtr(slice.ptr), mem.page_size));
43 const new_hint = @alignCast(mem.page_size, slice.ptr + aligned_len);43 const new_hint: [*]align(mem.page_size) u8 = @alignCast(slice.ptr + aligned_len);
44 _ = @cmpxchgStrong(@TypeOf(std.heap.next_mmap_addr_hint), &std.heap.next_mmap_addr_hint, hint, new_hint, .Monotonic, .Monotonic);44 _ = @cmpxchgStrong(@TypeOf(std.heap.next_mmap_addr_hint), &std.heap.next_mmap_addr_hint, hint, new_hint, .Monotonic, .Monotonic);
45 return slice.ptr;45 return slice.ptr;
46}46}
...@@ -66,7 +66,7 @@ fn resize(...@@ -66,7 +66,7 @@ fn resize(
66 // For shrinking that is not releasing, we will only66 // For shrinking that is not releasing, we will only
67 // decommit the pages not needed anymore.67 // decommit the pages not needed anymore.
68 w.VirtualFree(68 w.VirtualFree(
69 @ptrFromInt(*anyopaque, new_addr_end),69 @as(*anyopaque, @ptrFromInt(new_addr_end)),
70 old_addr_end - new_addr_end,70 old_addr_end - new_addr_end,
71 w.MEM_DECOMMIT,71 w.MEM_DECOMMIT,
72 );72 );
...@@ -85,9 +85,9 @@ fn resize(...@@ -85,9 +85,9 @@ fn resize(
85 return true;85 return true;
8686
87 if (new_size_aligned < buf_aligned_len) {87 if (new_size_aligned < buf_aligned_len) {
88 const ptr = @alignCast(mem.page_size, buf_unaligned.ptr + new_size_aligned);88 const ptr = buf_unaligned.ptr + new_size_aligned;
89 // TODO: if the next_mmap_addr_hint is within the unmapped range, update it89 // TODO: if the next_mmap_addr_hint is within the unmapped range, update it
90 os.munmap(ptr[0 .. buf_aligned_len - new_size_aligned]);90 os.munmap(@alignCast(ptr[0 .. buf_aligned_len - new_size_aligned]));
91 return true;91 return true;
92 }92 }
9393
...@@ -104,7 +104,6 @@ fn free(_: *anyopaque, slice: []u8, log2_buf_align: u8, return_address: usize) v...@@ -104,7 +104,6 @@ fn free(_: *anyopaque, slice: []u8, log2_buf_align: u8, return_address: usize) v
104 os.windows.VirtualFree(slice.ptr, 0, os.windows.MEM_RELEASE);104 os.windows.VirtualFree(slice.ptr, 0, os.windows.MEM_RELEASE);
105 } else {105 } else {
106 const buf_aligned_len = mem.alignForward(usize, slice.len, mem.page_size);106 const buf_aligned_len = mem.alignForward(usize, slice.len, mem.page_size);
107 const ptr = @alignCast(mem.page_size, slice.ptr);107 os.munmap(@alignCast(slice.ptr[0..buf_aligned_len]));
108 os.munmap(ptr[0..buf_aligned_len]);
109 }108 }
110}109}
lib/std/heap/ThreadSafeAllocator.zig+3-3
...@@ -15,7 +15,7 @@ pub fn allocator(self: *ThreadSafeAllocator) Allocator {...@@ -15,7 +15,7 @@ pub fn allocator(self: *ThreadSafeAllocator) Allocator {
15}15}
1616
17fn alloc(ctx: *anyopaque, n: usize, log2_ptr_align: u8, ra: usize) ?[*]u8 {17fn alloc(ctx: *anyopaque, n: usize, log2_ptr_align: u8, ra: usize) ?[*]u8 {
18 const self = @ptrCast(*ThreadSafeAllocator, @alignCast(@alignOf(ThreadSafeAllocator), ctx));18 const self: *ThreadSafeAllocator = @ptrCast(@alignCast(ctx));
19 self.mutex.lock();19 self.mutex.lock();
20 defer self.mutex.unlock();20 defer self.mutex.unlock();
2121
...@@ -23,7 +23,7 @@ fn alloc(ctx: *anyopaque, n: usize, log2_ptr_align: u8, ra: usize) ?[*]u8 {...@@ -23,7 +23,7 @@ fn alloc(ctx: *anyopaque, n: usize, log2_ptr_align: u8, ra: usize) ?[*]u8 {
23}23}
2424
25fn resize(ctx: *anyopaque, buf: []u8, log2_buf_align: u8, new_len: usize, ret_addr: usize) bool {25fn resize(ctx: *anyopaque, buf: []u8, log2_buf_align: u8, new_len: usize, ret_addr: usize) bool {
26 const self = @ptrCast(*ThreadSafeAllocator, @alignCast(@alignOf(ThreadSafeAllocator), ctx));26 const self: *ThreadSafeAllocator = @ptrCast(@alignCast(ctx));
2727
28 self.mutex.lock();28 self.mutex.lock();
29 defer self.mutex.unlock();29 defer self.mutex.unlock();
...@@ -32,7 +32,7 @@ fn resize(ctx: *anyopaque, buf: []u8, log2_buf_align: u8, new_len: usize, ret_ad...@@ -32,7 +32,7 @@ fn resize(ctx: *anyopaque, buf: []u8, log2_buf_align: u8, new_len: usize, ret_ad
32}32}
3333
34fn free(ctx: *anyopaque, buf: []u8, log2_buf_align: u8, ret_addr: usize) void {34fn free(ctx: *anyopaque, buf: []u8, log2_buf_align: u8, ret_addr: usize) void {
35 const self = @ptrCast(*ThreadSafeAllocator, @alignCast(@alignOf(ThreadSafeAllocator), ctx));35 const self: *ThreadSafeAllocator = @ptrCast(@alignCast(ctx));
3636
37 self.mutex.lock();37 self.mutex.lock();
38 defer self.mutex.unlock();38 defer self.mutex.unlock();
lib/std/heap/WasmAllocator.zig+10-10
...@@ -47,7 +47,7 @@ fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, return_address: usize) ?[*...@@ -47,7 +47,7 @@ fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, return_address: usize) ?[*
47 _ = ctx;47 _ = ctx;
48 _ = return_address;48 _ = return_address;
49 // Make room for the freelist next pointer.49 // Make room for the freelist next pointer.
50 const alignment = @as(usize, 1) << @intCast(Allocator.Log2Align, log2_align);50 const alignment = @as(usize, 1) << @as(Allocator.Log2Align, @intCast(log2_align));
51 const actual_len = @max(len +| @sizeOf(usize), alignment);51 const actual_len = @max(len +| @sizeOf(usize), alignment);
52 const slot_size = math.ceilPowerOfTwo(usize, actual_len) catch return null;52 const slot_size = math.ceilPowerOfTwo(usize, actual_len) catch return null;
53 const class = math.log2(slot_size) - min_class;53 const class = math.log2(slot_size) - min_class;
...@@ -55,7 +55,7 @@ fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, return_address: usize) ?[*...@@ -55,7 +55,7 @@ fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, return_address: usize) ?[*
55 const addr = a: {55 const addr = a: {
56 const top_free_ptr = frees[class];56 const top_free_ptr = frees[class];
57 if (top_free_ptr != 0) {57 if (top_free_ptr != 0) {
58 const node = @ptrFromInt(*usize, top_free_ptr + (slot_size - @sizeOf(usize)));58 const node = @as(*usize, @ptrFromInt(top_free_ptr + (slot_size - @sizeOf(usize))));
59 frees[class] = node.*;59 frees[class] = node.*;
60 break :a top_free_ptr;60 break :a top_free_ptr;
61 }61 }
...@@ -74,11 +74,11 @@ fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, return_address: usize) ?[*...@@ -74,11 +74,11 @@ fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, return_address: usize) ?[*
74 break :a next_addr;74 break :a next_addr;
75 }75 }
76 };76 };
77 return @ptrFromInt([*]u8, addr);77 return @as([*]u8, @ptrFromInt(addr));
78 }78 }
79 const bigpages_needed = bigPagesNeeded(actual_len);79 const bigpages_needed = bigPagesNeeded(actual_len);
80 const addr = allocBigPages(bigpages_needed);80 const addr = allocBigPages(bigpages_needed);
81 return @ptrFromInt([*]u8, addr);81 return @as([*]u8, @ptrFromInt(addr));
82}82}
8383
84fn resize(84fn resize(
...@@ -92,7 +92,7 @@ fn resize(...@@ -92,7 +92,7 @@ fn resize(
92 _ = return_address;92 _ = return_address;
93 // We don't want to move anything from one size class to another, but we93 // We don't want to move anything from one size class to another, but we
94 // can recover bytes in between powers of two.94 // can recover bytes in between powers of two.
95 const buf_align = @as(usize, 1) << @intCast(Allocator.Log2Align, log2_buf_align);95 const buf_align = @as(usize, 1) << @as(Allocator.Log2Align, @intCast(log2_buf_align));
96 const old_actual_len = @max(buf.len + @sizeOf(usize), buf_align);96 const old_actual_len = @max(buf.len + @sizeOf(usize), buf_align);
97 const new_actual_len = @max(new_len +| @sizeOf(usize), buf_align);97 const new_actual_len = @max(new_len +| @sizeOf(usize), buf_align);
98 const old_small_slot_size = math.ceilPowerOfTwoAssert(usize, old_actual_len);98 const old_small_slot_size = math.ceilPowerOfTwoAssert(usize, old_actual_len);
...@@ -117,20 +117,20 @@ fn free(...@@ -117,20 +117,20 @@ fn free(
117) void {117) void {
118 _ = ctx;118 _ = ctx;
119 _ = return_address;119 _ = return_address;
120 const buf_align = @as(usize, 1) << @intCast(Allocator.Log2Align, log2_buf_align);120 const buf_align = @as(usize, 1) << @as(Allocator.Log2Align, @intCast(log2_buf_align));
121 const actual_len = @max(buf.len + @sizeOf(usize), buf_align);121 const actual_len = @max(buf.len + @sizeOf(usize), buf_align);
122 const slot_size = math.ceilPowerOfTwoAssert(usize, actual_len);122 const slot_size = math.ceilPowerOfTwoAssert(usize, actual_len);
123 const class = math.log2(slot_size) - min_class;123 const class = math.log2(slot_size) - min_class;
124 const addr = @intFromPtr(buf.ptr);124 const addr = @intFromPtr(buf.ptr);
125 if (class < size_class_count) {125 if (class < size_class_count) {
126 const node = @ptrFromInt(*usize, addr + (slot_size - @sizeOf(usize)));126 const node = @as(*usize, @ptrFromInt(addr + (slot_size - @sizeOf(usize))));
127 node.* = frees[class];127 node.* = frees[class];
128 frees[class] = addr;128 frees[class] = addr;
129 } else {129 } else {
130 const bigpages_needed = bigPagesNeeded(actual_len);130 const bigpages_needed = bigPagesNeeded(actual_len);
131 const pow2_pages = math.ceilPowerOfTwoAssert(usize, bigpages_needed);131 const pow2_pages = math.ceilPowerOfTwoAssert(usize, bigpages_needed);
132 const big_slot_size_bytes = pow2_pages * bigpage_size;132 const big_slot_size_bytes = pow2_pages * bigpage_size;
133 const node = @ptrFromInt(*usize, addr + (big_slot_size_bytes - @sizeOf(usize)));133 const node = @as(*usize, @ptrFromInt(addr + (big_slot_size_bytes - @sizeOf(usize))));
134 const big_class = math.log2(pow2_pages);134 const big_class = math.log2(pow2_pages);
135 node.* = big_frees[big_class];135 node.* = big_frees[big_class];
136 big_frees[big_class] = addr;136 big_frees[big_class] = addr;
...@@ -148,14 +148,14 @@ fn allocBigPages(n: usize) usize {...@@ -148,14 +148,14 @@ fn allocBigPages(n: usize) usize {
148148
149 const top_free_ptr = big_frees[class];149 const top_free_ptr = big_frees[class];
150 if (top_free_ptr != 0) {150 if (top_free_ptr != 0) {
151 const node = @ptrFromInt(*usize, top_free_ptr + (slot_size_bytes - @sizeOf(usize)));151 const node = @as(*usize, @ptrFromInt(top_free_ptr + (slot_size_bytes - @sizeOf(usize))));
152 big_frees[class] = node.*;152 big_frees[class] = node.*;
153 return top_free_ptr;153 return top_free_ptr;
154 }154 }
155155
156 const page_index = @wasmMemoryGrow(0, pow2_pages * pages_per_bigpage);156 const page_index = @wasmMemoryGrow(0, pow2_pages * pages_per_bigpage);
157 if (page_index <= 0) return 0;157 if (page_index <= 0) return 0;
158 const addr = @intCast(u32, page_index) * wasm.page_size;158 const addr = @as(u32, @intCast(page_index)) * wasm.page_size;
159 return addr;159 return addr;
160}160}
161161
lib/std/heap/WasmPageAllocator.zig+6-6
...@@ -40,7 +40,7 @@ const FreeBlock = struct {...@@ -40,7 +40,7 @@ const FreeBlock = struct {
4040
41 fn getBit(self: FreeBlock, idx: usize) PageStatus {41 fn getBit(self: FreeBlock, idx: usize) PageStatus {
42 const bit_offset = 0;42 const bit_offset = 0;
43 return @enumFromInt(PageStatus, Io.get(mem.sliceAsBytes(self.data), idx, bit_offset));43 return @as(PageStatus, @enumFromInt(Io.get(mem.sliceAsBytes(self.data), idx, bit_offset)));
44 }44 }
4545
46 fn setBits(self: FreeBlock, start_idx: usize, len: usize, val: PageStatus) void {46 fn setBits(self: FreeBlock, start_idx: usize, len: usize, val: PageStatus) void {
...@@ -63,7 +63,7 @@ const FreeBlock = struct {...@@ -63,7 +63,7 @@ const FreeBlock = struct {
63 fn useRecycled(self: FreeBlock, num_pages: usize, log2_align: u8) usize {63 fn useRecycled(self: FreeBlock, num_pages: usize, log2_align: u8) usize {
64 @setCold(true);64 @setCold(true);
65 for (self.data, 0..) |segment, i| {65 for (self.data, 0..) |segment, i| {
66 const spills_into_next = @bitCast(i128, segment) < 0;66 const spills_into_next = @as(i128, @bitCast(segment)) < 0;
67 const has_enough_bits = @popCount(segment) >= num_pages;67 const has_enough_bits = @popCount(segment) >= num_pages;
6868
69 if (!spills_into_next and !has_enough_bits) continue;69 if (!spills_into_next and !has_enough_bits) continue;
...@@ -109,7 +109,7 @@ fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, ra: usize) ?[*]u8 {...@@ -109,7 +109,7 @@ fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, ra: usize) ?[*]u8 {
109 if (len > maxInt(usize) - (mem.page_size - 1)) return null;109 if (len > maxInt(usize) - (mem.page_size - 1)) return null;
110 const page_count = nPages(len);110 const page_count = nPages(len);
111 const page_idx = allocPages(page_count, log2_align) catch return null;111 const page_idx = allocPages(page_count, log2_align) catch return null;
112 return @ptrFromInt([*]u8, page_idx * mem.page_size);112 return @as([*]u8, @ptrFromInt(page_idx * mem.page_size));
113}113}
114114
115fn allocPages(page_count: usize, log2_align: u8) !usize {115fn allocPages(page_count: usize, log2_align: u8) !usize {
...@@ -129,7 +129,7 @@ fn allocPages(page_count: usize, log2_align: u8) !usize {...@@ -129,7 +129,7 @@ fn allocPages(page_count: usize, log2_align: u8) !usize {
129 const next_page_addr = next_page_idx * mem.page_size;129 const next_page_addr = next_page_idx * mem.page_size;
130 const aligned_addr = mem.alignForwardLog2(next_page_addr, log2_align);130 const aligned_addr = mem.alignForwardLog2(next_page_addr, log2_align);
131 const drop_page_count = @divExact(aligned_addr - next_page_addr, mem.page_size);131 const drop_page_count = @divExact(aligned_addr - next_page_addr, mem.page_size);
132 const result = @wasmMemoryGrow(0, @intCast(u32, drop_page_count + page_count));132 const result = @wasmMemoryGrow(0, @as(u32, @intCast(drop_page_count + page_count)));
133 if (result <= 0)133 if (result <= 0)
134 return error.OutOfMemory;134 return error.OutOfMemory;
135 assert(result == next_page_idx);135 assert(result == next_page_idx);
...@@ -137,7 +137,7 @@ fn allocPages(page_count: usize, log2_align: u8) !usize {...@@ -137,7 +137,7 @@ fn allocPages(page_count: usize, log2_align: u8) !usize {
137 if (drop_page_count > 0) {137 if (drop_page_count > 0) {
138 freePages(next_page_idx, aligned_page_idx);138 freePages(next_page_idx, aligned_page_idx);
139 }139 }
140 return @intCast(usize, aligned_page_idx);140 return @as(usize, @intCast(aligned_page_idx));
141}141}
142142
143fn freePages(start: usize, end: usize) void {143fn freePages(start: usize, end: usize) void {
...@@ -151,7 +151,7 @@ fn freePages(start: usize, end: usize) void {...@@ -151,7 +151,7 @@ fn freePages(start: usize, end: usize) void {
151 // TODO: would it be better if we use the first page instead?151 // TODO: would it be better if we use the first page instead?
152 new_end -= 1;152 new_end -= 1;
153153
154 extended.data = @ptrFromInt([*]u128, new_end * mem.page_size)[0 .. mem.page_size / @sizeOf(u128)];154 extended.data = @as([*]u128, @ptrFromInt(new_end * mem.page_size))[0 .. mem.page_size / @sizeOf(u128)];
155 // Since this is the first page being freed and we consume it, assume *nothing* is free.155 // Since this is the first page being freed and we consume it, assume *nothing* is free.
156 @memset(extended.data, PageStatus.none_free);156 @memset(extended.data, PageStatus.none_free);
157 }157 }
lib/std/heap/arena_allocator.zig+12-12
...@@ -48,7 +48,7 @@ pub const ArenaAllocator = struct {...@@ -48,7 +48,7 @@ pub const ArenaAllocator = struct {
48 // this has to occur before the free because the free frees node48 // this has to occur before the free because the free frees node
49 const next_it = node.next;49 const next_it = node.next;
50 const align_bits = std.math.log2_int(usize, @alignOf(BufNode));50 const align_bits = std.math.log2_int(usize, @alignOf(BufNode));
51 const alloc_buf = @ptrCast([*]u8, node)[0..node.data];51 const alloc_buf = @as([*]u8, @ptrCast(node))[0..node.data];
52 self.child_allocator.rawFree(alloc_buf, align_bits, @returnAddress());52 self.child_allocator.rawFree(alloc_buf, align_bits, @returnAddress());
53 it = next_it;53 it = next_it;
54 }54 }
...@@ -128,7 +128,7 @@ pub const ArenaAllocator = struct {...@@ -128,7 +128,7 @@ pub const ArenaAllocator = struct {
128 const next_it = node.next;128 const next_it = node.next;
129 if (next_it == null)129 if (next_it == null)
130 break node;130 break node;
131 const alloc_buf = @ptrCast([*]u8, node)[0..node.data];131 const alloc_buf = @as([*]u8, @ptrCast(node))[0..node.data];
132 self.child_allocator.rawFree(alloc_buf, align_bits, @returnAddress());132 self.child_allocator.rawFree(alloc_buf, align_bits, @returnAddress());
133 it = next_it;133 it = next_it;
134 } else null;134 } else null;
...@@ -140,7 +140,7 @@ pub const ArenaAllocator = struct {...@@ -140,7 +140,7 @@ pub const ArenaAllocator = struct {
140 // perfect, no need to invoke the child_allocator140 // perfect, no need to invoke the child_allocator
141 if (first_node.data == total_size)141 if (first_node.data == total_size)
142 return true;142 return true;
143 const first_alloc_buf = @ptrCast([*]u8, first_node)[0..first_node.data];143 const first_alloc_buf = @as([*]u8, @ptrCast(first_node))[0..first_node.data];
144 if (self.child_allocator.rawResize(first_alloc_buf, align_bits, total_size, @returnAddress())) {144 if (self.child_allocator.rawResize(first_alloc_buf, align_bits, total_size, @returnAddress())) {
145 // successful resize145 // successful resize
146 first_node.data = total_size;146 first_node.data = total_size;
...@@ -151,7 +151,7 @@ pub const ArenaAllocator = struct {...@@ -151,7 +151,7 @@ pub const ArenaAllocator = struct {
151 return false;151 return false;
152 };152 };
153 self.child_allocator.rawFree(first_alloc_buf, align_bits, @returnAddress());153 self.child_allocator.rawFree(first_alloc_buf, align_bits, @returnAddress());
154 const node = @ptrCast(*BufNode, @alignCast(@alignOf(BufNode), new_ptr));154 const node: *BufNode = @ptrCast(@alignCast(new_ptr));
155 node.* = .{ .data = total_size };155 node.* = .{ .data = total_size };
156 self.state.buffer_list.first = node;156 self.state.buffer_list.first = node;
157 }157 }
...@@ -166,7 +166,7 @@ pub const ArenaAllocator = struct {...@@ -166,7 +166,7 @@ pub const ArenaAllocator = struct {
166 const log2_align = comptime std.math.log2_int(usize, @alignOf(BufNode));166 const log2_align = comptime std.math.log2_int(usize, @alignOf(BufNode));
167 const ptr = self.child_allocator.rawAlloc(len, log2_align, @returnAddress()) orelse167 const ptr = self.child_allocator.rawAlloc(len, log2_align, @returnAddress()) orelse
168 return null;168 return null;
169 const buf_node = @ptrCast(*BufNode, @alignCast(@alignOf(BufNode), ptr));169 const buf_node: *BufNode = @ptrCast(@alignCast(ptr));
170 buf_node.* = .{ .data = len };170 buf_node.* = .{ .data = len };
171 self.state.buffer_list.prepend(buf_node);171 self.state.buffer_list.prepend(buf_node);
172 self.state.end_index = 0;172 self.state.end_index = 0;
...@@ -174,16 +174,16 @@ pub const ArenaAllocator = struct {...@@ -174,16 +174,16 @@ pub const ArenaAllocator = struct {
174 }174 }
175175
176 fn alloc(ctx: *anyopaque, n: usize, log2_ptr_align: u8, ra: usize) ?[*]u8 {176 fn alloc(ctx: *anyopaque, n: usize, log2_ptr_align: u8, ra: usize) ?[*]u8 {
177 const self = @ptrCast(*ArenaAllocator, @alignCast(@alignOf(ArenaAllocator), ctx));177 const self: *ArenaAllocator = @ptrCast(@alignCast(ctx));
178 _ = ra;178 _ = ra;
179179
180 const ptr_align = @as(usize, 1) << @intCast(Allocator.Log2Align, log2_ptr_align);180 const ptr_align = @as(usize, 1) << @as(Allocator.Log2Align, @intCast(log2_ptr_align));
181 var cur_node = if (self.state.buffer_list.first) |first_node|181 var cur_node = if (self.state.buffer_list.first) |first_node|
182 first_node182 first_node
183 else183 else
184 (self.createNode(0, n + ptr_align) orelse return null);184 (self.createNode(0, n + ptr_align) orelse return null);
185 while (true) {185 while (true) {
186 const cur_alloc_buf = @ptrCast([*]u8, cur_node)[0..cur_node.data];186 const cur_alloc_buf = @as([*]u8, @ptrCast(cur_node))[0..cur_node.data];
187 const cur_buf = cur_alloc_buf[@sizeOf(BufNode)..];187 const cur_buf = cur_alloc_buf[@sizeOf(BufNode)..];
188 const addr = @intFromPtr(cur_buf.ptr) + self.state.end_index;188 const addr = @intFromPtr(cur_buf.ptr) + self.state.end_index;
189 const adjusted_addr = mem.alignForward(usize, addr, ptr_align);189 const adjusted_addr = mem.alignForward(usize, addr, ptr_align);
...@@ -208,12 +208,12 @@ pub const ArenaAllocator = struct {...@@ -208,12 +208,12 @@ pub const ArenaAllocator = struct {
208 }208 }
209209
210 fn resize(ctx: *anyopaque, buf: []u8, log2_buf_align: u8, new_len: usize, ret_addr: usize) bool {210 fn resize(ctx: *anyopaque, buf: []u8, log2_buf_align: u8, new_len: usize, ret_addr: usize) bool {
211 const self = @ptrCast(*ArenaAllocator, @alignCast(@alignOf(ArenaAllocator), ctx));211 const self: *ArenaAllocator = @ptrCast(@alignCast(ctx));
212 _ = log2_buf_align;212 _ = log2_buf_align;
213 _ = ret_addr;213 _ = ret_addr;
214214
215 const cur_node = self.state.buffer_list.first orelse return false;215 const cur_node = self.state.buffer_list.first orelse return false;
216 const cur_buf = @ptrCast([*]u8, cur_node)[@sizeOf(BufNode)..cur_node.data];216 const cur_buf = @as([*]u8, @ptrCast(cur_node))[@sizeOf(BufNode)..cur_node.data];
217 if (@intFromPtr(cur_buf.ptr) + self.state.end_index != @intFromPtr(buf.ptr) + buf.len) {217 if (@intFromPtr(cur_buf.ptr) + self.state.end_index != @intFromPtr(buf.ptr) + buf.len) {
218 // It's not the most recent allocation, so it cannot be expanded,218 // It's not the most recent allocation, so it cannot be expanded,
219 // but it's fine if they want to make it smaller.219 // but it's fine if they want to make it smaller.
...@@ -235,10 +235,10 @@ pub const ArenaAllocator = struct {...@@ -235,10 +235,10 @@ pub const ArenaAllocator = struct {
235 _ = log2_buf_align;235 _ = log2_buf_align;
236 _ = ret_addr;236 _ = ret_addr;
237237
238 const self = @ptrCast(*ArenaAllocator, @alignCast(@alignOf(ArenaAllocator), ctx));238 const self: *ArenaAllocator = @ptrCast(@alignCast(ctx));
239239
240 const cur_node = self.state.buffer_list.first orelse return;240 const cur_node = self.state.buffer_list.first orelse return;
241 const cur_buf = @ptrCast([*]u8, cur_node)[@sizeOf(BufNode)..cur_node.data];241 const cur_buf = @as([*]u8, @ptrCast(cur_node))[@sizeOf(BufNode)..cur_node.data];
242242
243 if (@intFromPtr(cur_buf.ptr) + self.state.end_index == @intFromPtr(buf.ptr) + buf.len) {243 if (@intFromPtr(cur_buf.ptr) + self.state.end_index == @intFromPtr(buf.ptr) + buf.len) {
244 self.state.end_index -= buf.len;244 self.state.end_index -= buf.len;
lib/std/heap/general_purpose_allocator.zig+28-28
...@@ -250,7 +250,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -250,7 +250,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
250 used_count: SlotIndex,250 used_count: SlotIndex,
251251
252 fn usedBits(bucket: *BucketHeader, index: usize) *u8 {252 fn usedBits(bucket: *BucketHeader, index: usize) *u8 {
253 return @ptrFromInt(*u8, @intFromPtr(bucket) + @sizeOf(BucketHeader) + index);253 return @as(*u8, @ptrFromInt(@intFromPtr(bucket) + @sizeOf(BucketHeader) + index));
254 }254 }
255255
256 fn stackTracePtr(256 fn stackTracePtr(
...@@ -259,10 +259,10 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -259,10 +259,10 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
259 slot_index: SlotIndex,259 slot_index: SlotIndex,
260 trace_kind: TraceKind,260 trace_kind: TraceKind,
261 ) *[stack_n]usize {261 ) *[stack_n]usize {
262 const start_ptr = @ptrCast([*]u8, bucket) + bucketStackFramesStart(size_class);262 const start_ptr = @as([*]u8, @ptrCast(bucket)) + bucketStackFramesStart(size_class);
263 const addr = start_ptr + one_trace_size * traces_per_slot * slot_index +263 const addr = start_ptr + one_trace_size * traces_per_slot * slot_index +
264 @intFromEnum(trace_kind) * @as(usize, one_trace_size);264 @intFromEnum(trace_kind) * @as(usize, one_trace_size);
265 return @ptrCast(*[stack_n]usize, @alignCast(@alignOf(usize), addr));265 return @ptrCast(@alignCast(addr));
266 }266 }
267267
268 fn captureStackTrace(268 fn captureStackTrace(
...@@ -338,9 +338,9 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -338,9 +338,9 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
338 if (used_byte != 0) {338 if (used_byte != 0) {
339 var bit_index: u3 = 0;339 var bit_index: u3 = 0;
340 while (true) : (bit_index += 1) {340 while (true) : (bit_index += 1) {
341 const is_used = @truncate(u1, used_byte >> bit_index) != 0;341 const is_used = @as(u1, @truncate(used_byte >> bit_index)) != 0;
342 if (is_used) {342 if (is_used) {
343 const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);343 const slot_index = @as(SlotIndex, @intCast(used_bits_byte * 8 + bit_index));
344 const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);344 const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);
345 const addr = bucket.page + slot_index * size_class;345 const addr = bucket.page + slot_index * size_class;
346 log.err("memory address 0x{x} leaked: {}", .{346 log.err("memory address 0x{x} leaked: {}", .{
...@@ -361,7 +361,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -361,7 +361,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
361 var leaks = false;361 var leaks = false;
362 for (self.buckets, 0..) |optional_bucket, bucket_i| {362 for (self.buckets, 0..) |optional_bucket, bucket_i| {
363 const first_bucket = optional_bucket orelse continue;363 const first_bucket = optional_bucket orelse continue;
364 const size_class = @as(usize, 1) << @intCast(math.Log2Int(usize), bucket_i);364 const size_class = @as(usize, 1) << @as(math.Log2Int(usize), @intCast(bucket_i));
365 const used_bits_count = usedBitsCount(size_class);365 const used_bits_count = usedBitsCount(size_class);
366 var bucket = first_bucket;366 var bucket = first_bucket;
367 while (true) {367 while (true) {
...@@ -385,7 +385,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -385,7 +385,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
385385
386 fn freeBucket(self: *Self, bucket: *BucketHeader, size_class: usize) void {386 fn freeBucket(self: *Self, bucket: *BucketHeader, size_class: usize) void {
387 const bucket_size = bucketSize(size_class);387 const bucket_size = bucketSize(size_class);
388 const bucket_slice = @ptrCast([*]align(@alignOf(BucketHeader)) u8, bucket)[0..bucket_size];388 const bucket_slice = @as([*]align(@alignOf(BucketHeader)) u8, @ptrCast(bucket))[0..bucket_size];
389 self.backing_allocator.free(bucket_slice);389 self.backing_allocator.free(bucket_slice);
390 }390 }
391391
...@@ -444,7 +444,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -444,7 +444,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
444 self.small_allocations.deinit(self.backing_allocator);444 self.small_allocations.deinit(self.backing_allocator);
445 }445 }
446 self.* = undefined;446 self.* = undefined;
447 return @enumFromInt(Check, @intFromBool(leaks));447 return @as(Check, @enumFromInt(@intFromBool(leaks)));
448 }448 }
449449
450 fn collectStackTrace(first_trace_addr: usize, addresses: *[stack_n]usize) void {450 fn collectStackTrace(first_trace_addr: usize, addresses: *[stack_n]usize) void {
...@@ -496,7 +496,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -496,7 +496,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
496 bucket.alloc_cursor += 1;496 bucket.alloc_cursor += 1;
497497
498 var used_bits_byte = bucket.usedBits(slot_index / 8);498 var used_bits_byte = bucket.usedBits(slot_index / 8);
499 const used_bit_index: u3 = @intCast(u3, slot_index % 8); // TODO cast should be unnecessary499 const used_bit_index: u3 = @as(u3, @intCast(slot_index % 8)); // TODO cast should be unnecessary
500 used_bits_byte.* |= (@as(u8, 1) << used_bit_index);500 used_bits_byte.* |= (@as(u8, 1) << used_bit_index);
501 bucket.used_count += 1;501 bucket.used_count += 1;
502 bucket.captureStackTrace(trace_addr, size_class, slot_index, .alloc);502 bucket.captureStackTrace(trace_addr, size_class, slot_index, .alloc);
...@@ -667,8 +667,8 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -667,8 +667,8 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
667 new_size: usize,667 new_size: usize,
668 ret_addr: usize,668 ret_addr: usize,
669 ) bool {669 ) bool {
670 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));670 const self: *Self = @ptrCast(@alignCast(ctx));
671 const log2_old_align = @intCast(Allocator.Log2Align, log2_old_align_u8);671 const log2_old_align = @as(Allocator.Log2Align, @intCast(log2_old_align_u8));
672 self.mutex.lock();672 self.mutex.lock();
673 defer self.mutex.unlock();673 defer self.mutex.unlock();
674674
...@@ -704,11 +704,11 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -704,11 +704,11 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
704 return self.resizeLarge(old_mem, log2_old_align, new_size, ret_addr);704 return self.resizeLarge(old_mem, log2_old_align, new_size, ret_addr);
705 };705 };
706 const byte_offset = @intFromPtr(old_mem.ptr) - @intFromPtr(bucket.page);706 const byte_offset = @intFromPtr(old_mem.ptr) - @intFromPtr(bucket.page);
707 const slot_index = @intCast(SlotIndex, byte_offset / size_class);707 const slot_index = @as(SlotIndex, @intCast(byte_offset / size_class));
708 const used_byte_index = slot_index / 8;708 const used_byte_index = slot_index / 8;
709 const used_bit_index = @intCast(u3, slot_index % 8);709 const used_bit_index = @as(u3, @intCast(slot_index % 8));
710 const used_byte = bucket.usedBits(used_byte_index);710 const used_byte = bucket.usedBits(used_byte_index);
711 const is_used = @truncate(u1, used_byte.* >> used_bit_index) != 0;711 const is_used = @as(u1, @truncate(used_byte.* >> used_bit_index)) != 0;
712 if (!is_used) {712 if (!is_used) {
713 if (config.safety) {713 if (config.safety) {
714 reportDoubleFree(ret_addr, bucketStackTrace(bucket, size_class, slot_index, .alloc), bucketStackTrace(bucket, size_class, slot_index, .free));714 reportDoubleFree(ret_addr, bucketStackTrace(bucket, size_class, slot_index, .alloc), bucketStackTrace(bucket, size_class, slot_index, .free));
...@@ -739,8 +739,8 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -739,8 +739,8 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
739 }739 }
740 if (log2_old_align != entry.value_ptr.log2_ptr_align) {740 if (log2_old_align != entry.value_ptr.log2_ptr_align) {
741 log.err("Allocation alignment {d} does not match resize alignment {d}. Allocation: {} Resize: {}", .{741 log.err("Allocation alignment {d} does not match resize alignment {d}. Allocation: {} Resize: {}", .{
742 @as(usize, 1) << @intCast(math.Log2Int(usize), entry.value_ptr.log2_ptr_align),742 @as(usize, 1) << @as(math.Log2Int(usize), @intCast(entry.value_ptr.log2_ptr_align)),
743 @as(usize, 1) << @intCast(math.Log2Int(usize), log2_old_align),743 @as(usize, 1) << @as(math.Log2Int(usize), @intCast(log2_old_align)),
744 bucketStackTrace(bucket, size_class, slot_index, .alloc),744 bucketStackTrace(bucket, size_class, slot_index, .alloc),
745 free_stack_trace,745 free_stack_trace,
746 });746 });
...@@ -786,8 +786,8 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -786,8 +786,8 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
786 log2_old_align_u8: u8,786 log2_old_align_u8: u8,
787 ret_addr: usize,787 ret_addr: usize,
788 ) void {788 ) void {
789 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));789 const self: *Self = @ptrCast(@alignCast(ctx));
790 const log2_old_align = @intCast(Allocator.Log2Align, log2_old_align_u8);790 const log2_old_align = @as(Allocator.Log2Align, @intCast(log2_old_align_u8));
791 self.mutex.lock();791 self.mutex.lock();
792 defer self.mutex.unlock();792 defer self.mutex.unlock();
793793
...@@ -825,11 +825,11 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -825,11 +825,11 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
825 return;825 return;
826 };826 };
827 const byte_offset = @intFromPtr(old_mem.ptr) - @intFromPtr(bucket.page);827 const byte_offset = @intFromPtr(old_mem.ptr) - @intFromPtr(bucket.page);
828 const slot_index = @intCast(SlotIndex, byte_offset / size_class);828 const slot_index = @as(SlotIndex, @intCast(byte_offset / size_class));
829 const used_byte_index = slot_index / 8;829 const used_byte_index = slot_index / 8;
830 const used_bit_index = @intCast(u3, slot_index % 8);830 const used_bit_index = @as(u3, @intCast(slot_index % 8));
831 const used_byte = bucket.usedBits(used_byte_index);831 const used_byte = bucket.usedBits(used_byte_index);
832 const is_used = @truncate(u1, used_byte.* >> used_bit_index) != 0;832 const is_used = @as(u1, @truncate(used_byte.* >> used_bit_index)) != 0;
833 if (!is_used) {833 if (!is_used) {
834 if (config.safety) {834 if (config.safety) {
835 reportDoubleFree(ret_addr, bucketStackTrace(bucket, size_class, slot_index, .alloc), bucketStackTrace(bucket, size_class, slot_index, .free));835 reportDoubleFree(ret_addr, bucketStackTrace(bucket, size_class, slot_index, .alloc), bucketStackTrace(bucket, size_class, slot_index, .free));
...@@ -861,8 +861,8 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -861,8 +861,8 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
861 }861 }
862 if (log2_old_align != entry.value_ptr.log2_ptr_align) {862 if (log2_old_align != entry.value_ptr.log2_ptr_align) {
863 log.err("Allocation alignment {d} does not match free alignment {d}. Allocation: {} Free: {}", .{863 log.err("Allocation alignment {d} does not match free alignment {d}. Allocation: {} Free: {}", .{
864 @as(usize, 1) << @intCast(math.Log2Int(usize), entry.value_ptr.log2_ptr_align),864 @as(usize, 1) << @as(math.Log2Int(usize), @intCast(entry.value_ptr.log2_ptr_align)),
865 @as(usize, 1) << @intCast(math.Log2Int(usize), log2_old_align),865 @as(usize, 1) << @as(math.Log2Int(usize), @intCast(log2_old_align)),
866 bucketStackTrace(bucket, size_class, slot_index, .alloc),866 bucketStackTrace(bucket, size_class, slot_index, .alloc),
867 free_stack_trace,867 free_stack_trace,
868 });868 });
...@@ -896,7 +896,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -896,7 +896,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
896 } else {896 } else {
897 // move alloc_cursor to end so we can tell size_class later897 // move alloc_cursor to end so we can tell size_class later
898 const slot_count = @divExact(page_size, size_class);898 const slot_count = @divExact(page_size, size_class);
899 bucket.alloc_cursor = @truncate(SlotIndex, slot_count);899 bucket.alloc_cursor = @as(SlotIndex, @truncate(slot_count));
900 if (self.empty_buckets) |prev_bucket| {900 if (self.empty_buckets) |prev_bucket| {
901 // empty_buckets is ordered newest to oldest through prev so that if901 // empty_buckets is ordered newest to oldest through prev so that if
902 // config.never_unmap is false and backing_allocator reuses freed memory902 // config.never_unmap is false and backing_allocator reuses freed memory
...@@ -936,11 +936,11 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -936,11 +936,11 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
936 }936 }
937937
938 fn alloc(ctx: *anyopaque, len: usize, log2_ptr_align: u8, ret_addr: usize) ?[*]u8 {938 fn alloc(ctx: *anyopaque, len: usize, log2_ptr_align: u8, ret_addr: usize) ?[*]u8 {
939 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));939 const self: *Self = @ptrCast(@alignCast(ctx));
940 self.mutex.lock();940 self.mutex.lock();
941 defer self.mutex.unlock();941 defer self.mutex.unlock();
942 if (!self.isAllocationAllowed(len)) return null;942 if (!self.isAllocationAllowed(len)) return null;
943 return allocInner(self, len, @intCast(Allocator.Log2Align, log2_ptr_align), ret_addr) catch return null;943 return allocInner(self, len, @as(Allocator.Log2Align, @intCast(log2_ptr_align)), ret_addr) catch return null;
944 }944 }
945945
946 fn allocInner(946 fn allocInner(
...@@ -949,7 +949,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -949,7 +949,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
949 log2_ptr_align: Allocator.Log2Align,949 log2_ptr_align: Allocator.Log2Align,
950 ret_addr: usize,950 ret_addr: usize,
951 ) Allocator.Error![*]u8 {951 ) Allocator.Error![*]u8 {
952 const new_aligned_size = @max(len, @as(usize, 1) << @intCast(Allocator.Log2Align, log2_ptr_align));952 const new_aligned_size = @max(len, @as(usize, 1) << @as(Allocator.Log2Align, @intCast(log2_ptr_align)));
953 if (new_aligned_size > largest_bucket_object_size) {953 if (new_aligned_size > largest_bucket_object_size) {
954 try self.large_allocations.ensureUnusedCapacity(self.backing_allocator, 1);954 try self.large_allocations.ensureUnusedCapacity(self.backing_allocator, 1);
955 const ptr = self.backing_allocator.rawAlloc(len, log2_ptr_align, ret_addr) orelse955 const ptr = self.backing_allocator.rawAlloc(len, log2_ptr_align, ret_addr) orelse
...@@ -1002,7 +1002,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -1002,7 +1002,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
10021002
1003 const bucket_size = bucketSize(size_class);1003 const bucket_size = bucketSize(size_class);
1004 const bucket_bytes = try self.backing_allocator.alignedAlloc(u8, @alignOf(BucketHeader), bucket_size);1004 const bucket_bytes = try self.backing_allocator.alignedAlloc(u8, @alignOf(BucketHeader), bucket_size);
1005 const ptr = @ptrCast(*BucketHeader, bucket_bytes.ptr);1005 const ptr = @as(*BucketHeader, @ptrCast(bucket_bytes.ptr));
1006 ptr.* = BucketHeader{1006 ptr.* = BucketHeader{
1007 .prev = ptr,1007 .prev = ptr,
1008 .next = ptr,1008 .next = ptr,
lib/std/heap/log_to_writer_allocator.zig+3-3
...@@ -34,7 +34,7 @@ pub fn LogToWriterAllocator(comptime Writer: type) type {...@@ -34,7 +34,7 @@ pub fn LogToWriterAllocator(comptime Writer: type) type {
34 log2_ptr_align: u8,34 log2_ptr_align: u8,
35 ra: usize,35 ra: usize,
36 ) ?[*]u8 {36 ) ?[*]u8 {
37 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));37 const self: *Self = @ptrCast(@alignCast(ctx));
38 self.writer.print("alloc : {}", .{len}) catch {};38 self.writer.print("alloc : {}", .{len}) catch {};
39 const result = self.parent_allocator.rawAlloc(len, log2_ptr_align, ra);39 const result = self.parent_allocator.rawAlloc(len, log2_ptr_align, ra);
40 if (result != null) {40 if (result != null) {
...@@ -52,7 +52,7 @@ pub fn LogToWriterAllocator(comptime Writer: type) type {...@@ -52,7 +52,7 @@ pub fn LogToWriterAllocator(comptime Writer: type) type {
52 new_len: usize,52 new_len: usize,
53 ra: usize,53 ra: usize,
54 ) bool {54 ) bool {
55 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));55 const self: *Self = @ptrCast(@alignCast(ctx));
56 if (new_len <= buf.len) {56 if (new_len <= buf.len) {
57 self.writer.print("shrink: {} to {}\n", .{ buf.len, new_len }) catch {};57 self.writer.print("shrink: {} to {}\n", .{ buf.len, new_len }) catch {};
58 } else {58 } else {
...@@ -77,7 +77,7 @@ pub fn LogToWriterAllocator(comptime Writer: type) type {...@@ -77,7 +77,7 @@ pub fn LogToWriterAllocator(comptime Writer: type) type {
77 log2_buf_align: u8,77 log2_buf_align: u8,
78 ra: usize,78 ra: usize,
79 ) void {79 ) void {
80 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));80 const self: *Self = @ptrCast(@alignCast(ctx));
81 self.writer.print("free : {}\n", .{buf.len}) catch {};81 self.writer.print("free : {}\n", .{buf.len}) catch {};
82 self.parent_allocator.rawFree(buf, log2_buf_align, ra);82 self.parent_allocator.rawFree(buf, log2_buf_align, ra);
83 }83 }
lib/std/heap/logging_allocator.zig+3-3
...@@ -59,7 +59,7 @@ pub fn ScopedLoggingAllocator(...@@ -59,7 +59,7 @@ pub fn ScopedLoggingAllocator(
59 log2_ptr_align: u8,59 log2_ptr_align: u8,
60 ra: usize,60 ra: usize,
61 ) ?[*]u8 {61 ) ?[*]u8 {
62 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));62 const self: *Self = @ptrCast(@alignCast(ctx));
63 const result = self.parent_allocator.rawAlloc(len, log2_ptr_align, ra);63 const result = self.parent_allocator.rawAlloc(len, log2_ptr_align, ra);
64 if (result != null) {64 if (result != null) {
65 logHelper(65 logHelper(
...@@ -84,7 +84,7 @@ pub fn ScopedLoggingAllocator(...@@ -84,7 +84,7 @@ pub fn ScopedLoggingAllocator(
84 new_len: usize,84 new_len: usize,
85 ra: usize,85 ra: usize,
86 ) bool {86 ) bool {
87 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));87 const self: *Self = @ptrCast(@alignCast(ctx));
88 if (self.parent_allocator.rawResize(buf, log2_buf_align, new_len, ra)) {88 if (self.parent_allocator.rawResize(buf, log2_buf_align, new_len, ra)) {
89 if (new_len <= buf.len) {89 if (new_len <= buf.len) {
90 logHelper(90 logHelper(
...@@ -118,7 +118,7 @@ pub fn ScopedLoggingAllocator(...@@ -118,7 +118,7 @@ pub fn ScopedLoggingAllocator(
118 log2_buf_align: u8,118 log2_buf_align: u8,
119 ra: usize,119 ra: usize,
120 ) void {120 ) void {
121 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));121 const self: *Self = @ptrCast(@alignCast(ctx));
122 self.parent_allocator.rawFree(buf, log2_buf_align, ra);122 self.parent_allocator.rawFree(buf, log2_buf_align, ra);
123 logHelper(success_log_level, "free - len: {}", .{buf.len});123 logHelper(success_log_level, "free - len: {}", .{buf.len});
124 }124 }
lib/std/heap/memory_pool.zig+4-4
...@@ -70,7 +70,7 @@ pub fn MemoryPoolExtra(comptime Item: type, comptime pool_options: Options) type...@@ -70,7 +70,7 @@ pub fn MemoryPoolExtra(comptime Item: type, comptime pool_options: Options) type
70 var i: usize = 0;70 var i: usize = 0;
71 while (i < initial_size) : (i += 1) {71 while (i < initial_size) : (i += 1) {
72 const raw_mem = try pool.allocNew();72 const raw_mem = try pool.allocNew();
73 const free_node = @ptrCast(NodePtr, raw_mem);73 const free_node = @as(NodePtr, @ptrCast(raw_mem));
74 free_node.* = Node{74 free_node.* = Node{
75 .next = pool.free_list,75 .next = pool.free_list,
76 };76 };
...@@ -106,11 +106,11 @@ pub fn MemoryPoolExtra(comptime Item: type, comptime pool_options: Options) type...@@ -106,11 +106,11 @@ pub fn MemoryPoolExtra(comptime Item: type, comptime pool_options: Options) type
106 pool.free_list = item.next;106 pool.free_list = item.next;
107 break :blk item;107 break :blk item;
108 } else if (pool_options.growable)108 } else if (pool_options.growable)
109 @ptrCast(NodePtr, try pool.allocNew())109 @as(NodePtr, @ptrCast(try pool.allocNew()))
110 else110 else
111 return error.OutOfMemory;111 return error.OutOfMemory;
112112
113 const ptr = @ptrCast(ItemPtr, node);113 const ptr = @as(ItemPtr, @ptrCast(node));
114 ptr.* = undefined;114 ptr.* = undefined;
115 return ptr;115 return ptr;
116 }116 }
...@@ -120,7 +120,7 @@ pub fn MemoryPoolExtra(comptime Item: type, comptime pool_options: Options) type...@@ -120,7 +120,7 @@ pub fn MemoryPoolExtra(comptime Item: type, comptime pool_options: Options) type
120 pub fn destroy(pool: *Pool, ptr: ItemPtr) void {120 pub fn destroy(pool: *Pool, ptr: ItemPtr) void {
121 ptr.* = undefined;121 ptr.* = undefined;
122122
123 const node = @ptrCast(NodePtr, ptr);123 const node = @as(NodePtr, @ptrCast(ptr));
124 node.* = Node{124 node.* = Node{
125 .next = pool.free_list,125 .next = pool.free_list,
126 };126 };
lib/std/http/Client.zig+7-7
...@@ -187,7 +187,7 @@ pub const Connection = struct {...@@ -187,7 +187,7 @@ pub const Connection = struct {
187 const nread = try conn.rawReadAtLeast(conn.read_buf[0..], 1);187 const nread = try conn.rawReadAtLeast(conn.read_buf[0..], 1);
188 if (nread == 0) return error.EndOfStream;188 if (nread == 0) return error.EndOfStream;
189 conn.read_start = 0;189 conn.read_start = 0;
190 conn.read_end = @intCast(u16, nread);190 conn.read_end = @as(u16, @intCast(nread));
191 }191 }
192192
193 pub fn peek(conn: *Connection) []const u8 {193 pub fn peek(conn: *Connection) []const u8 {
...@@ -208,8 +208,8 @@ pub const Connection = struct {...@@ -208,8 +208,8 @@ pub const Connection = struct {
208208
209 if (available_read > available_buffer) { // partially read buffered data209 if (available_read > available_buffer) { // partially read buffered data
210 @memcpy(buffer[out_index..], conn.read_buf[conn.read_start..conn.read_end][0..available_buffer]);210 @memcpy(buffer[out_index..], conn.read_buf[conn.read_start..conn.read_end][0..available_buffer]);
211 out_index += @intCast(u16, available_buffer);211 out_index += @as(u16, @intCast(available_buffer));
212 conn.read_start += @intCast(u16, available_buffer);212 conn.read_start += @as(u16, @intCast(available_buffer));
213213
214 break;214 break;
215 } else if (available_read > 0) { // fully read buffered data215 } else if (available_read > 0) { // fully read buffered data
...@@ -343,7 +343,7 @@ pub const Response = struct {...@@ -343,7 +343,7 @@ pub const Response = struct {
343 else => return error.HttpHeadersInvalid,343 else => return error.HttpHeadersInvalid,
344 };344 };
345 if (first_line[8] != ' ') return error.HttpHeadersInvalid;345 if (first_line[8] != ' ') return error.HttpHeadersInvalid;
346 const status = @enumFromInt(http.Status, parseInt3(first_line[9..12].*));346 const status = @as(http.Status, @enumFromInt(parseInt3(first_line[9..12].*)));
347 const reason = mem.trimLeft(u8, first_line[12..], " ");347 const reason = mem.trimLeft(u8, first_line[12..], " ");
348348
349 res.version = version;349 res.version = version;
...@@ -415,7 +415,7 @@ pub const Response = struct {...@@ -415,7 +415,7 @@ pub const Response = struct {
415 }415 }
416416
417 inline fn int64(array: *const [8]u8) u64 {417 inline fn int64(array: *const [8]u8) u64 {
418 return @bitCast(u64, array.*);418 return @as(u64, @bitCast(array.*));
419 }419 }
420420
421 fn parseInt3(nnn: @Vector(3, u8)) u10 {421 fn parseInt3(nnn: @Vector(3, u8)) u10 {
...@@ -649,7 +649,7 @@ pub const Request = struct {...@@ -649,7 +649,7 @@ pub const Request = struct {
649 try req.connection.?.data.fill();649 try req.connection.?.data.fill();
650650
651 const nchecked = try req.response.parser.checkCompleteHead(req.client.allocator, req.connection.?.data.peek());651 const nchecked = try req.response.parser.checkCompleteHead(req.client.allocator, req.connection.?.data.peek());
652 req.connection.?.data.drop(@intCast(u16, nchecked));652 req.connection.?.data.drop(@as(u16, @intCast(nchecked)));
653653
654 if (req.response.parser.state.isContent()) break;654 if (req.response.parser.state.isContent()) break;
655 }655 }
...@@ -768,7 +768,7 @@ pub const Request = struct {...@@ -768,7 +768,7 @@ pub const Request = struct {
768 try req.connection.?.data.fill();768 try req.connection.?.data.fill();
769769
770 const nchecked = try req.response.parser.checkCompleteHead(req.client.allocator, req.connection.?.data.peek());770 const nchecked = try req.response.parser.checkCompleteHead(req.client.allocator, req.connection.?.data.peek());
771 req.connection.?.data.drop(@intCast(u16, nchecked));771 req.connection.?.data.drop(@as(u16, @intCast(nchecked)));
772 }772 }
773773
774 if (has_trail) {774 if (has_trail) {
lib/std/http/Server.zig+6-6
...@@ -46,7 +46,7 @@ pub const Connection = struct {...@@ -46,7 +46,7 @@ pub const Connection = struct {
46 const nread = try conn.rawReadAtLeast(conn.read_buf[0..], 1);46 const nread = try conn.rawReadAtLeast(conn.read_buf[0..], 1);
47 if (nread == 0) return error.EndOfStream;47 if (nread == 0) return error.EndOfStream;
48 conn.read_start = 0;48 conn.read_start = 0;
49 conn.read_end = @intCast(u16, nread);49 conn.read_end = @as(u16, @intCast(nread));
50 }50 }
5151
52 pub fn peek(conn: *Connection) []const u8 {52 pub fn peek(conn: *Connection) []const u8 {
...@@ -67,8 +67,8 @@ pub const Connection = struct {...@@ -67,8 +67,8 @@ pub const Connection = struct {
6767
68 if (available_read > available_buffer) { // partially read buffered data68 if (available_read > available_buffer) { // partially read buffered data
69 @memcpy(buffer[out_index..], conn.read_buf[conn.read_start..conn.read_end][0..available_buffer]);69 @memcpy(buffer[out_index..], conn.read_buf[conn.read_start..conn.read_end][0..available_buffer]);
70 out_index += @intCast(u16, available_buffer);70 out_index += @as(u16, @intCast(available_buffer));
71 conn.read_start += @intCast(u16, available_buffer);71 conn.read_start += @as(u16, @intCast(available_buffer));
7272
73 break;73 break;
74 } else if (available_read > 0) { // fully read buffered data74 } else if (available_read > 0) { // fully read buffered data
...@@ -268,7 +268,7 @@ pub const Request = struct {...@@ -268,7 +268,7 @@ pub const Request = struct {
268 }268 }
269269
270 inline fn int64(array: *const [8]u8) u64 {270 inline fn int64(array: *const [8]u8) u64 {
271 return @bitCast(u64, array.*);271 return @as(u64, @bitCast(array.*));
272 }272 }
273273
274 method: http.Method,274 method: http.Method,
...@@ -493,7 +493,7 @@ pub const Response = struct {...@@ -493,7 +493,7 @@ pub const Response = struct {
493 try res.connection.fill();493 try res.connection.fill();
494494
495 const nchecked = try res.request.parser.checkCompleteHead(res.allocator, res.connection.peek());495 const nchecked = try res.request.parser.checkCompleteHead(res.allocator, res.connection.peek());
496 res.connection.drop(@intCast(u16, nchecked));496 res.connection.drop(@as(u16, @intCast(nchecked)));
497497
498 if (res.request.parser.state.isContent()) break;498 if (res.request.parser.state.isContent()) break;
499 }499 }
...@@ -560,7 +560,7 @@ pub const Response = struct {...@@ -560,7 +560,7 @@ pub const Response = struct {
560 try res.connection.fill();560 try res.connection.fill();
561561
562 const nchecked = try res.request.parser.checkCompleteHead(res.allocator, res.connection.peek());562 const nchecked = try res.request.parser.checkCompleteHead(res.allocator, res.connection.peek());
563 res.connection.drop(@intCast(u16, nchecked));563 res.connection.drop(@as(u16, @intCast(nchecked)));
564 }564 }
565565
566 if (has_trail) {566 if (has_trail) {
lib/std/http/protocol.zig+24-24
...@@ -83,7 +83,7 @@ pub const HeadersParser = struct {...@@ -83,7 +83,7 @@ pub const HeadersParser = struct {
83 /// first byte of content is located at `bytes[result]`.83 /// first byte of content is located at `bytes[result]`.
84 pub fn findHeadersEnd(r: *HeadersParser, bytes: []const u8) u32 {84 pub fn findHeadersEnd(r: *HeadersParser, bytes: []const u8) u32 {
85 const vector_len: comptime_int = comptime @max(std.simd.suggestVectorSize(u8) orelse 1, 8);85 const vector_len: comptime_int = comptime @max(std.simd.suggestVectorSize(u8) orelse 1, 8);
86 const len = @intCast(u32, bytes.len);86 const len = @as(u32, @intCast(bytes.len));
87 var index: u32 = 0;87 var index: u32 = 0;
8888
89 while (true) {89 while (true) {
...@@ -182,8 +182,8 @@ pub const HeadersParser = struct {...@@ -182,8 +182,8 @@ pub const HeadersParser = struct {
182182
183 const chunk = bytes[index..][0..vector_len];183 const chunk = bytes[index..][0..vector_len];
184 const v: Vector = chunk.*;184 const v: Vector = chunk.*;
185 const matches_r = @bitCast(BitVector, v == @splat(vector_len, @as(u8, '\r')));185 const matches_r = @as(BitVector, @bitCast(v == @splat(vector_len, @as(u8, '\r'))));
186 const matches_n = @bitCast(BitVector, v == @splat(vector_len, @as(u8, '\n')));186 const matches_n = @as(BitVector, @bitCast(v == @splat(vector_len, @as(u8, '\n'))));
187 const matches_or: SizeVector = matches_r | matches_n;187 const matches_or: SizeVector = matches_r | matches_n;
188188
189 const matches = @reduce(.Add, matches_or);189 const matches = @reduce(.Add, matches_or);
...@@ -234,7 +234,7 @@ pub const HeadersParser = struct {...@@ -234,7 +234,7 @@ pub const HeadersParser = struct {
234 },234 },
235 4...vector_len => {235 4...vector_len => {
236 inline for (0..vector_len - 3) |i_usize| {236 inline for (0..vector_len - 3) |i_usize| {
237 const i = @truncate(u32, i_usize);237 const i = @as(u32, @truncate(i_usize));
238238
239 const b32 = int32(chunk[i..][0..4]);239 const b32 = int32(chunk[i..][0..4]);
240 const b16 = intShift(u16, b32);240 const b16 = intShift(u16, b32);
...@@ -405,10 +405,10 @@ pub const HeadersParser = struct {...@@ -405,10 +405,10 @@ pub const HeadersParser = struct {
405 /// If the amount returned is less than `bytes.len`, you may assume that the parser is in the `chunk_data` state405 /// If the amount returned is less than `bytes.len`, you may assume that the parser is in the `chunk_data` state
406 /// and that the first byte of the chunk is at `bytes[result]`.406 /// and that the first byte of the chunk is at `bytes[result]`.
407 pub fn findChunkedLen(r: *HeadersParser, bytes: []const u8) u32 {407 pub fn findChunkedLen(r: *HeadersParser, bytes: []const u8) u32 {
408 const len = @intCast(u32, bytes.len);408 const len = @as(u32, @intCast(bytes.len));
409409
410 for (bytes[0..], 0..) |c, i| {410 for (bytes[0..], 0..) |c, i| {
411 const index = @intCast(u32, i);411 const index = @as(u32, @intCast(i));
412 switch (r.state) {412 switch (r.state) {
413 .chunk_data_suffix => switch (c) {413 .chunk_data_suffix => switch (c) {
414 '\r' => r.state = .chunk_data_suffix_r,414 '\r' => r.state = .chunk_data_suffix_r,
...@@ -529,7 +529,7 @@ pub const HeadersParser = struct {...@@ -529,7 +529,7 @@ pub const HeadersParser = struct {
529 try conn.fill();529 try conn.fill();
530530
531 const nread = @min(conn.peek().len, data_avail);531 const nread = @min(conn.peek().len, data_avail);
532 conn.drop(@intCast(u16, nread));532 conn.drop(@as(u16, @intCast(nread)));
533 r.next_chunk_length -= nread;533 r.next_chunk_length -= nread;
534534
535 if (r.next_chunk_length == 0) r.done = true;535 if (r.next_chunk_length == 0) r.done = true;
...@@ -538,7 +538,7 @@ pub const HeadersParser = struct {...@@ -538,7 +538,7 @@ pub const HeadersParser = struct {
538 } else {538 } else {
539 const out_avail = buffer.len;539 const out_avail = buffer.len;
540540
541 const can_read = @intCast(usize, @min(data_avail, out_avail));541 const can_read = @as(usize, @intCast(@min(data_avail, out_avail)));
542 const nread = try conn.read(buffer[0..can_read]);542 const nread = try conn.read(buffer[0..can_read]);
543 r.next_chunk_length -= nread;543 r.next_chunk_length -= nread;
544544
...@@ -551,7 +551,7 @@ pub const HeadersParser = struct {...@@ -551,7 +551,7 @@ pub const HeadersParser = struct {
551 try conn.fill();551 try conn.fill();
552552
553 const i = r.findChunkedLen(conn.peek());553 const i = r.findChunkedLen(conn.peek());
554 conn.drop(@intCast(u16, i));554 conn.drop(@as(u16, @intCast(i)));
555555
556 switch (r.state) {556 switch (r.state) {
557 .invalid => return error.HttpChunkInvalid,557 .invalid => return error.HttpChunkInvalid,
...@@ -579,10 +579,10 @@ pub const HeadersParser = struct {...@@ -579,10 +579,10 @@ pub const HeadersParser = struct {
579 try conn.fill();579 try conn.fill();
580580
581 const nread = @min(conn.peek().len, data_avail);581 const nread = @min(conn.peek().len, data_avail);
582 conn.drop(@intCast(u16, nread));582 conn.drop(@as(u16, @intCast(nread)));
583 r.next_chunk_length -= nread;583 r.next_chunk_length -= nread;
584 } else if (out_avail > 0) {584 } else if (out_avail > 0) {
585 const can_read = @intCast(usize, @min(data_avail, out_avail));585 const can_read: usize = @intCast(@min(data_avail, out_avail));
586 const nread = try conn.read(buffer[out_index..][0..can_read]);586 const nread = try conn.read(buffer[out_index..][0..can_read]);
587 r.next_chunk_length -= nread;587 r.next_chunk_length -= nread;
588 out_index += nread;588 out_index += nread;
...@@ -601,21 +601,21 @@ pub const HeadersParser = struct {...@@ -601,21 +601,21 @@ pub const HeadersParser = struct {
601};601};
602602
603inline fn int16(array: *const [2]u8) u16 {603inline fn int16(array: *const [2]u8) u16 {
604 return @bitCast(u16, array.*);604 return @as(u16, @bitCast(array.*));
605}605}
606606
607inline fn int24(array: *const [3]u8) u24 {607inline fn int24(array: *const [3]u8) u24 {
608 return @bitCast(u24, array.*);608 return @as(u24, @bitCast(array.*));
609}609}
610610
611inline fn int32(array: *const [4]u8) u32 {611inline fn int32(array: *const [4]u8) u32 {
612 return @bitCast(u32, array.*);612 return @as(u32, @bitCast(array.*));
613}613}
614614
615inline fn intShift(comptime T: type, x: anytype) T {615inline fn intShift(comptime T: type, x: anytype) T {
616 switch (@import("builtin").cpu.arch.endian()) {616 switch (@import("builtin").cpu.arch.endian()) {
617 .Little => return @truncate(T, x >> (@bitSizeOf(@TypeOf(x)) - @bitSizeOf(T))),617 .Little => return @as(T, @truncate(x >> (@bitSizeOf(@TypeOf(x)) - @bitSizeOf(T)))),
618 .Big => return @truncate(T, x),618 .Big => return @as(T, @truncate(x)),
619 }619 }
620}620}
621621
...@@ -634,7 +634,7 @@ const MockBufferedConnection = struct {...@@ -634,7 +634,7 @@ const MockBufferedConnection = struct {
634 const nread = try conn.conn.read(conn.buf[0..]);634 const nread = try conn.conn.read(conn.buf[0..]);
635 if (nread == 0) return error.EndOfStream;635 if (nread == 0) return error.EndOfStream;
636 conn.start = 0;636 conn.start = 0;
637 conn.end = @truncate(u16, nread);637 conn.end = @as(u16, @truncate(nread));
638 }638 }
639639
640 pub fn peek(conn: *MockBufferedConnection) []const u8 {640 pub fn peek(conn: *MockBufferedConnection) []const u8 {
...@@ -652,7 +652,7 @@ const MockBufferedConnection = struct {...@@ -652,7 +652,7 @@ const MockBufferedConnection = struct {
652 const left = buffer.len - out_index;652 const left = buffer.len - out_index;
653653
654 if (available > 0) {654 if (available > 0) {
655 const can_read = @truncate(u16, @min(available, left));655 const can_read = @as(u16, @truncate(@min(available, left)));
656656
657 @memcpy(buffer[out_index..][0..can_read], conn.buf[conn.start..][0..can_read]);657 @memcpy(buffer[out_index..][0..can_read], conn.buf[conn.start..][0..can_read]);
658 out_index += can_read;658 out_index += can_read;
...@@ -705,8 +705,8 @@ test "HeadersParser.findHeadersEnd" {...@@ -705,8 +705,8 @@ test "HeadersParser.findHeadersEnd" {
705705
706 for (0..36) |i| {706 for (0..36) |i| {
707 r = HeadersParser.initDynamic(0);707 r = HeadersParser.initDynamic(0);
708 try std.testing.expectEqual(@intCast(u32, i), r.findHeadersEnd(data[0..i]));708 try std.testing.expectEqual(@as(u32, @intCast(i)), r.findHeadersEnd(data[0..i]));
709 try std.testing.expectEqual(@intCast(u32, 35 - i), r.findHeadersEnd(data[i..]));709 try std.testing.expectEqual(@as(u32, @intCast(35 - i)), r.findHeadersEnd(data[i..]));
710 }710 }
711}711}
712712
...@@ -761,7 +761,7 @@ test "HeadersParser.read length" {...@@ -761,7 +761,7 @@ test "HeadersParser.read length" {
761 try conn.fill();761 try conn.fill();
762762
763 const nchecked = try r.checkCompleteHead(std.testing.allocator, conn.peek());763 const nchecked = try r.checkCompleteHead(std.testing.allocator, conn.peek());
764 conn.drop(@intCast(u16, nchecked));764 conn.drop(@as(u16, @intCast(nchecked)));
765765
766 if (r.state.isContent()) break;766 if (r.state.isContent()) break;
767 }767 }
...@@ -792,7 +792,7 @@ test "HeadersParser.read chunked" {...@@ -792,7 +792,7 @@ test "HeadersParser.read chunked" {
792 try conn.fill();792 try conn.fill();
793793
794 const nchecked = try r.checkCompleteHead(std.testing.allocator, conn.peek());794 const nchecked = try r.checkCompleteHead(std.testing.allocator, conn.peek());
795 conn.drop(@intCast(u16, nchecked));795 conn.drop(@as(u16, @intCast(nchecked)));
796796
797 if (r.state.isContent()) break;797 if (r.state.isContent()) break;
798 }798 }
...@@ -822,7 +822,7 @@ test "HeadersParser.read chunked trailer" {...@@ -822,7 +822,7 @@ test "HeadersParser.read chunked trailer" {
822 try conn.fill();822 try conn.fill();
823823
824 const nchecked = try r.checkCompleteHead(std.testing.allocator, conn.peek());824 const nchecked = try r.checkCompleteHead(std.testing.allocator, conn.peek());
825 conn.drop(@intCast(u16, nchecked));825 conn.drop(@as(u16, @intCast(nchecked)));
826826
827 if (r.state.isContent()) break;827 if (r.state.isContent()) break;
828 }828 }
...@@ -837,7 +837,7 @@ test "HeadersParser.read chunked trailer" {...@@ -837,7 +837,7 @@ test "HeadersParser.read chunked trailer" {
837 try conn.fill();837 try conn.fill();
838838
839 const nchecked = try r.checkCompleteHead(std.testing.allocator, conn.peek());839 const nchecked = try r.checkCompleteHead(std.testing.allocator, conn.peek());
840 conn.drop(@intCast(u16, nchecked));840 conn.drop(@as(u16, @intCast(nchecked)));
841841
842 if (r.state.isContent()) break;842 if (r.state.isContent()) break;
843 }843 }
lib/std/io.zig+1-1
...@@ -275,7 +275,7 @@ pub fn Poller(comptime StreamEnum: type) type {...@@ -275,7 +275,7 @@ pub fn Poller(comptime StreamEnum: type) type {
275 )) {275 )) {
276 .pending => {276 .pending => {
277 self.windows.active.handles_buf[self.windows.active.count] = handle;277 self.windows.active.handles_buf[self.windows.active.count] = handle;
278 self.windows.active.stream_map[self.windows.active.count] = @enumFromInt(StreamEnum, i);278 self.windows.active.stream_map[self.windows.active.count] = @as(StreamEnum, @enumFromInt(i));
279 self.windows.active.count += 1;279 self.windows.active.count += 1;
280 },280 },
281 .closed => {}, // don't add to the wait_objects list281 .closed => {}, // don't add to the wait_objects list
lib/std/io/bit_reader.zig+11-11
...@@ -60,7 +60,7 @@ pub fn BitReader(comptime endian: std.builtin.Endian, comptime ReaderType: type)...@@ -60,7 +60,7 @@ pub fn BitReader(comptime endian: std.builtin.Endian, comptime ReaderType: type)
60 var out_buffer = @as(Buf, 0);60 var out_buffer = @as(Buf, 0);
6161
62 if (self.bit_count > 0) {62 if (self.bit_count > 0) {
63 const n = if (self.bit_count >= bits) @intCast(u3, bits) else self.bit_count;63 const n = if (self.bit_count >= bits) @as(u3, @intCast(bits)) else self.bit_count;
64 const shift = u7_bit_count - n;64 const shift = u7_bit_count - n;
65 switch (endian) {65 switch (endian) {
66 .Big => {66 .Big => {
...@@ -88,45 +88,45 @@ pub fn BitReader(comptime endian: std.builtin.Endian, comptime ReaderType: type)...@@ -88,45 +88,45 @@ pub fn BitReader(comptime endian: std.builtin.Endian, comptime ReaderType: type)
88 while (out_bits.* < bits) {88 while (out_bits.* < bits) {
89 const n = bits - out_bits.*;89 const n = bits - out_bits.*;
90 const next_byte = self.forward_reader.readByte() catch |err| switch (err) {90 const next_byte = self.forward_reader.readByte() catch |err| switch (err) {
91 error.EndOfStream => return @intCast(U, out_buffer),91 error.EndOfStream => return @as(U, @intCast(out_buffer)),
92 else => |e| return e,92 else => |e| return e,
93 };93 };
9494
95 switch (endian) {95 switch (endian) {
96 .Big => {96 .Big => {
97 if (n >= u8_bit_count) {97 if (n >= u8_bit_count) {
98 out_buffer <<= @intCast(u3, u8_bit_count - 1);98 out_buffer <<= @as(u3, @intCast(u8_bit_count - 1));
99 out_buffer <<= 1;99 out_buffer <<= 1;
100 out_buffer |= @as(Buf, next_byte);100 out_buffer |= @as(Buf, next_byte);
101 out_bits.* += u8_bit_count;101 out_bits.* += u8_bit_count;
102 continue;102 continue;
103 }103 }
104104
105 const shift = @intCast(u3, u8_bit_count - n);105 const shift = @as(u3, @intCast(u8_bit_count - n));
106 out_buffer <<= @intCast(BufShift, n);106 out_buffer <<= @as(BufShift, @intCast(n));
107 out_buffer |= @as(Buf, next_byte >> shift);107 out_buffer |= @as(Buf, next_byte >> shift);
108 out_bits.* += n;108 out_bits.* += n;
109 self.bit_buffer = @truncate(u7, next_byte << @intCast(u3, n - 1));109 self.bit_buffer = @as(u7, @truncate(next_byte << @as(u3, @intCast(n - 1))));
110 self.bit_count = shift;110 self.bit_count = shift;
111 },111 },
112 .Little => {112 .Little => {
113 if (n >= u8_bit_count) {113 if (n >= u8_bit_count) {
114 out_buffer |= @as(Buf, next_byte) << @intCast(BufShift, out_bits.*);114 out_buffer |= @as(Buf, next_byte) << @as(BufShift, @intCast(out_bits.*));
115 out_bits.* += u8_bit_count;115 out_bits.* += u8_bit_count;
116 continue;116 continue;
117 }117 }
118118
119 const shift = @intCast(u3, u8_bit_count - n);119 const shift = @as(u3, @intCast(u8_bit_count - n));
120 const value = (next_byte << shift) >> shift;120 const value = (next_byte << shift) >> shift;
121 out_buffer |= @as(Buf, value) << @intCast(BufShift, out_bits.*);121 out_buffer |= @as(Buf, value) << @as(BufShift, @intCast(out_bits.*));
122 out_bits.* += n;122 out_bits.* += n;
123 self.bit_buffer = @truncate(u7, next_byte >> @intCast(u3, n));123 self.bit_buffer = @as(u7, @truncate(next_byte >> @as(u3, @intCast(n))));
124 self.bit_count = shift;124 self.bit_count = shift;
125 },125 },
126 }126 }
127 }127 }
128128
129 return @intCast(U, out_buffer);129 return @as(U, @intCast(out_buffer));
130 }130 }
131131
132 pub fn alignToByte(self: *Self) void {132 pub fn alignToByte(self: *Self) void {
lib/std/io/bit_writer.zig+14-14
...@@ -47,27 +47,27 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type)...@@ -47,27 +47,27 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type)
47 const Buf = std.meta.Int(.unsigned, buf_bit_count);47 const Buf = std.meta.Int(.unsigned, buf_bit_count);
48 const BufShift = math.Log2Int(Buf);48 const BufShift = math.Log2Int(Buf);
4949
50 const buf_value = @intCast(Buf, value);50 const buf_value = @as(Buf, @intCast(value));
5151
52 const high_byte_shift = @intCast(BufShift, buf_bit_count - u8_bit_count);52 const high_byte_shift = @as(BufShift, @intCast(buf_bit_count - u8_bit_count));
53 var in_buffer = switch (endian) {53 var in_buffer = switch (endian) {
54 .Big => buf_value << @intCast(BufShift, buf_bit_count - bits),54 .Big => buf_value << @as(BufShift, @intCast(buf_bit_count - bits)),
55 .Little => buf_value,55 .Little => buf_value,
56 };56 };
57 var in_bits = bits;57 var in_bits = bits;
5858
59 if (self.bit_count > 0) {59 if (self.bit_count > 0) {
60 const bits_remaining = u8_bit_count - self.bit_count;60 const bits_remaining = u8_bit_count - self.bit_count;
61 const n = @intCast(u3, if (bits_remaining > bits) bits else bits_remaining);61 const n = @as(u3, @intCast(if (bits_remaining > bits) bits else bits_remaining));
62 switch (endian) {62 switch (endian) {
63 .Big => {63 .Big => {
64 const shift = @intCast(BufShift, high_byte_shift + self.bit_count);64 const shift = @as(BufShift, @intCast(high_byte_shift + self.bit_count));
65 const v = @intCast(u8, in_buffer >> shift);65 const v = @as(u8, @intCast(in_buffer >> shift));
66 self.bit_buffer |= v;66 self.bit_buffer |= v;
67 in_buffer <<= n;67 in_buffer <<= n;
68 },68 },
69 .Little => {69 .Little => {
70 const v = @truncate(u8, in_buffer) << @intCast(u3, self.bit_count);70 const v = @as(u8, @truncate(in_buffer)) << @as(u3, @intCast(self.bit_count));
71 self.bit_buffer |= v;71 self.bit_buffer |= v;
72 in_buffer >>= n;72 in_buffer >>= n;
73 },73 },
...@@ -87,15 +87,15 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type)...@@ -87,15 +87,15 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type)
87 while (in_bits >= u8_bit_count) {87 while (in_bits >= u8_bit_count) {
88 switch (endian) {88 switch (endian) {
89 .Big => {89 .Big => {
90 const v = @intCast(u8, in_buffer >> high_byte_shift);90 const v = @as(u8, @intCast(in_buffer >> high_byte_shift));
91 try self.forward_writer.writeByte(v);91 try self.forward_writer.writeByte(v);
92 in_buffer <<= @intCast(u3, u8_bit_count - 1);92 in_buffer <<= @as(u3, @intCast(u8_bit_count - 1));
93 in_buffer <<= 1;93 in_buffer <<= 1;
94 },94 },
95 .Little => {95 .Little => {
96 const v = @truncate(u8, in_buffer);96 const v = @as(u8, @truncate(in_buffer));
97 try self.forward_writer.writeByte(v);97 try self.forward_writer.writeByte(v);
98 in_buffer >>= @intCast(u3, u8_bit_count - 1);98 in_buffer >>= @as(u3, @intCast(u8_bit_count - 1));
99 in_buffer >>= 1;99 in_buffer >>= 1;
100 },100 },
101 }101 }
...@@ -103,10 +103,10 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type)...@@ -103,10 +103,10 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type)
103 }103 }
104104
105 if (in_bits > 0) {105 if (in_bits > 0) {
106 self.bit_count = @intCast(u4, in_bits);106 self.bit_count = @as(u4, @intCast(in_bits));
107 self.bit_buffer = switch (endian) {107 self.bit_buffer = switch (endian) {
108 .Big => @truncate(u8, in_buffer >> high_byte_shift),108 .Big => @as(u8, @truncate(in_buffer >> high_byte_shift)),
109 .Little => @truncate(u8, in_buffer),109 .Little => @as(u8, @truncate(in_buffer)),
110 };110 };
111 }111 }
112 }112 }
lib/std/io/c_writer.zig+1-1
...@@ -13,7 +13,7 @@ pub fn cWriter(c_file: *std.c.FILE) CWriter {...@@ -13,7 +13,7 @@ pub fn cWriter(c_file: *std.c.FILE) CWriter {
13fn cWriterWrite(c_file: *std.c.FILE, bytes: []const u8) std.fs.File.WriteError!usize {13fn cWriterWrite(c_file: *std.c.FILE, bytes: []const u8) std.fs.File.WriteError!usize {
14 const amt_written = std.c.fwrite(bytes.ptr, 1, bytes.len, c_file);14 const amt_written = std.c.fwrite(bytes.ptr, 1, bytes.len, c_file);
15 if (amt_written >= 0) return amt_written;15 if (amt_written >= 0) return amt_written;
16 switch (@enumFromInt(os.E, std.c._errno().*)) {16 switch (@as(os.E, @enumFromInt(std.c._errno().*))) {
17 .SUCCESS => unreachable,17 .SUCCESS => unreachable,
18 .INVAL => unreachable,18 .INVAL => unreachable,
19 .FAULT => unreachable,19 .FAULT => unreachable,
lib/std/io/reader.zig+1-1
...@@ -246,7 +246,7 @@ pub fn Reader(...@@ -246,7 +246,7 @@ pub fn Reader(
246246
247 /// Same as `readByte` except the returned byte is signed.247 /// Same as `readByte` except the returned byte is signed.
248 pub fn readByteSigned(self: Self) (Error || error{EndOfStream})!i8 {248 pub fn readByteSigned(self: Self) (Error || error{EndOfStream})!i8 {
249 return @bitCast(i8, try self.readByte());249 return @as(i8, @bitCast(try self.readByte()));
250 }250 }
251251
252 /// Reads exactly `num_bytes` bytes and returns as an array.252 /// Reads exactly `num_bytes` bytes and returns as an array.
lib/std/json/scanner.zig+4-4
...@@ -193,7 +193,7 @@ pub const TokenType = enum {...@@ -193,7 +193,7 @@ pub const TokenType = enum {
193/// to get meaningful information from this.193/// to get meaningful information from this.
194pub const Diagnostics = struct {194pub const Diagnostics = struct {
195 line_number: u64 = 1,195 line_number: u64 = 1,
196 line_start_cursor: usize = @bitCast(usize, @as(isize, -1)), // Start just "before" the input buffer to get a 1-based column for line 1.196 line_start_cursor: usize = @as(usize, @bitCast(@as(isize, -1))), // Start just "before" the input buffer to get a 1-based column for line 1.
197 total_bytes_before_current_input: u64 = 0,197 total_bytes_before_current_input: u64 = 0,
198 cursor_pointer: *const usize = undefined,198 cursor_pointer: *const usize = undefined,
199199
...@@ -1719,7 +1719,7 @@ const BitStack = struct {...@@ -1719,7 +1719,7 @@ const BitStack = struct {
17191719
1720 pub fn push(self: *@This(), b: u1) Allocator.Error!void {1720 pub fn push(self: *@This(), b: u1) Allocator.Error!void {
1721 const byte_index = self.bit_len >> 3;1721 const byte_index = self.bit_len >> 3;
1722 const bit_index = @intCast(u3, self.bit_len & 7);1722 const bit_index = @as(u3, @intCast(self.bit_len & 7));
17231723
1724 if (self.bytes.items.len <= byte_index) {1724 if (self.bytes.items.len <= byte_index) {
1725 try self.bytes.append(0);1725 try self.bytes.append(0);
...@@ -1733,8 +1733,8 @@ const BitStack = struct {...@@ -1733,8 +1733,8 @@ const BitStack = struct {
17331733
1734 pub fn peek(self: *const @This()) u1 {1734 pub fn peek(self: *const @This()) u1 {
1735 const byte_index = (self.bit_len - 1) >> 3;1735 const byte_index = (self.bit_len - 1) >> 3;
1736 const bit_index = @intCast(u3, (self.bit_len - 1) & 7);1736 const bit_index = @as(u3, @intCast((self.bit_len - 1) & 7));
1737 return @intCast(u1, (self.bytes.items[byte_index] >> bit_index) & 1);1737 return @as(u1, @intCast((self.bytes.items[byte_index] >> bit_index) & 1));
1738 }1738 }
17391739
1740 pub fn pop(self: *@This()) u1 {1740 pub fn pop(self: *@This()) u1 {
lib/std/json/static.zig+10-10
...@@ -442,7 +442,7 @@ fn internalParse(...@@ -442,7 +442,7 @@ fn internalParse(
442 }442 }
443443
444 if (ptrInfo.sentinel) |some| {444 if (ptrInfo.sentinel) |some| {
445 const sentinel_value = @ptrCast(*align(1) const ptrInfo.child, some).*;445 const sentinel_value = @as(*align(1) const ptrInfo.child, @ptrCast(some)).*;
446 return try arraylist.toOwnedSliceSentinel(sentinel_value);446 return try arraylist.toOwnedSliceSentinel(sentinel_value);
447 }447 }
448448
...@@ -456,7 +456,7 @@ fn internalParse(...@@ -456,7 +456,7 @@ fn internalParse(
456 // Use our own array list so we can append the sentinel.456 // Use our own array list so we can append the sentinel.
457 var value_list = ArrayList(u8).init(allocator);457 var value_list = ArrayList(u8).init(allocator);
458 _ = try source.allocNextIntoArrayList(&value_list, .alloc_always);458 _ = try source.allocNextIntoArrayList(&value_list, .alloc_always);
459 return try value_list.toOwnedSliceSentinel(@ptrCast(*const u8, sentinel_ptr).*);459 return try value_list.toOwnedSliceSentinel(@as(*const u8, @ptrCast(sentinel_ptr)).*);
460 }460 }
461 if (ptrInfo.is_const) {461 if (ptrInfo.is_const) {
462 switch (try source.nextAllocMax(allocator, .alloc_if_needed, options.max_value_len.?)) {462 switch (try source.nextAllocMax(allocator, .alloc_if_needed, options.max_value_len.?)) {
...@@ -518,8 +518,8 @@ fn internalParseFromValue(...@@ -518,8 +518,8 @@ fn internalParseFromValue(
518 },518 },
519 .Float, .ComptimeFloat => {519 .Float, .ComptimeFloat => {
520 switch (source) {520 switch (source) {
521 .float => |f| return @floatCast(T, f),521 .float => |f| return @as(T, @floatCast(f)),
522 .integer => |i| return @floatFromInt(T, i),522 .integer => |i| return @as(T, @floatFromInt(i)),
523 .number_string, .string => |s| return std.fmt.parseFloat(T, s),523 .number_string, .string => |s| return std.fmt.parseFloat(T, s),
524 else => return error.UnexpectedToken,524 else => return error.UnexpectedToken,
525 }525 }
...@@ -530,12 +530,12 @@ fn internalParseFromValue(...@@ -530,12 +530,12 @@ fn internalParseFromValue(
530 if (@round(f) != f) return error.InvalidNumber;530 if (@round(f) != f) return error.InvalidNumber;
531 if (f > std.math.maxInt(T)) return error.Overflow;531 if (f > std.math.maxInt(T)) return error.Overflow;
532 if (f < std.math.minInt(T)) return error.Overflow;532 if (f < std.math.minInt(T)) return error.Overflow;
533 return @intFromFloat(T, f);533 return @as(T, @intFromFloat(f));
534 },534 },
535 .integer => |i| {535 .integer => |i| {
536 if (i > std.math.maxInt(T)) return error.Overflow;536 if (i > std.math.maxInt(T)) return error.Overflow;
537 if (i < std.math.minInt(T)) return error.Overflow;537 if (i < std.math.minInt(T)) return error.Overflow;
538 return @intCast(T, i);538 return @as(T, @intCast(i));
539 },539 },
540 .number_string, .string => |s| {540 .number_string, .string => |s| {
541 return sliceToInt(T, s);541 return sliceToInt(T, s);
...@@ -686,7 +686,7 @@ fn internalParseFromValue(...@@ -686,7 +686,7 @@ fn internalParseFromValue(
686 switch (source) {686 switch (source) {
687 .array => |array| {687 .array => |array| {
688 const r = if (ptrInfo.sentinel) |sentinel_ptr|688 const r = if (ptrInfo.sentinel) |sentinel_ptr|
689 try allocator.allocSentinel(ptrInfo.child, array.items.len, @ptrCast(*align(1) const ptrInfo.child, sentinel_ptr).*)689 try allocator.allocSentinel(ptrInfo.child, array.items.len, @as(*align(1) const ptrInfo.child, @ptrCast(sentinel_ptr)).*)
690 else690 else
691 try allocator.alloc(ptrInfo.child, array.items.len);691 try allocator.alloc(ptrInfo.child, array.items.len);
692692
...@@ -701,7 +701,7 @@ fn internalParseFromValue(...@@ -701,7 +701,7 @@ fn internalParseFromValue(
701 // Dynamic length string.701 // Dynamic length string.
702702
703 const r = if (ptrInfo.sentinel) |sentinel_ptr|703 const r = if (ptrInfo.sentinel) |sentinel_ptr|
704 try allocator.allocSentinel(ptrInfo.child, s.len, @ptrCast(*align(1) const ptrInfo.child, sentinel_ptr).*)704 try allocator.allocSentinel(ptrInfo.child, s.len, @as(*align(1) const ptrInfo.child, @ptrCast(sentinel_ptr)).*)
705 else705 else
706 try allocator.alloc(ptrInfo.child, s.len);706 try allocator.alloc(ptrInfo.child, s.len);
707 @memcpy(r[0..], s);707 @memcpy(r[0..], s);
...@@ -743,7 +743,7 @@ fn sliceToInt(comptime T: type, slice: []const u8) !T {...@@ -743,7 +743,7 @@ fn sliceToInt(comptime T: type, slice: []const u8) !T {
743 const float = try std.fmt.parseFloat(f128, slice);743 const float = try std.fmt.parseFloat(f128, slice);
744 if (@round(float) != float) return error.InvalidNumber;744 if (@round(float) != float) return error.InvalidNumber;
745 if (float > std.math.maxInt(T) or float < std.math.minInt(T)) return error.Overflow;745 if (float > std.math.maxInt(T) or float < std.math.minInt(T)) return error.Overflow;
746 return @intCast(T, @intFromFloat(i128, float));746 return @as(T, @intCast(@as(i128, @intFromFloat(float))));
747}747}
748748
749fn sliceToEnum(comptime T: type, slice: []const u8) !T {749fn sliceToEnum(comptime T: type, slice: []const u8) !T {
...@@ -759,7 +759,7 @@ fn fillDefaultStructValues(comptime T: type, r: *T, fields_seen: *[@typeInfo(T)....@@ -759,7 +759,7 @@ fn fillDefaultStructValues(comptime T: type, r: *T, fields_seen: *[@typeInfo(T).
759 inline for (@typeInfo(T).Struct.fields, 0..) |field, i| {759 inline for (@typeInfo(T).Struct.fields, 0..) |field, i| {
760 if (!fields_seen[i]) {760 if (!fields_seen[i]) {
761 if (field.default_value) |default_ptr| {761 if (field.default_value) |default_ptr| {
762 const default = @ptrCast(*align(1) const field.type, default_ptr).*;762 const default = @as(*align(1) const field.type, @ptrCast(default_ptr)).*;
763 @field(r, field.name) = default;763 @field(r, field.name) = default;
764 } else {764 } else {
765 return error.MissingField;765 return error.MissingField;
lib/std/json/stringify.zig+2-2
...@@ -78,8 +78,8 @@ fn outputUnicodeEscape(...@@ -78,8 +78,8 @@ fn outputUnicodeEscape(
78 assert(codepoint <= 0x10FFFF);78 assert(codepoint <= 0x10FFFF);
79 // To escape an extended character that is not in the Basic Multilingual Plane,79 // To escape an extended character that is not in the Basic Multilingual Plane,
80 // the character is represented as a 12-character sequence, encoding the UTF-16 surrogate pair.80 // the character is represented as a 12-character sequence, encoding the UTF-16 surrogate pair.
81 const high = @intCast(u16, (codepoint - 0x10000) >> 10) + 0xD800;81 const high = @as(u16, @intCast((codepoint - 0x10000) >> 10)) + 0xD800;
82 const low = @intCast(u16, codepoint & 0x3FF) + 0xDC00;82 const low = @as(u16, @intCast(codepoint & 0x3FF)) + 0xDC00;
83 try out_stream.writeAll("\\u");83 try out_stream.writeAll("\\u");
84 try std.fmt.formatIntValue(high, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream);84 try std.fmt.formatIntValue(high, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream);
85 try out_stream.writeAll("\\u");85 try out_stream.writeAll("\\u");
lib/std/json/write_stream.zig+3-3
...@@ -176,8 +176,8 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {...@@ -176,8 +176,8 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
176 .ComptimeInt => {176 .ComptimeInt => {
177 return self.emitNumber(@as(std.math.IntFittingRange(value, value), value));177 return self.emitNumber(@as(std.math.IntFittingRange(value, value), value));
178 },178 },
179 .Float, .ComptimeFloat => if (@floatCast(f64, value) == value) {179 .Float, .ComptimeFloat => if (@as(f64, @floatCast(value)) == value) {
180 try self.stream.print("{}", .{@floatCast(f64, value)});180 try self.stream.print("{}", .{@as(f64, @floatCast(value))});
181 self.popState();181 self.popState();
182 return;182 return;
183 },183 },
...@@ -294,7 +294,7 @@ test "json write stream" {...@@ -294,7 +294,7 @@ test "json write stream" {
294294
295fn getJsonObject(allocator: std.mem.Allocator) !Value {295fn getJsonObject(allocator: std.mem.Allocator) !Value {
296 var value = Value{ .object = ObjectMap.init(allocator) };296 var value = Value{ .object = ObjectMap.init(allocator) };
297 try value.object.put("one", Value{ .integer = @intCast(i64, 1) });297 try value.object.put("one", Value{ .integer = @as(i64, @intCast(1)) });
298 try value.object.put("two", Value{ .float = 2.0 });298 try value.object.put("two", Value{ .float = 2.0 });
299 return value;299 return value;
300}300}
lib/std/leb128.zig+21-21
...@@ -30,17 +30,17 @@ pub fn readULEB128(comptime T: type, reader: anytype) !T {...@@ -30,17 +30,17 @@ pub fn readULEB128(comptime T: type, reader: anytype) !T {
30 if (value > std.math.maxInt(T)) return error.Overflow;30 if (value > std.math.maxInt(T)) return error.Overflow;
31 }31 }
3232
33 return @truncate(T, value);33 return @as(T, @truncate(value));
34}34}
3535
36/// Write a single unsigned integer as unsigned LEB128 to the given writer.36/// Write a single unsigned integer as unsigned LEB128 to the given writer.
37pub fn writeULEB128(writer: anytype, uint_value: anytype) !void {37pub fn writeULEB128(writer: anytype, uint_value: anytype) !void {
38 const T = @TypeOf(uint_value);38 const T = @TypeOf(uint_value);
39 const U = if (@typeInfo(T).Int.bits < 8) u8 else T;39 const U = if (@typeInfo(T).Int.bits < 8) u8 else T;
40 var value = @intCast(U, uint_value);40 var value = @as(U, @intCast(uint_value));
4141
42 while (true) {42 while (true) {
43 const byte = @truncate(u8, value & 0x7f);43 const byte = @as(u8, @truncate(value & 0x7f));
44 value >>= 7;44 value >>= 7;
45 if (value == 0) {45 if (value == 0) {
46 try writer.writeByte(byte);46 try writer.writeByte(byte);
...@@ -71,18 +71,18 @@ pub fn readILEB128(comptime T: type, reader: anytype) !T {...@@ -71,18 +71,18 @@ pub fn readILEB128(comptime T: type, reader: anytype) !T {
71 if (ov[1] != 0) {71 if (ov[1] != 0) {
72 // Overflow is ok so long as the sign bit is set and this is the last byte72 // Overflow is ok so long as the sign bit is set and this is the last byte
73 if (byte & 0x80 != 0) return error.Overflow;73 if (byte & 0x80 != 0) return error.Overflow;
74 if (@bitCast(S, ov[0]) >= 0) return error.Overflow;74 if (@as(S, @bitCast(ov[0])) >= 0) return error.Overflow;
7575
76 // and all the overflowed bits are 176 // and all the overflowed bits are 1
77 const remaining_shift = @intCast(u3, @typeInfo(U).Int.bits - @as(u16, shift));77 const remaining_shift = @as(u3, @intCast(@typeInfo(U).Int.bits - @as(u16, shift)));
78 const remaining_bits = @bitCast(i8, byte | 0x80) >> remaining_shift;78 const remaining_bits = @as(i8, @bitCast(byte | 0x80)) >> remaining_shift;
79 if (remaining_bits != -1) return error.Overflow;79 if (remaining_bits != -1) return error.Overflow;
80 } else {80 } else {
81 // If we don't overflow and this is the last byte and the number being decoded81 // If we don't overflow and this is the last byte and the number being decoded
82 // is negative, check that the remaining bits are 182 // is negative, check that the remaining bits are 1
83 if ((byte & 0x80 == 0) and (@bitCast(S, ov[0]) < 0)) {83 if ((byte & 0x80 == 0) and (@as(S, @bitCast(ov[0])) < 0)) {
84 const remaining_shift = @intCast(u3, @typeInfo(U).Int.bits - @as(u16, shift));84 const remaining_shift = @as(u3, @intCast(@typeInfo(U).Int.bits - @as(u16, shift)));
85 const remaining_bits = @bitCast(i8, byte | 0x80) >> remaining_shift;85 const remaining_bits = @as(i8, @bitCast(byte | 0x80)) >> remaining_shift;
86 if (remaining_bits != -1) return error.Overflow;86 if (remaining_bits != -1) return error.Overflow;
87 }87 }
88 }88 }
...@@ -92,7 +92,7 @@ pub fn readILEB128(comptime T: type, reader: anytype) !T {...@@ -92,7 +92,7 @@ pub fn readILEB128(comptime T: type, reader: anytype) !T {
92 const needs_sign_ext = group + 1 < max_group;92 const needs_sign_ext = group + 1 < max_group;
93 if (byte & 0x40 != 0 and needs_sign_ext) {93 if (byte & 0x40 != 0 and needs_sign_ext) {
94 const ones = @as(S, -1);94 const ones = @as(S, -1);
95 value |= @bitCast(U, ones) << (shift + 7);95 value |= @as(U, @bitCast(ones)) << (shift + 7);
96 }96 }
97 break;97 break;
98 }98 }
...@@ -100,13 +100,13 @@ pub fn readILEB128(comptime T: type, reader: anytype) !T {...@@ -100,13 +100,13 @@ pub fn readILEB128(comptime T: type, reader: anytype) !T {
100 return error.Overflow;100 return error.Overflow;
101 }101 }
102102
103 const result = @bitCast(S, value);103 const result = @as(S, @bitCast(value));
104 // Only applies if we extended to i8104 // Only applies if we extended to i8
105 if (S != T) {105 if (S != T) {
106 if (result > std.math.maxInt(T) or result < std.math.minInt(T)) return error.Overflow;106 if (result > std.math.maxInt(T) or result < std.math.minInt(T)) return error.Overflow;
107 }107 }
108108
109 return @truncate(T, result);109 return @as(T, @truncate(result));
110}110}
111111
112/// Write a single signed integer as signed LEB128 to the given writer.112/// Write a single signed integer as signed LEB128 to the given writer.
...@@ -115,11 +115,11 @@ pub fn writeILEB128(writer: anytype, int_value: anytype) !void {...@@ -115,11 +115,11 @@ pub fn writeILEB128(writer: anytype, int_value: anytype) !void {
115 const S = if (@typeInfo(T).Int.bits < 8) i8 else T;115 const S = if (@typeInfo(T).Int.bits < 8) i8 else T;
116 const U = std.meta.Int(.unsigned, @typeInfo(S).Int.bits);116 const U = std.meta.Int(.unsigned, @typeInfo(S).Int.bits);
117117
118 var value = @intCast(S, int_value);118 var value = @as(S, @intCast(int_value));
119119
120 while (true) {120 while (true) {
121 const uvalue = @bitCast(U, value);121 const uvalue = @as(U, @bitCast(value));
122 const byte = @truncate(u8, uvalue);122 const byte = @as(u8, @truncate(uvalue));
123 value >>= 6;123 value >>= 6;
124 if (value == -1 or value == 0) {124 if (value == -1 or value == 0) {
125 try writer.writeByte(byte & 0x7F);125 try writer.writeByte(byte & 0x7F);
...@@ -141,15 +141,15 @@ pub fn writeILEB128(writer: anytype, int_value: anytype) !void {...@@ -141,15 +141,15 @@ pub fn writeILEB128(writer: anytype, int_value: anytype) !void {
141pub fn writeUnsignedFixed(comptime l: usize, ptr: *[l]u8, int: std.meta.Int(.unsigned, l * 7)) void {141pub fn writeUnsignedFixed(comptime l: usize, ptr: *[l]u8, int: std.meta.Int(.unsigned, l * 7)) void {
142 const T = @TypeOf(int);142 const T = @TypeOf(int);
143 const U = if (@typeInfo(T).Int.bits < 8) u8 else T;143 const U = if (@typeInfo(T).Int.bits < 8) u8 else T;
144 var value = @intCast(U, int);144 var value = @as(U, @intCast(int));
145145
146 comptime var i = 0;146 comptime var i = 0;
147 inline while (i < (l - 1)) : (i += 1) {147 inline while (i < (l - 1)) : (i += 1) {
148 const byte = @truncate(u8, value) | 0b1000_0000;148 const byte = @as(u8, @truncate(value)) | 0b1000_0000;
149 value >>= 7;149 value >>= 7;
150 ptr[i] = byte;150 ptr[i] = byte;
151 }151 }
152 ptr[i] = @truncate(u8, value);152 ptr[i] = @as(u8, @truncate(value));
153}153}
154154
155test "writeUnsignedFixed" {155test "writeUnsignedFixed" {
...@@ -245,7 +245,7 @@ test "deserialize signed LEB128" {...@@ -245,7 +245,7 @@ test "deserialize signed LEB128" {
245 try testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1);245 try testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1);
246 try testing.expect((try test_read_ileb128(i32, "\xff\xff\xff\xff\x7f")) == -1);246 try testing.expect((try test_read_ileb128(i32, "\xff\xff\xff\xff\x7f")) == -1);
247 try testing.expect((try test_read_ileb128(i32, "\x80\x80\x80\x80\x78")) == -0x80000000);247 try testing.expect((try test_read_ileb128(i32, "\x80\x80\x80\x80\x78")) == -0x80000000);
248 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == @bitCast(i64, @intCast(u64, 0x8000000000000000)));248 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == @as(i64, @bitCast(@as(u64, @intCast(0x8000000000000000)))));
249 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000);249 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000);
250 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000);250 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000);
251251
...@@ -356,7 +356,7 @@ test "serialize unsigned LEB128" {...@@ -356,7 +356,7 @@ test "serialize unsigned LEB128" {
356 const max = std.math.maxInt(T);356 const max = std.math.maxInt(T);
357 var i = @as(std.meta.Int(.unsigned, @typeInfo(T).Int.bits + 1), min);357 var i = @as(std.meta.Int(.unsigned, @typeInfo(T).Int.bits + 1), min);
358358
359 while (i <= max) : (i += 1) try test_write_leb128(@intCast(T, i));359 while (i <= max) : (i += 1) try test_write_leb128(@as(T, @intCast(i)));
360 }360 }
361}361}
362362
...@@ -374,6 +374,6 @@ test "serialize signed LEB128" {...@@ -374,6 +374,6 @@ test "serialize signed LEB128" {
374 const max = std.math.maxInt(T);374 const max = std.math.maxInt(T);
375 var i = @as(std.meta.Int(.signed, @typeInfo(T).Int.bits + 1), min);375 var i = @as(std.meta.Int(.signed, @typeInfo(T).Int.bits + 1), min);
376376
377 while (i <= max) : (i += 1) try test_write_leb128(@intCast(T, i));377 while (i <= max) : (i += 1) try test_write_leb128(@as(T, @intCast(i)));
378 }378 }
379}379}
lib/std/macho.zig+7-7
...@@ -787,7 +787,7 @@ pub const section_64 = extern struct {...@@ -787,7 +787,7 @@ pub const section_64 = extern struct {
787 }787 }
788788
789 pub fn @"type"(sect: section_64) u8 {789 pub fn @"type"(sect: section_64) u8 {
790 return @truncate(u8, sect.flags & 0xff);790 return @as(u8, @truncate(sect.flags & 0xff));
791 }791 }
792792
793 pub fn attrs(sect: section_64) u32 {793 pub fn attrs(sect: section_64) u32 {
...@@ -1870,7 +1870,7 @@ pub const LoadCommandIterator = struct {...@@ -1870,7 +1870,7 @@ pub const LoadCommandIterator = struct {
18701870
1871 pub fn cast(lc: LoadCommand, comptime Cmd: type) ?Cmd {1871 pub fn cast(lc: LoadCommand, comptime Cmd: type) ?Cmd {
1872 if (lc.data.len < @sizeOf(Cmd)) return null;1872 if (lc.data.len < @sizeOf(Cmd)) return null;
1873 return @ptrCast(*const Cmd, @alignCast(@alignOf(Cmd), &lc.data[0])).*;1873 return @as(*const Cmd, @ptrCast(@alignCast(&lc.data[0]))).*;
1874 }1874 }
18751875
1876 /// Asserts LoadCommand is of type segment_command_64.1876 /// Asserts LoadCommand is of type segment_command_64.
...@@ -1878,9 +1878,9 @@ pub const LoadCommandIterator = struct {...@@ -1878,9 +1878,9 @@ pub const LoadCommandIterator = struct {
1878 const segment_lc = lc.cast(segment_command_64).?;1878 const segment_lc = lc.cast(segment_command_64).?;
1879 if (segment_lc.nsects == 0) return &[0]section_64{};1879 if (segment_lc.nsects == 0) return &[0]section_64{};
1880 const data = lc.data[@sizeOf(segment_command_64)..];1880 const data = lc.data[@sizeOf(segment_command_64)..];
1881 const sections = @ptrCast(1881 const sections = @as(
1882 [*]const section_64,1882 [*]const section_64,
1883 @alignCast(@alignOf(section_64), &data[0]),1883 @ptrCast(@alignCast(&data[0])),
1884 )[0..segment_lc.nsects];1884 )[0..segment_lc.nsects];
1885 return sections;1885 return sections;
1886 }1886 }
...@@ -1903,16 +1903,16 @@ pub const LoadCommandIterator = struct {...@@ -1903,16 +1903,16 @@ pub const LoadCommandIterator = struct {
1903 pub fn next(it: *LoadCommandIterator) ?LoadCommand {1903 pub fn next(it: *LoadCommandIterator) ?LoadCommand {
1904 if (it.index >= it.ncmds) return null;1904 if (it.index >= it.ncmds) return null;
19051905
1906 const hdr = @ptrCast(1906 const hdr = @as(
1907 *const load_command,1907 *const load_command,
1908 @alignCast(@alignOf(load_command), &it.buffer[0]),1908 @ptrCast(@alignCast(&it.buffer[0])),
1909 ).*;1909 ).*;
1910 const cmd = LoadCommand{1910 const cmd = LoadCommand{
1911 .hdr = hdr,1911 .hdr = hdr,
1912 .data = it.buffer[0..hdr.cmdsize],1912 .data = it.buffer[0..hdr.cmdsize],
1913 };1913 };
19141914
1915 it.buffer = @alignCast(@alignOf(u64), it.buffer[hdr.cmdsize..]);1915 it.buffer = @alignCast(it.buffer[hdr.cmdsize..]);
1916 it.index += 1;1916 it.index += 1;
19171917
1918 return cmd;1918 return cmd;
lib/std/math.zig+46-40
...@@ -85,31 +85,31 @@ pub const inf_f128 = @compileError("Deprecated: use `inf(f128)` instead");...@@ -85,31 +85,31 @@ pub const inf_f128 = @compileError("Deprecated: use `inf(f128)` instead");
85pub const epsilon = @compileError("Deprecated: use `floatEps` instead");85pub const epsilon = @compileError("Deprecated: use `floatEps` instead");
8686
87pub const nan_u16 = @as(u16, 0x7C01);87pub const nan_u16 = @as(u16, 0x7C01);
88pub const nan_f16 = @bitCast(f16, nan_u16);88pub const nan_f16 = @as(f16, @bitCast(nan_u16));
8989
90pub const qnan_u16 = @as(u16, 0x7E00);90pub const qnan_u16 = @as(u16, 0x7E00);
91pub const qnan_f16 = @bitCast(f16, qnan_u16);91pub const qnan_f16 = @as(f16, @bitCast(qnan_u16));
9292
93pub const nan_u32 = @as(u32, 0x7F800001);93pub const nan_u32 = @as(u32, 0x7F800001);
94pub const nan_f32 = @bitCast(f32, nan_u32);94pub const nan_f32 = @as(f32, @bitCast(nan_u32));
9595
96pub const qnan_u32 = @as(u32, 0x7FC00000);96pub const qnan_u32 = @as(u32, 0x7FC00000);
97pub const qnan_f32 = @bitCast(f32, qnan_u32);97pub const qnan_f32 = @as(f32, @bitCast(qnan_u32));
9898
99pub const nan_u64 = @as(u64, 0x7FF << 52) | 1;99pub const nan_u64 = @as(u64, 0x7FF << 52) | 1;
100pub const nan_f64 = @bitCast(f64, nan_u64);100pub const nan_f64 = @as(f64, @bitCast(nan_u64));
101101
102pub const qnan_u64 = @as(u64, 0x7ff8000000000000);102pub const qnan_u64 = @as(u64, 0x7ff8000000000000);
103pub const qnan_f64 = @bitCast(f64, qnan_u64);103pub const qnan_f64 = @as(f64, @bitCast(qnan_u64));
104104
105pub const nan_f80 = make_f80(F80{ .fraction = 0xA000000000000000, .exp = 0x7fff });105pub const nan_f80 = make_f80(F80{ .fraction = 0xA000000000000000, .exp = 0x7fff });
106pub const qnan_f80 = make_f80(F80{ .fraction = 0xC000000000000000, .exp = 0x7fff });106pub const qnan_f80 = make_f80(F80{ .fraction = 0xC000000000000000, .exp = 0x7fff });
107107
108pub const nan_u128 = @as(u128, 0x7fff0000000000000000000000000001);108pub const nan_u128 = @as(u128, 0x7fff0000000000000000000000000001);
109pub const nan_f128 = @bitCast(f128, nan_u128);109pub const nan_f128 = @as(f128, @bitCast(nan_u128));
110110
111pub const qnan_u128 = @as(u128, 0x7fff8000000000000000000000000000);111pub const qnan_u128 = @as(u128, 0x7fff8000000000000000000000000000);
112pub const qnan_f128 = @bitCast(f128, qnan_u128);112pub const qnan_f128 = @as(f128, @bitCast(qnan_u128));
113113
114pub const nan = @import("math/nan.zig").nan;114pub const nan = @import("math/nan.zig").nan;
115pub const snan = @import("math/nan.zig").snan;115pub const snan = @import("math/nan.zig").snan;
...@@ -508,10 +508,10 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {...@@ -508,10 +508,10 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
508 const C = @typeInfo(T).Vector.child;508 const C = @typeInfo(T).Vector.child;
509 const len = @typeInfo(T).Vector.len;509 const len = @typeInfo(T).Vector.len;
510 if (abs_shift_amt >= @typeInfo(C).Int.bits) return @splat(len, @as(C, 0));510 if (abs_shift_amt >= @typeInfo(C).Int.bits) return @splat(len, @as(C, 0));
511 break :blk @splat(len, @intCast(Log2Int(C), abs_shift_amt));511 break :blk @splat(len, @as(Log2Int(C), @intCast(abs_shift_amt)));
512 } else {512 } else {
513 if (abs_shift_amt >= @typeInfo(T).Int.bits) return 0;513 if (abs_shift_amt >= @typeInfo(T).Int.bits) return 0;
514 break :blk @intCast(Log2Int(T), abs_shift_amt);514 break :blk @as(Log2Int(T), @intCast(abs_shift_amt));
515 }515 }
516 };516 };
517517
...@@ -552,10 +552,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {...@@ -552,10 +552,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
552 const C = @typeInfo(T).Vector.child;552 const C = @typeInfo(T).Vector.child;
553 const len = @typeInfo(T).Vector.len;553 const len = @typeInfo(T).Vector.len;
554 if (abs_shift_amt >= @typeInfo(C).Int.bits) return @splat(len, @as(C, 0));554 if (abs_shift_amt >= @typeInfo(C).Int.bits) return @splat(len, @as(C, 0));
555 break :blk @splat(len, @intCast(Log2Int(C), abs_shift_amt));555 break :blk @splat(len, @as(Log2Int(C), @intCast(abs_shift_amt)));
556 } else {556 } else {
557 if (abs_shift_amt >= @typeInfo(T).Int.bits) return 0;557 if (abs_shift_amt >= @typeInfo(T).Int.bits) return 0;
558 break :blk @intCast(Log2Int(T), abs_shift_amt);558 break :blk @as(Log2Int(T), @intCast(abs_shift_amt));
559 }559 }
560 };560 };
561561
...@@ -596,7 +596,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {...@@ -596,7 +596,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
596 if (@typeInfo(C).Int.signedness == .signed) {596 if (@typeInfo(C).Int.signedness == .signed) {
597 @compileError("cannot rotate signed integers");597 @compileError("cannot rotate signed integers");
598 }598 }
599 const ar = @intCast(Log2Int(C), @mod(r, @typeInfo(C).Int.bits));599 const ar = @as(Log2Int(C), @intCast(@mod(r, @typeInfo(C).Int.bits)));
600 return (x >> @splat(@typeInfo(T).Vector.len, ar)) | (x << @splat(@typeInfo(T).Vector.len, 1 + ~ar));600 return (x >> @splat(@typeInfo(T).Vector.len, ar)) | (x << @splat(@typeInfo(T).Vector.len, 1 + ~ar));
601 } else if (@typeInfo(T).Int.signedness == .signed) {601 } else if (@typeInfo(T).Int.signedness == .signed) {
602 @compileError("cannot rotate signed integer");602 @compileError("cannot rotate signed integer");
...@@ -604,7 +604,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {...@@ -604,7 +604,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
604 if (T == u0) return 0;604 if (T == u0) return 0;
605605
606 if (isPowerOfTwo(@typeInfo(T).Int.bits)) {606 if (isPowerOfTwo(@typeInfo(T).Int.bits)) {
607 const ar = @intCast(Log2Int(T), @mod(r, @typeInfo(T).Int.bits));607 const ar = @as(Log2Int(T), @intCast(@mod(r, @typeInfo(T).Int.bits)));
608 return x >> ar | x << (1 +% ~ar);608 return x >> ar | x << (1 +% ~ar);
609 } else {609 } else {
610 const ar = @mod(r, @typeInfo(T).Int.bits);610 const ar = @mod(r, @typeInfo(T).Int.bits);
...@@ -640,7 +640,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {...@@ -640,7 +640,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
640 if (@typeInfo(C).Int.signedness == .signed) {640 if (@typeInfo(C).Int.signedness == .signed) {
641 @compileError("cannot rotate signed integers");641 @compileError("cannot rotate signed integers");
642 }642 }
643 const ar = @intCast(Log2Int(C), @mod(r, @typeInfo(C).Int.bits));643 const ar = @as(Log2Int(C), @intCast(@mod(r, @typeInfo(C).Int.bits)));
644 return (x << @splat(@typeInfo(T).Vector.len, ar)) | (x >> @splat(@typeInfo(T).Vector.len, 1 +% ~ar));644 return (x << @splat(@typeInfo(T).Vector.len, ar)) | (x >> @splat(@typeInfo(T).Vector.len, 1 +% ~ar));
645 } else if (@typeInfo(T).Int.signedness == .signed) {645 } else if (@typeInfo(T).Int.signedness == .signed) {
646 @compileError("cannot rotate signed integer");646 @compileError("cannot rotate signed integer");
...@@ -648,7 +648,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {...@@ -648,7 +648,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
648 if (T == u0) return 0;648 if (T == u0) return 0;
649649
650 if (isPowerOfTwo(@typeInfo(T).Int.bits)) {650 if (isPowerOfTwo(@typeInfo(T).Int.bits)) {
651 const ar = @intCast(Log2Int(T), @mod(r, @typeInfo(T).Int.bits));651 const ar = @as(Log2Int(T), @intCast(@mod(r, @typeInfo(T).Int.bits)));
652 return x << ar | x >> 1 +% ~ar;652 return x << ar | x >> 1 +% ~ar;
653 } else {653 } else {
654 const ar = @mod(r, @typeInfo(T).Int.bits);654 const ar = @mod(r, @typeInfo(T).Int.bits);
...@@ -1029,9 +1029,9 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {...@@ -1029,9 +1029,9 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
1029 if (int_info.signedness == .unsigned) return x;1029 if (int_info.signedness == .unsigned) return x;
1030 const Uint = std.meta.Int(.unsigned, int_info.bits);1030 const Uint = std.meta.Int(.unsigned, int_info.bits);
1031 if (x < 0) {1031 if (x < 0) {
1032 return ~@bitCast(Uint, x +% -1);1032 return ~@as(Uint, @bitCast(x +% -1));
1033 } else {1033 } else {
1034 return @intCast(Uint, x);1034 return @as(Uint, @intCast(x));
1035 }1035 }
1036 },1036 },
1037 else => unreachable,1037 else => unreachable,
...@@ -1056,7 +1056,7 @@ pub fn negateCast(x: anytype) !std.meta.Int(.signed, @bitSizeOf(@TypeOf(x))) {...@@ -1056,7 +1056,7 @@ pub fn negateCast(x: anytype) !std.meta.Int(.signed, @bitSizeOf(@TypeOf(x))) {
10561056
1057 if (x == -minInt(int)) return minInt(int);1057 if (x == -minInt(int)) return minInt(int);
10581058
1059 return -@intCast(int, x);1059 return -@as(int, @intCast(x));
1060}1060}
10611061
1062test "negateCast" {1062test "negateCast" {
...@@ -1080,7 +1080,7 @@ pub fn cast(comptime T: type, x: anytype) ?T {...@@ -1080,7 +1080,7 @@ pub fn cast(comptime T: type, x: anytype) ?T {
1080 } else if ((is_comptime or minInt(@TypeOf(x)) < minInt(T)) and x < minInt(T)) {1080 } else if ((is_comptime or minInt(@TypeOf(x)) < minInt(T)) and x < minInt(T)) {
1081 return null;1081 return null;
1082 } else {1082 } else {
1083 return @intCast(T, x);1083 return @as(T, @intCast(x));
1084 }1084 }
1085}1085}
10861086
...@@ -1102,13 +1102,19 @@ test "cast" {...@@ -1102,13 +1102,19 @@ test "cast" {
11021102
1103pub const AlignCastError = error{UnalignedMemory};1103pub const AlignCastError = error{UnalignedMemory};
11041104
1105fn AlignCastResult(comptime alignment: u29, comptime Ptr: type) type {
1106 var ptr_info = @typeInfo(Ptr);
1107 ptr_info.Pointer.alignment = alignment;
1108 return @Type(ptr_info);
1109}
1110
1105/// Align cast a pointer but return an error if it's the wrong alignment1111/// Align cast a pointer but return an error if it's the wrong alignment
1106pub fn alignCast(comptime alignment: u29, ptr: anytype) AlignCastError!@TypeOf(@alignCast(alignment, ptr)) {1112pub fn alignCast(comptime alignment: u29, ptr: anytype) AlignCastError!AlignCastResult(alignment, @TypeOf(ptr)) {
1107 const addr = @intFromPtr(ptr);1113 const addr = @intFromPtr(ptr);
1108 if (addr % alignment != 0) {1114 if (addr % alignment != 0) {
1109 return error.UnalignedMemory;1115 return error.UnalignedMemory;
1110 }1116 }
1111 return @alignCast(alignment, ptr);1117 return @alignCast(ptr);
1112}1118}
11131119
1114/// Asserts `int > 0`.1120/// Asserts `int > 0`.
...@@ -1172,7 +1178,7 @@ pub inline fn floor(value: anytype) @TypeOf(value) {...@@ -1172,7 +1178,7 @@ pub inline fn floor(value: anytype) @TypeOf(value) {
1172pub fn floorPowerOfTwo(comptime T: type, value: T) T {1178pub fn floorPowerOfTwo(comptime T: type, value: T) T {
1173 const uT = std.meta.Int(.unsigned, @typeInfo(T).Int.bits);1179 const uT = std.meta.Int(.unsigned, @typeInfo(T).Int.bits);
1174 if (value <= 0) return 0;1180 if (value <= 0) return 0;
1175 return @as(T, 1) << log2_int(uT, @intCast(uT, value));1181 return @as(T, 1) << log2_int(uT, @as(uT, @intCast(value)));
1176}1182}
11771183
1178test "floorPowerOfTwo" {1184test "floorPowerOfTwo" {
...@@ -1211,7 +1217,7 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(@typeInfo(...@@ -1211,7 +1217,7 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(@typeInfo(
1211 assert(value != 0);1217 assert(value != 0);
1212 const PromotedType = std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits + 1);1218 const PromotedType = std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits + 1);
1213 const ShiftType = std.math.Log2Int(PromotedType);1219 const ShiftType = std.math.Log2Int(PromotedType);
1214 return @as(PromotedType, 1) << @intCast(ShiftType, @typeInfo(T).Int.bits - @clz(value - 1));1220 return @as(PromotedType, 1) << @as(ShiftType, @intCast(@typeInfo(T).Int.bits - @clz(value - 1)));
1215}1221}
12161222
1217/// Returns the next power of two (if the value is not already a power of two).1223/// Returns the next power of two (if the value is not already a power of two).
...@@ -1227,7 +1233,7 @@ pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {...@@ -1227,7 +1233,7 @@ pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
1227 if (overflowBit & x != 0) {1233 if (overflowBit & x != 0) {
1228 return error.Overflow;1234 return error.Overflow;
1229 }1235 }
1230 return @intCast(T, x);1236 return @as(T, @intCast(x));
1231}1237}
12321238
1233/// Returns the next power of two (if the value is not already a power1239/// Returns the next power of two (if the value is not already a power
...@@ -1277,7 +1283,7 @@ pub fn log2_int(comptime T: type, x: T) Log2Int(T) {...@@ -1277,7 +1283,7 @@ pub fn log2_int(comptime T: type, x: T) Log2Int(T) {
1277 if (@typeInfo(T) != .Int or @typeInfo(T).Int.signedness != .unsigned)1283 if (@typeInfo(T) != .Int or @typeInfo(T).Int.signedness != .unsigned)
1278 @compileError("log2_int requires an unsigned integer, found " ++ @typeName(T));1284 @compileError("log2_int requires an unsigned integer, found " ++ @typeName(T));
1279 assert(x != 0);1285 assert(x != 0);
1280 return @intCast(Log2Int(T), @typeInfo(T).Int.bits - 1 - @clz(x));1286 return @as(Log2Int(T), @intCast(@typeInfo(T).Int.bits - 1 - @clz(x)));
1281}1287}
12821288
1283/// Return the log base 2 of integer value x, rounding up to the1289/// Return the log base 2 of integer value x, rounding up to the
...@@ -1311,8 +1317,8 @@ pub fn lossyCast(comptime T: type, value: anytype) T {...@@ -1311,8 +1317,8 @@ pub fn lossyCast(comptime T: type, value: anytype) T {
1311 switch (@typeInfo(T)) {1317 switch (@typeInfo(T)) {
1312 .Float => {1318 .Float => {
1313 switch (@typeInfo(@TypeOf(value))) {1319 switch (@typeInfo(@TypeOf(value))) {
1314 .Int => return @floatFromInt(T, value),1320 .Int => return @as(T, @floatFromInt(value)),
1315 .Float => return @floatCast(T, value),1321 .Float => return @as(T, @floatCast(value)),
1316 .ComptimeInt => return @as(T, value),1322 .ComptimeInt => return @as(T, value),
1317 .ComptimeFloat => return @as(T, value),1323 .ComptimeFloat => return @as(T, value),
1318 else => @compileError("bad type"),1324 else => @compileError("bad type"),
...@@ -1326,7 +1332,7 @@ pub fn lossyCast(comptime T: type, value: anytype) T {...@@ -1326,7 +1332,7 @@ pub fn lossyCast(comptime T: type, value: anytype) T {
1326 } else if (value <= minInt(T)) {1332 } else if (value <= minInt(T)) {
1327 return @as(T, minInt(T));1333 return @as(T, minInt(T));
1328 } else {1334 } else {
1329 return @intCast(T, value);1335 return @as(T, @intCast(value));
1330 }1336 }
1331 },1337 },
1332 .Float, .ComptimeFloat => {1338 .Float, .ComptimeFloat => {
...@@ -1335,7 +1341,7 @@ pub fn lossyCast(comptime T: type, value: anytype) T {...@@ -1335,7 +1341,7 @@ pub fn lossyCast(comptime T: type, value: anytype) T {
1335 } else if (value <= minInt(T)) {1341 } else if (value <= minInt(T)) {
1336 return @as(T, minInt(T));1342 return @as(T, minInt(T));
1337 } else {1343 } else {
1338 return @intFromFloat(T, value);1344 return @as(T, @intFromFloat(value));
1339 }1345 }
1340 },1346 },
1341 else => @compileError("bad type"),1347 else => @compileError("bad type"),
...@@ -1594,7 +1600,7 @@ test "compare between signed and unsigned" {...@@ -1594,7 +1600,7 @@ test "compare between signed and unsigned" {
1594 try testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1)));1600 try testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1)));
1595 try testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1)));1601 try testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1)));
1596 try testing.expect(compare(@as(u8, 1), .lt, @as(u8, 2)));1602 try testing.expect(compare(@as(u8, 1), .lt, @as(u8, 2)));
1597 try testing.expect(@bitCast(u8, @as(i8, -1)) == @as(u8, 255));1603 try testing.expect(@as(u8, @bitCast(@as(i8, -1))) == @as(u8, 255));
1598 try testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1)));1604 try testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1)));
1599 try testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));1605 try testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));
1600}1606}
...@@ -1624,7 +1630,7 @@ test "order.compare" {...@@ -1624,7 +1630,7 @@ test "order.compare" {
16241630
1625test "compare.reverse" {1631test "compare.reverse" {
1626 inline for (@typeInfo(CompareOperator).Enum.fields) |op_field| {1632 inline for (@typeInfo(CompareOperator).Enum.fields) |op_field| {
1627 const op = @enumFromInt(CompareOperator, op_field.value);1633 const op = @as(CompareOperator, @enumFromInt(op_field.value));
1628 try testing.expect(compare(2, op, 3) == compare(3, op.reverse(), 2));1634 try testing.expect(compare(2, op, 3) == compare(3, op.reverse(), 2));
1629 try testing.expect(compare(3, op, 3) == compare(3, op.reverse(), 3));1635 try testing.expect(compare(3, op, 3) == compare(3, op.reverse(), 3));
1630 try testing.expect(compare(4, op, 3) == compare(3, op.reverse(), 4));1636 try testing.expect(compare(4, op, 3) == compare(3, op.reverse(), 4));
...@@ -1646,10 +1652,10 @@ pub inline fn boolMask(comptime MaskInt: type, value: bool) MaskInt {...@@ -1646,10 +1652,10 @@ pub inline fn boolMask(comptime MaskInt: type, value: bool) MaskInt {
1646 if (MaskInt == u1) return @intFromBool(value);1652 if (MaskInt == u1) return @intFromBool(value);
1647 if (MaskInt == i1) {1653 if (MaskInt == i1) {
1648 // The @as here is a workaround for #79501654 // The @as here is a workaround for #7950
1649 return @bitCast(i1, @as(u1, @intFromBool(value)));1655 return @as(i1, @bitCast(@as(u1, @intFromBool(value))));
1650 }1656 }
16511657
1652 return -%@intCast(MaskInt, @intFromBool(value));1658 return -%@as(MaskInt, @intCast(@intFromBool(value)));
1653}1659}
16541660
1655test "boolMask" {1661test "boolMask" {
...@@ -1680,7 +1686,7 @@ test "boolMask" {...@@ -1680,7 +1686,7 @@ test "boolMask" {
16801686
1681/// Return the mod of `num` with the smallest integer type1687/// Return the mod of `num` with the smallest integer type
1682pub fn comptimeMod(num: anytype, comptime denom: comptime_int) IntFittingRange(0, denom - 1) {1688pub fn comptimeMod(num: anytype, comptime denom: comptime_int) IntFittingRange(0, denom - 1) {
1683 return @intCast(IntFittingRange(0, denom - 1), @mod(num, denom));1689 return @as(IntFittingRange(0, denom - 1), @intCast(@mod(num, denom)));
1684}1690}
16851691
1686pub const F80 = struct {1692pub const F80 = struct {
...@@ -1690,14 +1696,14 @@ pub const F80 = struct {...@@ -1690,14 +1696,14 @@ pub const F80 = struct {
16901696
1691pub fn make_f80(repr: F80) f80 {1697pub fn make_f80(repr: F80) f80 {
1692 const int = (@as(u80, repr.exp) << 64) | repr.fraction;1698 const int = (@as(u80, repr.exp) << 64) | repr.fraction;
1693 return @bitCast(f80, int);1699 return @as(f80, @bitCast(int));
1694}1700}
16951701
1696pub fn break_f80(x: f80) F80 {1702pub fn break_f80(x: f80) F80 {
1697 const int = @bitCast(u80, x);1703 const int = @as(u80, @bitCast(x));
1698 return .{1704 return .{
1699 .fraction = @truncate(u64, int),1705 .fraction = @as(u64, @truncate(int)),
1700 .exp = @truncate(u16, int >> 64),1706 .exp = @as(u16, @truncate(int >> 64)),
1701 };1707 };
1702}1708}
17031709
...@@ -1709,7 +1715,7 @@ pub inline fn sign(i: anytype) @TypeOf(i) {...@@ -1709,7 +1715,7 @@ pub inline fn sign(i: anytype) @TypeOf(i) {
1709 const T = @TypeOf(i);1715 const T = @TypeOf(i);
1710 return switch (@typeInfo(T)) {1716 return switch (@typeInfo(T)) {
1711 .Int, .ComptimeInt => @as(T, @intFromBool(i > 0)) - @as(T, @intFromBool(i < 0)),1717 .Int, .ComptimeInt => @as(T, @intFromBool(i > 0)) - @as(T, @intFromBool(i < 0)),
1712 .Float, .ComptimeFloat => @floatFromInt(T, @intFromBool(i > 0)) - @floatFromInt(T, @intFromBool(i < 0)),1718 .Float, .ComptimeFloat => @as(T, @floatFromInt(@intFromBool(i > 0))) - @as(T, @floatFromInt(@intFromBool(i < 0))),
1713 .Vector => |vinfo| blk: {1719 .Vector => |vinfo| blk: {
1714 switch (@typeInfo(vinfo.child)) {1720 switch (@typeInfo(vinfo.child)) {
1715 .Int, .Float => {1721 .Int, .Float => {
lib/std/math/acos.zig+8-8
...@@ -36,7 +36,7 @@ fn acos32(x: f32) f32 {...@@ -36,7 +36,7 @@ fn acos32(x: f32) f32 {
36 const pio2_hi = 1.5707962513e+00;36 const pio2_hi = 1.5707962513e+00;
37 const pio2_lo = 7.5497894159e-08;37 const pio2_lo = 7.5497894159e-08;
3838
39 const hx: u32 = @bitCast(u32, x);39 const hx: u32 = @as(u32, @bitCast(x));
40 const ix: u32 = hx & 0x7FFFFFFF;40 const ix: u32 = hx & 0x7FFFFFFF;
4141
42 // |x| >= 1 or nan42 // |x| >= 1 or nan
...@@ -72,8 +72,8 @@ fn acos32(x: f32) f32 {...@@ -72,8 +72,8 @@ fn acos32(x: f32) f32 {
72 // x > 0.572 // x > 0.5
73 const z = (1.0 - x) * 0.5;73 const z = (1.0 - x) * 0.5;
74 const s = @sqrt(z);74 const s = @sqrt(z);
75 const jx = @bitCast(u32, s);75 const jx = @as(u32, @bitCast(s));
76 const df = @bitCast(f32, jx & 0xFFFFF000);76 const df = @as(f32, @bitCast(jx & 0xFFFFF000));
77 const c = (z - df * df) / (s + df);77 const c = (z - df * df) / (s + df);
78 const w = r32(z) * s + c;78 const w = r32(z) * s + c;
79 return 2 * (df + w);79 return 2 * (df + w);
...@@ -100,13 +100,13 @@ fn acos64(x: f64) f64 {...@@ -100,13 +100,13 @@ fn acos64(x: f64) f64 {
100 const pio2_hi: f64 = 1.57079632679489655800e+00;100 const pio2_hi: f64 = 1.57079632679489655800e+00;
101 const pio2_lo: f64 = 6.12323399573676603587e-17;101 const pio2_lo: f64 = 6.12323399573676603587e-17;
102102
103 const ux = @bitCast(u64, x);103 const ux = @as(u64, @bitCast(x));
104 const hx = @intCast(u32, ux >> 32);104 const hx = @as(u32, @intCast(ux >> 32));
105 const ix = hx & 0x7FFFFFFF;105 const ix = hx & 0x7FFFFFFF;
106106
107 // |x| >= 1 or nan107 // |x| >= 1 or nan
108 if (ix >= 0x3FF00000) {108 if (ix >= 0x3FF00000) {
109 const lx = @intCast(u32, ux & 0xFFFFFFFF);109 const lx = @as(u32, @intCast(ux & 0xFFFFFFFF));
110110
111 // acos(1) = 0, acos(-1) = pi111 // acos(1) = 0, acos(-1) = pi
112 if ((ix - 0x3FF00000) | lx == 0) {112 if ((ix - 0x3FF00000) | lx == 0) {
...@@ -141,8 +141,8 @@ fn acos64(x: f64) f64 {...@@ -141,8 +141,8 @@ fn acos64(x: f64) f64 {
141 // x > 0.5141 // x > 0.5
142 const z = (1.0 - x) * 0.5;142 const z = (1.0 - x) * 0.5;
143 const s = @sqrt(z);143 const s = @sqrt(z);
144 const jx = @bitCast(u64, s);144 const jx = @as(u64, @bitCast(s));
145 const df = @bitCast(f64, jx & 0xFFFFFFFF00000000);145 const df = @as(f64, @bitCast(jx & 0xFFFFFFFF00000000));
146 const c = (z - df * df) / (s + df);146 const c = (z - df * df) / (s + df);
147 const w = r64(z) * s + c;147 const w = r64(z) * s + c;
148 return 2 * (df + w);148 return 2 * (df + w);
lib/std/math/acosh.zig+2-2
...@@ -24,7 +24,7 @@ pub fn acosh(x: anytype) @TypeOf(x) {...@@ -24,7 +24,7 @@ pub fn acosh(x: anytype) @TypeOf(x) {
2424
25// acosh(x) = log(x + sqrt(x * x - 1))25// acosh(x) = log(x + sqrt(x * x - 1))
26fn acosh32(x: f32) f32 {26fn acosh32(x: f32) f32 {
27 const u = @bitCast(u32, x);27 const u = @as(u32, @bitCast(x));
28 const i = u & 0x7FFFFFFF;28 const i = u & 0x7FFFFFFF;
2929
30 // |x| < 2, invalid if x < 1 or nan30 // |x| < 2, invalid if x < 1 or nan
...@@ -42,7 +42,7 @@ fn acosh32(x: f32) f32 {...@@ -42,7 +42,7 @@ fn acosh32(x: f32) f32 {
42}42}
4343
44fn acosh64(x: f64) f64 {44fn acosh64(x: f64) f64 {
45 const u = @bitCast(u64, x);45 const u = @as(u64, @bitCast(x));
46 const e = (u >> 52) & 0x7FF;46 const e = (u >> 52) & 0x7FF;
4747
48 // |x| < 2, invalid if x < 1 or nan48 // |x| < 2, invalid if x < 1 or nan
lib/std/math/asin.zig+6-6
...@@ -36,7 +36,7 @@ fn r32(z: f32) f32 {...@@ -36,7 +36,7 @@ fn r32(z: f32) f32 {
36fn asin32(x: f32) f32 {36fn asin32(x: f32) f32 {
37 const pio2 = 1.570796326794896558e+00;37 const pio2 = 1.570796326794896558e+00;
3838
39 const hx: u32 = @bitCast(u32, x);39 const hx: u32 = @as(u32, @bitCast(x));
40 const ix: u32 = hx & 0x7FFFFFFF;40 const ix: u32 = hx & 0x7FFFFFFF;
4141
42 // |x| >= 142 // |x| >= 1
...@@ -92,13 +92,13 @@ fn asin64(x: f64) f64 {...@@ -92,13 +92,13 @@ fn asin64(x: f64) f64 {
92 const pio2_hi: f64 = 1.57079632679489655800e+00;92 const pio2_hi: f64 = 1.57079632679489655800e+00;
93 const pio2_lo: f64 = 6.12323399573676603587e-17;93 const pio2_lo: f64 = 6.12323399573676603587e-17;
9494
95 const ux = @bitCast(u64, x);95 const ux = @as(u64, @bitCast(x));
96 const hx = @intCast(u32, ux >> 32);96 const hx = @as(u32, @intCast(ux >> 32));
97 const ix = hx & 0x7FFFFFFF;97 const ix = hx & 0x7FFFFFFF;
9898
99 // |x| >= 1 or nan99 // |x| >= 1 or nan
100 if (ix >= 0x3FF00000) {100 if (ix >= 0x3FF00000) {
101 const lx = @intCast(u32, ux & 0xFFFFFFFF);101 const lx = @as(u32, @intCast(ux & 0xFFFFFFFF));
102102
103 // asin(1) = +-pi/2 with inexact103 // asin(1) = +-pi/2 with inexact
104 if ((ix - 0x3FF00000) | lx == 0) {104 if ((ix - 0x3FF00000) | lx == 0) {
...@@ -128,8 +128,8 @@ fn asin64(x: f64) f64 {...@@ -128,8 +128,8 @@ fn asin64(x: f64) f64 {
128 if (ix >= 0x3FEF3333) {128 if (ix >= 0x3FEF3333) {
129 fx = pio2_hi - 2 * (s + s * r);129 fx = pio2_hi - 2 * (s + s * r);
130 } else {130 } else {
131 const jx = @bitCast(u64, s);131 const jx = @as(u64, @bitCast(s));
132 const df = @bitCast(f64, jx & 0xFFFFFFFF00000000);132 const df = @as(f64, @bitCast(jx & 0xFFFFFFFF00000000));
133 const c = (z - df * df) / (s + df);133 const c = (z - df * df) / (s + df);
134 fx = 0.5 * pio2_hi - (2 * s * r - (pio2_lo - 2 * c) - (0.5 * pio2_hi - 2 * df));134 fx = 0.5 * pio2_hi - (2 * s * r - (pio2_lo - 2 * c) - (0.5 * pio2_hi - 2 * df));
135 }135 }
lib/std/math/asinh.zig+4-4
...@@ -26,11 +26,11 @@ pub fn asinh(x: anytype) @TypeOf(x) {...@@ -26,11 +26,11 @@ pub fn asinh(x: anytype) @TypeOf(x) {
2626
27// asinh(x) = sign(x) * log(|x| + sqrt(x * x + 1)) ~= x - x^3/6 + o(x^5)27// asinh(x) = sign(x) * log(|x| + sqrt(x * x + 1)) ~= x - x^3/6 + o(x^5)
28fn asinh32(x: f32) f32 {28fn asinh32(x: f32) f32 {
29 const u = @bitCast(u32, x);29 const u = @as(u32, @bitCast(x));
30 const i = u & 0x7FFFFFFF;30 const i = u & 0x7FFFFFFF;
31 const s = i >> 31;31 const s = i >> 31;
3232
33 var rx = @bitCast(f32, i); // |x|33 var rx = @as(f32, @bitCast(i)); // |x|
3434
35 // TODO: Shouldn't need this explicit check.35 // TODO: Shouldn't need this explicit check.
36 if (math.isNegativeInf(x)) {36 if (math.isNegativeInf(x)) {
...@@ -58,11 +58,11 @@ fn asinh32(x: f32) f32 {...@@ -58,11 +58,11 @@ fn asinh32(x: f32) f32 {
58}58}
5959
60fn asinh64(x: f64) f64 {60fn asinh64(x: f64) f64 {
61 const u = @bitCast(u64, x);61 const u = @as(u64, @bitCast(x));
62 const e = (u >> 52) & 0x7FF;62 const e = (u >> 52) & 0x7FF;
63 const s = e >> 63;63 const s = e >> 63;
6464
65 var rx = @bitCast(f64, u & (maxInt(u64) >> 1)); // |x|65 var rx = @as(f64, @bitCast(u & (maxInt(u64) >> 1))); // |x|
6666
67 if (math.isNegativeInf(x)) {67 if (math.isNegativeInf(x)) {
68 return x;68 return x;
lib/std/math/atan.zig+5-5
...@@ -46,7 +46,7 @@ fn atan32(x_: f32) f32 {...@@ -46,7 +46,7 @@ fn atan32(x_: f32) f32 {
46 };46 };
4747
48 var x = x_;48 var x = x_;
49 var ix: u32 = @bitCast(u32, x);49 var ix: u32 = @as(u32, @bitCast(x));
50 const sign = ix >> 31;50 const sign = ix >> 31;
51 ix &= 0x7FFFFFFF;51 ix &= 0x7FFFFFFF;
5252
...@@ -143,8 +143,8 @@ fn atan64(x_: f64) f64 {...@@ -143,8 +143,8 @@ fn atan64(x_: f64) f64 {
143 };143 };
144144
145 var x = x_;145 var x = x_;
146 var ux = @bitCast(u64, x);146 var ux = @as(u64, @bitCast(x));
147 var ix = @intCast(u32, ux >> 32);147 var ix = @as(u32, @intCast(ux >> 32));
148 const sign = ix >> 31;148 const sign = ix >> 31;
149 ix &= 0x7FFFFFFF;149 ix &= 0x7FFFFFFF;
150150
...@@ -165,7 +165,7 @@ fn atan64(x_: f64) f64 {...@@ -165,7 +165,7 @@ fn atan64(x_: f64) f64 {
165 // |x| < 2^(-27)165 // |x| < 2^(-27)
166 if (ix < 0x3E400000) {166 if (ix < 0x3E400000) {
167 if (ix < 0x00100000) {167 if (ix < 0x00100000) {
168 math.doNotOptimizeAway(@floatCast(f32, x));168 math.doNotOptimizeAway(@as(f32, @floatCast(x)));
169 }169 }
170 return x;170 return x;
171 }171 }
...@@ -212,7 +212,7 @@ fn atan64(x_: f64) f64 {...@@ -212,7 +212,7 @@ fn atan64(x_: f64) f64 {
212}212}
213213
214test "math.atan" {214test "math.atan" {
215 try expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));215 try expect(@as(u32, @bitCast(atan(@as(f32, 0.2)))) == @as(u32, @bitCast(atan32(0.2))));
216 try expect(atan(@as(f64, 0.2)) == atan64(0.2));216 try expect(atan(@as(f64, 0.2)) == atan64(0.2));
217}217}
218218
lib/std/math/atan2.zig+8-8
...@@ -44,8 +44,8 @@ fn atan2_32(y: f32, x: f32) f32 {...@@ -44,8 +44,8 @@ fn atan2_32(y: f32, x: f32) f32 {
44 return x + y;44 return x + y;
45 }45 }
4646
47 var ix = @bitCast(u32, x);47 var ix = @as(u32, @bitCast(x));
48 var iy = @bitCast(u32, y);48 var iy = @as(u32, @bitCast(y));
4949
50 // x = 1.050 // x = 1.0
51 if (ix == 0x3F800000) {51 if (ix == 0x3F800000) {
...@@ -129,13 +129,13 @@ fn atan2_64(y: f64, x: f64) f64 {...@@ -129,13 +129,13 @@ fn atan2_64(y: f64, x: f64) f64 {
129 return x + y;129 return x + y;
130 }130 }
131131
132 var ux = @bitCast(u64, x);132 var ux = @as(u64, @bitCast(x));
133 var ix = @intCast(u32, ux >> 32);133 var ix = @as(u32, @intCast(ux >> 32));
134 var lx = @intCast(u32, ux & 0xFFFFFFFF);134 var lx = @as(u32, @intCast(ux & 0xFFFFFFFF));
135135
136 var uy = @bitCast(u64, y);136 var uy = @as(u64, @bitCast(y));
137 var iy = @intCast(u32, uy >> 32);137 var iy = @as(u32, @intCast(uy >> 32));
138 var ly = @intCast(u32, uy & 0xFFFFFFFF);138 var ly = @as(u32, @intCast(uy & 0xFFFFFFFF));
139139
140 // x = 1.0140 // x = 1.0
141 if ((ix -% 0x3FF00000) | lx == 0) {141 if ((ix -% 0x3FF00000) | lx == 0) {
lib/std/math/atanh.zig+5-5
...@@ -26,11 +26,11 @@ pub fn atanh(x: anytype) @TypeOf(x) {...@@ -26,11 +26,11 @@ pub fn atanh(x: anytype) @TypeOf(x) {
2626
27// atanh(x) = log((1 + x) / (1 - x)) / 2 = log1p(2x / (1 - x)) / 2 ~= x + x^3 / 3 + o(x^5)27// atanh(x) = log((1 + x) / (1 - x)) / 2 = log1p(2x / (1 - x)) / 2 ~= x + x^3 / 3 + o(x^5)
28fn atanh_32(x: f32) f32 {28fn atanh_32(x: f32) f32 {
29 const u = @bitCast(u32, x);29 const u = @as(u32, @bitCast(x));
30 const i = u & 0x7FFFFFFF;30 const i = u & 0x7FFFFFFF;
31 const s = u >> 31;31 const s = u >> 31;
3232
33 var y = @bitCast(f32, i); // |x|33 var y = @as(f32, @bitCast(i)); // |x|
3434
35 if (y == 1.0) {35 if (y == 1.0) {
36 return math.copysign(math.inf(f32), x);36 return math.copysign(math.inf(f32), x);
...@@ -55,11 +55,11 @@ fn atanh_32(x: f32) f32 {...@@ -55,11 +55,11 @@ fn atanh_32(x: f32) f32 {
55}55}
5656
57fn atanh_64(x: f64) f64 {57fn atanh_64(x: f64) f64 {
58 const u = @bitCast(u64, x);58 const u = @as(u64, @bitCast(x));
59 const e = (u >> 52) & 0x7FF;59 const e = (u >> 52) & 0x7FF;
60 const s = u >> 63;60 const s = u >> 63;
6161
62 var y = @bitCast(f64, u & (maxInt(u64) >> 1)); // |x|62 var y = @as(f64, @bitCast(u & (maxInt(u64) >> 1))); // |x|
6363
64 if (y == 1.0) {64 if (y == 1.0) {
65 return math.copysign(math.inf(f64), x);65 return math.copysign(math.inf(f64), x);
...@@ -69,7 +69,7 @@ fn atanh_64(x: f64) f64 {...@@ -69,7 +69,7 @@ fn atanh_64(x: f64) f64 {
69 if (e < 0x3FF - 32) {69 if (e < 0x3FF - 32) {
70 // underflow70 // underflow
71 if (e == 0) {71 if (e == 0) {
72 math.doNotOptimizeAway(@floatCast(f32, y));72 math.doNotOptimizeAway(@as(f32, @floatCast(y)));
73 }73 }
74 }74 }
75 // |x| < 0.575 // |x| < 0.5
lib/std/math/big/int.zig+32-32
...@@ -30,7 +30,7 @@ pub fn calcLimbLen(scalar: anytype) usize {...@@ -30,7 +30,7 @@ pub fn calcLimbLen(scalar: anytype) usize {
30 }30 }
3131
32 const w_value = std.math.absCast(scalar);32 const w_value = std.math.absCast(scalar);
33 return @intCast(usize, @divFloor(@intCast(Limb, math.log2(w_value)), limb_bits) + 1);33 return @as(usize, @intCast(@divFloor(@as(Limb, @intCast(math.log2(w_value))), limb_bits) + 1));
34}34}
3535
36pub fn calcToStringLimbsBufferLen(a_len: usize, base: u8) usize {36pub fn calcToStringLimbsBufferLen(a_len: usize, base: u8) usize {
...@@ -87,8 +87,8 @@ pub fn addMulLimbWithCarry(a: Limb, b: Limb, c: Limb, carry: *Limb) Limb {...@@ -87,8 +87,8 @@ pub fn addMulLimbWithCarry(a: Limb, b: Limb, c: Limb, carry: *Limb) Limb {
8787
88 // r2 = b * c88 // r2 = b * c
89 const bc = @as(DoubleLimb, math.mulWide(Limb, b, c));89 const bc = @as(DoubleLimb, math.mulWide(Limb, b, c));
90 const r2 = @truncate(Limb, bc);90 const r2 = @as(Limb, @truncate(bc));
91 const c2 = @truncate(Limb, bc >> limb_bits);91 const c2 = @as(Limb, @truncate(bc >> limb_bits));
9292
93 // ov2[0] = ov1[0] + r293 // ov2[0] = ov1[0] + r2
94 const ov2 = @addWithOverflow(ov1[0], r2);94 const ov2 = @addWithOverflow(ov1[0], r2);
...@@ -107,8 +107,8 @@ fn subMulLimbWithBorrow(a: Limb, b: Limb, c: Limb, carry: *Limb) Limb {...@@ -107,8 +107,8 @@ fn subMulLimbWithBorrow(a: Limb, b: Limb, c: Limb, carry: *Limb) Limb {
107107
108 // r2 = b * c108 // r2 = b * c
109 const bc = @as(DoubleLimb, std.math.mulWide(Limb, b, c));109 const bc = @as(DoubleLimb, std.math.mulWide(Limb, b, c));
110 const r2 = @truncate(Limb, bc);110 const r2 = @as(Limb, @truncate(bc));
111 const c2 = @truncate(Limb, bc >> limb_bits);111 const c2 = @as(Limb, @truncate(bc >> limb_bits));
112112
113 // ov2[0] = ov1[0] - r2113 // ov2[0] = ov1[0] - r2
114 const ov2 = @subWithOverflow(ov1[0], r2);114 const ov2 = @subWithOverflow(ov1[0], r2);
...@@ -244,7 +244,7 @@ pub const Mutable = struct {...@@ -244,7 +244,7 @@ pub const Mutable = struct {
244 } else {244 } else {
245 var i: usize = 0;245 var i: usize = 0;
246 while (true) : (i += 1) {246 while (true) : (i += 1) {
247 self.limbs[i] = @truncate(Limb, w_value);247 self.limbs[i] = @as(Limb, @truncate(w_value));
248 w_value >>= limb_bits;248 w_value >>= limb_bits;
249249
250 if (w_value == 0) break;250 if (w_value == 0) break;
...@@ -340,7 +340,7 @@ pub const Mutable = struct {...@@ -340,7 +340,7 @@ pub const Mutable = struct {
340 }340 }
341341
342 const req_limbs = calcTwosCompLimbCount(bit_count);342 const req_limbs = calcTwosCompLimbCount(bit_count);
343 const bit = @truncate(Log2Limb, bit_count - 1);343 const bit = @as(Log2Limb, @truncate(bit_count - 1));
344 const signmask = @as(Limb, 1) << bit; // 0b0..010..0 where 1 is the sign bit.344 const signmask = @as(Limb, 1) << bit; // 0b0..010..0 where 1 is the sign bit.
345 const mask = (signmask << 1) -% 1; // 0b0..011..1 where the leftmost 1 is the sign bit.345 const mask = (signmask << 1) -% 1; // 0b0..011..1 where the leftmost 1 is the sign bit.
346346
...@@ -365,7 +365,7 @@ pub const Mutable = struct {...@@ -365,7 +365,7 @@ pub const Mutable = struct {
365 r.set(0);365 r.set(0);
366 } else {366 } else {
367 const new_req_limbs = calcTwosCompLimbCount(bit_count - 1);367 const new_req_limbs = calcTwosCompLimbCount(bit_count - 1);
368 const msb = @truncate(Log2Limb, bit_count - 2);368 const msb = @as(Log2Limb, @truncate(bit_count - 2));
369 const new_signmask = @as(Limb, 1) << msb; // 0b0..010..0 where 1 is the sign bit.369 const new_signmask = @as(Limb, 1) << msb; // 0b0..010..0 where 1 is the sign bit.
370 const new_mask = (new_signmask << 1) -% 1; // 0b0..001..1 where the rightmost 0 is the sign bit.370 const new_mask = (new_signmask << 1) -% 1; // 0b0..001..1 where the rightmost 0 is the sign bit.
371371
...@@ -1153,7 +1153,7 @@ pub const Mutable = struct {...@@ -1153,7 +1153,7 @@ pub const Mutable = struct {
1153 // const msb = @truncate(Log2Limb, checkbit);1153 // const msb = @truncate(Log2Limb, checkbit);
1154 // const checkmask = (@as(Limb, 1) << msb) -% 1;1154 // const checkmask = (@as(Limb, 1) << msb) -% 1;
11551155
1156 if (a.limbs[a.limbs.len - 1] >> @truncate(Log2Limb, checkbit) != 0) {1156 if (a.limbs[a.limbs.len - 1] >> @as(Log2Limb, @truncate(checkbit)) != 0) {
1157 // Need to saturate.1157 // Need to saturate.
1158 r.setTwosCompIntLimit(if (a.positive) .max else .min, signedness, bit_count);1158 r.setTwosCompIntLimit(if (a.positive) .max else .min, signedness, bit_count);
1159 return;1159 return;
...@@ -1554,7 +1554,7 @@ pub const Mutable = struct {...@@ -1554,7 +1554,7 @@ pub const Mutable = struct {
1554 // Optimization for small divisor. By using a half limb we can avoid requiring DoubleLimb1554 // Optimization for small divisor. By using a half limb we can avoid requiring DoubleLimb
1555 // divisions in the hot code path. This may often require compiler_rt software-emulation.1555 // divisions in the hot code path. This may often require compiler_rt software-emulation.
1556 if (divisor < maxInt(HalfLimb)) {1556 if (divisor < maxInt(HalfLimb)) {
1557 lldiv0p5(q.limbs, &r.limbs[0], x.limbs[xy_trailing..x.len], @intCast(HalfLimb, divisor));1557 lldiv0p5(q.limbs, &r.limbs[0], x.limbs[xy_trailing..x.len], @as(HalfLimb, @intCast(divisor)));
1558 } else {1558 } else {
1559 lldiv1(q.limbs, &r.limbs[0], x.limbs[xy_trailing..x.len], divisor);1559 lldiv1(q.limbs, &r.limbs[0], x.limbs[xy_trailing..x.len], divisor);
1560 }1560 }
...@@ -1671,7 +1671,7 @@ pub const Mutable = struct {...@@ -1671,7 +1671,7 @@ pub const Mutable = struct {
1671 } else {1671 } else {
1672 const q0 = (@as(DoubleLimb, x.limbs[i]) << limb_bits) | @as(DoubleLimb, x.limbs[i - 1]);1672 const q0 = (@as(DoubleLimb, x.limbs[i]) << limb_bits) | @as(DoubleLimb, x.limbs[i - 1]);
1673 const n0 = @as(DoubleLimb, y.limbs[t]);1673 const n0 = @as(DoubleLimb, y.limbs[t]);
1674 q.limbs[k] = @intCast(Limb, q0 / n0);1674 q.limbs[k] = @as(Limb, @intCast(q0 / n0));
1675 }1675 }
16761676
1677 // 3.21677 // 3.2
...@@ -1750,7 +1750,7 @@ pub const Mutable = struct {...@@ -1750,7 +1750,7 @@ pub const Mutable = struct {
1750 return;1750 return;
1751 }1751 }
17521752
1753 const bit = @truncate(Log2Limb, bit_count - 1);1753 const bit = @as(Log2Limb, @truncate(bit_count - 1));
1754 const signmask = @as(Limb, 1) << bit;1754 const signmask = @as(Limb, 1) << bit;
1755 const mask = (signmask << 1) -% 1;1755 const mask = (signmask << 1) -% 1;
17561756
...@@ -1781,7 +1781,7 @@ pub const Mutable = struct {...@@ -1781,7 +1781,7 @@ pub const Mutable = struct {
1781 return;1781 return;
1782 }1782 }
17831783
1784 const bit = @truncate(Log2Limb, bit_count - 1);1784 const bit = @as(Log2Limb, @truncate(bit_count - 1));
1785 const signmask = @as(Limb, 1) << bit; // 0b0..010...0 where 1 is the sign bit.1785 const signmask = @as(Limb, 1) << bit; // 0b0..010...0 where 1 is the sign bit.
1786 const mask = (signmask << 1) -% 1; // 0b0..01..1 where the leftmost 1 is the sign bit.1786 const mask = (signmask << 1) -% 1; // 0b0..01..1 where the leftmost 1 is the sign bit.
17871787
...@@ -1912,7 +1912,7 @@ pub const Mutable = struct {...@@ -1912,7 +1912,7 @@ pub const Mutable = struct {
1912 .Big => buffer.len - ((total_bits + 7) / 8),1912 .Big => buffer.len - ((total_bits + 7) / 8),
1913 };1913 };
19141914
1915 const sign_bit = @as(u8, 1) << @intCast(u3, (total_bits - 1) % 8);1915 const sign_bit = @as(u8, 1) << @as(u3, @intCast((total_bits - 1) % 8));
1916 positive = ((buffer[last_byte] & sign_bit) == 0);1916 positive = ((buffer[last_byte] & sign_bit) == 0);
1917 }1917 }
19181918
...@@ -1942,7 +1942,7 @@ pub const Mutable = struct {...@@ -1942,7 +1942,7 @@ pub const Mutable = struct {
1942 .signed => b: {1942 .signed => b: {
1943 const SLimb = std.meta.Int(.signed, @bitSizeOf(Limb));1943 const SLimb = std.meta.Int(.signed, @bitSizeOf(Limb));
1944 const limb = mem.readVarPackedInt(SLimb, buffer, bit_index + bit_offset, bit_count - bit_index, endian, .signed);1944 const limb = mem.readVarPackedInt(SLimb, buffer, bit_index + bit_offset, bit_count - bit_index, endian, .signed);
1945 break :b @bitCast(Limb, limb);1945 break :b @as(Limb, @bitCast(limb));
1946 },1946 },
1947 };1947 };
19481948
...@@ -2170,7 +2170,7 @@ pub const Const = struct {...@@ -2170,7 +2170,7 @@ pub const Const = struct {
2170 var r: UT = 0;2170 var r: UT = 0;
21712171
2172 if (@sizeOf(UT) <= @sizeOf(Limb)) {2172 if (@sizeOf(UT) <= @sizeOf(Limb)) {
2173 r = @intCast(UT, self.limbs[0]);2173 r = @as(UT, @intCast(self.limbs[0]));
2174 } else {2174 } else {
2175 for (self.limbs[0..self.limbs.len], 0..) |_, ri| {2175 for (self.limbs[0..self.limbs.len], 0..) |_, ri| {
2176 const limb = self.limbs[self.limbs.len - ri - 1];2176 const limb = self.limbs[self.limbs.len - ri - 1];
...@@ -2180,10 +2180,10 @@ pub const Const = struct {...@@ -2180,10 +2180,10 @@ pub const Const = struct {
2180 }2180 }
21812181
2182 if (info.signedness == .unsigned) {2182 if (info.signedness == .unsigned) {
2183 return if (self.positive) @intCast(T, r) else error.NegativeIntoUnsigned;2183 return if (self.positive) @as(T, @intCast(r)) else error.NegativeIntoUnsigned;
2184 } else {2184 } else {
2185 if (self.positive) {2185 if (self.positive) {
2186 return @intCast(T, r);2186 return @as(T, @intCast(r));
2187 } else {2187 } else {
2188 if (math.cast(T, r)) |ok| {2188 if (math.cast(T, r)) |ok| {
2189 return -ok;2189 return -ok;
...@@ -2292,7 +2292,7 @@ pub const Const = struct {...@@ -2292,7 +2292,7 @@ pub const Const = struct {
2292 outer: for (self.limbs[0..self.limbs.len]) |limb| {2292 outer: for (self.limbs[0..self.limbs.len]) |limb| {
2293 var shift: usize = 0;2293 var shift: usize = 0;
2294 while (shift < limb_bits) : (shift += base_shift) {2294 while (shift < limb_bits) : (shift += base_shift) {
2295 const r = @intCast(u8, (limb >> @intCast(Log2Limb, shift)) & @as(Limb, base - 1));2295 const r = @as(u8, @intCast((limb >> @as(Log2Limb, @intCast(shift))) & @as(Limb, base - 1)));
2296 const ch = std.fmt.digitToChar(r, case);2296 const ch = std.fmt.digitToChar(r, case);
2297 string[digits_len] = ch;2297 string[digits_len] = ch;
2298 digits_len += 1;2298 digits_len += 1;
...@@ -2340,7 +2340,7 @@ pub const Const = struct {...@@ -2340,7 +2340,7 @@ pub const Const = struct {
2340 var r_word = r.limbs[0];2340 var r_word = r.limbs[0];
2341 var i: usize = 0;2341 var i: usize = 0;
2342 while (i < digits_per_limb) : (i += 1) {2342 while (i < digits_per_limb) : (i += 1) {
2343 const ch = std.fmt.digitToChar(@intCast(u8, r_word % base), case);2343 const ch = std.fmt.digitToChar(@as(u8, @intCast(r_word % base)), case);
2344 r_word /= base;2344 r_word /= base;
2345 string[digits_len] = ch;2345 string[digits_len] = ch;
2346 digits_len += 1;2346 digits_len += 1;
...@@ -2352,7 +2352,7 @@ pub const Const = struct {...@@ -2352,7 +2352,7 @@ pub const Const = struct {
23522352
2353 var r_word = q.limbs[0];2353 var r_word = q.limbs[0];
2354 while (r_word != 0) {2354 while (r_word != 0) {
2355 const ch = std.fmt.digitToChar(@intCast(u8, r_word % base), case);2355 const ch = std.fmt.digitToChar(@as(u8, @intCast(r_word % base)), case);
2356 r_word /= base;2356 r_word /= base;
2357 string[digits_len] = ch;2357 string[digits_len] = ch;
2358 digits_len += 1;2358 digits_len += 1;
...@@ -3680,13 +3680,13 @@ fn lldiv1(quo: []Limb, rem: *Limb, a: []const Limb, b: Limb) void {...@@ -3680,13 +3680,13 @@ fn lldiv1(quo: []Limb, rem: *Limb, a: []const Limb, b: Limb) void {
3680 rem.* = 0;3680 rem.* = 0;
3681 } else if (pdiv < b) {3681 } else if (pdiv < b) {
3682 quo[i] = 0;3682 quo[i] = 0;
3683 rem.* = @truncate(Limb, pdiv);3683 rem.* = @as(Limb, @truncate(pdiv));
3684 } else if (pdiv == b) {3684 } else if (pdiv == b) {
3685 quo[i] = 1;3685 quo[i] = 1;
3686 rem.* = 0;3686 rem.* = 0;
3687 } else {3687 } else {
3688 quo[i] = @truncate(Limb, @divTrunc(pdiv, b));3688 quo[i] = @as(Limb, @truncate(@divTrunc(pdiv, b)));
3689 rem.* = @truncate(Limb, pdiv - (quo[i] *% b));3689 rem.* = @as(Limb, @truncate(pdiv - (quo[i] *% b)));
3690 }3690 }
3691 }3691 }
3692}3692}
...@@ -3719,7 +3719,7 @@ fn llshl(r: []Limb, a: []const Limb, shift: usize) void {...@@ -3719,7 +3719,7 @@ fn llshl(r: []Limb, a: []const Limb, shift: usize) void {
3719 @setRuntimeSafety(debug_safety);3719 @setRuntimeSafety(debug_safety);
3720 assert(a.len >= 1);3720 assert(a.len >= 1);
37213721
3722 const interior_limb_shift = @truncate(Log2Limb, shift);3722 const interior_limb_shift = @as(Log2Limb, @truncate(shift));
37233723
3724 // We only need the extra limb if the shift of the last element overflows.3724 // We only need the extra limb if the shift of the last element overflows.
3725 // This is useful for the implementation of `shiftLeftSat`.3725 // This is useful for the implementation of `shiftLeftSat`.
...@@ -3741,7 +3741,7 @@ fn llshl(r: []Limb, a: []const Limb, shift: usize) void {...@@ -3741,7 +3741,7 @@ fn llshl(r: []Limb, a: []const Limb, shift: usize) void {
3741 r[dst_i] = carry | @call(.always_inline, math.shr, .{3741 r[dst_i] = carry | @call(.always_inline, math.shr, .{
3742 Limb,3742 Limb,
3743 src_digit,3743 src_digit,
3744 limb_bits - @intCast(Limb, interior_limb_shift),3744 limb_bits - @as(Limb, @intCast(interior_limb_shift)),
3745 });3745 });
3746 carry = (src_digit << interior_limb_shift);3746 carry = (src_digit << interior_limb_shift);
3747 }3747 }
...@@ -3756,7 +3756,7 @@ fn llshr(r: []Limb, a: []const Limb, shift: usize) void {...@@ -3756,7 +3756,7 @@ fn llshr(r: []Limb, a: []const Limb, shift: usize) void {
3756 assert(r.len >= a.len - (shift / limb_bits));3756 assert(r.len >= a.len - (shift / limb_bits));
37573757
3758 const limb_shift = shift / limb_bits;3758 const limb_shift = shift / limb_bits;
3759 const interior_limb_shift = @truncate(Log2Limb, shift);3759 const interior_limb_shift = @as(Log2Limb, @truncate(shift));
37603760
3761 var carry: Limb = 0;3761 var carry: Limb = 0;
3762 var i: usize = 0;3762 var i: usize = 0;
...@@ -3769,7 +3769,7 @@ fn llshr(r: []Limb, a: []const Limb, shift: usize) void {...@@ -3769,7 +3769,7 @@ fn llshr(r: []Limb, a: []const Limb, shift: usize) void {
3769 carry = @call(.always_inline, math.shl, .{3769 carry = @call(.always_inline, math.shl, .{
3770 Limb,3770 Limb,
3771 src_digit,3771 src_digit,
3772 limb_bits - @intCast(Limb, interior_limb_shift),3772 limb_bits - @as(Limb, @intCast(interior_limb_shift)),
3773 });3773 });
3774 }3774 }
3775}3775}
...@@ -4150,7 +4150,7 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {...@@ -4150,7 +4150,7 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {
4150 // Square the result if the current bit is zero, square and multiply by a if4150 // Square the result if the current bit is zero, square and multiply by a if
4151 // it is one.4151 // it is one.
4152 var exp_bits = 32 - 1 - b_leading_zeros;4152 var exp_bits = 32 - 1 - b_leading_zeros;
4153 var exp = b << @intCast(u5, 1 + b_leading_zeros);4153 var exp = b << @as(u5, @intCast(1 + b_leading_zeros));
41544154
4155 var i: usize = 0;4155 var i: usize = 0;
4156 while (i < exp_bits) : (i += 1) {4156 while (i < exp_bits) : (i += 1) {
...@@ -4174,9 +4174,9 @@ fn fixedIntFromSignedDoubleLimb(A: SignedDoubleLimb, storage: []Limb) Mutable {...@@ -4174,9 +4174,9 @@ fn fixedIntFromSignedDoubleLimb(A: SignedDoubleLimb, storage: []Limb) Mutable {
4174 assert(storage.len >= 2);4174 assert(storage.len >= 2);
41754175
4176 const A_is_positive = A >= 0;4176 const A_is_positive = A >= 0;
4177 const Au = @intCast(DoubleLimb, if (A < 0) -A else A);4177 const Au = @as(DoubleLimb, @intCast(if (A < 0) -A else A));
4178 storage[0] = @truncate(Limb, Au);4178 storage[0] = @as(Limb, @truncate(Au));
4179 storage[1] = @truncate(Limb, Au >> limb_bits);4179 storage[1] = @as(Limb, @truncate(Au >> limb_bits));
4180 return .{4180 return .{
4181 .limbs = storage[0..2],4181 .limbs = storage[0..2],
4182 .positive = A_is_positive,4182 .positive = A_is_positive,
lib/std/math/big/int_test.zig+33-33
...@@ -2898,19 +2898,19 @@ test "big int conversion write twos complement with padding" {...@@ -2898,19 +2898,19 @@ test "big int conversion write twos complement with padding" {
28982898
2899 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa };2899 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa };
2900 m.readTwosComplement(buffer[0..13], bit_count, .Little, .unsigned);2900 m.readTwosComplement(buffer[0..13], bit_count, .Little, .unsigned);
2901 try testing.expect(m.toConst().orderAgainstScalar(@truncate(Limb, 0xaa_02030405_06070809_0a0b0c0d)) == .eq);2901 try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaa_02030405_06070809_0a0b0c0d))) == .eq);
29022902
2903 buffer = &[_]u8{ 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };2903 buffer = &[_]u8{ 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };
2904 m.readTwosComplement(buffer[0..13], bit_count, .Big, .unsigned);2904 m.readTwosComplement(buffer[0..13], bit_count, .Big, .unsigned);
2905 try testing.expect(m.toConst().orderAgainstScalar(@truncate(Limb, 0xaa_02030405_06070809_0a0b0c0d)) == .eq);2905 try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaa_02030405_06070809_0a0b0c0d))) == .eq);
29062906
2907 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa, 0xaa, 0xaa, 0xaa };2907 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa, 0xaa, 0xaa, 0xaa };
2908 m.readTwosComplement(buffer[0..16], bit_count, .Little, .unsigned);2908 m.readTwosComplement(buffer[0..16], bit_count, .Little, .unsigned);
2909 try testing.expect(m.toConst().orderAgainstScalar(@truncate(Limb, 0xaaaaaaaa_02030405_06070809_0a0b0c0d)) == .eq);2909 try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaaaaaaaa_02030405_06070809_0a0b0c0d))) == .eq);
29102910
2911 buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };2911 buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };
2912 m.readTwosComplement(buffer[0..16], bit_count, .Big, .unsigned);2912 m.readTwosComplement(buffer[0..16], bit_count, .Big, .unsigned);
2913 try testing.expect(m.toConst().orderAgainstScalar(@truncate(Limb, 0xaaaaaaaa_02030405_06070809_0a0b0c0d)) == .eq);2913 try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaaaaaaaa_02030405_06070809_0a0b0c0d))) == .eq);
29142914
2915 bit_count = 12 * 8 + 2;2915 bit_count = 12 * 8 + 2;
29162916
...@@ -3014,20 +3014,20 @@ test "big int bit reverse" {...@@ -3014,20 +3014,20 @@ test "big int bit reverse" {
3014 try bitReverseTest(u96, 0x123456789abcdef111213141, 0x828c84888f7b3d591e6a2c48);3014 try bitReverseTest(u96, 0x123456789abcdef111213141, 0x828c84888f7b3d591e6a2c48);
3015 try bitReverseTest(u128, 0x123456789abcdef11121314151617181, 0x818e868a828c84888f7b3d591e6a2c48);3015 try bitReverseTest(u128, 0x123456789abcdef11121314151617181, 0x818e868a828c84888f7b3d591e6a2c48);
30163016
3017 try bitReverseTest(i8, @bitCast(i8, @as(u8, 0x92)), @bitCast(i8, @as(u8, 0x49)));3017 try bitReverseTest(i8, @as(i8, @bitCast(@as(u8, 0x92))), @as(i8, @bitCast(@as(u8, 0x49))));
3018 try bitReverseTest(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x2c48)));3018 try bitReverseTest(i16, @as(i16, @bitCast(@as(u16, 0x1234))), @as(i16, @bitCast(@as(u16, 0x2c48))));
3019 try bitReverseTest(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x6a2c48)));3019 try bitReverseTest(i24, @as(i24, @bitCast(@as(u24, 0x123456))), @as(i24, @bitCast(@as(u24, 0x6a2c48))));
3020 try bitReverseTest(i24, @bitCast(i24, @as(u24, 0x12345f)), @bitCast(i24, @as(u24, 0xfa2c48)));3020 try bitReverseTest(i24, @as(i24, @bitCast(@as(u24, 0x12345f))), @as(i24, @bitCast(@as(u24, 0xfa2c48))));
3021 try bitReverseTest(i24, @bitCast(i24, @as(u24, 0xf23456)), @bitCast(i24, @as(u24, 0x6a2c4f)));3021 try bitReverseTest(i24, @as(i24, @bitCast(@as(u24, 0xf23456))), @as(i24, @bitCast(@as(u24, 0x6a2c4f))));
3022 try bitReverseTest(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x1e6a2c48)));3022 try bitReverseTest(i32, @as(i32, @bitCast(@as(u32, 0x12345678))), @as(i32, @bitCast(@as(u32, 0x1e6a2c48))));
3023 try bitReverseTest(i32, @bitCast(i32, @as(u32, 0xf2345678)), @bitCast(i32, @as(u32, 0x1e6a2c4f)));3023 try bitReverseTest(i32, @as(i32, @bitCast(@as(u32, 0xf2345678))), @as(i32, @bitCast(@as(u32, 0x1e6a2c4f))));
3024 try bitReverseTest(i32, @bitCast(i32, @as(u32, 0x1234567f)), @bitCast(i32, @as(u32, 0xfe6a2c48)));3024 try bitReverseTest(i32, @as(i32, @bitCast(@as(u32, 0x1234567f))), @as(i32, @bitCast(@as(u32, 0xfe6a2c48))));
3025 try bitReverseTest(i40, @bitCast(i40, @as(u40, 0x123456789a)), @bitCast(i40, @as(u40, 0x591e6a2c48)));3025 try bitReverseTest(i40, @as(i40, @bitCast(@as(u40, 0x123456789a))), @as(i40, @bitCast(@as(u40, 0x591e6a2c48))));
3026 try bitReverseTest(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0x3d591e6a2c48)));3026 try bitReverseTest(i48, @as(i48, @bitCast(@as(u48, 0x123456789abc))), @as(i48, @bitCast(@as(u48, 0x3d591e6a2c48))));
3027 try bitReverseTest(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0x7b3d591e6a2c48)));3027 try bitReverseTest(i56, @as(i56, @bitCast(@as(u56, 0x123456789abcde))), @as(i56, @bitCast(@as(u56, 0x7b3d591e6a2c48))));
3028 try bitReverseTest(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48)));3028 try bitReverseTest(i64, @as(i64, @bitCast(@as(u64, 0x123456789abcdef1))), @as(i64, @bitCast(@as(u64, 0x8f7b3d591e6a2c48))));
3029 try bitReverseTest(i96, @bitCast(i96, @as(u96, 0x123456789abcdef111213141)), @bitCast(i96, @as(u96, 0x828c84888f7b3d591e6a2c48)));3029 try bitReverseTest(i96, @as(i96, @bitCast(@as(u96, 0x123456789abcdef111213141))), @as(i96, @bitCast(@as(u96, 0x828c84888f7b3d591e6a2c48))));
3030 try bitReverseTest(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)), @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48)));3030 try bitReverseTest(i128, @as(i128, @bitCast(@as(u128, 0x123456789abcdef11121314151617181))), @as(i128, @bitCast(@as(u128, 0x818e868a828c84888f7b3d591e6a2c48))));
3031}3031}
30323032
3033fn byteSwapTest(comptime T: type, comptime input: comptime_int, comptime expected_output: comptime_int) !void {3033fn byteSwapTest(comptime T: type, comptime input: comptime_int, comptime expected_output: comptime_int) !void {
...@@ -3063,16 +3063,16 @@ test "big int byte swap" {...@@ -3063,16 +3063,16 @@ test "big int byte swap" {
3063 try byteSwapTest(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412);3063 try byteSwapTest(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412);
30643064
3065 try byteSwapTest(i8, -50, -50);3065 try byteSwapTest(i8, -50, -50);
3066 try byteSwapTest(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412)));3066 try byteSwapTest(i16, @as(i16, @bitCast(@as(u16, 0x1234))), @as(i16, @bitCast(@as(u16, 0x3412))));
3067 try byteSwapTest(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x563412)));3067 try byteSwapTest(i24, @as(i24, @bitCast(@as(u24, 0x123456))), @as(i24, @bitCast(@as(u24, 0x563412))));
3068 try byteSwapTest(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412)));3068 try byteSwapTest(i32, @as(i32, @bitCast(@as(u32, 0x12345678))), @as(i32, @bitCast(@as(u32, 0x78563412))));
3069 try byteSwapTest(i40, @bitCast(i40, @as(u40, 0x123456789a)), @bitCast(i40, @as(u40, 0x9a78563412)));3069 try byteSwapTest(i40, @as(i40, @bitCast(@as(u40, 0x123456789a))), @as(i40, @bitCast(@as(u40, 0x9a78563412))));
3070 try byteSwapTest(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412)));3070 try byteSwapTest(i48, @as(i48, @bitCast(@as(u48, 0x123456789abc))), @as(i48, @bitCast(@as(u48, 0xbc9a78563412))));
3071 try byteSwapTest(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0xdebc9a78563412)));3071 try byteSwapTest(i56, @as(i56, @bitCast(@as(u56, 0x123456789abcde))), @as(i56, @bitCast(@as(u56, 0xdebc9a78563412))));
3072 try byteSwapTest(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412)));3072 try byteSwapTest(i64, @as(i64, @bitCast(@as(u64, 0x123456789abcdef1))), @as(i64, @bitCast(@as(u64, 0xf1debc9a78563412))));
3073 try byteSwapTest(i88, @bitCast(i88, @as(u88, 0x123456789abcdef1112131)), @bitCast(i88, @as(u88, 0x312111f1debc9a78563412)));3073 try byteSwapTest(i88, @as(i88, @bitCast(@as(u88, 0x123456789abcdef1112131))), @as(i88, @bitCast(@as(u88, 0x312111f1debc9a78563412))));
3074 try byteSwapTest(i96, @bitCast(i96, @as(u96, 0x123456789abcdef111213141)), @bitCast(i96, @as(u96, 0x41312111f1debc9a78563412)));3074 try byteSwapTest(i96, @as(i96, @bitCast(@as(u96, 0x123456789abcdef111213141))), @as(i96, @bitCast(@as(u96, 0x41312111f1debc9a78563412))));
3075 try byteSwapTest(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)), @bitCast(i128, @as(u128, 0x8171615141312111f1debc9a78563412)));3075 try byteSwapTest(i128, @as(i128, @bitCast(@as(u128, 0x123456789abcdef11121314151617181))), @as(i128, @bitCast(@as(u128, 0x8171615141312111f1debc9a78563412))));
30763076
3077 try byteSwapTest(u512, 0x80, 1 << 511);3077 try byteSwapTest(u512, 0x80, 1 << 511);
3078 try byteSwapTest(i512, 0x80, minInt(i512));3078 try byteSwapTest(i512, 0x80, minInt(i512));
...@@ -3080,11 +3080,11 @@ test "big int byte swap" {...@@ -3080,11 +3080,11 @@ test "big int byte swap" {
3080 try byteSwapTest(i512, -0x100, (1 << 504) - 1);3080 try byteSwapTest(i512, -0x100, (1 << 504) - 1);
3081 try byteSwapTest(i400, -0x100, (1 << 392) - 1);3081 try byteSwapTest(i400, -0x100, (1 << 392) - 1);
3082 try byteSwapTest(i400, -0x2, -(1 << 392) - 1);3082 try byteSwapTest(i400, -0x2, -(1 << 392) - 1);
3083 try byteSwapTest(i24, @bitCast(i24, @as(u24, 0xf23456)), 0x5634f2);3083 try byteSwapTest(i24, @as(i24, @bitCast(@as(u24, 0xf23456))), 0x5634f2);
3084 try byteSwapTest(i24, 0x1234f6, @bitCast(i24, @as(u24, 0xf63412)));3084 try byteSwapTest(i24, 0x1234f6, @as(i24, @bitCast(@as(u24, 0xf63412))));
3085 try byteSwapTest(i32, @bitCast(i32, @as(u32, 0xf2345678)), 0x785634f2);3085 try byteSwapTest(i32, @as(i32, @bitCast(@as(u32, 0xf2345678))), 0x785634f2);
3086 try byteSwapTest(i32, 0x123456f8, @bitCast(i32, @as(u32, 0xf8563412)));3086 try byteSwapTest(i32, 0x123456f8, @as(i32, @bitCast(@as(u32, 0xf8563412))));
3087 try byteSwapTest(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412)));3087 try byteSwapTest(i48, 0x123456789abc, @as(i48, @bitCast(@as(u48, 0xbc9a78563412))));
3088}3088}
30893089
3090test "big.int mul multi-multi alias r with a and b" {3090test "big.int mul multi-multi alias r with a and b" {
lib/std/math/big/rational.zig+11-11
...@@ -137,7 +137,7 @@ pub const Rational = struct {...@@ -137,7 +137,7 @@ pub const Rational = struct {
137 debug.assert(@typeInfo(T) == .Float);137 debug.assert(@typeInfo(T) == .Float);
138138
139 const UnsignedInt = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);139 const UnsignedInt = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
140 const f_bits = @bitCast(UnsignedInt, f);140 const f_bits = @as(UnsignedInt, @bitCast(f));
141141
142 const exponent_bits = math.floatExponentBits(T);142 const exponent_bits = math.floatExponentBits(T);
143 const exponent_bias = (1 << (exponent_bits - 1)) - 1;143 const exponent_bias = (1 << (exponent_bits - 1)) - 1;
...@@ -146,7 +146,7 @@ pub const Rational = struct {...@@ -146,7 +146,7 @@ pub const Rational = struct {
146 const exponent_mask = (1 << exponent_bits) - 1;146 const exponent_mask = (1 << exponent_bits) - 1;
147 const mantissa_mask = (1 << mantissa_bits) - 1;147 const mantissa_mask = (1 << mantissa_bits) - 1;
148148
149 var exponent = @intCast(i16, (f_bits >> mantissa_bits) & exponent_mask);149 var exponent = @as(i16, @intCast((f_bits >> mantissa_bits) & exponent_mask));
150 var mantissa = f_bits & mantissa_mask;150 var mantissa = f_bits & mantissa_mask;
151151
152 switch (exponent) {152 switch (exponent) {
...@@ -177,9 +177,9 @@ pub const Rational = struct {...@@ -177,9 +177,9 @@ pub const Rational = struct {
177177
178 try self.q.set(1);178 try self.q.set(1);
179 if (shift >= 0) {179 if (shift >= 0) {
180 try self.q.shiftLeft(&self.q, @intCast(usize, shift));180 try self.q.shiftLeft(&self.q, @as(usize, @intCast(shift)));
181 } else {181 } else {
182 try self.p.shiftLeft(&self.p, @intCast(usize, -shift));182 try self.p.shiftLeft(&self.p, @as(usize, @intCast(-shift)));
183 }183 }
184184
185 try self.reduce();185 try self.reduce();
...@@ -210,7 +210,7 @@ pub const Rational = struct {...@@ -210,7 +210,7 @@ pub const Rational = struct {
210 }210 }
211211
212 // 1. left-shift a or sub so that a/b is in [1 << msize1, 1 << (msize2 + 1)]212 // 1. left-shift a or sub so that a/b is in [1 << msize1, 1 << (msize2 + 1)]
213 var exp = @intCast(isize, self.p.bitCountTwosComp()) - @intCast(isize, self.q.bitCountTwosComp());213 var exp = @as(isize, @intCast(self.p.bitCountTwosComp())) - @as(isize, @intCast(self.q.bitCountTwosComp()));
214214
215 var a2 = try self.p.clone();215 var a2 = try self.p.clone();
216 defer a2.deinit();216 defer a2.deinit();
...@@ -220,9 +220,9 @@ pub const Rational = struct {...@@ -220,9 +220,9 @@ pub const Rational = struct {
220220
221 const shift = msize2 - exp;221 const shift = msize2 - exp;
222 if (shift >= 0) {222 if (shift >= 0) {
223 try a2.shiftLeft(&a2, @intCast(usize, shift));223 try a2.shiftLeft(&a2, @as(usize, @intCast(shift)));
224 } else {224 } else {
225 try b2.shiftLeft(&b2, @intCast(usize, -shift));225 try b2.shiftLeft(&b2, @as(usize, @intCast(-shift)));
226 }226 }
227227
228 // 2. compute quotient and remainder228 // 2. compute quotient and remainder
...@@ -254,8 +254,8 @@ pub const Rational = struct {...@@ -254,8 +254,8 @@ pub const Rational = struct {
254 // 4. Rounding254 // 4. Rounding
255 if (emin - msize <= exp and exp <= emin) {255 if (emin - msize <= exp and exp <= emin) {
256 // denormal256 // denormal
257 const shift1 = @intCast(math.Log2Int(BitReprType), emin - (exp - 1));257 const shift1 = @as(math.Log2Int(BitReprType), @intCast(emin - (exp - 1)));
258 const lost_bits = mantissa & ((@intCast(BitReprType, 1) << shift1) - 1);258 const lost_bits = mantissa & ((@as(BitReprType, @intCast(1)) << shift1) - 1);
259 have_rem = have_rem or lost_bits != 0;259 have_rem = have_rem or lost_bits != 0;
260 mantissa >>= shift1;260 mantissa >>= shift1;
261 exp = 2 - ebias;261 exp = 2 - ebias;
...@@ -276,7 +276,7 @@ pub const Rational = struct {...@@ -276,7 +276,7 @@ pub const Rational = struct {
276 }276 }
277 mantissa >>= 1;277 mantissa >>= 1;
278278
279 const f = math.scalbn(@floatFromInt(T, mantissa), @intCast(i32, exp - msize1));279 const f = math.scalbn(@as(T, @floatFromInt(mantissa)), @as(i32, @intCast(exp - msize1)));
280 if (math.isInf(f)) {280 if (math.isInf(f)) {
281 exact = false;281 exact = false;
282 }282 }
...@@ -477,7 +477,7 @@ fn extractLowBits(a: Int, comptime T: type) T {...@@ -477,7 +477,7 @@ fn extractLowBits(a: Int, comptime T: type) T {
477 const t_bits = @typeInfo(T).Int.bits;477 const t_bits = @typeInfo(T).Int.bits;
478 const limb_bits = @typeInfo(Limb).Int.bits;478 const limb_bits = @typeInfo(Limb).Int.bits;
479 if (t_bits <= limb_bits) {479 if (t_bits <= limb_bits) {
480 return @truncate(T, a.limbs[0]);480 return @as(T, @truncate(a.limbs[0]));
481 } else {481 } else {
482 var r: T = 0;482 var r: T = 0;
483 comptime var i: usize = 0;483 comptime var i: usize = 0;
lib/std/math/cbrt.zig+11-11
...@@ -27,7 +27,7 @@ fn cbrt32(x: f32) f32 {...@@ -27,7 +27,7 @@ fn cbrt32(x: f32) f32 {
27 const B1: u32 = 709958130; // (127 - 127.0 / 3 - 0.03306235651) * 2^2327 const B1: u32 = 709958130; // (127 - 127.0 / 3 - 0.03306235651) * 2^23
28 const B2: u32 = 642849266; // (127 - 127.0 / 3 - 24 / 3 - 0.03306235651) * 2^2328 const B2: u32 = 642849266; // (127 - 127.0 / 3 - 24 / 3 - 0.03306235651) * 2^23
2929
30 var u = @bitCast(u32, x);30 var u = @as(u32, @bitCast(x));
31 var hx = u & 0x7FFFFFFF;31 var hx = u & 0x7FFFFFFF;
3232
33 // cbrt(nan, inf) = itself33 // cbrt(nan, inf) = itself
...@@ -41,7 +41,7 @@ fn cbrt32(x: f32) f32 {...@@ -41,7 +41,7 @@ fn cbrt32(x: f32) f32 {
41 if (hx == 0) {41 if (hx == 0) {
42 return x;42 return x;
43 }43 }
44 u = @bitCast(u32, x * 0x1.0p24);44 u = @as(u32, @bitCast(x * 0x1.0p24));
45 hx = u & 0x7FFFFFFF;45 hx = u & 0x7FFFFFFF;
46 hx = hx / 3 + B2;46 hx = hx / 3 + B2;
47 } else {47 } else {
...@@ -52,7 +52,7 @@ fn cbrt32(x: f32) f32 {...@@ -52,7 +52,7 @@ fn cbrt32(x: f32) f32 {
52 u |= hx;52 u |= hx;
5353
54 // first step newton to 16 bits54 // first step newton to 16 bits
55 var t: f64 = @bitCast(f32, u);55 var t: f64 = @as(f32, @bitCast(u));
56 var r: f64 = t * t * t;56 var r: f64 = t * t * t;
57 t = t * (@as(f64, x) + x + r) / (x + r + r);57 t = t * (@as(f64, x) + x + r) / (x + r + r);
5858
...@@ -60,7 +60,7 @@ fn cbrt32(x: f32) f32 {...@@ -60,7 +60,7 @@ fn cbrt32(x: f32) f32 {
60 r = t * t * t;60 r = t * t * t;
61 t = t * (@as(f64, x) + x + r) / (x + r + r);61 t = t * (@as(f64, x) + x + r) / (x + r + r);
6262
63 return @floatCast(f32, t);63 return @as(f32, @floatCast(t));
64}64}
6565
66fn cbrt64(x: f64) f64 {66fn cbrt64(x: f64) f64 {
...@@ -74,8 +74,8 @@ fn cbrt64(x: f64) f64 {...@@ -74,8 +74,8 @@ fn cbrt64(x: f64) f64 {
74 const P3: f64 = -0.758397934778766047437;74 const P3: f64 = -0.758397934778766047437;
75 const P4: f64 = 0.145996192886612446982;75 const P4: f64 = 0.145996192886612446982;
7676
77 var u = @bitCast(u64, x);77 var u = @as(u64, @bitCast(x));
78 var hx = @intCast(u32, u >> 32) & 0x7FFFFFFF;78 var hx = @as(u32, @intCast(u >> 32)) & 0x7FFFFFFF;
7979
80 // cbrt(nan, inf) = itself80 // cbrt(nan, inf) = itself
81 if (hx >= 0x7FF00000) {81 if (hx >= 0x7FF00000) {
...@@ -84,8 +84,8 @@ fn cbrt64(x: f64) f64 {...@@ -84,8 +84,8 @@ fn cbrt64(x: f64) f64 {
8484
85 // cbrt to ~5bits85 // cbrt to ~5bits
86 if (hx < 0x00100000) {86 if (hx < 0x00100000) {
87 u = @bitCast(u64, x * 0x1.0p54);87 u = @as(u64, @bitCast(x * 0x1.0p54));
88 hx = @intCast(u32, u >> 32) & 0x7FFFFFFF;88 hx = @as(u32, @intCast(u >> 32)) & 0x7FFFFFFF;
8989
90 // cbrt(0) is itself90 // cbrt(0) is itself
91 if (hx == 0) {91 if (hx == 0) {
...@@ -98,7 +98,7 @@ fn cbrt64(x: f64) f64 {...@@ -98,7 +98,7 @@ fn cbrt64(x: f64) f64 {
9898
99 u &= 1 << 63;99 u &= 1 << 63;
100 u |= @as(u64, hx) << 32;100 u |= @as(u64, hx) << 32;
101 var t = @bitCast(f64, u);101 var t = @as(f64, @bitCast(u));
102102
103 // cbrt to 23 bits103 // cbrt to 23 bits
104 // cbrt(x) = t * cbrt(x / t^3) ~= t * P(t^3 / x)104 // cbrt(x) = t * cbrt(x / t^3) ~= t * P(t^3 / x)
...@@ -106,9 +106,9 @@ fn cbrt64(x: f64) f64 {...@@ -106,9 +106,9 @@ fn cbrt64(x: f64) f64 {
106 t = t * ((P0 + r * (P1 + r * P2)) + ((r * r) * r) * (P3 + r * P4));106 t = t * ((P0 + r * (P1 + r * P2)) + ((r * r) * r) * (P3 + r * P4));
107107
108 // Round t away from 0 to 23 bits108 // Round t away from 0 to 23 bits
109 u = @bitCast(u64, t);109 u = @as(u64, @bitCast(t));
110 u = (u + 0x80000000) & 0xFFFFFFFFC0000000;110 u = (u + 0x80000000) & 0xFFFFFFFFC0000000;
111 t = @bitCast(f64, u);111 t = @as(f64, @bitCast(u));
112112
113 // one step newton to 53 bits113 // one step newton to 53 bits
114 const s = t * t;114 const s = t * t;
lib/std/math/complex/atan.zig+2-2
...@@ -32,7 +32,7 @@ fn redupif32(x: f32) f32 {...@@ -32,7 +32,7 @@ fn redupif32(x: f32) f32 {
32 t -= 0.5;32 t -= 0.5;
33 }33 }
3434
35 const u = @floatFromInt(f32, @intFromFloat(i32, t));35 const u = @as(f32, @floatFromInt(@as(i32, @intFromFloat(t))));
36 return ((x - u * DP1) - u * DP2) - t * DP3;36 return ((x - u * DP1) - u * DP2) - t * DP3;
37}37}
3838
...@@ -81,7 +81,7 @@ fn redupif64(x: f64) f64 {...@@ -81,7 +81,7 @@ fn redupif64(x: f64) f64 {
81 t -= 0.5;81 t -= 0.5;
82 }82 }
8383
84 const u = @floatFromInt(f64, @intFromFloat(i64, t));84 const u = @as(f64, @floatFromInt(@as(i64, @intFromFloat(t))));
85 return ((x - u * DP1) - u * DP2) - t * DP3;85 return ((x - u * DP1) - u * DP2) - t * DP3;
86}86}
8787
lib/std/math/complex/cosh.zig+8-8
...@@ -26,10 +26,10 @@ fn cosh32(z: Complex(f32)) Complex(f32) {...@@ -26,10 +26,10 @@ fn cosh32(z: Complex(f32)) Complex(f32) {
26 const x = z.re;26 const x = z.re;
27 const y = z.im;27 const y = z.im;
2828
29 const hx = @bitCast(u32, x);29 const hx = @as(u32, @bitCast(x));
30 const ix = hx & 0x7fffffff;30 const ix = hx & 0x7fffffff;
3131
32 const hy = @bitCast(u32, y);32 const hy = @as(u32, @bitCast(y));
33 const iy = hy & 0x7fffffff;33 const iy = hy & 0x7fffffff;
3434
35 if (ix < 0x7f800000 and iy < 0x7f800000) {35 if (ix < 0x7f800000 and iy < 0x7f800000) {
...@@ -89,14 +89,14 @@ fn cosh64(z: Complex(f64)) Complex(f64) {...@@ -89,14 +89,14 @@ fn cosh64(z: Complex(f64)) Complex(f64) {
89 const x = z.re;89 const x = z.re;
90 const y = z.im;90 const y = z.im;
9191
92 const fx = @bitCast(u64, x);92 const fx = @as(u64, @bitCast(x));
93 const hx = @intCast(u32, fx >> 32);93 const hx = @as(u32, @intCast(fx >> 32));
94 const lx = @truncate(u32, fx);94 const lx = @as(u32, @truncate(fx));
95 const ix = hx & 0x7fffffff;95 const ix = hx & 0x7fffffff;
9696
97 const fy = @bitCast(u64, y);97 const fy = @as(u64, @bitCast(y));
98 const hy = @intCast(u32, fy >> 32);98 const hy = @as(u32, @intCast(fy >> 32));
99 const ly = @truncate(u32, fy);99 const ly = @as(u32, @truncate(fy));
100 const iy = hy & 0x7fffffff;100 const iy = hy & 0x7fffffff;
101101
102 // nearly non-exceptional case where x, y are finite102 // nearly non-exceptional case where x, y are finite
lib/std/math/complex/exp.zig+8-8
...@@ -30,13 +30,13 @@ fn exp32(z: Complex(f32)) Complex(f32) {...@@ -30,13 +30,13 @@ fn exp32(z: Complex(f32)) Complex(f32) {
30 const x = z.re;30 const x = z.re;
31 const y = z.im;31 const y = z.im;
3232
33 const hy = @bitCast(u32, y) & 0x7fffffff;33 const hy = @as(u32, @bitCast(y)) & 0x7fffffff;
34 // cexp(x + i0) = exp(x) + i034 // cexp(x + i0) = exp(x) + i0
35 if (hy == 0) {35 if (hy == 0) {
36 return Complex(f32).init(@exp(x), y);36 return Complex(f32).init(@exp(x), y);
37 }37 }
3838
39 const hx = @bitCast(u32, x);39 const hx = @as(u32, @bitCast(x));
40 // cexp(0 + iy) = cos(y) + isin(y)40 // cexp(0 + iy) = cos(y) + isin(y)
41 if ((hx & 0x7fffffff) == 0) {41 if ((hx & 0x7fffffff) == 0) {
42 return Complex(f32).init(@cos(y), @sin(y));42 return Complex(f32).init(@cos(y), @sin(y));
...@@ -75,18 +75,18 @@ fn exp64(z: Complex(f64)) Complex(f64) {...@@ -75,18 +75,18 @@ fn exp64(z: Complex(f64)) Complex(f64) {
75 const x = z.re;75 const x = z.re;
76 const y = z.im;76 const y = z.im;
7777
78 const fy = @bitCast(u64, y);78 const fy = @as(u64, @bitCast(y));
79 const hy = @intCast(u32, (fy >> 32) & 0x7fffffff);79 const hy = @as(u32, @intCast((fy >> 32) & 0x7fffffff));
80 const ly = @truncate(u32, fy);80 const ly = @as(u32, @truncate(fy));
8181
82 // cexp(x + i0) = exp(x) + i082 // cexp(x + i0) = exp(x) + i0
83 if (hy | ly == 0) {83 if (hy | ly == 0) {
84 return Complex(f64).init(@exp(x), y);84 return Complex(f64).init(@exp(x), y);
85 }85 }
8686
87 const fx = @bitCast(u64, x);87 const fx = @as(u64, @bitCast(x));
88 const hx = @intCast(u32, fx >> 32);88 const hx = @as(u32, @intCast(fx >> 32));
89 const lx = @truncate(u32, fx);89 const lx = @as(u32, @truncate(fx));
9090
91 // cexp(0 + iy) = cos(y) + isin(y)91 // cexp(0 + iy) = cos(y) + isin(y)
92 if ((hx & 0x7fffffff) | lx == 0) {92 if ((hx & 0x7fffffff) | lx == 0) {
lib/std/math/complex/ldexp.zig+12-12
...@@ -27,10 +27,10 @@ fn frexp_exp32(x: f32, expt: *i32) f32 {...@@ -27,10 +27,10 @@ fn frexp_exp32(x: f32, expt: *i32) f32 {
27 const kln2 = 162.88958740; // k * ln227 const kln2 = 162.88958740; // k * ln2
2828
29 const exp_x = @exp(x - kln2);29 const exp_x = @exp(x - kln2);
30 const hx = @bitCast(u32, exp_x);30 const hx = @as(u32, @bitCast(exp_x));
31 // TODO zig should allow this cast implicitly because it should know the value is in range31 // TODO zig should allow this cast implicitly because it should know the value is in range
32 expt.* = @intCast(i32, hx >> 23) - (0x7f + 127) + k;32 expt.* = @as(i32, @intCast(hx >> 23)) - (0x7f + 127) + k;
33 return @bitCast(f32, (hx & 0x7fffff) | ((0x7f + 127) << 23));33 return @as(f32, @bitCast((hx & 0x7fffff) | ((0x7f + 127) << 23)));
34}34}
3535
36fn ldexp_cexp32(z: Complex(f32), expt: i32) Complex(f32) {36fn ldexp_cexp32(z: Complex(f32), expt: i32) Complex(f32) {
...@@ -39,10 +39,10 @@ fn ldexp_cexp32(z: Complex(f32), expt: i32) Complex(f32) {...@@ -39,10 +39,10 @@ fn ldexp_cexp32(z: Complex(f32), expt: i32) Complex(f32) {
39 const exptf = expt + ex_expt;39 const exptf = expt + ex_expt;
4040
41 const half_expt1 = @divTrunc(exptf, 2);41 const half_expt1 = @divTrunc(exptf, 2);
42 const scale1 = @bitCast(f32, (0x7f + half_expt1) << 23);42 const scale1 = @as(f32, @bitCast((0x7f + half_expt1) << 23));
4343
44 const half_expt2 = exptf - half_expt1;44 const half_expt2 = exptf - half_expt1;
45 const scale2 = @bitCast(f32, (0x7f + half_expt2) << 23);45 const scale2 = @as(f32, @bitCast((0x7f + half_expt2) << 23));
4646
47 return Complex(f32).init(47 return Complex(f32).init(
48 @cos(z.im) * exp_x * scale1 * scale2,48 @cos(z.im) * exp_x * scale1 * scale2,
...@@ -56,14 +56,14 @@ fn frexp_exp64(x: f64, expt: *i32) f64 {...@@ -56,14 +56,14 @@ fn frexp_exp64(x: f64, expt: *i32) f64 {
5656
57 const exp_x = @exp(x - kln2);57 const exp_x = @exp(x - kln2);
5858
59 const fx = @bitCast(u64, exp_x);59 const fx = @as(u64, @bitCast(exp_x));
60 const hx = @intCast(u32, fx >> 32);60 const hx = @as(u32, @intCast(fx >> 32));
61 const lx = @truncate(u32, fx);61 const lx = @as(u32, @truncate(fx));
6262
63 expt.* = @intCast(i32, hx >> 20) - (0x3ff + 1023) + k;63 expt.* = @as(i32, @intCast(hx >> 20)) - (0x3ff + 1023) + k;
6464
65 const high_word = (hx & 0xfffff) | ((0x3ff + 1023) << 20);65 const high_word = (hx & 0xfffff) | ((0x3ff + 1023) << 20);
66 return @bitCast(f64, (@as(u64, high_word) << 32) | lx);66 return @as(f64, @bitCast((@as(u64, high_word) << 32) | lx));
67}67}
6868
69fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {69fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {
...@@ -72,10 +72,10 @@ fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {...@@ -72,10 +72,10 @@ fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {
72 const exptf = @as(i64, expt + ex_expt);72 const exptf = @as(i64, expt + ex_expt);
7373
74 const half_expt1 = @divTrunc(exptf, 2);74 const half_expt1 = @divTrunc(exptf, 2);
75 const scale1 = @bitCast(f64, (0x3ff + half_expt1) << (20 + 32));75 const scale1 = @as(f64, @bitCast((0x3ff + half_expt1) << (20 + 32)));
7676
77 const half_expt2 = exptf - half_expt1;77 const half_expt2 = exptf - half_expt1;
78 const scale2 = @bitCast(f64, (0x3ff + half_expt2) << (20 + 32));78 const scale2 = @as(f64, @bitCast((0x3ff + half_expt2) << (20 + 32)));
7979
80 return Complex(f64).init(80 return Complex(f64).init(
81 @cos(z.im) * exp_x * scale1 * scale2,81 @cos(z.im) * exp_x * scale1 * scale2,
lib/std/math/complex/sinh.zig+8-8
...@@ -26,10 +26,10 @@ fn sinh32(z: Complex(f32)) Complex(f32) {...@@ -26,10 +26,10 @@ fn sinh32(z: Complex(f32)) Complex(f32) {
26 const x = z.re;26 const x = z.re;
27 const y = z.im;27 const y = z.im;
2828
29 const hx = @bitCast(u32, x);29 const hx = @as(u32, @bitCast(x));
30 const ix = hx & 0x7fffffff;30 const ix = hx & 0x7fffffff;
3131
32 const hy = @bitCast(u32, y);32 const hy = @as(u32, @bitCast(y));
33 const iy = hy & 0x7fffffff;33 const iy = hy & 0x7fffffff;
3434
35 if (ix < 0x7f800000 and iy < 0x7f800000) {35 if (ix < 0x7f800000 and iy < 0x7f800000) {
...@@ -89,14 +89,14 @@ fn sinh64(z: Complex(f64)) Complex(f64) {...@@ -89,14 +89,14 @@ fn sinh64(z: Complex(f64)) Complex(f64) {
89 const x = z.re;89 const x = z.re;
90 const y = z.im;90 const y = z.im;
9191
92 const fx = @bitCast(u64, x);92 const fx = @as(u64, @bitCast(x));
93 const hx = @intCast(u32, fx >> 32);93 const hx = @as(u32, @intCast(fx >> 32));
94 const lx = @truncate(u32, fx);94 const lx = @as(u32, @truncate(fx));
95 const ix = hx & 0x7fffffff;95 const ix = hx & 0x7fffffff;
9696
97 const fy = @bitCast(u64, y);97 const fy = @as(u64, @bitCast(y));
98 const hy = @intCast(u32, fy >> 32);98 const hy = @as(u32, @intCast(fy >> 32));
99 const ly = @truncate(u32, fy);99 const ly = @as(u32, @truncate(fy));
100 const iy = hy & 0x7fffffff;100 const iy = hy & 0x7fffffff;
101101
102 if (ix < 0x7ff00000 and iy < 0x7ff00000) {102 if (ix < 0x7ff00000 and iy < 0x7ff00000) {
lib/std/math/complex/sqrt.zig+4-4
...@@ -58,14 +58,14 @@ fn sqrt32(z: Complex(f32)) Complex(f32) {...@@ -58,14 +58,14 @@ fn sqrt32(z: Complex(f32)) Complex(f32) {
58 if (dx >= 0) {58 if (dx >= 0) {
59 const t = @sqrt((dx + math.hypot(f64, dx, dy)) * 0.5);59 const t = @sqrt((dx + math.hypot(f64, dx, dy)) * 0.5);
60 return Complex(f32).init(60 return Complex(f32).init(
61 @floatCast(f32, t),61 @as(f32, @floatCast(t)),
62 @floatCast(f32, dy / (2.0 * t)),62 @as(f32, @floatCast(dy / (2.0 * t))),
63 );63 );
64 } else {64 } else {
65 const t = @sqrt((-dx + math.hypot(f64, dx, dy)) * 0.5);65 const t = @sqrt((-dx + math.hypot(f64, dx, dy)) * 0.5);
66 return Complex(f32).init(66 return Complex(f32).init(
67 @floatCast(f32, @fabs(y) / (2.0 * t)),67 @as(f32, @floatCast(@fabs(y) / (2.0 * t))),
68 @floatCast(f32, math.copysign(t, y)),68 @as(f32, @floatCast(math.copysign(t, y))),
69 );69 );
70 }70 }
71}71}
lib/std/math/complex/tanh.zig+6-6
...@@ -24,7 +24,7 @@ fn tanh32(z: Complex(f32)) Complex(f32) {...@@ -24,7 +24,7 @@ fn tanh32(z: Complex(f32)) Complex(f32) {
24 const x = z.re;24 const x = z.re;
25 const y = z.im;25 const y = z.im;
2626
27 const hx = @bitCast(u32, x);27 const hx = @as(u32, @bitCast(x));
28 const ix = hx & 0x7fffffff;28 const ix = hx & 0x7fffffff;
2929
30 if (ix >= 0x7f800000) {30 if (ix >= 0x7f800000) {
...@@ -32,7 +32,7 @@ fn tanh32(z: Complex(f32)) Complex(f32) {...@@ -32,7 +32,7 @@ fn tanh32(z: Complex(f32)) Complex(f32) {
32 const r = if (y == 0) y else x * y;32 const r = if (y == 0) y else x * y;
33 return Complex(f32).init(x, r);33 return Complex(f32).init(x, r);
34 }34 }
35 const xx = @bitCast(f32, hx - 0x40000000);35 const xx = @as(f32, @bitCast(hx - 0x40000000));
36 const r = if (math.isInf(y)) y else @sin(y) * @cos(y);36 const r = if (math.isInf(y)) y else @sin(y) * @cos(y);
37 return Complex(f32).init(xx, math.copysign(@as(f32, 0.0), r));37 return Complex(f32).init(xx, math.copysign(@as(f32, 0.0), r));
38 }38 }
...@@ -62,11 +62,11 @@ fn tanh64(z: Complex(f64)) Complex(f64) {...@@ -62,11 +62,11 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
62 const x = z.re;62 const x = z.re;
63 const y = z.im;63 const y = z.im;
6464
65 const fx = @bitCast(u64, x);65 const fx = @as(u64, @bitCast(x));
66 // TODO: zig should allow this conversion implicitly because it can notice that the value necessarily66 // TODO: zig should allow this conversion implicitly because it can notice that the value necessarily
67 // fits in range.67 // fits in range.
68 const hx = @intCast(u32, fx >> 32);68 const hx = @as(u32, @intCast(fx >> 32));
69 const lx = @truncate(u32, fx);69 const lx = @as(u32, @truncate(fx));
70 const ix = hx & 0x7fffffff;70 const ix = hx & 0x7fffffff;
7171
72 if (ix >= 0x7ff00000) {72 if (ix >= 0x7ff00000) {
...@@ -75,7 +75,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) {...@@ -75,7 +75,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
75 return Complex(f64).init(x, r);75 return Complex(f64).init(x, r);
76 }76 }
7777
78 const xx = @bitCast(f64, (@as(u64, hx - 0x40000000) << 32) | lx);78 const xx = @as(f64, @bitCast((@as(u64, hx - 0x40000000) << 32) | lx));
79 const r = if (math.isInf(y)) y else @sin(y) * @cos(y);79 const r = if (math.isInf(y)) y else @sin(y) * @cos(y);
80 return Complex(f64).init(xx, math.copysign(@as(f64, 0.0), r));80 return Complex(f64).init(xx, math.copysign(@as(f64, 0.0), r));
81 }81 }
lib/std/math/copysign.zig+3-3
...@@ -7,9 +7,9 @@ pub fn copysign(magnitude: anytype, sign: @TypeOf(magnitude)) @TypeOf(magnitude)...@@ -7,9 +7,9 @@ pub fn copysign(magnitude: anytype, sign: @TypeOf(magnitude)) @TypeOf(magnitude)
7 const T = @TypeOf(magnitude);7 const T = @TypeOf(magnitude);
8 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);8 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
9 const sign_bit_mask = @as(TBits, 1) << (@bitSizeOf(T) - 1);9 const sign_bit_mask = @as(TBits, 1) << (@bitSizeOf(T) - 1);
10 const mag = @bitCast(TBits, magnitude) & ~sign_bit_mask;10 const mag = @as(TBits, @bitCast(magnitude)) & ~sign_bit_mask;
11 const sgn = @bitCast(TBits, sign) & sign_bit_mask;11 const sgn = @as(TBits, @bitCast(sign)) & sign_bit_mask;
12 return @bitCast(T, mag | sgn);12 return @as(T, @bitCast(mag | sgn));
13}13}
1414
15test "math.copysign" {15test "math.copysign" {
lib/std/math/cosh.zig+5-5
...@@ -29,9 +29,9 @@ pub fn cosh(x: anytype) @TypeOf(x) {...@@ -29,9 +29,9 @@ pub fn cosh(x: anytype) @TypeOf(x) {
29// = 1 + 0.5 * (exp(x) - 1) * (exp(x) - 1) / exp(x)29// = 1 + 0.5 * (exp(x) - 1) * (exp(x) - 1) / exp(x)
30// = 1 + (x * x) / 2 + o(x^4)30// = 1 + (x * x) / 2 + o(x^4)
31fn cosh32(x: f32) f32 {31fn cosh32(x: f32) f32 {
32 const u = @bitCast(u32, x);32 const u = @as(u32, @bitCast(x));
33 const ux = u & 0x7FFFFFFF;33 const ux = u & 0x7FFFFFFF;
34 const ax = @bitCast(f32, ux);34 const ax = @as(f32, @bitCast(ux));
3535
36 // |x| < log(2)36 // |x| < log(2)
37 if (ux < 0x3F317217) {37 if (ux < 0x3F317217) {
...@@ -54,9 +54,9 @@ fn cosh32(x: f32) f32 {...@@ -54,9 +54,9 @@ fn cosh32(x: f32) f32 {
54}54}
5555
56fn cosh64(x: f64) f64 {56fn cosh64(x: f64) f64 {
57 const u = @bitCast(u64, x);57 const u = @as(u64, @bitCast(x));
58 const w = @intCast(u32, u >> 32) & (maxInt(u32) >> 1);58 const w = @as(u32, @intCast(u >> 32)) & (maxInt(u32) >> 1);
59 const ax = @bitCast(f64, u & (maxInt(u64) >> 1));59 const ax = @as(f64, @bitCast(u & (maxInt(u64) >> 1)));
6060
61 // TODO: Shouldn't need this explicit check.61 // TODO: Shouldn't need this explicit check.
62 if (x == 0.0) {62 if (x == 0.0) {
lib/std/math/expm1.zig+12-12
...@@ -38,7 +38,7 @@ fn expm1_32(x_: f32) f32 {...@@ -38,7 +38,7 @@ fn expm1_32(x_: f32) f32 {
38 const Q2: f32 = 1.5807170421e-3;38 const Q2: f32 = 1.5807170421e-3;
3939
40 var x = x_;40 var x = x_;
41 const ux = @bitCast(u32, x);41 const ux = @as(u32, @bitCast(x));
42 const hx = ux & 0x7FFFFFFF;42 const hx = ux & 0x7FFFFFFF;
43 const sign = hx >> 31;43 const sign = hx >> 31;
4444
...@@ -88,8 +88,8 @@ fn expm1_32(x_: f32) f32 {...@@ -88,8 +88,8 @@ fn expm1_32(x_: f32) f32 {
88 kf += 0.5;88 kf += 0.5;
89 }89 }
9090
91 k = @intFromFloat(i32, kf);91 k = @as(i32, @intFromFloat(kf));
92 const t = @floatFromInt(f32, k);92 const t = @as(f32, @floatFromInt(k));
93 hi = x - t * ln2_hi;93 hi = x - t * ln2_hi;
94 lo = t * ln2_lo;94 lo = t * ln2_lo;
95 }95 }
...@@ -133,7 +133,7 @@ fn expm1_32(x_: f32) f32 {...@@ -133,7 +133,7 @@ fn expm1_32(x_: f32) f32 {
133 }133 }
134 }134 }
135135
136 const twopk = @bitCast(f32, @intCast(u32, (0x7F +% k) << 23));136 const twopk = @as(f32, @bitCast(@as(u32, @intCast((0x7F +% k) << 23))));
137137
138 if (k < 0 or k > 56) {138 if (k < 0 or k > 56) {
139 var y = x - e + 1.0;139 var y = x - e + 1.0;
...@@ -146,7 +146,7 @@ fn expm1_32(x_: f32) f32 {...@@ -146,7 +146,7 @@ fn expm1_32(x_: f32) f32 {
146 return y - 1.0;146 return y - 1.0;
147 }147 }
148148
149 const uf = @bitCast(f32, @intCast(u32, 0x7F -% k) << 23);149 const uf = @as(f32, @bitCast(@as(u32, @intCast(0x7F -% k)) << 23));
150 if (k < 23) {150 if (k < 23) {
151 return (x - e + (1 - uf)) * twopk;151 return (x - e + (1 - uf)) * twopk;
152 } else {152 } else {
...@@ -169,8 +169,8 @@ fn expm1_64(x_: f64) f64 {...@@ -169,8 +169,8 @@ fn expm1_64(x_: f64) f64 {
169 const Q5: f64 = -2.01099218183624371326e-07;169 const Q5: f64 = -2.01099218183624371326e-07;
170170
171 var x = x_;171 var x = x_;
172 const ux = @bitCast(u64, x);172 const ux = @as(u64, @bitCast(x));
173 const hx = @intCast(u32, ux >> 32) & 0x7FFFFFFF;173 const hx = @as(u32, @intCast(ux >> 32)) & 0x7FFFFFFF;
174 const sign = ux >> 63;174 const sign = ux >> 63;
175175
176 if (math.isNegativeInf(x)) {176 if (math.isNegativeInf(x)) {
...@@ -219,8 +219,8 @@ fn expm1_64(x_: f64) f64 {...@@ -219,8 +219,8 @@ fn expm1_64(x_: f64) f64 {
219 kf += 0.5;219 kf += 0.5;
220 }220 }
221221
222 k = @intFromFloat(i32, kf);222 k = @as(i32, @intFromFloat(kf));
223 const t = @floatFromInt(f64, k);223 const t = @as(f64, @floatFromInt(k));
224 hi = x - t * ln2_hi;224 hi = x - t * ln2_hi;
225 lo = t * ln2_lo;225 lo = t * ln2_lo;
226 }226 }
...@@ -231,7 +231,7 @@ fn expm1_64(x_: f64) f64 {...@@ -231,7 +231,7 @@ fn expm1_64(x_: f64) f64 {
231 // |x| < 2^(-54)231 // |x| < 2^(-54)
232 else if (hx < 0x3C900000) {232 else if (hx < 0x3C900000) {
233 if (hx < 0x00100000) {233 if (hx < 0x00100000) {
234 math.doNotOptimizeAway(@floatCast(f32, x));234 math.doNotOptimizeAway(@as(f32, @floatCast(x)));
235 }235 }
236 return x;236 return x;
237 } else {237 } else {
...@@ -264,7 +264,7 @@ fn expm1_64(x_: f64) f64 {...@@ -264,7 +264,7 @@ fn expm1_64(x_: f64) f64 {
264 }264 }
265 }265 }
266266
267 const twopk = @bitCast(f64, @intCast(u64, 0x3FF +% k) << 52);267 const twopk = @as(f64, @bitCast(@as(u64, @intCast(0x3FF +% k)) << 52));
268268
269 if (k < 0 or k > 56) {269 if (k < 0 or k > 56) {
270 var y = x - e + 1.0;270 var y = x - e + 1.0;
...@@ -277,7 +277,7 @@ fn expm1_64(x_: f64) f64 {...@@ -277,7 +277,7 @@ fn expm1_64(x_: f64) f64 {
277 return y - 1.0;277 return y - 1.0;
278 }278 }
279279
280 const uf = @bitCast(f64, @intCast(u64, 0x3FF -% k) << 52);280 const uf = @as(f64, @bitCast(@as(u64, @intCast(0x3FF -% k)) << 52));
281 if (k < 20) {281 if (k < 20) {
282 return (x - e + (1 - uf)) * twopk;282 return (x - e + (1 - uf)) * twopk;
283 } else {283 } else {
lib/std/math/expo2.zig+2-2
...@@ -21,7 +21,7 @@ fn expo2f(x: f32) f32 {...@@ -21,7 +21,7 @@ fn expo2f(x: f32) f32 {
21 const kln2 = 0x1.45C778p+7;21 const kln2 = 0x1.45C778p+7;
2222
23 const u = (0x7F + k / 2) << 23;23 const u = (0x7F + k / 2) << 23;
24 const scale = @bitCast(f32, u);24 const scale = @as(f32, @bitCast(u));
25 return @exp(x - kln2) * scale * scale;25 return @exp(x - kln2) * scale * scale;
26}26}
2727
...@@ -30,6 +30,6 @@ fn expo2d(x: f64) f64 {...@@ -30,6 +30,6 @@ fn expo2d(x: f64) f64 {
30 const kln2 = 0x1.62066151ADD8BP+10;30 const kln2 = 0x1.62066151ADD8BP+10;
3131
32 const u = (0x3FF + k / 2) << 20;32 const u = (0x3FF + k / 2) << 20;
33 const scale = @bitCast(f64, @as(u64, u) << 32);33 const scale = @as(f64, @bitCast(@as(u64, u) << 32));
34 return @exp(x - kln2) * scale * scale;34 return @exp(x - kln2) * scale * scale;
35}35}
lib/std/math/float.zig+1-1
...@@ -11,7 +11,7 @@ inline fn mantissaOne(comptime T: type) comptime_int {...@@ -11,7 +11,7 @@ inline fn mantissaOne(comptime T: type) comptime_int {
11inline fn reconstructFloat(comptime T: type, comptime exponent: comptime_int, comptime mantissa: comptime_int) T {11inline fn reconstructFloat(comptime T: type, comptime exponent: comptime_int, comptime mantissa: comptime_int) T {
12 const TBits = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = @bitSizeOf(T) } });12 const TBits = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = @bitSizeOf(T) } });
13 const biased_exponent = @as(TBits, exponent + floatExponentMax(T));13 const biased_exponent = @as(TBits, exponent + floatExponentMax(T));
14 return @bitCast(T, (biased_exponent << floatMantissaBits(T)) | @as(TBits, mantissa));14 return @as(T, @bitCast((biased_exponent << floatMantissaBits(T)) | @as(TBits, mantissa)));
15}15}
1616
17/// Returns the number of bits in the exponent of floating point type T.17/// Returns the number of bits in the exponent of floating point type T.
lib/std/math/frexp.zig+9-9
...@@ -38,8 +38,8 @@ pub fn frexp(x: anytype) Frexp(@TypeOf(x)) {...@@ -38,8 +38,8 @@ pub fn frexp(x: anytype) Frexp(@TypeOf(x)) {
38fn frexp32(x: f32) Frexp(f32) {38fn frexp32(x: f32) Frexp(f32) {
39 var result: Frexp(f32) = undefined;39 var result: Frexp(f32) = undefined;
4040
41 var y = @bitCast(u32, x);41 var y = @as(u32, @bitCast(x));
42 const e = @intCast(i32, y >> 23) & 0xFF;42 const e = @as(i32, @intCast(y >> 23)) & 0xFF;
4343
44 if (e == 0) {44 if (e == 0) {
45 if (x != 0) {45 if (x != 0) {
...@@ -68,15 +68,15 @@ fn frexp32(x: f32) Frexp(f32) {...@@ -68,15 +68,15 @@ fn frexp32(x: f32) Frexp(f32) {
68 result.exponent = e - 0x7E;68 result.exponent = e - 0x7E;
69 y &= 0x807FFFFF;69 y &= 0x807FFFFF;
70 y |= 0x3F000000;70 y |= 0x3F000000;
71 result.significand = @bitCast(f32, y);71 result.significand = @as(f32, @bitCast(y));
72 return result;72 return result;
73}73}
7474
75fn frexp64(x: f64) Frexp(f64) {75fn frexp64(x: f64) Frexp(f64) {
76 var result: Frexp(f64) = undefined;76 var result: Frexp(f64) = undefined;
7777
78 var y = @bitCast(u64, x);78 var y = @as(u64, @bitCast(x));
79 const e = @intCast(i32, y >> 52) & 0x7FF;79 const e = @as(i32, @intCast(y >> 52)) & 0x7FF;
8080
81 if (e == 0) {81 if (e == 0) {
82 if (x != 0) {82 if (x != 0) {
...@@ -105,15 +105,15 @@ fn frexp64(x: f64) Frexp(f64) {...@@ -105,15 +105,15 @@ fn frexp64(x: f64) Frexp(f64) {
105 result.exponent = e - 0x3FE;105 result.exponent = e - 0x3FE;
106 y &= 0x800FFFFFFFFFFFFF;106 y &= 0x800FFFFFFFFFFFFF;
107 y |= 0x3FE0000000000000;107 y |= 0x3FE0000000000000;
108 result.significand = @bitCast(f64, y);108 result.significand = @as(f64, @bitCast(y));
109 return result;109 return result;
110}110}
111111
112fn frexp128(x: f128) Frexp(f128) {112fn frexp128(x: f128) Frexp(f128) {
113 var result: Frexp(f128) = undefined;113 var result: Frexp(f128) = undefined;
114114
115 var y = @bitCast(u128, x);115 var y = @as(u128, @bitCast(x));
116 const e = @intCast(i32, y >> 112) & 0x7FFF;116 const e = @as(i32, @intCast(y >> 112)) & 0x7FFF;
117117
118 if (e == 0) {118 if (e == 0) {
119 if (x != 0) {119 if (x != 0) {
...@@ -142,7 +142,7 @@ fn frexp128(x: f128) Frexp(f128) {...@@ -142,7 +142,7 @@ fn frexp128(x: f128) Frexp(f128) {
142 result.exponent = e - 0x3FFE;142 result.exponent = e - 0x3FFE;
143 y &= 0x8000FFFFFFFFFFFFFFFFFFFFFFFFFFFF;143 y &= 0x8000FFFFFFFFFFFFFFFFFFFFFFFFFFFF;
144 y |= 0x3FFE0000000000000000000000000000;144 y |= 0x3FFE0000000000000000000000000000;
145 result.significand = @bitCast(f128, y);145 result.significand = @as(f128, @bitCast(y));
146 return result;146 return result;
147}147}
148148
lib/std/math/hypot.zig+9-9
...@@ -25,8 +25,8 @@ pub fn hypot(comptime T: type, x: T, y: T) T {...@@ -25,8 +25,8 @@ pub fn hypot(comptime T: type, x: T, y: T) T {
25}25}
2626
27fn hypot32(x: f32, y: f32) f32 {27fn hypot32(x: f32, y: f32) f32 {
28 var ux = @bitCast(u32, x);28 var ux = @as(u32, @bitCast(x));
29 var uy = @bitCast(u32, y);29 var uy = @as(u32, @bitCast(y));
3030
31 ux &= maxInt(u32) >> 1;31 ux &= maxInt(u32) >> 1;
32 uy &= maxInt(u32) >> 1;32 uy &= maxInt(u32) >> 1;
...@@ -36,8 +36,8 @@ fn hypot32(x: f32, y: f32) f32 {...@@ -36,8 +36,8 @@ fn hypot32(x: f32, y: f32) f32 {
36 uy = tmp;36 uy = tmp;
37 }37 }
3838
39 var xx = @bitCast(f32, ux);39 var xx = @as(f32, @bitCast(ux));
40 var yy = @bitCast(f32, uy);40 var yy = @as(f32, @bitCast(uy));
41 if (uy == 0xFF << 23) {41 if (uy == 0xFF << 23) {
42 return yy;42 return yy;
43 }43 }
...@@ -56,7 +56,7 @@ fn hypot32(x: f32, y: f32) f32 {...@@ -56,7 +56,7 @@ fn hypot32(x: f32, y: f32) f32 {
56 yy *= 0x1.0p-90;56 yy *= 0x1.0p-90;
57 }57 }
5858
59 return z * @sqrt(@floatCast(f32, @as(f64, x) * x + @as(f64, y) * y));59 return z * @sqrt(@as(f32, @floatCast(@as(f64, x) * x + @as(f64, y) * y)));
60}60}
6161
62fn sq(hi: *f64, lo: *f64, x: f64) void {62fn sq(hi: *f64, lo: *f64, x: f64) void {
...@@ -69,8 +69,8 @@ fn sq(hi: *f64, lo: *f64, x: f64) void {...@@ -69,8 +69,8 @@ fn sq(hi: *f64, lo: *f64, x: f64) void {
69}69}
7070
71fn hypot64(x: f64, y: f64) f64 {71fn hypot64(x: f64, y: f64) f64 {
72 var ux = @bitCast(u64, x);72 var ux = @as(u64, @bitCast(x));
73 var uy = @bitCast(u64, y);73 var uy = @as(u64, @bitCast(y));
7474
75 ux &= maxInt(u64) >> 1;75 ux &= maxInt(u64) >> 1;
76 uy &= maxInt(u64) >> 1;76 uy &= maxInt(u64) >> 1;
...@@ -82,8 +82,8 @@ fn hypot64(x: f64, y: f64) f64 {...@@ -82,8 +82,8 @@ fn hypot64(x: f64, y: f64) f64 {
8282
83 const ex = ux >> 52;83 const ex = ux >> 52;
84 const ey = uy >> 52;84 const ey = uy >> 52;
85 var xx = @bitCast(f64, ux);85 var xx = @as(f64, @bitCast(ux));
86 var yy = @bitCast(f64, uy);86 var yy = @as(f64, @bitCast(uy));
8787
88 // hypot(inf, nan) == inf88 // hypot(inf, nan) == inf
89 if (ey == 0x7FF) {89 if (ey == 0x7FF) {
lib/std/math/ilogb.zig+4-4
...@@ -38,8 +38,8 @@ fn ilogbX(comptime T: type, x: T) i32 {...@@ -38,8 +38,8 @@ fn ilogbX(comptime T: type, x: T) i32 {
3838
39 const absMask = signBit - 1;39 const absMask = signBit - 1;
4040
41 var u = @bitCast(Z, x) & absMask;41 var u = @as(Z, @bitCast(x)) & absMask;
42 var e = @intCast(i32, u >> significandBits);42 var e = @as(i32, @intCast(u >> significandBits));
4343
44 if (e == 0) {44 if (e == 0) {
45 if (u == 0) {45 if (u == 0) {
...@@ -49,12 +49,12 @@ fn ilogbX(comptime T: type, x: T) i32 {...@@ -49,12 +49,12 @@ fn ilogbX(comptime T: type, x: T) i32 {
4949
50 // offset sign bit, exponent bits, and integer bit (if present) + bias50 // offset sign bit, exponent bits, and integer bit (if present) + bias
51 const offset = 1 + exponentBits + @as(comptime_int, @intFromBool(T == f80)) - exponentBias;51 const offset = 1 + exponentBits + @as(comptime_int, @intFromBool(T == f80)) - exponentBias;
52 return offset - @intCast(i32, @clz(u));52 return offset - @as(i32, @intCast(@clz(u)));
53 }53 }
5454
55 if (e == maxExponent) {55 if (e == maxExponent) {
56 math.raiseInvalid();56 math.raiseInvalid();
57 if (u > @bitCast(Z, math.inf(T))) {57 if (u > @as(Z, @bitCast(math.inf(T)))) {
58 return fp_ilogbnan; // u is a NaN58 return fp_ilogbnan; // u is a NaN
59 } else return maxInt(i32);59 } else return maxInt(i32);
60 }60 }
lib/std/math/isfinite.zig+1-1
...@@ -7,7 +7,7 @@ pub fn isFinite(x: anytype) bool {...@@ -7,7 +7,7 @@ pub fn isFinite(x: anytype) bool {
7 const T = @TypeOf(x);7 const T = @TypeOf(x);
8 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);8 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
9 const remove_sign = ~@as(TBits, 0) >> 1;9 const remove_sign = ~@as(TBits, 0) >> 1;
10 return @bitCast(TBits, x) & remove_sign < @bitCast(TBits, math.inf(T));10 return @as(TBits, @bitCast(x)) & remove_sign < @as(TBits, @bitCast(math.inf(T)));
11}11}
1212
13test "math.isFinite" {13test "math.isFinite" {
lib/std/math/isinf.zig+1-1
...@@ -7,7 +7,7 @@ pub inline fn isInf(x: anytype) bool {...@@ -7,7 +7,7 @@ pub inline fn isInf(x: anytype) bool {
7 const T = @TypeOf(x);7 const T = @TypeOf(x);
8 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);8 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
9 const remove_sign = ~@as(TBits, 0) >> 1;9 const remove_sign = ~@as(TBits, 0) >> 1;
10 return @bitCast(TBits, x) & remove_sign == @bitCast(TBits, math.inf(T));10 return @as(TBits, @bitCast(x)) & remove_sign == @as(TBits, @bitCast(math.inf(T)));
11}11}
1212
13/// Returns whether x is an infinity with a positive sign.13/// Returns whether x is an infinity with a positive sign.
lib/std/math/isnormal.zig+3-3
...@@ -15,7 +15,7 @@ pub fn isNormal(x: anytype) bool {...@@ -15,7 +15,7 @@ pub fn isNormal(x: anytype) bool {
15 // The sign bit is removed because all ones would overflow into it.15 // The sign bit is removed because all ones would overflow into it.
16 // For f80, even though it has an explicit integer part stored,16 // For f80, even though it has an explicit integer part stored,
17 // the exponent effectively takes priority if mismatching.17 // the exponent effectively takes priority if mismatching.
18 const value = @bitCast(TBits, x) +% increment_exp;18 const value = @as(TBits, @bitCast(x)) +% increment_exp;
19 return value & remove_sign >= (increment_exp << 1);19 return value & remove_sign >= (increment_exp << 1);
20}20}
2121
...@@ -35,7 +35,7 @@ test "math.isNormal" {...@@ -35,7 +35,7 @@ test "math.isNormal" {
35 try expect(!isNormal(@as(T, math.floatTrueMin(T))));35 try expect(!isNormal(@as(T, math.floatTrueMin(T))));
3636
37 // largest subnormal37 // largest subnormal
38 try expect(!isNormal(@bitCast(T, ~(~@as(TBits, 0) << math.floatFractionalBits(T)))));38 try expect(!isNormal(@as(T, @bitCast(~(~@as(TBits, 0) << math.floatFractionalBits(T))))));
3939
40 // non-finite numbers40 // non-finite numbers
41 try expect(!isNormal(-math.inf(T)));41 try expect(!isNormal(-math.inf(T)));
...@@ -43,6 +43,6 @@ test "math.isNormal" {...@@ -43,6 +43,6 @@ test "math.isNormal" {
43 try expect(!isNormal(math.nan(T)));43 try expect(!isNormal(math.nan(T)));
4444
45 // overflow edge-case (described in implementation, also see #10133)45 // overflow edge-case (described in implementation, also see #10133)
46 try expect(!isNormal(@bitCast(T, ~@as(TBits, 0))));46 try expect(!isNormal(@as(T, @bitCast(~@as(TBits, 0)))));
47 }47 }
48}48}
lib/std/math/ldexp.zig+15-15
...@@ -16,53 +16,53 @@ pub fn ldexp(x: anytype, n: i32) @TypeOf(x) {...@@ -16,53 +16,53 @@ pub fn ldexp(x: anytype, n: i32) @TypeOf(x) {
16 const max_biased_exponent = 2 * math.floatExponentMax(T);16 const max_biased_exponent = 2 * math.floatExponentMax(T);
17 const mantissa_mask = @as(TBits, (1 << mantissa_bits) - 1);17 const mantissa_mask = @as(TBits, (1 << mantissa_bits) - 1);
1818
19 const repr = @bitCast(TBits, x);19 const repr = @as(TBits, @bitCast(x));
20 const sign_bit = repr & (1 << (exponent_bits + mantissa_bits));20 const sign_bit = repr & (1 << (exponent_bits + mantissa_bits));
2121
22 if (math.isNan(x) or !math.isFinite(x))22 if (math.isNan(x) or !math.isFinite(x))
23 return x;23 return x;
2424
25 var exponent: i32 = @intCast(i32, (repr << 1) >> (mantissa_bits + 1));25 var exponent: i32 = @as(i32, @intCast((repr << 1) >> (mantissa_bits + 1)));
26 if (exponent == 0)26 if (exponent == 0)
27 exponent += (@as(i32, exponent_bits) + @intFromBool(T == f80)) - @clz(repr << 1);27 exponent += (@as(i32, exponent_bits) + @intFromBool(T == f80)) - @clz(repr << 1);
2828
29 if (n >= 0) {29 if (n >= 0) {
30 if (n > max_biased_exponent - exponent) {30 if (n > max_biased_exponent - exponent) {
31 // Overflow. Return +/- inf31 // Overflow. Return +/- inf
32 return @bitCast(T, @bitCast(TBits, math.inf(T)) | sign_bit);32 return @as(T, @bitCast(@as(TBits, @bitCast(math.inf(T))) | sign_bit));
33 } else if (exponent + n <= 0) {33 } else if (exponent + n <= 0) {
34 // Result is subnormal34 // Result is subnormal
35 return @bitCast(T, (repr << @intCast(Log2Int(TBits), n)) | sign_bit);35 return @as(T, @bitCast((repr << @as(Log2Int(TBits), @intCast(n))) | sign_bit));
36 } else if (exponent <= 0) {36 } else if (exponent <= 0) {
37 // Result is normal, but needs shifting37 // Result is normal, but needs shifting
38 var result = @intCast(TBits, n + exponent) << mantissa_bits;38 var result = @as(TBits, @intCast(n + exponent)) << mantissa_bits;
39 result |= (repr << @intCast(Log2Int(TBits), 1 - exponent)) & mantissa_mask;39 result |= (repr << @as(Log2Int(TBits), @intCast(1 - exponent))) & mantissa_mask;
40 return @bitCast(T, result | sign_bit);40 return @as(T, @bitCast(result | sign_bit));
41 }41 }
4242
43 // Result needs no shifting43 // Result needs no shifting
44 return @bitCast(T, repr + (@intCast(TBits, n) << mantissa_bits));44 return @as(T, @bitCast(repr + (@as(TBits, @intCast(n)) << mantissa_bits)));
45 } else {45 } else {
46 if (n <= -exponent) {46 if (n <= -exponent) {
47 if (n < -(mantissa_bits + exponent))47 if (n < -(mantissa_bits + exponent))
48 return @bitCast(T, sign_bit); // Severe underflow. Return +/- 048 return @as(T, @bitCast(sign_bit)); // Severe underflow. Return +/- 0
4949
50 // Result underflowed, we need to shift and round50 // Result underflowed, we need to shift and round
51 const shift = @intCast(Log2Int(TBits), @min(-n, -(exponent + n) + 1));51 const shift = @as(Log2Int(TBits), @intCast(@min(-n, -(exponent + n) + 1)));
52 const exact_tie: bool = @ctz(repr) == shift - 1;52 const exact_tie: bool = @ctz(repr) == shift - 1;
53 var result = repr & mantissa_mask;53 var result = repr & mantissa_mask;
5454
55 if (T != f80) // Include integer bit55 if (T != f80) // Include integer bit
56 result |= @as(TBits, @intFromBool(exponent > 0)) << fractional_bits;56 result |= @as(TBits, @intFromBool(exponent > 0)) << fractional_bits;
57 result = @intCast(TBits, (result >> (shift - 1)));57 result = @as(TBits, @intCast((result >> (shift - 1))));
5858
59 // Round result, including round-to-even for exact ties59 // Round result, including round-to-even for exact ties
60 result = ((result + 1) >> 1) & ~@as(TBits, @intFromBool(exact_tie));60 result = ((result + 1) >> 1) & ~@as(TBits, @intFromBool(exact_tie));
61 return @bitCast(T, result | sign_bit);61 return @as(T, @bitCast(result | sign_bit));
62 }62 }
6363
64 // Result is exact, and needs no shifting64 // Result is exact, and needs no shifting
65 return @bitCast(T, repr - (@intCast(TBits, -n) << mantissa_bits));65 return @as(T, @bitCast(repr - (@as(TBits, @intCast(-n)) << mantissa_bits)));
66 }66 }
67}67}
6868
...@@ -105,8 +105,8 @@ test "math.ldexp" {...@@ -105,8 +105,8 @@ test "math.ldexp" {
105 // Multiplications might flush the denormals to zero, esp. at105 // Multiplications might flush the denormals to zero, esp. at
106 // runtime, so we manually construct the constants here instead.106 // runtime, so we manually construct the constants here instead.
107 const Z = std.meta.Int(.unsigned, @bitSizeOf(T));107 const Z = std.meta.Int(.unsigned, @bitSizeOf(T));
108 const EightTimesTrueMin = @bitCast(T, @as(Z, 8));108 const EightTimesTrueMin = @as(T, @bitCast(@as(Z, 8)));
109 const TwoTimesTrueMin = @bitCast(T, @as(Z, 2));109 const TwoTimesTrueMin = @as(T, @bitCast(@as(Z, 2)));
110110
111 // subnormals -> subnormals111 // subnormals -> subnormals
112 try expect(ldexp(math.floatTrueMin(T), 3) == EightTimesTrueMin);112 try expect(ldexp(math.floatTrueMin(T), 3) == EightTimesTrueMin);
lib/std/math/log.zig+2-2
...@@ -30,12 +30,12 @@ pub fn log(comptime T: type, base: T, x: T) T {...@@ -30,12 +30,12 @@ pub fn log(comptime T: type, base: T, x: T) T {
30 // TODO implement integer log without using float math30 // TODO implement integer log without using float math
31 .Int => |IntType| switch (IntType.signedness) {31 .Int => |IntType| switch (IntType.signedness) {
32 .signed => @compileError("log not implemented for signed integers"),32 .signed => @compileError("log not implemented for signed integers"),
33 .unsigned => return @intFromFloat(T, @floor(@log(@floatFromInt(f64, x)) / @log(float_base))),33 .unsigned => return @as(T, @intFromFloat(@floor(@log(@as(f64, @floatFromInt(x))) / @log(float_base)))),
34 },34 },
3535
36 .Float => {36 .Float => {
37 switch (T) {37 switch (T) {
38 f32 => return @floatCast(f32, @log(@as(f64, x)) / @log(float_base)),38 f32 => return @as(f32, @floatCast(@log(@as(f64, x)) / @log(float_base))),
39 f64 => return @log(x) / @log(float_base),39 f64 => return @log(x) / @log(float_base),
40 else => @compileError("log not implemented for " ++ @typeName(T)),40 else => @compileError("log not implemented for " ++ @typeName(T)),
41 }41 }
lib/std/math/log10.zig+7-7
...@@ -49,9 +49,9 @@ pub fn log10_int(x: anytype) Log2Int(@TypeOf(x)) {...@@ -49,9 +49,9 @@ pub fn log10_int(x: anytype) Log2Int(@TypeOf(x)) {
49 const bit_size = @typeInfo(T).Int.bits;49 const bit_size = @typeInfo(T).Int.bits;
5050
51 if (bit_size <= 8) {51 if (bit_size <= 8) {
52 return @intCast(OutT, log10_int_u8(x));52 return @as(OutT, @intCast(log10_int_u8(x)));
53 } else if (bit_size <= 16) {53 } else if (bit_size <= 16) {
54 return @intCast(OutT, less_than_5(x));54 return @as(OutT, @intCast(less_than_5(x)));
55 }55 }
5656
57 var val = x;57 var val = x;
...@@ -71,7 +71,7 @@ pub fn log10_int(x: anytype) Log2Int(@TypeOf(x)) {...@@ -71,7 +71,7 @@ pub fn log10_int(x: anytype) Log2Int(@TypeOf(x)) {
71 log += 5;71 log += 5;
72 }72 }
7373
74 return @intCast(OutT, log + less_than_5(@intCast(u32, val)));74 return @as(OutT, @intCast(log + less_than_5(@as(u32, @intCast(val)))));
75}75}
7676
77fn pow10(comptime y: comptime_int) comptime_int {77fn pow10(comptime y: comptime_int) comptime_int {
...@@ -134,7 +134,7 @@ inline fn less_than_5(x: u32) u32 {...@@ -134,7 +134,7 @@ inline fn less_than_5(x: u32) u32 {
134}134}
135135
136fn oldlog10(x: anytype) u8 {136fn oldlog10(x: anytype) u8 {
137 return @intFromFloat(u8, @log10(@floatFromInt(f64, x)));137 return @as(u8, @intFromFloat(@log10(@as(f64, @floatFromInt(x)))));
138}138}
139139
140test "oldlog10 doesn't work" {140test "oldlog10 doesn't work" {
...@@ -158,7 +158,7 @@ test "log10_int vs old implementation" {...@@ -158,7 +158,7 @@ test "log10_int vs old implementation" {
158 inline for (int_types) |T| {158 inline for (int_types) |T| {
159 const last = @min(maxInt(T), 100_000);159 const last = @min(maxInt(T), 100_000);
160 for (1..last) |i| {160 for (1..last) |i| {
161 const x = @intCast(T, i);161 const x = @as(T, @intCast(i));
162 try testing.expectEqual(oldlog10(x), log10_int(x));162 try testing.expectEqual(oldlog10(x), log10_int(x));
163 }163 }
164164
...@@ -185,10 +185,10 @@ test "log10_int close to powers of 10" {...@@ -185,10 +185,10 @@ test "log10_int close to powers of 10" {
185 try testing.expectEqual(expected_max_ilog, log10_int(max_val));185 try testing.expectEqual(expected_max_ilog, log10_int(max_val));
186186
187 for (0..(expected_max_ilog + 1)) |idx| {187 for (0..(expected_max_ilog + 1)) |idx| {
188 const i = @intCast(T, idx);188 const i = @as(T, @intCast(idx));
189 const p: T = try math.powi(T, 10, i);189 const p: T = try math.powi(T, 10, i);
190190
191 const b = @intCast(Log2Int(T), i);191 const b = @as(Log2Int(T), @intCast(i));
192192
193 if (p >= 10) {193 if (p >= 10) {
194 try testing.expectEqual(b - 1, log10_int(p - 9));194 try testing.expectEqual(b - 1, log10_int(p - 9));
lib/std/math/log1p.zig+12-12
...@@ -33,7 +33,7 @@ fn log1p_32(x: f32) f32 {...@@ -33,7 +33,7 @@ fn log1p_32(x: f32) f32 {
33 const Lg3: f32 = 0x91e9ee.0p-25;33 const Lg3: f32 = 0x91e9ee.0p-25;
34 const Lg4: f32 = 0xf89e26.0p-26;34 const Lg4: f32 = 0xf89e26.0p-26;
3535
36 const u = @bitCast(u32, x);36 const u = @as(u32, @bitCast(x));
37 var ix = u;37 var ix = u;
38 var k: i32 = 1;38 var k: i32 = 1;
39 var f: f32 = undefined;39 var f: f32 = undefined;
...@@ -72,9 +72,9 @@ fn log1p_32(x: f32) f32 {...@@ -72,9 +72,9 @@ fn log1p_32(x: f32) f32 {
7272
73 if (k != 0) {73 if (k != 0) {
74 const uf = 1 + x;74 const uf = 1 + x;
75 var iu = @bitCast(u32, uf);75 var iu = @as(u32, @bitCast(uf));
76 iu += 0x3F800000 - 0x3F3504F3;76 iu += 0x3F800000 - 0x3F3504F3;
77 k = @intCast(i32, iu >> 23) - 0x7F;77 k = @as(i32, @intCast(iu >> 23)) - 0x7F;
7878
79 // correction to avoid underflow in c / u79 // correction to avoid underflow in c / u
80 if (k < 25) {80 if (k < 25) {
...@@ -86,7 +86,7 @@ fn log1p_32(x: f32) f32 {...@@ -86,7 +86,7 @@ fn log1p_32(x: f32) f32 {
8686
87 // u into [sqrt(2)/2, sqrt(2)]87 // u into [sqrt(2)/2, sqrt(2)]
88 iu = (iu & 0x007FFFFF) + 0x3F3504F3;88 iu = (iu & 0x007FFFFF) + 0x3F3504F3;
89 f = @bitCast(f32, iu) - 1;89 f = @as(f32, @bitCast(iu)) - 1;
90 }90 }
9191
92 const s = f / (2.0 + f);92 const s = f / (2.0 + f);
...@@ -96,7 +96,7 @@ fn log1p_32(x: f32) f32 {...@@ -96,7 +96,7 @@ fn log1p_32(x: f32) f32 {
96 const t2 = z * (Lg1 + w * Lg3);96 const t2 = z * (Lg1 + w * Lg3);
97 const R = t2 + t1;97 const R = t2 + t1;
98 const hfsq = 0.5 * f * f;98 const hfsq = 0.5 * f * f;
99 const dk = @floatFromInt(f32, k);99 const dk = @as(f32, @floatFromInt(k));
100100
101 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;101 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
102}102}
...@@ -112,8 +112,8 @@ fn log1p_64(x: f64) f64 {...@@ -112,8 +112,8 @@ fn log1p_64(x: f64) f64 {
112 const Lg6: f64 = 1.531383769920937332e-01;112 const Lg6: f64 = 1.531383769920937332e-01;
113 const Lg7: f64 = 1.479819860511658591e-01;113 const Lg7: f64 = 1.479819860511658591e-01;
114114
115 var ix = @bitCast(u64, x);115 var ix = @as(u64, @bitCast(x));
116 var hx = @intCast(u32, ix >> 32);116 var hx = @as(u32, @intCast(ix >> 32));
117 var k: i32 = 1;117 var k: i32 = 1;
118 var c: f64 = undefined;118 var c: f64 = undefined;
119 var f: f64 = undefined;119 var f: f64 = undefined;
...@@ -150,10 +150,10 @@ fn log1p_64(x: f64) f64 {...@@ -150,10 +150,10 @@ fn log1p_64(x: f64) f64 {
150150
151 if (k != 0) {151 if (k != 0) {
152 const uf = 1 + x;152 const uf = 1 + x;
153 const hu = @bitCast(u64, uf);153 const hu = @as(u64, @bitCast(uf));
154 var iu = @intCast(u32, hu >> 32);154 var iu = @as(u32, @intCast(hu >> 32));
155 iu += 0x3FF00000 - 0x3FE6A09E;155 iu += 0x3FF00000 - 0x3FE6A09E;
156 k = @intCast(i32, iu >> 20) - 0x3FF;156 k = @as(i32, @intCast(iu >> 20)) - 0x3FF;
157157
158 // correction to avoid underflow in c / u158 // correction to avoid underflow in c / u
159 if (k < 54) {159 if (k < 54) {
...@@ -166,7 +166,7 @@ fn log1p_64(x: f64) f64 {...@@ -166,7 +166,7 @@ fn log1p_64(x: f64) f64 {
166 // u into [sqrt(2)/2, sqrt(2)]166 // u into [sqrt(2)/2, sqrt(2)]
167 iu = (iu & 0x000FFFFF) + 0x3FE6A09E;167 iu = (iu & 0x000FFFFF) + 0x3FE6A09E;
168 const iq = (@as(u64, iu) << 32) | (hu & 0xFFFFFFFF);168 const iq = (@as(u64, iu) << 32) | (hu & 0xFFFFFFFF);
169 f = @bitCast(f64, iq) - 1;169 f = @as(f64, @bitCast(iq)) - 1;
170 }170 }
171171
172 const hfsq = 0.5 * f * f;172 const hfsq = 0.5 * f * f;
...@@ -176,7 +176,7 @@ fn log1p_64(x: f64) f64 {...@@ -176,7 +176,7 @@ fn log1p_64(x: f64) f64 {
176 const t1 = w * (Lg2 + w * (Lg4 + w * Lg6));176 const t1 = w * (Lg2 + w * (Lg4 + w * Lg6));
177 const t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));177 const t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));
178 const R = t2 + t1;178 const R = t2 + t1;
179 const dk = @floatFromInt(f64, k);179 const dk = @as(f64, @floatFromInt(k));
180180
181 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;181 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
182}182}
lib/std/math/modf.zig+14-14
...@@ -37,8 +37,8 @@ pub fn modf(x: anytype) modf_result(@TypeOf(x)) {...@@ -37,8 +37,8 @@ pub fn modf(x: anytype) modf_result(@TypeOf(x)) {
37fn modf32(x: f32) modf32_result {37fn modf32(x: f32) modf32_result {
38 var result: modf32_result = undefined;38 var result: modf32_result = undefined;
3939
40 const u = @bitCast(u32, x);40 const u = @as(u32, @bitCast(x));
41 const e = @intCast(i32, (u >> 23) & 0xFF) - 0x7F;41 const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;
42 const us = u & 0x80000000;42 const us = u & 0x80000000;
4343
44 // TODO: Shouldn't need this.44 // TODO: Shouldn't need this.
...@@ -54,26 +54,26 @@ fn modf32(x: f32) modf32_result {...@@ -54,26 +54,26 @@ fn modf32(x: f32) modf32_result {
54 if (e == 0x80 and u << 9 != 0) { // nan54 if (e == 0x80 and u << 9 != 0) { // nan
55 result.fpart = x;55 result.fpart = x;
56 } else {56 } else {
57 result.fpart = @bitCast(f32, us);57 result.fpart = @as(f32, @bitCast(us));
58 }58 }
59 return result;59 return result;
60 }60 }
6161
62 // no integral part62 // no integral part
63 if (e < 0) {63 if (e < 0) {
64 result.ipart = @bitCast(f32, us);64 result.ipart = @as(f32, @bitCast(us));
65 result.fpart = x;65 result.fpart = x;
66 return result;66 return result;
67 }67 }
6868
69 const mask = @as(u32, 0x007FFFFF) >> @intCast(u5, e);69 const mask = @as(u32, 0x007FFFFF) >> @as(u5, @intCast(e));
70 if (u & mask == 0) {70 if (u & mask == 0) {
71 result.ipart = x;71 result.ipart = x;
72 result.fpart = @bitCast(f32, us);72 result.fpart = @as(f32, @bitCast(us));
73 return result;73 return result;
74 }74 }
7575
76 const uf = @bitCast(f32, u & ~mask);76 const uf = @as(f32, @bitCast(u & ~mask));
77 result.ipart = uf;77 result.ipart = uf;
78 result.fpart = x - uf;78 result.fpart = x - uf;
79 return result;79 return result;
...@@ -82,8 +82,8 @@ fn modf32(x: f32) modf32_result {...@@ -82,8 +82,8 @@ fn modf32(x: f32) modf32_result {
82fn modf64(x: f64) modf64_result {82fn modf64(x: f64) modf64_result {
83 var result: modf64_result = undefined;83 var result: modf64_result = undefined;
8484
85 const u = @bitCast(u64, x);85 const u = @as(u64, @bitCast(x));
86 const e = @intCast(i32, (u >> 52) & 0x7FF) - 0x3FF;86 const e = @as(i32, @intCast((u >> 52) & 0x7FF)) - 0x3FF;
87 const us = u & (1 << 63);87 const us = u & (1 << 63);
8888
89 if (math.isInf(x)) {89 if (math.isInf(x)) {
...@@ -98,26 +98,26 @@ fn modf64(x: f64) modf64_result {...@@ -98,26 +98,26 @@ fn modf64(x: f64) modf64_result {
98 if (e == 0x400 and u << 12 != 0) { // nan98 if (e == 0x400 and u << 12 != 0) { // nan
99 result.fpart = x;99 result.fpart = x;
100 } else {100 } else {
101 result.fpart = @bitCast(f64, us);101 result.fpart = @as(f64, @bitCast(us));
102 }102 }
103 return result;103 return result;
104 }104 }
105105
106 // no integral part106 // no integral part
107 if (e < 0) {107 if (e < 0) {
108 result.ipart = @bitCast(f64, us);108 result.ipart = @as(f64, @bitCast(us));
109 result.fpart = x;109 result.fpart = x;
110 return result;110 return result;
111 }111 }
112112
113 const mask = @as(u64, maxInt(u64) >> 12) >> @intCast(u6, e);113 const mask = @as(u64, maxInt(u64) >> 12) >> @as(u6, @intCast(e));
114 if (u & mask == 0) {114 if (u & mask == 0) {
115 result.ipart = x;115 result.ipart = x;
116 result.fpart = @bitCast(f64, us);116 result.fpart = @as(f64, @bitCast(us));
117 return result;117 return result;
118 }118 }
119119
120 const uf = @bitCast(f64, u & ~mask);120 const uf = @as(f64, @bitCast(u & ~mask));
121 result.ipart = uf;121 result.ipart = uf;
122 result.fpart = x - uf;122 result.fpart = x - uf;
123 return result;123 return result;
lib/std/math/pow.zig+2-2
...@@ -144,7 +144,7 @@ pub fn pow(comptime T: type, x: T, y: T) T {...@@ -144,7 +144,7 @@ pub fn pow(comptime T: type, x: T, y: T) T {
144 var xe = r2.exponent;144 var xe = r2.exponent;
145 var x1 = r2.significand;145 var x1 = r2.significand;
146146
147 var i = @intFromFloat(std.meta.Int(.signed, @typeInfo(T).Float.bits), yi);147 var i = @as(std.meta.Int(.signed, @typeInfo(T).Float.bits), @intFromFloat(yi));
148 while (i != 0) : (i >>= 1) {148 while (i != 0) : (i >>= 1) {
149 const overflow_shift = math.floatExponentBits(T) + 1;149 const overflow_shift = math.floatExponentBits(T) + 1;
150 if (xe < -(1 << overflow_shift) or (1 << overflow_shift) < xe) {150 if (xe < -(1 << overflow_shift) or (1 << overflow_shift) < xe) {
...@@ -179,7 +179,7 @@ pub fn pow(comptime T: type, x: T, y: T) T {...@@ -179,7 +179,7 @@ pub fn pow(comptime T: type, x: T, y: T) T {
179179
180fn isOddInteger(x: f64) bool {180fn isOddInteger(x: f64) bool {
181 const r = math.modf(x);181 const r = math.modf(x);
182 return r.fpart == 0.0 and @intFromFloat(i64, r.ipart) & 1 == 1;182 return r.fpart == 0.0 and @as(i64, @intFromFloat(r.ipart)) & 1 == 1;
183}183}
184184
185test "math.pow" {185test "math.pow" {
lib/std/math/signbit.zig+1-1
...@@ -6,7 +6,7 @@ const expect = std.testing.expect;...@@ -6,7 +6,7 @@ const expect = std.testing.expect;
6pub fn signbit(x: anytype) bool {6pub fn signbit(x: anytype) bool {
7 const T = @TypeOf(x);7 const T = @TypeOf(x);
8 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);8 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
9 return @bitCast(TBits, x) >> (@bitSizeOf(T) - 1) != 0;9 return @as(TBits, @bitCast(x)) >> (@bitSizeOf(T) - 1) != 0;
10}10}
1111
12test "math.signbit" {12test "math.signbit" {
lib/std/math/sinh.zig+5-5
...@@ -29,9 +29,9 @@ pub fn sinh(x: anytype) @TypeOf(x) {...@@ -29,9 +29,9 @@ pub fn sinh(x: anytype) @TypeOf(x) {
29// = (exp(x) - 1 + (exp(x) - 1) / exp(x)) / 229// = (exp(x) - 1 + (exp(x) - 1) / exp(x)) / 2
30// = x + x^3 / 6 + o(x^5)30// = x + x^3 / 6 + o(x^5)
31fn sinh32(x: f32) f32 {31fn sinh32(x: f32) f32 {
32 const u = @bitCast(u32, x);32 const u = @as(u32, @bitCast(x));
33 const ux = u & 0x7FFFFFFF;33 const ux = u & 0x7FFFFFFF;
34 const ax = @bitCast(f32, ux);34 const ax = @as(f32, @bitCast(ux));
3535
36 if (x == 0.0 or math.isNan(x)) {36 if (x == 0.0 or math.isNan(x)) {
37 return x;37 return x;
...@@ -60,9 +60,9 @@ fn sinh32(x: f32) f32 {...@@ -60,9 +60,9 @@ fn sinh32(x: f32) f32 {
60}60}
6161
62fn sinh64(x: f64) f64 {62fn sinh64(x: f64) f64 {
63 const u = @bitCast(u64, x);63 const u = @as(u64, @bitCast(x));
64 const w = @intCast(u32, u >> 32) & (maxInt(u32) >> 1);64 const w = @as(u32, @intCast(u >> 32)) & (maxInt(u32) >> 1);
65 const ax = @bitCast(f64, u & (maxInt(u64) >> 1));65 const ax = @as(f64, @bitCast(u & (maxInt(u64) >> 1)));
6666
67 if (x == 0.0 or math.isNan(x)) {67 if (x == 0.0 or math.isNan(x)) {
68 return x;68 return x;
lib/std/math/sqrt.zig+1-1
...@@ -57,7 +57,7 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {...@@ -57,7 +57,7 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {
57 one >>= 2;57 one >>= 2;
58 }58 }
5959
60 return @intCast(Sqrt(T), res);60 return @as(Sqrt(T), @intCast(res));
61 }61 }
62}62}
6363
lib/std/math/tanh.zig+6-6
...@@ -29,9 +29,9 @@ pub fn tanh(x: anytype) @TypeOf(x) {...@@ -29,9 +29,9 @@ pub fn tanh(x: anytype) @TypeOf(x) {
29// = (exp(2x) - 1) / (exp(2x) - 1 + 2)29// = (exp(2x) - 1) / (exp(2x) - 1 + 2)
30// = (1 - exp(-2x)) / (exp(-2x) - 1 + 2)30// = (1 - exp(-2x)) / (exp(-2x) - 1 + 2)
31fn tanh32(x: f32) f32 {31fn tanh32(x: f32) f32 {
32 const u = @bitCast(u32, x);32 const u = @as(u32, @bitCast(x));
33 const ux = u & 0x7FFFFFFF;33 const ux = u & 0x7FFFFFFF;
34 const ax = @bitCast(f32, ux);34 const ax = @as(f32, @bitCast(ux));
35 const sign = (u >> 31) != 0;35 const sign = (u >> 31) != 0;
3636
37 var t: f32 = undefined;37 var t: f32 = undefined;
...@@ -66,10 +66,10 @@ fn tanh32(x: f32) f32 {...@@ -66,10 +66,10 @@ fn tanh32(x: f32) f32 {
66}66}
6767
68fn tanh64(x: f64) f64 {68fn tanh64(x: f64) f64 {
69 const u = @bitCast(u64, x);69 const u = @as(u64, @bitCast(x));
70 const ux = u & 0x7FFFFFFFFFFFFFFF;70 const ux = u & 0x7FFFFFFFFFFFFFFF;
71 const w = @intCast(u32, ux >> 32);71 const w = @as(u32, @intCast(ux >> 32));
72 const ax = @bitCast(f64, ux);72 const ax = @as(f64, @bitCast(ux));
73 const sign = (u >> 63) != 0;73 const sign = (u >> 63) != 0;
7474
75 var t: f64 = undefined;75 var t: f64 = undefined;
...@@ -96,7 +96,7 @@ fn tanh64(x: f64) f64 {...@@ -96,7 +96,7 @@ fn tanh64(x: f64) f64 {
96 }96 }
97 // |x| is subnormal97 // |x| is subnormal
98 else {98 else {
99 math.doNotOptimizeAway(@floatCast(f32, ax));99 math.doNotOptimizeAway(@as(f32, @floatCast(ax)));
100 t = ax;100 t = ax;
101 }101 }
102102
lib/std/mem.zig+110-113
...@@ -69,7 +69,7 @@ pub fn ValidationAllocator(comptime T: type) type {...@@ -69,7 +69,7 @@ pub fn ValidationAllocator(comptime T: type) type {
69 ret_addr: usize,69 ret_addr: usize,
70 ) ?[*]u8 {70 ) ?[*]u8 {
71 assert(n > 0);71 assert(n > 0);
72 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));72 const self: *Self = @ptrCast(@alignCast(ctx));
73 const underlying = self.getUnderlyingAllocatorPtr();73 const underlying = self.getUnderlyingAllocatorPtr();
74 const result = underlying.rawAlloc(n, log2_ptr_align, ret_addr) orelse74 const result = underlying.rawAlloc(n, log2_ptr_align, ret_addr) orelse
75 return null;75 return null;
...@@ -84,7 +84,7 @@ pub fn ValidationAllocator(comptime T: type) type {...@@ -84,7 +84,7 @@ pub fn ValidationAllocator(comptime T: type) type {
84 new_len: usize,84 new_len: usize,
85 ret_addr: usize,85 ret_addr: usize,
86 ) bool {86 ) bool {
87 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));87 const self: *Self = @ptrCast(@alignCast(ctx));
88 assert(buf.len > 0);88 assert(buf.len > 0);
89 const underlying = self.getUnderlyingAllocatorPtr();89 const underlying = self.getUnderlyingAllocatorPtr();
90 return underlying.rawResize(buf, log2_buf_align, new_len, ret_addr);90 return underlying.rawResize(buf, log2_buf_align, new_len, ret_addr);
...@@ -96,7 +96,7 @@ pub fn ValidationAllocator(comptime T: type) type {...@@ -96,7 +96,7 @@ pub fn ValidationAllocator(comptime T: type) type {
96 log2_buf_align: u8,96 log2_buf_align: u8,
97 ret_addr: usize,97 ret_addr: usize,
98 ) void {98 ) void {
99 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));99 const self: *Self = @ptrCast(@alignCast(ctx));
100 assert(buf.len > 0);100 assert(buf.len > 0);
101 const underlying = self.getUnderlyingAllocatorPtr();101 const underlying = self.getUnderlyingAllocatorPtr();
102 underlying.rawFree(buf, log2_buf_align, ret_addr);102 underlying.rawFree(buf, log2_buf_align, ret_addr);
...@@ -169,7 +169,7 @@ test "Allocator.resize" {...@@ -169,7 +169,7 @@ test "Allocator.resize" {
169 var values = try testing.allocator.alloc(T, 100);169 var values = try testing.allocator.alloc(T, 100);
170 defer testing.allocator.free(values);170 defer testing.allocator.free(values);
171171
172 for (values, 0..) |*v, i| v.* = @intCast(T, i);172 for (values, 0..) |*v, i| v.* = @as(T, @intCast(i));
173 if (!testing.allocator.resize(values, values.len + 10)) return error.OutOfMemory;173 if (!testing.allocator.resize(values, values.len + 10)) return error.OutOfMemory;
174 values = values.ptr[0 .. values.len + 10];174 values = values.ptr[0 .. values.len + 10];
175 try testing.expect(values.len == 110);175 try testing.expect(values.len == 110);
...@@ -185,7 +185,7 @@ test "Allocator.resize" {...@@ -185,7 +185,7 @@ test "Allocator.resize" {
185 var values = try testing.allocator.alloc(T, 100);185 var values = try testing.allocator.alloc(T, 100);
186 defer testing.allocator.free(values);186 defer testing.allocator.free(values);
187187
188 for (values, 0..) |*v, i| v.* = @floatFromInt(T, i);188 for (values, 0..) |*v, i| v.* = @as(T, @floatFromInt(i));
189 if (!testing.allocator.resize(values, values.len + 10)) return error.OutOfMemory;189 if (!testing.allocator.resize(values, values.len + 10)) return error.OutOfMemory;
190 values = values.ptr[0 .. values.len + 10];190 values = values.ptr[0 .. values.len + 10];
191 try testing.expect(values.len == 110);191 try testing.expect(values.len == 110);
...@@ -233,7 +233,7 @@ pub fn zeroes(comptime T: type) T {...@@ -233,7 +233,7 @@ pub fn zeroes(comptime T: type) T {
233 return @as(T, 0);233 return @as(T, 0);
234 },234 },
235 .Enum, .EnumLiteral => {235 .Enum, .EnumLiteral => {
236 return @enumFromInt(T, 0);236 return @as(T, @enumFromInt(0));
237 },237 },
238 .Void => {238 .Void => {
239 return {};239 return {};
...@@ -264,7 +264,7 @@ pub fn zeroes(comptime T: type) T {...@@ -264,7 +264,7 @@ pub fn zeroes(comptime T: type) T {
264 switch (ptr_info.size) {264 switch (ptr_info.size) {
265 .Slice => {265 .Slice => {
266 if (ptr_info.sentinel) |sentinel| {266 if (ptr_info.sentinel) |sentinel| {
267 if (ptr_info.child == u8 and @ptrCast(*const u8, sentinel).* == 0) {267 if (ptr_info.child == u8 and @as(*const u8, @ptrCast(sentinel)).* == 0) {
268 return ""; // A special case for the most common use-case: null-terminated strings.268 return ""; // A special case for the most common use-case: null-terminated strings.
269 }269 }
270 @compileError("Can't set a sentinel slice to zero. This would require allocating memory.");270 @compileError("Can't set a sentinel slice to zero. This would require allocating memory.");
...@@ -282,7 +282,7 @@ pub fn zeroes(comptime T: type) T {...@@ -282,7 +282,7 @@ pub fn zeroes(comptime T: type) T {
282 },282 },
283 .Array => |info| {283 .Array => |info| {
284 if (info.sentinel) |sentinel_ptr| {284 if (info.sentinel) |sentinel_ptr| {
285 const sentinel = @ptrCast(*align(1) const info.child, sentinel_ptr).*;285 const sentinel = @as(*align(1) const info.child, @ptrCast(sentinel_ptr)).*;
286 return [_:sentinel]info.child{zeroes(info.child)} ** info.len;286 return [_:sentinel]info.child{zeroes(info.child)} ** info.len;
287 }287 }
288 return [_]info.child{zeroes(info.child)} ** info.len;288 return [_]info.child{zeroes(info.child)} ** info.len;
...@@ -456,7 +456,7 @@ pub fn zeroInit(comptime T: type, init: anytype) T {...@@ -456,7 +456,7 @@ pub fn zeroInit(comptime T: type, init: anytype) T {
456 },456 },
457 }457 }
458 } else if (field.default_value) |default_value_ptr| {458 } else if (field.default_value) |default_value_ptr| {
459 const default_value = @ptrCast(*align(1) const field.type, default_value_ptr).*;459 const default_value = @as(*align(1) const field.type, @ptrCast(default_value_ptr)).*;
460 @field(value, field.name) = default_value;460 @field(value, field.name) = default_value;
461 } else {461 } else {
462 switch (@typeInfo(field.type)) {462 switch (@typeInfo(field.type)) {
...@@ -709,7 +709,7 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {...@@ -709,7 +709,7 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {
709 const l = len(ptr);709 const l = len(ptr);
710 const ptr_info = @typeInfo(Result).Pointer;710 const ptr_info = @typeInfo(Result).Pointer;
711 if (ptr_info.sentinel) |s_ptr| {711 if (ptr_info.sentinel) |s_ptr| {
712 const s = @ptrCast(*align(1) const ptr_info.child, s_ptr).*;712 const s = @as(*align(1) const ptr_info.child, @ptrCast(s_ptr)).*;
713 return ptr[0..l :s];713 return ptr[0..l :s];
714 } else {714 } else {
715 return ptr[0..l];715 return ptr[0..l];
...@@ -740,7 +740,7 @@ fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {...@@ -740,7 +740,7 @@ fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {
740 // to find the value searched for, which is only the case if it matches740 // to find the value searched for, which is only the case if it matches
741 // the sentinel of the type passed.741 // the sentinel of the type passed.
742 if (array_info.sentinel) |sentinel_ptr| {742 if (array_info.sentinel) |sentinel_ptr| {
743 const sentinel = @ptrCast(*align(1) const array_info.child, sentinel_ptr).*;743 const sentinel = @as(*align(1) const array_info.child, @ptrCast(sentinel_ptr)).*;
744 if (end == sentinel) {744 if (end == sentinel) {
745 new_ptr_info.sentinel = &end;745 new_ptr_info.sentinel = &end;
746 } else {746 } else {
...@@ -755,7 +755,7 @@ fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {...@@ -755,7 +755,7 @@ fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {
755 // to find the value searched for, which is only the case if it matches755 // to find the value searched for, which is only the case if it matches
756 // the sentinel of the type passed.756 // the sentinel of the type passed.
757 if (ptr_info.sentinel) |sentinel_ptr| {757 if (ptr_info.sentinel) |sentinel_ptr| {
758 const sentinel = @ptrCast(*align(1) const ptr_info.child, sentinel_ptr).*;758 const sentinel = @as(*align(1) const ptr_info.child, @ptrCast(sentinel_ptr)).*;
759 if (end == sentinel) {759 if (end == sentinel) {
760 new_ptr_info.sentinel = &end;760 new_ptr_info.sentinel = &end;
761 } else {761 } else {
...@@ -793,7 +793,7 @@ pub fn sliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) SliceTo(@Typ...@@ -793,7 +793,7 @@ pub fn sliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) SliceTo(@Typ
793 const length = lenSliceTo(ptr, end);793 const length = lenSliceTo(ptr, end);
794 const ptr_info = @typeInfo(Result).Pointer;794 const ptr_info = @typeInfo(Result).Pointer;
795 if (ptr_info.sentinel) |s_ptr| {795 if (ptr_info.sentinel) |s_ptr| {
796 const s = @ptrCast(*align(1) const ptr_info.child, s_ptr).*;796 const s = @as(*align(1) const ptr_info.child, @ptrCast(s_ptr)).*;
797 return ptr[0..length :s];797 return ptr[0..length :s];
798 } else {798 } else {
799 return ptr[0..length];799 return ptr[0..length];
...@@ -810,11 +810,11 @@ test "sliceTo" {...@@ -810,11 +810,11 @@ test "sliceTo" {
810 try testing.expectEqualSlices(u16, array[0..2], sliceTo(&array, 3));810 try testing.expectEqualSlices(u16, array[0..2], sliceTo(&array, 3));
811 try testing.expectEqualSlices(u16, array[0..2], sliceTo(array[0..3], 3));811 try testing.expectEqualSlices(u16, array[0..2], sliceTo(array[0..3], 3));
812812
813 const sentinel_ptr = @ptrCast([*:5]u16, &array);813 const sentinel_ptr = @as([*:5]u16, @ptrCast(&array));
814 try testing.expectEqualSlices(u16, array[0..2], sliceTo(sentinel_ptr, 3));814 try testing.expectEqualSlices(u16, array[0..2], sliceTo(sentinel_ptr, 3));
815 try testing.expectEqualSlices(u16, array[0..4], sliceTo(sentinel_ptr, 99));815 try testing.expectEqualSlices(u16, array[0..4], sliceTo(sentinel_ptr, 99));
816816
817 const optional_sentinel_ptr = @ptrCast(?[*:5]u16, &array);817 const optional_sentinel_ptr = @as(?[*:5]u16, @ptrCast(&array));
818 try testing.expectEqualSlices(u16, array[0..2], sliceTo(optional_sentinel_ptr, 3).?);818 try testing.expectEqualSlices(u16, array[0..2], sliceTo(optional_sentinel_ptr, 3).?);
819 try testing.expectEqualSlices(u16, array[0..4], sliceTo(optional_sentinel_ptr, 99).?);819 try testing.expectEqualSlices(u16, array[0..4], sliceTo(optional_sentinel_ptr, 99).?);
820820
...@@ -846,7 +846,7 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {...@@ -846,7 +846,7 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {
846 .One => switch (@typeInfo(ptr_info.child)) {846 .One => switch (@typeInfo(ptr_info.child)) {
847 .Array => |array_info| {847 .Array => |array_info| {
848 if (array_info.sentinel) |sentinel_ptr| {848 if (array_info.sentinel) |sentinel_ptr| {
849 const sentinel = @ptrCast(*align(1) const array_info.child, sentinel_ptr).*;849 const sentinel = @as(*align(1) const array_info.child, @ptrCast(sentinel_ptr)).*;
850 if (sentinel == end) {850 if (sentinel == end) {
851 return indexOfSentinel(array_info.child, end, ptr);851 return indexOfSentinel(array_info.child, end, ptr);
852 }852 }
...@@ -856,7 +856,7 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {...@@ -856,7 +856,7 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {
856 else => {},856 else => {},
857 },857 },
858 .Many => if (ptr_info.sentinel) |sentinel_ptr| {858 .Many => if (ptr_info.sentinel) |sentinel_ptr| {
859 const sentinel = @ptrCast(*align(1) const ptr_info.child, sentinel_ptr).*;859 const sentinel = @as(*align(1) const ptr_info.child, @ptrCast(sentinel_ptr)).*;
860 // We may be looking for something other than the sentinel,860 // We may be looking for something other than the sentinel,
861 // but iterating past the sentinel would be a bug so we need861 // but iterating past the sentinel would be a bug so we need
862 // to check for both.862 // to check for both.
...@@ -870,7 +870,7 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {...@@ -870,7 +870,7 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {
870 },870 },
871 .Slice => {871 .Slice => {
872 if (ptr_info.sentinel) |sentinel_ptr| {872 if (ptr_info.sentinel) |sentinel_ptr| {
873 const sentinel = @ptrCast(*align(1) const ptr_info.child, sentinel_ptr).*;873 const sentinel = @as(*align(1) const ptr_info.child, @ptrCast(sentinel_ptr)).*;
874 if (sentinel == end) {874 if (sentinel == end) {
875 return indexOfSentinel(ptr_info.child, sentinel, ptr);875 return indexOfSentinel(ptr_info.child, sentinel, ptr);
876 }876 }
...@@ -893,7 +893,7 @@ test "lenSliceTo" {...@@ -893,7 +893,7 @@ test "lenSliceTo" {
893 try testing.expectEqual(@as(usize, 2), lenSliceTo(&array, 3));893 try testing.expectEqual(@as(usize, 2), lenSliceTo(&array, 3));
894 try testing.expectEqual(@as(usize, 2), lenSliceTo(array[0..3], 3));894 try testing.expectEqual(@as(usize, 2), lenSliceTo(array[0..3], 3));
895895
896 const sentinel_ptr = @ptrCast([*:5]u16, &array);896 const sentinel_ptr = @as([*:5]u16, @ptrCast(&array));
897 try testing.expectEqual(@as(usize, 2), lenSliceTo(sentinel_ptr, 3));897 try testing.expectEqual(@as(usize, 2), lenSliceTo(sentinel_ptr, 3));
898 try testing.expectEqual(@as(usize, 4), lenSliceTo(sentinel_ptr, 99));898 try testing.expectEqual(@as(usize, 4), lenSliceTo(sentinel_ptr, 99));
899899
...@@ -925,7 +925,7 @@ pub fn len(value: anytype) usize {...@@ -925,7 +925,7 @@ pub fn len(value: anytype) usize {
925 .Many => {925 .Many => {
926 const sentinel_ptr = info.sentinel orelse926 const sentinel_ptr = info.sentinel orelse
927 @compileError("invalid type given to std.mem.len: " ++ @typeName(@TypeOf(value)));927 @compileError("invalid type given to std.mem.len: " ++ @typeName(@TypeOf(value)));
928 const sentinel = @ptrCast(*align(1) const info.child, sentinel_ptr).*;928 const sentinel = @as(*align(1) const info.child, @ptrCast(sentinel_ptr)).*;
929 return indexOfSentinel(info.child, sentinel, value);929 return indexOfSentinel(info.child, sentinel, value);
930 },930 },
931 .C => {931 .C => {
...@@ -1331,7 +1331,7 @@ pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: Endian)...@@ -1331,7 +1331,7 @@ pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: Endian)
1331 .Little => {1331 .Little => {
1332 const ShiftType = math.Log2Int(ReturnType);1332 const ShiftType = math.Log2Int(ReturnType);
1333 for (bytes, 0..) |b, index| {1333 for (bytes, 0..) |b, index| {
1334 result = result | (@as(ReturnType, b) << @intCast(ShiftType, index * 8));1334 result = result | (@as(ReturnType, b) << @as(ShiftType, @intCast(index * 8)));
1335 }1335 }
1336 },1336 },
1337 }1337 }
...@@ -1359,8 +1359,8 @@ pub fn readVarPackedInt(...@@ -1359,8 +1359,8 @@ pub fn readVarPackedInt(
1359 const Log2N = std.math.Log2Int(T);1359 const Log2N = std.math.Log2Int(T);
13601360
1361 const read_size = (bit_count + (bit_offset % 8) + 7) / 8;1361 const read_size = (bit_count + (bit_offset % 8) + 7) / 8;
1362 const bit_shift = @intCast(u3, bit_offset % 8);1362 const bit_shift = @as(u3, @intCast(bit_offset % 8));
1363 const pad = @intCast(Log2N, @bitSizeOf(T) - bit_count);1363 const pad = @as(Log2N, @intCast(@bitSizeOf(T) - bit_count));
13641364
1365 const lowest_byte = switch (endian) {1365 const lowest_byte = switch (endian) {
1366 .Big => bytes.len - (bit_offset / 8) - read_size,1366 .Big => bytes.len - (bit_offset / 8) - read_size,
...@@ -1372,17 +1372,17 @@ pub fn readVarPackedInt(...@@ -1372,17 +1372,17 @@ pub fn readVarPackedInt(
1372 // These are the same shifts/masks we perform below, but adds `@truncate`/`@intCast`1372 // These are the same shifts/masks we perform below, but adds `@truncate`/`@intCast`
1373 // where needed since int is smaller than a byte.1373 // where needed since int is smaller than a byte.
1374 const value = if (read_size == 1) b: {1374 const value = if (read_size == 1) b: {
1375 break :b @truncate(uN, read_bytes[0] >> bit_shift);1375 break :b @as(uN, @truncate(read_bytes[0] >> bit_shift));
1376 } else b: {1376 } else b: {
1377 const i: u1 = @intFromBool(endian == .Big);1377 const i: u1 = @intFromBool(endian == .Big);
1378 const head = @truncate(uN, read_bytes[i] >> bit_shift);1378 const head = @as(uN, @truncate(read_bytes[i] >> bit_shift));
1379 const tail_shift = @intCast(Log2N, @as(u4, 8) - bit_shift);1379 const tail_shift = @as(Log2N, @intCast(@as(u4, 8) - bit_shift));
1380 const tail = @truncate(uN, read_bytes[1 - i]);1380 const tail = @as(uN, @truncate(read_bytes[1 - i]));
1381 break :b (tail << tail_shift) | head;1381 break :b (tail << tail_shift) | head;
1382 };1382 };
1383 switch (signedness) {1383 switch (signedness) {
1384 .signed => return @intCast(T, (@bitCast(iN, value) << pad) >> pad),1384 .signed => return @as(T, @intCast((@as(iN, @bitCast(value)) << pad) >> pad)),
1385 .unsigned => return @intCast(T, (@bitCast(uN, value) << pad) >> pad),1385 .unsigned => return @as(T, @intCast((@as(uN, @bitCast(value)) << pad) >> pad)),
1386 }1386 }
1387 }1387 }
13881388
...@@ -1398,13 +1398,13 @@ pub fn readVarPackedInt(...@@ -1398,13 +1398,13 @@ pub fn readVarPackedInt(
1398 .Little => {1398 .Little => {
1399 int = read_bytes[0] >> bit_shift;1399 int = read_bytes[0] >> bit_shift;
1400 for (read_bytes[1..], 0..) |elem, i| {1400 for (read_bytes[1..], 0..) |elem, i| {
1401 int |= (@as(uN, elem) << @intCast(Log2N, (8 * (i + 1) - bit_shift)));1401 int |= (@as(uN, elem) << @as(Log2N, @intCast((8 * (i + 1) - bit_shift))));
1402 }1402 }
1403 },1403 },
1404 }1404 }
1405 switch (signedness) {1405 switch (signedness) {
1406 .signed => return @intCast(T, (@bitCast(iN, int) << pad) >> pad),1406 .signed => return @as(T, @intCast((@as(iN, @bitCast(int)) << pad) >> pad)),
1407 .unsigned => return @intCast(T, (@bitCast(uN, int) << pad) >> pad),1407 .unsigned => return @as(T, @intCast((@as(uN, @bitCast(int)) << pad) >> pad)),
1408 }1408 }
1409}1409}
14101410
...@@ -1414,7 +1414,7 @@ pub fn readVarPackedInt(...@@ -1414,7 +1414,7 @@ pub fn readVarPackedInt(
1414/// Assumes the endianness of memory is native. This means the function can1414/// Assumes the endianness of memory is native. This means the function can
1415/// simply pointer cast memory.1415/// simply pointer cast memory.
1416pub fn readIntNative(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8) T {1416pub fn readIntNative(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8) T {
1417 return @ptrCast(*align(1) const T, bytes).*;1417 return @as(*align(1) const T, @ptrCast(bytes)).*;
1418}1418}
14191419
1420/// Reads an integer from memory with bit count specified by T.1420/// Reads an integer from memory with bit count specified by T.
...@@ -1480,10 +1480,10 @@ fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T...@@ -1480,10 +1480,10 @@ fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T
1480 const Log2N = std.math.Log2Int(T);1480 const Log2N = std.math.Log2Int(T);
14811481
1482 const bit_count = @as(usize, @bitSizeOf(T));1482 const bit_count = @as(usize, @bitSizeOf(T));
1483 const bit_shift = @intCast(u3, bit_offset % 8);1483 const bit_shift = @as(u3, @intCast(bit_offset % 8));
14841484
1485 const load_size = (bit_count + 7) / 8;1485 const load_size = (bit_count + 7) / 8;
1486 const load_tail_bits = @intCast(u3, (load_size * 8) - bit_count);1486 const load_tail_bits = @as(u3, @intCast((load_size * 8) - bit_count));
1487 const LoadInt = std.meta.Int(.unsigned, load_size * 8);1487 const LoadInt = std.meta.Int(.unsigned, load_size * 8);
14881488
1489 if (bit_count == 0)1489 if (bit_count == 0)
...@@ -1492,13 +1492,13 @@ fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T...@@ -1492,13 +1492,13 @@ fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T
1492 // Read by loading a LoadInt, and then follow it up with a 1-byte read1492 // Read by loading a LoadInt, and then follow it up with a 1-byte read
1493 // of the tail if bit_offset pushed us over a byte boundary.1493 // of the tail if bit_offset pushed us over a byte boundary.
1494 const read_bytes = bytes[bit_offset / 8 ..];1494 const read_bytes = bytes[bit_offset / 8 ..];
1495 const val = @truncate(uN, readIntLittle(LoadInt, read_bytes[0..load_size]) >> bit_shift);1495 const val = @as(uN, @truncate(readIntLittle(LoadInt, read_bytes[0..load_size]) >> bit_shift));
1496 if (bit_shift > load_tail_bits) {1496 if (bit_shift > load_tail_bits) {
1497 const tail_bits = @intCast(Log2N, bit_shift - load_tail_bits);1497 const tail_bits = @as(Log2N, @intCast(bit_shift - load_tail_bits));
1498 const tail_byte = read_bytes[load_size];1498 const tail_byte = read_bytes[load_size];
1499 const tail_truncated = if (bit_count < 8) @truncate(uN, tail_byte) else @as(uN, tail_byte);1499 const tail_truncated = if (bit_count < 8) @as(uN, @truncate(tail_byte)) else @as(uN, tail_byte);
1500 return @bitCast(T, val | (tail_truncated << (@truncate(Log2N, bit_count) -% tail_bits)));1500 return @as(T, @bitCast(val | (tail_truncated << (@as(Log2N, @truncate(bit_count)) -% tail_bits))));
1501 } else return @bitCast(T, val);1501 } else return @as(T, @bitCast(val));
1502}1502}
15031503
1504fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T {1504fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T {
...@@ -1506,11 +1506,11 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T {...@@ -1506,11 +1506,11 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T {
1506 const Log2N = std.math.Log2Int(T);1506 const Log2N = std.math.Log2Int(T);
15071507
1508 const bit_count = @as(usize, @bitSizeOf(T));1508 const bit_count = @as(usize, @bitSizeOf(T));
1509 const bit_shift = @intCast(u3, bit_offset % 8);1509 const bit_shift = @as(u3, @intCast(bit_offset % 8));
1510 const byte_count = (@as(usize, bit_shift) + bit_count + 7) / 8;1510 const byte_count = (@as(usize, bit_shift) + bit_count + 7) / 8;
15111511
1512 const load_size = (bit_count + 7) / 8;1512 const load_size = (bit_count + 7) / 8;
1513 const load_tail_bits = @intCast(u3, (load_size * 8) - bit_count);1513 const load_tail_bits = @as(u3, @intCast((load_size * 8) - bit_count));
1514 const LoadInt = std.meta.Int(.unsigned, load_size * 8);1514 const LoadInt = std.meta.Int(.unsigned, load_size * 8);
15151515
1516 if (bit_count == 0)1516 if (bit_count == 0)
...@@ -1520,12 +1520,12 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T {...@@ -1520,12 +1520,12 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T {
1520 // of the tail if bit_offset pushed us over a byte boundary.1520 // of the tail if bit_offset pushed us over a byte boundary.
1521 const end = bytes.len - (bit_offset / 8);1521 const end = bytes.len - (bit_offset / 8);
1522 const read_bytes = bytes[(end - byte_count)..end];1522 const read_bytes = bytes[(end - byte_count)..end];
1523 const val = @truncate(uN, readIntBig(LoadInt, bytes[(end - load_size)..end][0..load_size]) >> bit_shift);1523 const val = @as(uN, @truncate(readIntBig(LoadInt, bytes[(end - load_size)..end][0..load_size]) >> bit_shift));
1524 if (bit_shift > load_tail_bits) {1524 if (bit_shift > load_tail_bits) {
1525 const tail_bits = @intCast(Log2N, bit_shift - load_tail_bits);1525 const tail_bits = @as(Log2N, @intCast(bit_shift - load_tail_bits));
1526 const tail_byte = if (bit_count < 8) @truncate(uN, read_bytes[0]) else @as(uN, read_bytes[0]);1526 const tail_byte = if (bit_count < 8) @as(uN, @truncate(read_bytes[0])) else @as(uN, read_bytes[0]);
1527 return @bitCast(T, val | (tail_byte << (@truncate(Log2N, bit_count) -% tail_bits)));1527 return @as(T, @bitCast(val | (tail_byte << (@as(Log2N, @truncate(bit_count)) -% tail_bits))));
1528 } else return @bitCast(T, val);1528 } else return @as(T, @bitCast(val));
1529}1529}
15301530
1531pub const readPackedIntNative = switch (native_endian) {1531pub const readPackedIntNative = switch (native_endian) {
...@@ -1605,7 +1605,7 @@ test "readIntBig and readIntLittle" {...@@ -1605,7 +1605,7 @@ test "readIntBig and readIntLittle" {
1605/// This function stores in native endian, which means it is implemented as a simple1605/// This function stores in native endian, which means it is implemented as a simple
1606/// memory store.1606/// memory store.
1607pub fn writeIntNative(comptime T: type, buf: *[(@typeInfo(T).Int.bits + 7) / 8]u8, value: T) void {1607pub fn writeIntNative(comptime T: type, buf: *[(@typeInfo(T).Int.bits + 7) / 8]u8, value: T) void {
1608 @ptrCast(*align(1) T, buf).* = value;1608 @as(*align(1) T, @ptrCast(buf)).* = value;
1609}1609}
16101610
1611/// Writes an integer to memory, storing it in twos-complement.1611/// Writes an integer to memory, storing it in twos-complement.
...@@ -1642,10 +1642,10 @@ fn writePackedIntLittle(comptime T: type, bytes: []u8, bit_offset: usize, value:...@@ -1642,10 +1642,10 @@ fn writePackedIntLittle(comptime T: type, bytes: []u8, bit_offset: usize, value:
1642 const Log2N = std.math.Log2Int(T);1642 const Log2N = std.math.Log2Int(T);
16431643
1644 const bit_count = @as(usize, @bitSizeOf(T));1644 const bit_count = @as(usize, @bitSizeOf(T));
1645 const bit_shift = @intCast(u3, bit_offset % 8);1645 const bit_shift = @as(u3, @intCast(bit_offset % 8));
16461646
1647 const store_size = (@bitSizeOf(T) + 7) / 8;1647 const store_size = (@bitSizeOf(T) + 7) / 8;
1648 const store_tail_bits = @intCast(u3, (store_size * 8) - bit_count);1648 const store_tail_bits = @as(u3, @intCast((store_size * 8) - bit_count));
1649 const StoreInt = std.meta.Int(.unsigned, store_size * 8);1649 const StoreInt = std.meta.Int(.unsigned, store_size * 8);
16501650
1651 if (bit_count == 0)1651 if (bit_count == 0)
...@@ -1656,11 +1656,11 @@ fn writePackedIntLittle(comptime T: type, bytes: []u8, bit_offset: usize, value:...@@ -1656,11 +1656,11 @@ fn writePackedIntLittle(comptime T: type, bytes: []u8, bit_offset: usize, value:
1656 const write_bytes = bytes[bit_offset / 8 ..];1656 const write_bytes = bytes[bit_offset / 8 ..];
1657 const head = write_bytes[0] & ((@as(u8, 1) << bit_shift) - 1);1657 const head = write_bytes[0] & ((@as(u8, 1) << bit_shift) - 1);
16581658
1659 var write_value = (@as(StoreInt, @bitCast(uN, value)) << bit_shift) | @intCast(StoreInt, head);1659 var write_value = (@as(StoreInt, @as(uN, @bitCast(value))) << bit_shift) | @as(StoreInt, @intCast(head));
1660 if (bit_shift > store_tail_bits) {1660 if (bit_shift > store_tail_bits) {
1661 const tail_len = @intCast(Log2N, bit_shift - store_tail_bits);1661 const tail_len = @as(Log2N, @intCast(bit_shift - store_tail_bits));
1662 write_bytes[store_size] &= ~((@as(u8, 1) << @intCast(u3, tail_len)) - 1);1662 write_bytes[store_size] &= ~((@as(u8, 1) << @as(u3, @intCast(tail_len))) - 1);
1663 write_bytes[store_size] |= @intCast(u8, (@bitCast(uN, value) >> (@truncate(Log2N, bit_count) -% tail_len)));1663 write_bytes[store_size] |= @as(u8, @intCast((@as(uN, @bitCast(value)) >> (@as(Log2N, @truncate(bit_count)) -% tail_len))));
1664 } else if (bit_shift < store_tail_bits) {1664 } else if (bit_shift < store_tail_bits) {
1665 const tail_len = store_tail_bits - bit_shift;1665 const tail_len = store_tail_bits - bit_shift;
1666 const tail = write_bytes[store_size - 1] & (@as(u8, 0xfe) << (7 - tail_len));1666 const tail = write_bytes[store_size - 1] & (@as(u8, 0xfe) << (7 - tail_len));
...@@ -1675,11 +1675,11 @@ fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T)...@@ -1675,11 +1675,11 @@ fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T)
1675 const Log2N = std.math.Log2Int(T);1675 const Log2N = std.math.Log2Int(T);
16761676
1677 const bit_count = @as(usize, @bitSizeOf(T));1677 const bit_count = @as(usize, @bitSizeOf(T));
1678 const bit_shift = @intCast(u3, bit_offset % 8);1678 const bit_shift = @as(u3, @intCast(bit_offset % 8));
1679 const byte_count = (bit_shift + bit_count + 7) / 8;1679 const byte_count = (bit_shift + bit_count + 7) / 8;
16801680
1681 const store_size = (@bitSizeOf(T) + 7) / 8;1681 const store_size = (@bitSizeOf(T) + 7) / 8;
1682 const store_tail_bits = @intCast(u3, (store_size * 8) - bit_count);1682 const store_tail_bits = @as(u3, @intCast((store_size * 8) - bit_count));
1683 const StoreInt = std.meta.Int(.unsigned, store_size * 8);1683 const StoreInt = std.meta.Int(.unsigned, store_size * 8);
16841684
1685 if (bit_count == 0)1685 if (bit_count == 0)
...@@ -1691,11 +1691,11 @@ fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T)...@@ -1691,11 +1691,11 @@ fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T)
1691 const write_bytes = bytes[(end - byte_count)..end];1691 const write_bytes = bytes[(end - byte_count)..end];
1692 const head = write_bytes[byte_count - 1] & ((@as(u8, 1) << bit_shift) - 1);1692 const head = write_bytes[byte_count - 1] & ((@as(u8, 1) << bit_shift) - 1);
16931693
1694 var write_value = (@as(StoreInt, @bitCast(uN, value)) << bit_shift) | @intCast(StoreInt, head);1694 var write_value = (@as(StoreInt, @as(uN, @bitCast(value))) << bit_shift) | @as(StoreInt, @intCast(head));
1695 if (bit_shift > store_tail_bits) {1695 if (bit_shift > store_tail_bits) {
1696 const tail_len = @intCast(Log2N, bit_shift - store_tail_bits);1696 const tail_len = @as(Log2N, @intCast(bit_shift - store_tail_bits));
1697 write_bytes[0] &= ~((@as(u8, 1) << @intCast(u3, tail_len)) - 1);1697 write_bytes[0] &= ~((@as(u8, 1) << @as(u3, @intCast(tail_len))) - 1);
1698 write_bytes[0] |= @intCast(u8, (@bitCast(uN, value) >> (@truncate(Log2N, bit_count) -% tail_len)));1698 write_bytes[0] |= @as(u8, @intCast((@as(uN, @bitCast(value)) >> (@as(Log2N, @truncate(bit_count)) -% tail_len))));
1699 } else if (bit_shift < store_tail_bits) {1699 } else if (bit_shift < store_tail_bits) {
1700 const tail_len = store_tail_bits - bit_shift;1700 const tail_len = store_tail_bits - bit_shift;
1701 const tail = write_bytes[0] & (@as(u8, 0xfe) << (7 - tail_len));1701 const tail = write_bytes[0] & (@as(u8, 0xfe) << (7 - tail_len));
...@@ -1744,14 +1744,14 @@ pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {...@@ -1744,14 +1744,14 @@ pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {
1744 return @memset(buffer, 0);1744 return @memset(buffer, 0);
1745 } else if (@typeInfo(T).Int.bits == 8) {1745 } else if (@typeInfo(T).Int.bits == 8) {
1746 @memset(buffer, 0);1746 @memset(buffer, 0);
1747 buffer[0] = @bitCast(u8, value);1747 buffer[0] = @as(u8, @bitCast(value));
1748 return;1748 return;
1749 }1749 }
1750 // TODO I want to call writeIntLittle here but comptime eval facilities aren't good enough1750 // TODO I want to call writeIntLittle here but comptime eval facilities aren't good enough
1751 const uint = std.meta.Int(.unsigned, @typeInfo(T).Int.bits);1751 const uint = std.meta.Int(.unsigned, @typeInfo(T).Int.bits);
1752 var bits = @bitCast(uint, value);1752 var bits = @as(uint, @bitCast(value));
1753 for (buffer) |*b| {1753 for (buffer) |*b| {
1754 b.* = @truncate(u8, bits);1754 b.* = @as(u8, @truncate(bits));
1755 bits >>= 8;1755 bits >>= 8;
1756 }1756 }
1757}1757}
...@@ -1768,17 +1768,17 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {...@@ -1768,17 +1768,17 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
1768 return @memset(buffer, 0);1768 return @memset(buffer, 0);
1769 } else if (@typeInfo(T).Int.bits == 8) {1769 } else if (@typeInfo(T).Int.bits == 8) {
1770 @memset(buffer, 0);1770 @memset(buffer, 0);
1771 buffer[buffer.len - 1] = @bitCast(u8, value);1771 buffer[buffer.len - 1] = @as(u8, @bitCast(value));
1772 return;1772 return;
1773 }1773 }
17741774
1775 // TODO I want to call writeIntBig here but comptime eval facilities aren't good enough1775 // TODO I want to call writeIntBig here but comptime eval facilities aren't good enough
1776 const uint = std.meta.Int(.unsigned, @typeInfo(T).Int.bits);1776 const uint = std.meta.Int(.unsigned, @typeInfo(T).Int.bits);
1777 var bits = @bitCast(uint, value);1777 var bits = @as(uint, @bitCast(value));
1778 var index: usize = buffer.len;1778 var index: usize = buffer.len;
1779 while (index != 0) {1779 while (index != 0) {
1780 index -= 1;1780 index -= 1;
1781 buffer[index] = @truncate(u8, bits);1781 buffer[index] = @as(u8, @truncate(bits));
1782 bits >>= 8;1782 bits >>= 8;
1783 }1783 }
1784}1784}
...@@ -1822,7 +1822,7 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value...@@ -1822,7 +1822,7 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value
1822 const uN = std.meta.Int(.unsigned, @bitSizeOf(T));1822 const uN = std.meta.Int(.unsigned, @bitSizeOf(T));
1823 const Log2N = std.math.Log2Int(T);1823 const Log2N = std.math.Log2Int(T);
18241824
1825 const bit_shift = @intCast(u3, bit_offset % 8);1825 const bit_shift = @as(u3, @intCast(bit_offset % 8));
1826 const write_size = (bit_count + bit_shift + 7) / 8;1826 const write_size = (bit_count + bit_shift + 7) / 8;
1827 const lowest_byte = switch (endian) {1827 const lowest_byte = switch (endian) {
1828 .Big => bytes.len - (bit_offset / 8) - write_size,1828 .Big => bytes.len - (bit_offset / 8) - write_size,
...@@ -1833,8 +1833,8 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value...@@ -1833,8 +1833,8 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value
1833 if (write_size == 1) {1833 if (write_size == 1) {
1834 // Single byte writes are handled specially, since we need to mask bits1834 // Single byte writes are handled specially, since we need to mask bits
1835 // on both ends of the byte.1835 // on both ends of the byte.
1836 const mask = (@as(u8, 0xff) >> @intCast(u3, 8 - bit_count));1836 const mask = (@as(u8, 0xff) >> @as(u3, @intCast(8 - bit_count)));
1837 const new_bits = @intCast(u8, @bitCast(uN, value) & mask) << bit_shift;1837 const new_bits = @as(u8, @intCast(@as(uN, @bitCast(value)) & mask)) << bit_shift;
1838 write_bytes[0] = (write_bytes[0] & ~(mask << bit_shift)) | new_bits;1838 write_bytes[0] = (write_bytes[0] & ~(mask << bit_shift)) | new_bits;
1839 return;1839 return;
1840 }1840 }
...@@ -1843,31 +1843,31 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value...@@ -1843,31 +1843,31 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value
18431843
1844 // Iterate bytes forward for Little-endian, backward for Big-endian1844 // Iterate bytes forward for Little-endian, backward for Big-endian
1845 const delta: i2 = if (endian == .Big) -1 else 1;1845 const delta: i2 = if (endian == .Big) -1 else 1;
1846 const start = if (endian == .Big) @intCast(isize, write_bytes.len - 1) else 0;1846 const start = if (endian == .Big) @as(isize, @intCast(write_bytes.len - 1)) else 0;
18471847
1848 var i: isize = start; // isize for signed index arithmetic1848 var i: isize = start; // isize for signed index arithmetic
18491849
1850 // Write first byte, using a mask to protects bits preceding bit_offset1850 // Write first byte, using a mask to protects bits preceding bit_offset
1851 const head_mask = @as(u8, 0xff) >> bit_shift;1851 const head_mask = @as(u8, 0xff) >> bit_shift;
1852 write_bytes[@intCast(usize, i)] &= ~(head_mask << bit_shift);1852 write_bytes[@as(usize, @intCast(i))] &= ~(head_mask << bit_shift);
1853 write_bytes[@intCast(usize, i)] |= @intCast(u8, @bitCast(uN, remaining) & head_mask) << bit_shift;1853 write_bytes[@as(usize, @intCast(i))] |= @as(u8, @intCast(@as(uN, @bitCast(remaining)) & head_mask)) << bit_shift;
1854 remaining >>= @intCast(Log2N, @as(u4, 8) - bit_shift);1854 remaining >>= @as(Log2N, @intCast(@as(u4, 8) - bit_shift));
1855 i += delta;1855 i += delta;
18561856
1857 // Write bytes[1..bytes.len - 1]1857 // Write bytes[1..bytes.len - 1]
1858 if (@bitSizeOf(T) > 8) {1858 if (@bitSizeOf(T) > 8) {
1859 const loop_end = start + delta * (@intCast(isize, write_size) - 1);1859 const loop_end = start + delta * (@as(isize, @intCast(write_size)) - 1);
1860 while (i != loop_end) : (i += delta) {1860 while (i != loop_end) : (i += delta) {
1861 write_bytes[@intCast(usize, i)] = @truncate(u8, @bitCast(uN, remaining));1861 write_bytes[@as(usize, @intCast(i))] = @as(u8, @truncate(@as(uN, @bitCast(remaining))));
1862 remaining >>= 8;1862 remaining >>= 8;
1863 }1863 }
1864 }1864 }
18651865
1866 // Write last byte, using a mask to protect bits following bit_offset + bit_count1866 // Write last byte, using a mask to protect bits following bit_offset + bit_count
1867 const following_bits = -%@truncate(u3, bit_shift + bit_count);1867 const following_bits = -%@as(u3, @truncate(bit_shift + bit_count));
1868 const tail_mask = (@as(u8, 0xff) << following_bits) >> following_bits;1868 const tail_mask = (@as(u8, 0xff) << following_bits) >> following_bits;
1869 write_bytes[@intCast(usize, i)] &= ~tail_mask;1869 write_bytes[@as(usize, @intCast(i))] &= ~tail_mask;
1870 write_bytes[@intCast(usize, i)] |= @intCast(u8, @bitCast(uN, remaining) & tail_mask);1870 write_bytes[@as(usize, @intCast(i))] |= @as(u8, @intCast(@as(uN, @bitCast(remaining)) & tail_mask));
1871}1871}
18721872
1873test "writeIntBig and writeIntLittle" {1873test "writeIntBig and writeIntLittle" {
...@@ -3799,15 +3799,14 @@ pub fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize {...@@ -3799,15 +3799,14 @@ pub fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize {
3799/// type.3799/// type.
3800pub fn alignPointer(ptr: anytype, align_to: usize) ?@TypeOf(ptr) {3800pub fn alignPointer(ptr: anytype, align_to: usize) ?@TypeOf(ptr) {
3801 const adjust_off = alignPointerOffset(ptr, align_to) orelse return null;3801 const adjust_off = alignPointerOffset(ptr, align_to) orelse return null;
3802 const T = @TypeOf(ptr);
3803 // Avoid the use of ptrFromInt to avoid losing the pointer provenance info.3802 // Avoid the use of ptrFromInt to avoid losing the pointer provenance info.
3804 return @alignCast(@typeInfo(T).Pointer.alignment, ptr + adjust_off);3803 return @alignCast(ptr + adjust_off);
3805}3804}
38063805
3807test "alignPointer" {3806test "alignPointer" {
3808 const S = struct {3807 const S = struct {
3809 fn checkAlign(comptime T: type, base: usize, align_to: usize, expected: usize) !void {3808 fn checkAlign(comptime T: type, base: usize, align_to: usize, expected: usize) !void {
3810 var ptr = @ptrFromInt(T, base);3809 var ptr = @as(T, @ptrFromInt(base));
3811 var aligned = alignPointer(ptr, align_to);3810 var aligned = alignPointer(ptr, align_to);
3812 try testing.expectEqual(expected, @intFromPtr(aligned));3811 try testing.expectEqual(expected, @intFromPtr(aligned));
3813 }3812 }
...@@ -3854,9 +3853,7 @@ fn AsBytesReturnType(comptime P: type) type {...@@ -3854,9 +3853,7 @@ fn AsBytesReturnType(comptime P: type) type {
38543853
3855/// Given a pointer to a single item, returns a slice of the underlying bytes, preserving pointer attributes.3854/// Given a pointer to a single item, returns a slice of the underlying bytes, preserving pointer attributes.
3856pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr)) {3855pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr)) {
3857 const P = @TypeOf(ptr);3856 return @ptrCast(@alignCast(ptr));
3858 const T = AsBytesReturnType(P);
3859 return @ptrCast(T, @alignCast(meta.alignment(T), ptr));
3860}3857}
38613858
3862test "asBytes" {3859test "asBytes" {
...@@ -3902,7 +3899,7 @@ test "asBytes" {...@@ -3902,7 +3899,7 @@ test "asBytes" {
39023899
3903test "asBytes preserves pointer attributes" {3900test "asBytes preserves pointer attributes" {
3904 const inArr: u32 align(16) = 0xDEADBEEF;3901 const inArr: u32 align(16) = 0xDEADBEEF;
3905 const inPtr = @ptrCast(*align(16) const volatile u32, &inArr);3902 const inPtr = @as(*align(16) const volatile u32, @ptrCast(&inArr));
3906 const outSlice = asBytes(inPtr);3903 const outSlice = asBytes(inPtr);
39073904
3908 const in = @typeInfo(@TypeOf(inPtr)).Pointer;3905 const in = @typeInfo(@TypeOf(inPtr)).Pointer;
...@@ -3948,7 +3945,7 @@ fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {...@@ -3948,7 +3945,7 @@ fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
3948/// Given a pointer to an array of bytes, returns a pointer to a value of the specified type3945/// Given a pointer to an array of bytes, returns a pointer to a value of the specified type
3949/// backed by those bytes, preserving pointer attributes.3946/// backed by those bytes, preserving pointer attributes.
3950pub fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T, @TypeOf(bytes)) {3947pub fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T, @TypeOf(bytes)) {
3951 return @ptrCast(BytesAsValueReturnType(T, @TypeOf(bytes)), bytes);3948 return @as(BytesAsValueReturnType(T, @TypeOf(bytes)), @ptrCast(bytes));
3952}3949}
39533950
3954test "bytesAsValue" {3951test "bytesAsValue" {
...@@ -3993,7 +3990,7 @@ test "bytesAsValue" {...@@ -3993,7 +3990,7 @@ test "bytesAsValue" {
39933990
3994test "bytesAsValue preserves pointer attributes" {3991test "bytesAsValue preserves pointer attributes" {
3995 const inArr align(16) = [4]u8{ 0xDE, 0xAD, 0xBE, 0xEF };3992 const inArr align(16) = [4]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
3996 const inSlice = @ptrCast(*align(16) const volatile [4]u8, &inArr)[0..];3993 const inSlice = @as(*align(16) const volatile [4]u8, @ptrCast(&inArr))[0..];
3997 const outPtr = bytesAsValue(u32, inSlice);3994 const outPtr = bytesAsValue(u32, inSlice);
39983995
3999 const in = @typeInfo(@TypeOf(inSlice)).Pointer;3996 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
...@@ -4043,7 +4040,7 @@ pub fn bytesAsSlice(comptime T: type, bytes: anytype) BytesAsSliceReturnType(T,...@@ -4043,7 +4040,7 @@ pub fn bytesAsSlice(comptime T: type, bytes: anytype) BytesAsSliceReturnType(T,
40434040
4044 const cast_target = CopyPtrAttrs(@TypeOf(bytes), .Many, T);4041 const cast_target = CopyPtrAttrs(@TypeOf(bytes), .Many, T);
40454042
4046 return @ptrCast(cast_target, bytes)[0..@divExact(bytes.len, @sizeOf(T))];4043 return @as(cast_target, @ptrCast(bytes))[0..@divExact(bytes.len, @sizeOf(T))];
4047}4044}
40484045
4049test "bytesAsSlice" {4046test "bytesAsSlice" {
...@@ -4101,7 +4098,7 @@ test "bytesAsSlice with specified alignment" {...@@ -4101,7 +4098,7 @@ test "bytesAsSlice with specified alignment" {
41014098
4102test "bytesAsSlice preserves pointer attributes" {4099test "bytesAsSlice preserves pointer attributes" {
4103 const inArr align(16) = [4]u8{ 0xDE, 0xAD, 0xBE, 0xEF };4100 const inArr align(16) = [4]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
4104 const inSlice = @ptrCast(*align(16) const volatile [4]u8, &inArr)[0..];4101 const inSlice = @as(*align(16) const volatile [4]u8, @ptrCast(&inArr))[0..];
4105 const outSlice = bytesAsSlice(u16, inSlice);4102 const outSlice = bytesAsSlice(u16, inSlice);
41064103
4107 const in = @typeInfo(@TypeOf(inSlice)).Pointer;4104 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
...@@ -4133,7 +4130,7 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) {...@@ -4133,7 +4130,7 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) {
41334130
4134 const cast_target = CopyPtrAttrs(Slice, .Many, u8);4131 const cast_target = CopyPtrAttrs(Slice, .Many, u8);
41354132
4136 return @ptrCast(cast_target, slice)[0 .. slice.len * @sizeOf(meta.Elem(Slice))];4133 return @as(cast_target, @ptrCast(slice))[0 .. slice.len * @sizeOf(meta.Elem(Slice))];
4137}4134}
41384135
4139test "sliceAsBytes" {4136test "sliceAsBytes" {
...@@ -4197,7 +4194,7 @@ test "sliceAsBytes and bytesAsSlice back" {...@@ -4197,7 +4194,7 @@ test "sliceAsBytes and bytesAsSlice back" {
41974194
4198test "sliceAsBytes preserves pointer attributes" {4195test "sliceAsBytes preserves pointer attributes" {
4199 const inArr align(16) = [2]u16{ 0xDEAD, 0xBEEF };4196 const inArr align(16) = [2]u16{ 0xDEAD, 0xBEEF };
4200 const inSlice = @ptrCast(*align(16) const volatile [2]u16, &inArr)[0..];4197 const inSlice = @as(*align(16) const volatile [2]u16, @ptrCast(&inArr))[0..];
4201 const outSlice = sliceAsBytes(inSlice);4198 const outSlice = sliceAsBytes(inSlice);
42024199
4203 const in = @typeInfo(@TypeOf(inSlice)).Pointer;4200 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
...@@ -4218,7 +4215,7 @@ pub fn alignForward(comptime T: type, addr: T, alignment: T) T {...@@ -4218,7 +4215,7 @@ pub fn alignForward(comptime T: type, addr: T, alignment: T) T {
4218}4215}
42194216
4220pub fn alignForwardLog2(addr: usize, log2_alignment: u8) usize {4217pub fn alignForwardLog2(addr: usize, log2_alignment: u8) usize {
4221 const alignment = @as(usize, 1) << @intCast(math.Log2Int(usize), log2_alignment);4218 const alignment = @as(usize, 1) << @as(math.Log2Int(usize), @intCast(log2_alignment));
4222 return alignForward(usize, addr, alignment);4219 return alignForward(usize, addr, alignment);
4223}4220}
42244221
...@@ -4282,7 +4279,7 @@ pub fn doNotOptimizeAway(val: anytype) void {...@@ -4282,7 +4279,7 @@ pub fn doNotOptimizeAway(val: anytype) void {
4282/// .stage2_c doesn't support asm blocks yet, so use volatile stores instead4279/// .stage2_c doesn't support asm blocks yet, so use volatile stores instead
4283var deopt_target: if (builtin.zig_backend == .stage2_c) u8 else void = undefined;4280var deopt_target: if (builtin.zig_backend == .stage2_c) u8 else void = undefined;
4284fn doNotOptimizeAwayC(ptr: anytype) void {4281fn doNotOptimizeAwayC(ptr: anytype) void {
4285 const dest = @ptrCast(*volatile u8, &deopt_target);4282 const dest = @as(*volatile u8, @ptrCast(&deopt_target));
4286 for (asBytes(ptr)) |b| {4283 for (asBytes(ptr)) |b| {
4287 dest.* = b;4284 dest.* = b;
4288 }4285 }
...@@ -4433,7 +4430,7 @@ pub fn alignInBytes(bytes: []u8, comptime new_alignment: usize) ?[]align(new_ali...@@ -4433,7 +4430,7 @@ pub fn alignInBytes(bytes: []u8, comptime new_alignment: usize) ?[]align(new_ali
4433 error.Overflow => return null,4430 error.Overflow => return null,
4434 };4431 };
4435 const alignment_offset = begin_address_aligned - begin_address;4432 const alignment_offset = begin_address_aligned - begin_address;
4436 return @alignCast(new_alignment, bytes[alignment_offset .. alignment_offset + new_length]);4433 return @alignCast(bytes[alignment_offset .. alignment_offset + new_length]);
4437}4434}
44384435
4439/// Returns the largest sub-slice within the given slice that conforms to the new alignment,4436/// Returns the largest sub-slice within the given slice that conforms to the new alignment,
...@@ -4445,7 +4442,7 @@ pub fn alignInSlice(slice: anytype, comptime new_alignment: usize) ?AlignedSlice...@@ -4445,7 +4442,7 @@ pub fn alignInSlice(slice: anytype, comptime new_alignment: usize) ?AlignedSlice
4445 const Element = @TypeOf(slice[0]);4442 const Element = @TypeOf(slice[0]);
4446 const slice_length_bytes = aligned_bytes.len - (aligned_bytes.len % @sizeOf(Element));4443 const slice_length_bytes = aligned_bytes.len - (aligned_bytes.len % @sizeOf(Element));
4447 const aligned_slice = bytesAsSlice(Element, aligned_bytes[0..slice_length_bytes]);4444 const aligned_slice = bytesAsSlice(Element, aligned_bytes[0..slice_length_bytes]);
4448 return @alignCast(new_alignment, aligned_slice);4445 return @alignCast(aligned_slice);
4449}4446}
44504447
4451test "read/write(Var)PackedInt" {4448test "read/write(Var)PackedInt" {
...@@ -4490,8 +4487,8 @@ test "read/write(Var)PackedInt" {...@@ -4490,8 +4487,8 @@ test "read/write(Var)PackedInt" {
4490 for ([_]PackedType{4487 for ([_]PackedType{
4491 ~@as(PackedType, 0), // all ones: -1 iN / maxInt uN4488 ~@as(PackedType, 0), // all ones: -1 iN / maxInt uN
4492 @as(PackedType, 0), // all zeros: 0 iN / 0 uN4489 @as(PackedType, 0), // all zeros: 0 iN / 0 uN
4493 @bitCast(PackedType, @as(iPackedType, math.maxInt(iPackedType))), // maxInt iN4490 @as(PackedType, @bitCast(@as(iPackedType, math.maxInt(iPackedType)))), // maxInt iN
4494 @bitCast(PackedType, @as(iPackedType, math.minInt(iPackedType))), // maxInt iN4491 @as(PackedType, @bitCast(@as(iPackedType, math.minInt(iPackedType)))), // maxInt iN
4495 random.int(PackedType), // random4492 random.int(PackedType), // random
4496 random.int(PackedType), // random4493 random.int(PackedType), // random
4497 }) |write_value| {4494 }) |write_value| {
...@@ -4502,11 +4499,11 @@ test "read/write(Var)PackedInt" {...@@ -4502,11 +4499,11 @@ test "read/write(Var)PackedInt" {
45024499
4503 // Read4500 // Read
4504 const read_value1 = readPackedInt(PackedType, asBytes(&value), offset, native_endian);4501 const read_value1 = readPackedInt(PackedType, asBytes(&value), offset, native_endian);
4505 try expect(read_value1 == @bitCast(PackedType, @truncate(uPackedType, value >> @intCast(Log2T, offset))));4502 try expect(read_value1 == @as(PackedType, @bitCast(@as(uPackedType, @truncate(value >> @as(Log2T, @intCast(offset)))))));
45064503
4507 // Write4504 // Write
4508 writePackedInt(PackedType, asBytes(&value), offset, write_value, native_endian);4505 writePackedInt(PackedType, asBytes(&value), offset, write_value, native_endian);
4509 try expect(write_value == @bitCast(PackedType, @truncate(uPackedType, value >> @intCast(Log2T, offset))));4506 try expect(write_value == @as(PackedType, @bitCast(@as(uPackedType, @truncate(value >> @as(Log2T, @intCast(offset)))))));
45104507
4511 // Read again4508 // Read again
4512 const read_value2 = readPackedInt(PackedType, asBytes(&value), offset, native_endian);4509 const read_value2 = readPackedInt(PackedType, asBytes(&value), offset, native_endian);
...@@ -4515,9 +4512,9 @@ test "read/write(Var)PackedInt" {...@@ -4515,9 +4512,9 @@ test "read/write(Var)PackedInt" {
4515 // Verify bits outside of the target integer are unmodified4512 // Verify bits outside of the target integer are unmodified
4516 const diff_bits = init_value ^ value;4513 const diff_bits = init_value ^ value;
4517 if (offset != offset_at_end)4514 if (offset != offset_at_end)
4518 try expect(diff_bits >> @intCast(Log2T, offset + @bitSizeOf(PackedType)) == 0);4515 try expect(diff_bits >> @as(Log2T, @intCast(offset + @bitSizeOf(PackedType))) == 0);
4519 if (offset != 0)4516 if (offset != 0)
4520 try expect(diff_bits << @intCast(Log2T, @bitSizeOf(BackingType) - offset) == 0);4517 try expect(diff_bits << @as(Log2T, @intCast(@bitSizeOf(BackingType) - offset)) == 0);
4521 }4518 }
45224519
4523 { // Fixed-size Read/Write (Foreign-endian)4520 { // Fixed-size Read/Write (Foreign-endian)
...@@ -4527,11 +4524,11 @@ test "read/write(Var)PackedInt" {...@@ -4527,11 +4524,11 @@ test "read/write(Var)PackedInt" {
45274524
4528 // Read4525 // Read
4529 const read_value1 = readPackedInt(PackedType, asBytes(&value), offset, foreign_endian);4526 const read_value1 = readPackedInt(PackedType, asBytes(&value), offset, foreign_endian);
4530 try expect(read_value1 == @bitCast(PackedType, @truncate(uPackedType, @byteSwap(value) >> @intCast(Log2T, offset))));4527 try expect(read_value1 == @as(PackedType, @bitCast(@as(uPackedType, @truncate(@byteSwap(value) >> @as(Log2T, @intCast(offset)))))));
45314528
4532 // Write4529 // Write
4533 writePackedInt(PackedType, asBytes(&value), offset, write_value, foreign_endian);4530 writePackedInt(PackedType, asBytes(&value), offset, write_value, foreign_endian);
4534 try expect(write_value == @bitCast(PackedType, @truncate(uPackedType, @byteSwap(value) >> @intCast(Log2T, offset))));4531 try expect(write_value == @as(PackedType, @bitCast(@as(uPackedType, @truncate(@byteSwap(value) >> @as(Log2T, @intCast(offset)))))));
45354532
4536 // Read again4533 // Read again
4537 const read_value2 = readPackedInt(PackedType, asBytes(&value), offset, foreign_endian);4534 const read_value2 = readPackedInt(PackedType, asBytes(&value), offset, foreign_endian);
...@@ -4540,9 +4537,9 @@ test "read/write(Var)PackedInt" {...@@ -4540,9 +4537,9 @@ test "read/write(Var)PackedInt" {
4540 // Verify bits outside of the target integer are unmodified4537 // Verify bits outside of the target integer are unmodified
4541 const diff_bits = init_value ^ @byteSwap(value);4538 const diff_bits = init_value ^ @byteSwap(value);
4542 if (offset != offset_at_end)4539 if (offset != offset_at_end)
4543 try expect(diff_bits >> @intCast(Log2T, offset + @bitSizeOf(PackedType)) == 0);4540 try expect(diff_bits >> @as(Log2T, @intCast(offset + @bitSizeOf(PackedType))) == 0);
4544 if (offset != 0)4541 if (offset != 0)
4545 try expect(diff_bits << @intCast(Log2T, @bitSizeOf(BackingType) - offset) == 0);4542 try expect(diff_bits << @as(Log2T, @intCast(@bitSizeOf(BackingType) - offset)) == 0);
4546 }4543 }
45474544
4548 const signedness = @typeInfo(PackedType).Int.signedness;4545 const signedness = @typeInfo(PackedType).Int.signedness;
...@@ -4559,11 +4556,11 @@ test "read/write(Var)PackedInt" {...@@ -4559,11 +4556,11 @@ test "read/write(Var)PackedInt" {
45594556
4560 // Read4557 // Read
4561 const read_value1 = readVarPackedInt(U, asBytes(&value), offset, @bitSizeOf(PackedType), native_endian, signedness);4558 const read_value1 = readVarPackedInt(U, asBytes(&value), offset, @bitSizeOf(PackedType), native_endian, signedness);
4562 try expect(read_value1 == @bitCast(PackedType, @truncate(uPackedType, value >> @intCast(Log2T, offset))));4559 try expect(read_value1 == @as(PackedType, @bitCast(@as(uPackedType, @truncate(value >> @as(Log2T, @intCast(offset)))))));
45634560
4564 // Write4561 // Write
4565 writeVarPackedInt(asBytes(&value), offset, @bitSizeOf(PackedType), @as(U, write_value), native_endian);4562 writeVarPackedInt(asBytes(&value), offset, @bitSizeOf(PackedType), @as(U, write_value), native_endian);
4566 try expect(write_value == @bitCast(PackedType, @truncate(uPackedType, value >> @intCast(Log2T, offset))));4563 try expect(write_value == @as(PackedType, @bitCast(@as(uPackedType, @truncate(value >> @as(Log2T, @intCast(offset)))))));
45674564
4568 // Read again4565 // Read again
4569 const read_value2 = readVarPackedInt(U, asBytes(&value), offset, @bitSizeOf(PackedType), native_endian, signedness);4566 const read_value2 = readVarPackedInt(U, asBytes(&value), offset, @bitSizeOf(PackedType), native_endian, signedness);
...@@ -4572,9 +4569,9 @@ test "read/write(Var)PackedInt" {...@@ -4572,9 +4569,9 @@ test "read/write(Var)PackedInt" {
4572 // Verify bits outside of the target integer are unmodified4569 // Verify bits outside of the target integer are unmodified
4573 const diff_bits = init_value ^ value;4570 const diff_bits = init_value ^ value;
4574 if (offset != offset_at_end)4571 if (offset != offset_at_end)
4575 try expect(diff_bits >> @intCast(Log2T, offset + @bitSizeOf(PackedType)) == 0);4572 try expect(diff_bits >> @as(Log2T, @intCast(offset + @bitSizeOf(PackedType))) == 0);
4576 if (offset != 0)4573 if (offset != 0)
4577 try expect(diff_bits << @intCast(Log2T, @bitSizeOf(BackingType) - offset) == 0);4574 try expect(diff_bits << @as(Log2T, @intCast(@bitSizeOf(BackingType) - offset)) == 0);
4578 }4575 }
45794576
4580 { // Variable-size Read/Write (Foreign-endian)4577 { // Variable-size Read/Write (Foreign-endian)
...@@ -4587,11 +4584,11 @@ test "read/write(Var)PackedInt" {...@@ -4587,11 +4584,11 @@ test "read/write(Var)PackedInt" {
45874584
4588 // Read4585 // Read
4589 const read_value1 = readVarPackedInt(U, asBytes(&value), offset, @bitSizeOf(PackedType), foreign_endian, signedness);4586 const read_value1 = readVarPackedInt(U, asBytes(&value), offset, @bitSizeOf(PackedType), foreign_endian, signedness);
4590 try expect(read_value1 == @bitCast(PackedType, @truncate(uPackedType, @byteSwap(value) >> @intCast(Log2T, offset))));4587 try expect(read_value1 == @as(PackedType, @bitCast(@as(uPackedType, @truncate(@byteSwap(value) >> @as(Log2T, @intCast(offset)))))));
45914588
4592 // Write4589 // Write
4593 writeVarPackedInt(asBytes(&value), offset, @bitSizeOf(PackedType), @as(U, write_value), foreign_endian);4590 writeVarPackedInt(asBytes(&value), offset, @bitSizeOf(PackedType), @as(U, write_value), foreign_endian);
4594 try expect(write_value == @bitCast(PackedType, @truncate(uPackedType, @byteSwap(value) >> @intCast(Log2T, offset))));4591 try expect(write_value == @as(PackedType, @bitCast(@as(uPackedType, @truncate(@byteSwap(value) >> @as(Log2T, @intCast(offset)))))));
45954592
4596 // Read again4593 // Read again
4597 const read_value2 = readVarPackedInt(U, asBytes(&value), offset, @bitSizeOf(PackedType), foreign_endian, signedness);4594 const read_value2 = readVarPackedInt(U, asBytes(&value), offset, @bitSizeOf(PackedType), foreign_endian, signedness);
...@@ -4600,9 +4597,9 @@ test "read/write(Var)PackedInt" {...@@ -4600,9 +4597,9 @@ test "read/write(Var)PackedInt" {
4600 // Verify bits outside of the target integer are unmodified4597 // Verify bits outside of the target integer are unmodified
4601 const diff_bits = init_value ^ @byteSwap(value);4598 const diff_bits = init_value ^ @byteSwap(value);
4602 if (offset != offset_at_end)4599 if (offset != offset_at_end)
4603 try expect(diff_bits >> @intCast(Log2T, offset + @bitSizeOf(PackedType)) == 0);4600 try expect(diff_bits >> @as(Log2T, @intCast(offset + @bitSizeOf(PackedType))) == 0);
4604 if (offset != 0)4601 if (offset != 0)
4605 try expect(diff_bits << @intCast(Log2T, @bitSizeOf(BackingType) - offset) == 0);4602 try expect(diff_bits << @as(Log2T, @intCast(@bitSizeOf(BackingType) - offset)) == 0);
4606 }4603 }
4607 }4604 }
4608 }4605 }
lib/std/mem/Allocator.zig+10-8
...@@ -101,7 +101,7 @@ pub inline fn rawFree(self: Allocator, buf: []u8, log2_buf_align: u8, ret_addr:...@@ -101,7 +101,7 @@ pub inline fn rawFree(self: Allocator, buf: []u8, log2_buf_align: u8, ret_addr:
101/// Returns a pointer to undefined memory.101/// Returns a pointer to undefined memory.
102/// Call `destroy` with the result to free the memory.102/// Call `destroy` with the result to free the memory.
103pub fn create(self: Allocator, comptime T: type) Error!*T {103pub fn create(self: Allocator, comptime T: type) Error!*T {
104 if (@sizeOf(T) == 0) return @ptrFromInt(*T, math.maxInt(usize));104 if (@sizeOf(T) == 0) return @as(*T, @ptrFromInt(math.maxInt(usize)));
105 const slice = try self.allocAdvancedWithRetAddr(T, null, 1, @returnAddress());105 const slice = try self.allocAdvancedWithRetAddr(T, null, 1, @returnAddress());
106 return &slice[0];106 return &slice[0];
107}107}
...@@ -112,7 +112,7 @@ pub fn destroy(self: Allocator, ptr: anytype) void {...@@ -112,7 +112,7 @@ pub fn destroy(self: Allocator, ptr: anytype) void {
112 const info = @typeInfo(@TypeOf(ptr)).Pointer;112 const info = @typeInfo(@TypeOf(ptr)).Pointer;
113 const T = info.child;113 const T = info.child;
114 if (@sizeOf(T) == 0) return;114 if (@sizeOf(T) == 0) return;
115 const non_const_ptr = @ptrCast([*]u8, @constCast(ptr));115 const non_const_ptr = @as([*]u8, @ptrCast(@constCast(ptr)));
116 self.rawFree(non_const_ptr[0..@sizeOf(T)], math.log2(info.alignment), @returnAddress());116 self.rawFree(non_const_ptr[0..@sizeOf(T)], math.log2(info.alignment), @returnAddress());
117}117}
118118
...@@ -209,15 +209,15 @@ pub fn allocAdvancedWithRetAddr(...@@ -209,15 +209,15 @@ pub fn allocAdvancedWithRetAddr(
209209
210 if (n == 0) {210 if (n == 0) {
211 const ptr = comptime std.mem.alignBackward(usize, math.maxInt(usize), a);211 const ptr = comptime std.mem.alignBackward(usize, math.maxInt(usize), a);
212 return @ptrFromInt([*]align(a) T, ptr)[0..0];212 return @as([*]align(a) T, @ptrFromInt(ptr))[0..0];
213 }213 }
214214
215 const byte_count = math.mul(usize, @sizeOf(T), n) catch return Error.OutOfMemory;215 const byte_count = math.mul(usize, @sizeOf(T), n) catch return Error.OutOfMemory;
216 const byte_ptr = self.rawAlloc(byte_count, log2a(a), return_address) orelse return Error.OutOfMemory;216 const byte_ptr = self.rawAlloc(byte_count, log2a(a), return_address) orelse return Error.OutOfMemory;
217 // TODO: https://github.com/ziglang/zig/issues/4298217 // TODO: https://github.com/ziglang/zig/issues/4298
218 @memset(byte_ptr[0..byte_count], undefined);218 @memset(byte_ptr[0..byte_count], undefined);
219 const byte_slice = byte_ptr[0..byte_count];219 const byte_slice: []align(a) u8 = @alignCast(byte_ptr[0..byte_count]);
220 return mem.bytesAsSlice(T, @alignCast(a, byte_slice));220 return mem.bytesAsSlice(T, byte_slice);
221}221}
222222
223/// Requests to modify the size of an allocation. It is guaranteed to not move223/// Requests to modify the size of an allocation. It is guaranteed to not move
...@@ -268,7 +268,7 @@ pub fn reallocAdvanced(...@@ -268,7 +268,7 @@ pub fn reallocAdvanced(
268 if (new_n == 0) {268 if (new_n == 0) {
269 self.free(old_mem);269 self.free(old_mem);
270 const ptr = comptime std.mem.alignBackward(usize, math.maxInt(usize), Slice.alignment);270 const ptr = comptime std.mem.alignBackward(usize, math.maxInt(usize), Slice.alignment);
271 return @ptrFromInt([*]align(Slice.alignment) T, ptr)[0..0];271 return @as([*]align(Slice.alignment) T, @ptrFromInt(ptr))[0..0];
272 }272 }
273273
274 const old_byte_slice = mem.sliceAsBytes(old_mem);274 const old_byte_slice = mem.sliceAsBytes(old_mem);
...@@ -276,7 +276,8 @@ pub fn reallocAdvanced(...@@ -276,7 +276,8 @@ pub fn reallocAdvanced(
276 // Note: can't set shrunk memory to undefined as memory shouldn't be modified on realloc failure276 // Note: can't set shrunk memory to undefined as memory shouldn't be modified on realloc failure
277 if (mem.isAligned(@intFromPtr(old_byte_slice.ptr), Slice.alignment)) {277 if (mem.isAligned(@intFromPtr(old_byte_slice.ptr), Slice.alignment)) {
278 if (self.rawResize(old_byte_slice, log2a(Slice.alignment), byte_count, return_address)) {278 if (self.rawResize(old_byte_slice, log2a(Slice.alignment), byte_count, return_address)) {
279 return mem.bytesAsSlice(T, @alignCast(Slice.alignment, old_byte_slice.ptr[0..byte_count]));279 const new_bytes: []align(Slice.alignment) u8 = @alignCast(old_byte_slice.ptr[0..byte_count]);
280 return mem.bytesAsSlice(T, new_bytes);
280 }281 }
281 }282 }
282283
...@@ -288,7 +289,8 @@ pub fn reallocAdvanced(...@@ -288,7 +289,8 @@ pub fn reallocAdvanced(
288 @memset(old_byte_slice, undefined);289 @memset(old_byte_slice, undefined);
289 self.rawFree(old_byte_slice, log2a(Slice.alignment), return_address);290 self.rawFree(old_byte_slice, log2a(Slice.alignment), return_address);
290291
291 return mem.bytesAsSlice(T, @alignCast(Slice.alignment, new_mem[0..byte_count]));292 const new_bytes: []align(Slice.alignment) u8 = @alignCast(new_mem[0..byte_count]);
293 return mem.bytesAsSlice(T, new_bytes);
292}294}
293295
294/// Free an array allocated with `alloc`. To free a single item,296/// Free an array allocated with `alloc`. To free a single item,
lib/std/meta.zig+9-9
...@@ -185,18 +185,18 @@ pub fn sentinel(comptime T: type) ?Elem(T) {...@@ -185,18 +185,18 @@ pub fn sentinel(comptime T: type) ?Elem(T) {
185 switch (@typeInfo(T)) {185 switch (@typeInfo(T)) {
186 .Array => |info| {186 .Array => |info| {
187 const sentinel_ptr = info.sentinel orelse return null;187 const sentinel_ptr = info.sentinel orelse return null;
188 return @ptrCast(*const info.child, sentinel_ptr).*;188 return @as(*const info.child, @ptrCast(sentinel_ptr)).*;
189 },189 },
190 .Pointer => |info| {190 .Pointer => |info| {
191 switch (info.size) {191 switch (info.size) {
192 .Many, .Slice => {192 .Many, .Slice => {
193 const sentinel_ptr = info.sentinel orelse return null;193 const sentinel_ptr = info.sentinel orelse return null;
194 return @ptrCast(*align(1) const info.child, sentinel_ptr).*;194 return @as(*align(1) const info.child, @ptrCast(sentinel_ptr)).*;
195 },195 },
196 .One => switch (@typeInfo(info.child)) {196 .One => switch (@typeInfo(info.child)) {
197 .Array => |array_info| {197 .Array => |array_info| {
198 const sentinel_ptr = array_info.sentinel orelse return null;198 const sentinel_ptr = array_info.sentinel orelse return null;
199 return @ptrCast(*align(1) const array_info.child, sentinel_ptr).*;199 return @as(*align(1) const array_info.child, @ptrCast(sentinel_ptr)).*;
200 },200 },
201 else => {},201 else => {},
202 },202 },
...@@ -241,7 +241,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {...@@ -241,7 +241,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
241 .Array = .{241 .Array = .{
242 .len = array_info.len,242 .len = array_info.len,
243 .child = array_info.child,243 .child = array_info.child,
244 .sentinel = @ptrCast(?*const anyopaque, &sentinel_val),244 .sentinel = @as(?*const anyopaque, @ptrCast(&sentinel_val)),
245 },245 },
246 }),246 }),
247 .is_allowzero = info.is_allowzero,247 .is_allowzero = info.is_allowzero,
...@@ -259,7 +259,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {...@@ -259,7 +259,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
259 .address_space = info.address_space,259 .address_space = info.address_space,
260 .child = info.child,260 .child = info.child,
261 .is_allowzero = info.is_allowzero,261 .is_allowzero = info.is_allowzero,
262 .sentinel = @ptrCast(?*const anyopaque, &sentinel_val),262 .sentinel = @as(?*const anyopaque, @ptrCast(&sentinel_val)),
263 },263 },
264 }),264 }),
265 else => {},265 else => {},
...@@ -277,7 +277,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {...@@ -277,7 +277,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
277 .address_space = ptr_info.address_space,277 .address_space = ptr_info.address_space,
278 .child = ptr_info.child,278 .child = ptr_info.child,
279 .is_allowzero = ptr_info.is_allowzero,279 .is_allowzero = ptr_info.is_allowzero,
280 .sentinel = @ptrCast(?*const anyopaque, &sentinel_val),280 .sentinel = @as(?*const anyopaque, @ptrCast(&sentinel_val)),
281 },281 },
282 }),282 }),
283 },283 },
...@@ -929,8 +929,8 @@ test "intToEnum with error return" {...@@ -929,8 +929,8 @@ test "intToEnum with error return" {
929 try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);929 try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
930 try testing.expect(intToEnum(E2, one) catch unreachable == E2.B);930 try testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
931 try testing.expect(intToEnum(E3, zero) catch unreachable == E3.A);931 try testing.expect(intToEnum(E3, zero) catch unreachable == E3.A);
932 try testing.expect(intToEnum(E3, 127) catch unreachable == @enumFromInt(E3, 127));932 try testing.expect(intToEnum(E3, 127) catch unreachable == @as(E3, @enumFromInt(127)));
933 try testing.expect(intToEnum(E3, -128) catch unreachable == @enumFromInt(E3, -128));933 try testing.expect(intToEnum(E3, -128) catch unreachable == @as(E3, @enumFromInt(-128)));
934 try testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));934 try testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));
935 try testing.expectError(error.InvalidEnumTag, intToEnum(E3, 128));935 try testing.expectError(error.InvalidEnumTag, intToEnum(E3, 128));
936 try testing.expectError(error.InvalidEnumTag, intToEnum(E3, -129));936 try testing.expectError(error.InvalidEnumTag, intToEnum(E3, -129));
...@@ -943,7 +943,7 @@ pub fn intToEnum(comptime EnumTag: type, tag_int: anytype) IntToEnumError!EnumTa...@@ -943,7 +943,7 @@ pub fn intToEnum(comptime EnumTag: type, tag_int: anytype) IntToEnumError!EnumTa
943943
944 if (!enum_info.is_exhaustive) {944 if (!enum_info.is_exhaustive) {
945 if (std.math.cast(enum_info.tag_type, tag_int)) |tag| {945 if (std.math.cast(enum_info.tag_type, tag_int)) |tag| {
946 return @enumFromInt(EnumTag, tag);946 return @as(EnumTag, @enumFromInt(tag));
947 }947 }
948 return error.InvalidEnumTag;948 return error.InvalidEnumTag;
949 }949 }
lib/std/meta/trailer_flags.zig+3-3
...@@ -72,7 +72,7 @@ pub fn TrailerFlags(comptime Fields: type) type {...@@ -72,7 +72,7 @@ pub fn TrailerFlags(comptime Fields: type) type {
72 pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: FieldValues) void {72 pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: FieldValues) void {
73 inline for (@typeInfo(Fields).Struct.fields, 0..) |field, i| {73 inline for (@typeInfo(Fields).Struct.fields, 0..) |field, i| {
74 if (@field(fields, field.name)) |value|74 if (@field(fields, field.name)) |value|
75 self.set(p, @enumFromInt(FieldEnum, i), value);75 self.set(p, @as(FieldEnum, @enumFromInt(i)), value);
76 }76 }
77 }77 }
7878
...@@ -89,14 +89,14 @@ pub fn TrailerFlags(comptime Fields: type) type {...@@ -89,14 +89,14 @@ pub fn TrailerFlags(comptime Fields: type) type {
89 if (@sizeOf(Field(field)) == 0)89 if (@sizeOf(Field(field)) == 0)
90 return undefined;90 return undefined;
91 const off = self.offset(field);91 const off = self.offset(field);
92 return @ptrCast(*Field(field), @alignCast(@alignOf(Field(field)), p + off));92 return @ptrCast(@alignCast(p + off));
93 }93 }
9494
95 pub fn ptrConst(self: Self, p: [*]align(@alignOf(Fields)) const u8, comptime field: FieldEnum) *const Field(field) {95 pub fn ptrConst(self: Self, p: [*]align(@alignOf(Fields)) const u8, comptime field: FieldEnum) *const Field(field) {
96 if (@sizeOf(Field(field)) == 0)96 if (@sizeOf(Field(field)) == 0)
97 return undefined;97 return undefined;
98 const off = self.offset(field);98 const off = self.offset(field);
99 return @ptrCast(*const Field(field), @alignCast(@alignOf(Field(field)), p + off));99 return @ptrCast(@alignCast(p + off));
100 }100 }
101101
102 pub fn offset(self: Self, comptime field: FieldEnum) usize {102 pub fn offset(self: Self, comptime field: FieldEnum) usize {
lib/std/meta/trait.zig+1-1
...@@ -237,7 +237,7 @@ pub fn isManyItemPtr(comptime T: type) bool {...@@ -237,7 +237,7 @@ pub fn isManyItemPtr(comptime T: type) bool {
237237
238test "isManyItemPtr" {238test "isManyItemPtr" {
239 const array = [_]u8{0} ** 10;239 const array = [_]u8{0} ** 10;
240 const mip = @ptrCast([*]const u8, &array[0]);240 const mip = @as([*]const u8, @ptrCast(&array[0]));
241 try testing.expect(isManyItemPtr(@TypeOf(mip)));241 try testing.expect(isManyItemPtr(@TypeOf(mip)));
242 try testing.expect(!isManyItemPtr(@TypeOf(array)));242 try testing.expect(!isManyItemPtr(@TypeOf(array)));
243 try testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));243 try testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));
lib/std/multi_array_list.zig+16-17
...@@ -78,7 +78,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -78,7 +78,7 @@ pub fn MultiArrayList(comptime T: type) type {
78 const casted_ptr: [*]F = if (@sizeOf(F) == 0)78 const casted_ptr: [*]F = if (@sizeOf(F) == 0)
79 undefined79 undefined
80 else80 else
81 @ptrCast([*]F, @alignCast(@alignOf(F), byte_ptr));81 @ptrCast(@alignCast(byte_ptr));
82 return casted_ptr[0..self.len];82 return casted_ptr[0..self.len];
83 }83 }
8484
...@@ -89,14 +89,14 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -89,14 +89,14 @@ pub fn MultiArrayList(comptime T: type) type {
89 else => unreachable,89 else => unreachable,
90 };90 };
91 inline for (fields, 0..) |field_info, i| {91 inline for (fields, 0..) |field_info, i| {
92 self.items(@enumFromInt(Field, i))[index] = @field(e, field_info.name);92 self.items(@as(Field, @enumFromInt(i)))[index] = @field(e, field_info.name);
93 }93 }
94 }94 }
9595
96 pub fn get(self: Slice, index: usize) T {96 pub fn get(self: Slice, index: usize) T {
97 var result: Elem = undefined;97 var result: Elem = undefined;
98 inline for (fields, 0..) |field_info, i| {98 inline for (fields, 0..) |field_info, i| {
99 @field(result, field_info.name) = self.items(@enumFromInt(Field, i))[index];99 @field(result, field_info.name) = self.items(@as(Field, @enumFromInt(i)))[index];
100 }100 }
101 return switch (@typeInfo(T)) {101 return switch (@typeInfo(T)) {
102 .Struct => result,102 .Struct => result,
...@@ -110,10 +110,9 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -110,10 +110,9 @@ pub fn MultiArrayList(comptime T: type) type {
110 return .{};110 return .{};
111 }111 }
112 const unaligned_ptr = self.ptrs[sizes.fields[0]];112 const unaligned_ptr = self.ptrs[sizes.fields[0]];
113 const aligned_ptr = @alignCast(@alignOf(Elem), unaligned_ptr);113 const aligned_ptr: [*]align(@alignOf(Elem)) u8 = @alignCast(unaligned_ptr);
114 const casted_ptr = @ptrCast([*]align(@alignOf(Elem)) u8, aligned_ptr);
115 return .{114 return .{
116 .bytes = casted_ptr,115 .bytes = aligned_ptr,
117 .len = self.len,116 .len = self.len,
118 .capacity = self.capacity,117 .capacity = self.capacity,
119 };118 };
...@@ -294,7 +293,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -294,7 +293,7 @@ pub fn MultiArrayList(comptime T: type) type {
294 };293 };
295 const slices = self.slice();294 const slices = self.slice();
296 inline for (fields, 0..) |field_info, field_index| {295 inline for (fields, 0..) |field_info, field_index| {
297 const field_slice = slices.items(@enumFromInt(Field, field_index));296 const field_slice = slices.items(@as(Field, @enumFromInt(field_index)));
298 var i: usize = self.len - 1;297 var i: usize = self.len - 1;
299 while (i > index) : (i -= 1) {298 while (i > index) : (i -= 1) {
300 field_slice[i] = field_slice[i - 1];299 field_slice[i] = field_slice[i - 1];
...@@ -309,7 +308,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -309,7 +308,7 @@ pub fn MultiArrayList(comptime T: type) type {
309 pub fn swapRemove(self: *Self, index: usize) void {308 pub fn swapRemove(self: *Self, index: usize) void {
310 const slices = self.slice();309 const slices = self.slice();
311 inline for (fields, 0..) |_, i| {310 inline for (fields, 0..) |_, i| {
312 const field_slice = slices.items(@enumFromInt(Field, i));311 const field_slice = slices.items(@as(Field, @enumFromInt(i)));
313 field_slice[index] = field_slice[self.len - 1];312 field_slice[index] = field_slice[self.len - 1];
314 field_slice[self.len - 1] = undefined;313 field_slice[self.len - 1] = undefined;
315 }314 }
...@@ -321,7 +320,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -321,7 +320,7 @@ pub fn MultiArrayList(comptime T: type) type {
321 pub fn orderedRemove(self: *Self, index: usize) void {320 pub fn orderedRemove(self: *Self, index: usize) void {
322 const slices = self.slice();321 const slices = self.slice();
323 inline for (fields, 0..) |_, field_index| {322 inline for (fields, 0..) |_, field_index| {
324 const field_slice = slices.items(@enumFromInt(Field, field_index));323 const field_slice = slices.items(@as(Field, @enumFromInt(field_index)));
325 var i = index;324 var i = index;
326 while (i < self.len - 1) : (i += 1) {325 while (i < self.len - 1) : (i += 1) {
327 field_slice[i] = field_slice[i + 1];326 field_slice[i] = field_slice[i + 1];
...@@ -358,7 +357,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -358,7 +357,7 @@ pub fn MultiArrayList(comptime T: type) type {
358 const self_slice = self.slice();357 const self_slice = self.slice();
359 inline for (fields, 0..) |field_info, i| {358 inline for (fields, 0..) |field_info, i| {
360 if (@sizeOf(field_info.type) != 0) {359 if (@sizeOf(field_info.type) != 0) {
361 const field = @enumFromInt(Field, i);360 const field = @as(Field, @enumFromInt(i));
362 const dest_slice = self_slice.items(field)[new_len..];361 const dest_slice = self_slice.items(field)[new_len..];
363 // We use memset here for more efficient codegen in safety-checked,362 // We use memset here for more efficient codegen in safety-checked,
364 // valgrind-enabled builds. Otherwise the valgrind client request363 // valgrind-enabled builds. Otherwise the valgrind client request
...@@ -379,7 +378,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -379,7 +378,7 @@ pub fn MultiArrayList(comptime T: type) type {
379 const other_slice = other.slice();378 const other_slice = other.slice();
380 inline for (fields, 0..) |field_info, i| {379 inline for (fields, 0..) |field_info, i| {
381 if (@sizeOf(field_info.type) != 0) {380 if (@sizeOf(field_info.type) != 0) {
382 const field = @enumFromInt(Field, i);381 const field = @as(Field, @enumFromInt(i));
383 @memcpy(other_slice.items(field), self_slice.items(field));382 @memcpy(other_slice.items(field), self_slice.items(field));
384 }383 }
385 }384 }
...@@ -440,7 +439,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -440,7 +439,7 @@ pub fn MultiArrayList(comptime T: type) type {
440 const other_slice = other.slice();439 const other_slice = other.slice();
441 inline for (fields, 0..) |field_info, i| {440 inline for (fields, 0..) |field_info, i| {
442 if (@sizeOf(field_info.type) != 0) {441 if (@sizeOf(field_info.type) != 0) {
443 const field = @enumFromInt(Field, i);442 const field = @as(Field, @enumFromInt(i));
444 @memcpy(other_slice.items(field), self_slice.items(field));443 @memcpy(other_slice.items(field), self_slice.items(field));
445 }444 }
446 }445 }
...@@ -459,7 +458,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -459,7 +458,7 @@ pub fn MultiArrayList(comptime T: type) type {
459 const result_slice = result.slice();458 const result_slice = result.slice();
460 inline for (fields, 0..) |field_info, i| {459 inline for (fields, 0..) |field_info, i| {
461 if (@sizeOf(field_info.type) != 0) {460 if (@sizeOf(field_info.type) != 0) {
462 const field = @enumFromInt(Field, i);461 const field = @as(Field, @enumFromInt(i));
463 @memcpy(result_slice.items(field), self_slice.items(field));462 @memcpy(result_slice.items(field), self_slice.items(field));
464 }463 }
465 }464 }
...@@ -476,7 +475,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -476,7 +475,7 @@ pub fn MultiArrayList(comptime T: type) type {
476 pub fn swap(sc: @This(), a_index: usize, b_index: usize) void {475 pub fn swap(sc: @This(), a_index: usize, b_index: usize) void {
477 inline for (fields, 0..) |field_info, i| {476 inline for (fields, 0..) |field_info, i| {
478 if (@sizeOf(field_info.type) != 0) {477 if (@sizeOf(field_info.type) != 0) {
479 const field = @enumFromInt(Field, i);478 const field = @as(Field, @enumFromInt(i));
480 const ptr = sc.slice.items(field);479 const ptr = sc.slice.items(field);
481 mem.swap(field_info.type, &ptr[a_index], &ptr[b_index]);480 mem.swap(field_info.type, &ptr[a_index], &ptr[b_index]);
482 }481 }
...@@ -592,9 +591,9 @@ test "basic usage" {...@@ -592,9 +591,9 @@ test "basic usage" {
592 var i: usize = 0;591 var i: usize = 0;
593 while (i < 6) : (i += 1) {592 while (i < 6) : (i += 1) {
594 try list.append(ally, .{593 try list.append(ally, .{
595 .a = @intCast(u32, 4 + i),594 .a = @as(u32, @intCast(4 + i)),
596 .b = "whatever",595 .b = "whatever",
597 .c = @intCast(u8, 'd' + i),596 .c = @as(u8, @intCast('d' + i)),
598 });597 });
599 }598 }
600599
...@@ -791,7 +790,7 @@ test "union" {...@@ -791,7 +790,7 @@ test "union" {
791790
792 // Add 6 more things to force a capacity increase.791 // Add 6 more things to force a capacity increase.
793 for (0..6) |i| {792 for (0..6) |i| {
794 try list.append(ally, .{ .a = @intCast(u32, 4 + i) });793 try list.append(ally, .{ .a = @as(u32, @intCast(4 + i)) });
795 }794 }
796795
797 try testing.expectEqualSlices(796 try testing.expectEqualSlices(
lib/std/net.zig+39-39
...@@ -137,8 +137,8 @@ pub const Address = extern union {...@@ -137,8 +137,8 @@ pub const Address = extern union {
137 /// on the address family.137 /// on the address family.
138 pub fn initPosix(addr: *align(4) const os.sockaddr) Address {138 pub fn initPosix(addr: *align(4) const os.sockaddr) Address {
139 switch (addr.family) {139 switch (addr.family) {
140 os.AF.INET => return Address{ .in = Ip4Address{ .sa = @ptrCast(*const os.sockaddr.in, addr).* } },140 os.AF.INET => return Address{ .in = Ip4Address{ .sa = @as(*const os.sockaddr.in, @ptrCast(addr)).* } },
141 os.AF.INET6 => return Address{ .in6 = Ip6Address{ .sa = @ptrCast(*const os.sockaddr.in6, addr).* } },141 os.AF.INET6 => return Address{ .in6 = Ip6Address{ .sa = @as(*const os.sockaddr.in6, @ptrCast(addr)).* } },
142 else => unreachable,142 else => unreachable,
143 }143 }
144 }144 }
...@@ -165,8 +165,8 @@ pub const Address = extern union {...@@ -165,8 +165,8 @@ pub const Address = extern union {
165 }165 }
166166
167 pub fn eql(a: Address, b: Address) bool {167 pub fn eql(a: Address, b: Address) bool {
168 const a_bytes = @ptrCast([*]const u8, &a.any)[0..a.getOsSockLen()];168 const a_bytes = @as([*]const u8, @ptrCast(&a.any))[0..a.getOsSockLen()];
169 const b_bytes = @ptrCast([*]const u8, &b.any)[0..b.getOsSockLen()];169 const b_bytes = @as([*]const u8, @ptrCast(&b.any))[0..b.getOsSockLen()];
170 return mem.eql(u8, a_bytes, b_bytes);170 return mem.eql(u8, a_bytes, b_bytes);
171 }171 }
172172
...@@ -187,7 +187,7 @@ pub const Address = extern union {...@@ -187,7 +187,7 @@ pub const Address = extern union {
187 // provide the full buffer size (e.g. getsockname, getpeername, recvfrom, accept).187 // provide the full buffer size (e.g. getsockname, getpeername, recvfrom, accept).
188 //188 //
189 // To access the path, std.mem.sliceTo(&address.un.path, 0) should be used.189 // To access the path, std.mem.sliceTo(&address.un.path, 0) should be used.
190 return @intCast(os.socklen_t, @sizeOf(os.sockaddr.un));190 return @as(os.socklen_t, @intCast(@sizeOf(os.sockaddr.un)));
191 },191 },
192192
193 else => unreachable,193 else => unreachable,
...@@ -260,7 +260,7 @@ pub const Ip4Address = extern struct {...@@ -260,7 +260,7 @@ pub const Ip4Address = extern struct {
260 return Ip4Address{260 return Ip4Address{
261 .sa = os.sockaddr.in{261 .sa = os.sockaddr.in{
262 .port = mem.nativeToBig(u16, port),262 .port = mem.nativeToBig(u16, port),
263 .addr = @ptrCast(*align(1) const u32, &addr).*,263 .addr = @as(*align(1) const u32, @ptrCast(&addr)).*,
264 },264 },
265 };265 };
266 }266 }
...@@ -285,7 +285,7 @@ pub const Ip4Address = extern struct {...@@ -285,7 +285,7 @@ pub const Ip4Address = extern struct {
285 ) !void {285 ) !void {
286 if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);286 if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
287 _ = options;287 _ = options;
288 const bytes = @ptrCast(*const [4]u8, &self.sa.addr);288 const bytes = @as(*const [4]u8, @ptrCast(&self.sa.addr));
289 try std.fmt.format(out_stream, "{}.{}.{}.{}:{}", .{289 try std.fmt.format(out_stream, "{}.{}.{}.{}:{}", .{
290 bytes[0],290 bytes[0],
291 bytes[1],291 bytes[1],
...@@ -354,9 +354,9 @@ pub const Ip6Address = extern struct {...@@ -354,9 +354,9 @@ pub const Ip6Address = extern struct {
354 if (index == 14) {354 if (index == 14) {
355 return error.InvalidEnd;355 return error.InvalidEnd;
356 }356 }
357 ip_slice[index] = @truncate(u8, x >> 8);357 ip_slice[index] = @as(u8, @truncate(x >> 8));
358 index += 1;358 index += 1;
359 ip_slice[index] = @truncate(u8, x);359 ip_slice[index] = @as(u8, @truncate(x));
360 index += 1;360 index += 1;
361361
362 x = 0;362 x = 0;
...@@ -408,13 +408,13 @@ pub const Ip6Address = extern struct {...@@ -408,13 +408,13 @@ pub const Ip6Address = extern struct {
408 }408 }
409409
410 if (index == 14) {410 if (index == 14) {
411 ip_slice[14] = @truncate(u8, x >> 8);411 ip_slice[14] = @as(u8, @truncate(x >> 8));
412 ip_slice[15] = @truncate(u8, x);412 ip_slice[15] = @as(u8, @truncate(x));
413 return result;413 return result;
414 } else {414 } else {
415 ip_slice[index] = @truncate(u8, x >> 8);415 ip_slice[index] = @as(u8, @truncate(x >> 8));
416 index += 1;416 index += 1;
417 ip_slice[index] = @truncate(u8, x);417 ip_slice[index] = @as(u8, @truncate(x));
418 index += 1;418 index += 1;
419 @memcpy(result.sa.addr[16 - index ..][0..index], ip_slice[0..index]);419 @memcpy(result.sa.addr[16 - index ..][0..index], ip_slice[0..index]);
420 return result;420 return result;
...@@ -473,9 +473,9 @@ pub const Ip6Address = extern struct {...@@ -473,9 +473,9 @@ pub const Ip6Address = extern struct {
473 if (index == 14) {473 if (index == 14) {
474 return error.InvalidEnd;474 return error.InvalidEnd;
475 }475 }
476 ip_slice[index] = @truncate(u8, x >> 8);476 ip_slice[index] = @as(u8, @truncate(x >> 8));
477 index += 1;477 index += 1;
478 ip_slice[index] = @truncate(u8, x);478 ip_slice[index] = @as(u8, @truncate(x));
479 index += 1;479 index += 1;
480480
481 x = 0;481 x = 0;
...@@ -542,13 +542,13 @@ pub const Ip6Address = extern struct {...@@ -542,13 +542,13 @@ pub const Ip6Address = extern struct {
542 result.sa.scope_id = resolved_scope_id;542 result.sa.scope_id = resolved_scope_id;
543543
544 if (index == 14) {544 if (index == 14) {
545 ip_slice[14] = @truncate(u8, x >> 8);545 ip_slice[14] = @as(u8, @truncate(x >> 8));
546 ip_slice[15] = @truncate(u8, x);546 ip_slice[15] = @as(u8, @truncate(x));
547 return result;547 return result;
548 } else {548 } else {
549 ip_slice[index] = @truncate(u8, x >> 8);549 ip_slice[index] = @as(u8, @truncate(x >> 8));
550 index += 1;550 index += 1;
551 ip_slice[index] = @truncate(u8, x);551 ip_slice[index] = @as(u8, @truncate(x));
552 index += 1;552 index += 1;
553 @memcpy(result.sa.addr[16 - index ..][0..index], ip_slice[0..index]);553 @memcpy(result.sa.addr[16 - index ..][0..index], ip_slice[0..index]);
554 return result;554 return result;
...@@ -597,7 +597,7 @@ pub const Ip6Address = extern struct {...@@ -597,7 +597,7 @@ pub const Ip6Address = extern struct {
597 });597 });
598 return;598 return;
599 }599 }
600 const big_endian_parts = @ptrCast(*align(1) const [8]u16, &self.sa.addr);600 const big_endian_parts = @as(*align(1) const [8]u16, @ptrCast(&self.sa.addr));
601 const native_endian_parts = switch (native_endian) {601 const native_endian_parts = switch (native_endian) {
602 .Big => big_endian_parts.*,602 .Big => big_endian_parts.*,
603 .Little => blk: {603 .Little => blk: {
...@@ -668,7 +668,7 @@ fn if_nametoindex(name: []const u8) !u32 {...@@ -668,7 +668,7 @@ fn if_nametoindex(name: []const u8) !u32 {
668 // TODO investigate if this needs to be integrated with evented I/O.668 // TODO investigate if this needs to be integrated with evented I/O.
669 try os.ioctl_SIOCGIFINDEX(sockfd, &ifr);669 try os.ioctl_SIOCGIFINDEX(sockfd, &ifr);
670670
671 return @bitCast(u32, ifr.ifru.ivalue);671 return @as(u32, @bitCast(ifr.ifru.ivalue));
672 }672 }
673673
674 if (comptime builtin.target.os.tag.isDarwin()) {674 if (comptime builtin.target.os.tag.isDarwin()) {
...@@ -682,7 +682,7 @@ fn if_nametoindex(name: []const u8) !u32 {...@@ -682,7 +682,7 @@ fn if_nametoindex(name: []const u8) !u32 {
682 const index = os.system.if_nametoindex(if_slice);682 const index = os.system.if_nametoindex(if_slice);
683 if (index == 0)683 if (index == 0)
684 return error.InterfaceNotFound;684 return error.InterfaceNotFound;
685 return @bitCast(u32, index);685 return @as(u32, @bitCast(index));
686 }686 }
687687
688 @compileError("std.net.if_nametoindex unimplemented for this OS");688 @compileError("std.net.if_nametoindex unimplemented for this OS");
...@@ -804,8 +804,8 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get...@@ -804,8 +804,8 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get
804 var first = true;804 var first = true;
805 while (true) {805 while (true) {
806 const rc = ws2_32.getaddrinfo(name_c.ptr, port_c.ptr, &hints, &res);806 const rc = ws2_32.getaddrinfo(name_c.ptr, port_c.ptr, &hints, &res);
807 switch (@enumFromInt(os.windows.ws2_32.WinsockError, @intCast(u16, rc))) {807 switch (@as(os.windows.ws2_32.WinsockError, @enumFromInt(@as(u16, @intCast(rc))))) {
808 @enumFromInt(os.windows.ws2_32.WinsockError, 0) => break,808 @as(os.windows.ws2_32.WinsockError, @enumFromInt(0)) => break,
809 .WSATRY_AGAIN => return error.TemporaryNameServerFailure,809 .WSATRY_AGAIN => return error.TemporaryNameServerFailure,
810 .WSANO_RECOVERY => return error.NameServerFailure,810 .WSANO_RECOVERY => return error.NameServerFailure,
811 .WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported,811 .WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported,
...@@ -841,7 +841,7 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get...@@ -841,7 +841,7 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get
841 var i: usize = 0;841 var i: usize = 0;
842 while (it) |info| : (it = info.next) {842 while (it) |info| : (it = info.next) {
843 const addr = info.addr orelse continue;843 const addr = info.addr orelse continue;
844 result.addrs[i] = Address.initPosix(@alignCast(4, addr));844 result.addrs[i] = Address.initPosix(@alignCast(addr));
845845
846 if (info.canonname) |n| {846 if (info.canonname) |n| {
847 if (result.canon_name == null) {847 if (result.canon_name == null) {
...@@ -874,7 +874,7 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get...@@ -874,7 +874,7 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get
874 };874 };
875 var res: ?*os.addrinfo = null;875 var res: ?*os.addrinfo = null;
876 switch (sys.getaddrinfo(name_c.ptr, port_c.ptr, &hints, &res)) {876 switch (sys.getaddrinfo(name_c.ptr, port_c.ptr, &hints, &res)) {
877 @enumFromInt(sys.EAI, 0) => {},877 @as(sys.EAI, @enumFromInt(0)) => {},
878 .ADDRFAMILY => return error.HostLacksNetworkAddresses,878 .ADDRFAMILY => return error.HostLacksNetworkAddresses,
879 .AGAIN => return error.TemporaryNameServerFailure,879 .AGAIN => return error.TemporaryNameServerFailure,
880 .BADFLAGS => unreachable, // Invalid hints880 .BADFLAGS => unreachable, // Invalid hints
...@@ -908,7 +908,7 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get...@@ -908,7 +908,7 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get
908 var i: usize = 0;908 var i: usize = 0;
909 while (it) |info| : (it = info.next) {909 while (it) |info| : (it = info.next) {
910 const addr = info.addr orelse continue;910 const addr = info.addr orelse continue;
911 result.addrs[i] = Address.initPosix(@alignCast(4, addr));911 result.addrs[i] = Address.initPosix(@alignCast(addr));
912912
913 if (info.canonname) |n| {913 if (info.canonname) |n| {
914 if (result.canon_name == null) {914 if (result.canon_name == null) {
...@@ -1020,7 +1020,7 @@ fn linuxLookupName(...@@ -1020,7 +1020,7 @@ fn linuxLookupName(
1020 for (addrs.items, 0..) |*addr, i| {1020 for (addrs.items, 0..) |*addr, i| {
1021 var key: i32 = 0;1021 var key: i32 = 0;
1022 var sa6: os.sockaddr.in6 = undefined;1022 var sa6: os.sockaddr.in6 = undefined;
1023 @memset(@ptrCast([*]u8, &sa6)[0..@sizeOf(os.sockaddr.in6)], 0);1023 @memset(@as([*]u8, @ptrCast(&sa6))[0..@sizeOf(os.sockaddr.in6)], 0);
1024 var da6 = os.sockaddr.in6{1024 var da6 = os.sockaddr.in6{
1025 .family = os.AF.INET6,1025 .family = os.AF.INET6,
1026 .scope_id = addr.addr.in6.sa.scope_id,1026 .scope_id = addr.addr.in6.sa.scope_id,
...@@ -1029,7 +1029,7 @@ fn linuxLookupName(...@@ -1029,7 +1029,7 @@ fn linuxLookupName(
1029 .addr = [1]u8{0} ** 16,1029 .addr = [1]u8{0} ** 16,
1030 };1030 };
1031 var sa4: os.sockaddr.in = undefined;1031 var sa4: os.sockaddr.in = undefined;
1032 @memset(@ptrCast([*]u8, &sa4)[0..@sizeOf(os.sockaddr.in)], 0);1032 @memset(@as([*]u8, @ptrCast(&sa4))[0..@sizeOf(os.sockaddr.in)], 0);
1033 var da4 = os.sockaddr.in{1033 var da4 = os.sockaddr.in{
1034 .family = os.AF.INET,1034 .family = os.AF.INET,
1035 .port = 65535,1035 .port = 65535,
...@@ -1042,18 +1042,18 @@ fn linuxLookupName(...@@ -1042,18 +1042,18 @@ fn linuxLookupName(
1042 var dalen: os.socklen_t = undefined;1042 var dalen: os.socklen_t = undefined;
1043 if (addr.addr.any.family == os.AF.INET6) {1043 if (addr.addr.any.family == os.AF.INET6) {
1044 da6.addr = addr.addr.in6.sa.addr;1044 da6.addr = addr.addr.in6.sa.addr;
1045 da = @ptrCast(*os.sockaddr, &da6);1045 da = @ptrCast(&da6);
1046 dalen = @sizeOf(os.sockaddr.in6);1046 dalen = @sizeOf(os.sockaddr.in6);
1047 sa = @ptrCast(*os.sockaddr, &sa6);1047 sa = @ptrCast(&sa6);
1048 salen = @sizeOf(os.sockaddr.in6);1048 salen = @sizeOf(os.sockaddr.in6);
1049 } else {1049 } else {
1050 sa6.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;1050 sa6.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;
1051 da6.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;1051 da6.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;
1052 mem.writeIntNative(u32, da6.addr[12..], addr.addr.in.sa.addr);1052 mem.writeIntNative(u32, da6.addr[12..], addr.addr.in.sa.addr);
1053 da4.addr = addr.addr.in.sa.addr;1053 da4.addr = addr.addr.in.sa.addr;
1054 da = @ptrCast(*os.sockaddr, &da4);1054 da = @ptrCast(&da4);
1055 dalen = @sizeOf(os.sockaddr.in);1055 dalen = @sizeOf(os.sockaddr.in);
1056 sa = @ptrCast(*os.sockaddr, &sa4);1056 sa = @ptrCast(&sa4);
1057 salen = @sizeOf(os.sockaddr.in);1057 salen = @sizeOf(os.sockaddr.in);
1058 }1058 }
1059 const dpolicy = policyOf(da6.addr);1059 const dpolicy = policyOf(da6.addr);
...@@ -1070,7 +1070,7 @@ fn linuxLookupName(...@@ -1070,7 +1070,7 @@ fn linuxLookupName(
1070 os.getsockname(fd, sa, &salen) catch break :syscalls;1070 os.getsockname(fd, sa, &salen) catch break :syscalls;
1071 if (addr.addr.any.family == os.AF.INET) {1071 if (addr.addr.any.family == os.AF.INET) {
1072 // TODO sa6.addr[12..16] should return *[4]u8, making this cast unnecessary.1072 // TODO sa6.addr[12..16] should return *[4]u8, making this cast unnecessary.
1073 mem.writeIntNative(u32, @ptrCast(*[4]u8, &sa6.addr[12]), sa4.addr);1073 mem.writeIntNative(u32, @as(*[4]u8, @ptrCast(&sa6.addr[12])), sa4.addr);
1074 }1074 }
1075 if (dscope == @as(i32, scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE;1075 if (dscope == @as(i32, scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE;
1076 if (dlabel == labelOf(sa6.addr)) key |= DAS_MATCHINGLABEL;1076 if (dlabel == labelOf(sa6.addr)) key |= DAS_MATCHINGLABEL;
...@@ -1079,7 +1079,7 @@ fn linuxLookupName(...@@ -1079,7 +1079,7 @@ fn linuxLookupName(
1079 key |= dprec << DAS_PREC_SHIFT;1079 key |= dprec << DAS_PREC_SHIFT;
1080 key |= (15 - dscope) << DAS_SCOPE_SHIFT;1080 key |= (15 - dscope) << DAS_SCOPE_SHIFT;
1081 key |= prefixlen << DAS_PREFIX_SHIFT;1081 key |= prefixlen << DAS_PREFIX_SHIFT;
1082 key |= (MAXADDRS - @intCast(i32, i)) << DAS_ORDER_SHIFT;1082 key |= (MAXADDRS - @as(i32, @intCast(i))) << DAS_ORDER_SHIFT;
1083 addr.sortkey = key;1083 addr.sortkey = key;
1084 }1084 }
1085 mem.sort(LookupAddr, addrs.items, {}, addrCmpLessThan);1085 mem.sort(LookupAddr, addrs.items, {}, addrCmpLessThan);
...@@ -1171,7 +1171,7 @@ fn prefixMatch(s: [16]u8, d: [16]u8) u8 {...@@ -1171,7 +1171,7 @@ fn prefixMatch(s: [16]u8, d: [16]u8) u8 {
1171 // address. However the definition of the source prefix length is1171 // address. However the definition of the source prefix length is
1172 // not clear and thus this limiting is not yet implemented.1172 // not clear and thus this limiting is not yet implemented.
1173 var i: u8 = 0;1173 var i: u8 = 0;
1174 while (i < 128 and ((s[i / 8] ^ d[i / 8]) & (@as(u8, 128) >> @intCast(u3, i % 8))) == 0) : (i += 1) {}1174 while (i < 128 and ((s[i / 8] ^ d[i / 8]) & (@as(u8, 128) >> @as(u3, @intCast(i % 8)))) == 0) : (i += 1) {}
1175 return i;1175 return i;
1176}1176}
11771177
...@@ -1577,7 +1577,7 @@ fn resMSendRc(...@@ -1577,7 +1577,7 @@ fn resMSendRc(
15771577
1578 // Get local address and open/bind a socket1578 // Get local address and open/bind a socket
1579 var sa: Address = undefined;1579 var sa: Address = undefined;
1580 @memset(@ptrCast([*]u8, &sa)[0..@sizeOf(Address)], 0);1580 @memset(@as([*]u8, @ptrCast(&sa))[0..@sizeOf(Address)], 0);
1581 sa.any.family = family;1581 sa.any.family = family;
1582 try os.bind(fd, &sa.any, sl);1582 try os.bind(fd, &sa.any, sl);
15831583
...@@ -1588,13 +1588,13 @@ fn resMSendRc(...@@ -1588,13 +1588,13 @@ fn resMSendRc(
1588 }};1588 }};
1589 const retry_interval = timeout / attempts;1589 const retry_interval = timeout / attempts;
1590 var next: u32 = 0;1590 var next: u32 = 0;
1591 var t2: u64 = @bitCast(u64, std.time.milliTimestamp());1591 var t2: u64 = @as(u64, @bitCast(std.time.milliTimestamp()));
1592 var t0 = t2;1592 var t0 = t2;
1593 var t1 = t2 - retry_interval;1593 var t1 = t2 - retry_interval;
15941594
1595 var servfail_retry: usize = undefined;1595 var servfail_retry: usize = undefined;
15961596
1597 outer: while (t2 - t0 < timeout) : (t2 = @bitCast(u64, std.time.milliTimestamp())) {1597 outer: while (t2 - t0 < timeout) : (t2 = @as(u64, @bitCast(std.time.milliTimestamp()))) {
1598 if (t2 - t1 >= retry_interval) {1598 if (t2 - t1 >= retry_interval) {
1599 // Query all configured nameservers in parallel1599 // Query all configured nameservers in parallel
1600 var i: usize = 0;1600 var i: usize = 0;
lib/std/os.zig+125-125
...@@ -494,7 +494,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {...@@ -494,7 +494,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
494 const res = if (use_c) blk: {494 const res = if (use_c) blk: {
495 const rc = std.c.getrandom(buf.ptr, buf.len, 0);495 const rc = std.c.getrandom(buf.ptr, buf.len, 0);
496 break :blk .{496 break :blk .{
497 .num_read = @bitCast(usize, rc),497 .num_read = @as(usize, @bitCast(rc)),
498 .err = std.c.getErrno(rc),498 .err = std.c.getErrno(rc),
499 };499 };
500 } else blk: {500 } else blk: {
...@@ -608,7 +608,7 @@ pub fn abort() noreturn {...@@ -608,7 +608,7 @@ pub fn abort() noreturn {
608 sigprocmask(SIG.UNBLOCK, &sigabrtmask, null);608 sigprocmask(SIG.UNBLOCK, &sigabrtmask, null);
609609
610 // Beyond this point should be unreachable.610 // Beyond this point should be unreachable.
611 @ptrFromInt(*allowzero volatile u8, 0).* = 0;611 @as(*allowzero volatile u8, @ptrFromInt(0)).* = 0;
612 raise(SIG.KILL) catch {};612 raise(SIG.KILL) catch {};
613 exit(127); // Pid 1 might not be signalled in some containers.613 exit(127); // Pid 1 might not be signalled in some containers.
614 }614 }
...@@ -678,10 +678,10 @@ pub fn exit(status: u8) noreturn {...@@ -678,10 +678,10 @@ pub fn exit(status: u8) noreturn {
678 // exit() is only available if exitBootServices() has not been called yet.678 // exit() is only available if exitBootServices() has not been called yet.
679 // This call to exit should not fail, so we don't care about its return value.679 // This call to exit should not fail, so we don't care about its return value.
680 if (uefi.system_table.boot_services) |bs| {680 if (uefi.system_table.boot_services) |bs| {
681 _ = bs.exit(uefi.handle, @enumFromInt(uefi.Status, status), 0, null);681 _ = bs.exit(uefi.handle, @as(uefi.Status, @enumFromInt(status)), 0, null);
682 }682 }
683 // If we can't exit, reboot the system instead.683 // If we can't exit, reboot the system instead.
684 uefi.system_table.runtime_services.resetSystem(uefi.tables.ResetType.ResetCold, @enumFromInt(uefi.Status, status), 0, null);684 uefi.system_table.runtime_services.resetSystem(uefi.tables.ResetType.ResetCold, @as(uefi.Status, @enumFromInt(status)), 0, null);
685 }685 }
686 system.exit(status);686 system.exit(status);
687}687}
...@@ -759,7 +759,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {...@@ -759,7 +759,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
759 while (true) {759 while (true) {
760 const rc = system.read(fd, buf.ptr, adjusted_len);760 const rc = system.read(fd, buf.ptr, adjusted_len);
761 switch (errno(rc)) {761 switch (errno(rc)) {
762 .SUCCESS => return @intCast(usize, rc),762 .SUCCESS => return @as(usize, @intCast(rc)),
763 .INTR => continue,763 .INTR => continue,
764 .INVAL => unreachable,764 .INVAL => unreachable,
765 .FAULT => unreachable,765 .FAULT => unreachable,
...@@ -818,7 +818,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {...@@ -818,7 +818,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
818 // TODO handle the case when iov_len is too large and get rid of this @intCast818 // TODO handle the case when iov_len is too large and get rid of this @intCast
819 const rc = system.readv(fd, iov.ptr, iov_count);819 const rc = system.readv(fd, iov.ptr, iov_count);
820 switch (errno(rc)) {820 switch (errno(rc)) {
821 .SUCCESS => return @intCast(usize, rc),821 .SUCCESS => return @as(usize, @intCast(rc)),
822 .INTR => continue,822 .INTR => continue,
823 .INVAL => unreachable,823 .INVAL => unreachable,
824 .FAULT => unreachable,824 .FAULT => unreachable,
...@@ -892,11 +892,11 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {...@@ -892,11 +892,11 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
892892
893 const pread_sym = if (lfs64_abi) system.pread64 else system.pread;893 const pread_sym = if (lfs64_abi) system.pread64 else system.pread;
894894
895 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned895 const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
896 while (true) {896 while (true) {
897 const rc = pread_sym(fd, buf.ptr, adjusted_len, ioffset);897 const rc = pread_sym(fd, buf.ptr, adjusted_len, ioffset);
898 switch (errno(rc)) {898 switch (errno(rc)) {
899 .SUCCESS => return @intCast(usize, rc),899 .SUCCESS => return @as(usize, @intCast(rc)),
900 .INTR => continue,900 .INTR => continue,
901 .INVAL => unreachable,901 .INVAL => unreachable,
902 .FAULT => unreachable,902 .FAULT => unreachable,
...@@ -929,7 +929,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {...@@ -929,7 +929,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
929 if (builtin.os.tag == .windows) {929 if (builtin.os.tag == .windows) {
930 var io_status_block: windows.IO_STATUS_BLOCK = undefined;930 var io_status_block: windows.IO_STATUS_BLOCK = undefined;
931 var eof_info = windows.FILE_END_OF_FILE_INFORMATION{931 var eof_info = windows.FILE_END_OF_FILE_INFORMATION{
932 .EndOfFile = @bitCast(windows.LARGE_INTEGER, length),932 .EndOfFile = @as(windows.LARGE_INTEGER, @bitCast(length)),
933 };933 };
934934
935 const rc = windows.ntdll.NtSetInformationFile(935 const rc = windows.ntdll.NtSetInformationFile(
...@@ -965,7 +965,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {...@@ -965,7 +965,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
965 while (true) {965 while (true) {
966 const ftruncate_sym = if (lfs64_abi) system.ftruncate64 else system.ftruncate;966 const ftruncate_sym = if (lfs64_abi) system.ftruncate64 else system.ftruncate;
967967
968 const ilen = @bitCast(i64, length); // the OS treats this as unsigned968 const ilen = @as(i64, @bitCast(length)); // the OS treats this as unsigned
969 switch (errno(ftruncate_sym(fd, ilen))) {969 switch (errno(ftruncate_sym(fd, ilen))) {
970 .SUCCESS => return,970 .SUCCESS => return,
971 .INTR => continue,971 .INTR => continue,
...@@ -1001,7 +1001,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {...@@ -1001,7 +1001,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
1001 if (have_pread_but_not_preadv) {1001 if (have_pread_but_not_preadv) {
1002 // We could loop here; but proper usage of `preadv` must handle partial reads anyway.1002 // We could loop here; but proper usage of `preadv` must handle partial reads anyway.
1003 // So we simply read into the first vector only.1003 // So we simply read into the first vector only.
1004 if (iov.len == 0) return @intCast(usize, 0);1004 if (iov.len == 0) return @as(usize, @intCast(0));
1005 const first = iov[0];1005 const first = iov[0];
1006 return pread(fd, first.iov_base[0..first.iov_len], offset);1006 return pread(fd, first.iov_base[0..first.iov_len], offset);
1007 }1007 }
...@@ -1030,11 +1030,11 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {...@@ -1030,11 +1030,11 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
10301030
1031 const preadv_sym = if (lfs64_abi) system.preadv64 else system.preadv;1031 const preadv_sym = if (lfs64_abi) system.preadv64 else system.preadv;
10321032
1033 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned1033 const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
1034 while (true) {1034 while (true) {
1035 const rc = preadv_sym(fd, iov.ptr, iov_count, ioffset);1035 const rc = preadv_sym(fd, iov.ptr, iov_count, ioffset);
1036 switch (errno(rc)) {1036 switch (errno(rc)) {
1037 .SUCCESS => return @bitCast(usize, rc),1037 .SUCCESS => return @as(usize, @bitCast(rc)),
1038 .INTR => continue,1038 .INTR => continue,
1039 .INVAL => unreachable,1039 .INVAL => unreachable,
1040 .FAULT => unreachable,1040 .FAULT => unreachable,
...@@ -1143,7 +1143,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {...@@ -1143,7 +1143,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
1143 while (true) {1143 while (true) {
1144 const rc = system.write(fd, bytes.ptr, adjusted_len);1144 const rc = system.write(fd, bytes.ptr, adjusted_len);
1145 switch (errno(rc)) {1145 switch (errno(rc)) {
1146 .SUCCESS => return @intCast(usize, rc),1146 .SUCCESS => return @as(usize, @intCast(rc)),
1147 .INTR => continue,1147 .INTR => continue,
1148 .INVAL => return error.InvalidArgument,1148 .INVAL => return error.InvalidArgument,
1149 .FAULT => unreachable,1149 .FAULT => unreachable,
...@@ -1212,11 +1212,11 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {...@@ -1212,11 +1212,11 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
1212 }1212 }
1213 }1213 }
12141214
1215 const iov_count = if (iov.len > IOV_MAX) IOV_MAX else @intCast(u31, iov.len);1215 const iov_count = if (iov.len > IOV_MAX) IOV_MAX else @as(u31, @intCast(iov.len));
1216 while (true) {1216 while (true) {
1217 const rc = system.writev(fd, iov.ptr, iov_count);1217 const rc = system.writev(fd, iov.ptr, iov_count);
1218 switch (errno(rc)) {1218 switch (errno(rc)) {
1219 .SUCCESS => return @intCast(usize, rc),1219 .SUCCESS => return @as(usize, @intCast(rc)),
1220 .INTR => continue,1220 .INTR => continue,
1221 .INVAL => return error.InvalidArgument,1221 .INVAL => return error.InvalidArgument,
1222 .FAULT => unreachable,1222 .FAULT => unreachable,
...@@ -1304,11 +1304,11 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {...@@ -1304,11 +1304,11 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
13041304
1305 const pwrite_sym = if (lfs64_abi) system.pwrite64 else system.pwrite;1305 const pwrite_sym = if (lfs64_abi) system.pwrite64 else system.pwrite;
13061306
1307 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned1307 const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
1308 while (true) {1308 while (true) {
1309 const rc = pwrite_sym(fd, bytes.ptr, adjusted_len, ioffset);1309 const rc = pwrite_sym(fd, bytes.ptr, adjusted_len, ioffset);
1310 switch (errno(rc)) {1310 switch (errno(rc)) {
1311 .SUCCESS => return @intCast(usize, rc),1311 .SUCCESS => return @as(usize, @intCast(rc)),
1312 .INTR => continue,1312 .INTR => continue,
1313 .INVAL => return error.InvalidArgument,1313 .INVAL => return error.InvalidArgument,
1314 .FAULT => unreachable,1314 .FAULT => unreachable,
...@@ -1390,12 +1390,12 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz...@@ -1390,12 +1390,12 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
13901390
1391 const pwritev_sym = if (lfs64_abi) system.pwritev64 else system.pwritev;1391 const pwritev_sym = if (lfs64_abi) system.pwritev64 else system.pwritev;
13921392
1393 const iov_count = if (iov.len > IOV_MAX) IOV_MAX else @intCast(u31, iov.len);1393 const iov_count = if (iov.len > IOV_MAX) IOV_MAX else @as(u31, @intCast(iov.len));
1394 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned1394 const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
1395 while (true) {1395 while (true) {
1396 const rc = pwritev_sym(fd, iov.ptr, iov_count, ioffset);1396 const rc = pwritev_sym(fd, iov.ptr, iov_count, ioffset);
1397 switch (errno(rc)) {1397 switch (errno(rc)) {
1398 .SUCCESS => return @intCast(usize, rc),1398 .SUCCESS => return @as(usize, @intCast(rc)),
1399 .INTR => continue,1399 .INTR => continue,
1400 .INVAL => return error.InvalidArgument,1400 .INVAL => return error.InvalidArgument,
1401 .FAULT => unreachable,1401 .FAULT => unreachable,
...@@ -1504,7 +1504,7 @@ pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t...@@ -1504,7 +1504,7 @@ pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t
1504 while (true) {1504 while (true) {
1505 const rc = open_sym(file_path, flags, perm);1505 const rc = open_sym(file_path, flags, perm);
1506 switch (errno(rc)) {1506 switch (errno(rc)) {
1507 .SUCCESS => return @intCast(fd_t, rc),1507 .SUCCESS => return @as(fd_t, @intCast(rc)),
1508 .INTR => continue,1508 .INTR => continue,
15091509
1510 .FAULT => unreachable,1510 .FAULT => unreachable,
...@@ -1653,11 +1653,11 @@ fn openOptionsFromFlagsWasi(fd: fd_t, oflag: u32) OpenError!WasiOpenOptions {...@@ -1653,11 +1653,11 @@ fn openOptionsFromFlagsWasi(fd: fd_t, oflag: u32) OpenError!WasiOpenOptions {
1653 rights &= fsb_cur.fs_rights_inheriting;1653 rights &= fsb_cur.fs_rights_inheriting;
16541654
1655 return WasiOpenOptions{1655 return WasiOpenOptions{
1656 .oflags = @truncate(w.oflags_t, (oflag >> 12)) & 0xfff,1656 .oflags = @as(w.oflags_t, @truncate((oflag >> 12))) & 0xfff,
1657 .lookup_flags = if (oflag & O.NOFOLLOW == 0) w.LOOKUP_SYMLINK_FOLLOW else 0,1657 .lookup_flags = if (oflag & O.NOFOLLOW == 0) w.LOOKUP_SYMLINK_FOLLOW else 0,
1658 .fs_rights_base = rights,1658 .fs_rights_base = rights,
1659 .fs_rights_inheriting = fsb_cur.fs_rights_inheriting,1659 .fs_rights_inheriting = fsb_cur.fs_rights_inheriting,
1660 .fs_flags = @truncate(w.fdflags_t, oflag & 0xfff),1660 .fs_flags = @as(w.fdflags_t, @truncate(oflag & 0xfff)),
1661 };1661 };
1662}1662}
16631663
...@@ -1717,7 +1717,7 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t)...@@ -1717,7 +1717,7 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t)
1717 while (true) {1717 while (true) {
1718 const rc = openat_sym(dir_fd, file_path, flags, mode);1718 const rc = openat_sym(dir_fd, file_path, flags, mode);
1719 switch (errno(rc)) {1719 switch (errno(rc)) {
1720 .SUCCESS => return @intCast(fd_t, rc),1720 .SUCCESS => return @as(fd_t, @intCast(rc)),
1721 .INTR => continue,1721 .INTR => continue,
17221722
1723 .FAULT => unreachable,1723 .FAULT => unreachable,
...@@ -1765,7 +1765,7 @@ pub fn openatW(dir_fd: fd_t, file_path_w: []const u16, flags: u32, mode: mode_t)...@@ -1765,7 +1765,7 @@ pub fn openatW(dir_fd: fd_t, file_path_w: []const u16, flags: u32, mode: mode_t)
1765pub fn dup(old_fd: fd_t) !fd_t {1765pub fn dup(old_fd: fd_t) !fd_t {
1766 const rc = system.dup(old_fd);1766 const rc = system.dup(old_fd);
1767 return switch (errno(rc)) {1767 return switch (errno(rc)) {
1768 .SUCCESS => return @intCast(fd_t, rc),1768 .SUCCESS => return @as(fd_t, @intCast(rc)),
1769 .MFILE => error.ProcessFdQuotaExceeded,1769 .MFILE => error.ProcessFdQuotaExceeded,
1770 .BADF => unreachable, // invalid file descriptor1770 .BADF => unreachable, // invalid file descriptor
1771 else => |err| return unexpectedErrno(err),1771 else => |err| return unexpectedErrno(err),
...@@ -2024,7 +2024,7 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {...@@ -2024,7 +2024,7 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
20242024
2025 const err = if (builtin.link_libc) blk: {2025 const err = if (builtin.link_libc) blk: {
2026 const c_err = if (std.c.getcwd(out_buffer.ptr, out_buffer.len)) |_| 0 else std.c._errno().*;2026 const c_err = if (std.c.getcwd(out_buffer.ptr, out_buffer.len)) |_| 0 else std.c._errno().*;
2027 break :blk @enumFromInt(E, c_err);2027 break :blk @as(E, @enumFromInt(c_err));
2028 } else blk: {2028 } else blk: {
2029 break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len));2029 break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len));
2030 };2030 };
...@@ -2661,12 +2661,12 @@ pub fn renameatW(...@@ -2661,12 +2661,12 @@ pub fn renameatW(
2661 const struct_len = @sizeOf(windows.FILE_RENAME_INFORMATION) - 1 + new_path_w.len * 2;2661 const struct_len = @sizeOf(windows.FILE_RENAME_INFORMATION) - 1 + new_path_w.len * 2;
2662 if (struct_len > struct_buf_len) return error.NameTooLong;2662 if (struct_len > struct_buf_len) return error.NameTooLong;
26632663
2664 const rename_info = @ptrCast(*windows.FILE_RENAME_INFORMATION, &rename_info_buf);2664 const rename_info = @as(*windows.FILE_RENAME_INFORMATION, @ptrCast(&rename_info_buf));
26652665
2666 rename_info.* = .{2666 rename_info.* = .{
2667 .ReplaceIfExists = ReplaceIfExists,2667 .ReplaceIfExists = ReplaceIfExists,
2668 .RootDirectory = if (std.fs.path.isAbsoluteWindowsWTF16(new_path_w)) null else new_dir_fd,2668 .RootDirectory = if (std.fs.path.isAbsoluteWindowsWTF16(new_path_w)) null else new_dir_fd,
2669 .FileNameLength = @intCast(u32, new_path_w.len * 2), // already checked error.NameTooLong2669 .FileNameLength = @as(u32, @intCast(new_path_w.len * 2)), // already checked error.NameTooLong
2670 .FileName = undefined,2670 .FileName = undefined,
2671 };2671 };
2672 @memcpy(@as([*]u16, &rename_info.FileName)[0..new_path_w.len], new_path_w);2672 @memcpy(@as([*]u16, &rename_info.FileName)[0..new_path_w.len], new_path_w);
...@@ -2677,7 +2677,7 @@ pub fn renameatW(...@@ -2677,7 +2677,7 @@ pub fn renameatW(
2677 src_fd,2677 src_fd,
2678 &io_status_block,2678 &io_status_block,
2679 rename_info,2679 rename_info,
2680 @intCast(u32, struct_len), // already checked for error.NameTooLong2680 @as(u32, @intCast(struct_len)), // already checked for error.NameTooLong
2681 .FileRenameInformation,2681 .FileRenameInformation,
2682 );2682 );
26832683
...@@ -3049,7 +3049,7 @@ pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8...@@ -3049,7 +3049,7 @@ pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8
3049 }3049 }
3050 const rc = system.readlink(file_path, out_buffer.ptr, out_buffer.len);3050 const rc = system.readlink(file_path, out_buffer.ptr, out_buffer.len);
3051 switch (errno(rc)) {3051 switch (errno(rc)) {
3052 .SUCCESS => return out_buffer[0..@bitCast(usize, rc)],3052 .SUCCESS => return out_buffer[0..@as(usize, @bitCast(rc))],
3053 .ACCES => return error.AccessDenied,3053 .ACCES => return error.AccessDenied,
3054 .FAULT => unreachable,3054 .FAULT => unreachable,
3055 .INVAL => return error.NotLink,3055 .INVAL => return error.NotLink,
...@@ -3115,7 +3115,7 @@ pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) Read...@@ -3115,7 +3115,7 @@ pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) Read
3115 }3115 }
3116 const rc = system.readlinkat(dirfd, file_path, out_buffer.ptr, out_buffer.len);3116 const rc = system.readlinkat(dirfd, file_path, out_buffer.ptr, out_buffer.len);
3117 switch (errno(rc)) {3117 switch (errno(rc)) {
3118 .SUCCESS => return out_buffer[0..@bitCast(usize, rc)],3118 .SUCCESS => return out_buffer[0..@as(usize, @bitCast(rc))],
3119 .ACCES => return error.AccessDenied,3119 .ACCES => return error.AccessDenied,
3120 .FAULT => unreachable,3120 .FAULT => unreachable,
3121 .INVAL => return error.NotLink,3121 .INVAL => return error.NotLink,
...@@ -3227,7 +3227,7 @@ pub fn isatty(handle: fd_t) bool {...@@ -3227,7 +3227,7 @@ pub fn isatty(handle: fd_t) bool {
3227 if (builtin.os.tag == .linux) {3227 if (builtin.os.tag == .linux) {
3228 while (true) {3228 while (true) {
3229 var wsz: linux.winsize = undefined;3229 var wsz: linux.winsize = undefined;
3230 const fd = @bitCast(usize, @as(isize, handle));3230 const fd = @as(usize, @bitCast(@as(isize, handle)));
3231 const rc = linux.syscall3(.ioctl, fd, linux.T.IOCGWINSZ, @intFromPtr(&wsz));3231 const rc = linux.syscall3(.ioctl, fd, linux.T.IOCGWINSZ, @intFromPtr(&wsz));
3232 switch (linux.getErrno(rc)) {3232 switch (linux.getErrno(rc)) {
3233 .SUCCESS => return true,3233 .SUCCESS => return true,
...@@ -3271,14 +3271,14 @@ pub fn isCygwinPty(handle: fd_t) bool {...@@ -3271,14 +3271,14 @@ pub fn isCygwinPty(handle: fd_t) bool {
3271 var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = [_]u8{0} ** (name_bytes_offset + num_name_bytes);3271 var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = [_]u8{0} ** (name_bytes_offset + num_name_bytes);
32723272
3273 var io_status_block: windows.IO_STATUS_BLOCK = undefined;3273 var io_status_block: windows.IO_STATUS_BLOCK = undefined;
3274 const rc = windows.ntdll.NtQueryInformationFile(handle, &io_status_block, &name_info_bytes, @intCast(u32, name_info_bytes.len), .FileNameInformation);3274 const rc = windows.ntdll.NtQueryInformationFile(handle, &io_status_block, &name_info_bytes, @as(u32, @intCast(name_info_bytes.len)), .FileNameInformation);
3275 switch (rc) {3275 switch (rc) {
3276 .SUCCESS => {},3276 .SUCCESS => {},
3277 .INVALID_PARAMETER => unreachable,3277 .INVALID_PARAMETER => unreachable,
3278 else => return false,3278 else => return false,
3279 }3279 }
32803280
3281 const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]);3281 const name_info = @as(*const windows.FILE_NAME_INFO, @ptrCast(&name_info_bytes[0]));
3282 const name_bytes = name_info_bytes[name_bytes_offset .. name_bytes_offset + @as(usize, name_info.FileNameLength)];3282 const name_bytes = name_info_bytes[name_bytes_offset .. name_bytes_offset + @as(usize, name_info.FileNameLength)];
3283 const name_wide = mem.bytesAsSlice(u16, name_bytes);3283 const name_wide = mem.bytesAsSlice(u16, name_bytes);
3284 // Note: The name we get from NtQueryInformationFile will be prefixed with a '\', e.g. \msys-1888ae32e00d56aa-pty0-to-master3284 // Note: The name we get from NtQueryInformationFile will be prefixed with a '\', e.g. \msys-1888ae32e00d56aa-pty0-to-master
...@@ -3325,9 +3325,9 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t...@@ -3325,9 +3325,9 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
3325 else3325 else
3326 0;3326 0;
3327 const rc = try windows.WSASocketW(3327 const rc = try windows.WSASocketW(
3328 @bitCast(i32, domain),3328 @as(i32, @bitCast(domain)),
3329 @bitCast(i32, filtered_sock_type),3329 @as(i32, @bitCast(filtered_sock_type)),
3330 @bitCast(i32, protocol),3330 @as(i32, @bitCast(protocol)),
3331 null,3331 null,
3332 0,3332 0,
3333 flags,3333 flags,
...@@ -3353,7 +3353,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t...@@ -3353,7 +3353,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
3353 const rc = system.socket(domain, filtered_sock_type, protocol);3353 const rc = system.socket(domain, filtered_sock_type, protocol);
3354 switch (errno(rc)) {3354 switch (errno(rc)) {
3355 .SUCCESS => {3355 .SUCCESS => {
3356 const fd = @intCast(fd_t, rc);3356 const fd = @as(fd_t, @intCast(rc));
3357 if (!have_sock_flags) {3357 if (!have_sock_flags) {
3358 try setSockFlags(fd, socket_type);3358 try setSockFlags(fd, socket_type);
3359 }3359 }
...@@ -3679,7 +3679,7 @@ pub fn accept(...@@ -3679,7 +3679,7 @@ pub fn accept(
3679 } else {3679 } else {
3680 switch (errno(rc)) {3680 switch (errno(rc)) {
3681 .SUCCESS => {3681 .SUCCESS => {
3682 break @intCast(socket_t, rc);3682 break @as(socket_t, @intCast(rc));
3683 },3683 },
3684 .INTR => continue,3684 .INTR => continue,
3685 .AGAIN => return error.WouldBlock,3685 .AGAIN => return error.WouldBlock,
...@@ -3723,7 +3723,7 @@ pub const EpollCreateError = error{...@@ -3723,7 +3723,7 @@ pub const EpollCreateError = error{
3723pub fn epoll_create1(flags: u32) EpollCreateError!i32 {3723pub fn epoll_create1(flags: u32) EpollCreateError!i32 {
3724 const rc = system.epoll_create1(flags);3724 const rc = system.epoll_create1(flags);
3725 switch (errno(rc)) {3725 switch (errno(rc)) {
3726 .SUCCESS => return @intCast(i32, rc),3726 .SUCCESS => return @as(i32, @intCast(rc)),
3727 else => |err| return unexpectedErrno(err),3727 else => |err| return unexpectedErrno(err),
37283728
3729 .INVAL => unreachable,3729 .INVAL => unreachable,
...@@ -3782,9 +3782,9 @@ pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*linux.epoll_event) EpollC...@@ -3782,9 +3782,9 @@ pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*linux.epoll_event) EpollC
3782pub fn epoll_wait(epfd: i32, events: []linux.epoll_event, timeout: i32) usize {3782pub fn epoll_wait(epfd: i32, events: []linux.epoll_event, timeout: i32) usize {
3783 while (true) {3783 while (true) {
3784 // TODO get rid of the @intCast3784 // TODO get rid of the @intCast
3785 const rc = system.epoll_wait(epfd, events.ptr, @intCast(u32, events.len), timeout);3785 const rc = system.epoll_wait(epfd, events.ptr, @as(u32, @intCast(events.len)), timeout);
3786 switch (errno(rc)) {3786 switch (errno(rc)) {
3787 .SUCCESS => return @intCast(usize, rc),3787 .SUCCESS => return @as(usize, @intCast(rc)),
3788 .INTR => continue,3788 .INTR => continue,
3789 .BADF => unreachable,3789 .BADF => unreachable,
3790 .FAULT => unreachable,3790 .FAULT => unreachable,
...@@ -3803,7 +3803,7 @@ pub const EventFdError = error{...@@ -3803,7 +3803,7 @@ pub const EventFdError = error{
3803pub fn eventfd(initval: u32, flags: u32) EventFdError!i32 {3803pub fn eventfd(initval: u32, flags: u32) EventFdError!i32 {
3804 const rc = system.eventfd(initval, flags);3804 const rc = system.eventfd(initval, flags);
3805 switch (errno(rc)) {3805 switch (errno(rc)) {
3806 .SUCCESS => return @intCast(i32, rc),3806 .SUCCESS => return @as(i32, @intCast(rc)),
3807 else => |err| return unexpectedErrno(err),3807 else => |err| return unexpectedErrno(err),
38083808
3809 .INVAL => unreachable, // invalid parameters3809 .INVAL => unreachable, // invalid parameters
...@@ -3937,7 +3937,7 @@ pub const ConnectError = error{...@@ -3937,7 +3937,7 @@ pub const ConnectError = error{
3937/// return error.WouldBlock when EAGAIN or EINPROGRESS is received.3937/// return error.WouldBlock when EAGAIN or EINPROGRESS is received.
3938pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) ConnectError!void {3938pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) ConnectError!void {
3939 if (builtin.os.tag == .windows) {3939 if (builtin.os.tag == .windows) {
3940 const rc = windows.ws2_32.connect(sock, sock_addr, @intCast(i32, len));3940 const rc = windows.ws2_32.connect(sock, sock_addr, @as(i32, @intCast(len)));
3941 if (rc == 0) return;3941 if (rc == 0) return;
3942 switch (windows.ws2_32.WSAGetLastError()) {3942 switch (windows.ws2_32.WSAGetLastError()) {
3943 .WSAEADDRINUSE => return error.AddressInUse,3943 .WSAEADDRINUSE => return error.AddressInUse,
...@@ -3992,10 +3992,10 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne...@@ -3992,10 +3992,10 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
3992pub fn getsockoptError(sockfd: fd_t) ConnectError!void {3992pub fn getsockoptError(sockfd: fd_t) ConnectError!void {
3993 var err_code: i32 = undefined;3993 var err_code: i32 = undefined;
3994 var size: u32 = @sizeOf(u32);3994 var size: u32 = @sizeOf(u32);
3995 const rc = system.getsockopt(sockfd, SOL.SOCKET, SO.ERROR, @ptrCast([*]u8, &err_code), &size);3995 const rc = system.getsockopt(sockfd, SOL.SOCKET, SO.ERROR, @as([*]u8, @ptrCast(&err_code)), &size);
3996 assert(size == 4);3996 assert(size == 4);
3997 switch (errno(rc)) {3997 switch (errno(rc)) {
3998 .SUCCESS => switch (@enumFromInt(E, err_code)) {3998 .SUCCESS => switch (@as(E, @enumFromInt(err_code))) {
3999 .SUCCESS => return,3999 .SUCCESS => return,
4000 .ACCES => return error.PermissionDenied,4000 .ACCES => return error.PermissionDenied,
4001 .PERM => return error.PermissionDenied,4001 .PERM => return error.PermissionDenied,
...@@ -4035,13 +4035,13 @@ pub const WaitPidResult = struct {...@@ -4035,13 +4035,13 @@ pub const WaitPidResult = struct {
4035pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {4035pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {
4036 const Status = if (builtin.link_libc) c_int else u32;4036 const Status = if (builtin.link_libc) c_int else u32;
4037 var status: Status = undefined;4037 var status: Status = undefined;
4038 const coerced_flags = if (builtin.link_libc) @intCast(c_int, flags) else flags;4038 const coerced_flags = if (builtin.link_libc) @as(c_int, @intCast(flags)) else flags;
4039 while (true) {4039 while (true) {
4040 const rc = system.waitpid(pid, &status, coerced_flags);4040 const rc = system.waitpid(pid, &status, coerced_flags);
4041 switch (errno(rc)) {4041 switch (errno(rc)) {
4042 .SUCCESS => return .{4042 .SUCCESS => return .{
4043 .pid = @intCast(pid_t, rc),4043 .pid = @as(pid_t, @intCast(rc)),
4044 .status = @bitCast(u32, status),4044 .status = @as(u32, @bitCast(status)),
4045 },4045 },
4046 .INTR => continue,4046 .INTR => continue,
4047 .CHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error.4047 .CHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error.
...@@ -4054,13 +4054,13 @@ pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {...@@ -4054,13 +4054,13 @@ pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {
4054pub fn wait4(pid: pid_t, flags: u32, ru: ?*rusage) WaitPidResult {4054pub fn wait4(pid: pid_t, flags: u32, ru: ?*rusage) WaitPidResult {
4055 const Status = if (builtin.link_libc) c_int else u32;4055 const Status = if (builtin.link_libc) c_int else u32;
4056 var status: Status = undefined;4056 var status: Status = undefined;
4057 const coerced_flags = if (builtin.link_libc) @intCast(c_int, flags) else flags;4057 const coerced_flags = if (builtin.link_libc) @as(c_int, @intCast(flags)) else flags;
4058 while (true) {4058 while (true) {
4059 const rc = system.wait4(pid, &status, coerced_flags, ru);4059 const rc = system.wait4(pid, &status, coerced_flags, ru);
4060 switch (errno(rc)) {4060 switch (errno(rc)) {
4061 .SUCCESS => return .{4061 .SUCCESS => return .{
4062 .pid = @intCast(pid_t, rc),4062 .pid = @as(pid_t, @intCast(rc)),
4063 .status = @bitCast(u32, status),4063 .status = @as(u32, @bitCast(status)),
4064 },4064 },
4065 .INTR => continue,4065 .INTR => continue,
4066 .CHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error.4066 .CHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error.
...@@ -4182,7 +4182,7 @@ pub const KQueueError = error{...@@ -4182,7 +4182,7 @@ pub const KQueueError = error{
4182pub fn kqueue() KQueueError!i32 {4182pub fn kqueue() KQueueError!i32 {
4183 const rc = system.kqueue();4183 const rc = system.kqueue();
4184 switch (errno(rc)) {4184 switch (errno(rc)) {
4185 .SUCCESS => return @intCast(i32, rc),4185 .SUCCESS => return @as(i32, @intCast(rc)),
4186 .MFILE => return error.ProcessFdQuotaExceeded,4186 .MFILE => return error.ProcessFdQuotaExceeded,
4187 .NFILE => return error.SystemFdQuotaExceeded,4187 .NFILE => return error.SystemFdQuotaExceeded,
4188 else => |err| return unexpectedErrno(err),4188 else => |err| return unexpectedErrno(err),
...@@ -4223,7 +4223,7 @@ pub fn kevent(...@@ -4223,7 +4223,7 @@ pub fn kevent(
4223 timeout,4223 timeout,
4224 );4224 );
4225 switch (errno(rc)) {4225 switch (errno(rc)) {
4226 .SUCCESS => return @intCast(usize, rc),4226 .SUCCESS => return @as(usize, @intCast(rc)),
4227 .ACCES => return error.AccessDenied,4227 .ACCES => return error.AccessDenied,
4228 .FAULT => unreachable,4228 .FAULT => unreachable,
4229 .BADF => unreachable, // Always a race condition.4229 .BADF => unreachable, // Always a race condition.
...@@ -4247,7 +4247,7 @@ pub const INotifyInitError = error{...@@ -4247,7 +4247,7 @@ pub const INotifyInitError = error{
4247pub fn inotify_init1(flags: u32) INotifyInitError!i32 {4247pub fn inotify_init1(flags: u32) INotifyInitError!i32 {
4248 const rc = system.inotify_init1(flags);4248 const rc = system.inotify_init1(flags);
4249 switch (errno(rc)) {4249 switch (errno(rc)) {
4250 .SUCCESS => return @intCast(i32, rc),4250 .SUCCESS => return @as(i32, @intCast(rc)),
4251 .INVAL => unreachable,4251 .INVAL => unreachable,
4252 .MFILE => return error.ProcessFdQuotaExceeded,4252 .MFILE => return error.ProcessFdQuotaExceeded,
4253 .NFILE => return error.SystemFdQuotaExceeded,4253 .NFILE => return error.SystemFdQuotaExceeded,
...@@ -4276,7 +4276,7 @@ pub fn inotify_add_watch(inotify_fd: i32, pathname: []const u8, mask: u32) INoti...@@ -4276,7 +4276,7 @@ pub fn inotify_add_watch(inotify_fd: i32, pathname: []const u8, mask: u32) INoti
4276pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 {4276pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 {
4277 const rc = system.inotify_add_watch(inotify_fd, pathname, mask);4277 const rc = system.inotify_add_watch(inotify_fd, pathname, mask);
4278 switch (errno(rc)) {4278 switch (errno(rc)) {
4279 .SUCCESS => return @intCast(i32, rc),4279 .SUCCESS => return @as(i32, @intCast(rc)),
4280 .ACCES => return error.AccessDenied,4280 .ACCES => return error.AccessDenied,
4281 .BADF => unreachable,4281 .BADF => unreachable,
4282 .FAULT => unreachable,4282 .FAULT => unreachable,
...@@ -4319,7 +4319,7 @@ pub const MProtectError = error{...@@ -4319,7 +4319,7 @@ pub const MProtectError = error{
4319pub fn mprotect(memory: []align(mem.page_size) u8, protection: u32) MProtectError!void {4319pub fn mprotect(memory: []align(mem.page_size) u8, protection: u32) MProtectError!void {
4320 assert(mem.isAligned(memory.len, mem.page_size));4320 assert(mem.isAligned(memory.len, mem.page_size));
4321 if (builtin.os.tag == .windows) {4321 if (builtin.os.tag == .windows) {
4322 const win_prot: windows.DWORD = switch (@truncate(u3, protection)) {4322 const win_prot: windows.DWORD = switch (@as(u3, @truncate(protection))) {
4323 0b000 => windows.PAGE_NOACCESS,4323 0b000 => windows.PAGE_NOACCESS,
4324 0b001 => windows.PAGE_READONLY,4324 0b001 => windows.PAGE_READONLY,
4325 0b010 => unreachable, // +w -r not allowed4325 0b010 => unreachable, // +w -r not allowed
...@@ -4350,7 +4350,7 @@ pub const ForkError = error{SystemResources} || UnexpectedError;...@@ -4350,7 +4350,7 @@ pub const ForkError = error{SystemResources} || UnexpectedError;
4350pub fn fork() ForkError!pid_t {4350pub fn fork() ForkError!pid_t {
4351 const rc = system.fork();4351 const rc = system.fork();
4352 switch (errno(rc)) {4352 switch (errno(rc)) {
4353 .SUCCESS => return @intCast(pid_t, rc),4353 .SUCCESS => return @as(pid_t, @intCast(rc)),
4354 .AGAIN => return error.SystemResources,4354 .AGAIN => return error.SystemResources,
4355 .NOMEM => return error.SystemResources,4355 .NOMEM => return error.SystemResources,
4356 else => |err| return unexpectedErrno(err),4356 else => |err| return unexpectedErrno(err),
...@@ -4391,14 +4391,14 @@ pub fn mmap(...@@ -4391,14 +4391,14 @@ pub fn mmap(
4391) MMapError![]align(mem.page_size) u8 {4391) MMapError![]align(mem.page_size) u8 {
4392 const mmap_sym = if (lfs64_abi) system.mmap64 else system.mmap;4392 const mmap_sym = if (lfs64_abi) system.mmap64 else system.mmap;
43934393
4394 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned4394 const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
4395 const rc = mmap_sym(ptr, length, prot, flags, fd, ioffset);4395 const rc = mmap_sym(ptr, length, prot, flags, fd, ioffset);
4396 const err = if (builtin.link_libc) blk: {4396 const err = if (builtin.link_libc) blk: {
4397 if (rc != std.c.MAP.FAILED) return @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length];4397 if (rc != std.c.MAP.FAILED) return @as([*]align(mem.page_size) u8, @ptrCast(@alignCast(rc)))[0..length];
4398 break :blk @enumFromInt(E, system._errno().*);4398 break :blk @as(E, @enumFromInt(system._errno().*));
4399 } else blk: {4399 } else blk: {
4400 const err = errno(rc);4400 const err = errno(rc);
4401 if (err == .SUCCESS) return @ptrFromInt([*]align(mem.page_size) u8, rc)[0..length];4401 if (err == .SUCCESS) return @as([*]align(mem.page_size) u8, @ptrFromInt(rc))[0..length];
4402 break :blk err;4402 break :blk err;
4403 };4403 };
4404 switch (err) {4404 switch (err) {
...@@ -4781,7 +4781,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {...@@ -4781,7 +4781,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
4781 }4781 }
4782 if (builtin.os.tag == .wasi and !builtin.link_libc) {4782 if (builtin.os.tag == .wasi and !builtin.link_libc) {
4783 var new_offset: wasi.filesize_t = undefined;4783 var new_offset: wasi.filesize_t = undefined;
4784 switch (wasi.fd_seek(fd, @bitCast(wasi.filedelta_t, offset), .SET, &new_offset)) {4784 switch (wasi.fd_seek(fd, @as(wasi.filedelta_t, @bitCast(offset)), .SET, &new_offset)) {
4785 .SUCCESS => return,4785 .SUCCESS => return,
4786 .BADF => unreachable, // always a race condition4786 .BADF => unreachable, // always a race condition
4787 .INVAL => return error.Unseekable,4787 .INVAL => return error.Unseekable,
...@@ -4795,7 +4795,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {...@@ -4795,7 +4795,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
47954795
4796 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;4796 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;
47974797
4798 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned4798 const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
4799 switch (errno(lseek_sym(fd, ioffset, SEEK.SET))) {4799 switch (errno(lseek_sym(fd, ioffset, SEEK.SET))) {
4800 .SUCCESS => return,4800 .SUCCESS => return,
4801 .BADF => unreachable, // always a race condition4801 .BADF => unreachable, // always a race condition
...@@ -4811,7 +4811,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {...@@ -4811,7 +4811,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
4811pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {4811pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
4812 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {4812 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
4813 var result: u64 = undefined;4813 var result: u64 = undefined;
4814 switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK.CUR))) {4814 switch (errno(system.llseek(fd, @as(u64, @bitCast(offset)), &result, SEEK.CUR))) {
4815 .SUCCESS => return,4815 .SUCCESS => return,
4816 .BADF => unreachable, // always a race condition4816 .BADF => unreachable, // always a race condition
4817 .INVAL => return error.Unseekable,4817 .INVAL => return error.Unseekable,
...@@ -4839,7 +4839,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {...@@ -4839,7 +4839,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
4839 }4839 }
4840 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;4840 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;
48414841
4842 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned4842 const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
4843 switch (errno(lseek_sym(fd, ioffset, SEEK.CUR))) {4843 switch (errno(lseek_sym(fd, ioffset, SEEK.CUR))) {
4844 .SUCCESS => return,4844 .SUCCESS => return,
4845 .BADF => unreachable, // always a race condition4845 .BADF => unreachable, // always a race condition
...@@ -4855,7 +4855,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {...@@ -4855,7 +4855,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
4855pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {4855pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
4856 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {4856 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
4857 var result: u64 = undefined;4857 var result: u64 = undefined;
4858 switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK.END))) {4858 switch (errno(system.llseek(fd, @as(u64, @bitCast(offset)), &result, SEEK.END))) {
4859 .SUCCESS => return,4859 .SUCCESS => return,
4860 .BADF => unreachable, // always a race condition4860 .BADF => unreachable, // always a race condition
4861 .INVAL => return error.Unseekable,4861 .INVAL => return error.Unseekable,
...@@ -4883,7 +4883,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {...@@ -4883,7 +4883,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
4883 }4883 }
4884 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;4884 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;
48854885
4886 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned4886 const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
4887 switch (errno(lseek_sym(fd, ioffset, SEEK.END))) {4887 switch (errno(lseek_sym(fd, ioffset, SEEK.END))) {
4888 .SUCCESS => return,4888 .SUCCESS => return,
4889 .BADF => unreachable, // always a race condition4889 .BADF => unreachable, // always a race condition
...@@ -4929,7 +4929,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {...@@ -4929,7 +4929,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
49294929
4930 const rc = lseek_sym(fd, 0, SEEK.CUR);4930 const rc = lseek_sym(fd, 0, SEEK.CUR);
4931 switch (errno(rc)) {4931 switch (errno(rc)) {
4932 .SUCCESS => return @bitCast(u64, rc),4932 .SUCCESS => return @as(u64, @bitCast(rc)),
4933 .BADF => unreachable, // always a race condition4933 .BADF => unreachable, // always a race condition
4934 .INVAL => return error.Unseekable,4934 .INVAL => return error.Unseekable,
4935 .OVERFLOW => return error.Unseekable,4935 .OVERFLOW => return error.Unseekable,
...@@ -4952,7 +4952,7 @@ pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) FcntlError!usize {...@@ -4952,7 +4952,7 @@ pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) FcntlError!usize {
4952 while (true) {4952 while (true) {
4953 const rc = system.fcntl(fd, cmd, arg);4953 const rc = system.fcntl(fd, cmd, arg);
4954 switch (errno(rc)) {4954 switch (errno(rc)) {
4955 .SUCCESS => return @intCast(usize, rc),4955 .SUCCESS => return @as(usize, @intCast(rc)),
4956 .INTR => continue,4956 .INTR => continue,
4957 .AGAIN, .ACCES => return error.Locked,4957 .AGAIN, .ACCES => return error.Locked,
4958 .BADF => unreachable,4958 .BADF => unreachable,
...@@ -5122,7 +5122,7 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP...@@ -5122,7 +5122,7 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
51225122
5123 return getFdPath(fd, out_buffer);5123 return getFdPath(fd, out_buffer);
5124 }5124 }
5125 const result_path = std.c.realpath(pathname, out_buffer) orelse switch (@enumFromInt(E, std.c._errno().*)) {5125 const result_path = std.c.realpath(pathname, out_buffer) orelse switch (@as(E, @enumFromInt(std.c._errno().*))) {
5126 .SUCCESS => unreachable,5126 .SUCCESS => unreachable,
5127 .INVAL => unreachable,5127 .INVAL => unreachable,
5128 .BADF => unreachable,5128 .BADF => unreachable,
...@@ -5269,7 +5269,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {...@@ -5269,7 +5269,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
5269 };5269 };
5270 var i: usize = 0;5270 var i: usize = 0;
5271 while (i < len) {5271 while (i < len) {
5272 const kf: *align(1) system.kinfo_file = @ptrCast(*align(1) system.kinfo_file, &buf[i]);5272 const kf: *align(1) system.kinfo_file = @as(*align(1) system.kinfo_file, @ptrCast(&buf[i]));
5273 if (kf.fd == fd) {5273 if (kf.fd == fd) {
5274 len = mem.indexOfScalar(u8, &kf.path, 0) orelse MAX_PATH_BYTES;5274 len = mem.indexOfScalar(u8, &kf.path, 0) orelse MAX_PATH_BYTES;
5275 if (len == 0) return error.NameTooLong;5275 if (len == 0) return error.NameTooLong;
...@@ -5277,7 +5277,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {...@@ -5277,7 +5277,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
5277 @memcpy(result, kf.path[0..len]);5277 @memcpy(result, kf.path[0..len]);
5278 return result;5278 return result;
5279 }5279 }
5280 i += @intCast(usize, kf.structsize);5280 i += @as(usize, @intCast(kf.structsize));
5281 }5281 }
5282 return error.InvalidHandle;5282 return error.InvalidHandle;
5283 }5283 }
...@@ -5357,22 +5357,22 @@ pub fn dl_iterate_phdr(...@@ -5357,22 +5357,22 @@ pub fn dl_iterate_phdr(
5357 if (builtin.link_libc) {5357 if (builtin.link_libc) {
5358 switch (system.dl_iterate_phdr(struct {5358 switch (system.dl_iterate_phdr(struct {
5359 fn callbackC(info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int {5359 fn callbackC(info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int {
5360 const context_ptr = @ptrCast(*const Context, @alignCast(@alignOf(*const Context), data));5360 const context_ptr: *const Context = @ptrCast(@alignCast(data));
5361 callback(info, size, context_ptr.*) catch |err| return @intFromError(err);5361 callback(info, size, context_ptr.*) catch |err| return @intFromError(err);
5362 return 0;5362 return 0;
5363 }5363 }
5364 }.callbackC, @ptrFromInt(?*anyopaque, @intFromPtr(&context)))) {5364 }.callbackC, @as(?*anyopaque, @ptrFromInt(@intFromPtr(&context))))) {
5365 0 => return,5365 0 => return,
5366 else => |err| return @errSetCast(Error, @errorFromInt(@intCast(u16, err))), // TODO don't hardcode u165366 else => |err| return @as(Error, @errSetCast(@errorFromInt(@as(u16, @intCast(err))))), // TODO don't hardcode u16
5367 }5367 }
5368 }5368 }
53695369
5370 const elf_base = std.process.getBaseAddress();5370 const elf_base = std.process.getBaseAddress();
5371 const ehdr = @ptrFromInt(*elf.Ehdr, elf_base);5371 const ehdr = @as(*elf.Ehdr, @ptrFromInt(elf_base));
5372 // Make sure the base address points to an ELF image.5372 // Make sure the base address points to an ELF image.
5373 assert(mem.eql(u8, ehdr.e_ident[0..4], elf.MAGIC));5373 assert(mem.eql(u8, ehdr.e_ident[0..4], elf.MAGIC));
5374 const n_phdr = ehdr.e_phnum;5374 const n_phdr = ehdr.e_phnum;
5375 const phdrs = (@ptrFromInt([*]elf.Phdr, elf_base + ehdr.e_phoff))[0..n_phdr];5375 const phdrs = (@as([*]elf.Phdr, @ptrFromInt(elf_base + ehdr.e_phoff)))[0..n_phdr];
53765376
5377 var it = dl.linkmap_iterator(phdrs) catch unreachable;5377 var it = dl.linkmap_iterator(phdrs) catch unreachable;
53785378
...@@ -5406,12 +5406,12 @@ pub fn dl_iterate_phdr(...@@ -5406,12 +5406,12 @@ pub fn dl_iterate_phdr(
5406 var dlpi_phnum: u16 = undefined;5406 var dlpi_phnum: u16 = undefined;
54075407
5408 if (entry.l_addr != 0) {5408 if (entry.l_addr != 0) {
5409 const elf_header = @ptrFromInt(*elf.Ehdr, entry.l_addr);5409 const elf_header = @as(*elf.Ehdr, @ptrFromInt(entry.l_addr));
5410 dlpi_phdr = @ptrFromInt([*]elf.Phdr, entry.l_addr + elf_header.e_phoff);5410 dlpi_phdr = @as([*]elf.Phdr, @ptrFromInt(entry.l_addr + elf_header.e_phoff));
5411 dlpi_phnum = elf_header.e_phnum;5411 dlpi_phnum = elf_header.e_phnum;
5412 } else {5412 } else {
5413 // This is the running ELF image5413 // This is the running ELF image
5414 dlpi_phdr = @ptrFromInt([*]elf.Phdr, elf_base + ehdr.e_phoff);5414 dlpi_phdr = @as([*]elf.Phdr, @ptrFromInt(elf_base + ehdr.e_phoff));
5415 dlpi_phnum = ehdr.e_phnum;5415 dlpi_phnum = ehdr.e_phnum;
5416 }5416 }
54175417
...@@ -5433,11 +5433,11 @@ pub const ClockGetTimeError = error{UnsupportedClock} || UnexpectedError;...@@ -5433,11 +5433,11 @@ pub const ClockGetTimeError = error{UnsupportedClock} || UnexpectedError;
5433pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {5433pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
5434 if (builtin.os.tag == .wasi and !builtin.link_libc) {5434 if (builtin.os.tag == .wasi and !builtin.link_libc) {
5435 var ts: timestamp_t = undefined;5435 var ts: timestamp_t = undefined;
5436 switch (system.clock_time_get(@bitCast(u32, clk_id), 1, &ts)) {5436 switch (system.clock_time_get(@as(u32, @bitCast(clk_id)), 1, &ts)) {
5437 .SUCCESS => {5437 .SUCCESS => {
5438 tp.* = .{5438 tp.* = .{
5439 .tv_sec = @intCast(i64, ts / std.time.ns_per_s),5439 .tv_sec = @as(i64, @intCast(ts / std.time.ns_per_s)),
5440 .tv_nsec = @intCast(isize, ts % std.time.ns_per_s),5440 .tv_nsec = @as(isize, @intCast(ts % std.time.ns_per_s)),
5441 };5441 };
5442 },5442 },
5443 .INVAL => return error.UnsupportedClock,5443 .INVAL => return error.UnsupportedClock,
...@@ -5453,8 +5453,8 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {...@@ -5453,8 +5453,8 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
5453 const ft64 = (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime;5453 const ft64 = (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
5454 const ft_per_s = std.time.ns_per_s / 100;5454 const ft_per_s = std.time.ns_per_s / 100;
5455 tp.* = .{5455 tp.* = .{
5456 .tv_sec = @intCast(i64, ft64 / ft_per_s) + std.time.epoch.windows,5456 .tv_sec = @as(i64, @intCast(ft64 / ft_per_s)) + std.time.epoch.windows,
5457 .tv_nsec = @intCast(c_long, ft64 % ft_per_s) * 100,5457 .tv_nsec = @as(c_long, @intCast(ft64 % ft_per_s)) * 100,
5458 };5458 };
5459 return;5459 return;
5460 } else {5460 } else {
...@@ -5474,10 +5474,10 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {...@@ -5474,10 +5474,10 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
5474pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {5474pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
5475 if (builtin.os.tag == .wasi and !builtin.link_libc) {5475 if (builtin.os.tag == .wasi and !builtin.link_libc) {
5476 var ts: timestamp_t = undefined;5476 var ts: timestamp_t = undefined;
5477 switch (system.clock_res_get(@bitCast(u32, clk_id), &ts)) {5477 switch (system.clock_res_get(@as(u32, @bitCast(clk_id)), &ts)) {
5478 .SUCCESS => res.* = .{5478 .SUCCESS => res.* = .{
5479 .tv_sec = @intCast(i64, ts / std.time.ns_per_s),5479 .tv_sec = @as(i64, @intCast(ts / std.time.ns_per_s)),
5480 .tv_nsec = @intCast(isize, ts % std.time.ns_per_s),5480 .tv_nsec = @as(isize, @intCast(ts % std.time.ns_per_s)),
5481 },5481 },
5482 .INVAL => return error.UnsupportedClock,5482 .INVAL => return error.UnsupportedClock,
5483 else => |err| return unexpectedErrno(err),5483 else => |err| return unexpectedErrno(err),
...@@ -5747,7 +5747,7 @@ pub fn res_mkquery(...@@ -5747,7 +5747,7 @@ pub fn res_mkquery(
5747 // TODO determine the circumstances for this and whether or5747 // TODO determine the circumstances for this and whether or
5748 // not this should be an error.5748 // not this should be an error.
5749 if (j - i - 1 > 62) unreachable;5749 if (j - i - 1 > 62) unreachable;
5750 q[i - 1] = @intCast(u8, j - i);5750 q[i - 1] = @as(u8, @intCast(j - i));
5751 }5751 }
5752 q[i + 1] = ty;5752 q[i + 1] = ty;
5753 q[i + 3] = class;5753 q[i + 3] = class;
...@@ -5756,10 +5756,10 @@ pub fn res_mkquery(...@@ -5756,10 +5756,10 @@ pub fn res_mkquery(
5756 var ts: timespec = undefined;5756 var ts: timespec = undefined;
5757 clock_gettime(CLOCK.REALTIME, &ts) catch {};5757 clock_gettime(CLOCK.REALTIME, &ts) catch {};
5758 const UInt = std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(ts.tv_nsec)));5758 const UInt = std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(ts.tv_nsec)));
5759 const unsec = @bitCast(UInt, ts.tv_nsec);5759 const unsec = @as(UInt, @bitCast(ts.tv_nsec));
5760 const id = @truncate(u32, unsec + unsec / 65536);5760 const id = @as(u32, @truncate(unsec + unsec / 65536));
5761 q[0] = @truncate(u8, id / 256);5761 q[0] = @as(u8, @truncate(id / 256));
5762 q[1] = @truncate(u8, id);5762 q[1] = @as(u8, @truncate(id));
57635763
5764 @memcpy(buf[0..n], q[0..n]);5764 @memcpy(buf[0..n], q[0..n]);
5765 return n;5765 return n;
...@@ -5865,11 +5865,11 @@ pub fn sendmsg(...@@ -5865,11 +5865,11 @@ pub fn sendmsg(
5865 else => |err| return windows.unexpectedWSAError(err),5865 else => |err| return windows.unexpectedWSAError(err),
5866 }5866 }
5867 } else {5867 } else {
5868 return @intCast(usize, rc);5868 return @as(usize, @intCast(rc));
5869 }5869 }
5870 } else {5870 } else {
5871 switch (errno(rc)) {5871 switch (errno(rc)) {
5872 .SUCCESS => return @intCast(usize, rc),5872 .SUCCESS => return @as(usize, @intCast(rc)),
58735873
5874 .ACCES => return error.AccessDenied,5874 .ACCES => return error.AccessDenied,
5875 .AGAIN => return error.WouldBlock,5875 .AGAIN => return error.WouldBlock,
...@@ -5965,13 +5965,13 @@ pub fn sendto(...@@ -5965,13 +5965,13 @@ pub fn sendto(
5965 .WSANOTINITIALISED => unreachable, // A successful WSAStartup call must occur before using this function.5965 .WSANOTINITIALISED => unreachable, // A successful WSAStartup call must occur before using this function.
5966 else => |err| return windows.unexpectedWSAError(err),5966 else => |err| return windows.unexpectedWSAError(err),
5967 },5967 },
5968 else => |rc| return @intCast(usize, rc),5968 else => |rc| return @as(usize, @intCast(rc)),
5969 }5969 }
5970 }5970 }
5971 while (true) {5971 while (true) {
5972 const rc = system.sendto(sockfd, buf.ptr, buf.len, flags, dest_addr, addrlen);5972 const rc = system.sendto(sockfd, buf.ptr, buf.len, flags, dest_addr, addrlen);
5973 switch (errno(rc)) {5973 switch (errno(rc)) {
5974 .SUCCESS => return @intCast(usize, rc),5974 .SUCCESS => return @as(usize, @intCast(rc)),
59755975
5976 .ACCES => return error.AccessDenied,5976 .ACCES => return error.AccessDenied,
5977 .AGAIN => return error.WouldBlock,5977 .AGAIN => return error.WouldBlock,
...@@ -6125,16 +6125,16 @@ pub fn sendfile(...@@ -6125,16 +6125,16 @@ pub fn sendfile(
6125 // Here we match BSD behavior, making a zero count value send as many bytes as possible.6125 // Here we match BSD behavior, making a zero count value send as many bytes as possible.
6126 const adjusted_count_tmp = if (in_len == 0) max_count else @min(in_len, @as(size_t, max_count));6126 const adjusted_count_tmp = if (in_len == 0) max_count else @min(in_len, @as(size_t, max_count));
6127 // TODO we should not need this cast; improve return type of @min6127 // TODO we should not need this cast; improve return type of @min
6128 const adjusted_count = @intCast(usize, adjusted_count_tmp);6128 const adjusted_count = @as(usize, @intCast(adjusted_count_tmp));
61296129
6130 const sendfile_sym = if (lfs64_abi) system.sendfile64 else system.sendfile;6130 const sendfile_sym = if (lfs64_abi) system.sendfile64 else system.sendfile;
61316131
6132 while (true) {6132 while (true) {
6133 var offset: off_t = @bitCast(off_t, in_offset);6133 var offset: off_t = @as(off_t, @bitCast(in_offset));
6134 const rc = sendfile_sym(out_fd, in_fd, &offset, adjusted_count);6134 const rc = sendfile_sym(out_fd, in_fd, &offset, adjusted_count);
6135 switch (errno(rc)) {6135 switch (errno(rc)) {
6136 .SUCCESS => {6136 .SUCCESS => {
6137 const amt = @bitCast(usize, rc);6137 const amt = @as(usize, @bitCast(rc));
6138 total_written += amt;6138 total_written += amt;
6139 if (in_len == 0 and amt == 0) {6139 if (in_len == 0 and amt == 0) {
6140 // We have detected EOF from `in_fd`.6140 // We have detected EOF from `in_fd`.
...@@ -6209,9 +6209,9 @@ pub fn sendfile(...@@ -6209,9 +6209,9 @@ pub fn sendfile(
62096209
6210 while (true) {6210 while (true) {
6211 var sbytes: off_t = undefined;6211 var sbytes: off_t = undefined;
6212 const offset = @bitCast(off_t, in_offset);6212 const offset = @as(off_t, @bitCast(in_offset));
6213 const err = errno(system.sendfile(in_fd, out_fd, offset, adjusted_count, hdtr, &sbytes, flags));6213 const err = errno(system.sendfile(in_fd, out_fd, offset, adjusted_count, hdtr, &sbytes, flags));
6214 const amt = @bitCast(usize, sbytes);6214 const amt = @as(usize, @bitCast(sbytes));
6215 switch (err) {6215 switch (err) {
6216 .SUCCESS => return amt,6216 .SUCCESS => return amt,
62176217
...@@ -6286,13 +6286,13 @@ pub fn sendfile(...@@ -6286,13 +6286,13 @@ pub fn sendfile(
62866286
6287 const adjusted_count_temporary = @min(in_len, @as(u63, max_count));6287 const adjusted_count_temporary = @min(in_len, @as(u63, max_count));
6288 // TODO we should not need this int cast; improve the return type of `@min`6288 // TODO we should not need this int cast; improve the return type of `@min`
6289 const adjusted_count = @intCast(u63, adjusted_count_temporary);6289 const adjusted_count = @as(u63, @intCast(adjusted_count_temporary));
62906290
6291 while (true) {6291 while (true) {
6292 var sbytes: off_t = adjusted_count;6292 var sbytes: off_t = adjusted_count;
6293 const signed_offset = @bitCast(i64, in_offset);6293 const signed_offset = @as(i64, @bitCast(in_offset));
6294 const err = errno(system.sendfile(in_fd, out_fd, signed_offset, &sbytes, hdtr, flags));6294 const err = errno(system.sendfile(in_fd, out_fd, signed_offset, &sbytes, hdtr, flags));
6295 const amt = @bitCast(usize, sbytes);6295 const amt = @as(usize, @bitCast(sbytes));
6296 switch (err) {6296 switch (err) {
6297 .SUCCESS => return amt,6297 .SUCCESS => return amt,
62986298
...@@ -6342,7 +6342,7 @@ pub fn sendfile(...@@ -6342,7 +6342,7 @@ pub fn sendfile(
6342 // Here we match BSD behavior, making a zero count value send as many bytes as possible.6342 // Here we match BSD behavior, making a zero count value send as many bytes as possible.
6343 const adjusted_count_tmp = if (in_len == 0) buf.len else @min(buf.len, in_len);6343 const adjusted_count_tmp = if (in_len == 0) buf.len else @min(buf.len, in_len);
6344 // TODO we should not need this cast; improve return type of @min6344 // TODO we should not need this cast; improve return type of @min
6345 const adjusted_count = @intCast(usize, adjusted_count_tmp);6345 const adjusted_count = @as(usize, @intCast(adjusted_count_tmp));
6346 const amt_read = try pread(in_fd, buf[0..adjusted_count], in_offset);6346 const amt_read = try pread(in_fd, buf[0..adjusted_count], in_offset);
6347 if (amt_read == 0) {6347 if (amt_read == 0) {
6348 if (in_len == 0) {6348 if (in_len == 0) {
...@@ -6413,14 +6413,14 @@ pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len...@@ -6413,14 +6413,14 @@ pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len
6413 std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok) and6413 std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok) and
6414 has_copy_file_range_syscall.load(.Monotonic)))6414 has_copy_file_range_syscall.load(.Monotonic)))
6415 {6415 {
6416 var off_in_copy = @bitCast(i64, off_in);6416 var off_in_copy = @as(i64, @bitCast(off_in));
6417 var off_out_copy = @bitCast(i64, off_out);6417 var off_out_copy = @as(i64, @bitCast(off_out));
64186418
6419 while (true) {6419 while (true) {
6420 const rc = system.copy_file_range(fd_in, &off_in_copy, fd_out, &off_out_copy, len, flags);6420 const rc = system.copy_file_range(fd_in, &off_in_copy, fd_out, &off_out_copy, len, flags);
6421 if (builtin.os.tag == .freebsd) {6421 if (builtin.os.tag == .freebsd) {
6422 switch (system.getErrno(rc)) {6422 switch (system.getErrno(rc)) {
6423 .SUCCESS => return @intCast(usize, rc),6423 .SUCCESS => return @as(usize, @intCast(rc)),
6424 .BADF => return error.FilesOpenedWithWrongFlags,6424 .BADF => return error.FilesOpenedWithWrongFlags,
6425 .FBIG => return error.FileTooBig,6425 .FBIG => return error.FileTooBig,
6426 .IO => return error.InputOutput,6426 .IO => return error.InputOutput,
...@@ -6433,7 +6433,7 @@ pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len...@@ -6433,7 +6433,7 @@ pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len
6433 }6433 }
6434 } else { // assume linux6434 } else { // assume linux
6435 switch (system.getErrno(rc)) {6435 switch (system.getErrno(rc)) {
6436 .SUCCESS => return @intCast(usize, rc),6436 .SUCCESS => return @as(usize, @intCast(rc)),
6437 .BADF => return error.FilesOpenedWithWrongFlags,6437 .BADF => return error.FilesOpenedWithWrongFlags,
6438 .FBIG => return error.FileTooBig,6438 .FBIG => return error.FileTooBig,
6439 .IO => return error.InputOutput,6439 .IO => return error.InputOutput,
...@@ -6486,11 +6486,11 @@ pub fn poll(fds: []pollfd, timeout: i32) PollError!usize {...@@ -6486,11 +6486,11 @@ pub fn poll(fds: []pollfd, timeout: i32) PollError!usize {
6486 else => |err| return windows.unexpectedWSAError(err),6486 else => |err| return windows.unexpectedWSAError(err),
6487 }6487 }
6488 } else {6488 } else {
6489 return @intCast(usize, rc);6489 return @as(usize, @intCast(rc));
6490 }6490 }
6491 } else {6491 } else {
6492 switch (errno(rc)) {6492 switch (errno(rc)) {
6493 .SUCCESS => return @intCast(usize, rc),6493 .SUCCESS => return @as(usize, @intCast(rc)),
6494 .FAULT => unreachable,6494 .FAULT => unreachable,
6495 .INTR => continue,6495 .INTR => continue,
6496 .INVAL => unreachable,6496 .INVAL => unreachable,
...@@ -6520,7 +6520,7 @@ pub fn ppoll(fds: []pollfd, timeout: ?*const timespec, mask: ?*const sigset_t) P...@@ -6520,7 +6520,7 @@ pub fn ppoll(fds: []pollfd, timeout: ?*const timespec, mask: ?*const sigset_t) P
6520 const fds_count = math.cast(nfds_t, fds.len) orelse return error.SystemResources;6520 const fds_count = math.cast(nfds_t, fds.len) orelse return error.SystemResources;
6521 const rc = system.ppoll(fds.ptr, fds_count, ts_ptr, mask);6521 const rc = system.ppoll(fds.ptr, fds_count, ts_ptr, mask);
6522 switch (errno(rc)) {6522 switch (errno(rc)) {
6523 .SUCCESS => return @intCast(usize, rc),6523 .SUCCESS => return @as(usize, @intCast(rc)),
6524 .FAULT => unreachable,6524 .FAULT => unreachable,
6525 .INTR => return error.SignalInterrupt,6525 .INTR => return error.SignalInterrupt,
6526 .INVAL => unreachable,6526 .INVAL => unreachable,
...@@ -6585,11 +6585,11 @@ pub fn recvfrom(...@@ -6585,11 +6585,11 @@ pub fn recvfrom(
6585 else => |err| return windows.unexpectedWSAError(err),6585 else => |err| return windows.unexpectedWSAError(err),
6586 }6586 }
6587 } else {6587 } else {
6588 return @intCast(usize, rc);6588 return @as(usize, @intCast(rc));
6589 }6589 }
6590 } else {6590 } else {
6591 switch (errno(rc)) {6591 switch (errno(rc)) {
6592 .SUCCESS => return @intCast(usize, rc),6592 .SUCCESS => return @as(usize, @intCast(rc)),
6593 .BADF => unreachable, // always a race condition6593 .BADF => unreachable, // always a race condition
6594 .FAULT => unreachable,6594 .FAULT => unreachable,
6595 .INVAL => unreachable,6595 .INVAL => unreachable,
...@@ -6681,7 +6681,7 @@ pub const SetSockOptError = error{...@@ -6681,7 +6681,7 @@ pub const SetSockOptError = error{
6681/// Set a socket's options.6681/// Set a socket's options.
6682pub fn setsockopt(fd: socket_t, level: u32, optname: u32, opt: []const u8) SetSockOptError!void {6682pub fn setsockopt(fd: socket_t, level: u32, optname: u32, opt: []const u8) SetSockOptError!void {
6683 if (builtin.os.tag == .windows) {6683 if (builtin.os.tag == .windows) {
6684 const rc = windows.ws2_32.setsockopt(fd, @intCast(i32, level), @intCast(i32, optname), opt.ptr, @intCast(i32, opt.len));6684 const rc = windows.ws2_32.setsockopt(fd, @as(i32, @intCast(level)), @as(i32, @intCast(optname)), opt.ptr, @as(i32, @intCast(opt.len)));
6685 if (rc == windows.ws2_32.SOCKET_ERROR) {6685 if (rc == windows.ws2_32.SOCKET_ERROR) {
6686 switch (windows.ws2_32.WSAGetLastError()) {6686 switch (windows.ws2_32.WSAGetLastError()) {
6687 .WSANOTINITIALISED => unreachable,6687 .WSANOTINITIALISED => unreachable,
...@@ -6694,7 +6694,7 @@ pub fn setsockopt(fd: socket_t, level: u32, optname: u32, opt: []const u8) SetSo...@@ -6694,7 +6694,7 @@ pub fn setsockopt(fd: socket_t, level: u32, optname: u32, opt: []const u8) SetSo
6694 }6694 }
6695 return;6695 return;
6696 } else {6696 } else {
6697 switch (errno(system.setsockopt(fd, level, optname, opt.ptr, @intCast(socklen_t, opt.len)))) {6697 switch (errno(system.setsockopt(fd, level, optname, opt.ptr, @as(socklen_t, @intCast(opt.len))))) {
6698 .SUCCESS => {},6698 .SUCCESS => {},
6699 .BADF => unreachable, // always a race condition6699 .BADF => unreachable, // always a race condition
6700 .NOTSOCK => unreachable, // always a race condition6700 .NOTSOCK => unreachable, // always a race condition
...@@ -6731,7 +6731,7 @@ pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {...@@ -6731,7 +6731,7 @@ pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {
6731 const getErrno = if (use_c) std.c.getErrno else linux.getErrno;6731 const getErrno = if (use_c) std.c.getErrno else linux.getErrno;
6732 const rc = sys.memfd_create(name, flags);6732 const rc = sys.memfd_create(name, flags);
6733 switch (getErrno(rc)) {6733 switch (getErrno(rc)) {
6734 .SUCCESS => return @intCast(fd_t, rc),6734 .SUCCESS => return @as(fd_t, @intCast(rc)),
6735 .FAULT => unreachable, // name has invalid memory6735 .FAULT => unreachable, // name has invalid memory
6736 .INVAL => unreachable, // name/flags are faulty6736 .INVAL => unreachable, // name/flags are faulty
6737 .NFILE => return error.SystemFdQuotaExceeded,6737 .NFILE => return error.SystemFdQuotaExceeded,
...@@ -6881,7 +6881,7 @@ pub fn ioctl_SIOCGIFINDEX(fd: fd_t, ifr: *ifreq) IoCtl_SIOCGIFINDEX_Error!void {...@@ -6881,7 +6881,7 @@ pub fn ioctl_SIOCGIFINDEX(fd: fd_t, ifr: *ifreq) IoCtl_SIOCGIFINDEX_Error!void {
6881pub fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) !fd_t {6881pub fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) !fd_t {
6882 const rc = system.signalfd(fd, mask, flags);6882 const rc = system.signalfd(fd, mask, flags);
6883 switch (errno(rc)) {6883 switch (errno(rc)) {
6884 .SUCCESS => return @intCast(fd_t, rc),6884 .SUCCESS => return @as(fd_t, @intCast(rc)),
6885 .BADF, .INVAL => unreachable,6885 .BADF, .INVAL => unreachable,
6886 .NFILE => return error.SystemFdQuotaExceeded,6886 .NFILE => return error.SystemFdQuotaExceeded,
6887 .NOMEM => return error.SystemResources,6887 .NOMEM => return error.SystemResources,
...@@ -6989,7 +6989,7 @@ pub fn prctl(option: PR, args: anytype) PrctlError!u31 {...@@ -6989,7 +6989,7 @@ pub fn prctl(option: PR, args: anytype) PrctlError!u31 {
69896989
6990 const rc = system.prctl(@intFromEnum(option), buf[0], buf[1], buf[2], buf[3]);6990 const rc = system.prctl(@intFromEnum(option), buf[0], buf[1], buf[2], buf[3]);
6991 switch (errno(rc)) {6991 switch (errno(rc)) {
6992 .SUCCESS => return @intCast(u31, rc),6992 .SUCCESS => return @as(u31, @intCast(rc)),
6993 .ACCES => return error.AccessDenied,6993 .ACCES => return error.AccessDenied,
6994 .BADF => return error.InvalidFileDescriptor,6994 .BADF => return error.InvalidFileDescriptor,
6995 .FAULT => return error.InvalidAddress,6995 .FAULT => return error.InvalidAddress,
...@@ -7170,7 +7170,7 @@ pub fn perf_event_open(...@@ -7170,7 +7170,7 @@ pub fn perf_event_open(
7170) PerfEventOpenError!fd_t {7170) PerfEventOpenError!fd_t {
7171 const rc = system.perf_event_open(attr, pid, cpu, group_fd, flags);7171 const rc = system.perf_event_open(attr, pid, cpu, group_fd, flags);
7172 switch (errno(rc)) {7172 switch (errno(rc)) {
7173 .SUCCESS => return @intCast(fd_t, rc),7173 .SUCCESS => return @as(fd_t, @intCast(rc)),
7174 .@"2BIG" => return error.TooBig,7174 .@"2BIG" => return error.TooBig,
7175 .ACCES => return error.PermissionDenied,7175 .ACCES => return error.PermissionDenied,
7176 .BADF => unreachable, // group_fd file descriptor is not valid.7176 .BADF => unreachable, // group_fd file descriptor is not valid.
...@@ -7205,7 +7205,7 @@ pub const TimerFdSetError = TimerFdGetError || error{Canceled};...@@ -7205,7 +7205,7 @@ pub const TimerFdSetError = TimerFdGetError || error{Canceled};
7205pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t {7205pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t {
7206 var rc = linux.timerfd_create(clokid, flags);7206 var rc = linux.timerfd_create(clokid, flags);
7207 return switch (errno(rc)) {7207 return switch (errno(rc)) {
7208 .SUCCESS => @intCast(fd_t, rc),7208 .SUCCESS => @as(fd_t, @intCast(rc)),
7209 .INVAL => unreachable,7209 .INVAL => unreachable,
7210 .MFILE => return error.ProcessFdQuotaExceeded,7210 .MFILE => return error.ProcessFdQuotaExceeded,
7211 .NFILE => return error.SystemFdQuotaExceeded,7211 .NFILE => return error.SystemFdQuotaExceeded,
...@@ -7267,7 +7267,7 @@ pub fn ptrace(request: u32, pid: pid_t, addr: usize, signal: usize) PtraceError!...@@ -7267,7 +7267,7 @@ pub fn ptrace(request: u32, pid: pid_t, addr: usize, signal: usize) PtraceError!
7267 .macos, .ios, .tvos, .watchos => switch (errno(darwin.ptrace(7267 .macos, .ios, .tvos, .watchos => switch (errno(darwin.ptrace(
7268 math.cast(i32, request) orelse return error.Overflow,7268 math.cast(i32, request) orelse return error.Overflow,
7269 pid,7269 pid,
7270 @ptrFromInt(?[*]u8, addr),7270 @as(?[*]u8, @ptrFromInt(addr)),
7271 math.cast(i32, signal) orelse return error.Overflow,7271 math.cast(i32, signal) orelse return error.Overflow,
7272 ))) {7272 ))) {
7273 .SUCCESS => {},7273 .SUCCESS => {},
lib/std/os/linux.zig+258-258
...@@ -175,62 +175,62 @@ const require_aligned_register_pair =...@@ -175,62 +175,62 @@ const require_aligned_register_pair =
175// Split a 64bit value into a {LSB,MSB} pair.175// Split a 64bit value into a {LSB,MSB} pair.
176// The LE/BE variants specify the endianness to assume.176// The LE/BE variants specify the endianness to assume.
177fn splitValueLE64(val: i64) [2]u32 {177fn splitValueLE64(val: i64) [2]u32 {
178 const u = @bitCast(u64, val);178 const u = @as(u64, @bitCast(val));
179 return [2]u32{179 return [2]u32{
180 @truncate(u32, u),180 @as(u32, @truncate(u)),
181 @truncate(u32, u >> 32),181 @as(u32, @truncate(u >> 32)),
182 };182 };
183}183}
184fn splitValueBE64(val: i64) [2]u32 {184fn splitValueBE64(val: i64) [2]u32 {
185 const u = @bitCast(u64, val);185 const u = @as(u64, @bitCast(val));
186 return [2]u32{186 return [2]u32{
187 @truncate(u32, u >> 32),187 @as(u32, @truncate(u >> 32)),
188 @truncate(u32, u),188 @as(u32, @truncate(u)),
189 };189 };
190}190}
191fn splitValue64(val: i64) [2]u32 {191fn splitValue64(val: i64) [2]u32 {
192 const u = @bitCast(u64, val);192 const u = @as(u64, @bitCast(val));
193 switch (native_endian) {193 switch (native_endian) {
194 .Little => return [2]u32{194 .Little => return [2]u32{
195 @truncate(u32, u),195 @as(u32, @truncate(u)),
196 @truncate(u32, u >> 32),196 @as(u32, @truncate(u >> 32)),
197 },197 },
198 .Big => return [2]u32{198 .Big => return [2]u32{
199 @truncate(u32, u >> 32),199 @as(u32, @truncate(u >> 32)),
200 @truncate(u32, u),200 @as(u32, @truncate(u)),
201 },201 },
202 }202 }
203}203}
204204
205/// Get the errno from a syscall return value, or 0 for no error.205/// Get the errno from a syscall return value, or 0 for no error.
206pub fn getErrno(r: usize) E {206pub fn getErrno(r: usize) E {
207 const signed_r = @bitCast(isize, r);207 const signed_r = @as(isize, @bitCast(r));
208 const int = if (signed_r > -4096 and signed_r < 0) -signed_r else 0;208 const int = if (signed_r > -4096 and signed_r < 0) -signed_r else 0;
209 return @enumFromInt(E, int);209 return @as(E, @enumFromInt(int));
210}210}
211211
212pub fn dup(old: i32) usize {212pub fn dup(old: i32) usize {
213 return syscall1(.dup, @bitCast(usize, @as(isize, old)));213 return syscall1(.dup, @as(usize, @bitCast(@as(isize, old))));
214}214}
215215
216pub fn dup2(old: i32, new: i32) usize {216pub fn dup2(old: i32, new: i32) usize {
217 if (@hasField(SYS, "dup2")) {217 if (@hasField(SYS, "dup2")) {
218 return syscall2(.dup2, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)));218 return syscall2(.dup2, @as(usize, @bitCast(@as(isize, old))), @as(usize, @bitCast(@as(isize, new))));
219 } else {219 } else {
220 if (old == new) {220 if (old == new) {
221 if (std.debug.runtime_safety) {221 if (std.debug.runtime_safety) {
222 const rc = syscall2(.fcntl, @bitCast(usize, @as(isize, old)), F.GETFD);222 const rc = syscall2(.fcntl, @as(usize, @bitCast(@as(isize, old))), F.GETFD);
223 if (@bitCast(isize, rc) < 0) return rc;223 if (@as(isize, @bitCast(rc)) < 0) return rc;
224 }224 }
225 return @intCast(usize, old);225 return @as(usize, @intCast(old));
226 } else {226 } else {
227 return syscall3(.dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), 0);227 return syscall3(.dup3, @as(usize, @bitCast(@as(isize, old))), @as(usize, @bitCast(@as(isize, new))), 0);
228 }228 }
229 }229 }
230}230}
231231
232pub fn dup3(old: i32, new: i32, flags: u32) usize {232pub fn dup3(old: i32, new: i32, flags: u32) usize {
233 return syscall3(.dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), flags);233 return syscall3(.dup3, @as(usize, @bitCast(@as(isize, old))), @as(usize, @bitCast(@as(isize, new))), flags);
234}234}
235235
236pub fn chdir(path: [*:0]const u8) usize {236pub fn chdir(path: [*:0]const u8) usize {
...@@ -238,7 +238,7 @@ pub fn chdir(path: [*:0]const u8) usize {...@@ -238,7 +238,7 @@ pub fn chdir(path: [*:0]const u8) usize {
238}238}
239239
240pub fn fchdir(fd: fd_t) usize {240pub fn fchdir(fd: fd_t) usize {
241 return syscall1(.fchdir, @bitCast(usize, @as(isize, fd)));241 return syscall1(.fchdir, @as(usize, @bitCast(@as(isize, fd))));
242}242}
243243
244pub fn chroot(path: [*:0]const u8) usize {244pub fn chroot(path: [*:0]const u8) usize {
...@@ -273,7 +273,7 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize {...@@ -273,7 +273,7 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize {
273}273}
274274
275pub fn utimensat(dirfd: i32, path: ?[*:0]const u8, times: *const [2]timespec, flags: u32) usize {275pub fn utimensat(dirfd: i32, path: ?[*:0]const u8, times: *const [2]timespec, flags: u32) usize {
276 return syscall4(.utimensat, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), @intFromPtr(times), flags);276 return syscall4(.utimensat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), @intFromPtr(times), flags);
277}277}
278278
279pub fn fallocate(fd: i32, mode: i32, offset: i64, length: i64) usize {279pub fn fallocate(fd: i32, mode: i32, offset: i64, length: i64) usize {
...@@ -282,8 +282,8 @@ pub fn fallocate(fd: i32, mode: i32, offset: i64, length: i64) usize {...@@ -282,8 +282,8 @@ pub fn fallocate(fd: i32, mode: i32, offset: i64, length: i64) usize {
282 const length_halves = splitValue64(length);282 const length_halves = splitValue64(length);
283 return syscall6(283 return syscall6(
284 .fallocate,284 .fallocate,
285 @bitCast(usize, @as(isize, fd)),285 @as(usize, @bitCast(@as(isize, fd))),
286 @bitCast(usize, @as(isize, mode)),286 @as(usize, @bitCast(@as(isize, mode))),
287 offset_halves[0],287 offset_halves[0],
288 offset_halves[1],288 offset_halves[1],
289 length_halves[0],289 length_halves[0],
...@@ -292,20 +292,20 @@ pub fn fallocate(fd: i32, mode: i32, offset: i64, length: i64) usize {...@@ -292,20 +292,20 @@ pub fn fallocate(fd: i32, mode: i32, offset: i64, length: i64) usize {
292 } else {292 } else {
293 return syscall4(293 return syscall4(
294 .fallocate,294 .fallocate,
295 @bitCast(usize, @as(isize, fd)),295 @as(usize, @bitCast(@as(isize, fd))),
296 @bitCast(usize, @as(isize, mode)),296 @as(usize, @bitCast(@as(isize, mode))),
297 @bitCast(u64, offset),297 @as(u64, @bitCast(offset)),
298 @bitCast(u64, length),298 @as(u64, @bitCast(length)),
299 );299 );
300 }300 }
301}301}
302302
303pub fn futex_wait(uaddr: *const i32, futex_op: u32, val: i32, timeout: ?*const timespec) usize {303pub fn futex_wait(uaddr: *const i32, futex_op: u32, val: i32, timeout: ?*const timespec) usize {
304 return syscall4(.futex, @intFromPtr(uaddr), futex_op, @bitCast(u32, val), @intFromPtr(timeout));304 return syscall4(.futex, @intFromPtr(uaddr), futex_op, @as(u32, @bitCast(val)), @intFromPtr(timeout));
305}305}
306306
307pub fn futex_wake(uaddr: *const i32, futex_op: u32, val: i32) usize {307pub fn futex_wake(uaddr: *const i32, futex_op: u32, val: i32) usize {
308 return syscall3(.futex, @intFromPtr(uaddr), futex_op, @bitCast(u32, val));308 return syscall3(.futex, @intFromPtr(uaddr), futex_op, @as(u32, @bitCast(val)));
309}309}
310310
311pub fn getcwd(buf: [*]u8, size: usize) usize {311pub fn getcwd(buf: [*]u8, size: usize) usize {
...@@ -315,7 +315,7 @@ pub fn getcwd(buf: [*]u8, size: usize) usize {...@@ -315,7 +315,7 @@ pub fn getcwd(buf: [*]u8, size: usize) usize {
315pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {315pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {
316 return syscall3(316 return syscall3(
317 .getdents,317 .getdents,
318 @bitCast(usize, @as(isize, fd)),318 @as(usize, @bitCast(@as(isize, fd))),
319 @intFromPtr(dirp),319 @intFromPtr(dirp),
320 @min(len, maxInt(c_int)),320 @min(len, maxInt(c_int)),
321 );321 );
...@@ -324,7 +324,7 @@ pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {...@@ -324,7 +324,7 @@ pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {
324pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize {324pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize {
325 return syscall3(325 return syscall3(
326 .getdents64,326 .getdents64,
327 @bitCast(usize, @as(isize, fd)),327 @as(usize, @bitCast(@as(isize, fd))),
328 @intFromPtr(dirp),328 @intFromPtr(dirp),
329 @min(len, maxInt(c_int)),329 @min(len, maxInt(c_int)),
330 );330 );
...@@ -335,35 +335,35 @@ pub fn inotify_init1(flags: u32) usize {...@@ -335,35 +335,35 @@ pub fn inotify_init1(flags: u32) usize {
335}335}
336336
337pub fn inotify_add_watch(fd: i32, pathname: [*:0]const u8, mask: u32) usize {337pub fn inotify_add_watch(fd: i32, pathname: [*:0]const u8, mask: u32) usize {
338 return syscall3(.inotify_add_watch, @bitCast(usize, @as(isize, fd)), @intFromPtr(pathname), mask);338 return syscall3(.inotify_add_watch, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(pathname), mask);
339}339}
340340
341pub fn inotify_rm_watch(fd: i32, wd: i32) usize {341pub fn inotify_rm_watch(fd: i32, wd: i32) usize {
342 return syscall2(.inotify_rm_watch, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, wd)));342 return syscall2(.inotify_rm_watch, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, wd))));
343}343}
344344
345pub fn readlink(noalias path: [*:0]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {345pub fn readlink(noalias path: [*:0]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
346 if (@hasField(SYS, "readlink")) {346 if (@hasField(SYS, "readlink")) {
347 return syscall3(.readlink, @intFromPtr(path), @intFromPtr(buf_ptr), buf_len);347 return syscall3(.readlink, @intFromPtr(path), @intFromPtr(buf_ptr), buf_len);
348 } else {348 } else {
349 return syscall4(.readlinkat, @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(path), @intFromPtr(buf_ptr), buf_len);349 return syscall4(.readlinkat, @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(path), @intFromPtr(buf_ptr), buf_len);
350 }350 }
351}351}
352352
353pub fn readlinkat(dirfd: i32, noalias path: [*:0]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {353pub fn readlinkat(dirfd: i32, noalias path: [*:0]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
354 return syscall4(.readlinkat, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), @intFromPtr(buf_ptr), buf_len);354 return syscall4(.readlinkat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), @intFromPtr(buf_ptr), buf_len);
355}355}
356356
357pub fn mkdir(path: [*:0]const u8, mode: u32) usize {357pub fn mkdir(path: [*:0]const u8, mode: u32) usize {
358 if (@hasField(SYS, "mkdir")) {358 if (@hasField(SYS, "mkdir")) {
359 return syscall2(.mkdir, @intFromPtr(path), mode);359 return syscall2(.mkdir, @intFromPtr(path), mode);
360 } else {360 } else {
361 return syscall3(.mkdirat, @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(path), mode);361 return syscall3(.mkdirat, @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(path), mode);
362 }362 }
363}363}
364364
365pub fn mkdirat(dirfd: i32, path: [*:0]const u8, mode: u32) usize {365pub fn mkdirat(dirfd: i32, path: [*:0]const u8, mode: u32) usize {
366 return syscall3(.mkdirat, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), mode);366 return syscall3(.mkdirat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), mode);
367}367}
368368
369pub fn mknod(path: [*:0]const u8, mode: u32, dev: u32) usize {369pub fn mknod(path: [*:0]const u8, mode: u32, dev: u32) usize {
...@@ -375,7 +375,7 @@ pub fn mknod(path: [*:0]const u8, mode: u32, dev: u32) usize {...@@ -375,7 +375,7 @@ pub fn mknod(path: [*:0]const u8, mode: u32, dev: u32) usize {
375}375}
376376
377pub fn mknodat(dirfd: i32, path: [*:0]const u8, mode: u32, dev: u32) usize {377pub fn mknodat(dirfd: i32, path: [*:0]const u8, mode: u32, dev: u32) usize {
378 return syscall4(.mknodat, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), mode, dev);378 return syscall4(.mknodat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), mode, dev);
379}379}
380380
381pub fn mount(special: [*:0]const u8, dir: [*:0]const u8, fstype: ?[*:0]const u8, flags: u32, data: usize) usize {381pub fn mount(special: [*:0]const u8, dir: [*:0]const u8, fstype: ?[*:0]const u8, flags: u32, data: usize) usize {
...@@ -394,7 +394,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of...@@ -394,7 +394,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
394 if (@hasField(SYS, "mmap2")) {394 if (@hasField(SYS, "mmap2")) {
395 // Make sure the offset is also specified in multiples of page size395 // Make sure the offset is also specified in multiples of page size
396 if ((offset & (MMAP2_UNIT - 1)) != 0)396 if ((offset & (MMAP2_UNIT - 1)) != 0)
397 return @bitCast(usize, -@as(isize, @intFromEnum(E.INVAL)));397 return @as(usize, @bitCast(-@as(isize, @intFromEnum(E.INVAL))));
398398
399 return syscall6(399 return syscall6(
400 .mmap2,400 .mmap2,
...@@ -402,8 +402,8 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of...@@ -402,8 +402,8 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
402 length,402 length,
403 prot,403 prot,
404 flags,404 flags,
405 @bitCast(usize, @as(isize, fd)),405 @as(usize, @bitCast(@as(isize, fd))),
406 @truncate(usize, @bitCast(u64, offset) / MMAP2_UNIT),406 @as(usize, @truncate(@as(u64, @bitCast(offset)) / MMAP2_UNIT)),
407 );407 );
408 } else {408 } else {
409 return syscall6(409 return syscall6(
...@@ -412,8 +412,8 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of...@@ -412,8 +412,8 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
412 length,412 length,
413 prot,413 prot,
414 flags,414 flags,
415 @bitCast(usize, @as(isize, fd)),415 @as(usize, @bitCast(@as(isize, fd))),
416 @bitCast(u64, offset),416 @as(u64, @bitCast(offset)),
417 );417 );
418 }418 }
419}419}
...@@ -429,7 +429,7 @@ pub const MSF = struct {...@@ -429,7 +429,7 @@ pub const MSF = struct {
429};429};
430430
431pub fn msync(address: [*]const u8, length: usize, flags: i32) usize {431pub fn msync(address: [*]const u8, length: usize, flags: i32) usize {
432 return syscall3(.msync, @intFromPtr(address), length, @bitCast(u32, flags));432 return syscall3(.msync, @intFromPtr(address), length, @as(u32, @bitCast(flags)));
433}433}
434434
435pub fn munmap(address: [*]const u8, length: usize) usize {435pub fn munmap(address: [*]const u8, length: usize) usize {
...@@ -438,7 +438,7 @@ pub fn munmap(address: [*]const u8, length: usize) usize {...@@ -438,7 +438,7 @@ pub fn munmap(address: [*]const u8, length: usize) usize {
438438
439pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {439pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {
440 if (@hasField(SYS, "poll")) {440 if (@hasField(SYS, "poll")) {
441 return syscall3(.poll, @intFromPtr(fds), n, @bitCast(u32, timeout));441 return syscall3(.poll, @intFromPtr(fds), n, @as(u32, @bitCast(timeout)));
442 } else {442 } else {
443 return syscall5(443 return syscall5(
444 .ppoll,444 .ppoll,
...@@ -462,69 +462,69 @@ pub fn ppoll(fds: [*]pollfd, n: nfds_t, timeout: ?*timespec, sigmask: ?*const si...@@ -462,69 +462,69 @@ pub fn ppoll(fds: [*]pollfd, n: nfds_t, timeout: ?*timespec, sigmask: ?*const si
462}462}
463463
464pub fn read(fd: i32, buf: [*]u8, count: usize) usize {464pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
465 return syscall3(.read, @bitCast(usize, @as(isize, fd)), @intFromPtr(buf), count);465 return syscall3(.read, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(buf), count);
466}466}
467467
468pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: i64) usize {468pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: i64) usize {
469 const offset_u = @bitCast(u64, offset);469 const offset_u = @as(u64, @bitCast(offset));
470 return syscall5(470 return syscall5(
471 .preadv,471 .preadv,
472 @bitCast(usize, @as(isize, fd)),472 @as(usize, @bitCast(@as(isize, fd))),
473 @intFromPtr(iov),473 @intFromPtr(iov),
474 count,474 count,
475 // Kernel expects the offset is split into largest natural word-size.475 // Kernel expects the offset is split into largest natural word-size.
476 // See following link for detail:476 // See following link for detail:
477 // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=601cc11d054ae4b5e9b5babec3d8e4667a2cb9b5477 // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=601cc11d054ae4b5e9b5babec3d8e4667a2cb9b5
478 @truncate(usize, offset_u),478 @as(usize, @truncate(offset_u)),
479 if (usize_bits < 64) @truncate(usize, offset_u >> 32) else 0,479 if (usize_bits < 64) @as(usize, @truncate(offset_u >> 32)) else 0,
480 );480 );
481}481}
482482
483pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: i64, flags: kernel_rwf) usize {483pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: i64, flags: kernel_rwf) usize {
484 const offset_u = @bitCast(u64, offset);484 const offset_u = @as(u64, @bitCast(offset));
485 return syscall6(485 return syscall6(
486 .preadv2,486 .preadv2,
487 @bitCast(usize, @as(isize, fd)),487 @as(usize, @bitCast(@as(isize, fd))),
488 @intFromPtr(iov),488 @intFromPtr(iov),
489 count,489 count,
490 // See comments in preadv490 // See comments in preadv
491 @truncate(usize, offset_u),491 @as(usize, @truncate(offset_u)),
492 if (usize_bits < 64) @truncate(usize, offset_u >> 32) else 0,492 if (usize_bits < 64) @as(usize, @truncate(offset_u >> 32)) else 0,
493 flags,493 flags,
494 );494 );
495}495}
496496
497pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize {497pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize {
498 return syscall3(.readv, @bitCast(usize, @as(isize, fd)), @intFromPtr(iov), count);498 return syscall3(.readv, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(iov), count);
499}499}
500500
501pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {501pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {
502 return syscall3(.writev, @bitCast(usize, @as(isize, fd)), @intFromPtr(iov), count);502 return syscall3(.writev, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(iov), count);
503}503}
504504
505pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64) usize {505pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64) usize {
506 const offset_u = @bitCast(u64, offset);506 const offset_u = @as(u64, @bitCast(offset));
507 return syscall5(507 return syscall5(
508 .pwritev,508 .pwritev,
509 @bitCast(usize, @as(isize, fd)),509 @as(usize, @bitCast(@as(isize, fd))),
510 @intFromPtr(iov),510 @intFromPtr(iov),
511 count,511 count,
512 // See comments in preadv512 // See comments in preadv
513 @truncate(usize, offset_u),513 @as(usize, @truncate(offset_u)),
514 if (usize_bits < 64) @truncate(usize, offset_u >> 32) else 0,514 if (usize_bits < 64) @as(usize, @truncate(offset_u >> 32)) else 0,
515 );515 );
516}516}
517517
518pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64, flags: kernel_rwf) usize {518pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64, flags: kernel_rwf) usize {
519 const offset_u = @bitCast(u64, offset);519 const offset_u = @as(u64, @bitCast(offset));
520 return syscall6(520 return syscall6(
521 .pwritev2,521 .pwritev2,
522 @bitCast(usize, @as(isize, fd)),522 @as(usize, @bitCast(@as(isize, fd))),
523 @intFromPtr(iov),523 @intFromPtr(iov),
524 count,524 count,
525 // See comments in preadv525 // See comments in preadv
526 @truncate(usize, offset_u),526 @as(usize, @truncate(offset_u)),
527 if (usize_bits < 64) @truncate(usize, offset_u >> 32) else 0,527 if (usize_bits < 64) @as(usize, @truncate(offset_u >> 32)) else 0,
528 flags,528 flags,
529 );529 );
530}530}
...@@ -533,7 +533,7 @@ pub fn rmdir(path: [*:0]const u8) usize {...@@ -533,7 +533,7 @@ pub fn rmdir(path: [*:0]const u8) usize {
533 if (@hasField(SYS, "rmdir")) {533 if (@hasField(SYS, "rmdir")) {
534 return syscall1(.rmdir, @intFromPtr(path));534 return syscall1(.rmdir, @intFromPtr(path));
535 } else {535 } else {
536 return syscall3(.unlinkat, @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(path), AT.REMOVEDIR);536 return syscall3(.unlinkat, @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(path), AT.REMOVEDIR);
537 }537 }
538}538}
539539
...@@ -541,12 +541,12 @@ pub fn symlink(existing: [*:0]const u8, new: [*:0]const u8) usize {...@@ -541,12 +541,12 @@ pub fn symlink(existing: [*:0]const u8, new: [*:0]const u8) usize {
541 if (@hasField(SYS, "symlink")) {541 if (@hasField(SYS, "symlink")) {
542 return syscall2(.symlink, @intFromPtr(existing), @intFromPtr(new));542 return syscall2(.symlink, @intFromPtr(existing), @intFromPtr(new));
543 } else {543 } else {
544 return syscall3(.symlinkat, @intFromPtr(existing), @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(new));544 return syscall3(.symlinkat, @intFromPtr(existing), @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(new));
545 }545 }
546}546}
547547
548pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) usize {548pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) usize {
549 return syscall3(.symlinkat, @intFromPtr(existing), @bitCast(usize, @as(isize, newfd)), @intFromPtr(newpath));549 return syscall3(.symlinkat, @intFromPtr(existing), @as(usize, @bitCast(@as(isize, newfd))), @intFromPtr(newpath));
550}550}
551551
552pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: i64) usize {552pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: i64) usize {
...@@ -555,7 +555,7 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: i64) usize {...@@ -555,7 +555,7 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: i64) usize {
555 if (require_aligned_register_pair) {555 if (require_aligned_register_pair) {
556 return syscall6(556 return syscall6(
557 .pread64,557 .pread64,
558 @bitCast(usize, @as(isize, fd)),558 @as(usize, @bitCast(@as(isize, fd))),
559 @intFromPtr(buf),559 @intFromPtr(buf),
560 count,560 count,
561 0,561 0,
...@@ -565,7 +565,7 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: i64) usize {...@@ -565,7 +565,7 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: i64) usize {
565 } else {565 } else {
566 return syscall5(566 return syscall5(
567 .pread64,567 .pread64,
568 @bitCast(usize, @as(isize, fd)),568 @as(usize, @bitCast(@as(isize, fd))),
569 @intFromPtr(buf),569 @intFromPtr(buf),
570 count,570 count,
571 offset_halves[0],571 offset_halves[0],
...@@ -580,10 +580,10 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: i64) usize {...@@ -580,10 +580,10 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: i64) usize {
580 .pread;580 .pread;
581 return syscall4(581 return syscall4(
582 syscall_number,582 syscall_number,
583 @bitCast(usize, @as(isize, fd)),583 @as(usize, @bitCast(@as(isize, fd))),
584 @intFromPtr(buf),584 @intFromPtr(buf),
585 count,585 count,
586 @bitCast(u64, offset),586 @as(u64, @bitCast(offset)),
587 );587 );
588 }588 }
589}589}
...@@ -592,12 +592,12 @@ pub fn access(path: [*:0]const u8, mode: u32) usize {...@@ -592,12 +592,12 @@ pub fn access(path: [*:0]const u8, mode: u32) usize {
592 if (@hasField(SYS, "access")) {592 if (@hasField(SYS, "access")) {
593 return syscall2(.access, @intFromPtr(path), mode);593 return syscall2(.access, @intFromPtr(path), mode);
594 } else {594 } else {
595 return syscall4(.faccessat, @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(path), mode, 0);595 return syscall4(.faccessat, @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(path), mode, 0);
596 }596 }
597}597}
598598
599pub fn faccessat(dirfd: i32, path: [*:0]const u8, mode: u32, flags: u32) usize {599pub fn faccessat(dirfd: i32, path: [*:0]const u8, mode: u32, flags: u32) usize {
600 return syscall4(.faccessat, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), mode, flags);600 return syscall4(.faccessat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), mode, flags);
601}601}
602602
603pub fn pipe(fd: *[2]i32) usize {603pub fn pipe(fd: *[2]i32) usize {
...@@ -615,7 +615,7 @@ pub fn pipe2(fd: *[2]i32, flags: u32) usize {...@@ -615,7 +615,7 @@ pub fn pipe2(fd: *[2]i32, flags: u32) usize {
615}615}
616616
617pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {617pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
618 return syscall3(.write, @bitCast(usize, @as(isize, fd)), @intFromPtr(buf), count);618 return syscall3(.write, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(buf), count);
619}619}
620620
621pub fn ftruncate(fd: i32, length: i64) usize {621pub fn ftruncate(fd: i32, length: i64) usize {
...@@ -624,7 +624,7 @@ pub fn ftruncate(fd: i32, length: i64) usize {...@@ -624,7 +624,7 @@ pub fn ftruncate(fd: i32, length: i64) usize {
624 if (require_aligned_register_pair) {624 if (require_aligned_register_pair) {
625 return syscall4(625 return syscall4(
626 .ftruncate64,626 .ftruncate64,
627 @bitCast(usize, @as(isize, fd)),627 @as(usize, @bitCast(@as(isize, fd))),
628 0,628 0,
629 length_halves[0],629 length_halves[0],
630 length_halves[1],630 length_halves[1],
...@@ -632,7 +632,7 @@ pub fn ftruncate(fd: i32, length: i64) usize {...@@ -632,7 +632,7 @@ pub fn ftruncate(fd: i32, length: i64) usize {
632 } else {632 } else {
633 return syscall3(633 return syscall3(
634 .ftruncate64,634 .ftruncate64,
635 @bitCast(usize, @as(isize, fd)),635 @as(usize, @bitCast(@as(isize, fd))),
636 length_halves[0],636 length_halves[0],
637 length_halves[1],637 length_halves[1],
638 );638 );
...@@ -640,8 +640,8 @@ pub fn ftruncate(fd: i32, length: i64) usize {...@@ -640,8 +640,8 @@ pub fn ftruncate(fd: i32, length: i64) usize {
640 } else {640 } else {
641 return syscall2(641 return syscall2(
642 .ftruncate,642 .ftruncate,
643 @bitCast(usize, @as(isize, fd)),643 @as(usize, @bitCast(@as(isize, fd))),
644 @bitCast(usize, length),644 @as(usize, @bitCast(length)),
645 );645 );
646 }646 }
647}647}
...@@ -653,7 +653,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: i64) usize {...@@ -653,7 +653,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: i64) usize {
653 if (require_aligned_register_pair) {653 if (require_aligned_register_pair) {
654 return syscall6(654 return syscall6(
655 .pwrite64,655 .pwrite64,
656 @bitCast(usize, @as(isize, fd)),656 @as(usize, @bitCast(@as(isize, fd))),
657 @intFromPtr(buf),657 @intFromPtr(buf),
658 count,658 count,
659 0,659 0,
...@@ -663,7 +663,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: i64) usize {...@@ -663,7 +663,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: i64) usize {
663 } else {663 } else {
664 return syscall5(664 return syscall5(
665 .pwrite64,665 .pwrite64,
666 @bitCast(usize, @as(isize, fd)),666 @as(usize, @bitCast(@as(isize, fd))),
667 @intFromPtr(buf),667 @intFromPtr(buf),
668 count,668 count,
669 offset_halves[0],669 offset_halves[0],
...@@ -678,10 +678,10 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: i64) usize {...@@ -678,10 +678,10 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: i64) usize {
678 .pwrite;678 .pwrite;
679 return syscall4(679 return syscall4(
680 syscall_number,680 syscall_number,
681 @bitCast(usize, @as(isize, fd)),681 @as(usize, @bitCast(@as(isize, fd))),
682 @intFromPtr(buf),682 @intFromPtr(buf),
683 count,683 count,
684 @bitCast(u64, offset),684 @as(u64, @bitCast(offset)),
685 );685 );
686 }686 }
687}687}
...@@ -690,9 +690,9 @@ pub fn rename(old: [*:0]const u8, new: [*:0]const u8) usize {...@@ -690,9 +690,9 @@ pub fn rename(old: [*:0]const u8, new: [*:0]const u8) usize {
690 if (@hasField(SYS, "rename")) {690 if (@hasField(SYS, "rename")) {
691 return syscall2(.rename, @intFromPtr(old), @intFromPtr(new));691 return syscall2(.rename, @intFromPtr(old), @intFromPtr(new));
692 } else if (@hasField(SYS, "renameat")) {692 } else if (@hasField(SYS, "renameat")) {
693 return syscall4(.renameat, @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(old), @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(new));693 return syscall4(.renameat, @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(old), @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(new));
694 } else {694 } else {
695 return syscall5(.renameat2, @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(old), @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(new), 0);695 return syscall5(.renameat2, @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(old), @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(new), 0);
696 }696 }
697}697}
698698
...@@ -700,17 +700,17 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const...@@ -700,17 +700,17 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
700 if (@hasField(SYS, "renameat")) {700 if (@hasField(SYS, "renameat")) {
701 return syscall4(701 return syscall4(
702 .renameat,702 .renameat,
703 @bitCast(usize, @as(isize, oldfd)),703 @as(usize, @bitCast(@as(isize, oldfd))),
704 @intFromPtr(oldpath),704 @intFromPtr(oldpath),
705 @bitCast(usize, @as(isize, newfd)),705 @as(usize, @bitCast(@as(isize, newfd))),
706 @intFromPtr(newpath),706 @intFromPtr(newpath),
707 );707 );
708 } else {708 } else {
709 return syscall5(709 return syscall5(
710 .renameat2,710 .renameat2,
711 @bitCast(usize, @as(isize, oldfd)),711 @as(usize, @bitCast(@as(isize, oldfd))),
712 @intFromPtr(oldpath),712 @intFromPtr(oldpath),
713 @bitCast(usize, @as(isize, newfd)),713 @as(usize, @bitCast(@as(isize, newfd))),
714 @intFromPtr(newpath),714 @intFromPtr(newpath),
715 0,715 0,
716 );716 );
...@@ -720,9 +720,9 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const...@@ -720,9 +720,9 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
720pub fn renameat2(oldfd: i32, oldpath: [*:0]const u8, newfd: i32, newpath: [*:0]const u8, flags: u32) usize {720pub fn renameat2(oldfd: i32, oldpath: [*:0]const u8, newfd: i32, newpath: [*:0]const u8, flags: u32) usize {
721 return syscall5(721 return syscall5(
722 .renameat2,722 .renameat2,
723 @bitCast(usize, @as(isize, oldfd)),723 @as(usize, @bitCast(@as(isize, oldfd))),
724 @intFromPtr(oldpath),724 @intFromPtr(oldpath),
725 @bitCast(usize, @as(isize, newfd)),725 @as(usize, @bitCast(@as(isize, newfd))),
726 @intFromPtr(newpath),726 @intFromPtr(newpath),
727 flags,727 flags,
728 );728 );
...@@ -734,7 +734,7 @@ pub fn open(path: [*:0]const u8, flags: u32, perm: mode_t) usize {...@@ -734,7 +734,7 @@ pub fn open(path: [*:0]const u8, flags: u32, perm: mode_t) usize {
734 } else {734 } else {
735 return syscall4(735 return syscall4(
736 .openat,736 .openat,
737 @bitCast(usize, @as(isize, AT.FDCWD)),737 @as(usize, @bitCast(@as(isize, AT.FDCWD))),
738 @intFromPtr(path),738 @intFromPtr(path),
739 flags,739 flags,
740 perm,740 perm,
...@@ -748,7 +748,7 @@ pub fn create(path: [*:0]const u8, perm: mode_t) usize {...@@ -748,7 +748,7 @@ pub fn create(path: [*:0]const u8, perm: mode_t) usize {
748748
749pub fn openat(dirfd: i32, path: [*:0]const u8, flags: u32, mode: mode_t) usize {749pub fn openat(dirfd: i32, path: [*:0]const u8, flags: u32, mode: mode_t) usize {
750 // dirfd could be negative, for example AT.FDCWD is -100750 // dirfd could be negative, for example AT.FDCWD is -100
751 return syscall4(.openat, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), flags, mode);751 return syscall4(.openat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), flags, mode);
752}752}
753753
754/// See also `clone` (from the arch-specific include)754/// See also `clone` (from the arch-specific include)
...@@ -762,11 +762,11 @@ pub fn clone2(flags: u32, child_stack_ptr: usize) usize {...@@ -762,11 +762,11 @@ pub fn clone2(flags: u32, child_stack_ptr: usize) usize {
762}762}
763763
764pub fn close(fd: i32) usize {764pub fn close(fd: i32) usize {
765 return syscall1(.close, @bitCast(usize, @as(isize, fd)));765 return syscall1(.close, @as(usize, @bitCast(@as(isize, fd))));
766}766}
767767
768pub fn fchmod(fd: i32, mode: mode_t) usize {768pub fn fchmod(fd: i32, mode: mode_t) usize {
769 return syscall2(.fchmod, @bitCast(usize, @as(isize, fd)), mode);769 return syscall2(.fchmod, @as(usize, @bitCast(@as(isize, fd))), mode);
770}770}
771771
772pub fn chmod(path: [*:0]const u8, mode: mode_t) usize {772pub fn chmod(path: [*:0]const u8, mode: mode_t) usize {
...@@ -775,7 +775,7 @@ pub fn chmod(path: [*:0]const u8, mode: mode_t) usize {...@@ -775,7 +775,7 @@ pub fn chmod(path: [*:0]const u8, mode: mode_t) usize {
775 } else {775 } else {
776 return syscall4(776 return syscall4(
777 .fchmodat,777 .fchmodat,
778 @bitCast(usize, @as(isize, AT.FDCWD)),778 @as(usize, @bitCast(@as(isize, AT.FDCWD))),
779 @intFromPtr(path),779 @intFromPtr(path),
780 mode,780 mode,
781 0,781 0,
...@@ -785,14 +785,14 @@ pub fn chmod(path: [*:0]const u8, mode: mode_t) usize {...@@ -785,14 +785,14 @@ pub fn chmod(path: [*:0]const u8, mode: mode_t) usize {
785785
786pub fn fchown(fd: i32, owner: uid_t, group: gid_t) usize {786pub fn fchown(fd: i32, owner: uid_t, group: gid_t) usize {
787 if (@hasField(SYS, "fchown32")) {787 if (@hasField(SYS, "fchown32")) {
788 return syscall3(.fchown32, @bitCast(usize, @as(isize, fd)), owner, group);788 return syscall3(.fchown32, @as(usize, @bitCast(@as(isize, fd))), owner, group);
789 } else {789 } else {
790 return syscall3(.fchown, @bitCast(usize, @as(isize, fd)), owner, group);790 return syscall3(.fchown, @as(usize, @bitCast(@as(isize, fd))), owner, group);
791 }791 }
792}792}
793793
794pub fn fchmodat(fd: i32, path: [*:0]const u8, mode: mode_t, flags: u32) usize {794pub fn fchmodat(fd: i32, path: [*:0]const u8, mode: mode_t, flags: u32) usize {
795 return syscall4(.fchmodat, @bitCast(usize, @as(isize, fd)), @intFromPtr(path), mode, flags);795 return syscall4(.fchmodat, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(path), mode, flags);
796}796}
797797
798/// Can only be called on 32 bit systems. For 64 bit see `lseek`.798/// Can only be called on 32 bit systems. For 64 bit see `lseek`.
...@@ -801,9 +801,9 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {...@@ -801,9 +801,9 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {
801 // endianness.801 // endianness.
802 return syscall5(802 return syscall5(
803 ._llseek,803 ._llseek,
804 @bitCast(usize, @as(isize, fd)),804 @as(usize, @bitCast(@as(isize, fd))),
805 @truncate(usize, offset >> 32),805 @as(usize, @truncate(offset >> 32)),
806 @truncate(usize, offset),806 @as(usize, @truncate(offset)),
807 @intFromPtr(result),807 @intFromPtr(result),
808 whence,808 whence,
809 );809 );
...@@ -811,16 +811,16 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {...@@ -811,16 +811,16 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {
811811
812/// Can only be called on 64 bit systems. For 32 bit see `llseek`.812/// Can only be called on 64 bit systems. For 32 bit see `llseek`.
813pub fn lseek(fd: i32, offset: i64, whence: usize) usize {813pub fn lseek(fd: i32, offset: i64, whence: usize) usize {
814 return syscall3(.lseek, @bitCast(usize, @as(isize, fd)), @bitCast(usize, offset), whence);814 return syscall3(.lseek, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(offset)), whence);
815}815}
816816
817pub fn exit(status: i32) noreturn {817pub fn exit(status: i32) noreturn {
818 _ = syscall1(.exit, @bitCast(usize, @as(isize, status)));818 _ = syscall1(.exit, @as(usize, @bitCast(@as(isize, status))));
819 unreachable;819 unreachable;
820}820}
821821
822pub fn exit_group(status: i32) noreturn {822pub fn exit_group(status: i32) noreturn {
823 _ = syscall1(.exit_group, @bitCast(usize, @as(isize, status)));823 _ = syscall1(.exit_group, @as(usize, @bitCast(@as(isize, status))));
824 unreachable;824 unreachable;
825}825}
826826
...@@ -886,15 +886,15 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {...@@ -886,15 +886,15 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
886}886}
887887
888pub fn kill(pid: pid_t, sig: i32) usize {888pub fn kill(pid: pid_t, sig: i32) usize {
889 return syscall2(.kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig)));889 return syscall2(.kill, @as(usize, @bitCast(@as(isize, pid))), @as(usize, @bitCast(@as(isize, sig))));
890}890}
891891
892pub fn tkill(tid: pid_t, sig: i32) usize {892pub fn tkill(tid: pid_t, sig: i32) usize {
893 return syscall2(.tkill, @bitCast(usize, @as(isize, tid)), @bitCast(usize, @as(isize, sig)));893 return syscall2(.tkill, @as(usize, @bitCast(@as(isize, tid))), @as(usize, @bitCast(@as(isize, sig))));
894}894}
895895
896pub fn tgkill(tgid: pid_t, tid: pid_t, sig: i32) usize {896pub fn tgkill(tgid: pid_t, tid: pid_t, sig: i32) usize {
897 return syscall3(.tgkill, @bitCast(usize, @as(isize, tgid)), @bitCast(usize, @as(isize, tid)), @bitCast(usize, @as(isize, sig)));897 return syscall3(.tgkill, @as(usize, @bitCast(@as(isize, tgid))), @as(usize, @bitCast(@as(isize, tid))), @as(usize, @bitCast(@as(isize, sig))));
898}898}
899899
900pub fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) usize {900pub fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) usize {
...@@ -903,16 +903,16 @@ pub fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) usize {...@@ -903,16 +903,16 @@ pub fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) usize {
903 .link,903 .link,
904 @intFromPtr(oldpath),904 @intFromPtr(oldpath),
905 @intFromPtr(newpath),905 @intFromPtr(newpath),
906 @bitCast(usize, @as(isize, flags)),906 @as(usize, @bitCast(@as(isize, flags))),
907 );907 );
908 } else {908 } else {
909 return syscall5(909 return syscall5(
910 .linkat,910 .linkat,
911 @bitCast(usize, @as(isize, AT.FDCWD)),911 @as(usize, @bitCast(@as(isize, AT.FDCWD))),
912 @intFromPtr(oldpath),912 @intFromPtr(oldpath),
913 @bitCast(usize, @as(isize, AT.FDCWD)),913 @as(usize, @bitCast(@as(isize, AT.FDCWD))),
914 @intFromPtr(newpath),914 @intFromPtr(newpath),
915 @bitCast(usize, @as(isize, flags)),915 @as(usize, @bitCast(@as(isize, flags))),
916 );916 );
917 }917 }
918}918}
...@@ -920,11 +920,11 @@ pub fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) usize {...@@ -920,11 +920,11 @@ pub fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) usize {
920pub fn linkat(oldfd: fd_t, oldpath: [*:0]const u8, newfd: fd_t, newpath: [*:0]const u8, flags: i32) usize {920pub fn linkat(oldfd: fd_t, oldpath: [*:0]const u8, newfd: fd_t, newpath: [*:0]const u8, flags: i32) usize {
921 return syscall5(921 return syscall5(
922 .linkat,922 .linkat,
923 @bitCast(usize, @as(isize, oldfd)),923 @as(usize, @bitCast(@as(isize, oldfd))),
924 @intFromPtr(oldpath),924 @intFromPtr(oldpath),
925 @bitCast(usize, @as(isize, newfd)),925 @as(usize, @bitCast(@as(isize, newfd))),
926 @intFromPtr(newpath),926 @intFromPtr(newpath),
927 @bitCast(usize, @as(isize, flags)),927 @as(usize, @bitCast(@as(isize, flags))),
928 );928 );
929}929}
930930
...@@ -932,22 +932,22 @@ pub fn unlink(path: [*:0]const u8) usize {...@@ -932,22 +932,22 @@ pub fn unlink(path: [*:0]const u8) usize {
932 if (@hasField(SYS, "unlink")) {932 if (@hasField(SYS, "unlink")) {
933 return syscall1(.unlink, @intFromPtr(path));933 return syscall1(.unlink, @intFromPtr(path));
934 } else {934 } else {
935 return syscall3(.unlinkat, @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(path), 0);935 return syscall3(.unlinkat, @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(path), 0);
936 }936 }
937}937}
938938
939pub fn unlinkat(dirfd: i32, path: [*:0]const u8, flags: u32) usize {939pub fn unlinkat(dirfd: i32, path: [*:0]const u8, flags: u32) usize {
940 return syscall3(.unlinkat, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), flags);940 return syscall3(.unlinkat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), flags);
941}941}
942942
943pub fn waitpid(pid: pid_t, status: *u32, flags: u32) usize {943pub fn waitpid(pid: pid_t, status: *u32, flags: u32) usize {
944 return syscall4(.wait4, @bitCast(usize, @as(isize, pid)), @intFromPtr(status), flags, 0);944 return syscall4(.wait4, @as(usize, @bitCast(@as(isize, pid))), @intFromPtr(status), flags, 0);
945}945}
946946
947pub fn wait4(pid: pid_t, status: *u32, flags: u32, usage: ?*rusage) usize {947pub fn wait4(pid: pid_t, status: *u32, flags: u32, usage: ?*rusage) usize {
948 return syscall4(948 return syscall4(
949 .wait4,949 .wait4,
950 @bitCast(usize, @as(isize, pid)),950 @as(usize, @bitCast(@as(isize, pid))),
951 @intFromPtr(status),951 @intFromPtr(status),
952 flags,952 flags,
953 @intFromPtr(usage),953 @intFromPtr(usage),
...@@ -955,18 +955,18 @@ pub fn wait4(pid: pid_t, status: *u32, flags: u32, usage: ?*rusage) usize {...@@ -955,18 +955,18 @@ pub fn wait4(pid: pid_t, status: *u32, flags: u32, usage: ?*rusage) usize {
955}955}
956956
957pub fn waitid(id_type: P, id: i32, infop: *siginfo_t, flags: u32) usize {957pub fn waitid(id_type: P, id: i32, infop: *siginfo_t, flags: u32) usize {
958 return syscall5(.waitid, @intFromEnum(id_type), @bitCast(usize, @as(isize, id)), @intFromPtr(infop), flags, 0);958 return syscall5(.waitid, @intFromEnum(id_type), @as(usize, @bitCast(@as(isize, id))), @intFromPtr(infop), flags, 0);
959}959}
960960
961pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) usize {961pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) usize {
962 return syscall3(.fcntl, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, cmd)), arg);962 return syscall3(.fcntl, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, cmd))), arg);
963}963}
964964
965pub fn flock(fd: fd_t, operation: i32) usize {965pub fn flock(fd: fd_t, operation: i32) usize {
966 return syscall2(.flock, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, operation)));966 return syscall2(.flock, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, operation))));
967}967}
968968
969var vdso_clock_gettime = @ptrCast(?*const anyopaque, &init_vdso_clock_gettime);969var vdso_clock_gettime = @as(?*const anyopaque, @ptrCast(&init_vdso_clock_gettime));
970970
971// We must follow the C calling convention when we call into the VDSO971// We must follow the C calling convention when we call into the VDSO
972const vdso_clock_gettime_ty = *align(1) const fn (i32, *timespec) callconv(.C) usize;972const vdso_clock_gettime_ty = *align(1) const fn (i32, *timespec) callconv(.C) usize;
...@@ -975,36 +975,36 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {...@@ -975,36 +975,36 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
975 if (@hasDecl(VDSO, "CGT_SYM")) {975 if (@hasDecl(VDSO, "CGT_SYM")) {
976 const ptr = @atomicLoad(?*const anyopaque, &vdso_clock_gettime, .Unordered);976 const ptr = @atomicLoad(?*const anyopaque, &vdso_clock_gettime, .Unordered);
977 if (ptr) |fn_ptr| {977 if (ptr) |fn_ptr| {
978 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);978 const f = @as(vdso_clock_gettime_ty, @ptrCast(fn_ptr));
979 const rc = f(clk_id, tp);979 const rc = f(clk_id, tp);
980 switch (rc) {980 switch (rc) {
981 0, @bitCast(usize, -@as(isize, @intFromEnum(E.INVAL))) => return rc,981 0, @as(usize, @bitCast(-@as(isize, @intFromEnum(E.INVAL)))) => return rc,
982 else => {},982 else => {},
983 }983 }
984 }984 }
985 }985 }
986 return syscall2(.clock_gettime, @bitCast(usize, @as(isize, clk_id)), @intFromPtr(tp));986 return syscall2(.clock_gettime, @as(usize, @bitCast(@as(isize, clk_id))), @intFromPtr(tp));
987}987}
988988
989fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize {989fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize {
990 const ptr = @ptrFromInt(?*const anyopaque, vdso.lookup(VDSO.CGT_VER, VDSO.CGT_SYM));990 const ptr = @as(?*const anyopaque, @ptrFromInt(vdso.lookup(VDSO.CGT_VER, VDSO.CGT_SYM)));
991 // Note that we may not have a VDSO at all, update the stub address anyway991 // Note that we may not have a VDSO at all, update the stub address anyway
992 // so that clock_gettime will fall back on the good old (and slow) syscall992 // so that clock_gettime will fall back on the good old (and slow) syscall
993 @atomicStore(?*const anyopaque, &vdso_clock_gettime, ptr, .Monotonic);993 @atomicStore(?*const anyopaque, &vdso_clock_gettime, ptr, .Monotonic);
994 // Call into the VDSO if available994 // Call into the VDSO if available
995 if (ptr) |fn_ptr| {995 if (ptr) |fn_ptr| {
996 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);996 const f = @as(vdso_clock_gettime_ty, @ptrCast(fn_ptr));
997 return f(clk, ts);997 return f(clk, ts);
998 }998 }
999 return @bitCast(usize, -@as(isize, @intFromEnum(E.NOSYS)));999 return @as(usize, @bitCast(-@as(isize, @intFromEnum(E.NOSYS))));
1000}1000}
10011001
1002pub fn clock_getres(clk_id: i32, tp: *timespec) usize {1002pub fn clock_getres(clk_id: i32, tp: *timespec) usize {
1003 return syscall2(.clock_getres, @bitCast(usize, @as(isize, clk_id)), @intFromPtr(tp));1003 return syscall2(.clock_getres, @as(usize, @bitCast(@as(isize, clk_id))), @intFromPtr(tp));
1004}1004}
10051005
1006pub fn clock_settime(clk_id: i32, tp: *const timespec) usize {1006pub fn clock_settime(clk_id: i32, tp: *const timespec) usize {
1007 return syscall2(.clock_settime, @bitCast(usize, @as(isize, clk_id)), @intFromPtr(tp));1007 return syscall2(.clock_settime, @as(usize, @bitCast(@as(isize, clk_id))), @intFromPtr(tp));
1008}1008}
10091009
1010pub fn gettimeofday(tv: *timeval, tz: *timezone) usize {1010pub fn gettimeofday(tv: *timeval, tz: *timezone) usize {
...@@ -1053,33 +1053,33 @@ pub fn setregid(rgid: gid_t, egid: gid_t) usize {...@@ -1053,33 +1053,33 @@ pub fn setregid(rgid: gid_t, egid: gid_t) usize {
10531053
1054pub fn getuid() uid_t {1054pub fn getuid() uid_t {
1055 if (@hasField(SYS, "getuid32")) {1055 if (@hasField(SYS, "getuid32")) {
1056 return @intCast(uid_t, syscall0(.getuid32));1056 return @as(uid_t, @intCast(syscall0(.getuid32)));
1057 } else {1057 } else {
1058 return @intCast(uid_t, syscall0(.getuid));1058 return @as(uid_t, @intCast(syscall0(.getuid)));
1059 }1059 }
1060}1060}
10611061
1062pub fn getgid() gid_t {1062pub fn getgid() gid_t {
1063 if (@hasField(SYS, "getgid32")) {1063 if (@hasField(SYS, "getgid32")) {
1064 return @intCast(gid_t, syscall0(.getgid32));1064 return @as(gid_t, @intCast(syscall0(.getgid32)));
1065 } else {1065 } else {
1066 return @intCast(gid_t, syscall0(.getgid));1066 return @as(gid_t, @intCast(syscall0(.getgid)));
1067 }1067 }
1068}1068}
10691069
1070pub fn geteuid() uid_t {1070pub fn geteuid() uid_t {
1071 if (@hasField(SYS, "geteuid32")) {1071 if (@hasField(SYS, "geteuid32")) {
1072 return @intCast(uid_t, syscall0(.geteuid32));1072 return @as(uid_t, @intCast(syscall0(.geteuid32)));
1073 } else {1073 } else {
1074 return @intCast(uid_t, syscall0(.geteuid));1074 return @as(uid_t, @intCast(syscall0(.geteuid)));
1075 }1075 }
1076}1076}
10771077
1078pub fn getegid() gid_t {1078pub fn getegid() gid_t {
1079 if (@hasField(SYS, "getegid32")) {1079 if (@hasField(SYS, "getegid32")) {
1080 return @intCast(gid_t, syscall0(.getegid32));1080 return @as(gid_t, @intCast(syscall0(.getegid32)));
1081 } else {1081 } else {
1082 return @intCast(gid_t, syscall0(.getegid));1082 return @as(gid_t, @intCast(syscall0(.getegid)));
1083 }1083 }
1084}1084}
10851085
...@@ -1154,11 +1154,11 @@ pub fn setgroups(size: usize, list: [*]const gid_t) usize {...@@ -1154,11 +1154,11 @@ pub fn setgroups(size: usize, list: [*]const gid_t) usize {
1154}1154}
11551155
1156pub fn getpid() pid_t {1156pub fn getpid() pid_t {
1157 return @bitCast(pid_t, @truncate(u32, syscall0(.getpid)));1157 return @as(pid_t, @bitCast(@as(u32, @truncate(syscall0(.getpid)))));
1158}1158}
11591159
1160pub fn gettid() pid_t {1160pub fn gettid() pid_t {
1161 return @bitCast(pid_t, @truncate(u32, syscall0(.gettid)));1161 return @as(pid_t, @bitCast(@as(u32, @truncate(syscall0(.gettid)))));
1162}1162}
11631163
1164pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?*sigset_t) usize {1164pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?*sigset_t) usize {
...@@ -1182,9 +1182,9 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact...@@ -1182,9 +1182,9 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact
1182 .handler = new.handler.handler,1182 .handler = new.handler.handler,
1183 .flags = new.flags | SA.RESTORER,1183 .flags = new.flags | SA.RESTORER,
1184 .mask = undefined,1184 .mask = undefined,
1185 .restorer = @ptrCast(k_sigaction_funcs.restorer, restorer_fn),1185 .restorer = @as(k_sigaction_funcs.restorer, @ptrCast(restorer_fn)),
1186 };1186 };
1187 @memcpy(@ptrCast([*]u8, &ksa.mask)[0..mask_size], @ptrCast([*]const u8, &new.mask));1187 @memcpy(@as([*]u8, @ptrCast(&ksa.mask))[0..mask_size], @as([*]const u8, @ptrCast(&new.mask)));
1188 }1188 }
11891189
1190 const ksa_arg = if (act != null) @intFromPtr(&ksa) else 0;1190 const ksa_arg = if (act != null) @intFromPtr(&ksa) else 0;
...@@ -1199,8 +1199,8 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact...@@ -1199,8 +1199,8 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact
11991199
1200 if (oact) |old| {1200 if (oact) |old| {
1201 old.handler.handler = oldksa.handler;1201 old.handler.handler = oldksa.handler;
1202 old.flags = @truncate(c_uint, oldksa.flags);1202 old.flags = @as(c_uint, @truncate(oldksa.flags));
1203 @memcpy(@ptrCast([*]u8, &old.mask)[0..mask_size], @ptrCast([*]const u8, &oldksa.mask));1203 @memcpy(@as([*]u8, @ptrCast(&old.mask))[0..mask_size], @as([*]const u8, @ptrCast(&oldksa.mask)));
1204 }1204 }
12051205
1206 return 0;1206 return 0;
...@@ -1211,28 +1211,28 @@ const usize_bits = @typeInfo(usize).Int.bits;...@@ -1211,28 +1211,28 @@ const usize_bits = @typeInfo(usize).Int.bits;
1211pub fn sigaddset(set: *sigset_t, sig: u6) void {1211pub fn sigaddset(set: *sigset_t, sig: u6) void {
1212 const s = sig - 1;1212 const s = sig - 1;
1213 // shift in musl: s&8*sizeof *set->__bits-11213 // shift in musl: s&8*sizeof *set->__bits-1
1214 const shift = @intCast(u5, s & (usize_bits - 1));1214 const shift = @as(u5, @intCast(s & (usize_bits - 1)));
1215 const val = @intCast(u32, 1) << shift;1215 const val = @as(u32, @intCast(1)) << shift;
1216 (set.*)[@intCast(usize, s) / usize_bits] |= val;1216 (set.*)[@as(usize, @intCast(s)) / usize_bits] |= val;
1217}1217}
12181218
1219pub fn sigismember(set: *const sigset_t, sig: u6) bool {1219pub fn sigismember(set: *const sigset_t, sig: u6) bool {
1220 const s = sig - 1;1220 const s = sig - 1;
1221 return ((set.*)[@intCast(usize, s) / usize_bits] & (@intCast(usize, 1) << (s & (usize_bits - 1)))) != 0;1221 return ((set.*)[@as(usize, @intCast(s)) / usize_bits] & (@as(usize, @intCast(1)) << (s & (usize_bits - 1)))) != 0;
1222}1222}
12231223
1224pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {1224pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
1225 if (native_arch == .x86) {1225 if (native_arch == .x86) {
1226 return socketcall(SC.getsockname, &[3]usize{ @bitCast(usize, @as(isize, fd)), @intFromPtr(addr), @intFromPtr(len) });1226 return socketcall(SC.getsockname, &[3]usize{ @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @intFromPtr(len) });
1227 }1227 }
1228 return syscall3(.getsockname, @bitCast(usize, @as(isize, fd)), @intFromPtr(addr), @intFromPtr(len));1228 return syscall3(.getsockname, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @intFromPtr(len));
1229}1229}
12301230
1231pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {1231pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
1232 if (native_arch == .x86) {1232 if (native_arch == .x86) {
1233 return socketcall(SC.getpeername, &[3]usize{ @bitCast(usize, @as(isize, fd)), @intFromPtr(addr), @intFromPtr(len) });1233 return socketcall(SC.getpeername, &[3]usize{ @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @intFromPtr(len) });
1234 }1234 }
1235 return syscall3(.getpeername, @bitCast(usize, @as(isize, fd)), @intFromPtr(addr), @intFromPtr(len));1235 return syscall3(.getpeername, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @intFromPtr(len));
1236}1236}
12371237
1238pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {1238pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
...@@ -1244,20 +1244,20 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {...@@ -1244,20 +1244,20 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
12441244
1245pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {1245pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
1246 if (native_arch == .x86) {1246 if (native_arch == .x86) {
1247 return socketcall(SC.setsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @intFromPtr(optval), @intCast(usize, optlen) });1247 return socketcall(SC.setsockopt, &[5]usize{ @as(usize, @bitCast(@as(isize, fd))), level, optname, @intFromPtr(optval), @as(usize, @intCast(optlen)) });
1248 }1248 }
1249 return syscall5(.setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @intFromPtr(optval), @intCast(usize, optlen));1249 return syscall5(.setsockopt, @as(usize, @bitCast(@as(isize, fd))), level, optname, @intFromPtr(optval), @as(usize, @intCast(optlen)));
1250}1250}
12511251
1252pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {1252pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
1253 if (native_arch == .x86) {1253 if (native_arch == .x86) {
1254 return socketcall(SC.getsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @intFromPtr(optval), @intFromPtr(optlen) });1254 return socketcall(SC.getsockopt, &[5]usize{ @as(usize, @bitCast(@as(isize, fd))), level, optname, @intFromPtr(optval), @intFromPtr(optlen) });
1255 }1255 }
1256 return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @intFromPtr(optval), @intFromPtr(optlen));1256 return syscall5(.getsockopt, @as(usize, @bitCast(@as(isize, fd))), level, optname, @intFromPtr(optval), @intFromPtr(optlen));
1257}1257}
12581258
1259pub fn sendmsg(fd: i32, msg: *const msghdr_const, flags: u32) usize {1259pub fn sendmsg(fd: i32, msg: *const msghdr_const, flags: u32) usize {
1260 const fd_usize = @bitCast(usize, @as(isize, fd));1260 const fd_usize = @as(usize, @bitCast(@as(isize, fd)));
1261 const msg_usize = @intFromPtr(msg);1261 const msg_usize = @intFromPtr(msg);
1262 if (native_arch == .x86) {1262 if (native_arch == .x86) {
1263 return socketcall(SC.sendmsg, &[3]usize{ fd_usize, msg_usize, flags });1263 return socketcall(SC.sendmsg, &[3]usize{ fd_usize, msg_usize, flags });
...@@ -1275,13 +1275,13 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize...@@ -1275,13 +1275,13 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
1275 var next_unsent: usize = 0;1275 var next_unsent: usize = 0;
1276 for (msgvec[0..kvlen], 0..) |*msg, i| {1276 for (msgvec[0..kvlen], 0..) |*msg, i| {
1277 var size: i32 = 0;1277 var size: i32 = 0;
1278 const msg_iovlen = @intCast(usize, msg.msg_hdr.msg_iovlen); // kernel side this is treated as unsigned1278 const msg_iovlen = @as(usize, @intCast(msg.msg_hdr.msg_iovlen)); // kernel side this is treated as unsigned
1279 for (msg.msg_hdr.msg_iov[0..msg_iovlen]) |iov| {1279 for (msg.msg_hdr.msg_iov[0..msg_iovlen]) |iov| {
1280 if (iov.iov_len > std.math.maxInt(i32) or @addWithOverflow(size, @intCast(i32, iov.iov_len))[1] != 0) {1280 if (iov.iov_len > std.math.maxInt(i32) or @addWithOverflow(size, @as(i32, @intCast(iov.iov_len)))[1] != 0) {
1281 // batch-send all messages up to the current message1281 // batch-send all messages up to the current message
1282 if (next_unsent < i) {1282 if (next_unsent < i) {
1283 const batch_size = i - next_unsent;1283 const batch_size = i - next_unsent;
1284 const r = syscall4(.sendmmsg, @bitCast(usize, @as(isize, fd)), @intFromPtr(&msgvec[next_unsent]), batch_size, flags);1284 const r = syscall4(.sendmmsg, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(&msgvec[next_unsent]), batch_size, flags);
1285 if (getErrno(r) != 0) return next_unsent;1285 if (getErrno(r) != 0) return next_unsent;
1286 if (r < batch_size) return next_unsent + r;1286 if (r < batch_size) return next_unsent + r;
1287 }1287 }
...@@ -1289,7 +1289,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize...@@ -1289,7 +1289,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
1289 const r = sendmsg(fd, &msg.msg_hdr, flags);1289 const r = sendmsg(fd, &msg.msg_hdr, flags);
1290 if (getErrno(r) != 0) return r;1290 if (getErrno(r) != 0) return r;
1291 // Linux limits the total bytes sent by sendmsg to INT_MAX, so this cast is safe.1291 // Linux limits the total bytes sent by sendmsg to INT_MAX, so this cast is safe.
1292 msg.msg_len = @intCast(u32, r);1292 msg.msg_len = @as(u32, @intCast(r));
1293 next_unsent = i + 1;1293 next_unsent = i + 1;
1294 break;1294 break;
1295 }1295 }
...@@ -1297,17 +1297,17 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize...@@ -1297,17 +1297,17 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
1297 }1297 }
1298 if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG.EOR)1298 if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG.EOR)
1299 const batch_size = kvlen - next_unsent;1299 const batch_size = kvlen - next_unsent;
1300 const r = syscall4(.sendmmsg, @bitCast(usize, @as(isize, fd)), @intFromPtr(&msgvec[next_unsent]), batch_size, flags);1300 const r = syscall4(.sendmmsg, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(&msgvec[next_unsent]), batch_size, flags);
1301 if (getErrno(r) != 0) return r;1301 if (getErrno(r) != 0) return r;
1302 return next_unsent + r;1302 return next_unsent + r;
1303 }1303 }
1304 return kvlen;1304 return kvlen;
1305 }1305 }
1306 return syscall4(.sendmmsg, @bitCast(usize, @as(isize, fd)), @intFromPtr(msgvec), vlen, flags);1306 return syscall4(.sendmmsg, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(msgvec), vlen, flags);
1307}1307}
13081308
1309pub fn connect(fd: i32, addr: *const anyopaque, len: socklen_t) usize {1309pub fn connect(fd: i32, addr: *const anyopaque, len: socklen_t) usize {
1310 const fd_usize = @bitCast(usize, @as(isize, fd));1310 const fd_usize = @as(usize, @bitCast(@as(isize, fd)));
1311 const addr_usize = @intFromPtr(addr);1311 const addr_usize = @intFromPtr(addr);
1312 if (native_arch == .x86) {1312 if (native_arch == .x86) {
1313 return socketcall(SC.connect, &[3]usize{ fd_usize, addr_usize, len });1313 return socketcall(SC.connect, &[3]usize{ fd_usize, addr_usize, len });
...@@ -1317,7 +1317,7 @@ pub fn connect(fd: i32, addr: *const anyopaque, len: socklen_t) usize {...@@ -1317,7 +1317,7 @@ pub fn connect(fd: i32, addr: *const anyopaque, len: socklen_t) usize {
1317}1317}
13181318
1319pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {1319pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {
1320 const fd_usize = @bitCast(usize, @as(isize, fd));1320 const fd_usize = @as(usize, @bitCast(@as(isize, fd)));
1321 const msg_usize = @intFromPtr(msg);1321 const msg_usize = @intFromPtr(msg);
1322 if (native_arch == .x86) {1322 if (native_arch == .x86) {
1323 return socketcall(SC.recvmsg, &[3]usize{ fd_usize, msg_usize, flags });1323 return socketcall(SC.recvmsg, &[3]usize{ fd_usize, msg_usize, flags });
...@@ -1334,7 +1334,7 @@ pub fn recvfrom(...@@ -1334,7 +1334,7 @@ pub fn recvfrom(
1334 noalias addr: ?*sockaddr,1334 noalias addr: ?*sockaddr,
1335 noalias alen: ?*socklen_t,1335 noalias alen: ?*socklen_t,
1336) usize {1336) usize {
1337 const fd_usize = @bitCast(usize, @as(isize, fd));1337 const fd_usize = @as(usize, @bitCast(@as(isize, fd)));
1338 const buf_usize = @intFromPtr(buf);1338 const buf_usize = @intFromPtr(buf);
1339 const addr_usize = @intFromPtr(addr);1339 const addr_usize = @intFromPtr(addr);
1340 const alen_usize = @intFromPtr(alen);1340 const alen_usize = @intFromPtr(alen);
...@@ -1347,46 +1347,46 @@ pub fn recvfrom(...@@ -1347,46 +1347,46 @@ pub fn recvfrom(
13471347
1348pub fn shutdown(fd: i32, how: i32) usize {1348pub fn shutdown(fd: i32, how: i32) usize {
1349 if (native_arch == .x86) {1349 if (native_arch == .x86) {
1350 return socketcall(SC.shutdown, &[2]usize{ @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)) });1350 return socketcall(SC.shutdown, &[2]usize{ @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, how))) });
1351 }1351 }
1352 return syscall2(.shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)));1352 return syscall2(.shutdown, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, how))));
1353}1353}
13541354
1355pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {1355pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
1356 if (native_arch == .x86) {1356 if (native_arch == .x86) {
1357 return socketcall(SC.bind, &[3]usize{ @bitCast(usize, @as(isize, fd)), @intFromPtr(addr), @intCast(usize, len) });1357 return socketcall(SC.bind, &[3]usize{ @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @as(usize, @intCast(len)) });
1358 }1358 }
1359 return syscall3(.bind, @bitCast(usize, @as(isize, fd)), @intFromPtr(addr), @intCast(usize, len));1359 return syscall3(.bind, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @as(usize, @intCast(len)));
1360}1360}
13611361
1362pub fn listen(fd: i32, backlog: u32) usize {1362pub fn listen(fd: i32, backlog: u32) usize {
1363 if (native_arch == .x86) {1363 if (native_arch == .x86) {
1364 return socketcall(SC.listen, &[2]usize{ @bitCast(usize, @as(isize, fd)), backlog });1364 return socketcall(SC.listen, &[2]usize{ @as(usize, @bitCast(@as(isize, fd))), backlog });
1365 }1365 }
1366 return syscall2(.listen, @bitCast(usize, @as(isize, fd)), backlog);1366 return syscall2(.listen, @as(usize, @bitCast(@as(isize, fd))), backlog);
1367}1367}
13681368
1369pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {1369pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {
1370 if (native_arch == .x86) {1370 if (native_arch == .x86) {
1371 return socketcall(SC.sendto, &[6]usize{ @bitCast(usize, @as(isize, fd)), @intFromPtr(buf), len, flags, @intFromPtr(addr), @intCast(usize, alen) });1371 return socketcall(SC.sendto, &[6]usize{ @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(buf), len, flags, @intFromPtr(addr), @as(usize, @intCast(alen)) });
1372 }1372 }
1373 return syscall6(.sendto, @bitCast(usize, @as(isize, fd)), @intFromPtr(buf), len, flags, @intFromPtr(addr), @intCast(usize, alen));1373 return syscall6(.sendto, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(buf), len, flags, @intFromPtr(addr), @as(usize, @intCast(alen)));
1374}1374}
13751375
1376pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize {1376pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize {
1377 if (@hasField(SYS, "sendfile64")) {1377 if (@hasField(SYS, "sendfile64")) {
1378 return syscall4(1378 return syscall4(
1379 .sendfile64,1379 .sendfile64,
1380 @bitCast(usize, @as(isize, outfd)),1380 @as(usize, @bitCast(@as(isize, outfd))),
1381 @bitCast(usize, @as(isize, infd)),1381 @as(usize, @bitCast(@as(isize, infd))),
1382 @intFromPtr(offset),1382 @intFromPtr(offset),
1383 count,1383 count,
1384 );1384 );
1385 } else {1385 } else {
1386 return syscall4(1386 return syscall4(
1387 .sendfile,1387 .sendfile,
1388 @bitCast(usize, @as(isize, outfd)),1388 @as(usize, @bitCast(@as(isize, outfd))),
1389 @bitCast(usize, @as(isize, infd)),1389 @as(usize, @bitCast(@as(isize, infd))),
1390 @intFromPtr(offset),1390 @intFromPtr(offset),
1391 count,1391 count,
1392 );1392 );
...@@ -1395,9 +1395,9 @@ pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize {...@@ -1395,9 +1395,9 @@ pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize {
13951395
1396pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: *[2]i32) usize {1396pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: *[2]i32) usize {
1397 if (native_arch == .x86) {1397 if (native_arch == .x86) {
1398 return socketcall(SC.socketpair, &[4]usize{ @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @intFromPtr(fd) });1398 return socketcall(SC.socketpair, &[4]usize{ @as(usize, @intCast(domain)), @as(usize, @intCast(socket_type)), @as(usize, @intCast(protocol)), @intFromPtr(fd) });
1399 }1399 }
1400 return syscall4(.socketpair, @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @intFromPtr(fd));1400 return syscall4(.socketpair, @as(usize, @intCast(domain)), @as(usize, @intCast(socket_type)), @as(usize, @intCast(protocol)), @intFromPtr(fd));
1401}1401}
14021402
1403pub fn accept(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t) usize {1403pub fn accept(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t) usize {
...@@ -1409,16 +1409,16 @@ pub fn accept(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t) usize...@@ -1409,16 +1409,16 @@ pub fn accept(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t) usize
14091409
1410pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flags: u32) usize {1410pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flags: u32) usize {
1411 if (native_arch == .x86) {1411 if (native_arch == .x86) {
1412 return socketcall(SC.accept4, &[4]usize{ @bitCast(usize, @as(isize, fd)), @intFromPtr(addr), @intFromPtr(len), flags });1412 return socketcall(SC.accept4, &[4]usize{ @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @intFromPtr(len), flags });
1413 }1413 }
1414 return syscall4(.accept4, @bitCast(usize, @as(isize, fd)), @intFromPtr(addr), @intFromPtr(len), flags);1414 return syscall4(.accept4, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @intFromPtr(len), flags);
1415}1415}
14161416
1417pub fn fstat(fd: i32, stat_buf: *Stat) usize {1417pub fn fstat(fd: i32, stat_buf: *Stat) usize {
1418 if (@hasField(SYS, "fstat64")) {1418 if (@hasField(SYS, "fstat64")) {
1419 return syscall2(.fstat64, @bitCast(usize, @as(isize, fd)), @intFromPtr(stat_buf));1419 return syscall2(.fstat64, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(stat_buf));
1420 } else {1420 } else {
1421 return syscall2(.fstat, @bitCast(usize, @as(isize, fd)), @intFromPtr(stat_buf));1421 return syscall2(.fstat, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(stat_buf));
1422 }1422 }
1423}1423}
14241424
...@@ -1440,9 +1440,9 @@ pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize {...@@ -1440,9 +1440,9 @@ pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize {
14401440
1441pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *Stat, flags: u32) usize {1441pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *Stat, flags: u32) usize {
1442 if (@hasField(SYS, "fstatat64")) {1442 if (@hasField(SYS, "fstatat64")) {
1443 return syscall4(.fstatat64, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), @intFromPtr(stat_buf), flags);1443 return syscall4(.fstatat64, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), @intFromPtr(stat_buf), flags);
1444 } else {1444 } else {
1445 return syscall4(.fstatat, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), @intFromPtr(stat_buf), flags);1445 return syscall4(.fstatat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), @intFromPtr(stat_buf), flags);
1446 }1446 }
1447}1447}
14481448
...@@ -1450,14 +1450,14 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S...@@ -1450,14 +1450,14 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S
1450 if (@hasField(SYS, "statx")) {1450 if (@hasField(SYS, "statx")) {
1451 return syscall5(1451 return syscall5(
1452 .statx,1452 .statx,
1453 @bitCast(usize, @as(isize, dirfd)),1453 @as(usize, @bitCast(@as(isize, dirfd))),
1454 @intFromPtr(path),1454 @intFromPtr(path),
1455 flags,1455 flags,
1456 mask,1456 mask,
1457 @intFromPtr(statx_buf),1457 @intFromPtr(statx_buf),
1458 );1458 );
1459 }1459 }
1460 return @bitCast(usize, -@as(isize, @intFromEnum(E.NOSYS)));1460 return @as(usize, @bitCast(-@as(isize, @intFromEnum(E.NOSYS))));
1461}1461}
14621462
1463pub fn listxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize {1463pub fn listxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize {
...@@ -1513,9 +1513,9 @@ pub fn sched_yield() usize {...@@ -1513,9 +1513,9 @@ pub fn sched_yield() usize {
1513}1513}
15141514
1515pub fn sched_getaffinity(pid: pid_t, size: usize, set: *cpu_set_t) usize {1515pub fn sched_getaffinity(pid: pid_t, size: usize, set: *cpu_set_t) usize {
1516 const rc = syscall3(.sched_getaffinity, @bitCast(usize, @as(isize, pid)), size, @intFromPtr(set));1516 const rc = syscall3(.sched_getaffinity, @as(usize, @bitCast(@as(isize, pid))), size, @intFromPtr(set));
1517 if (@bitCast(isize, rc) < 0) return rc;1517 if (@as(isize, @bitCast(rc)) < 0) return rc;
1518 if (rc < size) @memset(@ptrCast([*]u8, set)[rc..size], 0);1518 if (rc < size) @memset(@as([*]u8, @ptrCast(set))[rc..size], 0);
1519 return 0;1519 return 0;
1520}1520}
15211521
...@@ -1526,18 +1526,18 @@ pub fn getcpu(cpu: *u32, node: *u32) usize {...@@ -1526,18 +1526,18 @@ pub fn getcpu(cpu: *u32, node: *u32) usize {
1526pub fn sched_getcpu() usize {1526pub fn sched_getcpu() usize {
1527 var cpu: u32 = undefined;1527 var cpu: u32 = undefined;
1528 const rc = syscall3(.getcpu, @intFromPtr(&cpu), 0, 0);1528 const rc = syscall3(.getcpu, @intFromPtr(&cpu), 0, 0);
1529 if (@bitCast(isize, rc) < 0) return rc;1529 if (@as(isize, @bitCast(rc)) < 0) return rc;
1530 return @intCast(usize, cpu);1530 return @as(usize, @intCast(cpu));
1531}1531}
15321532
1533/// libc has no wrapper for this syscall1533/// libc has no wrapper for this syscall
1534pub fn mbind(addr: ?*anyopaque, len: u32, mode: i32, nodemask: *const u32, maxnode: u32, flags: u32) usize {1534pub fn mbind(addr: ?*anyopaque, len: u32, mode: i32, nodemask: *const u32, maxnode: u32, flags: u32) usize {
1535 return syscall6(.mbind, @intFromPtr(addr), len, @bitCast(usize, @as(isize, mode)), @intFromPtr(nodemask), maxnode, flags);1535 return syscall6(.mbind, @intFromPtr(addr), len, @as(usize, @bitCast(@as(isize, mode))), @intFromPtr(nodemask), maxnode, flags);
1536}1536}
15371537
1538pub fn sched_setaffinity(pid: pid_t, size: usize, set: *const cpu_set_t) usize {1538pub fn sched_setaffinity(pid: pid_t, size: usize, set: *const cpu_set_t) usize {
1539 const rc = syscall3(.sched_setaffinity, @bitCast(usize, @as(isize, pid)), size, @intFromPtr(set));1539 const rc = syscall3(.sched_setaffinity, @as(usize, @bitCast(@as(isize, pid))), size, @intFromPtr(set));
1540 if (@bitCast(isize, rc) < 0) return rc;1540 if (@as(isize, @bitCast(rc)) < 0) return rc;
1541 return 0;1541 return 0;
1542}1542}
15431543
...@@ -1550,7 +1550,7 @@ pub fn epoll_create1(flags: usize) usize {...@@ -1550,7 +1550,7 @@ pub fn epoll_create1(flags: usize) usize {
1550}1550}
15511551
1552pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize {1552pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize {
1553 return syscall4(.epoll_ctl, @bitCast(usize, @as(isize, epoll_fd)), @intCast(usize, op), @bitCast(usize, @as(isize, fd)), @intFromPtr(ev));1553 return syscall4(.epoll_ctl, @as(usize, @bitCast(@as(isize, epoll_fd))), @as(usize, @intCast(op)), @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(ev));
1554}1554}
15551555
1556pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize {1556pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize {
...@@ -1560,10 +1560,10 @@ pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout...@@ -1560,10 +1560,10 @@ pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout
1560pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*const sigset_t) usize {1560pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*const sigset_t) usize {
1561 return syscall6(1561 return syscall6(
1562 .epoll_pwait,1562 .epoll_pwait,
1563 @bitCast(usize, @as(isize, epoll_fd)),1563 @as(usize, @bitCast(@as(isize, epoll_fd))),
1564 @intFromPtr(events),1564 @intFromPtr(events),
1565 @intCast(usize, maxevents),1565 @as(usize, @intCast(maxevents)),
1566 @bitCast(usize, @as(isize, timeout)),1566 @as(usize, @bitCast(@as(isize, timeout))),
1567 @intFromPtr(sigmask),1567 @intFromPtr(sigmask),
1568 @sizeOf(sigset_t),1568 @sizeOf(sigset_t),
1569 );1569 );
...@@ -1574,7 +1574,7 @@ pub fn eventfd(count: u32, flags: u32) usize {...@@ -1574,7 +1574,7 @@ pub fn eventfd(count: u32, flags: u32) usize {
1574}1574}
15751575
1576pub fn timerfd_create(clockid: i32, flags: u32) usize {1576pub fn timerfd_create(clockid: i32, flags: u32) usize {
1577 return syscall2(.timerfd_create, @bitCast(usize, @as(isize, clockid)), flags);1577 return syscall2(.timerfd_create, @as(usize, @bitCast(@as(isize, clockid))), flags);
1578}1578}
15791579
1580pub const itimerspec = extern struct {1580pub const itimerspec = extern struct {
...@@ -1583,11 +1583,11 @@ pub const itimerspec = extern struct {...@@ -1583,11 +1583,11 @@ pub const itimerspec = extern struct {
1583};1583};
15841584
1585pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {1585pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {
1586 return syscall2(.timerfd_gettime, @bitCast(usize, @as(isize, fd)), @intFromPtr(curr_value));1586 return syscall2(.timerfd_gettime, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(curr_value));
1587}1587}
15881588
1589pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {1589pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
1590 return syscall4(.timerfd_settime, @bitCast(usize, @as(isize, fd)), flags, @intFromPtr(new_value), @intFromPtr(old_value));1590 return syscall4(.timerfd_settime, @as(usize, @bitCast(@as(isize, fd))), flags, @intFromPtr(new_value), @intFromPtr(old_value));
1591}1591}
15921592
1593pub const sigevent = extern struct {1593pub const sigevent = extern struct {
...@@ -1609,8 +1609,8 @@ pub const timer_t = ?*anyopaque;...@@ -1609,8 +1609,8 @@ pub const timer_t = ?*anyopaque;
16091609
1610pub fn timer_create(clockid: i32, sevp: *sigevent, timerid: *timer_t) usize {1610pub fn timer_create(clockid: i32, sevp: *sigevent, timerid: *timer_t) usize {
1611 var t: timer_t = undefined;1611 var t: timer_t = undefined;
1612 const rc = syscall3(.timer_create, @bitCast(usize, @as(isize, clockid)), @intFromPtr(sevp), @intFromPtr(&t));1612 const rc = syscall3(.timer_create, @as(usize, @bitCast(@as(isize, clockid))), @intFromPtr(sevp), @intFromPtr(&t));
1613 if (@bitCast(isize, rc) < 0) return rc;1613 if (@as(isize, @bitCast(rc)) < 0) return rc;
1614 timerid.* = t;1614 timerid.* = t;
1615 return rc;1615 return rc;
1616}1616}
...@@ -1624,7 +1624,7 @@ pub fn timer_gettime(timerid: timer_t, curr_value: *itimerspec) usize {...@@ -1624,7 +1624,7 @@ pub fn timer_gettime(timerid: timer_t, curr_value: *itimerspec) usize {
1624}1624}
16251625
1626pub fn timer_settime(timerid: timer_t, flags: i32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {1626pub fn timer_settime(timerid: timer_t, flags: i32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
1627 return syscall4(.timer_settime, @intFromPtr(timerid), @bitCast(usize, @as(isize, flags)), @intFromPtr(new_value), @intFromPtr(old_value));1627 return syscall4(.timer_settime, @intFromPtr(timerid), @as(usize, @bitCast(@as(isize, flags))), @intFromPtr(new_value), @intFromPtr(old_value));
1628}1628}
16291629
1630// Flags for the 'setitimer' system call1630// Flags for the 'setitimer' system call
...@@ -1635,11 +1635,11 @@ pub const ITIMER = enum(i32) {...@@ -1635,11 +1635,11 @@ pub const ITIMER = enum(i32) {
1635};1635};
16361636
1637pub fn getitimer(which: i32, curr_value: *itimerspec) usize {1637pub fn getitimer(which: i32, curr_value: *itimerspec) usize {
1638 return syscall2(.getitimer, @bitCast(usize, @as(isize, which)), @intFromPtr(curr_value));1638 return syscall2(.getitimer, @as(usize, @bitCast(@as(isize, which))), @intFromPtr(curr_value));
1639}1639}
16401640
1641pub fn setitimer(which: i32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {1641pub fn setitimer(which: i32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
1642 return syscall3(.setitimer, @bitCast(usize, @as(isize, which)), @intFromPtr(new_value), @intFromPtr(old_value));1642 return syscall3(.setitimer, @as(usize, @bitCast(@as(isize, which))), @intFromPtr(new_value), @intFromPtr(old_value));
1643}1643}
16441644
1645pub fn unshare(flags: usize) usize {1645pub fn unshare(flags: usize) usize {
...@@ -1667,11 +1667,11 @@ pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize {...@@ -1667,11 +1667,11 @@ pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize {
1667}1667}
16681668
1669pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize {1669pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize {
1670 return syscall6(.io_uring_enter, @bitCast(usize, @as(isize, fd)), to_submit, min_complete, flags, @intFromPtr(sig), NSIG / 8);1670 return syscall6(.io_uring_enter, @as(usize, @bitCast(@as(isize, fd))), to_submit, min_complete, flags, @intFromPtr(sig), NSIG / 8);
1671}1671}
16721672
1673pub fn io_uring_register(fd: i32, opcode: IORING_REGISTER, arg: ?*const anyopaque, nr_args: u32) usize {1673pub fn io_uring_register(fd: i32, opcode: IORING_REGISTER, arg: ?*const anyopaque, nr_args: u32) usize {
1674 return syscall4(.io_uring_register, @bitCast(usize, @as(isize, fd)), @intFromEnum(opcode), @intFromPtr(arg), nr_args);1674 return syscall4(.io_uring_register, @as(usize, @bitCast(@as(isize, fd))), @intFromEnum(opcode), @intFromPtr(arg), nr_args);
1675}1675}
16761676
1677pub fn memfd_create(name: [*:0]const u8, flags: u32) usize {1677pub fn memfd_create(name: [*:0]const u8, flags: u32) usize {
...@@ -1679,43 +1679,43 @@ pub fn memfd_create(name: [*:0]const u8, flags: u32) usize {...@@ -1679,43 +1679,43 @@ pub fn memfd_create(name: [*:0]const u8, flags: u32) usize {
1679}1679}
16801680
1681pub fn getrusage(who: i32, usage: *rusage) usize {1681pub fn getrusage(who: i32, usage: *rusage) usize {
1682 return syscall2(.getrusage, @bitCast(usize, @as(isize, who)), @intFromPtr(usage));1682 return syscall2(.getrusage, @as(usize, @bitCast(@as(isize, who))), @intFromPtr(usage));
1683}1683}
16841684
1685pub fn tcgetattr(fd: fd_t, termios_p: *termios) usize {1685pub fn tcgetattr(fd: fd_t, termios_p: *termios) usize {
1686 return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.CGETS, @intFromPtr(termios_p));1686 return syscall3(.ioctl, @as(usize, @bitCast(@as(isize, fd))), T.CGETS, @intFromPtr(termios_p));
1687}1687}
16881688
1689pub fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) usize {1689pub fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) usize {
1690 return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.CSETS + @intFromEnum(optional_action), @intFromPtr(termios_p));1690 return syscall3(.ioctl, @as(usize, @bitCast(@as(isize, fd))), T.CSETS + @intFromEnum(optional_action), @intFromPtr(termios_p));
1691}1691}
16921692
1693pub fn tcgetpgrp(fd: fd_t, pgrp: *pid_t) usize {1693pub fn tcgetpgrp(fd: fd_t, pgrp: *pid_t) usize {
1694 return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.IOCGPGRP, @intFromPtr(pgrp));1694 return syscall3(.ioctl, @as(usize, @bitCast(@as(isize, fd))), T.IOCGPGRP, @intFromPtr(pgrp));
1695}1695}
16961696
1697pub fn tcsetpgrp(fd: fd_t, pgrp: *const pid_t) usize {1697pub fn tcsetpgrp(fd: fd_t, pgrp: *const pid_t) usize {
1698 return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.IOCSPGRP, @intFromPtr(pgrp));1698 return syscall3(.ioctl, @as(usize, @bitCast(@as(isize, fd))), T.IOCSPGRP, @intFromPtr(pgrp));
1699}1699}
17001700
1701pub fn tcdrain(fd: fd_t) usize {1701pub fn tcdrain(fd: fd_t) usize {
1702 return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.CSBRK, 1);1702 return syscall3(.ioctl, @as(usize, @bitCast(@as(isize, fd))), T.CSBRK, 1);
1703}1703}
17041704
1705pub fn ioctl(fd: fd_t, request: u32, arg: usize) usize {1705pub fn ioctl(fd: fd_t, request: u32, arg: usize) usize {
1706 return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), request, arg);1706 return syscall3(.ioctl, @as(usize, @bitCast(@as(isize, fd))), request, arg);
1707}1707}
17081708
1709pub fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) usize {1709pub fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) usize {
1710 return syscall4(.signalfd4, @bitCast(usize, @as(isize, fd)), @intFromPtr(mask), NSIG / 8, flags);1710 return syscall4(.signalfd4, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(mask), NSIG / 8, flags);
1711}1711}
17121712
1713pub fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, len: usize, flags: u32) usize {1713pub fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, len: usize, flags: u32) usize {
1714 return syscall6(1714 return syscall6(
1715 .copy_file_range,1715 .copy_file_range,
1716 @bitCast(usize, @as(isize, fd_in)),1716 @as(usize, @bitCast(@as(isize, fd_in))),
1717 @intFromPtr(off_in),1717 @intFromPtr(off_in),
1718 @bitCast(usize, @as(isize, fd_out)),1718 @as(usize, @bitCast(@as(isize, fd_out))),
1719 @intFromPtr(off_out),1719 @intFromPtr(off_out),
1720 len,1720 len,
1721 flags,1721 flags,
...@@ -1731,19 +1731,19 @@ pub fn sync() void {...@@ -1731,19 +1731,19 @@ pub fn sync() void {
1731}1731}
17321732
1733pub fn syncfs(fd: fd_t) usize {1733pub fn syncfs(fd: fd_t) usize {
1734 return syscall1(.syncfs, @bitCast(usize, @as(isize, fd)));1734 return syscall1(.syncfs, @as(usize, @bitCast(@as(isize, fd))));
1735}1735}
17361736
1737pub fn fsync(fd: fd_t) usize {1737pub fn fsync(fd: fd_t) usize {
1738 return syscall1(.fsync, @bitCast(usize, @as(isize, fd)));1738 return syscall1(.fsync, @as(usize, @bitCast(@as(isize, fd))));
1739}1739}
17401740
1741pub fn fdatasync(fd: fd_t) usize {1741pub fn fdatasync(fd: fd_t) usize {
1742 return syscall1(.fdatasync, @bitCast(usize, @as(isize, fd)));1742 return syscall1(.fdatasync, @as(usize, @bitCast(@as(isize, fd))));
1743}1743}
17441744
1745pub fn prctl(option: i32, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {1745pub fn prctl(option: i32, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
1746 return syscall5(.prctl, @bitCast(usize, @as(isize, option)), arg2, arg3, arg4, arg5);1746 return syscall5(.prctl, @as(usize, @bitCast(@as(isize, option))), arg2, arg3, arg4, arg5);
1747}1747}
17481748
1749pub fn getrlimit(resource: rlimit_resource, rlim: *rlimit) usize {1749pub fn getrlimit(resource: rlimit_resource, rlim: *rlimit) usize {
...@@ -1759,8 +1759,8 @@ pub fn setrlimit(resource: rlimit_resource, rlim: *const rlimit) usize {...@@ -1759,8 +1759,8 @@ pub fn setrlimit(resource: rlimit_resource, rlim: *const rlimit) usize {
1759pub fn prlimit(pid: pid_t, resource: rlimit_resource, new_limit: ?*const rlimit, old_limit: ?*rlimit) usize {1759pub fn prlimit(pid: pid_t, resource: rlimit_resource, new_limit: ?*const rlimit, old_limit: ?*rlimit) usize {
1760 return syscall4(1760 return syscall4(
1761 .prlimit64,1761 .prlimit64,
1762 @bitCast(usize, @as(isize, pid)),1762 @as(usize, @bitCast(@as(isize, pid))),
1763 @bitCast(usize, @as(isize, @intFromEnum(resource))),1763 @as(usize, @bitCast(@as(isize, @intFromEnum(resource)))),
1764 @intFromPtr(new_limit),1764 @intFromPtr(new_limit),
1765 @intFromPtr(old_limit),1765 @intFromPtr(old_limit),
1766 );1766 );
...@@ -1775,14 +1775,14 @@ pub fn madvise(address: [*]u8, len: usize, advice: u32) usize {...@@ -1775,14 +1775,14 @@ pub fn madvise(address: [*]u8, len: usize, advice: u32) usize {
1775}1775}
17761776
1777pub fn pidfd_open(pid: pid_t, flags: u32) usize {1777pub fn pidfd_open(pid: pid_t, flags: u32) usize {
1778 return syscall2(.pidfd_open, @bitCast(usize, @as(isize, pid)), flags);1778 return syscall2(.pidfd_open, @as(usize, @bitCast(@as(isize, pid))), flags);
1779}1779}
17801780
1781pub fn pidfd_getfd(pidfd: fd_t, targetfd: fd_t, flags: u32) usize {1781pub fn pidfd_getfd(pidfd: fd_t, targetfd: fd_t, flags: u32) usize {
1782 return syscall3(1782 return syscall3(
1783 .pidfd_getfd,1783 .pidfd_getfd,
1784 @bitCast(usize, @as(isize, pidfd)),1784 @as(usize, @bitCast(@as(isize, pidfd))),
1785 @bitCast(usize, @as(isize, targetfd)),1785 @as(usize, @bitCast(@as(isize, targetfd))),
1786 flags,1786 flags,
1787 );1787 );
1788}1788}
...@@ -1790,8 +1790,8 @@ pub fn pidfd_getfd(pidfd: fd_t, targetfd: fd_t, flags: u32) usize {...@@ -1790,8 +1790,8 @@ pub fn pidfd_getfd(pidfd: fd_t, targetfd: fd_t, flags: u32) usize {
1790pub fn pidfd_send_signal(pidfd: fd_t, sig: i32, info: ?*siginfo_t, flags: u32) usize {1790pub fn pidfd_send_signal(pidfd: fd_t, sig: i32, info: ?*siginfo_t, flags: u32) usize {
1791 return syscall4(1791 return syscall4(
1792 .pidfd_send_signal,1792 .pidfd_send_signal,
1793 @bitCast(usize, @as(isize, pidfd)),1793 @as(usize, @bitCast(@as(isize, pidfd))),
1794 @bitCast(usize, @as(isize, sig)),1794 @as(usize, @bitCast(@as(isize, sig))),
1795 @intFromPtr(info),1795 @intFromPtr(info),
1796 flags,1796 flags,
1797 );1797 );
...@@ -1800,7 +1800,7 @@ pub fn pidfd_send_signal(pidfd: fd_t, sig: i32, info: ?*siginfo_t, flags: u32) u...@@ -1800,7 +1800,7 @@ pub fn pidfd_send_signal(pidfd: fd_t, sig: i32, info: ?*siginfo_t, flags: u32) u
1800pub fn process_vm_readv(pid: pid_t, local: []iovec, remote: []const iovec_const, flags: usize) usize {1800pub fn process_vm_readv(pid: pid_t, local: []iovec, remote: []const iovec_const, flags: usize) usize {
1801 return syscall6(1801 return syscall6(
1802 .process_vm_readv,1802 .process_vm_readv,
1803 @bitCast(usize, @as(isize, pid)),1803 @as(usize, @bitCast(@as(isize, pid))),
1804 @intFromPtr(local.ptr),1804 @intFromPtr(local.ptr),
1805 local.len,1805 local.len,
1806 @intFromPtr(remote.ptr),1806 @intFromPtr(remote.ptr),
...@@ -1812,7 +1812,7 @@ pub fn process_vm_readv(pid: pid_t, local: []iovec, remote: []const iovec_const,...@@ -1812,7 +1812,7 @@ pub fn process_vm_readv(pid: pid_t, local: []iovec, remote: []const iovec_const,
1812pub fn process_vm_writev(pid: pid_t, local: []const iovec_const, remote: []const iovec_const, flags: usize) usize {1812pub fn process_vm_writev(pid: pid_t, local: []const iovec_const, remote: []const iovec_const, flags: usize) usize {
1813 return syscall6(1813 return syscall6(
1814 .process_vm_writev,1814 .process_vm_writev,
1815 @bitCast(usize, @as(isize, pid)),1815 @as(usize, @bitCast(@as(isize, pid))),
1816 @intFromPtr(local.ptr),1816 @intFromPtr(local.ptr),
1817 local.len,1817 local.len,
1818 @intFromPtr(remote.ptr),1818 @intFromPtr(remote.ptr),
...@@ -1830,7 +1830,7 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {...@@ -1830,7 +1830,7 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {
18301830
1831 return syscall7(1831 return syscall7(
1832 .fadvise64,1832 .fadvise64,
1833 @bitCast(usize, @as(isize, fd)),1833 @as(usize, @bitCast(@as(isize, fd))),
1834 0,1834 0,
1835 offset_halves[0],1835 offset_halves[0],
1836 offset_halves[1],1836 offset_halves[1],
...@@ -1846,7 +1846,7 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {...@@ -1846,7 +1846,7 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {
18461846
1847 return syscall6(1847 return syscall6(
1848 .fadvise64_64,1848 .fadvise64_64,
1849 @bitCast(usize, @as(isize, fd)),1849 @as(usize, @bitCast(@as(isize, fd))),
1850 advice,1850 advice,
1851 offset_halves[0],1851 offset_halves[0],
1852 offset_halves[1],1852 offset_halves[1],
...@@ -1862,7 +1862,7 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {...@@ -1862,7 +1862,7 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {
18621862
1863 return syscall6(1863 return syscall6(
1864 .fadvise64_64,1864 .fadvise64_64,
1865 @bitCast(usize, @as(isize, fd)),1865 @as(usize, @bitCast(@as(isize, fd))),
1866 offset_halves[0],1866 offset_halves[0],
1867 offset_halves[1],1867 offset_halves[1],
1868 length_halves[0],1868 length_halves[0],
...@@ -1872,9 +1872,9 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {...@@ -1872,9 +1872,9 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {
1872 } else {1872 } else {
1873 return syscall4(1873 return syscall4(
1874 .fadvise64,1874 .fadvise64,
1875 @bitCast(usize, @as(isize, fd)),1875 @as(usize, @bitCast(@as(isize, fd))),
1876 @bitCast(usize, offset),1876 @as(usize, @bitCast(offset)),
1877 @bitCast(usize, len),1877 @as(usize, @bitCast(len)),
1878 advice,1878 advice,
1879 );1879 );
1880 }1880 }
...@@ -1890,9 +1890,9 @@ pub fn perf_event_open(...@@ -1890,9 +1890,9 @@ pub fn perf_event_open(
1890 return syscall5(1890 return syscall5(
1891 .perf_event_open,1891 .perf_event_open,
1892 @intFromPtr(attr),1892 @intFromPtr(attr),
1893 @bitCast(usize, @as(isize, pid)),1893 @as(usize, @bitCast(@as(isize, pid))),
1894 @bitCast(usize, @as(isize, cpu)),1894 @as(usize, @bitCast(@as(isize, cpu))),
1895 @bitCast(usize, @as(isize, group_fd)),1895 @as(usize, @bitCast(@as(isize, group_fd))),
1896 flags,1896 flags,
1897 );1897 );
1898}1898}
...@@ -1911,7 +1911,7 @@ pub fn ptrace(...@@ -1911,7 +1911,7 @@ pub fn ptrace(
1911 return syscall5(1911 return syscall5(
1912 .ptrace,1912 .ptrace,
1913 req,1913 req,
1914 @bitCast(usize, @as(isize, pid)),1914 @as(usize, @bitCast(@as(isize, pid))),
1915 addr,1915 addr,
1916 data,1916 data,
1917 addr2,1917 addr2,
...@@ -2057,7 +2057,7 @@ pub const W = struct {...@@ -2057,7 +2057,7 @@ pub const W = struct {
2057 pub const NOWAIT = 0x1000000;2057 pub const NOWAIT = 0x1000000;
20582058
2059 pub fn EXITSTATUS(s: u32) u8 {2059 pub fn EXITSTATUS(s: u32) u8 {
2060 return @intCast(u8, (s & 0xff00) >> 8);2060 return @as(u8, @intCast((s & 0xff00) >> 8));
2061 }2061 }
2062 pub fn TERMSIG(s: u32) u32 {2062 pub fn TERMSIG(s: u32) u32 {
2063 return s & 0x7f;2063 return s & 0x7f;
...@@ -2069,7 +2069,7 @@ pub const W = struct {...@@ -2069,7 +2069,7 @@ pub const W = struct {
2069 return TERMSIG(s) == 0;2069 return TERMSIG(s) == 0;
2070 }2070 }
2071 pub fn IFSTOPPED(s: u32) bool {2071 pub fn IFSTOPPED(s: u32) bool {
2072 return @truncate(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;2072 return @as(u16, @truncate(((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
2073 }2073 }
2074 pub fn IFSIGNALED(s: u32) bool {2074 pub fn IFSIGNALED(s: u32) bool {
2075 return (s & 0xffff) -% 1 < 0xff;2075 return (s & 0xffff) -% 1 < 0xff;
...@@ -2154,9 +2154,9 @@ pub const SIG = if (is_mips) struct {...@@ -2154,9 +2154,9 @@ pub const SIG = if (is_mips) struct {
2154 pub const SYS = 31;2154 pub const SYS = 31;
2155 pub const UNUSED = SIG.SYS;2155 pub const UNUSED = SIG.SYS;
21562156
2157 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));2157 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
2158 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);2158 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
2159 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);2159 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
2160} else if (is_sparc) struct {2160} else if (is_sparc) struct {
2161 pub const BLOCK = 1;2161 pub const BLOCK = 1;
2162 pub const UNBLOCK = 2;2162 pub const UNBLOCK = 2;
...@@ -2198,9 +2198,9 @@ pub const SIG = if (is_mips) struct {...@@ -2198,9 +2198,9 @@ pub const SIG = if (is_mips) struct {
2198 pub const PWR = LOST;2198 pub const PWR = LOST;
2199 pub const IO = SIG.POLL;2199 pub const IO = SIG.POLL;
22002200
2201 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));2201 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
2202 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);2202 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
2203 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);2203 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
2204} else struct {2204} else struct {
2205 pub const BLOCK = 0;2205 pub const BLOCK = 0;
2206 pub const UNBLOCK = 1;2206 pub const UNBLOCK = 1;
...@@ -2241,9 +2241,9 @@ pub const SIG = if (is_mips) struct {...@@ -2241,9 +2241,9 @@ pub const SIG = if (is_mips) struct {
2241 pub const SYS = 31;2241 pub const SYS = 31;
2242 pub const UNUSED = SIG.SYS;2242 pub const UNUSED = SIG.SYS;
22432243
2244 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));2244 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
2245 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);2245 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
2246 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);2246 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
2247};2247};
22482248
2249pub const kernel_rwf = u32;2249pub const kernel_rwf = u32;
...@@ -3541,7 +3541,7 @@ pub const CAP = struct {...@@ -3541,7 +3541,7 @@ pub const CAP = struct {
3541 }3541 }
35423542
3543 pub fn TO_MASK(cap: u8) u32 {3543 pub fn TO_MASK(cap: u8) u32 {
3544 return @as(u32, 1) << @intCast(u5, cap & 31);3544 return @as(u32, 1) << @as(u5, @intCast(cap & 31));
3545 }3545 }
35463546
3547 pub fn TO_INDEX(cap: u8) u8 {3547 pub fn TO_INDEX(cap: u8) u8 {
...@@ -3598,7 +3598,7 @@ pub const cpu_count_t = std.meta.Int(.unsigned, std.math.log2(CPU_SETSIZE * 8));...@@ -3598,7 +3598,7 @@ pub const cpu_count_t = std.meta.Int(.unsigned, std.math.log2(CPU_SETSIZE * 8));
35983598
3599fn cpu_mask(s: usize) cpu_count_t {3599fn cpu_mask(s: usize) cpu_count_t {
3600 var x = s & (CPU_SETSIZE * 8);3600 var x = s & (CPU_SETSIZE * 8);
3601 return @intCast(cpu_count_t, 1) << @intCast(u4, x);3601 return @as(cpu_count_t, @intCast(1)) << @as(u4, @intCast(x));
3602}3602}
36033603
3604pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {3604pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
...@@ -3999,7 +3999,7 @@ pub const io_uring_cqe = extern struct {...@@ -3999,7 +3999,7 @@ pub const io_uring_cqe = extern struct {
39993999
4000 pub fn err(self: io_uring_cqe) E {4000 pub fn err(self: io_uring_cqe) E {
4001 if (self.res > -4096 and self.res < 0) {4001 if (self.res > -4096 and self.res < 0) {
4002 return @enumFromInt(E, -self.res);4002 return @as(E, @enumFromInt(-self.res));
4003 }4003 }
4004 return .SUCCESS;4004 return .SUCCESS;
4005 }4005 }
lib/std/os/linux/bpf.zig+15-15
...@@ -643,7 +643,7 @@ pub const Insn = packed struct {...@@ -643,7 +643,7 @@ pub const Insn = packed struct {
643 .dst = @intFromEnum(dst),643 .dst = @intFromEnum(dst),
644 .src = @intFromEnum(src),644 .src = @intFromEnum(src),
645 .off = 0,645 .off = 0,
646 .imm = @intCast(i32, @truncate(u32, imm)),646 .imm = @as(i32, @intCast(@as(u32, @truncate(imm)))),
647 };647 };
648 }648 }
649649
...@@ -653,7 +653,7 @@ pub const Insn = packed struct {...@@ -653,7 +653,7 @@ pub const Insn = packed struct {
653 .dst = 0,653 .dst = 0,
654 .src = 0,654 .src = 0,
655 .off = 0,655 .off = 0,
656 .imm = @intCast(i32, @truncate(u32, imm >> 32)),656 .imm = @as(i32, @intCast(@as(u32, @truncate(imm >> 32)))),
657 };657 };
658 }658 }
659659
...@@ -666,11 +666,11 @@ pub const Insn = packed struct {...@@ -666,11 +666,11 @@ pub const Insn = packed struct {
666 }666 }
667667
668 pub fn ld_map_fd1(dst: Reg, map_fd: fd_t) Insn {668 pub fn ld_map_fd1(dst: Reg, map_fd: fd_t) Insn {
669 return ld_imm_impl1(dst, @enumFromInt(Reg, PSEUDO_MAP_FD), @intCast(u64, map_fd));669 return ld_imm_impl1(dst, @as(Reg, @enumFromInt(PSEUDO_MAP_FD)), @as(u64, @intCast(map_fd)));
670 }670 }
671671
672 pub fn ld_map_fd2(map_fd: fd_t) Insn {672 pub fn ld_map_fd2(map_fd: fd_t) Insn {
673 return ld_imm_impl2(@intCast(u64, map_fd));673 return ld_imm_impl2(@as(u64, @intCast(map_fd)));
674 }674 }
675675
676 pub fn st(comptime size: Size, dst: Reg, off: i16, imm: i32) Insn {676 pub fn st(comptime size: Size, dst: Reg, off: i16, imm: i32) Insn {
...@@ -786,17 +786,17 @@ test "opcodes" {...@@ -786,17 +786,17 @@ test "opcodes" {
786786
787 // TODO: byteswap instructions787 // TODO: byteswap instructions
788 try expect_opcode(0xd4, Insn.le(.half_word, .r1));788 try expect_opcode(0xd4, Insn.le(.half_word, .r1));
789 try expectEqual(@intCast(i32, 16), Insn.le(.half_word, .r1).imm);789 try expectEqual(@as(i32, @intCast(16)), Insn.le(.half_word, .r1).imm);
790 try expect_opcode(0xd4, Insn.le(.word, .r1));790 try expect_opcode(0xd4, Insn.le(.word, .r1));
791 try expectEqual(@intCast(i32, 32), Insn.le(.word, .r1).imm);791 try expectEqual(@as(i32, @intCast(32)), Insn.le(.word, .r1).imm);
792 try expect_opcode(0xd4, Insn.le(.double_word, .r1));792 try expect_opcode(0xd4, Insn.le(.double_word, .r1));
793 try expectEqual(@intCast(i32, 64), Insn.le(.double_word, .r1).imm);793 try expectEqual(@as(i32, @intCast(64)), Insn.le(.double_word, .r1).imm);
794 try expect_opcode(0xdc, Insn.be(.half_word, .r1));794 try expect_opcode(0xdc, Insn.be(.half_word, .r1));
795 try expectEqual(@intCast(i32, 16), Insn.be(.half_word, .r1).imm);795 try expectEqual(@as(i32, @intCast(16)), Insn.be(.half_word, .r1).imm);
796 try expect_opcode(0xdc, Insn.be(.word, .r1));796 try expect_opcode(0xdc, Insn.be(.word, .r1));
797 try expectEqual(@intCast(i32, 32), Insn.be(.word, .r1).imm);797 try expectEqual(@as(i32, @intCast(32)), Insn.be(.word, .r1).imm);
798 try expect_opcode(0xdc, Insn.be(.double_word, .r1));798 try expect_opcode(0xdc, Insn.be(.double_word, .r1));
799 try expectEqual(@intCast(i32, 64), Insn.be(.double_word, .r1).imm);799 try expectEqual(@as(i32, @intCast(64)), Insn.be(.double_word, .r1).imm);
800800
801 // memory instructions801 // memory instructions
802 try expect_opcode(0x18, Insn.ld_dw1(.r1, 0));802 try expect_opcode(0x18, Insn.ld_dw1(.r1, 0));
...@@ -804,7 +804,7 @@ test "opcodes" {...@@ -804,7 +804,7 @@ test "opcodes" {
804804
805 // loading a map fd805 // loading a map fd
806 try expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0));806 try expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0));
807 try expectEqual(@intCast(u4, PSEUDO_MAP_FD), Insn.ld_map_fd1(.r1, 0).src);807 try expectEqual(@as(u4, @intCast(PSEUDO_MAP_FD)), Insn.ld_map_fd1(.r1, 0).src);
808 try expect_opcode(0x00, Insn.ld_map_fd2(0));808 try expect_opcode(0x00, Insn.ld_map_fd2(0));
809809
810 try expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0));810 try expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0));
...@@ -1518,7 +1518,7 @@ pub fn map_create(map_type: MapType, key_size: u32, value_size: u32, max_entries...@@ -1518,7 +1518,7 @@ pub fn map_create(map_type: MapType, key_size: u32, value_size: u32, max_entries
15181518
1519 const rc = linux.bpf(.map_create, &attr, @sizeOf(MapCreateAttr));1519 const rc = linux.bpf(.map_create, &attr, @sizeOf(MapCreateAttr));
1520 switch (errno(rc)) {1520 switch (errno(rc)) {
1521 .SUCCESS => return @intCast(fd_t, rc),1521 .SUCCESS => return @as(fd_t, @intCast(rc)),
1522 .INVAL => return error.MapTypeOrAttrInvalid,1522 .INVAL => return error.MapTypeOrAttrInvalid,
1523 .NOMEM => return error.SystemResources,1523 .NOMEM => return error.SystemResources,
1524 .PERM => return error.AccessDenied,1524 .PERM => return error.AccessDenied,
...@@ -1668,20 +1668,20 @@ pub fn prog_load(...@@ -1668,20 +1668,20 @@ pub fn prog_load(
16681668
1669 attr.prog_load.prog_type = @intFromEnum(prog_type);1669 attr.prog_load.prog_type = @intFromEnum(prog_type);
1670 attr.prog_load.insns = @intFromPtr(insns.ptr);1670 attr.prog_load.insns = @intFromPtr(insns.ptr);
1671 attr.prog_load.insn_cnt = @intCast(u32, insns.len);1671 attr.prog_load.insn_cnt = @as(u32, @intCast(insns.len));
1672 attr.prog_load.license = @intFromPtr(license.ptr);1672 attr.prog_load.license = @intFromPtr(license.ptr);
1673 attr.prog_load.kern_version = kern_version;1673 attr.prog_load.kern_version = kern_version;
1674 attr.prog_load.prog_flags = flags;1674 attr.prog_load.prog_flags = flags;
16751675
1676 if (log) |l| {1676 if (log) |l| {
1677 attr.prog_load.log_buf = @intFromPtr(l.buf.ptr);1677 attr.prog_load.log_buf = @intFromPtr(l.buf.ptr);
1678 attr.prog_load.log_size = @intCast(u32, l.buf.len);1678 attr.prog_load.log_size = @as(u32, @intCast(l.buf.len));
1679 attr.prog_load.log_level = l.level;1679 attr.prog_load.log_level = l.level;
1680 }1680 }
16811681
1682 const rc = linux.bpf(.prog_load, &attr, @sizeOf(ProgLoadAttr));1682 const rc = linux.bpf(.prog_load, &attr, @sizeOf(ProgLoadAttr));
1683 return switch (errno(rc)) {1683 return switch (errno(rc)) {
1684 .SUCCESS => @intCast(fd_t, rc),1684 .SUCCESS => @as(fd_t, @intCast(rc)),
1685 .ACCES => error.UnsafeProgram,1685 .ACCES => error.UnsafeProgram,
1686 .FAULT => unreachable,1686 .FAULT => unreachable,
1687 .INVAL => error.InvalidProgram,1687 .INVAL => error.InvalidProgram,
lib/std/os/linux/bpf/helpers.zig+141-141
...@@ -11,147 +11,147 @@ const SkFullSock = @compileError("TODO missing os bits: SkFullSock");...@@ -11,147 +11,147 @@ const SkFullSock = @compileError("TODO missing os bits: SkFullSock");
11//11//
12// Note, these function signatures were created from documentation found in12// Note, these function signatures were created from documentation found in
13// '/usr/include/linux/bpf.h'13// '/usr/include/linux/bpf.h'
14pub const map_lookup_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, key: ?*const anyopaque) ?*anyopaque, 1);14pub const map_lookup_elem = @as(*const fn (map: *const kern.MapDef, key: ?*const anyopaque) ?*anyopaque, @ptrFromInt(1));
15pub const map_update_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, key: ?*const anyopaque, value: ?*const anyopaque, flags: u64) c_long, 2);15pub const map_update_elem = @as(*const fn (map: *const kern.MapDef, key: ?*const anyopaque, value: ?*const anyopaque, flags: u64) c_long, @ptrFromInt(2));
16pub const map_delete_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, key: ?*const anyopaque) c_long, 3);16pub const map_delete_elem = @as(*const fn (map: *const kern.MapDef, key: ?*const anyopaque) c_long, @ptrFromInt(3));
17pub const probe_read = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 4);17pub const probe_read = @as(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, @ptrFromInt(4));
18pub const ktime_get_ns = @ptrFromInt(*const fn () u64, 5);18pub const ktime_get_ns = @as(*const fn () u64, @ptrFromInt(5));
19pub const trace_printk = @ptrFromInt(*const fn (fmt: [*:0]const u8, fmt_size: u32, arg1: u64, arg2: u64, arg3: u64) c_long, 6);19pub const trace_printk = @as(*const fn (fmt: [*:0]const u8, fmt_size: u32, arg1: u64, arg2: u64, arg3: u64) c_long, @ptrFromInt(6));
20pub const get_prandom_u32 = @ptrFromInt(*const fn () u32, 7);20pub const get_prandom_u32 = @as(*const fn () u32, @ptrFromInt(7));
21pub const get_smp_processor_id = @ptrFromInt(*const fn () u32, 8);21pub const get_smp_processor_id = @as(*const fn () u32, @ptrFromInt(8));
22pub const skb_store_bytes = @ptrFromInt(*const fn (skb: *kern.SkBuff, offset: u32, from: ?*const anyopaque, len: u32, flags: u64) c_long, 9);22pub const skb_store_bytes = @as(*const fn (skb: *kern.SkBuff, offset: u32, from: ?*const anyopaque, len: u32, flags: u64) c_long, @ptrFromInt(9));
23pub const l3_csum_replace = @ptrFromInt(*const fn (skb: *kern.SkBuff, offset: u32, from: u64, to: u64, size: u64) c_long, 10);23pub const l3_csum_replace = @as(*const fn (skb: *kern.SkBuff, offset: u32, from: u64, to: u64, size: u64) c_long, @ptrFromInt(10));
24pub const l4_csum_replace = @ptrFromInt(*const fn (skb: *kern.SkBuff, offset: u32, from: u64, to: u64, flags: u64) c_long, 11);24pub const l4_csum_replace = @as(*const fn (skb: *kern.SkBuff, offset: u32, from: u64, to: u64, flags: u64) c_long, @ptrFromInt(11));
25pub const tail_call = @ptrFromInt(*const fn (ctx: ?*anyopaque, prog_array_map: *const kern.MapDef, index: u32) c_long, 12);25pub const tail_call = @as(*const fn (ctx: ?*anyopaque, prog_array_map: *const kern.MapDef, index: u32) c_long, @ptrFromInt(12));
26pub const clone_redirect = @ptrFromInt(*const fn (skb: *kern.SkBuff, ifindex: u32, flags: u64) c_long, 13);26pub const clone_redirect = @as(*const fn (skb: *kern.SkBuff, ifindex: u32, flags: u64) c_long, @ptrFromInt(13));
27pub const get_current_pid_tgid = @ptrFromInt(*const fn () u64, 14);27pub const get_current_pid_tgid = @as(*const fn () u64, @ptrFromInt(14));
28pub const get_current_uid_gid = @ptrFromInt(*const fn () u64, 15);28pub const get_current_uid_gid = @as(*const fn () u64, @ptrFromInt(15));
29pub const get_current_comm = @ptrFromInt(*const fn (buf: ?*anyopaque, size_of_buf: u32) c_long, 16);29pub const get_current_comm = @as(*const fn (buf: ?*anyopaque, size_of_buf: u32) c_long, @ptrFromInt(16));
30pub const get_cgroup_classid = @ptrFromInt(*const fn (skb: *kern.SkBuff) u32, 17);30pub const get_cgroup_classid = @as(*const fn (skb: *kern.SkBuff) u32, @ptrFromInt(17));
31// Note vlan_proto is big endian31// Note vlan_proto is big endian
32pub const skb_vlan_push = @ptrFromInt(*const fn (skb: *kern.SkBuff, vlan_proto: u16, vlan_tci: u16) c_long, 18);32pub const skb_vlan_push = @as(*const fn (skb: *kern.SkBuff, vlan_proto: u16, vlan_tci: u16) c_long, @ptrFromInt(18));
33pub const skb_vlan_pop = @ptrFromInt(*const fn (skb: *kern.SkBuff) c_long, 19);33pub const skb_vlan_pop = @as(*const fn (skb: *kern.SkBuff) c_long, @ptrFromInt(19));
34pub const skb_get_tunnel_key = @ptrFromInt(*const fn (skb: *kern.SkBuff, key: *kern.TunnelKey, size: u32, flags: u64) c_long, 20);34pub const skb_get_tunnel_key = @as(*const fn (skb: *kern.SkBuff, key: *kern.TunnelKey, size: u32, flags: u64) c_long, @ptrFromInt(20));
35pub const skb_set_tunnel_key = @ptrFromInt(*const fn (skb: *kern.SkBuff, key: *kern.TunnelKey, size: u32, flags: u64) c_long, 21);35pub const skb_set_tunnel_key = @as(*const fn (skb: *kern.SkBuff, key: *kern.TunnelKey, size: u32, flags: u64) c_long, @ptrFromInt(21));
36pub const perf_event_read = @ptrFromInt(*const fn (map: *const kern.MapDef, flags: u64) u64, 22);36pub const perf_event_read = @as(*const fn (map: *const kern.MapDef, flags: u64) u64, @ptrFromInt(22));
37pub const redirect = @ptrFromInt(*const fn (ifindex: u32, flags: u64) c_long, 23);37pub const redirect = @as(*const fn (ifindex: u32, flags: u64) c_long, @ptrFromInt(23));
38pub const get_route_realm = @ptrFromInt(*const fn (skb: *kern.SkBuff) u32, 24);38pub const get_route_realm = @as(*const fn (skb: *kern.SkBuff) u32, @ptrFromInt(24));
39pub const perf_event_output = @ptrFromInt(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64, data: ?*anyopaque, size: u64) c_long, 25);39pub const perf_event_output = @as(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64, data: ?*anyopaque, size: u64) c_long, @ptrFromInt(25));
40pub const skb_load_bytes = @ptrFromInt(*const fn (skb: ?*anyopaque, offset: u32, to: ?*anyopaque, len: u32) c_long, 26);40pub const skb_load_bytes = @as(*const fn (skb: ?*anyopaque, offset: u32, to: ?*anyopaque, len: u32) c_long, @ptrFromInt(26));
41pub const get_stackid = @ptrFromInt(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64) c_long, 27);41pub const get_stackid = @as(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64) c_long, @ptrFromInt(27));
42// from and to point to __be3242// from and to point to __be32
43pub const csum_diff = @ptrFromInt(*const fn (from: *u32, from_size: u32, to: *u32, to_size: u32, seed: u32) i64, 28);43pub const csum_diff = @as(*const fn (from: *u32, from_size: u32, to: *u32, to_size: u32, seed: u32) i64, @ptrFromInt(28));
44pub const skb_get_tunnel_opt = @ptrFromInt(*const fn (skb: *kern.SkBuff, opt: ?*anyopaque, size: u32) c_long, 29);44pub const skb_get_tunnel_opt = @as(*const fn (skb: *kern.SkBuff, opt: ?*anyopaque, size: u32) c_long, @ptrFromInt(29));
45pub const skb_set_tunnel_opt = @ptrFromInt(*const fn (skb: *kern.SkBuff, opt: ?*anyopaque, size: u32) c_long, 30);45pub const skb_set_tunnel_opt = @as(*const fn (skb: *kern.SkBuff, opt: ?*anyopaque, size: u32) c_long, @ptrFromInt(30));
46// proto is __be1646// proto is __be16
47pub const skb_change_proto = @ptrFromInt(*const fn (skb: *kern.SkBuff, proto: u16, flags: u64) c_long, 31);47pub const skb_change_proto = @as(*const fn (skb: *kern.SkBuff, proto: u16, flags: u64) c_long, @ptrFromInt(31));
48pub const skb_change_type = @ptrFromInt(*const fn (skb: *kern.SkBuff, skb_type: u32) c_long, 32);48pub const skb_change_type = @as(*const fn (skb: *kern.SkBuff, skb_type: u32) c_long, @ptrFromInt(32));
49pub const skb_under_cgroup = @ptrFromInt(*const fn (skb: *kern.SkBuff, map: ?*const anyopaque, index: u32) c_long, 33);49pub const skb_under_cgroup = @as(*const fn (skb: *kern.SkBuff, map: ?*const anyopaque, index: u32) c_long, @ptrFromInt(33));
50pub const get_hash_recalc = @ptrFromInt(*const fn (skb: *kern.SkBuff) u32, 34);50pub const get_hash_recalc = @as(*const fn (skb: *kern.SkBuff) u32, @ptrFromInt(34));
51pub const get_current_task = @ptrFromInt(*const fn () u64, 35);51pub const get_current_task = @as(*const fn () u64, @ptrFromInt(35));
52pub const probe_write_user = @ptrFromInt(*const fn (dst: ?*anyopaque, src: ?*const anyopaque, len: u32) c_long, 36);52pub const probe_write_user = @as(*const fn (dst: ?*anyopaque, src: ?*const anyopaque, len: u32) c_long, @ptrFromInt(36));
53pub const current_task_under_cgroup = @ptrFromInt(*const fn (map: *const kern.MapDef, index: u32) c_long, 37);53pub const current_task_under_cgroup = @as(*const fn (map: *const kern.MapDef, index: u32) c_long, @ptrFromInt(37));
54pub const skb_change_tail = @ptrFromInt(*const fn (skb: *kern.SkBuff, len: u32, flags: u64) c_long, 38);54pub const skb_change_tail = @as(*const fn (skb: *kern.SkBuff, len: u32, flags: u64) c_long, @ptrFromInt(38));
55pub const skb_pull_data = @ptrFromInt(*const fn (skb: *kern.SkBuff, len: u32) c_long, 39);55pub const skb_pull_data = @as(*const fn (skb: *kern.SkBuff, len: u32) c_long, @ptrFromInt(39));
56pub const csum_update = @ptrFromInt(*const fn (skb: *kern.SkBuff, csum: u32) i64, 40);56pub const csum_update = @as(*const fn (skb: *kern.SkBuff, csum: u32) i64, @ptrFromInt(40));
57pub const set_hash_invalid = @ptrFromInt(*const fn (skb: *kern.SkBuff) void, 41);57pub const set_hash_invalid = @as(*const fn (skb: *kern.SkBuff) void, @ptrFromInt(41));
58pub const get_numa_node_id = @ptrFromInt(*const fn () c_long, 42);58pub const get_numa_node_id = @as(*const fn () c_long, @ptrFromInt(42));
59pub const skb_change_head = @ptrFromInt(*const fn (skb: *kern.SkBuff, len: u32, flags: u64) c_long, 43);59pub const skb_change_head = @as(*const fn (skb: *kern.SkBuff, len: u32, flags: u64) c_long, @ptrFromInt(43));
60pub const xdp_adjust_head = @ptrFromInt(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, 44);60pub const xdp_adjust_head = @as(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, @ptrFromInt(44));
61pub const probe_read_str = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 45);61pub const probe_read_str = @as(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, @ptrFromInt(45));
62pub const get_socket_cookie = @ptrFromInt(*const fn (ctx: ?*anyopaque) u64, 46);62pub const get_socket_cookie = @as(*const fn (ctx: ?*anyopaque) u64, @ptrFromInt(46));
63pub const get_socket_uid = @ptrFromInt(*const fn (skb: *kern.SkBuff) u32, 47);63pub const get_socket_uid = @as(*const fn (skb: *kern.SkBuff) u32, @ptrFromInt(47));
64pub const set_hash = @ptrFromInt(*const fn (skb: *kern.SkBuff, hash: u32) c_long, 48);64pub const set_hash = @as(*const fn (skb: *kern.SkBuff, hash: u32) c_long, @ptrFromInt(48));
65pub const setsockopt = @ptrFromInt(*const fn (bpf_socket: *kern.SockOps, level: c_int, optname: c_int, optval: ?*anyopaque, optlen: c_int) c_long, 49);65pub const setsockopt = @as(*const fn (bpf_socket: *kern.SockOps, level: c_int, optname: c_int, optval: ?*anyopaque, optlen: c_int) c_long, @ptrFromInt(49));
66pub const skb_adjust_room = @ptrFromInt(*const fn (skb: *kern.SkBuff, len_diff: i32, mode: u32, flags: u64) c_long, 50);66pub const skb_adjust_room = @as(*const fn (skb: *kern.SkBuff, len_diff: i32, mode: u32, flags: u64) c_long, @ptrFromInt(50));
67pub const redirect_map = @ptrFromInt(*const fn (map: *const kern.MapDef, key: u32, flags: u64) c_long, 51);67pub const redirect_map = @as(*const fn (map: *const kern.MapDef, key: u32, flags: u64) c_long, @ptrFromInt(51));
68pub const sk_redirect_map = @ptrFromInt(*const fn (skb: *kern.SkBuff, map: *const kern.MapDef, key: u32, flags: u64) c_long, 52);68pub const sk_redirect_map = @as(*const fn (skb: *kern.SkBuff, map: *const kern.MapDef, key: u32, flags: u64) c_long, @ptrFromInt(52));
69pub const sock_map_update = @ptrFromInt(*const fn (skops: *kern.SockOps, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, 53);69pub const sock_map_update = @as(*const fn (skops: *kern.SockOps, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, @ptrFromInt(53));
70pub const xdp_adjust_meta = @ptrFromInt(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, 54);70pub const xdp_adjust_meta = @as(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, @ptrFromInt(54));
71pub const perf_event_read_value = @ptrFromInt(*const fn (map: *const kern.MapDef, flags: u64, buf: *kern.PerfEventValue, buf_size: u32) c_long, 55);71pub const perf_event_read_value = @as(*const fn (map: *const kern.MapDef, flags: u64, buf: *kern.PerfEventValue, buf_size: u32) c_long, @ptrFromInt(55));
72pub const perf_prog_read_value = @ptrFromInt(*const fn (ctx: *kern.PerfEventData, buf: *kern.PerfEventValue, buf_size: u32) c_long, 56);72pub const perf_prog_read_value = @as(*const fn (ctx: *kern.PerfEventData, buf: *kern.PerfEventValue, buf_size: u32) c_long, @ptrFromInt(56));
73pub const getsockopt = @ptrFromInt(*const fn (bpf_socket: ?*anyopaque, level: c_int, optname: c_int, optval: ?*anyopaque, optlen: c_int) c_long, 57);73pub const getsockopt = @as(*const fn (bpf_socket: ?*anyopaque, level: c_int, optname: c_int, optval: ?*anyopaque, optlen: c_int) c_long, @ptrFromInt(57));
74pub const override_return = @ptrFromInt(*const fn (regs: *PtRegs, rc: u64) c_long, 58);74pub const override_return = @as(*const fn (regs: *PtRegs, rc: u64) c_long, @ptrFromInt(58));
75pub const sock_ops_cb_flags_set = @ptrFromInt(*const fn (bpf_sock: *kern.SockOps, argval: c_int) c_long, 59);75pub const sock_ops_cb_flags_set = @as(*const fn (bpf_sock: *kern.SockOps, argval: c_int) c_long, @ptrFromInt(59));
76pub const msg_redirect_map = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, map: *const kern.MapDef, key: u32, flags: u64) c_long, 60);76pub const msg_redirect_map = @as(*const fn (msg: *kern.SkMsgMd, map: *const kern.MapDef, key: u32, flags: u64) c_long, @ptrFromInt(60));
77pub const msg_apply_bytes = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, bytes: u32) c_long, 61);77pub const msg_apply_bytes = @as(*const fn (msg: *kern.SkMsgMd, bytes: u32) c_long, @ptrFromInt(61));
78pub const msg_cork_bytes = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, bytes: u32) c_long, 62);78pub const msg_cork_bytes = @as(*const fn (msg: *kern.SkMsgMd, bytes: u32) c_long, @ptrFromInt(62));
79pub const msg_pull_data = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, start: u32, end: u32, flags: u64) c_long, 63);79pub const msg_pull_data = @as(*const fn (msg: *kern.SkMsgMd, start: u32, end: u32, flags: u64) c_long, @ptrFromInt(63));
80pub const bind = @ptrFromInt(*const fn (ctx: *kern.BpfSockAddr, addr: *kern.SockAddr, addr_len: c_int) c_long, 64);80pub const bind = @as(*const fn (ctx: *kern.BpfSockAddr, addr: *kern.SockAddr, addr_len: c_int) c_long, @ptrFromInt(64));
81pub const xdp_adjust_tail = @ptrFromInt(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, 65);81pub const xdp_adjust_tail = @as(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, @ptrFromInt(65));
82pub const skb_get_xfrm_state = @ptrFromInt(*const fn (skb: *kern.SkBuff, index: u32, xfrm_state: *kern.XfrmState, size: u32, flags: u64) c_long, 66);82pub const skb_get_xfrm_state = @as(*const fn (skb: *kern.SkBuff, index: u32, xfrm_state: *kern.XfrmState, size: u32, flags: u64) c_long, @ptrFromInt(66));
83pub const get_stack = @ptrFromInt(*const fn (ctx: ?*anyopaque, buf: ?*anyopaque, size: u32, flags: u64) c_long, 67);83pub const get_stack = @as(*const fn (ctx: ?*anyopaque, buf: ?*anyopaque, size: u32, flags: u64) c_long, @ptrFromInt(67));
84pub const skb_load_bytes_relative = @ptrFromInt(*const fn (skb: ?*const anyopaque, offset: u32, to: ?*anyopaque, len: u32, start_header: u32) c_long, 68);84pub const skb_load_bytes_relative = @as(*const fn (skb: ?*const anyopaque, offset: u32, to: ?*anyopaque, len: u32, start_header: u32) c_long, @ptrFromInt(68));
85pub const fib_lookup = @ptrFromInt(*const fn (ctx: ?*anyopaque, params: *kern.FibLookup, plen: c_int, flags: u32) c_long, 69);85pub const fib_lookup = @as(*const fn (ctx: ?*anyopaque, params: *kern.FibLookup, plen: c_int, flags: u32) c_long, @ptrFromInt(69));
86pub const sock_hash_update = @ptrFromInt(*const fn (skops: *kern.SockOps, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, 70);86pub const sock_hash_update = @as(*const fn (skops: *kern.SockOps, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, @ptrFromInt(70));
87pub const msg_redirect_hash = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, 71);87pub const msg_redirect_hash = @as(*const fn (msg: *kern.SkMsgMd, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, @ptrFromInt(71));
88pub const sk_redirect_hash = @ptrFromInt(*const fn (skb: *kern.SkBuff, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, 72);88pub const sk_redirect_hash = @as(*const fn (skb: *kern.SkBuff, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, @ptrFromInt(72));
89pub const lwt_push_encap = @ptrFromInt(*const fn (skb: *kern.SkBuff, typ: u32, hdr: ?*anyopaque, len: u32) c_long, 73);89pub const lwt_push_encap = @as(*const fn (skb: *kern.SkBuff, typ: u32, hdr: ?*anyopaque, len: u32) c_long, @ptrFromInt(73));
90pub const lwt_seg6_store_bytes = @ptrFromInt(*const fn (skb: *kern.SkBuff, offset: u32, from: ?*const anyopaque, len: u32) c_long, 74);90pub const lwt_seg6_store_bytes = @as(*const fn (skb: *kern.SkBuff, offset: u32, from: ?*const anyopaque, len: u32) c_long, @ptrFromInt(74));
91pub const lwt_seg6_adjust_srh = @ptrFromInt(*const fn (skb: *kern.SkBuff, offset: u32, delta: i32) c_long, 75);91pub const lwt_seg6_adjust_srh = @as(*const fn (skb: *kern.SkBuff, offset: u32, delta: i32) c_long, @ptrFromInt(75));
92pub const lwt_seg6_action = @ptrFromInt(*const fn (skb: *kern.SkBuff, action: u32, param: ?*anyopaque, param_len: u32) c_long, 76);92pub const lwt_seg6_action = @as(*const fn (skb: *kern.SkBuff, action: u32, param: ?*anyopaque, param_len: u32) c_long, @ptrFromInt(76));
93pub const rc_repeat = @ptrFromInt(*const fn (ctx: ?*anyopaque) c_long, 77);93pub const rc_repeat = @as(*const fn (ctx: ?*anyopaque) c_long, @ptrFromInt(77));
94pub const rc_keydown = @ptrFromInt(*const fn (ctx: ?*anyopaque, protocol: u32, scancode: u64, toggle: u32) c_long, 78);94pub const rc_keydown = @as(*const fn (ctx: ?*anyopaque, protocol: u32, scancode: u64, toggle: u32) c_long, @ptrFromInt(78));
95pub const skb_cgroup_id = @ptrFromInt(*const fn (skb: *kern.SkBuff) u64, 79);95pub const skb_cgroup_id = @as(*const fn (skb: *kern.SkBuff) u64, @ptrFromInt(79));
96pub const get_current_cgroup_id = @ptrFromInt(*const fn () u64, 80);96pub const get_current_cgroup_id = @as(*const fn () u64, @ptrFromInt(80));
97pub const get_local_storage = @ptrFromInt(*const fn (map: ?*anyopaque, flags: u64) ?*anyopaque, 81);97pub const get_local_storage = @as(*const fn (map: ?*anyopaque, flags: u64) ?*anyopaque, @ptrFromInt(81));
98pub const sk_select_reuseport = @ptrFromInt(*const fn (reuse: *kern.SkReusePortMd, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, 82);98pub const sk_select_reuseport = @as(*const fn (reuse: *kern.SkReusePortMd, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, @ptrFromInt(82));
99pub const skb_ancestor_cgroup_id = @ptrFromInt(*const fn (skb: *kern.SkBuff, ancestor_level: c_int) u64, 83);99pub const skb_ancestor_cgroup_id = @as(*const fn (skb: *kern.SkBuff, ancestor_level: c_int) u64, @ptrFromInt(83));
100pub const sk_lookup_tcp = @ptrFromInt(*const fn (ctx: ?*anyopaque, tuple: *kern.SockTuple, tuple_size: u32, netns: u64, flags: u64) ?*kern.Sock, 84);100pub const sk_lookup_tcp = @as(*const fn (ctx: ?*anyopaque, tuple: *kern.SockTuple, tuple_size: u32, netns: u64, flags: u64) ?*kern.Sock, @ptrFromInt(84));
101pub const sk_lookup_udp = @ptrFromInt(*const fn (ctx: ?*anyopaque, tuple: *kern.SockTuple, tuple_size: u32, netns: u64, flags: u64) ?*kern.Sock, 85);101pub const sk_lookup_udp = @as(*const fn (ctx: ?*anyopaque, tuple: *kern.SockTuple, tuple_size: u32, netns: u64, flags: u64) ?*kern.Sock, @ptrFromInt(85));
102pub const sk_release = @ptrFromInt(*const fn (sock: *kern.Sock) c_long, 86);102pub const sk_release = @as(*const fn (sock: *kern.Sock) c_long, @ptrFromInt(86));
103pub const map_push_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, value: ?*const anyopaque, flags: u64) c_long, 87);103pub const map_push_elem = @as(*const fn (map: *const kern.MapDef, value: ?*const anyopaque, flags: u64) c_long, @ptrFromInt(87));
104pub const map_pop_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, value: ?*anyopaque) c_long, 88);104pub const map_pop_elem = @as(*const fn (map: *const kern.MapDef, value: ?*anyopaque) c_long, @ptrFromInt(88));
105pub const map_peek_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, value: ?*anyopaque) c_long, 89);105pub const map_peek_elem = @as(*const fn (map: *const kern.MapDef, value: ?*anyopaque) c_long, @ptrFromInt(89));
106pub const msg_push_data = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, start: u32, len: u32, flags: u64) c_long, 90);106pub const msg_push_data = @as(*const fn (msg: *kern.SkMsgMd, start: u32, len: u32, flags: u64) c_long, @ptrFromInt(90));
107pub const msg_pop_data = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, start: u32, len: u32, flags: u64) c_long, 91);107pub const msg_pop_data = @as(*const fn (msg: *kern.SkMsgMd, start: u32, len: u32, flags: u64) c_long, @ptrFromInt(91));
108pub const rc_pointer_rel = @ptrFromInt(*const fn (ctx: ?*anyopaque, rel_x: i32, rel_y: i32) c_long, 92);108pub const rc_pointer_rel = @as(*const fn (ctx: ?*anyopaque, rel_x: i32, rel_y: i32) c_long, @ptrFromInt(92));
109pub const spin_lock = @ptrFromInt(*const fn (lock: *kern.SpinLock) c_long, 93);109pub const spin_lock = @as(*const fn (lock: *kern.SpinLock) c_long, @ptrFromInt(93));
110pub const spin_unlock = @ptrFromInt(*const fn (lock: *kern.SpinLock) c_long, 94);110pub const spin_unlock = @as(*const fn (lock: *kern.SpinLock) c_long, @ptrFromInt(94));
111pub const sk_fullsock = @ptrFromInt(*const fn (sk: *kern.Sock) ?*SkFullSock, 95);111pub const sk_fullsock = @as(*const fn (sk: *kern.Sock) ?*SkFullSock, @ptrFromInt(95));
112pub const tcp_sock = @ptrFromInt(*const fn (sk: *kern.Sock) ?*kern.TcpSock, 96);112pub const tcp_sock = @as(*const fn (sk: *kern.Sock) ?*kern.TcpSock, @ptrFromInt(96));
113pub const skb_ecn_set_ce = @ptrFromInt(*const fn (skb: *kern.SkBuff) c_long, 97);113pub const skb_ecn_set_ce = @as(*const fn (skb: *kern.SkBuff) c_long, @ptrFromInt(97));
114pub const get_listener_sock = @ptrFromInt(*const fn (sk: *kern.Sock) ?*kern.Sock, 98);114pub const get_listener_sock = @as(*const fn (sk: *kern.Sock) ?*kern.Sock, @ptrFromInt(98));
115pub const skc_lookup_tcp = @ptrFromInt(*const fn (ctx: ?*anyopaque, tuple: *kern.SockTuple, tuple_size: u32, netns: u64, flags: u64) ?*kern.Sock, 99);115pub const skc_lookup_tcp = @as(*const fn (ctx: ?*anyopaque, tuple: *kern.SockTuple, tuple_size: u32, netns: u64, flags: u64) ?*kern.Sock, @ptrFromInt(99));
116pub const tcp_check_syncookie = @ptrFromInt(*const fn (sk: *kern.Sock, iph: ?*anyopaque, iph_len: u32, th: *TcpHdr, th_len: u32) c_long, 100);116pub const tcp_check_syncookie = @as(*const fn (sk: *kern.Sock, iph: ?*anyopaque, iph_len: u32, th: *TcpHdr, th_len: u32) c_long, @ptrFromInt(100));
117pub const sysctl_get_name = @ptrFromInt(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong, flags: u64) c_long, 101);117pub const sysctl_get_name = @as(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong, flags: u64) c_long, @ptrFromInt(101));
118pub const sysctl_get_current_value = @ptrFromInt(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong) c_long, 102);118pub const sysctl_get_current_value = @as(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong) c_long, @ptrFromInt(102));
119pub const sysctl_get_new_value = @ptrFromInt(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong) c_long, 103);119pub const sysctl_get_new_value = @as(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong) c_long, @ptrFromInt(103));
120pub const sysctl_set_new_value = @ptrFromInt(*const fn (ctx: *kern.SysCtl, buf: ?*const u8, buf_len: c_ulong) c_long, 104);120pub const sysctl_set_new_value = @as(*const fn (ctx: *kern.SysCtl, buf: ?*const u8, buf_len: c_ulong) c_long, @ptrFromInt(104));
121pub const strtol = @ptrFromInt(*const fn (buf: *const u8, buf_len: c_ulong, flags: u64, res: *c_long) c_long, 105);121pub const strtol = @as(*const fn (buf: *const u8, buf_len: c_ulong, flags: u64, res: *c_long) c_long, @ptrFromInt(105));
122pub const strtoul = @ptrFromInt(*const fn (buf: *const u8, buf_len: c_ulong, flags: u64, res: *c_ulong) c_long, 106);122pub const strtoul = @as(*const fn (buf: *const u8, buf_len: c_ulong, flags: u64, res: *c_ulong) c_long, @ptrFromInt(106));
123pub const sk_storage_get = @ptrFromInt(*const fn (map: *const kern.MapDef, sk: *kern.Sock, value: ?*anyopaque, flags: u64) ?*anyopaque, 107);123pub const sk_storage_get = @as(*const fn (map: *const kern.MapDef, sk: *kern.Sock, value: ?*anyopaque, flags: u64) ?*anyopaque, @ptrFromInt(107));
124pub const sk_storage_delete = @ptrFromInt(*const fn (map: *const kern.MapDef, sk: *kern.Sock) c_long, 108);124pub const sk_storage_delete = @as(*const fn (map: *const kern.MapDef, sk: *kern.Sock) c_long, @ptrFromInt(108));
125pub const send_signal = @ptrFromInt(*const fn (sig: u32) c_long, 109);125pub const send_signal = @as(*const fn (sig: u32) c_long, @ptrFromInt(109));
126pub const tcp_gen_syncookie = @ptrFromInt(*const fn (sk: *kern.Sock, iph: ?*anyopaque, iph_len: u32, th: *TcpHdr, th_len: u32) i64, 110);126pub const tcp_gen_syncookie = @as(*const fn (sk: *kern.Sock, iph: ?*anyopaque, iph_len: u32, th: *TcpHdr, th_len: u32) i64, @ptrFromInt(110));
127pub const skb_output = @ptrFromInt(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64, data: ?*anyopaque, size: u64) c_long, 111);127pub const skb_output = @as(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64, data: ?*anyopaque, size: u64) c_long, @ptrFromInt(111));
128pub const probe_read_user = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 112);128pub const probe_read_user = @as(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, @ptrFromInt(112));
129pub const probe_read_kernel = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 113);129pub const probe_read_kernel = @as(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, @ptrFromInt(113));
130pub const probe_read_user_str = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 114);130pub const probe_read_user_str = @as(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, @ptrFromInt(114));
131pub const probe_read_kernel_str = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 115);131pub const probe_read_kernel_str = @as(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, @ptrFromInt(115));
132pub const tcp_send_ack = @ptrFromInt(*const fn (tp: ?*anyopaque, rcv_nxt: u32) c_long, 116);132pub const tcp_send_ack = @as(*const fn (tp: ?*anyopaque, rcv_nxt: u32) c_long, @ptrFromInt(116));
133pub const send_signal_thread = @ptrFromInt(*const fn (sig: u32) c_long, 117);133pub const send_signal_thread = @as(*const fn (sig: u32) c_long, @ptrFromInt(117));
134pub const jiffies64 = @ptrFromInt(*const fn () u64, 118);134pub const jiffies64 = @as(*const fn () u64, @ptrFromInt(118));
135pub const read_branch_records = @ptrFromInt(*const fn (ctx: *kern.PerfEventData, buf: ?*anyopaque, size: u32, flags: u64) c_long, 119);135pub const read_branch_records = @as(*const fn (ctx: *kern.PerfEventData, buf: ?*anyopaque, size: u32, flags: u64) c_long, @ptrFromInt(119));
136pub const get_ns_current_pid_tgid = @ptrFromInt(*const fn (dev: u64, ino: u64, nsdata: *kern.PidNsInfo, size: u32) c_long, 120);136pub const get_ns_current_pid_tgid = @as(*const fn (dev: u64, ino: u64, nsdata: *kern.PidNsInfo, size: u32) c_long, @ptrFromInt(120));
137pub const xdp_output = @ptrFromInt(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64, data: ?*anyopaque, size: u64) c_long, 121);137pub const xdp_output = @as(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64, data: ?*anyopaque, size: u64) c_long, @ptrFromInt(121));
138pub const get_netns_cookie = @ptrFromInt(*const fn (ctx: ?*anyopaque) u64, 122);138pub const get_netns_cookie = @as(*const fn (ctx: ?*anyopaque) u64, @ptrFromInt(122));
139pub const get_current_ancestor_cgroup_id = @ptrFromInt(*const fn (ancestor_level: c_int) u64, 123);139pub const get_current_ancestor_cgroup_id = @as(*const fn (ancestor_level: c_int) u64, @ptrFromInt(123));
140pub const sk_assign = @ptrFromInt(*const fn (skb: *kern.SkBuff, sk: *kern.Sock, flags: u64) c_long, 124);140pub const sk_assign = @as(*const fn (skb: *kern.SkBuff, sk: *kern.Sock, flags: u64) c_long, @ptrFromInt(124));
141pub const ktime_get_boot_ns = @ptrFromInt(*const fn () u64, 125);141pub const ktime_get_boot_ns = @as(*const fn () u64, @ptrFromInt(125));
142pub const seq_printf = @ptrFromInt(*const fn (m: *kern.SeqFile, fmt: ?*const u8, fmt_size: u32, data: ?*const anyopaque, data_len: u32) c_long, 126);142pub const seq_printf = @as(*const fn (m: *kern.SeqFile, fmt: ?*const u8, fmt_size: u32, data: ?*const anyopaque, data_len: u32) c_long, @ptrFromInt(126));
143pub const seq_write = @ptrFromInt(*const fn (m: *kern.SeqFile, data: ?*const u8, len: u32) c_long, 127);143pub const seq_write = @as(*const fn (m: *kern.SeqFile, data: ?*const u8, len: u32) c_long, @ptrFromInt(127));
144pub const sk_cgroup_id = @ptrFromInt(*const fn (sk: *kern.BpfSock) u64, 128);144pub const sk_cgroup_id = @as(*const fn (sk: *kern.BpfSock) u64, @ptrFromInt(128));
145pub const sk_ancestor_cgroup_id = @ptrFromInt(*const fn (sk: *kern.BpfSock, ancestor_level: c_long) u64, 129);145pub const sk_ancestor_cgroup_id = @as(*const fn (sk: *kern.BpfSock, ancestor_level: c_long) u64, @ptrFromInt(129));
146pub const ringbuf_output = @ptrFromInt(*const fn (ringbuf: ?*anyopaque, data: ?*anyopaque, size: u64, flags: u64) c_long, 130);146pub const ringbuf_output = @as(*const fn (ringbuf: ?*anyopaque, data: ?*anyopaque, size: u64, flags: u64) c_long, @ptrFromInt(130));
147pub const ringbuf_reserve = @ptrFromInt(*const fn (ringbuf: ?*anyopaque, size: u64, flags: u64) ?*anyopaque, 131);147pub const ringbuf_reserve = @as(*const fn (ringbuf: ?*anyopaque, size: u64, flags: u64) ?*anyopaque, @ptrFromInt(131));
148pub const ringbuf_submit = @ptrFromInt(*const fn (data: ?*anyopaque, flags: u64) void, 132);148pub const ringbuf_submit = @as(*const fn (data: ?*anyopaque, flags: u64) void, @ptrFromInt(132));
149pub const ringbuf_discard = @ptrFromInt(*const fn (data: ?*anyopaque, flags: u64) void, 133);149pub const ringbuf_discard = @as(*const fn (data: ?*anyopaque, flags: u64) void, @ptrFromInt(133));
150pub const ringbuf_query = @ptrFromInt(*const fn (ringbuf: ?*anyopaque, flags: u64) u64, 134);150pub const ringbuf_query = @as(*const fn (ringbuf: ?*anyopaque, flags: u64) u64, @ptrFromInt(134));
151pub const csum_level = @ptrFromInt(*const fn (skb: *kern.SkBuff, level: u64) c_long, 135);151pub const csum_level = @as(*const fn (skb: *kern.SkBuff, level: u64) c_long, @ptrFromInt(135));
152pub const skc_to_tcp6_sock = @ptrFromInt(*const fn (sk: ?*anyopaque) ?*kern.Tcp6Sock, 136);152pub const skc_to_tcp6_sock = @as(*const fn (sk: ?*anyopaque) ?*kern.Tcp6Sock, @ptrFromInt(136));
153pub const skc_to_tcp_sock = @ptrFromInt(*const fn (sk: ?*anyopaque) ?*kern.TcpSock, 137);153pub const skc_to_tcp_sock = @as(*const fn (sk: ?*anyopaque) ?*kern.TcpSock, @ptrFromInt(137));
154pub const skc_to_tcp_timewait_sock = @ptrFromInt(*const fn (sk: ?*anyopaque) ?*kern.TcpTimewaitSock, 138);154pub const skc_to_tcp_timewait_sock = @as(*const fn (sk: ?*anyopaque) ?*kern.TcpTimewaitSock, @ptrFromInt(138));
155pub const skc_to_tcp_request_sock = @ptrFromInt(*const fn (sk: ?*anyopaque) ?*kern.TcpRequestSock, 139);155pub const skc_to_tcp_request_sock = @as(*const fn (sk: ?*anyopaque) ?*kern.TcpRequestSock, @ptrFromInt(139));
156pub const skc_to_udp6_sock = @ptrFromInt(*const fn (sk: ?*anyopaque) ?*kern.Udp6Sock, 140);156pub const skc_to_udp6_sock = @as(*const fn (sk: ?*anyopaque) ?*kern.Udp6Sock, @ptrFromInt(140));
157pub const get_task_stack = @ptrFromInt(*const fn (task: ?*anyopaque, buf: ?*anyopaque, size: u32, flags: u64) c_long, 141);157pub const get_task_stack = @as(*const fn (task: ?*anyopaque, buf: ?*anyopaque, size: u32, flags: u64) c_long, @ptrFromInt(141));
lib/std/os/linux/io_uring.zig+47-54
...@@ -60,7 +60,7 @@ pub const IO_Uring = struct {...@@ -60,7 +60,7 @@ pub const IO_Uring = struct {
60 .NOSYS => return error.SystemOutdated,60 .NOSYS => return error.SystemOutdated,
61 else => |errno| return os.unexpectedErrno(errno),61 else => |errno| return os.unexpectedErrno(errno),
62 }62 }
63 const fd = @intCast(os.fd_t, res);63 const fd = @as(os.fd_t, @intCast(res));
64 assert(fd >= 0);64 assert(fd >= 0);
65 errdefer os.close(fd);65 errdefer os.close(fd);
6666
...@@ -198,7 +198,7 @@ pub const IO_Uring = struct {...@@ -198,7 +198,7 @@ pub const IO_Uring = struct {
198 .INTR => return error.SignalInterrupt,198 .INTR => return error.SignalInterrupt,
199 else => |errno| return os.unexpectedErrno(errno),199 else => |errno| return os.unexpectedErrno(errno),
200 }200 }
201 return @intCast(u32, res);201 return @as(u32, @intCast(res));
202 }202 }
203203
204 /// Sync internal state with kernel ring state on the SQ side.204 /// Sync internal state with kernel ring state on the SQ side.
...@@ -937,8 +937,8 @@ pub const IO_Uring = struct {...@@ -937,8 +937,8 @@ pub const IO_Uring = struct {
937 const res = linux.io_uring_register(937 const res = linux.io_uring_register(
938 self.fd,938 self.fd,
939 .REGISTER_FILES,939 .REGISTER_FILES,
940 @ptrCast(*const anyopaque, fds.ptr),940 @as(*const anyopaque, @ptrCast(fds.ptr)),
941 @intCast(u32, fds.len),941 @as(u32, @intCast(fds.len)),
942 );942 );
943 try handle_registration_result(res);943 try handle_registration_result(res);
944 }944 }
...@@ -968,8 +968,8 @@ pub const IO_Uring = struct {...@@ -968,8 +968,8 @@ pub const IO_Uring = struct {
968 const res = linux.io_uring_register(968 const res = linux.io_uring_register(
969 self.fd,969 self.fd,
970 .REGISTER_FILES_UPDATE,970 .REGISTER_FILES_UPDATE,
971 @ptrCast(*const anyopaque, &update),971 @as(*const anyopaque, @ptrCast(&update)),
972 @intCast(u32, fds.len),972 @as(u32, @intCast(fds.len)),
973 );973 );
974 try handle_registration_result(res);974 try handle_registration_result(res);
975 }975 }
...@@ -982,7 +982,7 @@ pub const IO_Uring = struct {...@@ -982,7 +982,7 @@ pub const IO_Uring = struct {
982 const res = linux.io_uring_register(982 const res = linux.io_uring_register(
983 self.fd,983 self.fd,
984 .REGISTER_EVENTFD,984 .REGISTER_EVENTFD,
985 @ptrCast(*const anyopaque, &fd),985 @as(*const anyopaque, @ptrCast(&fd)),
986 1,986 1,
987 );987 );
988 try handle_registration_result(res);988 try handle_registration_result(res);
...@@ -997,7 +997,7 @@ pub const IO_Uring = struct {...@@ -997,7 +997,7 @@ pub const IO_Uring = struct {
997 const res = linux.io_uring_register(997 const res = linux.io_uring_register(
998 self.fd,998 self.fd,
999 .REGISTER_EVENTFD_ASYNC,999 .REGISTER_EVENTFD_ASYNC,
1000 @ptrCast(*const anyopaque, &fd),1000 @as(*const anyopaque, @ptrCast(&fd)),
1001 1,1001 1,
1002 );1002 );
1003 try handle_registration_result(res);1003 try handle_registration_result(res);
...@@ -1022,7 +1022,7 @@ pub const IO_Uring = struct {...@@ -1022,7 +1022,7 @@ pub const IO_Uring = struct {
1022 self.fd,1022 self.fd,
1023 .REGISTER_BUFFERS,1023 .REGISTER_BUFFERS,
1024 buffers.ptr,1024 buffers.ptr,
1025 @intCast(u32, buffers.len),1025 @as(u32, @intCast(buffers.len)),
1026 );1026 );
1027 try handle_registration_result(res);1027 try handle_registration_result(res);
1028 }1028 }
...@@ -1122,20 +1122,17 @@ pub const SubmissionQueue = struct {...@@ -1122,20 +1122,17 @@ pub const SubmissionQueue = struct {
1122 errdefer os.munmap(mmap_sqes);1122 errdefer os.munmap(mmap_sqes);
1123 assert(mmap_sqes.len == size_sqes);1123 assert(mmap_sqes.len == size_sqes);
11241124
1125 const array = @ptrCast([*]u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.array]));1125 const array: [*]u32 = @ptrCast(@alignCast(&mmap[p.sq_off.array]));
1126 const sqes = @ptrCast([*]linux.io_uring_sqe, @alignCast(@alignOf(linux.io_uring_sqe), &mmap_sqes[0]));1126 const sqes: [*]linux.io_uring_sqe = @ptrCast(@alignCast(&mmap_sqes[0]));
1127 // We expect the kernel copies p.sq_entries to the u32 pointed to by p.sq_off.ring_entries,1127 // We expect the kernel copies p.sq_entries to the u32 pointed to by p.sq_off.ring_entries,
1128 // see https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L7843-L7844.1128 // see https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L7843-L7844.
1129 assert(1129 assert(p.sq_entries == @as(*u32, @ptrCast(@alignCast(&mmap[p.sq_off.ring_entries]))).*);
1130 p.sq_entries ==
1131 @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.ring_entries])).*,
1132 );
1133 return SubmissionQueue{1130 return SubmissionQueue{
1134 .head = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.head])),1131 .head = @ptrCast(@alignCast(&mmap[p.sq_off.head])),
1135 .tail = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.tail])),1132 .tail = @ptrCast(@alignCast(&mmap[p.sq_off.tail])),
1136 .mask = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.ring_mask])).*,1133 .mask = @as(*u32, @ptrCast(@alignCast(&mmap[p.sq_off.ring_mask]))).*,
1137 .flags = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.flags])),1134 .flags = @ptrCast(@alignCast(&mmap[p.sq_off.flags])),
1138 .dropped = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.dropped])),1135 .dropped = @ptrCast(@alignCast(&mmap[p.sq_off.dropped])),
1139 .array = array[0..p.sq_entries],1136 .array = array[0..p.sq_entries],
1140 .sqes = sqes[0..p.sq_entries],1137 .sqes = sqes[0..p.sq_entries],
1141 .mmap = mmap,1138 .mmap = mmap,
...@@ -1160,17 +1157,13 @@ pub const CompletionQueue = struct {...@@ -1160,17 +1157,13 @@ pub const CompletionQueue = struct {
1160 assert(fd >= 0);1157 assert(fd >= 0);
1161 assert((p.features & linux.IORING_FEAT_SINGLE_MMAP) != 0);1158 assert((p.features & linux.IORING_FEAT_SINGLE_MMAP) != 0);
1162 const mmap = sq.mmap;1159 const mmap = sq.mmap;
1163 const cqes = @ptrCast(1160 const cqes: [*]linux.io_uring_cqe = @ptrCast(@alignCast(&mmap[p.cq_off.cqes]));
1164 [*]linux.io_uring_cqe,1161 assert(p.cq_entries == @as(*u32, @ptrCast(@alignCast(&mmap[p.cq_off.ring_entries]))).*);
1165 @alignCast(@alignOf(linux.io_uring_cqe), &mmap[p.cq_off.cqes]),
1166 );
1167 assert(p.cq_entries ==
1168 @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.ring_entries])).*);
1169 return CompletionQueue{1162 return CompletionQueue{
1170 .head = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.head])),1163 .head = @ptrCast(@alignCast(&mmap[p.cq_off.head])),
1171 .tail = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.tail])),1164 .tail = @ptrCast(@alignCast(&mmap[p.cq_off.tail])),
1172 .mask = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.ring_mask])).*,1165 .mask = @as(*u32, @ptrCast(@alignCast(&mmap[p.cq_off.ring_mask]))).*,
1173 .overflow = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.overflow])),1166 .overflow = @ptrCast(@alignCast(&mmap[p.cq_off.overflow])),
1174 .cqes = cqes[0..p.cq_entries],1167 .cqes = cqes[0..p.cq_entries],
1175 };1168 };
1176 }1169 }
...@@ -1233,7 +1226,7 @@ pub fn io_uring_prep_rw(...@@ -1233,7 +1226,7 @@ pub fn io_uring_prep_rw(
1233 .fd = fd,1226 .fd = fd,
1234 .off = offset,1227 .off = offset,
1235 .addr = addr,1228 .addr = addr,
1236 .len = @intCast(u32, len),1229 .len = @as(u32, @intCast(len)),
1237 .rw_flags = 0,1230 .rw_flags = 0,
1238 .user_data = 0,1231 .user_data = 0,
1239 .buf_index = 0,1232 .buf_index = 0,
...@@ -1319,7 +1312,7 @@ pub fn io_uring_prep_epoll_ctl(...@@ -1319,7 +1312,7 @@ pub fn io_uring_prep_epoll_ctl(
1319 op: u32,1312 op: u32,
1320 ev: ?*linux.epoll_event,1313 ev: ?*linux.epoll_event,
1321) void {1314) void {
1322 io_uring_prep_rw(.EPOLL_CTL, sqe, epfd, @intFromPtr(ev), op, @intCast(u64, fd));1315 io_uring_prep_rw(.EPOLL_CTL, sqe, epfd, @intFromPtr(ev), op, @as(u64, @intCast(fd)));
1323}1316}
13241317
1325pub fn io_uring_prep_recv(sqe: *linux.io_uring_sqe, fd: os.fd_t, buffer: []u8, flags: u32) void {1318pub fn io_uring_prep_recv(sqe: *linux.io_uring_sqe, fd: os.fd_t, buffer: []u8, flags: u32) void {
...@@ -1459,7 +1452,7 @@ pub fn io_uring_prep_fallocate(...@@ -1459,7 +1452,7 @@ pub fn io_uring_prep_fallocate(
1459 .fd = fd,1452 .fd = fd,
1460 .off = offset,1453 .off = offset,
1461 .addr = len,1454 .addr = len,
1462 .len = @intCast(u32, mode),1455 .len = @as(u32, @intCast(mode)),
1463 .rw_flags = 0,1456 .rw_flags = 0,
1464 .user_data = 0,1457 .user_data = 0,
1465 .buf_index = 0,1458 .buf_index = 0,
...@@ -1514,7 +1507,7 @@ pub fn io_uring_prep_renameat(...@@ -1514,7 +1507,7 @@ pub fn io_uring_prep_renameat(
1514 0,1507 0,
1515 @intFromPtr(new_path),1508 @intFromPtr(new_path),
1516 );1509 );
1517 sqe.len = @bitCast(u32, new_dir_fd);1510 sqe.len = @as(u32, @bitCast(new_dir_fd));
1518 sqe.rw_flags = flags;1511 sqe.rw_flags = flags;
1519}1512}
15201513
...@@ -1569,7 +1562,7 @@ pub fn io_uring_prep_linkat(...@@ -1569,7 +1562,7 @@ pub fn io_uring_prep_linkat(
1569 0,1562 0,
1570 @intFromPtr(new_path),1563 @intFromPtr(new_path),
1571 );1564 );
1572 sqe.len = @bitCast(u32, new_dir_fd);1565 sqe.len = @as(u32, @bitCast(new_dir_fd));
1573 sqe.rw_flags = flags;1566 sqe.rw_flags = flags;
1574}1567}
15751568
...@@ -1582,8 +1575,8 @@ pub fn io_uring_prep_provide_buffers(...@@ -1582,8 +1575,8 @@ pub fn io_uring_prep_provide_buffers(
1582 buffer_id: usize,1575 buffer_id: usize,
1583) void {1576) void {
1584 const ptr = @intFromPtr(buffers);1577 const ptr = @intFromPtr(buffers);
1585 io_uring_prep_rw(.PROVIDE_BUFFERS, sqe, @intCast(i32, num), ptr, buffer_len, buffer_id);1578 io_uring_prep_rw(.PROVIDE_BUFFERS, sqe, @as(i32, @intCast(num)), ptr, buffer_len, buffer_id);
1586 sqe.buf_index = @intCast(u16, group_id);1579 sqe.buf_index = @as(u16, @intCast(group_id));
1587}1580}
15881581
1589pub fn io_uring_prep_remove_buffers(1582pub fn io_uring_prep_remove_buffers(
...@@ -1591,8 +1584,8 @@ pub fn io_uring_prep_remove_buffers(...@@ -1591,8 +1584,8 @@ pub fn io_uring_prep_remove_buffers(
1591 num: usize,1584 num: usize,
1592 group_id: usize,1585 group_id: usize,
1593) void {1586) void {
1594 io_uring_prep_rw(.REMOVE_BUFFERS, sqe, @intCast(i32, num), 0, 0, 0);1587 io_uring_prep_rw(.REMOVE_BUFFERS, sqe, @as(i32, @intCast(num)), 0, 0, 0);
1595 sqe.buf_index = @intCast(u16, group_id);1588 sqe.buf_index = @as(u16, @intCast(group_id));
1596}1589}
15971590
1598test "structs/offsets/entries" {1591test "structs/offsets/entries" {
...@@ -1886,12 +1879,12 @@ test "write_fixed/read_fixed" {...@@ -1886,12 +1879,12 @@ test "write_fixed/read_fixed" {
18861879
1887 try testing.expectEqual(linux.io_uring_cqe{1880 try testing.expectEqual(linux.io_uring_cqe{
1888 .user_data = 0x45454545,1881 .user_data = 0x45454545,
1889 .res = @intCast(i32, buffers[0].iov_len),1882 .res = @as(i32, @intCast(buffers[0].iov_len)),
1890 .flags = 0,1883 .flags = 0,
1891 }, cqe_write);1884 }, cqe_write);
1892 try testing.expectEqual(linux.io_uring_cqe{1885 try testing.expectEqual(linux.io_uring_cqe{
1893 .user_data = 0x12121212,1886 .user_data = 0x12121212,
1894 .res = @intCast(i32, buffers[1].iov_len),1887 .res = @as(i32, @intCast(buffers[1].iov_len)),
1895 .flags = 0,1888 .flags = 0,
1896 }, cqe_read);1889 }, cqe_read);
18971890
...@@ -2145,7 +2138,7 @@ test "timeout (after a relative time)" {...@@ -2145,7 +2138,7 @@ test "timeout (after a relative time)" {
2145 }, cqe);2138 }, cqe);
21462139
2147 // Tests should not depend on timings: skip test if outside margin.2140 // Tests should not depend on timings: skip test if outside margin.
2148 if (!std.math.approxEqAbs(f64, ms, @floatFromInt(f64, stopped - started), margin)) return error.SkipZigTest;2141 if (!std.math.approxEqAbs(f64, ms, @as(f64, @floatFromInt(stopped - started)), margin)) return error.SkipZigTest;
2149}2142}
21502143
2151test "timeout (after a number of completions)" {2144test "timeout (after a number of completions)" {
...@@ -2637,7 +2630,7 @@ test "renameat" {...@@ -2637,7 +2630,7 @@ test "renameat" {
2637 );2630 );
2638 try testing.expectEqual(linux.IORING_OP.RENAMEAT, sqe.opcode);2631 try testing.expectEqual(linux.IORING_OP.RENAMEAT, sqe.opcode);
2639 try testing.expectEqual(@as(i32, tmp.dir.fd), sqe.fd);2632 try testing.expectEqual(@as(i32, tmp.dir.fd), sqe.fd);
2640 try testing.expectEqual(@as(i32, tmp.dir.fd), @bitCast(i32, sqe.len));2633 try testing.expectEqual(@as(i32, tmp.dir.fd), @as(i32, @bitCast(sqe.len)));
2641 try testing.expectEqual(@as(u32, 1), try ring.submit());2634 try testing.expectEqual(@as(u32, 1), try ring.submit());
26422635
2643 const cqe = try ring.copy_cqe();2636 const cqe = try ring.copy_cqe();
...@@ -2850,7 +2843,7 @@ test "linkat" {...@@ -2850,7 +2843,7 @@ test "linkat" {
2850 );2843 );
2851 try testing.expectEqual(linux.IORING_OP.LINKAT, sqe.opcode);2844 try testing.expectEqual(linux.IORING_OP.LINKAT, sqe.opcode);
2852 try testing.expectEqual(@as(i32, tmp.dir.fd), sqe.fd);2845 try testing.expectEqual(@as(i32, tmp.dir.fd), sqe.fd);
2853 try testing.expectEqual(@as(i32, tmp.dir.fd), @bitCast(i32, sqe.len));2846 try testing.expectEqual(@as(i32, tmp.dir.fd), @as(i32, @bitCast(sqe.len)));
2854 try testing.expectEqual(@as(u32, 1), try ring.submit());2847 try testing.expectEqual(@as(u32, 1), try ring.submit());
28552848
2856 const cqe = try ring.copy_cqe();2849 const cqe = try ring.copy_cqe();
...@@ -2898,7 +2891,7 @@ test "provide_buffers: read" {...@@ -2898,7 +2891,7 @@ test "provide_buffers: read" {
2898 // Provide 4 buffers2891 // Provide 4 buffers
28992892
2900 {2893 {
2901 const sqe = try ring.provide_buffers(0xcccccccc, @ptrCast([*]u8, &buffers), buffer_len, buffers.len, group_id, buffer_id);2894 const sqe = try ring.provide_buffers(0xcccccccc, @as([*]u8, @ptrCast(&buffers)), buffer_len, buffers.len, group_id, buffer_id);
2902 try testing.expectEqual(linux.IORING_OP.PROVIDE_BUFFERS, sqe.opcode);2895 try testing.expectEqual(linux.IORING_OP.PROVIDE_BUFFERS, sqe.opcode);
2903 try testing.expectEqual(@as(i32, buffers.len), sqe.fd);2896 try testing.expectEqual(@as(i32, buffers.len), sqe.fd);
2904 try testing.expectEqual(@as(u32, buffers[0].len), sqe.len);2897 try testing.expectEqual(@as(u32, buffers[0].len), sqe.len);
...@@ -2939,7 +2932,7 @@ test "provide_buffers: read" {...@@ -2939,7 +2932,7 @@ test "provide_buffers: read" {
2939 try testing.expectEqual(@as(i32, buffer_len), cqe.res);2932 try testing.expectEqual(@as(i32, buffer_len), cqe.res);
29402933
2941 try testing.expectEqual(@as(u64, 0xdededede), cqe.user_data);2934 try testing.expectEqual(@as(u64, 0xdededede), cqe.user_data);
2942 try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@intCast(usize, cqe.res)]);2935 try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]);
2943 }2936 }
29442937
2945 // This read should fail2938 // This read should fail
...@@ -2971,7 +2964,7 @@ test "provide_buffers: read" {...@@ -2971,7 +2964,7 @@ test "provide_buffers: read" {
2971 const reprovided_buffer_id = 2;2964 const reprovided_buffer_id = 2;
29722965
2973 {2966 {
2974 _ = try ring.provide_buffers(0xabababab, @ptrCast([*]u8, &buffers[reprovided_buffer_id]), buffer_len, 1, group_id, reprovided_buffer_id);2967 _ = try ring.provide_buffers(0xabababab, @as([*]u8, @ptrCast(&buffers[reprovided_buffer_id])), buffer_len, 1, group_id, reprovided_buffer_id);
2975 try testing.expectEqual(@as(u32, 1), try ring.submit());2968 try testing.expectEqual(@as(u32, 1), try ring.submit());
29762969
2977 const cqe = try ring.copy_cqe();2970 const cqe = try ring.copy_cqe();
...@@ -3003,7 +2996,7 @@ test "provide_buffers: read" {...@@ -3003,7 +2996,7 @@ test "provide_buffers: read" {
3003 try testing.expectEqual(used_buffer_id, reprovided_buffer_id);2996 try testing.expectEqual(used_buffer_id, reprovided_buffer_id);
3004 try testing.expectEqual(@as(i32, buffer_len), cqe.res);2997 try testing.expectEqual(@as(i32, buffer_len), cqe.res);
3005 try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data);2998 try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data);
3006 try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@intCast(usize, cqe.res)]);2999 try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]);
3007 }3000 }
3008}3001}
30093002
...@@ -3030,7 +3023,7 @@ test "remove_buffers" {...@@ -3030,7 +3023,7 @@ test "remove_buffers" {
3030 // Provide 4 buffers3023 // Provide 4 buffers
30313024
3032 {3025 {
3033 _ = try ring.provide_buffers(0xcccccccc, @ptrCast([*]u8, &buffers), buffer_len, buffers.len, group_id, buffer_id);3026 _ = try ring.provide_buffers(0xcccccccc, @as([*]u8, @ptrCast(&buffers)), buffer_len, buffers.len, group_id, buffer_id);
3034 try testing.expectEqual(@as(u32, 1), try ring.submit());3027 try testing.expectEqual(@as(u32, 1), try ring.submit());
30353028
3036 const cqe = try ring.copy_cqe();3029 const cqe = try ring.copy_cqe();
...@@ -3076,7 +3069,7 @@ test "remove_buffers" {...@@ -3076,7 +3069,7 @@ test "remove_buffers" {
3076 try testing.expect(used_buffer_id >= 0 and used_buffer_id < 4);3069 try testing.expect(used_buffer_id >= 0 and used_buffer_id < 4);
3077 try testing.expectEqual(@as(i32, buffer_len), cqe.res);3070 try testing.expectEqual(@as(i32, buffer_len), cqe.res);
3078 try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data);3071 try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data);
3079 try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@intCast(usize, cqe.res)]);3072 try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]);
3080 }3073 }
30813074
3082 // Final read should _not_ work3075 // Final read should _not_ work
...@@ -3119,7 +3112,7 @@ test "provide_buffers: accept/connect/send/recv" {...@@ -3119,7 +3112,7 @@ test "provide_buffers: accept/connect/send/recv" {
3119 // Provide 4 buffers3112 // Provide 4 buffers
31203113
3121 {3114 {
3122 const sqe = try ring.provide_buffers(0xcccccccc, @ptrCast([*]u8, &buffers), buffer_len, buffers.len, group_id, buffer_id);3115 const sqe = try ring.provide_buffers(0xcccccccc, @as([*]u8, @ptrCast(&buffers)), buffer_len, buffers.len, group_id, buffer_id);
3123 try testing.expectEqual(linux.IORING_OP.PROVIDE_BUFFERS, sqe.opcode);3116 try testing.expectEqual(linux.IORING_OP.PROVIDE_BUFFERS, sqe.opcode);
3124 try testing.expectEqual(@as(i32, buffers.len), sqe.fd);3117 try testing.expectEqual(@as(i32, buffers.len), sqe.fd);
3125 try testing.expectEqual(@as(u32, buffer_len), sqe.len);3118 try testing.expectEqual(@as(u32, buffer_len), sqe.len);
...@@ -3181,7 +3174,7 @@ test "provide_buffers: accept/connect/send/recv" {...@@ -3181,7 +3174,7 @@ test "provide_buffers: accept/connect/send/recv" {
3181 try testing.expectEqual(@as(i32, buffer_len), cqe.res);3174 try testing.expectEqual(@as(i32, buffer_len), cqe.res);
31823175
3183 try testing.expectEqual(@as(u64, 0xdededede), cqe.user_data);3176 try testing.expectEqual(@as(u64, 0xdededede), cqe.user_data);
3184 const buffer = buffers[used_buffer_id][0..@intCast(usize, cqe.res)];3177 const buffer = buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))];
3185 try testing.expectEqualSlices(u8, &([_]u8{'z'} ** buffer_len), buffer);3178 try testing.expectEqualSlices(u8, &([_]u8{'z'} ** buffer_len), buffer);
3186 }3179 }
31873180
...@@ -3213,7 +3206,7 @@ test "provide_buffers: accept/connect/send/recv" {...@@ -3213,7 +3206,7 @@ test "provide_buffers: accept/connect/send/recv" {
3213 const reprovided_buffer_id = 2;3206 const reprovided_buffer_id = 2;
32143207
3215 {3208 {
3216 _ = try ring.provide_buffers(0xabababab, @ptrCast([*]u8, &buffers[reprovided_buffer_id]), buffer_len, 1, group_id, reprovided_buffer_id);3209 _ = try ring.provide_buffers(0xabababab, @as([*]u8, @ptrCast(&buffers[reprovided_buffer_id])), buffer_len, 1, group_id, reprovided_buffer_id);
3217 try testing.expectEqual(@as(u32, 1), try ring.submit());3210 try testing.expectEqual(@as(u32, 1), try ring.submit());
32183211
3219 const cqe = try ring.copy_cqe();3212 const cqe = try ring.copy_cqe();
...@@ -3259,7 +3252,7 @@ test "provide_buffers: accept/connect/send/recv" {...@@ -3259,7 +3252,7 @@ test "provide_buffers: accept/connect/send/recv" {
3259 try testing.expectEqual(used_buffer_id, reprovided_buffer_id);3252 try testing.expectEqual(used_buffer_id, reprovided_buffer_id);
3260 try testing.expectEqual(@as(i32, buffer_len), cqe.res);3253 try testing.expectEqual(@as(i32, buffer_len), cqe.res);
3261 try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data);3254 try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data);
3262 const buffer = buffers[used_buffer_id][0..@intCast(usize, cqe.res)];3255 const buffer = buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))];
3263 try testing.expectEqualSlices(u8, &([_]u8{'w'} ** buffer_len), buffer);3256 try testing.expectEqualSlices(u8, &([_]u8{'w'} ** buffer_len), buffer);
3264 }3257 }
3265}3258}
lib/std/os/linux/ioctl.zig+1-1
...@@ -32,7 +32,7 @@ fn io_impl(dir: Direction, io_type: u8, nr: u8, comptime T: type) u32 {...@@ -32,7 +32,7 @@ fn io_impl(dir: Direction, io_type: u8, nr: u8, comptime T: type) u32 {
32 .io_type = io_type,32 .io_type = io_type,
33 .nr = nr,33 .nr = nr,
34 };34 };
35 return @bitCast(u32, request);35 return @as(u32, @bitCast(request));
36}36}
3737
38pub fn IO(io_type: u8, nr: u8) u32 {38pub fn IO(io_type: u8, nr: u8) u32 {
lib/std/os/linux/start_pie.zig+4-4
...@@ -103,17 +103,17 @@ pub fn relocate(phdrs: []elf.Phdr) void {...@@ -103,17 +103,17 @@ pub fn relocate(phdrs: []elf.Phdr) void {
103103
104 // Apply the relocations.104 // Apply the relocations.
105 if (rel_addr != 0) {105 if (rel_addr != 0) {
106 const rel = std.mem.bytesAsSlice(elf.Rel, @ptrFromInt([*]u8, rel_addr)[0..rel_size]);106 const rel = std.mem.bytesAsSlice(elf.Rel, @as([*]u8, @ptrFromInt(rel_addr))[0..rel_size]);
107 for (rel) |r| {107 for (rel) |r| {
108 if (r.r_type() != R_RELATIVE) continue;108 if (r.r_type() != R_RELATIVE) continue;
109 @ptrFromInt(*usize, base_addr + r.r_offset).* += base_addr;109 @as(*usize, @ptrFromInt(base_addr + r.r_offset)).* += base_addr;
110 }110 }
111 }111 }
112 if (rela_addr != 0) {112 if (rela_addr != 0) {
113 const rela = std.mem.bytesAsSlice(elf.Rela, @ptrFromInt([*]u8, rela_addr)[0..rela_size]);113 const rela = std.mem.bytesAsSlice(elf.Rela, @as([*]u8, @ptrFromInt(rela_addr))[0..rela_size]);
114 for (rela) |r| {114 for (rela) |r| {
115 if (r.r_type() != R_RELATIVE) continue;115 if (r.r_type() != R_RELATIVE) continue;
116 @ptrFromInt(*usize, base_addr + r.r_offset).* += base_addr + @bitCast(usize, r.r_addend);116 @as(*usize, @ptrFromInt(base_addr + r.r_offset)).* += base_addr + @as(usize, @bitCast(r.r_addend));
117 }117 }
118 }118 }
119}119}
lib/std/os/linux/test.zig+8-8
...@@ -50,7 +50,7 @@ test "timer" {...@@ -50,7 +50,7 @@ test "timer" {
50 .it_value = time_interval,50 .it_value = time_interval,
51 };51 };
5252
53 err = linux.getErrno(linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null));53 err = linux.getErrno(linux.timerfd_settime(@as(i32, @intCast(timer_fd)), 0, &new_time, null));
54 try expect(err == .SUCCESS);54 try expect(err == .SUCCESS);
5555
56 var event = linux.epoll_event{56 var event = linux.epoll_event{
...@@ -58,13 +58,13 @@ test "timer" {...@@ -58,13 +58,13 @@ test "timer" {
58 .data = linux.epoll_data{ .ptr = 0 },58 .data = linux.epoll_data{ .ptr = 0 },
59 };59 };
6060
61 err = linux.getErrno(linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL.CTL_ADD, @intCast(i32, timer_fd), &event));61 err = linux.getErrno(linux.epoll_ctl(@as(i32, @intCast(epoll_fd)), linux.EPOLL.CTL_ADD, @as(i32, @intCast(timer_fd)), &event));
62 try expect(err == .SUCCESS);62 try expect(err == .SUCCESS);
6363
64 const events_one: linux.epoll_event = undefined;64 const events_one: linux.epoll_event = undefined;
65 var events = [_]linux.epoll_event{events_one} ** 8;65 var events = [_]linux.epoll_event{events_one} ** 8;
6666
67 err = linux.getErrno(linux.epoll_wait(@intCast(i32, epoll_fd), &events, 8, -1));67 err = linux.getErrno(linux.epoll_wait(@as(i32, @intCast(epoll_fd)), &events, 8, -1));
68 try expect(err == .SUCCESS);68 try expect(err == .SUCCESS);
69}69}
7070
...@@ -91,11 +91,11 @@ test "statx" {...@@ -91,11 +91,11 @@ test "statx" {
91 }91 }
9292
93 try expect(stat_buf.mode == statx_buf.mode);93 try expect(stat_buf.mode == statx_buf.mode);
94 try expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);94 try expect(@as(u32, @bitCast(stat_buf.uid)) == statx_buf.uid);
95 try expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);95 try expect(@as(u32, @bitCast(stat_buf.gid)) == statx_buf.gid);
96 try expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);96 try expect(@as(u64, @bitCast(@as(i64, stat_buf.size))) == statx_buf.size);
97 try expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);97 try expect(@as(u64, @bitCast(@as(i64, stat_buf.blksize))) == statx_buf.blksize);
98 try expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);98 try expect(@as(u64, @bitCast(@as(i64, stat_buf.blocks))) == statx_buf.blocks);
99}99}
100100
101test "user and group ids" {101test "user and group ids" {
lib/std/os/linux/tls.zig+3-3
...@@ -205,7 +205,7 @@ fn initTLS(phdrs: []elf.Phdr) void {...@@ -205,7 +205,7 @@ fn initTLS(phdrs: []elf.Phdr) void {
205 // the data stored in the PT_TLS segment is p_filesz and may be less205 // the data stored in the PT_TLS segment is p_filesz and may be less
206 // than the former206 // than the former
207 tls_align_factor = phdr.p_align;207 tls_align_factor = phdr.p_align;
208 tls_data = @ptrFromInt([*]u8, img_base + phdr.p_vaddr)[0..phdr.p_filesz];208 tls_data = @as([*]u8, @ptrFromInt(img_base + phdr.p_vaddr))[0..phdr.p_filesz];
209 tls_data_alloc_size = phdr.p_memsz;209 tls_data_alloc_size = phdr.p_memsz;
210 } else {210 } else {
211 tls_align_factor = @alignOf(usize);211 tls_align_factor = @alignOf(usize);
...@@ -263,12 +263,12 @@ fn initTLS(phdrs: []elf.Phdr) void {...@@ -263,12 +263,12 @@ fn initTLS(phdrs: []elf.Phdr) void {
263 .dtv_offset = dtv_offset,263 .dtv_offset = dtv_offset,
264 .data_offset = data_offset,264 .data_offset = data_offset,
265 .data_size = tls_data_alloc_size,265 .data_size = tls_data_alloc_size,
266 .gdt_entry_number = @bitCast(usize, @as(isize, -1)),266 .gdt_entry_number = @as(usize, @bitCast(@as(isize, -1))),
267 };267 };
268}268}
269269
270inline fn alignPtrCast(comptime T: type, ptr: [*]u8) *T {270inline fn alignPtrCast(comptime T: type, ptr: [*]u8) *T {
271 return @ptrCast(*T, @alignCast(@alignOf(T), ptr));271 return @ptrCast(@alignCast(ptr));
272}272}
273273
274/// Initializes all the fields of the static TLS area and returns the computed274/// Initializes all the fields of the static TLS area and returns the computed
lib/std/os/linux/vdso.zig+15-15
...@@ -8,7 +8,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -8,7 +8,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
8 const vdso_addr = std.os.system.getauxval(std.elf.AT_SYSINFO_EHDR);8 const vdso_addr = std.os.system.getauxval(std.elf.AT_SYSINFO_EHDR);
9 if (vdso_addr == 0) return 0;9 if (vdso_addr == 0) return 0;
1010
11 const eh = @ptrFromInt(*elf.Ehdr, vdso_addr);11 const eh = @as(*elf.Ehdr, @ptrFromInt(vdso_addr));
12 var ph_addr: usize = vdso_addr + eh.e_phoff;12 var ph_addr: usize = vdso_addr + eh.e_phoff;
1313
14 var maybe_dynv: ?[*]usize = null;14 var maybe_dynv: ?[*]usize = null;
...@@ -19,14 +19,14 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -19,14 +19,14 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
19 i += 1;19 i += 1;
20 ph_addr += eh.e_phentsize;20 ph_addr += eh.e_phentsize;
21 }) {21 }) {
22 const this_ph = @ptrFromInt(*elf.Phdr, ph_addr);22 const this_ph = @as(*elf.Phdr, @ptrFromInt(ph_addr));
23 switch (this_ph.p_type) {23 switch (this_ph.p_type) {
24 // On WSL1 as well as older kernels, the VDSO ELF image is pre-linked in the upper half24 // On WSL1 as well as older kernels, the VDSO ELF image is pre-linked in the upper half
25 // of the memory space (e.g. p_vaddr = 0xffffffffff700000 on WSL1).25 // of the memory space (e.g. p_vaddr = 0xffffffffff700000 on WSL1).
26 // Wrapping operations are used on this line as well as subsequent calculations relative to base26 // Wrapping operations are used on this line as well as subsequent calculations relative to base
27 // (lines 47, 78) to ensure no overflow check is tripped.27 // (lines 47, 78) to ensure no overflow check is tripped.
28 elf.PT_LOAD => base = vdso_addr +% this_ph.p_offset -% this_ph.p_vaddr,28 elf.PT_LOAD => base = vdso_addr +% this_ph.p_offset -% this_ph.p_vaddr,
29 elf.PT_DYNAMIC => maybe_dynv = @ptrFromInt([*]usize, vdso_addr + this_ph.p_offset),29 elf.PT_DYNAMIC => maybe_dynv = @as([*]usize, @ptrFromInt(vdso_addr + this_ph.p_offset)),
30 else => {},30 else => {},
31 }31 }
32 }32 }
...@@ -45,11 +45,11 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -45,11 +45,11 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
45 while (dynv[i] != 0) : (i += 2) {45 while (dynv[i] != 0) : (i += 2) {
46 const p = base +% dynv[i + 1];46 const p = base +% dynv[i + 1];
47 switch (dynv[i]) {47 switch (dynv[i]) {
48 elf.DT_STRTAB => maybe_strings = @ptrFromInt([*]u8, p),48 elf.DT_STRTAB => maybe_strings = @as([*]u8, @ptrFromInt(p)),
49 elf.DT_SYMTAB => maybe_syms = @ptrFromInt([*]elf.Sym, p),49 elf.DT_SYMTAB => maybe_syms = @as([*]elf.Sym, @ptrFromInt(p)),
50 elf.DT_HASH => maybe_hashtab = @ptrFromInt([*]linux.Elf_Symndx, p),50 elf.DT_HASH => maybe_hashtab = @as([*]linux.Elf_Symndx, @ptrFromInt(p)),
51 elf.DT_VERSYM => maybe_versym = @ptrFromInt([*]u16, p),51 elf.DT_VERSYM => maybe_versym = @as([*]u16, @ptrFromInt(p)),
52 elf.DT_VERDEF => maybe_verdef = @ptrFromInt(*elf.Verdef, p),52 elf.DT_VERDEF => maybe_verdef = @as(*elf.Verdef, @ptrFromInt(p)),
53 else => {},53 else => {},
54 }54 }
55 }55 }
...@@ -65,10 +65,10 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -65,10 +65,10 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
6565
66 var i: usize = 0;66 var i: usize = 0;
67 while (i < hashtab[1]) : (i += 1) {67 while (i < hashtab[1]) : (i += 1) {
68 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue;68 if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info & 0xf)) & OK_TYPES)) continue;
69 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;69 if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info >> 4)) & OK_BINDS)) continue;
70 if (0 == syms[i].st_shndx) continue;70 if (0 == syms[i].st_shndx) continue;
71 const sym_name = @ptrCast([*:0]u8, strings + syms[i].st_name);71 const sym_name = @as([*:0]u8, @ptrCast(strings + syms[i].st_name));
72 if (!mem.eql(u8, name, mem.sliceTo(sym_name, 0))) continue;72 if (!mem.eql(u8, name, mem.sliceTo(sym_name, 0))) continue;
73 if (maybe_versym) |versym| {73 if (maybe_versym) |versym| {
74 if (!checkver(maybe_verdef.?, versym[i], vername, strings))74 if (!checkver(maybe_verdef.?, versym[i], vername, strings))
...@@ -82,15 +82,15 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -82,15 +82,15 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
8282
83fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [*]u8) bool {83fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [*]u8) bool {
84 var def = def_arg;84 var def = def_arg;
85 const vsym = @bitCast(u32, vsym_arg) & 0x7fff;85 const vsym = @as(u32, @bitCast(vsym_arg)) & 0x7fff;
86 while (true) {86 while (true) {
87 if (0 == (def.vd_flags & elf.VER_FLG_BASE) and (def.vd_ndx & 0x7fff) == vsym)87 if (0 == (def.vd_flags & elf.VER_FLG_BASE) and (def.vd_ndx & 0x7fff) == vsym)
88 break;88 break;
89 if (def.vd_next == 0)89 if (def.vd_next == 0)
90 return false;90 return false;
91 def = @ptrFromInt(*elf.Verdef, @intFromPtr(def) + def.vd_next);91 def = @as(*elf.Verdef, @ptrFromInt(@intFromPtr(def) + def.vd_next));
92 }92 }
93 const aux = @ptrFromInt(*elf.Verdaux, @intFromPtr(def) + def.vd_aux);93 const aux = @as(*elf.Verdaux, @ptrFromInt(@intFromPtr(def) + def.vd_aux));
94 const vda_name = @ptrCast([*:0]u8, strings + aux.vda_name);94 const vda_name = @as([*:0]u8, @ptrCast(strings + aux.vda_name));
95 return mem.eql(u8, vername, mem.sliceTo(vda_name, 0));95 return mem.eql(u8, vername, mem.sliceTo(vda_name, 0));
96}96}
lib/std/os/plan9.zig+2-2
...@@ -8,9 +8,9 @@ pub const syscall_bits = switch (builtin.cpu.arch) {...@@ -8,9 +8,9 @@ pub const syscall_bits = switch (builtin.cpu.arch) {
8pub const E = @import("plan9/errno.zig").E;8pub const E = @import("plan9/errno.zig").E;
9/// Get the errno from a syscall return value, or 0 for no error.9/// Get the errno from a syscall return value, or 0 for no error.
10pub fn getErrno(r: usize) E {10pub fn getErrno(r: usize) E {
11 const signed_r = @bitCast(isize, r);11 const signed_r = @as(isize, @bitCast(r));
12 const int = if (signed_r > -4096 and signed_r < 0) -signed_r else 0;12 const int = if (signed_r > -4096 and signed_r < 0) -signed_r else 0;
13 return @enumFromInt(E, int);13 return @as(E, @enumFromInt(int));
14}14}
15pub const SIG = struct {15pub const SIG = struct {
16 /// hangup16 /// hangup
lib/std/os/test.zig+2-2
...@@ -488,7 +488,7 @@ fn iter_fn(info: *dl_phdr_info, size: usize, counter: *usize) IterFnError!void {...@@ -488,7 +488,7 @@ fn iter_fn(info: *dl_phdr_info, size: usize, counter: *usize) IterFnError!void {
488488
489 const reloc_addr = info.dlpi_addr + phdr.p_vaddr;489 const reloc_addr = info.dlpi_addr + phdr.p_vaddr;
490 // Find the ELF header490 // Find the ELF header
491 const elf_header = @ptrFromInt(*elf.Ehdr, reloc_addr - phdr.p_offset);491 const elf_header = @as(*elf.Ehdr, @ptrFromInt(reloc_addr - phdr.p_offset));
492 // Validate the magic492 // Validate the magic
493 if (!mem.eql(u8, elf_header.e_ident[0..4], elf.MAGIC)) return error.BadElfMagic;493 if (!mem.eql(u8, elf_header.e_ident[0..4], elf.MAGIC)) return error.BadElfMagic;
494 // Consistency check494 // Consistency check
...@@ -751,7 +751,7 @@ test "getrlimit and setrlimit" {...@@ -751,7 +751,7 @@ test "getrlimit and setrlimit" {
751 }751 }
752752
753 inline for (std.meta.fields(os.rlimit_resource)) |field| {753 inline for (std.meta.fields(os.rlimit_resource)) |field| {
754 const resource = @enumFromInt(os.rlimit_resource, field.value);754 const resource = @as(os.rlimit_resource, @enumFromInt(field.value));
755 const limit = try os.getrlimit(resource);755 const limit = try os.getrlimit(resource);
756756
757 // On 32 bit MIPS musl includes a fix which changes limits greater than -1UL/2 to RLIM_INFINITY.757 // On 32 bit MIPS musl includes a fix which changes limits greater than -1UL/2 to RLIM_INFINITY.
lib/std/os/uefi.zig+1-1
...@@ -143,7 +143,7 @@ pub const FileHandle = *opaque {};...@@ -143,7 +143,7 @@ pub const FileHandle = *opaque {};
143test "GUID formatting" {143test "GUID formatting" {
144 var bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 };144 var bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 };
145145
146 var guid = @bitCast(Guid, bytes);146 var guid = @as(Guid, @bitCast(bytes));
147147
148 var str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid});148 var str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid});
149 defer std.testing.allocator.free(str);149 defer std.testing.allocator.free(str);
lib/std/os/uefi/pool_allocator.zig+3-3
...@@ -9,7 +9,7 @@ const Allocator = mem.Allocator;...@@ -9,7 +9,7 @@ const Allocator = mem.Allocator;
99
10const UefiPoolAllocator = struct {10const UefiPoolAllocator = struct {
11 fn getHeader(ptr: [*]u8) *[*]align(8) u8 {11 fn getHeader(ptr: [*]u8) *[*]align(8) u8 {
12 return @ptrFromInt(*[*]align(8) u8, @intFromPtr(ptr) - @sizeOf(usize));12 return @as(*[*]align(8) u8, @ptrFromInt(@intFromPtr(ptr) - @sizeOf(usize)));
13 }13 }
1414
15 fn alloc(15 fn alloc(
...@@ -22,7 +22,7 @@ const UefiPoolAllocator = struct {...@@ -22,7 +22,7 @@ const UefiPoolAllocator = struct {
2222
23 assert(len > 0);23 assert(len > 0);
2424
25 const ptr_align = @as(usize, 1) << @intCast(Allocator.Log2Align, log2_ptr_align);25 const ptr_align = @as(usize, 1) << @as(Allocator.Log2Align, @intCast(log2_ptr_align));
2626
27 const metadata_len = mem.alignForward(usize, @sizeOf(usize), ptr_align);27 const metadata_len = mem.alignForward(usize, @sizeOf(usize), ptr_align);
2828
...@@ -135,5 +135,5 @@ fn uefi_free(...@@ -135,5 +135,5 @@ fn uefi_free(
135) void {135) void {
136 _ = log2_old_ptr_align;136 _ = log2_old_ptr_align;
137 _ = ret_addr;137 _ = ret_addr;
138 _ = uefi.system_table.boot_services.?.freePool(@alignCast(8, buf.ptr));138 _ = uefi.system_table.boot_services.?.freePool(@alignCast(buf.ptr));
139}139}
lib/std/os/uefi/protocols/device_path_protocol.zig+13-13
...@@ -23,10 +23,10 @@ pub const DevicePathProtocol = extern struct {...@@ -23,10 +23,10 @@ pub const DevicePathProtocol = extern struct {
2323
24 /// Returns the next DevicePathProtocol node in the sequence, if any.24 /// Returns the next DevicePathProtocol node in the sequence, if any.
25 pub fn next(self: *DevicePathProtocol) ?*DevicePathProtocol {25 pub fn next(self: *DevicePathProtocol) ?*DevicePathProtocol {
26 if (self.type == .End and @enumFromInt(EndDevicePath.Subtype, self.subtype) == .EndEntire)26 if (self.type == .End and @as(EndDevicePath.Subtype, @enumFromInt(self.subtype)) == .EndEntire)
27 return null;27 return null;
2828
29 return @ptrCast(*DevicePathProtocol, @ptrCast([*]u8, self) + self.length);29 return @as(*DevicePathProtocol, @ptrCast(@as([*]u8, @ptrCast(self)) + self.length));
30 }30 }
3131
32 /// Calculates the total length of the device path structure in bytes, including the end of device path node.32 /// Calculates the total length of the device path structure in bytes, including the end of device path node.
...@@ -48,30 +48,30 @@ pub const DevicePathProtocol = extern struct {...@@ -48,30 +48,30 @@ pub const DevicePathProtocol = extern struct {
48 // DevicePathProtocol for the extra node before the end48 // DevicePathProtocol for the extra node before the end
49 var buf = try allocator.alloc(u8, path_size + 2 * (path.len + 1) + @sizeOf(DevicePathProtocol));49 var buf = try allocator.alloc(u8, path_size + 2 * (path.len + 1) + @sizeOf(DevicePathProtocol));
5050
51 @memcpy(buf[0..path_size.len], @ptrCast([*]const u8, self)[0..path_size]);51 @memcpy(buf[0..path_size.len], @as([*]const u8, @ptrCast(self))[0..path_size]);
5252
53 // Pointer to the copy of the end node of the current chain, which is - 4 from the buffer53 // Pointer to the copy of the end node of the current chain, which is - 4 from the buffer
54 // as the end node itself is 4 bytes (type: u8 + subtype: u8 + length: u16).54 // as the end node itself is 4 bytes (type: u8 + subtype: u8 + length: u16).
55 var new = @ptrCast(*MediaDevicePath.FilePathDevicePath, buf.ptr + path_size - 4);55 var new = @as(*MediaDevicePath.FilePathDevicePath, @ptrCast(buf.ptr + path_size - 4));
5656
57 new.type = .Media;57 new.type = .Media;
58 new.subtype = .FilePath;58 new.subtype = .FilePath;
59 new.length = @sizeOf(MediaDevicePath.FilePathDevicePath) + 2 * (@intCast(u16, path.len) + 1);59 new.length = @sizeOf(MediaDevicePath.FilePathDevicePath) + 2 * (@as(u16, @intCast(path.len)) + 1);
6060
61 // The same as new.getPath(), but not const as we're filling it in.61 // The same as new.getPath(), but not const as we're filling it in.
62 var ptr = @ptrCast([*:0]align(1) u16, @ptrCast([*]u8, new) + @sizeOf(MediaDevicePath.FilePathDevicePath));62 var ptr = @as([*:0]align(1) u16, @ptrCast(@as([*]u8, @ptrCast(new)) + @sizeOf(MediaDevicePath.FilePathDevicePath)));
6363
64 for (path, 0..) |s, i|64 for (path, 0..) |s, i|
65 ptr[i] = s;65 ptr[i] = s;
6666
67 ptr[path.len] = 0;67 ptr[path.len] = 0;
6868
69 var end = @ptrCast(*EndDevicePath.EndEntireDevicePath, @ptrCast(*DevicePathProtocol, new).next().?);69 var end = @as(*EndDevicePath.EndEntireDevicePath, @ptrCast(@as(*DevicePathProtocol, @ptrCast(new)).next().?));
70 end.type = .End;70 end.type = .End;
71 end.subtype = .EndEntire;71 end.subtype = .EndEntire;
72 end.length = @sizeOf(EndDevicePath.EndEntireDevicePath);72 end.length = @sizeOf(EndDevicePath.EndEntireDevicePath);
7373
74 return @ptrCast(*DevicePathProtocol, buf.ptr);74 return @as(*DevicePathProtocol, @ptrCast(buf.ptr));
75 }75 }
7676
77 pub fn getDevicePath(self: *const DevicePathProtocol) ?DevicePath {77 pub fn getDevicePath(self: *const DevicePathProtocol) ?DevicePath {
...@@ -103,7 +103,7 @@ pub const DevicePathProtocol = extern struct {...@@ -103,7 +103,7 @@ pub const DevicePathProtocol = extern struct {
103103
104 if (self.subtype == tag_val) {104 if (self.subtype == tag_val) {
105 // e.g. expr = .{ .Pci = @ptrCast(...) }105 // e.g. expr = .{ .Pci = @ptrCast(...) }
106 return @unionInit(TUnion, subtype.name, @ptrCast(subtype.type, self));106 return @unionInit(TUnion, subtype.name, @as(subtype.type, @ptrCast(self)));
107 }107 }
108 }108 }
109109
...@@ -332,7 +332,7 @@ pub const AcpiDevicePath = union(Subtype) {...@@ -332,7 +332,7 @@ pub const AcpiDevicePath = union(Subtype) {
332 pub fn adrs(self: *const AdrDevicePath) []align(1) const u32 {332 pub fn adrs(self: *const AdrDevicePath) []align(1) const u32 {
333 // self.length is a minimum of 8 with one adr which is size 4.333 // self.length is a minimum of 8 with one adr which is size 4.
334 var entries = (self.length - 4) / @sizeOf(u32);334 var entries = (self.length - 4) / @sizeOf(u32);
335 return @ptrCast([*]align(1) const u32, &self.adr)[0..entries];335 return @as([*]align(1) const u32, @ptrCast(&self.adr))[0..entries];
336 }336 }
337 };337 };
338338
...@@ -550,7 +550,7 @@ pub const MessagingDevicePath = union(Subtype) {...@@ -550,7 +550,7 @@ pub const MessagingDevicePath = union(Subtype) {
550550
551 pub fn serial_number(self: *const UsbWwidDevicePath) []align(1) const u16 {551 pub fn serial_number(self: *const UsbWwidDevicePath) []align(1) const u16 {
552 var serial_len = (self.length - @sizeOf(UsbWwidDevicePath)) / @sizeOf(u16);552 var serial_len = (self.length - @sizeOf(UsbWwidDevicePath)) / @sizeOf(u16);
553 return @ptrCast([*]align(1) const u16, @ptrCast([*]const u8, self) + @sizeOf(UsbWwidDevicePath))[0..serial_len];553 return @as([*]align(1) const u16, @ptrCast(@as([*]const u8, @ptrCast(self)) + @sizeOf(UsbWwidDevicePath)))[0..serial_len];
554 }554 }
555 };555 };
556556
...@@ -943,7 +943,7 @@ pub const MediaDevicePath = union(Subtype) {...@@ -943,7 +943,7 @@ pub const MediaDevicePath = union(Subtype) {
943 length: u16 align(1),943 length: u16 align(1),
944944
945 pub fn getPath(self: *const FilePathDevicePath) [*:0]align(1) const u16 {945 pub fn getPath(self: *const FilePathDevicePath) [*:0]align(1) const u16 {
946 return @ptrCast([*:0]align(1) const u16, @ptrCast([*]const u8, self) + @sizeOf(FilePathDevicePath));946 return @as([*:0]align(1) const u16, @ptrCast(@as([*]const u8, @ptrCast(self)) + @sizeOf(FilePathDevicePath)));
947 }947 }
948 };948 };
949949
...@@ -1068,7 +1068,7 @@ pub const BiosBootSpecificationDevicePath = union(Subtype) {...@@ -1068,7 +1068,7 @@ pub const BiosBootSpecificationDevicePath = union(Subtype) {
1068 status_flag: u16 align(1),1068 status_flag: u16 align(1),
10691069
1070 pub fn getDescription(self: *const BBS101DevicePath) [*:0]const u8 {1070 pub fn getDescription(self: *const BBS101DevicePath) [*:0]const u8 {
1071 return @ptrCast([*:0]const u8, self) + @sizeOf(BBS101DevicePath);1071 return @as([*:0]const u8, @ptrCast(self)) + @sizeOf(BBS101DevicePath);
1072 }1072 }
1073 };1073 };
10741074
lib/std/os/uefi/protocols/file_protocol.zig+2-2
...@@ -152,7 +152,7 @@ pub const FileInfo = extern struct {...@@ -152,7 +152,7 @@ pub const FileInfo = extern struct {
152 attribute: u64,152 attribute: u64,
153153
154 pub fn getFileName(self: *const FileInfo) [*:0]const u16 {154 pub fn getFileName(self: *const FileInfo) [*:0]const u16 {
155 return @ptrCast([*:0]const u16, @ptrCast([*]const u8, self) + @sizeOf(FileInfo));155 return @as([*:0]const u16, @ptrCast(@as([*]const u8, @ptrCast(self)) + @sizeOf(FileInfo)));
156 }156 }
157157
158 pub const efi_file_read_only: u64 = 0x0000000000000001;158 pub const efi_file_read_only: u64 = 0x0000000000000001;
...@@ -182,7 +182,7 @@ pub const FileSystemInfo = extern struct {...@@ -182,7 +182,7 @@ pub const FileSystemInfo = extern struct {
182 _volume_label: u16,182 _volume_label: u16,
183183
184 pub fn getVolumeLabel(self: *const FileSystemInfo) [*:0]const u16 {184 pub fn getVolumeLabel(self: *const FileSystemInfo) [*:0]const u16 {
185 return @ptrCast([*:0]const u16, &self._volume_label);185 return @as([*:0]const u16, @ptrCast(&self._volume_label));
186 }186 }
187187
188 pub const guid align(8) = Guid{188 pub const guid align(8) = Guid{
lib/std/os/uefi/protocols/hii.zig+1-1
...@@ -39,7 +39,7 @@ pub const HIISimplifiedFontPackage = extern struct {...@@ -39,7 +39,7 @@ pub const HIISimplifiedFontPackage = extern struct {
39 number_of_wide_glyphs: u16,39 number_of_wide_glyphs: u16,
4040
41 pub fn getNarrowGlyphs(self: *HIISimplifiedFontPackage) []NarrowGlyph {41 pub fn getNarrowGlyphs(self: *HIISimplifiedFontPackage) []NarrowGlyph {
42 return @ptrCast([*]NarrowGlyph, @ptrCast([*]u8, self) + @sizeOf(HIISimplifiedFontPackage))[0..self.number_of_narrow_glyphs];42 return @as([*]NarrowGlyph, @ptrCast(@as([*]u8, @ptrCast(self)) + @sizeOf(HIISimplifiedFontPackage)))[0..self.number_of_narrow_glyphs];
43 }43 }
44};44};
4545
lib/std/os/uefi/protocols/managed_network_protocol.zig+1-1
...@@ -118,7 +118,7 @@ pub const ManagedNetworkTransmitData = extern struct {...@@ -118,7 +118,7 @@ pub const ManagedNetworkTransmitData = extern struct {
118 fragment_count: u16,118 fragment_count: u16,
119119
120 pub fn getFragments(self: *ManagedNetworkTransmitData) []ManagedNetworkFragmentData {120 pub fn getFragments(self: *ManagedNetworkTransmitData) []ManagedNetworkFragmentData {
121 return @ptrCast([*]ManagedNetworkFragmentData, @ptrCast([*]u8, self) + @sizeOf(ManagedNetworkTransmitData))[0..self.fragment_count];121 return @as([*]ManagedNetworkFragmentData, @ptrCast(@as([*]u8, @ptrCast(self)) + @sizeOf(ManagedNetworkTransmitData)))[0..self.fragment_count];
122 }122 }
123};123};
124124
lib/std/os/uefi/protocols/udp6_protocol.zig+2-2
...@@ -87,7 +87,7 @@ pub const Udp6ReceiveData = extern struct {...@@ -87,7 +87,7 @@ pub const Udp6ReceiveData = extern struct {
87 fragment_count: u32,87 fragment_count: u32,
8888
89 pub fn getFragments(self: *Udp6ReceiveData) []Udp6FragmentData {89 pub fn getFragments(self: *Udp6ReceiveData) []Udp6FragmentData {
90 return @ptrCast([*]Udp6FragmentData, @ptrCast([*]u8, self) + @sizeOf(Udp6ReceiveData))[0..self.fragment_count];90 return @as([*]Udp6FragmentData, @ptrCast(@as([*]u8, @ptrCast(self)) + @sizeOf(Udp6ReceiveData)))[0..self.fragment_count];
91 }91 }
92};92};
9393
...@@ -97,7 +97,7 @@ pub const Udp6TransmitData = extern struct {...@@ -97,7 +97,7 @@ pub const Udp6TransmitData = extern struct {
97 fragment_count: u32,97 fragment_count: u32,
9898
99 pub fn getFragments(self: *Udp6TransmitData) []Udp6FragmentData {99 pub fn getFragments(self: *Udp6TransmitData) []Udp6FragmentData {
100 return @ptrCast([*]Udp6FragmentData, @ptrCast([*]u8, self) + @sizeOf(Udp6TransmitData))[0..self.fragment_count];100 return @as([*]Udp6FragmentData, @ptrCast(@as([*]u8, @ptrCast(self)) + @sizeOf(Udp6TransmitData)))[0..self.fragment_count];
101 }101 }
102};102};
103103
lib/std/os/uefi/tables/boot_services.zig+1-1
...@@ -165,7 +165,7 @@ pub const BootServices = extern struct {...@@ -165,7 +165,7 @@ pub const BootServices = extern struct {
165 try self.openProtocol(165 try self.openProtocol(
166 handle,166 handle,
167 &protocol.guid,167 &protocol.guid,
168 @ptrCast(*?*anyopaque, &ptr),168 @as(*?*anyopaque, @ptrCast(&ptr)),
169 // Invoking handle (loaded image)169 // Invoking handle (loaded image)
170 uefi.handle,170 uefi.handle,
171 // Control handle (null as not a driver)171 // Control handle (null as not a driver)
lib/std/os/wasi.zig+3-3
...@@ -103,13 +103,13 @@ pub const timespec = extern struct {...@@ -103,13 +103,13 @@ pub const timespec = extern struct {
103 const tv_sec: timestamp_t = tm / 1_000_000_000;103 const tv_sec: timestamp_t = tm / 1_000_000_000;
104 const tv_nsec = tm - tv_sec * 1_000_000_000;104 const tv_nsec = tm - tv_sec * 1_000_000_000;
105 return timespec{105 return timespec{
106 .tv_sec = @intCast(time_t, tv_sec),106 .tv_sec = @as(time_t, @intCast(tv_sec)),
107 .tv_nsec = @intCast(isize, tv_nsec),107 .tv_nsec = @as(isize, @intCast(tv_nsec)),
108 };108 };
109 }109 }
110110
111 pub fn toTimestamp(ts: timespec) timestamp_t {111 pub fn toTimestamp(ts: timespec) timestamp_t {
112 const tm = @intCast(timestamp_t, ts.tv_sec * 1_000_000_000) + @intCast(timestamp_t, ts.tv_nsec);112 const tm = @as(timestamp_t, @intCast(ts.tv_sec * 1_000_000_000)) + @as(timestamp_t, @intCast(ts.tv_nsec));
113 return tm;113 return tm;
114 }114 }
115};115};
lib/std/os/windows.zig+83-83
...@@ -30,7 +30,7 @@ pub const gdi32 = @import("windows/gdi32.zig");...@@ -30,7 +30,7 @@ pub const gdi32 = @import("windows/gdi32.zig");
30pub const winmm = @import("windows/winmm.zig");30pub const winmm = @import("windows/winmm.zig");
31pub const crypt32 = @import("windows/crypt32.zig");31pub const crypt32 = @import("windows/crypt32.zig");
3232
33pub const self_process_handle = @ptrFromInt(HANDLE, maxInt(usize));33pub const self_process_handle = @as(HANDLE, @ptrFromInt(maxInt(usize)));
3434
35const Self = @This();35const Self = @This();
3636
...@@ -198,9 +198,9 @@ pub fn DeviceIoControl(...@@ -198,9 +198,9 @@ pub fn DeviceIoControl(
198198
199 var io: IO_STATUS_BLOCK = undefined;199 var io: IO_STATUS_BLOCK = undefined;
200 const in_ptr = if (in) |i| i.ptr else null;200 const in_ptr = if (in) |i| i.ptr else null;
201 const in_len = if (in) |i| @intCast(ULONG, i.len) else 0;201 const in_len = if (in) |i| @as(ULONG, @intCast(i.len)) else 0;
202 const out_ptr = if (out) |o| o.ptr else null;202 const out_ptr = if (out) |o| o.ptr else null;
203 const out_len = if (out) |o| @intCast(ULONG, o.len) else 0;203 const out_len = if (out) |o| @as(ULONG, @intCast(o.len)) else 0;
204204
205 const rc = blk: {205 const rc = blk: {
206 if (is_fsctl) {206 if (is_fsctl) {
...@@ -307,7 +307,7 @@ pub fn WaitForSingleObjectEx(handle: HANDLE, milliseconds: DWORD, alertable: boo...@@ -307,7 +307,7 @@ pub fn WaitForSingleObjectEx(handle: HANDLE, milliseconds: DWORD, alertable: boo
307307
308pub fn WaitForMultipleObjectsEx(handles: []const HANDLE, waitAll: bool, milliseconds: DWORD, alertable: bool) !u32 {308pub fn WaitForMultipleObjectsEx(handles: []const HANDLE, waitAll: bool, milliseconds: DWORD, alertable: bool) !u32 {
309 assert(handles.len < MAXIMUM_WAIT_OBJECTS);309 assert(handles.len < MAXIMUM_WAIT_OBJECTS);
310 const nCount: DWORD = @intCast(DWORD, handles.len);310 const nCount: DWORD = @as(DWORD, @intCast(handles.len));
311 switch (kernel32.WaitForMultipleObjectsEx(311 switch (kernel32.WaitForMultipleObjectsEx(
312 nCount,312 nCount,
313 handles.ptr,313 handles.ptr,
...@@ -419,7 +419,7 @@ pub fn GetQueuedCompletionStatusEx(...@@ -419,7 +419,7 @@ pub fn GetQueuedCompletionStatusEx(
419 const success = kernel32.GetQueuedCompletionStatusEx(419 const success = kernel32.GetQueuedCompletionStatusEx(
420 completion_port,420 completion_port,
421 completion_port_entries.ptr,421 completion_port_entries.ptr,
422 @intCast(ULONG, completion_port_entries.len),422 @as(ULONG, @intCast(completion_port_entries.len)),
423 &num_entries_removed,423 &num_entries_removed,
424 timeout_ms orelse INFINITE,424 timeout_ms orelse INFINITE,
425 @intFromBool(alertable),425 @intFromBool(alertable),
...@@ -469,8 +469,8 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo...@@ -469,8 +469,8 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo
469 .InternalHigh = 0,469 .InternalHigh = 0,
470 .DUMMYUNIONNAME = .{470 .DUMMYUNIONNAME = .{
471 .DUMMYSTRUCTNAME = .{471 .DUMMYSTRUCTNAME = .{
472 .Offset = @truncate(u32, off),472 .Offset = @as(u32, @truncate(off)),
473 .OffsetHigh = @truncate(u32, off >> 32),473 .OffsetHigh = @as(u32, @truncate(off >> 32)),
474 },474 },
475 },475 },
476 .hEvent = null,476 .hEvent = null,
...@@ -480,7 +480,7 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo...@@ -480,7 +480,7 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo
480 loop.beginOneEvent();480 loop.beginOneEvent();
481 suspend {481 suspend {
482 // TODO handle buffer bigger than DWORD can hold482 // TODO handle buffer bigger than DWORD can hold
483 _ = kernel32.ReadFile(in_hFile, buffer.ptr, @intCast(DWORD, buffer.len), null, &resume_node.base.overlapped);483 _ = kernel32.ReadFile(in_hFile, buffer.ptr, @as(DWORD, @intCast(buffer.len)), null, &resume_node.base.overlapped);
484 }484 }
485 var bytes_transferred: DWORD = undefined;485 var bytes_transferred: DWORD = undefined;
486 if (kernel32.GetOverlappedResult(in_hFile, &resume_node.base.overlapped, &bytes_transferred, FALSE) == 0) {486 if (kernel32.GetOverlappedResult(in_hFile, &resume_node.base.overlapped, &bytes_transferred, FALSE) == 0) {
...@@ -496,7 +496,7 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo...@@ -496,7 +496,7 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo
496 if (offset == null) {496 if (offset == null) {
497 // TODO make setting the file position non-blocking497 // TODO make setting the file position non-blocking
498 const new_off = off + bytes_transferred;498 const new_off = off + bytes_transferred;
499 try SetFilePointerEx_CURRENT(in_hFile, @bitCast(i64, new_off));499 try SetFilePointerEx_CURRENT(in_hFile, @as(i64, @bitCast(new_off)));
500 }500 }
501 return @as(usize, bytes_transferred);501 return @as(usize, bytes_transferred);
502 } else {502 } else {
...@@ -510,8 +510,8 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo...@@ -510,8 +510,8 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo
510 .InternalHigh = 0,510 .InternalHigh = 0,
511 .DUMMYUNIONNAME = .{511 .DUMMYUNIONNAME = .{
512 .DUMMYSTRUCTNAME = .{512 .DUMMYSTRUCTNAME = .{
513 .Offset = @truncate(u32, off),513 .Offset = @as(u32, @truncate(off)),
514 .OffsetHigh = @truncate(u32, off >> 32),514 .OffsetHigh = @as(u32, @truncate(off >> 32)),
515 },515 },
516 },516 },
517 .hEvent = null,517 .hEvent = null,
...@@ -563,8 +563,8 @@ pub fn WriteFile(...@@ -563,8 +563,8 @@ pub fn WriteFile(
563 .InternalHigh = 0,563 .InternalHigh = 0,
564 .DUMMYUNIONNAME = .{564 .DUMMYUNIONNAME = .{
565 .DUMMYSTRUCTNAME = .{565 .DUMMYSTRUCTNAME = .{
566 .Offset = @truncate(u32, off),566 .Offset = @as(u32, @truncate(off)),
567 .OffsetHigh = @truncate(u32, off >> 32),567 .OffsetHigh = @as(u32, @truncate(off >> 32)),
568 },568 },
569 },569 },
570 .hEvent = null,570 .hEvent = null,
...@@ -591,7 +591,7 @@ pub fn WriteFile(...@@ -591,7 +591,7 @@ pub fn WriteFile(
591 if (offset == null) {591 if (offset == null) {
592 // TODO make setting the file position non-blocking592 // TODO make setting the file position non-blocking
593 const new_off = off + bytes_transferred;593 const new_off = off + bytes_transferred;
594 try SetFilePointerEx_CURRENT(handle, @bitCast(i64, new_off));594 try SetFilePointerEx_CURRENT(handle, @as(i64, @bitCast(new_off)));
595 }595 }
596 return bytes_transferred;596 return bytes_transferred;
597 } else {597 } else {
...@@ -603,8 +603,8 @@ pub fn WriteFile(...@@ -603,8 +603,8 @@ pub fn WriteFile(
603 .InternalHigh = 0,603 .InternalHigh = 0,
604 .DUMMYUNIONNAME = .{604 .DUMMYUNIONNAME = .{
605 .DUMMYSTRUCTNAME = .{605 .DUMMYSTRUCTNAME = .{
606 .Offset = @truncate(u32, off),606 .Offset = @as(u32, @truncate(off)),
607 .OffsetHigh = @truncate(u32, off >> 32),607 .OffsetHigh = @as(u32, @truncate(off >> 32)),
608 },608 },
609 },609 },
610 .hEvent = null,610 .hEvent = null,
...@@ -745,19 +745,19 @@ pub fn CreateSymbolicLink(...@@ -745,19 +745,19 @@ pub fn CreateSymbolicLink(
745 const header_len = @sizeOf(ULONG) + @sizeOf(USHORT) * 2;745 const header_len = @sizeOf(ULONG) + @sizeOf(USHORT) * 2;
746 const symlink_data = SYMLINK_DATA{746 const symlink_data = SYMLINK_DATA{
747 .ReparseTag = IO_REPARSE_TAG_SYMLINK,747 .ReparseTag = IO_REPARSE_TAG_SYMLINK,
748 .ReparseDataLength = @intCast(u16, buf_len - header_len),748 .ReparseDataLength = @as(u16, @intCast(buf_len - header_len)),
749 .Reserved = 0,749 .Reserved = 0,
750 .SubstituteNameOffset = @intCast(u16, target_path.len * 2),750 .SubstituteNameOffset = @as(u16, @intCast(target_path.len * 2)),
751 .SubstituteNameLength = @intCast(u16, target_path.len * 2),751 .SubstituteNameLength = @as(u16, @intCast(target_path.len * 2)),
752 .PrintNameOffset = 0,752 .PrintNameOffset = 0,
753 .PrintNameLength = @intCast(u16, target_path.len * 2),753 .PrintNameLength = @as(u16, @intCast(target_path.len * 2)),
754 .Flags = if (dir) |_| SYMLINK_FLAG_RELATIVE else 0,754 .Flags = if (dir) |_| SYMLINK_FLAG_RELATIVE else 0,
755 };755 };
756756
757 @memcpy(buffer[0..@sizeOf(SYMLINK_DATA)], std.mem.asBytes(&symlink_data));757 @memcpy(buffer[0..@sizeOf(SYMLINK_DATA)], std.mem.asBytes(&symlink_data));
758 @memcpy(buffer[@sizeOf(SYMLINK_DATA)..][0 .. target_path.len * 2], @ptrCast([*]const u8, target_path));758 @memcpy(buffer[@sizeOf(SYMLINK_DATA)..][0 .. target_path.len * 2], @as([*]const u8, @ptrCast(target_path)));
759 const paths_start = @sizeOf(SYMLINK_DATA) + target_path.len * 2;759 const paths_start = @sizeOf(SYMLINK_DATA) + target_path.len * 2;
760 @memcpy(buffer[paths_start..][0 .. target_path.len * 2], @ptrCast([*]const u8, target_path));760 @memcpy(buffer[paths_start..][0 .. target_path.len * 2], @as([*]const u8, @ptrCast(target_path)));
761 _ = try DeviceIoControl(symlink_handle, FSCTL_SET_REPARSE_POINT, buffer[0..buf_len], null);761 _ = try DeviceIoControl(symlink_handle, FSCTL_SET_REPARSE_POINT, buffer[0..buf_len], null);
762}762}
763763
...@@ -827,10 +827,10 @@ pub fn ReadLink(dir: ?HANDLE, sub_path_w: []const u16, out_buffer: []u8) ReadLin...@@ -827,10 +827,10 @@ pub fn ReadLink(dir: ?HANDLE, sub_path_w: []const u16, out_buffer: []u8) ReadLin
827 else => |e| return e,827 else => |e| return e,
828 };828 };
829829
830 const reparse_struct = @ptrCast(*const REPARSE_DATA_BUFFER, @alignCast(@alignOf(REPARSE_DATA_BUFFER), &reparse_buf[0]));830 const reparse_struct: *const REPARSE_DATA_BUFFER = @ptrCast(@alignCast(&reparse_buf[0]));
831 switch (reparse_struct.ReparseTag) {831 switch (reparse_struct.ReparseTag) {
832 IO_REPARSE_TAG_SYMLINK => {832 IO_REPARSE_TAG_SYMLINK => {
833 const buf = @ptrCast(*const SYMBOLIC_LINK_REPARSE_BUFFER, @alignCast(@alignOf(SYMBOLIC_LINK_REPARSE_BUFFER), &reparse_struct.DataBuffer[0]));833 const buf: *const SYMBOLIC_LINK_REPARSE_BUFFER = @ptrCast(@alignCast(&reparse_struct.DataBuffer[0]));
834 const offset = buf.SubstituteNameOffset >> 1;834 const offset = buf.SubstituteNameOffset >> 1;
835 const len = buf.SubstituteNameLength >> 1;835 const len = buf.SubstituteNameLength >> 1;
836 const path_buf = @as([*]const u16, &buf.PathBuffer);836 const path_buf = @as([*]const u16, &buf.PathBuffer);
...@@ -838,7 +838,7 @@ pub fn ReadLink(dir: ?HANDLE, sub_path_w: []const u16, out_buffer: []u8) ReadLin...@@ -838,7 +838,7 @@ pub fn ReadLink(dir: ?HANDLE, sub_path_w: []const u16, out_buffer: []u8) ReadLin
838 return parseReadlinkPath(path_buf[offset..][0..len], is_relative, out_buffer);838 return parseReadlinkPath(path_buf[offset..][0..len], is_relative, out_buffer);
839 },839 },
840 IO_REPARSE_TAG_MOUNT_POINT => {840 IO_REPARSE_TAG_MOUNT_POINT => {
841 const buf = @ptrCast(*const MOUNT_POINT_REPARSE_BUFFER, @alignCast(@alignOf(MOUNT_POINT_REPARSE_BUFFER), &reparse_struct.DataBuffer[0]));841 const buf: *const MOUNT_POINT_REPARSE_BUFFER = @ptrCast(@alignCast(&reparse_struct.DataBuffer[0]));
842 const offset = buf.SubstituteNameOffset >> 1;842 const offset = buf.SubstituteNameOffset >> 1;
843 const len = buf.SubstituteNameLength >> 1;843 const len = buf.SubstituteNameLength >> 1;
844 const path_buf = @as([*]const u16, &buf.PathBuffer);844 const path_buf = @as([*]const u16, &buf.PathBuffer);
...@@ -884,7 +884,7 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil...@@ -884,7 +884,7 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil
884 else884 else
885 FILE_NON_DIRECTORY_FILE | FILE_OPEN_REPARSE_POINT; // would we ever want to delete the target instead?885 FILE_NON_DIRECTORY_FILE | FILE_OPEN_REPARSE_POINT; // would we ever want to delete the target instead?
886886
887 const path_len_bytes = @intCast(u16, sub_path_w.len * 2);887 const path_len_bytes = @as(u16, @intCast(sub_path_w.len * 2));
888 var nt_name = UNICODE_STRING{888 var nt_name = UNICODE_STRING{
889 .Length = path_len_bytes,889 .Length = path_len_bytes,
890 .MaximumLength = path_len_bytes,890 .MaximumLength = path_len_bytes,
...@@ -1020,7 +1020,7 @@ pub fn SetFilePointerEx_BEGIN(handle: HANDLE, offset: u64) SetFilePointerError!v...@@ -1020,7 +1020,7 @@ pub fn SetFilePointerEx_BEGIN(handle: HANDLE, offset: u64) SetFilePointerError!v
1020 // "The starting point is zero or the beginning of the file. If [FILE_BEGIN]1020 // "The starting point is zero or the beginning of the file. If [FILE_BEGIN]
1021 // is specified, then the liDistanceToMove parameter is interpreted as an unsigned value."1021 // is specified, then the liDistanceToMove parameter is interpreted as an unsigned value."
1022 // https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-setfilepointerex1022 // https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-setfilepointerex
1023 const ipos = @bitCast(LARGE_INTEGER, offset);1023 const ipos = @as(LARGE_INTEGER, @bitCast(offset));
1024 if (kernel32.SetFilePointerEx(handle, ipos, null, FILE_BEGIN) == 0) {1024 if (kernel32.SetFilePointerEx(handle, ipos, null, FILE_BEGIN) == 0) {
1025 switch (kernel32.GetLastError()) {1025 switch (kernel32.GetLastError()) {
1026 .INVALID_PARAMETER => unreachable,1026 .INVALID_PARAMETER => unreachable,
...@@ -1064,7 +1064,7 @@ pub fn SetFilePointerEx_CURRENT_get(handle: HANDLE) SetFilePointerError!u64 {...@@ -1064,7 +1064,7 @@ pub fn SetFilePointerEx_CURRENT_get(handle: HANDLE) SetFilePointerError!u64 {
1064 }1064 }
1065 // Based on the docs for FILE_BEGIN, it seems that the returned signed integer1065 // Based on the docs for FILE_BEGIN, it seems that the returned signed integer
1066 // should be interpreted as an unsigned integer.1066 // should be interpreted as an unsigned integer.
1067 return @bitCast(u64, result);1067 return @as(u64, @bitCast(result));
1068}1068}
10691069
1070pub fn QueryObjectName(1070pub fn QueryObjectName(
...@@ -1073,7 +1073,7 @@ pub fn QueryObjectName(...@@ -1073,7 +1073,7 @@ pub fn QueryObjectName(
1073) ![]u16 {1073) ![]u16 {
1074 const out_buffer_aligned = mem.alignInSlice(out_buffer, @alignOf(OBJECT_NAME_INFORMATION)) orelse return error.NameTooLong;1074 const out_buffer_aligned = mem.alignInSlice(out_buffer, @alignOf(OBJECT_NAME_INFORMATION)) orelse return error.NameTooLong;
10751075
1076 const info = @ptrCast(*OBJECT_NAME_INFORMATION, out_buffer_aligned);1076 const info = @as(*OBJECT_NAME_INFORMATION, @ptrCast(out_buffer_aligned));
1077 //buffer size is specified in bytes1077 //buffer size is specified in bytes
1078 const out_buffer_len = std.math.cast(ULONG, out_buffer_aligned.len * 2) orelse std.math.maxInt(ULONG);1078 const out_buffer_len = std.math.cast(ULONG, out_buffer_aligned.len * 2) orelse std.math.maxInt(ULONG);
1079 //last argument would return the length required for full_buffer, not exposed here1079 //last argument would return the length required for full_buffer, not exposed here
...@@ -1197,26 +1197,26 @@ pub fn GetFinalPathNameByHandle(...@@ -1197,26 +1197,26 @@ pub fn GetFinalPathNameByHandle(
1197 };1197 };
1198 defer CloseHandle(mgmt_handle);1198 defer CloseHandle(mgmt_handle);
11991199
1200 var input_struct = @ptrCast(*MOUNTMGR_MOUNT_POINT, &input_buf[0]);1200 var input_struct = @as(*MOUNTMGR_MOUNT_POINT, @ptrCast(&input_buf[0]));
1201 input_struct.DeviceNameOffset = @sizeOf(MOUNTMGR_MOUNT_POINT);1201 input_struct.DeviceNameOffset = @sizeOf(MOUNTMGR_MOUNT_POINT);
1202 input_struct.DeviceNameLength = @intCast(USHORT, volume_name_u16.len * 2);1202 input_struct.DeviceNameLength = @as(USHORT, @intCast(volume_name_u16.len * 2));
1203 @memcpy(input_buf[@sizeOf(MOUNTMGR_MOUNT_POINT)..][0 .. volume_name_u16.len * 2], @ptrCast([*]const u8, volume_name_u16.ptr));1203 @memcpy(input_buf[@sizeOf(MOUNTMGR_MOUNT_POINT)..][0 .. volume_name_u16.len * 2], @as([*]const u8, @ptrCast(volume_name_u16.ptr)));
12041204
1205 DeviceIoControl(mgmt_handle, IOCTL_MOUNTMGR_QUERY_POINTS, &input_buf, &output_buf) catch |err| switch (err) {1205 DeviceIoControl(mgmt_handle, IOCTL_MOUNTMGR_QUERY_POINTS, &input_buf, &output_buf) catch |err| switch (err) {
1206 error.AccessDenied => unreachable,1206 error.AccessDenied => unreachable,
1207 else => |e| return e,1207 else => |e| return e,
1208 };1208 };
1209 const mount_points_struct = @ptrCast(*const MOUNTMGR_MOUNT_POINTS, &output_buf[0]);1209 const mount_points_struct = @as(*const MOUNTMGR_MOUNT_POINTS, @ptrCast(&output_buf[0]));
12101210
1211 const mount_points = @ptrCast(1211 const mount_points = @as(
1212 [*]const MOUNTMGR_MOUNT_POINT,1212 [*]const MOUNTMGR_MOUNT_POINT,
1213 &mount_points_struct.MountPoints[0],1213 @ptrCast(&mount_points_struct.MountPoints[0]),
1214 )[0..mount_points_struct.NumberOfMountPoints];1214 )[0..mount_points_struct.NumberOfMountPoints];
12151215
1216 for (mount_points) |mount_point| {1216 for (mount_points) |mount_point| {
1217 const symlink = @ptrCast(1217 const symlink = @as(
1218 [*]const u16,1218 [*]const u16,
1219 @alignCast(@alignOf(u16), &output_buf[mount_point.SymbolicLinkNameOffset]),1219 @ptrCast(@alignCast(&output_buf[mount_point.SymbolicLinkNameOffset])),
1220 )[0 .. mount_point.SymbolicLinkNameLength / 2];1220 )[0 .. mount_point.SymbolicLinkNameLength / 2];
12211221
1222 // Look for `\DosDevices\` prefix. We don't really care if there are more than one symlinks1222 // Look for `\DosDevices\` prefix. We don't really care if there are more than one symlinks
...@@ -1282,7 +1282,7 @@ pub fn GetFileSizeEx(hFile: HANDLE) GetFileSizeError!u64 {...@@ -1282,7 +1282,7 @@ pub fn GetFileSizeEx(hFile: HANDLE) GetFileSizeError!u64 {
1282 else => |err| return unexpectedError(err),1282 else => |err| return unexpectedError(err),
1283 }1283 }
1284 }1284 }
1285 return @bitCast(u64, file_size);1285 return @as(u64, @bitCast(file_size));
1286}1286}
12871287
1288pub const GetFileAttributesError = error{1288pub const GetFileAttributesError = error{
...@@ -1313,7 +1313,7 @@ pub fn WSAStartup(majorVersion: u8, minorVersion: u8) !ws2_32.WSADATA {...@@ -1313,7 +1313,7 @@ pub fn WSAStartup(majorVersion: u8, minorVersion: u8) !ws2_32.WSADATA {
1313 var wsadata: ws2_32.WSADATA = undefined;1313 var wsadata: ws2_32.WSADATA = undefined;
1314 return switch (ws2_32.WSAStartup((@as(WORD, minorVersion) << 8) | majorVersion, &wsadata)) {1314 return switch (ws2_32.WSAStartup((@as(WORD, minorVersion) << 8) | majorVersion, &wsadata)) {
1315 0 => wsadata,1315 0 => wsadata,
1316 else => |err_int| switch (@enumFromInt(ws2_32.WinsockError, @intCast(u16, err_int))) {1316 else => |err_int| switch (@as(ws2_32.WinsockError, @enumFromInt(@as(u16, @intCast(err_int))))) {
1317 .WSASYSNOTREADY => return error.SystemNotAvailable,1317 .WSASYSNOTREADY => return error.SystemNotAvailable,
1318 .WSAVERNOTSUPPORTED => return error.VersionNotSupported,1318 .WSAVERNOTSUPPORTED => return error.VersionNotSupported,
1319 .WSAEINPROGRESS => return error.BlockingOperationInProgress,1319 .WSAEINPROGRESS => return error.BlockingOperationInProgress,
...@@ -1408,7 +1408,7 @@ pub fn WSASocketW(...@@ -1408,7 +1408,7 @@ pub fn WSASocketW(
1408}1408}
14091409
1410pub fn bind(s: ws2_32.SOCKET, name: *const ws2_32.sockaddr, namelen: ws2_32.socklen_t) i32 {1410pub fn bind(s: ws2_32.SOCKET, name: *const ws2_32.sockaddr, namelen: ws2_32.socklen_t) i32 {
1411 return ws2_32.bind(s, name, @intCast(i32, namelen));1411 return ws2_32.bind(s, name, @as(i32, @intCast(namelen)));
1412}1412}
14131413
1414pub fn listen(s: ws2_32.SOCKET, backlog: u31) i32 {1414pub fn listen(s: ws2_32.SOCKET, backlog: u31) i32 {
...@@ -1427,15 +1427,15 @@ pub fn closesocket(s: ws2_32.SOCKET) !void {...@@ -1427,15 +1427,15 @@ pub fn closesocket(s: ws2_32.SOCKET) !void {
14271427
1428pub fn accept(s: ws2_32.SOCKET, name: ?*ws2_32.sockaddr, namelen: ?*ws2_32.socklen_t) ws2_32.SOCKET {1428pub fn accept(s: ws2_32.SOCKET, name: ?*ws2_32.sockaddr, namelen: ?*ws2_32.socklen_t) ws2_32.SOCKET {
1429 assert((name == null) == (namelen == null));1429 assert((name == null) == (namelen == null));
1430 return ws2_32.accept(s, name, @ptrCast(?*i32, namelen));1430 return ws2_32.accept(s, name, @as(?*i32, @ptrCast(namelen)));
1431}1431}
14321432
1433pub fn getsockname(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.socklen_t) i32 {1433pub fn getsockname(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.socklen_t) i32 {
1434 return ws2_32.getsockname(s, name, @ptrCast(*i32, namelen));1434 return ws2_32.getsockname(s, name, @as(*i32, @ptrCast(namelen)));
1435}1435}
14361436
1437pub fn getpeername(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.socklen_t) i32 {1437pub fn getpeername(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.socklen_t) i32 {
1438 return ws2_32.getpeername(s, name, @ptrCast(*i32, namelen));1438 return ws2_32.getpeername(s, name, @as(*i32, @ptrCast(namelen)));
1439}1439}
14401440
1441pub fn sendmsg(1441pub fn sendmsg(
...@@ -1447,28 +1447,28 @@ pub fn sendmsg(...@@ -1447,28 +1447,28 @@ pub fn sendmsg(
1447 if (ws2_32.WSASendMsg(s, msg, flags, &bytes_send, null, null) == ws2_32.SOCKET_ERROR) {1447 if (ws2_32.WSASendMsg(s, msg, flags, &bytes_send, null, null) == ws2_32.SOCKET_ERROR) {
1448 return ws2_32.SOCKET_ERROR;1448 return ws2_32.SOCKET_ERROR;
1449 } else {1449 } else {
1450 return @as(i32, @intCast(u31, bytes_send));1450 return @as(i32, @as(u31, @intCast(bytes_send)));
1451 }1451 }
1452}1452}
14531453
1454pub fn sendto(s: ws2_32.SOCKET, buf: [*]const u8, len: usize, flags: u32, to: ?*const ws2_32.sockaddr, to_len: ws2_32.socklen_t) i32 {1454pub fn sendto(s: ws2_32.SOCKET, buf: [*]const u8, len: usize, flags: u32, to: ?*const ws2_32.sockaddr, to_len: ws2_32.socklen_t) i32 {
1455 var buffer = ws2_32.WSABUF{ .len = @truncate(u31, len), .buf = @constCast(buf) };1455 var buffer = ws2_32.WSABUF{ .len = @as(u31, @truncate(len)), .buf = @constCast(buf) };
1456 var bytes_send: DWORD = undefined;1456 var bytes_send: DWORD = undefined;
1457 if (ws2_32.WSASendTo(s, @ptrCast([*]ws2_32.WSABUF, &buffer), 1, &bytes_send, flags, to, @intCast(i32, to_len), null, null) == ws2_32.SOCKET_ERROR) {1457 if (ws2_32.WSASendTo(s, @as([*]ws2_32.WSABUF, @ptrCast(&buffer)), 1, &bytes_send, flags, to, @as(i32, @intCast(to_len)), null, null) == ws2_32.SOCKET_ERROR) {
1458 return ws2_32.SOCKET_ERROR;1458 return ws2_32.SOCKET_ERROR;
1459 } else {1459 } else {
1460 return @as(i32, @intCast(u31, bytes_send));1460 return @as(i32, @as(u31, @intCast(bytes_send)));
1461 }1461 }
1462}1462}
14631463
1464pub fn recvfrom(s: ws2_32.SOCKET, buf: [*]u8, len: usize, flags: u32, from: ?*ws2_32.sockaddr, from_len: ?*ws2_32.socklen_t) i32 {1464pub fn recvfrom(s: ws2_32.SOCKET, buf: [*]u8, len: usize, flags: u32, from: ?*ws2_32.sockaddr, from_len: ?*ws2_32.socklen_t) i32 {
1465 var buffer = ws2_32.WSABUF{ .len = @truncate(u31, len), .buf = buf };1465 var buffer = ws2_32.WSABUF{ .len = @as(u31, @truncate(len)), .buf = buf };
1466 var bytes_received: DWORD = undefined;1466 var bytes_received: DWORD = undefined;
1467 var flags_inout = flags;1467 var flags_inout = flags;
1468 if (ws2_32.WSARecvFrom(s, @ptrCast([*]ws2_32.WSABUF, &buffer), 1, &bytes_received, &flags_inout, from, @ptrCast(?*i32, from_len), null, null) == ws2_32.SOCKET_ERROR) {1468 if (ws2_32.WSARecvFrom(s, @as([*]ws2_32.WSABUF, @ptrCast(&buffer)), 1, &bytes_received, &flags_inout, from, @as(?*i32, @ptrCast(from_len)), null, null) == ws2_32.SOCKET_ERROR) {
1469 return ws2_32.SOCKET_ERROR;1469 return ws2_32.SOCKET_ERROR;
1470 } else {1470 } else {
1471 return @as(i32, @intCast(u31, bytes_received));1471 return @as(i32, @as(u31, @intCast(bytes_received)));
1472 }1472 }
1473}1473}
14741474
...@@ -1489,9 +1489,9 @@ pub fn WSAIoctl(...@@ -1489,9 +1489,9 @@ pub fn WSAIoctl(
1489 s,1489 s,
1490 dwIoControlCode,1490 dwIoControlCode,
1491 if (inBuffer) |i| i.ptr else null,1491 if (inBuffer) |i| i.ptr else null,
1492 if (inBuffer) |i| @intCast(DWORD, i.len) else 0,1492 if (inBuffer) |i| @as(DWORD, @intCast(i.len)) else 0,
1493 outBuffer.ptr,1493 outBuffer.ptr,
1494 @intCast(DWORD, outBuffer.len),1494 @as(DWORD, @intCast(outBuffer.len)),
1495 &bytes,1495 &bytes,
1496 overlapped,1496 overlapped,
1497 completionRoutine,1497 completionRoutine,
...@@ -1741,7 +1741,7 @@ pub fn QueryPerformanceFrequency() u64 {...@@ -1741,7 +1741,7 @@ pub fn QueryPerformanceFrequency() u64 {
1741 var result: LARGE_INTEGER = undefined;1741 var result: LARGE_INTEGER = undefined;
1742 assert(kernel32.QueryPerformanceFrequency(&result) != 0);1742 assert(kernel32.QueryPerformanceFrequency(&result) != 0);
1743 // The kernel treats this integer as unsigned.1743 // The kernel treats this integer as unsigned.
1744 return @bitCast(u64, result);1744 return @as(u64, @bitCast(result));
1745}1745}
17461746
1747pub fn QueryPerformanceCounter() u64 {1747pub fn QueryPerformanceCounter() u64 {
...@@ -1750,7 +1750,7 @@ pub fn QueryPerformanceCounter() u64 {...@@ -1750,7 +1750,7 @@ pub fn QueryPerformanceCounter() u64 {
1750 var result: LARGE_INTEGER = undefined;1750 var result: LARGE_INTEGER = undefined;
1751 assert(kernel32.QueryPerformanceCounter(&result) != 0);1751 assert(kernel32.QueryPerformanceCounter(&result) != 0);
1752 // The kernel treats this integer as unsigned.1752 // The kernel treats this integer as unsigned.
1753 return @bitCast(u64, result);1753 return @as(u64, @bitCast(result));
1754}1754}
17551755
1756pub fn InitOnceExecuteOnce(InitOnce: *INIT_ONCE, InitFn: INIT_ONCE_FN, Parameter: ?*anyopaque, Context: ?*anyopaque) void {1756pub fn InitOnceExecuteOnce(InitOnce: *INIT_ONCE, InitFn: INIT_ONCE_FN, Parameter: ?*anyopaque, Context: ?*anyopaque) void {
...@@ -1852,7 +1852,7 @@ pub fn teb() *TEB {...@@ -1852,7 +1852,7 @@ pub fn teb() *TEB {
1852 return switch (native_arch) {1852 return switch (native_arch) {
1853 .x86 => blk: {1853 .x86 => blk: {
1854 if (builtin.zig_backend == .stage2_c) {1854 if (builtin.zig_backend == .stage2_c) {
1855 break :blk @ptrCast(*TEB, @alignCast(@alignOf(TEB), zig_x86_windows_teb()));1855 break :blk @ptrCast(@alignCast(zig_x86_windows_teb()));
1856 } else {1856 } else {
1857 break :blk asm volatile (1857 break :blk asm volatile (
1858 \\ movl %%fs:0x18, %[ptr]1858 \\ movl %%fs:0x18, %[ptr]
...@@ -1862,7 +1862,7 @@ pub fn teb() *TEB {...@@ -1862,7 +1862,7 @@ pub fn teb() *TEB {
1862 },1862 },
1863 .x86_64 => blk: {1863 .x86_64 => blk: {
1864 if (builtin.zig_backend == .stage2_c) {1864 if (builtin.zig_backend == .stage2_c) {
1865 break :blk @ptrCast(*TEB, @alignCast(@alignOf(TEB), zig_x86_64_windows_teb()));1865 break :blk @ptrCast(@alignCast(zig_x86_64_windows_teb()));
1866 } else {1866 } else {
1867 break :blk asm volatile (1867 break :blk asm volatile (
1868 \\ movq %%gs:0x30, %[ptr]1868 \\ movq %%gs:0x30, %[ptr]
...@@ -1894,7 +1894,7 @@ pub fn fromSysTime(hns: i64) i128 {...@@ -1894,7 +1894,7 @@ pub fn fromSysTime(hns: i64) i128 {
18941894
1895pub fn toSysTime(ns: i128) i64 {1895pub fn toSysTime(ns: i128) i64 {
1896 const hns = @divFloor(ns, 100);1896 const hns = @divFloor(ns, 100);
1897 return @intCast(i64, hns) - std.time.epoch.windows * (std.time.ns_per_s / 100);1897 return @as(i64, @intCast(hns)) - std.time.epoch.windows * (std.time.ns_per_s / 100);
1898}1898}
18991899
1900pub fn fileTimeToNanoSeconds(ft: FILETIME) i128 {1900pub fn fileTimeToNanoSeconds(ft: FILETIME) i128 {
...@@ -1904,22 +1904,22 @@ pub fn fileTimeToNanoSeconds(ft: FILETIME) i128 {...@@ -1904,22 +1904,22 @@ pub fn fileTimeToNanoSeconds(ft: FILETIME) i128 {
19041904
1905/// Converts a number of nanoseconds since the POSIX epoch to a Windows FILETIME.1905/// Converts a number of nanoseconds since the POSIX epoch to a Windows FILETIME.
1906pub fn nanoSecondsToFileTime(ns: i128) FILETIME {1906pub fn nanoSecondsToFileTime(ns: i128) FILETIME {
1907 const adjusted = @bitCast(u64, toSysTime(ns));1907 const adjusted = @as(u64, @bitCast(toSysTime(ns)));
1908 return FILETIME{1908 return FILETIME{
1909 .dwHighDateTime = @truncate(u32, adjusted >> 32),1909 .dwHighDateTime = @as(u32, @truncate(adjusted >> 32)),
1910 .dwLowDateTime = @truncate(u32, adjusted),1910 .dwLowDateTime = @as(u32, @truncate(adjusted)),
1911 };1911 };
1912}1912}
19131913
1914/// Compares two WTF16 strings using RtlEqualUnicodeString1914/// Compares two WTF16 strings using RtlEqualUnicodeString
1915pub fn eqlIgnoreCaseWTF16(a: []const u16, b: []const u16) bool {1915pub fn eqlIgnoreCaseWTF16(a: []const u16, b: []const u16) bool {
1916 const a_bytes = @intCast(u16, a.len * 2);1916 const a_bytes = @as(u16, @intCast(a.len * 2));
1917 const a_string = UNICODE_STRING{1917 const a_string = UNICODE_STRING{
1918 .Length = a_bytes,1918 .Length = a_bytes,
1919 .MaximumLength = a_bytes,1919 .MaximumLength = a_bytes,
1920 .Buffer = @constCast(a.ptr),1920 .Buffer = @constCast(a.ptr),
1921 };1921 };
1922 const b_bytes = @intCast(u16, b.len * 2);1922 const b_bytes = @as(u16, @intCast(b.len * 2));
1923 const b_string = UNICODE_STRING{1923 const b_string = UNICODE_STRING{
1924 .Length = b_bytes,1924 .Length = b_bytes,
1925 .MaximumLength = b_bytes,1925 .MaximumLength = b_bytes,
...@@ -2117,7 +2117,7 @@ pub fn wToPrefixedFileW(path: [:0]const u16) !PathSpace {...@@ -2117,7 +2117,7 @@ pub fn wToPrefixedFileW(path: [:0]const u16) !PathSpace {
2117 .unc_absolute => nt_prefix.len + 2,2117 .unc_absolute => nt_prefix.len + 2,
2118 else => nt_prefix.len,2118 else => nt_prefix.len,
2119 };2119 };
2120 const buf_len = @intCast(u32, path_space.data.len - path_buf_offset);2120 const buf_len = @as(u32, @intCast(path_space.data.len - path_buf_offset));
2121 const path_byte_len = ntdll.RtlGetFullPathName_U(2121 const path_byte_len = ntdll.RtlGetFullPathName_U(
2122 path.ptr,2122 path.ptr,
2123 buf_len * 2,2123 buf_len * 2,
...@@ -2263,7 +2263,7 @@ test getUnprefixedPathType {...@@ -2263,7 +2263,7 @@ test getUnprefixedPathType {
2263}2263}
22642264
2265fn getFullPathNameW(path: [*:0]const u16, out: []u16) !usize {2265fn getFullPathNameW(path: [*:0]const u16, out: []u16) !usize {
2266 const result = kernel32.GetFullPathNameW(path, @intCast(u32, out.len), out.ptr, null);2266 const result = kernel32.GetFullPathNameW(path, @as(u32, @intCast(out.len)), out.ptr, null);
2267 if (result == 0) {2267 if (result == 0) {
2268 switch (kernel32.GetLastError()) {2268 switch (kernel32.GetLastError()) {
2269 else => |err| return unexpectedError(err),2269 else => |err| return unexpectedError(err),
...@@ -2284,9 +2284,9 @@ pub fn loadWinsockExtensionFunction(comptime T: type, sock: ws2_32.SOCKET, guid:...@@ -2284,9 +2284,9 @@ pub fn loadWinsockExtensionFunction(comptime T: type, sock: ws2_32.SOCKET, guid:
2284 const rc = ws2_32.WSAIoctl(2284 const rc = ws2_32.WSAIoctl(
2285 sock,2285 sock,
2286 ws2_32.SIO_GET_EXTENSION_FUNCTION_POINTER,2286 ws2_32.SIO_GET_EXTENSION_FUNCTION_POINTER,
2287 @ptrCast(*const anyopaque, &guid),2287 @as(*const anyopaque, @ptrCast(&guid)),
2288 @sizeOf(GUID),2288 @sizeOf(GUID),
2289 @ptrFromInt(?*anyopaque, @intFromPtr(&function)),2289 @as(?*anyopaque, @ptrFromInt(@intFromPtr(&function))),
2290 @sizeOf(T),2290 @sizeOf(T),
2291 &num_bytes,2291 &num_bytes,
2292 null,2292 null,
...@@ -2332,7 +2332,7 @@ pub fn unexpectedError(err: Win32Error) std.os.UnexpectedError {...@@ -2332,7 +2332,7 @@ pub fn unexpectedError(err: Win32Error) std.os.UnexpectedError {
2332}2332}
23332333
2334pub fn unexpectedWSAError(err: ws2_32.WinsockError) std.os.UnexpectedError {2334pub fn unexpectedWSAError(err: ws2_32.WinsockError) std.os.UnexpectedError {
2335 return unexpectedError(@enumFromInt(Win32Error, @intFromEnum(err)));2335 return unexpectedError(@as(Win32Error, @enumFromInt(@intFromEnum(err))));
2336}2336}
23372337
2338/// Call this when you made a windows NtDll call2338/// Call this when you made a windows NtDll call
...@@ -2530,7 +2530,7 @@ pub fn CTL_CODE(deviceType: u16, function: u12, method: TransferType, access: u2...@@ -2530,7 +2530,7 @@ pub fn CTL_CODE(deviceType: u16, function: u12, method: TransferType, access: u2
2530 @intFromEnum(method);2530 @intFromEnum(method);
2531}2531}
25322532
2533pub const INVALID_HANDLE_VALUE = @ptrFromInt(HANDLE, maxInt(usize));2533pub const INVALID_HANDLE_VALUE = @as(HANDLE, @ptrFromInt(maxInt(usize)));
25342534
2535pub const INVALID_FILE_ATTRIBUTES = @as(DWORD, maxInt(DWORD));2535pub const INVALID_FILE_ATTRIBUTES = @as(DWORD, maxInt(DWORD));
25362536
...@@ -3119,7 +3119,7 @@ pub const GUID = extern struct {...@@ -3119,7 +3119,7 @@ pub const GUID = extern struct {
3119 bytes[i] = (try std.fmt.charToDigit(s[hex_offset], 16)) << 4 |3119 bytes[i] = (try std.fmt.charToDigit(s[hex_offset], 16)) << 4 |
3120 try std.fmt.charToDigit(s[hex_offset + 1], 16);3120 try std.fmt.charToDigit(s[hex_offset + 1], 16);
3121 }3121 }
3122 return @bitCast(GUID, bytes);3122 return @as(GUID, @bitCast(bytes));
3123 }3123 }
3124};3124};
31253125
...@@ -3150,16 +3150,16 @@ pub const KF_FLAG_SIMPLE_IDLIST = 256;...@@ -3150,16 +3150,16 @@ pub const KF_FLAG_SIMPLE_IDLIST = 256;
3150pub const KF_FLAG_ALIAS_ONLY = -2147483648;3150pub const KF_FLAG_ALIAS_ONLY = -2147483648;
31513151
3152pub const S_OK = 0;3152pub const S_OK = 0;
3153pub const E_NOTIMPL = @bitCast(c_long, @as(c_ulong, 0x80004001));3153pub const E_NOTIMPL = @as(c_long, @bitCast(@as(c_ulong, 0x80004001)));
3154pub const E_NOINTERFACE = @bitCast(c_long, @as(c_ulong, 0x80004002));3154pub const E_NOINTERFACE = @as(c_long, @bitCast(@as(c_ulong, 0x80004002)));
3155pub const E_POINTER = @bitCast(c_long, @as(c_ulong, 0x80004003));3155pub const E_POINTER = @as(c_long, @bitCast(@as(c_ulong, 0x80004003)));
3156pub const E_ABORT = @bitCast(c_long, @as(c_ulong, 0x80004004));3156pub const E_ABORT = @as(c_long, @bitCast(@as(c_ulong, 0x80004004)));
3157pub const E_FAIL = @bitCast(c_long, @as(c_ulong, 0x80004005));3157pub const E_FAIL = @as(c_long, @bitCast(@as(c_ulong, 0x80004005)));
3158pub const E_UNEXPECTED = @bitCast(c_long, @as(c_ulong, 0x8000FFFF));3158pub const E_UNEXPECTED = @as(c_long, @bitCast(@as(c_ulong, 0x8000FFFF)));
3159pub const E_ACCESSDENIED = @bitCast(c_long, @as(c_ulong, 0x80070005));3159pub const E_ACCESSDENIED = @as(c_long, @bitCast(@as(c_ulong, 0x80070005)));
3160pub const E_HANDLE = @bitCast(c_long, @as(c_ulong, 0x80070006));3160pub const E_HANDLE = @as(c_long, @bitCast(@as(c_ulong, 0x80070006)));
3161pub const E_OUTOFMEMORY = @bitCast(c_long, @as(c_ulong, 0x8007000E));3161pub const E_OUTOFMEMORY = @as(c_long, @bitCast(@as(c_ulong, 0x8007000E)));
3162pub const E_INVALIDARG = @bitCast(c_long, @as(c_ulong, 0x80070057));3162pub const E_INVALIDARG = @as(c_long, @bitCast(@as(c_ulong, 0x80070057)));
31633163
3164pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;3164pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
3165pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000;3165pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000;
...@@ -3221,7 +3221,7 @@ pub const LSTATUS = LONG;...@@ -3221,7 +3221,7 @@ pub const LSTATUS = LONG;
32213221
3222pub const HKEY = *opaque {};3222pub const HKEY = *opaque {};
32233223
3224pub const HKEY_LOCAL_MACHINE: HKEY = @ptrFromInt(HKEY, 0x80000002);3224pub const HKEY_LOCAL_MACHINE: HKEY = @as(HKEY, @ptrFromInt(0x80000002));
32253225
3226/// Combines the STANDARD_RIGHTS_REQUIRED, KEY_QUERY_VALUE, KEY_SET_VALUE, KEY_CREATE_SUB_KEY,3226/// Combines the STANDARD_RIGHTS_REQUIRED, KEY_QUERY_VALUE, KEY_SET_VALUE, KEY_CREATE_SUB_KEY,
3227/// KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY, and KEY_CREATE_LINK access rights.3227/// KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY, and KEY_CREATE_LINK access rights.
...@@ -4685,7 +4685,7 @@ pub const KUSER_SHARED_DATA = extern struct {...@@ -4685,7 +4685,7 @@ pub const KUSER_SHARED_DATA = extern struct {
4685/// Read-only user-mode address for the shared data.4685/// Read-only user-mode address for the shared data.
4686/// https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/ntexapi_x/kuser_shared_data/index.htm4686/// https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/ntexapi_x/kuser_shared_data/index.htm
4687/// https://msrc-blog.microsoft.com/2022/04/05/randomizing-the-kuser_shared_data-structure-on-windows/4687/// https://msrc-blog.microsoft.com/2022/04/05/randomizing-the-kuser_shared_data-structure-on-windows/
4688pub const SharedUserData: *const KUSER_SHARED_DATA = @ptrFromInt(*const KUSER_SHARED_DATA, 0x7FFE0000);4688pub const SharedUserData: *const KUSER_SHARED_DATA = @as(*const KUSER_SHARED_DATA, @ptrFromInt(0x7FFE0000));
46894689
4690pub fn IsProcessorFeaturePresent(feature: PF) bool {4690pub fn IsProcessorFeaturePresent(feature: PF) bool {
4691 if (@intFromEnum(feature) >= PROCESSOR_FEATURE_MAX) return false;4691 if (@intFromEnum(feature) >= PROCESSOR_FEATURE_MAX) return false;
...@@ -4886,7 +4886,7 @@ pub fn WriteProcessMemory(handle: HANDLE, addr: ?LPVOID, buffer: []const u8) Wri...@@ -4886,7 +4886,7 @@ pub fn WriteProcessMemory(handle: HANDLE, addr: ?LPVOID, buffer: []const u8) Wri
4886 switch (ntdll.NtWriteVirtualMemory(4886 switch (ntdll.NtWriteVirtualMemory(
4887 handle,4887 handle,
4888 addr,4888 addr,
4889 @ptrCast(*const anyopaque, buffer.ptr),4889 @as(*const anyopaque, @ptrCast(buffer.ptr)),
4890 buffer.len,4890 buffer.len,
4891 &nwritten,4891 &nwritten,
4892 )) {4892 )) {
...@@ -4919,6 +4919,6 @@ pub fn ProcessBaseAddress(handle: HANDLE) ProcessBaseAddressError!HMODULE {...@@ -4919,6 +4919,6 @@ pub fn ProcessBaseAddress(handle: HANDLE) ProcessBaseAddressError!HMODULE {
49194919
4920 var peb_buf: [@sizeOf(PEB)]u8 align(@alignOf(PEB)) = undefined;4920 var peb_buf: [@sizeOf(PEB)]u8 align(@alignOf(PEB)) = undefined;
4921 const peb_out = try ReadProcessMemory(handle, info.PebBaseAddress, &peb_buf);4921 const peb_out = try ReadProcessMemory(handle, info.PebBaseAddress, &peb_buf);
4922 const ppeb = @ptrCast(*const PEB, @alignCast(@alignOf(PEB), peb_out.ptr));4922 const ppeb: *const PEB = @ptrCast(@alignCast(peb_out.ptr));
4923 return ppeb.ImageBaseAddress;4923 return ppeb.ImageBaseAddress;
4924}4924}
lib/std/os/windows/user32.zig+1-1
...@@ -1275,7 +1275,7 @@ pub const WS_EX_LAYERED = 0x00080000;...@@ -1275,7 +1275,7 @@ pub const WS_EX_LAYERED = 0x00080000;
1275pub const WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE;1275pub const WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE;
1276pub const WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST;1276pub const WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
12771277
1278pub const CW_USEDEFAULT = @bitCast(i32, @as(u32, 0x80000000));1278pub const CW_USEDEFAULT = @as(i32, @bitCast(@as(u32, 0x80000000)));
12791279
1280pub 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;1280pub 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;
1281pub 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 {1281pub 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/os/windows/ws2_32.zig+1-1
...@@ -21,7 +21,7 @@ const LPARAM = windows.LPARAM;...@@ -21,7 +21,7 @@ const LPARAM = windows.LPARAM;
21const FARPROC = windows.FARPROC;21const FARPROC = windows.FARPROC;
2222
23pub const SOCKET = *opaque {};23pub const SOCKET = *opaque {};
24pub const INVALID_SOCKET = @ptrFromInt(SOCKET, ~@as(usize, 0));24pub const INVALID_SOCKET = @as(SOCKET, @ptrFromInt(~@as(usize, 0)));
2525
26pub const GROUP = u32;26pub const GROUP = u32;
27pub const ADDRESS_FAMILY = u16;27pub const ADDRESS_FAMILY = u16;
lib/std/packed_int_array.zig+16-16
...@@ -73,25 +73,25 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {...@@ -73,25 +73,25 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {
73 const tail_keep_bits = container_bits - (int_bits + head_keep_bits);73 const tail_keep_bits = container_bits - (int_bits + head_keep_bits);
7474
75 //read bytes as container75 //read bytes as container
76 const value_ptr = @ptrCast(*align(1) const Container, &bytes[start_byte]);76 const value_ptr = @as(*align(1) const Container, @ptrCast(&bytes[start_byte]));
77 var value = value_ptr.*;77 var value = value_ptr.*;
7878
79 if (endian != native_endian) value = @byteSwap(value);79 if (endian != native_endian) value = @byteSwap(value);
8080
81 switch (endian) {81 switch (endian) {
82 .Big => {82 .Big => {
83 value <<= @intCast(Shift, head_keep_bits);83 value <<= @as(Shift, @intCast(head_keep_bits));
84 value >>= @intCast(Shift, head_keep_bits);84 value >>= @as(Shift, @intCast(head_keep_bits));
85 value >>= @intCast(Shift, tail_keep_bits);85 value >>= @as(Shift, @intCast(tail_keep_bits));
86 },86 },
87 .Little => {87 .Little => {
88 value <<= @intCast(Shift, tail_keep_bits);88 value <<= @as(Shift, @intCast(tail_keep_bits));
89 value >>= @intCast(Shift, tail_keep_bits);89 value >>= @as(Shift, @intCast(tail_keep_bits));
90 value >>= @intCast(Shift, head_keep_bits);90 value >>= @as(Shift, @intCast(head_keep_bits));
91 },91 },
92 }92 }
9393
94 return @bitCast(Int, @truncate(UnInt, value));94 return @as(Int, @bitCast(@as(UnInt, @truncate(value))));
95 }95 }
9696
97 /// Sets the integer at `index` to `val` within the packed data beginning97 /// Sets the integer at `index` to `val` within the packed data beginning
...@@ -115,21 +115,21 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {...@@ -115,21 +115,21 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {
115 const head_keep_bits = bit_index - (start_byte * 8);115 const head_keep_bits = bit_index - (start_byte * 8);
116 const tail_keep_bits = container_bits - (int_bits + head_keep_bits);116 const tail_keep_bits = container_bits - (int_bits + head_keep_bits);
117 const keep_shift = switch (endian) {117 const keep_shift = switch (endian) {
118 .Big => @intCast(Shift, tail_keep_bits),118 .Big => @as(Shift, @intCast(tail_keep_bits)),
119 .Little => @intCast(Shift, head_keep_bits),119 .Little => @as(Shift, @intCast(head_keep_bits)),
120 };120 };
121121
122 //position the bits where they need to be in the container122 //position the bits where they need to be in the container
123 const value = @intCast(Container, @bitCast(UnInt, int)) << keep_shift;123 const value = @as(Container, @intCast(@as(UnInt, @bitCast(int)))) << keep_shift;
124124
125 //read existing bytes125 //read existing bytes
126 const target_ptr = @ptrCast(*align(1) Container, &bytes[start_byte]);126 const target_ptr = @as(*align(1) Container, @ptrCast(&bytes[start_byte]));
127 var target = target_ptr.*;127 var target = target_ptr.*;
128128
129 if (endian != native_endian) target = @byteSwap(target);129 if (endian != native_endian) target = @byteSwap(target);
130130
131 //zero the bits we want to replace in the existing bytes131 //zero the bits we want to replace in the existing bytes
132 const inv_mask = @intCast(Container, std.math.maxInt(UnInt)) << keep_shift;132 const inv_mask = @as(Container, @intCast(std.math.maxInt(UnInt))) << keep_shift;
133 const mask = ~inv_mask;133 const mask = ~inv_mask;
134 target &= mask;134 target &= mask;
135135
...@@ -156,7 +156,7 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {...@@ -156,7 +156,7 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {
156 if (length == 0) return PackedIntSliceEndian(Int, endian).init(new_bytes[0..0], 0);156 if (length == 0) return PackedIntSliceEndian(Int, endian).init(new_bytes[0..0], 0);
157157
158 var new_slice = PackedIntSliceEndian(Int, endian).init(new_bytes, length);158 var new_slice = PackedIntSliceEndian(Int, endian).init(new_bytes, length);
159 new_slice.bit_offset = @intCast(u3, (bit_index - (start_byte * 8)));159 new_slice.bit_offset = @as(u3, @intCast((bit_index - (start_byte * 8))));
160 return new_slice;160 return new_slice;
161 }161 }
162162
...@@ -398,7 +398,7 @@ test "PackedIntArray init" {...@@ -398,7 +398,7 @@ test "PackedIntArray init" {
398 const PackedArray = PackedIntArray(u3, 8);398 const PackedArray = PackedIntArray(u3, 8);
399 var packed_array = PackedArray.init([_]u3{ 0, 1, 2, 3, 4, 5, 6, 7 });399 var packed_array = PackedArray.init([_]u3{ 0, 1, 2, 3, 4, 5, 6, 7 });
400 var i = @as(usize, 0);400 var i = @as(usize, 0);
401 while (i < packed_array.len) : (i += 1) try testing.expectEqual(@intCast(u3, i), packed_array.get(i));401 while (i < packed_array.len) : (i += 1) try testing.expectEqual(@as(u3, @intCast(i)), packed_array.get(i));
402}402}
403403
404test "PackedIntArray initAllTo" {404test "PackedIntArray initAllTo" {
...@@ -469,7 +469,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {...@@ -469,7 +469,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
469469
470 var i = @as(usize, 0);470 var i = @as(usize, 0);
471 while (i < packed_array.len) : (i += 1) {471 while (i < packed_array.len) : (i += 1) {
472 packed_array.set(i, @intCast(Int, i % limit));472 packed_array.set(i, @as(Int, @intCast(i % limit)));
473 }473 }
474474
475 //slice of array475 //slice of array
lib/std/pdb.zig+15-15
...@@ -573,7 +573,7 @@ pub const Pdb = struct {...@@ -573,7 +573,7 @@ pub const Pdb = struct {
573 if (this_record_len % 4 != 0) {573 if (this_record_len % 4 != 0) {
574 const round_to_next_4 = (this_record_len | 0x3) + 1;574 const round_to_next_4 = (this_record_len | 0x3) + 1;
575 const march_forward_bytes = round_to_next_4 - this_record_len;575 const march_forward_bytes = round_to_next_4 - this_record_len;
576 try stream.seekBy(@intCast(isize, march_forward_bytes));576 try stream.seekBy(@as(isize, @intCast(march_forward_bytes)));
577 this_record_len += march_forward_bytes;577 this_record_len += march_forward_bytes;
578 }578 }
579579
...@@ -689,14 +689,14 @@ pub const Pdb = struct {...@@ -689,14 +689,14 @@ pub const Pdb = struct {
689689
690 var symbol_i: usize = 0;690 var symbol_i: usize = 0;
691 while (symbol_i != module.symbols.len) {691 while (symbol_i != module.symbols.len) {
692 const prefix = @ptrCast(*align(1) RecordPrefix, &module.symbols[symbol_i]);692 const prefix = @as(*align(1) RecordPrefix, @ptrCast(&module.symbols[symbol_i]));
693 if (prefix.RecordLen < 2)693 if (prefix.RecordLen < 2)
694 return null;694 return null;
695 switch (prefix.RecordKind) {695 switch (prefix.RecordKind) {
696 .S_LPROC32, .S_GPROC32 => {696 .S_LPROC32, .S_GPROC32 => {
697 const proc_sym = @ptrCast(*align(1) ProcSym, &module.symbols[symbol_i + @sizeOf(RecordPrefix)]);697 const proc_sym = @as(*align(1) ProcSym, @ptrCast(&module.symbols[symbol_i + @sizeOf(RecordPrefix)]));
698 if (address >= proc_sym.CodeOffset and address < proc_sym.CodeOffset + proc_sym.CodeSize) {698 if (address >= proc_sym.CodeOffset and address < proc_sym.CodeOffset + proc_sym.CodeSize) {
699 return mem.sliceTo(@ptrCast([*:0]u8, &proc_sym.Name[0]), 0);699 return mem.sliceTo(@as([*:0]u8, @ptrCast(&proc_sym.Name[0])), 0);
700 }700 }
701 },701 },
702 else => {},702 else => {},
...@@ -715,7 +715,7 @@ pub const Pdb = struct {...@@ -715,7 +715,7 @@ pub const Pdb = struct {
715 var skip_len: usize = undefined;715 var skip_len: usize = undefined;
716 const checksum_offset = module.checksum_offset orelse return error.MissingDebugInfo;716 const checksum_offset = module.checksum_offset orelse return error.MissingDebugInfo;
717 while (sect_offset != subsect_info.len) : (sect_offset += skip_len) {717 while (sect_offset != subsect_info.len) : (sect_offset += skip_len) {
718 const subsect_hdr = @ptrCast(*align(1) DebugSubsectionHeader, &subsect_info[sect_offset]);718 const subsect_hdr = @as(*align(1) DebugSubsectionHeader, @ptrCast(&subsect_info[sect_offset]));
719 skip_len = subsect_hdr.Length;719 skip_len = subsect_hdr.Length;
720 sect_offset += @sizeOf(DebugSubsectionHeader);720 sect_offset += @sizeOf(DebugSubsectionHeader);
721721
...@@ -723,7 +723,7 @@ pub const Pdb = struct {...@@ -723,7 +723,7 @@ pub const Pdb = struct {
723 .Lines => {723 .Lines => {
724 var line_index = sect_offset;724 var line_index = sect_offset;
725725
726 const line_hdr = @ptrCast(*align(1) LineFragmentHeader, &subsect_info[line_index]);726 const line_hdr = @as(*align(1) LineFragmentHeader, @ptrCast(&subsect_info[line_index]));
727 if (line_hdr.RelocSegment == 0)727 if (line_hdr.RelocSegment == 0)
728 return error.MissingDebugInfo;728 return error.MissingDebugInfo;
729 line_index += @sizeOf(LineFragmentHeader);729 line_index += @sizeOf(LineFragmentHeader);
...@@ -737,7 +737,7 @@ pub const Pdb = struct {...@@ -737,7 +737,7 @@ pub const Pdb = struct {
737 const subsection_end_index = sect_offset + subsect_hdr.Length;737 const subsection_end_index = sect_offset + subsect_hdr.Length;
738738
739 while (line_index < subsection_end_index) {739 while (line_index < subsection_end_index) {
740 const block_hdr = @ptrCast(*align(1) LineBlockFragmentHeader, &subsect_info[line_index]);740 const block_hdr = @as(*align(1) LineBlockFragmentHeader, @ptrCast(&subsect_info[line_index]));
741 line_index += @sizeOf(LineBlockFragmentHeader);741 line_index += @sizeOf(LineBlockFragmentHeader);
742 const start_line_index = line_index;742 const start_line_index = line_index;
743743
...@@ -749,7 +749,7 @@ pub const Pdb = struct {...@@ -749,7 +749,7 @@ pub const Pdb = struct {
749 // This is done with a simple linear search.749 // This is done with a simple linear search.
750 var line_i: u32 = 0;750 var line_i: u32 = 0;
751 while (line_i < block_hdr.NumLines) : (line_i += 1) {751 while (line_i < block_hdr.NumLines) : (line_i += 1) {
752 const line_num_entry = @ptrCast(*align(1) LineNumberEntry, &subsect_info[line_index]);752 const line_num_entry = @as(*align(1) LineNumberEntry, @ptrCast(&subsect_info[line_index]));
753 line_index += @sizeOf(LineNumberEntry);753 line_index += @sizeOf(LineNumberEntry);
754754
755 const vaddr_start = frag_vaddr_start + line_num_entry.Offset;755 const vaddr_start = frag_vaddr_start + line_num_entry.Offset;
...@@ -761,7 +761,7 @@ pub const Pdb = struct {...@@ -761,7 +761,7 @@ pub const Pdb = struct {
761 // line_i == 0 would mean that no matching LineNumberEntry was found.761 // line_i == 0 would mean that no matching LineNumberEntry was found.
762 if (line_i > 0) {762 if (line_i > 0) {
763 const subsect_index = checksum_offset + block_hdr.NameIndex;763 const subsect_index = checksum_offset + block_hdr.NameIndex;
764 const chksum_hdr = @ptrCast(*align(1) FileChecksumEntryHeader, &module.subsect_info[subsect_index]);764 const chksum_hdr = @as(*align(1) FileChecksumEntryHeader, @ptrCast(&module.subsect_info[subsect_index]));
765 const strtab_offset = @sizeOf(PDBStringTableHeader) + chksum_hdr.FileNameOffset;765 const strtab_offset = @sizeOf(PDBStringTableHeader) + chksum_hdr.FileNameOffset;
766 try self.string_table.?.seekTo(strtab_offset);766 try self.string_table.?.seekTo(strtab_offset);
767 const source_file_name = try self.string_table.?.reader().readUntilDelimiterAlloc(self.allocator, 0, 1024);767 const source_file_name = try self.string_table.?.reader().readUntilDelimiterAlloc(self.allocator, 0, 1024);
...@@ -771,13 +771,13 @@ pub const Pdb = struct {...@@ -771,13 +771,13 @@ pub const Pdb = struct {
771 const column = if (has_column) blk: {771 const column = if (has_column) blk: {
772 const start_col_index = start_line_index + @sizeOf(LineNumberEntry) * block_hdr.NumLines;772 const start_col_index = start_line_index + @sizeOf(LineNumberEntry) * block_hdr.NumLines;
773 const col_index = start_col_index + @sizeOf(ColumnNumberEntry) * line_entry_idx;773 const col_index = start_col_index + @sizeOf(ColumnNumberEntry) * line_entry_idx;
774 const col_num_entry = @ptrCast(*align(1) ColumnNumberEntry, &subsect_info[col_index]);774 const col_num_entry = @as(*align(1) ColumnNumberEntry, @ptrCast(&subsect_info[col_index]));
775 break :blk col_num_entry.StartColumn;775 break :blk col_num_entry.StartColumn;
776 } else 0;776 } else 0;
777777
778 const found_line_index = start_line_index + line_entry_idx * @sizeOf(LineNumberEntry);778 const found_line_index = start_line_index + line_entry_idx * @sizeOf(LineNumberEntry);
779 const line_num_entry = @ptrCast(*align(1) LineNumberEntry, &subsect_info[found_line_index]);779 const line_num_entry = @as(*align(1) LineNumberEntry, @ptrCast(&subsect_info[found_line_index]));
780 const flags = @ptrCast(*LineNumberEntry.Flags, &line_num_entry.Flags);780 const flags = @as(*LineNumberEntry.Flags, @ptrCast(&line_num_entry.Flags));
781781
782 return debug.LineInfo{782 return debug.LineInfo{
783 .file_name = source_file_name,783 .file_name = source_file_name,
...@@ -836,7 +836,7 @@ pub const Pdb = struct {...@@ -836,7 +836,7 @@ pub const Pdb = struct {
836 var sect_offset: usize = 0;836 var sect_offset: usize = 0;
837 var skip_len: usize = undefined;837 var skip_len: usize = undefined;
838 while (sect_offset != mod.subsect_info.len) : (sect_offset += skip_len) {838 while (sect_offset != mod.subsect_info.len) : (sect_offset += skip_len) {
839 const subsect_hdr = @ptrCast(*align(1) DebugSubsectionHeader, &mod.subsect_info[sect_offset]);839 const subsect_hdr = @as(*align(1) DebugSubsectionHeader, @ptrCast(&mod.subsect_info[sect_offset]));
840 skip_len = subsect_hdr.Length;840 skip_len = subsect_hdr.Length;
841 sect_offset += @sizeOf(DebugSubsectionHeader);841 sect_offset += @sizeOf(DebugSubsectionHeader);
842842
...@@ -1038,7 +1038,7 @@ const MsfStream = struct {...@@ -1038,7 +1038,7 @@ const MsfStream = struct {
1038 }1038 }
10391039
1040 fn read(self: *MsfStream, buffer: []u8) !usize {1040 fn read(self: *MsfStream, buffer: []u8) !usize {
1041 var block_id = @intCast(usize, self.pos / self.block_size);1041 var block_id = @as(usize, @intCast(self.pos / self.block_size));
1042 if (block_id >= self.blocks.len) return 0; // End of Stream1042 if (block_id >= self.blocks.len) return 0; // End of Stream
1043 var block = self.blocks[block_id];1043 var block = self.blocks[block_id];
1044 var offset = self.pos % self.block_size;1044 var offset = self.pos % self.block_size;
...@@ -1069,7 +1069,7 @@ const MsfStream = struct {...@@ -1069,7 +1069,7 @@ const MsfStream = struct {
1069 }1069 }
10701070
1071 pub fn seekBy(self: *MsfStream, len: i64) !void {1071 pub fn seekBy(self: *MsfStream, len: i64) !void {
1072 self.pos = @intCast(u64, @intCast(i64, self.pos) + len);1072 self.pos = @as(u64, @intCast(@as(i64, @intCast(self.pos)) + len));
1073 if (self.pos >= self.blocks.len * self.block_size)1073 if (self.pos >= self.blocks.len * self.block_size)
1074 return error.EOF;1074 return error.EOF;
1075 }1075 }
lib/std/process.zig+9-9
...@@ -68,7 +68,7 @@ pub const EnvMap = struct {...@@ -68,7 +68,7 @@ pub const EnvMap = struct {
68 pub const EnvNameHashContext = struct {68 pub const EnvNameHashContext = struct {
69 fn upcase(c: u21) u21 {69 fn upcase(c: u21) u21 {
70 if (c <= std.math.maxInt(u16))70 if (c <= std.math.maxInt(u16))
71 return std.os.windows.ntdll.RtlUpcaseUnicodeChar(@intCast(u16, c));71 return std.os.windows.ntdll.RtlUpcaseUnicodeChar(@as(u16, @intCast(c)));
72 return c;72 return c;
73 }73 }
7474
...@@ -80,9 +80,9 @@ pub const EnvMap = struct {...@@ -80,9 +80,9 @@ pub const EnvMap = struct {
80 while (it.nextCodepoint()) |cp| {80 while (it.nextCodepoint()) |cp| {
81 const cp_upper = upcase(cp);81 const cp_upper = upcase(cp);
82 h.update(&[_]u8{82 h.update(&[_]u8{
83 @intCast(u8, (cp_upper >> 16) & 0xff),83 @as(u8, @intCast((cp_upper >> 16) & 0xff)),
84 @intCast(u8, (cp_upper >> 8) & 0xff),84 @as(u8, @intCast((cp_upper >> 8) & 0xff)),
85 @intCast(u8, (cp_upper >> 0) & 0xff),85 @as(u8, @intCast((cp_upper >> 0) & 0xff)),
86 });86 });
87 }87 }
88 return h.final();88 return h.final();
...@@ -872,8 +872,8 @@ pub fn argsFree(allocator: Allocator, args_alloc: []const [:0]u8) void {...@@ -872,8 +872,8 @@ pub fn argsFree(allocator: Allocator, args_alloc: []const [:0]u8) void {
872 for (args_alloc) |arg| {872 for (args_alloc) |arg| {
873 total_bytes += @sizeOf([]u8) + arg.len + 1;873 total_bytes += @sizeOf([]u8) + arg.len + 1;
874 }874 }
875 const unaligned_allocated_buf = @ptrCast([*]const u8, args_alloc.ptr)[0..total_bytes];875 const unaligned_allocated_buf = @as([*]const u8, @ptrCast(args_alloc.ptr))[0..total_bytes];
876 const aligned_allocated_buf = @alignCast(@alignOf([]u8), unaligned_allocated_buf);876 const aligned_allocated_buf: []align(@alignOf([]u8)) const u8 = @alignCast(unaligned_allocated_buf);
877 return allocator.free(aligned_allocated_buf);877 return allocator.free(aligned_allocated_buf);
878}878}
879879
...@@ -1143,7 +1143,7 @@ pub fn execve(...@@ -1143,7 +1143,7 @@ pub fn execve(
1143 } else if (builtin.output_mode == .Exe) {1143 } else if (builtin.output_mode == .Exe) {
1144 // Then we have Zig start code and this works.1144 // Then we have Zig start code and this works.
1145 // TODO type-safety for null-termination of `os.environ`.1145 // TODO type-safety for null-termination of `os.environ`.
1146 break :m @ptrCast([*:null]const ?[*:0]const u8, os.environ.ptr);1146 break :m @as([*:null]const ?[*:0]const u8, @ptrCast(os.environ.ptr));
1147 } else {1147 } else {
1148 // TODO come up with a solution for this.1148 // TODO come up with a solution for this.
1149 @compileError("missing std lib enhancement: std.process.execv implementation has no way to collect the environment variables to forward to the child process");1149 @compileError("missing std lib enhancement: std.process.execv implementation has no way to collect the environment variables to forward to the child process");
...@@ -1175,7 +1175,7 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {...@@ -1175,7 +1175,7 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {
1175 error.NameTooLong, error.UnknownName => unreachable,1175 error.NameTooLong, error.UnknownName => unreachable,
1176 else => return error.UnknownTotalSystemMemory,1176 else => return error.UnknownTotalSystemMemory,
1177 };1177 };
1178 return @intCast(usize, physmem);1178 return @as(usize, @intCast(physmem));
1179 },1179 },
1180 .openbsd => {1180 .openbsd => {
1181 const mib: [2]c_int = [_]c_int{1181 const mib: [2]c_int = [_]c_int{
...@@ -1192,7 +1192,7 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {...@@ -1192,7 +1192,7 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {
1192 else => return error.UnknownTotalSystemMemory,1192 else => return error.UnknownTotalSystemMemory,
1193 };1193 };
1194 assert(physmem >= 0);1194 assert(physmem >= 0);
1195 return @bitCast(usize, physmem);1195 return @as(usize, @bitCast(physmem));
1196 },1196 },
1197 .windows => {1197 .windows => {
1198 var sbi: std.os.windows.SYSTEM_BASIC_INFORMATION = undefined;1198 var sbi: std.os.windows.SYSTEM_BASIC_INFORMATION = undefined;
lib/std/rand.zig+29-30
...@@ -41,8 +41,7 @@ pub const Random = struct {...@@ -41,8 +41,7 @@ pub const Random = struct {
41 assert(@typeInfo(@typeInfo(Ptr).Pointer.child) == .Struct); // Must point to a struct41 assert(@typeInfo(@typeInfo(Ptr).Pointer.child) == .Struct); // Must point to a struct
42 const gen = struct {42 const gen = struct {
43 fn fill(ptr: *anyopaque, buf: []u8) void {43 fn fill(ptr: *anyopaque, buf: []u8) void {
44 const alignment = @typeInfo(Ptr).Pointer.alignment;44 const self: Ptr = @ptrCast(@alignCast(ptr));
45 const self = @ptrCast(Ptr, @alignCast(alignment, ptr));
46 fillFn(self, buf);45 fillFn(self, buf);
47 }46 }
48 };47 };
...@@ -97,7 +96,7 @@ pub const Random = struct {...@@ -97,7 +96,7 @@ pub const Random = struct {
97 r.uintLessThan(Index, values.len);96 r.uintLessThan(Index, values.len);
9897
99 const MinInt = MinArrayIndex(Index);98 const MinInt = MinArrayIndex(Index);
100 return values[@intCast(MinInt, index)];99 return values[@as(MinInt, @intCast(index))];
101 }100 }
102101
103 /// Returns a random int `i` such that `minInt(T) <= i <= maxInt(T)`.102 /// Returns a random int `i` such that `minInt(T) <= i <= maxInt(T)`.
...@@ -114,8 +113,8 @@ pub const Random = struct {...@@ -114,8 +113,8 @@ pub const Random = struct {
114 // TODO: endian portability is pointless if the underlying prng isn't endian portable.113 // TODO: endian portability is pointless if the underlying prng isn't endian portable.
115 // TODO: document the endian portability of this library.114 // TODO: document the endian portability of this library.
116 const byte_aligned_result = mem.readIntSliceLittle(ByteAlignedT, &rand_bytes);115 const byte_aligned_result = mem.readIntSliceLittle(ByteAlignedT, &rand_bytes);
117 const unsigned_result = @truncate(UnsignedT, byte_aligned_result);116 const unsigned_result = @as(UnsignedT, @truncate(byte_aligned_result));
118 return @bitCast(T, unsigned_result);117 return @as(T, @bitCast(unsigned_result));
119 }118 }
120119
121 /// Constant-time implementation off `uintLessThan`.120 /// Constant-time implementation off `uintLessThan`.
...@@ -126,9 +125,9 @@ pub const Random = struct {...@@ -126,9 +125,9 @@ pub const Random = struct {
126 comptime assert(bits <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!125 comptime assert(bits <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!
127 assert(0 < less_than);126 assert(0 < less_than);
128 if (bits <= 32) {127 if (bits <= 32) {
129 return @intCast(T, limitRangeBiased(u32, r.int(u32), less_than));128 return @as(T, @intCast(limitRangeBiased(u32, r.int(u32), less_than)));
130 } else {129 } else {
131 return @intCast(T, limitRangeBiased(u64, r.int(u64), less_than));130 return @as(T, @intCast(limitRangeBiased(u64, r.int(u64), less_than)));
132 }131 }
133 }132 }
134133
...@@ -156,7 +155,7 @@ pub const Random = struct {...@@ -156,7 +155,7 @@ pub const Random = struct {
156 // "Lemire's (with an extra tweak from me)"155 // "Lemire's (with an extra tweak from me)"
157 var x: Small = r.int(Small);156 var x: Small = r.int(Small);
158 var m: Large = @as(Large, x) * @as(Large, less_than);157 var m: Large = @as(Large, x) * @as(Large, less_than);
159 var l: Small = @truncate(Small, m);158 var l: Small = @as(Small, @truncate(m));
160 if (l < less_than) {159 if (l < less_than) {
161 var t: Small = -%less_than;160 var t: Small = -%less_than;
162161
...@@ -169,10 +168,10 @@ pub const Random = struct {...@@ -169,10 +168,10 @@ pub const Random = struct {
169 while (l < t) {168 while (l < t) {
170 x = r.int(Small);169 x = r.int(Small);
171 m = @as(Large, x) * @as(Large, less_than);170 m = @as(Large, x) * @as(Large, less_than);
172 l = @truncate(Small, m);171 l = @as(Small, @truncate(m));
173 }172 }
174 }173 }
175 return @intCast(T, m >> small_bits);174 return @as(T, @intCast(m >> small_bits));
176 }175 }
177176
178 /// Constant-time implementation off `uintAtMost`.177 /// Constant-time implementation off `uintAtMost`.
...@@ -206,10 +205,10 @@ pub const Random = struct {...@@ -206,10 +205,10 @@ pub const Random = struct {
206 if (info.signedness == .signed) {205 if (info.signedness == .signed) {
207 // Two's complement makes this math pretty easy.206 // Two's complement makes this math pretty easy.
208 const UnsignedT = std.meta.Int(.unsigned, info.bits);207 const UnsignedT = std.meta.Int(.unsigned, info.bits);
209 const lo = @bitCast(UnsignedT, at_least);208 const lo = @as(UnsignedT, @bitCast(at_least));
210 const hi = @bitCast(UnsignedT, less_than);209 const hi = @as(UnsignedT, @bitCast(less_than));
211 const result = lo +% r.uintLessThanBiased(UnsignedT, hi -% lo);210 const result = lo +% r.uintLessThanBiased(UnsignedT, hi -% lo);
212 return @bitCast(T, result);211 return @as(T, @bitCast(result));
213 } else {212 } else {
214 // The signed implementation would work fine, but we can use stricter arithmetic operators here.213 // The signed implementation would work fine, but we can use stricter arithmetic operators here.
215 return at_least + r.uintLessThanBiased(T, less_than - at_least);214 return at_least + r.uintLessThanBiased(T, less_than - at_least);
...@@ -225,10 +224,10 @@ pub const Random = struct {...@@ -225,10 +224,10 @@ pub const Random = struct {
225 if (info.signedness == .signed) {224 if (info.signedness == .signed) {
226 // Two's complement makes this math pretty easy.225 // Two's complement makes this math pretty easy.
227 const UnsignedT = std.meta.Int(.unsigned, info.bits);226 const UnsignedT = std.meta.Int(.unsigned, info.bits);
228 const lo = @bitCast(UnsignedT, at_least);227 const lo = @as(UnsignedT, @bitCast(at_least));
229 const hi = @bitCast(UnsignedT, less_than);228 const hi = @as(UnsignedT, @bitCast(less_than));
230 const result = lo +% r.uintLessThan(UnsignedT, hi -% lo);229 const result = lo +% r.uintLessThan(UnsignedT, hi -% lo);
231 return @bitCast(T, result);230 return @as(T, @bitCast(result));
232 } else {231 } else {
233 // The signed implementation would work fine, but we can use stricter arithmetic operators here.232 // The signed implementation would work fine, but we can use stricter arithmetic operators here.
234 return at_least + r.uintLessThan(T, less_than - at_least);233 return at_least + r.uintLessThan(T, less_than - at_least);
...@@ -243,10 +242,10 @@ pub const Random = struct {...@@ -243,10 +242,10 @@ pub const Random = struct {
243 if (info.signedness == .signed) {242 if (info.signedness == .signed) {
244 // Two's complement makes this math pretty easy.243 // Two's complement makes this math pretty easy.
245 const UnsignedT = std.meta.Int(.unsigned, info.bits);244 const UnsignedT = std.meta.Int(.unsigned, info.bits);
246 const lo = @bitCast(UnsignedT, at_least);245 const lo = @as(UnsignedT, @bitCast(at_least));
247 const hi = @bitCast(UnsignedT, at_most);246 const hi = @as(UnsignedT, @bitCast(at_most));
248 const result = lo +% r.uintAtMostBiased(UnsignedT, hi -% lo);247 const result = lo +% r.uintAtMostBiased(UnsignedT, hi -% lo);
249 return @bitCast(T, result);248 return @as(T, @bitCast(result));
250 } else {249 } else {
251 // The signed implementation would work fine, but we can use stricter arithmetic operators here.250 // The signed implementation would work fine, but we can use stricter arithmetic operators here.
252 return at_least + r.uintAtMostBiased(T, at_most - at_least);251 return at_least + r.uintAtMostBiased(T, at_most - at_least);
...@@ -262,10 +261,10 @@ pub const Random = struct {...@@ -262,10 +261,10 @@ pub const Random = struct {
262 if (info.signedness == .signed) {261 if (info.signedness == .signed) {
263 // Two's complement makes this math pretty easy.262 // Two's complement makes this math pretty easy.
264 const UnsignedT = std.meta.Int(.unsigned, info.bits);263 const UnsignedT = std.meta.Int(.unsigned, info.bits);
265 const lo = @bitCast(UnsignedT, at_least);264 const lo = @as(UnsignedT, @bitCast(at_least));
266 const hi = @bitCast(UnsignedT, at_most);265 const hi = @as(UnsignedT, @bitCast(at_most));
267 const result = lo +% r.uintAtMost(UnsignedT, hi -% lo);266 const result = lo +% r.uintAtMost(UnsignedT, hi -% lo);
268 return @bitCast(T, result);267 return @as(T, @bitCast(result));
269 } else {268 } else {
270 // The signed implementation would work fine, but we can use stricter arithmetic operators here.269 // The signed implementation would work fine, but we can use stricter arithmetic operators here.
271 return at_least + r.uintAtMost(T, at_most - at_least);270 return at_least + r.uintAtMost(T, at_most - at_least);
...@@ -294,9 +293,9 @@ pub const Random = struct {...@@ -294,9 +293,9 @@ pub const Random = struct {
294 rand_lz += @clz(r.int(u32) | 0x7FF);293 rand_lz += @clz(r.int(u32) | 0x7FF);
295 }294 }
296 }295 }
297 const mantissa = @truncate(u23, rand);296 const mantissa = @as(u23, @truncate(rand));
298 const exponent = @as(u32, 126 - rand_lz) << 23;297 const exponent = @as(u32, 126 - rand_lz) << 23;
299 return @bitCast(f32, exponent | mantissa);298 return @as(f32, @bitCast(exponent | mantissa));
300 },299 },
301 f64 => {300 f64 => {
302 // Use 52 random bits for the mantissa, and the rest for the exponent.301 // Use 52 random bits for the mantissa, and the rest for the exponent.
...@@ -321,7 +320,7 @@ pub const Random = struct {...@@ -321,7 +320,7 @@ pub const Random = struct {
321 }320 }
322 const mantissa = rand & 0xFFFFFFFFFFFFF;321 const mantissa = rand & 0xFFFFFFFFFFFFF;
323 const exponent = (1022 - rand_lz) << 52;322 const exponent = (1022 - rand_lz) << 52;
324 return @bitCast(f64, exponent | mantissa);323 return @as(f64, @bitCast(exponent | mantissa));
325 },324 },
326 else => @compileError("unknown floating point type"),325 else => @compileError("unknown floating point type"),
327 }326 }
...@@ -333,7 +332,7 @@ pub const Random = struct {...@@ -333,7 +332,7 @@ pub const Random = struct {
333 pub fn floatNorm(r: Random, comptime T: type) T {332 pub fn floatNorm(r: Random, comptime T: type) T {
334 const value = ziggurat.next_f64(r, ziggurat.NormDist);333 const value = ziggurat.next_f64(r, ziggurat.NormDist);
335 switch (T) {334 switch (T) {
336 f32 => return @floatCast(f32, value),335 f32 => return @as(f32, @floatCast(value)),
337 f64 => return value,336 f64 => return value,
338 else => @compileError("unknown floating point type"),337 else => @compileError("unknown floating point type"),
339 }338 }
...@@ -345,7 +344,7 @@ pub const Random = struct {...@@ -345,7 +344,7 @@ pub const Random = struct {
345 pub fn floatExp(r: Random, comptime T: type) T {344 pub fn floatExp(r: Random, comptime T: type) T {
346 const value = ziggurat.next_f64(r, ziggurat.ExpDist);345 const value = ziggurat.next_f64(r, ziggurat.ExpDist);
347 switch (T) {346 switch (T) {
348 f32 => return @floatCast(f32, value),347 f32 => return @as(f32, @floatCast(value)),
349 f64 => return value,348 f64 => return value,
350 else => @compileError("unknown floating point type"),349 else => @compileError("unknown floating point type"),
351 }350 }
...@@ -379,10 +378,10 @@ pub const Random = struct {...@@ -379,10 +378,10 @@ pub const Random = struct {
379 }378 }
380379
381 // `i <= j < max <= maxInt(MinInt)`380 // `i <= j < max <= maxInt(MinInt)`
382 const max = @intCast(MinInt, buf.len);381 const max = @as(MinInt, @intCast(buf.len));
383 var i: MinInt = 0;382 var i: MinInt = 0;
384 while (i < max - 1) : (i += 1) {383 while (i < max - 1) : (i += 1) {
385 const j = @intCast(MinInt, r.intRangeLessThan(Index, i, max));384 const j = @as(MinInt, @intCast(r.intRangeLessThan(Index, i, max)));
386 mem.swap(T, &buf[i], &buf[j]);385 mem.swap(T, &buf[i], &buf[j]);
387 }386 }
388 }387 }
...@@ -445,7 +444,7 @@ pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T {...@@ -445,7 +444,7 @@ pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T {
445 // http://www.pcg-random.org/posts/bounded-rands.html444 // http://www.pcg-random.org/posts/bounded-rands.html
446 // "Integer Multiplication (Biased)"445 // "Integer Multiplication (Biased)"
447 var m: T2 = @as(T2, random_int) * @as(T2, less_than);446 var m: T2 = @as(T2, random_int) * @as(T2, less_than);
448 return @intCast(T, m >> bits);447 return @as(T, @intCast(m >> bits));
449}448}
450449
451// Generator to extend 64-bit seed values into longer sequences.450// Generator to extend 64-bit seed values into longer sequences.
lib/std/rand/Isaac64.zig+4-4
...@@ -38,10 +38,10 @@ fn step(self: *Isaac64, mix: u64, base: usize, comptime m1: usize, comptime m2:...@@ -38,10 +38,10 @@ fn step(self: *Isaac64, mix: u64, base: usize, comptime m1: usize, comptime m2:
38 const x = self.m[base + m1];38 const x = self.m[base + m1];
39 self.a = mix +% self.m[base + m2];39 self.a = mix +% self.m[base + m2];
4040
41 const y = self.a +% self.b +% self.m[@intCast(usize, (x >> 3) % self.m.len)];41 const y = self.a +% self.b +% self.m[@as(usize, @intCast((x >> 3) % self.m.len))];
42 self.m[base + m1] = y;42 self.m[base + m1] = y;
4343
44 self.b = x +% self.m[@intCast(usize, (y >> 11) % self.m.len)];44 self.b = x +% self.m[@as(usize, @intCast((y >> 11) % self.m.len))];
45 self.r[self.r.len - 1 - base - m1] = self.b;45 self.r[self.r.len - 1 - base - m1] = self.b;
46}46}
4747
...@@ -159,7 +159,7 @@ pub fn fill(self: *Isaac64, buf: []u8) void {...@@ -159,7 +159,7 @@ pub fn fill(self: *Isaac64, buf: []u8) void {
159 var n = self.next();159 var n = self.next();
160 comptime var j: usize = 0;160 comptime var j: usize = 0;
161 inline while (j < 8) : (j += 1) {161 inline while (j < 8) : (j += 1) {
162 buf[i + j] = @truncate(u8, n);162 buf[i + j] = @as(u8, @truncate(n));
163 n >>= 8;163 n >>= 8;
164 }164 }
165 }165 }
...@@ -168,7 +168,7 @@ pub fn fill(self: *Isaac64, buf: []u8) void {...@@ -168,7 +168,7 @@ pub fn fill(self: *Isaac64, buf: []u8) void {
168 if (i != buf.len) {168 if (i != buf.len) {
169 var n = self.next();169 var n = self.next();
170 while (i < buf.len) : (i += 1) {170 while (i < buf.len) : (i += 1) {
171 buf[i] = @truncate(u8, n);171 buf[i] = @as(u8, @truncate(n));
172 n >>= 8;172 n >>= 8;
173 }173 }
174 }174 }
lib/std/rand/Pcg.zig+5-5
...@@ -29,10 +29,10 @@ fn next(self: *Pcg) u32 {...@@ -29,10 +29,10 @@ fn next(self: *Pcg) u32 {
29 const l = self.s;29 const l = self.s;
30 self.s = l *% default_multiplier +% (self.i | 1);30 self.s = l *% default_multiplier +% (self.i | 1);
3131
32 const xor_s = @truncate(u32, ((l >> 18) ^ l) >> 27);32 const xor_s = @as(u32, @truncate(((l >> 18) ^ l) >> 27));
33 const rot = @intCast(u32, l >> 59);33 const rot = @as(u32, @intCast(l >> 59));
3434
35 return (xor_s >> @intCast(u5, rot)) | (xor_s << @intCast(u5, (0 -% rot) & 31));35 return (xor_s >> @as(u5, @intCast(rot))) | (xor_s << @as(u5, @intCast((0 -% rot) & 31)));
36}36}
3737
38fn seed(self: *Pcg, init_s: u64) void {38fn seed(self: *Pcg, init_s: u64) void {
...@@ -58,7 +58,7 @@ pub fn fill(self: *Pcg, buf: []u8) void {...@@ -58,7 +58,7 @@ pub fn fill(self: *Pcg, buf: []u8) void {
58 var n = self.next();58 var n = self.next();
59 comptime var j: usize = 0;59 comptime var j: usize = 0;
60 inline while (j < 4) : (j += 1) {60 inline while (j < 4) : (j += 1) {
61 buf[i + j] = @truncate(u8, n);61 buf[i + j] = @as(u8, @truncate(n));
62 n >>= 8;62 n >>= 8;
63 }63 }
64 }64 }
...@@ -67,7 +67,7 @@ pub fn fill(self: *Pcg, buf: []u8) void {...@@ -67,7 +67,7 @@ pub fn fill(self: *Pcg, buf: []u8) void {
67 if (i != buf.len) {67 if (i != buf.len) {
68 var n = self.next();68 var n = self.next();
69 while (i < buf.len) : (i += 1) {69 while (i < buf.len) : (i += 1) {
70 buf[i] = @truncate(u8, n);70 buf[i] = @as(u8, @truncate(n));
71 n >>= 8;71 n >>= 8;
72 }72 }
73 }73 }
lib/std/rand/RomuTrio.zig+4-4
...@@ -34,7 +34,7 @@ fn next(self: *RomuTrio) u64 {...@@ -34,7 +34,7 @@ fn next(self: *RomuTrio) u64 {
34}34}
3535
36pub fn seedWithBuf(self: *RomuTrio, buf: [24]u8) void {36pub fn seedWithBuf(self: *RomuTrio, buf: [24]u8) void {
37 const seed_buf = @bitCast([3]u64, buf);37 const seed_buf = @as([3]u64, @bitCast(buf));
38 self.x_state = seed_buf[0];38 self.x_state = seed_buf[0];
39 self.y_state = seed_buf[1];39 self.y_state = seed_buf[1];
40 self.z_state = seed_buf[2];40 self.z_state = seed_buf[2];
...@@ -58,7 +58,7 @@ pub fn fill(self: *RomuTrio, buf: []u8) void {...@@ -58,7 +58,7 @@ pub fn fill(self: *RomuTrio, buf: []u8) void {
58 var n = self.next();58 var n = self.next();
59 comptime var j: usize = 0;59 comptime var j: usize = 0;
60 inline while (j < 8) : (j += 1) {60 inline while (j < 8) : (j += 1) {
61 buf[i + j] = @truncate(u8, n);61 buf[i + j] = @as(u8, @truncate(n));
62 n >>= 8;62 n >>= 8;
63 }63 }
64 }64 }
...@@ -67,7 +67,7 @@ pub fn fill(self: *RomuTrio, buf: []u8) void {...@@ -67,7 +67,7 @@ pub fn fill(self: *RomuTrio, buf: []u8) void {
67 if (i != buf.len) {67 if (i != buf.len) {
68 var n = self.next();68 var n = self.next();
69 while (i < buf.len) : (i += 1) {69 while (i < buf.len) : (i += 1) {
70 buf[i] = @truncate(u8, n);70 buf[i] = @as(u8, @truncate(n));
71 n >>= 8;71 n >>= 8;
72 }72 }
73 }73 }
...@@ -122,7 +122,7 @@ test "RomuTrio fill" {...@@ -122,7 +122,7 @@ test "RomuTrio fill" {
122}122}
123123
124test "RomuTrio buf seeding test" {124test "RomuTrio buf seeding test" {
125 const buf0 = @bitCast([24]u8, [3]u64{ 16294208416658607535, 13964609475759908645, 4703697494102998476 });125 const buf0 = @as([24]u8, @bitCast([3]u64{ 16294208416658607535, 13964609475759908645, 4703697494102998476 }));
126 const resulting_state = .{ .x = 16294208416658607535, .y = 13964609475759908645, .z = 4703697494102998476 };126 const resulting_state = .{ .x = 16294208416658607535, .y = 13964609475759908645, .z = 4703697494102998476 };
127 var r = RomuTrio.init(0);127 var r = RomuTrio.init(0);
128 r.seedWithBuf(buf0);128 r.seedWithBuf(buf0);
lib/std/rand/Sfc64.zig+2-2
...@@ -56,7 +56,7 @@ pub fn fill(self: *Sfc64, buf: []u8) void {...@@ -56,7 +56,7 @@ pub fn fill(self: *Sfc64, buf: []u8) void {
56 var n = self.next();56 var n = self.next();
57 comptime var j: usize = 0;57 comptime var j: usize = 0;
58 inline while (j < 8) : (j += 1) {58 inline while (j < 8) : (j += 1) {
59 buf[i + j] = @truncate(u8, n);59 buf[i + j] = @as(u8, @truncate(n));
60 n >>= 8;60 n >>= 8;
61 }61 }
62 }62 }
...@@ -65,7 +65,7 @@ pub fn fill(self: *Sfc64, buf: []u8) void {...@@ -65,7 +65,7 @@ pub fn fill(self: *Sfc64, buf: []u8) void {
65 if (i != buf.len) {65 if (i != buf.len) {
66 var n = self.next();66 var n = self.next();
67 while (i < buf.len) : (i += 1) {67 while (i < buf.len) : (i += 1) {
68 buf[i] = @truncate(u8, n);68 buf[i] = @as(u8, @truncate(n));
69 n >>= 8;69 n >>= 8;
70 }70 }
71 }71 }
lib/std/rand/Xoroshiro128.zig+3-3
...@@ -45,7 +45,7 @@ pub fn jump(self: *Xoroshiro128) void {...@@ -45,7 +45,7 @@ pub fn jump(self: *Xoroshiro128) void {
45 inline for (table) |entry| {45 inline for (table) |entry| {
46 var b: usize = 0;46 var b: usize = 0;
47 while (b < 64) : (b += 1) {47 while (b < 64) : (b += 1) {
48 if ((entry & (@as(u64, 1) << @intCast(u6, b))) != 0) {48 if ((entry & (@as(u64, 1) << @as(u6, @intCast(b)))) != 0) {
49 s0 ^= self.s[0];49 s0 ^= self.s[0];
50 s1 ^= self.s[1];50 s1 ^= self.s[1];
51 }51 }
...@@ -74,7 +74,7 @@ pub fn fill(self: *Xoroshiro128, buf: []u8) void {...@@ -74,7 +74,7 @@ pub fn fill(self: *Xoroshiro128, buf: []u8) void {
74 var n = self.next();74 var n = self.next();
75 comptime var j: usize = 0;75 comptime var j: usize = 0;
76 inline while (j < 8) : (j += 1) {76 inline while (j < 8) : (j += 1) {
77 buf[i + j] = @truncate(u8, n);77 buf[i + j] = @as(u8, @truncate(n));
78 n >>= 8;78 n >>= 8;
79 }79 }
80 }80 }
...@@ -83,7 +83,7 @@ pub fn fill(self: *Xoroshiro128, buf: []u8) void {...@@ -83,7 +83,7 @@ pub fn fill(self: *Xoroshiro128, buf: []u8) void {
83 if (i != buf.len) {83 if (i != buf.len) {
84 var n = self.next();84 var n = self.next();
85 while (i < buf.len) : (i += 1) {85 while (i < buf.len) : (i += 1) {
86 buf[i] = @truncate(u8, n);86 buf[i] = @as(u8, @truncate(n));
87 n >>= 8;87 n >>= 8;
88 }88 }
89 }89 }
lib/std/rand/Xoshiro256.zig+5-5
...@@ -46,13 +46,13 @@ pub fn jump(self: *Xoshiro256) void {...@@ -46,13 +46,13 @@ pub fn jump(self: *Xoshiro256) void {
46 var table: u256 = 0x39abdc4529b1661ca9582618e03fc9aad5a61266f0c9392c180ec6d33cfd0aba;46 var table: u256 = 0x39abdc4529b1661ca9582618e03fc9aad5a61266f0c9392c180ec6d33cfd0aba;
4747
48 while (table != 0) : (table >>= 1) {48 while (table != 0) : (table >>= 1) {
49 if (@truncate(u1, table) != 0) {49 if (@as(u1, @truncate(table)) != 0) {
50 s ^= @bitCast(u256, self.s);50 s ^= @as(u256, @bitCast(self.s));
51 }51 }
52 _ = self.next();52 _ = self.next();
53 }53 }
5454
55 self.s = @bitCast([4]u64, s);55 self.s = @as([4]u64, @bitCast(s));
56}56}
5757
58pub fn seed(self: *Xoshiro256, init_s: u64) void {58pub fn seed(self: *Xoshiro256, init_s: u64) void {
...@@ -74,7 +74,7 @@ pub fn fill(self: *Xoshiro256, buf: []u8) void {...@@ -74,7 +74,7 @@ pub fn fill(self: *Xoshiro256, buf: []u8) void {
74 var n = self.next();74 var n = self.next();
75 comptime var j: usize = 0;75 comptime var j: usize = 0;
76 inline while (j < 8) : (j += 1) {76 inline while (j < 8) : (j += 1) {
77 buf[i + j] = @truncate(u8, n);77 buf[i + j] = @as(u8, @truncate(n));
78 n >>= 8;78 n >>= 8;
79 }79 }
80 }80 }
...@@ -83,7 +83,7 @@ pub fn fill(self: *Xoshiro256, buf: []u8) void {...@@ -83,7 +83,7 @@ pub fn fill(self: *Xoshiro256, buf: []u8) void {
83 if (i != buf.len) {83 if (i != buf.len) {
84 var n = self.next();84 var n = self.next();
85 while (i < buf.len) : (i += 1) {85 while (i < buf.len) : (i += 1) {
86 buf[i] = @truncate(u8, n);86 buf[i] = @as(u8, @truncate(n));
87 n >>= 8;87 n >>= 8;
88 }88 }
89 }89 }
lib/std/rand/benchmark.zig+2-2
...@@ -91,8 +91,8 @@ pub fn benchmark(comptime H: anytype, bytes: usize, comptime block_size: usize)...@@ -91,8 +91,8 @@ pub fn benchmark(comptime H: anytype, bytes: usize, comptime block_size: usize)
91 }91 }
92 const end = timer.read();92 const end = timer.read();
9393
94 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;94 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
95 const throughput = @intFromFloat(u64, @floatFromInt(f64, bytes) / elapsed_s);95 const throughput = @as(u64, @intFromFloat(@as(f64, @floatFromInt(bytes)) / elapsed_s));
9696
97 std.debug.assert(rng.random().int(u64) != 0);97 std.debug.assert(rng.random().int(u64) != 0);
9898
lib/std/rand/test.zig+8-8
...@@ -332,13 +332,13 @@ test "Random float chi-square goodness of fit" {...@@ -332,13 +332,13 @@ test "Random float chi-square goodness of fit" {
332 while (i < num_numbers) : (i += 1) {332 while (i < num_numbers) : (i += 1) {
333 const rand_f32 = random.float(f32);333 const rand_f32 = random.float(f32);
334 const rand_f64 = random.float(f64);334 const rand_f64 = random.float(f64);
335 var f32_put = try f32_hist.getOrPut(@intFromFloat(u32, rand_f32 * @floatFromInt(f32, num_buckets)));335 var f32_put = try f32_hist.getOrPut(@as(u32, @intFromFloat(rand_f32 * @as(f32, @floatFromInt(num_buckets)))));
336 if (f32_put.found_existing) {336 if (f32_put.found_existing) {
337 f32_put.value_ptr.* += 1;337 f32_put.value_ptr.* += 1;
338 } else {338 } else {
339 f32_put.value_ptr.* = 1;339 f32_put.value_ptr.* = 1;
340 }340 }
341 var f64_put = try f64_hist.getOrPut(@intFromFloat(u32, rand_f64 * @floatFromInt(f64, num_buckets)));341 var f64_put = try f64_hist.getOrPut(@as(u32, @intFromFloat(rand_f64 * @as(f64, @floatFromInt(num_buckets)))));
342 if (f64_put.found_existing) {342 if (f64_put.found_existing) {
343 f64_put.value_ptr.* += 1;343 f64_put.value_ptr.* += 1;
344 } else {344 } else {
...@@ -352,8 +352,8 @@ test "Random float chi-square goodness of fit" {...@@ -352,8 +352,8 @@ test "Random float chi-square goodness of fit" {
352 {352 {
353 var j: u32 = 0;353 var j: u32 = 0;
354 while (j < num_buckets) : (j += 1) {354 while (j < num_buckets) : (j += 1) {
355 const count = @floatFromInt(f64, (if (f32_hist.get(j)) |v| v else 0));355 const count = @as(f64, @floatFromInt((if (f32_hist.get(j)) |v| v else 0)));
356 const expected = @floatFromInt(f64, num_numbers) / @floatFromInt(f64, num_buckets);356 const expected = @as(f64, @floatFromInt(num_numbers)) / @as(f64, @floatFromInt(num_buckets));
357 const delta = count - expected;357 const delta = count - expected;
358 const variance = (delta * delta) / expected;358 const variance = (delta * delta) / expected;
359 f32_total_variance += variance;359 f32_total_variance += variance;
...@@ -363,8 +363,8 @@ test "Random float chi-square goodness of fit" {...@@ -363,8 +363,8 @@ test "Random float chi-square goodness of fit" {
363 {363 {
364 var j: u64 = 0;364 var j: u64 = 0;
365 while (j < num_buckets) : (j += 1) {365 while (j < num_buckets) : (j += 1) {
366 const count = @floatFromInt(f64, (if (f64_hist.get(j)) |v| v else 0));366 const count = @as(f64, @floatFromInt((if (f64_hist.get(j)) |v| v else 0)));
367 const expected = @floatFromInt(f64, num_numbers) / @floatFromInt(f64, num_buckets);367 const expected = @as(f64, @floatFromInt(num_numbers)) / @as(f64, @floatFromInt(num_buckets));
368 const delta = count - expected;368 const delta = count - expected;
369 const variance = (delta * delta) / expected;369 const variance = (delta * delta) / expected;
370 f64_total_variance += variance;370 f64_total_variance += variance;
...@@ -421,13 +421,13 @@ fn testRange(r: Random, start: i8, end: i8) !void {...@@ -421,13 +421,13 @@ fn testRange(r: Random, start: i8, end: i8) !void {
421 try testRangeBias(r, start, end, false);421 try testRangeBias(r, start, end, false);
422}422}
423fn testRangeBias(r: Random, start: i8, end: i8, biased: bool) !void {423fn testRangeBias(r: Random, start: i8, end: i8, biased: bool) !void {
424 const count = @intCast(usize, @as(i32, end) - @as(i32, start));424 const count = @as(usize, @intCast(@as(i32, end) - @as(i32, start)));
425 var values_buffer = [_]bool{false} ** 0x100;425 var values_buffer = [_]bool{false} ** 0x100;
426 const values = values_buffer[0..count];426 const values = values_buffer[0..count];
427 var i: usize = 0;427 var i: usize = 0;
428 while (i < count) {428 while (i < count) {
429 const value: i32 = if (biased) r.intRangeLessThanBiased(i8, start, end) else r.intRangeLessThan(i8, start, end);429 const value: i32 = if (biased) r.intRangeLessThanBiased(i8, start, end) else r.intRangeLessThan(i8, start, end);
430 const index = @intCast(usize, value - start);430 const index = @as(usize, @intCast(value - start));
431 if (!values[index]) {431 if (!values[index]) {
432 i += 1;432 i += 1;
433 values[index] = true;433 values[index] = true;
lib/std/rand/ziggurat.zig+3-3
...@@ -18,17 +18,17 @@ pub fn next_f64(random: Random, comptime tables: ZigTable) f64 {...@@ -18,17 +18,17 @@ pub fn next_f64(random: Random, comptime tables: ZigTable) f64 {
18 // We manually construct a float from parts as we can avoid an extra random lookup here by18 // We manually construct a float from parts as we can avoid an extra random lookup here by
19 // using the unused exponent for the lookup table entry.19 // using the unused exponent for the lookup table entry.
20 const bits = random.int(u64);20 const bits = random.int(u64);
21 const i = @as(usize, @truncate(u8, bits));21 const i = @as(usize, @as(u8, @truncate(bits)));
2222
23 const u = blk: {23 const u = blk: {
24 if (tables.is_symmetric) {24 if (tables.is_symmetric) {
25 // Generate a value in the range [2, 4) and scale into [-1, 1)25 // Generate a value in the range [2, 4) and scale into [-1, 1)
26 const repr = ((0x3ff + 1) << 52) | (bits >> 12);26 const repr = ((0x3ff + 1) << 52) | (bits >> 12);
27 break :blk @bitCast(f64, repr) - 3.0;27 break :blk @as(f64, @bitCast(repr)) - 3.0;
28 } else {28 } else {
29 // Generate a value in the range [1, 2) and scale into (0, 1)29 // Generate a value in the range [1, 2) and scale into (0, 1)
30 const repr = (0x3ff << 52) | (bits >> 12);30 const repr = (0x3ff << 52) | (bits >> 12);
31 break :blk @bitCast(f64, repr) - (1.0 - math.floatEps(f64) / 2.0);31 break :blk @as(f64, @bitCast(repr)) - (1.0 - math.floatEps(f64) / 2.0);
32 }32 }
33 };33 };
3434
lib/std/segmented_list.zig+8-8
...@@ -107,7 +107,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -107,7 +107,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
107 }107 }
108108
109 pub fn deinit(self: *Self, allocator: Allocator) void {109 pub fn deinit(self: *Self, allocator: Allocator) void {
110 self.freeShelves(allocator, @intCast(ShelfIndex, self.dynamic_segments.len), 0);110 self.freeShelves(allocator, @as(ShelfIndex, @intCast(self.dynamic_segments.len)), 0);
111 allocator.free(self.dynamic_segments);111 allocator.free(self.dynamic_segments);
112 self.* = undefined;112 self.* = undefined;
113 }113 }
...@@ -171,7 +171,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -171,7 +171,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
171 /// TODO update this and related methods to match the conventions set by ArrayList171 /// TODO update this and related methods to match the conventions set by ArrayList
172 pub fn setCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {172 pub fn setCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
173 if (prealloc_item_count != 0) {173 if (prealloc_item_count != 0) {
174 if (new_capacity <= @as(usize, 1) << (prealloc_exp + @intCast(ShelfIndex, self.dynamic_segments.len))) {174 if (new_capacity <= @as(usize, 1) << (prealloc_exp + @as(ShelfIndex, @intCast(self.dynamic_segments.len)))) {
175 return self.shrinkCapacity(allocator, new_capacity);175 return self.shrinkCapacity(allocator, new_capacity);
176 }176 }
177 }177 }
...@@ -181,7 +181,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -181,7 +181,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
181 /// Only grows capacity, or retains current capacity.181 /// Only grows capacity, or retains current capacity.
182 pub fn growCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {182 pub fn growCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
183 const new_cap_shelf_count = shelfCount(new_capacity);183 const new_cap_shelf_count = shelfCount(new_capacity);
184 const old_shelf_count = @intCast(ShelfIndex, self.dynamic_segments.len);184 const old_shelf_count = @as(ShelfIndex, @intCast(self.dynamic_segments.len));
185 if (new_cap_shelf_count <= old_shelf_count) return;185 if (new_cap_shelf_count <= old_shelf_count) return;
186186
187 const new_dynamic_segments = try allocator.alloc([*]T, new_cap_shelf_count);187 const new_dynamic_segments = try allocator.alloc([*]T, new_cap_shelf_count);
...@@ -206,7 +206,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -206,7 +206,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
206 /// It may fail to reduce the capacity in which case the capacity will remain unchanged.206 /// It may fail to reduce the capacity in which case the capacity will remain unchanged.
207 pub fn shrinkCapacity(self: *Self, allocator: Allocator, new_capacity: usize) void {207 pub fn shrinkCapacity(self: *Self, allocator: Allocator, new_capacity: usize) void {
208 if (new_capacity <= prealloc_item_count) {208 if (new_capacity <= prealloc_item_count) {
209 const len = @intCast(ShelfIndex, self.dynamic_segments.len);209 const len = @as(ShelfIndex, @intCast(self.dynamic_segments.len));
210 self.freeShelves(allocator, len, 0);210 self.freeShelves(allocator, len, 0);
211 allocator.free(self.dynamic_segments);211 allocator.free(self.dynamic_segments);
212 self.dynamic_segments = &[_][*]T{};212 self.dynamic_segments = &[_][*]T{};
...@@ -214,7 +214,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -214,7 +214,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
214 }214 }
215215
216 const new_cap_shelf_count = shelfCount(new_capacity);216 const new_cap_shelf_count = shelfCount(new_capacity);
217 const old_shelf_count = @intCast(ShelfIndex, self.dynamic_segments.len);217 const old_shelf_count = @as(ShelfIndex, @intCast(self.dynamic_segments.len));
218 assert(new_cap_shelf_count <= old_shelf_count);218 assert(new_cap_shelf_count <= old_shelf_count);
219 if (new_cap_shelf_count == old_shelf_count) return;219 if (new_cap_shelf_count == old_shelf_count) return;
220220
...@@ -424,7 +424,7 @@ fn testSegmentedList(comptime prealloc: usize) !void {...@@ -424,7 +424,7 @@ fn testSegmentedList(comptime prealloc: usize) !void {
424 {424 {
425 var i: usize = 0;425 var i: usize = 0;
426 while (i < 100) : (i += 1) {426 while (i < 100) : (i += 1) {
427 try list.append(testing.allocator, @intCast(i32, i + 1));427 try list.append(testing.allocator, @as(i32, @intCast(i + 1)));
428 try testing.expect(list.len == i + 1);428 try testing.expect(list.len == i + 1);
429 }429 }
430 }430 }
...@@ -432,7 +432,7 @@ fn testSegmentedList(comptime prealloc: usize) !void {...@@ -432,7 +432,7 @@ fn testSegmentedList(comptime prealloc: usize) !void {
432 {432 {
433 var i: usize = 0;433 var i: usize = 0;
434 while (i < 100) : (i += 1) {434 while (i < 100) : (i += 1) {
435 try testing.expect(list.at(i).* == @intCast(i32, i + 1));435 try testing.expect(list.at(i).* == @as(i32, @intCast(i + 1)));
436 }436 }
437 }437 }
438438
...@@ -492,7 +492,7 @@ fn testSegmentedList(comptime prealloc: usize) !void {...@@ -492,7 +492,7 @@ fn testSegmentedList(comptime prealloc: usize) !void {
492 var i: i32 = 0;492 var i: i32 = 0;
493 while (i < 100) : (i += 1) {493 while (i < 100) : (i += 1) {
494 try list.append(testing.allocator, i + 1);494 try list.append(testing.allocator, i + 1);
495 control[@intCast(usize, i)] = i + 1;495 control[@as(usize, @intCast(i))] = i + 1;
496 }496 }
497497
498 @memset(dest[0..], 0);498 @memset(dest[0..], 0);
lib/std/simd.zig+12-12
...@@ -93,8 +93,8 @@ pub inline fn iota(comptime T: type, comptime len: usize) @Vector(len, T) {...@@ -93,8 +93,8 @@ pub inline fn iota(comptime T: type, comptime len: usize) @Vector(len, T) {
93 var out: [len]T = undefined;93 var out: [len]T = undefined;
94 for (&out, 0..) |*element, i| {94 for (&out, 0..) |*element, i| {
95 element.* = switch (@typeInfo(T)) {95 element.* = switch (@typeInfo(T)) {
96 .Int => @intCast(T, i),96 .Int => @as(T, @intCast(i)),
97 .Float => @floatFromInt(T, i),97 .Float => @as(T, @floatFromInt(i)),
98 else => @compileError("Can't use type " ++ @typeName(T) ++ " in iota."),98 else => @compileError("Can't use type " ++ @typeName(T) ++ " in iota."),
99 };99 };
100 }100 }
...@@ -107,7 +107,7 @@ pub inline fn iota(comptime T: type, comptime len: usize) @Vector(len, T) {...@@ -107,7 +107,7 @@ pub inline fn iota(comptime T: type, comptime len: usize) @Vector(len, T) {
107pub fn repeat(comptime len: usize, vec: anytype) @Vector(len, std.meta.Child(@TypeOf(vec))) {107pub fn repeat(comptime len: usize, vec: anytype) @Vector(len, std.meta.Child(@TypeOf(vec))) {
108 const Child = std.meta.Child(@TypeOf(vec));108 const Child = std.meta.Child(@TypeOf(vec));
109109
110 return @shuffle(Child, vec, undefined, iota(i32, len) % @splat(len, @intCast(i32, vectorLength(@TypeOf(vec)))));110 return @shuffle(Child, vec, undefined, iota(i32, len) % @splat(len, @as(i32, @intCast(vectorLength(@TypeOf(vec))))));
111}111}
112112
113/// Returns a vector containing all elements of the first vector at the lower indices followed by all elements of the second vector113/// Returns a vector containing all elements of the first vector at the lower indices followed by all elements of the second vector
...@@ -139,8 +139,8 @@ pub fn interlace(vecs: anytype) @Vector(vectorLength(@TypeOf(vecs[0])) * vecs.le...@@ -139,8 +139,8 @@ pub fn interlace(vecs: anytype) @Vector(vectorLength(@TypeOf(vecs[0])) * vecs.le
139 const a_vec_count = (1 + vecs_arr.len) >> 1;139 const a_vec_count = (1 + vecs_arr.len) >> 1;
140 const b_vec_count = vecs_arr.len >> 1;140 const b_vec_count = vecs_arr.len >> 1;
141141
142 const a = interlace(@ptrCast(*const [a_vec_count]VecType, vecs_arr[0..a_vec_count]).*);142 const a = interlace(@as(*const [a_vec_count]VecType, @ptrCast(vecs_arr[0..a_vec_count])).*);
143 const b = interlace(@ptrCast(*const [b_vec_count]VecType, vecs_arr[a_vec_count..]).*);143 const b = interlace(@as(*const [b_vec_count]VecType, @ptrCast(vecs_arr[a_vec_count..])).*);
144144
145 const a_len = vectorLength(@TypeOf(a));145 const a_len = vectorLength(@TypeOf(a));
146 const b_len = vectorLength(@TypeOf(b));146 const b_len = vectorLength(@TypeOf(b));
...@@ -148,10 +148,10 @@ pub fn interlace(vecs: anytype) @Vector(vectorLength(@TypeOf(vecs[0])) * vecs.le...@@ -148,10 +148,10 @@ pub fn interlace(vecs: anytype) @Vector(vectorLength(@TypeOf(vecs[0])) * vecs.le
148148
149 const indices = comptime blk: {149 const indices = comptime blk: {
150 const count_up = iota(i32, len);150 const count_up = iota(i32, len);
151 const cycle = @divFloor(count_up, @splat(len, @intCast(i32, vecs_arr.len)));151 const cycle = @divFloor(count_up, @splat(len, @as(i32, @intCast(vecs_arr.len))));
152 const select_mask = repeat(len, join(@splat(a_vec_count, true), @splat(b_vec_count, false)));152 const select_mask = repeat(len, join(@splat(a_vec_count, true), @splat(b_vec_count, false)));
153 const a_indices = count_up - cycle * @splat(len, @intCast(i32, b_vec_count));153 const a_indices = count_up - cycle * @splat(len, @as(i32, @intCast(b_vec_count)));
154 const b_indices = shiftElementsRight(count_up - cycle * @splat(len, @intCast(i32, a_vec_count)), a_vec_count, 0);154 const b_indices = shiftElementsRight(count_up - cycle * @splat(len, @as(i32, @intCast(a_vec_count))), a_vec_count, 0);
155 break :blk @select(i32, select_mask, a_indices, ~b_indices);155 break :blk @select(i32, select_mask, a_indices, ~b_indices);
156 };156 };
157157
...@@ -174,7 +174,7 @@ pub fn deinterlace(...@@ -174,7 +174,7 @@ pub fn deinterlace(
174174
175 comptime var i: usize = 0; // for-loops don't work for this, apparently.175 comptime var i: usize = 0; // for-loops don't work for this, apparently.
176 inline while (i < out.len) : (i += 1) {176 inline while (i < out.len) : (i += 1) {
177 const indices = comptime iota(i32, vec_len) * @splat(vec_len, @intCast(i32, vec_count)) + @splat(vec_len, @intCast(i32, i));177 const indices = comptime iota(i32, vec_len) * @splat(vec_len, @as(i32, @intCast(vec_count))) + @splat(vec_len, @as(i32, @intCast(i)));
178 out[i] = @shuffle(Child, interlaced, undefined, indices);178 out[i] = @shuffle(Child, interlaced, undefined, indices);
179 }179 }
180180
...@@ -189,9 +189,9 @@ pub fn extract(...@@ -189,9 +189,9 @@ pub fn extract(
189 const Child = std.meta.Child(@TypeOf(vec));189 const Child = std.meta.Child(@TypeOf(vec));
190 const len = vectorLength(@TypeOf(vec));190 const len = vectorLength(@TypeOf(vec));
191191
192 std.debug.assert(@intCast(comptime_int, first) + @intCast(comptime_int, count) <= len);192 std.debug.assert(@as(comptime_int, @intCast(first)) + @as(comptime_int, @intCast(count)) <= len);
193193
194 return @shuffle(Child, vec, undefined, iota(i32, count) + @splat(count, @intCast(i32, first)));194 return @shuffle(Child, vec, undefined, iota(i32, count) + @splat(count, @as(i32, @intCast(first))));
195}195}
196196
197test "vector patterns" {197test "vector patterns" {
...@@ -263,7 +263,7 @@ pub fn reverseOrder(vec: anytype) @TypeOf(vec) {...@@ -263,7 +263,7 @@ pub fn reverseOrder(vec: anytype) @TypeOf(vec) {
263 const Child = std.meta.Child(@TypeOf(vec));263 const Child = std.meta.Child(@TypeOf(vec));
264 const len = vectorLength(@TypeOf(vec));264 const len = vectorLength(@TypeOf(vec));
265265
266 return @shuffle(Child, vec, undefined, @splat(len, @intCast(i32, len) - 1) - iota(i32, len));266 return @shuffle(Child, vec, undefined, @splat(len, @as(i32, @intCast(len)) - 1) - iota(i32, len));
267}267}
268268
269test "vector shifting" {269test "vector shifting" {
lib/std/sort/pdq.zig+2-2
...@@ -251,7 +251,7 @@ fn breakPatterns(a: usize, b: usize, context: anytype) void {...@@ -251,7 +251,7 @@ fn breakPatterns(a: usize, b: usize, context: anytype) void {
251 const len = b - a;251 const len = b - a;
252 if (len < 8) return;252 if (len < 8) return;
253253
254 var rand = @intCast(u64, len);254 var rand = @as(u64, @intCast(len));
255 const modulus = math.ceilPowerOfTwoAssert(u64, len);255 const modulus = math.ceilPowerOfTwoAssert(u64, len);
256256
257 var i = a + (len / 4) * 2 - 1;257 var i = a + (len / 4) * 2 - 1;
...@@ -261,7 +261,7 @@ fn breakPatterns(a: usize, b: usize, context: anytype) void {...@@ -261,7 +261,7 @@ fn breakPatterns(a: usize, b: usize, context: anytype) void {
261 rand ^= rand >> 7;261 rand ^= rand >> 7;
262 rand ^= rand << 17;262 rand ^= rand << 17;
263263
264 var other = @intCast(usize, rand & (modulus - 1));264 var other = @as(usize, @intCast(rand & (modulus - 1)));
265 if (other >= len) other -= len;265 if (other >= len) other -= len;
266 context.swap(i, a + other);266 context.swap(i, a + other);
267 }267 }
lib/std/start.zig+12-12
...@@ -190,7 +190,7 @@ fn exit2(code: usize) noreturn {...@@ -190,7 +190,7 @@ fn exit2(code: usize) noreturn {
190 else => @compileError("TODO"),190 else => @compileError("TODO"),
191 },191 },
192 .windows => {192 .windows => {
193 ExitProcess(@truncate(u32, code));193 ExitProcess(@as(u32, @truncate(code)));
194 },194 },
195 else => @compileError("TODO"),195 else => @compileError("TODO"),
196 }196 }
...@@ -387,23 +387,23 @@ fn wWinMainCRTStartup() callconv(std.os.windows.WINAPI) noreturn {...@@ -387,23 +387,23 @@ fn wWinMainCRTStartup() callconv(std.os.windows.WINAPI) noreturn {
387 std.debug.maybeEnableSegfaultHandler();387 std.debug.maybeEnableSegfaultHandler();
388388
389 const result: std.os.windows.INT = initEventLoopAndCallWinMain();389 const result: std.os.windows.INT = initEventLoopAndCallWinMain();
390 std.os.windows.kernel32.ExitProcess(@bitCast(std.os.windows.UINT, result));390 std.os.windows.kernel32.ExitProcess(@as(std.os.windows.UINT, @bitCast(result)));
391}391}
392392
393fn posixCallMainAndExit() callconv(.C) noreturn {393fn posixCallMainAndExit() callconv(.C) noreturn {
394 @setAlignStack(16);394 @setAlignStack(16);
395395
396 const argc = argc_argv_ptr[0];396 const argc = argc_argv_ptr[0];
397 const argv = @ptrCast([*][*:0]u8, argc_argv_ptr + 1);397 const argv = @as([*][*:0]u8, @ptrCast(argc_argv_ptr + 1));
398398
399 const envp_optional = @ptrCast([*:null]?[*:0]u8, @alignCast(@alignOf(usize), argv + argc + 1));399 const envp_optional: [*:null]?[*:0]u8 = @ptrCast(@alignCast(argv + argc + 1));
400 var envp_count: usize = 0;400 var envp_count: usize = 0;
401 while (envp_optional[envp_count]) |_| : (envp_count += 1) {}401 while (envp_optional[envp_count]) |_| : (envp_count += 1) {}
402 const envp = @ptrCast([*][*:0]u8, envp_optional)[0..envp_count];402 const envp = @as([*][*:0]u8, @ptrCast(envp_optional))[0..envp_count];
403403
404 if (native_os == .linux) {404 if (native_os == .linux) {
405 // Find the beginning of the auxiliary vector405 // Find the beginning of the auxiliary vector
406 const auxv = @ptrCast([*]elf.Auxv, @alignCast(@alignOf(usize), envp.ptr + envp_count + 1));406 const auxv: [*]elf.Auxv = @ptrCast(@alignCast(envp.ptr + envp_count + 1));
407 std.os.linux.elf_aux_maybe = auxv;407 std.os.linux.elf_aux_maybe = auxv;
408408
409 var at_hwcap: usize = 0;409 var at_hwcap: usize = 0;
...@@ -419,7 +419,7 @@ fn posixCallMainAndExit() callconv(.C) noreturn {...@@ -419,7 +419,7 @@ fn posixCallMainAndExit() callconv(.C) noreturn {
419 else => continue,419 else => continue,
420 }420 }
421 }421 }
422 break :init @ptrFromInt([*]elf.Phdr, at_phdr)[0..at_phnum];422 break :init @as([*]elf.Phdr, @ptrFromInt(at_phdr))[0..at_phnum];
423 };423 };
424424
425 // Apply the initial relocations as early as possible in the startup425 // Apply the initial relocations as early as possible in the startup
...@@ -495,20 +495,20 @@ fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 {...@@ -495,20 +495,20 @@ fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 {
495fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) callconv(.C) c_int {495fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) callconv(.C) c_int {
496 var env_count: usize = 0;496 var env_count: usize = 0;
497 while (c_envp[env_count] != null) : (env_count += 1) {}497 while (c_envp[env_count] != null) : (env_count += 1) {}
498 const envp = @ptrCast([*][*:0]u8, c_envp)[0..env_count];498 const envp = @as([*][*:0]u8, @ptrCast(c_envp))[0..env_count];
499499
500 if (builtin.os.tag == .linux) {500 if (builtin.os.tag == .linux) {
501 const at_phdr = std.c.getauxval(elf.AT_PHDR);501 const at_phdr = std.c.getauxval(elf.AT_PHDR);
502 const at_phnum = std.c.getauxval(elf.AT_PHNUM);502 const at_phnum = std.c.getauxval(elf.AT_PHNUM);
503 const phdrs = (@ptrFromInt([*]elf.Phdr, at_phdr))[0..at_phnum];503 const phdrs = (@as([*]elf.Phdr, @ptrFromInt(at_phdr)))[0..at_phnum];
504 expandStackSize(phdrs);504 expandStackSize(phdrs);
505 }505 }
506506
507 return @call(.always_inline, callMainWithArgs, .{ @intCast(usize, c_argc), @ptrCast([*][*:0]u8, c_argv), envp });507 return @call(.always_inline, callMainWithArgs, .{ @as(usize, @intCast(c_argc)), @as([*][*:0]u8, @ptrCast(c_argv)), envp });
508}508}
509509
510fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]c_char) callconv(.C) c_int {510fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]c_char) callconv(.C) c_int {
511 std.os.argv = @ptrCast([*][*:0]u8, c_argv)[0..@intCast(usize, c_argc)];511 std.os.argv = @as([*][*:0]u8, @ptrCast(c_argv))[0..@as(usize, @intCast(c_argc))];
512 return @call(.always_inline, callMain, .{});512 return @call(.always_inline, callMain, .{});
513}513}
514514
...@@ -629,7 +629,7 @@ pub fn callMain() u8 {...@@ -629,7 +629,7 @@ pub fn callMain() u8 {
629629
630pub fn call_wWinMain() std.os.windows.INT {630pub fn call_wWinMain() std.os.windows.INT {
631 const MAIN_HINSTANCE = @typeInfo(@TypeOf(root.wWinMain)).Fn.params[0].type.?;631 const MAIN_HINSTANCE = @typeInfo(@TypeOf(root.wWinMain)).Fn.params[0].type.?;
632 const hInstance = @ptrCast(MAIN_HINSTANCE, std.os.windows.kernel32.GetModuleHandleW(null).?);632 const hInstance = @as(MAIN_HINSTANCE, @ptrCast(std.os.windows.kernel32.GetModuleHandleW(null).?));
633 const lpCmdLine = std.os.windows.kernel32.GetCommandLineW();633 const lpCmdLine = std.os.windows.kernel32.GetCommandLineW();
634634
635 // There's no (documented) way to get the nCmdShow parameter, so we're635 // There's no (documented) way to get the nCmdShow parameter, so we're
lib/std/start_windows_tls.zig+1-1
...@@ -42,7 +42,7 @@ export const _tls_used linksection(".rdata$T") = IMAGE_TLS_DIRECTORY{...@@ -42,7 +42,7 @@ export const _tls_used linksection(".rdata$T") = IMAGE_TLS_DIRECTORY{
42 .StartAddressOfRawData = &_tls_start,42 .StartAddressOfRawData = &_tls_start,
43 .EndAddressOfRawData = &_tls_end,43 .EndAddressOfRawData = &_tls_end,
44 .AddressOfIndex = &_tls_index,44 .AddressOfIndex = &_tls_index,
45 .AddressOfCallBacks = @ptrCast(*anyopaque, &__xl_a),45 .AddressOfCallBacks = @as(*anyopaque, @ptrCast(&__xl_a)),
46 .SizeOfZeroFill = 0,46 .SizeOfZeroFill = 0,
47 .Characteristics = 0,47 .Characteristics = 0,
48};48};
lib/std/tar.zig+7-7
...@@ -70,8 +70,8 @@ pub const Header = struct {...@@ -70,8 +70,8 @@ pub const Header = struct {
70 }70 }
7171
72 pub fn fileType(header: Header) FileType {72 pub fn fileType(header: Header) FileType {
73 const result = @enumFromInt(FileType, header.bytes[156]);73 const result = @as(FileType, @enumFromInt(header.bytes[156]));
74 return if (result == @enumFromInt(FileType, 0)) .normal else result;74 return if (result == @as(FileType, @enumFromInt(0))) .normal else result;
75 }75 }
7676
77 fn str(header: Header, start: usize, end: usize) []const u8 {77 fn str(header: Header, start: usize, end: usize) []const u8 {
...@@ -117,7 +117,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi...@@ -117,7 +117,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
117 start += 512;117 start += 512;
118 const file_size = try header.fileSize();118 const file_size = try header.fileSize();
119 const rounded_file_size = std.mem.alignForward(u64, file_size, 512);119 const rounded_file_size = std.mem.alignForward(u64, file_size, 512);
120 const pad_len = @intCast(usize, rounded_file_size - file_size);120 const pad_len = @as(usize, @intCast(rounded_file_size - file_size));
121 const unstripped_file_name = try header.fullFileName(&file_name_buffer);121 const unstripped_file_name = try header.fullFileName(&file_name_buffer);
122 switch (header.fileType()) {122 switch (header.fileType()) {
123 .directory => {123 .directory => {
...@@ -146,14 +146,14 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi...@@ -146,14 +146,14 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
146 }146 }
147 // Ask for the rounded up file size + 512 for the next header.147 // Ask for the rounded up file size + 512 for the next header.
148 // TODO: https://github.com/ziglang/zig/issues/14039148 // TODO: https://github.com/ziglang/zig/issues/14039
149 const ask = @intCast(usize, @min(149 const ask = @as(usize, @intCast(@min(
150 buffer.len - end,150 buffer.len - end,
151 rounded_file_size + 512 - file_off -| (end - start),151 rounded_file_size + 512 - file_off -| (end - start),
152 ));152 )));
153 end += try reader.readAtLeast(buffer[end..], ask);153 end += try reader.readAtLeast(buffer[end..], ask);
154 if (end - start < ask) return error.UnexpectedEndOfStream;154 if (end - start < ask) return error.UnexpectedEndOfStream;
155 // TODO: https://github.com/ziglang/zig/issues/14039155 // TODO: https://github.com/ziglang/zig/issues/14039
156 const slice = buffer[start..@intCast(usize, @min(file_size - file_off + start, end))];156 const slice = buffer[start..@as(usize, @intCast(@min(file_size - file_off + start, end)))];
157 try file.writeAll(slice);157 try file.writeAll(slice);
158 file_off += slice.len;158 file_off += slice.len;
159 start += slice.len;159 start += slice.len;
...@@ -167,7 +167,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi...@@ -167,7 +167,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
167 },167 },
168 .global_extended_header, .extended_header => {168 .global_extended_header, .extended_header => {
169 if (start + rounded_file_size > end) return error.TarHeadersTooBig;169 if (start + rounded_file_size > end) return error.TarHeadersTooBig;
170 start = @intCast(usize, start + rounded_file_size);170 start = @as(usize, @intCast(start + rounded_file_size));
171 },171 },
172 .hard_link => return error.TarUnsupportedFileType,172 .hard_link => return error.TarUnsupportedFileType,
173 .symbolic_link => return error.TarUnsupportedFileType,173 .symbolic_link => return error.TarUnsupportedFileType,
lib/std/target.zig+9-9
...@@ -711,14 +711,14 @@ pub const Target = struct {...@@ -711,14 +711,14 @@ pub const Target = struct {
711711
712 pub fn isEnabled(set: Set, arch_feature_index: Index) bool {712 pub fn isEnabled(set: Set, arch_feature_index: Index) bool {
713 const usize_index = arch_feature_index / @bitSizeOf(usize);713 const usize_index = arch_feature_index / @bitSizeOf(usize);
714 const bit_index = @intCast(ShiftInt, arch_feature_index % @bitSizeOf(usize));714 const bit_index = @as(ShiftInt, @intCast(arch_feature_index % @bitSizeOf(usize)));
715 return (set.ints[usize_index] & (@as(usize, 1) << bit_index)) != 0;715 return (set.ints[usize_index] & (@as(usize, 1) << bit_index)) != 0;
716 }716 }
717717
718 /// Adds the specified feature but not its dependencies.718 /// Adds the specified feature but not its dependencies.
719 pub fn addFeature(set: *Set, arch_feature_index: Index) void {719 pub fn addFeature(set: *Set, arch_feature_index: Index) void {
720 const usize_index = arch_feature_index / @bitSizeOf(usize);720 const usize_index = arch_feature_index / @bitSizeOf(usize);
721 const bit_index = @intCast(ShiftInt, arch_feature_index % @bitSizeOf(usize));721 const bit_index = @as(ShiftInt, @intCast(arch_feature_index % @bitSizeOf(usize)));
722 set.ints[usize_index] |= @as(usize, 1) << bit_index;722 set.ints[usize_index] |= @as(usize, 1) << bit_index;
723 }723 }
724724
...@@ -730,7 +730,7 @@ pub const Target = struct {...@@ -730,7 +730,7 @@ pub const Target = struct {
730 /// Removes the specified feature but not its dependents.730 /// Removes the specified feature but not its dependents.
731 pub fn removeFeature(set: *Set, arch_feature_index: Index) void {731 pub fn removeFeature(set: *Set, arch_feature_index: Index) void {
732 const usize_index = arch_feature_index / @bitSizeOf(usize);732 const usize_index = arch_feature_index / @bitSizeOf(usize);
733 const bit_index = @intCast(ShiftInt, arch_feature_index % @bitSizeOf(usize));733 const bit_index = @as(ShiftInt, @intCast(arch_feature_index % @bitSizeOf(usize)));
734 set.ints[usize_index] &= ~(@as(usize, 1) << bit_index);734 set.ints[usize_index] &= ~(@as(usize, 1) << bit_index);
735 }735 }
736736
...@@ -745,7 +745,7 @@ pub const Target = struct {...@@ -745,7 +745,7 @@ pub const Target = struct {
745 var old = set.ints;745 var old = set.ints;
746 while (true) {746 while (true) {
747 for (all_features_list, 0..) |feature, index_usize| {747 for (all_features_list, 0..) |feature, index_usize| {
748 const index = @intCast(Index, index_usize);748 const index = @as(Index, @intCast(index_usize));
749 if (set.isEnabled(index)) {749 if (set.isEnabled(index)) {
750 set.addFeatureSet(feature.dependencies);750 set.addFeatureSet(feature.dependencies);
751 }751 }
...@@ -757,7 +757,7 @@ pub const Target = struct {...@@ -757,7 +757,7 @@ pub const Target = struct {
757 }757 }
758758
759 pub fn asBytes(set: *const Set) *const [byte_count]u8 {759 pub fn asBytes(set: *const Set) *const [byte_count]u8 {
760 return @ptrCast(*const [byte_count]u8, &set.ints);760 return @as(*const [byte_count]u8, @ptrCast(&set.ints));
761 }761 }
762762
763 pub fn eql(set: Set, other_set: Set) bool {763 pub fn eql(set: Set, other_set: Set) bool {
...@@ -1526,7 +1526,7 @@ pub const Target = struct {...@@ -1526,7 +1526,7 @@ pub const Target = struct {
1526 pub fn set(self: *DynamicLinker, dl_or_null: ?[]const u8) void {1526 pub fn set(self: *DynamicLinker, dl_or_null: ?[]const u8) void {
1527 if (dl_or_null) |dl| {1527 if (dl_or_null) |dl| {
1528 @memcpy(self.buffer[0..dl.len], dl);1528 @memcpy(self.buffer[0..dl.len], dl);
1529 self.max_byte = @intCast(u8, dl.len - 1);1529 self.max_byte = @as(u8, @intCast(dl.len - 1));
1530 } else {1530 } else {
1531 self.max_byte = null;1531 self.max_byte = null;
1532 }1532 }
...@@ -1537,12 +1537,12 @@ pub const Target = struct {...@@ -1537,12 +1537,12 @@ pub const Target = struct {
1537 var result: DynamicLinker = .{};1537 var result: DynamicLinker = .{};
1538 const S = struct {1538 const S = struct {
1539 fn print(r: *DynamicLinker, comptime fmt: []const u8, args: anytype) DynamicLinker {1539 fn print(r: *DynamicLinker, comptime fmt: []const u8, args: anytype) DynamicLinker {
1540 r.max_byte = @intCast(u8, (std.fmt.bufPrint(&r.buffer, fmt, args) catch unreachable).len - 1);1540 r.max_byte = @as(u8, @intCast((std.fmt.bufPrint(&r.buffer, fmt, args) catch unreachable).len - 1));
1541 return r.*;1541 return r.*;
1542 }1542 }
1543 fn copy(r: *DynamicLinker, s: []const u8) DynamicLinker {1543 fn copy(r: *DynamicLinker, s: []const u8) DynamicLinker {
1544 @memcpy(r.buffer[0..s.len], s);1544 @memcpy(r.buffer[0..s.len], s);
1545 r.max_byte = @intCast(u8, s.len - 1);1545 r.max_byte = @as(u8, @intCast(s.len - 1));
1546 return r.*;1546 return r.*;
1547 }1547 }
1548 };1548 };
...@@ -1970,7 +1970,7 @@ pub const Target = struct {...@@ -1970,7 +1970,7 @@ pub const Target = struct {
1970 16 => 2,1970 16 => 2,
1971 32 => 4,1971 32 => 4,
1972 64 => 8,1972 64 => 8,
1973 80 => @intCast(u16, mem.alignForward(usize, 10, c_type_alignment(t, .longdouble))),1973 80 => @as(u16, @intCast(mem.alignForward(usize, 10, c_type_alignment(t, .longdouble)))),
1974 128 => 16,1974 128 => 16,
1975 else => unreachable,1975 else => unreachable,
1976 },1976 },
lib/std/testing/failing_allocator.zig+3-3
...@@ -63,7 +63,7 @@ pub const FailingAllocator = struct {...@@ -63,7 +63,7 @@ pub const FailingAllocator = struct {
63 log2_ptr_align: u8,63 log2_ptr_align: u8,
64 return_address: usize,64 return_address: usize,
65 ) ?[*]u8 {65 ) ?[*]u8 {
66 const self = @ptrCast(*FailingAllocator, @alignCast(@alignOf(FailingAllocator), ctx));66 const self: *FailingAllocator = @ptrCast(@alignCast(ctx));
67 if (self.index == self.fail_index) {67 if (self.index == self.fail_index) {
68 if (!self.has_induced_failure) {68 if (!self.has_induced_failure) {
69 @memset(&self.stack_addresses, 0);69 @memset(&self.stack_addresses, 0);
...@@ -91,7 +91,7 @@ pub const FailingAllocator = struct {...@@ -91,7 +91,7 @@ pub const FailingAllocator = struct {
91 new_len: usize,91 new_len: usize,
92 ra: usize,92 ra: usize,
93 ) bool {93 ) bool {
94 const self = @ptrCast(*FailingAllocator, @alignCast(@alignOf(FailingAllocator), ctx));94 const self: *FailingAllocator = @ptrCast(@alignCast(ctx));
95 if (!self.internal_allocator.rawResize(old_mem, log2_old_align, new_len, ra))95 if (!self.internal_allocator.rawResize(old_mem, log2_old_align, new_len, ra))
96 return false;96 return false;
97 if (new_len < old_mem.len) {97 if (new_len < old_mem.len) {
...@@ -108,7 +108,7 @@ pub const FailingAllocator = struct {...@@ -108,7 +108,7 @@ pub const FailingAllocator = struct {
108 log2_old_align: u8,108 log2_old_align: u8,
109 ra: usize,109 ra: usize,
110 ) void {110 ) void {
111 const self = @ptrCast(*FailingAllocator, @alignCast(@alignOf(FailingAllocator), ctx));111 const self: *FailingAllocator = @ptrCast(@alignCast(ctx));
112 self.internal_allocator.rawFree(old_mem, log2_old_align, ra);112 self.internal_allocator.rawFree(old_mem, log2_old_align, ra);
113 self.deallocations += 1;113 self.deallocations += 1;
114 self.freed_bytes += old_mem.len;114 self.freed_bytes += old_mem.len;
lib/std/time.zig+8-8
...@@ -70,7 +70,7 @@ pub fn timestamp() i64 {...@@ -70,7 +70,7 @@ pub fn timestamp() i64 {
70/// before the epoch.70/// before the epoch.
71/// See `std.os.clock_gettime` for a POSIX timestamp.71/// See `std.os.clock_gettime` for a POSIX timestamp.
72pub fn milliTimestamp() i64 {72pub fn milliTimestamp() i64 {
73 return @intCast(i64, @divFloor(nanoTimestamp(), ns_per_ms));73 return @as(i64, @intCast(@divFloor(nanoTimestamp(), ns_per_ms)));
74}74}
7575
76/// Get a calendar timestamp, in microseconds, relative to UTC 1970-01-01.76/// Get a calendar timestamp, in microseconds, relative to UTC 1970-01-01.
...@@ -79,7 +79,7 @@ pub fn milliTimestamp() i64 {...@@ -79,7 +79,7 @@ pub fn milliTimestamp() i64 {
79/// before the epoch.79/// before the epoch.
80/// See `std.os.clock_gettime` for a POSIX timestamp.80/// See `std.os.clock_gettime` for a POSIX timestamp.
81pub fn microTimestamp() i64 {81pub fn microTimestamp() i64 {
82 return @intCast(i64, @divFloor(nanoTimestamp(), ns_per_us));82 return @as(i64, @intCast(@divFloor(nanoTimestamp(), ns_per_us)));
83}83}
8484
85/// Get a calendar timestamp, in nanoseconds, relative to UTC 1970-01-01.85/// Get a calendar timestamp, in nanoseconds, relative to UTC 1970-01-01.
...@@ -96,7 +96,7 @@ pub fn nanoTimestamp() i128 {...@@ -96,7 +96,7 @@ pub fn nanoTimestamp() i128 {
96 var ft: os.windows.FILETIME = undefined;96 var ft: os.windows.FILETIME = undefined;
97 os.windows.kernel32.GetSystemTimeAsFileTime(&ft);97 os.windows.kernel32.GetSystemTimeAsFileTime(&ft);
98 const ft64 = (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime;98 const ft64 = (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
99 return @as(i128, @bitCast(i64, ft64) + epoch_adj) * 100;99 return @as(i128, @as(i64, @bitCast(ft64)) + epoch_adj) * 100;
100 }100 }
101101
102 if (builtin.os.tag == .wasi and !builtin.link_libc) {102 if (builtin.os.tag == .wasi and !builtin.link_libc) {
...@@ -239,9 +239,9 @@ pub const Instant = struct {...@@ -239,9 +239,9 @@ pub const Instant = struct {
239 }239 }
240240
241 // Convert to ns using fixed point.241 // Convert to ns using fixed point.
242 const scale = @as(u64, std.time.ns_per_s << 32) / @intCast(u32, qpf);242 const scale = @as(u64, std.time.ns_per_s << 32) / @as(u32, @intCast(qpf));
243 const result = (@as(u96, qpc) * scale) >> 32;243 const result = (@as(u96, qpc) * scale) >> 32;
244 return @truncate(u64, result);244 return @as(u64, @truncate(result));
245 }245 }
246246
247 // WASI timestamps are directly in nanoseconds247 // WASI timestamps are directly in nanoseconds
...@@ -250,9 +250,9 @@ pub const Instant = struct {...@@ -250,9 +250,9 @@ pub const Instant = struct {
250 }250 }
251251
252 // Convert timespec diff to ns252 // Convert timespec diff to ns
253 const seconds = @intCast(u64, self.timestamp.tv_sec - earlier.timestamp.tv_sec);253 const seconds = @as(u64, @intCast(self.timestamp.tv_sec - earlier.timestamp.tv_sec));
254 const elapsed = (seconds * ns_per_s) + @intCast(u32, self.timestamp.tv_nsec);254 const elapsed = (seconds * ns_per_s) + @as(u32, @intCast(self.timestamp.tv_nsec));
255 return elapsed - @intCast(u32, earlier.timestamp.tv_nsec);255 return elapsed - @as(u32, @intCast(earlier.timestamp.tv_nsec));
256 }256 }
257};257};
258258
lib/std/time/epoch.zig+6-6
...@@ -122,9 +122,9 @@ pub const YearAndDay = struct {...@@ -122,9 +122,9 @@ pub const YearAndDay = struct {
122 if (days_left < days_in_month)122 if (days_left < days_in_month)
123 break;123 break;
124 days_left -= days_in_month;124 days_left -= days_in_month;
125 month = @enumFromInt(Month, @intFromEnum(month) + 1);125 month = @as(Month, @enumFromInt(@intFromEnum(month) + 1));
126 }126 }
127 return .{ .month = month, .day_index = @intCast(u5, days_left) };127 return .{ .month = month, .day_index = @as(u5, @intCast(days_left)) };
128 }128 }
129};129};
130130
...@@ -146,7 +146,7 @@ pub const EpochDay = struct {...@@ -146,7 +146,7 @@ pub const EpochDay = struct {
146 year_day -= year_size;146 year_day -= year_size;
147 year += 1;147 year += 1;
148 }148 }
149 return .{ .year = year, .day = @intCast(u9, year_day) };149 return .{ .year = year, .day = @as(u9, @intCast(year_day)) };
150 }150 }
151};151};
152152
...@@ -156,11 +156,11 @@ pub const DaySeconds = struct {...@@ -156,11 +156,11 @@ pub const DaySeconds = struct {
156156
157 /// the number of hours past the start of the day (0 to 23)157 /// the number of hours past the start of the day (0 to 23)
158 pub fn getHoursIntoDay(self: DaySeconds) u5 {158 pub fn getHoursIntoDay(self: DaySeconds) u5 {
159 return @intCast(u5, @divTrunc(self.secs, 3600));159 return @as(u5, @intCast(@divTrunc(self.secs, 3600)));
160 }160 }
161 /// the number of minutes past the hour (0 to 59)161 /// the number of minutes past the hour (0 to 59)
162 pub fn getMinutesIntoHour(self: DaySeconds) u6 {162 pub fn getMinutesIntoHour(self: DaySeconds) u6 {
163 return @intCast(u6, @divTrunc(@mod(self.secs, 3600), 60));163 return @as(u6, @intCast(@divTrunc(@mod(self.secs, 3600), 60)));
164 }164 }
165 /// the number of seconds past the start of the minute (0 to 59)165 /// the number of seconds past the start of the minute (0 to 59)
166 pub fn getSecondsIntoMinute(self: DaySeconds) u6 {166 pub fn getSecondsIntoMinute(self: DaySeconds) u6 {
...@@ -175,7 +175,7 @@ pub const EpochSeconds = struct {...@@ -175,7 +175,7 @@ pub const EpochSeconds = struct {
175 /// Returns the number of days since the epoch as an EpochDay.175 /// Returns the number of days since the epoch as an EpochDay.
176 /// Use EpochDay to get information about the day of this time.176 /// Use EpochDay to get information about the day of this time.
177 pub fn getEpochDay(self: EpochSeconds) EpochDay {177 pub fn getEpochDay(self: EpochSeconds) EpochDay {
178 return EpochDay{ .day = @intCast(u47, @divTrunc(self.secs, secs_per_day)) };178 return EpochDay{ .day = @as(u47, @intCast(@divTrunc(self.secs, secs_per_day))) };
179 }179 }
180180
181 /// Returns the number of seconds into the day as DaySeconds.181 /// Returns the number of seconds into the day as DaySeconds.
lib/std/tz.zig+2-2
...@@ -155,8 +155,8 @@ pub const Tz = struct {...@@ -155,8 +155,8 @@ pub const Tz = struct {
155 if (corr > std.math.maxInt(i16)) return error.Malformed; // Unreasonably large correction155 if (corr > std.math.maxInt(i16)) return error.Malformed; // Unreasonably large correction
156156
157 leapseconds[i] = .{157 leapseconds[i] = .{
158 .occurrence = @intCast(i48, occur),158 .occurrence = @as(i48, @intCast(occur)),
159 .correction = @intCast(i16, corr),159 .correction = @as(i16, @intCast(corr)),
160 };160 };
161 }161 }
162162
lib/std/unicode.zig+16-16
...@@ -45,22 +45,22 @@ pub fn utf8Encode(c: u21, out: []u8) !u3 {...@@ -45,22 +45,22 @@ pub fn utf8Encode(c: u21, out: []u8) !u3 {
45 // - Increasing the initial shift by 6 each time45 // - Increasing the initial shift by 6 each time
46 // - Each time after the first shorten the shifted46 // - Each time after the first shorten the shifted
47 // value to a max of 0b111111 (63)47 // value to a max of 0b111111 (63)
48 1 => out[0] = @intCast(u8, c), // Can just do 0 + codepoint for initial range48 1 => out[0] = @as(u8, @intCast(c)), // Can just do 0 + codepoint for initial range
49 2 => {49 2 => {
50 out[0] = @intCast(u8, 0b11000000 | (c >> 6));50 out[0] = @as(u8, @intCast(0b11000000 | (c >> 6)));
51 out[1] = @intCast(u8, 0b10000000 | (c & 0b111111));51 out[1] = @as(u8, @intCast(0b10000000 | (c & 0b111111)));
52 },52 },
53 3 => {53 3 => {
54 if (0xd800 <= c and c <= 0xdfff) return error.Utf8CannotEncodeSurrogateHalf;54 if (0xd800 <= c and c <= 0xdfff) return error.Utf8CannotEncodeSurrogateHalf;
55 out[0] = @intCast(u8, 0b11100000 | (c >> 12));55 out[0] = @as(u8, @intCast(0b11100000 | (c >> 12)));
56 out[1] = @intCast(u8, 0b10000000 | ((c >> 6) & 0b111111));56 out[1] = @as(u8, @intCast(0b10000000 | ((c >> 6) & 0b111111)));
57 out[2] = @intCast(u8, 0b10000000 | (c & 0b111111));57 out[2] = @as(u8, @intCast(0b10000000 | (c & 0b111111)));
58 },58 },
59 4 => {59 4 => {
60 out[0] = @intCast(u8, 0b11110000 | (c >> 18));60 out[0] = @as(u8, @intCast(0b11110000 | (c >> 18)));
61 out[1] = @intCast(u8, 0b10000000 | ((c >> 12) & 0b111111));61 out[1] = @as(u8, @intCast(0b10000000 | ((c >> 12) & 0b111111)));
62 out[2] = @intCast(u8, 0b10000000 | ((c >> 6) & 0b111111));62 out[2] = @as(u8, @intCast(0b10000000 | ((c >> 6) & 0b111111)));
63 out[3] = @intCast(u8, 0b10000000 | (c & 0b111111));63 out[3] = @as(u8, @intCast(0b10000000 | (c & 0b111111)));
64 },64 },
65 else => unreachable,65 else => unreachable,
66 }66 }
...@@ -695,11 +695,11 @@ pub fn utf8ToUtf16LeWithNull(allocator: mem.Allocator, utf8: []const u8) ![:0]u1...@@ -695,11 +695,11 @@ pub fn utf8ToUtf16LeWithNull(allocator: mem.Allocator, utf8: []const u8) ![:0]u1
695 var it = view.iterator();695 var it = view.iterator();
696 while (it.nextCodepoint()) |codepoint| {696 while (it.nextCodepoint()) |codepoint| {
697 if (codepoint < 0x10000) {697 if (codepoint < 0x10000) {
698 const short = @intCast(u16, codepoint);698 const short = @as(u16, @intCast(codepoint));
699 try result.append(mem.nativeToLittle(u16, short));699 try result.append(mem.nativeToLittle(u16, short));
700 } else {700 } else {
701 const high = @intCast(u16, (codepoint - 0x10000) >> 10) + 0xD800;701 const high = @as(u16, @intCast((codepoint - 0x10000) >> 10)) + 0xD800;
702 const low = @intCast(u16, codepoint & 0x3FF) + 0xDC00;702 const low = @as(u16, @intCast(codepoint & 0x3FF)) + 0xDC00;
703 var out: [2]u16 = undefined;703 var out: [2]u16 = undefined;
704 out[0] = mem.nativeToLittle(u16, high);704 out[0] = mem.nativeToLittle(u16, high);
705 out[1] = mem.nativeToLittle(u16, low);705 out[1] = mem.nativeToLittle(u16, low);
...@@ -720,12 +720,12 @@ pub fn utf8ToUtf16Le(utf16le: []u16, utf8: []const u8) !usize {...@@ -720,12 +720,12 @@ pub fn utf8ToUtf16Le(utf16le: []u16, utf8: []const u8) !usize {
720 const next_src_i = src_i + n;720 const next_src_i = src_i + n;
721 const codepoint = utf8Decode(utf8[src_i..next_src_i]) catch return error.InvalidUtf8;721 const codepoint = utf8Decode(utf8[src_i..next_src_i]) catch return error.InvalidUtf8;
722 if (codepoint < 0x10000) {722 if (codepoint < 0x10000) {
723 const short = @intCast(u16, codepoint);723 const short = @as(u16, @intCast(codepoint));
724 utf16le[dest_i] = mem.nativeToLittle(u16, short);724 utf16le[dest_i] = mem.nativeToLittle(u16, short);
725 dest_i += 1;725 dest_i += 1;
726 } else {726 } else {
727 const high = @intCast(u16, (codepoint - 0x10000) >> 10) + 0xD800;727 const high = @as(u16, @intCast((codepoint - 0x10000) >> 10)) + 0xD800;
728 const low = @intCast(u16, codepoint & 0x3FF) + 0xDC00;728 const low = @as(u16, @intCast(codepoint & 0x3FF)) + 0xDC00;
729 utf16le[dest_i] = mem.nativeToLittle(u16, high);729 utf16le[dest_i] = mem.nativeToLittle(u16, high);
730 utf16le[dest_i + 1] = mem.nativeToLittle(u16, low);730 utf16le[dest_i + 1] = mem.nativeToLittle(u16, low);
731 dest_i += 2;731 dest_i += 2;
lib/std/unicode/throughput_test.zig+2-2
...@@ -32,8 +32,8 @@ fn benchmarkCodepointCount(buf: []const u8) !ResultCount {...@@ -32,8 +32,8 @@ fn benchmarkCodepointCount(buf: []const u8) !ResultCount {
32 }32 }
33 const end = timer.read();33 const end = timer.read();
3434
35 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;35 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
36 const throughput = @intFromFloat(u64, @floatFromInt(f64, bytes) / elapsed_s);36 const throughput = @as(u64, @intFromFloat(@as(f64, @floatFromInt(bytes)) / elapsed_s));
3737
38 return ResultCount{ .count = r, .throughput = throughput };38 return ResultCount{ .count = r, .throughput = throughput };
39}39}
lib/std/valgrind.zig+1-1
...@@ -94,7 +94,7 @@ pub fn IsTool(base: [2]u8, code: usize) bool {...@@ -94,7 +94,7 @@ pub fn IsTool(base: [2]u8, code: usize) bool {
94}94}
9595
96fn doClientRequestExpr(default: usize, request: ClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize {96fn doClientRequestExpr(default: usize, request: ClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize {
97 return doClientRequest(default, @intCast(usize, @intFromEnum(request)), a1, a2, a3, a4, a5);97 return doClientRequest(default, @as(usize, @intCast(@intFromEnum(request))), a1, a2, a3, a4, a5);
98}98}
9999
100fn doClientRequestStmt(request: ClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) void {100fn doClientRequestStmt(request: ClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) void {
lib/std/valgrind/callgrind.zig+1-1
...@@ -11,7 +11,7 @@ pub const CallgrindClientRequest = enum(usize) {...@@ -11,7 +11,7 @@ pub const CallgrindClientRequest = enum(usize) {
11};11};
1212
13fn doCallgrindClientRequestExpr(default: usize, request: CallgrindClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize {13fn doCallgrindClientRequestExpr(default: usize, request: CallgrindClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize {
14 return valgrind.doClientRequest(default, @intCast(usize, @intFromEnum(request)), a1, a2, a3, a4, a5);14 return valgrind.doClientRequest(default, @as(usize, @intCast(@intFromEnum(request))), a1, a2, a3, a4, a5);
15}15}
1616
17fn doCallgrindClientRequestStmt(request: CallgrindClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) void {17fn doCallgrindClientRequestStmt(request: CallgrindClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) void {
lib/std/valgrind/memcheck.zig+11-11
...@@ -21,7 +21,7 @@ pub const MemCheckClientRequest = enum(usize) {...@@ -21,7 +21,7 @@ pub const MemCheckClientRequest = enum(usize) {
21};21};
2222
23fn doMemCheckClientRequestExpr(default: usize, request: MemCheckClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize {23fn doMemCheckClientRequestExpr(default: usize, request: MemCheckClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize {
24 return valgrind.doClientRequest(default, @intCast(usize, @intFromEnum(request)), a1, a2, a3, a4, a5);24 return valgrind.doClientRequest(default, @as(usize, @intCast(@intFromEnum(request))), a1, a2, a3, a4, a5);
25}25}
2626
27fn doMemCheckClientRequestStmt(request: MemCheckClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) void {27fn doMemCheckClientRequestStmt(request: MemCheckClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) void {
...@@ -31,24 +31,24 @@ fn doMemCheckClientRequestStmt(request: MemCheckClientRequest, a1: usize, a2: us...@@ -31,24 +31,24 @@ fn doMemCheckClientRequestStmt(request: MemCheckClientRequest, a1: usize, a2: us
31/// Mark memory at qzz.ptr as unaddressable for qzz.len bytes.31/// Mark memory at qzz.ptr as unaddressable for qzz.len bytes.
32/// This returns -1 when run on Valgrind and 0 otherwise.32/// This returns -1 when run on Valgrind and 0 otherwise.
33pub fn makeMemNoAccess(qzz: []u8) i1 {33pub fn makeMemNoAccess(qzz: []u8) i1 {
34 return @intCast(i1, doMemCheckClientRequestExpr(0, // default return34 return @as(i1, @intCast(doMemCheckClientRequestExpr(0, // default return
35 .MakeMemNoAccess, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0));35 .MakeMemNoAccess, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0)));
36}36}
3737
38/// Similarly, mark memory at qzz.ptr as addressable but undefined38/// Similarly, mark memory at qzz.ptr as addressable but undefined
39/// for qzz.len bytes.39/// for qzz.len bytes.
40/// This returns -1 when run on Valgrind and 0 otherwise.40/// This returns -1 when run on Valgrind and 0 otherwise.
41pub fn makeMemUndefined(qzz: []u8) i1 {41pub fn makeMemUndefined(qzz: []u8) i1 {
42 return @intCast(i1, doMemCheckClientRequestExpr(0, // default return42 return @as(i1, @intCast(doMemCheckClientRequestExpr(0, // default return
43 .MakeMemUndefined, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0));43 .MakeMemUndefined, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0)));
44}44}
4545
46/// Similarly, mark memory at qzz.ptr as addressable and defined46/// Similarly, mark memory at qzz.ptr as addressable and defined
47/// for qzz.len bytes.47/// for qzz.len bytes.
48pub fn makeMemDefined(qzz: []u8) i1 {48pub fn makeMemDefined(qzz: []u8) i1 {
49 // This returns -1 when run on Valgrind and 0 otherwise.49 // This returns -1 when run on Valgrind and 0 otherwise.
50 return @intCast(i1, doMemCheckClientRequestExpr(0, // default return50 return @as(i1, @intCast(doMemCheckClientRequestExpr(0, // default return
51 .MakeMemDefined, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0));51 .MakeMemDefined, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0)));
52}52}
5353
54/// Similar to makeMemDefined except that addressability is54/// Similar to makeMemDefined except that addressability is
...@@ -56,8 +56,8 @@ pub fn makeMemDefined(qzz: []u8) i1 {...@@ -56,8 +56,8 @@ pub fn makeMemDefined(qzz: []u8) i1 {
56/// but those which are not addressable are left unchanged.56/// but those which are not addressable are left unchanged.
57/// This returns -1 when run on Valgrind and 0 otherwise.57/// This returns -1 when run on Valgrind and 0 otherwise.
58pub fn makeMemDefinedIfAddressable(qzz: []u8) i1 {58pub fn makeMemDefinedIfAddressable(qzz: []u8) i1 {
59 return @intCast(i1, doMemCheckClientRequestExpr(0, // default return59 return @as(i1, @intCast(doMemCheckClientRequestExpr(0, // default return
60 .MakeMemDefinedIfAddressable, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0));60 .MakeMemDefinedIfAddressable, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0)));
61}61}
6262
63/// Create a block-description handle. The description is an ascii63/// Create a block-description handle. The description is an ascii
...@@ -195,7 +195,7 @@ test "countLeakBlocks" {...@@ -195,7 +195,7 @@ test "countLeakBlocks" {
195/// impossible to segfault your system by using this call.195/// impossible to segfault your system by using this call.
196pub fn getVbits(zza: []u8, zzvbits: []u8) u2 {196pub fn getVbits(zza: []u8, zzvbits: []u8) u2 {
197 std.debug.assert(zzvbits.len >= zza.len / 8);197 std.debug.assert(zzvbits.len >= zza.len / 8);
198 return @intCast(u2, doMemCheckClientRequestExpr(0, .GetVbits, @intFromPtr(zza.ptr), @intFromPtr(zzvbits), zza.len, 0, 0));198 return @as(u2, @intCast(doMemCheckClientRequestExpr(0, .GetVbits, @intFromPtr(zza.ptr), @intFromPtr(zzvbits), zza.len, 0, 0)));
199}199}
200200
201/// Set the validity data for addresses zza, copying it201/// Set the validity data for addresses zza, copying it
...@@ -208,7 +208,7 @@ pub fn getVbits(zza: []u8, zzvbits: []u8) u2 {...@@ -208,7 +208,7 @@ pub fn getVbits(zza: []u8, zzvbits: []u8) u2 {
208/// impossible to segfault your system by using this call.208/// impossible to segfault your system by using this call.
209pub fn setVbits(zzvbits: []u8, zza: []u8) u2 {209pub fn setVbits(zzvbits: []u8, zza: []u8) u2 {
210 std.debug.assert(zzvbits.len >= zza.len / 8);210 std.debug.assert(zzvbits.len >= zza.len / 8);
211 return @intCast(u2, doMemCheckClientRequestExpr(0, .SetVbits, @intFromPtr(zza.ptr), @intFromPtr(zzvbits), zza.len, 0, 0));211 return @as(u2, @intCast(doMemCheckClientRequestExpr(0, .SetVbits, @intFromPtr(zza.ptr), @intFromPtr(zzvbits), zza.len, 0, 0)));
212}212}
213213
214/// Disable and re-enable reporting of addressing errors in the214/// Disable and re-enable reporting of addressing errors in the
lib/std/zig.zig+1-1
...@@ -36,7 +36,7 @@ pub fn hashSrc(src: []const u8) SrcHash {...@@ -36,7 +36,7 @@ pub fn hashSrc(src: []const u8) SrcHash {
36}36}
3737
38pub fn srcHashEql(a: SrcHash, b: SrcHash) bool {38pub fn srcHashEql(a: SrcHash, b: SrcHash) bool {
39 return @bitCast(u128, a) == @bitCast(u128, b);39 return @as(u128, @bitCast(a)) == @as(u128, @bitCast(b));
40}40}
4141
42pub fn hashName(parent_hash: SrcHash, sep: []const u8, name: []const u8) SrcHash {42pub fn hashName(parent_hash: SrcHash, sep: []const u8, name: []const u8) SrcHash {
lib/std/zig/Ast.zig+5-5
...@@ -62,7 +62,7 @@ pub fn parse(gpa: Allocator, source: [:0]const u8, mode: Mode) Allocator.Error!A...@@ -62,7 +62,7 @@ pub fn parse(gpa: Allocator, source: [:0]const u8, mode: Mode) Allocator.Error!A
62 const token = tokenizer.next();62 const token = tokenizer.next();
63 try tokens.append(gpa, .{63 try tokens.append(gpa, .{
64 .tag = token.tag,64 .tag = token.tag,
65 .start = @intCast(u32, token.loc.start),65 .start = @as(u32, @intCast(token.loc.start)),
66 });66 });
67 if (token.tag == .eof) break;67 if (token.tag == .eof) break;
68 }68 }
...@@ -123,7 +123,7 @@ pub fn renderToArrayList(tree: Ast, buffer: *std.ArrayList(u8)) RenderError!void...@@ -123,7 +123,7 @@ pub fn renderToArrayList(tree: Ast, buffer: *std.ArrayList(u8)) RenderError!void
123/// should point after the token in the error message.123/// should point after the token in the error message.
124pub fn errorOffset(tree: Ast, parse_error: Error) u32 {124pub fn errorOffset(tree: Ast, parse_error: Error) u32 {
125 return if (parse_error.token_is_prev)125 return if (parse_error.token_is_prev)
126 @intCast(u32, tree.tokenSlice(parse_error.token).len)126 @as(u32, @intCast(tree.tokenSlice(parse_error.token).len))
127 else127 else
128 0;128 0;
129}129}
...@@ -772,7 +772,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {...@@ -772,7 +772,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
772 var n = node;772 var n = node;
773 var end_offset: TokenIndex = 0;773 var end_offset: TokenIndex = 0;
774 while (true) switch (tags[n]) {774 while (true) switch (tags[n]) {
775 .root => return @intCast(TokenIndex, tree.tokens.len - 1),775 .root => return @as(TokenIndex, @intCast(tree.tokens.len - 1)),
776776
777 .@"usingnamespace",777 .@"usingnamespace",
778 .bool_not,778 .bool_not,
...@@ -1288,7 +1288,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {...@@ -1288,7 +1288,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
1288 n = extra.else_expr;1288 n = extra.else_expr;
1289 },1289 },
1290 .@"for" => {1290 .@"for" => {
1291 const extra = @bitCast(Node.For, datas[n].rhs);1291 const extra = @as(Node.For, @bitCast(datas[n].rhs));
1292 n = tree.extra_data[datas[n].lhs + extra.inputs + @intFromBool(extra.has_else)];1292 n = tree.extra_data[datas[n].lhs + extra.inputs + @intFromBool(extra.has_else)];
1293 },1293 },
1294 .@"suspend" => {1294 .@"suspend" => {
...@@ -1955,7 +1955,7 @@ pub fn forSimple(tree: Ast, node: Node.Index) full.For {...@@ -1955,7 +1955,7 @@ pub fn forSimple(tree: Ast, node: Node.Index) full.For {
19551955
1956pub fn forFull(tree: Ast, node: Node.Index) full.For {1956pub fn forFull(tree: Ast, node: Node.Index) full.For {
1957 const data = tree.nodes.items(.data)[node];1957 const data = tree.nodes.items(.data)[node];
1958 const extra = @bitCast(Node.For, data.rhs);1958 const extra = @as(Node.For, @bitCast(data.rhs));
1959 const inputs = tree.extra_data[data.lhs..][0..extra.inputs];1959 const inputs = tree.extra_data[data.lhs..][0..extra.inputs];
1960 const then_expr = tree.extra_data[data.lhs + extra.inputs];1960 const then_expr = tree.extra_data[data.lhs + extra.inputs];
1961 const else_expr = if (extra.has_else) tree.extra_data[data.lhs + extra.inputs + 1] else 0;1961 const else_expr = if (extra.has_else) tree.extra_data[data.lhs + extra.inputs + 1] else 0;
lib/std/zig/CrossTarget.zig+1-1
...@@ -317,7 +317,7 @@ pub fn parse(args: ParseOptions) !CrossTarget {...@@ -317,7 +317,7 @@ pub fn parse(args: ParseOptions) !CrossTarget {
317 }317 }
318 const feature_name = cpu_features[start..index];318 const feature_name = cpu_features[start..index];
319 for (all_features, 0..) |feature, feat_index_usize| {319 for (all_features, 0..) |feature, feat_index_usize| {
320 const feat_index = @intCast(Target.Cpu.Feature.Set.Index, feat_index_usize);320 const feat_index = @as(Target.Cpu.Feature.Set.Index, @intCast(feat_index_usize));
321 if (mem.eql(u8, feature_name, feature.name)) {321 if (mem.eql(u8, feature_name, feature.name)) {
322 set.addFeature(feat_index);322 set.addFeature(feat_index);
323 break;323 break;
lib/std/zig/ErrorBundle.zig+17-17
...@@ -94,7 +94,7 @@ pub fn getErrorMessageList(eb: ErrorBundle) ErrorMessageList {...@@ -94,7 +94,7 @@ pub fn getErrorMessageList(eb: ErrorBundle) ErrorMessageList {
9494
95pub fn getMessages(eb: ErrorBundle) []const MessageIndex {95pub fn getMessages(eb: ErrorBundle) []const MessageIndex {
96 const list = eb.getErrorMessageList();96 const list = eb.getErrorMessageList();
97 return @ptrCast([]const MessageIndex, eb.extra[list.start..][0..list.len]);97 return @as([]const MessageIndex, @ptrCast(eb.extra[list.start..][0..list.len]));
98}98}
9999
100pub fn getErrorMessage(eb: ErrorBundle, index: MessageIndex) ErrorMessage {100pub fn getErrorMessage(eb: ErrorBundle, index: MessageIndex) ErrorMessage {
...@@ -109,7 +109,7 @@ pub fn getSourceLocation(eb: ErrorBundle, index: SourceLocationIndex) SourceLoca...@@ -109,7 +109,7 @@ pub fn getSourceLocation(eb: ErrorBundle, index: SourceLocationIndex) SourceLoca
109pub fn getNotes(eb: ErrorBundle, index: MessageIndex) []const MessageIndex {109pub fn getNotes(eb: ErrorBundle, index: MessageIndex) []const MessageIndex {
110 const notes_len = eb.getErrorMessage(index).notes_len;110 const notes_len = eb.getErrorMessage(index).notes_len;
111 const start = @intFromEnum(index) + @typeInfo(ErrorMessage).Struct.fields.len;111 const start = @intFromEnum(index) + @typeInfo(ErrorMessage).Struct.fields.len;
112 return @ptrCast([]const MessageIndex, eb.extra[start..][0..notes_len]);112 return @as([]const MessageIndex, @ptrCast(eb.extra[start..][0..notes_len]));
113}113}
114114
115pub fn getCompileLogOutput(eb: ErrorBundle) [:0]const u8 {115pub fn getCompileLogOutput(eb: ErrorBundle) [:0]const u8 {
...@@ -125,8 +125,8 @@ fn extraData(eb: ErrorBundle, comptime T: type, index: usize) struct { data: T,...@@ -125,8 +125,8 @@ fn extraData(eb: ErrorBundle, comptime T: type, index: usize) struct { data: T,
125 inline for (fields) |field| {125 inline for (fields) |field| {
126 @field(result, field.name) = switch (field.type) {126 @field(result, field.name) = switch (field.type) {
127 u32 => eb.extra[i],127 u32 => eb.extra[i],
128 MessageIndex => @enumFromInt(MessageIndex, eb.extra[i]),128 MessageIndex => @as(MessageIndex, @enumFromInt(eb.extra[i])),
129 SourceLocationIndex => @enumFromInt(SourceLocationIndex, eb.extra[i]),129 SourceLocationIndex => @as(SourceLocationIndex, @enumFromInt(eb.extra[i])),
130 else => @compileError("bad field type"),130 else => @compileError("bad field type"),
131 };131 };
132 i += 1;132 i += 1;
...@@ -202,7 +202,7 @@ fn renderErrorMessageToWriter(...@@ -202,7 +202,7 @@ fn renderErrorMessageToWriter(
202 try counting_stderr.writeAll(": ");202 try counting_stderr.writeAll(": ");
203 // This is the length of the part before the error message:203 // This is the length of the part before the error message:
204 // e.g. "file.zig:4:5: error: "204 // e.g. "file.zig:4:5: error: "
205 const prefix_len = @intCast(usize, counting_stderr.context.bytes_written);205 const prefix_len = @as(usize, @intCast(counting_stderr.context.bytes_written));
206 try ttyconf.setColor(stderr, .reset);206 try ttyconf.setColor(stderr, .reset);
207 try ttyconf.setColor(stderr, .bold);207 try ttyconf.setColor(stderr, .bold);
208 if (err_msg.count == 1) {208 if (err_msg.count == 1) {
...@@ -357,7 +357,7 @@ pub const Wip = struct {...@@ -357,7 +357,7 @@ pub const Wip = struct {
357 }357 }
358358
359 const compile_log_str_index = if (compile_log_text.len == 0) 0 else str: {359 const compile_log_str_index = if (compile_log_text.len == 0) 0 else str: {
360 const str = @intCast(u32, wip.string_bytes.items.len);360 const str = @as(u32, @intCast(wip.string_bytes.items.len));
361 try wip.string_bytes.ensureUnusedCapacity(gpa, compile_log_text.len + 1);361 try wip.string_bytes.ensureUnusedCapacity(gpa, compile_log_text.len + 1);
362 wip.string_bytes.appendSliceAssumeCapacity(compile_log_text);362 wip.string_bytes.appendSliceAssumeCapacity(compile_log_text);
363 wip.string_bytes.appendAssumeCapacity(0);363 wip.string_bytes.appendAssumeCapacity(0);
...@@ -365,11 +365,11 @@ pub const Wip = struct {...@@ -365,11 +365,11 @@ pub const Wip = struct {
365 };365 };
366366
367 wip.setExtra(0, ErrorMessageList{367 wip.setExtra(0, ErrorMessageList{
368 .len = @intCast(u32, wip.root_list.items.len),368 .len = @as(u32, @intCast(wip.root_list.items.len)),
369 .start = @intCast(u32, wip.extra.items.len),369 .start = @as(u32, @intCast(wip.extra.items.len)),
370 .compile_log_text = compile_log_str_index,370 .compile_log_text = compile_log_str_index,
371 });371 });
372 try wip.extra.appendSlice(gpa, @ptrCast([]const u32, wip.root_list.items));372 try wip.extra.appendSlice(gpa, @as([]const u32, @ptrCast(wip.root_list.items)));
373 wip.root_list.clearAndFree(gpa);373 wip.root_list.clearAndFree(gpa);
374 return .{374 return .{
375 .string_bytes = try wip.string_bytes.toOwnedSlice(gpa),375 .string_bytes = try wip.string_bytes.toOwnedSlice(gpa),
...@@ -386,7 +386,7 @@ pub const Wip = struct {...@@ -386,7 +386,7 @@ pub const Wip = struct {
386386
387 pub fn addString(wip: *Wip, s: []const u8) !u32 {387 pub fn addString(wip: *Wip, s: []const u8) !u32 {
388 const gpa = wip.gpa;388 const gpa = wip.gpa;
389 const index = @intCast(u32, wip.string_bytes.items.len);389 const index = @as(u32, @intCast(wip.string_bytes.items.len));
390 try wip.string_bytes.ensureUnusedCapacity(gpa, s.len + 1);390 try wip.string_bytes.ensureUnusedCapacity(gpa, s.len + 1);
391 wip.string_bytes.appendSliceAssumeCapacity(s);391 wip.string_bytes.appendSliceAssumeCapacity(s);
392 wip.string_bytes.appendAssumeCapacity(0);392 wip.string_bytes.appendAssumeCapacity(0);
...@@ -395,7 +395,7 @@ pub const Wip = struct {...@@ -395,7 +395,7 @@ pub const Wip = struct {
395395
396 pub fn printString(wip: *Wip, comptime fmt: []const u8, args: anytype) !u32 {396 pub fn printString(wip: *Wip, comptime fmt: []const u8, args: anytype) !u32 {
397 const gpa = wip.gpa;397 const gpa = wip.gpa;
398 const index = @intCast(u32, wip.string_bytes.items.len);398 const index = @as(u32, @intCast(wip.string_bytes.items.len));
399 try wip.string_bytes.writer(gpa).print(fmt, args);399 try wip.string_bytes.writer(gpa).print(fmt, args);
400 try wip.string_bytes.append(gpa, 0);400 try wip.string_bytes.append(gpa, 0);
401 return index;401 return index;
...@@ -407,15 +407,15 @@ pub const Wip = struct {...@@ -407,15 +407,15 @@ pub const Wip = struct {
407 }407 }
408408
409 pub fn addErrorMessage(wip: *Wip, em: ErrorMessage) !MessageIndex {409 pub fn addErrorMessage(wip: *Wip, em: ErrorMessage) !MessageIndex {
410 return @enumFromInt(MessageIndex, try addExtra(wip, em));410 return @as(MessageIndex, @enumFromInt(try addExtra(wip, em)));
411 }411 }
412412
413 pub fn addErrorMessageAssumeCapacity(wip: *Wip, em: ErrorMessage) MessageIndex {413 pub fn addErrorMessageAssumeCapacity(wip: *Wip, em: ErrorMessage) MessageIndex {
414 return @enumFromInt(MessageIndex, addExtraAssumeCapacity(wip, em));414 return @as(MessageIndex, @enumFromInt(addExtraAssumeCapacity(wip, em)));
415 }415 }
416416
417 pub fn addSourceLocation(wip: *Wip, sl: SourceLocation) !SourceLocationIndex {417 pub fn addSourceLocation(wip: *Wip, sl: SourceLocation) !SourceLocationIndex {
418 return @enumFromInt(SourceLocationIndex, try addExtra(wip, sl));418 return @as(SourceLocationIndex, @enumFromInt(try addExtra(wip, sl)));
419 }419 }
420420
421 pub fn addReferenceTrace(wip: *Wip, rt: ReferenceTrace) !void {421 pub fn addReferenceTrace(wip: *Wip, rt: ReferenceTrace) !void {
...@@ -431,7 +431,7 @@ pub const Wip = struct {...@@ -431,7 +431,7 @@ pub const Wip = struct {
431 const other_list = other.getMessages();431 const other_list = other.getMessages();
432432
433 // The ensureUnusedCapacity call above guarantees this.433 // The ensureUnusedCapacity call above guarantees this.
434 const notes_start = wip.reserveNotes(@intCast(u32, other_list.len)) catch unreachable;434 const notes_start = wip.reserveNotes(@as(u32, @intCast(other_list.len))) catch unreachable;
435 for (notes_start.., other_list) |note, message| {435 for (notes_start.., other_list) |note, message| {
436 wip.extra.items[note] = @intFromEnum(wip.addOtherMessage(other, message) catch unreachable);436 wip.extra.items[note] = @intFromEnum(wip.addOtherMessage(other, message) catch unreachable);
437 }437 }
...@@ -441,7 +441,7 @@ pub const Wip = struct {...@@ -441,7 +441,7 @@ pub const Wip = struct {
441 try wip.extra.ensureUnusedCapacity(wip.gpa, notes_len +441 try wip.extra.ensureUnusedCapacity(wip.gpa, notes_len +
442 notes_len * @typeInfo(ErrorBundle.ErrorMessage).Struct.fields.len);442 notes_len * @typeInfo(ErrorBundle.ErrorMessage).Struct.fields.len);
443 wip.extra.items.len += notes_len;443 wip.extra.items.len += notes_len;
444 return @intCast(u32, wip.extra.items.len - notes_len);444 return @as(u32, @intCast(wip.extra.items.len - notes_len));
445 }445 }
446446
447 fn addOtherMessage(wip: *Wip, other: ErrorBundle, msg_index: MessageIndex) !MessageIndex {447 fn addOtherMessage(wip: *Wip, other: ErrorBundle, msg_index: MessageIndex) !MessageIndex {
...@@ -493,7 +493,7 @@ pub const Wip = struct {...@@ -493,7 +493,7 @@ pub const Wip = struct {
493493
494 fn addExtraAssumeCapacity(wip: *Wip, extra: anytype) u32 {494 fn addExtraAssumeCapacity(wip: *Wip, extra: anytype) u32 {
495 const fields = @typeInfo(@TypeOf(extra)).Struct.fields;495 const fields = @typeInfo(@TypeOf(extra)).Struct.fields;
496 const result = @intCast(u32, wip.extra.items.len);496 const result = @as(u32, @intCast(wip.extra.items.len));
497 wip.extra.items.len += fields.len;497 wip.extra.items.len += fields.len;
498 setExtra(wip, result, extra);498 setExtra(wip, result, extra);
499 return result;499 return result;
lib/std/zig/Parse.zig+15-15
...@@ -36,20 +36,20 @@ const Members = struct {...@@ -36,20 +36,20 @@ const Members = struct {
36fn listToSpan(p: *Parse, list: []const Node.Index) !Node.SubRange {36fn listToSpan(p: *Parse, list: []const Node.Index) !Node.SubRange {
37 try p.extra_data.appendSlice(p.gpa, list);37 try p.extra_data.appendSlice(p.gpa, list);
38 return Node.SubRange{38 return Node.SubRange{
39 .start = @intCast(Node.Index, p.extra_data.items.len - list.len),39 .start = @as(Node.Index, @intCast(p.extra_data.items.len - list.len)),
40 .end = @intCast(Node.Index, p.extra_data.items.len),40 .end = @as(Node.Index, @intCast(p.extra_data.items.len)),
41 };41 };
42}42}
4343
44fn addNode(p: *Parse, elem: Ast.Node) Allocator.Error!Node.Index {44fn addNode(p: *Parse, elem: Ast.Node) Allocator.Error!Node.Index {
45 const result = @intCast(Node.Index, p.nodes.len);45 const result = @as(Node.Index, @intCast(p.nodes.len));
46 try p.nodes.append(p.gpa, elem);46 try p.nodes.append(p.gpa, elem);
47 return result;47 return result;
48}48}
4949
50fn setNode(p: *Parse, i: usize, elem: Ast.Node) Node.Index {50fn setNode(p: *Parse, i: usize, elem: Ast.Node) Node.Index {
51 p.nodes.set(i, elem);51 p.nodes.set(i, elem);
52 return @intCast(Node.Index, i);52 return @as(Node.Index, @intCast(i));
53}53}
5454
55fn reserveNode(p: *Parse, tag: Ast.Node.Tag) !usize {55fn reserveNode(p: *Parse, tag: Ast.Node.Tag) !usize {
...@@ -72,7 +72,7 @@ fn unreserveNode(p: *Parse, node_index: usize) void {...@@ -72,7 +72,7 @@ fn unreserveNode(p: *Parse, node_index: usize) void {
72fn addExtra(p: *Parse, extra: anytype) Allocator.Error!Node.Index {72fn addExtra(p: *Parse, extra: anytype) Allocator.Error!Node.Index {
73 const fields = std.meta.fields(@TypeOf(extra));73 const fields = std.meta.fields(@TypeOf(extra));
74 try p.extra_data.ensureUnusedCapacity(p.gpa, fields.len);74 try p.extra_data.ensureUnusedCapacity(p.gpa, fields.len);
75 const result = @intCast(u32, p.extra_data.items.len);75 const result = @as(u32, @intCast(p.extra_data.items.len));
76 inline for (fields) |field| {76 inline for (fields) |field| {
77 comptime assert(field.type == Node.Index);77 comptime assert(field.type == Node.Index);
78 p.extra_data.appendAssumeCapacity(@field(extra, field.name));78 p.extra_data.appendAssumeCapacity(@field(extra, field.name));
...@@ -1202,10 +1202,10 @@ fn parseForStatement(p: *Parse) !Node.Index {...@@ -1202,10 +1202,10 @@ fn parseForStatement(p: *Parse) !Node.Index {
1202 .main_token = for_token,1202 .main_token = for_token,
1203 .data = .{1203 .data = .{
1204 .lhs = (try p.listToSpan(p.scratch.items[scratch_top..])).start,1204 .lhs = (try p.listToSpan(p.scratch.items[scratch_top..])).start,
1205 .rhs = @bitCast(u32, Node.For{1205 .rhs = @as(u32, @bitCast(Node.For{
1206 .inputs = @intCast(u31, inputs),1206 .inputs = @as(u31, @intCast(inputs)),
1207 .has_else = has_else,1207 .has_else = has_else,
1208 }),1208 })),
1209 },1209 },
1210 });1210 });
1211}1211}
...@@ -1486,7 +1486,7 @@ fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!Node.Index {...@@ -1486,7 +1486,7 @@ fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!Node.Index {
14861486
1487 while (true) {1487 while (true) {
1488 const tok_tag = p.token_tags[p.tok_i];1488 const tok_tag = p.token_tags[p.tok_i];
1489 const info = operTable[@intCast(usize, @intFromEnum(tok_tag))];1489 const info = operTable[@as(usize, @intCast(@intFromEnum(tok_tag)))];
1490 if (info.prec < min_prec) {1490 if (info.prec < min_prec) {
1491 break;1491 break;
1492 }1492 }
...@@ -2087,10 +2087,10 @@ fn parseForExpr(p: *Parse) !Node.Index {...@@ -2087,10 +2087,10 @@ fn parseForExpr(p: *Parse) !Node.Index {
2087 .main_token = for_token,2087 .main_token = for_token,
2088 .data = .{2088 .data = .{
2089 .lhs = (try p.listToSpan(p.scratch.items[scratch_top..])).start,2089 .lhs = (try p.listToSpan(p.scratch.items[scratch_top..])).start,
2090 .rhs = @bitCast(u32, Node.For{2090 .rhs = @as(u32, @bitCast(Node.For{
2091 .inputs = @intCast(u31, inputs),2091 .inputs = @as(u31, @intCast(inputs)),
2092 .has_else = has_else,2092 .has_else = has_else,
2093 }),2093 })),
2094 },2094 },
2095 });2095 });
2096}2096}
...@@ -2862,10 +2862,10 @@ fn parseForTypeExpr(p: *Parse) !Node.Index {...@@ -2862,10 +2862,10 @@ fn parseForTypeExpr(p: *Parse) !Node.Index {
2862 .main_token = for_token,2862 .main_token = for_token,
2863 .data = .{2863 .data = .{
2864 .lhs = (try p.listToSpan(p.scratch.items[scratch_top..])).start,2864 .lhs = (try p.listToSpan(p.scratch.items[scratch_top..])).start,
2865 .rhs = @bitCast(u32, Node.For{2865 .rhs = @as(u32, @bitCast(Node.For{
2866 .inputs = @intCast(u31, inputs),2866 .inputs = @as(u31, @intCast(inputs)),
2867 .has_else = has_else,2867 .has_else = has_else,
2868 }),2868 })),
2869 },2869 },
2870 });2870 });
2871}2871}
lib/std/zig/Server.zig+14-14
...@@ -132,7 +132,7 @@ pub fn receiveMessage(s: *Server) !InMessage.Header {...@@ -132,7 +132,7 @@ pub fn receiveMessage(s: *Server) !InMessage.Header {
132pub fn receiveBody_u32(s: *Server) !u32 {132pub fn receiveBody_u32(s: *Server) !u32 {
133 const fifo = &s.receive_fifo;133 const fifo = &s.receive_fifo;
134 const buf = fifo.readableSlice(0);134 const buf = fifo.readableSlice(0);
135 const result = @ptrCast(*align(1) const u32, buf[0..4]).*;135 const result = @as(*align(1) const u32, @ptrCast(buf[0..4])).*;
136 fifo.discard(4);136 fifo.discard(4);
137 return bswap(result);137 return bswap(result);
138}138}
...@@ -140,7 +140,7 @@ pub fn receiveBody_u32(s: *Server) !u32 {...@@ -140,7 +140,7 @@ pub fn receiveBody_u32(s: *Server) !u32 {
140pub fn serveStringMessage(s: *Server, tag: OutMessage.Tag, msg: []const u8) !void {140pub fn serveStringMessage(s: *Server, tag: OutMessage.Tag, msg: []const u8) !void {
141 return s.serveMessage(.{141 return s.serveMessage(.{
142 .tag = tag,142 .tag = tag,
143 .bytes_len = @intCast(u32, msg.len),143 .bytes_len = @as(u32, @intCast(msg.len)),
144 }, &.{msg});144 }, &.{msg});
145}145}
146146
...@@ -152,7 +152,7 @@ pub fn serveMessage(...@@ -152,7 +152,7 @@ pub fn serveMessage(
152 var iovecs: [10]std.os.iovec_const = undefined;152 var iovecs: [10]std.os.iovec_const = undefined;
153 const header_le = bswap(header);153 const header_le = bswap(header);
154 iovecs[0] = .{154 iovecs[0] = .{
155 .iov_base = @ptrCast([*]const u8, &header_le),155 .iov_base = @as([*]const u8, @ptrCast(&header_le)),
156 .iov_len = @sizeOf(OutMessage.Header),156 .iov_len = @sizeOf(OutMessage.Header),
157 };157 };
158 for (bufs, iovecs[1 .. bufs.len + 1]) |buf, *iovec| {158 for (bufs, iovecs[1 .. bufs.len + 1]) |buf, *iovec| {
...@@ -171,7 +171,7 @@ pub fn serveEmitBinPath(...@@ -171,7 +171,7 @@ pub fn serveEmitBinPath(
171) !void {171) !void {
172 try s.serveMessage(.{172 try s.serveMessage(.{
173 .tag = .emit_bin_path,173 .tag = .emit_bin_path,
174 .bytes_len = @intCast(u32, fs_path.len + @sizeOf(OutMessage.EmitBinPath)),174 .bytes_len = @as(u32, @intCast(fs_path.len + @sizeOf(OutMessage.EmitBinPath))),
175 }, &.{175 }, &.{
176 std.mem.asBytes(&header),176 std.mem.asBytes(&header),
177 fs_path,177 fs_path,
...@@ -185,7 +185,7 @@ pub fn serveTestResults(...@@ -185,7 +185,7 @@ pub fn serveTestResults(
185 const msg_le = bswap(msg);185 const msg_le = bswap(msg);
186 try s.serveMessage(.{186 try s.serveMessage(.{
187 .tag = .test_results,187 .tag = .test_results,
188 .bytes_len = @intCast(u32, @sizeOf(OutMessage.TestResults)),188 .bytes_len = @as(u32, @intCast(@sizeOf(OutMessage.TestResults))),
189 }, &.{189 }, &.{
190 std.mem.asBytes(&msg_le),190 std.mem.asBytes(&msg_le),
191 });191 });
...@@ -193,14 +193,14 @@ pub fn serveTestResults(...@@ -193,14 +193,14 @@ pub fn serveTestResults(
193193
194pub fn serveErrorBundle(s: *Server, error_bundle: std.zig.ErrorBundle) !void {194pub fn serveErrorBundle(s: *Server, error_bundle: std.zig.ErrorBundle) !void {
195 const eb_hdr: OutMessage.ErrorBundle = .{195 const eb_hdr: OutMessage.ErrorBundle = .{
196 .extra_len = @intCast(u32, error_bundle.extra.len),196 .extra_len = @as(u32, @intCast(error_bundle.extra.len)),
197 .string_bytes_len = @intCast(u32, error_bundle.string_bytes.len),197 .string_bytes_len = @as(u32, @intCast(error_bundle.string_bytes.len)),
198 };198 };
199 const bytes_len = @sizeOf(OutMessage.ErrorBundle) +199 const bytes_len = @sizeOf(OutMessage.ErrorBundle) +
200 4 * error_bundle.extra.len + error_bundle.string_bytes.len;200 4 * error_bundle.extra.len + error_bundle.string_bytes.len;
201 try s.serveMessage(.{201 try s.serveMessage(.{
202 .tag = .error_bundle,202 .tag = .error_bundle,
203 .bytes_len = @intCast(u32, bytes_len),203 .bytes_len = @as(u32, @intCast(bytes_len)),
204 }, &.{204 }, &.{
205 std.mem.asBytes(&eb_hdr),205 std.mem.asBytes(&eb_hdr),
206 // TODO: implement @ptrCast between slices changing the length206 // TODO: implement @ptrCast between slices changing the length
...@@ -218,8 +218,8 @@ pub const TestMetadata = struct {...@@ -218,8 +218,8 @@ pub const TestMetadata = struct {
218218
219pub fn serveTestMetadata(s: *Server, test_metadata: TestMetadata) !void {219pub fn serveTestMetadata(s: *Server, test_metadata: TestMetadata) !void {
220 const header: OutMessage.TestMetadata = .{220 const header: OutMessage.TestMetadata = .{
221 .tests_len = bswap(@intCast(u32, test_metadata.names.len)),221 .tests_len = bswap(@as(u32, @intCast(test_metadata.names.len))),
222 .string_bytes_len = bswap(@intCast(u32, test_metadata.string_bytes.len)),222 .string_bytes_len = bswap(@as(u32, @intCast(test_metadata.string_bytes.len))),
223 };223 };
224 const bytes_len = @sizeOf(OutMessage.TestMetadata) +224 const bytes_len = @sizeOf(OutMessage.TestMetadata) +
225 3 * 4 * test_metadata.names.len + test_metadata.string_bytes.len;225 3 * 4 * test_metadata.names.len + test_metadata.string_bytes.len;
...@@ -237,7 +237,7 @@ pub fn serveTestMetadata(s: *Server, test_metadata: TestMetadata) !void {...@@ -237,7 +237,7 @@ pub fn serveTestMetadata(s: *Server, test_metadata: TestMetadata) !void {
237237
238 return s.serveMessage(.{238 return s.serveMessage(.{
239 .tag = .test_metadata,239 .tag = .test_metadata,
240 .bytes_len = @intCast(u32, bytes_len),240 .bytes_len = @as(u32, @intCast(bytes_len)),
241 }, &.{241 }, &.{
242 std.mem.asBytes(&header),242 std.mem.asBytes(&header),
243 // TODO: implement @ptrCast between slices changing the length243 // TODO: implement @ptrCast between slices changing the length
...@@ -253,7 +253,7 @@ fn bswap(x: anytype) @TypeOf(x) {...@@ -253,7 +253,7 @@ fn bswap(x: anytype) @TypeOf(x) {
253253
254 const T = @TypeOf(x);254 const T = @TypeOf(x);
255 switch (@typeInfo(T)) {255 switch (@typeInfo(T)) {
256 .Enum => return @enumFromInt(T, @byteSwap(@intFromEnum(x))),256 .Enum => return @as(T, @enumFromInt(@byteSwap(@intFromEnum(x)))),
257 .Int => return @byteSwap(x),257 .Int => return @byteSwap(x),
258 .Struct => |info| switch (info.layout) {258 .Struct => |info| switch (info.layout) {
259 .Extern => {259 .Extern => {
...@@ -265,7 +265,7 @@ fn bswap(x: anytype) @TypeOf(x) {...@@ -265,7 +265,7 @@ fn bswap(x: anytype) @TypeOf(x) {
265 },265 },
266 .Packed => {266 .Packed => {
267 const I = info.backing_integer.?;267 const I = info.backing_integer.?;
268 return @bitCast(T, @byteSwap(@bitCast(I, x)));268 return @as(T, @bitCast(@byteSwap(@as(I, @bitCast(x)))));
269 },269 },
270 .Auto => @compileError("auto layout struct"),270 .Auto => @compileError("auto layout struct"),
271 },271 },
...@@ -286,7 +286,7 @@ fn bswap_and_workaround_u32(bytes_ptr: *const [4]u8) u32 {...@@ -286,7 +286,7 @@ fn bswap_and_workaround_u32(bytes_ptr: *const [4]u8) u32 {
286/// workaround for https://github.com/ziglang/zig/issues/14904286/// workaround for https://github.com/ziglang/zig/issues/14904
287fn bswap_and_workaround_tag(bytes_ptr: *const [4]u8) InMessage.Tag {287fn bswap_and_workaround_tag(bytes_ptr: *const [4]u8) InMessage.Tag {
288 const int = std.mem.readIntLittle(u32, bytes_ptr);288 const int = std.mem.readIntLittle(u32, bytes_ptr);
289 return @enumFromInt(InMessage.Tag, int);289 return @as(InMessage.Tag, @enumFromInt(int));
290}290}
291291
292const OutMessage = std.zig.Server.Message;292const OutMessage = std.zig.Server.Message;
lib/std/zig/c_builtins.zig+10-10
...@@ -20,19 +20,19 @@ pub inline fn __builtin_signbitf(val: f32) c_int {...@@ -20,19 +20,19 @@ pub inline fn __builtin_signbitf(val: f32) c_int {
20pub inline fn __builtin_popcount(val: c_uint) c_int {20pub inline fn __builtin_popcount(val: c_uint) c_int {
21 // popcount of a c_uint will never exceed the capacity of a c_int21 // popcount of a c_uint will never exceed the capacity of a c_int
22 @setRuntimeSafety(false);22 @setRuntimeSafety(false);
23 return @bitCast(c_int, @as(c_uint, @popCount(val)));23 return @as(c_int, @bitCast(@as(c_uint, @popCount(val))));
24}24}
25pub inline fn __builtin_ctz(val: c_uint) c_int {25pub inline fn __builtin_ctz(val: c_uint) c_int {
26 // Returns the number of trailing 0-bits in val, starting at the least significant bit position.26 // Returns the number of trailing 0-bits in val, starting at the least significant bit position.
27 // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint27 // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint
28 @setRuntimeSafety(false);28 @setRuntimeSafety(false);
29 return @bitCast(c_int, @as(c_uint, @ctz(val)));29 return @as(c_int, @bitCast(@as(c_uint, @ctz(val))));
30}30}
31pub inline fn __builtin_clz(val: c_uint) c_int {31pub inline fn __builtin_clz(val: c_uint) c_int {
32 // Returns the number of leading 0-bits in x, starting at the most significant bit position.32 // Returns the number of leading 0-bits in x, starting at the most significant bit position.
33 // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint33 // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint
34 @setRuntimeSafety(false);34 @setRuntimeSafety(false);
35 return @bitCast(c_int, @as(c_uint, @clz(val)));35 return @as(c_int, @bitCast(@as(c_uint, @clz(val))));
36}36}
3737
38pub inline fn __builtin_sqrt(val: f64) f64 {38pub inline fn __builtin_sqrt(val: f64) f64 {
...@@ -135,7 +135,7 @@ pub inline fn __builtin_object_size(ptr: ?*const anyopaque, ty: c_int) usize {...@@ -135,7 +135,7 @@ pub inline fn __builtin_object_size(ptr: ?*const anyopaque, ty: c_int) usize {
135 // If it is not possible to determine which objects ptr points to at compile time,135 // If it is not possible to determine which objects ptr points to at compile time,
136 // __builtin_object_size should return (size_t) -1 for type 0 or 1 and (size_t) 0136 // __builtin_object_size should return (size_t) -1 for type 0 or 1 and (size_t) 0
137 // for type 2 or 3.137 // for type 2 or 3.
138 if (ty == 0 or ty == 1) return @bitCast(usize, -@as(isize, 1));138 if (ty == 0 or ty == 1) return @as(usize, @bitCast(-@as(isize, 1)));
139 if (ty == 2 or ty == 3) return 0;139 if (ty == 2 or ty == 3) return 0;
140 unreachable;140 unreachable;
141}141}
...@@ -151,8 +151,8 @@ pub inline fn __builtin___memset_chk(...@@ -151,8 +151,8 @@ pub inline fn __builtin___memset_chk(
151}151}
152152
153pub inline fn __builtin_memset(dst: ?*anyopaque, val: c_int, len: usize) ?*anyopaque {153pub inline fn __builtin_memset(dst: ?*anyopaque, val: c_int, len: usize) ?*anyopaque {
154 const dst_cast = @ptrCast([*c]u8, dst);154 const dst_cast = @as([*c]u8, @ptrCast(dst));
155 @memset(dst_cast[0..len], @bitCast(u8, @truncate(i8, val)));155 @memset(dst_cast[0..len], @as(u8, @bitCast(@as(i8, @truncate(val)))));
156 return dst;156 return dst;
157}157}
158158
...@@ -172,8 +172,8 @@ pub inline fn __builtin_memcpy(...@@ -172,8 +172,8 @@ pub inline fn __builtin_memcpy(
172 len: usize,172 len: usize,
173) ?*anyopaque {173) ?*anyopaque {
174 if (len > 0) @memcpy(174 if (len > 0) @memcpy(
175 @ptrCast([*]u8, dst.?)[0..len],175 @as([*]u8, @ptrCast(dst.?))[0..len],
176 @ptrCast([*]const u8, src.?),176 @as([*]const u8, @ptrCast(src.?)),
177 );177 );
178 return dst;178 return dst;
179}179}
...@@ -202,8 +202,8 @@ pub inline fn __builtin_expect(expr: c_long, c: c_long) c_long {...@@ -202,8 +202,8 @@ pub inline fn __builtin_expect(expr: c_long, c: c_long) c_long {
202/// If tagp is empty, the function returns a NaN whose significand is zero.202/// If tagp is empty, the function returns a NaN whose significand is zero.
203pub inline fn __builtin_nanf(tagp: []const u8) f32 {203pub inline fn __builtin_nanf(tagp: []const u8) f32 {
204 const parsed = std.fmt.parseUnsigned(c_ulong, tagp, 0) catch 0;204 const parsed = std.fmt.parseUnsigned(c_ulong, tagp, 0) catch 0;
205 const bits = @truncate(u23, parsed); // single-precision float trailing significand is 23 bits205 const bits = @as(u23, @truncate(parsed)); // single-precision float trailing significand is 23 bits
206 return @bitCast(f32, @as(u32, bits) | std.math.qnan_u32);206 return @as(f32, @bitCast(@as(u32, bits) | std.math.qnan_u32));
207}207}
208208
209pub inline fn __builtin_huge_valf() f32 {209pub inline fn __builtin_huge_valf() f32 {
lib/std/zig/c_translation.zig+27-38
...@@ -42,9 +42,9 @@ pub fn cast(comptime DestType: type, target: anytype) DestType {...@@ -42,9 +42,9 @@ pub fn cast(comptime DestType: type, target: anytype) DestType {
42 },42 },
43 .Float => {43 .Float => {
44 switch (@typeInfo(SourceType)) {44 switch (@typeInfo(SourceType)) {
45 .Int => return @floatFromInt(DestType, target),45 .Int => return @as(DestType, @floatFromInt(target)),
46 .Float => return @floatCast(DestType, target),46 .Float => return @as(DestType, @floatCast(target)),
47 .Bool => return @floatFromInt(DestType, @intFromBool(target)),47 .Bool => return @as(DestType, @floatFromInt(@intFromBool(target))),
48 else => {},48 else => {},
49 }49 }
50 },50 },
...@@ -65,36 +65,25 @@ fn castInt(comptime DestType: type, target: anytype) DestType {...@@ -65,36 +65,25 @@ fn castInt(comptime DestType: type, target: anytype) DestType {
65 const source = @typeInfo(@TypeOf(target)).Int;65 const source = @typeInfo(@TypeOf(target)).Int;
6666
67 if (dest.bits < source.bits)67 if (dest.bits < source.bits)
68 return @bitCast(DestType, @truncate(std.meta.Int(source.signedness, dest.bits), target))68 return @as(DestType, @bitCast(@as(std.meta.Int(source.signedness, dest.bits), @truncate(target))))
69 else69 else
70 return @bitCast(DestType, @as(std.meta.Int(source.signedness, dest.bits), target));70 return @as(DestType, @bitCast(@as(std.meta.Int(source.signedness, dest.bits), target)));
71}71}
7272
73fn castPtr(comptime DestType: type, target: anytype) DestType {73fn castPtr(comptime DestType: type, target: anytype) DestType {
74 const dest = ptrInfo(DestType);74 return @constCast(@volatileCast(@alignCast(@ptrCast(target))));
75 const source = ptrInfo(@TypeOf(target));
76
77 if (source.is_const and !dest.is_const)
78 return @constCast(target)
79 else if (source.is_volatile and !dest.is_volatile)
80 return @volatileCast(target)
81 else if (@typeInfo(dest.child) == .Opaque)
82 // dest.alignment would error out
83 return @ptrCast(DestType, target)
84 else
85 return @ptrCast(DestType, @alignCast(dest.alignment, target));
86}75}
8776
88fn castToPtr(comptime DestType: type, comptime SourceType: type, target: anytype) DestType {77fn castToPtr(comptime DestType: type, comptime SourceType: type, target: anytype) DestType {
89 switch (@typeInfo(SourceType)) {78 switch (@typeInfo(SourceType)) {
90 .Int => {79 .Int => {
91 return @ptrFromInt(DestType, castInt(usize, target));80 return @as(DestType, @ptrFromInt(castInt(usize, target)));
92 },81 },
93 .ComptimeInt => {82 .ComptimeInt => {
94 if (target < 0)83 if (target < 0)
95 return @ptrFromInt(DestType, @bitCast(usize, @intCast(isize, target)))84 return @as(DestType, @ptrFromInt(@as(usize, @bitCast(@as(isize, @intCast(target))))))
96 else85 else
97 return @ptrFromInt(DestType, @intCast(usize, target));86 return @as(DestType, @ptrFromInt(@as(usize, @intCast(target))));
98 },87 },
99 .Pointer => {88 .Pointer => {
100 return castPtr(DestType, target);89 return castPtr(DestType, target);
...@@ -120,34 +109,34 @@ fn ptrInfo(comptime PtrType: type) std.builtin.Type.Pointer {...@@ -120,34 +109,34 @@ fn ptrInfo(comptime PtrType: type) std.builtin.Type.Pointer {
120test "cast" {109test "cast" {
121 var i = @as(i64, 10);110 var i = @as(i64, 10);
122111
123 try testing.expect(cast(*u8, 16) == @ptrFromInt(*u8, 16));112 try testing.expect(cast(*u8, 16) == @as(*u8, @ptrFromInt(16)));
124 try testing.expect(cast(*u64, &i).* == @as(u64, 10));113 try testing.expect(cast(*u64, &i).* == @as(u64, 10));
125 try testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i);114 try testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i);
126115
127 try testing.expect(cast(?*u8, 2) == @ptrFromInt(*u8, 2));116 try testing.expect(cast(?*u8, 2) == @as(*u8, @ptrFromInt(2)));
128 try testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i);117 try testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i);
129 try testing.expect(cast(?*i64, @as(?*align(1) i64, &i)) == &i);118 try testing.expect(cast(?*i64, @as(?*align(1) i64, &i)) == &i);
130119
131 try testing.expectEqual(@as(u32, 4), cast(u32, @ptrFromInt(*u32, 4)));120 try testing.expectEqual(@as(u32, 4), cast(u32, @as(*u32, @ptrFromInt(4))));
132 try testing.expectEqual(@as(u32, 4), cast(u32, @ptrFromInt(?*u32, 4)));121 try testing.expectEqual(@as(u32, 4), cast(u32, @as(?*u32, @ptrFromInt(4))));
133 try testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10)));122 try testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10)));
134123
135 try testing.expectEqual(@bitCast(i32, @as(u32, 0x8000_0000)), cast(i32, @as(u32, 0x8000_0000)));124 try testing.expectEqual(@as(i32, @bitCast(@as(u32, 0x8000_0000))), cast(i32, @as(u32, 0x8000_0000)));
136125
137 try testing.expectEqual(@ptrFromInt(*u8, 2), cast(*u8, @ptrFromInt(*const u8, 2)));126 try testing.expectEqual(@as(*u8, @ptrFromInt(2)), cast(*u8, @as(*const u8, @ptrFromInt(2))));
138 try testing.expectEqual(@ptrFromInt(*u8, 2), cast(*u8, @ptrFromInt(*volatile u8, 2)));127 try testing.expectEqual(@as(*u8, @ptrFromInt(2)), cast(*u8, @as(*volatile u8, @ptrFromInt(2))));
139128
140 try testing.expectEqual(@ptrFromInt(?*anyopaque, 2), cast(?*anyopaque, @ptrFromInt(*u8, 2)));129 try testing.expectEqual(@as(?*anyopaque, @ptrFromInt(2)), cast(?*anyopaque, @as(*u8, @ptrFromInt(2))));
141130
142 var foo: c_int = -1;131 var foo: c_int = -1;
143 try testing.expect(cast(*anyopaque, -1) == @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -1))));132 try testing.expect(cast(*anyopaque, -1) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
144 try testing.expect(cast(*anyopaque, foo) == @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -1))));133 try testing.expect(cast(*anyopaque, foo) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
145 try testing.expect(cast(?*anyopaque, -1) == @ptrFromInt(?*anyopaque, @bitCast(usize, @as(isize, -1))));134 try testing.expect(cast(?*anyopaque, -1) == @as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
146 try testing.expect(cast(?*anyopaque, foo) == @ptrFromInt(?*anyopaque, @bitCast(usize, @as(isize, -1))));135 try testing.expect(cast(?*anyopaque, foo) == @as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
147136
148 const FnPtr = ?*align(1) const fn (*anyopaque) void;137 const FnPtr = ?*align(1) const fn (*anyopaque) void;
149 try testing.expect(cast(FnPtr, 0) == @ptrFromInt(FnPtr, @as(usize, 0)));138 try testing.expect(cast(FnPtr, 0) == @as(FnPtr, @ptrFromInt(@as(usize, 0))));
150 try testing.expect(cast(FnPtr, foo) == @ptrFromInt(FnPtr, @bitCast(usize, @as(isize, -1))));139 try testing.expect(cast(FnPtr, foo) == @as(FnPtr, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
151}140}
152141
153/// Given a value returns its size as C's sizeof operator would.142/// Given a value returns its size as C's sizeof operator would.
...@@ -192,7 +181,7 @@ pub fn sizeof(target: anytype) usize {...@@ -192,7 +181,7 @@ pub fn sizeof(target: anytype) usize {
192 const array_info = @typeInfo(ptr.child).Array;181 const array_info = @typeInfo(ptr.child).Array;
193 if ((array_info.child == u8 or array_info.child == u16) and182 if ((array_info.child == u8 or array_info.child == u16) and
194 array_info.sentinel != null and183 array_info.sentinel != null and
195 @ptrCast(*align(1) const array_info.child, array_info.sentinel.?).* == 0)184 @as(*align(1) const array_info.child, @ptrCast(array_info.sentinel.?)).* == 0)
196 {185 {
197 // length of the string plus one for the null terminator.186 // length of the string plus one for the null terminator.
198 return (array_info.len + 1) * @sizeOf(array_info.child);187 return (array_info.len + 1) * @sizeOf(array_info.child);
...@@ -325,10 +314,10 @@ test "promoteIntLiteral" {...@@ -325,10 +314,10 @@ test "promoteIntLiteral" {
325pub fn shuffleVectorIndex(comptime this_index: c_int, comptime source_vector_len: usize) i32 {314pub fn shuffleVectorIndex(comptime this_index: c_int, comptime source_vector_len: usize) i32 {
326 if (this_index <= 0) return 0;315 if (this_index <= 0) return 0;
327316
328 const positive_index = @intCast(usize, this_index);317 const positive_index = @as(usize, @intCast(this_index));
329 if (positive_index < source_vector_len) return @intCast(i32, this_index);318 if (positive_index < source_vector_len) return @as(i32, @intCast(this_index));
330 const b_index = positive_index - source_vector_len;319 const b_index = positive_index - source_vector_len;
331 return ~@intCast(i32, b_index);320 return ~@as(i32, @intCast(b_index));
332}321}
333322
334test "shuffleVectorIndex" {323test "shuffleVectorIndex" {
lib/std/zig/number_literal.zig+3-3
...@@ -141,7 +141,7 @@ pub fn parseNumberLiteral(bytes: []const u8) Result {...@@ -141,7 +141,7 @@ pub fn parseNumberLiteral(bytes: []const u8) Result {
141 'a'...'z' => c - 'a' + 10,141 'a'...'z' => c - 'a' + 10,
142 else => return .{ .failure = .{ .invalid_character = i } },142 else => return .{ .failure = .{ .invalid_character = i } },
143 };143 };
144 if (digit >= base) return .{ .failure = .{ .invalid_digit = .{ .i = i, .base = @enumFromInt(Base, base) } } };144 if (digit >= base) return .{ .failure = .{ .invalid_digit = .{ .i = i, .base = @as(Base, @enumFromInt(base)) } } };
145 if (exponent and digit >= 10) return .{ .failure = .{ .invalid_digit_exponent = i } };145 if (exponent and digit >= 10) return .{ .failure = .{ .invalid_digit_exponent = i } };
146 underscore = false;146 underscore = false;
147 special = 0;147 special = 0;
...@@ -159,7 +159,7 @@ pub fn parseNumberLiteral(bytes: []const u8) Result {...@@ -159,7 +159,7 @@ pub fn parseNumberLiteral(bytes: []const u8) Result {
159 if (underscore) return .{ .failure = .{ .trailing_underscore = bytes.len - 1 } };159 if (underscore) return .{ .failure = .{ .trailing_underscore = bytes.len - 1 } };
160 if (special != 0) return .{ .failure = .{ .trailing_special = bytes.len - 1 } };160 if (special != 0) return .{ .failure = .{ .trailing_special = bytes.len - 1 } };
161161
162 if (float) return .{ .float = @enumFromInt(FloatBase, base) };162 if (float) return .{ .float = @as(FloatBase, @enumFromInt(base)) };
163 if (overflow) return .{ .big_int = @enumFromInt(Base, base) };163 if (overflow) return .{ .big_int = @as(Base, @enumFromInt(base)) };
164 return .{ .int = x };164 return .{ .int = x };
165}165}
lib/std/zig/parser_test.zig+10-10
...@@ -166,10 +166,10 @@ test "zig fmt: respect line breaks after var declarations" {...@@ -166,10 +166,10 @@ test "zig fmt: respect line breaks after var declarations" {
166 \\ lookup_tables[1][p[6]] ^166 \\ lookup_tables[1][p[6]] ^
167 \\ lookup_tables[2][p[5]] ^167 \\ lookup_tables[2][p[5]] ^
168 \\ lookup_tables[3][p[4]] ^168 \\ lookup_tables[3][p[4]] ^
169 \\ lookup_tables[4][@truncate(u8, self.crc >> 24)] ^169 \\ lookup_tables[4][@as(u8, self.crc >> 24)] ^
170 \\ lookup_tables[5][@truncate(u8, self.crc >> 16)] ^170 \\ lookup_tables[5][@as(u8, self.crc >> 16)] ^
171 \\ lookup_tables[6][@truncate(u8, self.crc >> 8)] ^171 \\ lookup_tables[6][@as(u8, self.crc >> 8)] ^
172 \\ lookup_tables[7][@truncate(u8, self.crc >> 0)];172 \\ lookup_tables[7][@as(u8, self.crc >> 0)];
173 \\173 \\
174 );174 );
175}175}
...@@ -1108,7 +1108,7 @@ test "zig fmt: async function" {...@@ -1108,7 +1108,7 @@ test "zig fmt: async function" {
1108 \\ handleRequestFn: fn (*Server, *const std.net.Address, File) callconv(.Async) void,1108 \\ handleRequestFn: fn (*Server, *const std.net.Address, File) callconv(.Async) void,
1109 \\};1109 \\};
1110 \\test "hi" {1110 \\test "hi" {
1111 \\ var ptr = @ptrCast(fn (i32) callconv(.Async) void, other);1111 \\ var ptr: fn (i32) callconv(.Async) void = @ptrCast(other);
1112 \\}1112 \\}
1113 \\1113 \\
1114 );1114 );
...@@ -1825,10 +1825,10 @@ test "zig fmt: respect line breaks after infix operators" {...@@ -1825,10 +1825,10 @@ test "zig fmt: respect line breaks after infix operators" {
1825 \\ lookup_tables[1][p[6]] ^1825 \\ lookup_tables[1][p[6]] ^
1826 \\ lookup_tables[2][p[5]] ^1826 \\ lookup_tables[2][p[5]] ^
1827 \\ lookup_tables[3][p[4]] ^1827 \\ lookup_tables[3][p[4]] ^
1828 \\ lookup_tables[4][@truncate(u8, self.crc >> 24)] ^1828 \\ lookup_tables[4][@as(u8, self.crc >> 24)] ^
1829 \\ lookup_tables[5][@truncate(u8, self.crc >> 16)] ^1829 \\ lookup_tables[5][@as(u8, self.crc >> 16)] ^
1830 \\ lookup_tables[6][@truncate(u8, self.crc >> 8)] ^1830 \\ lookup_tables[6][@as(u8, self.crc >> 8)] ^
1831 \\ lookup_tables[7][@truncate(u8, self.crc >> 0)];1831 \\ lookup_tables[7][@as(u8, self.crc >> 0)];
1832 \\}1832 \\}
1833 \\1833 \\
1834 );1834 );
...@@ -4814,7 +4814,7 @@ test "zig fmt: use of comments and multiline string literals may force the param...@@ -4814,7 +4814,7 @@ test "zig fmt: use of comments and multiline string literals may force the param
4814 \\ \\ unknown-length pointers and C pointers cannot be hashed deeply.4814 \\ \\ unknown-length pointers and C pointers cannot be hashed deeply.
4815 \\ \\ Consider providing your own hash function.4815 \\ \\ Consider providing your own hash function.
4816 \\ );4816 \\ );
4817 \\ return @intCast(i1, doMemCheckClientRequestExpr(0, // default return4817 \\ return @intCast(doMemCheckClientRequestExpr(0, // default return
4818 \\ .MakeMemUndefined, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0));4818 \\ .MakeMemUndefined, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0));
4819 \\}4819 \\}
4820 \\4820 \\
lib/std/zig/perf_test.zig+3-3
...@@ -18,9 +18,9 @@ pub fn main() !void {...@@ -18,9 +18,9 @@ pub fn main() !void {
18 }18 }
19 const end = timer.read();19 const end = timer.read();
20 memory_used /= iterations;20 memory_used /= iterations;
21 const elapsed_s = @floatFromInt(f64, end - start) / std.time.ns_per_s;21 const elapsed_s = @as(f64, @floatFromInt(end - start)) / std.time.ns_per_s;
22 const bytes_per_sec_float = @floatFromInt(f64, source.len * iterations) / elapsed_s;22 const bytes_per_sec_float = @as(f64, @floatFromInt(source.len * iterations)) / elapsed_s;
23 const bytes_per_sec = @intFromFloat(u64, @floor(bytes_per_sec_float));23 const bytes_per_sec = @as(u64, @intFromFloat(@floor(bytes_per_sec_float)));
2424
25 var stdout_file = std.io.getStdOut();25 var stdout_file = std.io.getStdOut();
26 const stdout = stdout_file.writer();26 const stdout = stdout_file.writer();
lib/std/zig/render.zig+2-2
...@@ -2719,7 +2719,7 @@ fn renderIdentifier(ais: *Ais, tree: Ast, token_index: Ast.TokenIndex, space: Sp...@@ -2719,7 +2719,7 @@ fn renderIdentifier(ais: *Ais, tree: Ast, token_index: Ast.TokenIndex, space: Sp
2719 while (contents_i < contents.len and buf_i < longest_keyword_or_primitive_len) {2719 while (contents_i < contents.len and buf_i < longest_keyword_or_primitive_len) {
2720 if (contents[contents_i] == '\\') {2720 if (contents[contents_i] == '\\') {
2721 const res = std.zig.string_literal.parseEscapeSequence(contents, &contents_i).success;2721 const res = std.zig.string_literal.parseEscapeSequence(contents, &contents_i).success;
2722 buf[buf_i] = @intCast(u8, res);2722 buf[buf_i] = @as(u8, @intCast(res));
2723 buf_i += 1;2723 buf_i += 1;
2724 } else {2724 } else {
2725 buf[buf_i] = contents[contents_i];2725 buf[buf_i] = contents[contents_i];
...@@ -2773,7 +2773,7 @@ fn renderIdentifierContents(writer: anytype, bytes: []const u8) !void {...@@ -2773,7 +2773,7 @@ fn renderIdentifierContents(writer: anytype, bytes: []const u8) !void {
2773 switch (res) {2773 switch (res) {
2774 .success => |codepoint| {2774 .success => |codepoint| {
2775 if (codepoint <= 0x7f) {2775 if (codepoint <= 0x7f) {
2776 const buf = [1]u8{@intCast(u8, codepoint)};2776 const buf = [1]u8{@as(u8, @intCast(codepoint))};
2777 try std.fmt.format(writer, "{}", .{std.zig.fmtEscapes(&buf)});2777 try std.fmt.format(writer, "{}", .{std.zig.fmtEscapes(&buf)});
2778 } else {2778 } else {
2779 try writer.writeAll(escape_sequence);2779 try writer.writeAll(escape_sequence);
lib/std/zig/string_literal.zig+2-2
...@@ -142,7 +142,7 @@ pub fn parseEscapeSequence(slice: []const u8, offset: *usize) ParsedCharLiteral...@@ -142,7 +142,7 @@ pub fn parseEscapeSequence(slice: []const u8, offset: *usize) ParsedCharLiteral
142 return .{ .failure = .{ .expected_rbrace = i } };142 return .{ .failure = .{ .expected_rbrace = i } };
143 }143 }
144 offset.* = i;144 offset.* = i;
145 return .{ .success = @intCast(u21, value) };145 return .{ .success = @as(u21, @intCast(value)) };
146 },146 },
147 else => return .{ .failure = .{ .invalid_escape_character = offset.* - 1 } },147 else => return .{ .failure = .{ .invalid_escape_character = offset.* - 1 } },
148 }148 }
...@@ -253,7 +253,7 @@ pub fn parseWrite(writer: anytype, bytes: []const u8) error{OutOfMemory}!Result...@@ -253,7 +253,7 @@ pub fn parseWrite(writer: anytype, bytes: []const u8) error{OutOfMemory}!Result
253 };253 };
254 try writer.writeAll(buf[0..len]);254 try writer.writeAll(buf[0..len]);
255 } else {255 } else {
256 try writer.writeByte(@intCast(u8, codepoint));256 try writer.writeByte(@as(u8, @intCast(codepoint)));
257 }257 }
258 },258 },
259 .failure => |err| return Result{ .failure = err },259 .failure => |err| return Result{ .failure = err },
lib/std/zig/system/NativeTargetInfo.zig+19-37
...@@ -479,8 +479,8 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion {...@@ -479,8 +479,8 @@ fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion {
479fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion {479fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion {
480 var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 align(@alignOf(elf.Elf64_Ehdr)) = undefined;480 var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 align(@alignOf(elf.Elf64_Ehdr)) = undefined;
481 _ = try preadMin(file, &hdr_buf, 0, hdr_buf.len);481 _ = try preadMin(file, &hdr_buf, 0, hdr_buf.len);
482 const hdr32 = @ptrCast(*elf.Elf32_Ehdr, &hdr_buf);482 const hdr32 = @as(*elf.Elf32_Ehdr, @ptrCast(&hdr_buf));
483 const hdr64 = @ptrCast(*elf.Elf64_Ehdr, &hdr_buf);483 const hdr64 = @as(*elf.Elf64_Ehdr, @ptrCast(&hdr_buf));
484 if (!mem.eql(u8, hdr32.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic;484 if (!mem.eql(u8, hdr32.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic;
485 const elf_endian: std.builtin.Endian = switch (hdr32.e_ident[elf.EI_DATA]) {485 const elf_endian: std.builtin.Endian = switch (hdr32.e_ident[elf.EI_DATA]) {
486 elf.ELFDATA2LSB => .Little,486 elf.ELFDATA2LSB => .Little,
...@@ -503,8 +503,8 @@ fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion {...@@ -503,8 +503,8 @@ fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion {
503 if (sh_buf.len < shentsize) return error.InvalidElfFile;503 if (sh_buf.len < shentsize) return error.InvalidElfFile;
504504
505 _ = try preadMin(file, &sh_buf, str_section_off, shentsize);505 _ = try preadMin(file, &sh_buf, str_section_off, shentsize);
506 const shstr32 = @ptrCast(*elf.Elf32_Shdr, @alignCast(@alignOf(elf.Elf32_Shdr), &sh_buf));506 const shstr32: *elf.Elf32_Shdr = @ptrCast(@alignCast(&sh_buf));
507 const shstr64 = @ptrCast(*elf.Elf64_Shdr, @alignCast(@alignOf(elf.Elf64_Shdr), &sh_buf));507 const shstr64: *elf.Elf64_Shdr = @ptrCast(@alignCast(&sh_buf));
508 const shstrtab_off = elfInt(is_64, need_bswap, shstr32.sh_offset, shstr64.sh_offset);508 const shstrtab_off = elfInt(is_64, need_bswap, shstr32.sh_offset, shstr64.sh_offset);
509 const shstrtab_size = elfInt(is_64, need_bswap, shstr32.sh_size, shstr64.sh_size);509 const shstrtab_size = elfInt(is_64, need_bswap, shstr32.sh_size, shstr64.sh_size);
510 var strtab_buf: [4096:0]u8 = undefined;510 var strtab_buf: [4096:0]u8 = undefined;
...@@ -529,14 +529,8 @@ fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion {...@@ -529,14 +529,8 @@ fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion {
529 shoff += shentsize;529 shoff += shentsize;
530 sh_buf_i += shentsize;530 sh_buf_i += shentsize;
531 }) {531 }) {
532 const sh32 = @ptrCast(532 const sh32: *elf.Elf32_Shdr = @ptrCast(@alignCast(&sh_buf[sh_buf_i]));
533 *elf.Elf32_Shdr,533 const sh64: *elf.Elf64_Shdr = @ptrCast(@alignCast(&sh_buf[sh_buf_i]));
534 @alignCast(@alignOf(elf.Elf32_Shdr), &sh_buf[sh_buf_i]),
535 );
536 const sh64 = @ptrCast(
537 *elf.Elf64_Shdr,
538 @alignCast(@alignOf(elf.Elf64_Shdr), &sh_buf[sh_buf_i]),
539 );
540 const sh_name_off = elfInt(is_64, need_bswap, sh32.sh_name, sh64.sh_name);534 const sh_name_off = elfInt(is_64, need_bswap, sh32.sh_name, sh64.sh_name);
541 const sh_name = mem.sliceTo(shstrtab[sh_name_off..], 0);535 const sh_name = mem.sliceTo(shstrtab[sh_name_off..], 0);
542 if (mem.eql(u8, sh_name, ".dynstr")) {536 if (mem.eql(u8, sh_name, ".dynstr")) {
...@@ -558,7 +552,7 @@ fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion {...@@ -558,7 +552,7 @@ fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion {
558 var buf: [80000]u8 = undefined;552 var buf: [80000]u8 = undefined;
559 if (buf.len < dynstr.size) return error.InvalidGnuLibCVersion;553 if (buf.len < dynstr.size) return error.InvalidGnuLibCVersion;
560554
561 const dynstr_size = @intCast(usize, dynstr.size);555 const dynstr_size = @as(usize, @intCast(dynstr.size));
562 const dynstr_bytes = buf[0..dynstr_size];556 const dynstr_bytes = buf[0..dynstr_size];
563 _ = try preadMin(file, dynstr_bytes, dynstr.offset, dynstr_bytes.len);557 _ = try preadMin(file, dynstr_bytes, dynstr.offset, dynstr_bytes.len);
564 var it = mem.splitScalar(u8, dynstr_bytes, 0);558 var it = mem.splitScalar(u8, dynstr_bytes, 0);
...@@ -621,8 +615,8 @@ pub fn abiAndDynamicLinkerFromFile(...@@ -621,8 +615,8 @@ pub fn abiAndDynamicLinkerFromFile(
621) AbiAndDynamicLinkerFromFileError!NativeTargetInfo {615) AbiAndDynamicLinkerFromFileError!NativeTargetInfo {
622 var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 align(@alignOf(elf.Elf64_Ehdr)) = undefined;616 var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 align(@alignOf(elf.Elf64_Ehdr)) = undefined;
623 _ = try preadMin(file, &hdr_buf, 0, hdr_buf.len);617 _ = try preadMin(file, &hdr_buf, 0, hdr_buf.len);
624 const hdr32 = @ptrCast(*elf.Elf32_Ehdr, &hdr_buf);618 const hdr32 = @as(*elf.Elf32_Ehdr, @ptrCast(&hdr_buf));
625 const hdr64 = @ptrCast(*elf.Elf64_Ehdr, &hdr_buf);619 const hdr64 = @as(*elf.Elf64_Ehdr, @ptrCast(&hdr_buf));
626 if (!mem.eql(u8, hdr32.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic;620 if (!mem.eql(u8, hdr32.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic;
627 const elf_endian: std.builtin.Endian = switch (hdr32.e_ident[elf.EI_DATA]) {621 const elf_endian: std.builtin.Endian = switch (hdr32.e_ident[elf.EI_DATA]) {
628 elf.ELFDATA2LSB => .Little,622 elf.ELFDATA2LSB => .Little,
...@@ -668,21 +662,21 @@ pub fn abiAndDynamicLinkerFromFile(...@@ -668,21 +662,21 @@ pub fn abiAndDynamicLinkerFromFile(
668 phoff += phentsize;662 phoff += phentsize;
669 ph_buf_i += phentsize;663 ph_buf_i += phentsize;
670 }) {664 }) {
671 const ph32 = @ptrCast(*elf.Elf32_Phdr, @alignCast(@alignOf(elf.Elf32_Phdr), &ph_buf[ph_buf_i]));665 const ph32: *elf.Elf32_Phdr = @ptrCast(@alignCast(&ph_buf[ph_buf_i]));
672 const ph64 = @ptrCast(*elf.Elf64_Phdr, @alignCast(@alignOf(elf.Elf64_Phdr), &ph_buf[ph_buf_i]));666 const ph64: *elf.Elf64_Phdr = @ptrCast(@alignCast(&ph_buf[ph_buf_i]));
673 const p_type = elfInt(is_64, need_bswap, ph32.p_type, ph64.p_type);667 const p_type = elfInt(is_64, need_bswap, ph32.p_type, ph64.p_type);
674 switch (p_type) {668 switch (p_type) {
675 elf.PT_INTERP => if (look_for_ld) {669 elf.PT_INTERP => if (look_for_ld) {
676 const p_offset = elfInt(is_64, need_bswap, ph32.p_offset, ph64.p_offset);670 const p_offset = elfInt(is_64, need_bswap, ph32.p_offset, ph64.p_offset);
677 const p_filesz = elfInt(is_64, need_bswap, ph32.p_filesz, ph64.p_filesz);671 const p_filesz = elfInt(is_64, need_bswap, ph32.p_filesz, ph64.p_filesz);
678 if (p_filesz > result.dynamic_linker.buffer.len) return error.NameTooLong;672 if (p_filesz > result.dynamic_linker.buffer.len) return error.NameTooLong;
679 const filesz = @intCast(usize, p_filesz);673 const filesz = @as(usize, @intCast(p_filesz));
680 _ = try preadMin(file, result.dynamic_linker.buffer[0..filesz], p_offset, filesz);674 _ = try preadMin(file, result.dynamic_linker.buffer[0..filesz], p_offset, filesz);
681 // PT_INTERP includes a null byte in filesz.675 // PT_INTERP includes a null byte in filesz.
682 const len = filesz - 1;676 const len = filesz - 1;
683 // dynamic_linker.max_byte is "max", not "len".677 // dynamic_linker.max_byte is "max", not "len".
684 // We know it will fit in u8 because we check against dynamic_linker.buffer.len above.678 // We know it will fit in u8 because we check against dynamic_linker.buffer.len above.
685 result.dynamic_linker.max_byte = @intCast(u8, len - 1);679 result.dynamic_linker.max_byte = @as(u8, @intCast(len - 1));
686680
687 // Use it to determine ABI.681 // Use it to determine ABI.
688 const full_ld_path = result.dynamic_linker.buffer[0..len];682 const full_ld_path = result.dynamic_linker.buffer[0..len];
...@@ -720,14 +714,8 @@ pub fn abiAndDynamicLinkerFromFile(...@@ -720,14 +714,8 @@ pub fn abiAndDynamicLinkerFromFile(
720 dyn_off += dyn_size;714 dyn_off += dyn_size;
721 dyn_buf_i += dyn_size;715 dyn_buf_i += dyn_size;
722 }) {716 }) {
723 const dyn32 = @ptrCast(717 const dyn32: *elf.Elf32_Dyn = @ptrCast(@alignCast(&dyn_buf[dyn_buf_i]));
724 *elf.Elf32_Dyn,718 const dyn64: *elf.Elf64_Dyn = @ptrCast(@alignCast(&dyn_buf[dyn_buf_i]));
725 @alignCast(@alignOf(elf.Elf32_Dyn), &dyn_buf[dyn_buf_i]),
726 );
727 const dyn64 = @ptrCast(
728 *elf.Elf64_Dyn,
729 @alignCast(@alignOf(elf.Elf64_Dyn), &dyn_buf[dyn_buf_i]),
730 );
731 const tag = elfInt(is_64, need_bswap, dyn32.d_tag, dyn64.d_tag);719 const tag = elfInt(is_64, need_bswap, dyn32.d_tag, dyn64.d_tag);
732 const val = elfInt(is_64, need_bswap, dyn32.d_val, dyn64.d_val);720 const val = elfInt(is_64, need_bswap, dyn32.d_val, dyn64.d_val);
733 if (tag == elf.DT_RUNPATH) {721 if (tag == elf.DT_RUNPATH) {
...@@ -755,8 +743,8 @@ pub fn abiAndDynamicLinkerFromFile(...@@ -755,8 +743,8 @@ pub fn abiAndDynamicLinkerFromFile(
755 if (sh_buf.len < shentsize) return error.InvalidElfFile;743 if (sh_buf.len < shentsize) return error.InvalidElfFile;
756744
757 _ = try preadMin(file, &sh_buf, str_section_off, shentsize);745 _ = try preadMin(file, &sh_buf, str_section_off, shentsize);
758 const shstr32 = @ptrCast(*elf.Elf32_Shdr, @alignCast(@alignOf(elf.Elf32_Shdr), &sh_buf));746 const shstr32: *elf.Elf32_Shdr = @ptrCast(@alignCast(&sh_buf));
759 const shstr64 = @ptrCast(*elf.Elf64_Shdr, @alignCast(@alignOf(elf.Elf64_Shdr), &sh_buf));747 const shstr64: *elf.Elf64_Shdr = @ptrCast(@alignCast(&sh_buf));
760 const shstrtab_off = elfInt(is_64, need_bswap, shstr32.sh_offset, shstr64.sh_offset);748 const shstrtab_off = elfInt(is_64, need_bswap, shstr32.sh_offset, shstr64.sh_offset);
761 const shstrtab_size = elfInt(is_64, need_bswap, shstr32.sh_size, shstr64.sh_size);749 const shstrtab_size = elfInt(is_64, need_bswap, shstr32.sh_size, shstr64.sh_size);
762 var strtab_buf: [4096:0]u8 = undefined;750 var strtab_buf: [4096:0]u8 = undefined;
...@@ -782,14 +770,8 @@ pub fn abiAndDynamicLinkerFromFile(...@@ -782,14 +770,8 @@ pub fn abiAndDynamicLinkerFromFile(
782 shoff += shentsize;770 shoff += shentsize;
783 sh_buf_i += shentsize;771 sh_buf_i += shentsize;
784 }) {772 }) {
785 const sh32 = @ptrCast(773 const sh32: *elf.Elf32_Shdr = @ptrCast(@alignCast(&sh_buf[sh_buf_i]));
786 *elf.Elf32_Shdr,774 const sh64: *elf.Elf64_Shdr = @ptrCast(@alignCast(&sh_buf[sh_buf_i]));
787 @alignCast(@alignOf(elf.Elf32_Shdr), &sh_buf[sh_buf_i]),
788 );
789 const sh64 = @ptrCast(
790 *elf.Elf64_Shdr,
791 @alignCast(@alignOf(elf.Elf64_Shdr), &sh_buf[sh_buf_i]),
792 );
793 const sh_name_off = elfInt(is_64, need_bswap, sh32.sh_name, sh64.sh_name);775 const sh_name_off = elfInt(is_64, need_bswap, sh32.sh_name, sh64.sh_name);
794 const sh_name = mem.sliceTo(shstrtab[sh_name_off..], 0);776 const sh_name = mem.sliceTo(shstrtab[sh_name_off..], 0);
795 if (mem.eql(u8, sh_name, ".dynstr")) {777 if (mem.eql(u8, sh_name, ".dynstr")) {
lib/std/zig/system/arm.zig+7-7
...@@ -141,7 +141,7 @@ pub const aarch64 = struct {...@@ -141,7 +141,7 @@ pub const aarch64 = struct {
141 }141 }
142142
143 inline fn bitField(input: u64, offset: u6) u4 {143 inline fn bitField(input: u64, offset: u6) u4 {
144 return @truncate(u4, input >> offset);144 return @as(u4, @truncate(input >> offset));
145 }145 }
146146
147 /// Input array should consist of readouts from 12 system registers such that:147 /// Input array should consist of readouts from 12 system registers such that:
...@@ -176,23 +176,23 @@ pub const aarch64 = struct {...@@ -176,23 +176,23 @@ pub const aarch64 = struct {
176 /// Takes readout of MIDR_EL1 register as input.176 /// Takes readout of MIDR_EL1 register as input.
177 fn detectNativeCoreInfo(midr: u64) CoreInfo {177 fn detectNativeCoreInfo(midr: u64) CoreInfo {
178 var info = CoreInfo{178 var info = CoreInfo{
179 .implementer = @truncate(u8, midr >> 24),179 .implementer = @as(u8, @truncate(midr >> 24)),
180 .part = @truncate(u12, midr >> 4),180 .part = @as(u12, @truncate(midr >> 4)),
181 };181 };
182182
183 blk: {183 blk: {
184 if (info.implementer == 0x41) {184 if (info.implementer == 0x41) {
185 // ARM Ltd.185 // ARM Ltd.
186 const special_bits = @truncate(u4, info.part >> 8);186 const special_bits = @as(u4, @truncate(info.part >> 8));
187 if (special_bits == 0x0 or special_bits == 0x7) {187 if (special_bits == 0x0 or special_bits == 0x7) {
188 // TODO Variant and arch encoded differently.188 // TODO Variant and arch encoded differently.
189 break :blk;189 break :blk;
190 }190 }
191 }191 }
192192
193 info.variant |= @intCast(u8, @truncate(u4, midr >> 20)) << 4;193 info.variant |= @as(u8, @intCast(@as(u4, @truncate(midr >> 20)))) << 4;
194 info.variant |= @truncate(u4, midr);194 info.variant |= @as(u4, @truncate(midr));
195 info.architecture = @truncate(u4, midr >> 16);195 info.architecture = @as(u4, @truncate(midr >> 16));
196 }196 }
197197
198 return info;198 return info;
lib/std/zig/system/windows.zig+20-20
...@@ -26,8 +26,8 @@ pub fn detectRuntimeVersion() WindowsVersion {...@@ -26,8 +26,8 @@ pub fn detectRuntimeVersion() WindowsVersion {
26 // `---` `` ``--> Sub-version (Starting from Windows 10 onwards)26 // `---` `` ``--> Sub-version (Starting from Windows 10 onwards)
27 // \ `--> Service pack (Always zero in the constants defined)27 // \ `--> Service pack (Always zero in the constants defined)
28 // `--> OS version (Major & minor)28 // `--> OS version (Major & minor)
29 const os_ver: u16 = @intCast(u16, version_info.dwMajorVersion & 0xff) << 8 |29 const os_ver: u16 = @as(u16, @intCast(version_info.dwMajorVersion & 0xff)) << 8 |
30 @intCast(u16, version_info.dwMinorVersion & 0xff);30 @as(u16, @intCast(version_info.dwMinorVersion & 0xff));
31 const sp_ver: u8 = 0;31 const sp_ver: u8 = 0;
32 const sub_ver: u8 = if (os_ver >= 0x0A00) subver: {32 const sub_ver: u8 = if (os_ver >= 0x0A00) subver: {
33 // There's no other way to obtain this info beside33 // There's no other way to obtain this info beside
...@@ -38,12 +38,12 @@ pub fn detectRuntimeVersion() WindowsVersion {...@@ -38,12 +38,12 @@ pub fn detectRuntimeVersion() WindowsVersion {
38 if (version_info.dwBuildNumber >= build)38 if (version_info.dwBuildNumber >= build)
39 last_idx = i;39 last_idx = i;
40 }40 }
41 break :subver @truncate(u8, last_idx);41 break :subver @as(u8, @truncate(last_idx));
42 } else 0;42 } else 0;
4343
44 const version: u32 = @as(u32, os_ver) << 16 | @as(u16, sp_ver) << 8 | sub_ver;44 const version: u32 = @as(u32, os_ver) << 16 | @as(u16, sp_ver) << 8 | sub_ver;
4545
46 return @enumFromInt(WindowsVersion, version);46 return @as(WindowsVersion, @enumFromInt(version));
47}47}
4848
49// Technically, a registry value can be as long as 1MB. However, MS recommends storing49// Technically, a registry value can be as long as 1MB. However, MS recommends storing
...@@ -100,11 +100,11 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {...@@ -100,11 +100,11 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
100 REG.MULTI_SZ,100 REG.MULTI_SZ,
101 => {101 => {
102 comptime assert(@sizeOf(std.os.windows.UNICODE_STRING) % 2 == 0);102 comptime assert(@sizeOf(std.os.windows.UNICODE_STRING) % 2 == 0);
103 const unicode = @ptrCast(*std.os.windows.UNICODE_STRING, &tmp_bufs[i]);103 const unicode = @as(*std.os.windows.UNICODE_STRING, @ptrCast(&tmp_bufs[i]));
104 unicode.* = .{104 unicode.* = .{
105 .Length = 0,105 .Length = 0,
106 .MaximumLength = max_value_len - @sizeOf(std.os.windows.UNICODE_STRING),106 .MaximumLength = max_value_len - @sizeOf(std.os.windows.UNICODE_STRING),
107 .Buffer = @ptrCast([*]u16, tmp_bufs[i][@sizeOf(std.os.windows.UNICODE_STRING)..]),107 .Buffer = @as([*]u16, @ptrCast(tmp_bufs[i][@sizeOf(std.os.windows.UNICODE_STRING)..])),
108 };108 };
109 break :blk unicode;109 break :blk unicode;
110 },110 },
...@@ -159,7 +159,7 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {...@@ -159,7 +159,7 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
159 REG.MULTI_SZ,159 REG.MULTI_SZ,
160 => {160 => {
161 var buf = @field(args, field.name).value_buf;161 var buf = @field(args, field.name).value_buf;
162 const entry = @ptrCast(*align(1) const std.os.windows.UNICODE_STRING, table[i + 1].EntryContext);162 const entry = @as(*align(1) const std.os.windows.UNICODE_STRING, @ptrCast(table[i + 1].EntryContext));
163 const len = try std.unicode.utf16leToUtf8(buf, entry.Buffer[0 .. entry.Length / 2]);163 const len = try std.unicode.utf16leToUtf8(buf, entry.Buffer[0 .. entry.Length / 2]);
164 buf[len] = 0;164 buf[len] = 0;
165 },165 },
...@@ -168,7 +168,7 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {...@@ -168,7 +168,7 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
168 REG.DWORD_BIG_ENDIAN,168 REG.DWORD_BIG_ENDIAN,
169 REG.QWORD,169 REG.QWORD,
170 => {170 => {
171 const entry = @ptrCast([*]align(1) const u8, table[i + 1].EntryContext);171 const entry = @as([*]align(1) const u8, @ptrCast(table[i + 1].EntryContext));
172 switch (@field(args, field.name).value_type) {172 switch (@field(args, field.name).value_type) {
173 REG.DWORD, REG.DWORD_BIG_ENDIAN => {173 REG.DWORD, REG.DWORD_BIG_ENDIAN => {
174 @memcpy(@field(args, field.name).value_buf[0..4], entry[0..4]);174 @memcpy(@field(args, field.name).value_buf[0..4], entry[0..4]);
...@@ -254,18 +254,18 @@ pub fn detectNativeCpuAndFeatures() ?Target.Cpu {...@@ -254,18 +254,18 @@ pub fn detectNativeCpuAndFeatures() ?Target.Cpu {
254 // CP 4039 -> ID_AA64MMFR1_EL1254 // CP 4039 -> ID_AA64MMFR1_EL1
255 // CP 403A -> ID_AA64MMFR2_EL1255 // CP 403A -> ID_AA64MMFR2_EL1
256 getCpuInfoFromRegistry(i, .{256 getCpuInfoFromRegistry(i, .{
257 .{ .key = "CP 4000", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[0]) },257 .{ .key = "CP 4000", .value_type = REG.QWORD, .value_buf = @as(*[8]u8, @ptrCast(&registers[0])) },
258 .{ .key = "CP 4020", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[1]) },258 .{ .key = "CP 4020", .value_type = REG.QWORD, .value_buf = @as(*[8]u8, @ptrCast(&registers[1])) },
259 .{ .key = "CP 4021", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[2]) },259 .{ .key = "CP 4021", .value_type = REG.QWORD, .value_buf = @as(*[8]u8, @ptrCast(&registers[2])) },
260 .{ .key = "CP 4028", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[3]) },260 .{ .key = "CP 4028", .value_type = REG.QWORD, .value_buf = @as(*[8]u8, @ptrCast(&registers[3])) },
261 .{ .key = "CP 4029", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[4]) },261 .{ .key = "CP 4029", .value_type = REG.QWORD, .value_buf = @as(*[8]u8, @ptrCast(&registers[4])) },
262 .{ .key = "CP 402C", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[5]) },262 .{ .key = "CP 402C", .value_type = REG.QWORD, .value_buf = @as(*[8]u8, @ptrCast(&registers[5])) },
263 .{ .key = "CP 402D", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[6]) },263 .{ .key = "CP 402D", .value_type = REG.QWORD, .value_buf = @as(*[8]u8, @ptrCast(&registers[6])) },
264 .{ .key = "CP 4030", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[7]) },264 .{ .key = "CP 4030", .value_type = REG.QWORD, .value_buf = @as(*[8]u8, @ptrCast(&registers[7])) },
265 .{ .key = "CP 4031", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[8]) },265 .{ .key = "CP 4031", .value_type = REG.QWORD, .value_buf = @as(*[8]u8, @ptrCast(&registers[8])) },
266 .{ .key = "CP 4038", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[9]) },266 .{ .key = "CP 4038", .value_type = REG.QWORD, .value_buf = @as(*[8]u8, @ptrCast(&registers[9])) },
267 .{ .key = "CP 4039", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[10]) },267 .{ .key = "CP 4039", .value_type = REG.QWORD, .value_buf = @as(*[8]u8, @ptrCast(&registers[10])) },
268 .{ .key = "CP 403A", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[11]) },268 .{ .key = "CP 403A", .value_type = REG.QWORD, .value_buf = @as(*[8]u8, @ptrCast(&registers[11])) },
269 }) catch break :blk null;269 }) catch break :blk null;
270270
271 cores[i] = @import("arm.zig").aarch64.detectNativeCpuAndFeatures(current_arch, registers) orelse271 cores[i] = @import("arm.zig").aarch64.detectNativeCpuAndFeatures(current_arch, registers) orelse
lib/std/zig/tokenizer.zig+1-1
...@@ -1290,7 +1290,7 @@ pub const Tokenizer = struct {...@@ -1290,7 +1290,7 @@ pub const Tokenizer = struct {
1290 // check utf8-encoded character.1290 // check utf8-encoded character.
1291 const length = std.unicode.utf8ByteSequenceLength(c0) catch return 1;1291 const length = std.unicode.utf8ByteSequenceLength(c0) catch return 1;
1292 if (self.index + length > self.buffer.len) {1292 if (self.index + length > self.buffer.len) {
1293 return @intCast(u3, self.buffer.len - self.index);1293 return @as(u3, @intCast(self.buffer.len - self.index));
1294 }1294 }
1295 const bytes = self.buffer[self.index .. self.index + length];1295 const bytes = self.buffer[self.index .. self.index + length];
1296 switch (length) {1296 switch (length) {
lib/test_runner.zig+3-3
...@@ -70,12 +70,12 @@ fn mainServer() !void {...@@ -70,12 +70,12 @@ fn mainServer() !void {
70 defer std.testing.allocator.free(expected_panic_msgs);70 defer std.testing.allocator.free(expected_panic_msgs);
7171
72 for (test_fns, names, async_frame_sizes, expected_panic_msgs) |test_fn, *name, *async_frame_size, *expected_panic_msg| {72 for (test_fns, names, async_frame_sizes, expected_panic_msgs) |test_fn, *name, *async_frame_size, *expected_panic_msg| {
73 name.* = @intCast(u32, string_bytes.items.len);73 name.* = @as(u32, @intCast(string_bytes.items.len));
74 try string_bytes.ensureUnusedCapacity(std.testing.allocator, test_fn.name.len + 1);74 try string_bytes.ensureUnusedCapacity(std.testing.allocator, test_fn.name.len + 1);
75 string_bytes.appendSliceAssumeCapacity(test_fn.name);75 string_bytes.appendSliceAssumeCapacity(test_fn.name);
76 string_bytes.appendAssumeCapacity(0);76 string_bytes.appendAssumeCapacity(0);
7777
78 async_frame_size.* = @intCast(u32, test_fn.async_frame_size orelse 0);78 async_frame_size.* = @as(u32, @intCast(test_fn.async_frame_size orelse 0));
79 expected_panic_msg.* = 0;79 expected_panic_msg.* = 0;
80 }80 }
8181
...@@ -163,7 +163,7 @@ fn mainTerminal() void {...@@ -163,7 +163,7 @@ fn mainTerminal() void {
163 std.heap.page_allocator.free(async_frame_buffer);163 std.heap.page_allocator.free(async_frame_buffer);
164 async_frame_buffer = std.heap.page_allocator.alignedAlloc(u8, std.Target.stack_align, size) catch @panic("out of memory");164 async_frame_buffer = std.heap.page_allocator.alignedAlloc(u8, std.Target.stack_align, size) catch @panic("out of memory");
165 }165 }
166 const casted_fn = @ptrCast(fn () callconv(.Async) anyerror!void, test_fn.func);166 const casted_fn = @as(fn () callconv(.Async) anyerror!void, @ptrCast(test_fn.func));
167 break :blk await @asyncCall(async_frame_buffer, {}, casted_fn, .{});167 break :blk await @asyncCall(async_frame_buffer, {}, casted_fn, .{});
168 },168 },
169 .blocking => {169 .blocking => {
src/Air.zig+13-13
...@@ -1106,7 +1106,7 @@ pub const VectorCmp = struct {...@@ -1106,7 +1106,7 @@ pub const VectorCmp = struct {
1106 op: u32,1106 op: u32,
11071107
1108 pub fn compareOperator(self: VectorCmp) std.math.CompareOperator {1108 pub fn compareOperator(self: VectorCmp) std.math.CompareOperator {
1109 return @enumFromInt(std.math.CompareOperator, @truncate(u3, self.op));1109 return @as(std.math.CompareOperator, @enumFromInt(@as(u3, @truncate(self.op))));
1110 }1110 }
11111111
1112 pub fn encodeOp(compare_operator: std.math.CompareOperator) u32 {1112 pub fn encodeOp(compare_operator: std.math.CompareOperator) u32 {
...@@ -1151,11 +1151,11 @@ pub const Cmpxchg = struct {...@@ -1151,11 +1151,11 @@ pub const Cmpxchg = struct {
1151 flags: u32,1151 flags: u32,
11521152
1153 pub fn successOrder(self: Cmpxchg) std.builtin.AtomicOrder {1153 pub fn successOrder(self: Cmpxchg) std.builtin.AtomicOrder {
1154 return @enumFromInt(std.builtin.AtomicOrder, @truncate(u3, self.flags));1154 return @as(std.builtin.AtomicOrder, @enumFromInt(@as(u3, @truncate(self.flags))));
1155 }1155 }
11561156
1157 pub fn failureOrder(self: Cmpxchg) std.builtin.AtomicOrder {1157 pub fn failureOrder(self: Cmpxchg) std.builtin.AtomicOrder {
1158 return @enumFromInt(std.builtin.AtomicOrder, @truncate(u3, self.flags >> 3));1158 return @as(std.builtin.AtomicOrder, @enumFromInt(@as(u3, @truncate(self.flags >> 3))));
1159 }1159 }
1160};1160};
11611161
...@@ -1166,11 +1166,11 @@ pub const AtomicRmw = struct {...@@ -1166,11 +1166,11 @@ pub const AtomicRmw = struct {
1166 flags: u32,1166 flags: u32,
11671167
1168 pub fn ordering(self: AtomicRmw) std.builtin.AtomicOrder {1168 pub fn ordering(self: AtomicRmw) std.builtin.AtomicOrder {
1169 return @enumFromInt(std.builtin.AtomicOrder, @truncate(u3, self.flags));1169 return @as(std.builtin.AtomicOrder, @enumFromInt(@as(u3, @truncate(self.flags))));
1170 }1170 }
11711171
1172 pub fn op(self: AtomicRmw) std.builtin.AtomicRmwOp {1172 pub fn op(self: AtomicRmw) std.builtin.AtomicRmwOp {
1173 return @enumFromInt(std.builtin.AtomicRmwOp, @truncate(u4, self.flags >> 3));1173 return @as(std.builtin.AtomicRmwOp, @enumFromInt(@as(u4, @truncate(self.flags >> 3))));
1174 }1174 }
1175};1175};
11761176
...@@ -1451,7 +1451,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)...@@ -1451,7 +1451,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
1451pub fn getRefType(air: Air, ref: Air.Inst.Ref) Type {1451pub fn getRefType(air: Air, ref: Air.Inst.Ref) Type {
1452 const ref_int = @intFromEnum(ref);1452 const ref_int = @intFromEnum(ref);
1453 if (ref_int < ref_start_index) {1453 if (ref_int < ref_start_index) {
1454 const ip_index = @enumFromInt(InternPool.Index, ref_int);1454 const ip_index = @as(InternPool.Index, @enumFromInt(ref_int));
1455 return ip_index.toType();1455 return ip_index.toType();
1456 }1456 }
1457 const inst_index = ref_int - ref_start_index;1457 const inst_index = ref_int - ref_start_index;
...@@ -1472,9 +1472,9 @@ pub fn extraData(air: Air, comptime T: type, index: usize) struct { data: T, end...@@ -1472,9 +1472,9 @@ pub fn extraData(air: Air, comptime T: type, index: usize) struct { data: T, end
1472 inline for (fields) |field| {1472 inline for (fields) |field| {
1473 @field(result, field.name) = switch (field.type) {1473 @field(result, field.name) = switch (field.type) {
1474 u32 => air.extra[i],1474 u32 => air.extra[i],
1475 Inst.Ref => @enumFromInt(Inst.Ref, air.extra[i]),1475 Inst.Ref => @as(Inst.Ref, @enumFromInt(air.extra[i])),
1476 i32 => @bitCast(i32, air.extra[i]),1476 i32 => @as(i32, @bitCast(air.extra[i])),
1477 InternPool.Index => @enumFromInt(InternPool.Index, air.extra[i]),1477 InternPool.Index => @as(InternPool.Index, @enumFromInt(air.extra[i])),
1478 else => @compileError("bad field type: " ++ @typeName(field.type)),1478 else => @compileError("bad field type: " ++ @typeName(field.type)),
1479 };1479 };
1480 i += 1;1480 i += 1;
...@@ -1494,7 +1494,7 @@ pub fn deinit(air: *Air, gpa: std.mem.Allocator) void {...@@ -1494,7 +1494,7 @@ pub fn deinit(air: *Air, gpa: std.mem.Allocator) void {
1494pub const ref_start_index: u32 = InternPool.static_len;1494pub const ref_start_index: u32 = InternPool.static_len;
14951495
1496pub fn indexToRef(inst: Inst.Index) Inst.Ref {1496pub fn indexToRef(inst: Inst.Index) Inst.Ref {
1497 return @enumFromInt(Inst.Ref, ref_start_index + inst);1497 return @as(Inst.Ref, @enumFromInt(ref_start_index + inst));
1498}1498}
14991499
1500pub fn refToIndex(inst: Inst.Ref) ?Inst.Index {1500pub fn refToIndex(inst: Inst.Ref) ?Inst.Index {
...@@ -1516,10 +1516,10 @@ pub fn refToIndexAllowNone(inst: Inst.Ref) ?Inst.Index {...@@ -1516,10 +1516,10 @@ pub fn refToIndexAllowNone(inst: Inst.Ref) ?Inst.Index {
1516pub fn value(air: Air, inst: Inst.Ref, mod: *Module) !?Value {1516pub fn value(air: Air, inst: Inst.Ref, mod: *Module) !?Value {
1517 const ref_int = @intFromEnum(inst);1517 const ref_int = @intFromEnum(inst);
1518 if (ref_int < ref_start_index) {1518 if (ref_int < ref_start_index) {
1519 const ip_index = @enumFromInt(InternPool.Index, ref_int);1519 const ip_index = @as(InternPool.Index, @enumFromInt(ref_int));
1520 return ip_index.toValue();1520 return ip_index.toValue();
1521 }1521 }
1522 const inst_index = @intCast(Air.Inst.Index, ref_int - ref_start_index);1522 const inst_index = @as(Air.Inst.Index, @intCast(ref_int - ref_start_index));
1523 const air_datas = air.instructions.items(.data);1523 const air_datas = air.instructions.items(.data);
1524 switch (air.instructions.items(.tag)[inst_index]) {1524 switch (air.instructions.items(.tag)[inst_index]) {
1525 .interned => return air_datas[inst_index].interned.toValue(),1525 .interned => return air_datas[inst_index].interned.toValue(),
...@@ -1747,7 +1747,7 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool {...@@ -1747,7 +1747,7 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool {
1747 .work_group_id,1747 .work_group_id,
1748 => false,1748 => false,
17491749
1750 .assembly => @truncate(u1, air.extraData(Air.Asm, data.ty_pl.payload).data.flags >> 31) != 0,1750 .assembly => @as(u1, @truncate(air.extraData(Air.Asm, data.ty_pl.payload).data.flags >> 31)) != 0,
1751 .load => air.typeOf(data.ty_op.operand, ip).isVolatilePtrIp(ip),1751 .load => air.typeOf(data.ty_op.operand, ip).isVolatilePtrIp(ip),
1752 .slice_elem_val, .ptr_elem_val => air.typeOf(data.bin_op.lhs, ip).isVolatilePtrIp(ip),1752 .slice_elem_val, .ptr_elem_val => air.typeOf(data.bin_op.lhs, ip).isVolatilePtrIp(ip),
1753 .atomic_load => air.typeOf(data.atomic_load.ptr, ip).isVolatilePtrIp(ip),1753 .atomic_load => air.typeOf(data.atomic_load.ptr, ip).isVolatilePtrIp(ip),
src/AstGen.zig+173-173
...@@ -70,7 +70,7 @@ fn addExtra(astgen: *AstGen, extra: anytype) Allocator.Error!u32 {...@@ -70,7 +70,7 @@ fn addExtra(astgen: *AstGen, extra: anytype) Allocator.Error!u32 {
7070
71fn addExtraAssumeCapacity(astgen: *AstGen, extra: anytype) u32 {71fn addExtraAssumeCapacity(astgen: *AstGen, extra: anytype) u32 {
72 const fields = std.meta.fields(@TypeOf(extra));72 const fields = std.meta.fields(@TypeOf(extra));
73 const result = @intCast(u32, astgen.extra.items.len);73 const result = @as(u32, @intCast(astgen.extra.items.len));
74 astgen.extra.items.len += fields.len;74 astgen.extra.items.len += fields.len;
75 setExtra(astgen, result, extra);75 setExtra(astgen, result, extra);
76 return result;76 return result;
...@@ -83,11 +83,11 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {...@@ -83,11 +83,11 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {
83 astgen.extra.items[i] = switch (field.type) {83 astgen.extra.items[i] = switch (field.type) {
84 u32 => @field(extra, field.name),84 u32 => @field(extra, field.name),
85 Zir.Inst.Ref => @intFromEnum(@field(extra, field.name)),85 Zir.Inst.Ref => @intFromEnum(@field(extra, field.name)),
86 i32 => @bitCast(u32, @field(extra, field.name)),86 i32 => @as(u32, @bitCast(@field(extra, field.name))),
87 Zir.Inst.Call.Flags => @bitCast(u32, @field(extra, field.name)),87 Zir.Inst.Call.Flags => @as(u32, @bitCast(@field(extra, field.name))),
88 Zir.Inst.BuiltinCall.Flags => @bitCast(u32, @field(extra, field.name)),88 Zir.Inst.BuiltinCall.Flags => @as(u32, @bitCast(@field(extra, field.name))),
89 Zir.Inst.SwitchBlock.Bits => @bitCast(u32, @field(extra, field.name)),89 Zir.Inst.SwitchBlock.Bits => @as(u32, @bitCast(@field(extra, field.name))),
90 Zir.Inst.FuncFancy.Bits => @bitCast(u32, @field(extra, field.name)),90 Zir.Inst.FuncFancy.Bits => @as(u32, @bitCast(@field(extra, field.name))),
91 else => @compileError("bad field type"),91 else => @compileError("bad field type"),
92 };92 };
93 i += 1;93 i += 1;
...@@ -95,18 +95,18 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {...@@ -95,18 +95,18 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {
95}95}
9696
97fn reserveExtra(astgen: *AstGen, size: usize) Allocator.Error!u32 {97fn reserveExtra(astgen: *AstGen, size: usize) Allocator.Error!u32 {
98 const result = @intCast(u32, astgen.extra.items.len);98 const result = @as(u32, @intCast(astgen.extra.items.len));
99 try astgen.extra.resize(astgen.gpa, result + size);99 try astgen.extra.resize(astgen.gpa, result + size);
100 return result;100 return result;
101}101}
102102
103fn appendRefs(astgen: *AstGen, refs: []const Zir.Inst.Ref) !void {103fn appendRefs(astgen: *AstGen, refs: []const Zir.Inst.Ref) !void {
104 const coerced = @ptrCast([]const u32, refs);104 const coerced = @as([]const u32, @ptrCast(refs));
105 return astgen.extra.appendSlice(astgen.gpa, coerced);105 return astgen.extra.appendSlice(astgen.gpa, coerced);
106}106}
107107
108fn appendRefsAssumeCapacity(astgen: *AstGen, refs: []const Zir.Inst.Ref) void {108fn appendRefsAssumeCapacity(astgen: *AstGen, refs: []const Zir.Inst.Ref) void {
109 const coerced = @ptrCast([]const u32, refs);109 const coerced = @as([]const u32, @ptrCast(refs));
110 astgen.extra.appendSliceAssumeCapacity(coerced);110 astgen.extra.appendSliceAssumeCapacity(coerced);
111}111}
112112
...@@ -176,7 +176,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {...@@ -176,7 +176,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
176 @typeInfo(Zir.Inst.CompileErrors.Item).Struct.fields.len);176 @typeInfo(Zir.Inst.CompileErrors.Item).Struct.fields.len);
177177
178 astgen.extra.items[err_index] = astgen.addExtraAssumeCapacity(Zir.Inst.CompileErrors{178 astgen.extra.items[err_index] = astgen.addExtraAssumeCapacity(Zir.Inst.CompileErrors{
179 .items_len = @intCast(u32, astgen.compile_errors.items.len),179 .items_len = @as(u32, @intCast(astgen.compile_errors.items.len)),
180 });180 });
181181
182 for (astgen.compile_errors.items) |item| {182 for (astgen.compile_errors.items) |item| {
...@@ -192,7 +192,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {...@@ -192,7 +192,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
192 astgen.imports.count() * @typeInfo(Zir.Inst.Imports.Item).Struct.fields.len);192 astgen.imports.count() * @typeInfo(Zir.Inst.Imports.Item).Struct.fields.len);
193193
194 astgen.extra.items[imports_index] = astgen.addExtraAssumeCapacity(Zir.Inst.Imports{194 astgen.extra.items[imports_index] = astgen.addExtraAssumeCapacity(Zir.Inst.Imports{
195 .imports_len = @intCast(u32, astgen.imports.count()),195 .imports_len = @as(u32, @intCast(astgen.imports.count())),
196 });196 });
197197
198 var it = astgen.imports.iterator();198 var it = astgen.imports.iterator();
...@@ -1334,7 +1334,7 @@ fn fnProtoExpr(...@@ -1334,7 +1334,7 @@ fn fnProtoExpr(
1334 var param_gz = block_scope.makeSubBlock(scope);1334 var param_gz = block_scope.makeSubBlock(scope);
1335 defer param_gz.unstack();1335 defer param_gz.unstack();
1336 const param_type = try expr(&param_gz, scope, coerced_type_ri, param_type_node);1336 const param_type = try expr(&param_gz, scope, coerced_type_ri, param_type_node);
1337 const param_inst_expected = @intCast(u32, astgen.instructions.len + 1);1337 const param_inst_expected = @as(u32, @intCast(astgen.instructions.len + 1));
1338 _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node);1338 _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node);
1339 const main_tokens = tree.nodes.items(.main_token);1339 const main_tokens = tree.nodes.items(.main_token);
1340 const name_token = param.name_token orelse main_tokens[param_type_node];1340 const name_token = param.name_token orelse main_tokens[param_type_node];
...@@ -1468,7 +1468,7 @@ fn arrayInitExpr(...@@ -1468,7 +1468,7 @@ fn arrayInitExpr(
1468 const array_type_inst = try typeExpr(gz, scope, array_init.ast.type_expr);1468 const array_type_inst = try typeExpr(gz, scope, array_init.ast.type_expr);
1469 _ = try gz.addPlNode(.validate_array_init_ty, node, Zir.Inst.ArrayInit{1469 _ = try gz.addPlNode(.validate_array_init_ty, node, Zir.Inst.ArrayInit{
1470 .ty = array_type_inst,1470 .ty = array_type_inst,
1471 .init_count = @intCast(u32, array_init.ast.elements.len),1471 .init_count = @as(u32, @intCast(array_init.ast.elements.len)),
1472 });1472 });
1473 break :inst .{1473 break :inst .{
1474 .array = array_type_inst,1474 .array = array_type_inst,
...@@ -1533,7 +1533,7 @@ fn arrayInitExprRlNone(...@@ -1533,7 +1533,7 @@ fn arrayInitExprRlNone(
1533 const astgen = gz.astgen;1533 const astgen = gz.astgen;
15341534
1535 const payload_index = try addExtra(astgen, Zir.Inst.MultiOp{1535 const payload_index = try addExtra(astgen, Zir.Inst.MultiOp{
1536 .operands_len = @intCast(u32, elements.len),1536 .operands_len = @as(u32, @intCast(elements.len)),
1537 });1537 });
1538 var extra_index = try reserveExtra(astgen, elements.len);1538 var extra_index = try reserveExtra(astgen, elements.len);
15391539
...@@ -1558,7 +1558,7 @@ fn arrayInitExprInner(...@@ -1558,7 +1558,7 @@ fn arrayInitExprInner(
15581558
1559 const len = elements.len + @intFromBool(array_ty_inst != .none);1559 const len = elements.len + @intFromBool(array_ty_inst != .none);
1560 const payload_index = try addExtra(astgen, Zir.Inst.MultiOp{1560 const payload_index = try addExtra(astgen, Zir.Inst.MultiOp{
1561 .operands_len = @intCast(u32, len),1561 .operands_len = @as(u32, @intCast(len)),
1562 });1562 });
1563 var extra_index = try reserveExtra(astgen, len);1563 var extra_index = try reserveExtra(astgen, len);
1564 if (array_ty_inst != .none) {1564 if (array_ty_inst != .none) {
...@@ -1574,7 +1574,7 @@ fn arrayInitExprInner(...@@ -1574,7 +1574,7 @@ fn arrayInitExprInner(
1574 .tag = .elem_type_index,1574 .tag = .elem_type_index,
1575 .data = .{ .bin = .{1575 .data = .{ .bin = .{
1576 .lhs = array_ty_inst,1576 .lhs = array_ty_inst,
1577 .rhs = @enumFromInt(Zir.Inst.Ref, i),1577 .rhs = @as(Zir.Inst.Ref, @enumFromInt(i)),
1578 } },1578 } },
1579 });1579 });
1580 break :ri ResultInfo{ .rl = .{ .coerced_ty = ty_expr } };1580 break :ri ResultInfo{ .rl = .{ .coerced_ty = ty_expr } };
...@@ -1619,14 +1619,14 @@ fn arrayInitExprRlPtrInner(...@@ -1619,14 +1619,14 @@ fn arrayInitExprRlPtrInner(
1619 const astgen = gz.astgen;1619 const astgen = gz.astgen;
16201620
1621 const payload_index = try addExtra(astgen, Zir.Inst.Block{1621 const payload_index = try addExtra(astgen, Zir.Inst.Block{
1622 .body_len = @intCast(u32, elements.len),1622 .body_len = @as(u32, @intCast(elements.len)),
1623 });1623 });
1624 var extra_index = try reserveExtra(astgen, elements.len);1624 var extra_index = try reserveExtra(astgen, elements.len);
16251625
1626 for (elements, 0..) |elem_init, i| {1626 for (elements, 0..) |elem_init, i| {
1627 const elem_ptr = try gz.addPlNode(.elem_ptr_imm, elem_init, Zir.Inst.ElemPtrImm{1627 const elem_ptr = try gz.addPlNode(.elem_ptr_imm, elem_init, Zir.Inst.ElemPtrImm{
1628 .ptr = result_ptr,1628 .ptr = result_ptr,
1629 .index = @intCast(u32, i),1629 .index = @as(u32, @intCast(i)),
1630 });1630 });
1631 astgen.extra.items[extra_index] = refToIndex(elem_ptr).?;1631 astgen.extra.items[extra_index] = refToIndex(elem_ptr).?;
1632 extra_index += 1;1632 extra_index += 1;
...@@ -1776,7 +1776,7 @@ fn structInitExprRlNone(...@@ -1776,7 +1776,7 @@ fn structInitExprRlNone(
1776 const tree = astgen.tree;1776 const tree = astgen.tree;
17771777
1778 const payload_index = try addExtra(astgen, Zir.Inst.StructInitAnon{1778 const payload_index = try addExtra(astgen, Zir.Inst.StructInitAnon{
1779 .fields_len = @intCast(u32, struct_init.ast.fields.len),1779 .fields_len = @as(u32, @intCast(struct_init.ast.fields.len)),
1780 });1780 });
1781 const field_size = @typeInfo(Zir.Inst.StructInitAnon.Item).Struct.fields.len;1781 const field_size = @typeInfo(Zir.Inst.StructInitAnon.Item).Struct.fields.len;
1782 var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size);1782 var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size);
...@@ -1834,7 +1834,7 @@ fn structInitExprRlPtrInner(...@@ -1834,7 +1834,7 @@ fn structInitExprRlPtrInner(
1834 const tree = astgen.tree;1834 const tree = astgen.tree;
18351835
1836 const payload_index = try addExtra(astgen, Zir.Inst.Block{1836 const payload_index = try addExtra(astgen, Zir.Inst.Block{
1837 .body_len = @intCast(u32, struct_init.ast.fields.len),1837 .body_len = @as(u32, @intCast(struct_init.ast.fields.len)),
1838 });1838 });
1839 var extra_index = try reserveExtra(astgen, struct_init.ast.fields.len);1839 var extra_index = try reserveExtra(astgen, struct_init.ast.fields.len);
18401840
...@@ -1866,7 +1866,7 @@ fn structInitExprRlTy(...@@ -1866,7 +1866,7 @@ fn structInitExprRlTy(
1866 const tree = astgen.tree;1866 const tree = astgen.tree;
18671867
1868 const payload_index = try addExtra(astgen, Zir.Inst.StructInit{1868 const payload_index = try addExtra(astgen, Zir.Inst.StructInit{
1869 .fields_len = @intCast(u32, struct_init.ast.fields.len),1869 .fields_len = @as(u32, @intCast(struct_init.ast.fields.len)),
1870 });1870 });
1871 const field_size = @typeInfo(Zir.Inst.StructInit.Item).Struct.fields.len;1871 const field_size = @typeInfo(Zir.Inst.StructInit.Item).Struct.fields.len;
1872 var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size);1872 var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size);
...@@ -2105,7 +2105,7 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn...@@ -2105,7 +2105,7 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn
2105 }2105 }
21062106
2107 const operand = try reachableExpr(parent_gz, parent_scope, block_gz.break_result_info, rhs, node);2107 const operand = try reachableExpr(parent_gz, parent_scope, block_gz.break_result_info, rhs, node);
2108 const search_index = @intCast(Zir.Inst.Index, astgen.instructions.len);2108 const search_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
21092109
2110 try genDefers(parent_gz, scope, parent_scope, .normal_only);2110 try genDefers(parent_gz, scope, parent_scope, .normal_only);
21112111
...@@ -2511,17 +2511,17 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As...@@ -2511,17 +2511,17 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
2511 .call, .field_call => {2511 .call, .field_call => {
2512 const extra_index = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index;2512 const extra_index = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index;
2513 const slot = &gz.astgen.extra.items[extra_index];2513 const slot = &gz.astgen.extra.items[extra_index];
2514 var flags = @bitCast(Zir.Inst.Call.Flags, slot.*);2514 var flags = @as(Zir.Inst.Call.Flags, @bitCast(slot.*));
2515 flags.ensure_result_used = true;2515 flags.ensure_result_used = true;
2516 slot.* = @bitCast(u32, flags);2516 slot.* = @as(u32, @bitCast(flags));
2517 break :b true;2517 break :b true;
2518 },2518 },
2519 .builtin_call => {2519 .builtin_call => {
2520 const extra_index = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index;2520 const extra_index = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index;
2521 const slot = &gz.astgen.extra.items[extra_index];2521 const slot = &gz.astgen.extra.items[extra_index];
2522 var flags = @bitCast(Zir.Inst.BuiltinCall.Flags, slot.*);2522 var flags = @as(Zir.Inst.BuiltinCall.Flags, @bitCast(slot.*));
2523 flags.ensure_result_used = true;2523 flags.ensure_result_used = true;
2524 slot.* = @bitCast(u32, flags);2524 slot.* = @as(u32, @bitCast(flags));
2525 break :b true;2525 break :b true;
2526 },2526 },
25272527
...@@ -2897,7 +2897,7 @@ fn genDefers(...@@ -2897,7 +2897,7 @@ fn genDefers(
2897 .index = defer_scope.index,2897 .index = defer_scope.index,
2898 .len = defer_scope.len,2898 .len = defer_scope.len,
2899 });2899 });
2900 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);2900 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
2901 gz.astgen.instructions.appendAssumeCapacity(.{2901 gz.astgen.instructions.appendAssumeCapacity(.{
2902 .tag = .defer_err_code,2902 .tag = .defer_err_code,
2903 .data = .{ .defer_err_code = .{2903 .data = .{ .defer_err_code = .{
...@@ -2976,7 +2976,7 @@ fn deferStmt(...@@ -2976,7 +2976,7 @@ fn deferStmt(
2976 const sub_scope = if (!have_err_code) &defer_gen.base else blk: {2976 const sub_scope = if (!have_err_code) &defer_gen.base else blk: {
2977 try gz.addDbgBlockBegin();2977 try gz.addDbgBlockBegin();
2978 const ident_name = try gz.astgen.identAsString(payload_token);2978 const ident_name = try gz.astgen.identAsString(payload_token);
2979 remapped_err_code = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);2979 remapped_err_code = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
2980 try gz.astgen.instructions.append(gz.astgen.gpa, .{2980 try gz.astgen.instructions.append(gz.astgen.gpa, .{
2981 .tag = .extended,2981 .tag = .extended,
2982 .data = .{ .extended = .{2982 .data = .{ .extended = .{
...@@ -3016,7 +3016,7 @@ fn deferStmt(...@@ -3016,7 +3016,7 @@ fn deferStmt(
3016 break :blk gz.astgen.countBodyLenAfterFixups(body) + refs;3016 break :blk gz.astgen.countBodyLenAfterFixups(body) + refs;
3017 };3017 };
30183018
3019 const index = @intCast(u32, gz.astgen.extra.items.len);3019 const index = @as(u32, @intCast(gz.astgen.extra.items.len));
3020 try gz.astgen.extra.ensureUnusedCapacity(gz.astgen.gpa, body_len);3020 try gz.astgen.extra.ensureUnusedCapacity(gz.astgen.gpa, body_len);
3021 if (have_err_code) {3021 if (have_err_code) {
3022 if (gz.astgen.ref_table.fetchRemove(remapped_err_code)) |kv| {3022 if (gz.astgen.ref_table.fetchRemove(remapped_err_code)) |kv| {
...@@ -3554,7 +3554,7 @@ fn ptrType(...@@ -3554,7 +3554,7 @@ fn ptrType(
3554 gz.astgen.extra.appendAssumeCapacity(@intFromEnum(bit_end_ref));3554 gz.astgen.extra.appendAssumeCapacity(@intFromEnum(bit_end_ref));
3555 }3555 }
35563556
3557 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);3557 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
3558 const result = indexToRef(new_index);3558 const result = indexToRef(new_index);
3559 gz.astgen.instructions.appendAssumeCapacity(.{ .tag = .ptr_type, .data = .{3559 gz.astgen.instructions.appendAssumeCapacity(.{ .tag = .ptr_type, .data = .{
3560 .ptr_type = .{3560 .ptr_type = .{
...@@ -3645,7 +3645,7 @@ const WipMembers = struct {...@@ -3645,7 +3645,7 @@ const WipMembers = struct {
3645 const max_decl_size = 11;3645 const max_decl_size = 11;
36463646
3647 fn init(gpa: Allocator, payload: *ArrayListUnmanaged(u32), decl_count: u32, field_count: u32, comptime bits_per_field: u32, comptime max_field_size: u32) Allocator.Error!Self {3647 fn init(gpa: Allocator, payload: *ArrayListUnmanaged(u32), decl_count: u32, field_count: u32, comptime bits_per_field: u32, comptime max_field_size: u32) Allocator.Error!Self {
3648 const payload_top = @intCast(u32, payload.items.len);3648 const payload_top = @as(u32, @intCast(payload.items.len));
3649 const decls_start = payload_top + (decl_count + decls_per_u32 - 1) / decls_per_u32;3649 const decls_start = payload_top + (decl_count + decls_per_u32 - 1) / decls_per_u32;
3650 const field_bits_start = decls_start + decl_count * max_decl_size;3650 const field_bits_start = decls_start + decl_count * max_decl_size;
3651 const fields_start = field_bits_start + if (bits_per_field > 0) blk: {3651 const fields_start = field_bits_start + if (bits_per_field > 0) blk: {
...@@ -3700,7 +3700,7 @@ const WipMembers = struct {...@@ -3700,7 +3700,7 @@ const WipMembers = struct {
3700 fn appendToDeclSlice(self: *Self, data: []const u32) void {3700 fn appendToDeclSlice(self: *Self, data: []const u32) void {
3701 assert(self.decls_end + data.len <= self.field_bits_start);3701 assert(self.decls_end + data.len <= self.field_bits_start);
3702 @memcpy(self.payload.items[self.decls_end..][0..data.len], data);3702 @memcpy(self.payload.items[self.decls_end..][0..data.len], data);
3703 self.decls_end += @intCast(u32, data.len);3703 self.decls_end += @as(u32, @intCast(data.len));
3704 }3704 }
37053705
3706 fn appendToField(self: *Self, data: u32) void {3706 fn appendToField(self: *Self, data: u32) void {
...@@ -3713,14 +3713,14 @@ const WipMembers = struct {...@@ -3713,14 +3713,14 @@ const WipMembers = struct {
3713 const empty_decl_slots = decls_per_u32 - (self.decl_index % decls_per_u32);3713 const empty_decl_slots = decls_per_u32 - (self.decl_index % decls_per_u32);
3714 if (self.decl_index > 0 and empty_decl_slots < decls_per_u32) {3714 if (self.decl_index > 0 and empty_decl_slots < decls_per_u32) {
3715 const index = self.payload_top + self.decl_index / decls_per_u32;3715 const index = self.payload_top + self.decl_index / decls_per_u32;
3716 self.payload.items[index] >>= @intCast(u5, empty_decl_slots * bits_per_decl);3716 self.payload.items[index] >>= @as(u5, @intCast(empty_decl_slots * bits_per_decl));
3717 }3717 }
3718 if (bits_per_field > 0) {3718 if (bits_per_field > 0) {
3719 const fields_per_u32 = 32 / bits_per_field;3719 const fields_per_u32 = 32 / bits_per_field;
3720 const empty_field_slots = fields_per_u32 - (self.field_index % fields_per_u32);3720 const empty_field_slots = fields_per_u32 - (self.field_index % fields_per_u32);
3721 if (self.field_index > 0 and empty_field_slots < fields_per_u32) {3721 if (self.field_index > 0 and empty_field_slots < fields_per_u32) {
3722 const index = self.field_bits_start + self.field_index / fields_per_u32;3722 const index = self.field_bits_start + self.field_index / fields_per_u32;
3723 self.payload.items[index] >>= @intCast(u5, empty_field_slots * bits_per_field);3723 self.payload.items[index] >>= @as(u5, @intCast(empty_field_slots * bits_per_field));
3724 }3724 }
3725 }3725 }
3726 }3726 }
...@@ -3882,7 +3882,7 @@ fn fnDecl(...@@ -3882,7 +3882,7 @@ fn fnDecl(
3882 var param_gz = decl_gz.makeSubBlock(scope);3882 var param_gz = decl_gz.makeSubBlock(scope);
3883 defer param_gz.unstack();3883 defer param_gz.unstack();
3884 const param_type = try expr(&param_gz, params_scope, coerced_type_ri, param_type_node);3884 const param_type = try expr(&param_gz, params_scope, coerced_type_ri, param_type_node);
3885 const param_inst_expected = @intCast(u32, astgen.instructions.len + 1);3885 const param_inst_expected = @as(u32, @intCast(astgen.instructions.len + 1));
3886 _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node);3886 _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node);
38873887
3888 const main_tokens = tree.nodes.items(.main_token);3888 const main_tokens = tree.nodes.items(.main_token);
...@@ -4097,7 +4097,7 @@ fn fnDecl(...@@ -4097,7 +4097,7 @@ fn fnDecl(
40974097
4098 {4098 {
4099 const contents_hash = std.zig.hashSrc(tree.getNodeSource(decl_node));4099 const contents_hash = std.zig.hashSrc(tree.getNodeSource(decl_node));
4100 const casted = @bitCast([4]u32, contents_hash);4100 const casted = @as([4]u32, @bitCast(contents_hash));
4101 wip_members.appendToDeclSlice(&casted);4101 wip_members.appendToDeclSlice(&casted);
4102 }4102 }
4103 {4103 {
...@@ -4248,7 +4248,7 @@ fn globalVarDecl(...@@ -4248,7 +4248,7 @@ fn globalVarDecl(
42484248
4249 {4249 {
4250 const contents_hash = std.zig.hashSrc(tree.getNodeSource(node));4250 const contents_hash = std.zig.hashSrc(tree.getNodeSource(node));
4251 const casted = @bitCast([4]u32, contents_hash);4251 const casted = @as([4]u32, @bitCast(contents_hash));
4252 wip_members.appendToDeclSlice(&casted);4252 wip_members.appendToDeclSlice(&casted);
4253 }4253 }
4254 {4254 {
...@@ -4303,7 +4303,7 @@ fn comptimeDecl(...@@ -4303,7 +4303,7 @@ fn comptimeDecl(
43034303
4304 {4304 {
4305 const contents_hash = std.zig.hashSrc(tree.getNodeSource(node));4305 const contents_hash = std.zig.hashSrc(tree.getNodeSource(node));
4306 const casted = @bitCast([4]u32, contents_hash);4306 const casted = @as([4]u32, @bitCast(contents_hash));
4307 wip_members.appendToDeclSlice(&casted);4307 wip_members.appendToDeclSlice(&casted);
4308 }4308 }
4309 {4309 {
...@@ -4355,7 +4355,7 @@ fn usingnamespaceDecl(...@@ -4355,7 +4355,7 @@ fn usingnamespaceDecl(
43554355
4356 {4356 {
4357 const contents_hash = std.zig.hashSrc(tree.getNodeSource(node));4357 const contents_hash = std.zig.hashSrc(tree.getNodeSource(node));
4358 const casted = @bitCast([4]u32, contents_hash);4358 const casted = @as([4]u32, @bitCast(contents_hash));
4359 wip_members.appendToDeclSlice(&casted);4359 wip_members.appendToDeclSlice(&casted);
4360 }4360 }
4361 {4361 {
...@@ -4542,7 +4542,7 @@ fn testDecl(...@@ -4542,7 +4542,7 @@ fn testDecl(
45424542
4543 {4543 {
4544 const contents_hash = std.zig.hashSrc(tree.getNodeSource(node));4544 const contents_hash = std.zig.hashSrc(tree.getNodeSource(node));
4545 const casted = @bitCast([4]u32, contents_hash);4545 const casted = @as([4]u32, @bitCast(contents_hash));
4546 wip_members.appendToDeclSlice(&casted);4546 wip_members.appendToDeclSlice(&casted);
4547 }4547 }
4548 {4548 {
...@@ -4642,7 +4642,7 @@ fn structDeclInner(...@@ -4642,7 +4642,7 @@ fn structDeclInner(
4642 };4642 };
46434643
4644 const decl_count = try astgen.scanDecls(&namespace, container_decl.ast.members);4644 const decl_count = try astgen.scanDecls(&namespace, container_decl.ast.members);
4645 const field_count = @intCast(u32, container_decl.ast.members.len - decl_count);4645 const field_count = @as(u32, @intCast(container_decl.ast.members.len - decl_count));
46464646
4647 const bits_per_field = 4;4647 const bits_per_field = 4;
4648 const max_field_size = 5;4648 const max_field_size = 5;
...@@ -4750,7 +4750,7 @@ fn structDeclInner(...@@ -4750,7 +4750,7 @@ fn structDeclInner(
4750 const old_scratch_len = astgen.scratch.items.len;4750 const old_scratch_len = astgen.scratch.items.len;
4751 try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body));4751 try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body));
4752 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);4752 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);
4753 wip_members.appendToField(@intCast(u32, astgen.scratch.items.len - old_scratch_len));4753 wip_members.appendToField(@as(u32, @intCast(astgen.scratch.items.len - old_scratch_len)));
4754 block_scope.instructions.items.len = block_scope.instructions_top;4754 block_scope.instructions.items.len = block_scope.instructions_top;
4755 } else {4755 } else {
4756 wip_members.appendToField(@intFromEnum(field_type));4756 wip_members.appendToField(@intFromEnum(field_type));
...@@ -4768,7 +4768,7 @@ fn structDeclInner(...@@ -4768,7 +4768,7 @@ fn structDeclInner(
4768 const old_scratch_len = astgen.scratch.items.len;4768 const old_scratch_len = astgen.scratch.items.len;
4769 try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body));4769 try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body));
4770 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);4770 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);
4771 wip_members.appendToField(@intCast(u32, astgen.scratch.items.len - old_scratch_len));4771 wip_members.appendToField(@as(u32, @intCast(astgen.scratch.items.len - old_scratch_len)));
4772 block_scope.instructions.items.len = block_scope.instructions_top;4772 block_scope.instructions.items.len = block_scope.instructions_top;
4773 }4773 }
47744774
...@@ -4783,7 +4783,7 @@ fn structDeclInner(...@@ -4783,7 +4783,7 @@ fn structDeclInner(
4783 const old_scratch_len = astgen.scratch.items.len;4783 const old_scratch_len = astgen.scratch.items.len;
4784 try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body));4784 try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body));
4785 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);4785 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);
4786 wip_members.appendToField(@intCast(u32, astgen.scratch.items.len - old_scratch_len));4786 wip_members.appendToField(@as(u32, @intCast(astgen.scratch.items.len - old_scratch_len)));
4787 block_scope.instructions.items.len = block_scope.instructions_top;4787 block_scope.instructions.items.len = block_scope.instructions_top;
4788 } else if (member.comptime_token) |comptime_token| {4788 } else if (member.comptime_token) |comptime_token| {
4789 return astgen.failTok(comptime_token, "comptime field without default initialization value", .{});4789 return astgen.failTok(comptime_token, "comptime field without default initialization value", .{});
...@@ -4796,7 +4796,7 @@ fn structDeclInner(...@@ -4796,7 +4796,7 @@ fn structDeclInner(
4796 .fields_len = field_count,4796 .fields_len = field_count,
4797 .decls_len = decl_count,4797 .decls_len = decl_count,
4798 .backing_int_ref = backing_int_ref,4798 .backing_int_ref = backing_int_ref,
4799 .backing_int_body_len = @intCast(u32, backing_int_body_len),4799 .backing_int_body_len = @as(u32, @intCast(backing_int_body_len)),
4800 .known_non_opv = known_non_opv,4800 .known_non_opv = known_non_opv,
4801 .known_comptime_only = known_comptime_only,4801 .known_comptime_only = known_comptime_only,
4802 .is_tuple = is_tuple,4802 .is_tuple = is_tuple,
...@@ -4856,7 +4856,7 @@ fn unionDeclInner(...@@ -4856,7 +4856,7 @@ fn unionDeclInner(
4856 defer block_scope.unstack();4856 defer block_scope.unstack();
48574857
4858 const decl_count = try astgen.scanDecls(&namespace, members);4858 const decl_count = try astgen.scanDecls(&namespace, members);
4859 const field_count = @intCast(u32, members.len - decl_count);4859 const field_count = @as(u32, @intCast(members.len - decl_count));
48604860
4861 if (layout != .Auto and (auto_enum_tok != null or arg_node != 0)) {4861 if (layout != .Auto and (auto_enum_tok != null or arg_node != 0)) {
4862 const layout_str = if (layout == .Extern) "extern" else "packed";4862 const layout_str = if (layout == .Extern) "extern" else "packed";
...@@ -5151,7 +5151,7 @@ fn containerDecl(...@@ -5151,7 +5151,7 @@ fn containerDecl(
51515151
5152 const bits_per_field = 1;5152 const bits_per_field = 1;
5153 const max_field_size = 3;5153 const max_field_size = 3;
5154 var wip_members = try WipMembers.init(gpa, &astgen.scratch, @intCast(u32, counts.decls), @intCast(u32, counts.total_fields), bits_per_field, max_field_size);5154 var wip_members = try WipMembers.init(gpa, &astgen.scratch, @as(u32, @intCast(counts.decls)), @as(u32, @intCast(counts.total_fields)), bits_per_field, max_field_size);
5155 defer wip_members.deinit();5155 defer wip_members.deinit();
51565156
5157 for (container_decl.ast.members) |member_node| {5157 for (container_decl.ast.members) |member_node| {
...@@ -5209,8 +5209,8 @@ fn containerDecl(...@@ -5209,8 +5209,8 @@ fn containerDecl(
5209 .nonexhaustive = nonexhaustive,5209 .nonexhaustive = nonexhaustive,
5210 .tag_type = arg_inst,5210 .tag_type = arg_inst,
5211 .body_len = body_len,5211 .body_len = body_len,
5212 .fields_len = @intCast(u32, counts.total_fields),5212 .fields_len = @as(u32, @intCast(counts.total_fields)),
5213 .decls_len = @intCast(u32, counts.decls),5213 .decls_len = @as(u32, @intCast(counts.decls)),
5214 });5214 });
52155215
5216 wip_members.finishBits(bits_per_field);5216 wip_members.finishBits(bits_per_field);
...@@ -5400,7 +5400,7 @@ fn errorSetDecl(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zi...@@ -5400,7 +5400,7 @@ fn errorSetDecl(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zi
5400 }5400 }
54015401
5402 setExtra(astgen, payload_index, Zir.Inst.ErrorSetDecl{5402 setExtra(astgen, payload_index, Zir.Inst.ErrorSetDecl{
5403 .fields_len = @intCast(u32, fields_len),5403 .fields_len = @as(u32, @intCast(fields_len)),
5404 });5404 });
5405 const result = try gz.addPlNodePayloadIndex(.error_set_decl, node, payload_index);5405 const result = try gz.addPlNodePayloadIndex(.error_set_decl, node, payload_index);
5406 return rvalue(gz, ri, result, node);5406 return rvalue(gz, ri, result, node);
...@@ -6463,7 +6463,7 @@ fn forExpr(...@@ -6463,7 +6463,7 @@ fn forExpr(
6463 {6463 {
6464 var capture_token = for_full.payload_token;6464 var capture_token = for_full.payload_token;
6465 for (for_full.ast.inputs, 0..) |input, i_usize| {6465 for (for_full.ast.inputs, 0..) |input, i_usize| {
6466 const i = @intCast(u32, i_usize);6466 const i = @as(u32, @intCast(i_usize));
6467 const capture_is_ref = token_tags[capture_token] == .asterisk;6467 const capture_is_ref = token_tags[capture_token] == .asterisk;
6468 const ident_tok = capture_token + @intFromBool(capture_is_ref);6468 const ident_tok = capture_token + @intFromBool(capture_is_ref);
6469 const is_discard = mem.eql(u8, tree.tokenSlice(ident_tok), "_");6469 const is_discard = mem.eql(u8, tree.tokenSlice(ident_tok), "_");
...@@ -6521,7 +6521,7 @@ fn forExpr(...@@ -6521,7 +6521,7 @@ fn forExpr(
6521 // We use a dedicated ZIR instruction to assert the lengths to assist with6521 // We use a dedicated ZIR instruction to assert the lengths to assist with
6522 // nicer error reporting as well as fewer ZIR bytes emitted.6522 // nicer error reporting as well as fewer ZIR bytes emitted.
6523 const len: Zir.Inst.Ref = len: {6523 const len: Zir.Inst.Ref = len: {
6524 const lens_len = @intCast(u32, lens.len);6524 const lens_len = @as(u32, @intCast(lens.len));
6525 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.MultiOp).Struct.fields.len + lens_len);6525 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.MultiOp).Struct.fields.len + lens_len);
6526 const len = try parent_gz.addPlNode(.for_len, node, Zir.Inst.MultiOp{6526 const len = try parent_gz.addPlNode(.for_len, node, Zir.Inst.MultiOp{
6527 .operands_len = lens_len,6527 .operands_len = lens_len,
...@@ -6591,7 +6591,7 @@ fn forExpr(...@@ -6591,7 +6591,7 @@ fn forExpr(
6591 var capture_token = for_full.payload_token;6591 var capture_token = for_full.payload_token;
6592 var capture_sub_scope: *Scope = &then_scope.base;6592 var capture_sub_scope: *Scope = &then_scope.base;
6593 for (for_full.ast.inputs, 0..) |input, i_usize| {6593 for (for_full.ast.inputs, 0..) |input, i_usize| {
6594 const i = @intCast(u32, i_usize);6594 const i = @as(u32, @intCast(i_usize));
6595 const capture_is_ref = token_tags[capture_token] == .asterisk;6595 const capture_is_ref = token_tags[capture_token] == .asterisk;
6596 const ident_tok = capture_token + @intFromBool(capture_is_ref);6596 const ident_tok = capture_token + @intFromBool(capture_is_ref);
6597 const capture_name = tree.tokenSlice(ident_tok);6597 const capture_name = tree.tokenSlice(ident_tok);
...@@ -6891,7 +6891,7 @@ fn switchExpr(...@@ -6891,7 +6891,7 @@ fn switchExpr(
68916891
6892 // If any prong has an inline tag capture, allocate a shared dummy instruction for it6892 // If any prong has an inline tag capture, allocate a shared dummy instruction for it
6893 const tag_inst = if (any_has_tag_capture) tag_inst: {6893 const tag_inst = if (any_has_tag_capture) tag_inst: {
6894 const inst = @intCast(Zir.Inst.Index, astgen.instructions.len);6894 const inst = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
6895 try astgen.instructions.append(astgen.gpa, .{6895 try astgen.instructions.append(astgen.gpa, .{
6896 .tag = .extended,6896 .tag = .extended,
6897 .data = .{ .extended = .{6897 .data = .{ .extended = .{
...@@ -6984,7 +6984,7 @@ fn switchExpr(...@@ -6984,7 +6984,7 @@ fn switchExpr(
6984 break :blk &tag_scope.base;6984 break :blk &tag_scope.base;
6985 };6985 };
69866986
6987 const header_index = @intCast(u32, payloads.items.len);6987 const header_index = @as(u32, @intCast(payloads.items.len));
6988 const body_len_index = if (is_multi_case) blk: {6988 const body_len_index = if (is_multi_case) blk: {
6989 payloads.items[multi_case_table + multi_case_index] = header_index;6989 payloads.items[multi_case_table + multi_case_index] = header_index;
6990 multi_case_index += 1;6990 multi_case_index += 1;
...@@ -7074,12 +7074,12 @@ fn switchExpr(...@@ -7074,12 +7074,12 @@ fn switchExpr(
7074 };7074 };
7075 const body_len = refs_len + astgen.countBodyLenAfterFixups(case_slice);7075 const body_len = refs_len + astgen.countBodyLenAfterFixups(case_slice);
7076 try payloads.ensureUnusedCapacity(gpa, body_len);7076 try payloads.ensureUnusedCapacity(gpa, body_len);
7077 payloads.items[body_len_index] = @bitCast(u32, Zir.Inst.SwitchBlock.ProngInfo{7077 payloads.items[body_len_index] = @as(u32, @bitCast(Zir.Inst.SwitchBlock.ProngInfo{
7078 .body_len = @intCast(u28, body_len),7078 .body_len = @as(u28, @intCast(body_len)),
7079 .capture = capture,7079 .capture = capture,
7080 .is_inline = case.inline_token != null,7080 .is_inline = case.inline_token != null,
7081 .has_tag_capture = has_tag_capture,7081 .has_tag_capture = has_tag_capture,
7082 });7082 }));
7083 if (astgen.ref_table.fetchRemove(switch_block)) |kv| {7083 if (astgen.ref_table.fetchRemove(switch_block)) |kv| {
7084 appendPossiblyRefdBodyInst(astgen, payloads, kv.value);7084 appendPossiblyRefdBodyInst(astgen, payloads, kv.value);
7085 }7085 }
...@@ -7106,7 +7106,7 @@ fn switchExpr(...@@ -7106,7 +7106,7 @@ fn switchExpr(
7106 .has_else = special_prong == .@"else",7106 .has_else = special_prong == .@"else",
7107 .has_under = special_prong == .under,7107 .has_under = special_prong == .under,
7108 .any_has_tag_capture = any_has_tag_capture,7108 .any_has_tag_capture = any_has_tag_capture,
7109 .scalar_cases_len = @intCast(Zir.Inst.SwitchBlock.Bits.ScalarCasesLen, scalar_cases_len),7109 .scalar_cases_len = @as(Zir.Inst.SwitchBlock.Bits.ScalarCasesLen, @intCast(scalar_cases_len)),
7110 },7110 },
7111 });7111 });
71127112
...@@ -7140,7 +7140,7 @@ fn switchExpr(...@@ -7140,7 +7140,7 @@ fn switchExpr(
7140 end_index += 3 + items_len + 2 * ranges_len;7140 end_index += 3 + items_len + 2 * ranges_len;
7141 }7141 }
71427142
7143 const body_len = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, payloads.items[body_len_index]).body_len;7143 const body_len = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(payloads.items[body_len_index])).body_len;
7144 end_index += body_len;7144 end_index += body_len;
71457145
7146 switch (strat.tag) {7146 switch (strat.tag) {
...@@ -7579,7 +7579,7 @@ fn tunnelThroughClosure(...@@ -7579,7 +7579,7 @@ fn tunnelThroughClosure(
7579 .src_tok = ns.?.declaring_gz.?.tokenIndexToRelative(token),7579 .src_tok = ns.?.declaring_gz.?.tokenIndexToRelative(token),
7580 } },7580 } },
7581 });7581 });
7582 gop.value_ptr.* = @intCast(Zir.Inst.Index, gz.astgen.instructions.len - 1);7582 gop.value_ptr.* = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len - 1));
7583 }7583 }
75847584
7585 // Add an instruction to get the value from the closure into7585 // Add an instruction to get the value from the closure into
...@@ -7680,7 +7680,7 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node:...@@ -7680,7 +7680,7 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node:
7680 };7680 };
7681 // If the value fits into a f64 without losing any precision, store it that way.7681 // If the value fits into a f64 without losing any precision, store it that way.
7682 @setFloatMode(.Strict);7682 @setFloatMode(.Strict);
7683 const smaller_float = @floatCast(f64, float_number);7683 const smaller_float = @as(f64, @floatCast(float_number));
7684 const bigger_again: f128 = smaller_float;7684 const bigger_again: f128 = smaller_float;
7685 if (bigger_again == float_number) {7685 if (bigger_again == float_number) {
7686 const result = try gz.addFloat(smaller_float);7686 const result = try gz.addFloat(smaller_float);
...@@ -7688,12 +7688,12 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node:...@@ -7688,12 +7688,12 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node:
7688 }7688 }
7689 // We need to use 128 bits. Break the float into 4 u32 values so we can7689 // We need to use 128 bits. Break the float into 4 u32 values so we can
7690 // put it into the `extra` array.7690 // put it into the `extra` array.
7691 const int_bits = @bitCast(u128, float_number);7691 const int_bits = @as(u128, @bitCast(float_number));
7692 const result = try gz.addPlNode(.float128, node, Zir.Inst.Float128{7692 const result = try gz.addPlNode(.float128, node, Zir.Inst.Float128{
7693 .piece0 = @truncate(u32, int_bits),7693 .piece0 = @as(u32, @truncate(int_bits)),
7694 .piece1 = @truncate(u32, int_bits >> 32),7694 .piece1 = @as(u32, @truncate(int_bits >> 32)),
7695 .piece2 = @truncate(u32, int_bits >> 64),7695 .piece2 = @as(u32, @truncate(int_bits >> 64)),
7696 .piece3 = @truncate(u32, int_bits >> 96),7696 .piece3 = @as(u32, @truncate(int_bits >> 96)),
7697 });7697 });
7698 return rvalue(gz, ri, result, source_node);7698 return rvalue(gz, ri, result, source_node);
7699 },7699 },
...@@ -7719,22 +7719,22 @@ fn failWithNumberError(astgen: *AstGen, err: std.zig.number_literal.Error, token...@@ -7719,22 +7719,22 @@ fn failWithNumberError(astgen: *AstGen, err: std.zig.number_literal.Error, token
7719 });7719 });
7720 },7720 },
7721 .digit_after_base => return astgen.failTok(token, "expected a digit after base prefix", .{}),7721 .digit_after_base => return astgen.failTok(token, "expected a digit after base prefix", .{}),
7722 .upper_case_base => |i| return astgen.failOff(token, @intCast(u32, i), "base prefix must be lowercase", .{}),7722 .upper_case_base => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "base prefix must be lowercase", .{}),
7723 .invalid_float_base => |i| return astgen.failOff(token, @intCast(u32, i), "invalid base for float literal", .{}),7723 .invalid_float_base => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "invalid base for float literal", .{}),
7724 .repeated_underscore => |i| return astgen.failOff(token, @intCast(u32, i), "repeated digit separator", .{}),7724 .repeated_underscore => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "repeated digit separator", .{}),
7725 .invalid_underscore_after_special => |i| return astgen.failOff(token, @intCast(u32, i), "expected digit before digit separator", .{}),7725 .invalid_underscore_after_special => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "expected digit before digit separator", .{}),
7726 .invalid_digit => |info| return astgen.failOff(token, @intCast(u32, info.i), "invalid digit '{c}' for {s} base", .{ bytes[info.i], @tagName(info.base) }),7726 .invalid_digit => |info| return astgen.failOff(token, @as(u32, @intCast(info.i)), "invalid digit '{c}' for {s} base", .{ bytes[info.i], @tagName(info.base) }),
7727 .invalid_digit_exponent => |i| return astgen.failOff(token, @intCast(u32, i), "invalid digit '{c}' in exponent", .{bytes[i]}),7727 .invalid_digit_exponent => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "invalid digit '{c}' in exponent", .{bytes[i]}),
7728 .duplicate_exponent => |i| return astgen.failOff(token, @intCast(u32, i), "duplicate exponent", .{}),7728 .duplicate_exponent => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "duplicate exponent", .{}),
7729 .exponent_after_underscore => |i| return astgen.failOff(token, @intCast(u32, i), "expected digit before exponent", .{}),7729 .exponent_after_underscore => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "expected digit before exponent", .{}),
7730 .special_after_underscore => |i| return astgen.failOff(token, @intCast(u32, i), "expected digit before '{c}'", .{bytes[i]}),7730 .special_after_underscore => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "expected digit before '{c}'", .{bytes[i]}),
7731 .trailing_special => |i| return astgen.failOff(token, @intCast(u32, i), "expected digit after '{c}'", .{bytes[i - 1]}),7731 .trailing_special => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "expected digit after '{c}'", .{bytes[i - 1]}),
7732 .trailing_underscore => |i| return astgen.failOff(token, @intCast(u32, i), "trailing digit separator", .{}),7732 .trailing_underscore => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "trailing digit separator", .{}),
7733 .duplicate_period => unreachable, // Validated by tokenizer7733 .duplicate_period => unreachable, // Validated by tokenizer
7734 .invalid_character => unreachable, // Validated by tokenizer7734 .invalid_character => unreachable, // Validated by tokenizer
7735 .invalid_exponent_sign => |i| {7735 .invalid_exponent_sign => |i| {
7736 assert(bytes.len >= 2 and bytes[0] == '0' and bytes[1] == 'x'); // Validated by tokenizer7736 assert(bytes.len >= 2 and bytes[0] == '0' and bytes[1] == 'x'); // Validated by tokenizer
7737 return astgen.failOff(token, @intCast(u32, i), "sign '{c}' cannot follow digit '{c}' in hex base", .{ bytes[i], bytes[i - 1] });7737 return astgen.failOff(token, @as(u32, @intCast(i)), "sign '{c}' cannot follow digit '{c}' in hex base", .{ bytes[i], bytes[i - 1] });
7738 },7738 },
7739 }7739 }
7740}7740}
...@@ -7801,7 +7801,7 @@ fn asmExpr(...@@ -7801,7 +7801,7 @@ fn asmExpr(
7801 if (output_type_bits != 0) {7801 if (output_type_bits != 0) {
7802 return astgen.failNode(output_node, "inline assembly allows up to one output value", .{});7802 return astgen.failNode(output_node, "inline assembly allows up to one output value", .{});
7803 }7803 }
7804 output_type_bits |= @as(u32, 1) << @intCast(u5, i);7804 output_type_bits |= @as(u32, 1) << @as(u5, @intCast(i));
7805 const out_type_node = node_datas[output_node].lhs;7805 const out_type_node = node_datas[output_node].lhs;
7806 const out_type_inst = try typeExpr(gz, scope, out_type_node);7806 const out_type_inst = try typeExpr(gz, scope, out_type_node);
7807 outputs[i] = .{7807 outputs[i] = .{
...@@ -8024,11 +8024,11 @@ fn ptrCast(...@@ -8024,11 +8024,11 @@ fn ptrCast(
8024 node = node_datas[node].lhs;8024 node = node_datas[node].lhs;
8025 }8025 }
80268026
8027 const flags_i = @bitCast(u5, flags);8027 const flags_i = @as(u5, @bitCast(flags));
8028 assert(flags_i != 0);8028 assert(flags_i != 0);
80298029
8030 const ptr_only: Zir.Inst.FullPtrCastFlags = .{ .ptr_cast = true };8030 const ptr_only: Zir.Inst.FullPtrCastFlags = .{ .ptr_cast = true };
8031 if (flags_i == @bitCast(u5, ptr_only)) {8031 if (flags_i == @as(u5, @bitCast(ptr_only))) {
8032 // Special case: simpler representation8032 // Special case: simpler representation
8033 return typeCast(gz, scope, ri, root_node, node, .ptr_cast, "@ptrCast");8033 return typeCast(gz, scope, ri, root_node, node, .ptr_cast, "@ptrCast");
8034 }8034 }
...@@ -8037,7 +8037,7 @@ fn ptrCast(...@@ -8037,7 +8037,7 @@ fn ptrCast(
8037 .const_cast = true,8037 .const_cast = true,
8038 .volatile_cast = true,8038 .volatile_cast = true,
8039 };8039 };
8040 if ((flags_i & ~@bitCast(u5, no_result_ty_flags)) == 0) {8040 if ((flags_i & ~@as(u5, @bitCast(no_result_ty_flags))) == 0) {
8041 // Result type not needed8041 // Result type not needed
8042 const cursor = maybeAdvanceSourceCursorToMainToken(gz, root_node);8042 const cursor = maybeAdvanceSourceCursorToMainToken(gz, root_node);
8043 const operand = try expr(gz, scope, .{ .rl = .none }, node);8043 const operand = try expr(gz, scope, .{ .rl = .none }, node);
...@@ -8119,8 +8119,8 @@ fn typeOf(...@@ -8119,8 +8119,8 @@ fn typeOf(
8119 const body = typeof_scope.instructionsSlice();8119 const body = typeof_scope.instructionsSlice();
8120 const body_len = astgen.countBodyLenAfterFixups(body);8120 const body_len = astgen.countBodyLenAfterFixups(body);
8121 astgen.setExtra(payload_index, Zir.Inst.TypeOfPeer{8121 astgen.setExtra(payload_index, Zir.Inst.TypeOfPeer{
8122 .body_len = @intCast(u32, body_len),8122 .body_len = @as(u32, @intCast(body_len)),
8123 .body_index = @intCast(u32, astgen.extra.items.len),8123 .body_index = @as(u32, @intCast(astgen.extra.items.len)),
8124 .src_node = gz.nodeIndexToRelative(node),8124 .src_node = gz.nodeIndexToRelative(node),
8125 });8125 });
8126 try astgen.extra.ensureUnusedCapacity(gpa, body_len);8126 try astgen.extra.ensureUnusedCapacity(gpa, body_len);
...@@ -8464,7 +8464,7 @@ fn builtinCall(...@@ -8464,7 +8464,7 @@ fn builtinCall(
8464 .node = gz.nodeIndexToRelative(node),8464 .node = gz.nodeIndexToRelative(node),
8465 .operand = operand,8465 .operand = operand,
8466 });8466 });
8467 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);8467 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
8468 gz.astgen.instructions.appendAssumeCapacity(.{8468 gz.astgen.instructions.appendAssumeCapacity(.{
8469 .tag = .extended,8469 .tag = .extended,
8470 .data = .{ .extended = .{8470 .data = .{ .extended = .{
...@@ -9115,7 +9115,7 @@ fn callExpr(...@@ -9115,7 +9115,7 @@ fn callExpr(
9115 }9115 }
9116 assert(node != 0);9116 assert(node != 0);
91179117
9118 const call_index = @intCast(Zir.Inst.Index, astgen.instructions.len);9118 const call_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
9119 const call_inst = Zir.indexToRef(call_index);9119 const call_inst = Zir.indexToRef(call_index);
9120 try gz.astgen.instructions.append(astgen.gpa, undefined);9120 try gz.astgen.instructions.append(astgen.gpa, undefined);
9121 try gz.instructions.append(astgen.gpa, call_index);9121 try gz.instructions.append(astgen.gpa, call_index);
...@@ -9139,7 +9139,7 @@ fn callExpr(...@@ -9139,7 +9139,7 @@ fn callExpr(
9139 try astgen.scratch.ensureUnusedCapacity(astgen.gpa, countBodyLenAfterFixups(astgen, body));9139 try astgen.scratch.ensureUnusedCapacity(astgen.gpa, countBodyLenAfterFixups(astgen, body));
9140 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);9140 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);
91419141
9142 astgen.scratch.items[scratch_index] = @intCast(u32, astgen.scratch.items.len - scratch_top);9142 astgen.scratch.items[scratch_index] = @as(u32, @intCast(astgen.scratch.items.len - scratch_top));
9143 scratch_index += 1;9143 scratch_index += 1;
9144 }9144 }
91459145
...@@ -9157,8 +9157,8 @@ fn callExpr(...@@ -9157,8 +9157,8 @@ fn callExpr(
9157 .callee = callee_obj,9157 .callee = callee_obj,
9158 .flags = .{9158 .flags = .{
9159 .pop_error_return_trace = !propagate_error_trace,9159 .pop_error_return_trace = !propagate_error_trace,
9160 .packed_modifier = @intCast(Zir.Inst.Call.Flags.PackedModifier, @intFromEnum(modifier)),9160 .packed_modifier = @as(Zir.Inst.Call.Flags.PackedModifier, @intCast(@intFromEnum(modifier))),
9161 .args_len = @intCast(Zir.Inst.Call.Flags.PackedArgsLen, call.ast.params.len),9161 .args_len = @as(Zir.Inst.Call.Flags.PackedArgsLen, @intCast(call.ast.params.len)),
9162 },9162 },
9163 });9163 });
9164 if (call.ast.params.len != 0) {9164 if (call.ast.params.len != 0) {
...@@ -9178,8 +9178,8 @@ fn callExpr(...@@ -9178,8 +9178,8 @@ fn callExpr(
9178 .field_name_start = callee_field.field_name_start,9178 .field_name_start = callee_field.field_name_start,
9179 .flags = .{9179 .flags = .{
9180 .pop_error_return_trace = !propagate_error_trace,9180 .pop_error_return_trace = !propagate_error_trace,
9181 .packed_modifier = @intCast(Zir.Inst.Call.Flags.PackedModifier, @intFromEnum(modifier)),9181 .packed_modifier = @as(Zir.Inst.Call.Flags.PackedModifier, @intCast(@intFromEnum(modifier))),
9182 .args_len = @intCast(Zir.Inst.Call.Flags.PackedArgsLen, call.ast.params.len),9182 .args_len = @as(Zir.Inst.Call.Flags.PackedArgsLen, @intCast(call.ast.params.len)),
9183 },9183 },
9184 });9184 });
9185 if (call.ast.params.len != 0) {9185 if (call.ast.params.len != 0) {
...@@ -10552,7 +10552,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token...@@ -10552,7 +10552,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
10552 .invalid_escape_character => |bad_index| {10552 .invalid_escape_character => |bad_index| {
10553 return astgen.failOff(10553 return astgen.failOff(
10554 token,10554 token,
10555 offset + @intCast(u32, bad_index),10555 offset + @as(u32, @intCast(bad_index)),
10556 "invalid escape character: '{c}'",10556 "invalid escape character: '{c}'",
10557 .{raw_string[bad_index]},10557 .{raw_string[bad_index]},
10558 );10558 );
...@@ -10560,7 +10560,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token...@@ -10560,7 +10560,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
10560 .expected_hex_digit => |bad_index| {10560 .expected_hex_digit => |bad_index| {
10561 return astgen.failOff(10561 return astgen.failOff(
10562 token,10562 token,
10563 offset + @intCast(u32, bad_index),10563 offset + @as(u32, @intCast(bad_index)),
10564 "expected hex digit, found '{c}'",10564 "expected hex digit, found '{c}'",
10565 .{raw_string[bad_index]},10565 .{raw_string[bad_index]},
10566 );10566 );
...@@ -10568,7 +10568,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token...@@ -10568,7 +10568,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
10568 .empty_unicode_escape_sequence => |bad_index| {10568 .empty_unicode_escape_sequence => |bad_index| {
10569 return astgen.failOff(10569 return astgen.failOff(
10570 token,10570 token,
10571 offset + @intCast(u32, bad_index),10571 offset + @as(u32, @intCast(bad_index)),
10572 "empty unicode escape sequence",10572 "empty unicode escape sequence",
10573 .{},10573 .{},
10574 );10574 );
...@@ -10576,7 +10576,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token...@@ -10576,7 +10576,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
10576 .expected_hex_digit_or_rbrace => |bad_index| {10576 .expected_hex_digit_or_rbrace => |bad_index| {
10577 return astgen.failOff(10577 return astgen.failOff(
10578 token,10578 token,
10579 offset + @intCast(u32, bad_index),10579 offset + @as(u32, @intCast(bad_index)),
10580 "expected hex digit or '}}', found '{c}'",10580 "expected hex digit or '}}', found '{c}'",
10581 .{raw_string[bad_index]},10581 .{raw_string[bad_index]},
10582 );10582 );
...@@ -10584,7 +10584,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token...@@ -10584,7 +10584,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
10584 .invalid_unicode_codepoint => |bad_index| {10584 .invalid_unicode_codepoint => |bad_index| {
10585 return astgen.failOff(10585 return astgen.failOff(
10586 token,10586 token,
10587 offset + @intCast(u32, bad_index),10587 offset + @as(u32, @intCast(bad_index)),
10588 "unicode escape does not correspond to a valid codepoint",10588 "unicode escape does not correspond to a valid codepoint",
10589 .{},10589 .{},
10590 );10590 );
...@@ -10592,7 +10592,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token...@@ -10592,7 +10592,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
10592 .expected_lbrace => |bad_index| {10592 .expected_lbrace => |bad_index| {
10593 return astgen.failOff(10593 return astgen.failOff(
10594 token,10594 token,
10595 offset + @intCast(u32, bad_index),10595 offset + @as(u32, @intCast(bad_index)),
10596 "expected '{{', found '{c}",10596 "expected '{{', found '{c}",
10597 .{raw_string[bad_index]},10597 .{raw_string[bad_index]},
10598 );10598 );
...@@ -10600,7 +10600,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token...@@ -10600,7 +10600,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
10600 .expected_rbrace => |bad_index| {10600 .expected_rbrace => |bad_index| {
10601 return astgen.failOff(10601 return astgen.failOff(
10602 token,10602 token,
10603 offset + @intCast(u32, bad_index),10603 offset + @as(u32, @intCast(bad_index)),
10604 "expected '}}', found '{c}",10604 "expected '}}', found '{c}",
10605 .{raw_string[bad_index]},10605 .{raw_string[bad_index]},
10606 );10606 );
...@@ -10608,7 +10608,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token...@@ -10608,7 +10608,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
10608 .expected_single_quote => |bad_index| {10608 .expected_single_quote => |bad_index| {
10609 return astgen.failOff(10609 return astgen.failOff(
10610 token,10610 token,
10611 offset + @intCast(u32, bad_index),10611 offset + @as(u32, @intCast(bad_index)),
10612 "expected single quote ('), found '{c}",10612 "expected single quote ('), found '{c}",
10613 .{raw_string[bad_index]},10613 .{raw_string[bad_index]},
10614 );10614 );
...@@ -10616,7 +10616,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token...@@ -10616,7 +10616,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
10616 .invalid_character => |bad_index| {10616 .invalid_character => |bad_index| {
10617 return astgen.failOff(10617 return astgen.failOff(
10618 token,10618 token,
10619 offset + @intCast(u32, bad_index),10619 offset + @as(u32, @intCast(bad_index)),
10620 "invalid byte in string or character literal: '{c}'",10620 "invalid byte in string or character literal: '{c}'",
10621 .{raw_string[bad_index]},10621 .{raw_string[bad_index]},
10622 );10622 );
...@@ -10651,14 +10651,14 @@ fn appendErrorNodeNotes(...@@ -10651,14 +10651,14 @@ fn appendErrorNodeNotes(
10651) Allocator.Error!void {10651) Allocator.Error!void {
10652 @setCold(true);10652 @setCold(true);
10653 const string_bytes = &astgen.string_bytes;10653 const string_bytes = &astgen.string_bytes;
10654 const msg = @intCast(u32, string_bytes.items.len);10654 const msg = @as(u32, @intCast(string_bytes.items.len));
10655 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);10655 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
10656 const notes_index: u32 = if (notes.len != 0) blk: {10656 const notes_index: u32 = if (notes.len != 0) blk: {
10657 const notes_start = astgen.extra.items.len;10657 const notes_start = astgen.extra.items.len;
10658 try astgen.extra.ensureTotalCapacity(astgen.gpa, notes_start + 1 + notes.len);10658 try astgen.extra.ensureTotalCapacity(astgen.gpa, notes_start + 1 + notes.len);
10659 astgen.extra.appendAssumeCapacity(@intCast(u32, notes.len));10659 astgen.extra.appendAssumeCapacity(@as(u32, @intCast(notes.len)));
10660 astgen.extra.appendSliceAssumeCapacity(notes);10660 astgen.extra.appendSliceAssumeCapacity(notes);
10661 break :blk @intCast(u32, notes_start);10661 break :blk @as(u32, @intCast(notes_start));
10662 } else 0;10662 } else 0;
10663 try astgen.compile_errors.append(astgen.gpa, .{10663 try astgen.compile_errors.append(astgen.gpa, .{
10664 .msg = msg,10664 .msg = msg,
...@@ -10743,14 +10743,14 @@ fn appendErrorTokNotesOff(...@@ -10743,14 +10743,14 @@ fn appendErrorTokNotesOff(
10743 @setCold(true);10743 @setCold(true);
10744 const gpa = astgen.gpa;10744 const gpa = astgen.gpa;
10745 const string_bytes = &astgen.string_bytes;10745 const string_bytes = &astgen.string_bytes;
10746 const msg = @intCast(u32, string_bytes.items.len);10746 const msg = @as(u32, @intCast(string_bytes.items.len));
10747 try string_bytes.writer(gpa).print(format ++ "\x00", args);10747 try string_bytes.writer(gpa).print(format ++ "\x00", args);
10748 const notes_index: u32 = if (notes.len != 0) blk: {10748 const notes_index: u32 = if (notes.len != 0) blk: {
10749 const notes_start = astgen.extra.items.len;10749 const notes_start = astgen.extra.items.len;
10750 try astgen.extra.ensureTotalCapacity(gpa, notes_start + 1 + notes.len);10750 try astgen.extra.ensureTotalCapacity(gpa, notes_start + 1 + notes.len);
10751 astgen.extra.appendAssumeCapacity(@intCast(u32, notes.len));10751 astgen.extra.appendAssumeCapacity(@as(u32, @intCast(notes.len)));
10752 astgen.extra.appendSliceAssumeCapacity(notes);10752 astgen.extra.appendSliceAssumeCapacity(notes);
10753 break :blk @intCast(u32, notes_start);10753 break :blk @as(u32, @intCast(notes_start));
10754 } else 0;10754 } else 0;
10755 try astgen.compile_errors.append(gpa, .{10755 try astgen.compile_errors.append(gpa, .{
10756 .msg = msg,10756 .msg = msg,
...@@ -10779,7 +10779,7 @@ fn errNoteTokOff(...@@ -10779,7 +10779,7 @@ fn errNoteTokOff(
10779) Allocator.Error!u32 {10779) Allocator.Error!u32 {
10780 @setCold(true);10780 @setCold(true);
10781 const string_bytes = &astgen.string_bytes;10781 const string_bytes = &astgen.string_bytes;
10782 const msg = @intCast(u32, string_bytes.items.len);10782 const msg = @as(u32, @intCast(string_bytes.items.len));
10783 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);10783 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
10784 return astgen.addExtra(Zir.Inst.CompileErrors.Item{10784 return astgen.addExtra(Zir.Inst.CompileErrors.Item{
10785 .msg = msg,10785 .msg = msg,
...@@ -10798,7 +10798,7 @@ fn errNoteNode(...@@ -10798,7 +10798,7 @@ fn errNoteNode(
10798) Allocator.Error!u32 {10798) Allocator.Error!u32 {
10799 @setCold(true);10799 @setCold(true);
10800 const string_bytes = &astgen.string_bytes;10800 const string_bytes = &astgen.string_bytes;
10801 const msg = @intCast(u32, string_bytes.items.len);10801 const msg = @as(u32, @intCast(string_bytes.items.len));
10802 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);10802 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
10803 return astgen.addExtra(Zir.Inst.CompileErrors.Item{10803 return astgen.addExtra(Zir.Inst.CompileErrors.Item{
10804 .msg = msg,10804 .msg = msg,
...@@ -10812,7 +10812,7 @@ fn errNoteNode(...@@ -10812,7 +10812,7 @@ fn errNoteNode(
10812fn identAsString(astgen: *AstGen, ident_token: Ast.TokenIndex) !u32 {10812fn identAsString(astgen: *AstGen, ident_token: Ast.TokenIndex) !u32 {
10813 const gpa = astgen.gpa;10813 const gpa = astgen.gpa;
10814 const string_bytes = &astgen.string_bytes;10814 const string_bytes = &astgen.string_bytes;
10815 const str_index = @intCast(u32, string_bytes.items.len);10815 const str_index = @as(u32, @intCast(string_bytes.items.len));
10816 try astgen.appendIdentStr(ident_token, string_bytes);10816 try astgen.appendIdentStr(ident_token, string_bytes);
10817 const key: []const u8 = string_bytes.items[str_index..];10817 const key: []const u8 = string_bytes.items[str_index..];
10818 const gop = try astgen.string_table.getOrPutContextAdapted(gpa, key, StringIndexAdapter{10818 const gop = try astgen.string_table.getOrPutContextAdapted(gpa, key, StringIndexAdapter{
...@@ -10858,7 +10858,7 @@ fn docCommentAsStringFromFirst(...@@ -10858,7 +10858,7 @@ fn docCommentAsStringFromFirst(
1085810858
10859 const gpa = astgen.gpa;10859 const gpa = astgen.gpa;
10860 const string_bytes = &astgen.string_bytes;10860 const string_bytes = &astgen.string_bytes;
10861 const str_index = @intCast(u32, string_bytes.items.len);10861 const str_index = @as(u32, @intCast(string_bytes.items.len));
10862 const token_starts = astgen.tree.tokens.items(.start);10862 const token_starts = astgen.tree.tokens.items(.start);
10863 const token_tags = astgen.tree.tokens.items(.tag);10863 const token_tags = astgen.tree.tokens.items(.tag);
1086410864
...@@ -10901,7 +10901,7 @@ const IndexSlice = struct { index: u32, len: u32 };...@@ -10901,7 +10901,7 @@ const IndexSlice = struct { index: u32, len: u32 };
10901fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {10901fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {
10902 const gpa = astgen.gpa;10902 const gpa = astgen.gpa;
10903 const string_bytes = &astgen.string_bytes;10903 const string_bytes = &astgen.string_bytes;
10904 const str_index = @intCast(u32, string_bytes.items.len);10904 const str_index = @as(u32, @intCast(string_bytes.items.len));
10905 const token_bytes = astgen.tree.tokenSlice(str_lit_token);10905 const token_bytes = astgen.tree.tokenSlice(str_lit_token);
10906 try astgen.parseStrLit(str_lit_token, string_bytes, token_bytes, 0);10906 try astgen.parseStrLit(str_lit_token, string_bytes, token_bytes, 0);
10907 const key = string_bytes.items[str_index..];10907 const key = string_bytes.items[str_index..];
...@@ -10914,7 +10914,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {...@@ -10914,7 +10914,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {
10914 string_bytes.shrinkRetainingCapacity(str_index);10914 string_bytes.shrinkRetainingCapacity(str_index);
10915 return IndexSlice{10915 return IndexSlice{
10916 .index = gop.key_ptr.*,10916 .index = gop.key_ptr.*,
10917 .len = @intCast(u32, key.len),10917 .len = @as(u32, @intCast(key.len)),
10918 };10918 };
10919 } else {10919 } else {
10920 gop.key_ptr.* = str_index;10920 gop.key_ptr.* = str_index;
...@@ -10924,7 +10924,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {...@@ -10924,7 +10924,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {
10924 try string_bytes.append(gpa, 0);10924 try string_bytes.append(gpa, 0);
10925 return IndexSlice{10925 return IndexSlice{
10926 .index = str_index,10926 .index = str_index,
10927 .len = @intCast(u32, key.len),10927 .len = @as(u32, @intCast(key.len)),
10928 };10928 };
10929 }10929 }
10930}10930}
...@@ -10961,15 +10961,15 @@ fn strLitNodeAsString(astgen: *AstGen, node: Ast.Node.Index) !IndexSlice {...@@ -10961,15 +10961,15 @@ fn strLitNodeAsString(astgen: *AstGen, node: Ast.Node.Index) !IndexSlice {
10961 const len = string_bytes.items.len - str_index;10961 const len = string_bytes.items.len - str_index;
10962 try string_bytes.append(gpa, 0);10962 try string_bytes.append(gpa, 0);
10963 return IndexSlice{10963 return IndexSlice{
10964 .index = @intCast(u32, str_index),10964 .index = @as(u32, @intCast(str_index)),
10965 .len = @intCast(u32, len),10965 .len = @as(u32, @intCast(len)),
10966 };10966 };
10967}10967}
1096810968
10969fn testNameString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !u32 {10969fn testNameString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !u32 {
10970 const gpa = astgen.gpa;10970 const gpa = astgen.gpa;
10971 const string_bytes = &astgen.string_bytes;10971 const string_bytes = &astgen.string_bytes;
10972 const str_index = @intCast(u32, string_bytes.items.len);10972 const str_index = @as(u32, @intCast(string_bytes.items.len));
10973 const token_bytes = astgen.tree.tokenSlice(str_lit_token);10973 const token_bytes = astgen.tree.tokenSlice(str_lit_token);
10974 try string_bytes.append(gpa, 0); // Indicates this is a test.10974 try string_bytes.append(gpa, 0); // Indicates this is a test.
10975 try astgen.parseStrLit(str_lit_token, string_bytes, token_bytes, 0);10975 try astgen.parseStrLit(str_lit_token, string_bytes, token_bytes, 0);
...@@ -11321,7 +11321,7 @@ const GenZir = struct {...@@ -11321,7 +11321,7 @@ const GenZir = struct {
11321 }11321 }
1132211322
11323 fn nodeIndexToRelative(gz: GenZir, node_index: Ast.Node.Index) i32 {11323 fn nodeIndexToRelative(gz: GenZir, node_index: Ast.Node.Index) i32 {
11324 return @bitCast(i32, node_index) - @bitCast(i32, gz.decl_node_index);11324 return @as(i32, @bitCast(node_index)) - @as(i32, @bitCast(gz.decl_node_index));
11325 }11325 }
1132611326
11327 fn tokenIndexToRelative(gz: GenZir, token: Ast.TokenIndex) u32 {11327 fn tokenIndexToRelative(gz: GenZir, token: Ast.TokenIndex) u32 {
...@@ -11478,7 +11478,7 @@ const GenZir = struct {...@@ -11478,7 +11478,7 @@ const GenZir = struct {
11478 const astgen = gz.astgen;11478 const astgen = gz.astgen;
11479 const gpa = astgen.gpa;11479 const gpa = astgen.gpa;
11480 const ret_ref = if (args.ret_ref == .void_type) .none else args.ret_ref;11480 const ret_ref = if (args.ret_ref == .void_type) .none else args.ret_ref;
11481 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);11481 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
1148211482
11483 try astgen.instructions.ensureUnusedCapacity(gpa, 1);11483 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
1148411484
...@@ -11496,8 +11496,8 @@ const GenZir = struct {...@@ -11496,8 +11496,8 @@ const GenZir = struct {
11496 const block = node_datas[fn_decl].rhs;11496 const block = node_datas[fn_decl].rhs;
11497 const rbrace_start = token_starts[tree.lastToken(block)];11497 const rbrace_start = token_starts[tree.lastToken(block)];
11498 astgen.advanceSourceCursor(rbrace_start);11498 astgen.advanceSourceCursor(rbrace_start);
11499 const rbrace_line = @intCast(u32, astgen.source_line - gz.decl_line);11499 const rbrace_line = @as(u32, @intCast(astgen.source_line - gz.decl_line));
11500 const rbrace_column = @intCast(u32, astgen.source_column);11500 const rbrace_column = @as(u32, @intCast(astgen.source_column));
1150111501
11502 const columns = args.lbrace_column | (rbrace_column << 16);11502 const columns = args.lbrace_column | (rbrace_column << 16);
11503 src_locs_buffer[0] = args.lbrace_line;11503 src_locs_buffer[0] = args.lbrace_line;
...@@ -11733,18 +11733,18 @@ const GenZir = struct {...@@ -11733,18 +11733,18 @@ const GenZir = struct {
11733 astgen.extra.appendAssumeCapacity(@intFromEnum(args.init));11733 astgen.extra.appendAssumeCapacity(@intFromEnum(args.init));
11734 }11734 }
1173511735
11736 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);11736 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
11737 astgen.instructions.appendAssumeCapacity(.{11737 astgen.instructions.appendAssumeCapacity(.{
11738 .tag = .extended,11738 .tag = .extended,
11739 .data = .{ .extended = .{11739 .data = .{ .extended = .{
11740 .opcode = .variable,11740 .opcode = .variable,
11741 .small = @bitCast(u16, Zir.Inst.ExtendedVar.Small{11741 .small = @as(u16, @bitCast(Zir.Inst.ExtendedVar.Small{
11742 .has_lib_name = args.lib_name != 0,11742 .has_lib_name = args.lib_name != 0,
11743 .has_align = args.align_inst != .none,11743 .has_align = args.align_inst != .none,
11744 .has_init = args.init != .none,11744 .has_init = args.init != .none,
11745 .is_extern = args.is_extern,11745 .is_extern = args.is_extern,
11746 .is_threadlocal = args.is_threadlocal,11746 .is_threadlocal = args.is_threadlocal,
11747 }),11747 })),
11748 .operand = payload_index,11748 .operand = payload_index,
11749 } },11749 } },
11750 });11750 });
...@@ -11764,7 +11764,7 @@ const GenZir = struct {...@@ -11764,7 +11764,7 @@ const GenZir = struct {
11764 try gz.instructions.ensureUnusedCapacity(gpa, 1);11764 try gz.instructions.ensureUnusedCapacity(gpa, 1);
11765 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);11765 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1176611766
11767 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);11767 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
11768 gz.astgen.instructions.appendAssumeCapacity(.{11768 gz.astgen.instructions.appendAssumeCapacity(.{
11769 .tag = tag,11769 .tag = tag,
11770 .data = .{ .bool_br = .{11770 .data = .{ .bool_br = .{
...@@ -11790,12 +11790,12 @@ const GenZir = struct {...@@ -11790,12 +11790,12 @@ const GenZir = struct {
11790 try astgen.instructions.ensureUnusedCapacity(gpa, 1);11790 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
11791 try astgen.string_bytes.ensureUnusedCapacity(gpa, @sizeOf(std.math.big.Limb) * limbs.len);11791 try astgen.string_bytes.ensureUnusedCapacity(gpa, @sizeOf(std.math.big.Limb) * limbs.len);
1179211792
11793 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);11793 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
11794 astgen.instructions.appendAssumeCapacity(.{11794 astgen.instructions.appendAssumeCapacity(.{
11795 .tag = .int_big,11795 .tag = .int_big,
11796 .data = .{ .str = .{11796 .data = .{ .str = .{
11797 .start = @intCast(u32, astgen.string_bytes.items.len),11797 .start = @as(u32, @intCast(astgen.string_bytes.items.len)),
11798 .len = @intCast(u32, limbs.len),11798 .len = @as(u32, @intCast(limbs.len)),
11799 } },11799 } },
11800 });11800 });
11801 gz.instructions.appendAssumeCapacity(new_index);11801 gz.instructions.appendAssumeCapacity(new_index);
...@@ -11835,7 +11835,7 @@ const GenZir = struct {...@@ -11835,7 +11835,7 @@ const GenZir = struct {
11835 src_node: Ast.Node.Index,11835 src_node: Ast.Node.Index,
11836 ) !Zir.Inst.Index {11836 ) !Zir.Inst.Index {
11837 assert(operand != .none);11837 assert(operand != .none);
11838 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);11838 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
11839 try gz.astgen.instructions.append(gz.astgen.gpa, .{11839 try gz.astgen.instructions.append(gz.astgen.gpa, .{
11840 .tag = tag,11840 .tag = tag,
11841 .data = .{ .un_node = .{11841 .data = .{ .un_node = .{
...@@ -11858,7 +11858,7 @@ const GenZir = struct {...@@ -11858,7 +11858,7 @@ const GenZir = struct {
11858 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);11858 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1185911859
11860 const payload_index = try gz.astgen.addExtra(extra);11860 const payload_index = try gz.astgen.addExtra(extra);
11861 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);11861 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
11862 gz.astgen.instructions.appendAssumeCapacity(.{11862 gz.astgen.instructions.appendAssumeCapacity(.{
11863 .tag = tag,11863 .tag = tag,
11864 .data = .{ .pl_node = .{11864 .data = .{ .pl_node = .{
...@@ -11910,12 +11910,12 @@ const GenZir = struct {...@@ -11910,12 +11910,12 @@ const GenZir = struct {
11910 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{11910 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{
11911 .name = name,11911 .name = name,
11912 .doc_comment = doc_comment_index,11912 .doc_comment = doc_comment_index,
11913 .body_len = @intCast(u32, body_len),11913 .body_len = @as(u32, @intCast(body_len)),
11914 });11914 });
11915 gz.astgen.appendBodyWithFixups(param_body);11915 gz.astgen.appendBodyWithFixups(param_body);
11916 param_gz.unstack();11916 param_gz.unstack();
1191711917
11918 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);11918 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
11919 gz.astgen.instructions.appendAssumeCapacity(.{11919 gz.astgen.instructions.appendAssumeCapacity(.{
11920 .tag = tag,11920 .tag = tag,
11921 .data = .{ .pl_tok = .{11921 .data = .{ .pl_tok = .{
...@@ -11943,7 +11943,7 @@ const GenZir = struct {...@@ -11943,7 +11943,7 @@ const GenZir = struct {
11943 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);11943 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1194411944
11945 const payload_index = try gz.astgen.addExtra(extra);11945 const payload_index = try gz.astgen.addExtra(extra);
11946 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);11946 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
11947 gz.astgen.instructions.appendAssumeCapacity(.{11947 gz.astgen.instructions.appendAssumeCapacity(.{
11948 .tag = .extended,11948 .tag = .extended,
11949 .data = .{ .extended = .{11949 .data = .{ .extended = .{
...@@ -11975,12 +11975,12 @@ const GenZir = struct {...@@ -11975,12 +11975,12 @@ const GenZir = struct {
11975 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.NodeMultiOp{11975 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.NodeMultiOp{
11976 .src_node = gz.nodeIndexToRelative(node),11976 .src_node = gz.nodeIndexToRelative(node),
11977 });11977 });
11978 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);11978 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
11979 astgen.instructions.appendAssumeCapacity(.{11979 astgen.instructions.appendAssumeCapacity(.{
11980 .tag = .extended,11980 .tag = .extended,
11981 .data = .{ .extended = .{11981 .data = .{ .extended = .{
11982 .opcode = opcode,11982 .opcode = opcode,
11983 .small = @intCast(u16, operands.len),11983 .small = @as(u16, @intCast(operands.len)),
11984 .operand = payload_index,11984 .operand = payload_index,
11985 } },11985 } },
11986 });11986 });
...@@ -12000,12 +12000,12 @@ const GenZir = struct {...@@ -12000,12 +12000,12 @@ const GenZir = struct {
1200012000
12001 try gz.instructions.ensureUnusedCapacity(gpa, 1);12001 try gz.instructions.ensureUnusedCapacity(gpa, 1);
12002 try astgen.instructions.ensureUnusedCapacity(gpa, 1);12002 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
12003 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);12003 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
12004 astgen.instructions.appendAssumeCapacity(.{12004 astgen.instructions.appendAssumeCapacity(.{
12005 .tag = .extended,12005 .tag = .extended,
12006 .data = .{ .extended = .{12006 .data = .{ .extended = .{
12007 .opcode = opcode,12007 .opcode = opcode,
12008 .small = @intCast(u16, trailing_len),12008 .small = @as(u16, @intCast(trailing_len)),
12009 .operand = payload_index,12009 .operand = payload_index,
12010 } },12010 } },
12011 });12011 });
...@@ -12038,7 +12038,7 @@ const GenZir = struct {...@@ -12038,7 +12038,7 @@ const GenZir = struct {
12038 abs_tok_index: Ast.TokenIndex,12038 abs_tok_index: Ast.TokenIndex,
12039 ) !Zir.Inst.Index {12039 ) !Zir.Inst.Index {
12040 const astgen = gz.astgen;12040 const astgen = gz.astgen;
12041 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);12041 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
12042 assert(operand != .none);12042 assert(operand != .none);
12043 try astgen.instructions.append(astgen.gpa, .{12043 try astgen.instructions.append(astgen.gpa, .{
12044 .tag = tag,12044 .tag = tag,
...@@ -12121,7 +12121,7 @@ const GenZir = struct {...@@ -12121,7 +12121,7 @@ const GenZir = struct {
12121 .operand_src_node = Zir.Inst.Break.no_src_node,12121 .operand_src_node = Zir.Inst.Break.no_src_node,
12122 };12122 };
12123 const payload_index = try gz.astgen.addExtra(extra);12123 const payload_index = try gz.astgen.addExtra(extra);
12124 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);12124 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
12125 gz.astgen.instructions.appendAssumeCapacity(.{12125 gz.astgen.instructions.appendAssumeCapacity(.{
12126 .tag = tag,12126 .tag = tag,
12127 .data = .{ .@"break" = .{12127 .data = .{ .@"break" = .{
...@@ -12147,7 +12147,7 @@ const GenZir = struct {...@@ -12147,7 +12147,7 @@ const GenZir = struct {
12147 .operand_src_node = Zir.Inst.Break.no_src_node,12147 .operand_src_node = Zir.Inst.Break.no_src_node,
12148 };12148 };
12149 const payload_index = try gz.astgen.addExtra(extra);12149 const payload_index = try gz.astgen.addExtra(extra);
12150 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);12150 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
12151 gz.astgen.instructions.appendAssumeCapacity(.{12151 gz.astgen.instructions.appendAssumeCapacity(.{
12152 .tag = tag,12152 .tag = tag,
12153 .data = .{ .@"break" = .{12153 .data = .{ .@"break" = .{
...@@ -12174,7 +12174,7 @@ const GenZir = struct {...@@ -12174,7 +12174,7 @@ const GenZir = struct {
12174 .operand_src_node = gz.nodeIndexToRelative(operand_src_node),12174 .operand_src_node = gz.nodeIndexToRelative(operand_src_node),
12175 };12175 };
12176 const payload_index = try gz.astgen.addExtra(extra);12176 const payload_index = try gz.astgen.addExtra(extra);
12177 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);12177 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
12178 gz.astgen.instructions.appendAssumeCapacity(.{12178 gz.astgen.instructions.appendAssumeCapacity(.{
12179 .tag = tag,12179 .tag = tag,
12180 .data = .{ .@"break" = .{12180 .data = .{ .@"break" = .{
...@@ -12201,7 +12201,7 @@ const GenZir = struct {...@@ -12201,7 +12201,7 @@ const GenZir = struct {
12201 .operand_src_node = gz.nodeIndexToRelative(operand_src_node),12201 .operand_src_node = gz.nodeIndexToRelative(operand_src_node),
12202 };12202 };
12203 const payload_index = try gz.astgen.addExtra(extra);12203 const payload_index = try gz.astgen.addExtra(extra);
12204 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);12204 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
12205 gz.astgen.instructions.appendAssumeCapacity(.{12205 gz.astgen.instructions.appendAssumeCapacity(.{
12206 .tag = tag,12206 .tag = tag,
12207 .data = .{ .@"break" = .{12207 .data = .{ .@"break" = .{
...@@ -12293,7 +12293,7 @@ const GenZir = struct {...@@ -12293,7 +12293,7 @@ const GenZir = struct {
12293 .data = .{ .extended = .{12293 .data = .{ .extended = .{
12294 .opcode = opcode,12294 .opcode = opcode,
12295 .small = undefined,12295 .small = undefined,
12296 .operand = @bitCast(u32, gz.nodeIndexToRelative(src_node)),12296 .operand = @as(u32, @bitCast(gz.nodeIndexToRelative(src_node))),
12297 } },12297 } },
12298 });12298 });
12299 }12299 }
...@@ -12336,7 +12336,7 @@ const GenZir = struct {...@@ -12336,7 +12336,7 @@ const GenZir = struct {
12336 const is_comptime: u4 = @intFromBool(args.is_comptime);12336 const is_comptime: u4 = @intFromBool(args.is_comptime);
12337 const small: u16 = has_type | (has_align << 1) | (is_const << 2) | (is_comptime << 3);12337 const small: u16 = has_type | (has_align << 1) | (is_const << 2) | (is_comptime << 3);
1233812338
12339 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);12339 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
12340 astgen.instructions.appendAssumeCapacity(.{12340 astgen.instructions.appendAssumeCapacity(.{
12341 .tag = .extended,12341 .tag = .extended,
12342 .data = .{ .extended = .{12342 .data = .{ .extended = .{
...@@ -12390,12 +12390,12 @@ const GenZir = struct {...@@ -12390,12 +12390,12 @@ const GenZir = struct {
12390 // * 0b000000XX_XXX00000 - `inputs_len`.12390 // * 0b000000XX_XXX00000 - `inputs_len`.
12391 // * 0b0XXXXX00_00000000 - `clobbers_len`.12391 // * 0b0XXXXX00_00000000 - `clobbers_len`.
12392 // * 0bX0000000_00000000 - is volatile12392 // * 0bX0000000_00000000 - is volatile
12393 const small: u16 = @intCast(u16, args.outputs.len) |12393 const small: u16 = @as(u16, @intCast(args.outputs.len)) |
12394 @intCast(u16, args.inputs.len << 5) |12394 @as(u16, @intCast(args.inputs.len << 5)) |
12395 @intCast(u16, args.clobbers.len << 10) |12395 @as(u16, @intCast(args.clobbers.len << 10)) |
12396 (@as(u16, @intFromBool(args.is_volatile)) << 15);12396 (@as(u16, @intFromBool(args.is_volatile)) << 15);
1239712397
12398 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);12398 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
12399 astgen.instructions.appendAssumeCapacity(.{12399 astgen.instructions.appendAssumeCapacity(.{
12400 .tag = .extended,12400 .tag = .extended,
12401 .data = .{ .extended = .{12401 .data = .{ .extended = .{
...@@ -12412,7 +12412,7 @@ const GenZir = struct {...@@ -12412,7 +12412,7 @@ const GenZir = struct {
12412 /// Does *not* append the block instruction to the scope.12412 /// Does *not* append the block instruction to the scope.
12413 /// Leaves the `payload_index` field undefined.12413 /// Leaves the `payload_index` field undefined.
12414 fn makeBlockInst(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {12414 fn makeBlockInst(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {
12415 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);12415 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
12416 const gpa = gz.astgen.gpa;12416 const gpa = gz.astgen.gpa;
12417 try gz.astgen.instructions.append(gpa, .{12417 try gz.astgen.instructions.append(gpa, .{
12418 .tag = tag,12418 .tag = tag,
...@@ -12429,7 +12429,7 @@ const GenZir = struct {...@@ -12429,7 +12429,7 @@ const GenZir = struct {
12429 fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {12429 fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {
12430 const gpa = gz.astgen.gpa;12430 const gpa = gz.astgen.gpa;
12431 try gz.instructions.ensureUnusedCapacity(gpa, 1);12431 try gz.instructions.ensureUnusedCapacity(gpa, 1);
12432 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);12432 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
12433 try gz.astgen.instructions.append(gpa, .{12433 try gz.astgen.instructions.append(gpa, .{
12434 .tag = tag,12434 .tag = tag,
12435 .data = .{ .pl_node = .{12435 .data = .{ .pl_node = .{
...@@ -12456,11 +12456,11 @@ const GenZir = struct {...@@ -12456,11 +12456,11 @@ const GenZir = struct {
12456 const gpa = astgen.gpa;12456 const gpa = astgen.gpa;
1245712457
12458 try astgen.extra.ensureUnusedCapacity(gpa, 6);12458 try astgen.extra.ensureUnusedCapacity(gpa, 6);
12459 const payload_index = @intCast(u32, astgen.extra.items.len);12459 const payload_index = @as(u32, @intCast(astgen.extra.items.len));
1246012460
12461 if (args.src_node != 0) {12461 if (args.src_node != 0) {
12462 const node_offset = gz.nodeIndexToRelative(args.src_node);12462 const node_offset = gz.nodeIndexToRelative(args.src_node);
12463 astgen.extra.appendAssumeCapacity(@bitCast(u32, node_offset));12463 astgen.extra.appendAssumeCapacity(@as(u32, @bitCast(node_offset)));
12464 }12464 }
12465 if (args.fields_len != 0) {12465 if (args.fields_len != 0) {
12466 astgen.extra.appendAssumeCapacity(args.fields_len);12466 astgen.extra.appendAssumeCapacity(args.fields_len);
...@@ -12478,7 +12478,7 @@ const GenZir = struct {...@@ -12478,7 +12478,7 @@ const GenZir = struct {
12478 .tag = .extended,12478 .tag = .extended,
12479 .data = .{ .extended = .{12479 .data = .{ .extended = .{
12480 .opcode = .struct_decl,12480 .opcode = .struct_decl,
12481 .small = @bitCast(u16, Zir.Inst.StructDecl.Small{12481 .small = @as(u16, @bitCast(Zir.Inst.StructDecl.Small{
12482 .has_src_node = args.src_node != 0,12482 .has_src_node = args.src_node != 0,
12483 .has_fields_len = args.fields_len != 0,12483 .has_fields_len = args.fields_len != 0,
12484 .has_decls_len = args.decls_len != 0,12484 .has_decls_len = args.decls_len != 0,
...@@ -12488,7 +12488,7 @@ const GenZir = struct {...@@ -12488,7 +12488,7 @@ const GenZir = struct {
12488 .is_tuple = args.is_tuple,12488 .is_tuple = args.is_tuple,
12489 .name_strategy = gz.anon_name_strategy,12489 .name_strategy = gz.anon_name_strategy,
12490 .layout = args.layout,12490 .layout = args.layout,
12491 }),12491 })),
12492 .operand = payload_index,12492 .operand = payload_index,
12493 } },12493 } },
12494 });12494 });
...@@ -12507,11 +12507,11 @@ const GenZir = struct {...@@ -12507,11 +12507,11 @@ const GenZir = struct {
12507 const gpa = astgen.gpa;12507 const gpa = astgen.gpa;
1250812508
12509 try astgen.extra.ensureUnusedCapacity(gpa, 5);12509 try astgen.extra.ensureUnusedCapacity(gpa, 5);
12510 const payload_index = @intCast(u32, astgen.extra.items.len);12510 const payload_index = @as(u32, @intCast(astgen.extra.items.len));
1251112511
12512 if (args.src_node != 0) {12512 if (args.src_node != 0) {
12513 const node_offset = gz.nodeIndexToRelative(args.src_node);12513 const node_offset = gz.nodeIndexToRelative(args.src_node);
12514 astgen.extra.appendAssumeCapacity(@bitCast(u32, node_offset));12514 astgen.extra.appendAssumeCapacity(@as(u32, @bitCast(node_offset)));
12515 }12515 }
12516 if (args.tag_type != .none) {12516 if (args.tag_type != .none) {
12517 astgen.extra.appendAssumeCapacity(@intFromEnum(args.tag_type));12517 astgen.extra.appendAssumeCapacity(@intFromEnum(args.tag_type));
...@@ -12529,7 +12529,7 @@ const GenZir = struct {...@@ -12529,7 +12529,7 @@ const GenZir = struct {
12529 .tag = .extended,12529 .tag = .extended,
12530 .data = .{ .extended = .{12530 .data = .{ .extended = .{
12531 .opcode = .union_decl,12531 .opcode = .union_decl,
12532 .small = @bitCast(u16, Zir.Inst.UnionDecl.Small{12532 .small = @as(u16, @bitCast(Zir.Inst.UnionDecl.Small{
12533 .has_src_node = args.src_node != 0,12533 .has_src_node = args.src_node != 0,
12534 .has_tag_type = args.tag_type != .none,12534 .has_tag_type = args.tag_type != .none,
12535 .has_body_len = args.body_len != 0,12535 .has_body_len = args.body_len != 0,
...@@ -12538,7 +12538,7 @@ const GenZir = struct {...@@ -12538,7 +12538,7 @@ const GenZir = struct {
12538 .name_strategy = gz.anon_name_strategy,12538 .name_strategy = gz.anon_name_strategy,
12539 .layout = args.layout,12539 .layout = args.layout,
12540 .auto_enum_tag = args.auto_enum_tag,12540 .auto_enum_tag = args.auto_enum_tag,
12541 }),12541 })),
12542 .operand = payload_index,12542 .operand = payload_index,
12543 } },12543 } },
12544 });12544 });
...@@ -12556,11 +12556,11 @@ const GenZir = struct {...@@ -12556,11 +12556,11 @@ const GenZir = struct {
12556 const gpa = astgen.gpa;12556 const gpa = astgen.gpa;
1255712557
12558 try astgen.extra.ensureUnusedCapacity(gpa, 5);12558 try astgen.extra.ensureUnusedCapacity(gpa, 5);
12559 const payload_index = @intCast(u32, astgen.extra.items.len);12559 const payload_index = @as(u32, @intCast(astgen.extra.items.len));
1256012560
12561 if (args.src_node != 0) {12561 if (args.src_node != 0) {
12562 const node_offset = gz.nodeIndexToRelative(args.src_node);12562 const node_offset = gz.nodeIndexToRelative(args.src_node);
12563 astgen.extra.appendAssumeCapacity(@bitCast(u32, node_offset));12563 astgen.extra.appendAssumeCapacity(@as(u32, @bitCast(node_offset)));
12564 }12564 }
12565 if (args.tag_type != .none) {12565 if (args.tag_type != .none) {
12566 astgen.extra.appendAssumeCapacity(@intFromEnum(args.tag_type));12566 astgen.extra.appendAssumeCapacity(@intFromEnum(args.tag_type));
...@@ -12578,7 +12578,7 @@ const GenZir = struct {...@@ -12578,7 +12578,7 @@ const GenZir = struct {
12578 .tag = .extended,12578 .tag = .extended,
12579 .data = .{ .extended = .{12579 .data = .{ .extended = .{
12580 .opcode = .enum_decl,12580 .opcode = .enum_decl,
12581 .small = @bitCast(u16, Zir.Inst.EnumDecl.Small{12581 .small = @as(u16, @bitCast(Zir.Inst.EnumDecl.Small{
12582 .has_src_node = args.src_node != 0,12582 .has_src_node = args.src_node != 0,
12583 .has_tag_type = args.tag_type != .none,12583 .has_tag_type = args.tag_type != .none,
12584 .has_body_len = args.body_len != 0,12584 .has_body_len = args.body_len != 0,
...@@ -12586,7 +12586,7 @@ const GenZir = struct {...@@ -12586,7 +12586,7 @@ const GenZir = struct {
12586 .has_decls_len = args.decls_len != 0,12586 .has_decls_len = args.decls_len != 0,
12587 .name_strategy = gz.anon_name_strategy,12587 .name_strategy = gz.anon_name_strategy,
12588 .nonexhaustive = args.nonexhaustive,12588 .nonexhaustive = args.nonexhaustive,
12589 }),12589 })),
12590 .operand = payload_index,12590 .operand = payload_index,
12591 } },12591 } },
12592 });12592 });
...@@ -12600,11 +12600,11 @@ const GenZir = struct {...@@ -12600,11 +12600,11 @@ const GenZir = struct {
12600 const gpa = astgen.gpa;12600 const gpa = astgen.gpa;
1260112601
12602 try astgen.extra.ensureUnusedCapacity(gpa, 2);12602 try astgen.extra.ensureUnusedCapacity(gpa, 2);
12603 const payload_index = @intCast(u32, astgen.extra.items.len);12603 const payload_index = @as(u32, @intCast(astgen.extra.items.len));
1260412604
12605 if (args.src_node != 0) {12605 if (args.src_node != 0) {
12606 const node_offset = gz.nodeIndexToRelative(args.src_node);12606 const node_offset = gz.nodeIndexToRelative(args.src_node);
12607 astgen.extra.appendAssumeCapacity(@bitCast(u32, node_offset));12607 astgen.extra.appendAssumeCapacity(@as(u32, @bitCast(node_offset)));
12608 }12608 }
12609 if (args.decls_len != 0) {12609 if (args.decls_len != 0) {
12610 astgen.extra.appendAssumeCapacity(args.decls_len);12610 astgen.extra.appendAssumeCapacity(args.decls_len);
...@@ -12613,11 +12613,11 @@ const GenZir = struct {...@@ -12613,11 +12613,11 @@ const GenZir = struct {
12613 .tag = .extended,12613 .tag = .extended,
12614 .data = .{ .extended = .{12614 .data = .{ .extended = .{
12615 .opcode = .opaque_decl,12615 .opcode = .opaque_decl,
12616 .small = @bitCast(u16, Zir.Inst.OpaqueDecl.Small{12616 .small = @as(u16, @bitCast(Zir.Inst.OpaqueDecl.Small{
12617 .has_src_node = args.src_node != 0,12617 .has_src_node = args.src_node != 0,
12618 .has_decls_len = args.decls_len != 0,12618 .has_decls_len = args.decls_len != 0,
12619 .name_strategy = gz.anon_name_strategy,12619 .name_strategy = gz.anon_name_strategy,
12620 }),12620 })),
12621 .operand = payload_index,12621 .operand = payload_index,
12622 } },12622 } },
12623 });12623 });
...@@ -12632,7 +12632,7 @@ const GenZir = struct {...@@ -12632,7 +12632,7 @@ const GenZir = struct {
12632 try gz.instructions.ensureUnusedCapacity(gpa, 1);12632 try gz.instructions.ensureUnusedCapacity(gpa, 1);
12633 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);12633 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1263412634
12635 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);12635 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
12636 gz.astgen.instructions.appendAssumeCapacity(inst);12636 gz.astgen.instructions.appendAssumeCapacity(inst);
12637 gz.instructions.appendAssumeCapacity(new_index);12637 gz.instructions.appendAssumeCapacity(new_index);
12638 return new_index;12638 return new_index;
...@@ -12643,7 +12643,7 @@ const GenZir = struct {...@@ -12643,7 +12643,7 @@ const GenZir = struct {
12643 try gz.instructions.ensureUnusedCapacity(gpa, 1);12643 try gz.instructions.ensureUnusedCapacity(gpa, 1);
12644 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);12644 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1264512645
12646 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);12646 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
12647 gz.astgen.instructions.len += 1;12647 gz.astgen.instructions.len += 1;
12648 gz.instructions.appendAssumeCapacity(new_index);12648 gz.instructions.appendAssumeCapacity(new_index);
12649 return new_index;12649 return new_index;
...@@ -12695,7 +12695,7 @@ const GenZir = struct {...@@ -12695,7 +12695,7 @@ const GenZir = struct {
12695 return;12695 return;
12696 }12696 }
1269712697
12698 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);12698 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
12699 try gz.astgen.instructions.append(gpa, .{ .tag = .dbg_block_end, .data = undefined });12699 try gz.astgen.instructions.append(gpa, .{ .tag = .dbg_block_end, .data = undefined });
12700 try gz.instructions.append(gpa, new_index);12700 try gz.instructions.append(gpa, new_index);
12701 }12701 }
...@@ -12704,7 +12704,7 @@ const GenZir = struct {...@@ -12704,7 +12704,7 @@ const GenZir = struct {
12704/// This can only be for short-lived references; the memory becomes invalidated12704/// This can only be for short-lived references; the memory becomes invalidated
12705/// when another string is added.12705/// when another string is added.
12706fn nullTerminatedString(astgen: AstGen, index: usize) [*:0]const u8 {12706fn nullTerminatedString(astgen: AstGen, index: usize) [*:0]const u8 {
12707 return @ptrCast([*:0]const u8, astgen.string_bytes.items.ptr) + index;12707 return @as([*:0]const u8, @ptrCast(astgen.string_bytes.items.ptr)) + index;
12708}12708}
1270912709
12710/// Local variables shadowing detection, including function parameters.12710/// Local variables shadowing detection, including function parameters.
...@@ -12983,7 +12983,7 @@ fn isInferred(astgen: *AstGen, ref: Zir.Inst.Ref) bool {...@@ -12983,7 +12983,7 @@ fn isInferred(astgen: *AstGen, ref: Zir.Inst.Ref) bool {
12983 .extended => {12983 .extended => {
12984 const zir_data = astgen.instructions.items(.data);12984 const zir_data = astgen.instructions.items(.data);
12985 if (zir_data[inst].extended.opcode != .alloc) return false;12985 if (zir_data[inst].extended.opcode != .alloc) return false;
12986 const small = @bitCast(Zir.Inst.AllocExtended.Small, zir_data[inst].extended.small);12986 const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(zir_data[inst].extended.small));
12987 return !small.has_type;12987 return !small.has_type;
12988 },12988 },
1298912989
...@@ -13027,7 +13027,7 @@ fn countBodyLenAfterFixups(astgen: *AstGen, body: []const Zir.Inst.Index) u32 {...@@ -13027,7 +13027,7 @@ fn countBodyLenAfterFixups(astgen: *AstGen, body: []const Zir.Inst.Index) u32 {
13027 check_inst = ref_inst;13027 check_inst = ref_inst;
13028 }13028 }
13029 }13029 }
13030 return @intCast(u32, count);13030 return @as(u32, @intCast(count));
13031}13031}
1303213032
13033fn emitDbgStmt(gz: *GenZir, lc: LineColumn) !void {13033fn emitDbgStmt(gz: *GenZir, lc: LineColumn) !void {
...@@ -13059,7 +13059,7 @@ fn lowerAstErrors(astgen: *AstGen) !void {...@@ -13059,7 +13059,7 @@ fn lowerAstErrors(astgen: *AstGen) !void {
1305913059
13060 if (token_tags[parse_err.token + @intFromBool(parse_err.token_is_prev)] == .invalid) {13060 if (token_tags[parse_err.token + @intFromBool(parse_err.token_is_prev)] == .invalid) {
13061 const tok = parse_err.token + @intFromBool(parse_err.token_is_prev);13061 const tok = parse_err.token + @intFromBool(parse_err.token_is_prev);
13062 const bad_off = @intCast(u32, tree.tokenSlice(parse_err.token + @intFromBool(parse_err.token_is_prev)).len);13062 const bad_off = @as(u32, @intCast(tree.tokenSlice(parse_err.token + @intFromBool(parse_err.token_is_prev)).len));
13063 const byte_abs = token_starts[parse_err.token + @intFromBool(parse_err.token_is_prev)] + bad_off;13063 const byte_abs = token_starts[parse_err.token + @intFromBool(parse_err.token_is_prev)] + bad_off;
13064 try notes.append(gpa, try astgen.errNoteTokOff(tok, bad_off, "invalid byte: '{'}'", .{13064 try notes.append(gpa, try astgen.errNoteTokOff(tok, bad_off, "invalid byte: '{'}'", .{
13065 std.zig.fmtEscapes(tree.source[byte_abs..][0..1]),13065 std.zig.fmtEscapes(tree.source[byte_abs..][0..1]),
src/Autodoc.zig+49-49
...@@ -110,7 +110,7 @@ pub fn generateZirData(self: *Autodoc) !void {...@@ -110,7 +110,7 @@ pub fn generateZirData(self: *Autodoc) !void {
110 comptime std.debug.assert(@intFromEnum(InternPool.Index.first_type) == 0);110 comptime std.debug.assert(@intFromEnum(InternPool.Index.first_type) == 0);
111 var i: u32 = 0;111 var i: u32 = 0;
112 while (i <= @intFromEnum(InternPool.Index.last_type)) : (i += 1) {112 while (i <= @intFromEnum(InternPool.Index.last_type)) : (i += 1) {
113 const ip_index = @enumFromInt(InternPool.Index, i);113 const ip_index = @as(InternPool.Index, @enumFromInt(i));
114 var tmpbuf = std.ArrayList(u8).init(self.arena);114 var tmpbuf = std.ArrayList(u8).init(self.arena);
115 if (ip_index == .generic_poison_type) {115 if (ip_index == .generic_poison_type) {
116 // Not a real type, doesn't have a normal name116 // Not a real type, doesn't have a normal name
...@@ -1669,7 +1669,7 @@ fn walkInstruction(...@@ -1669,7 +1669,7 @@ fn walkInstruction(
1669 // present in json1669 // present in json
1670 var sentinel: ?DocData.Expr = null;1670 var sentinel: ?DocData.Expr = null;
1671 if (ptr.flags.has_sentinel) {1671 if (ptr.flags.has_sentinel) {
1672 const ref = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);1672 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
1673 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);1673 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);
1674 sentinel = ref_result.expr;1674 sentinel = ref_result.expr;
1675 extra_index += 1;1675 extra_index += 1;
...@@ -1677,21 +1677,21 @@ fn walkInstruction(...@@ -1677,21 +1677,21 @@ fn walkInstruction(
16771677
1678 var @"align": ?DocData.Expr = null;1678 var @"align": ?DocData.Expr = null;
1679 if (ptr.flags.has_align) {1679 if (ptr.flags.has_align) {
1680 const ref = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);1680 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
1681 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);1681 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);
1682 @"align" = ref_result.expr;1682 @"align" = ref_result.expr;
1683 extra_index += 1;1683 extra_index += 1;
1684 }1684 }
1685 var address_space: ?DocData.Expr = null;1685 var address_space: ?DocData.Expr = null;
1686 if (ptr.flags.has_addrspace) {1686 if (ptr.flags.has_addrspace) {
1687 const ref = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);1687 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
1688 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);1688 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);
1689 address_space = ref_result.expr;1689 address_space = ref_result.expr;
1690 extra_index += 1;1690 extra_index += 1;
1691 }1691 }
1692 var bit_start: ?DocData.Expr = null;1692 var bit_start: ?DocData.Expr = null;
1693 if (ptr.flags.has_bit_range) {1693 if (ptr.flags.has_bit_range) {
1694 const ref = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);1694 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
1695 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);1695 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);
1696 address_space = ref_result.expr;1696 address_space = ref_result.expr;
1697 extra_index += 1;1697 extra_index += 1;
...@@ -1699,7 +1699,7 @@ fn walkInstruction(...@@ -1699,7 +1699,7 @@ fn walkInstruction(
16991699
1700 var host_size: ?DocData.Expr = null;1700 var host_size: ?DocData.Expr = null;
1701 if (ptr.flags.has_bit_range) {1701 if (ptr.flags.has_bit_range) {
1702 const ref = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);1702 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
1703 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);1703 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);
1704 host_size = ref_result.expr;1704 host_size = ref_result.expr;
1705 }1705 }
...@@ -2549,11 +2549,11 @@ fn walkInstruction(...@@ -2549,11 +2549,11 @@ fn walkInstruction(
2549 .enclosing_type = type_slot_index,2549 .enclosing_type = type_slot_index,
2550 };2550 };
25512551
2552 const small = @bitCast(Zir.Inst.OpaqueDecl.Small, extended.small);2552 const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small));
2553 var extra_index: usize = extended.operand;2553 var extra_index: usize = extended.operand;
25542554
2555 const src_node: ?i32 = if (small.has_src_node) blk: {2555 const src_node: ?i32 = if (small.has_src_node) blk: {
2556 const src_node = @bitCast(i32, file.zir.extra[extra_index]);2556 const src_node = @as(i32, @bitCast(file.zir.extra[extra_index]));
2557 extra_index += 1;2557 extra_index += 1;
2558 break :blk src_node;2558 break :blk src_node;
2559 } else null;2559 } else null;
...@@ -2606,7 +2606,7 @@ fn walkInstruction(...@@ -2606,7 +2606,7 @@ fn walkInstruction(
2606 .variable => {2606 .variable => {
2607 const extra = file.zir.extraData(Zir.Inst.ExtendedVar, extended.operand);2607 const extra = file.zir.extraData(Zir.Inst.ExtendedVar, extended.operand);
26082608
2609 const small = @bitCast(Zir.Inst.ExtendedVar.Small, extended.small);2609 const small = @as(Zir.Inst.ExtendedVar.Small, @bitCast(extended.small));
2610 var extra_index: usize = extra.end;2610 var extra_index: usize = extra.end;
2611 if (small.has_lib_name) extra_index += 1;2611 if (small.has_lib_name) extra_index += 1;
2612 if (small.has_align) extra_index += 1;2612 if (small.has_align) extra_index += 1;
...@@ -2619,7 +2619,7 @@ fn walkInstruction(...@@ -2619,7 +2619,7 @@ fn walkInstruction(
2619 };2619 };
26202620
2621 if (small.has_init) {2621 if (small.has_init) {
2622 const var_init_ref = @enumFromInt(Ref, file.zir.extra[extra_index]);2622 const var_init_ref = @as(Ref, @enumFromInt(file.zir.extra[extra_index]));
2623 const var_init = try self.walkRef(file, parent_scope, parent_src, var_init_ref, need_type);2623 const var_init = try self.walkRef(file, parent_scope, parent_src, var_init_ref, need_type);
2624 value.expr = var_init.expr;2624 value.expr = var_init.expr;
2625 value.typeRef = var_init.typeRef;2625 value.typeRef = var_init.typeRef;
...@@ -2636,11 +2636,11 @@ fn walkInstruction(...@@ -2636,11 +2636,11 @@ fn walkInstruction(
2636 .enclosing_type = type_slot_index,2636 .enclosing_type = type_slot_index,
2637 };2637 };
26382638
2639 const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small);2639 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));
2640 var extra_index: usize = extended.operand;2640 var extra_index: usize = extended.operand;
26412641
2642 const src_node: ?i32 = if (small.has_src_node) blk: {2642 const src_node: ?i32 = if (small.has_src_node) blk: {
2643 const src_node = @bitCast(i32, file.zir.extra[extra_index]);2643 const src_node = @as(i32, @bitCast(file.zir.extra[extra_index]));
2644 extra_index += 1;2644 extra_index += 1;
2645 break :blk src_node;2645 break :blk src_node;
2646 } else null;2646 } else null;
...@@ -2655,7 +2655,7 @@ fn walkInstruction(...@@ -2655,7 +2655,7 @@ fn walkInstruction(
2655 const tag_type_ref: ?Ref = if (small.has_tag_type) blk: {2655 const tag_type_ref: ?Ref = if (small.has_tag_type) blk: {
2656 const tag_type = file.zir.extra[extra_index];2656 const tag_type = file.zir.extra[extra_index];
2657 extra_index += 1;2657 extra_index += 1;
2658 const tag_ref = @enumFromInt(Ref, tag_type);2658 const tag_ref = @as(Ref, @enumFromInt(tag_type));
2659 break :blk tag_ref;2659 break :blk tag_ref;
2660 } else null;2660 } else null;
26612661
...@@ -2763,11 +2763,11 @@ fn walkInstruction(...@@ -2763,11 +2763,11 @@ fn walkInstruction(
2763 .enclosing_type = type_slot_index,2763 .enclosing_type = type_slot_index,
2764 };2764 };
27652765
2766 const small = @bitCast(Zir.Inst.EnumDecl.Small, extended.small);2766 const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small));
2767 var extra_index: usize = extended.operand;2767 var extra_index: usize = extended.operand;
27682768
2769 const src_node: ?i32 = if (small.has_src_node) blk: {2769 const src_node: ?i32 = if (small.has_src_node) blk: {
2770 const src_node = @bitCast(i32, file.zir.extra[extra_index]);2770 const src_node = @as(i32, @bitCast(file.zir.extra[extra_index]));
2771 extra_index += 1;2771 extra_index += 1;
2772 break :blk src_node;2772 break :blk src_node;
2773 } else null;2773 } else null;
...@@ -2780,7 +2780,7 @@ fn walkInstruction(...@@ -2780,7 +2780,7 @@ fn walkInstruction(
2780 const tag_type: ?DocData.Expr = if (small.has_tag_type) blk: {2780 const tag_type: ?DocData.Expr = if (small.has_tag_type) blk: {
2781 const tag_type = file.zir.extra[extra_index];2781 const tag_type = file.zir.extra[extra_index];
2782 extra_index += 1;2782 extra_index += 1;
2783 const tag_ref = @enumFromInt(Ref, tag_type);2783 const tag_ref = @as(Ref, @enumFromInt(tag_type));
2784 const wr = try self.walkRef(file, parent_scope, parent_src, tag_ref, false);2784 const wr = try self.walkRef(file, parent_scope, parent_src, tag_ref, false);
2785 break :blk wr.expr;2785 break :blk wr.expr;
2786 } else null;2786 } else null;
...@@ -2826,7 +2826,7 @@ fn walkInstruction(...@@ -2826,7 +2826,7 @@ fn walkInstruction(
2826 bit_bag_idx += 1;2826 bit_bag_idx += 1;
2827 }2827 }
28282828
2829 const has_value = @truncate(u1, cur_bit_bag) != 0;2829 const has_value = @as(u1, @truncate(cur_bit_bag)) != 0;
2830 cur_bit_bag >>= 1;2830 cur_bit_bag >>= 1;
28312831
2832 const field_name_index = file.zir.extra[extra_index];2832 const field_name_index = file.zir.extra[extra_index];
...@@ -2838,7 +2838,7 @@ fn walkInstruction(...@@ -2838,7 +2838,7 @@ fn walkInstruction(
2838 const value_expr: ?DocData.Expr = if (has_value) blk: {2838 const value_expr: ?DocData.Expr = if (has_value) blk: {
2839 const value_ref = file.zir.extra[extra_index];2839 const value_ref = file.zir.extra[extra_index];
2840 extra_index += 1;2840 extra_index += 1;
2841 const value = try self.walkRef(file, &scope, src_info, @enumFromInt(Ref, value_ref), false);2841 const value = try self.walkRef(file, &scope, src_info, @as(Ref, @enumFromInt(value_ref)), false);
2842 break :blk value.expr;2842 break :blk value.expr;
2843 } else null;2843 } else null;
2844 try field_values.append(self.arena, value_expr);2844 try field_values.append(self.arena, value_expr);
...@@ -2899,11 +2899,11 @@ fn walkInstruction(...@@ -2899,11 +2899,11 @@ fn walkInstruction(
2899 .enclosing_type = type_slot_index,2899 .enclosing_type = type_slot_index,
2900 };2900 };
29012901
2902 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);2902 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
2903 var extra_index: usize = extended.operand;2903 var extra_index: usize = extended.operand;
29042904
2905 const src_node: ?i32 = if (small.has_src_node) blk: {2905 const src_node: ?i32 = if (small.has_src_node) blk: {
2906 const src_node = @bitCast(i32, file.zir.extra[extra_index]);2906 const src_node = @as(i32, @bitCast(file.zir.extra[extra_index]));
2907 extra_index += 1;2907 extra_index += 1;
2908 break :blk src_node;2908 break :blk src_node;
2909 } else null;2909 } else null;
...@@ -2927,7 +2927,7 @@ fn walkInstruction(...@@ -2927,7 +2927,7 @@ fn walkInstruction(
2927 const backing_int_body_len = file.zir.extra[extra_index];2927 const backing_int_body_len = file.zir.extra[extra_index];
2928 extra_index += 1; // backing_int_body_len2928 extra_index += 1; // backing_int_body_len
2929 if (backing_int_body_len == 0) {2929 if (backing_int_body_len == 0) {
2930 const backing_int_ref = @enumFromInt(Ref, file.zir.extra[extra_index]);2930 const backing_int_ref = @as(Ref, @enumFromInt(file.zir.extra[extra_index]));
2931 const backing_int_res = try self.walkRef(file, &scope, src_info, backing_int_ref, true);2931 const backing_int_res = try self.walkRef(file, &scope, src_info, backing_int_ref, true);
2932 backing_int = backing_int_res.expr;2932 backing_int = backing_int_res.expr;
2933 extra_index += 1; // backing_int_ref2933 extra_index += 1; // backing_int_ref
...@@ -3154,7 +3154,7 @@ fn analyzeAllDecls(...@@ -3154,7 +3154,7 @@ fn analyzeAllDecls(
3154 priv_decl_indexes: *std.ArrayListUnmanaged(usize),3154 priv_decl_indexes: *std.ArrayListUnmanaged(usize),
3155) AutodocErrors!usize {3155) AutodocErrors!usize {
3156 const first_decl_indexes_slot = decl_indexes.items.len;3156 const first_decl_indexes_slot = decl_indexes.items.len;
3157 const original_it = file.zir.declIterator(@intCast(u32, parent_inst_index));3157 const original_it = file.zir.declIterator(@as(u32, @intCast(parent_inst_index)));
31583158
3159 // First loop to discover decl names3159 // First loop to discover decl names
3160 {3160 {
...@@ -3180,7 +3180,7 @@ fn analyzeAllDecls(...@@ -3180,7 +3180,7 @@ fn analyzeAllDecls(
3180 const decl_name_index = file.zir.extra[d.sub_index + 5];3180 const decl_name_index = file.zir.extra[d.sub_index + 5];
3181 switch (decl_name_index) {3181 switch (decl_name_index) {
3182 0 => {3182 0 => {
3183 const is_exported = @truncate(u1, d.flags >> 1);3183 const is_exported = @as(u1, @truncate(d.flags >> 1));
3184 switch (is_exported) {3184 switch (is_exported) {
3185 0 => continue, // comptime decl3185 0 => continue, // comptime decl
3186 1 => {3186 1 => {
...@@ -3255,10 +3255,10 @@ fn analyzeDecl(...@@ -3255,10 +3255,10 @@ fn analyzeDecl(
3255 d: Zir.DeclIterator.Item,3255 d: Zir.DeclIterator.Item,
3256) AutodocErrors!void {3256) AutodocErrors!void {
3257 const data = file.zir.instructions.items(.data);3257 const data = file.zir.instructions.items(.data);
3258 const is_pub = @truncate(u1, d.flags >> 0) != 0;3258 const is_pub = @as(u1, @truncate(d.flags >> 0)) != 0;
3259 // const is_exported = @truncate(u1, d.flags >> 1) != 0;3259 // const is_exported = @truncate(u1, d.flags >> 1) != 0;
3260 const has_align = @truncate(u1, d.flags >> 2) != 0;3260 const has_align = @as(u1, @truncate(d.flags >> 2)) != 0;
3261 const has_section_or_addrspace = @truncate(u1, d.flags >> 3) != 0;3261 const has_section_or_addrspace = @as(u1, @truncate(d.flags >> 3)) != 0;
32623262
3263 var extra_index = d.sub_index;3263 var extra_index = d.sub_index;
3264 // const hash_u32s = file.zir.extra[extra_index..][0..4];3264 // const hash_u32s = file.zir.extra[extra_index..][0..4];
...@@ -3277,21 +3277,21 @@ fn analyzeDecl(...@@ -3277,21 +3277,21 @@ fn analyzeDecl(
32773277
3278 extra_index += 1;3278 extra_index += 1;
3279 const align_inst: Zir.Inst.Ref = if (!has_align) .none else inst: {3279 const align_inst: Zir.Inst.Ref = if (!has_align) .none else inst: {
3280 const inst = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);3280 const inst = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
3281 extra_index += 1;3281 extra_index += 1;
3282 break :inst inst;3282 break :inst inst;
3283 };3283 };
3284 _ = align_inst;3284 _ = align_inst;
32853285
3286 const section_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: {3286 const section_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: {
3287 const inst = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);3287 const inst = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
3288 extra_index += 1;3288 extra_index += 1;
3289 break :inst inst;3289 break :inst inst;
3290 };3290 };
3291 _ = section_inst;3291 _ = section_inst;
32923292
3293 const addrspace_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: {3293 const addrspace_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: {
3294 const inst = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);3294 const inst = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
3295 extra_index += 1;3295 extra_index += 1;
3296 break :inst inst;3296 break :inst inst;
3297 };3297 };
...@@ -3381,7 +3381,7 @@ fn analyzeUsingnamespaceDecl(...@@ -3381,7 +3381,7 @@ fn analyzeUsingnamespaceDecl(
3381) AutodocErrors!void {3381) AutodocErrors!void {
3382 const data = file.zir.instructions.items(.data);3382 const data = file.zir.instructions.items(.data);
33833383
3384 const is_pub = @truncate(u1, d.flags) != 0;3384 const is_pub = @as(u1, @truncate(d.flags)) != 0;
3385 const value_index = file.zir.extra[d.sub_index + 6];3385 const value_index = file.zir.extra[d.sub_index + 6];
3386 const doc_comment_index = file.zir.extra[d.sub_index + 7];3386 const doc_comment_index = file.zir.extra[d.sub_index + 7];
33873387
...@@ -4028,7 +4028,7 @@ fn analyzeFancyFunction(...@@ -4028,7 +4028,7 @@ fn analyzeFancyFunction(
4028) AutodocErrors!DocData.WalkResult {4028) AutodocErrors!DocData.WalkResult {
4029 const tags = file.zir.instructions.items(.tag);4029 const tags = file.zir.instructions.items(.tag);
4030 const data = file.zir.instructions.items(.data);4030 const data = file.zir.instructions.items(.data);
4031 const fn_info = file.zir.getFnInfo(@intCast(u32, inst_index));4031 const fn_info = file.zir.getFnInfo(@as(u32, @intCast(inst_index)));
40324032
4033 try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len);4033 try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len);
4034 var param_type_refs = try std.ArrayListUnmanaged(DocData.Expr).initCapacity(4034 var param_type_refs = try std.ArrayListUnmanaged(DocData.Expr).initCapacity(
...@@ -4108,7 +4108,7 @@ fn analyzeFancyFunction(...@@ -4108,7 +4108,7 @@ fn analyzeFancyFunction(
41084108
4109 var align_index: ?usize = null;4109 var align_index: ?usize = null;
4110 if (extra.data.bits.has_align_ref) {4110 if (extra.data.bits.has_align_ref) {
4111 const align_ref = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);4111 const align_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
4112 align_index = self.exprs.items.len;4112 align_index = self.exprs.items.len;
4113 _ = try self.walkRef(file, scope, parent_src, align_ref, false);4113 _ = try self.walkRef(file, scope, parent_src, align_ref, false);
4114 extra_index += 1;4114 extra_index += 1;
...@@ -4125,7 +4125,7 @@ fn analyzeFancyFunction(...@@ -4125,7 +4125,7 @@ fn analyzeFancyFunction(
41254125
4126 var addrspace_index: ?usize = null;4126 var addrspace_index: ?usize = null;
4127 if (extra.data.bits.has_addrspace_ref) {4127 if (extra.data.bits.has_addrspace_ref) {
4128 const addrspace_ref = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);4128 const addrspace_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
4129 addrspace_index = self.exprs.items.len;4129 addrspace_index = self.exprs.items.len;
4130 _ = try self.walkRef(file, scope, parent_src, addrspace_ref, false);4130 _ = try self.walkRef(file, scope, parent_src, addrspace_ref, false);
4131 extra_index += 1;4131 extra_index += 1;
...@@ -4142,7 +4142,7 @@ fn analyzeFancyFunction(...@@ -4142,7 +4142,7 @@ fn analyzeFancyFunction(
41424142
4143 var section_index: ?usize = null;4143 var section_index: ?usize = null;
4144 if (extra.data.bits.has_section_ref) {4144 if (extra.data.bits.has_section_ref) {
4145 const section_ref = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);4145 const section_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
4146 section_index = self.exprs.items.len;4146 section_index = self.exprs.items.len;
4147 _ = try self.walkRef(file, scope, parent_src, section_ref, false);4147 _ = try self.walkRef(file, scope, parent_src, section_ref, false);
4148 extra_index += 1;4148 extra_index += 1;
...@@ -4159,7 +4159,7 @@ fn analyzeFancyFunction(...@@ -4159,7 +4159,7 @@ fn analyzeFancyFunction(
41594159
4160 var cc_index: ?usize = null;4160 var cc_index: ?usize = null;
4161 if (extra.data.bits.has_cc_ref and !extra.data.bits.has_cc_body) {4161 if (extra.data.bits.has_cc_ref and !extra.data.bits.has_cc_body) {
4162 const cc_ref = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);4162 const cc_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
4163 const cc_expr = try self.walkRef(file, scope, parent_src, cc_ref, false);4163 const cc_expr = try self.walkRef(file, scope, parent_src, cc_ref, false);
41644164
4165 cc_index = self.exprs.items.len;4165 cc_index = self.exprs.items.len;
...@@ -4262,7 +4262,7 @@ fn analyzeFunction(...@@ -4262,7 +4262,7 @@ fn analyzeFunction(
4262) AutodocErrors!DocData.WalkResult {4262) AutodocErrors!DocData.WalkResult {
4263 const tags = file.zir.instructions.items(.tag);4263 const tags = file.zir.instructions.items(.tag);
4264 const data = file.zir.instructions.items(.data);4264 const data = file.zir.instructions.items(.data);
4265 const fn_info = file.zir.getFnInfo(@intCast(u32, inst_index));4265 const fn_info = file.zir.getFnInfo(@as(u32, @intCast(inst_index)));
42664266
4267 try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len);4267 try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len);
4268 var param_type_refs = try std.ArrayListUnmanaged(DocData.Expr).initCapacity(4268 var param_type_refs = try std.ArrayListUnmanaged(DocData.Expr).initCapacity(
...@@ -4449,13 +4449,13 @@ fn collectUnionFieldInfo(...@@ -4449,13 +4449,13 @@ fn collectUnionFieldInfo(
4449 cur_bit_bag = file.zir.extra[bit_bag_index];4449 cur_bit_bag = file.zir.extra[bit_bag_index];
4450 bit_bag_index += 1;4450 bit_bag_index += 1;
4451 }4451 }
4452 const has_type = @truncate(u1, cur_bit_bag) != 0;4452 const has_type = @as(u1, @truncate(cur_bit_bag)) != 0;
4453 cur_bit_bag >>= 1;4453 cur_bit_bag >>= 1;
4454 const has_align = @truncate(u1, cur_bit_bag) != 0;4454 const has_align = @as(u1, @truncate(cur_bit_bag)) != 0;
4455 cur_bit_bag >>= 1;4455 cur_bit_bag >>= 1;
4456 const has_tag = @truncate(u1, cur_bit_bag) != 0;4456 const has_tag = @as(u1, @truncate(cur_bit_bag)) != 0;
4457 cur_bit_bag >>= 1;4457 cur_bit_bag >>= 1;
4458 const unused = @truncate(u1, cur_bit_bag) != 0;4458 const unused = @as(u1, @truncate(cur_bit_bag)) != 0;
4459 cur_bit_bag >>= 1;4459 cur_bit_bag >>= 1;
4460 _ = unused;4460 _ = unused;
44614461
...@@ -4464,7 +4464,7 @@ fn collectUnionFieldInfo(...@@ -4464,7 +4464,7 @@ fn collectUnionFieldInfo(
4464 const doc_comment_index = file.zir.extra[extra_index];4464 const doc_comment_index = file.zir.extra[extra_index];
4465 extra_index += 1;4465 extra_index += 1;
4466 const field_type = if (has_type)4466 const field_type = if (has_type)
4467 @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index])4467 @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]))
4468 else4468 else
4469 .void_type;4469 .void_type;
4470 if (has_type) extra_index += 1;4470 if (has_type) extra_index += 1;
...@@ -4532,13 +4532,13 @@ fn collectStructFieldInfo(...@@ -4532,13 +4532,13 @@ fn collectStructFieldInfo(
4532 cur_bit_bag = file.zir.extra[bit_bag_index];4532 cur_bit_bag = file.zir.extra[bit_bag_index];
4533 bit_bag_index += 1;4533 bit_bag_index += 1;
4534 }4534 }
4535 const has_align = @truncate(u1, cur_bit_bag) != 0;4535 const has_align = @as(u1, @truncate(cur_bit_bag)) != 0;
4536 cur_bit_bag >>= 1;4536 cur_bit_bag >>= 1;
4537 const has_default = @truncate(u1, cur_bit_bag) != 0;4537 const has_default = @as(u1, @truncate(cur_bit_bag)) != 0;
4538 cur_bit_bag >>= 1;4538 cur_bit_bag >>= 1;
4539 // const is_comptime = @truncate(u1, cur_bit_bag) != 0;4539 // const is_comptime = @truncate(u1, cur_bit_bag) != 0;
4540 cur_bit_bag >>= 1;4540 cur_bit_bag >>= 1;
4541 const has_type_body = @truncate(u1, cur_bit_bag) != 0;4541 const has_type_body = @as(u1, @truncate(cur_bit_bag)) != 0;
4542 cur_bit_bag >>= 1;4542 cur_bit_bag >>= 1;
45434543
4544 const field_name: ?u32 = if (!is_tuple) blk: {4544 const field_name: ?u32 = if (!is_tuple) blk: {
...@@ -4558,7 +4558,7 @@ fn collectStructFieldInfo(...@@ -4558,7 +4558,7 @@ fn collectStructFieldInfo(
4558 if (has_type_body) {4558 if (has_type_body) {
4559 fields[field_i].type_body_len = file.zir.extra[extra_index];4559 fields[field_i].type_body_len = file.zir.extra[extra_index];
4560 } else {4560 } else {
4561 fields[field_i].type_ref = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);4561 fields[field_i].type_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
4562 }4562 }
4563 extra_index += 1;4563 extra_index += 1;
45644564
...@@ -4855,9 +4855,9 @@ fn srcLocInfo(...@@ -4855,9 +4855,9 @@ fn srcLocInfo(
4855 src_node: i32,4855 src_node: i32,
4856 parent_src: SrcLocInfo,4856 parent_src: SrcLocInfo,
4857) !SrcLocInfo {4857) !SrcLocInfo {
4858 const sn = @intCast(u32, @intCast(i32, parent_src.src_node) + src_node);4858 const sn = @as(u32, @intCast(@as(i32, @intCast(parent_src.src_node)) + src_node));
4859 const tree = try file.getTree(self.comp_module.gpa);4859 const tree = try file.getTree(self.comp_module.gpa);
4860 const node_idx = @bitCast(Ast.Node.Index, sn);4860 const node_idx = @as(Ast.Node.Index, @bitCast(sn));
4861 const tokens = tree.nodes.items(.main_token);4861 const tokens = tree.nodes.items(.main_token);
48624862
4863 const tok_idx = tokens[node_idx];4863 const tok_idx = tokens[node_idx];
...@@ -4876,9 +4876,9 @@ fn declIsVar(...@@ -4876,9 +4876,9 @@ fn declIsVar(
4876 src_node: i32,4876 src_node: i32,
4877 parent_src: SrcLocInfo,4877 parent_src: SrcLocInfo,
4878) !bool {4878) !bool {
4879 const sn = @intCast(u32, @intCast(i32, parent_src.src_node) + src_node);4879 const sn = @as(u32, @intCast(@as(i32, @intCast(parent_src.src_node)) + src_node));
4880 const tree = try file.getTree(self.comp_module.gpa);4880 const tree = try file.getTree(self.comp_module.gpa);
4881 const node_idx = @bitCast(Ast.Node.Index, sn);4881 const node_idx = @as(Ast.Node.Index, @bitCast(sn));
4882 const tokens = tree.nodes.items(.main_token);4882 const tokens = tree.nodes.items(.main_token);
4883 const tags = tree.tokens.items(.tag);4883 const tags = tree.tokens.items(.tag);
48844884
src/Compilation.zig+20-20
...@@ -1046,7 +1046,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1046,7 +1046,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1046 const llvm_cpu_features: ?[*:0]const u8 = if (build_options.have_llvm and use_llvm) blk: {1046 const llvm_cpu_features: ?[*:0]const u8 = if (build_options.have_llvm and use_llvm) blk: {
1047 var buf = std.ArrayList(u8).init(arena);1047 var buf = std.ArrayList(u8).init(arena);
1048 for (options.target.cpu.arch.allFeaturesList(), 0..) |feature, index_usize| {1048 for (options.target.cpu.arch.allFeaturesList(), 0..) |feature, index_usize| {
1049 const index = @intCast(Target.Cpu.Feature.Set.Index, index_usize);1049 const index = @as(Target.Cpu.Feature.Set.Index, @intCast(index_usize));
1050 const is_enabled = options.target.cpu.features.isEnabled(index);1050 const is_enabled = options.target.cpu.features.isEnabled(index);
10511051
1052 if (feature.llvm_name) |llvm_name| {1052 if (feature.llvm_name) |llvm_name| {
...@@ -2562,7 +2562,7 @@ pub fn totalErrorCount(self: *Compilation) u32 {...@@ -2562,7 +2562,7 @@ pub fn totalErrorCount(self: *Compilation) u32 {
2562 }2562 }
2563 }2563 }
25642564
2565 return @intCast(u32, total);2565 return @as(u32, @intCast(total));
2566}2566}
25672567
2568/// This function is temporally single-threaded.2568/// This function is temporally single-threaded.
...@@ -2596,7 +2596,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {...@@ -2596,7 +2596,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {
2596 }2596 }
25972597
2598 for (self.lld_errors.items) |lld_error| {2598 for (self.lld_errors.items) |lld_error| {
2599 const notes_len = @intCast(u32, lld_error.context_lines.len);2599 const notes_len = @as(u32, @intCast(lld_error.context_lines.len));
26002600
2601 try bundle.addRootErrorMessage(.{2601 try bundle.addRootErrorMessage(.{
2602 .msg = try bundle.addString(lld_error.msg),2602 .msg = try bundle.addString(lld_error.msg),
...@@ -2753,7 +2753,7 @@ pub const ErrorNoteHashContext = struct {...@@ -2753,7 +2753,7 @@ pub const ErrorNoteHashContext = struct {
2753 std.hash.autoHash(&hasher, src.span_main);2753 std.hash.autoHash(&hasher, src.span_main);
2754 }2754 }
27552755
2756 return @truncate(u32, hasher.final());2756 return @as(u32, @truncate(hasher.final()));
2757 }2757 }
27582758
2759 pub fn eql(2759 pub fn eql(
...@@ -2830,8 +2830,8 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod...@@ -2830,8 +2830,8 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod
2830 .span_start = span.start,2830 .span_start = span.start,
2831 .span_main = span.main,2831 .span_main = span.main,
2832 .span_end = span.end,2832 .span_end = span.end,
2833 .line = @intCast(u32, loc.line),2833 .line = @as(u32, @intCast(loc.line)),
2834 .column = @intCast(u32, loc.column),2834 .column = @as(u32, @intCast(loc.column)),
2835 .source_line = 0,2835 .source_line = 0,
2836 }),2836 }),
2837 });2837 });
...@@ -2842,13 +2842,13 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod...@@ -2842,13 +2842,13 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod
2842 .span_start = err_span.start,2842 .span_start = err_span.start,
2843 .span_main = err_span.main,2843 .span_main = err_span.main,
2844 .span_end = err_span.end,2844 .span_end = err_span.end,
2845 .line = @intCast(u32, err_loc.line),2845 .line = @as(u32, @intCast(err_loc.line)),
2846 .column = @intCast(u32, err_loc.column),2846 .column = @as(u32, @intCast(err_loc.column)),
2847 .source_line = if (module_err_msg.src_loc.lazy == .entire_file)2847 .source_line = if (module_err_msg.src_loc.lazy == .entire_file)
2848 02848 0
2849 else2849 else
2850 try eb.addString(err_loc.source_line),2850 try eb.addString(err_loc.source_line),
2851 .reference_trace_len = @intCast(u32, ref_traces.items.len),2851 .reference_trace_len = @as(u32, @intCast(ref_traces.items.len)),
2852 });2852 });
28532853
2854 for (ref_traces.items) |rt| {2854 for (ref_traces.items) |rt| {
...@@ -2874,8 +2874,8 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod...@@ -2874,8 +2874,8 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod
2874 .span_start = span.start,2874 .span_start = span.start,
2875 .span_main = span.main,2875 .span_main = span.main,
2876 .span_end = span.end,2876 .span_end = span.end,
2877 .line = @intCast(u32, loc.line),2877 .line = @as(u32, @intCast(loc.line)),
2878 .column = @intCast(u32, loc.column),2878 .column = @as(u32, @intCast(loc.column)),
2879 .source_line = if (err_loc.eql(loc)) 0 else try eb.addString(loc.source_line),2879 .source_line = if (err_loc.eql(loc)) 0 else try eb.addString(loc.source_line),
2880 }),2880 }),
2881 }, .{ .eb = eb });2881 }, .{ .eb = eb });
...@@ -2884,7 +2884,7 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod...@@ -2884,7 +2884,7 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod
2884 }2884 }
2885 }2885 }
28862886
2887 const notes_len = @intCast(u32, notes.entries.len);2887 const notes_len = @as(u32, @intCast(notes.entries.len));
28882888
2889 try eb.addRootErrorMessage(.{2889 try eb.addRootErrorMessage(.{
2890 .msg = try eb.addString(module_err_msg.msg),2890 .msg = try eb.addString(module_err_msg.msg),
...@@ -2919,7 +2919,7 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void {...@@ -2919,7 +2919,7 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void {
2919 }2919 }
2920 const token_starts = file.tree.tokens.items(.start);2920 const token_starts = file.tree.tokens.items(.start);
2921 const start = token_starts[item.data.token] + item.data.byte_offset;2921 const start = token_starts[item.data.token] + item.data.byte_offset;
2922 const end = start + @intCast(u32, file.tree.tokenSlice(item.data.token).len) - item.data.byte_offset;2922 const end = start + @as(u32, @intCast(file.tree.tokenSlice(item.data.token).len)) - item.data.byte_offset;
2923 break :blk Module.SrcLoc.Span{ .start = start, .end = end, .main = start };2923 break :blk Module.SrcLoc.Span{ .start = start, .end = end, .main = start };
2924 };2924 };
2925 const err_loc = std.zig.findLineColumn(file.source, err_span.main);2925 const err_loc = std.zig.findLineColumn(file.source, err_span.main);
...@@ -2935,8 +2935,8 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void {...@@ -2935,8 +2935,8 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void {
2935 .span_start = err_span.start,2935 .span_start = err_span.start,
2936 .span_main = err_span.main,2936 .span_main = err_span.main,
2937 .span_end = err_span.end,2937 .span_end = err_span.end,
2938 .line = @intCast(u32, err_loc.line),2938 .line = @as(u32, @intCast(err_loc.line)),
2939 .column = @intCast(u32, err_loc.column),2939 .column = @as(u32, @intCast(err_loc.column)),
2940 .source_line = try eb.addString(err_loc.source_line),2940 .source_line = try eb.addString(err_loc.source_line),
2941 }),2941 }),
2942 .notes_len = item.data.notesLen(file.zir),2942 .notes_len = item.data.notesLen(file.zir),
...@@ -2956,7 +2956,7 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void {...@@ -2956,7 +2956,7 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void {
2956 }2956 }
2957 const token_starts = file.tree.tokens.items(.start);2957 const token_starts = file.tree.tokens.items(.start);
2958 const start = token_starts[note_item.data.token] + note_item.data.byte_offset;2958 const start = token_starts[note_item.data.token] + note_item.data.byte_offset;
2959 const end = start + @intCast(u32, file.tree.tokenSlice(note_item.data.token).len) - item.data.byte_offset;2959 const end = start + @as(u32, @intCast(file.tree.tokenSlice(note_item.data.token).len)) - item.data.byte_offset;
2960 break :blk Module.SrcLoc.Span{ .start = start, .end = end, .main = start };2960 break :blk Module.SrcLoc.Span{ .start = start, .end = end, .main = start };
2961 };2961 };
2962 const loc = std.zig.findLineColumn(file.source, span.main);2962 const loc = std.zig.findLineColumn(file.source, span.main);
...@@ -2970,8 +2970,8 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void {...@@ -2970,8 +2970,8 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void {
2970 .span_start = span.start,2970 .span_start = span.start,
2971 .span_main = span.main,2971 .span_main = span.main,
2972 .span_end = span.end,2972 .span_end = span.end,
2973 .line = @intCast(u32, loc.line),2973 .line = @as(u32, @intCast(loc.line)),
2974 .column = @intCast(u32, loc.column),2974 .column = @as(u32, @intCast(loc.column)),
2975 .source_line = if (loc.eql(err_loc))2975 .source_line = if (loc.eql(err_loc))
2976 02976 0
2977 else2977 else
...@@ -4302,7 +4302,7 @@ pub fn addCCArgs(...@@ -4302,7 +4302,7 @@ pub fn addCCArgs(
4302 const all_features_list = target.cpu.arch.allFeaturesList();4302 const all_features_list = target.cpu.arch.allFeaturesList();
4303 try argv.ensureUnusedCapacity(all_features_list.len * 4);4303 try argv.ensureUnusedCapacity(all_features_list.len * 4);
4304 for (all_features_list, 0..) |feature, index_usize| {4304 for (all_features_list, 0..) |feature, index_usize| {
4305 const index = @intCast(std.Target.Cpu.Feature.Set.Index, index_usize);4305 const index = @as(std.Target.Cpu.Feature.Set.Index, @intCast(index_usize));
4306 const is_enabled = target.cpu.features.isEnabled(index);4306 const is_enabled = target.cpu.features.isEnabled(index);
43074307
4308 if (feature.llvm_name) |llvm_name| {4308 if (feature.llvm_name) |llvm_name| {
...@@ -5172,7 +5172,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca...@@ -5172,7 +5172,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca
5172 });5172 });
51735173
5174 for (target.cpu.arch.allFeaturesList(), 0..) |feature, index_usize| {5174 for (target.cpu.arch.allFeaturesList(), 0..) |feature, index_usize| {
5175 const index = @intCast(std.Target.Cpu.Feature.Set.Index, index_usize);5175 const index = @as(std.Target.Cpu.Feature.Set.Index, @intCast(index_usize));
5176 const is_enabled = target.cpu.features.isEnabled(index);5176 const is_enabled = target.cpu.features.isEnabled(index);
5177 if (is_enabled) {5177 if (is_enabled) {
5178 try buffer.writer().print(" .{},\n", .{std.zig.fmtId(feature.name)});5178 try buffer.writer().print(" .{},\n", .{std.zig.fmtId(feature.name)});
src/InternPool.zig+205-205
...@@ -80,7 +80,7 @@ const KeyAdapter = struct {...@@ -80,7 +80,7 @@ const KeyAdapter = struct {
8080
81 pub fn eql(ctx: @This(), a: Key, b_void: void, b_map_index: usize) bool {81 pub fn eql(ctx: @This(), a: Key, b_void: void, b_map_index: usize) bool {
82 _ = b_void;82 _ = b_void;
83 return ctx.intern_pool.indexToKey(@enumFromInt(Index, b_map_index)).eql(a, ctx.intern_pool);83 return ctx.intern_pool.indexToKey(@as(Index, @enumFromInt(b_map_index))).eql(a, ctx.intern_pool);
84 }84 }
8585
86 pub fn hash(ctx: @This(), a: Key) u32 {86 pub fn hash(ctx: @This(), a: Key) u32 {
...@@ -95,7 +95,7 @@ pub const OptionalMapIndex = enum(u32) {...@@ -95,7 +95,7 @@ pub const OptionalMapIndex = enum(u32) {
9595
96 pub fn unwrap(oi: OptionalMapIndex) ?MapIndex {96 pub fn unwrap(oi: OptionalMapIndex) ?MapIndex {
97 if (oi == .none) return null;97 if (oi == .none) return null;
98 return @enumFromInt(MapIndex, @intFromEnum(oi));98 return @as(MapIndex, @enumFromInt(@intFromEnum(oi)));
99 }99 }
100};100};
101101
...@@ -104,7 +104,7 @@ pub const MapIndex = enum(u32) {...@@ -104,7 +104,7 @@ pub const MapIndex = enum(u32) {
104 _,104 _,
105105
106 pub fn toOptional(i: MapIndex) OptionalMapIndex {106 pub fn toOptional(i: MapIndex) OptionalMapIndex {
107 return @enumFromInt(OptionalMapIndex, @intFromEnum(i));107 return @as(OptionalMapIndex, @enumFromInt(@intFromEnum(i)));
108 }108 }
109};109};
110110
...@@ -114,7 +114,7 @@ pub const RuntimeIndex = enum(u32) {...@@ -114,7 +114,7 @@ pub const RuntimeIndex = enum(u32) {
114 _,114 _,
115115
116 pub fn increment(ri: *RuntimeIndex) void {116 pub fn increment(ri: *RuntimeIndex) void {
117 ri.* = @enumFromInt(RuntimeIndex, @intFromEnum(ri.*) + 1);117 ri.* = @as(RuntimeIndex, @enumFromInt(@intFromEnum(ri.*) + 1));
118 }118 }
119};119};
120120
...@@ -130,11 +130,11 @@ pub const NullTerminatedString = enum(u32) {...@@ -130,11 +130,11 @@ pub const NullTerminatedString = enum(u32) {
130 _,130 _,
131131
132 pub fn toString(self: NullTerminatedString) String {132 pub fn toString(self: NullTerminatedString) String {
133 return @enumFromInt(String, @intFromEnum(self));133 return @as(String, @enumFromInt(@intFromEnum(self)));
134 }134 }
135135
136 pub fn toOptional(self: NullTerminatedString) OptionalNullTerminatedString {136 pub fn toOptional(self: NullTerminatedString) OptionalNullTerminatedString {
137 return @enumFromInt(OptionalNullTerminatedString, @intFromEnum(self));137 return @as(OptionalNullTerminatedString, @enumFromInt(@intFromEnum(self)));
138 }138 }
139139
140 const Adapter = struct {140 const Adapter = struct {
...@@ -196,7 +196,7 @@ pub const OptionalNullTerminatedString = enum(u32) {...@@ -196,7 +196,7 @@ pub const OptionalNullTerminatedString = enum(u32) {
196196
197 pub fn unwrap(oi: OptionalNullTerminatedString) ?NullTerminatedString {197 pub fn unwrap(oi: OptionalNullTerminatedString) ?NullTerminatedString {
198 if (oi == .none) return null;198 if (oi == .none) return null;
199 return @enumFromInt(NullTerminatedString, @intFromEnum(oi));199 return @as(NullTerminatedString, @enumFromInt(@intFromEnum(oi)));
200 }200 }
201};201};
202202
...@@ -282,7 +282,7 @@ pub const Key = union(enum) {...@@ -282,7 +282,7 @@ pub const Key = union(enum) {
282 const map = &ip.maps.items[@intFromEnum(self.names_map.unwrap().?)];282 const map = &ip.maps.items[@intFromEnum(self.names_map.unwrap().?)];
283 const adapter: NullTerminatedString.Adapter = .{ .strings = self.names };283 const adapter: NullTerminatedString.Adapter = .{ .strings = self.names };
284 const field_index = map.getIndexAdapted(name, adapter) orelse return null;284 const field_index = map.getIndexAdapted(name, adapter) orelse return null;
285 return @intCast(u32, field_index);285 return @as(u32, @intCast(field_index));
286 }286 }
287 };287 };
288288
...@@ -420,7 +420,7 @@ pub const Key = union(enum) {...@@ -420,7 +420,7 @@ pub const Key = union(enum) {
420 const map = &ip.maps.items[@intFromEnum(self.names_map.unwrap().?)];420 const map = &ip.maps.items[@intFromEnum(self.names_map.unwrap().?)];
421 const adapter: NullTerminatedString.Adapter = .{ .strings = self.names };421 const adapter: NullTerminatedString.Adapter = .{ .strings = self.names };
422 const field_index = map.getIndexAdapted(name, adapter) orelse return null;422 const field_index = map.getIndexAdapted(name, adapter) orelse return null;
423 return @intCast(u32, field_index);423 return @as(u32, @intCast(field_index));
424 }424 }
425425
426 /// Look up field index based on tag value.426 /// Look up field index based on tag value.
...@@ -440,7 +440,7 @@ pub const Key = union(enum) {...@@ -440,7 +440,7 @@ pub const Key = union(enum) {
440 const map = &ip.maps.items[@intFromEnum(values_map)];440 const map = &ip.maps.items[@intFromEnum(values_map)];
441 const adapter: Index.Adapter = .{ .indexes = self.values };441 const adapter: Index.Adapter = .{ .indexes = self.values };
442 const field_index = map.getIndexAdapted(int_tag_val, adapter) orelse return null;442 const field_index = map.getIndexAdapted(int_tag_val, adapter) orelse return null;
443 return @intCast(u32, field_index);443 return @as(u32, @intCast(field_index));
444 }444 }
445 // Auto-numbered enum. Convert `int_tag_val` to field index.445 // Auto-numbered enum. Convert `int_tag_val` to field index.
446 const field_index = switch (ip.indexToKey(int_tag_val).int.storage) {446 const field_index = switch (ip.indexToKey(int_tag_val).int.storage) {
...@@ -511,12 +511,12 @@ pub const Key = union(enum) {...@@ -511,12 +511,12 @@ pub const Key = union(enum) {
511511
512 pub fn paramIsComptime(self: @This(), i: u5) bool {512 pub fn paramIsComptime(self: @This(), i: u5) bool {
513 assert(i < self.param_types.len);513 assert(i < self.param_types.len);
514 return @truncate(u1, self.comptime_bits >> i) != 0;514 return @as(u1, @truncate(self.comptime_bits >> i)) != 0;
515 }515 }
516516
517 pub fn paramIsNoalias(self: @This(), i: u5) bool {517 pub fn paramIsNoalias(self: @This(), i: u5) bool {
518 assert(i < self.param_types.len);518 assert(i < self.param_types.len);
519 return @truncate(u1, self.noalias_bits >> i) != 0;519 return @as(u1, @truncate(self.noalias_bits >> i)) != 0;
520 }520 }
521 };521 };
522522
...@@ -685,7 +685,7 @@ pub const Key = union(enum) {...@@ -685,7 +685,7 @@ pub const Key = union(enum) {
685 };685 };
686686
687 pub fn hash32(key: Key, ip: *const InternPool) u32 {687 pub fn hash32(key: Key, ip: *const InternPool) u32 {
688 return @truncate(u32, key.hash64(ip));688 return @as(u32, @truncate(key.hash64(ip)));
689 }689 }
690690
691 pub fn hash64(key: Key, ip: *const InternPool) u64 {691 pub fn hash64(key: Key, ip: *const InternPool) u64 {
...@@ -767,7 +767,7 @@ pub const Key = union(enum) {...@@ -767,7 +767,7 @@ pub const Key = union(enum) {
767 switch (float.storage) {767 switch (float.storage) {
768 inline else => |val| std.hash.autoHash(768 inline else => |val| std.hash.autoHash(
769 &hasher,769 &hasher,
770 @bitCast(std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(val))), val),770 @as(std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(val))), @bitCast(val)),
771 ),771 ),
772 }772 }
773 return hasher.final();773 return hasher.final();
...@@ -812,18 +812,18 @@ pub const Key = union(enum) {...@@ -812,18 +812,18 @@ pub const Key = union(enum) {
812812
813 if (child == .u8_type) {813 if (child == .u8_type) {
814 switch (aggregate.storage) {814 switch (aggregate.storage) {
815 .bytes => |bytes| for (bytes[0..@intCast(usize, len)]) |byte| {815 .bytes => |bytes| for (bytes[0..@as(usize, @intCast(len))]) |byte| {
816 std.hash.autoHash(&hasher, KeyTag.int);816 std.hash.autoHash(&hasher, KeyTag.int);
817 std.hash.autoHash(&hasher, byte);817 std.hash.autoHash(&hasher, byte);
818 },818 },
819 .elems => |elems| for (elems[0..@intCast(usize, len)]) |elem| {819 .elems => |elems| for (elems[0..@as(usize, @intCast(len))]) |elem| {
820 const elem_key = ip.indexToKey(elem);820 const elem_key = ip.indexToKey(elem);
821 std.hash.autoHash(&hasher, @as(KeyTag, elem_key));821 std.hash.autoHash(&hasher, @as(KeyTag, elem_key));
822 switch (elem_key) {822 switch (elem_key) {
823 .undef => {},823 .undef => {},
824 .int => |int| std.hash.autoHash(824 .int => |int| std.hash.autoHash(
825 &hasher,825 &hasher,
826 @intCast(u8, int.storage.u64),826 @as(u8, @intCast(int.storage.u64)),
827 ),827 ),
828 else => unreachable,828 else => unreachable,
829 }829 }
...@@ -837,7 +837,7 @@ pub const Key = union(enum) {...@@ -837,7 +837,7 @@ pub const Key = union(enum) {
837 .undef => {},837 .undef => {},
838 .int => |int| std.hash.autoHash(838 .int => |int| std.hash.autoHash(
839 &hasher,839 &hasher,
840 @intCast(u8, int.storage.u64),840 @as(u8, @intCast(int.storage.u64)),
841 ),841 ),
842 else => unreachable,842 else => unreachable,
843 }843 }
...@@ -849,7 +849,7 @@ pub const Key = union(enum) {...@@ -849,7 +849,7 @@ pub const Key = union(enum) {
849849
850 switch (aggregate.storage) {850 switch (aggregate.storage) {
851 .bytes => unreachable,851 .bytes => unreachable,
852 .elems => |elems| for (elems[0..@intCast(usize, len)]) |elem|852 .elems => |elems| for (elems[0..@as(usize, @intCast(len))]) |elem|
853 std.hash.autoHash(&hasher, elem),853 std.hash.autoHash(&hasher, elem),
854 .repeated_elem => |elem| {854 .repeated_elem => |elem| {
855 var remaining = len;855 var remaining = len;
...@@ -1061,10 +1061,10 @@ pub const Key = union(enum) {...@@ -1061,10 +1061,10 @@ pub const Key = union(enum) {
1061 // These are strange: we'll sometimes represent them as f128, even if the1061 // These are strange: we'll sometimes represent them as f128, even if the
1062 // underlying type is smaller. f80 is an exception: see float_c_longdouble_f80.1062 // underlying type is smaller. f80 is an exception: see float_c_longdouble_f80.
1063 const a_val = switch (a_info.storage) {1063 const a_val = switch (a_info.storage) {
1064 inline else => |val| @floatCast(f128, val),1064 inline else => |val| @as(f128, @floatCast(val)),
1065 };1065 };
1066 const b_val = switch (b_info.storage) {1066 const b_val = switch (b_info.storage) {
1067 inline else => |val| @floatCast(f128, val),1067 inline else => |val| @as(f128, @floatCast(val)),
1068 };1068 };
1069 return a_val == b_val;1069 return a_val == b_val;
1070 }1070 }
...@@ -1092,7 +1092,7 @@ pub const Key = union(enum) {...@@ -1092,7 +1092,7 @@ pub const Key = union(enum) {
1092 const len = ip.aggregateTypeLen(a_info.ty);1092 const len = ip.aggregateTypeLen(a_info.ty);
1093 const StorageTag = @typeInfo(Key.Aggregate.Storage).Union.tag_type.?;1093 const StorageTag = @typeInfo(Key.Aggregate.Storage).Union.tag_type.?;
1094 if (@as(StorageTag, a_info.storage) != @as(StorageTag, b_info.storage)) {1094 if (@as(StorageTag, a_info.storage) != @as(StorageTag, b_info.storage)) {
1095 for (0..@intCast(usize, len)) |elem_index| {1095 for (0..@as(usize, @intCast(len))) |elem_index| {
1096 const a_elem = switch (a_info.storage) {1096 const a_elem = switch (a_info.storage) {
1097 .bytes => |bytes| ip.getIfExists(.{ .int = .{1097 .bytes => |bytes| ip.getIfExists(.{ .int = .{
1098 .ty = .u8_type,1098 .ty = .u8_type,
...@@ -1119,16 +1119,16 @@ pub const Key = union(enum) {...@@ -1119,16 +1119,16 @@ pub const Key = union(enum) {
1119 const b_bytes = b_info.storage.bytes;1119 const b_bytes = b_info.storage.bytes;
1120 return std.mem.eql(1120 return std.mem.eql(
1121 u8,1121 u8,
1122 a_bytes[0..@intCast(usize, len)],1122 a_bytes[0..@as(usize, @intCast(len))],
1123 b_bytes[0..@intCast(usize, len)],1123 b_bytes[0..@as(usize, @intCast(len))],
1124 );1124 );
1125 },1125 },
1126 .elems => |a_elems| {1126 .elems => |a_elems| {
1127 const b_elems = b_info.storage.elems;1127 const b_elems = b_info.storage.elems;
1128 return std.mem.eql(1128 return std.mem.eql(
1129 Index,1129 Index,
1130 a_elems[0..@intCast(usize, len)],1130 a_elems[0..@as(usize, @intCast(len))],
1131 b_elems[0..@intCast(usize, len)],1131 b_elems[0..@as(usize, @intCast(len))],
1132 );1132 );
1133 },1133 },
1134 .repeated_elem => |a_elem| {1134 .repeated_elem => |a_elem| {
...@@ -2291,7 +2291,7 @@ pub const Alignment = enum(u6) {...@@ -2291,7 +2291,7 @@ pub const Alignment = enum(u6) {
2291 pub fn fromByteUnits(n: u64) Alignment {2291 pub fn fromByteUnits(n: u64) Alignment {
2292 if (n == 0) return .none;2292 if (n == 0) return .none;
2293 assert(std.math.isPowerOfTwo(n));2293 assert(std.math.isPowerOfTwo(n));
2294 return @enumFromInt(Alignment, @ctz(n));2294 return @as(Alignment, @enumFromInt(@ctz(n)));
2295 }2295 }
22962296
2297 pub fn fromNonzeroByteUnits(n: u64) Alignment {2297 pub fn fromNonzeroByteUnits(n: u64) Alignment {
...@@ -2368,11 +2368,11 @@ pub const PackedU64 = packed struct(u64) {...@@ -2368,11 +2368,11 @@ pub const PackedU64 = packed struct(u64) {
2368 b: u32,2368 b: u32,
23692369
2370 pub fn get(x: PackedU64) u64 {2370 pub fn get(x: PackedU64) u64 {
2371 return @bitCast(u64, x);2371 return @as(u64, @bitCast(x));
2372 }2372 }
23732373
2374 pub fn init(x: u64) PackedU64 {2374 pub fn init(x: u64) PackedU64 {
2375 return @bitCast(PackedU64, x);2375 return @as(PackedU64, @bitCast(x));
2376 }2376 }
2377};2377};
23782378
...@@ -2435,14 +2435,14 @@ pub const Float64 = struct {...@@ -2435,14 +2435,14 @@ pub const Float64 = struct {
24352435
2436 pub fn get(self: Float64) f64 {2436 pub fn get(self: Float64) f64 {
2437 const int_bits = @as(u64, self.piece0) | (@as(u64, self.piece1) << 32);2437 const int_bits = @as(u64, self.piece0) | (@as(u64, self.piece1) << 32);
2438 return @bitCast(f64, int_bits);2438 return @as(f64, @bitCast(int_bits));
2439 }2439 }
24402440
2441 fn pack(val: f64) Float64 {2441 fn pack(val: f64) Float64 {
2442 const bits = @bitCast(u64, val);2442 const bits = @as(u64, @bitCast(val));
2443 return .{2443 return .{
2444 .piece0 = @truncate(u32, bits),2444 .piece0 = @as(u32, @truncate(bits)),
2445 .piece1 = @truncate(u32, bits >> 32),2445 .piece1 = @as(u32, @truncate(bits >> 32)),
2446 };2446 };
2447 }2447 }
2448};2448};
...@@ -2457,15 +2457,15 @@ pub const Float80 = struct {...@@ -2457,15 +2457,15 @@ pub const Float80 = struct {
2457 const int_bits = @as(u80, self.piece0) |2457 const int_bits = @as(u80, self.piece0) |
2458 (@as(u80, self.piece1) << 32) |2458 (@as(u80, self.piece1) << 32) |
2459 (@as(u80, self.piece2) << 64);2459 (@as(u80, self.piece2) << 64);
2460 return @bitCast(f80, int_bits);2460 return @as(f80, @bitCast(int_bits));
2461 }2461 }
24622462
2463 fn pack(val: f80) Float80 {2463 fn pack(val: f80) Float80 {
2464 const bits = @bitCast(u80, val);2464 const bits = @as(u80, @bitCast(val));
2465 return .{2465 return .{
2466 .piece0 = @truncate(u32, bits),2466 .piece0 = @as(u32, @truncate(bits)),
2467 .piece1 = @truncate(u32, bits >> 32),2467 .piece1 = @as(u32, @truncate(bits >> 32)),
2468 .piece2 = @truncate(u16, bits >> 64),2468 .piece2 = @as(u16, @truncate(bits >> 64)),
2469 };2469 };
2470 }2470 }
2471};2471};
...@@ -2482,16 +2482,16 @@ pub const Float128 = struct {...@@ -2482,16 +2482,16 @@ pub const Float128 = struct {
2482 (@as(u128, self.piece1) << 32) |2482 (@as(u128, self.piece1) << 32) |
2483 (@as(u128, self.piece2) << 64) |2483 (@as(u128, self.piece2) << 64) |
2484 (@as(u128, self.piece3) << 96);2484 (@as(u128, self.piece3) << 96);
2485 return @bitCast(f128, int_bits);2485 return @as(f128, @bitCast(int_bits));
2486 }2486 }
24872487
2488 fn pack(val: f128) Float128 {2488 fn pack(val: f128) Float128 {
2489 const bits = @bitCast(u128, val);2489 const bits = @as(u128, @bitCast(val));
2490 return .{2490 return .{
2491 .piece0 = @truncate(u32, bits),2491 .piece0 = @as(u32, @truncate(bits)),
2492 .piece1 = @truncate(u32, bits >> 32),2492 .piece1 = @as(u32, @truncate(bits >> 32)),
2493 .piece2 = @truncate(u32, bits >> 64),2493 .piece2 = @as(u32, @truncate(bits >> 64)),
2494 .piece3 = @truncate(u32, bits >> 96),2494 .piece3 = @as(u32, @truncate(bits >> 96)),
2495 };2495 };
2496 }2496 }
2497};2497};
...@@ -2575,13 +2575,13 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -2575,13 +2575,13 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
2575 .type_int_signed => .{2575 .type_int_signed => .{
2576 .int_type = .{2576 .int_type = .{
2577 .signedness = .signed,2577 .signedness = .signed,
2578 .bits = @intCast(u16, data),2578 .bits = @as(u16, @intCast(data)),
2579 },2579 },
2580 },2580 },
2581 .type_int_unsigned => .{2581 .type_int_unsigned => .{
2582 .int_type = .{2582 .int_type = .{
2583 .signedness = .unsigned,2583 .signedness = .unsigned,
2584 .bits = @intCast(u16, data),2584 .bits = @as(u16, @intCast(data)),
2585 },2585 },
2586 },2586 },
2587 .type_array_big => {2587 .type_array_big => {
...@@ -2600,8 +2600,8 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -2600,8 +2600,8 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
2600 .sentinel = .none,2600 .sentinel = .none,
2601 } };2601 } };
2602 },2602 },
2603 .simple_type => .{ .simple_type = @enumFromInt(SimpleType, data) },2603 .simple_type => .{ .simple_type = @as(SimpleType, @enumFromInt(data)) },
2604 .simple_value => .{ .simple_value = @enumFromInt(SimpleValue, data) },2604 .simple_value => .{ .simple_value = @as(SimpleValue, @enumFromInt(data)) },
26052605
2606 .type_vector => {2606 .type_vector => {
2607 const vector_info = ip.extraData(Vector, data);2607 const vector_info = ip.extraData(Vector, data);
...@@ -2620,8 +2620,8 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -2620,8 +2620,8 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
2620 return .{ .ptr_type = ptr_info };2620 return .{ .ptr_type = ptr_info };
2621 },2621 },
26222622
2623 .type_optional => .{ .opt_type = @enumFromInt(Index, data) },2623 .type_optional => .{ .opt_type = @as(Index, @enumFromInt(data)) },
2624 .type_anyframe => .{ .anyframe_type = @enumFromInt(Index, data) },2624 .type_anyframe => .{ .anyframe_type = @as(Index, @enumFromInt(data)) },
26252625
2626 .type_error_union => .{ .error_union_type = ip.extraData(Key.ErrorUnionType, data) },2626 .type_error_union => .{ .error_union_type = ip.extraData(Key.ErrorUnionType, data) },
2627 .type_error_set => {2627 .type_error_set => {
...@@ -2629,17 +2629,17 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -2629,17 +2629,17 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
2629 const names_len = error_set.data.names_len;2629 const names_len = error_set.data.names_len;
2630 const names = ip.extra.items[error_set.end..][0..names_len];2630 const names = ip.extra.items[error_set.end..][0..names_len];
2631 return .{ .error_set_type = .{2631 return .{ .error_set_type = .{
2632 .names = @ptrCast([]const NullTerminatedString, names),2632 .names = @as([]const NullTerminatedString, @ptrCast(names)),
2633 .names_map = error_set.data.names_map.toOptional(),2633 .names_map = error_set.data.names_map.toOptional(),
2634 } };2634 } };
2635 },2635 },
2636 .type_inferred_error_set => .{2636 .type_inferred_error_set => .{
2637 .inferred_error_set_type = @enumFromInt(Module.Fn.InferredErrorSet.Index, data),2637 .inferred_error_set_type = @as(Module.Fn.InferredErrorSet.Index, @enumFromInt(data)),
2638 },2638 },
26392639
2640 .type_opaque => .{ .opaque_type = ip.extraData(Key.OpaqueType, data) },2640 .type_opaque => .{ .opaque_type = ip.extraData(Key.OpaqueType, data) },
2641 .type_struct => {2641 .type_struct => {
2642 const struct_index = @enumFromInt(Module.Struct.OptionalIndex, data);2642 const struct_index = @as(Module.Struct.OptionalIndex, @enumFromInt(data));
2643 const namespace = if (struct_index.unwrap()) |i|2643 const namespace = if (struct_index.unwrap()) |i|
2644 ip.structPtrConst(i).namespace.toOptional()2644 ip.structPtrConst(i).namespace.toOptional()
2645 else2645 else
...@@ -2651,7 +2651,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -2651,7 +2651,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
2651 },2651 },
2652 .type_struct_ns => .{ .struct_type = .{2652 .type_struct_ns => .{ .struct_type = .{
2653 .index = .none,2653 .index = .none,
2654 .namespace = @enumFromInt(Module.Namespace.Index, data).toOptional(),2654 .namespace = @as(Module.Namespace.Index, @enumFromInt(data)).toOptional(),
2655 } },2655 } },
26562656
2657 .type_struct_anon => {2657 .type_struct_anon => {
...@@ -2661,9 +2661,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -2661,9 +2661,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
2661 const values = ip.extra.items[type_struct_anon.end + fields_len ..][0..fields_len];2661 const values = ip.extra.items[type_struct_anon.end + fields_len ..][0..fields_len];
2662 const names = ip.extra.items[type_struct_anon.end + 2 * fields_len ..][0..fields_len];2662 const names = ip.extra.items[type_struct_anon.end + 2 * fields_len ..][0..fields_len];
2663 return .{ .anon_struct_type = .{2663 return .{ .anon_struct_type = .{
2664 .types = @ptrCast([]const Index, types),2664 .types = @as([]const Index, @ptrCast(types)),
2665 .values = @ptrCast([]const Index, values),2665 .values = @as([]const Index, @ptrCast(values)),
2666 .names = @ptrCast([]const NullTerminatedString, names),2666 .names = @as([]const NullTerminatedString, @ptrCast(names)),
2667 } };2667 } };
2668 },2668 },
2669 .type_tuple_anon => {2669 .type_tuple_anon => {
...@@ -2672,30 +2672,30 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -2672,30 +2672,30 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
2672 const types = ip.extra.items[type_struct_anon.end..][0..fields_len];2672 const types = ip.extra.items[type_struct_anon.end..][0..fields_len];
2673 const values = ip.extra.items[type_struct_anon.end + fields_len ..][0..fields_len];2673 const values = ip.extra.items[type_struct_anon.end + fields_len ..][0..fields_len];
2674 return .{ .anon_struct_type = .{2674 return .{ .anon_struct_type = .{
2675 .types = @ptrCast([]const Index, types),2675 .types = @as([]const Index, @ptrCast(types)),
2676 .values = @ptrCast([]const Index, values),2676 .values = @as([]const Index, @ptrCast(values)),
2677 .names = &.{},2677 .names = &.{},
2678 } };2678 } };
2679 },2679 },
26802680
2681 .type_union_untagged => .{ .union_type = .{2681 .type_union_untagged => .{ .union_type = .{
2682 .index = @enumFromInt(Module.Union.Index, data),2682 .index = @as(Module.Union.Index, @enumFromInt(data)),
2683 .runtime_tag = .none,2683 .runtime_tag = .none,
2684 } },2684 } },
2685 .type_union_tagged => .{ .union_type = .{2685 .type_union_tagged => .{ .union_type = .{
2686 .index = @enumFromInt(Module.Union.Index, data),2686 .index = @as(Module.Union.Index, @enumFromInt(data)),
2687 .runtime_tag = .tagged,2687 .runtime_tag = .tagged,
2688 } },2688 } },
2689 .type_union_safety => .{ .union_type = .{2689 .type_union_safety => .{ .union_type = .{
2690 .index = @enumFromInt(Module.Union.Index, data),2690 .index = @as(Module.Union.Index, @enumFromInt(data)),
2691 .runtime_tag = .safety,2691 .runtime_tag = .safety,
2692 } },2692 } },
26932693
2694 .type_enum_auto => {2694 .type_enum_auto => {
2695 const enum_auto = ip.extraDataTrail(EnumAuto, data);2695 const enum_auto = ip.extraDataTrail(EnumAuto, data);
2696 const names = @ptrCast(2696 const names = @as(
2697 []const NullTerminatedString,2697 []const NullTerminatedString,
2698 ip.extra.items[enum_auto.end..][0..enum_auto.data.fields_len],2698 @ptrCast(ip.extra.items[enum_auto.end..][0..enum_auto.data.fields_len]),
2699 );2699 );
2700 return .{ .enum_type = .{2700 return .{ .enum_type = .{
2701 .decl = enum_auto.data.decl,2701 .decl = enum_auto.data.decl,
...@@ -2712,10 +2712,10 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -2712,10 +2712,10 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
2712 .type_enum_nonexhaustive => ip.indexToKeyEnum(data, .nonexhaustive),2712 .type_enum_nonexhaustive => ip.indexToKeyEnum(data, .nonexhaustive),
2713 .type_function => .{ .func_type = ip.indexToKeyFuncType(data) },2713 .type_function => .{ .func_type = ip.indexToKeyFuncType(data) },
27142714
2715 .undef => .{ .undef = @enumFromInt(Index, data) },2715 .undef => .{ .undef = @as(Index, @enumFromInt(data)) },
2716 .runtime_value => .{ .runtime_value = ip.extraData(Tag.TypeValue, data) },2716 .runtime_value => .{ .runtime_value = ip.extraData(Tag.TypeValue, data) },
2717 .opt_null => .{ .opt = .{2717 .opt_null => .{ .opt = .{
2718 .ty = @enumFromInt(Index, data),2718 .ty = @as(Index, @enumFromInt(data)),
2719 .val = .none,2719 .val = .none,
2720 } },2720 } },
2721 .opt_payload => {2721 .opt_payload => {
...@@ -2877,7 +2877,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -2877,7 +2877,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
2877 } },2877 } },
2878 .int_i32 => .{ .int = .{2878 .int_i32 => .{ .int = .{
2879 .ty = .i32_type,2879 .ty = .i32_type,
2880 .storage = .{ .i64 = @bitCast(i32, data) },2880 .storage = .{ .i64 = @as(i32, @bitCast(data)) },
2881 } },2881 } },
2882 .int_usize => .{ .int = .{2882 .int_usize => .{ .int = .{
2883 .ty = .usize_type,2883 .ty = .usize_type,
...@@ -2889,7 +2889,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -2889,7 +2889,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
2889 } },2889 } },
2890 .int_comptime_int_i32 => .{ .int = .{2890 .int_comptime_int_i32 => .{ .int = .{
2891 .ty = .comptime_int_type,2891 .ty = .comptime_int_type,
2892 .storage = .{ .i64 = @bitCast(i32, data) },2892 .storage = .{ .i64 = @as(i32, @bitCast(data)) },
2893 } },2893 } },
2894 .int_positive => ip.indexToKeyBigInt(data, true),2894 .int_positive => ip.indexToKeyBigInt(data, true),
2895 .int_negative => ip.indexToKeyBigInt(data, false),2895 .int_negative => ip.indexToKeyBigInt(data, false),
...@@ -2913,11 +2913,11 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -2913,11 +2913,11 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
2913 },2913 },
2914 .float_f16 => .{ .float = .{2914 .float_f16 => .{ .float = .{
2915 .ty = .f16_type,2915 .ty = .f16_type,
2916 .storage = .{ .f16 = @bitCast(f16, @intCast(u16, data)) },2916 .storage = .{ .f16 = @as(f16, @bitCast(@as(u16, @intCast(data)))) },
2917 } },2917 } },
2918 .float_f32 => .{ .float = .{2918 .float_f32 => .{ .float = .{
2919 .ty = .f32_type,2919 .ty = .f32_type,
2920 .storage = .{ .f32 = @bitCast(f32, data) },2920 .storage = .{ .f32 = @as(f32, @bitCast(data)) },
2921 } },2921 } },
2922 .float_f64 => .{ .float = .{2922 .float_f64 => .{ .float = .{
2923 .ty = .f64_type,2923 .ty = .f64_type,
...@@ -2959,13 +2959,13 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -2959,13 +2959,13 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
2959 .extern_func => .{ .extern_func = ip.extraData(Tag.ExternFunc, data) },2959 .extern_func => .{ .extern_func = ip.extraData(Tag.ExternFunc, data) },
2960 .func => .{ .func = ip.extraData(Tag.Func, data) },2960 .func => .{ .func = ip.extraData(Tag.Func, data) },
2961 .only_possible_value => {2961 .only_possible_value => {
2962 const ty = @enumFromInt(Index, data);2962 const ty = @as(Index, @enumFromInt(data));
2963 const ty_item = ip.items.get(@intFromEnum(ty));2963 const ty_item = ip.items.get(@intFromEnum(ty));
2964 return switch (ty_item.tag) {2964 return switch (ty_item.tag) {
2965 .type_array_big => {2965 .type_array_big => {
2966 const sentinel = @ptrCast(2966 const sentinel = @as(
2967 *const [1]Index,2967 *const [1]Index,
2968 &ip.extra.items[ty_item.data + std.meta.fieldIndex(Array, "sentinel").?],2968 @ptrCast(&ip.extra.items[ty_item.data + std.meta.fieldIndex(Array, "sentinel").?]),
2969 );2969 );
2970 return .{ .aggregate = .{2970 return .{ .aggregate = .{
2971 .ty = ty,2971 .ty = ty,
...@@ -2994,7 +2994,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -2994,7 +2994,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
2994 const values = ip.extra.items[type_struct_anon.end + fields_len ..][0..fields_len];2994 const values = ip.extra.items[type_struct_anon.end + fields_len ..][0..fields_len];
2995 return .{ .aggregate = .{2995 return .{ .aggregate = .{
2996 .ty = ty,2996 .ty = ty,
2997 .storage = .{ .elems = @ptrCast([]const Index, values) },2997 .storage = .{ .elems = @as([]const Index, @ptrCast(values)) },
2998 } };2998 } };
2999 },2999 },
30003000
...@@ -3010,7 +3010,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -3010,7 +3010,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
3010 },3010 },
3011 .bytes => {3011 .bytes => {
3012 const extra = ip.extraData(Bytes, data);3012 const extra = ip.extraData(Bytes, data);
3013 const len = @intCast(u32, ip.aggregateTypeLenIncludingSentinel(extra.ty));3013 const len = @as(u32, @intCast(ip.aggregateTypeLenIncludingSentinel(extra.ty)));
3014 return .{ .aggregate = .{3014 return .{ .aggregate = .{
3015 .ty = extra.ty,3015 .ty = extra.ty,
3016 .storage = .{ .bytes = ip.string_bytes.items[@intFromEnum(extra.bytes)..][0..len] },3016 .storage = .{ .bytes = ip.string_bytes.items[@intFromEnum(extra.bytes)..][0..len] },
...@@ -3018,8 +3018,8 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -3018,8 +3018,8 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
3018 },3018 },
3019 .aggregate => {3019 .aggregate => {
3020 const extra = ip.extraDataTrail(Tag.Aggregate, data);3020 const extra = ip.extraDataTrail(Tag.Aggregate, data);
3021 const len = @intCast(u32, ip.aggregateTypeLenIncludingSentinel(extra.data.ty));3021 const len = @as(u32, @intCast(ip.aggregateTypeLenIncludingSentinel(extra.data.ty)));
3022 const fields = @ptrCast([]const Index, ip.extra.items[extra.end..][0..len]);3022 const fields = @as([]const Index, @ptrCast(ip.extra.items[extra.end..][0..len]));
3023 return .{ .aggregate = .{3023 return .{ .aggregate = .{
3024 .ty = extra.data.ty,3024 .ty = extra.data.ty,
3025 .storage = .{ .elems = fields },3025 .storage = .{ .elems = fields },
...@@ -3048,14 +3048,14 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -3048,14 +3048,14 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
3048 .val = .{ .payload = extra.val },3048 .val = .{ .payload = extra.val },
3049 } };3049 } };
3050 },3050 },
3051 .enum_literal => .{ .enum_literal = @enumFromInt(NullTerminatedString, data) },3051 .enum_literal => .{ .enum_literal = @as(NullTerminatedString, @enumFromInt(data)) },
3052 .enum_tag => .{ .enum_tag = ip.extraData(Tag.EnumTag, data) },3052 .enum_tag => .{ .enum_tag = ip.extraData(Tag.EnumTag, data) },
30533053
3054 .memoized_call => {3054 .memoized_call => {
3055 const extra = ip.extraDataTrail(MemoizedCall, data);3055 const extra = ip.extraDataTrail(MemoizedCall, data);
3056 return .{ .memoized_call = .{3056 return .{ .memoized_call = .{
3057 .func = extra.data.func,3057 .func = extra.data.func,
3058 .arg_values = @ptrCast([]const Index, ip.extra.items[extra.end..][0..extra.data.args_len]),3058 .arg_values = @as([]const Index, @ptrCast(ip.extra.items[extra.end..][0..extra.data.args_len])),
3059 .result = extra.data.result,3059 .result = extra.data.result,
3060 } };3060 } };
3061 },3061 },
...@@ -3064,9 +3064,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -3064,9 +3064,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
30643064
3065fn indexToKeyFuncType(ip: *const InternPool, data: u32) Key.FuncType {3065fn indexToKeyFuncType(ip: *const InternPool, data: u32) Key.FuncType {
3066 const type_function = ip.extraDataTrail(TypeFunction, data);3066 const type_function = ip.extraDataTrail(TypeFunction, data);
3067 const param_types = @ptrCast(3067 const param_types = @as(
3068 []Index,3068 []Index,
3069 ip.extra.items[type_function.end..][0..type_function.data.params_len],3069 @ptrCast(ip.extra.items[type_function.end..][0..type_function.data.params_len]),
3070 );3070 );
3071 return .{3071 return .{
3072 .param_types = param_types,3072 .param_types = param_types,
...@@ -3087,13 +3087,13 @@ fn indexToKeyFuncType(ip: *const InternPool, data: u32) Key.FuncType {...@@ -3087,13 +3087,13 @@ fn indexToKeyFuncType(ip: *const InternPool, data: u32) Key.FuncType {
30873087
3088fn indexToKeyEnum(ip: *const InternPool, data: u32, tag_mode: Key.EnumType.TagMode) Key {3088fn indexToKeyEnum(ip: *const InternPool, data: u32, tag_mode: Key.EnumType.TagMode) Key {
3089 const enum_explicit = ip.extraDataTrail(EnumExplicit, data);3089 const enum_explicit = ip.extraDataTrail(EnumExplicit, data);
3090 const names = @ptrCast(3090 const names = @as(
3091 []const NullTerminatedString,3091 []const NullTerminatedString,
3092 ip.extra.items[enum_explicit.end..][0..enum_explicit.data.fields_len],3092 @ptrCast(ip.extra.items[enum_explicit.end..][0..enum_explicit.data.fields_len]),
3093 );3093 );
3094 const values = if (enum_explicit.data.values_map != .none) @ptrCast(3094 const values = if (enum_explicit.data.values_map != .none) @as(
3095 []const Index,3095 []const Index,
3096 ip.extra.items[enum_explicit.end + names.len ..][0..enum_explicit.data.fields_len],3096 @ptrCast(ip.extra.items[enum_explicit.end + names.len ..][0..enum_explicit.data.fields_len]),
3097 ) else &[0]Index{};3097 ) else &[0]Index{};
30983098
3099 return .{ .enum_type = .{3099 return .{ .enum_type = .{
...@@ -3122,7 +3122,7 @@ fn indexToKeyBigInt(ip: *const InternPool, limb_index: u32, positive: bool) Key...@@ -3122,7 +3122,7 @@ fn indexToKeyBigInt(ip: *const InternPool, limb_index: u32, positive: bool) Key
3122pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {3122pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3123 const adapter: KeyAdapter = .{ .intern_pool = ip };3123 const adapter: KeyAdapter = .{ .intern_pool = ip };
3124 const gop = try ip.map.getOrPutAdapted(gpa, key, adapter);3124 const gop = try ip.map.getOrPutAdapted(gpa, key, adapter);
3125 if (gop.found_existing) return @enumFromInt(Index, gop.index);3125 if (gop.found_existing) return @as(Index, @enumFromInt(gop.index));
3126 try ip.items.ensureUnusedCapacity(gpa, 1);3126 try ip.items.ensureUnusedCapacity(gpa, 1);
3127 switch (key) {3127 switch (key) {
3128 .int_type => |int_type| {3128 .int_type => |int_type| {
...@@ -3150,7 +3150,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3150,7 +3150,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3150 .tag = .type_slice,3150 .tag = .type_slice,
3151 .data = @intFromEnum(ptr_type_index),3151 .data = @intFromEnum(ptr_type_index),
3152 });3152 });
3153 return @enumFromInt(Index, ip.items.len - 1);3153 return @as(Index, @enumFromInt(ip.items.len - 1));
3154 }3154 }
31553155
3156 var ptr_type_adjusted = ptr_type;3156 var ptr_type_adjusted = ptr_type;
...@@ -3174,7 +3174,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3174,7 +3174,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3174 .child = array_type.child,3174 .child = array_type.child,
3175 }),3175 }),
3176 });3176 });
3177 return @enumFromInt(Index, ip.items.len - 1);3177 return @as(Index, @enumFromInt(ip.items.len - 1));
3178 }3178 }
3179 }3179 }
31803180
...@@ -3223,7 +3223,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3223,7 +3223,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3223 assert(std.sort.isSorted(NullTerminatedString, error_set_type.names, {}, NullTerminatedString.indexLessThan));3223 assert(std.sort.isSorted(NullTerminatedString, error_set_type.names, {}, NullTerminatedString.indexLessThan));
3224 const names_map = try ip.addMap(gpa);3224 const names_map = try ip.addMap(gpa);
3225 try addStringsToMap(ip, gpa, names_map, error_set_type.names);3225 try addStringsToMap(ip, gpa, names_map, error_set_type.names);
3226 const names_len = @intCast(u32, error_set_type.names.len);3226 const names_len = @as(u32, @intCast(error_set_type.names.len));
3227 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(ErrorSet).Struct.fields.len + names_len);3227 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(ErrorSet).Struct.fields.len + names_len);
3228 ip.items.appendAssumeCapacity(.{3228 ip.items.appendAssumeCapacity(.{
3229 .tag = .type_error_set,3229 .tag = .type_error_set,
...@@ -3232,7 +3232,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3232,7 +3232,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3232 .names_map = names_map,3232 .names_map = names_map,
3233 }),3233 }),
3234 });3234 });
3235 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, error_set_type.names));3235 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(error_set_type.names)));
3236 },3236 },
3237 .inferred_error_set_type => |ies_index| {3237 .inferred_error_set_type => |ies_index| {
3238 ip.items.appendAssumeCapacity(.{3238 ip.items.appendAssumeCapacity(.{
...@@ -3284,7 +3284,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3284,7 +3284,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3284 assert(anon_struct_type.types.len == anon_struct_type.values.len);3284 assert(anon_struct_type.types.len == anon_struct_type.values.len);
3285 for (anon_struct_type.types) |elem| assert(elem != .none);3285 for (anon_struct_type.types) |elem| assert(elem != .none);
32863286
3287 const fields_len = @intCast(u32, anon_struct_type.types.len);3287 const fields_len = @as(u32, @intCast(anon_struct_type.types.len));
3288 if (anon_struct_type.names.len == 0) {3288 if (anon_struct_type.names.len == 0) {
3289 try ip.extra.ensureUnusedCapacity(3289 try ip.extra.ensureUnusedCapacity(
3290 gpa,3290 gpa,
...@@ -3296,9 +3296,9 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3296,9 +3296,9 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3296 .fields_len = fields_len,3296 .fields_len = fields_len,
3297 }),3297 }),
3298 });3298 });
3299 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, anon_struct_type.types));3299 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(anon_struct_type.types)));
3300 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, anon_struct_type.values));3300 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(anon_struct_type.values)));
3301 return @enumFromInt(Index, ip.items.len - 1);3301 return @as(Index, @enumFromInt(ip.items.len - 1));
3302 }3302 }
33033303
3304 assert(anon_struct_type.names.len == anon_struct_type.types.len);3304 assert(anon_struct_type.names.len == anon_struct_type.types.len);
...@@ -3313,10 +3313,10 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3313,10 +3313,10 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3313 .fields_len = fields_len,3313 .fields_len = fields_len,
3314 }),3314 }),
3315 });3315 });
3316 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, anon_struct_type.types));3316 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(anon_struct_type.types)));
3317 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, anon_struct_type.values));3317 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(anon_struct_type.values)));
3318 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, anon_struct_type.names));3318 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(anon_struct_type.names)));
3319 return @enumFromInt(Index, ip.items.len - 1);3319 return @as(Index, @enumFromInt(ip.items.len - 1));
3320 },3320 },
33213321
3322 .union_type => |union_type| {3322 .union_type => |union_type| {
...@@ -3348,7 +3348,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3348,7 +3348,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3348 const names_map = try ip.addMap(gpa);3348 const names_map = try ip.addMap(gpa);
3349 try addStringsToMap(ip, gpa, names_map, enum_type.names);3349 try addStringsToMap(ip, gpa, names_map, enum_type.names);
33503350
3351 const fields_len = @intCast(u32, enum_type.names.len);3351 const fields_len = @as(u32, @intCast(enum_type.names.len));
3352 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(EnumAuto).Struct.fields.len +3352 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(EnumAuto).Struct.fields.len +
3353 fields_len);3353 fields_len);
3354 ip.items.appendAssumeCapacity(.{3354 ip.items.appendAssumeCapacity(.{
...@@ -3361,8 +3361,8 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3361,8 +3361,8 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3361 .fields_len = fields_len,3361 .fields_len = fields_len,
3362 }),3362 }),
3363 });3363 });
3364 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, enum_type.names));3364 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(enum_type.names)));
3365 return @enumFromInt(Index, ip.items.len - 1);3365 return @as(Index, @enumFromInt(ip.items.len - 1));
3366 },3366 },
3367 .explicit => return finishGetEnum(ip, gpa, enum_type, .type_enum_explicit),3367 .explicit => return finishGetEnum(ip, gpa, enum_type, .type_enum_explicit),
3368 .nonexhaustive => return finishGetEnum(ip, gpa, enum_type, .type_enum_nonexhaustive),3368 .nonexhaustive => return finishGetEnum(ip, gpa, enum_type, .type_enum_nonexhaustive),
...@@ -3373,7 +3373,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3373,7 +3373,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3373 assert(func_type.return_type != .none);3373 assert(func_type.return_type != .none);
3374 for (func_type.param_types) |param_type| assert(param_type != .none);3374 for (func_type.param_types) |param_type| assert(param_type != .none);
33753375
3376 const params_len = @intCast(u32, func_type.param_types.len);3376 const params_len = @as(u32, @intCast(func_type.param_types.len));
33773377
3378 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(TypeFunction).Struct.fields.len +3378 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(TypeFunction).Struct.fields.len +
3379 params_len);3379 params_len);
...@@ -3397,7 +3397,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3397,7 +3397,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3397 },3397 },
3398 }),3398 }),
3399 });3399 });
3400 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, func_type.param_types));3400 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(func_type.param_types)));
3401 },3401 },
34023402
3403 .variable => |variable| {3403 .variable => |variable| {
...@@ -3559,7 +3559,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3559,7 +3559,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3559 });3559 });
3560 },3560 },
3561 }3561 }
3562 assert(ptr.ty == ip.indexToKey(@enumFromInt(Index, ip.items.len - 1)).ptr.ty);3562 assert(ptr.ty == ip.indexToKey(@as(Index, @enumFromInt(ip.items.len - 1))).ptr.ty);
3563 },3563 },
35643564
3565 .opt => |opt| {3565 .opt => |opt| {
...@@ -3593,7 +3593,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3593,7 +3593,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3593 .lazy_ty = lazy_ty,3593 .lazy_ty = lazy_ty,
3594 }),3594 }),
3595 });3595 });
3596 return @enumFromInt(Index, ip.items.len - 1);3596 return @as(Index, @enumFromInt(ip.items.len - 1));
3597 },3597 },
3598 }3598 }
3599 switch (int.ty) {3599 switch (int.ty) {
...@@ -3608,7 +3608,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3608,7 +3608,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3608 inline .u64, .i64 => |x| {3608 inline .u64, .i64 => |x| {
3609 ip.items.appendAssumeCapacity(.{3609 ip.items.appendAssumeCapacity(.{
3610 .tag = .int_u8,3610 .tag = .int_u8,
3611 .data = @intCast(u8, x),3611 .data = @as(u8, @intCast(x)),
3612 });3612 });
3613 break :b;3613 break :b;
3614 },3614 },
...@@ -3625,7 +3625,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3625,7 +3625,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3625 inline .u64, .i64 => |x| {3625 inline .u64, .i64 => |x| {
3626 ip.items.appendAssumeCapacity(.{3626 ip.items.appendAssumeCapacity(.{
3627 .tag = .int_u16,3627 .tag = .int_u16,
3628 .data = @intCast(u16, x),3628 .data = @as(u16, @intCast(x)),
3629 });3629 });
3630 break :b;3630 break :b;
3631 },3631 },
...@@ -3642,7 +3642,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3642,7 +3642,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3642 inline .u64, .i64 => |x| {3642 inline .u64, .i64 => |x| {
3643 ip.items.appendAssumeCapacity(.{3643 ip.items.appendAssumeCapacity(.{
3644 .tag = .int_u32,3644 .tag = .int_u32,
3645 .data = @intCast(u32, x),3645 .data = @as(u32, @intCast(x)),
3646 });3646 });
3647 break :b;3647 break :b;
3648 },3648 },
...@@ -3653,14 +3653,14 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3653,14 +3653,14 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3653 const casted = big_int.to(i32) catch unreachable;3653 const casted = big_int.to(i32) catch unreachable;
3654 ip.items.appendAssumeCapacity(.{3654 ip.items.appendAssumeCapacity(.{
3655 .tag = .int_i32,3655 .tag = .int_i32,
3656 .data = @bitCast(u32, casted),3656 .data = @as(u32, @bitCast(casted)),
3657 });3657 });
3658 break :b;3658 break :b;
3659 },3659 },
3660 inline .u64, .i64 => |x| {3660 inline .u64, .i64 => |x| {
3661 ip.items.appendAssumeCapacity(.{3661 ip.items.appendAssumeCapacity(.{
3662 .tag = .int_i32,3662 .tag = .int_i32,
3663 .data = @bitCast(u32, @intCast(i32, x)),3663 .data = @as(u32, @bitCast(@as(i32, @intCast(x)))),
3664 });3664 });
3665 break :b;3665 break :b;
3666 },3666 },
...@@ -3699,7 +3699,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3699,7 +3699,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3699 if (big_int.to(i32)) |casted| {3699 if (big_int.to(i32)) |casted| {
3700 ip.items.appendAssumeCapacity(.{3700 ip.items.appendAssumeCapacity(.{
3701 .tag = .int_comptime_int_i32,3701 .tag = .int_comptime_int_i32,
3702 .data = @bitCast(u32, casted),3702 .data = @as(u32, @bitCast(casted)),
3703 });3703 });
3704 break :b;3704 break :b;
3705 } else |_| {}3705 } else |_| {}
...@@ -3715,7 +3715,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3715,7 +3715,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3715 if (std.math.cast(i32, x)) |casted| {3715 if (std.math.cast(i32, x)) |casted| {
3716 ip.items.appendAssumeCapacity(.{3716 ip.items.appendAssumeCapacity(.{
3717 .tag = .int_comptime_int_i32,3717 .tag = .int_comptime_int_i32,
3718 .data = @bitCast(u32, casted),3718 .data = @as(u32, @bitCast(casted)),
3719 });3719 });
3720 break :b;3720 break :b;
3721 }3721 }
...@@ -3734,7 +3734,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3734,7 +3734,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3734 .value = casted,3734 .value = casted,
3735 }),3735 }),
3736 });3736 });
3737 return @enumFromInt(Index, ip.items.len - 1);3737 return @as(Index, @enumFromInt(ip.items.len - 1));
3738 } else |_| {}3738 } else |_| {}
37393739
3740 const tag: Tag = if (big_int.positive) .int_positive else .int_negative;3740 const tag: Tag = if (big_int.positive) .int_positive else .int_negative;
...@@ -3749,7 +3749,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3749,7 +3749,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3749 .value = casted,3749 .value = casted,
3750 }),3750 }),
3751 });3751 });
3752 return @enumFromInt(Index, ip.items.len - 1);3752 return @as(Index, @enumFromInt(ip.items.len - 1));
3753 }3753 }
37543754
3755 var buf: [2]Limb = undefined;3755 var buf: [2]Limb = undefined;
...@@ -3816,11 +3816,11 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3816,11 +3816,11 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3816 switch (float.ty) {3816 switch (float.ty) {
3817 .f16_type => ip.items.appendAssumeCapacity(.{3817 .f16_type => ip.items.appendAssumeCapacity(.{
3818 .tag = .float_f16,3818 .tag = .float_f16,
3819 .data = @bitCast(u16, float.storage.f16),3819 .data = @as(u16, @bitCast(float.storage.f16)),
3820 }),3820 }),
3821 .f32_type => ip.items.appendAssumeCapacity(.{3821 .f32_type => ip.items.appendAssumeCapacity(.{
3822 .tag = .float_f32,3822 .tag = .float_f32,
3823 .data = @bitCast(u32, float.storage.f32),3823 .data = @as(u32, @bitCast(float.storage.f32)),
3824 }),3824 }),
3825 .f64_type => ip.items.appendAssumeCapacity(.{3825 .f64_type => ip.items.appendAssumeCapacity(.{
3826 .tag = .float_f64,3826 .tag = .float_f64,
...@@ -3872,13 +3872,13 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3872,13 +3872,13 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3872 assert(child == .u8_type);3872 assert(child == .u8_type);
3873 if (bytes.len != len) {3873 if (bytes.len != len) {
3874 assert(bytes.len == len_including_sentinel);3874 assert(bytes.len == len_including_sentinel);
3875 assert(bytes[@intCast(usize, len)] == ip.indexToKey(sentinel).int.storage.u64);3875 assert(bytes[@as(usize, @intCast(len))] == ip.indexToKey(sentinel).int.storage.u64);
3876 }3876 }
3877 },3877 },
3878 .elems => |elems| {3878 .elems => |elems| {
3879 if (elems.len != len) {3879 if (elems.len != len) {
3880 assert(elems.len == len_including_sentinel);3880 assert(elems.len == len_including_sentinel);
3881 assert(elems[@intCast(usize, len)] == sentinel);3881 assert(elems[@as(usize, @intCast(len))] == sentinel);
3882 }3882 }
3883 },3883 },
3884 .repeated_elem => |elem| {3884 .repeated_elem => |elem| {
...@@ -3912,7 +3912,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3912,7 +3912,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3912 .tag = .only_possible_value,3912 .tag = .only_possible_value,
3913 .data = @intFromEnum(aggregate.ty),3913 .data = @intFromEnum(aggregate.ty),
3914 });3914 });
3915 return @enumFromInt(Index, ip.items.len - 1);3915 return @as(Index, @enumFromInt(ip.items.len - 1));
3916 }3916 }
39173917
3918 switch (ty_key) {3918 switch (ty_key) {
...@@ -3940,16 +3940,16 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3940,16 +3940,16 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3940 .tag = .only_possible_value,3940 .tag = .only_possible_value,
3941 .data = @intFromEnum(aggregate.ty),3941 .data = @intFromEnum(aggregate.ty),
3942 });3942 });
3943 return @enumFromInt(Index, ip.items.len - 1);3943 return @as(Index, @enumFromInt(ip.items.len - 1));
3944 },3944 },
3945 else => {},3945 else => {},
3946 }3946 }
39473947
3948 repeated: {3948 repeated: {
3949 switch (aggregate.storage) {3949 switch (aggregate.storage) {
3950 .bytes => |bytes| for (bytes[1..@intCast(usize, len)]) |byte|3950 .bytes => |bytes| for (bytes[1..@as(usize, @intCast(len))]) |byte|
3951 if (byte != bytes[0]) break :repeated,3951 if (byte != bytes[0]) break :repeated,
3952 .elems => |elems| for (elems[1..@intCast(usize, len)]) |elem|3952 .elems => |elems| for (elems[1..@as(usize, @intCast(len))]) |elem|
3953 if (elem != elems[0]) break :repeated,3953 if (elem != elems[0]) break :repeated,
3954 .repeated_elem => {},3954 .repeated_elem => {},
3955 }3955 }
...@@ -3979,12 +3979,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3979,12 +3979,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3979 .elem_val = elem,3979 .elem_val = elem,
3980 }),3980 }),
3981 });3981 });
3982 return @enumFromInt(Index, ip.items.len - 1);3982 return @as(Index, @enumFromInt(ip.items.len - 1));
3983 }3983 }
39843984
3985 if (child == .u8_type) bytes: {3985 if (child == .u8_type) bytes: {
3986 const string_bytes_index = ip.string_bytes.items.len;3986 const string_bytes_index = ip.string_bytes.items.len;
3987 try ip.string_bytes.ensureUnusedCapacity(gpa, @intCast(usize, len_including_sentinel + 1));3987 try ip.string_bytes.ensureUnusedCapacity(gpa, @as(usize, @intCast(len_including_sentinel + 1)));
3988 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Bytes).Struct.fields.len);3988 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Bytes).Struct.fields.len);
3989 switch (aggregate.storage) {3989 switch (aggregate.storage) {
3990 .bytes => |bytes| ip.string_bytes.appendSliceAssumeCapacity(bytes),3990 .bytes => |bytes| ip.string_bytes.appendSliceAssumeCapacity(bytes),
...@@ -3994,15 +3994,15 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3994,15 +3994,15 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3994 break :bytes;3994 break :bytes;
3995 },3995 },
3996 .int => |int| ip.string_bytes.appendAssumeCapacity(3996 .int => |int| ip.string_bytes.appendAssumeCapacity(
3997 @intCast(u8, int.storage.u64),3997 @as(u8, @intCast(int.storage.u64)),
3998 ),3998 ),
3999 else => unreachable,3999 else => unreachable,
4000 },4000 },
4001 .repeated_elem => |elem| switch (ip.indexToKey(elem)) {4001 .repeated_elem => |elem| switch (ip.indexToKey(elem)) {
4002 .undef => break :bytes,4002 .undef => break :bytes,
4003 .int => |int| @memset(4003 .int => |int| @memset(
4004 ip.string_bytes.addManyAsSliceAssumeCapacity(@intCast(usize, len)),4004 ip.string_bytes.addManyAsSliceAssumeCapacity(@as(usize, @intCast(len))),
4005 @intCast(u8, int.storage.u64),4005 @as(u8, @intCast(int.storage.u64)),
4006 ),4006 ),
4007 else => unreachable,4007 else => unreachable,
4008 },4008 },
...@@ -4010,12 +4010,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -4010,12 +4010,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
4010 const has_internal_null =4010 const has_internal_null =
4011 std.mem.indexOfScalar(u8, ip.string_bytes.items[string_bytes_index..], 0) != null;4011 std.mem.indexOfScalar(u8, ip.string_bytes.items[string_bytes_index..], 0) != null;
4012 if (sentinel != .none) ip.string_bytes.appendAssumeCapacity(4012 if (sentinel != .none) ip.string_bytes.appendAssumeCapacity(
4013 @intCast(u8, ip.indexToKey(sentinel).int.storage.u64),4013 @as(u8, @intCast(ip.indexToKey(sentinel).int.storage.u64)),
4014 );4014 );
4015 const string = if (has_internal_null)4015 const string = if (has_internal_null)
4016 @enumFromInt(String, string_bytes_index)4016 @as(String, @enumFromInt(string_bytes_index))
4017 else4017 else
4018 (try ip.getOrPutTrailingString(gpa, @intCast(usize, len_including_sentinel))).toString();4018 (try ip.getOrPutTrailingString(gpa, @as(usize, @intCast(len_including_sentinel)))).toString();
4019 ip.items.appendAssumeCapacity(.{4019 ip.items.appendAssumeCapacity(.{
4020 .tag = .bytes,4020 .tag = .bytes,
4021 .data = ip.addExtraAssumeCapacity(Bytes{4021 .data = ip.addExtraAssumeCapacity(Bytes{
...@@ -4023,12 +4023,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -4023,12 +4023,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
4023 .bytes = string,4023 .bytes = string,
4024 }),4024 }),
4025 });4025 });
4026 return @enumFromInt(Index, ip.items.len - 1);4026 return @as(Index, @enumFromInt(ip.items.len - 1));
4027 }4027 }
40284028
4029 try ip.extra.ensureUnusedCapacity(4029 try ip.extra.ensureUnusedCapacity(
4030 gpa,4030 gpa,
4031 @typeInfo(Tag.Aggregate).Struct.fields.len + @intCast(usize, len_including_sentinel),4031 @typeInfo(Tag.Aggregate).Struct.fields.len + @as(usize, @intCast(len_including_sentinel)),
4032 );4032 );
4033 ip.items.appendAssumeCapacity(.{4033 ip.items.appendAssumeCapacity(.{
4034 .tag = .aggregate,4034 .tag = .aggregate,
...@@ -4036,7 +4036,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -4036,7 +4036,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
4036 .ty = aggregate.ty,4036 .ty = aggregate.ty,
4037 }),4037 }),
4038 });4038 });
4039 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, aggregate.storage.elems));4039 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(aggregate.storage.elems)));
4040 if (sentinel != .none) ip.extra.appendAssumeCapacity(@intFromEnum(sentinel));4040 if (sentinel != .none) ip.extra.appendAssumeCapacity(@intFromEnum(sentinel));
4041 },4041 },
40424042
...@@ -4058,14 +4058,14 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -4058,14 +4058,14 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
4058 .tag = .memoized_call,4058 .tag = .memoized_call,
4059 .data = ip.addExtraAssumeCapacity(MemoizedCall{4059 .data = ip.addExtraAssumeCapacity(MemoizedCall{
4060 .func = memoized_call.func,4060 .func = memoized_call.func,
4061 .args_len = @intCast(u32, memoized_call.arg_values.len),4061 .args_len = @as(u32, @intCast(memoized_call.arg_values.len)),
4062 .result = memoized_call.result,4062 .result = memoized_call.result,
4063 }),4063 }),
4064 });4064 });
4065 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, memoized_call.arg_values));4065 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(memoized_call.arg_values)));
4066 },4066 },
4067 }4067 }
4068 return @enumFromInt(Index, ip.items.len - 1);4068 return @as(Index, @enumFromInt(ip.items.len - 1));
4069}4069}
40704070
4071/// Provides API for completing an enum type after calling `getIncompleteEnum`.4071/// Provides API for completing an enum type after calling `getIncompleteEnum`.
...@@ -4093,10 +4093,10 @@ pub const IncompleteEnumType = struct {...@@ -4093,10 +4093,10 @@ pub const IncompleteEnumType = struct {
4093 const field_index = map.count();4093 const field_index = map.count();
4094 const strings = ip.extra.items[self.names_start..][0..field_index];4094 const strings = ip.extra.items[self.names_start..][0..field_index];
4095 const adapter: NullTerminatedString.Adapter = .{4095 const adapter: NullTerminatedString.Adapter = .{
4096 .strings = @ptrCast([]const NullTerminatedString, strings),4096 .strings = @as([]const NullTerminatedString, @ptrCast(strings)),
4097 };4097 };
4098 const gop = try map.getOrPutAdapted(gpa, name, adapter);4098 const gop = try map.getOrPutAdapted(gpa, name, adapter);
4099 if (gop.found_existing) return @intCast(u32, gop.index);4099 if (gop.found_existing) return @as(u32, @intCast(gop.index));
4100 ip.extra.items[self.names_start + field_index] = @intFromEnum(name);4100 ip.extra.items[self.names_start + field_index] = @intFromEnum(name);
4101 return null;4101 return null;
4102 }4102 }
...@@ -4109,15 +4109,15 @@ pub const IncompleteEnumType = struct {...@@ -4109,15 +4109,15 @@ pub const IncompleteEnumType = struct {
4109 gpa: Allocator,4109 gpa: Allocator,
4110 value: Index,4110 value: Index,
4111 ) Allocator.Error!?u32 {4111 ) Allocator.Error!?u32 {
4112 assert(ip.typeOf(value) == @enumFromInt(Index, ip.extra.items[self.tag_ty_index]));4112 assert(ip.typeOf(value) == @as(Index, @enumFromInt(ip.extra.items[self.tag_ty_index])));
4113 const map = &ip.maps.items[@intFromEnum(self.values_map.unwrap().?)];4113 const map = &ip.maps.items[@intFromEnum(self.values_map.unwrap().?)];
4114 const field_index = map.count();4114 const field_index = map.count();
4115 const indexes = ip.extra.items[self.values_start..][0..field_index];4115 const indexes = ip.extra.items[self.values_start..][0..field_index];
4116 const adapter: Index.Adapter = .{4116 const adapter: Index.Adapter = .{
4117 .indexes = @ptrCast([]const Index, indexes),4117 .indexes = @as([]const Index, @ptrCast(indexes)),
4118 };4118 };
4119 const gop = try map.getOrPutAdapted(gpa, value, adapter);4119 const gop = try map.getOrPutAdapted(gpa, value, adapter);
4120 if (gop.found_existing) return @intCast(u32, gop.index);4120 if (gop.found_existing) return @as(u32, @intCast(gop.index));
4121 ip.extra.items[self.values_start + field_index] = @intFromEnum(value);4121 ip.extra.items[self.values_start + field_index] = @intFromEnum(value);
4122 return null;4122 return null;
4123 }4123 }
...@@ -4177,7 +4177,7 @@ fn getIncompleteEnumAuto(...@@ -4177,7 +4177,7 @@ fn getIncompleteEnumAuto(
4177 });4177 });
4178 ip.extra.appendNTimesAssumeCapacity(@intFromEnum(Index.none), enum_type.fields_len);4178 ip.extra.appendNTimesAssumeCapacity(@intFromEnum(Index.none), enum_type.fields_len);
4179 return .{4179 return .{
4180 .index = @enumFromInt(Index, ip.items.len - 1),4180 .index = @as(Index, @enumFromInt(ip.items.len - 1)),
4181 .tag_ty_index = extra_index + std.meta.fieldIndex(EnumAuto, "int_tag_type").?,4181 .tag_ty_index = extra_index + std.meta.fieldIndex(EnumAuto, "int_tag_type").?,
4182 .names_map = names_map,4182 .names_map = names_map,
4183 .names_start = extra_index + extra_fields_len,4183 .names_start = extra_index + extra_fields_len,
...@@ -4228,7 +4228,7 @@ fn getIncompleteEnumExplicit(...@@ -4228,7 +4228,7 @@ fn getIncompleteEnumExplicit(
4228 // This is both fields and values (if present).4228 // This is both fields and values (if present).
4229 ip.extra.appendNTimesAssumeCapacity(@intFromEnum(Index.none), reserved_len);4229 ip.extra.appendNTimesAssumeCapacity(@intFromEnum(Index.none), reserved_len);
4230 return .{4230 return .{
4231 .index = @enumFromInt(Index, ip.items.len - 1),4231 .index = @as(Index, @enumFromInt(ip.items.len - 1)),
4232 .tag_ty_index = extra_index + std.meta.fieldIndex(EnumExplicit, "int_tag_type").?,4232 .tag_ty_index = extra_index + std.meta.fieldIndex(EnumExplicit, "int_tag_type").?,
4233 .names_map = names_map,4233 .names_map = names_map,
4234 .names_start = extra_index + extra_fields_len,4234 .names_start = extra_index + extra_fields_len,
...@@ -4251,7 +4251,7 @@ pub fn finishGetEnum(...@@ -4251,7 +4251,7 @@ pub fn finishGetEnum(
4251 try addIndexesToMap(ip, gpa, values_map, enum_type.values);4251 try addIndexesToMap(ip, gpa, values_map, enum_type.values);
4252 break :m values_map.toOptional();4252 break :m values_map.toOptional();
4253 };4253 };
4254 const fields_len = @intCast(u32, enum_type.names.len);4254 const fields_len = @as(u32, @intCast(enum_type.names.len));
4255 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(EnumExplicit).Struct.fields.len +4255 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(EnumExplicit).Struct.fields.len +
4256 fields_len);4256 fields_len);
4257 ip.items.appendAssumeCapacity(.{4257 ip.items.appendAssumeCapacity(.{
...@@ -4265,15 +4265,15 @@ pub fn finishGetEnum(...@@ -4265,15 +4265,15 @@ pub fn finishGetEnum(
4265 .values_map = values_map,4265 .values_map = values_map,
4266 }),4266 }),
4267 });4267 });
4268 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, enum_type.names));4268 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(enum_type.names)));
4269 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, enum_type.values));4269 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(enum_type.values)));
4270 return @enumFromInt(Index, ip.items.len - 1);4270 return @as(Index, @enumFromInt(ip.items.len - 1));
4271}4271}
42724272
4273pub fn getIfExists(ip: *const InternPool, key: Key) ?Index {4273pub fn getIfExists(ip: *const InternPool, key: Key) ?Index {
4274 const adapter: KeyAdapter = .{ .intern_pool = ip };4274 const adapter: KeyAdapter = .{ .intern_pool = ip };
4275 const index = ip.map.getIndexAdapted(key, adapter) orelse return null;4275 const index = ip.map.getIndexAdapted(key, adapter) orelse return null;
4276 return @enumFromInt(Index, index);4276 return @as(Index, @enumFromInt(index));
4277}4277}
42784278
4279pub fn getAssumeExists(ip: *const InternPool, key: Key) Index {4279pub fn getAssumeExists(ip: *const InternPool, key: Key) Index {
...@@ -4311,7 +4311,7 @@ fn addIndexesToMap(...@@ -4311,7 +4311,7 @@ fn addIndexesToMap(
4311fn addMap(ip: *InternPool, gpa: Allocator) Allocator.Error!MapIndex {4311fn addMap(ip: *InternPool, gpa: Allocator) Allocator.Error!MapIndex {
4312 const ptr = try ip.maps.addOne(gpa);4312 const ptr = try ip.maps.addOne(gpa);
4313 ptr.* = .{};4313 ptr.* = .{};
4314 return @enumFromInt(MapIndex, ip.maps.items.len - 1);4314 return @as(MapIndex, @enumFromInt(ip.maps.items.len - 1));
4315}4315}
43164316
4317/// This operation only happens under compile error conditions.4317/// This operation only happens under compile error conditions.
...@@ -4320,7 +4320,7 @@ fn addMap(ip: *InternPool, gpa: Allocator) Allocator.Error!MapIndex {...@@ -4320,7 +4320,7 @@ fn addMap(ip: *InternPool, gpa: Allocator) Allocator.Error!MapIndex {
4320pub const remove = @compileError("InternPool.remove is not currently a supported operation; put a TODO there instead");4320pub const remove = @compileError("InternPool.remove is not currently a supported operation; put a TODO there instead");
43214321
4322fn addInt(ip: *InternPool, gpa: Allocator, ty: Index, tag: Tag, limbs: []const Limb) !void {4322fn addInt(ip: *InternPool, gpa: Allocator, ty: Index, tag: Tag, limbs: []const Limb) !void {
4323 const limbs_len = @intCast(u32, limbs.len);4323 const limbs_len = @as(u32, @intCast(limbs.len));
4324 try ip.reserveLimbs(gpa, @typeInfo(Int).Struct.fields.len + limbs_len);4324 try ip.reserveLimbs(gpa, @typeInfo(Int).Struct.fields.len + limbs_len);
4325 ip.items.appendAssumeCapacity(.{4325 ip.items.appendAssumeCapacity(.{
4326 .tag = tag,4326 .tag = tag,
...@@ -4339,7 +4339,7 @@ fn addExtra(ip: *InternPool, gpa: Allocator, extra: anytype) Allocator.Error!u32...@@ -4339,7 +4339,7 @@ fn addExtra(ip: *InternPool, gpa: Allocator, extra: anytype) Allocator.Error!u32
4339}4339}
43404340
4341fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {4341fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
4342 const result = @intCast(u32, ip.extra.items.len);4342 const result = @as(u32, @intCast(ip.extra.items.len));
4343 inline for (@typeInfo(@TypeOf(extra)).Struct.fields) |field| {4343 inline for (@typeInfo(@TypeOf(extra)).Struct.fields) |field| {
4344 ip.extra.appendAssumeCapacity(switch (field.type) {4344 ip.extra.appendAssumeCapacity(switch (field.type) {
4345 u32 => @field(extra, field.name),4345 u32 => @field(extra, field.name),
...@@ -4354,12 +4354,12 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {...@@ -4354,12 +4354,12 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
4354 String => @intFromEnum(@field(extra, field.name)),4354 String => @intFromEnum(@field(extra, field.name)),
4355 NullTerminatedString => @intFromEnum(@field(extra, field.name)),4355 NullTerminatedString => @intFromEnum(@field(extra, field.name)),
4356 OptionalNullTerminatedString => @intFromEnum(@field(extra, field.name)),4356 OptionalNullTerminatedString => @intFromEnum(@field(extra, field.name)),
4357 i32 => @bitCast(u32, @field(extra, field.name)),4357 i32 => @as(u32, @bitCast(@field(extra, field.name))),
4358 Tag.TypePointer.Flags => @bitCast(u32, @field(extra, field.name)),4358 Tag.TypePointer.Flags => @as(u32, @bitCast(@field(extra, field.name))),
4359 TypeFunction.Flags => @bitCast(u32, @field(extra, field.name)),4359 TypeFunction.Flags => @as(u32, @bitCast(@field(extra, field.name))),
4360 Tag.TypePointer.PackedOffset => @bitCast(u32, @field(extra, field.name)),4360 Tag.TypePointer.PackedOffset => @as(u32, @bitCast(@field(extra, field.name))),
4361 Tag.TypePointer.VectorIndex => @intFromEnum(@field(extra, field.name)),4361 Tag.TypePointer.VectorIndex => @intFromEnum(@field(extra, field.name)),
4362 Tag.Variable.Flags => @bitCast(u32, @field(extra, field.name)),4362 Tag.Variable.Flags => @as(u32, @bitCast(@field(extra, field.name))),
4363 else => @compileError("bad field type: " ++ @typeName(field.type)),4363 else => @compileError("bad field type: " ++ @typeName(field.type)),
4364 });4364 });
4365 }4365 }
...@@ -4380,7 +4380,7 @@ fn addLimbsExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {...@@ -4380,7 +4380,7 @@ fn addLimbsExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
4380 @sizeOf(u64) => {},4380 @sizeOf(u64) => {},
4381 else => @compileError("unsupported host"),4381 else => @compileError("unsupported host"),
4382 }4382 }
4383 const result = @intCast(u32, ip.limbs.items.len);4383 const result = @as(u32, @intCast(ip.limbs.items.len));
4384 inline for (@typeInfo(@TypeOf(extra)).Struct.fields, 0..) |field, i| {4384 inline for (@typeInfo(@TypeOf(extra)).Struct.fields, 0..) |field, i| {
4385 const new: u32 = switch (field.type) {4385 const new: u32 = switch (field.type) {
4386 u32 => @field(extra, field.name),4386 u32 => @field(extra, field.name),
...@@ -4411,23 +4411,23 @@ fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct...@@ -4411,23 +4411,23 @@ fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct
4411 const int32 = ip.extra.items[i + index];4411 const int32 = ip.extra.items[i + index];
4412 @field(result, field.name) = switch (field.type) {4412 @field(result, field.name) = switch (field.type) {
4413 u32 => int32,4413 u32 => int32,
4414 Index => @enumFromInt(Index, int32),4414 Index => @as(Index, @enumFromInt(int32)),
4415 Module.Decl.Index => @enumFromInt(Module.Decl.Index, int32),4415 Module.Decl.Index => @as(Module.Decl.Index, @enumFromInt(int32)),
4416 Module.Namespace.Index => @enumFromInt(Module.Namespace.Index, int32),4416 Module.Namespace.Index => @as(Module.Namespace.Index, @enumFromInt(int32)),
4417 Module.Namespace.OptionalIndex => @enumFromInt(Module.Namespace.OptionalIndex, int32),4417 Module.Namespace.OptionalIndex => @as(Module.Namespace.OptionalIndex, @enumFromInt(int32)),
4418 Module.Fn.Index => @enumFromInt(Module.Fn.Index, int32),4418 Module.Fn.Index => @as(Module.Fn.Index, @enumFromInt(int32)),
4419 MapIndex => @enumFromInt(MapIndex, int32),4419 MapIndex => @as(MapIndex, @enumFromInt(int32)),
4420 OptionalMapIndex => @enumFromInt(OptionalMapIndex, int32),4420 OptionalMapIndex => @as(OptionalMapIndex, @enumFromInt(int32)),
4421 RuntimeIndex => @enumFromInt(RuntimeIndex, int32),4421 RuntimeIndex => @as(RuntimeIndex, @enumFromInt(int32)),
4422 String => @enumFromInt(String, int32),4422 String => @as(String, @enumFromInt(int32)),
4423 NullTerminatedString => @enumFromInt(NullTerminatedString, int32),4423 NullTerminatedString => @as(NullTerminatedString, @enumFromInt(int32)),
4424 OptionalNullTerminatedString => @enumFromInt(OptionalNullTerminatedString, int32),4424 OptionalNullTerminatedString => @as(OptionalNullTerminatedString, @enumFromInt(int32)),
4425 i32 => @bitCast(i32, int32),4425 i32 => @as(i32, @bitCast(int32)),
4426 Tag.TypePointer.Flags => @bitCast(Tag.TypePointer.Flags, int32),4426 Tag.TypePointer.Flags => @as(Tag.TypePointer.Flags, @bitCast(int32)),
4427 TypeFunction.Flags => @bitCast(TypeFunction.Flags, int32),4427 TypeFunction.Flags => @as(TypeFunction.Flags, @bitCast(int32)),
4428 Tag.TypePointer.PackedOffset => @bitCast(Tag.TypePointer.PackedOffset, int32),4428 Tag.TypePointer.PackedOffset => @as(Tag.TypePointer.PackedOffset, @bitCast(int32)),
4429 Tag.TypePointer.VectorIndex => @enumFromInt(Tag.TypePointer.VectorIndex, int32),4429 Tag.TypePointer.VectorIndex => @as(Tag.TypePointer.VectorIndex, @enumFromInt(int32)),
4430 Tag.Variable.Flags => @bitCast(Tag.Variable.Flags, int32),4430 Tag.Variable.Flags => @as(Tag.Variable.Flags, @bitCast(int32)),
4431 else => @compileError("bad field type: " ++ @typeName(field.type)),4431 else => @compileError("bad field type: " ++ @typeName(field.type)),
4432 };4432 };
4433 }4433 }
...@@ -4452,13 +4452,13 @@ fn limbData(ip: *const InternPool, comptime T: type, index: usize) T {...@@ -4452,13 +4452,13 @@ fn limbData(ip: *const InternPool, comptime T: type, index: usize) T {
4452 inline for (@typeInfo(T).Struct.fields, 0..) |field, i| {4452 inline for (@typeInfo(T).Struct.fields, 0..) |field, i| {
4453 const host_int = ip.limbs.items[index + i / 2];4453 const host_int = ip.limbs.items[index + i / 2];
4454 const int32 = if (i % 2 == 0)4454 const int32 = if (i % 2 == 0)
4455 @truncate(u32, host_int)4455 @as(u32, @truncate(host_int))
4456 else4456 else
4457 @truncate(u32, host_int >> 32);4457 @as(u32, @truncate(host_int >> 32));
44584458
4459 @field(result, field.name) = switch (field.type) {4459 @field(result, field.name) = switch (field.type) {
4460 u32 => int32,4460 u32 => int32,
4461 Index => @enumFromInt(Index, int32),4461 Index => @as(Index, @enumFromInt(int32)),
4462 else => @compileError("bad field type: " ++ @typeName(field.type)),4462 else => @compileError("bad field type: " ++ @typeName(field.type)),
4463 };4463 };
4464 }4464 }
...@@ -4494,8 +4494,8 @@ fn limbsSliceToIndex(ip: *const InternPool, limbs: []const Limb) LimbsAsIndexes...@@ -4494,8 +4494,8 @@ fn limbsSliceToIndex(ip: *const InternPool, limbs: []const Limb) LimbsAsIndexes
4494 };4494 };
4495 // TODO: https://github.com/ziglang/zig/issues/17384495 // TODO: https://github.com/ziglang/zig/issues/1738
4496 return .{4496 return .{
4497 .start = @intCast(u32, @divExact(@intFromPtr(limbs.ptr) - @intFromPtr(host_slice.ptr), @sizeOf(Limb))),4497 .start = @as(u32, @intCast(@divExact(@intFromPtr(limbs.ptr) - @intFromPtr(host_slice.ptr), @sizeOf(Limb)))),
4498 .len = @intCast(u32, limbs.len),4498 .len = @as(u32, @intCast(limbs.len)),
4499 };4499 };
4500}4500}
45014501
...@@ -4557,7 +4557,7 @@ pub fn slicePtrType(ip: *const InternPool, i: Index) Index {...@@ -4557,7 +4557,7 @@ pub fn slicePtrType(ip: *const InternPool, i: Index) Index {
4557 }4557 }
4558 const item = ip.items.get(@intFromEnum(i));4558 const item = ip.items.get(@intFromEnum(i));
4559 switch (item.tag) {4559 switch (item.tag) {
4560 .type_slice => return @enumFromInt(Index, item.data),4560 .type_slice => return @as(Index, @enumFromInt(item.data)),
4561 else => unreachable, // not a slice type4561 else => unreachable, // not a slice type
4562 }4562 }
4563}4563}
...@@ -4727,7 +4727,7 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al...@@ -4727,7 +4727,7 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al
4727 .val = error_union.val,4727 .val = error_union.val,
4728 } }),4728 } }),
4729 .aggregate => |aggregate| {4729 .aggregate => |aggregate| {
4730 const new_len = @intCast(usize, ip.aggregateTypeLen(new_ty));4730 const new_len = @as(usize, @intCast(ip.aggregateTypeLen(new_ty)));
4731 direct: {4731 direct: {
4732 const old_ty_child = switch (ip.indexToKey(old_ty)) {4732 const old_ty_child = switch (ip.indexToKey(old_ty)) {
4733 inline .array_type, .vector_type => |seq_type| seq_type.child,4733 inline .array_type, .vector_type => |seq_type| seq_type.child,
...@@ -4862,7 +4862,7 @@ pub fn indexToStructType(ip: *const InternPool, val: Index) Module.Struct.Option...@@ -4862,7 +4862,7 @@ pub fn indexToStructType(ip: *const InternPool, val: Index) Module.Struct.Option
4862 const tags = ip.items.items(.tag);4862 const tags = ip.items.items(.tag);
4863 if (tags[@intFromEnum(val)] != .type_struct) return .none;4863 if (tags[@intFromEnum(val)] != .type_struct) return .none;
4864 const datas = ip.items.items(.data);4864 const datas = ip.items.items(.data);
4865 return @enumFromInt(Module.Struct.Index, datas[@intFromEnum(val)]).toOptional();4865 return @as(Module.Struct.Index, @enumFromInt(datas[@intFromEnum(val)])).toOptional();
4866}4866}
48674867
4868pub fn indexToUnionType(ip: *const InternPool, val: Index) Module.Union.OptionalIndex {4868pub fn indexToUnionType(ip: *const InternPool, val: Index) Module.Union.OptionalIndex {
...@@ -4873,7 +4873,7 @@ pub fn indexToUnionType(ip: *const InternPool, val: Index) Module.Union.Optional...@@ -4873,7 +4873,7 @@ pub fn indexToUnionType(ip: *const InternPool, val: Index) Module.Union.Optional
4873 else => return .none,4873 else => return .none,
4874 }4874 }
4875 const datas = ip.items.items(.data);4875 const datas = ip.items.items(.data);
4876 return @enumFromInt(Module.Union.Index, datas[@intFromEnum(val)]).toOptional();4876 return @as(Module.Union.Index, @enumFromInt(datas[@intFromEnum(val)])).toOptional();
4877}4877}
48784878
4879pub fn indexToFuncType(ip: *const InternPool, val: Index) ?Key.FuncType {4879pub fn indexToFuncType(ip: *const InternPool, val: Index) ?Key.FuncType {
...@@ -4899,7 +4899,7 @@ pub fn indexToInferredErrorSetType(ip: *const InternPool, val: Index) Module.Fn....@@ -4899,7 +4899,7 @@ pub fn indexToInferredErrorSetType(ip: *const InternPool, val: Index) Module.Fn.
4899 const tags = ip.items.items(.tag);4899 const tags = ip.items.items(.tag);
4900 if (tags[@intFromEnum(val)] != .type_inferred_error_set) return .none;4900 if (tags[@intFromEnum(val)] != .type_inferred_error_set) return .none;
4901 const datas = ip.items.items(.data);4901 const datas = ip.items.items(.data);
4902 return @enumFromInt(Module.Fn.InferredErrorSet.Index, datas[@intFromEnum(val)]).toOptional();4902 return @as(Module.Fn.InferredErrorSet.Index, @enumFromInt(datas[@intFromEnum(val)])).toOptional();
4903}4903}
49044904
4905/// includes .comptime_int_type4905/// includes .comptime_int_type
...@@ -5057,7 +5057,7 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {...@@ -5057,7 +5057,7 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
5057 .type_enum_auto => @sizeOf(EnumAuto),5057 .type_enum_auto => @sizeOf(EnumAuto),
5058 .type_opaque => @sizeOf(Key.OpaqueType),5058 .type_opaque => @sizeOf(Key.OpaqueType),
5059 .type_struct => b: {5059 .type_struct => b: {
5060 const struct_index = @enumFromInt(Module.Struct.Index, data);5060 const struct_index = @as(Module.Struct.Index, @enumFromInt(data));
5061 const struct_obj = ip.structPtrConst(struct_index);5061 const struct_obj = ip.structPtrConst(struct_index);
5062 break :b @sizeOf(Module.Struct) +5062 break :b @sizeOf(Module.Struct) +
5063 @sizeOf(Module.Namespace) +5063 @sizeOf(Module.Namespace) +
...@@ -5124,13 +5124,13 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {...@@ -5124,13 +5124,13 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
51245124
5125 .bytes => b: {5125 .bytes => b: {
5126 const info = ip.extraData(Bytes, data);5126 const info = ip.extraData(Bytes, data);
5127 const len = @intCast(u32, ip.aggregateTypeLenIncludingSentinel(info.ty));5127 const len = @as(u32, @intCast(ip.aggregateTypeLenIncludingSentinel(info.ty)));
5128 break :b @sizeOf(Bytes) + len +5128 break :b @sizeOf(Bytes) + len +
5129 @intFromBool(ip.string_bytes.items[@intFromEnum(info.bytes) + len - 1] != 0);5129 @intFromBool(ip.string_bytes.items[@intFromEnum(info.bytes) + len - 1] != 0);
5130 },5130 },
5131 .aggregate => b: {5131 .aggregate => b: {
5132 const info = ip.extraData(Tag.Aggregate, data);5132 const info = ip.extraData(Tag.Aggregate, data);
5133 const fields_len = @intCast(u32, ip.aggregateTypeLenIncludingSentinel(info.ty));5133 const fields_len = @as(u32, @intCast(ip.aggregateTypeLenIncludingSentinel(info.ty)));
5134 break :b @sizeOf(Tag.Aggregate) + (@sizeOf(Index) * fields_len);5134 break :b @sizeOf(Tag.Aggregate) + (@sizeOf(Index) * fields_len);
5135 },5135 },
5136 .repeated => @sizeOf(Repeated),5136 .repeated => @sizeOf(Repeated),
...@@ -5181,8 +5181,8 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void {...@@ -5181,8 +5181,8 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void {
5181 for (tags, datas, 0..) |tag, data, i| {5181 for (tags, datas, 0..) |tag, data, i| {
5182 try w.print("${d} = {s}(", .{ i, @tagName(tag) });5182 try w.print("${d} = {s}(", .{ i, @tagName(tag) });
5183 switch (tag) {5183 switch (tag) {
5184 .simple_type => try w.print("{s}", .{@tagName(@enumFromInt(SimpleType, data))}),5184 .simple_type => try w.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(data)))}),
5185 .simple_value => try w.print("{s}", .{@tagName(@enumFromInt(SimpleValue, data))}),5185 .simple_value => try w.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(data)))}),
51865186
5187 .type_int_signed,5187 .type_int_signed,
5188 .type_int_unsigned,5188 .type_int_unsigned,
...@@ -5311,7 +5311,7 @@ pub fn createStruct(...@@ -5311,7 +5311,7 @@ pub fn createStruct(
5311 }5311 }
5312 const ptr = try ip.allocated_structs.addOne(gpa);5312 const ptr = try ip.allocated_structs.addOne(gpa);
5313 ptr.* = initialization;5313 ptr.* = initialization;
5314 return @enumFromInt(Module.Struct.Index, ip.allocated_structs.len - 1);5314 return @as(Module.Struct.Index, @enumFromInt(ip.allocated_structs.len - 1));
5315}5315}
53165316
5317pub fn destroyStruct(ip: *InternPool, gpa: Allocator, index: Module.Struct.Index) void {5317pub fn destroyStruct(ip: *InternPool, gpa: Allocator, index: Module.Struct.Index) void {
...@@ -5333,7 +5333,7 @@ pub fn createUnion(...@@ -5333,7 +5333,7 @@ pub fn createUnion(
5333 }5333 }
5334 const ptr = try ip.allocated_unions.addOne(gpa);5334 const ptr = try ip.allocated_unions.addOne(gpa);
5335 ptr.* = initialization;5335 ptr.* = initialization;
5336 return @enumFromInt(Module.Union.Index, ip.allocated_unions.len - 1);5336 return @as(Module.Union.Index, @enumFromInt(ip.allocated_unions.len - 1));
5337}5337}
53385338
5339pub fn destroyUnion(ip: *InternPool, gpa: Allocator, index: Module.Union.Index) void {5339pub fn destroyUnion(ip: *InternPool, gpa: Allocator, index: Module.Union.Index) void {
...@@ -5355,7 +5355,7 @@ pub fn createFunc(...@@ -5355,7 +5355,7 @@ pub fn createFunc(
5355 }5355 }
5356 const ptr = try ip.allocated_funcs.addOne(gpa);5356 const ptr = try ip.allocated_funcs.addOne(gpa);
5357 ptr.* = initialization;5357 ptr.* = initialization;
5358 return @enumFromInt(Module.Fn.Index, ip.allocated_funcs.len - 1);5358 return @as(Module.Fn.Index, @enumFromInt(ip.allocated_funcs.len - 1));
5359}5359}
53605360
5361pub fn destroyFunc(ip: *InternPool, gpa: Allocator, index: Module.Fn.Index) void {5361pub fn destroyFunc(ip: *InternPool, gpa: Allocator, index: Module.Fn.Index) void {
...@@ -5377,7 +5377,7 @@ pub fn createInferredErrorSet(...@@ -5377,7 +5377,7 @@ pub fn createInferredErrorSet(
5377 }5377 }
5378 const ptr = try ip.allocated_inferred_error_sets.addOne(gpa);5378 const ptr = try ip.allocated_inferred_error_sets.addOne(gpa);
5379 ptr.* = initialization;5379 ptr.* = initialization;
5380 return @enumFromInt(Module.Fn.InferredErrorSet.Index, ip.allocated_inferred_error_sets.len - 1);5380 return @as(Module.Fn.InferredErrorSet.Index, @enumFromInt(ip.allocated_inferred_error_sets.len - 1));
5381}5381}
53825382
5383pub fn destroyInferredErrorSet(ip: *InternPool, gpa: Allocator, index: Module.Fn.InferredErrorSet.Index) void {5383pub fn destroyInferredErrorSet(ip: *InternPool, gpa: Allocator, index: Module.Fn.InferredErrorSet.Index) void {
...@@ -5406,7 +5406,7 @@ pub fn getOrPutStringFmt(...@@ -5406,7 +5406,7 @@ pub fn getOrPutStringFmt(
5406 args: anytype,5406 args: anytype,
5407) Allocator.Error!NullTerminatedString {5407) Allocator.Error!NullTerminatedString {
5408 // ensure that references to string_bytes in args do not get invalidated5408 // ensure that references to string_bytes in args do not get invalidated
5409 const len = @intCast(usize, std.fmt.count(format, args) + 1);5409 const len = @as(usize, @intCast(std.fmt.count(format, args) + 1));
5410 try ip.string_bytes.ensureUnusedCapacity(gpa, len);5410 try ip.string_bytes.ensureUnusedCapacity(gpa, len);
5411 ip.string_bytes.writer(undefined).print(format, args) catch unreachable;5411 ip.string_bytes.writer(undefined).print(format, args) catch unreachable;
5412 ip.string_bytes.appendAssumeCapacity(0);5412 ip.string_bytes.appendAssumeCapacity(0);
...@@ -5430,7 +5430,7 @@ pub fn getOrPutTrailingString(...@@ -5430,7 +5430,7 @@ pub fn getOrPutTrailingString(
5430 len: usize,5430 len: usize,
5431) Allocator.Error!NullTerminatedString {5431) Allocator.Error!NullTerminatedString {
5432 const string_bytes = &ip.string_bytes;5432 const string_bytes = &ip.string_bytes;
5433 const str_index = @intCast(u32, string_bytes.items.len - len);5433 const str_index = @as(u32, @intCast(string_bytes.items.len - len));
5434 if (len > 0 and string_bytes.getLast() == 0) {5434 if (len > 0 and string_bytes.getLast() == 0) {
5435 _ = string_bytes.pop();5435 _ = string_bytes.pop();
5436 } else {5436 } else {
...@@ -5444,11 +5444,11 @@ pub fn getOrPutTrailingString(...@@ -5444,11 +5444,11 @@ pub fn getOrPutTrailingString(
5444 });5444 });
5445 if (gop.found_existing) {5445 if (gop.found_existing) {
5446 string_bytes.shrinkRetainingCapacity(str_index);5446 string_bytes.shrinkRetainingCapacity(str_index);
5447 return @enumFromInt(NullTerminatedString, gop.key_ptr.*);5447 return @as(NullTerminatedString, @enumFromInt(gop.key_ptr.*));
5448 } else {5448 } else {
5449 gop.key_ptr.* = str_index;5449 gop.key_ptr.* = str_index;
5450 string_bytes.appendAssumeCapacity(0);5450 string_bytes.appendAssumeCapacity(0);
5451 return @enumFromInt(NullTerminatedString, str_index);5451 return @as(NullTerminatedString, @enumFromInt(str_index));
5452 }5452 }
5453}5453}
54545454
...@@ -5456,7 +5456,7 @@ pub fn getString(ip: *InternPool, s: []const u8) OptionalNullTerminatedString {...@@ -5456,7 +5456,7 @@ pub fn getString(ip: *InternPool, s: []const u8) OptionalNullTerminatedString {
5456 if (ip.string_table.getKeyAdapted(s, std.hash_map.StringIndexAdapter{5456 if (ip.string_table.getKeyAdapted(s, std.hash_map.StringIndexAdapter{
5457 .bytes = &ip.string_bytes,5457 .bytes = &ip.string_bytes,
5458 })) |index| {5458 })) |index| {
5459 return @enumFromInt(NullTerminatedString, index).toOptional();5459 return @as(NullTerminatedString, @enumFromInt(index)).toOptional();
5460 } else {5460 } else {
5461 return .none;5461 return .none;
5462 }5462 }
...@@ -5596,7 +5596,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {...@@ -5596,7 +5596,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
5596 .undef,5596 .undef,
5597 .opt_null,5597 .opt_null,
5598 .only_possible_value,5598 .only_possible_value,
5599 => @enumFromInt(Index, ip.items.items(.data)[@intFromEnum(index)]),5599 => @as(Index, @enumFromInt(ip.items.items(.data)[@intFromEnum(index)])),
56005600
5601 .simple_value => unreachable, // handled via Index above5601 .simple_value => unreachable, // handled via Index above
56025602
...@@ -5628,7 +5628,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {...@@ -5628,7 +5628,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
5628 => |t| {5628 => |t| {
5629 const extra_index = ip.items.items(.data)[@intFromEnum(index)];5629 const extra_index = ip.items.items(.data)[@intFromEnum(index)];
5630 const field_index = std.meta.fieldIndex(t.Payload(), "ty").?;5630 const field_index = std.meta.fieldIndex(t.Payload(), "ty").?;
5631 return @enumFromInt(Index, ip.extra.items[extra_index + field_index]);5631 return @as(Index, @enumFromInt(ip.extra.items[extra_index + field_index]));
5632 },5632 },
56335633
5634 .int_u8 => .u8_type,5634 .int_u8 => .u8_type,
...@@ -5670,7 +5670,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {...@@ -5670,7 +5670,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
5670/// Assumes that the enum's field indexes equal its value tags.5670/// Assumes that the enum's field indexes equal its value tags.
5671pub fn toEnum(ip: *const InternPool, comptime E: type, i: Index) E {5671pub fn toEnum(ip: *const InternPool, comptime E: type, i: Index) E {
5672 const int = ip.indexToKey(i).enum_tag.int;5672 const int = ip.indexToKey(i).enum_tag.int;
5673 return @enumFromInt(E, ip.indexToKey(int).int.storage.u64);5673 return @as(E, @enumFromInt(ip.indexToKey(int).int.storage.u64));
5674}5674}
56755675
5676pub fn aggregateTypeLen(ip: *const InternPool, ty: Index) u64 {5676pub fn aggregateTypeLen(ip: *const InternPool, ty: Index) u64 {
...@@ -5703,9 +5703,9 @@ pub fn funcReturnType(ip: *const InternPool, ty: Index) Index {...@@ -5703,9 +5703,9 @@ pub fn funcReturnType(ip: *const InternPool, ty: Index) Index {
5703 else => unreachable,5703 else => unreachable,
5704 };5704 };
5705 assert(child_item.tag == .type_function);5705 assert(child_item.tag == .type_function);
5706 return @enumFromInt(Index, ip.extra.items[5706 return @as(Index, @enumFromInt(ip.extra.items[
5707 child_item.data + std.meta.fieldIndex(TypeFunction, "return_type").?5707 child_item.data + std.meta.fieldIndex(TypeFunction, "return_type").?
5708 ]);5708 ]));
5709}5709}
57105710
5711pub fn isNoReturn(ip: *const InternPool, ty: Index) bool {5711pub fn isNoReturn(ip: *const InternPool, ty: Index) bool {
...@@ -5736,9 +5736,9 @@ pub fn getBackingDecl(ip: *const InternPool, val: Index) Module.Decl.OptionalInd...@@ -5736,9 +5736,9 @@ pub fn getBackingDecl(ip: *const InternPool, val: Index) Module.Decl.OptionalInd
5736 switch (ip.items.items(.tag)[base]) {5736 switch (ip.items.items(.tag)[base]) {
5737 inline .ptr_decl,5737 inline .ptr_decl,
5738 .ptr_mut_decl,5738 .ptr_mut_decl,
5739 => |tag| return @enumFromInt(Module.Decl.OptionalIndex, ip.extra.items[5739 => |tag| return @as(Module.Decl.OptionalIndex, @enumFromInt(ip.extra.items[
5740 ip.items.items(.data)[base] + std.meta.fieldIndex(tag.Payload(), "decl").?5740 ip.items.items(.data)[base] + std.meta.fieldIndex(tag.Payload(), "decl").?
5741 ]),5741 ])),
5742 inline .ptr_eu_payload,5742 inline .ptr_eu_payload,
5743 .ptr_opt_payload,5743 .ptr_opt_payload,
5744 .ptr_elem,5744 .ptr_elem,
src/Liveness.zig+34-34
...@@ -178,14 +178,14 @@ pub fn analyze(gpa: Allocator, air: Air, intern_pool: *const InternPool) Allocat...@@ -178,14 +178,14 @@ pub fn analyze(gpa: Allocator, air: Air, intern_pool: *const InternPool) Allocat
178178
179pub fn getTombBits(l: Liveness, inst: Air.Inst.Index) Bpi {179pub fn getTombBits(l: Liveness, inst: Air.Inst.Index) Bpi {
180 const usize_index = (inst * bpi) / @bitSizeOf(usize);180 const usize_index = (inst * bpi) / @bitSizeOf(usize);
181 return @truncate(Bpi, l.tomb_bits[usize_index] >>181 return @as(Bpi, @truncate(l.tomb_bits[usize_index] >>
182 @intCast(Log2Int(usize), (inst % (@bitSizeOf(usize) / bpi)) * bpi));182 @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi))));
183}183}
184184
185pub fn isUnused(l: Liveness, inst: Air.Inst.Index) bool {185pub fn isUnused(l: Liveness, inst: Air.Inst.Index) bool {
186 const usize_index = (inst * bpi) / @bitSizeOf(usize);186 const usize_index = (inst * bpi) / @bitSizeOf(usize);
187 const mask = @as(usize, 1) <<187 const mask = @as(usize, 1) <<
188 @intCast(Log2Int(usize), (inst % (@bitSizeOf(usize) / bpi)) * bpi + (bpi - 1));188 @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi + (bpi - 1)));
189 return (l.tomb_bits[usize_index] & mask) != 0;189 return (l.tomb_bits[usize_index] & mask) != 0;
190}190}
191191
...@@ -193,7 +193,7 @@ pub fn operandDies(l: Liveness, inst: Air.Inst.Index, operand: OperandInt) bool...@@ -193,7 +193,7 @@ pub fn operandDies(l: Liveness, inst: Air.Inst.Index, operand: OperandInt) bool
193 assert(operand < bpi - 1);193 assert(operand < bpi - 1);
194 const usize_index = (inst * bpi) / @bitSizeOf(usize);194 const usize_index = (inst * bpi) / @bitSizeOf(usize);
195 const mask = @as(usize, 1) <<195 const mask = @as(usize, 1) <<
196 @intCast(Log2Int(usize), (inst % (@bitSizeOf(usize) / bpi)) * bpi + operand);196 @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi + operand));
197 return (l.tomb_bits[usize_index] & mask) != 0;197 return (l.tomb_bits[usize_index] & mask) != 0;
198}198}
199199
...@@ -201,7 +201,7 @@ pub fn clearOperandDeath(l: Liveness, inst: Air.Inst.Index, operand: OperandInt)...@@ -201,7 +201,7 @@ pub fn clearOperandDeath(l: Liveness, inst: Air.Inst.Index, operand: OperandInt)
201 assert(operand < bpi - 1);201 assert(operand < bpi - 1);
202 const usize_index = (inst * bpi) / @bitSizeOf(usize);202 const usize_index = (inst * bpi) / @bitSizeOf(usize);
203 const mask = @as(usize, 1) <<203 const mask = @as(usize, 1) <<
204 @intCast(Log2Int(usize), (inst % (@bitSizeOf(usize) / bpi)) * bpi + operand);204 @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi + operand));
205 l.tomb_bits[usize_index] &= ~mask;205 l.tomb_bits[usize_index] &= ~mask;
206}206}
207207
...@@ -484,11 +484,11 @@ pub fn categorizeOperand(...@@ -484,11 +484,11 @@ pub fn categorizeOperand(
484 const inst_data = air_datas[inst].pl_op;484 const inst_data = air_datas[inst].pl_op;
485 const callee = inst_data.operand;485 const callee = inst_data.operand;
486 const extra = air.extraData(Air.Call, inst_data.payload);486 const extra = air.extraData(Air.Call, inst_data.payload);
487 const args = @ptrCast([]const Air.Inst.Ref, air.extra[extra.end..][0..extra.data.args_len]);487 const args = @as([]const Air.Inst.Ref, @ptrCast(air.extra[extra.end..][0..extra.data.args_len]));
488 if (args.len + 1 <= bpi - 1) {488 if (args.len + 1 <= bpi - 1) {
489 if (callee == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);489 if (callee == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);
490 for (args, 0..) |arg, i| {490 for (args, 0..) |arg, i| {
491 if (arg == operand_ref) return matchOperandSmallIndex(l, inst, @intCast(OperandInt, i + 1), .write);491 if (arg == operand_ref) return matchOperandSmallIndex(l, inst, @as(OperandInt, @intCast(i + 1)), .write);
492 }492 }
493 return .write;493 return .write;
494 }494 }
...@@ -535,12 +535,12 @@ pub fn categorizeOperand(...@@ -535,12 +535,12 @@ pub fn categorizeOperand(
535 .aggregate_init => {535 .aggregate_init => {
536 const ty_pl = air_datas[inst].ty_pl;536 const ty_pl = air_datas[inst].ty_pl;
537 const aggregate_ty = air.getRefType(ty_pl.ty);537 const aggregate_ty = air.getRefType(ty_pl.ty);
538 const len = @intCast(usize, aggregate_ty.arrayLenIp(ip));538 const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip)));
539 const elements = @ptrCast([]const Air.Inst.Ref, air.extra[ty_pl.payload..][0..len]);539 const elements = @as([]const Air.Inst.Ref, @ptrCast(air.extra[ty_pl.payload..][0..len]));
540540
541 if (elements.len <= bpi - 1) {541 if (elements.len <= bpi - 1) {
542 for (elements, 0..) |elem, i| {542 for (elements, 0..) |elem, i| {
543 if (elem == operand_ref) return matchOperandSmallIndex(l, inst, @intCast(OperandInt, i), .none);543 if (elem == operand_ref) return matchOperandSmallIndex(l, inst, @as(OperandInt, @intCast(i)), .none);
544 }544 }
545 return .none;545 return .none;
546 }546 }
...@@ -808,20 +808,20 @@ pub const BigTomb = struct {...@@ -808,20 +808,20 @@ pub const BigTomb = struct {
808808
809 const small_tombs = bpi - 1;809 const small_tombs = bpi - 1;
810 if (this_bit_index < small_tombs) {810 if (this_bit_index < small_tombs) {
811 const dies = @truncate(u1, bt.tomb_bits >> @intCast(Liveness.OperandInt, this_bit_index)) != 0;811 const dies = @as(u1, @truncate(bt.tomb_bits >> @as(Liveness.OperandInt, @intCast(this_bit_index)))) != 0;
812 return dies;812 return dies;
813 }813 }
814814
815 const big_bit_index = this_bit_index - small_tombs;815 const big_bit_index = this_bit_index - small_tombs;
816 while (big_bit_index - bt.extra_offset * 31 >= 31) {816 while (big_bit_index - bt.extra_offset * 31 >= 31) {
817 if (@truncate(u1, bt.extra[bt.extra_start + bt.extra_offset] >> 31) != 0) {817 if (@as(u1, @truncate(bt.extra[bt.extra_start + bt.extra_offset] >> 31)) != 0) {
818 bt.reached_end = true;818 bt.reached_end = true;
819 return false;819 return false;
820 }820 }
821 bt.extra_offset += 1;821 bt.extra_offset += 1;
822 }822 }
823 const dies = @truncate(u1, bt.extra[bt.extra_start + bt.extra_offset] >>823 const dies = @as(u1, @truncate(bt.extra[bt.extra_start + bt.extra_offset] >>
824 @intCast(u5, big_bit_index - bt.extra_offset * 31)) != 0;824 @as(u5, @intCast(big_bit_index - bt.extra_offset * 31)))) != 0;
825 return dies;825 return dies;
826 }826 }
827};827};
...@@ -838,7 +838,7 @@ const Analysis = struct {...@@ -838,7 +838,7 @@ const Analysis = struct {
838 fn storeTombBits(a: *Analysis, inst: Air.Inst.Index, tomb_bits: Bpi) void {838 fn storeTombBits(a: *Analysis, inst: Air.Inst.Index, tomb_bits: Bpi) void {
839 const usize_index = (inst * bpi) / @bitSizeOf(usize);839 const usize_index = (inst * bpi) / @bitSizeOf(usize);
840 a.tomb_bits[usize_index] |= @as(usize, tomb_bits) <<840 a.tomb_bits[usize_index] |= @as(usize, tomb_bits) <<
841 @intCast(Log2Int(usize), (inst % (@bitSizeOf(usize) / bpi)) * bpi);841 @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi));
842 }842 }
843843
844 fn addExtra(a: *Analysis, extra: anytype) Allocator.Error!u32 {844 fn addExtra(a: *Analysis, extra: anytype) Allocator.Error!u32 {
...@@ -849,7 +849,7 @@ const Analysis = struct {...@@ -849,7 +849,7 @@ const Analysis = struct {
849849
850 fn addExtraAssumeCapacity(a: *Analysis, extra: anytype) u32 {850 fn addExtraAssumeCapacity(a: *Analysis, extra: anytype) u32 {
851 const fields = std.meta.fields(@TypeOf(extra));851 const fields = std.meta.fields(@TypeOf(extra));
852 const result = @intCast(u32, a.extra.items.len);852 const result = @as(u32, @intCast(a.extra.items.len));
853 inline for (fields) |field| {853 inline for (fields) |field| {
854 a.extra.appendAssumeCapacity(switch (field.type) {854 a.extra.appendAssumeCapacity(switch (field.type) {
855 u32 => @field(extra, field.name),855 u32 => @field(extra, field.name),
...@@ -1108,7 +1108,7 @@ fn analyzeInst(...@@ -1108,7 +1108,7 @@ fn analyzeInst(
1108 const inst_data = inst_datas[inst].pl_op;1108 const inst_data = inst_datas[inst].pl_op;
1109 const callee = inst_data.operand;1109 const callee = inst_data.operand;
1110 const extra = a.air.extraData(Air.Call, inst_data.payload);1110 const extra = a.air.extraData(Air.Call, inst_data.payload);
1111 const args = @ptrCast([]const Air.Inst.Ref, a.air.extra[extra.end..][0..extra.data.args_len]);1111 const args = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[extra.end..][0..extra.data.args_len]));
1112 if (args.len + 1 <= bpi - 1) {1112 if (args.len + 1 <= bpi - 1) {
1113 var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1);1113 var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1);
1114 buf[0] = callee;1114 buf[0] = callee;
...@@ -1146,8 +1146,8 @@ fn analyzeInst(...@@ -1146,8 +1146,8 @@ fn analyzeInst(
1146 .aggregate_init => {1146 .aggregate_init => {
1147 const ty_pl = inst_datas[inst].ty_pl;1147 const ty_pl = inst_datas[inst].ty_pl;
1148 const aggregate_ty = a.air.getRefType(ty_pl.ty);1148 const aggregate_ty = a.air.getRefType(ty_pl.ty);
1149 const len = @intCast(usize, aggregate_ty.arrayLenIp(ip));1149 const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip)));
1150 const elements = @ptrCast([]const Air.Inst.Ref, a.air.extra[ty_pl.payload..][0..len]);1150 const elements = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[ty_pl.payload..][0..len]));
11511151
1152 if (elements.len <= bpi - 1) {1152 if (elements.len <= bpi - 1) {
1153 var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1);1153 var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1);
...@@ -1200,9 +1200,9 @@ fn analyzeInst(...@@ -1200,9 +1200,9 @@ fn analyzeInst(
1200 .assembly => {1200 .assembly => {
1201 const extra = a.air.extraData(Air.Asm, inst_datas[inst].ty_pl.payload);1201 const extra = a.air.extraData(Air.Asm, inst_datas[inst].ty_pl.payload);
1202 var extra_i: usize = extra.end;1202 var extra_i: usize = extra.end;
1203 const outputs = @ptrCast([]const Air.Inst.Ref, a.air.extra[extra_i..][0..extra.data.outputs_len]);1203 const outputs = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[extra_i..][0..extra.data.outputs_len]));
1204 extra_i += outputs.len;1204 extra_i += outputs.len;
1205 const inputs = @ptrCast([]const Air.Inst.Ref, a.air.extra[extra_i..][0..extra.data.inputs_len]);1205 const inputs = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[extra_i..][0..extra.data.inputs_len]));
1206 extra_i += inputs.len;1206 extra_i += inputs.len;
12071207
1208 const num_operands = simple: {1208 const num_operands = simple: {
...@@ -1310,7 +1310,7 @@ fn analyzeOperands(...@@ -1310,7 +1310,7 @@ fn analyzeOperands(
1310 // Don't compute any liveness for constants1310 // Don't compute any liveness for constants
1311 if (inst_tags[operand] == .interned) continue;1311 if (inst_tags[operand] == .interned) continue;
13121312
1313 const mask = @as(Bpi, 1) << @intCast(OperandInt, i);1313 const mask = @as(Bpi, 1) << @as(OperandInt, @intCast(i));
13141314
1315 if ((try data.live_set.fetchPut(gpa, operand, {})) == null) {1315 if ((try data.live_set.fetchPut(gpa, operand, {})) == null) {
1316 log.debug("[{}] %{}: added %{} to live set (operand dies here)", .{ pass, inst, operand });1316 log.debug("[{}] %{}: added %{} to live set (operand dies here)", .{ pass, inst, operand });
...@@ -1320,7 +1320,7 @@ fn analyzeOperands(...@@ -1320,7 +1320,7 @@ fn analyzeOperands(
1320 }1320 }
13211321
1322 a.tomb_bits[usize_index] |= @as(usize, tomb_bits) <<1322 a.tomb_bits[usize_index] |= @as(usize, tomb_bits) <<
1323 @intCast(Log2Int(usize), (inst % (@bitSizeOf(usize) / bpi)) * bpi);1323 @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi));
1324 },1324 },
1325 }1325 }
1326}1326}
...@@ -1472,7 +1472,7 @@ fn analyzeInstLoop(...@@ -1472,7 +1472,7 @@ fn analyzeInstLoop(
1472 const num_breaks = data.breaks.count();1472 const num_breaks = data.breaks.count();
1473 try a.extra.ensureUnusedCapacity(gpa, 1 + num_breaks);1473 try a.extra.ensureUnusedCapacity(gpa, 1 + num_breaks);
14741474
1475 const extra_index = @intCast(u32, a.extra.items.len);1475 const extra_index = @as(u32, @intCast(a.extra.items.len));
1476 a.extra.appendAssumeCapacity(num_breaks);1476 a.extra.appendAssumeCapacity(num_breaks);
14771477
1478 var it = data.breaks.keyIterator();1478 var it = data.breaks.keyIterator();
...@@ -1523,7 +1523,7 @@ fn analyzeInstLoop(...@@ -1523,7 +1523,7 @@ fn analyzeInstLoop(
1523 // This is necessarily not in the same control flow branch, because loops are noreturn1523 // This is necessarily not in the same control flow branch, because loops are noreturn
1524 data.live_set.clearRetainingCapacity();1524 data.live_set.clearRetainingCapacity();
15251525
1526 try data.live_set.ensureUnusedCapacity(gpa, @intCast(u32, loop_live.len));1526 try data.live_set.ensureUnusedCapacity(gpa, @as(u32, @intCast(loop_live.len)));
1527 for (loop_live) |alive| {1527 for (loop_live) |alive| {
1528 data.live_set.putAssumeCapacity(alive, {});1528 data.live_set.putAssumeCapacity(alive, {});
1529 }1529 }
...@@ -1647,8 +1647,8 @@ fn analyzeInstCondBr(...@@ -1647,8 +1647,8 @@ fn analyzeInstCondBr(
1647 log.debug("[{}] %{}: new live set is {}", .{ pass, inst, fmtInstSet(&data.live_set) });1647 log.debug("[{}] %{}: new live set is {}", .{ pass, inst, fmtInstSet(&data.live_set) });
16481648
1649 // Write the mirrored deaths to `extra`1649 // Write the mirrored deaths to `extra`
1650 const then_death_count = @intCast(u32, then_mirrored_deaths.items.len);1650 const then_death_count = @as(u32, @intCast(then_mirrored_deaths.items.len));
1651 const else_death_count = @intCast(u32, else_mirrored_deaths.items.len);1651 const else_death_count = @as(u32, @intCast(else_mirrored_deaths.items.len));
1652 try a.extra.ensureUnusedCapacity(gpa, std.meta.fields(CondBr).len + then_death_count + else_death_count);1652 try a.extra.ensureUnusedCapacity(gpa, std.meta.fields(CondBr).len + then_death_count + else_death_count);
1653 const extra_index = a.addExtraAssumeCapacity(CondBr{1653 const extra_index = a.addExtraAssumeCapacity(CondBr{
1654 .then_death_count = then_death_count,1654 .then_death_count = then_death_count,
...@@ -1758,12 +1758,12 @@ fn analyzeInstSwitchBr(...@@ -1758,12 +1758,12 @@ fn analyzeInstSwitchBr(
1758 log.debug("[{}] %{}: new live set is {}", .{ pass, inst, fmtInstSet(&data.live_set) });1758 log.debug("[{}] %{}: new live set is {}", .{ pass, inst, fmtInstSet(&data.live_set) });
1759 }1759 }
17601760
1761 const else_death_count = @intCast(u32, mirrored_deaths[ncases].items.len);1761 const else_death_count = @as(u32, @intCast(mirrored_deaths[ncases].items.len));
1762 const extra_index = try a.addExtra(SwitchBr{1762 const extra_index = try a.addExtra(SwitchBr{
1763 .else_death_count = else_death_count,1763 .else_death_count = else_death_count,
1764 });1764 });
1765 for (mirrored_deaths[0..ncases]) |mirrored| {1765 for (mirrored_deaths[0..ncases]) |mirrored| {
1766 const num = @intCast(u32, mirrored.items.len);1766 const num = @as(u32, @intCast(mirrored.items.len));
1767 try a.extra.ensureUnusedCapacity(gpa, num + 1);1767 try a.extra.ensureUnusedCapacity(gpa, num + 1);
1768 a.extra.appendAssumeCapacity(num);1768 a.extra.appendAssumeCapacity(num);
1769 a.extra.appendSliceAssumeCapacity(mirrored.items);1769 a.extra.appendSliceAssumeCapacity(mirrored.items);
...@@ -1798,7 +1798,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {...@@ -1798,7 +1798,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
1798 inst: Air.Inst.Index,1798 inst: Air.Inst.Index,
1799 total_operands: usize,1799 total_operands: usize,
1800 ) !Self {1800 ) !Self {
1801 const extra_operands = @intCast(u32, total_operands) -| (bpi - 1);1801 const extra_operands = @as(u32, @intCast(total_operands)) -| (bpi - 1);
1802 const max_extra_tombs = (extra_operands + 30) / 31;1802 const max_extra_tombs = (extra_operands + 30) / 31;
18031803
1804 const extra_tombs: []u32 = switch (pass) {1804 const extra_tombs: []u32 = switch (pass) {
...@@ -1818,7 +1818,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {...@@ -1818,7 +1818,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
1818 .a = a,1818 .a = a,
1819 .data = data,1819 .data = data,
1820 .inst = inst,1820 .inst = inst,
1821 .operands_remaining = @intCast(u32, total_operands),1821 .operands_remaining = @as(u32, @intCast(total_operands)),
1822 .extra_tombs = extra_tombs,1822 .extra_tombs = extra_tombs,
1823 .will_die_immediately = will_die_immediately,1823 .will_die_immediately = will_die_immediately,
1824 };1824 };
...@@ -1847,7 +1847,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {...@@ -1847,7 +1847,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
1847 if (big.will_die_immediately and !big.a.air.mustLower(big.inst, ip)) return;1847 if (big.will_die_immediately and !big.a.air.mustLower(big.inst, ip)) return;
18481848
1849 const extra_byte = (big.operands_remaining - (bpi - 1)) / 31;1849 const extra_byte = (big.operands_remaining - (bpi - 1)) / 31;
1850 const extra_bit = @intCast(u5, big.operands_remaining - (bpi - 1) - extra_byte * 31);1850 const extra_bit = @as(u5, @intCast(big.operands_remaining - (bpi - 1) - extra_byte * 31));
18511851
1852 const gpa = big.a.gpa;1852 const gpa = big.a.gpa;
18531853
...@@ -1881,7 +1881,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {...@@ -1881,7 +1881,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
1881 // keep at least one.1881 // keep at least one.
1882 var num: usize = big.extra_tombs.len;1882 var num: usize = big.extra_tombs.len;
1883 while (num > 1) {1883 while (num > 1) {
1884 if (@truncate(u31, big.extra_tombs[num - 1]) != 0) {1884 if (@as(u31, @truncate(big.extra_tombs[num - 1])) != 0) {
1885 // Some operand dies here1885 // Some operand dies here
1886 break;1886 break;
1887 }1887 }
...@@ -1892,7 +1892,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {...@@ -1892,7 +1892,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
18921892
1893 const extra_tombs = big.extra_tombs[0..num];1893 const extra_tombs = big.extra_tombs[0..num];
18941894
1895 const extra_index = @intCast(u32, big.a.extra.items.len);1895 const extra_index = @as(u32, @intCast(big.a.extra.items.len));
1896 try big.a.extra.appendSlice(gpa, extra_tombs);1896 try big.a.extra.appendSlice(gpa, extra_tombs);
1897 try big.a.special.put(gpa, big.inst, extra_index);1897 try big.a.special.put(gpa, big.inst, extra_index);
1898 },1898 },
src/Liveness/Verify.zig+11-11
...@@ -325,8 +325,8 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -325,8 +325,8 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
325 .aggregate_init => {325 .aggregate_init => {
326 const ty_pl = data[inst].ty_pl;326 const ty_pl = data[inst].ty_pl;
327 const aggregate_ty = self.air.getRefType(ty_pl.ty);327 const aggregate_ty = self.air.getRefType(ty_pl.ty);
328 const len = @intCast(usize, aggregate_ty.arrayLenIp(ip));328 const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip)));
329 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);329 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
330330
331 var bt = self.liveness.iterateBigTomb(inst);331 var bt = self.liveness.iterateBigTomb(inst);
332 for (elements) |element| {332 for (elements) |element| {
...@@ -337,9 +337,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -337,9 +337,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
337 .call, .call_always_tail, .call_never_tail, .call_never_inline => {337 .call, .call_always_tail, .call_never_tail, .call_never_inline => {
338 const pl_op = data[inst].pl_op;338 const pl_op = data[inst].pl_op;
339 const extra = self.air.extraData(Air.Call, pl_op.payload);339 const extra = self.air.extraData(Air.Call, pl_op.payload);
340 const args = @ptrCast(340 const args = @as(
341 []const Air.Inst.Ref,341 []const Air.Inst.Ref,
342 self.air.extra[extra.end..][0..extra.data.args_len],342 @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]),
343 );343 );
344344
345 var bt = self.liveness.iterateBigTomb(inst);345 var bt = self.liveness.iterateBigTomb(inst);
...@@ -353,14 +353,14 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -353,14 +353,14 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
353 const ty_pl = data[inst].ty_pl;353 const ty_pl = data[inst].ty_pl;
354 const extra = self.air.extraData(Air.Asm, ty_pl.payload);354 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
355 var extra_i = extra.end;355 var extra_i = extra.end;
356 const outputs = @ptrCast(356 const outputs = @as(
357 []const Air.Inst.Ref,357 []const Air.Inst.Ref,
358 self.air.extra[extra_i..][0..extra.data.outputs_len],358 @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]),
359 );359 );
360 extra_i += outputs.len;360 extra_i += outputs.len;
361 const inputs = @ptrCast(361 const inputs = @as(
362 []const Air.Inst.Ref,362 []const Air.Inst.Ref,
363 self.air.extra[extra_i..][0..extra.data.inputs_len],363 @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]),
364 );364 );
365 extra_i += inputs.len;365 extra_i += inputs.len;
366366
...@@ -521,9 +521,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -521,9 +521,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
521521
522 while (case_i < switch_br.data.cases_len) : (case_i += 1) {522 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
523 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);523 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
524 const items = @ptrCast(524 const items = @as(
525 []const Air.Inst.Ref,525 []const Air.Inst.Ref,
526 self.air.extra[case.end..][0..case.data.items_len],526 @ptrCast(self.air.extra[case.end..][0..case.data.items_len]),
527 );527 );
528 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];528 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
529 extra_index = case.end + items.len + case_body.len;529 extra_index = case.end + items.len + case_body.len;
...@@ -576,7 +576,7 @@ fn verifyInstOperands(...@@ -576,7 +576,7 @@ fn verifyInstOperands(
576 operands: [Liveness.bpi - 1]Air.Inst.Ref,576 operands: [Liveness.bpi - 1]Air.Inst.Ref,
577) Error!void {577) Error!void {
578 for (operands, 0..) |operand, operand_index| {578 for (operands, 0..) |operand, operand_index| {
579 const dies = self.liveness.operandDies(inst, @intCast(Liveness.OperandInt, operand_index));579 const dies = self.liveness.operandDies(inst, @as(Liveness.OperandInt, @intCast(operand_index)));
580 try self.verifyOperand(inst, operand, dies);580 try self.verifyOperand(inst, operand, dies);
581 }581 }
582 try self.verifyInst(inst);582 try self.verifyInst(inst);
src/Manifest.zig+11-11
...@@ -102,7 +102,7 @@ pub fn hex64(x: u64) [16]u8 {...@@ -102,7 +102,7 @@ pub fn hex64(x: u64) [16]u8 {
102 var result: [16]u8 = undefined;102 var result: [16]u8 = undefined;
103 var i: usize = 0;103 var i: usize = 0;
104 while (i < 8) : (i += 1) {104 while (i < 8) : (i += 1) {
105 const byte = @truncate(u8, x >> @intCast(u6, 8 * i));105 const byte = @as(u8, @truncate(x >> @as(u6, @intCast(8 * i))));
106 result[i * 2 + 0] = hex_charset[byte >> 4];106 result[i * 2 + 0] = hex_charset[byte >> 4];
107 result[i * 2 + 1] = hex_charset[byte & 15];107 result[i * 2 + 1] = hex_charset[byte & 15];
108 }108 }
...@@ -284,7 +284,7 @@ const Parse = struct {...@@ -284,7 +284,7 @@ const Parse = struct {
284 @errorName(err),284 @errorName(err),
285 });285 });
286 };286 };
287 if (@enumFromInt(MultihashFunction, their_multihash_func) != multihash_function) {287 if (@as(MultihashFunction, @enumFromInt(their_multihash_func)) != multihash_function) {
288 return fail(p, tok, "unsupported hash function: only sha2-256 is supported", .{});288 return fail(p, tok, "unsupported hash function: only sha2-256 is supported", .{});
289 }289 }
290 }290 }
...@@ -345,7 +345,7 @@ const Parse = struct {...@@ -345,7 +345,7 @@ const Parse = struct {
345 .invalid_escape_character => |bad_index| {345 .invalid_escape_character => |bad_index| {
346 try p.appendErrorOff(346 try p.appendErrorOff(
347 token,347 token,
348 offset + @intCast(u32, bad_index),348 offset + @as(u32, @intCast(bad_index)),
349 "invalid escape character: '{c}'",349 "invalid escape character: '{c}'",
350 .{raw_string[bad_index]},350 .{raw_string[bad_index]},
351 );351 );
...@@ -353,7 +353,7 @@ const Parse = struct {...@@ -353,7 +353,7 @@ const Parse = struct {
353 .expected_hex_digit => |bad_index| {353 .expected_hex_digit => |bad_index| {
354 try p.appendErrorOff(354 try p.appendErrorOff(
355 token,355 token,
356 offset + @intCast(u32, bad_index),356 offset + @as(u32, @intCast(bad_index)),
357 "expected hex digit, found '{c}'",357 "expected hex digit, found '{c}'",
358 .{raw_string[bad_index]},358 .{raw_string[bad_index]},
359 );359 );
...@@ -361,7 +361,7 @@ const Parse = struct {...@@ -361,7 +361,7 @@ const Parse = struct {
361 .empty_unicode_escape_sequence => |bad_index| {361 .empty_unicode_escape_sequence => |bad_index| {
362 try p.appendErrorOff(362 try p.appendErrorOff(
363 token,363 token,
364 offset + @intCast(u32, bad_index),364 offset + @as(u32, @intCast(bad_index)),
365 "empty unicode escape sequence",365 "empty unicode escape sequence",
366 .{},366 .{},
367 );367 );
...@@ -369,7 +369,7 @@ const Parse = struct {...@@ -369,7 +369,7 @@ const Parse = struct {
369 .expected_hex_digit_or_rbrace => |bad_index| {369 .expected_hex_digit_or_rbrace => |bad_index| {
370 try p.appendErrorOff(370 try p.appendErrorOff(
371 token,371 token,
372 offset + @intCast(u32, bad_index),372 offset + @as(u32, @intCast(bad_index)),
373 "expected hex digit or '}}', found '{c}'",373 "expected hex digit or '}}', found '{c}'",
374 .{raw_string[bad_index]},374 .{raw_string[bad_index]},
375 );375 );
...@@ -377,7 +377,7 @@ const Parse = struct {...@@ -377,7 +377,7 @@ const Parse = struct {
377 .invalid_unicode_codepoint => |bad_index| {377 .invalid_unicode_codepoint => |bad_index| {
378 try p.appendErrorOff(378 try p.appendErrorOff(
379 token,379 token,
380 offset + @intCast(u32, bad_index),380 offset + @as(u32, @intCast(bad_index)),
381 "unicode escape does not correspond to a valid codepoint",381 "unicode escape does not correspond to a valid codepoint",
382 .{},382 .{},
383 );383 );
...@@ -385,7 +385,7 @@ const Parse = struct {...@@ -385,7 +385,7 @@ const Parse = struct {
385 .expected_lbrace => |bad_index| {385 .expected_lbrace => |bad_index| {
386 try p.appendErrorOff(386 try p.appendErrorOff(
387 token,387 token,
388 offset + @intCast(u32, bad_index),388 offset + @as(u32, @intCast(bad_index)),
389 "expected '{{', found '{c}",389 "expected '{{', found '{c}",
390 .{raw_string[bad_index]},390 .{raw_string[bad_index]},
391 );391 );
...@@ -393,7 +393,7 @@ const Parse = struct {...@@ -393,7 +393,7 @@ const Parse = struct {
393 .expected_rbrace => |bad_index| {393 .expected_rbrace => |bad_index| {
394 try p.appendErrorOff(394 try p.appendErrorOff(
395 token,395 token,
396 offset + @intCast(u32, bad_index),396 offset + @as(u32, @intCast(bad_index)),
397 "expected '}}', found '{c}",397 "expected '}}', found '{c}",
398 .{raw_string[bad_index]},398 .{raw_string[bad_index]},
399 );399 );
...@@ -401,7 +401,7 @@ const Parse = struct {...@@ -401,7 +401,7 @@ const Parse = struct {
401 .expected_single_quote => |bad_index| {401 .expected_single_quote => |bad_index| {
402 try p.appendErrorOff(402 try p.appendErrorOff(
403 token,403 token,
404 offset + @intCast(u32, bad_index),404 offset + @as(u32, @intCast(bad_index)),
405 "expected single quote ('), found '{c}",405 "expected single quote ('), found '{c}",
406 .{raw_string[bad_index]},406 .{raw_string[bad_index]},
407 );407 );
...@@ -409,7 +409,7 @@ const Parse = struct {...@@ -409,7 +409,7 @@ const Parse = struct {
409 .invalid_character => |bad_index| {409 .invalid_character => |bad_index| {
410 try p.appendErrorOff(410 try p.appendErrorOff(
411 token,411 token,
412 offset + @intCast(u32, bad_index),412 offset + @as(u32, @intCast(bad_index)),
413 "invalid byte in string or character literal: '{c}'",413 "invalid byte in string or character literal: '{c}'",
414 .{raw_string[bad_index]},414 .{raw_string[bad_index]},
415 );415 );
src/Module.zig+83-83
...@@ -554,7 +554,7 @@ pub const Decl = struct {...@@ -554,7 +554,7 @@ pub const Decl = struct {
554 _,554 _,
555555
556 pub fn toOptional(i: Index) OptionalIndex {556 pub fn toOptional(i: Index) OptionalIndex {
557 return @enumFromInt(OptionalIndex, @intFromEnum(i));557 return @as(OptionalIndex, @enumFromInt(@intFromEnum(i)));
558 }558 }
559 };559 };
560560
...@@ -563,12 +563,12 @@ pub const Decl = struct {...@@ -563,12 +563,12 @@ pub const Decl = struct {
563 _,563 _,
564564
565 pub fn init(oi: ?Index) OptionalIndex {565 pub fn init(oi: ?Index) OptionalIndex {
566 return @enumFromInt(OptionalIndex, @intFromEnum(oi orelse return .none));566 return @as(OptionalIndex, @enumFromInt(@intFromEnum(oi orelse return .none)));
567 }567 }
568568
569 pub fn unwrap(oi: OptionalIndex) ?Index {569 pub fn unwrap(oi: OptionalIndex) ?Index {
570 if (oi == .none) return null;570 if (oi == .none) return null;
571 return @enumFromInt(Index, @intFromEnum(oi));571 return @as(Index, @enumFromInt(@intFromEnum(oi)));
572 }572 }
573 };573 };
574574
...@@ -619,7 +619,7 @@ pub const Decl = struct {...@@ -619,7 +619,7 @@ pub const Decl = struct {
619 pub fn contentsHashZir(decl: Decl, zir: Zir) std.zig.SrcHash {619 pub fn contentsHashZir(decl: Decl, zir: Zir) std.zig.SrcHash {
620 assert(decl.zir_decl_index != 0);620 assert(decl.zir_decl_index != 0);
621 const hash_u32s = zir.extra[decl.zir_decl_index..][0..4];621 const hash_u32s = zir.extra[decl.zir_decl_index..][0..4];
622 const contents_hash = @bitCast(std.zig.SrcHash, hash_u32s.*);622 const contents_hash = @as(std.zig.SrcHash, @bitCast(hash_u32s.*));
623 return contents_hash;623 return contents_hash;
624 }624 }
625625
...@@ -633,7 +633,7 @@ pub const Decl = struct {...@@ -633,7 +633,7 @@ pub const Decl = struct {
633 if (!decl.has_align) return .none;633 if (!decl.has_align) return .none;
634 assert(decl.zir_decl_index != 0);634 assert(decl.zir_decl_index != 0);
635 const zir = decl.getFileScope(mod).zir;635 const zir = decl.getFileScope(mod).zir;
636 return @enumFromInt(Zir.Inst.Ref, zir.extra[decl.zir_decl_index + 8]);636 return @as(Zir.Inst.Ref, @enumFromInt(zir.extra[decl.zir_decl_index + 8]));
637 }637 }
638638
639 pub fn zirLinksectionRef(decl: Decl, mod: *Module) Zir.Inst.Ref {639 pub fn zirLinksectionRef(decl: Decl, mod: *Module) Zir.Inst.Ref {
...@@ -641,7 +641,7 @@ pub const Decl = struct {...@@ -641,7 +641,7 @@ pub const Decl = struct {
641 assert(decl.zir_decl_index != 0);641 assert(decl.zir_decl_index != 0);
642 const zir = decl.getFileScope(mod).zir;642 const zir = decl.getFileScope(mod).zir;
643 const extra_index = decl.zir_decl_index + 8 + @intFromBool(decl.has_align);643 const extra_index = decl.zir_decl_index + 8 + @intFromBool(decl.has_align);
644 return @enumFromInt(Zir.Inst.Ref, zir.extra[extra_index]);644 return @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index]));
645 }645 }
646646
647 pub fn zirAddrspaceRef(decl: Decl, mod: *Module) Zir.Inst.Ref {647 pub fn zirAddrspaceRef(decl: Decl, mod: *Module) Zir.Inst.Ref {
...@@ -649,7 +649,7 @@ pub const Decl = struct {...@@ -649,7 +649,7 @@ pub const Decl = struct {
649 assert(decl.zir_decl_index != 0);649 assert(decl.zir_decl_index != 0);
650 const zir = decl.getFileScope(mod).zir;650 const zir = decl.getFileScope(mod).zir;
651 const extra_index = decl.zir_decl_index + 8 + @intFromBool(decl.has_align) + 1;651 const extra_index = decl.zir_decl_index + 8 + @intFromBool(decl.has_align) + 1;
652 return @enumFromInt(Zir.Inst.Ref, zir.extra[extra_index]);652 return @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index]));
653 }653 }
654654
655 pub fn relativeToLine(decl: Decl, offset: u32) u32 {655 pub fn relativeToLine(decl: Decl, offset: u32) u32 {
...@@ -657,11 +657,11 @@ pub const Decl = struct {...@@ -657,11 +657,11 @@ pub const Decl = struct {
657 }657 }
658658
659 pub fn relativeToNodeIndex(decl: Decl, offset: i32) Ast.Node.Index {659 pub fn relativeToNodeIndex(decl: Decl, offset: i32) Ast.Node.Index {
660 return @bitCast(Ast.Node.Index, offset + @bitCast(i32, decl.src_node));660 return @as(Ast.Node.Index, @bitCast(offset + @as(i32, @bitCast(decl.src_node))));
661 }661 }
662662
663 pub fn nodeIndexToRelative(decl: Decl, node_index: Ast.Node.Index) i32 {663 pub fn nodeIndexToRelative(decl: Decl, node_index: Ast.Node.Index) i32 {
664 return @bitCast(i32, node_index) - @bitCast(i32, decl.src_node);664 return @as(i32, @bitCast(node_index)) - @as(i32, @bitCast(decl.src_node));
665 }665 }
666666
667 pub fn tokSrcLoc(decl: Decl, token_index: Ast.TokenIndex) LazySrcLoc {667 pub fn tokSrcLoc(decl: Decl, token_index: Ast.TokenIndex) LazySrcLoc {
...@@ -864,7 +864,7 @@ pub const Decl = struct {...@@ -864,7 +864,7 @@ pub const Decl = struct {
864864
865 pub fn getAlignment(decl: Decl, mod: *Module) u32 {865 pub fn getAlignment(decl: Decl, mod: *Module) u32 {
866 assert(decl.has_tv);866 assert(decl.has_tv);
867 return @intCast(u32, decl.alignment.toByteUnitsOptional() orelse decl.ty.abiAlignment(mod));867 return @as(u32, @intCast(decl.alignment.toByteUnitsOptional() orelse decl.ty.abiAlignment(mod)));
868 }868 }
869869
870 pub fn intern(decl: *Decl, mod: *Module) Allocator.Error!void {870 pub fn intern(decl: *Decl, mod: *Module) Allocator.Error!void {
...@@ -922,7 +922,7 @@ pub const Struct = struct {...@@ -922,7 +922,7 @@ pub const Struct = struct {
922 _,922 _,
923923
924 pub fn toOptional(i: Index) OptionalIndex {924 pub fn toOptional(i: Index) OptionalIndex {
925 return @enumFromInt(OptionalIndex, @intFromEnum(i));925 return @as(OptionalIndex, @enumFromInt(@intFromEnum(i)));
926 }926 }
927 };927 };
928928
...@@ -931,12 +931,12 @@ pub const Struct = struct {...@@ -931,12 +931,12 @@ pub const Struct = struct {
931 _,931 _,
932932
933 pub fn init(oi: ?Index) OptionalIndex {933 pub fn init(oi: ?Index) OptionalIndex {
934 return @enumFromInt(OptionalIndex, @intFromEnum(oi orelse return .none));934 return @as(OptionalIndex, @enumFromInt(@intFromEnum(oi orelse return .none)));
935 }935 }
936936
937 pub fn unwrap(oi: OptionalIndex) ?Index {937 pub fn unwrap(oi: OptionalIndex) ?Index {
938 if (oi == .none) return null;938 if (oi == .none) return null;
939 return @enumFromInt(Index, @intFromEnum(oi));939 return @as(Index, @enumFromInt(@intFromEnum(oi)));
940 }940 }
941 };941 };
942942
...@@ -964,7 +964,7 @@ pub const Struct = struct {...@@ -964,7 +964,7 @@ pub const Struct = struct {
964 ) u32 {964 ) u32 {
965 if (field.abi_align.toByteUnitsOptional()) |abi_align| {965 if (field.abi_align.toByteUnitsOptional()) |abi_align| {
966 assert(layout != .Packed);966 assert(layout != .Packed);
967 return @intCast(u32, abi_align);967 return @as(u32, @intCast(abi_align));
968 }968 }
969969
970 const target = mod.getTarget();970 const target = mod.getTarget();
...@@ -1042,7 +1042,7 @@ pub const Struct = struct {...@@ -1042,7 +1042,7 @@ pub const Struct = struct {
1042 var bit_sum: u64 = 0;1042 var bit_sum: u64 = 0;
1043 for (s.fields.values(), 0..) |field, i| {1043 for (s.fields.values(), 0..) |field, i| {
1044 if (i == index) {1044 if (i == index) {
1045 return @intCast(u16, bit_sum);1045 return @as(u16, @intCast(bit_sum));
1046 }1046 }
1047 bit_sum += field.ty.bitSize(mod);1047 bit_sum += field.ty.bitSize(mod);
1048 }1048 }
...@@ -1123,7 +1123,7 @@ pub const Union = struct {...@@ -1123,7 +1123,7 @@ pub const Union = struct {
1123 _,1123 _,
11241124
1125 pub fn toOptional(i: Index) OptionalIndex {1125 pub fn toOptional(i: Index) OptionalIndex {
1126 return @enumFromInt(OptionalIndex, @intFromEnum(i));1126 return @as(OptionalIndex, @enumFromInt(@intFromEnum(i)));
1127 }1127 }
1128 };1128 };
11291129
...@@ -1132,12 +1132,12 @@ pub const Union = struct {...@@ -1132,12 +1132,12 @@ pub const Union = struct {
1132 _,1132 _,
11331133
1134 pub fn init(oi: ?Index) OptionalIndex {1134 pub fn init(oi: ?Index) OptionalIndex {
1135 return @enumFromInt(OptionalIndex, @intFromEnum(oi orelse return .none));1135 return @as(OptionalIndex, @enumFromInt(@intFromEnum(oi orelse return .none)));
1136 }1136 }
11371137
1138 pub fn unwrap(oi: OptionalIndex) ?Index {1138 pub fn unwrap(oi: OptionalIndex) ?Index {
1139 if (oi == .none) return null;1139 if (oi == .none) return null;
1140 return @enumFromInt(Index, @intFromEnum(oi));1140 return @as(Index, @enumFromInt(@intFromEnum(oi)));
1141 }1141 }
1142 };1142 };
11431143
...@@ -1151,7 +1151,7 @@ pub const Union = struct {...@@ -1151,7 +1151,7 @@ pub const Union = struct {
1151 /// Keep implementation in sync with `Sema.unionFieldAlignment`.1151 /// Keep implementation in sync with `Sema.unionFieldAlignment`.
1152 /// Prefer to call that function instead of this one during Sema.1152 /// Prefer to call that function instead of this one during Sema.
1153 pub fn normalAlignment(field: Field, mod: *Module) u32 {1153 pub fn normalAlignment(field: Field, mod: *Module) u32 {
1154 return @intCast(u32, field.abi_align.toByteUnitsOptional() orelse field.ty.abiAlignment(mod));1154 return @as(u32, @intCast(field.abi_align.toByteUnitsOptional() orelse field.ty.abiAlignment(mod)));
1155 }1155 }
1156 };1156 };
11571157
...@@ -1205,7 +1205,7 @@ pub const Union = struct {...@@ -1205,7 +1205,7 @@ pub const Union = struct {
1205 most_index = i;1205 most_index = i;
1206 }1206 }
1207 }1207 }
1208 return @intCast(u32, most_index);1208 return @as(u32, @intCast(most_index));
1209 }1209 }
12101210
1211 /// Returns 0 if the union is represented with 0 bits at runtime.1211 /// Returns 0 if the union is represented with 0 bits at runtime.
...@@ -1267,11 +1267,11 @@ pub const Union = struct {...@@ -1267,11 +1267,11 @@ pub const Union = struct {
1267 const field_size = field.ty.abiSize(mod);1267 const field_size = field.ty.abiSize(mod);
1268 if (field_size > payload_size) {1268 if (field_size > payload_size) {
1269 payload_size = field_size;1269 payload_size = field_size;
1270 biggest_field = @intCast(u32, i);1270 biggest_field = @as(u32, @intCast(i));
1271 }1271 }
1272 if (field_align > payload_align) {1272 if (field_align > payload_align) {
1273 payload_align = @intCast(u32, field_align);1273 payload_align = @as(u32, @intCast(field_align));
1274 most_aligned_field = @intCast(u32, i);1274 most_aligned_field = @as(u32, @intCast(i));
1275 most_aligned_field_size = field_size;1275 most_aligned_field_size = field_size;
1276 }1276 }
1277 }1277 }
...@@ -1303,7 +1303,7 @@ pub const Union = struct {...@@ -1303,7 +1303,7 @@ pub const Union = struct {
1303 size += payload_size;1303 size += payload_size;
1304 const prev_size = size;1304 const prev_size = size;
1305 size = std.mem.alignForward(u64, size, tag_align);1305 size = std.mem.alignForward(u64, size, tag_align);
1306 padding = @intCast(u32, size - prev_size);1306 padding = @as(u32, @intCast(size - prev_size));
1307 } else {1307 } else {
1308 // {Payload, Tag}1308 // {Payload, Tag}
1309 size += payload_size;1309 size += payload_size;
...@@ -1311,7 +1311,7 @@ pub const Union = struct {...@@ -1311,7 +1311,7 @@ pub const Union = struct {
1311 size += tag_size;1311 size += tag_size;
1312 const prev_size = size;1312 const prev_size = size;
1313 size = std.mem.alignForward(u64, size, payload_align);1313 size = std.mem.alignForward(u64, size, payload_align);
1314 padding = @intCast(u32, size - prev_size);1314 padding = @as(u32, @intCast(size - prev_size));
1315 }1315 }
1316 return .{1316 return .{
1317 .abi_size = size,1317 .abi_size = size,
...@@ -1409,7 +1409,7 @@ pub const Fn = struct {...@@ -1409,7 +1409,7 @@ pub const Fn = struct {
1409 _,1409 _,
14101410
1411 pub fn toOptional(i: Index) OptionalIndex {1411 pub fn toOptional(i: Index) OptionalIndex {
1412 return @enumFromInt(OptionalIndex, @intFromEnum(i));1412 return @as(OptionalIndex, @enumFromInt(@intFromEnum(i)));
1413 }1413 }
1414 };1414 };
14151415
...@@ -1418,12 +1418,12 @@ pub const Fn = struct {...@@ -1418,12 +1418,12 @@ pub const Fn = struct {
1418 _,1418 _,
14191419
1420 pub fn init(oi: ?Index) OptionalIndex {1420 pub fn init(oi: ?Index) OptionalIndex {
1421 return @enumFromInt(OptionalIndex, @intFromEnum(oi orelse return .none));1421 return @as(OptionalIndex, @enumFromInt(@intFromEnum(oi orelse return .none)));
1422 }1422 }
14231423
1424 pub fn unwrap(oi: OptionalIndex) ?Index {1424 pub fn unwrap(oi: OptionalIndex) ?Index {
1425 if (oi == .none) return null;1425 if (oi == .none) return null;
1426 return @enumFromInt(Index, @intFromEnum(oi));1426 return @as(Index, @enumFromInt(@intFromEnum(oi)));
1427 }1427 }
1428 };1428 };
14291429
...@@ -1477,7 +1477,7 @@ pub const Fn = struct {...@@ -1477,7 +1477,7 @@ pub const Fn = struct {
1477 _,1477 _,
14781478
1479 pub fn toOptional(i: InferredErrorSet.Index) InferredErrorSet.OptionalIndex {1479 pub fn toOptional(i: InferredErrorSet.Index) InferredErrorSet.OptionalIndex {
1480 return @enumFromInt(InferredErrorSet.OptionalIndex, @intFromEnum(i));1480 return @as(InferredErrorSet.OptionalIndex, @enumFromInt(@intFromEnum(i)));
1481 }1481 }
1482 };1482 };
14831483
...@@ -1486,12 +1486,12 @@ pub const Fn = struct {...@@ -1486,12 +1486,12 @@ pub const Fn = struct {
1486 _,1486 _,
14871487
1488 pub fn init(oi: ?InferredErrorSet.Index) InferredErrorSet.OptionalIndex {1488 pub fn init(oi: ?InferredErrorSet.Index) InferredErrorSet.OptionalIndex {
1489 return @enumFromInt(InferredErrorSet.OptionalIndex, @intFromEnum(oi orelse return .none));1489 return @as(InferredErrorSet.OptionalIndex, @enumFromInt(@intFromEnum(oi orelse return .none)));
1490 }1490 }
14911491
1492 pub fn unwrap(oi: InferredErrorSet.OptionalIndex) ?InferredErrorSet.Index {1492 pub fn unwrap(oi: InferredErrorSet.OptionalIndex) ?InferredErrorSet.Index {
1493 if (oi == .none) return null;1493 if (oi == .none) return null;
1494 return @enumFromInt(InferredErrorSet.Index, @intFromEnum(oi));1494 return @as(InferredErrorSet.Index, @enumFromInt(@intFromEnum(oi)));
1495 }1495 }
1496 };1496 };
14971497
...@@ -1613,7 +1613,7 @@ pub const Namespace = struct {...@@ -1613,7 +1613,7 @@ pub const Namespace = struct {
1613 _,1613 _,
16141614
1615 pub fn toOptional(i: Index) OptionalIndex {1615 pub fn toOptional(i: Index) OptionalIndex {
1616 return @enumFromInt(OptionalIndex, @intFromEnum(i));1616 return @as(OptionalIndex, @enumFromInt(@intFromEnum(i)));
1617 }1617 }
1618 };1618 };
16191619
...@@ -1622,12 +1622,12 @@ pub const Namespace = struct {...@@ -1622,12 +1622,12 @@ pub const Namespace = struct {
1622 _,1622 _,
16231623
1624 pub fn init(oi: ?Index) OptionalIndex {1624 pub fn init(oi: ?Index) OptionalIndex {
1625 return @enumFromInt(OptionalIndex, @intFromEnum(oi orelse return .none));1625 return @as(OptionalIndex, @enumFromInt(@intFromEnum(oi orelse return .none)));
1626 }1626 }
16271627
1628 pub fn unwrap(oi: OptionalIndex) ?Index {1628 pub fn unwrap(oi: OptionalIndex) ?Index {
1629 if (oi == .none) return null;1629 if (oi == .none) return null;
1630 return @enumFromInt(Index, @intFromEnum(oi));1630 return @as(Index, @enumFromInt(@intFromEnum(oi)));
1631 }1631 }
1632 };1632 };
16331633
...@@ -1867,7 +1867,7 @@ pub const File = struct {...@@ -1867,7 +1867,7 @@ pub const File = struct {
1867 if (stat.size > std.math.maxInt(u32))1867 if (stat.size > std.math.maxInt(u32))
1868 return error.FileTooBig;1868 return error.FileTooBig;
18691869
1870 const source = try gpa.allocSentinel(u8, @intCast(usize, stat.size), 0);1870 const source = try gpa.allocSentinel(u8, @as(usize, @intCast(stat.size)), 0);
1871 defer if (!file.source_loaded) gpa.free(source);1871 defer if (!file.source_loaded) gpa.free(source);
1872 const amt = try f.readAll(source);1872 const amt = try f.readAll(source);
1873 if (amt != stat.size)1873 if (amt != stat.size)
...@@ -2116,7 +2116,7 @@ pub const SrcLoc = struct {...@@ -2116,7 +2116,7 @@ pub const SrcLoc = struct {
2116 }2116 }
21172117
2118 pub fn declRelativeToNodeIndex(src_loc: SrcLoc, offset: i32) Ast.TokenIndex {2118 pub fn declRelativeToNodeIndex(src_loc: SrcLoc, offset: i32) Ast.TokenIndex {
2119 return @bitCast(Ast.Node.Index, offset + @bitCast(i32, src_loc.parent_decl_node));2119 return @as(Ast.Node.Index, @bitCast(offset + @as(i32, @bitCast(src_loc.parent_decl_node))));
2120 }2120 }
21212121
2122 pub const Span = struct {2122 pub const Span = struct {
...@@ -2135,7 +2135,7 @@ pub const SrcLoc = struct {...@@ -2135,7 +2135,7 @@ pub const SrcLoc = struct {
2135 .token_abs => |tok_index| {2135 .token_abs => |tok_index| {
2136 const tree = try src_loc.file_scope.getTree(gpa);2136 const tree = try src_loc.file_scope.getTree(gpa);
2137 const start = tree.tokens.items(.start)[tok_index];2137 const start = tree.tokens.items(.start)[tok_index];
2138 const end = start + @intCast(u32, tree.tokenSlice(tok_index).len);2138 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
2139 return Span{ .start = start, .end = end, .main = start };2139 return Span{ .start = start, .end = end, .main = start };
2140 },2140 },
2141 .node_abs => |node| {2141 .node_abs => |node| {
...@@ -2146,14 +2146,14 @@ pub const SrcLoc = struct {...@@ -2146,14 +2146,14 @@ pub const SrcLoc = struct {
2146 const tree = try src_loc.file_scope.getTree(gpa);2146 const tree = try src_loc.file_scope.getTree(gpa);
2147 const tok_index = src_loc.declSrcToken();2147 const tok_index = src_loc.declSrcToken();
2148 const start = tree.tokens.items(.start)[tok_index] + byte_off;2148 const start = tree.tokens.items(.start)[tok_index] + byte_off;
2149 const end = start + @intCast(u32, tree.tokenSlice(tok_index).len);2149 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
2150 return Span{ .start = start, .end = end, .main = start };2150 return Span{ .start = start, .end = end, .main = start };
2151 },2151 },
2152 .token_offset => |tok_off| {2152 .token_offset => |tok_off| {
2153 const tree = try src_loc.file_scope.getTree(gpa);2153 const tree = try src_loc.file_scope.getTree(gpa);
2154 const tok_index = src_loc.declSrcToken() + tok_off;2154 const tok_index = src_loc.declSrcToken() + tok_off;
2155 const start = tree.tokens.items(.start)[tok_index];2155 const start = tree.tokens.items(.start)[tok_index];
2156 const end = start + @intCast(u32, tree.tokenSlice(tok_index).len);2156 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
2157 return Span{ .start = start, .end = end, .main = start };2157 return Span{ .start = start, .end = end, .main = start };
2158 },2158 },
2159 .node_offset => |traced_off| {2159 .node_offset => |traced_off| {
...@@ -2206,7 +2206,7 @@ pub const SrcLoc = struct {...@@ -2206,7 +2206,7 @@ pub const SrcLoc = struct {
2206 }2206 }
2207 const tok_index = full.ast.mut_token + 1; // the name token2207 const tok_index = full.ast.mut_token + 1; // the name token
2208 const start = tree.tokens.items(.start)[tok_index];2208 const start = tree.tokens.items(.start)[tok_index];
2209 const end = start + @intCast(u32, tree.tokenSlice(tok_index).len);2209 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
2210 return Span{ .start = start, .end = end, .main = start };2210 return Span{ .start = start, .end = end, .main = start };
2211 },2211 },
2212 .node_offset_var_decl_align => |node_off| {2212 .node_offset_var_decl_align => |node_off| {
...@@ -2292,7 +2292,7 @@ pub const SrcLoc = struct {...@@ -2292,7 +2292,7 @@ pub const SrcLoc = struct {
2292 else => tree.firstToken(node) - 2,2292 else => tree.firstToken(node) - 2,
2293 };2293 };
2294 const start = tree.tokens.items(.start)[tok_index];2294 const start = tree.tokens.items(.start)[tok_index];
2295 const end = start + @intCast(u32, tree.tokenSlice(tok_index).len);2295 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
2296 return Span{ .start = start, .end = end, .main = start };2296 return Span{ .start = start, .end = end, .main = start };
2297 },2297 },
2298 .node_offset_deref_ptr => |node_off| {2298 .node_offset_deref_ptr => |node_off| {
...@@ -2359,7 +2359,7 @@ pub const SrcLoc = struct {...@@ -2359,7 +2359,7 @@ pub const SrcLoc = struct {
2359 // that contains this input.2359 // that contains this input.
2360 const node_tags = tree.nodes.items(.tag);2360 const node_tags = tree.nodes.items(.tag);
2361 for (node_tags, 0..) |node_tag, node_usize| {2361 for (node_tags, 0..) |node_tag, node_usize| {
2362 const node = @intCast(Ast.Node.Index, node_usize);2362 const node = @as(Ast.Node.Index, @intCast(node_usize));
2363 switch (node_tag) {2363 switch (node_tag) {
2364 .for_simple, .@"for" => {2364 .for_simple, .@"for" => {
2365 const for_full = tree.fullFor(node).?;2365 const for_full = tree.fullFor(node).?;
...@@ -2479,7 +2479,7 @@ pub const SrcLoc = struct {...@@ -2479,7 +2479,7 @@ pub const SrcLoc = struct {
2479 };2479 };
2480 const start = tree.tokens.items(.start)[start_tok];2480 const start = tree.tokens.items(.start)[start_tok];
2481 const end_start = tree.tokens.items(.start)[end_tok];2481 const end_start = tree.tokens.items(.start)[end_tok];
2482 const end = end_start + @intCast(u32, tree.tokenSlice(end_tok).len);2482 const end = end_start + @as(u32, @intCast(tree.tokenSlice(end_tok).len));
2483 return Span{ .start = start, .end = end, .main = start };2483 return Span{ .start = start, .end = end, .main = start };
2484 },2484 },
2485 .node_offset_fn_type_align => |node_off| {2485 .node_offset_fn_type_align => |node_off| {
...@@ -2539,7 +2539,7 @@ pub const SrcLoc = struct {...@@ -2539,7 +2539,7 @@ pub const SrcLoc = struct {
2539 const tree = try src_loc.file_scope.getTree(gpa);2539 const tree = try src_loc.file_scope.getTree(gpa);
2540 const token_tags = tree.tokens.items(.tag);2540 const token_tags = tree.tokens.items(.tag);
2541 const main_token = tree.nodes.items(.main_token)[src_loc.parent_decl_node];2541 const main_token = tree.nodes.items(.main_token)[src_loc.parent_decl_node];
2542 const tok_index = @bitCast(Ast.TokenIndex, token_off + @bitCast(i32, main_token));2542 const tok_index = @as(Ast.TokenIndex, @bitCast(token_off + @as(i32, @bitCast(main_token))));
25432543
2544 var first_tok = tok_index;2544 var first_tok = tok_index;
2545 while (true) switch (token_tags[first_tok - 1]) {2545 while (true) switch (token_tags[first_tok - 1]) {
...@@ -2568,7 +2568,7 @@ pub const SrcLoc = struct {...@@ -2568,7 +2568,7 @@ pub const SrcLoc = struct {
2568 const full = tree.fullFnProto(&buf, parent_node).?;2568 const full = tree.fullFnProto(&buf, parent_node).?;
2569 const tok_index = full.lib_name.?;2569 const tok_index = full.lib_name.?;
2570 const start = tree.tokens.items(.start)[tok_index];2570 const start = tree.tokens.items(.start)[tok_index];
2571 const end = start + @intCast(u32, tree.tokenSlice(tok_index).len);2571 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
2572 return Span{ .start = start, .end = end, .main = start };2572 return Span{ .start = start, .end = end, .main = start };
2573 },2573 },
25742574
...@@ -2761,7 +2761,7 @@ pub const SrcLoc = struct {...@@ -2761,7 +2761,7 @@ pub const SrcLoc = struct {
2761 end_tok = main;2761 end_tok = main;
2762 }2762 }
2763 const start_off = token_starts[start_tok];2763 const start_off = token_starts[start_tok];
2764 const end_off = token_starts[end_tok] + @intCast(u32, tree.tokenSlice(end_tok).len);2764 const end_off = token_starts[end_tok] + @as(u32, @intCast(tree.tokenSlice(end_tok).len));
2765 return Span{ .start = start_off, .end = end_off, .main = token_starts[main] };2765 return Span{ .start = start_off, .end = end_off, .main = token_starts[main] };
2766 }2766 }
2767};2767};
...@@ -3577,7 +3577,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void {...@@ -3577,7 +3577,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
3577 if (stat.size > std.math.maxInt(u32))3577 if (stat.size > std.math.maxInt(u32))
3578 return error.FileTooBig;3578 return error.FileTooBig;
35793579
3580 const source = try gpa.allocSentinel(u8, @intCast(usize, stat.size), 0);3580 const source = try gpa.allocSentinel(u8, @as(usize, @intCast(stat.size)), 0);
3581 defer if (!file.source_loaded) gpa.free(source);3581 defer if (!file.source_loaded) gpa.free(source);
3582 const amt = try source_file.readAll(source);3582 const amt = try source_file.readAll(source);
3583 if (amt != stat.size)3583 if (amt != stat.size)
...@@ -3609,21 +3609,21 @@ pub fn astGenFile(mod: *Module, file: *File) !void {...@@ -3609,21 +3609,21 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
3609 if (file.zir.instructions.len == 0)3609 if (file.zir.instructions.len == 0)
3610 @as([*]const u8, undefined)3610 @as([*]const u8, undefined)
3611 else3611 else
3612 @ptrCast([*]const u8, safety_buffer.ptr)3612 @as([*]const u8, @ptrCast(safety_buffer.ptr))
3613 else3613 else
3614 @ptrCast([*]const u8, file.zir.instructions.items(.data).ptr);3614 @as([*]const u8, @ptrCast(file.zir.instructions.items(.data).ptr));
3615 if (data_has_safety_tag) {3615 if (data_has_safety_tag) {
3616 // The `Data` union has a safety tag but in the file format we store it without.3616 // The `Data` union has a safety tag but in the file format we store it without.
3617 for (file.zir.instructions.items(.data), 0..) |*data, i| {3617 for (file.zir.instructions.items(.data), 0..) |*data, i| {
3618 const as_struct = @ptrCast(*const HackDataLayout, data);3618 const as_struct = @as(*const HackDataLayout, @ptrCast(data));
3619 safety_buffer[i] = as_struct.data;3619 safety_buffer[i] = as_struct.data;
3620 }3620 }
3621 }3621 }
36223622
3623 const header: Zir.Header = .{3623 const header: Zir.Header = .{
3624 .instructions_len = @intCast(u32, file.zir.instructions.len),3624 .instructions_len = @as(u32, @intCast(file.zir.instructions.len)),
3625 .string_bytes_len = @intCast(u32, file.zir.string_bytes.len),3625 .string_bytes_len = @as(u32, @intCast(file.zir.string_bytes.len)),
3626 .extra_len = @intCast(u32, file.zir.extra.len),3626 .extra_len = @as(u32, @intCast(file.zir.extra.len)),
36273627
3628 .stat_size = stat.size,3628 .stat_size = stat.size,
3629 .stat_inode = stat.inode,3629 .stat_inode = stat.inode,
...@@ -3631,11 +3631,11 @@ pub fn astGenFile(mod: *Module, file: *File) !void {...@@ -3631,11 +3631,11 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
3631 };3631 };
3632 var iovecs = [_]std.os.iovec_const{3632 var iovecs = [_]std.os.iovec_const{
3633 .{3633 .{
3634 .iov_base = @ptrCast([*]const u8, &header),3634 .iov_base = @as([*]const u8, @ptrCast(&header)),
3635 .iov_len = @sizeOf(Zir.Header),3635 .iov_len = @sizeOf(Zir.Header),
3636 },3636 },
3637 .{3637 .{
3638 .iov_base = @ptrCast([*]const u8, file.zir.instructions.items(.tag).ptr),3638 .iov_base = @as([*]const u8, @ptrCast(file.zir.instructions.items(.tag).ptr)),
3639 .iov_len = file.zir.instructions.len,3639 .iov_len = file.zir.instructions.len,
3640 },3640 },
3641 .{3641 .{
...@@ -3647,7 +3647,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void {...@@ -3647,7 +3647,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
3647 .iov_len = file.zir.string_bytes.len,3647 .iov_len = file.zir.string_bytes.len,
3648 },3648 },
3649 .{3649 .{
3650 .iov_base = @ptrCast([*]const u8, file.zir.extra.ptr),3650 .iov_base = @as([*]const u8, @ptrCast(file.zir.extra.ptr)),
3651 .iov_len = file.zir.extra.len * 4,3651 .iov_len = file.zir.extra.len * 4,
3652 },3652 },
3653 };3653 };
...@@ -3722,13 +3722,13 @@ fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File)...@@ -3722,13 +3722,13 @@ fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File)
3722 defer if (data_has_safety_tag) gpa.free(safety_buffer);3722 defer if (data_has_safety_tag) gpa.free(safety_buffer);
37233723
3724 const data_ptr = if (data_has_safety_tag)3724 const data_ptr = if (data_has_safety_tag)
3725 @ptrCast([*]u8, safety_buffer.ptr)3725 @as([*]u8, @ptrCast(safety_buffer.ptr))
3726 else3726 else
3727 @ptrCast([*]u8, zir.instructions.items(.data).ptr);3727 @as([*]u8, @ptrCast(zir.instructions.items(.data).ptr));
37283728
3729 var iovecs = [_]std.os.iovec{3729 var iovecs = [_]std.os.iovec{
3730 .{3730 .{
3731 .iov_base = @ptrCast([*]u8, zir.instructions.items(.tag).ptr),3731 .iov_base = @as([*]u8, @ptrCast(zir.instructions.items(.tag).ptr)),
3732 .iov_len = header.instructions_len,3732 .iov_len = header.instructions_len,
3733 },3733 },
3734 .{3734 .{
...@@ -3740,7 +3740,7 @@ fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File)...@@ -3740,7 +3740,7 @@ fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File)
3740 .iov_len = header.string_bytes_len,3740 .iov_len = header.string_bytes_len,
3741 },3741 },
3742 .{3742 .{
3743 .iov_base = @ptrCast([*]u8, zir.extra.ptr),3743 .iov_base = @as([*]u8, @ptrCast(zir.extra.ptr)),
3744 .iov_len = header.extra_len * 4,3744 .iov_len = header.extra_len * 4,
3745 },3745 },
3746 };3746 };
...@@ -3753,7 +3753,7 @@ fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File)...@@ -3753,7 +3753,7 @@ fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File)
3753 const tags = zir.instructions.items(.tag);3753 const tags = zir.instructions.items(.tag);
3754 for (zir.instructions.items(.data), 0..) |*data, i| {3754 for (zir.instructions.items(.data), 0..) |*data, i| {
3755 const union_tag = Zir.Inst.Tag.data_tags[@intFromEnum(tags[i])];3755 const union_tag = Zir.Inst.Tag.data_tags[@intFromEnum(tags[i])];
3756 const as_struct = @ptrCast(*HackDataLayout, data);3756 const as_struct = @as(*HackDataLayout, @ptrCast(data));
3757 as_struct.* = .{3757 as_struct.* = .{
3758 .safety_tag = @intFromEnum(union_tag),3758 .safety_tag = @intFromEnum(union_tag),
3759 .data = safety_buffer[i],3759 .data = safety_buffer[i],
...@@ -4394,7 +4394,7 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {...@@ -4394,7 +4394,7 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
4394 const struct_obj = mod.structPtr(struct_index);4394 const struct_obj = mod.structPtr(struct_index);
4395 struct_obj.zir_index = main_struct_inst;4395 struct_obj.zir_index = main_struct_inst;
4396 const extended = file.zir.instructions.items(.data)[main_struct_inst].extended;4396 const extended = file.zir.instructions.items(.data)[main_struct_inst].extended;
4397 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);4397 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
4398 struct_obj.is_tuple = small.is_tuple;4398 struct_obj.is_tuple = small.is_tuple;
43994399
4400 var sema_arena = std.heap.ArenaAllocator.init(gpa);4400 var sema_arena = std.heap.ArenaAllocator.init(gpa);
...@@ -5051,13 +5051,13 @@ pub fn scanNamespace(...@@ -5051,13 +5051,13 @@ pub fn scanNamespace(
5051 cur_bit_bag = zir.extra[bit_bag_index];5051 cur_bit_bag = zir.extra[bit_bag_index];
5052 bit_bag_index += 1;5052 bit_bag_index += 1;
5053 }5053 }
5054 const flags = @truncate(u4, cur_bit_bag);5054 const flags = @as(u4, @truncate(cur_bit_bag));
5055 cur_bit_bag >>= 4;5055 cur_bit_bag >>= 4;
50565056
5057 const decl_sub_index = extra_index;5057 const decl_sub_index = extra_index;
5058 extra_index += 8; // src_hash(4) + line(1) + name(1) + value(1) + doc_comment(1)5058 extra_index += 8; // src_hash(4) + line(1) + name(1) + value(1) + doc_comment(1)
5059 extra_index += @truncate(u1, flags >> 2); // Align5059 extra_index += @as(u1, @truncate(flags >> 2)); // Align
5060 extra_index += @as(u2, @truncate(u1, flags >> 3)) * 2; // Link section or address space, consists of 2 Refs5060 extra_index += @as(u2, @as(u1, @truncate(flags >> 3))) * 2; // Link section or address space, consists of 2 Refs
50615061
5062 try scanDecl(&scan_decl_iter, decl_sub_index, flags);5062 try scanDecl(&scan_decl_iter, decl_sub_index, flags);
5063 }5063 }
...@@ -5195,7 +5195,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err...@@ -5195,7 +5195,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
5195 new_decl.is_exported = is_exported;5195 new_decl.is_exported = is_exported;
5196 new_decl.has_align = has_align;5196 new_decl.has_align = has_align;
5197 new_decl.has_linksection_or_addrspace = has_linksection_or_addrspace;5197 new_decl.has_linksection_or_addrspace = has_linksection_or_addrspace;
5198 new_decl.zir_decl_index = @intCast(u32, decl_sub_index);5198 new_decl.zir_decl_index = @as(u32, @intCast(decl_sub_index));
5199 new_decl.alive = true; // This Decl corresponds to an AST node and therefore always alive.5199 new_decl.alive = true; // This Decl corresponds to an AST node and therefore always alive.
5200 return;5200 return;
5201 }5201 }
...@@ -5229,7 +5229,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err...@@ -5229,7 +5229,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
5229 decl.kind = kind;5229 decl.kind = kind;
5230 decl.has_align = has_align;5230 decl.has_align = has_align;
5231 decl.has_linksection_or_addrspace = has_linksection_or_addrspace;5231 decl.has_linksection_or_addrspace = has_linksection_or_addrspace;
5232 decl.zir_decl_index = @intCast(u32, decl_sub_index);5232 decl.zir_decl_index = @as(u32, @intCast(decl_sub_index));
5233 if (decl.getOwnedFunctionIndex(mod) != .none) {5233 if (decl.getOwnedFunctionIndex(mod) != .none) {
5234 switch (comp.bin_file.tag) {5234 switch (comp.bin_file.tag) {
5235 .coff, .elf, .macho, .plan9 => {5235 .coff, .elf, .macho, .plan9 => {
...@@ -5481,7 +5481,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: Fn.Index, arena: Allocator) SemaE...@@ -5481,7 +5481,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: Fn.Index, arena: Allocator) SemaE
5481 // This could be a generic function instantiation, however, in which case we need to5481 // This could be a generic function instantiation, however, in which case we need to
5482 // map the comptime parameters to constant values and only emit arg AIR instructions5482 // map the comptime parameters to constant values and only emit arg AIR instructions
5483 // for the runtime ones.5483 // for the runtime ones.
5484 const runtime_params_len = @intCast(u32, mod.typeToFunc(fn_ty).?.param_types.len);5484 const runtime_params_len = @as(u32, @intCast(mod.typeToFunc(fn_ty).?.param_types.len));
5485 try inner_block.instructions.ensureTotalCapacityPrecise(gpa, runtime_params_len);5485 try inner_block.instructions.ensureTotalCapacityPrecise(gpa, runtime_params_len);
5486 try sema.air_instructions.ensureUnusedCapacity(gpa, fn_info.total_params_len * 2); // * 2 for the `addType`5486 try sema.air_instructions.ensureUnusedCapacity(gpa, fn_info.total_params_len * 2); // * 2 for the `addType`
5487 try sema.inst_map.ensureSpaceForInstructions(gpa, fn_info.param_body);5487 try sema.inst_map.ensureSpaceForInstructions(gpa, fn_info.param_body);
...@@ -5524,13 +5524,13 @@ pub fn analyzeFnBody(mod: *Module, func_index: Fn.Index, arena: Allocator) SemaE...@@ -5524,13 +5524,13 @@ pub fn analyzeFnBody(mod: *Module, func_index: Fn.Index, arena: Allocator) SemaE
5524 continue;5524 continue;
5525 }5525 }
5526 const air_ty = try sema.addType(param_ty);5526 const air_ty = try sema.addType(param_ty);
5527 const arg_index = @intCast(u32, sema.air_instructions.len);5527 const arg_index = @as(u32, @intCast(sema.air_instructions.len));
5528 inner_block.instructions.appendAssumeCapacity(arg_index);5528 inner_block.instructions.appendAssumeCapacity(arg_index);
5529 sema.air_instructions.appendAssumeCapacity(.{5529 sema.air_instructions.appendAssumeCapacity(.{
5530 .tag = .arg,5530 .tag = .arg,
5531 .data = .{ .arg = .{5531 .data = .{ .arg = .{
5532 .ty = air_ty,5532 .ty = air_ty,
5533 .src_index = @intCast(u32, total_param_index),5533 .src_index = @as(u32, @intCast(total_param_index)),
5534 } },5534 } },
5535 });5535 });
5536 sema.inst_map.putAssumeCapacityNoClobber(inst, Air.indexToRef(arg_index));5536 sema.inst_map.putAssumeCapacityNoClobber(inst, Air.indexToRef(arg_index));
...@@ -5593,7 +5593,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: Fn.Index, arena: Allocator) SemaE...@@ -5593,7 +5593,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: Fn.Index, arena: Allocator) SemaE
5593 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +5593 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +
5594 inner_block.instructions.items.len);5594 inner_block.instructions.items.len);
5595 const main_block_index = sema.addExtraAssumeCapacity(Air.Block{5595 const main_block_index = sema.addExtraAssumeCapacity(Air.Block{
5596 .body_len = @intCast(u32, inner_block.instructions.items.len),5596 .body_len = @as(u32, @intCast(inner_block.instructions.items.len)),
5597 });5597 });
5598 sema.air_extra.appendSliceAssumeCapacity(inner_block.instructions.items);5598 sema.air_extra.appendSliceAssumeCapacity(inner_block.instructions.items);
5599 sema.air_extra.items[@intFromEnum(Air.ExtraIndex.main_block)] = main_block_index;5599 sema.air_extra.items[@intFromEnum(Air.ExtraIndex.main_block)] = main_block_index;
...@@ -5671,7 +5671,7 @@ pub fn createNamespace(mod: *Module, initialization: Namespace) !Namespace.Index...@@ -5671,7 +5671,7 @@ pub fn createNamespace(mod: *Module, initialization: Namespace) !Namespace.Index
5671 }5671 }
5672 const ptr = try mod.allocated_namespaces.addOne(mod.gpa);5672 const ptr = try mod.allocated_namespaces.addOne(mod.gpa);
5673 ptr.* = initialization;5673 ptr.* = initialization;
5674 return @enumFromInt(Namespace.Index, mod.allocated_namespaces.len - 1);5674 return @as(Namespace.Index, @enumFromInt(mod.allocated_namespaces.len - 1));
5675}5675}
56765676
5677pub fn destroyNamespace(mod: *Module, index: Namespace.Index) void {5677pub fn destroyNamespace(mod: *Module, index: Namespace.Index) void {
...@@ -5729,7 +5729,7 @@ pub fn allocateNewDecl(...@@ -5729,7 +5729,7 @@ pub fn allocateNewDecl(
5729 }5729 }
5730 break :d .{5730 break :d .{
5731 .new_decl = decl,5731 .new_decl = decl,
5732 .decl_index = @enumFromInt(Decl.Index, mod.allocated_decls.len - 1),5732 .decl_index = @as(Decl.Index, @enumFromInt(mod.allocated_decls.len - 1)),
5733 };5733 };
5734 };5734 };
57355735
...@@ -5767,7 +5767,7 @@ pub fn getErrorValue(...@@ -5767,7 +5767,7 @@ pub fn getErrorValue(
5767 name: InternPool.NullTerminatedString,5767 name: InternPool.NullTerminatedString,
5768) Allocator.Error!ErrorInt {5768) Allocator.Error!ErrorInt {
5769 const gop = try mod.global_error_set.getOrPut(mod.gpa, name);5769 const gop = try mod.global_error_set.getOrPut(mod.gpa, name);
5770 return @intCast(ErrorInt, gop.index);5770 return @as(ErrorInt, @intCast(gop.index));
5771}5771}
57725772
5773pub fn getErrorValueFromSlice(5773pub fn getErrorValueFromSlice(
...@@ -6139,7 +6139,7 @@ pub fn paramSrc(...@@ -6139,7 +6139,7 @@ pub fn paramSrc(
6139 if (i == param_i) {6139 if (i == param_i) {
6140 if (param.anytype_ellipsis3) |some| {6140 if (param.anytype_ellipsis3) |some| {
6141 const main_token = tree.nodes.items(.main_token)[decl.src_node];6141 const main_token = tree.nodes.items(.main_token)[decl.src_node];
6142 return .{ .token_offset_param = @bitCast(i32, some) - @bitCast(i32, main_token) };6142 return .{ .token_offset_param = @as(i32, @bitCast(some)) - @as(i32, @bitCast(main_token)) };
6143 }6143 }
6144 return .{ .node_offset_param = decl.nodeIndexToRelative(param.type_expr) };6144 return .{ .node_offset_param = decl.nodeIndexToRelative(param.type_expr) };
6145 }6145 }
...@@ -6892,11 +6892,11 @@ pub fn unionValue(mod: *Module, union_ty: Type, tag: Value, val: Value) Allocato...@@ -6892,11 +6892,11 @@ pub fn unionValue(mod: *Module, union_ty: Type, tag: Value, val: Value) Allocato
6892/// losing data if the representation wasn't correct.6892/// losing data if the representation wasn't correct.
6893pub fn floatValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {6893pub fn floatValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {
6894 const storage: InternPool.Key.Float.Storage = switch (ty.floatBits(mod.getTarget())) {6894 const storage: InternPool.Key.Float.Storage = switch (ty.floatBits(mod.getTarget())) {
6895 16 => .{ .f16 = @floatCast(f16, x) },6895 16 => .{ .f16 = @as(f16, @floatCast(x)) },
6896 32 => .{ .f32 = @floatCast(f32, x) },6896 32 => .{ .f32 = @as(f32, @floatCast(x)) },
6897 64 => .{ .f64 = @floatCast(f64, x) },6897 64 => .{ .f64 = @as(f64, @floatCast(x)) },
6898 80 => .{ .f80 = @floatCast(f80, x) },6898 80 => .{ .f80 = @as(f80, @floatCast(x)) },
6899 128 => .{ .f128 = @floatCast(f128, x) },6899 128 => .{ .f128 = @as(f128, @floatCast(x)) },
6900 else => unreachable,6900 else => unreachable,
6901 };6901 };
6902 const i = try intern(mod, .{ .float = .{6902 const i = try intern(mod, .{ .float = .{
...@@ -6956,18 +6956,18 @@ pub fn intBitsForValue(mod: *Module, val: Value, sign: bool) u16 {...@@ -6956,18 +6956,18 @@ pub fn intBitsForValue(mod: *Module, val: Value, sign: bool) u16 {
6956 assert(sign);6956 assert(sign);
6957 // Protect against overflow in the following negation.6957 // Protect against overflow in the following negation.
6958 if (x == std.math.minInt(i64)) return 64;6958 if (x == std.math.minInt(i64)) return 64;
6959 return Type.smallestUnsignedBits(@intCast(u64, -(x + 1))) + 1;6959 return Type.smallestUnsignedBits(@as(u64, @intCast(-(x + 1)))) + 1;
6960 },6960 },
6961 .u64 => |x| {6961 .u64 => |x| {
6962 return Type.smallestUnsignedBits(x) + @intFromBool(sign);6962 return Type.smallestUnsignedBits(x) + @intFromBool(sign);
6963 },6963 },
6964 .big_int => |big| {6964 .big_int => |big| {
6965 if (big.positive) return @intCast(u16, big.bitCountAbs() + @intFromBool(sign));6965 if (big.positive) return @as(u16, @intCast(big.bitCountAbs() + @intFromBool(sign)));
69666966
6967 // Zero is still a possibility, in which case unsigned is fine6967 // Zero is still a possibility, in which case unsigned is fine
6968 if (big.eqZero()) return 0;6968 if (big.eqZero()) return 0;
69696969
6970 return @intCast(u16, big.bitCountTwosComp());6970 return @as(u16, @intCast(big.bitCountTwosComp()));
6971 },6971 },
6972 .lazy_align => |lazy_ty| {6972 .lazy_align => |lazy_ty| {
6973 return Type.smallestUnsignedBits(lazy_ty.toType().abiAlignment(mod)) + @intFromBool(sign);6973 return Type.smallestUnsignedBits(lazy_ty.toType().abiAlignment(mod)) + @intFromBool(sign);
src/Package.zig+3-3
...@@ -390,10 +390,10 @@ const Report = struct {...@@ -390,10 +390,10 @@ const Report = struct {
390 .src_loc = try eb.addSourceLocation(.{390 .src_loc = try eb.addSourceLocation(.{
391 .src_path = try eb.addString(file_path),391 .src_path = try eb.addString(file_path),
392 .span_start = token_starts[msg.tok],392 .span_start = token_starts[msg.tok],
393 .span_end = @intCast(u32, token_starts[msg.tok] + ast.tokenSlice(msg.tok).len),393 .span_end = @as(u32, @intCast(token_starts[msg.tok] + ast.tokenSlice(msg.tok).len)),
394 .span_main = token_starts[msg.tok] + msg.off,394 .span_main = token_starts[msg.tok] + msg.off,
395 .line = @intCast(u32, start_loc.line),395 .line = @as(u32, @intCast(start_loc.line)),
396 .column = @intCast(u32, start_loc.column),396 .column = @as(u32, @intCast(start_loc.column)),
397 .source_line = try eb.addString(ast.source[start_loc.line_start..start_loc.line_end]),397 .source_line = try eb.addString(ast.source[start_loc.line_start..start_loc.line_end]),
398 }),398 }),
399 .notes_len = notes_len,399 .notes_len = notes_len,
src/Sema.zig+295-295
...@@ -212,7 +212,7 @@ pub const InstMap = struct {...@@ -212,7 +212,7 @@ pub const InstMap = struct {
212 while (true) {212 while (true) {
213 const extra_capacity = better_capacity / 2 + 16;213 const extra_capacity = better_capacity / 2 + 16;
214 better_capacity += extra_capacity;214 better_capacity += extra_capacity;
215 better_start -|= @intCast(Zir.Inst.Index, extra_capacity / 2);215 better_start -|= @as(Zir.Inst.Index, @intCast(extra_capacity / 2));
216 if (better_start <= start and end < better_capacity + better_start)216 if (better_start <= start and end < better_capacity + better_start)
217 break;217 break;
218 }218 }
...@@ -225,7 +225,7 @@ pub const InstMap = struct {...@@ -225,7 +225,7 @@ pub const InstMap = struct {
225225
226 allocator.free(map.items);226 allocator.free(map.items);
227 map.items = new_items;227 map.items = new_items;
228 map.start = @intCast(Zir.Inst.Index, better_start);228 map.start = @as(Zir.Inst.Index, @intCast(better_start));
229 }229 }
230};230};
231231
...@@ -619,7 +619,7 @@ pub const Block = struct {...@@ -619,7 +619,7 @@ pub const Block = struct {
619 const sema = block.sema;619 const sema = block.sema;
620 const ty_ref = try sema.addType(aggregate_ty);620 const ty_ref = try sema.addType(aggregate_ty);
621 try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements.len);621 try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements.len);
622 const extra_index = @intCast(u32, sema.air_extra.items.len);622 const extra_index = @as(u32, @intCast(sema.air_extra.items.len));
623 sema.appendRefsAssumeCapacity(elements);623 sema.appendRefsAssumeCapacity(elements);
624624
625 return block.addInst(.{625 return block.addInst(.{
...@@ -660,7 +660,7 @@ pub const Block = struct {...@@ -660,7 +660,7 @@ pub const Block = struct {
660 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);660 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
661 try block.instructions.ensureUnusedCapacity(gpa, 1);661 try block.instructions.ensureUnusedCapacity(gpa, 1);
662662
663 const result_index = @intCast(Air.Inst.Index, sema.air_instructions.len);663 const result_index = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
664 sema.air_instructions.appendAssumeCapacity(inst);664 sema.air_instructions.appendAssumeCapacity(inst);
665 block.instructions.appendAssumeCapacity(result_index);665 block.instructions.appendAssumeCapacity(result_index);
666 return result_index;666 return result_index;
...@@ -678,7 +678,7 @@ pub const Block = struct {...@@ -678,7 +678,7 @@ pub const Block = struct {
678678
679 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);679 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
680680
681 const result_index = @intCast(Air.Inst.Index, sema.air_instructions.len);681 const result_index = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
682 sema.air_instructions.appendAssumeCapacity(inst);682 sema.air_instructions.appendAssumeCapacity(inst);
683683
684 try block.instructions.insert(gpa, index, result_index);684 try block.instructions.insert(gpa, index, result_index);
...@@ -1763,7 +1763,7 @@ pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref {...@@ -1763,7 +1763,7 @@ pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref {
1763 const i = @intFromEnum(zir_ref);1763 const i = @intFromEnum(zir_ref);
1764 // First section of indexes correspond to a set number of constant values.1764 // First section of indexes correspond to a set number of constant values.
1765 // We intentionally map the same indexes to the same values between ZIR and AIR.1765 // We intentionally map the same indexes to the same values between ZIR and AIR.
1766 if (i < InternPool.static_len) return @enumFromInt(Air.Inst.Ref, i);1766 if (i < InternPool.static_len) return @as(Air.Inst.Ref, @enumFromInt(i));
1767 // The last section of indexes refers to the map of ZIR => AIR.1767 // The last section of indexes refers to the map of ZIR => AIR.
1768 const inst = sema.inst_map.get(i - InternPool.static_len).?;1768 const inst = sema.inst_map.get(i - InternPool.static_len).?;
1769 if (inst == .generic_poison) return error.GenericPoison;1769 if (inst == .generic_poison) return error.GenericPoison;
...@@ -2041,7 +2041,7 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime(...@@ -2041,7 +2041,7 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime(
2041 // First section of indexes correspond to a set number of constant values.2041 // First section of indexes correspond to a set number of constant values.
2042 const int = @intFromEnum(inst);2042 const int = @intFromEnum(inst);
2043 if (int < InternPool.static_len) {2043 if (int < InternPool.static_len) {
2044 return @enumFromInt(InternPool.Index, int).toValue();2044 return @as(InternPool.Index, @enumFromInt(int)).toValue();
2045 }2045 }
20462046
2047 const i = int - InternPool.static_len;2047 const i = int - InternPool.static_len;
...@@ -2430,7 +2430,7 @@ fn analyzeAsAlign(...@@ -2430,7 +2430,7 @@ fn analyzeAsAlign(
2430 air_ref: Air.Inst.Ref,2430 air_ref: Air.Inst.Ref,
2431) !Alignment {2431) !Alignment {
2432 const alignment_big = try sema.analyzeAsInt(block, src, air_ref, align_ty, "alignment must be comptime-known");2432 const alignment_big = try sema.analyzeAsInt(block, src, air_ref, align_ty, "alignment must be comptime-known");
2433 const alignment = @intCast(u32, alignment_big); // We coerce to u29 in the prev line.2433 const alignment = @as(u32, @intCast(alignment_big)); // We coerce to u29 in the prev line.
2434 try sema.validateAlign(block, src, alignment);2434 try sema.validateAlign(block, src, alignment);
2435 return Alignment.fromNonzeroByteUnits(alignment);2435 return Alignment.fromNonzeroByteUnits(alignment);
2436}2436}
...@@ -2737,7 +2737,7 @@ pub fn analyzeStructDecl(...@@ -2737,7 +2737,7 @@ pub fn analyzeStructDecl(
2737 const struct_obj = mod.structPtr(struct_index);2737 const struct_obj = mod.structPtr(struct_index);
2738 const extended = sema.code.instructions.items(.data)[inst].extended;2738 const extended = sema.code.instructions.items(.data)[inst].extended;
2739 assert(extended.opcode == .struct_decl);2739 assert(extended.opcode == .struct_decl);
2740 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);2740 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
27412741
2742 struct_obj.known_non_opv = small.known_non_opv;2742 struct_obj.known_non_opv = small.known_non_opv;
2743 if (small.known_comptime_only) {2743 if (small.known_comptime_only) {
...@@ -2774,9 +2774,9 @@ fn zirStructDecl(...@@ -2774,9 +2774,9 @@ fn zirStructDecl(
2774) CompileError!Air.Inst.Ref {2774) CompileError!Air.Inst.Ref {
2775 const mod = sema.mod;2775 const mod = sema.mod;
2776 const gpa = sema.gpa;2776 const gpa = sema.gpa;
2777 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);2777 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
2778 const src: LazySrcLoc = if (small.has_src_node) blk: {2778 const src: LazySrcLoc = if (small.has_src_node) blk: {
2779 const node_offset = @bitCast(i32, sema.code.extra[extended.operand]);2779 const node_offset = @as(i32, @bitCast(sema.code.extra[extended.operand]));
2780 break :blk LazySrcLoc.nodeOffset(node_offset);2780 break :blk LazySrcLoc.nodeOffset(node_offset);
2781 } else sema.src;2781 } else sema.src;
27822782
...@@ -2937,18 +2937,18 @@ fn zirEnumDecl(...@@ -2937,18 +2937,18 @@ fn zirEnumDecl(
29372937
2938 const mod = sema.mod;2938 const mod = sema.mod;
2939 const gpa = sema.gpa;2939 const gpa = sema.gpa;
2940 const small = @bitCast(Zir.Inst.EnumDecl.Small, extended.small);2940 const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small));
2941 var extra_index: usize = extended.operand;2941 var extra_index: usize = extended.operand;
29422942
2943 const src: LazySrcLoc = if (small.has_src_node) blk: {2943 const src: LazySrcLoc = if (small.has_src_node) blk: {
2944 const node_offset = @bitCast(i32, sema.code.extra[extra_index]);2944 const node_offset = @as(i32, @bitCast(sema.code.extra[extra_index]));
2945 extra_index += 1;2945 extra_index += 1;
2946 break :blk LazySrcLoc.nodeOffset(node_offset);2946 break :blk LazySrcLoc.nodeOffset(node_offset);
2947 } else sema.src;2947 } else sema.src;
2948 const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x };2948 const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x };
29492949
2950 const tag_type_ref = if (small.has_tag_type) blk: {2950 const tag_type_ref = if (small.has_tag_type) blk: {
2951 const tag_type_ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);2951 const tag_type_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
2952 extra_index += 1;2952 extra_index += 1;
2953 break :blk tag_type_ref;2953 break :blk tag_type_ref;
2954 } else .none;2954 } else .none;
...@@ -3108,7 +3108,7 @@ fn zirEnumDecl(...@@ -3108,7 +3108,7 @@ fn zirEnumDecl(
3108 cur_bit_bag = sema.code.extra[bit_bag_index];3108 cur_bit_bag = sema.code.extra[bit_bag_index];
3109 bit_bag_index += 1;3109 bit_bag_index += 1;
3110 }3110 }
3111 const has_tag_value = @truncate(u1, cur_bit_bag) != 0;3111 const has_tag_value = @as(u1, @truncate(cur_bit_bag)) != 0;
3112 cur_bit_bag >>= 1;3112 cur_bit_bag >>= 1;
31133113
3114 const field_name_zir = sema.code.nullTerminatedString(sema.code.extra[extra_index]);3114 const field_name_zir = sema.code.nullTerminatedString(sema.code.extra[extra_index]);
...@@ -3131,7 +3131,7 @@ fn zirEnumDecl(...@@ -3131,7 +3131,7 @@ fn zirEnumDecl(
3131 }3131 }
31323132
3133 const tag_overflow = if (has_tag_value) overflow: {3133 const tag_overflow = if (has_tag_value) overflow: {
3134 const tag_val_ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);3134 const tag_val_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
3135 extra_index += 1;3135 extra_index += 1;
3136 const tag_inst = try sema.resolveInst(tag_val_ref);3136 const tag_inst = try sema.resolveInst(tag_val_ref);
3137 last_tag_val = sema.resolveConstValue(block, .unneeded, tag_inst, "") catch |err| switch (err) {3137 last_tag_val = sema.resolveConstValue(block, .unneeded, tag_inst, "") catch |err| switch (err) {
...@@ -3213,11 +3213,11 @@ fn zirUnionDecl(...@@ -3213,11 +3213,11 @@ fn zirUnionDecl(
32133213
3214 const mod = sema.mod;3214 const mod = sema.mod;
3215 const gpa = sema.gpa;3215 const gpa = sema.gpa;
3216 const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small);3216 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));
3217 var extra_index: usize = extended.operand;3217 var extra_index: usize = extended.operand;
32183218
3219 const src: LazySrcLoc = if (small.has_src_node) blk: {3219 const src: LazySrcLoc = if (small.has_src_node) blk: {
3220 const node_offset = @bitCast(i32, sema.code.extra[extra_index]);3220 const node_offset = @as(i32, @bitCast(sema.code.extra[extra_index]));
3221 extra_index += 1;3221 extra_index += 1;
3222 break :blk LazySrcLoc.nodeOffset(node_offset);3222 break :blk LazySrcLoc.nodeOffset(node_offset);
3223 } else sema.src;3223 } else sema.src;
...@@ -3298,11 +3298,11 @@ fn zirOpaqueDecl(...@@ -3298,11 +3298,11 @@ fn zirOpaqueDecl(
3298 defer tracy.end();3298 defer tracy.end();
32993299
3300 const mod = sema.mod;3300 const mod = sema.mod;
3301 const small = @bitCast(Zir.Inst.OpaqueDecl.Small, extended.small);3301 const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small));
3302 var extra_index: usize = extended.operand;3302 var extra_index: usize = extended.operand;
33033303
3304 const src: LazySrcLoc = if (small.has_src_node) blk: {3304 const src: LazySrcLoc = if (small.has_src_node) blk: {
3305 const node_offset = @bitCast(i32, sema.code.extra[extra_index]);3305 const node_offset = @as(i32, @bitCast(sema.code.extra[extra_index]));
3306 extra_index += 1;3306 extra_index += 1;
3307 break :blk LazySrcLoc.nodeOffset(node_offset);3307 break :blk LazySrcLoc.nodeOffset(node_offset);
3308 } else sema.src;3308 } else sema.src;
...@@ -3369,7 +3369,7 @@ fn zirErrorSetDecl(...@@ -3369,7 +3369,7 @@ fn zirErrorSetDecl(
3369 var names: Module.Fn.InferredErrorSet.NameMap = .{};3369 var names: Module.Fn.InferredErrorSet.NameMap = .{};
3370 try names.ensureUnusedCapacity(sema.arena, extra.data.fields_len);3370 try names.ensureUnusedCapacity(sema.arena, extra.data.fields_len);
33713371
3372 var extra_index = @intCast(u32, extra.end);3372 var extra_index = @as(u32, @intCast(extra.end));
3373 const extra_index_end = extra_index + (extra.data.fields_len * 2);3373 const extra_index_end = extra_index + (extra.data.fields_len * 2);
3374 while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string3374 while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string
3375 const str_index = sema.code.extra[extra_index];3375 const str_index = sema.code.extra[extra_index];
...@@ -3569,18 +3569,18 @@ fn zirAllocExtended(...@@ -3569,18 +3569,18 @@ fn zirAllocExtended(
3569 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);3569 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);
3570 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node };3570 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node };
3571 const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node };3571 const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node };
3572 const small = @bitCast(Zir.Inst.AllocExtended.Small, extended.small);3572 const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small));
35733573
3574 var extra_index: usize = extra.end;3574 var extra_index: usize = extra.end;
35753575
3576 const var_ty: Type = if (small.has_type) blk: {3576 const var_ty: Type = if (small.has_type) blk: {
3577 const type_ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);3577 const type_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
3578 extra_index += 1;3578 extra_index += 1;
3579 break :blk try sema.resolveType(block, ty_src, type_ref);3579 break :blk try sema.resolveType(block, ty_src, type_ref);
3580 } else undefined;3580 } else undefined;
35813581
3582 const alignment = if (small.has_align) blk: {3582 const alignment = if (small.has_align) blk: {
3583 const align_ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);3583 const align_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
3584 extra_index += 1;3584 extra_index += 1;
3585 const alignment = try sema.resolveAlign(block, align_src, align_ref);3585 const alignment = try sema.resolveAlign(block, align_src, align_ref);
3586 break :blk alignment;3586 break :blk alignment;
...@@ -3598,7 +3598,7 @@ fn zirAllocExtended(...@@ -3598,7 +3598,7 @@ fn zirAllocExtended(
3598 .is_const = small.is_const,3598 .is_const = small.is_const,
3599 } },3599 } },
3600 });3600 });
3601 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));3601 return Air.indexToRef(@as(u32, @intCast(sema.air_instructions.len - 1)));
3602 }3602 }
3603 }3603 }
36043604
...@@ -3730,7 +3730,7 @@ fn zirAllocInferredComptime(...@@ -3730,7 +3730,7 @@ fn zirAllocInferredComptime(
3730 .is_const = is_const,3730 .is_const = is_const,
3731 } },3731 } },
3732 });3732 });
3733 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));3733 return Air.indexToRef(@as(u32, @intCast(sema.air_instructions.len - 1)));
3734}3734}
37353735
3736fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {3736fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -3795,7 +3795,7 @@ fn zirAllocInferred(...@@ -3795,7 +3795,7 @@ fn zirAllocInferred(
3795 .is_const = is_const,3795 .is_const = is_const,
3796 } },3796 } },
3797 });3797 });
3798 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));3798 return Air.indexToRef(@as(u32, @intCast(sema.air_instructions.len - 1)));
3799 }3799 }
38003800
3801 const result_index = try block.addInstAsIndex(.{3801 const result_index = try block.addInstAsIndex(.{
...@@ -4037,7 +4037,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4037,7 +4037,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
4037 .data = .{ .ty_pl = .{4037 .data = .{ .ty_pl = .{
4038 .ty = ty_inst,4038 .ty = ty_inst,
4039 .payload = sema.addExtraAssumeCapacity(Air.Block{4039 .payload = sema.addExtraAssumeCapacity(Air.Block{
4040 .body_len = @intCast(u32, replacement_block.instructions.items.len),4040 .body_len = @as(u32, @intCast(replacement_block.instructions.items.len)),
4041 }),4041 }),
4042 } },4042 } },
4043 });4043 });
...@@ -4121,7 +4121,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4121,7 +4121,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
41214121
4122 // First pass to look for comptime values.4122 // First pass to look for comptime values.
4123 for (args, 0..) |zir_arg, i_usize| {4123 for (args, 0..) |zir_arg, i_usize| {
4124 const i = @intCast(u32, i_usize);4124 const i = @as(u32, @intCast(i_usize));
4125 runtime_arg_lens[i] = .none;4125 runtime_arg_lens[i] = .none;
4126 if (zir_arg == .none) continue;4126 if (zir_arg == .none) continue;
4127 const object = try sema.resolveInst(zir_arg);4127 const object = try sema.resolveInst(zir_arg);
...@@ -4192,7 +4192,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4192,7 +4192,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4192 const msg = try sema.errMsg(block, src, "unbounded for loop", .{});4192 const msg = try sema.errMsg(block, src, "unbounded for loop", .{});
4193 errdefer msg.destroy(gpa);4193 errdefer msg.destroy(gpa);
4194 for (args, 0..) |zir_arg, i_usize| {4194 for (args, 0..) |zir_arg, i_usize| {
4195 const i = @intCast(u32, i_usize);4195 const i = @as(u32, @intCast(i_usize));
4196 if (zir_arg == .none) continue;4196 if (zir_arg == .none) continue;
4197 const object = try sema.resolveInst(zir_arg);4197 const object = try sema.resolveInst(zir_arg);
4198 const object_ty = sema.typeOf(object);4198 const object_ty = sema.typeOf(object);
...@@ -4435,7 +4435,7 @@ fn validateUnionInit(...@@ -4435,7 +4435,7 @@ fn validateUnionInit(
4435 }4435 }
44364436
4437 const tag_ty = union_ty.unionTagTypeHypothetical(mod);4437 const tag_ty = union_ty.unionTagTypeHypothetical(mod);
4438 const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?);4438 const enum_field_index = @as(u32, @intCast(tag_ty.enumFieldIndex(field_name, mod).?));
4439 const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index);4439 const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index);
44404440
4441 if (init_val) |val| {4441 if (init_val) |val| {
...@@ -4547,9 +4547,9 @@ fn validateStructInit(...@@ -4547,9 +4547,9 @@ fn validateStructInit(
45474547
4548 const field_src = init_src; // TODO better source location4548 const field_src = init_src; // TODO better source location
4549 const default_field_ptr = if (struct_ty.isTuple(mod))4549 const default_field_ptr = if (struct_ty.isTuple(mod))
4550 try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(u32, i), true)4550 try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @as(u32, @intCast(i)), true)
4551 else4551 else
4552 try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(u32, i), field_src, struct_ty, true);4552 try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @as(u32, @intCast(i)), field_src, struct_ty, true);
4553 const init = try sema.addConstant(default_val);4553 const init = try sema.addConstant(default_val);
4554 try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store);4554 try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store);
4555 }4555 }
...@@ -4729,9 +4729,9 @@ fn validateStructInit(...@@ -4729,9 +4729,9 @@ fn validateStructInit(
47294729
4730 const field_src = init_src; // TODO better source location4730 const field_src = init_src; // TODO better source location
4731 const default_field_ptr = if (struct_ty.isTuple(mod))4731 const default_field_ptr = if (struct_ty.isTuple(mod))
4732 try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(u32, i), true)4732 try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @as(u32, @intCast(i)), true)
4733 else4733 else
4734 try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(u32, i), field_src, struct_ty, true);4734 try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @as(u32, @intCast(i)), field_src, struct_ty, true);
4735 const init = try sema.addConstant(field_values[i].toValue());4735 const init = try sema.addConstant(field_values[i].toValue());
4736 try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store);4736 try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store);
4737 }4737 }
...@@ -5165,7 +5165,7 @@ fn storeToInferredAllocComptime(...@@ -5165,7 +5165,7 @@ fn storeToInferredAllocComptime(
5165fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {5165fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
5166 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5166 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5167 const src = inst_data.src();5167 const src = inst_data.src();
5168 const quota = @intCast(u32, try sema.resolveInt(block, src, inst_data.operand, Type.u32, "eval branch quota must be comptime-known"));5168 const quota = @as(u32, @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, "eval branch quota must be comptime-known")));
5169 sema.branch_quota = @max(sema.branch_quota, quota);5169 sema.branch_quota = @max(sema.branch_quota, quota);
5170}5170}
51715171
...@@ -5388,7 +5388,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError...@@ -5388,7 +5388,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
5388 // Reserve space for a Loop instruction so that generated Break instructions can5388 // Reserve space for a Loop instruction so that generated Break instructions can
5389 // point to it, even if it doesn't end up getting used because the code ends up being5389 // point to it, even if it doesn't end up getting used because the code ends up being
5390 // comptime evaluated.5390 // comptime evaluated.
5391 const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);5391 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
5392 const loop_inst = block_inst + 1;5392 const loop_inst = block_inst + 1;
5393 try sema.air_instructions.ensureUnusedCapacity(gpa, 2);5393 try sema.air_instructions.ensureUnusedCapacity(gpa, 2);
5394 sema.air_instructions.appendAssumeCapacity(.{5394 sema.air_instructions.appendAssumeCapacity(.{
...@@ -5436,7 +5436,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError...@@ -5436,7 +5436,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
54365436
5437 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + loop_block_len);5437 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + loop_block_len);
5438 sema.air_instructions.items(.data)[loop_inst].ty_pl.payload = sema.addExtraAssumeCapacity(5438 sema.air_instructions.items(.data)[loop_inst].ty_pl.payload = sema.addExtraAssumeCapacity(
5439 Air.Block{ .body_len = @intCast(u32, loop_block_len) },5439 Air.Block{ .body_len = @as(u32, @intCast(loop_block_len)) },
5440 );5440 );
5441 sema.air_extra.appendSliceAssumeCapacity(loop_block.instructions.items);5441 sema.air_extra.appendSliceAssumeCapacity(loop_block.instructions.items);
5442 }5442 }
...@@ -5586,7 +5586,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt...@@ -5586,7 +5586,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
5586 // Reserve space for a Block instruction so that generated Break instructions can5586 // Reserve space for a Block instruction so that generated Break instructions can
5587 // point to it, even if it doesn't end up getting used because the code ends up being5587 // point to it, even if it doesn't end up getting used because the code ends up being
5588 // comptime evaluated or is an unlabeled block.5588 // comptime evaluated or is an unlabeled block.
5589 const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);5589 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
5590 try sema.air_instructions.append(gpa, .{5590 try sema.air_instructions.append(gpa, .{
5591 .tag = .block,5591 .tag = .block,
5592 .data = undefined,5592 .data = undefined,
...@@ -5733,7 +5733,7 @@ fn analyzeBlockBody(...@@ -5733,7 +5733,7 @@ fn analyzeBlockBody(
5733 sema.air_instructions.items(.data)[merges.block_inst] = .{ .ty_pl = .{5733 sema.air_instructions.items(.data)[merges.block_inst] = .{ .ty_pl = .{
5734 .ty = ty_inst,5734 .ty = ty_inst,
5735 .payload = sema.addExtraAssumeCapacity(Air.Block{5735 .payload = sema.addExtraAssumeCapacity(Air.Block{
5736 .body_len = @intCast(u32, child_block.instructions.items.len),5736 .body_len = @as(u32, @intCast(child_block.instructions.items.len)),
5737 }),5737 }),
5738 } };5738 } };
5739 sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items);5739 sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items);
...@@ -5761,11 +5761,11 @@ fn analyzeBlockBody(...@@ -5761,11 +5761,11 @@ fn analyzeBlockBody(
57615761
5762 // Convert the br instruction to a block instruction that has the coercion5762 // Convert the br instruction to a block instruction that has the coercion
5763 // and then a new br inside that returns the coerced instruction.5763 // and then a new br inside that returns the coerced instruction.
5764 const sub_block_len = @intCast(u32, coerce_block.instructions.items.len + 1);5764 const sub_block_len = @as(u32, @intCast(coerce_block.instructions.items.len + 1));
5765 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +5765 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +
5766 sub_block_len);5766 sub_block_len);
5767 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);5767 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
5768 const sub_br_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);5768 const sub_br_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
57695769
5770 sema.air_instructions.items(.tag)[br] = .block;5770 sema.air_instructions.items(.tag)[br] = .block;
5771 sema.air_instructions.items(.data)[br] = .{ .ty_pl = .{5771 sema.air_instructions.items(.data)[br] = .{ .ty_pl = .{
...@@ -6114,7 +6114,7 @@ fn addDbgVar(...@@ -6114,7 +6114,7 @@ fn addDbgVar(
6114 try sema.queueFullTypeResolution(operand_ty);6114 try sema.queueFullTypeResolution(operand_ty);
61156115
6116 // Add the name to the AIR.6116 // Add the name to the AIR.
6117 const name_extra_index = @intCast(u32, sema.air_extra.items.len);6117 const name_extra_index = @as(u32, @intCast(sema.air_extra.items.len));
6118 const elements_used = name.len / 4 + 1;6118 const elements_used = name.len / 4 + 1;
6119 try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements_used);6119 try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements_used);
6120 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());6120 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
...@@ -6314,7 +6314,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref...@@ -6314,7 +6314,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
6314 .tag = .save_err_return_trace_index,6314 .tag = .save_err_return_trace_index,
6315 .data = .{ .ty_pl = .{6315 .data = .{ .ty_pl = .{
6316 .ty = try sema.addType(stack_trace_ty),6316 .ty = try sema.addType(stack_trace_ty),
6317 .payload = @intCast(u32, field_index),6317 .payload = @as(u32, @intCast(field_index)),
6318 } },6318 } },
6319 });6319 });
6320}6320}
...@@ -6386,12 +6386,12 @@ fn popErrorReturnTrace(...@@ -6386,12 +6386,12 @@ fn popErrorReturnTrace(
6386 then_block.instructions.items.len + else_block.instructions.items.len +6386 then_block.instructions.items.len + else_block.instructions.items.len +
6387 @typeInfo(Air.Block).Struct.fields.len + 1); // +1 for the sole .cond_br instruction in the .block6387 @typeInfo(Air.Block).Struct.fields.len + 1); // +1 for the sole .cond_br instruction in the .block
63886388
6389 const cond_br_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);6389 const cond_br_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
6390 try sema.air_instructions.append(gpa, .{ .tag = .cond_br, .data = .{ .pl_op = .{6390 try sema.air_instructions.append(gpa, .{ .tag = .cond_br, .data = .{ .pl_op = .{
6391 .operand = is_non_error_inst,6391 .operand = is_non_error_inst,
6392 .payload = sema.addExtraAssumeCapacity(Air.CondBr{6392 .payload = sema.addExtraAssumeCapacity(Air.CondBr{
6393 .then_body_len = @intCast(u32, then_block.instructions.items.len),6393 .then_body_len = @as(u32, @intCast(then_block.instructions.items.len)),
6394 .else_body_len = @intCast(u32, else_block.instructions.items.len),6394 .else_body_len = @as(u32, @intCast(else_block.instructions.items.len)),
6395 }),6395 }),
6396 } } });6396 } } });
6397 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);6397 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);
...@@ -6422,7 +6422,7 @@ fn zirCall(...@@ -6422,7 +6422,7 @@ fn zirCall(
6422 const extra = sema.code.extraData(ExtraType, inst_data.payload_index);6422 const extra = sema.code.extraData(ExtraType, inst_data.payload_index);
6423 const args_len = extra.data.flags.args_len;6423 const args_len = extra.data.flags.args_len;
64246424
6425 const modifier = @enumFromInt(std.builtin.CallModifier, extra.data.flags.packed_modifier);6425 const modifier = @as(std.builtin.CallModifier, @enumFromInt(extra.data.flags.packed_modifier));
6426 const ensure_result_used = extra.data.flags.ensure_result_used;6426 const ensure_result_used = extra.data.flags.ensure_result_used;
6427 const pop_error_return_trace = extra.data.flags.pop_error_return_trace;6427 const pop_error_return_trace = extra.data.flags.pop_error_return_trace;
64286428
...@@ -6460,7 +6460,7 @@ fn zirCall(...@@ -6460,7 +6460,7 @@ fn zirCall(
6460 const args_body = sema.code.extra[extra.end..];6460 const args_body = sema.code.extra[extra.end..];
64616461
6462 var input_is_error = false;6462 var input_is_error = false;
6463 const block_index = @intCast(Air.Inst.Index, block.instructions.items.len);6463 const block_index = @as(Air.Inst.Index, @intCast(block.instructions.items.len));
64646464
6465 const fn_params_len = mod.typeToFunc(func_ty).?.param_types.len;6465 const fn_params_len = mod.typeToFunc(func_ty).?.param_types.len;
6466 const parent_comptime = block.is_comptime;6466 const parent_comptime = block.is_comptime;
...@@ -6477,7 +6477,7 @@ fn zirCall(...@@ -6477,7 +6477,7 @@ fn zirCall(
64776477
6478 // Generate args to comptime params in comptime block.6478 // Generate args to comptime params in comptime block.
6479 defer block.is_comptime = parent_comptime;6479 defer block.is_comptime = parent_comptime;
6480 if (arg_index < @min(fn_params_len, 32) and func_ty_info.paramIsComptime(@intCast(u5, arg_index))) {6480 if (arg_index < @min(fn_params_len, 32) and func_ty_info.paramIsComptime(@as(u5, @intCast(arg_index)))) {
6481 block.is_comptime = true;6481 block.is_comptime = true;
6482 // TODO set comptime_reason6482 // TODO set comptime_reason
6483 }6483 }
...@@ -6533,7 +6533,7 @@ fn zirCall(...@@ -6533,7 +6533,7 @@ fn zirCall(
6533 .tag = .save_err_return_trace_index,6533 .tag = .save_err_return_trace_index,
6534 .data = .{ .ty_pl = .{6534 .data = .{ .ty_pl = .{
6535 .ty = try sema.addType(stack_trace_ty),6535 .ty = try sema.addType(stack_trace_ty),
6536 .payload = @intCast(u32, field_index),6536 .payload = @as(u32, @intCast(field_index)),
6537 } },6537 } },
6538 });6538 });
65396539
...@@ -6809,7 +6809,7 @@ fn analyzeCall(...@@ -6809,7 +6809,7 @@ fn analyzeCall(
6809 // set to in the `Block`.6809 // set to in the `Block`.
6810 // This block instruction will be used to capture the return value from the6810 // This block instruction will be used to capture the return value from the
6811 // inlined function.6811 // inlined function.
6812 const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);6812 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
6813 try sema.air_instructions.append(gpa, .{6813 try sema.air_instructions.append(gpa, .{
6814 .tag = .block,6814 .tag = .block,
6815 .data = undefined,6815 .data = undefined,
...@@ -7077,7 +7077,7 @@ fn analyzeCall(...@@ -7077,7 +7077,7 @@ fn analyzeCall(
7077 if (i < fn_params_len) {7077 if (i < fn_params_len) {
7078 const opts: CoerceOpts = .{ .param_src = .{7078 const opts: CoerceOpts = .{ .param_src = .{
7079 .func_inst = func,7079 .func_inst = func,
7080 .param_i = @intCast(u32, i),7080 .param_i = @as(u32, @intCast(i)),
7081 } };7081 } };
7082 const param_ty = mod.typeToFunc(func_ty).?.param_types[i].toType();7082 const param_ty = mod.typeToFunc(func_ty).?.param_types[i].toType();
7083 args[i] = sema.analyzeCallArg(7083 args[i] = sema.analyzeCallArg(
...@@ -7136,7 +7136,7 @@ fn analyzeCall(...@@ -7136,7 +7136,7 @@ fn analyzeCall(
7136 .data = .{ .pl_op = .{7136 .data = .{ .pl_op = .{
7137 .operand = func,7137 .operand = func,
7138 .payload = sema.addExtraAssumeCapacity(Air.Call{7138 .payload = sema.addExtraAssumeCapacity(Air.Call{
7139 .args_len = @intCast(u32, args.len),7139 .args_len = @as(u32, @intCast(args.len)),
7140 }),7140 }),
7141 } },7141 } },
7142 });7142 });
...@@ -7245,7 +7245,7 @@ fn analyzeInlineCallArg(...@@ -7245,7 +7245,7 @@ fn analyzeInlineCallArg(
7245 }7245 }
7246 const casted_arg = sema.coerceExtra(arg_block, param_ty.toType(), uncasted_arg, arg_src, .{ .param_src = .{7246 const casted_arg = sema.coerceExtra(arg_block, param_ty.toType(), uncasted_arg, arg_src, .{ .param_src = .{
7247 .func_inst = func_inst,7247 .func_inst = func_inst,
7248 .param_i = @intCast(u32, arg_i.*),7248 .param_i = @as(u32, @intCast(arg_i.*)),
7249 } }) catch |err| switch (err) {7249 } }) catch |err| switch (err) {
7250 error.NotCoercible => unreachable,7250 error.NotCoercible => unreachable,
7251 else => |e| return e,7251 else => |e| return e,
...@@ -7419,14 +7419,14 @@ fn instantiateGenericCall(...@@ -7419,14 +7419,14 @@ fn instantiateGenericCall(
7419 var is_anytype = false;7419 var is_anytype = false;
7420 switch (zir_tags[inst]) {7420 switch (zir_tags[inst]) {
7421 .param => {7421 .param => {
7422 is_comptime = generic_func_ty_info.paramIsComptime(@intCast(u5, arg_i));7422 is_comptime = generic_func_ty_info.paramIsComptime(@as(u5, @intCast(arg_i)));
7423 },7423 },
7424 .param_comptime => {7424 .param_comptime => {
7425 is_comptime = true;7425 is_comptime = true;
7426 },7426 },
7427 .param_anytype => {7427 .param_anytype => {
7428 is_anytype = true;7428 is_anytype = true;
7429 is_comptime = generic_func_ty_info.paramIsComptime(@intCast(u5, arg_i));7429 is_comptime = generic_func_ty_info.paramIsComptime(@as(u5, @intCast(arg_i)));
7430 },7430 },
7431 .param_anytype_comptime => {7431 .param_anytype_comptime => {
7432 is_anytype = true;7432 is_anytype = true;
...@@ -7588,7 +7588,7 @@ fn instantiateGenericCall(...@@ -7588,7 +7588,7 @@ fn instantiateGenericCall(
7588 // Make a runtime call to the new function, making sure to omit the comptime args.7588 // Make a runtime call to the new function, making sure to omit the comptime args.
7589 const comptime_args = callee.comptime_args.?;7589 const comptime_args = callee.comptime_args.?;
7590 const func_ty = mod.declPtr(callee.owner_decl).ty;7590 const func_ty = mod.declPtr(callee.owner_decl).ty;
7591 const runtime_args_len = @intCast(u32, mod.typeToFunc(func_ty).?.param_types.len);7591 const runtime_args_len = @as(u32, @intCast(mod.typeToFunc(func_ty).?.param_types.len));
7592 const runtime_args = try sema.arena.alloc(Air.Inst.Ref, runtime_args_len);7592 const runtime_args = try sema.arena.alloc(Air.Inst.Ref, runtime_args_len);
7593 {7593 {
7594 var runtime_i: u32 = 0;7594 var runtime_i: u32 = 0;
...@@ -7738,14 +7738,14 @@ fn resolveGenericInstantiationType(...@@ -7738,14 +7738,14 @@ fn resolveGenericInstantiationType(
7738 var is_anytype = false;7738 var is_anytype = false;
7739 switch (zir_tags[inst]) {7739 switch (zir_tags[inst]) {
7740 .param => {7740 .param => {
7741 is_comptime = generic_func_ty_info.paramIsComptime(@intCast(u5, arg_i));7741 is_comptime = generic_func_ty_info.paramIsComptime(@as(u5, @intCast(arg_i)));
7742 },7742 },
7743 .param_comptime => {7743 .param_comptime => {
7744 is_comptime = true;7744 is_comptime = true;
7745 },7745 },
7746 .param_anytype => {7746 .param_anytype => {
7747 is_anytype = true;7747 is_anytype = true;
7748 is_comptime = generic_func_ty_info.paramIsComptime(@intCast(u5, arg_i));7748 is_comptime = generic_func_ty_info.paramIsComptime(@as(u5, @intCast(arg_i)));
7749 },7749 },
7750 .param_anytype_comptime => {7750 .param_anytype_comptime => {
7751 is_anytype = true;7751 is_anytype = true;
...@@ -7779,7 +7779,7 @@ fn resolveGenericInstantiationType(...@@ -7779,7 +7779,7 @@ fn resolveGenericInstantiationType(
7779 .tag = .arg,7779 .tag = .arg,
7780 .data = .{ .arg = .{7780 .data = .{ .arg = .{
7781 .ty = try child_sema.addType(arg_ty),7781 .ty = try child_sema.addType(arg_ty),
7782 .src_index = @intCast(u32, arg_i),7782 .src_index = @as(u32, @intCast(arg_i)),
7783 } },7783 } },
7784 });7784 });
7785 child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg);7785 child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg);
...@@ -7799,7 +7799,7 @@ fn resolveGenericInstantiationType(...@@ -7799,7 +7799,7 @@ fn resolveGenericInstantiationType(
7799 const new_func = new_func_val.getFunctionIndex(mod).unwrap().?;7799 const new_func = new_func_val.getFunctionIndex(mod).unwrap().?;
7800 assert(new_func == new_module_func);7800 assert(new_func == new_module_func);
78017801
7802 const monomorphed_args_index = @intCast(u32, mod.monomorphed_func_keys.items.len);7802 const monomorphed_args_index = @as(u32, @intCast(mod.monomorphed_func_keys.items.len));
7803 const monomorphed_args = try mod.monomorphed_func_keys.addManyAsSlice(gpa, monomorphed_args_len);7803 const monomorphed_args = try mod.monomorphed_func_keys.addManyAsSlice(gpa, monomorphed_args_len);
7804 var monomorphed_arg_i: u32 = 0;7804 var monomorphed_arg_i: u32 = 0;
7805 try mod.monomorphed_funcs.ensureUnusedCapacityContext(gpa, monomorphed_args_len + 1, .{ .mod = mod });7805 try mod.monomorphed_funcs.ensureUnusedCapacityContext(gpa, monomorphed_args_len + 1, .{ .mod = mod });
...@@ -7811,14 +7811,14 @@ fn resolveGenericInstantiationType(...@@ -7811,14 +7811,14 @@ fn resolveGenericInstantiationType(
7811 var is_anytype = false;7811 var is_anytype = false;
7812 switch (zir_tags[inst]) {7812 switch (zir_tags[inst]) {
7813 .param => {7813 .param => {
7814 is_comptime = generic_func_ty_info.paramIsComptime(@intCast(u5, arg_i));7814 is_comptime = generic_func_ty_info.paramIsComptime(@as(u5, @intCast(arg_i)));
7815 },7815 },
7816 .param_comptime => {7816 .param_comptime => {
7817 is_comptime = true;7817 is_comptime = true;
7818 },7818 },
7819 .param_anytype => {7819 .param_anytype => {
7820 is_anytype = true;7820 is_anytype = true;
7821 is_comptime = generic_func_ty_info.paramIsComptime(@intCast(u5, arg_i));7821 is_comptime = generic_func_ty_info.paramIsComptime(@as(u5, @intCast(arg_i)));
7822 },7822 },
7823 .param_anytype_comptime => {7823 .param_anytype_comptime => {
7824 is_anytype = true;7824 is_anytype = true;
...@@ -7984,7 +7984,7 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -7984,7 +7984,7 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
7984 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };7984 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
7985 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };7985 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
7986 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;7986 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
7987 const len = @intCast(u32, try sema.resolveInt(block, len_src, extra.lhs, Type.u32, "vector length must be comptime-known"));7987 const len = @as(u32, @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, "vector length must be comptime-known")));
7988 const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs);7988 const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs);
7989 try sema.checkVectorElemType(block, elem_type_src, elem_type);7989 try sema.checkVectorElemType(block, elem_type_src, elem_type);
7990 const vector_type = try mod.vectorType(.{7990 const vector_type = try mod.vectorType(.{
...@@ -8140,7 +8140,7 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD...@@ -8140,7 +8140,7 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
8140 switch (names.len) {8140 switch (names.len) {
8141 0 => return sema.addConstant(try mod.intValue(Type.err_int, 0)),8141 0 => return sema.addConstant(try mod.intValue(Type.err_int, 0)),
8142 1 => {8142 1 => {
8143 const int = @intCast(Module.ErrorInt, mod.global_error_set.getIndex(names[0]).?);8143 const int = @as(Module.ErrorInt, @intCast(mod.global_error_set.getIndex(names[0]).?));
8144 return sema.addIntUnsigned(Type.err_int, int);8144 return sema.addIntUnsigned(Type.err_int, int);
8145 },8145 },
8146 else => {},8146 else => {},
...@@ -8727,7 +8727,7 @@ fn zirFunc(...@@ -8727,7 +8727,7 @@ fn zirFunc(
8727 const ret_ty: Type = switch (extra.data.ret_body_len) {8727 const ret_ty: Type = switch (extra.data.ret_body_len) {
8728 0 => Type.void,8728 0 => Type.void,
8729 1 => blk: {8729 1 => blk: {
8730 const ret_ty_ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);8730 const ret_ty_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
8731 extra_index += 1;8731 extra_index += 1;
8732 if (sema.resolveType(block, ret_ty_src, ret_ty_ref)) |ret_ty| {8732 if (sema.resolveType(block, ret_ty_src, ret_ty_ref)) |ret_ty| {
8733 break :blk ret_ty;8733 break :blk ret_ty;
...@@ -8964,7 +8964,7 @@ fn funcCommon(...@@ -8964,7 +8964,7 @@ fn funcCommon(
8964 for (param_types, block.params.items, 0..) |*dest_param_ty, param, i| {8964 for (param_types, block.params.items, 0..) |*dest_param_ty, param, i| {
8965 const is_noalias = blk: {8965 const is_noalias = blk: {
8966 const index = std.math.cast(u5, i) orelse break :blk false;8966 const index = std.math.cast(u5, i) orelse break :blk false;
8967 break :blk @truncate(u1, noalias_bits >> index) != 0;8967 break :blk @as(u1, @truncate(noalias_bits >> index)) != 0;
8968 };8968 };
8969 dest_param_ty.* = param.ty.toIntern();8969 dest_param_ty.* = param.ty.toIntern();
8970 sema.analyzeParameter(8970 sema.analyzeParameter(
...@@ -9199,8 +9199,8 @@ fn funcCommon(...@@ -9199,8 +9199,8 @@ fn funcCommon(
9199 .hash = hash,9199 .hash = hash,
9200 .lbrace_line = src_locs.lbrace_line,9200 .lbrace_line = src_locs.lbrace_line,
9201 .rbrace_line = src_locs.rbrace_line,9201 .rbrace_line = src_locs.rbrace_line,
9202 .lbrace_column = @truncate(u16, src_locs.columns),9202 .lbrace_column = @as(u16, @truncate(src_locs.columns)),
9203 .rbrace_column = @truncate(u16, src_locs.columns >> 16),9203 .rbrace_column = @as(u16, @truncate(src_locs.columns >> 16)),
9204 .branch_quota = default_branch_quota,9204 .branch_quota = default_branch_quota,
9205 .is_noinline = is_noinline,9205 .is_noinline = is_noinline,
9206 };9206 };
...@@ -9225,7 +9225,7 @@ fn analyzeParameter(...@@ -9225,7 +9225,7 @@ fn analyzeParameter(
9225 const mod = sema.mod;9225 const mod = sema.mod;
9226 const requires_comptime = try sema.typeRequiresComptime(param.ty);9226 const requires_comptime = try sema.typeRequiresComptime(param.ty);
9227 if (param.is_comptime or requires_comptime) {9227 if (param.is_comptime or requires_comptime) {
9228 comptime_bits.* |= @as(u32, 1) << @intCast(u5, i); // TODO: handle cast error9228 comptime_bits.* |= @as(u32, 1) << @as(u5, @intCast(i)); // TODO: handle cast error
9229 }9229 }
9230 const this_generic = param.ty.isGenericPoison();9230 const this_generic = param.ty.isGenericPoison();
9231 is_generic.* = is_generic.* or this_generic;9231 is_generic.* = is_generic.* or this_generic;
...@@ -9411,7 +9411,7 @@ fn zirParam(...@@ -9411,7 +9411,7 @@ fn zirParam(
9411 sema.inst_map.putAssumeCapacityNoClobber(inst, result);9411 sema.inst_map.putAssumeCapacityNoClobber(inst, result);
9412 } else {9412 } else {
9413 // Otherwise we need a dummy runtime instruction.9413 // Otherwise we need a dummy runtime instruction.
9414 const result_index = @intCast(Air.Inst.Index, sema.air_instructions.len);9414 const result_index = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
9415 try sema.air_instructions.append(sema.gpa, .{9415 try sema.air_instructions.append(sema.gpa, .{
9416 .tag = .alloc,9416 .tag = .alloc,
9417 .data = .{ .ty = param_ty },9417 .data = .{ .ty = param_ty },
...@@ -10287,7 +10287,7 @@ const SwitchProngAnalysis = struct {...@@ -10287,7 +10287,7 @@ const SwitchProngAnalysis = struct {
10287 if (inline_case_capture != .none) {10287 if (inline_case_capture != .none) {
10288 const item_val = sema.resolveConstValue(block, .unneeded, inline_case_capture, "") catch unreachable;10288 const item_val = sema.resolveConstValue(block, .unneeded, inline_case_capture, "") catch unreachable;
10289 if (operand_ty.zigTypeTag(mod) == .Union) {10289 if (operand_ty.zigTypeTag(mod) == .Union) {
10290 const field_index = @intCast(u32, operand_ty.unionTagFieldIndex(item_val, mod).?);10290 const field_index = @as(u32, @intCast(operand_ty.unionTagFieldIndex(item_val, mod).?));
10291 const union_obj = mod.typeToUnion(operand_ty).?;10291 const union_obj = mod.typeToUnion(operand_ty).?;
10292 const field_ty = union_obj.fields.values()[field_index].ty;10292 const field_ty = union_obj.fields.values()[field_index].ty;
10293 if (capture_byref) {10293 if (capture_byref) {
...@@ -10346,13 +10346,13 @@ const SwitchProngAnalysis = struct {...@@ -10346,13 +10346,13 @@ const SwitchProngAnalysis = struct {
10346 const union_obj = mod.typeToUnion(operand_ty).?;10346 const union_obj = mod.typeToUnion(operand_ty).?;
10347 const first_item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], "") catch unreachable;10347 const first_item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], "") catch unreachable;
1034810348
10349 const first_field_index = @intCast(u32, operand_ty.unionTagFieldIndex(first_item_val, mod).?);10349 const first_field_index = @as(u32, @intCast(operand_ty.unionTagFieldIndex(first_item_val, mod).?));
10350 const first_field = union_obj.fields.values()[first_field_index];10350 const first_field = union_obj.fields.values()[first_field_index];
1035110351
10352 const field_tys = try sema.arena.alloc(Type, case_vals.len);10352 const field_tys = try sema.arena.alloc(Type, case_vals.len);
10353 for (case_vals, field_tys) |item, *field_ty| {10353 for (case_vals, field_tys) |item, *field_ty| {
10354 const item_val = sema.resolveConstValue(block, .unneeded, item, "") catch unreachable;10354 const item_val = sema.resolveConstValue(block, .unneeded, item, "") catch unreachable;
10355 const field_idx = @intCast(u32, operand_ty.unionTagFieldIndex(item_val, sema.mod).?);10355 const field_idx = @as(u32, @intCast(operand_ty.unionTagFieldIndex(item_val, sema.mod).?));
10356 field_ty.* = union_obj.fields.values()[field_idx].ty;10356 field_ty.* = union_obj.fields.values()[field_idx].ty;
10357 }10357 }
1035810358
...@@ -10378,7 +10378,7 @@ const SwitchProngAnalysis = struct {...@@ -10378,7 +10378,7 @@ const SwitchProngAnalysis = struct {
10378 const multi_idx = raw_capture_src.multi_capture;10378 const multi_idx = raw_capture_src.multi_capture;
10379 const src_decl_ptr = sema.mod.declPtr(block.src_decl);10379 const src_decl_ptr = sema.mod.declPtr(block.src_decl);
10380 for (case_srcs, 0..) |*case_src, i| {10380 for (case_srcs, 0..) |*case_src, i| {
10381 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(u32, i) } };10381 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @as(u32, @intCast(i)) } };
10382 case_src.* = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);10382 case_src.* = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);
10383 }10383 }
10384 const capture_src = raw_capture_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);10384 const capture_src = raw_capture_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);
...@@ -10426,7 +10426,7 @@ const SwitchProngAnalysis = struct {...@@ -10426,7 +10426,7 @@ const SwitchProngAnalysis = struct {
10426 const multi_idx = raw_capture_src.multi_capture;10426 const multi_idx = raw_capture_src.multi_capture;
10427 const src_decl_ptr = sema.mod.declPtr(block.src_decl);10427 const src_decl_ptr = sema.mod.declPtr(block.src_decl);
10428 const capture_src = raw_capture_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);10428 const capture_src = raw_capture_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);
10429 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(u32, i) } };10429 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @as(u32, @intCast(i)) } };
10430 const case_src = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);10430 const case_src = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);
10431 const msg = msg: {10431 const msg = msg: {
10432 const msg = try sema.errMsg(block, capture_src, "capture group with incompatible types", .{});10432 const msg = try sema.errMsg(block, capture_src, "capture group with incompatible types", .{});
...@@ -10529,12 +10529,12 @@ const SwitchProngAnalysis = struct {...@@ -10529,12 +10529,12 @@ const SwitchProngAnalysis = struct {
10529 var coerce_block = block.makeSubBlock();10529 var coerce_block = block.makeSubBlock();
10530 defer coerce_block.instructions.deinit(sema.gpa);10530 defer coerce_block.instructions.deinit(sema.gpa);
1053110531
10532 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, @intCast(u32, idx), field_tys[idx]);10532 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, @as(u32, @intCast(idx)), field_tys[idx]);
10533 const coerced = sema.coerce(&coerce_block, capture_ty, uncoerced, .unneeded) catch |err| switch (err) {10533 const coerced = sema.coerce(&coerce_block, capture_ty, uncoerced, .unneeded) catch |err| switch (err) {
10534 error.NeededSourceLocation => {10534 error.NeededSourceLocation => {
10535 const multi_idx = raw_capture_src.multi_capture;10535 const multi_idx = raw_capture_src.multi_capture;
10536 const src_decl_ptr = sema.mod.declPtr(block.src_decl);10536 const src_decl_ptr = sema.mod.declPtr(block.src_decl);
10537 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(u32, idx) } };10537 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @as(u32, @intCast(idx)) } };
10538 const case_src = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);10538 const case_src = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);
10539 _ = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);10539 _ = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);
10540 unreachable;10540 unreachable;
...@@ -10545,7 +10545,7 @@ const SwitchProngAnalysis = struct {...@@ -10545,7 +10545,7 @@ const SwitchProngAnalysis = struct {
1054510545
10546 try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len);10546 try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len);
10547 cases_extra.appendAssumeCapacity(1); // items_len10547 cases_extra.appendAssumeCapacity(1); // items_len
10548 cases_extra.appendAssumeCapacity(@intCast(u32, coerce_block.instructions.items.len)); // body_len10548 cases_extra.appendAssumeCapacity(@as(u32, @intCast(coerce_block.instructions.items.len))); // body_len
10549 cases_extra.appendAssumeCapacity(@intFromEnum(case_vals[idx])); // item10549 cases_extra.appendAssumeCapacity(@intFromEnum(case_vals[idx])); // item
10550 cases_extra.appendSliceAssumeCapacity(coerce_block.instructions.items); // body10550 cases_extra.appendSliceAssumeCapacity(coerce_block.instructions.items); // body
10551 }10551 }
...@@ -10556,7 +10556,7 @@ const SwitchProngAnalysis = struct {...@@ -10556,7 +10556,7 @@ const SwitchProngAnalysis = struct {
10556 defer coerce_block.instructions.deinit(sema.gpa);10556 defer coerce_block.instructions.deinit(sema.gpa);
1055710557
10558 const first_imc = in_mem_coercible.findFirstSet().?;10558 const first_imc = in_mem_coercible.findFirstSet().?;
10559 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, @intCast(u32, first_imc), field_tys[first_imc]);10559 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, @as(u32, @intCast(first_imc)), field_tys[first_imc]);
10560 const coerced = try coerce_block.addBitCast(capture_ty, uncoerced);10560 const coerced = try coerce_block.addBitCast(capture_ty, uncoerced);
10561 _ = try coerce_block.addBr(capture_block_inst, coerced);10561 _ = try coerce_block.addBr(capture_block_inst, coerced);
1056210562
...@@ -10569,14 +10569,14 @@ const SwitchProngAnalysis = struct {...@@ -10569,14 +10569,14 @@ const SwitchProngAnalysis = struct {
10569 @typeInfo(Air.Block).Struct.fields.len +10569 @typeInfo(Air.Block).Struct.fields.len +
10570 1);10570 1);
1057110571
10572 const switch_br_inst = @intCast(u32, sema.air_instructions.len);10572 const switch_br_inst = @as(u32, @intCast(sema.air_instructions.len));
10573 try sema.air_instructions.append(sema.gpa, .{10573 try sema.air_instructions.append(sema.gpa, .{
10574 .tag = .switch_br,10574 .tag = .switch_br,
10575 .data = .{ .pl_op = .{10575 .data = .{ .pl_op = .{
10576 .operand = spa.cond,10576 .operand = spa.cond,
10577 .payload = sema.addExtraAssumeCapacity(Air.SwitchBr{10577 .payload = sema.addExtraAssumeCapacity(Air.SwitchBr{
10578 .cases_len = @intCast(u32, prong_count),10578 .cases_len = @as(u32, @intCast(prong_count)),
10579 .else_body_len = @intCast(u32, else_body_len),10579 .else_body_len = @as(u32, @intCast(else_body_len)),
10580 }),10580 }),
10581 } },10581 } },
10582 });10582 });
...@@ -10763,7 +10763,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -10763,7 +10763,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
10763 .has_tag_capture = false,10763 .has_tag_capture = false,
10764 },10764 },
10765 .under, .@"else" => blk: {10765 .under, .@"else" => blk: {
10766 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, sema.code.extra[header_extra_index]);10766 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[header_extra_index]));
10767 const extra_body_start = header_extra_index + 1;10767 const extra_body_start = header_extra_index + 1;
10768 break :blk .{10768 break :blk .{
10769 .body = sema.code.extra[extra_body_start..][0..info.body_len],10769 .body = sema.code.extra[extra_body_start..][0..info.body_len],
...@@ -10833,9 +10833,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -10833,9 +10833,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
10833 {10833 {
10834 var scalar_i: u32 = 0;10834 var scalar_i: u32 = 0;
10835 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {10835 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
10836 const item_ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);10836 const item_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
10837 extra_index += 1;10837 extra_index += 1;
10838 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, sema.code.extra[extra_index]);10838 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
10839 extra_index += 1 + info.body_len;10839 extra_index += 1 + info.body_len;
1084010840
10841 case_vals.appendAssumeCapacity(try sema.validateSwitchItemEnum(10841 case_vals.appendAssumeCapacity(try sema.validateSwitchItemEnum(
...@@ -10856,7 +10856,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -10856,7 +10856,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
10856 extra_index += 1;10856 extra_index += 1;
10857 const ranges_len = sema.code.extra[extra_index];10857 const ranges_len = sema.code.extra[extra_index];
10858 extra_index += 1;10858 extra_index += 1;
10859 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, sema.code.extra[extra_index]);10859 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
10860 extra_index += 1;10860 extra_index += 1;
10861 const items = sema.code.refSlice(extra_index, items_len);10861 const items = sema.code.refSlice(extra_index, items_len);
10862 extra_index += items_len + info.body_len;10862 extra_index += items_len + info.body_len;
...@@ -10870,7 +10870,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -10870,7 +10870,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
10870 item_ref,10870 item_ref,
10871 operand_ty,10871 operand_ty,
10872 src_node_offset,10872 src_node_offset,
10873 .{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } },10873 .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } },
10874 ));10874 ));
10875 }10875 }
1087610876
...@@ -10932,9 +10932,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -10932,9 +10932,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
10932 {10932 {
10933 var scalar_i: u32 = 0;10933 var scalar_i: u32 = 0;
10934 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {10934 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
10935 const item_ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);10935 const item_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
10936 extra_index += 1;10936 extra_index += 1;
10937 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, sema.code.extra[extra_index]);10937 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
10938 extra_index += 1 + info.body_len;10938 extra_index += 1 + info.body_len;
1093910939
10940 case_vals.appendAssumeCapacity(try sema.validateSwitchItemError(10940 case_vals.appendAssumeCapacity(try sema.validateSwitchItemError(
...@@ -10954,7 +10954,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -10954,7 +10954,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
10954 extra_index += 1;10954 extra_index += 1;
10955 const ranges_len = sema.code.extra[extra_index];10955 const ranges_len = sema.code.extra[extra_index];
10956 extra_index += 1;10956 extra_index += 1;
10957 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, sema.code.extra[extra_index]);10957 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
10958 extra_index += 1;10958 extra_index += 1;
10959 const items = sema.code.refSlice(extra_index, items_len);10959 const items = sema.code.refSlice(extra_index, items_len);
10960 extra_index += items_len + info.body_len;10960 extra_index += items_len + info.body_len;
...@@ -10967,7 +10967,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -10967,7 +10967,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
10967 item_ref,10967 item_ref,
10968 operand_ty,10968 operand_ty,
10969 src_node_offset,10969 src_node_offset,
10970 .{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } },10970 .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } },
10971 ));10971 ));
10972 }10972 }
1097310973
...@@ -11073,9 +11073,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11073,9 +11073,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11073 {11073 {
11074 var scalar_i: u32 = 0;11074 var scalar_i: u32 = 0;
11075 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {11075 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
11076 const item_ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);11076 const item_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
11077 extra_index += 1;11077 extra_index += 1;
11078 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, sema.code.extra[extra_index]);11078 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11079 extra_index += 1 + info.body_len;11079 extra_index += 1 + info.body_len;
1108011080
11081 case_vals.appendAssumeCapacity(try sema.validateSwitchItemInt(11081 case_vals.appendAssumeCapacity(try sema.validateSwitchItemInt(
...@@ -11095,7 +11095,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11095,7 +11095,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11095 extra_index += 1;11095 extra_index += 1;
11096 const ranges_len = sema.code.extra[extra_index];11096 const ranges_len = sema.code.extra[extra_index];
11097 extra_index += 1;11097 extra_index += 1;
11098 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, sema.code.extra[extra_index]);11098 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11099 extra_index += 1;11099 extra_index += 1;
11100 const items = sema.code.refSlice(extra_index, items_len);11100 const items = sema.code.refSlice(extra_index, items_len);
11101 extra_index += items_len;11101 extra_index += items_len;
...@@ -11108,16 +11108,16 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11108,16 +11108,16 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11108 item_ref,11108 item_ref,
11109 operand_ty,11109 operand_ty,
11110 src_node_offset,11110 src_node_offset,
11111 .{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } },11111 .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } },
11112 ));11112 ));
11113 }11113 }
1111411114
11115 try case_vals.ensureUnusedCapacity(gpa, 2 * ranges_len);11115 try case_vals.ensureUnusedCapacity(gpa, 2 * ranges_len);
11116 var range_i: u32 = 0;11116 var range_i: u32 = 0;
11117 while (range_i < ranges_len) : (range_i += 1) {11117 while (range_i < ranges_len) : (range_i += 1) {
11118 const item_first = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);11118 const item_first = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
11119 extra_index += 1;11119 extra_index += 1;
11120 const item_last = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);11120 const item_last = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
11121 extra_index += 1;11121 extra_index += 1;
1112211122
11123 const vals = try sema.validateSwitchRange(11123 const vals = try sema.validateSwitchRange(
...@@ -11168,9 +11168,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11168,9 +11168,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11168 {11168 {
11169 var scalar_i: u32 = 0;11169 var scalar_i: u32 = 0;
11170 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {11170 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
11171 const item_ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);11171 const item_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
11172 extra_index += 1;11172 extra_index += 1;
11173 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, sema.code.extra[extra_index]);11173 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11174 extra_index += 1 + info.body_len;11174 extra_index += 1 + info.body_len;
1117511175
11176 case_vals.appendAssumeCapacity(try sema.validateSwitchItemBool(11176 case_vals.appendAssumeCapacity(try sema.validateSwitchItemBool(
...@@ -11190,7 +11190,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11190,7 +11190,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11190 extra_index += 1;11190 extra_index += 1;
11191 const ranges_len = sema.code.extra[extra_index];11191 const ranges_len = sema.code.extra[extra_index];
11192 extra_index += 1;11192 extra_index += 1;
11193 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, sema.code.extra[extra_index]);11193 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11194 extra_index += 1;11194 extra_index += 1;
11195 const items = sema.code.refSlice(extra_index, items_len);11195 const items = sema.code.refSlice(extra_index, items_len);
11196 extra_index += items_len + info.body_len;11196 extra_index += items_len + info.body_len;
...@@ -11203,7 +11203,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11203,7 +11203,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11203 &false_count,11203 &false_count,
11204 item_ref,11204 item_ref,
11205 src_node_offset,11205 src_node_offset,
11206 .{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } },11206 .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } },
11207 ));11207 ));
11208 }11208 }
1120911209
...@@ -11250,9 +11250,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11250,9 +11250,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11250 {11250 {
11251 var scalar_i: u32 = 0;11251 var scalar_i: u32 = 0;
11252 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {11252 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
11253 const item_ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);11253 const item_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
11254 extra_index += 1;11254 extra_index += 1;
11255 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, sema.code.extra[extra_index]);11255 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11256 extra_index += 1;11256 extra_index += 1;
11257 extra_index += info.body_len;11257 extra_index += info.body_len;
1125811258
...@@ -11273,7 +11273,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11273,7 +11273,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11273 extra_index += 1;11273 extra_index += 1;
11274 const ranges_len = sema.code.extra[extra_index];11274 const ranges_len = sema.code.extra[extra_index];
11275 extra_index += 1;11275 extra_index += 1;
11276 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, sema.code.extra[extra_index]);11276 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11277 extra_index += 1;11277 extra_index += 1;
11278 const items = sema.code.refSlice(extra_index, items_len);11278 const items = sema.code.refSlice(extra_index, items_len);
11279 extra_index += items_len + info.body_len;11279 extra_index += items_len + info.body_len;
...@@ -11286,7 +11286,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11286,7 +11286,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11286 item_ref,11286 item_ref,
11287 operand_ty,11287 operand_ty,
11288 src_node_offset,11288 src_node_offset,
11289 .{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } },11289 .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } },
11290 ));11290 ));
11291 }11291 }
1129211292
...@@ -11324,7 +11324,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11324,7 +11324,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11324 .tag_capture_inst = tag_capture_inst,11324 .tag_capture_inst = tag_capture_inst,
11325 };11325 };
1132611326
11327 const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);11327 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
11328 try sema.air_instructions.append(gpa, .{11328 try sema.air_instructions.append(gpa, .{
11329 .tag = .block,11329 .tag = .block,
11330 .data = undefined,11330 .data = undefined,
...@@ -11368,7 +11368,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11368,7 +11368,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11368 var scalar_i: usize = 0;11368 var scalar_i: usize = 0;
11369 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {11369 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
11370 extra_index += 1;11370 extra_index += 1;
11371 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, sema.code.extra[extra_index]);11371 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11372 extra_index += 1;11372 extra_index += 1;
11373 const body = sema.code.extra[extra_index..][0..info.body_len];11373 const body = sema.code.extra[extra_index..][0..info.body_len];
11374 extra_index += info.body_len;11374 extra_index += info.body_len;
...@@ -11382,7 +11382,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11382,7 +11382,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11382 .normal,11382 .normal,
11383 body,11383 body,
11384 info.capture,11384 info.capture,
11385 .{ .scalar_capture = @intCast(u32, scalar_i) },11385 .{ .scalar_capture = @as(u32, @intCast(scalar_i)) },
11386 &.{item},11386 &.{item},
11387 if (info.is_inline) operand else .none,11387 if (info.is_inline) operand else .none,
11388 info.has_tag_capture,11388 info.has_tag_capture,
...@@ -11399,7 +11399,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11399,7 +11399,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11399 extra_index += 1;11399 extra_index += 1;
11400 const ranges_len = sema.code.extra[extra_index];11400 const ranges_len = sema.code.extra[extra_index];
11401 extra_index += 1;11401 extra_index += 1;
11402 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, sema.code.extra[extra_index]);11402 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11403 extra_index += 1 + items_len;11403 extra_index += 1 + items_len;
11404 const body = sema.code.extra[extra_index + 2 * ranges_len ..][0..info.body_len];11404 const body = sema.code.extra[extra_index + 2 * ranges_len ..][0..info.body_len];
1140511405
...@@ -11416,7 +11416,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11416,7 +11416,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11416 .normal,11416 .normal,
11417 body,11417 body,
11418 info.capture,11418 info.capture,
11419 .{ .multi_capture = @intCast(u32, multi_i) },11419 .{ .multi_capture = @as(u32, @intCast(multi_i)) },
11420 items,11420 items,
11421 if (info.is_inline) operand else .none,11421 if (info.is_inline) operand else .none,
11422 info.has_tag_capture,11422 info.has_tag_capture,
...@@ -11443,7 +11443,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11443,7 +11443,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11443 .normal,11443 .normal,
11444 body,11444 body,
11445 info.capture,11445 info.capture,
11446 .{ .multi_capture = @intCast(u32, multi_i) },11446 .{ .multi_capture = @as(u32, @intCast(multi_i)) },
11447 undefined, // case_vals may be undefined for ranges11447 undefined, // case_vals may be undefined for ranges
11448 if (info.is_inline) operand else .none,11448 if (info.is_inline) operand else .none,
11449 info.has_tag_capture,11449 info.has_tag_capture,
...@@ -11528,7 +11528,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11528,7 +11528,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11528 var scalar_i: usize = 0;11528 var scalar_i: usize = 0;
11529 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {11529 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
11530 extra_index += 1;11530 extra_index += 1;
11531 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, sema.code.extra[extra_index]);11531 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11532 extra_index += 1;11532 extra_index += 1;
11533 const body = sema.code.extra[extra_index..][0..info.body_len];11533 const body = sema.code.extra[extra_index..][0..info.body_len];
11534 extra_index += info.body_len;11534 extra_index += info.body_len;
...@@ -11556,7 +11556,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11556,7 +11556,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11556 .normal,11556 .normal,
11557 body,11557 body,
11558 info.capture,11558 info.capture,
11559 .{ .scalar_capture = @intCast(u32, scalar_i) },11559 .{ .scalar_capture = @as(u32, @intCast(scalar_i)) },
11560 &.{item},11560 &.{item},
11561 if (info.is_inline) item else .none,11561 if (info.is_inline) item else .none,
11562 info.has_tag_capture,11562 info.has_tag_capture,
...@@ -11569,7 +11569,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11569,7 +11569,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1156911569
11570 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);11570 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
11571 cases_extra.appendAssumeCapacity(1); // items_len11571 cases_extra.appendAssumeCapacity(1); // items_len
11572 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));11572 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
11573 cases_extra.appendAssumeCapacity(@intFromEnum(item));11573 cases_extra.appendAssumeCapacity(@intFromEnum(item));
11574 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);11574 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
11575 }11575 }
...@@ -11589,7 +11589,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11589,7 +11589,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11589 extra_index += 1;11589 extra_index += 1;
11590 const ranges_len = sema.code.extra[extra_index];11590 const ranges_len = sema.code.extra[extra_index];
11591 extra_index += 1;11591 extra_index += 1;
11592 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, sema.code.extra[extra_index]);11592 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11593 extra_index += 1 + items_len;11593 extra_index += 1 + items_len;
1159411594
11595 const items = case_vals.items[case_val_idx..][0..items_len];11595 const items = case_vals.items[case_val_idx..][0..items_len];
...@@ -11654,7 +11654,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11654,7 +11654,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1165411654
11655 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);11655 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
11656 cases_extra.appendAssumeCapacity(1); // items_len11656 cases_extra.appendAssumeCapacity(1); // items_len
11657 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));11657 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
11658 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));11658 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
11659 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);11659 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1166011660
...@@ -11676,7 +11676,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11676,7 +11676,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1167611676
11677 if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) {11677 if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) {
11678 error.NeededSourceLocation => {11678 error.NeededSourceLocation => {
11679 const case_src = Module.SwitchProngSrc{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } };11679 const case_src = Module.SwitchProngSrc{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } };
11680 const decl = mod.declPtr(case_block.src_decl);11680 const decl = mod.declPtr(case_block.src_decl);
11681 try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none));11681 try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none));
11682 unreachable;11682 unreachable;
...@@ -11702,7 +11702,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11702,7 +11702,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1170211702
11703 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);11703 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
11704 cases_extra.appendAssumeCapacity(1); // items_len11704 cases_extra.appendAssumeCapacity(1); // items_len
11705 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));11705 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
11706 cases_extra.appendAssumeCapacity(@intFromEnum(item));11706 cases_extra.appendAssumeCapacity(@intFromEnum(item));
11707 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);11707 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
11708 }11708 }
...@@ -11750,8 +11750,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11750,8 +11750,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11750 try cases_extra.ensureUnusedCapacity(gpa, 2 + items.len +11750 try cases_extra.ensureUnusedCapacity(gpa, 2 + items.len +
11751 case_block.instructions.items.len);11751 case_block.instructions.items.len);
1175211752
11753 cases_extra.appendAssumeCapacity(@intCast(u32, items.len));11753 cases_extra.appendAssumeCapacity(@as(u32, @intCast(items.len)));
11754 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));11754 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
1175511755
11756 for (items) |item| {11756 for (items) |item| {
11757 cases_extra.appendAssumeCapacity(@intFromEnum(item));11757 cases_extra.appendAssumeCapacity(@intFromEnum(item));
...@@ -11846,8 +11846,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11846,8 +11846,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1184611846
11847 sema.air_instructions.items(.data)[prev_cond_br].pl_op.payload =11847 sema.air_instructions.items(.data)[prev_cond_br].pl_op.payload =
11848 sema.addExtraAssumeCapacity(Air.CondBr{11848 sema.addExtraAssumeCapacity(Air.CondBr{
11849 .then_body_len = @intCast(u32, prev_then_body.len),11849 .then_body_len = @as(u32, @intCast(prev_then_body.len)),
11850 .else_body_len = @intCast(u32, cond_body.len),11850 .else_body_len = @as(u32, @intCast(cond_body.len)),
11851 });11851 });
11852 sema.air_extra.appendSliceAssumeCapacity(prev_then_body);11852 sema.air_extra.appendSliceAssumeCapacity(prev_then_body);
11853 sema.air_extra.appendSliceAssumeCapacity(cond_body);11853 sema.air_extra.appendSliceAssumeCapacity(cond_body);
...@@ -11872,7 +11872,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11872,7 +11872,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11872 if (f != null) continue;11872 if (f != null) continue;
11873 cases_len += 1;11873 cases_len += 1;
1187411874
11875 const item_val = try mod.enumValueFieldIndex(operand_ty, @intCast(u32, i));11875 const item_val = try mod.enumValueFieldIndex(operand_ty, @as(u32, @intCast(i)));
11876 const item_ref = try sema.addConstant(item_val);11876 const item_ref = try sema.addConstant(item_val);
1187711877
11878 case_block.instructions.shrinkRetainingCapacity(0);11878 case_block.instructions.shrinkRetainingCapacity(0);
...@@ -11903,7 +11903,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11903,7 +11903,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1190311903
11904 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);11904 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
11905 cases_extra.appendAssumeCapacity(1); // items_len11905 cases_extra.appendAssumeCapacity(1); // items_len
11906 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));11906 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
11907 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));11907 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
11908 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);11908 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
11909 }11909 }
...@@ -11944,7 +11944,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11944,7 +11944,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1194411944
11945 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);11945 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
11946 cases_extra.appendAssumeCapacity(1); // items_len11946 cases_extra.appendAssumeCapacity(1); // items_len
11947 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));11947 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
11948 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));11948 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
11949 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);11949 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
11950 }11950 }
...@@ -11975,7 +11975,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11975,7 +11975,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1197511975
11976 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);11976 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
11977 cases_extra.appendAssumeCapacity(1); // items_len11977 cases_extra.appendAssumeCapacity(1); // items_len
11978 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));11978 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
11979 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));11979 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
11980 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);11980 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
11981 }11981 }
...@@ -12003,7 +12003,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12003,7 +12003,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1200312003
12004 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);12004 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
12005 cases_extra.appendAssumeCapacity(1); // items_len12005 cases_extra.appendAssumeCapacity(1); // items_len
12006 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));12006 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
12007 cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_true));12007 cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_true));
12008 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);12008 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
12009 }12009 }
...@@ -12029,7 +12029,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12029,7 +12029,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1202912029
12030 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);12030 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
12031 cases_extra.appendAssumeCapacity(1); // items_len12031 cases_extra.appendAssumeCapacity(1); // items_len
12032 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));12032 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
12033 cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_false));12033 cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_false));
12034 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);12034 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
12035 }12035 }
...@@ -12098,8 +12098,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12098,8 +12098,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1209812098
12099 sema.air_instructions.items(.data)[prev_cond_br].pl_op.payload =12099 sema.air_instructions.items(.data)[prev_cond_br].pl_op.payload =
12100 sema.addExtraAssumeCapacity(Air.CondBr{12100 sema.addExtraAssumeCapacity(Air.CondBr{
12101 .then_body_len = @intCast(u32, prev_then_body.len),12101 .then_body_len = @as(u32, @intCast(prev_then_body.len)),
12102 .else_body_len = @intCast(u32, case_block.instructions.items.len),12102 .else_body_len = @as(u32, @intCast(case_block.instructions.items.len)),
12103 });12103 });
12104 sema.air_extra.appendSliceAssumeCapacity(prev_then_body);12104 sema.air_extra.appendSliceAssumeCapacity(prev_then_body);
12105 sema.air_extra.appendSliceAssumeCapacity(case_block.instructions.items);12105 sema.air_extra.appendSliceAssumeCapacity(case_block.instructions.items);
...@@ -12113,8 +12113,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12113,8 +12113,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12113 _ = try child_block.addInst(.{ .tag = .switch_br, .data = .{ .pl_op = .{12113 _ = try child_block.addInst(.{ .tag = .switch_br, .data = .{ .pl_op = .{
12114 .operand = operand,12114 .operand = operand,
12115 .payload = sema.addExtraAssumeCapacity(Air.SwitchBr{12115 .payload = sema.addExtraAssumeCapacity(Air.SwitchBr{
12116 .cases_len = @intCast(u32, cases_len),12116 .cases_len = @as(u32, @intCast(cases_len)),
12117 .else_body_len = @intCast(u32, final_else_body.len),12117 .else_body_len = @as(u32, @intCast(final_else_body.len)),
12118 }),12118 }),
12119 } } });12119 } } });
12120 sema.air_extra.appendSliceAssumeCapacity(cases_extra.items);12120 sema.air_extra.appendSliceAssumeCapacity(cases_extra.items);
...@@ -13527,7 +13527,7 @@ fn analyzeTupleMul(...@@ -13527,7 +13527,7 @@ fn analyzeTupleMul(
13527 var i: u32 = 0;13527 var i: u32 = 0;
13528 while (i < tuple_len) : (i += 1) {13528 while (i < tuple_len) : (i += 1) {
13529 const operand_src = lhs_src; // TODO better source location13529 const operand_src = lhs_src; // TODO better source location
13530 element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @intCast(u32, i), operand_ty);13530 element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @as(u32, @intCast(i)), operand_ty);
13531 }13531 }
13532 i = 1;13532 i = 1;
13533 while (i < factor) : (i += 1) {13533 while (i < factor) : (i += 1) {
...@@ -15593,10 +15593,10 @@ fn analyzePtrArithmetic(...@@ -15593,10 +15593,10 @@ fn analyzePtrArithmetic(
15593 // The resulting pointer is aligned to the lcd between the offset (an15593 // The resulting pointer is aligned to the lcd between the offset (an
15594 // arbitrary number) and the alignment factor (always a power of two,15594 // arbitrary number) and the alignment factor (always a power of two,
15595 // non zero).15595 // non zero).
15596 const new_align = @enumFromInt(Alignment, @min(15596 const new_align = @as(Alignment, @enumFromInt(@min(
15597 @ctz(addend),15597 @ctz(addend),
15598 @intFromEnum(ptr_info.flags.alignment),15598 @intFromEnum(ptr_info.flags.alignment),
15599 ));15599 )));
15600 assert(new_align != .none);15600 assert(new_align != .none);
1560115601
15602 break :t try mod.ptrType(.{15602 break :t try mod.ptrType(.{
...@@ -15675,14 +15675,14 @@ fn zirAsm(...@@ -15675,14 +15675,14 @@ fn zirAsm(
15675 const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand);15675 const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand);
15676 const src = LazySrcLoc.nodeOffset(extra.data.src_node);15676 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
15677 const ret_ty_src: LazySrcLoc = .{ .node_offset_asm_ret_ty = extra.data.src_node };15677 const ret_ty_src: LazySrcLoc = .{ .node_offset_asm_ret_ty = extra.data.src_node };
15678 const outputs_len = @truncate(u5, extended.small);15678 const outputs_len = @as(u5, @truncate(extended.small));
15679 const inputs_len = @truncate(u5, extended.small >> 5);15679 const inputs_len = @as(u5, @truncate(extended.small >> 5));
15680 const clobbers_len = @truncate(u5, extended.small >> 10);15680 const clobbers_len = @as(u5, @truncate(extended.small >> 10));
15681 const is_volatile = @truncate(u1, extended.small >> 15) != 0;15681 const is_volatile = @as(u1, @truncate(extended.small >> 15)) != 0;
15682 const is_global_assembly = sema.func_index == .none;15682 const is_global_assembly = sema.func_index == .none;
1568315683
15684 const asm_source: []const u8 = if (tmpl_is_expr) blk: {15684 const asm_source: []const u8 = if (tmpl_is_expr) blk: {
15685 const tmpl = @enumFromInt(Zir.Inst.Ref, extra.data.asm_source);15685 const tmpl = @as(Zir.Inst.Ref, @enumFromInt(extra.data.asm_source));
15686 const s: []const u8 = try sema.resolveConstString(block, src, tmpl, "assembly code must be comptime-known");15686 const s: []const u8 = try sema.resolveConstString(block, src, tmpl, "assembly code must be comptime-known");
15687 break :blk s;15687 break :blk s;
15688 } else sema.code.nullTerminatedString(extra.data.asm_source);15688 } else sema.code.nullTerminatedString(extra.data.asm_source);
...@@ -15721,7 +15721,7 @@ fn zirAsm(...@@ -15721,7 +15721,7 @@ fn zirAsm(
15721 const output = sema.code.extraData(Zir.Inst.Asm.Output, extra_i);15721 const output = sema.code.extraData(Zir.Inst.Asm.Output, extra_i);
15722 extra_i = output.end;15722 extra_i = output.end;
1572315723
15724 const is_type = @truncate(u1, output_type_bits) != 0;15724 const is_type = @as(u1, @truncate(output_type_bits)) != 0;
15725 output_type_bits >>= 1;15725 output_type_bits >>= 1;
1572615726
15727 if (is_type) {15727 if (is_type) {
...@@ -15783,10 +15783,10 @@ fn zirAsm(...@@ -15783,10 +15783,10 @@ fn zirAsm(
15783 .data = .{ .ty_pl = .{15783 .data = .{ .ty_pl = .{
15784 .ty = expr_ty,15784 .ty = expr_ty,
15785 .payload = sema.addExtraAssumeCapacity(Air.Asm{15785 .payload = sema.addExtraAssumeCapacity(Air.Asm{
15786 .source_len = @intCast(u32, asm_source.len),15786 .source_len = @as(u32, @intCast(asm_source.len)),
15787 .outputs_len = outputs_len,15787 .outputs_len = outputs_len,
15788 .inputs_len = @intCast(u32, args.len),15788 .inputs_len = @as(u32, @intCast(args.len)),
15789 .flags = (@as(u32, @intFromBool(is_volatile)) << 31) | @intCast(u32, clobbers.len),15789 .flags = (@as(u32, @intFromBool(is_volatile)) << 31) | @as(u32, @intCast(clobbers.len)),
15790 }),15790 }),
15791 } },15791 } },
15792 });15792 });
...@@ -16192,7 +16192,7 @@ fn zirThis(...@@ -16192,7 +16192,7 @@ fn zirThis(
16192) CompileError!Air.Inst.Ref {16192) CompileError!Air.Inst.Ref {
16193 const mod = sema.mod;16193 const mod = sema.mod;
16194 const this_decl_index = mod.namespaceDeclIndex(block.namespace);16194 const this_decl_index = mod.namespaceDeclIndex(block.namespace);
16195 const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand));16195 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
16196 return sema.analyzeDeclVal(block, src, this_decl_index);16196 return sema.analyzeDeclVal(block, src, this_decl_index);
16197}16197}
1619816198
...@@ -16329,7 +16329,7 @@ fn zirFrameAddress(...@@ -16329,7 +16329,7 @@ fn zirFrameAddress(
16329 block: *Block,16329 block: *Block,
16330 extended: Zir.Inst.Extended.InstData,16330 extended: Zir.Inst.Extended.InstData,
16331) CompileError!Air.Inst.Ref {16331) CompileError!Air.Inst.Ref {
16332 const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand));16332 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
16333 try sema.requireRuntimeBlock(block, src, null);16333 try sema.requireRuntimeBlock(block, src, null);
16334 return try block.addNoOp(.frame_addr);16334 return try block.addNoOp(.frame_addr);
16335}16335}
...@@ -16482,7 +16482,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16482,7 +16482,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1648216482
16483 const is_noalias = blk: {16483 const is_noalias = blk: {
16484 const index = std.math.cast(u5, i) orelse break :blk false;16484 const index = std.math.cast(u5, i) orelse break :blk false;
16485 break :blk @truncate(u1, info.noalias_bits >> index) != 0;16485 break :blk @as(u1, @truncate(info.noalias_bits >> index)) != 0;
16486 };16486 };
1648716487
16488 const param_fields = .{16488 const param_fields = .{
...@@ -16925,7 +16925,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16925,7 +16925,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16925 else16925 else
16926 try mod.intern(.{ .int = .{16926 try mod.intern(.{ .int = .{
16927 .ty = .comptime_int_type,16927 .ty = .comptime_int_type,
16928 .storage = .{ .u64 = @intCast(u64, i) },16928 .storage = .{ .u64 = @as(u64, @intCast(i)) },
16929 } });16929 } });
16930 // TODO: write something like getCoercedInts to avoid needing to dupe16930 // TODO: write something like getCoercedInts to avoid needing to dupe
16931 const name = try sema.arena.dupe(u8, ip.stringToSlice(enum_type.names[i]));16931 const name = try sema.arena.dupe(u8, ip.stringToSlice(enum_type.names[i]));
...@@ -17739,7 +17739,7 @@ fn zirBoolBr(...@@ -17739,7 +17739,7 @@ fn zirBoolBr(
17739 return sema.resolveBody(parent_block, body, inst);17739 return sema.resolveBody(parent_block, body, inst);
17740 }17740 }
1774117741
17742 const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);17742 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
17743 try sema.air_instructions.append(gpa, .{17743 try sema.air_instructions.append(gpa, .{
17744 .tag = .block,17744 .tag = .block,
17745 .data = .{ .ty_pl = .{17745 .data = .{ .ty_pl = .{
...@@ -17801,8 +17801,8 @@ fn finishCondBr(...@@ -17801,8 +17801,8 @@ fn finishCondBr(
17801 @typeInfo(Air.Block).Struct.fields.len + child_block.instructions.items.len + 1);17801 @typeInfo(Air.Block).Struct.fields.len + child_block.instructions.items.len + 1);
1780217802
17803 const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{17803 const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{
17804 .then_body_len = @intCast(u32, then_block.instructions.items.len),17804 .then_body_len = @as(u32, @intCast(then_block.instructions.items.len)),
17805 .else_body_len = @intCast(u32, else_block.instructions.items.len),17805 .else_body_len = @as(u32, @intCast(else_block.instructions.items.len)),
17806 });17806 });
17807 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);17807 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);
17808 sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items);17808 sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items);
...@@ -17813,7 +17813,7 @@ fn finishCondBr(...@@ -17813,7 +17813,7 @@ fn finishCondBr(
17813 } } });17813 } } });
1781417814
17815 sema.air_instructions.items(.data)[block_inst].ty_pl.payload = sema.addExtraAssumeCapacity(17815 sema.air_instructions.items(.data)[block_inst].ty_pl.payload = sema.addExtraAssumeCapacity(
17816 Air.Block{ .body_len = @intCast(u32, child_block.instructions.items.len) },17816 Air.Block{ .body_len = @as(u32, @intCast(child_block.instructions.items.len)) },
17817 );17817 );
17818 sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items);17818 sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items);
1781917819
...@@ -17976,8 +17976,8 @@ fn zirCondbr(...@@ -17976,8 +17976,8 @@ fn zirCondbr(
17976 .data = .{ .pl_op = .{17976 .data = .{ .pl_op = .{
17977 .operand = cond,17977 .operand = cond,
17978 .payload = sema.addExtraAssumeCapacity(Air.CondBr{17978 .payload = sema.addExtraAssumeCapacity(Air.CondBr{
17979 .then_body_len = @intCast(u32, true_instructions.len),17979 .then_body_len = @as(u32, @intCast(true_instructions.len)),
17980 .else_body_len = @intCast(u32, sub_block.instructions.items.len),17980 .else_body_len = @as(u32, @intCast(sub_block.instructions.items.len)),
17981 }),17981 }),
17982 } },17982 } },
17983 });17983 });
...@@ -18024,7 +18024,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -18024,7 +18024,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
18024 .data = .{ .pl_op = .{18024 .data = .{ .pl_op = .{
18025 .operand = err_union,18025 .operand = err_union,
18026 .payload = sema.addExtraAssumeCapacity(Air.Try{18026 .payload = sema.addExtraAssumeCapacity(Air.Try{
18027 .body_len = @intCast(u32, sub_block.instructions.items.len),18027 .body_len = @as(u32, @intCast(sub_block.instructions.items.len)),
18028 }),18028 }),
18029 } },18029 } },
18030 });18030 });
...@@ -18084,7 +18084,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -18084,7 +18084,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
18084 .ty = res_ty_ref,18084 .ty = res_ty_ref,
18085 .payload = sema.addExtraAssumeCapacity(Air.TryPtr{18085 .payload = sema.addExtraAssumeCapacity(Air.TryPtr{
18086 .ptr = operand,18086 .ptr = operand,
18087 .body_len = @intCast(u32, sub_block.instructions.items.len),18087 .body_len = @as(u32, @intCast(sub_block.instructions.items.len)),
18088 }),18088 }),
18089 } },18089 } },
18090 });18090 });
...@@ -18100,7 +18100,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi...@@ -18100,7 +18100,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi
18100 const labeled_block = if (!gop.found_existing) blk: {18100 const labeled_block = if (!gop.found_existing) blk: {
18101 try sema.post_hoc_blocks.ensureUnusedCapacity(sema.gpa, 1);18101 try sema.post_hoc_blocks.ensureUnusedCapacity(sema.gpa, 1);
1810218102
18103 const new_block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);18103 const new_block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
18104 gop.value_ptr.* = Air.indexToRef(new_block_inst);18104 gop.value_ptr.* = Air.indexToRef(new_block_inst);
18105 try sema.air_instructions.append(sema.gpa, .{18105 try sema.air_instructions.append(sema.gpa, .{
18106 .tag = .block,18106 .tag = .block,
...@@ -18296,8 +18296,8 @@ fn retWithErrTracing(...@@ -18296,8 +18296,8 @@ fn retWithErrTracing(
18296 @typeInfo(Air.Block).Struct.fields.len + 1);18296 @typeInfo(Air.Block).Struct.fields.len + 1);
1829718297
18298 const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{18298 const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{
18299 .then_body_len = @intCast(u32, then_block.instructions.items.len),18299 .then_body_len = @as(u32, @intCast(then_block.instructions.items.len)),
18300 .else_body_len = @intCast(u32, else_block.instructions.items.len),18300 .else_body_len = @as(u32, @intCast(else_block.instructions.items.len)),
18301 });18301 });
18302 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);18302 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);
18303 sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items);18303 sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items);
...@@ -18486,7 +18486,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -18486,7 +18486,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
18486 var extra_i = extra.end;18486 var extra_i = extra.end;
1848718487
18488 const sentinel = if (inst_data.flags.has_sentinel) blk: {18488 const sentinel = if (inst_data.flags.has_sentinel) blk: {
18489 const ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_i]);18489 const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i]));
18490 extra_i += 1;18490 extra_i += 1;
18491 const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src);18491 const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src);
18492 const val = try sema.resolveConstValue(block, sentinel_src, coerced, "pointer sentinel value must be comptime-known");18492 const val = try sema.resolveConstValue(block, sentinel_src, coerced, "pointer sentinel value must be comptime-known");
...@@ -18494,7 +18494,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -18494,7 +18494,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
18494 } else .none;18494 } else .none;
1849518495
18496 const abi_align: Alignment = if (inst_data.flags.has_align) blk: {18496 const abi_align: Alignment = if (inst_data.flags.has_align) blk: {
18497 const ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_i]);18497 const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i]));
18498 extra_i += 1;18498 extra_i += 1;
18499 const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src);18499 const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src);
18500 const val = try sema.resolveConstValue(block, align_src, coerced, "pointer alignment must be comptime-known");18500 const val = try sema.resolveConstValue(block, align_src, coerced, "pointer alignment must be comptime-known");
...@@ -18507,29 +18507,29 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -18507,29 +18507,29 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
18507 },18507 },
18508 else => {},18508 else => {},
18509 }18509 }
18510 const abi_align = @intCast(u32, (try val.getUnsignedIntAdvanced(mod, sema)).?);18510 const abi_align = @as(u32, @intCast((try val.getUnsignedIntAdvanced(mod, sema)).?));
18511 try sema.validateAlign(block, align_src, abi_align);18511 try sema.validateAlign(block, align_src, abi_align);
18512 break :blk Alignment.fromByteUnits(abi_align);18512 break :blk Alignment.fromByteUnits(abi_align);
18513 } else .none;18513 } else .none;
1851418514
18515 const address_space: std.builtin.AddressSpace = if (inst_data.flags.has_addrspace) blk: {18515 const address_space: std.builtin.AddressSpace = if (inst_data.flags.has_addrspace) blk: {
18516 const ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_i]);18516 const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i]));
18517 extra_i += 1;18517 extra_i += 1;
18518 break :blk try sema.analyzeAddressSpace(block, addrspace_src, ref, .pointer);18518 break :blk try sema.analyzeAddressSpace(block, addrspace_src, ref, .pointer);
18519 } else if (elem_ty.zigTypeTag(mod) == .Fn and target.cpu.arch == .avr) .flash else .generic;18519 } else if (elem_ty.zigTypeTag(mod) == .Fn and target.cpu.arch == .avr) .flash else .generic;
1852018520
18521 const bit_offset = if (inst_data.flags.has_bit_range) blk: {18521 const bit_offset = if (inst_data.flags.has_bit_range) blk: {
18522 const ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_i]);18522 const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i]));
18523 extra_i += 1;18523 extra_i += 1;
18524 const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16, "pointer bit-offset must be comptime-known");18524 const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16, "pointer bit-offset must be comptime-known");
18525 break :blk @intCast(u16, bit_offset);18525 break :blk @as(u16, @intCast(bit_offset));
18526 } else 0;18526 } else 0;
1852718527
18528 const host_size: u16 = if (inst_data.flags.has_bit_range) blk: {18528 const host_size: u16 = if (inst_data.flags.has_bit_range) blk: {
18529 const ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_i]);18529 const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i]));
18530 extra_i += 1;18530 extra_i += 1;
18531 const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16, "pointer host size must be comptime-known");18531 const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16, "pointer host size must be comptime-known");
18532 break :blk @intCast(u16, host_size);18532 break :blk @as(u16, @intCast(host_size));
18533 } else 0;18533 } else 0;
1853418534
18535 if (host_size != 0 and bit_offset >= host_size * 8) {18535 if (host_size != 0 and bit_offset >= host_size * 8) {
...@@ -18669,7 +18669,7 @@ fn unionInit(...@@ -18669,7 +18669,7 @@ fn unionInit(
1866918669
18670 if (try sema.resolveMaybeUndefVal(init)) |init_val| {18670 if (try sema.resolveMaybeUndefVal(init)) |init_val| {
18671 const tag_ty = union_ty.unionTagTypeHypothetical(mod);18671 const tag_ty = union_ty.unionTagTypeHypothetical(mod);
18672 const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?);18672 const enum_field_index = @as(u32, @intCast(tag_ty.enumFieldIndex(field_name, mod).?));
18673 const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index);18673 const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index);
18674 return sema.addConstant((try mod.intern(.{ .un = .{18674 return sema.addConstant((try mod.intern(.{ .un = .{
18675 .ty = union_ty.toIntern(),18675 .ty = union_ty.toIntern(),
...@@ -18771,7 +18771,7 @@ fn zirStructInit(...@@ -18771,7 +18771,7 @@ fn zirStructInit(
18771 const field_name = try mod.intern_pool.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start));18771 const field_name = try mod.intern_pool.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start));
18772 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);18772 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);
18773 const tag_ty = resolved_ty.unionTagTypeHypothetical(mod);18773 const tag_ty = resolved_ty.unionTagTypeHypothetical(mod);
18774 const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?);18774 const enum_field_index = @as(u32, @intCast(tag_ty.enumFieldIndex(field_name, mod).?));
18775 const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index);18775 const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index);
1877618776
18777 const init_inst = try sema.resolveInst(item.data.init);18777 const init_inst = try sema.resolveInst(item.data.init);
...@@ -18915,7 +18915,7 @@ fn finishStructInit(...@@ -18915,7 +18915,7 @@ fn finishStructInit(
18915 });18915 });
18916 const alloc = try block.addTy(.alloc, alloc_ty);18916 const alloc = try block.addTy(.alloc, alloc_ty);
18917 for (field_inits, 0..) |field_init, i_usize| {18917 for (field_inits, 0..) |field_init, i_usize| {
18918 const i = @intCast(u32, i_usize);18918 const i = @as(u32, @intCast(i_usize));
18919 const field_src = dest_src;18919 const field_src = dest_src;
18920 const field_ptr = try sema.structFieldPtrByIndex(block, dest_src, alloc, i, field_src, struct_ty, true);18920 const field_ptr = try sema.structFieldPtrByIndex(block, dest_src, alloc, i, field_src, struct_ty, true);
18921 try sema.storePtr(block, dest_src, field_ptr, field_init);18921 try sema.storePtr(block, dest_src, field_ptr, field_init);
...@@ -18958,7 +18958,7 @@ fn zirStructInitAnon(...@@ -18958,7 +18958,7 @@ fn zirStructInitAnon(
18958 var runtime_index: ?usize = null;18958 var runtime_index: ?usize = null;
18959 var extra_index = extra.end;18959 var extra_index = extra.end;
18960 for (types, 0..) |*field_ty, i_usize| {18960 for (types, 0..) |*field_ty, i_usize| {
18961 const i = @intCast(u32, i_usize);18961 const i = @as(u32, @intCast(i_usize));
18962 const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index);18962 const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index);
18963 extra_index = item.end;18963 extra_index = item.end;
1896418964
...@@ -19037,7 +19037,7 @@ fn zirStructInitAnon(...@@ -19037,7 +19037,7 @@ fn zirStructInitAnon(
19037 const alloc = try block.addTy(.alloc, alloc_ty);19037 const alloc = try block.addTy(.alloc, alloc_ty);
19038 var extra_index = extra.end;19038 var extra_index = extra.end;
19039 for (types, 0..) |field_ty, i_usize| {19039 for (types, 0..) |field_ty, i_usize| {
19040 const i = @intCast(u32, i_usize);19040 const i = @as(u32, @intCast(i_usize));
19041 const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index);19041 const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index);
19042 extra_index = item.end;19042 extra_index = item.end;
1904319043
...@@ -19109,7 +19109,7 @@ fn zirArrayInit(...@@ -19109,7 +19109,7 @@ fn zirArrayInit(
1910919109
19110 const opt_runtime_index: ?u32 = for (resolved_args, 0..) |arg, i| {19110 const opt_runtime_index: ?u32 = for (resolved_args, 0..) |arg, i| {
19111 const comptime_known = try sema.isComptimeKnown(arg);19111 const comptime_known = try sema.isComptimeKnown(arg);
19112 if (!comptime_known) break @intCast(u32, i);19112 if (!comptime_known) break @as(u32, @intCast(i));
19113 } else null;19113 } else null;
1911419114
19115 const runtime_index = opt_runtime_index orelse {19115 const runtime_index = opt_runtime_index orelse {
...@@ -19244,7 +19244,7 @@ fn zirArrayInitAnon(...@@ -19244,7 +19244,7 @@ fn zirArrayInitAnon(
19244 });19244 });
19245 const alloc = try block.addTy(.alloc, alloc_ty);19245 const alloc = try block.addTy(.alloc, alloc_ty);
19246 for (operands, 0..) |operand, i_usize| {19246 for (operands, 0..) |operand, i_usize| {
19247 const i = @intCast(u32, i_usize);19247 const i = @as(u32, @intCast(i_usize));
19248 const field_ptr_ty = try mod.ptrType(.{19248 const field_ptr_ty = try mod.ptrType(.{
19249 .child = types[i],19249 .child = types[i],
19250 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },19250 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
...@@ -19395,7 +19395,7 @@ fn zirFrame(...@@ -19395,7 +19395,7 @@ fn zirFrame(
19395 block: *Block,19395 block: *Block,
19396 extended: Zir.Inst.Extended.InstData,19396 extended: Zir.Inst.Extended.InstData,
19397) CompileError!Air.Inst.Ref {19397) CompileError!Air.Inst.Ref {
19398 const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand));19398 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
19399 return sema.failWithUseOfAsync(block, src);19399 return sema.failWithUseOfAsync(block, src);
19400}19400}
1940119401
...@@ -19588,7 +19588,7 @@ fn zirReify(...@@ -19588,7 +19588,7 @@ fn zirReify(
19588 const mod = sema.mod;19588 const mod = sema.mod;
19589 const gpa = sema.gpa;19589 const gpa = sema.gpa;
19590 const ip = &mod.intern_pool;19590 const ip = &mod.intern_pool;
19591 const name_strategy = @enumFromInt(Zir.Inst.NameStrategy, extended.small);19591 const name_strategy = @as(Zir.Inst.NameStrategy, @enumFromInt(extended.small));
19592 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;19592 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
19593 const src = LazySrcLoc.nodeOffset(extra.node);19593 const src = LazySrcLoc.nodeOffset(extra.node);
19594 const type_info_ty = try sema.getBuiltinType("Type");19594 const type_info_ty = try sema.getBuiltinType("Type");
...@@ -19600,7 +19600,7 @@ fn zirReify(...@@ -19600,7 +19600,7 @@ fn zirReify(
19600 const target = mod.getTarget();19600 const target = mod.getTarget();
19601 if (try union_val.val.toValue().anyUndef(mod)) return sema.failWithUseOfUndef(block, src);19601 if (try union_val.val.toValue().anyUndef(mod)) return sema.failWithUseOfUndef(block, src);
19602 const tag_index = type_info_ty.unionTagFieldIndex(union_val.tag.toValue(), mod).?;19602 const tag_index = type_info_ty.unionTagFieldIndex(union_val.tag.toValue(), mod).?;
19603 switch (@enumFromInt(std.builtin.TypeId, tag_index)) {19603 switch (@as(std.builtin.TypeId, @enumFromInt(tag_index))) {
19604 .Type => return Air.Inst.Ref.type_type,19604 .Type => return Air.Inst.Ref.type_type,
19605 .Void => return Air.Inst.Ref.void_type,19605 .Void => return Air.Inst.Ref.void_type,
19606 .Bool => return Air.Inst.Ref.bool_type,19606 .Bool => return Air.Inst.Ref.bool_type,
...@@ -19623,7 +19623,7 @@ fn zirReify(...@@ -19623,7 +19623,7 @@ fn zirReify(
19623 );19623 );
1962419624
19625 const signedness = mod.toEnum(std.builtin.Signedness, signedness_val);19625 const signedness = mod.toEnum(std.builtin.Signedness, signedness_val);
19626 const bits = @intCast(u16, bits_val.toUnsignedInt(mod));19626 const bits = @as(u16, @intCast(bits_val.toUnsignedInt(mod)));
19627 const ty = try mod.intType(signedness, bits);19627 const ty = try mod.intType(signedness, bits);
19628 return sema.addType(ty);19628 return sema.addType(ty);
19629 },19629 },
...@@ -19636,7 +19636,7 @@ fn zirReify(...@@ -19636,7 +19636,7 @@ fn zirReify(
19636 try ip.getOrPutString(gpa, "child"),19636 try ip.getOrPutString(gpa, "child"),
19637 ).?);19637 ).?);
1963819638
19639 const len = @intCast(u32, len_val.toUnsignedInt(mod));19639 const len = @as(u32, @intCast(len_val.toUnsignedInt(mod)));
19640 const child_ty = child_val.toType();19640 const child_ty = child_val.toType();
1964119641
19642 try sema.checkVectorElemType(block, src, child_ty);19642 try sema.checkVectorElemType(block, src, child_ty);
...@@ -19653,7 +19653,7 @@ fn zirReify(...@@ -19653,7 +19653,7 @@ fn zirReify(
19653 try ip.getOrPutString(gpa, "bits"),19653 try ip.getOrPutString(gpa, "bits"),
19654 ).?);19654 ).?);
1965519655
19656 const bits = @intCast(u16, bits_val.toUnsignedInt(mod));19656 const bits = @as(u16, @intCast(bits_val.toUnsignedInt(mod)));
19657 const ty = switch (bits) {19657 const ty = switch (bits) {
19658 16 => Type.f16,19658 16 => Type.f16,
19659 32 => Type.f32,19659 32 => Type.f32,
...@@ -19925,7 +19925,7 @@ fn zirReify(...@@ -19925,7 +19925,7 @@ fn zirReify(
19925 }19925 }
1992619926
19927 // Define our empty enum decl19927 // Define our empty enum decl
19928 const fields_len = @intCast(u32, try sema.usizeCast(block, src, fields_val.sliceLen(mod)));19928 const fields_len = @as(u32, @intCast(try sema.usizeCast(block, src, fields_val.sliceLen(mod))));
19929 const incomplete_enum = try ip.getIncompleteEnum(gpa, .{19929 const incomplete_enum = try ip.getIncompleteEnum(gpa, .{
19930 .decl = new_decl_index,19930 .decl = new_decl_index,
19931 .namespace = .none,19931 .namespace = .none,
...@@ -20288,7 +20288,7 @@ fn zirReify(...@@ -20288,7 +20288,7 @@ fn zirReify(
20288 if (!try sema.intFitsInType(alignment_val, Type.u32, null)) {20288 if (!try sema.intFitsInType(alignment_val, Type.u32, null)) {
20289 return sema.fail(block, src, "alignment must fit in 'u32'", .{});20289 return sema.fail(block, src, "alignment must fit in 'u32'", .{});
20290 }20290 }
20291 const alignment = @intCast(u29, alignment_val.toUnsignedInt(mod));20291 const alignment = @as(u29, @intCast(alignment_val.toUnsignedInt(mod)));
20292 if (alignment == target_util.defaultFunctionAlignment(target)) {20292 if (alignment == target_util.defaultFunctionAlignment(target)) {
20293 break :alignment .none;20293 break :alignment .none;
20294 } else {20294 } else {
...@@ -20565,7 +20565,7 @@ fn reifyStruct(...@@ -20565,7 +20565,7 @@ fn reifyStruct(
20565 try sema.checkBackingIntType(block, src, backing_int_ty, fields_bit_sum);20565 try sema.checkBackingIntType(block, src, backing_int_ty, fields_bit_sum);
20566 struct_obj.backing_int_ty = backing_int_ty;20566 struct_obj.backing_int_ty = backing_int_ty;
20567 } else {20567 } else {
20568 struct_obj.backing_int_ty = try mod.intType(.unsigned, @intCast(u16, fields_bit_sum));20568 struct_obj.backing_int_ty = try mod.intType(.unsigned, @as(u16, @intCast(fields_bit_sum)));
20569 }20569 }
2057020570
20571 struct_obj.status = .have_layout;20571 struct_obj.status = .have_layout;
...@@ -20636,7 +20636,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C...@@ -20636,7 +20636,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
20636}20636}
2063720637
20638fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {20638fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
20639 const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand));20639 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
2064020640
20641 const va_list_ty = try sema.getBuiltinType("VaList");20641 const va_list_ty = try sema.getBuiltinType("VaList");
20642 try sema.requireRuntimeBlock(block, src, null);20642 try sema.requireRuntimeBlock(block, src, null);
...@@ -20903,7 +20903,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -20903,7 +20903,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
20903}20903}
2090420904
20905fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {20905fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
20906 const flags = @bitCast(Zir.Inst.FullPtrCastFlags, @truncate(u5, extended.small));20906 const flags = @as(Zir.Inst.FullPtrCastFlags, @bitCast(@as(u5, @truncate(extended.small))));
20907 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;20907 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
20908 const src = LazySrcLoc.nodeOffset(extra.node);20908 const src = LazySrcLoc.nodeOffset(extra.node);
20909 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };20909 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
...@@ -21310,7 +21310,7 @@ fn ptrCastFull(...@@ -21310,7 +21310,7 @@ fn ptrCastFull(
2131021310
21311fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {21311fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
21312 const mod = sema.mod;21312 const mod = sema.mod;
21313 const flags = @bitCast(Zir.Inst.FullPtrCastFlags, @truncate(u5, extended.small));21313 const flags = @as(Zir.Inst.FullPtrCastFlags, @bitCast(@as(u5, @truncate(extended.small))));
21314 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;21314 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
21315 const src = LazySrcLoc.nodeOffset(extra.node);21315 const src = LazySrcLoc.nodeOffset(extra.node);
21316 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };21316 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
...@@ -22271,7 +22271,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -22271,7 +22271,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
22271 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;22271 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
22272 const len_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };22272 const len_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
22273 const scalar_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };22273 const scalar_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
22274 const len = @intCast(u32, try sema.resolveInt(block, len_src, extra.lhs, Type.u32, "vector splat destination length must be comptime-known"));22274 const len = @as(u32, @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, "vector splat destination length must be comptime-known")));
22275 const scalar = try sema.resolveInst(extra.rhs);22275 const scalar = try sema.resolveInst(extra.rhs);
22276 const scalar_ty = sema.typeOf(scalar);22276 const scalar_ty = sema.typeOf(scalar);
22277 try sema.checkVectorElemType(block, scalar_src, scalar_ty);22277 try sema.checkVectorElemType(block, scalar_src, scalar_ty);
...@@ -22376,12 +22376,12 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -22376,12 +22376,12 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
22376 else => return sema.fail(block, mask_src, "expected vector or array, found '{}'", .{sema.typeOf(mask).fmt(sema.mod)}),22376 else => return sema.fail(block, mask_src, "expected vector or array, found '{}'", .{sema.typeOf(mask).fmt(sema.mod)}),
22377 };22377 };
22378 mask_ty = try mod.vectorType(.{22378 mask_ty = try mod.vectorType(.{
22379 .len = @intCast(u32, mask_len),22379 .len = @as(u32, @intCast(mask_len)),
22380 .child = .i32_type,22380 .child = .i32_type,
22381 });22381 });
22382 mask = try sema.coerce(block, mask_ty, mask, mask_src);22382 mask = try sema.coerce(block, mask_ty, mask, mask_src);
22383 const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask, "shuffle mask must be comptime-known");22383 const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask, "shuffle mask must be comptime-known");
22384 return sema.analyzeShuffle(block, inst_data.src_node, elem_ty, a, b, mask_val, @intCast(u32, mask_len));22384 return sema.analyzeShuffle(block, inst_data.src_node, elem_ty, a, b, mask_val, @as(u32, @intCast(mask_len)));
22385}22385}
2238622386
22387fn analyzeShuffle(22387fn analyzeShuffle(
...@@ -22425,8 +22425,8 @@ fn analyzeShuffle(...@@ -22425,8 +22425,8 @@ fn analyzeShuffle(
22425 if (maybe_a_len == null and maybe_b_len == null) {22425 if (maybe_a_len == null and maybe_b_len == null) {
22426 return sema.addConstUndef(res_ty);22426 return sema.addConstUndef(res_ty);
22427 }22427 }
22428 const a_len = @intCast(u32, maybe_a_len orelse maybe_b_len.?);22428 const a_len = @as(u32, @intCast(maybe_a_len orelse maybe_b_len.?));
22429 const b_len = @intCast(u32, maybe_b_len orelse a_len);22429 const b_len = @as(u32, @intCast(maybe_b_len orelse a_len));
2243022430
22431 const a_ty = try mod.vectorType(.{22431 const a_ty = try mod.vectorType(.{
22432 .len = a_len,22432 .len = a_len,
...@@ -22445,17 +22445,17 @@ fn analyzeShuffle(...@@ -22445,17 +22445,17 @@ fn analyzeShuffle(
22445 .{ b_len, b_src, b_ty },22445 .{ b_len, b_src, b_ty },
22446 };22446 };
2244722447
22448 for (0..@intCast(usize, mask_len)) |i| {22448 for (0..@as(usize, @intCast(mask_len))) |i| {
22449 const elem = try mask.elemValue(sema.mod, i);22449 const elem = try mask.elemValue(sema.mod, i);
22450 if (elem.isUndef(mod)) continue;22450 if (elem.isUndef(mod)) continue;
22451 const int = elem.toSignedInt(mod);22451 const int = elem.toSignedInt(mod);
22452 var unsigned: u32 = undefined;22452 var unsigned: u32 = undefined;
22453 var chosen: u32 = undefined;22453 var chosen: u32 = undefined;
22454 if (int >= 0) {22454 if (int >= 0) {
22455 unsigned = @intCast(u32, int);22455 unsigned = @as(u32, @intCast(int));
22456 chosen = 0;22456 chosen = 0;
22457 } else {22457 } else {
22458 unsigned = @intCast(u32, ~int);22458 unsigned = @as(u32, @intCast(~int));
22459 chosen = 1;22459 chosen = 1;
22460 }22460 }
22461 if (unsigned >= operand_info[chosen][0]) {22461 if (unsigned >= operand_info[chosen][0]) {
...@@ -22488,7 +22488,7 @@ fn analyzeShuffle(...@@ -22488,7 +22488,7 @@ fn analyzeShuffle(
22488 continue;22488 continue;
22489 }22489 }
22490 const int = mask_elem_val.toSignedInt(mod);22490 const int = mask_elem_val.toSignedInt(mod);
22491 const unsigned = if (int >= 0) @intCast(u32, int) else @intCast(u32, ~int);22491 const unsigned = if (int >= 0) @as(u32, @intCast(int)) else @as(u32, @intCast(~int));
22492 values[i] = try (try (if (int >= 0) a_val else b_val).elemValue(mod, unsigned)).intern(elem_ty, mod);22492 values[i] = try (try (if (int >= 0) a_val else b_val).elemValue(mod, unsigned)).intern(elem_ty, mod);
22493 }22493 }
22494 return sema.addConstant((try mod.intern(.{ .aggregate = .{22494 return sema.addConstant((try mod.intern(.{ .aggregate = .{
...@@ -22509,23 +22509,23 @@ fn analyzeShuffle(...@@ -22509,23 +22509,23 @@ fn analyzeShuffle(
22509 const max_len = try sema.usizeCast(block, max_src, @max(a_len, b_len));22509 const max_len = try sema.usizeCast(block, max_src, @max(a_len, b_len));
2251022510
22511 const expand_mask_values = try sema.arena.alloc(InternPool.Index, max_len);22511 const expand_mask_values = try sema.arena.alloc(InternPool.Index, max_len);
22512 for (@intCast(usize, 0)..@intCast(usize, min_len)) |i| {22512 for (@as(usize, @intCast(0))..@as(usize, @intCast(min_len))) |i| {
22513 expand_mask_values[i] = (try mod.intValue(Type.comptime_int, i)).toIntern();22513 expand_mask_values[i] = (try mod.intValue(Type.comptime_int, i)).toIntern();
22514 }22514 }
22515 for (@intCast(usize, min_len)..@intCast(usize, max_len)) |i| {22515 for (@as(usize, @intCast(min_len))..@as(usize, @intCast(max_len))) |i| {
22516 expand_mask_values[i] = (try mod.intValue(Type.comptime_int, -1)).toIntern();22516 expand_mask_values[i] = (try mod.intValue(Type.comptime_int, -1)).toIntern();
22517 }22517 }
22518 const expand_mask = try mod.intern(.{ .aggregate = .{22518 const expand_mask = try mod.intern(.{ .aggregate = .{
22519 .ty = (try mod.vectorType(.{ .len = @intCast(u32, max_len), .child = .comptime_int_type })).toIntern(),22519 .ty = (try mod.vectorType(.{ .len = @as(u32, @intCast(max_len)), .child = .comptime_int_type })).toIntern(),
22520 .storage = .{ .elems = expand_mask_values },22520 .storage = .{ .elems = expand_mask_values },
22521 } });22521 } });
2252222522
22523 if (a_len < b_len) {22523 if (a_len < b_len) {
22524 const undef = try sema.addConstUndef(a_ty);22524 const undef = try sema.addConstUndef(a_ty);
22525 a = try sema.analyzeShuffle(block, src_node, elem_ty, a, undef, expand_mask.toValue(), @intCast(u32, max_len));22525 a = try sema.analyzeShuffle(block, src_node, elem_ty, a, undef, expand_mask.toValue(), @as(u32, @intCast(max_len)));
22526 } else {22526 } else {
22527 const undef = try sema.addConstUndef(b_ty);22527 const undef = try sema.addConstUndef(b_ty);
22528 b = try sema.analyzeShuffle(block, src_node, elem_ty, b, undef, expand_mask.toValue(), @intCast(u32, max_len));22528 b = try sema.analyzeShuffle(block, src_node, elem_ty, b, undef, expand_mask.toValue(), @as(u32, @intCast(max_len)));
22529 }22529 }
22530 }22530 }
2253122531
...@@ -22562,7 +22562,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C...@@ -22562,7 +22562,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
22562 .Vector, .Array => pred_ty.arrayLen(mod),22562 .Vector, .Array => pred_ty.arrayLen(mod),
22563 else => return sema.fail(block, pred_src, "expected vector or array, found '{}'", .{pred_ty.fmt(mod)}),22563 else => return sema.fail(block, pred_src, "expected vector or array, found '{}'", .{pred_ty.fmt(mod)}),
22564 };22564 };
22565 const vec_len = @intCast(u32, try sema.usizeCast(block, pred_src, vec_len_u64));22565 const vec_len = @as(u32, @intCast(try sema.usizeCast(block, pred_src, vec_len_u64)));
2256622566
22567 const bool_vec_ty = try mod.vectorType(.{22567 const bool_vec_ty = try mod.vectorType(.{
22568 .len = vec_len,22568 .len = vec_len,
...@@ -22930,7 +22930,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -22930,7 +22930,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2293022930
22931 var resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(mod));22931 var resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(mod));
22932 for (resolved_args, 0..) |*resolved, i| {22932 for (resolved_args, 0..) |*resolved, i| {
22933 resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @intCast(u32, i), args_ty);22933 resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @as(u32, @intCast(i)), args_ty);
22934 }22934 }
2293522935
22936 const callee_ty = sema.typeOf(func);22936 const callee_ty = sema.typeOf(func);
...@@ -23048,7 +23048,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -23048,7 +23048,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
23048 .ty = try sema.addType(result_ptr),23048 .ty = try sema.addType(result_ptr),
23049 .payload = try block.sema.addExtra(Air.FieldParentPtr{23049 .payload = try block.sema.addExtra(Air.FieldParentPtr{
23050 .field_ptr = casted_field_ptr,23050 .field_ptr = casted_field_ptr,
23051 .field_index = @intCast(u32, field_index),23051 .field_index = @as(u32, @intCast(field_index)),
23052 }),23052 }),
23053 } },23053 } },
23054 });23054 });
...@@ -23684,7 +23684,7 @@ fn zirVarExtended(...@@ -23684,7 +23684,7 @@ fn zirVarExtended(
23684 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);23684 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
23685 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };23685 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };
23686 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };23686 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };
23687 const small = @bitCast(Zir.Inst.ExtendedVar.Small, extended.small);23687 const small = @as(Zir.Inst.ExtendedVar.Small, @bitCast(extended.small));
2368823688
23689 var extra_index: usize = extra.end;23689 var extra_index: usize = extra.end;
2369023690
...@@ -23699,7 +23699,7 @@ fn zirVarExtended(...@@ -23699,7 +23699,7 @@ fn zirVarExtended(
23699 assert(!small.has_align);23699 assert(!small.has_align);
2370023700
23701 const uncasted_init: Air.Inst.Ref = if (small.has_init) blk: {23701 const uncasted_init: Air.Inst.Ref = if (small.has_init) blk: {
23702 const init_ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);23702 const init_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
23703 extra_index += 1;23703 extra_index += 1;
23704 break :blk try sema.resolveInst(init_ref);23704 break :blk try sema.resolveInst(init_ref);
23705 } else .none;23705 } else .none;
...@@ -23776,7 +23776,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -23776,7 +23776,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
23776 if (val.isGenericPoison()) {23776 if (val.isGenericPoison()) {
23777 break :blk null;23777 break :blk null;
23778 }23778 }
23779 const alignment = @intCast(u32, val.toUnsignedInt(mod));23779 const alignment = @as(u32, @intCast(val.toUnsignedInt(mod)));
23780 try sema.validateAlign(block, align_src, alignment);23780 try sema.validateAlign(block, align_src, alignment);
23781 if (alignment == target_util.defaultFunctionAlignment(target)) {23781 if (alignment == target_util.defaultFunctionAlignment(target)) {
23782 break :blk .none;23782 break :blk .none;
...@@ -23784,7 +23784,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -23784,7 +23784,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
23784 break :blk Alignment.fromNonzeroByteUnits(alignment);23784 break :blk Alignment.fromNonzeroByteUnits(alignment);
23785 }23785 }
23786 } else if (extra.data.bits.has_align_ref) blk: {23786 } else if (extra.data.bits.has_align_ref) blk: {
23787 const align_ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);23787 const align_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
23788 extra_index += 1;23788 extra_index += 1;
23789 const align_tv = sema.resolveInstConst(block, align_src, align_ref, "alignment must be comptime-known") catch |err| switch (err) {23789 const align_tv = sema.resolveInstConst(block, align_src, align_ref, "alignment must be comptime-known") catch |err| switch (err) {
23790 error.GenericPoison => {23790 error.GenericPoison => {
...@@ -23792,7 +23792,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -23792,7 +23792,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
23792 },23792 },
23793 else => |e| return e,23793 else => |e| return e,
23794 };23794 };
23795 const alignment = @intCast(u32, align_tv.val.toUnsignedInt(mod));23795 const alignment = @as(u32, @intCast(align_tv.val.toUnsignedInt(mod)));
23796 try sema.validateAlign(block, align_src, alignment);23796 try sema.validateAlign(block, align_src, alignment);
23797 if (alignment == target_util.defaultFunctionAlignment(target)) {23797 if (alignment == target_util.defaultFunctionAlignment(target)) {
23798 break :blk .none;23798 break :blk .none;
...@@ -23814,7 +23814,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -23814,7 +23814,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
23814 }23814 }
23815 break :blk mod.toEnum(std.builtin.AddressSpace, val);23815 break :blk mod.toEnum(std.builtin.AddressSpace, val);
23816 } else if (extra.data.bits.has_addrspace_ref) blk: {23816 } else if (extra.data.bits.has_addrspace_ref) blk: {
23817 const addrspace_ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);23817 const addrspace_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
23818 extra_index += 1;23818 extra_index += 1;
23819 const addrspace_tv = sema.resolveInstConst(block, addrspace_src, addrspace_ref, "addrespace must be comptime-known") catch |err| switch (err) {23819 const addrspace_tv = sema.resolveInstConst(block, addrspace_src, addrspace_ref, "addrespace must be comptime-known") catch |err| switch (err) {
23820 error.GenericPoison => {23820 error.GenericPoison => {
...@@ -23838,7 +23838,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -23838,7 +23838,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
23838 }23838 }
23839 break :blk FuncLinkSection{ .explicit = try val.toIpString(ty, mod) };23839 break :blk FuncLinkSection{ .explicit = try val.toIpString(ty, mod) };
23840 } else if (extra.data.bits.has_section_ref) blk: {23840 } else if (extra.data.bits.has_section_ref) blk: {
23841 const section_ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);23841 const section_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
23842 extra_index += 1;23842 extra_index += 1;
23843 const section_name = sema.resolveConstStringIntern(block, section_src, section_ref, "linksection must be comptime-known") catch |err| switch (err) {23843 const section_name = sema.resolveConstStringIntern(block, section_src, section_ref, "linksection must be comptime-known") catch |err| switch (err) {
23844 error.GenericPoison => {23844 error.GenericPoison => {
...@@ -23862,7 +23862,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -23862,7 +23862,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
23862 }23862 }
23863 break :blk mod.toEnum(std.builtin.CallingConvention, val);23863 break :blk mod.toEnum(std.builtin.CallingConvention, val);
23864 } else if (extra.data.bits.has_cc_ref) blk: {23864 } else if (extra.data.bits.has_cc_ref) blk: {
23865 const cc_ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);23865 const cc_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
23866 extra_index += 1;23866 extra_index += 1;
23867 const cc_tv = sema.resolveInstConst(block, cc_src, cc_ref, "calling convention must be comptime-known") catch |err| switch (err) {23867 const cc_tv = sema.resolveInstConst(block, cc_src, cc_ref, "calling convention must be comptime-known") catch |err| switch (err) {
23868 error.GenericPoison => {23868 error.GenericPoison => {
...@@ -23886,7 +23886,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -23886,7 +23886,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
23886 const ty = val.toType();23886 const ty = val.toType();
23887 break :blk ty;23887 break :blk ty;
23888 } else if (extra.data.bits.has_ret_ty_ref) blk: {23888 } else if (extra.data.bits.has_ret_ty_ref) blk: {
23889 const ret_ty_ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_index]);23889 const ret_ty_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
23890 extra_index += 1;23890 extra_index += 1;
23891 const ret_ty_tv = sema.resolveInstConst(block, ret_src, ret_ty_ref, "return type must be comptime-known") catch |err| switch (err) {23891 const ret_ty_tv = sema.resolveInstConst(block, ret_src, ret_ty_ref, "return type must be comptime-known") catch |err| switch (err) {
23892 error.GenericPoison => {23892 error.GenericPoison => {
...@@ -23995,7 +23995,7 @@ fn zirWasmMemorySize(...@@ -23995,7 +23995,7 @@ fn zirWasmMemorySize(
23995 return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});23995 return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
23996 }23996 }
2399723997
23998 const index = @intCast(u32, try sema.resolveInt(block, index_src, extra.operand, Type.u32, "wasm memory size index must be comptime-known"));23998 const index = @as(u32, @intCast(try sema.resolveInt(block, index_src, extra.operand, Type.u32, "wasm memory size index must be comptime-known")));
23999 try sema.requireRuntimeBlock(block, builtin_src, null);23999 try sema.requireRuntimeBlock(block, builtin_src, null);
24000 return block.addInst(.{24000 return block.addInst(.{
24001 .tag = .wasm_memory_size,24001 .tag = .wasm_memory_size,
...@@ -24020,7 +24020,7 @@ fn zirWasmMemoryGrow(...@@ -24020,7 +24020,7 @@ fn zirWasmMemoryGrow(
24020 return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});24020 return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
24021 }24021 }
2402224022
24023 const index = @intCast(u32, try sema.resolveInt(block, index_src, extra.lhs, Type.u32, "wasm memory size index must be comptime-known"));24023 const index = @as(u32, @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, "wasm memory size index must be comptime-known")));
24024 const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src);24024 const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src);
2402524025
24026 try sema.requireRuntimeBlock(block, builtin_src, null);24026 try sema.requireRuntimeBlock(block, builtin_src, null);
...@@ -24060,7 +24060,7 @@ fn resolvePrefetchOptions(...@@ -24060,7 +24060,7 @@ fn resolvePrefetchOptions(
2406024060
24061 return std.builtin.PrefetchOptions{24061 return std.builtin.PrefetchOptions{
24062 .rw = mod.toEnum(std.builtin.PrefetchOptions.Rw, rw_val),24062 .rw = mod.toEnum(std.builtin.PrefetchOptions.Rw, rw_val),
24063 .locality = @intCast(u2, locality_val.toUnsignedInt(mod)),24063 .locality = @as(u2, @intCast(locality_val.toUnsignedInt(mod))),
24064 .cache = mod.toEnum(std.builtin.PrefetchOptions.Cache, cache_val),24064 .cache = mod.toEnum(std.builtin.PrefetchOptions.Cache, cache_val),
24065 };24065 };
24066}24066}
...@@ -24259,7 +24259,7 @@ fn zirWorkItem(...@@ -24259,7 +24259,7 @@ fn zirWorkItem(
24259 },24259 },
24260 }24260 }
2426124261
24262 const dimension = @intCast(u32, try sema.resolveInt(block, dimension_src, extra.operand, Type.u32, "dimension must be comptime-known"));24262 const dimension = @as(u32, @intCast(try sema.resolveInt(block, dimension_src, extra.operand, Type.u32, "dimension must be comptime-known")));
24263 try sema.requireRuntimeBlock(block, builtin_src, null);24263 try sema.requireRuntimeBlock(block, builtin_src, null);
2426424264
24265 return block.addInst(.{24265 return block.addInst(.{
...@@ -24814,7 +24814,7 @@ fn addSafetyCheckExtra(...@@ -24814,7 +24814,7 @@ fn addSafetyCheckExtra(
24814 fail_block.instructions.items.len);24814 fail_block.instructions.items.len);
2481524815
24816 try sema.air_instructions.ensureUnusedCapacity(gpa, 3);24816 try sema.air_instructions.ensureUnusedCapacity(gpa, 3);
24817 const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);24817 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
24818 const cond_br_inst = block_inst + 1;24818 const cond_br_inst = block_inst + 1;
24819 const br_inst = cond_br_inst + 1;24819 const br_inst = cond_br_inst + 1;
24820 sema.air_instructions.appendAssumeCapacity(.{24820 sema.air_instructions.appendAssumeCapacity(.{
...@@ -24834,7 +24834,7 @@ fn addSafetyCheckExtra(...@@ -24834,7 +24834,7 @@ fn addSafetyCheckExtra(
24834 .operand = ok,24834 .operand = ok,
24835 .payload = sema.addExtraAssumeCapacity(Air.CondBr{24835 .payload = sema.addExtraAssumeCapacity(Air.CondBr{
24836 .then_body_len = 1,24836 .then_body_len = 1,
24837 .else_body_len = @intCast(u32, fail_block.instructions.items.len),24837 .else_body_len = @as(u32, @intCast(fail_block.instructions.items.len)),
24838 }),24838 }),
24839 } },24839 } },
24840 });24840 });
...@@ -25210,7 +25210,7 @@ fn fieldVal(...@@ -25210,7 +25210,7 @@ fn fieldVal(
25210 const union_ty = try sema.resolveTypeFields(child_type);25210 const union_ty = try sema.resolveTypeFields(child_type);
25211 if (union_ty.unionTagType(mod)) |enum_ty| {25211 if (union_ty.unionTagType(mod)) |enum_ty| {
25212 if (enum_ty.enumFieldIndex(field_name, mod)) |field_index_usize| {25212 if (enum_ty.enumFieldIndex(field_name, mod)) |field_index_usize| {
25213 const field_index = @intCast(u32, field_index_usize);25213 const field_index = @as(u32, @intCast(field_index_usize));
25214 return sema.addConstant(25214 return sema.addConstant(
25215 try mod.enumValueFieldIndex(enum_ty, field_index),25215 try mod.enumValueFieldIndex(enum_ty, field_index),
25216 );25216 );
...@@ -25226,7 +25226,7 @@ fn fieldVal(...@@ -25226,7 +25226,7 @@ fn fieldVal(
25226 }25226 }
25227 const field_index_usize = child_type.enumFieldIndex(field_name, mod) orelse25227 const field_index_usize = child_type.enumFieldIndex(field_name, mod) orelse
25228 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);25228 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
25229 const field_index = @intCast(u32, field_index_usize);25229 const field_index = @as(u32, @intCast(field_index_usize));
25230 const enum_val = try mod.enumValueFieldIndex(child_type, field_index);25230 const enum_val = try mod.enumValueFieldIndex(child_type, field_index);
25231 return sema.addConstant(enum_val);25231 return sema.addConstant(enum_val);
25232 },25232 },
...@@ -25438,7 +25438,7 @@ fn fieldPtr(...@@ -25438,7 +25438,7 @@ fn fieldPtr(
25438 const union_ty = try sema.resolveTypeFields(child_type);25438 const union_ty = try sema.resolveTypeFields(child_type);
25439 if (union_ty.unionTagType(mod)) |enum_ty| {25439 if (union_ty.unionTagType(mod)) |enum_ty| {
25440 if (enum_ty.enumFieldIndex(field_name, mod)) |field_index| {25440 if (enum_ty.enumFieldIndex(field_name, mod)) |field_index| {
25441 const field_index_u32 = @intCast(u32, field_index);25441 const field_index_u32 = @as(u32, @intCast(field_index));
25442 var anon_decl = try block.startAnonDecl();25442 var anon_decl = try block.startAnonDecl();
25443 defer anon_decl.deinit();25443 defer anon_decl.deinit();
25444 return sema.analyzeDeclRef(try anon_decl.finish(25444 return sema.analyzeDeclRef(try anon_decl.finish(
...@@ -25459,7 +25459,7 @@ fn fieldPtr(...@@ -25459,7 +25459,7 @@ fn fieldPtr(
25459 const field_index = child_type.enumFieldIndex(field_name, mod) orelse {25459 const field_index = child_type.enumFieldIndex(field_name, mod) orelse {
25460 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);25460 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
25461 };25461 };
25462 const field_index_u32 = @intCast(u32, field_index);25462 const field_index_u32 = @as(u32, @intCast(field_index));
25463 var anon_decl = try block.startAnonDecl();25463 var anon_decl = try block.startAnonDecl();
25464 defer anon_decl.deinit();25464 defer anon_decl.deinit();
25465 return sema.analyzeDeclRef(try anon_decl.finish(25465 return sema.analyzeDeclRef(try anon_decl.finish(
...@@ -25544,7 +25544,7 @@ fn fieldCallBind(...@@ -25544,7 +25544,7 @@ fn fieldCallBind(
25544 if (mod.typeToStruct(struct_ty)) |struct_obj| {25544 if (mod.typeToStruct(struct_ty)) |struct_obj| {
25545 const field_index_usize = struct_obj.fields.getIndex(field_name) orelse25545 const field_index_usize = struct_obj.fields.getIndex(field_name) orelse
25546 break :find_field;25546 break :find_field;
25547 const field_index = @intCast(u32, field_index_usize);25547 const field_index = @as(u32, @intCast(field_index_usize));
25548 const field = struct_obj.fields.values()[field_index];25548 const field = struct_obj.fields.values()[field_index];
2554925549
25550 return sema.finishFieldCallBind(block, src, ptr_ty, field.ty, field_index, object_ptr);25550 return sema.finishFieldCallBind(block, src, ptr_ty, field.ty, field_index, object_ptr);
...@@ -25559,7 +25559,7 @@ fn fieldCallBind(...@@ -25559,7 +25559,7 @@ fn fieldCallBind(
25559 } else {25559 } else {
25560 const max = struct_ty.structFieldCount(mod);25560 const max = struct_ty.structFieldCount(mod);
25561 for (0..max) |i_usize| {25561 for (0..max) |i_usize| {
25562 const i = @intCast(u32, i_usize);25562 const i = @as(u32, @intCast(i_usize));
25563 if (field_name == struct_ty.structFieldName(i, mod)) {25563 if (field_name == struct_ty.structFieldName(i, mod)) {
25564 return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(i, mod), i, object_ptr);25564 return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(i, mod), i, object_ptr);
25565 }25565 }
...@@ -25570,7 +25570,7 @@ fn fieldCallBind(...@@ -25570,7 +25570,7 @@ fn fieldCallBind(
25570 const union_ty = try sema.resolveTypeFields(concrete_ty);25570 const union_ty = try sema.resolveTypeFields(concrete_ty);
25571 const fields = union_ty.unionFields(mod);25571 const fields = union_ty.unionFields(mod);
25572 const field_index_usize = fields.getIndex(field_name) orelse break :find_field;25572 const field_index_usize = fields.getIndex(field_name) orelse break :find_field;
25573 const field_index = @intCast(u32, field_index_usize);25573 const field_index = @as(u32, @intCast(field_index_usize));
25574 const field = fields.values()[field_index];25574 const field = fields.values()[field_index];
2557525575
25576 return sema.finishFieldCallBind(block, src, ptr_ty, field.ty, field_index, object_ptr);25576 return sema.finishFieldCallBind(block, src, ptr_ty, field.ty, field_index, object_ptr);
...@@ -25792,7 +25792,7 @@ fn structFieldPtr(...@@ -25792,7 +25792,7 @@ fn structFieldPtr(
2579225792
25793 const field_index_big = struct_obj.fields.getIndex(field_name) orelse25793 const field_index_big = struct_obj.fields.getIndex(field_name) orelse
25794 return sema.failWithBadStructFieldAccess(block, struct_obj, field_name_src, field_name);25794 return sema.failWithBadStructFieldAccess(block, struct_obj, field_name_src, field_name);
25795 const field_index = @intCast(u32, field_index_big);25795 const field_index = @as(u32, @intCast(field_index_big));
2579625796
25797 return sema.structFieldPtrByIndex(block, src, struct_ptr, field_index, field_name_src, struct_ty, initializing);25797 return sema.structFieldPtrByIndex(block, src, struct_ptr, field_index, field_name_src, struct_ty, initializing);
25798}25798}
...@@ -25838,7 +25838,7 @@ fn structFieldPtrByIndex(...@@ -25838,7 +25838,7 @@ fn structFieldPtrByIndex(
25838 if (i == field_index) {25838 if (i == field_index) {
25839 ptr_ty_data.packed_offset.bit_offset = running_bits;25839 ptr_ty_data.packed_offset.bit_offset = running_bits;
25840 }25840 }
25841 running_bits += @intCast(u16, f.ty.bitSize(mod));25841 running_bits += @as(u16, @intCast(f.ty.bitSize(mod)));
25842 }25842 }
25843 ptr_ty_data.packed_offset.host_size = (running_bits + 7) / 8;25843 ptr_ty_data.packed_offset.host_size = (running_bits + 7) / 8;
2584425844
...@@ -25868,7 +25868,7 @@ fn structFieldPtrByIndex(...@@ -25868,7 +25868,7 @@ fn structFieldPtrByIndex(
25868 const elem_size_bits = ptr_ty_data.child.toType().bitSize(mod);25868 const elem_size_bits = ptr_ty_data.child.toType().bitSize(mod);
25869 if (elem_size_bytes * 8 == elem_size_bits) {25869 if (elem_size_bytes * 8 == elem_size_bits) {
25870 const byte_offset = ptr_ty_data.packed_offset.bit_offset / 8;25870 const byte_offset = ptr_ty_data.packed_offset.bit_offset / 8;
25871 const new_align = @enumFromInt(Alignment, @ctz(byte_offset | parent_align));25871 const new_align = @as(Alignment, @enumFromInt(@ctz(byte_offset | parent_align)));
25872 assert(new_align != .none);25872 assert(new_align != .none);
25873 ptr_ty_data.flags.alignment = new_align;25873 ptr_ty_data.flags.alignment = new_align;
25874 ptr_ty_data.packed_offset = .{ .host_size = 0, .bit_offset = 0 };25874 ptr_ty_data.packed_offset = .{ .host_size = 0, .bit_offset = 0 };
...@@ -25923,7 +25923,7 @@ fn structFieldVal(...@@ -25923,7 +25923,7 @@ fn structFieldVal(
2592325923
25924 const field_index_usize = struct_obj.fields.getIndex(field_name) orelse25924 const field_index_usize = struct_obj.fields.getIndex(field_name) orelse
25925 return sema.failWithBadStructFieldAccess(block, struct_obj, field_name_src, field_name);25925 return sema.failWithBadStructFieldAccess(block, struct_obj, field_name_src, field_name);
25926 const field_index = @intCast(u32, field_index_usize);25926 const field_index = @as(u32, @intCast(field_index_usize));
25927 const field = struct_obj.fields.values()[field_index];25927 const field = struct_obj.fields.values()[field_index];
2592825928
25929 if (field.is_comptime) {25929 if (field.is_comptime) {
...@@ -26058,7 +26058,7 @@ fn unionFieldPtr(...@@ -26058,7 +26058,7 @@ fn unionFieldPtr(
26058 .address_space = union_ptr_ty.ptrAddressSpace(mod),26058 .address_space = union_ptr_ty.ptrAddressSpace(mod),
26059 },26059 },
26060 });26060 });
26061 const enum_field_index = @intCast(u32, union_obj.tag_ty.enumFieldIndex(field_name, mod).?);26061 const enum_field_index = @as(u32, @intCast(union_obj.tag_ty.enumFieldIndex(field_name, mod).?));
2606226062
26063 if (initializing and field.ty.zigTypeTag(mod) == .NoReturn) {26063 if (initializing and field.ty.zigTypeTag(mod) == .NoReturn) {
26064 const msg = msg: {26064 const msg = msg: {
...@@ -26146,7 +26146,7 @@ fn unionFieldVal(...@@ -26146,7 +26146,7 @@ fn unionFieldVal(
26146 const union_obj = mod.typeToUnion(union_ty).?;26146 const union_obj = mod.typeToUnion(union_ty).?;
26147 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);26147 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);
26148 const field = union_obj.fields.values()[field_index];26148 const field = union_obj.fields.values()[field_index];
26149 const enum_field_index = @intCast(u32, union_obj.tag_ty.enumFieldIndex(field_name, mod).?);26149 const enum_field_index = @as(u32, @intCast(union_obj.tag_ty.enumFieldIndex(field_name, mod).?));
2615026150
26151 if (try sema.resolveMaybeUndefVal(union_byval)) |union_val| {26151 if (try sema.resolveMaybeUndefVal(union_byval)) |union_val| {
26152 if (union_val.isUndef(mod)) return sema.addConstUndef(field.ty);26152 if (union_val.isUndef(mod)) return sema.addConstUndef(field.ty);
...@@ -26226,7 +26226,7 @@ fn elemPtr(...@@ -26226,7 +26226,7 @@ fn elemPtr(
26226 .Struct => {26226 .Struct => {
26227 // Tuple field access.26227 // Tuple field access.
26228 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known");26228 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known");
26229 const index = @intCast(u32, index_val.toUnsignedInt(mod));26229 const index = @as(u32, @intCast(index_val.toUnsignedInt(mod)));
26230 return sema.tupleFieldPtr(block, src, indexable_ptr, elem_index_src, index, init);26230 return sema.tupleFieldPtr(block, src, indexable_ptr, elem_index_src, index, init);
26231 },26231 },
26232 else => {26232 else => {
...@@ -26261,7 +26261,7 @@ fn elemPtrOneLayerOnly(...@@ -26261,7 +26261,7 @@ fn elemPtrOneLayerOnly(
26261 const runtime_src = rs: {26261 const runtime_src = rs: {
26262 const ptr_val = maybe_ptr_val orelse break :rs indexable_src;26262 const ptr_val = maybe_ptr_val orelse break :rs indexable_src;
26263 const index_val = maybe_index_val orelse break :rs elem_index_src;26263 const index_val = maybe_index_val orelse break :rs elem_index_src;
26264 const index = @intCast(usize, index_val.toUnsignedInt(mod));26264 const index = @as(usize, @intCast(index_val.toUnsignedInt(mod)));
26265 const result_ty = try sema.elemPtrType(indexable_ty, index);26265 const result_ty = try sema.elemPtrType(indexable_ty, index);
26266 const elem_ptr = try ptr_val.elemPtr(result_ty, index, mod);26266 const elem_ptr = try ptr_val.elemPtr(result_ty, index, mod);
26267 return sema.addConstant(elem_ptr);26267 return sema.addConstant(elem_ptr);
...@@ -26280,7 +26280,7 @@ fn elemPtrOneLayerOnly(...@@ -26280,7 +26280,7 @@ fn elemPtrOneLayerOnly(
26280 .Struct => {26280 .Struct => {
26281 assert(child_ty.isTuple(mod));26281 assert(child_ty.isTuple(mod));
26282 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known");26282 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known");
26283 const index = @intCast(u32, index_val.toUnsignedInt(mod));26283 const index = @as(u32, @intCast(index_val.toUnsignedInt(mod)));
26284 return sema.tupleFieldPtr(block, indexable_src, indexable, elem_index_src, index, false);26284 return sema.tupleFieldPtr(block, indexable_src, indexable, elem_index_src, index, false);
26285 },26285 },
26286 else => unreachable, // Guaranteed by checkIndexable26286 else => unreachable, // Guaranteed by checkIndexable
...@@ -26318,7 +26318,7 @@ fn elemVal(...@@ -26318,7 +26318,7 @@ fn elemVal(
26318 const runtime_src = rs: {26318 const runtime_src = rs: {
26319 const indexable_val = maybe_indexable_val orelse break :rs indexable_src;26319 const indexable_val = maybe_indexable_val orelse break :rs indexable_src;
26320 const index_val = maybe_index_val orelse break :rs elem_index_src;26320 const index_val = maybe_index_val orelse break :rs elem_index_src;
26321 const index = @intCast(usize, index_val.toUnsignedInt(mod));26321 const index = @as(usize, @intCast(index_val.toUnsignedInt(mod)));
26322 const elem_ty = indexable_ty.elemType2(mod);26322 const elem_ty = indexable_ty.elemType2(mod);
26323 const many_ptr_ty = try mod.manyConstPtrType(elem_ty);26323 const many_ptr_ty = try mod.manyConstPtrType(elem_ty);
26324 const many_ptr_val = try mod.getCoerced(indexable_val, many_ptr_ty);26324 const many_ptr_val = try mod.getCoerced(indexable_val, many_ptr_ty);
...@@ -26355,7 +26355,7 @@ fn elemVal(...@@ -26355,7 +26355,7 @@ fn elemVal(
26355 .Struct => {26355 .Struct => {
26356 // Tuple field access.26356 // Tuple field access.
26357 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known");26357 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known");
26358 const index = @intCast(u32, index_val.toUnsignedInt(mod));26358 const index = @as(u32, @intCast(index_val.toUnsignedInt(mod)));
26359 return sema.tupleField(block, indexable_src, indexable, elem_index_src, index);26359 return sema.tupleField(block, indexable_src, indexable, elem_index_src, index);
26360 },26360 },
26361 else => unreachable,26361 else => unreachable,
...@@ -26516,7 +26516,7 @@ fn elemValArray(...@@ -26516,7 +26516,7 @@ fn elemValArray(
26516 const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index);26516 const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index);
2651726517
26518 if (maybe_index_val) |index_val| {26518 if (maybe_index_val) |index_val| {
26519 const index = @intCast(usize, index_val.toUnsignedInt(mod));26519 const index = @as(usize, @intCast(index_val.toUnsignedInt(mod)));
26520 if (array_sent) |s| {26520 if (array_sent) |s| {
26521 if (index == array_len) {26521 if (index == array_len) {
26522 return sema.addConstant(s);26522 return sema.addConstant(s);
...@@ -26532,7 +26532,7 @@ fn elemValArray(...@@ -26532,7 +26532,7 @@ fn elemValArray(
26532 return sema.addConstUndef(elem_ty);26532 return sema.addConstUndef(elem_ty);
26533 }26533 }
26534 if (maybe_index_val) |index_val| {26534 if (maybe_index_val) |index_val| {
26535 const index = @intCast(usize, index_val.toUnsignedInt(mod));26535 const index = @as(usize, @intCast(index_val.toUnsignedInt(mod)));
26536 const elem_val = try array_val.elemValue(mod, index);26536 const elem_val = try array_val.elemValue(mod, index);
26537 return sema.addConstant(elem_val);26537 return sema.addConstant(elem_val);
26538 }26538 }
...@@ -26644,7 +26644,7 @@ fn elemValSlice(...@@ -26644,7 +26644,7 @@ fn elemValSlice(
26644 return sema.fail(block, slice_src, "indexing into empty slice is not allowed", .{});26644 return sema.fail(block, slice_src, "indexing into empty slice is not allowed", .{});
26645 }26645 }
26646 if (maybe_index_val) |index_val| {26646 if (maybe_index_val) |index_val| {
26647 const index = @intCast(usize, index_val.toUnsignedInt(mod));26647 const index = @as(usize, @intCast(index_val.toUnsignedInt(mod)));
26648 if (index >= slice_len_s) {26648 if (index >= slice_len_s) {
26649 const sentinel_label: []const u8 = if (slice_sent) " +1 (sentinel)" else "";26649 const sentinel_label: []const u8 = if (slice_sent) " +1 (sentinel)" else "";
26650 return sema.fail(block, elem_index_src, "index {d} outside slice of length {d}{s}", .{ index, slice_len, sentinel_label });26650 return sema.fail(block, elem_index_src, "index {d} outside slice of length {d}{s}", .{ index, slice_len, sentinel_label });
...@@ -27287,7 +27287,7 @@ fn coerceExtra(...@@ -27287,7 +27287,7 @@ fn coerceExtra(
27287 return sema.failWithOwnedErrorMsg(msg);27287 return sema.failWithOwnedErrorMsg(msg);
27288 };27288 };
27289 return sema.addConstant(27289 return sema.addConstant(
27290 try mod.enumValueFieldIndex(dest_ty, @intCast(u32, field_index)),27290 try mod.enumValueFieldIndex(dest_ty, @as(u32, @intCast(field_index))),
27291 );27291 );
27292 },27292 },
27293 .Union => blk: {27293 .Union => blk: {
...@@ -27692,8 +27692,8 @@ const InMemoryCoercionResult = union(enum) {...@@ -27692,8 +27692,8 @@ const InMemoryCoercionResult = union(enum) {
27692 var index: u6 = 0;27692 var index: u6 = 0;
27693 var actual_noalias = false;27693 var actual_noalias = false;
27694 while (true) : (index += 1) {27694 while (true) : (index += 1) {
27695 const actual = @truncate(u1, param.actual >> index);27695 const actual = @as(u1, @truncate(param.actual >> index));
27696 const wanted = @truncate(u1, param.wanted >> index);27696 const wanted = @as(u1, @truncate(param.wanted >> index));
27697 if (actual != wanted) {27697 if (actual != wanted) {
27698 actual_noalias = actual == 1;27698 actual_noalias = actual == 1;
27699 break;27699 break;
...@@ -28218,7 +28218,7 @@ fn coerceInMemoryAllowedFns(...@@ -28218,7 +28218,7 @@ fn coerceInMemoryAllowedFns(
28218 const dest_param_ty = dest_info.param_types[param_i].toType();28218 const dest_param_ty = dest_info.param_types[param_i].toType();
28219 const src_param_ty = src_info.param_types[param_i].toType();28219 const src_param_ty = src_info.param_types[param_i].toType();
2822028220
28221 const param_i_small = @intCast(u5, param_i);28221 const param_i_small = @as(u5, @intCast(param_i));
28222 if (dest_info.paramIsComptime(param_i_small) != src_info.paramIsComptime(param_i_small)) {28222 if (dest_info.paramIsComptime(param_i_small) != src_info.paramIsComptime(param_i_small)) {
28223 return InMemoryCoercionResult{ .fn_param_comptime = .{28223 return InMemoryCoercionResult{ .fn_param_comptime = .{
28224 .index = param_i,28224 .index = param_i,
...@@ -28832,7 +28832,7 @@ fn beginComptimePtrMutation(...@@ -28832,7 +28832,7 @@ fn beginComptimePtrMutation(
28832 // bytes.len may be one greater than dest_len because of the case when28832 // bytes.len may be one greater than dest_len because of the case when
28833 // assigning `[N:S]T` to `[N]T`. This is allowed; the sentinel is omitted.28833 // assigning `[N:S]T` to `[N]T`. This is allowed; the sentinel is omitted.
28834 assert(bytes.len >= dest_len);28834 assert(bytes.len >= dest_len);
28835 const elems = try arena.alloc(Value, @intCast(usize, dest_len));28835 const elems = try arena.alloc(Value, @as(usize, @intCast(dest_len)));
28836 for (elems, 0..) |*elem, i| {28836 for (elems, 0..) |*elem, i| {
28837 elem.* = try mod.intValue(elem_ty, bytes[i]);28837 elem.* = try mod.intValue(elem_ty, bytes[i]);
28838 }28838 }
...@@ -28844,7 +28844,7 @@ fn beginComptimePtrMutation(...@@ -28844,7 +28844,7 @@ fn beginComptimePtrMutation(
28844 block,28844 block,
28845 src,28845 src,
28846 elem_ty,28846 elem_ty,
28847 &elems[@intCast(usize, elem_ptr.index)],28847 &elems[@as(usize, @intCast(elem_ptr.index))],
28848 ptr_elem_ty,28848 ptr_elem_ty,
28849 parent.mut_decl,28849 parent.mut_decl,
28850 );28850 );
...@@ -28872,7 +28872,7 @@ fn beginComptimePtrMutation(...@@ -28872,7 +28872,7 @@ fn beginComptimePtrMutation(
28872 block,28872 block,
28873 src,28873 src,
28874 elem_ty,28874 elem_ty,
28875 &elems[@intCast(usize, elem_ptr.index)],28875 &elems[@as(usize, @intCast(elem_ptr.index))],
28876 ptr_elem_ty,28876 ptr_elem_ty,
28877 parent.mut_decl,28877 parent.mut_decl,
28878 );28878 );
...@@ -28883,7 +28883,7 @@ fn beginComptimePtrMutation(...@@ -28883,7 +28883,7 @@ fn beginComptimePtrMutation(
28883 block,28883 block,
28884 src,28884 src,
28885 elem_ty,28885 elem_ty,
28886 &val_ptr.castTag(.aggregate).?.data[@intCast(usize, elem_ptr.index)],28886 &val_ptr.castTag(.aggregate).?.data[@as(usize, @intCast(elem_ptr.index))],
28887 ptr_elem_ty,28887 ptr_elem_ty,
28888 parent.mut_decl,28888 parent.mut_decl,
28889 ),28889 ),
...@@ -28909,7 +28909,7 @@ fn beginComptimePtrMutation(...@@ -28909,7 +28909,7 @@ fn beginComptimePtrMutation(
28909 block,28909 block,
28910 src,28910 src,
28911 elem_ty,28911 elem_ty,
28912 &elems[@intCast(usize, elem_ptr.index)],28912 &elems[@as(usize, @intCast(elem_ptr.index))],
28913 ptr_elem_ty,28913 ptr_elem_ty,
28914 parent.mut_decl,28914 parent.mut_decl,
28915 );28915 );
...@@ -28964,7 +28964,7 @@ fn beginComptimePtrMutation(...@@ -28964,7 +28964,7 @@ fn beginComptimePtrMutation(
28964 },28964 },
28965 .field => |field_ptr| {28965 .field => |field_ptr| {
28966 const base_child_ty = mod.intern_pool.typeOf(field_ptr.base).toType().childType(mod);28966 const base_child_ty = mod.intern_pool.typeOf(field_ptr.base).toType().childType(mod);
28967 const field_index = @intCast(u32, field_ptr.index);28967 const field_index = @as(u32, @intCast(field_ptr.index));
2896828968
28969 var parent = try sema.beginComptimePtrMutation(block, src, field_ptr.base.toValue(), base_child_ty);28969 var parent = try sema.beginComptimePtrMutation(block, src, field_ptr.base.toValue(), base_child_ty);
28970 switch (parent.pointee) {28970 switch (parent.pointee) {
...@@ -29401,12 +29401,12 @@ fn beginComptimePtrLoad(...@@ -29401,12 +29401,12 @@ fn beginComptimePtrLoad(
29401 }29401 }
29402 deref.pointee = TypedValue{29402 deref.pointee = TypedValue{
29403 .ty = elem_ty,29403 .ty = elem_ty,
29404 .val = try array_tv.val.elemValue(mod, @intCast(usize, elem_ptr.index)),29404 .val = try array_tv.val.elemValue(mod, @as(usize, @intCast(elem_ptr.index))),
29405 };29405 };
29406 break :blk deref;29406 break :blk deref;
29407 },29407 },
29408 .field => |field_ptr| blk: {29408 .field => |field_ptr| blk: {
29409 const field_index = @intCast(u32, field_ptr.index);29409 const field_index = @as(u32, @intCast(field_ptr.index));
29410 const container_ty = mod.intern_pool.typeOf(field_ptr.base).toType().childType(mod);29410 const container_ty = mod.intern_pool.typeOf(field_ptr.base).toType().childType(mod);
29411 var deref = try sema.beginComptimePtrLoad(block, src, field_ptr.base.toValue(), container_ty);29411 var deref = try sema.beginComptimePtrLoad(block, src, field_ptr.base.toValue(), container_ty);
2941229412
...@@ -29990,7 +29990,7 @@ fn coerceTupleToArray(...@@ -29990,7 +29990,7 @@ fn coerceTupleToArray(
2999029990
29991 var runtime_src: ?LazySrcLoc = null;29991 var runtime_src: ?LazySrcLoc = null;
29992 for (element_vals, element_refs, 0..) |*val, *ref, i_usize| {29992 for (element_vals, element_refs, 0..) |*val, *ref, i_usize| {
29993 const i = @intCast(u32, i_usize);29993 const i = @as(u32, @intCast(i_usize));
29994 if (i_usize == inst_len) {29994 if (i_usize == inst_len) {
29995 const sentinel_val = dest_ty.sentinel(mod).?;29995 const sentinel_val = dest_ty.sentinel(mod).?;
29996 val.* = sentinel_val.toIntern();29996 val.* = sentinel_val.toIntern();
...@@ -30101,7 +30101,7 @@ fn coerceTupleToStruct(...@@ -30101,7 +30101,7 @@ fn coerceTupleToStruct(
30101 else => unreachable,30101 else => unreachable,
30102 };30102 };
30103 for (0..field_count) |field_index_usize| {30103 for (0..field_count) |field_index_usize| {
30104 const field_i = @intCast(u32, field_index_usize);30104 const field_i = @as(u32, @intCast(field_index_usize));
30105 const field_src = inst_src; // TODO better source location30105 const field_src = inst_src; // TODO better source location
30106 // https://github.com/ziglang/zig/issues/1570930106 // https://github.com/ziglang/zig/issues/15709
30107 const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) {30107 const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) {
...@@ -30217,7 +30217,7 @@ fn coerceTupleToTuple(...@@ -30217,7 +30217,7 @@ fn coerceTupleToTuple(
3021730217
30218 var runtime_src: ?LazySrcLoc = null;30218 var runtime_src: ?LazySrcLoc = null;
30219 for (0..dest_field_count) |field_index_usize| {30219 for (0..dest_field_count) |field_index_usize| {
30220 const field_i = @intCast(u32, field_index_usize);30220 const field_i = @as(u32, @intCast(field_index_usize));
30221 const field_src = inst_src; // TODO better source location30221 const field_src = inst_src; // TODO better source location
30222 // https://github.com/ziglang/zig/issues/1570930222 // https://github.com/ziglang/zig/issues/15709
30223 const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) {30223 const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) {
...@@ -31532,7 +31532,7 @@ fn compareIntsOnlyPossibleResult(...@@ -31532,7 +31532,7 @@ fn compareIntsOnlyPossibleResult(
3153231532
31533 const ty = try mod.intType(31533 const ty = try mod.intType(
31534 if (is_negative) .signed else .unsigned,31534 if (is_negative) .signed else .unsigned,
31535 @intCast(u16, req_bits),31535 @as(u16, @intCast(req_bits)),
31536 );31536 );
31537 const pop_count = lhs_val.popCount(ty, mod);31537 const pop_count = lhs_val.popCount(ty, mod);
3153831538
...@@ -32294,7 +32294,7 @@ fn resolvePeerTypesInner(...@@ -32294,7 +32294,7 @@ fn resolvePeerTypesInner(
32294 };32294 };
3229532295
32296 return .{ .success = try mod.vectorType(.{32296 return .{ .success = try mod.vectorType(.{
32297 .len = @intCast(u32, len.?),32297 .len = @as(u32, @intCast(len.?)),
32298 .child = child_ty.toIntern(),32298 .child = child_ty.toIntern(),
32299 }) };32299 }) };
32300 },32300 },
...@@ -33402,7 +33402,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -33402,7 +33402,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
3340233402
33403 for (struct_obj.fields.values(), 0..) |field, i| {33403 for (struct_obj.fields.values(), 0..) |field, i| {
33404 optimized_order[i] = if (try sema.typeHasRuntimeBits(field.ty))33404 optimized_order[i] = if (try sema.typeHasRuntimeBits(field.ty))
33405 @intCast(u32, i)33405 @as(u32, @intCast(i))
33406 else33406 else
33407 Module.Struct.omitted_field;33407 Module.Struct.omitted_field;
33408 }33408 }
...@@ -33443,7 +33443,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi...@@ -33443,7 +33443,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
33443 const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir;33443 const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir;
33444 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;33444 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;
33445 assert(extended.opcode == .struct_decl);33445 assert(extended.opcode == .struct_decl);
33446 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);33446 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
3344733447
33448 if (small.has_backing_int) {33448 if (small.has_backing_int) {
33449 var extra_index: usize = extended.operand;33449 var extra_index: usize = extended.operand;
...@@ -33497,7 +33497,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi...@@ -33497,7 +33497,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
33497 const backing_int_src: LazySrcLoc = .{ .node_offset_container_tag = 0 };33497 const backing_int_src: LazySrcLoc = .{ .node_offset_container_tag = 0 };
33498 const backing_int_ty = blk: {33498 const backing_int_ty = blk: {
33499 if (backing_int_body_len == 0) {33499 if (backing_int_body_len == 0) {
33500 const backing_int_ref = @enumFromInt(Zir.Inst.Ref, zir.extra[extra_index]);33500 const backing_int_ref = @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index]));
33501 break :blk try sema.resolveType(&block, backing_int_src, backing_int_ref);33501 break :blk try sema.resolveType(&block, backing_int_src, backing_int_ref);
33502 } else {33502 } else {
33503 const body = zir.extra[extra_index..][0..backing_int_body_len];33503 const body = zir.extra[extra_index..][0..backing_int_body_len];
...@@ -33543,7 +33543,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi...@@ -33543,7 +33543,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
33543 };33543 };
33544 return sema.fail(&block, LazySrcLoc.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});33544 return sema.fail(&block, LazySrcLoc.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});
33545 }33545 }
33546 struct_obj.backing_int_ty = try mod.intType(.unsigned, @intCast(u16, fields_bit_sum));33546 struct_obj.backing_int_ty = try mod.intType(.unsigned, @as(u16, @intCast(fields_bit_sum)));
33547 }33547 }
33548}33548}
3354933549
...@@ -34178,7 +34178,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void...@@ -34178,7 +34178,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
34178 const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir;34178 const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir;
34179 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;34179 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;
34180 assert(extended.opcode == .struct_decl);34180 assert(extended.opcode == .struct_decl);
34181 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);34181 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
34182 var extra_index: usize = extended.operand;34182 var extra_index: usize = extended.operand;
3418334183
34184 const src = LazySrcLoc.nodeOffset(0);34184 const src = LazySrcLoc.nodeOffset(0);
...@@ -34288,13 +34288,13 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void...@@ -34288,13 +34288,13 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
34288 cur_bit_bag = zir.extra[bit_bag_index];34288 cur_bit_bag = zir.extra[bit_bag_index];
34289 bit_bag_index += 1;34289 bit_bag_index += 1;
34290 }34290 }
34291 const has_align = @truncate(u1, cur_bit_bag) != 0;34291 const has_align = @as(u1, @truncate(cur_bit_bag)) != 0;
34292 cur_bit_bag >>= 1;34292 cur_bit_bag >>= 1;
34293 const has_init = @truncate(u1, cur_bit_bag) != 0;34293 const has_init = @as(u1, @truncate(cur_bit_bag)) != 0;
34294 cur_bit_bag >>= 1;34294 cur_bit_bag >>= 1;
34295 const is_comptime = @truncate(u1, cur_bit_bag) != 0;34295 const is_comptime = @as(u1, @truncate(cur_bit_bag)) != 0;
34296 cur_bit_bag >>= 1;34296 cur_bit_bag >>= 1;
34297 const has_type_body = @truncate(u1, cur_bit_bag) != 0;34297 const has_type_body = @as(u1, @truncate(cur_bit_bag)) != 0;
34298 cur_bit_bag >>= 1;34298 cur_bit_bag >>= 1;
3429934299
34300 var field_name_zir: ?[:0]const u8 = null;34300 var field_name_zir: ?[:0]const u8 = null;
...@@ -34309,7 +34309,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void...@@ -34309,7 +34309,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
34309 if (has_type_body) {34309 if (has_type_body) {
34310 fields[field_i].type_body_len = zir.extra[extra_index];34310 fields[field_i].type_body_len = zir.extra[extra_index];
34311 } else {34311 } else {
34312 fields[field_i].type_ref = @enumFromInt(Zir.Inst.Ref, zir.extra[extra_index]);34312 fields[field_i].type_ref = @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index]));
34313 }34313 }
34314 extra_index += 1;34314 extra_index += 1;
3431534315
...@@ -34529,14 +34529,14 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {...@@ -34529,14 +34529,14 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
34529 const zir = mod.namespacePtr(union_obj.namespace).file_scope.zir;34529 const zir = mod.namespacePtr(union_obj.namespace).file_scope.zir;
34530 const extended = zir.instructions.items(.data)[union_obj.zir_index].extended;34530 const extended = zir.instructions.items(.data)[union_obj.zir_index].extended;
34531 assert(extended.opcode == .union_decl);34531 assert(extended.opcode == .union_decl);
34532 const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small);34532 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));
34533 var extra_index: usize = extended.operand;34533 var extra_index: usize = extended.operand;
3453434534
34535 const src = LazySrcLoc.nodeOffset(0);34535 const src = LazySrcLoc.nodeOffset(0);
34536 extra_index += @intFromBool(small.has_src_node);34536 extra_index += @intFromBool(small.has_src_node);
3453734537
34538 const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: {34538 const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: {
34539 const ty_ref = @enumFromInt(Zir.Inst.Ref, zir.extra[extra_index]);34539 const ty_ref = @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index]));
34540 extra_index += 1;34540 extra_index += 1;
34541 break :blk ty_ref;34541 break :blk ty_ref;
34542 } else .none;34542 } else .none;
...@@ -34684,13 +34684,13 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {...@@ -34684,13 +34684,13 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
34684 cur_bit_bag = zir.extra[bit_bag_index];34684 cur_bit_bag = zir.extra[bit_bag_index];
34685 bit_bag_index += 1;34685 bit_bag_index += 1;
34686 }34686 }
34687 const has_type = @truncate(u1, cur_bit_bag) != 0;34687 const has_type = @as(u1, @truncate(cur_bit_bag)) != 0;
34688 cur_bit_bag >>= 1;34688 cur_bit_bag >>= 1;
34689 const has_align = @truncate(u1, cur_bit_bag) != 0;34689 const has_align = @as(u1, @truncate(cur_bit_bag)) != 0;
34690 cur_bit_bag >>= 1;34690 cur_bit_bag >>= 1;
34691 const has_tag = @truncate(u1, cur_bit_bag) != 0;34691 const has_tag = @as(u1, @truncate(cur_bit_bag)) != 0;
34692 cur_bit_bag >>= 1;34692 cur_bit_bag >>= 1;
34693 const unused = @truncate(u1, cur_bit_bag) != 0;34693 const unused = @as(u1, @truncate(cur_bit_bag)) != 0;
34694 cur_bit_bag >>= 1;34694 cur_bit_bag >>= 1;
34695 _ = unused;34695 _ = unused;
3469634696
...@@ -34701,19 +34701,19 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {...@@ -34701,19 +34701,19 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
34701 extra_index += 1;34701 extra_index += 1;
3470234702
34703 const field_type_ref: Zir.Inst.Ref = if (has_type) blk: {34703 const field_type_ref: Zir.Inst.Ref = if (has_type) blk: {
34704 const field_type_ref = @enumFromInt(Zir.Inst.Ref, zir.extra[extra_index]);34704 const field_type_ref = @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index]));
34705 extra_index += 1;34705 extra_index += 1;
34706 break :blk field_type_ref;34706 break :blk field_type_ref;
34707 } else .none;34707 } else .none;
3470834708
34709 const align_ref: Zir.Inst.Ref = if (has_align) blk: {34709 const align_ref: Zir.Inst.Ref = if (has_align) blk: {
34710 const align_ref = @enumFromInt(Zir.Inst.Ref, zir.extra[extra_index]);34710 const align_ref = @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index]));
34711 extra_index += 1;34711 extra_index += 1;
34712 break :blk align_ref;34712 break :blk align_ref;
34713 } else .none;34713 } else .none;
3471434714
34715 const tag_ref: Air.Inst.Ref = if (has_tag) blk: {34715 const tag_ref: Air.Inst.Ref = if (has_tag) blk: {
34716 const tag_ref = @enumFromInt(Zir.Inst.Ref, zir.extra[extra_index]);34716 const tag_ref = @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index]));
34717 extra_index += 1;34717 extra_index += 1;
34718 break :blk try sema.resolveInst(tag_ref);34718 break :blk try sema.resolveInst(tag_ref);
34719 } else .none;34719 } else .none;
...@@ -35427,12 +35427,12 @@ pub fn getTmpAir(sema: Sema) Air {...@@ -35427,12 +35427,12 @@ pub fn getTmpAir(sema: Sema) Air {
3542735427
35428pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {35428pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
35429 if (@intFromEnum(ty.toIntern()) < Air.ref_start_index)35429 if (@intFromEnum(ty.toIntern()) < Air.ref_start_index)
35430 return @enumFromInt(Air.Inst.Ref, @intFromEnum(ty.toIntern()));35430 return @as(Air.Inst.Ref, @enumFromInt(@intFromEnum(ty.toIntern())));
35431 try sema.air_instructions.append(sema.gpa, .{35431 try sema.air_instructions.append(sema.gpa, .{
35432 .tag = .interned,35432 .tag = .interned,
35433 .data = .{ .interned = ty.toIntern() },35433 .data = .{ .interned = ty.toIntern() },
35434 });35434 });
35435 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));35435 return Air.indexToRef(@as(u32, @intCast(sema.air_instructions.len - 1)));
35436}35436}
3543735437
35438fn addIntUnsigned(sema: *Sema, ty: Type, int: u64) CompileError!Air.Inst.Ref {35438fn addIntUnsigned(sema: *Sema, ty: Type, int: u64) CompileError!Air.Inst.Ref {
...@@ -35446,12 +35446,12 @@ fn addConstUndef(sema: *Sema, ty: Type) CompileError!Air.Inst.Ref {...@@ -35446,12 +35446,12 @@ fn addConstUndef(sema: *Sema, ty: Type) CompileError!Air.Inst.Ref {
3544635446
35447pub fn addConstant(sema: *Sema, val: Value) SemaError!Air.Inst.Ref {35447pub fn addConstant(sema: *Sema, val: Value) SemaError!Air.Inst.Ref {
35448 if (@intFromEnum(val.toIntern()) < Air.ref_start_index)35448 if (@intFromEnum(val.toIntern()) < Air.ref_start_index)
35449 return @enumFromInt(Air.Inst.Ref, @intFromEnum(val.toIntern()));35449 return @as(Air.Inst.Ref, @enumFromInt(@intFromEnum(val.toIntern())));
35450 try sema.air_instructions.append(sema.gpa, .{35450 try sema.air_instructions.append(sema.gpa, .{
35451 .tag = .interned,35451 .tag = .interned,
35452 .data = .{ .interned = val.toIntern() },35452 .data = .{ .interned = val.toIntern() },
35453 });35453 });
35454 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));35454 return Air.indexToRef(@as(u32, @intCast(sema.air_instructions.len - 1)));
35455}35455}
3545635456
35457pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 {35457pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 {
...@@ -35462,12 +35462,12 @@ pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 {...@@ -35462,12 +35462,12 @@ pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 {
3546235462
35463pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 {35463pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 {
35464 const fields = std.meta.fields(@TypeOf(extra));35464 const fields = std.meta.fields(@TypeOf(extra));
35465 const result = @intCast(u32, sema.air_extra.items.len);35465 const result = @as(u32, @intCast(sema.air_extra.items.len));
35466 inline for (fields) |field| {35466 inline for (fields) |field| {
35467 sema.air_extra.appendAssumeCapacity(switch (field.type) {35467 sema.air_extra.appendAssumeCapacity(switch (field.type) {
35468 u32 => @field(extra, field.name),35468 u32 => @field(extra, field.name),
35469 Air.Inst.Ref => @intFromEnum(@field(extra, field.name)),35469 Air.Inst.Ref => @intFromEnum(@field(extra, field.name)),
35470 i32 => @bitCast(u32, @field(extra, field.name)),35470 i32 => @as(u32, @bitCast(@field(extra, field.name))),
35471 InternPool.Index => @intFromEnum(@field(extra, field.name)),35471 InternPool.Index => @intFromEnum(@field(extra, field.name)),
35472 else => @compileError("bad field type: " ++ @typeName(field.type)),35472 else => @compileError("bad field type: " ++ @typeName(field.type)),
35473 });35473 });
...@@ -35476,7 +35476,7 @@ pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 {...@@ -35476,7 +35476,7 @@ pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 {
35476}35476}
3547735477
35478fn appendRefsAssumeCapacity(sema: *Sema, refs: []const Air.Inst.Ref) void {35478fn appendRefsAssumeCapacity(sema: *Sema, refs: []const Air.Inst.Ref) void {
35479 const coerced = @ptrCast([]const u32, refs);35479 const coerced = @as([]const u32, @ptrCast(refs));
35480 sema.air_extra.appendSliceAssumeCapacity(coerced);35480 sema.air_extra.appendSliceAssumeCapacity(coerced);
35481}35481}
3548235482
...@@ -35916,10 +35916,10 @@ fn typeAbiAlignment(sema: *Sema, ty: Type) CompileError!u32 {...@@ -35916,10 +35916,10 @@ fn typeAbiAlignment(sema: *Sema, ty: Type) CompileError!u32 {
35916/// Not valid to call for packed unions.35916/// Not valid to call for packed unions.
35917/// Keep implementation in sync with `Module.Union.Field.normalAlignment`.35917/// Keep implementation in sync with `Module.Union.Field.normalAlignment`.
35918fn unionFieldAlignment(sema: *Sema, field: Module.Union.Field) !u32 {35918fn unionFieldAlignment(sema: *Sema, field: Module.Union.Field) !u32 {
35919 return @intCast(u32, if (field.ty.isNoReturn(sema.mod))35919 return @as(u32, @intCast(if (field.ty.isNoReturn(sema.mod))
35920 035920 0
35921 else35921 else
35922 field.abi_align.toByteUnitsOptional() orelse try sema.typeAbiAlignment(field.ty));35922 field.abi_align.toByteUnitsOptional() orelse try sema.typeAbiAlignment(field.ty)));
35923}35923}
3592435924
35925/// Synchronize logic with `Type.isFnOrHasRuntimeBits`.35925/// Synchronize logic with `Type.isFnOrHasRuntimeBits`.
...@@ -35951,7 +35951,7 @@ fn unionFieldIndex(...@@ -35951,7 +35951,7 @@ fn unionFieldIndex(
35951 const union_obj = mod.typeToUnion(union_ty).?;35951 const union_obj = mod.typeToUnion(union_ty).?;
35952 const field_index_usize = union_obj.fields.getIndex(field_name) orelse35952 const field_index_usize = union_obj.fields.getIndex(field_name) orelse
35953 return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name);35953 return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name);
35954 return @intCast(u32, field_index_usize);35954 return @as(u32, @intCast(field_index_usize));
35955}35955}
3595635956
35957fn structFieldIndex(35957fn structFieldIndex(
...@@ -35969,7 +35969,7 @@ fn structFieldIndex(...@@ -35969,7 +35969,7 @@ fn structFieldIndex(
35969 const struct_obj = mod.typeToStruct(struct_ty).?;35969 const struct_obj = mod.typeToStruct(struct_ty).?;
35970 const field_index_usize = struct_obj.fields.getIndex(field_name) orelse35970 const field_index_usize = struct_obj.fields.getIndex(field_name) orelse
35971 return sema.failWithBadStructFieldAccess(block, struct_obj, field_src, field_name);35971 return sema.failWithBadStructFieldAccess(block, struct_obj, field_src, field_name);
35972 return @intCast(u32, field_index_usize);35972 return @as(u32, @intCast(field_index_usize));
35973 }35973 }
35974}35974}
3597535975
...@@ -35983,12 +35983,12 @@ fn anonStructFieldIndex(...@@ -35983,12 +35983,12 @@ fn anonStructFieldIndex(
35983 const mod = sema.mod;35983 const mod = sema.mod;
35984 switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) {35984 switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) {
35985 .anon_struct_type => |anon_struct_type| for (anon_struct_type.names, 0..) |name, i| {35985 .anon_struct_type => |anon_struct_type| for (anon_struct_type.names, 0..) |name, i| {
35986 if (name == field_name) return @intCast(u32, i);35986 if (name == field_name) return @as(u32, @intCast(i));
35987 },35987 },
35988 .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| {35988 .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| {
35989 for (struct_obj.fields.keys(), 0..) |name, i| {35989 for (struct_obj.fields.keys(), 0..) |name, i| {
35990 if (name == field_name) {35990 if (name == field_name) {
35991 return @intCast(u32, i);35991 return @as(u32, @intCast(i));
35992 }35992 }
35993 }35993 }
35994 },35994 },
...@@ -36586,9 +36586,9 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {...@@ -36586,9 +36586,9 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {
36586 if (!is_packed) break :blk .{};36586 if (!is_packed) break :blk .{};
3658736587
36588 break :blk .{36588 break :blk .{
36589 .host_size = @intCast(u16, parent_ty.arrayLen(mod)),36589 .host_size = @as(u16, @intCast(parent_ty.arrayLen(mod))),
36590 .alignment = @intCast(u32, parent_ty.abiAlignment(mod)),36590 .alignment = @as(u32, @intCast(parent_ty.abiAlignment(mod))),
36591 .vector_index = if (offset) |some| @enumFromInt(VI, some) else .runtime,36591 .vector_index = if (offset) |some| @as(VI, @enumFromInt(some)) else .runtime,
36592 };36592 };
36593 } else .{};36593 } else .{};
3659436594
...@@ -36607,10 +36607,10 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {...@@ -36607,10 +36607,10 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {
36607 // The resulting pointer is aligned to the lcd between the offset (an36607 // The resulting pointer is aligned to the lcd between the offset (an
36608 // arbitrary number) and the alignment factor (always a power of two,36608 // arbitrary number) and the alignment factor (always a power of two,
36609 // non zero).36609 // non zero).
36610 const new_align = @enumFromInt(Alignment, @min(36610 const new_align = @as(Alignment, @enumFromInt(@min(
36611 @ctz(addend),36611 @ctz(addend),
36612 @intFromEnum(ptr_info.flags.alignment),36612 @intFromEnum(ptr_info.flags.alignment),
36613 ));36613 )));
36614 assert(new_align != .none);36614 assert(new_align != .none);
36615 break :a new_align;36615 break :a new_align;
36616 };36616 };
src/TypedValue.zig+4-4
...@@ -250,7 +250,7 @@ pub fn print(...@@ -250,7 +250,7 @@ pub fn print(
250 },250 },
251 .empty_enum_value => return writer.writeAll("(empty enum value)"),251 .empty_enum_value => return writer.writeAll("(empty enum value)"),
252 .float => |float| switch (float.storage) {252 .float => |float| switch (float.storage) {
253 inline else => |x| return writer.print("{d}", .{@floatCast(f64, x)}),253 inline else => |x| return writer.print("{d}", .{@as(f64, @floatCast(x))}),
254 },254 },
255 .ptr => |ptr| {255 .ptr => |ptr| {
256 if (ptr.addr == .int) {256 if (ptr.addr == .int) {
...@@ -273,7 +273,7 @@ pub fn print(...@@ -273,7 +273,7 @@ pub fn print(
273 for (buf[0..max_len], 0..) |*c, i| {273 for (buf[0..max_len], 0..) |*c, i| {
274 const elem = try val.elemValue(mod, i);274 const elem = try val.elemValue(mod, i);
275 if (elem.isUndef(mod)) break :str;275 if (elem.isUndef(mod)) break :str;
276 c.* = @intCast(u8, elem.toUnsignedInt(mod));276 c.* = @as(u8, @intCast(elem.toUnsignedInt(mod)));
277 }277 }
278 const truncated = if (len > max_string_len) " (truncated)" else "";278 const truncated = if (len > max_string_len) " (truncated)" else "";
279 return writer.print("\"{}{s}\"", .{ std.zig.fmtEscapes(buf[0..max_len]), truncated });279 return writer.print("\"{}{s}\"", .{ std.zig.fmtEscapes(buf[0..max_len]), truncated });
...@@ -352,11 +352,11 @@ pub fn print(...@@ -352,11 +352,11 @@ pub fn print(
352 if (container_ty.isTuple(mod)) {352 if (container_ty.isTuple(mod)) {
353 try writer.print("[{d}]", .{field.index});353 try writer.print("[{d}]", .{field.index});
354 }354 }
355 const field_name = container_ty.structFieldName(@intCast(usize, field.index), mod);355 const field_name = container_ty.structFieldName(@as(usize, @intCast(field.index)), mod);
356 try writer.print(".{i}", .{field_name.fmt(ip)});356 try writer.print(".{i}", .{field_name.fmt(ip)});
357 },357 },
358 .Union => {358 .Union => {
359 const field_name = container_ty.unionFields(mod).keys()[@intCast(usize, field.index)];359 const field_name = container_ty.unionFields(mod).keys()[@as(usize, @intCast(field.index))];
360 try writer.print(".{i}", .{field_name.fmt(ip)});360 try writer.print(".{i}", .{field_name.fmt(ip)});
361 },361 },
362 .Pointer => {362 .Pointer => {
src/Zir.zig+22-22
...@@ -74,12 +74,12 @@ pub fn extraData(code: Zir, comptime T: type, index: usize) struct { data: T, en...@@ -74,12 +74,12 @@ pub fn extraData(code: Zir, comptime T: type, index: usize) struct { data: T, en
74 inline for (fields) |field| {74 inline for (fields) |field| {
75 @field(result, field.name) = switch (field.type) {75 @field(result, field.name) = switch (field.type) {
76 u32 => code.extra[i],76 u32 => code.extra[i],
77 Inst.Ref => @enumFromInt(Inst.Ref, code.extra[i]),77 Inst.Ref => @as(Inst.Ref, @enumFromInt(code.extra[i])),
78 i32 => @bitCast(i32, code.extra[i]),78 i32 => @as(i32, @bitCast(code.extra[i])),
79 Inst.Call.Flags => @bitCast(Inst.Call.Flags, code.extra[i]),79 Inst.Call.Flags => @as(Inst.Call.Flags, @bitCast(code.extra[i])),
80 Inst.BuiltinCall.Flags => @bitCast(Inst.BuiltinCall.Flags, code.extra[i]),80 Inst.BuiltinCall.Flags => @as(Inst.BuiltinCall.Flags, @bitCast(code.extra[i])),
81 Inst.SwitchBlock.Bits => @bitCast(Inst.SwitchBlock.Bits, code.extra[i]),81 Inst.SwitchBlock.Bits => @as(Inst.SwitchBlock.Bits, @bitCast(code.extra[i])),
82 Inst.FuncFancy.Bits => @bitCast(Inst.FuncFancy.Bits, code.extra[i]),82 Inst.FuncFancy.Bits => @as(Inst.FuncFancy.Bits, @bitCast(code.extra[i])),
83 else => @compileError("bad field type"),83 else => @compileError("bad field type"),
84 };84 };
85 i += 1;85 i += 1;
...@@ -101,7 +101,7 @@ pub fn nullTerminatedString(code: Zir, index: usize) [:0]const u8 {...@@ -101,7 +101,7 @@ pub fn nullTerminatedString(code: Zir, index: usize) [:0]const u8 {
101101
102pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {102pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {
103 const raw_slice = code.extra[start..][0..len];103 const raw_slice = code.extra[start..][0..len];
104 return @ptrCast([]Inst.Ref, raw_slice);104 return @as([]Inst.Ref, @ptrCast(raw_slice));
105}105}
106106
107pub fn hasCompileErrors(code: Zir) bool {107pub fn hasCompileErrors(code: Zir) bool {
...@@ -2992,7 +2992,7 @@ pub const Inst = struct {...@@ -2992,7 +2992,7 @@ pub const Inst = struct {
2992 (@as(u128, self.piece1) << 32) |2992 (@as(u128, self.piece1) << 32) |
2993 (@as(u128, self.piece2) << 64) |2993 (@as(u128, self.piece2) << 64) |
2994 (@as(u128, self.piece3) << 96);2994 (@as(u128, self.piece3) << 96);
2995 return @bitCast(f128, int_bits);2995 return @as(f128, @bitCast(int_bits));
2996 }2996 }
2997 };2997 };
29982998
...@@ -3228,15 +3228,15 @@ pub const DeclIterator = struct {...@@ -3228,15 +3228,15 @@ pub const DeclIterator = struct {
3228 }3228 }
3229 it.decl_i += 1;3229 it.decl_i += 1;
32303230
3231 const flags = @truncate(u4, it.cur_bit_bag);3231 const flags = @as(u4, @truncate(it.cur_bit_bag));
3232 it.cur_bit_bag >>= 4;3232 it.cur_bit_bag >>= 4;
32333233
3234 const sub_index = @intCast(u32, it.extra_index);3234 const sub_index = @as(u32, @intCast(it.extra_index));
3235 it.extra_index += 5; // src_hash(4) + line(1)3235 it.extra_index += 5; // src_hash(4) + line(1)
3236 const name = it.zir.nullTerminatedString(it.zir.extra[it.extra_index]);3236 const name = it.zir.nullTerminatedString(it.zir.extra[it.extra_index]);
3237 it.extra_index += 3; // name(1) + value(1) + doc_comment(1)3237 it.extra_index += 3; // name(1) + value(1) + doc_comment(1)
3238 it.extra_index += @truncate(u1, flags >> 2);3238 it.extra_index += @as(u1, @truncate(flags >> 2));
3239 it.extra_index += @truncate(u1, flags >> 3);3239 it.extra_index += @as(u1, @truncate(flags >> 3));
32403240
3241 return Item{3241 return Item{
3242 .sub_index = sub_index,3242 .sub_index = sub_index,
...@@ -3258,7 +3258,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {...@@ -3258,7 +3258,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
3258 const extended = datas[decl_inst].extended;3258 const extended = datas[decl_inst].extended;
3259 switch (extended.opcode) {3259 switch (extended.opcode) {
3260 .struct_decl => {3260 .struct_decl => {
3261 const small = @bitCast(Inst.StructDecl.Small, extended.small);3261 const small = @as(Inst.StructDecl.Small, @bitCast(extended.small));
3262 var extra_index: usize = extended.operand;3262 var extra_index: usize = extended.operand;
3263 extra_index += @intFromBool(small.has_src_node);3263 extra_index += @intFromBool(small.has_src_node);
3264 extra_index += @intFromBool(small.has_fields_len);3264 extra_index += @intFromBool(small.has_fields_len);
...@@ -3281,7 +3281,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {...@@ -3281,7 +3281,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
3281 return declIteratorInner(zir, extra_index, decls_len);3281 return declIteratorInner(zir, extra_index, decls_len);
3282 },3282 },
3283 .enum_decl => {3283 .enum_decl => {
3284 const small = @bitCast(Inst.EnumDecl.Small, extended.small);3284 const small = @as(Inst.EnumDecl.Small, @bitCast(extended.small));
3285 var extra_index: usize = extended.operand;3285 var extra_index: usize = extended.operand;
3286 extra_index += @intFromBool(small.has_src_node);3286 extra_index += @intFromBool(small.has_src_node);
3287 extra_index += @intFromBool(small.has_tag_type);3287 extra_index += @intFromBool(small.has_tag_type);
...@@ -3296,7 +3296,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {...@@ -3296,7 +3296,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
3296 return declIteratorInner(zir, extra_index, decls_len);3296 return declIteratorInner(zir, extra_index, decls_len);
3297 },3297 },
3298 .union_decl => {3298 .union_decl => {
3299 const small = @bitCast(Inst.UnionDecl.Small, extended.small);3299 const small = @as(Inst.UnionDecl.Small, @bitCast(extended.small));
3300 var extra_index: usize = extended.operand;3300 var extra_index: usize = extended.operand;
3301 extra_index += @intFromBool(small.has_src_node);3301 extra_index += @intFromBool(small.has_src_node);
3302 extra_index += @intFromBool(small.has_tag_type);3302 extra_index += @intFromBool(small.has_tag_type);
...@@ -3311,7 +3311,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {...@@ -3311,7 +3311,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
3311 return declIteratorInner(zir, extra_index, decls_len);3311 return declIteratorInner(zir, extra_index, decls_len);
3312 },3312 },
3313 .opaque_decl => {3313 .opaque_decl => {
3314 const small = @bitCast(Inst.OpaqueDecl.Small, extended.small);3314 const small = @as(Inst.OpaqueDecl.Small, @bitCast(extended.small));
3315 var extra_index: usize = extended.operand;3315 var extra_index: usize = extended.operand;
3316 extra_index += @intFromBool(small.has_src_node);3316 extra_index += @intFromBool(small.has_src_node);
3317 const decls_len = if (small.has_decls_len) decls_len: {3317 const decls_len = if (small.has_decls_len) decls_len: {
...@@ -3507,7 +3507,7 @@ fn findDeclsSwitch(...@@ -3507,7 +3507,7 @@ fn findDeclsSwitch(
35073507
3508 const special_prong = extra.data.bits.specialProng();3508 const special_prong = extra.data.bits.specialProng();
3509 if (special_prong != .none) {3509 if (special_prong != .none) {
3510 const body_len = @truncate(u31, zir.extra[extra_index]);3510 const body_len = @as(u31, @truncate(zir.extra[extra_index]));
3511 extra_index += 1;3511 extra_index += 1;
3512 const body = zir.extra[extra_index..][0..body_len];3512 const body = zir.extra[extra_index..][0..body_len];
3513 extra_index += body.len;3513 extra_index += body.len;
...@@ -3520,7 +3520,7 @@ fn findDeclsSwitch(...@@ -3520,7 +3520,7 @@ fn findDeclsSwitch(
3520 var scalar_i: usize = 0;3520 var scalar_i: usize = 0;
3521 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {3521 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
3522 extra_index += 1;3522 extra_index += 1;
3523 const body_len = @truncate(u31, zir.extra[extra_index]);3523 const body_len = @as(u31, @truncate(zir.extra[extra_index]));
3524 extra_index += 1;3524 extra_index += 1;
3525 const body = zir.extra[extra_index..][0..body_len];3525 const body = zir.extra[extra_index..][0..body_len];
3526 extra_index += body_len;3526 extra_index += body_len;
...@@ -3535,7 +3535,7 @@ fn findDeclsSwitch(...@@ -3535,7 +3535,7 @@ fn findDeclsSwitch(
3535 extra_index += 1;3535 extra_index += 1;
3536 const ranges_len = zir.extra[extra_index];3536 const ranges_len = zir.extra[extra_index];
3537 extra_index += 1;3537 extra_index += 1;
3538 const body_len = @truncate(u31, zir.extra[extra_index]);3538 const body_len = @as(u31, @truncate(zir.extra[extra_index]));
3539 extra_index += 1;3539 extra_index += 1;
3540 const items = zir.refSlice(extra_index, items_len);3540 const items = zir.refSlice(extra_index, items_len);
3541 extra_index += items_len;3541 extra_index += items_len;
...@@ -3617,7 +3617,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {...@@ -3617,7 +3617,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
3617 ret_ty_ref = .void_type;3617 ret_ty_ref = .void_type;
3618 },3618 },
3619 1 => {3619 1 => {
3620 ret_ty_ref = @enumFromInt(Inst.Ref, zir.extra[extra_index]);3620 ret_ty_ref = @as(Inst.Ref, @enumFromInt(zir.extra[extra_index]));
3621 extra_index += 1;3621 extra_index += 1;
3622 },3622 },
3623 else => {3623 else => {
...@@ -3671,7 +3671,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {...@@ -3671,7 +3671,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
3671 ret_ty_body = zir.extra[extra_index..][0..body_len];3671 ret_ty_body = zir.extra[extra_index..][0..body_len];
3672 extra_index += ret_ty_body.len;3672 extra_index += ret_ty_body.len;
3673 } else if (extra.data.bits.has_ret_ty_ref) {3673 } else if (extra.data.bits.has_ret_ty_ref) {
3674 ret_ty_ref = @enumFromInt(Inst.Ref, zir.extra[extra_index]);3674 ret_ty_ref = @as(Inst.Ref, @enumFromInt(zir.extra[extra_index]));
3675 extra_index += 1;3675 extra_index += 1;
3676 }3676 }
36773677
...@@ -3715,7 +3715,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {...@@ -3715,7 +3715,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
3715pub const ref_start_index: u32 = InternPool.static_len;3715pub const ref_start_index: u32 = InternPool.static_len;
37163716
3717pub fn indexToRef(inst: Inst.Index) Inst.Ref {3717pub fn indexToRef(inst: Inst.Index) Inst.Ref {
3718 return @enumFromInt(Inst.Ref, ref_start_index + inst);3718 return @as(Inst.Ref, @enumFromInt(ref_start_index + inst));
3719}3719}
37203720
3721pub fn refToIndex(inst: Inst.Ref) ?Inst.Index {3721pub fn refToIndex(inst: Inst.Ref) ?Inst.Index {
src/arch/aarch64/CodeGen.zig+88-88
...@@ -187,8 +187,8 @@ const DbgInfoReloc = struct {...@@ -187,8 +187,8 @@ const DbgInfoReloc = struct {
187 .stack_argument_offset,187 .stack_argument_offset,
188 => |offset| blk: {188 => |offset| blk: {
189 const adjusted_offset = switch (reloc.mcv) {189 const adjusted_offset = switch (reloc.mcv) {
190 .stack_offset => -@intCast(i32, offset),190 .stack_offset => -@as(i32, @intCast(offset)),
191 .stack_argument_offset => @intCast(i32, function.saved_regs_stack_space + offset),191 .stack_argument_offset => @as(i32, @intCast(function.saved_regs_stack_space + offset)),
192 else => unreachable,192 else => unreachable,
193 };193 };
194 break :blk .{ .stack = .{194 break :blk .{ .stack = .{
...@@ -224,8 +224,8 @@ const DbgInfoReloc = struct {...@@ -224,8 +224,8 @@ const DbgInfoReloc = struct {
224 const adjusted_offset = switch (reloc.mcv) {224 const adjusted_offset = switch (reloc.mcv) {
225 .ptr_stack_offset,225 .ptr_stack_offset,
226 .stack_offset,226 .stack_offset,
227 => -@intCast(i32, offset),227 => -@as(i32, @intCast(offset)),
228 .stack_argument_offset => @intCast(i32, function.saved_regs_stack_space + offset),228 .stack_argument_offset => @as(i32, @intCast(function.saved_regs_stack_space + offset)),
229 else => unreachable,229 else => unreachable,
230 };230 };
231 break :blk .{231 break :blk .{
...@@ -440,7 +440,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {...@@ -440,7 +440,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
440440
441 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);441 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);
442442
443 const result_index = @intCast(Air.Inst.Index, self.mir_instructions.len);443 const result_index = @as(Air.Inst.Index, @intCast(self.mir_instructions.len));
444 self.mir_instructions.appendAssumeCapacity(inst);444 self.mir_instructions.appendAssumeCapacity(inst);
445 return result_index;445 return result_index;
446}446}
...@@ -460,11 +460,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {...@@ -460,11 +460,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {
460460
461pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {461pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
462 const fields = std.meta.fields(@TypeOf(extra));462 const fields = std.meta.fields(@TypeOf(extra));
463 const result = @intCast(u32, self.mir_extra.items.len);463 const result = @as(u32, @intCast(self.mir_extra.items.len));
464 inline for (fields) |field| {464 inline for (fields) |field| {
465 self.mir_extra.appendAssumeCapacity(switch (field.type) {465 self.mir_extra.appendAssumeCapacity(switch (field.type) {
466 u32 => @field(extra, field.name),466 u32 => @field(extra, field.name),
467 i32 => @bitCast(u32, @field(extra, field.name)),467 i32 => @as(u32, @bitCast(@field(extra, field.name))),
468 else => @compileError("bad field type"),468 else => @compileError("bad field type"),
469 });469 });
470 }470 }
...@@ -524,7 +524,7 @@ fn gen(self: *Self) !void {...@@ -524,7 +524,7 @@ fn gen(self: *Self) !void {
524524
525 const ty = self.typeOfIndex(inst);525 const ty = self.typeOfIndex(inst);
526526
527 const abi_size = @intCast(u32, ty.abiSize(mod));527 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
528 const abi_align = ty.abiAlignment(mod);528 const abi_align = ty.abiAlignment(mod);
529 const stack_offset = try self.allocMem(abi_size, abi_align, inst);529 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
530 try self.genSetStack(ty, stack_offset, MCValue{ .register = reg });530 try self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
...@@ -547,7 +547,7 @@ fn gen(self: *Self) !void {...@@ -547,7 +547,7 @@ fn gen(self: *Self) !void {
547 self.saved_regs_stack_space = 16;547 self.saved_regs_stack_space = 16;
548 inline for (callee_preserved_regs) |reg| {548 inline for (callee_preserved_regs) |reg| {
549 if (self.register_manager.isRegAllocated(reg)) {549 if (self.register_manager.isRegAllocated(reg)) {
550 saved_regs |= @as(u32, 1) << @intCast(u5, reg.id());550 saved_regs |= @as(u32, 1) << @as(u5, @intCast(reg.id()));
551 self.saved_regs_stack_space += 8;551 self.saved_regs_stack_space += 8;
552 }552 }
553 }553 }
...@@ -597,14 +597,14 @@ fn gen(self: *Self) !void {...@@ -597,14 +597,14 @@ fn gen(self: *Self) !void {
597 for (self.exitlude_jump_relocs.items) |jmp_reloc| {597 for (self.exitlude_jump_relocs.items) |jmp_reloc| {
598 self.mir_instructions.set(jmp_reloc, .{598 self.mir_instructions.set(jmp_reloc, .{
599 .tag = .b,599 .tag = .b,
600 .data = .{ .inst = @intCast(u32, self.mir_instructions.len) },600 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len)) },
601 });601 });
602 }602 }
603603
604 // add sp, sp, #stack_size604 // add sp, sp, #stack_size
605 _ = try self.addInst(.{605 _ = try self.addInst(.{
606 .tag = .add_immediate,606 .tag = .add_immediate,
607 .data = .{ .rr_imm12_sh = .{ .rd = .sp, .rn = .sp, .imm12 = @intCast(u12, stack_size) } },607 .data = .{ .rr_imm12_sh = .{ .rd = .sp, .rn = .sp, .imm12 = @as(u12, @intCast(stack_size)) } },
608 });608 });
609609
610 // <load other registers>610 // <load other registers>
...@@ -948,15 +948,15 @@ fn finishAirBookkeeping(self: *Self) void {...@@ -948,15 +948,15 @@ fn finishAirBookkeeping(self: *Self) void {
948fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void {948fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void {
949 var tomb_bits = self.liveness.getTombBits(inst);949 var tomb_bits = self.liveness.getTombBits(inst);
950 for (operands) |op| {950 for (operands) |op| {
951 const dies = @truncate(u1, tomb_bits) != 0;951 const dies = @as(u1, @truncate(tomb_bits)) != 0;
952 tomb_bits >>= 1;952 tomb_bits >>= 1;
953 if (!dies) continue;953 if (!dies) continue;
954 const op_int = @intFromEnum(op);954 const op_int = @intFromEnum(op);
955 if (op_int < Air.ref_start_index) continue;955 if (op_int < Air.ref_start_index) continue;
956 const op_index = @intCast(Air.Inst.Index, op_int - Air.ref_start_index);956 const op_index = @as(Air.Inst.Index, @intCast(op_int - Air.ref_start_index));
957 self.processDeath(op_index);957 self.processDeath(op_index);
958 }958 }
959 const is_used = @truncate(u1, tomb_bits) == 0;959 const is_used = @as(u1, @truncate(tomb_bits)) == 0;
960 if (is_used) {960 if (is_used) {
961 log.debug("%{d} => {}", .{ inst, result });961 log.debug("%{d} => {}", .{ inst, result });
962 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];962 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
...@@ -1232,7 +1232,7 @@ fn truncRegister(...@@ -1232,7 +1232,7 @@ fn truncRegister(
1232 .rd = dest_reg,1232 .rd = dest_reg,
1233 .rn = operand_reg,1233 .rn = operand_reg,
1234 .lsb = 0,1234 .lsb = 0,
1235 .width = @intCast(u6, int_bits),1235 .width = @as(u6, @intCast(int_bits)),
1236 } },1236 } },
1237 });1237 });
1238 },1238 },
...@@ -1877,7 +1877,7 @@ fn binOpImmediate(...@@ -1877,7 +1877,7 @@ fn binOpImmediate(
1877 => .{ .rr_imm12_sh = .{1877 => .{ .rr_imm12_sh = .{
1878 .rd = dest_reg,1878 .rd = dest_reg,
1879 .rn = lhs_reg,1879 .rn = lhs_reg,
1880 .imm12 = @intCast(u12, rhs_immediate),1880 .imm12 = @as(u12, @intCast(rhs_immediate)),
1881 } },1881 } },
1882 .lsl_immediate,1882 .lsl_immediate,
1883 .asr_immediate,1883 .asr_immediate,
...@@ -1885,7 +1885,7 @@ fn binOpImmediate(...@@ -1885,7 +1885,7 @@ fn binOpImmediate(
1885 => .{ .rr_shift = .{1885 => .{ .rr_shift = .{
1886 .rd = dest_reg,1886 .rd = dest_reg,
1887 .rn = lhs_reg,1887 .rn = lhs_reg,
1888 .shift = @intCast(u6, rhs_immediate),1888 .shift = @as(u6, @intCast(rhs_immediate)),
1889 } },1889 } },
1890 else => unreachable,1890 else => unreachable,
1891 };1891 };
...@@ -2526,9 +2526,9 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2526,9 +2526,9 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
2526 const rhs_ty = self.typeOf(extra.rhs);2526 const rhs_ty = self.typeOf(extra.rhs);
25272527
2528 const tuple_ty = self.typeOfIndex(inst);2528 const tuple_ty = self.typeOfIndex(inst);
2529 const tuple_size = @intCast(u32, tuple_ty.abiSize(mod));2529 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(mod)));
2530 const tuple_align = tuple_ty.abiAlignment(mod);2530 const tuple_align = tuple_ty.abiAlignment(mod);
2531 const overflow_bit_offset = @intCast(u32, tuple_ty.structFieldOffset(1, mod));2531 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, mod)));
25322532
2533 switch (lhs_ty.zigTypeTag(mod)) {2533 switch (lhs_ty.zigTypeTag(mod)) {
2534 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),2534 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),
...@@ -2654,9 +2654,9 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2654,9 +2654,9 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2654 const rhs_ty = self.typeOf(extra.rhs);2654 const rhs_ty = self.typeOf(extra.rhs);
26552655
2656 const tuple_ty = self.typeOfIndex(inst);2656 const tuple_ty = self.typeOfIndex(inst);
2657 const tuple_size = @intCast(u32, tuple_ty.abiSize(mod));2657 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(mod)));
2658 const tuple_align = tuple_ty.abiAlignment(mod);2658 const tuple_align = tuple_ty.abiAlignment(mod);
2659 const overflow_bit_offset = @intCast(u32, tuple_ty.structFieldOffset(1, mod));2659 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, mod)));
26602660
2661 switch (lhs_ty.zigTypeTag(mod)) {2661 switch (lhs_ty.zigTypeTag(mod)) {
2662 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),2662 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
...@@ -2777,7 +2777,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2777,7 +2777,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2777 } },2777 } },
2778 });2778 });
27792779
2780 const shift: u6 = @intCast(u6, @as(u7, 64) - @intCast(u7, int_info.bits));2780 const shift: u6 = @as(u6, @intCast(@as(u7, 64) - @as(u7, @intCast(int_info.bits))));
2781 if (shift > 0) {2781 if (shift > 0) {
2782 // lsl dest_high, dest, #shift2782 // lsl dest_high, dest, #shift
2783 _ = try self.addInst(.{2783 _ = try self.addInst(.{
...@@ -2837,7 +2837,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2837,7 +2837,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2837 .data = .{ .rr_shift = .{2837 .data = .{ .rr_shift = .{
2838 .rd = dest_high_reg,2838 .rd = dest_high_reg,
2839 .rn = dest_reg,2839 .rn = dest_reg,
2840 .shift = @intCast(u6, int_info.bits),2840 .shift = @as(u6, @intCast(int_info.bits)),
2841 } },2841 } },
2842 });2842 });
28432843
...@@ -2878,9 +2878,9 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2878,9 +2878,9 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2878 const rhs_ty = self.typeOf(extra.rhs);2878 const rhs_ty = self.typeOf(extra.rhs);
28792879
2880 const tuple_ty = self.typeOfIndex(inst);2880 const tuple_ty = self.typeOfIndex(inst);
2881 const tuple_size = @intCast(u32, tuple_ty.abiSize(mod));2881 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(mod)));
2882 const tuple_align = tuple_ty.abiAlignment(mod);2882 const tuple_align = tuple_ty.abiAlignment(mod);
2883 const overflow_bit_offset = @intCast(u32, tuple_ty.structFieldOffset(1, mod));2883 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, mod)));
28842884
2885 switch (lhs_ty.zigTypeTag(mod)) {2885 switch (lhs_ty.zigTypeTag(mod)) {
2886 .Vector => return self.fail("TODO implement shl_with_overflow for vectors", .{}),2886 .Vector => return self.fail("TODO implement shl_with_overflow for vectors", .{}),
...@@ -2917,7 +2917,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2917,7 +2917,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2917 .data = .{ .rr_shift = .{2917 .data = .{ .rr_shift = .{
2918 .rd = dest_reg,2918 .rd = dest_reg,
2919 .rn = lhs_reg,2919 .rn = lhs_reg,
2920 .shift = @intCast(u6, imm),2920 .shift = @as(u6, @intCast(imm)),
2921 } },2921 } },
2922 });2922 });
29232923
...@@ -2932,7 +2932,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2932,7 +2932,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2932 .data = .{ .rr_shift = .{2932 .data = .{ .rr_shift = .{
2933 .rd = reconstructed_reg,2933 .rd = reconstructed_reg,
2934 .rn = dest_reg,2934 .rn = dest_reg,
2935 .shift = @intCast(u6, imm),2935 .shift = @as(u6, @intCast(imm)),
2936 } },2936 } },
2937 });2937 });
2938 } else {2938 } else {
...@@ -3072,7 +3072,7 @@ fn errUnionErr(...@@ -3072,7 +3072,7 @@ fn errUnionErr(
3072 return try error_union_bind.resolveToMcv(self);3072 return try error_union_bind.resolveToMcv(self);
3073 }3073 }
30743074
3075 const err_offset = @intCast(u32, errUnionErrorOffset(payload_ty, mod));3075 const err_offset = @as(u32, @intCast(errUnionErrorOffset(payload_ty, mod)));
3076 switch (try error_union_bind.resolveToMcv(self)) {3076 switch (try error_union_bind.resolveToMcv(self)) {
3077 .register => {3077 .register => {
3078 var operand_reg: Register = undefined;3078 var operand_reg: Register = undefined;
...@@ -3094,7 +3094,7 @@ fn errUnionErr(...@@ -3094,7 +3094,7 @@ fn errUnionErr(
3094 );3094 );
30953095
3096 const err_bit_offset = err_offset * 8;3096 const err_bit_offset = err_offset * 8;
3097 const err_bit_size = @intCast(u32, err_ty.abiSize(mod)) * 8;3097 const err_bit_size = @as(u32, @intCast(err_ty.abiSize(mod))) * 8;
30983098
3099 _ = try self.addInst(.{3099 _ = try self.addInst(.{
3100 .tag = .ubfx, // errors are unsigned integers3100 .tag = .ubfx, // errors are unsigned integers
...@@ -3103,8 +3103,8 @@ fn errUnionErr(...@@ -3103,8 +3103,8 @@ fn errUnionErr(
3103 // Set both registers to the X variant to get the full width3103 // Set both registers to the X variant to get the full width
3104 .rd = dest_reg.toX(),3104 .rd = dest_reg.toX(),
3105 .rn = operand_reg.toX(),3105 .rn = operand_reg.toX(),
3106 .lsb = @intCast(u6, err_bit_offset),3106 .lsb = @as(u6, @intCast(err_bit_offset)),
3107 .width = @intCast(u7, err_bit_size),3107 .width = @as(u7, @intCast(err_bit_size)),
3108 },3108 },
3109 },3109 },
3110 });3110 });
...@@ -3152,7 +3152,7 @@ fn errUnionPayload(...@@ -3152,7 +3152,7 @@ fn errUnionPayload(
3152 return MCValue.none;3152 return MCValue.none;
3153 }3153 }
31543154
3155 const payload_offset = @intCast(u32, errUnionPayloadOffset(payload_ty, mod));3155 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, mod)));
3156 switch (try error_union_bind.resolveToMcv(self)) {3156 switch (try error_union_bind.resolveToMcv(self)) {
3157 .register => {3157 .register => {
3158 var operand_reg: Register = undefined;3158 var operand_reg: Register = undefined;
...@@ -3174,7 +3174,7 @@ fn errUnionPayload(...@@ -3174,7 +3174,7 @@ fn errUnionPayload(
3174 );3174 );
31753175
3176 const payload_bit_offset = payload_offset * 8;3176 const payload_bit_offset = payload_offset * 8;
3177 const payload_bit_size = @intCast(u32, payload_ty.abiSize(mod)) * 8;3177 const payload_bit_size = @as(u32, @intCast(payload_ty.abiSize(mod))) * 8;
31783178
3179 _ = try self.addInst(.{3179 _ = try self.addInst(.{
3180 .tag = if (payload_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,3180 .tag = if (payload_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,
...@@ -3183,8 +3183,8 @@ fn errUnionPayload(...@@ -3183,8 +3183,8 @@ fn errUnionPayload(
3183 // Set both registers to the X variant to get the full width3183 // Set both registers to the X variant to get the full width
3184 .rd = dest_reg.toX(),3184 .rd = dest_reg.toX(),
3185 .rn = operand_reg.toX(),3185 .rn = operand_reg.toX(),
3186 .lsb = @intCast(u5, payload_bit_offset),3186 .lsb = @as(u5, @intCast(payload_bit_offset)),
3187 .width = @intCast(u6, payload_bit_size),3187 .width = @as(u6, @intCast(payload_bit_size)),
3188 },3188 },
3189 },3189 },
3190 });3190 });
...@@ -3283,9 +3283,9 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {...@@ -3283,9 +3283,9 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
3283 break :result MCValue{ .register = reg };3283 break :result MCValue{ .register = reg };
3284 }3284 }
32853285
3286 const optional_abi_size = @intCast(u32, optional_ty.abiSize(mod));3286 const optional_abi_size = @as(u32, @intCast(optional_ty.abiSize(mod)));
3287 const optional_abi_align = optional_ty.abiAlignment(mod);3287 const optional_abi_align = optional_ty.abiAlignment(mod);
3288 const offset = @intCast(u32, payload_ty.abiSize(mod));3288 const offset = @as(u32, @intCast(payload_ty.abiSize(mod)));
32893289
3290 const stack_offset = try self.allocMem(optional_abi_size, optional_abi_align, inst);3290 const stack_offset = try self.allocMem(optional_abi_size, optional_abi_align, inst);
3291 try self.genSetStack(payload_ty, stack_offset, operand);3291 try self.genSetStack(payload_ty, stack_offset, operand);
...@@ -3308,13 +3308,13 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {...@@ -3308,13 +3308,13 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
3308 const operand = try self.resolveInst(ty_op.operand);3308 const operand = try self.resolveInst(ty_op.operand);
3309 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result operand;3309 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result operand;
33103310
3311 const abi_size = @intCast(u32, error_union_ty.abiSize(mod));3311 const abi_size = @as(u32, @intCast(error_union_ty.abiSize(mod)));
3312 const abi_align = error_union_ty.abiAlignment(mod);3312 const abi_align = error_union_ty.abiAlignment(mod);
3313 const stack_offset = try self.allocMem(abi_size, abi_align, inst);3313 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
3314 const payload_off = errUnionPayloadOffset(payload_ty, mod);3314 const payload_off = errUnionPayloadOffset(payload_ty, mod);
3315 const err_off = errUnionErrorOffset(payload_ty, mod);3315 const err_off = errUnionErrorOffset(payload_ty, mod);
3316 try self.genSetStack(payload_ty, stack_offset - @intCast(u32, payload_off), operand);3316 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), operand);
3317 try self.genSetStack(error_ty, stack_offset - @intCast(u32, err_off), .{ .immediate = 0 });3317 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), .{ .immediate = 0 });
33183318
3319 break :result MCValue{ .stack_offset = stack_offset };3319 break :result MCValue{ .stack_offset = stack_offset };
3320 };3320 };
...@@ -3332,13 +3332,13 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -3332,13 +3332,13 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
3332 const operand = try self.resolveInst(ty_op.operand);3332 const operand = try self.resolveInst(ty_op.operand);
3333 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result operand;3333 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result operand;
33343334
3335 const abi_size = @intCast(u32, error_union_ty.abiSize(mod));3335 const abi_size = @as(u32, @intCast(error_union_ty.abiSize(mod)));
3336 const abi_align = error_union_ty.abiAlignment(mod);3336 const abi_align = error_union_ty.abiAlignment(mod);
3337 const stack_offset = try self.allocMem(abi_size, abi_align, inst);3337 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
3338 const payload_off = errUnionPayloadOffset(payload_ty, mod);3338 const payload_off = errUnionPayloadOffset(payload_ty, mod);
3339 const err_off = errUnionErrorOffset(payload_ty, mod);3339 const err_off = errUnionErrorOffset(payload_ty, mod);
3340 try self.genSetStack(error_ty, stack_offset - @intCast(u32, err_off), operand);3340 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), operand);
3341 try self.genSetStack(payload_ty, stack_offset - @intCast(u32, payload_off), .undef);3341 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), .undef);
33423342
3343 break :result MCValue{ .stack_offset = stack_offset };3343 break :result MCValue{ .stack_offset = stack_offset };
3344 };3344 };
...@@ -3454,7 +3454,7 @@ fn ptrElemVal(...@@ -3454,7 +3454,7 @@ fn ptrElemVal(
3454) !MCValue {3454) !MCValue {
3455 const mod = self.bin_file.options.module.?;3455 const mod = self.bin_file.options.module.?;
3456 const elem_ty = ptr_ty.childType(mod);3456 const elem_ty = ptr_ty.childType(mod);
3457 const elem_size = @intCast(u32, elem_ty.abiSize(mod));3457 const elem_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
34583458
3459 // TODO optimize for elem_sizes of 1, 2, 4, 83459 // TODO optimize for elem_sizes of 1, 2, 4, 8
3460 switch (elem_size) {3460 switch (elem_size) {
...@@ -3716,7 +3716,7 @@ fn genInlineMemcpy(...@@ -3716,7 +3716,7 @@ fn genInlineMemcpy(
3716 _ = try self.addInst(.{3716 _ = try self.addInst(.{
3717 .tag = .b_cond,3717 .tag = .b_cond,
3718 .data = .{ .inst_cond = .{3718 .data = .{ .inst_cond = .{
3719 .inst = @intCast(u32, self.mir_instructions.len + 5),3719 .inst = @as(u32, @intCast(self.mir_instructions.len + 5)),
3720 .cond = .ge,3720 .cond = .ge,
3721 } },3721 } },
3722 });3722 });
...@@ -3754,7 +3754,7 @@ fn genInlineMemcpy(...@@ -3754,7 +3754,7 @@ fn genInlineMemcpy(
3754 // b loop3754 // b loop
3755 _ = try self.addInst(.{3755 _ = try self.addInst(.{
3756 .tag = .b,3756 .tag = .b,
3757 .data = .{ .inst = @intCast(u32, self.mir_instructions.len - 5) },3757 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len - 5)) },
3758 });3758 });
37593759
3760 // end:3760 // end:
...@@ -3824,7 +3824,7 @@ fn genInlineMemsetCode(...@@ -3824,7 +3824,7 @@ fn genInlineMemsetCode(
3824 _ = try self.addInst(.{3824 _ = try self.addInst(.{
3825 .tag = .b_cond,3825 .tag = .b_cond,
3826 .data = .{ .inst_cond = .{3826 .data = .{ .inst_cond = .{
3827 .inst = @intCast(u32, self.mir_instructions.len + 4),3827 .inst = @as(u32, @intCast(self.mir_instructions.len + 4)),
3828 .cond = .ge,3828 .cond = .ge,
3829 } },3829 } },
3830 });3830 });
...@@ -3852,7 +3852,7 @@ fn genInlineMemsetCode(...@@ -3852,7 +3852,7 @@ fn genInlineMemsetCode(
3852 // b loop3852 // b loop
3853 _ = try self.addInst(.{3853 _ = try self.addInst(.{
3854 .tag = .b,3854 .tag = .b,
3855 .data = .{ .inst = @intCast(u32, self.mir_instructions.len - 4) },3855 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len - 4)) },
3856 });3856 });
38573857
3858 // end:3858 // end:
...@@ -4002,7 +4002,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type...@@ -4002,7 +4002,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
4002 } },4002 } },
4003 });4003 });
4004 },4004 },
4005 .memory => |addr| try self.genSetReg(Type.usize, src_reg, .{ .immediate = @intCast(u32, addr) }),4005 .memory => |addr| try self.genSetReg(Type.usize, src_reg, .{ .immediate = @as(u32, @intCast(addr)) }),
4006 .linker_load => |load_struct| {4006 .linker_load => |load_struct| {
4007 const tag: Mir.Inst.Tag = switch (load_struct.type) {4007 const tag: Mir.Inst.Tag = switch (load_struct.type) {
4008 .got => .load_memory_ptr_got,4008 .got => .load_memory_ptr_got,
...@@ -4092,7 +4092,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde...@@ -4092,7 +4092,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
4092 const mcv = try self.resolveInst(operand);4092 const mcv = try self.resolveInst(operand);
4093 const ptr_ty = self.typeOf(operand);4093 const ptr_ty = self.typeOf(operand);
4094 const struct_ty = ptr_ty.childType(mod);4094 const struct_ty = ptr_ty.childType(mod);
4095 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, mod));4095 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, mod)));
4096 switch (mcv) {4096 switch (mcv) {
4097 .ptr_stack_offset => |off| {4097 .ptr_stack_offset => |off| {
4098 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };4098 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };
...@@ -4117,7 +4117,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -4117,7 +4117,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
4117 const mcv = try self.resolveInst(operand);4117 const mcv = try self.resolveInst(operand);
4118 const struct_ty = self.typeOf(operand);4118 const struct_ty = self.typeOf(operand);
4119 const struct_field_ty = struct_ty.structFieldType(index, mod);4119 const struct_field_ty = struct_ty.structFieldType(index, mod);
4120 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, mod));4120 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, mod)));
41214121
4122 switch (mcv) {4122 switch (mcv) {
4123 .dead, .unreach => unreachable,4123 .dead, .unreach => unreachable,
...@@ -4169,7 +4169,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4169,7 +4169,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
4169 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4169 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4170 const field_ptr = try self.resolveInst(extra.field_ptr);4170 const field_ptr = try self.resolveInst(extra.field_ptr);
4171 const struct_ty = self.air.getRefType(ty_pl.ty).childType(mod);4171 const struct_ty = self.air.getRefType(ty_pl.ty).childType(mod);
4172 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(extra.field_index, mod));4172 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(extra.field_index, mod)));
4173 switch (field_ptr) {4173 switch (field_ptr) {
4174 .ptr_stack_offset => |off| {4174 .ptr_stack_offset => |off| {
4175 break :result MCValue{ .ptr_stack_offset = off + struct_field_offset };4175 break :result MCValue{ .ptr_stack_offset = off + struct_field_offset };
...@@ -4243,7 +4243,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4243,7 +4243,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4243 const pl_op = self.air.instructions.items(.data)[inst].pl_op;4243 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
4244 const callee = pl_op.operand;4244 const callee = pl_op.operand;
4245 const extra = self.air.extraData(Air.Call, pl_op.payload);4245 const extra = self.air.extraData(Air.Call, pl_op.payload);
4246 const args = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra.end..][0..extra.data.args_len]);4246 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));
4247 const ty = self.typeOf(callee);4247 const ty = self.typeOf(callee);
4248 const mod = self.bin_file.options.module.?;4248 const mod = self.bin_file.options.module.?;
42494249
...@@ -4269,8 +4269,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4269,8 +4269,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4269 if (info.return_value == .stack_offset) {4269 if (info.return_value == .stack_offset) {
4270 log.debug("airCall: return by reference", .{});4270 log.debug("airCall: return by reference", .{});
4271 const ret_ty = fn_ty.fnReturnType(mod);4271 const ret_ty = fn_ty.fnReturnType(mod);
4272 const ret_abi_size = @intCast(u32, ret_ty.abiSize(mod));4272 const ret_abi_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
4273 const ret_abi_align = @intCast(u32, ret_ty.abiAlignment(mod));4273 const ret_abi_align = @as(u32, @intCast(ret_ty.abiAlignment(mod)));
4274 const stack_offset = try self.allocMem(ret_abi_size, ret_abi_align, inst);4274 const stack_offset = try self.allocMem(ret_abi_size, ret_abi_align, inst);
42754275
4276 const ret_ptr_reg = self.registerAlias(.x0, Type.usize);4276 const ret_ptr_reg = self.registerAlias(.x0, Type.usize);
...@@ -4314,7 +4314,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4314,7 +4314,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4314 const atom_index = try elf_file.getOrCreateAtomForDecl(func.owner_decl);4314 const atom_index = try elf_file.getOrCreateAtomForDecl(func.owner_decl);
4315 const atom = elf_file.getAtom(atom_index);4315 const atom = elf_file.getAtom(atom_index);
4316 _ = try atom.getOrCreateOffsetTableEntry(elf_file);4316 _ = try atom.getOrCreateOffsetTableEntry(elf_file);
4317 const got_addr = @intCast(u32, atom.getOffsetTableAddress(elf_file));4317 const got_addr = @as(u32, @intCast(atom.getOffsetTableAddress(elf_file)));
4318 try self.genSetReg(Type.usize, .x30, .{ .memory = got_addr });4318 try self.genSetReg(Type.usize, .x30, .{ .memory = got_addr });
4319 } else if (self.bin_file.cast(link.File.MachO)) |macho_file| {4319 } else if (self.bin_file.cast(link.File.MachO)) |macho_file| {
4320 const atom = try macho_file.getOrCreateAtomForDecl(func.owner_decl);4320 const atom = try macho_file.getOrCreateAtomForDecl(func.owner_decl);
...@@ -4473,7 +4473,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -4473,7 +4473,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
4473 // location.4473 // location.
4474 const op_inst = Air.refToIndex(un_op).?;4474 const op_inst = Air.refToIndex(un_op).?;
4475 if (self.air.instructions.items(.tag)[op_inst] != .ret_ptr) {4475 if (self.air.instructions.items(.tag)[op_inst] != .ret_ptr) {
4476 const abi_size = @intCast(u32, ret_ty.abiSize(mod));4476 const abi_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
4477 const abi_align = ret_ty.abiAlignment(mod);4477 const abi_align = ret_ty.abiAlignment(mod);
44784478
4479 const offset = try self.allocMem(abi_size, abi_align, null);4479 const offset = try self.allocMem(abi_size, abi_align, null);
...@@ -4554,7 +4554,7 @@ fn cmp(...@@ -4554,7 +4554,7 @@ fn cmp(
4554 .tag = .cmp_immediate,4554 .tag = .cmp_immediate,
4555 .data = .{ .r_imm12_sh = .{4555 .data = .{ .r_imm12_sh = .{
4556 .rn = lhs_reg,4556 .rn = lhs_reg,
4557 .imm12 = @intCast(u12, rhs_immediate.?),4557 .imm12 = @as(u12, @intCast(rhs_immediate.?)),
4558 } },4558 } },
4559 });4559 });
4560 } else {4560 } else {
...@@ -4696,7 +4696,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4696,7 +4696,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
4696 if (self.liveness.operandDies(inst, 0)) {4696 if (self.liveness.operandDies(inst, 0)) {
4697 const op_int = @intFromEnum(pl_op.operand);4697 const op_int = @intFromEnum(pl_op.operand);
4698 if (op_int >= Air.ref_start_index) {4698 if (op_int >= Air.ref_start_index) {
4699 const op_index = @intCast(Air.Inst.Index, op_int - Air.ref_start_index);4699 const op_index = @as(Air.Inst.Index, @intCast(op_int - Air.ref_start_index));
4700 self.processDeath(op_index);4700 self.processDeath(op_index);
4701 }4701 }
4702 }4702 }
...@@ -4833,7 +4833,7 @@ fn isNull(self: *Self, operand_bind: ReadArg.Bind, operand_ty: Type) !MCValue {...@@ -4833,7 +4833,7 @@ fn isNull(self: *Self, operand_bind: ReadArg.Bind, operand_ty: Type) !MCValue {
4833 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod))4833 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod))
4834 break :blk .{ .ty = operand_ty, .bind = operand_bind };4834 break :blk .{ .ty = operand_ty, .bind = operand_bind };
48354835
4836 const offset = @intCast(u32, payload_ty.abiSize(mod));4836 const offset = @as(u32, @intCast(payload_ty.abiSize(mod)));
4837 const operand_mcv = try operand_bind.resolveToMcv(self);4837 const operand_mcv = try operand_bind.resolveToMcv(self);
4838 const new_mcv: MCValue = switch (operand_mcv) {4838 const new_mcv: MCValue = switch (operand_mcv) {
4839 .register => |source_reg| new: {4839 .register => |source_reg| new: {
...@@ -4841,7 +4841,7 @@ fn isNull(self: *Self, operand_bind: ReadArg.Bind, operand_ty: Type) !MCValue {...@@ -4841,7 +4841,7 @@ fn isNull(self: *Self, operand_bind: ReadArg.Bind, operand_ty: Type) !MCValue {
4841 const raw_reg = try self.register_manager.allocReg(null, gp);4841 const raw_reg = try self.register_manager.allocReg(null, gp);
4842 const dest_reg = raw_reg.toX();4842 const dest_reg = raw_reg.toX();
48434843
4844 const shift = @intCast(u6, offset * 8);4844 const shift = @as(u6, @intCast(offset * 8));
4845 if (shift == 0) {4845 if (shift == 0) {
4846 try self.genSetReg(payload_ty, dest_reg, operand_mcv);4846 try self.genSetReg(payload_ty, dest_reg, operand_mcv);
4847 } else {4847 } else {
...@@ -5026,7 +5026,7 @@ fn airLoop(self: *Self, inst: Air.Inst.Index) !void {...@@ -5026,7 +5026,7 @@ fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
5026 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5026 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
5027 const loop = self.air.extraData(Air.Block, ty_pl.payload);5027 const loop = self.air.extraData(Air.Block, ty_pl.payload);
5028 const body = self.air.extra[loop.end..][0..loop.data.body_len];5028 const body = self.air.extra[loop.end..][0..loop.data.body_len];
5029 const start_index = @intCast(u32, self.mir_instructions.len);5029 const start_index = @as(u32, @intCast(self.mir_instructions.len));
50305030
5031 try self.genBody(body);5031 try self.genBody(body);
5032 try self.jump(start_index);5032 try self.jump(start_index);
...@@ -5091,7 +5091,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {...@@ -5091,7 +5091,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
5091 var case_i: u32 = 0;5091 var case_i: u32 = 0;
5092 while (case_i < switch_br.data.cases_len) : (case_i += 1) {5092 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
5093 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);5093 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
5094 const items = @ptrCast([]const Air.Inst.Ref, self.air.extra[case.end..][0..case.data.items_len]);5094 const items = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[case.end..][0..case.data.items_len]));
5095 assert(items.len > 0);5095 assert(items.len > 0);
5096 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];5096 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
5097 extra_index = case.end + items.len + case_body.len;5097 extra_index = case.end + items.len + case_body.len;
...@@ -5209,9 +5209,9 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {...@@ -5209,9 +5209,9 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
5209fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {5209fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {
5210 const tag = self.mir_instructions.items(.tag)[inst];5210 const tag = self.mir_instructions.items(.tag)[inst];
5211 switch (tag) {5211 switch (tag) {
5212 .cbz => self.mir_instructions.items(.data)[inst].r_inst.inst = @intCast(Mir.Inst.Index, self.mir_instructions.len),5212 .cbz => self.mir_instructions.items(.data)[inst].r_inst.inst = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len)),
5213 .b_cond => self.mir_instructions.items(.data)[inst].inst_cond.inst = @intCast(Mir.Inst.Index, self.mir_instructions.len),5213 .b_cond => self.mir_instructions.items(.data)[inst].inst_cond.inst = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len)),
5214 .b => self.mir_instructions.items(.data)[inst].inst = @intCast(Mir.Inst.Index, self.mir_instructions.len),5214 .b => self.mir_instructions.items(.data)[inst].inst = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len)),
5215 else => unreachable,5215 else => unreachable,
5216 }5216 }
5217}5217}
...@@ -5262,12 +5262,12 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {...@@ -5262,12 +5262,12 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {
5262fn airAsm(self: *Self, inst: Air.Inst.Index) !void {5262fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
5263 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5263 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
5264 const extra = self.air.extraData(Air.Asm, ty_pl.payload);5264 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
5265 const is_volatile = @truncate(u1, extra.data.flags >> 31) != 0;5265 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
5266 const clobbers_len = @truncate(u31, extra.data.flags);5266 const clobbers_len = @as(u31, @truncate(extra.data.flags));
5267 var extra_i: usize = extra.end;5267 var extra_i: usize = extra.end;
5268 const outputs = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra_i..][0..extra.data.outputs_len]);5268 const outputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]));
5269 extra_i += outputs.len;5269 extra_i += outputs.len;
5270 const inputs = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra_i..][0..extra.data.inputs_len]);5270 const inputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]));
5271 extra_i += inputs.len;5271 extra_i += inputs.len;
52725272
5273 const dead = !is_volatile and self.liveness.isUnused(inst);5273 const dead = !is_volatile and self.liveness.isUnused(inst);
...@@ -5401,7 +5401,7 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {...@@ -5401,7 +5401,7 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {
54015401
5402fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {5402fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
5403 const mod = self.bin_file.options.module.?;5403 const mod = self.bin_file.options.module.?;
5404 const abi_size = @intCast(u32, ty.abiSize(mod));5404 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
5405 switch (mcv) {5405 switch (mcv) {
5406 .dead => unreachable,5406 .dead => unreachable,
5407 .unreach, .none => return, // Nothing to do.5407 .unreach, .none => return, // Nothing to do.
...@@ -5460,7 +5460,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro...@@ -5460,7 +5460,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
5460 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = rwo.reg });5460 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = rwo.reg });
54615461
5462 const overflow_bit_ty = ty.structFieldType(1, mod);5462 const overflow_bit_ty = ty.structFieldType(1, mod);
5463 const overflow_bit_offset = @intCast(u32, ty.structFieldOffset(1, mod));5463 const overflow_bit_offset = @as(u32, @intCast(ty.structFieldOffset(1, mod)));
5464 const raw_cond_reg = try self.register_manager.allocReg(null, gp);5464 const raw_cond_reg = try self.register_manager.allocReg(null, gp);
5465 const cond_reg = self.registerAlias(raw_cond_reg, overflow_bit_ty);5465 const cond_reg = self.registerAlias(raw_cond_reg, overflow_bit_ty);
54665466
...@@ -5589,7 +5589,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5589,7 +5589,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5589 .tag = .ldr_ptr_stack,5589 .tag = .ldr_ptr_stack,
5590 .data = .{ .load_store_stack = .{5590 .data = .{ .load_store_stack = .{
5591 .rt = reg,5591 .rt = reg,
5592 .offset = @intCast(u32, off),5592 .offset = @as(u32, @intCast(off)),
5593 } },5593 } },
5594 });5594 });
5595 },5595 },
...@@ -5605,13 +5605,13 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5605,13 +5605,13 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5605 .immediate => |x| {5605 .immediate => |x| {
5606 _ = try self.addInst(.{5606 _ = try self.addInst(.{
5607 .tag = .movz,5607 .tag = .movz,
5608 .data = .{ .r_imm16_sh = .{ .rd = reg, .imm16 = @truncate(u16, x) } },5608 .data = .{ .r_imm16_sh = .{ .rd = reg, .imm16 = @as(u16, @truncate(x)) } },
5609 });5609 });
56105610
5611 if (x & 0x0000_0000_ffff_0000 != 0) {5611 if (x & 0x0000_0000_ffff_0000 != 0) {
5612 _ = try self.addInst(.{5612 _ = try self.addInst(.{
5613 .tag = .movk,5613 .tag = .movk,
5614 .data = .{ .r_imm16_sh = .{ .rd = reg, .imm16 = @truncate(u16, x >> 16), .hw = 1 } },5614 .data = .{ .r_imm16_sh = .{ .rd = reg, .imm16 = @as(u16, @truncate(x >> 16)), .hw = 1 } },
5615 });5615 });
5616 }5616 }
56175617
...@@ -5619,13 +5619,13 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5619,13 +5619,13 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5619 if (x & 0x0000_ffff_0000_0000 != 0) {5619 if (x & 0x0000_ffff_0000_0000 != 0) {
5620 _ = try self.addInst(.{5620 _ = try self.addInst(.{
5621 .tag = .movk,5621 .tag = .movk,
5622 .data = .{ .r_imm16_sh = .{ .rd = reg, .imm16 = @truncate(u16, x >> 32), .hw = 2 } },5622 .data = .{ .r_imm16_sh = .{ .rd = reg, .imm16 = @as(u16, @truncate(x >> 32)), .hw = 2 } },
5623 });5623 });
5624 }5624 }
5625 if (x & 0xffff_0000_0000_0000 != 0) {5625 if (x & 0xffff_0000_0000_0000 != 0) {
5626 _ = try self.addInst(.{5626 _ = try self.addInst(.{
5627 .tag = .movk,5627 .tag = .movk,
5628 .data = .{ .r_imm16_sh = .{ .rd = reg, .imm16 = @truncate(u16, x >> 48), .hw = 3 } },5628 .data = .{ .r_imm16_sh = .{ .rd = reg, .imm16 = @as(u16, @truncate(x >> 48)), .hw = 3 } },
5629 });5629 });
5630 }5630 }
5631 }5631 }
...@@ -5696,7 +5696,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5696,7 +5696,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5696 .tag = tag,5696 .tag = tag,
5697 .data = .{ .load_store_stack = .{5697 .data = .{ .load_store_stack = .{
5698 .rt = reg,5698 .rt = reg,
5699 .offset = @intCast(u32, off),5699 .offset = @as(u32, @intCast(off)),
5700 } },5700 } },
5701 });5701 });
5702 },5702 },
...@@ -5720,7 +5720,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5720,7 +5720,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5720 .tag = tag,5720 .tag = tag,
5721 .data = .{ .load_store_stack = .{5721 .data = .{ .load_store_stack = .{
5722 .rt = reg,5722 .rt = reg,
5723 .offset = @intCast(u32, off),5723 .offset = @as(u32, @intCast(off)),
5724 } },5724 } },
5725 });5725 });
5726 },5726 },
...@@ -5733,7 +5733,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5733,7 +5733,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
57335733
5734fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {5734fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
5735 const mod = self.bin_file.options.module.?;5735 const mod = self.bin_file.options.module.?;
5736 const abi_size = @intCast(u32, ty.abiSize(mod));5736 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
5737 switch (mcv) {5737 switch (mcv) {
5738 .dead => unreachable,5738 .dead => unreachable,
5739 .none, .unreach => return,5739 .none, .unreach => return,
...@@ -5840,7 +5840,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I...@@ -5840,7 +5840,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
5840 } },5840 } },
5841 });5841 });
5842 },5842 },
5843 .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @intCast(u32, addr) }),5843 .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @as(u32, @intCast(addr)) }),
5844 .linker_load => |load_struct| {5844 .linker_load => |load_struct| {
5845 const tag: Mir.Inst.Tag = switch (load_struct.type) {5845 const tag: Mir.Inst.Tag = switch (load_struct.type) {
5846 .got => .load_memory_ptr_got,5846 .got => .load_memory_ptr_got,
...@@ -5937,7 +5937,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {...@@ -5937,7 +5937,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
5937 const ptr_ty = self.typeOf(ty_op.operand);5937 const ptr_ty = self.typeOf(ty_op.operand);
5938 const ptr = try self.resolveInst(ty_op.operand);5938 const ptr = try self.resolveInst(ty_op.operand);
5939 const array_ty = ptr_ty.childType(mod);5939 const array_ty = ptr_ty.childType(mod);
5940 const array_len = @intCast(u32, array_ty.arrayLen(mod));5940 const array_len = @as(u32, @intCast(array_ty.arrayLen(mod)));
59415941
5942 const ptr_bits = self.target.ptrBitWidth();5942 const ptr_bits = self.target.ptrBitWidth();
5943 const ptr_bytes = @divExact(ptr_bits, 8);5943 const ptr_bytes = @divExact(ptr_bits, 8);
...@@ -6058,7 +6058,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -6058,7 +6058,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
6058 const vector_ty = self.typeOfIndex(inst);6058 const vector_ty = self.typeOfIndex(inst);
6059 const len = vector_ty.vectorLen(mod);6059 const len = vector_ty.vectorLen(mod);
6060 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;6060 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
6061 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);6061 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
6062 const result: MCValue = res: {6062 const result: MCValue = res: {
6063 if (self.liveness.isUnused(inst)) break :res MCValue.dead;6063 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
6064 return self.fail("TODO implement airAggregateInit for {}", .{self.target.cpu.arch});6064 return self.fail("TODO implement airAggregateInit for {}", .{self.target.cpu.arch});
...@@ -6105,7 +6105,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {...@@ -6105,7 +6105,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
6105 const result: MCValue = result: {6105 const result: MCValue = result: {
6106 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };6106 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };
6107 const error_union_ty = self.typeOf(pl_op.operand);6107 const error_union_ty = self.typeOf(pl_op.operand);
6108 const error_union_size = @intCast(u32, error_union_ty.abiSize(mod));6108 const error_union_size = @as(u32, @intCast(error_union_ty.abiSize(mod)));
6109 const error_union_align = error_union_ty.abiAlignment(mod);6109 const error_union_align = error_union_ty.abiAlignment(mod);
61106110
6111 // The error union will die in the body. However, we need the6111 // The error union will die in the body. However, we need the
...@@ -6247,7 +6247,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6247,7 +6247,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6247 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod) and !ret_ty.isError(mod)) {6247 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod) and !ret_ty.isError(mod)) {
6248 result.return_value = .{ .none = {} };6248 result.return_value = .{ .none = {} };
6249 } else {6249 } else {
6250 const ret_ty_size = @intCast(u32, ret_ty.abiSize(mod));6250 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
6251 if (ret_ty_size == 0) {6251 if (ret_ty_size == 0) {
6252 assert(ret_ty.isError(mod));6252 assert(ret_ty.isError(mod));
6253 result.return_value = .{ .immediate = 0 };6253 result.return_value = .{ .immediate = 0 };
...@@ -6259,7 +6259,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6259,7 +6259,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6259 }6259 }
62606260
6261 for (fn_info.param_types, 0..) |ty, i| {6261 for (fn_info.param_types, 0..) |ty, i| {
6262 const param_size = @intCast(u32, ty.toType().abiSize(mod));6262 const param_size = @as(u32, @intCast(ty.toType().abiSize(mod)));
6263 if (param_size == 0) {6263 if (param_size == 0) {
6264 result.args[i] = .{ .none = {} };6264 result.args[i] = .{ .none = {} };
6265 continue;6265 continue;
...@@ -6305,7 +6305,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6305,7 +6305,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6305 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod) and !ret_ty.isError(mod)) {6305 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod) and !ret_ty.isError(mod)) {
6306 result.return_value = .{ .none = {} };6306 result.return_value = .{ .none = {} };
6307 } else {6307 } else {
6308 const ret_ty_size = @intCast(u32, ret_ty.abiSize(mod));6308 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
6309 if (ret_ty_size == 0) {6309 if (ret_ty_size == 0) {
6310 assert(ret_ty.isError(mod));6310 assert(ret_ty.isError(mod));
6311 result.return_value = .{ .immediate = 0 };6311 result.return_value = .{ .immediate = 0 };
...@@ -6325,7 +6325,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6325,7 +6325,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
63256325
6326 for (fn_info.param_types, 0..) |ty, i| {6326 for (fn_info.param_types, 0..) |ty, i| {
6327 if (ty.toType().abiSize(mod) > 0) {6327 if (ty.toType().abiSize(mod) > 0) {
6328 const param_size = @intCast(u32, ty.toType().abiSize(mod));6328 const param_size = @as(u32, @intCast(ty.toType().abiSize(mod)));
6329 const param_alignment = ty.toType().abiAlignment(mod);6329 const param_alignment = ty.toType().abiAlignment(mod);
63306330
6331 stack_offset = std.mem.alignForward(u32, stack_offset, param_alignment);6331 stack_offset = std.mem.alignForward(u32, stack_offset, param_alignment);
src/arch/aarch64/Emit.zig+22-22
...@@ -81,7 +81,7 @@ pub fn emitMir(...@@ -81,7 +81,7 @@ pub fn emitMir(
8181
82 // Emit machine code82 // Emit machine code
83 for (mir_tags, 0..) |tag, index| {83 for (mir_tags, 0..) |tag, index| {
84 const inst = @intCast(u32, index);84 const inst = @as(u32, @intCast(index));
85 switch (tag) {85 switch (tag) {
86 .add_immediate => try emit.mirAddSubtractImmediate(inst),86 .add_immediate => try emit.mirAddSubtractImmediate(inst),
87 .adds_immediate => try emit.mirAddSubtractImmediate(inst),87 .adds_immediate => try emit.mirAddSubtractImmediate(inst),
...@@ -324,7 +324,7 @@ fn lowerBranches(emit: *Emit) !void {...@@ -324,7 +324,7 @@ fn lowerBranches(emit: *Emit) !void {
324 // TODO optimization opportunity: do this in codegen while324 // TODO optimization opportunity: do this in codegen while
325 // generating MIR325 // generating MIR
326 for (mir_tags, 0..) |tag, index| {326 for (mir_tags, 0..) |tag, index| {
327 const inst = @intCast(u32, index);327 const inst = @as(u32, @intCast(index));
328 if (isBranch(tag)) {328 if (isBranch(tag)) {
329 const target_inst = emit.branchTarget(inst);329 const target_inst = emit.branchTarget(inst);
330330
...@@ -369,7 +369,7 @@ fn lowerBranches(emit: *Emit) !void {...@@ -369,7 +369,7 @@ fn lowerBranches(emit: *Emit) !void {
369 var current_code_offset: usize = 0;369 var current_code_offset: usize = 0;
370370
371 for (mir_tags, 0..) |tag, index| {371 for (mir_tags, 0..) |tag, index| {
372 const inst = @intCast(u32, index);372 const inst = @as(u32, @intCast(index));
373373
374 // If this instruction contained in the code offset374 // If this instruction contained in the code offset
375 // mapping (when it is a target of a branch or if it is a375 // mapping (when it is a target of a branch or if it is a
...@@ -384,7 +384,7 @@ fn lowerBranches(emit: *Emit) !void {...@@ -384,7 +384,7 @@ fn lowerBranches(emit: *Emit) !void {
384 const target_inst = emit.branchTarget(inst);384 const target_inst = emit.branchTarget(inst);
385 if (target_inst < inst) {385 if (target_inst < inst) {
386 const target_offset = emit.code_offset_mapping.get(target_inst).?;386 const target_offset = emit.code_offset_mapping.get(target_inst).?;
387 const offset = @intCast(i64, target_offset) - @intCast(i64, current_code_offset);387 const offset = @as(i64, @intCast(target_offset)) - @as(i64, @intCast(current_code_offset));
388 const branch_type = emit.branch_types.getPtr(inst).?;388 const branch_type = emit.branch_types.getPtr(inst).?;
389 const optimal_branch_type = try emit.optimalBranchType(tag, offset);389 const optimal_branch_type = try emit.optimalBranchType(tag, offset);
390 if (branch_type.* != optimal_branch_type) {390 if (branch_type.* != optimal_branch_type) {
...@@ -403,7 +403,7 @@ fn lowerBranches(emit: *Emit) !void {...@@ -403,7 +403,7 @@ fn lowerBranches(emit: *Emit) !void {
403 for (origin_list.items) |forward_branch_inst| {403 for (origin_list.items) |forward_branch_inst| {
404 const branch_tag = emit.mir.instructions.items(.tag)[forward_branch_inst];404 const branch_tag = emit.mir.instructions.items(.tag)[forward_branch_inst];
405 const forward_branch_inst_offset = emit.code_offset_mapping.get(forward_branch_inst).?;405 const forward_branch_inst_offset = emit.code_offset_mapping.get(forward_branch_inst).?;
406 const offset = @intCast(i64, current_code_offset) - @intCast(i64, forward_branch_inst_offset);406 const offset = @as(i64, @intCast(current_code_offset)) - @as(i64, @intCast(forward_branch_inst_offset));
407 const branch_type = emit.branch_types.getPtr(forward_branch_inst).?;407 const branch_type = emit.branch_types.getPtr(forward_branch_inst).?;
408 const optimal_branch_type = try emit.optimalBranchType(branch_tag, offset);408 const optimal_branch_type = try emit.optimalBranchType(branch_tag, offset);
409 if (branch_type.* != optimal_branch_type) {409 if (branch_type.* != optimal_branch_type) {
...@@ -434,7 +434,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {...@@ -434,7 +434,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
434}434}
435435
436fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {436fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {
437 const delta_line = @intCast(i32, line) - @intCast(i32, self.prev_di_line);437 const delta_line = @as(i32, @intCast(line)) - @as(i32, @intCast(self.prev_di_line));
438 const delta_pc: usize = self.code.items.len - self.prev_di_pc;438 const delta_pc: usize = self.code.items.len - self.prev_di_pc;
439 switch (self.debug_output) {439 switch (self.debug_output) {
440 .dwarf => |dw| {440 .dwarf => |dw| {
...@@ -451,13 +451,13 @@ fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {...@@ -451,13 +451,13 @@ fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {
451 // increasing the line number451 // increasing the line number
452 try @import("../../link/Plan9.zig").changeLine(dbg_out.dbg_line, delta_line);452 try @import("../../link/Plan9.zig").changeLine(dbg_out.dbg_line, delta_line);
453 // increasing the pc453 // increasing the pc
454 const d_pc_p9 = @intCast(i64, delta_pc) - quant;454 const d_pc_p9 = @as(i64, @intCast(delta_pc)) - quant;
455 if (d_pc_p9 > 0) {455 if (d_pc_p9 > 0) {
456 // minus one because if its the last one, we want to leave space to change the line which is one quanta456 // minus one because if its the last one, we want to leave space to change the line which is one quanta
457 try dbg_out.dbg_line.append(@intCast(u8, @divExact(d_pc_p9, quant) + 128) - quant);457 try dbg_out.dbg_line.append(@as(u8, @intCast(@divExact(d_pc_p9, quant) + 128)) - quant);
458 if (dbg_out.pcop_change_index.*) |pci|458 if (dbg_out.pcop_change_index.*) |pci|
459 dbg_out.dbg_line.items[pci] += 1;459 dbg_out.dbg_line.items[pci] += 1;
460 dbg_out.pcop_change_index.* = @intCast(u32, dbg_out.dbg_line.items.len - 1);460 dbg_out.pcop_change_index.* = @as(u32, @intCast(dbg_out.dbg_line.items.len - 1));
461 } else if (d_pc_p9 == 0) {461 } else if (d_pc_p9 == 0) {
462 // we don't need to do anything, because adding the quant does it for us462 // we don't need to do anything, because adding the quant does it for us
463 } else unreachable;463 } else unreachable;
...@@ -548,13 +548,13 @@ fn mirConditionalBranchImmediate(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -548,13 +548,13 @@ fn mirConditionalBranchImmediate(emit: *Emit, inst: Mir.Inst.Index) !void {
548 const tag = emit.mir.instructions.items(.tag)[inst];548 const tag = emit.mir.instructions.items(.tag)[inst];
549 const inst_cond = emit.mir.instructions.items(.data)[inst].inst_cond;549 const inst_cond = emit.mir.instructions.items(.data)[inst].inst_cond;
550550
551 const offset = @intCast(i64, emit.code_offset_mapping.get(inst_cond.inst).?) - @intCast(i64, emit.code.items.len);551 const offset = @as(i64, @intCast(emit.code_offset_mapping.get(inst_cond.inst).?)) - @as(i64, @intCast(emit.code.items.len));
552 const branch_type = emit.branch_types.get(inst).?;552 const branch_type = emit.branch_types.get(inst).?;
553 log.debug("mirConditionalBranchImmediate: {} offset={}", .{ inst, offset });553 log.debug("mirConditionalBranchImmediate: {} offset={}", .{ inst, offset });
554554
555 switch (branch_type) {555 switch (branch_type) {
556 .b_cond => switch (tag) {556 .b_cond => switch (tag) {
557 .b_cond => try emit.writeInstruction(Instruction.bCond(inst_cond.cond, @intCast(i21, offset))),557 .b_cond => try emit.writeInstruction(Instruction.bCond(inst_cond.cond, @as(i21, @intCast(offset)))),
558 else => unreachable,558 else => unreachable,
559 },559 },
560 else => unreachable,560 else => unreachable,
...@@ -572,14 +572,14 @@ fn mirBranch(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -572,14 +572,14 @@ fn mirBranch(emit: *Emit, inst: Mir.Inst.Index) !void {
572 emit.mir.instructions.items(.tag)[target_inst],572 emit.mir.instructions.items(.tag)[target_inst],
573 });573 });
574574
575 const offset = @intCast(i64, emit.code_offset_mapping.get(target_inst).?) - @intCast(i64, emit.code.items.len);575 const offset = @as(i64, @intCast(emit.code_offset_mapping.get(target_inst).?)) - @as(i64, @intCast(emit.code.items.len));
576 const branch_type = emit.branch_types.get(inst).?;576 const branch_type = emit.branch_types.get(inst).?;
577 log.debug("mirBranch: {} offset={}", .{ inst, offset });577 log.debug("mirBranch: {} offset={}", .{ inst, offset });
578578
579 switch (branch_type) {579 switch (branch_type) {
580 .unconditional_branch_immediate => switch (tag) {580 .unconditional_branch_immediate => switch (tag) {
581 .b => try emit.writeInstruction(Instruction.b(@intCast(i28, offset))),581 .b => try emit.writeInstruction(Instruction.b(@as(i28, @intCast(offset)))),
582 .bl => try emit.writeInstruction(Instruction.bl(@intCast(i28, offset))),582 .bl => try emit.writeInstruction(Instruction.bl(@as(i28, @intCast(offset)))),
583 else => unreachable,583 else => unreachable,
584 },584 },
585 else => unreachable,585 else => unreachable,
...@@ -590,13 +590,13 @@ fn mirCompareAndBranch(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -590,13 +590,13 @@ fn mirCompareAndBranch(emit: *Emit, inst: Mir.Inst.Index) !void {
590 const tag = emit.mir.instructions.items(.tag)[inst];590 const tag = emit.mir.instructions.items(.tag)[inst];
591 const r_inst = emit.mir.instructions.items(.data)[inst].r_inst;591 const r_inst = emit.mir.instructions.items(.data)[inst].r_inst;
592592
593 const offset = @intCast(i64, emit.code_offset_mapping.get(r_inst.inst).?) - @intCast(i64, emit.code.items.len);593 const offset = @as(i64, @intCast(emit.code_offset_mapping.get(r_inst.inst).?)) - @as(i64, @intCast(emit.code.items.len));
594 const branch_type = emit.branch_types.get(inst).?;594 const branch_type = emit.branch_types.get(inst).?;
595 log.debug("mirCompareAndBranch: {} offset={}", .{ inst, offset });595 log.debug("mirCompareAndBranch: {} offset={}", .{ inst, offset });
596596
597 switch (branch_type) {597 switch (branch_type) {
598 .cbz => switch (tag) {598 .cbz => switch (tag) {
599 .cbz => try emit.writeInstruction(Instruction.cbz(r_inst.rt, @intCast(i21, offset))),599 .cbz => try emit.writeInstruction(Instruction.cbz(r_inst.rt, @as(i21, @intCast(offset)))),
600 else => unreachable,600 else => unreachable,
601 },601 },
602 else => unreachable,602 else => unreachable,
...@@ -662,7 +662,7 @@ fn mirCallExtern(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -662,7 +662,7 @@ fn mirCallExtern(emit: *Emit, inst: Mir.Inst.Index) !void {
662 const relocation = emit.mir.instructions.items(.data)[inst].relocation;662 const relocation = emit.mir.instructions.items(.data)[inst].relocation;
663663
664 const offset = blk: {664 const offset = blk: {
665 const offset = @intCast(u32, emit.code.items.len);665 const offset = @as(u32, @intCast(emit.code.items.len));
666 // bl666 // bl
667 try emit.writeInstruction(Instruction.bl(0));667 try emit.writeInstruction(Instruction.bl(0));
668 break :blk offset;668 break :blk offset;
...@@ -837,11 +837,11 @@ fn mirLoadMemoryPie(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -837,11 +837,11 @@ fn mirLoadMemoryPie(emit: *Emit, inst: Mir.Inst.Index) !void {
837 const tag = emit.mir.instructions.items(.tag)[inst];837 const tag = emit.mir.instructions.items(.tag)[inst];
838 const payload = emit.mir.instructions.items(.data)[inst].payload;838 const payload = emit.mir.instructions.items(.data)[inst].payload;
839 const data = emit.mir.extraData(Mir.LoadMemoryPie, payload).data;839 const data = emit.mir.extraData(Mir.LoadMemoryPie, payload).data;
840 const reg = @enumFromInt(Register, data.register);840 const reg = @as(Register, @enumFromInt(data.register));
841841
842 // PC-relative displacement to the entry in memory.842 // PC-relative displacement to the entry in memory.
843 // adrp843 // adrp
844 const offset = @intCast(u32, emit.code.items.len);844 const offset = @as(u32, @intCast(emit.code.items.len));
845 try emit.writeInstruction(Instruction.adrp(reg.toX(), 0));845 try emit.writeInstruction(Instruction.adrp(reg.toX(), 0));
846846
847 switch (tag) {847 switch (tag) {
...@@ -1220,7 +1220,7 @@ fn mirNop(emit: *Emit) !void {...@@ -1220,7 +1220,7 @@ fn mirNop(emit: *Emit) !void {
1220}1220}
12211221
1222fn regListIsSet(reg_list: u32, reg: Register) bool {1222fn regListIsSet(reg_list: u32, reg: Register) bool {
1223 return reg_list & @as(u32, 1) << @intCast(u5, reg.id()) != 0;1223 return reg_list & @as(u32, 1) << @as(u5, @intCast(reg.id())) != 0;
1224}1224}
12251225
1226fn mirPushPopRegs(emit: *Emit, inst: Mir.Inst.Index) !void {1226fn mirPushPopRegs(emit: *Emit, inst: Mir.Inst.Index) !void {
...@@ -1245,7 +1245,7 @@ fn mirPushPopRegs(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -1245,7 +1245,7 @@ fn mirPushPopRegs(emit: *Emit, inst: Mir.Inst.Index) !void {
1245 var count: u6 = 0;1245 var count: u6 = 0;
1246 var other_reg: ?Register = null;1246 var other_reg: ?Register = null;
1247 while (i > 0) : (i -= 1) {1247 while (i > 0) : (i -= 1) {
1248 const reg = @enumFromInt(Register, i - 1);1248 const reg = @as(Register, @enumFromInt(i - 1));
1249 if (regListIsSet(reg_list, reg)) {1249 if (regListIsSet(reg_list, reg)) {
1250 if (count == 0 and odd_number_of_regs) {1250 if (count == 0 and odd_number_of_regs) {
1251 try emit.writeInstruction(Instruction.ldr(1251 try emit.writeInstruction(Instruction.ldr(
...@@ -1274,7 +1274,7 @@ fn mirPushPopRegs(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -1274,7 +1274,7 @@ fn mirPushPopRegs(emit: *Emit, inst: Mir.Inst.Index) !void {
1274 var count: u6 = 0;1274 var count: u6 = 0;
1275 var other_reg: ?Register = null;1275 var other_reg: ?Register = null;
1276 while (i < 32) : (i += 1) {1276 while (i < 32) : (i += 1) {
1277 const reg = @enumFromInt(Register, i);1277 const reg = @as(Register, @enumFromInt(i));
1278 if (regListIsSet(reg_list, reg)) {1278 if (regListIsSet(reg_list, reg)) {
1279 if (count == number_of_regs - 1 and odd_number_of_regs) {1279 if (count == number_of_regs - 1 and odd_number_of_regs) {
1280 try emit.writeInstruction(Instruction.str(1280 try emit.writeInstruction(Instruction.str(
src/arch/aarch64/Mir.zig+1-1
...@@ -507,7 +507,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end...@@ -507,7 +507,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end
507 inline for (fields) |field| {507 inline for (fields) |field| {
508 @field(result, field.name) = switch (field.type) {508 @field(result, field.name) = switch (field.type) {
509 u32 => mir.extra[i],509 u32 => mir.extra[i],
510 i32 => @bitCast(i32, mir.extra[i]),510 i32 => @as(i32, @bitCast(mir.extra[i])),
511 else => @compileError("bad field type"),511 else => @compileError("bad field type"),
512 };512 };
513 i += 1;513 i += 1;
src/arch/aarch64/bits.zig+109-109
...@@ -80,34 +80,34 @@ pub const Register = enum(u8) {...@@ -80,34 +80,34 @@ pub const Register = enum(u8) {
8080
81 pub fn id(self: Register) u6 {81 pub fn id(self: Register) u6 {
82 return switch (@intFromEnum(self)) {82 return switch (@intFromEnum(self)) {
83 @intFromEnum(Register.x0)...@intFromEnum(Register.xzr) => @intCast(u6, @intFromEnum(self) - @intFromEnum(Register.x0)),83 @intFromEnum(Register.x0)...@intFromEnum(Register.xzr) => @as(u6, @intCast(@intFromEnum(self) - @intFromEnum(Register.x0))),
84 @intFromEnum(Register.w0)...@intFromEnum(Register.wzr) => @intCast(u6, @intFromEnum(self) - @intFromEnum(Register.w0)),84 @intFromEnum(Register.w0)...@intFromEnum(Register.wzr) => @as(u6, @intCast(@intFromEnum(self) - @intFromEnum(Register.w0))),
8585
86 @intFromEnum(Register.sp) => 32,86 @intFromEnum(Register.sp) => 32,
87 @intFromEnum(Register.wsp) => 32,87 @intFromEnum(Register.wsp) => 32,
8888
89 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @intCast(u6, @intFromEnum(self) - @intFromEnum(Register.q0) + 33),89 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @as(u6, @intCast(@intFromEnum(self) - @intFromEnum(Register.q0) + 33)),
90 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @intCast(u6, @intFromEnum(self) - @intFromEnum(Register.d0) + 33),90 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @as(u6, @intCast(@intFromEnum(self) - @intFromEnum(Register.d0) + 33)),
91 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @intCast(u6, @intFromEnum(self) - @intFromEnum(Register.s0) + 33),91 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @as(u6, @intCast(@intFromEnum(self) - @intFromEnum(Register.s0) + 33)),
92 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @intCast(u6, @intFromEnum(self) - @intFromEnum(Register.h0) + 33),92 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @as(u6, @intCast(@intFromEnum(self) - @intFromEnum(Register.h0) + 33)),
93 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @intCast(u6, @intFromEnum(self) - @intFromEnum(Register.b0) + 33),93 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @as(u6, @intCast(@intFromEnum(self) - @intFromEnum(Register.b0) + 33)),
94 else => unreachable,94 else => unreachable,
95 };95 };
96 }96 }
9797
98 pub fn enc(self: Register) u5 {98 pub fn enc(self: Register) u5 {
99 return switch (@intFromEnum(self)) {99 return switch (@intFromEnum(self)) {
100 @intFromEnum(Register.x0)...@intFromEnum(Register.xzr) => @intCast(u5, @intFromEnum(self) - @intFromEnum(Register.x0)),100 @intFromEnum(Register.x0)...@intFromEnum(Register.xzr) => @as(u5, @intCast(@intFromEnum(self) - @intFromEnum(Register.x0))),
101 @intFromEnum(Register.w0)...@intFromEnum(Register.wzr) => @intCast(u5, @intFromEnum(self) - @intFromEnum(Register.w0)),101 @intFromEnum(Register.w0)...@intFromEnum(Register.wzr) => @as(u5, @intCast(@intFromEnum(self) - @intFromEnum(Register.w0))),
102102
103 @intFromEnum(Register.sp) => 31,103 @intFromEnum(Register.sp) => 31,
104 @intFromEnum(Register.wsp) => 31,104 @intFromEnum(Register.wsp) => 31,
105105
106 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @intCast(u5, @intFromEnum(self) - @intFromEnum(Register.q0)),106 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @as(u5, @intCast(@intFromEnum(self) - @intFromEnum(Register.q0))),
107 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @intCast(u5, @intFromEnum(self) - @intFromEnum(Register.d0)),107 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @as(u5, @intCast(@intFromEnum(self) - @intFromEnum(Register.d0))),
108 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @intCast(u5, @intFromEnum(self) - @intFromEnum(Register.s0)),108 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @as(u5, @intCast(@intFromEnum(self) - @intFromEnum(Register.s0))),
109 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @intCast(u5, @intFromEnum(self) - @intFromEnum(Register.h0)),109 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @as(u5, @intCast(@intFromEnum(self) - @intFromEnum(Register.h0))),
110 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @intCast(u5, @intFromEnum(self) - @intFromEnum(Register.b0)),110 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @as(u5, @intCast(@intFromEnum(self) - @intFromEnum(Register.b0))),
111 else => unreachable,111 else => unreachable,
112 };112 };
113 }113 }
...@@ -133,13 +133,13 @@ pub const Register = enum(u8) {...@@ -133,13 +133,13 @@ pub const Register = enum(u8) {
133 /// Convert from a general-purpose register to its 64 bit alias.133 /// Convert from a general-purpose register to its 64 bit alias.
134 pub fn toX(self: Register) Register {134 pub fn toX(self: Register) Register {
135 return switch (@intFromEnum(self)) {135 return switch (@intFromEnum(self)) {
136 @intFromEnum(Register.x0)...@intFromEnum(Register.xzr) => @enumFromInt(136 @intFromEnum(Register.x0)...@intFromEnum(Register.xzr) => @as(
137 Register,137 Register,
138 @intFromEnum(self) - @intFromEnum(Register.x0) + @intFromEnum(Register.x0),138 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.x0) + @intFromEnum(Register.x0)),
139 ),139 ),
140 @intFromEnum(Register.w0)...@intFromEnum(Register.wzr) => @enumFromInt(140 @intFromEnum(Register.w0)...@intFromEnum(Register.wzr) => @as(
141 Register,141 Register,
142 @intFromEnum(self) - @intFromEnum(Register.w0) + @intFromEnum(Register.x0),142 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.w0) + @intFromEnum(Register.x0)),
143 ),143 ),
144 else => unreachable,144 else => unreachable,
145 };145 };
...@@ -148,13 +148,13 @@ pub const Register = enum(u8) {...@@ -148,13 +148,13 @@ pub const Register = enum(u8) {
148 /// Convert from a general-purpose register to its 32 bit alias.148 /// Convert from a general-purpose register to its 32 bit alias.
149 pub fn toW(self: Register) Register {149 pub fn toW(self: Register) Register {
150 return switch (@intFromEnum(self)) {150 return switch (@intFromEnum(self)) {
151 @intFromEnum(Register.x0)...@intFromEnum(Register.xzr) => @enumFromInt(151 @intFromEnum(Register.x0)...@intFromEnum(Register.xzr) => @as(
152 Register,152 Register,
153 @intFromEnum(self) - @intFromEnum(Register.x0) + @intFromEnum(Register.w0),153 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.x0) + @intFromEnum(Register.w0)),
154 ),154 ),
155 @intFromEnum(Register.w0)...@intFromEnum(Register.wzr) => @enumFromInt(155 @intFromEnum(Register.w0)...@intFromEnum(Register.wzr) => @as(
156 Register,156 Register,
157 @intFromEnum(self) - @intFromEnum(Register.w0) + @intFromEnum(Register.w0),157 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.w0) + @intFromEnum(Register.w0)),
158 ),158 ),
159 else => unreachable,159 else => unreachable,
160 };160 };
...@@ -163,25 +163,25 @@ pub const Register = enum(u8) {...@@ -163,25 +163,25 @@ pub const Register = enum(u8) {
163 /// Convert from a floating-point register to its 128 bit alias.163 /// Convert from a floating-point register to its 128 bit alias.
164 pub fn toQ(self: Register) Register {164 pub fn toQ(self: Register) Register {
165 return switch (@intFromEnum(self)) {165 return switch (@intFromEnum(self)) {
166 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @enumFromInt(166 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @as(
167 Register,167 Register,
168 @intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.q0),168 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.q0)),
169 ),169 ),
170 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @enumFromInt(170 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @as(
171 Register,171 Register,
172 @intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.q0),172 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.q0)),
173 ),173 ),
174 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @enumFromInt(174 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @as(
175 Register,175 Register,
176 @intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.q0),176 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.q0)),
177 ),177 ),
178 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @enumFromInt(178 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @as(
179 Register,179 Register,
180 @intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.q0),180 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.q0)),
181 ),181 ),
182 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @enumFromInt(182 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @as(
183 Register,183 Register,
184 @intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.q0),184 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.q0)),
185 ),185 ),
186 else => unreachable,186 else => unreachable,
187 };187 };
...@@ -190,25 +190,25 @@ pub const Register = enum(u8) {...@@ -190,25 +190,25 @@ pub const Register = enum(u8) {
190 /// Convert from a floating-point register to its 64 bit alias.190 /// Convert from a floating-point register to its 64 bit alias.
191 pub fn toD(self: Register) Register {191 pub fn toD(self: Register) Register {
192 return switch (@intFromEnum(self)) {192 return switch (@intFromEnum(self)) {
193 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @enumFromInt(193 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @as(
194 Register,194 Register,
195 @intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.d0),195 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.d0)),
196 ),196 ),
197 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @enumFromInt(197 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @as(
198 Register,198 Register,
199 @intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.d0),199 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.d0)),
200 ),200 ),
201 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @enumFromInt(201 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @as(
202 Register,202 Register,
203 @intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.d0),203 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.d0)),
204 ),204 ),
205 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @enumFromInt(205 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @as(
206 Register,206 Register,
207 @intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.d0),207 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.d0)),
208 ),208 ),
209 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @enumFromInt(209 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @as(
210 Register,210 Register,
211 @intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.d0),211 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.d0)),
212 ),212 ),
213 else => unreachable,213 else => unreachable,
214 };214 };
...@@ -217,25 +217,25 @@ pub const Register = enum(u8) {...@@ -217,25 +217,25 @@ pub const Register = enum(u8) {
217 /// Convert from a floating-point register to its 32 bit alias.217 /// Convert from a floating-point register to its 32 bit alias.
218 pub fn toS(self: Register) Register {218 pub fn toS(self: Register) Register {
219 return switch (@intFromEnum(self)) {219 return switch (@intFromEnum(self)) {
220 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @enumFromInt(220 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @as(
221 Register,221 Register,
222 @intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.s0),222 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.s0)),
223 ),223 ),
224 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @enumFromInt(224 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @as(
225 Register,225 Register,
226 @intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.s0),226 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.s0)),
227 ),227 ),
228 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @enumFromInt(228 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @as(
229 Register,229 Register,
230 @intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.s0),230 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.s0)),
231 ),231 ),
232 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @enumFromInt(232 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @as(
233 Register,233 Register,
234 @intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.s0),234 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.s0)),
235 ),235 ),
236 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @enumFromInt(236 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @as(
237 Register,237 Register,
238 @intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.s0),238 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.s0)),
239 ),239 ),
240 else => unreachable,240 else => unreachable,
241 };241 };
...@@ -244,25 +244,25 @@ pub const Register = enum(u8) {...@@ -244,25 +244,25 @@ pub const Register = enum(u8) {
244 /// Convert from a floating-point register to its 16 bit alias.244 /// Convert from a floating-point register to its 16 bit alias.
245 pub fn toH(self: Register) Register {245 pub fn toH(self: Register) Register {
246 return switch (@intFromEnum(self)) {246 return switch (@intFromEnum(self)) {
247 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @enumFromInt(247 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @as(
248 Register,248 Register,
249 @intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.h0),249 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.h0)),
250 ),250 ),
251 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @enumFromInt(251 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @as(
252 Register,252 Register,
253 @intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.h0),253 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.h0)),
254 ),254 ),
255 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @enumFromInt(255 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @as(
256 Register,256 Register,
257 @intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.h0),257 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.h0)),
258 ),258 ),
259 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @enumFromInt(259 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @as(
260 Register,260 Register,
261 @intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.h0),261 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.h0)),
262 ),262 ),
263 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @enumFromInt(263 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @as(
264 Register,264 Register,
265 @intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.h0),265 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.h0)),
266 ),266 ),
267 else => unreachable,267 else => unreachable,
268 };268 };
...@@ -271,25 +271,25 @@ pub const Register = enum(u8) {...@@ -271,25 +271,25 @@ pub const Register = enum(u8) {
271 /// Convert from a floating-point register to its 8 bit alias.271 /// Convert from a floating-point register to its 8 bit alias.
272 pub fn toB(self: Register) Register {272 pub fn toB(self: Register) Register {
273 return switch (@intFromEnum(self)) {273 return switch (@intFromEnum(self)) {
274 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @enumFromInt(274 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @as(
275 Register,275 Register,
276 @intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.b0),276 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.b0)),
277 ),277 ),
278 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @enumFromInt(278 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @as(
279 Register,279 Register,
280 @intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.b0),280 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.b0)),
281 ),281 ),
282 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @enumFromInt(282 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @as(
283 Register,283 Register,
284 @intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.b0),284 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.b0)),
285 ),285 ),
286 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @enumFromInt(286 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @as(
287 Register,287 Register,
288 @intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.b0),288 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.b0)),
289 ),289 ),
290 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @enumFromInt(290 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @as(
291 Register,291 Register,
292 @intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.b0),292 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.b0)),
293 ),293 ),
294 else => unreachable,294 else => unreachable,
295 };295 };
...@@ -612,27 +612,27 @@ pub const Instruction = union(enum) {...@@ -612,27 +612,27 @@ pub const Instruction = union(enum) {
612612
613 pub fn toU32(self: Instruction) u32 {613 pub fn toU32(self: Instruction) u32 {
614 return switch (self) {614 return switch (self) {
615 .move_wide_immediate => |v| @bitCast(u32, v),615 .move_wide_immediate => |v| @as(u32, @bitCast(v)),
616 .pc_relative_address => |v| @bitCast(u32, v),616 .pc_relative_address => |v| @as(u32, @bitCast(v)),
617 .load_store_register => |v| @bitCast(u32, v),617 .load_store_register => |v| @as(u32, @bitCast(v)),
618 .load_store_register_pair => |v| @bitCast(u32, v),618 .load_store_register_pair => |v| @as(u32, @bitCast(v)),
619 .load_literal => |v| @bitCast(u32, v),619 .load_literal => |v| @as(u32, @bitCast(v)),
620 .exception_generation => |v| @bitCast(u32, v),620 .exception_generation => |v| @as(u32, @bitCast(v)),
621 .unconditional_branch_register => |v| @bitCast(u32, v),621 .unconditional_branch_register => |v| @as(u32, @bitCast(v)),
622 .unconditional_branch_immediate => |v| @bitCast(u32, v),622 .unconditional_branch_immediate => |v| @as(u32, @bitCast(v)),
623 .no_operation => |v| @bitCast(u32, v),623 .no_operation => |v| @as(u32, @bitCast(v)),
624 .logical_shifted_register => |v| @bitCast(u32, v),624 .logical_shifted_register => |v| @as(u32, @bitCast(v)),
625 .add_subtract_immediate => |v| @bitCast(u32, v),625 .add_subtract_immediate => |v| @as(u32, @bitCast(v)),
626 .logical_immediate => |v| @bitCast(u32, v),626 .logical_immediate => |v| @as(u32, @bitCast(v)),
627 .bitfield => |v| @bitCast(u32, v),627 .bitfield => |v| @as(u32, @bitCast(v)),
628 .add_subtract_shifted_register => |v| @bitCast(u32, v),628 .add_subtract_shifted_register => |v| @as(u32, @bitCast(v)),
629 .add_subtract_extended_register => |v| @bitCast(u32, v),629 .add_subtract_extended_register => |v| @as(u32, @bitCast(v)),
630 // TODO once packed structs work, this can be refactored630 // TODO once packed structs work, this can be refactored
631 .conditional_branch => |v| @as(u32, v.cond) | (@as(u32, v.o0) << 4) | (@as(u32, v.imm19) << 5) | (@as(u32, v.o1) << 24) | (@as(u32, v.fixed) << 25),631 .conditional_branch => |v| @as(u32, v.cond) | (@as(u32, v.o0) << 4) | (@as(u32, v.imm19) << 5) | (@as(u32, v.o1) << 24) | (@as(u32, v.fixed) << 25),
632 .compare_and_branch => |v| @as(u32, v.rt) | (@as(u32, v.imm19) << 5) | (@as(u32, v.op) << 24) | (@as(u32, v.fixed) << 25) | (@as(u32, v.sf) << 31),632 .compare_and_branch => |v| @as(u32, v.rt) | (@as(u32, v.imm19) << 5) | (@as(u32, v.op) << 24) | (@as(u32, v.fixed) << 25) | (@as(u32, v.sf) << 31),
633 .conditional_select => |v| @as(u32, v.rd) | @as(u32, v.rn) << 5 | @as(u32, v.op2) << 10 | @as(u32, v.cond) << 12 | @as(u32, v.rm) << 16 | @as(u32, v.fixed) << 21 | @as(u32, v.s) << 29 | @as(u32, v.op) << 30 | @as(u32, v.sf) << 31,633 .conditional_select => |v| @as(u32, v.rd) | @as(u32, v.rn) << 5 | @as(u32, v.op2) << 10 | @as(u32, v.cond) << 12 | @as(u32, v.rm) << 16 | @as(u32, v.fixed) << 21 | @as(u32, v.s) << 29 | @as(u32, v.op) << 30 | @as(u32, v.sf) << 31,
634 .data_processing_3_source => |v| @bitCast(u32, v),634 .data_processing_3_source => |v| @as(u32, @bitCast(v)),
635 .data_processing_2_source => |v| @bitCast(u32, v),635 .data_processing_2_source => |v| @as(u32, @bitCast(v)),
636 };636 };
637 }637 }
638638
...@@ -650,7 +650,7 @@ pub const Instruction = union(enum) {...@@ -650,7 +650,7 @@ pub const Instruction = union(enum) {
650 .move_wide_immediate = .{650 .move_wide_immediate = .{
651 .rd = rd.enc(),651 .rd = rd.enc(),
652 .imm16 = imm16,652 .imm16 = imm16,
653 .hw = @intCast(u2, shift / 16),653 .hw = @as(u2, @intCast(shift / 16)),
654 .opc = opc,654 .opc = opc,
655 .sf = switch (rd.size()) {655 .sf = switch (rd.size()) {
656 32 => 0,656 32 => 0,
...@@ -663,12 +663,12 @@ pub const Instruction = union(enum) {...@@ -663,12 +663,12 @@ pub const Instruction = union(enum) {
663663
664 fn pcRelativeAddress(rd: Register, imm21: i21, op: u1) Instruction {664 fn pcRelativeAddress(rd: Register, imm21: i21, op: u1) Instruction {
665 assert(rd.size() == 64);665 assert(rd.size() == 64);
666 const imm21_u = @bitCast(u21, imm21);666 const imm21_u = @as(u21, @bitCast(imm21));
667 return Instruction{667 return Instruction{
668 .pc_relative_address = .{668 .pc_relative_address = .{
669 .rd = rd.enc(),669 .rd = rd.enc(),
670 .immlo = @truncate(u2, imm21_u),670 .immlo = @as(u2, @truncate(imm21_u)),
671 .immhi = @truncate(u19, imm21_u >> 2),671 .immhi = @as(u19, @truncate(imm21_u >> 2)),
672 .op = op,672 .op = op,
673 },673 },
674 };674 };
...@@ -704,15 +704,15 @@ pub const Instruction = union(enum) {...@@ -704,15 +704,15 @@ pub const Instruction = union(enum) {
704 pub fn toU12(self: LoadStoreOffset) u12 {704 pub fn toU12(self: LoadStoreOffset) u12 {
705 return switch (self) {705 return switch (self) {
706 .immediate => |imm_type| switch (imm_type) {706 .immediate => |imm_type| switch (imm_type) {
707 .post_index => |v| (@intCast(u12, @bitCast(u9, v)) << 2) + 1,707 .post_index => |v| (@as(u12, @intCast(@as(u9, @bitCast(v)))) << 2) + 1,
708 .pre_index => |v| (@intCast(u12, @bitCast(u9, v)) << 2) + 3,708 .pre_index => |v| (@as(u12, @intCast(@as(u9, @bitCast(v)))) << 2) + 3,
709 .unsigned => |v| v,709 .unsigned => |v| v,
710 },710 },
711 .register => |r| switch (r.shift) {711 .register => |r| switch (r.shift) {
712 .uxtw => |v| (@intCast(u12, r.rm) << 6) + (@intCast(u12, v) << 2) + 16 + 2050,712 .uxtw => |v| (@as(u12, @intCast(r.rm)) << 6) + (@as(u12, @intCast(v)) << 2) + 16 + 2050,
713 .lsl => |v| (@intCast(u12, r.rm) << 6) + (@intCast(u12, v) << 2) + 24 + 2050,713 .lsl => |v| (@as(u12, @intCast(r.rm)) << 6) + (@as(u12, @intCast(v)) << 2) + 24 + 2050,
714 .sxtw => |v| (@intCast(u12, r.rm) << 6) + (@intCast(u12, v) << 2) + 48 + 2050,714 .sxtw => |v| (@as(u12, @intCast(r.rm)) << 6) + (@as(u12, @intCast(v)) << 2) + 48 + 2050,
715 .sxtx => |v| (@intCast(u12, r.rm) << 6) + (@intCast(u12, v) << 2) + 56 + 2050,715 .sxtx => |v| (@as(u12, @intCast(r.rm)) << 6) + (@as(u12, @intCast(v)) << 2) + 56 + 2050,
716 },716 },
717 };717 };
718 }718 }
...@@ -894,7 +894,7 @@ pub const Instruction = union(enum) {...@@ -894,7 +894,7 @@ pub const Instruction = union(enum) {
894 switch (rt1.size()) {894 switch (rt1.size()) {
895 32 => {895 32 => {
896 assert(-256 <= offset and offset <= 252);896 assert(-256 <= offset and offset <= 252);
897 const imm7 = @truncate(u7, @bitCast(u9, offset >> 2));897 const imm7 = @as(u7, @truncate(@as(u9, @bitCast(offset >> 2))));
898 return Instruction{898 return Instruction{
899 .load_store_register_pair = .{899 .load_store_register_pair = .{
900 .rt1 = rt1.enc(),900 .rt1 = rt1.enc(),
...@@ -909,7 +909,7 @@ pub const Instruction = union(enum) {...@@ -909,7 +909,7 @@ pub const Instruction = union(enum) {
909 },909 },
910 64 => {910 64 => {
911 assert(-512 <= offset and offset <= 504);911 assert(-512 <= offset and offset <= 504);
912 const imm7 = @truncate(u7, @bitCast(u9, offset >> 3));912 const imm7 = @as(u7, @truncate(@as(u9, @bitCast(offset >> 3))));
913 return Instruction{913 return Instruction{
914 .load_store_register_pair = .{914 .load_store_register_pair = .{
915 .rt1 = rt1.enc(),915 .rt1 = rt1.enc(),
...@@ -982,7 +982,7 @@ pub const Instruction = union(enum) {...@@ -982,7 +982,7 @@ pub const Instruction = union(enum) {
982 ) Instruction {982 ) Instruction {
983 return Instruction{983 return Instruction{
984 .unconditional_branch_immediate = .{984 .unconditional_branch_immediate = .{
985 .imm26 = @bitCast(u26, @intCast(i26, offset >> 2)),985 .imm26 = @as(u26, @bitCast(@as(i26, @intCast(offset >> 2)))),
986 .op = op,986 .op = op,
987 },987 },
988 };988 };
...@@ -1188,7 +1188,7 @@ pub const Instruction = union(enum) {...@@ -1188,7 +1188,7 @@ pub const Instruction = union(enum) {
1188 .conditional_branch = .{1188 .conditional_branch = .{
1189 .cond = @intFromEnum(cond),1189 .cond = @intFromEnum(cond),
1190 .o0 = o0,1190 .o0 = o0,
1191 .imm19 = @bitCast(u19, @intCast(i19, offset >> 2)),1191 .imm19 = @as(u19, @bitCast(@as(i19, @intCast(offset >> 2)))),
1192 .o1 = o1,1192 .o1 = o1,
1193 },1193 },
1194 };1194 };
...@@ -1204,7 +1204,7 @@ pub const Instruction = union(enum) {...@@ -1204,7 +1204,7 @@ pub const Instruction = union(enum) {
1204 return Instruction{1204 return Instruction{
1205 .compare_and_branch = .{1205 .compare_and_branch = .{
1206 .rt = rt.enc(),1206 .rt = rt.enc(),
1207 .imm19 = @bitCast(u19, @intCast(i19, offset >> 2)),1207 .imm19 = @as(u19, @bitCast(@as(i19, @intCast(offset >> 2)))),
1208 .op = op,1208 .op = op,
1209 .sf = switch (rt.size()) {1209 .sf = switch (rt.size()) {
1210 32 => 0b0,1210 32 => 0b0,
...@@ -1609,12 +1609,12 @@ pub const Instruction = union(enum) {...@@ -1609,12 +1609,12 @@ pub const Instruction = union(enum) {
1609 }1609 }
16101610
1611 pub fn asrImmediate(rd: Register, rn: Register, shift: u6) Instruction {1611 pub fn asrImmediate(rd: Register, rn: Register, shift: u6) Instruction {
1612 const imms = @intCast(u6, rd.size() - 1);1612 const imms = @as(u6, @intCast(rd.size() - 1));
1613 return sbfm(rd, rn, shift, imms);1613 return sbfm(rd, rn, shift, imms);
1614 }1614 }
16151615
1616 pub fn sbfx(rd: Register, rn: Register, lsb: u6, width: u7) Instruction {1616 pub fn sbfx(rd: Register, rn: Register, lsb: u6, width: u7) Instruction {
1617 return sbfm(rd, rn, lsb, @intCast(u6, lsb + width - 1));1617 return sbfm(rd, rn, lsb, @as(u6, @intCast(lsb + width - 1)));
1618 }1618 }
16191619
1620 pub fn sxtb(rd: Register, rn: Register) Instruction {1620 pub fn sxtb(rd: Register, rn: Register) Instruction {
...@@ -1631,17 +1631,17 @@ pub const Instruction = union(enum) {...@@ -1631,17 +1631,17 @@ pub const Instruction = union(enum) {
1631 }1631 }
16321632
1633 pub fn lslImmediate(rd: Register, rn: Register, shift: u6) Instruction {1633 pub fn lslImmediate(rd: Register, rn: Register, shift: u6) Instruction {
1634 const size = @intCast(u6, rd.size() - 1);1634 const size = @as(u6, @intCast(rd.size() - 1));
1635 return ubfm(rd, rn, size - shift + 1, size - shift);1635 return ubfm(rd, rn, size - shift + 1, size - shift);
1636 }1636 }
16371637
1638 pub fn lsrImmediate(rd: Register, rn: Register, shift: u6) Instruction {1638 pub fn lsrImmediate(rd: Register, rn: Register, shift: u6) Instruction {
1639 const imms = @intCast(u6, rd.size() - 1);1639 const imms = @as(u6, @intCast(rd.size() - 1));
1640 return ubfm(rd, rn, shift, imms);1640 return ubfm(rd, rn, shift, imms);
1641 }1641 }
16421642
1643 pub fn ubfx(rd: Register, rn: Register, lsb: u6, width: u7) Instruction {1643 pub fn ubfx(rd: Register, rn: Register, lsb: u6, width: u7) Instruction {
1644 return ubfm(rd, rn, lsb, @intCast(u6, lsb + width - 1));1644 return ubfm(rd, rn, lsb, @as(u6, @intCast(lsb + width - 1)));
1645 }1645 }
16461646
1647 pub fn uxtb(rd: Register, rn: Register) Instruction {1647 pub fn uxtb(rd: Register, rn: Register) Instruction {
src/arch/arm/CodeGen.zig+96-96
...@@ -266,8 +266,8 @@ const DbgInfoReloc = struct {...@@ -266,8 +266,8 @@ const DbgInfoReloc = struct {
266 .stack_argument_offset,266 .stack_argument_offset,
267 => blk: {267 => blk: {
268 const adjusted_stack_offset = switch (reloc.mcv) {268 const adjusted_stack_offset = switch (reloc.mcv) {
269 .stack_offset => |offset| -@intCast(i32, offset),269 .stack_offset => |offset| -@as(i32, @intCast(offset)),
270 .stack_argument_offset => |offset| @intCast(i32, function.saved_regs_stack_space + offset),270 .stack_argument_offset => |offset| @as(i32, @intCast(function.saved_regs_stack_space + offset)),
271 else => unreachable,271 else => unreachable,
272 };272 };
273 break :blk .{ .stack = .{273 break :blk .{ .stack = .{
...@@ -303,8 +303,8 @@ const DbgInfoReloc = struct {...@@ -303,8 +303,8 @@ const DbgInfoReloc = struct {
303 const adjusted_offset = switch (reloc.mcv) {303 const adjusted_offset = switch (reloc.mcv) {
304 .ptr_stack_offset,304 .ptr_stack_offset,
305 .stack_offset,305 .stack_offset,
306 => -@intCast(i32, offset),306 => -@as(i32, @intCast(offset)),
307 .stack_argument_offset => @intCast(i32, function.saved_regs_stack_space + offset),307 .stack_argument_offset => @as(i32, @intCast(function.saved_regs_stack_space + offset)),
308 else => unreachable,308 else => unreachable,
309 };309 };
310 break :blk .{ .stack = .{310 break :blk .{ .stack = .{
...@@ -446,7 +446,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {...@@ -446,7 +446,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
446446
447 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);447 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);
448448
449 const result_index = @intCast(Air.Inst.Index, self.mir_instructions.len);449 const result_index = @as(Air.Inst.Index, @intCast(self.mir_instructions.len));
450 self.mir_instructions.appendAssumeCapacity(inst);450 self.mir_instructions.appendAssumeCapacity(inst);
451 return result_index;451 return result_index;
452}452}
...@@ -466,11 +466,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {...@@ -466,11 +466,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {
466466
467pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {467pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
468 const fields = std.meta.fields(@TypeOf(extra));468 const fields = std.meta.fields(@TypeOf(extra));
469 const result = @intCast(u32, self.mir_extra.items.len);469 const result = @as(u32, @intCast(self.mir_extra.items.len));
470 inline for (fields) |field| {470 inline for (fields) |field| {
471 self.mir_extra.appendAssumeCapacity(switch (field.type) {471 self.mir_extra.appendAssumeCapacity(switch (field.type) {
472 u32 => @field(extra, field.name),472 u32 => @field(extra, field.name),
473 i32 => @bitCast(u32, @field(extra, field.name)),473 i32 => @as(u32, @bitCast(@field(extra, field.name))),
474 else => @compileError("bad field type"),474 else => @compileError("bad field type"),
475 });475 });
476 }476 }
...@@ -522,7 +522,7 @@ fn gen(self: *Self) !void {...@@ -522,7 +522,7 @@ fn gen(self: *Self) !void {
522522
523 const ty = self.typeOfIndex(inst);523 const ty = self.typeOfIndex(inst);
524524
525 const abi_size = @intCast(u32, ty.abiSize(mod));525 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
526 const abi_align = ty.abiAlignment(mod);526 const abi_align = ty.abiAlignment(mod);
527 const stack_offset = try self.allocMem(abi_size, abi_align, inst);527 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
528 try self.genSetStack(ty, stack_offset, MCValue{ .register = reg });528 try self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
...@@ -588,7 +588,7 @@ fn gen(self: *Self) !void {...@@ -588,7 +588,7 @@ fn gen(self: *Self) !void {
588 for (self.exitlude_jump_relocs.items) |jmp_reloc| {588 for (self.exitlude_jump_relocs.items) |jmp_reloc| {
589 self.mir_instructions.set(jmp_reloc, .{589 self.mir_instructions.set(jmp_reloc, .{
590 .tag = .b,590 .tag = .b,
591 .data = .{ .inst = @intCast(u32, self.mir_instructions.len) },591 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len)) },
592 });592 });
593 }593 }
594594
...@@ -934,15 +934,15 @@ fn finishAirBookkeeping(self: *Self) void {...@@ -934,15 +934,15 @@ fn finishAirBookkeeping(self: *Self) void {
934fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void {934fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void {
935 var tomb_bits = self.liveness.getTombBits(inst);935 var tomb_bits = self.liveness.getTombBits(inst);
936 for (operands) |op| {936 for (operands) |op| {
937 const dies = @truncate(u1, tomb_bits) != 0;937 const dies = @as(u1, @truncate(tomb_bits)) != 0;
938 tomb_bits >>= 1;938 tomb_bits >>= 1;
939 if (!dies) continue;939 if (!dies) continue;
940 const op_int = @intFromEnum(op);940 const op_int = @intFromEnum(op);
941 if (op_int < Air.ref_start_index) continue;941 if (op_int < Air.ref_start_index) continue;
942 const op_index = @intCast(Air.Inst.Index, op_int - Air.ref_start_index);942 const op_index = @as(Air.Inst.Index, @intCast(op_int - Air.ref_start_index));
943 self.processDeath(op_index);943 self.processDeath(op_index);
944 }944 }
945 const is_used = @truncate(u1, tomb_bits) == 0;945 const is_used = @as(u1, @truncate(tomb_bits)) == 0;
946 if (is_used) {946 if (is_used) {
947 log.debug("%{d} => {}", .{ inst, result });947 log.debug("%{d} => {}", .{ inst, result });
948 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];948 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
...@@ -1201,7 +1201,7 @@ fn truncRegister(...@@ -1201,7 +1201,7 @@ fn truncRegister(
1201 .rd = dest_reg,1201 .rd = dest_reg,
1202 .rn = operand_reg,1202 .rn = operand_reg,
1203 .lsb = 0,1203 .lsb = 0,
1204 .width = @intCast(u6, int_bits),1204 .width = @as(u6, @intCast(int_bits)),
1205 } },1205 } },
1206 });1206 });
1207}1207}
...@@ -1591,9 +1591,9 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1591,9 +1591,9 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
1591 const rhs_ty = self.typeOf(extra.rhs);1591 const rhs_ty = self.typeOf(extra.rhs);
15921592
1593 const tuple_ty = self.typeOfIndex(inst);1593 const tuple_ty = self.typeOfIndex(inst);
1594 const tuple_size = @intCast(u32, tuple_ty.abiSize(mod));1594 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(mod)));
1595 const tuple_align = tuple_ty.abiAlignment(mod);1595 const tuple_align = tuple_ty.abiAlignment(mod);
1596 const overflow_bit_offset = @intCast(u32, tuple_ty.structFieldOffset(1, mod));1596 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, mod)));
15971597
1598 switch (lhs_ty.zigTypeTag(mod)) {1598 switch (lhs_ty.zigTypeTag(mod)) {
1599 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),1599 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),
...@@ -1704,9 +1704,9 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1704,9 +1704,9 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
1704 const rhs_ty = self.typeOf(extra.rhs);1704 const rhs_ty = self.typeOf(extra.rhs);
17051705
1706 const tuple_ty = self.typeOfIndex(inst);1706 const tuple_ty = self.typeOfIndex(inst);
1707 const tuple_size = @intCast(u32, tuple_ty.abiSize(mod));1707 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(mod)));
1708 const tuple_align = tuple_ty.abiAlignment(mod);1708 const tuple_align = tuple_ty.abiAlignment(mod);
1709 const overflow_bit_offset = @intCast(u32, tuple_ty.structFieldOffset(1, mod));1709 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, mod)));
17101710
1711 switch (lhs_ty.zigTypeTag(mod)) {1711 switch (lhs_ty.zigTypeTag(mod)) {
1712 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),1712 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
...@@ -1866,9 +1866,9 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1866,9 +1866,9 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
1866 const rhs_ty = self.typeOf(extra.rhs);1866 const rhs_ty = self.typeOf(extra.rhs);
18671867
1868 const tuple_ty = self.typeOfIndex(inst);1868 const tuple_ty = self.typeOfIndex(inst);
1869 const tuple_size = @intCast(u32, tuple_ty.abiSize(mod));1869 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(mod)));
1870 const tuple_align = tuple_ty.abiAlignment(mod);1870 const tuple_align = tuple_ty.abiAlignment(mod);
1871 const overflow_bit_offset = @intCast(u32, tuple_ty.structFieldOffset(1, mod));1871 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, mod)));
18721872
1873 switch (lhs_ty.zigTypeTag(mod)) {1873 switch (lhs_ty.zigTypeTag(mod)) {
1874 .Vector => return self.fail("TODO implement shl_with_overflow for vectors", .{}),1874 .Vector => return self.fail("TODO implement shl_with_overflow for vectors", .{}),
...@@ -1915,7 +1915,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1915,7 +1915,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
1915 .data = .{ .rr_shift = .{1915 .data = .{ .rr_shift = .{
1916 .rd = dest_reg,1916 .rd = dest_reg,
1917 .rm = lhs_reg,1917 .rm = lhs_reg,
1918 .shift_amount = Instruction.ShiftAmount.imm(@intCast(u5, rhs_mcv.immediate)),1918 .shift_amount = Instruction.ShiftAmount.imm(@as(u5, @intCast(rhs_mcv.immediate))),
1919 } },1919 } },
1920 });1920 });
19211921
...@@ -1927,7 +1927,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1927,7 +1927,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
1927 .data = .{ .rr_shift = .{1927 .data = .{ .rr_shift = .{
1928 .rd = reconstructed_reg,1928 .rd = reconstructed_reg,
1929 .rm = dest_reg,1929 .rm = dest_reg,
1930 .shift_amount = Instruction.ShiftAmount.imm(@intCast(u5, rhs_mcv.immediate)),1930 .shift_amount = Instruction.ShiftAmount.imm(@as(u5, @intCast(rhs_mcv.immediate))),
1931 } },1931 } },
1932 });1932 });
1933 } else {1933 } else {
...@@ -2020,7 +2020,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {...@@ -2020,7 +2020,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
2020 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2020 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
2021 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2021 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2022 const optional_ty = self.typeOfIndex(inst);2022 const optional_ty = self.typeOfIndex(inst);
2023 const abi_size = @intCast(u32, optional_ty.abiSize(mod));2023 const abi_size = @as(u32, @intCast(optional_ty.abiSize(mod)));
20242024
2025 // Optional with a zero-bit payload type is just a boolean true2025 // Optional with a zero-bit payload type is just a boolean true
2026 if (abi_size == 1) {2026 if (abi_size == 1) {
...@@ -2049,7 +2049,7 @@ fn errUnionErr(...@@ -2049,7 +2049,7 @@ fn errUnionErr(
2049 return try error_union_bind.resolveToMcv(self);2049 return try error_union_bind.resolveToMcv(self);
2050 }2050 }
20512051
2052 const err_offset = @intCast(u32, errUnionErrorOffset(payload_ty, mod));2052 const err_offset = @as(u32, @intCast(errUnionErrorOffset(payload_ty, mod)));
2053 switch (try error_union_bind.resolveToMcv(self)) {2053 switch (try error_union_bind.resolveToMcv(self)) {
2054 .register => {2054 .register => {
2055 var operand_reg: Register = undefined;2055 var operand_reg: Register = undefined;
...@@ -2071,15 +2071,15 @@ fn errUnionErr(...@@ -2071,15 +2071,15 @@ fn errUnionErr(
2071 );2071 );
20722072
2073 const err_bit_offset = err_offset * 8;2073 const err_bit_offset = err_offset * 8;
2074 const err_bit_size = @intCast(u32, err_ty.abiSize(mod)) * 8;2074 const err_bit_size = @as(u32, @intCast(err_ty.abiSize(mod))) * 8;
20752075
2076 _ = try self.addInst(.{2076 _ = try self.addInst(.{
2077 .tag = .ubfx, // errors are unsigned integers2077 .tag = .ubfx, // errors are unsigned integers
2078 .data = .{ .rr_lsb_width = .{2078 .data = .{ .rr_lsb_width = .{
2079 .rd = dest_reg,2079 .rd = dest_reg,
2080 .rn = operand_reg,2080 .rn = operand_reg,
2081 .lsb = @intCast(u5, err_bit_offset),2081 .lsb = @as(u5, @intCast(err_bit_offset)),
2082 .width = @intCast(u6, err_bit_size),2082 .width = @as(u6, @intCast(err_bit_size)),
2083 } },2083 } },
2084 });2084 });
20852085
...@@ -2126,7 +2126,7 @@ fn errUnionPayload(...@@ -2126,7 +2126,7 @@ fn errUnionPayload(
2126 return MCValue.none;2126 return MCValue.none;
2127 }2127 }
21282128
2129 const payload_offset = @intCast(u32, errUnionPayloadOffset(payload_ty, mod));2129 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, mod)));
2130 switch (try error_union_bind.resolveToMcv(self)) {2130 switch (try error_union_bind.resolveToMcv(self)) {
2131 .register => {2131 .register => {
2132 var operand_reg: Register = undefined;2132 var operand_reg: Register = undefined;
...@@ -2148,15 +2148,15 @@ fn errUnionPayload(...@@ -2148,15 +2148,15 @@ fn errUnionPayload(
2148 );2148 );
21492149
2150 const payload_bit_offset = payload_offset * 8;2150 const payload_bit_offset = payload_offset * 8;
2151 const payload_bit_size = @intCast(u32, payload_ty.abiSize(mod)) * 8;2151 const payload_bit_size = @as(u32, @intCast(payload_ty.abiSize(mod))) * 8;
21522152
2153 _ = try self.addInst(.{2153 _ = try self.addInst(.{
2154 .tag = if (payload_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,2154 .tag = if (payload_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,
2155 .data = .{ .rr_lsb_width = .{2155 .data = .{ .rr_lsb_width = .{
2156 .rd = dest_reg,2156 .rd = dest_reg,
2157 .rn = operand_reg,2157 .rn = operand_reg,
2158 .lsb = @intCast(u5, payload_bit_offset),2158 .lsb = @as(u5, @intCast(payload_bit_offset)),
2159 .width = @intCast(u6, payload_bit_size),2159 .width = @as(u6, @intCast(payload_bit_size)),
2160 } },2160 } },
2161 });2161 });
21622162
...@@ -2235,13 +2235,13 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {...@@ -2235,13 +2235,13 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
2235 const operand = try self.resolveInst(ty_op.operand);2235 const operand = try self.resolveInst(ty_op.operand);
2236 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result operand;2236 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result operand;
22372237
2238 const abi_size = @intCast(u32, error_union_ty.abiSize(mod));2238 const abi_size = @as(u32, @intCast(error_union_ty.abiSize(mod)));
2239 const abi_align = error_union_ty.abiAlignment(mod);2239 const abi_align = error_union_ty.abiAlignment(mod);
2240 const stack_offset = @intCast(u32, try self.allocMem(abi_size, abi_align, inst));2240 const stack_offset = @as(u32, @intCast(try self.allocMem(abi_size, abi_align, inst)));
2241 const payload_off = errUnionPayloadOffset(payload_ty, mod);2241 const payload_off = errUnionPayloadOffset(payload_ty, mod);
2242 const err_off = errUnionErrorOffset(payload_ty, mod);2242 const err_off = errUnionErrorOffset(payload_ty, mod);
2243 try self.genSetStack(payload_ty, stack_offset - @intCast(u32, payload_off), operand);2243 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), operand);
2244 try self.genSetStack(error_ty, stack_offset - @intCast(u32, err_off), .{ .immediate = 0 });2244 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), .{ .immediate = 0 });
22452245
2246 break :result MCValue{ .stack_offset = stack_offset };2246 break :result MCValue{ .stack_offset = stack_offset };
2247 };2247 };
...@@ -2259,13 +2259,13 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -2259,13 +2259,13 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
2259 const operand = try self.resolveInst(ty_op.operand);2259 const operand = try self.resolveInst(ty_op.operand);
2260 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result operand;2260 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result operand;
22612261
2262 const abi_size = @intCast(u32, error_union_ty.abiSize(mod));2262 const abi_size = @as(u32, @intCast(error_union_ty.abiSize(mod)));
2263 const abi_align = error_union_ty.abiAlignment(mod);2263 const abi_align = error_union_ty.abiAlignment(mod);
2264 const stack_offset = @intCast(u32, try self.allocMem(abi_size, abi_align, inst));2264 const stack_offset = @as(u32, @intCast(try self.allocMem(abi_size, abi_align, inst)));
2265 const payload_off = errUnionPayloadOffset(payload_ty, mod);2265 const payload_off = errUnionPayloadOffset(payload_ty, mod);
2266 const err_off = errUnionErrorOffset(payload_ty, mod);2266 const err_off = errUnionErrorOffset(payload_ty, mod);
2267 try self.genSetStack(error_ty, stack_offset - @intCast(u32, err_off), operand);2267 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), operand);
2268 try self.genSetStack(payload_ty, stack_offset - @intCast(u32, payload_off), .undef);2268 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), .undef);
22692269
2270 break :result MCValue{ .stack_offset = stack_offset };2270 break :result MCValue{ .stack_offset = stack_offset };
2271 };2271 };
...@@ -2369,7 +2369,7 @@ fn ptrElemVal(...@@ -2369,7 +2369,7 @@ fn ptrElemVal(
2369) !MCValue {2369) !MCValue {
2370 const mod = self.bin_file.options.module.?;2370 const mod = self.bin_file.options.module.?;
2371 const elem_ty = ptr_ty.childType(mod);2371 const elem_ty = ptr_ty.childType(mod);
2372 const elem_size = @intCast(u32, elem_ty.abiSize(mod));2372 const elem_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
23732373
2374 switch (elem_size) {2374 switch (elem_size) {
2375 1, 4 => {2375 1, 4 => {
...@@ -2480,7 +2480,7 @@ fn arrayElemVal(...@@ -2480,7 +2480,7 @@ fn arrayElemVal(
2480 => {2480 => {
2481 const ptr_to_mcv = switch (mcv) {2481 const ptr_to_mcv = switch (mcv) {
2482 .stack_offset => |off| MCValue{ .ptr_stack_offset = off },2482 .stack_offset => |off| MCValue{ .ptr_stack_offset = off },
2483 .memory => |addr| MCValue{ .immediate = @intCast(u32, addr) },2483 .memory => |addr| MCValue{ .immediate = @as(u32, @intCast(addr)) },
2484 .stack_argument_offset => |off| blk: {2484 .stack_argument_offset => |off| blk: {
2485 const reg = try self.register_manager.allocReg(null, gp);2485 const reg = try self.register_manager.allocReg(null, gp);
24862486
...@@ -2654,7 +2654,7 @@ fn reuseOperand(...@@ -2654,7 +2654,7 @@ fn reuseOperand(
2654fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {2654fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {
2655 const mod = self.bin_file.options.module.?;2655 const mod = self.bin_file.options.module.?;
2656 const elem_ty = ptr_ty.childType(mod);2656 const elem_ty = ptr_ty.childType(mod);
2657 const elem_size = @intCast(u32, elem_ty.abiSize(mod));2657 const elem_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
26582658
2659 switch (ptr) {2659 switch (ptr) {
2660 .none => unreachable,2660 .none => unreachable,
...@@ -2759,7 +2759,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -2759,7 +2759,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
27592759
2760fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {2760fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {
2761 const mod = self.bin_file.options.module.?;2761 const mod = self.bin_file.options.module.?;
2762 const elem_size = @intCast(u32, value_ty.abiSize(mod));2762 const elem_size = @as(u32, @intCast(value_ty.abiSize(mod)));
27632763
2764 switch (ptr) {2764 switch (ptr) {
2765 .none => unreachable,2765 .none => unreachable,
...@@ -2814,7 +2814,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type...@@ -2814,7 +2814,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
2814 // sub src_reg, fp, #off2814 // sub src_reg, fp, #off
2815 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });2815 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });
2816 },2816 },
2817 .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @intCast(u32, addr) }),2817 .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @as(u32, @intCast(addr)) }),
2818 .stack_argument_offset => |off| {2818 .stack_argument_offset => |off| {
2819 _ = try self.addInst(.{2819 _ = try self.addInst(.{
2820 .tag = .ldr_ptr_stack_argument,2820 .tag = .ldr_ptr_stack_argument,
...@@ -2882,7 +2882,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde...@@ -2882,7 +2882,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
2882 const mcv = try self.resolveInst(operand);2882 const mcv = try self.resolveInst(operand);
2883 const ptr_ty = self.typeOf(operand);2883 const ptr_ty = self.typeOf(operand);
2884 const struct_ty = ptr_ty.childType(mod);2884 const struct_ty = ptr_ty.childType(mod);
2885 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, mod));2885 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, mod)));
2886 switch (mcv) {2886 switch (mcv) {
2887 .ptr_stack_offset => |off| {2887 .ptr_stack_offset => |off| {
2888 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };2888 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };
...@@ -2906,7 +2906,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -2906,7 +2906,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
2906 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2906 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2907 const mcv = try self.resolveInst(operand);2907 const mcv = try self.resolveInst(operand);
2908 const struct_ty = self.typeOf(operand);2908 const struct_ty = self.typeOf(operand);
2909 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, mod));2909 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, mod)));
2910 const struct_field_ty = struct_ty.structFieldType(index, mod);2910 const struct_field_ty = struct_ty.structFieldType(index, mod);
29112911
2912 switch (mcv) {2912 switch (mcv) {
...@@ -2970,15 +2970,15 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -2970,15 +2970,15 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
2970 );2970 );
29712971
2972 const field_bit_offset = struct_field_offset * 8;2972 const field_bit_offset = struct_field_offset * 8;
2973 const field_bit_size = @intCast(u32, struct_field_ty.abiSize(mod)) * 8;2973 const field_bit_size = @as(u32, @intCast(struct_field_ty.abiSize(mod))) * 8;
29742974
2975 _ = try self.addInst(.{2975 _ = try self.addInst(.{
2976 .tag = if (struct_field_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,2976 .tag = if (struct_field_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,
2977 .data = .{ .rr_lsb_width = .{2977 .data = .{ .rr_lsb_width = .{
2978 .rd = dest_reg,2978 .rd = dest_reg,
2979 .rn = operand_reg,2979 .rn = operand_reg,
2980 .lsb = @intCast(u5, field_bit_offset),2980 .lsb = @as(u5, @intCast(field_bit_offset)),
2981 .width = @intCast(u6, field_bit_size),2981 .width = @as(u6, @intCast(field_bit_size)),
2982 } },2982 } },
2983 });2983 });
29842984
...@@ -3003,7 +3003,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -3003,7 +3003,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
3003 return self.fail("TODO implement @fieldParentPtr codegen for unions", .{});3003 return self.fail("TODO implement @fieldParentPtr codegen for unions", .{});
3004 }3004 }
30053005
3006 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(extra.field_index, mod));3006 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(extra.field_index, mod)));
3007 switch (field_ptr) {3007 switch (field_ptr) {
3008 .ptr_stack_offset => |off| {3008 .ptr_stack_offset => |off| {
3009 break :result MCValue{ .ptr_stack_offset = off + struct_field_offset };3009 break :result MCValue{ .ptr_stack_offset = off + struct_field_offset };
...@@ -3364,7 +3364,7 @@ fn binOpImmediate(...@@ -3364,7 +3364,7 @@ fn binOpImmediate(
3364 => .{ .rr_shift = .{3364 => .{ .rr_shift = .{
3365 .rd = dest_reg,3365 .rd = dest_reg,
3366 .rm = lhs_reg,3366 .rm = lhs_reg,
3367 .shift_amount = Instruction.ShiftAmount.imm(@intCast(u5, rhs_immediate)),3367 .shift_amount = Instruction.ShiftAmount.imm(@as(u5, @intCast(rhs_immediate))),
3368 } },3368 } },
3369 else => unreachable,3369 else => unreachable,
3370 };3370 };
...@@ -3895,7 +3895,7 @@ fn ptrArithmetic(...@@ -3895,7 +3895,7 @@ fn ptrArithmetic(
3895 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type3895 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type
3896 else => ptr_ty.childType(mod),3896 else => ptr_ty.childType(mod),
3897 };3897 };
3898 const elem_size = @intCast(u32, elem_ty.abiSize(mod));3898 const elem_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
38993899
3900 const base_tag: Air.Inst.Tag = switch (tag) {3900 const base_tag: Air.Inst.Tag = switch (tag) {
3901 .ptr_add => .add,3901 .ptr_add => .add,
...@@ -4022,7 +4022,7 @@ fn genInlineMemcpy(...@@ -4022,7 +4022,7 @@ fn genInlineMemcpy(
4022 _ = try self.addInst(.{4022 _ = try self.addInst(.{
4023 .tag = .b,4023 .tag = .b,
4024 .cond = .ge,4024 .cond = .ge,
4025 .data = .{ .inst = @intCast(u32, self.mir_instructions.len + 5) },4025 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len + 5)) },
4026 });4026 });
40274027
4028 // ldrb tmp, [src, count]4028 // ldrb tmp, [src, count]
...@@ -4058,7 +4058,7 @@ fn genInlineMemcpy(...@@ -4058,7 +4058,7 @@ fn genInlineMemcpy(
4058 // b loop4058 // b loop
4059 _ = try self.addInst(.{4059 _ = try self.addInst(.{
4060 .tag = .b,4060 .tag = .b,
4061 .data = .{ .inst = @intCast(u32, self.mir_instructions.len - 5) },4061 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len - 5)) },
4062 });4062 });
40634063
4064 // end:4064 // end:
...@@ -4126,7 +4126,7 @@ fn genInlineMemsetCode(...@@ -4126,7 +4126,7 @@ fn genInlineMemsetCode(
4126 _ = try self.addInst(.{4126 _ = try self.addInst(.{
4127 .tag = .b,4127 .tag = .b,
4128 .cond = .ge,4128 .cond = .ge,
4129 .data = .{ .inst = @intCast(u32, self.mir_instructions.len + 4) },4129 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len + 4)) },
4130 });4130 });
41314131
4132 // strb val, [src, count]4132 // strb val, [src, count]
...@@ -4152,7 +4152,7 @@ fn genInlineMemsetCode(...@@ -4152,7 +4152,7 @@ fn genInlineMemsetCode(
4152 // b loop4152 // b loop
4153 _ = try self.addInst(.{4153 _ = try self.addInst(.{
4154 .tag = .b,4154 .tag = .b,
4155 .data = .{ .inst = @intCast(u32, self.mir_instructions.len - 4) },4155 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len - 4)) },
4156 });4156 });
41574157
4158 // end:4158 // end:
...@@ -4216,7 +4216,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4216,7 +4216,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4216 const pl_op = self.air.instructions.items(.data)[inst].pl_op;4216 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
4217 const callee = pl_op.operand;4217 const callee = pl_op.operand;
4218 const extra = self.air.extraData(Air.Call, pl_op.payload);4218 const extra = self.air.extraData(Air.Call, pl_op.payload);
4219 const args = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra.end..][0..extra.data.args_len]);4219 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));
4220 const ty = self.typeOf(callee);4220 const ty = self.typeOf(callee);
4221 const mod = self.bin_file.options.module.?;4221 const mod = self.bin_file.options.module.?;
42224222
...@@ -4248,8 +4248,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4248,8 +4248,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4248 const r0_lock: ?RegisterLock = if (info.return_value == .stack_offset) blk: {4248 const r0_lock: ?RegisterLock = if (info.return_value == .stack_offset) blk: {
4249 log.debug("airCall: return by reference", .{});4249 log.debug("airCall: return by reference", .{});
4250 const ret_ty = fn_ty.fnReturnType(mod);4250 const ret_ty = fn_ty.fnReturnType(mod);
4251 const ret_abi_size = @intCast(u32, ret_ty.abiSize(mod));4251 const ret_abi_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
4252 const ret_abi_align = @intCast(u32, ret_ty.abiAlignment(mod));4252 const ret_abi_align = @as(u32, @intCast(ret_ty.abiAlignment(mod)));
4253 const stack_offset = try self.allocMem(ret_abi_size, ret_abi_align, inst);4253 const stack_offset = try self.allocMem(ret_abi_size, ret_abi_align, inst);
42544254
4255 const ptr_ty = try mod.singleMutPtrType(ret_ty);4255 const ptr_ty = try mod.singleMutPtrType(ret_ty);
...@@ -4294,7 +4294,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4294,7 +4294,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4294 const atom_index = try elf_file.getOrCreateAtomForDecl(func.owner_decl);4294 const atom_index = try elf_file.getOrCreateAtomForDecl(func.owner_decl);
4295 const atom = elf_file.getAtom(atom_index);4295 const atom = elf_file.getAtom(atom_index);
4296 _ = try atom.getOrCreateOffsetTableEntry(elf_file);4296 _ = try atom.getOrCreateOffsetTableEntry(elf_file);
4297 const got_addr = @intCast(u32, atom.getOffsetTableAddress(elf_file));4297 const got_addr = @as(u32, @intCast(atom.getOffsetTableAddress(elf_file)));
4298 try self.genSetReg(Type.usize, .lr, .{ .memory = got_addr });4298 try self.genSetReg(Type.usize, .lr, .{ .memory = got_addr });
4299 } else if (self.bin_file.cast(link.File.MachO)) |_| {4299 } else if (self.bin_file.cast(link.File.MachO)) |_| {
4300 unreachable; // unsupported architecture for MachO4300 unreachable; // unsupported architecture for MachO
...@@ -4425,7 +4425,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -4425,7 +4425,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
4425 // location.4425 // location.
4426 const op_inst = Air.refToIndex(un_op).?;4426 const op_inst = Air.refToIndex(un_op).?;
4427 if (self.air.instructions.items(.tag)[op_inst] != .ret_ptr) {4427 if (self.air.instructions.items(.tag)[op_inst] != .ret_ptr) {
4428 const abi_size = @intCast(u32, ret_ty.abiSize(mod));4428 const abi_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
4429 const abi_align = ret_ty.abiAlignment(mod);4429 const abi_align = ret_ty.abiAlignment(mod);
44304430
4431 const offset = try self.allocMem(abi_size, abi_align, null);4431 const offset = try self.allocMem(abi_size, abi_align, null);
...@@ -4651,7 +4651,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4651,7 +4651,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
4651 if (self.liveness.operandDies(inst, 0)) {4651 if (self.liveness.operandDies(inst, 0)) {
4652 const op_int = @intFromEnum(pl_op.operand);4652 const op_int = @intFromEnum(pl_op.operand);
4653 if (op_int >= Air.ref_start_index) {4653 if (op_int >= Air.ref_start_index) {
4654 const op_index = @intCast(Air.Inst.Index, op_int - Air.ref_start_index);4654 const op_index = @as(Air.Inst.Index, @intCast(op_int - Air.ref_start_index));
4655 self.processDeath(op_index);4655 self.processDeath(op_index);
4656 }4656 }
4657 }4657 }
...@@ -4956,7 +4956,7 @@ fn airLoop(self: *Self, inst: Air.Inst.Index) !void {...@@ -4956,7 +4956,7 @@ fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
4956 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;4956 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
4957 const loop = self.air.extraData(Air.Block, ty_pl.payload);4957 const loop = self.air.extraData(Air.Block, ty_pl.payload);
4958 const body = self.air.extra[loop.end..][0..loop.data.body_len];4958 const body = self.air.extra[loop.end..][0..loop.data.body_len];
4959 const start_index = @intCast(Mir.Inst.Index, self.mir_instructions.len);4959 const start_index = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len));
49604960
4961 try self.genBody(body);4961 try self.genBody(body);
4962 try self.jump(start_index);4962 try self.jump(start_index);
...@@ -5021,7 +5021,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {...@@ -5021,7 +5021,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
5021 var case_i: u32 = 0;5021 var case_i: u32 = 0;
5022 while (case_i < switch_br.data.cases_len) : (case_i += 1) {5022 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
5023 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);5023 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
5024 const items = @ptrCast([]const Air.Inst.Ref, self.air.extra[case.end..][0..case.data.items_len]);5024 const items = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[case.end..][0..case.data.items_len]));
5025 assert(items.len > 0);5025 assert(items.len > 0);
5026 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];5026 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
5027 extra_index = case.end + items.len + case_body.len;5027 extra_index = case.end + items.len + case_body.len;
...@@ -5139,7 +5139,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {...@@ -5139,7 +5139,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
5139fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {5139fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {
5140 const tag = self.mir_instructions.items(.tag)[inst];5140 const tag = self.mir_instructions.items(.tag)[inst];
5141 switch (tag) {5141 switch (tag) {
5142 .b => self.mir_instructions.items(.data)[inst].inst = @intCast(Air.Inst.Index, self.mir_instructions.len),5142 .b => self.mir_instructions.items(.data)[inst].inst = @as(Air.Inst.Index, @intCast(self.mir_instructions.len)),
5143 else => unreachable,5143 else => unreachable,
5144 }5144 }
5145}5145}
...@@ -5188,12 +5188,12 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {...@@ -5188,12 +5188,12 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {
5188fn airAsm(self: *Self, inst: Air.Inst.Index) !void {5188fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
5189 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5189 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
5190 const extra = self.air.extraData(Air.Asm, ty_pl.payload);5190 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
5191 const is_volatile = @truncate(u1, extra.data.flags >> 31) != 0;5191 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
5192 const clobbers_len = @truncate(u31, extra.data.flags);5192 const clobbers_len = @as(u31, @truncate(extra.data.flags));
5193 var extra_i: usize = extra.end;5193 var extra_i: usize = extra.end;
5194 const outputs = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra_i..][0..extra.data.outputs_len]);5194 const outputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]));
5195 extra_i += outputs.len;5195 extra_i += outputs.len;
5196 const inputs = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra_i..][0..extra.data.inputs_len]);5196 const inputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]));
5197 extra_i += inputs.len;5197 extra_i += inputs.len;
51985198
5199 const dead = !is_volatile and self.liveness.isUnused(inst);5199 const dead = !is_volatile and self.liveness.isUnused(inst);
...@@ -5323,7 +5323,7 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {...@@ -5323,7 +5323,7 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {
53235323
5324fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {5324fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
5325 const mod = self.bin_file.options.module.?;5325 const mod = self.bin_file.options.module.?;
5326 const abi_size = @intCast(u32, ty.abiSize(mod));5326 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
5327 switch (mcv) {5327 switch (mcv) {
5328 .dead => unreachable,5328 .dead => unreachable,
5329 .unreach, .none => return, // Nothing to do.5329 .unreach, .none => return, // Nothing to do.
...@@ -5376,7 +5376,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro...@@ -5376,7 +5376,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
5376 },5376 },
5377 2 => {5377 2 => {
5378 const offset = if (stack_offset <= math.maxInt(u8)) blk: {5378 const offset = if (stack_offset <= math.maxInt(u8)) blk: {
5379 break :blk Instruction.ExtraLoadStoreOffset.imm(@intCast(u8, stack_offset));5379 break :blk Instruction.ExtraLoadStoreOffset.imm(@as(u8, @intCast(stack_offset)));
5380 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset }));5380 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset }));
53815381
5382 _ = try self.addInst(.{5382 _ = try self.addInst(.{
...@@ -5404,7 +5404,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro...@@ -5404,7 +5404,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
5404 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = reg });5404 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = reg });
54055405
5406 const overflow_bit_ty = ty.structFieldType(1, mod);5406 const overflow_bit_ty = ty.structFieldType(1, mod);
5407 const overflow_bit_offset = @intCast(u32, ty.structFieldOffset(1, mod));5407 const overflow_bit_offset = @as(u32, @intCast(ty.structFieldOffset(1, mod)));
5408 const cond_reg = try self.register_manager.allocReg(null, gp);5408 const cond_reg = try self.register_manager.allocReg(null, gp);
54095409
5410 // C flag: movcs reg, #15410 // C flag: movcs reg, #1
...@@ -5457,7 +5457,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro...@@ -5457,7 +5457,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
5457 // sub src_reg, fp, #off5457 // sub src_reg, fp, #off
5458 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });5458 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });
5459 },5459 },
5460 .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @intCast(u32, addr) }),5460 .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @as(u32, @intCast(addr)) }),
5461 .stack_argument_offset => |off| {5461 .stack_argument_offset => |off| {
5462 _ = try self.addInst(.{5462 _ = try self.addInst(.{
5463 .tag = .ldr_ptr_stack_argument,5463 .tag = .ldr_ptr_stack_argument,
...@@ -5554,7 +5554,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5554,7 +5554,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5554 .tag = .movw,5554 .tag = .movw,
5555 .data = .{ .r_imm16 = .{5555 .data = .{ .r_imm16 = .{
5556 .rd = reg,5556 .rd = reg,
5557 .imm16 = @intCast(u16, x),5557 .imm16 = @as(u16, @intCast(x)),
5558 } },5558 } },
5559 });5559 });
5560 } else {5560 } else {
...@@ -5562,7 +5562,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5562,7 +5562,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5562 .tag = .mov,5562 .tag = .mov,
5563 .data = .{ .r_op_mov = .{5563 .data = .{ .r_op_mov = .{
5564 .rd = reg,5564 .rd = reg,
5565 .op = Instruction.Operand.imm(@truncate(u8, x), 0),5565 .op = Instruction.Operand.imm(@as(u8, @truncate(x)), 0),
5566 } },5566 } },
5567 });5567 });
5568 _ = try self.addInst(.{5568 _ = try self.addInst(.{
...@@ -5570,7 +5570,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5570,7 +5570,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5570 .data = .{ .rr_op = .{5570 .data = .{ .rr_op = .{
5571 .rd = reg,5571 .rd = reg,
5572 .rn = reg,5572 .rn = reg,
5573 .op = Instruction.Operand.imm(@truncate(u8, x >> 8), 12),5573 .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 8)), 12),
5574 } },5574 } },
5575 });5575 });
5576 }5576 }
...@@ -5585,14 +5585,14 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5585,14 +5585,14 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5585 .tag = .movw,5585 .tag = .movw,
5586 .data = .{ .r_imm16 = .{5586 .data = .{ .r_imm16 = .{
5587 .rd = reg,5587 .rd = reg,
5588 .imm16 = @truncate(u16, x),5588 .imm16 = @as(u16, @truncate(x)),
5589 } },5589 } },
5590 });5590 });
5591 _ = try self.addInst(.{5591 _ = try self.addInst(.{
5592 .tag = .movt,5592 .tag = .movt,
5593 .data = .{ .r_imm16 = .{5593 .data = .{ .r_imm16 = .{
5594 .rd = reg,5594 .rd = reg,
5595 .imm16 = @truncate(u16, x >> 16),5595 .imm16 = @as(u16, @truncate(x >> 16)),
5596 } },5596 } },
5597 });5597 });
5598 } else {5598 } else {
...@@ -5605,7 +5605,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5605,7 +5605,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5605 .tag = .mov,5605 .tag = .mov,
5606 .data = .{ .r_op_mov = .{5606 .data = .{ .r_op_mov = .{
5607 .rd = reg,5607 .rd = reg,
5608 .op = Instruction.Operand.imm(@truncate(u8, x), 0),5608 .op = Instruction.Operand.imm(@as(u8, @truncate(x)), 0),
5609 } },5609 } },
5610 });5610 });
5611 _ = try self.addInst(.{5611 _ = try self.addInst(.{
...@@ -5613,7 +5613,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5613,7 +5613,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5613 .data = .{ .rr_op = .{5613 .data = .{ .rr_op = .{
5614 .rd = reg,5614 .rd = reg,
5615 .rn = reg,5615 .rn = reg,
5616 .op = Instruction.Operand.imm(@truncate(u8, x >> 8), 12),5616 .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 8)), 12),
5617 } },5617 } },
5618 });5618 });
5619 _ = try self.addInst(.{5619 _ = try self.addInst(.{
...@@ -5621,7 +5621,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5621,7 +5621,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5621 .data = .{ .rr_op = .{5621 .data = .{ .rr_op = .{
5622 .rd = reg,5622 .rd = reg,
5623 .rn = reg,5623 .rn = reg,
5624 .op = Instruction.Operand.imm(@truncate(u8, x >> 16), 8),5624 .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 16)), 8),
5625 } },5625 } },
5626 });5626 });
5627 _ = try self.addInst(.{5627 _ = try self.addInst(.{
...@@ -5629,7 +5629,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5629,7 +5629,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5629 .data = .{ .rr_op = .{5629 .data = .{ .rr_op = .{
5630 .rd = reg,5630 .rd = reg,
5631 .rn = reg,5631 .rn = reg,
5632 .op = Instruction.Operand.imm(@truncate(u8, x >> 24), 4),5632 .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 24)), 4),
5633 } },5633 } },
5634 });5634 });
5635 }5635 }
...@@ -5654,12 +5654,12 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5654,12 +5654,12 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5654 .memory => |addr| {5654 .memory => |addr| {
5655 // The value is in memory at a hard-coded address.5655 // The value is in memory at a hard-coded address.
5656 // If the type is a pointer, it means the pointer address is at this memory location.5656 // If the type is a pointer, it means the pointer address is at this memory location.
5657 try self.genSetReg(ty, reg, .{ .immediate = @intCast(u32, addr) });5657 try self.genSetReg(ty, reg, .{ .immediate = @as(u32, @intCast(addr)) });
5658 try self.genLdrRegister(reg, reg, ty);5658 try self.genLdrRegister(reg, reg, ty);
5659 },5659 },
5660 .stack_offset => |off| {5660 .stack_offset => |off| {
5661 // TODO: maybe addressing from sp instead of fp5661 // TODO: maybe addressing from sp instead of fp
5662 const abi_size = @intCast(u32, ty.abiSize(mod));5662 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
56635663
5664 const tag: Mir.Inst.Tag = switch (abi_size) {5664 const tag: Mir.Inst.Tag = switch (abi_size) {
5665 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb else .ldrb,5665 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb else .ldrb,
...@@ -5677,7 +5677,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5677,7 +5677,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56775677
5678 if (extra_offset) {5678 if (extra_offset) {
5679 const offset = if (off <= math.maxInt(u8)) blk: {5679 const offset = if (off <= math.maxInt(u8)) blk: {
5680 break :blk Instruction.ExtraLoadStoreOffset.imm(@intCast(u8, off));5680 break :blk Instruction.ExtraLoadStoreOffset.imm(@as(u8, @intCast(off)));
5681 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.usize, MCValue{ .immediate = off }));5681 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.usize, MCValue{ .immediate = off }));
56825682
5683 _ = try self.addInst(.{5683 _ = try self.addInst(.{
...@@ -5693,7 +5693,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5693,7 +5693,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5693 });5693 });
5694 } else {5694 } else {
5695 const offset = if (off <= math.maxInt(u12)) blk: {5695 const offset = if (off <= math.maxInt(u12)) blk: {
5696 break :blk Instruction.Offset.imm(@intCast(u12, off));5696 break :blk Instruction.Offset.imm(@as(u12, @intCast(off)));
5697 } else Instruction.Offset.reg(try self.copyToTmpRegister(Type.usize, MCValue{ .immediate = off }), .none);5697 } else Instruction.Offset.reg(try self.copyToTmpRegister(Type.usize, MCValue{ .immediate = off }), .none);
56985698
5699 _ = try self.addInst(.{5699 _ = try self.addInst(.{
...@@ -5732,7 +5732,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5732,7 +5732,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
57325732
5733fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {5733fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
5734 const mod = self.bin_file.options.module.?;5734 const mod = self.bin_file.options.module.?;
5735 const abi_size = @intCast(u32, ty.abiSize(mod));5735 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
5736 switch (mcv) {5736 switch (mcv) {
5737 .dead => unreachable,5737 .dead => unreachable,
5738 .none, .unreach => return,5738 .none, .unreach => return,
...@@ -5771,7 +5771,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I...@@ -5771,7 +5771,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
5771 },5771 },
5772 2 => {5772 2 => {
5773 const offset = if (stack_offset <= math.maxInt(u8)) blk: {5773 const offset = if (stack_offset <= math.maxInt(u8)) blk: {
5774 break :blk Instruction.ExtraLoadStoreOffset.imm(@intCast(u8, stack_offset));5774 break :blk Instruction.ExtraLoadStoreOffset.imm(@as(u8, @intCast(stack_offset)));
5775 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset }));5775 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset }));
57765776
5777 _ = try self.addInst(.{5777 _ = try self.addInst(.{
...@@ -5814,7 +5814,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I...@@ -5814,7 +5814,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
5814 // sub src_reg, fp, #off5814 // sub src_reg, fp, #off
5815 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });5815 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });
5816 },5816 },
5817 .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @intCast(u32, addr) }),5817 .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @as(u32, @intCast(addr)) }),
5818 .stack_argument_offset => |off| {5818 .stack_argument_offset => |off| {
5819 _ = try self.addInst(.{5819 _ = try self.addInst(.{
5820 .tag = .ldr_ptr_stack_argument,5820 .tag = .ldr_ptr_stack_argument,
...@@ -5893,7 +5893,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {...@@ -5893,7 +5893,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
5893 const ptr_ty = self.typeOf(ty_op.operand);5893 const ptr_ty = self.typeOf(ty_op.operand);
5894 const ptr = try self.resolveInst(ty_op.operand);5894 const ptr = try self.resolveInst(ty_op.operand);
5895 const array_ty = ptr_ty.childType(mod);5895 const array_ty = ptr_ty.childType(mod);
5896 const array_len = @intCast(u32, array_ty.arrayLen(mod));5896 const array_len = @as(u32, @intCast(array_ty.arrayLen(mod)));
58975897
5898 const stack_offset = try self.allocMem(8, 8, inst);5898 const stack_offset = try self.allocMem(8, 8, inst);
5899 try self.genSetStack(ptr_ty, stack_offset, ptr);5899 try self.genSetStack(ptr_ty, stack_offset, ptr);
...@@ -6010,7 +6010,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -6010,7 +6010,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
6010 const vector_ty = self.typeOfIndex(inst);6010 const vector_ty = self.typeOfIndex(inst);
6011 const len = vector_ty.vectorLen(mod);6011 const len = vector_ty.vectorLen(mod);
6012 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;6012 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
6013 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);6013 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
6014 const result: MCValue = res: {6014 const result: MCValue = res: {
6015 if (self.liveness.isUnused(inst)) break :res MCValue.dead;6015 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
6016 return self.fail("TODO implement airAggregateInit for arm", .{});6016 return self.fail("TODO implement airAggregateInit for arm", .{});
...@@ -6058,7 +6058,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {...@@ -6058,7 +6058,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
6058 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };6058 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };
6059 const error_union_ty = self.typeOf(pl_op.operand);6059 const error_union_ty = self.typeOf(pl_op.operand);
6060 const mod = self.bin_file.options.module.?;6060 const mod = self.bin_file.options.module.?;
6061 const error_union_size = @intCast(u32, error_union_ty.abiSize(mod));6061 const error_union_size = @as(u32, @intCast(error_union_ty.abiSize(mod)));
6062 const error_union_align = error_union_ty.abiAlignment(mod);6062 const error_union_align = error_union_ty.abiAlignment(mod);
60636063
6064 // The error union will die in the body. However, we need the6064 // The error union will die in the body. However, we need the
...@@ -6141,7 +6141,7 @@ fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue {...@@ -6141,7 +6141,7 @@ fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue {
6141 .none => .none,6141 .none => .none,
6142 .undef => .undef,6142 .undef => .undef,
6143 .load_got, .load_direct, .load_tlv => unreachable, // TODO6143 .load_got, .load_direct, .load_tlv => unreachable, // TODO
6144 .immediate => |imm| .{ .immediate = @truncate(u32, imm) },6144 .immediate => |imm| .{ .immediate = @as(u32, @truncate(imm)) },
6145 .memory => |addr| .{ .memory = addr },6145 .memory => |addr| .{ .memory = addr },
6146 },6146 },
6147 .fail => |msg| {6147 .fail => |msg| {
...@@ -6198,7 +6198,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6198,7 +6198,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6198 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {6198 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
6199 result.return_value = .{ .none = {} };6199 result.return_value = .{ .none = {} };
6200 } else {6200 } else {
6201 const ret_ty_size = @intCast(u32, ret_ty.abiSize(mod));6201 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
6202 // TODO handle cases where multiple registers are used6202 // TODO handle cases where multiple registers are used
6203 if (ret_ty_size <= 4) {6203 if (ret_ty_size <= 4) {
6204 result.return_value = .{ .register = c_abi_int_return_regs[0] };6204 result.return_value = .{ .register = c_abi_int_return_regs[0] };
...@@ -6216,7 +6216,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6216,7 +6216,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6216 if (ty.toType().abiAlignment(mod) == 8)6216 if (ty.toType().abiAlignment(mod) == 8)
6217 ncrn = std.mem.alignForward(usize, ncrn, 2);6217 ncrn = std.mem.alignForward(usize, ncrn, 2);
62186218
6219 const param_size = @intCast(u32, ty.toType().abiSize(mod));6219 const param_size = @as(u32, @intCast(ty.toType().abiSize(mod)));
6220 if (std.math.divCeil(u32, param_size, 4) catch unreachable <= 4 - ncrn) {6220 if (std.math.divCeil(u32, param_size, 4) catch unreachable <= 4 - ncrn) {
6221 if (param_size <= 4) {6221 if (param_size <= 4) {
6222 result.args[i] = .{ .register = c_abi_int_param_regs[ncrn] };6222 result.args[i] = .{ .register = c_abi_int_param_regs[ncrn] };
...@@ -6245,7 +6245,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6245,7 +6245,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6245 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod) and !ret_ty.isError(mod)) {6245 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod) and !ret_ty.isError(mod)) {
6246 result.return_value = .{ .none = {} };6246 result.return_value = .{ .none = {} };
6247 } else {6247 } else {
6248 const ret_ty_size = @intCast(u32, ret_ty.abiSize(mod));6248 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
6249 if (ret_ty_size == 0) {6249 if (ret_ty_size == 0) {
6250 assert(ret_ty.isError(mod));6250 assert(ret_ty.isError(mod));
6251 result.return_value = .{ .immediate = 0 };6251 result.return_value = .{ .immediate = 0 };
...@@ -6264,7 +6264,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6264,7 +6264,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62646264
6265 for (fn_info.param_types, 0..) |ty, i| {6265 for (fn_info.param_types, 0..) |ty, i| {
6266 if (ty.toType().abiSize(mod) > 0) {6266 if (ty.toType().abiSize(mod) > 0) {
6267 const param_size = @intCast(u32, ty.toType().abiSize(mod));6267 const param_size = @as(u32, @intCast(ty.toType().abiSize(mod)));
6268 const param_alignment = ty.toType().abiAlignment(mod);6268 const param_alignment = ty.toType().abiAlignment(mod);
62696269
6270 stack_offset = std.mem.alignForward(u32, stack_offset, param_alignment);6270 stack_offset = std.mem.alignForward(u32, stack_offset, param_alignment);
src/arch/arm/Emit.zig+19-19
...@@ -78,7 +78,7 @@ pub fn emitMir(...@@ -78,7 +78,7 @@ pub fn emitMir(
7878
79 // Emit machine code79 // Emit machine code
80 for (mir_tags, 0..) |tag, index| {80 for (mir_tags, 0..) |tag, index| {
81 const inst = @intCast(u32, index);81 const inst = @as(u32, @intCast(index));
82 switch (tag) {82 switch (tag) {
83 .add => try emit.mirDataProcessing(inst),83 .add => try emit.mirDataProcessing(inst),
84 .adds => try emit.mirDataProcessing(inst),84 .adds => try emit.mirDataProcessing(inst),
...@@ -241,7 +241,7 @@ fn lowerBranches(emit: *Emit) !void {...@@ -241,7 +241,7 @@ fn lowerBranches(emit: *Emit) !void {
241 // TODO optimization opportunity: do this in codegen while241 // TODO optimization opportunity: do this in codegen while
242 // generating MIR242 // generating MIR
243 for (mir_tags, 0..) |tag, index| {243 for (mir_tags, 0..) |tag, index| {
244 const inst = @intCast(u32, index);244 const inst = @as(u32, @intCast(index));
245 if (isBranch(tag)) {245 if (isBranch(tag)) {
246 const target_inst = emit.branchTarget(inst);246 const target_inst = emit.branchTarget(inst);
247247
...@@ -286,7 +286,7 @@ fn lowerBranches(emit: *Emit) !void {...@@ -286,7 +286,7 @@ fn lowerBranches(emit: *Emit) !void {
286 var current_code_offset: usize = 0;286 var current_code_offset: usize = 0;
287287
288 for (mir_tags, 0..) |tag, index| {288 for (mir_tags, 0..) |tag, index| {
289 const inst = @intCast(u32, index);289 const inst = @as(u32, @intCast(index));
290290
291 // If this instruction contained in the code offset291 // If this instruction contained in the code offset
292 // mapping (when it is a target of a branch or if it is a292 // mapping (when it is a target of a branch or if it is a
...@@ -301,7 +301,7 @@ fn lowerBranches(emit: *Emit) !void {...@@ -301,7 +301,7 @@ fn lowerBranches(emit: *Emit) !void {
301 const target_inst = emit.branchTarget(inst);301 const target_inst = emit.branchTarget(inst);
302 if (target_inst < inst) {302 if (target_inst < inst) {
303 const target_offset = emit.code_offset_mapping.get(target_inst).?;303 const target_offset = emit.code_offset_mapping.get(target_inst).?;
304 const offset = @intCast(i64, target_offset) - @intCast(i64, current_code_offset + 8);304 const offset = @as(i64, @intCast(target_offset)) - @as(i64, @intCast(current_code_offset + 8));
305 const branch_type = emit.branch_types.getPtr(inst).?;305 const branch_type = emit.branch_types.getPtr(inst).?;
306 const optimal_branch_type = try emit.optimalBranchType(tag, offset);306 const optimal_branch_type = try emit.optimalBranchType(tag, offset);
307 if (branch_type.* != optimal_branch_type) {307 if (branch_type.* != optimal_branch_type) {
...@@ -320,7 +320,7 @@ fn lowerBranches(emit: *Emit) !void {...@@ -320,7 +320,7 @@ fn lowerBranches(emit: *Emit) !void {
320 for (origin_list.items) |forward_branch_inst| {320 for (origin_list.items) |forward_branch_inst| {
321 const branch_tag = emit.mir.instructions.items(.tag)[forward_branch_inst];321 const branch_tag = emit.mir.instructions.items(.tag)[forward_branch_inst];
322 const forward_branch_inst_offset = emit.code_offset_mapping.get(forward_branch_inst).?;322 const forward_branch_inst_offset = emit.code_offset_mapping.get(forward_branch_inst).?;
323 const offset = @intCast(i64, current_code_offset) - @intCast(i64, forward_branch_inst_offset + 8);323 const offset = @as(i64, @intCast(current_code_offset)) - @as(i64, @intCast(forward_branch_inst_offset + 8));
324 const branch_type = emit.branch_types.getPtr(forward_branch_inst).?;324 const branch_type = emit.branch_types.getPtr(forward_branch_inst).?;
325 const optimal_branch_type = try emit.optimalBranchType(branch_tag, offset);325 const optimal_branch_type = try emit.optimalBranchType(branch_tag, offset);
326 if (branch_type.* != optimal_branch_type) {326 if (branch_type.* != optimal_branch_type) {
...@@ -351,7 +351,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {...@@ -351,7 +351,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
351}351}
352352
353fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {353fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {
354 const delta_line = @intCast(i32, line) - @intCast(i32, self.prev_di_line);354 const delta_line = @as(i32, @intCast(line)) - @as(i32, @intCast(self.prev_di_line));
355 const delta_pc: usize = self.code.items.len - self.prev_di_pc;355 const delta_pc: usize = self.code.items.len - self.prev_di_pc;
356 switch (self.debug_output) {356 switch (self.debug_output) {
357 .dwarf => |dw| {357 .dwarf => |dw| {
...@@ -368,13 +368,13 @@ fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {...@@ -368,13 +368,13 @@ fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {
368 // increasing the line number368 // increasing the line number
369 try @import("../../link/Plan9.zig").changeLine(dbg_out.dbg_line, delta_line);369 try @import("../../link/Plan9.zig").changeLine(dbg_out.dbg_line, delta_line);
370 // increasing the pc370 // increasing the pc
371 const d_pc_p9 = @intCast(i64, delta_pc) - quant;371 const d_pc_p9 = @as(i64, @intCast(delta_pc)) - quant;
372 if (d_pc_p9 > 0) {372 if (d_pc_p9 > 0) {
373 // minus one because if its the last one, we want to leave space to change the line which is one quanta373 // minus one because if its the last one, we want to leave space to change the line which is one quanta
374 try dbg_out.dbg_line.append(@intCast(u8, @divExact(d_pc_p9, quant) + 128) - quant);374 try dbg_out.dbg_line.append(@as(u8, @intCast(@divExact(d_pc_p9, quant) + 128)) - quant);
375 if (dbg_out.pcop_change_index.*) |pci|375 if (dbg_out.pcop_change_index.*) |pci|
376 dbg_out.dbg_line.items[pci] += 1;376 dbg_out.dbg_line.items[pci] += 1;
377 dbg_out.pcop_change_index.* = @intCast(u32, dbg_out.dbg_line.items.len - 1);377 dbg_out.pcop_change_index.* = @as(u32, @intCast(dbg_out.dbg_line.items.len - 1));
378 } else if (d_pc_p9 == 0) {378 } else if (d_pc_p9 == 0) {
379 // we don't need to do anything, because adding the quant does it for us379 // we don't need to do anything, because adding the quant does it for us
380 } else unreachable;380 } else unreachable;
...@@ -448,13 +448,13 @@ fn mirSubStackPointer(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -448,13 +448,13 @@ fn mirSubStackPointer(emit: *Emit, inst: Mir.Inst.Index) !void {
448 const scratch: Register = .r4;448 const scratch: Register = .r4;
449449
450 if (Target.arm.featureSetHas(emit.target.cpu.features, .has_v7)) {450 if (Target.arm.featureSetHas(emit.target.cpu.features, .has_v7)) {
451 try emit.writeInstruction(Instruction.movw(cond, scratch, @truncate(u16, imm32)));451 try emit.writeInstruction(Instruction.movw(cond, scratch, @as(u16, @truncate(imm32))));
452 try emit.writeInstruction(Instruction.movt(cond, scratch, @truncate(u16, imm32 >> 16)));452 try emit.writeInstruction(Instruction.movt(cond, scratch, @as(u16, @truncate(imm32 >> 16))));
453 } else {453 } else {
454 try emit.writeInstruction(Instruction.mov(cond, scratch, Instruction.Operand.imm(@truncate(u8, imm32), 0)));454 try emit.writeInstruction(Instruction.mov(cond, scratch, Instruction.Operand.imm(@as(u8, @truncate(imm32)), 0)));
455 try emit.writeInstruction(Instruction.orr(cond, scratch, scratch, Instruction.Operand.imm(@truncate(u8, imm32 >> 8), 12)));455 try emit.writeInstruction(Instruction.orr(cond, scratch, scratch, Instruction.Operand.imm(@as(u8, @truncate(imm32 >> 8)), 12)));
456 try emit.writeInstruction(Instruction.orr(cond, scratch, scratch, Instruction.Operand.imm(@truncate(u8, imm32 >> 16), 8)));456 try emit.writeInstruction(Instruction.orr(cond, scratch, scratch, Instruction.Operand.imm(@as(u8, @truncate(imm32 >> 16)), 8)));
457 try emit.writeInstruction(Instruction.orr(cond, scratch, scratch, Instruction.Operand.imm(@truncate(u8, imm32 >> 24), 4)));457 try emit.writeInstruction(Instruction.orr(cond, scratch, scratch, Instruction.Operand.imm(@as(u8, @truncate(imm32 >> 24)), 4)));
458 }458 }
459459
460 break :blk Instruction.Operand.reg(scratch, Instruction.Operand.Shift.none);460 break :blk Instruction.Operand.reg(scratch, Instruction.Operand.Shift.none);
...@@ -484,12 +484,12 @@ fn mirBranch(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -484,12 +484,12 @@ fn mirBranch(emit: *Emit, inst: Mir.Inst.Index) !void {
484 const cond = emit.mir.instructions.items(.cond)[inst];484 const cond = emit.mir.instructions.items(.cond)[inst];
485 const target_inst = emit.mir.instructions.items(.data)[inst].inst;485 const target_inst = emit.mir.instructions.items(.data)[inst].inst;
486486
487 const offset = @intCast(i64, emit.code_offset_mapping.get(target_inst).?) - @intCast(i64, emit.code.items.len + 8);487 const offset = @as(i64, @intCast(emit.code_offset_mapping.get(target_inst).?)) - @as(i64, @intCast(emit.code.items.len + 8));
488 const branch_type = emit.branch_types.get(inst).?;488 const branch_type = emit.branch_types.get(inst).?;
489489
490 switch (branch_type) {490 switch (branch_type) {
491 .b => switch (tag) {491 .b => switch (tag) {
492 .b => try emit.writeInstruction(Instruction.b(cond, @intCast(i26, offset))),492 .b => try emit.writeInstruction(Instruction.b(cond, @as(i26, @intCast(offset)))),
493 else => unreachable,493 else => unreachable,
494 },494 },
495 }495 }
...@@ -585,7 +585,7 @@ fn mirLoadStackArgument(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -585,7 +585,7 @@ fn mirLoadStackArgument(emit: *Emit, inst: Mir.Inst.Index) !void {
585 .ldrb_stack_argument,585 .ldrb_stack_argument,
586 => {586 => {
587 const offset = if (raw_offset <= math.maxInt(u12)) blk: {587 const offset = if (raw_offset <= math.maxInt(u12)) blk: {
588 break :blk Instruction.Offset.imm(@intCast(u12, raw_offset));588 break :blk Instruction.Offset.imm(@as(u12, @intCast(raw_offset)));
589 } else return emit.fail("TODO mirLoadStack larger offsets", .{});589 } else return emit.fail("TODO mirLoadStack larger offsets", .{});
590590
591 switch (tag) {591 switch (tag) {
...@@ -599,7 +599,7 @@ fn mirLoadStackArgument(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -599,7 +599,7 @@ fn mirLoadStackArgument(emit: *Emit, inst: Mir.Inst.Index) !void {
599 .ldrsh_stack_argument,599 .ldrsh_stack_argument,
600 => {600 => {
601 const offset = if (raw_offset <= math.maxInt(u8)) blk: {601 const offset = if (raw_offset <= math.maxInt(u8)) blk: {
602 break :blk Instruction.ExtraLoadStoreOffset.imm(@intCast(u8, raw_offset));602 break :blk Instruction.ExtraLoadStoreOffset.imm(@as(u8, @intCast(raw_offset)));
603 } else return emit.fail("TODO mirLoadStack larger offsets", .{});603 } else return emit.fail("TODO mirLoadStack larger offsets", .{});
604604
605 switch (tag) {605 switch (tag) {
src/arch/arm/Mir.zig+1-1
...@@ -287,7 +287,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end...@@ -287,7 +287,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end
287 inline for (fields) |field| {287 inline for (fields) |field| {
288 @field(result, field.name) = switch (field.type) {288 @field(result, field.name) = switch (field.type) {
289 u32 => mir.extra[i],289 u32 => mir.extra[i],
290 i32 => @bitCast(i32, mir.extra[i]),290 i32 => @as(i32, @bitCast(mir.extra[i])),
291 else => @compileError("bad field type"),291 else => @compileError("bad field type"),
292 };292 };
293 i += 1;293 i += 1;
src/arch/arm/abi.zig+1-1
...@@ -13,7 +13,7 @@ pub const Class = union(enum) {...@@ -13,7 +13,7 @@ pub const Class = union(enum) {
13 i64_array: u8,13 i64_array: u8,
1414
15 fn arrSize(total_size: u64, arr_size: u64) Class {15 fn arrSize(total_size: u64, arr_size: u64) Class {
16 const count = @intCast(u8, std.mem.alignForward(u64, total_size, arr_size) / arr_size);16 const count = @as(u8, @intCast(std.mem.alignForward(u64, total_size, arr_size) / arr_size));
17 if (arr_size == 32) {17 if (arr_size == 32) {
18 return .{ .i32_array = count };18 return .{ .i32_array = count };
19 } else {19 } else {
src/arch/arm/bits.zig+32-32
...@@ -159,7 +159,7 @@ pub const Register = enum(u5) {...@@ -159,7 +159,7 @@ pub const Register = enum(u5) {
159 /// Returns the unique 4-bit ID of this register which is used in159 /// Returns the unique 4-bit ID of this register which is used in
160 /// the machine code160 /// the machine code
161 pub fn id(self: Register) u4 {161 pub fn id(self: Register) u4 {
162 return @truncate(u4, @intFromEnum(self));162 return @as(u4, @truncate(@intFromEnum(self)));
163 }163 }
164164
165 pub fn dwarfLocOp(self: Register) u8 {165 pub fn dwarfLocOp(self: Register) u8 {
...@@ -399,8 +399,8 @@ pub const Instruction = union(enum) {...@@ -399,8 +399,8 @@ pub const Instruction = union(enum) {
399399
400 pub fn toU8(self: Shift) u8 {400 pub fn toU8(self: Shift) u8 {
401 return switch (self) {401 return switch (self) {
402 .register => |v| @bitCast(u8, v),402 .register => |v| @as(u8, @bitCast(v)),
403 .immediate => |v| @bitCast(u8, v),403 .immediate => |v| @as(u8, @bitCast(v)),
404 };404 };
405 }405 }
406406
...@@ -425,8 +425,8 @@ pub const Instruction = union(enum) {...@@ -425,8 +425,8 @@ pub const Instruction = union(enum) {
425425
426 pub fn toU12(self: Operand) u12 {426 pub fn toU12(self: Operand) u12 {
427 return switch (self) {427 return switch (self) {
428 .register => |v| @bitCast(u12, v),428 .register => |v| @as(u12, @bitCast(v)),
429 .immediate => |v| @bitCast(u12, v),429 .immediate => |v| @as(u12, @bitCast(v)),
430 };430 };
431 }431 }
432432
...@@ -463,8 +463,8 @@ pub const Instruction = union(enum) {...@@ -463,8 +463,8 @@ pub const Instruction = union(enum) {
463 if (x & mask == x) {463 if (x & mask == x) {
464 break Operand{464 break Operand{
465 .immediate = .{465 .immediate = .{
466 .imm = @intCast(u8, std.math.rotl(u32, x, 2 * i)),466 .imm = @as(u8, @intCast(std.math.rotl(u32, x, 2 * i))),
467 .rotate = @intCast(u4, i),467 .rotate = @as(u4, @intCast(i)),
468 },468 },
469 };469 };
470 }470 }
...@@ -522,7 +522,7 @@ pub const Instruction = union(enum) {...@@ -522,7 +522,7 @@ pub const Instruction = union(enum) {
522522
523 pub fn toU12(self: Offset) u12 {523 pub fn toU12(self: Offset) u12 {
524 return switch (self) {524 return switch (self) {
525 .register => |v| @bitCast(u12, v),525 .register => |v| @as(u12, @bitCast(v)),
526 .immediate => |v| v,526 .immediate => |v| v,
527 };527 };
528 }528 }
...@@ -604,20 +604,20 @@ pub const Instruction = union(enum) {...@@ -604,20 +604,20 @@ pub const Instruction = union(enum) {
604604
605 pub fn toU32(self: Instruction) u32 {605 pub fn toU32(self: Instruction) u32 {
606 return switch (self) {606 return switch (self) {
607 .data_processing => |v| @bitCast(u32, v),607 .data_processing => |v| @as(u32, @bitCast(v)),
608 .multiply => |v| @bitCast(u32, v),608 .multiply => |v| @as(u32, @bitCast(v)),
609 .multiply_long => |v| @bitCast(u32, v),609 .multiply_long => |v| @as(u32, @bitCast(v)),
610 .signed_multiply_halfwords => |v| @bitCast(u32, v),610 .signed_multiply_halfwords => |v| @as(u32, @bitCast(v)),
611 .integer_saturating_arithmetic => |v| @bitCast(u32, v),611 .integer_saturating_arithmetic => |v| @as(u32, @bitCast(v)),
612 .bit_field_extract => |v| @bitCast(u32, v),612 .bit_field_extract => |v| @as(u32, @bitCast(v)),
613 .single_data_transfer => |v| @bitCast(u32, v),613 .single_data_transfer => |v| @as(u32, @bitCast(v)),
614 .extra_load_store => |v| @bitCast(u32, v),614 .extra_load_store => |v| @as(u32, @bitCast(v)),
615 .block_data_transfer => |v| @bitCast(u32, v),615 .block_data_transfer => |v| @as(u32, @bitCast(v)),
616 .branch => |v| @bitCast(u32, v),616 .branch => |v| @as(u32, @bitCast(v)),
617 .branch_exchange => |v| @bitCast(u32, v),617 .branch_exchange => |v| @as(u32, @bitCast(v)),
618 .supervisor_call => |v| @bitCast(u32, v),618 .supervisor_call => |v| @as(u32, @bitCast(v)),
619 .undefined_instruction => |v| v.imm32,619 .undefined_instruction => |v| v.imm32,
620 .breakpoint => |v| @intCast(u32, v.imm4) | (@intCast(u32, v.fixed_1) << 4) | (@intCast(u32, v.imm12) << 8) | (@intCast(u32, v.fixed_2_and_cond) << 20),620 .breakpoint => |v| @as(u32, @intCast(v.imm4)) | (@as(u32, @intCast(v.fixed_1)) << 4) | (@as(u32, @intCast(v.imm12)) << 8) | (@as(u32, @intCast(v.fixed_2_and_cond)) << 20),
621 };621 };
622 }622 }
623623
...@@ -656,9 +656,9 @@ pub const Instruction = union(enum) {...@@ -656,9 +656,9 @@ pub const Instruction = union(enum) {
656 .i = 1,656 .i = 1,
657 .opcode = if (top) 0b1010 else 0b1000,657 .opcode = if (top) 0b1010 else 0b1000,
658 .s = 0,658 .s = 0,
659 .rn = @truncate(u4, imm >> 12),659 .rn = @as(u4, @truncate(imm >> 12)),
660 .rd = rd.id(),660 .rd = rd.id(),
661 .op2 = @truncate(u12, imm),661 .op2 = @as(u12, @truncate(imm)),
662 },662 },
663 };663 };
664 }664 }
...@@ -760,7 +760,7 @@ pub const Instruction = union(enum) {...@@ -760,7 +760,7 @@ pub const Instruction = union(enum) {
760 .rn = rn.id(),760 .rn = rn.id(),
761 .lsb = lsb,761 .lsb = lsb,
762 .rd = rd.id(),762 .rd = rd.id(),
763 .widthm1 = @intCast(u5, width - 1),763 .widthm1 = @as(u5, @intCast(width - 1)),
764 .unsigned = unsigned,764 .unsigned = unsigned,
765 .cond = @intFromEnum(cond),765 .cond = @intFromEnum(cond),
766 },766 },
...@@ -810,11 +810,11 @@ pub const Instruction = union(enum) {...@@ -810,11 +810,11 @@ pub const Instruction = union(enum) {
810 offset: ExtraLoadStoreOffset,810 offset: ExtraLoadStoreOffset,
811 ) Instruction {811 ) Instruction {
812 const imm4l: u4 = switch (offset) {812 const imm4l: u4 = switch (offset) {
813 .immediate => |imm| @truncate(u4, imm),813 .immediate => |imm| @as(u4, @truncate(imm)),
814 .register => |reg| reg,814 .register => |reg| reg,
815 };815 };
816 const imm4h: u4 = switch (offset) {816 const imm4h: u4 = switch (offset) {
817 .immediate => |imm| @truncate(u4, imm >> 4),817 .immediate => |imm| @as(u4, @truncate(imm >> 4)),
818 .register => 0b0000,818 .register => 0b0000,
819 };819 };
820820
...@@ -853,7 +853,7 @@ pub const Instruction = union(enum) {...@@ -853,7 +853,7 @@ pub const Instruction = union(enum) {
853 ) Instruction {853 ) Instruction {
854 return Instruction{854 return Instruction{
855 .block_data_transfer = .{855 .block_data_transfer = .{
856 .register_list = @bitCast(u16, reg_list),856 .register_list = @as(u16, @bitCast(reg_list)),
857 .rn = rn.id(),857 .rn = rn.id(),
858 .load_store = load_store,858 .load_store = load_store,
859 .write_back = @intFromBool(write_back),859 .write_back = @intFromBool(write_back),
...@@ -870,7 +870,7 @@ pub const Instruction = union(enum) {...@@ -870,7 +870,7 @@ pub const Instruction = union(enum) {
870 .branch = .{870 .branch = .{
871 .cond = @intFromEnum(cond),871 .cond = @intFromEnum(cond),
872 .link = link,872 .link = link,
873 .offset = @bitCast(u24, @intCast(i24, offset >> 2)),873 .offset = @as(u24, @bitCast(@as(i24, @intCast(offset >> 2)))),
874 },874 },
875 };875 };
876 }876 }
...@@ -904,8 +904,8 @@ pub const Instruction = union(enum) {...@@ -904,8 +904,8 @@ pub const Instruction = union(enum) {
904 fn breakpoint(imm: u16) Instruction {904 fn breakpoint(imm: u16) Instruction {
905 return Instruction{905 return Instruction{
906 .breakpoint = .{906 .breakpoint = .{
907 .imm12 = @truncate(u12, imm >> 4),907 .imm12 = @as(u12, @truncate(imm >> 4)),
908 .imm4 = @truncate(u4, imm),908 .imm4 = @as(u4, @truncate(imm)),
909 },909 },
910 };910 };
911 }911 }
...@@ -1319,7 +1319,7 @@ pub const Instruction = union(enum) {...@@ -1319,7 +1319,7 @@ pub const Instruction = union(enum) {
1319 const reg = @as(Register, arg);1319 const reg = @as(Register, arg);
1320 register_list |= @as(u16, 1) << reg.id();1320 register_list |= @as(u16, 1) << reg.id();
1321 }1321 }
1322 return ldm(cond, .sp, true, @bitCast(RegisterList, register_list));1322 return ldm(cond, .sp, true, @as(RegisterList, @bitCast(register_list)));
1323 }1323 }
1324 }1324 }
13251325
...@@ -1343,7 +1343,7 @@ pub const Instruction = union(enum) {...@@ -1343,7 +1343,7 @@ pub const Instruction = union(enum) {
1343 const reg = @as(Register, arg);1343 const reg = @as(Register, arg);
1344 register_list |= @as(u16, 1) << reg.id();1344 register_list |= @as(u16, 1) << reg.id();
1345 }1345 }
1346 return stmdb(cond, .sp, true, @bitCast(RegisterList, register_list));1346 return stmdb(cond, .sp, true, @as(RegisterList, @bitCast(register_list)));
1347 }1347 }
1348 }1348 }
13491349
src/arch/riscv64/CodeGen.zig+19-19
...@@ -323,7 +323,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {...@@ -323,7 +323,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
323323
324 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);324 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);
325325
326 const result_index = @intCast(Air.Inst.Index, self.mir_instructions.len);326 const result_index = @as(Air.Inst.Index, @intCast(self.mir_instructions.len));
327 self.mir_instructions.appendAssumeCapacity(inst);327 self.mir_instructions.appendAssumeCapacity(inst);
328 return result_index;328 return result_index;
329}329}
...@@ -336,11 +336,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {...@@ -336,11 +336,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {
336336
337pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {337pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
338 const fields = std.meta.fields(@TypeOf(extra));338 const fields = std.meta.fields(@TypeOf(extra));
339 const result = @intCast(u32, self.mir_extra.items.len);339 const result = @as(u32, @intCast(self.mir_extra.items.len));
340 inline for (fields) |field| {340 inline for (fields) |field| {
341 self.mir_extra.appendAssumeCapacity(switch (field.type) {341 self.mir_extra.appendAssumeCapacity(switch (field.type) {
342 u32 => @field(extra, field.name),342 u32 => @field(extra, field.name),
343 i32 => @bitCast(u32, @field(extra, field.name)),343 i32 => @as(u32, @bitCast(@field(extra, field.name))),
344 else => @compileError("bad field type"),344 else => @compileError("bad field type"),
345 });345 });
346 }346 }
...@@ -752,15 +752,15 @@ fn finishAirBookkeeping(self: *Self) void {...@@ -752,15 +752,15 @@ fn finishAirBookkeeping(self: *Self) void {
752fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void {752fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void {
753 var tomb_bits = self.liveness.getTombBits(inst);753 var tomb_bits = self.liveness.getTombBits(inst);
754 for (operands) |op| {754 for (operands) |op| {
755 const dies = @truncate(u1, tomb_bits) != 0;755 const dies = @as(u1, @truncate(tomb_bits)) != 0;
756 tomb_bits >>= 1;756 tomb_bits >>= 1;
757 if (!dies) continue;757 if (!dies) continue;
758 const op_int = @intFromEnum(op);758 const op_int = @intFromEnum(op);
759 if (op_int < Air.ref_start_index) continue;759 if (op_int < Air.ref_start_index) continue;
760 const op_index = @intCast(Air.Inst.Index, op_int - Air.ref_start_index);760 const op_index = @as(Air.Inst.Index, @intCast(op_int - Air.ref_start_index));
761 self.processDeath(op_index);761 self.processDeath(op_index);
762 }762 }
763 const is_used = @truncate(u1, tomb_bits) == 0;763 const is_used = @as(u1, @truncate(tomb_bits)) == 0;
764 if (is_used) {764 if (is_used) {
765 log.debug("%{d} => {}", .{ inst, result });765 log.debug("%{d} => {}", .{ inst, result });
766 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];766 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
...@@ -1709,7 +1709,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -1709,7 +1709,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
1709 const fn_ty = self.typeOf(pl_op.operand);1709 const fn_ty = self.typeOf(pl_op.operand);
1710 const callee = pl_op.operand;1710 const callee = pl_op.operand;
1711 const extra = self.air.extraData(Air.Call, pl_op.payload);1711 const extra = self.air.extraData(Air.Call, pl_op.payload);
1712 const args = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra.end..][0..extra.data.args_len]);1712 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));
17131713
1714 var info = try self.resolveCallingConventionValues(fn_ty);1714 var info = try self.resolveCallingConventionValues(fn_ty);
1715 defer info.deinit(self);1715 defer info.deinit(self);
...@@ -1747,7 +1747,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -1747,7 +1747,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
1747 const atom_index = try elf_file.getOrCreateAtomForDecl(func.owner_decl);1747 const atom_index = try elf_file.getOrCreateAtomForDecl(func.owner_decl);
1748 const atom = elf_file.getAtom(atom_index);1748 const atom = elf_file.getAtom(atom_index);
1749 _ = try atom.getOrCreateOffsetTableEntry(elf_file);1749 _ = try atom.getOrCreateOffsetTableEntry(elf_file);
1750 const got_addr = @intCast(u32, atom.getOffsetTableAddress(elf_file));1750 const got_addr = @as(u32, @intCast(atom.getOffsetTableAddress(elf_file)));
1751 try self.genSetReg(Type.usize, .ra, .{ .memory = got_addr });1751 try self.genSetReg(Type.usize, .ra, .{ .memory = got_addr });
1752 _ = try self.addInst(.{1752 _ = try self.addInst(.{
1753 .tag = .jalr,1753 .tag = .jalr,
...@@ -2139,12 +2139,12 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {...@@ -2139,12 +2139,12 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {
2139fn airAsm(self: *Self, inst: Air.Inst.Index) !void {2139fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
2140 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2140 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
2141 const extra = self.air.extraData(Air.Asm, ty_pl.payload);2141 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
2142 const is_volatile = @truncate(u1, extra.data.flags >> 31) != 0;2142 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
2143 const clobbers_len = @truncate(u31, extra.data.flags);2143 const clobbers_len = @as(u31, @truncate(extra.data.flags));
2144 var extra_i: usize = extra.end;2144 var extra_i: usize = extra.end;
2145 const outputs = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra_i..][0..extra.data.outputs_len]);2145 const outputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]));
2146 extra_i += outputs.len;2146 extra_i += outputs.len;
2147 const inputs = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra_i..][0..extra.data.inputs_len]);2147 const inputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]));
2148 extra_i += inputs.len;2148 extra_i += inputs.len;
21492149
2150 const dead = !is_volatile and self.liveness.isUnused(inst);2150 const dead = !is_volatile and self.liveness.isUnused(inst);
...@@ -2289,20 +2289,20 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -2289,20 +2289,20 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
2289 return self.genSetReg(ty, reg, .{ .immediate = 0xaaaaaaaaaaaaaaaa });2289 return self.genSetReg(ty, reg, .{ .immediate = 0xaaaaaaaaaaaaaaaa });
2290 },2290 },
2291 .immediate => |unsigned_x| {2291 .immediate => |unsigned_x| {
2292 const x = @bitCast(i64, unsigned_x);2292 const x = @as(i64, @bitCast(unsigned_x));
2293 if (math.minInt(i12) <= x and x <= math.maxInt(i12)) {2293 if (math.minInt(i12) <= x and x <= math.maxInt(i12)) {
2294 _ = try self.addInst(.{2294 _ = try self.addInst(.{
2295 .tag = .addi,2295 .tag = .addi,
2296 .data = .{ .i_type = .{2296 .data = .{ .i_type = .{
2297 .rd = reg,2297 .rd = reg,
2298 .rs1 = .zero,2298 .rs1 = .zero,
2299 .imm12 = @intCast(i12, x),2299 .imm12 = @as(i12, @intCast(x)),
2300 } },2300 } },
2301 });2301 });
2302 } else if (math.minInt(i32) <= x and x <= math.maxInt(i32)) {2302 } else if (math.minInt(i32) <= x and x <= math.maxInt(i32)) {
2303 const lo12 = @truncate(i12, x);2303 const lo12 = @as(i12, @truncate(x));
2304 const carry: i32 = if (lo12 < 0) 1 else 0;2304 const carry: i32 = if (lo12 < 0) 1 else 0;
2305 const hi20 = @truncate(i20, (x >> 12) +% carry);2305 const hi20 = @as(i20, @truncate((x >> 12) +% carry));
23062306
2307 // TODO: add test case for 32-bit immediate2307 // TODO: add test case for 32-bit immediate
2308 _ = try self.addInst(.{2308 _ = try self.addInst(.{
...@@ -2501,7 +2501,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -2501,7 +2501,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
2501 const vector_ty = self.typeOfIndex(inst);2501 const vector_ty = self.typeOfIndex(inst);
2502 const len = vector_ty.vectorLen(mod);2502 const len = vector_ty.vectorLen(mod);
2503 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2503 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
2504 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);2504 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
2505 const result: MCValue = res: {2505 const result: MCValue = res: {
2506 if (self.liveness.isUnused(inst)) break :res MCValue.dead;2506 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
2507 return self.fail("TODO implement airAggregateInit for riscv64", .{});2507 return self.fail("TODO implement airAggregateInit for riscv64", .{});
...@@ -2653,7 +2653,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -2653,7 +2653,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
2653 const argument_registers = [_]Register{ .a0, .a1, .a2, .a3, .a4, .a5, .a6, .a7 };2653 const argument_registers = [_]Register{ .a0, .a1, .a2, .a3, .a4, .a5, .a6, .a7 };
26542654
2655 for (fn_info.param_types, 0..) |ty, i| {2655 for (fn_info.param_types, 0..) |ty, i| {
2656 const param_size = @intCast(u32, ty.toType().abiSize(mod));2656 const param_size = @as(u32, @intCast(ty.toType().abiSize(mod)));
2657 if (param_size <= 8) {2657 if (param_size <= 8) {
2658 if (next_register < argument_registers.len) {2658 if (next_register < argument_registers.len) {
2659 result.args[i] = .{ .register = argument_registers[next_register] };2659 result.args[i] = .{ .register = argument_registers[next_register] };
...@@ -2690,7 +2690,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -2690,7 +2690,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
2690 } else switch (cc) {2690 } else switch (cc) {
2691 .Naked => unreachable,2691 .Naked => unreachable,
2692 .Unspecified, .C => {2692 .Unspecified, .C => {
2693 const ret_ty_size = @intCast(u32, ret_ty.abiSize(mod));2693 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
2694 if (ret_ty_size <= 8) {2694 if (ret_ty_size <= 8) {
2695 result.return_value = .{ .register = .a0 };2695 result.return_value = .{ .register = .a0 };
2696 } else if (ret_ty_size <= 16) {2696 } else if (ret_ty_size <= 16) {
src/arch/riscv64/Emit.zig+5-5
...@@ -39,7 +39,7 @@ pub fn emitMir(...@@ -39,7 +39,7 @@ pub fn emitMir(
3939
40 // Emit machine code40 // Emit machine code
41 for (mir_tags, 0..) |tag, index| {41 for (mir_tags, 0..) |tag, index| {
42 const inst = @intCast(u32, index);42 const inst = @as(u32, @intCast(index));
43 switch (tag) {43 switch (tag) {
44 .add => try emit.mirRType(inst),44 .add => try emit.mirRType(inst),
45 .sub => try emit.mirRType(inst),45 .sub => try emit.mirRType(inst),
...@@ -85,7 +85,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {...@@ -85,7 +85,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
85}85}
8686
87fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {87fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {
88 const delta_line = @intCast(i32, line) - @intCast(i32, self.prev_di_line);88 const delta_line = @as(i32, @intCast(line)) - @as(i32, @intCast(self.prev_di_line));
89 const delta_pc: usize = self.code.items.len - self.prev_di_pc;89 const delta_pc: usize = self.code.items.len - self.prev_di_pc;
90 switch (self.debug_output) {90 switch (self.debug_output) {
91 .dwarf => |dw| {91 .dwarf => |dw| {
...@@ -102,13 +102,13 @@ fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {...@@ -102,13 +102,13 @@ fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {
102 // increasing the line number102 // increasing the line number
103 try @import("../../link/Plan9.zig").changeLine(dbg_out.dbg_line, delta_line);103 try @import("../../link/Plan9.zig").changeLine(dbg_out.dbg_line, delta_line);
104 // increasing the pc104 // increasing the pc
105 const d_pc_p9 = @intCast(i64, delta_pc) - quant;105 const d_pc_p9 = @as(i64, @intCast(delta_pc)) - quant;
106 if (d_pc_p9 > 0) {106 if (d_pc_p9 > 0) {
107 // minus one because if its the last one, we want to leave space to change the line which is one quanta107 // minus one because if its the last one, we want to leave space to change the line which is one quanta
108 try dbg_out.dbg_line.append(@intCast(u8, @divExact(d_pc_p9, quant) + 128) - quant);108 try dbg_out.dbg_line.append(@as(u8, @intCast(@divExact(d_pc_p9, quant) + 128)) - quant);
109 if (dbg_out.pcop_change_index.*) |pci|109 if (dbg_out.pcop_change_index.*) |pci|
110 dbg_out.dbg_line.items[pci] += 1;110 dbg_out.dbg_line.items[pci] += 1;
111 dbg_out.pcop_change_index.* = @intCast(u32, dbg_out.dbg_line.items.len - 1);111 dbg_out.pcop_change_index.* = @as(u32, @intCast(dbg_out.dbg_line.items.len - 1));
112 } else if (d_pc_p9 == 0) {112 } else if (d_pc_p9 == 0) {
113 // we don't need to do anything, because adding the quant does it for us113 // we don't need to do anything, because adding the quant does it for us
114 } else unreachable;114 } else unreachable;
src/arch/riscv64/Mir.zig+1-1
...@@ -135,7 +135,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end...@@ -135,7 +135,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end
135 inline for (fields) |field| {135 inline for (fields) |field| {
136 @field(result, field.name) = switch (field.type) {136 @field(result, field.name) = switch (field.type) {
137 u32 => mir.extra[i],137 u32 => mir.extra[i],
138 i32 => @bitCast(i32, mir.extra[i]),138 i32 => @as(i32, @bitCast(mir.extra[i])),
139 else => @compileError("bad field type"),139 else => @compileError("bad field type"),
140 };140 };
141 i += 1;141 i += 1;
src/arch/riscv64/bits.zig+23-23
...@@ -56,12 +56,12 @@ pub const Instruction = union(enum) {...@@ -56,12 +56,12 @@ pub const Instruction = union(enum) {
56 // TODO: once packed structs work we can remove this monstrosity.56 // TODO: once packed structs work we can remove this monstrosity.
57 pub fn toU32(self: Instruction) u32 {57 pub fn toU32(self: Instruction) u32 {
58 return switch (self) {58 return switch (self) {
59 .R => |v| @bitCast(u32, v),59 .R => |v| @as(u32, @bitCast(v)),
60 .I => |v| @bitCast(u32, v),60 .I => |v| @as(u32, @bitCast(v)),
61 .S => |v| @bitCast(u32, v),61 .S => |v| @as(u32, @bitCast(v)),
62 .B => |v| @intCast(u32, v.opcode) + (@intCast(u32, v.imm11) << 7) + (@intCast(u32, v.imm1_4) << 8) + (@intCast(u32, v.funct3) << 12) + (@intCast(u32, v.rs1) << 15) + (@intCast(u32, v.rs2) << 20) + (@intCast(u32, v.imm5_10) << 25) + (@intCast(u32, v.imm12) << 31),62 .B => |v| @as(u32, @intCast(v.opcode)) + (@as(u32, @intCast(v.imm11)) << 7) + (@as(u32, @intCast(v.imm1_4)) << 8) + (@as(u32, @intCast(v.funct3)) << 12) + (@as(u32, @intCast(v.rs1)) << 15) + (@as(u32, @intCast(v.rs2)) << 20) + (@as(u32, @intCast(v.imm5_10)) << 25) + (@as(u32, @intCast(v.imm12)) << 31),
63 .U => |v| @bitCast(u32, v),63 .U => |v| @as(u32, @bitCast(v)),
64 .J => |v| @bitCast(u32, v),64 .J => |v| @as(u32, @bitCast(v)),
65 };65 };
66 }66 }
6767
...@@ -80,7 +80,7 @@ pub const Instruction = union(enum) {...@@ -80,7 +80,7 @@ pub const Instruction = union(enum) {
8080
81 // RISC-V is all signed all the time -- convert immediates to unsigned for processing81 // RISC-V is all signed all the time -- convert immediates to unsigned for processing
82 fn iType(op: u7, fn3: u3, rd: Register, r1: Register, imm: i12) Instruction {82 fn iType(op: u7, fn3: u3, rd: Register, r1: Register, imm: i12) Instruction {
83 const umm = @bitCast(u12, imm);83 const umm = @as(u12, @bitCast(imm));
8484
85 return Instruction{85 return Instruction{
86 .I = .{86 .I = .{
...@@ -94,7 +94,7 @@ pub const Instruction = union(enum) {...@@ -94,7 +94,7 @@ pub const Instruction = union(enum) {
94 }94 }
9595
96 fn sType(op: u7, fn3: u3, r1: Register, r2: Register, imm: i12) Instruction {96 fn sType(op: u7, fn3: u3, r1: Register, r2: Register, imm: i12) Instruction {
97 const umm = @bitCast(u12, imm);97 const umm = @as(u12, @bitCast(imm));
9898
99 return Instruction{99 return Instruction{
100 .S = .{100 .S = .{
...@@ -102,8 +102,8 @@ pub const Instruction = union(enum) {...@@ -102,8 +102,8 @@ pub const Instruction = union(enum) {
102 .funct3 = fn3,102 .funct3 = fn3,
103 .rs1 = r1.id(),103 .rs1 = r1.id(),
104 .rs2 = r2.id(),104 .rs2 = r2.id(),
105 .imm0_4 = @truncate(u5, umm),105 .imm0_4 = @as(u5, @truncate(umm)),
106 .imm5_11 = @truncate(u7, umm >> 5),106 .imm5_11 = @as(u7, @truncate(umm >> 5)),
107 },107 },
108 };108 };
109 }109 }
...@@ -111,7 +111,7 @@ pub const Instruction = union(enum) {...@@ -111,7 +111,7 @@ pub const Instruction = union(enum) {
111 // Use significance value rather than bit value, same for J-type111 // Use significance value rather than bit value, same for J-type
112 // -- less burden on callsite, bonus semantic checking112 // -- less burden on callsite, bonus semantic checking
113 fn bType(op: u7, fn3: u3, r1: Register, r2: Register, imm: i13) Instruction {113 fn bType(op: u7, fn3: u3, r1: Register, r2: Register, imm: i13) Instruction {
114 const umm = @bitCast(u13, imm);114 const umm = @as(u13, @bitCast(imm));
115 assert(umm % 2 == 0); // misaligned branch target115 assert(umm % 2 == 0); // misaligned branch target
116116
117 return Instruction{117 return Instruction{
...@@ -120,17 +120,17 @@ pub const Instruction = union(enum) {...@@ -120,17 +120,17 @@ pub const Instruction = union(enum) {
120 .funct3 = fn3,120 .funct3 = fn3,
121 .rs1 = r1.id(),121 .rs1 = r1.id(),
122 .rs2 = r2.id(),122 .rs2 = r2.id(),
123 .imm1_4 = @truncate(u4, umm >> 1),123 .imm1_4 = @as(u4, @truncate(umm >> 1)),
124 .imm5_10 = @truncate(u6, umm >> 5),124 .imm5_10 = @as(u6, @truncate(umm >> 5)),
125 .imm11 = @truncate(u1, umm >> 11),125 .imm11 = @as(u1, @truncate(umm >> 11)),
126 .imm12 = @truncate(u1, umm >> 12),126 .imm12 = @as(u1, @truncate(umm >> 12)),
127 },127 },
128 };128 };
129 }129 }
130130
131 // We have to extract the 20 bits anyway -- let's not make it more painful131 // We have to extract the 20 bits anyway -- let's not make it more painful
132 fn uType(op: u7, rd: Register, imm: i20) Instruction {132 fn uType(op: u7, rd: Register, imm: i20) Instruction {
133 const umm = @bitCast(u20, imm);133 const umm = @as(u20, @bitCast(imm));
134134
135 return Instruction{135 return Instruction{
136 .U = .{136 .U = .{
...@@ -142,17 +142,17 @@ pub const Instruction = union(enum) {...@@ -142,17 +142,17 @@ pub const Instruction = union(enum) {
142 }142 }
143143
144 fn jType(op: u7, rd: Register, imm: i21) Instruction {144 fn jType(op: u7, rd: Register, imm: i21) Instruction {
145 const umm = @bitCast(u21, imm);145 const umm = @as(u21, @bitCast(imm));
146 assert(umm % 2 == 0); // misaligned jump target146 assert(umm % 2 == 0); // misaligned jump target
147147
148 return Instruction{148 return Instruction{
149 .J = .{149 .J = .{
150 .opcode = op,150 .opcode = op,
151 .rd = rd.id(),151 .rd = rd.id(),
152 .imm1_10 = @truncate(u10, umm >> 1),152 .imm1_10 = @as(u10, @truncate(umm >> 1)),
153 .imm11 = @truncate(u1, umm >> 11),153 .imm11 = @as(u1, @truncate(umm >> 11)),
154 .imm12_19 = @truncate(u8, umm >> 12),154 .imm12_19 = @as(u8, @truncate(umm >> 12)),
155 .imm20 = @truncate(u1, umm >> 20),155 .imm20 = @as(u1, @truncate(umm >> 20)),
156 },156 },
157 };157 };
158 }158 }
...@@ -258,7 +258,7 @@ pub const Instruction = union(enum) {...@@ -258,7 +258,7 @@ pub const Instruction = union(enum) {
258 }258 }
259259
260 pub fn sltiu(rd: Register, r1: Register, imm: u12) Instruction {260 pub fn sltiu(rd: Register, r1: Register, imm: u12) Instruction {
261 return iType(0b0010011, 0b011, rd, r1, @bitCast(i12, imm));261 return iType(0b0010011, 0b011, rd, r1, @as(i12, @bitCast(imm)));
262 }262 }
263263
264 // Arithmetic/Logical, Register-Immediate (32-bit)264 // Arithmetic/Logical, Register-Immediate (32-bit)
...@@ -407,7 +407,7 @@ pub const Register = enum(u6) {...@@ -407,7 +407,7 @@ pub const Register = enum(u6) {
407 /// Returns the unique 4-bit ID of this register which is used in407 /// Returns the unique 4-bit ID of this register which is used in
408 /// the machine code408 /// the machine code
409 pub fn id(self: Register) u5 {409 pub fn id(self: Register) u5 {
410 return @truncate(u5, @intFromEnum(self));410 return @as(u5, @truncate(@intFromEnum(self)));
411 }411 }
412412
413 pub fn dwarfLocOp(reg: Register) u8 {413 pub fn dwarfLocOp(reg: Register) u8 {
src/arch/sparc64/CodeGen.zig+43-43
...@@ -415,7 +415,7 @@ fn gen(self: *Self) !void {...@@ -415,7 +415,7 @@ fn gen(self: *Self) !void {
415 .branch_predict_int = .{415 .branch_predict_int = .{
416 .ccr = .xcc,416 .ccr = .xcc,
417 .cond = .al,417 .cond = .al,
418 .inst = @intCast(u32, self.mir_instructions.len),418 .inst = @as(u32, @intCast(self.mir_instructions.len)),
419 },419 },
420 },420 },
421 });421 });
...@@ -840,7 +840,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -840,7 +840,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
840 const vector_ty = self.typeOfIndex(inst);840 const vector_ty = self.typeOfIndex(inst);
841 const len = vector_ty.vectorLen(mod);841 const len = vector_ty.vectorLen(mod);
842 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;842 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
843 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);843 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
844 const result: MCValue = res: {844 const result: MCValue = res: {
845 if (self.liveness.isUnused(inst)) break :res MCValue.dead;845 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
846 return self.fail("TODO implement airAggregateInit for {}", .{self.target.cpu.arch});846 return self.fail("TODO implement airAggregateInit for {}", .{self.target.cpu.arch});
...@@ -876,7 +876,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {...@@ -876,7 +876,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
876 const ptr_ty = self.typeOf(ty_op.operand);876 const ptr_ty = self.typeOf(ty_op.operand);
877 const ptr = try self.resolveInst(ty_op.operand);877 const ptr = try self.resolveInst(ty_op.operand);
878 const array_ty = ptr_ty.childType(mod);878 const array_ty = ptr_ty.childType(mod);
879 const array_len = @intCast(u32, array_ty.arrayLen(mod));879 const array_len = @as(u32, @intCast(array_ty.arrayLen(mod)));
880880
881 const ptr_bits = self.target.ptrBitWidth();881 const ptr_bits = self.target.ptrBitWidth();
882 const ptr_bytes = @divExact(ptr_bits, 8);882 const ptr_bytes = @divExact(ptr_bits, 8);
...@@ -893,11 +893,11 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -893,11 +893,11 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
893 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;893 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
894 const extra = self.air.extraData(Air.Asm, ty_pl.payload);894 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
895 const is_volatile = (extra.data.flags & 0x80000000) != 0;895 const is_volatile = (extra.data.flags & 0x80000000) != 0;
896 const clobbers_len = @truncate(u31, extra.data.flags);896 const clobbers_len = @as(u31, @truncate(extra.data.flags));
897 var extra_i: usize = extra.end;897 var extra_i: usize = extra.end;
898 const outputs = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra_i .. extra_i + extra.data.outputs_len]);898 const outputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i .. extra_i + extra.data.outputs_len]));
899 extra_i += outputs.len;899 extra_i += outputs.len;
900 const inputs = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra_i .. extra_i + extra.data.inputs_len]);900 const inputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i .. extra_i + extra.data.inputs_len]));
901 extra_i += inputs.len;901 extra_i += inputs.len;
902902
903 const dead = !is_volatile and self.liveness.isUnused(inst);903 const dead = !is_volatile and self.liveness.isUnused(inst);
...@@ -1237,13 +1237,13 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {...@@ -1237,13 +1237,13 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
1237 switch (operand) {1237 switch (operand) {
1238 .immediate => |imm| {1238 .immediate => |imm| {
1239 const swapped = switch (int_info.bits) {1239 const swapped = switch (int_info.bits) {
1240 16 => @byteSwap(@intCast(u16, imm)),1240 16 => @byteSwap(@as(u16, @intCast(imm))),
1241 24 => @byteSwap(@intCast(u24, imm)),1241 24 => @byteSwap(@as(u24, @intCast(imm))),
1242 32 => @byteSwap(@intCast(u32, imm)),1242 32 => @byteSwap(@as(u32, @intCast(imm))),
1243 40 => @byteSwap(@intCast(u40, imm)),1243 40 => @byteSwap(@as(u40, @intCast(imm))),
1244 48 => @byteSwap(@intCast(u48, imm)),1244 48 => @byteSwap(@as(u48, @intCast(imm))),
1245 56 => @byteSwap(@intCast(u56, imm)),1245 56 => @byteSwap(@as(u56, @intCast(imm))),
1246 64 => @byteSwap(@intCast(u64, imm)),1246 64 => @byteSwap(@as(u64, @intCast(imm))),
1247 else => return self.fail("TODO synthesize SPARCv9 byteswap for other integer sizes", .{}),1247 else => return self.fail("TODO synthesize SPARCv9 byteswap for other integer sizes", .{}),
1248 };1248 };
1249 break :result .{ .immediate = swapped };1249 break :result .{ .immediate = swapped };
...@@ -1295,7 +1295,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -1295,7 +1295,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
1295 const pl_op = self.air.instructions.items(.data)[inst].pl_op;1295 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
1296 const callee = pl_op.operand;1296 const callee = pl_op.operand;
1297 const extra = self.air.extraData(Air.Call, pl_op.payload);1297 const extra = self.air.extraData(Air.Call, pl_op.payload);
1298 const args = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra.end .. extra.end + extra.data.args_len]);1298 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end .. extra.end + extra.data.args_len]));
1299 const ty = self.typeOf(callee);1299 const ty = self.typeOf(callee);
1300 const mod = self.bin_file.options.module.?;1300 const mod = self.bin_file.options.module.?;
1301 const fn_ty = switch (ty.zigTypeTag(mod)) {1301 const fn_ty = switch (ty.zigTypeTag(mod)) {
...@@ -1348,7 +1348,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -1348,7 +1348,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
1348 const atom_index = try elf_file.getOrCreateAtomForDecl(func.owner_decl);1348 const atom_index = try elf_file.getOrCreateAtomForDecl(func.owner_decl);
1349 const atom = elf_file.getAtom(atom_index);1349 const atom = elf_file.getAtom(atom_index);
1350 _ = try atom.getOrCreateOffsetTableEntry(elf_file);1350 _ = try atom.getOrCreateOffsetTableEntry(elf_file);
1351 break :blk @intCast(u32, atom.getOffsetTableAddress(elf_file));1351 break :blk @as(u32, @intCast(atom.getOffsetTableAddress(elf_file)));
1352 } else unreachable;1352 } else unreachable;
13531353
1354 try self.genSetReg(Type.usize, .o7, .{ .memory = got_addr });1354 try self.genSetReg(Type.usize, .o7, .{ .memory = got_addr });
...@@ -1515,7 +1515,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1515,7 +1515,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
1515 if (self.liveness.operandDies(inst, 0)) {1515 if (self.liveness.operandDies(inst, 0)) {
1516 const op_int = @intFromEnum(pl_op.operand);1516 const op_int = @intFromEnum(pl_op.operand);
1517 if (op_int >= Air.ref_start_index) {1517 if (op_int >= Air.ref_start_index) {
1518 const op_index = @intCast(Air.Inst.Index, op_int - Air.ref_start_index);1518 const op_index = @as(Air.Inst.Index, @intCast(op_int - Air.ref_start_index));
1519 self.processDeath(op_index);1519 self.processDeath(op_index);
1520 }1520 }
1521 }1521 }
...@@ -1851,7 +1851,7 @@ fn airLoop(self: *Self, inst: Air.Inst.Index) !void {...@@ -1851,7 +1851,7 @@ fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
1851 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;1851 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
1852 const loop = self.air.extraData(Air.Block, ty_pl.payload);1852 const loop = self.air.extraData(Air.Block, ty_pl.payload);
1853 const body = self.air.extra[loop.end .. loop.end + loop.data.body_len];1853 const body = self.air.extra[loop.end .. loop.end + loop.data.body_len];
1854 const start = @intCast(u32, self.mir_instructions.len);1854 const start = @as(u32, @intCast(self.mir_instructions.len));
18551855
1856 try self.genBody(body);1856 try self.genBody(body);
1857 try self.jump(start);1857 try self.jump(start);
...@@ -2574,7 +2574,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -2574,7 +2574,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
2574 const mod = self.bin_file.options.module.?;2574 const mod = self.bin_file.options.module.?;
2575 const mcv = try self.resolveInst(operand);2575 const mcv = try self.resolveInst(operand);
2576 const struct_ty = self.typeOf(operand);2576 const struct_ty = self.typeOf(operand);
2577 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, mod));2577 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, mod)));
25782578
2579 switch (mcv) {2579 switch (mcv) {
2580 .dead, .unreach => unreachable,2580 .dead, .unreach => unreachable,
...@@ -2772,7 +2772,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {...@@ -2772,7 +2772,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
2772fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {2772fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
2773 const gpa = self.gpa;2773 const gpa = self.gpa;
2774 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);2774 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);
2775 const result_index = @intCast(Air.Inst.Index, self.mir_instructions.len);2775 const result_index = @as(Air.Inst.Index, @intCast(self.mir_instructions.len));
2776 self.mir_instructions.appendAssumeCapacity(inst);2776 self.mir_instructions.appendAssumeCapacity(inst);
2777 return result_index;2777 return result_index;
2778}2778}
...@@ -3207,7 +3207,7 @@ fn binOpImmediate(...@@ -3207,7 +3207,7 @@ fn binOpImmediate(
3207 .is_imm = true,3207 .is_imm = true,
3208 .rd = dest_reg,3208 .rd = dest_reg,
3209 .rs1 = lhs_reg,3209 .rs1 = lhs_reg,
3210 .rs2_or_imm = .{ .imm = @intCast(u12, rhs.immediate) },3210 .rs2_or_imm = .{ .imm = @as(u12, @intCast(rhs.immediate)) },
3211 },3211 },
3212 },3212 },
3213 .sll,3213 .sll,
...@@ -3218,7 +3218,7 @@ fn binOpImmediate(...@@ -3218,7 +3218,7 @@ fn binOpImmediate(
3218 .is_imm = true,3218 .is_imm = true,
3219 .rd = dest_reg,3219 .rd = dest_reg,
3220 .rs1 = lhs_reg,3220 .rs1 = lhs_reg,
3221 .rs2_or_imm = .{ .imm = @intCast(u5, rhs.immediate) },3221 .rs2_or_imm = .{ .imm = @as(u5, @intCast(rhs.immediate)) },
3222 },3222 },
3223 },3223 },
3224 .sllx,3224 .sllx,
...@@ -3229,14 +3229,14 @@ fn binOpImmediate(...@@ -3229,14 +3229,14 @@ fn binOpImmediate(
3229 .is_imm = true,3229 .is_imm = true,
3230 .rd = dest_reg,3230 .rd = dest_reg,
3231 .rs1 = lhs_reg,3231 .rs1 = lhs_reg,
3232 .rs2_or_imm = .{ .imm = @intCast(u6, rhs.immediate) },3232 .rs2_or_imm = .{ .imm = @as(u6, @intCast(rhs.immediate)) },
3233 },3233 },
3234 },3234 },
3235 .cmp => .{3235 .cmp => .{
3236 .arithmetic_2op = .{3236 .arithmetic_2op = .{
3237 .is_imm = true,3237 .is_imm = true,
3238 .rs1 = lhs_reg,3238 .rs1 = lhs_reg,
3239 .rs2_or_imm = .{ .imm = @intCast(u12, rhs.immediate) },3239 .rs2_or_imm = .{ .imm = @as(u12, @intCast(rhs.immediate)) },
3240 },3240 },
3241 },3241 },
3242 else => unreachable,3242 else => unreachable,
...@@ -3535,7 +3535,7 @@ fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type)...@@ -3535,7 +3535,7 @@ fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type)
3535 return MCValue.none;3535 return MCValue.none;
3536 }3536 }
35373537
3538 const payload_offset = @intCast(u32, errUnionPayloadOffset(payload_ty, mod));3538 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, mod)));
3539 switch (error_union_mcv) {3539 switch (error_union_mcv) {
3540 .register => return self.fail("TODO errUnionPayload for registers", .{}),3540 .register => return self.fail("TODO errUnionPayload for registers", .{}),
3541 .stack_offset => |off| {3541 .stack_offset => |off| {
...@@ -3565,15 +3565,15 @@ fn finishAirBookkeeping(self: *Self) void {...@@ -3565,15 +3565,15 @@ fn finishAirBookkeeping(self: *Self) void {
3565fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void {3565fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void {
3566 var tomb_bits = self.liveness.getTombBits(inst);3566 var tomb_bits = self.liveness.getTombBits(inst);
3567 for (operands) |op| {3567 for (operands) |op| {
3568 const dies = @truncate(u1, tomb_bits) != 0;3568 const dies = @as(u1, @truncate(tomb_bits)) != 0;
3569 tomb_bits >>= 1;3569 tomb_bits >>= 1;
3570 if (!dies) continue;3570 if (!dies) continue;
3571 const op_int = @intFromEnum(op);3571 const op_int = @intFromEnum(op);
3572 if (op_int < Air.ref_start_index) continue;3572 if (op_int < Air.ref_start_index) continue;
3573 const op_index = @intCast(Air.Inst.Index, op_int - Air.ref_start_index);3573 const op_index = @as(Air.Inst.Index, @intCast(op_int - Air.ref_start_index));
3574 self.processDeath(op_index);3574 self.processDeath(op_index);
3575 }3575 }
3576 const is_used = @truncate(u1, tomb_bits) == 0;3576 const is_used = @as(u1, @truncate(tomb_bits)) == 0;
3577 if (is_used) {3577 if (is_used) {
3578 log.debug("%{d} => {}", .{ inst, result });3578 log.debug("%{d} => {}", .{ inst, result });
3579 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];3579 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
...@@ -3663,7 +3663,7 @@ fn genInlineMemcpy(...@@ -3663,7 +3663,7 @@ fn genInlineMemcpy(
3663 .data = .{ .branch_predict_reg = .{3663 .data = .{ .branch_predict_reg = .{
3664 .cond = .ne_zero,3664 .cond = .ne_zero,
3665 .rs1 = len,3665 .rs1 = len,
3666 .inst = @intCast(u32, self.mir_instructions.len - 2),3666 .inst = @as(u32, @intCast(self.mir_instructions.len - 2)),
3667 } },3667 } },
3668 });3668 });
36693669
...@@ -3838,7 +3838,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -3838,7 +3838,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
3838 .arithmetic_2op = .{3838 .arithmetic_2op = .{
3839 .is_imm = true,3839 .is_imm = true,
3840 .rs1 = reg,3840 .rs1 = reg,
3841 .rs2_or_imm = .{ .imm = @truncate(u12, x) },3841 .rs2_or_imm = .{ .imm = @as(u12, @truncate(x)) },
3842 },3842 },
3843 },3843 },
3844 });3844 });
...@@ -3848,7 +3848,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -3848,7 +3848,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
3848 .data = .{3848 .data = .{
3849 .sethi = .{3849 .sethi = .{
3850 .rd = reg,3850 .rd = reg,
3851 .imm = @truncate(u22, x >> 10),3851 .imm = @as(u22, @truncate(x >> 10)),
3852 },3852 },
3853 },3853 },
3854 });3854 });
...@@ -3860,12 +3860,12 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -3860,12 +3860,12 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
3860 .is_imm = true,3860 .is_imm = true,
3861 .rd = reg,3861 .rd = reg,
3862 .rs1 = reg,3862 .rs1 = reg,
3863 .rs2_or_imm = .{ .imm = @truncate(u10, x) },3863 .rs2_or_imm = .{ .imm = @as(u10, @truncate(x)) },
3864 },3864 },
3865 },3865 },
3866 });3866 });
3867 } else if (x <= math.maxInt(u44)) {3867 } else if (x <= math.maxInt(u44)) {
3868 try self.genSetReg(ty, reg, .{ .immediate = @truncate(u32, x >> 12) });3868 try self.genSetReg(ty, reg, .{ .immediate = @as(u32, @truncate(x >> 12)) });
38693869
3870 _ = try self.addInst(.{3870 _ = try self.addInst(.{
3871 .tag = .sllx,3871 .tag = .sllx,
...@@ -3886,7 +3886,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -3886,7 +3886,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
3886 .is_imm = true,3886 .is_imm = true,
3887 .rd = reg,3887 .rd = reg,
3888 .rs1 = reg,3888 .rs1 = reg,
3889 .rs2_or_imm = .{ .imm = @truncate(u12, x) },3889 .rs2_or_imm = .{ .imm = @as(u12, @truncate(x)) },
3890 },3890 },
3891 },3891 },
3892 });3892 });
...@@ -3894,8 +3894,8 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -3894,8 +3894,8 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
3894 // Need to allocate a temporary register to load 64-bit immediates.3894 // Need to allocate a temporary register to load 64-bit immediates.
3895 const tmp_reg = try self.register_manager.allocReg(null, gp);3895 const tmp_reg = try self.register_manager.allocReg(null, gp);
38963896
3897 try self.genSetReg(ty, tmp_reg, .{ .immediate = @truncate(u32, x) });3897 try self.genSetReg(ty, tmp_reg, .{ .immediate = @as(u32, @truncate(x)) });
3898 try self.genSetReg(ty, reg, .{ .immediate = @truncate(u32, x >> 32) });3898 try self.genSetReg(ty, reg, .{ .immediate = @as(u32, @truncate(x >> 32)) });
38993899
3900 _ = try self.addInst(.{3900 _ = try self.addInst(.{
3901 .tag = .sllx,3901 .tag = .sllx,
...@@ -3994,7 +3994,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro...@@ -3994,7 +3994,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
3994 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = rwo.reg });3994 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = rwo.reg });
39953995
3996 const overflow_bit_ty = ty.structFieldType(1, mod);3996 const overflow_bit_ty = ty.structFieldType(1, mod);
3997 const overflow_bit_offset = @intCast(u32, ty.structFieldOffset(1, mod));3997 const overflow_bit_offset = @as(u32, @intCast(ty.structFieldOffset(1, mod)));
3998 const cond_reg = try self.register_manager.allocReg(null, gp);3998 const cond_reg = try self.register_manager.allocReg(null, gp);
39993999
4000 // TODO handle floating point CCRs4000 // TODO handle floating point CCRs
...@@ -4412,8 +4412,8 @@ fn parseRegName(name: []const u8) ?Register {...@@ -4412,8 +4412,8 @@ fn parseRegName(name: []const u8) ?Register {
4412fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {4412fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {
4413 const tag = self.mir_instructions.items(.tag)[inst];4413 const tag = self.mir_instructions.items(.tag)[inst];
4414 switch (tag) {4414 switch (tag) {
4415 .bpcc => self.mir_instructions.items(.data)[inst].branch_predict_int.inst = @intCast(Mir.Inst.Index, self.mir_instructions.len),4415 .bpcc => self.mir_instructions.items(.data)[inst].branch_predict_int.inst = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len)),
4416 .bpr => self.mir_instructions.items(.data)[inst].branch_predict_reg.inst = @intCast(Mir.Inst.Index, self.mir_instructions.len),4416 .bpr => self.mir_instructions.items(.data)[inst].branch_predict_reg.inst = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len)),
4417 else => unreachable,4417 else => unreachable,
4418 }4418 }
4419}4419}
...@@ -4490,7 +4490,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)...@@ -4490,7 +4490,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
4490 };4490 };
44914491
4492 for (fn_info.param_types, 0..) |ty, i| {4492 for (fn_info.param_types, 0..) |ty, i| {
4493 const param_size = @intCast(u32, ty.toType().abiSize(mod));4493 const param_size = @as(u32, @intCast(ty.toType().abiSize(mod)));
4494 if (param_size <= 8) {4494 if (param_size <= 8) {
4495 if (next_register < argument_registers.len) {4495 if (next_register < argument_registers.len) {
4496 result.args[i] = .{ .register = argument_registers[next_register] };4496 result.args[i] = .{ .register = argument_registers[next_register] };
...@@ -4522,7 +4522,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)...@@ -4522,7 +4522,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
4522 } else if (!ret_ty.hasRuntimeBits(mod)) {4522 } else if (!ret_ty.hasRuntimeBits(mod)) {
4523 result.return_value = .{ .none = {} };4523 result.return_value = .{ .none = {} };
4524 } else {4524 } else {
4525 const ret_ty_size = @intCast(u32, ret_ty.abiSize(mod));4525 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
4526 // The callee puts the return values in %i0-%i3, which becomes %o0-%o3 inside the caller.4526 // The callee puts the return values in %i0-%i3, which becomes %o0-%o3 inside the caller.
4527 if (ret_ty_size <= 8) {4527 if (ret_ty_size <= 8) {
4528 result.return_value = switch (role) {4528 result.return_value = switch (role) {
...@@ -4721,7 +4721,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde...@@ -4721,7 +4721,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
4721 const mcv = try self.resolveInst(operand);4721 const mcv = try self.resolveInst(operand);
4722 const ptr_ty = self.typeOf(operand);4722 const ptr_ty = self.typeOf(operand);
4723 const struct_ty = ptr_ty.childType(mod);4723 const struct_ty = ptr_ty.childType(mod);
4724 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, mod));4724 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, mod)));
4725 switch (mcv) {4725 switch (mcv) {
4726 .ptr_stack_offset => |off| {4726 .ptr_stack_offset => |off| {
4727 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };4727 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };
...@@ -4816,7 +4816,7 @@ fn truncRegister(...@@ -4816,7 +4816,7 @@ fn truncRegister(
4816 .is_imm = true,4816 .is_imm = true,
4817 .rd = dest_reg,4817 .rd = dest_reg,
4818 .rs1 = operand_reg,4818 .rs1 = operand_reg,
4819 .rs2_or_imm = .{ .imm = @intCast(u6, 64 - int_bits) },4819 .rs2_or_imm = .{ .imm = @as(u6, @intCast(64 - int_bits)) },
4820 },4820 },
4821 },4821 },
4822 });4822 });
...@@ -4830,7 +4830,7 @@ fn truncRegister(...@@ -4830,7 +4830,7 @@ fn truncRegister(
4830 .is_imm = true,4830 .is_imm = true,
4831 .rd = dest_reg,4831 .rd = dest_reg,
4832 .rs1 = dest_reg,4832 .rs1 = dest_reg,
4833 .rs2_or_imm = .{ .imm = @intCast(u6, int_bits) },4833 .rs2_or_imm = .{ .imm = @as(u6, @intCast(int_bits)) },
4834 },4834 },
4835 },4835 },
4836 });4836 });
src/arch/sparc64/Emit.zig+13-13
...@@ -70,7 +70,7 @@ pub fn emitMir(...@@ -70,7 +70,7 @@ pub fn emitMir(
7070
71 // Emit machine code71 // Emit machine code
72 for (mir_tags, 0..) |tag, index| {72 for (mir_tags, 0..) |tag, index| {
73 const inst = @intCast(u32, index);73 const inst = @as(u32, @intCast(index));
74 switch (tag) {74 switch (tag) {
75 .dbg_line => try emit.mirDbgLine(inst),75 .dbg_line => try emit.mirDbgLine(inst),
76 .dbg_prologue_end => try emit.mirDebugPrologueEnd(),76 .dbg_prologue_end => try emit.mirDebugPrologueEnd(),
...@@ -294,7 +294,7 @@ fn mirConditionalBranch(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -294,7 +294,7 @@ fn mirConditionalBranch(emit: *Emit, inst: Mir.Inst.Index) !void {
294 .bpcc => switch (tag) {294 .bpcc => switch (tag) {
295 .bpcc => {295 .bpcc => {
296 const branch_predict_int = emit.mir.instructions.items(.data)[inst].branch_predict_int;296 const branch_predict_int = emit.mir.instructions.items(.data)[inst].branch_predict_int;
297 const offset = @intCast(i64, emit.code_offset_mapping.get(branch_predict_int.inst).?) - @intCast(i64, emit.code.items.len);297 const offset = @as(i64, @intCast(emit.code_offset_mapping.get(branch_predict_int.inst).?)) - @as(i64, @intCast(emit.code.items.len));
298 log.debug("mirConditionalBranch: {} offset={}", .{ inst, offset });298 log.debug("mirConditionalBranch: {} offset={}", .{ inst, offset });
299299
300 try emit.writeInstruction(300 try emit.writeInstruction(
...@@ -303,7 +303,7 @@ fn mirConditionalBranch(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -303,7 +303,7 @@ fn mirConditionalBranch(emit: *Emit, inst: Mir.Inst.Index) !void {
303 branch_predict_int.annul,303 branch_predict_int.annul,
304 branch_predict_int.pt,304 branch_predict_int.pt,
305 branch_predict_int.ccr,305 branch_predict_int.ccr,
306 @intCast(i21, offset),306 @as(i21, @intCast(offset)),
307 ),307 ),
308 );308 );
309 },309 },
...@@ -312,7 +312,7 @@ fn mirConditionalBranch(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -312,7 +312,7 @@ fn mirConditionalBranch(emit: *Emit, inst: Mir.Inst.Index) !void {
312 .bpr => switch (tag) {312 .bpr => switch (tag) {
313 .bpr => {313 .bpr => {
314 const branch_predict_reg = emit.mir.instructions.items(.data)[inst].branch_predict_reg;314 const branch_predict_reg = emit.mir.instructions.items(.data)[inst].branch_predict_reg;
315 const offset = @intCast(i64, emit.code_offset_mapping.get(branch_predict_reg.inst).?) - @intCast(i64, emit.code.items.len);315 const offset = @as(i64, @intCast(emit.code_offset_mapping.get(branch_predict_reg.inst).?)) - @as(i64, @intCast(emit.code.items.len));
316 log.debug("mirConditionalBranch: {} offset={}", .{ inst, offset });316 log.debug("mirConditionalBranch: {} offset={}", .{ inst, offset });
317317
318 try emit.writeInstruction(318 try emit.writeInstruction(
...@@ -321,7 +321,7 @@ fn mirConditionalBranch(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -321,7 +321,7 @@ fn mirConditionalBranch(emit: *Emit, inst: Mir.Inst.Index) !void {
321 branch_predict_reg.annul,321 branch_predict_reg.annul,
322 branch_predict_reg.pt,322 branch_predict_reg.pt,
323 branch_predict_reg.rs1,323 branch_predict_reg.rs1,
324 @intCast(i18, offset),324 @as(i18, @intCast(offset)),
325 ),325 ),
326 );326 );
327 },327 },
...@@ -437,9 +437,9 @@ fn mirShift(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -437,9 +437,9 @@ fn mirShift(emit: *Emit, inst: Mir.Inst.Index) !void {
437 if (data.is_imm) {437 if (data.is_imm) {
438 const imm = data.rs2_or_imm.imm;438 const imm = data.rs2_or_imm.imm;
439 switch (tag) {439 switch (tag) {
440 .sll => try emit.writeInstruction(Instruction.sll(u5, rs1, @truncate(u5, imm), rd)),440 .sll => try emit.writeInstruction(Instruction.sll(u5, rs1, @as(u5, @truncate(imm)), rd)),
441 .srl => try emit.writeInstruction(Instruction.srl(u5, rs1, @truncate(u5, imm), rd)),441 .srl => try emit.writeInstruction(Instruction.srl(u5, rs1, @as(u5, @truncate(imm)), rd)),
442 .sra => try emit.writeInstruction(Instruction.sra(u5, rs1, @truncate(u5, imm), rd)),442 .sra => try emit.writeInstruction(Instruction.sra(u5, rs1, @as(u5, @truncate(imm)), rd)),
443 .sllx => try emit.writeInstruction(Instruction.sllx(u6, rs1, imm, rd)),443 .sllx => try emit.writeInstruction(Instruction.sllx(u6, rs1, imm, rd)),
444 .srlx => try emit.writeInstruction(Instruction.srlx(u6, rs1, imm, rd)),444 .srlx => try emit.writeInstruction(Instruction.srlx(u6, rs1, imm, rd)),
445 .srax => try emit.writeInstruction(Instruction.srax(u6, rs1, imm, rd)),445 .srax => try emit.writeInstruction(Instruction.srax(u6, rs1, imm, rd)),
...@@ -495,7 +495,7 @@ fn branchTarget(emit: *Emit, inst: Mir.Inst.Index) Mir.Inst.Index {...@@ -495,7 +495,7 @@ fn branchTarget(emit: *Emit, inst: Mir.Inst.Index) Mir.Inst.Index {
495}495}
496496
497fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) !void {497fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) !void {
498 const delta_line = @intCast(i32, line) - @intCast(i32, emit.prev_di_line);498 const delta_line = @as(i32, @intCast(line)) - @as(i32, @intCast(emit.prev_di_line));
499 const delta_pc: usize = emit.code.items.len - emit.prev_di_pc;499 const delta_pc: usize = emit.code.items.len - emit.prev_di_pc;
500 switch (emit.debug_output) {500 switch (emit.debug_output) {
501 .dwarf => |dbg_out| {501 .dwarf => |dbg_out| {
...@@ -547,7 +547,7 @@ fn lowerBranches(emit: *Emit) !void {...@@ -547,7 +547,7 @@ fn lowerBranches(emit: *Emit) !void {
547 // TODO optimization opportunity: do this in codegen while547 // TODO optimization opportunity: do this in codegen while
548 // generating MIR548 // generating MIR
549 for (mir_tags, 0..) |tag, index| {549 for (mir_tags, 0..) |tag, index| {
550 const inst = @intCast(u32, index);550 const inst = @as(u32, @intCast(index));
551 if (isBranch(tag)) {551 if (isBranch(tag)) {
552 const target_inst = emit.branchTarget(inst);552 const target_inst = emit.branchTarget(inst);
553553
...@@ -592,7 +592,7 @@ fn lowerBranches(emit: *Emit) !void {...@@ -592,7 +592,7 @@ fn lowerBranches(emit: *Emit) !void {
592 var current_code_offset: usize = 0;592 var current_code_offset: usize = 0;
593593
594 for (mir_tags, 0..) |tag, index| {594 for (mir_tags, 0..) |tag, index| {
595 const inst = @intCast(u32, index);595 const inst = @as(u32, @intCast(index));
596596
597 // If this instruction contained in the code offset597 // If this instruction contained in the code offset
598 // mapping (when it is a target of a branch or if it is a598 // mapping (when it is a target of a branch or if it is a
...@@ -607,7 +607,7 @@ fn lowerBranches(emit: *Emit) !void {...@@ -607,7 +607,7 @@ fn lowerBranches(emit: *Emit) !void {
607 const target_inst = emit.branchTarget(inst);607 const target_inst = emit.branchTarget(inst);
608 if (target_inst < inst) {608 if (target_inst < inst) {
609 const target_offset = emit.code_offset_mapping.get(target_inst).?;609 const target_offset = emit.code_offset_mapping.get(target_inst).?;
610 const offset = @intCast(i64, target_offset) - @intCast(i64, current_code_offset);610 const offset = @as(i64, @intCast(target_offset)) - @as(i64, @intCast(current_code_offset));
611 const branch_type = emit.branch_types.getPtr(inst).?;611 const branch_type = emit.branch_types.getPtr(inst).?;
612 const optimal_branch_type = try emit.optimalBranchType(tag, offset);612 const optimal_branch_type = try emit.optimalBranchType(tag, offset);
613 if (branch_type.* != optimal_branch_type) {613 if (branch_type.* != optimal_branch_type) {
...@@ -626,7 +626,7 @@ fn lowerBranches(emit: *Emit) !void {...@@ -626,7 +626,7 @@ fn lowerBranches(emit: *Emit) !void {
626 for (origin_list.items) |forward_branch_inst| {626 for (origin_list.items) |forward_branch_inst| {
627 const branch_tag = emit.mir.instructions.items(.tag)[forward_branch_inst];627 const branch_tag = emit.mir.instructions.items(.tag)[forward_branch_inst];
628 const forward_branch_inst_offset = emit.code_offset_mapping.get(forward_branch_inst).?;628 const forward_branch_inst_offset = emit.code_offset_mapping.get(forward_branch_inst).?;
629 const offset = @intCast(i64, current_code_offset) - @intCast(i64, forward_branch_inst_offset);629 const offset = @as(i64, @intCast(current_code_offset)) - @as(i64, @intCast(forward_branch_inst_offset));
630 const branch_type = emit.branch_types.getPtr(forward_branch_inst).?;630 const branch_type = emit.branch_types.getPtr(forward_branch_inst).?;
631 const optimal_branch_type = try emit.optimalBranchType(branch_tag, offset);631 const optimal_branch_type = try emit.optimalBranchType(branch_tag, offset);
632 if (branch_type.* != optimal_branch_type) {632 if (branch_type.* != optimal_branch_type) {
src/arch/sparc64/Mir.zig+1-1
...@@ -379,7 +379,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end...@@ -379,7 +379,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end
379 inline for (fields) |field| {379 inline for (fields) |field| {
380 @field(result, field.name) = switch (field.type) {380 @field(result, field.name) = switch (field.type) {
381 u32 => mir.extra[i],381 u32 => mir.extra[i],
382 i32 => @bitCast(i32, mir.extra[i]),382 i32 => @as(i32, @bitCast(mir.extra[i])),
383 else => @compileError("bad field type"),383 else => @compileError("bad field type"),
384 };384 };
385 i += 1;385 i += 1;
src/arch/sparc64/bits.zig+40-40
...@@ -16,7 +16,7 @@ pub const Register = enum(u6) {...@@ -16,7 +16,7 @@ pub const Register = enum(u6) {
16 // zig fmt: on16 // zig fmt: on
1717
18 pub fn id(self: Register) u5 {18 pub fn id(self: Register) u5 {
19 return @truncate(u5, @intFromEnum(self));19 return @as(u5, @truncate(@intFromEnum(self)));
20 }20 }
2121
22 pub fn enc(self: Register) u5 {22 pub fn enc(self: Register) u5 {
...@@ -96,9 +96,9 @@ pub const FloatingPointRegister = enum(u7) {...@@ -96,9 +96,9 @@ pub const FloatingPointRegister = enum(u7) {
9696
97 pub fn id(self: FloatingPointRegister) u6 {97 pub fn id(self: FloatingPointRegister) u6 {
98 return switch (self.size()) {98 return switch (self.size()) {
99 32 => @truncate(u6, @intFromEnum(self)),99 32 => @as(u6, @truncate(@intFromEnum(self))),
100 64 => @truncate(u6, (@intFromEnum(self) - 32) * 2),100 64 => @as(u6, @truncate((@intFromEnum(self) - 32) * 2)),
101 128 => @truncate(u6, (@intFromEnum(self) - 64) * 4),101 128 => @as(u6, @truncate((@intFromEnum(self) - 64) * 4)),
102 else => unreachable,102 else => unreachable,
103 };103 };
104 }104 }
...@@ -109,7 +109,7 @@ pub const FloatingPointRegister = enum(u7) {...@@ -109,7 +109,7 @@ pub const FloatingPointRegister = enum(u7) {
109 // (See section 5.1.4.1 of SPARCv9 ISA specification)109 // (See section 5.1.4.1 of SPARCv9 ISA specification)
110110
111 const reg_id = self.id();111 const reg_id = self.id();
112 return @truncate(u5, reg_id | (reg_id >> 5));112 return @as(u5, @truncate(reg_id | (reg_id >> 5)));
113 }113 }
114114
115 /// Returns the bit-width of the register.115 /// Returns the bit-width of the register.
...@@ -752,13 +752,13 @@ pub const Instruction = union(enum) {...@@ -752,13 +752,13 @@ pub const Instruction = union(enum) {
752 // See section 6.2 of the SPARCv9 ISA manual.752 // See section 6.2 of the SPARCv9 ISA manual.
753753
754 fn format1(disp: i32) Instruction {754 fn format1(disp: i32) Instruction {
755 const udisp = @bitCast(u32, disp);755 const udisp = @as(u32, @bitCast(disp));
756756
757 // In SPARC, branch target needs to be aligned to 4 bytes.757 // In SPARC, branch target needs to be aligned to 4 bytes.
758 assert(udisp % 4 == 0);758 assert(udisp % 4 == 0);
759759
760 // Discard the last two bits since those are implicitly zero.760 // Discard the last two bits since those are implicitly zero.
761 const udisp_truncated = @truncate(u30, udisp >> 2);761 const udisp_truncated = @as(u30, @truncate(udisp >> 2));
762 return Instruction{762 return Instruction{
763 .format_1 = .{763 .format_1 = .{
764 .disp30 = udisp_truncated,764 .disp30 = udisp_truncated,
...@@ -777,13 +777,13 @@ pub const Instruction = union(enum) {...@@ -777,13 +777,13 @@ pub const Instruction = union(enum) {
777 }777 }
778778
779 fn format2b(op2: u3, cond: Condition, annul: bool, disp: i24) Instruction {779 fn format2b(op2: u3, cond: Condition, annul: bool, disp: i24) Instruction {
780 const udisp = @bitCast(u24, disp);780 const udisp = @as(u24, @bitCast(disp));
781781
782 // In SPARC, branch target needs to be aligned to 4 bytes.782 // In SPARC, branch target needs to be aligned to 4 bytes.
783 assert(udisp % 4 == 0);783 assert(udisp % 4 == 0);
784784
785 // Discard the last two bits since those are implicitly zero.785 // Discard the last two bits since those are implicitly zero.
786 const udisp_truncated = @truncate(u22, udisp >> 2);786 const udisp_truncated = @as(u22, @truncate(udisp >> 2));
787 return Instruction{787 return Instruction{
788 .format_2b = .{788 .format_2b = .{
789 .a = @intFromBool(annul),789 .a = @intFromBool(annul),
...@@ -795,16 +795,16 @@ pub const Instruction = union(enum) {...@@ -795,16 +795,16 @@ pub const Instruction = union(enum) {
795 }795 }
796796
797 fn format2c(op2: u3, cond: Condition, annul: bool, pt: bool, ccr: CCR, disp: i21) Instruction {797 fn format2c(op2: u3, cond: Condition, annul: bool, pt: bool, ccr: CCR, disp: i21) Instruction {
798 const udisp = @bitCast(u21, disp);798 const udisp = @as(u21, @bitCast(disp));
799799
800 // In SPARC, branch target needs to be aligned to 4 bytes.800 // In SPARC, branch target needs to be aligned to 4 bytes.
801 assert(udisp % 4 == 0);801 assert(udisp % 4 == 0);
802802
803 // Discard the last two bits since those are implicitly zero.803 // Discard the last two bits since those are implicitly zero.
804 const udisp_truncated = @truncate(u19, udisp >> 2);804 const udisp_truncated = @as(u19, @truncate(udisp >> 2));
805805
806 const ccr_cc1 = @truncate(u1, @intFromEnum(ccr) >> 1);806 const ccr_cc1 = @as(u1, @truncate(@intFromEnum(ccr) >> 1));
807 const ccr_cc0 = @truncate(u1, @intFromEnum(ccr));807 const ccr_cc0 = @as(u1, @truncate(@intFromEnum(ccr)));
808 return Instruction{808 return Instruction{
809 .format_2c = .{809 .format_2c = .{
810 .a = @intFromBool(annul),810 .a = @intFromBool(annul),
...@@ -819,16 +819,16 @@ pub const Instruction = union(enum) {...@@ -819,16 +819,16 @@ pub const Instruction = union(enum) {
819 }819 }
820820
821 fn format2d(op2: u3, rcond: RCondition, annul: bool, pt: bool, rs1: Register, disp: i18) Instruction {821 fn format2d(op2: u3, rcond: RCondition, annul: bool, pt: bool, rs1: Register, disp: i18) Instruction {
822 const udisp = @bitCast(u18, disp);822 const udisp = @as(u18, @bitCast(disp));
823823
824 // In SPARC, branch target needs to be aligned to 4 bytes.824 // In SPARC, branch target needs to be aligned to 4 bytes.
825 assert(udisp % 4 == 0);825 assert(udisp % 4 == 0);
826826
827 // Discard the last two bits since those are implicitly zero,827 // Discard the last two bits since those are implicitly zero,
828 // and split it into low and high parts.828 // and split it into low and high parts.
829 const udisp_truncated = @truncate(u16, udisp >> 2);829 const udisp_truncated = @as(u16, @truncate(udisp >> 2));
830 const udisp_hi = @truncate(u2, (udisp_truncated & 0b1100_0000_0000_0000) >> 14);830 const udisp_hi = @as(u2, @truncate((udisp_truncated & 0b1100_0000_0000_0000) >> 14));
831 const udisp_lo = @truncate(u14, udisp_truncated & 0b0011_1111_1111_1111);831 const udisp_lo = @as(u14, @truncate(udisp_truncated & 0b0011_1111_1111_1111));
832 return Instruction{832 return Instruction{
833 .format_2d = .{833 .format_2d = .{
834 .a = @intFromBool(annul),834 .a = @intFromBool(annul),
...@@ -860,7 +860,7 @@ pub const Instruction = union(enum) {...@@ -860,7 +860,7 @@ pub const Instruction = union(enum) {
860 .rd = rd.enc(),860 .rd = rd.enc(),
861 .op3 = op3,861 .op3 = op3,
862 .rs1 = rs1.enc(),862 .rs1 = rs1.enc(),
863 .simm13 = @bitCast(u13, imm),863 .simm13 = @as(u13, @bitCast(imm)),
864 },864 },
865 };865 };
866 }866 }
...@@ -880,7 +880,7 @@ pub const Instruction = union(enum) {...@@ -880,7 +880,7 @@ pub const Instruction = union(enum) {
880 .op = op,880 .op = op,
881 .op3 = op3,881 .op3 = op3,
882 .rs1 = rs1.enc(),882 .rs1 = rs1.enc(),
883 .simm13 = @bitCast(u13, imm),883 .simm13 = @as(u13, @bitCast(imm)),
884 },884 },
885 };885 };
886 }886 }
...@@ -904,7 +904,7 @@ pub const Instruction = union(enum) {...@@ -904,7 +904,7 @@ pub const Instruction = union(enum) {
904 .op3 = op3,904 .op3 = op3,
905 .rs1 = rs1.enc(),905 .rs1 = rs1.enc(),
906 .rcond = @intFromEnum(rcond),906 .rcond = @intFromEnum(rcond),
907 .simm10 = @bitCast(u10, imm),907 .simm10 = @as(u10, @bitCast(imm)),
908 },908 },
909 };909 };
910 }910 }
...@@ -922,8 +922,8 @@ pub const Instruction = union(enum) {...@@ -922,8 +922,8 @@ pub const Instruction = union(enum) {
922 fn format3h(cmask: MemCompletionConstraint, mmask: MemOrderingConstraint) Instruction {922 fn format3h(cmask: MemCompletionConstraint, mmask: MemOrderingConstraint) Instruction {
923 return Instruction{923 return Instruction{
924 .format_3h = .{924 .format_3h = .{
925 .cmask = @bitCast(u3, cmask),925 .cmask = @as(u3, @bitCast(cmask)),
926 .mmask = @bitCast(u4, mmask),926 .mmask = @as(u4, @bitCast(mmask)),
927 },927 },
928 };928 };
929 }929 }
...@@ -995,8 +995,8 @@ pub const Instruction = union(enum) {...@@ -995,8 +995,8 @@ pub const Instruction = union(enum) {
995 };995 };
996 }996 }
997 fn format3o(op: u2, op3: u6, opf: u9, ccr: CCR, rs1: Register, rs2: Register) Instruction {997 fn format3o(op: u2, op3: u6, opf: u9, ccr: CCR, rs1: Register, rs2: Register) Instruction {
998 const ccr_cc1 = @truncate(u1, @intFromEnum(ccr) >> 1);998 const ccr_cc1 = @as(u1, @truncate(@intFromEnum(ccr) >> 1));
999 const ccr_cc0 = @truncate(u1, @intFromEnum(ccr));999 const ccr_cc0 = @as(u1, @truncate(@intFromEnum(ccr)));
1000 return Instruction{1000 return Instruction{
1001 .format_3o = .{1001 .format_3o = .{
1002 .op = op,1002 .op = op,
...@@ -1051,8 +1051,8 @@ pub const Instruction = union(enum) {...@@ -1051,8 +1051,8 @@ pub const Instruction = union(enum) {
1051 }1051 }
10521052
1053 fn format4a(op3: u6, ccr: CCR, rs1: Register, rs2: Register, rd: Register) Instruction {1053 fn format4a(op3: u6, ccr: CCR, rs1: Register, rs2: Register, rd: Register) Instruction {
1054 const ccr_cc1 = @truncate(u1, @intFromEnum(ccr) >> 1);1054 const ccr_cc1 = @as(u1, @truncate(@intFromEnum(ccr) >> 1));
1055 const ccr_cc0 = @truncate(u1, @intFromEnum(ccr));1055 const ccr_cc0 = @as(u1, @truncate(@intFromEnum(ccr)));
1056 return Instruction{1056 return Instruction{
1057 .format_4a = .{1057 .format_4a = .{
1058 .rd = rd.enc(),1058 .rd = rd.enc(),
...@@ -1066,8 +1066,8 @@ pub const Instruction = union(enum) {...@@ -1066,8 +1066,8 @@ pub const Instruction = union(enum) {
1066 }1066 }
10671067
1068 fn format4b(op3: u6, ccr: CCR, rs1: Register, imm: i11, rd: Register) Instruction {1068 fn format4b(op3: u6, ccr: CCR, rs1: Register, imm: i11, rd: Register) Instruction {
1069 const ccr_cc1 = @truncate(u1, @intFromEnum(ccr) >> 1);1069 const ccr_cc1 = @as(u1, @truncate(@intFromEnum(ccr) >> 1));
1070 const ccr_cc0 = @truncate(u1, @intFromEnum(ccr));1070 const ccr_cc0 = @as(u1, @truncate(@intFromEnum(ccr)));
1071 return Instruction{1071 return Instruction{
1072 .format_4b = .{1072 .format_4b = .{
1073 .rd = rd.enc(),1073 .rd = rd.enc(),
...@@ -1075,15 +1075,15 @@ pub const Instruction = union(enum) {...@@ -1075,15 +1075,15 @@ pub const Instruction = union(enum) {
1075 .rs1 = rs1.enc(),1075 .rs1 = rs1.enc(),
1076 .cc1 = ccr_cc1,1076 .cc1 = ccr_cc1,
1077 .cc0 = ccr_cc0,1077 .cc0 = ccr_cc0,
1078 .simm11 = @bitCast(u11, imm),1078 .simm11 = @as(u11, @bitCast(imm)),
1079 },1079 },
1080 };1080 };
1081 }1081 }
10821082
1083 fn format4c(op3: u6, cond: Condition, ccr: CCR, rs2: Register, rd: Register) Instruction {1083 fn format4c(op3: u6, cond: Condition, ccr: CCR, rs2: Register, rd: Register) Instruction {
1084 const ccr_cc2 = @truncate(u1, @intFromEnum(ccr) >> 2);1084 const ccr_cc2 = @as(u1, @truncate(@intFromEnum(ccr) >> 2));
1085 const ccr_cc1 = @truncate(u1, @intFromEnum(ccr) >> 1);1085 const ccr_cc1 = @as(u1, @truncate(@intFromEnum(ccr) >> 1));
1086 const ccr_cc0 = @truncate(u1, @intFromEnum(ccr));1086 const ccr_cc0 = @as(u1, @truncate(@intFromEnum(ccr)));
1087 return Instruction{1087 return Instruction{
1088 .format_4c = .{1088 .format_4c = .{
1089 .rd = rd.enc(),1089 .rd = rd.enc(),
...@@ -1098,9 +1098,9 @@ pub const Instruction = union(enum) {...@@ -1098,9 +1098,9 @@ pub const Instruction = union(enum) {
1098 }1098 }
10991099
1100 fn format4d(op3: u6, cond: Condition, ccr: CCR, imm: i11, rd: Register) Instruction {1100 fn format4d(op3: u6, cond: Condition, ccr: CCR, imm: i11, rd: Register) Instruction {
1101 const ccr_cc2 = @truncate(u1, @intFromEnum(ccr) >> 2);1101 const ccr_cc2 = @as(u1, @truncate(@intFromEnum(ccr) >> 2));
1102 const ccr_cc1 = @truncate(u1, @intFromEnum(ccr) >> 1);1102 const ccr_cc1 = @as(u1, @truncate(@intFromEnum(ccr) >> 1));
1103 const ccr_cc0 = @truncate(u1, @intFromEnum(ccr));1103 const ccr_cc0 = @as(u1, @truncate(@intFromEnum(ccr)));
1104 return Instruction{1104 return Instruction{
1105 .format_4d = .{1105 .format_4d = .{
1106 .rd = rd.enc(),1106 .rd = rd.enc(),
...@@ -1109,14 +1109,14 @@ pub const Instruction = union(enum) {...@@ -1109,14 +1109,14 @@ pub const Instruction = union(enum) {
1109 .cond = cond.enc(),1109 .cond = cond.enc(),
1110 .cc1 = ccr_cc1,1110 .cc1 = ccr_cc1,
1111 .cc0 = ccr_cc0,1111 .cc0 = ccr_cc0,
1112 .simm11 = @bitCast(u11, imm),1112 .simm11 = @as(u11, @bitCast(imm)),
1113 },1113 },
1114 };1114 };
1115 }1115 }
11161116
1117 fn format4e(op3: u6, ccr: CCR, rs1: Register, rd: Register, sw_trap: u7) Instruction {1117 fn format4e(op3: u6, ccr: CCR, rs1: Register, rd: Register, sw_trap: u7) Instruction {
1118 const ccr_cc1 = @truncate(u1, @intFromEnum(ccr) >> 1);1118 const ccr_cc1 = @as(u1, @truncate(@intFromEnum(ccr) >> 1));
1119 const ccr_cc0 = @truncate(u1, @intFromEnum(ccr));1119 const ccr_cc0 = @as(u1, @truncate(@intFromEnum(ccr)));
1120 return Instruction{1120 return Instruction{
1121 .format_4e = .{1121 .format_4e = .{
1122 .rd = rd.enc(),1122 .rd = rd.enc(),
...@@ -1468,8 +1468,8 @@ pub const Instruction = union(enum) {...@@ -1468,8 +1468,8 @@ pub const Instruction = union(enum) {
1468 pub fn trap(comptime s2: type, cond: ICondition, ccr: CCR, rs1: Register, rs2: s2) Instruction {1468 pub fn trap(comptime s2: type, cond: ICondition, ccr: CCR, rs1: Register, rs2: s2) Instruction {
1469 // Tcc instructions abuse the rd field to store the conditionals.1469 // Tcc instructions abuse the rd field to store the conditionals.
1470 return switch (s2) {1470 return switch (s2) {
1471 Register => format4a(0b11_1010, ccr, rs1, rs2, @enumFromInt(Register, @intFromEnum(cond))),1471 Register => format4a(0b11_1010, ccr, rs1, rs2, @as(Register, @enumFromInt(@intFromEnum(cond)))),
1472 u7 => format4e(0b11_1010, ccr, rs1, @enumFromInt(Register, @intFromEnum(cond)), rs2),1472 u7 => format4e(0b11_1010, ccr, rs1, @as(Register, @enumFromInt(@intFromEnum(cond))), rs2),
1473 else => unreachable,1473 else => unreachable,
1474 };1474 };
1475 }1475 }
src/arch/wasm/CodeGen.zig+164-164
...@@ -120,7 +120,7 @@ const WValue = union(enum) {...@@ -120,7 +120,7 @@ const WValue = union(enum) {
120 if (local_value < reserved + 2) return; // reserved locals may never be re-used. Also accounts for 2 stack locals.120 if (local_value < reserved + 2) return; // reserved locals may never be re-used. Also accounts for 2 stack locals.
121121
122 const index = local_value - reserved;122 const index = local_value - reserved;
123 const valtype = @enumFromInt(wasm.Valtype, gen.locals.items[index]);123 const valtype = @as(wasm.Valtype, @enumFromInt(gen.locals.items[index]));
124 switch (valtype) {124 switch (valtype) {
125 .i32 => gen.free_locals_i32.append(gen.gpa, local_value) catch return, // It's ok to fail any of those, a new local can be allocated instead125 .i32 => gen.free_locals_i32.append(gen.gpa, local_value) catch return, // It's ok to fail any of those, a new local can be allocated instead
126 .i64 => gen.free_locals_i64.append(gen.gpa, local_value) catch return,126 .i64 => gen.free_locals_i64.append(gen.gpa, local_value) catch return,
...@@ -817,7 +817,7 @@ fn finishAir(func: *CodeGen, inst: Air.Inst.Index, result: WValue, operands: []c...@@ -817,7 +817,7 @@ fn finishAir(func: *CodeGen, inst: Air.Inst.Index, result: WValue, operands: []c
817 assert(operands.len <= Liveness.bpi - 1);817 assert(operands.len <= Liveness.bpi - 1);
818 var tomb_bits = func.liveness.getTombBits(inst);818 var tomb_bits = func.liveness.getTombBits(inst);
819 for (operands) |operand| {819 for (operands) |operand| {
820 const dies = @truncate(u1, tomb_bits) != 0;820 const dies = @as(u1, @truncate(tomb_bits)) != 0;
821 tomb_bits >>= 1;821 tomb_bits >>= 1;
822 if (!dies) continue;822 if (!dies) continue;
823 processDeath(func, operand);823 processDeath(func, operand);
...@@ -910,7 +910,7 @@ fn addTag(func: *CodeGen, tag: Mir.Inst.Tag) error{OutOfMemory}!void {...@@ -910,7 +910,7 @@ fn addTag(func: *CodeGen, tag: Mir.Inst.Tag) error{OutOfMemory}!void {
910}910}
911911
912fn addExtended(func: *CodeGen, opcode: wasm.MiscOpcode) error{OutOfMemory}!void {912fn addExtended(func: *CodeGen, opcode: wasm.MiscOpcode) error{OutOfMemory}!void {
913 const extra_index = @intCast(u32, func.mir_extra.items.len);913 const extra_index = @as(u32, @intCast(func.mir_extra.items.len));
914 try func.mir_extra.append(func.gpa, @intFromEnum(opcode));914 try func.mir_extra.append(func.gpa, @intFromEnum(opcode));
915 try func.addInst(.{ .tag = .misc_prefix, .data = .{ .payload = extra_index } });915 try func.addInst(.{ .tag = .misc_prefix, .data = .{ .payload = extra_index } });
916}916}
...@@ -934,11 +934,11 @@ fn addImm64(func: *CodeGen, imm: u64) error{OutOfMemory}!void {...@@ -934,11 +934,11 @@ fn addImm64(func: *CodeGen, imm: u64) error{OutOfMemory}!void {
934/// Accepts the index into the list of 128bit-immediates934/// Accepts the index into the list of 128bit-immediates
935fn addImm128(func: *CodeGen, index: u32) error{OutOfMemory}!void {935fn addImm128(func: *CodeGen, index: u32) error{OutOfMemory}!void {
936 const simd_values = func.simd_immediates.items[index];936 const simd_values = func.simd_immediates.items[index];
937 const extra_index = @intCast(u32, func.mir_extra.items.len);937 const extra_index = @as(u32, @intCast(func.mir_extra.items.len));
938 // tag + 128bit value938 // tag + 128bit value
939 try func.mir_extra.ensureUnusedCapacity(func.gpa, 5);939 try func.mir_extra.ensureUnusedCapacity(func.gpa, 5);
940 func.mir_extra.appendAssumeCapacity(std.wasm.simdOpcode(.v128_const));940 func.mir_extra.appendAssumeCapacity(std.wasm.simdOpcode(.v128_const));
941 func.mir_extra.appendSliceAssumeCapacity(@alignCast(4, mem.bytesAsSlice(u32, &simd_values)));941 func.mir_extra.appendSliceAssumeCapacity(@alignCast(mem.bytesAsSlice(u32, &simd_values)));
942 try func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });942 try func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });
943}943}
944944
...@@ -979,7 +979,7 @@ fn addExtra(func: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {...@@ -979,7 +979,7 @@ fn addExtra(func: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {
979/// Returns the index into `mir_extra`979/// Returns the index into `mir_extra`
980fn addExtraAssumeCapacity(func: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {980fn addExtraAssumeCapacity(func: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {
981 const fields = std.meta.fields(@TypeOf(extra));981 const fields = std.meta.fields(@TypeOf(extra));
982 const result = @intCast(u32, func.mir_extra.items.len);982 const result = @as(u32, @intCast(func.mir_extra.items.len));
983 inline for (fields) |field| {983 inline for (fields) |field| {
984 func.mir_extra.appendAssumeCapacity(switch (field.type) {984 func.mir_extra.appendAssumeCapacity(switch (field.type) {
985 u32 => @field(extra, field.name),985 u32 => @field(extra, field.name),
...@@ -1020,7 +1020,7 @@ fn typeToValtype(ty: Type, mod: *Module) wasm.Valtype {...@@ -1020,7 +1020,7 @@ fn typeToValtype(ty: Type, mod: *Module) wasm.Valtype {
1020 },1020 },
1021 .Union => switch (ty.containerLayout(mod)) {1021 .Union => switch (ty.containerLayout(mod)) {
1022 .Packed => {1022 .Packed => {
1023 const int_ty = mod.intType(.unsigned, @intCast(u16, ty.bitSize(mod))) catch @panic("out of memory");1023 const int_ty = mod.intType(.unsigned, @as(u16, @intCast(ty.bitSize(mod)))) catch @panic("out of memory");
1024 return typeToValtype(int_ty, mod);1024 return typeToValtype(int_ty, mod);
1025 },1025 },
1026 else => wasm.Valtype.i32,1026 else => wasm.Valtype.i32,
...@@ -1050,7 +1050,7 @@ fn emitWValue(func: *CodeGen, value: WValue) InnerError!void {...@@ -1050,7 +1050,7 @@ fn emitWValue(func: *CodeGen, value: WValue) InnerError!void {
1050 .dead => unreachable, // reference to free'd `WValue` (missing reuseOperand?)1050 .dead => unreachable, // reference to free'd `WValue` (missing reuseOperand?)
1051 .none, .stack => {}, // no-op1051 .none, .stack => {}, // no-op
1052 .local => |idx| try func.addLabel(.local_get, idx.value),1052 .local => |idx| try func.addLabel(.local_get, idx.value),
1053 .imm32 => |val| try func.addImm32(@bitCast(i32, val)),1053 .imm32 => |val| try func.addImm32(@as(i32, @bitCast(val))),
1054 .imm64 => |val| try func.addImm64(val),1054 .imm64 => |val| try func.addImm64(val),
1055 .imm128 => |val| try func.addImm128(val),1055 .imm128 => |val| try func.addImm128(val),
1056 .float32 => |val| try func.addInst(.{ .tag = .f32_const, .data = .{ .float32 = val } }),1056 .float32 => |val| try func.addInst(.{ .tag = .f32_const, .data = .{ .float32 = val } }),
...@@ -1264,7 +1264,7 @@ fn genFunc(func: *CodeGen) InnerError!void {...@@ -1264,7 +1264,7 @@ fn genFunc(func: *CodeGen) InnerError!void {
1264 // In case we have a return value, but the last instruction is a noreturn (such as a while loop)1264 // In case we have a return value, but the last instruction is a noreturn (such as a while loop)
1265 // we emit an unreachable instruction to tell the stack validator that part will never be reached.1265 // we emit an unreachable instruction to tell the stack validator that part will never be reached.
1266 if (func_type.returns.len != 0 and func.air.instructions.len > 0) {1266 if (func_type.returns.len != 0 and func.air.instructions.len > 0) {
1267 const inst = @intCast(u32, func.air.instructions.len - 1);1267 const inst = @as(u32, @intCast(func.air.instructions.len - 1));
1268 const last_inst_ty = func.typeOfIndex(inst);1268 const last_inst_ty = func.typeOfIndex(inst);
1269 if (!last_inst_ty.hasRuntimeBitsIgnoreComptime(mod) or last_inst_ty.isNoReturn(mod)) {1269 if (!last_inst_ty.hasRuntimeBitsIgnoreComptime(mod) or last_inst_ty.isNoReturn(mod)) {
1270 try func.addTag(.@"unreachable");1270 try func.addTag(.@"unreachable");
...@@ -1287,11 +1287,11 @@ fn genFunc(func: *CodeGen) InnerError!void {...@@ -1287,11 +1287,11 @@ fn genFunc(func: *CodeGen) InnerError!void {
1287 try prologue.append(.{ .tag = .local_tee, .data = .{ .label = func.initial_stack_value.local.value } });1287 try prologue.append(.{ .tag = .local_tee, .data = .{ .label = func.initial_stack_value.local.value } });
1288 // get the total stack size1288 // get the total stack size
1289 const aligned_stack = std.mem.alignForward(u32, func.stack_size, func.stack_alignment);1289 const aligned_stack = std.mem.alignForward(u32, func.stack_size, func.stack_alignment);
1290 try prologue.append(.{ .tag = .i32_const, .data = .{ .imm32 = @intCast(i32, aligned_stack) } });1290 try prologue.append(.{ .tag = .i32_const, .data = .{ .imm32 = @as(i32, @intCast(aligned_stack)) } });
1291 // substract it from the current stack pointer1291 // substract it from the current stack pointer
1292 try prologue.append(.{ .tag = .i32_sub, .data = .{ .tag = {} } });1292 try prologue.append(.{ .tag = .i32_sub, .data = .{ .tag = {} } });
1293 // Get negative stack aligment1293 // Get negative stack aligment
1294 try prologue.append(.{ .tag = .i32_const, .data = .{ .imm32 = @intCast(i32, func.stack_alignment) * -1 } });1294 try prologue.append(.{ .tag = .i32_const, .data = .{ .imm32 = @as(i32, @intCast(func.stack_alignment)) * -1 } });
1295 // Bitwise-and the value to get the new stack pointer to ensure the pointers are aligned with the abi alignment1295 // Bitwise-and the value to get the new stack pointer to ensure the pointers are aligned with the abi alignment
1296 try prologue.append(.{ .tag = .i32_and, .data = .{ .tag = {} } });1296 try prologue.append(.{ .tag = .i32_and, .data = .{ .tag = {} } });
1297 // store the current stack pointer as the bottom, which will be used to calculate all stack pointer offsets1297 // store the current stack pointer as the bottom, which will be used to calculate all stack pointer offsets
...@@ -1432,7 +1432,7 @@ fn lowerArg(func: *CodeGen, cc: std.builtin.CallingConvention, ty: Type, value:...@@ -1432,7 +1432,7 @@ fn lowerArg(func: *CodeGen, cc: std.builtin.CallingConvention, ty: Type, value:
1432 if (value != .imm32 and value != .imm64) {1432 if (value != .imm32 and value != .imm64) {
1433 const opcode = buildOpcode(.{1433 const opcode = buildOpcode(.{
1434 .op = .load,1434 .op = .load,
1435 .width = @intCast(u8, abi_size),1435 .width = @as(u8, @intCast(abi_size)),
1436 .signedness = if (scalar_type.isSignedInt(mod)) .signed else .unsigned,1436 .signedness = if (scalar_type.isSignedInt(mod)) .signed else .unsigned,
1437 .valtype1 = typeToValtype(scalar_type, mod),1437 .valtype1 = typeToValtype(scalar_type, mod),
1438 });1438 });
...@@ -1468,7 +1468,7 @@ fn lowerToStack(func: *CodeGen, value: WValue) !void {...@@ -1468,7 +1468,7 @@ fn lowerToStack(func: *CodeGen, value: WValue) !void {
1468 if (offset.value > 0) {1468 if (offset.value > 0) {
1469 switch (func.arch()) {1469 switch (func.arch()) {
1470 .wasm32 => {1470 .wasm32 => {
1471 try func.addImm32(@bitCast(i32, offset.value));1471 try func.addImm32(@as(i32, @bitCast(offset.value)));
1472 try func.addTag(.i32_add);1472 try func.addTag(.i32_add);
1473 },1473 },
1474 .wasm64 => {1474 .wasm64 => {
...@@ -1815,7 +1815,7 @@ fn buildPointerOffset(func: *CodeGen, ptr_value: WValue, offset: u64, action: en...@@ -1815,7 +1815,7 @@ fn buildPointerOffset(func: *CodeGen, ptr_value: WValue, offset: u64, action: en
1815 if (offset + ptr_value.offset() > 0) {1815 if (offset + ptr_value.offset() > 0) {
1816 switch (func.arch()) {1816 switch (func.arch()) {
1817 .wasm32 => {1817 .wasm32 => {
1818 try func.addImm32(@bitCast(i32, @intCast(u32, offset + ptr_value.offset())));1818 try func.addImm32(@as(i32, @bitCast(@as(u32, @intCast(offset + ptr_value.offset())))));
1819 try func.addTag(.i32_add);1819 try func.addTag(.i32_add);
1820 },1820 },
1821 .wasm64 => {1821 .wasm64 => {
...@@ -2111,7 +2111,7 @@ fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2111,7 +2111,7 @@ fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2111 try func.emitWValue(operand);2111 try func.emitWValue(operand);
2112 const opcode = buildOpcode(.{2112 const opcode = buildOpcode(.{
2113 .op = .load,2113 .op = .load,
2114 .width = @intCast(u8, scalar_type.abiSize(mod) * 8),2114 .width = @as(u8, @intCast(scalar_type.abiSize(mod) * 8)),
2115 .signedness = if (scalar_type.isSignedInt(mod)) .signed else .unsigned,2115 .signedness = if (scalar_type.isSignedInt(mod)) .signed else .unsigned,
2116 .valtype1 = typeToValtype(scalar_type, mod),2116 .valtype1 = typeToValtype(scalar_type, mod),
2117 });2117 });
...@@ -2180,7 +2180,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -2180,7 +2180,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
2180 if (modifier == .always_tail) return func.fail("TODO implement tail calls for wasm", .{});2180 if (modifier == .always_tail) return func.fail("TODO implement tail calls for wasm", .{});
2181 const pl_op = func.air.instructions.items(.data)[inst].pl_op;2181 const pl_op = func.air.instructions.items(.data)[inst].pl_op;
2182 const extra = func.air.extraData(Air.Call, pl_op.payload);2182 const extra = func.air.extraData(Air.Call, pl_op.payload);
2183 const args = @ptrCast([]const Air.Inst.Ref, func.air.extra[extra.end..][0..extra.data.args_len]);2183 const args = @as([]const Air.Inst.Ref, @ptrCast(func.air.extra[extra.end..][0..extra.data.args_len]));
2184 const ty = func.typeOf(pl_op.operand);2184 const ty = func.typeOf(pl_op.operand);
21852185
2186 const mod = func.bin_file.base.options.module.?;2186 const mod = func.bin_file.base.options.module.?;
...@@ -2319,15 +2319,15 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void...@@ -2319,15 +2319,15 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
2319 return func.fail("TODO: airStore for pointers to bitfields with backing type larger than 64bits", .{});2319 return func.fail("TODO: airStore for pointers to bitfields with backing type larger than 64bits", .{});
2320 }2320 }
23212321
2322 var mask = @intCast(u64, (@as(u65, 1) << @intCast(u7, ty.bitSize(mod))) - 1);2322 var mask = @as(u64, @intCast((@as(u65, 1) << @as(u7, @intCast(ty.bitSize(mod)))) - 1));
2323 mask <<= @intCast(u6, ptr_info.packed_offset.bit_offset);2323 mask <<= @as(u6, @intCast(ptr_info.packed_offset.bit_offset));
2324 mask ^= ~@as(u64, 0);2324 mask ^= ~@as(u64, 0);
2325 const shift_val = if (ptr_info.packed_offset.host_size <= 4)2325 const shift_val = if (ptr_info.packed_offset.host_size <= 4)
2326 WValue{ .imm32 = ptr_info.packed_offset.bit_offset }2326 WValue{ .imm32 = ptr_info.packed_offset.bit_offset }
2327 else2327 else
2328 WValue{ .imm64 = ptr_info.packed_offset.bit_offset };2328 WValue{ .imm64 = ptr_info.packed_offset.bit_offset };
2329 const mask_val = if (ptr_info.packed_offset.host_size <= 4)2329 const mask_val = if (ptr_info.packed_offset.host_size <= 4)
2330 WValue{ .imm32 = @truncate(u32, mask) }2330 WValue{ .imm32 = @as(u32, @truncate(mask)) }
2331 else2331 else
2332 WValue{ .imm64 = mask };2332 WValue{ .imm64 = mask };
23332333
...@@ -2357,7 +2357,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE...@@ -2357,7 +2357,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
2357 return func.store(lhs, rhs, Type.anyerror, 0);2357 return func.store(lhs, rhs, Type.anyerror, 0);
2358 }2358 }
23592359
2360 const len = @intCast(u32, abi_size);2360 const len = @as(u32, @intCast(abi_size));
2361 return func.memcpy(lhs, rhs, .{ .imm32 = len });2361 return func.memcpy(lhs, rhs, .{ .imm32 = len });
2362 },2362 },
2363 .Optional => {2363 .Optional => {
...@@ -2372,23 +2372,23 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE...@@ -2372,23 +2372,23 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
2372 return func.store(lhs, rhs, Type.anyerror, 0);2372 return func.store(lhs, rhs, Type.anyerror, 0);
2373 }2373 }
23742374
2375 const len = @intCast(u32, abi_size);2375 const len = @as(u32, @intCast(abi_size));
2376 return func.memcpy(lhs, rhs, .{ .imm32 = len });2376 return func.memcpy(lhs, rhs, .{ .imm32 = len });
2377 },2377 },
2378 .Struct, .Array, .Union => if (isByRef(ty, mod)) {2378 .Struct, .Array, .Union => if (isByRef(ty, mod)) {
2379 const len = @intCast(u32, abi_size);2379 const len = @as(u32, @intCast(abi_size));
2380 return func.memcpy(lhs, rhs, .{ .imm32 = len });2380 return func.memcpy(lhs, rhs, .{ .imm32 = len });
2381 },2381 },
2382 .Vector => switch (determineSimdStoreStrategy(ty, mod)) {2382 .Vector => switch (determineSimdStoreStrategy(ty, mod)) {
2383 .unrolled => {2383 .unrolled => {
2384 const len = @intCast(u32, abi_size);2384 const len = @as(u32, @intCast(abi_size));
2385 return func.memcpy(lhs, rhs, .{ .imm32 = len });2385 return func.memcpy(lhs, rhs, .{ .imm32 = len });
2386 },2386 },
2387 .direct => {2387 .direct => {
2388 try func.emitWValue(lhs);2388 try func.emitWValue(lhs);
2389 try func.lowerToStack(rhs);2389 try func.lowerToStack(rhs);
2390 // TODO: Add helper functions for simd opcodes2390 // TODO: Add helper functions for simd opcodes
2391 const extra_index = @intCast(u32, func.mir_extra.items.len);2391 const extra_index = @as(u32, @intCast(func.mir_extra.items.len));
2392 // stores as := opcode, offset, alignment (opcode::memarg)2392 // stores as := opcode, offset, alignment (opcode::memarg)
2393 try func.mir_extra.appendSlice(func.gpa, &[_]u32{2393 try func.mir_extra.appendSlice(func.gpa, &[_]u32{
2394 std.wasm.simdOpcode(.v128_store),2394 std.wasm.simdOpcode(.v128_store),
...@@ -2423,7 +2423,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE...@@ -2423,7 +2423,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
2423 try func.store(.{ .stack = {} }, msb, Type.u64, 8 + lhs.offset());2423 try func.store(.{ .stack = {} }, msb, Type.u64, 8 + lhs.offset());
2424 return;2424 return;
2425 } else if (abi_size > 16) {2425 } else if (abi_size > 16) {
2426 try func.memcpy(lhs, rhs, .{ .imm32 = @intCast(u32, ty.abiSize(mod)) });2426 try func.memcpy(lhs, rhs, .{ .imm32 = @as(u32, @intCast(ty.abiSize(mod))) });
2427 },2427 },
2428 else => if (abi_size > 8) {2428 else => if (abi_size > 8) {
2429 return func.fail("TODO: `store` for type `{}` with abisize `{d}`", .{2429 return func.fail("TODO: `store` for type `{}` with abisize `{d}`", .{
...@@ -2440,7 +2440,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE...@@ -2440,7 +2440,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
2440 const valtype = typeToValtype(ty, mod);2440 const valtype = typeToValtype(ty, mod);
2441 const opcode = buildOpcode(.{2441 const opcode = buildOpcode(.{
2442 .valtype1 = valtype,2442 .valtype1 = valtype,
2443 .width = @intCast(u8, abi_size * 8),2443 .width = @as(u8, @intCast(abi_size * 8)),
2444 .op = .store,2444 .op = .store,
2445 });2445 });
24462446
...@@ -2501,7 +2501,7 @@ fn load(func: *CodeGen, operand: WValue, ty: Type, offset: u32) InnerError!WValu...@@ -2501,7 +2501,7 @@ fn load(func: *CodeGen, operand: WValue, ty: Type, offset: u32) InnerError!WValu
25012501
2502 if (ty.zigTypeTag(mod) == .Vector) {2502 if (ty.zigTypeTag(mod) == .Vector) {
2503 // TODO: Add helper functions for simd opcodes2503 // TODO: Add helper functions for simd opcodes
2504 const extra_index = @intCast(u32, func.mir_extra.items.len);2504 const extra_index = @as(u32, @intCast(func.mir_extra.items.len));
2505 // stores as := opcode, offset, alignment (opcode::memarg)2505 // stores as := opcode, offset, alignment (opcode::memarg)
2506 try func.mir_extra.appendSlice(func.gpa, &[_]u32{2506 try func.mir_extra.appendSlice(func.gpa, &[_]u32{
2507 std.wasm.simdOpcode(.v128_load),2507 std.wasm.simdOpcode(.v128_load),
...@@ -2512,7 +2512,7 @@ fn load(func: *CodeGen, operand: WValue, ty: Type, offset: u32) InnerError!WValu...@@ -2512,7 +2512,7 @@ fn load(func: *CodeGen, operand: WValue, ty: Type, offset: u32) InnerError!WValu
2512 return WValue{ .stack = {} };2512 return WValue{ .stack = {} };
2513 }2513 }
25142514
2515 const abi_size = @intCast(u8, ty.abiSize(mod));2515 const abi_size = @as(u8, @intCast(ty.abiSize(mod)));
2516 const opcode = buildOpcode(.{2516 const opcode = buildOpcode(.{
2517 .valtype1 = typeToValtype(ty, mod),2517 .valtype1 = typeToValtype(ty, mod),
2518 .width = abi_size * 8,2518 .width = abi_size * 8,
...@@ -2589,10 +2589,10 @@ fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {...@@ -2589,10 +2589,10 @@ fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
2589 // For big integers we can ignore this as we will call into compiler-rt which handles this.2589 // For big integers we can ignore this as we will call into compiler-rt which handles this.
2590 const result = switch (op) {2590 const result = switch (op) {
2591 .shr, .shl => res: {2591 .shr, .shl => res: {
2592 const lhs_wasm_bits = toWasmBits(@intCast(u16, lhs_ty.bitSize(mod))) orelse {2592 const lhs_wasm_bits = toWasmBits(@as(u16, @intCast(lhs_ty.bitSize(mod)))) orelse {
2593 return func.fail("TODO: implement '{s}' for types larger than 128 bits", .{@tagName(op)});2593 return func.fail("TODO: implement '{s}' for types larger than 128 bits", .{@tagName(op)});
2594 };2594 };
2595 const rhs_wasm_bits = toWasmBits(@intCast(u16, rhs_ty.bitSize(mod))).?;2595 const rhs_wasm_bits = toWasmBits(@as(u16, @intCast(rhs_ty.bitSize(mod)))).?;
2596 const new_rhs = if (lhs_wasm_bits != rhs_wasm_bits and lhs_wasm_bits != 128) blk: {2596 const new_rhs = if (lhs_wasm_bits != rhs_wasm_bits and lhs_wasm_bits != 128) blk: {
2597 const tmp = try func.intcast(rhs, rhs_ty, lhs_ty);2597 const tmp = try func.intcast(rhs, rhs_ty, lhs_ty);
2598 break :blk try tmp.toLocal(func, lhs_ty);2598 break :blk try tmp.toLocal(func, lhs_ty);
...@@ -2868,10 +2868,10 @@ fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {...@@ -2868,10 +2868,10 @@ fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
2868 // For big integers we can ignore this as we will call into compiler-rt which handles this.2868 // For big integers we can ignore this as we will call into compiler-rt which handles this.
2869 const result = switch (op) {2869 const result = switch (op) {
2870 .shr, .shl => res: {2870 .shr, .shl => res: {
2871 const lhs_wasm_bits = toWasmBits(@intCast(u16, lhs_ty.bitSize(mod))) orelse {2871 const lhs_wasm_bits = toWasmBits(@as(u16, @intCast(lhs_ty.bitSize(mod)))) orelse {
2872 return func.fail("TODO: implement '{s}' for types larger than 128 bits", .{@tagName(op)});2872 return func.fail("TODO: implement '{s}' for types larger than 128 bits", .{@tagName(op)});
2873 };2873 };
2874 const rhs_wasm_bits = toWasmBits(@intCast(u16, rhs_ty.bitSize(mod))).?;2874 const rhs_wasm_bits = toWasmBits(@as(u16, @intCast(rhs_ty.bitSize(mod)))).?;
2875 const new_rhs = if (lhs_wasm_bits != rhs_wasm_bits and lhs_wasm_bits != 128) blk: {2875 const new_rhs = if (lhs_wasm_bits != rhs_wasm_bits and lhs_wasm_bits != 128) blk: {
2876 const tmp = try func.intcast(rhs, rhs_ty, lhs_ty);2876 const tmp = try func.intcast(rhs, rhs_ty, lhs_ty);
2877 break :blk try tmp.toLocal(func, lhs_ty);2877 break :blk try tmp.toLocal(func, lhs_ty);
...@@ -2902,7 +2902,7 @@ fn wrapBinOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerEr...@@ -2902,7 +2902,7 @@ fn wrapBinOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerEr
2902fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {2902fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
2903 const mod = func.bin_file.base.options.module.?;2903 const mod = func.bin_file.base.options.module.?;
2904 assert(ty.abiSize(mod) <= 16);2904 assert(ty.abiSize(mod) <= 16);
2905 const bitsize = @intCast(u16, ty.bitSize(mod));2905 const bitsize = @as(u16, @intCast(ty.bitSize(mod)));
2906 const wasm_bits = toWasmBits(bitsize) orelse {2906 const wasm_bits = toWasmBits(bitsize) orelse {
2907 return func.fail("TODO: Implement wrapOperand for bitsize '{d}'", .{bitsize});2907 return func.fail("TODO: Implement wrapOperand for bitsize '{d}'", .{bitsize});
2908 };2908 };
...@@ -2916,7 +2916,7 @@ fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {...@@ -2916,7 +2916,7 @@ fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
2916 const result_ptr = try func.allocStack(ty);2916 const result_ptr = try func.allocStack(ty);
2917 try func.emitWValue(result_ptr);2917 try func.emitWValue(result_ptr);
2918 try func.store(.{ .stack = {} }, lsb, Type.u64, 8 + result_ptr.offset());2918 try func.store(.{ .stack = {} }, lsb, Type.u64, 8 + result_ptr.offset());
2919 const result = (@as(u64, 1) << @intCast(u6, 64 - (wasm_bits - bitsize))) - 1;2919 const result = (@as(u64, 1) << @as(u6, @intCast(64 - (wasm_bits - bitsize)))) - 1;
2920 try func.emitWValue(result_ptr);2920 try func.emitWValue(result_ptr);
2921 _ = try func.load(operand, Type.u64, 0);2921 _ = try func.load(operand, Type.u64, 0);
2922 try func.addImm64(result);2922 try func.addImm64(result);
...@@ -2925,10 +2925,10 @@ fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {...@@ -2925,10 +2925,10 @@ fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
2925 return result_ptr;2925 return result_ptr;
2926 }2926 }
29272927
2928 const result = (@as(u64, 1) << @intCast(u6, bitsize)) - 1;2928 const result = (@as(u64, 1) << @as(u6, @intCast(bitsize))) - 1;
2929 try func.emitWValue(operand);2929 try func.emitWValue(operand);
2930 if (bitsize <= 32) {2930 if (bitsize <= 32) {
2931 try func.addImm32(@bitCast(i32, @intCast(u32, result)));2931 try func.addImm32(@as(i32, @bitCast(@as(u32, @intCast(result)))));
2932 try func.addTag(.i32_and);2932 try func.addTag(.i32_and);
2933 } else if (bitsize <= 64) {2933 } else if (bitsize <= 64) {
2934 try func.addImm64(result);2934 try func.addImm64(result);
...@@ -2957,15 +2957,15 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue...@@ -2957,15 +2957,15 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue
2957 const index = elem.index;2957 const index = elem.index;
2958 const elem_type = mod.intern_pool.typeOf(elem.base).toType().elemType2(mod);2958 const elem_type = mod.intern_pool.typeOf(elem.base).toType().elemType2(mod);
2959 const elem_offset = index * elem_type.abiSize(mod);2959 const elem_offset = index * elem_type.abiSize(mod);
2960 return func.lowerParentPtr(elem.base.toValue(), @intCast(u32, elem_offset + offset));2960 return func.lowerParentPtr(elem.base.toValue(), @as(u32, @intCast(elem_offset + offset)));
2961 },2961 },
2962 .field => |field| {2962 .field => |field| {
2963 const parent_ty = mod.intern_pool.typeOf(field.base).toType().childType(mod);2963 const parent_ty = mod.intern_pool.typeOf(field.base).toType().childType(mod);
29642964
2965 const field_offset = switch (parent_ty.zigTypeTag(mod)) {2965 const field_offset = switch (parent_ty.zigTypeTag(mod)) {
2966 .Struct => switch (parent_ty.containerLayout(mod)) {2966 .Struct => switch (parent_ty.containerLayout(mod)) {
2967 .Packed => parent_ty.packedStructFieldByteOffset(@intCast(usize, field.index), mod),2967 .Packed => parent_ty.packedStructFieldByteOffset(@as(usize, @intCast(field.index)), mod),
2968 else => parent_ty.structFieldOffset(@intCast(usize, field.index), mod),2968 else => parent_ty.structFieldOffset(@as(usize, @intCast(field.index)), mod),
2969 },2969 },
2970 .Union => switch (parent_ty.containerLayout(mod)) {2970 .Union => switch (parent_ty.containerLayout(mod)) {
2971 .Packed => 0,2971 .Packed => 0,
...@@ -2975,7 +2975,7 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue...@@ -2975,7 +2975,7 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue
2975 if (layout.payload_align > layout.tag_align) break :blk 0;2975 if (layout.payload_align > layout.tag_align) break :blk 0;
29762976
2977 // tag is stored first so calculate offset from where payload starts2977 // tag is stored first so calculate offset from where payload starts
2978 break :blk @intCast(u32, std.mem.alignForward(u64, layout.tag_size, layout.tag_align));2978 break :blk @as(u32, @intCast(std.mem.alignForward(u64, layout.tag_size, layout.tag_align)));
2979 },2979 },
2980 },2980 },
2981 .Pointer => switch (parent_ty.ptrSize(mod)) {2981 .Pointer => switch (parent_ty.ptrSize(mod)) {
...@@ -2988,7 +2988,7 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue...@@ -2988,7 +2988,7 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue
2988 },2988 },
2989 else => unreachable,2989 else => unreachable,
2990 };2990 };
2991 return func.lowerParentPtr(field.base.toValue(), @intCast(u32, offset + field_offset));2991 return func.lowerParentPtr(field.base.toValue(), @as(u32, @intCast(offset + field_offset)));
2992 },2992 },
2993 }2993 }
2994}2994}
...@@ -3045,11 +3045,11 @@ fn toTwosComplement(value: anytype, bits: u7) std.meta.Int(.unsigned, @typeInfo(...@@ -3045,11 +3045,11 @@ fn toTwosComplement(value: anytype, bits: u7) std.meta.Int(.unsigned, @typeInfo(
3045 comptime assert(@typeInfo(T).Int.signedness == .signed);3045 comptime assert(@typeInfo(T).Int.signedness == .signed);
3046 assert(bits <= 64);3046 assert(bits <= 64);
3047 const WantedT = std.meta.Int(.unsigned, @typeInfo(T).Int.bits);3047 const WantedT = std.meta.Int(.unsigned, @typeInfo(T).Int.bits);
3048 if (value >= 0) return @bitCast(WantedT, value);3048 if (value >= 0) return @as(WantedT, @bitCast(value));
3049 const max_value = @intCast(u64, (@as(u65, 1) << bits) - 1);3049 const max_value = @as(u64, @intCast((@as(u65, 1) << bits) - 1));
3050 const flipped = @intCast(T, (~-@as(i65, value)) + 1);3050 const flipped = @as(T, @intCast((~-@as(i65, value)) + 1));
3051 const result = @bitCast(WantedT, flipped) & max_value;3051 const result = @as(WantedT, @bitCast(flipped)) & max_value;
3052 return @intCast(WantedT, result);3052 return @as(WantedT, @intCast(result));
3053}3053}
30543054
3055fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {3055fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
...@@ -3150,18 +3150,18 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {...@@ -3150,18 +3150,18 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
3150 const int_info = ty.intInfo(mod);3150 const int_info = ty.intInfo(mod);
3151 switch (int_info.signedness) {3151 switch (int_info.signedness) {
3152 .signed => switch (int_info.bits) {3152 .signed => switch (int_info.bits) {
3153 0...32 => return WValue{ .imm32 = @intCast(u32, toTwosComplement(3153 0...32 => return WValue{ .imm32 = @as(u32, @intCast(toTwosComplement(
3154 val.toSignedInt(mod),3154 val.toSignedInt(mod),
3155 @intCast(u6, int_info.bits),3155 @as(u6, @intCast(int_info.bits)),
3156 )) },3156 ))) },
3157 33...64 => return WValue{ .imm64 = toTwosComplement(3157 33...64 => return WValue{ .imm64 = toTwosComplement(
3158 val.toSignedInt(mod),3158 val.toSignedInt(mod),
3159 @intCast(u7, int_info.bits),3159 @as(u7, @intCast(int_info.bits)),
3160 ) },3160 ) },
3161 else => unreachable,3161 else => unreachable,
3162 },3162 },
3163 .unsigned => switch (int_info.bits) {3163 .unsigned => switch (int_info.bits) {
3164 0...32 => return WValue{ .imm32 = @intCast(u32, val.toUnsignedInt(mod)) },3164 0...32 => return WValue{ .imm32 = @as(u32, @intCast(val.toUnsignedInt(mod))) },
3165 33...64 => return WValue{ .imm64 = val.toUnsignedInt(mod) },3165 33...64 => return WValue{ .imm64 = val.toUnsignedInt(mod) },
3166 else => unreachable,3166 else => unreachable,
3167 },3167 },
...@@ -3198,7 +3198,7 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {...@@ -3198,7 +3198,7 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
3198 return func.lowerConstant(enum_tag.int.toValue(), int_tag_ty.toType());3198 return func.lowerConstant(enum_tag.int.toValue(), int_tag_ty.toType());
3199 },3199 },
3200 .float => |float| switch (float.storage) {3200 .float => |float| switch (float.storage) {
3201 .f16 => |f16_val| return WValue{ .imm32 = @bitCast(u16, f16_val) },3201 .f16 => |f16_val| return WValue{ .imm32 = @as(u16, @bitCast(f16_val)) },
3202 .f32 => |f32_val| return WValue{ .float32 = f32_val },3202 .f32 => |f32_val| return WValue{ .float32 = f32_val },
3203 .f64 => |f64_val| return WValue{ .float64 = f64_val },3203 .f64 => |f64_val| return WValue{ .float64 = f64_val },
3204 else => unreachable,3204 else => unreachable,
...@@ -3254,7 +3254,7 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {...@@ -3254,7 +3254,7 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
3254/// Stores the value as a 128bit-immediate value by storing it inside3254/// Stores the value as a 128bit-immediate value by storing it inside
3255/// the list and returning the index into this list as `WValue`.3255/// the list and returning the index into this list as `WValue`.
3256fn storeSimdImmd(func: *CodeGen, value: [16]u8) !WValue {3256fn storeSimdImmd(func: *CodeGen, value: [16]u8) !WValue {
3257 const index = @intCast(u32, func.simd_immediates.items.len);3257 const index = @as(u32, @intCast(func.simd_immediates.items.len));
3258 try func.simd_immediates.append(func.gpa, value);3258 try func.simd_immediates.append(func.gpa, value);
3259 return WValue{ .imm128 = index };3259 return WValue{ .imm128 = index };
3260}3260}
...@@ -3270,8 +3270,8 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {...@@ -3270,8 +3270,8 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
3270 },3270 },
3271 .Float => switch (ty.floatBits(func.target)) {3271 .Float => switch (ty.floatBits(func.target)) {
3272 16 => return WValue{ .imm32 = 0xaaaaaaaa },3272 16 => return WValue{ .imm32 = 0xaaaaaaaa },
3273 32 => return WValue{ .float32 = @bitCast(f32, @as(u32, 0xaaaaaaaa)) },3273 32 => return WValue{ .float32 = @as(f32, @bitCast(@as(u32, 0xaaaaaaaa))) },
3274 64 => return WValue{ .float64 = @bitCast(f64, @as(u64, 0xaaaaaaaaaaaaaaaa)) },3274 64 => return WValue{ .float64 = @as(f64, @bitCast(@as(u64, 0xaaaaaaaaaaaaaaaa))) },
3275 else => unreachable,3275 else => unreachable,
3276 },3276 },
3277 .Pointer => switch (func.arch()) {3277 .Pointer => switch (func.arch()) {
...@@ -3312,13 +3312,13 @@ fn valueAsI32(func: *const CodeGen, val: Value, ty: Type) i32 {...@@ -3312,13 +3312,13 @@ fn valueAsI32(func: *const CodeGen, val: Value, ty: Type) i32 {
3312 .enum_tag => |enum_tag| intIndexAsI32(&mod.intern_pool, enum_tag.int, mod),3312 .enum_tag => |enum_tag| intIndexAsI32(&mod.intern_pool, enum_tag.int, mod),
3313 .int => |int| intStorageAsI32(int.storage, mod),3313 .int => |int| intStorageAsI32(int.storage, mod),
3314 .ptr => |ptr| intIndexAsI32(&mod.intern_pool, ptr.addr.int, mod),3314 .ptr => |ptr| intIndexAsI32(&mod.intern_pool, ptr.addr.int, mod),
3315 .err => |err| @bitCast(i32, @intCast(Module.ErrorInt, mod.global_error_set.getIndex(err.name).?)),3315 .err => |err| @as(i32, @bitCast(@as(Module.ErrorInt, @intCast(mod.global_error_set.getIndex(err.name).?)))),
3316 else => unreachable,3316 else => unreachable,
3317 },3317 },
3318 }3318 }
33193319
3320 return switch (ty.zigTypeTag(mod)) {3320 return switch (ty.zigTypeTag(mod)) {
3321 .ErrorSet => @bitCast(i32, val.getErrorInt(mod)),3321 .ErrorSet => @as(i32, @bitCast(val.getErrorInt(mod))),
3322 else => unreachable, // Programmer called this function for an illegal type3322 else => unreachable, // Programmer called this function for an illegal type
3323 };3323 };
3324}3324}
...@@ -3329,11 +3329,11 @@ fn intIndexAsI32(ip: *const InternPool, int: InternPool.Index, mod: *Module) i32...@@ -3329,11 +3329,11 @@ fn intIndexAsI32(ip: *const InternPool, int: InternPool.Index, mod: *Module) i32
33293329
3330fn intStorageAsI32(storage: InternPool.Key.Int.Storage, mod: *Module) i32 {3330fn intStorageAsI32(storage: InternPool.Key.Int.Storage, mod: *Module) i32 {
3331 return switch (storage) {3331 return switch (storage) {
3332 .i64 => |x| @intCast(i32, x),3332 .i64 => |x| @as(i32, @intCast(x)),
3333 .u64 => |x| @bitCast(i32, @intCast(u32, x)),3333 .u64 => |x| @as(i32, @bitCast(@as(u32, @intCast(x)))),
3334 .big_int => unreachable,3334 .big_int => unreachable,
3335 .lazy_align => |ty| @bitCast(i32, ty.toType().abiAlignment(mod)),3335 .lazy_align => |ty| @as(i32, @bitCast(ty.toType().abiAlignment(mod))),
3336 .lazy_size => |ty| @bitCast(i32, @intCast(u32, ty.toType().abiSize(mod))),3336 .lazy_size => |ty| @as(i32, @bitCast(@as(u32, @intCast(ty.toType().abiSize(mod))))),
3337 };3337 };
3338}3338}
33393339
...@@ -3421,7 +3421,7 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3421,7 +3421,7 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3421 try func.branches.ensureUnusedCapacity(func.gpa, 2);3421 try func.branches.ensureUnusedCapacity(func.gpa, 2);
3422 {3422 {
3423 func.branches.appendAssumeCapacity(.{});3423 func.branches.appendAssumeCapacity(.{});
3424 try func.currentBranch().values.ensureUnusedCapacity(func.gpa, @intCast(u32, liveness_condbr.else_deaths.len));3424 try func.currentBranch().values.ensureUnusedCapacity(func.gpa, @as(u32, @intCast(liveness_condbr.else_deaths.len)));
3425 defer {3425 defer {
3426 var else_stack = func.branches.pop();3426 var else_stack = func.branches.pop();
3427 else_stack.deinit(func.gpa);3427 else_stack.deinit(func.gpa);
...@@ -3433,7 +3433,7 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3433,7 +3433,7 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3433 // Outer block that matches the condition3433 // Outer block that matches the condition
3434 {3434 {
3435 func.branches.appendAssumeCapacity(.{});3435 func.branches.appendAssumeCapacity(.{});
3436 try func.currentBranch().values.ensureUnusedCapacity(func.gpa, @intCast(u32, liveness_condbr.then_deaths.len));3436 try func.currentBranch().values.ensureUnusedCapacity(func.gpa, @as(u32, @intCast(liveness_condbr.then_deaths.len)));
3437 defer {3437 defer {
3438 var then_stack = func.branches.pop();3438 var then_stack = func.branches.pop();
3439 then_stack.deinit(func.gpa);3439 then_stack.deinit(func.gpa);
...@@ -3715,7 +3715,7 @@ fn structFieldPtr(...@@ -3715,7 +3715,7 @@ fn structFieldPtr(
3715 }3715 }
3716 switch (struct_ptr) {3716 switch (struct_ptr) {
3717 .stack_offset => |stack_offset| {3717 .stack_offset => |stack_offset| {
3718 return WValue{ .stack_offset = .{ .value = stack_offset.value + @intCast(u32, offset), .references = 1 } };3718 return WValue{ .stack_offset = .{ .value = stack_offset.value + @as(u32, @intCast(offset)), .references = 1 } };
3719 },3719 },
3720 else => return func.buildPointerOffset(struct_ptr, offset, .new),3720 else => return func.buildPointerOffset(struct_ptr, offset, .new),
3721 }3721 }
...@@ -3755,7 +3755,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3755,7 +3755,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3755 try func.binOp(operand, const_wvalue, backing_ty, .shr);3755 try func.binOp(operand, const_wvalue, backing_ty, .shr);
37563756
3757 if (field_ty.zigTypeTag(mod) == .Float) {3757 if (field_ty.zigTypeTag(mod) == .Float) {
3758 const int_type = try mod.intType(.unsigned, @intCast(u16, field_ty.bitSize(mod)));3758 const int_type = try mod.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(mod))));
3759 const truncated = try func.trunc(shifted_value, int_type, backing_ty);3759 const truncated = try func.trunc(shifted_value, int_type, backing_ty);
3760 const bitcasted = try func.bitcast(field_ty, int_type, truncated);3760 const bitcasted = try func.bitcast(field_ty, int_type, truncated);
3761 break :result try bitcasted.toLocal(func, field_ty);3761 break :result try bitcasted.toLocal(func, field_ty);
...@@ -3764,7 +3764,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3764,7 +3764,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3764 // we can simply reuse the operand.3764 // we can simply reuse the operand.
3765 break :result func.reuseOperand(struct_field.struct_operand, operand);3765 break :result func.reuseOperand(struct_field.struct_operand, operand);
3766 } else if (field_ty.isPtrAtRuntime(mod)) {3766 } else if (field_ty.isPtrAtRuntime(mod)) {
3767 const int_type = try mod.intType(.unsigned, @intCast(u16, field_ty.bitSize(mod)));3767 const int_type = try mod.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(mod))));
3768 const truncated = try func.trunc(shifted_value, int_type, backing_ty);3768 const truncated = try func.trunc(shifted_value, int_type, backing_ty);
3769 break :result try truncated.toLocal(func, field_ty);3769 break :result try truncated.toLocal(func, field_ty);
3770 }3770 }
...@@ -3783,14 +3783,14 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3783,14 +3783,14 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3783 }3783 }
3784 }3784 }
37853785
3786 const union_int_type = try mod.intType(.unsigned, @intCast(u16, struct_ty.bitSize(mod)));3786 const union_int_type = try mod.intType(.unsigned, @as(u16, @intCast(struct_ty.bitSize(mod))));
3787 if (field_ty.zigTypeTag(mod) == .Float) {3787 if (field_ty.zigTypeTag(mod) == .Float) {
3788 const int_type = try mod.intType(.unsigned, @intCast(u16, field_ty.bitSize(mod)));3788 const int_type = try mod.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(mod))));
3789 const truncated = try func.trunc(operand, int_type, union_int_type);3789 const truncated = try func.trunc(operand, int_type, union_int_type);
3790 const bitcasted = try func.bitcast(field_ty, int_type, truncated);3790 const bitcasted = try func.bitcast(field_ty, int_type, truncated);
3791 break :result try bitcasted.toLocal(func, field_ty);3791 break :result try bitcasted.toLocal(func, field_ty);
3792 } else if (field_ty.isPtrAtRuntime(mod)) {3792 } else if (field_ty.isPtrAtRuntime(mod)) {
3793 const int_type = try mod.intType(.unsigned, @intCast(u16, field_ty.bitSize(mod)));3793 const int_type = try mod.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(mod))));
3794 const truncated = try func.trunc(operand, int_type, union_int_type);3794 const truncated = try func.trunc(operand, int_type, union_int_type);
3795 break :result try truncated.toLocal(func, field_ty);3795 break :result try truncated.toLocal(func, field_ty);
3796 }3796 }
...@@ -3847,7 +3847,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3847,7 +3847,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3847 var highest_maybe: ?i32 = null;3847 var highest_maybe: ?i32 = null;
3848 while (case_i < switch_br.data.cases_len) : (case_i += 1) {3848 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
3849 const case = func.air.extraData(Air.SwitchBr.Case, extra_index);3849 const case = func.air.extraData(Air.SwitchBr.Case, extra_index);
3850 const items = @ptrCast([]const Air.Inst.Ref, func.air.extra[case.end..][0..case.data.items_len]);3850 const items = @as([]const Air.Inst.Ref, @ptrCast(func.air.extra[case.end..][0..case.data.items_len]));
3851 const case_body = func.air.extra[case.end + items.len ..][0..case.data.body_len];3851 const case_body = func.air.extra[case.end + items.len ..][0..case.data.body_len];
3852 extra_index = case.end + items.len + case_body.len;3852 extra_index = case.end + items.len + case_body.len;
3853 const values = try func.gpa.alloc(CaseValue, items.len);3853 const values = try func.gpa.alloc(CaseValue, items.len);
...@@ -3904,7 +3904,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3904,7 +3904,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3904 }3904 }
39053905
3906 // Account for default branch so always add '1'3906 // Account for default branch so always add '1'
3907 const depth = @intCast(u32, highest - lowest + @intFromBool(has_else_body)) + 1;3907 const depth = @as(u32, @intCast(highest - lowest + @intFromBool(has_else_body))) + 1;
3908 const jump_table: Mir.JumpTable = .{ .length = depth };3908 const jump_table: Mir.JumpTable = .{ .length = depth };
3909 const table_extra_index = try func.addExtra(jump_table);3909 const table_extra_index = try func.addExtra(jump_table);
3910 try func.addInst(.{ .tag = .br_table, .data = .{ .payload = table_extra_index } });3910 try func.addInst(.{ .tag = .br_table, .data = .{ .payload = table_extra_index } });
...@@ -3915,7 +3915,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3915,7 +3915,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3915 const idx = blk: {3915 const idx = blk: {
3916 for (case_list.items, 0..) |case, idx| {3916 for (case_list.items, 0..) |case, idx| {
3917 for (case.values) |case_value| {3917 for (case.values) |case_value| {
3918 if (case_value.integer == value) break :blk @intCast(u32, idx);3918 if (case_value.integer == value) break :blk @as(u32, @intCast(idx));
3919 }3919 }
3920 }3920 }
3921 // error sets are almost always sparse so we use the default case3921 // error sets are almost always sparse so we use the default case
...@@ -4018,7 +4018,7 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro...@@ -4018,7 +4018,7 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro
4018 try func.emitWValue(operand);4018 try func.emitWValue(operand);
4019 if (pl_ty.hasRuntimeBitsIgnoreComptime(mod)) {4019 if (pl_ty.hasRuntimeBitsIgnoreComptime(mod)) {
4020 try func.addMemArg(.i32_load16_u, .{4020 try func.addMemArg(.i32_load16_u, .{
4021 .offset = operand.offset() + @intCast(u32, errUnionErrorOffset(pl_ty, mod)),4021 .offset = operand.offset() + @as(u32, @intCast(errUnionErrorOffset(pl_ty, mod))),
4022 .alignment = Type.anyerror.abiAlignment(mod),4022 .alignment = Type.anyerror.abiAlignment(mod),
4023 });4023 });
4024 }4024 }
...@@ -4051,7 +4051,7 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo...@@ -4051,7 +4051,7 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo
4051 break :result WValue{ .none = {} };4051 break :result WValue{ .none = {} };
4052 }4052 }
40534053
4054 const pl_offset = @intCast(u32, errUnionPayloadOffset(payload_ty, mod));4054 const pl_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, mod)));
4055 if (op_is_ptr or isByRef(payload_ty, mod)) {4055 if (op_is_ptr or isByRef(payload_ty, mod)) {
4056 break :result try func.buildPointerOffset(operand, pl_offset, .new);4056 break :result try func.buildPointerOffset(operand, pl_offset, .new);
4057 }4057 }
...@@ -4080,7 +4080,7 @@ fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)...@@ -4080,7 +4080,7 @@ fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)
4080 break :result func.reuseOperand(ty_op.operand, operand);4080 break :result func.reuseOperand(ty_op.operand, operand);
4081 }4081 }
40824082
4083 const error_val = try func.load(operand, Type.anyerror, @intCast(u32, errUnionErrorOffset(payload_ty, mod)));4083 const error_val = try func.load(operand, Type.anyerror, @as(u32, @intCast(errUnionErrorOffset(payload_ty, mod))));
4084 break :result try error_val.toLocal(func, Type.anyerror);4084 break :result try error_val.toLocal(func, Type.anyerror);
4085 };4085 };
4086 func.finishAir(inst, result, &.{ty_op.operand});4086 func.finishAir(inst, result, &.{ty_op.operand});
...@@ -4100,13 +4100,13 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void...@@ -4100,13 +4100,13 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void
4100 }4100 }
41014101
4102 const err_union = try func.allocStack(err_ty);4102 const err_union = try func.allocStack(err_ty);
4103 const payload_ptr = try func.buildPointerOffset(err_union, @intCast(u32, errUnionPayloadOffset(pl_ty, mod)), .new);4103 const payload_ptr = try func.buildPointerOffset(err_union, @as(u32, @intCast(errUnionPayloadOffset(pl_ty, mod))), .new);
4104 try func.store(payload_ptr, operand, pl_ty, 0);4104 try func.store(payload_ptr, operand, pl_ty, 0);
41054105
4106 // ensure we also write '0' to the error part, so any present stack value gets overwritten by it.4106 // ensure we also write '0' to the error part, so any present stack value gets overwritten by it.
4107 try func.emitWValue(err_union);4107 try func.emitWValue(err_union);
4108 try func.addImm32(0);4108 try func.addImm32(0);
4109 const err_val_offset = @intCast(u32, errUnionErrorOffset(pl_ty, mod));4109 const err_val_offset = @as(u32, @intCast(errUnionErrorOffset(pl_ty, mod)));
4110 try func.addMemArg(.i32_store16, .{ .offset = err_union.offset() + err_val_offset, .alignment = 2 });4110 try func.addMemArg(.i32_store16, .{ .offset = err_union.offset() + err_val_offset, .alignment = 2 });
4111 break :result err_union;4111 break :result err_union;
4112 };4112 };
...@@ -4128,11 +4128,11 @@ fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4128,11 +4128,11 @@ fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41284128
4129 const err_union = try func.allocStack(err_ty);4129 const err_union = try func.allocStack(err_ty);
4130 // store error value4130 // store error value
4131 try func.store(err_union, operand, Type.anyerror, @intCast(u32, errUnionErrorOffset(pl_ty, mod)));4131 try func.store(err_union, operand, Type.anyerror, @as(u32, @intCast(errUnionErrorOffset(pl_ty, mod))));
41324132
4133 // write 'undefined' to the payload4133 // write 'undefined' to the payload
4134 const payload_ptr = try func.buildPointerOffset(err_union, @intCast(u32, errUnionPayloadOffset(pl_ty, mod)), .new);4134 const payload_ptr = try func.buildPointerOffset(err_union, @as(u32, @intCast(errUnionPayloadOffset(pl_ty, mod))), .new);
4135 const len = @intCast(u32, err_ty.errorUnionPayload(mod).abiSize(mod));4135 const len = @as(u32, @intCast(err_ty.errorUnionPayload(mod).abiSize(mod)));
4136 try func.memset(Type.u8, payload_ptr, .{ .imm32 = len }, .{ .imm32 = 0xaa });4136 try func.memset(Type.u8, payload_ptr, .{ .imm32 = len }, .{ .imm32 = 0xaa });
41374137
4138 break :result err_union;4138 break :result err_union;
...@@ -4154,8 +4154,8 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4154,8 +4154,8 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4154 return func.fail("todo Wasm intcast for bitsize > 128", .{});4154 return func.fail("todo Wasm intcast for bitsize > 128", .{});
4155 }4155 }
41564156
4157 const op_bits = toWasmBits(@intCast(u16, operand_ty.bitSize(mod))).?;4157 const op_bits = toWasmBits(@as(u16, @intCast(operand_ty.bitSize(mod)))).?;
4158 const wanted_bits = toWasmBits(@intCast(u16, ty.bitSize(mod))).?;4158 const wanted_bits = toWasmBits(@as(u16, @intCast(ty.bitSize(mod)))).?;
4159 const result = if (op_bits == wanted_bits)4159 const result = if (op_bits == wanted_bits)
4160 func.reuseOperand(ty_op.operand, operand)4160 func.reuseOperand(ty_op.operand, operand)
4161 else4161 else
...@@ -4170,8 +4170,8 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4170,8 +4170,8 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4170/// NOTE: May leave the result on the top of the stack.4170/// NOTE: May leave the result on the top of the stack.
4171fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!WValue {4171fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!WValue {
4172 const mod = func.bin_file.base.options.module.?;4172 const mod = func.bin_file.base.options.module.?;
4173 const given_bitsize = @intCast(u16, given.bitSize(mod));4173 const given_bitsize = @as(u16, @intCast(given.bitSize(mod)));
4174 const wanted_bitsize = @intCast(u16, wanted.bitSize(mod));4174 const wanted_bitsize = @as(u16, @intCast(wanted.bitSize(mod)));
4175 assert(given_bitsize <= 128);4175 assert(given_bitsize <= 128);
4176 assert(wanted_bitsize <= 128);4176 assert(wanted_bitsize <= 128);
41774177
...@@ -4396,7 +4396,7 @@ fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4396,7 +4396,7 @@ fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43964396
4397 // calculate index into slice4397 // calculate index into slice
4398 try func.emitWValue(index);4398 try func.emitWValue(index);
4399 try func.addImm32(@bitCast(i32, @intCast(u32, elem_size)));4399 try func.addImm32(@as(i32, @bitCast(@as(u32, @intCast(elem_size)))));
4400 try func.addTag(.i32_mul);4400 try func.addTag(.i32_mul);
4401 try func.addTag(.i32_add);4401 try func.addTag(.i32_add);
44024402
...@@ -4426,7 +4426,7 @@ fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4426,7 +4426,7 @@ fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44264426
4427 // calculate index into slice4427 // calculate index into slice
4428 try func.emitWValue(index);4428 try func.emitWValue(index);
4429 try func.addImm32(@bitCast(i32, @intCast(u32, elem_size)));4429 try func.addImm32(@as(i32, @bitCast(@as(u32, @intCast(elem_size)))));
4430 try func.addTag(.i32_mul);4430 try func.addTag(.i32_mul);
4431 try func.addTag(.i32_add);4431 try func.addTag(.i32_add);
44324432
...@@ -4466,13 +4466,13 @@ fn airTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4466,13 +4466,13 @@ fn airTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4466/// NOTE: Resulting value is left on the stack.4466/// NOTE: Resulting value is left on the stack.
4467fn trunc(func: *CodeGen, operand: WValue, wanted_ty: Type, given_ty: Type) InnerError!WValue {4467fn trunc(func: *CodeGen, operand: WValue, wanted_ty: Type, given_ty: Type) InnerError!WValue {
4468 const mod = func.bin_file.base.options.module.?;4468 const mod = func.bin_file.base.options.module.?;
4469 const given_bits = @intCast(u16, given_ty.bitSize(mod));4469 const given_bits = @as(u16, @intCast(given_ty.bitSize(mod)));
4470 if (toWasmBits(given_bits) == null) {4470 if (toWasmBits(given_bits) == null) {
4471 return func.fail("TODO: Implement wasm integer truncation for integer bitsize: {d}", .{given_bits});4471 return func.fail("TODO: Implement wasm integer truncation for integer bitsize: {d}", .{given_bits});
4472 }4472 }
44734473
4474 var result = try func.intcast(operand, given_ty, wanted_ty);4474 var result = try func.intcast(operand, given_ty, wanted_ty);
4475 const wanted_bits = @intCast(u16, wanted_ty.bitSize(mod));4475 const wanted_bits = @as(u16, @intCast(wanted_ty.bitSize(mod)));
4476 const wasm_bits = toWasmBits(wanted_bits).?;4476 const wasm_bits = toWasmBits(wanted_bits).?;
4477 if (wasm_bits != wanted_bits) {4477 if (wasm_bits != wanted_bits) {
4478 result = try func.wrapOperand(result, wanted_ty);4478 result = try func.wrapOperand(result, wanted_ty);
...@@ -4505,7 +4505,7 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4505,7 +4505,7 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4505 }4505 }
45064506
4507 // store the length of the array in the slice4507 // store the length of the array in the slice
4508 const len = WValue{ .imm32 = @intCast(u32, array_ty.arrayLen(mod)) };4508 const len = WValue{ .imm32 = @as(u32, @intCast(array_ty.arrayLen(mod))) };
4509 try func.store(slice_local, len, Type.usize, func.ptrSize());4509 try func.store(slice_local, len, Type.usize, func.ptrSize());
45104510
4511 func.finishAir(inst, slice_local, &.{ty_op.operand});4511 func.finishAir(inst, slice_local, &.{ty_op.operand});
...@@ -4545,7 +4545,7 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4545,7 +4545,7 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45454545
4546 // calculate index into slice4546 // calculate index into slice
4547 try func.emitWValue(index);4547 try func.emitWValue(index);
4548 try func.addImm32(@bitCast(i32, @intCast(u32, elem_size)));4548 try func.addImm32(@as(i32, @bitCast(@as(u32, @intCast(elem_size)))));
4549 try func.addTag(.i32_mul);4549 try func.addTag(.i32_mul);
4550 try func.addTag(.i32_add);4550 try func.addTag(.i32_add);
45514551
...@@ -4584,7 +4584,7 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4584,7 +4584,7 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45844584
4585 // calculate index into ptr4585 // calculate index into ptr
4586 try func.emitWValue(index);4586 try func.emitWValue(index);
4587 try func.addImm32(@bitCast(i32, @intCast(u32, elem_size)));4587 try func.addImm32(@as(i32, @bitCast(@as(u32, @intCast(elem_size)))));
4588 try func.addTag(.i32_mul);4588 try func.addTag(.i32_mul);
4589 try func.addTag(.i32_add);4589 try func.addTag(.i32_add);
45904590
...@@ -4612,7 +4612,7 @@ fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {...@@ -4612,7 +4612,7 @@ fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
46124612
4613 try func.lowerToStack(ptr);4613 try func.lowerToStack(ptr);
4614 try func.emitWValue(offset);4614 try func.emitWValue(offset);
4615 try func.addImm32(@bitCast(i32, @intCast(u32, pointee_ty.abiSize(mod))));4615 try func.addImm32(@as(i32, @bitCast(@as(u32, @intCast(pointee_ty.abiSize(mod))))));
4616 try func.addTag(Mir.Inst.Tag.fromOpcode(mul_opcode));4616 try func.addTag(Mir.Inst.Tag.fromOpcode(mul_opcode));
4617 try func.addTag(Mir.Inst.Tag.fromOpcode(bin_opcode));4617 try func.addTag(Mir.Inst.Tag.fromOpcode(bin_opcode));
46184618
...@@ -4635,7 +4635,7 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void...@@ -4635,7 +4635,7 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
4635 const value = try func.resolveInst(bin_op.rhs);4635 const value = try func.resolveInst(bin_op.rhs);
4636 const len = switch (ptr_ty.ptrSize(mod)) {4636 const len = switch (ptr_ty.ptrSize(mod)) {
4637 .Slice => try func.sliceLen(ptr),4637 .Slice => try func.sliceLen(ptr),
4638 .One => @as(WValue, .{ .imm32 = @intCast(u32, ptr_ty.childType(mod).arrayLen(mod)) }),4638 .One => @as(WValue, .{ .imm32 = @as(u32, @intCast(ptr_ty.childType(mod).arrayLen(mod))) }),
4639 .C, .Many => unreachable,4639 .C, .Many => unreachable,
4640 };4640 };
46414641
...@@ -4656,7 +4656,7 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void...@@ -4656,7 +4656,7 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
4656/// we implement it manually.4656/// we implement it manually.
4657fn memset(func: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue) InnerError!void {4657fn memset(func: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue) InnerError!void {
4658 const mod = func.bin_file.base.options.module.?;4658 const mod = func.bin_file.base.options.module.?;
4659 const abi_size = @intCast(u32, elem_ty.abiSize(mod));4659 const abi_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
46604660
4661 // When bulk_memory is enabled, we lower it to wasm's memset instruction.4661 // When bulk_memory is enabled, we lower it to wasm's memset instruction.
4662 // If not, we lower it ourselves.4662 // If not, we lower it ourselves.
...@@ -4756,7 +4756,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4756,7 +4756,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4756 if (isByRef(array_ty, mod)) {4756 if (isByRef(array_ty, mod)) {
4757 try func.lowerToStack(array);4757 try func.lowerToStack(array);
4758 try func.emitWValue(index);4758 try func.emitWValue(index);
4759 try func.addImm32(@bitCast(i32, @intCast(u32, elem_size)));4759 try func.addImm32(@as(i32, @bitCast(@as(u32, @intCast(elem_size)))));
4760 try func.addTag(.i32_mul);4760 try func.addTag(.i32_mul);
4761 try func.addTag(.i32_add);4761 try func.addTag(.i32_add);
4762 } else {4762 } else {
...@@ -4772,11 +4772,11 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4772,11 +4772,11 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4772 else => unreachable,4772 else => unreachable,
4773 };4773 };
47744774
4775 var operands = [_]u32{ std.wasm.simdOpcode(opcode), @intCast(u8, lane) };4775 var operands = [_]u32{ std.wasm.simdOpcode(opcode), @as(u8, @intCast(lane)) };
47764776
4777 try func.emitWValue(array);4777 try func.emitWValue(array);
47784778
4779 const extra_index = @intCast(u32, func.mir_extra.items.len);4779 const extra_index = @as(u32, @intCast(func.mir_extra.items.len));
4780 try func.mir_extra.appendSlice(func.gpa, &operands);4780 try func.mir_extra.appendSlice(func.gpa, &operands);
4781 try func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });4781 try func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });
47824782
...@@ -4789,7 +4789,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4789,7 +4789,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4789 // Is a non-unrolled vector (v128)4789 // Is a non-unrolled vector (v128)
4790 try func.lowerToStack(stack_vec);4790 try func.lowerToStack(stack_vec);
4791 try func.emitWValue(index);4791 try func.emitWValue(index);
4792 try func.addImm32(@bitCast(i32, @intCast(u32, elem_size)));4792 try func.addImm32(@as(i32, @bitCast(@as(u32, @intCast(elem_size)))));
4793 try func.addTag(.i32_mul);4793 try func.addTag(.i32_mul);
4794 try func.addTag(.i32_add);4794 try func.addTag(.i32_add);
4795 },4795 },
...@@ -4886,7 +4886,7 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4886,7 +4886,7 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4886 const result = try func.allocLocal(ty);4886 const result = try func.allocLocal(ty);
4887 try func.emitWValue(operand);4887 try func.emitWValue(operand);
4888 // TODO: Add helper functions for simd opcodes4888 // TODO: Add helper functions for simd opcodes
4889 const extra_index = @intCast(u32, func.mir_extra.items.len);4889 const extra_index = @as(u32, @intCast(func.mir_extra.items.len));
4890 // stores as := opcode, offset, alignment (opcode::memarg)4890 // stores as := opcode, offset, alignment (opcode::memarg)
4891 try func.mir_extra.appendSlice(func.gpa, &[_]u32{4891 try func.mir_extra.appendSlice(func.gpa, &[_]u32{
4892 opcode,4892 opcode,
...@@ -4907,7 +4907,7 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4907,7 +4907,7 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4907 };4907 };
4908 const result = try func.allocLocal(ty);4908 const result = try func.allocLocal(ty);
4909 try func.emitWValue(operand);4909 try func.emitWValue(operand);
4910 const extra_index = @intCast(u32, func.mir_extra.items.len);4910 const extra_index = @as(u32, @intCast(func.mir_extra.items.len));
4911 try func.mir_extra.append(func.gpa, opcode);4911 try func.mir_extra.append(func.gpa, opcode);
4912 try func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });4912 try func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });
4913 try func.addLabel(.local_set, result.local.value);4913 try func.addLabel(.local_set, result.local.value);
...@@ -4917,13 +4917,13 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4917,13 +4917,13 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4917 }4917 }
4918 }4918 }
4919 const elem_size = elem_ty.bitSize(mod);4919 const elem_size = elem_ty.bitSize(mod);
4920 const vector_len = @intCast(usize, ty.vectorLen(mod));4920 const vector_len = @as(usize, @intCast(ty.vectorLen(mod)));
4921 if ((!std.math.isPowerOfTwo(elem_size) or elem_size % 8 != 0) and vector_len > 1) {4921 if ((!std.math.isPowerOfTwo(elem_size) or elem_size % 8 != 0) and vector_len > 1) {
4922 return func.fail("TODO: WebAssembly `@splat` for arbitrary element bitsize {d}", .{elem_size});4922 return func.fail("TODO: WebAssembly `@splat` for arbitrary element bitsize {d}", .{elem_size});
4923 }4923 }
49244924
4925 const result = try func.allocStack(ty);4925 const result = try func.allocStack(ty);
4926 const elem_byte_size = @intCast(u32, elem_ty.abiSize(mod));4926 const elem_byte_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
4927 var index: usize = 0;4927 var index: usize = 0;
4928 var offset: u32 = 0;4928 var offset: u32 = 0;
4929 while (index < vector_len) : (index += 1) {4929 while (index < vector_len) : (index += 1) {
...@@ -4966,11 +4966,11 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4966,11 +4966,11 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4966 try func.emitWValue(result);4966 try func.emitWValue(result);
49674967
4968 const loaded = if (value >= 0)4968 const loaded = if (value >= 0)
4969 try func.load(a, child_ty, @intCast(u32, @intCast(i64, elem_size) * value))4969 try func.load(a, child_ty, @as(u32, @intCast(@as(i64, @intCast(elem_size)) * value)))
4970 else4970 else
4971 try func.load(b, child_ty, @intCast(u32, @intCast(i64, elem_size) * ~value));4971 try func.load(b, child_ty, @as(u32, @intCast(@as(i64, @intCast(elem_size)) * ~value)));
49724972
4973 try func.store(.stack, loaded, child_ty, result.stack_offset.value + @intCast(u32, elem_size) * @intCast(u32, index));4973 try func.store(.stack, loaded, child_ty, result.stack_offset.value + @as(u32, @intCast(elem_size)) * @as(u32, @intCast(index)));
4974 }4974 }
49754975
4976 return func.finishAir(inst, result, &.{ extra.a, extra.b });4976 return func.finishAir(inst, result, &.{ extra.a, extra.b });
...@@ -4980,22 +4980,22 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4980,22 +4980,22 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4980 } ++ [1]u32{undefined} ** 4;4980 } ++ [1]u32{undefined} ** 4;
49814981
4982 var lanes = std.mem.asBytes(operands[1..]);4982 var lanes = std.mem.asBytes(operands[1..]);
4983 for (0..@intCast(usize, mask_len)) |index| {4983 for (0..@as(usize, @intCast(mask_len))) |index| {
4984 const mask_elem = (try mask.elemValue(mod, index)).toSignedInt(mod);4984 const mask_elem = (try mask.elemValue(mod, index)).toSignedInt(mod);
4985 const base_index = if (mask_elem >= 0)4985 const base_index = if (mask_elem >= 0)
4986 @intCast(u8, @intCast(i64, elem_size) * mask_elem)4986 @as(u8, @intCast(@as(i64, @intCast(elem_size)) * mask_elem))
4987 else4987 else
4988 16 + @intCast(u8, @intCast(i64, elem_size) * ~mask_elem);4988 16 + @as(u8, @intCast(@as(i64, @intCast(elem_size)) * ~mask_elem));
49894989
4990 for (0..@intCast(usize, elem_size)) |byte_offset| {4990 for (0..@as(usize, @intCast(elem_size))) |byte_offset| {
4991 lanes[index * @intCast(usize, elem_size) + byte_offset] = base_index + @intCast(u8, byte_offset);4991 lanes[index * @as(usize, @intCast(elem_size)) + byte_offset] = base_index + @as(u8, @intCast(byte_offset));
4992 }4992 }
4993 }4993 }
49944994
4995 try func.emitWValue(a);4995 try func.emitWValue(a);
4996 try func.emitWValue(b);4996 try func.emitWValue(b);
49974997
4998 const extra_index = @intCast(u32, func.mir_extra.items.len);4998 const extra_index = @as(u32, @intCast(func.mir_extra.items.len));
4999 try func.mir_extra.appendSlice(func.gpa, &operands);4999 try func.mir_extra.appendSlice(func.gpa, &operands);
5000 try func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });5000 try func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });
50015001
...@@ -5015,15 +5015,15 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5015,15 +5015,15 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5015 const mod = func.bin_file.base.options.module.?;5015 const mod = func.bin_file.base.options.module.?;
5016 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;5016 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
5017 const result_ty = func.typeOfIndex(inst);5017 const result_ty = func.typeOfIndex(inst);
5018 const len = @intCast(usize, result_ty.arrayLen(mod));5018 const len = @as(usize, @intCast(result_ty.arrayLen(mod)));
5019 const elements = @ptrCast([]const Air.Inst.Ref, func.air.extra[ty_pl.payload..][0..len]);5019 const elements = @as([]const Air.Inst.Ref, @ptrCast(func.air.extra[ty_pl.payload..][0..len]));
50205020
5021 const result: WValue = result_value: {5021 const result: WValue = result_value: {
5022 switch (result_ty.zigTypeTag(mod)) {5022 switch (result_ty.zigTypeTag(mod)) {
5023 .Array => {5023 .Array => {
5024 const result = try func.allocStack(result_ty);5024 const result = try func.allocStack(result_ty);
5025 const elem_ty = result_ty.childType(mod);5025 const elem_ty = result_ty.childType(mod);
5026 const elem_size = @intCast(u32, elem_ty.abiSize(mod));5026 const elem_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
5027 const sentinel = if (result_ty.sentinel(mod)) |sent| blk: {5027 const sentinel = if (result_ty.sentinel(mod)) |sent| blk: {
5028 break :blk try func.lowerConstant(sent, elem_ty);5028 break :blk try func.lowerConstant(sent, elem_ty);
5029 } else null;5029 } else null;
...@@ -5087,7 +5087,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5087,7 +5087,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5087 WValue{ .imm64 = current_bit };5087 WValue{ .imm64 = current_bit };
50885088
5089 const value = try func.resolveInst(elem);5089 const value = try func.resolveInst(elem);
5090 const value_bit_size = @intCast(u16, field.ty.bitSize(mod));5090 const value_bit_size = @as(u16, @intCast(field.ty.bitSize(mod)));
5091 const int_ty = try mod.intType(.unsigned, value_bit_size);5091 const int_ty = try mod.intType(.unsigned, value_bit_size);
50925092
5093 // load our current result on stack so we can perform all transformations5093 // load our current result on stack so we can perform all transformations
...@@ -5113,7 +5113,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5113,7 +5113,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5113 if ((try result_ty.structFieldValueComptime(mod, elem_index)) != null) continue;5113 if ((try result_ty.structFieldValueComptime(mod, elem_index)) != null) continue;
51145114
5115 const elem_ty = result_ty.structFieldType(elem_index, mod);5115 const elem_ty = result_ty.structFieldType(elem_index, mod);
5116 const elem_size = @intCast(u32, elem_ty.abiSize(mod));5116 const elem_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
5117 const value = try func.resolveInst(elem);5117 const value = try func.resolveInst(elem);
5118 try func.store(offset, value, elem_ty, 0);5118 try func.store(offset, value, elem_ty, 0);
51195119
...@@ -5174,7 +5174,7 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5174,7 +5174,7 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5174 const payload_ptr = try func.buildPointerOffset(result_ptr, layout.tag_size, .new);5174 const payload_ptr = try func.buildPointerOffset(result_ptr, layout.tag_size, .new);
5175 try func.store(payload_ptr, payload, field.ty, 0);5175 try func.store(payload_ptr, payload, field.ty, 0);
5176 } else {5176 } else {
5177 try func.store(result_ptr, payload, field.ty, @intCast(u32, layout.tag_size));5177 try func.store(result_ptr, payload, field.ty, @as(u32, @intCast(layout.tag_size)));
5178 }5178 }
51795179
5180 if (layout.tag_size > 0) {5180 if (layout.tag_size > 0) {
...@@ -5187,21 +5187,21 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5187,21 +5187,21 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5187 result_ptr,5187 result_ptr,
5188 tag_int,5188 tag_int,
5189 union_obj.tag_ty,5189 union_obj.tag_ty,
5190 @intCast(u32, layout.payload_size),5190 @as(u32, @intCast(layout.payload_size)),
5191 );5191 );
5192 }5192 }
5193 }5193 }
5194 break :result result_ptr;5194 break :result result_ptr;
5195 } else {5195 } else {
5196 const operand = try func.resolveInst(extra.init);5196 const operand = try func.resolveInst(extra.init);
5197 const union_int_type = try mod.intType(.unsigned, @intCast(u16, union_ty.bitSize(mod)));5197 const union_int_type = try mod.intType(.unsigned, @as(u16, @intCast(union_ty.bitSize(mod))));
5198 if (field.ty.zigTypeTag(mod) == .Float) {5198 if (field.ty.zigTypeTag(mod) == .Float) {
5199 const int_type = try mod.intType(.unsigned, @intCast(u16, field.ty.bitSize(mod)));5199 const int_type = try mod.intType(.unsigned, @as(u16, @intCast(field.ty.bitSize(mod))));
5200 const bitcasted = try func.bitcast(field.ty, int_type, operand);5200 const bitcasted = try func.bitcast(field.ty, int_type, operand);
5201 const casted = try func.trunc(bitcasted, int_type, union_int_type);5201 const casted = try func.trunc(bitcasted, int_type, union_int_type);
5202 break :result try casted.toLocal(func, field.ty);5202 break :result try casted.toLocal(func, field.ty);
5203 } else if (field.ty.isPtrAtRuntime(mod)) {5203 } else if (field.ty.isPtrAtRuntime(mod)) {
5204 const int_type = try mod.intType(.unsigned, @intCast(u16, field.ty.bitSize(mod)));5204 const int_type = try mod.intType(.unsigned, @as(u16, @intCast(field.ty.bitSize(mod))));
5205 const casted = try func.intcast(operand, int_type, union_int_type);5205 const casted = try func.intcast(operand, int_type, union_int_type);
5206 break :result try casted.toLocal(func, field.ty);5206 break :result try casted.toLocal(func, field.ty);
5207 }5207 }
...@@ -5334,7 +5334,7 @@ fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5334,7 +5334,7 @@ fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5334 // when the tag alignment is smaller than the payload, the field will be stored5334 // when the tag alignment is smaller than the payload, the field will be stored
5335 // after the payload.5335 // after the payload.
5336 const offset = if (layout.tag_align < layout.payload_align) blk: {5336 const offset = if (layout.tag_align < layout.payload_align) blk: {
5337 break :blk @intCast(u32, layout.payload_size);5337 break :blk @as(u32, @intCast(layout.payload_size));
5338 } else @as(u32, 0);5338 } else @as(u32, 0);
5339 try func.store(union_ptr, new_tag, tag_ty, offset);5339 try func.store(union_ptr, new_tag, tag_ty, offset);
5340 func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });5340 func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
...@@ -5353,7 +5353,7 @@ fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5353,7 +5353,7 @@ fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5353 // when the tag alignment is smaller than the payload, the field will be stored5353 // when the tag alignment is smaller than the payload, the field will be stored
5354 // after the payload.5354 // after the payload.
5355 const offset = if (layout.tag_align < layout.payload_align) blk: {5355 const offset = if (layout.tag_align < layout.payload_align) blk: {
5356 break :blk @intCast(u32, layout.payload_size);5356 break :blk @as(u32, @intCast(layout.payload_size));
5357 } else @as(u32, 0);5357 } else @as(u32, 0);
5358 const tag = try func.load(operand, tag_ty, offset);5358 const tag = try func.load(operand, tag_ty, offset);
5359 const result = try tag.toLocal(func, tag_ty);5359 const result = try tag.toLocal(func, tag_ty);
...@@ -5458,7 +5458,7 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi...@@ -5458,7 +5458,7 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
5458 operand,5458 operand,
5459 .{ .imm32 = 0 },5459 .{ .imm32 = 0 },
5460 Type.anyerror,5460 Type.anyerror,
5461 @intCast(u32, errUnionErrorOffset(payload_ty, mod)),5461 @as(u32, @intCast(errUnionErrorOffset(payload_ty, mod))),
5462 );5462 );
54635463
5464 const result = result: {5464 const result = result: {
...@@ -5466,7 +5466,7 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi...@@ -5466,7 +5466,7 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
5466 break :result func.reuseOperand(ty_op.operand, operand);5466 break :result func.reuseOperand(ty_op.operand, operand);
5467 }5467 }
54685468
5469 break :result try func.buildPointerOffset(operand, @intCast(u32, errUnionPayloadOffset(payload_ty, mod)), .new);5469 break :result try func.buildPointerOffset(operand, @as(u32, @intCast(errUnionPayloadOffset(payload_ty, mod))), .new);
5470 };5470 };
5471 func.finishAir(inst, result, &.{ty_op.operand});5471 func.finishAir(inst, result, &.{ty_op.operand});
5472}5472}
...@@ -5483,7 +5483,7 @@ fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5483,7 +5483,7 @@ fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5483 const result = if (field_offset != 0) result: {5483 const result = if (field_offset != 0) result: {
5484 const base = try func.buildPointerOffset(field_ptr, 0, .new);5484 const base = try func.buildPointerOffset(field_ptr, 0, .new);
5485 try func.addLabel(.local_get, base.local.value);5485 try func.addLabel(.local_get, base.local.value);
5486 try func.addImm32(@bitCast(i32, @intCast(u32, field_offset)));5486 try func.addImm32(@as(i32, @bitCast(@as(u32, @intCast(field_offset)))));
5487 try func.addTag(.i32_sub);5487 try func.addTag(.i32_sub);
5488 try func.addLabel(.local_set, base.local.value);5488 try func.addLabel(.local_set, base.local.value);
5489 break :result base;5489 break :result base;
...@@ -5514,14 +5514,14 @@ fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5514,14 +5514,14 @@ fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5514 const slice_len = try func.sliceLen(dst);5514 const slice_len = try func.sliceLen(dst);
5515 if (ptr_elem_ty.abiSize(mod) != 1) {5515 if (ptr_elem_ty.abiSize(mod) != 1) {
5516 try func.emitWValue(slice_len);5516 try func.emitWValue(slice_len);
5517 try func.emitWValue(.{ .imm32 = @intCast(u32, ptr_elem_ty.abiSize(mod)) });5517 try func.emitWValue(.{ .imm32 = @as(u32, @intCast(ptr_elem_ty.abiSize(mod))) });
5518 try func.addTag(.i32_mul);5518 try func.addTag(.i32_mul);
5519 try func.addLabel(.local_set, slice_len.local.value);5519 try func.addLabel(.local_set, slice_len.local.value);
5520 }5520 }
5521 break :blk slice_len;5521 break :blk slice_len;
5522 },5522 },
5523 .One => @as(WValue, .{5523 .One => @as(WValue, .{
5524 .imm32 = @intCast(u32, ptr_elem_ty.arrayLen(mod) * ptr_elem_ty.childType(mod).abiSize(mod)),5524 .imm32 = @as(u32, @intCast(ptr_elem_ty.arrayLen(mod) * ptr_elem_ty.childType(mod).abiSize(mod))),
5525 }),5525 }),
5526 .C, .Many => unreachable,5526 .C, .Many => unreachable,
5527 };5527 };
...@@ -5611,7 +5611,7 @@ fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5611,7 +5611,7 @@ fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5611 try func.emitWValue(operand);5611 try func.emitWValue(operand);
5612 switch (func.arch()) {5612 switch (func.arch()) {
5613 .wasm32 => {5613 .wasm32 => {
5614 try func.addImm32(@bitCast(i32, @intCast(u32, abi_size)));5614 try func.addImm32(@as(i32, @bitCast(@as(u32, @intCast(abi_size)))));
5615 try func.addTag(.i32_mul);5615 try func.addTag(.i32_mul);
5616 try func.addTag(.i32_add);5616 try func.addTag(.i32_add);
5617 },5617 },
...@@ -5708,7 +5708,7 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro...@@ -5708,7 +5708,7 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro
57085708
5709 const result_ptr = try func.allocStack(func.typeOfIndex(inst));5709 const result_ptr = try func.allocStack(func.typeOfIndex(inst));
5710 try func.store(result_ptr, result, lhs_ty, 0);5710 try func.store(result_ptr, result, lhs_ty, 0);
5711 const offset = @intCast(u32, lhs_ty.abiSize(mod));5711 const offset = @as(u32, @intCast(lhs_ty.abiSize(mod)));
5712 try func.store(result_ptr, overflow_local, Type.u1, offset);5712 try func.store(result_ptr, overflow_local, Type.u1, offset);
57135713
5714 func.finishAir(inst, result_ptr, &.{ extra.lhs, extra.rhs });5714 func.finishAir(inst, result_ptr, &.{ extra.lhs, extra.rhs });
...@@ -5830,7 +5830,7 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5830,7 +5830,7 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58305830
5831 const result_ptr = try func.allocStack(func.typeOfIndex(inst));5831 const result_ptr = try func.allocStack(func.typeOfIndex(inst));
5832 try func.store(result_ptr, result, lhs_ty, 0);5832 try func.store(result_ptr, result, lhs_ty, 0);
5833 const offset = @intCast(u32, lhs_ty.abiSize(mod));5833 const offset = @as(u32, @intCast(lhs_ty.abiSize(mod)));
5834 try func.store(result_ptr, overflow_local, Type.u1, offset);5834 try func.store(result_ptr, overflow_local, Type.u1, offset);
58355835
5836 func.finishAir(inst, result_ptr, &.{ extra.lhs, extra.rhs });5836 func.finishAir(inst, result_ptr, &.{ extra.lhs, extra.rhs });
...@@ -6005,7 +6005,7 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6005,7 +6005,7 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
60056005
6006 const result_ptr = try func.allocStack(func.typeOfIndex(inst));6006 const result_ptr = try func.allocStack(func.typeOfIndex(inst));
6007 try func.store(result_ptr, bin_op_local, lhs_ty, 0);6007 try func.store(result_ptr, bin_op_local, lhs_ty, 0);
6008 const offset = @intCast(u32, lhs_ty.abiSize(mod));6008 const offset = @as(u32, @intCast(lhs_ty.abiSize(mod)));
6009 try func.store(result_ptr, overflow_bit, Type.u1, offset);6009 try func.store(result_ptr, overflow_bit, Type.u1, offset);
60106010
6011 func.finishAir(inst, result_ptr, &.{ extra.lhs, extra.rhs });6011 func.finishAir(inst, result_ptr, &.{ extra.lhs, extra.rhs });
...@@ -6149,7 +6149,7 @@ fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6149,7 +6149,7 @@ fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6149 switch (wasm_bits) {6149 switch (wasm_bits) {
6150 32 => {6150 32 => {
6151 if (wasm_bits != int_info.bits) {6151 if (wasm_bits != int_info.bits) {
6152 const val: u32 = @as(u32, 1) << @intCast(u5, int_info.bits);6152 const val: u32 = @as(u32, 1) << @as(u5, @intCast(int_info.bits));
6153 // leave value on the stack6153 // leave value on the stack
6154 _ = try func.binOp(operand, .{ .imm32 = val }, ty, .@"or");6154 _ = try func.binOp(operand, .{ .imm32 = val }, ty, .@"or");
6155 } else try func.emitWValue(operand);6155 } else try func.emitWValue(operand);
...@@ -6157,7 +6157,7 @@ fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6157,7 +6157,7 @@ fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6157 },6157 },
6158 64 => {6158 64 => {
6159 if (wasm_bits != int_info.bits) {6159 if (wasm_bits != int_info.bits) {
6160 const val: u64 = @as(u64, 1) << @intCast(u6, int_info.bits);6160 const val: u64 = @as(u64, 1) << @as(u6, @intCast(int_info.bits));
6161 // leave value on the stack6161 // leave value on the stack
6162 _ = try func.binOp(operand, .{ .imm64 = val }, ty, .@"or");6162 _ = try func.binOp(operand, .{ .imm64 = val }, ty, .@"or");
6163 } else try func.emitWValue(operand);6163 } else try func.emitWValue(operand);
...@@ -6172,7 +6172,7 @@ fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6172,7 +6172,7 @@ fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6172 try func.addTag(.i64_ctz);6172 try func.addTag(.i64_ctz);
6173 _ = try func.load(operand, Type.u64, 8);6173 _ = try func.load(operand, Type.u64, 8);
6174 if (wasm_bits != int_info.bits) {6174 if (wasm_bits != int_info.bits) {
6175 try func.addImm64(@as(u64, 1) << @intCast(u6, int_info.bits - 64));6175 try func.addImm64(@as(u64, 1) << @as(u6, @intCast(int_info.bits - 64)));
6176 try func.addTag(.i64_or);6176 try func.addTag(.i64_or);
6177 }6177 }
6178 try func.addTag(.i64_ctz);6178 try func.addTag(.i64_ctz);
...@@ -6275,7 +6275,7 @@ fn lowerTry(...@@ -6275,7 +6275,7 @@ fn lowerTry(
6275 // check if the error tag is set for the error union.6275 // check if the error tag is set for the error union.
6276 try func.emitWValue(err_union);6276 try func.emitWValue(err_union);
6277 if (pl_has_bits) {6277 if (pl_has_bits) {
6278 const err_offset = @intCast(u32, errUnionErrorOffset(pl_ty, mod));6278 const err_offset = @as(u32, @intCast(errUnionErrorOffset(pl_ty, mod)));
6279 try func.addMemArg(.i32_load16_u, .{6279 try func.addMemArg(.i32_load16_u, .{
6280 .offset = err_union.offset() + err_offset,6280 .offset = err_union.offset() + err_offset,
6281 .alignment = Type.anyerror.abiAlignment(mod),6281 .alignment = Type.anyerror.abiAlignment(mod),
...@@ -6300,7 +6300,7 @@ fn lowerTry(...@@ -6300,7 +6300,7 @@ fn lowerTry(
6300 return WValue{ .none = {} };6300 return WValue{ .none = {} };
6301 }6301 }
63026302
6303 const pl_offset = @intCast(u32, errUnionPayloadOffset(pl_ty, mod));6303 const pl_offset = @as(u32, @intCast(errUnionPayloadOffset(pl_ty, mod)));
6304 if (isByRef(pl_ty, mod)) {6304 if (isByRef(pl_ty, mod)) {
6305 return buildPointerOffset(func, err_union, pl_offset, .new);6305 return buildPointerOffset(func, err_union, pl_offset, .new);
6306 }6306 }
...@@ -6590,9 +6590,9 @@ fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {...@@ -6590,9 +6590,9 @@ fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
6590 var bin_result = try (try func.binOp(lhs, rhs, ty, op)).toLocal(func, ty);6590 var bin_result = try (try func.binOp(lhs, rhs, ty, op)).toLocal(func, ty);
6591 defer bin_result.free(func);6591 defer bin_result.free(func);
6592 if (wasm_bits != int_info.bits and op == .add) {6592 if (wasm_bits != int_info.bits and op == .add) {
6593 const val: u64 = @intCast(u64, (@as(u65, 1) << @intCast(u7, int_info.bits)) - 1);6593 const val: u64 = @as(u64, @intCast((@as(u65, 1) << @as(u7, @intCast(int_info.bits))) - 1));
6594 const imm_val = switch (wasm_bits) {6594 const imm_val = switch (wasm_bits) {
6595 32 => WValue{ .imm32 = @intCast(u32, val) },6595 32 => WValue{ .imm32 = @as(u32, @intCast(val)) },
6596 64 => WValue{ .imm64 = val },6596 64 => WValue{ .imm64 = val },
6597 else => unreachable,6597 else => unreachable,
6598 };6598 };
...@@ -6603,7 +6603,7 @@ fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {...@@ -6603,7 +6603,7 @@ fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
6603 } else {6603 } else {
6604 switch (wasm_bits) {6604 switch (wasm_bits) {
6605 32 => try func.addImm32(if (op == .add) @as(i32, -1) else 0),6605 32 => try func.addImm32(if (op == .add) @as(i32, -1) else 0),
6606 64 => try func.addImm64(if (op == .add) @bitCast(u64, @as(i64, -1)) else 0),6606 64 => try func.addImm64(if (op == .add) @as(u64, @bitCast(@as(i64, -1))) else 0),
6607 else => unreachable,6607 else => unreachable,
6608 }6608 }
6609 try func.emitWValue(bin_result);6609 try func.emitWValue(bin_result);
...@@ -6629,16 +6629,16 @@ fn signedSat(func: *CodeGen, lhs_operand: WValue, rhs_operand: WValue, ty: Type,...@@ -6629,16 +6629,16 @@ fn signedSat(func: *CodeGen, lhs_operand: WValue, rhs_operand: WValue, ty: Type,
6629 break :rhs try (try func.signAbsValue(rhs_operand, ty)).toLocal(func, ty);6629 break :rhs try (try func.signAbsValue(rhs_operand, ty)).toLocal(func, ty);
6630 } else rhs_operand;6630 } else rhs_operand;
66316631
6632 const max_val: u64 = @intCast(u64, (@as(u65, 1) << @intCast(u7, int_info.bits - 1)) - 1);6632 const max_val: u64 = @as(u64, @intCast((@as(u65, 1) << @as(u7, @intCast(int_info.bits - 1))) - 1));
6633 const min_val: i64 = (-@intCast(i64, @intCast(u63, max_val))) - 1;6633 const min_val: i64 = (-@as(i64, @intCast(@as(u63, @intCast(max_val))))) - 1;
6634 const max_wvalue = switch (wasm_bits) {6634 const max_wvalue = switch (wasm_bits) {
6635 32 => WValue{ .imm32 = @truncate(u32, max_val) },6635 32 => WValue{ .imm32 = @as(u32, @truncate(max_val)) },
6636 64 => WValue{ .imm64 = max_val },6636 64 => WValue{ .imm64 = max_val },
6637 else => unreachable,6637 else => unreachable,
6638 };6638 };
6639 const min_wvalue = switch (wasm_bits) {6639 const min_wvalue = switch (wasm_bits) {
6640 32 => WValue{ .imm32 = @bitCast(u32, @truncate(i32, min_val)) },6640 32 => WValue{ .imm32 = @as(u32, @bitCast(@as(i32, @truncate(min_val)))) },
6641 64 => WValue{ .imm64 = @bitCast(u64, min_val) },6641 64 => WValue{ .imm64 = @as(u64, @bitCast(min_val)) },
6642 else => unreachable,6642 else => unreachable,
6643 };6643 };
66446644
...@@ -6715,11 +6715,11 @@ fn airShlSat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6715,11 +6715,11 @@ fn airShlSat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6715 },6715 },
6716 64 => blk: {6716 64 => blk: {
6717 if (!is_signed) {6717 if (!is_signed) {
6718 try func.addImm64(@bitCast(u64, @as(i64, -1)));6718 try func.addImm64(@as(u64, @bitCast(@as(i64, -1))));
6719 break :blk;6719 break :blk;
6720 }6720 }
6721 try func.addImm64(@bitCast(u64, @as(i64, std.math.minInt(i64))));6721 try func.addImm64(@as(u64, @bitCast(@as(i64, std.math.minInt(i64)))));
6722 try func.addImm64(@bitCast(u64, @as(i64, std.math.maxInt(i64))));6722 try func.addImm64(@as(u64, @bitCast(@as(i64, std.math.maxInt(i64)))));
6723 _ = try func.cmp(lhs, .{ .imm64 = 0 }, ty, .lt);6723 _ = try func.cmp(lhs, .{ .imm64 = 0 }, ty, .lt);
6724 try func.addTag(.select);6724 try func.addTag(.select);
6725 },6725 },
...@@ -6759,12 +6759,12 @@ fn airShlSat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6759,12 +6759,12 @@ fn airShlSat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6759 },6759 },
6760 64 => blk: {6760 64 => blk: {
6761 if (!is_signed) {6761 if (!is_signed) {
6762 try func.addImm64(@bitCast(u64, @as(i64, -1)));6762 try func.addImm64(@as(u64, @bitCast(@as(i64, -1))));
6763 break :blk;6763 break :blk;
6764 }6764 }
67656765
6766 try func.addImm64(@bitCast(u64, @as(i64, std.math.minInt(i64))));6766 try func.addImm64(@as(u64, @bitCast(@as(i64, std.math.minInt(i64)))));
6767 try func.addImm64(@bitCast(u64, @as(i64, std.math.maxInt(i64))));6767 try func.addImm64(@as(u64, @bitCast(@as(i64, std.math.maxInt(i64)))));
6768 _ = try func.cmp(shl_res, .{ .imm64 = 0 }, ty, .lt);6768 _ = try func.cmp(shl_res, .{ .imm64 = 0 }, ty, .lt);
6769 try func.addTag(.select);6769 try func.addTag(.select);
6770 },6770 },
...@@ -6894,7 +6894,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {...@@ -6894,7 +6894,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
6894 // TODO: Make switch implementation generic so we can use a jump table for this when the tags are not sparse.6894 // TODO: Make switch implementation generic so we can use a jump table for this when the tags are not sparse.
6895 // generate an if-else chain for each tag value as well as constant.6895 // generate an if-else chain for each tag value as well as constant.
6896 for (enum_ty.enumFields(mod), 0..) |tag_name_ip, field_index_usize| {6896 for (enum_ty.enumFields(mod), 0..) |tag_name_ip, field_index_usize| {
6897 const field_index = @intCast(u32, field_index_usize);6897 const field_index = @as(u32, @intCast(field_index_usize));
6898 const tag_name = mod.intern_pool.stringToSlice(tag_name_ip);6898 const tag_name = mod.intern_pool.stringToSlice(tag_name_ip);
6899 // for each tag name, create an unnamed const,6899 // for each tag name, create an unnamed const,
6900 // and then get a pointer to its value.6900 // and then get a pointer to its value.
...@@ -6953,7 +6953,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {...@@ -6953,7 +6953,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
6953 try writer.writeByte(std.wasm.opcode(.i32_const));6953 try writer.writeByte(std.wasm.opcode(.i32_const));
6954 try relocs.append(.{6954 try relocs.append(.{
6955 .relocation_type = .R_WASM_MEMORY_ADDR_LEB,6955 .relocation_type = .R_WASM_MEMORY_ADDR_LEB,
6956 .offset = @intCast(u32, body_list.items.len),6956 .offset = @as(u32, @intCast(body_list.items.len)),
6957 .index = tag_sym_index,6957 .index = tag_sym_index,
6958 });6958 });
6959 try writer.writeAll(&[_]u8{0} ** 5); // will be relocated6959 try writer.writeAll(&[_]u8{0} ** 5); // will be relocated
...@@ -6965,7 +6965,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {...@@ -6965,7 +6965,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
69656965
6966 // store length6966 // store length
6967 try writer.writeByte(std.wasm.opcode(.i32_const));6967 try writer.writeByte(std.wasm.opcode(.i32_const));
6968 try leb.writeULEB128(writer, @intCast(u32, tag_name.len));6968 try leb.writeULEB128(writer, @as(u32, @intCast(tag_name.len)));
6969 try writer.writeByte(std.wasm.opcode(.i32_store));6969 try writer.writeByte(std.wasm.opcode(.i32_store));
6970 try leb.writeULEB128(writer, encoded_alignment);6970 try leb.writeULEB128(writer, encoded_alignment);
6971 try leb.writeULEB128(writer, @as(u32, 4));6971 try leb.writeULEB128(writer, @as(u32, 4));
...@@ -6974,7 +6974,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {...@@ -6974,7 +6974,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
6974 try writer.writeByte(std.wasm.opcode(.i64_const));6974 try writer.writeByte(std.wasm.opcode(.i64_const));
6975 try relocs.append(.{6975 try relocs.append(.{
6976 .relocation_type = .R_WASM_MEMORY_ADDR_LEB64,6976 .relocation_type = .R_WASM_MEMORY_ADDR_LEB64,
6977 .offset = @intCast(u32, body_list.items.len),6977 .offset = @as(u32, @intCast(body_list.items.len)),
6978 .index = tag_sym_index,6978 .index = tag_sym_index,
6979 });6979 });
6980 try writer.writeAll(&[_]u8{0} ** 10); // will be relocated6980 try writer.writeAll(&[_]u8{0} ** 10); // will be relocated
...@@ -6986,7 +6986,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {...@@ -6986,7 +6986,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
69866986
6987 // store length6987 // store length
6988 try writer.writeByte(std.wasm.opcode(.i64_const));6988 try writer.writeByte(std.wasm.opcode(.i64_const));
6989 try leb.writeULEB128(writer, @intCast(u64, tag_name.len));6989 try leb.writeULEB128(writer, @as(u64, @intCast(tag_name.len)));
6990 try writer.writeByte(std.wasm.opcode(.i64_store));6990 try writer.writeByte(std.wasm.opcode(.i64_store));
6991 try leb.writeULEB128(writer, encoded_alignment);6991 try leb.writeULEB128(writer, encoded_alignment);
6992 try leb.writeULEB128(writer, @as(u32, 8));6992 try leb.writeULEB128(writer, @as(u32, 8));
...@@ -7026,7 +7026,7 @@ fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7026,7 +7026,7 @@ fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7026 var lowest: ?u32 = null;7026 var lowest: ?u32 = null;
7027 var highest: ?u32 = null;7027 var highest: ?u32 = null;
7028 for (names) |name| {7028 for (names) |name| {
7029 const err_int = @intCast(Module.ErrorInt, mod.global_error_set.getIndex(name).?);7029 const err_int = @as(Module.ErrorInt, @intCast(mod.global_error_set.getIndex(name).?));
7030 if (lowest) |*l| {7030 if (lowest) |*l| {
7031 if (err_int < l.*) {7031 if (err_int < l.*) {
7032 l.* = err_int;7032 l.* = err_int;
...@@ -7054,11 +7054,11 @@ fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7054,11 +7054,11 @@ fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
70547054
7055 // lower operand to determine jump table target7055 // lower operand to determine jump table target
7056 try func.emitWValue(operand);7056 try func.emitWValue(operand);
7057 try func.addImm32(@intCast(i32, lowest.?));7057 try func.addImm32(@as(i32, @intCast(lowest.?)));
7058 try func.addTag(.i32_sub);7058 try func.addTag(.i32_sub);
70597059
7060 // Account for default branch so always add '1'7060 // Account for default branch so always add '1'
7061 const depth = @intCast(u32, highest.? - lowest.? + 1);7061 const depth = @as(u32, @intCast(highest.? - lowest.? + 1));
7062 const jump_table: Mir.JumpTable = .{ .length = depth };7062 const jump_table: Mir.JumpTable = .{ .length = depth };
7063 const table_extra_index = try func.addExtra(jump_table);7063 const table_extra_index = try func.addExtra(jump_table);
7064 try func.addInst(.{ .tag = .br_table, .data = .{ .payload = table_extra_index } });7064 try func.addInst(.{ .tag = .br_table, .data = .{ .payload = table_extra_index } });
...@@ -7155,7 +7155,7 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7155,7 +7155,7 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7155 try func.addTag(.i32_and);7155 try func.addTag(.i32_and);
7156 const and_result = try WValue.toLocal(.stack, func, Type.bool);7156 const and_result = try WValue.toLocal(.stack, func, Type.bool);
7157 const result_ptr = try func.allocStack(result_ty);7157 const result_ptr = try func.allocStack(result_ty);
7158 try func.store(result_ptr, and_result, Type.bool, @intCast(u32, ty.abiSize(mod)));7158 try func.store(result_ptr, and_result, Type.bool, @as(u32, @intCast(ty.abiSize(mod))));
7159 try func.store(result_ptr, ptr_val, ty, 0);7159 try func.store(result_ptr, ptr_val, ty, 0);
7160 break :val result_ptr;7160 break :val result_ptr;
7161 } else val: {7161 } else val: {
...@@ -7221,13 +7221,13 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7221,13 +7221,13 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7221 try func.emitWValue(ptr);7221 try func.emitWValue(ptr);
7222 try func.emitWValue(value);7222 try func.emitWValue(value);
7223 if (op == .Nand) {7223 if (op == .Nand) {
7224 const wasm_bits = toWasmBits(@intCast(u16, ty.bitSize(mod))).?;7224 const wasm_bits = toWasmBits(@as(u16, @intCast(ty.bitSize(mod)))).?;
72257225
7226 const and_res = try func.binOp(value, operand, ty, .@"and");7226 const and_res = try func.binOp(value, operand, ty, .@"and");
7227 if (wasm_bits == 32)7227 if (wasm_bits == 32)
7228 try func.addImm32(-1)7228 try func.addImm32(-1)
7229 else if (wasm_bits == 64)7229 else if (wasm_bits == 64)
7230 try func.addImm64(@bitCast(u64, @as(i64, -1)))7230 try func.addImm64(@as(u64, @bitCast(@as(i64, -1))))
7231 else7231 else
7232 return func.fail("TODO: `@atomicRmw` with operator `Nand` for types larger than 64 bits", .{});7232 return func.fail("TODO: `@atomicRmw` with operator `Nand` for types larger than 64 bits", .{});
7233 _ = try func.binOp(and_res, .stack, ty, .xor);7233 _ = try func.binOp(and_res, .stack, ty, .xor);
...@@ -7352,14 +7352,14 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7352,14 +7352,14 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7352 try func.store(.stack, .stack, ty, ptr.offset());7352 try func.store(.stack, .stack, ty, ptr.offset());
7353 },7353 },
7354 .Nand => {7354 .Nand => {
7355 const wasm_bits = toWasmBits(@intCast(u16, ty.bitSize(mod))).?;7355 const wasm_bits = toWasmBits(@as(u16, @intCast(ty.bitSize(mod)))).?;
73567356
7357 try func.emitWValue(ptr);7357 try func.emitWValue(ptr);
7358 const and_res = try func.binOp(result, operand, ty, .@"and");7358 const and_res = try func.binOp(result, operand, ty, .@"and");
7359 if (wasm_bits == 32)7359 if (wasm_bits == 32)
7360 try func.addImm32(-1)7360 try func.addImm32(-1)
7361 else if (wasm_bits == 64)7361 else if (wasm_bits == 64)
7362 try func.addImm64(@bitCast(u64, @as(i64, -1)))7362 try func.addImm64(@as(u64, @bitCast(@as(i64, -1))))
7363 else7363 else
7364 return func.fail("TODO: `@atomicRmw` with operator `Nand` for types larger than 64 bits", .{});7364 return func.fail("TODO: `@atomicRmw` with operator `Nand` for types larger than 64 bits", .{});
7365 _ = try func.binOp(and_res, .stack, ty, .xor);7365 _ = try func.binOp(and_res, .stack, ty, .xor);
src/arch/wasm/Emit.zig+11-11
...@@ -45,7 +45,7 @@ pub fn emitMir(emit: *Emit) InnerError!void {...@@ -45,7 +45,7 @@ pub fn emitMir(emit: *Emit) InnerError!void {
45 try emit.emitLocals();45 try emit.emitLocals();
4646
47 for (mir_tags, 0..) |tag, index| {47 for (mir_tags, 0..) |tag, index| {
48 const inst = @intCast(u32, index);48 const inst = @as(u32, @intCast(index));
49 switch (tag) {49 switch (tag) {
50 // block instructions50 // block instructions
51 .block => try emit.emitBlock(tag, inst),51 .block => try emit.emitBlock(tag, inst),
...@@ -247,7 +247,7 @@ pub fn emitMir(emit: *Emit) InnerError!void {...@@ -247,7 +247,7 @@ pub fn emitMir(emit: *Emit) InnerError!void {
247}247}
248248
249fn offset(self: Emit) u32 {249fn offset(self: Emit) u32 {
250 return @intCast(u32, self.code.items.len);250 return @as(u32, @intCast(self.code.items.len));
251}251}
252252
253fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {253fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
...@@ -260,7 +260,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {...@@ -260,7 +260,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
260260
261fn emitLocals(emit: *Emit) !void {261fn emitLocals(emit: *Emit) !void {
262 const writer = emit.code.writer();262 const writer = emit.code.writer();
263 try leb128.writeULEB128(writer, @intCast(u32, emit.locals.len));263 try leb128.writeULEB128(writer, @as(u32, @intCast(emit.locals.len)));
264 // emit the actual locals amount264 // emit the actual locals amount
265 for (emit.locals) |local| {265 for (emit.locals) |local| {
266 try leb128.writeULEB128(writer, @as(u32, 1));266 try leb128.writeULEB128(writer, @as(u32, 1));
...@@ -324,13 +324,13 @@ fn emitImm64(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -324,13 +324,13 @@ fn emitImm64(emit: *Emit, inst: Mir.Inst.Index) !void {
324 const extra_index = emit.mir.instructions.items(.data)[inst].payload;324 const extra_index = emit.mir.instructions.items(.data)[inst].payload;
325 const value = emit.mir.extraData(Mir.Imm64, extra_index);325 const value = emit.mir.extraData(Mir.Imm64, extra_index);
326 try emit.code.append(std.wasm.opcode(.i64_const));326 try emit.code.append(std.wasm.opcode(.i64_const));
327 try leb128.writeILEB128(emit.code.writer(), @bitCast(i64, value.data.toU64()));327 try leb128.writeILEB128(emit.code.writer(), @as(i64, @bitCast(value.data.toU64())));
328}328}
329329
330fn emitFloat32(emit: *Emit, inst: Mir.Inst.Index) !void {330fn emitFloat32(emit: *Emit, inst: Mir.Inst.Index) !void {
331 const value: f32 = emit.mir.instructions.items(.data)[inst].float32;331 const value: f32 = emit.mir.instructions.items(.data)[inst].float32;
332 try emit.code.append(std.wasm.opcode(.f32_const));332 try emit.code.append(std.wasm.opcode(.f32_const));
333 try emit.code.writer().writeIntLittle(u32, @bitCast(u32, value));333 try emit.code.writer().writeIntLittle(u32, @as(u32, @bitCast(value)));
334}334}
335335
336fn emitFloat64(emit: *Emit, inst: Mir.Inst.Index) !void {336fn emitFloat64(emit: *Emit, inst: Mir.Inst.Index) !void {
...@@ -425,7 +425,7 @@ fn emitMemAddress(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -425,7 +425,7 @@ fn emitMemAddress(emit: *Emit, inst: Mir.Inst.Index) !void {
425 .offset = mem_offset,425 .offset = mem_offset,
426 .index = mem.pointer,426 .index = mem.pointer,
427 .relocation_type = if (is_wasm32) .R_WASM_MEMORY_ADDR_LEB else .R_WASM_MEMORY_ADDR_LEB64,427 .relocation_type = if (is_wasm32) .R_WASM_MEMORY_ADDR_LEB else .R_WASM_MEMORY_ADDR_LEB64,
428 .addend = @intCast(i32, mem.offset),428 .addend = @as(i32, @intCast(mem.offset)),
429 });429 });
430 }430 }
431}431}
...@@ -436,7 +436,7 @@ fn emitExtended(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -436,7 +436,7 @@ fn emitExtended(emit: *Emit, inst: Mir.Inst.Index) !void {
436 const writer = emit.code.writer();436 const writer = emit.code.writer();
437 try emit.code.append(std.wasm.opcode(.misc_prefix));437 try emit.code.append(std.wasm.opcode(.misc_prefix));
438 try leb128.writeULEB128(writer, opcode);438 try leb128.writeULEB128(writer, opcode);
439 switch (@enumFromInt(std.wasm.MiscOpcode, opcode)) {439 switch (@as(std.wasm.MiscOpcode, @enumFromInt(opcode))) {
440 // bulk-memory opcodes440 // bulk-memory opcodes
441 .data_drop => {441 .data_drop => {
442 const segment = emit.mir.extra[extra_index + 1];442 const segment = emit.mir.extra[extra_index + 1];
...@@ -475,7 +475,7 @@ fn emitSimd(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -475,7 +475,7 @@ fn emitSimd(emit: *Emit, inst: Mir.Inst.Index) !void {
475 const writer = emit.code.writer();475 const writer = emit.code.writer();
476 try emit.code.append(std.wasm.opcode(.simd_prefix));476 try emit.code.append(std.wasm.opcode(.simd_prefix));
477 try leb128.writeULEB128(writer, opcode);477 try leb128.writeULEB128(writer, opcode);
478 switch (@enumFromInt(std.wasm.SimdOpcode, opcode)) {478 switch (@as(std.wasm.SimdOpcode, @enumFromInt(opcode))) {
479 .v128_store,479 .v128_store,
480 .v128_load,480 .v128_load,
481 .v128_load8_splat,481 .v128_load8_splat,
...@@ -507,7 +507,7 @@ fn emitSimd(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -507,7 +507,7 @@ fn emitSimd(emit: *Emit, inst: Mir.Inst.Index) !void {
507 .f64x2_extract_lane,507 .f64x2_extract_lane,
508 .f64x2_replace_lane,508 .f64x2_replace_lane,
509 => {509 => {
510 try writer.writeByte(@intCast(u8, emit.mir.extra[extra_index + 1]));510 try writer.writeByte(@as(u8, @intCast(emit.mir.extra[extra_index + 1])));
511 },511 },
512 .i8x16_splat,512 .i8x16_splat,
513 .i16x8_splat,513 .i16x8_splat,
...@@ -526,7 +526,7 @@ fn emitAtomic(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -526,7 +526,7 @@ fn emitAtomic(emit: *Emit, inst: Mir.Inst.Index) !void {
526 const writer = emit.code.writer();526 const writer = emit.code.writer();
527 try emit.code.append(std.wasm.opcode(.atomics_prefix));527 try emit.code.append(std.wasm.opcode(.atomics_prefix));
528 try leb128.writeULEB128(writer, opcode);528 try leb128.writeULEB128(writer, opcode);
529 switch (@enumFromInt(std.wasm.AtomicsOpcode, opcode)) {529 switch (@as(std.wasm.AtomicsOpcode, @enumFromInt(opcode))) {
530 .i32_atomic_load,530 .i32_atomic_load,
531 .i64_atomic_load,531 .i64_atomic_load,
532 .i32_atomic_load8_u,532 .i32_atomic_load8_u,
...@@ -623,7 +623,7 @@ fn emitDbgLine(emit: *Emit, inst: Mir.Inst.Index) !void {...@@ -623,7 +623,7 @@ fn emitDbgLine(emit: *Emit, inst: Mir.Inst.Index) !void {
623fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) !void {623fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) !void {
624 if (emit.dbg_output != .dwarf) return;624 if (emit.dbg_output != .dwarf) return;
625625
626 const delta_line = @intCast(i32, line) - @intCast(i32, emit.prev_di_line);626 const delta_line = @as(i32, @intCast(line)) - @as(i32, @intCast(emit.prev_di_line));
627 const delta_pc = emit.offset() - emit.prev_di_offset;627 const delta_pc = emit.offset() - emit.prev_di_offset;
628 // TODO: This must emit a relocation to calculate the offset relative628 // TODO: This must emit a relocation to calculate the offset relative
629 // to the code section start.629 // to the code section start.
src/arch/wasm/Mir.zig+8-8
...@@ -544,12 +544,12 @@ pub const Inst = struct {...@@ -544,12 +544,12 @@ pub const Inst = struct {
544544
545 /// From a given wasm opcode, returns a MIR tag.545 /// From a given wasm opcode, returns a MIR tag.
546 pub fn fromOpcode(opcode: std.wasm.Opcode) Tag {546 pub fn fromOpcode(opcode: std.wasm.Opcode) Tag {
547 return @enumFromInt(Tag, @intFromEnum(opcode)); // Given `Opcode` is not present as a tag for MIR yet547 return @as(Tag, @enumFromInt(@intFromEnum(opcode))); // Given `Opcode` is not present as a tag for MIR yet
548 }548 }
549549
550 /// Returns a wasm opcode from a given MIR tag.550 /// Returns a wasm opcode from a given MIR tag.
551 pub fn toOpcode(self: Tag) std.wasm.Opcode {551 pub fn toOpcode(self: Tag) std.wasm.Opcode {
552 return @enumFromInt(std.wasm.Opcode, @intFromEnum(self));552 return @as(std.wasm.Opcode, @enumFromInt(@intFromEnum(self)));
553 }553 }
554 };554 };
555555
...@@ -621,8 +621,8 @@ pub const Imm64 = struct {...@@ -621,8 +621,8 @@ pub const Imm64 = struct {
621621
622 pub fn fromU64(imm: u64) Imm64 {622 pub fn fromU64(imm: u64) Imm64 {
623 return .{623 return .{
624 .msb = @truncate(u32, imm >> 32),624 .msb = @as(u32, @truncate(imm >> 32)),
625 .lsb = @truncate(u32, imm),625 .lsb = @as(u32, @truncate(imm)),
626 };626 };
627 }627 }
628628
...@@ -639,15 +639,15 @@ pub const Float64 = struct {...@@ -639,15 +639,15 @@ pub const Float64 = struct {
639 lsb: u32,639 lsb: u32,
640640
641 pub fn fromFloat64(float: f64) Float64 {641 pub fn fromFloat64(float: f64) Float64 {
642 const tmp = @bitCast(u64, float);642 const tmp = @as(u64, @bitCast(float));
643 return .{643 return .{
644 .msb = @truncate(u32, tmp >> 32),644 .msb = @as(u32, @truncate(tmp >> 32)),
645 .lsb = @truncate(u32, tmp),645 .lsb = @as(u32, @truncate(tmp)),
646 };646 };
647 }647 }
648648
649 pub fn toF64(self: Float64) f64 {649 pub fn toF64(self: Float64) f64 {
650 @bitCast(f64, self.toU64());650 @as(f64, @bitCast(self.toU64()));
651 }651 }
652652
653 pub fn toU64(self: Float64) u64 {653 pub fn toU64(self: Float64) u64 {
src/arch/x86_64/CodeGen.zig+229-229
...@@ -329,7 +329,7 @@ pub const MCValue = union(enum) {...@@ -329,7 +329,7 @@ pub const MCValue = union(enum) {
329 .load_frame,329 .load_frame,
330 .reserved_frame,330 .reserved_frame,
331 => unreachable, // not offsettable331 => unreachable, // not offsettable
332 .immediate => |imm| .{ .immediate = @bitCast(u64, @bitCast(i64, imm) +% off) },332 .immediate => |imm| .{ .immediate = @as(u64, @bitCast(@as(i64, @bitCast(imm)) +% off)) },
333 .register => |reg| .{ .register_offset = .{ .reg = reg, .off = off } },333 .register => |reg| .{ .register_offset = .{ .reg = reg, .off = off } },
334 .register_offset => |reg_off| .{334 .register_offset => |reg_off| .{
335 .register_offset = .{ .reg = reg_off.reg, .off = reg_off.off + off },335 .register_offset = .{ .reg = reg_off.reg, .off = reg_off.off + off },
...@@ -360,7 +360,7 @@ pub const MCValue = union(enum) {...@@ -360,7 +360,7 @@ pub const MCValue = union(enum) {
360 .lea_frame,360 .lea_frame,
361 .reserved_frame,361 .reserved_frame,
362 => unreachable,362 => unreachable,
363 .memory => |addr| if (math.cast(i32, @bitCast(i64, addr))) |small_addr|363 .memory => |addr| if (math.cast(i32, @as(i64, @bitCast(addr)))) |small_addr|
364 Memory.sib(ptr_size, .{ .base = .{ .reg = .ds }, .disp = small_addr })364 Memory.sib(ptr_size, .{ .base = .{ .reg = .ds }, .disp = small_addr })
365 else365 else
366 Memory.moffs(.ds, addr),366 Memory.moffs(.ds, addr),
...@@ -606,7 +606,7 @@ const FrameAlloc = struct {...@@ -606,7 +606,7 @@ const FrameAlloc = struct {
606 fn init(alloc_abi: struct { size: u64, alignment: u32 }) FrameAlloc {606 fn init(alloc_abi: struct { size: u64, alignment: u32 }) FrameAlloc {
607 assert(math.isPowerOfTwo(alloc_abi.alignment));607 assert(math.isPowerOfTwo(alloc_abi.alignment));
608 return .{608 return .{
609 .abi_size = @intCast(u31, alloc_abi.size),609 .abi_size = @as(u31, @intCast(alloc_abi.size)),
610 .abi_align = math.log2_int(u32, alloc_abi.alignment),610 .abi_align = math.log2_int(u32, alloc_abi.alignment),
611 .ref_count = 0,611 .ref_count = 0,
612 };612 };
...@@ -694,7 +694,7 @@ pub fn generate(...@@ -694,7 +694,7 @@ pub fn generate(
694 FrameAlloc.init(.{694 FrameAlloc.init(.{
695 .size = 0,695 .size = 0,
696 .alignment = if (mod.align_stack_fns.get(module_fn_index)) |set_align_stack|696 .alignment = if (mod.align_stack_fns.get(module_fn_index)) |set_align_stack|
697 @intCast(u32, set_align_stack.alignment.toByteUnitsOptional().?)697 @as(u32, @intCast(set_align_stack.alignment.toByteUnitsOptional().?))
698 else698 else
699 1,699 1,
700 }),700 }),
...@@ -979,7 +979,7 @@ fn fmtTracking(self: *Self) std.fmt.Formatter(formatTracking) {...@@ -979,7 +979,7 @@ fn fmtTracking(self: *Self) std.fmt.Formatter(formatTracking) {
979fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {979fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
980 const gpa = self.gpa;980 const gpa = self.gpa;
981 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);981 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);
982 const result_index = @intCast(Mir.Inst.Index, self.mir_instructions.len);982 const result_index = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len));
983 self.mir_instructions.appendAssumeCapacity(inst);983 self.mir_instructions.appendAssumeCapacity(inst);
984 if (inst.tag != .pseudo or switch (inst.ops) {984 if (inst.tag != .pseudo or switch (inst.ops) {
985 else => true,985 else => true,
...@@ -1000,11 +1000,11 @@ fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {...@@ -1000,11 +1000,11 @@ fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {
10001000
1001fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {1001fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
1002 const fields = std.meta.fields(@TypeOf(extra));1002 const fields = std.meta.fields(@TypeOf(extra));
1003 const result = @intCast(u32, self.mir_extra.items.len);1003 const result = @as(u32, @intCast(self.mir_extra.items.len));
1004 inline for (fields) |field| {1004 inline for (fields) |field| {
1005 self.mir_extra.appendAssumeCapacity(switch (field.type) {1005 self.mir_extra.appendAssumeCapacity(switch (field.type) {
1006 u32 => @field(extra, field.name),1006 u32 => @field(extra, field.name),
1007 i32 => @bitCast(u32, @field(extra, field.name)),1007 i32 => @as(u32, @bitCast(@field(extra, field.name))),
1008 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),1008 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
1009 });1009 });
1010 }1010 }
...@@ -1214,8 +1214,8 @@ fn asmImmediate(self: *Self, tag: Mir.Inst.FixedTag, imm: Immediate) !void {...@@ -1214,8 +1214,8 @@ fn asmImmediate(self: *Self, tag: Mir.Inst.FixedTag, imm: Immediate) !void {
1214 .data = .{ .i = .{1214 .data = .{ .i = .{
1215 .fixes = tag[0],1215 .fixes = tag[0],
1216 .i = switch (imm) {1216 .i = switch (imm) {
1217 .signed => |s| @bitCast(u32, s),1217 .signed => |s| @as(u32, @bitCast(s)),
1218 .unsigned => |u| @intCast(u32, u),1218 .unsigned => |u| @as(u32, @intCast(u)),
1219 },1219 },
1220 } },1220 } },
1221 });1221 });
...@@ -1246,8 +1246,8 @@ fn asmRegisterImmediate(self: *Self, tag: Mir.Inst.FixedTag, reg: Register, imm:...@@ -1246,8 +1246,8 @@ fn asmRegisterImmediate(self: *Self, tag: Mir.Inst.FixedTag, reg: Register, imm:
1246 .fixes = tag[0],1246 .fixes = tag[0],
1247 .r1 = reg,1247 .r1 = reg,
1248 .i = switch (imm) {1248 .i = switch (imm) {
1249 .signed => |s| @bitCast(u32, s),1249 .signed => |s| @as(u32, @bitCast(s)),
1250 .unsigned => |u| @intCast(u32, u),1250 .unsigned => |u| @as(u32, @intCast(u)),
1251 },1251 },
1252 } },1252 } },
1253 .ri64 => .{ .rx = .{1253 .ri64 => .{ .rx = .{
...@@ -1316,7 +1316,7 @@ fn asmRegisterRegisterRegisterImmediate(...@@ -1316,7 +1316,7 @@ fn asmRegisterRegisterRegisterImmediate(
1316 .r1 = reg1,1316 .r1 = reg1,
1317 .r2 = reg2,1317 .r2 = reg2,
1318 .r3 = reg3,1318 .r3 = reg3,
1319 .i = @intCast(u8, imm.unsigned),1319 .i = @as(u8, @intCast(imm.unsigned)),
1320 } },1320 } },
1321 });1321 });
1322}1322}
...@@ -1339,8 +1339,8 @@ fn asmRegisterRegisterImmediate(...@@ -1339,8 +1339,8 @@ fn asmRegisterRegisterImmediate(
1339 .r1 = reg1,1339 .r1 = reg1,
1340 .r2 = reg2,1340 .r2 = reg2,
1341 .i = switch (imm) {1341 .i = switch (imm) {
1342 .signed => |s| @bitCast(u32, s),1342 .signed => |s| @as(u32, @bitCast(s)),
1343 .unsigned => |u| @intCast(u32, u),1343 .unsigned => |u| @as(u32, @intCast(u)),
1344 },1344 },
1345 } },1345 } },
1346 });1346 });
...@@ -1429,7 +1429,7 @@ fn asmRegisterMemoryImmediate(...@@ -1429,7 +1429,7 @@ fn asmRegisterMemoryImmediate(
1429 .data = .{ .rix = .{1429 .data = .{ .rix = .{
1430 .fixes = tag[0],1430 .fixes = tag[0],
1431 .r1 = reg,1431 .r1 = reg,
1432 .i = @intCast(u8, imm.unsigned),1432 .i = @as(u8, @intCast(imm.unsigned)),
1433 .payload = switch (m) {1433 .payload = switch (m) {
1434 .sib => try self.addExtra(Mir.MemorySib.encode(m)),1434 .sib => try self.addExtra(Mir.MemorySib.encode(m)),
1435 .rip => try self.addExtra(Mir.MemoryRip.encode(m)),1435 .rip => try self.addExtra(Mir.MemoryRip.encode(m)),
...@@ -1458,7 +1458,7 @@ fn asmRegisterRegisterMemoryImmediate(...@@ -1458,7 +1458,7 @@ fn asmRegisterRegisterMemoryImmediate(
1458 .fixes = tag[0],1458 .fixes = tag[0],
1459 .r1 = reg1,1459 .r1 = reg1,
1460 .r2 = reg2,1460 .r2 = reg2,
1461 .i = @intCast(u8, imm.unsigned),1461 .i = @as(u8, @intCast(imm.unsigned)),
1462 .payload = switch (m) {1462 .payload = switch (m) {
1463 .sib => try self.addExtra(Mir.MemorySib.encode(m)),1463 .sib => try self.addExtra(Mir.MemorySib.encode(m)),
1464 .rip => try self.addExtra(Mir.MemoryRip.encode(m)),1464 .rip => try self.addExtra(Mir.MemoryRip.encode(m)),
...@@ -1490,8 +1490,8 @@ fn asmMemoryRegister(self: *Self, tag: Mir.Inst.FixedTag, m: Memory, reg: Regist...@@ -1490,8 +1490,8 @@ fn asmMemoryRegister(self: *Self, tag: Mir.Inst.FixedTag, m: Memory, reg: Regist
14901490
1491fn asmMemoryImmediate(self: *Self, tag: Mir.Inst.FixedTag, m: Memory, imm: Immediate) !void {1491fn asmMemoryImmediate(self: *Self, tag: Mir.Inst.FixedTag, m: Memory, imm: Immediate) !void {
1492 const payload = try self.addExtra(Mir.Imm32{ .imm = switch (imm) {1492 const payload = try self.addExtra(Mir.Imm32{ .imm = switch (imm) {
1493 .signed => |s| @bitCast(u32, s),1493 .signed => |s| @as(u32, @bitCast(s)),
1494 .unsigned => |u| @intCast(u32, u),1494 .unsigned => |u| @as(u32, @intCast(u)),
1495 } });1495 } });
1496 assert(payload + 1 == switch (m) {1496 assert(payload + 1 == switch (m) {
1497 .sib => try self.addExtra(Mir.MemorySib.encode(m)),1497 .sib => try self.addExtra(Mir.MemorySib.encode(m)),
...@@ -1562,7 +1562,7 @@ fn asmMemoryRegisterImmediate(...@@ -1562,7 +1562,7 @@ fn asmMemoryRegisterImmediate(
1562 .data = .{ .rix = .{1562 .data = .{ .rix = .{
1563 .fixes = tag[0],1563 .fixes = tag[0],
1564 .r1 = reg,1564 .r1 = reg,
1565 .i = @intCast(u8, imm.unsigned),1565 .i = @as(u8, @intCast(imm.unsigned)),
1566 .payload = switch (m) {1566 .payload = switch (m) {
1567 .sib => try self.addExtra(Mir.MemorySib.encode(m)),1567 .sib => try self.addExtra(Mir.MemorySib.encode(m)),
1568 .rip => try self.addExtra(Mir.MemoryRip.encode(m)),1568 .rip => try self.addExtra(Mir.MemoryRip.encode(m)),
...@@ -1617,7 +1617,7 @@ fn gen(self: *Self) InnerError!void {...@@ -1617,7 +1617,7 @@ fn gen(self: *Self) InnerError!void {
1617 // Eliding the reloc will cause a miscompilation in this case.1617 // Eliding the reloc will cause a miscompilation in this case.
1618 for (self.exitlude_jump_relocs.items) |jmp_reloc| {1618 for (self.exitlude_jump_relocs.items) |jmp_reloc| {
1619 self.mir_instructions.items(.data)[jmp_reloc].inst.inst =1619 self.mir_instructions.items(.data)[jmp_reloc].inst.inst =
1620 @intCast(u32, self.mir_instructions.len);1620 @as(u32, @intCast(self.mir_instructions.len));
1621 }1621 }
16221622
1623 try self.asmPseudo(.pseudo_dbg_epilogue_begin_none);1623 try self.asmPseudo(.pseudo_dbg_epilogue_begin_none);
...@@ -1739,7 +1739,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -1739,7 +1739,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
17391739
1740 for (body) |inst| {1740 for (body) |inst| {
1741 if (builtin.mode == .Debug) {1741 if (builtin.mode == .Debug) {
1742 const mir_inst = @intCast(Mir.Inst.Index, self.mir_instructions.len);1742 const mir_inst = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len));
1743 try self.mir_to_air_map.put(self.gpa, mir_inst, inst);1743 try self.mir_to_air_map.put(self.gpa, mir_inst, inst);
1744 }1744 }
17451745
...@@ -2032,7 +2032,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {...@@ -2032,7 +2032,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {
20322032
2033 var data_off: i32 = 0;2033 var data_off: i32 = 0;
2034 for (exitlude_jump_relocs, 0..) |*exitlude_jump_reloc, index_usize| {2034 for (exitlude_jump_relocs, 0..) |*exitlude_jump_reloc, index_usize| {
2035 const index = @intCast(u32, index_usize);2035 const index = @as(u32, @intCast(index_usize));
2036 const tag_name = mod.intern_pool.stringToSlice(enum_ty.enumFields(mod)[index_usize]);2036 const tag_name = mod.intern_pool.stringToSlice(enum_ty.enumFields(mod)[index_usize]);
2037 const tag_val = try mod.enumValueFieldIndex(enum_ty, index);2037 const tag_val = try mod.enumValueFieldIndex(enum_ty, index);
2038 const tag_mcv = try self.genTypedValue(.{ .ty = enum_ty, .val = tag_val });2038 const tag_mcv = try self.genTypedValue(.{ .ty = enum_ty, .val = tag_val });
...@@ -2050,7 +2050,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {...@@ -2050,7 +2050,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {
2050 exitlude_jump_reloc.* = try self.asmJmpReloc(undefined);2050 exitlude_jump_reloc.* = try self.asmJmpReloc(undefined);
2051 try self.performReloc(skip_reloc);2051 try self.performReloc(skip_reloc);
20522052
2053 data_off += @intCast(i32, tag_name.len + 1);2053 data_off += @as(i32, @intCast(tag_name.len + 1));
2054 }2054 }
20552055
2056 try self.airTrap();2056 try self.airTrap();
...@@ -2126,7 +2126,7 @@ fn finishAirResult(self: *Self, inst: Air.Inst.Index, result: MCValue) void {...@@ -2126,7 +2126,7 @@ fn finishAirResult(self: *Self, inst: Air.Inst.Index, result: MCValue) void {
2126fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void {2126fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void {
2127 var tomb_bits = self.liveness.getTombBits(inst);2127 var tomb_bits = self.liveness.getTombBits(inst);
2128 for (operands) |op| {2128 for (operands) |op| {
2129 const dies = @truncate(u1, tomb_bits) != 0;2129 const dies = @as(u1, @truncate(tomb_bits)) != 0;
2130 tomb_bits >>= 1;2130 tomb_bits >>= 1;
2131 if (!dies) continue;2131 if (!dies) continue;
2132 self.processDeath(Air.refToIndexAllowNone(op) orelse continue);2132 self.processDeath(Air.refToIndexAllowNone(op) orelse continue);
...@@ -2167,7 +2167,7 @@ fn computeFrameLayout(self: *Self) !FrameLayout {...@@ -2167,7 +2167,7 @@ fn computeFrameLayout(self: *Self) !FrameLayout {
2167 const frame_offset = self.frame_locs.items(.disp);2167 const frame_offset = self.frame_locs.items(.disp);
21682168
2169 for (stack_frame_order, FrameIndex.named_count..) |*frame_order, frame_index|2169 for (stack_frame_order, FrameIndex.named_count..) |*frame_order, frame_index|
2170 frame_order.* = @enumFromInt(FrameIndex, frame_index);2170 frame_order.* = @as(FrameIndex, @enumFromInt(frame_index));
2171 {2171 {
2172 const SortContext = struct {2172 const SortContext = struct {
2173 frame_align: @TypeOf(frame_align),2173 frame_align: @TypeOf(frame_align),
...@@ -2195,7 +2195,7 @@ fn computeFrameLayout(self: *Self) !FrameLayout {...@@ -2195,7 +2195,7 @@ fn computeFrameLayout(self: *Self) !FrameLayout {
2195 }2195 }
2196 }2196 }
21972197
2198 var rbp_offset = @intCast(i32, save_reg_list.count() * 8);2198 var rbp_offset = @as(i32, @intCast(save_reg_list.count() * 8));
2199 self.setFrameLoc(.base_ptr, .rbp, &rbp_offset, false);2199 self.setFrameLoc(.base_ptr, .rbp, &rbp_offset, false);
2200 self.setFrameLoc(.ret_addr, .rbp, &rbp_offset, false);2200 self.setFrameLoc(.ret_addr, .rbp, &rbp_offset, false);
2201 self.setFrameLoc(.args_frame, .rbp, &rbp_offset, false);2201 self.setFrameLoc(.args_frame, .rbp, &rbp_offset, false);
...@@ -2210,22 +2210,22 @@ fn computeFrameLayout(self: *Self) !FrameLayout {...@@ -2210,22 +2210,22 @@ fn computeFrameLayout(self: *Self) !FrameLayout {
2210 rsp_offset = mem.alignForward(i32, rsp_offset, @as(i32, 1) << needed_align);2210 rsp_offset = mem.alignForward(i32, rsp_offset, @as(i32, 1) << needed_align);
2211 rsp_offset -= stack_frame_align_offset;2211 rsp_offset -= stack_frame_align_offset;
2212 frame_size[@intFromEnum(FrameIndex.call_frame)] =2212 frame_size[@intFromEnum(FrameIndex.call_frame)] =
2213 @intCast(u31, rsp_offset - frame_offset[@intFromEnum(FrameIndex.stack_frame)]);2213 @as(u31, @intCast(rsp_offset - frame_offset[@intFromEnum(FrameIndex.stack_frame)]));
22142214
2215 return .{2215 return .{
2216 .stack_mask = @as(u32, math.maxInt(u32)) << (if (need_align_stack) needed_align else 0),2216 .stack_mask = @as(u32, math.maxInt(u32)) << (if (need_align_stack) needed_align else 0),
2217 .stack_adjust = @intCast(u32, rsp_offset - frame_offset[@intFromEnum(FrameIndex.call_frame)]),2217 .stack_adjust = @as(u32, @intCast(rsp_offset - frame_offset[@intFromEnum(FrameIndex.call_frame)])),
2218 .save_reg_list = save_reg_list,2218 .save_reg_list = save_reg_list,
2219 };2219 };
2220}2220}
22212221
2222fn getFrameAddrAlignment(self: *Self, frame_addr: FrameAddr) u32 {2222fn getFrameAddrAlignment(self: *Self, frame_addr: FrameAddr) u32 {
2223 const alloc_align = @as(u32, 1) << self.frame_allocs.get(@intFromEnum(frame_addr.index)).abi_align;2223 const alloc_align = @as(u32, 1) << self.frame_allocs.get(@intFromEnum(frame_addr.index)).abi_align;
2224 return @min(alloc_align, @bitCast(u32, frame_addr.off) & (alloc_align - 1));2224 return @min(alloc_align, @as(u32, @bitCast(frame_addr.off)) & (alloc_align - 1));
2225}2225}
22262226
2227fn getFrameAddrSize(self: *Self, frame_addr: FrameAddr) u32 {2227fn getFrameAddrSize(self: *Self, frame_addr: FrameAddr) u32 {
2228 return self.frame_allocs.get(@intFromEnum(frame_addr.index)).abi_size - @intCast(u31, frame_addr.off);2228 return self.frame_allocs.get(@intFromEnum(frame_addr.index)).abi_size - @as(u31, @intCast(frame_addr.off));
2229}2229}
22302230
2231fn allocFrameIndex(self: *Self, alloc: FrameAlloc) !FrameIndex {2231fn allocFrameIndex(self: *Self, alloc: FrameAlloc) !FrameIndex {
...@@ -2245,7 +2245,7 @@ fn allocFrameIndex(self: *Self, alloc: FrameAlloc) !FrameIndex {...@@ -2245,7 +2245,7 @@ fn allocFrameIndex(self: *Self, alloc: FrameAlloc) !FrameIndex {
2245 _ = self.free_frame_indices.swapRemoveAt(free_i);2245 _ = self.free_frame_indices.swapRemoveAt(free_i);
2246 return frame_index;2246 return frame_index;
2247 }2247 }
2248 const frame_index = @enumFromInt(FrameIndex, self.frame_allocs.len);2248 const frame_index = @as(FrameIndex, @enumFromInt(self.frame_allocs.len));
2249 try self.frame_allocs.append(self.gpa, alloc);2249 try self.frame_allocs.append(self.gpa, alloc);
2250 return frame_index;2250 return frame_index;
2251}2251}
...@@ -2321,7 +2321,7 @@ const State = struct {...@@ -2321,7 +2321,7 @@ const State = struct {
23212321
2322fn initRetroactiveState(self: *Self) State {2322fn initRetroactiveState(self: *Self) State {
2323 var state: State = undefined;2323 var state: State = undefined;
2324 state.inst_tracking_len = @intCast(u32, self.inst_tracking.count());2324 state.inst_tracking_len = @as(u32, @intCast(self.inst_tracking.count()));
2325 state.scope_generation = self.scope_generation;2325 state.scope_generation = self.scope_generation;
2326 return state;2326 return state;
2327}2327}
...@@ -2393,7 +2393,7 @@ fn restoreState(self: *Self, state: State, deaths: []const Air.Inst.Index, compt...@@ -2393,7 +2393,7 @@ fn restoreState(self: *Self, state: State, deaths: []const Air.Inst.Index, compt
2393 }2393 }
2394 {2394 {
2395 const reg = RegisterManager.regAtTrackedIndex(2395 const reg = RegisterManager.regAtTrackedIndex(
2396 @intCast(RegisterManager.RegisterBitSet.ShiftInt, index),2396 @as(RegisterManager.RegisterBitSet.ShiftInt, @intCast(index)),
2397 );2397 );
2398 self.register_manager.freeReg(reg);2398 self.register_manager.freeReg(reg);
2399 self.register_manager.getRegAssumeFree(reg, target_maybe_inst);2399 self.register_manager.getRegAssumeFree(reg, target_maybe_inst);
...@@ -2628,7 +2628,7 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -2628,7 +2628,7 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
26282628
2629 const dst_ty = self.typeOfIndex(inst);2629 const dst_ty = self.typeOfIndex(inst);
2630 const dst_int_info = dst_ty.intInfo(mod);2630 const dst_int_info = dst_ty.intInfo(mod);
2631 const abi_size = @intCast(u32, dst_ty.abiSize(mod));2631 const abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
26322632
2633 const min_ty = if (dst_int_info.bits < src_int_info.bits) dst_ty else src_ty;2633 const min_ty = if (dst_int_info.bits < src_int_info.bits) dst_ty else src_ty;
2634 const extend = switch (src_int_info.signedness) {2634 const extend = switch (src_int_info.signedness) {
...@@ -2706,9 +2706,9 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {...@@ -2706,9 +2706,9 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
2706 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2706 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
27072707
2708 const dst_ty = self.typeOfIndex(inst);2708 const dst_ty = self.typeOfIndex(inst);
2709 const dst_abi_size = @intCast(u32, dst_ty.abiSize(mod));2709 const dst_abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
2710 const src_ty = self.typeOf(ty_op.operand);2710 const src_ty = self.typeOf(ty_op.operand);
2711 const src_abi_size = @intCast(u32, src_ty.abiSize(mod));2711 const src_abi_size = @as(u32, @intCast(src_ty.abiSize(mod)));
27122712
2713 const result = result: {2713 const result = result: {
2714 const src_mcv = try self.resolveInst(ty_op.operand);2714 const src_mcv = try self.resolveInst(ty_op.operand);
...@@ -2753,13 +2753,13 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {...@@ -2753,13 +2753,13 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
2753 });2753 });
27542754
2755 const elem_ty = src_ty.childType(mod);2755 const elem_ty = src_ty.childType(mod);
2756 const mask_val = try mod.intValue(elem_ty, @as(u64, math.maxInt(u64)) >> @intCast(u6, 64 - dst_info.bits));2756 const mask_val = try mod.intValue(elem_ty, @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - dst_info.bits)));
27572757
2758 const splat_ty = try mod.vectorType(.{2758 const splat_ty = try mod.vectorType(.{
2759 .len = @intCast(u32, @divExact(@as(u64, if (src_abi_size > 16) 256 else 128), src_info.bits)),2759 .len = @as(u32, @intCast(@divExact(@as(u64, if (src_abi_size > 16) 256 else 128), src_info.bits))),
2760 .child = elem_ty.ip_index,2760 .child = elem_ty.ip_index,
2761 });2761 });
2762 const splat_abi_size = @intCast(u32, splat_ty.abiSize(mod));2762 const splat_abi_size = @as(u32, @intCast(splat_ty.abiSize(mod)));
27632763
2764 const splat_val = try mod.intern(.{ .aggregate = .{2764 const splat_val = try mod.intern(.{ .aggregate = .{
2765 .ty = splat_ty.ip_index,2765 .ty = splat_ty.ip_index,
...@@ -2834,7 +2834,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {...@@ -2834,7 +2834,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
2834 try self.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr);2834 try self.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr);
2835 try self.genSetMem(2835 try self.genSetMem(
2836 .{ .frame = frame_index },2836 .{ .frame = frame_index },
2837 @intCast(i32, ptr_ty.abiSize(mod)),2837 @as(i32, @intCast(ptr_ty.abiSize(mod))),
2838 len_ty,2838 len_ty,
2839 len,2839 len,
2840 );2840 );
...@@ -2875,7 +2875,7 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {...@@ -2875,7 +2875,7 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
2875 const src_val = air_data[inst].interned.toValue();2875 const src_val = air_data[inst].interned.toValue();
2876 var space: Value.BigIntSpace = undefined;2876 var space: Value.BigIntSpace = undefined;
2877 const src_int = src_val.toBigInt(&space, mod);2877 const src_int = src_val.toBigInt(&space, mod);
2878 return @intCast(u16, src_int.bitCountTwosComp()) +2878 return @as(u16, @intCast(src_int.bitCountTwosComp())) +
2879 @intFromBool(src_int.positive and dst_info.signedness == .signed);2879 @intFromBool(src_int.positive and dst_info.signedness == .signed);
2880 },2880 },
2881 .intcast => {2881 .intcast => {
...@@ -2964,7 +2964,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -2964,7 +2964,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
2964 try self.genSetReg(limit_reg, ty, dst_mcv);2964 try self.genSetReg(limit_reg, ty, dst_mcv);
2965 try self.genShiftBinOpMir(.{ ._r, .sa }, ty, limit_mcv, .{ .immediate = reg_bits - 1 });2965 try self.genShiftBinOpMir(.{ ._r, .sa }, ty, limit_mcv, .{ .immediate = reg_bits - 1 });
2966 try self.genBinOpMir(.{ ._, .xor }, ty, limit_mcv, .{2966 try self.genBinOpMir(.{ ._, .xor }, ty, limit_mcv, .{
2967 .immediate = (@as(u64, 1) << @intCast(u6, reg_bits - 1)) - 1,2967 .immediate = (@as(u64, 1) << @as(u6, @intCast(reg_bits - 1))) - 1,
2968 });2968 });
2969 if (reg_extra_bits > 0) {2969 if (reg_extra_bits > 0) {
2970 const shifted_rhs_reg = try self.copyToTmpRegister(ty, rhs_mcv);2970 const shifted_rhs_reg = try self.copyToTmpRegister(ty, rhs_mcv);
...@@ -2983,7 +2983,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -2983,7 +2983,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
2983 break :cc .o;2983 break :cc .o;
2984 } else cc: {2984 } else cc: {
2985 try self.genSetReg(limit_reg, ty, .{2985 try self.genSetReg(limit_reg, ty, .{
2986 .immediate = @as(u64, math.maxInt(u64)) >> @intCast(u6, 64 - ty.bitSize(mod)),2986 .immediate = @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - ty.bitSize(mod))),
2987 });2987 });
29882988
2989 try self.genBinOpMir(.{ ._, .add }, ty, dst_mcv, rhs_mcv);2989 try self.genBinOpMir(.{ ._, .add }, ty, dst_mcv, rhs_mcv);
...@@ -2994,7 +2994,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -2994,7 +2994,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
2994 break :cc .c;2994 break :cc .c;
2995 };2995 };
29962996
2997 const cmov_abi_size = @max(@intCast(u32, ty.abiSize(mod)), 2);2997 const cmov_abi_size = @max(@as(u32, @intCast(ty.abiSize(mod))), 2);
2998 try self.asmCmovccRegisterRegister(2998 try self.asmCmovccRegisterRegister(
2999 registerAlias(dst_reg, cmov_abi_size),2999 registerAlias(dst_reg, cmov_abi_size),
3000 registerAlias(limit_reg, cmov_abi_size),3000 registerAlias(limit_reg, cmov_abi_size),
...@@ -3043,7 +3043,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -3043,7 +3043,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
3043 try self.genSetReg(limit_reg, ty, dst_mcv);3043 try self.genSetReg(limit_reg, ty, dst_mcv);
3044 try self.genShiftBinOpMir(.{ ._r, .sa }, ty, limit_mcv, .{ .immediate = reg_bits - 1 });3044 try self.genShiftBinOpMir(.{ ._r, .sa }, ty, limit_mcv, .{ .immediate = reg_bits - 1 });
3045 try self.genBinOpMir(.{ ._, .xor }, ty, limit_mcv, .{3045 try self.genBinOpMir(.{ ._, .xor }, ty, limit_mcv, .{
3046 .immediate = (@as(u64, 1) << @intCast(u6, reg_bits - 1)) - 1,3046 .immediate = (@as(u64, 1) << @as(u6, @intCast(reg_bits - 1))) - 1,
3047 });3047 });
3048 if (reg_extra_bits > 0) {3048 if (reg_extra_bits > 0) {
3049 const shifted_rhs_reg = try self.copyToTmpRegister(ty, rhs_mcv);3049 const shifted_rhs_reg = try self.copyToTmpRegister(ty, rhs_mcv);
...@@ -3066,7 +3066,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -3066,7 +3066,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
3066 break :cc .c;3066 break :cc .c;
3067 };3067 };
30683068
3069 const cmov_abi_size = @max(@intCast(u32, ty.abiSize(mod)), 2);3069 const cmov_abi_size = @max(@as(u32, @intCast(ty.abiSize(mod))), 2);
3070 try self.asmCmovccRegisterRegister(3070 try self.asmCmovccRegisterRegister(
3071 registerAlias(dst_reg, cmov_abi_size),3071 registerAlias(dst_reg, cmov_abi_size),
3072 registerAlias(limit_reg, cmov_abi_size),3072 registerAlias(limit_reg, cmov_abi_size),
...@@ -3114,18 +3114,18 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -3114,18 +3114,18 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
3114 try self.genBinOpMir(.{ ._, .xor }, ty, limit_mcv, rhs_mcv);3114 try self.genBinOpMir(.{ ._, .xor }, ty, limit_mcv, rhs_mcv);
3115 try self.genShiftBinOpMir(.{ ._, .sa }, ty, limit_mcv, .{ .immediate = reg_bits - 1 });3115 try self.genShiftBinOpMir(.{ ._, .sa }, ty, limit_mcv, .{ .immediate = reg_bits - 1 });
3116 try self.genBinOpMir(.{ ._, .xor }, ty, limit_mcv, .{3116 try self.genBinOpMir(.{ ._, .xor }, ty, limit_mcv, .{
3117 .immediate = (@as(u64, 1) << @intCast(u6, reg_bits - 1)) - 1,3117 .immediate = (@as(u64, 1) << @as(u6, @intCast(reg_bits - 1))) - 1,
3118 });3118 });
3119 break :cc .o;3119 break :cc .o;
3120 } else cc: {3120 } else cc: {
3121 try self.genSetReg(limit_reg, ty, .{3121 try self.genSetReg(limit_reg, ty, .{
3122 .immediate = @as(u64, math.maxInt(u64)) >> @intCast(u6, 64 - reg_bits),3122 .immediate = @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - reg_bits)),
3123 });3123 });
3124 break :cc .c;3124 break :cc .c;
3125 };3125 };
31263126
3127 const dst_mcv = try self.genMulDivBinOp(.mul, inst, ty, ty, lhs_mcv, rhs_mcv);3127 const dst_mcv = try self.genMulDivBinOp(.mul, inst, ty, ty, lhs_mcv, rhs_mcv);
3128 const cmov_abi_size = @max(@intCast(u32, ty.abiSize(mod)), 2);3128 const cmov_abi_size = @max(@as(u32, @intCast(ty.abiSize(mod))), 2);
3129 try self.asmCmovccRegisterRegister(3129 try self.asmCmovccRegisterRegister(
3130 registerAlias(dst_mcv.register, cmov_abi_size),3130 registerAlias(dst_mcv.register, cmov_abi_size),
3131 registerAlias(limit_reg, cmov_abi_size),3131 registerAlias(limit_reg, cmov_abi_size),
...@@ -3172,13 +3172,13 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -3172,13 +3172,13 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
3172 try self.allocFrameIndex(FrameAlloc.initType(tuple_ty, mod));3172 try self.allocFrameIndex(FrameAlloc.initType(tuple_ty, mod));
3173 try self.genSetMem(3173 try self.genSetMem(
3174 .{ .frame = frame_index },3174 .{ .frame = frame_index },
3175 @intCast(i32, tuple_ty.structFieldOffset(1, mod)),3175 @as(i32, @intCast(tuple_ty.structFieldOffset(1, mod))),
3176 Type.u1,3176 Type.u1,
3177 .{ .eflags = cc },3177 .{ .eflags = cc },
3178 );3178 );
3179 try self.genSetMem(3179 try self.genSetMem(
3180 .{ .frame = frame_index },3180 .{ .frame = frame_index },
3181 @intCast(i32, tuple_ty.structFieldOffset(0, mod)),3181 @as(i32, @intCast(tuple_ty.structFieldOffset(0, mod))),
3182 ty,3182 ty,
3183 partial_mcv,3183 partial_mcv,
3184 );3184 );
...@@ -3245,13 +3245,13 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -3245,13 +3245,13 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
3245 try self.allocFrameIndex(FrameAlloc.initType(tuple_ty, mod));3245 try self.allocFrameIndex(FrameAlloc.initType(tuple_ty, mod));
3246 try self.genSetMem(3246 try self.genSetMem(
3247 .{ .frame = frame_index },3247 .{ .frame = frame_index },
3248 @intCast(i32, tuple_ty.structFieldOffset(1, mod)),3248 @as(i32, @intCast(tuple_ty.structFieldOffset(1, mod))),
3249 tuple_ty.structFieldType(1, mod),3249 tuple_ty.structFieldType(1, mod),
3250 .{ .eflags = cc },3250 .{ .eflags = cc },
3251 );3251 );
3252 try self.genSetMem(3252 try self.genSetMem(
3253 .{ .frame = frame_index },3253 .{ .frame = frame_index },
3254 @intCast(i32, tuple_ty.structFieldOffset(0, mod)),3254 @as(i32, @intCast(tuple_ty.structFieldOffset(0, mod))),
3255 tuple_ty.structFieldType(0, mod),3255 tuple_ty.structFieldType(0, mod),
3256 partial_mcv,3256 partial_mcv,
3257 );3257 );
...@@ -3319,7 +3319,7 @@ fn genSetFrameTruncatedOverflowCompare(...@@ -3319,7 +3319,7 @@ fn genSetFrameTruncatedOverflowCompare(
3319 );3319 );
3320 }3320 }
33213321
3322 const payload_off = @intCast(i32, tuple_ty.structFieldOffset(0, mod));3322 const payload_off = @as(i32, @intCast(tuple_ty.structFieldOffset(0, mod)));
3323 if (hi_limb_off > 0) try self.genSetMem(.{ .frame = frame_index }, payload_off, rest_ty, src_mcv);3323 if (hi_limb_off > 0) try self.genSetMem(.{ .frame = frame_index }, payload_off, rest_ty, src_mcv);
3324 try self.genSetMem(3324 try self.genSetMem(
3325 .{ .frame = frame_index },3325 .{ .frame = frame_index },
...@@ -3329,7 +3329,7 @@ fn genSetFrameTruncatedOverflowCompare(...@@ -3329,7 +3329,7 @@ fn genSetFrameTruncatedOverflowCompare(
3329 );3329 );
3330 try self.genSetMem(3330 try self.genSetMem(
3331 .{ .frame = frame_index },3331 .{ .frame = frame_index },
3332 @intCast(i32, tuple_ty.structFieldOffset(1, mod)),3332 @as(i32, @intCast(tuple_ty.structFieldOffset(1, mod))),
3333 tuple_ty.structFieldType(1, mod),3333 tuple_ty.structFieldType(1, mod),
3334 if (overflow_cc) |_| .{ .register = overflow_reg.to8() } else .{ .eflags = .ne },3334 if (overflow_cc) |_| .{ .register = overflow_reg.to8() } else .{ .eflags = .ne },
3335 );3335 );
...@@ -3386,13 +3386,13 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -3386,13 +3386,13 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
3386 if (dst_info.bits >= lhs_active_bits + rhs_active_bits) {3386 if (dst_info.bits >= lhs_active_bits + rhs_active_bits) {
3387 try self.genSetMem(3387 try self.genSetMem(
3388 .{ .frame = frame_index },3388 .{ .frame = frame_index },
3389 @intCast(i32, tuple_ty.structFieldOffset(0, mod)),3389 @as(i32, @intCast(tuple_ty.structFieldOffset(0, mod))),
3390 tuple_ty.structFieldType(0, mod),3390 tuple_ty.structFieldType(0, mod),
3391 partial_mcv,3391 partial_mcv,
3392 );3392 );
3393 try self.genSetMem(3393 try self.genSetMem(
3394 .{ .frame = frame_index },3394 .{ .frame = frame_index },
3395 @intCast(i32, tuple_ty.structFieldOffset(1, mod)),3395 @as(i32, @intCast(tuple_ty.structFieldOffset(1, mod))),
3396 tuple_ty.structFieldType(1, mod),3396 tuple_ty.structFieldType(1, mod),
3397 .{ .immediate = 0 }, // cc being set is impossible3397 .{ .immediate = 0 }, // cc being set is impossible
3398 );3398 );
...@@ -3416,7 +3416,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -3416,7 +3416,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
3416/// Quotient is saved in .rax and remainder in .rdx.3416/// Quotient is saved in .rax and remainder in .rdx.
3417fn genIntMulDivOpMir(self: *Self, tag: Mir.Inst.FixedTag, ty: Type, lhs: MCValue, rhs: MCValue) !void {3417fn genIntMulDivOpMir(self: *Self, tag: Mir.Inst.FixedTag, ty: Type, lhs: MCValue, rhs: MCValue) !void {
3418 const mod = self.bin_file.options.module.?;3418 const mod = self.bin_file.options.module.?;
3419 const abi_size = @intCast(u32, ty.abiSize(mod));3419 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
3420 if (abi_size > 8) {3420 if (abi_size > 8) {
3421 return self.fail("TODO implement genIntMulDivOpMir for ABI size larger than 8", .{});3421 return self.fail("TODO implement genIntMulDivOpMir for ABI size larger than 8", .{});
3422 }3422 }
...@@ -3456,7 +3456,7 @@ fn genIntMulDivOpMir(self: *Self, tag: Mir.Inst.FixedTag, ty: Type, lhs: MCValue...@@ -3456,7 +3456,7 @@ fn genIntMulDivOpMir(self: *Self, tag: Mir.Inst.FixedTag, ty: Type, lhs: MCValue
3456/// Clobbers .rax and .rdx registers.3456/// Clobbers .rax and .rdx registers.
3457fn genInlineIntDivFloor(self: *Self, ty: Type, lhs: MCValue, rhs: MCValue) !MCValue {3457fn genInlineIntDivFloor(self: *Self, ty: Type, lhs: MCValue, rhs: MCValue) !MCValue {
3458 const mod = self.bin_file.options.module.?;3458 const mod = self.bin_file.options.module.?;
3459 const abi_size = @intCast(u32, ty.abiSize(mod));3459 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
3460 const int_info = ty.intInfo(mod);3460 const int_info = ty.intInfo(mod);
3461 const dividend: Register = switch (lhs) {3461 const dividend: Register = switch (lhs) {
3462 .register => |reg| reg,3462 .register => |reg| reg,
...@@ -3595,7 +3595,7 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {...@@ -3595,7 +3595,7 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
3595 try self.copyToRegisterWithInstTracking(inst, dst_ty, src_mcv);3595 try self.copyToRegisterWithInstTracking(inst, dst_ty, src_mcv);
35963596
3597 const pl_ty = dst_ty.childType(mod);3597 const pl_ty = dst_ty.childType(mod);
3598 const pl_abi_size = @intCast(i32, pl_ty.abiSize(mod));3598 const pl_abi_size = @as(i32, @intCast(pl_ty.abiSize(mod)));
3599 try self.genSetMem(.{ .reg = dst_mcv.getReg().? }, pl_abi_size, Type.bool, .{ .immediate = 1 });3599 try self.genSetMem(.{ .reg = dst_mcv.getReg().? }, pl_abi_size, Type.bool, .{ .immediate = 1 });
3600 break :result if (self.liveness.isUnused(inst)) .unreach else dst_mcv;3600 break :result if (self.liveness.isUnused(inst)) .unreach else dst_mcv;
3601 };3601 };
...@@ -3628,7 +3628,7 @@ fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -3628,7 +3628,7 @@ fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
36283628
3629 const result = try self.copyToRegisterWithInstTracking(inst, err_union_ty, operand);3629 const result = try self.copyToRegisterWithInstTracking(inst, err_union_ty, operand);
3630 if (err_off > 0) {3630 if (err_off > 0) {
3631 const shift = @intCast(u6, err_off * 8);3631 const shift = @as(u6, @intCast(err_off * 8));
3632 try self.genShiftBinOpMir(3632 try self.genShiftBinOpMir(
3633 .{ ._r, .sh },3633 .{ ._r, .sh },
3634 err_union_ty,3634 err_union_ty,
...@@ -3642,7 +3642,7 @@ fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -3642,7 +3642,7 @@ fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
3642 },3642 },
3643 .load_frame => |frame_addr| break :result .{ .load_frame = .{3643 .load_frame => |frame_addr| break :result .{ .load_frame = .{
3644 .index = frame_addr.index,3644 .index = frame_addr.index,
3645 .off = frame_addr.off + @intCast(i32, err_off),3645 .off = frame_addr.off + @as(i32, @intCast(err_off)),
3646 } },3646 } },
3647 else => return self.fail("TODO implement unwrap_err_err for {}", .{operand}),3647 else => return self.fail("TODO implement unwrap_err_err for {}", .{operand}),
3648 }3648 }
...@@ -3674,7 +3674,7 @@ fn genUnwrapErrorUnionPayloadMir(...@@ -3674,7 +3674,7 @@ fn genUnwrapErrorUnionPayloadMir(
3674 switch (err_union) {3674 switch (err_union) {
3675 .load_frame => |frame_addr| break :result .{ .load_frame = .{3675 .load_frame => |frame_addr| break :result .{ .load_frame = .{
3676 .index = frame_addr.index,3676 .index = frame_addr.index,
3677 .off = frame_addr.off + @intCast(i32, payload_off),3677 .off = frame_addr.off + @as(i32, @intCast(payload_off)),
3678 } },3678 } },
3679 .register => |reg| {3679 .register => |reg| {
3680 // TODO reuse operand3680 // TODO reuse operand
...@@ -3686,7 +3686,7 @@ fn genUnwrapErrorUnionPayloadMir(...@@ -3686,7 +3686,7 @@ fn genUnwrapErrorUnionPayloadMir(
3686 else3686 else
3687 .{ .register = try self.copyToTmpRegister(err_union_ty, err_union) };3687 .{ .register = try self.copyToTmpRegister(err_union_ty, err_union) };
3688 if (payload_off > 0) {3688 if (payload_off > 0) {
3689 const shift = @intCast(u6, payload_off * 8);3689 const shift = @as(u6, @intCast(payload_off * 8));
3690 try self.genShiftBinOpMir(3690 try self.genShiftBinOpMir(
3691 .{ ._r, .sh },3691 .{ ._r, .sh },
3692 err_union_ty,3692 err_union_ty,
...@@ -3727,8 +3727,8 @@ fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -3727,8 +3727,8 @@ fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {
3727 const eu_ty = src_ty.childType(mod);3727 const eu_ty = src_ty.childType(mod);
3728 const pl_ty = eu_ty.errorUnionPayload(mod);3728 const pl_ty = eu_ty.errorUnionPayload(mod);
3729 const err_ty = eu_ty.errorUnionSet(mod);3729 const err_ty = eu_ty.errorUnionSet(mod);
3730 const err_off = @intCast(i32, errUnionErrorOffset(pl_ty, mod));3730 const err_off = @as(i32, @intCast(errUnionErrorOffset(pl_ty, mod)));
3731 const err_abi_size = @intCast(u32, err_ty.abiSize(mod));3731 const err_abi_size = @as(u32, @intCast(err_ty.abiSize(mod)));
3732 try self.asmRegisterMemory(3732 try self.asmRegisterMemory(
3733 .{ ._, .mov },3733 .{ ._, .mov },
3734 registerAlias(dst_reg, err_abi_size),3734 registerAlias(dst_reg, err_abi_size),
...@@ -3766,8 +3766,8 @@ fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -3766,8 +3766,8 @@ fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
37663766
3767 const eu_ty = src_ty.childType(mod);3767 const eu_ty = src_ty.childType(mod);
3768 const pl_ty = eu_ty.errorUnionPayload(mod);3768 const pl_ty = eu_ty.errorUnionPayload(mod);
3769 const pl_off = @intCast(i32, errUnionPayloadOffset(pl_ty, mod));3769 const pl_off = @as(i32, @intCast(errUnionPayloadOffset(pl_ty, mod)));
3770 const dst_abi_size = @intCast(u32, dst_ty.abiSize(mod));3770 const dst_abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
3771 try self.asmRegisterMemory(3771 try self.asmRegisterMemory(
3772 .{ ._, .lea },3772 .{ ._, .lea },
3773 registerAlias(dst_reg, dst_abi_size),3773 registerAlias(dst_reg, dst_abi_size),
...@@ -3793,8 +3793,8 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {...@@ -3793,8 +3793,8 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
3793 const eu_ty = src_ty.childType(mod);3793 const eu_ty = src_ty.childType(mod);
3794 const pl_ty = eu_ty.errorUnionPayload(mod);3794 const pl_ty = eu_ty.errorUnionPayload(mod);
3795 const err_ty = eu_ty.errorUnionSet(mod);3795 const err_ty = eu_ty.errorUnionSet(mod);
3796 const err_off = @intCast(i32, errUnionErrorOffset(pl_ty, mod));3796 const err_off = @as(i32, @intCast(errUnionErrorOffset(pl_ty, mod)));
3797 const err_abi_size = @intCast(u32, err_ty.abiSize(mod));3797 const err_abi_size = @as(u32, @intCast(err_ty.abiSize(mod)));
3798 try self.asmMemoryImmediate(3798 try self.asmMemoryImmediate(
3799 .{ ._, .mov },3799 .{ ._, .mov },
3800 Memory.sib(Memory.PtrSize.fromSize(err_abi_size), .{3800 Memory.sib(Memory.PtrSize.fromSize(err_abi_size), .{
...@@ -3814,8 +3814,8 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {...@@ -3814,8 +3814,8 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
3814 const dst_lock = self.register_manager.lockReg(dst_reg);3814 const dst_lock = self.register_manager.lockReg(dst_reg);
3815 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);3815 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
38163816
3817 const pl_off = @intCast(i32, errUnionPayloadOffset(pl_ty, mod));3817 const pl_off = @as(i32, @intCast(errUnionPayloadOffset(pl_ty, mod)));
3818 const dst_abi_size = @intCast(u32, dst_ty.abiSize(mod));3818 const dst_abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
3819 try self.asmRegisterMemory(3819 try self.asmRegisterMemory(
3820 .{ ._, .lea },3820 .{ ._, .lea },
3821 registerAlias(dst_reg, dst_abi_size),3821 registerAlias(dst_reg, dst_abi_size),
...@@ -3864,14 +3864,14 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {...@@ -3864,14 +3864,14 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
3864 try self.genCopy(pl_ty, opt_mcv, pl_mcv);3864 try self.genCopy(pl_ty, opt_mcv, pl_mcv);
38653865
3866 if (!same_repr) {3866 if (!same_repr) {
3867 const pl_abi_size = @intCast(i32, pl_ty.abiSize(mod));3867 const pl_abi_size = @as(i32, @intCast(pl_ty.abiSize(mod)));
3868 switch (opt_mcv) {3868 switch (opt_mcv) {
3869 else => unreachable,3869 else => unreachable,
38703870
3871 .register => |opt_reg| try self.asmRegisterImmediate(3871 .register => |opt_reg| try self.asmRegisterImmediate(
3872 .{ ._s, .bt },3872 .{ ._s, .bt },
3873 opt_reg,3873 opt_reg,
3874 Immediate.u(@intCast(u6, pl_abi_size * 8)),3874 Immediate.u(@as(u6, @intCast(pl_abi_size * 8))),
3875 ),3875 ),
38763876
3877 .load_frame => |frame_addr| try self.asmMemoryImmediate(3877 .load_frame => |frame_addr| try self.asmMemoryImmediate(
...@@ -3903,8 +3903,8 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {...@@ -3903,8 +3903,8 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
3903 if (!pl_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result .{ .immediate = 0 };3903 if (!pl_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result .{ .immediate = 0 };
39043904
3905 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(eu_ty, mod));3905 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(eu_ty, mod));
3906 const pl_off = @intCast(i32, errUnionPayloadOffset(pl_ty, mod));3906 const pl_off = @as(i32, @intCast(errUnionPayloadOffset(pl_ty, mod)));
3907 const err_off = @intCast(i32, errUnionErrorOffset(pl_ty, mod));3907 const err_off = @as(i32, @intCast(errUnionErrorOffset(pl_ty, mod)));
3908 try self.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, operand);3908 try self.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, operand);
3909 try self.genSetMem(.{ .frame = frame_index }, err_off, err_ty, .{ .immediate = 0 });3909 try self.genSetMem(.{ .frame = frame_index }, err_off, err_ty, .{ .immediate = 0 });
3910 break :result .{ .load_frame = .{ .index = frame_index } };3910 break :result .{ .load_frame = .{ .index = frame_index } };
...@@ -3925,8 +3925,8 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -3925,8 +3925,8 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
3925 if (!pl_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result try self.resolveInst(ty_op.operand);3925 if (!pl_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result try self.resolveInst(ty_op.operand);
39263926
3927 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(eu_ty, mod));3927 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(eu_ty, mod));
3928 const pl_off = @intCast(i32, errUnionPayloadOffset(pl_ty, mod));3928 const pl_off = @as(i32, @intCast(errUnionPayloadOffset(pl_ty, mod)));
3929 const err_off = @intCast(i32, errUnionErrorOffset(pl_ty, mod));3929 const err_off = @as(i32, @intCast(errUnionErrorOffset(pl_ty, mod)));
3930 try self.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, .undef);3930 try self.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, .undef);
3931 const operand = try self.resolveInst(ty_op.operand);3931 const operand = try self.resolveInst(ty_op.operand);
3932 try self.genSetMem(.{ .frame = frame_index }, err_off, err_ty, operand);3932 try self.genSetMem(.{ .frame = frame_index }, err_off, err_ty, operand);
...@@ -3988,7 +3988,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -3988,7 +3988,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
3988 const dst_lock = self.register_manager.lockReg(dst_reg);3988 const dst_lock = self.register_manager.lockReg(dst_reg);
3989 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);3989 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
39903990
3991 const dst_abi_size = @intCast(u32, dst_ty.abiSize(mod));3991 const dst_abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
3992 try self.asmRegisterMemory(3992 try self.asmRegisterMemory(
3993 .{ ._, .lea },3993 .{ ._, .lea },
3994 registerAlias(dst_reg, dst_abi_size),3994 registerAlias(dst_reg, dst_abi_size),
...@@ -4165,7 +4165,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -4165,7 +4165,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
4165 // additional `mov` is needed at the end to get the actual value4165 // additional `mov` is needed at the end to get the actual value
41664166
4167 const elem_ty = ptr_ty.elemType2(mod);4167 const elem_ty = ptr_ty.elemType2(mod);
4168 const elem_abi_size = @intCast(u32, elem_ty.abiSize(mod));4168 const elem_abi_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
4169 const index_ty = self.typeOf(bin_op.rhs);4169 const index_ty = self.typeOf(bin_op.rhs);
4170 const index_mcv = try self.resolveInst(bin_op.rhs);4170 const index_mcv = try self.resolveInst(bin_op.rhs);
4171 const index_lock = switch (index_mcv) {4171 const index_lock = switch (index_mcv) {
...@@ -4305,7 +4305,7 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {...@@ -4305,7 +4305,7 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
4305 .load_frame => |frame_addr| {4305 .load_frame => |frame_addr| {
4306 if (tag_abi_size <= 8) {4306 if (tag_abi_size <= 8) {
4307 const off: i32 = if (layout.tag_align < layout.payload_align)4307 const off: i32 = if (layout.tag_align < layout.payload_align)
4308 @intCast(i32, layout.payload_size)4308 @as(i32, @intCast(layout.payload_size))
4309 else4309 else
4310 0;4310 0;
4311 break :blk try self.copyToRegisterWithInstTracking(inst, tag_ty, .{4311 break :blk try self.copyToRegisterWithInstTracking(inst, tag_ty, .{
...@@ -4317,13 +4317,13 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {...@@ -4317,13 +4317,13 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
4317 },4317 },
4318 .register => {4318 .register => {
4319 const shift: u6 = if (layout.tag_align < layout.payload_align)4319 const shift: u6 = if (layout.tag_align < layout.payload_align)
4320 @intCast(u6, layout.payload_size * 8)4320 @as(u6, @intCast(layout.payload_size * 8))
4321 else4321 else
4322 0;4322 0;
4323 const result = try self.copyToRegisterWithInstTracking(inst, union_ty, operand);4323 const result = try self.copyToRegisterWithInstTracking(inst, union_ty, operand);
4324 try self.genShiftBinOpMir(.{ ._r, .sh }, Type.usize, result, .{ .immediate = shift });4324 try self.genShiftBinOpMir(.{ ._r, .sh }, Type.usize, result, .{ .immediate = shift });
4325 break :blk MCValue{4325 break :blk MCValue{
4326 .register = registerAlias(result.register, @intCast(u32, layout.tag_size)),4326 .register = registerAlias(result.register, @as(u32, @intCast(layout.tag_size))),
4327 };4327 };
4328 },4328 },
4329 else => return self.fail("TODO implement get_union_tag for {}", .{operand}),4329 else => return self.fail("TODO implement get_union_tag for {}", .{operand}),
...@@ -4420,7 +4420,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {...@@ -4420,7 +4420,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
4420 try self.genBinOpMir(.{ ._, .bsr }, Type.u16, dst_mcv, .{ .register = wide_reg });4420 try self.genBinOpMir(.{ ._, .bsr }, Type.u16, dst_mcv, .{ .register = wide_reg });
4421 } else try self.genBinOpMir(.{ ._, .bsr }, src_ty, dst_mcv, mat_src_mcv);4421 } else try self.genBinOpMir(.{ ._, .bsr }, src_ty, dst_mcv, mat_src_mcv);
44224422
4423 const cmov_abi_size = @max(@intCast(u32, dst_ty.abiSize(mod)), 2);4423 const cmov_abi_size = @max(@as(u32, @intCast(dst_ty.abiSize(mod))), 2);
4424 try self.asmCmovccRegisterRegister(4424 try self.asmCmovccRegisterRegister(
4425 registerAlias(dst_reg, cmov_abi_size),4425 registerAlias(dst_reg, cmov_abi_size),
4426 registerAlias(imm_reg, cmov_abi_size),4426 registerAlias(imm_reg, cmov_abi_size),
...@@ -4430,7 +4430,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {...@@ -4430,7 +4430,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
4430 try self.genBinOpMir(.{ ._, .xor }, dst_ty, dst_mcv, .{ .immediate = src_bits - 1 });4430 try self.genBinOpMir(.{ ._, .xor }, dst_ty, dst_mcv, .{ .immediate = src_bits - 1 });
4431 } else {4431 } else {
4432 const imm_reg = try self.copyToTmpRegister(dst_ty, .{4432 const imm_reg = try self.copyToTmpRegister(dst_ty, .{
4433 .immediate = @as(u64, math.maxInt(u64)) >> @intCast(u6, 64 - self.regBitSize(dst_ty)),4433 .immediate = @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - self.regBitSize(dst_ty))),
4434 });4434 });
4435 const imm_lock = self.register_manager.lockRegAssumeUnused(imm_reg);4435 const imm_lock = self.register_manager.lockRegAssumeUnused(imm_reg);
4436 defer self.register_manager.unlockReg(imm_lock);4436 defer self.register_manager.unlockReg(imm_lock);
...@@ -4447,7 +4447,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {...@@ -4447,7 +4447,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
4447 .{ .register = wide_reg },4447 .{ .register = wide_reg },
4448 );4448 );
44494449
4450 const cmov_abi_size = @max(@intCast(u32, dst_ty.abiSize(mod)), 2);4450 const cmov_abi_size = @max(@as(u32, @intCast(dst_ty.abiSize(mod))), 2);
4451 try self.asmCmovccRegisterRegister(4451 try self.asmCmovccRegisterRegister(
4452 registerAlias(imm_reg, cmov_abi_size),4452 registerAlias(imm_reg, cmov_abi_size),
4453 registerAlias(dst_reg, cmov_abi_size),4453 registerAlias(dst_reg, cmov_abi_size),
...@@ -4501,8 +4501,8 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {...@@ -4501,8 +4501,8 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
4501 .{ ._, .@"or" },4501 .{ ._, .@"or" },
4502 wide_ty,4502 wide_ty,
4503 tmp_mcv,4503 tmp_mcv,
4504 .{ .immediate = (@as(u64, math.maxInt(u64)) >> @intCast(u6, 64 - extra_bits)) <<4504 .{ .immediate = (@as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - extra_bits))) <<
4505 @intCast(u6, src_bits) },4505 @as(u6, @intCast(src_bits)) },
4506 );4506 );
4507 break :masked tmp_mcv;4507 break :masked tmp_mcv;
4508 } else mat_src_mcv;4508 } else mat_src_mcv;
...@@ -4519,7 +4519,7 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {...@@ -4519,7 +4519,7 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
4519 .{ ._, .@"or" },4519 .{ ._, .@"or" },
4520 Type.u64,4520 Type.u64,
4521 dst_mcv,4521 dst_mcv,
4522 .{ .immediate = @as(u64, math.maxInt(u64)) << @intCast(u6, src_bits - 64) },4522 .{ .immediate = @as(u64, math.maxInt(u64)) << @as(u6, @intCast(src_bits - 64)) },
4523 );4523 );
4524 break :masked dst_mcv;4524 break :masked dst_mcv;
4525 } else mat_src_mcv.address().offset(8).deref();4525 } else mat_src_mcv.address().offset(8).deref();
...@@ -4547,7 +4547,7 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {...@@ -4547,7 +4547,7 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
4547 try self.genBinOpMir(.{ ._, .bsf }, Type.u16, dst_mcv, .{ .register = wide_reg });4547 try self.genBinOpMir(.{ ._, .bsf }, Type.u16, dst_mcv, .{ .register = wide_reg });
4548 } else try self.genBinOpMir(.{ ._, .bsf }, src_ty, dst_mcv, mat_src_mcv);4548 } else try self.genBinOpMir(.{ ._, .bsf }, src_ty, dst_mcv, mat_src_mcv);
45494549
4550 const cmov_abi_size = @max(@intCast(u32, dst_ty.abiSize(mod)), 2);4550 const cmov_abi_size = @max(@as(u32, @intCast(dst_ty.abiSize(mod))), 2);
4551 try self.asmCmovccRegisterRegister(4551 try self.asmCmovccRegisterRegister(
4552 registerAlias(dst_reg, cmov_abi_size),4552 registerAlias(dst_reg, cmov_abi_size),
4553 registerAlias(width_reg, cmov_abi_size),4553 registerAlias(width_reg, cmov_abi_size),
...@@ -4563,7 +4563,7 @@ fn airPopcount(self: *Self, inst: Air.Inst.Index) !void {...@@ -4563,7 +4563,7 @@ fn airPopcount(self: *Self, inst: Air.Inst.Index) !void {
4563 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4563 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
4564 const result: MCValue = result: {4564 const result: MCValue = result: {
4565 const src_ty = self.typeOf(ty_op.operand);4565 const src_ty = self.typeOf(ty_op.operand);
4566 const src_abi_size = @intCast(u32, src_ty.abiSize(mod));4566 const src_abi_size = @as(u32, @intCast(src_ty.abiSize(mod)));
4567 const src_mcv = try self.resolveInst(ty_op.operand);4567 const src_mcv = try self.resolveInst(ty_op.operand);
45684568
4569 if (self.hasFeature(.popcnt)) {4569 if (self.hasFeature(.popcnt)) {
...@@ -4588,7 +4588,7 @@ fn airPopcount(self: *Self, inst: Air.Inst.Index) !void {...@@ -4588,7 +4588,7 @@ fn airPopcount(self: *Self, inst: Air.Inst.Index) !void {
4588 break :result dst_mcv;4588 break :result dst_mcv;
4589 }4589 }
45904590
4591 const mask = @as(u64, math.maxInt(u64)) >> @intCast(u6, 64 - src_abi_size * 8);4591 const mask = @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - src_abi_size * 8));
4592 const imm_0_1 = Immediate.u(mask / 0b1_1);4592 const imm_0_1 = Immediate.u(mask / 0b1_1);
4593 const imm_00_11 = Immediate.u(mask / 0b01_01);4593 const imm_00_11 = Immediate.u(mask / 0b01_01);
4594 const imm_0000_1111 = Immediate.u(mask / 0b0001_0001);4594 const imm_0000_1111 = Immediate.u(mask / 0b0001_0001);
...@@ -4754,7 +4754,7 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {...@@ -4754,7 +4754,7 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
4754 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4754 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
47554755
4756 const src_ty = self.typeOf(ty_op.operand);4756 const src_ty = self.typeOf(ty_op.operand);
4757 const src_abi_size = @intCast(u32, src_ty.abiSize(mod));4757 const src_abi_size = @as(u32, @intCast(src_ty.abiSize(mod)));
4758 const src_mcv = try self.resolveInst(ty_op.operand);4758 const src_mcv = try self.resolveInst(ty_op.operand);
47594759
4760 const dst_mcv = try self.byteSwap(inst, src_ty, src_mcv, false);4760 const dst_mcv = try self.byteSwap(inst, src_ty, src_mcv, false);
...@@ -4774,7 +4774,7 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {...@@ -4774,7 +4774,7 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
4774 else4774 else
4775 undefined;4775 undefined;
47764776
4777 const mask = @as(u64, math.maxInt(u64)) >> @intCast(u6, 64 - src_abi_size * 8);4777 const mask = @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - src_abi_size * 8));
4778 const imm_0000_1111 = Immediate.u(mask / 0b0001_0001);4778 const imm_0000_1111 = Immediate.u(mask / 0b0001_0001);
4779 const imm_00_11 = Immediate.u(mask / 0b01_01);4779 const imm_00_11 = Immediate.u(mask / 0b01_01);
4780 const imm_0_1 = Immediate.u(mask / 0b1_1);4780 const imm_0_1 = Immediate.u(mask / 0b1_1);
...@@ -5017,7 +5017,7 @@ fn genRound(self: *Self, ty: Type, dst_reg: Register, src_mcv: MCValue, mode: u4...@@ -5017,7 +5017,7 @@ fn genRound(self: *Self, ty: Type, dst_reg: Register, src_mcv: MCValue, mode: u4
5017 })) |tag| tag else return self.fail("TODO implement genRound for {}", .{5017 })) |tag| tag else return self.fail("TODO implement genRound for {}", .{
5018 ty.fmt(self.bin_file.options.module.?),5018 ty.fmt(self.bin_file.options.module.?),
5019 });5019 });
5020 const abi_size = @intCast(u32, ty.abiSize(mod));5020 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
5021 const dst_alias = registerAlias(dst_reg, abi_size);5021 const dst_alias = registerAlias(dst_reg, abi_size);
5022 switch (mir_tag[0]) {5022 switch (mir_tag[0]) {
5023 .v_ss, .v_sd => if (src_mcv.isMemory()) try self.asmRegisterRegisterMemoryImmediate(5023 .v_ss, .v_sd => if (src_mcv.isMemory()) try self.asmRegisterRegisterMemoryImmediate(
...@@ -5057,7 +5057,7 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {...@@ -5057,7 +5057,7 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
5057 const mod = self.bin_file.options.module.?;5057 const mod = self.bin_file.options.module.?;
5058 const un_op = self.air.instructions.items(.data)[inst].un_op;5058 const un_op = self.air.instructions.items(.data)[inst].un_op;
5059 const ty = self.typeOf(un_op);5059 const ty = self.typeOf(un_op);
5060 const abi_size = @intCast(u32, ty.abiSize(mod));5060 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
50615061
5062 const src_mcv = try self.resolveInst(un_op);5062 const src_mcv = try self.resolveInst(un_op);
5063 const dst_mcv = if (src_mcv.isRegister() and self.reuseOperand(inst, un_op, 0, src_mcv))5063 const dst_mcv = if (src_mcv.isRegister() and self.reuseOperand(inst, un_op, 0, src_mcv))
...@@ -5123,7 +5123,7 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {...@@ -5123,7 +5123,7 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
5123 .{ .v_ps, .cvtph2 },5123 .{ .v_ps, .cvtph2 },
5124 wide_reg,5124 wide_reg,
5125 src_mcv.mem(Memory.PtrSize.fromSize(5125 src_mcv.mem(Memory.PtrSize.fromSize(
5126 @intCast(u32, @divExact(wide_reg.bitSize(), 16)),5126 @as(u32, @intCast(@divExact(wide_reg.bitSize(), 16))),
5127 )),5127 )),
5128 ) else try self.asmRegisterRegister(5128 ) else try self.asmRegisterRegister(
5129 .{ .v_ps, .cvtph2 },5129 .{ .v_ps, .cvtph2 },
...@@ -5255,10 +5255,10 @@ fn packedLoad(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) Inn...@@ -5255,10 +5255,10 @@ fn packedLoad(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) Inn
5255 const ptr_info = ptr_ty.ptrInfo(mod);5255 const ptr_info = ptr_ty.ptrInfo(mod);
52565256
5257 const val_ty = ptr_info.child.toType();5257 const val_ty = ptr_info.child.toType();
5258 const val_abi_size = @intCast(u32, val_ty.abiSize(mod));5258 const val_abi_size = @as(u32, @intCast(val_ty.abiSize(mod)));
5259 const limb_abi_size: u32 = @min(val_abi_size, 8);5259 const limb_abi_size: u32 = @min(val_abi_size, 8);
5260 const limb_abi_bits = limb_abi_size * 8;5260 const limb_abi_bits = limb_abi_size * 8;
5261 const val_byte_off = @intCast(i32, ptr_info.packed_offset.bit_offset / limb_abi_bits * limb_abi_size);5261 const val_byte_off = @as(i32, @intCast(ptr_info.packed_offset.bit_offset / limb_abi_bits * limb_abi_size));
5262 const val_bit_off = ptr_info.packed_offset.bit_offset % limb_abi_bits;5262 const val_bit_off = ptr_info.packed_offset.bit_offset % limb_abi_bits;
5263 const val_extra_bits = self.regExtraBits(val_ty);5263 const val_extra_bits = self.regExtraBits(val_ty);
52645264
...@@ -5404,7 +5404,7 @@ fn packedStore(self: *Self, ptr_ty: Type, ptr_mcv: MCValue, src_mcv: MCValue) In...@@ -5404,7 +5404,7 @@ fn packedStore(self: *Self, ptr_ty: Type, ptr_mcv: MCValue, src_mcv: MCValue) In
5404 const limb_abi_bits = limb_abi_size * 8;5404 const limb_abi_bits = limb_abi_size * 8;
54055405
5406 const src_bit_size = src_ty.bitSize(mod);5406 const src_bit_size = src_ty.bitSize(mod);
5407 const src_byte_off = @intCast(i32, ptr_info.packed_offset.bit_offset / limb_abi_bits * limb_abi_size);5407 const src_byte_off = @as(i32, @intCast(ptr_info.packed_offset.bit_offset / limb_abi_bits * limb_abi_size));
5408 const src_bit_off = ptr_info.packed_offset.bit_offset % limb_abi_bits;5408 const src_bit_off = ptr_info.packed_offset.bit_offset % limb_abi_bits;
54095409
5410 const ptr_reg = try self.copyToTmpRegister(ptr_ty, ptr_mcv);5410 const ptr_reg = try self.copyToTmpRegister(ptr_ty, ptr_mcv);
...@@ -5421,13 +5421,13 @@ fn packedStore(self: *Self, ptr_ty: Type, ptr_mcv: MCValue, src_mcv: MCValue) In...@@ -5421,13 +5421,13 @@ fn packedStore(self: *Self, ptr_ty: Type, ptr_mcv: MCValue, src_mcv: MCValue) In
5421 .disp = src_byte_off + limb_i * limb_abi_bits,5421 .disp = src_byte_off + limb_i * limb_abi_bits,
5422 });5422 });
54235423
5424 const part_mask = (@as(u64, math.maxInt(u64)) >> @intCast(u6, 64 - part_bit_size)) <<5424 const part_mask = (@as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - part_bit_size))) <<
5425 @intCast(u6, part_bit_off);5425 @as(u6, @intCast(part_bit_off));
5426 const part_mask_not = part_mask ^5426 const part_mask_not = part_mask ^
5427 (@as(u64, math.maxInt(u64)) >> @intCast(u6, 64 - limb_abi_bits));5427 (@as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - limb_abi_bits)));
5428 if (limb_abi_size <= 4) {5428 if (limb_abi_size <= 4) {
5429 try self.asmMemoryImmediate(.{ ._, .@"and" }, limb_mem, Immediate.u(part_mask_not));5429 try self.asmMemoryImmediate(.{ ._, .@"and" }, limb_mem, Immediate.u(part_mask_not));
5430 } else if (math.cast(i32, @bitCast(i64, part_mask_not))) |small| {5430 } else if (math.cast(i32, @as(i64, @bitCast(part_mask_not)))) |small| {
5431 try self.asmMemoryImmediate(.{ ._, .@"and" }, limb_mem, Immediate.s(small));5431 try self.asmMemoryImmediate(.{ ._, .@"and" }, limb_mem, Immediate.s(small));
5432 } else {5432 } else {
5433 const part_mask_reg = try self.register_manager.allocReg(null, gp);5433 const part_mask_reg = try self.register_manager.allocReg(null, gp);
...@@ -5542,14 +5542,14 @@ fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32...@@ -5542,14 +5542,14 @@ fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32
5542 const ptr_field_ty = self.typeOfIndex(inst);5542 const ptr_field_ty = self.typeOfIndex(inst);
5543 const ptr_container_ty = self.typeOf(operand);5543 const ptr_container_ty = self.typeOf(operand);
5544 const container_ty = ptr_container_ty.childType(mod);5544 const container_ty = ptr_container_ty.childType(mod);
5545 const field_offset = @intCast(i32, switch (container_ty.containerLayout(mod)) {5545 const field_offset = @as(i32, @intCast(switch (container_ty.containerLayout(mod)) {
5546 .Auto, .Extern => container_ty.structFieldOffset(index, mod),5546 .Auto, .Extern => container_ty.structFieldOffset(index, mod),
5547 .Packed => if (container_ty.zigTypeTag(mod) == .Struct and5547 .Packed => if (container_ty.zigTypeTag(mod) == .Struct and
5548 ptr_field_ty.ptrInfo(mod).packed_offset.host_size == 0)5548 ptr_field_ty.ptrInfo(mod).packed_offset.host_size == 0)
5549 container_ty.packedStructFieldByteOffset(index, mod)5549 container_ty.packedStructFieldByteOffset(index, mod)
5550 else5550 else
5551 0,5551 0,
5552 });5552 }));
55535553
5554 const src_mcv = try self.resolveInst(operand);5554 const src_mcv = try self.resolveInst(operand);
5555 const dst_mcv = if (switch (src_mcv) {5555 const dst_mcv = if (switch (src_mcv) {
...@@ -5577,7 +5577,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -5577,7 +5577,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
55775577
5578 const src_mcv = try self.resolveInst(operand);5578 const src_mcv = try self.resolveInst(operand);
5579 const field_off = switch (container_ty.containerLayout(mod)) {5579 const field_off = switch (container_ty.containerLayout(mod)) {
5580 .Auto, .Extern => @intCast(u32, container_ty.structFieldOffset(index, mod) * 8),5580 .Auto, .Extern => @as(u32, @intCast(container_ty.structFieldOffset(index, mod) * 8)),
5581 .Packed => if (mod.typeToStruct(container_ty)) |struct_obj|5581 .Packed => if (mod.typeToStruct(container_ty)) |struct_obj|
5582 struct_obj.packedFieldBitOffset(mod, index)5582 struct_obj.packedFieldBitOffset(mod, index)
5583 else5583 else
...@@ -5588,7 +5588,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -5588,7 +5588,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
5588 .load_frame => |frame_addr| {5588 .load_frame => |frame_addr| {
5589 if (field_off % 8 == 0) {5589 if (field_off % 8 == 0) {
5590 const off_mcv =5590 const off_mcv =
5591 src_mcv.address().offset(@intCast(i32, @divExact(field_off, 8))).deref();5591 src_mcv.address().offset(@as(i32, @intCast(@divExact(field_off, 8)))).deref();
5592 if (self.reuseOperand(inst, operand, 0, src_mcv)) break :result off_mcv;5592 if (self.reuseOperand(inst, operand, 0, src_mcv)) break :result off_mcv;
55935593
5594 const dst_mcv = try self.allocRegOrMem(inst, true);5594 const dst_mcv = try self.allocRegOrMem(inst, true);
...@@ -5596,10 +5596,10 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -5596,10 +5596,10 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
5596 break :result dst_mcv;5596 break :result dst_mcv;
5597 }5597 }
55985598
5599 const field_abi_size = @intCast(u32, field_ty.abiSize(mod));5599 const field_abi_size = @as(u32, @intCast(field_ty.abiSize(mod)));
5600 const limb_abi_size: u32 = @min(field_abi_size, 8);5600 const limb_abi_size: u32 = @min(field_abi_size, 8);
5601 const limb_abi_bits = limb_abi_size * 8;5601 const limb_abi_bits = limb_abi_size * 8;
5602 const field_byte_off = @intCast(i32, field_off / limb_abi_bits * limb_abi_size);5602 const field_byte_off = @as(i32, @intCast(field_off / limb_abi_bits * limb_abi_size));
5603 const field_bit_off = field_off % limb_abi_bits;5603 const field_bit_off = field_off % limb_abi_bits;
56045604
5605 if (field_abi_size > 8) {5605 if (field_abi_size > 8) {
...@@ -5643,7 +5643,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -5643,7 +5643,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
5643 tmp_reg,5643 tmp_reg,
5644 Memory.sib(Memory.PtrSize.fromSize(field_abi_size), .{5644 Memory.sib(Memory.PtrSize.fromSize(field_abi_size), .{
5645 .base = .{ .frame = frame_addr.index },5645 .base = .{ .frame = frame_addr.index },
5646 .disp = frame_addr.off + field_byte_off + @intCast(i32, limb_abi_size),5646 .disp = frame_addr.off + field_byte_off + @as(i32, @intCast(limb_abi_size)),
5647 }),5647 }),
5648 );5648 );
5649 try self.asmRegisterRegisterImmediate(5649 try self.asmRegisterRegisterImmediate(
...@@ -5724,7 +5724,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -5724,7 +5724,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
57245724
5725 const inst_ty = self.typeOfIndex(inst);5725 const inst_ty = self.typeOfIndex(inst);
5726 const parent_ty = inst_ty.childType(mod);5726 const parent_ty = inst_ty.childType(mod);
5727 const field_offset = @intCast(i32, parent_ty.structFieldOffset(extra.field_index, mod));5727 const field_offset = @as(i32, @intCast(parent_ty.structFieldOffset(extra.field_index, mod)));
57285728
5729 const src_mcv = try self.resolveInst(extra.field_ptr);5729 const src_mcv = try self.resolveInst(extra.field_ptr);
5730 const dst_mcv = if (src_mcv.isRegisterOffset() and5730 const dst_mcv = if (src_mcv.isRegisterOffset() and
...@@ -5773,14 +5773,14 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:...@@ -5773,14 +5773,14 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:
57735773
5774 switch (tag) {5774 switch (tag) {
5775 .not => {5775 .not => {
5776 const limb_abi_size = @intCast(u16, @min(src_ty.abiSize(mod), 8));5776 const limb_abi_size = @as(u16, @intCast(@min(src_ty.abiSize(mod), 8)));
5777 const int_info = if (src_ty.ip_index == .bool_type)5777 const int_info = if (src_ty.ip_index == .bool_type)
5778 std.builtin.Type.Int{ .signedness = .unsigned, .bits = 1 }5778 std.builtin.Type.Int{ .signedness = .unsigned, .bits = 1 }
5779 else5779 else
5780 src_ty.intInfo(mod);5780 src_ty.intInfo(mod);
5781 var byte_off: i32 = 0;5781 var byte_off: i32 = 0;
5782 while (byte_off * 8 < int_info.bits) : (byte_off += limb_abi_size) {5782 while (byte_off * 8 < int_info.bits) : (byte_off += limb_abi_size) {
5783 const limb_bits = @intCast(u16, @min(int_info.bits - byte_off * 8, limb_abi_size * 8));5783 const limb_bits = @as(u16, @intCast(@min(int_info.bits - byte_off * 8, limb_abi_size * 8)));
5784 const limb_ty = try mod.intType(int_info.signedness, limb_bits);5784 const limb_ty = try mod.intType(int_info.signedness, limb_bits);
5785 const limb_mcv = switch (byte_off) {5785 const limb_mcv = switch (byte_off) {
5786 0 => dst_mcv,5786 0 => dst_mcv,
...@@ -5788,7 +5788,7 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:...@@ -5788,7 +5788,7 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:
5788 };5788 };
57895789
5790 if (int_info.signedness == .unsigned and self.regExtraBits(limb_ty) > 0) {5790 if (int_info.signedness == .unsigned and self.regExtraBits(limb_ty) > 0) {
5791 const mask = @as(u64, math.maxInt(u64)) >> @intCast(u6, 64 - limb_bits);5791 const mask = @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - limb_bits));
5792 try self.genBinOpMir(.{ ._, .xor }, limb_ty, limb_mcv, .{ .immediate = mask });5792 try self.genBinOpMir(.{ ._, .xor }, limb_ty, limb_mcv, .{ .immediate = mask });
5793 } else try self.genUnOpMir(.{ ._, .not }, limb_ty, limb_mcv);5793 } else try self.genUnOpMir(.{ ._, .not }, limb_ty, limb_mcv);
5794 }5794 }
...@@ -5801,7 +5801,7 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:...@@ -5801,7 +5801,7 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:
58015801
5802fn genUnOpMir(self: *Self, mir_tag: Mir.Inst.FixedTag, dst_ty: Type, dst_mcv: MCValue) !void {5802fn genUnOpMir(self: *Self, mir_tag: Mir.Inst.FixedTag, dst_ty: Type, dst_mcv: MCValue) !void {
5803 const mod = self.bin_file.options.module.?;5803 const mod = self.bin_file.options.module.?;
5804 const abi_size = @intCast(u32, dst_ty.abiSize(mod));5804 const abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
5805 if (abi_size > 8) return self.fail("TODO implement {} for {}", .{5805 if (abi_size > 8) return self.fail("TODO implement {} for {}", .{
5806 mir_tag,5806 mir_tag,
5807 dst_ty.fmt(self.bin_file.options.module.?),5807 dst_ty.fmt(self.bin_file.options.module.?),
...@@ -5863,7 +5863,7 @@ fn genShiftBinOpMir(...@@ -5863,7 +5863,7 @@ fn genShiftBinOpMir(
5863 break :rhs .{ .register = .rcx };5863 break :rhs .{ .register = .rcx };
5864 };5864 };
58655865
5866 const abi_size = @intCast(u32, ty.abiSize(mod));5866 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
5867 if (abi_size <= 8) {5867 if (abi_size <= 8) {
5868 switch (lhs_mcv) {5868 switch (lhs_mcv) {
5869 .register => |lhs_reg| switch (rhs_mcv) {5869 .register => |lhs_reg| switch (rhs_mcv) {
...@@ -5886,7 +5886,7 @@ fn genShiftBinOpMir(...@@ -5886,7 +5886,7 @@ fn genShiftBinOpMir(
5886 const lhs_mem = Memory.sib(Memory.PtrSize.fromSize(abi_size), switch (lhs_mcv) {5886 const lhs_mem = Memory.sib(Memory.PtrSize.fromSize(abi_size), switch (lhs_mcv) {
5887 .memory => |addr| .{5887 .memory => |addr| .{
5888 .base = .{ .reg = .ds },5888 .base = .{ .reg = .ds },
5889 .disp = math.cast(i32, @bitCast(i64, addr)) orelse5889 .disp = math.cast(i32, @as(i64, @bitCast(addr))) orelse
5890 return self.fail("TODO genShiftBinOpMir between {s} and {s}", .{5890 return self.fail("TODO genShiftBinOpMir between {s} and {s}", .{
5891 @tagName(lhs_mcv),5891 @tagName(lhs_mcv),
5892 @tagName(rhs_mcv),5892 @tagName(rhs_mcv),
...@@ -6151,8 +6151,8 @@ fn genMulDivBinOp(...@@ -6151,8 +6151,8 @@ fn genMulDivBinOp(
6151 if (dst_ty.zigTypeTag(mod) == .Vector or dst_ty.zigTypeTag(mod) == .Float) {6151 if (dst_ty.zigTypeTag(mod) == .Vector or dst_ty.zigTypeTag(mod) == .Float) {
6152 return self.fail("TODO implement genMulDivBinOp for {}", .{dst_ty.fmtDebug()});6152 return self.fail("TODO implement genMulDivBinOp for {}", .{dst_ty.fmtDebug()});
6153 }6153 }
6154 const dst_abi_size = @intCast(u32, dst_ty.abiSize(mod));6154 const dst_abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
6155 const src_abi_size = @intCast(u32, src_ty.abiSize(mod));6155 const src_abi_size = @as(u32, @intCast(src_ty.abiSize(mod)));
6156 if (switch (tag) {6156 if (switch (tag) {
6157 else => unreachable,6157 else => unreachable,
6158 .mul, .mulwrap => dst_abi_size != src_abi_size and dst_abi_size != src_abi_size * 2,6158 .mul, .mulwrap => dst_abi_size != src_abi_size and dst_abi_size != src_abi_size * 2,
...@@ -6326,7 +6326,7 @@ fn genBinOp(...@@ -6326,7 +6326,7 @@ fn genBinOp(
6326 const mod = self.bin_file.options.module.?;6326 const mod = self.bin_file.options.module.?;
6327 const lhs_ty = self.typeOf(lhs_air);6327 const lhs_ty = self.typeOf(lhs_air);
6328 const rhs_ty = self.typeOf(rhs_air);6328 const rhs_ty = self.typeOf(rhs_air);
6329 const abi_size = @intCast(u32, lhs_ty.abiSize(mod));6329 const abi_size = @as(u32, @intCast(lhs_ty.abiSize(mod)));
63306330
6331 const maybe_mask_reg = switch (air_tag) {6331 const maybe_mask_reg = switch (air_tag) {
6332 else => null,6332 else => null,
...@@ -6481,7 +6481,7 @@ fn genBinOp(...@@ -6481,7 +6481,7 @@ fn genBinOp(
6481 .lea_tlv,6481 .lea_tlv,
6482 .lea_frame,6482 .lea_frame,
6483 => true,6483 => true,
6484 .memory => |addr| math.cast(i32, @bitCast(i64, addr)) == null,6484 .memory => |addr| math.cast(i32, @as(i64, @bitCast(addr))) == null,
6485 else => false,6485 else => false,
6486 }) .{ .register = try self.copyToTmpRegister(rhs_ty, src_mcv) } else src_mcv;6486 }) .{ .register = try self.copyToTmpRegister(rhs_ty, src_mcv) } else src_mcv;
6487 const mat_mcv_lock = switch (mat_src_mcv) {6487 const mat_mcv_lock = switch (mat_src_mcv) {
...@@ -6506,7 +6506,7 @@ fn genBinOp(...@@ -6506,7 +6506,7 @@ fn genBinOp(
6506 },6506 },
6507 };6507 };
65086508
6509 const cmov_abi_size = @max(@intCast(u32, lhs_ty.abiSize(mod)), 2);6509 const cmov_abi_size = @max(@as(u32, @intCast(lhs_ty.abiSize(mod))), 2);
6510 const tmp_reg = switch (dst_mcv) {6510 const tmp_reg = switch (dst_mcv) {
6511 .register => |reg| reg,6511 .register => |reg| reg,
6512 else => try self.copyToTmpRegister(lhs_ty, dst_mcv),6512 else => try self.copyToTmpRegister(lhs_ty, dst_mcv),
...@@ -6541,7 +6541,7 @@ fn genBinOp(...@@ -6541,7 +6541,7 @@ fn genBinOp(
6541 Memory.sib(Memory.PtrSize.fromSize(cmov_abi_size), switch (mat_src_mcv) {6541 Memory.sib(Memory.PtrSize.fromSize(cmov_abi_size), switch (mat_src_mcv) {
6542 .memory => |addr| .{6542 .memory => |addr| .{
6543 .base = .{ .reg = .ds },6543 .base = .{ .reg = .ds },
6544 .disp = @intCast(i32, @bitCast(i64, addr)),6544 .disp = @as(i32, @intCast(@as(i64, @bitCast(addr)))),
6545 },6545 },
6546 .indirect => |reg_off| .{6546 .indirect => |reg_off| .{
6547 .base = .{ .reg = reg_off.reg },6547 .base = .{ .reg = reg_off.reg },
...@@ -7429,7 +7429,7 @@ fn genBinOpMir(...@@ -7429,7 +7429,7 @@ fn genBinOpMir(
7429 src_mcv: MCValue,7429 src_mcv: MCValue,
7430) !void {7430) !void {
7431 const mod = self.bin_file.options.module.?;7431 const mod = self.bin_file.options.module.?;
7432 const abi_size = @intCast(u32, ty.abiSize(mod));7432 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
7433 switch (dst_mcv) {7433 switch (dst_mcv) {
7434 .none,7434 .none,
7435 .unreach,7435 .unreach,
...@@ -7465,28 +7465,28 @@ fn genBinOpMir(...@@ -7465,28 +7465,28 @@ fn genBinOpMir(
7465 8 => try self.asmRegisterImmediate(7465 8 => try self.asmRegisterImmediate(
7466 mir_tag,7466 mir_tag,
7467 dst_alias,7467 dst_alias,
7468 if (math.cast(i8, @bitCast(i64, imm))) |small|7468 if (math.cast(i8, @as(i64, @bitCast(imm)))) |small|
7469 Immediate.s(small)7469 Immediate.s(small)
7470 else7470 else
7471 Immediate.u(@intCast(u8, imm)),7471 Immediate.u(@as(u8, @intCast(imm))),
7472 ),7472 ),
7473 16 => try self.asmRegisterImmediate(7473 16 => try self.asmRegisterImmediate(
7474 mir_tag,7474 mir_tag,
7475 dst_alias,7475 dst_alias,
7476 if (math.cast(i16, @bitCast(i64, imm))) |small|7476 if (math.cast(i16, @as(i64, @bitCast(imm)))) |small|
7477 Immediate.s(small)7477 Immediate.s(small)
7478 else7478 else
7479 Immediate.u(@intCast(u16, imm)),7479 Immediate.u(@as(u16, @intCast(imm))),
7480 ),7480 ),
7481 32 => try self.asmRegisterImmediate(7481 32 => try self.asmRegisterImmediate(
7482 mir_tag,7482 mir_tag,
7483 dst_alias,7483 dst_alias,
7484 if (math.cast(i32, @bitCast(i64, imm))) |small|7484 if (math.cast(i32, @as(i64, @bitCast(imm)))) |small|
7485 Immediate.s(small)7485 Immediate.s(small)
7486 else7486 else
7487 Immediate.u(@intCast(u32, imm)),7487 Immediate.u(@as(u32, @intCast(imm))),
7488 ),7488 ),
7489 64 => if (math.cast(i32, @bitCast(i64, imm))) |small|7489 64 => if (math.cast(i32, @as(i64, @bitCast(imm)))) |small|
7490 try self.asmRegisterImmediate(mir_tag, dst_alias, Immediate.s(small))7490 try self.asmRegisterImmediate(mir_tag, dst_alias, Immediate.s(small))
7491 else7491 else
7492 try self.asmRegisterRegister(mir_tag, dst_alias, registerAlias(7492 try self.asmRegisterRegister(mir_tag, dst_alias, registerAlias(
...@@ -7602,8 +7602,8 @@ fn genBinOpMir(...@@ -7602,8 +7602,8 @@ fn genBinOpMir(
7602 => null,7602 => null,
7603 .memory, .load_got, .load_direct, .load_tlv => src: {7603 .memory, .load_got, .load_direct, .load_tlv => src: {
7604 switch (src_mcv) {7604 switch (src_mcv) {
7605 .memory => |addr| if (math.cast(i32, @bitCast(i64, addr)) != null and7605 .memory => |addr| if (math.cast(i32, @as(i64, @bitCast(addr))) != null and
7606 math.cast(i32, @bitCast(i64, addr) + abi_size - limb_abi_size) != null)7606 math.cast(i32, @as(i64, @bitCast(addr)) + abi_size - limb_abi_size) != null)
7607 break :src null,7607 break :src null,
7608 .load_got, .load_direct, .load_tlv => {},7608 .load_got, .load_direct, .load_tlv => {},
7609 else => unreachable,7609 else => unreachable,
...@@ -7680,7 +7680,7 @@ fn genBinOpMir(...@@ -7680,7 +7680,7 @@ fn genBinOpMir(
7680 const imm = switch (off) {7680 const imm = switch (off) {
7681 0 => src_imm,7681 0 => src_imm,
7682 else => switch (ty_signedness) {7682 else => switch (ty_signedness) {
7683 .signed => @bitCast(u64, @bitCast(i64, src_imm) >> 63),7683 .signed => @as(u64, @bitCast(@as(i64, @bitCast(src_imm)) >> 63)),
7684 .unsigned => 0,7684 .unsigned => 0,
7685 },7685 },
7686 };7686 };
...@@ -7688,28 +7688,28 @@ fn genBinOpMir(...@@ -7688,28 +7688,28 @@ fn genBinOpMir(
7688 8 => try self.asmMemoryImmediate(7688 8 => try self.asmMemoryImmediate(
7689 mir_limb_tag,7689 mir_limb_tag,
7690 dst_limb_mem,7690 dst_limb_mem,
7691 if (math.cast(i8, @bitCast(i64, imm))) |small|7691 if (math.cast(i8, @as(i64, @bitCast(imm)))) |small|
7692 Immediate.s(small)7692 Immediate.s(small)
7693 else7693 else
7694 Immediate.u(@intCast(u8, imm)),7694 Immediate.u(@as(u8, @intCast(imm))),
7695 ),7695 ),
7696 16 => try self.asmMemoryImmediate(7696 16 => try self.asmMemoryImmediate(
7697 mir_limb_tag,7697 mir_limb_tag,
7698 dst_limb_mem,7698 dst_limb_mem,
7699 if (math.cast(i16, @bitCast(i64, imm))) |small|7699 if (math.cast(i16, @as(i64, @bitCast(imm)))) |small|
7700 Immediate.s(small)7700 Immediate.s(small)
7701 else7701 else
7702 Immediate.u(@intCast(u16, imm)),7702 Immediate.u(@as(u16, @intCast(imm))),
7703 ),7703 ),
7704 32 => try self.asmMemoryImmediate(7704 32 => try self.asmMemoryImmediate(
7705 mir_limb_tag,7705 mir_limb_tag,
7706 dst_limb_mem,7706 dst_limb_mem,
7707 if (math.cast(i32, @bitCast(i64, imm))) |small|7707 if (math.cast(i32, @as(i64, @bitCast(imm)))) |small|
7708 Immediate.s(small)7708 Immediate.s(small)
7709 else7709 else
7710 Immediate.u(@intCast(u32, imm)),7710 Immediate.u(@as(u32, @intCast(imm))),
7711 ),7711 ),
7712 64 => if (math.cast(i32, @bitCast(i64, imm))) |small|7712 64 => if (math.cast(i32, @as(i64, @bitCast(imm)))) |small|
7713 try self.asmMemoryImmediate(7713 try self.asmMemoryImmediate(
7714 mir_limb_tag,7714 mir_limb_tag,
7715 dst_limb_mem,7715 dst_limb_mem,
...@@ -7753,7 +7753,7 @@ fn genBinOpMir(...@@ -7753,7 +7753,7 @@ fn genBinOpMir(
7753 0 => src_mcv,7753 0 => src_mcv,
7754 else => .{ .immediate = 0 },7754 else => .{ .immediate = 0 },
7755 },7755 },
7756 .memory => |addr| .{ .memory = @bitCast(u64, @bitCast(i64, addr) + off) },7756 .memory => |addr| .{ .memory = @as(u64, @bitCast(@as(i64, @bitCast(addr)) + off)) },
7757 .indirect => |reg_off| .{ .indirect = .{7757 .indirect => |reg_off| .{ .indirect = .{
7758 .reg = reg_off.reg,7758 .reg = reg_off.reg,
7759 .off = reg_off.off + off,7759 .off = reg_off.off + off,
...@@ -7780,7 +7780,7 @@ fn genBinOpMir(...@@ -7780,7 +7780,7 @@ fn genBinOpMir(
7780/// Does not support byte-size operands.7780/// Does not support byte-size operands.
7781fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError!void {7781fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError!void {
7782 const mod = self.bin_file.options.module.?;7782 const mod = self.bin_file.options.module.?;
7783 const abi_size = @intCast(u32, dst_ty.abiSize(mod));7783 const abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
7784 switch (dst_mcv) {7784 switch (dst_mcv) {
7785 .none,7785 .none,
7786 .unreach,7786 .unreach,
...@@ -7847,7 +7847,7 @@ fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: M...@@ -7847,7 +7847,7 @@ fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: M
7847 Memory.sib(Memory.PtrSize.fromSize(abi_size), switch (src_mcv) {7847 Memory.sib(Memory.PtrSize.fromSize(abi_size), switch (src_mcv) {
7848 .memory => |addr| .{7848 .memory => |addr| .{
7849 .base = .{ .reg = .ds },7849 .base = .{ .reg = .ds },
7850 .disp = math.cast(i32, @bitCast(i64, addr)) orelse7850 .disp = math.cast(i32, @as(i64, @bitCast(addr))) orelse
7851 return self.asmRegisterRegister(7851 return self.asmRegisterRegister(
7852 .{ .i_, .mul },7852 .{ .i_, .mul },
7853 dst_alias,7853 dst_alias,
...@@ -8014,7 +8014,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -8014,7 +8014,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
8014 const pl_op = self.air.instructions.items(.data)[inst].pl_op;8014 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
8015 const callee = pl_op.operand;8015 const callee = pl_op.operand;
8016 const extra = self.air.extraData(Air.Call, pl_op.payload);8016 const extra = self.air.extraData(Air.Call, pl_op.payload);
8017 const args = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra.end..][0..extra.data.args_len]);8017 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));
8018 const ty = self.typeOf(callee);8018 const ty = self.typeOf(callee);
80198019
8020 const fn_ty = switch (ty.zigTypeTag(mod)) {8020 const fn_ty = switch (ty.zigTypeTag(mod)) {
...@@ -8107,7 +8107,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -8107,7 +8107,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
8107 const got_addr = atom.getOffsetTableAddress(elf_file);8107 const got_addr = atom.getOffsetTableAddress(elf_file);
8108 try self.asmMemory(.{ ._, .call }, Memory.sib(.qword, .{8108 try self.asmMemory(.{ ._, .call }, Memory.sib(.qword, .{
8109 .base = .{ .reg = .ds },8109 .base = .{ .reg = .ds },
8110 .disp = @intCast(i32, got_addr),8110 .disp = @as(i32, @intCast(got_addr)),
8111 }));8111 }));
8112 } else if (self.bin_file.cast(link.File.Coff)) |coff_file| {8112 } else if (self.bin_file.cast(link.File.Coff)) |coff_file| {
8113 const atom = try coff_file.getOrCreateAtomForDecl(owner_decl);8113 const atom = try coff_file.getOrCreateAtomForDecl(owner_decl);
...@@ -8124,7 +8124,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -8124,7 +8124,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
8124 const atom = p9.getAtom(atom_index);8124 const atom = p9.getAtom(atom_index);
8125 try self.asmMemory(.{ ._, .call }, Memory.sib(.qword, .{8125 try self.asmMemory(.{ ._, .call }, Memory.sib(.qword, .{
8126 .base = .{ .reg = .ds },8126 .base = .{ .reg = .ds },
8127 .disp = @intCast(i32, atom.getOffsetTableAddress(p9)),8127 .disp = @as(i32, @intCast(atom.getOffsetTableAddress(p9))),
8128 }));8128 }));
8129 } else unreachable;8129 } else unreachable;
8130 } else if (func_value.getExternFunc(mod)) |extern_func| {8130 } else if (func_value.getExternFunc(mod)) |extern_func| {
...@@ -8244,7 +8244,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {...@@ -8244,7 +8244,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
8244 const result = MCValue{8244 const result = MCValue{
8245 .eflags = switch (ty.zigTypeTag(mod)) {8245 .eflags = switch (ty.zigTypeTag(mod)) {
8246 else => result: {8246 else => result: {
8247 const abi_size = @intCast(u16, ty.abiSize(mod));8247 const abi_size = @as(u16, @intCast(ty.abiSize(mod)));
8248 const may_flip: enum {8248 const may_flip: enum {
8249 may_flip,8249 may_flip,
8250 must_flip,8250 must_flip,
...@@ -8441,7 +8441,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {...@@ -8441,7 +8441,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
8441 self.eflags_inst = inst;8441 self.eflags_inst = inst;
84428442
8443 const op_ty = self.typeOf(un_op);8443 const op_ty = self.typeOf(un_op);
8444 const op_abi_size = @intCast(u32, op_ty.abiSize(mod));8444 const op_abi_size = @as(u32, @intCast(op_ty.abiSize(mod)));
8445 const op_mcv = try self.resolveInst(un_op);8445 const op_mcv = try self.resolveInst(un_op);
8446 const dst_reg = switch (op_mcv) {8446 const dst_reg = switch (op_mcv) {
8447 .register => |reg| reg,8447 .register => |reg| reg,
...@@ -8650,7 +8650,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC...@@ -8650,7 +8650,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
8650 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))8650 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))
8651 .{ .off = 0, .ty = if (pl_ty.isSlice(mod)) pl_ty.slicePtrFieldType(mod) else pl_ty }8651 .{ .off = 0, .ty = if (pl_ty.isSlice(mod)) pl_ty.slicePtrFieldType(mod) else pl_ty }
8652 else8652 else
8653 .{ .off = @intCast(i32, pl_ty.abiSize(mod)), .ty = Type.bool };8653 .{ .off = @as(i32, @intCast(pl_ty.abiSize(mod))), .ty = Type.bool };
86548654
8655 switch (opt_mcv) {8655 switch (opt_mcv) {
8656 .none,8656 .none,
...@@ -8670,18 +8670,18 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC...@@ -8670,18 +8670,18 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
86708670
8671 .register => |opt_reg| {8671 .register => |opt_reg| {
8672 if (some_info.off == 0) {8672 if (some_info.off == 0) {
8673 const some_abi_size = @intCast(u32, some_info.ty.abiSize(mod));8673 const some_abi_size = @as(u32, @intCast(some_info.ty.abiSize(mod)));
8674 const alias_reg = registerAlias(opt_reg, some_abi_size);8674 const alias_reg = registerAlias(opt_reg, some_abi_size);
8675 assert(some_abi_size * 8 == alias_reg.bitSize());8675 assert(some_abi_size * 8 == alias_reg.bitSize());
8676 try self.asmRegisterRegister(.{ ._, .@"test" }, alias_reg, alias_reg);8676 try self.asmRegisterRegister(.{ ._, .@"test" }, alias_reg, alias_reg);
8677 return .{ .eflags = .z };8677 return .{ .eflags = .z };
8678 }8678 }
8679 assert(some_info.ty.ip_index == .bool_type);8679 assert(some_info.ty.ip_index == .bool_type);
8680 const opt_abi_size = @intCast(u32, opt_ty.abiSize(mod));8680 const opt_abi_size = @as(u32, @intCast(opt_ty.abiSize(mod)));
8681 try self.asmRegisterImmediate(8681 try self.asmRegisterImmediate(
8682 .{ ._, .bt },8682 .{ ._, .bt },
8683 registerAlias(opt_reg, opt_abi_size),8683 registerAlias(opt_reg, opt_abi_size),
8684 Immediate.u(@intCast(u6, some_info.off * 8)),8684 Immediate.u(@as(u6, @intCast(some_info.off * 8))),
8685 );8685 );
8686 return .{ .eflags = .nc };8686 return .{ .eflags = .nc };
8687 },8687 },
...@@ -8696,7 +8696,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC...@@ -8696,7 +8696,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
8696 defer self.register_manager.unlockReg(addr_reg_lock);8696 defer self.register_manager.unlockReg(addr_reg_lock);
86978697
8698 try self.genSetReg(addr_reg, Type.usize, opt_mcv.address());8698 try self.genSetReg(addr_reg, Type.usize, opt_mcv.address());
8699 const some_abi_size = @intCast(u32, some_info.ty.abiSize(mod));8699 const some_abi_size = @as(u32, @intCast(some_info.ty.abiSize(mod)));
8700 try self.asmMemoryImmediate(8700 try self.asmMemoryImmediate(
8701 .{ ._, .cmp },8701 .{ ._, .cmp },
8702 Memory.sib(Memory.PtrSize.fromSize(some_abi_size), .{8702 Memory.sib(Memory.PtrSize.fromSize(some_abi_size), .{
...@@ -8709,7 +8709,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC...@@ -8709,7 +8709,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
8709 },8709 },
87108710
8711 .indirect, .load_frame => {8711 .indirect, .load_frame => {
8712 const some_abi_size = @intCast(u32, some_info.ty.abiSize(mod));8712 const some_abi_size = @as(u32, @intCast(some_info.ty.abiSize(mod)));
8713 try self.asmMemoryImmediate(8713 try self.asmMemoryImmediate(
8714 .{ ._, .cmp },8714 .{ ._, .cmp },
8715 Memory.sib(Memory.PtrSize.fromSize(some_abi_size), switch (opt_mcv) {8715 Memory.sib(Memory.PtrSize.fromSize(some_abi_size), switch (opt_mcv) {
...@@ -8741,7 +8741,7 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue)...@@ -8741,7 +8741,7 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue)
8741 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))8741 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))
8742 .{ .off = 0, .ty = if (pl_ty.isSlice(mod)) pl_ty.slicePtrFieldType(mod) else pl_ty }8742 .{ .off = 0, .ty = if (pl_ty.isSlice(mod)) pl_ty.slicePtrFieldType(mod) else pl_ty }
8743 else8743 else
8744 .{ .off = @intCast(i32, pl_ty.abiSize(mod)), .ty = Type.bool };8744 .{ .off = @as(i32, @intCast(pl_ty.abiSize(mod))), .ty = Type.bool };
87458745
8746 const ptr_reg = switch (ptr_mcv) {8746 const ptr_reg = switch (ptr_mcv) {
8747 .register => |reg| reg,8747 .register => |reg| reg,
...@@ -8750,7 +8750,7 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue)...@@ -8750,7 +8750,7 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue)
8750 const ptr_lock = self.register_manager.lockReg(ptr_reg);8750 const ptr_lock = self.register_manager.lockReg(ptr_reg);
8751 defer if (ptr_lock) |lock| self.register_manager.unlockReg(lock);8751 defer if (ptr_lock) |lock| self.register_manager.unlockReg(lock);
87528752
8753 const some_abi_size = @intCast(u32, some_info.ty.abiSize(mod));8753 const some_abi_size = @as(u32, @intCast(some_info.ty.abiSize(mod)));
8754 try self.asmMemoryImmediate(8754 try self.asmMemoryImmediate(
8755 .{ ._, .cmp },8755 .{ ._, .cmp },
8756 Memory.sib(Memory.PtrSize.fromSize(some_abi_size), .{8756 Memory.sib(Memory.PtrSize.fromSize(some_abi_size), .{
...@@ -8783,7 +8783,7 @@ fn isErr(self: *Self, maybe_inst: ?Air.Inst.Index, ty: Type, operand: MCValue) !...@@ -8783,7 +8783,7 @@ fn isErr(self: *Self, maybe_inst: ?Air.Inst.Index, ty: Type, operand: MCValue) !
87838783
8784 const tmp_reg = try self.copyToTmpRegister(ty, operand);8784 const tmp_reg = try self.copyToTmpRegister(ty, operand);
8785 if (err_off > 0) {8785 if (err_off > 0) {
8786 const shift = @intCast(u6, err_off * 8);8786 const shift = @as(u6, @intCast(err_off * 8));
8787 try self.genShiftBinOpMir(8787 try self.genShiftBinOpMir(
8788 .{ ._r, .sh },8788 .{ ._r, .sh },
8789 ty,8789 ty,
...@@ -8805,7 +8805,7 @@ fn isErr(self: *Self, maybe_inst: ?Air.Inst.Index, ty: Type, operand: MCValue) !...@@ -8805,7 +8805,7 @@ fn isErr(self: *Self, maybe_inst: ?Air.Inst.Index, ty: Type, operand: MCValue) !
8805 Type.anyerror,8805 Type.anyerror,
8806 .{ .load_frame = .{8806 .{ .load_frame = .{
8807 .index = frame_addr.index,8807 .index = frame_addr.index,
8808 .off = frame_addr.off + @intCast(i32, err_off),8808 .off = frame_addr.off + @as(i32, @intCast(err_off)),
8809 } },8809 } },
8810 .{ .immediate = 0 },8810 .{ .immediate = 0 },
8811 ),8811 ),
...@@ -8943,7 +8943,7 @@ fn airLoop(self: *Self, inst: Air.Inst.Index) !void {...@@ -8943,7 +8943,7 @@ fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
8943 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;8943 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
8944 const loop = self.air.extraData(Air.Block, ty_pl.payload);8944 const loop = self.air.extraData(Air.Block, ty_pl.payload);
8945 const body = self.air.extra[loop.end..][0..loop.data.body_len];8945 const body = self.air.extra[loop.end..][0..loop.data.body_len];
8946 const jmp_target = @intCast(u32, self.mir_instructions.len);8946 const jmp_target = @as(u32, @intCast(self.mir_instructions.len));
89478947
8948 self.scope_generation += 1;8948 self.scope_generation += 1;
8949 const state = try self.saveState();8949 const state = try self.saveState();
...@@ -9015,9 +9015,9 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -9015,9 +9015,9 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {
90159015
9016 while (case_i < switch_br.data.cases_len) : (case_i += 1) {9016 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
9017 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);9017 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
9018 const items = @ptrCast(9018 const items = @as(
9019 []const Air.Inst.Ref,9019 []const Air.Inst.Ref,
9020 self.air.extra[case.end..][0..case.data.items_len],9020 @ptrCast(self.air.extra[case.end..][0..case.data.items_len]),
9021 );9021 );
9022 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];9022 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
9023 extra_index = case.end + items.len + case_body.len;9023 extra_index = case.end + items.len + case_body.len;
...@@ -9066,7 +9066,7 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -9066,7 +9066,7 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {
9066}9066}
90679067
9068fn performReloc(self: *Self, reloc: Mir.Inst.Index) !void {9068fn performReloc(self: *Self, reloc: Mir.Inst.Index) !void {
9069 const next_inst = @intCast(u32, self.mir_instructions.len);9069 const next_inst = @as(u32, @intCast(self.mir_instructions.len));
9070 switch (self.mir_instructions.items(.tag)[reloc]) {9070 switch (self.mir_instructions.items(.tag)[reloc]) {
9071 .j, .jmp => {},9071 .j, .jmp => {},
9072 .pseudo => switch (self.mir_instructions.items(.ops)[reloc]) {9072 .pseudo => switch (self.mir_instructions.items(.ops)[reloc]) {
...@@ -9141,11 +9141,11 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -9141,11 +9141,11 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {
9141fn airAsm(self: *Self, inst: Air.Inst.Index) !void {9141fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
9142 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;9142 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
9143 const extra = self.air.extraData(Air.Asm, ty_pl.payload);9143 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
9144 const clobbers_len = @truncate(u31, extra.data.flags);9144 const clobbers_len = @as(u31, @truncate(extra.data.flags));
9145 var extra_i: usize = extra.end;9145 var extra_i: usize = extra.end;
9146 const outputs = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra_i..][0..extra.data.outputs_len]);9146 const outputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]));
9147 extra_i += outputs.len;9147 extra_i += outputs.len;
9148 const inputs = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra_i..][0..extra.data.inputs_len]);9148 const inputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]));
9149 extra_i += inputs.len;9149 extra_i += inputs.len;
91509150
9151 var result: MCValue = .none;9151 var result: MCValue = .none;
...@@ -9281,7 +9281,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -9281,7 +9281,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
9281 if (std.fmt.parseInt(i32, op_str["$".len..], 0)) |s| {9281 if (std.fmt.parseInt(i32, op_str["$".len..], 0)) |s| {
9282 if (mnem_size) |size| {9282 if (mnem_size) |size| {
9283 const max = @as(u64, math.maxInt(u64)) >>9283 const max = @as(u64, math.maxInt(u64)) >>
9284 @intCast(u6, 64 - (size.bitSize() - 1));9284 @as(u6, @intCast(64 - (size.bitSize() - 1)));
9285 if ((if (s < 0) ~s else s) > max)9285 if ((if (s < 0) ~s else s) > max)
9286 return self.fail("Invalid immediate size: '{s}'", .{op_str});9286 return self.fail("Invalid immediate size: '{s}'", .{op_str});
9287 }9287 }
...@@ -9289,7 +9289,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -9289,7 +9289,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
9289 } else |_| if (std.fmt.parseInt(u64, op_str["$".len..], 0)) |u| {9289 } else |_| if (std.fmt.parseInt(u64, op_str["$".len..], 0)) |u| {
9290 if (mnem_size) |size| {9290 if (mnem_size) |size| {
9291 const max = @as(u64, math.maxInt(u64)) >>9291 const max = @as(u64, math.maxInt(u64)) >>
9292 @intCast(u6, 64 - size.bitSize());9292 @as(u6, @intCast(64 - size.bitSize()));
9293 if (u > max)9293 if (u > max)
9294 return self.fail("Invalid immediate size: '{s}'", .{op_str});9294 return self.fail("Invalid immediate size: '{s}'", .{op_str});
9295 }9295 }
...@@ -9618,7 +9618,7 @@ fn genCopy(self: *Self, ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError...@@ -9618,7 +9618,7 @@ fn genCopy(self: *Self, ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError
9618 .indirect => |reg_off| try self.genSetMem(.{ .reg = reg_off.reg }, reg_off.off, ty, src_mcv),9618 .indirect => |reg_off| try self.genSetMem(.{ .reg = reg_off.reg }, reg_off.off, ty, src_mcv),
9619 .memory, .load_direct, .load_got, .load_tlv => {9619 .memory, .load_direct, .load_got, .load_tlv => {
9620 switch (dst_mcv) {9620 switch (dst_mcv) {
9621 .memory => |addr| if (math.cast(i32, @bitCast(i64, addr))) |small_addr|9621 .memory => |addr| if (math.cast(i32, @as(i64, @bitCast(addr)))) |small_addr|
9622 return self.genSetMem(.{ .reg = .ds }, small_addr, ty, src_mcv),9622 return self.genSetMem(.{ .reg = .ds }, small_addr, ty, src_mcv),
9623 .load_direct, .load_got, .load_tlv => {},9623 .load_direct, .load_got, .load_tlv => {},
9624 else => unreachable,9624 else => unreachable,
...@@ -9641,7 +9641,7 @@ fn genCopy(self: *Self, ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError...@@ -9641,7 +9641,7 @@ fn genCopy(self: *Self, ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError
96419641
9642fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerError!void {9642fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerError!void {
9643 const mod = self.bin_file.options.module.?;9643 const mod = self.bin_file.options.module.?;
9644 const abi_size = @intCast(u32, ty.abiSize(mod));9644 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
9645 if (abi_size * 8 > dst_reg.bitSize())9645 if (abi_size * 8 > dst_reg.bitSize())
9646 return self.fail("genSetReg called with a value larger than dst_reg", .{});9646 return self.fail("genSetReg called with a value larger than dst_reg", .{});
9647 switch (src_mcv) {9647 switch (src_mcv) {
...@@ -9662,11 +9662,11 @@ fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerEr...@@ -9662,11 +9662,11 @@ fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerEr
9662 } else if (abi_size > 4 and math.cast(u32, imm) != null) {9662 } else if (abi_size > 4 and math.cast(u32, imm) != null) {
9663 // 32-bit moves zero-extend to 64-bit.9663 // 32-bit moves zero-extend to 64-bit.
9664 try self.asmRegisterImmediate(.{ ._, .mov }, dst_reg.to32(), Immediate.u(imm));9664 try self.asmRegisterImmediate(.{ ._, .mov }, dst_reg.to32(), Immediate.u(imm));
9665 } else if (abi_size <= 4 and @bitCast(i64, imm) < 0) {9665 } else if (abi_size <= 4 and @as(i64, @bitCast(imm)) < 0) {
9666 try self.asmRegisterImmediate(9666 try self.asmRegisterImmediate(
9667 .{ ._, .mov },9667 .{ ._, .mov },
9668 registerAlias(dst_reg, abi_size),9668 registerAlias(dst_reg, abi_size),
9669 Immediate.s(@intCast(i32, @bitCast(i64, imm))),9669 Immediate.s(@as(i32, @intCast(@as(i64, @bitCast(imm))))),
9670 );9670 );
9671 } else {9671 } else {
9672 try self.asmRegisterImmediate(9672 try self.asmRegisterImmediate(
...@@ -9806,7 +9806,7 @@ fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerEr...@@ -9806,7 +9806,7 @@ fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerEr
9806 },9806 },
9807 .memory, .load_direct, .load_got, .load_tlv => {9807 .memory, .load_direct, .load_got, .load_tlv => {
9808 switch (src_mcv) {9808 switch (src_mcv) {
9809 .memory => |addr| if (math.cast(i32, @bitCast(i64, addr))) |small_addr| {9809 .memory => |addr| if (math.cast(i32, @as(i64, @bitCast(addr)))) |small_addr| {
9810 const dst_alias = registerAlias(dst_reg, abi_size);9810 const dst_alias = registerAlias(dst_reg, abi_size);
9811 const src_mem = Memory.sib(Memory.PtrSize.fromSize(abi_size), .{9811 const src_mem = Memory.sib(Memory.PtrSize.fromSize(abi_size), .{
9812 .base = .{ .reg = .ds },9812 .base = .{ .reg = .ds },
...@@ -9814,7 +9814,7 @@ fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerEr...@@ -9814,7 +9814,7 @@ fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerEr
9814 });9814 });
9815 switch (try self.moveStrategy(ty, mem.isAlignedGeneric(9815 switch (try self.moveStrategy(ty, mem.isAlignedGeneric(
9816 u32,9816 u32,
9817 @bitCast(u32, small_addr),9817 @as(u32, @bitCast(small_addr)),
9818 ty.abiAlignment(mod),9818 ty.abiAlignment(mod),
9819 ))) {9819 ))) {
9820 .move => |tag| try self.asmRegisterMemory(tag, dst_alias, src_mem),9820 .move => |tag| try self.asmRegisterMemory(tag, dst_alias, src_mem),
...@@ -9928,9 +9928,9 @@ fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerEr...@@ -9928,9 +9928,9 @@ fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerEr
99289928
9929fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCValue) InnerError!void {9929fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCValue) InnerError!void {
9930 const mod = self.bin_file.options.module.?;9930 const mod = self.bin_file.options.module.?;
9931 const abi_size = @intCast(u32, ty.abiSize(mod));9931 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
9932 const dst_ptr_mcv: MCValue = switch (base) {9932 const dst_ptr_mcv: MCValue = switch (base) {
9933 .none => .{ .immediate = @bitCast(u64, @as(i64, disp)) },9933 .none => .{ .immediate = @as(u64, @bitCast(@as(i64, disp))) },
9934 .reg => |base_reg| .{ .register_offset = .{ .reg = base_reg, .off = disp } },9934 .reg => |base_reg| .{ .register_offset = .{ .reg = base_reg, .off = disp } },
9935 .frame => |base_frame_index| .{ .lea_frame = .{ .index = base_frame_index, .off = disp } },9935 .frame => |base_frame_index| .{ .lea_frame = .{ .index = base_frame_index, .off = disp } },
9936 };9936 };
...@@ -9941,9 +9941,9 @@ fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCVal...@@ -9941,9 +9941,9 @@ fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCVal
9941 .immediate => |imm| switch (abi_size) {9941 .immediate => |imm| switch (abi_size) {
9942 1, 2, 4 => {9942 1, 2, 4 => {
9943 const immediate = if (ty.isSignedInt(mod))9943 const immediate = if (ty.isSignedInt(mod))
9944 Immediate.s(@truncate(i32, @bitCast(i64, imm)))9944 Immediate.s(@as(i32, @truncate(@as(i64, @bitCast(imm)))))
9945 else9945 else
9946 Immediate.u(@intCast(u32, imm));9946 Immediate.u(@as(u32, @intCast(imm)));
9947 try self.asmMemoryImmediate(9947 try self.asmMemoryImmediate(
9948 .{ ._, .mov },9948 .{ ._, .mov },
9949 Memory.sib(Memory.PtrSize.fromSize(abi_size), .{ .base = base, .disp = disp }),9949 Memory.sib(Memory.PtrSize.fromSize(abi_size), .{ .base = base, .disp = disp }),
...@@ -9951,7 +9951,7 @@ fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCVal...@@ -9951,7 +9951,7 @@ fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCVal
9951 );9951 );
9952 },9952 },
9953 3, 5...7 => unreachable,9953 3, 5...7 => unreachable,
9954 else => if (math.cast(i32, @bitCast(i64, imm))) |small| {9954 else => if (math.cast(i32, @as(i64, @bitCast(imm)))) |small| {
9955 try self.asmMemoryImmediate(9955 try self.asmMemoryImmediate(
9956 .{ ._, .mov },9956 .{ ._, .mov },
9957 Memory.sib(Memory.PtrSize.fromSize(abi_size), .{ .base = base, .disp = disp }),9957 Memory.sib(Memory.PtrSize.fromSize(abi_size), .{ .base = base, .disp = disp }),
...@@ -9963,14 +9963,14 @@ fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCVal...@@ -9963,14 +9963,14 @@ fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCVal
9963 .{ ._, .mov },9963 .{ ._, .mov },
9964 Memory.sib(.dword, .{ .base = base, .disp = disp + offset }),9964 Memory.sib(.dword, .{ .base = base, .disp = disp + offset }),
9965 if (ty.isSignedInt(mod))9965 if (ty.isSignedInt(mod))
9966 Immediate.s(@truncate(9966 Immediate.s(@as(
9967 i32,9967 i32,
9968 @bitCast(i64, imm) >> (math.cast(u6, offset * 8) orelse 63),9968 @truncate(@as(i64, @bitCast(imm)) >> (math.cast(u6, offset * 8) orelse 63)),
9969 ))9969 ))
9970 else9970 else
9971 Immediate.u(@truncate(9971 Immediate.u(@as(
9972 u32,9972 u32,
9973 if (math.cast(u6, offset * 8)) |shift| imm >> shift else 0,9973 @truncate(if (math.cast(u6, offset * 8)) |shift| imm >> shift else 0),
9974 )),9974 )),
9975 );9975 );
9976 },9976 },
...@@ -9985,13 +9985,13 @@ fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCVal...@@ -9985,13 +9985,13 @@ fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCVal
9985 switch (try self.moveStrategy(ty, switch (base) {9985 switch (try self.moveStrategy(ty, switch (base) {
9986 .none => mem.isAlignedGeneric(9986 .none => mem.isAlignedGeneric(
9987 u32,9987 u32,
9988 @bitCast(u32, disp),9988 @as(u32, @bitCast(disp)),
9989 ty.abiAlignment(mod),9989 ty.abiAlignment(mod),
9990 ),9990 ),
9991 .reg => |reg| switch (reg) {9991 .reg => |reg| switch (reg) {
9992 .es, .cs, .ss, .ds => mem.isAlignedGeneric(9992 .es, .cs, .ss, .ds => mem.isAlignedGeneric(
9993 u32,9993 u32,
9994 @bitCast(u32, disp),9994 @as(u32, @bitCast(disp)),
9995 ty.abiAlignment(mod),9995 ty.abiAlignment(mod),
9996 ),9996 ),
9997 else => false,9997 else => false,
...@@ -10012,13 +10012,13 @@ fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCVal...@@ -10012,13 +10012,13 @@ fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCVal
10012 .register_overflow => |ro| {10012 .register_overflow => |ro| {
10013 try self.genSetMem(10013 try self.genSetMem(
10014 base,10014 base,
10015 disp + @intCast(i32, ty.structFieldOffset(0, mod)),10015 disp + @as(i32, @intCast(ty.structFieldOffset(0, mod))),
10016 ty.structFieldType(0, mod),10016 ty.structFieldType(0, mod),
10017 .{ .register = ro.reg },10017 .{ .register = ro.reg },
10018 );10018 );
10019 try self.genSetMem(10019 try self.genSetMem(
10020 base,10020 base,
10021 disp + @intCast(i32, ty.structFieldOffset(1, mod)),10021 disp + @as(i32, @intCast(ty.structFieldOffset(1, mod))),
10022 ty.structFieldType(1, mod),10022 ty.structFieldType(1, mod),
10023 .{ .eflags = ro.eflags },10023 .{ .eflags = ro.eflags },
10024 );10024 );
...@@ -10077,7 +10077,7 @@ fn genLazySymbolRef(...@@ -10077,7 +10077,7 @@ fn genLazySymbolRef(
10077 _ = try atom.getOrCreateOffsetTableEntry(elf_file);10077 _ = try atom.getOrCreateOffsetTableEntry(elf_file);
10078 const got_addr = atom.getOffsetTableAddress(elf_file);10078 const got_addr = atom.getOffsetTableAddress(elf_file);
10079 const got_mem =10079 const got_mem =
10080 Memory.sib(.qword, .{ .base = .{ .reg = .ds }, .disp = @intCast(i32, got_addr) });10080 Memory.sib(.qword, .{ .base = .{ .reg = .ds }, .disp = @as(i32, @intCast(got_addr)) });
10081 switch (tag) {10081 switch (tag) {
10082 .lea, .mov => try self.asmRegisterMemory(.{ ._, .mov }, reg.to64(), got_mem),10082 .lea, .mov => try self.asmRegisterMemory(.{ ._, .mov }, reg.to64(), got_mem),
10083 .call => try self.asmMemory(.{ ._, .call }, got_mem),10083 .call => try self.asmMemory(.{ ._, .call }, got_mem),
...@@ -10099,7 +10099,7 @@ fn genLazySymbolRef(...@@ -10099,7 +10099,7 @@ fn genLazySymbolRef(
10099 _ = atom.getOrCreateOffsetTableEntry(p9_file);10099 _ = atom.getOrCreateOffsetTableEntry(p9_file);
10100 const got_addr = atom.getOffsetTableAddress(p9_file);10100 const got_addr = atom.getOffsetTableAddress(p9_file);
10101 const got_mem =10101 const got_mem =
10102 Memory.sib(.qword, .{ .base = .{ .reg = .ds }, .disp = @intCast(i32, got_addr) });10102 Memory.sib(.qword, .{ .base = .{ .reg = .ds }, .disp = @as(i32, @intCast(got_addr)) });
10103 switch (tag) {10103 switch (tag) {
10104 .lea, .mov => try self.asmRegisterMemory(.{ ._, .mov }, reg.to64(), got_mem),10104 .lea, .mov => try self.asmRegisterMemory(.{ ._, .mov }, reg.to64(), got_mem),
10105 .call => try self.asmMemory(.{ ._, .call }, got_mem),10105 .call => try self.asmMemory(.{ ._, .call }, got_mem),
...@@ -10195,8 +10195,8 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -10195,8 +10195,8 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
10195 if (src_ty.isAbiInt(mod)) src_ty.intInfo(mod).signedness else .unsigned;10195 if (src_ty.isAbiInt(mod)) src_ty.intInfo(mod).signedness else .unsigned;
10196 if (dst_signedness == src_signedness) break :result dst_mcv;10196 if (dst_signedness == src_signedness) break :result dst_mcv;
1019710197
10198 const abi_size = @intCast(u16, dst_ty.abiSize(mod));10198 const abi_size = @as(u16, @intCast(dst_ty.abiSize(mod)));
10199 const bit_size = @intCast(u16, dst_ty.bitSize(mod));10199 const bit_size = @as(u16, @intCast(dst_ty.bitSize(mod)));
10200 if (abi_size * 8 <= bit_size) break :result dst_mcv;10200 if (abi_size * 8 <= bit_size) break :result dst_mcv;
1020110201
10202 const dst_limbs_len = math.divCeil(i32, bit_size, 64) catch unreachable;10202 const dst_limbs_len = math.divCeil(i32, bit_size, 64) catch unreachable;
...@@ -10237,7 +10237,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {...@@ -10237,7 +10237,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
10237 try self.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr);10237 try self.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr);
10238 try self.genSetMem(10238 try self.genSetMem(
10239 .{ .frame = frame_index },10239 .{ .frame = frame_index },
10240 @intCast(i32, ptr_ty.abiSize(mod)),10240 @as(i32, @intCast(ptr_ty.abiSize(mod))),
10241 Type.usize,10241 Type.usize,
10242 .{ .immediate = array_len },10242 .{ .immediate = array_len },
10243 );10243 );
...@@ -10251,7 +10251,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {...@@ -10251,7 +10251,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
10251 const ty_op = self.air.instructions.items(.data)[inst].ty_op;10251 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1025210252
10253 const src_ty = self.typeOf(ty_op.operand);10253 const src_ty = self.typeOf(ty_op.operand);
10254 const src_bits = @intCast(u32, src_ty.bitSize(mod));10254 const src_bits = @as(u32, @intCast(src_ty.bitSize(mod)));
10255 const src_signedness =10255 const src_signedness =
10256 if (src_ty.isAbiInt(mod)) src_ty.intInfo(mod).signedness else .unsigned;10256 if (src_ty.isAbiInt(mod)) src_ty.intInfo(mod).signedness else .unsigned;
10257 const dst_ty = self.typeOfIndex(inst);10257 const dst_ty = self.typeOfIndex(inst);
...@@ -10306,7 +10306,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {...@@ -10306,7 +10306,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
1030610306
10307 const src_ty = self.typeOf(ty_op.operand);10307 const src_ty = self.typeOf(ty_op.operand);
10308 const dst_ty = self.typeOfIndex(inst);10308 const dst_ty = self.typeOfIndex(inst);
10309 const dst_bits = @intCast(u32, dst_ty.bitSize(mod));10309 const dst_bits = @as(u32, @intCast(dst_ty.bitSize(mod)));
10310 const dst_signedness =10310 const dst_signedness =
10311 if (dst_ty.isAbiInt(mod)) dst_ty.intInfo(mod).signedness else .unsigned;10311 if (dst_ty.isAbiInt(mod)) dst_ty.intInfo(mod).signedness else .unsigned;
1031210312
...@@ -10359,7 +10359,7 @@ fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {...@@ -10359,7 +10359,7 @@ fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {
1035910359
10360 const ptr_ty = self.typeOf(extra.ptr);10360 const ptr_ty = self.typeOf(extra.ptr);
10361 const val_ty = self.typeOf(extra.expected_value);10361 const val_ty = self.typeOf(extra.expected_value);
10362 const val_abi_size = @intCast(u32, val_ty.abiSize(mod));10362 const val_abi_size = @as(u32, @intCast(val_ty.abiSize(mod)));
1036310363
10364 try self.spillRegisters(&.{ .rax, .rdx, .rbx, .rcx });10364 try self.spillRegisters(&.{ .rax, .rdx, .rbx, .rcx });
10365 const regs_lock = self.register_manager.lockRegsAssumeUnused(4, .{ .rax, .rdx, .rbx, .rcx });10365 const regs_lock = self.register_manager.lockRegsAssumeUnused(4, .{ .rax, .rdx, .rbx, .rcx });
...@@ -10461,7 +10461,7 @@ fn atomicOp(...@@ -10461,7 +10461,7 @@ fn atomicOp(
10461 };10461 };
10462 defer if (val_lock) |lock| self.register_manager.unlockReg(lock);10462 defer if (val_lock) |lock| self.register_manager.unlockReg(lock);
1046310463
10464 const val_abi_size = @intCast(u32, val_ty.abiSize(mod));10464 const val_abi_size = @as(u32, @intCast(val_ty.abiSize(mod)));
10465 const ptr_size = Memory.PtrSize.fromSize(val_abi_size);10465 const ptr_size = Memory.PtrSize.fromSize(val_abi_size);
10466 const ptr_mem = switch (ptr_mcv) {10466 const ptr_mem = switch (ptr_mcv) {
10467 .immediate, .register, .register_offset, .lea_frame => ptr_mcv.deref().mem(ptr_size),10467 .immediate, .register, .register_offset, .lea_frame => ptr_mcv.deref().mem(ptr_size),
...@@ -10539,7 +10539,7 @@ fn atomicOp(...@@ -10539,7 +10539,7 @@ fn atomicOp(
10539 defer self.register_manager.unlockReg(tmp_lock);10539 defer self.register_manager.unlockReg(tmp_lock);
1054010540
10541 try self.asmRegisterMemory(.{ ._, .mov }, registerAlias(.rax, val_abi_size), ptr_mem);10541 try self.asmRegisterMemory(.{ ._, .mov }, registerAlias(.rax, val_abi_size), ptr_mem);
10542 const loop = @intCast(u32, self.mir_instructions.len);10542 const loop = @as(u32, @intCast(self.mir_instructions.len));
10543 if (rmw_op != std.builtin.AtomicRmwOp.Xchg) {10543 if (rmw_op != std.builtin.AtomicRmwOp.Xchg) {
10544 try self.genSetReg(tmp_reg, val_ty, .{ .register = .rax });10544 try self.genSetReg(tmp_reg, val_ty, .{ .register = .rax });
10545 }10545 }
...@@ -10613,7 +10613,7 @@ fn atomicOp(...@@ -10613,7 +10613,7 @@ fn atomicOp(
10613 .scale_index = ptr_mem.scaleIndex(),10613 .scale_index = ptr_mem.scaleIndex(),
10614 .disp = ptr_mem.sib.disp + 8,10614 .disp = ptr_mem.sib.disp + 8,
10615 }));10615 }));
10616 const loop = @intCast(u32, self.mir_instructions.len);10616 const loop = @as(u32, @intCast(self.mir_instructions.len));
10617 const val_mem_mcv: MCValue = switch (val_mcv) {10617 const val_mem_mcv: MCValue = switch (val_mcv) {
10618 .memory, .indirect, .load_frame => val_mcv,10618 .memory, .indirect, .load_frame => val_mcv,
10619 else => .{ .indirect = .{10619 else => .{ .indirect = .{
...@@ -10769,7 +10769,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -10769,7 +10769,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
10769 };10769 };
10770 defer if (src_val_lock) |lock| self.register_manager.unlockReg(lock);10770 defer if (src_val_lock) |lock| self.register_manager.unlockReg(lock);
1077110771
10772 const elem_abi_size = @intCast(u31, elem_ty.abiSize(mod));10772 const elem_abi_size = @as(u31, @intCast(elem_ty.abiSize(mod)));
1077310773
10774 if (elem_abi_size == 1) {10774 if (elem_abi_size == 1) {
10775 const ptr: MCValue = switch (dst_ptr_ty.ptrSize(mod)) {10775 const ptr: MCValue = switch (dst_ptr_ty.ptrSize(mod)) {
...@@ -11249,9 +11249,9 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {...@@ -11249,9 +11249,9 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
11249fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {11249fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
11250 const mod = self.bin_file.options.module.?;11250 const mod = self.bin_file.options.module.?;
11251 const result_ty = self.typeOfIndex(inst);11251 const result_ty = self.typeOfIndex(inst);
11252 const len = @intCast(usize, result_ty.arrayLen(mod));11252 const len = @as(usize, @intCast(result_ty.arrayLen(mod)));
11253 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;11253 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
11254 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);11254 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
11255 const result: MCValue = result: {11255 const result: MCValue = result: {
11256 switch (result_ty.zigTypeTag(mod)) {11256 switch (result_ty.zigTypeTag(mod)) {
11257 .Struct => {11257 .Struct => {
...@@ -11268,17 +11268,17 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -11268,17 +11268,17 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
11268 if ((try result_ty.structFieldValueComptime(mod, elem_i)) != null) continue;11268 if ((try result_ty.structFieldValueComptime(mod, elem_i)) != null) continue;
1126911269
11270 const elem_ty = result_ty.structFieldType(elem_i, mod);11270 const elem_ty = result_ty.structFieldType(elem_i, mod);
11271 const elem_bit_size = @intCast(u32, elem_ty.bitSize(mod));11271 const elem_bit_size = @as(u32, @intCast(elem_ty.bitSize(mod)));
11272 if (elem_bit_size > 64) {11272 if (elem_bit_size > 64) {
11273 return self.fail(11273 return self.fail(
11274 "TODO airAggregateInit implement packed structs with large fields",11274 "TODO airAggregateInit implement packed structs with large fields",
11275 .{},11275 .{},
11276 );11276 );
11277 }11277 }
11278 const elem_abi_size = @intCast(u32, elem_ty.abiSize(mod));11278 const elem_abi_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
11279 const elem_abi_bits = elem_abi_size * 8;11279 const elem_abi_bits = elem_abi_size * 8;
11280 const elem_off = struct_obj.packedFieldBitOffset(mod, elem_i);11280 const elem_off = struct_obj.packedFieldBitOffset(mod, elem_i);
11281 const elem_byte_off = @intCast(i32, elem_off / elem_abi_bits * elem_abi_size);11281 const elem_byte_off = @as(i32, @intCast(elem_off / elem_abi_bits * elem_abi_size));
11282 const elem_bit_off = elem_off % elem_abi_bits;11282 const elem_bit_off = elem_off % elem_abi_bits;
11283 const elem_mcv = try self.resolveInst(elem);11283 const elem_mcv = try self.resolveInst(elem);
11284 const mat_elem_mcv = switch (elem_mcv) {11284 const mat_elem_mcv = switch (elem_mcv) {
...@@ -11330,7 +11330,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -11330,7 +11330,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
11330 elem_ty,11330 elem_ty,
11331 .{ .load_frame = .{11331 .{ .load_frame = .{
11332 .index = frame_index,11332 .index = frame_index,
11333 .off = elem_byte_off + @intCast(i32, elem_abi_size),11333 .off = elem_byte_off + @as(i32, @intCast(elem_abi_size)),
11334 } },11334 } },
11335 .{ .register = reg },11335 .{ .register = reg },
11336 );11336 );
...@@ -11340,7 +11340,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -11340,7 +11340,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
11340 if ((try result_ty.structFieldValueComptime(mod, elem_i)) != null) continue;11340 if ((try result_ty.structFieldValueComptime(mod, elem_i)) != null) continue;
1134111341
11342 const elem_ty = result_ty.structFieldType(elem_i, mod);11342 const elem_ty = result_ty.structFieldType(elem_i, mod);
11343 const elem_off = @intCast(i32, result_ty.structFieldOffset(elem_i, mod));11343 const elem_off = @as(i32, @intCast(result_ty.structFieldOffset(elem_i, mod)));
11344 const elem_mcv = try self.resolveInst(elem);11344 const elem_mcv = try self.resolveInst(elem);
11345 const mat_elem_mcv = switch (elem_mcv) {11345 const mat_elem_mcv = switch (elem_mcv) {
11346 .load_tlv => |sym_index| MCValue{ .lea_tlv = sym_index },11346 .load_tlv => |sym_index| MCValue{ .lea_tlv = sym_index },
...@@ -11354,7 +11354,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -11354,7 +11354,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
11354 const frame_index =11354 const frame_index =
11355 try self.allocFrameIndex(FrameAlloc.initType(result_ty, mod));11355 try self.allocFrameIndex(FrameAlloc.initType(result_ty, mod));
11356 const elem_ty = result_ty.childType(mod);11356 const elem_ty = result_ty.childType(mod);
11357 const elem_size = @intCast(u32, elem_ty.abiSize(mod));11357 const elem_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
1135811358
11359 for (elements, 0..) |elem, elem_i| {11359 for (elements, 0..) |elem, elem_i| {
11360 const elem_mcv = try self.resolveInst(elem);11360 const elem_mcv = try self.resolveInst(elem);
...@@ -11362,12 +11362,12 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -11362,12 +11362,12 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
11362 .load_tlv => |sym_index| MCValue{ .lea_tlv = sym_index },11362 .load_tlv => |sym_index| MCValue{ .lea_tlv = sym_index },
11363 else => elem_mcv,11363 else => elem_mcv,
11364 };11364 };
11365 const elem_off = @intCast(i32, elem_size * elem_i);11365 const elem_off = @as(i32, @intCast(elem_size * elem_i));
11366 try self.genSetMem(.{ .frame = frame_index }, elem_off, elem_ty, mat_elem_mcv);11366 try self.genSetMem(.{ .frame = frame_index }, elem_off, elem_ty, mat_elem_mcv);
11367 }11367 }
11368 if (result_ty.sentinel(mod)) |sentinel| try self.genSetMem(11368 if (result_ty.sentinel(mod)) |sentinel| try self.genSetMem(
11369 .{ .frame = frame_index },11369 .{ .frame = frame_index },
11370 @intCast(i32, elem_size * elements.len),11370 @as(i32, @intCast(elem_size * elements.len)),
11371 elem_ty,11371 elem_ty,
11372 try self.genTypedValue(.{ .ty = elem_ty, .val = sentinel }),11372 try self.genTypedValue(.{ .ty = elem_ty, .val = sentinel }),
11373 );11373 );
...@@ -11416,7 +11416,7 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -11416,7 +11416,7 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
11416 const tag_int_val = try tag_val.intFromEnum(tag_ty, mod);11416 const tag_int_val = try tag_val.intFromEnum(tag_ty, mod);
11417 const tag_int = tag_int_val.toUnsignedInt(mod);11417 const tag_int = tag_int_val.toUnsignedInt(mod);
11418 const tag_off = if (layout.tag_align < layout.payload_align)11418 const tag_off = if (layout.tag_align < layout.payload_align)
11419 @intCast(i32, layout.payload_size)11419 @as(i32, @intCast(layout.payload_size))
11420 else11420 else
11421 0;11421 0;
11422 try self.genCopy(tag_ty, dst_mcv.address().offset(tag_off).deref(), .{ .immediate = tag_int });11422 try self.genCopy(tag_ty, dst_mcv.address().offset(tag_off).deref(), .{ .immediate = tag_int });
...@@ -11424,7 +11424,7 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -11424,7 +11424,7 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
11424 const pl_off = if (layout.tag_align < layout.payload_align)11424 const pl_off = if (layout.tag_align < layout.payload_align)
11425 011425 0
11426 else11426 else
11427 @intCast(i32, layout.tag_size);11427 @as(i32, @intCast(layout.tag_size));
11428 try self.genCopy(src_ty, dst_mcv.address().offset(pl_off).deref(), src_mcv);11428 try self.genCopy(src_ty, dst_mcv.address().offset(pl_off).deref(), src_mcv);
1142911429
11430 break :result dst_mcv;11430 break :result dst_mcv;
...@@ -11454,7 +11454,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {...@@ -11454,7 +11454,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
11454 var order = [1]u2{0} ** 3;11454 var order = [1]u2{0} ** 3;
11455 var unused = std.StaticBitSet(3).initFull();11455 var unused = std.StaticBitSet(3).initFull();
11456 for (ops, &mcvs, &locks, 0..) |op, *mcv, *lock, op_i| {11456 for (ops, &mcvs, &locks, 0..) |op, *mcv, *lock, op_i| {
11457 const op_index = @intCast(u2, op_i);11457 const op_index = @as(u2, @intCast(op_i));
11458 mcv.* = try self.resolveInst(op);11458 mcv.* = try self.resolveInst(op);
11459 if (unused.isSet(0) and mcv.isRegister() and self.reuseOperand(inst, op, op_index, mcv.*)) {11459 if (unused.isSet(0) and mcv.isRegister() and self.reuseOperand(inst, op, op_index, mcv.*)) {
11460 order[op_index] = 1;11460 order[op_index] = 1;
...@@ -11470,7 +11470,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {...@@ -11470,7 +11470,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
11470 }11470 }
11471 for (&order, &mcvs, &locks) |*mop_index, *mcv, *lock| {11471 for (&order, &mcvs, &locks) |*mop_index, *mcv, *lock| {
11472 if (mop_index.* != 0) continue;11472 if (mop_index.* != 0) continue;
11473 mop_index.* = 1 + @intCast(u2, unused.toggleFirstSet().?);11473 mop_index.* = 1 + @as(u2, @intCast(unused.toggleFirstSet().?));
11474 if (mop_index.* > 1 and mcv.isRegister()) continue;11474 if (mop_index.* > 1 and mcv.isRegister()) continue;
11475 const reg = try self.copyToTmpRegister(ty, mcv.*);11475 const reg = try self.copyToTmpRegister(ty, mcv.*);
11476 mcv.* = .{ .register = reg };11476 mcv.* = .{ .register = reg };
...@@ -11570,7 +11570,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {...@@ -11570,7 +11570,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
11570 var mops: [3]MCValue = undefined;11570 var mops: [3]MCValue = undefined;
11571 for (order, mcvs) |mop_index, mcv| mops[mop_index - 1] = mcv;11571 for (order, mcvs) |mop_index, mcv| mops[mop_index - 1] = mcv;
1157211572
11573 const abi_size = @intCast(u32, ty.abiSize(mod));11573 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
11574 const mop1_reg = registerAlias(mops[0].getReg().?, abi_size);11574 const mop1_reg = registerAlias(mops[0].getReg().?, abi_size);
11575 const mop2_reg = registerAlias(mops[1].getReg().?, abi_size);11575 const mop2_reg = registerAlias(mops[1].getReg().?, abi_size);
11576 if (mops[2].isRegister()) try self.asmRegisterRegisterRegister(11576 if (mops[2].isRegister()) try self.asmRegisterRegisterRegister(
...@@ -11723,7 +11723,7 @@ fn resolveCallingConventionValues(...@@ -11723,7 +11723,7 @@ fn resolveCallingConventionValues(
11723 switch (self.target.os.tag) {11723 switch (self.target.os.tag) {
11724 .windows => {11724 .windows => {
11725 // Align the stack to 16bytes before allocating shadow stack space (if any).11725 // Align the stack to 16bytes before allocating shadow stack space (if any).
11726 result.stack_byte_count += @intCast(u31, 4 * Type.usize.abiSize(mod));11726 result.stack_byte_count += @as(u31, @intCast(4 * Type.usize.abiSize(mod)));
11727 },11727 },
11728 else => {},11728 else => {},
11729 }11729 }
...@@ -11746,7 +11746,7 @@ fn resolveCallingConventionValues(...@@ -11746,7 +11746,7 @@ fn resolveCallingConventionValues(
11746 result.return_value = switch (classes[0]) {11746 result.return_value = switch (classes[0]) {
11747 .integer => InstTracking.init(.{ .register = registerAlias(11747 .integer => InstTracking.init(.{ .register = registerAlias(
11748 ret_reg,11748 ret_reg,
11749 @intCast(u32, ret_ty.abiSize(mod)),11749 @as(u32, @intCast(ret_ty.abiSize(mod))),
11750 ) }),11750 ) }),
11751 .float, .sse => InstTracking.init(.{ .register = .xmm0 }),11751 .float, .sse => InstTracking.init(.{ .register = .xmm0 }),
11752 .memory => ret: {11752 .memory => ret: {
...@@ -11782,17 +11782,17 @@ fn resolveCallingConventionValues(...@@ -11782,17 +11782,17 @@ fn resolveCallingConventionValues(
11782 },11782 },
11783 .float, .sse => switch (self.target.os.tag) {11783 .float, .sse => switch (self.target.os.tag) {
11784 .windows => if (param_reg_i < 4) {11784 .windows => if (param_reg_i < 4) {
11785 arg.* = .{ .register = @enumFromInt(11785 arg.* = .{ .register = @as(
11786 Register,11786 Register,
11787 @intFromEnum(Register.xmm0) + param_reg_i,11787 @enumFromInt(@intFromEnum(Register.xmm0) + param_reg_i),
11788 ) };11788 ) };
11789 param_reg_i += 1;11789 param_reg_i += 1;
11790 continue;11790 continue;
11791 },11791 },
11792 else => if (param_sse_reg_i < 8) {11792 else => if (param_sse_reg_i < 8) {
11793 arg.* = .{ .register = @enumFromInt(11793 arg.* = .{ .register = @as(
11794 Register,11794 Register,
11795 @intFromEnum(Register.xmm0) + param_sse_reg_i,11795 @enumFromInt(@intFromEnum(Register.xmm0) + param_sse_reg_i),
11796 ) };11796 ) };
11797 param_sse_reg_i += 1;11797 param_sse_reg_i += 1;
11798 continue;11798 continue;
...@@ -11804,8 +11804,8 @@ fn resolveCallingConventionValues(...@@ -11804,8 +11804,8 @@ fn resolveCallingConventionValues(
11804 }),11804 }),
11805 }11805 }
1180611806
11807 const param_size = @intCast(u31, ty.abiSize(mod));11807 const param_size = @as(u31, @intCast(ty.abiSize(mod)));
11808 const param_align = @intCast(u31, ty.abiAlignment(mod));11808 const param_align = @as(u31, @intCast(ty.abiAlignment(mod)));
11809 result.stack_byte_count =11809 result.stack_byte_count =
11810 mem.alignForward(u31, result.stack_byte_count, param_align);11810 mem.alignForward(u31, result.stack_byte_count, param_align);
11811 arg.* = .{ .load_frame = .{11811 arg.* = .{ .load_frame = .{
...@@ -11825,7 +11825,7 @@ fn resolveCallingConventionValues(...@@ -11825,7 +11825,7 @@ fn resolveCallingConventionValues(
11825 result.return_value = InstTracking.init(.none);11825 result.return_value = InstTracking.init(.none);
11826 } else {11826 } else {
11827 const ret_reg = abi.getCAbiIntReturnRegs(self.target.*)[0];11827 const ret_reg = abi.getCAbiIntReturnRegs(self.target.*)[0];
11828 const ret_ty_size = @intCast(u31, ret_ty.abiSize(mod));11828 const ret_ty_size = @as(u31, @intCast(ret_ty.abiSize(mod)));
11829 if (ret_ty_size <= 8 and !ret_ty.isRuntimeFloat()) {11829 if (ret_ty_size <= 8 and !ret_ty.isRuntimeFloat()) {
11830 const aliased_reg = registerAlias(ret_reg, ret_ty_size);11830 const aliased_reg = registerAlias(ret_reg, ret_ty_size);
11831 result.return_value = .{ .short = .{ .register = aliased_reg }, .long = .none };11831 result.return_value = .{ .short = .{ .register = aliased_reg }, .long = .none };
...@@ -11844,8 +11844,8 @@ fn resolveCallingConventionValues(...@@ -11844,8 +11844,8 @@ fn resolveCallingConventionValues(
11844 arg.* = .none;11844 arg.* = .none;
11845 continue;11845 continue;
11846 }11846 }
11847 const param_size = @intCast(u31, ty.abiSize(mod));11847 const param_size = @as(u31, @intCast(ty.abiSize(mod)));
11848 const param_align = @intCast(u31, ty.abiAlignment(mod));11848 const param_align = @as(u31, @intCast(ty.abiAlignment(mod)));
11849 result.stack_byte_count =11849 result.stack_byte_count =
11850 mem.alignForward(u31, result.stack_byte_count, param_align);11850 mem.alignForward(u31, result.stack_byte_count, param_align);
11851 arg.* = .{ .load_frame = .{11851 arg.* = .{ .load_frame = .{
...@@ -11932,12 +11932,12 @@ fn truncateRegister(self: *Self, ty: Type, reg: Register) !void {...@@ -11932,12 +11932,12 @@ fn truncateRegister(self: *Self, ty: Type, reg: Register) !void {
11932 const mod = self.bin_file.options.module.?;11932 const mod = self.bin_file.options.module.?;
11933 const int_info = if (ty.isAbiInt(mod)) ty.intInfo(mod) else std.builtin.Type.Int{11933 const int_info = if (ty.isAbiInt(mod)) ty.intInfo(mod) else std.builtin.Type.Int{
11934 .signedness = .unsigned,11934 .signedness = .unsigned,
11935 .bits = @intCast(u16, ty.bitSize(mod)),11935 .bits = @as(u16, @intCast(ty.bitSize(mod))),
11936 };11936 };
11937 const max_reg_bit_width = Register.rax.bitSize();11937 const max_reg_bit_width = Register.rax.bitSize();
11938 switch (int_info.signedness) {11938 switch (int_info.signedness) {
11939 .signed => {11939 .signed => {
11940 const shift = @intCast(u6, max_reg_bit_width - int_info.bits);11940 const shift = @as(u6, @intCast(max_reg_bit_width - int_info.bits));
11941 try self.genShiftBinOpMir(11941 try self.genShiftBinOpMir(
11942 .{ ._l, .sa },11942 .{ ._l, .sa },
11943 Type.isize,11943 Type.isize,
...@@ -11952,7 +11952,7 @@ fn truncateRegister(self: *Self, ty: Type, reg: Register) !void {...@@ -11952,7 +11952,7 @@ fn truncateRegister(self: *Self, ty: Type, reg: Register) !void {
11952 );11952 );
11953 },11953 },
11954 .unsigned => {11954 .unsigned => {
11955 const shift = @intCast(u6, max_reg_bit_width - int_info.bits);11955 const shift = @as(u6, @intCast(max_reg_bit_width - int_info.bits));
11956 const mask = (~@as(u64, 0)) >> shift;11956 const mask = (~@as(u64, 0)) >> shift;
11957 if (int_info.bits <= 32) {11957 if (int_info.bits <= 32) {
11958 try self.genBinOpMir(11958 try self.genBinOpMir(
src/arch/x86_64/Emit.zig+14-14
...@@ -19,18 +19,18 @@ pub const Error = Lower.Error || error{...@@ -19,18 +19,18 @@ pub const Error = Lower.Error || error{
1919
20pub fn emitMir(emit: *Emit) Error!void {20pub fn emitMir(emit: *Emit) Error!void {
21 for (0..emit.lower.mir.instructions.len) |mir_i| {21 for (0..emit.lower.mir.instructions.len) |mir_i| {
22 const mir_index = @intCast(Mir.Inst.Index, mir_i);22 const mir_index = @as(Mir.Inst.Index, @intCast(mir_i));
23 try emit.code_offset_mapping.putNoClobber(23 try emit.code_offset_mapping.putNoClobber(
24 emit.lower.allocator,24 emit.lower.allocator,
25 mir_index,25 mir_index,
26 @intCast(u32, emit.code.items.len),26 @as(u32, @intCast(emit.code.items.len)),
27 );27 );
28 const lowered = try emit.lower.lowerMir(mir_index);28 const lowered = try emit.lower.lowerMir(mir_index);
29 var lowered_relocs = lowered.relocs;29 var lowered_relocs = lowered.relocs;
30 for (lowered.insts, 0..) |lowered_inst, lowered_index| {30 for (lowered.insts, 0..) |lowered_inst, lowered_index| {
31 const start_offset = @intCast(u32, emit.code.items.len);31 const start_offset = @as(u32, @intCast(emit.code.items.len));
32 try lowered_inst.encode(emit.code.writer(), .{});32 try lowered_inst.encode(emit.code.writer(), .{});
33 const end_offset = @intCast(u32, emit.code.items.len);33 const end_offset = @as(u32, @intCast(emit.code.items.len));
34 while (lowered_relocs.len > 0 and34 while (lowered_relocs.len > 0 and
35 lowered_relocs[0].lowered_inst_index == lowered_index) : ({35 lowered_relocs[0].lowered_inst_index == lowered_index) : ({
36 lowered_relocs = lowered_relocs[1..];36 lowered_relocs = lowered_relocs[1..];
...@@ -39,7 +39,7 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -39,7 +39,7 @@ pub fn emitMir(emit: *Emit) Error!void {
39 .source = start_offset,39 .source = start_offset,
40 .target = target,40 .target = target,
41 .offset = end_offset - 4,41 .offset = end_offset - 4,
42 .length = @intCast(u5, end_offset - start_offset),42 .length = @as(u5, @intCast(end_offset - start_offset)),
43 }),43 }),
44 .linker_extern_fn => |symbol| if (emit.bin_file.cast(link.File.MachO)) |macho_file| {44 .linker_extern_fn => |symbol| if (emit.bin_file.cast(link.File.MachO)) |macho_file| {
45 // Add relocation to the decl.45 // Add relocation to the decl.
...@@ -89,7 +89,7 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -89,7 +89,7 @@ pub fn emitMir(emit: *Emit) Error!void {
89 else => unreachable,89 else => unreachable,
90 },90 },
91 .target = .{ .sym_index = symbol.sym_index, .file = null },91 .target = .{ .sym_index = symbol.sym_index, .file = null },
92 .offset = @intCast(u32, end_offset - 4),92 .offset = @as(u32, @intCast(end_offset - 4)),
93 .addend = 0,93 .addend = 0,
94 .pcrel = true,94 .pcrel = true,
95 .length = 2,95 .length = 2,
...@@ -113,7 +113,7 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -113,7 +113,7 @@ pub fn emitMir(emit: *Emit) Error!void {
113 .linker_import => coff_file.getGlobalByIndex(symbol.sym_index),113 .linker_import => coff_file.getGlobalByIndex(symbol.sym_index),
114 else => unreachable,114 else => unreachable,
115 },115 },
116 .offset = @intCast(u32, end_offset - 4),116 .offset = @as(u32, @intCast(end_offset - 4)),
117 .addend = 0,117 .addend = 0,
118 .pcrel = true,118 .pcrel = true,
119 .length = 2,119 .length = 2,
...@@ -122,7 +122,7 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -122,7 +122,7 @@ pub fn emitMir(emit: *Emit) Error!void {
122 const atom_index = symbol.atom_index;122 const atom_index = symbol.atom_index;
123 try p9_file.addReloc(atom_index, .{ // TODO we may need to add a .type field to the relocs if they are .linker_got instead of just .linker_direct123 try p9_file.addReloc(atom_index, .{ // TODO we may need to add a .type field to the relocs if they are .linker_got instead of just .linker_direct
124 .target = symbol.sym_index, // we set sym_index to just be the atom index124 .target = symbol.sym_index, // we set sym_index to just be the atom index
125 .offset = @intCast(u32, end_offset - 4),125 .offset = @as(u32, @intCast(end_offset - 4)),
126 .addend = 0,126 .addend = 0,
127 .pcrel = true,127 .pcrel = true,
128 });128 });
...@@ -209,13 +209,13 @@ fn fixupRelocs(emit: *Emit) Error!void {...@@ -209,13 +209,13 @@ fn fixupRelocs(emit: *Emit) Error!void {
209 for (emit.relocs.items) |reloc| {209 for (emit.relocs.items) |reloc| {
210 const target = emit.code_offset_mapping.get(reloc.target) orelse210 const target = emit.code_offset_mapping.get(reloc.target) orelse
211 return emit.fail("JMP/CALL relocation target not found!", .{});211 return emit.fail("JMP/CALL relocation target not found!", .{});
212 const disp = @intCast(i32, @intCast(i64, target) - @intCast(i64, reloc.source + reloc.length));212 const disp = @as(i32, @intCast(@as(i64, @intCast(target)) - @as(i64, @intCast(reloc.source + reloc.length))));
213 mem.writeIntLittle(i32, emit.code.items[reloc.offset..][0..4], disp);213 mem.writeIntLittle(i32, emit.code.items[reloc.offset..][0..4], disp);
214 }214 }
215}215}
216216
217fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) Error!void {217fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) Error!void {
218 const delta_line = @intCast(i32, line) - @intCast(i32, emit.prev_di_line);218 const delta_line = @as(i32, @intCast(line)) - @as(i32, @intCast(emit.prev_di_line));
219 const delta_pc: usize = emit.code.items.len - emit.prev_di_pc;219 const delta_pc: usize = emit.code.items.len - emit.prev_di_pc;
220 log.debug(" (advance pc={d} and line={d})", .{ delta_line, delta_pc });220 log.debug(" (advance pc={d} and line={d})", .{ delta_line, delta_pc });
221 switch (emit.debug_output) {221 switch (emit.debug_output) {
...@@ -233,22 +233,22 @@ fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) Error!void {...@@ -233,22 +233,22 @@ fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) Error!void {
233 // increasing the line number233 // increasing the line number
234 try @import("../../link/Plan9.zig").changeLine(dbg_out.dbg_line, delta_line);234 try @import("../../link/Plan9.zig").changeLine(dbg_out.dbg_line, delta_line);
235 // increasing the pc235 // increasing the pc
236 const d_pc_p9 = @intCast(i64, delta_pc) - quant;236 const d_pc_p9 = @as(i64, @intCast(delta_pc)) - quant;
237 if (d_pc_p9 > 0) {237 if (d_pc_p9 > 0) {
238 // minus one because if its the last one, we want to leave space to change the line which is one quanta238 // minus one because if its the last one, we want to leave space to change the line which is one quanta
239 var diff = @divExact(d_pc_p9, quant) - quant;239 var diff = @divExact(d_pc_p9, quant) - quant;
240 while (diff > 0) {240 while (diff > 0) {
241 if (diff < 64) {241 if (diff < 64) {
242 try dbg_out.dbg_line.append(@intCast(u8, diff + 128));242 try dbg_out.dbg_line.append(@as(u8, @intCast(diff + 128)));
243 diff = 0;243 diff = 0;
244 } else {244 } else {
245 try dbg_out.dbg_line.append(@intCast(u8, 64 + 128));245 try dbg_out.dbg_line.append(@as(u8, @intCast(64 + 128)));
246 diff -= 64;246 diff -= 64;
247 }247 }
248 }248 }
249 if (dbg_out.pcop_change_index.*) |pci|249 if (dbg_out.pcop_change_index.*) |pci|
250 dbg_out.dbg_line.items[pci] += 1;250 dbg_out.dbg_line.items[pci] += 1;
251 dbg_out.pcop_change_index.* = @intCast(u32, dbg_out.dbg_line.items.len - 1);251 dbg_out.pcop_change_index.* = @as(u32, @intCast(dbg_out.dbg_line.items.len - 1));
252 } else if (d_pc_p9 == 0) {252 } else if (d_pc_p9 == 0) {
253 // we don't need to do anything, because adding the quant does it for us253 // we don't need to do anything, because adding the quant does it for us
254 } else unreachable;254 } else unreachable;
src/arch/x86_64/Encoding.zig+2-2
...@@ -85,7 +85,7 @@ pub fn findByOpcode(opc: []const u8, prefixes: struct {...@@ -85,7 +85,7 @@ pub fn findByOpcode(opc: []const u8, prefixes: struct {
85 rex: Rex,85 rex: Rex,
86}, modrm_ext: ?u3) ?Encoding {86}, modrm_ext: ?u3) ?Encoding {
87 for (mnemonic_to_encodings_map, 0..) |encs, mnemonic_int| for (encs) |data| {87 for (mnemonic_to_encodings_map, 0..) |encs, mnemonic_int| for (encs) |data| {
88 const enc = Encoding{ .mnemonic = @enumFromInt(Mnemonic, mnemonic_int), .data = data };88 const enc = Encoding{ .mnemonic = @as(Mnemonic, @enumFromInt(mnemonic_int)), .data = data };
89 if (modrm_ext) |ext| if (ext != data.modrm_ext) continue;89 if (modrm_ext) |ext| if (ext != data.modrm_ext) continue;
90 if (!std.mem.eql(u8, opc, enc.opcode())) continue;90 if (!std.mem.eql(u8, opc, enc.opcode())) continue;
91 if (prefixes.rex.w) {91 if (prefixes.rex.w) {
...@@ -763,7 +763,7 @@ fn estimateInstructionLength(prefix: Prefix, encoding: Encoding, ops: []const Op...@@ -763,7 +763,7 @@ fn estimateInstructionLength(prefix: Prefix, encoding: Encoding, ops: []const Op
763763
764 var cwriter = std.io.countingWriter(std.io.null_writer);764 var cwriter = std.io.countingWriter(std.io.null_writer);
765 inst.encode(cwriter.writer(), .{ .allow_frame_loc = true }) catch unreachable; // Not allowed to fail here unless OOM.765 inst.encode(cwriter.writer(), .{ .allow_frame_loc = true }) catch unreachable; // Not allowed to fail here unless OOM.
766 return @intCast(usize, cwriter.bytes_written);766 return @as(usize, @intCast(cwriter.bytes_written));
767}767}
768768
769const mnemonic_to_encodings_map = init: {769const mnemonic_to_encodings_map = init: {
src/arch/x86_64/Lower.zig+5-5
...@@ -188,7 +188,7 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index) Error!struct {...@@ -188,7 +188,7 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index) Error!struct {
188 .pseudo_probe_align_ri_s => {188 .pseudo_probe_align_ri_s => {
189 try lower.emit(.none, .@"test", &.{189 try lower.emit(.none, .@"test", &.{
190 .{ .reg = inst.data.ri.r1 },190 .{ .reg = inst.data.ri.r1 },
191 .{ .imm = Immediate.s(@bitCast(i32, inst.data.ri.i)) },191 .{ .imm = Immediate.s(@as(i32, @bitCast(inst.data.ri.i))) },
192 });192 });
193 try lower.emit(.none, .jz, &.{193 try lower.emit(.none, .jz, &.{
194 .{ .imm = lower.reloc(.{ .inst = index + 1 }) },194 .{ .imm = lower.reloc(.{ .inst = index + 1 }) },
...@@ -213,7 +213,7 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index) Error!struct {...@@ -213,7 +213,7 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index) Error!struct {
213 },213 },
214 .pseudo_probe_adjust_unrolled_ri_s => {214 .pseudo_probe_adjust_unrolled_ri_s => {
215 var offset = page_size;215 var offset = page_size;
216 while (offset < @bitCast(i32, inst.data.ri.i)) : (offset += page_size) {216 while (offset < @as(i32, @bitCast(inst.data.ri.i))) : (offset += page_size) {
217 try lower.emit(.none, .@"test", &.{217 try lower.emit(.none, .@"test", &.{
218 .{ .mem = Memory.sib(.dword, .{218 .{ .mem = Memory.sib(.dword, .{
219 .base = .{ .reg = inst.data.ri.r1 },219 .base = .{ .reg = inst.data.ri.r1 },
...@@ -224,14 +224,14 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index) Error!struct {...@@ -224,14 +224,14 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index) Error!struct {
224 }224 }
225 try lower.emit(.none, .sub, &.{225 try lower.emit(.none, .sub, &.{
226 .{ .reg = inst.data.ri.r1 },226 .{ .reg = inst.data.ri.r1 },
227 .{ .imm = Immediate.s(@bitCast(i32, inst.data.ri.i)) },227 .{ .imm = Immediate.s(@as(i32, @bitCast(inst.data.ri.i))) },
228 });228 });
229 assert(lower.result_insts_len <= pseudo_probe_adjust_unrolled_max_insts);229 assert(lower.result_insts_len <= pseudo_probe_adjust_unrolled_max_insts);
230 },230 },
231 .pseudo_probe_adjust_setup_rri_s => {231 .pseudo_probe_adjust_setup_rri_s => {
232 try lower.emit(.none, .mov, &.{232 try lower.emit(.none, .mov, &.{
233 .{ .reg = inst.data.rri.r2.to32() },233 .{ .reg = inst.data.rri.r2.to32() },
234 .{ .imm = Immediate.s(@bitCast(i32, inst.data.rri.i)) },234 .{ .imm = Immediate.s(@as(i32, @bitCast(inst.data.rri.i))) },
235 });235 });
236 try lower.emit(.none, .sub, &.{236 try lower.emit(.none, .sub, &.{
237 .{ .reg = inst.data.rri.r1 },237 .{ .reg = inst.data.rri.r1 },
...@@ -289,7 +289,7 @@ fn imm(lower: Lower, ops: Mir.Inst.Ops, i: u32) Immediate {...@@ -289,7 +289,7 @@ fn imm(lower: Lower, ops: Mir.Inst.Ops, i: u32) Immediate {
289 .i_s,289 .i_s,
290 .mi_sib_s,290 .mi_sib_s,
291 .mi_rip_s,291 .mi_rip_s,
292 => Immediate.s(@bitCast(i32, i)),292 => Immediate.s(@as(i32, @bitCast(i))),
293293
294 .rrri,294 .rrri,
295 .rri_u,295 .rri_u,
src/arch/x86_64/Mir.zig+17-17
...@@ -989,7 +989,7 @@ pub const RegisterList = struct {...@@ -989,7 +989,7 @@ pub const RegisterList = struct {
989989
990 fn getIndexForReg(registers: []const Register, reg: Register) BitSet.MaskInt {990 fn getIndexForReg(registers: []const Register, reg: Register) BitSet.MaskInt {
991 for (registers, 0..) |cpreg, i| {991 for (registers, 0..) |cpreg, i| {
992 if (reg.id() == cpreg.id()) return @intCast(u32, i);992 if (reg.id() == cpreg.id()) return @as(u32, @intCast(i));
993 }993 }
994 unreachable; // register not in input register list!994 unreachable; // register not in input register list!
995 }995 }
...@@ -1009,7 +1009,7 @@ pub const RegisterList = struct {...@@ -1009,7 +1009,7 @@ pub const RegisterList = struct {
1009 }1009 }
10101010
1011 pub fn count(self: Self) u32 {1011 pub fn count(self: Self) u32 {
1012 return @intCast(u32, self.bitset.count());1012 return @as(u32, @intCast(self.bitset.count()));
1013 }1013 }
1014};1014};
10151015
...@@ -1023,15 +1023,15 @@ pub const Imm64 = struct {...@@ -1023,15 +1023,15 @@ pub const Imm64 = struct {
10231023
1024 pub fn encode(v: u64) Imm64 {1024 pub fn encode(v: u64) Imm64 {
1025 return .{1025 return .{
1026 .msb = @truncate(u32, v >> 32),1026 .msb = @as(u32, @truncate(v >> 32)),
1027 .lsb = @truncate(u32, v),1027 .lsb = @as(u32, @truncate(v)),
1028 };1028 };
1029 }1029 }
10301030
1031 pub fn decode(imm: Imm64) u64 {1031 pub fn decode(imm: Imm64) u64 {
1032 var res: u64 = 0;1032 var res: u64 = 0;
1033 res |= (@intCast(u64, imm.msb) << 32);1033 res |= (@as(u64, @intCast(imm.msb)) << 32);
1034 res |= @intCast(u64, imm.lsb);1034 res |= @as(u64, @intCast(imm.lsb));
1035 return res;1035 return res;
1036 }1036 }
1037};1037};
...@@ -1070,18 +1070,18 @@ pub const MemorySib = struct {...@@ -1070,18 +1070,18 @@ pub const MemorySib = struct {
1070 }1070 }
10711071
1072 pub fn decode(msib: MemorySib) Memory {1072 pub fn decode(msib: MemorySib) Memory {
1073 const scale = @truncate(u4, msib.scale_index);1073 const scale = @as(u4, @truncate(msib.scale_index));
1074 assert(scale == 0 or std.math.isPowerOfTwo(scale));1074 assert(scale == 0 or std.math.isPowerOfTwo(scale));
1075 return .{ .sib = .{1075 return .{ .sib = .{
1076 .ptr_size = @enumFromInt(Memory.PtrSize, msib.ptr_size),1076 .ptr_size = @as(Memory.PtrSize, @enumFromInt(msib.ptr_size)),
1077 .base = switch (@enumFromInt(Memory.Base.Tag, msib.base_tag)) {1077 .base = switch (@as(Memory.Base.Tag, @enumFromInt(msib.base_tag))) {
1078 .none => .none,1078 .none => .none,
1079 .reg => .{ .reg = @enumFromInt(Register, msib.base) },1079 .reg => .{ .reg = @as(Register, @enumFromInt(msib.base)) },
1080 .frame => .{ .frame = @enumFromInt(bits.FrameIndex, msib.base) },1080 .frame => .{ .frame = @as(bits.FrameIndex, @enumFromInt(msib.base)) },
1081 },1081 },
1082 .scale_index = .{1082 .scale_index = .{
1083 .scale = scale,1083 .scale = scale,
1084 .index = if (scale > 0) @enumFromInt(Register, msib.scale_index >> 4) else undefined,1084 .index = if (scale > 0) @as(Register, @enumFromInt(msib.scale_index >> 4)) else undefined,
1085 },1085 },
1086 .disp = msib.disp,1086 .disp = msib.disp,
1087 } };1087 } };
...@@ -1103,7 +1103,7 @@ pub const MemoryRip = struct {...@@ -1103,7 +1103,7 @@ pub const MemoryRip = struct {
11031103
1104 pub fn decode(mrip: MemoryRip) Memory {1104 pub fn decode(mrip: MemoryRip) Memory {
1105 return .{ .rip = .{1105 return .{ .rip = .{
1106 .ptr_size = @enumFromInt(Memory.PtrSize, mrip.ptr_size),1106 .ptr_size = @as(Memory.PtrSize, @enumFromInt(mrip.ptr_size)),
1107 .disp = mrip.disp,1107 .disp = mrip.disp,
1108 } };1108 } };
1109 }1109 }
...@@ -1120,14 +1120,14 @@ pub const MemoryMoffs = struct {...@@ -1120,14 +1120,14 @@ pub const MemoryMoffs = struct {
1120 pub fn encode(seg: Register, offset: u64) MemoryMoffs {1120 pub fn encode(seg: Register, offset: u64) MemoryMoffs {
1121 return .{1121 return .{
1122 .seg = @intFromEnum(seg),1122 .seg = @intFromEnum(seg),
1123 .msb = @truncate(u32, offset >> 32),1123 .msb = @as(u32, @truncate(offset >> 32)),
1124 .lsb = @truncate(u32, offset >> 0),1124 .lsb = @as(u32, @truncate(offset >> 0)),
1125 };1125 };
1126 }1126 }
11271127
1128 pub fn decode(moffs: MemoryMoffs) Memory {1128 pub fn decode(moffs: MemoryMoffs) Memory {
1129 return .{ .moffs = .{1129 return .{ .moffs = .{
1130 .seg = @enumFromInt(Register, moffs.seg),1130 .seg = @as(Register, @enumFromInt(moffs.seg)),
1131 .offset = @as(u64, moffs.msb) << 32 | @as(u64, moffs.lsb) << 0,1131 .offset = @as(u64, moffs.msb) << 32 | @as(u64, moffs.lsb) << 0,
1132 } };1132 } };
1133 }1133 }
...@@ -1147,7 +1147,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: u32) struct { data: T, end:...@@ -1147,7 +1147,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: u32) struct { data: T, end:
1147 inline for (fields) |field| {1147 inline for (fields) |field| {
1148 @field(result, field.name) = switch (field.type) {1148 @field(result, field.name) = switch (field.type) {
1149 u32 => mir.extra[i],1149 u32 => mir.extra[i],
1150 i32 => @bitCast(i32, mir.extra[i]),1150 i32 => @as(i32, @bitCast(mir.extra[i])),
1151 else => @compileError("bad field type"),1151 else => @compileError("bad field type"),
1152 };1152 };
1153 i += 1;1153 i += 1;
src/arch/x86_64/abi.zig+2-2
...@@ -278,7 +278,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {...@@ -278,7 +278,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {
278 // "Otherwise class SSE is used."278 // "Otherwise class SSE is used."
279 result[result_i] = .sse;279 result[result_i] = .sse;
280 }280 }
281 byte_i += @intCast(usize, field_size);281 byte_i += @as(usize, @intCast(field_size));
282 if (byte_i == 8) {282 if (byte_i == 8) {
283 byte_i = 0;283 byte_i = 0;
284 result_i += 1;284 result_i += 1;
...@@ -293,7 +293,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {...@@ -293,7 +293,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {
293 result_i += field_class.len;293 result_i += field_class.len;
294 // If there are any bytes leftover, we have to try to combine294 // If there are any bytes leftover, we have to try to combine
295 // the next field with them.295 // the next field with them.
296 byte_i = @intCast(usize, field_size % 8);296 byte_i = @as(usize, @intCast(field_size % 8));
297 if (byte_i != 0) result_i -= 1;297 if (byte_i != 0) result_i -= 1;
298 }298 }
299 }299 }
src/arch/x86_64/bits.zig+16-16
...@@ -232,7 +232,7 @@ pub const Register = enum(u7) {...@@ -232,7 +232,7 @@ pub const Register = enum(u7) {
232 else => unreachable,232 else => unreachable,
233 // zig fmt: on233 // zig fmt: on
234 };234 };
235 return @intCast(u6, @intFromEnum(reg) - base);235 return @as(u6, @intCast(@intFromEnum(reg) - base));
236 }236 }
237237
238 pub fn bitSize(reg: Register) u64 {238 pub fn bitSize(reg: Register) u64 {
...@@ -291,11 +291,11 @@ pub const Register = enum(u7) {...@@ -291,11 +291,11 @@ pub const Register = enum(u7) {
291 else => unreachable,291 else => unreachable,
292 // zig fmt: on292 // zig fmt: on
293 };293 };
294 return @truncate(u4, @intFromEnum(reg) - base);294 return @as(u4, @truncate(@intFromEnum(reg) - base));
295 }295 }
296296
297 pub fn lowEnc(reg: Register) u3 {297 pub fn lowEnc(reg: Register) u3 {
298 return @truncate(u3, reg.enc());298 return @as(u3, @truncate(reg.enc()));
299 }299 }
300300
301 pub fn toBitSize(reg: Register, bit_size: u64) Register {301 pub fn toBitSize(reg: Register, bit_size: u64) Register {
...@@ -325,19 +325,19 @@ pub const Register = enum(u7) {...@@ -325,19 +325,19 @@ pub const Register = enum(u7) {
325 }325 }
326326
327 pub fn to64(reg: Register) Register {327 pub fn to64(reg: Register) Register {
328 return @enumFromInt(Register, @intFromEnum(reg) - reg.gpBase() + @intFromEnum(Register.rax));328 return @as(Register, @enumFromInt(@intFromEnum(reg) - reg.gpBase() + @intFromEnum(Register.rax)));
329 }329 }
330330
331 pub fn to32(reg: Register) Register {331 pub fn to32(reg: Register) Register {
332 return @enumFromInt(Register, @intFromEnum(reg) - reg.gpBase() + @intFromEnum(Register.eax));332 return @as(Register, @enumFromInt(@intFromEnum(reg) - reg.gpBase() + @intFromEnum(Register.eax)));
333 }333 }
334334
335 pub fn to16(reg: Register) Register {335 pub fn to16(reg: Register) Register {
336 return @enumFromInt(Register, @intFromEnum(reg) - reg.gpBase() + @intFromEnum(Register.ax));336 return @as(Register, @enumFromInt(@intFromEnum(reg) - reg.gpBase() + @intFromEnum(Register.ax)));
337 }337 }
338338
339 pub fn to8(reg: Register) Register {339 pub fn to8(reg: Register) Register {
340 return @enumFromInt(Register, @intFromEnum(reg) - reg.gpBase() + @intFromEnum(Register.al));340 return @as(Register, @enumFromInt(@intFromEnum(reg) - reg.gpBase() + @intFromEnum(Register.al)));
341 }341 }
342342
343 fn sseBase(reg: Register) u7 {343 fn sseBase(reg: Register) u7 {
...@@ -350,11 +350,11 @@ pub const Register = enum(u7) {...@@ -350,11 +350,11 @@ pub const Register = enum(u7) {
350 }350 }
351351
352 pub fn to256(reg: Register) Register {352 pub fn to256(reg: Register) Register {
353 return @enumFromInt(Register, @intFromEnum(reg) - reg.sseBase() + @intFromEnum(Register.ymm0));353 return @as(Register, @enumFromInt(@intFromEnum(reg) - reg.sseBase() + @intFromEnum(Register.ymm0)));
354 }354 }
355355
356 pub fn to128(reg: Register) Register {356 pub fn to128(reg: Register) Register {
357 return @enumFromInt(Register, @intFromEnum(reg) - reg.sseBase() + @intFromEnum(Register.xmm0));357 return @as(Register, @enumFromInt(@intFromEnum(reg) - reg.sseBase() + @intFromEnum(Register.xmm0)));
358 }358 }
359359
360 /// DWARF register encoding360 /// DWARF register encoding
...@@ -363,7 +363,7 @@ pub const Register = enum(u7) {...@@ -363,7 +363,7 @@ pub const Register = enum(u7) {
363 .general_purpose => if (reg.isExtended())363 .general_purpose => if (reg.isExtended())
364 reg.enc()364 reg.enc()
365 else365 else
366 @truncate(u3, @as(u24, 0o54673120) >> @as(u5, reg.enc()) * 3),366 @as(u3, @truncate(@as(u24, 0o54673120) >> @as(u5, reg.enc()) * 3)),
367 .sse => 17 + @as(u6, reg.enc()),367 .sse => 17 + @as(u6, reg.enc()),
368 .x87 => 33 + @as(u6, reg.enc()),368 .x87 => 33 + @as(u6, reg.enc()),
369 .mmx => 41 + @as(u6, reg.enc()),369 .mmx => 41 + @as(u6, reg.enc()),
...@@ -610,15 +610,15 @@ pub const Immediate = union(enum) {...@@ -610,15 +610,15 @@ pub const Immediate = union(enum) {
610 pub fn asUnsigned(imm: Immediate, bit_size: u64) u64 {610 pub fn asUnsigned(imm: Immediate, bit_size: u64) u64 {
611 return switch (imm) {611 return switch (imm) {
612 .signed => |x| switch (bit_size) {612 .signed => |x| switch (bit_size) {
613 1, 8 => @bitCast(u8, @intCast(i8, x)),613 1, 8 => @as(u8, @bitCast(@as(i8, @intCast(x)))),
614 16 => @bitCast(u16, @intCast(i16, x)),614 16 => @as(u16, @bitCast(@as(i16, @intCast(x)))),
615 32, 64 => @bitCast(u32, x),615 32, 64 => @as(u32, @bitCast(x)),
616 else => unreachable,616 else => unreachable,
617 },617 },
618 .unsigned => |x| switch (bit_size) {618 .unsigned => |x| switch (bit_size) {
619 1, 8 => @intCast(u8, x),619 1, 8 => @as(u8, @intCast(x)),
620 16 => @intCast(u16, x),620 16 => @as(u16, @intCast(x)),
621 32 => @intCast(u32, x),621 32 => @as(u32, @intCast(x)),
622 64 => x,622 64 => x,
623 else => unreachable,623 else => unreachable,
624 },624 },
src/arch/x86_64/encoder.zig+7-7
...@@ -471,7 +471,7 @@ pub const Instruction = struct {...@@ -471,7 +471,7 @@ pub const Instruction = struct {
471 } else {471 } else {
472 try encoder.sib_baseDisp8(dst);472 try encoder.sib_baseDisp8(dst);
473 }473 }
474 try encoder.disp8(@truncate(i8, sib.disp));474 try encoder.disp8(@as(i8, @truncate(sib.disp)));
475 } else {475 } else {
476 try encoder.modRm_SIBDisp32(src);476 try encoder.modRm_SIBDisp32(src);
477 if (mem.scaleIndex()) |si| {477 if (mem.scaleIndex()) |si| {
...@@ -487,7 +487,7 @@ pub const Instruction = struct {...@@ -487,7 +487,7 @@ pub const Instruction = struct {
487 try encoder.modRm_indirectDisp0(src, dst);487 try encoder.modRm_indirectDisp0(src, dst);
488 } else if (math.cast(i8, sib.disp)) |_| {488 } else if (math.cast(i8, sib.disp)) |_| {
489 try encoder.modRm_indirectDisp8(src, dst);489 try encoder.modRm_indirectDisp8(src, dst);
490 try encoder.disp8(@truncate(i8, sib.disp));490 try encoder.disp8(@as(i8, @truncate(sib.disp)));
491 } else {491 } else {
492 try encoder.modRm_indirectDisp32(src, dst);492 try encoder.modRm_indirectDisp32(src, dst);
493 try encoder.disp32(sib.disp);493 try encoder.disp32(sib.disp);
...@@ -509,9 +509,9 @@ pub const Instruction = struct {...@@ -509,9 +509,9 @@ pub const Instruction = struct {
509 fn encodeImm(imm: Immediate, kind: Encoding.Op, encoder: anytype) !void {509 fn encodeImm(imm: Immediate, kind: Encoding.Op, encoder: anytype) !void {
510 const raw = imm.asUnsigned(kind.immBitSize());510 const raw = imm.asUnsigned(kind.immBitSize());
511 switch (kind.immBitSize()) {511 switch (kind.immBitSize()) {
512 8 => try encoder.imm8(@intCast(u8, raw)),512 8 => try encoder.imm8(@as(u8, @intCast(raw))),
513 16 => try encoder.imm16(@intCast(u16, raw)),513 16 => try encoder.imm16(@as(u16, @intCast(raw))),
514 32 => try encoder.imm32(@intCast(u32, raw)),514 32 => try encoder.imm32(@as(u32, @intCast(raw))),
515 64 => try encoder.imm64(raw),515 64 => try encoder.imm64(raw),
516 else => unreachable,516 else => unreachable,
517 }517 }
...@@ -581,7 +581,7 @@ fn Encoder(comptime T: type, comptime opts: Options) type {...@@ -581,7 +581,7 @@ fn Encoder(comptime T: type, comptime opts: Options) type {
581581
582 /// Encodes legacy prefixes582 /// Encodes legacy prefixes
583 pub fn legacyPrefixes(self: Self, prefixes: LegacyPrefixes) !void {583 pub fn legacyPrefixes(self: Self, prefixes: LegacyPrefixes) !void {
584 if (@bitCast(u16, prefixes) != 0) {584 if (@as(u16, @bitCast(prefixes)) != 0) {
585 // Hopefully this path isn't taken very often, so we'll do it the slow way for now585 // Hopefully this path isn't taken very often, so we'll do it the slow way for now
586586
587 // LOCK587 // LOCK
...@@ -891,7 +891,7 @@ fn Encoder(comptime T: type, comptime opts: Options) type {...@@ -891,7 +891,7 @@ fn Encoder(comptime T: type, comptime opts: Options) type {
891 ///891 ///
892 /// It is sign-extended to 64 bits by the cpu.892 /// It is sign-extended to 64 bits by the cpu.
893 pub fn disp8(self: Self, disp: i8) !void {893 pub fn disp8(self: Self, disp: i8) !void {
894 try self.writer.writeByte(@bitCast(u8, disp));894 try self.writer.writeByte(@as(u8, @bitCast(disp)));
895 }895 }
896896
897 /// Encode an 32 bit displacement897 /// Encode an 32 bit displacement
src/clang.zig+1-1
...@@ -117,7 +117,7 @@ pub const APFloatBaseSemantics = enum(c_int) {...@@ -117,7 +117,7 @@ pub const APFloatBaseSemantics = enum(c_int) {
117117
118pub const APInt = opaque {118pub const APInt = opaque {
119 pub fn getLimitedValue(self: *const APInt, comptime T: type) T {119 pub fn getLimitedValue(self: *const APInt, comptime T: type) T {
120 return @truncate(T, ZigClangAPInt_getLimitedValue(self, std.math.maxInt(T)));120 return @as(T, @truncate(ZigClangAPInt_getLimitedValue(self, std.math.maxInt(T))));
121 }121 }
122 extern fn ZigClangAPInt_getLimitedValue(*const APInt, limit: u64) u64;122 extern fn ZigClangAPInt_getLimitedValue(*const APInt, limit: u64) u64;
123};123};
src/codegen.zig+19-19
...@@ -108,7 +108,7 @@ fn writeFloat(comptime F: type, f: F, target: Target, endian: std.builtin.Endian...@@ -108,7 +108,7 @@ fn writeFloat(comptime F: type, f: F, target: Target, endian: std.builtin.Endian
108 _ = target;108 _ = target;
109 const bits = @typeInfo(F).Float.bits;109 const bits = @typeInfo(F).Float.bits;
110 const Int = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = bits } });110 const Int = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = bits } });
111 const int = @bitCast(Int, f);111 const int = @as(Int, @bitCast(f));
112 mem.writeInt(Int, code[0..@divExact(bits, 8)], int, endian);112 mem.writeInt(Int, code[0..@divExact(bits, 8)], int, endian);
113}113}
114114
...@@ -143,18 +143,18 @@ pub fn generateLazySymbol(...@@ -143,18 +143,18 @@ pub fn generateLazySymbol(
143 if (lazy_sym.ty.isAnyError(mod)) {143 if (lazy_sym.ty.isAnyError(mod)) {
144 alignment.* = 4;144 alignment.* = 4;
145 const err_names = mod.global_error_set.keys();145 const err_names = mod.global_error_set.keys();
146 mem.writeInt(u32, try code.addManyAsArray(4), @intCast(u32, err_names.len), endian);146 mem.writeInt(u32, try code.addManyAsArray(4), @as(u32, @intCast(err_names.len)), endian);
147 var offset = code.items.len;147 var offset = code.items.len;
148 try code.resize((1 + err_names.len + 1) * 4);148 try code.resize((1 + err_names.len + 1) * 4);
149 for (err_names) |err_name_nts| {149 for (err_names) |err_name_nts| {
150 const err_name = mod.intern_pool.stringToSlice(err_name_nts);150 const err_name = mod.intern_pool.stringToSlice(err_name_nts);
151 mem.writeInt(u32, code.items[offset..][0..4], @intCast(u32, code.items.len), endian);151 mem.writeInt(u32, code.items[offset..][0..4], @as(u32, @intCast(code.items.len)), endian);
152 offset += 4;152 offset += 4;
153 try code.ensureUnusedCapacity(err_name.len + 1);153 try code.ensureUnusedCapacity(err_name.len + 1);
154 code.appendSliceAssumeCapacity(err_name);154 code.appendSliceAssumeCapacity(err_name);
155 code.appendAssumeCapacity(0);155 code.appendAssumeCapacity(0);
156 }156 }
157 mem.writeInt(u32, code.items[offset..][0..4], @intCast(u32, code.items.len), endian);157 mem.writeInt(u32, code.items[offset..][0..4], @as(u32, @intCast(code.items.len)), endian);
158 return Result.ok;158 return Result.ok;
159 } else if (lazy_sym.ty.zigTypeTag(mod) == .Enum) {159 } else if (lazy_sym.ty.zigTypeTag(mod) == .Enum) {
160 alignment.* = 1;160 alignment.* = 1;
...@@ -253,12 +253,12 @@ pub fn generateSymbol(...@@ -253,12 +253,12 @@ pub fn generateSymbol(
253 },253 },
254 .err => |err| {254 .err => |err| {
255 const int = try mod.getErrorValue(err.name);255 const int = try mod.getErrorValue(err.name);
256 try code.writer().writeInt(u16, @intCast(u16, int), endian);256 try code.writer().writeInt(u16, @as(u16, @intCast(int)), endian);
257 },257 },
258 .error_union => |error_union| {258 .error_union => |error_union| {
259 const payload_ty = typed_value.ty.errorUnionPayload(mod);259 const payload_ty = typed_value.ty.errorUnionPayload(mod);
260 const err_val = switch (error_union.val) {260 const err_val = switch (error_union.val) {
261 .err_name => |err_name| @intCast(u16, try mod.getErrorValue(err_name)),261 .err_name => |err_name| @as(u16, @intCast(try mod.getErrorValue(err_name))),
262 .payload => @as(u16, 0),262 .payload => @as(u16, 0),
263 };263 };
264264
...@@ -397,7 +397,7 @@ pub fn generateSymbol(...@@ -397,7 +397,7 @@ pub fn generateSymbol(
397 .ty = array_type.child.toType(),397 .ty = array_type.child.toType(),
398 .val = switch (aggregate.storage) {398 .val = switch (aggregate.storage) {
399 .bytes => unreachable,399 .bytes => unreachable,
400 .elems => |elems| elems[@intCast(usize, index)],400 .elems => |elems| elems[@as(usize, @intCast(index))],
401 .repeated_elem => |elem| elem,401 .repeated_elem => |elem| elem,
402 }.toValue(),402 }.toValue(),
403 }, code, debug_output, reloc_info)) {403 }, code, debug_output, reloc_info)) {
...@@ -417,7 +417,7 @@ pub fn generateSymbol(...@@ -417,7 +417,7 @@ pub fn generateSymbol(
417 .ty = vector_type.child.toType(),417 .ty = vector_type.child.toType(),
418 .val = switch (aggregate.storage) {418 .val = switch (aggregate.storage) {
419 .bytes => unreachable,419 .bytes => unreachable,
420 .elems => |elems| elems[@intCast(usize, index)],420 .elems => |elems| elems[@as(usize, @intCast(index))],
421 .repeated_elem => |elem| elem,421 .repeated_elem => |elem| elem,
422 }.toValue(),422 }.toValue(),
423 }, code, debug_output, reloc_info)) {423 }, code, debug_output, reloc_info)) {
...@@ -509,7 +509,7 @@ pub fn generateSymbol(...@@ -509,7 +509,7 @@ pub fn generateSymbol(
509 } else {509 } else {
510 field_val.toValue().writeToPackedMemory(field_ty, mod, code.items[current_pos..], bits) catch unreachable;510 field_val.toValue().writeToPackedMemory(field_ty, mod, code.items[current_pos..], bits) catch unreachable;
511 }511 }
512 bits += @intCast(u16, field_ty.bitSize(mod));512 bits += @as(u16, @intCast(field_ty.bitSize(mod)));
513 }513 }
514 } else {514 } else {
515 const struct_begin = code.items.len;515 const struct_begin = code.items.len;
...@@ -642,10 +642,10 @@ fn lowerParentPtr(...@@ -642,10 +642,10 @@ fn lowerParentPtr(
642 eu_payload,642 eu_payload,
643 code,643 code,
644 debug_output,644 debug_output,
645 reloc_info.offset(@intCast(u32, errUnionPayloadOffset(645 reloc_info.offset(@as(u32, @intCast(errUnionPayloadOffset(
646 mod.intern_pool.typeOf(eu_payload).toType(),646 mod.intern_pool.typeOf(eu_payload).toType(),
647 mod,647 mod,
648 ))),648 )))),
649 ),649 ),
650 .opt_payload => |opt_payload| try lowerParentPtr(650 .opt_payload => |opt_payload| try lowerParentPtr(
651 bin_file,651 bin_file,
...@@ -661,8 +661,8 @@ fn lowerParentPtr(...@@ -661,8 +661,8 @@ fn lowerParentPtr(
661 elem.base,661 elem.base,
662 code,662 code,
663 debug_output,663 debug_output,
664 reloc_info.offset(@intCast(u32, elem.index *664 reloc_info.offset(@as(u32, @intCast(elem.index *
665 mod.intern_pool.typeOf(elem.base).toType().elemType2(mod).abiSize(mod))),665 mod.intern_pool.typeOf(elem.base).toType().elemType2(mod).abiSize(mod)))),
666 ),666 ),
667 .field => |field| {667 .field => |field| {
668 const base_type = mod.intern_pool.indexToKey(mod.intern_pool.typeOf(field.base)).ptr_type.child;668 const base_type = mod.intern_pool.indexToKey(mod.intern_pool.typeOf(field.base)).ptr_type.child;
...@@ -684,10 +684,10 @@ fn lowerParentPtr(...@@ -684,10 +684,10 @@ fn lowerParentPtr(
684 .struct_type,684 .struct_type,
685 .anon_struct_type,685 .anon_struct_type,
686 .union_type,686 .union_type,
687 => @intCast(u32, base_type.toType().structFieldOffset(687 => @as(u32, @intCast(base_type.toType().structFieldOffset(
688 @intCast(u32, field.index),688 @as(u32, @intCast(field.index)),
689 mod,689 mod,
690 )),690 ))),
691 else => unreachable,691 else => unreachable,
692 }),692 }),
693 );693 );
...@@ -735,8 +735,8 @@ fn lowerDeclRef(...@@ -735,8 +735,8 @@ fn lowerDeclRef(
735 });735 });
736 const endian = target.cpu.arch.endian();736 const endian = target.cpu.arch.endian();
737 switch (ptr_width) {737 switch (ptr_width) {
738 16 => mem.writeInt(u16, try code.addManyAsArray(2), @intCast(u16, vaddr), endian),738 16 => mem.writeInt(u16, try code.addManyAsArray(2), @as(u16, @intCast(vaddr)), endian),
739 32 => mem.writeInt(u32, try code.addManyAsArray(4), @intCast(u32, vaddr), endian),739 32 => mem.writeInt(u32, try code.addManyAsArray(4), @as(u32, @intCast(vaddr)), endian),
740 64 => mem.writeInt(u64, try code.addManyAsArray(8), vaddr, endian),740 64 => mem.writeInt(u64, try code.addManyAsArray(8), vaddr, endian),
741 else => unreachable,741 else => unreachable,
742 }742 }
...@@ -945,7 +945,7 @@ pub fn genTypedValue(...@@ -945,7 +945,7 @@ pub fn genTypedValue(
945 const info = typed_value.ty.intInfo(mod);945 const info = typed_value.ty.intInfo(mod);
946 if (info.bits <= ptr_bits) {946 if (info.bits <= ptr_bits) {
947 const unsigned = switch (info.signedness) {947 const unsigned = switch (info.signedness) {
948 .signed => @bitCast(u64, typed_value.val.toSignedInt(mod)),948 .signed => @as(u64, @bitCast(typed_value.val.toSignedInt(mod))),
949 .unsigned => typed_value.val.toUnsignedInt(mod),949 .unsigned => typed_value.val.toUnsignedInt(mod),
950 };950 };
951 return GenResult.mcv(.{ .immediate = unsigned });951 return GenResult.mcv(.{ .immediate = unsigned });
src/codegen/c.zig+51-51
...@@ -326,7 +326,7 @@ pub const Function = struct {...@@ -326,7 +326,7 @@ pub const Function = struct {
326 .cty_idx = try f.typeToIndex(ty, .complete),326 .cty_idx = try f.typeToIndex(ty, .complete),
327 .alignas = CType.AlignAs.init(alignment, ty.abiAlignment(mod)),327 .alignas = CType.AlignAs.init(alignment, ty.abiAlignment(mod)),
328 });328 });
329 return .{ .new_local = @intCast(LocalIndex, f.locals.items.len - 1) };329 return .{ .new_local = @as(LocalIndex, @intCast(f.locals.items.len - 1)) };
330 }330 }
331331
332 fn allocLocal(f: *Function, inst: Air.Inst.Index, ty: Type) !CValue {332 fn allocLocal(f: *Function, inst: Air.Inst.Index, ty: Type) !CValue {
...@@ -644,7 +644,7 @@ pub const DeclGen = struct {...@@ -644,7 +644,7 @@ pub const DeclGen = struct {
644 // Ensure complete type definition is visible before accessing fields.644 // Ensure complete type definition is visible before accessing fields.
645 _ = try dg.typeToIndex(base_ty, .complete);645 _ = try dg.typeToIndex(base_ty, .complete);
646 const field_ty = switch (mod.intern_pool.indexToKey(base_ty.toIntern())) {646 const field_ty = switch (mod.intern_pool.indexToKey(base_ty.toIntern())) {
647 .anon_struct_type, .struct_type, .union_type => base_ty.structFieldType(@intCast(usize, field.index), mod),647 .anon_struct_type, .struct_type, .union_type => base_ty.structFieldType(@as(usize, @intCast(field.index)), mod),
648 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {648 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
649 .One, .Many, .C => unreachable,649 .One, .Many, .C => unreachable,
650 .Slice => switch (field.index) {650 .Slice => switch (field.index) {
...@@ -662,7 +662,7 @@ pub const DeclGen = struct {...@@ -662,7 +662,7 @@ pub const DeclGen = struct {
662 try dg.renderCType(writer, ptr_cty);662 try dg.renderCType(writer, ptr_cty);
663 try writer.writeByte(')');663 try writer.writeByte(')');
664 }664 }
665 switch (fieldLocation(base_ty, ptr_ty, @intCast(u32, field.index), mod)) {665 switch (fieldLocation(base_ty, ptr_ty, @as(u32, @intCast(field.index)), mod)) {
666 .begin => try dg.renderParentPtr(writer, field.base, location),666 .begin => try dg.renderParentPtr(writer, field.base, location),
667 .field => |name| {667 .field => |name| {
668 try writer.writeAll("&(");668 try writer.writeAll("&(");
...@@ -740,11 +740,11 @@ pub const DeclGen = struct {...@@ -740,11 +740,11 @@ pub const DeclGen = struct {
740 try dg.renderTypeForBuiltinFnName(writer, ty);740 try dg.renderTypeForBuiltinFnName(writer, ty);
741 try writer.writeByte('(');741 try writer.writeByte('(');
742 switch (bits) {742 switch (bits) {
743 16 => try writer.print("{x}", .{@bitCast(f16, undefPattern(i16))}),743 16 => try writer.print("{x}", .{@as(f16, @bitCast(undefPattern(i16)))}),
744 32 => try writer.print("{x}", .{@bitCast(f32, undefPattern(i32))}),744 32 => try writer.print("{x}", .{@as(f32, @bitCast(undefPattern(i32)))}),
745 64 => try writer.print("{x}", .{@bitCast(f64, undefPattern(i64))}),745 64 => try writer.print("{x}", .{@as(f64, @bitCast(undefPattern(i64)))}),
746 80 => try writer.print("{x}", .{@bitCast(f80, undefPattern(i80))}),746 80 => try writer.print("{x}", .{@as(f80, @bitCast(undefPattern(i80)))}),
747 128 => try writer.print("{x}", .{@bitCast(f128, undefPattern(i128))}),747 128 => try writer.print("{x}", .{@as(f128, @bitCast(undefPattern(i128)))}),
748 else => unreachable,748 else => unreachable,
749 }749 }
750 try writer.writeAll(", ");750 try writer.writeAll(", ");
...@@ -1041,11 +1041,11 @@ pub const DeclGen = struct {...@@ -1041,11 +1041,11 @@ pub const DeclGen = struct {
1041 };1041 };
10421042
1043 switch (bits) {1043 switch (bits) {
1044 16 => repr_val_big.set(@bitCast(u16, val.toFloat(f16, mod))),1044 16 => repr_val_big.set(@as(u16, @bitCast(val.toFloat(f16, mod)))),
1045 32 => repr_val_big.set(@bitCast(u32, val.toFloat(f32, mod))),1045 32 => repr_val_big.set(@as(u32, @bitCast(val.toFloat(f32, mod)))),
1046 64 => repr_val_big.set(@bitCast(u64, val.toFloat(f64, mod))),1046 64 => repr_val_big.set(@as(u64, @bitCast(val.toFloat(f64, mod)))),
1047 80 => repr_val_big.set(@bitCast(u80, val.toFloat(f80, mod))),1047 80 => repr_val_big.set(@as(u80, @bitCast(val.toFloat(f80, mod)))),
1048 128 => repr_val_big.set(@bitCast(u128, f128_val)),1048 128 => repr_val_big.set(@as(u128, @bitCast(f128_val))),
1049 else => unreachable,1049 else => unreachable,
1050 }1050 }
10511051
...@@ -1103,11 +1103,11 @@ pub const DeclGen = struct {...@@ -1103,11 +1103,11 @@ pub const DeclGen = struct {
1103 if (std.math.isNan(f128_val)) switch (bits) {1103 if (std.math.isNan(f128_val)) switch (bits) {
1104 // We only actually need to pass the significand, but it will get1104 // We only actually need to pass the significand, but it will get
1105 // properly masked anyway, so just pass the whole value.1105 // properly masked anyway, so just pass the whole value.
1106 16 => try writer.print("\"0x{x}\"", .{@bitCast(u16, val.toFloat(f16, mod))}),1106 16 => try writer.print("\"0x{x}\"", .{@as(u16, @bitCast(val.toFloat(f16, mod)))}),
1107 32 => try writer.print("\"0x{x}\"", .{@bitCast(u32, val.toFloat(f32, mod))}),1107 32 => try writer.print("\"0x{x}\"", .{@as(u32, @bitCast(val.toFloat(f32, mod)))}),
1108 64 => try writer.print("\"0x{x}\"", .{@bitCast(u64, val.toFloat(f64, mod))}),1108 64 => try writer.print("\"0x{x}\"", .{@as(u64, @bitCast(val.toFloat(f64, mod)))}),
1109 80 => try writer.print("\"0x{x}\"", .{@bitCast(u80, val.toFloat(f80, mod))}),1109 80 => try writer.print("\"0x{x}\"", .{@as(u80, @bitCast(val.toFloat(f80, mod)))}),
1110 128 => try writer.print("\"0x{x}\"", .{@bitCast(u128, f128_val)}),1110 128 => try writer.print("\"0x{x}\"", .{@as(u128, @bitCast(f128_val))}),
1111 else => unreachable,1111 else => unreachable,
1112 };1112 };
1113 try writer.writeAll(", ");1113 try writer.writeAll(", ");
...@@ -1225,11 +1225,11 @@ pub const DeclGen = struct {...@@ -1225,11 +1225,11 @@ pub const DeclGen = struct {
1225 var index: usize = 0;1225 var index: usize = 0;
1226 while (index < ai.len) : (index += 1) {1226 while (index < ai.len) : (index += 1) {
1227 const elem_val = try val.elemValue(mod, index);1227 const elem_val = try val.elemValue(mod, index);
1228 const elem_val_u8 = if (elem_val.isUndef(mod)) undefPattern(u8) else @intCast(u8, elem_val.toUnsignedInt(mod));1228 const elem_val_u8 = if (elem_val.isUndef(mod)) undefPattern(u8) else @as(u8, @intCast(elem_val.toUnsignedInt(mod)));
1229 try literal.writeChar(elem_val_u8);1229 try literal.writeChar(elem_val_u8);
1230 }1230 }
1231 if (ai.sentinel) |s| {1231 if (ai.sentinel) |s| {
1232 const s_u8 = @intCast(u8, s.toUnsignedInt(mod));1232 const s_u8 = @as(u8, @intCast(s.toUnsignedInt(mod)));
1233 if (s_u8 != 0) try literal.writeChar(s_u8);1233 if (s_u8 != 0) try literal.writeChar(s_u8);
1234 }1234 }
1235 try literal.end();1235 try literal.end();
...@@ -1239,7 +1239,7 @@ pub const DeclGen = struct {...@@ -1239,7 +1239,7 @@ pub const DeclGen = struct {
1239 while (index < ai.len) : (index += 1) {1239 while (index < ai.len) : (index += 1) {
1240 if (index != 0) try writer.writeByte(',');1240 if (index != 0) try writer.writeByte(',');
1241 const elem_val = try val.elemValue(mod, index);1241 const elem_val = try val.elemValue(mod, index);
1242 const elem_val_u8 = if (elem_val.isUndef(mod)) undefPattern(u8) else @intCast(u8, elem_val.toUnsignedInt(mod));1242 const elem_val_u8 = if (elem_val.isUndef(mod)) undefPattern(u8) else @as(u8, @intCast(elem_val.toUnsignedInt(mod)));
1243 try writer.print("'\\x{x}'", .{elem_val_u8});1243 try writer.print("'\\x{x}'", .{elem_val_u8});
1244 }1244 }
1245 if (ai.sentinel) |s| {1245 if (ai.sentinel) |s| {
...@@ -1840,7 +1840,7 @@ pub const DeclGen = struct {...@@ -1840,7 +1840,7 @@ pub const DeclGen = struct {
1840 decl.ty,1840 decl.ty,
1841 .{ .decl = decl_index },1841 .{ .decl = decl_index },
1842 CQualifiers.init(.{ .@"const" = variable.is_const }),1842 CQualifiers.init(.{ .@"const" = variable.is_const }),
1843 @intCast(u32, decl.alignment.toByteUnits(0)),1843 @as(u32, @intCast(decl.alignment.toByteUnits(0))),
1844 .complete,1844 .complete,
1845 );1845 );
1846 try fwd_decl_writer.writeAll(";\n");1846 try fwd_decl_writer.writeAll(";\n");
...@@ -1907,7 +1907,7 @@ pub const DeclGen = struct {...@@ -1907,7 +1907,7 @@ pub const DeclGen = struct {
1907 const mod = dg.module;1907 const mod = dg.module;
1908 const int_info = if (ty.isAbiInt(mod)) ty.intInfo(mod) else std.builtin.Type.Int{1908 const int_info = if (ty.isAbiInt(mod)) ty.intInfo(mod) else std.builtin.Type.Int{
1909 .signedness = .unsigned,1909 .signedness = .unsigned,
1910 .bits = @intCast(u16, ty.bitSize(mod)),1910 .bits = @as(u16, @intCast(ty.bitSize(mod))),
1911 };1911 };
19121912
1913 if (is_big) try writer.print(", {}", .{int_info.signedness == .signed});1913 if (is_big) try writer.print(", {}", .{int_info.signedness == .signed});
...@@ -2481,7 +2481,7 @@ fn genExports(o: *Object) !void {...@@ -2481,7 +2481,7 @@ fn genExports(o: *Object) !void {
2481 if (mod.decl_exports.get(o.dg.decl_index.unwrap().?)) |exports| {2481 if (mod.decl_exports.get(o.dg.decl_index.unwrap().?)) |exports| {
2482 for (exports.items[1..], 1..) |@"export", i| {2482 for (exports.items[1..], 1..) |@"export", i| {
2483 try fwd_decl_writer.writeAll("zig_export(");2483 try fwd_decl_writer.writeAll("zig_export(");
2484 try o.dg.renderFunctionSignature(fwd_decl_writer, o.dg.decl_index.unwrap().?, .forward, .{ .export_index = @intCast(u32, i) });2484 try o.dg.renderFunctionSignature(fwd_decl_writer, o.dg.decl_index.unwrap().?, .forward, .{ .export_index = @as(u32, @intCast(i)) });
2485 try fwd_decl_writer.print(", {s}, {s});\n", .{2485 try fwd_decl_writer.print(", {s}, {s});\n", .{
2486 fmtStringLiteral(ip.stringToSlice(exports.items[0].opts.name), null),2486 fmtStringLiteral(ip.stringToSlice(exports.items[0].opts.name), null),
2487 fmtStringLiteral(ip.stringToSlice(@"export".opts.name), null),2487 fmtStringLiteral(ip.stringToSlice(@"export".opts.name), null),
...@@ -2510,7 +2510,7 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void {...@@ -2510,7 +2510,7 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void {
2510 try o.dg.renderTypeAndName(w, enum_ty, .{ .identifier = "tag" }, Const, 0, .complete);2510 try o.dg.renderTypeAndName(w, enum_ty, .{ .identifier = "tag" }, Const, 0, .complete);
2511 try w.writeAll(") {\n switch (tag) {\n");2511 try w.writeAll(") {\n switch (tag) {\n");
2512 for (enum_ty.enumFields(mod), 0..) |name_ip, index_usize| {2512 for (enum_ty.enumFields(mod), 0..) |name_ip, index_usize| {
2513 const index = @intCast(u32, index_usize);2513 const index = @as(u32, @intCast(index_usize));
2514 const name = mod.intern_pool.stringToSlice(name_ip);2514 const name = mod.intern_pool.stringToSlice(name_ip);
2515 const tag_val = try mod.enumValueFieldIndex(enum_ty, index);2515 const tag_val = try mod.enumValueFieldIndex(enum_ty, index);
25162516
...@@ -2783,7 +2783,7 @@ fn genBodyResolveState(f: *Function, inst: Air.Inst.Index, leading_deaths: []con...@@ -2783,7 +2783,7 @@ fn genBodyResolveState(f: *Function, inst: Air.Inst.Index, leading_deaths: []con
2783 // Remember how many locals there were before entering the body so that we can free any that2783 // Remember how many locals there were before entering the body so that we can free any that
2784 // were newly introduced. Any new locals must necessarily be logically free after the then2784 // were newly introduced. Any new locals must necessarily be logically free after the then
2785 // branch is complete.2785 // branch is complete.
2786 const pre_locals_len = @intCast(LocalIndex, f.locals.items.len);2786 const pre_locals_len = @as(LocalIndex, @intCast(f.locals.items.len));
27872787
2788 for (leading_deaths) |death| {2788 for (leading_deaths) |death| {
2789 try die(f, inst, Air.indexToRef(death));2789 try die(f, inst, Air.indexToRef(death));
...@@ -2804,7 +2804,7 @@ fn genBodyResolveState(f: *Function, inst: Air.Inst.Index, leading_deaths: []con...@@ -2804,7 +2804,7 @@ fn genBodyResolveState(f: *Function, inst: Air.Inst.Index, leading_deaths: []con
2804 // them, unless they were used to store allocs.2804 // them, unless they were used to store allocs.
28052805
2806 for (pre_locals_len..f.locals.items.len) |local_i| {2806 for (pre_locals_len..f.locals.items.len) |local_i| {
2807 const local_index = @intCast(LocalIndex, local_i);2807 const local_index = @as(LocalIndex, @intCast(local_i));
2808 if (f.allocs.contains(local_index)) {2808 if (f.allocs.contains(local_index)) {
2809 continue;2809 continue;
2810 }2810 }
...@@ -3364,7 +3364,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3364,7 +3364,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
3364 const bit_offset_ty = try mod.intType(.unsigned, Type.smallestUnsignedBits(host_bits - 1));3364 const bit_offset_ty = try mod.intType(.unsigned, Type.smallestUnsignedBits(host_bits - 1));
3365 const bit_offset_val = try mod.intValue(bit_offset_ty, ptr_info.packed_offset.bit_offset);3365 const bit_offset_val = try mod.intValue(bit_offset_ty, ptr_info.packed_offset.bit_offset);
33663366
3367 const field_ty = try mod.intType(.unsigned, @intCast(u16, src_ty.bitSize(mod)));3367 const field_ty = try mod.intType(.unsigned, @as(u16, @intCast(src_ty.bitSize(mod))));
33683368
3369 try f.writeCValue(writer, local, .Other);3369 try f.writeCValue(writer, local, .Other);
3370 try v.elem(f, writer);3370 try v.elem(f, writer);
...@@ -3667,7 +3667,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -3667,7 +3667,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
3667 var mask = try BigInt.Managed.initCapacity(stack.get(), BigInt.calcTwosCompLimbCount(host_bits));3667 var mask = try BigInt.Managed.initCapacity(stack.get(), BigInt.calcTwosCompLimbCount(host_bits));
3668 defer mask.deinit();3668 defer mask.deinit();
36693669
3670 try mask.setTwosCompIntLimit(.max, .unsigned, @intCast(usize, src_bits));3670 try mask.setTwosCompIntLimit(.max, .unsigned, @as(usize, @intCast(src_bits)));
3671 try mask.shiftLeft(&mask, ptr_info.packed_offset.bit_offset);3671 try mask.shiftLeft(&mask, ptr_info.packed_offset.bit_offset);
3672 try mask.bitNotWrap(&mask, .unsigned, host_bits);3672 try mask.bitNotWrap(&mask, .unsigned, host_bits);
36733673
...@@ -4096,7 +4096,7 @@ fn airCall(...@@ -4096,7 +4096,7 @@ fn airCall(
40964096
4097 const pl_op = f.air.instructions.items(.data)[inst].pl_op;4097 const pl_op = f.air.instructions.items(.data)[inst].pl_op;
4098 const extra = f.air.extraData(Air.Call, pl_op.payload);4098 const extra = f.air.extraData(Air.Call, pl_op.payload);
4099 const args = @ptrCast([]const Air.Inst.Ref, f.air.extra[extra.end..][0..extra.data.args_len]);4099 const args = @as([]const Air.Inst.Ref, @ptrCast(f.air.extra[extra.end..][0..extra.data.args_len]));
41004100
4101 const resolved_args = try gpa.alloc(CValue, args.len);4101 const resolved_args = try gpa.alloc(CValue, args.len);
4102 defer gpa.free(resolved_args);4102 defer gpa.free(resolved_args);
...@@ -4537,7 +4537,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca...@@ -4537,7 +4537,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca
4537 wrap_cty = elem_cty.toSignedness(dest_info.signedness);4537 wrap_cty = elem_cty.toSignedness(dest_info.signedness);
4538 need_bitcasts = wrap_cty.?.tag() == .zig_i128;4538 need_bitcasts = wrap_cty.?.tag() == .zig_i128;
4539 bits -= 1;4539 bits -= 1;
4540 bits %= @intCast(u16, f.byteSize(elem_cty) * 8);4540 bits %= @as(u16, @intCast(f.byteSize(elem_cty) * 8));
4541 bits += 1;4541 bits += 1;
4542 }4542 }
4543 try writer.writeAll(" = ");4543 try writer.writeAll(" = ");
...@@ -4711,7 +4711,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4711,7 +4711,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
4711 var extra_index: usize = switch_br.end;4711 var extra_index: usize = switch_br.end;
4712 for (0..switch_br.data.cases_len) |case_i| {4712 for (0..switch_br.data.cases_len) |case_i| {
4713 const case = f.air.extraData(Air.SwitchBr.Case, extra_index);4713 const case = f.air.extraData(Air.SwitchBr.Case, extra_index);
4714 const items = @ptrCast([]const Air.Inst.Ref, f.air.extra[case.end..][0..case.data.items_len]);4714 const items = @as([]const Air.Inst.Ref, @ptrCast(f.air.extra[case.end..][0..case.data.items_len]));
4715 const case_body = f.air.extra[case.end + items.len ..][0..case.data.body_len];4715 const case_body = f.air.extra[case.end + items.len ..][0..case.data.body_len];
4716 extra_index = case.end + case.data.items_len + case_body.len;4716 extra_index = case.end + case.data.items_len + case_body.len;
47174717
...@@ -4771,13 +4771,13 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4771,13 +4771,13 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
4771 const mod = f.object.dg.module;4771 const mod = f.object.dg.module;
4772 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;4772 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
4773 const extra = f.air.extraData(Air.Asm, ty_pl.payload);4773 const extra = f.air.extraData(Air.Asm, ty_pl.payload);
4774 const is_volatile = @truncate(u1, extra.data.flags >> 31) != 0;4774 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
4775 const clobbers_len = @truncate(u31, extra.data.flags);4775 const clobbers_len = @as(u31, @truncate(extra.data.flags));
4776 const gpa = f.object.dg.gpa;4776 const gpa = f.object.dg.gpa;
4777 var extra_i: usize = extra.end;4777 var extra_i: usize = extra.end;
4778 const outputs = @ptrCast([]const Air.Inst.Ref, f.air.extra[extra_i..][0..extra.data.outputs_len]);4778 const outputs = @as([]const Air.Inst.Ref, @ptrCast(f.air.extra[extra_i..][0..extra.data.outputs_len]));
4779 extra_i += outputs.len;4779 extra_i += outputs.len;
4780 const inputs = @ptrCast([]const Air.Inst.Ref, f.air.extra[extra_i..][0..extra.data.inputs_len]);4780 const inputs = @as([]const Air.Inst.Ref, @ptrCast(f.air.extra[extra_i..][0..extra.data.inputs_len]));
4781 extra_i += inputs.len;4781 extra_i += inputs.len;
47824782
4783 const result = result: {4783 const result = result: {
...@@ -4794,7 +4794,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4794,7 +4794,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
4794 break :local local;4794 break :local local;
4795 } else .none;4795 } else .none;
47964796
4797 const locals_begin = @intCast(LocalIndex, f.locals.items.len);4797 const locals_begin = @as(LocalIndex, @intCast(f.locals.items.len));
4798 const constraints_extra_begin = extra_i;4798 const constraints_extra_begin = extra_i;
4799 for (outputs) |output| {4799 for (outputs) |output| {
4800 const extra_bytes = mem.sliceAsBytes(f.air.extra[extra_i..]);4800 const extra_bytes = mem.sliceAsBytes(f.air.extra[extra_i..]);
...@@ -5402,7 +5402,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5402,7 +5402,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
5402 inst_ty.intInfo(mod).signedness5402 inst_ty.intInfo(mod).signedness
5403 else5403 else
5404 .unsigned;5404 .unsigned;
5405 const field_int_ty = try mod.intType(field_int_signedness, @intCast(u16, inst_ty.bitSize(mod)));5405 const field_int_ty = try mod.intType(field_int_signedness, @as(u16, @intCast(inst_ty.bitSize(mod))));
54065406
5407 const temp_local = try f.allocLocal(inst, field_int_ty);5407 const temp_local = try f.allocLocal(inst, field_int_ty);
5408 try f.writeCValue(writer, temp_local, .Other);5408 try f.writeCValue(writer, temp_local, .Other);
...@@ -6033,7 +6033,7 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue...@@ -6033,7 +6033,7 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue
6033 try reap(f, inst, &.{ extra.ptr, extra.expected_value, extra.new_value });6033 try reap(f, inst, &.{ extra.ptr, extra.expected_value, extra.new_value });
60346034
6035 const repr_ty = if (ty.isRuntimeFloat())6035 const repr_ty = if (ty.isRuntimeFloat())
6036 mod.intType(.unsigned, @intCast(u16, ty.abiSize(mod) * 8)) catch unreachable6036 mod.intType(.unsigned, @as(u16, @intCast(ty.abiSize(mod) * 8))) catch unreachable
6037 else6037 else
6038 ty;6038 ty;
60396039
...@@ -6136,7 +6136,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6136,7 +6136,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {
6136 const operand_mat = try Materialize.start(f, inst, writer, ty, operand);6136 const operand_mat = try Materialize.start(f, inst, writer, ty, operand);
6137 try reap(f, inst, &.{ pl_op.operand, extra.operand });6137 try reap(f, inst, &.{ pl_op.operand, extra.operand });
61386138
6139 const repr_bits = @intCast(u16, ty.abiSize(mod) * 8);6139 const repr_bits = @as(u16, @intCast(ty.abiSize(mod) * 8));
6140 const is_float = ty.isRuntimeFloat();6140 const is_float = ty.isRuntimeFloat();
6141 const is_128 = repr_bits == 128;6141 const is_128 = repr_bits == 128;
6142 const repr_ty = if (is_float) mod.intType(.unsigned, repr_bits) catch unreachable else ty;6142 const repr_ty = if (is_float) mod.intType(.unsigned, repr_bits) catch unreachable else ty;
...@@ -6186,7 +6186,7 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6186,7 +6186,7 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue {
6186 const ty = ptr_ty.childType(mod);6186 const ty = ptr_ty.childType(mod);
61876187
6188 const repr_ty = if (ty.isRuntimeFloat())6188 const repr_ty = if (ty.isRuntimeFloat())
6189 mod.intType(.unsigned, @intCast(u16, ty.abiSize(mod) * 8)) catch unreachable6189 mod.intType(.unsigned, @as(u16, @intCast(ty.abiSize(mod) * 8))) catch unreachable
6190 else6190 else
6191 ty;6191 ty;
61926192
...@@ -6226,7 +6226,7 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa...@@ -6226,7 +6226,7 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa
6226 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });6226 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
62276227
6228 const repr_ty = if (ty.isRuntimeFloat())6228 const repr_ty = if (ty.isRuntimeFloat())
6229 mod.intType(.unsigned, @intCast(u16, ty.abiSize(mod) * 8)) catch unreachable6229 mod.intType(.unsigned, @as(u16, @intCast(ty.abiSize(mod) * 8))) catch unreachable
6230 else6230 else
6231 ty;6231 ty;
62326232
...@@ -6574,7 +6574,7 @@ fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6574,7 +6574,7 @@ fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {
6574 try writer.writeAll("] = ");6574 try writer.writeAll("] = ");
65756575
6576 const mask_elem = (try mask.elemValue(mod, index)).toSignedInt(mod);6576 const mask_elem = (try mask.elemValue(mod, index)).toSignedInt(mod);
6577 const src_val = try mod.intValue(Type.usize, @intCast(u64, mask_elem ^ mask_elem >> 63));6577 const src_val = try mod.intValue(Type.usize, @as(u64, @intCast(mask_elem ^ mask_elem >> 63)));
65786578
6579 try f.writeCValue(writer, if (mask_elem >= 0) lhs else rhs, .Other);6579 try f.writeCValue(writer, if (mask_elem >= 0) lhs else rhs, .Other);
6580 try writer.writeByte('[');6580 try writer.writeByte('[');
...@@ -6745,8 +6745,8 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6745,8 +6745,8 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
6745 const ip = &mod.intern_pool;6745 const ip = &mod.intern_pool;
6746 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;6746 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
6747 const inst_ty = f.typeOfIndex(inst);6747 const inst_ty = f.typeOfIndex(inst);
6748 const len = @intCast(usize, inst_ty.arrayLen(mod));6748 const len = @as(usize, @intCast(inst_ty.arrayLen(mod)));
6749 const elements = @ptrCast([]const Air.Inst.Ref, f.air.extra[ty_pl.payload..][0..len]);6749 const elements = @as([]const Air.Inst.Ref, @ptrCast(f.air.extra[ty_pl.payload..][0..len]));
6750 const gpa = f.object.dg.gpa;6750 const gpa = f.object.dg.gpa;
6751 const resolved_elements = try gpa.alloc(CValue, elements.len);6751 const resolved_elements = try gpa.alloc(CValue, elements.len);
6752 defer gpa.free(resolved_elements);6752 defer gpa.free(resolved_elements);
...@@ -7387,7 +7387,7 @@ fn fmtStringLiteral(str: []const u8, sentinel: ?u8) std.fmt.Formatter(formatStri...@@ -7387,7 +7387,7 @@ fn fmtStringLiteral(str: []const u8, sentinel: ?u8) std.fmt.Formatter(formatStri
7387fn undefPattern(comptime IntType: type) IntType {7387fn undefPattern(comptime IntType: type) IntType {
7388 const int_info = @typeInfo(IntType).Int;7388 const int_info = @typeInfo(IntType).Int;
7389 const UnsignedType = std.meta.Int(.unsigned, int_info.bits);7389 const UnsignedType = std.meta.Int(.unsigned, int_info.bits);
7390 return @bitCast(IntType, @as(UnsignedType, (1 << (int_info.bits | 1)) / 3));7390 return @as(IntType, @bitCast(@as(UnsignedType, (1 << (int_info.bits | 1)) / 3)));
7391}7391}
73927392
7393const FormatIntLiteralContext = struct {7393const FormatIntLiteralContext = struct {
...@@ -7438,7 +7438,7 @@ fn formatIntLiteral(...@@ -7438,7 +7438,7 @@ fn formatIntLiteral(
7438 } else data.val.toBigInt(&int_buf, mod);7438 } else data.val.toBigInt(&int_buf, mod);
7439 assert(int.fitsInTwosComp(data.int_info.signedness, data.int_info.bits));7439 assert(int.fitsInTwosComp(data.int_info.signedness, data.int_info.bits));
74407440
7441 const c_bits = @intCast(usize, data.cty.byteSize(data.dg.ctypes.set, target) * 8);7441 const c_bits = @as(usize, @intCast(data.cty.byteSize(data.dg.ctypes.set, target) * 8));
7442 var one_limbs: [BigInt.calcLimbLen(1)]BigIntLimb = undefined;7442 var one_limbs: [BigInt.calcLimbLen(1)]BigIntLimb = undefined;
7443 const one = BigInt.Mutable.init(&one_limbs, 1).toConst();7443 const one = BigInt.Mutable.init(&one_limbs, 1).toConst();
74447444
...@@ -7471,7 +7471,7 @@ fn formatIntLiteral(...@@ -7471,7 +7471,7 @@ fn formatIntLiteral(
7471 const array_data = data.cty.castTag(.array).?.data;7471 const array_data = data.cty.castTag(.array).?.data;
7472 break :info .{7472 break :info .{
7473 .cty = data.dg.indexToCType(array_data.elem_type),7473 .cty = data.dg.indexToCType(array_data.elem_type),
7474 .count = @intCast(usize, array_data.len),7474 .count = @as(usize, @intCast(array_data.len)),
7475 .endian = target.cpu.arch.endian(),7475 .endian = target.cpu.arch.endian(),
7476 .homogeneous = true,7476 .homogeneous = true,
7477 };7477 };
...@@ -7527,7 +7527,7 @@ fn formatIntLiteral(...@@ -7527,7 +7527,7 @@ fn formatIntLiteral(
75277527
7528 var c_limb_int_info = std.builtin.Type.Int{7528 var c_limb_int_info = std.builtin.Type.Int{
7529 .signedness = undefined,7529 .signedness = undefined,
7530 .bits = @intCast(u16, @divExact(c_bits, c_limb_info.count)),7530 .bits = @as(u16, @intCast(@divExact(c_bits, c_limb_info.count))),
7531 };7531 };
7532 var c_limb_cty: CType = undefined;7532 var c_limb_cty: CType = undefined;
75337533
...@@ -7727,7 +7727,7 @@ fn lowerFnRetTy(ret_ty: Type, mod: *Module) !Type {...@@ -7727,7 +7727,7 @@ fn lowerFnRetTy(ret_ty: Type, mod: *Module) !Type {
7727fn lowersToArray(ty: Type, mod: *Module) bool {7727fn lowersToArray(ty: Type, mod: *Module) bool {
7728 return switch (ty.zigTypeTag(mod)) {7728 return switch (ty.zigTypeTag(mod)) {
7729 .Array, .Vector => return true,7729 .Array, .Vector => return true,
7730 else => return ty.isAbiInt(mod) and toCIntBits(@intCast(u32, ty.bitSize(mod))) == null,7730 else => return ty.isAbiInt(mod) and toCIntBits(@as(u32, @intCast(ty.bitSize(mod)))) == null,
7731 };7731 };
7732}7732}
77337733
...@@ -7735,7 +7735,7 @@ fn reap(f: *Function, inst: Air.Inst.Index, operands: []const Air.Inst.Ref) !voi...@@ -7735,7 +7735,7 @@ fn reap(f: *Function, inst: Air.Inst.Index, operands: []const Air.Inst.Ref) !voi
7735 assert(operands.len <= Liveness.bpi - 1);7735 assert(operands.len <= Liveness.bpi - 1);
7736 var tomb_bits = f.liveness.getTombBits(inst);7736 var tomb_bits = f.liveness.getTombBits(inst);
7737 for (operands) |operand| {7737 for (operands) |operand| {
7738 const dies = @truncate(u1, tomb_bits) != 0;7738 const dies = @as(u1, @truncate(tomb_bits)) != 0;
7739 tomb_bits >>= 1;7739 tomb_bits >>= 1;
7740 if (!dies) continue;7740 if (!dies) continue;
7741 try die(f, inst, operand);7741 try die(f, inst, operand);
src/codegen/c/type.zig+10-10
...@@ -138,7 +138,7 @@ pub const CType = extern union {...@@ -138,7 +138,7 @@ pub const CType = extern union {
138138
139 pub fn toIndex(self: Tag) Index {139 pub fn toIndex(self: Tag) Index {
140 assert(!self.hasPayload());140 assert(!self.hasPayload());
141 return @intCast(Index, @intFromEnum(self));141 return @as(Index, @intCast(@intFromEnum(self)));
142 }142 }
143143
144 pub fn Type(comptime self: Tag) type {144 pub fn Type(comptime self: Tag) type {
...@@ -330,7 +330,7 @@ pub const CType = extern union {...@@ -330,7 +330,7 @@ pub const CType = extern union {
330 store: *const Set,330 store: *const Set,
331331
332 pub fn hash(self: @This(), cty: CType) Map.Hash {332 pub fn hash(self: @This(), cty: CType) Map.Hash {
333 return @truncate(Map.Hash, cty.hash(self.store.*));333 return @as(Map.Hash, @truncate(cty.hash(self.store.*)));
334 }334 }
335 pub fn eql(_: @This(), lhs: CType, rhs: CType, _: usize) bool {335 pub fn eql(_: @This(), lhs: CType, rhs: CType, _: usize) bool {
336 return lhs.eql(rhs);336 return lhs.eql(rhs);
...@@ -340,7 +340,7 @@ pub const CType = extern union {...@@ -340,7 +340,7 @@ pub const CType = extern union {
340 map: Map = .{},340 map: Map = .{},
341341
342 pub fn indexToCType(self: Set, index: Index) CType {342 pub fn indexToCType(self: Set, index: Index) CType {
343 if (index < Tag.no_payload_count) return initTag(@enumFromInt(Tag, index));343 if (index < Tag.no_payload_count) return initTag(@as(Tag, @enumFromInt(index)));
344 return self.map.keys()[index - Tag.no_payload_count];344 return self.map.keys()[index - Tag.no_payload_count];
345 }345 }
346346
...@@ -362,7 +362,7 @@ pub const CType = extern union {...@@ -362,7 +362,7 @@ pub const CType = extern union {
362 return if (self.map.getIndexAdapted(362 return if (self.map.getIndexAdapted(
363 ty,363 ty,
364 TypeAdapter32{ .kind = kind, .lookup = lookup, .convert = &convert },364 TypeAdapter32{ .kind = kind, .lookup = lookup, .convert = &convert },
365 )) |idx| @intCast(Index, Tag.no_payload_count + idx) else null;365 )) |idx| @as(Index, @intCast(Tag.no_payload_count + idx)) else null;
366 }366 }
367 };367 };
368368
...@@ -376,7 +376,7 @@ pub const CType = extern union {...@@ -376,7 +376,7 @@ pub const CType = extern union {
376376
377 pub fn cTypeToIndex(self: *Promoted, cty: CType) Allocator.Error!Index {377 pub fn cTypeToIndex(self: *Promoted, cty: CType) Allocator.Error!Index {
378 const t = cty.tag();378 const t = cty.tag();
379 if (@intFromEnum(t) < Tag.no_payload_count) return @intCast(Index, @intFromEnum(t));379 if (@intFromEnum(t) < Tag.no_payload_count) return @as(Index, @intCast(@intFromEnum(t)));
380380
381 const gop = try self.set.map.getOrPutContext(self.gpa(), cty, .{ .store = &self.set });381 const gop = try self.set.map.getOrPutContext(self.gpa(), cty, .{ .store = &self.set });
382 if (!gop.found_existing) gop.key_ptr.* = cty;382 if (!gop.found_existing) gop.key_ptr.* = cty;
...@@ -386,7 +386,7 @@ pub const CType = extern union {...@@ -386,7 +386,7 @@ pub const CType = extern union {
386 assert(cty.eql(key.*));386 assert(cty.eql(key.*));
387 assert(cty.hash(self.set) == key.hash(self.set));387 assert(cty.hash(self.set) == key.hash(self.set));
388 }388 }
389 return @intCast(Index, Tag.no_payload_count + gop.index);389 return @as(Index, @intCast(Tag.no_payload_count + gop.index));
390 }390 }
391391
392 pub fn typeToIndex(392 pub fn typeToIndex(
...@@ -424,7 +424,7 @@ pub const CType = extern union {...@@ -424,7 +424,7 @@ pub const CType = extern union {
424 assert(adapter.eql(ty, cty.*));424 assert(adapter.eql(ty, cty.*));
425 assert(adapter.hash(ty) == cty.hash(self.set));425 assert(adapter.hash(ty) == cty.hash(self.set));
426 }426 }
427 return @intCast(Index, Tag.no_payload_count + gop.index);427 return @as(Index, @intCast(Tag.no_payload_count + gop.index));
428 }428 }
429 };429 };
430430
...@@ -1388,7 +1388,7 @@ pub const CType = extern union {...@@ -1388,7 +1388,7 @@ pub const CType = extern union {
1388 .len = @divExact(abi_size, abi_align),1388 .len = @divExact(abi_size, abi_align),
1389 .elem_type = tagFromIntInfo(.{1389 .elem_type = tagFromIntInfo(.{
1390 .signedness = .unsigned,1390 .signedness = .unsigned,
1391 .bits = @intCast(u16, abi_align * 8),1391 .bits = @as(u16, @intCast(abi_align * 8)),
1392 }).toIndex(),1392 }).toIndex(),
1393 } } };1393 } } };
1394 self.value = .{ .cty = initPayload(&self.storage.seq) };1394 self.value = .{ .cty = initPayload(&self.storage.seq) };
...@@ -1492,7 +1492,7 @@ pub const CType = extern union {...@@ -1492,7 +1492,7 @@ pub const CType = extern union {
1492 if (mod.typeToStruct(ty)) |struct_obj| {1492 if (mod.typeToStruct(ty)) |struct_obj| {
1493 try self.initType(struct_obj.backing_int_ty, kind, lookup);1493 try self.initType(struct_obj.backing_int_ty, kind, lookup);
1494 } else {1494 } else {
1495 const bits = @intCast(u16, ty.bitSize(mod));1495 const bits = @as(u16, @intCast(ty.bitSize(mod)));
1496 const int_ty = try mod.intType(.unsigned, bits);1496 const int_ty = try mod.intType(.unsigned, bits);
1497 try self.initType(int_ty, kind, lookup);1497 try self.initType(int_ty, kind, lookup);
1498 }1498 }
...@@ -2299,7 +2299,7 @@ pub const CType = extern union {...@@ -2299,7 +2299,7 @@ pub const CType = extern union {
2299 }2299 }
23002300
2301 pub fn hash(self: @This(), ty: Type) u32 {2301 pub fn hash(self: @This(), ty: Type) u32 {
2302 return @truncate(u32, self.to64().hash(ty));2302 return @as(u32, @truncate(self.to64().hash(ty)));
2303 }2303 }
2304 };2304 };
2305};2305};
src/codegen/llvm.zig+132-132
...@@ -592,7 +592,7 @@ pub const Object = struct {...@@ -592,7 +592,7 @@ pub const Object = struct {
592 llvm_errors[0] = llvm_slice_ty.getUndef();592 llvm_errors[0] = llvm_slice_ty.getUndef();
593 for (llvm_errors[1..], error_name_list[1..]) |*llvm_error, name_nts| {593 for (llvm_errors[1..], error_name_list[1..]) |*llvm_error, name_nts| {
594 const name = mod.intern_pool.stringToSlice(name_nts);594 const name = mod.intern_pool.stringToSlice(name_nts);
595 const str_init = o.context.constString(name.ptr, @intCast(c_uint, name.len), .False);595 const str_init = o.context.constString(name.ptr, @as(c_uint, @intCast(name.len)), .False);
596 const str_global = o.llvm_module.addGlobal(str_init.typeOf(), "");596 const str_global = o.llvm_module.addGlobal(str_init.typeOf(), "");
597 str_global.setInitializer(str_init);597 str_global.setInitializer(str_init);
598 str_global.setLinkage(.Private);598 str_global.setLinkage(.Private);
...@@ -607,7 +607,7 @@ pub const Object = struct {...@@ -607,7 +607,7 @@ pub const Object = struct {
607 llvm_error.* = llvm_slice_ty.constNamedStruct(&slice_fields, slice_fields.len);607 llvm_error.* = llvm_slice_ty.constNamedStruct(&slice_fields, slice_fields.len);
608 }608 }
609609
610 const error_name_table_init = llvm_slice_ty.constArray(llvm_errors.ptr, @intCast(c_uint, error_name_list.len));610 const error_name_table_init = llvm_slice_ty.constArray(llvm_errors.ptr, @as(c_uint, @intCast(error_name_list.len)));
611611
612 const error_name_table_global = o.llvm_module.addGlobal(error_name_table_init.typeOf(), "");612 const error_name_table_global = o.llvm_module.addGlobal(error_name_table_init.typeOf(), "");
613 error_name_table_global.setInitializer(error_name_table_init);613 error_name_table_global.setInitializer(error_name_table_init);
...@@ -1027,7 +1027,7 @@ pub const Object = struct {...@@ -1027,7 +1027,7 @@ pub const Object = struct {
1027 llvm_arg_i += 1;1027 llvm_arg_i += 1;
10281028
1029 const param_llvm_ty = try o.lowerType(param_ty);1029 const param_llvm_ty = try o.lowerType(param_ty);
1030 const abi_size = @intCast(c_uint, param_ty.abiSize(mod));1030 const abi_size = @as(c_uint, @intCast(param_ty.abiSize(mod)));
1031 const int_llvm_ty = o.context.intType(abi_size * 8);1031 const int_llvm_ty = o.context.intType(abi_size * 8);
1032 const alignment = @max(1032 const alignment = @max(
1033 param_ty.abiAlignment(mod),1033 param_ty.abiAlignment(mod),
...@@ -1053,7 +1053,7 @@ pub const Object = struct {...@@ -1053,7 +1053,7 @@ pub const Object = struct {
1053 const ptr_info = param_ty.ptrInfo(mod);1053 const ptr_info = param_ty.ptrInfo(mod);
10541054
1055 if (math.cast(u5, it.zig_index - 1)) |i| {1055 if (math.cast(u5, it.zig_index - 1)) |i| {
1056 if (@truncate(u1, fn_info.noalias_bits >> i) != 0) {1056 if (@as(u1, @truncate(fn_info.noalias_bits >> i)) != 0) {
1057 o.addArgAttr(llvm_func, llvm_arg_i, "noalias");1057 o.addArgAttr(llvm_func, llvm_arg_i, "noalias");
1058 }1058 }
1059 }1059 }
...@@ -1083,9 +1083,9 @@ pub const Object = struct {...@@ -1083,9 +1083,9 @@ pub const Object = struct {
1083 const param_llvm_ty = try o.lowerType(param_ty);1083 const param_llvm_ty = try o.lowerType(param_ty);
1084 const param_alignment = param_ty.abiAlignment(mod);1084 const param_alignment = param_ty.abiAlignment(mod);
1085 const arg_ptr = buildAllocaInner(o.context, builder, llvm_func, false, param_llvm_ty, param_alignment, target);1085 const arg_ptr = buildAllocaInner(o.context, builder, llvm_func, false, param_llvm_ty, param_alignment, target);
1086 const llvm_ty = o.context.structType(field_types.ptr, @intCast(c_uint, field_types.len), .False);1086 const llvm_ty = o.context.structType(field_types.ptr, @as(c_uint, @intCast(field_types.len)), .False);
1087 for (field_types, 0..) |_, field_i_usize| {1087 for (field_types, 0..) |_, field_i_usize| {
1088 const field_i = @intCast(c_uint, field_i_usize);1088 const field_i = @as(c_uint, @intCast(field_i_usize));
1089 const param = llvm_func.getParam(llvm_arg_i);1089 const param = llvm_func.getParam(llvm_arg_i);
1090 llvm_arg_i += 1;1090 llvm_arg_i += 1;
1091 const field_ptr = builder.buildStructGEP(llvm_ty, arg_ptr, field_i, "");1091 const field_ptr = builder.buildStructGEP(llvm_ty, arg_ptr, field_i, "");
...@@ -1289,11 +1289,11 @@ pub const Object = struct {...@@ -1289,11 +1289,11 @@ pub const Object = struct {
1289 if (mod.wantDllExports()) llvm_global.setDLLStorageClass(.Default);1289 if (mod.wantDllExports()) llvm_global.setDLLStorageClass(.Default);
1290 if (self.di_map.get(decl)) |di_node| {1290 if (self.di_map.get(decl)) |di_node| {
1291 if (try decl.isFunction(mod)) {1291 if (try decl.isFunction(mod)) {
1292 const di_func = @ptrCast(*llvm.DISubprogram, di_node);1292 const di_func = @as(*llvm.DISubprogram, @ptrCast(di_node));
1293 const linkage_name = llvm.MDString.get(self.context, decl_name.ptr, decl_name.len);1293 const linkage_name = llvm.MDString.get(self.context, decl_name.ptr, decl_name.len);
1294 di_func.replaceLinkageName(linkage_name);1294 di_func.replaceLinkageName(linkage_name);
1295 } else {1295 } else {
1296 const di_global = @ptrCast(*llvm.DIGlobalVariable, di_node);1296 const di_global = @as(*llvm.DIGlobalVariable, @ptrCast(di_node));
1297 const linkage_name = llvm.MDString.get(self.context, decl_name.ptr, decl_name.len);1297 const linkage_name = llvm.MDString.get(self.context, decl_name.ptr, decl_name.len);
1298 di_global.replaceLinkageName(linkage_name);1298 di_global.replaceLinkageName(linkage_name);
1299 }1299 }
...@@ -1315,11 +1315,11 @@ pub const Object = struct {...@@ -1315,11 +1315,11 @@ pub const Object = struct {
1315 if (mod.wantDllExports()) llvm_global.setDLLStorageClass(.DLLExport);1315 if (mod.wantDllExports()) llvm_global.setDLLStorageClass(.DLLExport);
1316 if (self.di_map.get(decl)) |di_node| {1316 if (self.di_map.get(decl)) |di_node| {
1317 if (try decl.isFunction(mod)) {1317 if (try decl.isFunction(mod)) {
1318 const di_func = @ptrCast(*llvm.DISubprogram, di_node);1318 const di_func = @as(*llvm.DISubprogram, @ptrCast(di_node));
1319 const linkage_name = llvm.MDString.get(self.context, exp_name.ptr, exp_name.len);1319 const linkage_name = llvm.MDString.get(self.context, exp_name.ptr, exp_name.len);
1320 di_func.replaceLinkageName(linkage_name);1320 di_func.replaceLinkageName(linkage_name);
1321 } else {1321 } else {
1322 const di_global = @ptrCast(*llvm.DIGlobalVariable, di_node);1322 const di_global = @as(*llvm.DIGlobalVariable, @ptrCast(di_node));
1323 const linkage_name = llvm.MDString.get(self.context, exp_name.ptr, exp_name.len);1323 const linkage_name = llvm.MDString.get(self.context, exp_name.ptr, exp_name.len);
1324 di_global.replaceLinkageName(linkage_name);1324 di_global.replaceLinkageName(linkage_name);
1325 }1325 }
...@@ -1390,7 +1390,7 @@ pub const Object = struct {...@@ -1390,7 +1390,7 @@ pub const Object = struct {
1390 const gop = try o.di_map.getOrPut(gpa, file);1390 const gop = try o.di_map.getOrPut(gpa, file);
1391 errdefer assert(o.di_map.remove(file));1391 errdefer assert(o.di_map.remove(file));
1392 if (gop.found_existing) {1392 if (gop.found_existing) {
1393 return @ptrCast(*llvm.DIFile, gop.value_ptr.*);1393 return @as(*llvm.DIFile, @ptrCast(gop.value_ptr.*));
1394 }1394 }
1395 const dir_path_z = d: {1395 const dir_path_z = d: {
1396 var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;1396 var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
...@@ -1514,7 +1514,7 @@ pub const Object = struct {...@@ -1514,7 +1514,7 @@ pub const Object = struct {
1514 if (@sizeOf(usize) == @sizeOf(u64)) {1514 if (@sizeOf(usize) == @sizeOf(u64)) {
1515 enumerators[i] = dib.createEnumerator2(1515 enumerators[i] = dib.createEnumerator2(
1516 field_name_z,1516 field_name_z,
1517 @intCast(c_uint, bigint.limbs.len),1517 @as(c_uint, @intCast(bigint.limbs.len)),
1518 bigint.limbs.ptr,1518 bigint.limbs.ptr,
1519 int_info.bits,1519 int_info.bits,
1520 int_info.signedness == .unsigned,1520 int_info.signedness == .unsigned,
...@@ -1538,7 +1538,7 @@ pub const Object = struct {...@@ -1538,7 +1538,7 @@ pub const Object = struct {
1538 ty.abiSize(mod) * 8,1538 ty.abiSize(mod) * 8,
1539 ty.abiAlignment(mod) * 8,1539 ty.abiAlignment(mod) * 8,
1540 enumerators.ptr,1540 enumerators.ptr,
1541 @intCast(c_int, enumerators.len),1541 @as(c_int, @intCast(enumerators.len)),
1542 try o.lowerDebugType(int_ty, .full),1542 try o.lowerDebugType(int_ty, .full),
1543 "",1543 "",
1544 );1544 );
...@@ -1713,7 +1713,7 @@ pub const Object = struct {...@@ -1713,7 +1713,7 @@ pub const Object = struct {
1713 ty.abiSize(mod) * 8,1713 ty.abiSize(mod) * 8,
1714 ty.abiAlignment(mod) * 8,1714 ty.abiAlignment(mod) * 8,
1715 try o.lowerDebugType(ty.childType(mod), .full),1715 try o.lowerDebugType(ty.childType(mod), .full),
1716 @intCast(i64, ty.arrayLen(mod)),1716 @as(i64, @intCast(ty.arrayLen(mod))),
1717 );1717 );
1718 // The recursive call to `lowerDebugType` means we can't use `gop` anymore.1718 // The recursive call to `lowerDebugType` means we can't use `gop` anymore.
1719 try o.di_type_map.put(gpa, ty.toIntern(), AnnotatedDITypePtr.initFull(array_di_ty));1719 try o.di_type_map.put(gpa, ty.toIntern(), AnnotatedDITypePtr.initFull(array_di_ty));
...@@ -2018,7 +2018,7 @@ pub const Object = struct {...@@ -2018,7 +2018,7 @@ pub const Object = struct {
2018 0, // flags2018 0, // flags
2019 null, // derived from2019 null, // derived from
2020 di_fields.items.ptr,2020 di_fields.items.ptr,
2021 @intCast(c_int, di_fields.items.len),2021 @as(c_int, @intCast(di_fields.items.len)),
2022 0, // run time lang2022 0, // run time lang
2023 null, // vtable holder2023 null, // vtable holder
2024 "", // unique id2024 "", // unique id
...@@ -2105,7 +2105,7 @@ pub const Object = struct {...@@ -2105,7 +2105,7 @@ pub const Object = struct {
2105 0, // flags2105 0, // flags
2106 null, // derived from2106 null, // derived from
2107 di_fields.items.ptr,2107 di_fields.items.ptr,
2108 @intCast(c_int, di_fields.items.len),2108 @as(c_int, @intCast(di_fields.items.len)),
2109 0, // run time lang2109 0, // run time lang
2110 null, // vtable holder2110 null, // vtable holder
2111 "", // unique id2111 "", // unique id
...@@ -2217,7 +2217,7 @@ pub const Object = struct {...@@ -2217,7 +2217,7 @@ pub const Object = struct {
2217 ty.abiAlignment(mod) * 8, // align in bits2217 ty.abiAlignment(mod) * 8, // align in bits
2218 0, // flags2218 0, // flags
2219 di_fields.items.ptr,2219 di_fields.items.ptr,
2220 @intCast(c_int, di_fields.items.len),2220 @as(c_int, @intCast(di_fields.items.len)),
2221 0, // run time lang2221 0, // run time lang
2222 "", // unique id2222 "", // unique id
2223 );2223 );
...@@ -2330,7 +2330,7 @@ pub const Object = struct {...@@ -2330,7 +2330,7 @@ pub const Object = struct {
23302330
2331 const fn_di_ty = dib.createSubroutineType(2331 const fn_di_ty = dib.createSubroutineType(
2332 param_di_types.items.ptr,2332 param_di_types.items.ptr,
2333 @intCast(c_int, param_di_types.items.len),2333 @as(c_int, @intCast(param_di_types.items.len)),
2334 0,2334 0,
2335 );2335 );
2336 // The recursive call to `lowerDebugType` means we can't use `gop` anymore.2336 // The recursive call to `lowerDebugType` means we can't use `gop` anymore.
...@@ -2487,7 +2487,7 @@ pub const Object = struct {...@@ -2487,7 +2487,7 @@ pub const Object = struct {
2487 }2487 }
24882488
2489 if (fn_info.alignment.toByteUnitsOptional()) |a| {2489 if (fn_info.alignment.toByteUnitsOptional()) |a| {
2490 llvm_fn.setAlignment(@intCast(c_uint, a));2490 llvm_fn.setAlignment(@as(c_uint, @intCast(a)));
2491 }2491 }
24922492
2493 // Function attributes that are independent of analysis results of the function body.2493 // Function attributes that are independent of analysis results of the function body.
...@@ -2710,7 +2710,7 @@ pub const Object = struct {...@@ -2710,7 +2710,7 @@ pub const Object = struct {
2710 if (std.debug.runtime_safety) assert((try elem_ty.onePossibleValue(mod)) == null);2710 if (std.debug.runtime_safety) assert((try elem_ty.onePossibleValue(mod)) == null);
2711 const elem_llvm_ty = try o.lowerType(elem_ty);2711 const elem_llvm_ty = try o.lowerType(elem_ty);
2712 const total_len = t.arrayLen(mod) + @intFromBool(t.sentinel(mod) != null);2712 const total_len = t.arrayLen(mod) + @intFromBool(t.sentinel(mod) != null);
2713 return elem_llvm_ty.arrayType(@intCast(c_uint, total_len));2713 return elem_llvm_ty.arrayType(@as(c_uint, @intCast(total_len)));
2714 },2714 },
2715 .Vector => {2715 .Vector => {
2716 const elem_type = try o.lowerType(t.childType(mod));2716 const elem_type = try o.lowerType(t.childType(mod));
...@@ -2732,7 +2732,7 @@ pub const Object = struct {...@@ -2732,7 +2732,7 @@ pub const Object = struct {
2732 };2732 };
2733 const offset = child_ty.abiSize(mod) + 1;2733 const offset = child_ty.abiSize(mod) + 1;
2734 const abi_size = t.abiSize(mod);2734 const abi_size = t.abiSize(mod);
2735 const padding = @intCast(c_uint, abi_size - offset);2735 const padding = @as(c_uint, @intCast(abi_size - offset));
2736 if (padding == 0) {2736 if (padding == 0) {
2737 return o.context.structType(&fields_buf, 2, .False);2737 return o.context.structType(&fields_buf, 2, .False);
2738 }2738 }
...@@ -2761,7 +2761,7 @@ pub const Object = struct {...@@ -2761,7 +2761,7 @@ pub const Object = struct {
2761 std.mem.alignForward(u64, error_size, payload_align) +2761 std.mem.alignForward(u64, error_size, payload_align) +
2762 payload_size;2762 payload_size;
2763 const abi_size = std.mem.alignForward(u64, payload_end, error_align);2763 const abi_size = std.mem.alignForward(u64, payload_end, error_align);
2764 const padding = @intCast(c_uint, abi_size - payload_end);2764 const padding = @as(c_uint, @intCast(abi_size - payload_end));
2765 if (padding == 0) {2765 if (padding == 0) {
2766 return o.context.structType(&fields_buf, 2, .False);2766 return o.context.structType(&fields_buf, 2, .False);
2767 }2767 }
...@@ -2774,7 +2774,7 @@ pub const Object = struct {...@@ -2774,7 +2774,7 @@ pub const Object = struct {
2774 std.mem.alignForward(u64, payload_size, error_align) +2774 std.mem.alignForward(u64, payload_size, error_align) +
2775 error_size;2775 error_size;
2776 const abi_size = std.mem.alignForward(u64, error_end, payload_align);2776 const abi_size = std.mem.alignForward(u64, error_end, payload_align);
2777 const padding = @intCast(c_uint, abi_size - error_end);2777 const padding = @as(c_uint, @intCast(abi_size - error_end));
2778 if (padding == 0) {2778 if (padding == 0) {
2779 return o.context.structType(&fields_buf, 2, .False);2779 return o.context.structType(&fields_buf, 2, .False);
2780 }2780 }
...@@ -2811,7 +2811,7 @@ pub const Object = struct {...@@ -2811,7 +2811,7 @@ pub const Object = struct {
28112811
2812 const padding_len = offset - prev_offset;2812 const padding_len = offset - prev_offset;
2813 if (padding_len > 0) {2813 if (padding_len > 0) {
2814 const llvm_array_ty = o.context.intType(8).arrayType(@intCast(c_uint, padding_len));2814 const llvm_array_ty = o.context.intType(8).arrayType(@as(c_uint, @intCast(padding_len)));
2815 try llvm_field_types.append(gpa, llvm_array_ty);2815 try llvm_field_types.append(gpa, llvm_array_ty);
2816 }2816 }
2817 const field_llvm_ty = try o.lowerType(field_ty.toType());2817 const field_llvm_ty = try o.lowerType(field_ty.toType());
...@@ -2824,14 +2824,14 @@ pub const Object = struct {...@@ -2824,14 +2824,14 @@ pub const Object = struct {
2824 offset = std.mem.alignForward(u64, offset, big_align);2824 offset = std.mem.alignForward(u64, offset, big_align);
2825 const padding_len = offset - prev_offset;2825 const padding_len = offset - prev_offset;
2826 if (padding_len > 0) {2826 if (padding_len > 0) {
2827 const llvm_array_ty = o.context.intType(8).arrayType(@intCast(c_uint, padding_len));2827 const llvm_array_ty = o.context.intType(8).arrayType(@as(c_uint, @intCast(padding_len)));
2828 try llvm_field_types.append(gpa, llvm_array_ty);2828 try llvm_field_types.append(gpa, llvm_array_ty);
2829 }2829 }
2830 }2830 }
28312831
2832 llvm_struct_ty.structSetBody(2832 llvm_struct_ty.structSetBody(
2833 llvm_field_types.items.ptr,2833 llvm_field_types.items.ptr,
2834 @intCast(c_uint, llvm_field_types.items.len),2834 @as(c_uint, @intCast(llvm_field_types.items.len)),
2835 .False,2835 .False,
2836 );2836 );
28372837
...@@ -2880,7 +2880,7 @@ pub const Object = struct {...@@ -2880,7 +2880,7 @@ pub const Object = struct {
28802880
2881 const padding_len = offset - prev_offset;2881 const padding_len = offset - prev_offset;
2882 if (padding_len > 0) {2882 if (padding_len > 0) {
2883 const llvm_array_ty = o.context.intType(8).arrayType(@intCast(c_uint, padding_len));2883 const llvm_array_ty = o.context.intType(8).arrayType(@as(c_uint, @intCast(padding_len)));
2884 try llvm_field_types.append(gpa, llvm_array_ty);2884 try llvm_field_types.append(gpa, llvm_array_ty);
2885 }2885 }
2886 const field_llvm_ty = try o.lowerType(field.ty);2886 const field_llvm_ty = try o.lowerType(field.ty);
...@@ -2893,14 +2893,14 @@ pub const Object = struct {...@@ -2893,14 +2893,14 @@ pub const Object = struct {
2893 offset = std.mem.alignForward(u64, offset, big_align);2893 offset = std.mem.alignForward(u64, offset, big_align);
2894 const padding_len = offset - prev_offset;2894 const padding_len = offset - prev_offset;
2895 if (padding_len > 0) {2895 if (padding_len > 0) {
2896 const llvm_array_ty = o.context.intType(8).arrayType(@intCast(c_uint, padding_len));2896 const llvm_array_ty = o.context.intType(8).arrayType(@as(c_uint, @intCast(padding_len)));
2897 try llvm_field_types.append(gpa, llvm_array_ty);2897 try llvm_field_types.append(gpa, llvm_array_ty);
2898 }2898 }
2899 }2899 }
29002900
2901 llvm_struct_ty.structSetBody(2901 llvm_struct_ty.structSetBody(
2902 llvm_field_types.items.ptr,2902 llvm_field_types.items.ptr,
2903 @intCast(c_uint, llvm_field_types.items.len),2903 @as(c_uint, @intCast(llvm_field_types.items.len)),
2904 llvm.Bool.fromBool(any_underaligned_fields),2904 llvm.Bool.fromBool(any_underaligned_fields),
2905 );2905 );
29062906
...@@ -2914,7 +2914,7 @@ pub const Object = struct {...@@ -2914,7 +2914,7 @@ pub const Object = struct {
2914 const union_obj = mod.typeToUnion(t).?;2914 const union_obj = mod.typeToUnion(t).?;
29152915
2916 if (union_obj.layout == .Packed) {2916 if (union_obj.layout == .Packed) {
2917 const bitsize = @intCast(c_uint, t.bitSize(mod));2917 const bitsize = @as(c_uint, @intCast(t.bitSize(mod)));
2918 const int_llvm_ty = o.context.intType(bitsize);2918 const int_llvm_ty = o.context.intType(bitsize);
2919 gop.value_ptr.* = int_llvm_ty;2919 gop.value_ptr.* = int_llvm_ty;
2920 return int_llvm_ty;2920 return int_llvm_ty;
...@@ -2939,9 +2939,9 @@ pub const Object = struct {...@@ -2939,9 +2939,9 @@ pub const Object = struct {
2939 break :t llvm_aligned_field_ty;2939 break :t llvm_aligned_field_ty;
2940 }2940 }
2941 const padding_len = if (layout.tag_size == 0)2941 const padding_len = if (layout.tag_size == 0)
2942 @intCast(c_uint, layout.abi_size - layout.most_aligned_field_size)2942 @as(c_uint, @intCast(layout.abi_size - layout.most_aligned_field_size))
2943 else2943 else
2944 @intCast(c_uint, layout.payload_size - layout.most_aligned_field_size);2944 @as(c_uint, @intCast(layout.payload_size - layout.most_aligned_field_size));
2945 const fields: [2]*llvm.Type = .{2945 const fields: [2]*llvm.Type = .{
2946 llvm_aligned_field_ty,2946 llvm_aligned_field_ty,
2947 o.context.intType(8).arrayType(padding_len),2947 o.context.intType(8).arrayType(padding_len),
...@@ -3020,7 +3020,7 @@ pub const Object = struct {...@@ -3020,7 +3020,7 @@ pub const Object = struct {
3020 },3020 },
3021 .abi_sized_int => {3021 .abi_sized_int => {
3022 const param_ty = fn_info.param_types[it.zig_index - 1].toType();3022 const param_ty = fn_info.param_types[it.zig_index - 1].toType();
3023 const abi_size = @intCast(c_uint, param_ty.abiSize(mod));3023 const abi_size = @as(c_uint, @intCast(param_ty.abiSize(mod)));
3024 try llvm_params.append(o.context.intType(abi_size * 8));3024 try llvm_params.append(o.context.intType(abi_size * 8));
3025 },3025 },
3026 .slice => {3026 .slice => {
...@@ -3045,7 +3045,7 @@ pub const Object = struct {...@@ -3045,7 +3045,7 @@ pub const Object = struct {
3045 .float_array => |count| {3045 .float_array => |count| {
3046 const param_ty = fn_info.param_types[it.zig_index - 1].toType();3046 const param_ty = fn_info.param_types[it.zig_index - 1].toType();
3047 const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(param_ty, mod).?);3047 const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(param_ty, mod).?);
3048 const field_count = @intCast(c_uint, count);3048 const field_count = @as(c_uint, @intCast(count));
3049 const arr_ty = float_ty.arrayType(field_count);3049 const arr_ty = float_ty.arrayType(field_count);
3050 try llvm_params.append(arr_ty);3050 try llvm_params.append(arr_ty);
3051 },3051 },
...@@ -3059,7 +3059,7 @@ pub const Object = struct {...@@ -3059,7 +3059,7 @@ pub const Object = struct {
3059 return llvm.functionType(3059 return llvm.functionType(
3060 llvm_ret_ty,3060 llvm_ret_ty,
3061 llvm_params.items.ptr,3061 llvm_params.items.ptr,
3062 @intCast(c_uint, llvm_params.items.len),3062 @as(c_uint, @intCast(llvm_params.items.len)),
3063 llvm.Bool.fromBool(fn_info.is_var_args),3063 llvm.Bool.fromBool(fn_info.is_var_args),
3064 );3064 );
3065 }3065 }
...@@ -3219,7 +3219,7 @@ pub const Object = struct {...@@ -3219,7 +3219,7 @@ pub const Object = struct {
3219 }3219 }
3220 if (@sizeOf(usize) == @sizeOf(u64)) {3220 if (@sizeOf(usize) == @sizeOf(u64)) {
3221 break :v llvm_type.constIntOfArbitraryPrecision(3221 break :v llvm_type.constIntOfArbitraryPrecision(
3222 @intCast(c_uint, bigint.limbs.len),3222 @as(c_uint, @intCast(bigint.limbs.len)),
3223 bigint.limbs.ptr,3223 bigint.limbs.ptr,
3224 );3224 );
3225 }3225 }
...@@ -3234,19 +3234,19 @@ pub const Object = struct {...@@ -3234,19 +3234,19 @@ pub const Object = struct {
3234 const llvm_ty = try o.lowerType(tv.ty);3234 const llvm_ty = try o.lowerType(tv.ty);
3235 switch (tv.ty.floatBits(target)) {3235 switch (tv.ty.floatBits(target)) {
3236 16 => {3236 16 => {
3237 const repr = @bitCast(u16, tv.val.toFloat(f16, mod));3237 const repr = @as(u16, @bitCast(tv.val.toFloat(f16, mod)));
3238 const llvm_i16 = o.context.intType(16);3238 const llvm_i16 = o.context.intType(16);
3239 const int = llvm_i16.constInt(repr, .False);3239 const int = llvm_i16.constInt(repr, .False);
3240 return int.constBitCast(llvm_ty);3240 return int.constBitCast(llvm_ty);
3241 },3241 },
3242 32 => {3242 32 => {
3243 const repr = @bitCast(u32, tv.val.toFloat(f32, mod));3243 const repr = @as(u32, @bitCast(tv.val.toFloat(f32, mod)));
3244 const llvm_i32 = o.context.intType(32);3244 const llvm_i32 = o.context.intType(32);
3245 const int = llvm_i32.constInt(repr, .False);3245 const int = llvm_i32.constInt(repr, .False);
3246 return int.constBitCast(llvm_ty);3246 return int.constBitCast(llvm_ty);
3247 },3247 },
3248 64 => {3248 64 => {
3249 const repr = @bitCast(u64, tv.val.toFloat(f64, mod));3249 const repr = @as(u64, @bitCast(tv.val.toFloat(f64, mod)));
3250 const llvm_i64 = o.context.intType(64);3250 const llvm_i64 = o.context.intType(64);
3251 const int = llvm_i64.constInt(repr, .False);3251 const int = llvm_i64.constInt(repr, .False);
3252 return int.constBitCast(llvm_ty);3252 return int.constBitCast(llvm_ty);
...@@ -3265,7 +3265,7 @@ pub const Object = struct {...@@ -3265,7 +3265,7 @@ pub const Object = struct {
3265 }3265 }
3266 },3266 },
3267 128 => {3267 128 => {
3268 var buf: [2]u64 = @bitCast([2]u64, tv.val.toFloat(f128, mod));3268 var buf: [2]u64 = @as([2]u64, @bitCast(tv.val.toFloat(f128, mod)));
3269 // LLVM seems to require that the lower half of the f128 be placed first3269 // LLVM seems to require that the lower half of the f128 be placed first
3270 // in the buffer.3270 // in the buffer.
3271 if (native_endian == .Big) {3271 if (native_endian == .Big) {
...@@ -3343,7 +3343,7 @@ pub const Object = struct {...@@ -3343,7 +3343,7 @@ pub const Object = struct {
3343 .array_type => switch (aggregate.storage) {3343 .array_type => switch (aggregate.storage) {
3344 .bytes => |bytes| return o.context.constString(3344 .bytes => |bytes| return o.context.constString(
3345 bytes.ptr,3345 bytes.ptr,
3346 @intCast(c_uint, tv.ty.arrayLenIncludingSentinel(mod)),3346 @as(c_uint, @intCast(tv.ty.arrayLenIncludingSentinel(mod))),
3347 .True, // Don't null terminate. Bytes has the sentinel, if any.3347 .True, // Don't null terminate. Bytes has the sentinel, if any.
3348 ),3348 ),
3349 .elems => |elem_vals| {3349 .elems => |elem_vals| {
...@@ -3358,21 +3358,21 @@ pub const Object = struct {...@@ -3358,21 +3358,21 @@ pub const Object = struct {
3358 if (need_unnamed) {3358 if (need_unnamed) {
3359 return o.context.constStruct(3359 return o.context.constStruct(
3360 llvm_elems.ptr,3360 llvm_elems.ptr,
3361 @intCast(c_uint, llvm_elems.len),3361 @as(c_uint, @intCast(llvm_elems.len)),
3362 .True,3362 .True,
3363 );3363 );
3364 } else {3364 } else {
3365 const llvm_elem_ty = try o.lowerType(elem_ty);3365 const llvm_elem_ty = try o.lowerType(elem_ty);
3366 return llvm_elem_ty.constArray(3366 return llvm_elem_ty.constArray(
3367 llvm_elems.ptr,3367 llvm_elems.ptr,
3368 @intCast(c_uint, llvm_elems.len),3368 @as(c_uint, @intCast(llvm_elems.len)),
3369 );3369 );
3370 }3370 }
3371 },3371 },
3372 .repeated_elem => |val| {3372 .repeated_elem => |val| {
3373 const elem_ty = tv.ty.childType(mod);3373 const elem_ty = tv.ty.childType(mod);
3374 const sentinel = tv.ty.sentinel(mod);3374 const sentinel = tv.ty.sentinel(mod);
3375 const len = @intCast(usize, tv.ty.arrayLen(mod));3375 const len = @as(usize, @intCast(tv.ty.arrayLen(mod)));
3376 const len_including_sent = len + @intFromBool(sentinel != null);3376 const len_including_sent = len + @intFromBool(sentinel != null);
3377 const llvm_elems = try gpa.alloc(*llvm.Value, len_including_sent);3377 const llvm_elems = try gpa.alloc(*llvm.Value, len_including_sent);
3378 defer gpa.free(llvm_elems);3378 defer gpa.free(llvm_elems);
...@@ -3393,14 +3393,14 @@ pub const Object = struct {...@@ -3393,14 +3393,14 @@ pub const Object = struct {
3393 if (need_unnamed) {3393 if (need_unnamed) {
3394 return o.context.constStruct(3394 return o.context.constStruct(
3395 llvm_elems.ptr,3395 llvm_elems.ptr,
3396 @intCast(c_uint, llvm_elems.len),3396 @as(c_uint, @intCast(llvm_elems.len)),
3397 .True,3397 .True,
3398 );3398 );
3399 } else {3399 } else {
3400 const llvm_elem_ty = try o.lowerType(elem_ty);3400 const llvm_elem_ty = try o.lowerType(elem_ty);
3401 return llvm_elem_ty.constArray(3401 return llvm_elem_ty.constArray(
3402 llvm_elems.ptr,3402 llvm_elems.ptr,
3403 @intCast(c_uint, llvm_elems.len),3403 @as(c_uint, @intCast(llvm_elems.len)),
3404 );3404 );
3405 }3405 }
3406 },3406 },
...@@ -3425,7 +3425,7 @@ pub const Object = struct {...@@ -3425,7 +3425,7 @@ pub const Object = struct {
3425 }3425 }
3426 return llvm.constVector(3426 return llvm.constVector(
3427 llvm_elems.ptr,3427 llvm_elems.ptr,
3428 @intCast(c_uint, llvm_elems.len),3428 @as(c_uint, @intCast(llvm_elems.len)),
3429 );3429 );
3430 },3430 },
3431 .anon_struct_type => |tuple| {3431 .anon_struct_type => |tuple| {
...@@ -3450,7 +3450,7 @@ pub const Object = struct {...@@ -3450,7 +3450,7 @@ pub const Object = struct {
34503450
3451 const padding_len = offset - prev_offset;3451 const padding_len = offset - prev_offset;
3452 if (padding_len > 0) {3452 if (padding_len > 0) {
3453 const llvm_array_ty = o.context.intType(8).arrayType(@intCast(c_uint, padding_len));3453 const llvm_array_ty = o.context.intType(8).arrayType(@as(c_uint, @intCast(padding_len)));
3454 // TODO make this and all other padding elsewhere in debug3454 // TODO make this and all other padding elsewhere in debug
3455 // builds be 0xaa not undef.3455 // builds be 0xaa not undef.
3456 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());3456 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());
...@@ -3472,7 +3472,7 @@ pub const Object = struct {...@@ -3472,7 +3472,7 @@ pub const Object = struct {
3472 offset = std.mem.alignForward(u64, offset, big_align);3472 offset = std.mem.alignForward(u64, offset, big_align);
3473 const padding_len = offset - prev_offset;3473 const padding_len = offset - prev_offset;
3474 if (padding_len > 0) {3474 if (padding_len > 0) {
3475 const llvm_array_ty = o.context.intType(8).arrayType(@intCast(c_uint, padding_len));3475 const llvm_array_ty = o.context.intType(8).arrayType(@as(c_uint, @intCast(padding_len)));
3476 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());3476 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());
3477 }3477 }
3478 }3478 }
...@@ -3480,14 +3480,14 @@ pub const Object = struct {...@@ -3480,14 +3480,14 @@ pub const Object = struct {
3480 if (need_unnamed) {3480 if (need_unnamed) {
3481 return o.context.constStruct(3481 return o.context.constStruct(
3482 llvm_fields.items.ptr,3482 llvm_fields.items.ptr,
3483 @intCast(c_uint, llvm_fields.items.len),3483 @as(c_uint, @intCast(llvm_fields.items.len)),
3484 .False,3484 .False,
3485 );3485 );
3486 } else {3486 } else {
3487 const llvm_struct_ty = try o.lowerType(tv.ty);3487 const llvm_struct_ty = try o.lowerType(tv.ty);
3488 return llvm_struct_ty.constNamedStruct(3488 return llvm_struct_ty.constNamedStruct(
3489 llvm_fields.items.ptr,3489 llvm_fields.items.ptr,
3490 @intCast(c_uint, llvm_fields.items.len),3490 @as(c_uint, @intCast(llvm_fields.items.len)),
3491 );3491 );
3492 }3492 }
3493 },3493 },
...@@ -3498,7 +3498,7 @@ pub const Object = struct {...@@ -3498,7 +3498,7 @@ pub const Object = struct {
3498 if (struct_obj.layout == .Packed) {3498 if (struct_obj.layout == .Packed) {
3499 assert(struct_obj.haveLayout());3499 assert(struct_obj.haveLayout());
3500 const big_bits = struct_obj.backing_int_ty.bitSize(mod);3500 const big_bits = struct_obj.backing_int_ty.bitSize(mod);
3501 const int_llvm_ty = o.context.intType(@intCast(c_uint, big_bits));3501 const int_llvm_ty = o.context.intType(@as(c_uint, @intCast(big_bits)));
3502 const fields = struct_obj.fields.values();3502 const fields = struct_obj.fields.values();
3503 comptime assert(Type.packed_struct_layout_version == 2);3503 comptime assert(Type.packed_struct_layout_version == 2);
3504 var running_int: *llvm.Value = int_llvm_ty.constNull();3504 var running_int: *llvm.Value = int_llvm_ty.constNull();
...@@ -3510,7 +3510,7 @@ pub const Object = struct {...@@ -3510,7 +3510,7 @@ pub const Object = struct {
3510 .ty = field.ty,3510 .ty = field.ty,
3511 .val = try tv.val.fieldValue(mod, i),3511 .val = try tv.val.fieldValue(mod, i),
3512 });3512 });
3513 const ty_bit_size = @intCast(u16, field.ty.bitSize(mod));3513 const ty_bit_size = @as(u16, @intCast(field.ty.bitSize(mod)));
3514 const small_int_ty = o.context.intType(ty_bit_size);3514 const small_int_ty = o.context.intType(ty_bit_size);
3515 const small_int_val = if (field.ty.isPtrAtRuntime(mod))3515 const small_int_val = if (field.ty.isPtrAtRuntime(mod))
3516 non_int_val.constPtrToInt(small_int_ty)3516 non_int_val.constPtrToInt(small_int_ty)
...@@ -3547,7 +3547,7 @@ pub const Object = struct {...@@ -3547,7 +3547,7 @@ pub const Object = struct {
35473547
3548 const padding_len = offset - prev_offset;3548 const padding_len = offset - prev_offset;
3549 if (padding_len > 0) {3549 if (padding_len > 0) {
3550 const llvm_array_ty = o.context.intType(8).arrayType(@intCast(c_uint, padding_len));3550 const llvm_array_ty = o.context.intType(8).arrayType(@as(c_uint, @intCast(padding_len)));
3551 // TODO make this and all other padding elsewhere in debug3551 // TODO make this and all other padding elsewhere in debug
3552 // builds be 0xaa not undef.3552 // builds be 0xaa not undef.
3553 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());3553 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());
...@@ -3569,7 +3569,7 @@ pub const Object = struct {...@@ -3569,7 +3569,7 @@ pub const Object = struct {
3569 offset = std.mem.alignForward(u64, offset, big_align);3569 offset = std.mem.alignForward(u64, offset, big_align);
3570 const padding_len = offset - prev_offset;3570 const padding_len = offset - prev_offset;
3571 if (padding_len > 0) {3571 if (padding_len > 0) {
3572 const llvm_array_ty = o.context.intType(8).arrayType(@intCast(c_uint, padding_len));3572 const llvm_array_ty = o.context.intType(8).arrayType(@as(c_uint, @intCast(padding_len)));
3573 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());3573 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());
3574 }3574 }
3575 }3575 }
...@@ -3577,13 +3577,13 @@ pub const Object = struct {...@@ -3577,13 +3577,13 @@ pub const Object = struct {
3577 if (need_unnamed) {3577 if (need_unnamed) {
3578 return o.context.constStruct(3578 return o.context.constStruct(
3579 llvm_fields.items.ptr,3579 llvm_fields.items.ptr,
3580 @intCast(c_uint, llvm_fields.items.len),3580 @as(c_uint, @intCast(llvm_fields.items.len)),
3581 .False,3581 .False,
3582 );3582 );
3583 } else {3583 } else {
3584 return llvm_struct_ty.constNamedStruct(3584 return llvm_struct_ty.constNamedStruct(
3585 llvm_fields.items.ptr,3585 llvm_fields.items.ptr,
3586 @intCast(c_uint, llvm_fields.items.len),3586 @as(c_uint, @intCast(llvm_fields.items.len)),
3587 );3587 );
3588 }3588 }
3589 },3589 },
...@@ -3616,7 +3616,7 @@ pub const Object = struct {...@@ -3616,7 +3616,7 @@ pub const Object = struct {
3616 if (!field_ty.hasRuntimeBits(mod))3616 if (!field_ty.hasRuntimeBits(mod))
3617 return llvm_union_ty.constNull();3617 return llvm_union_ty.constNull();
3618 const non_int_val = try lowerValue(o, .{ .ty = field_ty, .val = tag_and_val.val });3618 const non_int_val = try lowerValue(o, .{ .ty = field_ty, .val = tag_and_val.val });
3619 const ty_bit_size = @intCast(u16, field_ty.bitSize(mod));3619 const ty_bit_size = @as(u16, @intCast(field_ty.bitSize(mod)));
3620 const small_int_ty = o.context.intType(ty_bit_size);3620 const small_int_ty = o.context.intType(ty_bit_size);
3621 const small_int_val = if (field_ty.isPtrAtRuntime(mod))3621 const small_int_val = if (field_ty.isPtrAtRuntime(mod))
3622 non_int_val.constPtrToInt(small_int_ty)3622 non_int_val.constPtrToInt(small_int_ty)
...@@ -3632,7 +3632,7 @@ pub const Object = struct {...@@ -3632,7 +3632,7 @@ pub const Object = struct {
3632 var need_unnamed: bool = layout.most_aligned_field != field_index;3632 var need_unnamed: bool = layout.most_aligned_field != field_index;
3633 const payload = p: {3633 const payload = p: {
3634 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) {3634 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) {
3635 const padding_len = @intCast(c_uint, layout.payload_size);3635 const padding_len = @as(c_uint, @intCast(layout.payload_size));
3636 break :p o.context.intType(8).arrayType(padding_len).getUndef();3636 break :p o.context.intType(8).arrayType(padding_len).getUndef();
3637 }3637 }
3638 const field = try lowerValue(o, .{ .ty = field_ty, .val = tag_and_val.val });3638 const field = try lowerValue(o, .{ .ty = field_ty, .val = tag_and_val.val });
...@@ -3641,7 +3641,7 @@ pub const Object = struct {...@@ -3641,7 +3641,7 @@ pub const Object = struct {
3641 if (field_size == layout.payload_size) {3641 if (field_size == layout.payload_size) {
3642 break :p field;3642 break :p field;
3643 }3643 }
3644 const padding_len = @intCast(c_uint, layout.payload_size - field_size);3644 const padding_len = @as(c_uint, @intCast(layout.payload_size - field_size));
3645 const fields: [2]*llvm.Value = .{3645 const fields: [2]*llvm.Value = .{
3646 field, o.context.intType(8).arrayType(padding_len).getUndef(),3646 field, o.context.intType(8).arrayType(padding_len).getUndef(),
3647 };3647 };
...@@ -3706,7 +3706,7 @@ pub const Object = struct {...@@ -3706,7 +3706,7 @@ pub const Object = struct {
3706 }3706 }
3707 if (@sizeOf(usize) == @sizeOf(u64)) {3707 if (@sizeOf(usize) == @sizeOf(u64)) {
3708 break :v llvm_type.constIntOfArbitraryPrecision(3708 break :v llvm_type.constIntOfArbitraryPrecision(
3709 @intCast(c_uint, bigint.limbs.len),3709 @as(c_uint, @intCast(bigint.limbs.len)),
3710 bigint.limbs.ptr,3710 bigint.limbs.ptr,
3711 );3711 );
3712 }3712 }
...@@ -3799,7 +3799,7 @@ pub const Object = struct {...@@ -3799,7 +3799,7 @@ pub const Object = struct {
3799 const parent_llvm_ptr = try o.lowerParentPtr(field_ptr.base.toValue(), byte_aligned);3799 const parent_llvm_ptr = try o.lowerParentPtr(field_ptr.base.toValue(), byte_aligned);
3800 const parent_ty = mod.intern_pool.typeOf(field_ptr.base).toType().childType(mod);3800 const parent_ty = mod.intern_pool.typeOf(field_ptr.base).toType().childType(mod);
38013801
3802 const field_index = @intCast(u32, field_ptr.index);3802 const field_index = @as(u32, @intCast(field_ptr.index));
3803 const llvm_u32 = o.context.intType(32);3803 const llvm_u32 = o.context.intType(32);
3804 switch (parent_ty.zigTypeTag(mod)) {3804 switch (parent_ty.zigTypeTag(mod)) {
3805 .Union => {3805 .Union => {
...@@ -3834,7 +3834,7 @@ pub const Object = struct {...@@ -3834,7 +3834,7 @@ pub const Object = struct {
3834 var b: usize = 0;3834 var b: usize = 0;
3835 for (parent_ty.structFields(mod).values()[0..field_index]) |field| {3835 for (parent_ty.structFields(mod).values()[0..field_index]) |field| {
3836 if (field.is_comptime or !field.ty.hasRuntimeBitsIgnoreComptime(mod)) continue;3836 if (field.is_comptime or !field.ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
3837 b += @intCast(usize, field.ty.bitSize(mod));3837 b += @as(usize, @intCast(field.ty.bitSize(mod)));
3838 }3838 }
3839 break :b b;3839 break :b b;
3840 };3840 };
...@@ -3992,9 +3992,9 @@ pub const Object = struct {...@@ -3992,9 +3992,9 @@ pub const Object = struct {
3992 ) void {3992 ) void {
3993 const llvm_attr = o.context.createStringAttribute(3993 const llvm_attr = o.context.createStringAttribute(
3994 name.ptr,3994 name.ptr,
3995 @intCast(c_uint, name.len),3995 @as(c_uint, @intCast(name.len)),
3996 value.ptr,3996 value.ptr,
3997 @intCast(c_uint, value.len),3997 @as(c_uint, @intCast(value.len)),
3998 );3998 );
3999 val.addAttributeAtIndex(index, llvm_attr);3999 val.addAttributeAtIndex(index, llvm_attr);
4000 }4000 }
...@@ -4026,14 +4026,14 @@ pub const Object = struct {...@@ -4026,14 +4026,14 @@ pub const Object = struct {
4026 .Enum => ty.intTagType(mod),4026 .Enum => ty.intTagType(mod),
4027 .Float => {4027 .Float => {
4028 if (!is_rmw_xchg) return null;4028 if (!is_rmw_xchg) return null;
4029 return o.context.intType(@intCast(c_uint, ty.abiSize(mod) * 8));4029 return o.context.intType(@as(c_uint, @intCast(ty.abiSize(mod) * 8)));
4030 },4030 },
4031 .Bool => return o.context.intType(8),4031 .Bool => return o.context.intType(8),
4032 else => return null,4032 else => return null,
4033 };4033 };
4034 const bit_count = int_ty.intInfo(mod).bits;4034 const bit_count = int_ty.intInfo(mod).bits;
4035 if (!std.math.isPowerOfTwo(bit_count) or (bit_count % 8) != 0) {4035 if (!std.math.isPowerOfTwo(bit_count) or (bit_count % 8) != 0) {
4036 return o.context.intType(@intCast(c_uint, int_ty.abiSize(mod) * 8));4036 return o.context.intType(@as(c_uint, @intCast(int_ty.abiSize(mod) * 8)));
4037 } else {4037 } else {
4038 return null;4038 return null;
4039 }4039 }
...@@ -4051,7 +4051,7 @@ pub const Object = struct {...@@ -4051,7 +4051,7 @@ pub const Object = struct {
4051 if (param_ty.isPtrAtRuntime(mod)) {4051 if (param_ty.isPtrAtRuntime(mod)) {
4052 const ptr_info = param_ty.ptrInfo(mod);4052 const ptr_info = param_ty.ptrInfo(mod);
4053 if (math.cast(u5, param_index)) |i| {4053 if (math.cast(u5, param_index)) |i| {
4054 if (@truncate(u1, fn_info.noalias_bits >> i) != 0) {4054 if (@as(u1, @truncate(fn_info.noalias_bits >> i)) != 0) {
4055 o.addArgAttr(llvm_fn, llvm_arg_i, "noalias");4055 o.addArgAttr(llvm_fn, llvm_arg_i, "noalias");
4056 }4056 }
4057 }4057 }
...@@ -4550,7 +4550,7 @@ pub const FuncGen = struct {...@@ -4550,7 +4550,7 @@ pub const FuncGen = struct {
4550 fn airCall(self: *FuncGen, inst: Air.Inst.Index, attr: llvm.CallAttr) !?*llvm.Value {4550 fn airCall(self: *FuncGen, inst: Air.Inst.Index, attr: llvm.CallAttr) !?*llvm.Value {
4551 const pl_op = self.air.instructions.items(.data)[inst].pl_op;4551 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
4552 const extra = self.air.extraData(Air.Call, pl_op.payload);4552 const extra = self.air.extraData(Air.Call, pl_op.payload);
4553 const args = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra.end..][0..extra.data.args_len]);4553 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));
4554 const o = self.dg.object;4554 const o = self.dg.object;
4555 const mod = o.module;4555 const mod = o.module;
4556 const callee_ty = self.typeOf(pl_op.operand);4556 const callee_ty = self.typeOf(pl_op.operand);
...@@ -4638,7 +4638,7 @@ pub const FuncGen = struct {...@@ -4638,7 +4638,7 @@ pub const FuncGen = struct {
4638 const arg = args[it.zig_index - 1];4638 const arg = args[it.zig_index - 1];
4639 const param_ty = self.typeOf(arg);4639 const param_ty = self.typeOf(arg);
4640 const llvm_arg = try self.resolveInst(arg);4640 const llvm_arg = try self.resolveInst(arg);
4641 const abi_size = @intCast(c_uint, param_ty.abiSize(mod));4641 const abi_size = @as(c_uint, @intCast(param_ty.abiSize(mod)));
4642 const int_llvm_ty = self.context.intType(abi_size * 8);4642 const int_llvm_ty = self.context.intType(abi_size * 8);
46434643
4644 if (isByRef(param_ty, mod)) {4644 if (isByRef(param_ty, mod)) {
...@@ -4683,10 +4683,10 @@ pub const FuncGen = struct {...@@ -4683,10 +4683,10 @@ pub const FuncGen = struct {
4683 break :p p;4683 break :p p;
4684 };4684 };
46854685
4686 const llvm_ty = self.context.structType(llvm_types.ptr, @intCast(c_uint, llvm_types.len), .False);4686 const llvm_ty = self.context.structType(llvm_types.ptr, @as(c_uint, @intCast(llvm_types.len)), .False);
4687 try llvm_args.ensureUnusedCapacity(it.llvm_types_len);4687 try llvm_args.ensureUnusedCapacity(it.llvm_types_len);
4688 for (llvm_types, 0..) |field_ty, i_usize| {4688 for (llvm_types, 0..) |field_ty, i_usize| {
4689 const i = @intCast(c_uint, i_usize);4689 const i = @as(c_uint, @intCast(i_usize));
4690 const field_ptr = self.builder.buildStructGEP(llvm_ty, arg_ptr, i, "");4690 const field_ptr = self.builder.buildStructGEP(llvm_ty, arg_ptr, i, "");
4691 const load_inst = self.builder.buildLoad(field_ty, field_ptr, "");4691 const load_inst = self.builder.buildLoad(field_ty, field_ptr, "");
4692 load_inst.setAlignment(target.ptrBitWidth() / 8);4692 load_inst.setAlignment(target.ptrBitWidth() / 8);
...@@ -4742,7 +4742,7 @@ pub const FuncGen = struct {...@@ -4742,7 +4742,7 @@ pub const FuncGen = struct {
4742 try o.lowerType(zig_fn_ty),4742 try o.lowerType(zig_fn_ty),
4743 llvm_fn,4743 llvm_fn,
4744 llvm_args.items.ptr,4744 llvm_args.items.ptr,
4745 @intCast(c_uint, llvm_args.items.len),4745 @as(c_uint, @intCast(llvm_args.items.len)),
4746 toLlvmCallConv(fn_info.cc, target),4746 toLlvmCallConv(fn_info.cc, target),
4747 attr,4747 attr,
4748 "",4748 "",
...@@ -4788,7 +4788,7 @@ pub const FuncGen = struct {...@@ -4788,7 +4788,7 @@ pub const FuncGen = struct {
4788 const llvm_arg_i = it.llvm_index - 2;4788 const llvm_arg_i = it.llvm_index - 2;
47894789
4790 if (math.cast(u5, it.zig_index - 1)) |i| {4790 if (math.cast(u5, it.zig_index - 1)) |i| {
4791 if (@truncate(u1, fn_info.noalias_bits >> i) != 0) {4791 if (@as(u1, @truncate(fn_info.noalias_bits >> i)) != 0) {
4792 o.addArgAttr(call, llvm_arg_i, "noalias");4792 o.addArgAttr(call, llvm_arg_i, "noalias");
4793 }4793 }
4794 }4794 }
...@@ -5213,7 +5213,7 @@ pub const FuncGen = struct {...@@ -5213,7 +5213,7 @@ pub const FuncGen = struct {
5213 phi_node.addIncoming(5213 phi_node.addIncoming(
5214 breaks.items(.val).ptr,5214 breaks.items(.val).ptr,
5215 breaks.items(.bb).ptr,5215 breaks.items(.bb).ptr,
5216 @intCast(c_uint, breaks.len),5216 @as(c_uint, @intCast(breaks.len)),
5217 );5217 );
5218 return phi_node;5218 return phi_node;
5219 }5219 }
...@@ -5379,7 +5379,7 @@ pub const FuncGen = struct {...@@ -5379,7 +5379,7 @@ pub const FuncGen = struct {
53795379
5380 while (case_i < switch_br.data.cases_len) : (case_i += 1) {5380 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
5381 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);5381 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
5382 const items = @ptrCast([]const Air.Inst.Ref, self.air.extra[case.end..][0..case.data.items_len]);5382 const items = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[case.end..][0..case.data.items_len]));
5383 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];5383 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
5384 extra_index = case.end + case.data.items_len + case_body.len;5384 extra_index = case.end + case.data.items_len + case_body.len;
53855385
...@@ -5479,7 +5479,7 @@ pub const FuncGen = struct {...@@ -5479,7 +5479,7 @@ pub const FuncGen = struct {
5479 }5479 }
5480 }5480 }
54815481
5482 const operand_bits = @intCast(u16, operand_scalar_ty.bitSize(mod));5482 const operand_bits = @as(u16, @intCast(operand_scalar_ty.bitSize(mod)));
5483 const rt_int_bits = compilerRtIntBits(operand_bits);5483 const rt_int_bits = compilerRtIntBits(operand_bits);
5484 const rt_int_ty = self.context.intType(rt_int_bits);5484 const rt_int_ty = self.context.intType(rt_int_bits);
5485 var extended = e: {5485 var extended = e: {
...@@ -5540,7 +5540,7 @@ pub const FuncGen = struct {...@@ -5540,7 +5540,7 @@ pub const FuncGen = struct {
5540 }5540 }
5541 }5541 }
55425542
5543 const rt_int_bits = compilerRtIntBits(@intCast(u16, dest_scalar_ty.bitSize(mod)));5543 const rt_int_bits = compilerRtIntBits(@as(u16, @intCast(dest_scalar_ty.bitSize(mod))));
5544 const ret_ty = self.context.intType(rt_int_bits);5544 const ret_ty = self.context.intType(rt_int_bits);
5545 const libc_ret_ty = if (rt_int_bits == 128 and (target.os.tag == .windows and target.cpu.arch == .x86_64)) b: {5545 const libc_ret_ty = if (rt_int_bits == 128 and (target.os.tag == .windows and target.cpu.arch == .x86_64)) b: {
5546 // On Windows x86-64, "ti" functions must use Vector(2, u64) instead of the standard5546 // On Windows x86-64, "ti" functions must use Vector(2, u64) instead of the standard
...@@ -5806,12 +5806,12 @@ pub const FuncGen = struct {...@@ -5806,12 +5806,12 @@ pub const FuncGen = struct {
5806 const shifted_value = self.builder.buildLShr(containing_int, shift_amt, "");5806 const shifted_value = self.builder.buildLShr(containing_int, shift_amt, "");
5807 const elem_llvm_ty = try o.lowerType(field_ty);5807 const elem_llvm_ty = try o.lowerType(field_ty);
5808 if (field_ty.zigTypeTag(mod) == .Float or field_ty.zigTypeTag(mod) == .Vector) {5808 if (field_ty.zigTypeTag(mod) == .Float or field_ty.zigTypeTag(mod) == .Vector) {
5809 const elem_bits = @intCast(c_uint, field_ty.bitSize(mod));5809 const elem_bits = @as(c_uint, @intCast(field_ty.bitSize(mod)));
5810 const same_size_int = self.context.intType(elem_bits);5810 const same_size_int = self.context.intType(elem_bits);
5811 const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, "");5811 const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, "");
5812 return self.builder.buildBitCast(truncated_int, elem_llvm_ty, "");5812 return self.builder.buildBitCast(truncated_int, elem_llvm_ty, "");
5813 } else if (field_ty.isPtrAtRuntime(mod)) {5813 } else if (field_ty.isPtrAtRuntime(mod)) {
5814 const elem_bits = @intCast(c_uint, field_ty.bitSize(mod));5814 const elem_bits = @as(c_uint, @intCast(field_ty.bitSize(mod)));
5815 const same_size_int = self.context.intType(elem_bits);5815 const same_size_int = self.context.intType(elem_bits);
5816 const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, "");5816 const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, "");
5817 return self.builder.buildIntToPtr(truncated_int, elem_llvm_ty, "");5817 return self.builder.buildIntToPtr(truncated_int, elem_llvm_ty, "");
...@@ -5828,12 +5828,12 @@ pub const FuncGen = struct {...@@ -5828,12 +5828,12 @@ pub const FuncGen = struct {
5828 const containing_int = struct_llvm_val;5828 const containing_int = struct_llvm_val;
5829 const elem_llvm_ty = try o.lowerType(field_ty);5829 const elem_llvm_ty = try o.lowerType(field_ty);
5830 if (field_ty.zigTypeTag(mod) == .Float or field_ty.zigTypeTag(mod) == .Vector) {5830 if (field_ty.zigTypeTag(mod) == .Float or field_ty.zigTypeTag(mod) == .Vector) {
5831 const elem_bits = @intCast(c_uint, field_ty.bitSize(mod));5831 const elem_bits = @as(c_uint, @intCast(field_ty.bitSize(mod)));
5832 const same_size_int = self.context.intType(elem_bits);5832 const same_size_int = self.context.intType(elem_bits);
5833 const truncated_int = self.builder.buildTrunc(containing_int, same_size_int, "");5833 const truncated_int = self.builder.buildTrunc(containing_int, same_size_int, "");
5834 return self.builder.buildBitCast(truncated_int, elem_llvm_ty, "");5834 return self.builder.buildBitCast(truncated_int, elem_llvm_ty, "");
5835 } else if (field_ty.isPtrAtRuntime(mod)) {5835 } else if (field_ty.isPtrAtRuntime(mod)) {
5836 const elem_bits = @intCast(c_uint, field_ty.bitSize(mod));5836 const elem_bits = @as(c_uint, @intCast(field_ty.bitSize(mod)));
5837 const same_size_int = self.context.intType(elem_bits);5837 const same_size_int = self.context.intType(elem_bits);
5838 const truncated_int = self.builder.buildTrunc(containing_int, same_size_int, "");5838 const truncated_int = self.builder.buildTrunc(containing_int, same_size_int, "");
5839 return self.builder.buildIntToPtr(truncated_int, elem_llvm_ty, "");5839 return self.builder.buildIntToPtr(truncated_int, elem_llvm_ty, "");
...@@ -5924,8 +5924,8 @@ pub const FuncGen = struct {...@@ -5924,8 +5924,8 @@ pub const FuncGen = struct {
5924 fn airDbgStmt(self: *FuncGen, inst: Air.Inst.Index) ?*llvm.Value {5924 fn airDbgStmt(self: *FuncGen, inst: Air.Inst.Index) ?*llvm.Value {
5925 const di_scope = self.di_scope orelse return null;5925 const di_scope = self.di_scope orelse return null;
5926 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;5926 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;
5927 self.prev_dbg_line = @intCast(c_uint, self.base_line + dbg_stmt.line + 1);5927 self.prev_dbg_line = @as(c_uint, @intCast(self.base_line + dbg_stmt.line + 1));
5928 self.prev_dbg_column = @intCast(c_uint, dbg_stmt.column + 1);5928 self.prev_dbg_column = @as(c_uint, @intCast(dbg_stmt.column + 1));
5929 const inlined_at = if (self.dbg_inlined.items.len > 0)5929 const inlined_at = if (self.dbg_inlined.items.len > 0)
5930 self.dbg_inlined.items[self.dbg_inlined.items.len - 1].loc5930 self.dbg_inlined.items[self.dbg_inlined.items.len - 1].loc
5931 else5931 else
...@@ -5949,7 +5949,7 @@ pub const FuncGen = struct {...@@ -5949,7 +5949,7 @@ pub const FuncGen = struct {
5949 const cur_debug_location = self.builder.getCurrentDebugLocation2();5949 const cur_debug_location = self.builder.getCurrentDebugLocation2();
59505950
5951 try self.dbg_inlined.append(self.gpa, .{5951 try self.dbg_inlined.append(self.gpa, .{
5952 .loc = @ptrCast(*llvm.DILocation, cur_debug_location),5952 .loc = @as(*llvm.DILocation, @ptrCast(cur_debug_location)),
5953 .scope = self.di_scope.?,5953 .scope = self.di_scope.?,
5954 .base_line = self.base_line,5954 .base_line = self.base_line,
5955 });5955 });
...@@ -6107,13 +6107,13 @@ pub const FuncGen = struct {...@@ -6107,13 +6107,13 @@ pub const FuncGen = struct {
6107 const o = self.dg.object;6107 const o = self.dg.object;
6108 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;6108 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
6109 const extra = self.air.extraData(Air.Asm, ty_pl.payload);6109 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
6110 const is_volatile = @truncate(u1, extra.data.flags >> 31) != 0;6110 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
6111 const clobbers_len = @truncate(u31, extra.data.flags);6111 const clobbers_len = @as(u31, @truncate(extra.data.flags));
6112 var extra_i: usize = extra.end;6112 var extra_i: usize = extra.end;
61136113
6114 const outputs = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra_i..][0..extra.data.outputs_len]);6114 const outputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]));
6115 extra_i += outputs.len;6115 extra_i += outputs.len;
6116 const inputs = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra_i..][0..extra.data.inputs_len]);6116 const inputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]));
6117 extra_i += inputs.len;6117 extra_i += inputs.len;
61186118
6119 var llvm_constraints: std.ArrayListUnmanaged(u8) = .{};6119 var llvm_constraints: std.ArrayListUnmanaged(u8) = .{};
...@@ -6390,7 +6390,7 @@ pub const FuncGen = struct {...@@ -6390,7 +6390,7 @@ pub const FuncGen = struct {
6390 1 => llvm_ret_types[0],6390 1 => llvm_ret_types[0],
6391 else => self.context.structType(6391 else => self.context.structType(
6392 llvm_ret_types.ptr,6392 llvm_ret_types.ptr,
6393 @intCast(c_uint, return_count),6393 @as(c_uint, @intCast(return_count)),
6394 .False,6394 .False,
6395 ),6395 ),
6396 };6396 };
...@@ -6398,7 +6398,7 @@ pub const FuncGen = struct {...@@ -6398,7 +6398,7 @@ pub const FuncGen = struct {
6398 const llvm_fn_ty = llvm.functionType(6398 const llvm_fn_ty = llvm.functionType(
6399 ret_llvm_ty,6399 ret_llvm_ty,
6400 llvm_param_types.ptr,6400 llvm_param_types.ptr,
6401 @intCast(c_uint, param_count),6401 @as(c_uint, @intCast(param_count)),
6402 .False,6402 .False,
6403 );6403 );
6404 const asm_fn = llvm.getInlineAsm(6404 const asm_fn = llvm.getInlineAsm(
...@@ -6416,7 +6416,7 @@ pub const FuncGen = struct {...@@ -6416,7 +6416,7 @@ pub const FuncGen = struct {
6416 llvm_fn_ty,6416 llvm_fn_ty,
6417 asm_fn,6417 asm_fn,
6418 llvm_param_values.ptr,6418 llvm_param_values.ptr,
6419 @intCast(c_uint, param_count),6419 @as(c_uint, @intCast(param_count)),
6420 .C,6420 .C,
6421 .Auto,6421 .Auto,
6422 "",6422 "",
...@@ -6433,7 +6433,7 @@ pub const FuncGen = struct {...@@ -6433,7 +6433,7 @@ pub const FuncGen = struct {
6433 if (llvm_ret_indirect[i]) continue;6433 if (llvm_ret_indirect[i]) continue;
64346434
6435 const output_value = if (return_count > 1) b: {6435 const output_value = if (return_count > 1) b: {
6436 break :b self.builder.buildExtractValue(call, @intCast(c_uint, llvm_ret_i), "");6436 break :b self.builder.buildExtractValue(call, @as(c_uint, @intCast(llvm_ret_i)), "");
6437 } else call;6437 } else call;
64386438
6439 if (output != .none) {6439 if (output != .none) {
...@@ -7315,7 +7315,7 @@ pub const FuncGen = struct {...@@ -7315,7 +7315,7 @@ pub const FuncGen = struct {
7315 result_vector: *llvm.Value,7315 result_vector: *llvm.Value,
7316 vector_len: usize,7316 vector_len: usize,
7317 ) !*llvm.Value {7317 ) !*llvm.Value {
7318 const args_len = @intCast(c_uint, args_vectors.len);7318 const args_len = @as(c_uint, @intCast(args_vectors.len));
7319 const llvm_i32 = self.context.intType(32);7319 const llvm_i32 = self.context.intType(32);
7320 assert(args_len <= 3);7320 assert(args_len <= 3);
73217321
...@@ -7345,7 +7345,7 @@ pub const FuncGen = struct {...@@ -7345,7 +7345,7 @@ pub const FuncGen = struct {
7345 const alias = o.llvm_module.getNamedGlobalAlias(fn_name.ptr, fn_name.len);7345 const alias = o.llvm_module.getNamedGlobalAlias(fn_name.ptr, fn_name.len);
7346 break :b if (alias) |a| a.getAliasee() else null;7346 break :b if (alias) |a| a.getAliasee() else null;
7347 } orelse b: {7347 } orelse b: {
7348 const params_len = @intCast(c_uint, param_types.len);7348 const params_len = @as(c_uint, @intCast(param_types.len));
7349 const fn_type = llvm.functionType(return_type, param_types.ptr, params_len, .False);7349 const fn_type = llvm.functionType(return_type, param_types.ptr, params_len, .False);
7350 const f = o.llvm_module.addFunction(fn_name, fn_type);7350 const f = o.llvm_module.addFunction(fn_name, fn_type);
7351 break :b f;7351 break :b f;
...@@ -8319,8 +8319,8 @@ pub const FuncGen = struct {...@@ -8319,8 +8319,8 @@ pub const FuncGen = struct {
8319 return null;8319 return null;
8320 const ordering = toLlvmAtomicOrdering(atomic_load.order);8320 const ordering = toLlvmAtomicOrdering(atomic_load.order);
8321 const opt_abi_llvm_ty = o.getAtomicAbiType(elem_ty, false);8321 const opt_abi_llvm_ty = o.getAtomicAbiType(elem_ty, false);
8322 const ptr_alignment = @intCast(u32, ptr_info.flags.alignment.toByteUnitsOptional() orelse8322 const ptr_alignment = @as(u32, @intCast(ptr_info.flags.alignment.toByteUnitsOptional() orelse
8323 ptr_info.child.toType().abiAlignment(mod));8323 ptr_info.child.toType().abiAlignment(mod)));
8324 const ptr_volatile = llvm.Bool.fromBool(ptr_info.flags.is_volatile);8324 const ptr_volatile = llvm.Bool.fromBool(ptr_info.flags.is_volatile);
8325 const elem_llvm_ty = try o.lowerType(elem_ty);8325 const elem_llvm_ty = try o.lowerType(elem_ty);
83268326
...@@ -8696,10 +8696,10 @@ pub const FuncGen = struct {...@@ -8696,10 +8696,10 @@ pub const FuncGen = struct {
8696 const valid_block = self.context.appendBasicBlock(self.llvm_func, "Valid");8696 const valid_block = self.context.appendBasicBlock(self.llvm_func, "Valid");
8697 const invalid_block = self.context.appendBasicBlock(self.llvm_func, "Invalid");8697 const invalid_block = self.context.appendBasicBlock(self.llvm_func, "Invalid");
8698 const end_block = self.context.appendBasicBlock(self.llvm_func, "End");8698 const end_block = self.context.appendBasicBlock(self.llvm_func, "End");
8699 const switch_instr = self.builder.buildSwitch(operand, invalid_block, @intCast(c_uint, names.len));8699 const switch_instr = self.builder.buildSwitch(operand, invalid_block, @as(c_uint, @intCast(names.len)));
87008700
8701 for (names) |name| {8701 for (names) |name| {
8702 const err_int = @intCast(Module.ErrorInt, mod.global_error_set.getIndex(name).?);8702 const err_int = @as(Module.ErrorInt, @intCast(mod.global_error_set.getIndex(name).?));
8703 const this_tag_int_value = try o.lowerValue(.{8703 const this_tag_int_value = try o.lowerValue(.{
8704 .ty = Type.err_int,8704 .ty = Type.err_int,
8705 .val = try mod.intValue(Type.err_int, err_int),8705 .val = try mod.intValue(Type.err_int, err_int),
...@@ -8779,10 +8779,10 @@ pub const FuncGen = struct {...@@ -8779,10 +8779,10 @@ pub const FuncGen = struct {
8779 const named_block = self.context.appendBasicBlock(fn_val, "Named");8779 const named_block = self.context.appendBasicBlock(fn_val, "Named");
8780 const unnamed_block = self.context.appendBasicBlock(fn_val, "Unnamed");8780 const unnamed_block = self.context.appendBasicBlock(fn_val, "Unnamed");
8781 const tag_int_value = fn_val.getParam(0);8781 const tag_int_value = fn_val.getParam(0);
8782 const switch_instr = self.builder.buildSwitch(tag_int_value, unnamed_block, @intCast(c_uint, enum_type.names.len));8782 const switch_instr = self.builder.buildSwitch(tag_int_value, unnamed_block, @as(c_uint, @intCast(enum_type.names.len)));
87838783
8784 for (enum_type.names, 0..) |_, field_index_usize| {8784 for (enum_type.names, 0..) |_, field_index_usize| {
8785 const field_index = @intCast(u32, field_index_usize);8785 const field_index = @as(u32, @intCast(field_index_usize));
8786 const this_tag_int_value = int: {8786 const this_tag_int_value = int: {
8787 break :int try o.lowerValue(.{8787 break :int try o.lowerValue(.{
8788 .ty = enum_ty,8788 .ty = enum_ty,
...@@ -8855,16 +8855,16 @@ pub const FuncGen = struct {...@@ -8855,16 +8855,16 @@ pub const FuncGen = struct {
88558855
8856 const bad_value_block = self.context.appendBasicBlock(fn_val, "BadValue");8856 const bad_value_block = self.context.appendBasicBlock(fn_val, "BadValue");
8857 const tag_int_value = fn_val.getParam(0);8857 const tag_int_value = fn_val.getParam(0);
8858 const switch_instr = self.builder.buildSwitch(tag_int_value, bad_value_block, @intCast(c_uint, enum_type.names.len));8858 const switch_instr = self.builder.buildSwitch(tag_int_value, bad_value_block, @as(c_uint, @intCast(enum_type.names.len)));
88598859
8860 const array_ptr_indices = [_]*llvm.Value{8860 const array_ptr_indices = [_]*llvm.Value{
8861 usize_llvm_ty.constNull(), usize_llvm_ty.constNull(),8861 usize_llvm_ty.constNull(), usize_llvm_ty.constNull(),
8862 };8862 };
88638863
8864 for (enum_type.names, 0..) |name_ip, field_index_usize| {8864 for (enum_type.names, 0..) |name_ip, field_index_usize| {
8865 const field_index = @intCast(u32, field_index_usize);8865 const field_index = @as(u32, @intCast(field_index_usize));
8866 const name = mod.intern_pool.stringToSlice(name_ip);8866 const name = mod.intern_pool.stringToSlice(name_ip);
8867 const str_init = self.context.constString(name.ptr, @intCast(c_uint, name.len), .False);8867 const str_init = self.context.constString(name.ptr, @as(c_uint, @intCast(name.len)), .False);
8868 const str_init_llvm_ty = str_init.typeOf();8868 const str_init_llvm_ty = str_init.typeOf();
8869 const str_global = o.llvm_module.addGlobal(str_init_llvm_ty, "");8869 const str_global = o.llvm_module.addGlobal(str_init_llvm_ty, "");
8870 str_global.setInitializer(str_init);8870 str_global.setInitializer(str_init);
...@@ -8986,7 +8986,7 @@ pub const FuncGen = struct {...@@ -8986,7 +8986,7 @@ pub const FuncGen = struct {
8986 val.* = llvm_i32.getUndef();8986 val.* = llvm_i32.getUndef();
8987 } else {8987 } else {
8988 const int = elem.toSignedInt(mod);8988 const int = elem.toSignedInt(mod);
8989 const unsigned = if (int >= 0) @intCast(u32, int) else @intCast(u32, ~int + a_len);8989 const unsigned = if (int >= 0) @as(u32, @intCast(int)) else @as(u32, @intCast(~int + a_len));
8990 val.* = llvm_i32.constInt(unsigned, .False);8990 val.* = llvm_i32.constInt(unsigned, .False);
8991 }8991 }
8992 }8992 }
...@@ -9150,8 +9150,8 @@ pub const FuncGen = struct {...@@ -9150,8 +9150,8 @@ pub const FuncGen = struct {
9150 const mod = o.module;9150 const mod = o.module;
9151 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;9151 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
9152 const result_ty = self.typeOfIndex(inst);9152 const result_ty = self.typeOfIndex(inst);
9153 const len = @intCast(usize, result_ty.arrayLen(mod));9153 const len = @as(usize, @intCast(result_ty.arrayLen(mod)));
9154 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);9154 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
9155 const llvm_result_ty = try o.lowerType(result_ty);9155 const llvm_result_ty = try o.lowerType(result_ty);
91569156
9157 switch (result_ty.zigTypeTag(mod)) {9157 switch (result_ty.zigTypeTag(mod)) {
...@@ -9171,7 +9171,7 @@ pub const FuncGen = struct {...@@ -9171,7 +9171,7 @@ pub const FuncGen = struct {
9171 const struct_obj = mod.typeToStruct(result_ty).?;9171 const struct_obj = mod.typeToStruct(result_ty).?;
9172 assert(struct_obj.haveLayout());9172 assert(struct_obj.haveLayout());
9173 const big_bits = struct_obj.backing_int_ty.bitSize(mod);9173 const big_bits = struct_obj.backing_int_ty.bitSize(mod);
9174 const int_llvm_ty = self.context.intType(@intCast(c_uint, big_bits));9174 const int_llvm_ty = self.context.intType(@as(c_uint, @intCast(big_bits)));
9175 const fields = struct_obj.fields.values();9175 const fields = struct_obj.fields.values();
9176 comptime assert(Type.packed_struct_layout_version == 2);9176 comptime assert(Type.packed_struct_layout_version == 2);
9177 var running_int: *llvm.Value = int_llvm_ty.constNull();9177 var running_int: *llvm.Value = int_llvm_ty.constNull();
...@@ -9181,7 +9181,7 @@ pub const FuncGen = struct {...@@ -9181,7 +9181,7 @@ pub const FuncGen = struct {
9181 if (!field.ty.hasRuntimeBitsIgnoreComptime(mod)) continue;9181 if (!field.ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
91829182
9183 const non_int_val = try self.resolveInst(elem);9183 const non_int_val = try self.resolveInst(elem);
9184 const ty_bit_size = @intCast(u16, field.ty.bitSize(mod));9184 const ty_bit_size = @as(u16, @intCast(field.ty.bitSize(mod)));
9185 const small_int_ty = self.context.intType(ty_bit_size);9185 const small_int_ty = self.context.intType(ty_bit_size);
9186 const small_int_val = if (field.ty.isPtrAtRuntime(mod))9186 const small_int_val = if (field.ty.isPtrAtRuntime(mod))
9187 self.builder.buildPtrToInt(non_int_val, small_int_ty, "")9187 self.builder.buildPtrToInt(non_int_val, small_int_ty, "")
...@@ -9251,7 +9251,7 @@ pub const FuncGen = struct {...@@ -9251,7 +9251,7 @@ pub const FuncGen = struct {
9251 for (elements, 0..) |elem, i| {9251 for (elements, 0..) |elem, i| {
9252 const indices: [2]*llvm.Value = .{9252 const indices: [2]*llvm.Value = .{
9253 llvm_usize.constNull(),9253 llvm_usize.constNull(),
9254 llvm_usize.constInt(@intCast(c_uint, i), .False),9254 llvm_usize.constInt(@as(c_uint, @intCast(i)), .False),
9255 };9255 };
9256 const elem_ptr = self.builder.buildInBoundsGEP(llvm_result_ty, alloca_inst, &indices, indices.len, "");9256 const elem_ptr = self.builder.buildInBoundsGEP(llvm_result_ty, alloca_inst, &indices, indices.len, "");
9257 const llvm_elem = try self.resolveInst(elem);9257 const llvm_elem = try self.resolveInst(elem);
...@@ -9260,7 +9260,7 @@ pub const FuncGen = struct {...@@ -9260,7 +9260,7 @@ pub const FuncGen = struct {
9260 if (array_info.sentinel) |sent_val| {9260 if (array_info.sentinel) |sent_val| {
9261 const indices: [2]*llvm.Value = .{9261 const indices: [2]*llvm.Value = .{
9262 llvm_usize.constNull(),9262 llvm_usize.constNull(),
9263 llvm_usize.constInt(@intCast(c_uint, array_info.len), .False),9263 llvm_usize.constInt(@as(c_uint, @intCast(array_info.len)), .False),
9264 };9264 };
9265 const elem_ptr = self.builder.buildInBoundsGEP(llvm_result_ty, alloca_inst, &indices, indices.len, "");9265 const elem_ptr = self.builder.buildInBoundsGEP(llvm_result_ty, alloca_inst, &indices, indices.len, "");
9266 const llvm_elem = try self.resolveValue(.{9266 const llvm_elem = try self.resolveValue(.{
...@@ -9289,10 +9289,10 @@ pub const FuncGen = struct {...@@ -9289,10 +9289,10 @@ pub const FuncGen = struct {
92899289
9290 if (union_obj.layout == .Packed) {9290 if (union_obj.layout == .Packed) {
9291 const big_bits = union_ty.bitSize(mod);9291 const big_bits = union_ty.bitSize(mod);
9292 const int_llvm_ty = self.context.intType(@intCast(c_uint, big_bits));9292 const int_llvm_ty = self.context.intType(@as(c_uint, @intCast(big_bits)));
9293 const field = union_obj.fields.values()[extra.field_index];9293 const field = union_obj.fields.values()[extra.field_index];
9294 const non_int_val = try self.resolveInst(extra.init);9294 const non_int_val = try self.resolveInst(extra.init);
9295 const ty_bit_size = @intCast(u16, field.ty.bitSize(mod));9295 const ty_bit_size = @as(u16, @intCast(field.ty.bitSize(mod)));
9296 const small_int_ty = self.context.intType(ty_bit_size);9296 const small_int_ty = self.context.intType(ty_bit_size);
9297 const small_int_val = if (field.ty.isPtrAtRuntime(mod))9297 const small_int_val = if (field.ty.isPtrAtRuntime(mod))
9298 self.builder.buildPtrToInt(non_int_val, small_int_ty, "")9298 self.builder.buildPtrToInt(non_int_val, small_int_ty, "")
...@@ -9332,13 +9332,13 @@ pub const FuncGen = struct {...@@ -9332,13 +9332,13 @@ pub const FuncGen = struct {
9332 const llvm_union_ty = t: {9332 const llvm_union_ty = t: {
9333 const payload = p: {9333 const payload = p: {
9334 if (!field.ty.hasRuntimeBitsIgnoreComptime(mod)) {9334 if (!field.ty.hasRuntimeBitsIgnoreComptime(mod)) {
9335 const padding_len = @intCast(c_uint, layout.payload_size);9335 const padding_len = @as(c_uint, @intCast(layout.payload_size));
9336 break :p self.context.intType(8).arrayType(padding_len);9336 break :p self.context.intType(8).arrayType(padding_len);
9337 }9337 }
9338 if (field_size == layout.payload_size) {9338 if (field_size == layout.payload_size) {
9339 break :p field_llvm_ty;9339 break :p field_llvm_ty;
9340 }9340 }
9341 const padding_len = @intCast(c_uint, layout.payload_size - field_size);9341 const padding_len = @as(c_uint, @intCast(layout.payload_size - field_size));
9342 const fields: [2]*llvm.Type = .{9342 const fields: [2]*llvm.Type = .{
9343 field_llvm_ty, self.context.intType(8).arrayType(padding_len),9343 field_llvm_ty, self.context.intType(8).arrayType(padding_len),
9344 };9344 };
...@@ -9766,8 +9766,8 @@ pub const FuncGen = struct {...@@ -9766,8 +9766,8 @@ pub const FuncGen = struct {
9766 const elem_ty = info.child.toType();9766 const elem_ty = info.child.toType();
9767 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) return null;9767 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) return null;
97689768
9769 const ptr_alignment = @intCast(u32, info.flags.alignment.toByteUnitsOptional() orelse9769 const ptr_alignment = @as(u32, @intCast(info.flags.alignment.toByteUnitsOptional() orelse
9770 elem_ty.abiAlignment(mod));9770 elem_ty.abiAlignment(mod)));
9771 const ptr_volatile = llvm.Bool.fromBool(info.flags.is_volatile);9771 const ptr_volatile = llvm.Bool.fromBool(info.flags.is_volatile);
97729772
9773 assert(info.flags.vector_index != .runtime);9773 assert(info.flags.vector_index != .runtime);
...@@ -9799,7 +9799,7 @@ pub const FuncGen = struct {...@@ -9799,7 +9799,7 @@ pub const FuncGen = struct {
9799 containing_int.setAlignment(ptr_alignment);9799 containing_int.setAlignment(ptr_alignment);
9800 containing_int.setVolatile(ptr_volatile);9800 containing_int.setVolatile(ptr_volatile);
98019801
9802 const elem_bits = @intCast(c_uint, ptr_ty.childType(mod).bitSize(mod));9802 const elem_bits = @as(c_uint, @intCast(ptr_ty.childType(mod).bitSize(mod)));
9803 const shift_amt = containing_int.typeOf().constInt(info.packed_offset.bit_offset, .False);9803 const shift_amt = containing_int.typeOf().constInt(info.packed_offset.bit_offset, .False);
9804 const shifted_value = self.builder.buildLShr(containing_int, shift_amt, "");9804 const shifted_value = self.builder.buildLShr(containing_int, shift_amt, "");
9805 const elem_llvm_ty = try o.lowerType(elem_ty);9805 const elem_llvm_ty = try o.lowerType(elem_ty);
...@@ -9872,7 +9872,7 @@ pub const FuncGen = struct {...@@ -9872,7 +9872,7 @@ pub const FuncGen = struct {
9872 assert(ordering == .NotAtomic);9872 assert(ordering == .NotAtomic);
9873 containing_int.setAlignment(ptr_alignment);9873 containing_int.setAlignment(ptr_alignment);
9874 containing_int.setVolatile(ptr_volatile);9874 containing_int.setVolatile(ptr_volatile);
9875 const elem_bits = @intCast(c_uint, ptr_ty.childType(mod).bitSize(mod));9875 const elem_bits = @as(c_uint, @intCast(ptr_ty.childType(mod).bitSize(mod)));
9876 const containing_int_ty = containing_int.typeOf();9876 const containing_int_ty = containing_int.typeOf();
9877 const shift_amt = containing_int_ty.constInt(info.packed_offset.bit_offset, .False);9877 const shift_amt = containing_int_ty.constInt(info.packed_offset.bit_offset, .False);
9878 // Convert to equally-sized integer type in order to perform the bit9878 // Convert to equally-sized integer type in order to perform the bit
...@@ -9945,7 +9945,7 @@ pub const FuncGen = struct {...@@ -9945,7 +9945,7 @@ pub const FuncGen = struct {
9945 if (!target_util.hasValgrindSupport(target)) return default_value;9945 if (!target_util.hasValgrindSupport(target)) return default_value;
99469946
9947 const usize_llvm_ty = fg.context.intType(target.ptrBitWidth());9947 const usize_llvm_ty = fg.context.intType(target.ptrBitWidth());
9948 const usize_alignment = @intCast(c_uint, Type.usize.abiSize(mod));9948 const usize_alignment = @as(c_uint, @intCast(Type.usize.abiSize(mod)));
99499949
9950 const array_llvm_ty = usize_llvm_ty.arrayType(6);9950 const array_llvm_ty = usize_llvm_ty.arrayType(6);
9951 const array_ptr = fg.valgrind_client_request_array orelse a: {9951 const array_ptr = fg.valgrind_client_request_array orelse a: {
...@@ -9957,7 +9957,7 @@ pub const FuncGen = struct {...@@ -9957,7 +9957,7 @@ pub const FuncGen = struct {
9957 const zero = usize_llvm_ty.constInt(0, .False);9957 const zero = usize_llvm_ty.constInt(0, .False);
9958 for (array_elements, 0..) |elem, i| {9958 for (array_elements, 0..) |elem, i| {
9959 const indexes = [_]*llvm.Value{9959 const indexes = [_]*llvm.Value{
9960 zero, usize_llvm_ty.constInt(@intCast(c_uint, i), .False),9960 zero, usize_llvm_ty.constInt(@as(c_uint, @intCast(i)), .False),
9961 };9961 };
9962 const elem_ptr = fg.builder.buildInBoundsGEP(array_llvm_ty, array_ptr, &indexes, indexes.len, "");9962 const elem_ptr = fg.builder.buildInBoundsGEP(array_llvm_ty, array_ptr, &indexes, indexes.len, "");
9963 const store_inst = fg.builder.buildStore(elem, elem_ptr);9963 const store_inst = fg.builder.buildStore(elem, elem_ptr);
...@@ -10530,7 +10530,7 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) !*llvm.Type {...@@ -10530,7 +10530,7 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) !*llvm.Type {
10530 assert(classes[0] == .direct and classes[1] == .none);10530 assert(classes[0] == .direct and classes[1] == .none);
10531 const scalar_type = wasm_c_abi.scalarType(return_type, mod);10531 const scalar_type = wasm_c_abi.scalarType(return_type, mod);
10532 const abi_size = scalar_type.abiSize(mod);10532 const abi_size = scalar_type.abiSize(mod);
10533 return o.context.intType(@intCast(c_uint, abi_size * 8));10533 return o.context.intType(@as(c_uint, @intCast(abi_size * 8)));
10534 },10534 },
10535 .aarch64, .aarch64_be => {10535 .aarch64, .aarch64_be => {
10536 switch (aarch64_c_abi.classifyType(return_type, mod)) {10536 switch (aarch64_c_abi.classifyType(return_type, mod)) {
...@@ -10539,7 +10539,7 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) !*llvm.Type {...@@ -10539,7 +10539,7 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) !*llvm.Type {
10539 .byval => return o.lowerType(return_type),10539 .byval => return o.lowerType(return_type),
10540 .integer => {10540 .integer => {
10541 const bit_size = return_type.bitSize(mod);10541 const bit_size = return_type.bitSize(mod);
10542 return o.context.intType(@intCast(c_uint, bit_size));10542 return o.context.intType(@as(c_uint, @intCast(bit_size)));
10543 },10543 },
10544 .double_integer => return o.context.intType(64).arrayType(2),10544 .double_integer => return o.context.intType(64).arrayType(2),
10545 }10545 }
...@@ -10560,7 +10560,7 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) !*llvm.Type {...@@ -10560,7 +10560,7 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) !*llvm.Type {
10560 .memory => return o.context.voidType(),10560 .memory => return o.context.voidType(),
10561 .integer => {10561 .integer => {
10562 const bit_size = return_type.bitSize(mod);10562 const bit_size = return_type.bitSize(mod);
10563 return o.context.intType(@intCast(c_uint, bit_size));10563 return o.context.intType(@as(c_uint, @intCast(bit_size)));
10564 },10564 },
10565 .double_integer => {10565 .double_integer => {
10566 var llvm_types_buffer: [2]*llvm.Type = .{10566 var llvm_types_buffer: [2]*llvm.Type = .{
...@@ -10598,7 +10598,7 @@ fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) !*llvm.Type {...@@ -10598,7 +10598,7 @@ fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) !*llvm.Type {
10598 return o.lowerType(return_type);10598 return o.lowerType(return_type);
10599 } else {10599 } else {
10600 const abi_size = return_type.abiSize(mod);10600 const abi_size = return_type.abiSize(mod);
10601 return o.context.intType(@intCast(c_uint, abi_size * 8));10601 return o.context.intType(@as(c_uint, @intCast(abi_size * 8)));
10602 }10602 }
10603 },10603 },
10604 .win_i128 => return o.context.intType(64).vectorType(2),10604 .win_i128 => return o.context.intType(64).vectorType(2),
...@@ -10656,7 +10656,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) !*llvm.Type...@@ -10656,7 +10656,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) !*llvm.Type
10656 }10656 }
10657 if (classes[0] == .integer and classes[1] == .none) {10657 if (classes[0] == .integer and classes[1] == .none) {
10658 const abi_size = return_type.abiSize(mod);10658 const abi_size = return_type.abiSize(mod);
10659 return o.context.intType(@intCast(c_uint, abi_size * 8));10659 return o.context.intType(@as(c_uint, @intCast(abi_size * 8)));
10660 }10660 }
10661 return o.context.structType(&llvm_types_buffer, llvm_types_index, .False);10661 return o.context.structType(&llvm_types_buffer, llvm_types_index, .False);
10662}10662}
...@@ -11145,28 +11145,28 @@ const AnnotatedDITypePtr = enum(usize) {...@@ -11145,28 +11145,28 @@ const AnnotatedDITypePtr = enum(usize) {
1114511145
11146 fn initFwd(di_type: *llvm.DIType) AnnotatedDITypePtr {11146 fn initFwd(di_type: *llvm.DIType) AnnotatedDITypePtr {
11147 const addr = @intFromPtr(di_type);11147 const addr = @intFromPtr(di_type);
11148 assert(@truncate(u1, addr) == 0);11148 assert(@as(u1, @truncate(addr)) == 0);
11149 return @enumFromInt(AnnotatedDITypePtr, addr | 1);11149 return @as(AnnotatedDITypePtr, @enumFromInt(addr | 1));
11150 }11150 }
1115111151
11152 fn initFull(di_type: *llvm.DIType) AnnotatedDITypePtr {11152 fn initFull(di_type: *llvm.DIType) AnnotatedDITypePtr {
11153 const addr = @intFromPtr(di_type);11153 const addr = @intFromPtr(di_type);
11154 return @enumFromInt(AnnotatedDITypePtr, addr);11154 return @as(AnnotatedDITypePtr, @enumFromInt(addr));
11155 }11155 }
1115611156
11157 fn init(di_type: *llvm.DIType, resolve: Object.DebugResolveStatus) AnnotatedDITypePtr {11157 fn init(di_type: *llvm.DIType, resolve: Object.DebugResolveStatus) AnnotatedDITypePtr {
11158 const addr = @intFromPtr(di_type);11158 const addr = @intFromPtr(di_type);
11159 const bit = @intFromBool(resolve == .fwd);11159 const bit = @intFromBool(resolve == .fwd);
11160 return @enumFromInt(AnnotatedDITypePtr, addr | bit);11160 return @as(AnnotatedDITypePtr, @enumFromInt(addr | bit));
11161 }11161 }
1116211162
11163 fn toDIType(self: AnnotatedDITypePtr) *llvm.DIType {11163 fn toDIType(self: AnnotatedDITypePtr) *llvm.DIType {
11164 const fixed_addr = @intFromEnum(self) & ~@as(usize, 1);11164 const fixed_addr = @intFromEnum(self) & ~@as(usize, 1);
11165 return @ptrFromInt(*llvm.DIType, fixed_addr);11165 return @as(*llvm.DIType, @ptrFromInt(fixed_addr));
11166 }11166 }
1116711167
11168 fn isFwdOnly(self: AnnotatedDITypePtr) bool {11168 fn isFwdOnly(self: AnnotatedDITypePtr) bool {
11169 return @truncate(u1, @intFromEnum(self)) != 0;11169 return @as(u1, @truncate(@intFromEnum(self))) != 0;
11170 }11170 }
11171};11171};
1117211172
src/codegen/llvm/bindings.zig+1-1
...@@ -8,7 +8,7 @@ pub const Bool = enum(c_int) {...@@ -8,7 +8,7 @@ pub const Bool = enum(c_int) {
8 _,8 _,
99
10 pub fn fromBool(b: bool) Bool {10 pub fn fromBool(b: bool) Bool {
11 return @enumFromInt(Bool, @intFromBool(b));11 return @as(Bool, @enumFromInt(@intFromBool(b)));
12 }12 }
1313
14 pub fn toBool(b: Bool) bool {14 pub fn toBool(b: Bool) bool {
src/codegen/spirv.zig+25-25
...@@ -466,7 +466,7 @@ pub const DeclGen = struct {...@@ -466,7 +466,7 @@ pub const DeclGen = struct {
466 unused.* = undef;466 unused.* = undef;
467 }467 }
468468
469 const word = @bitCast(Word, self.partial_word.buffer);469 const word = @as(Word, @bitCast(self.partial_word.buffer));
470 const result_id = try self.dg.spv.constInt(self.u32_ty_ref, word);470 const result_id = try self.dg.spv.constInt(self.u32_ty_ref, word);
471 try self.members.append(self.u32_ty_ref);471 try self.members.append(self.u32_ty_ref);
472 try self.initializers.append(result_id);472 try self.initializers.append(result_id);
...@@ -482,7 +482,7 @@ pub const DeclGen = struct {...@@ -482,7 +482,7 @@ pub const DeclGen = struct {
482 }482 }
483483
484 fn addUndef(self: *@This(), amt: u64) !void {484 fn addUndef(self: *@This(), amt: u64) !void {
485 for (0..@intCast(usize, amt)) |_| {485 for (0..@as(usize, @intCast(amt))) |_| {
486 try self.addByte(undef);486 try self.addByte(undef);
487 }487 }
488 }488 }
...@@ -539,13 +539,13 @@ pub const DeclGen = struct {...@@ -539,13 +539,13 @@ pub const DeclGen = struct {
539 const mod = self.dg.module;539 const mod = self.dg.module;
540 const int_info = ty.intInfo(mod);540 const int_info = ty.intInfo(mod);
541 const int_bits = switch (int_info.signedness) {541 const int_bits = switch (int_info.signedness) {
542 .signed => @bitCast(u64, val.toSignedInt(mod)),542 .signed => @as(u64, @bitCast(val.toSignedInt(mod))),
543 .unsigned => val.toUnsignedInt(mod),543 .unsigned => val.toUnsignedInt(mod),
544 };544 };
545545
546 // TODO: Swap endianess if the compiler is big endian.546 // TODO: Swap endianess if the compiler is big endian.
547 const len = ty.abiSize(mod);547 const len = ty.abiSize(mod);
548 try self.addBytes(std.mem.asBytes(&int_bits)[0..@intCast(usize, len)]);548 try self.addBytes(std.mem.asBytes(&int_bits)[0..@as(usize, @intCast(len))]);
549 }549 }
550550
551 fn addFloat(self: *@This(), ty: Type, val: Value) !void {551 fn addFloat(self: *@This(), ty: Type, val: Value) !void {
...@@ -557,15 +557,15 @@ pub const DeclGen = struct {...@@ -557,15 +557,15 @@ pub const DeclGen = struct {
557 switch (ty.floatBits(target)) {557 switch (ty.floatBits(target)) {
558 16 => {558 16 => {
559 const float_bits = val.toFloat(f16, mod);559 const float_bits = val.toFloat(f16, mod);
560 try self.addBytes(std.mem.asBytes(&float_bits)[0..@intCast(usize, len)]);560 try self.addBytes(std.mem.asBytes(&float_bits)[0..@as(usize, @intCast(len))]);
561 },561 },
562 32 => {562 32 => {
563 const float_bits = val.toFloat(f32, mod);563 const float_bits = val.toFloat(f32, mod);
564 try self.addBytes(std.mem.asBytes(&float_bits)[0..@intCast(usize, len)]);564 try self.addBytes(std.mem.asBytes(&float_bits)[0..@as(usize, @intCast(len))]);
565 },565 },
566 64 => {566 64 => {
567 const float_bits = val.toFloat(f64, mod);567 const float_bits = val.toFloat(f64, mod);
568 try self.addBytes(std.mem.asBytes(&float_bits)[0..@intCast(usize, len)]);568 try self.addBytes(std.mem.asBytes(&float_bits)[0..@as(usize, @intCast(len))]);
569 },569 },
570 else => unreachable,570 else => unreachable,
571 }571 }
...@@ -664,7 +664,7 @@ pub const DeclGen = struct {...@@ -664,7 +664,7 @@ pub const DeclGen = struct {
664 .int => try self.addInt(ty, val),664 .int => try self.addInt(ty, val),
665 .err => |err| {665 .err => |err| {
666 const int = try mod.getErrorValue(err.name);666 const int = try mod.getErrorValue(err.name);
667 try self.addConstInt(u16, @intCast(u16, int));667 try self.addConstInt(u16, @as(u16, @intCast(int)));
668 },668 },
669 .error_union => |error_union| {669 .error_union => |error_union| {
670 const payload_ty = ty.errorUnionPayload(mod);670 const payload_ty = ty.errorUnionPayload(mod);
...@@ -755,10 +755,10 @@ pub const DeclGen = struct {...@@ -755,10 +755,10 @@ pub const DeclGen = struct {
755 switch (aggregate.storage) {755 switch (aggregate.storage) {
756 .bytes => |bytes| try self.addBytes(bytes),756 .bytes => |bytes| try self.addBytes(bytes),
757 .elems, .repeated_elem => {757 .elems, .repeated_elem => {
758 for (0..@intCast(usize, array_type.len)) |i| {758 for (0..@as(usize, @intCast(array_type.len))) |i| {
759 try self.lower(elem_ty, switch (aggregate.storage) {759 try self.lower(elem_ty, switch (aggregate.storage) {
760 .bytes => unreachable,760 .bytes => unreachable,
761 .elems => |elem_vals| elem_vals[@intCast(usize, i)].toValue(),761 .elems => |elem_vals| elem_vals[@as(usize, @intCast(i))].toValue(),
762 .repeated_elem => |elem_val| elem_val.toValue(),762 .repeated_elem => |elem_val| elem_val.toValue(),
763 });763 });
764 }764 }
...@@ -1132,7 +1132,7 @@ pub const DeclGen = struct {...@@ -1132,7 +1132,7 @@ pub const DeclGen = struct {
11321132
1133 const payload_padding_len = layout.payload_size - active_field_size;1133 const payload_padding_len = layout.payload_size - active_field_size;
1134 if (payload_padding_len != 0) {1134 if (payload_padding_len != 0) {
1135 const payload_padding_ty_ref = try self.spv.arrayType(@intCast(u32, payload_padding_len), u8_ty_ref);1135 const payload_padding_ty_ref = try self.spv.arrayType(@as(u32, @intCast(payload_padding_len)), u8_ty_ref);
1136 member_types.appendAssumeCapacity(payload_padding_ty_ref);1136 member_types.appendAssumeCapacity(payload_padding_ty_ref);
1137 member_names.appendAssumeCapacity(try self.spv.resolveString("payload_padding"));1137 member_names.appendAssumeCapacity(try self.spv.resolveString("payload_padding"));
1138 }1138 }
...@@ -1259,7 +1259,7 @@ pub const DeclGen = struct {...@@ -1259,7 +1259,7 @@ pub const DeclGen = struct {
12591259
1260 return try self.spv.resolve(.{ .vector_type = .{1260 return try self.spv.resolve(.{ .vector_type = .{
1261 .component_type = try self.resolveType(ty.childType(mod), repr),1261 .component_type = try self.resolveType(ty.childType(mod), repr),
1262 .component_count = @intCast(u32, ty.vectorLen(mod)),1262 .component_count = @as(u32, @intCast(ty.vectorLen(mod))),
1263 } });1263 } });
1264 },1264 },
1265 .Struct => {1265 .Struct => {
...@@ -1588,7 +1588,7 @@ pub const DeclGen = struct {...@@ -1588,7 +1588,7 @@ pub const DeclGen = struct {
1588 init_val,1588 init_val,
1589 actual_storage_class,1589 actual_storage_class,
1590 final_storage_class == .Generic,1590 final_storage_class == .Generic,
1591 @intCast(u32, decl.alignment.toByteUnits(0)),1591 @as(u32, @intCast(decl.alignment.toByteUnits(0))),
1592 );1592 );
1593 }1593 }
1594 }1594 }
...@@ -1856,7 +1856,7 @@ pub const DeclGen = struct {...@@ -1856,7 +1856,7 @@ pub const DeclGen = struct {
1856 }1856 }
18571857
1858 fn maskStrangeInt(self: *DeclGen, ty_ref: CacheRef, value_id: IdRef, bits: u16) !IdRef {1858 fn maskStrangeInt(self: *DeclGen, ty_ref: CacheRef, value_id: IdRef, bits: u16) !IdRef {
1859 const mask_value = if (bits == 64) 0xFFFF_FFFF_FFFF_FFFF else (@as(u64, 1) << @intCast(u6, bits)) - 1;1859 const mask_value = if (bits == 64) 0xFFFF_FFFF_FFFF_FFFF else (@as(u64, 1) << @as(u6, @intCast(bits))) - 1;
1860 const result_id = self.spv.allocId();1860 const result_id = self.spv.allocId();
1861 const mask_id = try self.spv.constInt(ty_ref, mask_value);1861 const mask_id = try self.spv.constInt(ty_ref, mask_value);
1862 try self.func.body.emit(self.spv.gpa, .OpBitwiseAnd, .{1862 try self.func.body.emit(self.spv.gpa, .OpBitwiseAnd, .{
...@@ -2063,7 +2063,7 @@ pub const DeclGen = struct {...@@ -2063,7 +2063,7 @@ pub const DeclGen = struct {
2063 self.func.body.writeOperand(spec.LiteralInteger, 0xFFFF_FFFF);2063 self.func.body.writeOperand(spec.LiteralInteger, 0xFFFF_FFFF);
2064 } else {2064 } else {
2065 const int = elem.toSignedInt(mod);2065 const int = elem.toSignedInt(mod);
2066 const unsigned = if (int >= 0) @intCast(u32, int) else @intCast(u32, ~int + a_len);2066 const unsigned = if (int >= 0) @as(u32, @intCast(int)) else @as(u32, @intCast(~int + a_len));
2067 self.func.body.writeOperand(spec.LiteralInteger, unsigned);2067 self.func.body.writeOperand(spec.LiteralInteger, unsigned);
2068 }2068 }
2069 }2069 }
...@@ -2689,7 +2689,7 @@ pub const DeclGen = struct {...@@ -2689,7 +2689,7 @@ pub const DeclGen = struct {
2689 // are not allowed to be created from a phi node, and throw an error for those.2689 // are not allowed to be created from a phi node, and throw an error for those.
2690 const result_type_id = try self.resolveTypeId(ty);2690 const result_type_id = try self.resolveTypeId(ty);
26912691
2692 try self.func.body.emitRaw(self.spv.gpa, .OpPhi, 2 + @intCast(u16, incoming_blocks.items.len * 2)); // result type + result + variable/parent...2692 try self.func.body.emitRaw(self.spv.gpa, .OpPhi, 2 + @as(u16, @intCast(incoming_blocks.items.len * 2))); // result type + result + variable/parent...
2693 self.func.body.writeOperand(spec.IdResultType, result_type_id);2693 self.func.body.writeOperand(spec.IdResultType, result_type_id);
2694 self.func.body.writeOperand(spec.IdRef, result_id);2694 self.func.body.writeOperand(spec.IdRef, result_id);
26952695
...@@ -3105,7 +3105,7 @@ pub const DeclGen = struct {...@@ -3105,7 +3105,7 @@ pub const DeclGen = struct {
3105 while (case_i < num_cases) : (case_i += 1) {3105 while (case_i < num_cases) : (case_i += 1) {
3106 // SPIR-V needs a literal here, which' width depends on the case condition.3106 // SPIR-V needs a literal here, which' width depends on the case condition.
3107 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);3107 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
3108 const items = @ptrCast([]const Air.Inst.Ref, self.air.extra[case.end..][0..case.data.items_len]);3108 const items = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[case.end..][0..case.data.items_len]));
3109 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];3109 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
3110 extra_index = case.end + case.data.items_len + case_body.len;3110 extra_index = case.end + case.data.items_len + case_body.len;
31113111
...@@ -3116,7 +3116,7 @@ pub const DeclGen = struct {...@@ -3116,7 +3116,7 @@ pub const DeclGen = struct {
3116 return self.todo("switch on runtime value???", .{});3116 return self.todo("switch on runtime value???", .{});
3117 };3117 };
3118 const int_val = switch (cond_ty.zigTypeTag(mod)) {3118 const int_val = switch (cond_ty.zigTypeTag(mod)) {
3119 .Int => if (cond_ty.isSignedInt(mod)) @bitCast(u64, value.toSignedInt(mod)) else value.toUnsignedInt(mod),3119 .Int => if (cond_ty.isSignedInt(mod)) @as(u64, @bitCast(value.toSignedInt(mod))) else value.toUnsignedInt(mod),
3120 .Enum => blk: {3120 .Enum => blk: {
3121 // TODO: figure out of cond_ty is correct (something with enum literals)3121 // TODO: figure out of cond_ty is correct (something with enum literals)
3122 break :blk (try value.intFromEnum(cond_ty, mod)).toUnsignedInt(mod); // TODO: composite integer constants3122 break :blk (try value.intFromEnum(cond_ty, mod)).toUnsignedInt(mod); // TODO: composite integer constants
...@@ -3124,7 +3124,7 @@ pub const DeclGen = struct {...@@ -3124,7 +3124,7 @@ pub const DeclGen = struct {
3124 else => unreachable,3124 else => unreachable,
3125 };3125 };
3126 const int_lit: spec.LiteralContextDependentNumber = switch (cond_words) {3126 const int_lit: spec.LiteralContextDependentNumber = switch (cond_words) {
3127 1 => .{ .uint32 = @intCast(u32, int_val) },3127 1 => .{ .uint32 = @as(u32, @intCast(int_val)) },
3128 2 => .{ .uint64 = int_val },3128 2 => .{ .uint64 = int_val },
3129 else => unreachable,3129 else => unreachable,
3130 };3130 };
...@@ -3139,7 +3139,7 @@ pub const DeclGen = struct {...@@ -3139,7 +3139,7 @@ pub const DeclGen = struct {
3139 var case_i: u32 = 0;3139 var case_i: u32 = 0;
3140 while (case_i < num_cases) : (case_i += 1) {3140 while (case_i < num_cases) : (case_i += 1) {
3141 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);3141 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
3142 const items = @ptrCast([]const Air.Inst.Ref, self.air.extra[case.end..][0..case.data.items_len]);3142 const items = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[case.end..][0..case.data.items_len]));
3143 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];3143 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
3144 extra_index = case.end + case.data.items_len + case_body.len;3144 extra_index = case.end + case.data.items_len + case_body.len;
31453145
...@@ -3167,15 +3167,15 @@ pub const DeclGen = struct {...@@ -3167,15 +3167,15 @@ pub const DeclGen = struct {
3167 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;3167 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
3168 const extra = self.air.extraData(Air.Asm, ty_pl.payload);3168 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
31693169
3170 const is_volatile = @truncate(u1, extra.data.flags >> 31) != 0;3170 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
3171 const clobbers_len = @truncate(u31, extra.data.flags);3171 const clobbers_len = @as(u31, @truncate(extra.data.flags));
31723172
3173 if (!is_volatile and self.liveness.isUnused(inst)) return null;3173 if (!is_volatile and self.liveness.isUnused(inst)) return null;
31743174
3175 var extra_i: usize = extra.end;3175 var extra_i: usize = extra.end;
3176 const outputs = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra_i..][0..extra.data.outputs_len]);3176 const outputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]));
3177 extra_i += outputs.len;3177 extra_i += outputs.len;
3178 const inputs = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra_i..][0..extra.data.inputs_len]);3178 const inputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]));
3179 extra_i += inputs.len;3179 extra_i += inputs.len;
31803180
3181 if (outputs.len > 1) {3181 if (outputs.len > 1) {
...@@ -3297,7 +3297,7 @@ pub const DeclGen = struct {...@@ -3297,7 +3297,7 @@ pub const DeclGen = struct {
3297 const mod = self.module;3297 const mod = self.module;
3298 const pl_op = self.air.instructions.items(.data)[inst].pl_op;3298 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
3299 const extra = self.air.extraData(Air.Call, pl_op.payload);3299 const extra = self.air.extraData(Air.Call, pl_op.payload);
3300 const args = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra.end..][0..extra.data.args_len]);3300 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));
3301 const callee_ty = self.typeOf(pl_op.operand);3301 const callee_ty = self.typeOf(pl_op.operand);
3302 const zig_fn_ty = switch (callee_ty.zigTypeTag(mod)) {3302 const zig_fn_ty = switch (callee_ty.zigTypeTag(mod)) {
3303 .Fn => callee_ty,3303 .Fn => callee_ty,
src/codegen/spirv/Assembler.zig+12-12
...@@ -293,7 +293,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {...@@ -293,7 +293,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {
293 return self.fail(0, "{} is not a valid bit count for floats (expected 16, 32 or 64)", .{bits});293 return self.fail(0, "{} is not a valid bit count for floats (expected 16, 32 or 64)", .{bits});
294 },294 },
295 }295 }
296 break :blk try self.spv.resolve(.{ .float_type = .{ .bits = @intCast(u16, bits) } });296 break :blk try self.spv.resolve(.{ .float_type = .{ .bits = @as(u16, @intCast(bits)) } });
297 },297 },
298 .OpTypeVector => try self.spv.resolve(.{ .vector_type = .{298 .OpTypeVector => try self.spv.resolve(.{ .vector_type = .{
299 .component_type = try self.resolveTypeRef(operands[1].ref_id),299 .component_type = try self.resolveTypeRef(operands[1].ref_id),
...@@ -306,7 +306,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {...@@ -306,7 +306,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {
306 },306 },
307 .OpTypePointer => try self.spv.ptrType(307 .OpTypePointer => try self.spv.ptrType(
308 try self.resolveTypeRef(operands[2].ref_id),308 try self.resolveTypeRef(operands[2].ref_id),
309 @enumFromInt(spec.StorageClass, operands[1].value),309 @as(spec.StorageClass, @enumFromInt(operands[1].value)),
310 ),310 ),
311 .OpTypeFunction => blk: {311 .OpTypeFunction => blk: {
312 const param_operands = operands[2..];312 const param_operands = operands[2..];
...@@ -340,7 +340,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {...@@ -340,7 +340,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
340 else => switch (self.inst.opcode) {340 else => switch (self.inst.opcode) {
341 .OpEntryPoint => unreachable,341 .OpEntryPoint => unreachable,
342 .OpExecutionMode, .OpExecutionModeId => &self.spv.sections.execution_modes,342 .OpExecutionMode, .OpExecutionModeId => &self.spv.sections.execution_modes,
343 .OpVariable => switch (@enumFromInt(spec.StorageClass, operands[2].value)) {343 .OpVariable => switch (@as(spec.StorageClass, @enumFromInt(operands[2].value))) {
344 .Function => &self.func.prologue,344 .Function => &self.func.prologue,
345 else => {345 else => {
346 // This is currently disabled because global variables are required to be346 // This is currently disabled because global variables are required to be
...@@ -391,7 +391,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {...@@ -391,7 +391,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
391 }391 }
392392
393 const actual_word_count = section.instructions.items.len - first_word;393 const actual_word_count = section.instructions.items.len - first_word;
394 section.instructions.items[first_word] |= @as(u32, @intCast(u16, actual_word_count)) << 16 | @intFromEnum(self.inst.opcode);394 section.instructions.items[first_word] |= @as(u32, @as(u16, @intCast(actual_word_count))) << 16 | @intFromEnum(self.inst.opcode);
395395
396 if (maybe_result_id) |result| {396 if (maybe_result_id) |result| {
397 return AsmValue{ .value = result };397 return AsmValue{ .value = result };
...@@ -458,7 +458,7 @@ fn parseInstruction(self: *Assembler) !void {...@@ -458,7 +458,7 @@ fn parseInstruction(self: *Assembler) !void {
458 if (!entry.found_existing) {458 if (!entry.found_existing) {
459 entry.value_ptr.* = .just_declared;459 entry.value_ptr.* = .just_declared;
460 }460 }
461 break :blk @intCast(AsmValue.Ref, entry.index);461 break :blk @as(AsmValue.Ref, @intCast(entry.index));
462 } else null;462 } else null;
463463
464 const opcode_tok = self.currentToken();464 const opcode_tok = self.currentToken();
...@@ -613,7 +613,7 @@ fn parseRefId(self: *Assembler) !void {...@@ -613,7 +613,7 @@ fn parseRefId(self: *Assembler) !void {
613 entry.value_ptr.* = .unresolved_forward_reference;613 entry.value_ptr.* = .unresolved_forward_reference;
614 }614 }
615615
616 const index = @intCast(AsmValue.Ref, entry.index);616 const index = @as(AsmValue.Ref, @intCast(entry.index));
617 try self.inst.operands.append(self.gpa, .{ .ref_id = index });617 try self.inst.operands.append(self.gpa, .{ .ref_id = index });
618}618}
619619
...@@ -645,7 +645,7 @@ fn parseString(self: *Assembler) !void {...@@ -645,7 +645,7 @@ fn parseString(self: *Assembler) !void {
645 else645 else
646 text[1..];646 text[1..];
647647
648 const string_offset = @intCast(u32, self.inst.string_bytes.items.len);648 const string_offset = @as(u32, @intCast(self.inst.string_bytes.items.len));
649 try self.inst.string_bytes.ensureUnusedCapacity(self.gpa, literal.len + 1);649 try self.inst.string_bytes.ensureUnusedCapacity(self.gpa, literal.len + 1);
650 self.inst.string_bytes.appendSliceAssumeCapacity(literal);650 self.inst.string_bytes.appendSliceAssumeCapacity(literal);
651 self.inst.string_bytes.appendAssumeCapacity(0);651 self.inst.string_bytes.appendAssumeCapacity(0);
...@@ -693,18 +693,18 @@ fn parseContextDependentInt(self: *Assembler, signedness: std.builtin.Signedness...@@ -693,18 +693,18 @@ fn parseContextDependentInt(self: *Assembler, signedness: std.builtin.Signedness
693 const int = std.fmt.parseInt(i128, text, 0) catch break :invalid;693 const int = std.fmt.parseInt(i128, text, 0) catch break :invalid;
694 const min = switch (signedness) {694 const min = switch (signedness) {
695 .unsigned => 0,695 .unsigned => 0,
696 .signed => -(@as(i128, 1) << (@intCast(u7, width) - 1)),696 .signed => -(@as(i128, 1) << (@as(u7, @intCast(width)) - 1)),
697 };697 };
698 const max = (@as(i128, 1) << (@intCast(u7, width) - @intFromBool(signedness == .signed))) - 1;698 const max = (@as(i128, 1) << (@as(u7, @intCast(width)) - @intFromBool(signedness == .signed))) - 1;
699 if (int < min or int > max) {699 if (int < min or int > max) {
700 break :invalid;700 break :invalid;
701 }701 }
702702
703 // Note, we store the sign-extended version here.703 // Note, we store the sign-extended version here.
704 if (width <= @bitSizeOf(spec.Word)) {704 if (width <= @bitSizeOf(spec.Word)) {
705 try self.inst.operands.append(self.gpa, .{ .literal32 = @truncate(u32, @bitCast(u128, int)) });705 try self.inst.operands.append(self.gpa, .{ .literal32 = @as(u32, @truncate(@as(u128, @bitCast(int)))) });
706 } else {706 } else {
707 try self.inst.operands.append(self.gpa, .{ .literal64 = @truncate(u64, @bitCast(u128, int)) });707 try self.inst.operands.append(self.gpa, .{ .literal64 = @as(u64, @truncate(@as(u128, @bitCast(int)))) });
708 }708 }
709 return;709 return;
710 }710 }
...@@ -725,7 +725,7 @@ fn parseContextDependentFloat(self: *Assembler, comptime width: u16) !void {...@@ -725,7 +725,7 @@ fn parseContextDependentFloat(self: *Assembler, comptime width: u16) !void {
725 return self.fail(tok.start, "'{s}' is not a valid {}-bit float literal", .{ text, width });725 return self.fail(tok.start, "'{s}' is not a valid {}-bit float literal", .{ text, width });
726 };726 };
727727
728 const float_bits = @bitCast(Int, value);728 const float_bits = @as(Int, @bitCast(value));
729 if (width <= @bitSizeOf(spec.Word)) {729 if (width <= @bitSizeOf(spec.Word)) {
730 try self.inst.operands.append(self.gpa, .{ .literal32 = float_bits });730 try self.inst.operands.append(self.gpa, .{ .literal32 = float_bits });
731 } else {731 } else {
src/codegen/spirv/Cache.zig+62-62
...@@ -158,16 +158,16 @@ const Tag = enum {...@@ -158,16 +158,16 @@ const Tag = enum {
158 high: u32,158 high: u32,
159159
160 fn encode(value: f64) Float64 {160 fn encode(value: f64) Float64 {
161 const bits = @bitCast(u64, value);161 const bits = @as(u64, @bitCast(value));
162 return .{162 return .{
163 .low = @truncate(u32, bits),163 .low = @as(u32, @truncate(bits)),
164 .high = @truncate(u32, bits >> 32),164 .high = @as(u32, @truncate(bits >> 32)),
165 };165 };
166 }166 }
167167
168 fn decode(self: Float64) f64 {168 fn decode(self: Float64) f64 {
169 const bits = @as(u64, self.low) | (@as(u64, self.high) << 32);169 const bits = @as(u64, self.low) | (@as(u64, self.high) << 32);
170 return @bitCast(f64, bits);170 return @as(f64, @bitCast(bits));
171 }171 }
172 };172 };
173173
...@@ -189,8 +189,8 @@ const Tag = enum {...@@ -189,8 +189,8 @@ const Tag = enum {
189 fn encode(ty: Ref, value: u64) Int64 {189 fn encode(ty: Ref, value: u64) Int64 {
190 return .{190 return .{
191 .ty = ty,191 .ty = ty,
192 .low = @truncate(u32, value),192 .low = @as(u32, @truncate(value)),
193 .high = @truncate(u32, value >> 32),193 .high = @as(u32, @truncate(value >> 32)),
194 };194 };
195 }195 }
196196
...@@ -207,13 +207,13 @@ const Tag = enum {...@@ -207,13 +207,13 @@ const Tag = enum {
207 fn encode(ty: Ref, value: i64) Int64 {207 fn encode(ty: Ref, value: i64) Int64 {
208 return .{208 return .{
209 .ty = ty,209 .ty = ty,
210 .low = @truncate(u32, @bitCast(u64, value)),210 .low = @as(u32, @truncate(@as(u64, @bitCast(value)))),
211 .high = @truncate(u32, @bitCast(u64, value) >> 32),211 .high = @as(u32, @truncate(@as(u64, @bitCast(value)) >> 32)),
212 };212 };
213 }213 }
214214
215 fn decode(self: Int64) i64 {215 fn decode(self: Int64) i64 {
216 return @bitCast(i64, @as(u64, self.low) | (@as(u64, self.high) << 32));216 return @as(i64, @bitCast(@as(u64, self.low) | (@as(u64, self.high) << 32)));
217 }217 }
218 };218 };
219};219};
...@@ -305,21 +305,21 @@ pub const Key = union(enum) {...@@ -305,21 +305,21 @@ pub const Key = union(enum) {
305 /// Turns this value into the corresponding 32-bit literal, 2s complement signed.305 /// Turns this value into the corresponding 32-bit literal, 2s complement signed.
306 fn toBits32(self: Int) u32 {306 fn toBits32(self: Int) u32 {
307 return switch (self.value) {307 return switch (self.value) {
308 .uint64 => |val| @intCast(u32, val),308 .uint64 => |val| @as(u32, @intCast(val)),
309 .int64 => |val| if (val < 0) @bitCast(u32, @intCast(i32, val)) else @intCast(u32, val),309 .int64 => |val| if (val < 0) @as(u32, @bitCast(@as(i32, @intCast(val)))) else @as(u32, @intCast(val)),
310 };310 };
311 }311 }
312312
313 fn toBits64(self: Int) u64 {313 fn toBits64(self: Int) u64 {
314 return switch (self.value) {314 return switch (self.value) {
315 .uint64 => |val| val,315 .uint64 => |val| val,
316 .int64 => |val| @bitCast(u64, val),316 .int64 => |val| @as(u64, @bitCast(val)),
317 };317 };
318 }318 }
319319
320 fn to(self: Int, comptime T: type) T {320 fn to(self: Int, comptime T: type) T {
321 return switch (self.value) {321 return switch (self.value) {
322 inline else => |val| @intCast(T, val),322 inline else => |val| @as(T, @intCast(val)),
323 };323 };
324 }324 }
325 };325 };
...@@ -357,9 +357,9 @@ pub const Key = union(enum) {...@@ -357,9 +357,9 @@ pub const Key = union(enum) {
357 .float => |float| {357 .float => |float| {
358 std.hash.autoHash(&hasher, float.ty);358 std.hash.autoHash(&hasher, float.ty);
359 switch (float.value) {359 switch (float.value) {
360 .float16 => |value| std.hash.autoHash(&hasher, @bitCast(u16, value)),360 .float16 => |value| std.hash.autoHash(&hasher, @as(u16, @bitCast(value))),
361 .float32 => |value| std.hash.autoHash(&hasher, @bitCast(u32, value)),361 .float32 => |value| std.hash.autoHash(&hasher, @as(u32, @bitCast(value))),
362 .float64 => |value| std.hash.autoHash(&hasher, @bitCast(u64, value)),362 .float64 => |value| std.hash.autoHash(&hasher, @as(u64, @bitCast(value))),
363 }363 }
364 },364 },
365 .function_type => |func| {365 .function_type => |func| {
...@@ -379,7 +379,7 @@ pub const Key = union(enum) {...@@ -379,7 +379,7 @@ pub const Key = union(enum) {
379 },379 },
380 inline else => |key| std.hash.autoHash(&hasher, key),380 inline else => |key| std.hash.autoHash(&hasher, key),
381 }381 }
382 return @truncate(u32, hasher.final());382 return @as(u32, @truncate(hasher.final()));
383 }383 }
384384
385 fn eql(a: Key, b: Key) bool {385 fn eql(a: Key, b: Key) bool {
...@@ -411,7 +411,7 @@ pub const Key = union(enum) {...@@ -411,7 +411,7 @@ pub const Key = union(enum) {
411411
412 pub fn eql(ctx: @This(), a: Key, b_void: void, b_index: usize) bool {412 pub fn eql(ctx: @This(), a: Key, b_void: void, b_index: usize) bool {
413 _ = b_void;413 _ = b_void;
414 return ctx.self.lookup(@enumFromInt(Ref, b_index)).eql(a);414 return ctx.self.lookup(@as(Ref, @enumFromInt(b_index))).eql(a);
415 }415 }
416416
417 pub fn hash(ctx: @This(), a: Key) u32 {417 pub fn hash(ctx: @This(), a: Key) u32 {
...@@ -445,7 +445,7 @@ pub fn materialize(self: *const Self, spv: *Module) !Section {...@@ -445,7 +445,7 @@ pub fn materialize(self: *const Self, spv: *Module) !Section {
445 var section = Section{};445 var section = Section{};
446 errdefer section.deinit(spv.gpa);446 errdefer section.deinit(spv.gpa);
447 for (self.items.items(.result_id), 0..) |result_id, index| {447 for (self.items.items(.result_id), 0..) |result_id, index| {
448 try self.emit(spv, result_id, @enumFromInt(Ref, index), &section);448 try self.emit(spv, result_id, @as(Ref, @enumFromInt(index)), &section);
449 }449 }
450 return section;450 return section;
451}451}
...@@ -534,7 +534,7 @@ fn emit(...@@ -534,7 +534,7 @@ fn emit(
534 }534 }
535 for (struct_type.memberNames(), 0..) |member_name, i| {535 for (struct_type.memberNames(), 0..) |member_name, i| {
536 if (self.getString(member_name)) |name| {536 if (self.getString(member_name)) |name| {
537 try spv.memberDebugName(result_id, @intCast(u32, i), "{s}", .{name});537 try spv.memberDebugName(result_id, @as(u32, @intCast(i)), "{s}", .{name});
538 }538 }
539 }539 }
540 // TODO: Decorations?540 // TODO: Decorations?
...@@ -557,7 +557,7 @@ fn emit(...@@ -557,7 +557,7 @@ fn emit(
557 .float => |float| {557 .float => |float| {
558 const ty_id = self.resultId(float.ty);558 const ty_id = self.resultId(float.ty);
559 const lit: Lit = switch (float.value) {559 const lit: Lit = switch (float.value) {
560 .float16 => |value| .{ .uint32 = @bitCast(u16, value) },560 .float16 => |value| .{ .uint32 = @as(u16, @bitCast(value)) },
561 .float32 => |value| .{ .float32 = value },561 .float32 => |value| .{ .float32 = value },
562 .float64 => |value| .{ .float64 = value },562 .float64 => |value| .{ .float64 = value },
563 };563 };
...@@ -603,7 +603,7 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {...@@ -603,7 +603,7 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
603 const adapter: Key.Adapter = .{ .self = self };603 const adapter: Key.Adapter = .{ .self = self };
604 const entry = try self.map.getOrPutAdapted(spv.gpa, key, adapter);604 const entry = try self.map.getOrPutAdapted(spv.gpa, key, adapter);
605 if (entry.found_existing) {605 if (entry.found_existing) {
606 return @enumFromInt(Ref, entry.index);606 return @as(Ref, @enumFromInt(entry.index));
607 }607 }
608 const result_id = spv.allocId();608 const result_id = spv.allocId();
609 const item: Item = switch (key) {609 const item: Item = switch (key) {
...@@ -640,10 +640,10 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {...@@ -640,10 +640,10 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
640 },640 },
641 .function_type => |function| blk: {641 .function_type => |function| blk: {
642 const extra = try self.addExtra(spv, Tag.FunctionType{642 const extra = try self.addExtra(spv, Tag.FunctionType{
643 .param_len = @intCast(u32, function.parameters.len),643 .param_len = @as(u32, @intCast(function.parameters.len)),
644 .return_type = function.return_type,644 .return_type = function.return_type,
645 });645 });
646 try self.extra.appendSlice(spv.gpa, @ptrCast([]const u32, function.parameters));646 try self.extra.appendSlice(spv.gpa, @as([]const u32, @ptrCast(function.parameters)));
647 break :blk .{647 break :blk .{
648 .tag = .type_function,648 .tag = .type_function,
649 .result_id = result_id,649 .result_id = result_id,
...@@ -678,12 +678,12 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {...@@ -678,12 +678,12 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
678 .struct_type => |struct_type| blk: {678 .struct_type => |struct_type| blk: {
679 const extra = try self.addExtra(spv, Tag.SimpleStructType{679 const extra = try self.addExtra(spv, Tag.SimpleStructType{
680 .name = struct_type.name,680 .name = struct_type.name,
681 .members_len = @intCast(u32, struct_type.member_types.len),681 .members_len = @as(u32, @intCast(struct_type.member_types.len)),
682 });682 });
683 try self.extra.appendSlice(spv.gpa, @ptrCast([]const u32, struct_type.member_types));683 try self.extra.appendSlice(spv.gpa, @as([]const u32, @ptrCast(struct_type.member_types)));
684684
685 if (struct_type.member_names) |member_names| {685 if (struct_type.member_names) |member_names| {
686 try self.extra.appendSlice(spv.gpa, @ptrCast([]const u32, member_names));686 try self.extra.appendSlice(spv.gpa, @as([]const u32, @ptrCast(member_names)));
687 break :blk Item{687 break :blk Item{
688 .tag = .type_struct_simple_with_member_names,688 .tag = .type_struct_simple_with_member_names,
689 .result_id = result_id,689 .result_id = result_id,
...@@ -721,7 +721,7 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {...@@ -721,7 +721,7 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
721 .result_id = result_id,721 .result_id = result_id,
722 .data = try self.addExtra(spv, Tag.UInt32{722 .data = try self.addExtra(spv, Tag.UInt32{
723 .ty = int.ty,723 .ty = int.ty,
724 .value = @intCast(u32, val),724 .value = @as(u32, @intCast(val)),
725 }),725 }),
726 };726 };
727 } else if (val >= std.math.minInt(i32) and val <= std.math.maxInt(i32)) {727 } else if (val >= std.math.minInt(i32) and val <= std.math.maxInt(i32)) {
...@@ -730,20 +730,20 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {...@@ -730,20 +730,20 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
730 .result_id = result_id,730 .result_id = result_id,
731 .data = try self.addExtra(spv, Tag.Int32{731 .data = try self.addExtra(spv, Tag.Int32{
732 .ty = int.ty,732 .ty = int.ty,
733 .value = @intCast(i32, val),733 .value = @as(i32, @intCast(val)),
734 }),734 }),
735 };735 };
736 } else if (val < 0) {736 } else if (val < 0) {
737 break :blk .{737 break :blk .{
738 .tag = .int_large,738 .tag = .int_large,
739 .result_id = result_id,739 .result_id = result_id,
740 .data = try self.addExtra(spv, Tag.Int64.encode(int.ty, @intCast(i64, val))),740 .data = try self.addExtra(spv, Tag.Int64.encode(int.ty, @as(i64, @intCast(val)))),
741 };741 };
742 } else {742 } else {
743 break :blk .{743 break :blk .{
744 .tag = .uint_large,744 .tag = .uint_large,
745 .result_id = result_id,745 .result_id = result_id,
746 .data = try self.addExtra(spv, Tag.UInt64.encode(int.ty, @intCast(u64, val))),746 .data = try self.addExtra(spv, Tag.UInt64.encode(int.ty, @as(u64, @intCast(val)))),
747 };747 };
748 }748 }
749 },749 },
...@@ -753,12 +753,12 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {...@@ -753,12 +753,12 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
753 16 => .{753 16 => .{
754 .tag = .float16,754 .tag = .float16,
755 .result_id = result_id,755 .result_id = result_id,
756 .data = @bitCast(u16, float.value.float16),756 .data = @as(u16, @bitCast(float.value.float16)),
757 },757 },
758 32 => .{758 32 => .{
759 .tag = .float32,759 .tag = .float32,
760 .result_id = result_id,760 .result_id = result_id,
761 .data = @bitCast(u32, float.value.float32),761 .data = @as(u32, @bitCast(float.value.float32)),
762 },762 },
763 64 => .{763 64 => .{
764 .tag = .float64,764 .tag = .float64,
...@@ -788,7 +788,7 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {...@@ -788,7 +788,7 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
788 };788 };
789 try self.items.append(spv.gpa, item);789 try self.items.append(spv.gpa, item);
790790
791 return @enumFromInt(Ref, entry.index);791 return @as(Ref, @enumFromInt(entry.index));
792}792}
793793
794/// Turn a Ref back into a Key.794/// Turn a Ref back into a Key.
...@@ -797,20 +797,20 @@ pub fn lookup(self: *const Self, ref: Ref) Key {...@@ -797,20 +797,20 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
797 const item = self.items.get(@intFromEnum(ref));797 const item = self.items.get(@intFromEnum(ref));
798 const data = item.data;798 const data = item.data;
799 return switch (item.tag) {799 return switch (item.tag) {
800 .type_simple => switch (@enumFromInt(Tag.SimpleType, data)) {800 .type_simple => switch (@as(Tag.SimpleType, @enumFromInt(data))) {
801 .void => .void_type,801 .void => .void_type,
802 .bool => .bool_type,802 .bool => .bool_type,
803 },803 },
804 .type_int_signed => .{ .int_type = .{804 .type_int_signed => .{ .int_type = .{
805 .signedness = .signed,805 .signedness = .signed,
806 .bits = @intCast(u16, data),806 .bits = @as(u16, @intCast(data)),
807 } },807 } },
808 .type_int_unsigned => .{ .int_type = .{808 .type_int_unsigned => .{ .int_type = .{
809 .signedness = .unsigned,809 .signedness = .unsigned,
810 .bits = @intCast(u16, data),810 .bits = @as(u16, @intCast(data)),
811 } },811 } },
812 .type_float => .{ .float_type = .{812 .type_float => .{ .float_type = .{
813 .bits = @intCast(u16, data),813 .bits = @as(u16, @intCast(data)),
814 } },814 } },
815 .type_vector => .{ .vector_type = self.extraData(Tag.VectorType, data) },815 .type_vector => .{ .vector_type = self.extraData(Tag.VectorType, data) },
816 .type_array => .{ .array_type = self.extraData(Tag.ArrayType, data) },816 .type_array => .{ .array_type = self.extraData(Tag.ArrayType, data) },
...@@ -819,26 +819,26 @@ pub fn lookup(self: *const Self, ref: Ref) Key {...@@ -819,26 +819,26 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
819 return .{819 return .{
820 .function_type = .{820 .function_type = .{
821 .return_type = payload.data.return_type,821 .return_type = payload.data.return_type,
822 .parameters = @ptrCast([]const Ref, self.extra.items[payload.trail..][0..payload.data.param_len]),822 .parameters = @as([]const Ref, @ptrCast(self.extra.items[payload.trail..][0..payload.data.param_len])),
823 },823 },
824 };824 };
825 },825 },
826 .type_ptr_generic => .{826 .type_ptr_generic => .{
827 .ptr_type = .{827 .ptr_type = .{
828 .storage_class = .Generic,828 .storage_class = .Generic,
829 .child_type = @enumFromInt(Ref, data),829 .child_type = @as(Ref, @enumFromInt(data)),
830 },830 },
831 },831 },
832 .type_ptr_crosswgp => .{832 .type_ptr_crosswgp => .{
833 .ptr_type = .{833 .ptr_type = .{
834 .storage_class = .CrossWorkgroup,834 .storage_class = .CrossWorkgroup,
835 .child_type = @enumFromInt(Ref, data),835 .child_type = @as(Ref, @enumFromInt(data)),
836 },836 },
837 },837 },
838 .type_ptr_function => .{838 .type_ptr_function => .{
839 .ptr_type = .{839 .ptr_type = .{
840 .storage_class = .Function,840 .storage_class = .Function,
841 .child_type = @enumFromInt(Ref, data),841 .child_type = @as(Ref, @enumFromInt(data)),
842 },842 },
843 },843 },
844 .type_ptr_simple => {844 .type_ptr_simple => {
...@@ -852,7 +852,7 @@ pub fn lookup(self: *const Self, ref: Ref) Key {...@@ -852,7 +852,7 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
852 },852 },
853 .type_struct_simple => {853 .type_struct_simple => {
854 const payload = self.extraDataTrail(Tag.SimpleStructType, data);854 const payload = self.extraDataTrail(Tag.SimpleStructType, data);
855 const member_types = @ptrCast([]const Ref, self.extra.items[payload.trail..][0..payload.data.members_len]);855 const member_types = @as([]const Ref, @ptrCast(self.extra.items[payload.trail..][0..payload.data.members_len]));
856 return .{856 return .{
857 .struct_type = .{857 .struct_type = .{
858 .name = payload.data.name,858 .name = payload.data.name,
...@@ -864,8 +864,8 @@ pub fn lookup(self: *const Self, ref: Ref) Key {...@@ -864,8 +864,8 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
864 .type_struct_simple_with_member_names => {864 .type_struct_simple_with_member_names => {
865 const payload = self.extraDataTrail(Tag.SimpleStructType, data);865 const payload = self.extraDataTrail(Tag.SimpleStructType, data);
866 const trailing = self.extra.items[payload.trail..];866 const trailing = self.extra.items[payload.trail..];
867 const member_types = @ptrCast([]const Ref, trailing[0..payload.data.members_len]);867 const member_types = @as([]const Ref, @ptrCast(trailing[0..payload.data.members_len]));
868 const member_names = @ptrCast([]const String, trailing[payload.data.members_len..][0..payload.data.members_len]);868 const member_names = @as([]const String, @ptrCast(trailing[payload.data.members_len..][0..payload.data.members_len]));
869 return .{869 return .{
870 .struct_type = .{870 .struct_type = .{
871 .name = payload.data.name,871 .name = payload.data.name,
...@@ -876,11 +876,11 @@ pub fn lookup(self: *const Self, ref: Ref) Key {...@@ -876,11 +876,11 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
876 },876 },
877 .float16 => .{ .float = .{877 .float16 => .{ .float = .{
878 .ty = self.get(.{ .float_type = .{ .bits = 16 } }),878 .ty = self.get(.{ .float_type = .{ .bits = 16 } }),
879 .value = .{ .float16 = @bitCast(f16, @intCast(u16, data)) },879 .value = .{ .float16 = @as(f16, @bitCast(@as(u16, @intCast(data)))) },
880 } },880 } },
881 .float32 => .{ .float = .{881 .float32 => .{ .float = .{
882 .ty = self.get(.{ .float_type = .{ .bits = 32 } }),882 .ty = self.get(.{ .float_type = .{ .bits = 32 } }),
883 .value = .{ .float32 = @bitCast(f32, data) },883 .value = .{ .float32 = @as(f32, @bitCast(data)) },
884 } },884 } },
885 .float64 => .{ .float = .{885 .float64 => .{ .float = .{
886 .ty = self.get(.{ .float_type = .{ .bits = 64 } }),886 .ty = self.get(.{ .float_type = .{ .bits = 64 } }),
...@@ -923,17 +923,17 @@ pub fn lookup(self: *const Self, ref: Ref) Key {...@@ -923,17 +923,17 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
923 } };923 } };
924 },924 },
925 .undef => .{ .undef = .{925 .undef => .{ .undef = .{
926 .ty = @enumFromInt(Ref, data),926 .ty = @as(Ref, @enumFromInt(data)),
927 } },927 } },
928 .null => .{ .null = .{928 .null => .{ .null = .{
929 .ty = @enumFromInt(Ref, data),929 .ty = @as(Ref, @enumFromInt(data)),
930 } },930 } },
931 .bool_true => .{ .bool = .{931 .bool_true => .{ .bool = .{
932 .ty = @enumFromInt(Ref, data),932 .ty = @as(Ref, @enumFromInt(data)),
933 .value = true,933 .value = true,
934 } },934 } },
935 .bool_false => .{ .bool = .{935 .bool_false => .{ .bool = .{
936 .ty = @enumFromInt(Ref, data),936 .ty = @as(Ref, @enumFromInt(data)),
937 .value = false,937 .value = false,
938 } },938 } },
939 };939 };
...@@ -949,7 +949,7 @@ pub fn resultId(self: Self, ref: Ref) IdResult {...@@ -949,7 +949,7 @@ pub fn resultId(self: Self, ref: Ref) IdResult {
949fn get(self: *const Self, key: Key) Ref {949fn get(self: *const Self, key: Key) Ref {
950 const adapter: Key.Adapter = .{ .self = self };950 const adapter: Key.Adapter = .{ .self = self };
951 const index = self.map.getIndexAdapted(key, adapter).?;951 const index = self.map.getIndexAdapted(key, adapter).?;
952 return @enumFromInt(Ref, index);952 return @as(Ref, @enumFromInt(index));
953}953}
954954
955fn addExtra(self: *Self, spv: *Module, extra: anytype) !u32 {955fn addExtra(self: *Self, spv: *Module, extra: anytype) !u32 {
...@@ -959,12 +959,12 @@ fn addExtra(self: *Self, spv: *Module, extra: anytype) !u32 {...@@ -959,12 +959,12 @@ fn addExtra(self: *Self, spv: *Module, extra: anytype) !u32 {
959}959}
960960
961fn addExtraAssumeCapacity(self: *Self, extra: anytype) !u32 {961fn addExtraAssumeCapacity(self: *Self, extra: anytype) !u32 {
962 const payload_offset = @intCast(u32, self.extra.items.len);962 const payload_offset = @as(u32, @intCast(self.extra.items.len));
963 inline for (@typeInfo(@TypeOf(extra)).Struct.fields) |field| {963 inline for (@typeInfo(@TypeOf(extra)).Struct.fields) |field| {
964 const field_val = @field(extra, field.name);964 const field_val = @field(extra, field.name);
965 const word = switch (field.type) {965 const word = switch (field.type) {
966 u32 => field_val,966 u32 => field_val,
967 i32 => @bitCast(u32, field_val),967 i32 => @as(u32, @bitCast(field_val)),
968 Ref => @intFromEnum(field_val),968 Ref => @intFromEnum(field_val),
969 StorageClass => @intFromEnum(field_val),969 StorageClass => @intFromEnum(field_val),
970 String => @intFromEnum(field_val),970 String => @intFromEnum(field_val),
...@@ -986,16 +986,16 @@ fn extraDataTrail(self: Self, comptime T: type, offset: u32) struct { data: T, t...@@ -986,16 +986,16 @@ fn extraDataTrail(self: Self, comptime T: type, offset: u32) struct { data: T, t
986 const word = self.extra.items[offset + i];986 const word = self.extra.items[offset + i];
987 @field(result, field.name) = switch (field.type) {987 @field(result, field.name) = switch (field.type) {
988 u32 => word,988 u32 => word,
989 i32 => @bitCast(i32, word),989 i32 => @as(i32, @bitCast(word)),
990 Ref => @enumFromInt(Ref, word),990 Ref => @as(Ref, @enumFromInt(word)),
991 StorageClass => @enumFromInt(StorageClass, word),991 StorageClass => @as(StorageClass, @enumFromInt(word)),
992 String => @enumFromInt(String, word),992 String => @as(String, @enumFromInt(word)),
993 else => @compileError("Invalid type: " ++ @typeName(field.type)),993 else => @compileError("Invalid type: " ++ @typeName(field.type)),
994 };994 };
995 }995 }
996 return .{996 return .{
997 .data = result,997 .data = result,
998 .trail = offset + @intCast(u32, fields.len),998 .trail = offset + @as(u32, @intCast(fields.len)),
999 };999 };
1000}1000}
10011001
...@@ -1017,7 +1017,7 @@ pub const String = enum(u32) {...@@ -1017,7 +1017,7 @@ pub const String = enum(u32) {
1017 _ = ctx;1017 _ = ctx;
1018 var hasher = std.hash.Wyhash.init(0);1018 var hasher = std.hash.Wyhash.init(0);
1019 hasher.update(a);1019 hasher.update(a);
1020 return @truncate(u32, hasher.final());1020 return @as(u32, @truncate(hasher.final()));
1021 }1021 }
1022 };1022 };
1023};1023};
...@@ -1032,10 +1032,10 @@ pub fn addString(self: *Self, spv: *Module, str: []const u8) !String {...@@ -1032,10 +1032,10 @@ pub fn addString(self: *Self, spv: *Module, str: []const u8) !String {
1032 try self.string_bytes.ensureUnusedCapacity(spv.gpa, 1 + str.len);1032 try self.string_bytes.ensureUnusedCapacity(spv.gpa, 1 + str.len);
1033 self.string_bytes.appendSliceAssumeCapacity(str);1033 self.string_bytes.appendSliceAssumeCapacity(str);
1034 self.string_bytes.appendAssumeCapacity(0);1034 self.string_bytes.appendAssumeCapacity(0);
1035 entry.value_ptr.* = @intCast(u32, offset);1035 entry.value_ptr.* = @as(u32, @intCast(offset));
1036 }1036 }
10371037
1038 return @enumFromInt(String, entry.index);1038 return @as(String, @enumFromInt(entry.index));
1039}1039}
10401040
1041pub fn getString(self: *const Self, ref: String) ?[]const u8 {1041pub fn getString(self: *const Self, ref: String) ?[]const u8 {
src/codegen/spirv/Module.zig+7-7
...@@ -451,8 +451,8 @@ pub fn constInt(self: *Module, ty_ref: CacheRef, value: anytype) !IdRef {...@@ -451,8 +451,8 @@ pub fn constInt(self: *Module, ty_ref: CacheRef, value: anytype) !IdRef {
451 return try self.resolveId(.{ .int = .{451 return try self.resolveId(.{ .int = .{
452 .ty = ty_ref,452 .ty = ty_ref,
453 .value = switch (ty.signedness) {453 .value = switch (ty.signedness) {
454 .signed => Value{ .int64 = @intCast(i64, value) },454 .signed => Value{ .int64 = @as(i64, @intCast(value)) },
455 .unsigned => Value{ .uint64 = @intCast(u64, value) },455 .unsigned => Value{ .uint64 = @as(u64, @intCast(value)) },
456 },456 },
457 } });457 } });
458}458}
...@@ -516,7 +516,7 @@ pub fn allocDecl(self: *Module, kind: DeclKind) !Decl.Index {...@@ -516,7 +516,7 @@ pub fn allocDecl(self: *Module, kind: DeclKind) !Decl.Index {
516 .begin_dep = undefined,516 .begin_dep = undefined,
517 .end_dep = undefined,517 .end_dep = undefined,
518 });518 });
519 const index = @enumFromInt(Decl.Index, @intCast(u32, self.decls.items.len - 1));519 const index = @as(Decl.Index, @enumFromInt(@as(u32, @intCast(self.decls.items.len - 1))));
520 switch (kind) {520 switch (kind) {
521 .func => {},521 .func => {},
522 // If the decl represents a global, also allocate a global node.522 // If the decl represents a global, also allocate a global node.
...@@ -540,9 +540,9 @@ pub fn globalPtr(self: *Module, index: Decl.Index) ?*Global {...@@ -540,9 +540,9 @@ pub fn globalPtr(self: *Module, index: Decl.Index) ?*Global {
540540
541/// Declare ALL dependencies for a decl.541/// Declare ALL dependencies for a decl.
542pub fn declareDeclDeps(self: *Module, decl_index: Decl.Index, deps: []const Decl.Index) !void {542pub fn declareDeclDeps(self: *Module, decl_index: Decl.Index, deps: []const Decl.Index) !void {
543 const begin_dep = @intCast(u32, self.decl_deps.items.len);543 const begin_dep = @as(u32, @intCast(self.decl_deps.items.len));
544 try self.decl_deps.appendSlice(self.gpa, deps);544 try self.decl_deps.appendSlice(self.gpa, deps);
545 const end_dep = @intCast(u32, self.decl_deps.items.len);545 const end_dep = @as(u32, @intCast(self.decl_deps.items.len));
546546
547 const decl = self.declPtr(decl_index);547 const decl = self.declPtr(decl_index);
548 decl.begin_dep = begin_dep;548 decl.begin_dep = begin_dep;
...@@ -550,13 +550,13 @@ pub fn declareDeclDeps(self: *Module, decl_index: Decl.Index, deps: []const Decl...@@ -550,13 +550,13 @@ pub fn declareDeclDeps(self: *Module, decl_index: Decl.Index, deps: []const Decl
550}550}
551551
552pub fn beginGlobal(self: *Module) u32 {552pub fn beginGlobal(self: *Module) u32 {
553 return @intCast(u32, self.globals.section.instructions.items.len);553 return @as(u32, @intCast(self.globals.section.instructions.items.len));
554}554}
555555
556pub fn endGlobal(self: *Module, global_index: Decl.Index, begin_inst: u32) void {556pub fn endGlobal(self: *Module, global_index: Decl.Index, begin_inst: u32) void {
557 const global = self.globalPtr(global_index).?;557 const global = self.globalPtr(global_index).?;
558 global.begin_inst = begin_inst;558 global.begin_inst = begin_inst;
559 global.end_inst = @intCast(u32, self.globals.section.instructions.items.len);559 global.end_inst = @as(u32, @intCast(self.globals.section.instructions.items.len));
560}560}
561561
562pub fn declareEntryPoint(self: *Module, decl_index: Decl.Index, name: []const u8) !void {562pub fn declareEntryPoint(self: *Module, decl_index: Decl.Index, name: []const u8) !void {
src/codegen/spirv/Section.zig+15-15
...@@ -50,7 +50,7 @@ pub fn emitRaw(...@@ -50,7 +50,7 @@ pub fn emitRaw(
50) !void {50) !void {
51 const word_count = 1 + operand_words;51 const word_count = 1 + operand_words;
52 try section.instructions.ensureUnusedCapacity(allocator, word_count);52 try section.instructions.ensureUnusedCapacity(allocator, word_count);
53 section.writeWord((@intCast(Word, word_count << 16)) | @intFromEnum(opcode));53 section.writeWord((@as(Word, @intCast(word_count << 16))) | @intFromEnum(opcode));
54}54}
5555
56pub fn emit(56pub fn emit(
...@@ -61,7 +61,7 @@ pub fn emit(...@@ -61,7 +61,7 @@ pub fn emit(
61) !void {61) !void {
62 const word_count = instructionSize(opcode, operands);62 const word_count = instructionSize(opcode, operands);
63 try section.instructions.ensureUnusedCapacity(allocator, word_count);63 try section.instructions.ensureUnusedCapacity(allocator, word_count);
64 section.writeWord(@intCast(Word, word_count << 16) | @intFromEnum(opcode));64 section.writeWord(@as(Word, @intCast(word_count << 16)) | @intFromEnum(opcode));
65 section.writeOperands(opcode.Operands(), operands);65 section.writeOperands(opcode.Operands(), operands);
66}66}
6767
...@@ -94,8 +94,8 @@ pub fn writeWords(section: *Section, words: []const Word) void {...@@ -94,8 +94,8 @@ pub fn writeWords(section: *Section, words: []const Word) void {
9494
95pub fn writeDoubleWord(section: *Section, dword: DoubleWord) void {95pub fn writeDoubleWord(section: *Section, dword: DoubleWord) void {
96 section.writeWords(&.{96 section.writeWords(&.{
97 @truncate(Word, dword),97 @as(Word, @truncate(dword)),
98 @truncate(Word, dword >> @bitSizeOf(Word)),98 @as(Word, @truncate(dword >> @bitSizeOf(Word))),
99 });99 });
100}100}
101101
...@@ -145,7 +145,7 @@ pub fn writeOperand(section: *Section, comptime Operand: type, operand: Operand)...@@ -145,7 +145,7 @@ pub fn writeOperand(section: *Section, comptime Operand: type, operand: Operand)
145 },145 },
146 .Struct => |info| {146 .Struct => |info| {
147 if (info.layout == .Packed) {147 if (info.layout == .Packed) {
148 section.writeWord(@bitCast(Word, operand));148 section.writeWord(@as(Word, @bitCast(operand)));
149 } else {149 } else {
150 section.writeExtendedMask(Operand, operand);150 section.writeExtendedMask(Operand, operand);
151 }151 }
...@@ -166,7 +166,7 @@ fn writeString(section: *Section, str: []const u8) void {...@@ -166,7 +166,7 @@ fn writeString(section: *Section, str: []const u8) void {
166166
167 var j: usize = 0;167 var j: usize = 0;
168 while (j < @sizeOf(Word) and i + j < str.len) : (j += 1) {168 while (j < @sizeOf(Word) and i + j < str.len) : (j += 1) {
169 word |= @as(Word, str[i + j]) << @intCast(Log2Word, j * @bitSizeOf(u8));169 word |= @as(Word, str[i + j]) << @as(Log2Word, @intCast(j * @bitSizeOf(u8)));
170 }170 }
171171
172 section.instructions.appendAssumeCapacity(word);172 section.instructions.appendAssumeCapacity(word);
...@@ -175,12 +175,12 @@ fn writeString(section: *Section, str: []const u8) void {...@@ -175,12 +175,12 @@ fn writeString(section: *Section, str: []const u8) void {
175175
176fn writeContextDependentNumber(section: *Section, operand: spec.LiteralContextDependentNumber) void {176fn writeContextDependentNumber(section: *Section, operand: spec.LiteralContextDependentNumber) void {
177 switch (operand) {177 switch (operand) {
178 .int32 => |int| section.writeWord(@bitCast(Word, int)),178 .int32 => |int| section.writeWord(@as(Word, @bitCast(int))),
179 .uint32 => |int| section.writeWord(@bitCast(Word, int)),179 .uint32 => |int| section.writeWord(@as(Word, @bitCast(int))),
180 .int64 => |int| section.writeDoubleWord(@bitCast(DoubleWord, int)),180 .int64 => |int| section.writeDoubleWord(@as(DoubleWord, @bitCast(int))),
181 .uint64 => |int| section.writeDoubleWord(@bitCast(DoubleWord, int)),181 .uint64 => |int| section.writeDoubleWord(@as(DoubleWord, @bitCast(int))),
182 .float32 => |float| section.writeWord(@bitCast(Word, float)),182 .float32 => |float| section.writeWord(@as(Word, @bitCast(float))),
183 .float64 => |float| section.writeDoubleWord(@bitCast(DoubleWord, float)),183 .float64 => |float| section.writeDoubleWord(@as(DoubleWord, @bitCast(float))),
184 }184 }
185}185}
186186
...@@ -189,10 +189,10 @@ fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand...@@ -189,10 +189,10 @@ fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand
189 inline for (@typeInfo(Operand).Struct.fields, 0..) |field, bit| {189 inline for (@typeInfo(Operand).Struct.fields, 0..) |field, bit| {
190 switch (@typeInfo(field.type)) {190 switch (@typeInfo(field.type)) {
191 .Optional => if (@field(operand, field.name) != null) {191 .Optional => if (@field(operand, field.name) != null) {
192 mask |= 1 << @intCast(u5, bit);192 mask |= 1 << @as(u5, @intCast(bit));
193 },193 },
194 .Bool => if (@field(operand, field.name)) {194 .Bool => if (@field(operand, field.name)) {
195 mask |= 1 << @intCast(u5, bit);195 mask |= 1 << @as(u5, @intCast(bit));
196 },196 },
197 else => unreachable,197 else => unreachable,
198 }198 }
...@@ -392,7 +392,7 @@ test "SPIR-V Section emit() - extended mask" {...@@ -392,7 +392,7 @@ test "SPIR-V Section emit() - extended mask" {
392 (@as(Word, 5) << 16) | @intFromEnum(Opcode.OpLoopMerge),392 (@as(Word, 5) << 16) | @intFromEnum(Opcode.OpLoopMerge),
393 10,393 10,
394 20,394 20,
395 @bitCast(Word, spec.LoopControl{ .Unroll = true, .DependencyLength = true }),395 @as(Word, @bitCast(spec.LoopControl{ .Unroll = true, .DependencyLength = true })),
396 2,396 2,
397 }, section.instructions.items);397 }, section.instructions.items);
398}398}
src/crash_report.zig+24-24
...@@ -204,49 +204,49 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any...@@ -204,49 +204,49 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any
204204
205 const stack_ctx: StackContext = switch (builtin.cpu.arch) {205 const stack_ctx: StackContext = switch (builtin.cpu.arch) {
206 .x86 => ctx: {206 .x86 => ctx: {
207 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));207 const ctx: *const os.ucontext_t = @ptrCast(@alignCast(ctx_ptr));
208 const ip = @intCast(usize, ctx.mcontext.gregs[os.REG.EIP]);208 const ip = @as(usize, @intCast(ctx.mcontext.gregs[os.REG.EIP]));
209 const bp = @intCast(usize, ctx.mcontext.gregs[os.REG.EBP]);209 const bp = @as(usize, @intCast(ctx.mcontext.gregs[os.REG.EBP]));
210 break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };210 break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };
211 },211 },
212 .x86_64 => ctx: {212 .x86_64 => ctx: {
213 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));213 const ctx: *const os.ucontext_t = @ptrCast(@alignCast(ctx_ptr));
214 const ip = switch (builtin.os.tag) {214 const ip = switch (builtin.os.tag) {
215 .linux, .netbsd, .solaris => @intCast(usize, ctx.mcontext.gregs[os.REG.RIP]),215 .linux, .netbsd, .solaris => @as(usize, @intCast(ctx.mcontext.gregs[os.REG.RIP])),
216 .freebsd => @intCast(usize, ctx.mcontext.rip),216 .freebsd => @as(usize, @intCast(ctx.mcontext.rip)),
217 .openbsd => @intCast(usize, ctx.sc_rip),217 .openbsd => @as(usize, @intCast(ctx.sc_rip)),
218 .macos => @intCast(usize, ctx.mcontext.ss.rip),218 .macos => @as(usize, @intCast(ctx.mcontext.ss.rip)),
219 else => unreachable,219 else => unreachable,
220 };220 };
221 const bp = switch (builtin.os.tag) {221 const bp = switch (builtin.os.tag) {
222 .linux, .netbsd, .solaris => @intCast(usize, ctx.mcontext.gregs[os.REG.RBP]),222 .linux, .netbsd, .solaris => @as(usize, @intCast(ctx.mcontext.gregs[os.REG.RBP])),
223 .openbsd => @intCast(usize, ctx.sc_rbp),223 .openbsd => @as(usize, @intCast(ctx.sc_rbp)),
224 .freebsd => @intCast(usize, ctx.mcontext.rbp),224 .freebsd => @as(usize, @intCast(ctx.mcontext.rbp)),
225 .macos => @intCast(usize, ctx.mcontext.ss.rbp),225 .macos => @as(usize, @intCast(ctx.mcontext.ss.rbp)),
226 else => unreachable,226 else => unreachable,
227 };227 };
228 break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };228 break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };
229 },229 },
230 .arm => ctx: {230 .arm => ctx: {
231 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));231 const ctx: *const os.ucontext_t = @ptrCast(@alignCast(ctx_ptr));
232 const ip = @intCast(usize, ctx.mcontext.arm_pc);232 const ip = @as(usize, @intCast(ctx.mcontext.arm_pc));
233 const bp = @intCast(usize, ctx.mcontext.arm_fp);233 const bp = @as(usize, @intCast(ctx.mcontext.arm_fp));
234 break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };234 break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };
235 },235 },
236 .aarch64 => ctx: {236 .aarch64 => ctx: {
237 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));237 const ctx: *const os.ucontext_t = @ptrCast(@alignCast(ctx_ptr));
238 const ip = switch (native_os) {238 const ip = switch (native_os) {
239 .macos => @intCast(usize, ctx.mcontext.ss.pc),239 .macos => @as(usize, @intCast(ctx.mcontext.ss.pc)),
240 .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.PC]),240 .netbsd => @as(usize, @intCast(ctx.mcontext.gregs[os.REG.PC])),
241 .freebsd => @intCast(usize, ctx.mcontext.gpregs.elr),241 .freebsd => @as(usize, @intCast(ctx.mcontext.gpregs.elr)),
242 else => @intCast(usize, ctx.mcontext.pc),242 else => @as(usize, @intCast(ctx.mcontext.pc)),
243 };243 };
244 // x29 is the ABI-designated frame pointer244 // x29 is the ABI-designated frame pointer
245 const bp = switch (native_os) {245 const bp = switch (native_os) {
246 .macos => @intCast(usize, ctx.mcontext.ss.fp),246 .macos => @as(usize, @intCast(ctx.mcontext.ss.fp)),
247 .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.FP]),247 .netbsd => @as(usize, @intCast(ctx.mcontext.gregs[os.REG.FP])),
248 .freebsd => @intCast(usize, ctx.mcontext.gpregs.x[os.REG.FP]),248 .freebsd => @as(usize, @intCast(ctx.mcontext.gpregs.x[os.REG.FP])),
249 else => @intCast(usize, ctx.mcontext.regs[29]),249 else => @as(usize, @intCast(ctx.mcontext.regs[29])),
250 };250 };
251 break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };251 break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };
252 },252 },
src/glibc.zig+4-4
...@@ -779,13 +779,13 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo...@@ -779,13 +779,13 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo
779 // Test whether the inclusion applies to our current library and target.779 // Test whether the inclusion applies to our current library and target.
780 const ok_lib_and_target =780 const ok_lib_and_target =
781 (lib_index == lib_i) and781 (lib_index == lib_i) and
782 ((targets & (@as(u32, 1) << @intCast(u5, target_targ_index))) != 0);782 ((targets & (@as(u32, 1) << @as(u5, @intCast(target_targ_index)))) != 0);
783783
784 while (true) {784 while (true) {
785 const byte = metadata.inclusions[inc_i];785 const byte = metadata.inclusions[inc_i];
786 inc_i += 1;786 inc_i += 1;
787 const last = (byte & 0b1000_0000) != 0;787 const last = (byte & 0b1000_0000) != 0;
788 const ver_i = @truncate(u7, byte);788 const ver_i = @as(u7, @truncate(byte));
789 if (ok_lib_and_target and ver_i <= target_ver_index) {789 if (ok_lib_and_target and ver_i <= target_ver_index) {
790 versions_buffer[versions_len] = ver_i;790 versions_buffer[versions_len] = ver_i;
791 versions_len += 1;791 versions_len += 1;
...@@ -913,13 +913,13 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo...@@ -913,13 +913,13 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo
913 // Test whether the inclusion applies to our current library and target.913 // Test whether the inclusion applies to our current library and target.
914 const ok_lib_and_target =914 const ok_lib_and_target =
915 (lib_index == lib_i) and915 (lib_index == lib_i) and
916 ((targets & (@as(u32, 1) << @intCast(u5, target_targ_index))) != 0);916 ((targets & (@as(u32, 1) << @as(u5, @intCast(target_targ_index)))) != 0);
917917
918 while (true) {918 while (true) {
919 const byte = metadata.inclusions[inc_i];919 const byte = metadata.inclusions[inc_i];
920 inc_i += 1;920 inc_i += 1;
921 const last = (byte & 0b1000_0000) != 0;921 const last = (byte & 0b1000_0000) != 0;
922 const ver_i = @truncate(u7, byte);922 const ver_i = @as(u7, @truncate(byte));
923 if (ok_lib_and_target and ver_i <= target_ver_index) {923 if (ok_lib_and_target and ver_i <= target_ver_index) {
924 versions_buffer[versions_len] = ver_i;924 versions_buffer[versions_len] = ver_i;
925 versions_len += 1;925 versions_len += 1;
src/link/C.zig+4-4
...@@ -292,7 +292,7 @@ pub fn flushModule(self: *C, _: *Compilation, prog_node: *std.Progress.Node) !vo...@@ -292,7 +292,7 @@ pub fn flushModule(self: *C, _: *Compilation, prog_node: *std.Progress.Node) !vo
292 {292 {
293 var export_names: std.AutoHashMapUnmanaged(InternPool.NullTerminatedString, void) = .{};293 var export_names: std.AutoHashMapUnmanaged(InternPool.NullTerminatedString, void) = .{};
294 defer export_names.deinit(gpa);294 defer export_names.deinit(gpa);
295 try export_names.ensureTotalCapacity(gpa, @intCast(u32, module.decl_exports.entries.len));295 try export_names.ensureTotalCapacity(gpa, @as(u32, @intCast(module.decl_exports.entries.len)));
296 for (module.decl_exports.values()) |exports| for (exports.items) |@"export"|296 for (module.decl_exports.values()) |exports| for (exports.items) |@"export"|
297 try export_names.put(gpa, @"export".opts.name, {});297 try export_names.put(gpa, @"export".opts.name, {});
298298
...@@ -426,7 +426,7 @@ fn flushCTypes(...@@ -426,7 +426,7 @@ fn flushCTypes(
426 return ctx.ctypes_map[idx - codegen.CType.Tag.no_payload_count];426 return ctx.ctypes_map[idx - codegen.CType.Tag.no_payload_count];
427 }427 }
428 };428 };
429 const decl_idx = @intCast(codegen.CType.Index, codegen.CType.Tag.no_payload_count + decl_i);429 const decl_idx = @as(codegen.CType.Index, @intCast(codegen.CType.Tag.no_payload_count + decl_i));
430 const ctx = Context{430 const ctx = Context{
431 .arena = global_ctypes.arena.allocator(),431 .arena = global_ctypes.arena.allocator(),
432 .ctypes_map = f.ctypes_map.items,432 .ctypes_map = f.ctypes_map.items,
...@@ -437,7 +437,7 @@ fn flushCTypes(...@@ -437,7 +437,7 @@ fn flushCTypes(
437 .store = &global_ctypes.set,437 .store = &global_ctypes.set,
438 });438 });
439 const global_idx =439 const global_idx =
440 @intCast(codegen.CType.Index, codegen.CType.Tag.no_payload_count + gop.index);440 @as(codegen.CType.Index, @intCast(codegen.CType.Tag.no_payload_count + gop.index));
441 f.ctypes_map.appendAssumeCapacity(global_idx);441 f.ctypes_map.appendAssumeCapacity(global_idx);
442 if (!gop.found_existing) {442 if (!gop.found_existing) {
443 errdefer _ = global_ctypes.set.map.pop();443 errdefer _ = global_ctypes.set.map.pop();
...@@ -538,7 +538,7 @@ fn flushLazyFn(self: *C, db: *DeclBlock, lazy_fn: codegen.LazyFnMap.Entry) Flush...@@ -538,7 +538,7 @@ fn flushLazyFn(self: *C, db: *DeclBlock, lazy_fn: codegen.LazyFnMap.Entry) Flush
538538
539fn flushLazyFns(self: *C, f: *Flush, lazy_fns: codegen.LazyFnMap) FlushDeclError!void {539fn flushLazyFns(self: *C, f: *Flush, lazy_fns: codegen.LazyFnMap) FlushDeclError!void {
540 const gpa = self.base.allocator;540 const gpa = self.base.allocator;
541 try f.lazy_fns.ensureUnusedCapacity(gpa, @intCast(Flush.LazyFns.Size, lazy_fns.count()));541 try f.lazy_fns.ensureUnusedCapacity(gpa, @as(Flush.LazyFns.Size, @intCast(lazy_fns.count())));
542542
543 var it = lazy_fns.iterator();543 var it = lazy_fns.iterator();
544 while (it.next()) |entry| {544 while (it.next()) |entry| {
src/link/Coff.zig+55-55
...@@ -358,7 +358,7 @@ fn populateMissingMetadata(self: *Coff) !void {...@@ -358,7 +358,7 @@ fn populateMissingMetadata(self: *Coff) !void {
358 });358 });
359359
360 if (self.text_section_index == null) {360 if (self.text_section_index == null) {
361 const file_size = @intCast(u32, self.base.options.program_code_size_hint);361 const file_size = @as(u32, @intCast(self.base.options.program_code_size_hint));
362 self.text_section_index = try self.allocateSection(".text", file_size, .{362 self.text_section_index = try self.allocateSection(".text", file_size, .{
363 .CNT_CODE = 1,363 .CNT_CODE = 1,
364 .MEM_EXECUTE = 1,364 .MEM_EXECUTE = 1,
...@@ -367,7 +367,7 @@ fn populateMissingMetadata(self: *Coff) !void {...@@ -367,7 +367,7 @@ fn populateMissingMetadata(self: *Coff) !void {
367 }367 }
368368
369 if (self.got_section_index == null) {369 if (self.got_section_index == null) {
370 const file_size = @intCast(u32, self.base.options.symbol_count_hint) * self.ptr_width.size();370 const file_size = @as(u32, @intCast(self.base.options.symbol_count_hint)) * self.ptr_width.size();
371 self.got_section_index = try self.allocateSection(".got", file_size, .{371 self.got_section_index = try self.allocateSection(".got", file_size, .{
372 .CNT_INITIALIZED_DATA = 1,372 .CNT_INITIALIZED_DATA = 1,
373 .MEM_READ = 1,373 .MEM_READ = 1,
...@@ -392,7 +392,7 @@ fn populateMissingMetadata(self: *Coff) !void {...@@ -392,7 +392,7 @@ fn populateMissingMetadata(self: *Coff) !void {
392 }392 }
393393
394 if (self.idata_section_index == null) {394 if (self.idata_section_index == null) {
395 const file_size = @intCast(u32, self.base.options.symbol_count_hint) * self.ptr_width.size();395 const file_size = @as(u32, @intCast(self.base.options.symbol_count_hint)) * self.ptr_width.size();
396 self.idata_section_index = try self.allocateSection(".idata", file_size, .{396 self.idata_section_index = try self.allocateSection(".idata", file_size, .{
397 .CNT_INITIALIZED_DATA = 1,397 .CNT_INITIALIZED_DATA = 1,
398 .MEM_READ = 1,398 .MEM_READ = 1,
...@@ -400,7 +400,7 @@ fn populateMissingMetadata(self: *Coff) !void {...@@ -400,7 +400,7 @@ fn populateMissingMetadata(self: *Coff) !void {
400 }400 }
401401
402 if (self.reloc_section_index == null) {402 if (self.reloc_section_index == null) {
403 const file_size = @intCast(u32, self.base.options.symbol_count_hint) * @sizeOf(coff.BaseRelocation);403 const file_size = @as(u32, @intCast(self.base.options.symbol_count_hint)) * @sizeOf(coff.BaseRelocation);
404 self.reloc_section_index = try self.allocateSection(".reloc", file_size, .{404 self.reloc_section_index = try self.allocateSection(".reloc", file_size, .{
405 .CNT_INITIALIZED_DATA = 1,405 .CNT_INITIALIZED_DATA = 1,
406 .MEM_DISCARDABLE = 1,406 .MEM_DISCARDABLE = 1,
...@@ -409,7 +409,7 @@ fn populateMissingMetadata(self: *Coff) !void {...@@ -409,7 +409,7 @@ fn populateMissingMetadata(self: *Coff) !void {
409 }409 }
410410
411 if (self.strtab_offset == null) {411 if (self.strtab_offset == null) {
412 const file_size = @intCast(u32, self.strtab.len());412 const file_size = @as(u32, @intCast(self.strtab.len()));
413 self.strtab_offset = self.findFreeSpace(file_size, @alignOf(u32)); // 4bytes aligned seems like a good idea here413 self.strtab_offset = self.findFreeSpace(file_size, @alignOf(u32)); // 4bytes aligned seems like a good idea here
414 log.debug("found strtab free space 0x{x} to 0x{x}", .{ self.strtab_offset.?, self.strtab_offset.? + file_size });414 log.debug("found strtab free space 0x{x} to 0x{x}", .{ self.strtab_offset.?, self.strtab_offset.? + file_size });
415 }415 }
...@@ -430,7 +430,7 @@ fn populateMissingMetadata(self: *Coff) !void {...@@ -430,7 +430,7 @@ fn populateMissingMetadata(self: *Coff) !void {
430}430}
431431
432fn allocateSection(self: *Coff, name: []const u8, size: u32, flags: coff.SectionHeaderFlags) !u16 {432fn allocateSection(self: *Coff, name: []const u8, size: u32, flags: coff.SectionHeaderFlags) !u16 {
433 const index = @intCast(u16, self.sections.slice().len);433 const index = @as(u16, @intCast(self.sections.slice().len));
434 const off = self.findFreeSpace(size, default_file_alignment);434 const off = self.findFreeSpace(size, default_file_alignment);
435 // Memory is always allocated in sequence435 // Memory is always allocated in sequence
436 // TODO: investigate if we can allocate .text last; this way it would never need to grow in memory!436 // TODO: investigate if we can allocate .text last; this way it would never need to grow in memory!
...@@ -652,7 +652,7 @@ pub fn allocateSymbol(self: *Coff) !u32 {...@@ -652,7 +652,7 @@ pub fn allocateSymbol(self: *Coff) !u32 {
652 break :blk index;652 break :blk index;
653 } else {653 } else {
654 log.debug(" (allocating symbol index {d})", .{self.locals.items.len});654 log.debug(" (allocating symbol index {d})", .{self.locals.items.len});
655 const index = @intCast(u32, self.locals.items.len);655 const index = @as(u32, @intCast(self.locals.items.len));
656 _ = self.locals.addOneAssumeCapacity();656 _ = self.locals.addOneAssumeCapacity();
657 break :blk index;657 break :blk index;
658 }658 }
...@@ -680,7 +680,7 @@ fn allocateGlobal(self: *Coff) !u32 {...@@ -680,7 +680,7 @@ fn allocateGlobal(self: *Coff) !u32 {
680 break :blk index;680 break :blk index;
681 } else {681 } else {
682 log.debug(" (allocating global index {d})", .{self.globals.items.len});682 log.debug(" (allocating global index {d})", .{self.globals.items.len});
683 const index = @intCast(u32, self.globals.items.len);683 const index = @as(u32, @intCast(self.globals.items.len));
684 _ = self.globals.addOneAssumeCapacity();684 _ = self.globals.addOneAssumeCapacity();
685 break :blk index;685 break :blk index;
686 }686 }
...@@ -704,7 +704,7 @@ fn addGotEntry(self: *Coff, target: SymbolWithLoc) !void {...@@ -704,7 +704,7 @@ fn addGotEntry(self: *Coff, target: SymbolWithLoc) !void {
704704
705pub fn createAtom(self: *Coff) !Atom.Index {705pub fn createAtom(self: *Coff) !Atom.Index {
706 const gpa = self.base.allocator;706 const gpa = self.base.allocator;
707 const atom_index = @intCast(Atom.Index, self.atoms.items.len);707 const atom_index = @as(Atom.Index, @intCast(self.atoms.items.len));
708 const atom = try self.atoms.addOne(gpa);708 const atom = try self.atoms.addOne(gpa);
709 const sym_index = try self.allocateSymbol();709 const sym_index = try self.allocateSymbol();
710 try self.atom_by_index_table.putNoClobber(gpa, sym_index, atom_index);710 try self.atom_by_index_table.putNoClobber(gpa, sym_index, atom_index);
...@@ -776,7 +776,7 @@ fn writeAtom(self: *Coff, atom_index: Atom.Index, code: []u8) !void {...@@ -776,7 +776,7 @@ fn writeAtom(self: *Coff, atom_index: Atom.Index, code: []u8) !void {
776 self.resolveRelocs(atom_index, relocs.items, mem_code, slide);776 self.resolveRelocs(atom_index, relocs.items, mem_code, slide);
777777
778 const vaddr = sym.value + slide;778 const vaddr = sym.value + slide;
779 const pvaddr = @ptrFromInt(*anyopaque, vaddr);779 const pvaddr = @as(*anyopaque, @ptrFromInt(vaddr));
780780
781 log.debug("writing to memory at address {x}", .{vaddr});781 log.debug("writing to memory at address {x}", .{vaddr});
782782
...@@ -830,7 +830,7 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void {...@@ -830,7 +830,7 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void {
830 const sect_id = self.got_section_index.?;830 const sect_id = self.got_section_index.?;
831831
832 if (self.got_table_count_dirty) {832 if (self.got_table_count_dirty) {
833 const needed_size = @intCast(u32, self.got_table.entries.items.len * self.ptr_width.size());833 const needed_size = @as(u32, @intCast(self.got_table.entries.items.len * self.ptr_width.size()));
834 try self.growSection(sect_id, needed_size);834 try self.growSection(sect_id, needed_size);
835 self.got_table_count_dirty = false;835 self.got_table_count_dirty = false;
836 }836 }
...@@ -847,7 +847,7 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void {...@@ -847,7 +847,7 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void {
847 switch (self.ptr_width) {847 switch (self.ptr_width) {
848 .p32 => {848 .p32 => {
849 var buf: [4]u8 = undefined;849 var buf: [4]u8 = undefined;
850 mem.writeIntLittle(u32, &buf, @intCast(u32, entry_value + self.getImageBase()));850 mem.writeIntLittle(u32, &buf, @as(u32, @intCast(entry_value + self.getImageBase())));
851 try self.base.file.?.pwriteAll(&buf, file_offset);851 try self.base.file.?.pwriteAll(&buf, file_offset);
852 },852 },
853 .p64 => {853 .p64 => {
...@@ -862,7 +862,7 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void {...@@ -862,7 +862,7 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void {
862 const gpa = self.base.allocator;862 const gpa = self.base.allocator;
863 const slide = @intFromPtr(self.hot_state.loaded_base_address.?);863 const slide = @intFromPtr(self.hot_state.loaded_base_address.?);
864 const actual_vmaddr = vmaddr + slide;864 const actual_vmaddr = vmaddr + slide;
865 const pvaddr = @ptrFromInt(*anyopaque, actual_vmaddr);865 const pvaddr = @as(*anyopaque, @ptrFromInt(actual_vmaddr));
866 log.debug("writing GOT entry to memory at address {x}", .{actual_vmaddr});866 log.debug("writing GOT entry to memory at address {x}", .{actual_vmaddr});
867 if (build_options.enable_logging) {867 if (build_options.enable_logging) {
868 switch (self.ptr_width) {868 switch (self.ptr_width) {
...@@ -880,7 +880,7 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void {...@@ -880,7 +880,7 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void {
880 switch (self.ptr_width) {880 switch (self.ptr_width) {
881 .p32 => {881 .p32 => {
882 var buf: [4]u8 = undefined;882 var buf: [4]u8 = undefined;
883 mem.writeIntLittle(u32, &buf, @intCast(u32, entry_value + slide));883 mem.writeIntLittle(u32, &buf, @as(u32, @intCast(entry_value + slide)));
884 writeMem(handle, pvaddr, &buf) catch |err| {884 writeMem(handle, pvaddr, &buf) catch |err| {
885 log.warn("writing to protected memory failed with error: {s}", .{@errorName(err)});885 log.warn("writing to protected memory failed with error: {s}", .{@errorName(err)});
886 };886 };
...@@ -1107,7 +1107,7 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In...@@ -1107,7 +1107,7 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In
1107 const atom = self.getAtom(atom_index);1107 const atom = self.getAtom(atom_index);
1108 const sym = atom.getSymbolPtr(self);1108 const sym = atom.getSymbolPtr(self);
1109 try self.setSymbolName(sym, sym_name);1109 try self.setSymbolName(sym, sym_name);
1110 sym.section_number = @enumFromInt(coff.SectionNumber, self.rdata_section_index.? + 1);1110 sym.section_number = @as(coff.SectionNumber, @enumFromInt(self.rdata_section_index.? + 1));
1111 }1111 }
11121112
1113 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), tv, &code_buffer, .none, .{1113 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), tv, &code_buffer, .none, .{
...@@ -1125,7 +1125,7 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In...@@ -1125,7 +1125,7 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In
11251125
1126 const required_alignment = tv.ty.abiAlignment(mod);1126 const required_alignment = tv.ty.abiAlignment(mod);
1127 const atom = self.getAtomPtr(atom_index);1127 const atom = self.getAtomPtr(atom_index);
1128 atom.size = @intCast(u32, code.len);1128 atom.size = @as(u32, @intCast(code.len));
1129 atom.getSymbolPtr(self).value = try self.allocateAtom(atom_index, atom.size, required_alignment);1129 atom.getSymbolPtr(self).value = try self.allocateAtom(atom_index, atom.size, required_alignment);
1130 errdefer self.freeAtom(atom_index);1130 errdefer self.freeAtom(atom_index);
11311131
...@@ -1241,10 +1241,10 @@ fn updateLazySymbolAtom(...@@ -1241,10 +1241,10 @@ fn updateLazySymbolAtom(
1241 },1241 },
1242 };1242 };
12431243
1244 const code_len = @intCast(u32, code.len);1244 const code_len = @as(u32, @intCast(code.len));
1245 const symbol = atom.getSymbolPtr(self);1245 const symbol = atom.getSymbolPtr(self);
1246 try self.setSymbolName(symbol, name);1246 try self.setSymbolName(symbol, name);
1247 symbol.section_number = @enumFromInt(coff.SectionNumber, section_index + 1);1247 symbol.section_number = @as(coff.SectionNumber, @enumFromInt(section_index + 1));
1248 symbol.type = .{ .complex_type = .NULL, .base_type = .NULL };1248 symbol.type = .{ .complex_type = .NULL, .base_type = .NULL };
12491249
1250 const vaddr = try self.allocateAtom(atom_index, code_len, required_alignment);1250 const vaddr = try self.allocateAtom(atom_index, code_len, required_alignment);
...@@ -1336,12 +1336,12 @@ fn updateDeclCode(self: *Coff, decl_index: Module.Decl.Index, code: []u8, comple...@@ -1336,12 +1336,12 @@ fn updateDeclCode(self: *Coff, decl_index: Module.Decl.Index, code: []u8, comple
1336 const atom = self.getAtom(atom_index);1336 const atom = self.getAtom(atom_index);
1337 const sym_index = atom.getSymbolIndex().?;1337 const sym_index = atom.getSymbolIndex().?;
1338 const sect_index = decl_metadata.section;1338 const sect_index = decl_metadata.section;
1339 const code_len = @intCast(u32, code.len);1339 const code_len = @as(u32, @intCast(code.len));
13401340
1341 if (atom.size != 0) {1341 if (atom.size != 0) {
1342 const sym = atom.getSymbolPtr(self);1342 const sym = atom.getSymbolPtr(self);
1343 try self.setSymbolName(sym, decl_name);1343 try self.setSymbolName(sym, decl_name);
1344 sym.section_number = @enumFromInt(coff.SectionNumber, sect_index + 1);1344 sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_index + 1));
1345 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };1345 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };
13461346
1347 const capacity = atom.capacity(self);1347 const capacity = atom.capacity(self);
...@@ -1365,7 +1365,7 @@ fn updateDeclCode(self: *Coff, decl_index: Module.Decl.Index, code: []u8, comple...@@ -1365,7 +1365,7 @@ fn updateDeclCode(self: *Coff, decl_index: Module.Decl.Index, code: []u8, comple
1365 } else {1365 } else {
1366 const sym = atom.getSymbolPtr(self);1366 const sym = atom.getSymbolPtr(self);
1367 try self.setSymbolName(sym, decl_name);1367 try self.setSymbolName(sym, decl_name);
1368 sym.section_number = @enumFromInt(coff.SectionNumber, sect_index + 1);1368 sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_index + 1));
1369 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };1369 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };
13701370
1371 const vaddr = try self.allocateAtom(atom_index, code_len, required_alignment);1371 const vaddr = try self.allocateAtom(atom_index, code_len, required_alignment);
...@@ -1502,7 +1502,7 @@ pub fn updateDeclExports(...@@ -1502,7 +1502,7 @@ pub fn updateDeclExports(
1502 const sym = self.getSymbolPtr(sym_loc);1502 const sym = self.getSymbolPtr(sym_loc);
1503 try self.setSymbolName(sym, mod.intern_pool.stringToSlice(exp.opts.name));1503 try self.setSymbolName(sym, mod.intern_pool.stringToSlice(exp.opts.name));
1504 sym.value = decl_sym.value;1504 sym.value = decl_sym.value;
1505 sym.section_number = @enumFromInt(coff.SectionNumber, self.text_section_index.? + 1);1505 sym.section_number = @as(coff.SectionNumber, @enumFromInt(self.text_section_index.? + 1));
1506 sym.type = .{ .complex_type = .FUNCTION, .base_type = .NULL };1506 sym.type = .{ .complex_type = .FUNCTION, .base_type = .NULL };
15071507
1508 switch (exp.opts.linkage) {1508 switch (exp.opts.linkage) {
...@@ -1728,12 +1728,12 @@ pub fn getDeclVAddr(self: *Coff, decl_index: Module.Decl.Index, reloc_info: link...@@ -1728,12 +1728,12 @@ pub fn getDeclVAddr(self: *Coff, decl_index: Module.Decl.Index, reloc_info: link
1728 try Atom.addRelocation(self, atom_index, .{1728 try Atom.addRelocation(self, atom_index, .{
1729 .type = .direct,1729 .type = .direct,
1730 .target = target,1730 .target = target,
1731 .offset = @intCast(u32, reloc_info.offset),1731 .offset = @as(u32, @intCast(reloc_info.offset)),
1732 .addend = reloc_info.addend,1732 .addend = reloc_info.addend,
1733 .pcrel = false,1733 .pcrel = false,
1734 .length = 3,1734 .length = 3,
1735 });1735 });
1736 try Atom.addBaseRelocation(self, atom_index, @intCast(u32, reloc_info.offset));1736 try Atom.addBaseRelocation(self, atom_index, @as(u32, @intCast(reloc_info.offset)));
17371737
1738 return 0;1738 return 0;
1739}1739}
...@@ -1804,7 +1804,7 @@ fn writeBaseRelocations(self: *Coff) !void {...@@ -1804,7 +1804,7 @@ fn writeBaseRelocations(self: *Coff) !void {
1804 gop.value_ptr.* = std.ArrayList(coff.BaseRelocation).init(gpa);1804 gop.value_ptr.* = std.ArrayList(coff.BaseRelocation).init(gpa);
1805 }1805 }
1806 try gop.value_ptr.append(.{1806 try gop.value_ptr.append(.{
1807 .offset = @intCast(u12, rva - page),1807 .offset = @as(u12, @intCast(rva - page)),
1808 .type = .DIR64,1808 .type = .DIR64,
1809 });1809 });
1810 }1810 }
...@@ -1818,14 +1818,14 @@ fn writeBaseRelocations(self: *Coff) !void {...@@ -1818,14 +1818,14 @@ fn writeBaseRelocations(self: *Coff) !void {
1818 const sym = self.getSymbol(entry);1818 const sym = self.getSymbol(entry);
1819 if (sym.section_number == .UNDEFINED) continue;1819 if (sym.section_number == .UNDEFINED) continue;
18201820
1821 const rva = @intCast(u32, header.virtual_address + index * self.ptr_width.size());1821 const rva = @as(u32, @intCast(header.virtual_address + index * self.ptr_width.size()));
1822 const page = mem.alignBackward(u32, rva, self.page_size);1822 const page = mem.alignBackward(u32, rva, self.page_size);
1823 const gop = try page_table.getOrPut(page);1823 const gop = try page_table.getOrPut(page);
1824 if (!gop.found_existing) {1824 if (!gop.found_existing) {
1825 gop.value_ptr.* = std.ArrayList(coff.BaseRelocation).init(gpa);1825 gop.value_ptr.* = std.ArrayList(coff.BaseRelocation).init(gpa);
1826 }1826 }
1827 try gop.value_ptr.append(.{1827 try gop.value_ptr.append(.{
1828 .offset = @intCast(u12, rva - page),1828 .offset = @as(u12, @intCast(rva - page)),
1829 .type = .DIR64,1829 .type = .DIR64,
1830 });1830 });
1831 }1831 }
...@@ -1860,9 +1860,9 @@ fn writeBaseRelocations(self: *Coff) !void {...@@ -1860,9 +1860,9 @@ fn writeBaseRelocations(self: *Coff) !void {
1860 });1860 });
1861 }1861 }
18621862
1863 const block_size = @intCast(1863 const block_size = @as(
1864 u32,1864 u32,
1865 entries.items.len * @sizeOf(coff.BaseRelocation) + @sizeOf(coff.BaseRelocationDirectoryEntry),1865 @intCast(entries.items.len * @sizeOf(coff.BaseRelocation) + @sizeOf(coff.BaseRelocationDirectoryEntry)),
1866 );1866 );
1867 try buffer.ensureUnusedCapacity(block_size);1867 try buffer.ensureUnusedCapacity(block_size);
1868 buffer.appendSliceAssumeCapacity(mem.asBytes(&coff.BaseRelocationDirectoryEntry{1868 buffer.appendSliceAssumeCapacity(mem.asBytes(&coff.BaseRelocationDirectoryEntry{
...@@ -1873,7 +1873,7 @@ fn writeBaseRelocations(self: *Coff) !void {...@@ -1873,7 +1873,7 @@ fn writeBaseRelocations(self: *Coff) !void {
1873 }1873 }
18741874
1875 const header = &self.sections.items(.header)[self.reloc_section_index.?];1875 const header = &self.sections.items(.header)[self.reloc_section_index.?];
1876 const needed_size = @intCast(u32, buffer.items.len);1876 const needed_size = @as(u32, @intCast(buffer.items.len));
1877 try self.growSection(self.reloc_section_index.?, needed_size);1877 try self.growSection(self.reloc_section_index.?, needed_size);
18781878
1879 try self.base.file.?.pwriteAll(buffer.items, header.pointer_to_raw_data);1879 try self.base.file.?.pwriteAll(buffer.items, header.pointer_to_raw_data);
...@@ -1904,12 +1904,12 @@ fn writeImportTables(self: *Coff) !void {...@@ -1904,12 +1904,12 @@ fn writeImportTables(self: *Coff) !void {
1904 const itable = self.import_tables.values()[i];1904 const itable = self.import_tables.values()[i];
1905 iat_size += itable.size() + 8;1905 iat_size += itable.size() + 8;
1906 dir_table_size += @sizeOf(coff.ImportDirectoryEntry);1906 dir_table_size += @sizeOf(coff.ImportDirectoryEntry);
1907 lookup_table_size += @intCast(u32, itable.entries.items.len + 1) * @sizeOf(coff.ImportLookupEntry64.ByName);1907 lookup_table_size += @as(u32, @intCast(itable.entries.items.len + 1)) * @sizeOf(coff.ImportLookupEntry64.ByName);
1908 for (itable.entries.items) |entry| {1908 for (itable.entries.items) |entry| {
1909 const sym_name = self.getSymbolName(entry);1909 const sym_name = self.getSymbolName(entry);
1910 names_table_size += 2 + mem.alignForward(u32, @intCast(u32, sym_name.len + 1), 2);1910 names_table_size += 2 + mem.alignForward(u32, @as(u32, @intCast(sym_name.len + 1)), 2);
1911 }1911 }
1912 dll_names_size += @intCast(u32, lib_name.len + ext.len + 1);1912 dll_names_size += @as(u32, @intCast(lib_name.len + ext.len + 1));
1913 }1913 }
19141914
1915 const needed_size = iat_size + dir_table_size + lookup_table_size + names_table_size + dll_names_size;1915 const needed_size = iat_size + dir_table_size + lookup_table_size + names_table_size + dll_names_size;
...@@ -1948,7 +1948,7 @@ fn writeImportTables(self: *Coff) !void {...@@ -1948,7 +1948,7 @@ fn writeImportTables(self: *Coff) !void {
1948 const import_name = self.getSymbolName(entry);1948 const import_name = self.getSymbolName(entry);
19491949
1950 // IAT and lookup table entry1950 // IAT and lookup table entry
1951 const lookup = coff.ImportLookupEntry64.ByName{ .name_table_rva = @intCast(u31, header.virtual_address + names_table_offset) };1951 const lookup = coff.ImportLookupEntry64.ByName{ .name_table_rva = @as(u31, @intCast(header.virtual_address + names_table_offset)) };
1952 @memcpy(1952 @memcpy(
1953 buffer.items[iat_offset..][0..@sizeOf(coff.ImportLookupEntry64.ByName)],1953 buffer.items[iat_offset..][0..@sizeOf(coff.ImportLookupEntry64.ByName)],
1954 mem.asBytes(&lookup),1954 mem.asBytes(&lookup),
...@@ -1964,7 +1964,7 @@ fn writeImportTables(self: *Coff) !void {...@@ -1964,7 +1964,7 @@ fn writeImportTables(self: *Coff) !void {
1964 mem.writeIntLittle(u16, buffer.items[names_table_offset..][0..2], 0); // Hint set to 0 until we learn how to parse DLLs1964 mem.writeIntLittle(u16, buffer.items[names_table_offset..][0..2], 0); // Hint set to 0 until we learn how to parse DLLs
1965 names_table_offset += 2;1965 names_table_offset += 2;
1966 @memcpy(buffer.items[names_table_offset..][0..import_name.len], import_name);1966 @memcpy(buffer.items[names_table_offset..][0..import_name.len], import_name);
1967 names_table_offset += @intCast(u32, import_name.len);1967 names_table_offset += @as(u32, @intCast(import_name.len));
1968 buffer.items[names_table_offset] = 0;1968 buffer.items[names_table_offset] = 0;
1969 names_table_offset += 1;1969 names_table_offset += 1;
1970 if (!mem.isAlignedGeneric(usize, names_table_offset, @sizeOf(u16))) {1970 if (!mem.isAlignedGeneric(usize, names_table_offset, @sizeOf(u16))) {
...@@ -1986,9 +1986,9 @@ fn writeImportTables(self: *Coff) !void {...@@ -1986,9 +1986,9 @@ fn writeImportTables(self: *Coff) !void {
19861986
1987 // DLL name1987 // DLL name
1988 @memcpy(buffer.items[dll_names_offset..][0..lib_name.len], lib_name);1988 @memcpy(buffer.items[dll_names_offset..][0..lib_name.len], lib_name);
1989 dll_names_offset += @intCast(u32, lib_name.len);1989 dll_names_offset += @as(u32, @intCast(lib_name.len));
1990 @memcpy(buffer.items[dll_names_offset..][0..ext.len], ext);1990 @memcpy(buffer.items[dll_names_offset..][0..ext.len], ext);
1991 dll_names_offset += @intCast(u32, ext.len);1991 dll_names_offset += @as(u32, @intCast(ext.len));
1992 buffer.items[dll_names_offset] = 0;1992 buffer.items[dll_names_offset] = 0;
1993 dll_names_offset += 1;1993 dll_names_offset += 1;
1994 }1994 }
...@@ -2027,11 +2027,11 @@ fn writeStrtab(self: *Coff) !void {...@@ -2027,11 +2027,11 @@ fn writeStrtab(self: *Coff) !void {
2027 if (self.strtab_offset == null) return;2027 if (self.strtab_offset == null) return;
20282028
2029 const allocated_size = self.allocatedSize(self.strtab_offset.?);2029 const allocated_size = self.allocatedSize(self.strtab_offset.?);
2030 const needed_size = @intCast(u32, self.strtab.len());2030 const needed_size = @as(u32, @intCast(self.strtab.len()));
20312031
2032 if (needed_size > allocated_size) {2032 if (needed_size > allocated_size) {
2033 self.strtab_offset = null;2033 self.strtab_offset = null;
2034 self.strtab_offset = @intCast(u32, self.findFreeSpace(needed_size, @alignOf(u32)));2034 self.strtab_offset = @as(u32, @intCast(self.findFreeSpace(needed_size, @alignOf(u32))));
2035 }2035 }
20362036
2037 log.debug("writing strtab from 0x{x} to 0x{x}", .{ self.strtab_offset.?, self.strtab_offset.? + needed_size });2037 log.debug("writing strtab from 0x{x} to 0x{x}", .{ self.strtab_offset.?, self.strtab_offset.? + needed_size });
...@@ -2042,7 +2042,7 @@ fn writeStrtab(self: *Coff) !void {...@@ -2042,7 +2042,7 @@ fn writeStrtab(self: *Coff) !void {
2042 buffer.appendSliceAssumeCapacity(self.strtab.items());2042 buffer.appendSliceAssumeCapacity(self.strtab.items());
2043 // Here, we do a trick in that we do not commit the size of the strtab to strtab buffer, instead2043 // Here, we do a trick in that we do not commit the size of the strtab to strtab buffer, instead
2044 // we write the length of the strtab to a temporary buffer that goes to file.2044 // we write the length of the strtab to a temporary buffer that goes to file.
2045 mem.writeIntLittle(u32, buffer.items[0..4], @intCast(u32, self.strtab.len()));2045 mem.writeIntLittle(u32, buffer.items[0..4], @as(u32, @intCast(self.strtab.len())));
20462046
2047 try self.base.file.?.pwriteAll(buffer.items, self.strtab_offset.?);2047 try self.base.file.?.pwriteAll(buffer.items, self.strtab_offset.?);
2048}2048}
...@@ -2081,11 +2081,11 @@ fn writeHeader(self: *Coff) !void {...@@ -2081,11 +2081,11 @@ fn writeHeader(self: *Coff) !void {
2081 }2081 }
20822082
2083 const timestamp = std.time.timestamp();2083 const timestamp = std.time.timestamp();
2084 const size_of_optional_header = @intCast(u16, self.getOptionalHeaderSize() + self.getDataDirectoryHeadersSize());2084 const size_of_optional_header = @as(u16, @intCast(self.getOptionalHeaderSize() + self.getDataDirectoryHeadersSize()));
2085 var coff_header = coff.CoffHeader{2085 var coff_header = coff.CoffHeader{
2086 .machine = coff.MachineType.fromTargetCpuArch(self.base.options.target.cpu.arch),2086 .machine = coff.MachineType.fromTargetCpuArch(self.base.options.target.cpu.arch),
2087 .number_of_sections = @intCast(u16, self.sections.slice().len), // TODO what if we prune a section2087 .number_of_sections = @as(u16, @intCast(self.sections.slice().len)), // TODO what if we prune a section
2088 .time_date_stamp = @truncate(u32, @bitCast(u64, timestamp)),2088 .time_date_stamp = @as(u32, @truncate(@as(u64, @bitCast(timestamp)))),
2089 .pointer_to_symbol_table = self.strtab_offset orelse 0,2089 .pointer_to_symbol_table = self.strtab_offset orelse 0,
2090 .number_of_symbols = 0,2090 .number_of_symbols = 0,
2091 .size_of_optional_header = size_of_optional_header,2091 .size_of_optional_header = size_of_optional_header,
...@@ -2135,7 +2135,7 @@ fn writeHeader(self: *Coff) !void {...@@ -2135,7 +2135,7 @@ fn writeHeader(self: *Coff) !void {
2135 .address_of_entry_point = self.entry_addr orelse 0,2135 .address_of_entry_point = self.entry_addr orelse 0,
2136 .base_of_code = base_of_code,2136 .base_of_code = base_of_code,
2137 .base_of_data = base_of_data,2137 .base_of_data = base_of_data,
2138 .image_base = @intCast(u32, image_base),2138 .image_base = @as(u32, @intCast(image_base)),
2139 .section_alignment = self.page_size,2139 .section_alignment = self.page_size,
2140 .file_alignment = default_file_alignment,2140 .file_alignment = default_file_alignment,
2141 .major_operating_system_version = 6,2141 .major_operating_system_version = 6,
...@@ -2155,7 +2155,7 @@ fn writeHeader(self: *Coff) !void {...@@ -2155,7 +2155,7 @@ fn writeHeader(self: *Coff) !void {
2155 .size_of_heap_reserve = default_size_of_heap_reserve,2155 .size_of_heap_reserve = default_size_of_heap_reserve,
2156 .size_of_heap_commit = default_size_of_heap_commit,2156 .size_of_heap_commit = default_size_of_heap_commit,
2157 .loader_flags = 0,2157 .loader_flags = 0,
2158 .number_of_rva_and_sizes = @intCast(u32, self.data_directories.len),2158 .number_of_rva_and_sizes = @as(u32, @intCast(self.data_directories.len)),
2159 };2159 };
2160 writer.writeAll(mem.asBytes(&opt_header)) catch unreachable;2160 writer.writeAll(mem.asBytes(&opt_header)) catch unreachable;
2161 },2161 },
...@@ -2189,7 +2189,7 @@ fn writeHeader(self: *Coff) !void {...@@ -2189,7 +2189,7 @@ fn writeHeader(self: *Coff) !void {
2189 .size_of_heap_reserve = default_size_of_heap_reserve,2189 .size_of_heap_reserve = default_size_of_heap_reserve,
2190 .size_of_heap_commit = default_size_of_heap_commit,2190 .size_of_heap_commit = default_size_of_heap_commit,
2191 .loader_flags = 0,2191 .loader_flags = 0,
2192 .number_of_rva_and_sizes = @intCast(u32, self.data_directories.len),2192 .number_of_rva_and_sizes = @as(u32, @intCast(self.data_directories.len)),
2193 };2193 };
2194 writer.writeAll(mem.asBytes(&opt_header)) catch unreachable;2194 writer.writeAll(mem.asBytes(&opt_header)) catch unreachable;
2195 },2195 },
...@@ -2210,7 +2210,7 @@ fn detectAllocCollision(self: *Coff, start: u32, size: u32) ?u32 {...@@ -2210,7 +2210,7 @@ fn detectAllocCollision(self: *Coff, start: u32, size: u32) ?u32 {
2210 const end = start + padToIdeal(size);2210 const end = start + padToIdeal(size);
22112211
2212 if (self.strtab_offset) |off| {2212 if (self.strtab_offset) |off| {
2213 const tight_size = @intCast(u32, self.strtab.len());2213 const tight_size = @as(u32, @intCast(self.strtab.len()));
2214 const increased_size = padToIdeal(tight_size);2214 const increased_size = padToIdeal(tight_size);
2215 const test_end = off + increased_size;2215 const test_end = off + increased_size;
2216 if (end > off and start < test_end) {2216 if (end > off and start < test_end) {
...@@ -2265,28 +2265,28 @@ fn allocatedVirtualSize(self: *Coff, start: u32) u32 {...@@ -2265,28 +2265,28 @@ fn allocatedVirtualSize(self: *Coff, start: u32) u32 {
22652265
2266inline fn getSizeOfHeaders(self: Coff) u32 {2266inline fn getSizeOfHeaders(self: Coff) u32 {
2267 const msdos_hdr_size = msdos_stub.len + 4;2267 const msdos_hdr_size = msdos_stub.len + 4;
2268 return @intCast(u32, msdos_hdr_size + @sizeOf(coff.CoffHeader) + self.getOptionalHeaderSize() +2268 return @as(u32, @intCast(msdos_hdr_size + @sizeOf(coff.CoffHeader) + self.getOptionalHeaderSize() +
2269 self.getDataDirectoryHeadersSize() + self.getSectionHeadersSize());2269 self.getDataDirectoryHeadersSize() + self.getSectionHeadersSize()));
2270}2270}
22712271
2272inline fn getOptionalHeaderSize(self: Coff) u32 {2272inline fn getOptionalHeaderSize(self: Coff) u32 {
2273 return switch (self.ptr_width) {2273 return switch (self.ptr_width) {
2274 .p32 => @intCast(u32, @sizeOf(coff.OptionalHeaderPE32)),2274 .p32 => @as(u32, @intCast(@sizeOf(coff.OptionalHeaderPE32))),
2275 .p64 => @intCast(u32, @sizeOf(coff.OptionalHeaderPE64)),2275 .p64 => @as(u32, @intCast(@sizeOf(coff.OptionalHeaderPE64))),
2276 };2276 };
2277}2277}
22782278
2279inline fn getDataDirectoryHeadersSize(self: Coff) u32 {2279inline fn getDataDirectoryHeadersSize(self: Coff) u32 {
2280 return @intCast(u32, self.data_directories.len * @sizeOf(coff.ImageDataDirectory));2280 return @as(u32, @intCast(self.data_directories.len * @sizeOf(coff.ImageDataDirectory)));
2281}2281}
22822282
2283inline fn getSectionHeadersSize(self: Coff) u32 {2283inline fn getSectionHeadersSize(self: Coff) u32 {
2284 return @intCast(u32, self.sections.slice().len * @sizeOf(coff.SectionHeader));2284 return @as(u32, @intCast(self.sections.slice().len * @sizeOf(coff.SectionHeader)));
2285}2285}
22862286
2287inline fn getDataDirectoryHeadersOffset(self: Coff) u32 {2287inline fn getDataDirectoryHeadersOffset(self: Coff) u32 {
2288 const msdos_hdr_size = msdos_stub.len + 4;2288 const msdos_hdr_size = msdos_stub.len + 4;
2289 return @intCast(u32, msdos_hdr_size + @sizeOf(coff.CoffHeader) + self.getOptionalHeaderSize());2289 return @as(u32, @intCast(msdos_hdr_size + @sizeOf(coff.CoffHeader) + self.getOptionalHeaderSize()));
2290}2290}
22912291
2292inline fn getSectionHeadersOffset(self: Coff) u32 {2292inline fn getSectionHeadersOffset(self: Coff) u32 {
...@@ -2473,7 +2473,7 @@ fn logSymtab(self: *Coff) void {...@@ -2473,7 +2473,7 @@ fn logSymtab(self: *Coff) void {
2473 };2473 };
2474 log.debug(" %{d}: {?s} @{x} in {s}({d}), {s}", .{2474 log.debug(" %{d}: {?s} @{x} in {s}({d}), {s}", .{
2475 sym_id,2475 sym_id,
2476 self.getSymbolName(.{ .sym_index = @intCast(u32, sym_id), .file = null }),2476 self.getSymbolName(.{ .sym_index = @as(u32, @intCast(sym_id)), .file = null }),
2477 sym.value,2477 sym.value,
2478 where,2478 where,
2479 def_index,2479 def_index,
src/link/Coff/ImportTable.zig+3-3
...@@ -38,7 +38,7 @@ pub fn deinit(itab: *ImportTable, allocator: Allocator) void {...@@ -38,7 +38,7 @@ pub fn deinit(itab: *ImportTable, allocator: Allocator) void {
3838
39/// Size of the import table does not include the sentinel.39/// Size of the import table does not include the sentinel.
40pub fn size(itab: ImportTable) u32 {40pub fn size(itab: ImportTable) u32 {
41 return @intCast(u32, itab.entries.items.len) * @sizeOf(u64);41 return @as(u32, @intCast(itab.entries.items.len)) * @sizeOf(u64);
42}42}
4343
44pub fn addImport(itab: *ImportTable, allocator: Allocator, target: SymbolWithLoc) !ImportIndex {44pub fn addImport(itab: *ImportTable, allocator: Allocator, target: SymbolWithLoc) !ImportIndex {
...@@ -49,7 +49,7 @@ pub fn addImport(itab: *ImportTable, allocator: Allocator, target: SymbolWithLoc...@@ -49,7 +49,7 @@ pub fn addImport(itab: *ImportTable, allocator: Allocator, target: SymbolWithLoc
49 break :blk index;49 break :blk index;
50 } else {50 } else {
51 log.debug(" (allocating import entry at index {d})", .{itab.entries.items.len});51 log.debug(" (allocating import entry at index {d})", .{itab.entries.items.len});
52 const index = @intCast(u32, itab.entries.items.len);52 const index = @as(u32, @intCast(itab.entries.items.len));
53 _ = itab.entries.addOneAssumeCapacity();53 _ = itab.entries.addOneAssumeCapacity();
54 break :blk index;54 break :blk index;
55 }55 }
...@@ -73,7 +73,7 @@ fn getBaseAddress(ctx: Context) u32 {...@@ -73,7 +73,7 @@ fn getBaseAddress(ctx: Context) u32 {
73 var addr = header.virtual_address;73 var addr = header.virtual_address;
74 for (ctx.coff_file.import_tables.values(), 0..) |other_itab, i| {74 for (ctx.coff_file.import_tables.values(), 0..) |other_itab, i| {
75 if (ctx.index == i) break;75 if (ctx.index == i) break;
76 addr += @intCast(u32, other_itab.entries.items.len * @sizeOf(u64)) + 8;76 addr += @as(u32, @intCast(other_itab.entries.items.len * @sizeOf(u64))) + 8;
77 }77 }
78 return addr;78 return addr;
79}79}
src/link/Coff/Relocation.zig+12-12
...@@ -126,23 +126,23 @@ fn resolveAarch64(self: Relocation, ctx: Context) void {...@@ -126,23 +126,23 @@ fn resolveAarch64(self: Relocation, ctx: Context) void {
126 var buffer = ctx.code[self.offset..];126 var buffer = ctx.code[self.offset..];
127 switch (self.type) {127 switch (self.type) {
128 .got_page, .import_page, .page => {128 .got_page, .import_page, .page => {
129 const source_page = @intCast(i32, ctx.source_vaddr >> 12);129 const source_page = @as(i32, @intCast(ctx.source_vaddr >> 12));
130 const target_page = @intCast(i32, ctx.target_vaddr >> 12);130 const target_page = @as(i32, @intCast(ctx.target_vaddr >> 12));
131 const pages = @bitCast(u21, @intCast(i21, target_page - source_page));131 const pages = @as(u21, @bitCast(@as(i21, @intCast(target_page - source_page))));
132 var inst = aarch64.Instruction{132 var inst = aarch64.Instruction{
133 .pc_relative_address = mem.bytesToValue(meta.TagPayload(133 .pc_relative_address = mem.bytesToValue(meta.TagPayload(
134 aarch64.Instruction,134 aarch64.Instruction,
135 aarch64.Instruction.pc_relative_address,135 aarch64.Instruction.pc_relative_address,
136 ), buffer[0..4]),136 ), buffer[0..4]),
137 };137 };
138 inst.pc_relative_address.immhi = @truncate(u19, pages >> 2);138 inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2));
139 inst.pc_relative_address.immlo = @truncate(u2, pages);139 inst.pc_relative_address.immlo = @as(u2, @truncate(pages));
140 mem.writeIntLittle(u32, buffer[0..4], inst.toU32());140 mem.writeIntLittle(u32, buffer[0..4], inst.toU32());
141 },141 },
142 .got_pageoff, .import_pageoff, .pageoff => {142 .got_pageoff, .import_pageoff, .pageoff => {
143 assert(!self.pcrel);143 assert(!self.pcrel);
144144
145 const narrowed = @truncate(u12, @intCast(u64, ctx.target_vaddr));145 const narrowed = @as(u12, @truncate(@as(u64, @intCast(ctx.target_vaddr))));
146 if (isArithmeticOp(buffer[0..4])) {146 if (isArithmeticOp(buffer[0..4])) {
147 var inst = aarch64.Instruction{147 var inst = aarch64.Instruction{
148 .add_subtract_immediate = mem.bytesToValue(meta.TagPayload(148 .add_subtract_immediate = mem.bytesToValue(meta.TagPayload(
...@@ -182,7 +182,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void {...@@ -182,7 +182,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void {
182 2 => mem.writeIntLittle(182 2 => mem.writeIntLittle(
183 u32,183 u32,
184 buffer[0..4],184 buffer[0..4],
185 @truncate(u32, ctx.target_vaddr + ctx.image_base),185 @as(u32, @truncate(ctx.target_vaddr + ctx.image_base)),
186 ),186 ),
187 3 => mem.writeIntLittle(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base),187 3 => mem.writeIntLittle(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base),
188 else => unreachable,188 else => unreachable,
...@@ -206,17 +206,17 @@ fn resolveX86(self: Relocation, ctx: Context) void {...@@ -206,17 +206,17 @@ fn resolveX86(self: Relocation, ctx: Context) void {
206206
207 .got, .import => {207 .got, .import => {
208 assert(self.pcrel);208 assert(self.pcrel);
209 const disp = @intCast(i32, ctx.target_vaddr) - @intCast(i32, ctx.source_vaddr) - 4;209 const disp = @as(i32, @intCast(ctx.target_vaddr)) - @as(i32, @intCast(ctx.source_vaddr)) - 4;
210 mem.writeIntLittle(i32, buffer[0..4], disp);210 mem.writeIntLittle(i32, buffer[0..4], disp);
211 },211 },
212 .direct => {212 .direct => {
213 if (self.pcrel) {213 if (self.pcrel) {
214 const disp = @intCast(i32, ctx.target_vaddr) - @intCast(i32, ctx.source_vaddr) - 4;214 const disp = @as(i32, @intCast(ctx.target_vaddr)) - @as(i32, @intCast(ctx.source_vaddr)) - 4;
215 mem.writeIntLittle(i32, buffer[0..4], disp);215 mem.writeIntLittle(i32, buffer[0..4], disp);
216 } else switch (ctx.ptr_width) {216 } else switch (ctx.ptr_width) {
217 .p32 => mem.writeIntLittle(u32, buffer[0..4], @intCast(u32, ctx.target_vaddr + ctx.image_base)),217 .p32 => mem.writeIntLittle(u32, buffer[0..4], @as(u32, @intCast(ctx.target_vaddr + ctx.image_base))),
218 .p64 => switch (self.length) {218 .p64 => switch (self.length) {
219 2 => mem.writeIntLittle(u32, buffer[0..4], @truncate(u32, ctx.target_vaddr + ctx.image_base)),219 2 => mem.writeIntLittle(u32, buffer[0..4], @as(u32, @truncate(ctx.target_vaddr + ctx.image_base))),
220 3 => mem.writeIntLittle(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base),220 3 => mem.writeIntLittle(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base),
221 else => unreachable,221 else => unreachable,
222 },222 },
...@@ -226,6 +226,6 @@ fn resolveX86(self: Relocation, ctx: Context) void {...@@ -226,6 +226,6 @@ fn resolveX86(self: Relocation, ctx: Context) void {
226}226}
227227
228inline fn isArithmeticOp(inst: *const [4]u8) bool {228inline fn isArithmeticOp(inst: *const [4]u8) bool {
229 const group_decode = @truncate(u5, inst[3]);229 const group_decode = @as(u5, @truncate(inst[3]));
230 return ((group_decode >> 2) == 4);230 return ((group_decode >> 2) == 4);
231}231}
src/link/Dwarf.zig+58-58
...@@ -138,7 +138,7 @@ pub const DeclState = struct {...@@ -138,7 +138,7 @@ pub const DeclState = struct {
138 /// which we use as our target of the relocation.138 /// which we use as our target of the relocation.
139 fn addTypeRelocGlobal(self: *DeclState, atom_index: Atom.Index, ty: Type, offset: u32) !void {139 fn addTypeRelocGlobal(self: *DeclState, atom_index: Atom.Index, ty: Type, offset: u32) !void {
140 const resolv = self.abbrev_resolver.get(ty.toIntern()) orelse blk: {140 const resolv = self.abbrev_resolver.get(ty.toIntern()) orelse blk: {
141 const sym_index = @intCast(u32, self.abbrev_table.items.len);141 const sym_index = @as(u32, @intCast(self.abbrev_table.items.len));
142 try self.abbrev_table.append(self.gpa, .{142 try self.abbrev_table.append(self.gpa, .{
143 .atom_index = atom_index,143 .atom_index = atom_index,
144 .type = ty,144 .type = ty,
...@@ -225,7 +225,7 @@ pub const DeclState = struct {...@@ -225,7 +225,7 @@ pub const DeclState = struct {
225 // DW.AT.type, DW.FORM.ref4225 // DW.AT.type, DW.FORM.ref4
226 var index = dbg_info_buffer.items.len;226 var index = dbg_info_buffer.items.len;
227 try dbg_info_buffer.resize(index + 4);227 try dbg_info_buffer.resize(index + 4);
228 try self.addTypeRelocGlobal(atom_index, Type.bool, @intCast(u32, index));228 try self.addTypeRelocGlobal(atom_index, Type.bool, @as(u32, @intCast(index)));
229 // DW.AT.data_member_location, DW.FORM.udata229 // DW.AT.data_member_location, DW.FORM.udata
230 try dbg_info_buffer.ensureUnusedCapacity(6);230 try dbg_info_buffer.ensureUnusedCapacity(6);
231 dbg_info_buffer.appendAssumeCapacity(0);231 dbg_info_buffer.appendAssumeCapacity(0);
...@@ -237,7 +237,7 @@ pub const DeclState = struct {...@@ -237,7 +237,7 @@ pub const DeclState = struct {
237 // DW.AT.type, DW.FORM.ref4237 // DW.AT.type, DW.FORM.ref4
238 index = dbg_info_buffer.items.len;238 index = dbg_info_buffer.items.len;
239 try dbg_info_buffer.resize(index + 4);239 try dbg_info_buffer.resize(index + 4);
240 try self.addTypeRelocGlobal(atom_index, payload_ty, @intCast(u32, index));240 try self.addTypeRelocGlobal(atom_index, payload_ty, @as(u32, @intCast(index)));
241 // DW.AT.data_member_location, DW.FORM.udata241 // DW.AT.data_member_location, DW.FORM.udata
242 const offset = abi_size - payload_ty.abiSize(mod);242 const offset = abi_size - payload_ty.abiSize(mod);
243 try leb128.writeULEB128(dbg_info_buffer.writer(), offset);243 try leb128.writeULEB128(dbg_info_buffer.writer(), offset);
...@@ -249,7 +249,7 @@ pub const DeclState = struct {...@@ -249,7 +249,7 @@ pub const DeclState = struct {
249 if (ty.isSlice(mod)) {249 if (ty.isSlice(mod)) {
250 // Slices are structs: struct { .ptr = *, .len = N }250 // Slices are structs: struct { .ptr = *, .len = N }
251 const ptr_bits = target.ptrBitWidth();251 const ptr_bits = target.ptrBitWidth();
252 const ptr_bytes = @intCast(u8, @divExact(ptr_bits, 8));252 const ptr_bytes = @as(u8, @intCast(@divExact(ptr_bits, 8)));
253 // DW.AT.structure_type253 // DW.AT.structure_type
254 try dbg_info_buffer.ensureUnusedCapacity(2);254 try dbg_info_buffer.ensureUnusedCapacity(2);
255 dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevKind.struct_type));255 dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevKind.struct_type));
...@@ -267,7 +267,7 @@ pub const DeclState = struct {...@@ -267,7 +267,7 @@ pub const DeclState = struct {
267 var index = dbg_info_buffer.items.len;267 var index = dbg_info_buffer.items.len;
268 try dbg_info_buffer.resize(index + 4);268 try dbg_info_buffer.resize(index + 4);
269 const ptr_ty = ty.slicePtrFieldType(mod);269 const ptr_ty = ty.slicePtrFieldType(mod);
270 try self.addTypeRelocGlobal(atom_index, ptr_ty, @intCast(u32, index));270 try self.addTypeRelocGlobal(atom_index, ptr_ty, @as(u32, @intCast(index)));
271 // DW.AT.data_member_location, DW.FORM.udata271 // DW.AT.data_member_location, DW.FORM.udata
272 try dbg_info_buffer.ensureUnusedCapacity(6);272 try dbg_info_buffer.ensureUnusedCapacity(6);
273 dbg_info_buffer.appendAssumeCapacity(0);273 dbg_info_buffer.appendAssumeCapacity(0);
...@@ -279,7 +279,7 @@ pub const DeclState = struct {...@@ -279,7 +279,7 @@ pub const DeclState = struct {
279 // DW.AT.type, DW.FORM.ref4279 // DW.AT.type, DW.FORM.ref4
280 index = dbg_info_buffer.items.len;280 index = dbg_info_buffer.items.len;
281 try dbg_info_buffer.resize(index + 4);281 try dbg_info_buffer.resize(index + 4);
282 try self.addTypeRelocGlobal(atom_index, Type.usize, @intCast(u32, index));282 try self.addTypeRelocGlobal(atom_index, Type.usize, @as(u32, @intCast(index)));
283 // DW.AT.data_member_location, DW.FORM.udata283 // DW.AT.data_member_location, DW.FORM.udata
284 try dbg_info_buffer.ensureUnusedCapacity(2);284 try dbg_info_buffer.ensureUnusedCapacity(2);
285 dbg_info_buffer.appendAssumeCapacity(ptr_bytes);285 dbg_info_buffer.appendAssumeCapacity(ptr_bytes);
...@@ -291,7 +291,7 @@ pub const DeclState = struct {...@@ -291,7 +291,7 @@ pub const DeclState = struct {
291 // DW.AT.type, DW.FORM.ref4291 // DW.AT.type, DW.FORM.ref4
292 const index = dbg_info_buffer.items.len;292 const index = dbg_info_buffer.items.len;
293 try dbg_info_buffer.resize(index + 4);293 try dbg_info_buffer.resize(index + 4);
294 try self.addTypeRelocGlobal(atom_index, ty.childType(mod), @intCast(u32, index));294 try self.addTypeRelocGlobal(atom_index, ty.childType(mod), @as(u32, @intCast(index)));
295 }295 }
296 },296 },
297 .Array => {297 .Array => {
...@@ -302,13 +302,13 @@ pub const DeclState = struct {...@@ -302,13 +302,13 @@ pub const DeclState = struct {
302 // DW.AT.type, DW.FORM.ref4302 // DW.AT.type, DW.FORM.ref4
303 var index = dbg_info_buffer.items.len;303 var index = dbg_info_buffer.items.len;
304 try dbg_info_buffer.resize(index + 4);304 try dbg_info_buffer.resize(index + 4);
305 try self.addTypeRelocGlobal(atom_index, ty.childType(mod), @intCast(u32, index));305 try self.addTypeRelocGlobal(atom_index, ty.childType(mod), @as(u32, @intCast(index)));
306 // DW.AT.subrange_type306 // DW.AT.subrange_type
307 try dbg_info_buffer.append(@intFromEnum(AbbrevKind.array_dim));307 try dbg_info_buffer.append(@intFromEnum(AbbrevKind.array_dim));
308 // DW.AT.type, DW.FORM.ref4308 // DW.AT.type, DW.FORM.ref4
309 index = dbg_info_buffer.items.len;309 index = dbg_info_buffer.items.len;
310 try dbg_info_buffer.resize(index + 4);310 try dbg_info_buffer.resize(index + 4);
311 try self.addTypeRelocGlobal(atom_index, Type.usize, @intCast(u32, index));311 try self.addTypeRelocGlobal(atom_index, Type.usize, @as(u32, @intCast(index)));
312 // DW.AT.count, DW.FORM.udata312 // DW.AT.count, DW.FORM.udata
313 const len = ty.arrayLenIncludingSentinel(mod);313 const len = ty.arrayLenIncludingSentinel(mod);
314 try leb128.writeULEB128(dbg_info_buffer.writer(), len);314 try leb128.writeULEB128(dbg_info_buffer.writer(), len);
...@@ -334,7 +334,7 @@ pub const DeclState = struct {...@@ -334,7 +334,7 @@ pub const DeclState = struct {
334 // DW.AT.type, DW.FORM.ref4334 // DW.AT.type, DW.FORM.ref4
335 var index = dbg_info_buffer.items.len;335 var index = dbg_info_buffer.items.len;
336 try dbg_info_buffer.resize(index + 4);336 try dbg_info_buffer.resize(index + 4);
337 try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(u32, index));337 try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @as(u32, @intCast(index)));
338 // DW.AT.data_member_location, DW.FORM.udata338 // DW.AT.data_member_location, DW.FORM.udata
339 const field_off = ty.structFieldOffset(field_index, mod);339 const field_off = ty.structFieldOffset(field_index, mod);
340 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);340 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);
...@@ -367,7 +367,7 @@ pub const DeclState = struct {...@@ -367,7 +367,7 @@ pub const DeclState = struct {
367 // DW.AT.type, DW.FORM.ref4367 // DW.AT.type, DW.FORM.ref4
368 var index = dbg_info_buffer.items.len;368 var index = dbg_info_buffer.items.len;
369 try dbg_info_buffer.resize(index + 4);369 try dbg_info_buffer.resize(index + 4);
370 try self.addTypeRelocGlobal(atom_index, field.ty, @intCast(u32, index));370 try self.addTypeRelocGlobal(atom_index, field.ty, @as(u32, @intCast(index)));
371 // DW.AT.data_member_location, DW.FORM.udata371 // DW.AT.data_member_location, DW.FORM.udata
372 const field_off = ty.structFieldOffset(field_index, mod);372 const field_off = ty.structFieldOffset(field_index, mod);
373 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);373 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);
...@@ -404,7 +404,7 @@ pub const DeclState = struct {...@@ -404,7 +404,7 @@ pub const DeclState = struct {
404 // TODO do not assume a 64bit enum value - could be bigger.404 // TODO do not assume a 64bit enum value - could be bigger.
405 // See https://github.com/ziglang/zig/issues/645405 // See https://github.com/ziglang/zig/issues/645
406 const field_int_val = try value.toValue().intFromEnum(ty, mod);406 const field_int_val = try value.toValue().intFromEnum(ty, mod);
407 break :value @bitCast(u64, field_int_val.toSignedInt(mod));407 break :value @as(u64, @bitCast(field_int_val.toSignedInt(mod)));
408 };408 };
409 mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), value, target_endian);409 mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), value, target_endian);
410 }410 }
...@@ -439,7 +439,7 @@ pub const DeclState = struct {...@@ -439,7 +439,7 @@ pub const DeclState = struct {
439 // DW.AT.type, DW.FORM.ref4439 // DW.AT.type, DW.FORM.ref4
440 const inner_union_index = dbg_info_buffer.items.len;440 const inner_union_index = dbg_info_buffer.items.len;
441 try dbg_info_buffer.resize(inner_union_index + 4);441 try dbg_info_buffer.resize(inner_union_index + 4);
442 try self.addTypeRelocLocal(atom_index, @intCast(u32, inner_union_index), 5);442 try self.addTypeRelocLocal(atom_index, @as(u32, @intCast(inner_union_index)), 5);
443 // DW.AT.data_member_location, DW.FORM.udata443 // DW.AT.data_member_location, DW.FORM.udata
444 try leb128.writeULEB128(dbg_info_buffer.writer(), payload_offset);444 try leb128.writeULEB128(dbg_info_buffer.writer(), payload_offset);
445 }445 }
...@@ -468,7 +468,7 @@ pub const DeclState = struct {...@@ -468,7 +468,7 @@ pub const DeclState = struct {
468 // DW.AT.type, DW.FORM.ref4468 // DW.AT.type, DW.FORM.ref4
469 const index = dbg_info_buffer.items.len;469 const index = dbg_info_buffer.items.len;
470 try dbg_info_buffer.resize(index + 4);470 try dbg_info_buffer.resize(index + 4);
471 try self.addTypeRelocGlobal(atom_index, field.ty, @intCast(u32, index));471 try self.addTypeRelocGlobal(atom_index, field.ty, @as(u32, @intCast(index)));
472 // DW.AT.data_member_location, DW.FORM.udata472 // DW.AT.data_member_location, DW.FORM.udata
473 try dbg_info_buffer.append(0);473 try dbg_info_buffer.append(0);
474 }474 }
...@@ -485,7 +485,7 @@ pub const DeclState = struct {...@@ -485,7 +485,7 @@ pub const DeclState = struct {
485 // DW.AT.type, DW.FORM.ref4485 // DW.AT.type, DW.FORM.ref4
486 const index = dbg_info_buffer.items.len;486 const index = dbg_info_buffer.items.len;
487 try dbg_info_buffer.resize(index + 4);487 try dbg_info_buffer.resize(index + 4);
488 try self.addTypeRelocGlobal(atom_index, union_obj.tag_ty, @intCast(u32, index));488 try self.addTypeRelocGlobal(atom_index, union_obj.tag_ty, @as(u32, @intCast(index)));
489 // DW.AT.data_member_location, DW.FORM.udata489 // DW.AT.data_member_location, DW.FORM.udata
490 try leb128.writeULEB128(dbg_info_buffer.writer(), tag_offset);490 try leb128.writeULEB128(dbg_info_buffer.writer(), tag_offset);
491491
...@@ -521,7 +521,7 @@ pub const DeclState = struct {...@@ -521,7 +521,7 @@ pub const DeclState = struct {
521 // DW.AT.type, DW.FORM.ref4521 // DW.AT.type, DW.FORM.ref4
522 const index = dbg_info_buffer.items.len;522 const index = dbg_info_buffer.items.len;
523 try dbg_info_buffer.resize(index + 4);523 try dbg_info_buffer.resize(index + 4);
524 try self.addTypeRelocGlobal(atom_index, payload_ty, @intCast(u32, index));524 try self.addTypeRelocGlobal(atom_index, payload_ty, @as(u32, @intCast(index)));
525 // DW.AT.data_member_location, DW.FORM.udata525 // DW.AT.data_member_location, DW.FORM.udata
526 try leb128.writeULEB128(dbg_info_buffer.writer(), payload_off);526 try leb128.writeULEB128(dbg_info_buffer.writer(), payload_off);
527 }527 }
...@@ -536,7 +536,7 @@ pub const DeclState = struct {...@@ -536,7 +536,7 @@ pub const DeclState = struct {
536 // DW.AT.type, DW.FORM.ref4536 // DW.AT.type, DW.FORM.ref4
537 const index = dbg_info_buffer.items.len;537 const index = dbg_info_buffer.items.len;
538 try dbg_info_buffer.resize(index + 4);538 try dbg_info_buffer.resize(index + 4);
539 try self.addTypeRelocGlobal(atom_index, error_ty, @intCast(u32, index));539 try self.addTypeRelocGlobal(atom_index, error_ty, @as(u32, @intCast(index)));
540 // DW.AT.data_member_location, DW.FORM.udata540 // DW.AT.data_member_location, DW.FORM.udata
541 try leb128.writeULEB128(dbg_info_buffer.writer(), error_off);541 try leb128.writeULEB128(dbg_info_buffer.writer(), error_off);
542 }542 }
...@@ -640,7 +640,7 @@ pub const DeclState = struct {...@@ -640,7 +640,7 @@ pub const DeclState = struct {
640 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);640 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
641 const index = dbg_info.items.len;641 const index = dbg_info.items.len;
642 try dbg_info.resize(index + 4); // dw.at.type, dw.form.ref4642 try dbg_info.resize(index + 4); // dw.at.type, dw.form.ref4
643 try self.addTypeRelocGlobal(atom_index, ty, @intCast(u32, index)); // DW.AT.type, DW.FORM.ref4643 try self.addTypeRelocGlobal(atom_index, ty, @as(u32, @intCast(index))); // DW.AT.type, DW.FORM.ref4
644 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string644 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
645 }645 }
646646
...@@ -723,20 +723,20 @@ pub const DeclState = struct {...@@ -723,20 +723,20 @@ pub const DeclState = struct {
723 .memory,723 .memory,
724 .linker_load,724 .linker_load,
725 => {725 => {
726 const ptr_width = @intCast(u8, @divExact(target.ptrBitWidth(), 8));726 const ptr_width = @as(u8, @intCast(@divExact(target.ptrBitWidth(), 8)));
727 try dbg_info.ensureUnusedCapacity(2 + ptr_width);727 try dbg_info.ensureUnusedCapacity(2 + ptr_width);
728 dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc728 dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc
729 1 + ptr_width + @intFromBool(is_ptr),729 1 + ptr_width + @intFromBool(is_ptr),
730 DW.OP.addr, // literal address730 DW.OP.addr, // literal address
731 });731 });
732 const offset = @intCast(u32, dbg_info.items.len);732 const offset = @as(u32, @intCast(dbg_info.items.len));
733 const addr = switch (loc) {733 const addr = switch (loc) {
734 .memory => |x| x,734 .memory => |x| x,
735 else => 0,735 else => 0,
736 };736 };
737 switch (ptr_width) {737 switch (ptr_width) {
738 0...4 => {738 0...4 => {
739 try dbg_info.writer().writeInt(u32, @intCast(u32, addr), endian);739 try dbg_info.writer().writeInt(u32, @as(u32, @intCast(addr)), endian);
740 },740 },
741 5...8 => {741 5...8 => {
742 try dbg_info.writer().writeInt(u64, addr, endian);742 try dbg_info.writer().writeInt(u64, addr, endian);
...@@ -765,19 +765,19 @@ pub const DeclState = struct {...@@ -765,19 +765,19 @@ pub const DeclState = struct {
765 if (child_ty.isSignedInt(mod)) DW.OP.consts else DW.OP.constu,765 if (child_ty.isSignedInt(mod)) DW.OP.consts else DW.OP.constu,
766 });766 });
767 if (child_ty.isSignedInt(mod)) {767 if (child_ty.isSignedInt(mod)) {
768 try leb128.writeILEB128(dbg_info.writer(), @bitCast(i64, x));768 try leb128.writeILEB128(dbg_info.writer(), @as(i64, @bitCast(x)));
769 } else {769 } else {
770 try leb128.writeULEB128(dbg_info.writer(), x);770 try leb128.writeULEB128(dbg_info.writer(), x);
771 }771 }
772 try dbg_info.append(DW.OP.stack_value);772 try dbg_info.append(DW.OP.stack_value);
773 dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2);773 dbg_info.items[fixup] += @as(u8, @intCast(dbg_info.items.len - fixup - 2));
774 },774 },
775775
776 .undef => {776 .undef => {
777 // DW.AT.location, DW.FORM.exprloc777 // DW.AT.location, DW.FORM.exprloc
778 // uleb128(exprloc_len)778 // uleb128(exprloc_len)
779 // DW.OP.implicit_value uleb128(len_of_bytes) bytes779 // DW.OP.implicit_value uleb128(len_of_bytes) bytes
780 const abi_size = @intCast(u32, child_ty.abiSize(mod));780 const abi_size = @as(u32, @intCast(child_ty.abiSize(mod)));
781 var implicit_value_len = std.ArrayList(u8).init(self.gpa);781 var implicit_value_len = std.ArrayList(u8).init(self.gpa);
782 defer implicit_value_len.deinit();782 defer implicit_value_len.deinit();
783 try leb128.writeULEB128(implicit_value_len.writer(), abi_size);783 try leb128.writeULEB128(implicit_value_len.writer(), abi_size);
...@@ -807,7 +807,7 @@ pub const DeclState = struct {...@@ -807,7 +807,7 @@ pub const DeclState = struct {
807 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);807 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
808 const index = dbg_info.items.len;808 const index = dbg_info.items.len;
809 try dbg_info.resize(index + 4); // dw.at.type, dw.form.ref4809 try dbg_info.resize(index + 4); // dw.at.type, dw.form.ref4
810 try self.addTypeRelocGlobal(atom_index, child_ty, @intCast(u32, index));810 try self.addTypeRelocGlobal(atom_index, child_ty, @as(u32, @intCast(index)));
811 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string811 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
812 }812 }
813813
...@@ -963,7 +963,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index)...@@ -963,7 +963,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index)
963 func.lbrace_line,963 func.lbrace_line,
964 func.rbrace_line,964 func.rbrace_line,
965 });965 });
966 const line = @intCast(u28, decl.src_line + func.lbrace_line);966 const line = @as(u28, @intCast(decl.src_line + func.lbrace_line));
967967
968 const ptr_width_bytes = self.ptrWidthBytes();968 const ptr_width_bytes = self.ptrWidthBytes();
969 dbg_line_buffer.appendSliceAssumeCapacity(&[_]u8{969 dbg_line_buffer.appendSliceAssumeCapacity(&[_]u8{
...@@ -1013,7 +1013,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index)...@@ -1013,7 +1013,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index)
1013 dbg_info_buffer.items.len += 4; // DW.AT.high_pc, DW.FORM.data41013 dbg_info_buffer.items.len += 4; // DW.AT.high_pc, DW.FORM.data4
1014 //1014 //
1015 if (fn_ret_has_bits) {1015 if (fn_ret_has_bits) {
1016 try decl_state.addTypeRelocGlobal(di_atom_index, fn_ret_type, @intCast(u32, dbg_info_buffer.items.len));1016 try decl_state.addTypeRelocGlobal(di_atom_index, fn_ret_type, @as(u32, @intCast(dbg_info_buffer.items.len)));
1017 dbg_info_buffer.items.len += 4; // DW.AT.type, DW.FORM.ref41017 dbg_info_buffer.items.len += 4; // DW.AT.type, DW.FORM.ref4
1018 }1018 }
10191019
...@@ -1055,11 +1055,11 @@ pub fn commitDeclState(...@@ -1055,11 +1055,11 @@ pub fn commitDeclState(
1055 .p32 => {1055 .p32 => {
1056 {1056 {
1057 const ptr = dbg_line_buffer.items[dbg_line_vaddr_reloc_index..][0..4];1057 const ptr = dbg_line_buffer.items[dbg_line_vaddr_reloc_index..][0..4];
1058 mem.writeInt(u32, ptr, @intCast(u32, sym_addr), target_endian);1058 mem.writeInt(u32, ptr, @as(u32, @intCast(sym_addr)), target_endian);
1059 }1059 }
1060 {1060 {
1061 const ptr = dbg_info_buffer.items[dbg_info_low_pc_reloc_index..][0..4];1061 const ptr = dbg_info_buffer.items[dbg_info_low_pc_reloc_index..][0..4];
1062 mem.writeInt(u32, ptr, @intCast(u32, sym_addr), target_endian);1062 mem.writeInt(u32, ptr, @as(u32, @intCast(sym_addr)), target_endian);
1063 }1063 }
1064 },1064 },
1065 .p64 => {1065 .p64 => {
...@@ -1079,7 +1079,7 @@ pub fn commitDeclState(...@@ -1079,7 +1079,7 @@ pub fn commitDeclState(
1079 sym_size,1079 sym_size,
1080 });1080 });
1081 const ptr = dbg_info_buffer.items[self.getRelocDbgInfoSubprogramHighPC()..][0..4];1081 const ptr = dbg_info_buffer.items[self.getRelocDbgInfoSubprogramHighPC()..][0..4];
1082 mem.writeInt(u32, ptr, @intCast(u32, sym_size), target_endian);1082 mem.writeInt(u32, ptr, @as(u32, @intCast(sym_size)), target_endian);
1083 }1083 }
10841084
1085 try dbg_line_buffer.appendSlice(&[_]u8{ DW.LNS.extended_op, 1, DW.LNE.end_sequence });1085 try dbg_line_buffer.appendSlice(&[_]u8{ DW.LNS.extended_op, 1, DW.LNE.end_sequence });
...@@ -1091,7 +1091,7 @@ pub fn commitDeclState(...@@ -1091,7 +1091,7 @@ pub fn commitDeclState(
1091 // probably need to edit that logic too.1091 // probably need to edit that logic too.
1092 const src_fn_index = self.src_fn_decls.get(decl_index).?;1092 const src_fn_index = self.src_fn_decls.get(decl_index).?;
1093 const src_fn = self.getAtomPtr(.src_fn, src_fn_index);1093 const src_fn = self.getAtomPtr(.src_fn, src_fn_index);
1094 src_fn.len = @intCast(u32, dbg_line_buffer.items.len);1094 src_fn.len = @as(u32, @intCast(dbg_line_buffer.items.len));
10951095
1096 if (self.src_fn_last_index) |last_index| blk: {1096 if (self.src_fn_last_index) |last_index| blk: {
1097 if (src_fn_index == last_index) break :blk;1097 if (src_fn_index == last_index) break :blk;
...@@ -1254,12 +1254,12 @@ pub fn commitDeclState(...@@ -1254,12 +1254,12 @@ pub fn commitDeclState(
1254 };1254 };
1255 if (deferred) continue;1255 if (deferred) continue;
12561256
1257 symbol.offset = @intCast(u32, dbg_info_buffer.items.len);1257 symbol.offset = @as(u32, @intCast(dbg_info_buffer.items.len));
1258 try decl_state.addDbgInfoType(mod, di_atom_index, ty);1258 try decl_state.addDbgInfoType(mod, di_atom_index, ty);
1259 }1259 }
1260 }1260 }
12611261
1262 try self.updateDeclDebugInfoAllocation(di_atom_index, @intCast(u32, dbg_info_buffer.items.len));1262 try self.updateDeclDebugInfoAllocation(di_atom_index, @as(u32, @intCast(dbg_info_buffer.items.len)));
12631263
1264 while (decl_state.abbrev_relocs.popOrNull()) |reloc| {1264 while (decl_state.abbrev_relocs.popOrNull()) |reloc| {
1265 if (reloc.target) |target| {1265 if (reloc.target) |target| {
...@@ -1402,7 +1402,7 @@ fn updateDeclDebugInfoAllocation(self: *Dwarf, atom_index: Atom.Index, len: u32)...@@ -1402,7 +1402,7 @@ fn updateDeclDebugInfoAllocation(self: *Dwarf, atom_index: Atom.Index, len: u32)
1402 self.di_atom_first_index = atom_index;1402 self.di_atom_first_index = atom_index;
1403 self.di_atom_last_index = atom_index;1403 self.di_atom_last_index = atom_index;
14041404
1405 atom.off = @intCast(u32, padToIdeal(self.dbgInfoHeaderBytes()));1405 atom.off = @as(u32, @intCast(padToIdeal(self.dbgInfoHeaderBytes())));
1406 }1406 }
1407}1407}
14081408
...@@ -1513,7 +1513,7 @@ pub fn updateDeclLineNumber(self: *Dwarf, mod: *Module, decl_index: Module.Decl....@@ -1513,7 +1513,7 @@ pub fn updateDeclLineNumber(self: *Dwarf, mod: *Module, decl_index: Module.Decl.
1513 func.lbrace_line,1513 func.lbrace_line,
1514 func.rbrace_line,1514 func.rbrace_line,
1515 });1515 });
1516 const line = @intCast(u28, decl.src_line + func.lbrace_line);1516 const line = @as(u28, @intCast(decl.src_line + func.lbrace_line));
1517 var data: [4]u8 = undefined;1517 var data: [4]u8 = undefined;
1518 leb128.writeUnsignedFixed(4, &data, line);1518 leb128.writeUnsignedFixed(4, &data, line);
15191519
...@@ -1791,10 +1791,10 @@ pub fn writeDbgInfoHeader(self: *Dwarf, module: *Module, low_pc: u64, high_pc: u...@@ -1791,10 +1791,10 @@ pub fn writeDbgInfoHeader(self: *Dwarf, module: *Module, low_pc: u64, high_pc: u
1791 const dbg_info_end = self.getDebugInfoEnd().? + 1;1791 const dbg_info_end = self.getDebugInfoEnd().? + 1;
1792 const init_len = dbg_info_end - after_init_len;1792 const init_len = dbg_info_end - after_init_len;
1793 if (self.bin_file.tag == .macho) {1793 if (self.bin_file.tag == .macho) {
1794 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, init_len));1794 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @as(u32, @intCast(init_len)));
1795 } else switch (self.ptr_width) {1795 } else switch (self.ptr_width) {
1796 .p32 => {1796 .p32 => {
1797 mem.writeInt(u32, di_buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, init_len), target_endian);1797 mem.writeInt(u32, di_buf.addManyAsArrayAssumeCapacity(4), @as(u32, @intCast(init_len)), target_endian);
1798 },1798 },
1799 .p64 => {1799 .p64 => {
1800 di_buf.appendNTimesAssumeCapacity(0xff, 4);1800 di_buf.appendNTimesAssumeCapacity(0xff, 4);
...@@ -1804,11 +1804,11 @@ pub fn writeDbgInfoHeader(self: *Dwarf, module: *Module, low_pc: u64, high_pc: u...@@ -1804,11 +1804,11 @@ pub fn writeDbgInfoHeader(self: *Dwarf, module: *Module, low_pc: u64, high_pc: u
1804 mem.writeInt(u16, di_buf.addManyAsArrayAssumeCapacity(2), 4, target_endian); // DWARF version1804 mem.writeInt(u16, di_buf.addManyAsArrayAssumeCapacity(2), 4, target_endian); // DWARF version
1805 const abbrev_offset = self.abbrev_table_offset.?;1805 const abbrev_offset = self.abbrev_table_offset.?;
1806 if (self.bin_file.tag == .macho) {1806 if (self.bin_file.tag == .macho) {
1807 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, abbrev_offset));1807 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @as(u32, @intCast(abbrev_offset)));
1808 di_buf.appendAssumeCapacity(8); // address size1808 di_buf.appendAssumeCapacity(8); // address size
1809 } else switch (self.ptr_width) {1809 } else switch (self.ptr_width) {
1810 .p32 => {1810 .p32 => {
1811 mem.writeInt(u32, di_buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, abbrev_offset), target_endian);1811 mem.writeInt(u32, di_buf.addManyAsArrayAssumeCapacity(4), @as(u32, @intCast(abbrev_offset)), target_endian);
1812 di_buf.appendAssumeCapacity(4); // address size1812 di_buf.appendAssumeCapacity(4); // address size
1813 },1813 },
1814 .p64 => {1814 .p64 => {
...@@ -1828,9 +1828,9 @@ pub fn writeDbgInfoHeader(self: *Dwarf, module: *Module, low_pc: u64, high_pc: u...@@ -1828,9 +1828,9 @@ pub fn writeDbgInfoHeader(self: *Dwarf, module: *Module, low_pc: u64, high_pc: u
1828 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), 0); // DW.AT.stmt_list, DW.FORM.sec_offset1828 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), 0); // DW.AT.stmt_list, DW.FORM.sec_offset
1829 mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), low_pc);1829 mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), low_pc);
1830 mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), high_pc);1830 mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), high_pc);
1831 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, name_strp));1831 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @as(u32, @intCast(name_strp)));
1832 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, comp_dir_strp));1832 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @as(u32, @intCast(comp_dir_strp)));
1833 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, producer_strp));1833 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @as(u32, @intCast(producer_strp)));
1834 } else {1834 } else {
1835 self.writeAddrAssumeCapacity(&di_buf, 0); // DW.AT.stmt_list, DW.FORM.sec_offset1835 self.writeAddrAssumeCapacity(&di_buf, 0); // DW.AT.stmt_list, DW.FORM.sec_offset
1836 self.writeAddrAssumeCapacity(&di_buf, low_pc);1836 self.writeAddrAssumeCapacity(&di_buf, low_pc);
...@@ -1885,7 +1885,7 @@ fn resolveCompilationDir(module: *Module, buffer: *[std.fs.MAX_PATH_BYTES]u8) []...@@ -1885,7 +1885,7 @@ fn resolveCompilationDir(module: *Module, buffer: *[std.fs.MAX_PATH_BYTES]u8) []
1885fn writeAddrAssumeCapacity(self: *Dwarf, buf: *std.ArrayList(u8), addr: u64) void {1885fn writeAddrAssumeCapacity(self: *Dwarf, buf: *std.ArrayList(u8), addr: u64) void {
1886 const target_endian = self.target.cpu.arch.endian();1886 const target_endian = self.target.cpu.arch.endian();
1887 switch (self.ptr_width) {1887 switch (self.ptr_width) {
1888 .p32 => mem.writeInt(u32, buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, addr), target_endian),1888 .p32 => mem.writeInt(u32, buf.addManyAsArrayAssumeCapacity(4), @as(u32, @intCast(addr)), target_endian),
1889 .p64 => mem.writeInt(u64, buf.addManyAsArrayAssumeCapacity(8), addr, target_endian),1889 .p64 => mem.writeInt(u64, buf.addManyAsArrayAssumeCapacity(8), addr, target_endian),
1890 }1890 }
1891}1891}
...@@ -2152,10 +2152,10 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void {...@@ -2152,10 +2152,10 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void {
2152 // Go back and populate the initial length.2152 // Go back and populate the initial length.
2153 const init_len = di_buf.items.len - after_init_len;2153 const init_len = di_buf.items.len - after_init_len;
2154 if (self.bin_file.tag == .macho) {2154 if (self.bin_file.tag == .macho) {
2155 mem.writeIntLittle(u32, di_buf.items[init_len_index..][0..4], @intCast(u32, init_len));2155 mem.writeIntLittle(u32, di_buf.items[init_len_index..][0..4], @as(u32, @intCast(init_len)));
2156 } else switch (self.ptr_width) {2156 } else switch (self.ptr_width) {
2157 .p32 => {2157 .p32 => {
2158 mem.writeInt(u32, di_buf.items[init_len_index..][0..4], @intCast(u32, init_len), target_endian);2158 mem.writeInt(u32, di_buf.items[init_len_index..][0..4], @as(u32, @intCast(init_len)), target_endian);
2159 },2159 },
2160 .p64 => {2160 .p64 => {
2161 // initial length - length of the .debug_aranges contribution for this compilation unit,2161 // initial length - length of the .debug_aranges contribution for this compilation unit,
...@@ -2165,7 +2165,7 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void {...@@ -2165,7 +2165,7 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void {
2165 },2165 },
2166 }2166 }
21672167
2168 const needed_size = @intCast(u32, di_buf.items.len);2168 const needed_size = @as(u32, @intCast(di_buf.items.len));
2169 switch (self.bin_file.tag) {2169 switch (self.bin_file.tag) {
2170 .elf => {2170 .elf => {
2171 const elf_file = self.bin_file.cast(File.Elf).?;2171 const elf_file = self.bin_file.cast(File.Elf).?;
...@@ -2293,7 +2293,7 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {...@@ -2293,7 +2293,7 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {
2293 di_buf.appendSliceAssumeCapacity(file);2293 di_buf.appendSliceAssumeCapacity(file);
2294 di_buf.appendSliceAssumeCapacity(&[_]u8{2294 di_buf.appendSliceAssumeCapacity(&[_]u8{
2295 0, // null byte for the relative path name2295 0, // null byte for the relative path name
2296 @intCast(u8, dir_index), // directory_index2296 @as(u8, @intCast(dir_index)), // directory_index
2297 0, // mtime (TODO supply this)2297 0, // mtime (TODO supply this)
2298 0, // file size bytes (TODO supply this)2298 0, // file size bytes (TODO supply this)
2299 });2299 });
...@@ -2304,11 +2304,11 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {...@@ -2304,11 +2304,11 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {
23042304
2305 switch (self.bin_file.tag) {2305 switch (self.bin_file.tag) {
2306 .macho => {2306 .macho => {
2307 mem.writeIntLittle(u32, di_buf.items[before_header_len..][0..4], @intCast(u32, header_len));2307 mem.writeIntLittle(u32, di_buf.items[before_header_len..][0..4], @as(u32, @intCast(header_len)));
2308 },2308 },
2309 else => switch (self.ptr_width) {2309 else => switch (self.ptr_width) {
2310 .p32 => {2310 .p32 => {
2311 mem.writeInt(u32, di_buf.items[before_header_len..][0..4], @intCast(u32, header_len), target_endian);2311 mem.writeInt(u32, di_buf.items[before_header_len..][0..4], @as(u32, @intCast(header_len)), target_endian);
2312 },2312 },
2313 .p64 => {2313 .p64 => {
2314 mem.writeInt(u64, di_buf.items[before_header_len..][0..8], header_len, target_endian);2314 mem.writeInt(u64, di_buf.items[before_header_len..][0..8], header_len, target_endian);
...@@ -2348,7 +2348,7 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {...@@ -2348,7 +2348,7 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {
2348 .macho => {2348 .macho => {
2349 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;2349 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
2350 const sect_index = d_sym.debug_line_section_index.?;2350 const sect_index = d_sym.debug_line_section_index.?;
2351 const needed_size = @intCast(u32, d_sym.getSection(sect_index).size + delta);2351 const needed_size = @as(u32, @intCast(d_sym.getSection(sect_index).size + delta));
2352 try d_sym.growSection(sect_index, needed_size, true);2352 try d_sym.growSection(sect_index, needed_size, true);
2353 const file_pos = d_sym.getSection(sect_index).offset + first_fn.off;2353 const file_pos = d_sym.getSection(sect_index).offset + first_fn.off;
23542354
...@@ -2384,11 +2384,11 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {...@@ -2384,11 +2384,11 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {
2384 const init_len = self.getDebugLineProgramEnd().? - before_init_len - init_len_size;2384 const init_len = self.getDebugLineProgramEnd().? - before_init_len - init_len_size;
2385 switch (self.bin_file.tag) {2385 switch (self.bin_file.tag) {
2386 .macho => {2386 .macho => {
2387 mem.writeIntLittle(u32, di_buf.items[before_init_len..][0..4], @intCast(u32, init_len));2387 mem.writeIntLittle(u32, di_buf.items[before_init_len..][0..4], @as(u32, @intCast(init_len)));
2388 },2388 },
2389 else => switch (self.ptr_width) {2389 else => switch (self.ptr_width) {
2390 .p32 => {2390 .p32 => {
2391 mem.writeInt(u32, di_buf.items[before_init_len..][0..4], @intCast(u32, init_len), target_endian);2391 mem.writeInt(u32, di_buf.items[before_init_len..][0..4], @as(u32, @intCast(init_len)), target_endian);
2392 },2392 },
2393 .p64 => {2393 .p64 => {
2394 mem.writeInt(u64, di_buf.items[before_init_len + 4 ..][0..8], init_len, target_endian);2394 mem.writeInt(u64, di_buf.items[before_init_len + 4 ..][0..8], init_len, target_endian);
...@@ -2477,7 +2477,7 @@ fn dbgLineNeededHeaderBytes(self: Dwarf, dirs: []const []const u8, files: []cons...@@ -2477,7 +2477,7 @@ fn dbgLineNeededHeaderBytes(self: Dwarf, dirs: []const []const u8, files: []cons
2477 }2477 }
2478 size += 1; // file names sentinel2478 size += 1; // file names sentinel
24792479
2480 return @intCast(u32, size);2480 return @as(u32, @intCast(size));
2481}2481}
24822482
2483/// The reloc offset for the line offset of a function from the previous function's line.2483/// The reloc offset for the line offset of a function from the previous function's line.
...@@ -2516,7 +2516,7 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void {...@@ -2516,7 +2516,7 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void {
25162516
2517 const di_atom_index = try self.createAtom(.di_atom);2517 const di_atom_index = try self.createAtom(.di_atom);
2518 log.debug("updateDeclDebugInfoAllocation in flushModule", .{});2518 log.debug("updateDeclDebugInfoAllocation in flushModule", .{});
2519 try self.updateDeclDebugInfoAllocation(di_atom_index, @intCast(u32, dbg_info_buffer.items.len));2519 try self.updateDeclDebugInfoAllocation(di_atom_index, @as(u32, @intCast(dbg_info_buffer.items.len)));
2520 log.debug("writeDeclDebugInfo in flushModule", .{});2520 log.debug("writeDeclDebugInfo in flushModule", .{});
2521 try self.writeDeclDebugInfo(di_atom_index, dbg_info_buffer.items);2521 try self.writeDeclDebugInfo(di_atom_index, dbg_info_buffer.items);
25222522
...@@ -2581,7 +2581,7 @@ fn addDIFile(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index) !u28 {...@@ -2581,7 +2581,7 @@ fn addDIFile(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index) !u28 {
2581 else => unreachable,2581 else => unreachable,
2582 }2582 }
2583 }2583 }
2584 return @intCast(u28, gop.index + 1);2584 return @as(u28, @intCast(gop.index + 1));
2585}2585}
25862586
2587fn genIncludeDirsAndFileNames(self: *Dwarf, arena: Allocator) !struct {2587fn genIncludeDirsAndFileNames(self: *Dwarf, arena: Allocator) !struct {
...@@ -2614,7 +2614,7 @@ fn genIncludeDirsAndFileNames(self: *Dwarf, arena: Allocator) !struct {...@@ -2614,7 +2614,7 @@ fn genIncludeDirsAndFileNames(self: *Dwarf, arena: Allocator) !struct {
26142614
2615 const dir_index: u28 = blk: {2615 const dir_index: u28 = blk: {
2616 const dirs_gop = dirs.getOrPutAssumeCapacity(dir_path);2616 const dirs_gop = dirs.getOrPutAssumeCapacity(dir_path);
2617 break :blk @intCast(u28, dirs_gop.index + 1);2617 break :blk @as(u28, @intCast(dirs_gop.index + 1));
2618 };2618 };
26192619
2620 files_dir_indexes.appendAssumeCapacity(dir_index);2620 files_dir_indexes.appendAssumeCapacity(dir_index);
...@@ -2679,12 +2679,12 @@ fn createAtom(self: *Dwarf, comptime kind: Kind) !Atom.Index {...@@ -2679,12 +2679,12 @@ fn createAtom(self: *Dwarf, comptime kind: Kind) !Atom.Index {
2679 const index = blk: {2679 const index = blk: {
2680 switch (kind) {2680 switch (kind) {
2681 .src_fn => {2681 .src_fn => {
2682 const index = @intCast(Atom.Index, self.src_fns.items.len);2682 const index = @as(Atom.Index, @intCast(self.src_fns.items.len));
2683 _ = try self.src_fns.addOne(self.allocator);2683 _ = try self.src_fns.addOne(self.allocator);
2684 break :blk index;2684 break :blk index;
2685 },2685 },
2686 .di_atom => {2686 .di_atom => {
2687 const index = @intCast(Atom.Index, self.di_atoms.items.len);2687 const index = @as(Atom.Index, @intCast(self.di_atoms.items.len));
2688 _ = try self.di_atoms.addOne(self.allocator);2688 _ = try self.di_atoms.addOne(self.allocator);
2689 break :blk index;2689 break :blk index;
2690 },2690 },
src/link/Elf.zig+52-52
...@@ -455,7 +455,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -455,7 +455,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
455 const ptr_size: u8 = self.ptrWidthBytes();455 const ptr_size: u8 = self.ptrWidthBytes();
456456
457 if (self.phdr_table_index == null) {457 if (self.phdr_table_index == null) {
458 self.phdr_table_index = @intCast(u16, self.program_headers.items.len);458 self.phdr_table_index = @as(u16, @intCast(self.program_headers.items.len));
459 const p_align: u16 = switch (self.ptr_width) {459 const p_align: u16 = switch (self.ptr_width) {
460 .p32 => @alignOf(elf.Elf32_Phdr),460 .p32 => @alignOf(elf.Elf32_Phdr),
461 .p64 => @alignOf(elf.Elf64_Phdr),461 .p64 => @alignOf(elf.Elf64_Phdr),
...@@ -474,7 +474,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -474,7 +474,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
474 }474 }
475475
476 if (self.phdr_table_load_index == null) {476 if (self.phdr_table_load_index == null) {
477 self.phdr_table_load_index = @intCast(u16, self.program_headers.items.len);477 self.phdr_table_load_index = @as(u16, @intCast(self.program_headers.items.len));
478 // TODO Same as for GOT478 // TODO Same as for GOT
479 const phdr_addr: u64 = if (self.base.options.target.ptrBitWidth() >= 32) 0x1000000 else 0x1000;479 const phdr_addr: u64 = if (self.base.options.target.ptrBitWidth() >= 32) 0x1000000 else 0x1000;
480 const p_align = self.page_size;480 const p_align = self.page_size;
...@@ -492,7 +492,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -492,7 +492,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
492 }492 }
493493
494 if (self.phdr_load_re_index == null) {494 if (self.phdr_load_re_index == null) {
495 self.phdr_load_re_index = @intCast(u16, self.program_headers.items.len);495 self.phdr_load_re_index = @as(u16, @intCast(self.program_headers.items.len));
496 const file_size = self.base.options.program_code_size_hint;496 const file_size = self.base.options.program_code_size_hint;
497 const p_align = self.page_size;497 const p_align = self.page_size;
498 const off = self.findFreeSpace(file_size, p_align);498 const off = self.findFreeSpace(file_size, p_align);
...@@ -513,7 +513,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -513,7 +513,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
513 }513 }
514514
515 if (self.phdr_got_index == null) {515 if (self.phdr_got_index == null) {
516 self.phdr_got_index = @intCast(u16, self.program_headers.items.len);516 self.phdr_got_index = @as(u16, @intCast(self.program_headers.items.len));
517 const file_size = @as(u64, ptr_size) * self.base.options.symbol_count_hint;517 const file_size = @as(u64, ptr_size) * self.base.options.symbol_count_hint;
518 // We really only need ptr alignment but since we are using PROGBITS, linux requires518 // We really only need ptr alignment but since we are using PROGBITS, linux requires
519 // page align.519 // page align.
...@@ -538,7 +538,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -538,7 +538,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
538 }538 }
539539
540 if (self.phdr_load_ro_index == null) {540 if (self.phdr_load_ro_index == null) {
541 self.phdr_load_ro_index = @intCast(u16, self.program_headers.items.len);541 self.phdr_load_ro_index = @as(u16, @intCast(self.program_headers.items.len));
542 // TODO Find a hint about how much data need to be in rodata ?542 // TODO Find a hint about how much data need to be in rodata ?
543 const file_size = 1024;543 const file_size = 1024;
544 // Same reason as for GOT544 // Same reason as for GOT
...@@ -561,7 +561,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -561,7 +561,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
561 }561 }
562562
563 if (self.phdr_load_rw_index == null) {563 if (self.phdr_load_rw_index == null) {
564 self.phdr_load_rw_index = @intCast(u16, self.program_headers.items.len);564 self.phdr_load_rw_index = @as(u16, @intCast(self.program_headers.items.len));
565 // TODO Find a hint about how much data need to be in data ?565 // TODO Find a hint about how much data need to be in data ?
566 const file_size = 1024;566 const file_size = 1024;
567 // Same reason as for GOT567 // Same reason as for GOT
...@@ -584,7 +584,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -584,7 +584,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
584 }584 }
585585
586 if (self.shstrtab_index == null) {586 if (self.shstrtab_index == null) {
587 self.shstrtab_index = @intCast(u16, self.sections.slice().len);587 self.shstrtab_index = @as(u16, @intCast(self.sections.slice().len));
588 assert(self.shstrtab.buffer.items.len == 0);588 assert(self.shstrtab.buffer.items.len == 0);
589 try self.shstrtab.buffer.append(gpa, 0); // need a 0 at position 0589 try self.shstrtab.buffer.append(gpa, 0); // need a 0 at position 0
590 const off = self.findFreeSpace(self.shstrtab.buffer.items.len, 1);590 const off = self.findFreeSpace(self.shstrtab.buffer.items.len, 1);
...@@ -609,7 +609,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -609,7 +609,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
609 }609 }
610610
611 if (self.text_section_index == null) {611 if (self.text_section_index == null) {
612 self.text_section_index = @intCast(u16, self.sections.slice().len);612 self.text_section_index = @as(u16, @intCast(self.sections.slice().len));
613 const phdr = &self.program_headers.items[self.phdr_load_re_index.?];613 const phdr = &self.program_headers.items[self.phdr_load_re_index.?];
614614
615 try self.sections.append(gpa, .{615 try self.sections.append(gpa, .{
...@@ -631,7 +631,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -631,7 +631,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
631 }631 }
632632
633 if (self.got_section_index == null) {633 if (self.got_section_index == null) {
634 self.got_section_index = @intCast(u16, self.sections.slice().len);634 self.got_section_index = @as(u16, @intCast(self.sections.slice().len));
635 const phdr = &self.program_headers.items[self.phdr_got_index.?];635 const phdr = &self.program_headers.items[self.phdr_got_index.?];
636636
637 try self.sections.append(gpa, .{637 try self.sections.append(gpa, .{
...@@ -653,7 +653,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -653,7 +653,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
653 }653 }
654654
655 if (self.rodata_section_index == null) {655 if (self.rodata_section_index == null) {
656 self.rodata_section_index = @intCast(u16, self.sections.slice().len);656 self.rodata_section_index = @as(u16, @intCast(self.sections.slice().len));
657 const phdr = &self.program_headers.items[self.phdr_load_ro_index.?];657 const phdr = &self.program_headers.items[self.phdr_load_ro_index.?];
658658
659 try self.sections.append(gpa, .{659 try self.sections.append(gpa, .{
...@@ -675,7 +675,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -675,7 +675,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
675 }675 }
676676
677 if (self.data_section_index == null) {677 if (self.data_section_index == null) {
678 self.data_section_index = @intCast(u16, self.sections.slice().len);678 self.data_section_index = @as(u16, @intCast(self.sections.slice().len));
679 const phdr = &self.program_headers.items[self.phdr_load_rw_index.?];679 const phdr = &self.program_headers.items[self.phdr_load_rw_index.?];
680680
681 try self.sections.append(gpa, .{681 try self.sections.append(gpa, .{
...@@ -697,7 +697,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -697,7 +697,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
697 }697 }
698698
699 if (self.symtab_section_index == null) {699 if (self.symtab_section_index == null) {
700 self.symtab_section_index = @intCast(u16, self.sections.slice().len);700 self.symtab_section_index = @as(u16, @intCast(self.sections.slice().len));
701 const min_align: u16 = if (small_ptr) @alignOf(elf.Elf32_Sym) else @alignOf(elf.Elf64_Sym);701 const min_align: u16 = if (small_ptr) @alignOf(elf.Elf32_Sym) else @alignOf(elf.Elf64_Sym);
702 const each_size: u64 = if (small_ptr) @sizeOf(elf.Elf32_Sym) else @sizeOf(elf.Elf64_Sym);702 const each_size: u64 = if (small_ptr) @sizeOf(elf.Elf32_Sym) else @sizeOf(elf.Elf64_Sym);
703 const file_size = self.base.options.symbol_count_hint * each_size;703 const file_size = self.base.options.symbol_count_hint * each_size;
...@@ -714,7 +714,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -714,7 +714,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
714 .sh_size = file_size,714 .sh_size = file_size,
715 // The section header index of the associated string table.715 // The section header index of the associated string table.
716 .sh_link = self.shstrtab_index.?,716 .sh_link = self.shstrtab_index.?,
717 .sh_info = @intCast(u32, self.local_symbols.items.len),717 .sh_info = @as(u32, @intCast(self.local_symbols.items.len)),
718 .sh_addralign = min_align,718 .sh_addralign = min_align,
719 .sh_entsize = each_size,719 .sh_entsize = each_size,
720 },720 },
...@@ -726,7 +726,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -726,7 +726,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
726726
727 if (self.dwarf) |*dw| {727 if (self.dwarf) |*dw| {
728 if (self.debug_str_section_index == null) {728 if (self.debug_str_section_index == null) {
729 self.debug_str_section_index = @intCast(u16, self.sections.slice().len);729 self.debug_str_section_index = @as(u16, @intCast(self.sections.slice().len));
730 assert(dw.strtab.buffer.items.len == 0);730 assert(dw.strtab.buffer.items.len == 0);
731 try dw.strtab.buffer.append(gpa, 0);731 try dw.strtab.buffer.append(gpa, 0);
732 try self.sections.append(gpa, .{732 try self.sections.append(gpa, .{
...@@ -749,7 +749,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -749,7 +749,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
749 }749 }
750750
751 if (self.debug_info_section_index == null) {751 if (self.debug_info_section_index == null) {
752 self.debug_info_section_index = @intCast(u16, self.sections.slice().len);752 self.debug_info_section_index = @as(u16, @intCast(self.sections.slice().len));
753753
754 const file_size_hint = 200;754 const file_size_hint = 200;
755 const p_align = 1;755 const p_align = 1;
...@@ -778,7 +778,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -778,7 +778,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
778 }778 }
779779
780 if (self.debug_abbrev_section_index == null) {780 if (self.debug_abbrev_section_index == null) {
781 self.debug_abbrev_section_index = @intCast(u16, self.sections.slice().len);781 self.debug_abbrev_section_index = @as(u16, @intCast(self.sections.slice().len));
782782
783 const file_size_hint = 128;783 const file_size_hint = 128;
784 const p_align = 1;784 const p_align = 1;
...@@ -807,7 +807,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -807,7 +807,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
807 }807 }
808808
809 if (self.debug_aranges_section_index == null) {809 if (self.debug_aranges_section_index == null) {
810 self.debug_aranges_section_index = @intCast(u16, self.sections.slice().len);810 self.debug_aranges_section_index = @as(u16, @intCast(self.sections.slice().len));
811811
812 const file_size_hint = 160;812 const file_size_hint = 160;
813 const p_align = 16;813 const p_align = 16;
...@@ -836,7 +836,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -836,7 +836,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
836 }836 }
837837
838 if (self.debug_line_section_index == null) {838 if (self.debug_line_section_index == null) {
839 self.debug_line_section_index = @intCast(u16, self.sections.slice().len);839 self.debug_line_section_index = @as(u16, @intCast(self.sections.slice().len));
840840
841 const file_size_hint = 250;841 const file_size_hint = 250;
842 const p_align = 1;842 const p_align = 1;
...@@ -1100,7 +1100,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node...@@ -1100,7 +1100,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
1100 });1100 });
11011101
1102 switch (self.ptr_width) {1102 switch (self.ptr_width) {
1103 .p32 => try self.base.file.?.pwriteAll(mem.asBytes(&@intCast(u32, target_vaddr)), file_offset),1103 .p32 => try self.base.file.?.pwriteAll(mem.asBytes(&@as(u32, @intCast(target_vaddr))), file_offset),
1104 .p64 => try self.base.file.?.pwriteAll(mem.asBytes(&target_vaddr), file_offset),1104 .p64 => try self.base.file.?.pwriteAll(mem.asBytes(&target_vaddr), file_offset),
1105 }1105 }
11061106
...@@ -1170,7 +1170,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node...@@ -1170,7 +1170,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
11701170
1171 if (needed_size > allocated_size) {1171 if (needed_size > allocated_size) {
1172 phdr_table.p_offset = 0; // free the space1172 phdr_table.p_offset = 0; // free the space
1173 phdr_table.p_offset = self.findFreeSpace(needed_size, @intCast(u32, phdr_table.p_align));1173 phdr_table.p_offset = self.findFreeSpace(needed_size, @as(u32, @intCast(phdr_table.p_align)));
1174 }1174 }
11751175
1176 phdr_table_load.p_offset = mem.alignBackward(u64, phdr_table.p_offset, phdr_table_load.p_align);1176 phdr_table_load.p_offset = mem.alignBackward(u64, phdr_table.p_offset, phdr_table_load.p_align);
...@@ -2004,7 +2004,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v...@@ -2004,7 +2004,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
2004fn writeDwarfAddrAssumeCapacity(self: *Elf, buf: *std.ArrayList(u8), addr: u64) void {2004fn writeDwarfAddrAssumeCapacity(self: *Elf, buf: *std.ArrayList(u8), addr: u64) void {
2005 const target_endian = self.base.options.target.cpu.arch.endian();2005 const target_endian = self.base.options.target.cpu.arch.endian();
2006 switch (self.ptr_width) {2006 switch (self.ptr_width) {
2007 .p32 => mem.writeInt(u32, buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, addr), target_endian),2007 .p32 => mem.writeInt(u32, buf.addManyAsArrayAssumeCapacity(4), @as(u32, @intCast(addr)), target_endian),
2008 .p64 => mem.writeInt(u64, buf.addManyAsArrayAssumeCapacity(8), addr, target_endian),2008 .p64 => mem.writeInt(u64, buf.addManyAsArrayAssumeCapacity(8), addr, target_endian),
2009 }2009 }
2010}2010}
...@@ -2064,15 +2064,15 @@ fn writeElfHeader(self: *Elf) !void {...@@ -2064,15 +2064,15 @@ fn writeElfHeader(self: *Elf) !void {
2064 const phdr_table_offset = self.program_headers.items[self.phdr_table_index.?].p_offset;2064 const phdr_table_offset = self.program_headers.items[self.phdr_table_index.?].p_offset;
2065 switch (self.ptr_width) {2065 switch (self.ptr_width) {
2066 .p32 => {2066 .p32 => {
2067 mem.writeInt(u32, hdr_buf[index..][0..4], @intCast(u32, e_entry), endian);2067 mem.writeInt(u32, hdr_buf[index..][0..4], @as(u32, @intCast(e_entry)), endian);
2068 index += 4;2068 index += 4;
20692069
2070 // e_phoff2070 // e_phoff
2071 mem.writeInt(u32, hdr_buf[index..][0..4], @intCast(u32, phdr_table_offset), endian);2071 mem.writeInt(u32, hdr_buf[index..][0..4], @as(u32, @intCast(phdr_table_offset)), endian);
2072 index += 4;2072 index += 4;
20732073
2074 // e_shoff2074 // e_shoff
2075 mem.writeInt(u32, hdr_buf[index..][0..4], @intCast(u32, self.shdr_table_offset.?), endian);2075 mem.writeInt(u32, hdr_buf[index..][0..4], @as(u32, @intCast(self.shdr_table_offset.?)), endian);
2076 index += 4;2076 index += 4;
2077 },2077 },
2078 .p64 => {2078 .p64 => {
...@@ -2108,7 +2108,7 @@ fn writeElfHeader(self: *Elf) !void {...@@ -2108,7 +2108,7 @@ fn writeElfHeader(self: *Elf) !void {
2108 mem.writeInt(u16, hdr_buf[index..][0..2], e_phentsize, endian);2108 mem.writeInt(u16, hdr_buf[index..][0..2], e_phentsize, endian);
2109 index += 2;2109 index += 2;
21102110
2111 const e_phnum = @intCast(u16, self.program_headers.items.len);2111 const e_phnum = @as(u16, @intCast(self.program_headers.items.len));
2112 mem.writeInt(u16, hdr_buf[index..][0..2], e_phnum, endian);2112 mem.writeInt(u16, hdr_buf[index..][0..2], e_phnum, endian);
2113 index += 2;2113 index += 2;
21142114
...@@ -2119,7 +2119,7 @@ fn writeElfHeader(self: *Elf) !void {...@@ -2119,7 +2119,7 @@ fn writeElfHeader(self: *Elf) !void {
2119 mem.writeInt(u16, hdr_buf[index..][0..2], e_shentsize, endian);2119 mem.writeInt(u16, hdr_buf[index..][0..2], e_shentsize, endian);
2120 index += 2;2120 index += 2;
21212121
2122 const e_shnum = @intCast(u16, self.sections.slice().len);2122 const e_shnum = @as(u16, @intCast(self.sections.slice().len));
2123 mem.writeInt(u16, hdr_buf[index..][0..2], e_shnum, endian);2123 mem.writeInt(u16, hdr_buf[index..][0..2], e_shnum, endian);
2124 index += 2;2124 index += 2;
21252125
...@@ -2223,7 +2223,7 @@ fn growAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64, alignment:...@@ -2223,7 +2223,7 @@ fn growAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64, alignment:
22232223
2224pub fn createAtom(self: *Elf) !Atom.Index {2224pub fn createAtom(self: *Elf) !Atom.Index {
2225 const gpa = self.base.allocator;2225 const gpa = self.base.allocator;
2226 const atom_index = @intCast(Atom.Index, self.atoms.items.len);2226 const atom_index = @as(Atom.Index, @intCast(self.atoms.items.len));
2227 const atom = try self.atoms.addOne(gpa);2227 const atom = try self.atoms.addOne(gpa);
2228 const local_sym_index = try self.allocateLocalSymbol();2228 const local_sym_index = try self.allocateLocalSymbol();
2229 try self.atom_by_index_table.putNoClobber(gpa, local_sym_index, atom_index);2229 try self.atom_by_index_table.putNoClobber(gpa, local_sym_index, atom_index);
...@@ -2367,7 +2367,7 @@ pub fn allocateLocalSymbol(self: *Elf) !u32 {...@@ -2367,7 +2367,7 @@ pub fn allocateLocalSymbol(self: *Elf) !u32 {
2367 break :blk index;2367 break :blk index;
2368 } else {2368 } else {
2369 log.debug(" (allocating symbol index {d})", .{self.local_symbols.items.len});2369 log.debug(" (allocating symbol index {d})", .{self.local_symbols.items.len});
2370 const index = @intCast(u32, self.local_symbols.items.len);2370 const index = @as(u32, @intCast(self.local_symbols.items.len));
2371 _ = self.local_symbols.addOneAssumeCapacity();2371 _ = self.local_symbols.addOneAssumeCapacity();
2372 break :blk index;2372 break :blk index;
2373 }2373 }
...@@ -2557,7 +2557,7 @@ fn updateDeclCode(self: *Elf, decl_index: Module.Decl.Index, code: []const u8, s...@@ -2557,7 +2557,7 @@ fn updateDeclCode(self: *Elf, decl_index: Module.Decl.Index, code: []const u8, s
2557 .iov_len = code.len,2557 .iov_len = code.len,
2558 }};2558 }};
2559 var remote_vec: [1]std.os.iovec_const = .{.{2559 var remote_vec: [1]std.os.iovec_const = .{.{
2560 .iov_base = @ptrFromInt([*]u8, @intCast(usize, local_sym.st_value)),2560 .iov_base = @as([*]u8, @ptrFromInt(@as(usize, @intCast(local_sym.st_value)))),
2561 .iov_len = code.len,2561 .iov_len = code.len,
2562 }};2562 }};
2563 const rc = std.os.linux.process_vm_writev(pid, &code_vec, &remote_vec, 0);2563 const rc = std.os.linux.process_vm_writev(pid, &code_vec, &remote_vec, 0);
...@@ -2910,7 +2910,7 @@ pub fn updateDeclExports(...@@ -2910,7 +2910,7 @@ pub fn updateDeclExports(
2910 continue;2910 continue;
2911 },2911 },
2912 };2912 };
2913 const stt_bits: u8 = @truncate(u4, decl_sym.st_info);2913 const stt_bits: u8 = @as(u4, @truncate(decl_sym.st_info));
2914 if (decl_metadata.getExport(self, exp_name)) |i| {2914 if (decl_metadata.getExport(self, exp_name)) |i| {
2915 const sym = &self.global_symbols.items[i];2915 const sym = &self.global_symbols.items[i];
2916 sym.* = .{2916 sym.* = .{
...@@ -2926,7 +2926,7 @@ pub fn updateDeclExports(...@@ -2926,7 +2926,7 @@ pub fn updateDeclExports(
2926 _ = self.global_symbols.addOneAssumeCapacity();2926 _ = self.global_symbols.addOneAssumeCapacity();
2927 break :blk self.global_symbols.items.len - 1;2927 break :blk self.global_symbols.items.len - 1;
2928 };2928 };
2929 try decl_metadata.exports.append(gpa, @intCast(u32, i));2929 try decl_metadata.exports.append(gpa, @as(u32, @intCast(i)));
2930 self.global_symbols.items[i] = .{2930 self.global_symbols.items[i] = .{
2931 .st_name = try self.shstrtab.insert(gpa, exp_name),2931 .st_name = try self.shstrtab.insert(gpa, exp_name),
2932 .st_info = (stb_bits << 4) | stt_bits,2932 .st_info = (stb_bits << 4) | stt_bits,
...@@ -3030,12 +3030,12 @@ fn writeOffsetTableEntry(self: *Elf, index: @TypeOf(self.got_table).Index) !void...@@ -3030,12 +3030,12 @@ fn writeOffsetTableEntry(self: *Elf, index: @TypeOf(self.got_table).Index) !void
3030 switch (entry_size) {3030 switch (entry_size) {
3031 2 => {3031 2 => {
3032 var buf: [2]u8 = undefined;3032 var buf: [2]u8 = undefined;
3033 mem.writeInt(u16, &buf, @intCast(u16, got_value), endian);3033 mem.writeInt(u16, &buf, @as(u16, @intCast(got_value)), endian);
3034 try self.base.file.?.pwriteAll(&buf, off);3034 try self.base.file.?.pwriteAll(&buf, off);
3035 },3035 },
3036 4 => {3036 4 => {
3037 var buf: [4]u8 = undefined;3037 var buf: [4]u8 = undefined;
3038 mem.writeInt(u32, &buf, @intCast(u32, got_value), endian);3038 mem.writeInt(u32, &buf, @as(u32, @intCast(got_value)), endian);
3039 try self.base.file.?.pwriteAll(&buf, off);3039 try self.base.file.?.pwriteAll(&buf, off);
3040 },3040 },
3041 8 => {3041 8 => {
...@@ -3051,7 +3051,7 @@ fn writeOffsetTableEntry(self: *Elf, index: @TypeOf(self.got_table).Index) !void...@@ -3051,7 +3051,7 @@ fn writeOffsetTableEntry(self: *Elf, index: @TypeOf(self.got_table).Index) !void
3051 .iov_len = buf.len,3051 .iov_len = buf.len,
3052 }};3052 }};
3053 var remote_vec: [1]std.os.iovec_const = .{.{3053 var remote_vec: [1]std.os.iovec_const = .{.{
3054 .iov_base = @ptrFromInt([*]u8, @intCast(usize, vaddr)),3054 .iov_base = @as([*]u8, @ptrFromInt(@as(usize, @intCast(vaddr)))),
3055 .iov_len = buf.len,3055 .iov_len = buf.len,
3056 }};3056 }};
3057 const rc = std.os.linux.process_vm_writev(pid, &local_vec, &remote_vec, 0);3057 const rc = std.os.linux.process_vm_writev(pid, &local_vec, &remote_vec, 0);
...@@ -3086,7 +3086,7 @@ fn writeSymbol(self: *Elf, index: usize) !void {...@@ -3086,7 +3086,7 @@ fn writeSymbol(self: *Elf, index: usize) !void {
3086 };3086 };
3087 const needed_size = (self.local_symbols.items.len + self.global_symbols.items.len) * sym_size;3087 const needed_size = (self.local_symbols.items.len + self.global_symbols.items.len) * sym_size;
3088 try self.growNonAllocSection(self.symtab_section_index.?, needed_size, sym_align, true);3088 try self.growNonAllocSection(self.symtab_section_index.?, needed_size, sym_align, true);
3089 syms_sect.sh_info = @intCast(u32, self.local_symbols.items.len);3089 syms_sect.sh_info = @as(u32, @intCast(self.local_symbols.items.len));
3090 }3090 }
3091 const foreign_endian = self.base.options.target.cpu.arch.endian() != builtin.cpu.arch.endian();3091 const foreign_endian = self.base.options.target.cpu.arch.endian() != builtin.cpu.arch.endian();
3092 const off = switch (self.ptr_width) {3092 const off = switch (self.ptr_width) {
...@@ -3101,8 +3101,8 @@ fn writeSymbol(self: *Elf, index: usize) !void {...@@ -3101,8 +3101,8 @@ fn writeSymbol(self: *Elf, index: usize) !void {
3101 var sym = [1]elf.Elf32_Sym{3101 var sym = [1]elf.Elf32_Sym{
3102 .{3102 .{
3103 .st_name = local.st_name,3103 .st_name = local.st_name,
3104 .st_value = @intCast(u32, local.st_value),3104 .st_value = @as(u32, @intCast(local.st_value)),
3105 .st_size = @intCast(u32, local.st_size),3105 .st_size = @as(u32, @intCast(local.st_size)),
3106 .st_info = local.st_info,3106 .st_info = local.st_info,
3107 .st_other = local.st_other,3107 .st_other = local.st_other,
3108 .st_shndx = local.st_shndx,3108 .st_shndx = local.st_shndx,
...@@ -3148,8 +3148,8 @@ fn writeAllGlobalSymbols(self: *Elf) !void {...@@ -3148,8 +3148,8 @@ fn writeAllGlobalSymbols(self: *Elf) !void {
3148 const global = self.global_symbols.items[i];3148 const global = self.global_symbols.items[i];
3149 sym.* = .{3149 sym.* = .{
3150 .st_name = global.st_name,3150 .st_name = global.st_name,
3151 .st_value = @intCast(u32, global.st_value),3151 .st_value = @as(u32, @intCast(global.st_value)),
3152 .st_size = @intCast(u32, global.st_size),3152 .st_size = @as(u32, @intCast(global.st_size)),
3153 .st_info = global.st_info,3153 .st_info = global.st_info,
3154 .st_other = global.st_other,3154 .st_other = global.st_other,
3155 .st_shndx = global.st_shndx,3155 .st_shndx = global.st_shndx,
...@@ -3194,19 +3194,19 @@ fn ptrWidthBytes(self: Elf) u8 {...@@ -3194,19 +3194,19 @@ fn ptrWidthBytes(self: Elf) u8 {
3194/// Does not necessarily match `ptrWidthBytes` for example can be 2 bytes3194/// Does not necessarily match `ptrWidthBytes` for example can be 2 bytes
3195/// in a 32-bit ELF file.3195/// in a 32-bit ELF file.
3196fn archPtrWidthBytes(self: Elf) u8 {3196fn archPtrWidthBytes(self: Elf) u8 {
3197 return @intCast(u8, self.base.options.target.ptrBitWidth() / 8);3197 return @as(u8, @intCast(self.base.options.target.ptrBitWidth() / 8));
3198}3198}
31993199
3200fn progHeaderTo32(phdr: elf.Elf64_Phdr) elf.Elf32_Phdr {3200fn progHeaderTo32(phdr: elf.Elf64_Phdr) elf.Elf32_Phdr {
3201 return .{3201 return .{
3202 .p_type = phdr.p_type,3202 .p_type = phdr.p_type,
3203 .p_flags = phdr.p_flags,3203 .p_flags = phdr.p_flags,
3204 .p_offset = @intCast(u32, phdr.p_offset),3204 .p_offset = @as(u32, @intCast(phdr.p_offset)),
3205 .p_vaddr = @intCast(u32, phdr.p_vaddr),3205 .p_vaddr = @as(u32, @intCast(phdr.p_vaddr)),
3206 .p_paddr = @intCast(u32, phdr.p_paddr),3206 .p_paddr = @as(u32, @intCast(phdr.p_paddr)),
3207 .p_filesz = @intCast(u32, phdr.p_filesz),3207 .p_filesz = @as(u32, @intCast(phdr.p_filesz)),
3208 .p_memsz = @intCast(u32, phdr.p_memsz),3208 .p_memsz = @as(u32, @intCast(phdr.p_memsz)),
3209 .p_align = @intCast(u32, phdr.p_align),3209 .p_align = @as(u32, @intCast(phdr.p_align)),
3210 };3210 };
3211}3211}
32123212
...@@ -3214,14 +3214,14 @@ fn sectHeaderTo32(shdr: elf.Elf64_Shdr) elf.Elf32_Shdr {...@@ -3214,14 +3214,14 @@ fn sectHeaderTo32(shdr: elf.Elf64_Shdr) elf.Elf32_Shdr {
3214 return .{3214 return .{
3215 .sh_name = shdr.sh_name,3215 .sh_name = shdr.sh_name,
3216 .sh_type = shdr.sh_type,3216 .sh_type = shdr.sh_type,
3217 .sh_flags = @intCast(u32, shdr.sh_flags),3217 .sh_flags = @as(u32, @intCast(shdr.sh_flags)),
3218 .sh_addr = @intCast(u32, shdr.sh_addr),3218 .sh_addr = @as(u32, @intCast(shdr.sh_addr)),
3219 .sh_offset = @intCast(u32, shdr.sh_offset),3219 .sh_offset = @as(u32, @intCast(shdr.sh_offset)),
3220 .sh_size = @intCast(u32, shdr.sh_size),3220 .sh_size = @as(u32, @intCast(shdr.sh_size)),
3221 .sh_link = shdr.sh_link,3221 .sh_link = shdr.sh_link,
3222 .sh_info = shdr.sh_info,3222 .sh_info = shdr.sh_info,
3223 .sh_addralign = @intCast(u32, shdr.sh_addralign),3223 .sh_addralign = @as(u32, @intCast(shdr.sh_addralign)),
3224 .sh_entsize = @intCast(u32, shdr.sh_entsize),3224 .sh_entsize = @as(u32, @intCast(shdr.sh_entsize)),
3225 };3225 };
3226}3226}
32273227
src/link/MachO.zig+49-49
...@@ -741,7 +741,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -741,7 +741,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
741 };741 };
742 const sym = self.getSymbol(global);742 const sym = self.getSymbol(global);
743 try lc_writer.writeStruct(macho.entry_point_command{743 try lc_writer.writeStruct(macho.entry_point_command{
744 .entryoff = @intCast(u32, sym.n_value - seg.vmaddr),744 .entryoff = @as(u32, @intCast(sym.n_value - seg.vmaddr)),
745 .stacksize = self.base.options.stack_size_override orelse 0,745 .stacksize = self.base.options.stack_size_override orelse 0,
746 });746 });
747 },747 },
...@@ -757,7 +757,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -757,7 +757,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
757 });757 });
758 try load_commands.writeBuildVersionLC(&self.base.options, lc_writer);758 try load_commands.writeBuildVersionLC(&self.base.options, lc_writer);
759759
760 const uuid_cmd_offset = @sizeOf(macho.mach_header_64) + @intCast(u32, lc_buffer.items.len);760 const uuid_cmd_offset = @sizeOf(macho.mach_header_64) + @as(u32, @intCast(lc_buffer.items.len));
761 try lc_writer.writeStruct(self.uuid_cmd);761 try lc_writer.writeStruct(self.uuid_cmd);
762762
763 try load_commands.writeLoadDylibLCs(self.dylibs.items, self.referenced_dylibs.keys(), lc_writer);763 try load_commands.writeLoadDylibLCs(self.dylibs.items, self.referenced_dylibs.keys(), lc_writer);
...@@ -768,7 +768,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -768,7 +768,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
768768
769 const ncmds = load_commands.calcNumOfLCs(lc_buffer.items);769 const ncmds = load_commands.calcNumOfLCs(lc_buffer.items);
770 try self.base.file.?.pwriteAll(lc_buffer.items, @sizeOf(macho.mach_header_64));770 try self.base.file.?.pwriteAll(lc_buffer.items, @sizeOf(macho.mach_header_64));
771 try self.writeHeader(ncmds, @intCast(u32, lc_buffer.items.len));771 try self.writeHeader(ncmds, @as(u32, @intCast(lc_buffer.items.len)));
772 try self.writeUuid(comp, uuid_cmd_offset, requires_codesig);772 try self.writeUuid(comp, uuid_cmd_offset, requires_codesig);
773773
774 if (codesig) |*csig| {774 if (codesig) |*csig| {
...@@ -992,7 +992,7 @@ pub fn parseDylib(...@@ -992,7 +992,7 @@ pub fn parseDylib(
992 const contents = try file.readToEndAllocOptions(gpa, file_size, file_size, @alignOf(u64), null);992 const contents = try file.readToEndAllocOptions(gpa, file_size, file_size, @alignOf(u64), null);
993 defer gpa.free(contents);993 defer gpa.free(contents);
994994
995 const dylib_id = @intCast(u16, self.dylibs.items.len);995 const dylib_id = @as(u16, @intCast(self.dylibs.items.len));
996 var dylib = Dylib{ .weak = opts.weak };996 var dylib = Dylib{ .weak = opts.weak };
997997
998 dylib.parseFromBinary(998 dylib.parseFromBinary(
...@@ -1412,7 +1412,7 @@ pub fn allocateSpecialSymbols(self: *MachO) !void {...@@ -1412,7 +1412,7 @@ pub fn allocateSpecialSymbols(self: *MachO) !void {
14121412
1413pub fn createAtom(self: *MachO) !Atom.Index {1413pub fn createAtom(self: *MachO) !Atom.Index {
1414 const gpa = self.base.allocator;1414 const gpa = self.base.allocator;
1415 const atom_index = @intCast(Atom.Index, self.atoms.items.len);1415 const atom_index = @as(Atom.Index, @intCast(self.atoms.items.len));
1416 const atom = try self.atoms.addOne(gpa);1416 const atom = try self.atoms.addOne(gpa);
1417 const sym_index = try self.allocateSymbol();1417 const sym_index = try self.allocateSymbol();
1418 try self.atom_by_index_table.putNoClobber(gpa, sym_index, atom_index);1418 try self.atom_by_index_table.putNoClobber(gpa, sym_index, atom_index);
...@@ -1588,14 +1588,14 @@ fn resolveSymbolsInDylibs(self: *MachO, actions: *std.ArrayList(ResolveAction))...@@ -1588,14 +1588,14 @@ fn resolveSymbolsInDylibs(self: *MachO, actions: *std.ArrayList(ResolveAction))
1588 for (self.dylibs.items, 0..) |dylib, id| {1588 for (self.dylibs.items, 0..) |dylib, id| {
1589 if (!dylib.symbols.contains(sym_name)) continue;1589 if (!dylib.symbols.contains(sym_name)) continue;
15901590
1591 const dylib_id = @intCast(u16, id);1591 const dylib_id = @as(u16, @intCast(id));
1592 if (!self.referenced_dylibs.contains(dylib_id)) {1592 if (!self.referenced_dylibs.contains(dylib_id)) {
1593 try self.referenced_dylibs.putNoClobber(gpa, dylib_id, {});1593 try self.referenced_dylibs.putNoClobber(gpa, dylib_id, {});
1594 }1594 }
15951595
1596 const ordinal = self.referenced_dylibs.getIndex(dylib_id) orelse unreachable;1596 const ordinal = self.referenced_dylibs.getIndex(dylib_id) orelse unreachable;
1597 sym.n_type |= macho.N_EXT;1597 sym.n_type |= macho.N_EXT;
1598 sym.n_desc = @intCast(u16, ordinal + 1) * macho.N_SYMBOL_RESOLVER;1598 sym.n_desc = @as(u16, @intCast(ordinal + 1)) * macho.N_SYMBOL_RESOLVER;
15991599
1600 if (dylib.weak) {1600 if (dylib.weak) {
1601 sym.n_desc |= macho.N_WEAK_REF;1601 sym.n_desc |= macho.N_WEAK_REF;
...@@ -1789,7 +1789,7 @@ fn allocateSymbol(self: *MachO) !u32 {...@@ -1789,7 +1789,7 @@ fn allocateSymbol(self: *MachO) !u32 {
1789 break :blk index;1789 break :blk index;
1790 } else {1790 } else {
1791 log.debug(" (allocating symbol index {d})", .{self.locals.items.len});1791 log.debug(" (allocating symbol index {d})", .{self.locals.items.len});
1792 const index = @intCast(u32, self.locals.items.len);1792 const index = @as(u32, @intCast(self.locals.items.len));
1793 _ = self.locals.addOneAssumeCapacity();1793 _ = self.locals.addOneAssumeCapacity();
1794 break :blk index;1794 break :blk index;
1795 }1795 }
...@@ -1815,7 +1815,7 @@ fn allocateGlobal(self: *MachO) !u32 {...@@ -1815,7 +1815,7 @@ fn allocateGlobal(self: *MachO) !u32 {
1815 break :blk index;1815 break :blk index;
1816 } else {1816 } else {
1817 log.debug(" (allocating symbol index {d})", .{self.globals.items.len});1817 log.debug(" (allocating symbol index {d})", .{self.globals.items.len});
1818 const index = @intCast(u32, self.globals.items.len);1818 const index = @as(u32, @intCast(self.globals.items.len));
1819 _ = self.globals.addOneAssumeCapacity();1819 _ = self.globals.addOneAssumeCapacity();
1820 break :blk index;1820 break :blk index;
1821 }1821 }
...@@ -2563,12 +2563,12 @@ pub fn getDeclVAddr(self: *MachO, decl_index: Module.Decl.Index, reloc_info: Fil...@@ -2563,12 +2563,12 @@ pub fn getDeclVAddr(self: *MachO, decl_index: Module.Decl.Index, reloc_info: Fil
2563 try Atom.addRelocation(self, atom_index, .{2563 try Atom.addRelocation(self, atom_index, .{
2564 .type = .unsigned,2564 .type = .unsigned,
2565 .target = .{ .sym_index = sym_index, .file = null },2565 .target = .{ .sym_index = sym_index, .file = null },
2566 .offset = @intCast(u32, reloc_info.offset),2566 .offset = @as(u32, @intCast(reloc_info.offset)),
2567 .addend = reloc_info.addend,2567 .addend = reloc_info.addend,
2568 .pcrel = false,2568 .pcrel = false,
2569 .length = 3,2569 .length = 3,
2570 });2570 });
2571 try Atom.addRebase(self, atom_index, @intCast(u32, reloc_info.offset));2571 try Atom.addRebase(self, atom_index, @as(u32, @intCast(reloc_info.offset)));
25722572
2573 return 0;2573 return 0;
2574}2574}
...@@ -2582,7 +2582,7 @@ fn populateMissingMetadata(self: *MachO) !void {...@@ -2582,7 +2582,7 @@ fn populateMissingMetadata(self: *MachO) !void {
25822582
2583 if (self.pagezero_segment_cmd_index == null) {2583 if (self.pagezero_segment_cmd_index == null) {
2584 if (pagezero_vmsize > 0) {2584 if (pagezero_vmsize > 0) {
2585 self.pagezero_segment_cmd_index = @intCast(u8, self.segments.items.len);2585 self.pagezero_segment_cmd_index = @as(u8, @intCast(self.segments.items.len));
2586 try self.segments.append(gpa, .{2586 try self.segments.append(gpa, .{
2587 .segname = makeStaticString("__PAGEZERO"),2587 .segname = makeStaticString("__PAGEZERO"),
2588 .vmsize = pagezero_vmsize,2588 .vmsize = pagezero_vmsize,
...@@ -2593,7 +2593,7 @@ fn populateMissingMetadata(self: *MachO) !void {...@@ -2593,7 +2593,7 @@ fn populateMissingMetadata(self: *MachO) !void {
25932593
2594 if (self.header_segment_cmd_index == null) {2594 if (self.header_segment_cmd_index == null) {
2595 // The first __TEXT segment is immovable and covers MachO header and load commands.2595 // The first __TEXT segment is immovable and covers MachO header and load commands.
2596 self.header_segment_cmd_index = @intCast(u8, self.segments.items.len);2596 self.header_segment_cmd_index = @as(u8, @intCast(self.segments.items.len));
2597 const ideal_size = @max(self.base.options.headerpad_size orelse 0, default_headerpad_size);2597 const ideal_size = @max(self.base.options.headerpad_size orelse 0, default_headerpad_size);
2598 const needed_size = mem.alignForward(u64, padToIdeal(ideal_size), self.page_size);2598 const needed_size = mem.alignForward(u64, padToIdeal(ideal_size), self.page_size);
25992599
...@@ -2719,7 +2719,7 @@ fn populateMissingMetadata(self: *MachO) !void {...@@ -2719,7 +2719,7 @@ fn populateMissingMetadata(self: *MachO) !void {
2719 }2719 }
27202720
2721 if (self.linkedit_segment_cmd_index == null) {2721 if (self.linkedit_segment_cmd_index == null) {
2722 self.linkedit_segment_cmd_index = @intCast(u8, self.segments.items.len);2722 self.linkedit_segment_cmd_index = @as(u8, @intCast(self.segments.items.len));
27232723
2724 try self.segments.append(gpa, .{2724 try self.segments.append(gpa, .{
2725 .segname = makeStaticString("__LINKEDIT"),2725 .segname = makeStaticString("__LINKEDIT"),
...@@ -2752,8 +2752,8 @@ fn allocateSection(self: *MachO, segname: []const u8, sectname: []const u8, opts...@@ -2752,8 +2752,8 @@ fn allocateSection(self: *MachO, segname: []const u8, sectname: []const u8, opts
2752 const gpa = self.base.allocator;2752 const gpa = self.base.allocator;
2753 // In incremental context, we create one section per segment pairing. This way,2753 // In incremental context, we create one section per segment pairing. This way,
2754 // we can move the segment in raw file as we please.2754 // we can move the segment in raw file as we please.
2755 const segment_id = @intCast(u8, self.segments.items.len);2755 const segment_id = @as(u8, @intCast(self.segments.items.len));
2756 const section_id = @intCast(u8, self.sections.slice().len);2756 const section_id = @as(u8, @intCast(self.sections.slice().len));
2757 const vmaddr = blk: {2757 const vmaddr = blk: {
2758 const prev_segment = self.segments.items[segment_id - 1];2758 const prev_segment = self.segments.items[segment_id - 1];
2759 break :blk mem.alignForward(u64, prev_segment.vmaddr + prev_segment.vmsize, self.page_size);2759 break :blk mem.alignForward(u64, prev_segment.vmaddr + prev_segment.vmsize, self.page_size);
...@@ -2788,7 +2788,7 @@ fn allocateSection(self: *MachO, segname: []const u8, sectname: []const u8, opts...@@ -2788,7 +2788,7 @@ fn allocateSection(self: *MachO, segname: []const u8, sectname: []const u8, opts
2788 .sectname = makeStaticString(sectname),2788 .sectname = makeStaticString(sectname),
2789 .segname = makeStaticString(segname),2789 .segname = makeStaticString(segname),
2790 .addr = mem.alignForward(u64, vmaddr, opts.alignment),2790 .addr = mem.alignForward(u64, vmaddr, opts.alignment),
2791 .offset = mem.alignForward(u32, @intCast(u32, off), opts.alignment),2791 .offset = mem.alignForward(u32, @as(u32, @intCast(off)), opts.alignment),
2792 .size = opts.size,2792 .size = opts.size,
2793 .@"align" = math.log2(opts.alignment),2793 .@"align" = math.log2(opts.alignment),
2794 .flags = opts.flags,2794 .flags = opts.flags,
...@@ -2832,7 +2832,7 @@ fn growSection(self: *MachO, sect_id: u8, needed_size: u64) !void {...@@ -2832,7 +2832,7 @@ fn growSection(self: *MachO, sect_id: u8, needed_size: u64) !void {
2832 current_size,2832 current_size,
2833 );2833 );
2834 if (amt != current_size) return error.InputOutput;2834 if (amt != current_size) return error.InputOutput;
2835 header.offset = @intCast(u32, new_offset);2835 header.offset = @as(u32, @intCast(new_offset));
2836 segment.fileoff = new_offset;2836 segment.fileoff = new_offset;
2837 }2837 }
28382838
...@@ -2862,7 +2862,7 @@ fn growSectionVirtualMemory(self: *MachO, sect_id: u8, needed_size: u64) !void {...@@ -2862,7 +2862,7 @@ fn growSectionVirtualMemory(self: *MachO, sect_id: u8, needed_size: u64) !void {
28622862
2863 // TODO: enforce order by increasing VM addresses in self.sections container.2863 // TODO: enforce order by increasing VM addresses in self.sections container.
2864 for (self.sections.items(.header)[sect_id + 1 ..], 0..) |*next_header, next_sect_id| {2864 for (self.sections.items(.header)[sect_id + 1 ..], 0..) |*next_header, next_sect_id| {
2865 const index = @intCast(u8, sect_id + 1 + next_sect_id);2865 const index = @as(u8, @intCast(sect_id + 1 + next_sect_id));
2866 const next_segment = self.getSegmentPtr(index);2866 const next_segment = self.getSegmentPtr(index);
2867 next_header.addr += diff;2867 next_header.addr += diff;
2868 next_segment.vmaddr += diff;2868 next_segment.vmaddr += diff;
...@@ -2972,7 +2972,7 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm...@@ -2972,7 +2972,7 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm
2972 self.segment_table_dirty = true;2972 self.segment_table_dirty = true;
2973 }2973 }
29742974
2975 const align_pow = @intCast(u32, math.log2(alignment));2975 const align_pow = @as(u32, @intCast(math.log2(alignment)));
2976 if (header.@"align" < align_pow) {2976 if (header.@"align" < align_pow) {
2977 header.@"align" = align_pow;2977 header.@"align" = align_pow;
2978 }2978 }
...@@ -3015,7 +3015,7 @@ pub fn getGlobalSymbol(self: *MachO, name: []const u8, lib_name: ?[]const u8) !u...@@ -3015,7 +3015,7 @@ pub fn getGlobalSymbol(self: *MachO, name: []const u8, lib_name: ?[]const u8) !u
30153015
3016fn writeSegmentHeaders(self: *MachO, writer: anytype) !void {3016fn writeSegmentHeaders(self: *MachO, writer: anytype) !void {
3017 for (self.segments.items, 0..) |seg, i| {3017 for (self.segments.items, 0..) |seg, i| {
3018 const indexes = self.getSectionIndexes(@intCast(u8, i));3018 const indexes = self.getSectionIndexes(@as(u8, @intCast(i)));
3019 try writer.writeStruct(seg);3019 try writer.writeStruct(seg);
3020 for (self.sections.items(.header)[indexes.start..indexes.end]) |header| {3020 for (self.sections.items(.header)[indexes.start..indexes.end]) |header| {
3021 try writer.writeStruct(header);3021 try writer.writeStruct(header);
...@@ -3029,7 +3029,7 @@ fn writeLinkeditSegmentData(self: *MachO) !void {...@@ -3029,7 +3029,7 @@ fn writeLinkeditSegmentData(self: *MachO) !void {
3029 seg.vmsize = 0;3029 seg.vmsize = 0;
30303030
3031 for (self.segments.items, 0..) |segment, id| {3031 for (self.segments.items, 0..) |segment, id| {
3032 if (self.linkedit_segment_cmd_index.? == @intCast(u8, id)) continue;3032 if (self.linkedit_segment_cmd_index.? == @as(u8, @intCast(id))) continue;
3033 if (seg.vmaddr < segment.vmaddr + segment.vmsize) {3033 if (seg.vmaddr < segment.vmaddr + segment.vmsize) {
3034 seg.vmaddr = mem.alignForward(u64, segment.vmaddr + segment.vmsize, self.page_size);3034 seg.vmaddr = mem.alignForward(u64, segment.vmaddr + segment.vmsize, self.page_size);
3035 }3035 }
...@@ -3115,7 +3115,7 @@ fn collectBindDataFromTableSection(self: *MachO, sect_id: u8, bind: anytype, tab...@@ -3115,7 +3115,7 @@ fn collectBindDataFromTableSection(self: *MachO, sect_id: u8, bind: anytype, tab
3115 log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{3115 log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{
3116 base_offset + offset,3116 base_offset + offset,
3117 self.getSymbolName(entry),3117 self.getSymbolName(entry),
3118 @divTrunc(@bitCast(i16, bind_sym.n_desc), macho.N_SYMBOL_RESOLVER),3118 @divTrunc(@as(i16, @bitCast(bind_sym.n_desc)), macho.N_SYMBOL_RESOLVER),
3119 });3119 });
3120 if (bind_sym.weakRef()) {3120 if (bind_sym.weakRef()) {
3121 log.debug(" | marking as weak ref ", .{});3121 log.debug(" | marking as weak ref ", .{});
...@@ -3150,7 +3150,7 @@ fn collectBindData(self: *MachO, bind: anytype, raw_bindings: anytype) !void {...@@ -3150,7 +3150,7 @@ fn collectBindData(self: *MachO, bind: anytype, raw_bindings: anytype) !void {
3150 const bind_sym = self.getSymbol(binding.target);3150 const bind_sym = self.getSymbol(binding.target);
3151 const bind_sym_name = self.getSymbolName(binding.target);3151 const bind_sym_name = self.getSymbolName(binding.target);
3152 const dylib_ordinal = @divTrunc(3152 const dylib_ordinal = @divTrunc(
3153 @bitCast(i16, bind_sym.n_desc),3153 @as(i16, @bitCast(bind_sym.n_desc)),
3154 macho.N_SYMBOL_RESOLVER,3154 macho.N_SYMBOL_RESOLVER,
3155 );3155 );
3156 log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{3156 log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{
...@@ -3285,14 +3285,14 @@ fn writeDyldInfoData(self: *MachO) !void {...@@ -3285,14 +3285,14 @@ fn writeDyldInfoData(self: *MachO) !void {
3285 try self.base.file.?.pwriteAll(buffer, rebase_off);3285 try self.base.file.?.pwriteAll(buffer, rebase_off);
3286 try self.populateLazyBindOffsetsInStubHelper(lazy_bind);3286 try self.populateLazyBindOffsetsInStubHelper(lazy_bind);
32873287
3288 self.dyld_info_cmd.rebase_off = @intCast(u32, rebase_off);3288 self.dyld_info_cmd.rebase_off = @as(u32, @intCast(rebase_off));
3289 self.dyld_info_cmd.rebase_size = @intCast(u32, rebase_size_aligned);3289 self.dyld_info_cmd.rebase_size = @as(u32, @intCast(rebase_size_aligned));
3290 self.dyld_info_cmd.bind_off = @intCast(u32, bind_off);3290 self.dyld_info_cmd.bind_off = @as(u32, @intCast(bind_off));
3291 self.dyld_info_cmd.bind_size = @intCast(u32, bind_size_aligned);3291 self.dyld_info_cmd.bind_size = @as(u32, @intCast(bind_size_aligned));
3292 self.dyld_info_cmd.lazy_bind_off = @intCast(u32, lazy_bind_off);3292 self.dyld_info_cmd.lazy_bind_off = @as(u32, @intCast(lazy_bind_off));
3293 self.dyld_info_cmd.lazy_bind_size = @intCast(u32, lazy_bind_size_aligned);3293 self.dyld_info_cmd.lazy_bind_size = @as(u32, @intCast(lazy_bind_size_aligned));
3294 self.dyld_info_cmd.export_off = @intCast(u32, export_off);3294 self.dyld_info_cmd.export_off = @as(u32, @intCast(export_off));
3295 self.dyld_info_cmd.export_size = @intCast(u32, export_size_aligned);3295 self.dyld_info_cmd.export_size = @as(u32, @intCast(export_size_aligned));
3296}3296}
32973297
3298fn populateLazyBindOffsetsInStubHelper(self: *MachO, lazy_bind: LazyBind) !void {3298fn populateLazyBindOffsetsInStubHelper(self: *MachO, lazy_bind: LazyBind) !void {
...@@ -3337,7 +3337,7 @@ fn writeSymtab(self: *MachO) !SymtabCtx {...@@ -3337,7 +3337,7 @@ fn writeSymtab(self: *MachO) !SymtabCtx {
33373337
3338 for (self.locals.items, 0..) |sym, sym_id| {3338 for (self.locals.items, 0..) |sym, sym_id| {
3339 if (sym.n_strx == 0) continue; // no name, skip3339 if (sym.n_strx == 0) continue; // no name, skip
3340 const sym_loc = SymbolWithLoc{ .sym_index = @intCast(u32, sym_id), .file = null };3340 const sym_loc = SymbolWithLoc{ .sym_index = @as(u32, @intCast(sym_id)), .file = null };
3341 if (self.symbolIsTemp(sym_loc)) continue; // local temp symbol, skip3341 if (self.symbolIsTemp(sym_loc)) continue; // local temp symbol, skip
3342 if (self.getGlobal(self.getSymbolName(sym_loc)) != null) continue; // global symbol is either an export or import, skip3342 if (self.getGlobal(self.getSymbolName(sym_loc)) != null) continue; // global symbol is either an export or import, skip
3343 try locals.append(sym);3343 try locals.append(sym);
...@@ -3363,16 +3363,16 @@ fn writeSymtab(self: *MachO) !SymtabCtx {...@@ -3363,16 +3363,16 @@ fn writeSymtab(self: *MachO) !SymtabCtx {
3363 const sym = self.getSymbol(global);3363 const sym = self.getSymbol(global);
3364 if (sym.n_strx == 0) continue; // no name, skip3364 if (sym.n_strx == 0) continue; // no name, skip
3365 if (!sym.undf()) continue; // not an import, skip3365 if (!sym.undf()) continue; // not an import, skip
3366 const new_index = @intCast(u32, imports.items.len);3366 const new_index = @as(u32, @intCast(imports.items.len));
3367 var out_sym = sym;3367 var out_sym = sym;
3368 out_sym.n_strx = try self.strtab.insert(gpa, self.getSymbolName(global));3368 out_sym.n_strx = try self.strtab.insert(gpa, self.getSymbolName(global));
3369 try imports.append(out_sym);3369 try imports.append(out_sym);
3370 try imports_table.putNoClobber(global, new_index);3370 try imports_table.putNoClobber(global, new_index);
3371 }3371 }
33723372
3373 const nlocals = @intCast(u32, locals.items.len);3373 const nlocals = @as(u32, @intCast(locals.items.len));
3374 const nexports = @intCast(u32, exports.items.len);3374 const nexports = @as(u32, @intCast(exports.items.len));
3375 const nimports = @intCast(u32, imports.items.len);3375 const nimports = @as(u32, @intCast(imports.items.len));
3376 const nsyms = nlocals + nexports + nimports;3376 const nsyms = nlocals + nexports + nimports;
33773377
3378 const seg = self.getLinkeditSegmentPtr();3378 const seg = self.getLinkeditSegmentPtr();
...@@ -3392,7 +3392,7 @@ fn writeSymtab(self: *MachO) !SymtabCtx {...@@ -3392,7 +3392,7 @@ fn writeSymtab(self: *MachO) !SymtabCtx {
3392 log.debug("writing symtab from 0x{x} to 0x{x}", .{ offset, offset + needed_size });3392 log.debug("writing symtab from 0x{x} to 0x{x}", .{ offset, offset + needed_size });
3393 try self.base.file.?.pwriteAll(buffer.items, offset);3393 try self.base.file.?.pwriteAll(buffer.items, offset);
33943394
3395 self.symtab_cmd.symoff = @intCast(u32, offset);3395 self.symtab_cmd.symoff = @as(u32, @intCast(offset));
3396 self.symtab_cmd.nsyms = nsyms;3396 self.symtab_cmd.nsyms = nsyms;
33973397
3398 return SymtabCtx{3398 return SymtabCtx{
...@@ -3421,8 +3421,8 @@ fn writeStrtab(self: *MachO) !void {...@@ -3421,8 +3421,8 @@ fn writeStrtab(self: *MachO) !void {
34213421
3422 try self.base.file.?.pwriteAll(buffer, offset);3422 try self.base.file.?.pwriteAll(buffer, offset);
34233423
3424 self.symtab_cmd.stroff = @intCast(u32, offset);3424 self.symtab_cmd.stroff = @as(u32, @intCast(offset));
3425 self.symtab_cmd.strsize = @intCast(u32, needed_size_aligned);3425 self.symtab_cmd.strsize = @as(u32, @intCast(needed_size_aligned));
3426}3426}
34273427
3428const SymtabCtx = struct {3428const SymtabCtx = struct {
...@@ -3434,8 +3434,8 @@ const SymtabCtx = struct {...@@ -3434,8 +3434,8 @@ const SymtabCtx = struct {
34343434
3435fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void {3435fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void {
3436 const gpa = self.base.allocator;3436 const gpa = self.base.allocator;
3437 const nstubs = @intCast(u32, self.stub_table.lookup.count());3437 const nstubs = @as(u32, @intCast(self.stub_table.lookup.count()));
3438 const ngot_entries = @intCast(u32, self.got_table.lookup.count());3438 const ngot_entries = @as(u32, @intCast(self.got_table.lookup.count()));
3439 const nindirectsyms = nstubs * 2 + ngot_entries;3439 const nindirectsyms = nstubs * 2 + ngot_entries;
3440 const iextdefsym = ctx.nlocalsym;3440 const iextdefsym = ctx.nlocalsym;
3441 const iundefsym = iextdefsym + ctx.nextdefsym;3441 const iundefsym = iextdefsym + ctx.nextdefsym;
...@@ -3503,7 +3503,7 @@ fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void {...@@ -3503,7 +3503,7 @@ fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void {
3503 self.dysymtab_cmd.nextdefsym = ctx.nextdefsym;3503 self.dysymtab_cmd.nextdefsym = ctx.nextdefsym;
3504 self.dysymtab_cmd.iundefsym = iundefsym;3504 self.dysymtab_cmd.iundefsym = iundefsym;
3505 self.dysymtab_cmd.nundefsym = ctx.nundefsym;3505 self.dysymtab_cmd.nundefsym = ctx.nundefsym;
3506 self.dysymtab_cmd.indirectsymoff = @intCast(u32, offset);3506 self.dysymtab_cmd.indirectsymoff = @as(u32, @intCast(offset));
3507 self.dysymtab_cmd.nindirectsyms = nindirectsyms;3507 self.dysymtab_cmd.nindirectsyms = nindirectsyms;
3508}3508}
35093509
...@@ -3530,8 +3530,8 @@ fn writeCodeSignaturePadding(self: *MachO, code_sig: *CodeSignature) !void {...@@ -3530,8 +3530,8 @@ fn writeCodeSignaturePadding(self: *MachO, code_sig: *CodeSignature) !void {
3530 // except for code signature data.3530 // except for code signature data.
3531 try self.base.file.?.pwriteAll(&[_]u8{0}, offset + needed_size - 1);3531 try self.base.file.?.pwriteAll(&[_]u8{0}, offset + needed_size - 1);
35323532
3533 self.codesig_cmd.dataoff = @intCast(u32, offset);3533 self.codesig_cmd.dataoff = @as(u32, @intCast(offset));
3534 self.codesig_cmd.datasize = @intCast(u32, needed_size);3534 self.codesig_cmd.datasize = @as(u32, @intCast(needed_size));
3535}3535}
35363536
3537fn writeCodeSignature(self: *MachO, comp: *const Compilation, code_sig: *CodeSignature) !void {3537fn writeCodeSignature(self: *MachO, comp: *const Compilation, code_sig: *CodeSignature) !void {
...@@ -3711,7 +3711,7 @@ pub fn makeStaticString(bytes: []const u8) [16]u8 {...@@ -3711,7 +3711,7 @@ pub fn makeStaticString(bytes: []const u8) [16]u8 {
37113711
3712fn getSegmentByName(self: MachO, segname: []const u8) ?u8 {3712fn getSegmentByName(self: MachO, segname: []const u8) ?u8 {
3713 for (self.segments.items, 0..) |seg, i| {3713 for (self.segments.items, 0..) |seg, i| {
3714 if (mem.eql(u8, segname, seg.segName())) return @intCast(u8, i);3714 if (mem.eql(u8, segname, seg.segName())) return @as(u8, @intCast(i));
3715 } else return null;3715 } else return null;
3716}3716}
37173717
...@@ -3734,15 +3734,15 @@ pub fn getSectionByName(self: MachO, segname: []const u8, sectname: []const u8)...@@ -3734,15 +3734,15 @@ pub fn getSectionByName(self: MachO, segname: []const u8, sectname: []const u8)
3734 // TODO investigate caching with a hashmap3734 // TODO investigate caching with a hashmap
3735 for (self.sections.items(.header), 0..) |header, i| {3735 for (self.sections.items(.header), 0..) |header, i| {
3736 if (mem.eql(u8, header.segName(), segname) and mem.eql(u8, header.sectName(), sectname))3736 if (mem.eql(u8, header.segName(), segname) and mem.eql(u8, header.sectName(), sectname))
3737 return @intCast(u8, i);3737 return @as(u8, @intCast(i));
3738 } else return null;3738 } else return null;
3739}3739}
37403740
3741pub fn getSectionIndexes(self: MachO, segment_index: u8) struct { start: u8, end: u8 } {3741pub fn getSectionIndexes(self: MachO, segment_index: u8) struct { start: u8, end: u8 } {
3742 var start: u8 = 0;3742 var start: u8 = 0;
3743 const nsects = for (self.segments.items, 0..) |seg, i| {3743 const nsects = for (self.segments.items, 0..) |seg, i| {
3744 if (i == segment_index) break @intCast(u8, seg.nsects);3744 if (i == segment_index) break @as(u8, @intCast(seg.nsects));
3745 start += @intCast(u8, seg.nsects);3745 start += @as(u8, @intCast(seg.nsects));
3746 } else 0;3746 } else 0;
3747 return .{ .start = start, .end = start + nsects };3747 return .{ .start = start, .end = start + nsects };
3748}3748}
src/link/MachO/Archive.zig+1-1
...@@ -169,7 +169,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !...@@ -169,7 +169,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !
169 };169 };
170 const object_offset = try symtab_reader.readIntLittle(u32);170 const object_offset = try symtab_reader.readIntLittle(u32);
171171
172 const sym_name = mem.sliceTo(@ptrCast([*:0]const u8, strtab.ptr + n_strx), 0);172 const sym_name = mem.sliceTo(@as([*:0]const u8, @ptrCast(strtab.ptr + n_strx)), 0);
173 const owned_name = try allocator.dupe(u8, sym_name);173 const owned_name = try allocator.dupe(u8, sym_name);
174 const res = try self.toc.getOrPut(allocator, owned_name);174 const res = try self.toc.getOrPut(allocator, owned_name);
175 defer if (res.found_existing) allocator.free(owned_name);175 defer if (res.found_existing) allocator.free(owned_name);
src/link/MachO/CodeSignature.zig+9-9
...@@ -72,7 +72,7 @@ const CodeDirectory = struct {...@@ -72,7 +72,7 @@ const CodeDirectory = struct {
72 .hashSize = hash_size,72 .hashSize = hash_size,
73 .hashType = macho.CS_HASHTYPE_SHA256,73 .hashType = macho.CS_HASHTYPE_SHA256,
74 .platform = 0,74 .platform = 0,
75 .pageSize = @truncate(u8, std.math.log2(page_size)),75 .pageSize = @as(u8, @truncate(std.math.log2(page_size))),
76 .spare2 = 0,76 .spare2 = 0,
77 .scatterOffset = 0,77 .scatterOffset = 0,
78 .teamOffset = 0,78 .teamOffset = 0,
...@@ -110,7 +110,7 @@ const CodeDirectory = struct {...@@ -110,7 +110,7 @@ const CodeDirectory = struct {
110 fn size(self: CodeDirectory) u32 {110 fn size(self: CodeDirectory) u32 {
111 const code_slots = self.inner.nCodeSlots * hash_size;111 const code_slots = self.inner.nCodeSlots * hash_size;
112 const special_slots = self.inner.nSpecialSlots * hash_size;112 const special_slots = self.inner.nSpecialSlots * hash_size;
113 return @sizeOf(macho.CodeDirectory) + @intCast(u32, self.ident.len + 1 + special_slots + code_slots);113 return @sizeOf(macho.CodeDirectory) + @as(u32, @intCast(self.ident.len + 1 + special_slots + code_slots));
114 }114 }
115115
116 fn write(self: CodeDirectory, writer: anytype) !void {116 fn write(self: CodeDirectory, writer: anytype) !void {
...@@ -139,9 +139,9 @@ const CodeDirectory = struct {...@@ -139,9 +139,9 @@ const CodeDirectory = struct {
139 try writer.writeAll(self.ident);139 try writer.writeAll(self.ident);
140 try writer.writeByte(0);140 try writer.writeByte(0);
141141
142 var i: isize = @intCast(isize, self.inner.nSpecialSlots);142 var i: isize = @as(isize, @intCast(self.inner.nSpecialSlots));
143 while (i > 0) : (i -= 1) {143 while (i > 0) : (i -= 1) {
144 try writer.writeAll(&self.special_slots[@intCast(usize, i - 1)]);144 try writer.writeAll(&self.special_slots[@as(usize, @intCast(i - 1))]);
145 }145 }
146146
147 for (self.code_slots.items) |slot| {147 for (self.code_slots.items) |slot| {
...@@ -186,7 +186,7 @@ const Entitlements = struct {...@@ -186,7 +186,7 @@ const Entitlements = struct {
186 }186 }
187187
188 fn size(self: Entitlements) u32 {188 fn size(self: Entitlements) u32 {
189 return @intCast(u32, self.inner.len) + 2 * @sizeOf(u32);189 return @as(u32, @intCast(self.inner.len)) + 2 * @sizeOf(u32);
190 }190 }
191191
192 fn write(self: Entitlements, writer: anytype) !void {192 fn write(self: Entitlements, writer: anytype) !void {
...@@ -281,7 +281,7 @@ pub fn writeAdhocSignature(...@@ -281,7 +281,7 @@ pub fn writeAdhocSignature(
281 self.code_directory.inner.execSegFlags = if (opts.output_mode == .Exe) macho.CS_EXECSEG_MAIN_BINARY else 0;281 self.code_directory.inner.execSegFlags = if (opts.output_mode == .Exe) macho.CS_EXECSEG_MAIN_BINARY else 0;
282 self.code_directory.inner.codeLimit = opts.file_size;282 self.code_directory.inner.codeLimit = opts.file_size;
283283
284 const total_pages = @intCast(u32, mem.alignForward(usize, opts.file_size, self.page_size) / self.page_size);284 const total_pages = @as(u32, @intCast(mem.alignForward(usize, opts.file_size, self.page_size) / self.page_size));
285285
286 try self.code_directory.code_slots.ensureTotalCapacityPrecise(gpa, total_pages);286 try self.code_directory.code_slots.ensureTotalCapacityPrecise(gpa, total_pages);
287 self.code_directory.code_slots.items.len = total_pages;287 self.code_directory.code_slots.items.len = total_pages;
...@@ -331,7 +331,7 @@ pub fn writeAdhocSignature(...@@ -331,7 +331,7 @@ pub fn writeAdhocSignature(
331 }331 }
332332
333 self.code_directory.inner.hashOffset =333 self.code_directory.inner.hashOffset =
334 @sizeOf(macho.CodeDirectory) + @intCast(u32, self.code_directory.ident.len + 1 + self.code_directory.inner.nSpecialSlots * hash_size);334 @sizeOf(macho.CodeDirectory) + @as(u32, @intCast(self.code_directory.ident.len + 1 + self.code_directory.inner.nSpecialSlots * hash_size));
335 self.code_directory.inner.length = self.code_directory.size();335 self.code_directory.inner.length = self.code_directory.size();
336 header.length += self.code_directory.size();336 header.length += self.code_directory.size();
337337
...@@ -339,7 +339,7 @@ pub fn writeAdhocSignature(...@@ -339,7 +339,7 @@ pub fn writeAdhocSignature(
339 try writer.writeIntBig(u32, header.length);339 try writer.writeIntBig(u32, header.length);
340 try writer.writeIntBig(u32, header.count);340 try writer.writeIntBig(u32, header.count);
341341
342 var offset: u32 = @sizeOf(macho.SuperBlob) + @sizeOf(macho.BlobIndex) * @intCast(u32, blobs.items.len);342 var offset: u32 = @sizeOf(macho.SuperBlob) + @sizeOf(macho.BlobIndex) * @as(u32, @intCast(blobs.items.len));
343 for (blobs.items) |blob| {343 for (blobs.items) |blob| {
344 try writer.writeIntBig(u32, blob.slotType());344 try writer.writeIntBig(u32, blob.slotType());
345 try writer.writeIntBig(u32, offset);345 try writer.writeIntBig(u32, offset);
...@@ -383,7 +383,7 @@ pub fn estimateSize(self: CodeSignature, file_size: u64) u32 {...@@ -383,7 +383,7 @@ pub fn estimateSize(self: CodeSignature, file_size: u64) u32 {
383 ssize += @sizeOf(macho.BlobIndex) + sig.size();383 ssize += @sizeOf(macho.BlobIndex) + sig.size();
384 }384 }
385 ssize += n_special_slots * hash_size;385 ssize += n_special_slots * hash_size;
386 return @intCast(u32, mem.alignForward(u64, ssize, @sizeOf(u64)));386 return @as(u32, @intCast(mem.alignForward(u64, ssize, @sizeOf(u64))));
387}387}
388388
389pub fn clear(self: *CodeSignature, allocator: Allocator) void {389pub fn clear(self: *CodeSignature, allocator: Allocator) void {
src/link/MachO/DebugSymbols.zig+21-21
...@@ -64,9 +64,9 @@ pub const Reloc = struct {...@@ -64,9 +64,9 @@ pub const Reloc = struct {
64/// has been called to get a viable debug symbols output.64/// has been called to get a viable debug symbols output.
65pub fn populateMissingMetadata(self: *DebugSymbols) !void {65pub fn populateMissingMetadata(self: *DebugSymbols) !void {
66 if (self.dwarf_segment_cmd_index == null) {66 if (self.dwarf_segment_cmd_index == null) {
67 self.dwarf_segment_cmd_index = @intCast(u8, self.segments.items.len);67 self.dwarf_segment_cmd_index = @as(u8, @intCast(self.segments.items.len));
6868
69 const off = @intCast(u64, self.page_size);69 const off = @as(u64, @intCast(self.page_size));
70 const ideal_size: u16 = 200 + 128 + 160 + 250;70 const ideal_size: u16 = 200 + 128 + 160 + 250;
71 const needed_size = mem.alignForward(u64, padToIdeal(ideal_size), self.page_size);71 const needed_size = mem.alignForward(u64, padToIdeal(ideal_size), self.page_size);
7272
...@@ -86,7 +86,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols) !void {...@@ -86,7 +86,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols) !void {
86 try self.dwarf.strtab.buffer.append(self.allocator, 0);86 try self.dwarf.strtab.buffer.append(self.allocator, 0);
87 self.debug_str_section_index = try self.allocateSection(87 self.debug_str_section_index = try self.allocateSection(
88 "__debug_str",88 "__debug_str",
89 @intCast(u32, self.dwarf.strtab.buffer.items.len),89 @as(u32, @intCast(self.dwarf.strtab.buffer.items.len)),
90 0,90 0,
91 );91 );
92 self.debug_string_table_dirty = true;92 self.debug_string_table_dirty = true;
...@@ -113,7 +113,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols) !void {...@@ -113,7 +113,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols) !void {
113 }113 }
114114
115 if (self.linkedit_segment_cmd_index == null) {115 if (self.linkedit_segment_cmd_index == null) {
116 self.linkedit_segment_cmd_index = @intCast(u8, self.segments.items.len);116 self.linkedit_segment_cmd_index = @as(u8, @intCast(self.segments.items.len));
117 try self.segments.append(self.allocator, .{117 try self.segments.append(self.allocator, .{
118 .segname = makeStaticString("__LINKEDIT"),118 .segname = makeStaticString("__LINKEDIT"),
119 .maxprot = macho.PROT.READ,119 .maxprot = macho.PROT.READ,
...@@ -128,7 +128,7 @@ fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignme...@@ -128,7 +128,7 @@ fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignme
128 var sect = macho.section_64{128 var sect = macho.section_64{
129 .sectname = makeStaticString(sectname),129 .sectname = makeStaticString(sectname),
130 .segname = segment.segname,130 .segname = segment.segname,
131 .size = @intCast(u32, size),131 .size = @as(u32, @intCast(size)),
132 .@"align" = alignment,132 .@"align" = alignment,
133 };133 };
134 const alignment_pow_2 = try math.powi(u32, 2, alignment);134 const alignment_pow_2 = try math.powi(u32, 2, alignment);
...@@ -141,9 +141,9 @@ fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignme...@@ -141,9 +141,9 @@ fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignme
141 off + size,141 off + size,
142 });142 });
143143
144 sect.offset = @intCast(u32, off);144 sect.offset = @as(u32, @intCast(off));
145145
146 const index = @intCast(u8, self.sections.items.len);146 const index = @as(u8, @intCast(self.sections.items.len));
147 try self.sections.append(self.allocator, sect);147 try self.sections.append(self.allocator, sect);
148 segment.cmdsize += @sizeOf(macho.section_64);148 segment.cmdsize += @sizeOf(macho.section_64);
149 segment.nsects += 1;149 segment.nsects += 1;
...@@ -176,7 +176,7 @@ pub fn growSection(self: *DebugSymbols, sect_index: u8, needed_size: u32, requir...@@ -176,7 +176,7 @@ pub fn growSection(self: *DebugSymbols, sect_index: u8, needed_size: u32, requir
176 if (amt != existing_size) return error.InputOutput;176 if (amt != existing_size) return error.InputOutput;
177 }177 }
178178
179 sect.offset = @intCast(u32, new_offset);179 sect.offset = @as(u32, @intCast(new_offset));
180 }180 }
181181
182 sect.size = needed_size;182 sect.size = needed_size;
...@@ -286,7 +286,7 @@ pub fn flushModule(self: *DebugSymbols, macho_file: *MachO) !void {...@@ -286,7 +286,7 @@ pub fn flushModule(self: *DebugSymbols, macho_file: *MachO) !void {
286 {286 {
287 const sect_index = self.debug_str_section_index.?;287 const sect_index = self.debug_str_section_index.?;
288 if (self.debug_string_table_dirty or self.dwarf.strtab.buffer.items.len != self.getSection(sect_index).size) {288 if (self.debug_string_table_dirty or self.dwarf.strtab.buffer.items.len != self.getSection(sect_index).size) {
289 const needed_size = @intCast(u32, self.dwarf.strtab.buffer.items.len);289 const needed_size = @as(u32, @intCast(self.dwarf.strtab.buffer.items.len));
290 try self.growSection(sect_index, needed_size, false);290 try self.growSection(sect_index, needed_size, false);
291 try self.file.pwriteAll(self.dwarf.strtab.buffer.items, self.getSection(sect_index).offset);291 try self.file.pwriteAll(self.dwarf.strtab.buffer.items, self.getSection(sect_index).offset);
292 self.debug_string_table_dirty = false;292 self.debug_string_table_dirty = false;
...@@ -307,7 +307,7 @@ pub fn flushModule(self: *DebugSymbols, macho_file: *MachO) !void {...@@ -307,7 +307,7 @@ pub fn flushModule(self: *DebugSymbols, macho_file: *MachO) !void {
307307
308 const ncmds = load_commands.calcNumOfLCs(lc_buffer.items);308 const ncmds = load_commands.calcNumOfLCs(lc_buffer.items);
309 try self.file.pwriteAll(lc_buffer.items, @sizeOf(macho.mach_header_64));309 try self.file.pwriteAll(lc_buffer.items, @sizeOf(macho.mach_header_64));
310 try self.writeHeader(macho_file, ncmds, @intCast(u32, lc_buffer.items.len));310 try self.writeHeader(macho_file, ncmds, @as(u32, @intCast(lc_buffer.items.len)));
311311
312 assert(!self.debug_abbrev_section_dirty);312 assert(!self.debug_abbrev_section_dirty);
313 assert(!self.debug_aranges_section_dirty);313 assert(!self.debug_aranges_section_dirty);
...@@ -378,7 +378,7 @@ fn writeSegmentHeaders(self: *DebugSymbols, macho_file: *MachO, writer: anytype)...@@ -378,7 +378,7 @@ fn writeSegmentHeaders(self: *DebugSymbols, macho_file: *MachO, writer: anytype)
378 // Write segment/section headers from the binary file first.378 // Write segment/section headers from the binary file first.
379 const end = macho_file.linkedit_segment_cmd_index.?;379 const end = macho_file.linkedit_segment_cmd_index.?;
380 for (macho_file.segments.items[0..end], 0..) |seg, i| {380 for (macho_file.segments.items[0..end], 0..) |seg, i| {
381 const indexes = macho_file.getSectionIndexes(@intCast(u8, i));381 const indexes = macho_file.getSectionIndexes(@as(u8, @intCast(i)));
382 var out_seg = seg;382 var out_seg = seg;
383 out_seg.fileoff = 0;383 out_seg.fileoff = 0;
384 out_seg.filesize = 0;384 out_seg.filesize = 0;
...@@ -407,7 +407,7 @@ fn writeSegmentHeaders(self: *DebugSymbols, macho_file: *MachO, writer: anytype)...@@ -407,7 +407,7 @@ fn writeSegmentHeaders(self: *DebugSymbols, macho_file: *MachO, writer: anytype)
407 }407 }
408 // Next, commit DSYM's __LINKEDIT and __DWARF segments headers.408 // Next, commit DSYM's __LINKEDIT and __DWARF segments headers.
409 for (self.segments.items, 0..) |seg, i| {409 for (self.segments.items, 0..) |seg, i| {
410 const indexes = self.getSectionIndexes(@intCast(u8, i));410 const indexes = self.getSectionIndexes(@as(u8, @intCast(i)));
411 try writer.writeStruct(seg);411 try writer.writeStruct(seg);
412 for (self.sections.items[indexes.start..indexes.end]) |header| {412 for (self.sections.items[indexes.start..indexes.end]) |header| {
413 try writer.writeStruct(header);413 try writer.writeStruct(header);
...@@ -473,7 +473,7 @@ fn writeSymtab(self: *DebugSymbols, macho_file: *MachO) !void {...@@ -473,7 +473,7 @@ fn writeSymtab(self: *DebugSymbols, macho_file: *MachO) !void {
473473
474 for (macho_file.locals.items, 0..) |sym, sym_id| {474 for (macho_file.locals.items, 0..) |sym, sym_id| {
475 if (sym.n_strx == 0) continue; // no name, skip475 if (sym.n_strx == 0) continue; // no name, skip
476 const sym_loc = MachO.SymbolWithLoc{ .sym_index = @intCast(u32, sym_id), .file = null };476 const sym_loc = MachO.SymbolWithLoc{ .sym_index = @as(u32, @intCast(sym_id)), .file = null };
477 if (macho_file.symbolIsTemp(sym_loc)) continue; // local temp symbol, skip477 if (macho_file.symbolIsTemp(sym_loc)) continue; // local temp symbol, skip
478 if (macho_file.getGlobal(macho_file.getSymbolName(sym_loc)) != null) continue; // global symbol is either an export or import, skip478 if (macho_file.getGlobal(macho_file.getSymbolName(sym_loc)) != null) continue; // global symbol is either an export or import, skip
479 var out_sym = sym;479 var out_sym = sym;
...@@ -501,10 +501,10 @@ fn writeSymtab(self: *DebugSymbols, macho_file: *MachO) !void {...@@ -501,10 +501,10 @@ fn writeSymtab(self: *DebugSymbols, macho_file: *MachO) !void {
501 const needed_size = nsyms * @sizeOf(macho.nlist_64);501 const needed_size = nsyms * @sizeOf(macho.nlist_64);
502 seg.filesize = offset + needed_size - seg.fileoff;502 seg.filesize = offset + needed_size - seg.fileoff;
503503
504 self.symtab_cmd.symoff = @intCast(u32, offset);504 self.symtab_cmd.symoff = @as(u32, @intCast(offset));
505 self.symtab_cmd.nsyms = @intCast(u32, nsyms);505 self.symtab_cmd.nsyms = @as(u32, @intCast(nsyms));
506506
507 const locals_off = @intCast(u32, offset);507 const locals_off = @as(u32, @intCast(offset));
508 const locals_size = nlocals * @sizeOf(macho.nlist_64);508 const locals_size = nlocals * @sizeOf(macho.nlist_64);
509 const exports_off = locals_off + locals_size;509 const exports_off = locals_off + locals_size;
510 const exports_size = nexports * @sizeOf(macho.nlist_64);510 const exports_size = nexports * @sizeOf(macho.nlist_64);
...@@ -521,13 +521,13 @@ fn writeStrtab(self: *DebugSymbols) !void {...@@ -521,13 +521,13 @@ fn writeStrtab(self: *DebugSymbols) !void {
521 defer tracy.end();521 defer tracy.end();
522522
523 const seg = &self.segments.items[self.linkedit_segment_cmd_index.?];523 const seg = &self.segments.items[self.linkedit_segment_cmd_index.?];
524 const symtab_size = @intCast(u32, self.symtab_cmd.nsyms * @sizeOf(macho.nlist_64));524 const symtab_size = @as(u32, @intCast(self.symtab_cmd.nsyms * @sizeOf(macho.nlist_64)));
525 const offset = mem.alignForward(u64, self.symtab_cmd.symoff + symtab_size, @alignOf(u64));525 const offset = mem.alignForward(u64, self.symtab_cmd.symoff + symtab_size, @alignOf(u64));
526 const needed_size = mem.alignForward(u64, self.strtab.buffer.items.len, @alignOf(u64));526 const needed_size = mem.alignForward(u64, self.strtab.buffer.items.len, @alignOf(u64));
527527
528 seg.filesize = offset + needed_size - seg.fileoff;528 seg.filesize = offset + needed_size - seg.fileoff;
529 self.symtab_cmd.stroff = @intCast(u32, offset);529 self.symtab_cmd.stroff = @as(u32, @intCast(offset));
530 self.symtab_cmd.strsize = @intCast(u32, needed_size);530 self.symtab_cmd.strsize = @as(u32, @intCast(needed_size));
531531
532 log.debug("writing string table from 0x{x} to 0x{x}", .{ offset, offset + needed_size });532 log.debug("writing string table from 0x{x} to 0x{x}", .{ offset, offset + needed_size });
533533
...@@ -542,8 +542,8 @@ fn writeStrtab(self: *DebugSymbols) !void {...@@ -542,8 +542,8 @@ fn writeStrtab(self: *DebugSymbols) !void {
542pub fn getSectionIndexes(self: *DebugSymbols, segment_index: u8) struct { start: u8, end: u8 } {542pub fn getSectionIndexes(self: *DebugSymbols, segment_index: u8) struct { start: u8, end: u8 } {
543 var start: u8 = 0;543 var start: u8 = 0;
544 const nsects = for (self.segments.items, 0..) |seg, i| {544 const nsects = for (self.segments.items, 0..) |seg, i| {
545 if (i == segment_index) break @intCast(u8, seg.nsects);545 if (i == segment_index) break @as(u8, @intCast(seg.nsects));
546 start += @intCast(u8, seg.nsects);546 start += @as(u8, @intCast(seg.nsects));
547 } else 0;547 } else 0;
548 return .{ .start = start, .end = start + nsects };548 return .{ .start = start, .end = start + nsects };
549}549}
src/link/MachO/DwarfInfo.zig+4-4
...@@ -70,7 +70,7 @@ pub fn genSubprogramLookupByName(...@@ -70,7 +70,7 @@ pub fn genSubprogramLookupByName(
70 low_pc = addr;70 low_pc = addr;
71 }71 }
72 if (try attr.getConstant(self)) |constant| {72 if (try attr.getConstant(self)) |constant| {
73 low_pc = @intCast(u64, constant);73 low_pc = @as(u64, @intCast(constant));
74 }74 }
75 },75 },
76 dwarf.AT.high_pc => {76 dwarf.AT.high_pc => {
...@@ -78,7 +78,7 @@ pub fn genSubprogramLookupByName(...@@ -78,7 +78,7 @@ pub fn genSubprogramLookupByName(
78 high_pc = addr;78 high_pc = addr;
79 }79 }
80 if (try attr.getConstant(self)) |constant| {80 if (try attr.getConstant(self)) |constant| {
81 high_pc = @intCast(u64, constant);81 high_pc = @as(u64, @intCast(constant));
82 }82 }
83 },83 },
84 else => {},84 else => {},
...@@ -261,7 +261,7 @@ pub const Attribute = struct {...@@ -261,7 +261,7 @@ pub const Attribute = struct {
261261
262 switch (self.form) {262 switch (self.form) {
263 dwarf.FORM.string => {263 dwarf.FORM.string => {
264 return mem.sliceTo(@ptrCast([*:0]const u8, debug_info.ptr), 0);264 return mem.sliceTo(@as([*:0]const u8, @ptrCast(debug_info.ptr)), 0);
265 },265 },
266 dwarf.FORM.strp => {266 dwarf.FORM.strp => {
267 const off = if (cuh.is_64bit)267 const off = if (cuh.is_64bit)
...@@ -499,5 +499,5 @@ fn findAbbrevEntrySize(self: DwarfInfo, da_off: usize, da_len: usize, di_off: us...@@ -499,5 +499,5 @@ fn findAbbrevEntrySize(self: DwarfInfo, da_off: usize, da_len: usize, di_off: us
499499
500fn getString(self: DwarfInfo, off: u64) []const u8 {500fn getString(self: DwarfInfo, off: u64) []const u8 {
501 assert(off < self.debug_str.len);501 assert(off < self.debug_str.len);
502 return mem.sliceTo(@ptrCast([*:0]const u8, self.debug_str.ptr + @intCast(usize, off)), 0);502 return mem.sliceTo(@as([*:0]const u8, @ptrCast(self.debug_str.ptr + @as(usize, @intCast(off)))), 0);
503}503}
src/link/MachO/Dylib.zig+6-6
...@@ -75,7 +75,7 @@ pub const Id = struct {...@@ -75,7 +75,7 @@ pub const Id = struct {
75 .int => |int| {75 .int => |int| {
76 var out: u32 = 0;76 var out: u32 = 0;
77 const major = math.cast(u16, int) orelse return error.Overflow;77 const major = math.cast(u16, int) orelse return error.Overflow;
78 out += @intCast(u32, major) << 16;78 out += @as(u32, @intCast(major)) << 16;
79 return out;79 return out;
80 },80 },
81 .float => |float| {81 .float => |float| {
...@@ -106,9 +106,9 @@ pub const Id = struct {...@@ -106,9 +106,9 @@ pub const Id = struct {
106 out += try fmt.parseInt(u8, values[2], 10);106 out += try fmt.parseInt(u8, values[2], 10);
107 }107 }
108 if (count > 1) {108 if (count > 1) {
109 out += @intCast(u32, try fmt.parseInt(u8, values[1], 10)) << 8;109 out += @as(u32, @intCast(try fmt.parseInt(u8, values[1], 10))) << 8;
110 }110 }
111 out += @intCast(u32, try fmt.parseInt(u16, values[0], 10)) << 16;111 out += @as(u32, @intCast(try fmt.parseInt(u16, values[0], 10))) << 16;
112112
113 return out;113 return out;
114 }114 }
...@@ -164,11 +164,11 @@ pub fn parseFromBinary(...@@ -164,11 +164,11 @@ pub fn parseFromBinary(
164 switch (cmd.cmd()) {164 switch (cmd.cmd()) {
165 .SYMTAB => {165 .SYMTAB => {
166 const symtab_cmd = cmd.cast(macho.symtab_command).?;166 const symtab_cmd = cmd.cast(macho.symtab_command).?;
167 const symtab = @ptrCast(167 const symtab = @as(
168 [*]const macho.nlist_64,168 [*]const macho.nlist_64,
169 // Alignment is guaranteed as a dylib is a final linked image and has to have sections169 // Alignment is guaranteed as a dylib is a final linked image and has to have sections
170 // properly aligned in order to be correctly loaded by the loader.170 // properly aligned in order to be correctly loaded by the loader.
171 @alignCast(@alignOf(macho.nlist_64), &data[symtab_cmd.symoff]),171 @ptrCast(@alignCast(&data[symtab_cmd.symoff])),
172 )[0..symtab_cmd.nsyms];172 )[0..symtab_cmd.nsyms];
173 const strtab = data[symtab_cmd.stroff..][0..symtab_cmd.strsize];173 const strtab = data[symtab_cmd.stroff..][0..symtab_cmd.strsize];
174174
...@@ -176,7 +176,7 @@ pub fn parseFromBinary(...@@ -176,7 +176,7 @@ pub fn parseFromBinary(
176 const add_to_symtab = sym.ext() and (sym.sect() or sym.indr());176 const add_to_symtab = sym.ext() and (sym.sect() or sym.indr());
177 if (!add_to_symtab) continue;177 if (!add_to_symtab) continue;
178178
179 const sym_name = mem.sliceTo(@ptrCast([*:0]const u8, strtab.ptr + sym.n_strx), 0);179 const sym_name = mem.sliceTo(@as([*:0]const u8, @ptrCast(strtab.ptr + sym.n_strx)), 0);
180 try self.symbols.putNoClobber(allocator, try allocator.dupe(u8, sym_name), false);180 try self.symbols.putNoClobber(allocator, try allocator.dupe(u8, sym_name), false);
181 }181 }
182 },182 },
src/link/MachO/Object.zig+32-32
...@@ -164,7 +164,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)...@@ -164,7 +164,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
164 else => {},164 else => {},
165 } else return;165 } else return;
166166
167 self.in_symtab = @ptrCast([*]align(1) const macho.nlist_64, self.contents.ptr + symtab.symoff)[0..symtab.nsyms];167 self.in_symtab = @as([*]align(1) const macho.nlist_64, @ptrCast(self.contents.ptr + symtab.symoff))[0..symtab.nsyms];
168 self.in_strtab = self.contents[symtab.stroff..][0..symtab.strsize];168 self.in_strtab = self.contents[symtab.stroff..][0..symtab.strsize];
169169
170 self.symtab = try allocator.alloc(macho.nlist_64, self.in_symtab.?.len + nsects);170 self.symtab = try allocator.alloc(macho.nlist_64, self.in_symtab.?.len + nsects);
...@@ -202,7 +202,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)...@@ -202,7 +202,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
202 defer sorted_all_syms.deinit();202 defer sorted_all_syms.deinit();
203203
204 for (self.in_symtab.?, 0..) |_, index| {204 for (self.in_symtab.?, 0..) |_, index| {
205 sorted_all_syms.appendAssumeCapacity(.{ .index = @intCast(u32, index) });205 sorted_all_syms.appendAssumeCapacity(.{ .index = @as(u32, @intCast(index)) });
206 }206 }
207207
208 // We sort by type: defined < undefined, and208 // We sort by type: defined < undefined, and
...@@ -225,18 +225,18 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)...@@ -225,18 +225,18 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
225 }225 }
226 }226 }
227 if (sym.sect() and section_index_lookup == null) {227 if (sym.sect() and section_index_lookup == null) {
228 section_index_lookup = .{ .start = @intCast(u32, i), .len = 1 };228 section_index_lookup = .{ .start = @as(u32, @intCast(i)), .len = 1 };
229 }229 }
230230
231 prev_sect_id = sym.n_sect;231 prev_sect_id = sym.n_sect;
232232
233 self.symtab[i] = sym;233 self.symtab[i] = sym;
234 self.source_symtab_lookup[i] = sym_id.index;234 self.source_symtab_lookup[i] = sym_id.index;
235 self.reverse_symtab_lookup[sym_id.index] = @intCast(u32, i);235 self.reverse_symtab_lookup[sym_id.index] = @as(u32, @intCast(i));
236 self.source_address_lookup[i] = if (sym.undf()) -1 else @intCast(i64, sym.n_value);236 self.source_address_lookup[i] = if (sym.undf()) -1 else @as(i64, @intCast(sym.n_value));
237237
238 const sym_name_len = mem.sliceTo(@ptrCast([*:0]const u8, self.in_strtab.?.ptr + sym.n_strx), 0).len + 1;238 const sym_name_len = mem.sliceTo(@as([*:0]const u8, @ptrCast(self.in_strtab.?.ptr + sym.n_strx)), 0).len + 1;
239 self.strtab_lookup[i] = @intCast(u32, sym_name_len);239 self.strtab_lookup[i] = @as(u32, @intCast(sym_name_len));
240 }240 }
241241
242 // If there were no undefined symbols, make sure we populate the242 // If there were no undefined symbols, make sure we populate the
...@@ -267,7 +267,7 @@ const SymbolAtIndex = struct {...@@ -267,7 +267,7 @@ const SymbolAtIndex = struct {
267267
268 fn getSymbolName(self: SymbolAtIndex, ctx: Context) []const u8 {268 fn getSymbolName(self: SymbolAtIndex, ctx: Context) []const u8 {
269 const off = self.getSymbol(ctx).n_strx;269 const off = self.getSymbol(ctx).n_strx;
270 return mem.sliceTo(@ptrCast([*:0]const u8, ctx.in_strtab.?.ptr + off), 0);270 return mem.sliceTo(@as([*:0]const u8, @ptrCast(ctx.in_strtab.?.ptr + off)), 0);
271 }271 }
272272
273 fn getSymbolSeniority(self: SymbolAtIndex, ctx: Context) u2 {273 fn getSymbolSeniority(self: SymbolAtIndex, ctx: Context) u2 {
...@@ -338,7 +338,7 @@ fn filterSymbolsBySection(symbols: []macho.nlist_64, n_sect: u8) struct {...@@ -338,7 +338,7 @@ fn filterSymbolsBySection(symbols: []macho.nlist_64, n_sect: u8) struct {
338 .n_sect = n_sect,338 .n_sect = n_sect,
339 });339 });
340340
341 return .{ .index = @intCast(u32, index), .len = @intCast(u32, len) };341 return .{ .index = @as(u32, @intCast(index)), .len = @as(u32, @intCast(len)) };
342}342}
343343
344fn filterSymbolsByAddress(symbols: []macho.nlist_64, start_addr: u64, end_addr: u64) struct {344fn filterSymbolsByAddress(symbols: []macho.nlist_64, start_addr: u64, end_addr: u64) struct {
...@@ -360,7 +360,7 @@ fn filterSymbolsByAddress(symbols: []macho.nlist_64, start_addr: u64, end_addr:...@@ -360,7 +360,7 @@ fn filterSymbolsByAddress(symbols: []macho.nlist_64, start_addr: u64, end_addr:
360 .addr = end_addr,360 .addr = end_addr,
361 });361 });
362362
363 return .{ .index = @intCast(u32, index), .len = @intCast(u32, len) };363 return .{ .index = @as(u32, @intCast(index)), .len = @as(u32, @intCast(len)) };
364}364}
365365
366const SortedSection = struct {366const SortedSection = struct {
...@@ -400,7 +400,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void {...@@ -400,7 +400,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void {
400 };400 };
401 if (sect.size == 0) continue;401 if (sect.size == 0) continue;
402402
403 const sect_id = @intCast(u8, id);403 const sect_id = @as(u8, @intCast(id));
404 const sym = self.getSectionAliasSymbolPtr(sect_id);404 const sym = self.getSectionAliasSymbolPtr(sect_id);
405 sym.* = .{405 sym.* = .{
406 .n_strx = 0,406 .n_strx = 0,
...@@ -417,7 +417,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void {...@@ -417,7 +417,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void {
417 const out_sect_id = (try zld.getOutputSection(sect)) orelse continue;417 const out_sect_id = (try zld.getOutputSection(sect)) orelse continue;
418 if (sect.size == 0) continue;418 if (sect.size == 0) continue;
419419
420 const sect_id = @intCast(u8, id);420 const sect_id = @as(u8, @intCast(id));
421 const sym_index = self.getSectionAliasSymbolIndex(sect_id);421 const sym_index = self.getSectionAliasSymbolIndex(sect_id);
422 const atom_index = try self.createAtomFromSubsection(422 const atom_index = try self.createAtomFromSubsection(
423 zld,423 zld,
...@@ -459,7 +459,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void {...@@ -459,7 +459,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void {
459 defer gpa.free(sorted_sections);459 defer gpa.free(sorted_sections);
460460
461 for (sections, 0..) |sect, id| {461 for (sections, 0..) |sect, id| {
462 sorted_sections[id] = .{ .header = sect, .id = @intCast(u8, id) };462 sorted_sections[id] = .{ .header = sect, .id = @as(u8, @intCast(id)) };
463 }463 }
464464
465 mem.sort(SortedSection, sorted_sections, {}, sectionLessThanByAddress);465 mem.sort(SortedSection, sorted_sections, {}, sectionLessThanByAddress);
...@@ -651,7 +651,7 @@ fn filterRelocs(...@@ -651,7 +651,7 @@ fn filterRelocs(
651 const start = @import("zld.zig").bsearch(macho.relocation_info, relocs, Predicate{ .addr = end_addr });651 const start = @import("zld.zig").bsearch(macho.relocation_info, relocs, Predicate{ .addr = end_addr });
652 const len = @import("zld.zig").lsearch(macho.relocation_info, relocs[start..], LPredicate{ .addr = start_addr });652 const len = @import("zld.zig").lsearch(macho.relocation_info, relocs[start..], LPredicate{ .addr = start_addr });
653653
654 return .{ .start = @intCast(u32, start), .len = @intCast(u32, len) };654 return .{ .start = @as(u32, @intCast(start)), .len = @as(u32, @intCast(len)) };
655}655}
656656
657/// Parse all relocs for the input section, and sort in descending order.657/// Parse all relocs for the input section, and sort in descending order.
...@@ -659,7 +659,7 @@ fn filterRelocs(...@@ -659,7 +659,7 @@ fn filterRelocs(
659/// section in a sorted manner which is simply not true.659/// section in a sorted manner which is simply not true.
660fn parseRelocs(self: *Object, gpa: Allocator, sect_id: u8) !void {660fn parseRelocs(self: *Object, gpa: Allocator, sect_id: u8) !void {
661 const section = self.getSourceSection(sect_id);661 const section = self.getSourceSection(sect_id);
662 const start = @intCast(u32, self.relocations.items.len);662 const start = @as(u32, @intCast(self.relocations.items.len));
663 if (self.getSourceRelocs(section)) |relocs| {663 if (self.getSourceRelocs(section)) |relocs| {
664 try self.relocations.ensureUnusedCapacity(gpa, relocs.len);664 try self.relocations.ensureUnusedCapacity(gpa, relocs.len);
665 self.relocations.appendUnalignedSliceAssumeCapacity(relocs);665 self.relocations.appendUnalignedSliceAssumeCapacity(relocs);
...@@ -677,8 +677,8 @@ fn cacheRelocs(self: *Object, zld: *Zld, atom_index: AtomIndex) !void {...@@ -677,8 +677,8 @@ fn cacheRelocs(self: *Object, zld: *Zld, atom_index: AtomIndex) !void {
677 // If there was no matching symbol present in the source symtab, this means677 // If there was no matching symbol present in the source symtab, this means
678 // we are dealing with either an entire section, or part of it, but also678 // we are dealing with either an entire section, or part of it, but also
679 // starting at the beginning.679 // starting at the beginning.
680 const nbase = @intCast(u32, self.in_symtab.?.len);680 const nbase = @as(u32, @intCast(self.in_symtab.?.len));
681 const sect_id = @intCast(u8, atom.sym_index - nbase);681 const sect_id = @as(u8, @intCast(atom.sym_index - nbase));
682 break :blk sect_id;682 break :blk sect_id;
683 };683 };
684 const source_sect = self.getSourceSection(source_sect_id);684 const source_sect = self.getSourceSection(source_sect_id);
...@@ -745,7 +745,7 @@ fn parseEhFrameSection(self: *Object, zld: *Zld, object_id: u32) !void {...@@ -745,7 +745,7 @@ fn parseEhFrameSection(self: *Object, zld: *Zld, object_id: u32) !void {
745 .object_id = object_id,745 .object_id = object_id,
746 .rel = rel,746 .rel = rel,
747 .code = it.data[offset..],747 .code = it.data[offset..],
748 .base_offset = @intCast(i32, offset),748 .base_offset = @as(i32, @intCast(offset)),
749 });749 });
750 break :blk target;750 break :blk target;
751 },751 },
...@@ -798,7 +798,7 @@ fn parseUnwindInfo(self: *Object, zld: *Zld, object_id: u32) !void {...@@ -798,7 +798,7 @@ fn parseUnwindInfo(self: *Object, zld: *Zld, object_id: u32) !void {
798 _ = try zld.initSection("__TEXT", "__unwind_info", .{});798 _ = try zld.initSection("__TEXT", "__unwind_info", .{});
799 }799 }
800800
801 try self.unwind_records_lookup.ensureTotalCapacity(gpa, @intCast(u32, self.exec_atoms.items.len));801 try self.unwind_records_lookup.ensureTotalCapacity(gpa, @as(u32, @intCast(self.exec_atoms.items.len)));
802802
803 const unwind_records = self.getUnwindRecords();803 const unwind_records = self.getUnwindRecords();
804804
...@@ -834,14 +834,14 @@ fn parseUnwindInfo(self: *Object, zld: *Zld, object_id: u32) !void {...@@ -834,14 +834,14 @@ fn parseUnwindInfo(self: *Object, zld: *Zld, object_id: u32) !void {
834 .object_id = object_id,834 .object_id = object_id,
835 .rel = rel,835 .rel = rel,
836 .code = mem.asBytes(&record),836 .code = mem.asBytes(&record),
837 .base_offset = @intCast(i32, offset),837 .base_offset = @as(i32, @intCast(offset)),
838 });838 });
839 log.debug("unwind record {d} tracks {s}", .{ record_id, zld.getSymbolName(target) });839 log.debug("unwind record {d} tracks {s}", .{ record_id, zld.getSymbolName(target) });
840 if (target.getFile() != object_id) {840 if (target.getFile() != object_id) {
841 self.unwind_relocs_lookup[record_id].dead = true;841 self.unwind_relocs_lookup[record_id].dead = true;
842 } else {842 } else {
843 const atom_index = self.getAtomIndexForSymbol(target.sym_index).?;843 const atom_index = self.getAtomIndexForSymbol(target.sym_index).?;
844 self.unwind_records_lookup.putAssumeCapacityNoClobber(atom_index, @intCast(u32, record_id));844 self.unwind_records_lookup.putAssumeCapacityNoClobber(atom_index, @as(u32, @intCast(record_id)));
845 }845 }
846 }846 }
847}847}
...@@ -869,7 +869,7 @@ pub fn getSourceSectionIndexByName(self: Object, segname: []const u8, sectname:...@@ -869,7 +869,7 @@ pub fn getSourceSectionIndexByName(self: Object, segname: []const u8, sectname:
869 const sections = self.getSourceSections();869 const sections = self.getSourceSections();
870 for (sections, 0..) |sect, i| {870 for (sections, 0..) |sect, i| {
871 if (mem.eql(u8, segname, sect.segName()) and mem.eql(u8, sectname, sect.sectName()))871 if (mem.eql(u8, segname, sect.segName()) and mem.eql(u8, sectname, sect.sectName()))
872 return @intCast(u8, i);872 return @as(u8, @intCast(i));
873 } else return null;873 } else return null;
874}874}
875875
...@@ -898,7 +898,7 @@ pub fn parseDataInCode(self: *Object, gpa: Allocator) !void {...@@ -898,7 +898,7 @@ pub fn parseDataInCode(self: *Object, gpa: Allocator) !void {
898 }898 }
899 } else return;899 } else return;
900 const ndice = @divExact(cmd.datasize, @sizeOf(macho.data_in_code_entry));900 const ndice = @divExact(cmd.datasize, @sizeOf(macho.data_in_code_entry));
901 const dice = @ptrCast([*]align(1) const macho.data_in_code_entry, self.contents.ptr + cmd.dataoff)[0..ndice];901 const dice = @as([*]align(1) const macho.data_in_code_entry, @ptrCast(self.contents.ptr + cmd.dataoff))[0..ndice];
902 try self.data_in_code.ensureTotalCapacityPrecise(gpa, dice.len);902 try self.data_in_code.ensureTotalCapacityPrecise(gpa, dice.len);
903 self.data_in_code.appendUnalignedSliceAssumeCapacity(dice);903 self.data_in_code.appendUnalignedSliceAssumeCapacity(dice);
904 mem.sort(macho.data_in_code_entry, self.data_in_code.items, {}, diceLessThan);904 mem.sort(macho.data_in_code_entry, self.data_in_code.items, {}, diceLessThan);
...@@ -945,12 +945,12 @@ pub fn parseDwarfInfo(self: Object) DwarfInfo {...@@ -945,12 +945,12 @@ pub fn parseDwarfInfo(self: Object) DwarfInfo {
945}945}
946946
947pub fn getSectionContents(self: Object, sect: macho.section_64) []const u8 {947pub fn getSectionContents(self: Object, sect: macho.section_64) []const u8 {
948 const size = @intCast(usize, sect.size);948 const size = @as(usize, @intCast(sect.size));
949 return self.contents[sect.offset..][0..size];949 return self.contents[sect.offset..][0..size];
950}950}
951951
952pub fn getSectionAliasSymbolIndex(self: Object, sect_id: u8) u32 {952pub fn getSectionAliasSymbolIndex(self: Object, sect_id: u8) u32 {
953 const start = @intCast(u32, self.in_symtab.?.len);953 const start = @as(u32, @intCast(self.in_symtab.?.len));
954 return start + sect_id;954 return start + sect_id;
955}955}
956956
...@@ -964,7 +964,7 @@ pub fn getSectionAliasSymbolPtr(self: *Object, sect_id: u8) *macho.nlist_64 {...@@ -964,7 +964,7 @@ pub fn getSectionAliasSymbolPtr(self: *Object, sect_id: u8) *macho.nlist_64 {
964964
965fn getSourceRelocs(self: Object, sect: macho.section_64) ?[]align(1) const macho.relocation_info {965fn getSourceRelocs(self: Object, sect: macho.section_64) ?[]align(1) const macho.relocation_info {
966 if (sect.nreloc == 0) return null;966 if (sect.nreloc == 0) return null;
967 return @ptrCast([*]align(1) const macho.relocation_info, self.contents.ptr + sect.reloff)[0..sect.nreloc];967 return @as([*]align(1) const macho.relocation_info, @ptrCast(self.contents.ptr + sect.reloff))[0..sect.nreloc];
968}968}
969969
970pub fn getRelocs(self: Object, sect_id: u8) []const macho.relocation_info {970pub fn getRelocs(self: Object, sect_id: u8) []const macho.relocation_info {
...@@ -1005,25 +1005,25 @@ pub fn getSymbolByAddress(self: Object, addr: u64, sect_hint: ?u8) u32 {...@@ -1005,25 +1005,25 @@ pub fn getSymbolByAddress(self: Object, addr: u64, sect_hint: ?u8) u32 {
1005 const target_sym_index = @import("zld.zig").lsearch(1005 const target_sym_index = @import("zld.zig").lsearch(
1006 i64,1006 i64,
1007 self.source_address_lookup[lookup.start..][0..lookup.len],1007 self.source_address_lookup[lookup.start..][0..lookup.len],
1008 Predicate{ .addr = @intCast(i64, addr) },1008 Predicate{ .addr = @as(i64, @intCast(addr)) },
1009 );1009 );
1010 if (target_sym_index > 0) {1010 if (target_sym_index > 0) {
1011 return @intCast(u32, lookup.start + target_sym_index - 1);1011 return @as(u32, @intCast(lookup.start + target_sym_index - 1));
1012 }1012 }
1013 }1013 }
1014 return self.getSectionAliasSymbolIndex(sect_id);1014 return self.getSectionAliasSymbolIndex(sect_id);
1015 }1015 }
10161016
1017 const target_sym_index = @import("zld.zig").lsearch(i64, self.source_address_lookup, Predicate{1017 const target_sym_index = @import("zld.zig").lsearch(i64, self.source_address_lookup, Predicate{
1018 .addr = @intCast(i64, addr),1018 .addr = @as(i64, @intCast(addr)),
1019 });1019 });
1020 assert(target_sym_index > 0);1020 assert(target_sym_index > 0);
1021 return @intCast(u32, target_sym_index - 1);1021 return @as(u32, @intCast(target_sym_index - 1));
1022}1022}
10231023
1024pub fn getGlobal(self: Object, sym_index: u32) ?u32 {1024pub fn getGlobal(self: Object, sym_index: u32) ?u32 {
1025 if (self.globals_lookup[sym_index] == -1) return null;1025 if (self.globals_lookup[sym_index] == -1) return null;
1026 return @intCast(u32, self.globals_lookup[sym_index]);1026 return @as(u32, @intCast(self.globals_lookup[sym_index]));
1027}1027}
10281028
1029pub fn getAtomIndexForSymbol(self: Object, sym_index: u32) ?AtomIndex {1029pub fn getAtomIndexForSymbol(self: Object, sym_index: u32) ?AtomIndex {
...@@ -1041,7 +1041,7 @@ pub fn getUnwindRecords(self: Object) []align(1) const macho.compact_unwind_entr...@@ -1041,7 +1041,7 @@ pub fn getUnwindRecords(self: Object) []align(1) const macho.compact_unwind_entr
1041 const sect = self.getSourceSection(sect_id);1041 const sect = self.getSourceSection(sect_id);
1042 const data = self.getSectionContents(sect);1042 const data = self.getSectionContents(sect);
1043 const num_entries = @divExact(data.len, @sizeOf(macho.compact_unwind_entry));1043 const num_entries = @divExact(data.len, @sizeOf(macho.compact_unwind_entry));
1044 return @ptrCast([*]align(1) const macho.compact_unwind_entry, data)[0..num_entries];1044 return @as([*]align(1) const macho.compact_unwind_entry, @ptrCast(data))[0..num_entries];
1045}1045}
10461046
1047pub fn hasEhFrameRecords(self: Object) bool {1047pub fn hasEhFrameRecords(self: Object) bool {
src/link/MachO/Relocation.zig+23-23
...@@ -94,9 +94,9 @@ pub fn resolve(self: Relocation, macho_file: *MachO, atom_index: Atom.Index, cod...@@ -94,9 +94,9 @@ pub fn resolve(self: Relocation, macho_file: *MachO, atom_index: Atom.Index, cod
94 .tlv_initializer => blk: {94 .tlv_initializer => blk: {
95 assert(self.addend == 0); // Addend here makes no sense.95 assert(self.addend == 0); // Addend here makes no sense.
96 const header = macho_file.sections.items(.header)[macho_file.thread_data_section_index.?];96 const header = macho_file.sections.items(.header)[macho_file.thread_data_section_index.?];
97 break :blk @intCast(i64, target_base_addr - header.addr);97 break :blk @as(i64, @intCast(target_base_addr - header.addr));
98 },98 },
99 else => @intCast(i64, target_base_addr) + self.addend,99 else => @as(i64, @intCast(target_base_addr)) + self.addend,
100 };100 };
101101
102 log.debug(" ({x}: [() => 0x{x} ({s})) ({s})", .{102 log.debug(" ({x}: [() => 0x{x} ({s})) ({s})", .{
...@@ -119,7 +119,7 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: []...@@ -119,7 +119,7 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: []
119 .branch => {119 .branch => {
120 const displacement = math.cast(120 const displacement = math.cast(
121 i28,121 i28,
122 @intCast(i64, target_addr) - @intCast(i64, source_addr),122 @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr)),
123 ) orelse unreachable; // TODO codegen should never allow for jump larger than i28 displacement123 ) orelse unreachable; // TODO codegen should never allow for jump larger than i28 displacement
124 var inst = aarch64.Instruction{124 var inst = aarch64.Instruction{
125 .unconditional_branch_immediate = mem.bytesToValue(meta.TagPayload(125 .unconditional_branch_immediate = mem.bytesToValue(meta.TagPayload(
...@@ -127,25 +127,25 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: []...@@ -127,25 +127,25 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: []
127 aarch64.Instruction.unconditional_branch_immediate,127 aarch64.Instruction.unconditional_branch_immediate,
128 ), buffer[0..4]),128 ), buffer[0..4]),
129 };129 };
130 inst.unconditional_branch_immediate.imm26 = @truncate(u26, @bitCast(u28, displacement >> 2));130 inst.unconditional_branch_immediate.imm26 = @as(u26, @truncate(@as(u28, @bitCast(displacement >> 2))));
131 mem.writeIntLittle(u32, buffer[0..4], inst.toU32());131 mem.writeIntLittle(u32, buffer[0..4], inst.toU32());
132 },132 },
133 .page, .got_page => {133 .page, .got_page => {
134 const source_page = @intCast(i32, source_addr >> 12);134 const source_page = @as(i32, @intCast(source_addr >> 12));
135 const target_page = @intCast(i32, target_addr >> 12);135 const target_page = @as(i32, @intCast(target_addr >> 12));
136 const pages = @bitCast(u21, @intCast(i21, target_page - source_page));136 const pages = @as(u21, @bitCast(@as(i21, @intCast(target_page - source_page))));
137 var inst = aarch64.Instruction{137 var inst = aarch64.Instruction{
138 .pc_relative_address = mem.bytesToValue(meta.TagPayload(138 .pc_relative_address = mem.bytesToValue(meta.TagPayload(
139 aarch64.Instruction,139 aarch64.Instruction,
140 aarch64.Instruction.pc_relative_address,140 aarch64.Instruction.pc_relative_address,
141 ), buffer[0..4]),141 ), buffer[0..4]),
142 };142 };
143 inst.pc_relative_address.immhi = @truncate(u19, pages >> 2);143 inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2));
144 inst.pc_relative_address.immlo = @truncate(u2, pages);144 inst.pc_relative_address.immlo = @as(u2, @truncate(pages));
145 mem.writeIntLittle(u32, buffer[0..4], inst.toU32());145 mem.writeIntLittle(u32, buffer[0..4], inst.toU32());
146 },146 },
147 .pageoff, .got_pageoff => {147 .pageoff, .got_pageoff => {
148 const narrowed = @truncate(u12, @intCast(u64, target_addr));148 const narrowed = @as(u12, @truncate(@as(u64, @intCast(target_addr))));
149 if (isArithmeticOp(buffer[0..4])) {149 if (isArithmeticOp(buffer[0..4])) {
150 var inst = aarch64.Instruction{150 var inst = aarch64.Instruction{
151 .add_subtract_immediate = mem.bytesToValue(meta.TagPayload(151 .add_subtract_immediate = mem.bytesToValue(meta.TagPayload(
...@@ -180,8 +180,8 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: []...@@ -180,8 +180,8 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: []
180 }180 }
181 },181 },
182 .tlv_initializer, .unsigned => switch (self.length) {182 .tlv_initializer, .unsigned => switch (self.length) {
183 2 => mem.writeIntLittle(u32, buffer[0..4], @truncate(u32, @bitCast(u64, target_addr))),183 2 => mem.writeIntLittle(u32, buffer[0..4], @as(u32, @truncate(@as(u64, @bitCast(target_addr))))),
184 3 => mem.writeIntLittle(u64, buffer[0..8], @bitCast(u64, target_addr)),184 3 => mem.writeIntLittle(u64, buffer[0..8], @as(u64, @bitCast(target_addr))),
185 else => unreachable,185 else => unreachable,
186 },186 },
187 .got, .signed, .tlv => unreachable, // Invalid target architecture.187 .got, .signed, .tlv => unreachable, // Invalid target architecture.
...@@ -191,16 +191,16 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: []...@@ -191,16 +191,16 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: []
191fn resolveX8664(self: Relocation, source_addr: u64, target_addr: i64, code: []u8) void {191fn resolveX8664(self: Relocation, source_addr: u64, target_addr: i64, code: []u8) void {
192 switch (self.type) {192 switch (self.type) {
193 .branch, .got, .tlv, .signed => {193 .branch, .got, .tlv, .signed => {
194 const displacement = @intCast(i32, @intCast(i64, target_addr) - @intCast(i64, source_addr) - 4);194 const displacement = @as(i32, @intCast(@as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr)) - 4));
195 mem.writeIntLittle(u32, code[self.offset..][0..4], @bitCast(u32, displacement));195 mem.writeIntLittle(u32, code[self.offset..][0..4], @as(u32, @bitCast(displacement)));
196 },196 },
197 .tlv_initializer, .unsigned => {197 .tlv_initializer, .unsigned => {
198 switch (self.length) {198 switch (self.length) {
199 2 => {199 2 => {
200 mem.writeIntLittle(u32, code[self.offset..][0..4], @truncate(u32, @bitCast(u64, target_addr)));200 mem.writeIntLittle(u32, code[self.offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(target_addr)))));
201 },201 },
202 3 => {202 3 => {
203 mem.writeIntLittle(u64, code[self.offset..][0..8], @bitCast(u64, target_addr));203 mem.writeIntLittle(u64, code[self.offset..][0..8], @as(u64, @bitCast(target_addr)));
204 },204 },
205 else => unreachable,205 else => unreachable,
206 }206 }
...@@ -210,24 +210,24 @@ fn resolveX8664(self: Relocation, source_addr: u64, target_addr: i64, code: []u8...@@ -210,24 +210,24 @@ fn resolveX8664(self: Relocation, source_addr: u64, target_addr: i64, code: []u8
210}210}
211211
212pub inline fn isArithmeticOp(inst: *const [4]u8) bool {212pub inline fn isArithmeticOp(inst: *const [4]u8) bool {
213 const group_decode = @truncate(u5, inst[3]);213 const group_decode = @as(u5, @truncate(inst[3]));
214 return ((group_decode >> 2) == 4);214 return ((group_decode >> 2) == 4);
215}215}
216216
217pub fn calcPcRelativeDisplacementX86(source_addr: u64, target_addr: u64, correction: u3) error{Overflow}!i32 {217pub fn calcPcRelativeDisplacementX86(source_addr: u64, target_addr: u64, correction: u3) error{Overflow}!i32 {
218 const disp = @intCast(i64, target_addr) - @intCast(i64, source_addr + 4 + correction);218 const disp = @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr + 4 + correction));
219 return math.cast(i32, disp) orelse error.Overflow;219 return math.cast(i32, disp) orelse error.Overflow;
220}220}
221221
222pub fn calcPcRelativeDisplacementArm64(source_addr: u64, target_addr: u64) error{Overflow}!i28 {222pub fn calcPcRelativeDisplacementArm64(source_addr: u64, target_addr: u64) error{Overflow}!i28 {
223 const disp = @intCast(i64, target_addr) - @intCast(i64, source_addr);223 const disp = @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr));
224 return math.cast(i28, disp) orelse error.Overflow;224 return math.cast(i28, disp) orelse error.Overflow;
225}225}
226226
227pub fn calcNumberOfPages(source_addr: u64, target_addr: u64) i21 {227pub fn calcNumberOfPages(source_addr: u64, target_addr: u64) i21 {
228 const source_page = @intCast(i32, source_addr >> 12);228 const source_page = @as(i32, @intCast(source_addr >> 12));
229 const target_page = @intCast(i32, target_addr >> 12);229 const target_page = @as(i32, @intCast(target_addr >> 12));
230 const pages = @intCast(i21, target_page - source_page);230 const pages = @as(i21, @intCast(target_page - source_page));
231 return pages;231 return pages;
232}232}
233233
...@@ -241,7 +241,7 @@ pub const PageOffsetInstKind = enum {...@@ -241,7 +241,7 @@ pub const PageOffsetInstKind = enum {
241};241};
242242
243pub fn calcPageOffset(target_addr: u64, kind: PageOffsetInstKind) !u12 {243pub fn calcPageOffset(target_addr: u64, kind: PageOffsetInstKind) !u12 {
244 const narrowed = @truncate(u12, target_addr);244 const narrowed = @as(u12, @truncate(target_addr));
245 return switch (kind) {245 return switch (kind) {
246 .arithmetic, .load_store_8 => narrowed,246 .arithmetic, .load_store_8 => narrowed,
247 .load_store_16 => try math.divExact(u12, narrowed, 2),247 .load_store_16 => try math.divExact(u12, narrowed, 2),
src/link/MachO/Trie.zig+1-1
...@@ -220,7 +220,7 @@ pub const Node = struct {...@@ -220,7 +220,7 @@ pub const Node = struct {
220 try writer.writeByte(0);220 try writer.writeByte(0);
221 }221 }
222 // Write number of edges (max legal number of edges is 256).222 // Write number of edges (max legal number of edges is 256).
223 try writer.writeByte(@intCast(u8, self.edges.items.len));223 try writer.writeByte(@as(u8, @intCast(self.edges.items.len)));
224224
225 for (self.edges.items) |edge| {225 for (self.edges.items) |edge| {
226 // Write edge label and offset to next node in trie.226 // Write edge label and offset to next node in trie.
src/link/MachO/UnwindInfo.zig+54-54
...@@ -87,7 +87,7 @@ const Page = struct {...@@ -87,7 +87,7 @@ const Page = struct {
87 const record_id = page.page_encodings[index];87 const record_id = page.page_encodings[index];
88 const record = info.records.items[record_id];88 const record = info.records.items[record_id];
89 if (record.compactUnwindEncoding == enc) {89 if (record.compactUnwindEncoding == enc) {
90 return @intCast(u8, index);90 return @as(u8, @intCast(index));
91 }91 }
92 }92 }
93 return null;93 return null;
...@@ -150,14 +150,14 @@ const Page = struct {...@@ -150,14 +150,14 @@ const Page = struct {
150150
151 for (info.records.items[page.start..][0..page.count]) |record| {151 for (info.records.items[page.start..][0..page.count]) |record| {
152 try writer.writeStruct(macho.unwind_info_regular_second_level_entry{152 try writer.writeStruct(macho.unwind_info_regular_second_level_entry{
153 .functionOffset = @intCast(u32, record.rangeStart),153 .functionOffset = @as(u32, @intCast(record.rangeStart)),
154 .encoding = record.compactUnwindEncoding,154 .encoding = record.compactUnwindEncoding,
155 });155 });
156 }156 }
157 },157 },
158 .compressed => {158 .compressed => {
159 const entry_offset = @sizeOf(macho.unwind_info_compressed_second_level_page_header) +159 const entry_offset = @sizeOf(macho.unwind_info_compressed_second_level_page_header) +
160 @intCast(u16, page.page_encodings_count) * @sizeOf(u32);160 @as(u16, @intCast(page.page_encodings_count)) * @sizeOf(u32);
161 try writer.writeStruct(macho.unwind_info_compressed_second_level_page_header{161 try writer.writeStruct(macho.unwind_info_compressed_second_level_page_header{
162 .entryPageOffset = entry_offset,162 .entryPageOffset = entry_offset,
163 .entryCount = page.count,163 .entryCount = page.count,
...@@ -183,8 +183,8 @@ const Page = struct {...@@ -183,8 +183,8 @@ const Page = struct {
183 break :blk ncommon + page.getPageEncoding(info, record.compactUnwindEncoding).?;183 break :blk ncommon + page.getPageEncoding(info, record.compactUnwindEncoding).?;
184 };184 };
185 const compressed = macho.UnwindInfoCompressedEntry{185 const compressed = macho.UnwindInfoCompressedEntry{
186 .funcOffset = @intCast(u24, record.rangeStart - first_entry.rangeStart),186 .funcOffset = @as(u24, @intCast(record.rangeStart - first_entry.rangeStart)),
187 .encodingIndex = @intCast(u8, enc_index),187 .encodingIndex = @as(u8, @intCast(enc_index)),
188 };188 };
189 try writer.writeStruct(compressed);189 try writer.writeStruct(compressed);
190 }190 }
...@@ -214,15 +214,15 @@ pub fn scanRelocs(zld: *Zld) !void {...@@ -214,15 +214,15 @@ pub fn scanRelocs(zld: *Zld) !void {
214 if (!UnwindEncoding.isDwarf(record.compactUnwindEncoding, cpu_arch)) {214 if (!UnwindEncoding.isDwarf(record.compactUnwindEncoding, cpu_arch)) {
215 if (getPersonalityFunctionReloc(215 if (getPersonalityFunctionReloc(
216 zld,216 zld,
217 @intCast(u32, object_id),217 @as(u32, @intCast(object_id)),
218 record_id,218 record_id,
219 )) |rel| {219 )) |rel| {
220 // Personality function; add GOT pointer.220 // Personality function; add GOT pointer.
221 const target = Atom.parseRelocTarget(zld, .{221 const target = Atom.parseRelocTarget(zld, .{
222 .object_id = @intCast(u32, object_id),222 .object_id = @as(u32, @intCast(object_id)),
223 .rel = rel,223 .rel = rel,
224 .code = mem.asBytes(&record),224 .code = mem.asBytes(&record),
225 .base_offset = @intCast(i32, record_id * @sizeOf(macho.compact_unwind_entry)),225 .base_offset = @as(i32, @intCast(record_id * @sizeOf(macho.compact_unwind_entry))),
226 });226 });
227 try Atom.addGotEntry(zld, target);227 try Atom.addGotEntry(zld, target);
228 }228 }
...@@ -258,18 +258,18 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {...@@ -258,18 +258,18 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
258 var record = unwind_records[record_id];258 var record = unwind_records[record_id];
259259
260 if (UnwindEncoding.isDwarf(record.compactUnwindEncoding, cpu_arch)) {260 if (UnwindEncoding.isDwarf(record.compactUnwindEncoding, cpu_arch)) {
261 try info.collectPersonalityFromDwarf(zld, @intCast(u32, object_id), atom_index, &record);261 try info.collectPersonalityFromDwarf(zld, @as(u32, @intCast(object_id)), atom_index, &record);
262 } else {262 } else {
263 if (getPersonalityFunctionReloc(263 if (getPersonalityFunctionReloc(
264 zld,264 zld,
265 @intCast(u32, object_id),265 @as(u32, @intCast(object_id)),
266 record_id,266 record_id,
267 )) |rel| {267 )) |rel| {
268 const target = Atom.parseRelocTarget(zld, .{268 const target = Atom.parseRelocTarget(zld, .{
269 .object_id = @intCast(u32, object_id),269 .object_id = @as(u32, @intCast(object_id)),
270 .rel = rel,270 .rel = rel,
271 .code = mem.asBytes(&record),271 .code = mem.asBytes(&record),
272 .base_offset = @intCast(i32, record_id * @sizeOf(macho.compact_unwind_entry)),272 .base_offset = @as(i32, @intCast(record_id * @sizeOf(macho.compact_unwind_entry))),
273 });273 });
274 const personality_index = info.getPersonalityFunction(target) orelse inner: {274 const personality_index = info.getPersonalityFunction(target) orelse inner: {
275 const personality_index = info.personalities_count;275 const personality_index = info.personalities_count;
...@@ -282,14 +282,14 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {...@@ -282,14 +282,14 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
282 UnwindEncoding.setPersonalityIndex(&record.compactUnwindEncoding, personality_index + 1);282 UnwindEncoding.setPersonalityIndex(&record.compactUnwindEncoding, personality_index + 1);
283 }283 }
284284
285 if (getLsdaReloc(zld, @intCast(u32, object_id), record_id)) |rel| {285 if (getLsdaReloc(zld, @as(u32, @intCast(object_id)), record_id)) |rel| {
286 const target = Atom.parseRelocTarget(zld, .{286 const target = Atom.parseRelocTarget(zld, .{
287 .object_id = @intCast(u32, object_id),287 .object_id = @as(u32, @intCast(object_id)),
288 .rel = rel,288 .rel = rel,
289 .code = mem.asBytes(&record),289 .code = mem.asBytes(&record),
290 .base_offset = @intCast(i32, record_id * @sizeOf(macho.compact_unwind_entry)),290 .base_offset = @as(i32, @intCast(record_id * @sizeOf(macho.compact_unwind_entry))),
291 });291 });
292 record.lsda = @bitCast(u64, target);292 record.lsda = @as(u64, @bitCast(target));
293 }293 }
294 }294 }
295 break :blk record;295 break :blk record;
...@@ -302,7 +302,7 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {...@@ -302,7 +302,7 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
302 if (object.eh_frame_records_lookup.get(atom_index)) |fde_offset| {302 if (object.eh_frame_records_lookup.get(atom_index)) |fde_offset| {
303 if (object.eh_frame_relocs_lookup.get(fde_offset).?.dead) continue;303 if (object.eh_frame_relocs_lookup.get(fde_offset).?.dead) continue;
304 var record = nullRecord();304 var record = nullRecord();
305 try info.collectPersonalityFromDwarf(zld, @intCast(u32, object_id), atom_index, &record);305 try info.collectPersonalityFromDwarf(zld, @as(u32, @intCast(object_id)), atom_index, &record);
306 switch (cpu_arch) {306 switch (cpu_arch) {
307 .aarch64 => UnwindEncoding.setMode(&record.compactUnwindEncoding, macho.UNWIND_ARM64_MODE.DWARF),307 .aarch64 => UnwindEncoding.setMode(&record.compactUnwindEncoding, macho.UNWIND_ARM64_MODE.DWARF),
308 .x86_64 => UnwindEncoding.setMode(&record.compactUnwindEncoding, macho.UNWIND_X86_64_MODE.DWARF),308 .x86_64 => UnwindEncoding.setMode(&record.compactUnwindEncoding, macho.UNWIND_X86_64_MODE.DWARF),
...@@ -320,7 +320,7 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {...@@ -320,7 +320,7 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
320 const sym = zld.getSymbol(sym_loc);320 const sym = zld.getSymbol(sym_loc);
321 assert(sym.n_desc != N_DEAD);321 assert(sym.n_desc != N_DEAD);
322 record.rangeStart = sym.n_value;322 record.rangeStart = sym.n_value;
323 record.rangeLength = @intCast(u32, atom.size);323 record.rangeLength = @as(u32, @intCast(atom.size));
324324
325 records.appendAssumeCapacity(record);325 records.appendAssumeCapacity(record);
326 atom_indexes.appendAssumeCapacity(atom_index);326 atom_indexes.appendAssumeCapacity(atom_index);
...@@ -329,7 +329,7 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {...@@ -329,7 +329,7 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
329329
330 // Fold records330 // Fold records
331 try info.records.ensureTotalCapacity(info.gpa, records.items.len);331 try info.records.ensureTotalCapacity(info.gpa, records.items.len);
332 try info.records_lookup.ensureTotalCapacity(info.gpa, @intCast(u32, atom_indexes.items.len));332 try info.records_lookup.ensureTotalCapacity(info.gpa, @as(u32, @intCast(atom_indexes.items.len)));
333333
334 var maybe_prev: ?macho.compact_unwind_entry = null;334 var maybe_prev: ?macho.compact_unwind_entry = null;
335 for (records.items, 0..) |record, i| {335 for (records.items, 0..) |record, i| {
...@@ -341,15 +341,15 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {...@@ -341,15 +341,15 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
341 (prev.personalityFunction != record.personalityFunction) or341 (prev.personalityFunction != record.personalityFunction) or
342 record.lsda > 0)342 record.lsda > 0)
343 {343 {
344 const record_id = @intCast(RecordIndex, info.records.items.len);344 const record_id = @as(RecordIndex, @intCast(info.records.items.len));
345 info.records.appendAssumeCapacity(record);345 info.records.appendAssumeCapacity(record);
346 maybe_prev = record;346 maybe_prev = record;
347 break :blk record_id;347 break :blk record_id;
348 } else {348 } else {
349 break :blk @intCast(RecordIndex, info.records.items.len - 1);349 break :blk @as(RecordIndex, @intCast(info.records.items.len - 1));
350 }350 }
351 } else {351 } else {
352 const record_id = @intCast(RecordIndex, info.records.items.len);352 const record_id = @as(RecordIndex, @intCast(info.records.items.len));
353 info.records.appendAssumeCapacity(record);353 info.records.appendAssumeCapacity(record);
354 maybe_prev = record;354 maybe_prev = record;
355 break :blk record_id;355 break :blk record_id;
...@@ -459,14 +459,14 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {...@@ -459,14 +459,14 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
459 }459 }
460 }460 }
461461
462 page.count = @intCast(u16, i - page.start);462 page.count = @as(u16, @intCast(i - page.start));
463463
464 if (i < info.records.items.len and page.count < max_regular_second_level_entries) {464 if (i < info.records.items.len and page.count < max_regular_second_level_entries) {
465 page.kind = .regular;465 page.kind = .regular;
466 page.count = @intCast(u16, @min(466 page.count = @as(u16, @intCast(@min(
467 max_regular_second_level_entries,467 max_regular_second_level_entries,
468 info.records.items.len - page.start,468 info.records.items.len - page.start,
469 ));469 )));
470 i = page.start + page.count;470 i = page.start + page.count;
471 } else {471 } else {
472 page.kind = .compressed;472 page.kind = .compressed;
...@@ -479,11 +479,11 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {...@@ -479,11 +479,11 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
479 }479 }
480480
481 // Save indices of records requiring LSDA relocation481 // Save indices of records requiring LSDA relocation
482 try info.lsdas_lookup.ensureTotalCapacity(info.gpa, @intCast(u32, info.records.items.len));482 try info.lsdas_lookup.ensureTotalCapacity(info.gpa, @as(u32, @intCast(info.records.items.len)));
483 for (info.records.items, 0..) |rec, i| {483 for (info.records.items, 0..) |rec, i| {
484 info.lsdas_lookup.putAssumeCapacityNoClobber(@intCast(RecordIndex, i), @intCast(u32, info.lsdas.items.len));484 info.lsdas_lookup.putAssumeCapacityNoClobber(@as(RecordIndex, @intCast(i)), @as(u32, @intCast(info.lsdas.items.len)));
485 if (rec.lsda == 0) continue;485 if (rec.lsda == 0) continue;
486 try info.lsdas.append(info.gpa, @intCast(RecordIndex, i));486 try info.lsdas.append(info.gpa, @as(RecordIndex, @intCast(i)));
487 }487 }
488}488}
489489
...@@ -506,7 +506,7 @@ fn collectPersonalityFromDwarf(...@@ -506,7 +506,7 @@ fn collectPersonalityFromDwarf(
506506
507 if (cie.getPersonalityPointerReloc(507 if (cie.getPersonalityPointerReloc(
508 zld,508 zld,
509 @intCast(u32, object_id),509 @as(u32, @intCast(object_id)),
510 cie_offset,510 cie_offset,
511 )) |target| {511 )) |target| {
512 const personality_index = info.getPersonalityFunction(target) orelse inner: {512 const personality_index = info.getPersonalityFunction(target) orelse inner: {
...@@ -532,8 +532,8 @@ fn calcRequiredSize(info: UnwindInfo) usize {...@@ -532,8 +532,8 @@ fn calcRequiredSize(info: UnwindInfo) usize {
532 var total_size: usize = 0;532 var total_size: usize = 0;
533 total_size += @sizeOf(macho.unwind_info_section_header);533 total_size += @sizeOf(macho.unwind_info_section_header);
534 total_size +=534 total_size +=
535 @intCast(usize, info.common_encodings_count) * @sizeOf(macho.compact_unwind_encoding_t);535 @as(usize, @intCast(info.common_encodings_count)) * @sizeOf(macho.compact_unwind_encoding_t);
536 total_size += @intCast(usize, info.personalities_count) * @sizeOf(u32);536 total_size += @as(usize, @intCast(info.personalities_count)) * @sizeOf(u32);
537 total_size += (info.pages.items.len + 1) * @sizeOf(macho.unwind_info_section_header_index_entry);537 total_size += (info.pages.items.len + 1) * @sizeOf(macho.unwind_info_section_header_index_entry);
538 total_size += info.lsdas.items.len * @sizeOf(macho.unwind_info_section_header_lsda_index_entry);538 total_size += info.lsdas.items.len * @sizeOf(macho.unwind_info_section_header_lsda_index_entry);
539 total_size += info.pages.items.len * second_level_page_bytes;539 total_size += info.pages.items.len * second_level_page_bytes;
...@@ -557,7 +557,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {...@@ -557,7 +557,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {
557 const atom_index = zld.getGotAtomIndexForSymbol(target).?;557 const atom_index = zld.getGotAtomIndexForSymbol(target).?;
558 const atom = zld.getAtom(atom_index);558 const atom = zld.getAtom(atom_index);
559 const sym = zld.getSymbol(atom.getSymbolWithLoc());559 const sym = zld.getSymbol(atom.getSymbolWithLoc());
560 personalities[i] = @intCast(u32, sym.n_value - seg.vmaddr);560 personalities[i] = @as(u32, @intCast(sym.n_value - seg.vmaddr));
561 log.debug(" {d}: 0x{x} ({s})", .{ i, personalities[i], zld.getSymbolName(target) });561 log.debug(" {d}: 0x{x} ({s})", .{ i, personalities[i], zld.getSymbolName(target) });
562 }562 }
563563
...@@ -570,7 +570,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {...@@ -570,7 +570,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {
570 }570 }
571571
572 if (rec.compactUnwindEncoding > 0 and !UnwindEncoding.isDwarf(rec.compactUnwindEncoding, cpu_arch)) {572 if (rec.compactUnwindEncoding > 0 and !UnwindEncoding.isDwarf(rec.compactUnwindEncoding, cpu_arch)) {
573 const lsda_target = @bitCast(SymbolWithLoc, rec.lsda);573 const lsda_target = @as(SymbolWithLoc, @bitCast(rec.lsda));
574 if (lsda_target.getFile()) |_| {574 if (lsda_target.getFile()) |_| {
575 const sym = zld.getSymbol(lsda_target);575 const sym = zld.getSymbol(lsda_target);
576 rec.lsda = sym.n_value - seg.vmaddr;576 rec.lsda = sym.n_value - seg.vmaddr;
...@@ -601,7 +601,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {...@@ -601,7 +601,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {
601 const personalities_offset: u32 = common_encodings_offset + common_encodings_count * @sizeOf(u32);601 const personalities_offset: u32 = common_encodings_offset + common_encodings_count * @sizeOf(u32);
602 const personalities_count: u32 = info.personalities_count;602 const personalities_count: u32 = info.personalities_count;
603 const indexes_offset: u32 = personalities_offset + personalities_count * @sizeOf(u32);603 const indexes_offset: u32 = personalities_offset + personalities_count * @sizeOf(u32);
604 const indexes_count: u32 = @intCast(u32, info.pages.items.len + 1);604 const indexes_count: u32 = @as(u32, @intCast(info.pages.items.len + 1));
605605
606 try writer.writeStruct(macho.unwind_info_section_header{606 try writer.writeStruct(macho.unwind_info_section_header{
607 .commonEncodingsArraySectionOffset = common_encodings_offset,607 .commonEncodingsArraySectionOffset = common_encodings_offset,
...@@ -615,34 +615,34 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {...@@ -615,34 +615,34 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {
615 try writer.writeAll(mem.sliceAsBytes(info.common_encodings[0..info.common_encodings_count]));615 try writer.writeAll(mem.sliceAsBytes(info.common_encodings[0..info.common_encodings_count]));
616 try writer.writeAll(mem.sliceAsBytes(personalities[0..info.personalities_count]));616 try writer.writeAll(mem.sliceAsBytes(personalities[0..info.personalities_count]));
617617
618 const pages_base_offset = @intCast(u32, size - (info.pages.items.len * second_level_page_bytes));618 const pages_base_offset = @as(u32, @intCast(size - (info.pages.items.len * second_level_page_bytes)));
619 const lsda_base_offset = @intCast(u32, pages_base_offset -619 const lsda_base_offset = @as(u32, @intCast(pages_base_offset -
620 (info.lsdas.items.len * @sizeOf(macho.unwind_info_section_header_lsda_index_entry)));620 (info.lsdas.items.len * @sizeOf(macho.unwind_info_section_header_lsda_index_entry))));
621 for (info.pages.items, 0..) |page, i| {621 for (info.pages.items, 0..) |page, i| {
622 assert(page.count > 0);622 assert(page.count > 0);
623 const first_entry = info.records.items[page.start];623 const first_entry = info.records.items[page.start];
624 try writer.writeStruct(macho.unwind_info_section_header_index_entry{624 try writer.writeStruct(macho.unwind_info_section_header_index_entry{
625 .functionOffset = @intCast(u32, first_entry.rangeStart),625 .functionOffset = @as(u32, @intCast(first_entry.rangeStart)),
626 .secondLevelPagesSectionOffset = @intCast(u32, pages_base_offset + i * second_level_page_bytes),626 .secondLevelPagesSectionOffset = @as(u32, @intCast(pages_base_offset + i * second_level_page_bytes)),
627 .lsdaIndexArraySectionOffset = lsda_base_offset +627 .lsdaIndexArraySectionOffset = lsda_base_offset +
628 info.lsdas_lookup.get(page.start).? * @sizeOf(macho.unwind_info_section_header_lsda_index_entry),628 info.lsdas_lookup.get(page.start).? * @sizeOf(macho.unwind_info_section_header_lsda_index_entry),
629 });629 });
630 }630 }
631631
632 const last_entry = info.records.items[info.records.items.len - 1];632 const last_entry = info.records.items[info.records.items.len - 1];
633 const sentinel_address = @intCast(u32, last_entry.rangeStart + last_entry.rangeLength);633 const sentinel_address = @as(u32, @intCast(last_entry.rangeStart + last_entry.rangeLength));
634 try writer.writeStruct(macho.unwind_info_section_header_index_entry{634 try writer.writeStruct(macho.unwind_info_section_header_index_entry{
635 .functionOffset = sentinel_address,635 .functionOffset = sentinel_address,
636 .secondLevelPagesSectionOffset = 0,636 .secondLevelPagesSectionOffset = 0,
637 .lsdaIndexArraySectionOffset = lsda_base_offset +637 .lsdaIndexArraySectionOffset = lsda_base_offset +
638 @intCast(u32, info.lsdas.items.len) * @sizeOf(macho.unwind_info_section_header_lsda_index_entry),638 @as(u32, @intCast(info.lsdas.items.len)) * @sizeOf(macho.unwind_info_section_header_lsda_index_entry),
639 });639 });
640640
641 for (info.lsdas.items) |record_id| {641 for (info.lsdas.items) |record_id| {
642 const record = info.records.items[record_id];642 const record = info.records.items[record_id];
643 try writer.writeStruct(macho.unwind_info_section_header_lsda_index_entry{643 try writer.writeStruct(macho.unwind_info_section_header_lsda_index_entry{
644 .functionOffset = @intCast(u32, record.rangeStart),644 .functionOffset = @as(u32, @intCast(record.rangeStart)),
645 .lsdaOffset = @intCast(u32, record.lsda),645 .lsdaOffset = @as(u32, @intCast(record.lsda)),
646 });646 });
647 }647 }
648648
...@@ -674,7 +674,7 @@ fn getRelocs(zld: *Zld, object_id: u32, record_id: usize) []const macho.relocati...@@ -674,7 +674,7 @@ fn getRelocs(zld: *Zld, object_id: u32, record_id: usize) []const macho.relocati
674}674}
675675
676fn isPersonalityFunction(record_id: usize, rel: macho.relocation_info) bool {676fn isPersonalityFunction(record_id: usize, rel: macho.relocation_info) bool {
677 const base_offset = @intCast(i32, record_id * @sizeOf(macho.compact_unwind_entry));677 const base_offset = @as(i32, @intCast(record_id * @sizeOf(macho.compact_unwind_entry)));
678 const rel_offset = rel.r_address - base_offset;678 const rel_offset = rel.r_address - base_offset;
679 return rel_offset == 16;679 return rel_offset == 16;
680}680}
...@@ -703,7 +703,7 @@ fn getPersonalityFunction(info: UnwindInfo, global_index: SymbolWithLoc) ?u2 {...@@ -703,7 +703,7 @@ fn getPersonalityFunction(info: UnwindInfo, global_index: SymbolWithLoc) ?u2 {
703}703}
704704
705fn isLsda(record_id: usize, rel: macho.relocation_info) bool {705fn isLsda(record_id: usize, rel: macho.relocation_info) bool {
706 const base_offset = @intCast(i32, record_id * @sizeOf(macho.compact_unwind_entry));706 const base_offset = @as(i32, @intCast(record_id * @sizeOf(macho.compact_unwind_entry)));
707 const rel_offset = rel.r_address - base_offset;707 const rel_offset = rel.r_address - base_offset;
708 return rel_offset == 24;708 return rel_offset == 24;
709}709}
...@@ -754,45 +754,45 @@ fn getCommonEncoding(info: UnwindInfo, enc: macho.compact_unwind_encoding_t) ?u7...@@ -754,45 +754,45 @@ fn getCommonEncoding(info: UnwindInfo, enc: macho.compact_unwind_encoding_t) ?u7
754pub const UnwindEncoding = struct {754pub const UnwindEncoding = struct {
755 pub fn getMode(enc: macho.compact_unwind_encoding_t) u4 {755 pub fn getMode(enc: macho.compact_unwind_encoding_t) u4 {
756 comptime assert(macho.UNWIND_ARM64_MODE_MASK == macho.UNWIND_X86_64_MODE_MASK);756 comptime assert(macho.UNWIND_ARM64_MODE_MASK == macho.UNWIND_X86_64_MODE_MASK);
757 return @truncate(u4, (enc & macho.UNWIND_ARM64_MODE_MASK) >> 24);757 return @as(u4, @truncate((enc & macho.UNWIND_ARM64_MODE_MASK) >> 24));
758 }758 }
759759
760 pub fn isDwarf(enc: macho.compact_unwind_encoding_t, cpu_arch: std.Target.Cpu.Arch) bool {760 pub fn isDwarf(enc: macho.compact_unwind_encoding_t, cpu_arch: std.Target.Cpu.Arch) bool {
761 const mode = getMode(enc);761 const mode = getMode(enc);
762 return switch (cpu_arch) {762 return switch (cpu_arch) {
763 .aarch64 => @enumFromInt(macho.UNWIND_ARM64_MODE, mode) == .DWARF,763 .aarch64 => @as(macho.UNWIND_ARM64_MODE, @enumFromInt(mode)) == .DWARF,
764 .x86_64 => @enumFromInt(macho.UNWIND_X86_64_MODE, mode) == .DWARF,764 .x86_64 => @as(macho.UNWIND_X86_64_MODE, @enumFromInt(mode)) == .DWARF,
765 else => unreachable,765 else => unreachable,
766 };766 };
767 }767 }
768768
769 pub fn setMode(enc: *macho.compact_unwind_encoding_t, mode: anytype) void {769 pub fn setMode(enc: *macho.compact_unwind_encoding_t, mode: anytype) void {
770 enc.* |= @intCast(u32, @intFromEnum(mode)) << 24;770 enc.* |= @as(u32, @intCast(@intFromEnum(mode))) << 24;
771 }771 }
772772
773 pub fn hasLsda(enc: macho.compact_unwind_encoding_t) bool {773 pub fn hasLsda(enc: macho.compact_unwind_encoding_t) bool {
774 const has_lsda = @truncate(u1, (enc & macho.UNWIND_HAS_LSDA) >> 31);774 const has_lsda = @as(u1, @truncate((enc & macho.UNWIND_HAS_LSDA) >> 31));
775 return has_lsda == 1;775 return has_lsda == 1;
776 }776 }
777777
778 pub fn setHasLsda(enc: *macho.compact_unwind_encoding_t, has_lsda: bool) void {778 pub fn setHasLsda(enc: *macho.compact_unwind_encoding_t, has_lsda: bool) void {
779 const mask = @intCast(u32, @intFromBool(has_lsda)) << 31;779 const mask = @as(u32, @intCast(@intFromBool(has_lsda))) << 31;
780 enc.* |= mask;780 enc.* |= mask;
781 }781 }
782782
783 pub fn getPersonalityIndex(enc: macho.compact_unwind_encoding_t) u2 {783 pub fn getPersonalityIndex(enc: macho.compact_unwind_encoding_t) u2 {
784 const index = @truncate(u2, (enc & macho.UNWIND_PERSONALITY_MASK) >> 28);784 const index = @as(u2, @truncate((enc & macho.UNWIND_PERSONALITY_MASK) >> 28));
785 return index;785 return index;
786 }786 }
787787
788 pub fn setPersonalityIndex(enc: *macho.compact_unwind_encoding_t, index: u2) void {788 pub fn setPersonalityIndex(enc: *macho.compact_unwind_encoding_t, index: u2) void {
789 const mask = @intCast(u32, index) << 28;789 const mask = @as(u32, @intCast(index)) << 28;
790 enc.* |= mask;790 enc.* |= mask;
791 }791 }
792792
793 pub fn getDwarfSectionOffset(enc: macho.compact_unwind_encoding_t, cpu_arch: std.Target.Cpu.Arch) u24 {793 pub fn getDwarfSectionOffset(enc: macho.compact_unwind_encoding_t, cpu_arch: std.Target.Cpu.Arch) u24 {
794 assert(isDwarf(enc, cpu_arch));794 assert(isDwarf(enc, cpu_arch));
795 const offset = @truncate(u24, enc);795 const offset = @as(u24, @truncate(enc));
796 return offset;796 return offset;
797 }797 }
798798
src/link/MachO/ZldAtom.zig+60-60
...@@ -117,8 +117,8 @@ pub fn getSectionAlias(zld: *Zld, atom_index: AtomIndex) ?SymbolWithLoc {...@@ -117,8 +117,8 @@ pub fn getSectionAlias(zld: *Zld, atom_index: AtomIndex) ?SymbolWithLoc {
117 assert(atom.getFile() != null);117 assert(atom.getFile() != null);
118118
119 const object = zld.objects.items[atom.getFile().?];119 const object = zld.objects.items[atom.getFile().?];
120 const nbase = @intCast(u32, object.in_symtab.?.len);120 const nbase = @as(u32, @intCast(object.in_symtab.?.len));
121 const ntotal = @intCast(u32, object.symtab.len);121 const ntotal = @as(u32, @intCast(object.symtab.len));
122 var sym_index: u32 = nbase;122 var sym_index: u32 = nbase;
123 while (sym_index < ntotal) : (sym_index += 1) {123 while (sym_index < ntotal) : (sym_index += 1) {
124 if (object.getAtomIndexForSymbol(sym_index)) |other_atom_index| {124 if (object.getAtomIndexForSymbol(sym_index)) |other_atom_index| {
...@@ -144,8 +144,8 @@ pub fn calcInnerSymbolOffset(zld: *Zld, atom_index: AtomIndex, sym_index: u32) u...@@ -144,8 +144,8 @@ pub fn calcInnerSymbolOffset(zld: *Zld, atom_index: AtomIndex, sym_index: u32) u
144 const base_addr = if (object.getSourceSymbol(atom.sym_index)) |sym|144 const base_addr = if (object.getSourceSymbol(atom.sym_index)) |sym|
145 sym.n_value145 sym.n_value
146 else blk: {146 else blk: {
147 const nbase = @intCast(u32, object.in_symtab.?.len);147 const nbase = @as(u32, @intCast(object.in_symtab.?.len));
148 const sect_id = @intCast(u8, atom.sym_index - nbase);148 const sect_id = @as(u8, @intCast(atom.sym_index - nbase));
149 const source_sect = object.getSourceSection(sect_id);149 const source_sect = object.getSourceSection(sect_id);
150 break :blk source_sect.addr;150 break :blk source_sect.addr;
151 };151 };
...@@ -177,15 +177,15 @@ pub fn getRelocContext(zld: *Zld, atom_index: AtomIndex) RelocContext {...@@ -177,15 +177,15 @@ pub fn getRelocContext(zld: *Zld, atom_index: AtomIndex) RelocContext {
177 if (object.getSourceSymbol(atom.sym_index)) |source_sym| {177 if (object.getSourceSymbol(atom.sym_index)) |source_sym| {
178 const source_sect = object.getSourceSection(source_sym.n_sect - 1);178 const source_sect = object.getSourceSection(source_sym.n_sect - 1);
179 return .{179 return .{
180 .base_addr = @intCast(i64, source_sect.addr),180 .base_addr = @as(i64, @intCast(source_sect.addr)),
181 .base_offset = @intCast(i32, source_sym.n_value - source_sect.addr),181 .base_offset = @as(i32, @intCast(source_sym.n_value - source_sect.addr)),
182 };182 };
183 }183 }
184 const nbase = @intCast(u32, object.in_symtab.?.len);184 const nbase = @as(u32, @intCast(object.in_symtab.?.len));
185 const sect_id = @intCast(u8, atom.sym_index - nbase);185 const sect_id = @as(u8, @intCast(atom.sym_index - nbase));
186 const source_sect = object.getSourceSection(sect_id);186 const source_sect = object.getSourceSection(sect_id);
187 return .{187 return .{
188 .base_addr = @intCast(i64, source_sect.addr),188 .base_addr = @as(i64, @intCast(source_sect.addr)),
189 .base_offset = 0,189 .base_offset = 0,
190 };190 };
191}191}
...@@ -204,8 +204,8 @@ pub fn parseRelocTarget(zld: *Zld, ctx: struct {...@@ -204,8 +204,8 @@ pub fn parseRelocTarget(zld: *Zld, ctx: struct {
204 log.debug("parsing reloc target in object({d}) '{s}' ", .{ ctx.object_id, object.name });204 log.debug("parsing reloc target in object({d}) '{s}' ", .{ ctx.object_id, object.name });
205205
206 const sym_index = if (ctx.rel.r_extern == 0) sym_index: {206 const sym_index = if (ctx.rel.r_extern == 0) sym_index: {
207 const sect_id = @intCast(u8, ctx.rel.r_symbolnum - 1);207 const sect_id = @as(u8, @intCast(ctx.rel.r_symbolnum - 1));
208 const rel_offset = @intCast(u32, ctx.rel.r_address - ctx.base_offset);208 const rel_offset = @as(u32, @intCast(ctx.rel.r_address - ctx.base_offset));
209209
210 const address_in_section = if (ctx.rel.r_pcrel == 0) blk: {210 const address_in_section = if (ctx.rel.r_pcrel == 0) blk: {
211 break :blk if (ctx.rel.r_length == 3)211 break :blk if (ctx.rel.r_length == 3)
...@@ -214,7 +214,7 @@ pub fn parseRelocTarget(zld: *Zld, ctx: struct {...@@ -214,7 +214,7 @@ pub fn parseRelocTarget(zld: *Zld, ctx: struct {
214 mem.readIntLittle(u32, ctx.code[rel_offset..][0..4]);214 mem.readIntLittle(u32, ctx.code[rel_offset..][0..4]);
215 } else blk: {215 } else blk: {
216 assert(zld.options.target.cpu.arch == .x86_64);216 assert(zld.options.target.cpu.arch == .x86_64);
217 const correction: u3 = switch (@enumFromInt(macho.reloc_type_x86_64, ctx.rel.r_type)) {217 const correction: u3 = switch (@as(macho.reloc_type_x86_64, @enumFromInt(ctx.rel.r_type))) {
218 .X86_64_RELOC_SIGNED => 0,218 .X86_64_RELOC_SIGNED => 0,
219 .X86_64_RELOC_SIGNED_1 => 1,219 .X86_64_RELOC_SIGNED_1 => 1,
220 .X86_64_RELOC_SIGNED_2 => 2,220 .X86_64_RELOC_SIGNED_2 => 2,
...@@ -222,8 +222,8 @@ pub fn parseRelocTarget(zld: *Zld, ctx: struct {...@@ -222,8 +222,8 @@ pub fn parseRelocTarget(zld: *Zld, ctx: struct {
222 else => unreachable,222 else => unreachable,
223 };223 };
224 const addend = mem.readIntLittle(i32, ctx.code[rel_offset..][0..4]);224 const addend = mem.readIntLittle(i32, ctx.code[rel_offset..][0..4]);
225 const target_address = @intCast(i64, ctx.base_addr) + ctx.rel.r_address + 4 + correction + addend;225 const target_address = @as(i64, @intCast(ctx.base_addr)) + ctx.rel.r_address + 4 + correction + addend;
226 break :blk @intCast(u64, target_address);226 break :blk @as(u64, @intCast(target_address));
227 };227 };
228228
229 // Find containing atom229 // Find containing atom
...@@ -272,7 +272,7 @@ pub fn getRelocTargetAtomIndex(zld: *Zld, target: SymbolWithLoc, is_via_got: boo...@@ -272,7 +272,7 @@ pub fn getRelocTargetAtomIndex(zld: *Zld, target: SymbolWithLoc, is_via_got: boo
272272
273fn scanAtomRelocsArm64(zld: *Zld, atom_index: AtomIndex, relocs: []align(1) const macho.relocation_info) !void {273fn scanAtomRelocsArm64(zld: *Zld, atom_index: AtomIndex, relocs: []align(1) const macho.relocation_info) !void {
274 for (relocs) |rel| {274 for (relocs) |rel| {
275 const rel_type = @enumFromInt(macho.reloc_type_arm64, rel.r_type);275 const rel_type = @as(macho.reloc_type_arm64, @enumFromInt(rel.r_type));
276276
277 switch (rel_type) {277 switch (rel_type) {
278 .ARM64_RELOC_ADDEND, .ARM64_RELOC_SUBTRACTOR => continue,278 .ARM64_RELOC_ADDEND, .ARM64_RELOC_SUBTRACTOR => continue,
...@@ -318,7 +318,7 @@ fn scanAtomRelocsArm64(zld: *Zld, atom_index: AtomIndex, relocs: []align(1) cons...@@ -318,7 +318,7 @@ fn scanAtomRelocsArm64(zld: *Zld, atom_index: AtomIndex, relocs: []align(1) cons
318318
319fn scanAtomRelocsX86(zld: *Zld, atom_index: AtomIndex, relocs: []align(1) const macho.relocation_info) !void {319fn scanAtomRelocsX86(zld: *Zld, atom_index: AtomIndex, relocs: []align(1) const macho.relocation_info) !void {
320 for (relocs) |rel| {320 for (relocs) |rel| {
321 const rel_type = @enumFromInt(macho.reloc_type_x86_64, rel.r_type);321 const rel_type = @as(macho.reloc_type_x86_64, @enumFromInt(rel.r_type));
322322
323 switch (rel_type) {323 switch (rel_type) {
324 .X86_64_RELOC_SUBTRACTOR => continue,324 .X86_64_RELOC_SUBTRACTOR => continue,
...@@ -364,7 +364,7 @@ fn addTlvPtrEntry(zld: *Zld, target: SymbolWithLoc) !void {...@@ -364,7 +364,7 @@ fn addTlvPtrEntry(zld: *Zld, target: SymbolWithLoc) !void {
364364
365 const gpa = zld.gpa;365 const gpa = zld.gpa;
366 const atom_index = try zld.createTlvPtrAtom();366 const atom_index = try zld.createTlvPtrAtom();
367 const tlv_ptr_index = @intCast(u32, zld.tlv_ptr_entries.items.len);367 const tlv_ptr_index = @as(u32, @intCast(zld.tlv_ptr_entries.items.len));
368 try zld.tlv_ptr_entries.append(gpa, .{368 try zld.tlv_ptr_entries.append(gpa, .{
369 .target = target,369 .target = target,
370 .atom_index = atom_index,370 .atom_index = atom_index,
...@@ -376,7 +376,7 @@ pub fn addGotEntry(zld: *Zld, target: SymbolWithLoc) !void {...@@ -376,7 +376,7 @@ pub fn addGotEntry(zld: *Zld, target: SymbolWithLoc) !void {
376 if (zld.got_table.contains(target)) return;376 if (zld.got_table.contains(target)) return;
377 const gpa = zld.gpa;377 const gpa = zld.gpa;
378 const atom_index = try zld.createGotAtom();378 const atom_index = try zld.createGotAtom();
379 const got_index = @intCast(u32, zld.got_entries.items.len);379 const got_index = @as(u32, @intCast(zld.got_entries.items.len));
380 try zld.got_entries.append(gpa, .{380 try zld.got_entries.append(gpa, .{
381 .target = target,381 .target = target,
382 .atom_index = atom_index,382 .atom_index = atom_index,
...@@ -393,7 +393,7 @@ pub fn addStub(zld: *Zld, target: SymbolWithLoc) !void {...@@ -393,7 +393,7 @@ pub fn addStub(zld: *Zld, target: SymbolWithLoc) !void {
393 _ = try zld.createStubHelperAtom();393 _ = try zld.createStubHelperAtom();
394 _ = try zld.createLazyPointerAtom();394 _ = try zld.createLazyPointerAtom();
395 const atom_index = try zld.createStubAtom();395 const atom_index = try zld.createStubAtom();
396 const stubs_index = @intCast(u32, zld.stubs.items.len);396 const stubs_index = @as(u32, @intCast(zld.stubs.items.len));
397 try zld.stubs.append(gpa, .{397 try zld.stubs.append(gpa, .{
398 .target = target,398 .target = target,
399 .atom_index = atom_index,399 .atom_index = atom_index,
...@@ -489,7 +489,7 @@ fn resolveRelocsArm64(...@@ -489,7 +489,7 @@ fn resolveRelocsArm64(
489 var subtractor: ?SymbolWithLoc = null;489 var subtractor: ?SymbolWithLoc = null;
490490
491 for (atom_relocs) |rel| {491 for (atom_relocs) |rel| {
492 const rel_type = @enumFromInt(macho.reloc_type_arm64, rel.r_type);492 const rel_type = @as(macho.reloc_type_arm64, @enumFromInt(rel.r_type));
493493
494 switch (rel_type) {494 switch (rel_type) {
495 .ARM64_RELOC_ADDEND => {495 .ARM64_RELOC_ADDEND => {
...@@ -529,7 +529,7 @@ fn resolveRelocsArm64(...@@ -529,7 +529,7 @@ fn resolveRelocsArm64(
529 .base_addr = context.base_addr,529 .base_addr = context.base_addr,
530 .base_offset = context.base_offset,530 .base_offset = context.base_offset,
531 });531 });
532 const rel_offset = @intCast(u32, rel.r_address - context.base_offset);532 const rel_offset = @as(u32, @intCast(rel.r_address - context.base_offset));
533533
534 log.debug(" RELA({s}) @ {x} => %{d} ('{s}') in object({?})", .{534 log.debug(" RELA({s}) @ {x} => %{d} ('{s}') in object({?})", .{
535 @tagName(rel_type),535 @tagName(rel_type),
...@@ -590,7 +590,7 @@ fn resolveRelocsArm64(...@@ -590,7 +590,7 @@ fn resolveRelocsArm64(
590 aarch64.Instruction.unconditional_branch_immediate,590 aarch64.Instruction.unconditional_branch_immediate,
591 ), code),591 ), code),
592 };592 };
593 inst.unconditional_branch_immediate.imm26 = @truncate(u26, @bitCast(u28, displacement >> 2));593 inst.unconditional_branch_immediate.imm26 = @as(u26, @truncate(@as(u28, @bitCast(displacement >> 2))));
594 mem.writeIntLittle(u32, code, inst.toU32());594 mem.writeIntLittle(u32, code, inst.toU32());
595 },595 },
596596
...@@ -598,11 +598,11 @@ fn resolveRelocsArm64(...@@ -598,11 +598,11 @@ fn resolveRelocsArm64(
598 .ARM64_RELOC_GOT_LOAD_PAGE21,598 .ARM64_RELOC_GOT_LOAD_PAGE21,
599 .ARM64_RELOC_TLVP_LOAD_PAGE21,599 .ARM64_RELOC_TLVP_LOAD_PAGE21,
600 => {600 => {
601 const adjusted_target_addr = @intCast(u64, @intCast(i64, target_addr) + (addend orelse 0));601 const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + (addend orelse 0)));
602602
603 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});603 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
604604
605 const pages = @bitCast(u21, Relocation.calcNumberOfPages(source_addr, adjusted_target_addr));605 const pages = @as(u21, @bitCast(Relocation.calcNumberOfPages(source_addr, adjusted_target_addr)));
606 const code = atom_code[rel_offset..][0..4];606 const code = atom_code[rel_offset..][0..4];
607 var inst = aarch64.Instruction{607 var inst = aarch64.Instruction{
608 .pc_relative_address = mem.bytesToValue(meta.TagPayload(608 .pc_relative_address = mem.bytesToValue(meta.TagPayload(
...@@ -610,14 +610,14 @@ fn resolveRelocsArm64(...@@ -610,14 +610,14 @@ fn resolveRelocsArm64(
610 aarch64.Instruction.pc_relative_address,610 aarch64.Instruction.pc_relative_address,
611 ), code),611 ), code),
612 };612 };
613 inst.pc_relative_address.immhi = @truncate(u19, pages >> 2);613 inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2));
614 inst.pc_relative_address.immlo = @truncate(u2, pages);614 inst.pc_relative_address.immlo = @as(u2, @truncate(pages));
615 mem.writeIntLittle(u32, code, inst.toU32());615 mem.writeIntLittle(u32, code, inst.toU32());
616 addend = null;616 addend = null;
617 },617 },
618618
619 .ARM64_RELOC_PAGEOFF12 => {619 .ARM64_RELOC_PAGEOFF12 => {
620 const adjusted_target_addr = @intCast(u64, @intCast(i64, target_addr) + (addend orelse 0));620 const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + (addend orelse 0)));
621621
622 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});622 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
623623
...@@ -656,7 +656,7 @@ fn resolveRelocsArm64(...@@ -656,7 +656,7 @@ fn resolveRelocsArm64(
656656
657 .ARM64_RELOC_GOT_LOAD_PAGEOFF12 => {657 .ARM64_RELOC_GOT_LOAD_PAGEOFF12 => {
658 const code = atom_code[rel_offset..][0..4];658 const code = atom_code[rel_offset..][0..4];
659 const adjusted_target_addr = @intCast(u64, @intCast(i64, target_addr) + (addend orelse 0));659 const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + (addend orelse 0)));
660660
661 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});661 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
662662
...@@ -674,7 +674,7 @@ fn resolveRelocsArm64(...@@ -674,7 +674,7 @@ fn resolveRelocsArm64(
674674
675 .ARM64_RELOC_TLVP_LOAD_PAGEOFF12 => {675 .ARM64_RELOC_TLVP_LOAD_PAGEOFF12 => {
676 const code = atom_code[rel_offset..][0..4];676 const code = atom_code[rel_offset..][0..4];
677 const adjusted_target_addr = @intCast(u64, @intCast(i64, target_addr) + (addend orelse 0));677 const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + (addend orelse 0)));
678678
679 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});679 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
680680
...@@ -725,7 +725,7 @@ fn resolveRelocsArm64(...@@ -725,7 +725,7 @@ fn resolveRelocsArm64(
725 .sh = 0,725 .sh = 0,
726 .s = 0,726 .s = 0,
727 .op = 0,727 .op = 0,
728 .sf = @truncate(u1, reg_info.size),728 .sf = @as(u1, @truncate(reg_info.size)),
729 },729 },
730 };730 };
731 mem.writeIntLittle(u32, code, inst.toU32());731 mem.writeIntLittle(u32, code, inst.toU32());
...@@ -734,9 +734,9 @@ fn resolveRelocsArm64(...@@ -734,9 +734,9 @@ fn resolveRelocsArm64(
734734
735 .ARM64_RELOC_POINTER_TO_GOT => {735 .ARM64_RELOC_POINTER_TO_GOT => {
736 log.debug(" | target_addr = 0x{x}", .{target_addr});736 log.debug(" | target_addr = 0x{x}", .{target_addr});
737 const result = math.cast(i32, @intCast(i64, target_addr) - @intCast(i64, source_addr)) orelse737 const result = math.cast(i32, @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr))) orelse
738 return error.Overflow;738 return error.Overflow;
739 mem.writeIntLittle(u32, atom_code[rel_offset..][0..4], @bitCast(u32, result));739 mem.writeIntLittle(u32, atom_code[rel_offset..][0..4], @as(u32, @bitCast(result)));
740 },740 },
741741
742 .ARM64_RELOC_UNSIGNED => {742 .ARM64_RELOC_UNSIGNED => {
...@@ -747,7 +747,7 @@ fn resolveRelocsArm64(...@@ -747,7 +747,7 @@ fn resolveRelocsArm64(
747747
748 if (rel.r_extern == 0) {748 if (rel.r_extern == 0) {
749 const base_addr = if (target.sym_index >= object.source_address_lookup.len)749 const base_addr = if (target.sym_index >= object.source_address_lookup.len)
750 @intCast(i64, object.getSourceSection(@intCast(u8, rel.r_symbolnum - 1)).addr)750 @as(i64, @intCast(object.getSourceSection(@as(u8, @intCast(rel.r_symbolnum - 1))).addr))
751 else751 else
752 object.source_address_lookup[target.sym_index];752 object.source_address_lookup[target.sym_index];
753 ptr_addend -= base_addr;753 ptr_addend -= base_addr;
...@@ -756,17 +756,17 @@ fn resolveRelocsArm64(...@@ -756,17 +756,17 @@ fn resolveRelocsArm64(
756 const result = blk: {756 const result = blk: {
757 if (subtractor) |sub| {757 if (subtractor) |sub| {
758 const sym = zld.getSymbol(sub);758 const sym = zld.getSymbol(sub);
759 break :blk @intCast(i64, target_addr) - @intCast(i64, sym.n_value) + ptr_addend;759 break :blk @as(i64, @intCast(target_addr)) - @as(i64, @intCast(sym.n_value)) + ptr_addend;
760 } else {760 } else {
761 break :blk @intCast(i64, target_addr) + ptr_addend;761 break :blk @as(i64, @intCast(target_addr)) + ptr_addend;
762 }762 }
763 };763 };
764 log.debug(" | target_addr = 0x{x}", .{result});764 log.debug(" | target_addr = 0x{x}", .{result});
765765
766 if (rel.r_length == 3) {766 if (rel.r_length == 3) {
767 mem.writeIntLittle(u64, atom_code[rel_offset..][0..8], @bitCast(u64, result));767 mem.writeIntLittle(u64, atom_code[rel_offset..][0..8], @as(u64, @bitCast(result)));
768 } else {768 } else {
769 mem.writeIntLittle(u32, atom_code[rel_offset..][0..4], @truncate(u32, @bitCast(u64, result)));769 mem.writeIntLittle(u32, atom_code[rel_offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(result)))));
770 }770 }
771771
772 subtractor = null;772 subtractor = null;
...@@ -791,7 +791,7 @@ fn resolveRelocsX86(...@@ -791,7 +791,7 @@ fn resolveRelocsX86(
791 var subtractor: ?SymbolWithLoc = null;791 var subtractor: ?SymbolWithLoc = null;
792792
793 for (atom_relocs) |rel| {793 for (atom_relocs) |rel| {
794 const rel_type = @enumFromInt(macho.reloc_type_x86_64, rel.r_type);794 const rel_type = @as(macho.reloc_type_x86_64, @enumFromInt(rel.r_type));
795795
796 switch (rel_type) {796 switch (rel_type) {
797 .X86_64_RELOC_SUBTRACTOR => {797 .X86_64_RELOC_SUBTRACTOR => {
...@@ -823,7 +823,7 @@ fn resolveRelocsX86(...@@ -823,7 +823,7 @@ fn resolveRelocsX86(
823 .base_addr = context.base_addr,823 .base_addr = context.base_addr,
824 .base_offset = context.base_offset,824 .base_offset = context.base_offset,
825 });825 });
826 const rel_offset = @intCast(u32, rel.r_address - context.base_offset);826 const rel_offset = @as(u32, @intCast(rel.r_address - context.base_offset));
827827
828 log.debug(" RELA({s}) @ {x} => %{d} ('{s}') in object({?})", .{828 log.debug(" RELA({s}) @ {x} => %{d} ('{s}') in object({?})", .{
829 @tagName(rel_type),829 @tagName(rel_type),
...@@ -851,7 +851,7 @@ fn resolveRelocsX86(...@@ -851,7 +851,7 @@ fn resolveRelocsX86(
851 switch (rel_type) {851 switch (rel_type) {
852 .X86_64_RELOC_BRANCH => {852 .X86_64_RELOC_BRANCH => {
853 const addend = mem.readIntLittle(i32, atom_code[rel_offset..][0..4]);853 const addend = mem.readIntLittle(i32, atom_code[rel_offset..][0..4]);
854 const adjusted_target_addr = @intCast(u64, @intCast(i64, target_addr) + addend);854 const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend));
855 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});855 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
856 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);856 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);
857 mem.writeIntLittle(i32, atom_code[rel_offset..][0..4], disp);857 mem.writeIntLittle(i32, atom_code[rel_offset..][0..4], disp);
...@@ -861,7 +861,7 @@ fn resolveRelocsX86(...@@ -861,7 +861,7 @@ fn resolveRelocsX86(
861 .X86_64_RELOC_GOT_LOAD,861 .X86_64_RELOC_GOT_LOAD,
862 => {862 => {
863 const addend = mem.readIntLittle(i32, atom_code[rel_offset..][0..4]);863 const addend = mem.readIntLittle(i32, atom_code[rel_offset..][0..4]);
864 const adjusted_target_addr = @intCast(u64, @intCast(i64, target_addr) + addend);864 const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend));
865 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});865 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
866 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);866 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);
867 mem.writeIntLittle(i32, atom_code[rel_offset..][0..4], disp);867 mem.writeIntLittle(i32, atom_code[rel_offset..][0..4], disp);
...@@ -869,7 +869,7 @@ fn resolveRelocsX86(...@@ -869,7 +869,7 @@ fn resolveRelocsX86(
869869
870 .X86_64_RELOC_TLV => {870 .X86_64_RELOC_TLV => {
871 const addend = mem.readIntLittle(i32, atom_code[rel_offset..][0..4]);871 const addend = mem.readIntLittle(i32, atom_code[rel_offset..][0..4]);
872 const adjusted_target_addr = @intCast(u64, @intCast(i64, target_addr) + addend);872 const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend));
873 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});873 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
874 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);874 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);
875875
...@@ -897,14 +897,14 @@ fn resolveRelocsX86(...@@ -897,14 +897,14 @@ fn resolveRelocsX86(
897897
898 if (rel.r_extern == 0) {898 if (rel.r_extern == 0) {
899 const base_addr = if (target.sym_index >= object.source_address_lookup.len)899 const base_addr = if (target.sym_index >= object.source_address_lookup.len)
900 @intCast(i64, object.getSourceSection(@intCast(u8, rel.r_symbolnum - 1)).addr)900 @as(i64, @intCast(object.getSourceSection(@as(u8, @intCast(rel.r_symbolnum - 1))).addr))
901 else901 else
902 object.source_address_lookup[target.sym_index];902 object.source_address_lookup[target.sym_index];
903 addend += @intCast(i32, @intCast(i64, context.base_addr) + rel.r_address + 4 -903 addend += @as(i32, @intCast(@as(i64, @intCast(context.base_addr)) + rel.r_address + 4 -
904 @intCast(i64, base_addr));904 @as(i64, @intCast(base_addr))));
905 }905 }
906906
907 const adjusted_target_addr = @intCast(u64, @intCast(i64, target_addr) + addend);907 const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend));
908908
909 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});909 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
910910
...@@ -920,7 +920,7 @@ fn resolveRelocsX86(...@@ -920,7 +920,7 @@ fn resolveRelocsX86(
920920
921 if (rel.r_extern == 0) {921 if (rel.r_extern == 0) {
922 const base_addr = if (target.sym_index >= object.source_address_lookup.len)922 const base_addr = if (target.sym_index >= object.source_address_lookup.len)
923 @intCast(i64, object.getSourceSection(@intCast(u8, rel.r_symbolnum - 1)).addr)923 @as(i64, @intCast(object.getSourceSection(@as(u8, @intCast(rel.r_symbolnum - 1))).addr))
924 else924 else
925 object.source_address_lookup[target.sym_index];925 object.source_address_lookup[target.sym_index];
926 addend -= base_addr;926 addend -= base_addr;
...@@ -929,17 +929,17 @@ fn resolveRelocsX86(...@@ -929,17 +929,17 @@ fn resolveRelocsX86(
929 const result = blk: {929 const result = blk: {
930 if (subtractor) |sub| {930 if (subtractor) |sub| {
931 const sym = zld.getSymbol(sub);931 const sym = zld.getSymbol(sub);
932 break :blk @intCast(i64, target_addr) - @intCast(i64, sym.n_value) + addend;932 break :blk @as(i64, @intCast(target_addr)) - @as(i64, @intCast(sym.n_value)) + addend;
933 } else {933 } else {
934 break :blk @intCast(i64, target_addr) + addend;934 break :blk @as(i64, @intCast(target_addr)) + addend;
935 }935 }
936 };936 };
937 log.debug(" | target_addr = 0x{x}", .{result});937 log.debug(" | target_addr = 0x{x}", .{result});
938938
939 if (rel.r_length == 3) {939 if (rel.r_length == 3) {
940 mem.writeIntLittle(u64, atom_code[rel_offset..][0..8], @bitCast(u64, result));940 mem.writeIntLittle(u64, atom_code[rel_offset..][0..8], @as(u64, @bitCast(result)));
941 } else {941 } else {
942 mem.writeIntLittle(u32, atom_code[rel_offset..][0..4], @truncate(u32, @bitCast(u64, result)));942 mem.writeIntLittle(u32, atom_code[rel_offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(result)))));
943 }943 }
944944
945 subtractor = null;945 subtractor = null;
...@@ -958,19 +958,19 @@ pub fn getAtomCode(zld: *Zld, atom_index: AtomIndex) []const u8 {...@@ -958,19 +958,19 @@ pub fn getAtomCode(zld: *Zld, atom_index: AtomIndex) []const u8 {
958 // If there was no matching symbol present in the source symtab, this means958 // If there was no matching symbol present in the source symtab, this means
959 // we are dealing with either an entire section, or part of it, but also959 // we are dealing with either an entire section, or part of it, but also
960 // starting at the beginning.960 // starting at the beginning.
961 const nbase = @intCast(u32, object.in_symtab.?.len);961 const nbase = @as(u32, @intCast(object.in_symtab.?.len));
962 const sect_id = @intCast(u8, atom.sym_index - nbase);962 const sect_id = @as(u8, @intCast(atom.sym_index - nbase));
963 const source_sect = object.getSourceSection(sect_id);963 const source_sect = object.getSourceSection(sect_id);
964 assert(!source_sect.isZerofill());964 assert(!source_sect.isZerofill());
965 const code = object.getSectionContents(source_sect);965 const code = object.getSectionContents(source_sect);
966 const code_len = @intCast(usize, atom.size);966 const code_len = @as(usize, @intCast(atom.size));
967 return code[0..code_len];967 return code[0..code_len];
968 };968 };
969 const source_sect = object.getSourceSection(source_sym.n_sect - 1);969 const source_sect = object.getSourceSection(source_sym.n_sect - 1);
970 assert(!source_sect.isZerofill());970 assert(!source_sect.isZerofill());
971 const code = object.getSectionContents(source_sect);971 const code = object.getSectionContents(source_sect);
972 const offset = @intCast(usize, source_sym.n_value - source_sect.addr);972 const offset = @as(usize, @intCast(source_sym.n_value - source_sect.addr));
973 const code_len = @intCast(usize, atom.size);973 const code_len = @as(usize, @intCast(atom.size));
974 return code[offset..][0..code_len];974 return code[offset..][0..code_len];
975}975}
976976
...@@ -986,8 +986,8 @@ pub fn getAtomRelocs(zld: *Zld, atom_index: AtomIndex) []const macho.relocation_...@@ -986,8 +986,8 @@ pub fn getAtomRelocs(zld: *Zld, atom_index: AtomIndex) []const macho.relocation_
986 // If there was no matching symbol present in the source symtab, this means986 // If there was no matching symbol present in the source symtab, this means
987 // we are dealing with either an entire section, or part of it, but also987 // we are dealing with either an entire section, or part of it, but also
988 // starting at the beginning.988 // starting at the beginning.
989 const nbase = @intCast(u32, object.in_symtab.?.len);989 const nbase = @as(u32, @intCast(object.in_symtab.?.len));
990 const sect_id = @intCast(u8, atom.sym_index - nbase);990 const sect_id = @as(u8, @intCast(atom.sym_index - nbase));
991 break :blk sect_id;991 break :blk sect_id;
992 };992 };
993 const source_sect = object.getSourceSection(source_sect_id);993 const source_sect = object.getSourceSection(source_sect_id);
...@@ -998,14 +998,14 @@ pub fn getAtomRelocs(zld: *Zld, atom_index: AtomIndex) []const macho.relocation_...@@ -998,14 +998,14 @@ pub fn getAtomRelocs(zld: *Zld, atom_index: AtomIndex) []const macho.relocation_
998998
999pub fn relocRequiresGot(zld: *Zld, rel: macho.relocation_info) bool {999pub fn relocRequiresGot(zld: *Zld, rel: macho.relocation_info) bool {
1000 switch (zld.options.target.cpu.arch) {1000 switch (zld.options.target.cpu.arch) {
1001 .aarch64 => switch (@enumFromInt(macho.reloc_type_arm64, rel.r_type)) {1001 .aarch64 => switch (@as(macho.reloc_type_arm64, @enumFromInt(rel.r_type))) {
1002 .ARM64_RELOC_GOT_LOAD_PAGE21,1002 .ARM64_RELOC_GOT_LOAD_PAGE21,
1003 .ARM64_RELOC_GOT_LOAD_PAGEOFF12,1003 .ARM64_RELOC_GOT_LOAD_PAGEOFF12,
1004 .ARM64_RELOC_POINTER_TO_GOT,1004 .ARM64_RELOC_POINTER_TO_GOT,
1005 => return true,1005 => return true,
1006 else => return false,1006 else => return false,
1007 },1007 },
1008 .x86_64 => switch (@enumFromInt(macho.reloc_type_x86_64, rel.r_type)) {1008 .x86_64 => switch (@as(macho.reloc_type_x86_64, @enumFromInt(rel.r_type))) {
1009 .X86_64_RELOC_GOT,1009 .X86_64_RELOC_GOT,
1010 .X86_64_RELOC_GOT_LOAD,1010 .X86_64_RELOC_GOT_LOAD,
1011 => return true,1011 => return true,
src/link/MachO/dead_strip.zig+12-12
...@@ -27,10 +27,10 @@ pub fn gcAtoms(zld: *Zld, resolver: *const SymbolResolver) !void {...@@ -27,10 +27,10 @@ pub fn gcAtoms(zld: *Zld, resolver: *const SymbolResolver) !void {
27 defer arena.deinit();27 defer arena.deinit();
2828
29 var roots = AtomTable.init(arena.allocator());29 var roots = AtomTable.init(arena.allocator());
30 try roots.ensureUnusedCapacity(@intCast(u32, zld.globals.items.len));30 try roots.ensureUnusedCapacity(@as(u32, @intCast(zld.globals.items.len)));
3131
32 var alive = AtomTable.init(arena.allocator());32 var alive = AtomTable.init(arena.allocator());
33 try alive.ensureTotalCapacity(@intCast(u32, zld.atoms.items.len));33 try alive.ensureTotalCapacity(@as(u32, @intCast(zld.atoms.items.len)));
3434
35 try collectRoots(zld, &roots, resolver);35 try collectRoots(zld, &roots, resolver);
36 try mark(zld, roots, &alive);36 try mark(zld, roots, &alive);
...@@ -99,8 +99,8 @@ fn collectRoots(zld: *Zld, roots: *AtomTable, resolver: *const SymbolResolver) !...@@ -99,8 +99,8 @@ fn collectRoots(zld: *Zld, roots: *AtomTable, resolver: *const SymbolResolver) !
99 const sect_id = if (object.getSourceSymbol(atom.sym_index)) |source_sym|99 const sect_id = if (object.getSourceSymbol(atom.sym_index)) |source_sym|
100 source_sym.n_sect - 1100 source_sym.n_sect - 1
101 else sect_id: {101 else sect_id: {
102 const nbase = @intCast(u32, object.in_symtab.?.len);102 const nbase = @as(u32, @intCast(object.in_symtab.?.len));
103 const sect_id = @intCast(u8, atom.sym_index - nbase);103 const sect_id = @as(u8, @intCast(atom.sym_index - nbase));
104 break :sect_id sect_id;104 break :sect_id sect_id;
105 };105 };
106 const source_sect = object.getSourceSection(sect_id);106 const source_sect = object.getSourceSection(sect_id);
...@@ -148,7 +148,7 @@ fn markLive(zld: *Zld, atom_index: AtomIndex, alive: *AtomTable) void {...@@ -148,7 +148,7 @@ fn markLive(zld: *Zld, atom_index: AtomIndex, alive: *AtomTable) void {
148148
149 for (relocs) |rel| {149 for (relocs) |rel| {
150 const target = switch (cpu_arch) {150 const target = switch (cpu_arch) {
151 .aarch64 => switch (@enumFromInt(macho.reloc_type_arm64, rel.r_type)) {151 .aarch64 => switch (@as(macho.reloc_type_arm64, @enumFromInt(rel.r_type))) {
152 .ARM64_RELOC_ADDEND => continue,152 .ARM64_RELOC_ADDEND => continue,
153 else => Atom.parseRelocTarget(zld, .{153 else => Atom.parseRelocTarget(zld, .{
154 .object_id = atom.getFile().?,154 .object_id = atom.getFile().?,
...@@ -208,7 +208,7 @@ fn refersLive(zld: *Zld, atom_index: AtomIndex, alive: AtomTable) bool {...@@ -208,7 +208,7 @@ fn refersLive(zld: *Zld, atom_index: AtomIndex, alive: AtomTable) bool {
208208
209 for (relocs) |rel| {209 for (relocs) |rel| {
210 const target = switch (cpu_arch) {210 const target = switch (cpu_arch) {
211 .aarch64 => switch (@enumFromInt(macho.reloc_type_arm64, rel.r_type)) {211 .aarch64 => switch (@as(macho.reloc_type_arm64, @enumFromInt(rel.r_type))) {
212 .ARM64_RELOC_ADDEND => continue,212 .ARM64_RELOC_ADDEND => continue,
213 else => Atom.parseRelocTarget(zld, .{213 else => Atom.parseRelocTarget(zld, .{
214 .object_id = atom.getFile().?,214 .object_id = atom.getFile().?,
...@@ -264,8 +264,8 @@ fn mark(zld: *Zld, roots: AtomTable, alive: *AtomTable) !void {...@@ -264,8 +264,8 @@ fn mark(zld: *Zld, roots: AtomTable, alive: *AtomTable) !void {
264 const sect_id = if (object.getSourceSymbol(atom.sym_index)) |source_sym|264 const sect_id = if (object.getSourceSymbol(atom.sym_index)) |source_sym|
265 source_sym.n_sect - 1265 source_sym.n_sect - 1
266 else blk: {266 else blk: {
267 const nbase = @intCast(u32, object.in_symtab.?.len);267 const nbase = @as(u32, @intCast(object.in_symtab.?.len));
268 const sect_id = @intCast(u8, atom.sym_index - nbase);268 const sect_id = @as(u8, @intCast(atom.sym_index - nbase));
269 break :blk sect_id;269 break :blk sect_id;
270 };270 };
271 const source_sect = object.getSourceSection(sect_id);271 const source_sect = object.getSourceSection(sect_id);
...@@ -283,7 +283,7 @@ fn mark(zld: *Zld, roots: AtomTable, alive: *AtomTable) !void {...@@ -283,7 +283,7 @@ fn mark(zld: *Zld, roots: AtomTable, alive: *AtomTable) !void {
283 for (zld.objects.items, 0..) |_, object_id| {283 for (zld.objects.items, 0..) |_, object_id| {
284 // Traverse unwind and eh_frame records noting if the source symbol has been marked, and if so,284 // Traverse unwind and eh_frame records noting if the source symbol has been marked, and if so,
285 // marking all references as live.285 // marking all references as live.
286 try markUnwindRecords(zld, @intCast(u32, object_id), alive);286 try markUnwindRecords(zld, @as(u32, @intCast(object_id)), alive);
287 }287 }
288}288}
289289
...@@ -329,7 +329,7 @@ fn markUnwindRecords(zld: *Zld, object_id: u32, alive: *AtomTable) !void {...@@ -329,7 +329,7 @@ fn markUnwindRecords(zld: *Zld, object_id: u32, alive: *AtomTable) !void {
329 .object_id = object_id,329 .object_id = object_id,
330 .rel = rel,330 .rel = rel,
331 .code = mem.asBytes(&record),331 .code = mem.asBytes(&record),
332 .base_offset = @intCast(i32, record_id * @sizeOf(macho.compact_unwind_entry)),332 .base_offset = @as(i32, @intCast(record_id * @sizeOf(macho.compact_unwind_entry))),
333 });333 });
334 const target_sym = zld.getSymbol(target);334 const target_sym = zld.getSymbol(target);
335 if (!target_sym.undf()) {335 if (!target_sym.undf()) {
...@@ -344,7 +344,7 @@ fn markUnwindRecords(zld: *Zld, object_id: u32, alive: *AtomTable) !void {...@@ -344,7 +344,7 @@ fn markUnwindRecords(zld: *Zld, object_id: u32, alive: *AtomTable) !void {
344 .object_id = object_id,344 .object_id = object_id,
345 .rel = rel,345 .rel = rel,
346 .code = mem.asBytes(&record),346 .code = mem.asBytes(&record),
347 .base_offset = @intCast(i32, record_id * @sizeOf(macho.compact_unwind_entry)),347 .base_offset = @as(i32, @intCast(record_id * @sizeOf(macho.compact_unwind_entry))),
348 });348 });
349 const target_object = zld.objects.items[target.getFile().?];349 const target_object = zld.objects.items[target.getFile().?];
350 const target_atom_index = target_object.getAtomIndexForSymbol(target.sym_index).?;350 const target_atom_index = target_object.getAtomIndexForSymbol(target.sym_index).?;
...@@ -377,7 +377,7 @@ fn markEhFrameRecord(zld: *Zld, object_id: u32, atom_index: AtomIndex, alive: *A...@@ -377,7 +377,7 @@ fn markEhFrameRecord(zld: *Zld, object_id: u32, atom_index: AtomIndex, alive: *A
377 .object_id = object_id,377 .object_id = object_id,
378 .rel = rel,378 .rel = rel,
379 .code = fde.data,379 .code = fde.data,
380 .base_offset = @intCast(i32, fde_offset) + 4,380 .base_offset = @as(i32, @intCast(fde_offset)) + 4,
381 });381 });
382 const target_sym = zld.getSymbol(target);382 const target_sym = zld.getSymbol(target);
383 if (!target_sym.undf()) blk: {383 if (!target_sym.undf()) blk: {
src/link/MachO/dyld_info/Rebase.zig+5-5
...@@ -31,7 +31,7 @@ pub fn deinit(rebase: *Rebase, gpa: Allocator) void {...@@ -31,7 +31,7 @@ pub fn deinit(rebase: *Rebase, gpa: Allocator) void {
31}31}
3232
33pub fn size(rebase: Rebase) u64 {33pub fn size(rebase: Rebase) u64 {
34 return @intCast(u64, rebase.buffer.items.len);34 return @as(u64, @intCast(rebase.buffer.items.len));
35}35}
3636
37pub fn finalize(rebase: *Rebase, gpa: Allocator) !void {37pub fn finalize(rebase: *Rebase, gpa: Allocator) !void {
...@@ -145,12 +145,12 @@ fn finalizeSegment(entries: []const Entry, writer: anytype) !void {...@@ -145,12 +145,12 @@ fn finalizeSegment(entries: []const Entry, writer: anytype) !void {
145145
146fn setTypePointer(writer: anytype) !void {146fn setTypePointer(writer: anytype) !void {
147 log.debug(">>> set type: {d}", .{macho.REBASE_TYPE_POINTER});147 log.debug(">>> set type: {d}", .{macho.REBASE_TYPE_POINTER});
148 try writer.writeByte(macho.REBASE_OPCODE_SET_TYPE_IMM | @truncate(u4, macho.REBASE_TYPE_POINTER));148 try writer.writeByte(macho.REBASE_OPCODE_SET_TYPE_IMM | @as(u4, @truncate(macho.REBASE_TYPE_POINTER)));
149}149}
150150
151fn setSegmentOffset(segment_id: u8, offset: u64, writer: anytype) !void {151fn setSegmentOffset(segment_id: u8, offset: u64, writer: anytype) !void {
152 log.debug(">>> set segment: {d} and offset: {x}", .{ segment_id, offset });152 log.debug(">>> set segment: {d} and offset: {x}", .{ segment_id, offset });
153 try writer.writeByte(macho.REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB | @truncate(u4, segment_id));153 try writer.writeByte(macho.REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB | @as(u4, @truncate(segment_id)));
154 try std.leb.writeULEB128(writer, offset);154 try std.leb.writeULEB128(writer, offset);
155}155}
156156
...@@ -163,7 +163,7 @@ fn rebaseAddAddr(addr: u64, writer: anytype) !void {...@@ -163,7 +163,7 @@ fn rebaseAddAddr(addr: u64, writer: anytype) !void {
163fn rebaseTimes(count: usize, writer: anytype) !void {163fn rebaseTimes(count: usize, writer: anytype) !void {
164 log.debug(">>> rebase with count: {d}", .{count});164 log.debug(">>> rebase with count: {d}", .{count});
165 if (count <= 0xf) {165 if (count <= 0xf) {
166 try writer.writeByte(macho.REBASE_OPCODE_DO_REBASE_IMM_TIMES | @truncate(u4, count));166 try writer.writeByte(macho.REBASE_OPCODE_DO_REBASE_IMM_TIMES | @as(u4, @truncate(count)));
167 } else {167 } else {
168 try writer.writeByte(macho.REBASE_OPCODE_DO_REBASE_ULEB_TIMES);168 try writer.writeByte(macho.REBASE_OPCODE_DO_REBASE_ULEB_TIMES);
169 try std.leb.writeULEB128(writer, count);169 try std.leb.writeULEB128(writer, count);
...@@ -182,7 +182,7 @@ fn addAddr(addr: u64, writer: anytype) !void {...@@ -182,7 +182,7 @@ fn addAddr(addr: u64, writer: anytype) !void {
182 if (std.mem.isAlignedGeneric(u64, addr, @sizeOf(u64))) {182 if (std.mem.isAlignedGeneric(u64, addr, @sizeOf(u64))) {
183 const imm = @divExact(addr, @sizeOf(u64));183 const imm = @divExact(addr, @sizeOf(u64));
184 if (imm <= 0xf) {184 if (imm <= 0xf) {
185 try writer.writeByte(macho.REBASE_OPCODE_ADD_ADDR_IMM_SCALED | @truncate(u4, imm));185 try writer.writeByte(macho.REBASE_OPCODE_ADD_ADDR_IMM_SCALED | @as(u4, @truncate(imm)));
186 return;186 return;
187 }187 }
188 }188 }
src/link/MachO/dyld_info/bind.zig+18-18
...@@ -39,7 +39,7 @@ pub fn Bind(comptime Ctx: type, comptime Target: type) type {...@@ -39,7 +39,7 @@ pub fn Bind(comptime Ctx: type, comptime Target: type) type {
39 }39 }
4040
41 pub fn size(self: Self) u64 {41 pub fn size(self: Self) u64 {
42 return @intCast(u64, self.buffer.items.len);42 return @as(u64, @intCast(self.buffer.items.len));
43 }43 }
4444
45 pub fn finalize(self: *Self, gpa: Allocator, ctx: Ctx) !void {45 pub fn finalize(self: *Self, gpa: Allocator, ctx: Ctx) !void {
...@@ -95,7 +95,7 @@ pub fn Bind(comptime Ctx: type, comptime Target: type) type {...@@ -95,7 +95,7 @@ pub fn Bind(comptime Ctx: type, comptime Target: type) type {
95 const sym = ctx.getSymbol(current.target);95 const sym = ctx.getSymbol(current.target);
96 const name = ctx.getSymbolName(current.target);96 const name = ctx.getSymbolName(current.target);
97 const flags: u8 = if (sym.weakRef()) macho.BIND_SYMBOL_FLAGS_WEAK_IMPORT else 0;97 const flags: u8 = if (sym.weakRef()) macho.BIND_SYMBOL_FLAGS_WEAK_IMPORT else 0;
98 const ordinal = @divTrunc(@bitCast(i16, sym.n_desc), macho.N_SYMBOL_RESOLVER);98 const ordinal = @divTrunc(@as(i16, @bitCast(sym.n_desc)), macho.N_SYMBOL_RESOLVER);
9999
100 try setSymbol(name, flags, writer);100 try setSymbol(name, flags, writer);
101 try setTypePointer(writer);101 try setTypePointer(writer);
...@@ -112,7 +112,7 @@ pub fn Bind(comptime Ctx: type, comptime Target: type) type {...@@ -112,7 +112,7 @@ pub fn Bind(comptime Ctx: type, comptime Target: type) type {
112 switch (state) {112 switch (state) {
113 .start => {113 .start => {
114 if (current.offset < offset) {114 if (current.offset < offset) {
115 try addAddr(@bitCast(u64, @intCast(i64, current.offset) - @intCast(i64, offset)), writer);115 try addAddr(@as(u64, @bitCast(@as(i64, @intCast(current.offset)) - @as(i64, @intCast(offset)))), writer);
116 offset = offset - (offset - current.offset);116 offset = offset - (offset - current.offset);
117 } else if (current.offset > offset) {117 } else if (current.offset > offset) {
118 const delta = current.offset - offset;118 const delta = current.offset - offset;
...@@ -130,7 +130,7 @@ pub fn Bind(comptime Ctx: type, comptime Target: type) type {...@@ -130,7 +130,7 @@ pub fn Bind(comptime Ctx: type, comptime Target: type) type {
130 } else if (current.offset > offset) {130 } else if (current.offset > offset) {
131 const delta = current.offset - offset;131 const delta = current.offset - offset;
132 state = .bind_times_skip;132 state = .bind_times_skip;
133 skip = @intCast(u64, delta);133 skip = @as(u64, @intCast(delta));
134 offset += skip;134 offset += skip;
135 } else unreachable;135 } else unreachable;
136 i -= 1;136 i -= 1;
...@@ -194,7 +194,7 @@ pub fn LazyBind(comptime Ctx: type, comptime Target: type) type {...@@ -194,7 +194,7 @@ pub fn LazyBind(comptime Ctx: type, comptime Target: type) type {
194 }194 }
195195
196 pub fn size(self: Self) u64 {196 pub fn size(self: Self) u64 {
197 return @intCast(u64, self.buffer.items.len);197 return @as(u64, @intCast(self.buffer.items.len));
198 }198 }
199199
200 pub fn finalize(self: *Self, gpa: Allocator, ctx: Ctx) !void {200 pub fn finalize(self: *Self, gpa: Allocator, ctx: Ctx) !void {
...@@ -208,12 +208,12 @@ pub fn LazyBind(comptime Ctx: type, comptime Target: type) type {...@@ -208,12 +208,12 @@ pub fn LazyBind(comptime Ctx: type, comptime Target: type) type {
208 var addend: i64 = 0;208 var addend: i64 = 0;
209209
210 for (self.entries.items) |entry| {210 for (self.entries.items) |entry| {
211 self.offsets.appendAssumeCapacity(@intCast(u32, cwriter.bytes_written));211 self.offsets.appendAssumeCapacity(@as(u32, @intCast(cwriter.bytes_written)));
212212
213 const sym = ctx.getSymbol(entry.target);213 const sym = ctx.getSymbol(entry.target);
214 const name = ctx.getSymbolName(entry.target);214 const name = ctx.getSymbolName(entry.target);
215 const flags: u8 = if (sym.weakRef()) macho.BIND_SYMBOL_FLAGS_WEAK_IMPORT else 0;215 const flags: u8 = if (sym.weakRef()) macho.BIND_SYMBOL_FLAGS_WEAK_IMPORT else 0;
216 const ordinal = @divTrunc(@bitCast(i16, sym.n_desc), macho.N_SYMBOL_RESOLVER);216 const ordinal = @divTrunc(@as(i16, @bitCast(sym.n_desc)), macho.N_SYMBOL_RESOLVER);
217217
218 try setSegmentOffset(entry.segment_id, entry.offset, writer);218 try setSegmentOffset(entry.segment_id, entry.offset, writer);
219 try setSymbol(name, flags, writer);219 try setSymbol(name, flags, writer);
...@@ -238,20 +238,20 @@ pub fn LazyBind(comptime Ctx: type, comptime Target: type) type {...@@ -238,20 +238,20 @@ pub fn LazyBind(comptime Ctx: type, comptime Target: type) type {
238238
239fn setSegmentOffset(segment_id: u8, offset: u64, writer: anytype) !void {239fn setSegmentOffset(segment_id: u8, offset: u64, writer: anytype) !void {
240 log.debug(">>> set segment: {d} and offset: {x}", .{ segment_id, offset });240 log.debug(">>> set segment: {d} and offset: {x}", .{ segment_id, offset });
241 try writer.writeByte(macho.BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB | @truncate(u4, segment_id));241 try writer.writeByte(macho.BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB | @as(u4, @truncate(segment_id)));
242 try std.leb.writeULEB128(writer, offset);242 try std.leb.writeULEB128(writer, offset);
243}243}
244244
245fn setSymbol(name: []const u8, flags: u8, writer: anytype) !void {245fn setSymbol(name: []const u8, flags: u8, writer: anytype) !void {
246 log.debug(">>> set symbol: {s} with flags: {x}", .{ name, flags });246 log.debug(">>> set symbol: {s} with flags: {x}", .{ name, flags });
247 try writer.writeByte(macho.BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM | @truncate(u4, flags));247 try writer.writeByte(macho.BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM | @as(u4, @truncate(flags)));
248 try writer.writeAll(name);248 try writer.writeAll(name);
249 try writer.writeByte(0);249 try writer.writeByte(0);
250}250}
251251
252fn setTypePointer(writer: anytype) !void {252fn setTypePointer(writer: anytype) !void {
253 log.debug(">>> set type: {d}", .{macho.BIND_TYPE_POINTER});253 log.debug(">>> set type: {d}", .{macho.BIND_TYPE_POINTER});
254 try writer.writeByte(macho.BIND_OPCODE_SET_TYPE_IMM | @truncate(u4, macho.BIND_TYPE_POINTER));254 try writer.writeByte(macho.BIND_OPCODE_SET_TYPE_IMM | @as(u4, @truncate(macho.BIND_TYPE_POINTER)));
255}255}
256256
257fn setDylibOrdinal(ordinal: i16, writer: anytype) !void {257fn setDylibOrdinal(ordinal: i16, writer: anytype) !void {
...@@ -264,13 +264,13 @@ fn setDylibOrdinal(ordinal: i16, writer: anytype) !void {...@@ -264,13 +264,13 @@ fn setDylibOrdinal(ordinal: i16, writer: anytype) !void {
264 else => unreachable, // Invalid dylib special binding264 else => unreachable, // Invalid dylib special binding
265 }265 }
266 log.debug(">>> set dylib special: {d}", .{ordinal});266 log.debug(">>> set dylib special: {d}", .{ordinal});
267 const cast = @bitCast(u16, ordinal);267 const cast = @as(u16, @bitCast(ordinal));
268 try writer.writeByte(macho.BIND_OPCODE_SET_DYLIB_SPECIAL_IMM | @truncate(u4, cast));268 try writer.writeByte(macho.BIND_OPCODE_SET_DYLIB_SPECIAL_IMM | @as(u4, @truncate(cast)));
269 } else {269 } else {
270 const cast = @bitCast(u16, ordinal);270 const cast = @as(u16, @bitCast(ordinal));
271 log.debug(">>> set dylib ordinal: {d}", .{ordinal});271 log.debug(">>> set dylib ordinal: {d}", .{ordinal});
272 if (cast <= 0xf) {272 if (cast <= 0xf) {
273 try writer.writeByte(macho.BIND_OPCODE_SET_DYLIB_ORDINAL_IMM | @truncate(u4, cast));273 try writer.writeByte(macho.BIND_OPCODE_SET_DYLIB_ORDINAL_IMM | @as(u4, @truncate(cast)));
274 } else {274 } else {
275 try writer.writeByte(macho.BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB);275 try writer.writeByte(macho.BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB);
276 try std.leb.writeULEB128(writer, cast);276 try std.leb.writeULEB128(writer, cast);
...@@ -295,7 +295,7 @@ fn doBindAddAddr(addr: u64, writer: anytype) !void {...@@ -295,7 +295,7 @@ fn doBindAddAddr(addr: u64, writer: anytype) !void {
295 const imm = @divExact(addr, @sizeOf(u64));295 const imm = @divExact(addr, @sizeOf(u64));
296 if (imm <= 0xf) {296 if (imm <= 0xf) {
297 try writer.writeByte(297 try writer.writeByte(
298 macho.BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED | @truncate(u4, imm),298 macho.BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED | @as(u4, @truncate(imm)),
299 );299 );
300 return;300 return;
301 }301 }
...@@ -341,7 +341,7 @@ const TestContext = struct {...@@ -341,7 +341,7 @@ const TestContext = struct {
341341
342 fn addSymbol(ctx: *TestContext, gpa: Allocator, name: []const u8, ordinal: i16, flags: u16) !void {342 fn addSymbol(ctx: *TestContext, gpa: Allocator, name: []const u8, ordinal: i16, flags: u16) !void {
343 const n_strx = try ctx.addString(gpa, name);343 const n_strx = try ctx.addString(gpa, name);
344 var n_desc = @bitCast(u16, ordinal * macho.N_SYMBOL_RESOLVER);344 var n_desc = @as(u16, @bitCast(ordinal * macho.N_SYMBOL_RESOLVER));
345 n_desc |= flags;345 n_desc |= flags;
346 try ctx.symbols.append(gpa, .{346 try ctx.symbols.append(gpa, .{
347 .n_value = 0,347 .n_value = 0,
...@@ -353,7 +353,7 @@ const TestContext = struct {...@@ -353,7 +353,7 @@ const TestContext = struct {
353 }353 }
354354
355 fn addString(ctx: *TestContext, gpa: Allocator, name: []const u8) !u32 {355 fn addString(ctx: *TestContext, gpa: Allocator, name: []const u8) !u32 {
356 const n_strx = @intCast(u32, ctx.strtab.items.len);356 const n_strx = @as(u32, @intCast(ctx.strtab.items.len));
357 try ctx.strtab.appendSlice(gpa, name);357 try ctx.strtab.appendSlice(gpa, name);
358 try ctx.strtab.append(gpa, 0);358 try ctx.strtab.append(gpa, 0);
359 return n_strx;359 return n_strx;
...@@ -366,7 +366,7 @@ const TestContext = struct {...@@ -366,7 +366,7 @@ const TestContext = struct {
366 fn getSymbolName(ctx: TestContext, target: Target) []const u8 {366 fn getSymbolName(ctx: TestContext, target: Target) []const u8 {
367 const sym = ctx.getSymbol(target);367 const sym = ctx.getSymbol(target);
368 assert(sym.n_strx < ctx.strtab.items.len);368 assert(sym.n_strx < ctx.strtab.items.len);
369 return std.mem.sliceTo(@ptrCast([*:0]const u8, ctx.strtab.items.ptr + sym.n_strx), 0);369 return std.mem.sliceTo(@as([*:0]const u8, @ptrCast(ctx.strtab.items.ptr + sym.n_strx)), 0);
370 }370 }
371};371};
372372
src/link/MachO/eh_frame.zig+36-36
...@@ -36,7 +36,7 @@ pub fn scanRelocs(zld: *Zld) !void {...@@ -36,7 +36,7 @@ pub fn scanRelocs(zld: *Zld) !void {
36 try cies.putNoClobber(cie_offset, {});36 try cies.putNoClobber(cie_offset, {});
37 it.seekTo(cie_offset);37 it.seekTo(cie_offset);
38 const cie = (try it.next()).?;38 const cie = (try it.next()).?;
39 try cie.scanRelocs(zld, @intCast(u32, object_id), cie_offset);39 try cie.scanRelocs(zld, @as(u32, @intCast(object_id)), cie_offset);
40 }40 }
41 }41 }
42 }42 }
...@@ -110,7 +110,7 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void {...@@ -110,7 +110,7 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void {
110 var eh_frame_offset: u32 = 0;110 var eh_frame_offset: u32 = 0;
111111
112 for (zld.objects.items, 0..) |*object, object_id| {112 for (zld.objects.items, 0..) |*object, object_id| {
113 try eh_records.ensureUnusedCapacity(2 * @intCast(u32, object.exec_atoms.items.len));113 try eh_records.ensureUnusedCapacity(2 * @as(u32, @intCast(object.exec_atoms.items.len)));
114114
115 var cies = std.AutoHashMap(u32, u32).init(gpa);115 var cies = std.AutoHashMap(u32, u32).init(gpa);
116 defer cies.deinit();116 defer cies.deinit();
...@@ -139,7 +139,7 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void {...@@ -139,7 +139,7 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void {
139 eh_it.seekTo(cie_offset);139 eh_it.seekTo(cie_offset);
140 const source_cie_record = (try eh_it.next()).?;140 const source_cie_record = (try eh_it.next()).?;
141 var cie_record = try source_cie_record.toOwned(gpa);141 var cie_record = try source_cie_record.toOwned(gpa);
142 try cie_record.relocate(zld, @intCast(u32, object_id), .{142 try cie_record.relocate(zld, @as(u32, @intCast(object_id)), .{
143 .source_offset = cie_offset,143 .source_offset = cie_offset,
144 .out_offset = eh_frame_offset,144 .out_offset = eh_frame_offset,
145 .sect_addr = sect.addr,145 .sect_addr = sect.addr,
...@@ -151,7 +151,7 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void {...@@ -151,7 +151,7 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void {
151151
152 var fde_record = try source_fde_record.toOwned(gpa);152 var fde_record = try source_fde_record.toOwned(gpa);
153 fde_record.setCiePointer(eh_frame_offset + 4 - gop.value_ptr.*);153 fde_record.setCiePointer(eh_frame_offset + 4 - gop.value_ptr.*);
154 try fde_record.relocate(zld, @intCast(u32, object_id), .{154 try fde_record.relocate(zld, @as(u32, @intCast(object_id)), .{
155 .source_offset = fde_record_offset,155 .source_offset = fde_record_offset,
156 .out_offset = eh_frame_offset,156 .out_offset = eh_frame_offset,
157 .sect_addr = sect.addr,157 .sect_addr = sect.addr,
...@@ -194,7 +194,7 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void {...@@ -194,7 +194,7 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void {
194 UnwindInfo.UnwindEncoding.setDwarfSectionOffset(194 UnwindInfo.UnwindEncoding.setDwarfSectionOffset(
195 &record.compactUnwindEncoding,195 &record.compactUnwindEncoding,
196 cpu_arch,196 cpu_arch,
197 @intCast(u24, eh_frame_offset),197 @as(u24, @intCast(eh_frame_offset)),
198 );198 );
199199
200 const cie_record = eh_records.get(200 const cie_record = eh_records.get(
...@@ -268,7 +268,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {...@@ -268,7 +268,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
268 }) u64 {268 }) u64 {
269 assert(rec.tag == .fde);269 assert(rec.tag == .fde);
270 const addend = mem.readIntLittle(i64, rec.data[4..][0..8]);270 const addend = mem.readIntLittle(i64, rec.data[4..][0..8]);
271 return @intCast(u64, @intCast(i64, ctx.base_addr + ctx.base_offset + 8) + addend);271 return @as(u64, @intCast(@as(i64, @intCast(ctx.base_addr + ctx.base_offset + 8)) + addend));
272 }272 }
273273
274 pub fn setTargetSymbolAddress(rec: *Record, value: u64, ctx: struct {274 pub fn setTargetSymbolAddress(rec: *Record, value: u64, ctx: struct {
...@@ -276,7 +276,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {...@@ -276,7 +276,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
276 base_offset: u64,276 base_offset: u64,
277 }) !void {277 }) !void {
278 assert(rec.tag == .fde);278 assert(rec.tag == .fde);
279 const addend = @intCast(i64, value) - @intCast(i64, ctx.base_addr + ctx.base_offset + 8);279 const addend = @as(i64, @intCast(value)) - @as(i64, @intCast(ctx.base_addr + ctx.base_offset + 8));
280 mem.writeIntLittle(i64, rec.data[4..][0..8], addend);280 mem.writeIntLittle(i64, rec.data[4..][0..8], addend);
281 }281 }
282282
...@@ -291,7 +291,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {...@@ -291,7 +291,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
291 for (relocs) |rel| {291 for (relocs) |rel| {
292 switch (cpu_arch) {292 switch (cpu_arch) {
293 .aarch64 => {293 .aarch64 => {
294 const rel_type = @enumFromInt(macho.reloc_type_arm64, rel.r_type);294 const rel_type = @as(macho.reloc_type_arm64, @enumFromInt(rel.r_type));
295 switch (rel_type) {295 switch (rel_type) {
296 .ARM64_RELOC_SUBTRACTOR,296 .ARM64_RELOC_SUBTRACTOR,
297 .ARM64_RELOC_UNSIGNED,297 .ARM64_RELOC_UNSIGNED,
...@@ -301,7 +301,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {...@@ -301,7 +301,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
301 }301 }
302 },302 },
303 .x86_64 => {303 .x86_64 => {
304 const rel_type = @enumFromInt(macho.reloc_type_x86_64, rel.r_type);304 const rel_type = @as(macho.reloc_type_x86_64, @enumFromInt(rel.r_type));
305 switch (rel_type) {305 switch (rel_type) {
306 .X86_64_RELOC_GOT => {},306 .X86_64_RELOC_GOT => {},
307 else => unreachable,307 else => unreachable,
...@@ -313,7 +313,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {...@@ -313,7 +313,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
313 .object_id = object_id,313 .object_id = object_id,
314 .rel = rel,314 .rel = rel,
315 .code = rec.data,315 .code = rec.data,
316 .base_offset = @intCast(i32, source_offset) + 4,316 .base_offset = @as(i32, @intCast(source_offset)) + 4,
317 });317 });
318 return target;318 return target;
319 }319 }
...@@ -335,40 +335,40 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {...@@ -335,40 +335,40 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
335 .object_id = object_id,335 .object_id = object_id,
336 .rel = rel,336 .rel = rel,
337 .code = rec.data,337 .code = rec.data,
338 .base_offset = @intCast(i32, ctx.source_offset) + 4,338 .base_offset = @as(i32, @intCast(ctx.source_offset)) + 4,
339 });339 });
340 const rel_offset = @intCast(u32, rel.r_address - @intCast(i32, ctx.source_offset) - 4);340 const rel_offset = @as(u32, @intCast(rel.r_address - @as(i32, @intCast(ctx.source_offset)) - 4));
341 const source_addr = ctx.sect_addr + rel_offset + ctx.out_offset + 4;341 const source_addr = ctx.sect_addr + rel_offset + ctx.out_offset + 4;
342342
343 switch (cpu_arch) {343 switch (cpu_arch) {
344 .aarch64 => {344 .aarch64 => {
345 const rel_type = @enumFromInt(macho.reloc_type_arm64, rel.r_type);345 const rel_type = @as(macho.reloc_type_arm64, @enumFromInt(rel.r_type));
346 switch (rel_type) {346 switch (rel_type) {
347 .ARM64_RELOC_SUBTRACTOR => {347 .ARM64_RELOC_SUBTRACTOR => {
348 // Address of the __eh_frame in the source object file348 // Address of the __eh_frame in the source object file
349 },349 },
350 .ARM64_RELOC_POINTER_TO_GOT => {350 .ARM64_RELOC_POINTER_TO_GOT => {
351 const target_addr = try Atom.getRelocTargetAddress(zld, target, true, false);351 const target_addr = try Atom.getRelocTargetAddress(zld, target, true, false);
352 const result = math.cast(i32, @intCast(i64, target_addr) - @intCast(i64, source_addr)) orelse352 const result = math.cast(i32, @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr))) orelse
353 return error.Overflow;353 return error.Overflow;
354 mem.writeIntLittle(i32, rec.data[rel_offset..][0..4], result);354 mem.writeIntLittle(i32, rec.data[rel_offset..][0..4], result);
355 },355 },
356 .ARM64_RELOC_UNSIGNED => {356 .ARM64_RELOC_UNSIGNED => {
357 assert(rel.r_extern == 1);357 assert(rel.r_extern == 1);
358 const target_addr = try Atom.getRelocTargetAddress(zld, target, false, false);358 const target_addr = try Atom.getRelocTargetAddress(zld, target, false, false);
359 const result = @intCast(i64, target_addr) - @intCast(i64, source_addr);359 const result = @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr));
360 mem.writeIntLittle(i64, rec.data[rel_offset..][0..8], @intCast(i64, result));360 mem.writeIntLittle(i64, rec.data[rel_offset..][0..8], @as(i64, @intCast(result)));
361 },361 },
362 else => unreachable,362 else => unreachable,
363 }363 }
364 },364 },
365 .x86_64 => {365 .x86_64 => {
366 const rel_type = @enumFromInt(macho.reloc_type_x86_64, rel.r_type);366 const rel_type = @as(macho.reloc_type_x86_64, @enumFromInt(rel.r_type));
367 switch (rel_type) {367 switch (rel_type) {
368 .X86_64_RELOC_GOT => {368 .X86_64_RELOC_GOT => {
369 const target_addr = try Atom.getRelocTargetAddress(zld, target, true, false);369 const target_addr = try Atom.getRelocTargetAddress(zld, target, true, false);
370 const addend = mem.readIntLittle(i32, rec.data[rel_offset..][0..4]);370 const addend = mem.readIntLittle(i32, rec.data[rel_offset..][0..4]);
371 const adjusted_target_addr = @intCast(u64, @intCast(i64, target_addr) + addend);371 const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend));
372 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);372 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);
373 mem.writeIntLittle(i32, rec.data[rel_offset..][0..4], disp);373 mem.writeIntLittle(i32, rec.data[rel_offset..][0..4], disp);
374 },374 },
...@@ -392,7 +392,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {...@@ -392,7 +392,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
392392
393 pub fn getAugmentationString(rec: Record) []const u8 {393 pub fn getAugmentationString(rec: Record) []const u8 {
394 assert(rec.tag == .cie);394 assert(rec.tag == .cie);
395 return mem.sliceTo(@ptrCast([*:0]const u8, rec.data.ptr + 5), 0);395 return mem.sliceTo(@as([*:0]const u8, @ptrCast(rec.data.ptr + 5)), 0);
396 }396 }
397397
398 pub fn getPersonalityPointer(rec: Record, ctx: struct {398 pub fn getPersonalityPointer(rec: Record, ctx: struct {
...@@ -418,7 +418,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {...@@ -418,7 +418,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
418 'P' => {418 'P' => {
419 const enc = try reader.readByte();419 const enc = try reader.readByte();
420 const offset = ctx.base_offset + 13 + aug_str.len + creader.bytes_read;420 const offset = ctx.base_offset + 13 + aug_str.len + creader.bytes_read;
421 const ptr = try getEncodedPointer(enc, @intCast(i64, ctx.base_addr + offset), reader);421 const ptr = try getEncodedPointer(enc, @as(i64, @intCast(ctx.base_addr + offset)), reader);
422 return ptr;422 return ptr;
423 },423 },
424 'L' => {424 'L' => {
...@@ -441,7 +441,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {...@@ -441,7 +441,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
441 const reader = stream.reader();441 const reader = stream.reader();
442 _ = try reader.readByte();442 _ = try reader.readByte();
443 const offset = ctx.base_offset + 25;443 const offset = ctx.base_offset + 25;
444 const ptr = try getEncodedPointer(enc, @intCast(i64, ctx.base_addr + offset), reader);444 const ptr = try getEncodedPointer(enc, @as(i64, @intCast(ctx.base_addr + offset)), reader);
445 return ptr;445 return ptr;
446 }446 }
447447
...@@ -454,7 +454,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {...@@ -454,7 +454,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
454 var stream = std.io.fixedBufferStream(rec.data[21..]);454 var stream = std.io.fixedBufferStream(rec.data[21..]);
455 const writer = stream.writer();455 const writer = stream.writer();
456 const offset = ctx.base_offset + 25;456 const offset = ctx.base_offset + 25;
457 try setEncodedPointer(enc, @intCast(i64, ctx.base_addr + offset), value, writer);457 try setEncodedPointer(enc, @as(i64, @intCast(ctx.base_addr + offset)), value, writer);
458 }458 }
459459
460 fn getLsdaEncoding(rec: Record) !?u8 {460 fn getLsdaEncoding(rec: Record) !?u8 {
...@@ -494,11 +494,11 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {...@@ -494,11 +494,11 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
494 if (enc == EH_PE.omit) return null;494 if (enc == EH_PE.omit) return null;
495495
496 var ptr: i64 = switch (enc & 0x0F) {496 var ptr: i64 = switch (enc & 0x0F) {
497 EH_PE.absptr => @bitCast(i64, try reader.readIntLittle(u64)),497 EH_PE.absptr => @as(i64, @bitCast(try reader.readIntLittle(u64))),
498 EH_PE.udata2 => @bitCast(i16, try reader.readIntLittle(u16)),498 EH_PE.udata2 => @as(i16, @bitCast(try reader.readIntLittle(u16))),
499 EH_PE.udata4 => @bitCast(i32, try reader.readIntLittle(u32)),499 EH_PE.udata4 => @as(i32, @bitCast(try reader.readIntLittle(u32))),
500 EH_PE.udata8 => @bitCast(i64, try reader.readIntLittle(u64)),500 EH_PE.udata8 => @as(i64, @bitCast(try reader.readIntLittle(u64))),
501 EH_PE.uleb128 => @bitCast(i64, try leb.readULEB128(u64, reader)),501 EH_PE.uleb128 => @as(i64, @bitCast(try leb.readULEB128(u64, reader))),
502 EH_PE.sdata2 => try reader.readIntLittle(i16),502 EH_PE.sdata2 => try reader.readIntLittle(i16),
503 EH_PE.sdata4 => try reader.readIntLittle(i32),503 EH_PE.sdata4 => try reader.readIntLittle(i32),
504 EH_PE.sdata8 => try reader.readIntLittle(i64),504 EH_PE.sdata8 => try reader.readIntLittle(i64),
...@@ -517,13 +517,13 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {...@@ -517,13 +517,13 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
517 else => return null,517 else => return null,
518 }518 }
519519
520 return @bitCast(u64, ptr);520 return @as(u64, @bitCast(ptr));
521 }521 }
522522
523 fn setEncodedPointer(enc: u8, pcrel_offset: i64, value: u64, writer: anytype) !void {523 fn setEncodedPointer(enc: u8, pcrel_offset: i64, value: u64, writer: anytype) !void {
524 if (enc == EH_PE.omit) return;524 if (enc == EH_PE.omit) return;
525525
526 var actual = @intCast(i64, value);526 var actual = @as(i64, @intCast(value));
527527
528 switch (enc & 0x70) {528 switch (enc & 0x70) {
529 EH_PE.absptr => {},529 EH_PE.absptr => {},
...@@ -537,13 +537,13 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {...@@ -537,13 +537,13 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
537 }537 }
538538
539 switch (enc & 0x0F) {539 switch (enc & 0x0F) {
540 EH_PE.absptr => try writer.writeIntLittle(u64, @bitCast(u64, actual)),540 EH_PE.absptr => try writer.writeIntLittle(u64, @as(u64, @bitCast(actual))),
541 EH_PE.udata2 => try writer.writeIntLittle(u16, @bitCast(u16, @intCast(i16, actual))),541 EH_PE.udata2 => try writer.writeIntLittle(u16, @as(u16, @bitCast(@as(i16, @intCast(actual))))),
542 EH_PE.udata4 => try writer.writeIntLittle(u32, @bitCast(u32, @intCast(i32, actual))),542 EH_PE.udata4 => try writer.writeIntLittle(u32, @as(u32, @bitCast(@as(i32, @intCast(actual))))),
543 EH_PE.udata8 => try writer.writeIntLittle(u64, @bitCast(u64, actual)),543 EH_PE.udata8 => try writer.writeIntLittle(u64, @as(u64, @bitCast(actual))),
544 EH_PE.uleb128 => try leb.writeULEB128(writer, @bitCast(u64, actual)),544 EH_PE.uleb128 => try leb.writeULEB128(writer, @as(u64, @bitCast(actual))),
545 EH_PE.sdata2 => try writer.writeIntLittle(i16, @intCast(i16, actual)),545 EH_PE.sdata2 => try writer.writeIntLittle(i16, @as(i16, @intCast(actual))),
546 EH_PE.sdata4 => try writer.writeIntLittle(i32, @intCast(i32, actual)),546 EH_PE.sdata4 => try writer.writeIntLittle(i32, @as(i32, @intCast(actual))),
547 EH_PE.sdata8 => try writer.writeIntLittle(i64, actual),547 EH_PE.sdata8 => try writer.writeIntLittle(i64, actual),
548 EH_PE.sleb128 => try leb.writeILEB128(writer, actual),548 EH_PE.sleb128 => try leb.writeILEB128(writer, actual),
549 else => unreachable,549 else => unreachable,
src/link/MachO/load_commands.zig+12-12
...@@ -114,7 +114,7 @@ fn calcLCsSize(gpa: Allocator, options: *const link.Options, ctx: CalcLCsSizeCtx...@@ -114,7 +114,7 @@ fn calcLCsSize(gpa: Allocator, options: *const link.Options, ctx: CalcLCsSizeCtx
114 }114 }
115 }115 }
116116
117 return @intCast(u32, sizeofcmds);117 return @as(u32, @intCast(sizeofcmds));
118}118}
119119
120pub fn calcMinHeaderPad(gpa: Allocator, options: *const link.Options, ctx: CalcLCsSizeCtx) !u64 {120pub fn calcMinHeaderPad(gpa: Allocator, options: *const link.Options, ctx: CalcLCsSizeCtx) !u64 {
...@@ -140,7 +140,7 @@ pub fn calcNumOfLCs(lc_buffer: []const u8) u32 {...@@ -140,7 +140,7 @@ pub fn calcNumOfLCs(lc_buffer: []const u8) u32 {
140 var pos: usize = 0;140 var pos: usize = 0;
141 while (true) {141 while (true) {
142 if (pos >= lc_buffer.len) break;142 if (pos >= lc_buffer.len) break;
143 const cmd = @ptrCast(*align(1) const macho.load_command, lc_buffer.ptr + pos).*;143 const cmd = @as(*align(1) const macho.load_command, @ptrCast(lc_buffer.ptr + pos)).*;
144 ncmds += 1;144 ncmds += 1;
145 pos += cmd.cmdsize;145 pos += cmd.cmdsize;
146 }146 }
...@@ -149,11 +149,11 @@ pub fn calcNumOfLCs(lc_buffer: []const u8) u32 {...@@ -149,11 +149,11 @@ pub fn calcNumOfLCs(lc_buffer: []const u8) u32 {
149149
150pub fn writeDylinkerLC(lc_writer: anytype) !void {150pub fn writeDylinkerLC(lc_writer: anytype) !void {
151 const name_len = mem.sliceTo(default_dyld_path, 0).len;151 const name_len = mem.sliceTo(default_dyld_path, 0).len;
152 const cmdsize = @intCast(u32, mem.alignForward(152 const cmdsize = @as(u32, @intCast(mem.alignForward(
153 u64,153 u64,
154 @sizeOf(macho.dylinker_command) + name_len,154 @sizeOf(macho.dylinker_command) + name_len,
155 @sizeOf(u64),155 @sizeOf(u64),
156 ));156 )));
157 try lc_writer.writeStruct(macho.dylinker_command{157 try lc_writer.writeStruct(macho.dylinker_command{
158 .cmd = .LOAD_DYLINKER,158 .cmd = .LOAD_DYLINKER,
159 .cmdsize = cmdsize,159 .cmdsize = cmdsize,
...@@ -176,11 +176,11 @@ const WriteDylibLCCtx = struct {...@@ -176,11 +176,11 @@ const WriteDylibLCCtx = struct {
176176
177fn writeDylibLC(ctx: WriteDylibLCCtx, lc_writer: anytype) !void {177fn writeDylibLC(ctx: WriteDylibLCCtx, lc_writer: anytype) !void {
178 const name_len = ctx.name.len + 1;178 const name_len = ctx.name.len + 1;
179 const cmdsize = @intCast(u32, mem.alignForward(179 const cmdsize = @as(u32, @intCast(mem.alignForward(
180 u64,180 u64,
181 @sizeOf(macho.dylib_command) + name_len,181 @sizeOf(macho.dylib_command) + name_len,
182 @sizeOf(u64),182 @sizeOf(u64),
183 ));183 )));
184 try lc_writer.writeStruct(macho.dylib_command{184 try lc_writer.writeStruct(macho.dylib_command{
185 .cmd = ctx.cmd,185 .cmd = ctx.cmd,
186 .cmdsize = cmdsize,186 .cmdsize = cmdsize,
...@@ -217,8 +217,8 @@ pub fn writeDylibIdLC(gpa: Allocator, options: *const link.Options, lc_writer: a...@@ -217,8 +217,8 @@ pub fn writeDylibIdLC(gpa: Allocator, options: *const link.Options, lc_writer: a
217 try writeDylibLC(.{217 try writeDylibLC(.{
218 .cmd = .ID_DYLIB,218 .cmd = .ID_DYLIB,
219 .name = install_name,219 .name = install_name,
220 .current_version = @intCast(u32, curr.major << 16 | curr.minor << 8 | curr.patch),220 .current_version = @as(u32, @intCast(curr.major << 16 | curr.minor << 8 | curr.patch)),
221 .compatibility_version = @intCast(u32, compat.major << 16 | compat.minor << 8 | compat.patch),221 .compatibility_version = @as(u32, @intCast(compat.major << 16 | compat.minor << 8 | compat.patch)),
222 }, lc_writer);222 }, lc_writer);
223}223}
224224
...@@ -253,11 +253,11 @@ pub fn writeRpathLCs(gpa: Allocator, options: *const link.Options, lc_writer: an...@@ -253,11 +253,11 @@ pub fn writeRpathLCs(gpa: Allocator, options: *const link.Options, lc_writer: an
253253
254 while (try it.next()) |rpath| {254 while (try it.next()) |rpath| {
255 const rpath_len = rpath.len + 1;255 const rpath_len = rpath.len + 1;
256 const cmdsize = @intCast(u32, mem.alignForward(256 const cmdsize = @as(u32, @intCast(mem.alignForward(
257 u64,257 u64,
258 @sizeOf(macho.rpath_command) + rpath_len,258 @sizeOf(macho.rpath_command) + rpath_len,
259 @sizeOf(u64),259 @sizeOf(u64),
260 ));260 )));
261 try lc_writer.writeStruct(macho.rpath_command{261 try lc_writer.writeStruct(macho.rpath_command{
262 .cmdsize = cmdsize,262 .cmdsize = cmdsize,
263 .path = @sizeOf(macho.rpath_command),263 .path = @sizeOf(macho.rpath_command),
...@@ -275,12 +275,12 @@ pub fn writeBuildVersionLC(options: *const link.Options, lc_writer: anytype) !vo...@@ -275,12 +275,12 @@ pub fn writeBuildVersionLC(options: *const link.Options, lc_writer: anytype) !vo
275 const cmdsize = @sizeOf(macho.build_version_command) + @sizeOf(macho.build_tool_version);275 const cmdsize = @sizeOf(macho.build_version_command) + @sizeOf(macho.build_tool_version);
276 const platform_version = blk: {276 const platform_version = blk: {
277 const ver = options.target.os.version_range.semver.min;277 const ver = options.target.os.version_range.semver.min;
278 const platform_version = @intCast(u32, ver.major << 16 | ver.minor << 8);278 const platform_version = @as(u32, @intCast(ver.major << 16 | ver.minor << 8));
279 break :blk platform_version;279 break :blk platform_version;
280 };280 };
281 const sdk_version = if (options.native_darwin_sdk) |sdk| blk: {281 const sdk_version = if (options.native_darwin_sdk) |sdk| blk: {
282 const ver = sdk.version;282 const ver = sdk.version;
283 const sdk_version = @intCast(u32, ver.major << 16 | ver.minor << 8);283 const sdk_version = @as(u32, @intCast(ver.major << 16 | ver.minor << 8));
284 break :blk sdk_version;284 break :blk sdk_version;
285 } else platform_version;285 } else platform_version;
286 const is_simulator_abi = options.target.abi == .simulator;286 const is_simulator_abi = options.target.abi == .simulator;
src/link/MachO/thunks.zig+6-6
...@@ -131,7 +131,7 @@ pub fn createThunks(zld: *Zld, sect_id: u8) !void {...@@ -131,7 +131,7 @@ pub fn createThunks(zld: *Zld, sect_id: u8) !void {
131 log.debug("GROUP END at {d}", .{group_end});131 log.debug("GROUP END at {d}", .{group_end});
132132
133 // Insert thunk at group_end133 // Insert thunk at group_end
134 const thunk_index = @intCast(u32, zld.thunks.items.len);134 const thunk_index = @as(u32, @intCast(zld.thunks.items.len));
135 try zld.thunks.append(gpa, .{ .start_index = undefined, .len = 0 });135 try zld.thunks.append(gpa, .{ .start_index = undefined, .len = 0 });
136136
137 // Scan relocs in the group and create trampolines for any unreachable callsite.137 // Scan relocs in the group and create trampolines for any unreachable callsite.
...@@ -174,7 +174,7 @@ pub fn createThunks(zld: *Zld, sect_id: u8) !void {...@@ -174,7 +174,7 @@ pub fn createThunks(zld: *Zld, sect_id: u8) !void {
174 }174 }
175 }175 }
176176
177 header.size = @intCast(u32, offset);177 header.size = @as(u32, @intCast(offset));
178}178}
179179
180fn allocateThunk(180fn allocateThunk(
...@@ -223,7 +223,7 @@ fn scanRelocs(...@@ -223,7 +223,7 @@ fn scanRelocs(
223223
224 const base_offset = if (object.getSourceSymbol(atom.sym_index)) |source_sym| blk: {224 const base_offset = if (object.getSourceSymbol(atom.sym_index)) |source_sym| blk: {
225 const source_sect = object.getSourceSection(source_sym.n_sect - 1);225 const source_sect = object.getSourceSection(source_sym.n_sect - 1);
226 break :blk @intCast(i32, source_sym.n_value - source_sect.addr);226 break :blk @as(i32, @intCast(source_sym.n_value - source_sect.addr));
227 } else 0;227 } else 0;
228228
229 const code = Atom.getAtomCode(zld, atom_index);229 const code = Atom.getAtomCode(zld, atom_index);
...@@ -289,7 +289,7 @@ fn scanRelocs(...@@ -289,7 +289,7 @@ fn scanRelocs(
289}289}
290290
291inline fn relocNeedsThunk(rel: macho.relocation_info) bool {291inline fn relocNeedsThunk(rel: macho.relocation_info) bool {
292 const rel_type = @enumFromInt(macho.reloc_type_arm64, rel.r_type);292 const rel_type = @as(macho.reloc_type_arm64, @enumFromInt(rel.r_type));
293 return rel_type == .ARM64_RELOC_BRANCH26;293 return rel_type == .ARM64_RELOC_BRANCH26;
294}294}
295295
...@@ -315,7 +315,7 @@ fn isReachable(...@@ -315,7 +315,7 @@ fn isReachable(
315315
316 if (!allocated.contains(target_atom_index)) return false;316 if (!allocated.contains(target_atom_index)) return false;
317317
318 const source_addr = source_sym.n_value + @intCast(u32, rel.r_address - base_offset);318 const source_addr = source_sym.n_value + @as(u32, @intCast(rel.r_address - base_offset));
319 const is_via_got = Atom.relocRequiresGot(zld, rel);319 const is_via_got = Atom.relocRequiresGot(zld, rel);
320 const target_addr = Atom.getRelocTargetAddress(zld, target, is_via_got, false) catch unreachable;320 const target_addr = Atom.getRelocTargetAddress(zld, target, is_via_got, false) catch unreachable;
321 _ = Relocation.calcPcRelativeDisplacementArm64(source_addr, target_addr) catch321 _ = Relocation.calcPcRelativeDisplacementArm64(source_addr, target_addr) catch
...@@ -349,7 +349,7 @@ fn getThunkIndex(zld: *Zld, atom_index: AtomIndex) ?ThunkIndex {...@@ -349,7 +349,7 @@ fn getThunkIndex(zld: *Zld, atom_index: AtomIndex) ?ThunkIndex {
349 const end_addr = start_addr + thunk.getSize();349 const end_addr = start_addr + thunk.getSize();
350350
351 if (start_addr <= sym.n_value and sym.n_value < end_addr) {351 if (start_addr <= sym.n_value and sym.n_value < end_addr) {
352 return @intCast(u32, i);352 return @as(u32, @intCast(i));
353 }353 }
354 }354 }
355 return null;355 return null;
src/link/MachO/zld.zig+72-72
...@@ -103,7 +103,7 @@ pub const Zld = struct {...@@ -103,7 +103,7 @@ pub const Zld = struct {
103 const cpu_arch = self.options.target.cpu.arch;103 const cpu_arch = self.options.target.cpu.arch;
104 const mtime: u64 = mtime: {104 const mtime: u64 = mtime: {
105 const stat = file.stat() catch break :mtime 0;105 const stat = file.stat() catch break :mtime 0;
106 break :mtime @intCast(u64, @divFloor(stat.mtime, 1_000_000_000));106 break :mtime @as(u64, @intCast(@divFloor(stat.mtime, 1_000_000_000)));
107 };107 };
108 const file_stat = try file.stat();108 const file_stat = try file.stat();
109 const file_size = math.cast(usize, file_stat.size) orelse return error.Overflow;109 const file_size = math.cast(usize, file_stat.size) orelse return error.Overflow;
...@@ -220,7 +220,7 @@ pub const Zld = struct {...@@ -220,7 +220,7 @@ pub const Zld = struct {
220 const contents = try file.readToEndAllocOptions(gpa, file_size, file_size, @alignOf(u64), null);220 const contents = try file.readToEndAllocOptions(gpa, file_size, file_size, @alignOf(u64), null);
221 defer gpa.free(contents);221 defer gpa.free(contents);
222222
223 const dylib_id = @intCast(u16, self.dylibs.items.len);223 const dylib_id = @as(u16, @intCast(self.dylibs.items.len));
224 var dylib = Dylib{ .weak = opts.weak };224 var dylib = Dylib{ .weak = opts.weak };
225225
226 dylib.parseFromBinary(226 dylib.parseFromBinary(
...@@ -535,7 +535,7 @@ pub const Zld = struct {...@@ -535,7 +535,7 @@ pub const Zld = struct {
535535
536 pub fn createEmptyAtom(self: *Zld, sym_index: u32, size: u64, alignment: u32) !AtomIndex {536 pub fn createEmptyAtom(self: *Zld, sym_index: u32, size: u64, alignment: u32) !AtomIndex {
537 const gpa = self.gpa;537 const gpa = self.gpa;
538 const index = @intCast(AtomIndex, self.atoms.items.len);538 const index = @as(AtomIndex, @intCast(self.atoms.items.len));
539 const atom = try self.atoms.addOne(gpa);539 const atom = try self.atoms.addOne(gpa);
540 atom.* = Atom.empty;540 atom.* = Atom.empty;
541 atom.sym_index = sym_index;541 atom.sym_index = sym_index;
...@@ -596,7 +596,7 @@ pub const Zld = struct {...@@ -596,7 +596,7 @@ pub const Zld = struct {
596 const global_index = self.dyld_stub_binder_index orelse return;596 const global_index = self.dyld_stub_binder_index orelse return;
597 const target = self.globals.items[global_index];597 const target = self.globals.items[global_index];
598 const atom_index = try self.createGotAtom();598 const atom_index = try self.createGotAtom();
599 const got_index = @intCast(u32, self.got_entries.items.len);599 const got_index = @as(u32, @intCast(self.got_entries.items.len));
600 try self.got_entries.append(gpa, .{600 try self.got_entries.append(gpa, .{
601 .target = target,601 .target = target,
602 .atom_index = atom_index,602 .atom_index = atom_index,
...@@ -874,7 +874,7 @@ pub const Zld = struct {...@@ -874,7 +874,7 @@ pub const Zld = struct {
874 }874 }
875875
876 for (self.objects.items, 0..) |_, object_id| {876 for (self.objects.items, 0..) |_, object_id| {
877 try self.resolveSymbolsInObject(@intCast(u32, object_id), resolver);877 try self.resolveSymbolsInObject(@as(u32, @intCast(object_id)), resolver);
878 }878 }
879879
880 try self.resolveSymbolsInArchives(resolver);880 try self.resolveSymbolsInArchives(resolver);
...@@ -1024,7 +1024,7 @@ pub const Zld = struct {...@@ -1024,7 +1024,7 @@ pub const Zld = struct {
1024 };1024 };
1025 assert(offsets.items.len > 0);1025 assert(offsets.items.len > 0);
10261026
1027 const object_id = @intCast(u16, self.objects.items.len);1027 const object_id = @as(u16, @intCast(self.objects.items.len));
1028 const object = archive.parseObject(gpa, cpu_arch, offsets.items[0]) catch |e| switch (e) {1028 const object = archive.parseObject(gpa, cpu_arch, offsets.items[0]) catch |e| switch (e) {
1029 error.MismatchedCpuArchitecture => {1029 error.MismatchedCpuArchitecture => {
1030 log.err("CPU architecture mismatch found in {s}", .{archive.name});1030 log.err("CPU architecture mismatch found in {s}", .{archive.name});
...@@ -1055,14 +1055,14 @@ pub const Zld = struct {...@@ -1055,14 +1055,14 @@ pub const Zld = struct {
1055 for (self.dylibs.items, 0..) |dylib, id| {1055 for (self.dylibs.items, 0..) |dylib, id| {
1056 if (!dylib.symbols.contains(sym_name)) continue;1056 if (!dylib.symbols.contains(sym_name)) continue;
10571057
1058 const dylib_id = @intCast(u16, id);1058 const dylib_id = @as(u16, @intCast(id));
1059 if (!self.referenced_dylibs.contains(dylib_id)) {1059 if (!self.referenced_dylibs.contains(dylib_id)) {
1060 try self.referenced_dylibs.putNoClobber(self.gpa, dylib_id, {});1060 try self.referenced_dylibs.putNoClobber(self.gpa, dylib_id, {});
1061 }1061 }
10621062
1063 const ordinal = self.referenced_dylibs.getIndex(dylib_id) orelse unreachable;1063 const ordinal = self.referenced_dylibs.getIndex(dylib_id) orelse unreachable;
1064 sym.n_type |= macho.N_EXT;1064 sym.n_type |= macho.N_EXT;
1065 sym.n_desc = @intCast(u16, ordinal + 1) * macho.N_SYMBOL_RESOLVER;1065 sym.n_desc = @as(u16, @intCast(ordinal + 1)) * macho.N_SYMBOL_RESOLVER;
10661066
1067 if (dylib.weak) {1067 if (dylib.weak) {
1068 sym.n_desc |= macho.N_WEAK_REF;1068 sym.n_desc |= macho.N_WEAK_REF;
...@@ -1099,9 +1099,9 @@ pub const Zld = struct {...@@ -1099,9 +1099,9 @@ pub const Zld = struct {
1099 _ = resolver.unresolved.swapRemove(global_index);1099 _ = resolver.unresolved.swapRemove(global_index);
1100 continue;1100 continue;
1101 } else if (allow_undef) {1101 } else if (allow_undef) {
1102 const n_desc = @bitCast(1102 const n_desc = @as(
1103 u16,1103 u16,
1104 macho.BIND_SPECIAL_DYLIB_FLAT_LOOKUP * @intCast(i16, macho.N_SYMBOL_RESOLVER),1104 @bitCast(macho.BIND_SPECIAL_DYLIB_FLAT_LOOKUP * @as(i16, @intCast(macho.N_SYMBOL_RESOLVER))),
1105 );1105 );
1106 sym.n_type = macho.N_EXT;1106 sym.n_type = macho.N_EXT;
1107 sym.n_desc = n_desc;1107 sym.n_desc = n_desc;
...@@ -1238,7 +1238,7 @@ pub const Zld = struct {...@@ -1238,7 +1238,7 @@ pub const Zld = struct {
1238 const segname = header.segName();1238 const segname = header.segName();
1239 const segment_id = self.getSegmentByName(segname) orelse blk: {1239 const segment_id = self.getSegmentByName(segname) orelse blk: {
1240 log.debug("creating segment '{s}'", .{segname});1240 log.debug("creating segment '{s}'", .{segname});
1241 const segment_id = @intCast(u8, self.segments.items.len);1241 const segment_id = @as(u8, @intCast(self.segments.items.len));
1242 const protection = getSegmentMemoryProtection(segname);1242 const protection = getSegmentMemoryProtection(segname);
1243 try self.segments.append(self.gpa, .{1243 try self.segments.append(self.gpa, .{
1244 .cmdsize = @sizeOf(macho.segment_command_64),1244 .cmdsize = @sizeOf(macho.segment_command_64),
...@@ -1269,7 +1269,7 @@ pub const Zld = struct {...@@ -1269,7 +1269,7 @@ pub const Zld = struct {
1269 pub fn allocateSymbol(self: *Zld) !u32 {1269 pub fn allocateSymbol(self: *Zld) !u32 {
1270 try self.locals.ensureUnusedCapacity(self.gpa, 1);1270 try self.locals.ensureUnusedCapacity(self.gpa, 1);
1271 log.debug(" (allocating symbol index {d})", .{self.locals.items.len});1271 log.debug(" (allocating symbol index {d})", .{self.locals.items.len});
1272 const index = @intCast(u32, self.locals.items.len);1272 const index = @as(u32, @intCast(self.locals.items.len));
1273 _ = self.locals.addOneAssumeCapacity();1273 _ = self.locals.addOneAssumeCapacity();
1274 self.locals.items[index] = .{1274 self.locals.items[index] = .{
1275 .n_strx = 0,1275 .n_strx = 0,
...@@ -1282,7 +1282,7 @@ pub const Zld = struct {...@@ -1282,7 +1282,7 @@ pub const Zld = struct {
1282 }1282 }
12831283
1284 fn addGlobal(self: *Zld, sym_loc: SymbolWithLoc) !u32 {1284 fn addGlobal(self: *Zld, sym_loc: SymbolWithLoc) !u32 {
1285 const global_index = @intCast(u32, self.globals.items.len);1285 const global_index = @as(u32, @intCast(self.globals.items.len));
1286 try self.globals.append(self.gpa, sym_loc);1286 try self.globals.append(self.gpa, sym_loc);
1287 return global_index;1287 return global_index;
1288 }1288 }
...@@ -1489,7 +1489,7 @@ pub const Zld = struct {...@@ -1489,7 +1489,7 @@ pub const Zld = struct {
1489 if (mem.eql(u8, header.sectName(), "__stub_helper")) continue;1489 if (mem.eql(u8, header.sectName(), "__stub_helper")) continue;
14901490
1491 // Create jump/branch range extenders if needed.1491 // Create jump/branch range extenders if needed.
1492 try thunks.createThunks(self, @intCast(u8, sect_id));1492 try thunks.createThunks(self, @as(u8, @intCast(sect_id)));
1493 }1493 }
1494 }1494 }
1495 }1495 }
...@@ -1502,7 +1502,7 @@ pub const Zld = struct {...@@ -1502,7 +1502,7 @@ pub const Zld = struct {
1502 .dylibs = self.dylibs.items,1502 .dylibs = self.dylibs.items,
1503 .referenced_dylibs = self.referenced_dylibs.keys(),1503 .referenced_dylibs = self.referenced_dylibs.keys(),
1504 }) else 0;1504 }) else 0;
1505 try self.allocateSegment(@intCast(u8, segment_index), base_size);1505 try self.allocateSegment(@as(u8, @intCast(segment_index)), base_size);
1506 }1506 }
1507 }1507 }
15081508
...@@ -1536,12 +1536,12 @@ pub const Zld = struct {...@@ -1536,12 +1536,12 @@ pub const Zld = struct {
1536 for (slice.items(.header)[indexes.start..indexes.end], 0..) |*header, sect_id| {1536 for (slice.items(.header)[indexes.start..indexes.end], 0..) |*header, sect_id| {
1537 const alignment = try math.powi(u32, 2, header.@"align");1537 const alignment = try math.powi(u32, 2, header.@"align");
1538 const start_aligned = mem.alignForward(u64, start, alignment);1538 const start_aligned = mem.alignForward(u64, start, alignment);
1539 const n_sect = @intCast(u8, indexes.start + sect_id + 1);1539 const n_sect = @as(u8, @intCast(indexes.start + sect_id + 1));
15401540
1541 header.offset = if (header.isZerofill())1541 header.offset = if (header.isZerofill())
1542 01542 0
1543 else1543 else
1544 @intCast(u32, segment.fileoff + start_aligned);1544 @as(u32, @intCast(segment.fileoff + start_aligned));
1545 header.addr = segment.vmaddr + start_aligned;1545 header.addr = segment.vmaddr + start_aligned;
15461546
1547 var atom_index = slice.items(.first_atom_index)[indexes.start + sect_id];1547 var atom_index = slice.items(.first_atom_index)[indexes.start + sect_id];
...@@ -1617,7 +1617,7 @@ pub const Zld = struct {...@@ -1617,7 +1617,7 @@ pub const Zld = struct {
1617 ) !u8 {1617 ) !u8 {
1618 const gpa = self.gpa;1618 const gpa = self.gpa;
1619 log.debug("creating section '{s},{s}'", .{ segname, sectname });1619 log.debug("creating section '{s},{s}'", .{ segname, sectname });
1620 const index = @intCast(u8, self.sections.slice().len);1620 const index = @as(u8, @intCast(self.sections.slice().len));
1621 try self.sections.append(gpa, .{1621 try self.sections.append(gpa, .{
1622 .segment_index = undefined, // Segments will be created automatically later down the pipeline1622 .segment_index = undefined, // Segments will be created automatically later down the pipeline
1623 .header = .{1623 .header = .{
...@@ -1673,12 +1673,12 @@ pub const Zld = struct {...@@ -1673,12 +1673,12 @@ pub const Zld = struct {
1673 },1673 },
1674 }1674 }
1675 };1675 };
1676 return (@intCast(u8, segment_precedence) << 4) + section_precedence;1676 return (@as(u8, @intCast(segment_precedence)) << 4) + section_precedence;
1677 }1677 }
16781678
1679 fn writeSegmentHeaders(self: *Zld, writer: anytype) !void {1679 fn writeSegmentHeaders(self: *Zld, writer: anytype) !void {
1680 for (self.segments.items, 0..) |seg, i| {1680 for (self.segments.items, 0..) |seg, i| {
1681 const indexes = self.getSectionIndexes(@intCast(u8, i));1681 const indexes = self.getSectionIndexes(@as(u8, @intCast(i)));
1682 var out_seg = seg;1682 var out_seg = seg;
1683 out_seg.cmdsize = @sizeOf(macho.segment_command_64);1683 out_seg.cmdsize = @sizeOf(macho.segment_command_64);
1684 out_seg.nsects = 0;1684 out_seg.nsects = 0;
...@@ -1790,7 +1790,7 @@ pub const Zld = struct {...@@ -1790,7 +1790,7 @@ pub const Zld = struct {
1790 }1790 }
17911791
1792 const segment_index = slice.items(.segment_index)[sect_id];1792 const segment_index = slice.items(.segment_index)[sect_id];
1793 const segment = self.getSegment(@intCast(u8, sect_id));1793 const segment = self.getSegment(@as(u8, @intCast(sect_id)));
1794 if (segment.maxprot & macho.PROT.WRITE == 0) continue;1794 if (segment.maxprot & macho.PROT.WRITE == 0) continue;
17951795
1796 log.debug("{s},{s}", .{ header.segName(), header.sectName() });1796 log.debug("{s},{s}", .{ header.segName(), header.sectName() });
...@@ -1820,12 +1820,12 @@ pub const Zld = struct {...@@ -1820,12 +1820,12 @@ pub const Zld = struct {
1820 for (relocs) |rel| {1820 for (relocs) |rel| {
1821 switch (cpu_arch) {1821 switch (cpu_arch) {
1822 .aarch64 => {1822 .aarch64 => {
1823 const rel_type = @enumFromInt(macho.reloc_type_arm64, rel.r_type);1823 const rel_type = @as(macho.reloc_type_arm64, @enumFromInt(rel.r_type));
1824 if (rel_type != .ARM64_RELOC_UNSIGNED) continue;1824 if (rel_type != .ARM64_RELOC_UNSIGNED) continue;
1825 if (rel.r_length != 3) continue;1825 if (rel.r_length != 3) continue;
1826 },1826 },
1827 .x86_64 => {1827 .x86_64 => {
1828 const rel_type = @enumFromInt(macho.reloc_type_x86_64, rel.r_type);1828 const rel_type = @as(macho.reloc_type_x86_64, @enumFromInt(rel.r_type));
1829 if (rel_type != .X86_64_RELOC_UNSIGNED) continue;1829 if (rel_type != .X86_64_RELOC_UNSIGNED) continue;
1830 if (rel.r_length != 3) continue;1830 if (rel.r_length != 3) continue;
1831 },1831 },
...@@ -1841,9 +1841,9 @@ pub const Zld = struct {...@@ -1841,9 +1841,9 @@ pub const Zld = struct {
1841 const target_sym = self.getSymbol(target);1841 const target_sym = self.getSymbol(target);
1842 if (target_sym.undf()) continue;1842 if (target_sym.undf()) continue;
18431843
1844 const base_offset = @intCast(i32, sym.n_value - segment.vmaddr);1844 const base_offset = @as(i32, @intCast(sym.n_value - segment.vmaddr));
1845 const rel_offset = rel.r_address - ctx.base_offset;1845 const rel_offset = rel.r_address - ctx.base_offset;
1846 const offset = @intCast(u64, base_offset + rel_offset);1846 const offset = @as(u64, @intCast(base_offset + rel_offset));
1847 log.debug(" | rebase at {x}", .{offset});1847 log.debug(" | rebase at {x}", .{offset});
18481848
1849 try rebase.entries.append(self.gpa, .{1849 try rebase.entries.append(self.gpa, .{
...@@ -1882,7 +1882,7 @@ pub const Zld = struct {...@@ -1882,7 +1882,7 @@ pub const Zld = struct {
1882 const sym = entry.getAtomSymbol(self);1882 const sym = entry.getAtomSymbol(self);
1883 const base_offset = sym.n_value - seg.vmaddr;1883 const base_offset = sym.n_value - seg.vmaddr;
18841884
1885 const dylib_ordinal = @divTrunc(@bitCast(i16, bind_sym.n_desc), macho.N_SYMBOL_RESOLVER);1885 const dylib_ordinal = @divTrunc(@as(i16, @bitCast(bind_sym.n_desc)), macho.N_SYMBOL_RESOLVER);
1886 log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{1886 log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{
1887 base_offset,1887 base_offset,
1888 bind_sym_name,1888 bind_sym_name,
...@@ -1929,7 +1929,7 @@ pub const Zld = struct {...@@ -1929,7 +1929,7 @@ pub const Zld = struct {
1929 }1929 }
19301930
1931 const segment_index = slice.items(.segment_index)[sect_id];1931 const segment_index = slice.items(.segment_index)[sect_id];
1932 const segment = self.getSegment(@intCast(u8, sect_id));1932 const segment = self.getSegment(@as(u8, @intCast(sect_id)));
1933 if (segment.maxprot & macho.PROT.WRITE == 0) continue;1933 if (segment.maxprot & macho.PROT.WRITE == 0) continue;
19341934
1935 const cpu_arch = self.options.target.cpu.arch;1935 const cpu_arch = self.options.target.cpu.arch;
...@@ -1959,12 +1959,12 @@ pub const Zld = struct {...@@ -1959,12 +1959,12 @@ pub const Zld = struct {
1959 for (relocs) |rel| {1959 for (relocs) |rel| {
1960 switch (cpu_arch) {1960 switch (cpu_arch) {
1961 .aarch64 => {1961 .aarch64 => {
1962 const rel_type = @enumFromInt(macho.reloc_type_arm64, rel.r_type);1962 const rel_type = @as(macho.reloc_type_arm64, @enumFromInt(rel.r_type));
1963 if (rel_type != .ARM64_RELOC_UNSIGNED) continue;1963 if (rel_type != .ARM64_RELOC_UNSIGNED) continue;
1964 if (rel.r_length != 3) continue;1964 if (rel.r_length != 3) continue;
1965 },1965 },
1966 .x86_64 => {1966 .x86_64 => {
1967 const rel_type = @enumFromInt(macho.reloc_type_x86_64, rel.r_type);1967 const rel_type = @as(macho.reloc_type_x86_64, @enumFromInt(rel.r_type));
1968 if (rel_type != .X86_64_RELOC_UNSIGNED) continue;1968 if (rel_type != .X86_64_RELOC_UNSIGNED) continue;
1969 if (rel.r_length != 3) continue;1969 if (rel.r_length != 3) continue;
1970 },1970 },
...@@ -1983,11 +1983,11 @@ pub const Zld = struct {...@@ -1983,11 +1983,11 @@ pub const Zld = struct {
1983 if (!bind_sym.undf()) continue;1983 if (!bind_sym.undf()) continue;
19841984
1985 const base_offset = sym.n_value - segment.vmaddr;1985 const base_offset = sym.n_value - segment.vmaddr;
1986 const rel_offset = @intCast(u32, rel.r_address - ctx.base_offset);1986 const rel_offset = @as(u32, @intCast(rel.r_address - ctx.base_offset));
1987 const offset = @intCast(u64, base_offset + rel_offset);1987 const offset = @as(u64, @intCast(base_offset + rel_offset));
1988 const addend = mem.readIntLittle(i64, code[rel_offset..][0..8]);1988 const addend = mem.readIntLittle(i64, code[rel_offset..][0..8]);
19891989
1990 const dylib_ordinal = @divTrunc(@bitCast(i16, bind_sym.n_desc), macho.N_SYMBOL_RESOLVER);1990 const dylib_ordinal = @divTrunc(@as(i16, @bitCast(bind_sym.n_desc)), macho.N_SYMBOL_RESOLVER);
1991 log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{1991 log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{
1992 base_offset,1992 base_offset,
1993 bind_sym_name,1993 bind_sym_name,
...@@ -2039,7 +2039,7 @@ pub const Zld = struct {...@@ -2039,7 +2039,7 @@ pub const Zld = struct {
2039 const stub_entry = self.stubs.items[count];2039 const stub_entry = self.stubs.items[count];
2040 const bind_sym = stub_entry.getTargetSymbol(self);2040 const bind_sym = stub_entry.getTargetSymbol(self);
2041 const bind_sym_name = stub_entry.getTargetSymbolName(self);2041 const bind_sym_name = stub_entry.getTargetSymbolName(self);
2042 const dylib_ordinal = @divTrunc(@bitCast(i16, bind_sym.n_desc), macho.N_SYMBOL_RESOLVER);2042 const dylib_ordinal = @divTrunc(@as(i16, @bitCast(bind_sym.n_desc)), macho.N_SYMBOL_RESOLVER);
2043 log.debug(" | lazy bind at {x}, import('{s}') in dylib({d})", .{2043 log.debug(" | lazy bind at {x}, import('{s}') in dylib({d})", .{
2044 base_offset,2044 base_offset,
2045 bind_sym_name,2045 bind_sym_name,
...@@ -2165,14 +2165,14 @@ pub const Zld = struct {...@@ -2165,14 +2165,14 @@ pub const Zld = struct {
2165 try self.file.pwriteAll(buffer, rebase_off);2165 try self.file.pwriteAll(buffer, rebase_off);
2166 try self.populateLazyBindOffsetsInStubHelper(lazy_bind);2166 try self.populateLazyBindOffsetsInStubHelper(lazy_bind);
21672167
2168 self.dyld_info_cmd.rebase_off = @intCast(u32, rebase_off);2168 self.dyld_info_cmd.rebase_off = @as(u32, @intCast(rebase_off));
2169 self.dyld_info_cmd.rebase_size = @intCast(u32, rebase_size_aligned);2169 self.dyld_info_cmd.rebase_size = @as(u32, @intCast(rebase_size_aligned));
2170 self.dyld_info_cmd.bind_off = @intCast(u32, bind_off);2170 self.dyld_info_cmd.bind_off = @as(u32, @intCast(bind_off));
2171 self.dyld_info_cmd.bind_size = @intCast(u32, bind_size_aligned);2171 self.dyld_info_cmd.bind_size = @as(u32, @intCast(bind_size_aligned));
2172 self.dyld_info_cmd.lazy_bind_off = @intCast(u32, lazy_bind_off);2172 self.dyld_info_cmd.lazy_bind_off = @as(u32, @intCast(lazy_bind_off));
2173 self.dyld_info_cmd.lazy_bind_size = @intCast(u32, lazy_bind_size_aligned);2173 self.dyld_info_cmd.lazy_bind_size = @as(u32, @intCast(lazy_bind_size_aligned));
2174 self.dyld_info_cmd.export_off = @intCast(u32, export_off);2174 self.dyld_info_cmd.export_off = @as(u32, @intCast(export_off));
2175 self.dyld_info_cmd.export_size = @intCast(u32, export_size_aligned);2175 self.dyld_info_cmd.export_size = @as(u32, @intCast(export_size_aligned));
2176 }2176 }
21772177
2178 fn populateLazyBindOffsetsInStubHelper(self: *Zld, lazy_bind: LazyBind) !void {2178 fn populateLazyBindOffsetsInStubHelper(self: *Zld, lazy_bind: LazyBind) !void {
...@@ -2246,7 +2246,7 @@ pub const Zld = struct {...@@ -2246,7 +2246,7 @@ pub const Zld = struct {
22462246
2247 var last_off: u32 = 0;2247 var last_off: u32 = 0;
2248 for (addresses.items) |addr| {2248 for (addresses.items) |addr| {
2249 const offset = @intCast(u32, addr - text_seg.vmaddr);2249 const offset = @as(u32, @intCast(addr - text_seg.vmaddr));
2250 const diff = offset - last_off;2250 const diff = offset - last_off;
22512251
2252 if (diff == 0) continue;2252 if (diff == 0) continue;
...@@ -2258,7 +2258,7 @@ pub const Zld = struct {...@@ -2258,7 +2258,7 @@ pub const Zld = struct {
2258 var buffer = std.ArrayList(u8).init(gpa);2258 var buffer = std.ArrayList(u8).init(gpa);
2259 defer buffer.deinit();2259 defer buffer.deinit();
22602260
2261 const max_size = @intCast(usize, offsets.items.len * @sizeOf(u64));2261 const max_size = @as(usize, @intCast(offsets.items.len * @sizeOf(u64)));
2262 try buffer.ensureTotalCapacity(max_size);2262 try buffer.ensureTotalCapacity(max_size);
22632263
2264 for (offsets.items) |offset| {2264 for (offsets.items) |offset| {
...@@ -2281,8 +2281,8 @@ pub const Zld = struct {...@@ -2281,8 +2281,8 @@ pub const Zld = struct {
22812281
2282 try self.file.pwriteAll(buffer.items, offset);2282 try self.file.pwriteAll(buffer.items, offset);
22832283
2284 self.function_starts_cmd.dataoff = @intCast(u32, offset);2284 self.function_starts_cmd.dataoff = @as(u32, @intCast(offset));
2285 self.function_starts_cmd.datasize = @intCast(u32, needed_size_aligned);2285 self.function_starts_cmd.datasize = @as(u32, @intCast(needed_size_aligned));
2286 }2286 }
22872287
2288 fn filterDataInCode(2288 fn filterDataInCode(
...@@ -2324,8 +2324,8 @@ pub const Zld = struct {...@@ -2324,8 +2324,8 @@ pub const Zld = struct {
2324 const source_addr = if (object.getSourceSymbol(atom.sym_index)) |source_sym|2324 const source_addr = if (object.getSourceSymbol(atom.sym_index)) |source_sym|
2325 source_sym.n_value2325 source_sym.n_value
2326 else blk: {2326 else blk: {
2327 const nbase = @intCast(u32, object.in_symtab.?.len);2327 const nbase = @as(u32, @intCast(object.in_symtab.?.len));
2328 const source_sect_id = @intCast(u8, atom.sym_index - nbase);2328 const source_sect_id = @as(u8, @intCast(atom.sym_index - nbase));
2329 break :blk object.getSourceSection(source_sect_id).addr;2329 break :blk object.getSourceSection(source_sect_id).addr;
2330 };2330 };
2331 const filtered_dice = filterDataInCode(dice, source_addr, source_addr + atom.size);2331 const filtered_dice = filterDataInCode(dice, source_addr, source_addr + atom.size);
...@@ -2363,8 +2363,8 @@ pub const Zld = struct {...@@ -2363,8 +2363,8 @@ pub const Zld = struct {
23632363
2364 try self.file.pwriteAll(buffer, offset);2364 try self.file.pwriteAll(buffer, offset);
23652365
2366 self.data_in_code_cmd.dataoff = @intCast(u32, offset);2366 self.data_in_code_cmd.dataoff = @as(u32, @intCast(offset));
2367 self.data_in_code_cmd.datasize = @intCast(u32, needed_size_aligned);2367 self.data_in_code_cmd.datasize = @as(u32, @intCast(needed_size_aligned));
2368 }2368 }
23692369
2370 fn writeSymtabs(self: *Zld) !void {2370 fn writeSymtabs(self: *Zld) !void {
...@@ -2428,7 +2428,7 @@ pub const Zld = struct {...@@ -2428,7 +2428,7 @@ pub const Zld = struct {
2428 if (!sym.undf()) continue; // not an import, skip2428 if (!sym.undf()) continue; // not an import, skip
2429 if (sym.n_desc == N_DEAD) continue;2429 if (sym.n_desc == N_DEAD) continue;
24302430
2431 const new_index = @intCast(u32, imports.items.len);2431 const new_index = @as(u32, @intCast(imports.items.len));
2432 var out_sym = sym;2432 var out_sym = sym;
2433 out_sym.n_strx = try self.strtab.insert(gpa, self.getSymbolName(global));2433 out_sym.n_strx = try self.strtab.insert(gpa, self.getSymbolName(global));
2434 try imports.append(out_sym);2434 try imports.append(out_sym);
...@@ -2443,9 +2443,9 @@ pub const Zld = struct {...@@ -2443,9 +2443,9 @@ pub const Zld = struct {
2443 }2443 }
2444 }2444 }
24452445
2446 const nlocals = @intCast(u32, locals.items.len);2446 const nlocals = @as(u32, @intCast(locals.items.len));
2447 const nexports = @intCast(u32, exports.items.len);2447 const nexports = @as(u32, @intCast(exports.items.len));
2448 const nimports = @intCast(u32, imports.items.len);2448 const nimports = @as(u32, @intCast(imports.items.len));
2449 const nsyms = nlocals + nexports + nimports;2449 const nsyms = nlocals + nexports + nimports;
24502450
2451 const seg = self.getLinkeditSegmentPtr();2451 const seg = self.getLinkeditSegmentPtr();
...@@ -2465,7 +2465,7 @@ pub const Zld = struct {...@@ -2465,7 +2465,7 @@ pub const Zld = struct {
2465 log.debug("writing symtab from 0x{x} to 0x{x}", .{ offset, offset + needed_size });2465 log.debug("writing symtab from 0x{x} to 0x{x}", .{ offset, offset + needed_size });
2466 try self.file.pwriteAll(buffer.items, offset);2466 try self.file.pwriteAll(buffer.items, offset);
24672467
2468 self.symtab_cmd.symoff = @intCast(u32, offset);2468 self.symtab_cmd.symoff = @as(u32, @intCast(offset));
2469 self.symtab_cmd.nsyms = nsyms;2469 self.symtab_cmd.nsyms = nsyms;
24702470
2471 return SymtabCtx{2471 return SymtabCtx{
...@@ -2493,8 +2493,8 @@ pub const Zld = struct {...@@ -2493,8 +2493,8 @@ pub const Zld = struct {
24932493
2494 try self.file.pwriteAll(buffer, offset);2494 try self.file.pwriteAll(buffer, offset);
24952495
2496 self.symtab_cmd.stroff = @intCast(u32, offset);2496 self.symtab_cmd.stroff = @as(u32, @intCast(offset));
2497 self.symtab_cmd.strsize = @intCast(u32, needed_size_aligned);2497 self.symtab_cmd.strsize = @as(u32, @intCast(needed_size_aligned));
2498 }2498 }
24992499
2500 const SymtabCtx = struct {2500 const SymtabCtx = struct {
...@@ -2506,8 +2506,8 @@ pub const Zld = struct {...@@ -2506,8 +2506,8 @@ pub const Zld = struct {
25062506
2507 fn writeDysymtab(self: *Zld, ctx: SymtabCtx) !void {2507 fn writeDysymtab(self: *Zld, ctx: SymtabCtx) !void {
2508 const gpa = self.gpa;2508 const gpa = self.gpa;
2509 const nstubs = @intCast(u32, self.stubs.items.len);2509 const nstubs = @as(u32, @intCast(self.stubs.items.len));
2510 const ngot_entries = @intCast(u32, self.got_entries.items.len);2510 const ngot_entries = @as(u32, @intCast(self.got_entries.items.len));
2511 const nindirectsyms = nstubs * 2 + ngot_entries;2511 const nindirectsyms = nstubs * 2 + ngot_entries;
2512 const iextdefsym = ctx.nlocalsym;2512 const iextdefsym = ctx.nlocalsym;
2513 const iundefsym = iextdefsym + ctx.nextdefsym;2513 const iundefsym = iextdefsym + ctx.nextdefsym;
...@@ -2572,7 +2572,7 @@ pub const Zld = struct {...@@ -2572,7 +2572,7 @@ pub const Zld = struct {
2572 self.dysymtab_cmd.nextdefsym = ctx.nextdefsym;2572 self.dysymtab_cmd.nextdefsym = ctx.nextdefsym;
2573 self.dysymtab_cmd.iundefsym = iundefsym;2573 self.dysymtab_cmd.iundefsym = iundefsym;
2574 self.dysymtab_cmd.nundefsym = ctx.nundefsym;2574 self.dysymtab_cmd.nundefsym = ctx.nundefsym;
2575 self.dysymtab_cmd.indirectsymoff = @intCast(u32, offset);2575 self.dysymtab_cmd.indirectsymoff = @as(u32, @intCast(offset));
2576 self.dysymtab_cmd.nindirectsyms = nindirectsyms;2576 self.dysymtab_cmd.nindirectsyms = nindirectsyms;
2577 }2577 }
25782578
...@@ -2599,8 +2599,8 @@ pub const Zld = struct {...@@ -2599,8 +2599,8 @@ pub const Zld = struct {
2599 // except for code signature data.2599 // except for code signature data.
2600 try self.file.pwriteAll(&[_]u8{0}, offset + needed_size - 1);2600 try self.file.pwriteAll(&[_]u8{0}, offset + needed_size - 1);
26012601
2602 self.codesig_cmd.dataoff = @intCast(u32, offset);2602 self.codesig_cmd.dataoff = @as(u32, @intCast(offset));
2603 self.codesig_cmd.datasize = @intCast(u32, needed_size);2603 self.codesig_cmd.datasize = @as(u32, @intCast(needed_size));
2604 }2604 }
26052605
2606 fn writeCodeSignature(self: *Zld, comp: *const Compilation, code_sig: *CodeSignature) !void {2606 fn writeCodeSignature(self: *Zld, comp: *const Compilation, code_sig: *CodeSignature) !void {
...@@ -2689,7 +2689,7 @@ pub const Zld = struct {...@@ -2689,7 +2689,7 @@ pub const Zld = struct {
26892689
2690 fn getSegmentByName(self: Zld, segname: []const u8) ?u8 {2690 fn getSegmentByName(self: Zld, segname: []const u8) ?u8 {
2691 for (self.segments.items, 0..) |seg, i| {2691 for (self.segments.items, 0..) |seg, i| {
2692 if (mem.eql(u8, segname, seg.segName())) return @intCast(u8, i);2692 if (mem.eql(u8, segname, seg.segName())) return @as(u8, @intCast(i));
2693 } else return null;2693 } else return null;
2694 }2694 }
26952695
...@@ -2714,15 +2714,15 @@ pub const Zld = struct {...@@ -2714,15 +2714,15 @@ pub const Zld = struct {
2714 // TODO investigate caching with a hashmap2714 // TODO investigate caching with a hashmap
2715 for (self.sections.items(.header), 0..) |header, i| {2715 for (self.sections.items(.header), 0..) |header, i| {
2716 if (mem.eql(u8, header.segName(), segname) and mem.eql(u8, header.sectName(), sectname))2716 if (mem.eql(u8, header.segName(), segname) and mem.eql(u8, header.sectName(), sectname))
2717 return @intCast(u8, i);2717 return @as(u8, @intCast(i));
2718 } else return null;2718 } else return null;
2719 }2719 }
27202720
2721 pub fn getSectionIndexes(self: Zld, segment_index: u8) struct { start: u8, end: u8 } {2721 pub fn getSectionIndexes(self: Zld, segment_index: u8) struct { start: u8, end: u8 } {
2722 var start: u8 = 0;2722 var start: u8 = 0;
2723 const nsects = for (self.segments.items, 0..) |seg, i| {2723 const nsects = for (self.segments.items, 0..) |seg, i| {
2724 if (i == segment_index) break @intCast(u8, seg.nsects);2724 if (i == segment_index) break @as(u8, @intCast(seg.nsects));
2725 start += @intCast(u8, seg.nsects);2725 start += @as(u8, @intCast(seg.nsects));
2726 } else 0;2726 } else 0;
2727 return .{ .start = start, .end = start + nsects };2727 return .{ .start = start, .end = start + nsects };
2728 }2728 }
...@@ -2879,7 +2879,7 @@ pub const Zld = struct {...@@ -2879,7 +2879,7 @@ pub const Zld = struct {
2879 var name_lookup: ?DwarfInfo.SubprogramLookupByName = if (object.header.flags & macho.MH_SUBSECTIONS_VIA_SYMBOLS == 0) blk: {2879 var name_lookup: ?DwarfInfo.SubprogramLookupByName = if (object.header.flags & macho.MH_SUBSECTIONS_VIA_SYMBOLS == 0) blk: {
2880 var name_lookup = DwarfInfo.SubprogramLookupByName.init(gpa);2880 var name_lookup = DwarfInfo.SubprogramLookupByName.init(gpa);
2881 errdefer name_lookup.deinit();2881 errdefer name_lookup.deinit();
2882 try name_lookup.ensureUnusedCapacity(@intCast(u32, object.atoms.items.len));2882 try name_lookup.ensureUnusedCapacity(@as(u32, @intCast(object.atoms.items.len)));
2883 try debug_info.genSubprogramLookupByName(compile_unit, lookup, &name_lookup);2883 try debug_info.genSubprogramLookupByName(compile_unit, lookup, &name_lookup);
2884 break :blk name_lookup;2884 break :blk name_lookup;
2885 } else null;2885 } else null;
...@@ -3069,7 +3069,7 @@ pub const Zld = struct {...@@ -3069,7 +3069,7 @@ pub const Zld = struct {
3069 @memset(&buf, '_');3069 @memset(&buf, '_');
3070 scoped_log.debug(" %{d}: {s} @{x} in sect({d}), {s}", .{3070 scoped_log.debug(" %{d}: {s} @{x} in sect({d}), {s}", .{
3071 sym_id,3071 sym_id,
3072 object.getSymbolName(@intCast(u32, sym_id)),3072 object.getSymbolName(@as(u32, @intCast(sym_id))),
3073 sym.n_value,3073 sym.n_value,
3074 sym.n_sect,3074 sym.n_sect,
3075 logSymAttributes(sym, &buf),3075 logSymAttributes(sym, &buf),
...@@ -3252,7 +3252,7 @@ pub const Zld = struct {...@@ -3252,7 +3252,7 @@ pub const Zld = struct {
3252 }3252 }
3253};3253};
32543254
3255pub const N_DEAD: u16 = @bitCast(u16, @as(i16, -1));3255pub const N_DEAD: u16 = @as(u16, @bitCast(@as(i16, -1)));
32563256
3257const Section = struct {3257const Section = struct {
3258 header: macho.section_64,3258 header: macho.section_64,
...@@ -3791,7 +3791,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr...@@ -3791,7 +3791,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
3791 }3791 }
37923792
3793 for (zld.objects.items, 0..) |*object, object_id| {3793 for (zld.objects.items, 0..) |*object, object_id| {
3794 try object.splitIntoAtoms(&zld, @intCast(u32, object_id));3794 try object.splitIntoAtoms(&zld, @as(u32, @intCast(object_id)));
3795 }3795 }
37963796
3797 if (gc_sections) {3797 if (gc_sections) {
...@@ -3929,7 +3929,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr...@@ -3929,7 +3929,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
3929 } else sym.n_value;3929 } else sym.n_value;
39303930
3931 try lc_writer.writeStruct(macho.entry_point_command{3931 try lc_writer.writeStruct(macho.entry_point_command{
3932 .entryoff = @intCast(u32, addr - seg.vmaddr),3932 .entryoff = @as(u32, @intCast(addr - seg.vmaddr)),
3933 .stacksize = options.stack_size_override orelse 0,3933 .stacksize = options.stack_size_override orelse 0,
3934 });3934 });
3935 } else {3935 } else {
...@@ -3943,7 +3943,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr...@@ -3943,7 +3943,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
3943 });3943 });
3944 try load_commands.writeBuildVersionLC(zld.options, lc_writer);3944 try load_commands.writeBuildVersionLC(zld.options, lc_writer);
39453945
3946 const uuid_cmd_offset = @sizeOf(macho.mach_header_64) + @intCast(u32, lc_buffer.items.len);3946 const uuid_cmd_offset = @sizeOf(macho.mach_header_64) + @as(u32, @intCast(lc_buffer.items.len));
3947 try lc_writer.writeStruct(zld.uuid_cmd);3947 try lc_writer.writeStruct(zld.uuid_cmd);
39483948
3949 try load_commands.writeLoadDylibLCs(zld.dylibs.items, zld.referenced_dylibs.keys(), lc_writer);3949 try load_commands.writeLoadDylibLCs(zld.dylibs.items, zld.referenced_dylibs.keys(), lc_writer);
...@@ -3954,7 +3954,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr...@@ -3954,7 +3954,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
39543954
3955 const ncmds = load_commands.calcNumOfLCs(lc_buffer.items);3955 const ncmds = load_commands.calcNumOfLCs(lc_buffer.items);
3956 try zld.file.pwriteAll(lc_buffer.items, @sizeOf(macho.mach_header_64));3956 try zld.file.pwriteAll(lc_buffer.items, @sizeOf(macho.mach_header_64));
3957 try zld.writeHeader(ncmds, @intCast(u32, lc_buffer.items.len));3957 try zld.writeHeader(ncmds, @as(u32, @intCast(lc_buffer.items.len)));
3958 try zld.writeUuid(comp, uuid_cmd_offset, requires_codesig);3958 try zld.writeUuid(comp, uuid_cmd_offset, requires_codesig);
39593959
3960 if (codesig) |*csig| {3960 if (codesig) |*csig| {
src/link/Plan9.zig+22-22
...@@ -295,7 +295,7 @@ fn putFn(self: *Plan9, decl_index: Module.Decl.Index, out: FnDeclOutput) !void {...@@ -295,7 +295,7 @@ fn putFn(self: *Plan9, decl_index: Module.Decl.Index, out: FnDeclOutput) !void {
295 .sym_index = blk: {295 .sym_index = blk: {
296 try self.syms.append(gpa, undefined);296 try self.syms.append(gpa, undefined);
297 try self.syms.append(gpa, undefined);297 try self.syms.append(gpa, undefined);
298 break :blk @intCast(u32, self.syms.items.len - 1);298 break :blk @as(u32, @intCast(self.syms.items.len - 1));
299 },299 },
300 };300 };
301 try fn_map_res.value_ptr.functions.put(gpa, decl_index, out);301 try fn_map_res.value_ptr.functions.put(gpa, decl_index, out);
...@@ -485,7 +485,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !vo...@@ -485,7 +485,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !vo
485 .ty = decl.ty,485 .ty = decl.ty,
486 .val = decl_val,486 .val = decl_val,
487 }, &code_buffer, .{ .none = {} }, .{487 }, &code_buffer, .{ .none = {} }, .{
488 .parent_atom_index = @intCast(Atom.Index, atom_idx),488 .parent_atom_index = @as(Atom.Index, @intCast(atom_idx)),
489 });489 });
490 const code = switch (res) {490 const code = switch (res) {
491 .ok => code_buffer.items,491 .ok => code_buffer.items,
...@@ -562,10 +562,10 @@ pub fn flush(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.Node) li...@@ -562,10 +562,10 @@ pub fn flush(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.Node) li
562562
563pub fn changeLine(l: *std.ArrayList(u8), delta_line: i32) !void {563pub fn changeLine(l: *std.ArrayList(u8), delta_line: i32) !void {
564 if (delta_line > 0 and delta_line < 65) {564 if (delta_line > 0 and delta_line < 65) {
565 const toappend = @intCast(u8, delta_line);565 const toappend = @as(u8, @intCast(delta_line));
566 try l.append(toappend);566 try l.append(toappend);
567 } else if (delta_line < 0 and delta_line > -65) {567 } else if (delta_line < 0 and delta_line > -65) {
568 const toadd: u8 = @intCast(u8, -delta_line + 64);568 const toadd: u8 = @as(u8, @intCast(-delta_line + 64));
569 try l.append(toadd);569 try l.append(toadd);
570 } else if (delta_line != 0) {570 } else if (delta_line != 0) {
571 try l.append(0);571 try l.append(0);
...@@ -675,7 +675,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No...@@ -675,7 +675,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
675 const out = entry.value_ptr.*;675 const out = entry.value_ptr.*;
676 {676 {
677 // connect the previous decl to the next677 // connect the previous decl to the next
678 const delta_line = @intCast(i32, out.start_line) - @intCast(i32, linecount);678 const delta_line = @as(i32, @intCast(out.start_line)) - @as(i32, @intCast(linecount));
679679
680 try changeLine(&linecountinfo, delta_line);680 try changeLine(&linecountinfo, delta_line);
681 // TODO change the pc too (maybe?)681 // TODO change the pc too (maybe?)
...@@ -692,7 +692,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No...@@ -692,7 +692,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
692 atom.offset = off;692 atom.offset = off;
693 log.debug("write text decl {*} ({}), lines {d} to {d}.;__GOT+0x{x} vaddr: 0x{x}", .{ decl, decl.name.fmt(&mod.intern_pool), out.start_line + 1, out.end_line, atom.got_index.? * 8, off });693 log.debug("write text decl {*} ({}), lines {d} to {d}.;__GOT+0x{x} vaddr: 0x{x}", .{ decl, decl.name.fmt(&mod.intern_pool), out.start_line + 1, out.end_line, atom.got_index.? * 8, off });
694 if (!self.sixtyfour_bit) {694 if (!self.sixtyfour_bit) {
695 mem.writeInt(u32, got_table[atom.got_index.? * 4 ..][0..4], @intCast(u32, off), self.base.options.target.cpu.arch.endian());695 mem.writeInt(u32, got_table[atom.got_index.? * 4 ..][0..4], @as(u32, @intCast(off)), self.base.options.target.cpu.arch.endian());
696 } else {696 } else {
697 mem.writeInt(u64, got_table[atom.got_index.? * 8 ..][0..8], off, self.base.options.target.cpu.arch.endian());697 mem.writeInt(u64, got_table[atom.got_index.? * 8 ..][0..8], off, self.base.options.target.cpu.arch.endian());
698 }698 }
...@@ -721,7 +721,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No...@@ -721,7 +721,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
721 text_i += code.len;721 text_i += code.len;
722 text_atom.offset = off;722 text_atom.offset = off;
723 if (!self.sixtyfour_bit) {723 if (!self.sixtyfour_bit) {
724 mem.writeInt(u32, got_table[text_atom.got_index.? * 4 ..][0..4], @intCast(u32, off), self.base.options.target.cpu.arch.endian());724 mem.writeInt(u32, got_table[text_atom.got_index.? * 4 ..][0..4], @as(u32, @intCast(off)), self.base.options.target.cpu.arch.endian());
725 } else {725 } else {
726 mem.writeInt(u64, got_table[text_atom.got_index.? * 8 ..][0..8], off, self.base.options.target.cpu.arch.endian());726 mem.writeInt(u64, got_table[text_atom.got_index.? * 8 ..][0..8], off, self.base.options.target.cpu.arch.endian());
727 }727 }
...@@ -749,7 +749,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No...@@ -749,7 +749,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
749 data_i += code.len;749 data_i += code.len;
750 atom.offset = off;750 atom.offset = off;
751 if (!self.sixtyfour_bit) {751 if (!self.sixtyfour_bit) {
752 mem.writeInt(u32, got_table[atom.got_index.? * 4 ..][0..4], @intCast(u32, off), self.base.options.target.cpu.arch.endian());752 mem.writeInt(u32, got_table[atom.got_index.? * 4 ..][0..4], @as(u32, @intCast(off)), self.base.options.target.cpu.arch.endian());
753 } else {753 } else {
754 mem.writeInt(u64, got_table[atom.got_index.? * 8 ..][0..8], off, self.base.options.target.cpu.arch.endian());754 mem.writeInt(u64, got_table[atom.got_index.? * 8 ..][0..8], off, self.base.options.target.cpu.arch.endian());
755 }755 }
...@@ -772,7 +772,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No...@@ -772,7 +772,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
772 data_i += code.len;772 data_i += code.len;
773 atom.offset = off;773 atom.offset = off;
774 if (!self.sixtyfour_bit) {774 if (!self.sixtyfour_bit) {
775 mem.writeInt(u32, got_table[atom.got_index.? * 4 ..][0..4], @intCast(u32, off), self.base.options.target.cpu.arch.endian());775 mem.writeInt(u32, got_table[atom.got_index.? * 4 ..][0..4], @as(u32, @intCast(off)), self.base.options.target.cpu.arch.endian());
776 } else {776 } else {
777 mem.writeInt(u64, got_table[atom.got_index.? * 8 ..][0..8], off, self.base.options.target.cpu.arch.endian());777 mem.writeInt(u64, got_table[atom.got_index.? * 8 ..][0..8], off, self.base.options.target.cpu.arch.endian());
778 }778 }
...@@ -792,7 +792,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No...@@ -792,7 +792,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
792 data_i += code.len;792 data_i += code.len;
793 data_atom.offset = off;793 data_atom.offset = off;
794 if (!self.sixtyfour_bit) {794 if (!self.sixtyfour_bit) {
795 mem.writeInt(u32, got_table[data_atom.got_index.? * 4 ..][0..4], @intCast(u32, off), self.base.options.target.cpu.arch.endian());795 mem.writeInt(u32, got_table[data_atom.got_index.? * 4 ..][0..4], @as(u32, @intCast(off)), self.base.options.target.cpu.arch.endian());
796 } else {796 } else {
797 mem.writeInt(u64, got_table[data_atom.got_index.? * 8 ..][0..8], off, self.base.options.target.cpu.arch.endian());797 mem.writeInt(u64, got_table[data_atom.got_index.? * 8 ..][0..8], off, self.base.options.target.cpu.arch.endian());
798 }798 }
...@@ -815,13 +815,13 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No...@@ -815,13 +815,13 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
815 // generate the header815 // generate the header
816 self.hdr = .{816 self.hdr = .{
817 .magic = self.magic,817 .magic = self.magic,
818 .text = @intCast(u32, text_i),818 .text = @as(u32, @intCast(text_i)),
819 .data = @intCast(u32, data_i),819 .data = @as(u32, @intCast(data_i)),
820 .syms = @intCast(u32, syms.len),820 .syms = @as(u32, @intCast(syms.len)),
821 .bss = 0,821 .bss = 0,
822 .spsz = 0,822 .spsz = 0,
823 .pcsz = @intCast(u32, linecountinfo.items.len),823 .pcsz = @as(u32, @intCast(linecountinfo.items.len)),
824 .entry = @intCast(u32, self.entry_val.?),824 .entry = @as(u32, @intCast(self.entry_val.?)),
825 };825 };
826 @memcpy(hdr_slice, self.hdr.toU8s()[0..hdr_size]);826 @memcpy(hdr_slice, self.hdr.toU8s()[0..hdr_size]);
827 // write the fat header for 64 bit entry points827 // write the fat header for 64 bit entry points
...@@ -847,13 +847,13 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No...@@ -847,13 +847,13 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
847 const code = source_atom.code.getCode(self);847 const code = source_atom.code.getCode(self);
848848
849 if (reloc.pcrel) {849 if (reloc.pcrel) {
850 const disp = @intCast(i32, target_offset) - @intCast(i32, source_atom.offset.?) - 4 - @intCast(i32, offset);850 const disp = @as(i32, @intCast(target_offset)) - @as(i32, @intCast(source_atom.offset.?)) - 4 - @as(i32, @intCast(offset));
851 mem.writeInt(i32, code[@intCast(usize, offset)..][0..4], @intCast(i32, disp), self.base.options.target.cpu.arch.endian());851 mem.writeInt(i32, code[@as(usize, @intCast(offset))..][0..4], @as(i32, @intCast(disp)), self.base.options.target.cpu.arch.endian());
852 } else {852 } else {
853 if (!self.sixtyfour_bit) {853 if (!self.sixtyfour_bit) {
854 mem.writeInt(u32, code[@intCast(usize, offset)..][0..4], @intCast(u32, target_offset + addend), self.base.options.target.cpu.arch.endian());854 mem.writeInt(u32, code[@as(usize, @intCast(offset))..][0..4], @as(u32, @intCast(target_offset + addend)), self.base.options.target.cpu.arch.endian());
855 } else {855 } else {
856 mem.writeInt(u64, code[@intCast(usize, offset)..][0..8], target_offset + addend, self.base.options.target.cpu.arch.endian());856 mem.writeInt(u64, code[@as(usize, @intCast(offset))..][0..8], target_offset + addend, self.base.options.target.cpu.arch.endian());
857 }857 }
858 }858 }
859 log.debug("relocating the address of '{s}' + {d} into '{s}' + {d} (({s}[{d}] = 0x{x} + 0x{x})", .{ target_symbol.name, addend, source_atom_symbol.name, offset, source_atom_symbol.name, offset, target_offset, addend });859 log.debug("relocating the address of '{s}' + {d} into '{s}' + {d} (({s}[{d}] = 0x{x} + 0x{x})", .{ target_symbol.name, addend, source_atom_symbol.name, offset, source_atom_symbol.name, offset, target_offset, addend });
...@@ -960,7 +960,7 @@ fn freeUnnamedConsts(self: *Plan9, decl_index: Module.Decl.Index) void {...@@ -960,7 +960,7 @@ fn freeUnnamedConsts(self: *Plan9, decl_index: Module.Decl.Index) void {
960960
961fn createAtom(self: *Plan9) !Atom.Index {961fn createAtom(self: *Plan9) !Atom.Index {
962 const gpa = self.base.allocator;962 const gpa = self.base.allocator;
963 const index = @intCast(Atom.Index, self.atoms.items.len);963 const index = @as(Atom.Index, @intCast(self.atoms.items.len));
964 const atom = try self.atoms.addOne(gpa);964 const atom = try self.atoms.addOne(gpa);
965 atom.* = .{965 atom.* = .{
966 .type = .t,966 .type = .t,
...@@ -1060,7 +1060,7 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind...@@ -1060,7 +1060,7 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind
1060 &required_alignment,1060 &required_alignment,
1061 &code_buffer,1061 &code_buffer,
1062 .none,1062 .none,
1063 .{ .parent_atom_index = @intCast(Atom.Index, atom_index) },1063 .{ .parent_atom_index = @as(Atom.Index, @intCast(atom_index)) },
1064 );1064 );
1065 const code = switch (res) {1065 const code = switch (res) {
1066 .ok => code_buffer.items,1066 .ok => code_buffer.items,
...@@ -1188,7 +1188,7 @@ pub fn writeSym(self: *Plan9, w: anytype, sym: aout.Sym) !void {...@@ -1188,7 +1188,7 @@ pub fn writeSym(self: *Plan9, w: anytype, sym: aout.Sym) !void {
1188 // log.debug("write sym{{name: {s}, value: {x}}}", .{ sym.name, sym.value });1188 // log.debug("write sym{{name: {s}, value: {x}}}", .{ sym.name, sym.value });
1189 if (sym.type == .bad) return; // we don't want to write free'd symbols1189 if (sym.type == .bad) return; // we don't want to write free'd symbols
1190 if (!self.sixtyfour_bit) {1190 if (!self.sixtyfour_bit) {
1191 try w.writeIntBig(u32, @intCast(u32, sym.value));1191 try w.writeIntBig(u32, @as(u32, @intCast(sym.value)));
1192 } else {1192 } else {
1193 try w.writeIntBig(u64, sym.value);1193 try w.writeIntBig(u64, sym.value);
1194 }1194 }
src/link/Wasm.zig+138-138
...@@ -317,7 +317,7 @@ pub const StringTable = struct {...@@ -317,7 +317,7 @@ pub const StringTable = struct {
317 }317 }
318318
319 try table.string_data.ensureUnusedCapacity(allocator, string.len + 1);319 try table.string_data.ensureUnusedCapacity(allocator, string.len + 1);
320 const offset = @intCast(u32, table.string_data.items.len);320 const offset = @as(u32, @intCast(table.string_data.items.len));
321321
322 log.debug("writing new string '{s}' at offset 0x{x}", .{ string, offset });322 log.debug("writing new string '{s}' at offset 0x{x}", .{ string, offset });
323323
...@@ -333,7 +333,7 @@ pub const StringTable = struct {...@@ -333,7 +333,7 @@ pub const StringTable = struct {
333 /// Asserts offset does not exceed bounds.333 /// Asserts offset does not exceed bounds.
334 pub fn get(table: StringTable, off: u32) []const u8 {334 pub fn get(table: StringTable, off: u32) []const u8 {
335 assert(off < table.string_data.items.len);335 assert(off < table.string_data.items.len);
336 return mem.sliceTo(@ptrCast([*:0]const u8, table.string_data.items.ptr + off), 0);336 return mem.sliceTo(@as([*:0]const u8, @ptrCast(table.string_data.items.ptr + off)), 0);
337 }337 }
338338
339 /// Returns the offset of a given string when it exists.339 /// Returns the offset of a given string when it exists.
...@@ -396,7 +396,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option...@@ -396,7 +396,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
396 // For object files we will import the stack pointer symbol396 // For object files we will import the stack pointer symbol
397 if (options.output_mode == .Obj) {397 if (options.output_mode == .Obj) {
398 symbol.setUndefined(true);398 symbol.setUndefined(true);
399 symbol.index = @intCast(u32, wasm_bin.imported_globals_count);399 symbol.index = @as(u32, @intCast(wasm_bin.imported_globals_count));
400 wasm_bin.imported_globals_count += 1;400 wasm_bin.imported_globals_count += 1;
401 try wasm_bin.imports.putNoClobber(401 try wasm_bin.imports.putNoClobber(
402 allocator,402 allocator,
...@@ -408,7 +408,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option...@@ -408,7 +408,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
408 },408 },
409 );409 );
410 } else {410 } else {
411 symbol.index = @intCast(u32, wasm_bin.imported_globals_count + wasm_bin.wasm_globals.items.len);411 symbol.index = @as(u32, @intCast(wasm_bin.imported_globals_count + wasm_bin.wasm_globals.items.len));
412 symbol.setFlag(.WASM_SYM_VISIBILITY_HIDDEN);412 symbol.setFlag(.WASM_SYM_VISIBILITY_HIDDEN);
413 const global = try wasm_bin.wasm_globals.addOne(allocator);413 const global = try wasm_bin.wasm_globals.addOne(allocator);
414 global.* = .{414 global.* = .{
...@@ -431,7 +431,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option...@@ -431,7 +431,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
431 };431 };
432 if (options.output_mode == .Obj or options.import_table) {432 if (options.output_mode == .Obj or options.import_table) {
433 symbol.setUndefined(true);433 symbol.setUndefined(true);
434 symbol.index = @intCast(u32, wasm_bin.imported_tables_count);434 symbol.index = @as(u32, @intCast(wasm_bin.imported_tables_count));
435 wasm_bin.imported_tables_count += 1;435 wasm_bin.imported_tables_count += 1;
436 try wasm_bin.imports.put(allocator, loc, .{436 try wasm_bin.imports.put(allocator, loc, .{
437 .module_name = try wasm_bin.string_table.put(allocator, wasm_bin.host_name),437 .module_name = try wasm_bin.string_table.put(allocator, wasm_bin.host_name),
...@@ -439,7 +439,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option...@@ -439,7 +439,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
439 .kind = .{ .table = table },439 .kind = .{ .table = table },
440 });440 });
441 } else {441 } else {
442 symbol.index = @intCast(u32, wasm_bin.imported_tables_count + wasm_bin.tables.items.len);442 symbol.index = @as(u32, @intCast(wasm_bin.imported_tables_count + wasm_bin.tables.items.len));
443 try wasm_bin.tables.append(allocator, table);443 try wasm_bin.tables.append(allocator, table);
444 if (options.export_table) {444 if (options.export_table) {
445 symbol.setFlag(.WASM_SYM_EXPORTED);445 symbol.setFlag(.WASM_SYM_EXPORTED);
...@@ -519,7 +519,7 @@ fn createSyntheticSymbol(wasm: *Wasm, name: []const u8, tag: Symbol.Tag) !Symbol...@@ -519,7 +519,7 @@ fn createSyntheticSymbol(wasm: *Wasm, name: []const u8, tag: Symbol.Tag) !Symbol
519}519}
520520
521fn createSyntheticSymbolOffset(wasm: *Wasm, name_offset: u32, tag: Symbol.Tag) !SymbolLoc {521fn createSyntheticSymbolOffset(wasm: *Wasm, name_offset: u32, tag: Symbol.Tag) !SymbolLoc {
522 const sym_index = @intCast(u32, wasm.symbols.items.len);522 const sym_index = @as(u32, @intCast(wasm.symbols.items.len));
523 const loc: SymbolLoc = .{ .index = sym_index, .file = null };523 const loc: SymbolLoc = .{ .index = sym_index, .file = null };
524 try wasm.symbols.append(wasm.base.allocator, .{524 try wasm.symbols.append(wasm.base.allocator, .{
525 .name = name_offset,525 .name = name_offset,
...@@ -588,7 +588,7 @@ pub fn getOrCreateAtomForDecl(wasm: *Wasm, decl_index: Module.Decl.Index) !Atom....@@ -588,7 +588,7 @@ pub fn getOrCreateAtomForDecl(wasm: *Wasm, decl_index: Module.Decl.Index) !Atom.
588588
589/// Creates a new empty `Atom` and returns its `Atom.Index`589/// Creates a new empty `Atom` and returns its `Atom.Index`
590fn createAtom(wasm: *Wasm) !Atom.Index {590fn createAtom(wasm: *Wasm) !Atom.Index {
591 const index = @intCast(Atom.Index, wasm.managed_atoms.items.len);591 const index = @as(Atom.Index, @intCast(wasm.managed_atoms.items.len));
592 const atom = try wasm.managed_atoms.addOne(wasm.base.allocator);592 const atom = try wasm.managed_atoms.addOne(wasm.base.allocator);
593 atom.* = Atom.empty;593 atom.* = Atom.empty;
594 atom.sym_index = try wasm.allocateSymbol();594 atom.sym_index = try wasm.allocateSymbol();
...@@ -669,7 +669,7 @@ fn resolveSymbolsInObject(wasm: *Wasm, object_index: u16) !void {...@@ -669,7 +669,7 @@ fn resolveSymbolsInObject(wasm: *Wasm, object_index: u16) !void {
669 log.debug("Resolving symbols in object: '{s}'", .{object.name});669 log.debug("Resolving symbols in object: '{s}'", .{object.name});
670670
671 for (object.symtable, 0..) |symbol, i| {671 for (object.symtable, 0..) |symbol, i| {
672 const sym_index = @intCast(u32, i);672 const sym_index = @as(u32, @intCast(i));
673 const location: SymbolLoc = .{673 const location: SymbolLoc = .{
674 .file = object_index,674 .file = object_index,
675 .index = sym_index,675 .index = sym_index,
...@@ -830,7 +830,7 @@ fn resolveSymbolsInArchives(wasm: *Wasm) !void {...@@ -830,7 +830,7 @@ fn resolveSymbolsInArchives(wasm: *Wasm) !void {
830 // Symbol is found in unparsed object file within current archive.830 // Symbol is found in unparsed object file within current archive.
831 // Parse object and and resolve symbols again before we check remaining831 // Parse object and and resolve symbols again before we check remaining
832 // undefined symbols.832 // undefined symbols.
833 const object_file_index = @intCast(u16, wasm.objects.items.len);833 const object_file_index = @as(u16, @intCast(wasm.objects.items.len));
834 var object = try archive.parseObject(wasm.base.allocator, offset.items[0]);834 var object = try archive.parseObject(wasm.base.allocator, offset.items[0]);
835 try wasm.objects.append(wasm.base.allocator, object);835 try wasm.objects.append(wasm.base.allocator, object);
836 try wasm.resolveSymbolsInObject(object_file_index);836 try wasm.resolveSymbolsInObject(object_file_index);
...@@ -1046,7 +1046,7 @@ fn setupTLSRelocationsFunction(wasm: *Wasm) !void {...@@ -1046,7 +1046,7 @@ fn setupTLSRelocationsFunction(wasm: *Wasm) !void {
10461046
1047 try writer.writeByte(std.wasm.opcode(.i32_add));1047 try writer.writeByte(std.wasm.opcode(.i32_add));
1048 try writer.writeByte(std.wasm.opcode(.global_set));1048 try writer.writeByte(std.wasm.opcode(.global_set));
1049 try leb.writeULEB128(writer, wasm.imported_globals_count + @intCast(u32, wasm.wasm_globals.items.len + got_index));1049 try leb.writeULEB128(writer, wasm.imported_globals_count + @as(u32, @intCast(wasm.wasm_globals.items.len + got_index)));
1050 }1050 }
1051 try writer.writeByte(std.wasm.opcode(.end));1051 try writer.writeByte(std.wasm.opcode(.end));
10521052
...@@ -1091,7 +1091,7 @@ fn validateFeatures(...@@ -1091,7 +1091,7 @@ fn validateFeatures(
1091 // linked object file so we can test them.1091 // linked object file so we can test them.
1092 for (wasm.objects.items, 0..) |object, object_index| {1092 for (wasm.objects.items, 0..) |object, object_index| {
1093 for (object.features) |feature| {1093 for (object.features) |feature| {
1094 const value = @intCast(u16, object_index) << 1 | @as(u1, 1);1094 const value = @as(u16, @intCast(object_index)) << 1 | @as(u1, 1);
1095 switch (feature.prefix) {1095 switch (feature.prefix) {
1096 .used => {1096 .used => {
1097 used[@intFromEnum(feature.tag)] = value;1097 used[@intFromEnum(feature.tag)] = value;
...@@ -1117,12 +1117,12 @@ fn validateFeatures(...@@ -1117,12 +1117,12 @@ fn validateFeatures(
1117 // and insert it into the 'allowed' set. When features are not inferred,1117 // and insert it into the 'allowed' set. When features are not inferred,
1118 // we validate that a used feature is allowed.1118 // we validate that a used feature is allowed.
1119 for (used, 0..) |used_set, used_index| {1119 for (used, 0..) |used_set, used_index| {
1120 const is_enabled = @truncate(u1, used_set) != 0;1120 const is_enabled = @as(u1, @truncate(used_set)) != 0;
1121 if (infer) {1121 if (infer) {
1122 allowed[used_index] = is_enabled;1122 allowed[used_index] = is_enabled;
1123 emit_features_count.* += @intFromBool(is_enabled);1123 emit_features_count.* += @intFromBool(is_enabled);
1124 } else if (is_enabled and !allowed[used_index]) {1124 } else if (is_enabled and !allowed[used_index]) {
1125 log.err("feature '{}' not allowed, but used by linked object", .{@enumFromInt(types.Feature.Tag, used_index)});1125 log.err("feature '{}' not allowed, but used by linked object", .{@as(types.Feature.Tag, @enumFromInt(used_index))});
1126 log.err(" defined in '{s}'", .{wasm.objects.items[used_set >> 1].name});1126 log.err(" defined in '{s}'", .{wasm.objects.items[used_set >> 1].name});
1127 valid_feature_set = false;1127 valid_feature_set = false;
1128 }1128 }
...@@ -1134,7 +1134,7 @@ fn validateFeatures(...@@ -1134,7 +1134,7 @@ fn validateFeatures(
11341134
1135 if (wasm.base.options.shared_memory) {1135 if (wasm.base.options.shared_memory) {
1136 const disallowed_feature = disallowed[@intFromEnum(types.Feature.Tag.shared_mem)];1136 const disallowed_feature = disallowed[@intFromEnum(types.Feature.Tag.shared_mem)];
1137 if (@truncate(u1, disallowed_feature) != 0) {1137 if (@as(u1, @truncate(disallowed_feature)) != 0) {
1138 log.err(1138 log.err(
1139 "shared-memory is disallowed by '{s}' because it wasn't compiled with 'atomics' and 'bulk-memory' features enabled",1139 "shared-memory is disallowed by '{s}' because it wasn't compiled with 'atomics' and 'bulk-memory' features enabled",
1140 .{wasm.objects.items[disallowed_feature >> 1].name},1140 .{wasm.objects.items[disallowed_feature >> 1].name},
...@@ -1163,7 +1163,7 @@ fn validateFeatures(...@@ -1163,7 +1163,7 @@ fn validateFeatures(
1163 if (feature.prefix == .disallowed) continue; // already defined in 'disallowed' set.1163 if (feature.prefix == .disallowed) continue; // already defined in 'disallowed' set.
1164 // from here a feature is always used1164 // from here a feature is always used
1165 const disallowed_feature = disallowed[@intFromEnum(feature.tag)];1165 const disallowed_feature = disallowed[@intFromEnum(feature.tag)];
1166 if (@truncate(u1, disallowed_feature) != 0) {1166 if (@as(u1, @truncate(disallowed_feature)) != 0) {
1167 log.err("feature '{}' is disallowed, but used by linked object", .{feature.tag});1167 log.err("feature '{}' is disallowed, but used by linked object", .{feature.tag});
1168 log.err(" disallowed by '{s}'", .{wasm.objects.items[disallowed_feature >> 1].name});1168 log.err(" disallowed by '{s}'", .{wasm.objects.items[disallowed_feature >> 1].name});
1169 log.err(" used in '{s}'", .{object.name});1169 log.err(" used in '{s}'", .{object.name});
...@@ -1175,9 +1175,9 @@ fn validateFeatures(...@@ -1175,9 +1175,9 @@ fn validateFeatures(
11751175
1176 // validate the linked object file has each required feature1176 // validate the linked object file has each required feature
1177 for (required, 0..) |required_feature, feature_index| {1177 for (required, 0..) |required_feature, feature_index| {
1178 const is_required = @truncate(u1, required_feature) != 0;1178 const is_required = @as(u1, @truncate(required_feature)) != 0;
1179 if (is_required and !object_used_features[feature_index]) {1179 if (is_required and !object_used_features[feature_index]) {
1180 log.err("feature '{}' is required but not used in linked object", .{@enumFromInt(types.Feature.Tag, feature_index)});1180 log.err("feature '{}' is required but not used in linked object", .{@as(types.Feature.Tag, @enumFromInt(feature_index))});
1181 log.err(" required by '{s}'", .{wasm.objects.items[required_feature >> 1].name});1181 log.err(" required by '{s}'", .{wasm.objects.items[required_feature >> 1].name});
1182 log.err(" missing in '{s}'", .{object.name});1182 log.err(" missing in '{s}'", .{object.name});
1183 valid_feature_set = false;1183 valid_feature_set = false;
...@@ -1333,7 +1333,7 @@ pub fn allocateSymbol(wasm: *Wasm) !u32 {...@@ -1333,7 +1333,7 @@ pub fn allocateSymbol(wasm: *Wasm) !u32 {
1333 wasm.symbols.items[index] = symbol;1333 wasm.symbols.items[index] = symbol;
1334 return index;1334 return index;
1335 }1335 }
1336 const index = @intCast(u32, wasm.symbols.items.len);1336 const index = @as(u32, @intCast(wasm.symbols.items.len));
1337 wasm.symbols.appendAssumeCapacity(symbol);1337 wasm.symbols.appendAssumeCapacity(symbol);
1338 return index;1338 return index;
1339}1339}
...@@ -1485,7 +1485,7 @@ fn finishUpdateDecl(wasm: *Wasm, decl_index: Module.Decl.Index, code: []const u8...@@ -1485,7 +1485,7 @@ fn finishUpdateDecl(wasm: *Wasm, decl_index: Module.Decl.Index, code: []const u8
1485 try atom.code.appendSlice(wasm.base.allocator, code);1485 try atom.code.appendSlice(wasm.base.allocator, code);
1486 try wasm.resolved_symbols.put(wasm.base.allocator, atom.symbolLoc(), {});1486 try wasm.resolved_symbols.put(wasm.base.allocator, atom.symbolLoc(), {});
14871487
1488 atom.size = @intCast(u32, code.len);1488 atom.size = @as(u32, @intCast(code.len));
1489 if (code.len == 0) return;1489 if (code.len == 0) return;
1490 atom.alignment = decl.getAlignment(mod);1490 atom.alignment = decl.getAlignment(mod);
1491}1491}
...@@ -1589,7 +1589,7 @@ pub fn lowerUnnamedConst(wasm: *Wasm, tv: TypedValue, decl_index: Module.Decl.In...@@ -1589,7 +1589,7 @@ pub fn lowerUnnamedConst(wasm: *Wasm, tv: TypedValue, decl_index: Module.Decl.In
1589 };1589 };
15901590
1591 const atom = wasm.getAtomPtr(atom_index);1591 const atom = wasm.getAtomPtr(atom_index);
1592 atom.size = @intCast(u32, code.len);1592 atom.size = @as(u32, @intCast(code.len));
1593 try atom.code.appendSlice(wasm.base.allocator, code);1593 try atom.code.appendSlice(wasm.base.allocator, code);
1594 return atom.sym_index;1594 return atom.sym_index;
1595}1595}
...@@ -1617,7 +1617,7 @@ pub fn getGlobalSymbol(wasm: *Wasm, name: []const u8, lib_name: ?[]const u8) !u3...@@ -1617,7 +1617,7 @@ pub fn getGlobalSymbol(wasm: *Wasm, name: []const u8, lib_name: ?[]const u8) !u3
1617 symbol.setUndefined(true);1617 symbol.setUndefined(true);
16181618
1619 const sym_index = if (wasm.symbols_free_list.popOrNull()) |index| index else blk: {1619 const sym_index = if (wasm.symbols_free_list.popOrNull()) |index| index else blk: {
1620 var index = @intCast(u32, wasm.symbols.items.len);1620 var index = @as(u32, @intCast(wasm.symbols.items.len));
1621 try wasm.symbols.ensureUnusedCapacity(wasm.base.allocator, 1);1621 try wasm.symbols.ensureUnusedCapacity(wasm.base.allocator, 1);
1622 wasm.symbols.items.len += 1;1622 wasm.symbols.items.len += 1;
1623 break :blk index;1623 break :blk index;
...@@ -1654,15 +1654,15 @@ pub fn getDeclVAddr(...@@ -1654,15 +1654,15 @@ pub fn getDeclVAddr(
1654 try wasm.addTableFunction(target_symbol_index);1654 try wasm.addTableFunction(target_symbol_index);
1655 try atom.relocs.append(wasm.base.allocator, .{1655 try atom.relocs.append(wasm.base.allocator, .{
1656 .index = target_symbol_index,1656 .index = target_symbol_index,
1657 .offset = @intCast(u32, reloc_info.offset),1657 .offset = @as(u32, @intCast(reloc_info.offset)),
1658 .relocation_type = if (is_wasm32) .R_WASM_TABLE_INDEX_I32 else .R_WASM_TABLE_INDEX_I64,1658 .relocation_type = if (is_wasm32) .R_WASM_TABLE_INDEX_I32 else .R_WASM_TABLE_INDEX_I64,
1659 });1659 });
1660 } else {1660 } else {
1661 try atom.relocs.append(wasm.base.allocator, .{1661 try atom.relocs.append(wasm.base.allocator, .{
1662 .index = target_symbol_index,1662 .index = target_symbol_index,
1663 .offset = @intCast(u32, reloc_info.offset),1663 .offset = @as(u32, @intCast(reloc_info.offset)),
1664 .relocation_type = if (is_wasm32) .R_WASM_MEMORY_ADDR_I32 else .R_WASM_MEMORY_ADDR_I64,1664 .relocation_type = if (is_wasm32) .R_WASM_MEMORY_ADDR_I32 else .R_WASM_MEMORY_ADDR_I64,
1665 .addend = @intCast(i32, reloc_info.addend),1665 .addend = @as(i32, @intCast(reloc_info.addend)),
1666 });1666 });
1667 }1667 }
1668 // we do not know the final address at this point,1668 // we do not know the final address at this point,
...@@ -1840,7 +1840,7 @@ pub fn freeDecl(wasm: *Wasm, decl_index: Module.Decl.Index) void {...@@ -1840,7 +1840,7 @@ pub fn freeDecl(wasm: *Wasm, decl_index: Module.Decl.Index) void {
18401840
1841/// Appends a new entry to the indirect function table1841/// Appends a new entry to the indirect function table
1842pub fn addTableFunction(wasm: *Wasm, symbol_index: u32) !void {1842pub fn addTableFunction(wasm: *Wasm, symbol_index: u32) !void {
1843 const index = @intCast(u32, wasm.function_table.count());1843 const index = @as(u32, @intCast(wasm.function_table.count()));
1844 try wasm.function_table.put(wasm.base.allocator, .{ .file = null, .index = symbol_index }, index);1844 try wasm.function_table.put(wasm.base.allocator, .{ .file = null, .index = symbol_index }, index);
1845}1845}
18461846
...@@ -1971,7 +1971,7 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {...@@ -1971,7 +1971,7 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {
1971 const symbol = (SymbolLoc{ .file = null, .index = atom.sym_index }).getSymbol(wasm);1971 const symbol = (SymbolLoc{ .file = null, .index = atom.sym_index }).getSymbol(wasm);
1972 const final_index: u32 = switch (kind) {1972 const final_index: u32 = switch (kind) {
1973 .function => result: {1973 .function => result: {
1974 const index = @intCast(u32, wasm.functions.count() + wasm.imported_functions_count);1974 const index = @as(u32, @intCast(wasm.functions.count() + wasm.imported_functions_count));
1975 const type_index = wasm.atom_types.get(atom_index).?;1975 const type_index = wasm.atom_types.get(atom_index).?;
1976 try wasm.functions.putNoClobber(1976 try wasm.functions.putNoClobber(
1977 wasm.base.allocator,1977 wasm.base.allocator,
...@@ -1982,7 +1982,7 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {...@@ -1982,7 +1982,7 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {
1982 symbol.index = index;1982 symbol.index = index;
19831983
1984 if (wasm.code_section_index == null) {1984 if (wasm.code_section_index == null) {
1985 wasm.code_section_index = @intCast(u32, wasm.segments.items.len);1985 wasm.code_section_index = @as(u32, @intCast(wasm.segments.items.len));
1986 try wasm.segments.append(wasm.base.allocator, .{1986 try wasm.segments.append(wasm.base.allocator, .{
1987 .alignment = atom.alignment,1987 .alignment = atom.alignment,
1988 .size = atom.size,1988 .size = atom.size,
...@@ -2020,12 +2020,12 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {...@@ -2020,12 +2020,12 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {
2020 const index = gop.value_ptr.*;2020 const index = gop.value_ptr.*;
2021 wasm.segments.items[index].size += atom.size;2021 wasm.segments.items[index].size += atom.size;
20222022
2023 symbol.index = @intCast(u32, wasm.segment_info.getIndex(index).?);2023 symbol.index = @as(u32, @intCast(wasm.segment_info.getIndex(index).?));
2024 // segment info already exists, so free its memory2024 // segment info already exists, so free its memory
2025 wasm.base.allocator.free(segment_name);2025 wasm.base.allocator.free(segment_name);
2026 break :result index;2026 break :result index;
2027 } else {2027 } else {
2028 const index = @intCast(u32, wasm.segments.items.len);2028 const index = @as(u32, @intCast(wasm.segments.items.len));
2029 var flags: u32 = 0;2029 var flags: u32 = 0;
2030 if (wasm.base.options.shared_memory) {2030 if (wasm.base.options.shared_memory) {
2031 flags |= @intFromEnum(Segment.Flag.WASM_DATA_SEGMENT_IS_PASSIVE);2031 flags |= @intFromEnum(Segment.Flag.WASM_DATA_SEGMENT_IS_PASSIVE);
...@@ -2038,7 +2038,7 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {...@@ -2038,7 +2038,7 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {
2038 });2038 });
2039 gop.value_ptr.* = index;2039 gop.value_ptr.* = index;
20402040
2041 const info_index = @intCast(u32, wasm.segment_info.count());2041 const info_index = @as(u32, @intCast(wasm.segment_info.count()));
2042 try wasm.segment_info.put(wasm.base.allocator, index, segment_info);2042 try wasm.segment_info.put(wasm.base.allocator, index, segment_info);
2043 symbol.index = info_index;2043 symbol.index = info_index;
2044 break :result index;2044 break :result index;
...@@ -2074,13 +2074,13 @@ fn allocateDebugAtoms(wasm: *Wasm) !void {...@@ -2074,13 +2074,13 @@ fn allocateDebugAtoms(wasm: *Wasm) !void {
2074 const allocAtom = struct {2074 const allocAtom = struct {
2075 fn f(bin: *Wasm, maybe_index: *?u32, atom_index: Atom.Index) !void {2075 fn f(bin: *Wasm, maybe_index: *?u32, atom_index: Atom.Index) !void {
2076 const index = maybe_index.* orelse idx: {2076 const index = maybe_index.* orelse idx: {
2077 const index = @intCast(u32, bin.segments.items.len);2077 const index = @as(u32, @intCast(bin.segments.items.len));
2078 try bin.appendDummySegment();2078 try bin.appendDummySegment();
2079 maybe_index.* = index;2079 maybe_index.* = index;
2080 break :idx index;2080 break :idx index;
2081 };2081 };
2082 const atom = bin.getAtomPtr(atom_index);2082 const atom = bin.getAtomPtr(atom_index);
2083 atom.size = @intCast(u32, atom.code.items.len);2083 atom.size = @as(u32, @intCast(atom.code.items.len));
2084 bin.symbols.items[atom.sym_index].index = index;2084 bin.symbols.items[atom.sym_index].index = index;
2085 try bin.appendAtomAtIndex(index, atom_index);2085 try bin.appendAtomAtIndex(index, atom_index);
2086 }2086 }
...@@ -2215,7 +2215,7 @@ fn setupInitFunctions(wasm: *Wasm) !void {...@@ -2215,7 +2215,7 @@ fn setupInitFunctions(wasm: *Wasm) !void {
2215 log.debug("appended init func '{s}'\n", .{object.string_table.get(symbol.name)});2215 log.debug("appended init func '{s}'\n", .{object.string_table.get(symbol.name)});
2216 wasm.init_funcs.appendAssumeCapacity(.{2216 wasm.init_funcs.appendAssumeCapacity(.{
2217 .index = init_func.symbol_index,2217 .index = init_func.symbol_index,
2218 .file = @intCast(u16, file_index),2218 .file = @as(u16, @intCast(file_index)),
2219 .priority = init_func.priority,2219 .priority = init_func.priority,
2220 });2220 });
2221 }2221 }
...@@ -2248,7 +2248,7 @@ fn setupErrorsLen(wasm: *Wasm) !void {...@@ -2248,7 +2248,7 @@ fn setupErrorsLen(wasm: *Wasm) !void {
2248 atom.deinit(wasm);2248 atom.deinit(wasm);
2249 break :blk index;2249 break :blk index;
2250 } else new_atom: {2250 } else new_atom: {
2251 const atom_index = @intCast(Atom.Index, wasm.managed_atoms.items.len);2251 const atom_index = @as(Atom.Index, @intCast(wasm.managed_atoms.items.len));
2252 try wasm.symbol_atom.put(wasm.base.allocator, loc, atom_index);2252 try wasm.symbol_atom.put(wasm.base.allocator, loc, atom_index);
2253 try wasm.managed_atoms.append(wasm.base.allocator, undefined);2253 try wasm.managed_atoms.append(wasm.base.allocator, undefined);
2254 break :new_atom atom_index;2254 break :new_atom atom_index;
...@@ -2257,7 +2257,7 @@ fn setupErrorsLen(wasm: *Wasm) !void {...@@ -2257,7 +2257,7 @@ fn setupErrorsLen(wasm: *Wasm) !void {
2257 atom.* = Atom.empty;2257 atom.* = Atom.empty;
2258 atom.sym_index = loc.index;2258 atom.sym_index = loc.index;
2259 atom.size = 2;2259 atom.size = 2;
2260 try atom.code.writer(wasm.base.allocator).writeIntLittle(u16, @intCast(u16, errors_len));2260 try atom.code.writer(wasm.base.allocator).writeIntLittle(u16, @as(u16, @intCast(errors_len)));
22612261
2262 try wasm.parseAtom(atom_index, .{ .data = .read_only });2262 try wasm.parseAtom(atom_index, .{ .data = .read_only });
2263}2263}
...@@ -2325,7 +2325,7 @@ fn createSyntheticFunction(...@@ -2325,7 +2325,7 @@ fn createSyntheticFunction(
2325 const symbol = loc.getSymbol(wasm);2325 const symbol = loc.getSymbol(wasm);
2326 const ty_index = try wasm.putOrGetFuncType(func_ty);2326 const ty_index = try wasm.putOrGetFuncType(func_ty);
2327 // create function with above type2327 // create function with above type
2328 const func_index = wasm.imported_functions_count + @intCast(u32, wasm.functions.count());2328 const func_index = wasm.imported_functions_count + @as(u32, @intCast(wasm.functions.count()));
2329 try wasm.functions.putNoClobber(2329 try wasm.functions.putNoClobber(
2330 wasm.base.allocator,2330 wasm.base.allocator,
2331 .{ .file = null, .index = func_index },2331 .{ .file = null, .index = func_index },
...@@ -2334,10 +2334,10 @@ fn createSyntheticFunction(...@@ -2334,10 +2334,10 @@ fn createSyntheticFunction(
2334 symbol.index = func_index;2334 symbol.index = func_index;
23352335
2336 // create the atom that will be output into the final binary2336 // create the atom that will be output into the final binary
2337 const atom_index = @intCast(Atom.Index, wasm.managed_atoms.items.len);2337 const atom_index = @as(Atom.Index, @intCast(wasm.managed_atoms.items.len));
2338 const atom = try wasm.managed_atoms.addOne(wasm.base.allocator);2338 const atom = try wasm.managed_atoms.addOne(wasm.base.allocator);
2339 atom.* = .{2339 atom.* = .{
2340 .size = @intCast(u32, function_body.items.len),2340 .size = @as(u32, @intCast(function_body.items.len)),
2341 .offset = 0,2341 .offset = 0,
2342 .sym_index = loc.index,2342 .sym_index = loc.index,
2343 .file = null,2343 .file = null,
...@@ -2369,10 +2369,10 @@ pub fn createFunction(...@@ -2369,10 +2369,10 @@ pub fn createFunction(
2369) !u32 {2369) !u32 {
2370 const loc = try wasm.createSyntheticSymbol(symbol_name, .function);2370 const loc = try wasm.createSyntheticSymbol(symbol_name, .function);
23712371
2372 const atom_index = @intCast(Atom.Index, wasm.managed_atoms.items.len);2372 const atom_index = @as(Atom.Index, @intCast(wasm.managed_atoms.items.len));
2373 const atom = try wasm.managed_atoms.addOne(wasm.base.allocator);2373 const atom = try wasm.managed_atoms.addOne(wasm.base.allocator);
2374 atom.* = .{2374 atom.* = .{
2375 .size = @intCast(u32, function_body.items.len),2375 .size = @as(u32, @intCast(function_body.items.len)),
2376 .offset = 0,2376 .offset = 0,
2377 .sym_index = loc.index,2377 .sym_index = loc.index,
2378 .file = null,2378 .file = null,
...@@ -2386,7 +2386,7 @@ pub fn createFunction(...@@ -2386,7 +2386,7 @@ pub fn createFunction(
2386 symbol.setFlag(.WASM_SYM_VISIBILITY_HIDDEN); // ensure function does not get exported2386 symbol.setFlag(.WASM_SYM_VISIBILITY_HIDDEN); // ensure function does not get exported
23872387
2388 const section_index = wasm.code_section_index orelse idx: {2388 const section_index = wasm.code_section_index orelse idx: {
2389 const index = @intCast(u32, wasm.segments.items.len);2389 const index = @as(u32, @intCast(wasm.segments.items.len));
2390 try wasm.appendDummySegment();2390 try wasm.appendDummySegment();
2391 break :idx index;2391 break :idx index;
2392 };2392 };
...@@ -2438,7 +2438,7 @@ fn initializeTLSFunction(wasm: *Wasm) !void {...@@ -2438,7 +2438,7 @@ fn initializeTLSFunction(wasm: *Wasm) !void {
2438 try writer.writeByte(std.wasm.opcode(.misc_prefix));2438 try writer.writeByte(std.wasm.opcode(.misc_prefix));
2439 try leb.writeULEB128(writer, std.wasm.miscOpcode(.memory_init));2439 try leb.writeULEB128(writer, std.wasm.miscOpcode(.memory_init));
2440 // segment immediate2440 // segment immediate
2441 try leb.writeULEB128(writer, @intCast(u32, data_index));2441 try leb.writeULEB128(writer, @as(u32, @intCast(data_index)));
2442 // memory index immediate (always 0)2442 // memory index immediate (always 0)
2443 try leb.writeULEB128(writer, @as(u32, 0));2443 try leb.writeULEB128(writer, @as(u32, 0));
2444 }2444 }
...@@ -2567,16 +2567,16 @@ fn mergeSections(wasm: *Wasm) !void {...@@ -2567,16 +2567,16 @@ fn mergeSections(wasm: *Wasm) !void {
2567 if (!gop.found_existing) {2567 if (!gop.found_existing) {
2568 gop.value_ptr.* = object.functions[index];2568 gop.value_ptr.* = object.functions[index];
2569 }2569 }
2570 symbol.index = @intCast(u32, gop.index) + wasm.imported_functions_count;2570 symbol.index = @as(u32, @intCast(gop.index)) + wasm.imported_functions_count;
2571 },2571 },
2572 .global => {2572 .global => {
2573 const original_global = object.globals[index];2573 const original_global = object.globals[index];
2574 symbol.index = @intCast(u32, wasm.wasm_globals.items.len) + wasm.imported_globals_count;2574 symbol.index = @as(u32, @intCast(wasm.wasm_globals.items.len)) + wasm.imported_globals_count;
2575 try wasm.wasm_globals.append(wasm.base.allocator, original_global);2575 try wasm.wasm_globals.append(wasm.base.allocator, original_global);
2576 },2576 },
2577 .table => {2577 .table => {
2578 const original_table = object.tables[index];2578 const original_table = object.tables[index];
2579 symbol.index = @intCast(u32, wasm.tables.items.len) + wasm.imported_tables_count;2579 symbol.index = @as(u32, @intCast(wasm.tables.items.len)) + wasm.imported_tables_count;
2580 try wasm.tables.append(wasm.base.allocator, original_table);2580 try wasm.tables.append(wasm.base.allocator, original_table);
2581 },2581 },
2582 else => unreachable,2582 else => unreachable,
...@@ -2596,7 +2596,7 @@ fn mergeTypes(wasm: *Wasm) !void {...@@ -2596,7 +2596,7 @@ fn mergeTypes(wasm: *Wasm) !void {
2596 // type inserted. If we do this for the same function multiple times,2596 // type inserted. If we do this for the same function multiple times,
2597 // it will be overwritten with the incorrect type.2597 // it will be overwritten with the incorrect type.
2598 var dirty = std.AutoHashMap(u32, void).init(wasm.base.allocator);2598 var dirty = std.AutoHashMap(u32, void).init(wasm.base.allocator);
2599 try dirty.ensureUnusedCapacity(@intCast(u32, wasm.functions.count()));2599 try dirty.ensureUnusedCapacity(@as(u32, @intCast(wasm.functions.count())));
2600 defer dirty.deinit();2600 defer dirty.deinit();
26012601
2602 for (wasm.resolved_symbols.keys()) |sym_loc| {2602 for (wasm.resolved_symbols.keys()) |sym_loc| {
...@@ -2660,10 +2660,10 @@ fn setupExports(wasm: *Wasm) !void {...@@ -2660,10 +2660,10 @@ fn setupExports(wasm: *Wasm) !void {
2660 break :blk try wasm.string_table.put(wasm.base.allocator, sym_name);2660 break :blk try wasm.string_table.put(wasm.base.allocator, sym_name);
2661 };2661 };
2662 const exp: types.Export = if (symbol.tag == .data) exp: {2662 const exp: types.Export = if (symbol.tag == .data) exp: {
2663 const global_index = @intCast(u32, wasm.imported_globals_count + wasm.wasm_globals.items.len);2663 const global_index = @as(u32, @intCast(wasm.imported_globals_count + wasm.wasm_globals.items.len));
2664 try wasm.wasm_globals.append(wasm.base.allocator, .{2664 try wasm.wasm_globals.append(wasm.base.allocator, .{
2665 .global_type = .{ .valtype = .i32, .mutable = false },2665 .global_type = .{ .valtype = .i32, .mutable = false },
2666 .init = .{ .i32_const = @intCast(i32, symbol.virtual_address) },2666 .init = .{ .i32_const = @as(i32, @intCast(symbol.virtual_address)) },
2667 });2667 });
2668 break :exp .{2668 break :exp .{
2669 .name = export_name,2669 .name = export_name,
...@@ -2734,10 +2734,10 @@ fn setupMemory(wasm: *Wasm) !void {...@@ -2734,10 +2734,10 @@ fn setupMemory(wasm: *Wasm) !void {
2734 memory_ptr = std.mem.alignForward(u64, memory_ptr, stack_alignment);2734 memory_ptr = std.mem.alignForward(u64, memory_ptr, stack_alignment);
2735 memory_ptr += stack_size;2735 memory_ptr += stack_size;
2736 // We always put the stack pointer global at index 02736 // We always put the stack pointer global at index 0
2737 wasm.wasm_globals.items[0].init.i32_const = @bitCast(i32, @intCast(u32, memory_ptr));2737 wasm.wasm_globals.items[0].init.i32_const = @as(i32, @bitCast(@as(u32, @intCast(memory_ptr))));
2738 }2738 }
27392739
2740 var offset: u32 = @intCast(u32, memory_ptr);2740 var offset: u32 = @as(u32, @intCast(memory_ptr));
2741 var data_seg_it = wasm.data_segments.iterator();2741 var data_seg_it = wasm.data_segments.iterator();
2742 while (data_seg_it.next()) |entry| {2742 while (data_seg_it.next()) |entry| {
2743 const segment = &wasm.segments.items[entry.value_ptr.*];2743 const segment = &wasm.segments.items[entry.value_ptr.*];
...@@ -2747,26 +2747,26 @@ fn setupMemory(wasm: *Wasm) !void {...@@ -2747,26 +2747,26 @@ fn setupMemory(wasm: *Wasm) !void {
2747 if (mem.eql(u8, entry.key_ptr.*, ".tdata")) {2747 if (mem.eql(u8, entry.key_ptr.*, ".tdata")) {
2748 if (wasm.findGlobalSymbol("__tls_size")) |loc| {2748 if (wasm.findGlobalSymbol("__tls_size")) |loc| {
2749 const sym = loc.getSymbol(wasm);2749 const sym = loc.getSymbol(wasm);
2750 sym.index = @intCast(u32, wasm.wasm_globals.items.len) + wasm.imported_globals_count;2750 sym.index = @as(u32, @intCast(wasm.wasm_globals.items.len)) + wasm.imported_globals_count;
2751 try wasm.wasm_globals.append(wasm.base.allocator, .{2751 try wasm.wasm_globals.append(wasm.base.allocator, .{
2752 .global_type = .{ .valtype = .i32, .mutable = false },2752 .global_type = .{ .valtype = .i32, .mutable = false },
2753 .init = .{ .i32_const = @intCast(i32, segment.size) },2753 .init = .{ .i32_const = @as(i32, @intCast(segment.size)) },
2754 });2754 });
2755 }2755 }
2756 if (wasm.findGlobalSymbol("__tls_align")) |loc| {2756 if (wasm.findGlobalSymbol("__tls_align")) |loc| {
2757 const sym = loc.getSymbol(wasm);2757 const sym = loc.getSymbol(wasm);
2758 sym.index = @intCast(u32, wasm.wasm_globals.items.len) + wasm.imported_globals_count;2758 sym.index = @as(u32, @intCast(wasm.wasm_globals.items.len)) + wasm.imported_globals_count;
2759 try wasm.wasm_globals.append(wasm.base.allocator, .{2759 try wasm.wasm_globals.append(wasm.base.allocator, .{
2760 .global_type = .{ .valtype = .i32, .mutable = false },2760 .global_type = .{ .valtype = .i32, .mutable = false },
2761 .init = .{ .i32_const = @intCast(i32, segment.alignment) },2761 .init = .{ .i32_const = @as(i32, @intCast(segment.alignment)) },
2762 });2762 });
2763 }2763 }
2764 if (wasm.findGlobalSymbol("__tls_base")) |loc| {2764 if (wasm.findGlobalSymbol("__tls_base")) |loc| {
2765 const sym = loc.getSymbol(wasm);2765 const sym = loc.getSymbol(wasm);
2766 sym.index = @intCast(u32, wasm.wasm_globals.items.len) + wasm.imported_globals_count;2766 sym.index = @as(u32, @intCast(wasm.wasm_globals.items.len)) + wasm.imported_globals_count;
2767 try wasm.wasm_globals.append(wasm.base.allocator, .{2767 try wasm.wasm_globals.append(wasm.base.allocator, .{
2768 .global_type = .{ .valtype = .i32, .mutable = wasm.base.options.shared_memory },2768 .global_type = .{ .valtype = .i32, .mutable = wasm.base.options.shared_memory },
2769 .init = .{ .i32_const = if (wasm.base.options.shared_memory) @as(u32, 0) else @intCast(i32, memory_ptr) },2769 .init = .{ .i32_const = if (wasm.base.options.shared_memory) @as(u32, 0) else @as(i32, @intCast(memory_ptr)) },
2770 });2770 });
2771 }2771 }
2772 }2772 }
...@@ -2782,21 +2782,21 @@ fn setupMemory(wasm: *Wasm) !void {...@@ -2782,21 +2782,21 @@ fn setupMemory(wasm: *Wasm) !void {
2782 memory_ptr = mem.alignForward(u64, memory_ptr, 4);2782 memory_ptr = mem.alignForward(u64, memory_ptr, 4);
2783 const loc = try wasm.createSyntheticSymbol("__wasm_init_memory_flag", .data);2783 const loc = try wasm.createSyntheticSymbol("__wasm_init_memory_flag", .data);
2784 const sym = loc.getSymbol(wasm);2784 const sym = loc.getSymbol(wasm);
2785 sym.virtual_address = @intCast(u32, memory_ptr);2785 sym.virtual_address = @as(u32, @intCast(memory_ptr));
2786 memory_ptr += 4;2786 memory_ptr += 4;
2787 }2787 }
27882788
2789 if (!place_stack_first and !is_obj) {2789 if (!place_stack_first and !is_obj) {
2790 memory_ptr = std.mem.alignForward(u64, memory_ptr, stack_alignment);2790 memory_ptr = std.mem.alignForward(u64, memory_ptr, stack_alignment);
2791 memory_ptr += stack_size;2791 memory_ptr += stack_size;
2792 wasm.wasm_globals.items[0].init.i32_const = @bitCast(i32, @intCast(u32, memory_ptr));2792 wasm.wasm_globals.items[0].init.i32_const = @as(i32, @bitCast(@as(u32, @intCast(memory_ptr))));
2793 }2793 }
27942794
2795 // One of the linked object files has a reference to the __heap_base symbol.2795 // One of the linked object files has a reference to the __heap_base symbol.
2796 // We must set its virtual address so it can be used in relocations.2796 // We must set its virtual address so it can be used in relocations.
2797 if (wasm.findGlobalSymbol("__heap_base")) |loc| {2797 if (wasm.findGlobalSymbol("__heap_base")) |loc| {
2798 const symbol = loc.getSymbol(wasm);2798 const symbol = loc.getSymbol(wasm);
2799 symbol.virtual_address = @intCast(u32, mem.alignForward(u64, memory_ptr, heap_alignment));2799 symbol.virtual_address = @as(u32, @intCast(mem.alignForward(u64, memory_ptr, heap_alignment)));
2800 }2800 }
28012801
2802 // Setup the max amount of pages2802 // Setup the max amount of pages
...@@ -2821,12 +2821,12 @@ fn setupMemory(wasm: *Wasm) !void {...@@ -2821,12 +2821,12 @@ fn setupMemory(wasm: *Wasm) !void {
2821 memory_ptr = mem.alignForward(u64, memory_ptr, std.wasm.page_size);2821 memory_ptr = mem.alignForward(u64, memory_ptr, std.wasm.page_size);
2822 // In case we do not import memory, but define it ourselves,2822 // In case we do not import memory, but define it ourselves,
2823 // set the minimum amount of pages on the memory section.2823 // set the minimum amount of pages on the memory section.
2824 wasm.memories.limits.min = @intCast(u32, memory_ptr / page_size);2824 wasm.memories.limits.min = @as(u32, @intCast(memory_ptr / page_size));
2825 log.debug("Total memory pages: {d}", .{wasm.memories.limits.min});2825 log.debug("Total memory pages: {d}", .{wasm.memories.limits.min});
28262826
2827 if (wasm.findGlobalSymbol("__heap_end")) |loc| {2827 if (wasm.findGlobalSymbol("__heap_end")) |loc| {
2828 const symbol = loc.getSymbol(wasm);2828 const symbol = loc.getSymbol(wasm);
2829 symbol.virtual_address = @intCast(u32, memory_ptr);2829 symbol.virtual_address = @as(u32, @intCast(memory_ptr));
2830 }2830 }
28312831
2832 if (wasm.base.options.max_memory) |max_memory| {2832 if (wasm.base.options.max_memory) |max_memory| {
...@@ -2842,7 +2842,7 @@ fn setupMemory(wasm: *Wasm) !void {...@@ -2842,7 +2842,7 @@ fn setupMemory(wasm: *Wasm) !void {
2842 log.err("Maximum memory exceeds maxmium amount {d}", .{max_memory_allowed});2842 log.err("Maximum memory exceeds maxmium amount {d}", .{max_memory_allowed});
2843 return error.MemoryTooBig;2843 return error.MemoryTooBig;
2844 }2844 }
2845 wasm.memories.limits.max = @intCast(u32, max_memory / page_size);2845 wasm.memories.limits.max = @as(u32, @intCast(max_memory / page_size));
2846 wasm.memories.limits.setFlag(.WASM_LIMITS_FLAG_HAS_MAX);2846 wasm.memories.limits.setFlag(.WASM_LIMITS_FLAG_HAS_MAX);
2847 if (wasm.base.options.shared_memory) {2847 if (wasm.base.options.shared_memory) {
2848 wasm.memories.limits.setFlag(.WASM_LIMITS_FLAG_IS_SHARED);2848 wasm.memories.limits.setFlag(.WASM_LIMITS_FLAG_IS_SHARED);
...@@ -2857,7 +2857,7 @@ fn setupMemory(wasm: *Wasm) !void {...@@ -2857,7 +2857,7 @@ fn setupMemory(wasm: *Wasm) !void {
2857pub fn getMatchingSegment(wasm: *Wasm, object_index: u16, relocatable_index: u32) !?u32 {2857pub fn getMatchingSegment(wasm: *Wasm, object_index: u16, relocatable_index: u32) !?u32 {
2858 const object: Object = wasm.objects.items[object_index];2858 const object: Object = wasm.objects.items[object_index];
2859 const relocatable_data = object.relocatable_data[relocatable_index];2859 const relocatable_data = object.relocatable_data[relocatable_index];
2860 const index = @intCast(u32, wasm.segments.items.len);2860 const index = @as(u32, @intCast(wasm.segments.items.len));
28612861
2862 switch (relocatable_data.type) {2862 switch (relocatable_data.type) {
2863 .data => {2863 .data => {
...@@ -3023,10 +3023,10 @@ fn populateErrorNameTable(wasm: *Wasm) !void {...@@ -3023,10 +3023,10 @@ fn populateErrorNameTable(wasm: *Wasm) !void {
3023 const mod = wasm.base.options.module.?;3023 const mod = wasm.base.options.module.?;
3024 for (mod.global_error_set.keys()) |error_name_nts| {3024 for (mod.global_error_set.keys()) |error_name_nts| {
3025 const error_name = mod.intern_pool.stringToSlice(error_name_nts);3025 const error_name = mod.intern_pool.stringToSlice(error_name_nts);
3026 const len = @intCast(u32, error_name.len + 1); // names are 0-termianted3026 const len = @as(u32, @intCast(error_name.len + 1)); // names are 0-termianted
30273027
3028 const slice_ty = Type.slice_const_u8_sentinel_0;3028 const slice_ty = Type.slice_const_u8_sentinel_0;
3029 const offset = @intCast(u32, atom.code.items.len);3029 const offset = @as(u32, @intCast(atom.code.items.len));
3030 // first we create the data for the slice of the name3030 // first we create the data for the slice of the name
3031 try atom.code.appendNTimes(wasm.base.allocator, 0, 4); // ptr to name, will be relocated3031 try atom.code.appendNTimes(wasm.base.allocator, 0, 4); // ptr to name, will be relocated
3032 try atom.code.writer(wasm.base.allocator).writeIntLittle(u32, len - 1);3032 try atom.code.writer(wasm.base.allocator).writeIntLittle(u32, len - 1);
...@@ -3035,9 +3035,9 @@ fn populateErrorNameTable(wasm: *Wasm) !void {...@@ -3035,9 +3035,9 @@ fn populateErrorNameTable(wasm: *Wasm) !void {
3035 .index = names_atom.sym_index,3035 .index = names_atom.sym_index,
3036 .relocation_type = .R_WASM_MEMORY_ADDR_I32,3036 .relocation_type = .R_WASM_MEMORY_ADDR_I32,
3037 .offset = offset,3037 .offset = offset,
3038 .addend = @intCast(i32, addend),3038 .addend = @as(i32, @intCast(addend)),
3039 });3039 });
3040 atom.size += @intCast(u32, slice_ty.abiSize(mod));3040 atom.size += @as(u32, @intCast(slice_ty.abiSize(mod)));
3041 addend += len;3041 addend += len;
30423042
3043 // as we updated the error name table, we now store the actual name within the names atom3043 // as we updated the error name table, we now store the actual name within the names atom
...@@ -3063,7 +3063,7 @@ fn populateErrorNameTable(wasm: *Wasm) !void {...@@ -3063,7 +3063,7 @@ fn populateErrorNameTable(wasm: *Wasm) !void {
3063/// This initializes the index, appends a new segment,3063/// This initializes the index, appends a new segment,
3064/// and finally, creates a managed `Atom`.3064/// and finally, creates a managed `Atom`.
3065pub fn createDebugSectionForIndex(wasm: *Wasm, index: *?u32, name: []const u8) !Atom.Index {3065pub fn createDebugSectionForIndex(wasm: *Wasm, index: *?u32, name: []const u8) !Atom.Index {
3066 const new_index = @intCast(u32, wasm.segments.items.len);3066 const new_index = @as(u32, @intCast(wasm.segments.items.len));
3067 index.* = new_index;3067 index.* = new_index;
3068 try wasm.appendDummySegment();3068 try wasm.appendDummySegment();
30693069
...@@ -3294,7 +3294,7 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l...@@ -3294,7 +3294,7 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
3294 try wasm.parseInputFiles(positionals.items);3294 try wasm.parseInputFiles(positionals.items);
32953295
3296 for (wasm.objects.items, 0..) |_, object_index| {3296 for (wasm.objects.items, 0..) |_, object_index| {
3297 try wasm.resolveSymbolsInObject(@intCast(u16, object_index));3297 try wasm.resolveSymbolsInObject(@as(u16, @intCast(object_index)));
3298 }3298 }
32993299
3300 var emit_features_count: u32 = 0;3300 var emit_features_count: u32 = 0;
...@@ -3309,7 +3309,7 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l...@@ -3309,7 +3309,7 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
3309 try wasm.setupImports();3309 try wasm.setupImports();
33103310
3311 for (wasm.objects.items, 0..) |*object, object_index| {3311 for (wasm.objects.items, 0..) |*object, object_index| {
3312 try object.parseIntoAtoms(gpa, @intCast(u16, object_index), wasm);3312 try object.parseIntoAtoms(gpa, @as(u16, @intCast(object_index)), wasm);
3313 }3313 }
33143314
3315 try wasm.allocateAtoms();3315 try wasm.allocateAtoms();
...@@ -3382,7 +3382,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod...@@ -3382,7 +3382,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
3382 try wasm.parseInputFiles(positionals.items);3382 try wasm.parseInputFiles(positionals.items);
33833383
3384 for (wasm.objects.items, 0..) |_, object_index| {3384 for (wasm.objects.items, 0..) |_, object_index| {
3385 try wasm.resolveSymbolsInObject(@intCast(u16, object_index));3385 try wasm.resolveSymbolsInObject(@as(u16, @intCast(object_index)));
3386 }3386 }
33873387
3388 var emit_features_count: u32 = 0;3388 var emit_features_count: u32 = 0;
...@@ -3446,7 +3446,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod...@@ -3446,7 +3446,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
3446 }3446 }
34473447
3448 for (wasm.objects.items, 0..) |*object, object_index| {3448 for (wasm.objects.items, 0..) |*object, object_index| {
3449 try object.parseIntoAtoms(wasm.base.allocator, @intCast(u16, object_index), wasm);3449 try object.parseIntoAtoms(wasm.base.allocator, @as(u16, @intCast(object_index)), wasm);
3450 }3450 }
34513451
3452 try wasm.allocateAtoms();3452 try wasm.allocateAtoms();
...@@ -3497,11 +3497,11 @@ fn writeToFile(...@@ -3497,11 +3497,11 @@ fn writeToFile(
3497 log.debug("Writing type section. Count: ({d})", .{wasm.func_types.items.len});3497 log.debug("Writing type section. Count: ({d})", .{wasm.func_types.items.len});
3498 for (wasm.func_types.items) |func_type| {3498 for (wasm.func_types.items) |func_type| {
3499 try leb.writeULEB128(binary_writer, std.wasm.function_type);3499 try leb.writeULEB128(binary_writer, std.wasm.function_type);
3500 try leb.writeULEB128(binary_writer, @intCast(u32, func_type.params.len));3500 try leb.writeULEB128(binary_writer, @as(u32, @intCast(func_type.params.len)));
3501 for (func_type.params) |param_ty| {3501 for (func_type.params) |param_ty| {
3502 try leb.writeULEB128(binary_writer, std.wasm.valtype(param_ty));3502 try leb.writeULEB128(binary_writer, std.wasm.valtype(param_ty));
3503 }3503 }
3504 try leb.writeULEB128(binary_writer, @intCast(u32, func_type.returns.len));3504 try leb.writeULEB128(binary_writer, @as(u32, @intCast(func_type.returns.len)));
3505 for (func_type.returns) |ret_ty| {3505 for (func_type.returns) |ret_ty| {
3506 try leb.writeULEB128(binary_writer, std.wasm.valtype(ret_ty));3506 try leb.writeULEB128(binary_writer, std.wasm.valtype(ret_ty));
3507 }3507 }
...@@ -3511,8 +3511,8 @@ fn writeToFile(...@@ -3511,8 +3511,8 @@ fn writeToFile(
3511 binary_bytes.items,3511 binary_bytes.items,
3512 header_offset,3512 header_offset,
3513 .type,3513 .type,
3514 @intCast(u32, binary_bytes.items.len - header_offset - header_size),3514 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3515 @intCast(u32, wasm.func_types.items.len),3515 @as(u32, @intCast(wasm.func_types.items.len)),
3516 );3516 );
3517 section_count += 1;3517 section_count += 1;
3518 }3518 }
...@@ -3543,8 +3543,8 @@ fn writeToFile(...@@ -3543,8 +3543,8 @@ fn writeToFile(
3543 binary_bytes.items,3543 binary_bytes.items,
3544 header_offset,3544 header_offset,
3545 .import,3545 .import,
3546 @intCast(u32, binary_bytes.items.len - header_offset - header_size),3546 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3547 @intCast(u32, wasm.imports.count() + @intFromBool(import_memory)),3547 @as(u32, @intCast(wasm.imports.count() + @intFromBool(import_memory))),
3548 );3548 );
3549 section_count += 1;3549 section_count += 1;
3550 }3550 }
...@@ -3560,8 +3560,8 @@ fn writeToFile(...@@ -3560,8 +3560,8 @@ fn writeToFile(
3560 binary_bytes.items,3560 binary_bytes.items,
3561 header_offset,3561 header_offset,
3562 .function,3562 .function,
3563 @intCast(u32, binary_bytes.items.len - header_offset - header_size),3563 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3564 @intCast(u32, wasm.functions.count()),3564 @as(u32, @intCast(wasm.functions.count())),
3565 );3565 );
3566 section_count += 1;3566 section_count += 1;
3567 }3567 }
...@@ -3579,8 +3579,8 @@ fn writeToFile(...@@ -3579,8 +3579,8 @@ fn writeToFile(
3579 binary_bytes.items,3579 binary_bytes.items,
3580 header_offset,3580 header_offset,
3581 .table,3581 .table,
3582 @intCast(u32, binary_bytes.items.len - header_offset - header_size),3582 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3583 @intCast(u32, wasm.tables.items.len),3583 @as(u32, @intCast(wasm.tables.items.len)),
3584 );3584 );
3585 section_count += 1;3585 section_count += 1;
3586 }3586 }
...@@ -3594,7 +3594,7 @@ fn writeToFile(...@@ -3594,7 +3594,7 @@ fn writeToFile(
3594 binary_bytes.items,3594 binary_bytes.items,
3595 header_offset,3595 header_offset,
3596 .memory,3596 .memory,
3597 @intCast(u32, binary_bytes.items.len - header_offset - header_size),3597 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3598 @as(u32, 1), // wasm currently only supports 1 linear memory segment3598 @as(u32, 1), // wasm currently only supports 1 linear memory segment
3599 );3599 );
3600 section_count += 1;3600 section_count += 1;
...@@ -3614,8 +3614,8 @@ fn writeToFile(...@@ -3614,8 +3614,8 @@ fn writeToFile(
3614 binary_bytes.items,3614 binary_bytes.items,
3615 header_offset,3615 header_offset,
3616 .global,3616 .global,
3617 @intCast(u32, binary_bytes.items.len - header_offset - header_size),3617 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3618 @intCast(u32, wasm.wasm_globals.items.len),3618 @as(u32, @intCast(wasm.wasm_globals.items.len)),
3619 );3619 );
3620 section_count += 1;3620 section_count += 1;
3621 }3621 }
...@@ -3626,14 +3626,14 @@ fn writeToFile(...@@ -3626,14 +3626,14 @@ fn writeToFile(
36263626
3627 for (wasm.exports.items) |exp| {3627 for (wasm.exports.items) |exp| {
3628 const name = wasm.string_table.get(exp.name);3628 const name = wasm.string_table.get(exp.name);
3629 try leb.writeULEB128(binary_writer, @intCast(u32, name.len));3629 try leb.writeULEB128(binary_writer, @as(u32, @intCast(name.len)));
3630 try binary_writer.writeAll(name);3630 try binary_writer.writeAll(name);
3631 try leb.writeULEB128(binary_writer, @intFromEnum(exp.kind));3631 try leb.writeULEB128(binary_writer, @intFromEnum(exp.kind));
3632 try leb.writeULEB128(binary_writer, exp.index);3632 try leb.writeULEB128(binary_writer, exp.index);
3633 }3633 }
36343634
3635 if (!import_memory) {3635 if (!import_memory) {
3636 try leb.writeULEB128(binary_writer, @intCast(u32, "memory".len));3636 try leb.writeULEB128(binary_writer, @as(u32, @intCast("memory".len)));
3637 try binary_writer.writeAll("memory");3637 try binary_writer.writeAll("memory");
3638 try binary_writer.writeByte(std.wasm.externalKind(.memory));3638 try binary_writer.writeByte(std.wasm.externalKind(.memory));
3639 try leb.writeULEB128(binary_writer, @as(u32, 0));3639 try leb.writeULEB128(binary_writer, @as(u32, 0));
...@@ -3643,8 +3643,8 @@ fn writeToFile(...@@ -3643,8 +3643,8 @@ fn writeToFile(
3643 binary_bytes.items,3643 binary_bytes.items,
3644 header_offset,3644 header_offset,
3645 .@"export",3645 .@"export",
3646 @intCast(u32, binary_bytes.items.len - header_offset - header_size),3646 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3647 @intCast(u32, wasm.exports.items.len) + @intFromBool(!import_memory),3647 @as(u32, @intCast(wasm.exports.items.len)) + @intFromBool(!import_memory),
3648 );3648 );
3649 section_count += 1;3649 section_count += 1;
3650 }3650 }
...@@ -3665,7 +3665,7 @@ fn writeToFile(...@@ -3665,7 +3665,7 @@ fn writeToFile(
3665 if (flags == 0x02) {3665 if (flags == 0x02) {
3666 try leb.writeULEB128(binary_writer, @as(u8, 0)); // represents funcref3666 try leb.writeULEB128(binary_writer, @as(u8, 0)); // represents funcref
3667 }3667 }
3668 try leb.writeULEB128(binary_writer, @intCast(u32, wasm.function_table.count()));3668 try leb.writeULEB128(binary_writer, @as(u32, @intCast(wasm.function_table.count())));
3669 var symbol_it = wasm.function_table.keyIterator();3669 var symbol_it = wasm.function_table.keyIterator();
3670 while (symbol_it.next()) |symbol_loc_ptr| {3670 while (symbol_it.next()) |symbol_loc_ptr| {
3671 try leb.writeULEB128(binary_writer, symbol_loc_ptr.*.getSymbol(wasm).index);3671 try leb.writeULEB128(binary_writer, symbol_loc_ptr.*.getSymbol(wasm).index);
...@@ -3675,7 +3675,7 @@ fn writeToFile(...@@ -3675,7 +3675,7 @@ fn writeToFile(
3675 binary_bytes.items,3675 binary_bytes.items,
3676 header_offset,3676 header_offset,
3677 .element,3677 .element,
3678 @intCast(u32, binary_bytes.items.len - header_offset - header_size),3678 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3679 @as(u32, 1),3679 @as(u32, 1),
3680 );3680 );
3681 section_count += 1;3681 section_count += 1;
...@@ -3689,8 +3689,8 @@ fn writeToFile(...@@ -3689,8 +3689,8 @@ fn writeToFile(
3689 binary_bytes.items,3689 binary_bytes.items,
3690 header_offset,3690 header_offset,
3691 .data_count,3691 .data_count,
3692 @intCast(u32, binary_bytes.items.len - header_offset - header_size),3692 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3693 @intCast(u32, data_segments_count),3693 @as(u32, @intCast(data_segments_count)),
3694 );3694 );
3695 }3695 }
36963696
...@@ -3731,13 +3731,13 @@ fn writeToFile(...@@ -3731,13 +3731,13 @@ fn writeToFile(
3731 try binary_writer.writeAll(sorted_atom.code.items);3731 try binary_writer.writeAll(sorted_atom.code.items);
3732 }3732 }
37333733
3734 code_section_size = @intCast(u32, binary_bytes.items.len - header_offset - header_size);3734 code_section_size = @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size));
3735 try writeVecSectionHeader(3735 try writeVecSectionHeader(
3736 binary_bytes.items,3736 binary_bytes.items,
3737 header_offset,3737 header_offset,
3738 .code,3738 .code,
3739 code_section_size,3739 code_section_size,
3740 @intCast(u32, wasm.functions.count()),3740 @as(u32, @intCast(wasm.functions.count())),
3741 );3741 );
3742 code_section_index = section_count;3742 code_section_index = section_count;
3743 section_count += 1;3743 section_count += 1;
...@@ -3765,7 +3765,7 @@ fn writeToFile(...@@ -3765,7 +3765,7 @@ fn writeToFile(
3765 }3765 }
3766 // when a segment is passive, it's initialized during runtime.3766 // when a segment is passive, it's initialized during runtime.
3767 if (!segment.isPassive()) {3767 if (!segment.isPassive()) {
3768 try emitInit(binary_writer, .{ .i32_const = @bitCast(i32, segment.offset) });3768 try emitInit(binary_writer, .{ .i32_const = @as(i32, @bitCast(segment.offset)) });
3769 }3769 }
3770 // offset into data section3770 // offset into data section
3771 try leb.writeULEB128(binary_writer, segment.size);3771 try leb.writeULEB128(binary_writer, segment.size);
...@@ -3808,8 +3808,8 @@ fn writeToFile(...@@ -3808,8 +3808,8 @@ fn writeToFile(
3808 binary_bytes.items,3808 binary_bytes.items,
3809 header_offset,3809 header_offset,
3810 .data,3810 .data,
3811 @intCast(u32, binary_bytes.items.len - header_offset - header_size),3811 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3812 @intCast(u32, segment_count),3812 @as(u32, @intCast(segment_count)),
3813 );3813 );
3814 data_section_index = section_count;3814 data_section_index = section_count;
3815 section_count += 1;3815 section_count += 1;
...@@ -3927,7 +3927,7 @@ fn emitDebugSection(binary_bytes: *std.ArrayList(u8), data: []const u8, name: []...@@ -3927,7 +3927,7 @@ fn emitDebugSection(binary_bytes: *std.ArrayList(u8), data: []const u8, name: []
3927 if (data.len == 0) return;3927 if (data.len == 0) return;
3928 const header_offset = try reserveCustomSectionHeader(binary_bytes);3928 const header_offset = try reserveCustomSectionHeader(binary_bytes);
3929 const writer = binary_bytes.writer();3929 const writer = binary_bytes.writer();
3930 try leb.writeULEB128(writer, @intCast(u32, name.len));3930 try leb.writeULEB128(writer, @as(u32, @intCast(name.len)));
3931 try writer.writeAll(name);3931 try writer.writeAll(name);
39323932
3933 const start = binary_bytes.items.len - header_offset;3933 const start = binary_bytes.items.len - header_offset;
...@@ -3937,7 +3937,7 @@ fn emitDebugSection(binary_bytes: *std.ArrayList(u8), data: []const u8, name: []...@@ -3937,7 +3937,7 @@ fn emitDebugSection(binary_bytes: *std.ArrayList(u8), data: []const u8, name: []
3937 try writeCustomSectionHeader(3937 try writeCustomSectionHeader(
3938 binary_bytes.items,3938 binary_bytes.items,
3939 header_offset,3939 header_offset,
3940 @intCast(u32, binary_bytes.items.len - header_offset - 6),3940 @as(u32, @intCast(binary_bytes.items.len - header_offset - 6)),
3941 );3941 );
3942}3942}
39433943
...@@ -3946,7 +3946,7 @@ fn emitProducerSection(binary_bytes: *std.ArrayList(u8)) !void {...@@ -3946,7 +3946,7 @@ fn emitProducerSection(binary_bytes: *std.ArrayList(u8)) !void {
39463946
3947 const writer = binary_bytes.writer();3947 const writer = binary_bytes.writer();
3948 const producers = "producers";3948 const producers = "producers";
3949 try leb.writeULEB128(writer, @intCast(u32, producers.len));3949 try leb.writeULEB128(writer, @as(u32, @intCast(producers.len)));
3950 try writer.writeAll(producers);3950 try writer.writeAll(producers);
39513951
3952 try leb.writeULEB128(writer, @as(u32, 2)); // 2 fields: Language + processed-by3952 try leb.writeULEB128(writer, @as(u32, 2)); // 2 fields: Language + processed-by
...@@ -3958,7 +3958,7 @@ fn emitProducerSection(binary_bytes: *std.ArrayList(u8)) !void {...@@ -3958,7 +3958,7 @@ fn emitProducerSection(binary_bytes: *std.ArrayList(u8)) !void {
3958 // language field3958 // language field
3959 {3959 {
3960 const language = "language";3960 const language = "language";
3961 try leb.writeULEB128(writer, @intCast(u32, language.len));3961 try leb.writeULEB128(writer, @as(u32, @intCast(language.len)));
3962 try writer.writeAll(language);3962 try writer.writeAll(language);
39633963
3964 // field_value_count (TODO: Parse object files for producer sections to detect their language)3964 // field_value_count (TODO: Parse object files for producer sections to detect their language)
...@@ -3969,7 +3969,7 @@ fn emitProducerSection(binary_bytes: *std.ArrayList(u8)) !void {...@@ -3969,7 +3969,7 @@ fn emitProducerSection(binary_bytes: *std.ArrayList(u8)) !void {
3969 try leb.writeULEB128(writer, @as(u32, 3)); // len of "Zig"3969 try leb.writeULEB128(writer, @as(u32, 3)); // len of "Zig"
3970 try writer.writeAll("Zig");3970 try writer.writeAll("Zig");
39713971
3972 try leb.writeULEB128(writer, @intCast(u32, version.len));3972 try leb.writeULEB128(writer, @as(u32, @intCast(version.len)));
3973 try writer.writeAll(version);3973 try writer.writeAll(version);
3974 }3974 }
3975 }3975 }
...@@ -3977,7 +3977,7 @@ fn emitProducerSection(binary_bytes: *std.ArrayList(u8)) !void {...@@ -3977,7 +3977,7 @@ fn emitProducerSection(binary_bytes: *std.ArrayList(u8)) !void {
3977 // processed-by field3977 // processed-by field
3978 {3978 {
3979 const processed_by = "processed-by";3979 const processed_by = "processed-by";
3980 try leb.writeULEB128(writer, @intCast(u32, processed_by.len));3980 try leb.writeULEB128(writer, @as(u32, @intCast(processed_by.len)));
3981 try writer.writeAll(processed_by);3981 try writer.writeAll(processed_by);
39823982
3983 // field_value_count (TODO: Parse object files for producer sections to detect other used tools)3983 // field_value_count (TODO: Parse object files for producer sections to detect other used tools)
...@@ -3988,7 +3988,7 @@ fn emitProducerSection(binary_bytes: *std.ArrayList(u8)) !void {...@@ -3988,7 +3988,7 @@ fn emitProducerSection(binary_bytes: *std.ArrayList(u8)) !void {
3988 try leb.writeULEB128(writer, @as(u32, 3)); // len of "Zig"3988 try leb.writeULEB128(writer, @as(u32, 3)); // len of "Zig"
3989 try writer.writeAll("Zig");3989 try writer.writeAll("Zig");
39903990
3991 try leb.writeULEB128(writer, @intCast(u32, version.len));3991 try leb.writeULEB128(writer, @as(u32, @intCast(version.len)));
3992 try writer.writeAll(version);3992 try writer.writeAll(version);
3993 }3993 }
3994 }3994 }
...@@ -3996,7 +3996,7 @@ fn emitProducerSection(binary_bytes: *std.ArrayList(u8)) !void {...@@ -3996,7 +3996,7 @@ fn emitProducerSection(binary_bytes: *std.ArrayList(u8)) !void {
3996 try writeCustomSectionHeader(3996 try writeCustomSectionHeader(
3997 binary_bytes.items,3997 binary_bytes.items,
3998 header_offset,3998 header_offset,
3999 @intCast(u32, binary_bytes.items.len - header_offset - 6),3999 @as(u32, @intCast(binary_bytes.items.len - header_offset - 6)),
4000 );4000 );
4001}4001}
40024002
...@@ -4005,17 +4005,17 @@ fn emitBuildIdSection(binary_bytes: *std.ArrayList(u8), build_id: []const u8) !v...@@ -4005,17 +4005,17 @@ fn emitBuildIdSection(binary_bytes: *std.ArrayList(u8), build_id: []const u8) !v
40054005
4006 const writer = binary_bytes.writer();4006 const writer = binary_bytes.writer();
4007 const hdr_build_id = "build_id";4007 const hdr_build_id = "build_id";
4008 try leb.writeULEB128(writer, @intCast(u32, hdr_build_id.len));4008 try leb.writeULEB128(writer, @as(u32, @intCast(hdr_build_id.len)));
4009 try writer.writeAll(hdr_build_id);4009 try writer.writeAll(hdr_build_id);
40104010
4011 try leb.writeULEB128(writer, @as(u32, 1));4011 try leb.writeULEB128(writer, @as(u32, 1));
4012 try leb.writeULEB128(writer, @intCast(u32, build_id.len));4012 try leb.writeULEB128(writer, @as(u32, @intCast(build_id.len)));
4013 try writer.writeAll(build_id);4013 try writer.writeAll(build_id);
40144014
4015 try writeCustomSectionHeader(4015 try writeCustomSectionHeader(
4016 binary_bytes.items,4016 binary_bytes.items,
4017 header_offset,4017 header_offset,
4018 @intCast(u32, binary_bytes.items.len - header_offset - 6),4018 @as(u32, @intCast(binary_bytes.items.len - header_offset - 6)),
4019 );4019 );
4020}4020}
40214021
...@@ -4024,17 +4024,17 @@ fn emitFeaturesSection(binary_bytes: *std.ArrayList(u8), enabled_features: []con...@@ -4024,17 +4024,17 @@ fn emitFeaturesSection(binary_bytes: *std.ArrayList(u8), enabled_features: []con
40244024
4025 const writer = binary_bytes.writer();4025 const writer = binary_bytes.writer();
4026 const target_features = "target_features";4026 const target_features = "target_features";
4027 try leb.writeULEB128(writer, @intCast(u32, target_features.len));4027 try leb.writeULEB128(writer, @as(u32, @intCast(target_features.len)));
4028 try writer.writeAll(target_features);4028 try writer.writeAll(target_features);
40294029
4030 try leb.writeULEB128(writer, features_count);4030 try leb.writeULEB128(writer, features_count);
4031 for (enabled_features, 0..) |enabled, feature_index| {4031 for (enabled_features, 0..) |enabled, feature_index| {
4032 if (enabled) {4032 if (enabled) {
4033 const feature: types.Feature = .{ .prefix = .used, .tag = @enumFromInt(types.Feature.Tag, feature_index) };4033 const feature: types.Feature = .{ .prefix = .used, .tag = @as(types.Feature.Tag, @enumFromInt(feature_index)) };
4034 try leb.writeULEB128(writer, @intFromEnum(feature.prefix));4034 try leb.writeULEB128(writer, @intFromEnum(feature.prefix));
4035 var buf: [100]u8 = undefined;4035 var buf: [100]u8 = undefined;
4036 const string = try std.fmt.bufPrint(&buf, "{}", .{feature.tag});4036 const string = try std.fmt.bufPrint(&buf, "{}", .{feature.tag});
4037 try leb.writeULEB128(writer, @intCast(u32, string.len));4037 try leb.writeULEB128(writer, @as(u32, @intCast(string.len)));
4038 try writer.writeAll(string);4038 try writer.writeAll(string);
4039 }4039 }
4040 }4040 }
...@@ -4042,7 +4042,7 @@ fn emitFeaturesSection(binary_bytes: *std.ArrayList(u8), enabled_features: []con...@@ -4042,7 +4042,7 @@ fn emitFeaturesSection(binary_bytes: *std.ArrayList(u8), enabled_features: []con
4042 try writeCustomSectionHeader(4042 try writeCustomSectionHeader(
4043 binary_bytes.items,4043 binary_bytes.items,
4044 header_offset,4044 header_offset,
4045 @intCast(u32, binary_bytes.items.len - header_offset - 6),4045 @as(u32, @intCast(binary_bytes.items.len - header_offset - 6)),
4046 );4046 );
4047}4047}
40484048
...@@ -4092,7 +4092,7 @@ fn emitNameSection(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), arena: std.mem...@@ -4092,7 +4092,7 @@ fn emitNameSection(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), arena: std.mem
40924092
4093 const header_offset = try reserveCustomSectionHeader(binary_bytes);4093 const header_offset = try reserveCustomSectionHeader(binary_bytes);
4094 const writer = binary_bytes.writer();4094 const writer = binary_bytes.writer();
4095 try leb.writeULEB128(writer, @intCast(u32, "name".len));4095 try leb.writeULEB128(writer, @as(u32, @intCast("name".len)));
4096 try writer.writeAll("name");4096 try writer.writeAll("name");
40974097
4098 try wasm.emitNameSubsection(.function, funcs.values(), writer);4098 try wasm.emitNameSubsection(.function, funcs.values(), writer);
...@@ -4102,7 +4102,7 @@ fn emitNameSection(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), arena: std.mem...@@ -4102,7 +4102,7 @@ fn emitNameSection(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), arena: std.mem
4102 try writeCustomSectionHeader(4102 try writeCustomSectionHeader(
4103 binary_bytes.items,4103 binary_bytes.items,
4104 header_offset,4104 header_offset,
4105 @intCast(u32, binary_bytes.items.len - header_offset - 6),4105 @as(u32, @intCast(binary_bytes.items.len - header_offset - 6)),
4106 );4106 );
4107}4107}
41084108
...@@ -4112,17 +4112,17 @@ fn emitNameSubsection(wasm: *Wasm, section_id: std.wasm.NameSubsection, names: a...@@ -4112,17 +4112,17 @@ fn emitNameSubsection(wasm: *Wasm, section_id: std.wasm.NameSubsection, names: a
4112 defer section_list.deinit();4112 defer section_list.deinit();
4113 const sub_writer = section_list.writer();4113 const sub_writer = section_list.writer();
41144114
4115 try leb.writeULEB128(sub_writer, @intCast(u32, names.len));4115 try leb.writeULEB128(sub_writer, @as(u32, @intCast(names.len)));
4116 for (names) |name| {4116 for (names) |name| {
4117 log.debug("Emit symbol '{s}' type({s})", .{ name.name, @tagName(section_id) });4117 log.debug("Emit symbol '{s}' type({s})", .{ name.name, @tagName(section_id) });
4118 try leb.writeULEB128(sub_writer, name.index);4118 try leb.writeULEB128(sub_writer, name.index);
4119 try leb.writeULEB128(sub_writer, @intCast(u32, name.name.len));4119 try leb.writeULEB128(sub_writer, @as(u32, @intCast(name.name.len)));
4120 try sub_writer.writeAll(name.name);4120 try sub_writer.writeAll(name.name);
4121 }4121 }
41224122
4123 // From now, write to the actual writer4123 // From now, write to the actual writer
4124 try leb.writeULEB128(writer, @intFromEnum(section_id));4124 try leb.writeULEB128(writer, @intFromEnum(section_id));
4125 try leb.writeULEB128(writer, @intCast(u32, section_list.items.len));4125 try leb.writeULEB128(writer, @as(u32, @intCast(section_list.items.len)));
4126 try writer.writeAll(section_list.items);4126 try writer.writeAll(section_list.items);
4127}4127}
41284128
...@@ -4146,11 +4146,11 @@ fn emitInit(writer: anytype, init_expr: std.wasm.InitExpression) !void {...@@ -4146,11 +4146,11 @@ fn emitInit(writer: anytype, init_expr: std.wasm.InitExpression) !void {
4146 },4146 },
4147 .f32_const => |val| {4147 .f32_const => |val| {
4148 try writer.writeByte(std.wasm.opcode(.f32_const));4148 try writer.writeByte(std.wasm.opcode(.f32_const));
4149 try writer.writeIntLittle(u32, @bitCast(u32, val));4149 try writer.writeIntLittle(u32, @as(u32, @bitCast(val)));
4150 },4150 },
4151 .f64_const => |val| {4151 .f64_const => |val| {
4152 try writer.writeByte(std.wasm.opcode(.f64_const));4152 try writer.writeByte(std.wasm.opcode(.f64_const));
4153 try writer.writeIntLittle(u64, @bitCast(u64, val));4153 try writer.writeIntLittle(u64, @as(u64, @bitCast(val)));
4154 },4154 },
4155 .global_get => |val| {4155 .global_get => |val| {
4156 try writer.writeByte(std.wasm.opcode(.global_get));4156 try writer.writeByte(std.wasm.opcode(.global_get));
...@@ -4162,11 +4162,11 @@ fn emitInit(writer: anytype, init_expr: std.wasm.InitExpression) !void {...@@ -4162,11 +4162,11 @@ fn emitInit(writer: anytype, init_expr: std.wasm.InitExpression) !void {
41624162
4163fn emitImport(wasm: *Wasm, writer: anytype, import: types.Import) !void {4163fn emitImport(wasm: *Wasm, writer: anytype, import: types.Import) !void {
4164 const module_name = wasm.string_table.get(import.module_name);4164 const module_name = wasm.string_table.get(import.module_name);
4165 try leb.writeULEB128(writer, @intCast(u32, module_name.len));4165 try leb.writeULEB128(writer, @as(u32, @intCast(module_name.len)));
4166 try writer.writeAll(module_name);4166 try writer.writeAll(module_name);
41674167
4168 const name = wasm.string_table.get(import.name);4168 const name = wasm.string_table.get(import.name);
4169 try leb.writeULEB128(writer, @intCast(u32, name.len));4169 try leb.writeULEB128(writer, @as(u32, @intCast(name.len)));
4170 try writer.writeAll(name);4170 try writer.writeAll(name);
41714171
4172 try writer.writeByte(@intFromEnum(import.kind));4172 try writer.writeByte(@intFromEnum(import.kind));
...@@ -4594,7 +4594,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !...@@ -4594,7 +4594,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
4594fn reserveVecSectionHeader(bytes: *std.ArrayList(u8)) !u32 {4594fn reserveVecSectionHeader(bytes: *std.ArrayList(u8)) !u32 {
4595 // section id + fixed leb contents size + fixed leb vector length4595 // section id + fixed leb contents size + fixed leb vector length
4596 const header_size = 1 + 5 + 5;4596 const header_size = 1 + 5 + 5;
4597 const offset = @intCast(u32, bytes.items.len);4597 const offset = @as(u32, @intCast(bytes.items.len));
4598 try bytes.appendSlice(&[_]u8{0} ** header_size);4598 try bytes.appendSlice(&[_]u8{0} ** header_size);
4599 return offset;4599 return offset;
4600}4600}
...@@ -4602,7 +4602,7 @@ fn reserveVecSectionHeader(bytes: *std.ArrayList(u8)) !u32 {...@@ -4602,7 +4602,7 @@ fn reserveVecSectionHeader(bytes: *std.ArrayList(u8)) !u32 {
4602fn reserveCustomSectionHeader(bytes: *std.ArrayList(u8)) !u32 {4602fn reserveCustomSectionHeader(bytes: *std.ArrayList(u8)) !u32 {
4603 // unlike regular section, we don't emit the count4603 // unlike regular section, we don't emit the count
4604 const header_size = 1 + 5;4604 const header_size = 1 + 5;
4605 const offset = @intCast(u32, bytes.items.len);4605 const offset = @as(u32, @intCast(bytes.items.len));
4606 try bytes.appendSlice(&[_]u8{0} ** header_size);4606 try bytes.appendSlice(&[_]u8{0} ** header_size);
4607 return offset;4607 return offset;
4608}4608}
...@@ -4638,7 +4638,7 @@ fn emitLinkSection(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), symbol_table:...@@ -4638,7 +4638,7 @@ fn emitLinkSection(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), symbol_table:
4638 try wasm.emitSymbolTable(binary_bytes, symbol_table);4638 try wasm.emitSymbolTable(binary_bytes, symbol_table);
4639 try wasm.emitSegmentInfo(binary_bytes);4639 try wasm.emitSegmentInfo(binary_bytes);
46404640
4641 const size = @intCast(u32, binary_bytes.items.len - offset - 6);4641 const size = @as(u32, @intCast(binary_bytes.items.len - offset - 6));
4642 try writeCustomSectionHeader(binary_bytes.items, offset, size);4642 try writeCustomSectionHeader(binary_bytes.items, offset, size);
4643}4643}
46444644
...@@ -4661,7 +4661,7 @@ fn emitSymbolTable(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), symbol_table:...@@ -4661,7 +4661,7 @@ fn emitSymbolTable(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), symbol_table:
4661 const sym_name = if (wasm.export_names.get(sym_loc)) |exp_name| wasm.string_table.get(exp_name) else sym_loc.getName(wasm);4661 const sym_name = if (wasm.export_names.get(sym_loc)) |exp_name| wasm.string_table.get(exp_name) else sym_loc.getName(wasm);
4662 switch (symbol.tag) {4662 switch (symbol.tag) {
4663 .data => {4663 .data => {
4664 try leb.writeULEB128(writer, @intCast(u32, sym_name.len));4664 try leb.writeULEB128(writer, @as(u32, @intCast(sym_name.len)));
4665 try writer.writeAll(sym_name);4665 try writer.writeAll(sym_name);
46664666
4667 if (symbol.isDefined()) {4667 if (symbol.isDefined()) {
...@@ -4678,7 +4678,7 @@ fn emitSymbolTable(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), symbol_table:...@@ -4678,7 +4678,7 @@ fn emitSymbolTable(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), symbol_table:
4678 else => {4678 else => {
4679 try leb.writeULEB128(writer, symbol.index);4679 try leb.writeULEB128(writer, symbol.index);
4680 if (symbol.isDefined()) {4680 if (symbol.isDefined()) {
4681 try leb.writeULEB128(writer, @intCast(u32, sym_name.len));4681 try leb.writeULEB128(writer, @as(u32, @intCast(sym_name.len)));
4682 try writer.writeAll(sym_name);4682 try writer.writeAll(sym_name);
4683 }4683 }
4684 },4684 },
...@@ -4686,7 +4686,7 @@ fn emitSymbolTable(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), symbol_table:...@@ -4686,7 +4686,7 @@ fn emitSymbolTable(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), symbol_table:
4686 }4686 }
46874687
4688 var buf: [10]u8 = undefined;4688 var buf: [10]u8 = undefined;
4689 leb.writeUnsignedFixed(5, buf[0..5], @intCast(u32, binary_bytes.items.len - table_offset + 5));4689 leb.writeUnsignedFixed(5, buf[0..5], @as(u32, @intCast(binary_bytes.items.len - table_offset + 5)));
4690 leb.writeUnsignedFixed(5, buf[5..], symbol_count);4690 leb.writeUnsignedFixed(5, buf[5..], symbol_count);
4691 try binary_bytes.insertSlice(table_offset, &buf);4691 try binary_bytes.insertSlice(table_offset, &buf);
4692}4692}
...@@ -4696,28 +4696,28 @@ fn emitSegmentInfo(wasm: *Wasm, binary_bytes: *std.ArrayList(u8)) !void {...@@ -4696,28 +4696,28 @@ fn emitSegmentInfo(wasm: *Wasm, binary_bytes: *std.ArrayList(u8)) !void {
4696 try leb.writeULEB128(writer, @intFromEnum(types.SubsectionType.WASM_SEGMENT_INFO));4696 try leb.writeULEB128(writer, @intFromEnum(types.SubsectionType.WASM_SEGMENT_INFO));
4697 const segment_offset = binary_bytes.items.len;4697 const segment_offset = binary_bytes.items.len;
46984698
4699 try leb.writeULEB128(writer, @intCast(u32, wasm.segment_info.count()));4699 try leb.writeULEB128(writer, @as(u32, @intCast(wasm.segment_info.count())));
4700 for (wasm.segment_info.values()) |segment_info| {4700 for (wasm.segment_info.values()) |segment_info| {
4701 log.debug("Emit segment: {s} align({d}) flags({b})", .{4701 log.debug("Emit segment: {s} align({d}) flags({b})", .{
4702 segment_info.name,4702 segment_info.name,
4703 @ctz(segment_info.alignment),4703 @ctz(segment_info.alignment),
4704 segment_info.flags,4704 segment_info.flags,
4705 });4705 });
4706 try leb.writeULEB128(writer, @intCast(u32, segment_info.name.len));4706 try leb.writeULEB128(writer, @as(u32, @intCast(segment_info.name.len)));
4707 try writer.writeAll(segment_info.name);4707 try writer.writeAll(segment_info.name);
4708 try leb.writeULEB128(writer, @ctz(segment_info.alignment));4708 try leb.writeULEB128(writer, @ctz(segment_info.alignment));
4709 try leb.writeULEB128(writer, segment_info.flags);4709 try leb.writeULEB128(writer, segment_info.flags);
4710 }4710 }
47114711
4712 var buf: [5]u8 = undefined;4712 var buf: [5]u8 = undefined;
4713 leb.writeUnsignedFixed(5, &buf, @intCast(u32, binary_bytes.items.len - segment_offset));4713 leb.writeUnsignedFixed(5, &buf, @as(u32, @intCast(binary_bytes.items.len - segment_offset)));
4714 try binary_bytes.insertSlice(segment_offset, &buf);4714 try binary_bytes.insertSlice(segment_offset, &buf);
4715}4715}
47164716
4717pub fn getULEB128Size(uint_value: anytype) u32 {4717pub fn getULEB128Size(uint_value: anytype) u32 {
4718 const T = @TypeOf(uint_value);4718 const T = @TypeOf(uint_value);
4719 const U = if (@typeInfo(T).Int.bits < 8) u8 else T;4719 const U = if (@typeInfo(T).Int.bits < 8) u8 else T;
4720 var value = @intCast(U, uint_value);4720 var value = @as(U, @intCast(uint_value));
47214721
4722 var size: u32 = 0;4722 var size: u32 = 0;
4723 while (value != 0) : (size += 1) {4723 while (value != 0) : (size += 1) {
...@@ -4739,7 +4739,7 @@ fn emitCodeRelocations(...@@ -4739,7 +4739,7 @@ fn emitCodeRelocations(
47394739
4740 // write custom section information4740 // write custom section information
4741 const name = "reloc.CODE";4741 const name = "reloc.CODE";
4742 try leb.writeULEB128(writer, @intCast(u32, name.len));4742 try leb.writeULEB128(writer, @as(u32, @intCast(name.len)));
4743 try writer.writeAll(name);4743 try writer.writeAll(name);
4744 try leb.writeULEB128(writer, section_index);4744 try leb.writeULEB128(writer, section_index);
4745 const reloc_start = binary_bytes.items.len;4745 const reloc_start = binary_bytes.items.len;
...@@ -4769,7 +4769,7 @@ fn emitCodeRelocations(...@@ -4769,7 +4769,7 @@ fn emitCodeRelocations(
4769 var buf: [5]u8 = undefined;4769 var buf: [5]u8 = undefined;
4770 leb.writeUnsignedFixed(5, &buf, count);4770 leb.writeUnsignedFixed(5, &buf, count);
4771 try binary_bytes.insertSlice(reloc_start, &buf);4771 try binary_bytes.insertSlice(reloc_start, &buf);
4772 const size = @intCast(u32, binary_bytes.items.len - header_offset - 6);4772 const size = @as(u32, @intCast(binary_bytes.items.len - header_offset - 6));
4773 try writeCustomSectionHeader(binary_bytes.items, header_offset, size);4773 try writeCustomSectionHeader(binary_bytes.items, header_offset, size);
4774}4774}
47754775
...@@ -4785,7 +4785,7 @@ fn emitDataRelocations(...@@ -4785,7 +4785,7 @@ fn emitDataRelocations(
47854785
4786 // write custom section information4786 // write custom section information
4787 const name = "reloc.DATA";4787 const name = "reloc.DATA";
4788 try leb.writeULEB128(writer, @intCast(u32, name.len));4788 try leb.writeULEB128(writer, @as(u32, @intCast(name.len)));
4789 try writer.writeAll(name);4789 try writer.writeAll(name);
4790 try leb.writeULEB128(writer, section_index);4790 try leb.writeULEB128(writer, section_index);
4791 const reloc_start = binary_bytes.items.len;4791 const reloc_start = binary_bytes.items.len;
...@@ -4821,7 +4821,7 @@ fn emitDataRelocations(...@@ -4821,7 +4821,7 @@ fn emitDataRelocations(
4821 var buf: [5]u8 = undefined;4821 var buf: [5]u8 = undefined;
4822 leb.writeUnsignedFixed(5, &buf, count);4822 leb.writeUnsignedFixed(5, &buf, count);
4823 try binary_bytes.insertSlice(reloc_start, &buf);4823 try binary_bytes.insertSlice(reloc_start, &buf);
4824 const size = @intCast(u32, binary_bytes.items.len - header_offset - 6);4824 const size = @as(u32, @intCast(binary_bytes.items.len - header_offset - 6));
4825 try writeCustomSectionHeader(binary_bytes.items, header_offset, size);4825 try writeCustomSectionHeader(binary_bytes.items, header_offset, size);
4826}4826}
48274827
...@@ -4852,7 +4852,7 @@ pub fn putOrGetFuncType(wasm: *Wasm, func_type: std.wasm.Type) !u32 {...@@ -4852,7 +4852,7 @@ pub fn putOrGetFuncType(wasm: *Wasm, func_type: std.wasm.Type) !u32 {
4852 }4852 }
48534853
4854 // functype does not exist.4854 // functype does not exist.
4855 const index = @intCast(u32, wasm.func_types.items.len);4855 const index = @as(u32, @intCast(wasm.func_types.items.len));
4856 const params = try wasm.base.allocator.dupe(std.wasm.Valtype, func_type.params);4856 const params = try wasm.base.allocator.dupe(std.wasm.Valtype, func_type.params);
4857 errdefer wasm.base.allocator.free(params);4857 errdefer wasm.base.allocator.free(params);
4858 const returns = try wasm.base.allocator.dupe(std.wasm.Valtype, func_type.returns);4858 const returns = try wasm.base.allocator.dupe(std.wasm.Valtype, func_type.returns);
src/link/Wasm/Atom.zig+9-9
...@@ -114,7 +114,7 @@ pub fn resolveRelocs(atom: *Atom, wasm_bin: *const Wasm) void {...@@ -114,7 +114,7 @@ pub fn resolveRelocs(atom: *Atom, wasm_bin: *const Wasm) void {
114 .R_WASM_GLOBAL_INDEX_I32,114 .R_WASM_GLOBAL_INDEX_I32,
115 .R_WASM_MEMORY_ADDR_I32,115 .R_WASM_MEMORY_ADDR_I32,
116 .R_WASM_SECTION_OFFSET_I32,116 .R_WASM_SECTION_OFFSET_I32,
117 => std.mem.writeIntLittle(u32, atom.code.items[reloc.offset..][0..4], @intCast(u32, value)),117 => std.mem.writeIntLittle(u32, atom.code.items[reloc.offset..][0..4], @as(u32, @intCast(value))),
118 .R_WASM_TABLE_INDEX_I64,118 .R_WASM_TABLE_INDEX_I64,
119 .R_WASM_MEMORY_ADDR_I64,119 .R_WASM_MEMORY_ADDR_I64,
120 => std.mem.writeIntLittle(u64, atom.code.items[reloc.offset..][0..8], value),120 => std.mem.writeIntLittle(u64, atom.code.items[reloc.offset..][0..8], value),
...@@ -127,7 +127,7 @@ pub fn resolveRelocs(atom: *Atom, wasm_bin: *const Wasm) void {...@@ -127,7 +127,7 @@ pub fn resolveRelocs(atom: *Atom, wasm_bin: *const Wasm) void {
127 .R_WASM_TABLE_NUMBER_LEB,127 .R_WASM_TABLE_NUMBER_LEB,
128 .R_WASM_TYPE_INDEX_LEB,128 .R_WASM_TYPE_INDEX_LEB,
129 .R_WASM_MEMORY_ADDR_TLS_SLEB,129 .R_WASM_MEMORY_ADDR_TLS_SLEB,
130 => leb.writeUnsignedFixed(5, atom.code.items[reloc.offset..][0..5], @intCast(u32, value)),130 => leb.writeUnsignedFixed(5, atom.code.items[reloc.offset..][0..5], @as(u32, @intCast(value))),
131 .R_WASM_MEMORY_ADDR_LEB64,131 .R_WASM_MEMORY_ADDR_LEB64,
132 .R_WASM_MEMORY_ADDR_SLEB64,132 .R_WASM_MEMORY_ADDR_SLEB64,
133 .R_WASM_TABLE_INDEX_SLEB64,133 .R_WASM_TABLE_INDEX_SLEB64,
...@@ -173,24 +173,24 @@ fn relocationValue(atom: Atom, relocation: types.Relocation, wasm_bin: *const Wa...@@ -173,24 +173,24 @@ fn relocationValue(atom: Atom, relocation: types.Relocation, wasm_bin: *const Wa
173 if (symbol.isUndefined()) {173 if (symbol.isUndefined()) {
174 return 0;174 return 0;
175 }175 }
176 const va = @intCast(i64, symbol.virtual_address);176 const va = @as(i64, @intCast(symbol.virtual_address));
177 return @intCast(u32, va + relocation.addend);177 return @as(u32, @intCast(va + relocation.addend));
178 },178 },
179 .R_WASM_EVENT_INDEX_LEB => return symbol.index,179 .R_WASM_EVENT_INDEX_LEB => return symbol.index,
180 .R_WASM_SECTION_OFFSET_I32 => {180 .R_WASM_SECTION_OFFSET_I32 => {
181 const target_atom_index = wasm_bin.symbol_atom.get(target_loc).?;181 const target_atom_index = wasm_bin.symbol_atom.get(target_loc).?;
182 const target_atom = wasm_bin.getAtom(target_atom_index);182 const target_atom = wasm_bin.getAtom(target_atom_index);
183 const rel_value = @intCast(i32, target_atom.offset) + relocation.addend;183 const rel_value = @as(i32, @intCast(target_atom.offset)) + relocation.addend;
184 return @intCast(u32, rel_value);184 return @as(u32, @intCast(rel_value));
185 },185 },
186 .R_WASM_FUNCTION_OFFSET_I32 => {186 .R_WASM_FUNCTION_OFFSET_I32 => {
187 const target_atom_index = wasm_bin.symbol_atom.get(target_loc) orelse {187 const target_atom_index = wasm_bin.symbol_atom.get(target_loc) orelse {
188 return @bitCast(u32, @as(i32, -1));188 return @as(u32, @bitCast(@as(i32, -1)));
189 };189 };
190 const target_atom = wasm_bin.getAtom(target_atom_index);190 const target_atom = wasm_bin.getAtom(target_atom_index);
191 const offset: u32 = 11 + Wasm.getULEB128Size(target_atom.size); // Header (11 bytes fixed-size) + body size (leb-encoded)191 const offset: u32 = 11 + Wasm.getULEB128Size(target_atom.size); // Header (11 bytes fixed-size) + body size (leb-encoded)
192 const rel_value = @intCast(i32, target_atom.offset + offset) + relocation.addend;192 const rel_value = @as(i32, @intCast(target_atom.offset + offset)) + relocation.addend;
193 return @intCast(u32, rel_value);193 return @as(u32, @intCast(rel_value));
194 },194 },
195 .R_WASM_MEMORY_ADDR_TLS_SLEB,195 .R_WASM_MEMORY_ADDR_TLS_SLEB,
196 .R_WASM_MEMORY_ADDR_TLS_SLEB64,196 .R_WASM_MEMORY_ADDR_TLS_SLEB64,
src/link/Wasm/Object.zig+16-16
...@@ -93,7 +93,7 @@ const RelocatableData = struct {...@@ -93,7 +93,7 @@ const RelocatableData = struct {
93 const data_alignment = object.segment_info[relocatable_data.index].alignment;93 const data_alignment = object.segment_info[relocatable_data.index].alignment;
94 if (data_alignment == 0) return 1;94 if (data_alignment == 0) return 1;
95 // Decode from power of 2 to natural alignment95 // Decode from power of 2 to natural alignment
96 return @as(u32, 1) << @intCast(u5, data_alignment);96 return @as(u32, 1) << @as(u5, @intCast(data_alignment));
97 }97 }
9898
99 /// Returns the symbol kind that corresponds to the relocatable section99 /// Returns the symbol kind that corresponds to the relocatable section
...@@ -130,7 +130,7 @@ pub fn create(gpa: Allocator, file: std.fs.File, name: []const u8, maybe_max_siz...@@ -130,7 +130,7 @@ pub fn create(gpa: Allocator, file: std.fs.File, name: []const u8, maybe_max_siz
130 const size = maybe_max_size orelse size: {130 const size = maybe_max_size orelse size: {
131 errdefer gpa.free(object.name);131 errdefer gpa.free(object.name);
132 const stat = try file.stat();132 const stat = try file.stat();
133 break :size @intCast(usize, stat.size);133 break :size @as(usize, @intCast(stat.size));
134 };134 };
135135
136 const file_contents = try gpa.alloc(u8, size);136 const file_contents = try gpa.alloc(u8, size);
...@@ -365,7 +365,7 @@ fn Parser(comptime ReaderType: type) type {...@@ -365,7 +365,7 @@ fn Parser(comptime ReaderType: type) type {
365 const len = try readLeb(u32, parser.reader.reader());365 const len = try readLeb(u32, parser.reader.reader());
366 var limited_reader = std.io.limitedReader(parser.reader.reader(), len);366 var limited_reader = std.io.limitedReader(parser.reader.reader(), len);
367 const reader = limited_reader.reader();367 const reader = limited_reader.reader();
368 switch (@enumFromInt(std.wasm.Section, byte)) {368 switch (@as(std.wasm.Section, @enumFromInt(byte))) {
369 .custom => {369 .custom => {
370 const name_len = try readLeb(u32, reader);370 const name_len = try readLeb(u32, reader);
371 const name = try gpa.alloc(u8, name_len);371 const name = try gpa.alloc(u8, name_len);
...@@ -375,13 +375,13 @@ fn Parser(comptime ReaderType: type) type {...@@ -375,13 +375,13 @@ fn Parser(comptime ReaderType: type) type {
375 if (std.mem.eql(u8, name, "linking")) {375 if (std.mem.eql(u8, name, "linking")) {
376 is_object_file.* = true;376 is_object_file.* = true;
377 parser.object.relocatable_data = relocatable_data.items; // at this point no new relocatable sections will appear so we're free to store them.377 parser.object.relocatable_data = relocatable_data.items; // at this point no new relocatable sections will appear so we're free to store them.
378 try parser.parseMetadata(gpa, @intCast(usize, reader.context.bytes_left));378 try parser.parseMetadata(gpa, @as(usize, @intCast(reader.context.bytes_left)));
379 } else if (std.mem.startsWith(u8, name, "reloc")) {379 } else if (std.mem.startsWith(u8, name, "reloc")) {
380 try parser.parseRelocations(gpa);380 try parser.parseRelocations(gpa);
381 } else if (std.mem.eql(u8, name, "target_features")) {381 } else if (std.mem.eql(u8, name, "target_features")) {
382 try parser.parseFeatures(gpa);382 try parser.parseFeatures(gpa);
383 } else if (std.mem.startsWith(u8, name, ".debug")) {383 } else if (std.mem.startsWith(u8, name, ".debug")) {
384 const debug_size = @intCast(u32, reader.context.bytes_left);384 const debug_size = @as(u32, @intCast(reader.context.bytes_left));
385 const debug_content = try gpa.alloc(u8, debug_size);385 const debug_content = try gpa.alloc(u8, debug_size);
386 errdefer gpa.free(debug_content);386 errdefer gpa.free(debug_content);
387 try reader.readNoEof(debug_content);387 try reader.readNoEof(debug_content);
...@@ -514,7 +514,7 @@ fn Parser(comptime ReaderType: type) type {...@@ -514,7 +514,7 @@ fn Parser(comptime ReaderType: type) type {
514 const count = try readLeb(u32, reader);514 const count = try readLeb(u32, reader);
515 while (index < count) : (index += 1) {515 while (index < count) : (index += 1) {
516 const code_len = try readLeb(u32, reader);516 const code_len = try readLeb(u32, reader);
517 const offset = @intCast(u32, start - reader.context.bytes_left);517 const offset = @as(u32, @intCast(start - reader.context.bytes_left));
518 const data = try gpa.alloc(u8, code_len);518 const data = try gpa.alloc(u8, code_len);
519 errdefer gpa.free(data);519 errdefer gpa.free(data);
520 try reader.readNoEof(data);520 try reader.readNoEof(data);
...@@ -538,7 +538,7 @@ fn Parser(comptime ReaderType: type) type {...@@ -538,7 +538,7 @@ fn Parser(comptime ReaderType: type) type {
538 _ = flags; // TODO: Do we need to check flags to detect passive/active memory?538 _ = flags; // TODO: Do we need to check flags to detect passive/active memory?
539 _ = data_offset;539 _ = data_offset;
540 const data_len = try readLeb(u32, reader);540 const data_len = try readLeb(u32, reader);
541 const offset = @intCast(u32, start - reader.context.bytes_left);541 const offset = @as(u32, @intCast(start - reader.context.bytes_left));
542 const data = try gpa.alloc(u8, data_len);542 const data = try gpa.alloc(u8, data_len);
543 errdefer gpa.free(data);543 errdefer gpa.free(data);
544 try reader.readNoEof(data);544 try reader.readNoEof(data);
...@@ -645,7 +645,7 @@ fn Parser(comptime ReaderType: type) type {...@@ -645,7 +645,7 @@ fn Parser(comptime ReaderType: type) type {
645 /// such as access to the `import` section to find the name of a symbol.645 /// such as access to the `import` section to find the name of a symbol.
646 fn parseSubsection(parser: *ObjectParser, gpa: Allocator, reader: anytype) !void {646 fn parseSubsection(parser: *ObjectParser, gpa: Allocator, reader: anytype) !void {
647 const sub_type = try leb.readULEB128(u8, reader);647 const sub_type = try leb.readULEB128(u8, reader);
648 log.debug("Found subsection: {s}", .{@tagName(@enumFromInt(types.SubsectionType, sub_type))});648 log.debug("Found subsection: {s}", .{@tagName(@as(types.SubsectionType, @enumFromInt(sub_type)))});
649 const payload_len = try leb.readULEB128(u32, reader);649 const payload_len = try leb.readULEB128(u32, reader);
650 if (payload_len == 0) return;650 if (payload_len == 0) return;
651651
...@@ -655,7 +655,7 @@ fn Parser(comptime ReaderType: type) type {...@@ -655,7 +655,7 @@ fn Parser(comptime ReaderType: type) type {
655 // every subsection contains a 'count' field655 // every subsection contains a 'count' field
656 const count = try leb.readULEB128(u32, limited_reader);656 const count = try leb.readULEB128(u32, limited_reader);
657657
658 switch (@enumFromInt(types.SubsectionType, sub_type)) {658 switch (@as(types.SubsectionType, @enumFromInt(sub_type))) {
659 .WASM_SEGMENT_INFO => {659 .WASM_SEGMENT_INFO => {
660 const segments = try gpa.alloc(types.Segment, count);660 const segments = try gpa.alloc(types.Segment, count);
661 errdefer gpa.free(segments);661 errdefer gpa.free(segments);
...@@ -714,7 +714,7 @@ fn Parser(comptime ReaderType: type) type {...@@ -714,7 +714,7 @@ fn Parser(comptime ReaderType: type) type {
714 errdefer gpa.free(symbols);714 errdefer gpa.free(symbols);
715 for (symbols) |*symbol| {715 for (symbols) |*symbol| {
716 symbol.* = .{716 symbol.* = .{
717 .kind = @enumFromInt(types.ComdatSym.Type, try leb.readULEB128(u8, reader)),717 .kind = @as(types.ComdatSym.Type, @enumFromInt(try leb.readULEB128(u8, reader))),
718 .index = try leb.readULEB128(u32, reader),718 .index = try leb.readULEB128(u32, reader),
719 };719 };
720 }720 }
...@@ -758,7 +758,7 @@ fn Parser(comptime ReaderType: type) type {...@@ -758,7 +758,7 @@ fn Parser(comptime ReaderType: type) type {
758 /// requires access to `Object` to find the name of a symbol when it's758 /// requires access to `Object` to find the name of a symbol when it's
759 /// an import and flag `WASM_SYM_EXPLICIT_NAME` is not set.759 /// an import and flag `WASM_SYM_EXPLICIT_NAME` is not set.
760 fn parseSymbol(parser: *ObjectParser, gpa: Allocator, reader: anytype) !Symbol {760 fn parseSymbol(parser: *ObjectParser, gpa: Allocator, reader: anytype) !Symbol {
761 const tag = @enumFromInt(Symbol.Tag, try leb.readULEB128(u8, reader));761 const tag = @as(Symbol.Tag, @enumFromInt(try leb.readULEB128(u8, reader)));
762 const flags = try leb.readULEB128(u32, reader);762 const flags = try leb.readULEB128(u32, reader);
763 var symbol: Symbol = .{763 var symbol: Symbol = .{
764 .flags = flags,764 .flags = flags,
...@@ -846,7 +846,7 @@ fn readLeb(comptime T: type, reader: anytype) !T {...@@ -846,7 +846,7 @@ fn readLeb(comptime T: type, reader: anytype) !T {
846/// Asserts `T` is an enum846/// Asserts `T` is an enum
847fn readEnum(comptime T: type, reader: anytype) !T {847fn readEnum(comptime T: type, reader: anytype) !T {
848 switch (@typeInfo(T)) {848 switch (@typeInfo(T)) {
849 .Enum => |enum_type| return @enumFromInt(T, try readLeb(enum_type.tag_type, reader)),849 .Enum => |enum_type| return @as(T, @enumFromInt(try readLeb(enum_type.tag_type, reader))),
850 else => @compileError("T must be an enum. Instead was given type " ++ @typeName(T)),850 else => @compileError("T must be an enum. Instead was given type " ++ @typeName(T)),
851 }851 }
852}852}
...@@ -867,7 +867,7 @@ fn readLimits(reader: anytype) !std.wasm.Limits {...@@ -867,7 +867,7 @@ fn readLimits(reader: anytype) !std.wasm.Limits {
867867
868fn readInit(reader: anytype) !std.wasm.InitExpression {868fn readInit(reader: anytype) !std.wasm.InitExpression {
869 const opcode = try reader.readByte();869 const opcode = try reader.readByte();
870 const init_expr: std.wasm.InitExpression = switch (@enumFromInt(std.wasm.Opcode, opcode)) {870 const init_expr: std.wasm.InitExpression = switch (@as(std.wasm.Opcode, @enumFromInt(opcode))) {
871 .i32_const => .{ .i32_const = try readLeb(i32, reader) },871 .i32_const => .{ .i32_const = try readLeb(i32, reader) },
872 .global_get => .{ .global_get = try readLeb(u32, reader) },872 .global_get => .{ .global_get = try readLeb(u32, reader) },
873 else => @panic("TODO: initexpression for other opcodes"),873 else => @panic("TODO: initexpression for other opcodes"),
...@@ -899,7 +899,7 @@ pub fn parseIntoAtoms(object: *Object, gpa: Allocator, object_index: u16, wasm_b...@@ -899,7 +899,7 @@ pub fn parseIntoAtoms(object: *Object, gpa: Allocator, object_index: u16, wasm_b
899 switch (symbol.tag) {899 switch (symbol.tag) {
900 .function, .data, .section => if (!symbol.isUndefined()) {900 .function, .data, .section => if (!symbol.isUndefined()) {
901 const gop = try symbol_for_segment.getOrPut(.{ .kind = symbol.tag, .index = symbol.index });901 const gop = try symbol_for_segment.getOrPut(.{ .kind = symbol.tag, .index = symbol.index });
902 const sym_idx = @intCast(u32, symbol_index);902 const sym_idx = @as(u32, @intCast(symbol_index));
903 if (!gop.found_existing) {903 if (!gop.found_existing) {
904 gop.value_ptr.* = std.ArrayList(u32).init(gpa);904 gop.value_ptr.* = std.ArrayList(u32).init(gpa);
905 }905 }
...@@ -910,11 +910,11 @@ pub fn parseIntoAtoms(object: *Object, gpa: Allocator, object_index: u16, wasm_b...@@ -910,11 +910,11 @@ pub fn parseIntoAtoms(object: *Object, gpa: Allocator, object_index: u16, wasm_b
910 }910 }
911911
912 for (object.relocatable_data, 0..) |relocatable_data, index| {912 for (object.relocatable_data, 0..) |relocatable_data, index| {
913 const final_index = (try wasm_bin.getMatchingSegment(object_index, @intCast(u32, index))) orelse {913 const final_index = (try wasm_bin.getMatchingSegment(object_index, @as(u32, @intCast(index)))) orelse {
914 continue; // found unknown section, so skip parsing into atom as we do not know how to handle it.914 continue; // found unknown section, so skip parsing into atom as we do not know how to handle it.
915 };915 };
916916
917 const atom_index = @intCast(Atom.Index, wasm_bin.managed_atoms.items.len);917 const atom_index = @as(Atom.Index, @intCast(wasm_bin.managed_atoms.items.len));
918 const atom = try wasm_bin.managed_atoms.addOne(gpa);918 const atom = try wasm_bin.managed_atoms.addOne(gpa);
919 atom.* = Atom.empty;919 atom.* = Atom.empty;
920 atom.file = object_index;920 atom.file = object_index;
src/link/Wasm/types.zig+1-1
...@@ -205,7 +205,7 @@ pub const Feature = struct {...@@ -205,7 +205,7 @@ pub const Feature = struct {
205205
206 /// From a given cpu feature, returns its linker feature206 /// From a given cpu feature, returns its linker feature
207 pub fn fromCpuFeature(feature: std.Target.wasm.Feature) Tag {207 pub fn fromCpuFeature(feature: std.Target.wasm.Feature) Tag {
208 return @enumFromInt(Tag, @intFromEnum(feature));208 return @as(Tag, @enumFromInt(@intFromEnum(feature)));
209 }209 }
210210
211 pub fn format(tag: Tag, comptime fmt: []const u8, opt: std.fmt.FormatOptions, writer: anytype) !void {211 pub fn format(tag: Tag, comptime fmt: []const u8, opt: std.fmt.FormatOptions, writer: anytype) !void {
src/link/strtab.zig+3-3
...@@ -45,7 +45,7 @@ pub fn StringTable(comptime log_scope: @Type(.EnumLiteral)) type {...@@ -45,7 +45,7 @@ pub fn StringTable(comptime log_scope: @Type(.EnumLiteral)) type {
45 const off = entry.key_ptr.*;45 const off = entry.key_ptr.*;
46 const save = entry.value_ptr.*;46 const save = entry.value_ptr.*;
47 if (!save) continue;47 if (!save) continue;
48 const new_off = @intCast(u32, buffer.items.len);48 const new_off = @as(u32, @intCast(buffer.items.len));
49 buffer.appendSliceAssumeCapacity(self.getAssumeExists(off));49 buffer.appendSliceAssumeCapacity(self.getAssumeExists(off));
50 idx_map.putAssumeCapacityNoClobber(off, new_off);50 idx_map.putAssumeCapacityNoClobber(off, new_off);
51 }51 }
...@@ -73,7 +73,7 @@ pub fn StringTable(comptime log_scope: @Type(.EnumLiteral)) type {...@@ -73,7 +73,7 @@ pub fn StringTable(comptime log_scope: @Type(.EnumLiteral)) type {
73 }73 }
7474
75 try self.buffer.ensureUnusedCapacity(gpa, string.len + 1);75 try self.buffer.ensureUnusedCapacity(gpa, string.len + 1);
76 const new_off = @intCast(u32, self.buffer.items.len);76 const new_off = @as(u32, @intCast(self.buffer.items.len));
7777
78 log.debug("writing new string '{s}' at offset 0x{x}", .{ string, new_off });78 log.debug("writing new string '{s}' at offset 0x{x}", .{ string, new_off });
7979
...@@ -103,7 +103,7 @@ pub fn StringTable(comptime log_scope: @Type(.EnumLiteral)) type {...@@ -103,7 +103,7 @@ pub fn StringTable(comptime log_scope: @Type(.EnumLiteral)) type {
103 pub fn get(self: Self, off: u32) ?[]const u8 {103 pub fn get(self: Self, off: u32) ?[]const u8 {
104 log.debug("getting string at 0x{x}", .{off});104 log.debug("getting string at 0x{x}", .{off});
105 if (off >= self.buffer.items.len) return null;105 if (off >= self.buffer.items.len) return null;
106 return mem.sliceTo(@ptrCast([*:0]const u8, self.buffer.items.ptr + off), 0);106 return mem.sliceTo(@as([*:0]const u8, @ptrCast(self.buffer.items.ptr + off)), 0);
107 }107 }
108108
109 pub fn getAssumeExists(self: Self, off: u32) []const u8 {109 pub fn getAssumeExists(self: Self, off: u32) []const u8 {
src/link/table_section.zig+1-1
...@@ -18,7 +18,7 @@ pub fn TableSection(comptime Entry: type) type {...@@ -18,7 +18,7 @@ pub fn TableSection(comptime Entry: type) type {
18 break :blk index;18 break :blk index;
19 } else {19 } else {
20 log.debug(" (allocating entry at index {d})", .{self.entries.items.len});20 log.debug(" (allocating entry at index {d})", .{self.entries.items.len});
21 const index = @intCast(u32, self.entries.items.len);21 const index = @as(u32, @intCast(self.entries.items.len));
22 _ = self.entries.addOneAssumeCapacity();22 _ = self.entries.addOneAssumeCapacity();
23 break :blk index;23 break :blk index;
24 }24 }
src/link/tapi/Tokenizer.zig+2-2
...@@ -67,11 +67,11 @@ pub const TokenIterator = struct {...@@ -67,11 +67,11 @@ pub const TokenIterator = struct {
67 }67 }
6868
69 pub fn seekBy(self: *TokenIterator, offset: isize) void {69 pub fn seekBy(self: *TokenIterator, offset: isize) void {
70 const new_pos = @bitCast(isize, self.pos) + offset;70 const new_pos = @as(isize, @bitCast(self.pos)) + offset;
71 if (new_pos < 0) {71 if (new_pos < 0) {
72 self.pos = 0;72 self.pos = 0;
73 } else {73 } else {
74 self.pos = @intCast(usize, new_pos);74 self.pos = @as(usize, @intCast(new_pos));
75 }75 }
76 }76 }
77};77};
src/main.zig+9-9
...@@ -3523,7 +3523,7 @@ fn progressThread(progress: *std.Progress, server: *const Server, reset: *std.Th...@@ -3523,7 +3523,7 @@ fn progressThread(progress: *std.Progress, server: *const Server, reset: *std.Th
35233523
3524 server.serveMessage(.{3524 server.serveMessage(.{
3525 .tag = .progress,3525 .tag = .progress,
3526 .bytes_len = @intCast(u32, progress_string.len),3526 .bytes_len = @as(u32, @intCast(progress_string.len)),
3527 }, &.{3527 }, &.{
3528 progress_string,3528 progress_string,
3529 }) catch |err| {3529 }) catch |err| {
...@@ -5020,8 +5020,8 @@ pub fn clangMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}!...@@ -5020,8 +5020,8 @@ pub fn clangMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}!
50205020
5021 // Convert the args to the null-terminated format Clang expects.5021 // Convert the args to the null-terminated format Clang expects.
5022 const argv = try argsCopyZ(arena, args);5022 const argv = try argsCopyZ(arena, args);
5023 const exit_code = ZigClang_main(@intCast(c_int, argv.len), argv.ptr);5023 const exit_code = ZigClang_main(@as(c_int, @intCast(argv.len)), argv.ptr);
5024 return @bitCast(u8, @truncate(i8, exit_code));5024 return @as(u8, @bitCast(@as(i8, @truncate(exit_code))));
5025}5025}
50265026
5027pub fn llvmArMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}!u8 {5027pub fn llvmArMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}!u8 {
...@@ -5035,8 +5035,8 @@ pub fn llvmArMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}...@@ -5035,8 +5035,8 @@ pub fn llvmArMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}
5035 // Convert the args to the format llvm-ar expects.5035 // Convert the args to the format llvm-ar expects.
5036 // We intentionally shave off the zig binary at args[0].5036 // We intentionally shave off the zig binary at args[0].
5037 const argv = try argsCopyZ(arena, args[1..]);5037 const argv = try argsCopyZ(arena, args[1..]);
5038 const exit_code = ZigLlvmAr_main(@intCast(c_int, argv.len), argv.ptr);5038 const exit_code = ZigLlvmAr_main(@as(c_int, @intCast(argv.len)), argv.ptr);
5039 return @bitCast(u8, @truncate(i8, exit_code));5039 return @as(u8, @bitCast(@as(i8, @truncate(exit_code))));
5040}5040}
50415041
5042/// The first argument determines which backend is invoked. The options are:5042/// The first argument determines which backend is invoked. The options are:
...@@ -5072,7 +5072,7 @@ pub fn lldMain(...@@ -5072,7 +5072,7 @@ pub fn lldMain(
5072 // "If an error occurs, false will be returned."5072 // "If an error occurs, false will be returned."
5073 const ok = rc: {5073 const ok = rc: {
5074 const llvm = @import("codegen/llvm/bindings.zig");5074 const llvm = @import("codegen/llvm/bindings.zig");
5075 const argc = @intCast(c_int, argv.len);5075 const argc = @as(c_int, @intCast(argv.len));
5076 if (mem.eql(u8, args[1], "ld.lld")) {5076 if (mem.eql(u8, args[1], "ld.lld")) {
5077 break :rc llvm.LinkELF(argc, argv.ptr, can_exit_early, false);5077 break :rc llvm.LinkELF(argc, argv.ptr, can_exit_early, false);
5078 } else if (mem.eql(u8, args[1], "lld-link")) {5078 } else if (mem.eql(u8, args[1], "lld-link")) {
...@@ -5507,7 +5507,7 @@ pub fn cmdAstCheck(...@@ -5507,7 +5507,7 @@ pub fn cmdAstCheck(
5507 if (stat.size > max_src_size)5507 if (stat.size > max_src_size)
5508 return error.FileTooBig;5508 return error.FileTooBig;
55095509
5510 const source = try arena.allocSentinel(u8, @intCast(usize, stat.size), 0);5510 const source = try arena.allocSentinel(u8, @as(usize, @intCast(stat.size)), 0);
5511 const amt = try f.readAll(source);5511 const amt = try f.readAll(source);
5512 if (amt != stat.size)5512 if (amt != stat.size)
5513 return error.UnexpectedEndOfFile;5513 return error.UnexpectedEndOfFile;
...@@ -5703,7 +5703,7 @@ pub fn cmdChangelist(...@@ -5703,7 +5703,7 @@ pub fn cmdChangelist(
5703 file.pkg = try Package.create(gpa, null, file.sub_file_path);5703 file.pkg = try Package.create(gpa, null, file.sub_file_path);
5704 defer file.pkg.destroy(gpa);5704 defer file.pkg.destroy(gpa);
57055705
5706 const source = try arena.allocSentinel(u8, @intCast(usize, stat.size), 0);5706 const source = try arena.allocSentinel(u8, @as(usize, @intCast(stat.size)), 0);
5707 const amt = try f.readAll(source);5707 const amt = try f.readAll(source);
5708 if (amt != stat.size)5708 if (amt != stat.size)
5709 return error.UnexpectedEndOfFile;5709 return error.UnexpectedEndOfFile;
...@@ -5739,7 +5739,7 @@ pub fn cmdChangelist(...@@ -5739,7 +5739,7 @@ pub fn cmdChangelist(
5739 if (new_stat.size > max_src_size)5739 if (new_stat.size > max_src_size)
5740 return error.FileTooBig;5740 return error.FileTooBig;
57415741
5742 const new_source = try arena.allocSentinel(u8, @intCast(usize, new_stat.size), 0);5742 const new_source = try arena.allocSentinel(u8, @as(usize, @intCast(new_stat.size)), 0);
5743 const new_amt = try new_f.readAll(new_source);5743 const new_amt = try new_f.readAll(new_source);
5744 if (new_amt != new_stat.size)5744 if (new_amt != new_stat.size)
5745 return error.UnexpectedEndOfFile;5745 return error.UnexpectedEndOfFile;
src/objcopy.zig+27-27
...@@ -345,7 +345,7 @@ const BinaryElfOutput = struct {...@@ -345,7 +345,7 @@ const BinaryElfOutput = struct {
345345
346 const shstrtab_shdr = (try section_headers.next()).?;346 const shstrtab_shdr = (try section_headers.next()).?;
347347
348 const buffer = try allocator.alloc(u8, @intCast(usize, shstrtab_shdr.sh_size));348 const buffer = try allocator.alloc(u8, @as(usize, @intCast(shstrtab_shdr.sh_size)));
349 errdefer allocator.free(buffer);349 errdefer allocator.free(buffer);
350350
351 const num_read = try elf_file.preadAll(buffer, shstrtab_shdr.sh_offset);351 const num_read = try elf_file.preadAll(buffer, shstrtab_shdr.sh_offset);
...@@ -363,11 +363,11 @@ const BinaryElfOutput = struct {...@@ -363,11 +363,11 @@ const BinaryElfOutput = struct {
363363
364 newSection.binaryOffset = 0;364 newSection.binaryOffset = 0;
365 newSection.elfOffset = section.sh_offset;365 newSection.elfOffset = section.sh_offset;
366 newSection.fileSize = @intCast(usize, section.sh_size);366 newSection.fileSize = @as(usize, @intCast(section.sh_size));
367 newSection.segment = null;367 newSection.segment = null;
368368
369 newSection.name = if (self.shstrtab) |shstrtab|369 newSection.name = if (self.shstrtab) |shstrtab|
370 std.mem.span(@ptrCast([*:0]const u8, &shstrtab[section.sh_name]))370 std.mem.span(@as([*:0]const u8, @ptrCast(&shstrtab[section.sh_name])))
371 else371 else
372 null;372 null;
373373
...@@ -382,7 +382,7 @@ const BinaryElfOutput = struct {...@@ -382,7 +382,7 @@ const BinaryElfOutput = struct {
382382
383 newSegment.physicalAddress = if (phdr.p_paddr != 0) phdr.p_paddr else phdr.p_vaddr;383 newSegment.physicalAddress = if (phdr.p_paddr != 0) phdr.p_paddr else phdr.p_vaddr;
384 newSegment.virtualAddress = phdr.p_vaddr;384 newSegment.virtualAddress = phdr.p_vaddr;
385 newSegment.fileSize = @intCast(usize, phdr.p_filesz);385 newSegment.fileSize = @as(usize, @intCast(phdr.p_filesz));
386 newSegment.elfOffset = phdr.p_offset;386 newSegment.elfOffset = phdr.p_offset;
387 newSegment.binaryOffset = 0;387 newSegment.binaryOffset = 0;
388 newSegment.firstSection = null;388 newSegment.firstSection = null;
...@@ -478,8 +478,8 @@ const HexWriter = struct {...@@ -478,8 +478,8 @@ const HexWriter = struct {
478 const MAX_PAYLOAD_LEN: u8 = 16;478 const MAX_PAYLOAD_LEN: u8 = 16;
479479
480 fn addressParts(address: u16) [2]u8 {480 fn addressParts(address: u16) [2]u8 {
481 const msb = @truncate(u8, address >> 8);481 const msb = @as(u8, @truncate(address >> 8));
482 const lsb = @truncate(u8, address);482 const lsb = @as(u8, @truncate(address));
483 return [2]u8{ msb, lsb };483 return [2]u8{ msb, lsb };
484 }484 }
485485
...@@ -508,14 +508,14 @@ const HexWriter = struct {...@@ -508,14 +508,14 @@ const HexWriter = struct {
508508
509 fn Data(address: u32, data: []const u8) Record {509 fn Data(address: u32, data: []const u8) Record {
510 return Record{510 return Record{
511 .address = @intCast(u16, address % 0x10000),511 .address = @as(u16, @intCast(address % 0x10000)),
512 .payload = .{ .Data = data },512 .payload = .{ .Data = data },
513 };513 };
514 }514 }
515515
516 fn Address(address: u32) Record {516 fn Address(address: u32) Record {
517 assert(address > 0xFFFF);517 assert(address > 0xFFFF);
518 const segment = @intCast(u16, address / 0x10000);518 const segment = @as(u16, @intCast(address / 0x10000));
519 if (address > 0xFFFFF) {519 if (address > 0xFFFFF) {
520 return Record{520 return Record{
521 .address = 0,521 .address = 0,
...@@ -540,7 +540,7 @@ const HexWriter = struct {...@@ -540,7 +540,7 @@ const HexWriter = struct {
540 fn checksum(self: Record) u8 {540 fn checksum(self: Record) u8 {
541 const payload_bytes = self.getPayloadBytes();541 const payload_bytes = self.getPayloadBytes();
542542
543 var sum: u8 = @intCast(u8, payload_bytes.len);543 var sum: u8 = @as(u8, @intCast(payload_bytes.len));
544 const parts = addressParts(self.address);544 const parts = addressParts(self.address);
545 sum +%= parts[0];545 sum +%= parts[0];
546 sum +%= parts[1];546 sum +%= parts[1];
...@@ -560,7 +560,7 @@ const HexWriter = struct {...@@ -560,7 +560,7 @@ const HexWriter = struct {
560 assert(payload_bytes.len <= MAX_PAYLOAD_LEN);560 assert(payload_bytes.len <= MAX_PAYLOAD_LEN);
561561
562 const line = try std.fmt.bufPrint(&outbuf, ":{0X:0>2}{1X:0>4}{2X:0>2}{3s}{4X:0>2}" ++ linesep, .{562 const line = try std.fmt.bufPrint(&outbuf, ":{0X:0>2}{1X:0>4}{2X:0>2}{3s}{4X:0>2}" ++ linesep, .{
563 @intCast(u8, payload_bytes.len),563 @as(u8, @intCast(payload_bytes.len)),
564 self.address,564 self.address,
565 @intFromEnum(self.payload),565 @intFromEnum(self.payload),
566 std.fmt.fmtSliceHexUpper(payload_bytes),566 std.fmt.fmtSliceHexUpper(payload_bytes),
...@@ -574,10 +574,10 @@ const HexWriter = struct {...@@ -574,10 +574,10 @@ const HexWriter = struct {
574 var buf: [MAX_PAYLOAD_LEN]u8 = undefined;574 var buf: [MAX_PAYLOAD_LEN]u8 = undefined;
575 var bytes_read: usize = 0;575 var bytes_read: usize = 0;
576 while (bytes_read < segment.fileSize) {576 while (bytes_read < segment.fileSize) {
577 const row_address = @intCast(u32, segment.physicalAddress + bytes_read);577 const row_address = @as(u32, @intCast(segment.physicalAddress + bytes_read));
578578
579 const remaining = segment.fileSize - bytes_read;579 const remaining = segment.fileSize - bytes_read;
580 const to_read = @intCast(usize, @min(remaining, MAX_PAYLOAD_LEN));580 const to_read = @as(usize, @intCast(@min(remaining, MAX_PAYLOAD_LEN)));
581 const did_read = try elf_file.preadAll(buf[0..to_read], segment.elfOffset + bytes_read);581 const did_read = try elf_file.preadAll(buf[0..to_read], segment.elfOffset + bytes_read);
582 if (did_read < to_read) return error.UnexpectedEOF;582 if (did_read < to_read) return error.UnexpectedEOF;
583583
...@@ -593,7 +593,7 @@ const HexWriter = struct {...@@ -593,7 +593,7 @@ const HexWriter = struct {
593 try Record.Address(address).write(self.out_file);593 try Record.Address(address).write(self.out_file);
594 }594 }
595 try record.write(self.out_file);595 try record.write(self.out_file);
596 self.prev_addr = @intCast(u32, record.address + data.len);596 self.prev_addr = @as(u32, @intCast(record.address + data.len));
597 }597 }
598598
599 fn writeEOF(self: HexWriter) File.WriteError!void {599 fn writeEOF(self: HexWriter) File.WriteError!void {
...@@ -814,7 +814,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -814,7 +814,7 @@ fn ElfFile(comptime is_64: bool) type {
814 const need_strings = (idx == header.shstrndx);814 const need_strings = (idx == header.shstrndx);
815815
816 if (need_data or need_strings) {816 if (need_data or need_strings) {
817 const buffer = try allocator.alignedAlloc(u8, section_memory_align, @intCast(usize, section.section.sh_size));817 const buffer = try allocator.alignedAlloc(u8, section_memory_align, @as(usize, @intCast(section.section.sh_size)));
818 const bytes_read = try in_file.preadAll(buffer, section.section.sh_offset);818 const bytes_read = try in_file.preadAll(buffer, section.section.sh_offset);
819 if (bytes_read != section.section.sh_size) return error.TRUNCATED_ELF;819 if (bytes_read != section.section.sh_size) return error.TRUNCATED_ELF;
820 section.payload = buffer;820 section.payload = buffer;
...@@ -831,7 +831,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -831,7 +831,7 @@ fn ElfFile(comptime is_64: bool) type {
831 } else null;831 } else null;
832832
833 if (section.section.sh_name != 0 and header.shstrndx != elf.SHN_UNDEF)833 if (section.section.sh_name != 0 and header.shstrndx != elf.SHN_UNDEF)
834 section.name = std.mem.span(@ptrCast([*:0]const u8, &sections[header.shstrndx].payload.?[section.section.sh_name]));834 section.name = std.mem.span(@as([*:0]const u8, @ptrCast(&sections[header.shstrndx].payload.?[section.section.sh_name])));
835835
836 const category_from_program: SectionCategory = if (section.segment != null) .exe else .debug;836 const category_from_program: SectionCategory = if (section.segment != null) .exe else .debug;
837 section.category = switch (section.section.sh_type) {837 section.category = switch (section.section.sh_type) {
...@@ -935,7 +935,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -935,7 +935,7 @@ fn ElfFile(comptime is_64: bool) type {
935 const update = &sections_update[self.raw_elf_header.e_shstrndx];935 const update = &sections_update[self.raw_elf_header.e_shstrndx];
936936
937 const name: []const u8 = ".gnu_debuglink";937 const name: []const u8 = ".gnu_debuglink";
938 const new_offset = @intCast(u32, strtab.payload.?.len);938 const new_offset = @as(u32, @intCast(strtab.payload.?.len));
939 const buf = try allocator.alignedAlloc(u8, section_memory_align, new_offset + name.len + 1);939 const buf = try allocator.alignedAlloc(u8, section_memory_align, new_offset + name.len + 1);
940 @memcpy(buf[0..new_offset], strtab.payload.?);940 @memcpy(buf[0..new_offset], strtab.payload.?);
941 @memcpy(buf[new_offset..][0..name.len], name);941 @memcpy(buf[new_offset..][0..name.len], name);
...@@ -965,7 +965,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -965,7 +965,7 @@ fn ElfFile(comptime is_64: bool) type {
965 update.payload = payload;965 update.payload = payload;
966 update.section = section.section;966 update.section = section.section;
967 update.section.?.sh_addralign = @alignOf(Elf_Chdr);967 update.section.?.sh_addralign = @alignOf(Elf_Chdr);
968 update.section.?.sh_size = @intCast(Elf_OffSize, payload.len);968 update.section.?.sh_size = @as(Elf_OffSize, @intCast(payload.len));
969 update.section.?.sh_flags |= elf.SHF_COMPRESSED;969 update.section.?.sh_flags |= elf.SHF_COMPRESSED;
970 }970 }
971 }971 }
...@@ -991,7 +991,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -991,7 +991,7 @@ fn ElfFile(comptime is_64: bool) type {
991 const data = std.mem.sliceAsBytes(self.program_segments);991 const data = std.mem.sliceAsBytes(self.program_segments);
992 assert(data.len == @as(usize, updated_elf_header.e_phentsize) * updated_elf_header.e_phnum);992 assert(data.len == @as(usize, updated_elf_header.e_phentsize) * updated_elf_header.e_phnum);
993 cmdbuf.appendAssumeCapacity(.{ .write_data = .{ .data = data, .out_offset = updated_elf_header.e_phoff } });993 cmdbuf.appendAssumeCapacity(.{ .write_data = .{ .data = data, .out_offset = updated_elf_header.e_phoff } });
994 eof_offset = updated_elf_header.e_phoff + @intCast(Elf_OffSize, data.len);994 eof_offset = updated_elf_header.e_phoff + @as(Elf_OffSize, @intCast(data.len));
995 }995 }
996996
997 // update sections and queue payload writes997 // update sections and queue payload writes
...@@ -1032,7 +1032,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -1032,7 +1032,7 @@ fn ElfFile(comptime is_64: bool) type {
1032 dest.sh_info = sections_update[src.sh_info].remap_idx;1032 dest.sh_info = sections_update[src.sh_info].remap_idx;
10331033
1034 if (payload) |data|1034 if (payload) |data|
1035 dest.sh_size = @intCast(Elf_OffSize, data.len);1035 dest.sh_size = @as(Elf_OffSize, @intCast(data.len));
10361036
1037 const addralign = if (src.sh_addralign == 0 or dest.sh_type == elf.SHT_NOBITS) 1 else src.sh_addralign;1037 const addralign = if (src.sh_addralign == 0 or dest.sh_type == elf.SHT_NOBITS) 1 else src.sh_addralign;
1038 dest.sh_offset = std.mem.alignForward(Elf_OffSize, eof_offset, addralign);1038 dest.sh_offset = std.mem.alignForward(Elf_OffSize, eof_offset, addralign);
...@@ -1056,7 +1056,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -1056,7 +1056,7 @@ fn ElfFile(comptime is_64: bool) type {
1056 const data = try allocator.alignedAlloc(u8, section_memory_align, src_data.len);1056 const data = try allocator.alignedAlloc(u8, section_memory_align, src_data.len);
1057 @memcpy(data, src_data);1057 @memcpy(data, src_data);
10581058
1059 const defs = @ptrCast([*]Elf_Verdef, data)[0 .. @intCast(usize, src.sh_size) / @sizeOf(Elf_Verdef)];1059 const defs = @as([*]Elf_Verdef, @ptrCast(data))[0 .. @as(usize, @intCast(src.sh_size)) / @sizeOf(Elf_Verdef)];
1060 for (defs) |*def| {1060 for (defs) |*def| {
1061 if (def.vd_ndx != elf.SHN_UNDEF)1061 if (def.vd_ndx != elf.SHN_UNDEF)
1062 def.vd_ndx = sections_update[src.sh_info].remap_idx;1062 def.vd_ndx = sections_update[src.sh_info].remap_idx;
...@@ -1068,7 +1068,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -1068,7 +1068,7 @@ fn ElfFile(comptime is_64: bool) type {
1068 const data = try allocator.alignedAlloc(u8, section_memory_align, src_data.len);1068 const data = try allocator.alignedAlloc(u8, section_memory_align, src_data.len);
1069 @memcpy(data, src_data);1069 @memcpy(data, src_data);
10701070
1071 const syms = @ptrCast([*]Elf_Sym, data)[0 .. @intCast(usize, src.sh_size) / @sizeOf(Elf_Sym)];1071 const syms = @as([*]Elf_Sym, @ptrCast(data))[0 .. @as(usize, @intCast(src.sh_size)) / @sizeOf(Elf_Sym)];
1072 for (syms) |*sym| {1072 for (syms) |*sym| {
1073 if (sym.st_shndx != elf.SHN_UNDEF and sym.st_shndx < elf.SHN_LORESERVE)1073 if (sym.st_shndx != elf.SHN_UNDEF and sym.st_shndx < elf.SHN_LORESERVE)
1074 sym.st_shndx = sections_update[sym.st_shndx].remap_idx;1074 sym.st_shndx = sections_update[sym.st_shndx].remap_idx;
...@@ -1110,7 +1110,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -1110,7 +1110,7 @@ fn ElfFile(comptime is_64: bool) type {
1110 .sh_flags = 0,1110 .sh_flags = 0,
1111 .sh_addr = 0,1111 .sh_addr = 0,
1112 .sh_offset = eof_offset,1112 .sh_offset = eof_offset,
1113 .sh_size = @intCast(Elf_OffSize, payload.len),1113 .sh_size = @as(Elf_OffSize, @intCast(payload.len)),
1114 .sh_link = elf.SHN_UNDEF,1114 .sh_link = elf.SHN_UNDEF,
1115 .sh_info = elf.SHN_UNDEF,1115 .sh_info = elf.SHN_UNDEF,
1116 .sh_addralign = 4,1116 .sh_addralign = 4,
...@@ -1119,7 +1119,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -1119,7 +1119,7 @@ fn ElfFile(comptime is_64: bool) type {
1119 dest_section_idx += 1;1119 dest_section_idx += 1;
11201120
1121 cmdbuf.appendAssumeCapacity(.{ .write_data = .{ .data = payload, .out_offset = eof_offset } });1121 cmdbuf.appendAssumeCapacity(.{ .write_data = .{ .data = payload, .out_offset = eof_offset } });
1122 eof_offset += @intCast(Elf_OffSize, payload.len);1122 eof_offset += @as(Elf_OffSize, @intCast(payload.len));
1123 }1123 }
11241124
1125 assert(dest_section_idx == new_shnum);1125 assert(dest_section_idx == new_shnum);
...@@ -1232,7 +1232,7 @@ const ElfFileHelper = struct {...@@ -1232,7 +1232,7 @@ const ElfFileHelper = struct {
1232 fused_cmd = null;1232 fused_cmd = null;
1233 }1233 }
1234 if (data.out_offset > offset) {1234 if (data.out_offset > offset) {
1235 consolidated.appendAssumeCapacity(.{ .write_data = .{ .data = zeroes[0..@intCast(usize, data.out_offset - offset)], .out_offset = offset } });1235 consolidated.appendAssumeCapacity(.{ .write_data = .{ .data = zeroes[0..@as(usize, @intCast(data.out_offset - offset))], .out_offset = offset } });
1236 }1236 }
1237 consolidated.appendAssumeCapacity(cmd);1237 consolidated.appendAssumeCapacity(cmd);
1238 offset = data.out_offset + data.data.len;1238 offset = data.out_offset + data.data.len;
...@@ -1249,7 +1249,7 @@ const ElfFileHelper = struct {...@@ -1249,7 +1249,7 @@ const ElfFileHelper = struct {
1249 } else {1249 } else {
1250 consolidated.appendAssumeCapacity(prev);1250 consolidated.appendAssumeCapacity(prev);
1251 if (range.out_offset > offset) {1251 if (range.out_offset > offset) {
1252 consolidated.appendAssumeCapacity(.{ .write_data = .{ .data = zeroes[0..@intCast(usize, range.out_offset - offset)], .out_offset = offset } });1252 consolidated.appendAssumeCapacity(.{ .write_data = .{ .data = zeroes[0..@as(usize, @intCast(range.out_offset - offset))], .out_offset = offset } });
1253 }1253 }
1254 fused_cmd = cmd;1254 fused_cmd = cmd;
1255 }1255 }
...@@ -1286,7 +1286,7 @@ const ElfFileHelper = struct {...@@ -1286,7 +1286,7 @@ const ElfFileHelper = struct {
1286 var section_reader = std.io.limitedReader(in_file.reader(), size);1286 var section_reader = std.io.limitedReader(in_file.reader(), size);
12871287
1288 // allocate as large as decompressed data. if the compression doesn't fit, keep the data uncompressed.1288 // allocate as large as decompressed data. if the compression doesn't fit, keep the data uncompressed.
1289 const compressed_data = try allocator.alignedAlloc(u8, 8, @intCast(usize, size));1289 const compressed_data = try allocator.alignedAlloc(u8, 8, @as(usize, @intCast(size)));
1290 var compressed_stream = std.io.fixedBufferStream(compressed_data);1290 var compressed_stream = std.io.fixedBufferStream(compressed_data);
12911291
1292 try compressed_stream.writer().writeAll(prefix);1292 try compressed_stream.writer().writeAll(prefix);
...@@ -1317,7 +1317,7 @@ const ElfFileHelper = struct {...@@ -1317,7 +1317,7 @@ const ElfFileHelper = struct {
1317 };1317 };
1318 }1318 }
13191319
1320 const compressed_len = @intCast(usize, compressed_stream.getPos() catch unreachable);1320 const compressed_len = @as(usize, @intCast(compressed_stream.getPos() catch unreachable));
1321 const data = allocator.realloc(compressed_data, compressed_len) catch compressed_data;1321 const data = allocator.realloc(compressed_data, compressed_len) catch compressed_data;
1322 return data[0..compressed_len];1322 return data[0..compressed_len];
1323 }1323 }
src/print_air.zig+11-11
...@@ -91,7 +91,7 @@ const Writer = struct {...@@ -91,7 +91,7 @@ const Writer = struct {
91 fn writeAllConstants(w: *Writer, s: anytype) @TypeOf(s).Error!void {91 fn writeAllConstants(w: *Writer, s: anytype) @TypeOf(s).Error!void {
92 for (w.air.instructions.items(.tag), 0..) |tag, i| {92 for (w.air.instructions.items(.tag), 0..) |tag, i| {
93 if (tag != .interned) continue;93 if (tag != .interned) continue;
94 const inst = @intCast(Air.Inst.Index, i);94 const inst = @as(Air.Inst.Index, @intCast(i));
95 try w.writeInst(s, inst);95 try w.writeInst(s, inst);
96 try s.writeByte('\n');96 try s.writeByte('\n');
97 }97 }
...@@ -424,8 +424,8 @@ const Writer = struct {...@@ -424,8 +424,8 @@ const Writer = struct {
424 const mod = w.module;424 const mod = w.module;
425 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;425 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
426 const vector_ty = w.air.getRefType(ty_pl.ty);426 const vector_ty = w.air.getRefType(ty_pl.ty);
427 const len = @intCast(usize, vector_ty.arrayLen(mod));427 const len = @as(usize, @intCast(vector_ty.arrayLen(mod)));
428 const elements = @ptrCast([]const Air.Inst.Ref, w.air.extra[ty_pl.payload..][0..len]);428 const elements = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[ty_pl.payload..][0..len]));
429429
430 try w.writeType(s, vector_ty);430 try w.writeType(s, vector_ty);
431 try s.writeAll(", [");431 try s.writeAll(", [");
...@@ -607,8 +607,8 @@ const Writer = struct {...@@ -607,8 +607,8 @@ const Writer = struct {
607 fn writeAssembly(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {607 fn writeAssembly(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
608 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;608 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
609 const extra = w.air.extraData(Air.Asm, ty_pl.payload);609 const extra = w.air.extraData(Air.Asm, ty_pl.payload);
610 const is_volatile = @truncate(u1, extra.data.flags >> 31) != 0;610 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
611 const clobbers_len = @truncate(u31, extra.data.flags);611 const clobbers_len = @as(u31, @truncate(extra.data.flags));
612 var extra_i: usize = extra.end;612 var extra_i: usize = extra.end;
613 var op_index: usize = 0;613 var op_index: usize = 0;
614614
...@@ -619,9 +619,9 @@ const Writer = struct {...@@ -619,9 +619,9 @@ const Writer = struct {
619 try s.writeAll(", volatile");619 try s.writeAll(", volatile");
620 }620 }
621621
622 const outputs = @ptrCast([]const Air.Inst.Ref, w.air.extra[extra_i..][0..extra.data.outputs_len]);622 const outputs = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[extra_i..][0..extra.data.outputs_len]));
623 extra_i += outputs.len;623 extra_i += outputs.len;
624 const inputs = @ptrCast([]const Air.Inst.Ref, w.air.extra[extra_i..][0..extra.data.inputs_len]);624 const inputs = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[extra_i..][0..extra.data.inputs_len]));
625 extra_i += inputs.len;625 extra_i += inputs.len;
626626
627 for (outputs) |output| {627 for (outputs) |output| {
...@@ -699,7 +699,7 @@ const Writer = struct {...@@ -699,7 +699,7 @@ const Writer = struct {
699 fn writeCall(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {699 fn writeCall(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
700 const pl_op = w.air.instructions.items(.data)[inst].pl_op;700 const pl_op = w.air.instructions.items(.data)[inst].pl_op;
701 const extra = w.air.extraData(Air.Call, pl_op.payload);701 const extra = w.air.extraData(Air.Call, pl_op.payload);
702 const args = @ptrCast([]const Air.Inst.Ref, w.air.extra[extra.end..][0..extra.data.args_len]);702 const args = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[extra.end..][0..extra.data.args_len]));
703 try w.writeOperand(s, inst, 0, pl_op.operand);703 try w.writeOperand(s, inst, 0, pl_op.operand);
704 try s.writeAll(", [");704 try s.writeAll(", [");
705 for (args, 0..) |arg, i| {705 for (args, 0..) |arg, i| {
...@@ -855,7 +855,7 @@ const Writer = struct {...@@ -855,7 +855,7 @@ const Writer = struct {
855855
856 while (case_i < switch_br.data.cases_len) : (case_i += 1) {856 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
857 const case = w.air.extraData(Air.SwitchBr.Case, extra_index);857 const case = w.air.extraData(Air.SwitchBr.Case, extra_index);
858 const items = @ptrCast([]const Air.Inst.Ref, w.air.extra[case.end..][0..case.data.items_len]);858 const items = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[case.end..][0..case.data.items_len]));
859 const case_body = w.air.extra[case.end + items.len ..][0..case.data.body_len];859 const case_body = w.air.extra[case.end + items.len ..][0..case.data.body_len];
860 extra_index = case.end + case.data.items_len + case_body.len;860 extra_index = case.end + case.data.items_len + case_body.len;
861861
...@@ -934,13 +934,13 @@ const Writer = struct {...@@ -934,13 +934,13 @@ const Writer = struct {
934 const small_tomb_bits = Liveness.bpi - 1;934 const small_tomb_bits = Liveness.bpi - 1;
935 const dies = if (w.liveness) |liveness| blk: {935 const dies = if (w.liveness) |liveness| blk: {
936 if (op_index < small_tomb_bits)936 if (op_index < small_tomb_bits)
937 break :blk liveness.operandDies(inst, @intCast(Liveness.OperandInt, op_index));937 break :blk liveness.operandDies(inst, @as(Liveness.OperandInt, @intCast(op_index)));
938 var extra_index = liveness.special.get(inst).?;938 var extra_index = liveness.special.get(inst).?;
939 var tomb_op_index: usize = small_tomb_bits;939 var tomb_op_index: usize = small_tomb_bits;
940 while (true) {940 while (true) {
941 const bits = liveness.extra[extra_index];941 const bits = liveness.extra[extra_index];
942 if (op_index < tomb_op_index + 31) {942 if (op_index < tomb_op_index + 31) {
943 break :blk @truncate(u1, bits >> @intCast(u5, op_index - tomb_op_index)) != 0;943 break :blk @as(u1, @truncate(bits >> @as(u5, @intCast(op_index - tomb_op_index)))) != 0;
944 }944 }
945 if ((bits >> 31) != 0) break :blk false;945 if ((bits >> 31) != 0) break :blk false;
946 extra_index += 1;946 extra_index += 1;
src/print_targets.zig+2-2
...@@ -100,7 +100,7 @@ pub fn cmdTargets(...@@ -100,7 +100,7 @@ pub fn cmdTargets(
100 try jws.objectField(model.name);100 try jws.objectField(model.name);
101 try jws.beginArray();101 try jws.beginArray();
102 for (arch.allFeaturesList(), 0..) |feature, i_usize| {102 for (arch.allFeaturesList(), 0..) |feature, i_usize| {
103 const index = @intCast(Target.Cpu.Feature.Set.Index, i_usize);103 const index = @as(Target.Cpu.Feature.Set.Index, @intCast(i_usize));
104 if (model.features.isEnabled(index)) {104 if (model.features.isEnabled(index)) {
105 try jws.arrayElem();105 try jws.arrayElem();
106 try jws.emitString(feature.name);106 try jws.emitString(feature.name);
...@@ -147,7 +147,7 @@ pub fn cmdTargets(...@@ -147,7 +147,7 @@ pub fn cmdTargets(
147 try jws.objectField("features");147 try jws.objectField("features");
148 try jws.beginArray();148 try jws.beginArray();
149 for (native_target.cpu.arch.allFeaturesList(), 0..) |feature, i_usize| {149 for (native_target.cpu.arch.allFeaturesList(), 0..) |feature, i_usize| {
150 const index = @intCast(Target.Cpu.Feature.Set.Index, i_usize);150 const index = @as(Target.Cpu.Feature.Set.Index, @intCast(i_usize));
151 if (cpu.features.isEnabled(index)) {151 if (cpu.features.isEnabled(index)) {
152 try jws.arrayElem();152 try jws.arrayElem();
153 try jws.emitString(feature.name);153 try jws.emitString(feature.name);
src/print_zir.zig+72-72
...@@ -131,7 +131,7 @@ const Writer = struct {...@@ -131,7 +131,7 @@ const Writer = struct {
131 recurse_blocks: bool,131 recurse_blocks: bool,
132132
133 fn relativeToNodeIndex(self: *Writer, offset: i32) Ast.Node.Index {133 fn relativeToNodeIndex(self: *Writer, offset: i32) Ast.Node.Index {
134 return @bitCast(Ast.Node.Index, offset + @bitCast(i32, self.parent_decl_node));134 return @as(Ast.Node.Index, @bitCast(offset + @as(i32, @bitCast(self.parent_decl_node))));
135 }135 }
136136
137 fn writeInstToStream(137 fn writeInstToStream(
...@@ -542,7 +542,7 @@ const Writer = struct {...@@ -542,7 +542,7 @@ const Writer = struct {
542 }542 }
543543
544 fn writeExtNode(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {544 fn writeExtNode(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
545 const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand));545 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
546 try stream.writeAll(")) ");546 try stream.writeAll(")) ");
547 try self.writeSrc(stream, src);547 try self.writeSrc(stream, src);
548 }548 }
...@@ -631,25 +631,25 @@ const Writer = struct {...@@ -631,25 +631,25 @@ const Writer = struct {
631 var extra_index = extra.end;631 var extra_index = extra.end;
632 if (inst_data.flags.has_sentinel) {632 if (inst_data.flags.has_sentinel) {
633 try stream.writeAll(", ");633 try stream.writeAll(", ");
634 try self.writeInstRef(stream, @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]));634 try self.writeInstRef(stream, @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])));
635 extra_index += 1;635 extra_index += 1;
636 }636 }
637 if (inst_data.flags.has_align) {637 if (inst_data.flags.has_align) {
638 try stream.writeAll(", align(");638 try stream.writeAll(", align(");
639 try self.writeInstRef(stream, @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]));639 try self.writeInstRef(stream, @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])));
640 extra_index += 1;640 extra_index += 1;
641 if (inst_data.flags.has_bit_range) {641 if (inst_data.flags.has_bit_range) {
642 const bit_start = extra_index + @intFromBool(inst_data.flags.has_addrspace);642 const bit_start = extra_index + @intFromBool(inst_data.flags.has_addrspace);
643 try stream.writeAll(":");643 try stream.writeAll(":");
644 try self.writeInstRef(stream, @enumFromInt(Zir.Inst.Ref, self.code.extra[bit_start]));644 try self.writeInstRef(stream, @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[bit_start])));
645 try stream.writeAll(":");645 try stream.writeAll(":");
646 try self.writeInstRef(stream, @enumFromInt(Zir.Inst.Ref, self.code.extra[bit_start + 1]));646 try self.writeInstRef(stream, @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[bit_start + 1])));
647 }647 }
648 try stream.writeAll(")");648 try stream.writeAll(")");
649 }649 }
650 if (inst_data.flags.has_addrspace) {650 if (inst_data.flags.has_addrspace) {
651 try stream.writeAll(", addrspace(");651 try stream.writeAll(", addrspace(");
652 try self.writeInstRef(stream, @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]));652 try self.writeInstRef(stream, @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])));
653 try stream.writeAll(")");653 try stream.writeAll(")");
654 }654 }
655 try stream.writeAll(") ");655 try stream.writeAll(") ");
...@@ -691,7 +691,7 @@ const Writer = struct {...@@ -691,7 +691,7 @@ const Writer = struct {
691 const src = inst_data.src();691 const src = inst_data.src();
692 const number = extra.get();692 const number = extra.get();
693 // TODO improve std.format to be able to print f128 values693 // TODO improve std.format to be able to print f128 values
694 try stream.print("{d}) ", .{@floatCast(f64, number)});694 try stream.print("{d}) ", .{@as(f64, @floatCast(number))});
695 try self.writeSrc(stream, src);695 try self.writeSrc(stream, src);
696 }696 }
697697
...@@ -964,7 +964,7 @@ const Writer = struct {...@@ -964,7 +964,7 @@ const Writer = struct {
964 }964 }
965965
966 fn writePtrCastFull(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {966 fn writePtrCastFull(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
967 const flags = @bitCast(Zir.Inst.FullPtrCastFlags, @truncate(u5, extended.small));967 const flags = @as(Zir.Inst.FullPtrCastFlags, @bitCast(@as(u5, @truncate(extended.small))));
968 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;968 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
969 const src = LazySrcLoc.nodeOffset(extra.node);969 const src = LazySrcLoc.nodeOffset(extra.node);
970 if (flags.ptr_cast) try stream.writeAll("ptr_cast, ");970 if (flags.ptr_cast) try stream.writeAll("ptr_cast, ");
...@@ -980,7 +980,7 @@ const Writer = struct {...@@ -980,7 +980,7 @@ const Writer = struct {
980 }980 }
981981
982 fn writePtrCastNoDest(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {982 fn writePtrCastNoDest(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
983 const flags = @bitCast(Zir.Inst.FullPtrCastFlags, @truncate(u5, extended.small));983 const flags = @as(Zir.Inst.FullPtrCastFlags, @bitCast(@as(u5, @truncate(extended.small))));
984 const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;984 const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
985 const src = LazySrcLoc.nodeOffset(extra.node);985 const src = LazySrcLoc.nodeOffset(extra.node);
986 if (flags.const_cast) try stream.writeAll("const_cast, ");986 if (flags.const_cast) try stream.writeAll("const_cast, ");
...@@ -1103,14 +1103,14 @@ const Writer = struct {...@@ -1103,14 +1103,14 @@ const Writer = struct {
1103 ) !void {1103 ) !void {
1104 const extra = self.code.extraData(Zir.Inst.Asm, extended.operand);1104 const extra = self.code.extraData(Zir.Inst.Asm, extended.operand);
1105 const src = LazySrcLoc.nodeOffset(extra.data.src_node);1105 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
1106 const outputs_len = @truncate(u5, extended.small);1106 const outputs_len = @as(u5, @truncate(extended.small));
1107 const inputs_len = @truncate(u5, extended.small >> 5);1107 const inputs_len = @as(u5, @truncate(extended.small >> 5));
1108 const clobbers_len = @truncate(u5, extended.small >> 10);1108 const clobbers_len = @as(u5, @truncate(extended.small >> 10));
1109 const is_volatile = @truncate(u1, extended.small >> 15) != 0;1109 const is_volatile = @as(u1, @truncate(extended.small >> 15)) != 0;
11101110
1111 try self.writeFlag(stream, "volatile, ", is_volatile);1111 try self.writeFlag(stream, "volatile, ", is_volatile);
1112 if (tmpl_is_expr) {1112 if (tmpl_is_expr) {
1113 try self.writeInstRef(stream, @enumFromInt(Zir.Inst.Ref, extra.data.asm_source));1113 try self.writeInstRef(stream, @as(Zir.Inst.Ref, @enumFromInt(extra.data.asm_source)));
1114 try stream.writeAll(", ");1114 try stream.writeAll(", ");
1115 } else {1115 } else {
1116 const asm_source = self.code.nullTerminatedString(extra.data.asm_source);1116 const asm_source = self.code.nullTerminatedString(extra.data.asm_source);
...@@ -1126,7 +1126,7 @@ const Writer = struct {...@@ -1126,7 +1126,7 @@ const Writer = struct {
1126 const output = self.code.extraData(Zir.Inst.Asm.Output, extra_i);1126 const output = self.code.extraData(Zir.Inst.Asm.Output, extra_i);
1127 extra_i = output.end;1127 extra_i = output.end;
11281128
1129 const is_type = @truncate(u1, output_type_bits) != 0;1129 const is_type = @as(u1, @truncate(output_type_bits)) != 0;
1130 output_type_bits >>= 1;1130 output_type_bits >>= 1;
11311131
1132 const name = self.code.nullTerminatedString(output.data.name);1132 const name = self.code.nullTerminatedString(output.data.name);
...@@ -1205,7 +1205,7 @@ const Writer = struct {...@@ -1205,7 +1205,7 @@ const Writer = struct {
1205 if (extra.data.flags.ensure_result_used) {1205 if (extra.data.flags.ensure_result_used) {
1206 try stream.writeAll("nodiscard ");1206 try stream.writeAll("nodiscard ");
1207 }1207 }
1208 try stream.print(".{s}, ", .{@tagName(@enumFromInt(std.builtin.CallModifier, extra.data.flags.packed_modifier))});1208 try stream.print(".{s}, ", .{@tagName(@as(std.builtin.CallModifier, @enumFromInt(extra.data.flags.packed_modifier)))});
1209 switch (kind) {1209 switch (kind) {
1210 .direct => try self.writeInstRef(stream, extra.data.callee),1210 .direct => try self.writeInstRef(stream, extra.data.callee),
1211 .field => {1211 .field => {
...@@ -1280,12 +1280,12 @@ const Writer = struct {...@@ -1280,12 +1280,12 @@ const Writer = struct {
1280 }1280 }
12811281
1282 fn writeStructDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1282 fn writeStructDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1283 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);1283 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
12841284
1285 var extra_index: usize = extended.operand;1285 var extra_index: usize = extended.operand;
12861286
1287 const src_node: ?i32 = if (small.has_src_node) blk: {1287 const src_node: ?i32 = if (small.has_src_node) blk: {
1288 const src_node = @bitCast(i32, self.code.extra[extra_index]);1288 const src_node = @as(i32, @bitCast(self.code.extra[extra_index]));
1289 extra_index += 1;1289 extra_index += 1;
1290 break :blk src_node;1290 break :blk src_node;
1291 } else null;1291 } else null;
...@@ -1313,7 +1313,7 @@ const Writer = struct {...@@ -1313,7 +1313,7 @@ const Writer = struct {
1313 extra_index += 1;1313 extra_index += 1;
1314 try stream.writeAll("Packed(");1314 try stream.writeAll("Packed(");
1315 if (backing_int_body_len == 0) {1315 if (backing_int_body_len == 0) {
1316 const backing_int_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);1316 const backing_int_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
1317 extra_index += 1;1317 extra_index += 1;
1318 try self.writeInstRef(stream, backing_int_ref);1318 try self.writeInstRef(stream, backing_int_ref);
1319 } else {1319 } else {
...@@ -1369,13 +1369,13 @@ const Writer = struct {...@@ -1369,13 +1369,13 @@ const Writer = struct {
1369 cur_bit_bag = self.code.extra[bit_bag_index];1369 cur_bit_bag = self.code.extra[bit_bag_index];
1370 bit_bag_index += 1;1370 bit_bag_index += 1;
1371 }1371 }
1372 const has_align = @truncate(u1, cur_bit_bag) != 0;1372 const has_align = @as(u1, @truncate(cur_bit_bag)) != 0;
1373 cur_bit_bag >>= 1;1373 cur_bit_bag >>= 1;
1374 const has_default = @truncate(u1, cur_bit_bag) != 0;1374 const has_default = @as(u1, @truncate(cur_bit_bag)) != 0;
1375 cur_bit_bag >>= 1;1375 cur_bit_bag >>= 1;
1376 const is_comptime = @truncate(u1, cur_bit_bag) != 0;1376 const is_comptime = @as(u1, @truncate(cur_bit_bag)) != 0;
1377 cur_bit_bag >>= 1;1377 cur_bit_bag >>= 1;
1378 const has_type_body = @truncate(u1, cur_bit_bag) != 0;1378 const has_type_body = @as(u1, @truncate(cur_bit_bag)) != 0;
1379 cur_bit_bag >>= 1;1379 cur_bit_bag >>= 1;
13801380
1381 var field_name: u32 = 0;1381 var field_name: u32 = 0;
...@@ -1395,7 +1395,7 @@ const Writer = struct {...@@ -1395,7 +1395,7 @@ const Writer = struct {
1395 if (has_type_body) {1395 if (has_type_body) {
1396 fields[field_i].type_len = self.code.extra[extra_index];1396 fields[field_i].type_len = self.code.extra[extra_index];
1397 } else {1397 } else {
1398 fields[field_i].type = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);1398 fields[field_i].type = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
1399 }1399 }
1400 extra_index += 1;1400 extra_index += 1;
14011401
...@@ -1469,18 +1469,18 @@ const Writer = struct {...@@ -1469,18 +1469,18 @@ const Writer = struct {
1469 }1469 }
14701470
1471 fn writeUnionDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1471 fn writeUnionDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1472 const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small);1472 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));
14731473
1474 var extra_index: usize = extended.operand;1474 var extra_index: usize = extended.operand;
14751475
1476 const src_node: ?i32 = if (small.has_src_node) blk: {1476 const src_node: ?i32 = if (small.has_src_node) blk: {
1477 const src_node = @bitCast(i32, self.code.extra[extra_index]);1477 const src_node = @as(i32, @bitCast(self.code.extra[extra_index]));
1478 extra_index += 1;1478 extra_index += 1;
1479 break :blk src_node;1479 break :blk src_node;
1480 } else null;1480 } else null;
14811481
1482 const tag_type_ref = if (small.has_tag_type) blk: {1482 const tag_type_ref = if (small.has_tag_type) blk: {
1483 const tag_type_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);1483 const tag_type_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
1484 extra_index += 1;1484 extra_index += 1;
1485 break :blk tag_type_ref;1485 break :blk tag_type_ref;
1486 } else .none;1486 } else .none;
...@@ -1557,13 +1557,13 @@ const Writer = struct {...@@ -1557,13 +1557,13 @@ const Writer = struct {
1557 cur_bit_bag = self.code.extra[bit_bag_index];1557 cur_bit_bag = self.code.extra[bit_bag_index];
1558 bit_bag_index += 1;1558 bit_bag_index += 1;
1559 }1559 }
1560 const has_type = @truncate(u1, cur_bit_bag) != 0;1560 const has_type = @as(u1, @truncate(cur_bit_bag)) != 0;
1561 cur_bit_bag >>= 1;1561 cur_bit_bag >>= 1;
1562 const has_align = @truncate(u1, cur_bit_bag) != 0;1562 const has_align = @as(u1, @truncate(cur_bit_bag)) != 0;
1563 cur_bit_bag >>= 1;1563 cur_bit_bag >>= 1;
1564 const has_value = @truncate(u1, cur_bit_bag) != 0;1564 const has_value = @as(u1, @truncate(cur_bit_bag)) != 0;
1565 cur_bit_bag >>= 1;1565 cur_bit_bag >>= 1;
1566 const unused = @truncate(u1, cur_bit_bag) != 0;1566 const unused = @as(u1, @truncate(cur_bit_bag)) != 0;
1567 cur_bit_bag >>= 1;1567 cur_bit_bag >>= 1;
15681568
1569 _ = unused;1569 _ = unused;
...@@ -1578,14 +1578,14 @@ const Writer = struct {...@@ -1578,14 +1578,14 @@ const Writer = struct {
1578 try stream.print("{}", .{std.zig.fmtId(field_name)});1578 try stream.print("{}", .{std.zig.fmtId(field_name)});
15791579
1580 if (has_type) {1580 if (has_type) {
1581 const field_type = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);1581 const field_type = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
1582 extra_index += 1;1582 extra_index += 1;
15831583
1584 try stream.writeAll(": ");1584 try stream.writeAll(": ");
1585 try self.writeInstRef(stream, field_type);1585 try self.writeInstRef(stream, field_type);
1586 }1586 }
1587 if (has_align) {1587 if (has_align) {
1588 const align_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);1588 const align_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
1589 extra_index += 1;1589 extra_index += 1;
15901590
1591 try stream.writeAll(" align(");1591 try stream.writeAll(" align(");
...@@ -1593,7 +1593,7 @@ const Writer = struct {...@@ -1593,7 +1593,7 @@ const Writer = struct {
1593 try stream.writeAll(")");1593 try stream.writeAll(")");
1594 }1594 }
1595 if (has_value) {1595 if (has_value) {
1596 const default_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);1596 const default_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
1597 extra_index += 1;1597 extra_index += 1;
15981598
1599 try stream.writeAll(" = ");1599 try stream.writeAll(" = ");
...@@ -1621,13 +1621,13 @@ const Writer = struct {...@@ -1621,13 +1621,13 @@ const Writer = struct {
1621 cur_bit_bag = self.code.extra[bit_bag_index];1621 cur_bit_bag = self.code.extra[bit_bag_index];
1622 bit_bag_index += 1;1622 bit_bag_index += 1;
1623 }1623 }
1624 const is_pub = @truncate(u1, cur_bit_bag) != 0;1624 const is_pub = @as(u1, @truncate(cur_bit_bag)) != 0;
1625 cur_bit_bag >>= 1;1625 cur_bit_bag >>= 1;
1626 const is_exported = @truncate(u1, cur_bit_bag) != 0;1626 const is_exported = @as(u1, @truncate(cur_bit_bag)) != 0;
1627 cur_bit_bag >>= 1;1627 cur_bit_bag >>= 1;
1628 const has_align = @truncate(u1, cur_bit_bag) != 0;1628 const has_align = @as(u1, @truncate(cur_bit_bag)) != 0;
1629 cur_bit_bag >>= 1;1629 cur_bit_bag >>= 1;
1630 const has_section_or_addrspace = @truncate(u1, cur_bit_bag) != 0;1630 const has_section_or_addrspace = @as(u1, @truncate(cur_bit_bag)) != 0;
1631 cur_bit_bag >>= 1;1631 cur_bit_bag >>= 1;
16321632
1633 const sub_index = extra_index;1633 const sub_index = extra_index;
...@@ -1644,23 +1644,23 @@ const Writer = struct {...@@ -1644,23 +1644,23 @@ const Writer = struct {
1644 extra_index += 1;1644 extra_index += 1;
16451645
1646 const align_inst: Zir.Inst.Ref = if (!has_align) .none else inst: {1646 const align_inst: Zir.Inst.Ref = if (!has_align) .none else inst: {
1647 const inst = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);1647 const inst = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
1648 extra_index += 1;1648 extra_index += 1;
1649 break :inst inst;1649 break :inst inst;
1650 };1650 };
1651 const section_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: {1651 const section_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: {
1652 const inst = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);1652 const inst = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
1653 extra_index += 1;1653 extra_index += 1;
1654 break :inst inst;1654 break :inst inst;
1655 };1655 };
1656 const addrspace_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: {1656 const addrspace_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: {
1657 const inst = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);1657 const inst = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
1658 extra_index += 1;1658 extra_index += 1;
1659 break :inst inst;1659 break :inst inst;
1660 };1660 };
16611661
1662 const pub_str = if (is_pub) "pub " else "";1662 const pub_str = if (is_pub) "pub " else "";
1663 const hash_bytes = @bitCast([16]u8, hash_u32s.*);1663 const hash_bytes = @as([16]u8, @bitCast(hash_u32s.*));
1664 if (decl_name_index == 0) {1664 if (decl_name_index == 0) {
1665 try stream.writeByteNTimes(' ', self.indent);1665 try stream.writeByteNTimes(' ', self.indent);
1666 const name = if (is_exported) "usingnamespace" else "comptime";1666 const name = if (is_exported) "usingnamespace" else "comptime";
...@@ -1728,17 +1728,17 @@ const Writer = struct {...@@ -1728,17 +1728,17 @@ const Writer = struct {
1728 }1728 }
17291729
1730 fn writeEnumDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1730 fn writeEnumDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1731 const small = @bitCast(Zir.Inst.EnumDecl.Small, extended.small);1731 const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small));
1732 var extra_index: usize = extended.operand;1732 var extra_index: usize = extended.operand;
17331733
1734 const src_node: ?i32 = if (small.has_src_node) blk: {1734 const src_node: ?i32 = if (small.has_src_node) blk: {
1735 const src_node = @bitCast(i32, self.code.extra[extra_index]);1735 const src_node = @as(i32, @bitCast(self.code.extra[extra_index]));
1736 extra_index += 1;1736 extra_index += 1;
1737 break :blk src_node;1737 break :blk src_node;
1738 } else null;1738 } else null;
17391739
1740 const tag_type_ref = if (small.has_tag_type) blk: {1740 const tag_type_ref = if (small.has_tag_type) blk: {
1741 const tag_type_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);1741 const tag_type_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
1742 extra_index += 1;1742 extra_index += 1;
1743 break :blk tag_type_ref;1743 break :blk tag_type_ref;
1744 } else .none;1744 } else .none;
...@@ -1808,7 +1808,7 @@ const Writer = struct {...@@ -1808,7 +1808,7 @@ const Writer = struct {
1808 cur_bit_bag = self.code.extra[bit_bag_index];1808 cur_bit_bag = self.code.extra[bit_bag_index];
1809 bit_bag_index += 1;1809 bit_bag_index += 1;
1810 }1810 }
1811 const has_tag_value = @truncate(u1, cur_bit_bag) != 0;1811 const has_tag_value = @as(u1, @truncate(cur_bit_bag)) != 0;
1812 cur_bit_bag >>= 1;1812 cur_bit_bag >>= 1;
18131813
1814 const field_name = self.code.nullTerminatedString(self.code.extra[extra_index]);1814 const field_name = self.code.nullTerminatedString(self.code.extra[extra_index]);
...@@ -1823,7 +1823,7 @@ const Writer = struct {...@@ -1823,7 +1823,7 @@ const Writer = struct {
1823 try stream.print("{}", .{std.zig.fmtId(field_name)});1823 try stream.print("{}", .{std.zig.fmtId(field_name)});
18241824
1825 if (has_tag_value) {1825 if (has_tag_value) {
1826 const tag_value_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);1826 const tag_value_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
1827 extra_index += 1;1827 extra_index += 1;
18281828
1829 try stream.writeAll(" = ");1829 try stream.writeAll(" = ");
...@@ -1844,11 +1844,11 @@ const Writer = struct {...@@ -1844,11 +1844,11 @@ const Writer = struct {
1844 stream: anytype,1844 stream: anytype,
1845 extended: Zir.Inst.Extended.InstData,1845 extended: Zir.Inst.Extended.InstData,
1846 ) !void {1846 ) !void {
1847 const small = @bitCast(Zir.Inst.OpaqueDecl.Small, extended.small);1847 const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small));
1848 var extra_index: usize = extended.operand;1848 var extra_index: usize = extended.operand;
18491849
1850 const src_node: ?i32 = if (small.has_src_node) blk: {1850 const src_node: ?i32 = if (small.has_src_node) blk: {
1851 const src_node = @bitCast(i32, self.code.extra[extra_index]);1851 const src_node = @as(i32, @bitCast(self.code.extra[extra_index]));
1852 extra_index += 1;1852 extra_index += 1;
1853 break :blk src_node;1853 break :blk src_node;
1854 } else null;1854 } else null;
...@@ -1892,7 +1892,7 @@ const Writer = struct {...@@ -1892,7 +1892,7 @@ const Writer = struct {
1892 try stream.writeAll("{\n");1892 try stream.writeAll("{\n");
1893 self.indent += 2;1893 self.indent += 2;
18941894
1895 var extra_index = @intCast(u32, extra.end);1895 var extra_index = @as(u32, @intCast(extra.end));
1896 const extra_index_end = extra_index + (extra.data.fields_len * 2);1896 const extra_index_end = extra_index + (extra.data.fields_len * 2);
1897 while (extra_index < extra_index_end) : (extra_index += 2) {1897 while (extra_index < extra_index_end) : (extra_index += 2) {
1898 const str_index = self.code.extra[extra_index];1898 const str_index = self.code.extra[extra_index];
...@@ -1945,7 +1945,7 @@ const Writer = struct {...@@ -1945,7 +1945,7 @@ const Writer = struct {
1945 else => break :else_prong,1945 else => break :else_prong,
1946 };1946 };
19471947
1948 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, self.code.extra[extra_index]);1948 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(self.code.extra[extra_index]));
1949 const capture_text = switch (info.capture) {1949 const capture_text = switch (info.capture) {
1950 .none => "",1950 .none => "",
1951 .by_val => "by_val ",1951 .by_val => "by_val ",
...@@ -1966,9 +1966,9 @@ const Writer = struct {...@@ -1966,9 +1966,9 @@ const Writer = struct {
1966 const scalar_cases_len = extra.data.bits.scalar_cases_len;1966 const scalar_cases_len = extra.data.bits.scalar_cases_len;
1967 var scalar_i: usize = 0;1967 var scalar_i: usize = 0;
1968 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {1968 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
1969 const item_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);1969 const item_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
1970 extra_index += 1;1970 extra_index += 1;
1971 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, self.code.extra[extra_index]);1971 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(self.code.extra[extra_index]));
1972 extra_index += 1;1972 extra_index += 1;
1973 const body = self.code.extra[extra_index..][0..info.body_len];1973 const body = self.code.extra[extra_index..][0..info.body_len];
1974 extra_index += info.body_len;1974 extra_index += info.body_len;
...@@ -1993,7 +1993,7 @@ const Writer = struct {...@@ -1993,7 +1993,7 @@ const Writer = struct {
1993 extra_index += 1;1993 extra_index += 1;
1994 const ranges_len = self.code.extra[extra_index];1994 const ranges_len = self.code.extra[extra_index];
1995 extra_index += 1;1995 extra_index += 1;
1996 const info = @bitCast(Zir.Inst.SwitchBlock.ProngInfo, self.code.extra[extra_index]);1996 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(self.code.extra[extra_index]));
1997 extra_index += 1;1997 extra_index += 1;
1998 const items = self.code.refSlice(extra_index, items_len);1998 const items = self.code.refSlice(extra_index, items_len);
1999 extra_index += items_len;1999 extra_index += items_len;
...@@ -2014,9 +2014,9 @@ const Writer = struct {...@@ -2014,9 +2014,9 @@ const Writer = struct {
20142014
2015 var range_i: usize = 0;2015 var range_i: usize = 0;
2016 while (range_i < ranges_len) : (range_i += 1) {2016 while (range_i < ranges_len) : (range_i += 1) {
2017 const item_first = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);2017 const item_first = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
2018 extra_index += 1;2018 extra_index += 1;
2019 const item_last = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);2019 const item_last = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
2020 extra_index += 1;2020 extra_index += 1;
20212021
2022 if (range_i != 0 or items.len != 0) {2022 if (range_i != 0 or items.len != 0) {
...@@ -2117,7 +2117,7 @@ const Writer = struct {...@@ -2117,7 +2117,7 @@ const Writer = struct {
2117 ret_ty_ref = .void_type;2117 ret_ty_ref = .void_type;
2118 },2118 },
2119 1 => {2119 1 => {
2120 ret_ty_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);2120 ret_ty_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
2121 extra_index += 1;2121 extra_index += 1;
2122 },2122 },
2123 else => {2123 else => {
...@@ -2188,7 +2188,7 @@ const Writer = struct {...@@ -2188,7 +2188,7 @@ const Writer = struct {
2188 align_body = self.code.extra[extra_index..][0..body_len];2188 align_body = self.code.extra[extra_index..][0..body_len];
2189 extra_index += align_body.len;2189 extra_index += align_body.len;
2190 } else if (extra.data.bits.has_align_ref) {2190 } else if (extra.data.bits.has_align_ref) {
2191 align_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);2191 align_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
2192 extra_index += 1;2192 extra_index += 1;
2193 }2193 }
2194 if (extra.data.bits.has_addrspace_body) {2194 if (extra.data.bits.has_addrspace_body) {
...@@ -2197,7 +2197,7 @@ const Writer = struct {...@@ -2197,7 +2197,7 @@ const Writer = struct {
2197 addrspace_body = self.code.extra[extra_index..][0..body_len];2197 addrspace_body = self.code.extra[extra_index..][0..body_len];
2198 extra_index += addrspace_body.len;2198 extra_index += addrspace_body.len;
2199 } else if (extra.data.bits.has_addrspace_ref) {2199 } else if (extra.data.bits.has_addrspace_ref) {
2200 addrspace_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);2200 addrspace_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
2201 extra_index += 1;2201 extra_index += 1;
2202 }2202 }
2203 if (extra.data.bits.has_section_body) {2203 if (extra.data.bits.has_section_body) {
...@@ -2206,7 +2206,7 @@ const Writer = struct {...@@ -2206,7 +2206,7 @@ const Writer = struct {
2206 section_body = self.code.extra[extra_index..][0..body_len];2206 section_body = self.code.extra[extra_index..][0..body_len];
2207 extra_index += section_body.len;2207 extra_index += section_body.len;
2208 } else if (extra.data.bits.has_section_ref) {2208 } else if (extra.data.bits.has_section_ref) {
2209 section_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);2209 section_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
2210 extra_index += 1;2210 extra_index += 1;
2211 }2211 }
2212 if (extra.data.bits.has_cc_body) {2212 if (extra.data.bits.has_cc_body) {
...@@ -2215,7 +2215,7 @@ const Writer = struct {...@@ -2215,7 +2215,7 @@ const Writer = struct {
2215 cc_body = self.code.extra[extra_index..][0..body_len];2215 cc_body = self.code.extra[extra_index..][0..body_len];
2216 extra_index += cc_body.len;2216 extra_index += cc_body.len;
2217 } else if (extra.data.bits.has_cc_ref) {2217 } else if (extra.data.bits.has_cc_ref) {
2218 cc_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);2218 cc_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
2219 extra_index += 1;2219 extra_index += 1;
2220 }2220 }
2221 if (extra.data.bits.has_ret_ty_body) {2221 if (extra.data.bits.has_ret_ty_body) {
...@@ -2224,7 +2224,7 @@ const Writer = struct {...@@ -2224,7 +2224,7 @@ const Writer = struct {
2224 ret_ty_body = self.code.extra[extra_index..][0..body_len];2224 ret_ty_body = self.code.extra[extra_index..][0..body_len];
2225 extra_index += ret_ty_body.len;2225 extra_index += ret_ty_body.len;
2226 } else if (extra.data.bits.has_ret_ty_ref) {2226 } else if (extra.data.bits.has_ret_ty_ref) {
2227 ret_ty_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);2227 ret_ty_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
2228 extra_index += 1;2228 extra_index += 1;
2229 }2229 }
22302230
...@@ -2266,7 +2266,7 @@ const Writer = struct {...@@ -2266,7 +2266,7 @@ const Writer = struct {
22662266
2267 fn writeVarExtended(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {2267 fn writeVarExtended(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
2268 const extra = self.code.extraData(Zir.Inst.ExtendedVar, extended.operand);2268 const extra = self.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
2269 const small = @bitCast(Zir.Inst.ExtendedVar.Small, extended.small);2269 const small = @as(Zir.Inst.ExtendedVar.Small, @bitCast(extended.small));
22702270
2271 try self.writeInstRef(stream, extra.data.var_type);2271 try self.writeInstRef(stream, extra.data.var_type);
22722272
...@@ -2277,12 +2277,12 @@ const Writer = struct {...@@ -2277,12 +2277,12 @@ const Writer = struct {
2277 try stream.print(", lib_name=\"{}\"", .{std.zig.fmtEscapes(lib_name)});2277 try stream.print(", lib_name=\"{}\"", .{std.zig.fmtEscapes(lib_name)});
2278 }2278 }
2279 const align_inst: Zir.Inst.Ref = if (!small.has_align) .none else blk: {2279 const align_inst: Zir.Inst.Ref = if (!small.has_align) .none else blk: {
2280 const align_inst = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);2280 const align_inst = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
2281 extra_index += 1;2281 extra_index += 1;
2282 break :blk align_inst;2282 break :blk align_inst;
2283 };2283 };
2284 const init_inst: Zir.Inst.Ref = if (!small.has_init) .none else blk: {2284 const init_inst: Zir.Inst.Ref = if (!small.has_init) .none else blk: {
2285 const init_inst = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);2285 const init_inst = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
2286 extra_index += 1;2286 extra_index += 1;
2287 break :blk init_inst;2287 break :blk init_inst;
2288 };2288 };
...@@ -2295,17 +2295,17 @@ const Writer = struct {...@@ -2295,17 +2295,17 @@ const Writer = struct {
22952295
2296 fn writeAllocExtended(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {2296 fn writeAllocExtended(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
2297 const extra = self.code.extraData(Zir.Inst.AllocExtended, extended.operand);2297 const extra = self.code.extraData(Zir.Inst.AllocExtended, extended.operand);
2298 const small = @bitCast(Zir.Inst.AllocExtended.Small, extended.small);2298 const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small));
2299 const src = LazySrcLoc.nodeOffset(extra.data.src_node);2299 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
23002300
2301 var extra_index: usize = extra.end;2301 var extra_index: usize = extra.end;
2302 const type_inst: Zir.Inst.Ref = if (!small.has_type) .none else blk: {2302 const type_inst: Zir.Inst.Ref = if (!small.has_type) .none else blk: {
2303 const type_inst = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);2303 const type_inst = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
2304 extra_index += 1;2304 extra_index += 1;
2305 break :blk type_inst;2305 break :blk type_inst;
2306 };2306 };
2307 const align_inst: Zir.Inst.Ref = if (!small.has_align) .none else blk: {2307 const align_inst: Zir.Inst.Ref = if (!small.has_align) .none else blk: {
2308 const align_inst = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);2308 const align_inst = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
2309 extra_index += 1;2309 extra_index += 1;
2310 break :blk align_inst;2310 break :blk align_inst;
2311 };2311 };
...@@ -2473,8 +2473,8 @@ const Writer = struct {...@@ -2473,8 +2473,8 @@ const Writer = struct {
2473 try stream.writeAll(") ");2473 try stream.writeAll(") ");
2474 if (body.len != 0) {2474 if (body.len != 0) {
2475 try stream.print("(lbrace={d}:{d},rbrace={d}:{d}) ", .{2475 try stream.print("(lbrace={d}:{d},rbrace={d}:{d}) ", .{
2476 src_locs.lbrace_line + 1, @truncate(u16, src_locs.columns) + 1,2476 src_locs.lbrace_line + 1, @as(u16, @truncate(src_locs.columns)) + 1,
2477 src_locs.rbrace_line + 1, @truncate(u16, src_locs.columns >> 16) + 1,2477 src_locs.rbrace_line + 1, @as(u16, @truncate(src_locs.columns >> 16)) + 1,
2478 });2478 });
2479 }2479 }
2480 try self.writeSrc(stream, src);2480 try self.writeSrc(stream, src);
...@@ -2507,7 +2507,7 @@ const Writer = struct {...@@ -2507,7 +2507,7 @@ const Writer = struct {
25072507
2508 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {2508 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {
2509 const i = @intFromEnum(ref);2509 const i = @intFromEnum(ref);
2510 if (i < InternPool.static_len) return stream.print("@{}", .{@enumFromInt(InternPool.Index, i)});2510 if (i < InternPool.static_len) return stream.print("@{}", .{@as(InternPool.Index, @enumFromInt(i))});
2511 return self.writeInstIndex(stream, i - InternPool.static_len);2511 return self.writeInstIndex(stream, i - InternPool.static_len);
2512 }2512 }
25132513
src/register_manager.zig+2-2
...@@ -427,13 +427,13 @@ const MockRegister3 = enum(u3) {...@@ -427,13 +427,13 @@ const MockRegister3 = enum(u3) {
427427
428 pub fn id(reg: MockRegister3) u3 {428 pub fn id(reg: MockRegister3) u3 {
429 return switch (@intFromEnum(reg)) {429 return switch (@intFromEnum(reg)) {
430 0...3 => @as(u3, @truncate(u2, @intFromEnum(reg))),430 0...3 => @as(u3, @as(u2, @truncate(@intFromEnum(reg)))),
431 4...7 => @intFromEnum(reg),431 4...7 => @intFromEnum(reg),
432 };432 };
433 }433 }
434434
435 pub fn enc(reg: MockRegister3) u2 {435 pub fn enc(reg: MockRegister3) u2 {
436 return @truncate(u2, @intFromEnum(reg));436 return @as(u2, @truncate(@intFromEnum(reg)));
437 }437 }
438438
439 const gp_regs = [_]MockRegister3{ .r0, .r1, .r2, .r3 };439 const gp_regs = [_]MockRegister3{ .r0, .r1, .r2, .r3 };
src/tracy.zig+3-3
...@@ -132,7 +132,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type {...@@ -132,7 +132,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type {
132 }132 }
133133
134 fn allocFn(ptr: *anyopaque, len: usize, ptr_align: u8, ret_addr: usize) ?[*]u8 {134 fn allocFn(ptr: *anyopaque, len: usize, ptr_align: u8, ret_addr: usize) ?[*]u8 {
135 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ptr));135 const self: *Self = @ptrCast(@alignCast(ptr));
136 const result = self.parent_allocator.rawAlloc(len, ptr_align, ret_addr);136 const result = self.parent_allocator.rawAlloc(len, ptr_align, ret_addr);
137 if (result) |data| {137 if (result) |data| {
138 if (len != 0) {138 if (len != 0) {
...@@ -149,7 +149,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type {...@@ -149,7 +149,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type {
149 }149 }
150150
151 fn resizeFn(ptr: *anyopaque, buf: []u8, buf_align: u8, new_len: usize, ret_addr: usize) bool {151 fn resizeFn(ptr: *anyopaque, buf: []u8, buf_align: u8, new_len: usize, ret_addr: usize) bool {
152 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ptr));152 const self: *Self = @ptrCast(@alignCast(ptr));
153 if (self.parent_allocator.rawResize(buf, buf_align, new_len, ret_addr)) {153 if (self.parent_allocator.rawResize(buf, buf_align, new_len, ret_addr)) {
154 if (name) |n| {154 if (name) |n| {
155 freeNamed(buf.ptr, n);155 freeNamed(buf.ptr, n);
...@@ -168,7 +168,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type {...@@ -168,7 +168,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type {
168 }168 }
169169
170 fn freeFn(ptr: *anyopaque, buf: []u8, buf_align: u8, ret_addr: usize) void {170 fn freeFn(ptr: *anyopaque, buf: []u8, buf_align: u8, ret_addr: usize) void {
171 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ptr));171 const self: *Self = @ptrCast(@alignCast(ptr));
172 self.parent_allocator.rawFree(buf, buf_align, ret_addr);172 self.parent_allocator.rawFree(buf, buf_align, ret_addr);
173 // this condition is to handle free being called on an empty slice that was never even allocated173 // this condition is to handle free being called on an empty slice that was never even allocated
174 // example case: `std.process.getSelfExeSharedLibPaths` can return `&[_][:0]u8{}`174 // example case: `std.process.getSelfExeSharedLibPaths` can return `&[_][:0]u8{}`
src/translate_c.zig+237-237
...@@ -467,7 +467,7 @@ fn prepopulateGlobalNameTable(ast_unit: *clang.ASTUnit, c: *Context) !void {...@@ -467,7 +467,7 @@ fn prepopulateGlobalNameTable(ast_unit: *clang.ASTUnit, c: *Context) !void {
467 const entity = it.deref();467 const entity = it.deref();
468 switch (entity.getKind()) {468 switch (entity.getKind()) {
469 .MacroDefinitionKind => {469 .MacroDefinitionKind => {
470 const macro = @ptrCast(*clang.MacroDefinitionRecord, entity);470 const macro = @as(*clang.MacroDefinitionRecord, @ptrCast(entity));
471 const raw_name = macro.getName_getNameStart();471 const raw_name = macro.getName_getNameStart();
472 const name = try c.str(raw_name);472 const name = try c.str(raw_name);
473473
...@@ -481,13 +481,13 @@ fn prepopulateGlobalNameTable(ast_unit: *clang.ASTUnit, c: *Context) !void {...@@ -481,13 +481,13 @@ fn prepopulateGlobalNameTable(ast_unit: *clang.ASTUnit, c: *Context) !void {
481}481}
482482
483fn declVisitorNamesOnlyC(context: ?*anyopaque, decl: *const clang.Decl) callconv(.C) bool {483fn declVisitorNamesOnlyC(context: ?*anyopaque, decl: *const clang.Decl) callconv(.C) bool {
484 const c = @ptrCast(*Context, @alignCast(@alignOf(Context), context));484 const c: *Context = @ptrCast(@alignCast(context));
485 declVisitorNamesOnly(c, decl) catch return false;485 declVisitorNamesOnly(c, decl) catch return false;
486 return true;486 return true;
487}487}
488488
489fn declVisitorC(context: ?*anyopaque, decl: *const clang.Decl) callconv(.C) bool {489fn declVisitorC(context: ?*anyopaque, decl: *const clang.Decl) callconv(.C) bool {
490 const c = @ptrCast(*Context, @alignCast(@alignOf(Context), context));490 const c: *Context = @ptrCast(@alignCast(context));
491 declVisitor(c, decl) catch return false;491 declVisitor(c, decl) catch return false;
492 return true;492 return true;
493}493}
...@@ -499,37 +499,37 @@ fn declVisitorNamesOnly(c: *Context, decl: *const clang.Decl) Error!void {...@@ -499,37 +499,37 @@ fn declVisitorNamesOnly(c: *Context, decl: *const clang.Decl) Error!void {
499499
500 // Check for typedefs with unnamed enum/record child types.500 // Check for typedefs with unnamed enum/record child types.
501 if (decl.getKind() == .Typedef) {501 if (decl.getKind() == .Typedef) {
502 const typedef_decl = @ptrCast(*const clang.TypedefNameDecl, decl);502 const typedef_decl = @as(*const clang.TypedefNameDecl, @ptrCast(decl));
503 var child_ty = typedef_decl.getUnderlyingType().getTypePtr();503 var child_ty = typedef_decl.getUnderlyingType().getTypePtr();
504 const addr: usize = while (true) switch (child_ty.getTypeClass()) {504 const addr: usize = while (true) switch (child_ty.getTypeClass()) {
505 .Enum => {505 .Enum => {
506 const enum_ty = @ptrCast(*const clang.EnumType, child_ty);506 const enum_ty = @as(*const clang.EnumType, @ptrCast(child_ty));
507 const enum_decl = enum_ty.getDecl();507 const enum_decl = enum_ty.getDecl();
508 // check if this decl is unnamed508 // check if this decl is unnamed
509 if (@ptrCast(*const clang.NamedDecl, enum_decl).getName_bytes_begin()[0] != 0) return;509 if (@as(*const clang.NamedDecl, @ptrCast(enum_decl)).getName_bytes_begin()[0] != 0) return;
510 break @intFromPtr(enum_decl.getCanonicalDecl());510 break @intFromPtr(enum_decl.getCanonicalDecl());
511 },511 },
512 .Record => {512 .Record => {
513 const record_ty = @ptrCast(*const clang.RecordType, child_ty);513 const record_ty = @as(*const clang.RecordType, @ptrCast(child_ty));
514 const record_decl = record_ty.getDecl();514 const record_decl = record_ty.getDecl();
515 // check if this decl is unnamed515 // check if this decl is unnamed
516 if (@ptrCast(*const clang.NamedDecl, record_decl).getName_bytes_begin()[0] != 0) return;516 if (@as(*const clang.NamedDecl, @ptrCast(record_decl)).getName_bytes_begin()[0] != 0) return;
517 break @intFromPtr(record_decl.getCanonicalDecl());517 break @intFromPtr(record_decl.getCanonicalDecl());
518 },518 },
519 .Elaborated => {519 .Elaborated => {
520 const elaborated_ty = @ptrCast(*const clang.ElaboratedType, child_ty);520 const elaborated_ty = @as(*const clang.ElaboratedType, @ptrCast(child_ty));
521 child_ty = elaborated_ty.getNamedType().getTypePtr();521 child_ty = elaborated_ty.getNamedType().getTypePtr();
522 },522 },
523 .Decayed => {523 .Decayed => {
524 const decayed_ty = @ptrCast(*const clang.DecayedType, child_ty);524 const decayed_ty = @as(*const clang.DecayedType, @ptrCast(child_ty));
525 child_ty = decayed_ty.getDecayedType().getTypePtr();525 child_ty = decayed_ty.getDecayedType().getTypePtr();
526 },526 },
527 .Attributed => {527 .Attributed => {
528 const attributed_ty = @ptrCast(*const clang.AttributedType, child_ty);528 const attributed_ty = @as(*const clang.AttributedType, @ptrCast(child_ty));
529 child_ty = attributed_ty.getEquivalentType().getTypePtr();529 child_ty = attributed_ty.getEquivalentType().getTypePtr();
530 },530 },
531 .MacroQualified => {531 .MacroQualified => {
532 const macroqualified_ty = @ptrCast(*const clang.MacroQualifiedType, child_ty);532 const macroqualified_ty = @as(*const clang.MacroQualifiedType, @ptrCast(child_ty));
533 child_ty = macroqualified_ty.getModifiedType().getTypePtr();533 child_ty = macroqualified_ty.getModifiedType().getTypePtr();
534 },534 },
535 else => return,535 else => return,
...@@ -552,25 +552,25 @@ fn declVisitorNamesOnly(c: *Context, decl: *const clang.Decl) Error!void {...@@ -552,25 +552,25 @@ fn declVisitorNamesOnly(c: *Context, decl: *const clang.Decl) Error!void {
552fn declVisitor(c: *Context, decl: *const clang.Decl) Error!void {552fn declVisitor(c: *Context, decl: *const clang.Decl) Error!void {
553 switch (decl.getKind()) {553 switch (decl.getKind()) {
554 .Function => {554 .Function => {
555 return visitFnDecl(c, @ptrCast(*const clang.FunctionDecl, decl));555 return visitFnDecl(c, @as(*const clang.FunctionDecl, @ptrCast(decl)));
556 },556 },
557 .Typedef => {557 .Typedef => {
558 try transTypeDef(c, &c.global_scope.base, @ptrCast(*const clang.TypedefNameDecl, decl));558 try transTypeDef(c, &c.global_scope.base, @as(*const clang.TypedefNameDecl, @ptrCast(decl)));
559 },559 },
560 .Enum => {560 .Enum => {
561 try transEnumDecl(c, &c.global_scope.base, @ptrCast(*const clang.EnumDecl, decl));561 try transEnumDecl(c, &c.global_scope.base, @as(*const clang.EnumDecl, @ptrCast(decl)));
562 },562 },
563 .Record => {563 .Record => {
564 try transRecordDecl(c, &c.global_scope.base, @ptrCast(*const clang.RecordDecl, decl));564 try transRecordDecl(c, &c.global_scope.base, @as(*const clang.RecordDecl, @ptrCast(decl)));
565 },565 },
566 .Var => {566 .Var => {
567 return visitVarDecl(c, @ptrCast(*const clang.VarDecl, decl), null);567 return visitVarDecl(c, @as(*const clang.VarDecl, @ptrCast(decl)), null);
568 },568 },
569 .Empty => {569 .Empty => {
570 // Do nothing570 // Do nothing
571 },571 },
572 .FileScopeAsm => {572 .FileScopeAsm => {
573 try transFileScopeAsm(c, &c.global_scope.base, @ptrCast(*const clang.FileScopeAsmDecl, decl));573 try transFileScopeAsm(c, &c.global_scope.base, @as(*const clang.FileScopeAsmDecl, @ptrCast(decl)));
574 },574 },
575 else => {575 else => {
576 const decl_name = try c.str(decl.getDeclKindName());576 const decl_name = try c.str(decl.getDeclKindName());
...@@ -595,7 +595,7 @@ fn transFileScopeAsm(c: *Context, scope: *Scope, file_scope_asm: *const clang.Fi...@@ -595,7 +595,7 @@ fn transFileScopeAsm(c: *Context, scope: *Scope, file_scope_asm: *const clang.Fi
595}595}
596596
597fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {597fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {
598 const fn_name = try c.str(@ptrCast(*const clang.NamedDecl, fn_decl).getName_bytes_begin());598 const fn_name = try c.str(@as(*const clang.NamedDecl, @ptrCast(fn_decl)).getName_bytes_begin());
599 if (c.global_scope.sym_table.contains(fn_name))599 if (c.global_scope.sym_table.contains(fn_name))
600 return; // Avoid processing this decl twice600 return; // Avoid processing this decl twice
601601
...@@ -630,22 +630,22 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {...@@ -630,22 +630,22 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {
630630
631 switch (fn_type.getTypeClass()) {631 switch (fn_type.getTypeClass()) {
632 .Attributed => {632 .Attributed => {
633 const attr_type = @ptrCast(*const clang.AttributedType, fn_type);633 const attr_type = @as(*const clang.AttributedType, @ptrCast(fn_type));
634 fn_qt = attr_type.getEquivalentType();634 fn_qt = attr_type.getEquivalentType();
635 },635 },
636 .Paren => {636 .Paren => {
637 const paren_type = @ptrCast(*const clang.ParenType, fn_type);637 const paren_type = @as(*const clang.ParenType, @ptrCast(fn_type));
638 fn_qt = paren_type.getInnerType();638 fn_qt = paren_type.getInnerType();
639 },639 },
640 else => break fn_type,640 else => break fn_type,
641 }641 }
642 };642 };
643 const fn_ty = @ptrCast(*const clang.FunctionType, fn_type);643 const fn_ty = @as(*const clang.FunctionType, @ptrCast(fn_type));
644 const return_qt = fn_ty.getReturnType();644 const return_qt = fn_ty.getReturnType();
645645
646 const proto_node = switch (fn_type.getTypeClass()) {646 const proto_node = switch (fn_type.getTypeClass()) {
647 .FunctionProto => blk: {647 .FunctionProto => blk: {
648 const fn_proto_type = @ptrCast(*const clang.FunctionProtoType, fn_type);648 const fn_proto_type = @as(*const clang.FunctionProtoType, @ptrCast(fn_type));
649 if (has_body and fn_proto_type.isVariadic()) {649 if (has_body and fn_proto_type.isVariadic()) {
650 decl_ctx.has_body = false;650 decl_ctx.has_body = false;
651 decl_ctx.storage_class = .Extern;651 decl_ctx.storage_class = .Extern;
...@@ -661,7 +661,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {...@@ -661,7 +661,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {
661 };661 };
662 },662 },
663 .FunctionNoProto => blk: {663 .FunctionNoProto => blk: {
664 const fn_no_proto_type = @ptrCast(*const clang.FunctionType, fn_type);664 const fn_no_proto_type = @as(*const clang.FunctionType, @ptrCast(fn_type));
665 break :blk transFnNoProto(c, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) {665 break :blk transFnNoProto(c, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) {
666 error.UnsupportedType => {666 error.UnsupportedType => {
667 return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{});667 return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{});
...@@ -714,7 +714,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {...@@ -714,7 +714,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {
714 param_id += 1;714 param_id += 1;
715 }715 }
716716
717 const casted_body = @ptrCast(*const clang.CompoundStmt, body_stmt);717 const casted_body = @as(*const clang.CompoundStmt, @ptrCast(body_stmt));
718 transCompoundStmtInline(c, casted_body, &block_scope) catch |err| switch (err) {718 transCompoundStmtInline(c, casted_body, &block_scope) catch |err| switch (err) {
719 error.OutOfMemory => |e| return e,719 error.OutOfMemory => |e| return e,
720 error.UnsupportedTranslation,720 error.UnsupportedTranslation,
...@@ -788,7 +788,7 @@ fn stringLiteralToCharStar(c: *Context, str: Node) Error!Node {...@@ -788,7 +788,7 @@ fn stringLiteralToCharStar(c: *Context, str: Node) Error!Node {
788788
789/// if mangled_name is not null, this var decl was declared in a block scope.789/// if mangled_name is not null, this var decl was declared in a block scope.
790fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]const u8) Error!void {790fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]const u8) Error!void {
791 const var_name = mangled_name orelse try c.str(@ptrCast(*const clang.NamedDecl, var_decl).getName_bytes_begin());791 const var_name = mangled_name orelse try c.str(@as(*const clang.NamedDecl, @ptrCast(var_decl)).getName_bytes_begin());
792 if (c.global_scope.sym_table.contains(var_name))792 if (c.global_scope.sym_table.contains(var_name))
793 return; // Avoid processing this decl twice793 return; // Avoid processing this decl twice
794794
...@@ -830,7 +830,7 @@ fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]co...@@ -830,7 +830,7 @@ fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]co
830 if (has_init) trans_init: {830 if (has_init) trans_init: {
831 if (decl_init) |expr| {831 if (decl_init) |expr| {
832 const node_or_error = if (expr.getStmtClass() == .StringLiteralClass)832 const node_or_error = if (expr.getStmtClass() == .StringLiteralClass)
833 transStringLiteralInitializer(c, @ptrCast(*const clang.StringLiteral, expr), type_node)833 transStringLiteralInitializer(c, @as(*const clang.StringLiteral, @ptrCast(expr)), type_node)
834 else834 else
835 transExprCoercing(c, scope, expr, .used);835 transExprCoercing(c, scope, expr, .used);
836 init_node = node_or_error catch |err| switch (err) {836 init_node = node_or_error catch |err| switch (err) {
...@@ -918,7 +918,7 @@ fn transTypeDef(c: *Context, scope: *Scope, typedef_decl: *const clang.TypedefNa...@@ -918,7 +918,7 @@ fn transTypeDef(c: *Context, scope: *Scope, typedef_decl: *const clang.TypedefNa
918 const toplevel = scope.id == .root;918 const toplevel = scope.id == .root;
919 const bs: *Scope.Block = if (!toplevel) try scope.findBlockScope(c) else undefined;919 const bs: *Scope.Block = if (!toplevel) try scope.findBlockScope(c) else undefined;
920920
921 var name: []const u8 = try c.str(@ptrCast(*const clang.NamedDecl, typedef_decl).getName_bytes_begin());921 var name: []const u8 = try c.str(@as(*const clang.NamedDecl, @ptrCast(typedef_decl)).getName_bytes_begin());
922 try c.typedefs.put(c.gpa, name, {});922 try c.typedefs.put(c.gpa, name, {});
923923
924 if (builtin_typedef_map.get(name)) |builtin| {924 if (builtin_typedef_map.get(name)) |builtin| {
...@@ -981,7 +981,7 @@ fn buildFlexibleArrayFn(...@@ -981,7 +981,7 @@ fn buildFlexibleArrayFn(
981 .is_noalias = false,981 .is_noalias = false,
982 };982 };
983983
984 const array_type = @ptrCast(*const clang.ArrayType, field_qt.getTypePtr());984 const array_type = @as(*const clang.ArrayType, @ptrCast(field_qt.getTypePtr()));
985 const element_qt = array_type.getElementType();985 const element_qt = array_type.getElementType();
986 const element_type = try transQualType(c, scope, element_qt, field_decl.getLocation());986 const element_type = try transQualType(c, scope, element_qt, field_decl.getLocation());
987987
...@@ -1077,7 +1077,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD...@@ -1077,7 +1077,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD
10771077
1078 var is_union = false;1078 var is_union = false;
1079 var container_kind_name: []const u8 = undefined;1079 var container_kind_name: []const u8 = undefined;
1080 var bare_name: []const u8 = try c.str(@ptrCast(*const clang.NamedDecl, record_decl).getName_bytes_begin());1080 var bare_name: []const u8 = try c.str(@as(*const clang.NamedDecl, @ptrCast(record_decl)).getName_bytes_begin());
10811081
1082 if (record_decl.isUnion()) {1082 if (record_decl.isUnion()) {
1083 container_kind_name = "union";1083 container_kind_name = "union";
...@@ -1138,7 +1138,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD...@@ -1138,7 +1138,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD
1138 }1138 }
11391139
1140 var is_anon = false;1140 var is_anon = false;
1141 var field_name = try c.str(@ptrCast(*const clang.NamedDecl, field_decl).getName_bytes_begin());1141 var field_name = try c.str(@as(*const clang.NamedDecl, @ptrCast(field_decl)).getName_bytes_begin());
1142 if (field_decl.isAnonymousStructOrUnion() or field_name.len == 0) {1142 if (field_decl.isAnonymousStructOrUnion() or field_name.len == 0) {
1143 // Context.getMangle() is not used here because doing so causes unpredictable field names for anonymous fields.1143 // Context.getMangle() is not used here because doing so causes unpredictable field names for anonymous fields.
1144 field_name = try std.fmt.allocPrint(c.arena, "unnamed_{d}", .{unnamed_field_count});1144 field_name = try std.fmt.allocPrint(c.arena, "unnamed_{d}", .{unnamed_field_count});
...@@ -1167,7 +1167,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD...@@ -1167,7 +1167,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD
1167 };1167 };
11681168
1169 const alignment = if (has_flexible_array and field_decl.getFieldIndex() == 0)1169 const alignment = if (has_flexible_array and field_decl.getFieldIndex() == 0)
1170 @intCast(c_uint, record_alignment)1170 @as(c_uint, @intCast(record_alignment))
1171 else1171 else
1172 ClangAlignment.forField(c, field_decl, record_def).zigAlignment();1172 ClangAlignment.forField(c, field_decl, record_def).zigAlignment();
11731173
...@@ -1224,7 +1224,7 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const clang.EnumDecl) E...@@ -1224,7 +1224,7 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const clang.EnumDecl) E
1224 const bs: *Scope.Block = if (!toplevel) try scope.findBlockScope(c) else undefined;1224 const bs: *Scope.Block = if (!toplevel) try scope.findBlockScope(c) else undefined;
12251225
1226 var is_unnamed = false;1226 var is_unnamed = false;
1227 var bare_name: []const u8 = try c.str(@ptrCast(*const clang.NamedDecl, enum_decl).getName_bytes_begin());1227 var bare_name: []const u8 = try c.str(@as(*const clang.NamedDecl, @ptrCast(enum_decl)).getName_bytes_begin());
1228 var name = bare_name;1228 var name = bare_name;
1229 if (c.unnamed_typedefs.get(@intFromPtr(enum_decl.getCanonicalDecl()))) |typedef_name| {1229 if (c.unnamed_typedefs.get(@intFromPtr(enum_decl.getCanonicalDecl()))) |typedef_name| {
1230 bare_name = typedef_name;1230 bare_name = typedef_name;
...@@ -1244,13 +1244,13 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const clang.EnumDecl) E...@@ -1244,13 +1244,13 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const clang.EnumDecl) E
1244 const end_it = enum_def.enumerator_end();1244 const end_it = enum_def.enumerator_end();
1245 while (it.neq(end_it)) : (it = it.next()) {1245 while (it.neq(end_it)) : (it = it.next()) {
1246 const enum_const = it.deref();1246 const enum_const = it.deref();
1247 var enum_val_name: []const u8 = try c.str(@ptrCast(*const clang.NamedDecl, enum_const).getName_bytes_begin());1247 var enum_val_name: []const u8 = try c.str(@as(*const clang.NamedDecl, @ptrCast(enum_const)).getName_bytes_begin());
1248 if (!toplevel) {1248 if (!toplevel) {
1249 enum_val_name = try bs.makeMangledName(c, enum_val_name);1249 enum_val_name = try bs.makeMangledName(c, enum_val_name);
1250 }1250 }
12511251
1252 const enum_const_qt = @ptrCast(*const clang.ValueDecl, enum_const).getType();1252 const enum_const_qt = @as(*const clang.ValueDecl, @ptrCast(enum_const)).getType();
1253 const enum_const_loc = @ptrCast(*const clang.Decl, enum_const).getLocation();1253 const enum_const_loc = @as(*const clang.Decl, @ptrCast(enum_const)).getLocation();
1254 const enum_const_type_node: ?Node = transQualType(c, scope, enum_const_qt, enum_const_loc) catch |err| switch (err) {1254 const enum_const_type_node: ?Node = transQualType(c, scope, enum_const_qt, enum_const_loc) catch |err| switch (err) {
1255 error.UnsupportedType => null,1255 error.UnsupportedType => null,
1256 else => |e| return e,1256 else => |e| return e,
...@@ -1325,77 +1325,77 @@ fn transStmt(...@@ -1325,77 +1325,77 @@ fn transStmt(
1325) TransError!Node {1325) TransError!Node {
1326 const sc = stmt.getStmtClass();1326 const sc = stmt.getStmtClass();
1327 switch (sc) {1327 switch (sc) {
1328 .BinaryOperatorClass => return transBinaryOperator(c, scope, @ptrCast(*const clang.BinaryOperator, stmt), result_used),1328 .BinaryOperatorClass => return transBinaryOperator(c, scope, @as(*const clang.BinaryOperator, @ptrCast(stmt)), result_used),
1329 .CompoundStmtClass => return transCompoundStmt(c, scope, @ptrCast(*const clang.CompoundStmt, stmt)),1329 .CompoundStmtClass => return transCompoundStmt(c, scope, @as(*const clang.CompoundStmt, @ptrCast(stmt))),
1330 .CStyleCastExprClass => return transCStyleCastExprClass(c, scope, @ptrCast(*const clang.CStyleCastExpr, stmt), result_used),1330 .CStyleCastExprClass => return transCStyleCastExprClass(c, scope, @as(*const clang.CStyleCastExpr, @ptrCast(stmt)), result_used),
1331 .DeclStmtClass => return transDeclStmt(c, scope, @ptrCast(*const clang.DeclStmt, stmt)),1331 .DeclStmtClass => return transDeclStmt(c, scope, @as(*const clang.DeclStmt, @ptrCast(stmt))),
1332 .DeclRefExprClass => return transDeclRefExpr(c, scope, @ptrCast(*const clang.DeclRefExpr, stmt)),1332 .DeclRefExprClass => return transDeclRefExpr(c, scope, @as(*const clang.DeclRefExpr, @ptrCast(stmt))),
1333 .ImplicitCastExprClass => return transImplicitCastExpr(c, scope, @ptrCast(*const clang.ImplicitCastExpr, stmt), result_used),1333 .ImplicitCastExprClass => return transImplicitCastExpr(c, scope, @as(*const clang.ImplicitCastExpr, @ptrCast(stmt)), result_used),
1334 .IntegerLiteralClass => return transIntegerLiteral(c, scope, @ptrCast(*const clang.IntegerLiteral, stmt), result_used, .with_as),1334 .IntegerLiteralClass => return transIntegerLiteral(c, scope, @as(*const clang.IntegerLiteral, @ptrCast(stmt)), result_used, .with_as),
1335 .ReturnStmtClass => return transReturnStmt(c, scope, @ptrCast(*const clang.ReturnStmt, stmt)),1335 .ReturnStmtClass => return transReturnStmt(c, scope, @as(*const clang.ReturnStmt, @ptrCast(stmt))),
1336 .StringLiteralClass => return transStringLiteral(c, scope, @ptrCast(*const clang.StringLiteral, stmt), result_used),1336 .StringLiteralClass => return transStringLiteral(c, scope, @as(*const clang.StringLiteral, @ptrCast(stmt)), result_used),
1337 .ParenExprClass => {1337 .ParenExprClass => {
1338 const expr = try transExpr(c, scope, @ptrCast(*const clang.ParenExpr, stmt).getSubExpr(), .used);1338 const expr = try transExpr(c, scope, @as(*const clang.ParenExpr, @ptrCast(stmt)).getSubExpr(), .used);
1339 return maybeSuppressResult(c, result_used, expr);1339 return maybeSuppressResult(c, result_used, expr);
1340 },1340 },
1341 .InitListExprClass => return transInitListExpr(c, scope, @ptrCast(*const clang.InitListExpr, stmt), result_used),1341 .InitListExprClass => return transInitListExpr(c, scope, @as(*const clang.InitListExpr, @ptrCast(stmt)), result_used),
1342 .ImplicitValueInitExprClass => return transImplicitValueInitExpr(c, scope, @ptrCast(*const clang.Expr, stmt)),1342 .ImplicitValueInitExprClass => return transImplicitValueInitExpr(c, scope, @as(*const clang.Expr, @ptrCast(stmt))),
1343 .IfStmtClass => return transIfStmt(c, scope, @ptrCast(*const clang.IfStmt, stmt)),1343 .IfStmtClass => return transIfStmt(c, scope, @as(*const clang.IfStmt, @ptrCast(stmt))),
1344 .WhileStmtClass => return transWhileLoop(c, scope, @ptrCast(*const clang.WhileStmt, stmt)),1344 .WhileStmtClass => return transWhileLoop(c, scope, @as(*const clang.WhileStmt, @ptrCast(stmt))),
1345 .DoStmtClass => return transDoWhileLoop(c, scope, @ptrCast(*const clang.DoStmt, stmt)),1345 .DoStmtClass => return transDoWhileLoop(c, scope, @as(*const clang.DoStmt, @ptrCast(stmt))),
1346 .NullStmtClass => {1346 .NullStmtClass => {
1347 return Tag.empty_block.init();1347 return Tag.empty_block.init();
1348 },1348 },
1349 .ContinueStmtClass => return Tag.@"continue".init(),1349 .ContinueStmtClass => return Tag.@"continue".init(),
1350 .BreakStmtClass => return Tag.@"break".init(),1350 .BreakStmtClass => return Tag.@"break".init(),
1351 .ForStmtClass => return transForLoop(c, scope, @ptrCast(*const clang.ForStmt, stmt)),1351 .ForStmtClass => return transForLoop(c, scope, @as(*const clang.ForStmt, @ptrCast(stmt))),
1352 .FloatingLiteralClass => return transFloatingLiteral(c, @ptrCast(*const clang.FloatingLiteral, stmt), result_used),1352 .FloatingLiteralClass => return transFloatingLiteral(c, @as(*const clang.FloatingLiteral, @ptrCast(stmt)), result_used),
1353 .ConditionalOperatorClass => {1353 .ConditionalOperatorClass => {
1354 return transConditionalOperator(c, scope, @ptrCast(*const clang.ConditionalOperator, stmt), result_used);1354 return transConditionalOperator(c, scope, @as(*const clang.ConditionalOperator, @ptrCast(stmt)), result_used);
1355 },1355 },
1356 .BinaryConditionalOperatorClass => {1356 .BinaryConditionalOperatorClass => {
1357 return transBinaryConditionalOperator(c, scope, @ptrCast(*const clang.BinaryConditionalOperator, stmt), result_used);1357 return transBinaryConditionalOperator(c, scope, @as(*const clang.BinaryConditionalOperator, @ptrCast(stmt)), result_used);
1358 },1358 },
1359 .SwitchStmtClass => return transSwitch(c, scope, @ptrCast(*const clang.SwitchStmt, stmt)),1359 .SwitchStmtClass => return transSwitch(c, scope, @as(*const clang.SwitchStmt, @ptrCast(stmt))),
1360 .CaseStmtClass, .DefaultStmtClass => {1360 .CaseStmtClass, .DefaultStmtClass => {
1361 return fail(c, error.UnsupportedTranslation, stmt.getBeginLoc(), "TODO complex switch", .{});1361 return fail(c, error.UnsupportedTranslation, stmt.getBeginLoc(), "TODO complex switch", .{});
1362 },1362 },
1363 .ConstantExprClass => return transConstantExpr(c, scope, @ptrCast(*const clang.Expr, stmt), result_used),1363 .ConstantExprClass => return transConstantExpr(c, scope, @as(*const clang.Expr, @ptrCast(stmt)), result_used),
1364 .PredefinedExprClass => return transPredefinedExpr(c, scope, @ptrCast(*const clang.PredefinedExpr, stmt), result_used),1364 .PredefinedExprClass => return transPredefinedExpr(c, scope, @as(*const clang.PredefinedExpr, @ptrCast(stmt)), result_used),
1365 .CharacterLiteralClass => return transCharLiteral(c, scope, @ptrCast(*const clang.CharacterLiteral, stmt), result_used, .with_as),1365 .CharacterLiteralClass => return transCharLiteral(c, scope, @as(*const clang.CharacterLiteral, @ptrCast(stmt)), result_used, .with_as),
1366 .StmtExprClass => return transStmtExpr(c, scope, @ptrCast(*const clang.StmtExpr, stmt), result_used),1366 .StmtExprClass => return transStmtExpr(c, scope, @as(*const clang.StmtExpr, @ptrCast(stmt)), result_used),
1367 .MemberExprClass => return transMemberExpr(c, scope, @ptrCast(*const clang.MemberExpr, stmt), result_used),1367 .MemberExprClass => return transMemberExpr(c, scope, @as(*const clang.MemberExpr, @ptrCast(stmt)), result_used),
1368 .ArraySubscriptExprClass => return transArrayAccess(c, scope, @ptrCast(*const clang.ArraySubscriptExpr, stmt), result_used),1368 .ArraySubscriptExprClass => return transArrayAccess(c, scope, @as(*const clang.ArraySubscriptExpr, @ptrCast(stmt)), result_used),
1369 .CallExprClass => return transCallExpr(c, scope, @ptrCast(*const clang.CallExpr, stmt), result_used),1369 .CallExprClass => return transCallExpr(c, scope, @as(*const clang.CallExpr, @ptrCast(stmt)), result_used),
1370 .UnaryExprOrTypeTraitExprClass => return transUnaryExprOrTypeTraitExpr(c, scope, @ptrCast(*const clang.UnaryExprOrTypeTraitExpr, stmt), result_used),1370 .UnaryExprOrTypeTraitExprClass => return transUnaryExprOrTypeTraitExpr(c, scope, @as(*const clang.UnaryExprOrTypeTraitExpr, @ptrCast(stmt)), result_used),
1371 .UnaryOperatorClass => return transUnaryOperator(c, scope, @ptrCast(*const clang.UnaryOperator, stmt), result_used),1371 .UnaryOperatorClass => return transUnaryOperator(c, scope, @as(*const clang.UnaryOperator, @ptrCast(stmt)), result_used),
1372 .CompoundAssignOperatorClass => return transCompoundAssignOperator(c, scope, @ptrCast(*const clang.CompoundAssignOperator, stmt), result_used),1372 .CompoundAssignOperatorClass => return transCompoundAssignOperator(c, scope, @as(*const clang.CompoundAssignOperator, @ptrCast(stmt)), result_used),
1373 .OpaqueValueExprClass => {1373 .OpaqueValueExprClass => {
1374 const source_expr = @ptrCast(*const clang.OpaqueValueExpr, stmt).getSourceExpr().?;1374 const source_expr = @as(*const clang.OpaqueValueExpr, @ptrCast(stmt)).getSourceExpr().?;
1375 const expr = try transExpr(c, scope, source_expr, .used);1375 const expr = try transExpr(c, scope, source_expr, .used);
1376 return maybeSuppressResult(c, result_used, expr);1376 return maybeSuppressResult(c, result_used, expr);
1377 },1377 },
1378 .OffsetOfExprClass => return transOffsetOfExpr(c, @ptrCast(*const clang.OffsetOfExpr, stmt), result_used),1378 .OffsetOfExprClass => return transOffsetOfExpr(c, @as(*const clang.OffsetOfExpr, @ptrCast(stmt)), result_used),
1379 .CompoundLiteralExprClass => {1379 .CompoundLiteralExprClass => {
1380 const compound_literal = @ptrCast(*const clang.CompoundLiteralExpr, stmt);1380 const compound_literal = @as(*const clang.CompoundLiteralExpr, @ptrCast(stmt));
1381 return transExpr(c, scope, compound_literal.getInitializer(), result_used);1381 return transExpr(c, scope, compound_literal.getInitializer(), result_used);
1382 },1382 },
1383 .GenericSelectionExprClass => {1383 .GenericSelectionExprClass => {
1384 const gen_sel = @ptrCast(*const clang.GenericSelectionExpr, stmt);1384 const gen_sel = @as(*const clang.GenericSelectionExpr, @ptrCast(stmt));
1385 return transExpr(c, scope, gen_sel.getResultExpr(), result_used);1385 return transExpr(c, scope, gen_sel.getResultExpr(), result_used);
1386 },1386 },
1387 .ConvertVectorExprClass => {1387 .ConvertVectorExprClass => {
1388 const conv_vec = @ptrCast(*const clang.ConvertVectorExpr, stmt);1388 const conv_vec = @as(*const clang.ConvertVectorExpr, @ptrCast(stmt));
1389 const conv_vec_node = try transConvertVectorExpr(c, scope, conv_vec);1389 const conv_vec_node = try transConvertVectorExpr(c, scope, conv_vec);
1390 return maybeSuppressResult(c, result_used, conv_vec_node);1390 return maybeSuppressResult(c, result_used, conv_vec_node);
1391 },1391 },
1392 .ShuffleVectorExprClass => {1392 .ShuffleVectorExprClass => {
1393 const shuffle_vec_expr = @ptrCast(*const clang.ShuffleVectorExpr, stmt);1393 const shuffle_vec_expr = @as(*const clang.ShuffleVectorExpr, @ptrCast(stmt));
1394 const shuffle_vec_node = try transShuffleVectorExpr(c, scope, shuffle_vec_expr);1394 const shuffle_vec_node = try transShuffleVectorExpr(c, scope, shuffle_vec_expr);
1395 return maybeSuppressResult(c, result_used, shuffle_vec_node);1395 return maybeSuppressResult(c, result_used, shuffle_vec_node);
1396 },1396 },
1397 .ChooseExprClass => {1397 .ChooseExprClass => {
1398 const choose_expr = @ptrCast(*const clang.ChooseExpr, stmt);1398 const choose_expr = @as(*const clang.ChooseExpr, @ptrCast(stmt));
1399 return transExpr(c, scope, choose_expr.getChosenSubExpr(), result_used);1399 return transExpr(c, scope, choose_expr.getChosenSubExpr(), result_used);
1400 },1400 },
1401 // When adding new cases here, see comment for maybeBlockify()1401 // When adding new cases here, see comment for maybeBlockify()
...@@ -1421,21 +1421,21 @@ fn transConvertVectorExpr(...@@ -1421,21 +1421,21 @@ fn transConvertVectorExpr(
1421 scope: *Scope,1421 scope: *Scope,
1422 expr: *const clang.ConvertVectorExpr,1422 expr: *const clang.ConvertVectorExpr,
1423) TransError!Node {1423) TransError!Node {
1424 const base_stmt = @ptrCast(*const clang.Stmt, expr);1424 const base_stmt = @as(*const clang.Stmt, @ptrCast(expr));
14251425
1426 var block_scope = try Scope.Block.init(c, scope, true);1426 var block_scope = try Scope.Block.init(c, scope, true);
1427 defer block_scope.deinit();1427 defer block_scope.deinit();
14281428
1429 const src_expr = expr.getSrcExpr();1429 const src_expr = expr.getSrcExpr();
1430 const src_type = qualTypeCanon(src_expr.getType());1430 const src_type = qualTypeCanon(src_expr.getType());
1431 const src_vector_ty = @ptrCast(*const clang.VectorType, src_type);1431 const src_vector_ty = @as(*const clang.VectorType, @ptrCast(src_type));
1432 const src_element_qt = src_vector_ty.getElementType();1432 const src_element_qt = src_vector_ty.getElementType();
14331433
1434 const src_expr_node = try transExpr(c, &block_scope.base, src_expr, .used);1434 const src_expr_node = try transExpr(c, &block_scope.base, src_expr, .used);
14351435
1436 const dst_qt = expr.getTypeSourceInfo_getType();1436 const dst_qt = expr.getTypeSourceInfo_getType();
1437 const dst_type_node = try transQualType(c, &block_scope.base, dst_qt, base_stmt.getBeginLoc());1437 const dst_type_node = try transQualType(c, &block_scope.base, dst_qt, base_stmt.getBeginLoc());
1438 const dst_vector_ty = @ptrCast(*const clang.VectorType, qualTypeCanon(dst_qt));1438 const dst_vector_ty = @as(*const clang.VectorType, @ptrCast(qualTypeCanon(dst_qt)));
1439 const num_elements = dst_vector_ty.getNumElements();1439 const num_elements = dst_vector_ty.getNumElements();
1440 const dst_element_qt = dst_vector_ty.getElementType();1440 const dst_element_qt = dst_vector_ty.getElementType();
14411441
...@@ -1490,7 +1490,7 @@ fn makeShuffleMask(c: *Context, scope: *Scope, expr: *const clang.ShuffleVectorE...@@ -1490,7 +1490,7 @@ fn makeShuffleMask(c: *Context, scope: *Scope, expr: *const clang.ShuffleVectorE
1490 const init_list = try c.arena.alloc(Node, mask_len);1490 const init_list = try c.arena.alloc(Node, mask_len);
14911491
1492 for (init_list, 0..) |*init, i| {1492 for (init_list, 0..) |*init, i| {
1493 const index_expr = try transExprCoercing(c, scope, expr.getExpr(@intCast(c_uint, i + 2)), .used);1493 const index_expr = try transExprCoercing(c, scope, expr.getExpr(@as(c_uint, @intCast(i + 2))), .used);
1494 const converted_index = try Tag.helpers_shuffle_vector_index.create(c.arena, .{ .lhs = index_expr, .rhs = vector_len });1494 const converted_index = try Tag.helpers_shuffle_vector_index.create(c.arena, .{ .lhs = index_expr, .rhs = vector_len });
1495 init.* = converted_index;1495 init.* = converted_index;
1496 }1496 }
...@@ -1514,7 +1514,7 @@ fn transShuffleVectorExpr(...@@ -1514,7 +1514,7 @@ fn transShuffleVectorExpr(
1514 scope: *Scope,1514 scope: *Scope,
1515 expr: *const clang.ShuffleVectorExpr,1515 expr: *const clang.ShuffleVectorExpr,
1516) TransError!Node {1516) TransError!Node {
1517 const base_expr = @ptrCast(*const clang.Expr, expr);1517 const base_expr = @as(*const clang.Expr, @ptrCast(expr));
1518 const num_subexprs = expr.getNumSubExprs();1518 const num_subexprs = expr.getNumSubExprs();
1519 if (num_subexprs < 3) return fail(c, error.UnsupportedTranslation, base_expr.getBeginLoc(), "ShuffleVector needs at least 1 index", .{});1519 if (num_subexprs < 3) return fail(c, error.UnsupportedTranslation, base_expr.getBeginLoc(), "ShuffleVector needs at least 1 index", .{});
15201520
...@@ -1545,7 +1545,7 @@ fn transSimpleOffsetOfExpr(c: *Context, expr: *const clang.OffsetOfExpr) TransEr...@@ -1545,7 +1545,7 @@ fn transSimpleOffsetOfExpr(c: *Context, expr: *const clang.OffsetOfExpr) TransEr
1545 if (c.decl_table.get(@intFromPtr(record_decl.getCanonicalDecl()))) |type_name| {1545 if (c.decl_table.get(@intFromPtr(record_decl.getCanonicalDecl()))) |type_name| {
1546 const type_node = try Tag.type.create(c.arena, type_name);1546 const type_node = try Tag.type.create(c.arena, type_name);
15471547
1548 var raw_field_name = try c.str(@ptrCast(*const clang.NamedDecl, field_decl).getName_bytes_begin());1548 var raw_field_name = try c.str(@as(*const clang.NamedDecl, @ptrCast(field_decl)).getName_bytes_begin());
1549 const quoted_field_name = try std.fmt.allocPrint(c.arena, "\"{s}\"", .{raw_field_name});1549 const quoted_field_name = try std.fmt.allocPrint(c.arena, "\"{s}\"", .{raw_field_name});
1550 const field_name_node = try Tag.string_literal.create(c.arena, quoted_field_name);1550 const field_name_node = try Tag.string_literal.create(c.arena, quoted_field_name);
15511551
...@@ -1829,7 +1829,7 @@ fn transCStyleCastExprClass(...@@ -1829,7 +1829,7 @@ fn transCStyleCastExprClass(
1829 stmt: *const clang.CStyleCastExpr,1829 stmt: *const clang.CStyleCastExpr,
1830 result_used: ResultUsed,1830 result_used: ResultUsed,
1831) TransError!Node {1831) TransError!Node {
1832 const cast_expr = @ptrCast(*const clang.CastExpr, stmt);1832 const cast_expr = @as(*const clang.CastExpr, @ptrCast(stmt));
1833 const sub_expr = stmt.getSubExpr();1833 const sub_expr = stmt.getSubExpr();
1834 const dst_type = stmt.getType();1834 const dst_type = stmt.getType();
1835 const src_type = sub_expr.getType();1835 const src_type = sub_expr.getType();
...@@ -1838,7 +1838,7 @@ fn transCStyleCastExprClass(...@@ -1838,7 +1838,7 @@ fn transCStyleCastExprClass(
18381838
1839 const cast_node = if (cast_expr.getCastKind() == .ToUnion) blk: {1839 const cast_node = if (cast_expr.getCastKind() == .ToUnion) blk: {
1840 const field_decl = cast_expr.getTargetFieldForToUnionCast(dst_type, src_type).?; // C syntax error if target field is null1840 const field_decl = cast_expr.getTargetFieldForToUnionCast(dst_type, src_type).?; // C syntax error if target field is null
1841 const field_name = try c.str(@ptrCast(*const clang.NamedDecl, field_decl).getName_bytes_begin());1841 const field_name = try c.str(@as(*const clang.NamedDecl, @ptrCast(field_decl)).getName_bytes_begin());
18421842
1843 const union_ty = try transQualType(c, scope, dst_type, loc);1843 const union_ty = try transQualType(c, scope, dst_type, loc);
18441844
...@@ -1923,12 +1923,12 @@ fn transDeclStmtOne(...@@ -1923,12 +1923,12 @@ fn transDeclStmtOne(
1923) TransError!void {1923) TransError!void {
1924 switch (decl.getKind()) {1924 switch (decl.getKind()) {
1925 .Var => {1925 .Var => {
1926 const var_decl = @ptrCast(*const clang.VarDecl, decl);1926 const var_decl = @as(*const clang.VarDecl, @ptrCast(decl));
1927 const decl_init = var_decl.getInit();1927 const decl_init = var_decl.getInit();
1928 const loc = decl.getLocation();1928 const loc = decl.getLocation();
19291929
1930 const qual_type = var_decl.getTypeSourceInfo_getType();1930 const qual_type = var_decl.getTypeSourceInfo_getType();
1931 const name = try c.str(@ptrCast(*const clang.NamedDecl, var_decl).getName_bytes_begin());1931 const name = try c.str(@as(*const clang.NamedDecl, @ptrCast(var_decl)).getName_bytes_begin());
1932 const mangled_name = try block_scope.makeMangledName(c, name);1932 const mangled_name = try block_scope.makeMangledName(c, name);
19331933
1934 if (var_decl.getStorageClass() == .Extern) {1934 if (var_decl.getStorageClass() == .Extern) {
...@@ -1945,7 +1945,7 @@ fn transDeclStmtOne(...@@ -1945,7 +1945,7 @@ fn transDeclStmtOne(
19451945
1946 var init_node = if (decl_init) |expr|1946 var init_node = if (decl_init) |expr|
1947 if (expr.getStmtClass() == .StringLiteralClass)1947 if (expr.getStmtClass() == .StringLiteralClass)
1948 try transStringLiteralInitializer(c, @ptrCast(*const clang.StringLiteral, expr), type_node)1948 try transStringLiteralInitializer(c, @as(*const clang.StringLiteral, @ptrCast(expr)), type_node)
1949 else1949 else
1950 try transExprCoercing(c, scope, expr, .used)1950 try transExprCoercing(c, scope, expr, .used)
1951 else if (is_static_local)1951 else if (is_static_local)
...@@ -1980,7 +1980,7 @@ fn transDeclStmtOne(...@@ -1980,7 +1980,7 @@ fn transDeclStmtOne(
19801980
1981 const cleanup_attr = var_decl.getCleanupAttribute();1981 const cleanup_attr = var_decl.getCleanupAttribute();
1982 if (cleanup_attr) |fn_decl| {1982 if (cleanup_attr) |fn_decl| {
1983 const cleanup_fn_name = try c.str(@ptrCast(*const clang.NamedDecl, fn_decl).getName_bytes_begin());1983 const cleanup_fn_name = try c.str(@as(*const clang.NamedDecl, @ptrCast(fn_decl)).getName_bytes_begin());
1984 const fn_id = try Tag.identifier.create(c.arena, cleanup_fn_name);1984 const fn_id = try Tag.identifier.create(c.arena, cleanup_fn_name);
19851985
1986 const varname = try Tag.identifier.create(c.arena, mangled_name);1986 const varname = try Tag.identifier.create(c.arena, mangled_name);
...@@ -1995,16 +1995,16 @@ fn transDeclStmtOne(...@@ -1995,16 +1995,16 @@ fn transDeclStmtOne(
1995 }1995 }
1996 },1996 },
1997 .Typedef => {1997 .Typedef => {
1998 try transTypeDef(c, scope, @ptrCast(*const clang.TypedefNameDecl, decl));1998 try transTypeDef(c, scope, @as(*const clang.TypedefNameDecl, @ptrCast(decl)));
1999 },1999 },
2000 .Record => {2000 .Record => {
2001 try transRecordDecl(c, scope, @ptrCast(*const clang.RecordDecl, decl));2001 try transRecordDecl(c, scope, @as(*const clang.RecordDecl, @ptrCast(decl)));
2002 },2002 },
2003 .Enum => {2003 .Enum => {
2004 try transEnumDecl(c, scope, @ptrCast(*const clang.EnumDecl, decl));2004 try transEnumDecl(c, scope, @as(*const clang.EnumDecl, @ptrCast(decl)));
2005 },2005 },
2006 .Function => {2006 .Function => {
2007 try visitFnDecl(c, @ptrCast(*const clang.FunctionDecl, decl));2007 try visitFnDecl(c, @as(*const clang.FunctionDecl, @ptrCast(decl)));
2008 },2008 },
2009 else => {2009 else => {
2010 const decl_name = try c.str(decl.getDeclKindName());2010 const decl_name = try c.str(decl.getDeclKindName());
...@@ -2030,15 +2030,15 @@ fn transDeclRefExpr(...@@ -2030,15 +2030,15 @@ fn transDeclRefExpr(
2030 expr: *const clang.DeclRefExpr,2030 expr: *const clang.DeclRefExpr,
2031) TransError!Node {2031) TransError!Node {
2032 const value_decl = expr.getDecl();2032 const value_decl = expr.getDecl();
2033 const name = try c.str(@ptrCast(*const clang.NamedDecl, value_decl).getName_bytes_begin());2033 const name = try c.str(@as(*const clang.NamedDecl, @ptrCast(value_decl)).getName_bytes_begin());
2034 const mangled_name = scope.getAlias(name);2034 const mangled_name = scope.getAlias(name);
2035 var ref_expr = if (cIsFunctionDeclRef(@ptrCast(*const clang.Expr, expr)))2035 var ref_expr = if (cIsFunctionDeclRef(@as(*const clang.Expr, @ptrCast(expr))))
2036 try Tag.fn_identifier.create(c.arena, mangled_name)2036 try Tag.fn_identifier.create(c.arena, mangled_name)
2037 else2037 else
2038 try Tag.identifier.create(c.arena, mangled_name);2038 try Tag.identifier.create(c.arena, mangled_name);
20392039
2040 if (@ptrCast(*const clang.Decl, value_decl).getKind() == .Var) {2040 if (@as(*const clang.Decl, @ptrCast(value_decl)).getKind() == .Var) {
2041 const var_decl = @ptrCast(*const clang.VarDecl, value_decl);2041 const var_decl = @as(*const clang.VarDecl, @ptrCast(value_decl));
2042 if (var_decl.isStaticLocal()) {2042 if (var_decl.isStaticLocal()) {
2043 ref_expr = try Tag.field_access.create(c.arena, .{2043 ref_expr = try Tag.field_access.create(c.arena, .{
2044 .lhs = ref_expr,2044 .lhs = ref_expr,
...@@ -2057,7 +2057,7 @@ fn transImplicitCastExpr(...@@ -2057,7 +2057,7 @@ fn transImplicitCastExpr(
2057 result_used: ResultUsed,2057 result_used: ResultUsed,
2058) TransError!Node {2058) TransError!Node {
2059 const sub_expr = expr.getSubExpr();2059 const sub_expr = expr.getSubExpr();
2060 const dest_type = getExprQualType(c, @ptrCast(*const clang.Expr, expr));2060 const dest_type = getExprQualType(c, @as(*const clang.Expr, @ptrCast(expr)));
2061 const src_type = getExprQualType(c, sub_expr);2061 const src_type = getExprQualType(c, sub_expr);
2062 switch (expr.getCastKind()) {2062 switch (expr.getCastKind()) {
2063 .BitCast, .FloatingCast, .FloatingToIntegral, .IntegralToFloating, .IntegralCast, .PointerToIntegral, .IntegralToPointer => {2063 .BitCast, .FloatingCast, .FloatingToIntegral, .IntegralToFloating, .IntegralCast, .PointerToIntegral, .IntegralToPointer => {
...@@ -2111,7 +2111,7 @@ fn transImplicitCastExpr(...@@ -2111,7 +2111,7 @@ fn transImplicitCastExpr(
2111 else => |kind| return fail(2111 else => |kind| return fail(
2112 c,2112 c,
2113 error.UnsupportedTranslation,2113 error.UnsupportedTranslation,
2114 @ptrCast(*const clang.Stmt, expr).getBeginLoc(),2114 @as(*const clang.Stmt, @ptrCast(expr)).getBeginLoc(),
2115 "unsupported CastKind {s}",2115 "unsupported CastKind {s}",
2116 .{@tagName(kind)},2116 .{@tagName(kind)},
2117 ),2117 ),
...@@ -2141,9 +2141,9 @@ fn transBoolExpr(...@@ -2141,9 +2141,9 @@ fn transBoolExpr(
2141 expr: *const clang.Expr,2141 expr: *const clang.Expr,
2142 used: ResultUsed,2142 used: ResultUsed,
2143) TransError!Node {2143) TransError!Node {
2144 if (@ptrCast(*const clang.Stmt, expr).getStmtClass() == .IntegerLiteralClass) {2144 if (@as(*const clang.Stmt, @ptrCast(expr)).getStmtClass() == .IntegerLiteralClass) {
2145 var signum: c_int = undefined;2145 var signum: c_int = undefined;
2146 if (!(@ptrCast(*const clang.IntegerLiteral, expr).getSignum(&signum, c.clang_context))) {2146 if (!(@as(*const clang.IntegerLiteral, @ptrCast(expr)).getSignum(&signum, c.clang_context))) {
2147 return fail(c, error.UnsupportedTranslation, expr.getBeginLoc(), "invalid integer literal", .{});2147 return fail(c, error.UnsupportedTranslation, expr.getBeginLoc(), "invalid integer literal", .{});
2148 }2148 }
2149 const is_zero = signum == 0;2149 const is_zero = signum == 0;
...@@ -2168,20 +2168,20 @@ fn exprIsBooleanType(expr: *const clang.Expr) bool {...@@ -2168,20 +2168,20 @@ fn exprIsBooleanType(expr: *const clang.Expr) bool {
2168fn exprIsNarrowStringLiteral(expr: *const clang.Expr) bool {2168fn exprIsNarrowStringLiteral(expr: *const clang.Expr) bool {
2169 switch (expr.getStmtClass()) {2169 switch (expr.getStmtClass()) {
2170 .StringLiteralClass => {2170 .StringLiteralClass => {
2171 const string_lit = @ptrCast(*const clang.StringLiteral, expr);2171 const string_lit = @as(*const clang.StringLiteral, @ptrCast(expr));
2172 return string_lit.getCharByteWidth() == 1;2172 return string_lit.getCharByteWidth() == 1;
2173 },2173 },
2174 .PredefinedExprClass => return true,2174 .PredefinedExprClass => return true,
2175 .UnaryOperatorClass => {2175 .UnaryOperatorClass => {
2176 const op_expr = @ptrCast(*const clang.UnaryOperator, expr).getSubExpr();2176 const op_expr = @as(*const clang.UnaryOperator, @ptrCast(expr)).getSubExpr();
2177 return exprIsNarrowStringLiteral(op_expr);2177 return exprIsNarrowStringLiteral(op_expr);
2178 },2178 },
2179 .ParenExprClass => {2179 .ParenExprClass => {
2180 const op_expr = @ptrCast(*const clang.ParenExpr, expr).getSubExpr();2180 const op_expr = @as(*const clang.ParenExpr, @ptrCast(expr)).getSubExpr();
2181 return exprIsNarrowStringLiteral(op_expr);2181 return exprIsNarrowStringLiteral(op_expr);
2182 },2182 },
2183 .GenericSelectionExprClass => {2183 .GenericSelectionExprClass => {
2184 const gen_sel = @ptrCast(*const clang.GenericSelectionExpr, expr);2184 const gen_sel = @as(*const clang.GenericSelectionExpr, @ptrCast(expr));
2185 return exprIsNarrowStringLiteral(gen_sel.getResultExpr());2185 return exprIsNarrowStringLiteral(gen_sel.getResultExpr());
2186 },2186 },
2187 else => return false,2187 else => return false,
...@@ -2190,11 +2190,11 @@ fn exprIsNarrowStringLiteral(expr: *const clang.Expr) bool {...@@ -2190,11 +2190,11 @@ fn exprIsNarrowStringLiteral(expr: *const clang.Expr) bool {
21902190
2191fn exprIsFlexibleArrayRef(c: *Context, expr: *const clang.Expr) bool {2191fn exprIsFlexibleArrayRef(c: *Context, expr: *const clang.Expr) bool {
2192 if (expr.getStmtClass() == .MemberExprClass) {2192 if (expr.getStmtClass() == .MemberExprClass) {
2193 const member_expr = @ptrCast(*const clang.MemberExpr, expr);2193 const member_expr = @as(*const clang.MemberExpr, @ptrCast(expr));
2194 const member_decl = member_expr.getMemberDecl();2194 const member_decl = member_expr.getMemberDecl();
2195 const decl_kind = @ptrCast(*const clang.Decl, member_decl).getKind();2195 const decl_kind = @as(*const clang.Decl, @ptrCast(member_decl)).getKind();
2196 if (decl_kind == .Field) {2196 if (decl_kind == .Field) {
2197 const field_decl = @ptrCast(*const clang.FieldDecl, member_decl);2197 const field_decl = @as(*const clang.FieldDecl, @ptrCast(member_decl));
2198 return isFlexibleArrayFieldDecl(c, field_decl);2198 return isFlexibleArrayFieldDecl(c, field_decl);
2199 }2199 }
2200 }2200 }
...@@ -2229,7 +2229,7 @@ fn finishBoolExpr(...@@ -2229,7 +2229,7 @@ fn finishBoolExpr(
2229) TransError!Node {2229) TransError!Node {
2230 switch (ty.getTypeClass()) {2230 switch (ty.getTypeClass()) {
2231 .Builtin => {2231 .Builtin => {
2232 const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);2232 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(ty));
22332233
2234 switch (builtin_ty.getKind()) {2234 switch (builtin_ty.getKind()) {
2235 .Bool => return node,2235 .Bool => return node,
...@@ -2273,7 +2273,7 @@ fn finishBoolExpr(...@@ -2273,7 +2273,7 @@ fn finishBoolExpr(
2273 return Tag.not_equal.create(c.arena, .{ .lhs = node, .rhs = Tag.null_literal.init() });2273 return Tag.not_equal.create(c.arena, .{ .lhs = node, .rhs = Tag.null_literal.init() });
2274 },2274 },
2275 .Typedef => {2275 .Typedef => {
2276 const typedef_ty = @ptrCast(*const clang.TypedefType, ty);2276 const typedef_ty = @as(*const clang.TypedefType, @ptrCast(ty));
2277 const typedef_decl = typedef_ty.getDecl();2277 const typedef_decl = typedef_ty.getDecl();
2278 const underlying_type = typedef_decl.getUnderlyingType();2278 const underlying_type = typedef_decl.getUnderlyingType();
2279 return finishBoolExpr(c, scope, loc, underlying_type.getTypePtr(), node, used);2279 return finishBoolExpr(c, scope, loc, underlying_type.getTypePtr(), node, used);
...@@ -2283,7 +2283,7 @@ fn finishBoolExpr(...@@ -2283,7 +2283,7 @@ fn finishBoolExpr(
2283 return Tag.not_equal.create(c.arena, .{ .lhs = node, .rhs = Tag.zero_literal.init() });2283 return Tag.not_equal.create(c.arena, .{ .lhs = node, .rhs = Tag.zero_literal.init() });
2284 },2284 },
2285 .Elaborated => {2285 .Elaborated => {
2286 const elaborated_ty = @ptrCast(*const clang.ElaboratedType, ty);2286 const elaborated_ty = @as(*const clang.ElaboratedType, @ptrCast(ty));
2287 const named_type = elaborated_ty.getNamedType();2287 const named_type = elaborated_ty.getNamedType();
2288 return finishBoolExpr(c, scope, loc, named_type.getTypePtr(), node, used);2288 return finishBoolExpr(c, scope, loc, named_type.getTypePtr(), node, used);
2289 },2289 },
...@@ -2325,7 +2325,7 @@ fn transIntegerLiteral(...@@ -2325,7 +2325,7 @@ fn transIntegerLiteral(
2325 // But the first step is to be correct, and the next step is to make the output more elegant.2325 // But the first step is to be correct, and the next step is to make the output more elegant.
23262326
2327 // @as(T, x)2327 // @as(T, x)
2328 const expr_base = @ptrCast(*const clang.Expr, expr);2328 const expr_base = @as(*const clang.Expr, @ptrCast(expr));
2329 const ty_node = try transQualType(c, scope, expr_base.getType(), expr_base.getBeginLoc());2329 const ty_node = try transQualType(c, scope, expr_base.getType(), expr_base.getBeginLoc());
2330 const rhs = try transCreateNodeAPInt(c, eval_result.Val.getInt());2330 const rhs = try transCreateNodeAPInt(c, eval_result.Val.getInt());
2331 const as = try Tag.as.create(c.arena, .{ .lhs = ty_node, .rhs = rhs });2331 const as = try Tag.as.create(c.arena, .{ .lhs = ty_node, .rhs = rhs });
...@@ -2374,7 +2374,7 @@ fn transStringLiteral(...@@ -2374,7 +2374,7 @@ fn transStringLiteral(
2374 const str_type = @tagName(stmt.getKind());2374 const str_type = @tagName(stmt.getKind());
2375 const name = try std.fmt.allocPrint(c.arena, "zig.{s}_string_{d}", .{ str_type, c.getMangle() });2375 const name = try std.fmt.allocPrint(c.arena, "zig.{s}_string_{d}", .{ str_type, c.getMangle() });
23762376
2377 const expr_base = @ptrCast(*const clang.Expr, stmt);2377 const expr_base = @as(*const clang.Expr, @ptrCast(stmt));
2378 const array_type = try transQualTypeInitialized(c, scope, expr_base.getType(), expr_base, expr_base.getBeginLoc());2378 const array_type = try transQualTypeInitialized(c, scope, expr_base.getType(), expr_base, expr_base.getBeginLoc());
2379 const lit_array = try transStringLiteralInitializer(c, stmt, array_type);2379 const lit_array = try transStringLiteralInitializer(c, stmt, array_type);
2380 const decl = try Tag.var_simple.create(c.arena, .{ .name = name, .init = lit_array });2380 const decl = try Tag.var_simple.create(c.arena, .{ .name = name, .init = lit_array });
...@@ -2451,11 +2451,11 @@ fn transStringLiteralInitializer(...@@ -2451,11 +2451,11 @@ fn transStringLiteralInitializer(
2451/// both operands resolve to addresses. The C standard requires that both operands2451/// both operands resolve to addresses. The C standard requires that both operands
2452/// point to elements of the same array object, but we do not verify that here.2452/// point to elements of the same array object, but we do not verify that here.
2453fn cIsPointerDiffExpr(stmt: *const clang.BinaryOperator) bool {2453fn cIsPointerDiffExpr(stmt: *const clang.BinaryOperator) bool {
2454 const lhs = @ptrCast(*const clang.Stmt, stmt.getLHS());2454 const lhs = @as(*const clang.Stmt, @ptrCast(stmt.getLHS()));
2455 const rhs = @ptrCast(*const clang.Stmt, stmt.getRHS());2455 const rhs = @as(*const clang.Stmt, @ptrCast(stmt.getRHS()));
2456 return stmt.getOpcode() == .Sub and2456 return stmt.getOpcode() == .Sub and
2457 qualTypeIsPtr(@ptrCast(*const clang.Expr, lhs).getType()) and2457 qualTypeIsPtr(@as(*const clang.Expr, @ptrCast(lhs)).getType()) and
2458 qualTypeIsPtr(@ptrCast(*const clang.Expr, rhs).getType());2458 qualTypeIsPtr(@as(*const clang.Expr, @ptrCast(rhs)).getType());
2459}2459}
24602460
2461fn cIsEnum(qt: clang.QualType) bool {2461fn cIsEnum(qt: clang.QualType) bool {
...@@ -2472,7 +2472,7 @@ fn cIsVector(qt: clang.QualType) bool {...@@ -2472,7 +2472,7 @@ fn cIsVector(qt: clang.QualType) bool {
2472fn cIntTypeForEnum(enum_qt: clang.QualType) clang.QualType {2472fn cIntTypeForEnum(enum_qt: clang.QualType) clang.QualType {
2473 assert(cIsEnum(enum_qt));2473 assert(cIsEnum(enum_qt));
2474 const ty = enum_qt.getCanonicalType().getTypePtr();2474 const ty = enum_qt.getCanonicalType().getTypePtr();
2475 const enum_ty = @ptrCast(*const clang.EnumType, ty);2475 const enum_ty = @as(*const clang.EnumType, @ptrCast(ty));
2476 const enum_decl = enum_ty.getDecl();2476 const enum_decl = enum_ty.getDecl();
2477 return enum_decl.getIntegerType();2477 return enum_decl.getIntegerType();
2478}2478}
...@@ -2588,29 +2588,29 @@ fn transCCast(...@@ -2588,29 +2588,29 @@ fn transCCast(
2588}2588}
25892589
2590fn transExpr(c: *Context, scope: *Scope, expr: *const clang.Expr, used: ResultUsed) TransError!Node {2590fn transExpr(c: *Context, scope: *Scope, expr: *const clang.Expr, used: ResultUsed) TransError!Node {
2591 return transStmt(c, scope, @ptrCast(*const clang.Stmt, expr), used);2591 return transStmt(c, scope, @as(*const clang.Stmt, @ptrCast(expr)), used);
2592}2592}
25932593
2594/// Same as `transExpr` but with the knowledge that the operand will be type coerced, and therefore2594/// Same as `transExpr` but with the knowledge that the operand will be type coerced, and therefore
2595/// an `@as` would be redundant. This is used to prevent redundant `@as` in integer literals.2595/// an `@as` would be redundant. This is used to prevent redundant `@as` in integer literals.
2596fn transExprCoercing(c: *Context, scope: *Scope, expr: *const clang.Expr, used: ResultUsed) TransError!Node {2596fn transExprCoercing(c: *Context, scope: *Scope, expr: *const clang.Expr, used: ResultUsed) TransError!Node {
2597 switch (@ptrCast(*const clang.Stmt, expr).getStmtClass()) {2597 switch (@as(*const clang.Stmt, @ptrCast(expr)).getStmtClass()) {
2598 .IntegerLiteralClass => {2598 .IntegerLiteralClass => {
2599 return transIntegerLiteral(c, scope, @ptrCast(*const clang.IntegerLiteral, expr), .used, .no_as);2599 return transIntegerLiteral(c, scope, @as(*const clang.IntegerLiteral, @ptrCast(expr)), .used, .no_as);
2600 },2600 },
2601 .CharacterLiteralClass => {2601 .CharacterLiteralClass => {
2602 return transCharLiteral(c, scope, @ptrCast(*const clang.CharacterLiteral, expr), .used, .no_as);2602 return transCharLiteral(c, scope, @as(*const clang.CharacterLiteral, @ptrCast(expr)), .used, .no_as);
2603 },2603 },
2604 .UnaryOperatorClass => {2604 .UnaryOperatorClass => {
2605 const un_expr = @ptrCast(*const clang.UnaryOperator, expr);2605 const un_expr = @as(*const clang.UnaryOperator, @ptrCast(expr));
2606 if (un_expr.getOpcode() == .Extension) {2606 if (un_expr.getOpcode() == .Extension) {
2607 return transExprCoercing(c, scope, un_expr.getSubExpr(), used);2607 return transExprCoercing(c, scope, un_expr.getSubExpr(), used);
2608 }2608 }
2609 },2609 },
2610 .ImplicitCastExprClass => {2610 .ImplicitCastExprClass => {
2611 const cast_expr = @ptrCast(*const clang.ImplicitCastExpr, expr);2611 const cast_expr = @as(*const clang.ImplicitCastExpr, @ptrCast(expr));
2612 const sub_expr = cast_expr.getSubExpr();2612 const sub_expr = cast_expr.getSubExpr();
2613 switch (@ptrCast(*const clang.Stmt, sub_expr).getStmtClass()) {2613 switch (@as(*const clang.Stmt, @ptrCast(sub_expr)).getStmtClass()) {
2614 .IntegerLiteralClass, .CharacterLiteralClass => switch (cast_expr.getCastKind()) {2614 .IntegerLiteralClass, .CharacterLiteralClass => switch (cast_expr.getCastKind()) {
2615 .IntegralToFloating => return transExprCoercing(c, scope, sub_expr, used),2615 .IntegralToFloating => return transExprCoercing(c, scope, sub_expr, used),
2616 .IntegralCast => {2616 .IntegralCast => {
...@@ -2634,15 +2634,15 @@ fn literalFitsInType(c: *Context, expr: *const clang.Expr, qt: clang.QualType) b...@@ -2634,15 +2634,15 @@ fn literalFitsInType(c: *Context, expr: *const clang.Expr, qt: clang.QualType) b
2634 const is_signed = cIsSignedInteger(qt);2634 const is_signed = cIsSignedInteger(qt);
2635 const width_max_int = (@as(u64, 1) << math.lossyCast(u6, width - @intFromBool(is_signed))) - 1;2635 const width_max_int = (@as(u64, 1) << math.lossyCast(u6, width - @intFromBool(is_signed))) - 1;
26362636
2637 switch (@ptrCast(*const clang.Stmt, expr).getStmtClass()) {2637 switch (@as(*const clang.Stmt, @ptrCast(expr)).getStmtClass()) {
2638 .CharacterLiteralClass => {2638 .CharacterLiteralClass => {
2639 const char_lit = @ptrCast(*const clang.CharacterLiteral, expr);2639 const char_lit = @as(*const clang.CharacterLiteral, @ptrCast(expr));
2640 const val = char_lit.getValue();2640 const val = char_lit.getValue();
2641 // If the val is less than the max int then it fits.2641 // If the val is less than the max int then it fits.
2642 return val <= width_max_int;2642 return val <= width_max_int;
2643 },2643 },
2644 .IntegerLiteralClass => {2644 .IntegerLiteralClass => {
2645 const int_lit = @ptrCast(*const clang.IntegerLiteral, expr);2645 const int_lit = @as(*const clang.IntegerLiteral, @ptrCast(expr));
2646 var eval_result: clang.ExprEvalResult = undefined;2646 var eval_result: clang.ExprEvalResult = undefined;
2647 if (!int_lit.EvaluateAsInt(&eval_result, c.clang_context)) {2647 if (!int_lit.EvaluateAsInt(&eval_result, c.clang_context)) {
2648 return false;2648 return false;
...@@ -2695,7 +2695,7 @@ fn transInitListExprRecord(...@@ -2695,7 +2695,7 @@ fn transInitListExprRecord(
26952695
2696 // Generate the field assignment expression:2696 // Generate the field assignment expression:
2697 // .field_name = expr2697 // .field_name = expr
2698 var raw_name = try c.str(@ptrCast(*const clang.NamedDecl, field_decl).getName_bytes_begin());2698 var raw_name = try c.str(@as(*const clang.NamedDecl, @ptrCast(field_decl)).getName_bytes_begin());
2699 if (field_decl.isAnonymousStructOrUnion()) {2699 if (field_decl.isAnonymousStructOrUnion()) {
2700 const name = c.decl_table.get(@intFromPtr(field_decl.getCanonicalDecl())).?;2700 const name = c.decl_table.get(@intFromPtr(field_decl.getCanonicalDecl())).?;
2701 raw_name = try c.arena.dupe(u8, name);2701 raw_name = try c.arena.dupe(u8, name);
...@@ -2736,8 +2736,8 @@ fn transInitListExprArray(...@@ -2736,8 +2736,8 @@ fn transInitListExprArray(
2736 const child_qt = arr_type.getElementType();2736 const child_qt = arr_type.getElementType();
2737 const child_type = try transQualType(c, scope, child_qt, loc);2737 const child_type = try transQualType(c, scope, child_qt, loc);
2738 const init_count = expr.getNumInits();2738 const init_count = expr.getNumInits();
2739 assert(@ptrCast(*const clang.Type, arr_type).isConstantArrayType());2739 assert(@as(*const clang.Type, @ptrCast(arr_type)).isConstantArrayType());
2740 const const_arr_ty = @ptrCast(*const clang.ConstantArrayType, arr_type);2740 const const_arr_ty = @as(*const clang.ConstantArrayType, @ptrCast(arr_type));
2741 const size_ap_int = const_arr_ty.getSize();2741 const size_ap_int = const_arr_ty.getSize();
2742 const all_count = size_ap_int.getLimitedValue(usize);2742 const all_count = size_ap_int.getLimitedValue(usize);
2743 const leftover_count = all_count - init_count;2743 const leftover_count = all_count - init_count;
...@@ -2757,7 +2757,7 @@ fn transInitListExprArray(...@@ -2757,7 +2757,7 @@ fn transInitListExprArray(
2757 const init_list = try c.arena.alloc(Node, init_count);2757 const init_list = try c.arena.alloc(Node, init_count);
27582758
2759 for (init_list, 0..) |*init, i| {2759 for (init_list, 0..) |*init, i| {
2760 const elem_expr = expr.getInit(@intCast(c_uint, i));2760 const elem_expr = expr.getInit(@as(c_uint, @intCast(i)));
2761 init.* = try transExprCoercing(c, scope, elem_expr, .used);2761 init.* = try transExprCoercing(c, scope, elem_expr, .used);
2762 }2762 }
2763 const init_node = try Tag.array_init.create(c.arena, .{2763 const init_node = try Tag.array_init.create(c.arena, .{
...@@ -2791,8 +2791,8 @@ fn transInitListExprVector(...@@ -2791,8 +2791,8 @@ fn transInitListExprVector(
2791 loc: clang.SourceLocation,2791 loc: clang.SourceLocation,
2792 expr: *const clang.InitListExpr,2792 expr: *const clang.InitListExpr,
2793) TransError!Node {2793) TransError!Node {
2794 const qt = getExprQualType(c, @ptrCast(*const clang.Expr, expr));2794 const qt = getExprQualType(c, @as(*const clang.Expr, @ptrCast(expr)));
2795 const vector_ty = @ptrCast(*const clang.VectorType, qualTypeCanon(qt));2795 const vector_ty = @as(*const clang.VectorType, @ptrCast(qualTypeCanon(qt)));
27962796
2797 const init_count = expr.getNumInits();2797 const init_count = expr.getNumInits();
2798 const num_elements = vector_ty.getNumElements();2798 const num_elements = vector_ty.getNumElements();
...@@ -2822,7 +2822,7 @@ fn transInitListExprVector(...@@ -2822,7 +2822,7 @@ fn transInitListExprVector(
2822 var i: usize = 0;2822 var i: usize = 0;
2823 while (i < init_count) : (i += 1) {2823 while (i < init_count) : (i += 1) {
2824 const mangled_name = try block_scope.makeMangledName(c, "tmp");2824 const mangled_name = try block_scope.makeMangledName(c, "tmp");
2825 const init_expr = expr.getInit(@intCast(c_uint, i));2825 const init_expr = expr.getInit(@as(c_uint, @intCast(i)));
2826 const tmp_decl_node = try Tag.var_simple.create(c.arena, .{2826 const tmp_decl_node = try Tag.var_simple.create(c.arena, .{
2827 .name = mangled_name,2827 .name = mangled_name,
2828 .init = try transExpr(c, &block_scope.base, init_expr, .used),2828 .init = try transExpr(c, &block_scope.base, init_expr, .used),
...@@ -2860,9 +2860,9 @@ fn transInitListExpr(...@@ -2860,9 +2860,9 @@ fn transInitListExpr(
2860 expr: *const clang.InitListExpr,2860 expr: *const clang.InitListExpr,
2861 used: ResultUsed,2861 used: ResultUsed,
2862) TransError!Node {2862) TransError!Node {
2863 const qt = getExprQualType(c, @ptrCast(*const clang.Expr, expr));2863 const qt = getExprQualType(c, @as(*const clang.Expr, @ptrCast(expr)));
2864 var qual_type = qt.getTypePtr();2864 var qual_type = qt.getTypePtr();
2865 const source_loc = @ptrCast(*const clang.Expr, expr).getBeginLoc();2865 const source_loc = @as(*const clang.Expr, @ptrCast(expr)).getBeginLoc();
28662866
2867 if (qualTypeWasDemotedToOpaque(c, qt)) {2867 if (qualTypeWasDemotedToOpaque(c, qt)) {
2868 return fail(c, error.UnsupportedTranslation, source_loc, "cannot initialize opaque type", .{});2868 return fail(c, error.UnsupportedTranslation, source_loc, "cannot initialize opaque type", .{});
...@@ -2900,7 +2900,7 @@ fn transZeroInitExpr(...@@ -2900,7 +2900,7 @@ fn transZeroInitExpr(
2900) TransError!Node {2900) TransError!Node {
2901 switch (ty.getTypeClass()) {2901 switch (ty.getTypeClass()) {
2902 .Builtin => {2902 .Builtin => {
2903 const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);2903 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(ty));
2904 switch (builtin_ty.getKind()) {2904 switch (builtin_ty.getKind()) {
2905 .Bool => return Tag.false_literal.init(),2905 .Bool => return Tag.false_literal.init(),
2906 .Char_U,2906 .Char_U,
...@@ -2929,7 +2929,7 @@ fn transZeroInitExpr(...@@ -2929,7 +2929,7 @@ fn transZeroInitExpr(
2929 },2929 },
2930 .Pointer => return Tag.null_literal.init(),2930 .Pointer => return Tag.null_literal.init(),
2931 .Typedef => {2931 .Typedef => {
2932 const typedef_ty = @ptrCast(*const clang.TypedefType, ty);2932 const typedef_ty = @as(*const clang.TypedefType, @ptrCast(ty));
2933 const typedef_decl = typedef_ty.getDecl();2933 const typedef_decl = typedef_ty.getDecl();
2934 return transZeroInitExpr(2934 return transZeroInitExpr(
2935 c,2935 c,
...@@ -2998,7 +2998,7 @@ fn transIfStmt(...@@ -2998,7 +2998,7 @@ fn transIfStmt(
2998 },2998 },
2999 };2999 };
3000 defer cond_scope.deinit();3000 defer cond_scope.deinit();
3001 const cond_expr = @ptrCast(*const clang.Expr, stmt.getCond());3001 const cond_expr = @as(*const clang.Expr, @ptrCast(stmt.getCond()));
3002 const cond = try transBoolExpr(c, &cond_scope.base, cond_expr, .used);3002 const cond = try transBoolExpr(c, &cond_scope.base, cond_expr, .used);
30033003
3004 const then_stmt = stmt.getThen();3004 const then_stmt = stmt.getThen();
...@@ -3034,7 +3034,7 @@ fn transWhileLoop(...@@ -3034,7 +3034,7 @@ fn transWhileLoop(
3034 },3034 },
3035 };3035 };
3036 defer cond_scope.deinit();3036 defer cond_scope.deinit();
3037 const cond_expr = @ptrCast(*const clang.Expr, stmt.getCond());3037 const cond_expr = @as(*const clang.Expr, @ptrCast(stmt.getCond()));
3038 const cond = try transBoolExpr(c, &cond_scope.base, cond_expr, .used);3038 const cond = try transBoolExpr(c, &cond_scope.base, cond_expr, .used);
30393039
3040 var loop_scope = Scope{3040 var loop_scope = Scope{
...@@ -3063,7 +3063,7 @@ fn transDoWhileLoop(...@@ -3063,7 +3063,7 @@ fn transDoWhileLoop(
3063 },3063 },
3064 };3064 };
3065 defer cond_scope.deinit();3065 defer cond_scope.deinit();
3066 const cond = try transBoolExpr(c, &cond_scope.base, @ptrCast(*const clang.Expr, stmt.getCond()), .used);3066 const cond = try transBoolExpr(c, &cond_scope.base, @as(*const clang.Expr, @ptrCast(stmt.getCond())), .used);
3067 const if_not_break = switch (cond.tag()) {3067 const if_not_break = switch (cond.tag()) {
3068 .true_literal => {3068 .true_literal => {
3069 const body_node = try maybeBlockify(c, scope, stmt.getBody());3069 const body_node = try maybeBlockify(c, scope, stmt.getBody());
...@@ -3184,7 +3184,7 @@ fn transSwitch(...@@ -3184,7 +3184,7 @@ fn transSwitch(
31843184
3185 const body = stmt.getBody();3185 const body = stmt.getBody();
3186 assert(body.getStmtClass() == .CompoundStmtClass);3186 assert(body.getStmtClass() == .CompoundStmtClass);
3187 const compound_stmt = @ptrCast(*const clang.CompoundStmt, body);3187 const compound_stmt = @as(*const clang.CompoundStmt, @ptrCast(body));
3188 var it = compound_stmt.body_begin();3188 var it = compound_stmt.body_begin();
3189 const end_it = compound_stmt.body_end();3189 const end_it = compound_stmt.body_end();
3190 // Iterate over switch body and collect all cases.3190 // Iterate over switch body and collect all cases.
...@@ -3211,12 +3211,12 @@ fn transSwitch(...@@ -3211,12 +3211,12 @@ fn transSwitch(
3211 },3211 },
3212 .DefaultStmtClass => {3212 .DefaultStmtClass => {
3213 has_default = true;3213 has_default = true;
3214 const default_stmt = @ptrCast(*const clang.DefaultStmt, it[0]);3214 const default_stmt = @as(*const clang.DefaultStmt, @ptrCast(it[0]));
32153215
3216 var sub = default_stmt.getSubStmt();3216 var sub = default_stmt.getSubStmt();
3217 while (true) switch (sub.getStmtClass()) {3217 while (true) switch (sub.getStmtClass()) {
3218 .CaseStmtClass => sub = @ptrCast(*const clang.CaseStmt, sub).getSubStmt(),3218 .CaseStmtClass => sub = @as(*const clang.CaseStmt, @ptrCast(sub)).getSubStmt(),
3219 .DefaultStmtClass => sub = @ptrCast(*const clang.DefaultStmt, sub).getSubStmt(),3219 .DefaultStmtClass => sub = @as(*const clang.DefaultStmt, @ptrCast(sub)).getSubStmt(),
3220 else => break,3220 else => break,
3221 };3221 };
32223222
...@@ -3255,11 +3255,11 @@ fn transCaseStmt(c: *Context, scope: *Scope, stmt: *const clang.Stmt, items: *st...@@ -3255,11 +3255,11 @@ fn transCaseStmt(c: *Context, scope: *Scope, stmt: *const clang.Stmt, items: *st
3255 .DefaultStmtClass => {3255 .DefaultStmtClass => {
3256 seen_default = true;3256 seen_default = true;
3257 items.items.len = 0;3257 items.items.len = 0;
3258 const default_stmt = @ptrCast(*const clang.DefaultStmt, sub);3258 const default_stmt = @as(*const clang.DefaultStmt, @ptrCast(sub));
3259 sub = default_stmt.getSubStmt();3259 sub = default_stmt.getSubStmt();
3260 },3260 },
3261 .CaseStmtClass => {3261 .CaseStmtClass => {
3262 const case_stmt = @ptrCast(*const clang.CaseStmt, sub);3262 const case_stmt = @as(*const clang.CaseStmt, @ptrCast(sub));
32633263
3264 if (seen_default) {3264 if (seen_default) {
3265 items.items.len = 0;3265 items.items.len = 0;
...@@ -3326,10 +3326,10 @@ fn transSwitchProngStmtInline(...@@ -3326,10 +3326,10 @@ fn transSwitchProngStmtInline(
3326 return;3326 return;
3327 },3327 },
3328 .CaseStmtClass => {3328 .CaseStmtClass => {
3329 var sub = @ptrCast(*const clang.CaseStmt, it[0]).getSubStmt();3329 var sub = @as(*const clang.CaseStmt, @ptrCast(it[0])).getSubStmt();
3330 while (true) switch (sub.getStmtClass()) {3330 while (true) switch (sub.getStmtClass()) {
3331 .CaseStmtClass => sub = @ptrCast(*const clang.CaseStmt, sub).getSubStmt(),3331 .CaseStmtClass => sub = @as(*const clang.CaseStmt, @ptrCast(sub)).getSubStmt(),
3332 .DefaultStmtClass => sub = @ptrCast(*const clang.DefaultStmt, sub).getSubStmt(),3332 .DefaultStmtClass => sub = @as(*const clang.DefaultStmt, @ptrCast(sub)).getSubStmt(),
3333 else => break,3333 else => break,
3334 };3334 };
3335 const result = try transStmt(c, &block.base, sub, .unused);3335 const result = try transStmt(c, &block.base, sub, .unused);
...@@ -3340,10 +3340,10 @@ fn transSwitchProngStmtInline(...@@ -3340,10 +3340,10 @@ fn transSwitchProngStmtInline(
3340 }3340 }
3341 },3341 },
3342 .DefaultStmtClass => {3342 .DefaultStmtClass => {
3343 var sub = @ptrCast(*const clang.DefaultStmt, it[0]).getSubStmt();3343 var sub = @as(*const clang.DefaultStmt, @ptrCast(it[0])).getSubStmt();
3344 while (true) switch (sub.getStmtClass()) {3344 while (true) switch (sub.getStmtClass()) {
3345 .CaseStmtClass => sub = @ptrCast(*const clang.CaseStmt, sub).getSubStmt(),3345 .CaseStmtClass => sub = @as(*const clang.CaseStmt, @ptrCast(sub)).getSubStmt(),
3346 .DefaultStmtClass => sub = @ptrCast(*const clang.DefaultStmt, sub).getSubStmt(),3346 .DefaultStmtClass => sub = @as(*const clang.DefaultStmt, @ptrCast(sub)).getSubStmt(),
3347 else => break,3347 else => break,
3348 };3348 };
3349 const result = try transStmt(c, &block.base, sub, .unused);3349 const result = try transStmt(c, &block.base, sub, .unused);
...@@ -3354,7 +3354,7 @@ fn transSwitchProngStmtInline(...@@ -3354,7 +3354,7 @@ fn transSwitchProngStmtInline(
3354 }3354 }
3355 },3355 },
3356 .CompoundStmtClass => {3356 .CompoundStmtClass => {
3357 const result = try transCompoundStmt(c, &block.base, @ptrCast(*const clang.CompoundStmt, it[0]));3357 const result = try transCompoundStmt(c, &block.base, @as(*const clang.CompoundStmt, @ptrCast(it[0])));
3358 try block.statements.append(result);3358 try block.statements.append(result);
3359 if (result.isNoreturn(true)) {3359 if (result.isNoreturn(true)) {
3360 return;3360 return;
...@@ -3381,7 +3381,7 @@ fn transConstantExpr(c: *Context, scope: *Scope, expr: *const clang.Expr, used:...@@ -3381,7 +3381,7 @@ fn transConstantExpr(c: *Context, scope: *Scope, expr: *const clang.Expr, used:
3381 .Int => {3381 .Int => {
3382 // See comment in `transIntegerLiteral` for why this code is here.3382 // See comment in `transIntegerLiteral` for why this code is here.
3383 // @as(T, x)3383 // @as(T, x)
3384 const expr_base = @ptrCast(*const clang.Expr, expr);3384 const expr_base = @as(*const clang.Expr, @ptrCast(expr));
3385 const as_node = try Tag.as.create(c.arena, .{3385 const as_node = try Tag.as.create(c.arena, .{
3386 .lhs = try transQualType(c, scope, expr_base.getType(), expr_base.getBeginLoc()),3386 .lhs = try transQualType(c, scope, expr_base.getType(), expr_base.getBeginLoc()),
3387 .rhs = try transCreateNodeAPInt(c, result.Val.getInt()),3387 .rhs = try transCreateNodeAPInt(c, result.Val.getInt()),
...@@ -3400,7 +3400,7 @@ fn transPredefinedExpr(c: *Context, scope: *Scope, expr: *const clang.Predefined...@@ -3400,7 +3400,7 @@ fn transPredefinedExpr(c: *Context, scope: *Scope, expr: *const clang.Predefined
34003400
3401fn transCreateCharLitNode(c: *Context, narrow: bool, val: u32) TransError!Node {3401fn transCreateCharLitNode(c: *Context, narrow: bool, val: u32) TransError!Node {
3402 return Tag.char_literal.create(c.arena, if (narrow)3402 return Tag.char_literal.create(c.arena, if (narrow)
3403 try std.fmt.allocPrint(c.arena, "'{'}'", .{std.zig.fmtEscapes(&.{@intCast(u8, val)})})3403 try std.fmt.allocPrint(c.arena, "'{'}'", .{std.zig.fmtEscapes(&.{@as(u8, @intCast(val))})})
3404 else3404 else
3405 try std.fmt.allocPrint(c.arena, "'\\u{{{x}}}'", .{val}));3405 try std.fmt.allocPrint(c.arena, "'\\u{{{x}}}'", .{val}));
3406}3406}
...@@ -3427,7 +3427,7 @@ fn transCharLiteral(...@@ -3427,7 +3427,7 @@ fn transCharLiteral(
3427 }3427 }
3428 // See comment in `transIntegerLiteral` for why this code is here.3428 // See comment in `transIntegerLiteral` for why this code is here.
3429 // @as(T, x)3429 // @as(T, x)
3430 const expr_base = @ptrCast(*const clang.Expr, stmt);3430 const expr_base = @as(*const clang.Expr, @ptrCast(stmt));
3431 const as_node = try Tag.as.create(c.arena, .{3431 const as_node = try Tag.as.create(c.arena, .{
3432 .lhs = try transQualType(c, scope, expr_base.getType(), expr_base.getBeginLoc()),3432 .lhs = try transQualType(c, scope, expr_base.getType(), expr_base.getBeginLoc()),
3433 .rhs = int_lit_node,3433 .rhs = int_lit_node,
...@@ -3469,22 +3469,22 @@ fn transMemberExpr(c: *Context, scope: *Scope, stmt: *const clang.MemberExpr, re...@@ -3469,22 +3469,22 @@ fn transMemberExpr(c: *Context, scope: *Scope, stmt: *const clang.MemberExpr, re
34693469
3470 const member_decl = stmt.getMemberDecl();3470 const member_decl = stmt.getMemberDecl();
3471 const name = blk: {3471 const name = blk: {
3472 const decl_kind = @ptrCast(*const clang.Decl, member_decl).getKind();3472 const decl_kind = @as(*const clang.Decl, @ptrCast(member_decl)).getKind();
3473 // If we're referring to a anonymous struct/enum find the bogus name3473 // If we're referring to a anonymous struct/enum find the bogus name
3474 // we've assigned to it during the RecordDecl translation3474 // we've assigned to it during the RecordDecl translation
3475 if (decl_kind == .Field) {3475 if (decl_kind == .Field) {
3476 const field_decl = @ptrCast(*const clang.FieldDecl, member_decl);3476 const field_decl = @as(*const clang.FieldDecl, @ptrCast(member_decl));
3477 if (field_decl.isAnonymousStructOrUnion()) {3477 if (field_decl.isAnonymousStructOrUnion()) {
3478 const name = c.decl_table.get(@intFromPtr(field_decl.getCanonicalDecl())).?;3478 const name = c.decl_table.get(@intFromPtr(field_decl.getCanonicalDecl())).?;
3479 break :blk try c.arena.dupe(u8, name);3479 break :blk try c.arena.dupe(u8, name);
3480 }3480 }
3481 }3481 }
3482 const decl = @ptrCast(*const clang.NamedDecl, member_decl);3482 const decl = @as(*const clang.NamedDecl, @ptrCast(member_decl));
3483 break :blk try c.str(decl.getName_bytes_begin());3483 break :blk try c.str(decl.getName_bytes_begin());
3484 };3484 };
34853485
3486 var node = try Tag.field_access.create(c.arena, .{ .lhs = container_node, .field_name = name });3486 var node = try Tag.field_access.create(c.arena, .{ .lhs = container_node, .field_name = name });
3487 if (exprIsFlexibleArrayRef(c, @ptrCast(*const clang.Expr, stmt))) {3487 if (exprIsFlexibleArrayRef(c, @as(*const clang.Expr, @ptrCast(stmt)))) {
3488 node = try Tag.call.create(c.arena, .{ .lhs = node, .args = &.{} });3488 node = try Tag.call.create(c.arena, .{ .lhs = node, .args = &.{} });
3489 }3489 }
3490 return maybeSuppressResult(c, result_used, node);3490 return maybeSuppressResult(c, result_used, node);
...@@ -3582,8 +3582,8 @@ fn transArrayAccess(c: *Context, scope: *Scope, stmt: *const clang.ArraySubscrip...@@ -3582,8 +3582,8 @@ fn transArrayAccess(c: *Context, scope: *Scope, stmt: *const clang.ArraySubscrip
3582 // Unwrap the base statement if it's an array decayed to a bare pointer type3582 // Unwrap the base statement if it's an array decayed to a bare pointer type
3583 // so that we index the array itself3583 // so that we index the array itself
3584 var unwrapped_base = base_stmt;3584 var unwrapped_base = base_stmt;
3585 if (@ptrCast(*const clang.Stmt, base_stmt).getStmtClass() == .ImplicitCastExprClass) {3585 if (@as(*const clang.Stmt, @ptrCast(base_stmt)).getStmtClass() == .ImplicitCastExprClass) {
3586 const implicit_cast = @ptrCast(*const clang.ImplicitCastExpr, base_stmt);3586 const implicit_cast = @as(*const clang.ImplicitCastExpr, @ptrCast(base_stmt));
35873587
3588 if (implicit_cast.getCastKind() == .ArrayToPointerDecay) {3588 if (implicit_cast.getCastKind() == .ArrayToPointerDecay) {
3589 unwrapped_base = implicit_cast.getSubExpr();3589 unwrapped_base = implicit_cast.getSubExpr();
...@@ -3620,17 +3620,17 @@ fn transArrayAccess(c: *Context, scope: *Scope, stmt: *const clang.ArraySubscrip...@@ -3620,17 +3620,17 @@ fn transArrayAccess(c: *Context, scope: *Scope, stmt: *const clang.ArraySubscrip
3620fn cIsFunctionDeclRef(expr: *const clang.Expr) bool {3620fn cIsFunctionDeclRef(expr: *const clang.Expr) bool {
3621 switch (expr.getStmtClass()) {3621 switch (expr.getStmtClass()) {
3622 .ParenExprClass => {3622 .ParenExprClass => {
3623 const op_expr = @ptrCast(*const clang.ParenExpr, expr).getSubExpr();3623 const op_expr = @as(*const clang.ParenExpr, @ptrCast(expr)).getSubExpr();
3624 return cIsFunctionDeclRef(op_expr);3624 return cIsFunctionDeclRef(op_expr);
3625 },3625 },
3626 .DeclRefExprClass => {3626 .DeclRefExprClass => {
3627 const decl_ref = @ptrCast(*const clang.DeclRefExpr, expr);3627 const decl_ref = @as(*const clang.DeclRefExpr, @ptrCast(expr));
3628 const value_decl = decl_ref.getDecl();3628 const value_decl = decl_ref.getDecl();
3629 const qt = value_decl.getType();3629 const qt = value_decl.getType();
3630 return qualTypeChildIsFnProto(qt);3630 return qualTypeChildIsFnProto(qt);
3631 },3631 },
3632 .ImplicitCastExprClass => {3632 .ImplicitCastExprClass => {
3633 const implicit_cast = @ptrCast(*const clang.ImplicitCastExpr, expr);3633 const implicit_cast = @as(*const clang.ImplicitCastExpr, @ptrCast(expr));
3634 const cast_kind = implicit_cast.getCastKind();3634 const cast_kind = implicit_cast.getCastKind();
3635 if (cast_kind == .BuiltinFnToFnPtr) return true;3635 if (cast_kind == .BuiltinFnToFnPtr) return true;
3636 if (cast_kind == .FunctionToPointerDecay) {3636 if (cast_kind == .FunctionToPointerDecay) {
...@@ -3639,12 +3639,12 @@ fn cIsFunctionDeclRef(expr: *const clang.Expr) bool {...@@ -3639,12 +3639,12 @@ fn cIsFunctionDeclRef(expr: *const clang.Expr) bool {
3639 return false;3639 return false;
3640 },3640 },
3641 .UnaryOperatorClass => {3641 .UnaryOperatorClass => {
3642 const un_op = @ptrCast(*const clang.UnaryOperator, expr);3642 const un_op = @as(*const clang.UnaryOperator, @ptrCast(expr));
3643 const opcode = un_op.getOpcode();3643 const opcode = un_op.getOpcode();
3644 return (opcode == .AddrOf or opcode == .Deref) and cIsFunctionDeclRef(un_op.getSubExpr());3644 return (opcode == .AddrOf or opcode == .Deref) and cIsFunctionDeclRef(un_op.getSubExpr());
3645 },3645 },
3646 .GenericSelectionExprClass => {3646 .GenericSelectionExprClass => {
3647 const gen_sel = @ptrCast(*const clang.GenericSelectionExpr, expr);3647 const gen_sel = @as(*const clang.GenericSelectionExpr, @ptrCast(expr));
3648 return cIsFunctionDeclRef(gen_sel.getResultExpr());3648 return cIsFunctionDeclRef(gen_sel.getResultExpr());
3649 },3649 },
3650 else => return false,3650 else => return false,
...@@ -3679,11 +3679,11 @@ fn transCallExpr(c: *Context, scope: *Scope, stmt: *const clang.CallExpr, result...@@ -3679,11 +3679,11 @@ fn transCallExpr(c: *Context, scope: *Scope, stmt: *const clang.CallExpr, result
3679 .Proto => |fn_proto| {3679 .Proto => |fn_proto| {
3680 const param_count = fn_proto.getNumParams();3680 const param_count = fn_proto.getNumParams();
3681 if (i < param_count) {3681 if (i < param_count) {
3682 const param_qt = fn_proto.getParamType(@intCast(c_uint, i));3682 const param_qt = fn_proto.getParamType(@as(c_uint, @intCast(i)));
3683 if (isBoolRes(arg) and cIsNativeInt(param_qt)) {3683 if (isBoolRes(arg) and cIsNativeInt(param_qt)) {
3684 arg = try Tag.int_from_bool.create(c.arena, arg);3684 arg = try Tag.int_from_bool.create(c.arena, arg);
3685 } else if (arg.tag() == .string_literal and qualTypeIsCharStar(param_qt)) {3685 } else if (arg.tag() == .string_literal and qualTypeIsCharStar(param_qt)) {
3686 const loc = @ptrCast(*const clang.Stmt, stmt).getBeginLoc();3686 const loc = @as(*const clang.Stmt, @ptrCast(stmt)).getBeginLoc();
3687 const dst_type_node = try transQualType(c, scope, param_qt, loc);3687 const dst_type_node = try transQualType(c, scope, param_qt, loc);
3688 arg = try removeCVQualifiers(c, dst_type_node, arg);3688 arg = try removeCVQualifiers(c, dst_type_node, arg);
3689 }3689 }
...@@ -3729,10 +3729,10 @@ fn qualTypeGetFnProto(qt: clang.QualType, is_ptr: *bool) ?ClangFunctionType {...@@ -3729,10 +3729,10 @@ fn qualTypeGetFnProto(qt: clang.QualType, is_ptr: *bool) ?ClangFunctionType {
3729 ty = child_qt.getTypePtr();3729 ty = child_qt.getTypePtr();
3730 }3730 }
3731 if (ty.getTypeClass() == .FunctionProto) {3731 if (ty.getTypeClass() == .FunctionProto) {
3732 return ClangFunctionType{ .Proto = @ptrCast(*const clang.FunctionProtoType, ty) };3732 return ClangFunctionType{ .Proto = @as(*const clang.FunctionProtoType, @ptrCast(ty)) };
3733 }3733 }
3734 if (ty.getTypeClass() == .FunctionNoProto) {3734 if (ty.getTypeClass() == .FunctionNoProto) {
3735 return ClangFunctionType{ .NoProto = @ptrCast(*const clang.FunctionType, ty) };3735 return ClangFunctionType{ .NoProto = @as(*const clang.FunctionType, @ptrCast(ty)) };
3736 }3736 }
3737 return null;3737 return null;
3738}3738}
...@@ -4141,9 +4141,9 @@ fn transFloatingLiteral(c: *Context, expr: *const clang.FloatingLiteral, used: R...@@ -4141,9 +4141,9 @@ fn transFloatingLiteral(c: *Context, expr: *const clang.FloatingLiteral, used: R
4141fn transBinaryConditionalOperator(c: *Context, scope: *Scope, stmt: *const clang.BinaryConditionalOperator, used: ResultUsed) TransError!Node {4141fn transBinaryConditionalOperator(c: *Context, scope: *Scope, stmt: *const clang.BinaryConditionalOperator, used: ResultUsed) TransError!Node {
4142 // GNU extension of the ternary operator where the middle expression is4142 // GNU extension of the ternary operator where the middle expression is
4143 // omitted, the condition itself is returned if it evaluates to true4143 // omitted, the condition itself is returned if it evaluates to true
4144 const qt = @ptrCast(*const clang.Expr, stmt).getType();4144 const qt = @as(*const clang.Expr, @ptrCast(stmt)).getType();
4145 const res_is_bool = qualTypeIsBoolean(qt);4145 const res_is_bool = qualTypeIsBoolean(qt);
4146 const casted_stmt = @ptrCast(*const clang.AbstractConditionalOperator, stmt);4146 const casted_stmt = @as(*const clang.AbstractConditionalOperator, @ptrCast(stmt));
4147 const cond_expr = casted_stmt.getCond();4147 const cond_expr = casted_stmt.getCond();
4148 const false_expr = casted_stmt.getFalseExpr();4148 const false_expr = casted_stmt.getFalseExpr();
41494149
...@@ -4203,9 +4203,9 @@ fn transConditionalOperator(c: *Context, scope: *Scope, stmt: *const clang.Condi...@@ -4203,9 +4203,9 @@ fn transConditionalOperator(c: *Context, scope: *Scope, stmt: *const clang.Condi
4203 };4203 };
4204 defer cond_scope.deinit();4204 defer cond_scope.deinit();
42054205
4206 const qt = @ptrCast(*const clang.Expr, stmt).getType();4206 const qt = @as(*const clang.Expr, @ptrCast(stmt)).getType();
4207 const res_is_bool = qualTypeIsBoolean(qt);4207 const res_is_bool = qualTypeIsBoolean(qt);
4208 const casted_stmt = @ptrCast(*const clang.AbstractConditionalOperator, stmt);4208 const casted_stmt = @as(*const clang.AbstractConditionalOperator, @ptrCast(stmt));
4209 const cond_expr = casted_stmt.getCond();4209 const cond_expr = casted_stmt.getCond();
4210 const true_expr = casted_stmt.getTrueExpr();4210 const true_expr = casted_stmt.getTrueExpr();
4211 const false_expr = casted_stmt.getFalseExpr();4211 const false_expr = casted_stmt.getFalseExpr();
...@@ -4246,7 +4246,7 @@ fn addTopLevelDecl(c: *Context, name: []const u8, decl_node: Node) !void {...@@ -4246,7 +4246,7 @@ fn addTopLevelDecl(c: *Context, name: []const u8, decl_node: Node) !void {
42464246
4247fn transQualTypeInitializedStringLiteral(c: *Context, elem_ty: Node, string_lit: *const clang.StringLiteral) TypeError!Node {4247fn transQualTypeInitializedStringLiteral(c: *Context, elem_ty: Node, string_lit: *const clang.StringLiteral) TypeError!Node {
4248 const string_lit_size = string_lit.getLength();4248 const string_lit_size = string_lit.getLength();
4249 const array_size = @intCast(usize, string_lit_size);4249 const array_size = @as(usize, @intCast(string_lit_size));
42504250
4251 // incomplete array initialized with empty string, will be translated as [1]T{0}4251 // incomplete array initialized with empty string, will be translated as [1]T{0}
4252 // see https://github.com/ziglang/zig/issues/82564252 // see https://github.com/ziglang/zig/issues/8256
...@@ -4266,16 +4266,16 @@ fn transQualTypeInitialized(...@@ -4266,16 +4266,16 @@ fn transQualTypeInitialized(
4266) TypeError!Node {4266) TypeError!Node {
4267 const ty = qt.getTypePtr();4267 const ty = qt.getTypePtr();
4268 if (ty.getTypeClass() == .IncompleteArray) {4268 if (ty.getTypeClass() == .IncompleteArray) {
4269 const incomplete_array_ty = @ptrCast(*const clang.IncompleteArrayType, ty);4269 const incomplete_array_ty = @as(*const clang.IncompleteArrayType, @ptrCast(ty));
4270 const elem_ty = try transType(c, scope, incomplete_array_ty.getElementType().getTypePtr(), source_loc);4270 const elem_ty = try transType(c, scope, incomplete_array_ty.getElementType().getTypePtr(), source_loc);
42714271
4272 switch (decl_init.getStmtClass()) {4272 switch (decl_init.getStmtClass()) {
4273 .StringLiteralClass => {4273 .StringLiteralClass => {
4274 const string_lit = @ptrCast(*const clang.StringLiteral, decl_init);4274 const string_lit = @as(*const clang.StringLiteral, @ptrCast(decl_init));
4275 return transQualTypeInitializedStringLiteral(c, elem_ty, string_lit);4275 return transQualTypeInitializedStringLiteral(c, elem_ty, string_lit);
4276 },4276 },
4277 .InitListExprClass => {4277 .InitListExprClass => {
4278 const init_expr = @ptrCast(*const clang.InitListExpr, decl_init);4278 const init_expr = @as(*const clang.InitListExpr, @ptrCast(decl_init));
4279 const size = init_expr.getNumInits();4279 const size = init_expr.getNumInits();
42804280
4281 if (init_expr.isStringLiteralInit()) {4281 if (init_expr.isStringLiteralInit()) {
...@@ -4306,7 +4306,7 @@ fn transQualTypeIntWidthOf(c: *Context, ty: clang.QualType, is_signed: bool) Typ...@@ -4306,7 +4306,7 @@ fn transQualTypeIntWidthOf(c: *Context, ty: clang.QualType, is_signed: bool) Typ
4306/// Asserts the type is an integer.4306/// Asserts the type is an integer.
4307fn transTypeIntWidthOf(c: *Context, ty: *const clang.Type, is_signed: bool) TypeError!Node {4307fn transTypeIntWidthOf(c: *Context, ty: *const clang.Type, is_signed: bool) TypeError!Node {
4308 assert(ty.getTypeClass() == .Builtin);4308 assert(ty.getTypeClass() == .Builtin);
4309 const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);4309 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(ty));
4310 return Tag.type.create(c.arena, switch (builtin_ty.getKind()) {4310 return Tag.type.create(c.arena, switch (builtin_ty.getKind()) {
4311 .Char_U, .Char_S, .UChar, .SChar, .Char8 => if (is_signed) "i8" else "u8",4311 .Char_U, .Char_S, .UChar, .SChar, .Char8 => if (is_signed) "i8" else "u8",
4312 .UShort, .Short => if (is_signed) "c_short" else "c_ushort",4312 .UShort, .Short => if (is_signed) "c_short" else "c_ushort",
...@@ -4324,7 +4324,7 @@ fn isCBuiltinType(qt: clang.QualType, kind: clang.BuiltinTypeKind) bool {...@@ -4324,7 +4324,7 @@ fn isCBuiltinType(qt: clang.QualType, kind: clang.BuiltinTypeKind) bool {
4324 const c_type = qualTypeCanon(qt);4324 const c_type = qualTypeCanon(qt);
4325 if (c_type.getTypeClass() != .Builtin)4325 if (c_type.getTypeClass() != .Builtin)
4326 return false;4326 return false;
4327 const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);4327 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(c_type));
4328 return builtin_ty.getKind() == kind;4328 return builtin_ty.getKind() == kind;
4329}4329}
43304330
...@@ -4341,7 +4341,7 @@ fn qualTypeIntBitWidth(c: *Context, qt: clang.QualType) !u32 {...@@ -4341,7 +4341,7 @@ fn qualTypeIntBitWidth(c: *Context, qt: clang.QualType) !u32 {
43414341
4342 switch (ty.getTypeClass()) {4342 switch (ty.getTypeClass()) {
4343 .Builtin => {4343 .Builtin => {
4344 const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);4344 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(ty));
43454345
4346 switch (builtin_ty.getKind()) {4346 switch (builtin_ty.getKind()) {
4347 .Char_U,4347 .Char_U,
...@@ -4358,9 +4358,9 @@ fn qualTypeIntBitWidth(c: *Context, qt: clang.QualType) !u32 {...@@ -4358,9 +4358,9 @@ fn qualTypeIntBitWidth(c: *Context, qt: clang.QualType) !u32 {
4358 unreachable;4358 unreachable;
4359 },4359 },
4360 .Typedef => {4360 .Typedef => {
4361 const typedef_ty = @ptrCast(*const clang.TypedefType, ty);4361 const typedef_ty = @as(*const clang.TypedefType, @ptrCast(ty));
4362 const typedef_decl = typedef_ty.getDecl();4362 const typedef_decl = typedef_ty.getDecl();
4363 const type_name = try c.str(@ptrCast(*const clang.NamedDecl, typedef_decl).getName_bytes_begin());4363 const type_name = try c.str(@as(*const clang.NamedDecl, @ptrCast(typedef_decl)).getName_bytes_begin());
43644364
4365 if (mem.eql(u8, type_name, "uint8_t") or mem.eql(u8, type_name, "int8_t")) {4365 if (mem.eql(u8, type_name, "uint8_t") or mem.eql(u8, type_name, "int8_t")) {
4366 return 8;4366 return 8;
...@@ -4396,12 +4396,12 @@ fn getExprQualType(c: *Context, expr: *const clang.Expr) clang.QualType {...@@ -4396,12 +4396,12 @@ fn getExprQualType(c: *Context, expr: *const clang.Expr) clang.QualType {
4396 blk: {4396 blk: {
4397 // If this is a C `char *`, turn it into a `const char *`4397 // If this is a C `char *`, turn it into a `const char *`
4398 if (expr.getStmtClass() != .ImplicitCastExprClass) break :blk;4398 if (expr.getStmtClass() != .ImplicitCastExprClass) break :blk;
4399 const cast_expr = @ptrCast(*const clang.ImplicitCastExpr, expr);4399 const cast_expr = @as(*const clang.ImplicitCastExpr, @ptrCast(expr));
4400 if (cast_expr.getCastKind() != .ArrayToPointerDecay) break :blk;4400 if (cast_expr.getCastKind() != .ArrayToPointerDecay) break :blk;
4401 const sub_expr = cast_expr.getSubExpr();4401 const sub_expr = cast_expr.getSubExpr();
4402 if (sub_expr.getStmtClass() != .StringLiteralClass) break :blk;4402 if (sub_expr.getStmtClass() != .StringLiteralClass) break :blk;
4403 const array_qt = sub_expr.getType();4403 const array_qt = sub_expr.getType();
4404 const array_type = @ptrCast(*const clang.ArrayType, array_qt.getTypePtr());4404 const array_type = @as(*const clang.ArrayType, @ptrCast(array_qt.getTypePtr()));
4405 var pointee_qt = array_type.getElementType();4405 var pointee_qt = array_type.getElementType();
4406 pointee_qt.addConst();4406 pointee_qt.addConst();
4407 return c.clang_context.getPointerType(pointee_qt);4407 return c.clang_context.getPointerType(pointee_qt);
...@@ -4412,11 +4412,11 @@ fn getExprQualType(c: *Context, expr: *const clang.Expr) clang.QualType {...@@ -4412,11 +4412,11 @@ fn getExprQualType(c: *Context, expr: *const clang.Expr) clang.QualType {
4412fn typeIsOpaque(c: *Context, ty: *const clang.Type, loc: clang.SourceLocation) bool {4412fn typeIsOpaque(c: *Context, ty: *const clang.Type, loc: clang.SourceLocation) bool {
4413 switch (ty.getTypeClass()) {4413 switch (ty.getTypeClass()) {
4414 .Builtin => {4414 .Builtin => {
4415 const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);4415 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(ty));
4416 return builtin_ty.getKind() == .Void;4416 return builtin_ty.getKind() == .Void;
4417 },4417 },
4418 .Record => {4418 .Record => {
4419 const record_ty = @ptrCast(*const clang.RecordType, ty);4419 const record_ty = @as(*const clang.RecordType, @ptrCast(ty));
4420 const record_decl = record_ty.getDecl();4420 const record_decl = record_ty.getDecl();
4421 const record_def = record_decl.getDefinition() orelse4421 const record_def = record_decl.getDefinition() orelse
4422 return true;4422 return true;
...@@ -4432,12 +4432,12 @@ fn typeIsOpaque(c: *Context, ty: *const clang.Type, loc: clang.SourceLocation) b...@@ -4432,12 +4432,12 @@ fn typeIsOpaque(c: *Context, ty: *const clang.Type, loc: clang.SourceLocation) b
4432 return false;4432 return false;
4433 },4433 },
4434 .Elaborated => {4434 .Elaborated => {
4435 const elaborated_ty = @ptrCast(*const clang.ElaboratedType, ty);4435 const elaborated_ty = @as(*const clang.ElaboratedType, @ptrCast(ty));
4436 const qt = elaborated_ty.getNamedType();4436 const qt = elaborated_ty.getNamedType();
4437 return typeIsOpaque(c, qt.getTypePtr(), loc);4437 return typeIsOpaque(c, qt.getTypePtr(), loc);
4438 },4438 },
4439 .Typedef => {4439 .Typedef => {
4440 const typedef_ty = @ptrCast(*const clang.TypedefType, ty);4440 const typedef_ty = @as(*const clang.TypedefType, @ptrCast(ty));
4441 const typedef_decl = typedef_ty.getDecl();4441 const typedef_decl = typedef_ty.getDecl();
4442 const underlying_type = typedef_decl.getUnderlyingType();4442 const underlying_type = typedef_decl.getUnderlyingType();
4443 return typeIsOpaque(c, underlying_type.getTypePtr(), loc);4443 return typeIsOpaque(c, underlying_type.getTypePtr(), loc);
...@@ -4459,7 +4459,7 @@ fn qualTypeIsCharStar(qt: clang.QualType) bool {...@@ -4459,7 +4459,7 @@ fn qualTypeIsCharStar(qt: clang.QualType) bool {
4459fn cIsUnqualifiedChar(qt: clang.QualType) bool {4459fn cIsUnqualifiedChar(qt: clang.QualType) bool {
4460 const c_type = qualTypeCanon(qt);4460 const c_type = qualTypeCanon(qt);
4461 if (c_type.getTypeClass() != .Builtin) return false;4461 if (c_type.getTypeClass() != .Builtin) return false;
4462 const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);4462 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(c_type));
4463 return switch (builtin_ty.getKind()) {4463 return switch (builtin_ty.getKind()) {
4464 .Char_S, .Char_U => true,4464 .Char_S, .Char_U => true,
4465 else => false,4465 else => false,
...@@ -4473,7 +4473,7 @@ fn cIsInteger(qt: clang.QualType) bool {...@@ -4473,7 +4473,7 @@ fn cIsInteger(qt: clang.QualType) bool {
4473fn cIsUnsignedInteger(qt: clang.QualType) bool {4473fn cIsUnsignedInteger(qt: clang.QualType) bool {
4474 const c_type = qualTypeCanon(qt);4474 const c_type = qualTypeCanon(qt);
4475 if (c_type.getTypeClass() != .Builtin) return false;4475 if (c_type.getTypeClass() != .Builtin) return false;
4476 const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);4476 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(c_type));
4477 return switch (builtin_ty.getKind()) {4477 return switch (builtin_ty.getKind()) {
4478 .Char_U,4478 .Char_U,
4479 .UChar,4479 .UChar,
...@@ -4492,7 +4492,7 @@ fn cIsUnsignedInteger(qt: clang.QualType) bool {...@@ -4492,7 +4492,7 @@ fn cIsUnsignedInteger(qt: clang.QualType) bool {
4492fn cIntTypeToIndex(qt: clang.QualType) u8 {4492fn cIntTypeToIndex(qt: clang.QualType) u8 {
4493 const c_type = qualTypeCanon(qt);4493 const c_type = qualTypeCanon(qt);
4494 assert(c_type.getTypeClass() == .Builtin);4494 assert(c_type.getTypeClass() == .Builtin);
4495 const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);4495 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(c_type));
4496 return switch (builtin_ty.getKind()) {4496 return switch (builtin_ty.getKind()) {
4497 .Bool, .Char_U, .Char_S, .UChar, .SChar, .Char8 => 1,4497 .Bool, .Char_U, .Char_S, .UChar, .SChar, .Char8 => 1,
4498 .WChar_U, .WChar_S => 2,4498 .WChar_U, .WChar_S => 2,
...@@ -4513,9 +4513,9 @@ fn cIntTypeCmp(a: clang.QualType, b: clang.QualType) math.Order {...@@ -4513,9 +4513,9 @@ fn cIntTypeCmp(a: clang.QualType, b: clang.QualType) math.Order {
45134513
4514/// Checks if expr is an integer literal >= 04514/// Checks if expr is an integer literal >= 0
4515fn cIsNonNegativeIntLiteral(c: *Context, expr: *const clang.Expr) bool {4515fn cIsNonNegativeIntLiteral(c: *Context, expr: *const clang.Expr) bool {
4516 if (@ptrCast(*const clang.Stmt, expr).getStmtClass() == .IntegerLiteralClass) {4516 if (@as(*const clang.Stmt, @ptrCast(expr)).getStmtClass() == .IntegerLiteralClass) {
4517 var signum: c_int = undefined;4517 var signum: c_int = undefined;
4518 if (!(@ptrCast(*const clang.IntegerLiteral, expr).getSignum(&signum, c.clang_context))) {4518 if (!(@as(*const clang.IntegerLiteral, @ptrCast(expr)).getSignum(&signum, c.clang_context))) {
4519 return false;4519 return false;
4520 }4520 }
4521 return signum >= 0;4521 return signum >= 0;
...@@ -4526,7 +4526,7 @@ fn cIsNonNegativeIntLiteral(c: *Context, expr: *const clang.Expr) bool {...@@ -4526,7 +4526,7 @@ fn cIsNonNegativeIntLiteral(c: *Context, expr: *const clang.Expr) bool {
4526fn cIsSignedInteger(qt: clang.QualType) bool {4526fn cIsSignedInteger(qt: clang.QualType) bool {
4527 const c_type = qualTypeCanon(qt);4527 const c_type = qualTypeCanon(qt);
4528 if (c_type.getTypeClass() != .Builtin) return false;4528 if (c_type.getTypeClass() != .Builtin) return false;
4529 const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);4529 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(c_type));
4530 return switch (builtin_ty.getKind()) {4530 return switch (builtin_ty.getKind()) {
4531 .SChar,4531 .SChar,
4532 .Short,4532 .Short,
...@@ -4543,14 +4543,14 @@ fn cIsSignedInteger(qt: clang.QualType) bool {...@@ -4543,14 +4543,14 @@ fn cIsSignedInteger(qt: clang.QualType) bool {
4543fn cIsNativeInt(qt: clang.QualType) bool {4543fn cIsNativeInt(qt: clang.QualType) bool {
4544 const c_type = qualTypeCanon(qt);4544 const c_type = qualTypeCanon(qt);
4545 if (c_type.getTypeClass() != .Builtin) return false;4545 if (c_type.getTypeClass() != .Builtin) return false;
4546 const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);4546 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(c_type));
4547 return builtin_ty.getKind() == .Int;4547 return builtin_ty.getKind() == .Int;
4548}4548}
45494549
4550fn cIsFloating(qt: clang.QualType) bool {4550fn cIsFloating(qt: clang.QualType) bool {
4551 const c_type = qualTypeCanon(qt);4551 const c_type = qualTypeCanon(qt);
4552 if (c_type.getTypeClass() != .Builtin) return false;4552 if (c_type.getTypeClass() != .Builtin) return false;
4553 const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);4553 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(c_type));
4554 return switch (builtin_ty.getKind()) {4554 return switch (builtin_ty.getKind()) {
4555 .Float,4555 .Float,
4556 .Double,4556 .Double,
...@@ -4564,7 +4564,7 @@ fn cIsFloating(qt: clang.QualType) bool {...@@ -4564,7 +4564,7 @@ fn cIsFloating(qt: clang.QualType) bool {
4564fn cIsLongLongInteger(qt: clang.QualType) bool {4564fn cIsLongLongInteger(qt: clang.QualType) bool {
4565 const c_type = qualTypeCanon(qt);4565 const c_type = qualTypeCanon(qt);
4566 if (c_type.getTypeClass() != .Builtin) return false;4566 if (c_type.getTypeClass() != .Builtin) return false;
4567 const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);4567 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(c_type));
4568 return switch (builtin_ty.getKind()) {4568 return switch (builtin_ty.getKind()) {
4569 .LongLong, .ULongLong, .Int128, .UInt128 => true,4569 .LongLong, .ULongLong, .Int128, .UInt128 => true,
4570 else => false,4570 else => false,
...@@ -4681,8 +4681,8 @@ fn transCreateNodeAPInt(c: *Context, int: *const clang.APSInt) !Node {...@@ -4681,8 +4681,8 @@ fn transCreateNodeAPInt(c: *Context, int: *const clang.APSInt) !Node {
4681 limb_i += 2;4681 limb_i += 2;
4682 data_i += 1;4682 data_i += 1;
4683 }) {4683 }) {
4684 limbs[limb_i] = @truncate(u32, data[data_i]);4684 limbs[limb_i] = @as(u32, @truncate(data[data_i]));
4685 limbs[limb_i + 1] = @truncate(u32, data[data_i] >> 32);4685 limbs[limb_i + 1] = @as(u32, @truncate(data[data_i] >> 32));
4686 }4686 }
4687 },4687 },
4688 else => @compileError("unimplemented"),4688 else => @compileError("unimplemented"),
...@@ -4772,7 +4772,7 @@ fn transCreateNodeShiftOp(...@@ -4772,7 +4772,7 @@ fn transCreateNodeShiftOp(
4772fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clang.SourceLocation) TypeError!Node {4772fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clang.SourceLocation) TypeError!Node {
4773 switch (ty.getTypeClass()) {4773 switch (ty.getTypeClass()) {
4774 .Builtin => {4774 .Builtin => {
4775 const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);4775 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(ty));
4776 return Tag.type.create(c.arena, switch (builtin_ty.getKind()) {4776 return Tag.type.create(c.arena, switch (builtin_ty.getKind()) {
4777 .Void => "anyopaque",4777 .Void => "anyopaque",
4778 .Bool => "bool",4778 .Bool => "bool",
...@@ -4797,17 +4797,17 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan...@@ -4797,17 +4797,17 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
4797 });4797 });
4798 },4798 },
4799 .FunctionProto => {4799 .FunctionProto => {
4800 const fn_proto_ty = @ptrCast(*const clang.FunctionProtoType, ty);4800 const fn_proto_ty = @as(*const clang.FunctionProtoType, @ptrCast(ty));
4801 const fn_proto = try transFnProto(c, null, fn_proto_ty, source_loc, null, false);4801 const fn_proto = try transFnProto(c, null, fn_proto_ty, source_loc, null, false);
4802 return Node.initPayload(&fn_proto.base);4802 return Node.initPayload(&fn_proto.base);
4803 },4803 },
4804 .FunctionNoProto => {4804 .FunctionNoProto => {
4805 const fn_no_proto_ty = @ptrCast(*const clang.FunctionType, ty);4805 const fn_no_proto_ty = @as(*const clang.FunctionType, @ptrCast(ty));
4806 const fn_proto = try transFnNoProto(c, fn_no_proto_ty, source_loc, null, false);4806 const fn_proto = try transFnNoProto(c, fn_no_proto_ty, source_loc, null, false);
4807 return Node.initPayload(&fn_proto.base);4807 return Node.initPayload(&fn_proto.base);
4808 },4808 },
4809 .Paren => {4809 .Paren => {
4810 const paren_ty = @ptrCast(*const clang.ParenType, ty);4810 const paren_ty = @as(*const clang.ParenType, @ptrCast(ty));
4811 return transQualType(c, scope, paren_ty.getInnerType(), source_loc);4811 return transQualType(c, scope, paren_ty.getInnerType(), source_loc);
4812 },4812 },
4813 .Pointer => {4813 .Pointer => {
...@@ -4832,7 +4832,7 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan...@@ -4832,7 +4832,7 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
4832 return Tag.c_pointer.create(c.arena, ptr_info);4832 return Tag.c_pointer.create(c.arena, ptr_info);
4833 },4833 },
4834 .ConstantArray => {4834 .ConstantArray => {
4835 const const_arr_ty = @ptrCast(*const clang.ConstantArrayType, ty);4835 const const_arr_ty = @as(*const clang.ConstantArrayType, @ptrCast(ty));
48364836
4837 const size_ap_int = const_arr_ty.getSize();4837 const size_ap_int = const_arr_ty.getSize();
4838 const size = size_ap_int.getLimitedValue(usize);4838 const size = size_ap_int.getLimitedValue(usize);
...@@ -4841,7 +4841,7 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan...@@ -4841,7 +4841,7 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
4841 return Tag.array_type.create(c.arena, .{ .len = size, .elem_type = elem_type });4841 return Tag.array_type.create(c.arena, .{ .len = size, .elem_type = elem_type });
4842 },4842 },
4843 .IncompleteArray => {4843 .IncompleteArray => {
4844 const incomplete_array_ty = @ptrCast(*const clang.IncompleteArrayType, ty);4844 const incomplete_array_ty = @as(*const clang.IncompleteArrayType, @ptrCast(ty));
48454845
4846 const child_qt = incomplete_array_ty.getElementType();4846 const child_qt = incomplete_array_ty.getElementType();
4847 const is_const = child_qt.isConstQualified();4847 const is_const = child_qt.isConstQualified();
...@@ -4851,11 +4851,11 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan...@@ -4851,11 +4851,11 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
4851 return Tag.c_pointer.create(c.arena, .{ .is_const = is_const, .is_volatile = is_volatile, .elem_type = elem_type });4851 return Tag.c_pointer.create(c.arena, .{ .is_const = is_const, .is_volatile = is_volatile, .elem_type = elem_type });
4852 },4852 },
4853 .Typedef => {4853 .Typedef => {
4854 const typedef_ty = @ptrCast(*const clang.TypedefType, ty);4854 const typedef_ty = @as(*const clang.TypedefType, @ptrCast(ty));
48554855
4856 const typedef_decl = typedef_ty.getDecl();4856 const typedef_decl = typedef_ty.getDecl();
4857 var trans_scope = scope;4857 var trans_scope = scope;
4858 if (@ptrCast(*const clang.Decl, typedef_decl).castToNamedDecl()) |named_decl| {4858 if (@as(*const clang.Decl, @ptrCast(typedef_decl)).castToNamedDecl()) |named_decl| {
4859 const decl_name = try c.str(named_decl.getName_bytes_begin());4859 const decl_name = try c.str(named_decl.getName_bytes_begin());
4860 if (c.global_names.get(decl_name)) |_| trans_scope = &c.global_scope.base;4860 if (c.global_names.get(decl_name)) |_| trans_scope = &c.global_scope.base;
4861 if (builtin_typedef_map.get(decl_name)) |builtin| return Tag.type.create(c.arena, builtin);4861 if (builtin_typedef_map.get(decl_name)) |builtin| return Tag.type.create(c.arena, builtin);
...@@ -4865,11 +4865,11 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan...@@ -4865,11 +4865,11 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
4865 return Tag.identifier.create(c.arena, name);4865 return Tag.identifier.create(c.arena, name);
4866 },4866 },
4867 .Record => {4867 .Record => {
4868 const record_ty = @ptrCast(*const clang.RecordType, ty);4868 const record_ty = @as(*const clang.RecordType, @ptrCast(ty));
48694869
4870 const record_decl = record_ty.getDecl();4870 const record_decl = record_ty.getDecl();
4871 var trans_scope = scope;4871 var trans_scope = scope;
4872 if (@ptrCast(*const clang.Decl, record_decl).castToNamedDecl()) |named_decl| {4872 if (@as(*const clang.Decl, @ptrCast(record_decl)).castToNamedDecl()) |named_decl| {
4873 const decl_name = try c.str(named_decl.getName_bytes_begin());4873 const decl_name = try c.str(named_decl.getName_bytes_begin());
4874 if (c.global_names.get(decl_name)) |_| trans_scope = &c.global_scope.base;4874 if (c.global_names.get(decl_name)) |_| trans_scope = &c.global_scope.base;
4875 }4875 }
...@@ -4878,11 +4878,11 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan...@@ -4878,11 +4878,11 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
4878 return Tag.identifier.create(c.arena, name);4878 return Tag.identifier.create(c.arena, name);
4879 },4879 },
4880 .Enum => {4880 .Enum => {
4881 const enum_ty = @ptrCast(*const clang.EnumType, ty);4881 const enum_ty = @as(*const clang.EnumType, @ptrCast(ty));
48824882
4883 const enum_decl = enum_ty.getDecl();4883 const enum_decl = enum_ty.getDecl();
4884 var trans_scope = scope;4884 var trans_scope = scope;
4885 if (@ptrCast(*const clang.Decl, enum_decl).castToNamedDecl()) |named_decl| {4885 if (@as(*const clang.Decl, @ptrCast(enum_decl)).castToNamedDecl()) |named_decl| {
4886 const decl_name = try c.str(named_decl.getName_bytes_begin());4886 const decl_name = try c.str(named_decl.getName_bytes_begin());
4887 if (c.global_names.get(decl_name)) |_| trans_scope = &c.global_scope.base;4887 if (c.global_names.get(decl_name)) |_| trans_scope = &c.global_scope.base;
4888 }4888 }
...@@ -4891,27 +4891,27 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan...@@ -4891,27 +4891,27 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
4891 return Tag.identifier.create(c.arena, name);4891 return Tag.identifier.create(c.arena, name);
4892 },4892 },
4893 .Elaborated => {4893 .Elaborated => {
4894 const elaborated_ty = @ptrCast(*const clang.ElaboratedType, ty);4894 const elaborated_ty = @as(*const clang.ElaboratedType, @ptrCast(ty));
4895 return transQualType(c, scope, elaborated_ty.getNamedType(), source_loc);4895 return transQualType(c, scope, elaborated_ty.getNamedType(), source_loc);
4896 },4896 },
4897 .Decayed => {4897 .Decayed => {
4898 const decayed_ty = @ptrCast(*const clang.DecayedType, ty);4898 const decayed_ty = @as(*const clang.DecayedType, @ptrCast(ty));
4899 return transQualType(c, scope, decayed_ty.getDecayedType(), source_loc);4899 return transQualType(c, scope, decayed_ty.getDecayedType(), source_loc);
4900 },4900 },
4901 .Attributed => {4901 .Attributed => {
4902 const attributed_ty = @ptrCast(*const clang.AttributedType, ty);4902 const attributed_ty = @as(*const clang.AttributedType, @ptrCast(ty));
4903 return transQualType(c, scope, attributed_ty.getEquivalentType(), source_loc);4903 return transQualType(c, scope, attributed_ty.getEquivalentType(), source_loc);
4904 },4904 },
4905 .MacroQualified => {4905 .MacroQualified => {
4906 const macroqualified_ty = @ptrCast(*const clang.MacroQualifiedType, ty);4906 const macroqualified_ty = @as(*const clang.MacroQualifiedType, @ptrCast(ty));
4907 return transQualType(c, scope, macroqualified_ty.getModifiedType(), source_loc);4907 return transQualType(c, scope, macroqualified_ty.getModifiedType(), source_loc);
4908 },4908 },
4909 .TypeOf => {4909 .TypeOf => {
4910 const typeof_ty = @ptrCast(*const clang.TypeOfType, ty);4910 const typeof_ty = @as(*const clang.TypeOfType, @ptrCast(ty));
4911 return transQualType(c, scope, typeof_ty.getUnmodifiedType(), source_loc);4911 return transQualType(c, scope, typeof_ty.getUnmodifiedType(), source_loc);
4912 },4912 },
4913 .TypeOfExpr => {4913 .TypeOfExpr => {
4914 const typeofexpr_ty = @ptrCast(*const clang.TypeOfExprType, ty);4914 const typeofexpr_ty = @as(*const clang.TypeOfExprType, @ptrCast(ty));
4915 const underlying_expr = transExpr(c, scope, typeofexpr_ty.getUnderlyingExpr(), .used) catch |err| switch (err) {4915 const underlying_expr = transExpr(c, scope, typeofexpr_ty.getUnderlyingExpr(), .used) catch |err| switch (err) {
4916 error.UnsupportedTranslation => {4916 error.UnsupportedTranslation => {
4917 return fail(c, error.UnsupportedType, source_loc, "unsupported underlying expression for TypeOfExpr", .{});4917 return fail(c, error.UnsupportedType, source_loc, "unsupported underlying expression for TypeOfExpr", .{});
...@@ -4921,7 +4921,7 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan...@@ -4921,7 +4921,7 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
4921 return Tag.typeof.create(c.arena, underlying_expr);4921 return Tag.typeof.create(c.arena, underlying_expr);
4922 },4922 },
4923 .Vector => {4923 .Vector => {
4924 const vector_ty = @ptrCast(*const clang.VectorType, ty);4924 const vector_ty = @as(*const clang.VectorType, @ptrCast(ty));
4925 const num_elements = vector_ty.getNumElements();4925 const num_elements = vector_ty.getNumElements();
4926 const element_qt = vector_ty.getElementType();4926 const element_qt = vector_ty.getElementType();
4927 return Tag.vector.create(c.arena, .{4927 return Tag.vector.create(c.arena, .{
...@@ -4944,14 +4944,14 @@ fn qualTypeWasDemotedToOpaque(c: *Context, qt: clang.QualType) bool {...@@ -4944,14 +4944,14 @@ fn qualTypeWasDemotedToOpaque(c: *Context, qt: clang.QualType) bool {
4944 const ty = qt.getTypePtr();4944 const ty = qt.getTypePtr();
4945 switch (qt.getTypeClass()) {4945 switch (qt.getTypeClass()) {
4946 .Typedef => {4946 .Typedef => {
4947 const typedef_ty = @ptrCast(*const clang.TypedefType, ty);4947 const typedef_ty = @as(*const clang.TypedefType, @ptrCast(ty));
49484948
4949 const typedef_decl = typedef_ty.getDecl();4949 const typedef_decl = typedef_ty.getDecl();
4950 const underlying_type = typedef_decl.getUnderlyingType();4950 const underlying_type = typedef_decl.getUnderlyingType();
4951 return qualTypeWasDemotedToOpaque(c, underlying_type);4951 return qualTypeWasDemotedToOpaque(c, underlying_type);
4952 },4952 },
4953 .Record => {4953 .Record => {
4954 const record_ty = @ptrCast(*const clang.RecordType, ty);4954 const record_ty = @as(*const clang.RecordType, @ptrCast(ty));
49554955
4956 const record_decl = record_ty.getDecl();4956 const record_decl = record_ty.getDecl();
4957 const canonical = @intFromPtr(record_decl.getCanonicalDecl());4957 const canonical = @intFromPtr(record_decl.getCanonicalDecl());
...@@ -4967,26 +4967,26 @@ fn qualTypeWasDemotedToOpaque(c: *Context, qt: clang.QualType) bool {...@@ -4967,26 +4967,26 @@ fn qualTypeWasDemotedToOpaque(c: *Context, qt: clang.QualType) bool {
4967 return false;4967 return false;
4968 },4968 },
4969 .Enum => {4969 .Enum => {
4970 const enum_ty = @ptrCast(*const clang.EnumType, ty);4970 const enum_ty = @as(*const clang.EnumType, @ptrCast(ty));
49714971
4972 const enum_decl = enum_ty.getDecl();4972 const enum_decl = enum_ty.getDecl();
4973 const canonical = @intFromPtr(enum_decl.getCanonicalDecl());4973 const canonical = @intFromPtr(enum_decl.getCanonicalDecl());
4974 return c.opaque_demotes.contains(canonical);4974 return c.opaque_demotes.contains(canonical);
4975 },4975 },
4976 .Elaborated => {4976 .Elaborated => {
4977 const elaborated_ty = @ptrCast(*const clang.ElaboratedType, ty);4977 const elaborated_ty = @as(*const clang.ElaboratedType, @ptrCast(ty));
4978 return qualTypeWasDemotedToOpaque(c, elaborated_ty.getNamedType());4978 return qualTypeWasDemotedToOpaque(c, elaborated_ty.getNamedType());
4979 },4979 },
4980 .Decayed => {4980 .Decayed => {
4981 const decayed_ty = @ptrCast(*const clang.DecayedType, ty);4981 const decayed_ty = @as(*const clang.DecayedType, @ptrCast(ty));
4982 return qualTypeWasDemotedToOpaque(c, decayed_ty.getDecayedType());4982 return qualTypeWasDemotedToOpaque(c, decayed_ty.getDecayedType());
4983 },4983 },
4984 .Attributed => {4984 .Attributed => {
4985 const attributed_ty = @ptrCast(*const clang.AttributedType, ty);4985 const attributed_ty = @as(*const clang.AttributedType, @ptrCast(ty));
4986 return qualTypeWasDemotedToOpaque(c, attributed_ty.getEquivalentType());4986 return qualTypeWasDemotedToOpaque(c, attributed_ty.getEquivalentType());
4987 },4987 },
4988 .MacroQualified => {4988 .MacroQualified => {
4989 const macroqualified_ty = @ptrCast(*const clang.MacroQualifiedType, ty);4989 const macroqualified_ty = @as(*const clang.MacroQualifiedType, @ptrCast(ty));
4990 return qualTypeWasDemotedToOpaque(c, macroqualified_ty.getModifiedType());4990 return qualTypeWasDemotedToOpaque(c, macroqualified_ty.getModifiedType());
4991 },4991 },
4992 else => return false,4992 else => return false,
...@@ -4997,28 +4997,28 @@ fn isAnyopaque(qt: clang.QualType) bool {...@@ -4997,28 +4997,28 @@ fn isAnyopaque(qt: clang.QualType) bool {
4997 const ty = qt.getTypePtr();4997 const ty = qt.getTypePtr();
4998 switch (ty.getTypeClass()) {4998 switch (ty.getTypeClass()) {
4999 .Builtin => {4999 .Builtin => {
5000 const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);5000 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(ty));
5001 return builtin_ty.getKind() == .Void;5001 return builtin_ty.getKind() == .Void;
5002 },5002 },
5003 .Typedef => {5003 .Typedef => {
5004 const typedef_ty = @ptrCast(*const clang.TypedefType, ty);5004 const typedef_ty = @as(*const clang.TypedefType, @ptrCast(ty));
5005 const typedef_decl = typedef_ty.getDecl();5005 const typedef_decl = typedef_ty.getDecl();
5006 return isAnyopaque(typedef_decl.getUnderlyingType());5006 return isAnyopaque(typedef_decl.getUnderlyingType());
5007 },5007 },
5008 .Elaborated => {5008 .Elaborated => {
5009 const elaborated_ty = @ptrCast(*const clang.ElaboratedType, ty);5009 const elaborated_ty = @as(*const clang.ElaboratedType, @ptrCast(ty));
5010 return isAnyopaque(elaborated_ty.getNamedType().getCanonicalType());5010 return isAnyopaque(elaborated_ty.getNamedType().getCanonicalType());
5011 },5011 },
5012 .Decayed => {5012 .Decayed => {
5013 const decayed_ty = @ptrCast(*const clang.DecayedType, ty);5013 const decayed_ty = @as(*const clang.DecayedType, @ptrCast(ty));
5014 return isAnyopaque(decayed_ty.getDecayedType().getCanonicalType());5014 return isAnyopaque(decayed_ty.getDecayedType().getCanonicalType());
5015 },5015 },
5016 .Attributed => {5016 .Attributed => {
5017 const attributed_ty = @ptrCast(*const clang.AttributedType, ty);5017 const attributed_ty = @as(*const clang.AttributedType, @ptrCast(ty));
5018 return isAnyopaque(attributed_ty.getEquivalentType().getCanonicalType());5018 return isAnyopaque(attributed_ty.getEquivalentType().getCanonicalType());
5019 },5019 },
5020 .MacroQualified => {5020 .MacroQualified => {
5021 const macroqualified_ty = @ptrCast(*const clang.MacroQualifiedType, ty);5021 const macroqualified_ty = @as(*const clang.MacroQualifiedType, @ptrCast(ty));
5022 return isAnyopaque(macroqualified_ty.getModifiedType().getCanonicalType());5022 return isAnyopaque(macroqualified_ty.getModifiedType().getCanonicalType());
5023 },5023 },
5024 else => return false,5024 else => return false,
...@@ -5066,7 +5066,7 @@ fn transFnProto(...@@ -5066,7 +5066,7 @@ fn transFnProto(
5066 fn_decl_context: ?FnDeclContext,5066 fn_decl_context: ?FnDeclContext,
5067 is_pub: bool,5067 is_pub: bool,
5068) !*ast.Payload.Func {5068) !*ast.Payload.Func {
5069 const fn_ty = @ptrCast(*const clang.FunctionType, fn_proto_ty);5069 const fn_ty = @as(*const clang.FunctionType, @ptrCast(fn_proto_ty));
5070 const cc = try transCC(c, fn_ty, source_loc);5070 const cc = try transCC(c, fn_ty, source_loc);
5071 const is_var_args = fn_proto_ty.isVariadic();5071 const is_var_args = fn_proto_ty.isVariadic();
5072 return finishTransFnProto(c, fn_decl, fn_proto_ty, fn_ty, source_loc, fn_decl_context, is_var_args, cc, is_pub);5072 return finishTransFnProto(c, fn_decl, fn_proto_ty, fn_ty, source_loc, fn_decl_context, is_var_args, cc, is_pub);
...@@ -5108,14 +5108,14 @@ fn finishTransFnProto(...@@ -5108,14 +5108,14 @@ fn finishTransFnProto(
51085108
5109 var i: usize = 0;5109 var i: usize = 0;
5110 while (i < param_count) : (i += 1) {5110 while (i < param_count) : (i += 1) {
5111 const param_qt = fn_proto_ty.?.getParamType(@intCast(c_uint, i));5111 const param_qt = fn_proto_ty.?.getParamType(@as(c_uint, @intCast(i)));
5112 const is_noalias = param_qt.isRestrictQualified();5112 const is_noalias = param_qt.isRestrictQualified();
51135113
5114 const param_name: ?[]const u8 =5114 const param_name: ?[]const u8 =
5115 if (fn_decl) |decl|5115 if (fn_decl) |decl|
5116 blk: {5116 blk: {
5117 const param = decl.getParamDecl(@intCast(c_uint, i));5117 const param = decl.getParamDecl(@as(c_uint, @intCast(i)));
5118 const param_name: []const u8 = try c.str(@ptrCast(*const clang.NamedDecl, param).getName_bytes_begin());5118 const param_name: []const u8 = try c.str(@as(*const clang.NamedDecl, @ptrCast(param)).getName_bytes_begin());
5119 if (param_name.len < 1)5119 if (param_name.len < 1)
5120 break :blk null;5120 break :blk null;
51215121
...@@ -5576,7 +5576,7 @@ fn transPreprocessorEntities(c: *Context, unit: *clang.ASTUnit) Error!void {...@@ -5576,7 +5576,7 @@ fn transPreprocessorEntities(c: *Context, unit: *clang.ASTUnit) Error!void {
5576 tok_list.items.len = 0;5576 tok_list.items.len = 0;
5577 switch (entity.getKind()) {5577 switch (entity.getKind()) {
5578 .MacroDefinitionKind => {5578 .MacroDefinitionKind => {
5579 const macro = @ptrCast(*clang.MacroDefinitionRecord, entity);5579 const macro = @as(*clang.MacroDefinitionRecord, @ptrCast(entity));
5580 const raw_name = macro.getName_getNameStart();5580 const raw_name = macro.getName_getNameStart();
5581 const begin_loc = macro.getSourceRange_getBegin();5581 const begin_loc = macro.getSourceRange_getBegin();
55825582
...@@ -6046,7 +6046,7 @@ fn escapeUnprintables(ctx: *Context, m: *MacroCtx) ![]const u8 {...@@ -6046,7 +6046,7 @@ fn escapeUnprintables(ctx: *Context, m: *MacroCtx) ![]const u8 {
6046 if (std.unicode.utf8ValidateSlice(zigified)) return zigified;6046 if (std.unicode.utf8ValidateSlice(zigified)) return zigified;
60476047
6048 const formatter = std.fmt.fmtSliceEscapeLower(zigified);6048 const formatter = std.fmt.fmtSliceEscapeLower(zigified);
6049 const encoded_size = @intCast(usize, std.fmt.count("{s}", .{formatter}));6049 const encoded_size = @as(usize, @intCast(std.fmt.count("{s}", .{formatter})));
6050 var output = try ctx.arena.alloc(u8, encoded_size);6050 var output = try ctx.arena.alloc(u8, encoded_size);
6051 return std.fmt.bufPrint(output, "{s}", .{formatter}) catch |err| switch (err) {6051 return std.fmt.bufPrint(output, "{s}", .{formatter}) catch |err| switch (err) {
6052 error.NoSpaceLeft => unreachable,6052 error.NoSpaceLeft => unreachable,
src/translate_c/ast.zig+8-8
...@@ -393,7 +393,7 @@ pub const Node = extern union {...@@ -393,7 +393,7 @@ pub const Node = extern union {
393393
394 pub fn tag(self: Node) Tag {394 pub fn tag(self: Node) Tag {
395 if (self.tag_if_small_enough < Tag.no_payload_count) {395 if (self.tag_if_small_enough < Tag.no_payload_count) {
396 return @enumFromInt(Tag, @intCast(std.meta.Tag(Tag), self.tag_if_small_enough));396 return @as(Tag, @enumFromInt(@as(std.meta.Tag(Tag), @intCast(self.tag_if_small_enough))));
397 } else {397 } else {
398 return self.ptr_otherwise.tag;398 return self.ptr_otherwise.tag;
399 }399 }
...@@ -778,7 +778,7 @@ pub fn render(gpa: Allocator, nodes: []const Node) !std.zig.Ast {...@@ -778,7 +778,7 @@ pub fn render(gpa: Allocator, nodes: []const Node) !std.zig.Ast {
778778
779 try ctx.tokens.append(gpa, .{779 try ctx.tokens.append(gpa, .{
780 .tag = .eof,780 .tag = .eof,
781 .start = @intCast(u32, ctx.buf.items.len),781 .start = @as(u32, @intCast(ctx.buf.items.len)),
782 });782 });
783783
784 return std.zig.Ast{784 return std.zig.Ast{
...@@ -808,10 +808,10 @@ const Context = struct {...@@ -808,10 +808,10 @@ const Context = struct {
808808
809 try c.tokens.append(c.gpa, .{809 try c.tokens.append(c.gpa, .{
810 .tag = tag,810 .tag = tag,
811 .start = @intCast(u32, start_index),811 .start = @as(u32, @intCast(start_index)),
812 });812 });
813813
814 return @intCast(u32, c.tokens.len - 1);814 return @as(u32, @intCast(c.tokens.len - 1));
815 }815 }
816816
817 fn addToken(c: *Context, tag: TokenTag, bytes: []const u8) Allocator.Error!TokenIndex {817 fn addToken(c: *Context, tag: TokenTag, bytes: []const u8) Allocator.Error!TokenIndex {
...@@ -827,13 +827,13 @@ const Context = struct {...@@ -827,13 +827,13 @@ const Context = struct {
827 fn listToSpan(c: *Context, list: []const NodeIndex) Allocator.Error!NodeSubRange {827 fn listToSpan(c: *Context, list: []const NodeIndex) Allocator.Error!NodeSubRange {
828 try c.extra_data.appendSlice(c.gpa, list);828 try c.extra_data.appendSlice(c.gpa, list);
829 return NodeSubRange{829 return NodeSubRange{
830 .start = @intCast(NodeIndex, c.extra_data.items.len - list.len),830 .start = @as(NodeIndex, @intCast(c.extra_data.items.len - list.len)),
831 .end = @intCast(NodeIndex, c.extra_data.items.len),831 .end = @as(NodeIndex, @intCast(c.extra_data.items.len)),
832 };832 };
833 }833 }
834834
835 fn addNode(c: *Context, elem: std.zig.Ast.Node) Allocator.Error!NodeIndex {835 fn addNode(c: *Context, elem: std.zig.Ast.Node) Allocator.Error!NodeIndex {
836 const result = @intCast(NodeIndex, c.nodes.len);836 const result = @as(NodeIndex, @intCast(c.nodes.len));
837 try c.nodes.append(c.gpa, elem);837 try c.nodes.append(c.gpa, elem);
838 return result;838 return result;
839 }839 }
...@@ -841,7 +841,7 @@ const Context = struct {...@@ -841,7 +841,7 @@ const Context = struct {
841 fn addExtra(c: *Context, extra: anytype) Allocator.Error!NodeIndex {841 fn addExtra(c: *Context, extra: anytype) Allocator.Error!NodeIndex {
842 const fields = std.meta.fields(@TypeOf(extra));842 const fields = std.meta.fields(@TypeOf(extra));
843 try c.extra_data.ensureUnusedCapacity(c.gpa, fields.len);843 try c.extra_data.ensureUnusedCapacity(c.gpa, fields.len);
844 const result = @intCast(u32, c.extra_data.items.len);844 const result = @as(u32, @intCast(c.extra_data.items.len));
845 inline for (fields) |field| {845 inline for (fields) |field| {
846 comptime std.debug.assert(field.type == NodeIndex);846 comptime std.debug.assert(field.type == NodeIndex);
847 c.extra_data.appendAssumeCapacity(@field(extra, field.name));847 c.extra_data.appendAssumeCapacity(@field(extra, field.name));
src/type.zig+14-14
...@@ -807,7 +807,7 @@ pub const Type = struct {...@@ -807,7 +807,7 @@ pub const Type = struct {
807 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {807 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
808 .ptr_type => |ptr_type| {808 .ptr_type => |ptr_type| {
809 if (ptr_type.flags.alignment.toByteUnitsOptional()) |a| {809 if (ptr_type.flags.alignment.toByteUnitsOptional()) |a| {
810 return @intCast(u32, a);810 return @as(u32, @intCast(a));
811 } else if (opt_sema) |sema| {811 } else if (opt_sema) |sema| {
812 const res = try ptr_type.child.toType().abiAlignmentAdvanced(mod, .{ .sema = sema });812 const res = try ptr_type.child.toType().abiAlignmentAdvanced(mod, .{ .sema = sema });
813 return res.scalar;813 return res.scalar;
...@@ -886,7 +886,7 @@ pub const Type = struct {...@@ -886,7 +886,7 @@ pub const Type = struct {
886 },886 },
887 .vector_type => |vector_type| {887 .vector_type => |vector_type| {
888 const bits_u64 = try bitSizeAdvanced(vector_type.child.toType(), mod, opt_sema);888 const bits_u64 = try bitSizeAdvanced(vector_type.child.toType(), mod, opt_sema);
889 const bits = @intCast(u32, bits_u64);889 const bits = @as(u32, @intCast(bits_u64));
890 const bytes = ((bits * vector_type.len) + 7) / 8;890 const bytes = ((bits * vector_type.len) + 7) / 8;
891 const alignment = std.math.ceilPowerOfTwoAssert(u32, bytes);891 const alignment = std.math.ceilPowerOfTwoAssert(u32, bytes);
892 return AbiAlignmentAdvanced{ .scalar = alignment };892 return AbiAlignmentAdvanced{ .scalar = alignment };
...@@ -901,7 +901,7 @@ pub const Type = struct {...@@ -901,7 +901,7 @@ pub const Type = struct {
901 // represents machine code; not a pointer901 // represents machine code; not a pointer
902 .func_type => |func_type| return AbiAlignmentAdvanced{902 .func_type => |func_type| return AbiAlignmentAdvanced{
903 .scalar = if (func_type.alignment.toByteUnitsOptional()) |a|903 .scalar = if (func_type.alignment.toByteUnitsOptional()) |a|
904 @intCast(u32, a)904 @as(u32, @intCast(a))
905 else905 else
906 target_util.defaultFunctionAlignment(target),906 target_util.defaultFunctionAlignment(target),
907 },907 },
...@@ -1015,7 +1015,7 @@ pub const Type = struct {...@@ -1015,7 +1015,7 @@ pub const Type = struct {
1015 else => |e| return e,1015 else => |e| return e,
1016 })) continue;1016 })) continue;
10171017
1018 const field_align = @intCast(u32, field.abi_align.toByteUnitsOptional() orelse1018 const field_align = @as(u32, @intCast(field.abi_align.toByteUnitsOptional() orelse
1019 switch (try field.ty.abiAlignmentAdvanced(mod, strat)) {1019 switch (try field.ty.abiAlignmentAdvanced(mod, strat)) {
1020 .scalar => |a| a,1020 .scalar => |a| a,
1021 .val => switch (strat) {1021 .val => switch (strat) {
...@@ -1026,7 +1026,7 @@ pub const Type = struct {...@@ -1026,7 +1026,7 @@ pub const Type = struct {
1026 .storage = .{ .lazy_align = ty.toIntern() },1026 .storage = .{ .lazy_align = ty.toIntern() },
1027 } })).toValue() },1027 } })).toValue() },
1028 },1028 },
1029 });1029 }));
1030 big_align = @max(big_align, field_align);1030 big_align = @max(big_align, field_align);
10311031
1032 // This logic is duplicated in Module.Struct.Field.alignment.1032 // This logic is duplicated in Module.Struct.Field.alignment.
...@@ -1221,7 +1221,7 @@ pub const Type = struct {...@@ -1221,7 +1221,7 @@ pub const Type = struct {
1221 else => |e| return e,1221 else => |e| return e,
1222 })) continue;1222 })) continue;
12231223
1224 const field_align = @intCast(u32, field.abi_align.toByteUnitsOptional() orelse1224 const field_align = @as(u32, @intCast(field.abi_align.toByteUnitsOptional() orelse
1225 switch (try field.ty.abiAlignmentAdvanced(mod, strat)) {1225 switch (try field.ty.abiAlignmentAdvanced(mod, strat)) {
1226 .scalar => |a| a,1226 .scalar => |a| a,
1227 .val => switch (strat) {1227 .val => switch (strat) {
...@@ -1232,7 +1232,7 @@ pub const Type = struct {...@@ -1232,7 +1232,7 @@ pub const Type = struct {
1232 .storage = .{ .lazy_align = ty.toIntern() },1232 .storage = .{ .lazy_align = ty.toIntern() },
1233 } })).toValue() },1233 } })).toValue() },
1234 },1234 },
1235 });1235 }));
1236 max_align = @max(max_align, field_align);1236 max_align = @max(max_align, field_align);
1237 }1237 }
1238 return AbiAlignmentAdvanced{ .scalar = max_align };1238 return AbiAlignmentAdvanced{ .scalar = max_align };
...@@ -1307,7 +1307,7 @@ pub const Type = struct {...@@ -1307,7 +1307,7 @@ pub const Type = struct {
1307 } })).toValue() },1307 } })).toValue() },
1308 };1308 };
1309 const elem_bits_u64 = try vector_type.child.toType().bitSizeAdvanced(mod, opt_sema);1309 const elem_bits_u64 = try vector_type.child.toType().bitSizeAdvanced(mod, opt_sema);
1310 const elem_bits = @intCast(u32, elem_bits_u64);1310 const elem_bits = @as(u32, @intCast(elem_bits_u64));
1311 const total_bits = elem_bits * vector_type.len;1311 const total_bits = elem_bits * vector_type.len;
1312 const total_bytes = (total_bits + 7) / 8;1312 const total_bytes = (total_bits + 7) / 8;
1313 const alignment = switch (try ty.abiAlignmentAdvanced(mod, strat)) {1313 const alignment = switch (try ty.abiAlignmentAdvanced(mod, strat)) {
...@@ -1573,12 +1573,12 @@ pub const Type = struct {...@@ -1573,12 +1573,12 @@ pub const Type = struct {
15731573
1574 fn intAbiSize(bits: u16, target: Target) u64 {1574 fn intAbiSize(bits: u16, target: Target) u64 {
1575 const alignment = intAbiAlignment(bits, target);1575 const alignment = intAbiAlignment(bits, target);
1576 return std.mem.alignForward(u64, @intCast(u16, (@as(u17, bits) + 7) / 8), alignment);1576 return std.mem.alignForward(u64, @as(u16, @intCast((@as(u17, bits) + 7) / 8)), alignment);
1577 }1577 }
15781578
1579 fn intAbiAlignment(bits: u16, target: Target) u32 {1579 fn intAbiAlignment(bits: u16, target: Target) u32 {
1580 return @min(1580 return @min(
1581 std.math.ceilPowerOfTwoPromote(u16, @intCast(u16, (@as(u17, bits) + 7) / 8)),1581 std.math.ceilPowerOfTwoPromote(u16, @as(u16, @intCast((@as(u17, bits) + 7) / 8))),
1582 target.maxIntAlignment(),1582 target.maxIntAlignment(),
1583 );1583 );
1584 }1584 }
...@@ -2166,7 +2166,7 @@ pub const Type = struct {...@@ -2166,7 +2166,7 @@ pub const Type = struct {
2166 pub fn vectorLen(ty: Type, mod: *const Module) u32 {2166 pub fn vectorLen(ty: Type, mod: *const Module) u32 {
2167 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {2167 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
2168 .vector_type => |vector_type| vector_type.len,2168 .vector_type => |vector_type| vector_type.len,
2169 .anon_struct_type => |tuple| @intCast(u32, tuple.types.len),2169 .anon_struct_type => |tuple| @as(u32, @intCast(tuple.types.len)),
2170 else => unreachable,2170 else => unreachable,
2171 };2171 };
2172 }2172 }
...@@ -3124,7 +3124,7 @@ pub const Type = struct {...@@ -3124,7 +3124,7 @@ pub const Type = struct {
3124 for (struct_obj.fields.values(), 0..) |f, i| {3124 for (struct_obj.fields.values(), 0..) |f, i| {
3125 if (!f.ty.hasRuntimeBits(mod)) continue;3125 if (!f.ty.hasRuntimeBits(mod)) continue;
31263126
3127 const field_bits = @intCast(u16, f.ty.bitSize(mod));3127 const field_bits = @as(u16, @intCast(f.ty.bitSize(mod)));
3128 if (i == field_index) {3128 if (i == field_index) {
3129 bit_offset = running_bits;3129 bit_offset = running_bits;
3130 elem_size_bits = field_bits;3130 elem_size_bits = field_bits;
...@@ -3385,8 +3385,8 @@ pub const Type = struct {...@@ -3385,8 +3385,8 @@ pub const Type = struct {
3385 pub fn smallestUnsignedBits(max: u64) u16 {3385 pub fn smallestUnsignedBits(max: u64) u16 {
3386 if (max == 0) return 0;3386 if (max == 0) return 0;
3387 const base = std.math.log2(max);3387 const base = std.math.log2(max);
3388 const upper = (@as(u64, 1) << @intCast(u6, base)) - 1;3388 const upper = (@as(u64, 1) << @as(u6, @intCast(base))) - 1;
3389 return @intCast(u16, base + @intFromBool(upper < max));3389 return @as(u16, @intCast(base + @intFromBool(upper < max)));
3390 }3390 }
33913391
3392 /// This is only used for comptime asserts. Bump this number when you make a change3392 /// This is only used for comptime asserts. Bump this number when you make a change
src/value.zig+88-88
...@@ -112,7 +112,7 @@ pub const Value = struct {...@@ -112,7 +112,7 @@ pub const Value = struct {
112 return self.castTag(T.base_tag);112 return self.castTag(T.base_tag);
113 }113 }
114 inline for (@typeInfo(Tag).Enum.fields) |field| {114 inline for (@typeInfo(Tag).Enum.fields) |field| {
115 const t = @enumFromInt(Tag, field.value);115 const t = @as(Tag, @enumFromInt(field.value));
116 if (self.legacy.ptr_otherwise.tag == t) {116 if (self.legacy.ptr_otherwise.tag == t) {
117 if (T == t.Type()) {117 if (T == t.Type()) {
118 return @fieldParentPtr(T, "base", self.legacy.ptr_otherwise);118 return @fieldParentPtr(T, "base", self.legacy.ptr_otherwise);
...@@ -203,8 +203,8 @@ pub const Value = struct {...@@ -203,8 +203,8 @@ pub const Value = struct {
203 .bytes => |bytes| try ip.getOrPutString(mod.gpa, bytes),203 .bytes => |bytes| try ip.getOrPutString(mod.gpa, bytes),
204 .elems => try arrayToIpString(val, ty.arrayLen(mod), mod),204 .elems => try arrayToIpString(val, ty.arrayLen(mod), mod),
205 .repeated_elem => |elem| {205 .repeated_elem => |elem| {
206 const byte = @intCast(u8, elem.toValue().toUnsignedInt(mod));206 const byte = @as(u8, @intCast(elem.toValue().toUnsignedInt(mod)));
207 const len = @intCast(usize, ty.arrayLen(mod));207 const len = @as(usize, @intCast(ty.arrayLen(mod)));
208 try ip.string_bytes.appendNTimes(mod.gpa, byte, len);208 try ip.string_bytes.appendNTimes(mod.gpa, byte, len);
209 return ip.getOrPutTrailingString(mod.gpa, len);209 return ip.getOrPutTrailingString(mod.gpa, len);
210 },210 },
...@@ -226,8 +226,8 @@ pub const Value = struct {...@@ -226,8 +226,8 @@ pub const Value = struct {
226 .bytes => |bytes| try allocator.dupe(u8, bytes),226 .bytes => |bytes| try allocator.dupe(u8, bytes),
227 .elems => try arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, mod),227 .elems => try arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, mod),
228 .repeated_elem => |elem| {228 .repeated_elem => |elem| {
229 const byte = @intCast(u8, elem.toValue().toUnsignedInt(mod));229 const byte = @as(u8, @intCast(elem.toValue().toUnsignedInt(mod)));
230 const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen(mod)));230 const result = try allocator.alloc(u8, @as(usize, @intCast(ty.arrayLen(mod))));
231 @memset(result, byte);231 @memset(result, byte);
232 return result;232 return result;
233 },233 },
...@@ -237,10 +237,10 @@ pub const Value = struct {...@@ -237,10 +237,10 @@ pub const Value = struct {
237 }237 }
238238
239 fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, mod: *Module) ![]u8 {239 fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, mod: *Module) ![]u8 {
240 const result = try allocator.alloc(u8, @intCast(usize, len));240 const result = try allocator.alloc(u8, @as(usize, @intCast(len)));
241 for (result, 0..) |*elem, i| {241 for (result, 0..) |*elem, i| {
242 const elem_val = try val.elemValue(mod, i);242 const elem_val = try val.elemValue(mod, i);
243 elem.* = @intCast(u8, elem_val.toUnsignedInt(mod));243 elem.* = @as(u8, @intCast(elem_val.toUnsignedInt(mod)));
244 }244 }
245 return result;245 return result;
246 }246 }
...@@ -248,7 +248,7 @@ pub const Value = struct {...@@ -248,7 +248,7 @@ pub const Value = struct {
248 fn arrayToIpString(val: Value, len_u64: u64, mod: *Module) !InternPool.NullTerminatedString {248 fn arrayToIpString(val: Value, len_u64: u64, mod: *Module) !InternPool.NullTerminatedString {
249 const gpa = mod.gpa;249 const gpa = mod.gpa;
250 const ip = &mod.intern_pool;250 const ip = &mod.intern_pool;
251 const len = @intCast(usize, len_u64);251 const len = @as(usize, @intCast(len_u64));
252 try ip.string_bytes.ensureUnusedCapacity(gpa, len);252 try ip.string_bytes.ensureUnusedCapacity(gpa, len);
253 for (0..len) |i| {253 for (0..len) |i| {
254 // I don't think elemValue has the possibility to affect ip.string_bytes. Let's254 // I don't think elemValue has the possibility to affect ip.string_bytes. Let's
...@@ -256,7 +256,7 @@ pub const Value = struct {...@@ -256,7 +256,7 @@ pub const Value = struct {
256 const prev = ip.string_bytes.items.len;256 const prev = ip.string_bytes.items.len;
257 const elem_val = try val.elemValue(mod, i);257 const elem_val = try val.elemValue(mod, i);
258 assert(ip.string_bytes.items.len == prev);258 assert(ip.string_bytes.items.len == prev);
259 const byte = @intCast(u8, elem_val.toUnsignedInt(mod));259 const byte = @as(u8, @intCast(elem_val.toUnsignedInt(mod)));
260 ip.string_bytes.appendAssumeCapacity(byte);260 ip.string_bytes.appendAssumeCapacity(byte);
261 }261 }
262 return ip.getOrPutTrailingString(gpa, len);262 return ip.getOrPutTrailingString(gpa, len);
...@@ -303,7 +303,7 @@ pub const Value = struct {...@@ -303,7 +303,7 @@ pub const Value = struct {
303 } });303 } });
304 },304 },
305 .aggregate => {305 .aggregate => {
306 const len = @intCast(usize, ty.arrayLen(mod));306 const len = @as(usize, @intCast(ty.arrayLen(mod)));
307 const old_elems = val.castTag(.aggregate).?.data[0..len];307 const old_elems = val.castTag(.aggregate).?.data[0..len];
308 const new_elems = try mod.gpa.alloc(InternPool.Index, old_elems.len);308 const new_elems = try mod.gpa.alloc(InternPool.Index, old_elems.len);
309 defer mod.gpa.free(new_elems);309 defer mod.gpa.free(new_elems);
...@@ -534,7 +534,7 @@ pub const Value = struct {...@@ -534,7 +534,7 @@ pub const Value = struct {
534 const base_addr = (try field.base.toValue().getUnsignedIntAdvanced(mod, opt_sema)) orelse return null;534 const base_addr = (try field.base.toValue().getUnsignedIntAdvanced(mod, opt_sema)) orelse return null;
535 const struct_ty = mod.intern_pool.typeOf(field.base).toType().childType(mod);535 const struct_ty = mod.intern_pool.typeOf(field.base).toType().childType(mod);
536 if (opt_sema) |sema| try sema.resolveTypeLayout(struct_ty);536 if (opt_sema) |sema| try sema.resolveTypeLayout(struct_ty);
537 return base_addr + struct_ty.structFieldOffset(@intCast(usize, field.index), mod);537 return base_addr + struct_ty.structFieldOffset(@as(usize, @intCast(field.index)), mod);
538 },538 },
539 else => null,539 else => null,
540 },540 },
...@@ -561,9 +561,9 @@ pub const Value = struct {...@@ -561,9 +561,9 @@ pub const Value = struct {
561 .int => |int| switch (int.storage) {561 .int => |int| switch (int.storage) {
562 .big_int => |big_int| big_int.to(i64) catch unreachable,562 .big_int => |big_int| big_int.to(i64) catch unreachable,
563 .i64 => |x| x,563 .i64 => |x| x,
564 .u64 => |x| @intCast(i64, x),564 .u64 => |x| @as(i64, @intCast(x)),
565 .lazy_align => |ty| @intCast(i64, ty.toType().abiAlignment(mod)),565 .lazy_align => |ty| @as(i64, @intCast(ty.toType().abiAlignment(mod))),
566 .lazy_size => |ty| @intCast(i64, ty.toType().abiSize(mod)),566 .lazy_size => |ty| @as(i64, @intCast(ty.toType().abiSize(mod))),
567 },567 },
568 else => unreachable,568 else => unreachable,
569 },569 },
...@@ -604,7 +604,7 @@ pub const Value = struct {...@@ -604,7 +604,7 @@ pub const Value = struct {
604 const target = mod.getTarget();604 const target = mod.getTarget();
605 const endian = target.cpu.arch.endian();605 const endian = target.cpu.arch.endian();
606 if (val.isUndef(mod)) {606 if (val.isUndef(mod)) {
607 const size = @intCast(usize, ty.abiSize(mod));607 const size = @as(usize, @intCast(ty.abiSize(mod)));
608 @memset(buffer[0..size], 0xaa);608 @memset(buffer[0..size], 0xaa);
609 return;609 return;
610 }610 }
...@@ -623,17 +623,17 @@ pub const Value = struct {...@@ -623,17 +623,17 @@ pub const Value = struct {
623 bigint.writeTwosComplement(buffer[0..byte_count], endian);623 bigint.writeTwosComplement(buffer[0..byte_count], endian);
624 },624 },
625 .Float => switch (ty.floatBits(target)) {625 .Float => switch (ty.floatBits(target)) {
626 16 => std.mem.writeInt(u16, buffer[0..2], @bitCast(u16, val.toFloat(f16, mod)), endian),626 16 => std.mem.writeInt(u16, buffer[0..2], @as(u16, @bitCast(val.toFloat(f16, mod))), endian),
627 32 => std.mem.writeInt(u32, buffer[0..4], @bitCast(u32, val.toFloat(f32, mod)), endian),627 32 => std.mem.writeInt(u32, buffer[0..4], @as(u32, @bitCast(val.toFloat(f32, mod))), endian),
628 64 => std.mem.writeInt(u64, buffer[0..8], @bitCast(u64, val.toFloat(f64, mod)), endian),628 64 => std.mem.writeInt(u64, buffer[0..8], @as(u64, @bitCast(val.toFloat(f64, mod))), endian),
629 80 => std.mem.writeInt(u80, buffer[0..10], @bitCast(u80, val.toFloat(f80, mod)), endian),629 80 => std.mem.writeInt(u80, buffer[0..10], @as(u80, @bitCast(val.toFloat(f80, mod))), endian),
630 128 => std.mem.writeInt(u128, buffer[0..16], @bitCast(u128, val.toFloat(f128, mod)), endian),630 128 => std.mem.writeInt(u128, buffer[0..16], @as(u128, @bitCast(val.toFloat(f128, mod))), endian),
631 else => unreachable,631 else => unreachable,
632 },632 },
633 .Array => {633 .Array => {
634 const len = ty.arrayLen(mod);634 const len = ty.arrayLen(mod);
635 const elem_ty = ty.childType(mod);635 const elem_ty = ty.childType(mod);
636 const elem_size = @intCast(usize, elem_ty.abiSize(mod));636 const elem_size = @as(usize, @intCast(elem_ty.abiSize(mod)));
637 var elem_i: usize = 0;637 var elem_i: usize = 0;
638 var buf_off: usize = 0;638 var buf_off: usize = 0;
639 while (elem_i < len) : (elem_i += 1) {639 while (elem_i < len) : (elem_i += 1) {
...@@ -645,13 +645,13 @@ pub const Value = struct {...@@ -645,13 +645,13 @@ pub const Value = struct {
645 .Vector => {645 .Vector => {
646 // We use byte_count instead of abi_size here, so that any padding bytes646 // We use byte_count instead of abi_size here, so that any padding bytes
647 // follow the data bytes, on both big- and little-endian systems.647 // follow the data bytes, on both big- and little-endian systems.
648 const byte_count = (@intCast(usize, ty.bitSize(mod)) + 7) / 8;648 const byte_count = (@as(usize, @intCast(ty.bitSize(mod))) + 7) / 8;
649 return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0);649 return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0);
650 },650 },
651 .Struct => switch (ty.containerLayout(mod)) {651 .Struct => switch (ty.containerLayout(mod)) {
652 .Auto => return error.IllDefinedMemoryLayout,652 .Auto => return error.IllDefinedMemoryLayout,
653 .Extern => for (ty.structFields(mod).values(), 0..) |field, i| {653 .Extern => for (ty.structFields(mod).values(), 0..) |field, i| {
654 const off = @intCast(usize, ty.structFieldOffset(i, mod));654 const off = @as(usize, @intCast(ty.structFieldOffset(i, mod)));
655 const field_val = switch (val.ip_index) {655 const field_val = switch (val.ip_index) {
656 .none => switch (val.tag()) {656 .none => switch (val.tag()) {
657 .bytes => {657 .bytes => {
...@@ -674,7 +674,7 @@ pub const Value = struct {...@@ -674,7 +674,7 @@ pub const Value = struct {
674 try writeToMemory(field_val, field.ty, mod, buffer[off..]);674 try writeToMemory(field_val, field.ty, mod, buffer[off..]);
675 },675 },
676 .Packed => {676 .Packed => {
677 const byte_count = (@intCast(usize, ty.bitSize(mod)) + 7) / 8;677 const byte_count = (@as(usize, @intCast(ty.bitSize(mod))) + 7) / 8;
678 return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0);678 return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0);
679 },679 },
680 },680 },
...@@ -686,14 +686,14 @@ pub const Value = struct {...@@ -686,14 +686,14 @@ pub const Value = struct {
686 .error_union => |error_union| error_union.val.err_name,686 .error_union => |error_union| error_union.val.err_name,
687 else => unreachable,687 else => unreachable,
688 };688 };
689 const int = @intCast(Module.ErrorInt, mod.global_error_set.getIndex(name).?);689 const int = @as(Module.ErrorInt, @intCast(mod.global_error_set.getIndex(name).?));
690 std.mem.writeInt(Int, buffer[0..@sizeOf(Int)], @intCast(Int, int), endian);690 std.mem.writeInt(Int, buffer[0..@sizeOf(Int)], @as(Int, @intCast(int)), endian);
691 },691 },
692 .Union => switch (ty.containerLayout(mod)) {692 .Union => switch (ty.containerLayout(mod)) {
693 .Auto => return error.IllDefinedMemoryLayout,693 .Auto => return error.IllDefinedMemoryLayout,
694 .Extern => return error.Unimplemented,694 .Extern => return error.Unimplemented,
695 .Packed => {695 .Packed => {
696 const byte_count = (@intCast(usize, ty.bitSize(mod)) + 7) / 8;696 const byte_count = (@as(usize, @intCast(ty.bitSize(mod))) + 7) / 8;
697 return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0);697 return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0);
698 },698 },
699 },699 },
...@@ -730,7 +730,7 @@ pub const Value = struct {...@@ -730,7 +730,7 @@ pub const Value = struct {
730 const target = mod.getTarget();730 const target = mod.getTarget();
731 const endian = target.cpu.arch.endian();731 const endian = target.cpu.arch.endian();
732 if (val.isUndef(mod)) {732 if (val.isUndef(mod)) {
733 const bit_size = @intCast(usize, ty.bitSize(mod));733 const bit_size = @as(usize, @intCast(ty.bitSize(mod)));
734 std.mem.writeVarPackedInt(buffer, bit_offset, bit_size, @as(u1, 0), endian);734 std.mem.writeVarPackedInt(buffer, bit_offset, bit_size, @as(u1, 0), endian);
735 return;735 return;
736 }736 }
...@@ -742,9 +742,9 @@ pub const Value = struct {...@@ -742,9 +742,9 @@ pub const Value = struct {
742 .Big => buffer.len - bit_offset / 8 - 1,742 .Big => buffer.len - bit_offset / 8 - 1,
743 };743 };
744 if (val.toBool()) {744 if (val.toBool()) {
745 buffer[byte_index] |= (@as(u8, 1) << @intCast(u3, bit_offset % 8));745 buffer[byte_index] |= (@as(u8, 1) << @as(u3, @intCast(bit_offset % 8)));
746 } else {746 } else {
747 buffer[byte_index] &= ~(@as(u8, 1) << @intCast(u3, bit_offset % 8));747 buffer[byte_index] &= ~(@as(u8, 1) << @as(u3, @intCast(bit_offset % 8)));
748 }748 }
749 },749 },
750 .Int, .Enum => {750 .Int, .Enum => {
...@@ -759,17 +759,17 @@ pub const Value = struct {...@@ -759,17 +759,17 @@ pub const Value = struct {
759 }759 }
760 },760 },
761 .Float => switch (ty.floatBits(target)) {761 .Float => switch (ty.floatBits(target)) {
762 16 => std.mem.writePackedInt(u16, buffer, bit_offset, @bitCast(u16, val.toFloat(f16, mod)), endian),762 16 => std.mem.writePackedInt(u16, buffer, bit_offset, @as(u16, @bitCast(val.toFloat(f16, mod))), endian),
763 32 => std.mem.writePackedInt(u32, buffer, bit_offset, @bitCast(u32, val.toFloat(f32, mod)), endian),763 32 => std.mem.writePackedInt(u32, buffer, bit_offset, @as(u32, @bitCast(val.toFloat(f32, mod))), endian),
764 64 => std.mem.writePackedInt(u64, buffer, bit_offset, @bitCast(u64, val.toFloat(f64, mod)), endian),764 64 => std.mem.writePackedInt(u64, buffer, bit_offset, @as(u64, @bitCast(val.toFloat(f64, mod))), endian),
765 80 => std.mem.writePackedInt(u80, buffer, bit_offset, @bitCast(u80, val.toFloat(f80, mod)), endian),765 80 => std.mem.writePackedInt(u80, buffer, bit_offset, @as(u80, @bitCast(val.toFloat(f80, mod))), endian),
766 128 => std.mem.writePackedInt(u128, buffer, bit_offset, @bitCast(u128, val.toFloat(f128, mod)), endian),766 128 => std.mem.writePackedInt(u128, buffer, bit_offset, @as(u128, @bitCast(val.toFloat(f128, mod))), endian),
767 else => unreachable,767 else => unreachable,
768 },768 },
769 .Vector => {769 .Vector => {
770 const elem_ty = ty.childType(mod);770 const elem_ty = ty.childType(mod);
771 const elem_bit_size = @intCast(u16, elem_ty.bitSize(mod));771 const elem_bit_size = @as(u16, @intCast(elem_ty.bitSize(mod)));
772 const len = @intCast(usize, ty.arrayLen(mod));772 const len = @as(usize, @intCast(ty.arrayLen(mod)));
773773
774 var bits: u16 = 0;774 var bits: u16 = 0;
775 var elem_i: usize = 0;775 var elem_i: usize = 0;
...@@ -789,7 +789,7 @@ pub const Value = struct {...@@ -789,7 +789,7 @@ pub const Value = struct {
789 const fields = ty.structFields(mod).values();789 const fields = ty.structFields(mod).values();
790 const storage = mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage;790 const storage = mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage;
791 for (fields, 0..) |field, i| {791 for (fields, 0..) |field, i| {
792 const field_bits = @intCast(u16, field.ty.bitSize(mod));792 const field_bits = @as(u16, @intCast(field.ty.bitSize(mod)));
793 const field_val = switch (storage) {793 const field_val = switch (storage) {
794 .bytes => unreachable,794 .bytes => unreachable,
795 .elems => |elems| elems[i],795 .elems => |elems| elems[i],
...@@ -865,12 +865,12 @@ pub const Value = struct {...@@ -865,12 +865,12 @@ pub const Value = struct {
865 if (bits <= 64) switch (int_info.signedness) { // Fast path for integers <= u64865 if (bits <= 64) switch (int_info.signedness) { // Fast path for integers <= u64
866 .signed => {866 .signed => {
867 const val = std.mem.readVarInt(i64, buffer[0..byte_count], endian);867 const val = std.mem.readVarInt(i64, buffer[0..byte_count], endian);
868 const result = (val << @intCast(u6, 64 - bits)) >> @intCast(u6, 64 - bits);868 const result = (val << @as(u6, @intCast(64 - bits))) >> @as(u6, @intCast(64 - bits));
869 return mod.getCoerced(try mod.intValue(int_ty, result), ty);869 return mod.getCoerced(try mod.intValue(int_ty, result), ty);
870 },870 },
871 .unsigned => {871 .unsigned => {
872 const val = std.mem.readVarInt(u64, buffer[0..byte_count], endian);872 const val = std.mem.readVarInt(u64, buffer[0..byte_count], endian);
873 const result = (val << @intCast(u6, 64 - bits)) >> @intCast(u6, 64 - bits);873 const result = (val << @as(u6, @intCast(64 - bits))) >> @as(u6, @intCast(64 - bits));
874 return mod.getCoerced(try mod.intValue(int_ty, result), ty);874 return mod.getCoerced(try mod.intValue(int_ty, result), ty);
875 },875 },
876 } else { // Slow path, we have to construct a big-int876 } else { // Slow path, we have to construct a big-int
...@@ -886,22 +886,22 @@ pub const Value = struct {...@@ -886,22 +886,22 @@ pub const Value = struct {
886 .Float => return (try mod.intern(.{ .float = .{886 .Float => return (try mod.intern(.{ .float = .{
887 .ty = ty.toIntern(),887 .ty = ty.toIntern(),
888 .storage = switch (ty.floatBits(target)) {888 .storage = switch (ty.floatBits(target)) {
889 16 => .{ .f16 = @bitCast(f16, std.mem.readInt(u16, buffer[0..2], endian)) },889 16 => .{ .f16 = @as(f16, @bitCast(std.mem.readInt(u16, buffer[0..2], endian))) },
890 32 => .{ .f32 = @bitCast(f32, std.mem.readInt(u32, buffer[0..4], endian)) },890 32 => .{ .f32 = @as(f32, @bitCast(std.mem.readInt(u32, buffer[0..4], endian))) },
891 64 => .{ .f64 = @bitCast(f64, std.mem.readInt(u64, buffer[0..8], endian)) },891 64 => .{ .f64 = @as(f64, @bitCast(std.mem.readInt(u64, buffer[0..8], endian))) },
892 80 => .{ .f80 = @bitCast(f80, std.mem.readInt(u80, buffer[0..10], endian)) },892 80 => .{ .f80 = @as(f80, @bitCast(std.mem.readInt(u80, buffer[0..10], endian))) },
893 128 => .{ .f128 = @bitCast(f128, std.mem.readInt(u128, buffer[0..16], endian)) },893 128 => .{ .f128 = @as(f128, @bitCast(std.mem.readInt(u128, buffer[0..16], endian))) },
894 else => unreachable,894 else => unreachable,
895 },895 },
896 } })).toValue(),896 } })).toValue(),
897 .Array => {897 .Array => {
898 const elem_ty = ty.childType(mod);898 const elem_ty = ty.childType(mod);
899 const elem_size = elem_ty.abiSize(mod);899 const elem_size = elem_ty.abiSize(mod);
900 const elems = try arena.alloc(InternPool.Index, @intCast(usize, ty.arrayLen(mod)));900 const elems = try arena.alloc(InternPool.Index, @as(usize, @intCast(ty.arrayLen(mod))));
901 var offset: usize = 0;901 var offset: usize = 0;
902 for (elems) |*elem| {902 for (elems) |*elem| {
903 elem.* = try (try readFromMemory(elem_ty, mod, buffer[offset..], arena)).intern(elem_ty, mod);903 elem.* = try (try readFromMemory(elem_ty, mod, buffer[offset..], arena)).intern(elem_ty, mod);
904 offset += @intCast(usize, elem_size);904 offset += @as(usize, @intCast(elem_size));
905 }905 }
906 return (try mod.intern(.{ .aggregate = .{906 return (try mod.intern(.{ .aggregate = .{
907 .ty = ty.toIntern(),907 .ty = ty.toIntern(),
...@@ -911,7 +911,7 @@ pub const Value = struct {...@@ -911,7 +911,7 @@ pub const Value = struct {
911 .Vector => {911 .Vector => {
912 // We use byte_count instead of abi_size here, so that any padding bytes912 // We use byte_count instead of abi_size here, so that any padding bytes
913 // follow the data bytes, on both big- and little-endian systems.913 // follow the data bytes, on both big- and little-endian systems.
914 const byte_count = (@intCast(usize, ty.bitSize(mod)) + 7) / 8;914 const byte_count = (@as(usize, @intCast(ty.bitSize(mod))) + 7) / 8;
915 return readFromPackedMemory(ty, mod, buffer[0..byte_count], 0, arena);915 return readFromPackedMemory(ty, mod, buffer[0..byte_count], 0, arena);
916 },916 },
917 .Struct => switch (ty.containerLayout(mod)) {917 .Struct => switch (ty.containerLayout(mod)) {
...@@ -920,8 +920,8 @@ pub const Value = struct {...@@ -920,8 +920,8 @@ pub const Value = struct {
920 const fields = ty.structFields(mod).values();920 const fields = ty.structFields(mod).values();
921 const field_vals = try arena.alloc(InternPool.Index, fields.len);921 const field_vals = try arena.alloc(InternPool.Index, fields.len);
922 for (field_vals, fields, 0..) |*field_val, field, i| {922 for (field_vals, fields, 0..) |*field_val, field, i| {
923 const off = @intCast(usize, ty.structFieldOffset(i, mod));923 const off = @as(usize, @intCast(ty.structFieldOffset(i, mod)));
924 const sz = @intCast(usize, field.ty.abiSize(mod));924 const sz = @as(usize, @intCast(field.ty.abiSize(mod)));
925 field_val.* = try (try readFromMemory(field.ty, mod, buffer[off..(off + sz)], arena)).intern(field.ty, mod);925 field_val.* = try (try readFromMemory(field.ty, mod, buffer[off..(off + sz)], arena)).intern(field.ty, mod);
926 }926 }
927 return (try mod.intern(.{ .aggregate = .{927 return (try mod.intern(.{ .aggregate = .{
...@@ -930,7 +930,7 @@ pub const Value = struct {...@@ -930,7 +930,7 @@ pub const Value = struct {
930 } })).toValue();930 } })).toValue();
931 },931 },
932 .Packed => {932 .Packed => {
933 const byte_count = (@intCast(usize, ty.bitSize(mod)) + 7) / 8;933 const byte_count = (@as(usize, @intCast(ty.bitSize(mod))) + 7) / 8;
934 return readFromPackedMemory(ty, mod, buffer[0..byte_count], 0, arena);934 return readFromPackedMemory(ty, mod, buffer[0..byte_count], 0, arena);
935 },935 },
936 },936 },
...@@ -938,7 +938,7 @@ pub const Value = struct {...@@ -938,7 +938,7 @@ pub const Value = struct {
938 // TODO revisit this when we have the concept of the error tag type938 // TODO revisit this when we have the concept of the error tag type
939 const Int = u16;939 const Int = u16;
940 const int = std.mem.readInt(Int, buffer[0..@sizeOf(Int)], endian);940 const int = std.mem.readInt(Int, buffer[0..@sizeOf(Int)], endian);
941 const name = mod.global_error_set.keys()[@intCast(usize, int)];941 const name = mod.global_error_set.keys()[@as(usize, @intCast(int))];
942 return (try mod.intern(.{ .err = .{942 return (try mod.intern(.{ .err = .{
943 .ty = ty.toIntern(),943 .ty = ty.toIntern(),
944 .name = name,944 .name = name,
...@@ -977,7 +977,7 @@ pub const Value = struct {...@@ -977,7 +977,7 @@ pub const Value = struct {
977 .Big => buffer[buffer.len - bit_offset / 8 - 1],977 .Big => buffer[buffer.len - bit_offset / 8 - 1],
978 .Little => buffer[bit_offset / 8],978 .Little => buffer[bit_offset / 8],
979 };979 };
980 if (((byte >> @intCast(u3, bit_offset % 8)) & 1) == 0) {980 if (((byte >> @as(u3, @intCast(bit_offset % 8))) & 1) == 0) {
981 return Value.false;981 return Value.false;
982 } else {982 } else {
983 return Value.true;983 return Value.true;
...@@ -1009,7 +1009,7 @@ pub const Value = struct {...@@ -1009,7 +1009,7 @@ pub const Value = struct {
1009 }1009 }
10101010
1011 // Slow path, we have to construct a big-int1011 // Slow path, we have to construct a big-int
1012 const abi_size = @intCast(usize, ty.abiSize(mod));1012 const abi_size = @as(usize, @intCast(ty.abiSize(mod)));
1013 const Limb = std.math.big.Limb;1013 const Limb = std.math.big.Limb;
1014 const limb_count = (abi_size + @sizeOf(Limb) - 1) / @sizeOf(Limb);1014 const limb_count = (abi_size + @sizeOf(Limb) - 1) / @sizeOf(Limb);
1015 const limbs_buffer = try arena.alloc(Limb, limb_count);1015 const limbs_buffer = try arena.alloc(Limb, limb_count);
...@@ -1021,20 +1021,20 @@ pub const Value = struct {...@@ -1021,20 +1021,20 @@ pub const Value = struct {
1021 .Float => return (try mod.intern(.{ .float = .{1021 .Float => return (try mod.intern(.{ .float = .{
1022 .ty = ty.toIntern(),1022 .ty = ty.toIntern(),
1023 .storage = switch (ty.floatBits(target)) {1023 .storage = switch (ty.floatBits(target)) {
1024 16 => .{ .f16 = @bitCast(f16, std.mem.readPackedInt(u16, buffer, bit_offset, endian)) },1024 16 => .{ .f16 = @as(f16, @bitCast(std.mem.readPackedInt(u16, buffer, bit_offset, endian))) },
1025 32 => .{ .f32 = @bitCast(f32, std.mem.readPackedInt(u32, buffer, bit_offset, endian)) },1025 32 => .{ .f32 = @as(f32, @bitCast(std.mem.readPackedInt(u32, buffer, bit_offset, endian))) },
1026 64 => .{ .f64 = @bitCast(f64, std.mem.readPackedInt(u64, buffer, bit_offset, endian)) },1026 64 => .{ .f64 = @as(f64, @bitCast(std.mem.readPackedInt(u64, buffer, bit_offset, endian))) },
1027 80 => .{ .f80 = @bitCast(f80, std.mem.readPackedInt(u80, buffer, bit_offset, endian)) },1027 80 => .{ .f80 = @as(f80, @bitCast(std.mem.readPackedInt(u80, buffer, bit_offset, endian))) },
1028 128 => .{ .f128 = @bitCast(f128, std.mem.readPackedInt(u128, buffer, bit_offset, endian)) },1028 128 => .{ .f128 = @as(f128, @bitCast(std.mem.readPackedInt(u128, buffer, bit_offset, endian))) },
1029 else => unreachable,1029 else => unreachable,
1030 },1030 },
1031 } })).toValue(),1031 } })).toValue(),
1032 .Vector => {1032 .Vector => {
1033 const elem_ty = ty.childType(mod);1033 const elem_ty = ty.childType(mod);
1034 const elems = try arena.alloc(InternPool.Index, @intCast(usize, ty.arrayLen(mod)));1034 const elems = try arena.alloc(InternPool.Index, @as(usize, @intCast(ty.arrayLen(mod))));
10351035
1036 var bits: u16 = 0;1036 var bits: u16 = 0;
1037 const elem_bit_size = @intCast(u16, elem_ty.bitSize(mod));1037 const elem_bit_size = @as(u16, @intCast(elem_ty.bitSize(mod)));
1038 for (elems, 0..) |_, i| {1038 for (elems, 0..) |_, i| {
1039 // On big-endian systems, LLVM reverses the element order of vectors by default1039 // On big-endian systems, LLVM reverses the element order of vectors by default
1040 const tgt_elem_i = if (endian == .Big) elems.len - i - 1 else i;1040 const tgt_elem_i = if (endian == .Big) elems.len - i - 1 else i;
...@@ -1054,7 +1054,7 @@ pub const Value = struct {...@@ -1054,7 +1054,7 @@ pub const Value = struct {
1054 const fields = ty.structFields(mod).values();1054 const fields = ty.structFields(mod).values();
1055 const field_vals = try arena.alloc(InternPool.Index, fields.len);1055 const field_vals = try arena.alloc(InternPool.Index, fields.len);
1056 for (fields, 0..) |field, i| {1056 for (fields, 0..) |field, i| {
1057 const field_bits = @intCast(u16, field.ty.bitSize(mod));1057 const field_bits = @as(u16, @intCast(field.ty.bitSize(mod)));
1058 field_vals[i] = try (try readFromPackedMemory(field.ty, mod, buffer, bit_offset + bits, arena)).intern(field.ty, mod);1058 field_vals[i] = try (try readFromPackedMemory(field.ty, mod, buffer, bit_offset + bits, arena)).intern(field.ty, mod);
1059 bits += field_bits;1059 bits += field_bits;
1060 }1060 }
...@@ -1081,18 +1081,18 @@ pub const Value = struct {...@@ -1081,18 +1081,18 @@ pub const Value = struct {
1081 pub fn toFloat(val: Value, comptime T: type, mod: *Module) T {1081 pub fn toFloat(val: Value, comptime T: type, mod: *Module) T {
1082 return switch (mod.intern_pool.indexToKey(val.toIntern())) {1082 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1083 .int => |int| switch (int.storage) {1083 .int => |int| switch (int.storage) {
1084 .big_int => |big_int| @floatCast(T, bigIntToFloat(big_int.limbs, big_int.positive)),1084 .big_int => |big_int| @as(T, @floatCast(bigIntToFloat(big_int.limbs, big_int.positive))),
1085 inline .u64, .i64 => |x| {1085 inline .u64, .i64 => |x| {
1086 if (T == f80) {1086 if (T == f80) {
1087 @panic("TODO we can't lower this properly on non-x86 llvm backend yet");1087 @panic("TODO we can't lower this properly on non-x86 llvm backend yet");
1088 }1088 }
1089 return @floatFromInt(T, x);1089 return @as(T, @floatFromInt(x));
1090 },1090 },
1091 .lazy_align => |ty| @floatFromInt(T, ty.toType().abiAlignment(mod)),1091 .lazy_align => |ty| @as(T, @floatFromInt(ty.toType().abiAlignment(mod))),
1092 .lazy_size => |ty| @floatFromInt(T, ty.toType().abiSize(mod)),1092 .lazy_size => |ty| @as(T, @floatFromInt(ty.toType().abiSize(mod))),
1093 },1093 },
1094 .float => |float| switch (float.storage) {1094 .float => |float| switch (float.storage) {
1095 inline else => |x| @floatCast(T, x),1095 inline else => |x| @as(T, @floatCast(x)),
1096 },1096 },
1097 else => unreachable,1097 else => unreachable,
1098 };1098 };
...@@ -1107,7 +1107,7 @@ pub const Value = struct {...@@ -1107,7 +1107,7 @@ pub const Value = struct {
1107 var i: usize = limbs.len;1107 var i: usize = limbs.len;
1108 while (i != 0) {1108 while (i != 0) {
1109 i -= 1;1109 i -= 1;
1110 const limb: f128 = @floatFromInt(f128, limbs[i]);1110 const limb: f128 = @as(f128, @floatFromInt(limbs[i]));
1111 result = @mulAdd(f128, base, result, limb);1111 result = @mulAdd(f128, base, result, limb);
1112 }1112 }
1113 if (positive) {1113 if (positive) {
...@@ -1132,7 +1132,7 @@ pub const Value = struct {...@@ -1132,7 +1132,7 @@ pub const Value = struct {
1132 pub fn popCount(val: Value, ty: Type, mod: *Module) u64 {1132 pub fn popCount(val: Value, ty: Type, mod: *Module) u64 {
1133 var bigint_buf: BigIntSpace = undefined;1133 var bigint_buf: BigIntSpace = undefined;
1134 const bigint = val.toBigInt(&bigint_buf, mod);1134 const bigint = val.toBigInt(&bigint_buf, mod);
1135 return @intCast(u64, bigint.popCount(ty.intInfo(mod).bits));1135 return @as(u64, @intCast(bigint.popCount(ty.intInfo(mod).bits)));
1136 }1136 }
11371137
1138 pub fn bitReverse(val: Value, ty: Type, mod: *Module, arena: Allocator) !Value {1138 pub fn bitReverse(val: Value, ty: Type, mod: *Module, arena: Allocator) !Value {
...@@ -1505,10 +1505,10 @@ pub const Value = struct {...@@ -1505,10 +1505,10 @@ pub const Value = struct {
1505 .int, .eu_payload => unreachable,1505 .int, .eu_payload => unreachable,
1506 .opt_payload => |base| base.toValue().elemValue(mod, index),1506 .opt_payload => |base| base.toValue().elemValue(mod, index),
1507 .comptime_field => |field_val| field_val.toValue().elemValue(mod, index),1507 .comptime_field => |field_val| field_val.toValue().elemValue(mod, index),
1508 .elem => |elem| elem.base.toValue().elemValue(mod, index + @intCast(usize, elem.index)),1508 .elem => |elem| elem.base.toValue().elemValue(mod, index + @as(usize, @intCast(elem.index))),
1509 .field => |field| if (field.base.toValue().pointerDecl(mod)) |decl_index| {1509 .field => |field| if (field.base.toValue().pointerDecl(mod)) |decl_index| {
1510 const base_decl = mod.declPtr(decl_index);1510 const base_decl = mod.declPtr(decl_index);
1511 const field_val = try base_decl.val.fieldValue(mod, @intCast(usize, field.index));1511 const field_val = try base_decl.val.fieldValue(mod, @as(usize, @intCast(field.index)));
1512 return field_val.elemValue(mod, index);1512 return field_val.elemValue(mod, index);
1513 } else unreachable,1513 } else unreachable,
1514 },1514 },
...@@ -1604,18 +1604,18 @@ pub const Value = struct {...@@ -1604,18 +1604,18 @@ pub const Value = struct {
1604 .comptime_field => |comptime_field| comptime_field.toValue()1604 .comptime_field => |comptime_field| comptime_field.toValue()
1605 .sliceArray(mod, arena, start, end),1605 .sliceArray(mod, arena, start, end),
1606 .elem => |elem| elem.base.toValue()1606 .elem => |elem| elem.base.toValue()
1607 .sliceArray(mod, arena, start + @intCast(usize, elem.index), end + @intCast(usize, elem.index)),1607 .sliceArray(mod, arena, start + @as(usize, @intCast(elem.index)), end + @as(usize, @intCast(elem.index))),
1608 else => unreachable,1608 else => unreachable,
1609 },1609 },
1610 .aggregate => |aggregate| (try mod.intern(.{ .aggregate = .{1610 .aggregate => |aggregate| (try mod.intern(.{ .aggregate = .{
1611 .ty = switch (mod.intern_pool.indexToKey(mod.intern_pool.typeOf(val.toIntern()))) {1611 .ty = switch (mod.intern_pool.indexToKey(mod.intern_pool.typeOf(val.toIntern()))) {
1612 .array_type => |array_type| try mod.arrayType(.{1612 .array_type => |array_type| try mod.arrayType(.{
1613 .len = @intCast(u32, end - start),1613 .len = @as(u32, @intCast(end - start)),
1614 .child = array_type.child,1614 .child = array_type.child,
1615 .sentinel = if (end == array_type.len) array_type.sentinel else .none,1615 .sentinel = if (end == array_type.len) array_type.sentinel else .none,
1616 }),1616 }),
1617 .vector_type => |vector_type| try mod.vectorType(.{1617 .vector_type => |vector_type| try mod.vectorType(.{
1618 .len = @intCast(u32, end - start),1618 .len = @as(u32, @intCast(end - start)),
1619 .child = vector_type.child,1619 .child = vector_type.child,
1620 }),1620 }),
1621 else => unreachable,1621 else => unreachable,
...@@ -1734,7 +1734,7 @@ pub const Value = struct {...@@ -1734,7 +1734,7 @@ pub const Value = struct {
1734 .simple_value => |v| v == .undefined,1734 .simple_value => |v| v == .undefined,
1735 .ptr => |ptr| switch (ptr.len) {1735 .ptr => |ptr| switch (ptr.len) {
1736 .none => false,1736 .none => false,
1737 else => for (0..@intCast(usize, ptr.len.toValue().toUnsignedInt(mod))) |index| {1737 else => for (0..@as(usize, @intCast(ptr.len.toValue().toUnsignedInt(mod)))) |index| {
1738 if (try (try val.elemValue(mod, index)).anyUndef(mod)) break true;1738 if (try (try val.elemValue(mod, index)).anyUndef(mod)) break true;
1739 } else false,1739 } else false,
1740 },1740 },
...@@ -1783,7 +1783,7 @@ pub const Value = struct {...@@ -1783,7 +1783,7 @@ pub const Value = struct {
17831783
1784 pub fn getErrorInt(val: Value, mod: *const Module) Module.ErrorInt {1784 pub fn getErrorInt(val: Value, mod: *const Module) Module.ErrorInt {
1785 return if (getErrorName(val, mod).unwrap()) |err_name|1785 return if (getErrorName(val, mod).unwrap()) |err_name|
1786 @intCast(Module.ErrorInt, mod.global_error_set.getIndex(err_name).?)1786 @as(Module.ErrorInt, @intCast(mod.global_error_set.getIndex(err_name).?))
1787 else1787 else
1788 0;1788 0;
1789 }1789 }
...@@ -1868,11 +1868,11 @@ pub const Value = struct {...@@ -1868,11 +1868,11 @@ pub const Value = struct {
1868 fn floatFromIntInner(x: anytype, dest_ty: Type, mod: *Module) !Value {1868 fn floatFromIntInner(x: anytype, dest_ty: Type, mod: *Module) !Value {
1869 const target = mod.getTarget();1869 const target = mod.getTarget();
1870 const storage: InternPool.Key.Float.Storage = switch (dest_ty.floatBits(target)) {1870 const storage: InternPool.Key.Float.Storage = switch (dest_ty.floatBits(target)) {
1871 16 => .{ .f16 = @floatFromInt(f16, x) },1871 16 => .{ .f16 = @as(f16, @floatFromInt(x)) },
1872 32 => .{ .f32 = @floatFromInt(f32, x) },1872 32 => .{ .f32 = @as(f32, @floatFromInt(x)) },
1873 64 => .{ .f64 = @floatFromInt(f64, x) },1873 64 => .{ .f64 = @as(f64, @floatFromInt(x)) },
1874 80 => .{ .f80 = @floatFromInt(f80, x) },1874 80 => .{ .f80 = @as(f80, @floatFromInt(x)) },
1875 128 => .{ .f128 = @floatFromInt(f128, x) },1875 128 => .{ .f128 = @as(f128, @floatFromInt(x)) },
1876 else => unreachable,1876 else => unreachable,
1877 };1877 };
1878 return (try mod.intern(.{ .float = .{1878 return (try mod.intern(.{ .float = .{
...@@ -1887,7 +1887,7 @@ pub const Value = struct {...@@ -1887,7 +1887,7 @@ pub const Value = struct {
1887 }1887 }
18881888
1889 const w_value = @fabs(scalar);1889 const w_value = @fabs(scalar);
1890 return @divFloor(@intFromFloat(std.math.big.Limb, std.math.log2(w_value)), @typeInfo(std.math.big.Limb).Int.bits) + 1;1890 return @divFloor(@as(std.math.big.Limb, @intFromFloat(std.math.log2(w_value))), @typeInfo(std.math.big.Limb).Int.bits) + 1;
1891 }1891 }
18921892
1893 pub const OverflowArithmeticResult = struct {1893 pub const OverflowArithmeticResult = struct {
...@@ -2738,14 +2738,14 @@ pub const Value = struct {...@@ -2738,14 +2738,14 @@ pub const Value = struct {
2738 for (result_data, 0..) |*scalar, i| {2738 for (result_data, 0..) |*scalar, i| {
2739 const elem_val = try val.elemValue(mod, i);2739 const elem_val = try val.elemValue(mod, i);
2740 const bits_elem = try bits.elemValue(mod, i);2740 const bits_elem = try bits.elemValue(mod, i);
2741 scalar.* = try (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, @intCast(u16, bits_elem.toUnsignedInt(mod)), mod)).intern(scalar_ty, mod);2741 scalar.* = try (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, @as(u16, @intCast(bits_elem.toUnsignedInt(mod))), mod)).intern(scalar_ty, mod);
2742 }2742 }
2743 return (try mod.intern(.{ .aggregate = .{2743 return (try mod.intern(.{ .aggregate = .{
2744 .ty = ty.toIntern(),2744 .ty = ty.toIntern(),
2745 .storage = .{ .elems = result_data },2745 .storage = .{ .elems = result_data },
2746 } })).toValue();2746 } })).toValue();
2747 }2747 }
2748 return intTruncScalar(val, ty, allocator, signedness, @intCast(u16, bits.toUnsignedInt(mod)), mod);2748 return intTruncScalar(val, ty, allocator, signedness, @as(u16, @intCast(bits.toUnsignedInt(mod))), mod);
2749 }2749 }
27502750
2751 pub fn intTruncScalar(2751 pub fn intTruncScalar(
...@@ -2793,7 +2793,7 @@ pub const Value = struct {...@@ -2793,7 +2793,7 @@ pub const Value = struct {
2793 // resorting to BigInt first.2793 // resorting to BigInt first.
2794 var lhs_space: Value.BigIntSpace = undefined;2794 var lhs_space: Value.BigIntSpace = undefined;
2795 const lhs_bigint = lhs.toBigInt(&lhs_space, mod);2795 const lhs_bigint = lhs.toBigInt(&lhs_space, mod);
2796 const shift = @intCast(usize, rhs.toUnsignedInt(mod));2796 const shift = @as(usize, @intCast(rhs.toUnsignedInt(mod)));
2797 const limbs = try allocator.alloc(2797 const limbs = try allocator.alloc(
2798 std.math.big.Limb,2798 std.math.big.Limb,
2799 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,2799 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,
...@@ -2855,7 +2855,7 @@ pub const Value = struct {...@@ -2855,7 +2855,7 @@ pub const Value = struct {
2855 const info = ty.intInfo(mod);2855 const info = ty.intInfo(mod);
2856 var lhs_space: Value.BigIntSpace = undefined;2856 var lhs_space: Value.BigIntSpace = undefined;
2857 const lhs_bigint = lhs.toBigInt(&lhs_space, mod);2857 const lhs_bigint = lhs.toBigInt(&lhs_space, mod);
2858 const shift = @intCast(usize, rhs.toUnsignedInt(mod));2858 const shift = @as(usize, @intCast(rhs.toUnsignedInt(mod)));
2859 const limbs = try allocator.alloc(2859 const limbs = try allocator.alloc(
2860 std.math.big.Limb,2860 std.math.big.Limb,
2861 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,2861 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,
...@@ -2912,7 +2912,7 @@ pub const Value = struct {...@@ -2912,7 +2912,7 @@ pub const Value = struct {
29122912
2913 var lhs_space: Value.BigIntSpace = undefined;2913 var lhs_space: Value.BigIntSpace = undefined;
2914 const lhs_bigint = lhs.toBigInt(&lhs_space, mod);2914 const lhs_bigint = lhs.toBigInt(&lhs_space, mod);
2915 const shift = @intCast(usize, rhs.toUnsignedInt(mod));2915 const shift = @as(usize, @intCast(rhs.toUnsignedInt(mod)));
2916 const limbs = try arena.alloc(2916 const limbs = try arena.alloc(
2917 std.math.big.Limb,2917 std.math.big.Limb,
2918 std.math.big.int.calcTwosCompLimbCount(info.bits) + 1,2918 std.math.big.int.calcTwosCompLimbCount(info.bits) + 1,
...@@ -2984,7 +2984,7 @@ pub const Value = struct {...@@ -2984,7 +2984,7 @@ pub const Value = struct {
2984 // resorting to BigInt first.2984 // resorting to BigInt first.
2985 var lhs_space: Value.BigIntSpace = undefined;2985 var lhs_space: Value.BigIntSpace = undefined;
2986 const lhs_bigint = lhs.toBigInt(&lhs_space, mod);2986 const lhs_bigint = lhs.toBigInt(&lhs_space, mod);
2987 const shift = @intCast(usize, rhs.toUnsignedInt(mod));2987 const shift = @as(usize, @intCast(rhs.toUnsignedInt(mod)));
29882988
2989 const result_limbs = lhs_bigint.limbs.len -| (shift / (@sizeOf(std.math.big.Limb) * 8));2989 const result_limbs = lhs_bigint.limbs.len -| (shift / (@sizeOf(std.math.big.Limb) * 8));
2990 if (result_limbs == 0) {2990 if (result_limbs == 0) {
test/behavior/align.zig+12-16
...@@ -24,7 +24,7 @@ test "slicing array of length 1 can not assume runtime index is always zero" {...@@ -24,7 +24,7 @@ test "slicing array of length 1 can not assume runtime index is always zero" {
24 const slice = @as(*align(4) [1]u8, &foo)[runtime_index..];24 const slice = @as(*align(4) [1]u8, &foo)[runtime_index..];
25 try expect(@TypeOf(slice) == []u8);25 try expect(@TypeOf(slice) == []u8);
26 try expect(slice.len == 0);26 try expect(slice.len == 0);
27 try expect(@truncate(u2, @intFromPtr(slice.ptr) - 1) == 0);27 try expect(@as(u2, @truncate(@intFromPtr(slice.ptr) - 1)) == 0);
28}28}
2929
30test "default alignment allows unspecified in type syntax" {30test "default alignment allows unspecified in type syntax" {
...@@ -47,7 +47,7 @@ test "@alignCast pointers" {...@@ -47,7 +47,7 @@ test "@alignCast pointers" {
47 try expect(x == 2);47 try expect(x == 2);
48}48}
49fn expectsOnly1(x: *align(1) u32) void {49fn expectsOnly1(x: *align(1) u32) void {
50 expects4(@alignCast(4, x));50 expects4(@alignCast(x));
51}51}
52fn expects4(x: *align(4) u32) void {52fn expects4(x: *align(4) u32) void {
53 x.* += 1;53 x.* += 1;
...@@ -213,12 +213,6 @@ test "alignment and size of structs with 128-bit fields" {...@@ -213,12 +213,6 @@ test "alignment and size of structs with 128-bit fields" {
213 }213 }
214}214}
215215
216test "@ptrCast preserves alignment of bigger source" {
217 var x: u32 align(16) = 1234;
218 const ptr = @ptrCast(*u8, &x);
219 try expect(@TypeOf(ptr) == *align(16) u8);
220}
221
222test "alignstack" {216test "alignstack" {
223 try expect(fnWithAlignedStack() == 1234);217 try expect(fnWithAlignedStack() == 1234);
224}218}
...@@ -249,7 +243,7 @@ test "specifying alignment allows pointer cast" {...@@ -249,7 +243,7 @@ test "specifying alignment allows pointer cast" {
249}243}
250fn testBytesAlign(b: u8) !void {244fn testBytesAlign(b: u8) !void {
251 var bytes align(4) = [_]u8{ b, b, b, b };245 var bytes align(4) = [_]u8{ b, b, b, b };
252 const ptr = @ptrCast(*u32, &bytes[0]);246 const ptr = @as(*u32, @ptrCast(&bytes[0]));
253 try expect(ptr.* == 0x33333333);247 try expect(ptr.* == 0x33333333);
254}248}
255249
...@@ -265,7 +259,7 @@ test "@alignCast slices" {...@@ -265,7 +259,7 @@ test "@alignCast slices" {
265 try expect(slice[0] == 2);259 try expect(slice[0] == 2);
266}260}
267fn sliceExpectsOnly1(slice: []align(1) u32) void {261fn sliceExpectsOnly1(slice: []align(1) u32) void {
268 sliceExpects4(@alignCast(4, slice));262 sliceExpects4(@alignCast(slice));
269}263}
270fn sliceExpects4(slice: []align(4) u32) void {264fn sliceExpects4(slice: []align(4) u32) void {
271 slice[0] += 1;265 slice[0] += 1;
...@@ -302,8 +296,8 @@ test "page aligned array on stack" {...@@ -302,8 +296,8 @@ test "page aligned array on stack" {
302 try expect(@intFromPtr(&array[0]) & 0xFFF == 0);296 try expect(@intFromPtr(&array[0]) & 0xFFF == 0);
303 try expect(array[3] == 4);297 try expect(array[3] == 4);
304298
305 try expect(@truncate(u4, @intFromPtr(&number1)) == 0);299 try expect(@as(u4, @truncate(@intFromPtr(&number1))) == 0);
306 try expect(@truncate(u4, @intFromPtr(&number2)) == 0);300 try expect(@as(u4, @truncate(@intFromPtr(&number2))) == 0);
307 try expect(number1 == 42);301 try expect(number1 == 42);
308 try expect(number2 == 43);302 try expect(number2 == 43);
309}303}
...@@ -366,7 +360,7 @@ test "@alignCast functions" {...@@ -366,7 +360,7 @@ test "@alignCast functions" {
366 try expect(fnExpectsOnly1(simple4) == 0x19);360 try expect(fnExpectsOnly1(simple4) == 0x19);
367}361}
368fn fnExpectsOnly1(ptr: *const fn () align(1) i32) i32 {362fn fnExpectsOnly1(ptr: *const fn () align(1) i32) i32 {
369 return fnExpects4(@alignCast(4, ptr));363 return fnExpects4(@alignCast(ptr));
370}364}
371fn fnExpects4(ptr: *const fn () align(4) i32) i32 {365fn fnExpects4(ptr: *const fn () align(4) i32) i32 {
372 return ptr();366 return ptr();
...@@ -461,9 +455,11 @@ fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) !void {...@@ -461,9 +455,11 @@ fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) !void {
461test "alignment of function with c calling convention" {455test "alignment of function with c calling convention" {
462 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;456 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
463457
458 const a = @alignOf(@TypeOf(nothing));
459
464 var runtime_nothing = &nothing;460 var runtime_nothing = &nothing;
465 const casted1 = @ptrCast(*const u8, runtime_nothing);461 const casted1: *align(a) const u8 = @ptrCast(runtime_nothing);
466 const casted2 = @ptrCast(*const fn () callconv(.C) void, casted1);462 const casted2: *const fn () callconv(.C) void = @ptrCast(casted1);
467 casted2();463 casted2();
468}464}
469465
...@@ -588,7 +584,7 @@ test "@alignCast null" {...@@ -588,7 +584,7 @@ test "@alignCast null" {
588 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;584 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
589585
590 var ptr: ?*anyopaque = null;586 var ptr: ?*anyopaque = null;
591 const aligned: ?*anyopaque = @alignCast(@alignOf(?*anyopaque), ptr);587 const aligned: ?*anyopaque = @alignCast(ptr);
592 try expect(aligned == null);588 try expect(aligned == null);
593}589}
594590
test/behavior/array.zig+2-2
...@@ -170,7 +170,7 @@ test "array with sentinels" {...@@ -170,7 +170,7 @@ test "array with sentinels" {
170 {170 {
171 var zero_sized: [0:0xde]u8 = [_:0xde]u8{};171 var zero_sized: [0:0xde]u8 = [_:0xde]u8{};
172 try expect(zero_sized[0] == 0xde);172 try expect(zero_sized[0] == 0xde);
173 var reinterpreted = @ptrCast(*[1]u8, &zero_sized);173 var reinterpreted = @as(*[1]u8, @ptrCast(&zero_sized));
174 try expect(reinterpreted[0] == 0xde);174 try expect(reinterpreted[0] == 0xde);
175 }175 }
176 var arr: [3:0x55]u8 = undefined;176 var arr: [3:0x55]u8 = undefined;
...@@ -694,7 +694,7 @@ test "array init of container level array variable" {...@@ -694,7 +694,7 @@ test "array init of container level array variable" {
694test "runtime initialized sentinel-terminated array literal" {694test "runtime initialized sentinel-terminated array literal" {
695 var c: u16 = 300;695 var c: u16 = 300;
696 const f = &[_:0x9999]u16{c};696 const f = &[_:0x9999]u16{c};
697 const g = @ptrCast(*const [4]u8, f);697 const g = @as(*const [4]u8, @ptrCast(f));
698 try std.testing.expect(g[2] == 0x99);698 try std.testing.expect(g[2] == 0x99);
699 try std.testing.expect(g[3] == 0x99);699 try std.testing.expect(g[3] == 0x99);
700}700}
test/behavior/async_fn.zig+5-5
...@@ -136,12 +136,12 @@ test "@frameSize" {...@@ -136,12 +136,12 @@ test "@frameSize" {
136 const S = struct {136 const S = struct {
137 fn doTheTest() !void {137 fn doTheTest() !void {
138 {138 {
139 var ptr = @ptrCast(fn (i32) callconv(.Async) void, other);139 var ptr = @as(fn (i32) callconv(.Async) void, @ptrCast(other));
140 const size = @frameSize(ptr);140 const size = @frameSize(ptr);
141 try expect(size == @sizeOf(@Frame(other)));141 try expect(size == @sizeOf(@Frame(other)));
142 }142 }
143 {143 {
144 var ptr = @ptrCast(fn () callconv(.Async) void, first);144 var ptr = @as(fn () callconv(.Async) void, @ptrCast(first));
145 const size = @frameSize(ptr);145 const size = @frameSize(ptr);
146 try expect(size == @sizeOf(@Frame(first)));146 try expect(size == @sizeOf(@Frame(first)));
147 }147 }
...@@ -1184,7 +1184,7 @@ test "using @TypeOf on a generic function call" {...@@ -1184,7 +1184,7 @@ test "using @TypeOf on a generic function call" {
1184 global_frame = @frame();1184 global_frame = @frame();
1185 }1185 }
1186 const F = @TypeOf(async amain(x - 1));1186 const F = @TypeOf(async amain(x - 1));
1187 const frame = @ptrFromInt(*F, @intFromPtr(&buf));1187 const frame = @as(*F, @ptrFromInt(@intFromPtr(&buf)));
1188 return await @asyncCall(frame, {}, amain, .{x - 1});1188 return await @asyncCall(frame, {}, amain, .{x - 1});
1189 }1189 }
1190 };1190 };
...@@ -1212,7 +1212,7 @@ test "recursive call of await @asyncCall with struct return type" {...@@ -1212,7 +1212,7 @@ test "recursive call of await @asyncCall with struct return type" {
1212 global_frame = @frame();1212 global_frame = @frame();
1213 }1213 }
1214 const F = @TypeOf(async amain(x - 1));1214 const F = @TypeOf(async amain(x - 1));
1215 const frame = @ptrFromInt(*F, @intFromPtr(&buf));1215 const frame = @as(*F, @ptrFromInt(@intFromPtr(&buf)));
1216 return await @asyncCall(frame, {}, amain, .{x - 1});1216 return await @asyncCall(frame, {}, amain, .{x - 1});
1217 }1217 }
12181218
...@@ -1833,7 +1833,7 @@ test "avoid forcing frame alignment resolution implicit cast to *anyopaque" {...@@ -1833,7 +1833,7 @@ test "avoid forcing frame alignment resolution implicit cast to *anyopaque" {
1833 }1833 }
1834 };1834 };
1835 var frame = async S.foo();1835 var frame = async S.foo();
1836 resume @ptrCast(anyframe->bool, @alignCast(@alignOf(@Frame(S.foo)), S.x));1836 resume @as(anyframe->bool, @ptrCast(@alignCast(S.x)));
1837 try expect(nosuspend await frame);1837 try expect(nosuspend await frame);
1838}1838}
18391839
test/behavior/atomics.zig+1-1
...@@ -326,7 +326,7 @@ fn testAtomicRmwInt128(comptime signedness: std.builtin.Signedness) !void {...@@ -326,7 +326,7 @@ fn testAtomicRmwInt128(comptime signedness: std.builtin.Signedness) !void {
326 const uint = std.meta.Int(.unsigned, 128);326 const uint = std.meta.Int(.unsigned, 128);
327 const int = std.meta.Int(signedness, 128);327 const int = std.meta.Int(signedness, 128);
328328
329 const initial: int = @bitCast(int, @as(uint, 0xaaaaaaaa_bbbbbbbb_cccccccc_dddddddd));329 const initial: int = @as(int, @bitCast(@as(uint, 0xaaaaaaaa_bbbbbbbb_cccccccc_dddddddd)));
330 const replacement: int = 0x00000000_00000005_00000000_00000003;330 const replacement: int = 0x00000000_00000005_00000000_00000003;
331331
332 var x: int align(16) = initial;332 var x: int align(16) = initial;
test/behavior/basic.zig+11-11
...@@ -20,7 +20,7 @@ test "truncate" {...@@ -20,7 +20,7 @@ test "truncate" {
20 try comptime expect(testTruncate(0x10fd) == 0xfd);20 try comptime expect(testTruncate(0x10fd) == 0xfd);
21}21}
22fn testTruncate(x: u32) u8 {22fn testTruncate(x: u32) u8 {
23 return @truncate(u8, x);23 return @as(u8, @truncate(x));
24}24}
2525
26test "truncate to non-power-of-two integers" {26test "truncate to non-power-of-two integers" {
...@@ -56,7 +56,7 @@ test "truncate to non-power-of-two integers from 128-bit" {...@@ -56,7 +56,7 @@ test "truncate to non-power-of-two integers from 128-bit" {
56}56}
5757
58fn testTrunc(comptime Big: type, comptime Little: type, big: Big, little: Little) !void {58fn testTrunc(comptime Big: type, comptime Little: type, big: Big, little: Little) !void {
59 try expect(@truncate(Little, big) == little);59 try expect(@as(Little, @truncate(big)) == little);
60}60}
6161
62const g1: i32 = 1233 + 1;62const g1: i32 = 1233 + 1;
...@@ -229,9 +229,9 @@ test "opaque types" {...@@ -229,9 +229,9 @@ test "opaque types" {
229229
230const global_a: i32 = 1234;230const global_a: i32 = 1234;
231const global_b: *const i32 = &global_a;231const global_b: *const i32 = &global_a;
232const global_c: *const f32 = @ptrCast(*const f32, global_b);232const global_c: *const f32 = @as(*const f32, @ptrCast(global_b));
233test "compile time global reinterpret" {233test "compile time global reinterpret" {
234 const d = @ptrCast(*const i32, global_c);234 const d = @as(*const i32, @ptrCast(global_c));
235 try expect(d.* == 1234);235 try expect(d.* == 1234);
236}236}
237237
...@@ -362,7 +362,7 @@ test "variable is allowed to be a pointer to an opaque type" {...@@ -362,7 +362,7 @@ test "variable is allowed to be a pointer to an opaque type" {
362 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;362 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
363363
364 var x: i32 = 1234;364 var x: i32 = 1234;
365 _ = hereIsAnOpaqueType(@ptrCast(*OpaqueA, &x));365 _ = hereIsAnOpaqueType(@as(*OpaqueA, @ptrCast(&x)));
366}366}
367fn hereIsAnOpaqueType(ptr: *OpaqueA) *OpaqueA {367fn hereIsAnOpaqueType(ptr: *OpaqueA) *OpaqueA {
368 var a = ptr;368 var a = ptr;
...@@ -442,7 +442,7 @@ test "array 3D const double ptr with offset" {...@@ -442,7 +442,7 @@ test "array 3D const double ptr with offset" {
442}442}
443443
444fn testArray2DConstDoublePtr(ptr: *const f32) !void {444fn testArray2DConstDoublePtr(ptr: *const f32) !void {
445 const ptr2 = @ptrCast([*]const f32, ptr);445 const ptr2 = @as([*]const f32, @ptrCast(ptr));
446 try expect(ptr2[0] == 1.0);446 try expect(ptr2[0] == 1.0);
447 try expect(ptr2[1] == 2.0);447 try expect(ptr2[1] == 2.0);
448}448}
...@@ -574,9 +574,9 @@ test "constant equal function pointers" {...@@ -574,9 +574,9 @@ test "constant equal function pointers" {
574574
575fn emptyFn() void {}575fn emptyFn() void {}
576576
577const addr1 = @ptrCast(*const u8, &emptyFn);577const addr1 = @as(*const u8, @ptrCast(&emptyFn));
578test "comptime cast fn to ptr" {578test "comptime cast fn to ptr" {
579 const addr2 = @ptrCast(*const u8, &emptyFn);579 const addr2 = @as(*const u8, @ptrCast(&emptyFn));
580 try comptime expect(addr1 == addr2);580 try comptime expect(addr1 == addr2);
581}581}
582582
...@@ -667,7 +667,7 @@ test "string escapes" {...@@ -667,7 +667,7 @@ test "string escapes" {
667667
668test "explicit cast optional pointers" {668test "explicit cast optional pointers" {
669 const a: ?*i32 = undefined;669 const a: ?*i32 = undefined;
670 const b: ?*f32 = @ptrCast(?*f32, a);670 const b: ?*f32 = @as(?*f32, @ptrCast(a));
671 _ = b;671 _ = b;
672}672}
673673
...@@ -752,7 +752,7 @@ test "auto created variables have correct alignment" {...@@ -752,7 +752,7 @@ test "auto created variables have correct alignment" {
752752
753 const S = struct {753 const S = struct {
754 fn foo(str: [*]const u8) u32 {754 fn foo(str: [*]const u8) u32 {
755 for (@ptrCast([*]align(1) const u32, str)[0..1]) |v| {755 for (@as([*]align(1) const u32, @ptrCast(str))[0..1]) |v| {
756 return v;756 return v;
757 }757 }
758 return 0;758 return 0;
...@@ -772,7 +772,7 @@ test "extern variable with non-pointer opaque type" {...@@ -772,7 +772,7 @@ test "extern variable with non-pointer opaque type" {
772 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;772 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
773773
774 @export(var_to_export, .{ .name = "opaque_extern_var" });774 @export(var_to_export, .{ .name = "opaque_extern_var" });
775 try expect(@ptrCast(*align(1) u32, &opaque_extern_var).* == 42);775 try expect(@as(*align(1) u32, @ptrCast(&opaque_extern_var)).* == 42);
776}776}
777extern var opaque_extern_var: opaque {};777extern var opaque_extern_var: opaque {};
778var var_to_export: u32 = 42;778var var_to_export: u32 = 42;
test/behavior/bit_shifting.zig+3-3
...@@ -28,7 +28,7 @@ fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, compt...@@ -28,7 +28,7 @@ fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, compt
28 // TODO: https://github.com/ziglang/zig/issues/154428 // TODO: https://github.com/ziglang/zig/issues/1544
29 // This cast could be implicit if we teach the compiler that29 // This cast could be implicit if we teach the compiler that
30 // u32 >> 30 -> u230 // u32 >> 30 -> u2
31 return @intCast(ShardKey, shard_key);31 return @as(ShardKey, @intCast(shard_key));
32 }32 }
3333
34 pub fn put(self: *Self, node: *Node) void {34 pub fn put(self: *Self, node: *Node) void {
...@@ -85,14 +85,14 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c...@@ -85,14 +85,14 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c
85 var table = Table.create();85 var table = Table.create();
86 var node_buffer: [node_count]Table.Node = undefined;86 var node_buffer: [node_count]Table.Node = undefined;
87 for (&node_buffer, 0..) |*node, i| {87 for (&node_buffer, 0..) |*node, i| {
88 const key = @intCast(Key, i);88 const key = @as(Key, @intCast(i));
89 try expect(table.get(key) == null);89 try expect(table.get(key) == null);
90 node.init(key, {});90 node.init(key, {});
91 table.put(node);91 table.put(node);
92 }92 }
9393
94 for (&node_buffer, 0..) |*node, i| {94 for (&node_buffer, 0..) |*node, i| {
95 try expect(table.get(@intCast(Key, i)) == node);95 try expect(table.get(@as(Key, @intCast(i))) == node);
96 }96 }
97}97}
9898
test/behavior/bitcast.zig+37-37
...@@ -71,11 +71,11 @@ fn testBitCast(comptime N: usize) !void {...@@ -71,11 +71,11 @@ fn testBitCast(comptime N: usize) !void {
71}71}
7272
73fn conv_iN(comptime N: usize, x: std.meta.Int(.signed, N)) std.meta.Int(.unsigned, N) {73fn conv_iN(comptime N: usize, x: std.meta.Int(.signed, N)) std.meta.Int(.unsigned, N) {
74 return @bitCast(std.meta.Int(.unsigned, N), x);74 return @as(std.meta.Int(.unsigned, N), @bitCast(x));
75}75}
7676
77fn conv_uN(comptime N: usize, x: std.meta.Int(.unsigned, N)) std.meta.Int(.signed, N) {77fn conv_uN(comptime N: usize, x: std.meta.Int(.unsigned, N)) std.meta.Int(.signed, N) {
78 return @bitCast(std.meta.Int(.signed, N), x);78 return @as(std.meta.Int(.signed, N), @bitCast(x));
79}79}
8080
81test "bitcast uX to bytes" {81test "bitcast uX to bytes" {
...@@ -114,14 +114,14 @@ fn testBitCastuXToBytes(comptime N: usize) !void {...@@ -114,14 +114,14 @@ fn testBitCastuXToBytes(comptime N: usize) !void {
114 while (byte_i < (byte_count - 1)) : (byte_i += 1) {114 while (byte_i < (byte_count - 1)) : (byte_i += 1) {
115 try expect(bytes[byte_i] == 0xff);115 try expect(bytes[byte_i] == 0xff);
116 }116 }
117 try expect(((bytes[byte_i] ^ 0xff) << -%@truncate(u3, N)) == 0);117 try expect(((bytes[byte_i] ^ 0xff) << -%@as(u3, @truncate(N))) == 0);
118 },118 },
119 .Big => {119 .Big => {
120 var byte_i = byte_count - 1;120 var byte_i = byte_count - 1;
121 while (byte_i > 0) : (byte_i -= 1) {121 while (byte_i > 0) : (byte_i -= 1) {
122 try expect(bytes[byte_i] == 0xff);122 try expect(bytes[byte_i] == 0xff);
123 }123 }
124 try expect(((bytes[byte_i] ^ 0xff) << -%@truncate(u3, N)) == 0);124 try expect(((bytes[byte_i] ^ 0xff) << -%@as(u3, @truncate(N))) == 0);
125 },125 },
126 }126 }
127 }127 }
...@@ -130,12 +130,12 @@ fn testBitCastuXToBytes(comptime N: usize) !void {...@@ -130,12 +130,12 @@ fn testBitCastuXToBytes(comptime N: usize) !void {
130test "nested bitcast" {130test "nested bitcast" {
131 const S = struct {131 const S = struct {
132 fn moo(x: isize) !void {132 fn moo(x: isize) !void {
133 try expect(@intCast(isize, 42) == x);133 try expect(@as(isize, @intCast(42)) == x);
134 }134 }
135135
136 fn foo(x: isize) !void {136 fn foo(x: isize) !void {
137 try @This().moo(137 try @This().moo(
138 @bitCast(isize, if (x != 0) @bitCast(usize, x) else @bitCast(usize, x)),138 @as(isize, @bitCast(if (x != 0) @as(usize, @bitCast(x)) else @as(usize, @bitCast(x)))),
139 );139 );
140 }140 }
141 };141 };
...@@ -146,7 +146,7 @@ test "nested bitcast" {...@@ -146,7 +146,7 @@ test "nested bitcast" {
146146
147// issue #3010: compiler segfault147// issue #3010: compiler segfault
148test "bitcast literal [4]u8 param to u32" {148test "bitcast literal [4]u8 param to u32" {
149 const ip = @bitCast(u32, [_]u8{ 255, 255, 255, 255 });149 const ip = @as(u32, @bitCast([_]u8{ 255, 255, 255, 255 }));
150 try expect(ip == maxInt(u32));150 try expect(ip == maxInt(u32));
151}151}
152152
...@@ -154,7 +154,7 @@ test "bitcast generates a temporary value" {...@@ -154,7 +154,7 @@ test "bitcast generates a temporary value" {
154 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;154 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
155155
156 var y = @as(u16, 0x55AA);156 var y = @as(u16, 0x55AA);
157 const x = @bitCast(u16, @bitCast([2]u8, y));157 const x = @as(u16, @bitCast(@as([2]u8, @bitCast(y))));
158 try expect(y == x);158 try expect(y == x);
159}159}
160160
...@@ -175,7 +175,7 @@ test "@bitCast packed structs at runtime and comptime" {...@@ -175,7 +175,7 @@ test "@bitCast packed structs at runtime and comptime" {
175 const S = struct {175 const S = struct {
176 fn doTheTest() !void {176 fn doTheTest() !void {
177 var full = Full{ .number = 0x1234 };177 var full = Full{ .number = 0x1234 };
178 var two_halves = @bitCast(Divided, full);178 var two_halves = @as(Divided, @bitCast(full));
179 try expect(two_halves.half1 == 0x34);179 try expect(two_halves.half1 == 0x34);
180 try expect(two_halves.quarter3 == 0x2);180 try expect(two_halves.quarter3 == 0x2);
181 try expect(two_halves.quarter4 == 0x1);181 try expect(two_halves.quarter4 == 0x1);
...@@ -200,7 +200,7 @@ test "@bitCast extern structs at runtime and comptime" {...@@ -200,7 +200,7 @@ test "@bitCast extern structs at runtime and comptime" {
200 const S = struct {200 const S = struct {
201 fn doTheTest() !void {201 fn doTheTest() !void {
202 var full = Full{ .number = 0x1234 };202 var full = Full{ .number = 0x1234 };
203 var two_halves = @bitCast(TwoHalves, full);203 var two_halves = @as(TwoHalves, @bitCast(full));
204 switch (native_endian) {204 switch (native_endian) {
205 .Big => {205 .Big => {
206 try expect(two_halves.half1 == 0x12);206 try expect(two_halves.half1 == 0x12);
...@@ -230,8 +230,8 @@ test "bitcast packed struct to integer and back" {...@@ -230,8 +230,8 @@ test "bitcast packed struct to integer and back" {
230 const S = struct {230 const S = struct {
231 fn doTheTest() !void {231 fn doTheTest() !void {
232 var move = LevelUpMove{ .move_id = 1, .level = 2 };232 var move = LevelUpMove{ .move_id = 1, .level = 2 };
233 var v = @bitCast(u16, move);233 var v = @as(u16, @bitCast(move));
234 var back_to_a_move = @bitCast(LevelUpMove, v);234 var back_to_a_move = @as(LevelUpMove, @bitCast(v));
235 try expect(back_to_a_move.move_id == 1);235 try expect(back_to_a_move.move_id == 1);
236 try expect(back_to_a_move.level == 2);236 try expect(back_to_a_move.level == 2);
237 }237 }
...@@ -250,7 +250,7 @@ test "implicit cast to error union by returning" {...@@ -250,7 +250,7 @@ test "implicit cast to error union by returning" {
250 try expect((func(-1) catch unreachable) == maxInt(u64));250 try expect((func(-1) catch unreachable) == maxInt(u64));
251 }251 }
252 pub fn func(sz: i64) anyerror!u64 {252 pub fn func(sz: i64) anyerror!u64 {
253 return @bitCast(u64, sz);253 return @as(u64, @bitCast(sz));
254 }254 }
255 };255 };
256 try S.entry();256 try S.entry();
...@@ -261,7 +261,7 @@ test "bitcast packed struct literal to byte" {...@@ -261,7 +261,7 @@ test "bitcast packed struct literal to byte" {
261 const Foo = packed struct {261 const Foo = packed struct {
262 value: u8,262 value: u8,
263 };263 };
264 const casted = @bitCast(u8, Foo{ .value = 0xF });264 const casted = @as(u8, @bitCast(Foo{ .value = 0xF }));
265 try expect(casted == 0xf);265 try expect(casted == 0xf);
266}266}
267267
...@@ -269,7 +269,7 @@ test "comptime bitcast used in expression has the correct type" {...@@ -269,7 +269,7 @@ test "comptime bitcast used in expression has the correct type" {
269 const Foo = packed struct {269 const Foo = packed struct {
270 value: u8,270 value: u8,
271 };271 };
272 try expect(@bitCast(u8, Foo{ .value = 0xF }) == 0xf);272 try expect(@as(u8, @bitCast(Foo{ .value = 0xF })) == 0xf);
273}273}
274274
275test "bitcast passed as tuple element" {275test "bitcast passed as tuple element" {
...@@ -279,7 +279,7 @@ test "bitcast passed as tuple element" {...@@ -279,7 +279,7 @@ test "bitcast passed as tuple element" {
279 try expect(args[0] == 12.34);279 try expect(args[0] == 12.34);
280 }280 }
281 };281 };
282 try S.foo(.{@bitCast(f32, @as(u32, 0x414570A4))});282 try S.foo(.{@as(f32, @bitCast(@as(u32, 0x414570A4)))});
283}283}
284284
285test "triple level result location with bitcast sandwich passed as tuple element" {285test "triple level result location with bitcast sandwich passed as tuple element" {
...@@ -289,7 +289,7 @@ test "triple level result location with bitcast sandwich passed as tuple element...@@ -289,7 +289,7 @@ test "triple level result location with bitcast sandwich passed as tuple element
289 try expect(args[0] > 12.33 and args[0] < 12.35);289 try expect(args[0] > 12.33 and args[0] < 12.35);
290 }290 }
291 };291 };
292 try S.foo(.{@as(f64, @bitCast(f32, @as(u32, 0x414570A4)))});292 try S.foo(.{@as(f64, @as(f32, @bitCast(@as(u32, 0x414570A4))))});
293}293}
294294
295test "@bitCast packed struct of floats" {295test "@bitCast packed struct of floats" {
...@@ -318,7 +318,7 @@ test "@bitCast packed struct of floats" {...@@ -318,7 +318,7 @@ test "@bitCast packed struct of floats" {
318 const S = struct {318 const S = struct {
319 fn doTheTest() !void {319 fn doTheTest() !void {
320 var foo = Foo{};320 var foo = Foo{};
321 var v = @bitCast(Foo2, foo);321 var v = @as(Foo2, @bitCast(foo));
322 try expect(v.a == foo.a);322 try expect(v.a == foo.a);
323 try expect(v.b == foo.b);323 try expect(v.b == foo.b);
324 try expect(v.c == foo.c);324 try expect(v.c == foo.c);
...@@ -360,12 +360,12 @@ test "comptime @bitCast packed struct to int and back" {...@@ -360,12 +360,12 @@ test "comptime @bitCast packed struct to int and back" {
360360
361 // S -> Int361 // S -> Int
362 var s: S = .{};362 var s: S = .{};
363 try expectEqual(@bitCast(Int, s), comptime @bitCast(Int, S{}));363 try expectEqual(@as(Int, @bitCast(s)), comptime @as(Int, @bitCast(S{})));
364364
365 // Int -> S365 // Int -> S
366 var i: Int = 0;366 var i: Int = 0;
367 const rt_cast = @bitCast(S, i);367 const rt_cast = @as(S, @bitCast(i));
368 const ct_cast = comptime @bitCast(S, @as(Int, 0));368 const ct_cast = comptime @as(S, @bitCast(@as(Int, 0)));
369 inline for (@typeInfo(S).Struct.fields) |field| {369 inline for (@typeInfo(S).Struct.fields) |field| {
370 try expectEqual(@field(rt_cast, field.name), @field(ct_cast, field.name));370 try expectEqual(@field(rt_cast, field.name), @field(ct_cast, field.name));
371 }371 }
...@@ -381,10 +381,10 @@ test "comptime bitcast with fields following f80" {...@@ -381,10 +381,10 @@ test "comptime bitcast with fields following f80" {
381381
382 const FloatT = extern struct { f: f80, x: u128 align(16) };382 const FloatT = extern struct { f: f80, x: u128 align(16) };
383 const x: FloatT = .{ .f = 0.5, .x = 123 };383 const x: FloatT = .{ .f = 0.5, .x = 123 };
384 var x_as_uint: u256 = comptime @bitCast(u256, x);384 var x_as_uint: u256 = comptime @as(u256, @bitCast(x));
385385
386 try expect(x.f == @bitCast(FloatT, x_as_uint).f);386 try expect(x.f == @as(FloatT, @bitCast(x_as_uint)).f);
387 try expect(x.x == @bitCast(FloatT, x_as_uint).x);387 try expect(x.x == @as(FloatT, @bitCast(x_as_uint)).x);
388}388}
389389
390test "bitcast vector to integer and back" {390test "bitcast vector to integer and back" {
...@@ -398,20 +398,20 @@ test "bitcast vector to integer and back" {...@@ -398,20 +398,20 @@ test "bitcast vector to integer and back" {
398 const arr: [16]bool = [_]bool{ true, false } ++ [_]bool{true} ** 14;398 const arr: [16]bool = [_]bool{ true, false } ++ [_]bool{true} ** 14;
399 var x = @splat(16, true);399 var x = @splat(16, true);
400 x[1] = false;400 x[1] = false;
401 try expect(@bitCast(u16, x) == comptime @bitCast(u16, @as(@Vector(16, bool), arr)));401 try expect(@as(u16, @bitCast(x)) == comptime @as(u16, @bitCast(@as(@Vector(16, bool), arr))));
402}402}
403403
404fn bitCastWrapper16(x: f16) u16 {404fn bitCastWrapper16(x: f16) u16 {
405 return @bitCast(u16, x);405 return @as(u16, @bitCast(x));
406}406}
407fn bitCastWrapper32(x: f32) u32 {407fn bitCastWrapper32(x: f32) u32 {
408 return @bitCast(u32, x);408 return @as(u32, @bitCast(x));
409}409}
410fn bitCastWrapper64(x: f64) u64 {410fn bitCastWrapper64(x: f64) u64 {
411 return @bitCast(u64, x);411 return @as(u64, @bitCast(x));
412}412}
413fn bitCastWrapper128(x: f128) u128 {413fn bitCastWrapper128(x: f128) u128 {
414 return @bitCast(u128, x);414 return @as(u128, @bitCast(x));
415}415}
416test "bitcast nan float does modify signaling bit" {416test "bitcast nan float does modify signaling bit" {
417 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO417 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
...@@ -425,37 +425,37 @@ test "bitcast nan float does modify signaling bit" {...@@ -425,37 +425,37 @@ test "bitcast nan float does modify signaling bit" {
425425
426 // 16 bit426 // 16 bit
427 const snan_f16_const = math.nan_f16;427 const snan_f16_const = math.nan_f16;
428 try expectEqual(math.nan_u16, @bitCast(u16, snan_f16_const));428 try expectEqual(math.nan_u16, @as(u16, @bitCast(snan_f16_const)));
429 try expectEqual(math.nan_u16, bitCastWrapper16(snan_f16_const));429 try expectEqual(math.nan_u16, bitCastWrapper16(snan_f16_const));
430430
431 var snan_f16_var = math.nan_f16;431 var snan_f16_var = math.nan_f16;
432 try expectEqual(math.nan_u16, @bitCast(u16, snan_f16_var));432 try expectEqual(math.nan_u16, @as(u16, @bitCast(snan_f16_var)));
433 try expectEqual(math.nan_u16, bitCastWrapper16(snan_f16_var));433 try expectEqual(math.nan_u16, bitCastWrapper16(snan_f16_var));
434434
435 // 32 bit435 // 32 bit
436 const snan_f32_const = math.nan_f32;436 const snan_f32_const = math.nan_f32;
437 try expectEqual(math.nan_u32, @bitCast(u32, snan_f32_const));437 try expectEqual(math.nan_u32, @as(u32, @bitCast(snan_f32_const)));
438 try expectEqual(math.nan_u32, bitCastWrapper32(snan_f32_const));438 try expectEqual(math.nan_u32, bitCastWrapper32(snan_f32_const));
439439
440 var snan_f32_var = math.nan_f32;440 var snan_f32_var = math.nan_f32;
441 try expectEqual(math.nan_u32, @bitCast(u32, snan_f32_var));441 try expectEqual(math.nan_u32, @as(u32, @bitCast(snan_f32_var)));
442 try expectEqual(math.nan_u32, bitCastWrapper32(snan_f32_var));442 try expectEqual(math.nan_u32, bitCastWrapper32(snan_f32_var));
443443
444 // 64 bit444 // 64 bit
445 const snan_f64_const = math.nan_f64;445 const snan_f64_const = math.nan_f64;
446 try expectEqual(math.nan_u64, @bitCast(u64, snan_f64_const));446 try expectEqual(math.nan_u64, @as(u64, @bitCast(snan_f64_const)));
447 try expectEqual(math.nan_u64, bitCastWrapper64(snan_f64_const));447 try expectEqual(math.nan_u64, bitCastWrapper64(snan_f64_const));
448448
449 var snan_f64_var = math.nan_f64;449 var snan_f64_var = math.nan_f64;
450 try expectEqual(math.nan_u64, @bitCast(u64, snan_f64_var));450 try expectEqual(math.nan_u64, @as(u64, @bitCast(snan_f64_var)));
451 try expectEqual(math.nan_u64, bitCastWrapper64(snan_f64_var));451 try expectEqual(math.nan_u64, bitCastWrapper64(snan_f64_var));
452452
453 // 128 bit453 // 128 bit
454 const snan_f128_const = math.nan_f128;454 const snan_f128_const = math.nan_f128;
455 try expectEqual(math.nan_u128, @bitCast(u128, snan_f128_const));455 try expectEqual(math.nan_u128, @as(u128, @bitCast(snan_f128_const)));
456 try expectEqual(math.nan_u128, bitCastWrapper128(snan_f128_const));456 try expectEqual(math.nan_u128, bitCastWrapper128(snan_f128_const));
457457
458 var snan_f128_var = math.nan_f128;458 var snan_f128_var = math.nan_f128;
459 try expectEqual(math.nan_u128, @bitCast(u128, snan_f128_var));459 try expectEqual(math.nan_u128, @as(u128, @bitCast(snan_f128_var)));
460 try expectEqual(math.nan_u128, bitCastWrapper128(snan_f128_var));460 try expectEqual(math.nan_u128, bitCastWrapper128(snan_f128_var));
461}461}
test/behavior/bitreverse.zig+14-14
...@@ -62,20 +62,20 @@ fn testBitReverse() !void {...@@ -62,20 +62,20 @@ fn testBitReverse() !void {
6262
63 // using comptime_ints, signed, positive63 // using comptime_ints, signed, positive
64 try expect(@bitReverse(@as(u8, 0)) == 0);64 try expect(@bitReverse(@as(u8, 0)) == 0);
65 try expect(@bitReverse(@bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49)));65 try expect(@bitReverse(@as(i8, @bitCast(@as(u8, 0x92)))) == @as(i8, @bitCast(@as(u8, 0x49))));
66 try expect(@bitReverse(@bitCast(i16, @as(u16, 0x1234))) == @bitCast(i16, @as(u16, 0x2c48)));66 try expect(@bitReverse(@as(i16, @bitCast(@as(u16, 0x1234)))) == @as(i16, @bitCast(@as(u16, 0x2c48))));
67 try expect(@bitReverse(@bitCast(i24, @as(u24, 0x123456))) == @bitCast(i24, @as(u24, 0x6a2c48)));67 try expect(@bitReverse(@as(i24, @bitCast(@as(u24, 0x123456)))) == @as(i24, @bitCast(@as(u24, 0x6a2c48))));
68 try expect(@bitReverse(@bitCast(i24, @as(u24, 0x12345f))) == @bitCast(i24, @as(u24, 0xfa2c48)));68 try expect(@bitReverse(@as(i24, @bitCast(@as(u24, 0x12345f)))) == @as(i24, @bitCast(@as(u24, 0xfa2c48))));
69 try expect(@bitReverse(@bitCast(i24, @as(u24, 0xf23456))) == @bitCast(i24, @as(u24, 0x6a2c4f)));69 try expect(@bitReverse(@as(i24, @bitCast(@as(u24, 0xf23456)))) == @as(i24, @bitCast(@as(u24, 0x6a2c4f))));
70 try expect(@bitReverse(@bitCast(i32, @as(u32, 0x12345678))) == @bitCast(i32, @as(u32, 0x1e6a2c48)));70 try expect(@bitReverse(@as(i32, @bitCast(@as(u32, 0x12345678)))) == @as(i32, @bitCast(@as(u32, 0x1e6a2c48))));
71 try expect(@bitReverse(@bitCast(i32, @as(u32, 0xf2345678))) == @bitCast(i32, @as(u32, 0x1e6a2c4f)));71 try expect(@bitReverse(@as(i32, @bitCast(@as(u32, 0xf2345678)))) == @as(i32, @bitCast(@as(u32, 0x1e6a2c4f))));
72 try expect(@bitReverse(@bitCast(i32, @as(u32, 0x1234567f))) == @bitCast(i32, @as(u32, 0xfe6a2c48)));72 try expect(@bitReverse(@as(i32, @bitCast(@as(u32, 0x1234567f)))) == @as(i32, @bitCast(@as(u32, 0xfe6a2c48))));
73 try expect(@bitReverse(@bitCast(i40, @as(u40, 0x123456789a))) == @bitCast(i40, @as(u40, 0x591e6a2c48)));73 try expect(@bitReverse(@as(i40, @bitCast(@as(u40, 0x123456789a)))) == @as(i40, @bitCast(@as(u40, 0x591e6a2c48))));
74 try expect(@bitReverse(@bitCast(i48, @as(u48, 0x123456789abc))) == @bitCast(i48, @as(u48, 0x3d591e6a2c48)));74 try expect(@bitReverse(@as(i48, @bitCast(@as(u48, 0x123456789abc)))) == @as(i48, @bitCast(@as(u48, 0x3d591e6a2c48))));
75 try expect(@bitReverse(@bitCast(i56, @as(u56, 0x123456789abcde))) == @bitCast(i56, @as(u56, 0x7b3d591e6a2c48)));75 try expect(@bitReverse(@as(i56, @bitCast(@as(u56, 0x123456789abcde)))) == @as(i56, @bitCast(@as(u56, 0x7b3d591e6a2c48))));
76 try expect(@bitReverse(@bitCast(i64, @as(u64, 0x123456789abcdef1))) == @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48)));76 try expect(@bitReverse(@as(i64, @bitCast(@as(u64, 0x123456789abcdef1)))) == @as(i64, @bitCast(@as(u64, 0x8f7b3d591e6a2c48))));
77 try expect(@bitReverse(@bitCast(i96, @as(u96, 0x123456789abcdef111213141))) == @bitCast(i96, @as(u96, 0x828c84888f7b3d591e6a2c48)));77 try expect(@bitReverse(@as(i96, @bitCast(@as(u96, 0x123456789abcdef111213141)))) == @as(i96, @bitCast(@as(u96, 0x828c84888f7b3d591e6a2c48))));
78 try expect(@bitReverse(@bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48)));78 try expect(@bitReverse(@as(i128, @bitCast(@as(u128, 0x123456789abcdef11121314151617181)))) == @as(i128, @bitCast(@as(u128, 0x818e868a828c84888f7b3d591e6a2c48))));
7979
80 // using signed, negative. Compare to runtime ints returned from llvm.80 // using signed, negative. Compare to runtime ints returned from llvm.
81 var neg8: i8 = -18;81 var neg8: i8 = -18;
test/behavior/bool.zig+4-4
...@@ -15,8 +15,8 @@ test "cast bool to int" {...@@ -15,8 +15,8 @@ test "cast bool to int" {
15 const f = false;15 const f = false;
16 try expectEqual(@as(u32, 1), @intFromBool(t));16 try expectEqual(@as(u32, 1), @intFromBool(t));
17 try expectEqual(@as(u32, 0), @intFromBool(f));17 try expectEqual(@as(u32, 0), @intFromBool(f));
18 try expectEqual(-1, @bitCast(i1, @intFromBool(t)));18 try expectEqual(-1, @as(i1, @bitCast(@intFromBool(t))));
19 try expectEqual(0, @bitCast(i1, @intFromBool(f)));19 try expectEqual(0, @as(i1, @bitCast(@intFromBool(f))));
20 try expectEqual(u1, @TypeOf(@intFromBool(t)));20 try expectEqual(u1, @TypeOf(@intFromBool(t)));
21 try expectEqual(u1, @TypeOf(@intFromBool(f)));21 try expectEqual(u1, @TypeOf(@intFromBool(f)));
22 try nonConstCastIntFromBool(t, f);22 try nonConstCastIntFromBool(t, f);
...@@ -25,8 +25,8 @@ test "cast bool to int" {...@@ -25,8 +25,8 @@ test "cast bool to int" {
25fn nonConstCastIntFromBool(t: bool, f: bool) !void {25fn nonConstCastIntFromBool(t: bool, f: bool) !void {
26 try expectEqual(@as(u32, 1), @intFromBool(t));26 try expectEqual(@as(u32, 1), @intFromBool(t));
27 try expectEqual(@as(u32, 0), @intFromBool(f));27 try expectEqual(@as(u32, 0), @intFromBool(f));
28 try expectEqual(@as(i1, -1), @bitCast(i1, @intFromBool(t)));28 try expectEqual(@as(i1, -1), @as(i1, @bitCast(@intFromBool(t))));
29 try expectEqual(@as(i1, 0), @bitCast(i1, @intFromBool(f)));29 try expectEqual(@as(i1, 0), @as(i1, @bitCast(@intFromBool(f))));
30 try expectEqual(u1, @TypeOf(@intFromBool(t)));30 try expectEqual(u1, @TypeOf(@intFromBool(t)));
31 try expectEqual(u1, @TypeOf(@intFromBool(f)));31 try expectEqual(u1, @TypeOf(@intFromBool(f)));
32}32}
test/behavior/bugs/11995.zig+1-1
...@@ -25,7 +25,7 @@ test {...@@ -25,7 +25,7 @@ test {
25 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;25 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
2626
27 var string: [5]u8 = "hello".*;27 var string: [5]u8 = "hello".*;
28 const arg_data = wuffs_base__slice_u8{ .ptr = @ptrCast([*c]u8, &string), .len = string.len };28 const arg_data = wuffs_base__slice_u8{ .ptr = @as([*c]u8, @ptrCast(&string)), .len = string.len };
29 var arg_meta = wuffs_base__io_buffer_meta{ .wi = 1, .ri = 2, .pos = 3, .closed = true };29 var arg_meta = wuffs_base__io_buffer_meta{ .wi = 1, .ri = 2, .pos = 3, .closed = true };
30 wuffs_base__make_io_buffer(arg_data, &arg_meta);30 wuffs_base__make_io_buffer(arg_data, &arg_meta);
31 try std.testing.expectEqualStrings("wello", arg_data.ptr[0..arg_data.len]);31 try std.testing.expectEqualStrings("wello", arg_data.ptr[0..arg_data.len]);
test/behavior/bugs/12051.zig+2-2
...@@ -30,8 +30,8 @@ const Y = struct {...@@ -30,8 +30,8 @@ const Y = struct {
30 return .{30 return .{
31 .a = 0,31 .a = 0,
32 .b = false,32 .b = false,
33 .c = @bitCast(Z, @as(u32, 0)),33 .c = @as(Z, @bitCast(@as(u32, 0))),
34 .d = @bitCast(Z, @as(u32, 0)),34 .d = @as(Z, @bitCast(@as(u32, 0))),
35 };35 };
36 }36 }
37};37};
test/behavior/bugs/12119.zig+1-1
...@@ -12,6 +12,6 @@ test {...@@ -12,6 +12,6 @@ test {
12 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;12 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1313
14 const zerox32: u8x32 = [_]u8{0} ** 32;14 const zerox32: u8x32 = [_]u8{0} ** 32;
15 const bigsum: u32x8 = @bitCast(u32x8, zerox32);15 const bigsum: u32x8 = @as(u32x8, @bitCast(zerox32));
16 try std.testing.expectEqual(0, @reduce(.Add, bigsum));16 try std.testing.expectEqual(0, @reduce(.Add, bigsum));
17}17}
test/behavior/bugs/12450.zig+1-1
...@@ -16,7 +16,7 @@ test {...@@ -16,7 +16,7 @@ test {
16 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO16 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
17 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;17 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1818
19 var f1: *align(16) Foo = @alignCast(16, @ptrCast(*align(1) Foo, &buffer[0]));19 var f1: *align(16) Foo = @alignCast(@as(*align(1) Foo, @ptrCast(&buffer[0])));
20 try expect(@typeInfo(@TypeOf(f1)).Pointer.alignment == 16);20 try expect(@typeInfo(@TypeOf(f1)).Pointer.alignment == 16);
21 try expect(@intFromPtr(f1) == @intFromPtr(&f1.a));21 try expect(@intFromPtr(f1) == @intFromPtr(&f1.a));
22 try expect(@typeInfo(@TypeOf(&f1.a)).Pointer.alignment == 16);22 try expect(@typeInfo(@TypeOf(&f1.a)).Pointer.alignment == 16);
test/behavior/bugs/12723.zig+1-1
...@@ -3,6 +3,6 @@ const expect = @import("std").testing.expect;...@@ -3,6 +3,6 @@ const expect = @import("std").testing.expect;
3test "Non-exhaustive enum backed by comptime_int" {3test "Non-exhaustive enum backed by comptime_int" {
4 const E = enum(comptime_int) { a, b, c, _ };4 const E = enum(comptime_int) { a, b, c, _ };
5 comptime var e: E = .a;5 comptime var e: E = .a;
6 e = @enumFromInt(E, 378089457309184723749);6 e = @as(E, @enumFromInt(378089457309184723749));
7 try expect(@intFromEnum(e) == 378089457309184723749);7 try expect(@intFromEnum(e) == 378089457309184723749);
8}8}
test/behavior/bugs/13664.zig+1-1
...@@ -21,7 +21,7 @@ test {...@@ -21,7 +21,7 @@ test {
2121
22 const timestamp: i64 = value();22 const timestamp: i64 = value();
23 const id = ID{ .fields = Fields{23 const id = ID{ .fields = Fields{
24 .timestamp = @intCast(u50, timestamp),24 .timestamp = @as(u50, @intCast(timestamp)),
25 .random_bits = 420,25 .random_bits = 420,
26 } };26 } };
27 try std.testing.expect((ID{ .value = id.value }).fields.timestamp == timestamp);27 try std.testing.expect((ID{ .value = id.value }).fields.timestamp == timestamp);
test/behavior/bugs/421.zig+1-1
...@@ -16,6 +16,6 @@ fn testBitCastArray() !void {...@@ -16,6 +16,6 @@ fn testBitCastArray() !void {
16}16}
1717
18fn extractOne64(a: u128) u64 {18fn extractOne64(a: u128) u64 {
19 const x = @bitCast([2]u64, a);19 const x = @as([2]u64, @bitCast(a));
20 return x[1];20 return x[1];
21}21}
test/behavior/bugs/6781.zig+4-4
...@@ -23,7 +23,7 @@ pub const JournalHeader = packed struct {...@@ -23,7 +23,7 @@ pub const JournalHeader = packed struct {
2323
24 var target: [32]u8 = undefined;24 var target: [32]u8 = undefined;
25 std.crypto.hash.Blake3.hash(entry[checksum_offset + checksum_size ..], target[0..], .{});25 std.crypto.hash.Blake3.hash(entry[checksum_offset + checksum_size ..], target[0..], .{});
26 return @bitCast(u128, target[0..checksum_size].*);26 return @as(u128, @bitCast(target[0..checksum_size].*));
27 }27 }
2828
29 pub fn calculate_hash_chain_root(self: *const JournalHeader) u128 {29 pub fn calculate_hash_chain_root(self: *const JournalHeader) u128 {
...@@ -42,16 +42,16 @@ pub const JournalHeader = packed struct {...@@ -42,16 +42,16 @@ pub const JournalHeader = packed struct {
4242
43 assert(prev_hash_chain_root_offset + prev_hash_chain_root_size == checksum_offset);43 assert(prev_hash_chain_root_offset + prev_hash_chain_root_size == checksum_offset);
4444
45 const header = @bitCast([@sizeOf(JournalHeader)]u8, self.*);45 const header = @as([@sizeOf(JournalHeader)]u8, @bitCast(self.*));
46 const source = header[prev_hash_chain_root_offset .. checksum_offset + checksum_size];46 const source = header[prev_hash_chain_root_offset .. checksum_offset + checksum_size];
47 assert(source.len == prev_hash_chain_root_size + checksum_size);47 assert(source.len == prev_hash_chain_root_size + checksum_size);
48 var target: [32]u8 = undefined;48 var target: [32]u8 = undefined;
49 std.crypto.hash.Blake3.hash(source, target[0..], .{});49 std.crypto.hash.Blake3.hash(source, target[0..], .{});
50 if (segfault) {50 if (segfault) {
51 return @bitCast(u128, target[0..hash_chain_root_size].*);51 return @as(u128, @bitCast(target[0..hash_chain_root_size].*));
52 } else {52 } else {
53 var array = target[0..hash_chain_root_size].*;53 var array = target[0..hash_chain_root_size].*;
54 return @bitCast(u128, array);54 return @as(u128, @bitCast(array));
55 }55 }
56 }56 }
5757
test/behavior/bugs/718.zig+1-1
...@@ -15,7 +15,7 @@ test "zero keys with @memset" {...@@ -15,7 +15,7 @@ test "zero keys with @memset" {
15 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO15 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
16 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;16 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1717
18 @memset(@ptrCast([*]u8, &keys)[0..@sizeOf(@TypeOf(keys))], 0);18 @memset(@as([*]u8, @ptrCast(&keys))[0..@sizeOf(@TypeOf(keys))], 0);
19 try expect(!keys.up);19 try expect(!keys.up);
20 try expect(!keys.down);20 try expect(!keys.down);
21 try expect(!keys.left);21 try expect(!keys.left);
test/behavior/bugs/726.zig+2-2
...@@ -8,7 +8,7 @@ test "@ptrCast from const to nullable" {...@@ -8,7 +8,7 @@ test "@ptrCast from const to nullable" {
8 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;8 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
99
10 const c: u8 = 4;10 const c: u8 = 4;
11 var x: ?*const u8 = @ptrCast(?*const u8, &c);11 var x: ?*const u8 = @as(?*const u8, @ptrCast(&c));
12 try expect(x.?.* == 4);12 try expect(x.?.* == 4);
13}13}
1414
...@@ -21,6 +21,6 @@ test "@ptrCast from var in empty struct to nullable" {...@@ -21,6 +21,6 @@ test "@ptrCast from var in empty struct to nullable" {
21 const container = struct {21 const container = struct {
22 var c: u8 = 4;22 var c: u8 = 4;
23 };23 };
24 var x: ?*const u8 = @ptrCast(?*const u8, &container.c);24 var x: ?*const u8 = @as(?*const u8, @ptrCast(&container.c));
25 try expect(x.?.* == 4);25 try expect(x.?.* == 4);
26}26}
test/behavior/builtin_functions_returning_void_or_noreturn.zig+2-2
...@@ -17,8 +17,8 @@ test {...@@ -17,8 +17,8 @@ test {
17 try testing.expectEqual(void, @TypeOf(@breakpoint()));17 try testing.expectEqual(void, @TypeOf(@breakpoint()));
18 try testing.expectEqual({}, @export(x, .{ .name = "x" }));18 try testing.expectEqual({}, @export(x, .{ .name = "x" }));
19 try testing.expectEqual({}, @fence(.Acquire));19 try testing.expectEqual({}, @fence(.Acquire));
20 try testing.expectEqual({}, @memcpy(@ptrFromInt([*]u8, 1)[0..0], @ptrFromInt([*]u8, 1)[0..0]));20 try testing.expectEqual({}, @memcpy(@as([*]u8, @ptrFromInt(1))[0..0], @as([*]u8, @ptrFromInt(1))[0..0]));
21 try testing.expectEqual({}, @memset(@ptrFromInt([*]u8, 1)[0..0], undefined));21 try testing.expectEqual({}, @memset(@as([*]u8, @ptrFromInt(1))[0..0], undefined));
22 try testing.expectEqual(noreturn, @TypeOf(if (true) @panic("") else {}));22 try testing.expectEqual(noreturn, @TypeOf(if (true) @panic("") else {}));
23 try testing.expectEqual({}, @prefetch(&val, .{}));23 try testing.expectEqual({}, @prefetch(&val, .{}));
24 try testing.expectEqual({}, @setAlignStack(16));24 try testing.expectEqual({}, @setAlignStack(16));
test/behavior/byteswap.zig+16-16
...@@ -16,13 +16,13 @@ test "@byteSwap integers" {...@@ -16,13 +16,13 @@ test "@byteSwap integers" {
16 try t(u8, 0x12, 0x12);16 try t(u8, 0x12, 0x12);
17 try t(u16, 0x1234, 0x3412);17 try t(u16, 0x1234, 0x3412);
18 try t(u24, 0x123456, 0x563412);18 try t(u24, 0x123456, 0x563412);
19 try t(i24, @bitCast(i24, @as(u24, 0xf23456)), 0x5634f2);19 try t(i24, @as(i24, @bitCast(@as(u24, 0xf23456))), 0x5634f2);
20 try t(i24, 0x1234f6, @bitCast(i24, @as(u24, 0xf63412)));20 try t(i24, 0x1234f6, @as(i24, @bitCast(@as(u24, 0xf63412))));
21 try t(u32, 0x12345678, 0x78563412);21 try t(u32, 0x12345678, 0x78563412);
22 try t(i32, @bitCast(i32, @as(u32, 0xf2345678)), 0x785634f2);22 try t(i32, @as(i32, @bitCast(@as(u32, 0xf2345678))), 0x785634f2);
23 try t(i32, 0x123456f8, @bitCast(i32, @as(u32, 0xf8563412)));23 try t(i32, 0x123456f8, @as(i32, @bitCast(@as(u32, 0xf8563412))));
24 try t(u40, 0x123456789a, 0x9a78563412);24 try t(u40, 0x123456789a, 0x9a78563412);
25 try t(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412)));25 try t(i48, 0x123456789abc, @as(i48, @bitCast(@as(u48, 0xbc9a78563412))));
26 try t(u56, 0x123456789abcde, 0xdebc9a78563412);26 try t(u56, 0x123456789abcde, 0xdebc9a78563412);
27 try t(u64, 0x123456789abcdef1, 0xf1debc9a78563412);27 try t(u64, 0x123456789abcdef1, 0xf1debc9a78563412);
28 try t(u88, 0x123456789abcdef1112131, 0x312111f1debc9a78563412);28 try t(u88, 0x123456789abcdef1112131, 0x312111f1debc9a78563412);
...@@ -31,19 +31,19 @@ test "@byteSwap integers" {...@@ -31,19 +31,19 @@ test "@byteSwap integers" {
3131
32 try t(u0, @as(u0, 0), 0);32 try t(u0, @as(u0, 0), 0);
33 try t(i8, @as(i8, -50), -50);33 try t(i8, @as(i8, -50), -50);
34 try t(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412)));34 try t(i16, @as(i16, @bitCast(@as(u16, 0x1234))), @as(i16, @bitCast(@as(u16, 0x3412))));
35 try t(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x563412)));35 try t(i24, @as(i24, @bitCast(@as(u24, 0x123456))), @as(i24, @bitCast(@as(u24, 0x563412))));
36 try t(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412)));36 try t(i32, @as(i32, @bitCast(@as(u32, 0x12345678))), @as(i32, @bitCast(@as(u32, 0x78563412))));
37 try t(u40, @bitCast(i40, @as(u40, 0x123456789a)), @as(u40, 0x9a78563412));37 try t(u40, @as(i40, @bitCast(@as(u40, 0x123456789a))), @as(u40, 0x9a78563412));
38 try t(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412)));38 try t(i48, @as(i48, @bitCast(@as(u48, 0x123456789abc))), @as(i48, @bitCast(@as(u48, 0xbc9a78563412))));
39 try t(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0xdebc9a78563412)));39 try t(i56, @as(i56, @bitCast(@as(u56, 0x123456789abcde))), @as(i56, @bitCast(@as(u56, 0xdebc9a78563412))));
40 try t(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412)));40 try t(i64, @as(i64, @bitCast(@as(u64, 0x123456789abcdef1))), @as(i64, @bitCast(@as(u64, 0xf1debc9a78563412))));
41 try t(i88, @bitCast(i88, @as(u88, 0x123456789abcdef1112131)), @bitCast(i88, @as(u88, 0x312111f1debc9a78563412)));41 try t(i88, @as(i88, @bitCast(@as(u88, 0x123456789abcdef1112131))), @as(i88, @bitCast(@as(u88, 0x312111f1debc9a78563412))));
42 try t(i96, @bitCast(i96, @as(u96, 0x123456789abcdef111213141)), @bitCast(i96, @as(u96, 0x41312111f1debc9a78563412)));42 try t(i96, @as(i96, @bitCast(@as(u96, 0x123456789abcdef111213141))), @as(i96, @bitCast(@as(u96, 0x41312111f1debc9a78563412))));
43 try t(43 try t(
44 i128,44 i128,
45 @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)),45 @as(i128, @bitCast(@as(u128, 0x123456789abcdef11121314151617181))),
46 @bitCast(i128, @as(u128, 0x8171615141312111f1debc9a78563412)),46 @as(i128, @bitCast(@as(u128, 0x8171615141312111f1debc9a78563412))),
47 );47 );
48 }48 }
49 fn t(comptime I: type, input: I, expected_output: I) !void {49 fn t(comptime I: type, input: I, expected_output: I) !void {
test/behavior/call.zig+1-1
...@@ -368,7 +368,7 @@ test "Enum constructed by @Type passed as generic argument" {...@@ -368,7 +368,7 @@ test "Enum constructed by @Type passed as generic argument" {
368 }368 }
369 };369 };
370 inline for (@typeInfo(S.E).Enum.fields, 0..) |_, i| {370 inline for (@typeInfo(S.E).Enum.fields, 0..) |_, i| {
371 try S.foo(@enumFromInt(S.E, i), i);371 try S.foo(@as(S.E, @enumFromInt(i)), i);
372 }372 }
373}373}
374374
test/behavior/cast.zig+60-60
...@@ -10,13 +10,13 @@ const native_endian = builtin.target.cpu.arch.endian();...@@ -10,13 +10,13 @@ const native_endian = builtin.target.cpu.arch.endian();
1010
11test "int to ptr cast" {11test "int to ptr cast" {
12 const x = @as(usize, 13);12 const x = @as(usize, 13);
13 const y = @ptrFromInt(*u8, x);13 const y = @as(*u8, @ptrFromInt(x));
14 const z = @intFromPtr(y);14 const z = @intFromPtr(y);
15 try expect(z == 13);15 try expect(z == 13);
16}16}
1717
18test "integer literal to pointer cast" {18test "integer literal to pointer cast" {
19 const vga_mem = @ptrFromInt(*u16, 0xB8000);19 const vga_mem = @as(*u16, @ptrFromInt(0xB8000));
20 try expect(@intFromPtr(vga_mem) == 0xB8000);20 try expect(@intFromPtr(vga_mem) == 0xB8000);
21}21}
2222
...@@ -52,7 +52,7 @@ fn testResolveUndefWithInt(b: bool, x: i32) !void {...@@ -52,7 +52,7 @@ fn testResolveUndefWithInt(b: bool, x: i32) !void {
52}52}
5353
54test "@intCast to comptime_int" {54test "@intCast to comptime_int" {
55 try expect(@intCast(comptime_int, 0) == 0);55 try expect(@as(comptime_int, @intCast(0)) == 0);
56}56}
5757
58test "implicit cast comptime numbers to any type when the value fits" {58test "implicit cast comptime numbers to any type when the value fits" {
...@@ -68,29 +68,29 @@ test "implicit cast comptime_int to comptime_float" {...@@ -68,29 +68,29 @@ test "implicit cast comptime_int to comptime_float" {
6868
69test "comptime_int @floatFromInt" {69test "comptime_int @floatFromInt" {
70 {70 {
71 const result = @floatFromInt(f16, 1234);71 const result = @as(f16, @floatFromInt(1234));
72 try expect(@TypeOf(result) == f16);72 try expect(@TypeOf(result) == f16);
73 try expect(result == 1234.0);73 try expect(result == 1234.0);
74 }74 }
75 {75 {
76 const result = @floatFromInt(f32, 1234);76 const result = @as(f32, @floatFromInt(1234));
77 try expect(@TypeOf(result) == f32);77 try expect(@TypeOf(result) == f32);
78 try expect(result == 1234.0);78 try expect(result == 1234.0);
79 }79 }
80 {80 {
81 const result = @floatFromInt(f64, 1234);81 const result = @as(f64, @floatFromInt(1234));
82 try expect(@TypeOf(result) == f64);82 try expect(@TypeOf(result) == f64);
83 try expect(result == 1234.0);83 try expect(result == 1234.0);
84 }84 }
8585
86 {86 {
87 const result = @floatFromInt(f128, 1234);87 const result = @as(f128, @floatFromInt(1234));
88 try expect(@TypeOf(result) == f128);88 try expect(@TypeOf(result) == f128);
89 try expect(result == 1234.0);89 try expect(result == 1234.0);
90 }90 }
91 // big comptime_int (> 64 bits) to f128 conversion91 // big comptime_int (> 64 bits) to f128 conversion
92 {92 {
93 const result = @floatFromInt(f128, 0x1_0000_0000_0000_0000);93 const result = @as(f128, @floatFromInt(0x1_0000_0000_0000_0000));
94 try expect(@TypeOf(result) == f128);94 try expect(@TypeOf(result) == f128);
95 try expect(result == 0x1_0000_0000_0000_0000.0);95 try expect(result == 0x1_0000_0000_0000_0000.0);
96 }96 }
...@@ -107,8 +107,8 @@ test "@floatFromInt" {...@@ -107,8 +107,8 @@ test "@floatFromInt" {
107 }107 }
108108
109 fn testIntToFloat(k: i32) !void {109 fn testIntToFloat(k: i32) !void {
110 const f = @floatFromInt(f32, k);110 const f = @as(f32, @floatFromInt(k));
111 const i = @intFromFloat(i32, f);111 const i = @as(i32, @intFromFloat(f));
112 try expect(i == k);112 try expect(i == k);
113 }113 }
114 };114 };
...@@ -131,8 +131,8 @@ test "@floatFromInt(f80)" {...@@ -131,8 +131,8 @@ test "@floatFromInt(f80)" {
131131
132 fn testIntToFloat(comptime Int: type, k: Int) !void {132 fn testIntToFloat(comptime Int: type, k: Int) !void {
133 @setRuntimeSafety(false); // TODO133 @setRuntimeSafety(false); // TODO
134 const f = @floatFromInt(f80, k);134 const f = @as(f80, @floatFromInt(k));
135 const i = @intFromFloat(Int, f);135 const i = @as(Int, @intFromFloat(f));
136 try expect(i == k);136 try expect(i == k);
137 }137 }
138 };138 };
...@@ -165,7 +165,7 @@ test "@intFromFloat" {...@@ -165,7 +165,7 @@ test "@intFromFloat" {
165fn testIntFromFloats() !void {165fn testIntFromFloats() !void {
166 const x = @as(i32, 1e4);166 const x = @as(i32, 1e4);
167 try expect(x == 10000);167 try expect(x == 10000);
168 const y = @intFromFloat(i32, @as(f32, 1e4));168 const y = @as(i32, @intFromFloat(@as(f32, 1e4)));
169 try expect(y == 10000);169 try expect(y == 10000);
170 try expectIntFromFloat(f32, 255.1, u8, 255);170 try expectIntFromFloat(f32, 255.1, u8, 255);
171 try expectIntFromFloat(f32, 127.2, i8, 127);171 try expectIntFromFloat(f32, 127.2, i8, 127);
...@@ -173,7 +173,7 @@ fn testIntFromFloats() !void {...@@ -173,7 +173,7 @@ fn testIntFromFloats() !void {
173}173}
174174
175fn expectIntFromFloat(comptime F: type, f: F, comptime I: type, i: I) !void {175fn expectIntFromFloat(comptime F: type, f: F, comptime I: type, i: I) !void {
176 try expect(@intFromFloat(I, f) == i);176 try expect(@as(I, @intFromFloat(f)) == i);
177}177}
178178
179test "implicitly cast indirect pointer to maybe-indirect pointer" {179test "implicitly cast indirect pointer to maybe-indirect pointer" {
...@@ -208,29 +208,29 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {...@@ -208,29 +208,29 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
208}208}
209209
210test "@intCast comptime_int" {210test "@intCast comptime_int" {
211 const result = @intCast(i32, 1234);211 const result = @as(i32, @intCast(1234));
212 try expect(@TypeOf(result) == i32);212 try expect(@TypeOf(result) == i32);
213 try expect(result == 1234);213 try expect(result == 1234);
214}214}
215215
216test "@floatCast comptime_int and comptime_float" {216test "@floatCast comptime_int and comptime_float" {
217 {217 {
218 const result = @floatCast(f16, 1234);218 const result = @as(f16, @floatCast(1234));
219 try expect(@TypeOf(result) == f16);219 try expect(@TypeOf(result) == f16);
220 try expect(result == 1234.0);220 try expect(result == 1234.0);
221 }221 }
222 {222 {
223 const result = @floatCast(f16, 1234.0);223 const result = @as(f16, @floatCast(1234.0));
224 try expect(@TypeOf(result) == f16);224 try expect(@TypeOf(result) == f16);
225 try expect(result == 1234.0);225 try expect(result == 1234.0);
226 }226 }
227 {227 {
228 const result = @floatCast(f32, 1234);228 const result = @as(f32, @floatCast(1234));
229 try expect(@TypeOf(result) == f32);229 try expect(@TypeOf(result) == f32);
230 try expect(result == 1234.0);230 try expect(result == 1234.0);
231 }231 }
232 {232 {
233 const result = @floatCast(f32, 1234.0);233 const result = @as(f32, @floatCast(1234.0));
234 try expect(@TypeOf(result) == f32);234 try expect(@TypeOf(result) == f32);
235 try expect(result == 1234.0);235 try expect(result == 1234.0);
236 }236 }
...@@ -276,21 +276,21 @@ test "*usize to *void" {...@@ -276,21 +276,21 @@ test "*usize to *void" {
276 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;276 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
277277
278 var i = @as(usize, 0);278 var i = @as(usize, 0);
279 var v = @ptrCast(*void, &i);279 var v = @as(*void, @ptrCast(&i));
280 v.* = {};280 v.* = {};
281}281}
282282
283test "@enumFromInt passed a comptime_int to an enum with one item" {283test "@enumFromInt passed a comptime_int to an enum with one item" {
284 const E = enum { A };284 const E = enum { A };
285 const x = @enumFromInt(E, 0);285 const x = @as(E, @enumFromInt(0));
286 try expect(x == E.A);286 try expect(x == E.A);
287}287}
288288
289test "@intCast to u0 and use the result" {289test "@intCast to u0 and use the result" {
290 const S = struct {290 const S = struct {
291 fn doTheTest(zero: u1, one: u1, bigzero: i32) !void {291 fn doTheTest(zero: u1, one: u1, bigzero: i32) !void {
292 try expect((one << @intCast(u0, bigzero)) == 1);292 try expect((one << @as(u0, @intCast(bigzero))) == 1);
293 try expect((zero << @intCast(u0, bigzero)) == 0);293 try expect((zero << @as(u0, @intCast(bigzero))) == 0);
294 }294 }
295 };295 };
296 try S.doTheTest(0, 1, 0);296 try S.doTheTest(0, 1, 0);
...@@ -605,7 +605,7 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" {...@@ -605,7 +605,7 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
605605
606 const window_name = [1][*]const u8{"window name"};606 const window_name = [1][*]const u8{"window name"};
607 const x: [*]const ?[*]const u8 = &window_name;607 const x: [*]const ?[*]const u8 = &window_name;
608 try expect(mem.eql(u8, std.mem.sliceTo(@ptrCast([*:0]const u8, x[0].?), 0), "window name"));608 try expect(mem.eql(u8, std.mem.sliceTo(@as([*:0]const u8, @ptrCast(x[0].?)), 0), "window name"));
609}609}
610610
611test "vector casts" {611test "vector casts" {
...@@ -625,9 +625,9 @@ test "vector casts" {...@@ -625,9 +625,9 @@ test "vector casts" {
625 var up3 = @as(@Vector(2, u64), up0);625 var up3 = @as(@Vector(2, u64), up0);
626 // Downcast (safety-checked)626 // Downcast (safety-checked)
627 var down0 = up3;627 var down0 = up3;
628 var down1 = @intCast(@Vector(2, u32), down0);628 var down1 = @as(@Vector(2, u32), @intCast(down0));
629 var down2 = @intCast(@Vector(2, u16), down0);629 var down2 = @as(@Vector(2, u16), @intCast(down0));
630 var down3 = @intCast(@Vector(2, u8), down0);630 var down3 = @as(@Vector(2, u8), @intCast(down0));
631631
632 try expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa }));632 try expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa }));
633 try expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa }));633 try expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa }));
...@@ -660,12 +660,12 @@ test "@floatCast cast down" {...@@ -660,12 +660,12 @@ test "@floatCast cast down" {
660660
661 {661 {
662 var double: f64 = 0.001534;662 var double: f64 = 0.001534;
663 var single = @floatCast(f32, double);663 var single = @as(f32, @floatCast(double));
664 try expect(single == 0.001534);664 try expect(single == 0.001534);
665 }665 }
666 {666 {
667 const double: f64 = 0.001534;667 const double: f64 = 0.001534;
668 const single = @floatCast(f32, double);668 const single = @as(f32, @floatCast(double));
669 try expect(single == 0.001534);669 try expect(single == 0.001534);
670 }670 }
671}671}
...@@ -1041,7 +1041,7 @@ test "cast between C pointer with different but compatible types" {...@@ -1041,7 +1041,7 @@ test "cast between C pointer with different but compatible types" {
1041 }1041 }
1042 fn doTheTest() !void {1042 fn doTheTest() !void {
1043 var x = [_]u16{ 4, 2, 1, 3 };1043 var x = [_]u16{ 4, 2, 1, 3 };
1044 try expect(foo(@ptrCast([*]u16, &x)) == 4);1044 try expect(foo(@as([*]u16, @ptrCast(&x))) == 4);
1045 }1045 }
1046 };1046 };
1047 try S.doTheTest();1047 try S.doTheTest();
...@@ -1093,10 +1093,10 @@ test "peer type resolve array pointer and unknown pointer" {...@@ -1093,10 +1093,10 @@ test "peer type resolve array pointer and unknown pointer" {
1093test "comptime float casts" {1093test "comptime float casts" {
1094 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;1094 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
10951095
1096 const a = @floatFromInt(comptime_float, 1);1096 const a = @as(comptime_float, @floatFromInt(1));
1097 try expect(a == 1);1097 try expect(a == 1);
1098 try expect(@TypeOf(a) == comptime_float);1098 try expect(@TypeOf(a) == comptime_float);
1099 const b = @intFromFloat(comptime_int, 2);1099 const b = @as(comptime_int, @intFromFloat(2));
1100 try expect(b == 2);1100 try expect(b == 2);
1101 try expect(@TypeOf(b) == comptime_int);1101 try expect(@TypeOf(b) == comptime_int);
11021102
...@@ -1111,7 +1111,7 @@ test "pointer reinterpret const float to int" {...@@ -1111,7 +1111,7 @@ test "pointer reinterpret const float to int" {
1111 // The hex representation is 0x3fe3333333333303.1111 // The hex representation is 0x3fe3333333333303.
1112 const float: f64 = 5.99999999999994648725e-01;1112 const float: f64 = 5.99999999999994648725e-01;
1113 const float_ptr = &float;1113 const float_ptr = &float;
1114 const int_ptr = @ptrCast(*const i32, float_ptr);1114 const int_ptr = @as(*const i32, @ptrCast(float_ptr));
1115 const int_val = int_ptr.*;1115 const int_val = int_ptr.*;
1116 if (native_endian == .Little)1116 if (native_endian == .Little)
1117 try expect(int_val == 0x33333303)1117 try expect(int_val == 0x33333303)
...@@ -1134,7 +1134,7 @@ test "implicit cast from [*]T to ?*anyopaque" {...@@ -1134,7 +1134,7 @@ test "implicit cast from [*]T to ?*anyopaque" {
1134fn incrementVoidPtrArray(array: ?*anyopaque, len: usize) void {1134fn incrementVoidPtrArray(array: ?*anyopaque, len: usize) void {
1135 var n: usize = 0;1135 var n: usize = 0;
1136 while (n < len) : (n += 1) {1136 while (n < len) : (n += 1) {
1137 @ptrCast([*]u8, array.?)[n] += 1;1137 @as([*]u8, @ptrCast(array.?))[n] += 1;
1138 }1138 }
1139}1139}
11401140
...@@ -1146,7 +1146,7 @@ test "compile time int to ptr of function" {...@@ -1146,7 +1146,7 @@ test "compile time int to ptr of function" {
11461146
1147// On some architectures function pointers must be aligned.1147// On some architectures function pointers must be aligned.
1148const hardcoded_fn_addr = maxInt(usize) & ~@as(usize, 0xf);1148const hardcoded_fn_addr = maxInt(usize) & ~@as(usize, 0xf);
1149pub const FUNCTION_CONSTANT = @ptrFromInt(PFN_void, hardcoded_fn_addr);1149pub const FUNCTION_CONSTANT = @as(PFN_void, @ptrFromInt(hardcoded_fn_addr));
1150pub const PFN_void = *const fn (*anyopaque) callconv(.C) void;1150pub const PFN_void = *const fn (*anyopaque) callconv(.C) void;
11511151
1152fn foobar(func: PFN_void) !void {1152fn foobar(func: PFN_void) !void {
...@@ -1161,10 +1161,10 @@ test "implicit ptr to *anyopaque" {...@@ -1161,10 +1161,10 @@ test "implicit ptr to *anyopaque" {
11611161
1162 var a: u32 = 1;1162 var a: u32 = 1;
1163 var ptr: *align(@alignOf(u32)) anyopaque = &a;1163 var ptr: *align(@alignOf(u32)) anyopaque = &a;
1164 var b: *u32 = @ptrCast(*u32, ptr);1164 var b: *u32 = @as(*u32, @ptrCast(ptr));
1165 try expect(b.* == 1);1165 try expect(b.* == 1);
1166 var ptr2: ?*align(@alignOf(u32)) anyopaque = &a;1166 var ptr2: ?*align(@alignOf(u32)) anyopaque = &a;
1167 var c: *u32 = @ptrCast(*u32, ptr2.?);1167 var c: *u32 = @as(*u32, @ptrCast(ptr2.?));
1168 try expect(c.* == 1);1168 try expect(c.* == 1);
1169}1169}
11701170
...@@ -1235,11 +1235,11 @@ fn testCast128() !void {...@@ -1235,11 +1235,11 @@ fn testCast128() !void {
1235}1235}
12361236
1237fn cast128Int(x: f128) u128 {1237fn cast128Int(x: f128) u128 {
1238 return @bitCast(u128, x);1238 return @as(u128, @bitCast(x));
1239}1239}
12401240
1241fn cast128Float(x: u128) f128 {1241fn cast128Float(x: u128) f128 {
1242 return @bitCast(f128, x);1242 return @as(f128, @bitCast(x));
1243}1243}
12441244
1245test "implicit cast from *[N]T to ?[*]T" {1245test "implicit cast from *[N]T to ?[*]T" {
...@@ -1270,7 +1270,7 @@ test "implicit cast from *T to ?*anyopaque" {...@@ -1270,7 +1270,7 @@ test "implicit cast from *T to ?*anyopaque" {
1270}1270}
12711271
1272fn incrementVoidPtrValue(value: ?*anyopaque) void {1272fn incrementVoidPtrValue(value: ?*anyopaque) void {
1273 @ptrCast(*u8, value.?).* += 1;1273 @as(*u8, @ptrCast(value.?)).* += 1;
1274}1274}
12751275
1276test "implicit cast *[0]T to E![]const u8" {1276test "implicit cast *[0]T to E![]const u8" {
...@@ -1284,11 +1284,11 @@ test "implicit cast *[0]T to E![]const u8" {...@@ -1284,11 +1284,11 @@ test "implicit cast *[0]T to E![]const u8" {
12841284
1285var global_array: [4]u8 = undefined;1285var global_array: [4]u8 = undefined;
1286test "cast from array reference to fn: comptime fn ptr" {1286test "cast from array reference to fn: comptime fn ptr" {
1287 const f = @ptrCast(*align(1) const fn () callconv(.C) void, &global_array);1287 const f = @as(*align(1) const fn () callconv(.C) void, @ptrCast(&global_array));
1288 try expect(@intFromPtr(f) == @intFromPtr(&global_array));1288 try expect(@intFromPtr(f) == @intFromPtr(&global_array));
1289}1289}
1290test "cast from array reference to fn: runtime fn ptr" {1290test "cast from array reference to fn: runtime fn ptr" {
1291 var f = @ptrCast(*align(1) const fn () callconv(.C) void, &global_array);1291 var f = @as(*align(1) const fn () callconv(.C) void, @ptrCast(&global_array));
1292 try expect(@intFromPtr(f) == @intFromPtr(&global_array));1292 try expect(@intFromPtr(f) == @intFromPtr(&global_array));
1293}1293}
12941294
...@@ -1337,7 +1337,7 @@ test "assignment to optional pointer result loc" {...@@ -1337,7 +1337,7 @@ test "assignment to optional pointer result loc" {
1337 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;1337 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
13381338
1339 var foo: struct { ptr: ?*anyopaque } = .{ .ptr = &global_struct };1339 var foo: struct { ptr: ?*anyopaque } = .{ .ptr = &global_struct };
1340 try expect(foo.ptr.? == @ptrCast(*anyopaque, &global_struct));1340 try expect(foo.ptr.? == @as(*anyopaque, @ptrCast(&global_struct)));
1341}1341}
13421342
1343test "cast between *[N]void and []void" {1343test "cast between *[N]void and []void" {
...@@ -1393,9 +1393,9 @@ test "cast f128 to narrower types" {...@@ -1393,9 +1393,9 @@ test "cast f128 to narrower types" {
1393 const S = struct {1393 const S = struct {
1394 fn doTheTest() !void {1394 fn doTheTest() !void {
1395 var x: f128 = 1234.0;1395 var x: f128 = 1234.0;
1396 try expect(@as(f16, 1234.0) == @floatCast(f16, x));1396 try expect(@as(f16, 1234.0) == @as(f16, @floatCast(x)));
1397 try expect(@as(f32, 1234.0) == @floatCast(f32, x));1397 try expect(@as(f32, 1234.0) == @as(f32, @floatCast(x)));
1398 try expect(@as(f64, 1234.0) == @floatCast(f64, x));1398 try expect(@as(f64, 1234.0) == @as(f64, @floatCast(x)));
1399 }1399 }
1400 };1400 };
1401 try S.doTheTest();1401 try S.doTheTest();
...@@ -1500,8 +1500,8 @@ test "coerce between pointers of compatible differently-named floats" {...@@ -1500,8 +1500,8 @@ test "coerce between pointers of compatible differently-named floats" {
1500}1500}
15011501
1502test "peer type resolution of const and non-const pointer to array" {1502test "peer type resolution of const and non-const pointer to array" {
1503 const a = @ptrFromInt(*[1024]u8, 42);1503 const a = @as(*[1024]u8, @ptrFromInt(42));
1504 const b = @ptrFromInt(*const [1024]u8, 42);1504 const b = @as(*const [1024]u8, @ptrFromInt(42));
1505 try std.testing.expect(@TypeOf(a, b) == *const [1024]u8);1505 try std.testing.expect(@TypeOf(a, b) == *const [1024]u8);
1506 try std.testing.expect(a == b);1506 try std.testing.expect(a == b);
1507}1507}
...@@ -1512,7 +1512,7 @@ test "intFromFloat to zero-bit int" {...@@ -1512,7 +1512,7 @@ test "intFromFloat to zero-bit int" {
1512 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1512 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
15131513
1514 const a: f32 = 0.0;1514 const a: f32 = 0.0;
1515 try comptime std.testing.expect(@intFromFloat(u0, a) == 0);1515 try comptime std.testing.expect(@as(u0, @intFromFloat(a)) == 0);
1516}1516}
15171517
1518test "peer type resolution of function pointer and function body" {1518test "peer type resolution of function pointer and function body" {
...@@ -1547,10 +1547,10 @@ test "bitcast packed struct with u0" {...@@ -1547,10 +1547,10 @@ test "bitcast packed struct with u0" {
1547 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO1547 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
15481548
1549 const S = packed struct(u2) { a: u0, b: u2 };1549 const S = packed struct(u2) { a: u0, b: u2 };
1550 const s = @bitCast(S, @as(u2, 2));1550 const s = @as(S, @bitCast(@as(u2, 2)));
1551 try expect(s.a == 0);1551 try expect(s.a == 0);
1552 try expect(s.b == 2);1552 try expect(s.b == 2);
1553 const i = @bitCast(u2, s);1553 const i = @as(u2, @bitCast(s));
1554 try expect(i == 2);1554 try expect(i == 2);
1555}1555}
15561556
...@@ -1560,7 +1560,7 @@ test "optional pointer coerced to optional allowzero pointer" {...@@ -1560,7 +1560,7 @@ test "optional pointer coerced to optional allowzero pointer" {
15601560
1561 var p: ?*u32 = undefined;1561 var p: ?*u32 = undefined;
1562 var q: ?*allowzero u32 = undefined;1562 var q: ?*allowzero u32 = undefined;
1563 p = @ptrFromInt(*u32, 4);1563 p = @as(*u32, @ptrFromInt(4));
1564 q = p;1564 q = p;
1565 try expect(@intFromPtr(q.?) == 4);1565 try expect(@intFromPtr(q.?) == 4);
1566}1566}
...@@ -1583,7 +1583,7 @@ test "peer type resolution forms error union" {...@@ -1583,7 +1583,7 @@ test "peer type resolution forms error union" {
1583 0 => unreachable,1583 0 => unreachable,
1584 42 => error.AccessDenied,1584 42 => error.AccessDenied,
1585 else => unreachable,1585 else => unreachable,
1586 } else @intCast(u32, foo);1586 } else @as(u32, @intCast(foo));
1587 try expect(try result == 123);1587 try expect(try result == 123);
1588}1588}
15891589
...@@ -1623,8 +1623,8 @@ test "peer type resolution: const sentinel slice and mutable non-sentinel slice"...@@ -1623,8 +1623,8 @@ test "peer type resolution: const sentinel slice and mutable non-sentinel slice"
16231623
1624 const S = struct {1624 const S = struct {
1625 fn doTheTest(comptime T: type, comptime s: T) !void {1625 fn doTheTest(comptime T: type, comptime s: T) !void {
1626 var a: [:s]const T = @ptrFromInt(*const [2:s]T, 0x1000);1626 var a: [:s]const T = @as(*const [2:s]T, @ptrFromInt(0x1000));
1627 var b: []T = @ptrFromInt(*[3]T, 0x2000);1627 var b: []T = @as(*[3]T, @ptrFromInt(0x2000));
1628 comptime assert(@TypeOf(a, b) == []const T);1628 comptime assert(@TypeOf(a, b) == []const T);
1629 comptime assert(@TypeOf(b, a) == []const T);1629 comptime assert(@TypeOf(b, a) == []const T);
16301630
...@@ -1634,8 +1634,8 @@ test "peer type resolution: const sentinel slice and mutable non-sentinel slice"...@@ -1634,8 +1634,8 @@ test "peer type resolution: const sentinel slice and mutable non-sentinel slice"
16341634
1635 const R = @TypeOf(r1);1635 const R = @TypeOf(r1);
16361636
1637 try expectEqual(@as(R, @ptrFromInt(*const [2:s]T, 0x1000)), r1);1637 try expectEqual(@as(R, @as(*const [2:s]T, @ptrFromInt(0x1000))), r1);
1638 try expectEqual(@as(R, @ptrFromInt(*const [3]T, 0x2000)), r2);1638 try expectEqual(@as(R, @as(*const [3]T, @ptrFromInt(0x2000))), r2);
1639 }1639 }
1640 };1640 };
16411641
...@@ -1815,7 +1815,7 @@ test "peer type resolution: three-way resolution combines error set and optional...@@ -1815,7 +1815,7 @@ test "peer type resolution: three-way resolution combines error set and optional
18151815
1816 const E = error{Foo};1816 const E = error{Foo};
1817 var a: E = error.Foo;1817 var a: E = error.Foo;
1818 var b: *const [5:0]u8 = @ptrFromInt(*const [5:0]u8, 0x1000);1818 var b: *const [5:0]u8 = @as(*const [5:0]u8, @ptrFromInt(0x1000));
1819 var c: ?[*:0]u8 = null;1819 var c: ?[*:0]u8 = null;
1820 comptime assert(@TypeOf(a, b, c) == E!?[*:0]const u8);1820 comptime assert(@TypeOf(a, b, c) == E!?[*:0]const u8);
1821 comptime assert(@TypeOf(a, c, b) == E!?[*:0]const u8);1821 comptime assert(@TypeOf(a, c, b) == E!?[*:0]const u8);
...@@ -1844,7 +1844,7 @@ test "peer type resolution: three-way resolution combines error set and optional...@@ -1844,7 +1844,7 @@ test "peer type resolution: three-way resolution combines error set and optional
1844 const T = @TypeOf(r1);1844 const T = @TypeOf(r1);
18451845
1846 try expectEqual(@as(T, error.Foo), r1);1846 try expectEqual(@as(T, error.Foo), r1);
1847 try expectEqual(@as(T, @ptrFromInt([*:0]u8, 0x1000)), r2);1847 try expectEqual(@as(T, @as([*:0]u8, @ptrFromInt(0x1000))), r2);
1848 try expectEqual(@as(T, null), r3);1848 try expectEqual(@as(T, null), r3);
1849}1849}
18501850
...@@ -2114,7 +2114,7 @@ test "peer type resolution: many compatible pointers" {...@@ -2114,7 +2114,7 @@ test "peer type resolution: many compatible pointers" {
2114 4 => "foo-4",2114 4 => "foo-4",
2115 else => unreachable,2115 else => unreachable,
2116 };2116 };
2117 try expectEqualSlices(u8, expected, std.mem.span(@ptrCast([*:0]const u8, r)));2117 try expectEqualSlices(u8, expected, std.mem.span(@as([*:0]const u8, @ptrCast(r))));
2118 }2118 }
2119}2119}
21202120
test/behavior/cast_int.zig+1-1
...@@ -11,6 +11,6 @@ test "@intCast i32 to u7" {...@@ -11,6 +11,6 @@ test "@intCast i32 to u7" {
1111
12 var x: u128 = maxInt(u128);12 var x: u128 = maxInt(u128);
13 var y: i32 = 120;13 var y: i32 = 120;
14 var z = x >> @intCast(u7, y);14 var z = x >> @as(u7, @intCast(y));
15 try expect(z == 0xff);15 try expect(z == 0xff);
16}16}
test/behavior/comptime_memory.zig+34-34
...@@ -6,7 +6,7 @@ const ptr_size = @sizeOf(usize);...@@ -6,7 +6,7 @@ const ptr_size = @sizeOf(usize);
6test "type pun signed and unsigned as single pointer" {6test "type pun signed and unsigned as single pointer" {
7 comptime {7 comptime {
8 var x: u32 = 0;8 var x: u32 = 0;
9 const y = @ptrCast(*i32, &x);9 const y = @as(*i32, @ptrCast(&x));
10 y.* = -1;10 y.* = -1;
11 try testing.expectEqual(@as(u32, 0xFFFFFFFF), x);11 try testing.expectEqual(@as(u32, 0xFFFFFFFF), x);
12 }12 }
...@@ -15,7 +15,7 @@ test "type pun signed and unsigned as single pointer" {...@@ -15,7 +15,7 @@ test "type pun signed and unsigned as single pointer" {
15test "type pun signed and unsigned as many pointer" {15test "type pun signed and unsigned as many pointer" {
16 comptime {16 comptime {
17 var x: u32 = 0;17 var x: u32 = 0;
18 const y = @ptrCast([*]i32, &x);18 const y = @as([*]i32, @ptrCast(&x));
19 y[0] = -1;19 y[0] = -1;
20 try testing.expectEqual(@as(u32, 0xFFFFFFFF), x);20 try testing.expectEqual(@as(u32, 0xFFFFFFFF), x);
21 }21 }
...@@ -24,7 +24,7 @@ test "type pun signed and unsigned as many pointer" {...@@ -24,7 +24,7 @@ test "type pun signed and unsigned as many pointer" {
24test "type pun signed and unsigned as array pointer" {24test "type pun signed and unsigned as array pointer" {
25 comptime {25 comptime {
26 var x: u32 = 0;26 var x: u32 = 0;
27 const y = @ptrCast(*[1]i32, &x);27 const y = @as(*[1]i32, @ptrCast(&x));
28 y[0] = -1;28 y[0] = -1;
29 try testing.expectEqual(@as(u32, 0xFFFFFFFF), x);29 try testing.expectEqual(@as(u32, 0xFFFFFFFF), x);
30 }30 }
...@@ -38,7 +38,7 @@ test "type pun signed and unsigned as offset many pointer" {...@@ -38,7 +38,7 @@ test "type pun signed and unsigned as offset many pointer" {
3838
39 comptime {39 comptime {
40 var x: u32 = 0;40 var x: u32 = 0;
41 var y = @ptrCast([*]i32, &x);41 var y = @as([*]i32, @ptrCast(&x));
42 y -= 10;42 y -= 10;
43 y[10] = -1;43 y[10] = -1;
44 try testing.expectEqual(@as(u32, 0xFFFFFFFF), x);44 try testing.expectEqual(@as(u32, 0xFFFFFFFF), x);
...@@ -53,7 +53,7 @@ test "type pun signed and unsigned as array pointer with pointer arithemtic" {...@@ -53,7 +53,7 @@ test "type pun signed and unsigned as array pointer with pointer arithemtic" {
5353
54 comptime {54 comptime {
55 var x: u32 = 0;55 var x: u32 = 0;
56 const y = @ptrCast([*]i32, &x) - 10;56 const y = @as([*]i32, @ptrCast(&x)) - 10;
57 const z: *[15]i32 = y[0..15];57 const z: *[15]i32 = y[0..15];
58 z[10] = -1;58 z[10] = -1;
59 try testing.expectEqual(@as(u32, 0xFFFFFFFF), x);59 try testing.expectEqual(@as(u32, 0xFFFFFFFF), x);
...@@ -64,9 +64,9 @@ test "type pun value and struct" {...@@ -64,9 +64,9 @@ test "type pun value and struct" {
64 comptime {64 comptime {
65 const StructOfU32 = extern struct { x: u32 };65 const StructOfU32 = extern struct { x: u32 };
66 var inst: StructOfU32 = .{ .x = 0 };66 var inst: StructOfU32 = .{ .x = 0 };
67 @ptrCast(*i32, &inst.x).* = -1;67 @as(*i32, @ptrCast(&inst.x)).* = -1;
68 try testing.expectEqual(@as(u32, 0xFFFFFFFF), inst.x);68 try testing.expectEqual(@as(u32, 0xFFFFFFFF), inst.x);
69 @ptrCast(*i32, &inst).* = -2;69 @as(*i32, @ptrCast(&inst)).* = -2;
70 try testing.expectEqual(@as(u32, 0xFFFFFFFE), inst.x);70 try testing.expectEqual(@as(u32, 0xFFFFFFFE), inst.x);
71 }71 }
72}72}
...@@ -81,8 +81,8 @@ test "type pun endianness" {...@@ -81,8 +81,8 @@ test "type pun endianness" {
81 comptime {81 comptime {
82 const StructOfBytes = extern struct { x: [4]u8 };82 const StructOfBytes = extern struct { x: [4]u8 };
83 var inst: StructOfBytes = .{ .x = [4]u8{ 0, 0, 0, 0 } };83 var inst: StructOfBytes = .{ .x = [4]u8{ 0, 0, 0, 0 } };
84 const structPtr = @ptrCast(*align(1) u32, &inst);84 const structPtr = @as(*align(1) u32, @ptrCast(&inst));
85 const arrayPtr = @ptrCast(*align(1) u32, &inst.x);85 const arrayPtr = @as(*align(1) u32, @ptrCast(&inst.x));
86 inst.x[0] = 0xFE;86 inst.x[0] = 0xFE;
87 inst.x[2] = 0xBE;87 inst.x[2] = 0xBE;
88 try testing.expectEqual(bigToNativeEndian(u32, 0xFE00BE00), structPtr.*);88 try testing.expectEqual(bigToNativeEndian(u32, 0xFE00BE00), structPtr.*);
...@@ -124,8 +124,8 @@ fn shuffle(ptr: usize, comptime From: type, comptime To: type) usize {...@@ -124,8 +124,8 @@ fn shuffle(ptr: usize, comptime From: type, comptime To: type) usize {
124 @compileError("Mismatched sizes! " ++ @typeName(From) ++ " and " ++ @typeName(To) ++ " must have the same size!");124 @compileError("Mismatched sizes! " ++ @typeName(From) ++ " and " ++ @typeName(To) ++ " must have the same size!");
125 const array_len = @divExact(ptr_size, @sizeOf(From));125 const array_len = @divExact(ptr_size, @sizeOf(From));
126 var result: usize = 0;126 var result: usize = 0;
127 const pSource = @ptrCast(*align(1) const [array_len]From, &ptr);127 const pSource = @as(*align(1) const [array_len]From, @ptrCast(&ptr));
128 const pResult = @ptrCast(*align(1) [array_len]To, &result);128 const pResult = @as(*align(1) [array_len]To, @ptrCast(&result));
129 var i: usize = 0;129 var i: usize = 0;
130 while (i < array_len) : (i += 1) {130 while (i < array_len) : (i += 1) {
131 inline for (@typeInfo(To).Struct.fields) |f| {131 inline for (@typeInfo(To).Struct.fields) |f| {
...@@ -136,8 +136,8 @@ fn shuffle(ptr: usize, comptime From: type, comptime To: type) usize {...@@ -136,8 +136,8 @@ fn shuffle(ptr: usize, comptime From: type, comptime To: type) usize {
136}136}
137137
138fn doTypePunBitsTest(as_bits: *Bits) !void {138fn doTypePunBitsTest(as_bits: *Bits) !void {
139 const as_u32 = @ptrCast(*align(1) u32, as_bits);139 const as_u32 = @as(*align(1) u32, @ptrCast(as_bits));
140 const as_bytes = @ptrCast(*[4]u8, as_bits);140 const as_bytes = @as(*[4]u8, @ptrCast(as_bits));
141 as_u32.* = bigToNativeEndian(u32, 0xB0A7DEED);141 as_u32.* = bigToNativeEndian(u32, 0xB0A7DEED);
142 try testing.expectEqual(@as(u1, 0x00), as_bits.p0);142 try testing.expectEqual(@as(u1, 0x00), as_bits.p0);
143 try testing.expectEqual(@as(u4, 0x08), as_bits.p1);143 try testing.expectEqual(@as(u4, 0x08), as_bits.p1);
...@@ -176,7 +176,7 @@ test "type pun bits" {...@@ -176,7 +176,7 @@ test "type pun bits" {
176176
177 comptime {177 comptime {
178 var v: u32 = undefined;178 var v: u32 = undefined;
179 try doTypePunBitsTest(@ptrCast(*Bits, &v));179 try doTypePunBitsTest(@as(*Bits, @ptrCast(&v)));
180 }180 }
181}181}
182182
...@@ -194,7 +194,7 @@ test "basic pointer preservation" {...@@ -194,7 +194,7 @@ test "basic pointer preservation" {
194 comptime {194 comptime {
195 const lazy_address = @intFromPtr(&imports.global_u32);195 const lazy_address = @intFromPtr(&imports.global_u32);
196 try testing.expectEqual(@intFromPtr(&imports.global_u32), lazy_address);196 try testing.expectEqual(@intFromPtr(&imports.global_u32), lazy_address);
197 try testing.expectEqual(&imports.global_u32, @ptrFromInt(*u32, lazy_address));197 try testing.expectEqual(&imports.global_u32, @as(*u32, @ptrFromInt(lazy_address)));
198 }198 }
199}199}
200200
...@@ -207,8 +207,8 @@ test "byte copy preserves linker value" {...@@ -207,8 +207,8 @@ test "byte copy preserves linker value" {
207 const ct_value = comptime blk: {207 const ct_value = comptime blk: {
208 const lazy = &imports.global_u32;208 const lazy = &imports.global_u32;
209 var result: *u32 = undefined;209 var result: *u32 = undefined;
210 const pSource = @ptrCast(*const [ptr_size]u8, &lazy);210 const pSource = @as(*const [ptr_size]u8, @ptrCast(&lazy));
211 const pResult = @ptrCast(*[ptr_size]u8, &result);211 const pResult = @as(*[ptr_size]u8, @ptrCast(&result));
212 var i: usize = 0;212 var i: usize = 0;
213 while (i < ptr_size) : (i += 1) {213 while (i < ptr_size) : (i += 1) {
214 pResult[i] = pSource[i];214 pResult[i] = pSource[i];
...@@ -230,8 +230,8 @@ test "unordered byte copy preserves linker value" {...@@ -230,8 +230,8 @@ test "unordered byte copy preserves linker value" {
230 const ct_value = comptime blk: {230 const ct_value = comptime blk: {
231 const lazy = &imports.global_u32;231 const lazy = &imports.global_u32;
232 var result: *u32 = undefined;232 var result: *u32 = undefined;
233 const pSource = @ptrCast(*const [ptr_size]u8, &lazy);233 const pSource = @as(*const [ptr_size]u8, @ptrCast(&lazy));
234 const pResult = @ptrCast(*[ptr_size]u8, &result);234 const pResult = @as(*[ptr_size]u8, @ptrCast(&result));
235 if (ptr_size > 8) @compileError("This array needs to be expanded for platform with very big pointers");235 if (ptr_size > 8) @compileError("This array needs to be expanded for platform with very big pointers");
236 const shuffled_indices = [_]usize{ 4, 5, 2, 6, 1, 3, 0, 7 };236 const shuffled_indices = [_]usize{ 4, 5, 2, 6, 1, 3, 0, 7 };
237 for (shuffled_indices) |i| {237 for (shuffled_indices) |i| {
...@@ -274,12 +274,12 @@ test "dance on linker values" {...@@ -274,12 +274,12 @@ test "dance on linker values" {
274 arr[0] = @intFromPtr(&imports.global_u32);274 arr[0] = @intFromPtr(&imports.global_u32);
275 arr[1] = @intFromPtr(&imports.global_u32);275 arr[1] = @intFromPtr(&imports.global_u32);
276276
277 const weird_ptr = @ptrCast([*]Bits, @ptrCast([*]u8, &arr) + @sizeOf(usize) - 3);277 const weird_ptr = @as([*]Bits, @ptrCast(@as([*]u8, @ptrCast(&arr)) + @sizeOf(usize) - 3));
278 try doTypePunBitsTest(&weird_ptr[0]);278 try doTypePunBitsTest(&weird_ptr[0]);
279 if (ptr_size > @sizeOf(Bits))279 if (ptr_size > @sizeOf(Bits))
280 try doTypePunBitsTest(&weird_ptr[1]);280 try doTypePunBitsTest(&weird_ptr[1]);
281281
282 var arr_bytes = @ptrCast(*[2][ptr_size]u8, &arr);282 var arr_bytes = @as(*[2][ptr_size]u8, @ptrCast(&arr));
283283
284 var rebuilt_bytes: [ptr_size]u8 = undefined;284 var rebuilt_bytes: [ptr_size]u8 = undefined;
285 var i: usize = 0;285 var i: usize = 0;
...@@ -290,7 +290,7 @@ test "dance on linker values" {...@@ -290,7 +290,7 @@ test "dance on linker values" {
290 rebuilt_bytes[i] = arr_bytes[1][i];290 rebuilt_bytes[i] = arr_bytes[1][i];
291 }291 }
292292
293 try testing.expectEqual(&imports.global_u32, @ptrFromInt(*u32, @bitCast(usize, rebuilt_bytes)));293 try testing.expectEqual(&imports.global_u32, @as(*u32, @ptrFromInt(@as(usize, @bitCast(rebuilt_bytes)))));
294 }294 }
295}295}
296296
...@@ -316,7 +316,7 @@ test "offset array ptr by element size" {...@@ -316,7 +316,7 @@ test "offset array ptr by element size" {
316 try testing.expectEqual(@intFromPtr(&arr[2]), address + 2 * @sizeOf(VirtualStruct));316 try testing.expectEqual(@intFromPtr(&arr[2]), address + 2 * @sizeOf(VirtualStruct));
317 try testing.expectEqual(@intFromPtr(&arr[3]), address + @sizeOf(VirtualStruct) * 3);317 try testing.expectEqual(@intFromPtr(&arr[3]), address + @sizeOf(VirtualStruct) * 3);
318318
319 const secondElement = @ptrFromInt(*VirtualStruct, @intFromPtr(&arr[0]) + 2 * @sizeOf(VirtualStruct));319 const secondElement = @as(*VirtualStruct, @ptrFromInt(@intFromPtr(&arr[0]) + 2 * @sizeOf(VirtualStruct)));
320 try testing.expectEqual(bigToNativeEndian(u32, 0x02060a0e), secondElement.x);320 try testing.expectEqual(bigToNativeEndian(u32, 0x02060a0e), secondElement.x);
321 }321 }
322}322}
...@@ -334,15 +334,15 @@ test "offset instance by field size" {...@@ -334,15 +334,15 @@ test "offset instance by field size" {
334 var ptr = @intFromPtr(&inst);334 var ptr = @intFromPtr(&inst);
335 ptr -= 4;335 ptr -= 4;
336 ptr += @offsetOf(VirtualStruct, "x");336 ptr += @offsetOf(VirtualStruct, "x");
337 try testing.expectEqual(@as(u32, 0), @ptrFromInt([*]u32, ptr)[1]);337 try testing.expectEqual(@as(u32, 0), @as([*]u32, @ptrFromInt(ptr))[1]);
338 ptr -= @offsetOf(VirtualStruct, "x");338 ptr -= @offsetOf(VirtualStruct, "x");
339 ptr += @offsetOf(VirtualStruct, "y");339 ptr += @offsetOf(VirtualStruct, "y");
340 try testing.expectEqual(@as(u32, 1), @ptrFromInt([*]u32, ptr)[1]);340 try testing.expectEqual(@as(u32, 1), @as([*]u32, @ptrFromInt(ptr))[1]);
341 ptr = ptr - @offsetOf(VirtualStruct, "y") + @offsetOf(VirtualStruct, "z");341 ptr = ptr - @offsetOf(VirtualStruct, "y") + @offsetOf(VirtualStruct, "z");
342 try testing.expectEqual(@as(u32, 2), @ptrFromInt([*]u32, ptr)[1]);342 try testing.expectEqual(@as(u32, 2), @as([*]u32, @ptrFromInt(ptr))[1]);
343 ptr = @intFromPtr(&inst.z) - 4 - @offsetOf(VirtualStruct, "z");343 ptr = @intFromPtr(&inst.z) - 4 - @offsetOf(VirtualStruct, "z");
344 ptr += @offsetOf(VirtualStruct, "w");344 ptr += @offsetOf(VirtualStruct, "w");
345 try testing.expectEqual(@as(u32, 3), @ptrFromInt(*u32, ptr + 4).*);345 try testing.expectEqual(@as(u32, 3), @as(*u32, @ptrFromInt(ptr + 4)).*);
346 }346 }
347}347}
348348
...@@ -363,13 +363,13 @@ test "offset field ptr by enclosing array element size" {...@@ -363,13 +363,13 @@ test "offset field ptr by enclosing array element size" {
363363
364 var i: usize = 0;364 var i: usize = 0;
365 while (i < 4) : (i += 1) {365 while (i < 4) : (i += 1) {
366 var ptr: [*]u8 = @ptrCast([*]u8, &arr[0]);366 var ptr: [*]u8 = @as([*]u8, @ptrCast(&arr[0]));
367 ptr += i;367 ptr += i;
368 ptr += @offsetOf(VirtualStruct, "x");368 ptr += @offsetOf(VirtualStruct, "x");
369 var j: usize = 0;369 var j: usize = 0;
370 while (j < 4) : (j += 1) {370 while (j < 4) : (j += 1) {
371 const base = ptr + j * @sizeOf(VirtualStruct);371 const base = ptr + j * @sizeOf(VirtualStruct);
372 try testing.expectEqual(@intCast(u8, i * 4 + j), base[0]);372 try testing.expectEqual(@as(u8, @intCast(i * 4 + j)), base[0]);
373 }373 }
374 }374 }
375 }375 }
...@@ -393,7 +393,7 @@ test "accessing reinterpreted memory of parent object" {...@@ -393,7 +393,7 @@ test "accessing reinterpreted memory of parent object" {
393 .c = 2.6,393 .c = 2.6,
394 };394 };
395 const ptr = &x.b[0];395 const ptr = &x.b[0];
396 const b = @ptrCast([*c]const u8, ptr)[5];396 const b = @as([*c]const u8, @ptrCast(ptr))[5];
397 try testing.expect(b == expected);397 try testing.expect(b == expected);
398 }398 }
399}399}
...@@ -407,11 +407,11 @@ test "bitcast packed union to integer" {...@@ -407,11 +407,11 @@ test "bitcast packed union to integer" {
407 comptime {407 comptime {
408 const a = U{ .x = 1 };408 const a = U{ .x = 1 };
409 const b = U{ .y = 2 };409 const b = U{ .y = 2 };
410 const cast_a = @bitCast(u2, a);410 const cast_a = @as(u2, @bitCast(a));
411 const cast_b = @bitCast(u2, b);411 const cast_b = @as(u2, @bitCast(b));
412412
413 // truncated because the upper bit is garbage memory that we don't care about413 // truncated because the upper bit is garbage memory that we don't care about
414 try testing.expectEqual(@as(u1, 1), @truncate(u1, cast_a));414 try testing.expectEqual(@as(u1, 1), @as(u1, @truncate(cast_a)));
415 try testing.expectEqual(@as(u2, 2), cast_b);415 try testing.expectEqual(@as(u2, 2), cast_b);
416 }416 }
417}417}
...@@ -435,6 +435,6 @@ test "dereference undefined pointer to zero-bit type" {...@@ -435,6 +435,6 @@ test "dereference undefined pointer to zero-bit type" {
435test "type pun extern struct" {435test "type pun extern struct" {
436 const S = extern struct { f: u8 };436 const S = extern struct { f: u8 };
437 comptime var s = S{ .f = 123 };437 comptime var s = S{ .f = 123 };
438 @ptrCast(*u8, &s).* = 72;438 @as(*u8, @ptrCast(&s)).* = 72;
439 try testing.expectEqual(@as(u8, 72), s.f);439 try testing.expectEqual(@as(u8, 72), s.f);
440}440}
test/behavior/enum.zig+18-18
...@@ -20,7 +20,7 @@ test "enum to int" {...@@ -20,7 +20,7 @@ test "enum to int" {
20}20}
2121
22fn testIntToEnumEval(x: i32) !void {22fn testIntToEnumEval(x: i32) !void {
23 try expect(@enumFromInt(IntToEnumNumber, x) == IntToEnumNumber.Three);23 try expect(@as(IntToEnumNumber, @enumFromInt(x)) == IntToEnumNumber.Three);
24}24}
25const IntToEnumNumber = enum { Zero, One, Two, Three, Four };25const IntToEnumNumber = enum { Zero, One, Two, Three, Four };
2626
...@@ -629,7 +629,7 @@ test "non-exhaustive enum" {...@@ -629,7 +629,7 @@ test "non-exhaustive enum" {
629 .b => true,629 .b => true,
630 _ => false,630 _ => false,
631 });631 });
632 e = @enumFromInt(E, 12);632 e = @as(E, @enumFromInt(12));
633 try expect(switch (e) {633 try expect(switch (e) {
634 .a => false,634 .a => false,
635 .b => false,635 .b => false,
...@@ -648,9 +648,9 @@ test "non-exhaustive enum" {...@@ -648,9 +648,9 @@ test "non-exhaustive enum" {
648 });648 });
649649
650 try expect(@typeInfo(E).Enum.fields.len == 2);650 try expect(@typeInfo(E).Enum.fields.len == 2);
651 e = @enumFromInt(E, 12);651 e = @as(E, @enumFromInt(12));
652 try expect(@intFromEnum(e) == 12);652 try expect(@intFromEnum(e) == 12);
653 e = @enumFromInt(E, y);653 e = @as(E, @enumFromInt(y));
654 try expect(@intFromEnum(e) == 52);654 try expect(@intFromEnum(e) == 52);
655 try expect(@typeInfo(E).Enum.is_exhaustive == false);655 try expect(@typeInfo(E).Enum.is_exhaustive == false);
656 }656 }
...@@ -666,7 +666,7 @@ test "empty non-exhaustive enum" {...@@ -666,7 +666,7 @@ test "empty non-exhaustive enum" {
666 const E = enum(u8) { _ };666 const E = enum(u8) { _ };
667667
668 fn doTheTest(y: u8) !void {668 fn doTheTest(y: u8) !void {
669 var e = @enumFromInt(E, y);669 var e = @as(E, @enumFromInt(y));
670 try expect(switch (e) {670 try expect(switch (e) {
671 _ => true,671 _ => true,
672 });672 });
...@@ -693,7 +693,7 @@ test "single field non-exhaustive enum" {...@@ -693,7 +693,7 @@ test "single field non-exhaustive enum" {
693 .a => true,693 .a => true,
694 _ => false,694 _ => false,
695 });695 });
696 e = @enumFromInt(E, 12);696 e = @as(E, @enumFromInt(12));
697 try expect(switch (e) {697 try expect(switch (e) {
698 .a => false,698 .a => false,
699 _ => true,699 _ => true,
...@@ -709,7 +709,7 @@ test "single field non-exhaustive enum" {...@@ -709,7 +709,7 @@ test "single field non-exhaustive enum" {
709 else => false,709 else => false,
710 });710 });
711711
712 try expect(@intFromEnum(@enumFromInt(E, y)) == y);712 try expect(@intFromEnum(@as(E, @enumFromInt(y))) == y);
713 try expect(@typeInfo(E).Enum.fields.len == 1);713 try expect(@typeInfo(E).Enum.fields.len == 1);
714 try expect(@typeInfo(E).Enum.is_exhaustive == false);714 try expect(@typeInfo(E).Enum.is_exhaustive == false);
715 }715 }
...@@ -741,8 +741,8 @@ const MultipleChoice2 = enum(u32) {...@@ -741,8 +741,8 @@ const MultipleChoice2 = enum(u32) {
741};741};
742742
743test "cast integer literal to enum" {743test "cast integer literal to enum" {
744 try expect(@enumFromInt(MultipleChoice2, 0) == MultipleChoice2.Unspecified1);744 try expect(@as(MultipleChoice2, @enumFromInt(0)) == MultipleChoice2.Unspecified1);
745 try expect(@enumFromInt(MultipleChoice2, 40) == MultipleChoice2.B);745 try expect(@as(MultipleChoice2, @enumFromInt(40)) == MultipleChoice2.B);
746}746}
747747
748test "enum with specified and unspecified tag values" {748test "enum with specified and unspecified tag values" {
...@@ -1155,7 +1155,7 @@ test "size of enum with only one tag which has explicit integer tag type" {...@@ -1155,7 +1155,7 @@ test "size of enum with only one tag which has explicit integer tag type" {
1155 var s1: S1 = undefined;1155 var s1: S1 = undefined;
1156 s1.e = .nope;1156 s1.e = .nope;
1157 try expect(s1.e == .nope);1157 try expect(s1.e == .nope);
1158 const ptr = @ptrCast(*u8, &s1);1158 const ptr = @as(*u8, @ptrCast(&s1));
1159 try expect(ptr.* == 10);1159 try expect(ptr.* == 10);
11601160
1161 var s0: S0 = undefined;1161 var s0: S0 = undefined;
...@@ -1183,7 +1183,7 @@ test "Non-exhaustive enum with nonstandard int size behaves correctly" {...@@ -1183,7 +1183,7 @@ test "Non-exhaustive enum with nonstandard int size behaves correctly" {
1183test "runtime int to enum with one possible value" {1183test "runtime int to enum with one possible value" {
1184 const E = enum { one };1184 const E = enum { one };
1185 var runtime: usize = 0;1185 var runtime: usize = 0;
1186 if (@enumFromInt(E, runtime) != .one) {1186 if (@as(E, @enumFromInt(runtime)) != .one) {
1187 @compileError("test failed");1187 @compileError("test failed");
1188 }1188 }
1189}1189}
...@@ -1194,7 +1194,7 @@ test "enum tag from a local variable" {...@@ -1194,7 +1194,7 @@ test "enum tag from a local variable" {
1194 return enum(Inner) { _ };1194 return enum(Inner) { _ };
1195 }1195 }
1196 };1196 };
1197 const i = @enumFromInt(S.Int(u32), 0);1197 const i = @as(S.Int(u32), @enumFromInt(0));
1198 try std.testing.expect(@intFromEnum(i) == 0);1198 try std.testing.expect(@intFromEnum(i) == 0);
1199}1199}
12001200
...@@ -1203,12 +1203,12 @@ test "auto-numbered enum with signed tag type" {...@@ -1203,12 +1203,12 @@ test "auto-numbered enum with signed tag type" {
12031203
1204 try std.testing.expectEqual(@as(i32, 0), @intFromEnum(E.a));1204 try std.testing.expectEqual(@as(i32, 0), @intFromEnum(E.a));
1205 try std.testing.expectEqual(@as(i32, 1), @intFromEnum(E.b));1205 try std.testing.expectEqual(@as(i32, 1), @intFromEnum(E.b));
1206 try std.testing.expectEqual(E.a, @enumFromInt(E, 0));1206 try std.testing.expectEqual(E.a, @as(E, @enumFromInt(0)));
1207 try std.testing.expectEqual(E.b, @enumFromInt(E, 1));1207 try std.testing.expectEqual(E.b, @as(E, @enumFromInt(1)));
1208 try std.testing.expectEqual(E.a, @enumFromInt(E, @as(i32, 0)));1208 try std.testing.expectEqual(E.a, @as(E, @enumFromInt(@as(i32, 0))));
1209 try std.testing.expectEqual(E.b, @enumFromInt(E, @as(i32, 1)));1209 try std.testing.expectEqual(E.b, @as(E, @enumFromInt(@as(i32, 1))));
1210 try std.testing.expectEqual(E.a, @enumFromInt(E, @as(u32, 0)));1210 try std.testing.expectEqual(E.a, @as(E, @enumFromInt(@as(u32, 0))));
1211 try std.testing.expectEqual(E.b, @enumFromInt(E, @as(u32, 1)));1211 try std.testing.expectEqual(E.b, @as(E, @enumFromInt(@as(u32, 1))));
1212 try std.testing.expectEqualStrings("a", @tagName(E.a));1212 try std.testing.expectEqualStrings("a", @tagName(E.a));
1213 try std.testing.expectEqualStrings("b", @tagName(E.b));1213 try std.testing.expectEqualStrings("b", @tagName(E.b));
1214}1214}
test/behavior/error.zig+2-2
...@@ -234,9 +234,9 @@ const Set1 = error{ A, B };...@@ -234,9 +234,9 @@ const Set1 = error{ A, B };
234const Set2 = error{ A, C };234const Set2 = error{ A, C };
235235
236fn testExplicitErrorSetCast(set1: Set1) !void {236fn testExplicitErrorSetCast(set1: Set1) !void {
237 var x = @errSetCast(Set2, set1);237 var x = @as(Set2, @errSetCast(set1));
238 try expect(@TypeOf(x) == Set2);238 try expect(@TypeOf(x) == Set2);
239 var y = @errSetCast(Set1, x);239 var y = @as(Set1, @errSetCast(x));
240 try expect(@TypeOf(y) == Set1);240 try expect(@TypeOf(y) == Set1);
241 try expect(y == error.A);241 try expect(y == error.A);
242}242}
test/behavior/eval.zig+10-10
...@@ -9,7 +9,7 @@ test "compile time recursion" {...@@ -9,7 +9,7 @@ test "compile time recursion" {
99
10 try expect(some_data.len == 21);10 try expect(some_data.len == 21);
11}11}
12var some_data: [@intCast(usize, fibonacci(7))]u8 = undefined;12var some_data: [@as(usize, @intCast(fibonacci(7)))]u8 = undefined;
13fn fibonacci(x: i32) i32 {13fn fibonacci(x: i32) i32 {
14 if (x <= 1) return 1;14 if (x <= 1) return 1;
15 return fibonacci(x - 1) + fibonacci(x - 2);15 return fibonacci(x - 1) + fibonacci(x - 2);
...@@ -123,7 +123,7 @@ fn fnWithSetRuntimeSafety() i32 {...@@ -123,7 +123,7 @@ fn fnWithSetRuntimeSafety() i32 {
123test "compile-time downcast when the bits fit" {123test "compile-time downcast when the bits fit" {
124 comptime {124 comptime {
125 const spartan_count: u16 = 255;125 const spartan_count: u16 = 255;
126 const byte = @intCast(u8, spartan_count);126 const byte = @as(u8, @intCast(spartan_count));
127 try expect(byte == 255);127 try expect(byte == 255);
128 }128 }
129}129}
...@@ -149,7 +149,7 @@ test "a type constructed in a global expression" {...@@ -149,7 +149,7 @@ test "a type constructed in a global expression" {
149 l.array[0] = 10;149 l.array[0] = 10;
150 l.array[1] = 11;150 l.array[1] = 11;
151 l.array[2] = 12;151 l.array[2] = 12;
152 const ptr = @ptrCast([*]u8, &l.array);152 const ptr = @as([*]u8, @ptrCast(&l.array));
153 try expect(ptr[0] == 10);153 try expect(ptr[0] == 10);
154 try expect(ptr[1] == 11);154 try expect(ptr[1] == 11);
155 try expect(ptr[2] == 12);155 try expect(ptr[2] == 12);
...@@ -332,7 +332,7 @@ fn generateTable(comptime T: type) [1010]T {...@@ -332,7 +332,7 @@ fn generateTable(comptime T: type) [1010]T {
332 var res: [1010]T = undefined;332 var res: [1010]T = undefined;
333 var i: usize = 0;333 var i: usize = 0;
334 while (i < 1010) : (i += 1) {334 while (i < 1010) : (i += 1) {
335 res[i] = @intCast(T, i);335 res[i] = @as(T, @intCast(i));
336 }336 }
337 return res;337 return res;
338}338}
...@@ -460,7 +460,7 @@ test "binary math operator in partially inlined function" {...@@ -460,7 +460,7 @@ test "binary math operator in partially inlined function" {
460 var b: [16]u8 = undefined;460 var b: [16]u8 = undefined;
461461
462 for (&b, 0..) |*r, i|462 for (&b, 0..) |*r, i|
463 r.* = @intCast(u8, i + 1);463 r.* = @as(u8, @intCast(i + 1));
464464
465 copyWithPartialInline(s[0..], b[0..]);465 copyWithPartialInline(s[0..], b[0..]);
466 try expect(s[0] == 0x1020304);466 try expect(s[0] == 0x1020304);
...@@ -942,7 +942,7 @@ test "comptime pointer load through elem_ptr" {...@@ -942,7 +942,7 @@ test "comptime pointer load through elem_ptr" {
942 .x = i,942 .x = i,
943 };943 };
944 }944 }
945 var ptr = @ptrCast([*]S, &array);945 var ptr = @as([*]S, @ptrCast(&array));
946 var x = ptr[0].x;946 var x = ptr[0].x;
947 assert(x == 0);947 assert(x == 0);
948 ptr += 1;948 ptr += 1;
...@@ -1281,9 +1281,9 @@ test "comptime write through extern struct reinterpreted as array" {...@@ -1281,9 +1281,9 @@ test "comptime write through extern struct reinterpreted as array" {
1281 c: u8,1281 c: u8,
1282 };1282 };
1283 var s: S = undefined;1283 var s: S = undefined;
1284 @ptrCast(*[3]u8, &s)[0] = 1;1284 @as(*[3]u8, @ptrCast(&s))[0] = 1;
1285 @ptrCast(*[3]u8, &s)[1] = 2;1285 @as(*[3]u8, @ptrCast(&s))[1] = 2;
1286 @ptrCast(*[3]u8, &s)[2] = 3;1286 @as(*[3]u8, @ptrCast(&s))[2] = 3;
1287 assert(s.a == 1);1287 assert(s.a == 1);
1288 assert(s.b == 2);1288 assert(s.b == 2);
1289 assert(s.c == 3);1289 assert(s.c == 3);
...@@ -1371,7 +1371,7 @@ test "lazy value is resolved as slice operand" {...@@ -1371,7 +1371,7 @@ test "lazy value is resolved as slice operand" {
1371 var a: [512]u64 = undefined;1371 var a: [512]u64 = undefined;
13721372
1373 const ptr1 = a[0..@sizeOf(A)];1373 const ptr1 = a[0..@sizeOf(A)];
1374 const ptr2 = @ptrCast([*]u8, &a)[0..@sizeOf(A)];1374 const ptr2 = @as([*]u8, @ptrCast(&a))[0..@sizeOf(A)];
1375 try expect(@intFromPtr(ptr1) == @intFromPtr(ptr2));1375 try expect(@intFromPtr(ptr1) == @intFromPtr(ptr2));
1376 try expect(ptr1.len == ptr2.len);1376 try expect(ptr1.len == ptr2.len);
1377}1377}
test/behavior/export.zig+1-1
...@@ -7,7 +7,7 @@ const builtin = @import("builtin");...@@ -7,7 +7,7 @@ const builtin = @import("builtin");
77
8// can't really run this test but we can make sure it has no compile error8// can't really run this test but we can make sure it has no compile error
9// and generates code9// and generates code
10const vram = @ptrFromInt([*]volatile u8, 0x20000000)[0..0x8000];10const vram = @as([*]volatile u8, @ptrFromInt(0x20000000))[0..0x8000];
11export fn writeToVRam() void {11export fn writeToVRam() void {
12 vram[0] = 'X';12 vram[0] = 'X';
13}13}
test/behavior/floatop.zig+3-3
...@@ -94,7 +94,7 @@ test "negative f128 intFromFloat at compile-time" {...@@ -94,7 +94,7 @@ test "negative f128 intFromFloat at compile-time" {
94 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO94 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
9595
96 const a: f128 = -2;96 const a: f128 = -2;
97 var b = @intFromFloat(i64, a);97 var b = @as(i64, @intFromFloat(a));
98 try expect(@as(i64, -2) == b);98 try expect(@as(i64, -2) == b);
99}99}
100100
...@@ -387,11 +387,11 @@ fn testLog() !void {...@@ -387,11 +387,11 @@ fn testLog() !void {
387 }387 }
388 {388 {
389 var a: f32 = e;389 var a: f32 = e;
390 try expect(@log(a) == 1 or @log(a) == @bitCast(f32, @as(u32, 0x3f7fffff)));390 try expect(@log(a) == 1 or @log(a) == @as(f32, @bitCast(@as(u32, 0x3f7fffff))));
391 }391 }
392 {392 {
393 var a: f64 = e;393 var a: f64 = e;
394 try expect(@log(a) == 1 or @log(a) == @bitCast(f64, @as(u64, 0x3ff0000000000000)));394 try expect(@log(a) == 1 or @log(a) == @as(f64, @bitCast(@as(u64, 0x3ff0000000000000))));
395 }395 }
396 inline for ([_]type{ f16, f32, f64 }) |ty| {396 inline for ([_]type{ f16, f32, f64 }) |ty| {
397 const eps = epsForType(ty);397 const eps = epsForType(ty);
test/behavior/fn.zig+4-4
...@@ -326,7 +326,7 @@ test "function pointers" {...@@ -326,7 +326,7 @@ test "function pointers" {
326 &fn4,326 &fn4,
327 };327 };
328 for (fns, 0..) |f, i| {328 for (fns, 0..) |f, i| {
329 try expect(f() == @intCast(u32, i) + 5);329 try expect(f() == @as(u32, @intCast(i)) + 5);
330 }330 }
331}331}
332fn fn1() u32 {332fn fn1() u32 {
...@@ -512,8 +512,8 @@ test "using @ptrCast on function pointers" {...@@ -512,8 +512,8 @@ test "using @ptrCast on function pointers" {
512512
513 fn run() !void {513 fn run() !void {
514 const a = A{ .data = "abcd".* };514 const a = A{ .data = "abcd".* };
515 const casted_fn = @ptrCast(*const fn (*const anyopaque, usize) *const u8, &at);515 const casted_fn = @as(*const fn (*const anyopaque, usize) *const u8, @ptrCast(&at));
516 const casted_impl = @ptrCast(*const anyopaque, &a);516 const casted_impl = @as(*const anyopaque, @ptrCast(&a));
517 const ptr = casted_fn(casted_impl, 2);517 const ptr = casted_fn(casted_impl, 2);
518 try expect(ptr.* == 'c');518 try expect(ptr.* == 'c');
519 }519 }
...@@ -575,7 +575,7 @@ test "lazy values passed to anytype parameter" {...@@ -575,7 +575,7 @@ test "lazy values passed to anytype parameter" {
575 try B.foo(.{ .x = @sizeOf(B) });575 try B.foo(.{ .x = @sizeOf(B) });
576576
577 const C = struct {};577 const C = struct {};
578 try expect(@truncate(u32, @sizeOf(C)) == 0);578 try expect(@as(u32, @truncate(@sizeOf(C))) == 0);
579579
580 const D = struct {};580 const D = struct {};
581 try expect(@sizeOf(D) << 1 == 0);581 try expect(@sizeOf(D) << 1 == 0);
test/behavior/fn_in_struct_in_comptime.zig+1-1
...@@ -14,5 +14,5 @@ fn get_foo() fn (*u8) usize {...@@ -14,5 +14,5 @@ fn get_foo() fn (*u8) usize {
1414
15test "define a function in an anonymous struct in comptime" {15test "define a function in an anonymous struct in comptime" {
16 const foo = get_foo();16 const foo = get_foo();
17 try expect(foo(@ptrFromInt(*u8, 12345)) == 12345);17 try expect(foo(@as(*u8, @ptrFromInt(12345))) == 12345);
18}18}
test/behavior/for.zig+5-5
...@@ -84,7 +84,7 @@ test "basic for loop" {...@@ -84,7 +84,7 @@ test "basic for loop" {
84 }84 }
85 for (array, 0..) |item, index| {85 for (array, 0..) |item, index| {
86 _ = item;86 _ = item;
87 buffer[buf_index] = @intCast(u8, index);87 buffer[buf_index] = @as(u8, @intCast(index));
88 buf_index += 1;88 buf_index += 1;
89 }89 }
90 const array_ptr = &array;90 const array_ptr = &array;
...@@ -94,7 +94,7 @@ test "basic for loop" {...@@ -94,7 +94,7 @@ test "basic for loop" {
94 }94 }
95 for (array_ptr, 0..) |item, index| {95 for (array_ptr, 0..) |item, index| {
96 _ = item;96 _ = item;
97 buffer[buf_index] = @intCast(u8, index);97 buffer[buf_index] = @as(u8, @intCast(index));
98 buf_index += 1;98 buf_index += 1;
99 }99 }
100 const unknown_size: []const u8 = &array;100 const unknown_size: []const u8 = &array;
...@@ -103,7 +103,7 @@ test "basic for loop" {...@@ -103,7 +103,7 @@ test "basic for loop" {
103 buf_index += 1;103 buf_index += 1;
104 }104 }
105 for (unknown_size, 0..) |_, index| {105 for (unknown_size, 0..) |_, index| {
106 buffer[buf_index] = @intCast(u8, index);106 buffer[buf_index] = @as(u8, @intCast(index));
107 buf_index += 1;107 buf_index += 1;
108 }108 }
109109
...@@ -208,7 +208,7 @@ test "for on slice with allowzero ptr" {...@@ -208,7 +208,7 @@ test "for on slice with allowzero ptr" {
208208
209 const S = struct {209 const S = struct {
210 fn doTheTest(slice: []const u8) !void {210 fn doTheTest(slice: []const u8) !void {
211 var ptr = @ptrCast([*]allowzero const u8, slice.ptr)[0..slice.len];211 var ptr = @as([*]allowzero const u8, @ptrCast(slice.ptr))[0..slice.len];
212 for (ptr, 0..) |x, i| try expect(x == i + 1);212 for (ptr, 0..) |x, i| try expect(x == i + 1);
213 for (ptr, 0..) |*x, i| try expect(x.* == i + 1);213 for (ptr, 0..) |*x, i| try expect(x.* == i + 1);
214 }214 }
...@@ -393,7 +393,7 @@ test "raw pointer and counter" {...@@ -393,7 +393,7 @@ test "raw pointer and counter" {
393 const ptr: [*]u8 = &buf;393 const ptr: [*]u8 = &buf;
394394
395 for (ptr, 0..4) |*a, b| {395 for (ptr, 0..4) |*a, b| {
396 a.* = @intCast(u8, 'A' + b);396 a.* = @as(u8, @intCast('A' + b));
397 }397 }
398398
399 try expect(buf[0] == 'A');399 try expect(buf[0] == 'A');
test/behavior/generics.zig+3-3
...@@ -97,7 +97,7 @@ test "type constructed by comptime function call" {...@@ -97,7 +97,7 @@ test "type constructed by comptime function call" {
97 l.array[0] = 10;97 l.array[0] = 10;
98 l.array[1] = 11;98 l.array[1] = 11;
99 l.array[2] = 12;99 l.array[2] = 12;
100 const ptr = @ptrCast([*]u8, &l.array);100 const ptr = @as([*]u8, @ptrCast(&l.array));
101 try expect(ptr[0] == 10);101 try expect(ptr[0] == 10);
102 try expect(ptr[1] == 11);102 try expect(ptr[1] == 11);
103 try expect(ptr[2] == 12);103 try expect(ptr[2] == 12);
...@@ -171,7 +171,7 @@ fn getByte(ptr: ?*const u8) u8 {...@@ -171,7 +171,7 @@ fn getByte(ptr: ?*const u8) u8 {
171 return ptr.?.*;171 return ptr.?.*;
172}172}
173fn getFirstByte(comptime T: type, mem: []const T) u8 {173fn getFirstByte(comptime T: type, mem: []const T) u8 {
174 return getByte(@ptrCast(*const u8, &mem[0]));174 return getByte(@as(*const u8, @ptrCast(&mem[0])));
175}175}
176176
177test "generic fn keeps non-generic parameter types" {177test "generic fn keeps non-generic parameter types" {
...@@ -428,7 +428,7 @@ test "null sentinel pointer passed as generic argument" {...@@ -428,7 +428,7 @@ test "null sentinel pointer passed as generic argument" {
428 try std.testing.expect(@intFromPtr(a) == 8);428 try std.testing.expect(@intFromPtr(a) == 8);
429 }429 }
430 };430 };
431 try S.doTheTest((@ptrFromInt([*:null]const [*c]const u8, 8)));431 try S.doTheTest((@as([*:null]const [*c]const u8, @ptrFromInt(8))));
432}432}
433433
434test "generic function passed as comptime argument" {434test "generic function passed as comptime argument" {
test/behavior/int128.zig+8-8
...@@ -38,7 +38,7 @@ test "undefined 128 bit int" {...@@ -38,7 +38,7 @@ test "undefined 128 bit int" {
3838
39 var undef: u128 = undefined;39 var undef: u128 = undefined;
40 var undef_signed: i128 = undefined;40 var undef_signed: i128 = undefined;
41 try expect(undef == 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa and @bitCast(u128, undef_signed) == undef);41 try expect(undef == 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa and @as(u128, @bitCast(undef_signed)) == undef);
42}42}
4343
44test "int128" {44test "int128" {
...@@ -49,7 +49,7 @@ test "int128" {...@@ -49,7 +49,7 @@ test "int128" {
4949
50 var buff: i128 = -1;50 var buff: i128 = -1;
51 try expect(buff < 0 and (buff + 1) == 0);51 try expect(buff < 0 and (buff + 1) == 0);
52 try expect(@intCast(i8, buff) == @as(i8, -1));52 try expect(@as(i8, @intCast(buff)) == @as(i8, -1));
5353
54 buff = minInt(i128);54 buff = minInt(i128);
55 try expect(buff < 0);55 try expect(buff < 0);
...@@ -73,16 +73,16 @@ test "truncate int128" {...@@ -73,16 +73,16 @@ test "truncate int128" {
7373
74 {74 {
75 var buff: u128 = maxInt(u128);75 var buff: u128 = maxInt(u128);
76 try expect(@truncate(u64, buff) == maxInt(u64));76 try expect(@as(u64, @truncate(buff)) == maxInt(u64));
77 try expect(@truncate(u90, buff) == maxInt(u90));77 try expect(@as(u90, @truncate(buff)) == maxInt(u90));
78 try expect(@truncate(u128, buff) == maxInt(u128));78 try expect(@as(u128, @truncate(buff)) == maxInt(u128));
79 }79 }
8080
81 {81 {
82 var buff: i128 = maxInt(i128);82 var buff: i128 = maxInt(i128);
83 try expect(@truncate(i64, buff) == -1);83 try expect(@as(i64, @truncate(buff)) == -1);
84 try expect(@truncate(i90, buff) == -1);84 try expect(@as(i90, @truncate(buff)) == -1);
85 try expect(@truncate(i128, buff) == maxInt(i128));85 try expect(@as(i128, @truncate(buff)) == maxInt(i128));
86 }86 }
87}87}
8888
test/behavior/math.zig+10-10
...@@ -391,11 +391,11 @@ test "binary not 128-bit" {...@@ -391,11 +391,11 @@ test "binary not 128-bit" {
391 break :x ~@as(u128, 0x55555555_55555555_55555555_55555555) == 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa;391 break :x ~@as(u128, 0x55555555_55555555_55555555_55555555) == 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa;
392 });392 });
393 try expect(comptime x: {393 try expect(comptime x: {
394 break :x ~@as(i128, 0x55555555_55555555_55555555_55555555) == @bitCast(i128, @as(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa));394 break :x ~@as(i128, 0x55555555_55555555_55555555_55555555) == @as(i128, @bitCast(@as(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa)));
395 });395 });
396396
397 try testBinaryNot128(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa);397 try testBinaryNot128(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa);
398 try testBinaryNot128(i128, @bitCast(i128, @as(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa)));398 try testBinaryNot128(i128, @as(i128, @bitCast(@as(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa))));
399}399}
400400
401fn testBinaryNot128(comptime Type: type, x: Type) !void {401fn testBinaryNot128(comptime Type: type, x: Type) !void {
...@@ -1156,29 +1156,29 @@ test "quad hex float literal parsing accurate" {...@@ -1156,29 +1156,29 @@ test "quad hex float literal parsing accurate" {
11561156
1157 // implied 1 is dropped, with an exponent of 0 (0x3fff) after biasing.1157 // implied 1 is dropped, with an exponent of 0 (0x3fff) after biasing.
1158 const expected: u128 = 0x3fff1111222233334444555566667777;1158 const expected: u128 = 0x3fff1111222233334444555566667777;
1159 try expect(@bitCast(u128, a) == expected);1159 try expect(@as(u128, @bitCast(a)) == expected);
11601160
1161 // non-normalized1161 // non-normalized
1162 const b: f128 = 0x11.111222233334444555566667777p-4;1162 const b: f128 = 0x11.111222233334444555566667777p-4;
1163 try expect(@bitCast(u128, b) == expected);1163 try expect(@as(u128, @bitCast(b)) == expected);
11641164
1165 const S = struct {1165 const S = struct {
1166 fn doTheTest() !void {1166 fn doTheTest() !void {
1167 {1167 {
1168 var f: f128 = 0x1.2eab345678439abcdefea56782346p+5;1168 var f: f128 = 0x1.2eab345678439abcdefea56782346p+5;
1169 try expect(@bitCast(u128, f) == 0x40042eab345678439abcdefea5678234);1169 try expect(@as(u128, @bitCast(f)) == 0x40042eab345678439abcdefea5678234);
1170 }1170 }
1171 {1171 {
1172 var f: f128 = 0x1.edcb34a235253948765432134674fp-1;1172 var f: f128 = 0x1.edcb34a235253948765432134674fp-1;
1173 try expect(@bitCast(u128, f) == 0x3ffeedcb34a235253948765432134675); // round-to-even1173 try expect(@as(u128, @bitCast(f)) == 0x3ffeedcb34a235253948765432134675); // round-to-even
1174 }1174 }
1175 {1175 {
1176 var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50;1176 var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50;
1177 try expect(@bitCast(u128, f) == 0x3fcd353e45674d89abacc3a2ebf3ff50);1177 try expect(@as(u128, @bitCast(f)) == 0x3fcd353e45674d89abacc3a2ebf3ff50);
1178 }1178 }
1179 {1179 {
1180 var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9;1180 var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9;
1181 try expect(@bitCast(u128, f) == 0x3ff6ed8764648369535adf4be3214568);1181 try expect(@as(u128, @bitCast(f)) == 0x3ff6ed8764648369535adf4be3214568);
1182 }1182 }
1183 const exp2ft = [_]f64{1183 const exp2ft = [_]f64{
1184 0x1.6a09e667f3bcdp-1,1184 0x1.6a09e667f3bcdp-1,
...@@ -1233,7 +1233,7 @@ test "quad hex float literal parsing accurate" {...@@ -1233,7 +1233,7 @@ test "quad hex float literal parsing accurate" {
1233 };1233 };
12341234
1235 for (exp2ft, 0..) |x, i| {1235 for (exp2ft, 0..) |x, i| {
1236 try expect(@bitCast(u64, x) == answers[i]);1236 try expect(@as(u64, @bitCast(x)) == answers[i]);
1237 }1237 }
1238 }1238 }
1239 };1239 };
...@@ -1586,7 +1586,7 @@ test "signed zeros are represented properly" {...@@ -1586,7 +1586,7 @@ test "signed zeros are represented properly" {
1586 fn testOne(comptime T: type) !void {1586 fn testOne(comptime T: type) !void {
1587 const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);1587 const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
1588 var as_fp_val = -@as(T, 0.0);1588 var as_fp_val = -@as(T, 0.0);
1589 var as_uint_val = @bitCast(ST, as_fp_val);1589 var as_uint_val = @as(ST, @bitCast(as_fp_val));
1590 // Ensure the sign bit is set.1590 // Ensure the sign bit is set.
1591 try expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1);1591 try expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1);
1592 }1592 }
test/behavior/memcpy.zig+1-1
...@@ -59,7 +59,7 @@ fn testMemcpyDestManyPtr() !void {...@@ -59,7 +59,7 @@ fn testMemcpyDestManyPtr() !void {
59 var str = "hello".*;59 var str = "hello".*;
60 var buf: [5]u8 = undefined;60 var buf: [5]u8 = undefined;
61 var len: usize = 5;61 var len: usize = 5;
62 @memcpy(@ptrCast([*]u8, &buf), @ptrCast([*]const u8, &str)[0..len]);62 @memcpy(@as([*]u8, @ptrCast(&buf)), @as([*]const u8, @ptrCast(&str))[0..len]);
63 try expect(buf[0] == 'h');63 try expect(buf[0] == 'h');
64 try expect(buf[1] == 'e');64 try expect(buf[1] == 'e');
65 try expect(buf[2] == 'l');65 try expect(buf[2] == 'l');
test/behavior/packed-struct.zig+5-5
...@@ -166,7 +166,7 @@ test "correct sizeOf and offsets in packed structs" {...@@ -166,7 +166,7 @@ test "correct sizeOf and offsets in packed structs" {
166 try expectEqual(4, @sizeOf(PStruct));166 try expectEqual(4, @sizeOf(PStruct));
167167
168 if (native_endian == .Little) {168 if (native_endian == .Little) {
169 const s1 = @bitCast(PStruct, @as(u32, 0x12345678));169 const s1 = @as(PStruct, @bitCast(@as(u32, 0x12345678)));
170 try expectEqual(false, s1.bool_a);170 try expectEqual(false, s1.bool_a);
171 try expectEqual(false, s1.bool_b);171 try expectEqual(false, s1.bool_b);
172 try expectEqual(false, s1.bool_c);172 try expectEqual(false, s1.bool_c);
...@@ -180,7 +180,7 @@ test "correct sizeOf and offsets in packed structs" {...@@ -180,7 +180,7 @@ test "correct sizeOf and offsets in packed structs" {
180 try expectEqual(@as(u10, 0b1101000101), s1.u10_a);180 try expectEqual(@as(u10, 0b1101000101), s1.u10_a);
181 try expectEqual(@as(u10, 0b0001001000), s1.u10_b);181 try expectEqual(@as(u10, 0b0001001000), s1.u10_b);
182182
183 const s2 = @bitCast(packed struct { x: u1, y: u7, z: u24 }, @as(u32, 0xd5c71ff4));183 const s2 = @as(packed struct { x: u1, y: u7, z: u24 }, @bitCast(@as(u32, 0xd5c71ff4)));
184 try expectEqual(@as(u1, 0), s2.x);184 try expectEqual(@as(u1, 0), s2.x);
185 try expectEqual(@as(u7, 0b1111010), s2.y);185 try expectEqual(@as(u7, 0b1111010), s2.y);
186 try expectEqual(@as(u24, 0xd5c71f), s2.z);186 try expectEqual(@as(u24, 0xd5c71f), s2.z);
...@@ -207,7 +207,7 @@ test "nested packed structs" {...@@ -207,7 +207,7 @@ test "nested packed structs" {
207 try expectEqual(24, @bitOffsetOf(S3, "y"));207 try expectEqual(24, @bitOffsetOf(S3, "y"));
208208
209 if (native_endian == .Little) {209 if (native_endian == .Little) {
210 const s3 = @bitCast(S3Padded, @as(u64, 0xe952d5c71ff4)).s3;210 const s3 = @as(S3Padded, @bitCast(@as(u64, 0xe952d5c71ff4))).s3;
211 try expectEqual(@as(u8, 0xf4), s3.x.a);211 try expectEqual(@as(u8, 0xf4), s3.x.a);
212 try expectEqual(@as(u8, 0x1f), s3.x.b);212 try expectEqual(@as(u8, 0x1f), s3.x.b);
213 try expectEqual(@as(u8, 0xc7), s3.x.c);213 try expectEqual(@as(u8, 0xc7), s3.x.c);
...@@ -600,7 +600,7 @@ test "packed struct initialized in bitcast" {...@@ -600,7 +600,7 @@ test "packed struct initialized in bitcast" {
600600
601 const T = packed struct { val: u8 };601 const T = packed struct { val: u8 };
602 var val: u8 = 123;602 var val: u8 = 123;
603 const t = @bitCast(u8, T{ .val = val });603 const t = @as(u8, @bitCast(T{ .val = val }));
604 try expect(t == val);604 try expect(t == val);
605}605}
606606
...@@ -627,7 +627,7 @@ test "pointer to container level packed struct field" {...@@ -627,7 +627,7 @@ test "pointer to container level packed struct field" {
627 },627 },
628 var arr = [_]u32{0} ** 2;628 var arr = [_]u32{0} ** 2;
629 };629 };
630 @ptrCast(*S, &S.arr[0]).other_bits.enable_3 = true;630 @as(*S, @ptrCast(&S.arr[0])).other_bits.enable_3 = true;
631 try expect(S.arr[0] == 0x10000000);631 try expect(S.arr[0] == 0x10000000);
632}632}
633633
test/behavior/packed_struct_explicit_backing_int.zig+1-1
...@@ -25,7 +25,7 @@ test "packed struct explicit backing integer" {...@@ -25,7 +25,7 @@ test "packed struct explicit backing integer" {
25 try expectEqual(24, @bitOffsetOf(S3, "y"));25 try expectEqual(24, @bitOffsetOf(S3, "y"));
2626
27 if (native_endian == .Little) {27 if (native_endian == .Little) {
28 const s3 = @bitCast(S3Padded, @as(u64, 0xe952d5c71ff4)).s3;28 const s3 = @as(S3Padded, @bitCast(@as(u64, 0xe952d5c71ff4))).s3;
29 try expectEqual(@as(u8, 0xf4), s3.x.a);29 try expectEqual(@as(u8, 0xf4), s3.x.a);
30 try expectEqual(@as(u8, 0x1f), s3.x.b);30 try expectEqual(@as(u8, 0x1f), s3.x.b);
31 try expectEqual(@as(u8, 0xc7), s3.x.c);31 try expectEqual(@as(u8, 0xc7), s3.x.c);
test/behavior/pointers.zig+12-12
...@@ -184,8 +184,8 @@ test "implicit cast error unions with non-optional to optional pointer" {...@@ -184,8 +184,8 @@ test "implicit cast error unions with non-optional to optional pointer" {
184}184}
185185
186test "compare equality of optional and non-optional pointer" {186test "compare equality of optional and non-optional pointer" {
187 const a = @ptrFromInt(*const usize, 0x12345678);187 const a = @as(*const usize, @ptrFromInt(0x12345678));
188 const b = @ptrFromInt(?*usize, 0x12345678);188 const b = @as(?*usize, @ptrFromInt(0x12345678));
189 try expect(a == b);189 try expect(a == b);
190 try expect(b == a);190 try expect(b == a);
191}191}
...@@ -197,7 +197,7 @@ test "allowzero pointer and slice" {...@@ -197,7 +197,7 @@ test "allowzero pointer and slice" {
197 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO197 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
198 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;198 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
199199
200 var ptr = @ptrFromInt([*]allowzero i32, 0);200 var ptr = @as([*]allowzero i32, @ptrFromInt(0));
201 var opt_ptr: ?[*]allowzero i32 = ptr;201 var opt_ptr: ?[*]allowzero i32 = ptr;
202 try expect(opt_ptr != null);202 try expect(opt_ptr != null);
203 try expect(@intFromPtr(ptr) == 0);203 try expect(@intFromPtr(ptr) == 0);
...@@ -286,9 +286,9 @@ test "null terminated pointer" {...@@ -286,9 +286,9 @@ test "null terminated pointer" {
286 const S = struct {286 const S = struct {
287 fn doTheTest() !void {287 fn doTheTest() !void {
288 var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' };288 var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' };
289 var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero);289 var zero_ptr: [*:0]const u8 = @as([*:0]const u8, @ptrCast(&array_with_zero));
290 var no_zero_ptr: [*]const u8 = zero_ptr;290 var no_zero_ptr: [*]const u8 = zero_ptr;
291 var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr);291 var zero_ptr_again = @as([*:0]const u8, @ptrCast(no_zero_ptr));
292 try expect(std.mem.eql(u8, std.mem.sliceTo(zero_ptr_again, 0), "hello"));292 try expect(std.mem.eql(u8, std.mem.sliceTo(zero_ptr_again, 0), "hello"));
293 }293 }
294 };294 };
...@@ -367,7 +367,7 @@ test "pointer sentinel with +inf" {...@@ -367,7 +367,7 @@ test "pointer sentinel with +inf" {
367}367}
368368
369test "pointer to array at fixed address" {369test "pointer to array at fixed address" {
370 const array = @ptrFromInt(*volatile [2]u32, 0x10);370 const array = @as(*volatile [2]u32, @ptrFromInt(0x10));
371 // Silly check just to reference `array`371 // Silly check just to reference `array`
372 try expect(@intFromPtr(&array[0]) == 0x10);372 try expect(@intFromPtr(&array[0]) == 0x10);
373 try expect(@intFromPtr(&array[1]) == 0x14);373 try expect(@intFromPtr(&array[1]) == 0x14);
...@@ -406,13 +406,13 @@ test "pointer arithmetic affects the alignment" {...@@ -406,13 +406,13 @@ test "pointer arithmetic affects the alignment" {
406406
407test "@intFromPtr on null optional at comptime" {407test "@intFromPtr on null optional at comptime" {
408 {408 {
409 const pointer = @ptrFromInt(?*u8, 0x000);409 const pointer = @as(?*u8, @ptrFromInt(0x000));
410 const x = @intFromPtr(pointer);410 const x = @intFromPtr(pointer);
411 _ = x;411 _ = x;
412 try comptime expect(0 == @intFromPtr(pointer));412 try comptime expect(0 == @intFromPtr(pointer));
413 }413 }
414 {414 {
415 const pointer = @ptrFromInt(?*u8, 0xf00);415 const pointer = @as(?*u8, @ptrFromInt(0xf00));
416 try comptime expect(0xf00 == @intFromPtr(pointer));416 try comptime expect(0xf00 == @intFromPtr(pointer));
417 }417 }
418}418}
...@@ -463,8 +463,8 @@ test "element pointer arithmetic to slice" {...@@ -463,8 +463,8 @@ test "element pointer arithmetic to slice" {
463 };463 };
464464
465 const elem_ptr = &cases[0]; // *[2]i32465 const elem_ptr = &cases[0]; // *[2]i32
466 const many = @ptrCast([*][2]i32, elem_ptr);466 const many = @as([*][2]i32, @ptrCast(elem_ptr));
467 const many_elem = @ptrCast(*[2]i32, &many[1]);467 const many_elem = @as(*[2]i32, @ptrCast(&many[1]));
468 const items: []i32 = many_elem;468 const items: []i32 = many_elem;
469 try testing.expect(items.len == 2);469 try testing.expect(items.len == 2);
470 try testing.expect(items[1] == 3);470 try testing.expect(items[1] == 3);
...@@ -512,7 +512,7 @@ test "ptrCast comptime known slice to C pointer" {...@@ -512,7 +512,7 @@ test "ptrCast comptime known slice to C pointer" {
512 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;512 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
513513
514 const s: [:0]const u8 = "foo";514 const s: [:0]const u8 = "foo";
515 var p = @ptrCast([*c]const u8, s);515 var p = @as([*c]const u8, @ptrCast(s));
516 try std.testing.expectEqualStrings(s, std.mem.sliceTo(p, 0));516 try std.testing.expectEqualStrings(s, std.mem.sliceTo(p, 0));
517}517}
518518
...@@ -550,7 +550,7 @@ test "pointer to array has explicit alignment" {...@@ -550,7 +550,7 @@ test "pointer to array has explicit alignment" {
550 const Base = extern struct { a: u8 };550 const Base = extern struct { a: u8 };
551 const Base2 = extern struct { a: u8 };551 const Base2 = extern struct { a: u8 };
552 fn func(ptr: *[4]Base) *align(1) [4]Base2 {552 fn func(ptr: *[4]Base) *align(1) [4]Base2 {
553 return @alignCast(1, @ptrCast(*[4]Base2, ptr));553 return @alignCast(@as(*[4]Base2, @ptrCast(ptr)));
554 }554 }
555 };555 };
556 var bases = [_]S.Base{.{ .a = 2 }} ** 4;556 var bases = [_]S.Base{.{ .a = 2 }} ** 4;
test/behavior/popcount.zig+1-1
...@@ -63,7 +63,7 @@ fn testPopCountIntegers() !void {...@@ -63,7 +63,7 @@ fn testPopCountIntegers() !void {
63 try expect(@popCount(x) == 2);63 try expect(@popCount(x) == 2);
64 }64 }
65 comptime {65 comptime {
66 try expect(@popCount(@bitCast(u8, @as(i8, -120))) == 2);66 try expect(@popCount(@as(u8, @bitCast(@as(i8, -120)))) == 2);
67 }67 }
68}68}
6969
test/behavior/ptrcast.zig+17-27
...@@ -16,7 +16,7 @@ fn testReinterpretBytesAsInteger() !void {...@@ -16,7 +16,7 @@ fn testReinterpretBytesAsInteger() !void {
16 .Little => 0xab785634,16 .Little => 0xab785634,
17 .Big => 0x345678ab,17 .Big => 0x345678ab,
18 };18 };
19 try expect(@ptrCast(*align(1) const u32, bytes[1..5]).* == expected);19 try expect(@as(*align(1) const u32, @ptrCast(bytes[1..5])).* == expected);
20}20}
2121
22test "reinterpret an array over multiple elements, with no well-defined layout" {22test "reinterpret an array over multiple elements, with no well-defined layout" {
...@@ -32,7 +32,7 @@ test "reinterpret an array over multiple elements, with no well-defined layout"...@@ -32,7 +32,7 @@ test "reinterpret an array over multiple elements, with no well-defined layout"
32fn testReinterpretWithOffsetAndNoWellDefinedLayout() !void {32fn testReinterpretWithOffsetAndNoWellDefinedLayout() !void {
33 const bytes: ?[5]?u8 = [5]?u8{ 0x12, 0x34, 0x56, 0x78, 0x9a };33 const bytes: ?[5]?u8 = [5]?u8{ 0x12, 0x34, 0x56, 0x78, 0x9a };
34 const ptr = &bytes.?[1];34 const ptr = &bytes.?[1];
35 const copy: [4]?u8 = @ptrCast(*const [4]?u8, ptr).*;35 const copy: [4]?u8 = @as(*const [4]?u8, @ptrCast(ptr)).*;
36 _ = copy;36 _ = copy;
37 //try expect(@ptrCast(*align(1)?u8, bytes[1..5]).* == );37 //try expect(@ptrCast(*align(1)?u8, bytes[1..5]).* == );
38}38}
...@@ -51,7 +51,7 @@ fn testReinterpretStructWrappedBytesAsInteger() !void {...@@ -51,7 +51,7 @@ fn testReinterpretStructWrappedBytesAsInteger() !void {
51 .Little => 0xab785634,51 .Little => 0xab785634,
52 .Big => 0x345678ab,52 .Big => 0x345678ab,
53 };53 };
54 try expect(@ptrCast(*align(1) const u32, obj.bytes[1..5]).* == expected);54 try expect(@as(*align(1) const u32, @ptrCast(obj.bytes[1..5])).* == expected);
55}55}
5656
57test "reinterpret bytes of an array into an extern struct" {57test "reinterpret bytes of an array into an extern struct" {
...@@ -71,7 +71,7 @@ fn testReinterpretBytesAsExternStruct() !void {...@@ -71,7 +71,7 @@ fn testReinterpretBytesAsExternStruct() !void {
71 c: u8,71 c: u8,
72 };72 };
7373
74 var ptr = @ptrCast(*const S, &bytes);74 var ptr = @as(*const S, @ptrCast(&bytes));
75 var val = ptr.c;75 var val = ptr.c;
76 try expect(val == 5);76 try expect(val == 5);
77}77}
...@@ -95,7 +95,7 @@ fn testReinterpretExternStructAsExternStruct() !void {...@@ -95,7 +95,7 @@ fn testReinterpretExternStructAsExternStruct() !void {
95 a: u32 align(2),95 a: u32 align(2),
96 c: u8,96 c: u8,
97 };97 };
98 var ptr = @ptrCast(*const S2, &bytes);98 var ptr = @as(*const S2, @ptrCast(&bytes));
99 var val = ptr.c;99 var val = ptr.c;
100 try expect(val == 5);100 try expect(val == 5);
101}101}
...@@ -121,7 +121,7 @@ fn testReinterpretOverAlignedExternStructAsExternStruct() !void {...@@ -121,7 +121,7 @@ fn testReinterpretOverAlignedExternStructAsExternStruct() !void {
121 a2: u16,121 a2: u16,
122 c: u8,122 c: u8,
123 };123 };
124 var ptr = @ptrCast(*const S2, &bytes);124 var ptr = @as(*const S2, @ptrCast(&bytes));
125 var val = ptr.c;125 var val = ptr.c;
126 try expect(val == 5);126 try expect(val == 5);
127}127}
...@@ -138,13 +138,13 @@ test "lower reinterpreted comptime field ptr (with under-aligned fields)" {...@@ -138,13 +138,13 @@ test "lower reinterpreted comptime field ptr (with under-aligned fields)" {
138 a: u32 align(2),138 a: u32 align(2),
139 c: u8,139 c: u8,
140 };140 };
141 comptime var ptr = @ptrCast(*const S, &bytes);141 comptime var ptr = @as(*const S, @ptrCast(&bytes));
142 var val = &ptr.c;142 var val = &ptr.c;
143 try expect(val.* == 5);143 try expect(val.* == 5);
144144
145 // Test lowering an elem ptr145 // Test lowering an elem ptr
146 comptime var src_value = S{ .a = 15, .c = 5 };146 comptime var src_value = S{ .a = 15, .c = 5 };
147 comptime var ptr2 = @ptrCast(*[@sizeOf(S)]u8, &src_value);147 comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value));
148 var val2 = &ptr2[4];148 var val2 = &ptr2[4];
149 try expect(val2.* == 5);149 try expect(val2.* == 5);
150}150}
...@@ -161,13 +161,13 @@ test "lower reinterpreted comptime field ptr" {...@@ -161,13 +161,13 @@ test "lower reinterpreted comptime field ptr" {
161 a: u32,161 a: u32,
162 c: u8,162 c: u8,
163 };163 };
164 comptime var ptr = @ptrCast(*const S, &bytes);164 comptime var ptr = @as(*const S, @ptrCast(&bytes));
165 var val = &ptr.c;165 var val = &ptr.c;
166 try expect(val.* == 5);166 try expect(val.* == 5);
167167
168 // Test lowering an elem ptr168 // Test lowering an elem ptr
169 comptime var src_value = S{ .a = 15, .c = 5 };169 comptime var src_value = S{ .a = 15, .c = 5 };
170 comptime var ptr2 = @ptrCast(*[@sizeOf(S)]u8, &src_value);170 comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value));
171 var val2 = &ptr2[4];171 var val2 = &ptr2[4];
172 try expect(val2.* == 5);172 try expect(val2.* == 5);
173}173}
...@@ -190,27 +190,17 @@ const Bytes = struct {...@@ -190,27 +190,17 @@ const Bytes = struct {
190190
191 pub fn init(v: u32) Bytes {191 pub fn init(v: u32) Bytes {
192 var res: Bytes = undefined;192 var res: Bytes = undefined;
193 @ptrCast(*align(1) u32, &res.bytes).* = v;193 @as(*align(1) u32, @ptrCast(&res.bytes)).* = v;
194194
195 return res;195 return res;
196 }196 }
197};197};
198198
199test "comptime ptrcast keeps larger alignment" {
200 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
201
202 comptime {
203 const a: u32 = 1234;
204 const p = @ptrCast([*]const u8, &a);
205 try expect(@TypeOf(p) == [*]align(@alignOf(u32)) const u8);
206 }
207}
208
209test "ptrcast of const integer has the correct object size" {199test "ptrcast of const integer has the correct object size" {
210 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO200 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
211201
212 const is_value = ~@intCast(isize, std.math.minInt(isize));202 const is_value = ~@as(isize, @intCast(std.math.minInt(isize)));
213 const is_bytes = @ptrCast([*]const u8, &is_value)[0..@sizeOf(isize)];203 const is_bytes = @as([*]const u8, @ptrCast(&is_value))[0..@sizeOf(isize)];
214 if (@sizeOf(isize) == 8) {204 if (@sizeOf(isize) == 8) {
215 switch (native_endian) {205 switch (native_endian) {
216 .Little => {206 .Little => {
...@@ -248,7 +238,7 @@ test "implicit optional pointer to optional anyopaque pointer" {...@@ -248,7 +238,7 @@ test "implicit optional pointer to optional anyopaque pointer" {
248 var buf: [4]u8 = "aoeu".*;238 var buf: [4]u8 = "aoeu".*;
249 var x: ?[*]u8 = &buf;239 var x: ?[*]u8 = &buf;
250 var y: ?*anyopaque = x;240 var y: ?*anyopaque = x;
251 var z = @ptrCast(*[4]u8, y);241 var z = @as(*[4]u8, @ptrCast(y));
252 try expect(std.mem.eql(u8, z, "aoeu"));242 try expect(std.mem.eql(u8, z, "aoeu"));
253}243}
254244
...@@ -260,7 +250,7 @@ test "@ptrCast slice to slice" {...@@ -260,7 +250,7 @@ test "@ptrCast slice to slice" {
260250
261 const S = struct {251 const S = struct {
262 fn foo(slice: []u32) []i32 {252 fn foo(slice: []u32) []i32 {
263 return @ptrCast([]i32, slice);253 return @as([]i32, @ptrCast(slice));
264 }254 }
265 };255 };
266 var buf: [4]u32 = .{ 0, 0, 0, 0 };256 var buf: [4]u32 = .{ 0, 0, 0, 0 };
...@@ -277,7 +267,7 @@ test "comptime @ptrCast a subset of an array, then write through it" {...@@ -277,7 +267,7 @@ test "comptime @ptrCast a subset of an array, then write through it" {
277267
278 comptime {268 comptime {
279 var buff: [16]u8 align(4) = undefined;269 var buff: [16]u8 align(4) = undefined;
280 const len_bytes = @ptrCast(*u32, &buff);270 const len_bytes = @as(*u32, @ptrCast(&buff));
281 len_bytes.* = 16;271 len_bytes.* = 16;
282 std.mem.copy(u8, buff[4..], "abcdef");272 std.mem.copy(u8, buff[4..], "abcdef");
283 }273 }
...@@ -286,7 +276,7 @@ test "comptime @ptrCast a subset of an array, then write through it" {...@@ -286,7 +276,7 @@ test "comptime @ptrCast a subset of an array, then write through it" {
286test "@ptrCast undefined value at comptime" {276test "@ptrCast undefined value at comptime" {
287 const S = struct {277 const S = struct {
288 fn transmute(comptime T: type, comptime U: type, value: T) U {278 fn transmute(comptime T: type, comptime U: type, value: T) U {
289 return @ptrCast(*const U, &value).*;279 return @as(*const U, @ptrCast(&value)).*;
290 }280 }
291 };281 };
292 comptime {282 comptime {
test/behavior/ptrfromint.zig+4-4
...@@ -9,7 +9,7 @@ test "casting integer address to function pointer" {...@@ -9,7 +9,7 @@ test "casting integer address to function pointer" {
99
10fn addressToFunction() void {10fn addressToFunction() void {
11 var addr: usize = 0xdeadbee0;11 var addr: usize = 0xdeadbee0;
12 _ = @ptrFromInt(*const fn () void, addr);12 _ = @as(*const fn () void, @ptrFromInt(addr));
13}13}
1414
15test "mutate through ptr initialized with constant ptrFromInt value" {15test "mutate through ptr initialized with constant ptrFromInt value" {
...@@ -21,7 +21,7 @@ test "mutate through ptr initialized with constant ptrFromInt value" {...@@ -21,7 +21,7 @@ test "mutate through ptr initialized with constant ptrFromInt value" {
21}21}
2222
23fn forceCompilerAnalyzeBranchHardCodedPtrDereference(x: bool) void {23fn forceCompilerAnalyzeBranchHardCodedPtrDereference(x: bool) void {
24 const hardCodedP = @ptrFromInt(*volatile u8, 0xdeadbeef);24 const hardCodedP = @as(*volatile u8, @ptrFromInt(0xdeadbeef));
25 if (x) {25 if (x) {
26 hardCodedP.* = hardCodedP.* | 10;26 hardCodedP.* = hardCodedP.* | 10;
27 } else {27 } else {
...@@ -34,7 +34,7 @@ test "@ptrFromInt creates null pointer" {...@@ -34,7 +34,7 @@ test "@ptrFromInt creates null pointer" {
34 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;34 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
35 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO35 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
3636
37 const ptr = @ptrFromInt(?*u32, 0);37 const ptr = @as(?*u32, @ptrFromInt(0));
38 try expectEqual(@as(?*u32, null), ptr);38 try expectEqual(@as(?*u32, null), ptr);
39}39}
4040
...@@ -43,6 +43,6 @@ test "@ptrFromInt creates allowzero zero pointer" {...@@ -43,6 +43,6 @@ test "@ptrFromInt creates allowzero zero pointer" {
43 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;43 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
44 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO44 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
4545
46 const ptr = @ptrFromInt(*allowzero u32, 0);46 const ptr = @as(*allowzero u32, @ptrFromInt(0));
47 try expectEqual(@as(usize, 0), @intFromPtr(ptr));47 try expectEqual(@as(usize, 0), @intFromPtr(ptr));
48}48}
test/behavior/sizeof_and_typeof.zig+2-2
...@@ -231,7 +231,7 @@ test "@sizeOf comparison against zero" {...@@ -231,7 +231,7 @@ test "@sizeOf comparison against zero" {
231231
232test "hardcoded address in typeof expression" {232test "hardcoded address in typeof expression" {
233 const S = struct {233 const S = struct {
234 fn func() @TypeOf(@ptrFromInt(*[]u8, 0x10).*[0]) {234 fn func() @TypeOf(@as(*[]u8, @ptrFromInt(0x10)).*[0]) {
235 return 0;235 return 0;
236 }236 }
237 };237 };
...@@ -252,7 +252,7 @@ test "array access of generic param in typeof expression" {...@@ -252,7 +252,7 @@ test "array access of generic param in typeof expression" {
252test "lazy size cast to float" {252test "lazy size cast to float" {
253 {253 {
254 const S = struct { a: u8 };254 const S = struct { a: u8 };
255 try expect(@floatFromInt(f32, @sizeOf(S)) == 1.0);255 try expect(@as(f32, @floatFromInt(@sizeOf(S))) == 1.0);
256 }256 }
257 {257 {
258 const S = struct { a: u8 };258 const S = struct { a: u8 };
test/behavior/slice.zig+10-10
...@@ -129,7 +129,7 @@ test "generic malloc free" {...@@ -129,7 +129,7 @@ test "generic malloc free" {
129}129}
130var some_mem: [100]u8 = undefined;130var some_mem: [100]u8 = undefined;
131fn memAlloc(comptime T: type, n: usize) anyerror![]T {131fn memAlloc(comptime T: type, n: usize) anyerror![]T {
132 return @ptrCast([*]T, &some_mem[0])[0..n];132 return @as([*]T, @ptrCast(&some_mem[0]))[0..n];
133}133}
134fn memFree(comptime T: type, memory: []T) void {134fn memFree(comptime T: type, memory: []T) void {
135 _ = memory;135 _ = memory;
...@@ -138,7 +138,7 @@ fn memFree(comptime T: type, memory: []T) void {...@@ -138,7 +138,7 @@ fn memFree(comptime T: type, memory: []T) void {
138test "slice of hardcoded address to pointer" {138test "slice of hardcoded address to pointer" {
139 const S = struct {139 const S = struct {
140 fn doTheTest() !void {140 fn doTheTest() !void {
141 const pointer = @ptrFromInt([*]u8, 0x04)[0..2];141 const pointer = @as([*]u8, @ptrFromInt(0x04))[0..2];
142 try comptime expect(@TypeOf(pointer) == *[2]u8);142 try comptime expect(@TypeOf(pointer) == *[2]u8);
143 const slice: []const u8 = pointer;143 const slice: []const u8 = pointer;
144 try expect(@intFromPtr(slice.ptr) == 4);144 try expect(@intFromPtr(slice.ptr) == 4);
...@@ -152,7 +152,7 @@ test "slice of hardcoded address to pointer" {...@@ -152,7 +152,7 @@ test "slice of hardcoded address to pointer" {
152test "comptime slice of pointer preserves comptime var" {152test "comptime slice of pointer preserves comptime var" {
153 comptime {153 comptime {
154 var buff: [10]u8 = undefined;154 var buff: [10]u8 = undefined;
155 var a = @ptrCast([*]u8, &buff);155 var a = @as([*]u8, @ptrCast(&buff));
156 a[0..1][0] = 1;156 a[0..1][0] = 1;
157 try expect(buff[0..][0..][0] == 1);157 try expect(buff[0..][0..][0] == 1);
158 }158 }
...@@ -161,7 +161,7 @@ test "comptime slice of pointer preserves comptime var" {...@@ -161,7 +161,7 @@ test "comptime slice of pointer preserves comptime var" {
161test "comptime pointer cast array and then slice" {161test "comptime pointer cast array and then slice" {
162 const array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };162 const array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };
163163
164 const ptrA: [*]const u8 = @ptrCast([*]const u8, &array);164 const ptrA: [*]const u8 = @as([*]const u8, @ptrCast(&array));
165 const sliceA: []const u8 = ptrA[0..2];165 const sliceA: []const u8 = ptrA[0..2];
166166
167 const ptrB: [*]const u8 = &array;167 const ptrB: [*]const u8 = &array;
...@@ -188,7 +188,7 @@ test "slicing pointer by length" {...@@ -188,7 +188,7 @@ test "slicing pointer by length" {
188 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;188 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
189189
190 const array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };190 const array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };
191 const ptr: [*]const u8 = @ptrCast([*]const u8, &array);191 const ptr: [*]const u8 = @as([*]const u8, @ptrCast(&array));
192 const slice = ptr[1..][0..5];192 const slice = ptr[1..][0..5];
193 try expect(slice.len == 5);193 try expect(slice.len == 5);
194 var i: usize = 0;194 var i: usize = 0;
...@@ -197,7 +197,7 @@ test "slicing pointer by length" {...@@ -197,7 +197,7 @@ test "slicing pointer by length" {
197 }197 }
198}198}
199199
200const x = @ptrFromInt([*]i32, 0x1000)[0..0x500];200const x = @as([*]i32, @ptrFromInt(0x1000))[0..0x500];
201const y = x[0x100..];201const y = x[0x100..];
202test "compile time slice of pointer to hard coded address" {202test "compile time slice of pointer to hard coded address" {
203 try expect(@intFromPtr(x) == 0x1000);203 try expect(@intFromPtr(x) == 0x1000);
...@@ -262,7 +262,7 @@ test "C pointer slice access" {...@@ -262,7 +262,7 @@ test "C pointer slice access" {
262 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;262 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
263263
264 var buf: [10]u32 = [1]u32{42} ** 10;264 var buf: [10]u32 = [1]u32{42} ** 10;
265 const c_ptr = @ptrCast([*c]const u32, &buf);265 const c_ptr = @as([*c]const u32, @ptrCast(&buf));
266266
267 var runtime_zero: usize = 0;267 var runtime_zero: usize = 0;
268 try comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1]));268 try comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1]));
...@@ -352,7 +352,7 @@ test "@ptrCast slice to pointer" {...@@ -352,7 +352,7 @@ test "@ptrCast slice to pointer" {
352 fn doTheTest() !void {352 fn doTheTest() !void {
353 var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff };353 var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff };
354 var slice: []align(@alignOf(u16)) u8 = &array;354 var slice: []align(@alignOf(u16)) u8 = &array;
355 var ptr = @ptrCast(*u16, slice);355 var ptr = @as(*u16, @ptrCast(slice));
356 try expect(ptr.* == 65535);356 try expect(ptr.* == 65535);
357 }357 }
358 };358 };
...@@ -837,13 +837,13 @@ test "empty slice ptr is non null" {...@@ -837,13 +837,13 @@ test "empty slice ptr is non null" {
837 {837 {
838 const empty_slice: []u8 = &[_]u8{};838 const empty_slice: []u8 = &[_]u8{};
839 const p: [*]u8 = empty_slice.ptr + 0;839 const p: [*]u8 = empty_slice.ptr + 0;
840 const t = @ptrCast([*]i8, p);840 const t = @as([*]i8, @ptrCast(p));
841 try expect(@intFromPtr(t) == @intFromPtr(empty_slice.ptr));841 try expect(@intFromPtr(t) == @intFromPtr(empty_slice.ptr));
842 }842 }
843 {843 {
844 const empty_slice: []u8 = &.{};844 const empty_slice: []u8 = &.{};
845 const p: [*]u8 = empty_slice.ptr + 0;845 const p: [*]u8 = empty_slice.ptr + 0;
846 const t = @ptrCast([*]i8, p);846 const t = @as([*]i8, @ptrCast(p));
847 try expect(@intFromPtr(t) == @intFromPtr(empty_slice.ptr));847 try expect(@intFromPtr(t) == @intFromPtr(empty_slice.ptr));
848 }848 }
849}849}
test/behavior/slice_sentinel_comptime.zig+8-8
...@@ -25,7 +25,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {...@@ -25,7 +25,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
25 // vector_ConstPtrSpecialRef25 // vector_ConstPtrSpecialRef
26 comptime {26 comptime {
27 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;27 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
28 var target: [*]u8 = @ptrCast([*]u8, &buf);28 var target: [*]u8 = @as([*]u8, @ptrCast(&buf));
29 const slice = target[0..3 :'d'];29 const slice = target[0..3 :'d'];
30 _ = slice;30 _ = slice;
31 }31 }
...@@ -41,7 +41,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {...@@ -41,7 +41,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
41 // cvector_ConstPtrSpecialRef41 // cvector_ConstPtrSpecialRef
42 comptime {42 comptime {
43 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;43 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
44 var target: [*c]u8 = @ptrCast([*c]u8, &buf);44 var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf));
45 const slice = target[0..3 :'d'];45 const slice = target[0..3 :'d'];
46 _ = slice;46 _ = slice;
47 }47 }
...@@ -82,7 +82,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {...@@ -82,7 +82,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
82 // vector_ConstPtrSpecialRef82 // vector_ConstPtrSpecialRef
83 comptime {83 comptime {
84 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;84 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
85 var target: [*]u8 = @ptrCast([*]u8, &buf);85 var target: [*]u8 = @as([*]u8, @ptrCast(&buf));
86 const slice = target[0..13 :0xff];86 const slice = target[0..13 :0xff];
87 _ = slice;87 _ = slice;
88 }88 }
...@@ -98,7 +98,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {...@@ -98,7 +98,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
98 // cvector_ConstPtrSpecialRef98 // cvector_ConstPtrSpecialRef
99 comptime {99 comptime {
100 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;100 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
101 var target: [*c]u8 = @ptrCast([*c]u8, &buf);101 var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf));
102 const slice = target[0..13 :0xff];102 const slice = target[0..13 :0xff];
103 _ = slice;103 _ = slice;
104 }104 }
...@@ -139,7 +139,7 @@ test "comptime slice-sentinel in bounds (terminated)" {...@@ -139,7 +139,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
139 // vector_ConstPtrSpecialRef139 // vector_ConstPtrSpecialRef
140 comptime {140 comptime {
141 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;141 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
142 var target: [*]u8 = @ptrCast([*]u8, &buf);142 var target: [*]u8 = @as([*]u8, @ptrCast(&buf));
143 const slice = target[0..3 :'d'];143 const slice = target[0..3 :'d'];
144 _ = slice;144 _ = slice;
145 }145 }
...@@ -155,7 +155,7 @@ test "comptime slice-sentinel in bounds (terminated)" {...@@ -155,7 +155,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
155 // cvector_ConstPtrSpecialRef155 // cvector_ConstPtrSpecialRef
156 comptime {156 comptime {
157 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;157 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
158 var target: [*c]u8 = @ptrCast([*c]u8, &buf);158 var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf));
159 const slice = target[0..3 :'d'];159 const slice = target[0..3 :'d'];
160 _ = slice;160 _ = slice;
161 }161 }
...@@ -196,7 +196,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {...@@ -196,7 +196,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
196 // vector_ConstPtrSpecialRef196 // vector_ConstPtrSpecialRef
197 comptime {197 comptime {
198 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;198 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
199 var target: [*]u8 = @ptrCast([*]u8, &buf);199 var target: [*]u8 = @as([*]u8, @ptrCast(&buf));
200 const slice = target[0..14 :0];200 const slice = target[0..14 :0];
201 _ = slice;201 _ = slice;
202 }202 }
...@@ -212,7 +212,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {...@@ -212,7 +212,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
212 // cvector_ConstPtrSpecialRef212 // cvector_ConstPtrSpecialRef
213 comptime {213 comptime {
214 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;214 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
215 var target: [*c]u8 = @ptrCast([*c]u8, &buf);215 var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf));
216 const slice = target[0..14 :0];216 const slice = target[0..14 :0];
217 _ = slice;217 _ = slice;
218 }218 }
test/behavior/struct.zig+10-10
...@@ -92,7 +92,7 @@ test "structs" {...@@ -92,7 +92,7 @@ test "structs" {
92 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;92 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
9393
94 var foo: StructFoo = undefined;94 var foo: StructFoo = undefined;
95 @memset(@ptrCast([*]u8, &foo)[0..@sizeOf(StructFoo)], 0);95 @memset(@as([*]u8, @ptrCast(&foo))[0..@sizeOf(StructFoo)], 0);
96 foo.a += 1;96 foo.a += 1;
97 foo.b = foo.a == 1;97 foo.b = foo.a == 1;
98 try testFoo(foo);98 try testFoo(foo);
...@@ -479,14 +479,14 @@ test "runtime struct initialization of bitfield" {...@@ -479,14 +479,14 @@ test "runtime struct initialization of bitfield" {
479 .y = x1,479 .y = x1,
480 };480 };
481 const s2 = Nibbles{481 const s2 = Nibbles{
482 .x = @intCast(u4, x2),482 .x = @as(u4, @intCast(x2)),
483 .y = @intCast(u4, x2),483 .y = @as(u4, @intCast(x2)),
484 };484 };
485485
486 try expect(s1.x == x1);486 try expect(s1.x == x1);
487 try expect(s1.y == x1);487 try expect(s1.y == x1);
488 try expect(s2.x == @intCast(u4, x2));488 try expect(s2.x == @as(u4, @intCast(x2)));
489 try expect(s2.y == @intCast(u4, x2));489 try expect(s2.y == @as(u4, @intCast(x2)));
490}490}
491491
492var x1 = @as(u4, 1);492var x1 = @as(u4, 1);
...@@ -515,8 +515,8 @@ test "packed struct fields are ordered from LSB to MSB" {...@@ -515,8 +515,8 @@ test "packed struct fields are ordered from LSB to MSB" {
515515
516 var all: u64 = 0x7765443322221111;516 var all: u64 = 0x7765443322221111;
517 var bytes: [8]u8 align(@alignOf(Bitfields)) = undefined;517 var bytes: [8]u8 align(@alignOf(Bitfields)) = undefined;
518 @memcpy(bytes[0..8], @ptrCast([*]u8, &all));518 @memcpy(bytes[0..8], @as([*]u8, @ptrCast(&all)));
519 var bitfields = @ptrCast(*Bitfields, &bytes).*;519 var bitfields = @as(*Bitfields, @ptrCast(&bytes)).*;
520520
521 try expect(bitfields.f1 == 0x1111);521 try expect(bitfields.f1 == 0x1111);
522 try expect(bitfields.f2 == 0x2222);522 try expect(bitfields.f2 == 0x2222);
...@@ -1281,7 +1281,7 @@ test "packed struct aggregate init" {...@@ -1281,7 +1281,7 @@ test "packed struct aggregate init" {
12811281
1282 const S = struct {1282 const S = struct {
1283 fn foo(a: i2, b: i6) u8 {1283 fn foo(a: i2, b: i6) u8 {
1284 return @bitCast(u8, P{ .a = a, .b = b });1284 return @as(u8, @bitCast(P{ .a = a, .b = b }));
1285 }1285 }
12861286
1287 const P = packed struct {1287 const P = packed struct {
...@@ -1289,7 +1289,7 @@ test "packed struct aggregate init" {...@@ -1289,7 +1289,7 @@ test "packed struct aggregate init" {
1289 b: i6,1289 b: i6,
1290 };1290 };
1291 };1291 };
1292 const result = @bitCast(u8, S.foo(1, 2));1292 const result = @as(u8, @bitCast(S.foo(1, 2)));
1293 try expect(result == 9);1293 try expect(result == 9);
1294}1294}
12951295
...@@ -1365,7 +1365,7 @@ test "under-aligned struct field" {...@@ -1365,7 +1365,7 @@ test "under-aligned struct field" {
1365 };1365 };
1366 var runtime: usize = 1234;1366 var runtime: usize = 1234;
1367 const ptr = &S{ .events = 0, .data = .{ .u64 = runtime } };1367 const ptr = &S{ .events = 0, .data = .{ .u64 = runtime } };
1368 const array = @ptrCast(*const [12]u8, ptr);1368 const array = @as(*const [12]u8, @ptrCast(ptr));
1369 const result = std.mem.readIntNative(u64, array[4..12]);1369 const result = std.mem.readIntNative(u64, array[4..12]);
1370 try expect(result == 1234);1370 try expect(result == 1234);
1371}1371}
test/behavior/switch.zig+5-5
...@@ -590,9 +590,9 @@ test "switch on pointer type" {...@@ -590,9 +590,9 @@ test "switch on pointer type" {
590 field: u32,590 field: u32,
591 };591 };
592592
593 const P1 = @ptrFromInt(*X, 0x400);593 const P1 = @as(*X, @ptrFromInt(0x400));
594 const P2 = @ptrFromInt(*X, 0x800);594 const P2 = @as(*X, @ptrFromInt(0x800));
595 const P3 = @ptrFromInt(*X, 0xC00);595 const P3 = @as(*X, @ptrFromInt(0xC00));
596596
597 fn doTheTest(arg: *X) i32 {597 fn doTheTest(arg: *X) i32 {
598 switch (arg) {598 switch (arg) {
...@@ -682,9 +682,9 @@ test "enum value without tag name used as switch item" {...@@ -682,9 +682,9 @@ test "enum value without tag name used as switch item" {
682 b = 2,682 b = 2,
683 _,683 _,
684 };684 };
685 var e: E = @enumFromInt(E, 0);685 var e: E = @as(E, @enumFromInt(0));
686 switch (e) {686 switch (e) {
687 @enumFromInt(E, 0) => {},687 @as(E, @enumFromInt(0)) => {},
688 .a => return error.TestFailed,688 .a => return error.TestFailed,
689 .b => return error.TestFailed,689 .b => return error.TestFailed,
690 _ => return error.TestFailed,690 _ => return error.TestFailed,
test/behavior/translate_c_macros.zig+2-2
...@@ -60,7 +60,7 @@ test "cast negative integer to pointer" {...@@ -60,7 +60,7 @@ test "cast negative integer to pointer" {
60 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO60 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
61 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;61 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
6262
63 try expectEqual(@ptrFromInt(?*anyopaque, @bitCast(usize, @as(isize, -1))), h.MAP_FAILED);63 try expectEqual(@as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))), h.MAP_FAILED);
64}64}
6565
66test "casting to union with a macro" {66test "casting to union with a macro" {
...@@ -89,7 +89,7 @@ test "casting or calling a value with a paren-surrounded macro" {...@@ -89,7 +89,7 @@ test "casting or calling a value with a paren-surrounded macro" {
8989
90 const l: c_long = 42;90 const l: c_long = 42;
91 const casted = h.CAST_OR_CALL_WITH_PARENS(c_int, l);91 const casted = h.CAST_OR_CALL_WITH_PARENS(c_int, l);
92 try expect(casted == @intCast(c_int, l));92 try expect(casted == @as(c_int, @intCast(l)));
9393
94 const Helper = struct {94 const Helper = struct {
95 fn foo(n: c_int) !void {95 fn foo(n: c_int) !void {
test/behavior/truncate.zig+13-13
...@@ -4,58 +4,58 @@ const expect = std.testing.expect;...@@ -4,58 +4,58 @@ const expect = std.testing.expect;
44
5test "truncate u0 to larger integer allowed and has comptime-known result" {5test "truncate u0 to larger integer allowed and has comptime-known result" {
6 var x: u0 = 0;6 var x: u0 = 0;
7 const y = @truncate(u8, x);7 const y = @as(u8, @truncate(x));
8 try comptime expect(y == 0);8 try comptime expect(y == 0);
9}9}
1010
11test "truncate.u0.literal" {11test "truncate.u0.literal" {
12 var z = @truncate(u0, 0);12 var z = @as(u0, @truncate(0));
13 try expect(z == 0);13 try expect(z == 0);
14}14}
1515
16test "truncate.u0.const" {16test "truncate.u0.const" {
17 const c0: usize = 0;17 const c0: usize = 0;
18 var z = @truncate(u0, c0);18 var z = @as(u0, @truncate(c0));
19 try expect(z == 0);19 try expect(z == 0);
20}20}
2121
22test "truncate.u0.var" {22test "truncate.u0.var" {
23 var d: u8 = 2;23 var d: u8 = 2;
24 var z = @truncate(u0, d);24 var z = @as(u0, @truncate(d));
25 try expect(z == 0);25 try expect(z == 0);
26}26}
2727
28test "truncate i0 to larger integer allowed and has comptime-known result" {28test "truncate i0 to larger integer allowed and has comptime-known result" {
29 var x: i0 = 0;29 var x: i0 = 0;
30 const y = @truncate(i8, x);30 const y = @as(i8, @truncate(x));
31 try comptime expect(y == 0);31 try comptime expect(y == 0);
32}32}
3333
34test "truncate.i0.literal" {34test "truncate.i0.literal" {
35 var z = @truncate(i0, 0);35 var z = @as(i0, @truncate(0));
36 try expect(z == 0);36 try expect(z == 0);
37}37}
3838
39test "truncate.i0.const" {39test "truncate.i0.const" {
40 const c0: isize = 0;40 const c0: isize = 0;
41 var z = @truncate(i0, c0);41 var z = @as(i0, @truncate(c0));
42 try expect(z == 0);42 try expect(z == 0);
43}43}
4444
45test "truncate.i0.var" {45test "truncate.i0.var" {
46 var d: i8 = 2;46 var d: i8 = 2;
47 var z = @truncate(i0, d);47 var z = @as(i0, @truncate(d));
48 try expect(z == 0);48 try expect(z == 0);
49}49}
5050
51test "truncate on comptime integer" {51test "truncate on comptime integer" {
52 var x = @truncate(u16, 9999);52 var x = @as(u16, @truncate(9999));
53 try expect(x == 9999);53 try expect(x == 9999);
54 var y = @truncate(u16, -21555);54 var y = @as(u16, @truncate(-21555));
55 try expect(y == 0xabcd);55 try expect(y == 0xabcd);
56 var z = @truncate(i16, -65537);56 var z = @as(i16, @truncate(-65537));
57 try expect(z == -1);57 try expect(z == -1);
58 var w = @truncate(u1, 1 << 100);58 var w = @as(u1, @truncate(1 << 100));
59 try expect(w == 0);59 try expect(w == 0);
60}60}
6161
...@@ -69,7 +69,7 @@ test "truncate on vectors" {...@@ -69,7 +69,7 @@ test "truncate on vectors" {
69 const S = struct {69 const S = struct {
70 fn doTheTest() !void {70 fn doTheTest() !void {
71 var v1: @Vector(4, u16) = .{ 0xaabb, 0xccdd, 0xeeff, 0x1122 };71 var v1: @Vector(4, u16) = .{ 0xaabb, 0xccdd, 0xeeff, 0x1122 };
72 var v2 = @truncate(u8, v1);72 var v2: @Vector(4, u8) = @truncate(v1);
73 try expect(std.mem.eql(u8, &@as([4]u8, v2), &[4]u8{ 0xbb, 0xdd, 0xff, 0x22 }));73 try expect(std.mem.eql(u8, &@as([4]u8, v2), &[4]u8{ 0xbb, 0xdd, 0xff, 0x22 }));
74 }74 }
75 };75 };
test/behavior/tuple.zig+1-1
...@@ -403,7 +403,7 @@ test "nested runtime conditionals in tuple initializer" {...@@ -403,7 +403,7 @@ test "nested runtime conditionals in tuple initializer" {
403403
404 var data: u8 = 0;404 var data: u8 = 0;
405 const x = .{405 const x = .{
406 if (data != 0) "" else switch (@truncate(u1, data)) {406 if (data != 0) "" else switch (@as(u1, @truncate(data))) {
407 0 => "up",407 0 => "up",
408 1 => "down",408 1 => "down",
409 },409 },
test/behavior/tuple_declarations.zig+1-1
...@@ -21,7 +21,7 @@ test "tuple declaration type info" {...@@ -21,7 +21,7 @@ test "tuple declaration type info" {
2121
22 try expectEqualStrings(info.fields[0].name, "0");22 try expectEqualStrings(info.fields[0].name, "0");
23 try expect(info.fields[0].type == u32);23 try expect(info.fields[0].type == u32);
24 try expect(@ptrCast(*const u32, @alignCast(@alignOf(u32), info.fields[0].default_value)).* == 1);24 try expect(@as(*const u32, @ptrCast(@alignCast(info.fields[0].default_value))).* == 1);
25 try expect(info.fields[0].is_comptime);25 try expect(info.fields[0].is_comptime);
26 try expect(info.fields[0].alignment == 2);26 try expect(info.fields[0].alignment == 2);
2727
test/behavior/type.zig+8-8
...@@ -289,7 +289,7 @@ test "Type.Struct" {...@@ -289,7 +289,7 @@ test "Type.Struct" {
289 try testing.expectEqual(@as(?*const anyopaque, null), infoB.fields[0].default_value);289 try testing.expectEqual(@as(?*const anyopaque, null), infoB.fields[0].default_value);
290 try testing.expectEqualSlices(u8, "y", infoB.fields[1].name);290 try testing.expectEqualSlices(u8, "y", infoB.fields[1].name);
291 try testing.expectEqual(u32, infoB.fields[1].type);291 try testing.expectEqual(u32, infoB.fields[1].type);
292 try testing.expectEqual(@as(u32, 5), @ptrCast(*align(1) const u32, infoB.fields[1].default_value.?).*);292 try testing.expectEqual(@as(u32, 5), @as(*align(1) const u32, @ptrCast(infoB.fields[1].default_value.?)).*);
293 try testing.expectEqual(@as(usize, 0), infoB.decls.len);293 try testing.expectEqual(@as(usize, 0), infoB.decls.len);
294 try testing.expectEqual(@as(bool, false), infoB.is_tuple);294 try testing.expectEqual(@as(bool, false), infoB.is_tuple);
295295
...@@ -298,10 +298,10 @@ test "Type.Struct" {...@@ -298,10 +298,10 @@ test "Type.Struct" {
298 try testing.expectEqual(Type.ContainerLayout.Packed, infoC.layout);298 try testing.expectEqual(Type.ContainerLayout.Packed, infoC.layout);
299 try testing.expectEqualSlices(u8, "x", infoC.fields[0].name);299 try testing.expectEqualSlices(u8, "x", infoC.fields[0].name);
300 try testing.expectEqual(u8, infoC.fields[0].type);300 try testing.expectEqual(u8, infoC.fields[0].type);
301 try testing.expectEqual(@as(u8, 3), @ptrCast(*const u8, infoC.fields[0].default_value.?).*);301 try testing.expectEqual(@as(u8, 3), @as(*const u8, @ptrCast(infoC.fields[0].default_value.?)).*);
302 try testing.expectEqualSlices(u8, "y", infoC.fields[1].name);302 try testing.expectEqualSlices(u8, "y", infoC.fields[1].name);
303 try testing.expectEqual(u32, infoC.fields[1].type);303 try testing.expectEqual(u32, infoC.fields[1].type);
304 try testing.expectEqual(@as(u32, 5), @ptrCast(*align(1) const u32, infoC.fields[1].default_value.?).*);304 try testing.expectEqual(@as(u32, 5), @as(*align(1) const u32, @ptrCast(infoC.fields[1].default_value.?)).*);
305 try testing.expectEqual(@as(usize, 0), infoC.decls.len);305 try testing.expectEqual(@as(usize, 0), infoC.decls.len);
306 try testing.expectEqual(@as(bool, false), infoC.is_tuple);306 try testing.expectEqual(@as(bool, false), infoC.is_tuple);
307307
...@@ -311,10 +311,10 @@ test "Type.Struct" {...@@ -311,10 +311,10 @@ test "Type.Struct" {
311 try testing.expectEqual(Type.ContainerLayout.Auto, infoD.layout);311 try testing.expectEqual(Type.ContainerLayout.Auto, infoD.layout);
312 try testing.expectEqualSlices(u8, "x", infoD.fields[0].name);312 try testing.expectEqualSlices(u8, "x", infoD.fields[0].name);
313 try testing.expectEqual(comptime_int, infoD.fields[0].type);313 try testing.expectEqual(comptime_int, infoD.fields[0].type);
314 try testing.expectEqual(@as(comptime_int, 3), @ptrCast(*const comptime_int, infoD.fields[0].default_value.?).*);314 try testing.expectEqual(@as(comptime_int, 3), @as(*const comptime_int, @ptrCast(infoD.fields[0].default_value.?)).*);
315 try testing.expectEqualSlices(u8, "y", infoD.fields[1].name);315 try testing.expectEqualSlices(u8, "y", infoD.fields[1].name);
316 try testing.expectEqual(comptime_int, infoD.fields[1].type);316 try testing.expectEqual(comptime_int, infoD.fields[1].type);
317 try testing.expectEqual(@as(comptime_int, 5), @ptrCast(*const comptime_int, infoD.fields[1].default_value.?).*);317 try testing.expectEqual(@as(comptime_int, 5), @as(*const comptime_int, @ptrCast(infoD.fields[1].default_value.?)).*);
318 try testing.expectEqual(@as(usize, 0), infoD.decls.len);318 try testing.expectEqual(@as(usize, 0), infoD.decls.len);
319 try testing.expectEqual(@as(bool, false), infoD.is_tuple);319 try testing.expectEqual(@as(bool, false), infoD.is_tuple);
320320
...@@ -324,10 +324,10 @@ test "Type.Struct" {...@@ -324,10 +324,10 @@ test "Type.Struct" {
324 try testing.expectEqual(Type.ContainerLayout.Auto, infoE.layout);324 try testing.expectEqual(Type.ContainerLayout.Auto, infoE.layout);
325 try testing.expectEqualSlices(u8, "0", infoE.fields[0].name);325 try testing.expectEqualSlices(u8, "0", infoE.fields[0].name);
326 try testing.expectEqual(comptime_int, infoE.fields[0].type);326 try testing.expectEqual(comptime_int, infoE.fields[0].type);
327 try testing.expectEqual(@as(comptime_int, 1), @ptrCast(*const comptime_int, infoE.fields[0].default_value.?).*);327 try testing.expectEqual(@as(comptime_int, 1), @as(*const comptime_int, @ptrCast(infoE.fields[0].default_value.?)).*);
328 try testing.expectEqualSlices(u8, "1", infoE.fields[1].name);328 try testing.expectEqualSlices(u8, "1", infoE.fields[1].name);
329 try testing.expectEqual(comptime_int, infoE.fields[1].type);329 try testing.expectEqual(comptime_int, infoE.fields[1].type);
330 try testing.expectEqual(@as(comptime_int, 2), @ptrCast(*const comptime_int, infoE.fields[1].default_value.?).*);330 try testing.expectEqual(@as(comptime_int, 2), @as(*const comptime_int, @ptrCast(infoE.fields[1].default_value.?)).*);
331 try testing.expectEqual(@as(usize, 0), infoE.decls.len);331 try testing.expectEqual(@as(usize, 0), infoE.decls.len);
332 try testing.expectEqual(@as(bool, true), infoE.is_tuple);332 try testing.expectEqual(@as(bool, true), infoE.is_tuple);
333333
...@@ -379,7 +379,7 @@ test "Type.Enum" {...@@ -379,7 +379,7 @@ test "Type.Enum" {
379 try testing.expectEqual(false, @typeInfo(Bar).Enum.is_exhaustive);379 try testing.expectEqual(false, @typeInfo(Bar).Enum.is_exhaustive);
380 try testing.expectEqual(@as(u32, 1), @intFromEnum(Bar.a));380 try testing.expectEqual(@as(u32, 1), @intFromEnum(Bar.a));
381 try testing.expectEqual(@as(u32, 5), @intFromEnum(Bar.b));381 try testing.expectEqual(@as(u32, 5), @intFromEnum(Bar.b));
382 try testing.expectEqual(@as(u32, 6), @intFromEnum(@enumFromInt(Bar, 6)));382 try testing.expectEqual(@as(u32, 6), @intFromEnum(@as(Bar, @enumFromInt(6))));
383}383}
384384
385test "Type.Union" {385test "Type.Union" {
test/behavior/type_info.zig+8-8
...@@ -113,7 +113,7 @@ fn testNullTerminatedPtr() !void {...@@ -113,7 +113,7 @@ fn testNullTerminatedPtr() !void {
113 try expect(ptr_info.Pointer.size == .Many);113 try expect(ptr_info.Pointer.size == .Many);
114 try expect(ptr_info.Pointer.is_const == false);114 try expect(ptr_info.Pointer.is_const == false);
115 try expect(ptr_info.Pointer.is_volatile == false);115 try expect(ptr_info.Pointer.is_volatile == false);
116 try expect(@ptrCast(*const u8, ptr_info.Pointer.sentinel.?).* == 0);116 try expect(@as(*const u8, @ptrCast(ptr_info.Pointer.sentinel.?)).* == 0);
117117
118 try expect(@typeInfo([:0]u8).Pointer.sentinel != null);118 try expect(@typeInfo([:0]u8).Pointer.sentinel != null);
119}119}
...@@ -151,7 +151,7 @@ fn testArray() !void {...@@ -151,7 +151,7 @@ fn testArray() !void {
151 const info = @typeInfo([10:0]u8);151 const info = @typeInfo([10:0]u8);
152 try expect(info.Array.len == 10);152 try expect(info.Array.len == 10);
153 try expect(info.Array.child == u8);153 try expect(info.Array.child == u8);
154 try expect(@ptrCast(*const u8, info.Array.sentinel.?).* == @as(u8, 0));154 try expect(@as(*const u8, @ptrCast(info.Array.sentinel.?)).* == @as(u8, 0));
155 try expect(@sizeOf([10:0]u8) == info.Array.len + 1);155 try expect(@sizeOf([10:0]u8) == info.Array.len + 1);
156 }156 }
157}157}
...@@ -295,8 +295,8 @@ fn testStruct() !void {...@@ -295,8 +295,8 @@ fn testStruct() !void {
295 try expect(unpacked_struct_info.Struct.is_tuple == false);295 try expect(unpacked_struct_info.Struct.is_tuple == false);
296 try expect(unpacked_struct_info.Struct.backing_integer == null);296 try expect(unpacked_struct_info.Struct.backing_integer == null);
297 try expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32));297 try expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32));
298 try expect(@ptrCast(*align(1) const u32, unpacked_struct_info.Struct.fields[0].default_value.?).* == 4);298 try expect(@as(*align(1) const u32, @ptrCast(unpacked_struct_info.Struct.fields[0].default_value.?)).* == 4);
299 try expect(mem.eql(u8, "foobar", @ptrCast(*align(1) const *const [6:0]u8, unpacked_struct_info.Struct.fields[1].default_value.?).*));299 try expect(mem.eql(u8, "foobar", @as(*align(1) const *const [6:0]u8, @ptrCast(unpacked_struct_info.Struct.fields[1].default_value.?)).*));
300}300}
301301
302const TestStruct = struct {302const TestStruct = struct {
...@@ -319,7 +319,7 @@ fn testPackedStruct() !void {...@@ -319,7 +319,7 @@ fn testPackedStruct() !void {
319 try expect(struct_info.Struct.fields[0].alignment == 0);319 try expect(struct_info.Struct.fields[0].alignment == 0);
320 try expect(struct_info.Struct.fields[2].type == f32);320 try expect(struct_info.Struct.fields[2].type == f32);
321 try expect(struct_info.Struct.fields[2].default_value == null);321 try expect(struct_info.Struct.fields[2].default_value == null);
322 try expect(@ptrCast(*align(1) const u32, struct_info.Struct.fields[3].default_value.?).* == 4);322 try expect(@as(*align(1) const u32, @ptrCast(struct_info.Struct.fields[3].default_value.?)).* == 4);
323 try expect(struct_info.Struct.fields[3].alignment == 0);323 try expect(struct_info.Struct.fields[3].alignment == 0);
324 try expect(struct_info.Struct.decls.len == 2);324 try expect(struct_info.Struct.decls.len == 2);
325 try expect(struct_info.Struct.decls[0].is_pub);325 try expect(struct_info.Struct.decls[0].is_pub);
...@@ -504,7 +504,7 @@ test "type info for async frames" {...@@ -504,7 +504,7 @@ test "type info for async frames" {
504504
505 switch (@typeInfo(@Frame(add))) {505 switch (@typeInfo(@Frame(add))) {
506 .Frame => |frame| {506 .Frame => |frame| {
507 try expect(@ptrCast(@TypeOf(add), frame.function) == add);507 try expect(@as(@TypeOf(add), @ptrCast(frame.function)) == add);
508 },508 },
509 else => unreachable,509 else => unreachable,
510 }510 }
...@@ -564,7 +564,7 @@ test "typeInfo resolves usingnamespace declarations" {...@@ -564,7 +564,7 @@ test "typeInfo resolves usingnamespace declarations" {
564test "value from struct @typeInfo default_value can be loaded at comptime" {564test "value from struct @typeInfo default_value can be loaded at comptime" {
565 comptime {565 comptime {
566 const a = @typeInfo(@TypeOf(.{ .foo = @as(u8, 1) })).Struct.fields[0].default_value;566 const a = @typeInfo(@TypeOf(.{ .foo = @as(u8, 1) })).Struct.fields[0].default_value;
567 try expect(@ptrCast(*const u8, a).* == 1);567 try expect(@as(*const u8, @ptrCast(a)).* == 1);
568 }568 }
569}569}
570570
...@@ -607,6 +607,6 @@ test "@typeInfo decls ignore dependency loops" {...@@ -607,6 +607,6 @@ test "@typeInfo decls ignore dependency loops" {
607607
608test "type info of tuple of string literal default value" {608test "type info of tuple of string literal default value" {
609 const struct_field = @typeInfo(@TypeOf(.{"hi"})).Struct.fields[0];609 const struct_field = @typeInfo(@TypeOf(.{"hi"})).Struct.fields[0];
610 const value = @ptrCast(*align(1) const *const [2:0]u8, struct_field.default_value.?).*;610 const value = @as(*align(1) const *const [2:0]u8, @ptrCast(struct_field.default_value.?)).*;
611 comptime std.debug.assert(value[0] == 'h');611 comptime std.debug.assert(value[0] == 'h');
612}612}
test/behavior/vector.zig+1-1
...@@ -1244,7 +1244,7 @@ test "@intCast to u0" {...@@ -1244,7 +1244,7 @@ test "@intCast to u0" {
1244 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;1244 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
12451245
1246 var zeros = @Vector(2, u32){ 0, 0 };1246 var zeros = @Vector(2, u32){ 0, 0 };
1247 const casted = @intCast(@Vector(2, u0), zeros);1247 const casted = @as(@Vector(2, u0), @intCast(zeros));
12481248
1249 _ = casted[0];1249 _ = casted[0];
1250}1250}
test/c_abi/main.zig+9-9
...@@ -143,7 +143,7 @@ export fn zig_longdouble(x: c_longdouble) void {...@@ -143,7 +143,7 @@ export fn zig_longdouble(x: c_longdouble) void {
143extern fn c_ptr(*anyopaque) void;143extern fn c_ptr(*anyopaque) void;
144144
145test "C ABI pointer" {145test "C ABI pointer" {
146 c_ptr(@ptrFromInt(*anyopaque, 0xdeadbeef));146 c_ptr(@as(*anyopaque, @ptrFromInt(0xdeadbeef)));
147}147}
148148
149export fn zig_ptr(x: *anyopaque) void {149export fn zig_ptr(x: *anyopaque) void {
...@@ -1058,14 +1058,14 @@ test "C function that takes byval struct called via function pointer" {...@@ -1058,14 +1058,14 @@ test "C function that takes byval struct called via function pointer" {
10581058
1059 var fn_ptr = &c_func_ptr_byval;1059 var fn_ptr = &c_func_ptr_byval;
1060 fn_ptr(1060 fn_ptr(
1061 @ptrFromInt(*anyopaque, 1),1061 @as(*anyopaque, @ptrFromInt(1)),
1062 @ptrFromInt(*anyopaque, 2),1062 @as(*anyopaque, @ptrFromInt(2)),
1063 ByVal{1063 ByVal{
1064 .origin = .{ .x = 9, .y = 10, .z = 11 },1064 .origin = .{ .x = 9, .y = 10, .z = 11 },
1065 .size = .{ .width = 12, .height = 13, .depth = 14 },1065 .size = .{ .width = 12, .height = 13, .depth = 14 },
1066 },1066 },
1067 @as(c_ulong, 3),1067 @as(c_ulong, 3),
1068 @ptrFromInt(*anyopaque, 4),1068 @as(*anyopaque, @ptrFromInt(4)),
1069 @as(c_ulong, 5),1069 @as(c_ulong, 5),
1070 );1070 );
1071}1071}
...@@ -1098,7 +1098,7 @@ test "f80 bare" {...@@ -1098,7 +1098,7 @@ test "f80 bare" {
1098 if (!has_f80) return error.SkipZigTest;1098 if (!has_f80) return error.SkipZigTest;
10991099
1100 const a = c_f80(12.34);1100 const a = c_f80(12.34);
1101 try expect(@floatCast(f64, a) == 56.78);1101 try expect(@as(f64, @floatCast(a)) == 56.78);
1102}1102}
11031103
1104const f80_struct = extern struct {1104const f80_struct = extern struct {
...@@ -1111,7 +1111,7 @@ test "f80 struct" {...@@ -1111,7 +1111,7 @@ test "f80 struct" {
1111 if (builtin.mode != .Debug) return error.SkipZigTest;1111 if (builtin.mode != .Debug) return error.SkipZigTest;
11121112
1113 const a = c_f80_struct(.{ .a = 12.34 });1113 const a = c_f80_struct(.{ .a = 12.34 });
1114 try expect(@floatCast(f64, a.a) == 56.78);1114 try expect(@as(f64, @floatCast(a.a)) == 56.78);
1115}1115}
11161116
1117const f80_extra_struct = extern struct {1117const f80_extra_struct = extern struct {
...@@ -1124,7 +1124,7 @@ test "f80 extra struct" {...@@ -1124,7 +1124,7 @@ test "f80 extra struct" {
1124 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;1124 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
11251125
1126 const a = c_f80_extra_struct(.{ .a = 12.34, .b = 42 });1126 const a = c_f80_extra_struct(.{ .a = 12.34, .b = 42 });
1127 try expect(@floatCast(f64, a.a) == 56.78);1127 try expect(@as(f64, @floatCast(a.a)) == 56.78);
1128 try expect(a.b == 24);1128 try expect(a.b == 24);
1129}1129}
11301130
...@@ -1133,7 +1133,7 @@ test "f128 bare" {...@@ -1133,7 +1133,7 @@ test "f128 bare" {
1133 if (!has_f128) return error.SkipZigTest;1133 if (!has_f128) return error.SkipZigTest;
11341134
1135 const a = c_f128(12.34);1135 const a = c_f128(12.34);
1136 try expect(@floatCast(f64, a) == 56.78);1136 try expect(@as(f64, @floatCast(a)) == 56.78);
1137}1137}
11381138
1139const f128_struct = extern struct {1139const f128_struct = extern struct {
...@@ -1144,7 +1144,7 @@ test "f128 struct" {...@@ -1144,7 +1144,7 @@ test "f128 struct" {
1144 if (!has_f128) return error.SkipZigTest;1144 if (!has_f128) return error.SkipZigTest;
11451145
1146 const a = c_f128_struct(.{ .a = 12.34 });1146 const a = c_f128_struct(.{ .a = 12.34 });
1147 try expect(@floatCast(f64, a.a) == 56.78);1147 try expect(@as(f64, @floatCast(a.a)) == 56.78);
1148}1148}
11491149
1150// The stdcall attribute on C functions is ignored when compiled on non-x861150// The stdcall attribute on C functions is ignored when compiled on non-x86
test/cases/compile_errors/alignCast_expects_pointer_or_slice.zig+3-2
...@@ -1,9 +1,10 @@...@@ -1,9 +1,10 @@
1export fn entry() void {1export fn entry() void {
2 @alignCast(4, @as(u32, 3));2 const x: *align(8) u32 = @alignCast(@as(u32, 3));
3 _ = x;
3}4}
45
5// error6// error
6// backend=stage27// backend=stage2
7// target=native8// target=native
8//9//
9// :2:19: error: expected pointer type, found 'u32'10// :2:41: error: expected pointer type, found 'u32'
test/cases/compile_errors/bad_alignCast_at_comptime.zig+3-3
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1comptime {1comptime {
2 const ptr = @ptrFromInt(*align(1) i32, 0x1);2 const ptr: *align(1) i32 = @ptrFromInt(0x1);
3 const aligned = @alignCast(4, ptr);3 const aligned: *align(4) i32 = @alignCast(ptr);
4 _ = aligned;4 _ = aligned;
5}5}
66
...@@ -8,4 +8,4 @@ comptime {...@@ -8,4 +8,4 @@ comptime {
8// backend=stage28// backend=stage2
9// target=native9// target=native
10//10//
11// :3:35: error: pointer address 0x1 is not aligned to 4 bytes11// :3:47: error: pointer address 0x1 is not aligned to 4 bytes
test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1export fn entry(byte: u8) void {1export fn entry(byte: u8) void {
2 var oops = @bitCast(u7, byte);2 var oops: u7 = @bitCast(byte);
3 _ = oops;3 _ = oops;
4}4}
55
...@@ -7,4 +7,4 @@ export fn entry(byte: u8) void {...@@ -7,4 +7,4 @@ export fn entry(byte: u8) void {
7// backend=stage27// backend=stage2
8// target=native8// target=native
9//9//
10// :2:16: error: @bitCast size mismatch: destination type 'u7' has 7 bits but source type 'u8' has 8 bits10// :2:20: error: @bitCast size mismatch: destination type 'u7' has 7 bits but source type 'u8' has 8 bits
test/cases/compile_errors/bitCast_to_enum_type.zig+3-3
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 const E = enum(u32) { a, b };2 const E = enum(u32) { a, b };
3 const y = @bitCast(E, @as(u32, 3));3 const y: E = @bitCast(@as(u32, 3));
4 _ = y;4 _ = y;
5}5}
66
...@@ -8,5 +8,5 @@ export fn entry() void {...@@ -8,5 +8,5 @@ export fn entry() void {
8// backend=stage28// backend=stage2
9// target=native9// target=native
10//10//
11// :3:24: error: cannot @bitCast to 'tmp.entry.E'11// :3:18: error: cannot @bitCast to 'tmp.entry.E'
12// :3:24: note: use @enumFromInt to cast from 'u32'12// :3:18: note: use @enumFromInt to cast from 'u32'
test/cases/compile_errors/bitCast_with_different_sizes_inside_an_expression.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1export fn entry() void {1export fn entry() void {
2 var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf);2 var foo = (@as(u8, @bitCast(@as(f32, 1.0))) == 0xf);
3 _ = foo;3 _ = foo;
4}4}
55
...@@ -7,4 +7,4 @@ export fn entry() void {...@@ -7,4 +7,4 @@ export fn entry() void {
7// backend=stage27// backend=stage2
8// target=native8// target=native
9//9//
10// :2:16: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'f32' has 32 bits10// :2:24: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'f32' has 32 bits
test/cases/compile_errors/cast_negative_value_to_unsigned_integer.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1comptime {1comptime {
2 const value: i32 = -1;2 const value: i32 = -1;
3 const unsigned = @intCast(u32, value);3 const unsigned: u32 = @intCast(value);
4 _ = unsigned;4 _ = unsigned;
5}5}
6export fn entry1() void {6export fn entry1() void {
test/cases/compile_errors/compile_log_a_pointer_to_an_opaque_value.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1export fn entry() void {1export fn entry() void {
2 @compileLog(@as(*align(1) const anyopaque, @ptrCast(*const anyopaque, &entry)));2 @compileLog(@as(*const anyopaque, @ptrCast(&entry)));
3}3}
44
5// error5// error
test/cases/compile_errors/compile_time_null_ptr_cast.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1comptime {1comptime {
2 var opt_ptr: ?*i32 = null;2 var opt_ptr: ?*i32 = null;
3 const ptr = @ptrCast(*i32, opt_ptr);3 const ptr: *i32 = @ptrCast(opt_ptr);
4 _ = ptr;4 _ = ptr;
5}5}
66
test/cases/compile_errors/compile_time_undef_ptr_cast.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1comptime {1comptime {
2 var undef_ptr: *i32 = undefined;2 var undef_ptr: *i32 = undefined;
3 const ptr = @ptrCast(*i32, undef_ptr);3 const ptr: *i32 = @ptrCast(undef_ptr);
4 _ = ptr;4 _ = ptr;
5}5}
66
test/cases/compile_errors/comptime_call_of_function_pointer.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1export fn entry() void {1export fn entry() void {
2 const fn_ptr = @ptrFromInt(*align(1) fn () void, 0xffd2);2 const fn_ptr: *align(1) fn () void = @ptrFromInt(0xffd2);
3 comptime fn_ptr();3 comptime fn_ptr();
4}4}
55
test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig+2-2
...@@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void {...@@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void {
24export fn foo_vector_ConstPtrSpecialRef() void {24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {25 comptime {
26 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;26 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);27 var target: [*]u8 = @ptrCast(&buf);
28 const slice = target[0..3 :0];28 const slice = target[0..3 :0];
29 _ = slice;29 _ = slice;
30 }30 }
...@@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {...@@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {
40export fn foo_cvector_ConstPtrSpecialRef() void {40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {41 comptime {
42 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;42 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);43 var target: [*c]u8 = @ptrCast(&buf);
44 const slice = target[0..3 :0];44 const slice = target[0..3 :0];
45 _ = slice;45 _ = slice;
46 }46 }
test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig+2-2
...@@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void {...@@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void {
24export fn foo_vector_ConstPtrSpecialRef() void {24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {25 comptime {
26 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;26 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);27 var target: [*]u8 = @ptrCast(&buf);
28 const slice = target[0..3 :0];28 const slice = target[0..3 :0];
29 _ = slice;29 _ = slice;
30 }30 }
...@@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {...@@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {
40export fn foo_cvector_ConstPtrSpecialRef() void {40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {41 comptime {
42 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;42 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);43 var target: [*c]u8 = @ptrCast(&buf);
44 const slice = target[0..3 :0];44 const slice = target[0..3 :0];
45 _ = slice;45 _ = slice;
46 }46 }
test/cases/compile_errors/comptime_slice-sentinel_does_not_match_target-sentinel.zig+2-2
...@@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void {...@@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void {
24export fn foo_vector_ConstPtrSpecialRef() void {24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {25 comptime {
26 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;26 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);27 var target: [*]u8 = @ptrCast(&buf);
28 const slice = target[0..14 :255];28 const slice = target[0..14 :255];
29 _ = slice;29 _ = slice;
30 }30 }
...@@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {...@@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {
40export fn foo_cvector_ConstPtrSpecialRef() void {40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {41 comptime {
42 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;42 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);43 var target: [*c]u8 = @ptrCast(&buf);
44 const slice = target[0..14 :255];44 const slice = target[0..14 :255];
45 _ = slice;45 _ = slice;
46 }46 }
test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_terminated.zig+2-2
...@@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void {...@@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void {
24export fn foo_vector_ConstPtrSpecialRef() void {24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {25 comptime {
26 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;26 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);27 var target: [*]u8 = @ptrCast(&buf);
28 const slice = target[0..15 :0];28 const slice = target[0..15 :0];
29 _ = slice;29 _ = slice;
30 }30 }
...@@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {...@@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {
40export fn foo_cvector_ConstPtrSpecialRef() void {40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {41 comptime {
42 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;42 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);43 var target: [*c]u8 = @ptrCast(&buf);
44 const slice = target[0..15 :0];44 const slice = target[0..15 :0];
45 _ = slice;45 _ = slice;
46 }46 }
test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig+2-2
...@@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void {...@@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void {
24export fn foo_vector_ConstPtrSpecialRef() void {24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {25 comptime {
26 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;26 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);27 var target: [*]u8 = @ptrCast(&buf);
28 const slice = target[0..14 :0];28 const slice = target[0..14 :0];
29 _ = slice;29 _ = slice;
30 }30 }
...@@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {...@@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {
40export fn foo_cvector_ConstPtrSpecialRef() void {40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {41 comptime {
42 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;42 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);43 var target: [*c]u8 = @ptrCast(&buf);
44 const slice = target[0..14 :0];44 const slice = target[0..14 :0];
45 _ = slice;45 _ = slice;
46 }46 }
test/cases/compile_errors/enumFromInt_on_non-exhaustive_enums_checks_int_in_range.zig+2-2
...@@ -1,11 +1,11 @@...@@ -1,11 +1,11 @@
1pub export fn entry() void {1pub export fn entry() void {
2 const E = enum(u3) { a, b, c, _ };2 const E = enum(u3) { a, b, c, _ };
3 @compileLog(@enumFromInt(E, 100));3 @compileLog(@as(E, @enumFromInt(100)));
4}4}
55
6// error6// error
7// target=native7// target=native
8// backend=stage28// backend=stage2
9//9//
10// :3:17: error: int value '100' out of range of non-exhaustive enum 'tmp.entry.E'10// :3:24: error: int value '100' out of range of non-exhaustive enum 'tmp.entry.E'
11// :2:15: note: enum declared here11// :2:15: note: enum declared here
test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig+2-2
...@@ -3,7 +3,7 @@ const Foo = enum(u32) {...@@ -3,7 +3,7 @@ const Foo = enum(u32) {
3 B = 11,3 B = 11,
4};4};
5export fn entry() void {5export fn entry() void {
6 var x = @enumFromInt(Foo, 0);6 var x: Foo = @enumFromInt(0);
7 _ = x;7 _ = x;
8}8}
99
...@@ -11,5 +11,5 @@ export fn entry() void {...@@ -11,5 +11,5 @@ export fn entry() void {
11// backend=stage211// backend=stage2
12// target=native12// target=native
13//13//
14// :6:13: error: enum 'tmp.Foo' has no tag with value '0'14// :6:18: error: enum 'tmp.Foo' has no tag with value '0'
15// :1:13: note: enum declared here15// :1:13: note: enum declared here
test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig+2-2
...@@ -2,7 +2,7 @@ const Set1 = error{ A, B };...@@ -2,7 +2,7 @@ const Set1 = error{ A, B };
2const Set2 = error{ A, C };2const Set2 = error{ A, C };
3comptime {3comptime {
4 var x = Set1.B;4 var x = Set1.B;
5 var y = @errSetCast(Set2, x);5 var y: Set2 = @errSetCast(x);
6 _ = y;6 _ = y;
7}7}
88
...@@ -10,4 +10,4 @@ comptime {...@@ -10,4 +10,4 @@ comptime {
10// backend=stage210// backend=stage2
11// target=native11// target=native
12//12//
13// :5:13: error: 'error.B' not a member of error set 'error{C,A}'13// :5:19: error: 'error.B' not a member of error set 'error{C,A}'
test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig+1-1
...@@ -7,7 +7,7 @@ const Small = enum(u2) {...@@ -7,7 +7,7 @@ const Small = enum(u2) {
77
8export fn entry() void {8export fn entry() void {
9 var y = @as(f32, 3);9 var y = @as(f32, 3);
10 var x = @enumFromInt(Small, y);10 var x: Small = @enumFromInt(y);
11 _ = x;11 _ = x;
12}12}
1313
test/cases/compile_errors/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig+1-1
...@@ -8,7 +8,7 @@ const foo = Foo{...@@ -8,7 +8,7 @@ const foo = Foo{
8};8};
99
10comptime {10comptime {
11 const field_ptr = @ptrFromInt(*i32, 0x1234);11 const field_ptr: *i32 = @ptrFromInt(0x1234);
12 const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr);12 const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr);
13 _ = another_foo_ptr;13 _ = another_foo_ptr;
14}14}
test/cases/compile_errors/field_access_of_opaque_type.zig+1-1
...@@ -2,7 +2,7 @@ const MyType = opaque {};...@@ -2,7 +2,7 @@ const MyType = opaque {};
22
3export fn entry() bool {3export fn entry() bool {
4 var x: i32 = 1;4 var x: i32 = 1;
5 return bar(@ptrCast(*MyType, &x));5 return bar(@ptrCast(&x));
6}6}
77
8fn bar(x: *MyType) bool {8fn bar(x: *MyType) bool {
test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig+2-2
...@@ -2,7 +2,7 @@ pub export fn entry() void {...@@ -2,7 +2,7 @@ pub export fn entry() void {
2 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };2 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
3 var slice: []u8 = &buf;3 var slice: []u8 = &buf;
4 const a: u32 = 1234;4 const a: u32 = 1234;
5 @memcpy(slice.ptr, @ptrCast([*]const u8, &a));5 @memcpy(slice.ptr, @as([*]const u8, @ptrCast(&a)));
6}6}
7pub export fn entry1() void {7pub export fn entry1() void {
8 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };8 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
...@@ -39,7 +39,7 @@ pub export fn memset_array() void {...@@ -39,7 +39,7 @@ pub export fn memset_array() void {
39//39//
40// :5:5: error: unknown @memcpy length40// :5:5: error: unknown @memcpy length
41// :5:18: note: destination type '[*]u8' provides no length41// :5:18: note: destination type '[*]u8' provides no length
42// :5:24: note: source type '[*]align(4) const u8' provides no length42// :5:24: note: source type '[*]const u8' provides no length
43// :10:13: error: type '*u8' is not an indexable pointer43// :10:13: error: type '*u8' is not an indexable pointer
44// :10:13: note: operand must be a slice, a many pointer or a pointer to an array44// :10:13: note: operand must be a slice, a many pointer or a pointer to an array
45// :15:13: error: type '*u8' is not an indexable pointer45// :15:13: error: type '*u8' is not an indexable pointer
test/cases/compile_errors/increase_pointer_alignment_in_ptrCast.zig+4-4
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1export fn entry() u32 {1export fn entry() u32 {
2 var bytes: [4]u8 = [_]u8{ 0x01, 0x02, 0x03, 0x04 };2 var bytes: [4]u8 = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
3 const ptr = @ptrCast(*u32, &bytes[0]);3 const ptr: *u32 = @ptrCast(&bytes[0]);
4 return ptr.*;4 return ptr.*;
5}5}
66
...@@ -8,7 +8,7 @@ export fn entry() u32 {...@@ -8,7 +8,7 @@ export fn entry() u32 {
8// backend=stage28// backend=stage2
9// target=native9// target=native
10//10//
11// :3:17: error: cast increases pointer alignment11// :3:23: error: cast increases pointer alignment
12// :3:32: note: '*u8' has alignment '1'12// :3:32: note: '*u8' has alignment '1'
13// :3:26: note: '*u32' has alignment '4'13// :3:23: note: '*u32' has alignment '4'
14// :3:17: note: consider using '@alignCast'14// :3:23: note: use @alignCast to assert pointer alignment
test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig+6-6
...@@ -1,17 +1,17 @@...@@ -1,17 +1,17 @@
1export fn foo() void {1export fn foo() void {
2 var a: f32 = 2;2 var a: f32 = 2;
3 _ = @intFromFloat(comptime_int, a);3 _ = @as(comptime_int, @intFromFloat(a));
4}4}
5export fn bar() void {5export fn bar() void {
6 var a: u32 = 2;6 var a: u32 = 2;
7 _ = @floatFromInt(comptime_float, a);7 _ = @as(comptime_float, @floatFromInt(a));
8}8}
99
10// error10// error
11// backend=stage211// backend=stage2
12// target=native12// target=native
13//13//
14// :3:37: error: unable to resolve comptime value14// :3:41: error: unable to resolve comptime value
15// :3:37: note: value being casted to 'comptime_int' must be comptime-known15// :3:41: note: value being casted to 'comptime_int' must be comptime-known
16// :7:39: error: unable to resolve comptime value16// :7:43: error: unable to resolve comptime value
17// :7:39: note: value being casted to 'comptime_float' must be comptime-known17// :7:43: note: value being casted to 'comptime_float' must be comptime-known
test/cases/compile_errors/intFromFloat_comptime_safety.zig+6-6
...@@ -1,17 +1,17 @@...@@ -1,17 +1,17 @@
1comptime {1comptime {
2 _ = @intFromFloat(i8, @as(f32, -129.1));2 _ = @as(i8, @intFromFloat(@as(f32, -129.1)));
3}3}
4comptime {4comptime {
5 _ = @intFromFloat(u8, @as(f32, -1.1));5 _ = @as(u8, @intFromFloat(@as(f32, -1.1)));
6}6}
7comptime {7comptime {
8 _ = @intFromFloat(u8, @as(f32, 256.1));8 _ = @as(u8, @intFromFloat(@as(f32, 256.1)));
9}9}
1010
11// error11// error
12// backend=stage212// backend=stage2
13// target=native13// target=native
14//14//
15// :2:27: error: float value '-129.10000610351562' cannot be stored in integer type 'i8'15// :2:31: error: float value '-129.10000610351562' cannot be stored in integer type 'i8'
16// :5:27: error: float value '-1.100000023841858' cannot be stored in integer type 'u8'16// :5:31: error: float value '-1.100000023841858' cannot be stored in integer type 'u8'
17// :8:27: error: float value '256.1000061035156' cannot be stored in integer type 'u8'17// :8:31: error: float value '256.1000061035156' cannot be stored in integer type 'u8'
test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1export fn entry() void {1export fn entry() void {
2 var b = @ptrFromInt(*i32, 0);2 var b: *i32 = @ptrFromInt(0);
3 _ = b;3 _ = b;
4}4}
55
test/cases/compile_errors/int_to_err_non_global_invalid_number.zig+2-2
...@@ -8,7 +8,7 @@ const Set2 = error{...@@ -8,7 +8,7 @@ const Set2 = error{
8};8};
9comptime {9comptime {
10 var x = @intFromError(Set1.B);10 var x = @intFromError(Set1.B);
11 var y = @errSetCast(Set2, @errorFromInt(x));11 var y: Set2 = @errSetCast(@errorFromInt(x));
12 _ = y;12 _ = y;
13}13}
1414
...@@ -16,4 +16,4 @@ comptime {...@@ -16,4 +16,4 @@ comptime {
16// backend=llvm16// backend=llvm
17// target=native17// target=native
18//18//
19// :11:13: error: 'error.B' not a member of error set 'error{C,A}'19// :11:19: error: 'error.B' not a member of error set 'error{C,A}'
test/cases/compile_errors/integer_cast_truncates_bits.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1export fn entry1() void {1export fn entry1() void {
2 const spartan_count: u16 = 300;2 const spartan_count: u16 = 300;
3 const byte = @intCast(u8, spartan_count);3 const byte: u8 = @intCast(spartan_count);
4 _ = byte;4 _ = byte;
5}5}
6export fn entry2() void {6export fn entry2() void {
test/cases/compile_errors/integer_underflow_error.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1export fn entry() void {1export fn entry() void {
2 _ = @ptrFromInt(*anyopaque, ~@as(usize, @import("std").math.maxInt(usize)) - 1);2 _ = @as(*anyopaque, @ptrFromInt(~@as(usize, @import("std").math.maxInt(usize)) - 1));
3}3}
44
5// error5// error
6// backend=stage26// backend=stage2
7// target=native7// target=native
8//8//
9// :2:80: error: overflow of integer type 'usize' with value '-1'9// :2:84: error: overflow of integer type 'usize' with value '-1'
test/cases/compile_errors/invalid_float_casts.zig+8-8
...@@ -1,25 +1,25 @@...@@ -1,25 +1,25 @@
1export fn foo() void {1export fn foo() void {
2 var a: f32 = 2;2 var a: f32 = 2;
3 _ = @floatCast(comptime_float, a);3 _ = @as(comptime_float, @floatCast(a));
4}4}
5export fn bar() void {5export fn bar() void {
6 var a: f32 = 2;6 var a: f32 = 2;
7 _ = @intFromFloat(f32, a);7 _ = @as(f32, @intFromFloat(a));
8}8}
9export fn baz() void {9export fn baz() void {
10 var a: f32 = 2;10 var a: f32 = 2;
11 _ = @floatFromInt(f32, a);11 _ = @as(f32, @floatFromInt(a));
12}12}
13export fn qux() void {13export fn qux() void {
14 var a: u32 = 2;14 var a: u32 = 2;
15 _ = @floatCast(f32, a);15 _ = @as(f32, @floatCast(a));
16}16}
1717
18// error18// error
19// backend=stage219// backend=stage2
20// target=native20// target=native
21//21//
22// :3:36: error: unable to cast runtime value to 'comptime_float'22// :3:40: error: unable to cast runtime value to 'comptime_float'
23// :7:23: error: expected integer type, found 'f32'23// :7:18: error: expected integer type, found 'f32'
24// :11:28: error: expected integer type, found 'f32'24// :11:32: error: expected integer type, found 'f32'
25// :15:25: error: expected float type, found 'u32'25// :15:29: error: expected float type, found 'u32'
test/cases/compile_errors/invalid_int_casts.zig+8-8
...@@ -1,25 +1,25 @@...@@ -1,25 +1,25 @@
1export fn foo() void {1export fn foo() void {
2 var a: u32 = 2;2 var a: u32 = 2;
3 _ = @intCast(comptime_int, a);3 _ = @as(comptime_int, @intCast(a));
4}4}
5export fn bar() void {5export fn bar() void {
6 var a: u32 = 2;6 var a: u32 = 2;
7 _ = @floatFromInt(u32, a);7 _ = @as(u32, @floatFromInt(a));
8}8}
9export fn baz() void {9export fn baz() void {
10 var a: u32 = 2;10 var a: u32 = 2;
11 _ = @intFromFloat(u32, a);11 _ = @as(u32, @intFromFloat(a));
12}12}
13export fn qux() void {13export fn qux() void {
14 var a: f32 = 2;14 var a: f32 = 2;
15 _ = @intCast(u32, a);15 _ = @as(u32, @intCast(a));
16}16}
1717
18// error18// error
19// backend=stage219// backend=stage2
20// target=native20// target=native
21//21//
22// :3:32: error: unable to cast runtime value to 'comptime_int'22// :3:36: error: unable to cast runtime value to 'comptime_int'
23// :7:23: error: expected float type, found 'u32'23// :7:18: error: expected float type, found 'u32'
24// :11:28: error: expected float type, found 'u32'24// :11:32: error: expected float type, found 'u32'
25// :15:23: error: expected integer or vector, found 'f32'25// :15:27: error: expected integer or vector, found 'f32'
test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig+3-3
...@@ -8,12 +8,12 @@ const U = union(E) {...@@ -8,12 +8,12 @@ const U = union(E) {
8 b,8 b,
9};9};
10export fn foo() void {10export fn foo() void {
11 var e = @enumFromInt(E, 15);11 var e: E = @enumFromInt(15);
12 var u: U = e;12 var u: U = e;
13 _ = u;13 _ = u;
14}14}
15export fn bar() void {15export fn bar() void {
16 const e = @enumFromInt(E, 15);16 const e: E = @enumFromInt(15);
17 var u: U = e;17 var u: U = e;
18 _ = u;18 _ = u;
19}19}
...@@ -24,5 +24,5 @@ export fn bar() void {...@@ -24,5 +24,5 @@ export fn bar() void {
24//24//
25// :12:16: error: runtime coercion to union 'tmp.U' from non-exhaustive enum25// :12:16: error: runtime coercion to union 'tmp.U' from non-exhaustive enum
26// :1:11: note: enum declared here26// :1:11: note: enum declared here
27// :17:16: error: union 'tmp.U' has no tag with value '@enumFromInt(tmp.E, 15)'27// :17:16: error: union 'tmp.U' has no tag with value '@enumFromInt(15)'
28// :6:11: note: union declared here28// :6:11: note: union declared here
test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig+6-6
...@@ -1,11 +1,11 @@...@@ -1,11 +1,11 @@
1export fn foo1() void {1export fn foo1() void {
2 var bytes = [_]u8{ 1, 2 };2 var bytes = [_]u8{ 1, 2 };
3 const word: u16 = @bitCast(u16, bytes[0..]);3 const word: u16 = @bitCast(bytes[0..]);
4 _ = word;4 _ = word;
5}5}
6export fn foo2() void {6export fn foo2() void {
7 var bytes: []const u8 = &[_]u8{ 1, 2 };7 var bytes: []const u8 = &[_]u8{ 1, 2 };
8 const word: u16 = @bitCast(u16, bytes);8 const word: u16 = @bitCast(bytes);
9 _ = word;9 _ = word;
10}10}
1111
...@@ -13,7 +13,7 @@ export fn foo2() void {...@@ -13,7 +13,7 @@ export fn foo2() void {
13// backend=stage213// backend=stage2
14// target=native14// target=native
15//15//
16// :3:42: error: cannot @bitCast from '*[2]u8'16// :3:37: error: cannot @bitCast from '*[2]u8'
17// :3:42: note: use @intFromPtr to cast to 'u16'17// :3:37: note: use @intFromPtr to cast to 'u16'
18// :8:37: error: cannot @bitCast from '[]const u8'18// :8:32: error: cannot @bitCast from '[]const u8'
19// :8:37: note: use @intFromPtr to cast to 'u16'19// :8:32: note: use @intFromPtr to cast to 'u16'
test/cases/compile_errors/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1export fn entry() void {1export fn entry() void {
2 const float: f32 align(@alignOf(i64)) = 5.99999999999994648725e-01;2 const float: f32 align(@alignOf(i64)) = 5.99999999999994648725e-01;
3 const float_ptr = &float;3 const float_ptr = &float;
4 const int_ptr = @ptrCast(*const i64, float_ptr);4 const int_ptr: *const i64 = @ptrCast(float_ptr);
5 const int_val = int_ptr.*;5 const int_val = int_ptr.*;
6 _ = int_val;6 _ = int_val;
7}7}
test/cases/compile_errors/missing_builtin_arg_in_initializer.zig+7-3
...@@ -1,8 +1,11 @@...@@ -1,8 +1,11 @@
1comptime {1comptime {
2 const v = @as();2 const a = @as();
3}3}
4comptime {4comptime {
5 const u = @bitCast(u32);5 const b = @bitCast();
6}
7comptime {
8 const c = @as(u32);
6}9}
710
8// error11// error
...@@ -10,4 +13,5 @@ comptime {...@@ -10,4 +13,5 @@ comptime {
10// target=native13// target=native
11//14//
12// :2:15: error: expected 2 arguments, found 015// :2:15: error: expected 2 arguments, found 0
13// :5:15: error: expected 2 arguments, found 116// :5:15: error: expected 1 argument, found 0
17// :8:15: error: expected 2 arguments, found 1
test/cases/compile_errors/non_float_passed_to_intFromFloat.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1export fn entry() void {1export fn entry() void {
2 const x = @intFromFloat(i32, @as(i32, 54));2 const x: i32 = @intFromFloat(@as(i32, 54));
3 _ = x;3 _ = x;
4}4}
55
test/cases/compile_errors/non_int_passed_to_floatFromInt.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1export fn entry() void {1export fn entry() void {
2 const x = @floatFromInt(f32, 1.1);2 const x: f32 = @floatFromInt(1.1);
3 _ = x;3 _ = x;
4}4}
55
test/cases/compile_errors/out_of_int_range_comptime_float_passed_to_intFromFloat.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1export fn entry() void {1export fn entry() void {
2 const x = @intFromFloat(i8, 200);2 const x: i8 = @intFromFloat(200);
3 _ = x;3 _ = x;
4}4}
55
test/cases/compile_errors/ptrCast_discards_const_qualifier.zig+3-3
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 const x: i32 = 1234;2 const x: i32 = 1234;
3 const y = @ptrCast(*i32, &x);3 const y: *i32 = @ptrCast(&x);
4 _ = y;4 _ = y;
5}5}
66
...@@ -8,5 +8,5 @@ export fn entry() void {...@@ -8,5 +8,5 @@ export fn entry() void {
8// backend=stage28// backend=stage2
9// target=native9// target=native
10//10//
11// :3:15: error: cast discards const qualifier11// :3:21: error: cast discards const qualifier
12// :3:15: note: consider using '@constCast'12// :3:21: note: use @constCast to discard const qualifier
test/cases/compile_errors/ptrFromInt_non_ptr_type.zig+5-5
...@@ -1,15 +1,15 @@...@@ -1,15 +1,15 @@
1pub export fn entry() void {1pub export fn entry() void {
2 _ = @ptrFromInt(i32, 10);2 _ = @as(i32, @ptrFromInt(10));
3}3}
44
5pub export fn entry2() void {5pub export fn entry2() void {
6 _ = @ptrFromInt([]u8, 20);6 _ = @as([]u8, @ptrFromInt(20));
7}7}
88
9// error9// error
10// backend=stage210// backend=stage2
11// target=native11// target=native
12//12//
13// :2:21: error: expected pointer type, found 'i32'13// :2:18: error: expected pointer type, found 'i32'
14// :6:21: error: integer cannot be converted to slice type '[]u8'14// :6:19: error: integer cannot be converted to slice type '[]u8'
15// :6:21: note: slice length cannot be inferred from address15// :6:19: note: slice length cannot be inferred from address
test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1pub export fn entry() void {1pub export fn entry() void {
2 var y = @ptrFromInt([*]align(4) u8, 5);2 var y: [*]align(4) u8 = @ptrFromInt(5);
3 _ = y;3 _ = y;
4}4}
55
test/cases/compile_errors/ptrcast_to_non-pointer.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1export fn entry(a: *i32) usize {1export fn entry(a: *i32) usize {
2 return @ptrCast(usize, a);2 return @ptrCast(a);
3}3}
44
5// error5// error
6// backend=llvm6// backend=llvm
7// target=native7// target=native
8//8//
9// :2:21: error: expected pointer type, found 'usize'9// :2:12: error: expected pointer type, found 'usize'
test/cases/compile_errors/reading_past_end_of_pointer_casted_array.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1comptime {1comptime {
2 const array: [4]u8 = "aoeu".*;2 const array: [4]u8 = "aoeu".*;
3 const sub_array = array[1..];3 const sub_array = array[1..];
4 const int_ptr = @ptrCast(*const u24, @alignCast(@alignOf(u24), sub_array));4 const int_ptr: *const u24 = @ptrCast(@alignCast(sub_array));
5 const deref = int_ptr.*;5 const deref = int_ptr.*;
6 _ = deref;6 _ = deref;
7}7}
test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig+1-1
...@@ -7,7 +7,7 @@ const Tag = @Type(.{...@@ -7,7 +7,7 @@ const Tag = @Type(.{
7 },7 },
8});8});
9export fn entry() void {9export fn entry() void {
10 _ = @enumFromInt(Tag, 0);10 _ = @as(Tag, @enumFromInt(0));
11}11}
1212
13// error13// error
test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig+1-1
...@@ -7,7 +7,7 @@ const Tag = @Type(.{...@@ -7,7 +7,7 @@ const Tag = @Type(.{
7 },7 },
8});8});
9export fn entry() void {9export fn entry() void {
10 _ = @enumFromInt(Tag, 0);10 _ = @as(Tag, @enumFromInt(0));
11}11}
1212
13// error13// error
test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig+2-2
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1export fn foo() void {1export fn foo() void {
2 const bytes align(@alignOf([]const u8)) = [1]u8{0xfa} ** 16;2 const bytes align(@alignOf([]const u8)) = [1]u8{0xfa} ** 16;
3 var value = @ptrCast(*const []const u8, &bytes).*;3 var value = @as(*const []const u8, @ptrCast(&bytes)).*;
4 _ = value;4 _ = value;
5}5}
66
...@@ -8,4 +8,4 @@ export fn foo() void {...@@ -8,4 +8,4 @@ export fn foo() void {
8// backend=stage28// backend=stage2
9// target=native9// target=native
10//10//
11// :3:52: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not.11// :3:57: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not.
test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig+2-2
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1test "enum" {1test "enum" {
2 const E = enum(u8) { A, B, _ };2 const E = enum(u8) { A, B, _ };
3 _ = @tagName(@enumFromInt(E, 5));3 _ = @tagName(@as(E, @enumFromInt(5)));
4}4}
55
6// error6// error
...@@ -8,5 +8,5 @@ test "enum" {...@@ -8,5 +8,5 @@ test "enum" {
8// target=native8// target=native
9// is_test=19// is_test=1
10//10//
11// :3:9: error: no field with value '@enumFromInt(tmp.test.enum.E, 5)' in enum 'test.enum.E'11// :3:9: error: no field with value '@enumFromInt(5)' in enum 'test.enum.E'
12// :2:15: note: declared here12// :2:15: note: declared here
test/cases/compile_errors/truncate_sign_mismatch.zig+8-8
...@@ -1,25 +1,25 @@...@@ -1,25 +1,25 @@
1export fn entry1() i8 {1export fn entry1() i8 {
2 var x: u32 = 10;2 var x: u32 = 10;
3 return @truncate(i8, x);3 return @truncate(x);
4}4}
5export fn entry2() u8 {5export fn entry2() u8 {
6 var x: i32 = -10;6 var x: i32 = -10;
7 return @truncate(u8, x);7 return @truncate(x);
8}8}
9export fn entry3() i8 {9export fn entry3() i8 {
10 comptime var x: u32 = 10;10 comptime var x: u32 = 10;
11 return @truncate(i8, x);11 return @truncate(x);
12}12}
13export fn entry4() u8 {13export fn entry4() u8 {
14 comptime var x: i32 = -10;14 comptime var x: i32 = -10;
15 return @truncate(u8, x);15 return @truncate(x);
16}16}
1717
18// error18// error
19// backend=stage219// backend=stage2
20// target=native20// target=native
21//21//
22// :3:26: error: expected signed integer type, found 'u32'22// :3:22: error: expected signed integer type, found 'u32'
23// :7:26: error: expected unsigned integer type, found 'i32'23// :7:22: error: expected unsigned integer type, found 'i32'
24// :11:26: error: expected signed integer type, found 'u32'24// :11:22: error: expected signed integer type, found 'u32'
25// :15:26: error: expected unsigned integer type, found 'i32'25// :15:22: error: expected unsigned integer type, found 'i32'
test/cases/compile_errors/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig+1-1
...@@ -2,7 +2,7 @@ const Derp = opaque {};...@@ -2,7 +2,7 @@ const Derp = opaque {};
2extern fn bar(d: *Derp) void;2extern fn bar(d: *Derp) void;
3export fn foo() void {3export fn foo() void {
4 var x = @as(u8, 1);4 var x = @as(u8, 1);
5 bar(@ptrCast(*anyopaque, &x));5 bar(@as(*anyopaque, @ptrCast(&x)));
6}6}
77
8// error8// error
test/cases/enum_values.0.zig+1-1
...@@ -7,7 +7,7 @@ pub fn main() void {...@@ -7,7 +7,7 @@ pub fn main() void {
7 number1;7 number1;
8 number2;8 number2;
9 }9 }
10 const number3 = @enumFromInt(Number, 2);10 const number3: Number = @enumFromInt(2);
11 if (@intFromEnum(number3) != 2) {11 if (@intFromEnum(number3) != 2) {
12 unreachable;12 unreachable;
13 }13 }
test/cases/enum_values.1.zig+1-1
...@@ -3,7 +3,7 @@ const Number = enum { One, Two, Three };...@@ -3,7 +3,7 @@ const Number = enum { One, Two, Three };
3pub fn main() void {3pub fn main() void {
4 var number1 = Number.One;4 var number1 = Number.One;
5 var number2: Number = .Two;5 var number2: Number = .Two;
6 const number3 = @enumFromInt(Number, 2);6 const number3: Number = @enumFromInt(2);
7 assert(number1 != number2);7 assert(number1 != number2);
8 assert(number2 != number3);8 assert(number2 != number3);
9 assert(@intFromEnum(number1) == 0);9 assert(@intFromEnum(number1) == 0);
test/cases/error_in_nested_declaration.zig+3-3
...@@ -3,7 +3,7 @@ const S = struct {...@@ -3,7 +3,7 @@ const S = struct {
3 c: i32,3 c: i32,
4 a: struct {4 a: struct {
5 pub fn str(_: @This(), extra: []u32) []i32 {5 pub fn str(_: @This(), extra: []u32) []i32 {
6 return @bitCast([]i32, extra);6 return @bitCast(extra);
7 }7 }
8 },8 },
9};9};
...@@ -27,5 +27,5 @@ pub export fn entry2() void {...@@ -27,5 +27,5 @@ pub export fn entry2() void {
27// target=native27// target=native
28//28//
29// :17:12: error: C pointers cannot point to opaque types29// :17:12: error: C pointers cannot point to opaque types
30// :6:29: error: cannot @bitCast to '[]i32'30// :6:20: error: cannot @bitCast to '[]i32'
31// :6:29: note: use @ptrCast to cast from '[]u32'31// :6:20: note: use @ptrCast to cast from '[]u32'
test/cases/int_to_ptr.0.zig+2-2
...@@ -1,8 +1,8 @@...@@ -1,8 +1,8 @@
1pub fn main() void {1pub fn main() void {
2 _ = @ptrFromInt(*u8, 0);2 _ = @as(*u8, @ptrFromInt(0));
3}3}
44
5// error5// error
6// output_mode=Exe6// output_mode=Exe
7//7//
8// :2:24: error: pointer type '*u8' does not allow address zero8// :2:18: error: pointer type '*u8' does not allow address zero
test/cases/int_to_ptr.1.zig+2-2
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1pub fn main() void {1pub fn main() void {
2 _ = @ptrFromInt(*u32, 2);2 _ = @as(*u32, @ptrFromInt(2));
3}3}
44
5// error5// error
6//6//
7// :2:25: error: pointer type '*u32' requires aligned address7// :2:19: error: pointer type '*u32' requires aligned address
test/cases/llvm/f_segment_address_space_reading_and_writing.zig+1-1
...@@ -34,7 +34,7 @@ pub fn main() void {...@@ -34,7 +34,7 @@ pub fn main() void {
34 setFs(@intFromPtr(&test_value));34 setFs(@intFromPtr(&test_value));
35 assert(getFs() == @intFromPtr(&test_value));35 assert(getFs() == @intFromPtr(&test_value));
3636
37 var test_ptr = @ptrFromInt(*allowzero addrspace(.fs) u64, 0);37 var test_ptr: *allowzero addrspace(.fs) u64 = @ptrFromInt(0);
38 assert(test_ptr.* == 12345);38 assert(test_ptr.* == 12345);
39 test_ptr.* = 98765;39 test_ptr.* = 98765;
40 assert(test_value == 98765);40 assert(test_value == 98765);
test/cases/llvm/large_slices.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1pub fn main() void {1pub fn main() void {
2 const large_slice = @ptrFromInt([*]const u8, 1)[0..(0xffffffffffffffff >> 3)];2 const large_slice = @as([*]const u8, @ptrFromInt(1))[0..(0xffffffffffffffff >> 3)];
3 _ = large_slice;3 _ = large_slice;
4}4}
55
test/cases/safety/@alignCast misaligned.zig +2-1
...@@ -16,7 +16,8 @@ pub fn main() !void {...@@ -16,7 +16,8 @@ pub fn main() !void {
16}16}
17fn foo(bytes: []u8) u32 {17fn foo(bytes: []u8) u32 {
18 const slice4 = bytes[1..5];18 const slice4 = bytes[1..5];
19 const int_slice = std.mem.bytesAsSlice(u32, @alignCast(4, slice4));19 const aligned: *align(4) [4]u8 = @alignCast(slice4);
20 const int_slice = std.mem.bytesAsSlice(u32, aligned);
20 return int_slice[0];21 return int_slice[0];
21}22}
22// run23// run
test/cases/safety/@enumFromInt - no matching tag value.zig +1-1
...@@ -17,7 +17,7 @@ pub fn main() !void {...@@ -17,7 +17,7 @@ pub fn main() !void {
17 return error.TestFailed;17 return error.TestFailed;
18}18}
19fn bar(a: u2) Foo {19fn bar(a: u2) Foo {
20 return @enumFromInt(Foo, a);20 return @enumFromInt(a);
21}21}
22fn baz(_: Foo) void {}22fn baz(_: Foo) void {}
2323
test/cases/safety/@errSetCast error not present in destination.zig +1-1
...@@ -14,7 +14,7 @@ pub fn main() !void {...@@ -14,7 +14,7 @@ pub fn main() !void {
14 return error.TestFailed;14 return error.TestFailed;
15}15}
16fn foo(set1: Set1) Set2 {16fn foo(set1: Set1) Set2 {
17 return @errSetCast(Set2, set1);17 return @errSetCast(set1);
18}18}
19// run19// run
20// backend=llvm20// backend=llvm
test/cases/safety/@intCast to u0.zig +1-1
...@@ -14,7 +14,7 @@ pub fn main() !void {...@@ -14,7 +14,7 @@ pub fn main() !void {
14}14}
1515
16fn bar(one: u1, not_zero: i32) void {16fn bar(one: u1, not_zero: i32) void {
17 var x = one << @intCast(u0, not_zero);17 var x = one << @as(u0, @intCast(not_zero));
18 _ = x;18 _ = x;
19}19}
20// run20// run
test/cases/safety/@intFromFloat cannot fit - negative out of range.zig +1-1
...@@ -12,7 +12,7 @@ pub fn main() !void {...@@ -12,7 +12,7 @@ pub fn main() !void {
12 return error.TestFailed;12 return error.TestFailed;
13}13}
14fn bar(a: f32) i8 {14fn bar(a: f32) i8 {
15 return @intFromFloat(i8, a);15 return @intFromFloat(a);
16}16}
17fn baz(_: i8) void {}17fn baz(_: i8) void {}
18// run18// run
test/cases/safety/@intFromFloat cannot fit - negative to unsigned.zig +1-1
...@@ -12,7 +12,7 @@ pub fn main() !void {...@@ -12,7 +12,7 @@ pub fn main() !void {
12 return error.TestFailed;12 return error.TestFailed;
13}13}
14fn bar(a: f32) u8 {14fn bar(a: f32) u8 {
15 return @intFromFloat(u8, a);15 return @intFromFloat(a);
16}16}
17fn baz(_: u8) void {}17fn baz(_: u8) void {}
18// run18// run
test/cases/safety/@intFromFloat cannot fit - positive out of range.zig +1-1
...@@ -12,7 +12,7 @@ pub fn main() !void {...@@ -12,7 +12,7 @@ pub fn main() !void {
12 return error.TestFailed;12 return error.TestFailed;
13}13}
14fn bar(a: f32) u8 {14fn bar(a: f32) u8 {
15 return @intFromFloat(u8, a);15 return @intFromFloat(a);
16}16}
17fn baz(_: u8) void {}17fn baz(_: u8) void {}
18// run18// run
test/cases/safety/@ptrFromInt address zero to non-optional byte-aligned pointer.zig +1-1
...@@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var zero: usize = 0;11 var zero: usize = 0;
12 var b = @ptrFromInt(*u8, zero);12 var b: *u8 = @ptrFromInt(zero);
13 _ = b;13 _ = b;
14 return error.TestFailed;14 return error.TestFailed;
15}15}
test/cases/safety/@ptrFromInt address zero to non-optional pointer.zig +1-1
...@@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var zero: usize = 0;11 var zero: usize = 0;
12 var b = @ptrFromInt(*i32, zero);12 var b: *i32 = @ptrFromInt(zero);
13 _ = b;13 _ = b;
14 return error.TestFailed;14 return error.TestFailed;
15}15}
test/cases/safety/@ptrFromInt with misaligned address.zig +1-1
...@@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var x: usize = 5;11 var x: usize = 5;
12 var y = @ptrFromInt([*]align(4) u8, x);12 var y: [*]align(4) u8 = @ptrFromInt(x);
13 _ = y;13 _ = y;
14 return error.TestFailed;14 return error.TestFailed;
15}15}
test/cases/safety/@tagName on corrupted enum value.zig +1-1
...@@ -15,7 +15,7 @@ const E = enum(u32) {...@@ -15,7 +15,7 @@ const E = enum(u32) {
1515
16pub fn main() !void {16pub fn main() !void {
17 var e: E = undefined;17 var e: E = undefined;
18 @memset(@ptrCast([*]u8, &e)[0..@sizeOf(E)], 0x55);18 @memset(@as([*]u8, @ptrCast(&e))[0..@sizeOf(E)], 0x55);
19 var n = @tagName(e);19 var n = @tagName(e);
20 _ = n;20 _ = n;
21 return error.TestFailed;21 return error.TestFailed;
test/cases/safety/@tagName on corrupted union value.zig +1-1
...@@ -15,7 +15,7 @@ const U = union(enum(u32)) {...@@ -15,7 +15,7 @@ const U = union(enum(u32)) {
1515
16pub fn main() !void {16pub fn main() !void {
17 var u: U = undefined;17 var u: U = undefined;
18 @memset(@ptrCast([*]u8, &u)[0..@sizeOf(U)], 0x55);18 @memset(@as([*]u8, @ptrCast(&u))[0..@sizeOf(U)], 0x55);
19 var t: @typeInfo(U).Union.tag_type.? = u;19 var t: @typeInfo(U).Union.tag_type.? = u;
20 var n = @tagName(t);20 var n = @tagName(t);
21 _ = n;21 _ = n;
test/cases/safety/pointer casting to null function pointer.zig +1-1
...@@ -13,7 +13,7 @@ fn getNullPtr() ?*const anyopaque {...@@ -13,7 +13,7 @@ fn getNullPtr() ?*const anyopaque {
13}13}
14pub fn main() !void {14pub fn main() !void {
15 const null_ptr: ?*const anyopaque = getNullPtr();15 const null_ptr: ?*const anyopaque = getNullPtr();
16 const required_ptr: *align(1) const fn () void = @ptrCast(*align(1) const fn () void, null_ptr);16 const required_ptr: *align(1) const fn () void = @ptrCast(null_ptr);
17 _ = required_ptr;17 _ = required_ptr;
18 return error.TestFailed;18 return error.TestFailed;
19}19}
test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig +1-1
...@@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var value: c_short = -1;11 var value: c_short = -1;
12 var casted = @intCast(u32, value);12 var casted: u32 = @intCast(value);
13 _ = casted;13 _ = casted;
14 return error.TestFailed;14 return error.TestFailed;
15}15}
test/cases/safety/signed integer not fitting in cast to unsigned integer.zig +1-1
...@@ -13,7 +13,7 @@ pub fn main() !void {...@@ -13,7 +13,7 @@ pub fn main() !void {
13 return error.TestFailed;13 return error.TestFailed;
14}14}
15fn unsigned_cast(x: i32) u32 {15fn unsigned_cast(x: i32) u32 {
16 return @intCast(u32, x);16 return @intCast(x);
17}17}
18// run18// run
19// backend=llvm19// backend=llvm
test/cases/safety/signed-unsigned vector cast.zig +1-1
...@@ -10,7 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -10,7 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010
11pub fn main() !void {11pub fn main() !void {
12 var x = @splat(4, @as(i32, -2147483647));12 var x = @splat(4, @as(i32, -2147483647));
13 var y = @intCast(@Vector(4, u32), x);13 var y: @Vector(4, u32) = @intCast(x);
14 _ = y;14 _ = y;
15 return error.TestFailed;15 return error.TestFailed;
16}16}
test/cases/safety/slice sentinel mismatch - optional pointers.zig +1-1
...@@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
9}9}
1010
11pub fn main() !void {11pub fn main() !void {
12 var buf: [4]?*i32 = .{ @ptrFromInt(*i32, 4), @ptrFromInt(*i32, 8), @ptrFromInt(*i32, 12), @ptrFromInt(*i32, 16) };12 var buf: [4]?*i32 = .{ @ptrFromInt(4), @ptrFromInt(8), @ptrFromInt(12), @ptrFromInt(16) };
13 const slice = buf[0..3 :null];13 const slice = buf[0..3 :null];
14 _ = slice;14 _ = slice;
15 return error.TestFailed;15 return error.TestFailed;
test/cases/safety/switch else on corrupt enum value - one prong.zig +1-1
...@@ -13,7 +13,7 @@ const E = enum(u32) {...@@ -13,7 +13,7 @@ const E = enum(u32) {
13};13};
14pub fn main() !void {14pub fn main() !void {
15 var a: E = undefined;15 var a: E = undefined;
16 @ptrCast(*u32, &a).* = 255;16 @as(*u32, @ptrCast(&a)).* = 255;
17 switch (a) {17 switch (a) {
18 .one => @panic("one"),18 .one => @panic("one"),
19 else => @panic("else"),19 else => @panic("else"),
test/cases/safety/switch else on corrupt enum value - union.zig +1-1
...@@ -18,7 +18,7 @@ const U = union(E) {...@@ -18,7 +18,7 @@ const U = union(E) {
18};18};
19pub fn main() !void {19pub fn main() !void {
20 var a: U = undefined;20 var a: U = undefined;
21 @ptrCast(*align(@alignOf(U)) u32, &a).* = 0xFFFF_FFFF;21 @as(*align(@alignOf(U)) u32, @ptrCast(&a)).* = 0xFFFF_FFFF;
22 switch (a) {22 switch (a) {
23 .one => @panic("one"),23 .one => @panic("one"),
24 else => @panic("else"),24 else => @panic("else"),
test/cases/safety/switch else on corrupt enum value.zig +1-1
...@@ -13,7 +13,7 @@ const E = enum(u32) {...@@ -13,7 +13,7 @@ const E = enum(u32) {
13};13};
14pub fn main() !void {14pub fn main() !void {
15 var a: E = undefined;15 var a: E = undefined;
16 @ptrCast(*u32, &a).* = 255;16 @as(*u32, @ptrCast(&a)).* = 255;
17 switch (a) {17 switch (a) {
18 else => @panic("else"),18 else => @panic("else"),
19 }19 }
test/cases/safety/switch on corrupted enum value.zig +1-1
...@@ -15,7 +15,7 @@ const E = enum(u32) {...@@ -15,7 +15,7 @@ const E = enum(u32) {
1515
16pub fn main() !void {16pub fn main() !void {
17 var e: E = undefined;17 var e: E = undefined;
18 @memset(@ptrCast([*]u8, &e)[0..@sizeOf(E)], 0x55);18 @memset(@as([*]u8, @ptrCast(&e))[0..@sizeOf(E)], 0x55);
19 switch (e) {19 switch (e) {
20 .X, .Y => @breakpoint(),20 .X, .Y => @breakpoint(),
21 }21 }
test/cases/safety/switch on corrupted union value.zig +1-1
...@@ -15,7 +15,7 @@ const U = union(enum(u32)) {...@@ -15,7 +15,7 @@ const U = union(enum(u32)) {
1515
16pub fn main() !void {16pub fn main() !void {
17 var u: U = undefined;17 var u: U = undefined;
18 @memset(@ptrCast([*]u8, &u)[0..@sizeOf(U)], 0x55);18 @memset(@as([*]u8, @ptrCast(&u))[0..@sizeOf(U)], 0x55);
19 switch (u) {19 switch (u) {
20 .X, .Y => @breakpoint(),20 .X, .Y => @breakpoint(),
21 }21 }
test/cases/safety/truncating vector cast.zig +1-1
...@@ -10,7 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -10,7 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010
11pub fn main() !void {11pub fn main() !void {
12 var x = @splat(4, @as(u32, 0xdeadbeef));12 var x = @splat(4, @as(u32, 0xdeadbeef));
13 var y = @intCast(@Vector(4, u16), x);13 var y: @Vector(4, u16) = @intCast(x);
14 _ = y;14 _ = y;
15 return error.TestFailed;15 return error.TestFailed;
16}16}
test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig +1-1
...@@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var value: u8 = 245;11 var value: u8 = 245;
12 var casted = @intCast(i8, value);12 var casted: i8 = @intCast(value);
13 _ = casted;13 _ = casted;
14 return error.TestFailed;14 return error.TestFailed;
15}15}
test/cases/safety/unsigned-signed vector cast.zig +1-1
...@@ -10,7 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -10,7 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010
11pub fn main() !void {11pub fn main() !void {
12 var x = @splat(4, @as(u32, 0x80000000));12 var x = @splat(4, @as(u32, 0x80000000));
13 var y = @intCast(@Vector(4, i32), x);13 var y: @Vector(4, i32) = @intCast(x);
14 _ = y;14 _ = y;
15 return error.TestFailed;15 return error.TestFailed;
16}16}
test/cases/safety/value does not fit in shortening cast - u0.zig +1-1
...@@ -14,7 +14,7 @@ pub fn main() !void {...@@ -14,7 +14,7 @@ pub fn main() !void {
14 return error.TestFailed;14 return error.TestFailed;
15}15}
16fn shorten_cast(x: u8) u0 {16fn shorten_cast(x: u8) u0 {
17 return @intCast(u0, x);17 return @intCast(x);
18}18}
19// run19// run
20// backend=llvm20// backend=llvm
test/cases/safety/value does not fit in shortening cast.zig +1-1
...@@ -14,7 +14,7 @@ pub fn main() !void {...@@ -14,7 +14,7 @@ pub fn main() !void {
14 return error.TestFailed;14 return error.TestFailed;
15}15}
16fn shorten_cast(x: i32) i8 {16fn shorten_cast(x: i32) i8 {
17 return @intCast(i8, x);17 return @intCast(x);
18}18}
19// run19// run
20// backend=llvm20// backend=llvm
test/cbe.zig+5-5
...@@ -642,7 +642,7 @@ pub fn addCases(ctx: *Cases) !void {...@@ -642,7 +642,7 @@ pub fn addCases(ctx: *Cases) !void {
642 \\pub export fn main() c_int {642 \\pub export fn main() c_int {
643 \\ var number1 = Number.One;643 \\ var number1 = Number.One;
644 \\ var number2: Number = .Two;644 \\ var number2: Number = .Two;
645 \\ const number3 = @enumFromInt(Number, 2);645 \\ const number3: Number = @enumFromInt(2);
646 \\ if (number1 == number2) return 1;646 \\ if (number1 == number2) return 1;
647 \\ if (number2 == number3) return 1;647 \\ if (number2 == number3) return 1;
648 \\ if (@intFromEnum(number1) != 0) return 1;648 \\ if (@intFromEnum(number1) != 0) return 1;
...@@ -737,19 +737,19 @@ pub fn addCases(ctx: *Cases) !void {...@@ -737,19 +737,19 @@ pub fn addCases(ctx: *Cases) !void {
737 case.addError(737 case.addError(
738 \\pub export fn main() c_int {738 \\pub export fn main() c_int {
739 \\ const a = 1;739 \\ const a = 1;
740 \\ _ = @enumFromInt(bool, a);740 \\ _ = @as(bool, @enumFromInt(a));
741 \\}741 \\}
742 , &.{742 , &.{
743 ":3:20: error: expected enum, found 'bool'",743 ":3:19: error: expected enum, found 'bool'",
744 });744 });
745745
746 case.addError(746 case.addError(
747 \\const E = enum { a, b, c };747 \\const E = enum { a, b, c };
748 \\pub export fn main() c_int {748 \\pub export fn main() c_int {
749 \\ _ = @enumFromInt(E, 3);749 \\ _ = @as(E, @enumFromInt(3));
750 \\}750 \\}
751 , &.{751 , &.{
752 ":3:9: error: enum 'tmp.E' has no tag with value '3'",752 ":3:16: error: enum 'tmp.E' has no tag with value '3'",
753 ":1:11: note: enum declared here",753 ":1:11: note: enum declared here",
754 });754 });
755755
test/compare_output.zig+5-5
...@@ -180,8 +180,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -180,8 +180,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
180 \\const c = @cImport(@cInclude("stdlib.h"));180 \\const c = @cImport(@cInclude("stdlib.h"));
181 \\181 \\
182 \\export fn compare_fn(a: ?*const anyopaque, b: ?*const anyopaque) c_int {182 \\export fn compare_fn(a: ?*const anyopaque, b: ?*const anyopaque) c_int {
183 \\ const a_int = @ptrCast(*const i32, @alignCast(@alignOf(i32), a));183 \\ const a_int: *const i32 = @ptrCast(@alignCast(a));
184 \\ const b_int = @ptrCast(*const i32, @alignCast(@alignOf(i32), b));184 \\ const b_int: *const i32 = @ptrCast(@alignCast(b));
185 \\ if (a_int.* < b_int.*) {185 \\ if (a_int.* < b_int.*) {
186 \\ return -1;186 \\ return -1;
187 \\ } else if (a_int.* > b_int.*) {187 \\ } else if (a_int.* > b_int.*) {
...@@ -194,7 +194,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -194,7 +194,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
194 \\pub export fn main() c_int {194 \\pub export fn main() c_int {
195 \\ var array = [_]u32{ 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 };195 \\ var array = [_]u32{ 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 };
196 \\196 \\
197 \\ c.qsort(@ptrCast(?*anyopaque, &array), @intCast(c_ulong, array.len), @sizeOf(i32), compare_fn);197 \\ c.qsort(@ptrCast(&array), @intCast(array.len), @sizeOf(i32), compare_fn);
198 \\198 \\
199 \\ for (array, 0..) |item, i| {199 \\ for (array, 0..) |item, i| {
200 \\ if (item != i) {200 \\ if (item != i) {
...@@ -229,8 +229,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -229,8 +229,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
229 \\ }229 \\ }
230 \\ const small: f32 = 3.25;230 \\ const small: f32 = 3.25;
231 \\ const x: f64 = small;231 \\ const x: f64 = small;
232 \\ const y = @intFromFloat(i32, x);232 \\ const y: i32 = @intFromFloat(x);
233 \\ const z = @floatFromInt(f64, y);233 \\ const z: f64 = @floatFromInt(y);
234 \\ _ = c.printf("%.2f\n%d\n%.2f\n%.2f\n", x, y, z, @as(f64, -0.4));234 \\ _ = c.printf("%.2f\n%d\n%.2f\n%.2f\n", x, y, z, @as(f64, -0.4));
235 \\ return 0;235 \\ return 0;
236 \\}236 \\}
test/link/macho/dead_strip_dylibs/build.zig+1-1
...@@ -37,7 +37,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize...@@ -37,7 +37,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
37 exe.dead_strip_dylibs = true;37 exe.dead_strip_dylibs = true;
3838
39 const run_cmd = b.addRunArtifact(exe);39 const run_cmd = b.addRunArtifact(exe);
40 run_cmd.expectExitCode(@bitCast(u8, @as(i8, -2))); // should fail40 run_cmd.expectExitCode(@as(u8, @bitCast(@as(i8, -2)))); // should fail
41 test_step.dependOn(&run_cmd.step);41 test_step.dependOn(&run_cmd.step);
42 }42 }
43}43}
test/nvptx.zig+1-1
...@@ -60,7 +60,7 @@ pub fn addCases(ctx: *Cases) !void {...@@ -60,7 +60,7 @@ pub fn addCases(ctx: *Cases) !void {
60 \\60 \\
61 \\ var _sdata: [1024]f32 addrspace(.shared) = undefined;61 \\ var _sdata: [1024]f32 addrspace(.shared) = undefined;
62 \\ pub export fn reduceSum(d_x: []const f32, out: *f32) callconv(.Kernel) void {62 \\ pub export fn reduceSum(d_x: []const f32, out: *f32) callconv(.Kernel) void {
63 \\ var sdata = @addrSpaceCast(.generic, &_sdata);63 \\ var sdata: *addrspace(.generic) [1024]f32 = @addrSpaceCast(&_sdata);
64 \\ const tid: u32 = threadIdX();64 \\ const tid: u32 = threadIdX();
65 \\ var sum = d_x[tid];65 \\ var sum = d_x[tid];
66 \\ sdata[tid] = sum;66 \\ sdata[tid] = sum;
test/standalone/hello_world/hello_libc.zig+1-1
...@@ -10,6 +10,6 @@ const msg = "Hello, world!\n";...@@ -10,6 +10,6 @@ const msg = "Hello, world!\n";
10pub export fn main(argc: c_int, argv: **u8) c_int {10pub export fn main(argc: c_int, argv: **u8) c_int {
11 _ = argv;11 _ = argv;
12 _ = argc;12 _ = argc;
13 if (c.printf(msg) != @intCast(c_int, c.strlen(msg))) return -1;13 if (c.printf(msg) != @as(c_int, @intCast(c.strlen(msg)))) return -1;
14 return 0;14 return 0;
15}15}
test/standalone/issue_11595/main.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1extern fn check() c_int;1extern fn check() c_int;
22
3pub fn main() u8 {3pub fn main() u8 {
4 return @intCast(u8, check());4 return @as(u8, @intCast(check()));
5}5}
test/standalone/main_return_error/error_u8_non_zero.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const Err = error{Foo};1const Err = error{Foo};
22
3fn foo() u8 {3fn foo() u8 {
4 var x = @intCast(u8, 9);4 var x = @as(u8, @intCast(9));
5 return x;5 return x;
6}6}
77
test/standalone/mix_c_files/main.zig+1-1
...@@ -25,6 +25,6 @@ pub fn main() anyerror!void {...@@ -25,6 +25,6 @@ pub fn main() anyerror!void {
25 x = add_C(x);25 x = add_C(x);
26 x = add_C_zig(x);26 x = add_C_zig(x);
2727
28 const u = @intCast(u32, x);28 const u = @as(u32, @intCast(x));
29 try std.testing.expect(u / 100 == u % 100);29 try std.testing.expect(u / 100 == u % 100);
30}30}
test/standalone/pie/main.zig+1-1
...@@ -5,7 +5,7 @@ threadlocal var foo: u8 = 42;...@@ -5,7 +5,7 @@ threadlocal var foo: u8 = 42;
55
6test "Check ELF header" {6test "Check ELF header" {
7 // PIE executables are marked as ET_DYN, regular exes as ET_EXEC.7 // PIE executables are marked as ET_DYN, regular exes as ET_EXEC.
8 const header = @ptrFromInt(*elf.Ehdr, std.process.getBaseAddress());8 const header = @as(*elf.Ehdr, @ptrFromInt(std.process.getBaseAddress()));
9 try std.testing.expectEqual(elf.ET.DYN, header.e_type);9 try std.testing.expectEqual(elf.ET.DYN, header.e_type);
10}10}
1111
test/translate_c.zig+70-70
...@@ -351,7 +351,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -351,7 +351,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
351 \\}351 \\}
352 , &[_][]const u8{352 , &[_][]const u8{
353 \\pub export fn main() void {353 \\pub export fn main() void {
354 \\ var a: c_int = @bitCast(c_int, @truncate(c_uint, @alignOf(c_int)));354 \\ var a: c_int = @as(c_int, @bitCast(@as(c_uint, @truncate(@alignOf(c_int)))));
355 \\ _ = @TypeOf(a);355 \\ _ = @TypeOf(a);
356 \\}356 \\}
357 });357 });
...@@ -465,7 +465,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -465,7 +465,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
465 \\ pub fn y(self: anytype) @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int) {465 \\ pub fn y(self: anytype) @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int) {
466 \\ const Intermediate = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8);466 \\ const Intermediate = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8);
467 \\ const ReturnType = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int);467 \\ const ReturnType = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int);
468 \\ return @ptrCast(ReturnType, @alignCast(@alignOf(c_int), @ptrCast(Intermediate, self) + 4));468 \\ return @as(ReturnType, @ptrCast(@alignCast(@as(Intermediate, @ptrCast(self)) + 4)));
469 \\ }469 \\ }
470 \\};470 \\};
471 \\pub const struct_bar = extern struct {471 \\pub const struct_bar = extern struct {
...@@ -473,7 +473,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -473,7 +473,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
473 \\ pub fn y(self: anytype) @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int) {473 \\ pub fn y(self: anytype) @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int) {
474 \\ const Intermediate = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8);474 \\ const Intermediate = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8);
475 \\ const ReturnType = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int);475 \\ const ReturnType = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int);
476 \\ return @ptrCast(ReturnType, @alignCast(@alignOf(c_int), @ptrCast(Intermediate, self) + 4));476 \\ return @as(ReturnType, @ptrCast(@alignCast(@as(Intermediate, @ptrCast(self)) + 4)));
477 \\ }477 \\ }
478 \\};478 \\};
479 });479 });
...@@ -635,7 +635,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -635,7 +635,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
635 \\};635 \\};
636 \\pub export fn foo(arg_x: [*c]outer) void {636 \\pub export fn foo(arg_x: [*c]outer) void {
637 \\ var x = arg_x;637 \\ var x = arg_x;
638 \\ x.*.unnamed_0.unnamed_0.y = @bitCast(c_int, @as(c_uint, x.*.unnamed_0.x));638 \\ x.*.unnamed_0.unnamed_0.y = @as(c_int, @bitCast(@as(c_uint, x.*.unnamed_0.x)));
639 \\}639 \\}
640 });640 });
641641
...@@ -721,7 +721,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -721,7 +721,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
721 \\pub const struct_opaque_2 = opaque {};721 \\pub const struct_opaque_2 = opaque {};
722 \\pub export fn function(arg_opaque_1: ?*struct_opaque) void {722 \\pub export fn function(arg_opaque_1: ?*struct_opaque) void {
723 \\ var opaque_1 = arg_opaque_1;723 \\ var opaque_1 = arg_opaque_1;
724 \\ var cast: ?*struct_opaque_2 = @ptrCast(?*struct_opaque_2, opaque_1);724 \\ var cast: ?*struct_opaque_2 = @as(?*struct_opaque_2, @ptrCast(opaque_1));
725 \\ _ = @TypeOf(cast);725 \\ _ = @TypeOf(cast);
726 \\}726 \\}
727 });727 });
...@@ -799,7 +799,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -799,7 +799,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
799 \\ _ = @TypeOf(b);799 \\ _ = @TypeOf(b);
800 \\ const c: c_int = undefined;800 \\ const c: c_int = undefined;
801 \\ _ = @TypeOf(c);801 \\ _ = @TypeOf(c);
802 \\ const d: c_uint = @bitCast(c_uint, @as(c_int, 440));802 \\ const d: c_uint = @as(c_uint, @bitCast(@as(c_int, 440)));
803 \\ _ = @TypeOf(d);803 \\ _ = @TypeOf(d);
804 \\ var e: c_int = 10;804 \\ var e: c_int = 10;
805 \\ _ = @TypeOf(e);805 \\ _ = @TypeOf(e);
...@@ -904,8 +904,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -904,8 +904,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
904 , &[_][]const u8{904 , &[_][]const u8{
905 \\pub extern fn foo() void;905 \\pub extern fn foo() void;
906 \\pub export fn bar() void {906 \\pub export fn bar() void {
907 \\ var func_ptr: ?*anyopaque = @ptrCast(?*anyopaque, &foo);907 \\ var func_ptr: ?*anyopaque = @as(?*anyopaque, @ptrCast(&foo));
908 \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @ptrFromInt(?*const fn () callconv(.C) void, @intCast(c_ulong, @intFromPtr(func_ptr)));908 \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @as(?*const fn () callconv(.C) void, @ptrFromInt(@as(c_ulong, @intCast(@intFromPtr(func_ptr)))));
909 \\ _ = @TypeOf(typed_func_ptr);909 \\ _ = @TypeOf(typed_func_ptr);
910 \\}910 \\}
911 });911 });
...@@ -1353,7 +1353,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1353,7 +1353,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1353 , &[_][]const u8{1353 , &[_][]const u8{
1354 \\pub export fn foo() ?*anyopaque {1354 \\pub export fn foo() ?*anyopaque {
1355 \\ var x: [*c]c_ushort = undefined;1355 \\ var x: [*c]c_ushort = undefined;
1356 \\ return @ptrCast(?*anyopaque, x);1356 \\ return @as(?*anyopaque, @ptrCast(x));
1357 \\}1357 \\}
1358 });1358 });
13591359
...@@ -1543,7 +1543,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1543,7 +1543,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1543 , &[_][]const u8{1543 , &[_][]const u8{
1544 \\pub export fn ptrcast() [*c]f32 {1544 \\pub export fn ptrcast() [*c]f32 {
1545 \\ var a: [*c]c_int = undefined;1545 \\ var a: [*c]c_int = undefined;
1546 \\ return @ptrCast([*c]f32, @alignCast(@import("std").meta.alignment([*c]f32), a));1546 \\ return @as([*c]f32, @ptrCast(@alignCast(a)));
1547 \\}1547 \\}
1548 });1548 });
15491549
...@@ -1555,7 +1555,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1555,7 +1555,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1555 , &[_][]const u8{1555 , &[_][]const u8{
1556 \\pub export fn ptrptrcast() [*c][*c]f32 {1556 \\pub export fn ptrptrcast() [*c][*c]f32 {
1557 \\ var a: [*c][*c]c_int = undefined;1557 \\ var a: [*c][*c]c_int = undefined;
1558 \\ return @ptrCast([*c][*c]f32, @alignCast(@import("std").meta.alignment([*c][*c]f32), a));1558 \\ return @as([*c][*c]f32, @ptrCast(@alignCast(a)));
1559 \\}1559 \\}
1560 });1560 });
15611561
...@@ -1579,23 +1579,23 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1579,23 +1579,23 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1579 \\pub export fn test_ptr_cast() void {1579 \\pub export fn test_ptr_cast() void {
1580 \\ var p: ?*anyopaque = undefined;1580 \\ var p: ?*anyopaque = undefined;
1581 \\ {1581 \\ {
1582 \\ var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@import("std").meta.alignment([*c]u8), p));1582 \\ var to_char: [*c]u8 = @as([*c]u8, @ptrCast(@alignCast(p)));
1583 \\ _ = @TypeOf(to_char);1583 \\ _ = @TypeOf(to_char);
1584 \\ var to_short: [*c]c_short = @ptrCast([*c]c_short, @alignCast(@import("std").meta.alignment([*c]c_short), p));1584 \\ var to_short: [*c]c_short = @as([*c]c_short, @ptrCast(@alignCast(p)));
1585 \\ _ = @TypeOf(to_short);1585 \\ _ = @TypeOf(to_short);
1586 \\ var to_int: [*c]c_int = @ptrCast([*c]c_int, @alignCast(@import("std").meta.alignment([*c]c_int), p));1586 \\ var to_int: [*c]c_int = @as([*c]c_int, @ptrCast(@alignCast(p)));
1587 \\ _ = @TypeOf(to_int);1587 \\ _ = @TypeOf(to_int);
1588 \\ var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@import("std").meta.alignment([*c]c_longlong), p));1588 \\ var to_longlong: [*c]c_longlong = @as([*c]c_longlong, @ptrCast(@alignCast(p)));
1589 \\ _ = @TypeOf(to_longlong);1589 \\ _ = @TypeOf(to_longlong);
1590 \\ }1590 \\ }
1591 \\ {1591 \\ {
1592 \\ var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@import("std").meta.alignment([*c]u8), p));1592 \\ var to_char: [*c]u8 = @as([*c]u8, @ptrCast(@alignCast(p)));
1593 \\ _ = @TypeOf(to_char);1593 \\ _ = @TypeOf(to_char);
1594 \\ var to_short: [*c]c_short = @ptrCast([*c]c_short, @alignCast(@import("std").meta.alignment([*c]c_short), p));1594 \\ var to_short: [*c]c_short = @as([*c]c_short, @ptrCast(@alignCast(p)));
1595 \\ _ = @TypeOf(to_short);1595 \\ _ = @TypeOf(to_short);
1596 \\ var to_int: [*c]c_int = @ptrCast([*c]c_int, @alignCast(@import("std").meta.alignment([*c]c_int), p));1596 \\ var to_int: [*c]c_int = @as([*c]c_int, @ptrCast(@alignCast(p)));
1597 \\ _ = @TypeOf(to_int);1597 \\ _ = @TypeOf(to_int);
1598 \\ var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@import("std").meta.alignment([*c]c_longlong), p));1598 \\ var to_longlong: [*c]c_longlong = @as([*c]c_longlong, @ptrCast(@alignCast(p)));
1599 \\ _ = @TypeOf(to_longlong);1599 \\ _ = @TypeOf(to_longlong);
1600 \\ }1600 \\ }
1601 \\}1601 \\}
...@@ -1651,7 +1651,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1651,7 +1651,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1651 \\}1651 \\}
1652 , &[_][]const u8{1652 , &[_][]const u8{
1653 \\pub export fn foo() c_int {1653 \\pub export fn foo() c_int {
1654 \\ return (@as(c_int, 1) << @intCast(@import("std").math.Log2Int(c_int), 2)) >> @intCast(@import("std").math.Log2Int(c_int), 1);1654 \\ return (@as(c_int, 1) << @intCast(2)) >> @intCast(1);
1655 \\}1655 \\}
1656 });1656 });
16571657
...@@ -1885,7 +1885,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1885,7 +1885,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1885 \\const enum_unnamed_1 =1885 \\const enum_unnamed_1 =
1886 ++ " " ++ default_enum_type ++1886 ++ " " ++ default_enum_type ++
1887 \\;1887 \\;
1888 \\pub export var h: enum_unnamed_1 = @bitCast(c_uint, e);1888 \\pub export var h: enum_unnamed_1 = @as(c_uint, @bitCast(e));
1889 \\pub const i: c_int = 0;1889 \\pub const i: c_int = 0;
1890 \\pub const j: c_int = 1;1890 \\pub const j: c_int = 1;
1891 \\pub const k: c_int = 2;1891 \\pub const k: c_int = 2;
...@@ -2091,12 +2091,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2091,12 +2091,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2091 \\ _ = @TypeOf(c_1);2091 \\ _ = @TypeOf(c_1);
2092 \\ var a_2: c_int = undefined;2092 \\ var a_2: c_int = undefined;
2093 \\ var b_3: u8 = 123;2093 \\ var b_3: u8 = 123;
2094 \\ b_3 = @bitCast(u8, @truncate(i8, a_2));2094 \\ b_3 = @as(u8, @bitCast(@as(i8, @truncate(a_2))));
2095 \\ {2095 \\ {
2096 \\ var d: c_int = 5;2096 \\ var d: c_int = 5;
2097 \\ _ = @TypeOf(d);2097 \\ _ = @TypeOf(d);
2098 \\ }2098 \\ }
2099 \\ var d: c_uint = @bitCast(c_uint, @as(c_int, 440));2099 \\ var d: c_uint = @as(c_uint, @bitCast(@as(c_int, 440)));
2100 \\ _ = @TypeOf(d);2100 \\ _ = @TypeOf(d);
2101 \\}2101 \\}
2102 });2102 });
...@@ -2236,9 +2236,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2236,9 +2236,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2236 \\int c = 3.1415;2236 \\int c = 3.1415;
2237 \\double d = 3;2237 \\double d = 3;
2238 , &[_][]const u8{2238 , &[_][]const u8{
2239 \\pub export var a: f32 = @floatCast(f32, 3.1415);2239 \\pub export var a: f32 = @as(f32, @floatCast(3.1415));
2240 \\pub export var b: f64 = 3.1415;2240 \\pub export var b: f64 = 3.1415;
2241 \\pub export var c: c_int = @intFromFloat(c_int, 3.1415);2241 \\pub export var c: c_int = @as(c_int, @intFromFloat(3.1415));
2242 \\pub export var d: f64 = 3;2242 \\pub export var d: f64 = 3;
2243 });2243 });
22442244
...@@ -2423,7 +2423,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2423,7 +2423,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2423 , &[_][]const u8{2423 , &[_][]const u8{
2424 \\pub export fn int_from_float(arg_a: f32) c_int {2424 \\pub export fn int_from_float(arg_a: f32) c_int {
2425 \\ var a = arg_a;2425 \\ var a = arg_a;
2426 \\ return @intFromFloat(c_int, a);2426 \\ return @as(c_int, @intFromFloat(a));
2427 \\}2427 \\}
2428 });2428 });
24292429
...@@ -2533,15 +2533,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2533,15 +2533,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2533 \\ var a = arg_a;2533 \\ var a = arg_a;
2534 \\ var b = arg_b;2534 \\ var b = arg_b;
2535 \\ var c = arg_c;2535 \\ var c = arg_c;
2536 \\ var d: enum_Foo = @bitCast(c_uint, FooA);2536 \\ var d: enum_Foo = @as(c_uint, @bitCast(FooA));
2537 \\ var e: c_int = @intFromBool((a != 0) and (b != 0));2537 \\ var e: c_int = @intFromBool((a != 0) and (b != 0));
2538 \\ var f: c_int = @intFromBool((b != 0) and (c != null));2538 \\ var f: c_int = @intFromBool((b != 0) and (c != null));
2539 \\ var g: c_int = @intFromBool((a != 0) and (c != null));2539 \\ var g: c_int = @intFromBool((a != 0) and (c != null));
2540 \\ var h: c_int = @intFromBool((a != 0) or (b != 0));2540 \\ var h: c_int = @intFromBool((a != 0) or (b != 0));
2541 \\ var i: c_int = @intFromBool((b != 0) or (c != null));2541 \\ var i: c_int = @intFromBool((b != 0) or (c != null));
2542 \\ var j: c_int = @intFromBool((a != 0) or (c != null));2542 \\ var j: c_int = @intFromBool((a != 0) or (c != null));
2543 \\ var k: c_int = @intFromBool((a != 0) or (@bitCast(c_int, d) != 0));2543 \\ var k: c_int = @intFromBool((a != 0) or (@as(c_int, @bitCast(d)) != 0));
2544 \\ var l: c_int = @intFromBool((@bitCast(c_int, d) != 0) and (b != 0));2544 \\ var l: c_int = @intFromBool((@as(c_int, @bitCast(d)) != 0) and (b != 0));
2545 \\ var m: c_int = @intFromBool((c != null) or (d != 0));2545 \\ var m: c_int = @intFromBool((c != null) or (d != 0));
2546 \\ var td: SomeTypedef = 44;2546 \\ var td: SomeTypedef = 44;
2547 \\ var o: c_int = @intFromBool((td != 0) or (b != 0));2547 \\ var o: c_int = @intFromBool((td != 0) or (b != 0));
...@@ -2707,10 +2707,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2707,10 +2707,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2707 \\pub export var array: [100]c_int = [1]c_int{0} ** 100;2707 \\pub export var array: [100]c_int = [1]c_int{0} ** 100;
2708 \\pub export fn foo(arg_index: c_int) c_int {2708 \\pub export fn foo(arg_index: c_int) c_int {
2709 \\ var index = arg_index;2709 \\ var index = arg_index;
2710 \\ return array[@intCast(c_uint, index)];2710 \\ return array[@as(c_uint, @intCast(index))];
2711 \\}2711 \\}
2712 ,2712 ,
2713 \\pub const ACCESS = array[@intCast(usize, @as(c_int, 2))];2713 \\pub const ACCESS = array[@as(usize, @intCast(@as(c_int, 2)))];
2714 });2714 });
27152715
2716 cases.add("cast signed array index to unsigned",2716 cases.add("cast signed array index to unsigned",
...@@ -2722,7 +2722,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2722,7 +2722,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2722 \\pub export fn foo() void {2722 \\pub export fn foo() void {
2723 \\ var a: [10]c_int = undefined;2723 \\ var a: [10]c_int = undefined;
2724 \\ var i: c_int = 0;2724 \\ var i: c_int = 0;
2725 \\ a[@intCast(c_uint, i)] = 0;2725 \\ a[@as(c_uint, @intCast(i))] = 0;
2726 \\}2726 \\}
2727 });2727 });
27282728
...@@ -2735,7 +2735,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2735,7 +2735,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2735 \\pub export fn foo() void {2735 \\pub export fn foo() void {
2736 \\ var a: [10]c_longlong = undefined;2736 \\ var a: [10]c_longlong = undefined;
2737 \\ var i: c_longlong = 0;2737 \\ var i: c_longlong = 0;
2738 \\ a[@intCast(usize, i)] = 0;2738 \\ a[@as(usize, @intCast(i))] = 0;
2739 \\}2739 \\}
2740 });2740 });
27412741
...@@ -3006,8 +3006,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3006,8 +3006,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3006 \\pub export fn log2(arg_a: c_uint) c_int {3006 \\pub export fn log2(arg_a: c_uint) c_int {
3007 \\ var a = arg_a;3007 \\ var a = arg_a;
3008 \\ var i: c_int = 0;3008 \\ var i: c_int = 0;
3009 \\ while (a > @bitCast(c_uint, @as(c_int, 0))) {3009 \\ while (a > @as(c_uint, @bitCast(@as(c_int, 0)))) {
3010 \\ a >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));3010 \\ a >>= @intCast(@as(c_int, 1));
3011 \\ }3011 \\ }
3012 \\ return i;3012 \\ return i;
3013 \\}3013 \\}
...@@ -3026,8 +3026,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3026,8 +3026,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3026 \\pub export fn log2(arg_a: u32) c_int {3026 \\pub export fn log2(arg_a: u32) c_int {
3027 \\ var a = arg_a;3027 \\ var a = arg_a;
3028 \\ var i: c_int = 0;3028 \\ var i: c_int = 0;
3029 \\ while (a > @bitCast(u32, @as(c_int, 0))) {3029 \\ while (a > @as(u32, @bitCast(@as(c_int, 0)))) {
3030 \\ a >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));3030 \\ a >>= @intCast(@as(c_int, 1));
3031 \\ }3031 \\ }
3032 \\ return i;3032 \\ return i;
3033 \\}3033 \\}
...@@ -3084,14 +3084,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3084,14 +3084,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3084 \\ ref.* ^= @as(c_int, 1);3084 \\ ref.* ^= @as(c_int, 1);
3085 \\ break :blk ref.*;3085 \\ break :blk ref.*;
3086 \\ };3086 \\ };
3087 \\ a >>= @intCast(@import("std").math.Log2Int(c_int), blk: {3087 \\ a >>= @intCast(blk: {
3088 \\ const ref = &a;3088 \\ const ref = &a;
3089 \\ ref.* >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));3089 \\ ref.* >>= @intCast(@as(c_int, 1));
3090 \\ break :blk ref.*;3090 \\ break :blk ref.*;
3091 \\ });3091 \\ });
3092 \\ a <<= @intCast(@import("std").math.Log2Int(c_int), blk: {3092 \\ a <<= @intCast(blk: {
3093 \\ const ref = &a;3093 \\ const ref = &a;
3094 \\ ref.* <<= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));3094 \\ ref.* <<= @intCast(@as(c_int, 1));
3095 \\ break :blk ref.*;3095 \\ break :blk ref.*;
3096 \\ });3096 \\ });
3097 \\ a = @divTrunc(a, blk: {3097 \\ a = @divTrunc(a, blk: {
...@@ -3106,12 +3106,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3106,12 +3106,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3106 \\ });3106 \\ });
3107 \\ b /= blk: {3107 \\ b /= blk: {
3108 \\ const ref = &b;3108 \\ const ref = &b;
3109 \\ ref.* /= @bitCast(c_uint, @as(c_int, 1));3109 \\ ref.* /= @as(c_uint, @bitCast(@as(c_int, 1)));
3110 \\ break :blk ref.*;3110 \\ break :blk ref.*;
3111 \\ };3111 \\ };
3112 \\ b %= blk: {3112 \\ b %= blk: {
3113 \\ const ref = &b;3113 \\ const ref = &b;
3114 \\ ref.* %= @bitCast(c_uint, @as(c_int, 1));3114 \\ ref.* %= @as(c_uint, @bitCast(@as(c_int, 1)));
3115 \\ break :blk ref.*;3115 \\ break :blk ref.*;
3116 \\ };3116 \\ };
3117 \\}3117 \\}
...@@ -3134,42 +3134,42 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3134,42 +3134,42 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3134 \\ var a: c_uint = 0;3134 \\ var a: c_uint = 0;
3135 \\ a +%= blk: {3135 \\ a +%= blk: {
3136 \\ const ref = &a;3136 \\ const ref = &a;
3137 \\ ref.* +%= @bitCast(c_uint, @as(c_int, 1));3137 \\ ref.* +%= @as(c_uint, @bitCast(@as(c_int, 1)));
3138 \\ break :blk ref.*;3138 \\ break :blk ref.*;
3139 \\ };3139 \\ };
3140 \\ a -%= blk: {3140 \\ a -%= blk: {
3141 \\ const ref = &a;3141 \\ const ref = &a;
3142 \\ ref.* -%= @bitCast(c_uint, @as(c_int, 1));3142 \\ ref.* -%= @as(c_uint, @bitCast(@as(c_int, 1)));
3143 \\ break :blk ref.*;3143 \\ break :blk ref.*;
3144 \\ };3144 \\ };
3145 \\ a *%= blk: {3145 \\ a *%= blk: {
3146 \\ const ref = &a;3146 \\ const ref = &a;
3147 \\ ref.* *%= @bitCast(c_uint, @as(c_int, 1));3147 \\ ref.* *%= @as(c_uint, @bitCast(@as(c_int, 1)));
3148 \\ break :blk ref.*;3148 \\ break :blk ref.*;
3149 \\ };3149 \\ };
3150 \\ a &= blk: {3150 \\ a &= blk: {
3151 \\ const ref = &a;3151 \\ const ref = &a;
3152 \\ ref.* &= @bitCast(c_uint, @as(c_int, 1));3152 \\ ref.* &= @as(c_uint, @bitCast(@as(c_int, 1)));
3153 \\ break :blk ref.*;3153 \\ break :blk ref.*;
3154 \\ };3154 \\ };
3155 \\ a |= blk: {3155 \\ a |= blk: {
3156 \\ const ref = &a;3156 \\ const ref = &a;
3157 \\ ref.* |= @bitCast(c_uint, @as(c_int, 1));3157 \\ ref.* |= @as(c_uint, @bitCast(@as(c_int, 1)));
3158 \\ break :blk ref.*;3158 \\ break :blk ref.*;
3159 \\ };3159 \\ };
3160 \\ a ^= blk: {3160 \\ a ^= blk: {
3161 \\ const ref = &a;3161 \\ const ref = &a;
3162 \\ ref.* ^= @bitCast(c_uint, @as(c_int, 1));3162 \\ ref.* ^= @as(c_uint, @bitCast(@as(c_int, 1)));
3163 \\ break :blk ref.*;3163 \\ break :blk ref.*;
3164 \\ };3164 \\ };
3165 \\ a >>= @intCast(@import("std").math.Log2Int(c_uint), blk: {3165 \\ a >>= @intCast(blk: {
3166 \\ const ref = &a;3166 \\ const ref = &a;
3167 \\ ref.* >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));3167 \\ ref.* >>= @intCast(@as(c_int, 1));
3168 \\ break :blk ref.*;3168 \\ break :blk ref.*;
3169 \\ });3169 \\ });
3170 \\ a <<= @intCast(@import("std").math.Log2Int(c_uint), blk: {3170 \\ a <<= @intCast(blk: {
3171 \\ const ref = &a;3171 \\ const ref = &a;
3172 \\ ref.* <<= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));3172 \\ ref.* <<= @intCast(@as(c_int, 1));
3173 \\ break :blk ref.*;3173 \\ break :blk ref.*;
3174 \\ });3174 \\ });
3175 \\}3175 \\}
...@@ -3258,21 +3258,21 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3258,21 +3258,21 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3258 \\pub extern fn fn_bool(x: bool) void;3258 \\pub extern fn fn_bool(x: bool) void;
3259 \\pub extern fn fn_ptr(x: ?*anyopaque) void;3259 \\pub extern fn fn_ptr(x: ?*anyopaque) void;
3260 \\pub export fn call() void {3260 \\pub export fn call() void {
3261 \\ fn_int(@intFromFloat(c_int, 3.0));3261 \\ fn_int(@as(c_int, @intFromFloat(3.0)));
3262 \\ fn_int(@intFromFloat(c_int, 3.0));3262 \\ fn_int(@as(c_int, @intFromFloat(3.0)));
3263 \\ fn_int(@as(c_int, 1094861636));3263 \\ fn_int(@as(c_int, 1094861636));
3264 \\ fn_f32(@floatFromInt(f32, @as(c_int, 3)));3264 \\ fn_f32(@as(f32, @floatFromInt(@as(c_int, 3))));
3265 \\ fn_f64(@floatFromInt(f64, @as(c_int, 3)));3265 \\ fn_f64(@as(f64, @floatFromInt(@as(c_int, 3))));
3266 \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '3'))));3266 \\ fn_char(@as(u8, @bitCast(@as(i8, @truncate(@as(c_int, '3'))))));
3267 \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '\x01'))));3267 \\ fn_char(@as(u8, @bitCast(@as(i8, @truncate(@as(c_int, '\x01'))))));
3268 \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, 0))));3268 \\ fn_char(@as(u8, @bitCast(@as(i8, @truncate(@as(c_int, 0))))));
3269 \\ fn_f32(3.0);3269 \\ fn_f32(3.0);
3270 \\ fn_f64(3.0);3270 \\ fn_f64(3.0);
3271 \\ fn_bool(@as(c_int, 123) != 0);3271 \\ fn_bool(@as(c_int, 123) != 0);
3272 \\ fn_bool(@as(c_int, 0) != 0);3272 \\ fn_bool(@as(c_int, 0) != 0);
3273 \\ fn_bool(@intFromPtr(&fn_int) != 0);3273 \\ fn_bool(@intFromPtr(&fn_int) != 0);
3274 \\ fn_int(@intCast(c_int, @intFromPtr(&fn_int)));3274 \\ fn_int(@as(c_int, @intCast(@intFromPtr(&fn_int))));
3275 \\ fn_ptr(@ptrFromInt(?*anyopaque, @as(c_int, 42)));3275 \\ fn_ptr(@as(?*anyopaque, @ptrFromInt(@as(c_int, 42))));
3276 \\}3276 \\}
3277 });3277 });
32783278
...@@ -3411,11 +3411,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3411,11 +3411,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3411 \\}3411 \\}
3412 , &[_][]const u8{3412 , &[_][]const u8{
3413 \\pub export fn foo() c_ulong {3413 \\pub export fn foo() c_ulong {
3414 \\ return @bitCast(c_ulong, @as(c_long, -@as(c_int, 1)));3414 \\ return @as(c_ulong, @bitCast(@as(c_long, -@as(c_int, 1))));
3415 \\}3415 \\}
3416 \\pub export fn bar(arg_x: c_long) c_ushort {3416 \\pub export fn bar(arg_x: c_long) c_ushort {
3417 \\ var x = arg_x;3417 \\ var x = arg_x;
3418 \\ return @bitCast(c_ushort, @truncate(c_short, x));3418 \\ return @as(c_ushort, @bitCast(@as(c_short, @truncate(x))));
3419 \\}3419 \\}
3420 });3420 });
34213421
...@@ -3473,11 +3473,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3473,11 +3473,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3473 \\}3473 \\}
3474 \\pub export fn bar(arg_a: [*c]const c_int) void {3474 \\pub export fn bar(arg_a: [*c]const c_int) void {
3475 \\ var a = arg_a;3475 \\ var a = arg_a;
3476 \\ foo(@ptrFromInt([*c]c_int, @intFromPtr(a)));3476 \\ foo(@as([*c]c_int, @ptrFromInt(@intFromPtr(a))));
3477 \\}3477 \\}
3478 \\pub export fn baz(arg_a: [*c]volatile c_int) void {3478 \\pub export fn baz(arg_a: [*c]volatile c_int) void {
3479 \\ var a = arg_a;3479 \\ var a = arg_a;
3480 \\ foo(@ptrFromInt([*c]c_int, @intFromPtr(a)));3480 \\ foo(@as([*c]c_int, @ptrFromInt(@intFromPtr(a))));
3481 \\}3481 \\}
3482 });3482 });
34833483
...@@ -3860,9 +3860,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3860,9 +3860,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3860 \\ p[1];3860 \\ p[1];
3861 \\}3861 \\}
3862 , &[_][]const u8{3862 , &[_][]const u8{
3863 \\_ = p[@intCast(c_uint, @as(c_int, 0))];3863 \\_ = p[@as(c_uint, @intCast(@as(c_int, 0)))];
3864 ,3864 ,
3865 \\_ = p[@intCast(c_uint, @as(c_int, 1))];3865 \\_ = p[@as(c_uint, @intCast(@as(c_int, 1)))];
3866 });3866 });
38673867
3868 cases.add("Undefined macro identifier",3868 cases.add("Undefined macro identifier",
...@@ -3928,7 +3928,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3928,7 +3928,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3928 \\pub export fn foo() void {3928 \\pub export fn foo() void {
3929 \\ var a: S = undefined;3929 \\ var a: S = undefined;
3930 \\ var b: S = undefined;3930 \\ var b: S = undefined;
3931 \\ var c: c_longlong = @divExact(@bitCast(c_longlong, @intFromPtr(a) -% @intFromPtr(b)), @sizeOf(u8));3931 \\ var c: c_longlong = @divExact(@as(c_longlong, @bitCast(@intFromPtr(a) -% @intFromPtr(b))), @sizeOf(u8));
3932 \\ _ = @TypeOf(c);3932 \\ _ = @TypeOf(c);
3933 \\}3933 \\}
3934 });3934 });
...@@ -3943,7 +3943,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3943,7 +3943,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3943 \\pub export fn foo() void {3943 \\pub export fn foo() void {
3944 \\ var a: S = undefined;3944 \\ var a: S = undefined;
3945 \\ var b: S = undefined;3945 \\ var b: S = undefined;
3946 \\ var c: c_long = @divExact(@bitCast(c_long, @intFromPtr(a) -% @intFromPtr(b)), @sizeOf(u8));3946 \\ var c: c_long = @divExact(@as(c_long, @bitCast(@intFromPtr(a) -% @intFromPtr(b))), @sizeOf(u8));
3947 \\ _ = @TypeOf(c);3947 \\ _ = @TypeOf(c);
3948 \\}3948 \\}
3949 });3949 });
tools/extract-grammar.zig+1-1
...@@ -90,7 +90,7 @@ fn read(path: []const u8, allocator: mem.Allocator) ![:0]const u8 {...@@ -90,7 +90,7 @@ fn read(path: []const u8, allocator: mem.Allocator) ![:0]const u8 {
90 const st = try f.stat();90 const st = try f.stat();
91 if (st.size > max_src_size) return error.FileTooBig;91 if (st.size > max_src_size) return error.FileTooBig;
9292
93 const src = try allocator.allocSentinel(u8, @intCast(usize, st.size), 0);93 const src = try allocator.allocSentinel(u8, @as(usize, @intCast(st.size)), 0);
94 const n = try f.readAll(src);94 const n = try f.readAll(src);
95 if (n != st.size) return error.UnexpectedEndOfFile;95 if (n != st.size) return error.UnexpectedEndOfFile;
9696
tools/gen_spirv_spec.zig+1-1
...@@ -40,7 +40,7 @@ fn extendedStructs(...@@ -40,7 +40,7 @@ fn extendedStructs(
40 kinds: []const g.OperandKind,40 kinds: []const g.OperandKind,
41) !ExtendedStructSet {41) !ExtendedStructSet {
42 var map = ExtendedStructSet.init(arena);42 var map = ExtendedStructSet.init(arena);
43 try map.ensureTotalCapacity(@intCast(u32, kinds.len));43 try map.ensureTotalCapacity(@as(u32, @intCast(kinds.len)));
4444
45 for (kinds) |kind| {45 for (kinds) |kind| {
46 const enumerants = kind.enumerants orelse continue;46 const enumerants = kind.enumerants orelse continue;
tools/gen_stubs.zig+5-5
...@@ -441,10 +441,10 @@ fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: builtin.Endian)...@@ -441,10 +441,10 @@ fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: builtin.Endian)
441 const sh_name = try arena.dupe(u8, mem.sliceTo(shstrtab[s(shdr.sh_name)..], 0));441 const sh_name = try arena.dupe(u8, mem.sliceTo(shstrtab[s(shdr.sh_name)..], 0));
442 log.debug("found section: {s}", .{sh_name});442 log.debug("found section: {s}", .{sh_name});
443 if (mem.eql(u8, sh_name, ".dynsym")) {443 if (mem.eql(u8, sh_name, ".dynsym")) {
444 dynsym_index = @intCast(u16, i);444 dynsym_index = @as(u16, @intCast(i));
445 }445 }
446 const gop = try parse.sections.getOrPut(sh_name);446 const gop = try parse.sections.getOrPut(sh_name);
447 section_index_map[i] = @intCast(u16, gop.index);447 section_index_map[i] = @as(u16, @intCast(gop.index));
448 }448 }
449 if (dynsym_index == 0) @panic("did not find the .dynsym section");449 if (dynsym_index == 0) @panic("did not find the .dynsym section");
450450
...@@ -470,9 +470,9 @@ fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: builtin.Endian)...@@ -470,9 +470,9 @@ fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: builtin.Endian)
470 for (copied_dyn_syms) |sym| {470 for (copied_dyn_syms) |sym| {
471 const this_section = s(sym.st_shndx);471 const this_section = s(sym.st_shndx);
472 const name = try arena.dupe(u8, mem.sliceTo(dynstr[s(sym.st_name)..], 0));472 const name = try arena.dupe(u8, mem.sliceTo(dynstr[s(sym.st_name)..], 0));
473 const ty = @truncate(u4, sym.st_info);473 const ty = @as(u4, @truncate(sym.st_info));
474 const binding = @truncate(u4, sym.st_info >> 4);474 const binding = @as(u4, @truncate(sym.st_info >> 4));
475 const visib = @enumFromInt(elf.STV, @truncate(u2, sym.st_other));475 const visib = @as(elf.STV, @enumFromInt(@as(u2, @truncate(sym.st_other))));
476 const size = s(sym.st_size);476 const size = s(sym.st_size);
477477
478 if (parse.blacklist.contains(name)) continue;478 if (parse.blacklist.contains(name)) continue;
tools/update-linux-headers.zig+1-1
...@@ -112,7 +112,7 @@ const DestTarget = struct {...@@ -112,7 +112,7 @@ const DestTarget = struct {
112 _ = self;112 _ = self;
113 var hasher = std.hash.Wyhash.init(0);113 var hasher = std.hash.Wyhash.init(0);
114 std.hash.autoHash(&hasher, a.arch);114 std.hash.autoHash(&hasher, a.arch);
115 return @truncate(u32, hasher.final());115 return @as(u32, @truncate(hasher.final()));
116 }116 }
117117
118 pub fn eql(self: @This(), a: DestTarget, b: DestTarget, b_index: usize) bool {118 pub fn eql(self: @This(), a: DestTarget, b: DestTarget, b_index: usize) bool {
tools/update_clang_options.zig+2-2
...@@ -591,7 +591,7 @@ pub fn main() anyerror!void {...@@ -591,7 +591,7 @@ pub fn main() anyerror!void {
591591
592 for (all_features, 0..) |feat, i| {592 for (all_features, 0..) |feat, i| {
593 const llvm_name = feat.llvm_name orelse continue;593 const llvm_name = feat.llvm_name orelse continue;
594 const zig_feat = @enumFromInt(Feature, i);594 const zig_feat = @as(Feature, @enumFromInt(i));
595 const zig_name = @tagName(zig_feat);595 const zig_name = @tagName(zig_feat);
596 try llvm_to_zig_cpu_features.put(llvm_name, zig_name);596 try llvm_to_zig_cpu_features.put(llvm_name, zig_name);
597 }597 }
...@@ -790,7 +790,7 @@ const Syntax = union(enum) {...@@ -790,7 +790,7 @@ const Syntax = union(enum) {
790};790};
791791
792fn objSyntax(obj: *json.ObjectMap) ?Syntax {792fn objSyntax(obj: *json.ObjectMap) ?Syntax {
793 const num_args = @intCast(u8, obj.get("NumArgs").?.integer);793 const num_args = @as(u8, @intCast(obj.get("NumArgs").?.integer));
794 for (obj.get("!superclasses").?.array.items) |superclass_json| {794 for (obj.get("!superclasses").?.array.items) |superclass_json| {
795 const superclass = superclass_json.string;795 const superclass = superclass_json.string;
796 if (std.mem.eql(u8, superclass, "Joined")) {796 if (std.mem.eql(u8, superclass, "Joined")) {