authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-24 16:58:19-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-06-24 16:58:19-07:00
log146b79af153bbd5dafda0ba12a040385c7fc58f8
tree67e3db8b444d65c667e314770fc983a7fc8ba293
parent13853bef0df3c90633021850cc6d6abaeea03282
parent21ac0beb436f49fe49c6982a872f2dc48e4bea5e
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #16163 from mlugg/feat/builtins-infer-dest-ty

Infer destination type of cast builtins using result type

654 files changed, 9915 insertions(+), 9611 deletions(-)

doc/langref.html.in+65-59
......@@ -2410,7 +2410,7 @@ var some_integers: [100]i32 = undefined;
24102410
24112411test "modify an array" {
24122412 for (&some_integers, 0..) |*item, i| {
2413 item.* = @intCast(i32, i);
2413 item.* = @intCast(i);
24142414 }
24152415 try expect(some_integers[10] == 10);
24162416 try expect(some_integers[99] == 99);
......@@ -2452,8 +2452,8 @@ var fancy_array = init: {
24522452 var initial_value: [10]Point = undefined;
24532453 for (&initial_value, 0..) |*pt, i| {
24542454 pt.* = Point{
2455 .x = @intCast(i32, i),
2456 .y = @intCast(i32, i) * 2,
2455 .x = @intCast(i),
2456 .y = @intCast(i * 2),
24572457 };
24582458 }
24592459 break :init initial_value;
......@@ -2769,7 +2769,7 @@ test "comptime pointers" {
27692769const expect = @import("std").testing.expect;
27702770
27712771test "@intFromPtr and @ptrFromInt" {
2772 const ptr = @ptrFromInt(*i32, 0xdeadbee0);
2772 const ptr: *i32 = @ptrFromInt(0xdeadbee0);
27732773 const addr = @intFromPtr(ptr);
27742774 try expect(@TypeOf(addr) == usize);
27752775 try expect(addr == 0xdeadbee0);
......@@ -2784,7 +2784,7 @@ test "comptime @ptrFromInt" {
27842784 comptime {
27852785 // Zig is able to do this at compile-time, as long as
27862786 // ptr is never dereferenced.
2787 const ptr = @ptrFromInt(*i32, 0xdeadbee0);
2787 const ptr: *i32 = @ptrFromInt(0xdeadbee0);
27882788 const addr = @intFromPtr(ptr);
27892789 try expect(@TypeOf(addr) == usize);
27902790 try expect(addr == 0xdeadbee0);
......@@ -2801,7 +2801,7 @@ test "comptime @ptrFromInt" {
28012801const expect = @import("std").testing.expect;
28022802
28032803test "volatile" {
2804 const mmio_ptr = @ptrFromInt(*volatile u8, 0x12345678);
2804 const mmio_ptr: *volatile u8 = @ptrFromInt(0x12345678);
28052805 try expect(@TypeOf(mmio_ptr) == *volatile u8);
28062806}
28072807 {#code_end#}
......@@ -2822,7 +2822,7 @@ const expect = std.testing.expect;
28222822
28232823test "pointer casting" {
28242824 const bytes align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12 };
2825 const u32_ptr = @ptrCast(*const u32, &bytes);
2825 const u32_ptr: *const u32 = @ptrCast(&bytes);
28262826 try expect(u32_ptr.* == 0x12121212);
28272827
28282828 // Even this example is contrived - there are better ways to do the above than
......@@ -2831,7 +2831,7 @@ test "pointer casting" {
28312831 try expect(u32_value == 0x12121212);
28322832
28332833 // And even another way, the most straightforward way to do it:
2834 try expect(@bitCast(u32, bytes) == 0x12121212);
2834 try expect(@as(u32, @bitCast(bytes)) == 0x12121212);
28352835}
28362836
28372837test "pointer child type" {
......@@ -2921,7 +2921,7 @@ test "pointer alignment safety" {
29212921}
29222922fn foo(bytes: []u8) u32 {
29232923 const slice4 = bytes[1..5];
2924 const int_slice = std.mem.bytesAsSlice(u32, @alignCast(4, slice4));
2924 const int_slice = std.mem.bytesAsSlice(u32, @as([]align(4) u8, @alignCast(slice4)));
29252925 return int_slice[0];
29262926}
29272927 {#code_end#}
......@@ -2942,7 +2942,7 @@ const expect = std.testing.expect;
29422942
29432943test "allowzero" {
29442944 var zero: usize = 0;
2945 var ptr = @ptrFromInt(*allowzero i32, zero);
2945 var ptr: *allowzero i32 = @ptrFromInt(zero);
29462946 try expect(@intFromPtr(ptr) == 0);
29472947}
29482948 {#code_end#}
......@@ -3354,12 +3354,12 @@ fn doTheTest() !void {
33543354 try expect(@sizeOf(Full) == 2);
33553355 try expect(@sizeOf(Divided) == 2);
33563356 var full = Full{ .number = 0x1234 };
3357 var divided = @bitCast(Divided, full);
3357 var divided: Divided = @bitCast(full);
33583358 try expect(divided.half1 == 0x34);
33593359 try expect(divided.quarter3 == 0x2);
33603360 try expect(divided.quarter4 == 0x1);
33613361
3362 var ordered = @bitCast([2]u8, full);
3362 var ordered: [2]u8 = @bitCast(full);
33633363 switch (native_endian) {
33643364 .Big => {
33653365 try expect(ordered[0] == 0x12);
......@@ -4428,7 +4428,7 @@ fn getNum(u: U) u32 {
44284428 // `u.a` or `u.b` and `tag` is `u`'s comptime-known tag value.
44294429 inline else => |num, tag| {
44304430 if (tag == .b) {
4431 return @intFromFloat(u32, num);
4431 return @intFromFloat(num);
44324432 }
44334433 return num;
44344434 }
......@@ -4714,7 +4714,7 @@ test "for basics" {
47144714 var sum2: i32 = 0;
47154715 for (items, 0..) |_, i| {
47164716 try expect(@TypeOf(i) == usize);
4717 sum2 += @intCast(i32, i);
4717 sum2 += @as(i32, @intCast(i));
47184718 }
47194719 try expect(sum2 == 10);
47204720
......@@ -6363,7 +6363,7 @@ const mem = std.mem;
63636363test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
63646364 const window_name = [1][*]const u8{"window name"};
63656365 const x: [*]const ?[*]const u8 = &window_name;
6366 try expect(mem.eql(u8, std.mem.sliceTo(@ptrCast([*:0]const u8, x[0].?), 0), "window name"));
6366 try expect(mem.eql(u8, std.mem.sliceTo(@as([*:0]const u8, @ptrCast(x[0].?)), 0), "window name"));
63676367}
63686368 {#code_end#}
63696369 {#header_close#}
......@@ -6760,8 +6760,8 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
67606760}
67616761
67626762test "peer type resolution: *const T and ?*T" {
6763 const a = @ptrFromInt(*const usize, 0x123456780);
6764 const b = @ptrFromInt(?*usize, 0x123456780);
6763 const a: *const usize = @ptrFromInt(0x123456780);
6764 const b: ?*usize = @ptrFromInt(0x123456780);
67656765 try expect(a == b);
67666766 try expect(b == a);
67676767}
......@@ -7762,12 +7762,13 @@ test "global assembly" {
77627762 at compile time.
77637763 </p>
77647764 {#header_open|@addrSpaceCast#}
7765 <pre>{#syntax#}@addrSpaceCast(comptime addrspace: std.builtin.AddressSpace, ptr: anytype) anytype{#endsyntax#}</pre>
7765 <pre>{#syntax#}@addrSpaceCast(ptr: anytype) anytype{#endsyntax#}</pre>
77667766 <p>
7767 Converts a pointer from one address space to another. Depending on the current target and
7768 address spaces, this cast may be a no-op, a complex operation, or illegal. If the cast is
7769 legal, then the resulting pointer points to the same memory location as the pointer operand.
7770 It is always valid to cast a pointer between the same address spaces.
7767 Converts a pointer from one address space to another. The new address space is inferred
7768 based on the result type. Depending on the current target and address spaces, this cast
7769 may be a no-op, a complex operation, or illegal. If the cast is legal, then the resulting
7770 pointer points to the same memory location as the pointer operand. It is always valid to
7771 cast a pointer between the same address spaces.
77717772 </p>
77727773 {#header_close#}
77737774 {#header_open|@addWithOverflow#}
......@@ -7777,10 +7778,10 @@ test "global assembly" {
77777778 </p>
77787779 {#header_close#}
77797780 {#header_open|@alignCast#}
7780 <pre>{#syntax#}@alignCast(comptime alignment: u29, ptr: anytype) anytype{#endsyntax#}</pre>
7781 <pre>{#syntax#}@alignCast(ptr: anytype) anytype{#endsyntax#}</pre>
77817782 <p>
77827783 {#syntax#}ptr{#endsyntax#} can be {#syntax#}*T{#endsyntax#}, {#syntax#}?*T{#endsyntax#}, or {#syntax#}[]T{#endsyntax#}.
7783 It returns the same type as {#syntax#}ptr{#endsyntax#} except with the alignment adjusted to the new value.
7784 Changes the alignment of a pointer. The alignment to use is inferred based on the result type.
77847785 </p>
77857786 <p>A {#link|pointer alignment safety check|Incorrect Pointer Alignment#} is added
77867787 to the generated code to make sure the pointer is aligned as promised.</p>
......@@ -7865,9 +7866,10 @@ comptime {
78657866 {#header_close#}
78667867
78677868 {#header_open|@bitCast#}
7868 <pre>{#syntax#}@bitCast(comptime DestType: type, value: anytype) DestType{#endsyntax#}</pre>
7869 <pre>{#syntax#}@bitCast(value: anytype) anytype{#endsyntax#}</pre>
78697870 <p>
7870 Converts a value of one type to another type.
7871 Converts a value of one type to another type. The return type is the
7872 inferred result type.
78717873 </p>
78727874 <p>
78737875 Asserts that {#syntax#}@sizeOf(@TypeOf(value)) == @sizeOf(DestType){#endsyntax#}.
......@@ -8420,10 +8422,11 @@ test "main" {
84208422 {#header_close#}
84218423
84228424 {#header_open|@errSetCast#}
8423 <pre>{#syntax#}@errSetCast(comptime T: DestType, value: anytype) DestType{#endsyntax#}</pre>
8425 <pre>{#syntax#}@errSetCast(value: anytype) anytype{#endsyntax#}</pre>
84248426 <p>
8425 Converts an error value from one error set to another error set. Attempting to convert an error
8426 which is not in the destination error set results in safety-protected {#link|Undefined Behavior#}.
8427 Converts an error value from one error set to another error set. The return type is the
8428 inferred result type. Attempting to convert an error which is not in the destination error
8429 set results in safety-protected {#link|Undefined Behavior#}.
84278430 </p>
84288431 {#header_close#}
84298432
......@@ -8535,17 +8538,17 @@ test "decl access by string" {
85358538 {#header_close#}
85368539
85378540 {#header_open|@floatCast#}
8538 <pre>{#syntax#}@floatCast(comptime DestType: type, value: anytype) DestType{#endsyntax#}</pre>
8541 <pre>{#syntax#}@floatCast(value: anytype) anytype{#endsyntax#}</pre>
85398542 <p>
85408543 Convert from one float type to another. This cast is safe, but may cause the
8541 numeric value to lose precision.
8544 numeric value to lose precision. The return type is the inferred result type.
85428545 </p>
85438546 {#header_close#}
85448547
85458548 {#header_open|@intFromFloat#}
8546 <pre>{#syntax#}@intFromFloat(comptime DestType: type, float: anytype) DestType{#endsyntax#}</pre>
8549 <pre>{#syntax#}@intFromFloat(float: anytype) anytype{#endsyntax#}</pre>
85478550 <p>
8548 Converts the integer part of a floating point number to the destination type.
8551 Converts the integer part of a floating point number to the inferred result type.
85498552 </p>
85508553 <p>
85518554 If the integer part of the floating point number cannot fit in the destination type,
......@@ -8660,16 +8663,17 @@ test "@hasDecl" {
86608663 {#header_close#}
86618664
86628665 {#header_open|@intCast#}
8663 <pre>{#syntax#}@intCast(comptime DestType: type, int: anytype) DestType{#endsyntax#}</pre>
8666 <pre>{#syntax#}@intCast(int: anytype) anytype{#endsyntax#}</pre>
86648667 <p>
86658668 Converts an integer to another integer while keeping the same numerical value.
8669 The return type is the inferred result type.
86668670 Attempting to convert a number which is out of range of the destination type results in
86678671 safety-protected {#link|Undefined Behavior#}.
86688672 </p>
86698673 {#code_begin|test_err|test_intCast_builtin|cast truncated bits#}
86708674test "integer cast panic" {
86718675 var a: u16 = 0xabcd;
8672 var b: u8 = @intCast(u8, a);
8676 var b: u8 = @intCast(a);
86738677 _ = b;
86748678}
86758679 {#code_end#}
......@@ -8683,9 +8687,9 @@ test "integer cast panic" {
86838687 {#header_close#}
86848688
86858689 {#header_open|@enumFromInt#}
8686 <pre>{#syntax#}@enumFromInt(comptime DestType: type, integer: anytype) DestType{#endsyntax#}</pre>
8690 <pre>{#syntax#}@enumFromInt(integer: anytype) anytype{#endsyntax#}</pre>
86878691 <p>
8688 Converts an integer into an {#link|enum#} value.
8692 Converts an integer into an {#link|enum#} value. The return type is the inferred result type.
86898693 </p>
86908694 <p>
86918695 Attempting to convert an integer which represents no value in the chosen enum type invokes
......@@ -8711,16 +8715,18 @@ test "integer cast panic" {
87118715 {#header_close#}
87128716
87138717 {#header_open|@floatFromInt#}
8714 <pre>{#syntax#}@floatFromInt(comptime DestType: type, int: anytype) DestType{#endsyntax#}</pre>
8718 <pre>{#syntax#}@floatFromInt(int: anytype) anytype{#endsyntax#}</pre>
87158719 <p>
8716 Converts an integer to the closest floating point representation. To convert the other way, use {#link|@intFromFloat#}. This cast is always safe.
8720 Converts an integer to the closest floating point representation. The return type is the inferred result type.
8721 To convert the other way, use {#link|@intFromFloat#}. This cast is always safe.
87178722 </p>
87188723 {#header_close#}
87198724
87208725 {#header_open|@ptrFromInt#}
8721 <pre>{#syntax#}@ptrFromInt(comptime DestType: type, address: usize) DestType{#endsyntax#}</pre>
8726 <pre>{#syntax#}@ptrFromInt(address: usize) anytype{#endsyntax#}</pre>
87228727 <p>
8723 Converts an integer to a {#link|pointer|Pointers#}. To convert the other way, use {#link|@intFromPtr#}. Casting an address of 0 to a destination type
8728 Converts an integer to a {#link|pointer|Pointers#}. The return type is the inferred result type.
8729 To convert the other way, use {#link|@intFromPtr#}. Casting an address of 0 to a destination type
87248730 which in not {#link|optional|Optional Pointers#} and does not have the {#syntax#}allowzero{#endsyntax#} attribute will result in a
87258731 {#link|Pointer Cast Invalid Null#} panic when runtime safety checks are enabled.
87268732 </p>
......@@ -8924,9 +8930,9 @@ pub const PrefetchOptions = struct {
89248930 {#header_close#}
89258931
89268932 {#header_open|@ptrCast#}
8927 <pre>{#syntax#}@ptrCast(comptime DestType: type, value: anytype) DestType{#endsyntax#}</pre>
8933 <pre>{#syntax#}@ptrCast(value: anytype) anytype{#endsyntax#}</pre>
89288934 <p>
8929 Converts a pointer of one type to a pointer of another type.
8935 Converts a pointer of one type to a pointer of another type. The return type is the inferred result type.
89308936 </p>
89318937 <p>
89328938 {#link|Optional Pointers#} are allowed. Casting an optional pointer which is {#link|null#}
......@@ -9522,10 +9528,10 @@ fn List(comptime T: type) type {
95229528 {#header_close#}
95239529
95249530 {#header_open|@truncate#}
9525 <pre>{#syntax#}@truncate(comptime T: type, integer: anytype) T{#endsyntax#}</pre>
9531 <pre>{#syntax#}@truncate(integer: anytype) anytype{#endsyntax#}</pre>
95269532 <p>
95279533 This function truncates bits from an integer type, resulting in a smaller
9528 or same-sized integer type.
9534 or same-sized integer type. The return type is the inferred result type.
95299535 </p>
95309536 <p>
95319537 This function always truncates the significant bits of the integer, regardless
......@@ -9540,7 +9546,7 @@ const expect = std.testing.expect;
95409546
95419547test "integer truncation" {
95429548 var a: u16 = 0xabcd;
9543 var b: u8 = @truncate(u8, a);
9549 var b: u8 = @truncate(a);
95449550 try expect(b == 0xcd);
95459551}
95469552 {#code_end#}
......@@ -9838,7 +9844,7 @@ fn foo(x: []const u8) u8 {
98389844 {#code_begin|test_err|test_comptime_invalid_cast|type 'u32' cannot represent integer value '-1'#}
98399845comptime {
98409846 var value: i32 = -1;
9841 const unsigned = @intCast(u32, value);
9847 const unsigned: u32 = @intCast(value);
98429848 _ = unsigned;
98439849}
98449850 {#code_end#}
......@@ -9848,7 +9854,7 @@ const std = @import("std");
98489854
98499855pub fn main() void {
98509856 var value: i32 = -1;
9851 var unsigned = @intCast(u32, value);
9857 var unsigned: u32 = @intCast(value);
98529858 std.debug.print("value: {}\n", .{unsigned});
98539859}
98549860 {#code_end#}
......@@ -9861,7 +9867,7 @@ pub fn main() void {
98619867 {#code_begin|test_err|test_comptime_invalid_cast_truncate|type 'u8' cannot represent integer value '300'#}
98629868comptime {
98639869 const spartan_count: u16 = 300;
9864 const byte = @intCast(u8, spartan_count);
9870 const byte: u8 = @intCast(spartan_count);
98659871 _ = byte;
98669872}
98679873 {#code_end#}
......@@ -9871,7 +9877,7 @@ const std = @import("std");
98719877
98729878pub fn main() void {
98739879 var spartan_count: u16 = 300;
9874 const byte = @intCast(u8, spartan_count);
9880 const byte: u8 = @intCast(spartan_count);
98759881 std.debug.print("value: {}\n", .{byte});
98769882}
98779883 {#code_end#}
......@@ -10208,7 +10214,7 @@ const Foo = enum {
1020810214};
1020910215comptime {
1021010216 const a: u2 = 3;
10211 const b = @enumFromInt(Foo, a);
10217 const b: Foo = @enumFromInt(a);
1021210218 _ = b;
1021310219}
1021410220 {#code_end#}
......@@ -10224,7 +10230,7 @@ const Foo = enum {
1022410230
1022510231pub fn main() void {
1022610232 var a: u2 = 3;
10227 var b = @enumFromInt(Foo, a);
10233 var b: Foo = @enumFromInt(a);
1022810234 std.debug.print("value: {s}\n", .{@tagName(b)});
1022910235}
1023010236 {#code_end#}
......@@ -10242,7 +10248,7 @@ const Set2 = error{
1024210248 C,
1024310249};
1024410250comptime {
10245 _ = @errSetCast(Set2, Set1.B);
10251 _ = @as(Set2, @errSetCast(Set1.B));
1024610252}
1024710253 {#code_end#}
1024810254 <p>At runtime:</p>
......@@ -10261,7 +10267,7 @@ pub fn main() void {
1026110267 foo(Set1.B);
1026210268}
1026310269fn foo(set1: Set1) void {
10264 const x = @errSetCast(Set2, set1);
10270 const x = @as(Set2, @errSetCast(set1));
1026510271 std.debug.print("value: {}\n", .{x});
1026610272}
1026710273 {#code_end#}
......@@ -10271,8 +10277,8 @@ fn foo(set1: Set1) void {
1027110277 <p>At compile-time:</p>
1027210278 {#code_begin|test_err|test_comptime_incorrect_pointer_alignment|pointer address 0x1 is not aligned to 4 bytes#}
1027310279comptime {
10274 const ptr = @ptrFromInt(*align(1) i32, 0x1);
10275 const aligned = @alignCast(4, ptr);
10280 const ptr: *align(1) i32 = @ptrFromInt(0x1);
10281 const aligned: *align(4) i32 = @alignCast(ptr);
1027610282 _ = aligned;
1027710283}
1027810284 {#code_end#}
......@@ -10286,7 +10292,7 @@ pub fn main() !void {
1028610292}
1028710293fn foo(bytes: []u8) u32 {
1028810294 const slice4 = bytes[1..5];
10289 const int_slice = mem.bytesAsSlice(u32, @alignCast(4, slice4));
10295 const int_slice = mem.bytesAsSlice(u32, @as([]align(4) u8, @alignCast(slice4)));
1029010296 return int_slice[0];
1029110297}
1029210298 {#code_end#}
......@@ -10387,7 +10393,7 @@ fn bar(f: *Foo) void {
1038710393 {#code_begin|test_err|test_comptime_invalid_null_pointer_cast|null pointer casted to type#}
1038810394comptime {
1038910395 const opt_ptr: ?*i32 = null;
10390 const ptr = @ptrCast(*i32, opt_ptr);
10396 const ptr: *i32 = @ptrCast(opt_ptr);
1039110397 _ = ptr;
1039210398}
1039310399 {#code_end#}
......@@ -10395,7 +10401,7 @@ comptime {
1039510401 {#code_begin|exe_err|runtime_invalid_null_pointer_cast#}
1039610402pub fn main() void {
1039710403 var opt_ptr: ?*i32 = null;
10398 var ptr = @ptrCast(*i32, opt_ptr);
10404 var ptr: *i32 = @ptrCast(opt_ptr);
1039910405 _ = ptr;
1040010406}
1040110407 {#code_end#}
lib/compiler_rt/addf3.zig+22-22
......@@ -24,28 +24,28 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
2424 const significandMask = (@as(Z, 1) << significandBits) - 1;
2525
2626 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);
30 var bRep = @bitCast(Z, b);
29 var aRep = @as(Z, @bitCast(a));
30 var bRep = @as(Z, @bitCast(b));
3131 const aAbs = aRep & absMask;
3232 const bAbs = bRep & absMask;
3333
34 const infRep = @bitCast(Z, math.inf(T));
34 const infRep = @as(Z, @bitCast(math.inf(T)));
3535
3636 // Detect if a or b is zero, infinity, or NaN.
3737 if (aAbs -% @as(Z, 1) >= infRep - @as(Z, 1) or
3838 bAbs -% @as(Z, 1) >= infRep - @as(Z, 1))
3939 {
4040 // 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));
4242 // 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
4545 if (aAbs == infRep) {
4646 // +/-infinity + -/+infinity = qNaN
47 if ((@bitCast(Z, a) ^ @bitCast(Z, b)) == signBit) {
48 return @bitCast(T, qnanRep);
47 if ((@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) == signBit) {
48 return @as(T, @bitCast(qnanRep));
4949 }
5050 // +/-infinity + anything remaining = +/- infinity
5151 else {
......@@ -60,7 +60,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
6060 if (aAbs == 0) {
6161 // but we need to get the sign right for zero + zero
6262 if (bAbs == 0) {
63 return @bitCast(T, @bitCast(Z, a) & @bitCast(Z, b));
63 return @as(T, @bitCast(@as(Z, @bitCast(a)) & @as(Z, @bitCast(b))));
6464 } else {
6565 return b;
6666 }
......@@ -78,8 +78,8 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
7878 }
7979
8080 // Extract the exponent and significand from the (possibly swapped) a and b.
81 var aExponent = @intCast(i32, (aRep >> significandBits) & maxExponent);
82 var bExponent = @intCast(i32, (bRep >> significandBits) & maxExponent);
81 var aExponent = @as(i32, @intCast((aRep >> significandBits) & maxExponent));
82 var bExponent = @as(i32, @intCast((bRep >> significandBits) & maxExponent));
8383 var aSignificand = aRep & significandMask;
8484 var bSignificand = bRep & significandMask;
8585
......@@ -101,11 +101,11 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
101101
102102 // Shift the significand of b by the difference in exponents, with a sticky
103103 // bottom bit to get rounding correct.
104 const @"align" = @intCast(u32, aExponent - bExponent);
104 const @"align" = @as(u32, @intCast(aExponent - bExponent));
105105 if (@"align" != 0) {
106106 if (@"align" < typeWidth) {
107 const sticky = if (bSignificand << @intCast(S, typeWidth - @"align") != 0) @as(Z, 1) else 0;
108 bSignificand = (bSignificand >> @truncate(S, @"align")) | sticky;
107 const sticky = if (bSignificand << @as(S, @intCast(typeWidth - @"align")) != 0) @as(Z, 1) else 0;
108 bSignificand = (bSignificand >> @as(S, @truncate(@"align"))) | sticky;
109109 } else {
110110 bSignificand = 1; // sticky; b is known to be non-zero.
111111 }
......@@ -113,13 +113,13 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
113113 if (subtraction) {
114114 aSignificand -= bSignificand;
115115 // If a == -b, return +zero.
116 if (aSignificand == 0) return @bitCast(T, @as(Z, 0));
116 if (aSignificand == 0) return @as(T, @bitCast(@as(Z, 0)));
117117
118118 // If partial cancellation occured, we need to left-shift the result
119119 // and adjust the exponent:
120120 if (aSignificand < integerBit << 3) {
121 const shift = @intCast(i32, @clz(aSignificand)) - @intCast(i32, @clz(integerBit << 3));
122 aSignificand <<= @intCast(S, shift);
121 const shift = @as(i32, @intCast(@clz(aSignificand))) - @as(i32, @intCast(@clz(integerBit << 3)));
122 aSignificand <<= @as(S, @intCast(shift));
123123 aExponent -= shift;
124124 }
125125 } else { // addition
......@@ -135,13 +135,13 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
135135 }
136136
137137 // If we have overflowed the type, return +/- infinity:
138 if (aExponent >= maxExponent) return @bitCast(T, infRep | resultSign);
138 if (aExponent >= maxExponent) return @as(T, @bitCast(infRep | resultSign));
139139
140140 if (aExponent <= 0) {
141141 // Result is denormal; the exponent and round/sticky bits are zero.
142142 // All we need to do is shift the significand and apply the correct sign.
143 aSignificand >>= @intCast(S, 4 - aExponent);
144 return @bitCast(T, resultSign | aSignificand);
143 aSignificand >>= @as(S, @intCast(4 - aExponent));
144 return @as(T, @bitCast(resultSign | aSignificand));
145145 }
146146
147147 // Low three bits are round, guard, and sticky.
......@@ -151,7 +151,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
151151 var result = (aSignificand >> 3) & significandMask;
152152
153153 // Insert the exponent and sign.
154 result |= @intCast(Z, aExponent) << significandBits;
154 result |= @as(Z, @intCast(aExponent)) << significandBits;
155155 result |= resultSign;
156156
157157 // 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 {
164164 if ((result >> significandBits) != 0) result |= integerBit;
165165 }
166166
167 return @bitCast(T, result);
167 return @as(T, @bitCast(result));
168168}
169169
170170test {
lib/compiler_rt/addf3_test.zig+23-23
......@@ -5,7 +5,7 @@
55
66const std = @import("std");
77const math = std.math;
8const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64);
8const qnan128 = @as(f128, @bitCast(@as(u128, 0x7fff800000000000) << 64));
99
1010const __addtf3 = @import("addtf3.zig").__addtf3;
1111const __addxf3 = @import("addxf3.zig").__addxf3;
......@@ -14,9 +14,9 @@ const __subtf3 = @import("subtf3.zig").__subtf3;
1414fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
1515 const x = __addtf3(a, b);
1616
17 const rep = @bitCast(u128, x);
18 const hi = @intCast(u64, rep >> 64);
19 const lo = @truncate(u64, rep);
17 const rep = @as(u128, @bitCast(x));
18 const hi = @as(u64, @intCast(rep >> 64));
19 const lo = @as(u64, @truncate(rep));
2020
2121 if (hi == expected_hi and lo == expected_lo) {
2222 return;
......@@ -37,7 +37,7 @@ test "addtf3" {
3737 try test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
3838
3939 // 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
4242 // inf + inf = inf
4343 try test__addtf3(math.inf(f128), math.inf(f128), 0x7fff000000000000, 0x0);
......@@ -53,9 +53,9 @@ test "addtf3" {
5353fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
5454 const x = __subtf3(a, b);
5555
56 const rep = @bitCast(u128, x);
57 const hi = @intCast(u64, rep >> 64);
58 const lo = @truncate(u64, rep);
56 const rep = @as(u128, @bitCast(x));
57 const hi = @as(u64, @intCast(rep >> 64));
58 const lo = @as(u64, @truncate(rep));
5959
6060 if (hi == expected_hi and lo == expected_lo) {
6161 return;
......@@ -77,7 +77,7 @@ test "subtf3" {
7777 try test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
7878
7979 // 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
8282 // inf - any = inf
8383 try test__subtf3(math.inf(f128), 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);
......@@ -87,16 +87,16 @@ test "subtf3" {
8787 try test__subtf3(0x1.ee9d7c52354a6936ab8d7654321fp-1, 0x1.234567829a3bcdef5678ade36734p+5, 0xc0041b8af1915166, 0xa44a7bca780a166c);
8888}
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
9292fn test__addxf3(a: f80, b: f80, expected: u80) !void {
9393 const x = __addxf3(a, b);
94 const rep = @bitCast(u80, x);
94 const rep = @as(u80, @bitCast(x));
9595
9696 if (rep == expected)
9797 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))
100100 return; // We don't currently test NaN payload propagation
101101
102102 return error.TestFailed;
......@@ -104,33 +104,33 @@ fn test__addxf3(a: f80, b: f80, expected: u80) !void {
104104
105105test "addxf3" {
106106 // NaN + any = NaN
107 try test__addxf3(qnan80, 0x1.23456789abcdefp+5, @bitCast(u80, qnan80));
108 try test__addxf3(@bitCast(f80, @as(u80, 0x7fff_8000_8000_3000_0000)), 0x1.23456789abcdefp+5, @bitCast(u80, qnan80));
107 try test__addxf3(qnan80, 0x1.23456789abcdefp+5, @as(u80, @bitCast(qnan80)));
108 try test__addxf3(@as(f80, @bitCast(@as(u80, 0x7fff_8000_8000_3000_0000))), 0x1.23456789abcdefp+5, @as(u80, @bitCast(qnan80)));
109109
110110 // any + NaN = NaN
111 try test__addxf3(0x1.23456789abcdefp+5, qnan80, @bitCast(u80, qnan80));
112 try test__addxf3(0x1.23456789abcdefp+5, @bitCast(f80, @as(u80, 0x7fff_8000_8000_3000_0000)), @bitCast(u80, qnan80));
111 try test__addxf3(0x1.23456789abcdefp+5, qnan80, @as(u80, @bitCast(qnan80)));
112 try test__addxf3(0x1.23456789abcdefp+5, @as(f80, @bitCast(@as(u80, 0x7fff_8000_8000_3000_0000))), @as(u80, @bitCast(qnan80)));
113113
114114 // 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
117117 // 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
120120 // 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
123123 // 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
126126 // -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
129129 // 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
132132 // 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
135135 // any + any
136136 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 {
192192}
193193
194194pub 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)));
196196 return b + neg_a;
197197}
lib/compiler_rt/atomics.zig+3-3
......@@ -232,16 +232,16 @@ fn wideUpdate(comptime T: type, ptr: *T, val: T, update: anytype) T {
232232
233233 const addr = @intFromPtr(ptr);
234234 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
237237 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
240240 const mask = @as(WideAtomic, std.math.maxInt(T)) << inner_shift;
241241
242242 var wide_old = @atomicLoad(WideAtomic, wide_ptr, .SeqCst);
243243 while (true) {
244 const old = @truncate(T, (wide_old & mask) >> inner_shift);
244 const old = @as(T, @truncate((wide_old & mask) >> inner_shift));
245245 const new = update(val, old);
246246 const wide_new = wide_old & ~mask | (@as(WideAtomic, new) << inner_shift);
247247 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 {
2121 const an = (a ^ s_a) -% s_a;
2222 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));
2525 const s = s_a ^ s_b;
26 return (@bitCast(i64, r) ^ s) -% s;
26 return (@as(i64, @bitCast(r)) ^ s) -% s;
2727}
2828
2929pub 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 {
2121 const an = (a ^ s_a) -% s_a;
2222 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));
2525 const s = s_a ^ s_b;
26 return (@bitCast(i64, r) ^ s) -% s;
26 return (@as(i64, @bitCast(r)) ^ s) -% s;
2727}
2828
2929pub fn _aullrem() callconv(.Naked) void {
lib/compiler_rt/ceil.zig+8-8
......@@ -27,12 +27,12 @@ comptime {
2727
2828pub fn __ceilh(x: f16) callconv(.C) f16 {
2929 // TODO: more efficient implementation
30 return @floatCast(f16, ceilf(x));
30 return @as(f16, @floatCast(ceilf(x)));
3131}
3232
3333pub fn ceilf(x: f32) callconv(.C) f32 {
34 var u = @bitCast(u32, x);
35 var e = @intCast(i32, (u >> 23) & 0xFF) - 0x7F;
34 var u = @as(u32, @bitCast(x));
35 var e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;
3636 var m: u32 = undefined;
3737
3838 // TODO: Shouldn't need this explicit check.
......@@ -43,7 +43,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 {
4343 if (e >= 23) {
4444 return x;
4545 } else if (e >= 0) {
46 m = @as(u32, 0x007FFFFF) >> @intCast(u5, e);
46 m = @as(u32, 0x007FFFFF) >> @as(u5, @intCast(e));
4747 if (u & m == 0) {
4848 return x;
4949 }
......@@ -52,7 +52,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 {
5252 u += m;
5353 }
5454 u &= ~m;
55 return @bitCast(f32, u);
55 return @as(f32, @bitCast(u));
5656 } else {
5757 math.doNotOptimizeAway(x + 0x1.0p120);
5858 if (u >> 31 != 0) {
......@@ -66,7 +66,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 {
6666pub fn ceil(x: f64) callconv(.C) f64 {
6767 const f64_toint = 1.0 / math.floatEps(f64);
6868
69 const u = @bitCast(u64, x);
69 const u = @as(u64, @bitCast(x));
7070 const e = (u >> 52) & 0x7FF;
7171 var y: f64 = undefined;
7272
......@@ -96,13 +96,13 @@ pub fn ceil(x: f64) callconv(.C) f64 {
9696
9797pub fn __ceilx(x: f80) callconv(.C) f80 {
9898 // TODO: more efficient implementation
99 return @floatCast(f80, ceilq(x));
99 return @as(f80, @floatCast(ceilq(x)));
100100}
101101
102102pub fn ceilq(x: f128) callconv(.C) f128 {
103103 const f128_toint = 1.0 / math.floatEps(f128);
104104
105 const u = @bitCast(u128, x);
105 const u = @as(u128, @bitCast(x));
106106 const e = (u >> 112) & 0x7FFF;
107107 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 {
102102 // If CTR_EL0.IDC is set, data cache cleaning to the point of unification
103103 // is not required for instruction to data coherence.
104104 if (((ctr_el0 >> 28) & 0x1) == 0x0) {
105 const dcache_line_size: usize = @as(usize, 4) << @intCast(u6, (ctr_el0 >> 16) & 15);
105 const dcache_line_size: usize = @as(usize, 4) << @as(u6, @intCast((ctr_el0 >> 16) & 15));
106106 addr = start & ~(dcache_line_size - 1);
107107 while (addr < end) : (addr += dcache_line_size) {
108108 asm volatile ("dc cvau, %[addr]"
......@@ -115,7 +115,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void {
115115 // If CTR_EL0.DIC is set, instruction cache invalidation to the point of
116116 // unification is not required for instruction to data coherence.
117117 if (((ctr_el0 >> 29) & 0x1) == 0x0) {
118 const icache_line_size: usize = @as(usize, 4) << @intCast(u6, (ctr_el0 >> 0) & 15);
118 const icache_line_size: usize = @as(usize, 4) << @as(u6, @intCast((ctr_el0 >> 0) & 15));
119119 addr = start & ~(icache_line_size - 1);
120120 while (addr < end) : (addr += icache_line_size) {
121121 asm volatile ("ic ivau, %[addr]"
lib/compiler_rt/clzdi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const clz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__clzdi2(a: u64, expected: i64) !void {
5 var x = @bitCast(i64, a);
5 var x = @as(i64, @bitCast(a));
66 var result = clz.__clzdi2(x);
77 try testing.expectEqual(expected, result);
88}
lib/compiler_rt/clzsi2_test.zig+2-2
......@@ -4,8 +4,8 @@ const testing = @import("std").testing;
44
55fn test__clzsi2(a: u32, expected: i32) !void {
66 const nakedClzsi2 = clz.__clzsi2;
7 const actualClzsi2 = @ptrCast(*const fn (a: i32) callconv(.C) i32, &nakedClzsi2);
8 const x = @bitCast(i32, a);
7 const actualClzsi2 = @as(*const fn (a: i32) callconv(.C) i32, @ptrCast(&nakedClzsi2));
8 const x = @as(i32, @bitCast(a));
99 const result = actualClzsi2(x);
1010 try testing.expectEqual(expected, result);
1111}
lib/compiler_rt/clzti2_test.zig+1-1
......@@ -2,7 +2,7 @@ const clz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__clzti2(a: u128, expected: i64) !void {
5 var x = @bitCast(i128, a);
5 var x = @as(i128, @bitCast(a));
66 var result = clz.__clzti2(x);
77 try testing.expectEqual(expected, result);
88}
lib/compiler_rt/cmptf2.zig+6-6
......@@ -75,30 +75,30 @@ fn _Qp_cmp(a: *const f128, b: *const f128) callconv(.C) i32 {
7575}
7676
7777fn _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;
7979}
8080
8181fn _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;
8383}
8484
8585fn _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;
8787}
8888
8989fn _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;
9191}
9292
9393fn _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)))) {
9595 .Equal, .Greater => true,
9696 .Less, .Unordered => false,
9797 };
9898}
9999
100100fn _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)))) {
102102 .Equal, .Less => true,
103103 .Greater, .Unordered => false,
104104 };
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 {
102102 u16 => {
103103 // 16x16 --> 32 bit multiply
104104 const product = @as(u32, a) * @as(u32, b);
105 hi.* = @intCast(u16, product >> 16);
106 lo.* = @truncate(u16, product);
105 hi.* = @as(u16, @intCast(product >> 16));
106 lo.* = @as(u16, @truncate(product));
107107 },
108108 u32 => {
109109 // 32x32 --> 64 bit multiply
110110 const product = @as(u64, a) * @as(u64, b);
111 hi.* = @truncate(u32, product >> 32);
112 lo.* = @truncate(u32, product);
111 hi.* = @as(u32, @truncate(product >> 32));
112 lo.* = @as(u32, @truncate(product));
113113 },
114114 u64 => {
115115 const S = struct {
116116 fn loWord(x: u64) u64 {
117 return @truncate(u32, x);
117 return @as(u32, @truncate(x));
118118 }
119119 fn hiWord(x: u64) u64 {
120 return @truncate(u32, x >> 32);
120 return @as(u32, @truncate(x >> 32));
121121 }
122122 };
123123 // 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 {
141141 const Word_FullMask = @as(u64, 0xffffffffffffffff);
142142 const S = struct {
143143 fn Word_1(x: u128) u64 {
144 return @truncate(u32, x >> 96);
144 return @as(u32, @truncate(x >> 96));
145145 }
146146 fn Word_2(x: u128) u64 {
147 return @truncate(u32, x >> 64);
147 return @as(u32, @truncate(x >> 64));
148148 }
149149 fn Word_3(x: u128) u64 {
150 return @truncate(u32, x >> 32);
150 return @as(u32, @truncate(x >> 32));
151151 }
152152 fn Word_4(x: u128) u64 {
153 return @truncate(u32, x);
153 return @as(u32, @truncate(x));
154154 }
155155 };
156156 // 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
216216 const integerBit = @as(Z, 1) << std.math.floatFractionalBits(T);
217217
218218 const shift = @clz(significand.*) - @clz(integerBit);
219 significand.* <<= @intCast(std.math.Log2Int(Z), shift);
219 significand.* <<= @as(std.math.Log2Int(Z), @intCast(shift));
220220 return @as(i32, 1) - shift;
221221}
222222
......@@ -228,8 +228,8 @@ pub inline fn fneg(a: anytype) @TypeOf(a) {
228228 .bits = bits,
229229 } });
230230 const sign_bit_mask = @as(U, 1) << (bits - 1);
231 const negated = @bitCast(U, a) ^ sign_bit_mask;
232 return @bitCast(F, negated);
231 const negated = @as(U, @bitCast(a)) ^ sign_bit_mask;
232 return @as(F, @bitCast(negated));
233233}
234234
235235/// 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 {
2626 const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
2727 const absMask = signBit - 1;
2828 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);
32 const bInt = @bitCast(srep_t, b);
33 const aAbs = @bitCast(rep_t, aInt) & absMask;
34 const bAbs = @bitCast(rep_t, bInt) & absMask;
31 const aInt = @as(srep_t, @bitCast(a));
32 const bInt = @as(srep_t, @bitCast(b));
33 const aAbs = @as(rep_t, @bitCast(aInt)) & absMask;
34 const bAbs = @as(rep_t, @bitCast(bInt)) & absMask;
3535
3636 // If either a or b is NaN, they are unordered.
3737 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 {
8181 return .Equal;
8282 } else if (a_rep.exp & sign_bit != b_rep.exp & sign_bit) {
8383 // 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))) {
8585 return .Less;
8686 } else {
8787 return .Greater;
......@@ -104,10 +104,10 @@ pub inline fn unordcmp(comptime T: type, a: T, b: T) i32 {
104104 const exponentBits = std.math.floatExponentBits(T);
105105 const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
106106 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;
110 const bAbs: rep_t = @bitCast(rep_t, b) & absMask;
109 const aAbs: rep_t = @as(rep_t, @bitCast(a)) & absMask;
110 const bAbs: rep_t = @as(rep_t, @bitCast(b)) & absMask;
111111
112112 return @intFromBool(aAbs > infRep or bAbs > infRep);
113113}
lib/compiler_rt/cos.zig+5-5
......@@ -25,7 +25,7 @@ comptime {
2525
2626pub fn __cosh(a: f16) callconv(.C) f16 {
2727 // TODO: more efficient implementation
28 return @floatCast(f16, cosf(a));
28 return @as(f16, @floatCast(cosf(a)));
2929}
3030
3131pub fn cosf(x: f32) callconv(.C) f32 {
......@@ -35,7 +35,7 @@ pub fn cosf(x: f32) callconv(.C) f32 {
3535 const c3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2
3636 const c4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18
3737
38 var ix = @bitCast(u32, x);
38 var ix = @as(u32, @bitCast(x));
3939 const sign = ix >> 31 != 0;
4040 ix &= 0x7fffffff;
4141
......@@ -86,7 +86,7 @@ pub fn cosf(x: f32) callconv(.C) f32 {
8686}
8787
8888pub fn cos(x: f64) callconv(.C) f64 {
89 var ix = @bitCast(u64, x) >> 32;
89 var ix = @as(u64, @bitCast(x)) >> 32;
9090 ix &= 0x7fffffff;
9191
9292 // |x| ~< pi/4
......@@ -116,12 +116,12 @@ pub fn cos(x: f64) callconv(.C) f64 {
116116
117117pub fn __cosx(a: f80) callconv(.C) f80 {
118118 // TODO: more efficient implementation
119 return @floatCast(f80, cosq(a));
119 return @as(f80, @floatCast(cosq(a)));
120120}
121121
122122pub fn cosq(a: f128) callconv(.C) f128 {
123123 // TODO: more correct implementation
124 return cos(@floatCast(f64, a));
124 return cos(@as(f64, @floatCast(a)));
125125}
126126
127127pub fn cosl(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/count0bits.zig+12-12
......@@ -32,9 +32,9 @@ comptime {
3232
3333inline fn clzXi2(comptime T: type, a: T) i32 {
3434 var x = switch (@bitSizeOf(T)) {
35 32 => @bitCast(u32, a),
36 64 => @bitCast(u64, a),
37 128 => @bitCast(u128, a),
35 32 => @as(u32, @bitCast(a)),
36 64 => @as(u64, @bitCast(a)),
37 128 => @as(u128, @bitCast(a)),
3838 else => unreachable,
3939 };
4040 var n: T = @bitSizeOf(T);
......@@ -49,7 +49,7 @@ inline fn clzXi2(comptime T: type, a: T) i32 {
4949 x = y;
5050 }
5151 }
52 return @intCast(i32, n - @bitCast(T, x));
52 return @as(i32, @intCast(n - @as(T, @bitCast(x))));
5353}
5454
5555fn __clzsi2_thumb1() callconv(.Naked) void {
......@@ -169,9 +169,9 @@ pub fn __clzti2(a: i128) callconv(.C) i32 {
169169
170170inline fn ctzXi2(comptime T: type, a: T) i32 {
171171 var x = switch (@bitSizeOf(T)) {
172 32 => @bitCast(u32, a),
173 64 => @bitCast(u64, a),
174 128 => @bitCast(u128, a),
172 32 => @as(u32, @bitCast(a)),
173 64 => @as(u64, @bitCast(a)),
174 128 => @as(u128, @bitCast(a)),
175175 else => unreachable,
176176 };
177177 var n: T = 1;
......@@ -187,7 +187,7 @@ inline fn ctzXi2(comptime T: type, a: T) i32 {
187187 x = x >> shift;
188188 }
189189 }
190 return @intCast(i32, n - @bitCast(T, (x & 1)));
190 return @as(i32, @intCast(n - @as(T, @bitCast((x & 1)))));
191191}
192192
193193pub fn __ctzsi2(a: i32) callconv(.C) i32 {
......@@ -204,9 +204,9 @@ pub fn __ctzti2(a: i128) callconv(.C) i32 {
204204
205205inline fn ffsXi2(comptime T: type, a: T) i32 {
206206 var x = switch (@bitSizeOf(T)) {
207 32 => @bitCast(u32, a),
208 64 => @bitCast(u64, a),
209 128 => @bitCast(u128, a),
207 32 => @as(u32, @bitCast(a)),
208 64 => @as(u64, @bitCast(a)),
209 128 => @as(u128, @bitCast(a)),
210210 else => unreachable,
211211 };
212212 var n: T = 1;
......@@ -224,7 +224,7 @@ inline fn ffsXi2(comptime T: type, a: T) i32 {
224224 }
225225 }
226226 // 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);
228228}
229229
230230pub fn __ffssi2(a: i32) callconv(.C) i32 {
lib/compiler_rt/ctzdi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const ctz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ctzdi2(a: u64, expected: i32) !void {
5 var x = @bitCast(i64, a);
5 var x = @as(i64, @bitCast(a));
66 var result = ctz.__ctzdi2(x);
77 try testing.expectEqual(expected, result);
88}
lib/compiler_rt/ctzsi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const ctz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ctzsi2(a: u32, expected: i32) !void {
5 var x = @bitCast(i32, a);
5 var x = @as(i32, @bitCast(a));
66 var result = ctz.__ctzsi2(x);
77 try testing.expectEqual(expected, result);
88}
lib/compiler_rt/ctzti2_test.zig+1-1
......@@ -2,7 +2,7 @@ const ctz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ctzti2(a: u128, expected: i32) !void {
5 var x = @bitCast(i128, a);
5 var x = @as(i128, @bitCast(a));
66 var result = ctz.__ctzti2(x);
77 try testing.expectEqual(expected, result);
88}
lib/compiler_rt/divdf3.zig+32-32
......@@ -47,52 +47,52 @@ inline fn div(a: f64, b: f64) f64 {
4747 const absMask = signBit - 1;
4848 const exponentMask = absMask ^ significandMask;
4949 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);
53 const bExponent = @truncate(u32, (@bitCast(Z, b) >> significandBits) & maxExponent);
54 const quotientSign: Z = (@bitCast(Z, a) ^ @bitCast(Z, b)) & signBit;
52 const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
53 const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
54 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
5555
56 var aSignificand: Z = @bitCast(Z, a) & significandMask;
57 var bSignificand: Z = @bitCast(Z, b) & significandMask;
56 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;
57 var bSignificand: Z = @as(Z, @bitCast(b)) & significandMask;
5858 var scale: i32 = 0;
5959
6060 // Detect if a or b is zero, denormal, infinity, or NaN.
6161 if (aExponent -% 1 >= maxExponent - 1 or bExponent -% 1 >= maxExponent - 1) {
62 const aAbs: Z = @bitCast(Z, a) & absMask;
63 const bAbs: Z = @bitCast(Z, b) & absMask;
62 const aAbs: Z = @as(Z, @bitCast(a)) & absMask;
63 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
6464
6565 // 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));
6767 // 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
7070 if (aAbs == infRep) {
7171 // infinity / infinity = NaN
7272 if (bAbs == infRep) {
73 return @bitCast(f64, qnanRep);
73 return @as(f64, @bitCast(qnanRep));
7474 }
7575 // infinity / anything else = +/- infinity
7676 else {
77 return @bitCast(f64, aAbs | quotientSign);
77 return @as(f64, @bitCast(aAbs | quotientSign));
7878 }
7979 }
8080
8181 // anything else / infinity = +/- 0
82 if (bAbs == infRep) return @bitCast(f64, quotientSign);
82 if (bAbs == infRep) return @as(f64, @bitCast(quotientSign));
8383
8484 if (aAbs == 0) {
8585 // zero / zero = NaN
8686 if (bAbs == 0) {
87 return @bitCast(f64, qnanRep);
87 return @as(f64, @bitCast(qnanRep));
8888 }
8989 // zero / anything else = +/- zero
9090 else {
91 return @bitCast(f64, quotientSign);
91 return @as(f64, @bitCast(quotientSign));
9292 }
9393 }
9494 // anything else / zero = +/- infinity
95 if (bAbs == 0) return @bitCast(f64, infRep | quotientSign);
95 if (bAbs == 0) return @as(f64, @bitCast(infRep | quotientSign));
9696
9797 // one or both of a or b is denormal, the other (if applicable) is a
9898 // normal number. Renormalize one or both of a and b, and set scale to
......@@ -106,13 +106,13 @@ inline fn div(a: f64, b: f64) f64 {
106106 // won't hurt anything.)
107107 aSignificand |= implicitBit;
108108 bSignificand |= implicitBit;
109 var quotientExponent: i32 = @bitCast(i32, aExponent -% bExponent) +% scale;
109 var quotientExponent: i32 = @as(i32, @bitCast(aExponent -% bExponent)) +% scale;
110110
111111 // Align the significand of b as a Q31 fixed-point number in the range
112112 // [1, 2.0) and get a Q32 approximate reciprocal using a small minimax
113113 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
114114 // is accurate to about 3.5 binary digits.
115 const q31b: u32 = @truncate(u32, bSignificand >> 21);
115 const q31b: u32 = @as(u32, @truncate(bSignificand >> 21));
116116 var recip32 = @as(u32, 0x7504f333) -% q31b;
117117
118118 // Now refine the reciprocal estimate using a Newton-Raphson iteration:
......@@ -123,12 +123,12 @@ inline fn div(a: f64, b: f64) f64 {
123123 // with each iteration, so after three iterations, we have about 28 binary
124124 // digits of accuracy.
125125 var correction32: u32 = undefined;
126 correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1);
127 recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31);
128 correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1);
129 recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31);
130 correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1);
131 recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31);
126 correction32 = @as(u32, @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1));
127 recip32 = @as(u32, @truncate(@as(u64, recip32) *% correction32 >> 31));
128 correction32 = @as(u32, @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1));
129 recip32 = @as(u32, @truncate(@as(u64, recip32) *% correction32 >> 31));
130 correction32 = @as(u32, @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1));
131 recip32 = @as(u32, @truncate(@as(u64, recip32) *% correction32 >> 31));
132132
133133 // recip32 might have overflowed to exactly zero in the preceding
134134 // computation if the high word of b is exactly 1.0. This would sabotage
......@@ -138,12 +138,12 @@ inline fn div(a: f64, b: f64) f64 {
138138
139139 // We need to perform one more iteration to get us to 56 binary digits;
140140 // The last iteration needs to happen with extra precision.
141 const q63blo: u32 = @truncate(u32, bSignificand << 11);
141 const q63blo: u32 = @as(u32, @truncate(bSignificand << 11));
142142 var correction: u64 = undefined;
143143 var reciprocal: u64 = undefined;
144144 correction = ~(@as(u64, recip32) *% q31b +% (@as(u64, recip32) *% q63blo >> 32)) +% 1;
145 const cHi = @truncate(u32, correction >> 32);
146 const cLo = @truncate(u32, correction);
145 const cHi = @as(u32, @truncate(correction >> 32));
146 const cLo = @as(u32, @truncate(correction));
147147 reciprocal = @as(u64, recip32) *% cHi +% (@as(u64, recip32) *% cLo >> 32);
148148
149149 // We already adjusted the 32-bit estimate, now we need to adjust the final
......@@ -195,7 +195,7 @@ inline fn div(a: f64, b: f64) f64 {
195195
196196 if (writtenExponent >= maxExponent) {
197197 // If we have overflowed the exponent, return infinity.
198 return @bitCast(f64, infRep | quotientSign);
198 return @as(f64, @bitCast(infRep | quotientSign));
199199 } else if (writtenExponent < 1) {
200200 if (writtenExponent == 0) {
201201 // Check whether the rounded result is normal.
......@@ -206,22 +206,22 @@ inline fn div(a: f64, b: f64) f64 {
206206 absResult += round;
207207 if ((absResult & ~significandMask) != 0) {
208208 // The rounded result is normal; return it.
209 return @bitCast(f64, absResult | quotientSign);
209 return @as(f64, @bitCast(absResult | quotientSign));
210210 }
211211 }
212212 // Flush denormals to zero. In the future, it would be nice to add
213213 // code to round them correctly.
214 return @bitCast(f64, quotientSign);
214 return @as(f64, @bitCast(quotientSign));
215215 } else {
216216 const round = @intFromBool((residual << 1) > bSignificand);
217217 // Clear the implicit bit
218218 var absResult = quotient & significandMask;
219219 // Insert the exponent
220 absResult |= @bitCast(Z, @as(SignedZ, writtenExponent)) << significandBits;
220 absResult |= @as(Z, @bitCast(@as(SignedZ, writtenExponent))) << significandBits;
221221 // Round
222222 absResult +%= round;
223223 // Insert the sign and return
224 return @bitCast(f64, absResult | quotientSign);
224 return @as(f64, @bitCast(absResult | quotientSign));
225225 }
226226}
227227
lib/compiler_rt/divdf3_test.zig+1-1
......@@ -6,7 +6,7 @@ const __divdf3 = @import("divdf3.zig").__divdf3;
66const testing = @import("std").testing;
77
88fn compareResultD(result: f64, expected: u64) bool {
9 const rep = @bitCast(u64, result);
9 const rep = @as(u64, @bitCast(result));
1010
1111 if (rep == expected) {
1212 return true;
lib/compiler_rt/divhf3.zig+1-1
......@@ -7,5 +7,5 @@ comptime {
77
88pub fn __divhf3(a: f16, b: f16) callconv(.C) f16 {
99 // TODO: more efficient implementation
10 return @floatCast(f16, divsf3.__divsf3(a, b));
10 return @as(f16, @floatCast(divsf3.__divsf3(a, b)));
1111}
lib/compiler_rt/divsf3.zig+29-29
......@@ -44,52 +44,52 @@ inline fn div(a: f32, b: f32) f32 {
4444 const absMask = signBit - 1;
4545 const exponentMask = absMask ^ significandMask;
4646 const qnanRep = exponentMask | quietBit;
47 const infRep = @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);
50 const bExponent = @truncate(u32, (@bitCast(Z, b) >> significandBits) & maxExponent);
51 const quotientSign: Z = (@bitCast(Z, a) ^ @bitCast(Z, b)) & signBit;
49 const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
50 const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
51 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
5252
53 var aSignificand: Z = @bitCast(Z, a) & significandMask;
54 var bSignificand: Z = @bitCast(Z, b) & significandMask;
53 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;
54 var bSignificand: Z = @as(Z, @bitCast(b)) & significandMask;
5555 var scale: i32 = 0;
5656
5757 // Detect if a or b is zero, denormal, infinity, or NaN.
5858 if (aExponent -% 1 >= maxExponent - 1 or bExponent -% 1 >= maxExponent - 1) {
59 const aAbs: Z = @bitCast(Z, a) & absMask;
60 const bAbs: Z = @bitCast(Z, b) & absMask;
59 const aAbs: Z = @as(Z, @bitCast(a)) & absMask;
60 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
6161
6262 // 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));
6464 // 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
6767 if (aAbs == infRep) {
6868 // infinity / infinity = NaN
6969 if (bAbs == infRep) {
70 return @bitCast(f32, qnanRep);
70 return @as(f32, @bitCast(qnanRep));
7171 }
7272 // infinity / anything else = +/- infinity
7373 else {
74 return @bitCast(f32, aAbs | quotientSign);
74 return @as(f32, @bitCast(aAbs | quotientSign));
7575 }
7676 }
7777
7878 // anything else / infinity = +/- 0
79 if (bAbs == infRep) return @bitCast(f32, quotientSign);
79 if (bAbs == infRep) return @as(f32, @bitCast(quotientSign));
8080
8181 if (aAbs == 0) {
8282 // zero / zero = NaN
8383 if (bAbs == 0) {
84 return @bitCast(f32, qnanRep);
84 return @as(f32, @bitCast(qnanRep));
8585 }
8686 // zero / anything else = +/- zero
8787 else {
88 return @bitCast(f32, quotientSign);
88 return @as(f32, @bitCast(quotientSign));
8989 }
9090 }
9191 // anything else / zero = +/- infinity
92 if (bAbs == 0) return @bitCast(f32, infRep | quotientSign);
92 if (bAbs == 0) return @as(f32, @bitCast(infRep | quotientSign));
9393
9494 // one or both of a or b is denormal, the other (if applicable) is a
9595 // normal number. Renormalize one or both of a and b, and set scale to
......@@ -103,7 +103,7 @@ inline fn div(a: f32, b: f32) f32 {
103103 // won't hurt anything.)
104104 aSignificand |= implicitBit;
105105 bSignificand |= implicitBit;
106 var quotientExponent: i32 = @bitCast(i32, aExponent -% bExponent) +% scale;
106 var quotientExponent: i32 = @as(i32, @bitCast(aExponent -% bExponent)) +% scale;
107107
108108 // Align the significand of b as a Q31 fixed-point number in the range
109109 // [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 {
120120 // with each iteration, so after three iterations, we have about 28 binary
121121 // digits of accuracy.
122122 var correction: u32 = undefined;
123 correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
124 reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31);
125 correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
126 reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31);
127 correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
128 reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31);
123 correction = @as(u32, @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1));
124 reciprocal = @as(u32, @truncate(@as(u64, reciprocal) *% correction >> 31));
125 correction = @as(u32, @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1));
126 reciprocal = @as(u32, @truncate(@as(u64, reciprocal) *% correction >> 31));
127 correction = @as(u32, @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1));
128 reciprocal = @as(u32, @truncate(@as(u64, reciprocal) *% correction >> 31));
129129
130130 // Exhaustive testing shows that the error in reciprocal after three steps
131131 // is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our
......@@ -147,7 +147,7 @@ inline fn div(a: f32, b: f32) f32 {
147147 // is the error in the reciprocal of b scaled by the maximum
148148 // possible value of a. As a consequence of this error bound,
149149 // either q or nextafter(q) is the correctly rounded
150 var quotient: Z = @truncate(u32, @as(u64, reciprocal) *% (aSignificand << 1) >> 32);
150 var quotient: Z = @as(u32, @truncate(@as(u64, reciprocal) *% (aSignificand << 1) >> 32));
151151
152152 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
153153 // In either case, we are going to compute a residual of the form
......@@ -175,7 +175,7 @@ inline fn div(a: f32, b: f32) f32 {
175175
176176 if (writtenExponent >= maxExponent) {
177177 // If we have overflowed the exponent, return infinity.
178 return @bitCast(f32, infRep | quotientSign);
178 return @as(f32, @bitCast(infRep | quotientSign));
179179 } else if (writtenExponent < 1) {
180180 if (writtenExponent == 0) {
181181 // Check whether the rounded result is normal.
......@@ -186,22 +186,22 @@ inline fn div(a: f32, b: f32) f32 {
186186 absResult += round;
187187 if ((absResult & ~significandMask) > 0) {
188188 // The rounded result is normal; return it.
189 return @bitCast(f32, absResult | quotientSign);
189 return @as(f32, @bitCast(absResult | quotientSign));
190190 }
191191 }
192192 // Flush denormals to zero. In the future, it would be nice to add
193193 // code to round them correctly.
194 return @bitCast(f32, quotientSign);
194 return @as(f32, @bitCast(quotientSign));
195195 } else {
196196 const round = @intFromBool((residual << 1) > bSignificand);
197197 // Clear the implicit bit
198198 var absResult = quotient & significandMask;
199199 // Insert the exponent
200 absResult |= @bitCast(Z, writtenExponent) << significandBits;
200 absResult |= @as(Z, @bitCast(writtenExponent)) << significandBits;
201201 // Round
202202 absResult +%= round;
203203 // Insert the sign and return
204 return @bitCast(f32, absResult | quotientSign);
204 return @as(f32, @bitCast(absResult | quotientSign));
205205 }
206206}
207207
lib/compiler_rt/divsf3_test.zig+1-1
......@@ -6,7 +6,7 @@ const __divsf3 = @import("divsf3.zig").__divsf3;
66const testing = @import("std").testing;
77
88fn compareResultF(result: f32, expected: u32) bool {
9 const rep = @bitCast(u32, result);
9 const rep = @as(u32, @bitCast(result));
1010
1111 if (rep == expected) {
1212 return true;
lib/compiler_rt/divtf3.zig+36-36
......@@ -41,52 +41,52 @@ inline fn div(a: f128, b: f128) f128 {
4141 const absMask = signBit - 1;
4242 const exponentMask = absMask ^ significandMask;
4343 const qnanRep = exponentMask | quietBit;
44 const infRep = @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);
47 const bExponent = @truncate(u32, (@bitCast(Z, b) >> significandBits) & maxExponent);
48 const quotientSign: Z = (@bitCast(Z, a) ^ @bitCast(Z, b)) & signBit;
46 const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
47 const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
48 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
4949
50 var aSignificand: Z = @bitCast(Z, a) & significandMask;
51 var bSignificand: Z = @bitCast(Z, b) & significandMask;
50 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;
51 var bSignificand: Z = @as(Z, @bitCast(b)) & significandMask;
5252 var scale: i32 = 0;
5353
5454 // Detect if a or b is zero, denormal, infinity, or NaN.
5555 if (aExponent -% 1 >= maxExponent - 1 or bExponent -% 1 >= maxExponent - 1) {
56 const aAbs: Z = @bitCast(Z, a) & absMask;
57 const bAbs: Z = @bitCast(Z, b) & absMask;
56 const aAbs: Z = @as(Z, @bitCast(a)) & absMask;
57 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
5858
5959 // 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));
6161 // 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
6464 if (aAbs == infRep) {
6565 // infinity / infinity = NaN
6666 if (bAbs == infRep) {
67 return @bitCast(f128, qnanRep);
67 return @as(f128, @bitCast(qnanRep));
6868 }
6969 // infinity / anything else = +/- infinity
7070 else {
71 return @bitCast(f128, aAbs | quotientSign);
71 return @as(f128, @bitCast(aAbs | quotientSign));
7272 }
7373 }
7474
7575 // anything else / infinity = +/- 0
76 if (bAbs == infRep) return @bitCast(f128, quotientSign);
76 if (bAbs == infRep) return @as(f128, @bitCast(quotientSign));
7777
7878 if (aAbs == 0) {
7979 // zero / zero = NaN
8080 if (bAbs == 0) {
81 return @bitCast(f128, qnanRep);
81 return @as(f128, @bitCast(qnanRep));
8282 }
8383 // zero / anything else = +/- zero
8484 else {
85 return @bitCast(f128, quotientSign);
85 return @as(f128, @bitCast(quotientSign));
8686 }
8787 }
8888 // anything else / zero = +/- infinity
89 if (bAbs == 0) return @bitCast(f128, infRep | quotientSign);
89 if (bAbs == 0) return @as(f128, @bitCast(infRep | quotientSign));
9090
9191 // one or both of a or b is denormal, the other (if applicable) is a
9292 // normal number. Renormalize one or both of a and b, and set scale to
......@@ -100,13 +100,13 @@ inline fn div(a: f128, b: f128) f128 {
100100 // won't hurt anything.
101101 aSignificand |= implicitBit;
102102 bSignificand |= implicitBit;
103 var quotientExponent: i32 = @bitCast(i32, aExponent -% bExponent) +% scale;
103 var quotientExponent: i32 = @as(i32, @bitCast(aExponent -% bExponent)) +% scale;
104104
105105 // Align the significand of b as a Q63 fixed-point number in the range
106106 // [1, 2.0) and get a Q64 approximate reciprocal using a small minimax
107107 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
108108 // is accurate to about 3.5 binary digits.
109 const q63b = @truncate(u64, bSignificand >> 49);
109 const q63b = @as(u64, @truncate(bSignificand >> 49));
110110 var recip64 = @as(u64, 0x7504f333F9DE6484) -% q63b;
111111 // 0x7504f333F9DE6484 / 2^64 + 1 = 3/4 + 1/sqrt(2)
112112
......@@ -117,16 +117,16 @@ inline fn div(a: f128, b: f128) f128 {
117117 // This doubles the number of correct binary digits in the approximation
118118 // with each iteration.
119119 var correction64: u64 = undefined;
120 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);
121 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);
122 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);
123 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);
124 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);
125 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);
126 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);
127 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);
128 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);
129 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);
120 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
121 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
122 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
123 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
124 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
125 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
126 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
127 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
128 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
129 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
130130
131131 // The reciprocal may have overflowed to zero if the upper half of b is
132132 // exactly 1.0. This would sabatoge the full-width final stage of the
......@@ -135,7 +135,7 @@ inline fn div(a: f128, b: f128) f128 {
135135
136136 // We need to perform one more iteration to get us to 112 binary digits;
137137 // The last iteration needs to happen with extra precision.
138 const q127blo: u64 = @truncate(u64, bSignificand << 15);
138 const q127blo: u64 = @as(u64, @truncate(bSignificand << 15));
139139 var correction: u128 = undefined;
140140 var reciprocal: u128 = undefined;
141141
......@@ -151,8 +151,8 @@ inline fn div(a: f128, b: f128) f128 {
151151
152152 correction = -%(r64q63 + (r64q127 >> 64));
153153
154 const cHi = @truncate(u64, correction >> 64);
155 const cLo = @truncate(u64, correction);
154 const cHi = @as(u64, @truncate(correction >> 64));
155 const cLo = @as(u64, @truncate(correction));
156156
157157 wideMultiply(u128, recip64, cHi, &dummy, &r64cH);
158158 wideMultiply(u128, recip64, cLo, &dummy, &r64cL);
......@@ -210,7 +210,7 @@ inline fn div(a: f128, b: f128) f128 {
210210
211211 if (writtenExponent >= maxExponent) {
212212 // If we have overflowed the exponent, return infinity.
213 return @bitCast(f128, infRep | quotientSign);
213 return @as(f128, @bitCast(infRep | quotientSign));
214214 } else if (writtenExponent < 1) {
215215 if (writtenExponent == 0) {
216216 // Check whether the rounded result is normal.
......@@ -221,22 +221,22 @@ inline fn div(a: f128, b: f128) f128 {
221221 absResult += round;
222222 if ((absResult & ~significandMask) > 0) {
223223 // The rounded result is normal; return it.
224 return @bitCast(f128, absResult | quotientSign);
224 return @as(f128, @bitCast(absResult | quotientSign));
225225 }
226226 }
227227 // Flush denormals to zero. In the future, it would be nice to add
228228 // code to round them correctly.
229 return @bitCast(f128, quotientSign);
229 return @as(f128, @bitCast(quotientSign));
230230 } else {
231231 const round = @intFromBool((residual << 1) >= bSignificand);
232232 // Clear the implicit bit
233233 var absResult = quotient & significandMask;
234234 // Insert the exponent
235 absResult |= @intCast(Z, writtenExponent) << significandBits;
235 absResult |= @as(Z, @intCast(writtenExponent)) << significandBits;
236236 // Round
237237 absResult +%= round;
238238 // Insert the sign and return
239 return @bitCast(f128, absResult | quotientSign);
239 return @as(f128, @bitCast(absResult | quotientSign));
240240 }
241241}
242242
lib/compiler_rt/divtf3_test.zig+3-3
......@@ -5,9 +5,9 @@ const testing = std.testing;
55const __divtf3 = @import("divtf3.zig").__divtf3;
66
77fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
8 const rep = @bitCast(u128, result);
9 const hi = @truncate(u64, rep >> 64);
10 const lo = @truncate(u64, rep);
8 const rep = @as(u128, @bitCast(result));
9 const hi = @as(u64, @truncate(rep >> 64));
10 const lo = @as(u64, @truncate(rep));
1111
1212 if (hi == expectedHi and lo == expectedLo) {
1313 return true;
lib/compiler_rt/divti3.zig+3-3
......@@ -21,7 +21,7 @@ pub fn __divti3(a: i128, b: i128) callconv(.C) i128 {
2121const v128 = @Vector(2, u64);
2222
2323fn __divti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
24 return @bitCast(v128, div(@bitCast(i128, a), @bitCast(i128, b)));
24 return @as(v128, @bitCast(div(@as(i128, @bitCast(a)), @as(i128, @bitCast(b)))));
2525}
2626
2727inline fn div(a: i128, b: i128) i128 {
......@@ -31,9 +31,9 @@ inline fn div(a: i128, b: i128) i128 {
3131 const an = (a ^ s_a) -% s_a;
3232 const bn = (b ^ s_b) -% s_b;
3333
34 const r = udivmod(u128, @bitCast(u128, an), @bitCast(u128, bn), null);
34 const r = udivmod(u128, @as(u128, @bitCast(an)), @as(u128, @bitCast(bn)), null);
3535 const s = s_a ^ s_b;
36 return (@bitCast(i128, r) ^ s) -% s;
36 return (@as(i128, @bitCast(r)) ^ s) -% s;
3737}
3838
3939test {
lib/compiler_rt/divti3_test.zig+4-4
......@@ -14,8 +14,8 @@ test "divti3" {
1414 try test__divti3(-2, 1, -2);
1515 try test__divti3(-2, -1, 2);
1616
17 try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 1, @bitCast(i128, @as(u128, 0x8 << 124)));
18 try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -1, @bitCast(i128, @as(u128, 0x8 << 124)));
19 try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -2, @bitCast(i128, @as(u128, 0x4 << 124)));
20 try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 2, @bitCast(i128, @as(u128, 0xc << 124)));
17 try test__divti3(@as(i128, @bitCast(@as(u128, 0x8 << 124))), 1, @as(i128, @bitCast(@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(@as(i128, @bitCast(@as(u128, 0x8 << 124))), -2, @as(i128, @bitCast(@as(u128, 0x4 << 124))));
20 try test__divti3(@as(i128, @bitCast(@as(u128, 0x8 << 124))), 2, @as(i128, @bitCast(@as(u128, 0xc << 124))));
2121}
lib/compiler_rt/divxf3.zig+38-38
......@@ -29,53 +29,53 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
2929 const significandMask = (@as(Z, 1) << significandBits) - 1;
3030
3131 const absMask = signBit - 1;
32 const qnanRep = @bitCast(Z, std.math.nan(T)) | quietBit;
33 const infRep = @bitCast(Z, std.math.inf(T));
32 const qnanRep = @as(Z, @bitCast(std.math.nan(T))) | quietBit;
33 const infRep = @as(Z, @bitCast(std.math.inf(T)));
3434
35 const aExponent = @truncate(u32, (@bitCast(Z, a) >> significandBits) & maxExponent);
36 const bExponent = @truncate(u32, (@bitCast(Z, b) >> significandBits) & maxExponent);
37 const quotientSign: Z = (@bitCast(Z, a) ^ @bitCast(Z, b)) & signBit;
35 const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
36 const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
37 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
3838
39 var aSignificand: Z = @bitCast(Z, a) & significandMask;
40 var bSignificand: Z = @bitCast(Z, b) & significandMask;
39 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;
40 var bSignificand: Z = @as(Z, @bitCast(b)) & significandMask;
4141 var scale: i32 = 0;
4242
4343 // Detect if a or b is zero, denormal, infinity, or NaN.
4444 if (aExponent -% 1 >= maxExponent - 1 or bExponent -% 1 >= maxExponent - 1) {
45 const aAbs: Z = @bitCast(Z, a) & absMask;
46 const bAbs: Z = @bitCast(Z, b) & absMask;
45 const aAbs: Z = @as(Z, @bitCast(a)) & absMask;
46 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
4747
4848 // 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));
5050 // 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
5353 if (aAbs == infRep) {
5454 // infinity / infinity = NaN
5555 if (bAbs == infRep) {
56 return @bitCast(T, qnanRep);
56 return @as(T, @bitCast(qnanRep));
5757 }
5858 // infinity / anything else = +/- infinity
5959 else {
60 return @bitCast(T, aAbs | quotientSign);
60 return @as(T, @bitCast(aAbs | quotientSign));
6161 }
6262 }
6363
6464 // anything else / infinity = +/- 0
65 if (bAbs == infRep) return @bitCast(T, quotientSign);
65 if (bAbs == infRep) return @as(T, @bitCast(quotientSign));
6666
6767 if (aAbs == 0) {
6868 // zero / zero = NaN
6969 if (bAbs == 0) {
70 return @bitCast(T, qnanRep);
70 return @as(T, @bitCast(qnanRep));
7171 }
7272 // zero / anything else = +/- zero
7373 else {
74 return @bitCast(T, quotientSign);
74 return @as(T, @bitCast(quotientSign));
7575 }
7676 }
7777 // anything else / zero = +/- infinity
78 if (bAbs == 0) return @bitCast(T, infRep | quotientSign);
78 if (bAbs == 0) return @as(T, @bitCast(infRep | quotientSign));
7979
8080 // one or both of a or b is denormal, the other (if applicable) is a
8181 // normal number. Renormalize one or both of a and b, and set scale to
......@@ -83,13 +83,13 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
8383 if (aAbs < integerBit) scale +%= normalize(T, &aSignificand);
8484 if (bAbs < integerBit) scale -%= normalize(T, &bSignificand);
8585 }
86 var quotientExponent: i32 = @bitCast(i32, aExponent -% bExponent) +% scale;
86 var quotientExponent: i32 = @as(i32, @bitCast(aExponent -% bExponent)) +% scale;
8787
8888 // Align the significand of b as a Q63 fixed-point number in the range
8989 // [1, 2.0) and get a Q64 approximate reciprocal using a small minimax
9090 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
9191 // is accurate to about 3.5 binary digits.
92 const q63b = @intCast(u64, bSignificand);
92 const q63b = @as(u64, @intCast(bSignificand));
9393 var recip64 = @as(u64, 0x7504f333F9DE6484) -% q63b;
9494 // 0x7504f333F9DE6484 / 2^64 + 1 = 3/4 + 1/sqrt(2)
9595
......@@ -100,16 +100,16 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
100100 // This doubles the number of correct binary digits in the approximation
101101 // with each iteration.
102102 var correction64: u64 = undefined;
103 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);
104 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);
105 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);
106 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);
107 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);
108 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);
109 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);
110 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);
111 correction64 = @truncate(u64, ~(@as(u128, recip64) *% q63b >> 64) +% 1);
112 recip64 = @truncate(u64, @as(u128, recip64) *% correction64 >> 63);
103 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
104 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
105 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
106 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
107 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
108 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
109 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
110 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
111 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));
112 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));
113113
114114 // The reciprocal may have overflowed to zero if the upper half of b is
115115 // exactly 1.0. This would sabatoge the full-width final stage of the
......@@ -128,8 +128,8 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
128128
129129 correction = -%correction;
130130
131 const cHi = @truncate(u64, correction >> 64);
132 const cLo = @truncate(u64, correction);
131 const cHi = @as(u64, @truncate(correction >> 64));
132 const cLo = @as(u64, @truncate(correction));
133133
134134 var r64cH: u128 = undefined;
135135 var r64cL: u128 = undefined;
......@@ -164,8 +164,8 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
164164 // exponent accordingly.
165165 var quotient: u64 = if (quotient128 < (integerBit << 1)) b: {
166166 quotientExponent -= 1;
167 break :b @intCast(u64, quotient128);
168 } else @intCast(u64, quotient128 >> 1);
167 break :b @as(u64, @intCast(quotient128));
168 } else @as(u64, @intCast(quotient128 >> 1));
169169
170170 // We are going to compute a residual of the form
171171 //
......@@ -182,26 +182,26 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
182182 const writtenExponent = quotientExponent + exponentBias;
183183 if (writtenExponent >= maxExponent) {
184184 // If we have overflowed the exponent, return infinity.
185 return @bitCast(T, infRep | quotientSign);
185 return @as(T, @bitCast(infRep | quotientSign));
186186 } else if (writtenExponent < 1) {
187187 if (writtenExponent == 0) {
188188 // Check whether the rounded result is normal.
189189 if (residual > (bSignificand >> 1)) { // round
190190 if (quotient == (integerBit - 1)) // If the rounded result is normal, return it
191 return @bitCast(T, @bitCast(Z, std.math.floatMin(T)) | quotientSign);
191 return @as(T, @bitCast(@as(Z, @bitCast(std.math.floatMin(T))) | quotientSign));
192192 }
193193 }
194194 // Flush denormals to zero. In the future, it would be nice to add
195195 // code to round them correctly.
196 return @bitCast(T, quotientSign);
196 return @as(T, @bitCast(quotientSign));
197197 } else {
198198 const round = @intFromBool(residual > (bSignificand >> 1));
199199 // Insert the exponent
200 var absResult = quotient | (@intCast(Z, writtenExponent) << significandBits);
200 var absResult = quotient | (@as(Z, @intCast(writtenExponent)) << significandBits);
201201 // Round
202202 absResult +%= round;
203203 // Insert the sign and return
204 return @bitCast(T, absResult | quotientSign | integerBit);
204 return @as(T, @bitCast(absResult | quotientSign | integerBit));
205205 }
206206}
207207
lib/compiler_rt/divxf3_test.zig+4-4
......@@ -5,11 +5,11 @@ const testing = std.testing;
55const __divxf3 = @import("divxf3.zig").__divxf3;
66
77fn compareResult(result: f80, expected: u80) bool {
8 const rep = @bitCast(u80, result);
8 const rep = @as(u80, @bitCast(result));
99
1010 if (rep == expected) return true;
1111 // 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
1414 return false;
1515}
......@@ -25,9 +25,9 @@ fn test__divxf3(a: f80, b: f80) !void {
2525 const x = __divxf3(a, b);
2626
2727 // Next float (assuming normal, non-zero result)
28 const x_plus_eps = @bitCast(f80, (@bitCast(u80, x) + 1) | integerBit);
28 const x_plus_eps = @as(f80, @bitCast((@as(u80, @bitCast(x)) + 1) | integerBit));
2929 // 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
3232 // Make sure result is more accurate than the adjacent floats
3333 const err_x = @fabs(@mulAdd(f80, x, b, -a));
lib/compiler_rt/emutls.zig+19-38
......@@ -33,18 +33,14 @@ pub fn __emutls_get_address(control: *emutls_control) callconv(.C) *anyopaque {
3333const simple_allocator = struct {
3434 /// Allocate a memory chunk for requested type. Return a pointer on the data.
3535 pub fn alloc(comptime T: type) *T {
36 return @ptrCast(*T, @alignCast(
37 @alignOf(T),
38 advancedAlloc(@alignOf(T), @sizeOf(T)),
39 ));
36 return @ptrCast(@alignCast(advancedAlloc(@alignOf(T), @sizeOf(T))));
4037 }
4138
4239 /// Allocate a slice of T, with len elements.
4340 pub fn allocSlice(comptime T: type, len: usize) []T {
44 return @ptrCast([*]T, @alignCast(
45 @alignOf(T),
41 return @as([*]T, @ptrCast(@alignCast(
4642 advancedAlloc(@alignOf(T), @sizeOf(T) * len),
47 ))[0 .. len - 1];
43 )))[0 .. len - 1];
4844 }
4945
5046 /// Allocate a memory chunk.
......@@ -56,22 +52,19 @@ const simple_allocator = struct {
5652 abort();
5753 }
5854
59 return @ptrCast([*]u8, aligned_ptr);
55 return @as([*]u8, @ptrCast(aligned_ptr));
6056 }
6157
6258 /// Resize a slice.
6359 pub fn reallocSlice(comptime T: type, slice: []T, len: usize) []T {
64 var c_ptr: *anyopaque = @ptrCast(*anyopaque, slice.ptr);
65 var new_array: [*]T = @ptrCast([*]T, @alignCast(
66 @alignOf(T),
67 std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort(),
68 ));
60 var c_ptr: *anyopaque = @as(*anyopaque, @ptrCast(slice.ptr));
61 var new_array: [*]T = @ptrCast(@alignCast(std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort()));
6962 return new_array[0..len];
7063 }
7164
7265 /// Free a memory chunk allocated with simple_allocator.
7366 pub fn free(ptr: anytype) void {
74 std.c.free(@ptrCast(*anyopaque, ptr));
67 std.c.free(@as(*anyopaque, @ptrCast(ptr)));
7568 }
7669};
7770
......@@ -132,20 +125,20 @@ const ObjectArray = struct {
132125 if (self.slots[index] == null) {
133126 // initialize the slot
134127 const size = control.size;
135 const alignment = @truncate(u29, control.alignment);
128 const alignment = @as(u29, @truncate(control.alignment));
136129
137130 var data = simple_allocator.advancedAlloc(alignment, size);
138131 errdefer simple_allocator.free(data);
139132
140133 if (control.default_value) |value| {
141134 // 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)));
143136 } else {
144137 // no default: return zeroed memory.
145138 @memset(data[0..size], 0);
146139 }
147140
148 self.slots[index] = @ptrCast(*anyopaque, data);
141 self.slots[index] = @as(*anyopaque, @ptrCast(data));
149142 }
150143
151144 return self.slots[index].?;
......@@ -180,18 +173,12 @@ const current_thread_storage = struct {
180173
181174 /// Return casted thread specific value.
182175 fn getspecific() ?*ObjectArray {
183 return @ptrCast(
184 ?*ObjectArray,
185 @alignCast(
186 @alignOf(ObjectArray),
187 std.c.pthread_getspecific(current_thread_storage.key),
188 ),
189 );
176 return @ptrCast(@alignCast(std.c.pthread_getspecific(current_thread_storage.key)));
190177 }
191178
192179 /// Set casted thread specific value.
193180 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) {
195182 abort();
196183 }
197184 }
......@@ -205,10 +192,7 @@ const current_thread_storage = struct {
205192
206193 /// Invoked by pthread specific destructor. the passed argument is the ObjectArray pointer.
207194 fn deinit(arrayPtr: *anyopaque) callconv(.C) void {
208 var array = @ptrCast(
209 *ObjectArray,
210 @alignCast(@alignOf(ObjectArray), arrayPtr),
211 );
195 var array: *ObjectArray = @ptrCast(@alignCast(arrayPtr));
212196 array.deinit();
213197 }
214198};
......@@ -294,7 +278,7 @@ const emutls_control = extern struct {
294278 .size = @sizeOf(T),
295279 .alignment = @alignOf(T),
296280 .object = .{ .index = 0 },
297 .default_value = @ptrCast(?*const anyopaque, default_value),
281 .default_value = @as(?*const anyopaque, @ptrCast(default_value)),
298282 };
299283 }
300284
......@@ -313,10 +297,7 @@ const emutls_control = extern struct {
313297 pub fn get_typed_pointer(self: *emutls_control, comptime T: type) *T {
314298 assert(self.size == @sizeOf(T));
315299 assert(self.alignment == @alignOf(T));
316 return @ptrCast(
317 *T,
318 @alignCast(@alignOf(T), self.getPointer()),
319 );
300 return @ptrCast(@alignCast(self.getPointer()));
320301 }
321302};
322303
......@@ -343,7 +324,7 @@ test "__emutls_get_address zeroed" {
343324 try expect(ctl.object.index == 0);
344325
345326 // 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)));
347328 try expect(ctl.object.index != 0); // index has been allocated for this ctl
348329 try expect(x.* == 0); // storage has been zeroed
349330
......@@ -351,7 +332,7 @@ test "__emutls_get_address zeroed" {
351332 x.* = 1234;
352333
353334 // 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
356337 try expect(y.* == 1234); // same content that x.*
357338 try expect(x == y); // same pointer
......@@ -364,7 +345,7 @@ test "__emutls_get_address with default_value" {
364345 var ctl = emutls_control.init(usize, &value);
365346 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)));
368349 try expect(ctl.object.index != 0);
369350 try expect(x.* == 5678); // storage initialized with default value
370351
......@@ -373,7 +354,7 @@ test "__emutls_get_address with default_value" {
373354
374355 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)));
377358 try expect(y.* == 9012); // the modified storage persists
378359}
379360
lib/compiler_rt/exp.zig+11-11
......@@ -27,7 +27,7 @@ comptime {
2727
2828pub fn __exph(a: f16) callconv(.C) f16 {
2929 // TODO: more efficient implementation
30 return @floatCast(f16, expf(a));
30 return @as(f16, @floatCast(expf(a)));
3131}
3232
3333pub fn expf(x_: f32) callconv(.C) f32 {
......@@ -39,8 +39,8 @@ pub fn expf(x_: f32) callconv(.C) f32 {
3939 const P2 = -2.7667332906e-3;
4040
4141 var x = x_;
42 var hx = @bitCast(u32, x);
43 const sign = @intCast(i32, hx >> 31);
42 var hx = @as(u32, @bitCast(x));
43 const sign = @as(i32, @intCast(hx >> 31));
4444 hx &= 0x7FFFFFFF;
4545
4646 if (math.isNan(x)) {
......@@ -74,12 +74,12 @@ pub fn expf(x_: f32) callconv(.C) f32 {
7474 if (hx > 0x3EB17218) {
7575 // |x| > 1.5 * ln2
7676 if (hx > 0x3F851592) {
77 k = @intFromFloat(i32, invln2 * x + half[@intCast(usize, sign)]);
77 k = @as(i32, @intFromFloat(invln2 * x + half[@as(usize, @intCast(sign))]));
7878 } else {
7979 k = 1 - sign - sign;
8080 }
8181
82 const fk = @floatFromInt(f32, k);
82 const fk = @as(f32, @floatFromInt(k));
8383 hi = x - fk * ln2hi;
8484 lo = fk * ln2lo;
8585 x = hi - lo;
......@@ -117,9 +117,9 @@ pub fn exp(x_: f64) callconv(.C) f64 {
117117 const P5: f64 = 4.13813679705723846039e-08;
118118
119119 var x = x_;
120 var ux = @bitCast(u64, x);
120 var ux = @as(u64, @bitCast(x));
121121 var hx = ux >> 32;
122 const sign = @intCast(i32, hx >> 31);
122 const sign = @as(i32, @intCast(hx >> 31));
123123 hx &= 0x7FFFFFFF;
124124
125125 if (math.isNan(x)) {
......@@ -157,12 +157,12 @@ pub fn exp(x_: f64) callconv(.C) f64 {
157157 if (hx > 0x3FD62E42) {
158158 // |x| >= 1.5 * ln2
159159 if (hx > 0x3FF0A2B2) {
160 k = @intFromFloat(i32, invln2 * x + half[@intCast(usize, sign)]);
160 k = @as(i32, @intFromFloat(invln2 * x + half[@as(usize, @intCast(sign))]));
161161 } else {
162162 k = 1 - sign - sign;
163163 }
164164
165 const dk = @floatFromInt(f64, k);
165 const dk = @as(f64, @floatFromInt(k));
166166 hi = x - dk * ln2hi;
167167 lo = dk * ln2lo;
168168 x = hi - lo;
......@@ -191,12 +191,12 @@ pub fn exp(x_: f64) callconv(.C) f64 {
191191
192192pub fn __expx(a: f80) callconv(.C) f80 {
193193 // TODO: more efficient implementation
194 return @floatCast(f80, expq(a));
194 return @as(f80, @floatCast(expq(a)));
195195}
196196
197197pub fn expq(a: f128) callconv(.C) f128 {
198198 // TODO: more correct implementation
199 return exp(@floatCast(f64, a));
199 return exp(@as(f64, @floatCast(a)));
200200}
201201
202202pub fn expl(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/exp2.zig+19-19
......@@ -27,18 +27,18 @@ comptime {
2727
2828pub fn __exp2h(x: f16) callconv(.C) f16 {
2929 // TODO: more efficient implementation
30 return @floatCast(f16, exp2f(x));
30 return @as(f16, @floatCast(exp2f(x)));
3131}
3232
3333pub fn exp2f(x: f32) callconv(.C) f32 {
34 const tblsiz = @intCast(u32, exp2ft.len);
35 const redux: f32 = 0x1.8p23 / @floatFromInt(f32, tblsiz);
34 const tblsiz = @as(u32, @intCast(exp2ft.len));
35 const redux: f32 = 0x1.8p23 / @as(f32, @floatFromInt(tblsiz));
3636 const P1: f32 = 0x1.62e430p-1;
3737 const P2: f32 = 0x1.ebfbe0p-3;
3838 const P3: f32 = 0x1.c6b348p-5;
3939 const P4: f32 = 0x1.3b2c9cp-7;
4040
41 var u = @bitCast(u32, x);
41 var u = @as(u32, @bitCast(x));
4242 const ix = u & 0x7FFFFFFF;
4343
4444 // |x| > 126
......@@ -72,32 +72,32 @@ pub fn exp2f(x: f32) callconv(.C) f32 {
7272 // intended result but should confirm how GCC/Clang handle this to ensure.
7373
7474 var uf = x + redux;
75 var i_0 = @bitCast(u32, uf);
75 var i_0 = @as(u32, @bitCast(uf));
7676 i_0 +%= tblsiz / 2;
7777
7878 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));
8080 i_0 &= tblsiz - 1;
8181 uf -= redux;
8282
8383 const z: f64 = x - uf;
84 var r: f64 = exp2ft[@intCast(usize, i_0)];
84 var r: f64 = exp2ft[@as(usize, @intCast(i_0))];
8585 const t: f64 = r * z;
8686 r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4);
87 return @floatCast(f32, r * uk);
87 return @as(f32, @floatCast(r * uk));
8888}
8989
9090pub fn exp2(x: f64) callconv(.C) f64 {
91 const tblsiz: u32 = @intCast(u32, exp2dt.len / 2);
92 const redux: f64 = 0x1.8p52 / @floatFromInt(f64, tblsiz);
91 const tblsiz: u32 = @as(u32, @intCast(exp2dt.len / 2));
92 const redux: f64 = 0x1.8p52 / @as(f64, @floatFromInt(tblsiz));
9393 const P1: f64 = 0x1.62e42fefa39efp-1;
9494 const P2: f64 = 0x1.ebfbdff82c575p-3;
9595 const P3: f64 = 0x1.c6b08d704a0a6p-5;
9696 const P4: f64 = 0x1.3b2ab88f70400p-7;
9797 const P5: f64 = 0x1.5d88003875c74p-10;
9898
99 const ux = @bitCast(u64, x);
100 const ix = @intCast(u32, ux >> 32) & 0x7FFFFFFF;
99 const ux = @as(u64, @bitCast(x));
100 const ix = @as(u32, @intCast(ux >> 32)) & 0x7FFFFFFF;
101101
102102 // TODO: This should be handled beneath.
103103 if (math.isNan(x)) {
......@@ -119,7 +119,7 @@ pub fn exp2(x: f64) callconv(.C) f64 {
119119 if (ux >> 63 != 0) {
120120 // underflow
121121 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)));
123123 }
124124 if (x <= -1075) {
125125 return 0;
......@@ -139,18 +139,18 @@ pub fn exp2(x: f64) callconv(.C) f64 {
139139 // reduce x
140140 var uf: f64 = x + redux;
141141 // NOTE: musl performs an implicit 64-bit to 32-bit u32 truncation here
142 var i_0: u32 = @truncate(u32, @bitCast(u64, uf));
142 var i_0: u32 = @as(u32, @truncate(@as(u64, @bitCast(uf))));
143143 i_0 +%= tblsiz / 2;
144144
145145 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);
147147 i_0 %= tblsiz;
148148 uf -= redux;
149149
150150 // r = exp2(y) = exp2t[i_0] * p(z - eps[i])
151151 var z: f64 = x - uf;
152 const t: f64 = exp2dt[@intCast(usize, 2 * i_0)];
153 z -= exp2dt[@intCast(usize, 2 * i_0 + 1)];
152 const t: f64 = exp2dt[@as(usize, @intCast(2 * i_0))];
153 z -= exp2dt[@as(usize, @intCast(2 * i_0 + 1))];
154154 const r: f64 = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5))));
155155
156156 return math.scalbn(r, ik);
......@@ -158,12 +158,12 @@ pub fn exp2(x: f64) callconv(.C) f64 {
158158
159159pub fn __exp2x(x: f80) callconv(.C) f80 {
160160 // TODO: more efficient implementation
161 return @floatCast(f80, exp2q(x));
161 return @as(f80, @floatCast(exp2q(x)));
162162}
163163
164164pub fn exp2q(x: f128) callconv(.C) f128 {
165165 // TODO: more correct implementation
166 return exp2(@floatCast(f64, x));
166 return exp2(@as(f64, @floatCast(x)));
167167}
168168
169169pub fn exp2l(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/extenddftf2.zig+2-2
......@@ -13,9 +13,9 @@ comptime {
1313}
1414
1515pub fn __extenddftf2(a: f64) callconv(.C) f128 {
16 return extendf(f128, f64, @bitCast(u64, a));
16 return extendf(f128, f64, @as(u64, @bitCast(a)));
1717}
1818
1919fn _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)));
2121}
lib/compiler_rt/extenddfxf2.zig+1-1
......@@ -8,5 +8,5 @@ comptime {
88}
99
1010pub fn __extenddfxf2(a: f64) callconv(.C) f80 {
11 return extend_f80(f64, @bitCast(u64, a));
11 return extend_f80(f64, @as(u64, @bitCast(a)));
1212}
lib/compiler_rt/extendf.zig+7-7
......@@ -33,7 +33,7 @@ pub inline fn extendf(
3333 const dstMinNormal: dst_rep_t = @as(dst_rep_t, 1) << dstSigBits;
3434
3535 // Break a into a sign and representation of the absolute value
36 const aRep: src_rep_t = @bitCast(src_rep_t, a);
36 const aRep: src_rep_t = @as(src_rep_t, @bitCast(a));
3737 const aAbs: src_rep_t = aRep & srcAbsMask;
3838 const sign: src_rep_t = aRep & srcSignMask;
3939 var absResult: dst_rep_t = undefined;
......@@ -58,10 +58,10 @@ pub inline fn extendf(
5858 // the correct adjusted exponent in the destination type.
5959 const scale: u32 = @clz(aAbs) -
6060 @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));
6262 absResult ^= dstMinNormal;
6363 const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1;
64 absResult |= @intCast(dst_rep_t, resultExponent) << dstSigBits;
64 absResult |= @as(dst_rep_t, @intCast(resultExponent)) << dstSigBits;
6565 } else {
6666 // a is zero.
6767 absResult = 0;
......@@ -69,7 +69,7 @@ pub inline fn extendf(
6969
7070 // Apply the signbit to (dst_t)abs(a).
7171 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));
7373}
7474
7575pub 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
104104 // a is a normal number.
105105 // Extend to the destination type by shifting the significand and
106106 // exponent into the proper position and rebiasing the exponent.
107 dst.exp = @intCast(u16, a_abs >> src_sig_bits);
107 dst.exp = @as(u16, @intCast(a_abs >> src_sig_bits));
108108 dst.exp += dst_exp_bias - src_exp_bias;
109109 dst.fraction = @as(u64, a_abs) << (dst_sig_bits - src_sig_bits);
110110 dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers
......@@ -124,9 +124,9 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI
124124 const scale: u16 = @clz(a_abs) -
125125 @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));
128128 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))));
130130 dst.exp ^= 1;
131131 dst.exp |= dst_exp_bias - src_exp_bias - scale + 1;
132132 } else {
lib/compiler_rt/extendf_test.zig+21-21
......@@ -11,12 +11,12 @@ const F16T = @import("./common.zig").F16T;
1111fn test__extenddfxf2(a: f64, expected: u80) !void {
1212 const x = __extenddfxf2(a);
1313
14 const rep = @bitCast(u80, x);
14 const rep = @as(u80, @bitCast(x));
1515 if (rep == expected)
1616 return;
1717
1818 // 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))
2020 return;
2121
2222 @panic("__extenddfxf2 test failure");
......@@ -25,9 +25,9 @@ fn test__extenddfxf2(a: f64, expected: u80) !void {
2525fn test__extenddftf2(a: f64, expected_hi: u64, expected_lo: u64) !void {
2626 const x = __extenddftf2(a);
2727
28 const rep = @bitCast(u128, x);
29 const hi = @intCast(u64, rep >> 64);
30 const lo = @truncate(u64, rep);
28 const rep = @as(u128, @bitCast(x));
29 const hi = @as(u64, @intCast(rep >> 64));
30 const lo = @as(u64, @truncate(rep));
3131
3232 if (hi == expected_hi and lo == expected_lo)
3333 return;
......@@ -45,14 +45,14 @@ fn test__extenddftf2(a: f64, expected_hi: u64, expected_lo: u64) !void {
4545}
4646
4747fn test__extendhfsf2(a: u16, expected: u32) !void {
48 const x = __extendhfsf2(@bitCast(F16T(f32), a));
49 const rep = @bitCast(u32, x);
48 const x = __extendhfsf2(@as(F16T(f32), @bitCast(a)));
49 const rep = @as(u32, @bitCast(x));
5050
5151 if (rep == expected) {
5252 if (rep & 0x7fffffff > 0x7f800000) {
5353 return; // NaN is always unequal.
5454 }
55 if (x == @bitCast(f32, expected)) {
55 if (x == @as(f32, @bitCast(expected))) {
5656 return;
5757 }
5858 }
......@@ -63,9 +63,9 @@ fn test__extendhfsf2(a: u16, expected: u32) !void {
6363fn test__extendsftf2(a: f32, expected_hi: u64, expected_lo: u64) !void {
6464 const x = __extendsftf2(a);
6565
66 const rep = @bitCast(u128, x);
67 const hi = @intCast(u64, rep >> 64);
68 const lo = @truncate(u64, rep);
66 const rep = @as(u128, @bitCast(x));
67 const hi = @as(u64, @intCast(rep >> 64));
68 const lo = @as(u64, @truncate(rep));
6969
7070 if (hi == expected_hi and lo == expected_lo)
7171 return;
......@@ -184,35 +184,35 @@ test "extendsftf2" {
184184}
185185
186186fn makeQNaN64() f64 {
187 return @bitCast(f64, @as(u64, 0x7ff8000000000000));
187 return @as(f64, @bitCast(@as(u64, 0x7ff8000000000000)));
188188}
189189
190190fn makeInf64() f64 {
191 return @bitCast(f64, @as(u64, 0x7ff0000000000000));
191 return @as(f64, @bitCast(@as(u64, 0x7ff0000000000000)));
192192}
193193
194194fn makeNaN64(rand: u64) f64 {
195 return @bitCast(f64, 0x7ff0000000000000 | (rand & 0xfffffffffffff));
195 return @as(f64, @bitCast(0x7ff0000000000000 | (rand & 0xfffffffffffff)));
196196}
197197
198198fn makeQNaN32() f32 {
199 return @bitCast(f32, @as(u32, 0x7fc00000));
199 return @as(f32, @bitCast(@as(u32, 0x7fc00000)));
200200}
201201
202202fn makeNaN32(rand: u32) f32 {
203 return @bitCast(f32, 0x7f800000 | (rand & 0x7fffff));
203 return @as(f32, @bitCast(0x7f800000 | (rand & 0x7fffff)));
204204}
205205
206206fn makeInf32() f32 {
207 return @bitCast(f32, @as(u32, 0x7f800000));
207 return @as(f32, @bitCast(@as(u32, 0x7f800000)));
208208}
209209
210210fn 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);
214 const hi = @intCast(u64, rep >> 64);
215 const lo = @truncate(u64, rep);
213 const rep = @as(u128, @bitCast(x));
214 const hi = @as(u64, @intCast(rep >> 64));
215 const lo = @as(u64, @truncate(rep));
216216
217217 if (hi == expected_hi and lo == expected_lo)
218218 return;
lib/compiler_rt/extendhfdf2.zig+1-1
......@@ -8,5 +8,5 @@ comptime {
88}
99
1010pub 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)));
1212}
lib/compiler_rt/extendhfsf2.zig+3-3
......@@ -13,13 +13,13 @@ comptime {
1313}
1414
1515pub 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)));
1717}
1818
1919fn __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)));
2121}
2222
2323fn __aeabi_h2f(a: u16) callconv(.AAPCS) f32 {
24 return extendf(f32, f16, @bitCast(u16, a));
24 return extendf(f32, f16, @as(u16, @bitCast(a)));
2525}
lib/compiler_rt/extendhftf2.zig+1-1
......@@ -8,5 +8,5 @@ comptime {
88}
99
1010pub 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)));
1212}
lib/compiler_rt/extendhfxf2.zig+1-1
......@@ -8,5 +8,5 @@ comptime {
88}
99
1010fn __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)));
1212}
lib/compiler_rt/extendsfdf2.zig+2-2
......@@ -12,9 +12,9 @@ comptime {
1212}
1313
1414fn __extendsfdf2(a: f32) callconv(.C) f64 {
15 return extendf(f64, f32, @bitCast(u32, a));
15 return extendf(f64, f32, @as(u32, @bitCast(a)));
1616}
1717
1818fn __aeabi_f2d(a: f32) callconv(.AAPCS) f64 {
19 return extendf(f64, f32, @bitCast(u32, a));
19 return extendf(f64, f32, @as(u32, @bitCast(a)));
2020}
lib/compiler_rt/extendsftf2.zig+2-2
......@@ -13,9 +13,9 @@ comptime {
1313}
1414
1515pub fn __extendsftf2(a: f32) callconv(.C) f128 {
16 return extendf(f128, f32, @bitCast(u32, a));
16 return extendf(f128, f32, @as(u32, @bitCast(a)));
1717}
1818
1919fn _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)));
2121}
lib/compiler_rt/extendsfxf2.zig+1-1
......@@ -8,5 +8,5 @@ comptime {
88}
99
1010fn __extendsfxf2(a: f32) callconv(.C) f80 {
11 return extend_f80(f32, @bitCast(u32, a));
11 return extend_f80(f32, @as(u32, @bitCast(a)));
1212}
lib/compiler_rt/extendxftf2.zig+2-2
......@@ -39,12 +39,12 @@ fn __extendxftf2(a: f80) callconv(.C) f128 {
3939 // renormalize the significand and clear the leading bit and integer part,
4040 // then insert the correct adjusted exponent in the destination type.
4141 const scale: u32 = @clz(a_rep.fraction);
42 abs_result = @as(u128, a_rep.fraction) << @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));
4343 abs_result ^= dst_min_normal;
4444 abs_result |= @as(u128, scale + 1) << dst_sig_bits;
4545 }
4646
4747 // Apply the signbit to (dst_t)abs(a).
4848 const result: u128 align(@alignOf(f128)) = abs_result | @as(u128, sign) << (dst_bits - 16);
49 return @bitCast(f128, result);
49 return @as(f128, @bitCast(result));
5050}
lib/compiler_rt/fabs.zig+2-2
......@@ -51,7 +51,7 @@ pub fn fabsl(x: c_longdouble) callconv(.C) c_longdouble {
5151inline fn generic_fabs(x: anytype) @TypeOf(x) {
5252 const T = @TypeOf(x);
5353 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
54 const float_bits = @bitCast(TBits, x);
54 const float_bits = @as(TBits, @bitCast(x));
5555 const remove_sign = ~@as(TBits, 0) >> 1;
56 return @bitCast(T, float_bits & remove_sign);
56 return @as(T, @bitCast(float_bits & remove_sign));
5757}
lib/compiler_rt/ffsdi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const ffs = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ffsdi2(a: u64, expected: i32) !void {
5 var x = @bitCast(i64, a);
5 var x = @as(i64, @bitCast(a));
66 var result = ffs.__ffsdi2(x);
77 try testing.expectEqual(expected, result);
88}
lib/compiler_rt/ffssi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const ffs = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ffssi2(a: u32, expected: i32) !void {
5 var x = @bitCast(i32, a);
5 var x = @as(i32, @bitCast(a));
66 var result = ffs.__ffssi2(x);
77 try testing.expectEqual(expected, result);
88}
lib/compiler_rt/ffsti2_test.zig+1-1
......@@ -2,7 +2,7 @@ const ffs = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ffsti2(a: u128, expected: i32) !void {
5 var x = @bitCast(i128, a);
5 var x = @as(i128, @bitCast(a));
66 var result = ffs.__ffsti2(x);
77 try testing.expectEqual(expected, result);
88}
lib/compiler_rt/fixdfti.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __fixdfti(a: f64) callconv(.C) i128 {
1919const v2u64 = @Vector(2, u64);
2020
2121fn __fixdfti_windows_x86_64(a: f64) callconv(.C) v2u64 {
22 return @bitCast(v2u64, intFromFloat(i128, a));
22 return @as(v2u64, @bitCast(intFromFloat(i128, a)));
2323}
lib/compiler_rt/fixhfti.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __fixhfti(a: f16) callconv(.C) i128 {
1919const v2u64 = @Vector(2, u64);
2020
2121fn __fixhfti_windows_x86_64(a: f16) callconv(.C) v2u64 {
22 return @bitCast(v2u64, intFromFloat(i128, a));
22 return @as(v2u64, @bitCast(intFromFloat(i128, a)));
2323}
lib/compiler_rt/fixsfti.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __fixsfti(a: f32) callconv(.C) i128 {
1919const v2u64 = @Vector(2, u64);
2020
2121fn __fixsfti_windows_x86_64(a: f32) callconv(.C) v2u64 {
22 return @bitCast(v2u64, intFromFloat(i128, a));
22 return @as(v2u64, @bitCast(intFromFloat(i128, a)));
2323}
lib/compiler_rt/fixtfti.zig+1-1
......@@ -21,5 +21,5 @@ pub fn __fixtfti(a: f128) callconv(.C) i128 {
2121const v2u64 = @Vector(2, u64);
2222
2323fn __fixtfti_windows_x86_64(a: f128) callconv(.C) v2u64 {
24 return @bitCast(v2u64, intFromFloat(i128, a));
24 return @as(v2u64, @bitCast(intFromFloat(i128, a)));
2525}
lib/compiler_rt/fixunsdfti.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __fixunsdfti(a: f64) callconv(.C) u128 {
1919const v2u64 = @Vector(2, u64);
2020
2121fn __fixunsdfti_windows_x86_64(a: f64) callconv(.C) v2u64 {
22 return @bitCast(v2u64, intFromFloat(u128, a));
22 return @as(v2u64, @bitCast(intFromFloat(u128, a)));
2323}
lib/compiler_rt/fixunshfti.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __fixunshfti(a: f16) callconv(.C) u128 {
1919const v2u64 = @Vector(2, u64);
2020
2121fn __fixunshfti_windows_x86_64(a: f16) callconv(.C) v2u64 {
22 return @bitCast(v2u64, intFromFloat(u128, a));
22 return @as(v2u64, @bitCast(intFromFloat(u128, a)));
2323}
lib/compiler_rt/fixunssfti.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __fixunssfti(a: f32) callconv(.C) u128 {
1919const v2u64 = @Vector(2, u64);
2020
2121fn __fixunssfti_windows_x86_64(a: f32) callconv(.C) v2u64 {
22 return @bitCast(v2u64, intFromFloat(u128, a));
22 return @as(v2u64, @bitCast(intFromFloat(u128, a)));
2323}
lib/compiler_rt/fixunstfti.zig+1-1
......@@ -21,5 +21,5 @@ pub fn __fixunstfti(a: f128) callconv(.C) u128 {
2121const v2u64 = @Vector(2, u64);
2222
2323fn __fixunstfti_windows_x86_64(a: f128) callconv(.C) v2u64 {
24 return @bitCast(v2u64, intFromFloat(u128, a));
24 return @as(v2u64, @bitCast(intFromFloat(u128, a)));
2525}
lib/compiler_rt/fixunsxfti.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __fixunsxfti(a: f80) callconv(.C) u128 {
1919const v2u64 = @Vector(2, u64);
2020
2121fn __fixunsxfti_windows_x86_64(a: f80) callconv(.C) v2u64 {
22 return @bitCast(v2u64, intFromFloat(u128, a));
22 return @as(v2u64, @bitCast(intFromFloat(u128, a)));
2323}
lib/compiler_rt/fixxfti.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __fixxfti(a: f80) callconv(.C) i128 {
1919const v2u64 = @Vector(2, u64);
2020
2121fn __fixxfti_windows_x86_64(a: f80) callconv(.C) v2u64 {
22 return @bitCast(v2u64, intFromFloat(i128, a));
22 return @as(v2u64, @bitCast(intFromFloat(i128, a)));
2323}
lib/compiler_rt/float_from_int.zig+6-6
......@@ -25,17 +25,17 @@ pub fn floatFromInt(comptime T: type, x: anytype) T {
2525 // Compute significand
2626 var exp = int_bits - @clz(abs_val) - 1;
2727 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
3030 // 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);
3232 result ^= implicit_bit; // Remove implicit integer bit
3333 } else {
34 var shift_amt = @intCast(math.Log2Int(Z), exp - fractional_bits);
34 var shift_amt = @as(math.Log2Int(Z), @intCast(exp - fractional_bits));
3535 const exact_tie: bool = @ctz(abs_val) == shift_amt - 1;
3636
3737 // Shift down result and remove implicit integer bit
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
4040 // Round result, including round-to-even for exact ties
4141 result = ((result + 1) >> 1) & ~@as(uT, @intFromBool(exact_tie));
......@@ -43,14 +43,14 @@ pub fn floatFromInt(comptime T: type, x: anytype) T {
4343
4444 // Compute exponent
4545 if ((int_bits > max_exp) and (exp > max_exp)) // If exponent too large, overflow to infinity
46 return @bitCast(T, sign_bit | @bitCast(uT, inf));
46 return @as(T, @bitCast(sign_bit | @as(uT, @bitCast(inf))));
4747
4848 result += (@as(uT, exp) + exp_bias) << math.floatMantissaBits(T);
4949
5050 // If the result included a carry, we need to restore the explicit integer bit
5151 if (T == f80) result |= 1 << fractional_bits;
5252
53 return @bitCast(T, sign_bit | result);
53 return @as(T, @bitCast(sign_bit | result));
5454}
5555
5656test {
lib/compiler_rt/float_from_int_test.zig+48-48
......@@ -30,12 +30,12 @@ const __floatuntitf = @import("floatuntitf.zig").__floatuntitf;
3030
3131fn test__floatsisf(a: i32, expected: u32) !void {
3232 const r = __floatsisf(a);
33 try std.testing.expect(@bitCast(u32, r) == expected);
33 try std.testing.expect(@as(u32, @bitCast(r)) == expected);
3434}
3535
3636fn test_one_floatunsisf(a: u32, expected: u32) !void {
3737 const r = __floatunsisf(a);
38 try std.testing.expect(@bitCast(u32, r) == expected);
38 try std.testing.expect(@as(u32, @bitCast(r)) == expected);
3939}
4040
4141test "floatsisf" {
......@@ -43,7 +43,7 @@ test "floatsisf" {
4343 try test__floatsisf(1, 0x3f800000);
4444 try test__floatsisf(-1, 0xbf800000);
4545 try test__floatsisf(0x7FFFFFFF, 0x4f000000);
46 try test__floatsisf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xcf000000);
46 try test__floatsisf(@as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 0xcf000000);
4747}
4848
4949test "floatunsisf" {
......@@ -72,10 +72,10 @@ test "floatdisf" {
7272 try test__floatdisf(-2, -2.0);
7373 try test__floatdisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
7474 try test__floatdisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
75 try test__floatdisf(@bitCast(i64, @as(u64, 0x8000008000000000)), -0x1.FFFFFEp+62);
76 try test__floatdisf(@bitCast(i64, @as(u64, 0x8000010000000000)), -0x1.FFFFFCp+62);
77 try test__floatdisf(@bitCast(i64, @as(u64, 0x8000000000000000)), -0x1.000000p+63);
78 try test__floatdisf(@bitCast(i64, @as(u64, 0x8000000000000001)), -0x1.000000p+63);
75 try test__floatdisf(@as(i64, @bitCast(@as(u64, 0x8000008000000000))), -0x1.FFFFFEp+62);
76 try test__floatdisf(@as(i64, @bitCast(@as(u64, 0x8000010000000000))), -0x1.FFFFFCp+62);
77 try test__floatdisf(@as(i64, @bitCast(@as(u64, 0x8000000000000000))), -0x1.000000p+63);
78 try test__floatdisf(@as(i64, @bitCast(@as(u64, 0x8000000000000001))), -0x1.000000p+63);
7979 try test__floatdisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
8080 try test__floatdisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
8181 try test__floatdisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
......@@ -228,17 +228,17 @@ test "floatuntisf" {
228228 try test__floatuntisf(make_uti(0x0000000000001FED, 0xCBE0000000000000), 0x1.FEDCBEp+76);
229229
230230 // Test overflow to infinity
231 try test__floatuntisf(@as(u128, math.maxInt(u128)), @bitCast(f32, math.inf(f32)));
231 try test__floatuntisf(@as(u128, math.maxInt(u128)), @as(f32, @bitCast(math.inf(f32))));
232232}
233233
234234fn test_one_floatsidf(a: i32, expected: u64) !void {
235235 const r = __floatsidf(a);
236 try std.testing.expect(@bitCast(u64, r) == expected);
236 try std.testing.expect(@as(u64, @bitCast(r)) == expected);
237237}
238238
239239fn test_one_floatunsidf(a: u32, expected: u64) !void {
240240 const r = __floatunsidf(a);
241 try std.testing.expect(@bitCast(u64, r) == expected);
241 try std.testing.expect(@as(u64, @bitCast(r)) == expected);
242242}
243243
244244test "floatsidf" {
......@@ -246,15 +246,15 @@ test "floatsidf" {
246246 try test_one_floatsidf(1, 0x3ff0000000000000);
247247 try test_one_floatsidf(-1, 0xbff0000000000000);
248248 try test_one_floatsidf(0x7FFFFFFF, 0x41dfffffffc00000);
249 try test_one_floatsidf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc1e0000000000000);
249 try test_one_floatsidf(@as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 0xc1e0000000000000);
250250}
251251
252252test "floatunsidf" {
253253 try test_one_floatunsidf(0, 0x0000000000000000);
254254 try test_one_floatunsidf(1, 0x3ff0000000000000);
255255 try test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000);
256 try test_one_floatunsidf(@intCast(u32, 0x80000000), 0x41e0000000000000);
257 try test_one_floatunsidf(@intCast(u32, 0xFFFFFFFF), 0x41efffffffe00000);
256 try test_one_floatunsidf(@as(u32, @intCast(0x80000000)), 0x41e0000000000000);
257 try test_one_floatunsidf(@as(u32, @intCast(0xFFFFFFFF)), 0x41efffffffe00000);
258258}
259259
260260fn test__floatdidf(a: i64, expected: f64) !void {
......@@ -279,12 +279,12 @@ test "floatdidf" {
279279 try test__floatdidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
280280 try test__floatdidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
281281 try test__floatdidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
282 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000008000000000)), -0x1.FFFFFEp+62);
283 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000800)), -0x1.FFFFFFFFFFFFEp+62);
284 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000010000000000)), -0x1.FFFFFCp+62);
285 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000001000)), -0x1.FFFFFFFFFFFFCp+62);
286 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000000)), -0x1.000000p+63);
287 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000001)), -0x1.000000p+63); // 0x8000000000000001
282 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000008000000000)))), -0x1.FFFFFEp+62);
283 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000000000000800)))), -0x1.FFFFFFFFFFFFEp+62);
284 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000010000000000)))), -0x1.FFFFFCp+62);
285 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000000000001000)))), -0x1.FFFFFFFFFFFFCp+62);
286 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000000000000000)))), -0x1.000000p+63);
287 try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000000000000001)))), -0x1.000000p+63); // 0x8000000000000001
288288 try test__floatdidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
289289 try test__floatdidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
290290 try test__floatdidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
......@@ -505,7 +505,7 @@ test "floatuntidf" {
505505
506506fn test__floatsitf(a: i32, expected: u128) !void {
507507 const r = __floatsitf(a);
508 try std.testing.expect(@bitCast(u128, r) == expected);
508 try std.testing.expect(@as(u128, @bitCast(r)) == expected);
509509}
510510
511511test "floatsitf" {
......@@ -513,16 +513,16 @@ test "floatsitf" {
513513 try test__floatsitf(0x7FFFFFFF, 0x401dfffffffc00000000000000000000);
514514 try test__floatsitf(0x12345678, 0x401b2345678000000000000000000000);
515515 try test__floatsitf(-0x12345678, 0xc01b2345678000000000000000000000);
516 try test__floatsitf(@bitCast(i32, @intCast(u32, 0xffffffff)), 0xbfff0000000000000000000000000000);
517 try test__floatsitf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc01e0000000000000000000000000000);
516 try test__floatsitf(@as(i32, @bitCast(@as(u32, @intCast(0xffffffff)))), 0xbfff0000000000000000000000000000);
517 try test__floatsitf(@as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 0xc01e0000000000000000000000000000);
518518}
519519
520520fn test__floatunsitf(a: u32, expected_hi: u64, expected_lo: u64) !void {
521521 const x = __floatunsitf(a);
522522
523 const x_repr = @bitCast(u128, x);
524 const x_hi = @intCast(u64, x_repr >> 64);
525 const x_lo = @truncate(u64, x_repr);
523 const x_repr = @as(u128, @bitCast(x));
524 const x_hi = @as(u64, @intCast(x_repr >> 64));
525 const x_lo = @as(u64, @truncate(x_repr));
526526
527527 if (x_hi == expected_hi and x_lo == expected_lo) {
528528 return;
......@@ -552,9 +552,9 @@ fn test__floatditf(a: i64, expected: f128) !void {
552552fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) !void {
553553 const x = __floatunditf(a);
554554
555 const x_repr = @bitCast(u128, x);
556 const x_hi = @intCast(u64, x_repr >> 64);
557 const x_lo = @truncate(u64, x_repr);
555 const x_repr = @as(u128, @bitCast(x));
556 const x_hi = @as(u64, @intCast(x_repr >> 64));
557 const x_lo = @as(u64, @truncate(x_repr));
558558
559559 if (x_hi == expected_hi and x_lo == expected_lo) {
560560 return;
......@@ -575,10 +575,10 @@ test "floatditf" {
575575 try test__floatditf(0x2, make_tf(0x4000000000000000, 0x0));
576576 try test__floatditf(0x1, make_tf(0x3fff000000000000, 0x0));
577577 try test__floatditf(0x0, make_tf(0x0, 0x0));
578 try test__floatditf(@bitCast(i64, @as(u64, 0xffffffffffffffff)), make_tf(0xbfff000000000000, 0x0));
579 try test__floatditf(@bitCast(i64, @as(u64, 0xfffffffffffffffe)), make_tf(0xc000000000000000, 0x0));
578 try test__floatditf(@as(i64, @bitCast(@as(u64, 0xffffffffffffffff))), make_tf(0xbfff000000000000, 0x0));
579 try test__floatditf(@as(i64, @bitCast(@as(u64, 0xfffffffffffffffe))), make_tf(0xc000000000000000, 0x0));
580580 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));
582582}
583583
584584test "floatunditf" {
......@@ -773,7 +773,7 @@ fn make_ti(high: u64, low: u64) i128 {
773773 var result: u128 = high;
774774 result <<= 64;
775775 result |= low;
776 return @bitCast(i128, result);
776 return @as(i128, @bitCast(result));
777777}
778778
779779fn make_uti(high: u64, low: u64) u128 {
......@@ -787,7 +787,7 @@ fn make_tf(high: u64, low: u64) f128 {
787787 var result: u128 = high;
788788 result <<= 64;
789789 result |= low;
790 return @bitCast(f128, result);
790 return @as(f128, @bitCast(result));
791791}
792792
793793test "conversion to f16" {
......@@ -815,22 +815,22 @@ test "conversion to f80" {
815815 const floatFromInt = @import("./float_from_int.zig").floatFromInt;
816816
817817 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);
819 try testing.expect(@intFromFloat(u80, floatFromInt(f80, @as(u80, math.maxInt(u64)) + 1)) == math.maxInt(u64) + 1);
818 try testing.expect(@as(u80, @intFromFloat(floatFromInt(f80, @as(u64, math.maxInt(u64)) + 0))) == math.maxInt(u64) + 0);
819 try testing.expect(@as(u80, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u64)) + 1))) == math.maxInt(u64) + 1);
820820
821821 try testing.expect(floatFromInt(f80, @as(u32, 0)) == 0.0);
822822 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));
824 try testing.expect(@intFromFloat(u128, 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); // Exact
826 try testing.expect(@intFromFloat(u128, 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 - Exact
828 try testing.expect(@intFromFloat(u128, floatFromInt(f80, @as(u80, math.maxInt(u64)) + 4)) == math.maxInt(u64) + 5); // Rounds up
829
830 try testing.expect(@intFromFloat(u128, 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); // Exact
832 try testing.expect(@intFromFloat(u128, 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 down
834 try testing.expect(@intFromFloat(u128, 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); // Exact
823 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u32, math.maxInt(u24)) + 0))) == math.maxInt(u24));
824 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u64)) + 0))) == math.maxInt(u64));
825 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u64)) + 1))) == math.maxInt(u64) + 1); // Exact
826 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u64)) + 2))) == math.maxInt(u64) + 1); // Rounds down
827 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u64)) + 3))) == math.maxInt(u64) + 3); // Tie - Exact
828 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u64)) + 4))) == math.maxInt(u64) + 5); // Rounds up
829
830 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u65)) + 0))) == math.maxInt(u65) + 1); // Rounds up
831 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u65)) + 1))) == math.maxInt(u65) + 1); // Exact
832 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u65)) + 2))) == math.maxInt(u65) + 1); // Rounds down
833 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(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u65)) + 4))) == math.maxInt(u65) + 5); // Rounds up
835 try testing.expect(@as(u128, @intFromFloat(floatFromInt(f80, @as(u80, math.maxInt(u65)) + 5))) == math.maxInt(u65) + 5); // Exact
836836}
lib/compiler_rt/floattidf.zig+1-1
......@@ -17,5 +17,5 @@ pub fn __floattidf(a: i128) callconv(.C) f64 {
1717}
1818
1919fn __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)));
2121}
lib/compiler_rt/floattihf.zig+1-1
......@@ -17,5 +17,5 @@ pub fn __floattihf(a: i128) callconv(.C) f16 {
1717}
1818
1919fn __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)));
2121}
lib/compiler_rt/floattisf.zig+1-1
......@@ -17,5 +17,5 @@ pub fn __floattisf(a: i128) callconv(.C) f32 {
1717}
1818
1919fn __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)));
2121}
lib/compiler_rt/floattitf.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __floattitf(a: i128) callconv(.C) f128 {
1919}
2020
2121fn __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)));
2323}
lib/compiler_rt/floattixf.zig+1-1
......@@ -17,5 +17,5 @@ pub fn __floattixf(a: i128) callconv(.C) f80 {
1717}
1818
1919fn __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)));
2121}
lib/compiler_rt/floatuntidf.zig+1-1
......@@ -17,5 +17,5 @@ pub fn __floatuntidf(a: u128) callconv(.C) f64 {
1717}
1818
1919fn __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)));
2121}
lib/compiler_rt/floatuntihf.zig+1-1
......@@ -17,5 +17,5 @@ pub fn __floatuntihf(a: u128) callconv(.C) f16 {
1717}
1818
1919fn __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)));
2121}
lib/compiler_rt/floatuntisf.zig+1-1
......@@ -17,5 +17,5 @@ pub fn __floatuntisf(a: u128) callconv(.C) f32 {
1717}
1818
1919fn __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)));
2121}
lib/compiler_rt/floatuntitf.zig+1-1
......@@ -19,5 +19,5 @@ pub fn __floatuntitf(a: u128) callconv(.C) f128 {
1919}
2020
2121fn __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)));
2323}
lib/compiler_rt/floatuntixf.zig+1-1
......@@ -17,5 +17,5 @@ pub fn __floatuntixf(a: u128) callconv(.C) f80 {
1717}
1818
1919fn __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)));
2121}
lib/compiler_rt/floor.zig+11-11
......@@ -26,8 +26,8 @@ comptime {
2626}
2727
2828pub fn __floorh(x: f16) callconv(.C) f16 {
29 var u = @bitCast(u16, x);
30 const e = @intCast(i16, (u >> 10) & 31) - 15;
29 var u = @as(u16, @bitCast(x));
30 const e = @as(i16, @intCast((u >> 10) & 31)) - 15;
3131 var m: u16 = undefined;
3232
3333 // TODO: Shouldn't need this explicit check.
......@@ -40,7 +40,7 @@ pub fn __floorh(x: f16) callconv(.C) f16 {
4040 }
4141
4242 if (e >= 0) {
43 m = @as(u16, 1023) >> @intCast(u4, e);
43 m = @as(u16, 1023) >> @as(u4, @intCast(e));
4444 if (u & m == 0) {
4545 return x;
4646 }
......@@ -48,7 +48,7 @@ pub fn __floorh(x: f16) callconv(.C) f16 {
4848 if (u >> 15 != 0) {
4949 u += m;
5050 }
51 return @bitCast(f16, u & ~m);
51 return @as(f16, @bitCast(u & ~m));
5252 } else {
5353 math.doNotOptimizeAway(x + 0x1.0p120);
5454 if (u >> 15 == 0) {
......@@ -60,8 +60,8 @@ pub fn __floorh(x: f16) callconv(.C) f16 {
6060}
6161
6262pub fn floorf(x: f32) callconv(.C) f32 {
63 var u = @bitCast(u32, x);
64 const e = @intCast(i32, (u >> 23) & 0xFF) - 0x7F;
63 var u = @as(u32, @bitCast(x));
64 const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;
6565 var m: u32 = undefined;
6666
6767 // TODO: Shouldn't need this explicit check.
......@@ -74,7 +74,7 @@ pub fn floorf(x: f32) callconv(.C) f32 {
7474 }
7575
7676 if (e >= 0) {
77 m = @as(u32, 0x007FFFFF) >> @intCast(u5, e);
77 m = @as(u32, 0x007FFFFF) >> @as(u5, @intCast(e));
7878 if (u & m == 0) {
7979 return x;
8080 }
......@@ -82,7 +82,7 @@ pub fn floorf(x: f32) callconv(.C) f32 {
8282 if (u >> 31 != 0) {
8383 u += m;
8484 }
85 return @bitCast(f32, u & ~m);
85 return @as(f32, @bitCast(u & ~m));
8686 } else {
8787 math.doNotOptimizeAway(x + 0x1.0p120);
8888 if (u >> 31 == 0) {
......@@ -96,7 +96,7 @@ pub fn floorf(x: f32) callconv(.C) f32 {
9696pub fn floor(x: f64) callconv(.C) f64 {
9797 const f64_toint = 1.0 / math.floatEps(f64);
9898
99 const u = @bitCast(u64, x);
99 const u = @as(u64, @bitCast(x));
100100 const e = (u >> 52) & 0x7FF;
101101 var y: f64 = undefined;
102102
......@@ -126,13 +126,13 @@ pub fn floor(x: f64) callconv(.C) f64 {
126126
127127pub fn __floorx(x: f80) callconv(.C) f80 {
128128 // TODO: more efficient implementation
129 return @floatCast(f80, floorq(x));
129 return @as(f80, @floatCast(floorq(x)));
130130}
131131
132132pub fn floorq(x: f128) callconv(.C) f128 {
133133 const f128_toint = 1.0 / math.floatEps(f128);
134134
135 const u = @bitCast(u128, x);
135 const u = @as(u128, @bitCast(x));
136136 const e = (u >> 112) & 0x7FFF;
137137 var y: f128 = undefined;
138138
lib/compiler_rt/fma.zig+19-19
......@@ -28,20 +28,20 @@ comptime {
2828
2929pub fn __fmah(x: f16, y: f16, z: f16) callconv(.C) f16 {
3030 // TODO: more efficient implementation
31 return @floatCast(f16, fmaf(x, y, z));
31 return @as(f16, @floatCast(fmaf(x, y, z)));
3232}
3333
3434pub fn fmaf(x: f32, y: f32, z: f32) callconv(.C) f32 {
3535 const xy = @as(f64, x) * y;
3636 const xy_z = xy + z;
37 const u = @bitCast(u64, xy_z);
37 const u = @as(u64, @bitCast(xy_z));
3838 const e = (u >> 52) & 0x7FF;
3939
4040 if ((u & 0x1FFFFFFF) != 0x10000000 or e == 0x7FF or (xy_z - xy == z and xy_z - z == xy)) {
41 return @floatCast(f32, xy_z);
41 return @as(f32, @floatCast(xy_z));
4242 } else {
4343 // TODO: Handle inexact case with double-rounding
44 return @floatCast(f32, xy_z);
44 return @as(f32, @floatCast(xy_z));
4545 }
4646}
4747
......@@ -95,7 +95,7 @@ pub fn fma(x: f64, y: f64, z: f64) callconv(.C) f64 {
9595
9696pub fn __fmax(a: f80, b: f80, c: f80) callconv(.C) f80 {
9797 // TODO: more efficient implementation
98 return @floatCast(f80, fmaq(a, b, c));
98 return @as(f80, @floatCast(fmaq(a, b, c)));
9999}
100100
101101/// Fused multiply-add: Compute x * y + z with a single rounding error.
......@@ -201,12 +201,12 @@ fn dd_mul(a: f64, b: f64) dd {
201201fn add_adjusted(a: f64, b: f64) f64 {
202202 var sum = dd_add(a, b);
203203 if (sum.lo != 0) {
204 var uhii = @bitCast(u64, sum.hi);
204 var uhii = @as(u64, @bitCast(sum.hi));
205205 if (uhii & 1 == 0) {
206206 // hibits += copysign(1.0, sum.hi, sum.lo)
207 const uloi = @bitCast(u64, sum.lo);
207 const uloi = @as(u64, @bitCast(sum.lo));
208208 uhii += 1 - ((uhii ^ uloi) >> 62);
209 sum.hi = @bitCast(f64, uhii);
209 sum.hi = @as(f64, @bitCast(uhii));
210210 }
211211 }
212212 return sum.hi;
......@@ -215,12 +215,12 @@ fn add_adjusted(a: f64, b: f64) f64 {
215215fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {
216216 var sum = dd_add(a, b);
217217 if (sum.lo != 0) {
218 var uhii = @bitCast(u64, sum.hi);
219 const bits_lost = -@intCast(i32, (uhii >> 52) & 0x7FF) - scale + 1;
218 var uhii = @as(u64, @bitCast(sum.hi));
219 const bits_lost = -@as(i32, @intCast((uhii >> 52) & 0x7FF)) - scale + 1;
220220 if ((bits_lost != 1) == (uhii & 1 != 0)) {
221 const uloi = @bitCast(u64, sum.lo);
221 const uloi = @as(u64, @bitCast(sum.lo));
222222 uhii += 1 - (((uhii ^ uloi) >> 62) & 2);
223 sum.hi = @bitCast(f64, uhii);
223 sum.hi = @as(f64, @bitCast(uhii));
224224 }
225225 }
226226 return math.scalbn(sum.hi, scale);
......@@ -257,12 +257,12 @@ fn dd_add128(a: f128, b: f128) dd128 {
257257fn add_adjusted128(a: f128, b: f128) f128 {
258258 var sum = dd_add128(a, b);
259259 if (sum.lo != 0) {
260 var uhii = @bitCast(u128, sum.hi);
260 var uhii = @as(u128, @bitCast(sum.hi));
261261 if (uhii & 1 == 0) {
262262 // hibits += copysign(1.0, sum.hi, sum.lo)
263 const uloi = @bitCast(u128, sum.lo);
263 const uloi = @as(u128, @bitCast(sum.lo));
264264 uhii += 1 - ((uhii ^ uloi) >> 126);
265 sum.hi = @bitCast(f128, uhii);
265 sum.hi = @as(f128, @bitCast(uhii));
266266 }
267267 }
268268 return sum.hi;
......@@ -282,12 +282,12 @@ fn add_and_denorm128(a: f128, b: f128, scale: i32) f128 {
282282 // If we are losing only one bit to denormalization, however, we must
283283 // break the ties manually.
284284 if (sum.lo != 0) {
285 var uhii = @bitCast(u128, sum.hi);
286 const bits_lost = -@intCast(i32, (uhii >> 112) & 0x7FFF) - scale + 1;
285 var uhii = @as(u128, @bitCast(sum.hi));
286 const bits_lost = -@as(i32, @intCast((uhii >> 112) & 0x7FFF)) - scale + 1;
287287 if ((bits_lost != 1) == (uhii & 1 != 0)) {
288 const uloi = @bitCast(u128, sum.lo);
288 const uloi = @as(u128, @bitCast(sum.lo));
289289 uhii += 1 - (((uhii ^ uloi) >> 126) & 2);
290 sum.hi = @bitCast(f128, uhii);
290 sum.hi = @as(f128, @bitCast(uhii));
291291 }
292292 }
293293 return math.scalbn(sum.hi, scale);
lib/compiler_rt/fmod.zig+32-32
......@@ -22,7 +22,7 @@ comptime {
2222
2323pub fn __fmodh(x: f16, y: f16) callconv(.C) f16 {
2424 // TODO: more efficient implementation
25 return @floatCast(f16, fmodf(x, y));
25 return @as(f16, @floatCast(fmodf(x, y)));
2626}
2727
2828pub fn fmodf(x: f32, y: f32) callconv(.C) f32 {
......@@ -46,12 +46,12 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
4646 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
4747 const maxExponent = ((1 << exponentBits) - 1);
4848
49 var aRep = @bitCast(Z, a);
50 var bRep = @bitCast(Z, b);
49 var aRep = @as(Z, @bitCast(a));
50 var bRep = @as(Z, @bitCast(b));
5151
5252 const signA = aRep & signBit;
53 var expA = @intCast(i32, (@bitCast(Z, a) >> significandBits) & maxExponent);
54 var expB = @intCast(i32, (@bitCast(Z, b) >> significandBits) & maxExponent);
53 var expA = @as(i32, @intCast((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
54 var expB = @as(i32, @intCast((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
5555
5656 // There are 3 cases where the answer is undefined, check for:
5757 // - fmodx(val, 0)
......@@ -82,8 +82,8 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
8282
8383 var highA: u64 = 0;
8484 var highB: u64 = 0;
85 var lowA: u64 = @truncate(u64, aRep);
86 var lowB: u64 = @truncate(u64, bRep);
85 var lowA: u64 = @as(u64, @truncate(aRep));
86 var lowB: u64 = @as(u64, @truncate(bRep));
8787
8888 while (expA > expB) : (expA -= 1) {
8989 var high = highA -% highB;
......@@ -123,11 +123,11 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
123123
124124 // Combine the exponent with the sign and significand, normalize if happened to be denormalized
125125 if (expA < -fractionalBits) {
126 return @bitCast(T, signA);
126 return @as(T, @bitCast(signA));
127127 } 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));
129129 } 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));
131131 }
132132}
133133
......@@ -136,10 +136,10 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
136136pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
137137 var amod = a;
138138 var bmod = b;
139 const aPtr_u64 = @ptrCast([*]u64, &amod);
140 const bPtr_u64 = @ptrCast([*]u64, &bmod);
141 const aPtr_u16 = @ptrCast([*]u16, &amod);
142 const bPtr_u16 = @ptrCast([*]u16, &bmod);
139 const aPtr_u64 = @as([*]u64, @ptrCast(&amod));
140 const bPtr_u64 = @as([*]u64, @ptrCast(&bmod));
141 const aPtr_u16 = @as([*]u16, @ptrCast(&amod));
142 const bPtr_u16 = @as([*]u16, @ptrCast(&bmod));
143143
144144 const exp_and_sign_index = comptime switch (builtin.target.cpu.arch.endian()) {
145145 .Little => 7,
......@@ -155,8 +155,8 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
155155 };
156156
157157 const signA = aPtr_u16[exp_and_sign_index] & 0x8000;
158 var expA = @intCast(i32, (aPtr_u16[exp_and_sign_index] & 0x7fff));
159 var expB = @intCast(i32, (bPtr_u16[exp_and_sign_index] & 0x7fff));
158 var expA = @as(i32, @intCast((aPtr_u16[exp_and_sign_index] & 0x7fff)));
159 var expB = @as(i32, @intCast((bPtr_u16[exp_and_sign_index] & 0x7fff)));
160160
161161 // There are 3 cases where the answer is undefined, check for:
162162 // - fmodq(val, 0)
......@@ -173,8 +173,8 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
173173 }
174174
175175 // Remove the sign from both
176 aPtr_u16[exp_and_sign_index] = @bitCast(u16, @intCast(i16, expA));
177 bPtr_u16[exp_and_sign_index] = @bitCast(u16, @intCast(i16, expB));
176 aPtr_u16[exp_and_sign_index] = @as(u16, @bitCast(@as(i16, @intCast(expA))));
177 bPtr_u16[exp_and_sign_index] = @as(u16, @bitCast(@as(i16, @intCast(expB))));
178178 if (amod <= bmod) {
179179 if (amod == bmod) {
180180 return 0 * a;
......@@ -241,10 +241,10 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
241241
242242 // Combine the exponent with the sign, normalize if happend to be denormalized
243243 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;
245245 amod *= 0x1p-120;
246246 } 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;
248248 }
249249
250250 return amod;
......@@ -270,14 +270,14 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {
270270 const exp_bits = if (T == f32) 9 else 12;
271271 const bits_minus_1 = bits - 1;
272272 const mask = if (T == f32) 0xff else 0x7ff;
273 var ux = @bitCast(uint, x);
274 var uy = @bitCast(uint, y);
275 var ex = @intCast(i32, (ux >> digits) & mask);
276 var ey = @intCast(i32, (uy >> digits) & mask);
277 const sx = if (T == f32) @intCast(u32, ux & 0x80000000) else @intCast(i32, ux >> bits_minus_1);
273 var ux = @as(uint, @bitCast(x));
274 var uy = @as(uint, @bitCast(y));
275 var ex = @as(i32, @intCast((ux >> digits) & mask));
276 var ey = @as(i32, @intCast((uy >> digits) & mask));
277 const sx = if (T == f32) @as(u32, @intCast(ux & 0x80000000)) else @as(i32, @intCast(ux >> bits_minus_1));
278278 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)
281281 return (x * y) / (x * y);
282282
283283 if (ux << 1 <= uy << 1) {
......@@ -293,7 +293,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {
293293 ex -= 1;
294294 i <<= 1;
295295 }) {}
296 ux <<= @intCast(log2uint, @bitCast(u32, -ex + 1));
296 ux <<= @as(log2uint, @intCast(@as(u32, @bitCast(-ex + 1))));
297297 } else {
298298 ux &= math.maxInt(uint) >> exp_bits;
299299 ux |= 1 << digits;
......@@ -304,7 +304,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {
304304 ey -= 1;
305305 i <<= 1;
306306 }) {}
307 uy <<= @intCast(log2uint, @bitCast(u32, -ey + 1));
307 uy <<= @as(log2uint, @intCast(@as(u32, @bitCast(-ey + 1))));
308308 } else {
309309 uy &= math.maxInt(uint) >> exp_bits;
310310 uy |= 1 << digits;
......@@ -334,16 +334,16 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {
334334 // scale result up
335335 if (ex > 0) {
336336 ux -%= 1 << digits;
337 ux |= @as(uint, @bitCast(u32, ex)) << digits;
337 ux |= @as(uint, @as(u32, @bitCast(ex))) << digits;
338338 } else {
339 ux >>= @intCast(log2uint, @bitCast(u32, -ex + 1));
339 ux >>= @as(log2uint, @intCast(@as(u32, @bitCast(-ex + 1))));
340340 }
341341 if (T == f32) {
342342 ux |= sx;
343343 } else {
344 ux |= @intCast(uint, sx) << bits_minus_1;
344 ux |= @as(uint, @intCast(sx)) << bits_minus_1;
345345 }
346 return @bitCast(T, ux);
346 return @as(T, @bitCast(ux));
347347}
348348
349349test "fmodf" {
lib/compiler_rt/int.zig+41-41
......@@ -52,8 +52,8 @@ test "test_divmodti4" {
5252 [_]i128{ -7, 5, -1, -2 },
5353 [_]i128{ 19, 5, 3, 4 },
5454 [_]i128{ 19, -5, -3, 4 },
55 [_]i128{ @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 8, @bitCast(i128, @as(u128, 0xf0000000000000000000000000000000)), 0 },
56 [_]i128{ @bitCast(i128, @as(u128, 0x80000000000000000000000000000007)), 8, @bitCast(i128, @as(u128, 0xf0000000000000000000000000000001)), -1 },
55 [_]i128{ @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 8, @as(i128, @bitCast(@as(u128, 0xf0000000000000000000000000000000))), 0 },
56 [_]i128{ @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000007))), 8, @as(i128, @bitCast(@as(u128, 0xf0000000000000000000000000000001))), -1 },
5757 };
5858
5959 for (cases) |case| {
......@@ -85,8 +85,8 @@ test "test_divmoddi4" {
8585 [_]i64{ -7, 5, -1, -2 },
8686 [_]i64{ 19, 5, 3, 4 },
8787 [_]i64{ 19, -5, -3, 4 },
88 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 8, @bitCast(i64, @as(u64, 0xf000000000000000)), 0 },
89 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000007)), 8, @bitCast(i64, @as(u64, 0xf000000000000001)), -1 },
88 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 8, @as(i64, @bitCast(@as(u64, 0xf000000000000000))), 0 },
89 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000007))), 8, @as(i64, @bitCast(@as(u64, 0xf000000000000001))), -1 },
9090 };
9191
9292 for (cases) |case| {
......@@ -110,14 +110,14 @@ test "test_udivmoddi4" {
110110
111111pub fn __divdi3(a: i64, b: i64) callconv(.C) i64 {
112112 // Set aside the sign of the quotient.
113 const sign = @bitCast(u64, (a ^ b) >> 63);
113 const sign = @as(u64, @bitCast((a ^ b) >> 63));
114114 // Take absolute value of a and b via abs(x) = (x^(x >> 63)) - (x >> 63).
115115 const abs_a = (a ^ (a >> 63)) -% (a >> 63);
116116 const abs_b = (b ^ (b >> 63)) -% (b >> 63);
117117 // Unsigned division
118 const res = __udivmoddi4(@bitCast(u64, abs_a), @bitCast(u64, abs_b), null);
118 const res = __udivmoddi4(@as(u64, @bitCast(abs_a)), @as(u64, @bitCast(abs_b)), null);
119119 // Apply sign of quotient to result and return.
120 return @bitCast(i64, (res ^ sign) -% sign);
120 return @as(i64, @bitCast((res ^ sign) -% sign));
121121}
122122
123123test "test_divdi3" {
......@@ -129,10 +129,10 @@ test "test_divdi3" {
129129 [_]i64{ -2, 1, -2 },
130130 [_]i64{ -2, -1, 2 },
131131
132 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)) },
133 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)) },
134 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -2, 0x4000000000000000 },
135 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0xC000000000000000)) },
132 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1, @as(i64, @bitCast(@as(u64, 0x8000000000000000))) },
133 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), -1, @as(i64, @bitCast(@as(u64, 0x8000000000000000))) },
134 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), -2, 0x4000000000000000 },
135 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 2, @as(i64, @bitCast(@as(u64, 0xC000000000000000))) },
136136 };
137137
138138 for (cases) |case| {
......@@ -151,9 +151,9 @@ pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 {
151151 const abs_b = (b ^ (b >> 63)) -% (b >> 63);
152152 // Unsigned division
153153 var r: u64 = undefined;
154 _ = __udivmoddi4(@bitCast(u64, abs_a), @bitCast(u64, abs_b), &r);
154 _ = __udivmoddi4(@as(u64, @bitCast(abs_a)), @as(u64, @bitCast(abs_b)), &r);
155155 // 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);
157157}
158158
159159test "test_moddi3" {
......@@ -165,12 +165,12 @@ test "test_moddi3" {
165165 [_]i64{ -5, 3, -2 },
166166 [_]i64{ -5, -3, -2 },
167167
168 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 1, 0 },
169 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -1, 0 },
170 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 2, 0 },
171 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -2, 0 },
172 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 3, -2 },
173 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -3, -2 },
168 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1, 0 },
169 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), -1, 0 },
170 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 2, 0 },
171 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), -2, 0 },
172 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 3, -2 },
173 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), -3, -2 },
174174 };
175175
176176 for (cases) |case| {
......@@ -225,8 +225,8 @@ test "test_divmodsi4" {
225225 [_]i32{ 19, 5, 3, 4 },
226226 [_]i32{ 19, -5, -3, 4 },
227227
228 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 8, @bitCast(i32, @as(u32, 0xf0000000)), 0 },
229 [_]i32{ @bitCast(i32, @as(u32, 0x80000007)), 8, @bitCast(i32, @as(u32, 0xf0000001)), -1 },
228 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), 8, @as(i32, @bitCast(@as(u32, 0xf0000000))), 0 },
229 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000007))), 8, @as(i32, @bitCast(@as(u32, 0xf0000001))), -1 },
230230 };
231231
232232 for (cases) |case| {
......@@ -242,7 +242,7 @@ fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) !void {
242242
243243pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {
244244 const d = __udivsi3(a, b);
245 rem.* = @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)))));
246246 return d;
247247}
248248
......@@ -256,14 +256,14 @@ fn __aeabi_idiv(n: i32, d: i32) callconv(.AAPCS) i32 {
256256
257257inline fn div_i32(n: i32, d: i32) i32 {
258258 // Set aside the sign of the quotient.
259 const sign = @bitCast(u32, (n ^ d) >> 31);
259 const sign = @as(u32, @bitCast((n ^ d) >> 31));
260260 // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
261261 const abs_n = (n ^ (n >> 31)) -% (n >> 31);
262262 const abs_d = (d ^ (d >> 31)) -% (d >> 31);
263263 // abs(a) / abs(b)
264 const res = @bitCast(u32, abs_n) / @bitCast(u32, abs_d);
264 const res = @as(u32, @bitCast(abs_n)) / @as(u32, @bitCast(abs_d));
265265 // Apply sign of quotient to result and return.
266 return @bitCast(i32, (res ^ sign) -% sign);
266 return @as(i32, @bitCast((res ^ sign) -% sign));
267267}
268268
269269test "test_divsi3" {
......@@ -275,10 +275,10 @@ test "test_divsi3" {
275275 [_]i32{ -2, 1, -2 },
276276 [_]i32{ -2, -1, 2 },
277277
278 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 1, @bitCast(i32, @as(u32, 0x80000000)) },
279 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), -1, @bitCast(i32, @as(u32, 0x80000000)) },
280 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), -2, 0x40000000 },
281 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 2, @bitCast(i32, @as(u32, 0xC0000000)) },
278 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), 1, @as(i32, @bitCast(@as(u32, 0x80000000))) },
279 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), -1, @as(i32, @bitCast(@as(u32, 0x80000000))) },
280 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), -2, 0x40000000 },
281 [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), 2, @as(i32, @bitCast(@as(u32, 0xC0000000))) },
282282 };
283283
284284 for (cases) |case| {
......@@ -304,7 +304,7 @@ inline fn div_u32(n: u32, d: u32) u32 {
304304 // special cases
305305 if (d == 0) return 0; // ?!
306306 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))));
308308 // 0 <= sr <= n_uword_bits - 1 or sr large
309309 if (sr > n_uword_bits - 1) {
310310 // d > r
......@@ -317,12 +317,12 @@ inline fn div_u32(n: u32, d: u32) u32 {
317317 sr += 1;
318318 // 1 <= sr <= n_uword_bits - 1
319319 // Not a special case
320 var q: u32 = n << @intCast(u5, n_uword_bits - sr);
321 var r: u32 = n >> @intCast(u5, sr);
320 var q: u32 = n << @as(u5, @intCast(n_uword_bits - sr));
321 var r: u32 = n >> @as(u5, @intCast(sr));
322322 var carry: u32 = 0;
323323 while (sr > 0) : (sr -= 1) {
324324 // r:q = ((r:q) << 1) | carry
325 r = (r << 1) | (q >> @intCast(u5, n_uword_bits - 1));
325 r = (r << 1) | (q >> @as(u5, @intCast(n_uword_bits - 1)));
326326 q = (q << 1) | carry;
327327 // carry = 0;
328328 // if (r.all >= d.all)
......@@ -330,9 +330,9 @@ inline fn div_u32(n: u32, d: u32) u32 {
330330 // r.all -= d.all;
331331 // carry = 1;
332332 // }
333 const s = @bitCast(i32, d -% r -% 1) >> @intCast(u5, n_uword_bits - 1);
334 carry = @intCast(u32, s & 1);
335 r -= d & @bitCast(u32, s);
333 const s = @as(i32, @bitCast(d -% r -% 1)) >> @as(u5, @intCast(n_uword_bits - 1));
334 carry = @as(u32, @intCast(s & 1));
335 r -= d & @as(u32, @bitCast(s));
336336 }
337337 q = (q << 1) | carry;
338338 return q;
......@@ -496,11 +496,11 @@ test "test_modsi3" {
496496 [_]i32{ 5, -3, 2 },
497497 [_]i32{ -5, 3, -2 },
498498 [_]i32{ -5, -3, -2 },
499 [_]i32{ @bitCast(i32, @intCast(u32, 0x80000000)), 1, 0x0 },
500 [_]i32{ @bitCast(i32, @intCast(u32, 0x80000000)), 2, 0x0 },
501 [_]i32{ @bitCast(i32, @intCast(u32, 0x80000000)), -2, 0x0 },
502 [_]i32{ @bitCast(i32, @intCast(u32, 0x80000000)), 3, -2 },
503 [_]i32{ @bitCast(i32, @intCast(u32, 0x80000000)), -3, -2 },
499 [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 1, 0x0 },
500 [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 2, 0x0 },
501 [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), -2, 0x0 },
502 [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 3, -2 },
503 [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), -3, -2 },
504504 };
505505
506506 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 {
1717 const sig_mask = (@as(rep_t, 1) << sig_bits) - 1;
1818
1919 // Break a into sign, exponent, significand
20 const a_rep: rep_t = @bitCast(rep_t, a);
20 const a_rep: rep_t = @as(rep_t, @bitCast(a));
2121 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;
2323 const significand: rep_t = (a_rep & sig_mask) | implicit_bit;
2424
2525 // If the exponent is negative, the result rounds to zero.
......@@ -29,9 +29,9 @@ pub inline fn intFromFloat(comptime I: type, a: anytype) I {
2929 switch (@typeInfo(I).Int.signedness) {
3030 .unsigned => {
3131 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);
3333 },
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)) {
3535 return if (negative) math.minInt(I) else math.maxInt(I);
3636 },
3737 }
......@@ -40,9 +40,9 @@ pub inline fn intFromFloat(comptime I: type, a: anytype) I {
4040 // Otherwise, shift left.
4141 var result: I = undefined;
4242 if (exponent < fractional_bits) {
43 result = @intCast(I, significand >> @intCast(Log2Int(rep_t), fractional_bits - exponent));
43 result = @as(I, @intCast(significand >> @as(Log2Int(rep_t), @intCast(fractional_bits - exponent))));
4444 } 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));
4646 }
4747
4848 if ((@typeInfo(I).Int.signedness == .signed) and negative)
lib/compiler_rt/log.zig+14-14
......@@ -27,7 +27,7 @@ comptime {
2727
2828pub fn __logh(a: f16) callconv(.C) f16 {
2929 // TODO: more efficient implementation
30 return @floatCast(f16, logf(a));
30 return @as(f16, @floatCast(logf(a)));
3131}
3232
3333pub fn logf(x_: f32) callconv(.C) f32 {
......@@ -39,7 +39,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {
3939 const Lg4: f32 = 0xf89e26.0p-26;
4040
4141 var x = x_;
42 var ix = @bitCast(u32, x);
42 var ix = @as(u32, @bitCast(x));
4343 var k: i32 = 0;
4444
4545 // x < 2^(-126)
......@@ -56,7 +56,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {
5656 // subnormal, scale x
5757 k -= 25;
5858 x *= 0x1.0p25;
59 ix = @bitCast(u32, x);
59 ix = @as(u32, @bitCast(x));
6060 } else if (ix >= 0x7F800000) {
6161 return x;
6262 } else if (ix == 0x3F800000) {
......@@ -65,9 +65,9 @@ pub fn logf(x_: f32) callconv(.C) f32 {
6565
6666 // x into [sqrt(2) / 2, sqrt(2)]
6767 ix += 0x3F800000 - 0x3F3504F3;
68 k += @intCast(i32, ix >> 23) - 0x7F;
68 k += @as(i32, @intCast(ix >> 23)) - 0x7F;
6969 ix = (ix & 0x007FFFFF) + 0x3F3504F3;
70 x = @bitCast(f32, ix);
70 x = @as(f32, @bitCast(ix));
7171
7272 const f = x - 1.0;
7373 const s = f / (2.0 + f);
......@@ -77,7 +77,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {
7777 const t2 = z * (Lg1 + w * Lg3);
7878 const R = t2 + t1;
7979 const hfsq = 0.5 * f * f;
80 const dk = @floatFromInt(f32, k);
80 const dk = @as(f32, @floatFromInt(k));
8181
8282 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
8383}
......@@ -94,8 +94,8 @@ pub fn log(x_: f64) callconv(.C) f64 {
9494 const Lg7: f64 = 1.479819860511658591e-01;
9595
9696 var x = x_;
97 var ix = @bitCast(u64, x);
98 var hx = @intCast(u32, ix >> 32);
97 var ix = @as(u64, @bitCast(x));
98 var hx = @as(u32, @intCast(ix >> 32));
9999 var k: i32 = 0;
100100
101101 if (hx < 0x00100000 or hx >> 31 != 0) {
......@@ -111,7 +111,7 @@ pub fn log(x_: f64) callconv(.C) f64 {
111111 // subnormal, scale x
112112 k -= 54;
113113 x *= 0x1.0p54;
114 hx = @intCast(u32, @bitCast(u64, ix) >> 32);
114 hx = @as(u32, @intCast(@as(u64, @bitCast(ix)) >> 32));
115115 } else if (hx >= 0x7FF00000) {
116116 return x;
117117 } else if (hx == 0x3FF00000 and ix << 32 == 0) {
......@@ -120,10 +120,10 @@ pub fn log(x_: f64) callconv(.C) f64 {
120120
121121 // x into [sqrt(2) / 2, sqrt(2)]
122122 hx += 0x3FF00000 - 0x3FE6A09E;
123 k += @intCast(i32, hx >> 20) - 0x3FF;
123 k += @as(i32, @intCast(hx >> 20)) - 0x3FF;
124124 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
125125 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
126 x = @bitCast(f64, ix);
126 x = @as(f64, @bitCast(ix));
127127
128128 const f = x - 1.0;
129129 const hfsq = 0.5 * f * f;
......@@ -133,19 +133,19 @@ pub fn log(x_: f64) callconv(.C) f64 {
133133 const t1 = w * (Lg2 + w * (Lg4 + w * Lg6));
134134 const t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));
135135 const R = t2 + t1;
136 const dk = @floatFromInt(f64, k);
136 const dk = @as(f64, @floatFromInt(k));
137137
138138 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
139139}
140140
141141pub fn __logx(a: f80) callconv(.C) f80 {
142142 // TODO: more efficient implementation
143 return @floatCast(f80, logq(a));
143 return @as(f80, @floatCast(logq(a)));
144144}
145145
146146pub fn logq(a: f128) callconv(.C) f128 {
147147 // TODO: more correct implementation
148 return log(@floatCast(f64, a));
148 return log(@as(f64, @floatCast(a)));
149149}
150150
151151pub fn logl(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/log10.zig+18-18
......@@ -28,7 +28,7 @@ comptime {
2828
2929pub fn __log10h(a: f16) callconv(.C) f16 {
3030 // TODO: more efficient implementation
31 return @floatCast(f16, log10f(a));
31 return @as(f16, @floatCast(log10f(a)));
3232}
3333
3434pub fn log10f(x_: f32) callconv(.C) f32 {
......@@ -42,7 +42,7 @@ pub fn log10f(x_: f32) callconv(.C) f32 {
4242 const Lg4: f32 = 0xf89e26.0p-26;
4343
4444 var x = x_;
45 var u = @bitCast(u32, x);
45 var u = @as(u32, @bitCast(x));
4646 var ix = u;
4747 var k: i32 = 0;
4848
......@@ -59,7 +59,7 @@ pub fn log10f(x_: f32) callconv(.C) f32 {
5959
6060 k -= 25;
6161 x *= 0x1.0p25;
62 ix = @bitCast(u32, x);
62 ix = @as(u32, @bitCast(x));
6363 } else if (ix >= 0x7F800000) {
6464 return x;
6565 } else if (ix == 0x3F800000) {
......@@ -68,9 +68,9 @@ pub fn log10f(x_: f32) callconv(.C) f32 {
6868
6969 // x into [sqrt(2) / 2, sqrt(2)]
7070 ix += 0x3F800000 - 0x3F3504F3;
71 k += @intCast(i32, ix >> 23) - 0x7F;
71 k += @as(i32, @intCast(ix >> 23)) - 0x7F;
7272 ix = (ix & 0x007FFFFF) + 0x3F3504F3;
73 x = @bitCast(f32, ix);
73 x = @as(f32, @bitCast(ix));
7474
7575 const f = x - 1.0;
7676 const s = f / (2.0 + f);
......@@ -82,11 +82,11 @@ pub fn log10f(x_: f32) callconv(.C) f32 {
8282 const hfsq = 0.5 * f * f;
8383
8484 var hi = f - hfsq;
85 u = @bitCast(u32, hi);
85 u = @as(u32, @bitCast(hi));
8686 u &= 0xFFFFF000;
87 hi = @bitCast(f32, u);
87 hi = @as(f32, @bitCast(u));
8888 const lo = f - hi - hfsq + s * (hfsq + R);
89 const dk = @floatFromInt(f32, k);
89 const dk = @as(f32, @floatFromInt(k));
9090
9191 return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi;
9292}
......@@ -105,8 +105,8 @@ pub fn log10(x_: f64) callconv(.C) f64 {
105105 const Lg7: f64 = 1.479819860511658591e-01;
106106
107107 var x = x_;
108 var ix = @bitCast(u64, x);
109 var hx = @intCast(u32, ix >> 32);
108 var ix = @as(u64, @bitCast(x));
109 var hx = @as(u32, @intCast(ix >> 32));
110110 var k: i32 = 0;
111111
112112 if (hx < 0x00100000 or hx >> 31 != 0) {
......@@ -122,7 +122,7 @@ pub fn log10(x_: f64) callconv(.C) f64 {
122122 // subnormal, scale x
123123 k -= 54;
124124 x *= 0x1.0p54;
125 hx = @intCast(u32, @bitCast(u64, x) >> 32);
125 hx = @as(u32, @intCast(@as(u64, @bitCast(x)) >> 32));
126126 } else if (hx >= 0x7FF00000) {
127127 return x;
128128 } else if (hx == 0x3FF00000 and ix << 32 == 0) {
......@@ -131,10 +131,10 @@ pub fn log10(x_: f64) callconv(.C) f64 {
131131
132132 // x into [sqrt(2) / 2, sqrt(2)]
133133 hx += 0x3FF00000 - 0x3FE6A09E;
134 k += @intCast(i32, hx >> 20) - 0x3FF;
134 k += @as(i32, @intCast(hx >> 20)) - 0x3FF;
135135 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
136136 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
137 x = @bitCast(f64, ix);
137 x = @as(f64, @bitCast(ix));
138138
139139 const f = x - 1.0;
140140 const hfsq = 0.5 * f * f;
......@@ -147,14 +147,14 @@ pub fn log10(x_: f64) callconv(.C) f64 {
147147
148148 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
149149 var hi = f - hfsq;
150 var hii = @bitCast(u64, hi);
150 var hii = @as(u64, @bitCast(hi));
151151 hii &= @as(u64, maxInt(u64)) << 32;
152 hi = @bitCast(f64, hii);
152 hi = @as(f64, @bitCast(hii));
153153 const lo = f - hi - hfsq + s * (hfsq + R);
154154
155155 // val_hi + val_lo ~ log10(1 + f) + k * log10(2)
156156 var val_hi = hi * ivln10hi;
157 const dk = @floatFromInt(f64, k);
157 const dk = @as(f64, @floatFromInt(k));
158158 const y = dk * log10_2hi;
159159 var val_lo = dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi;
160160
......@@ -168,12 +168,12 @@ pub fn log10(x_: f64) callconv(.C) f64 {
168168
169169pub fn __log10x(a: f80) callconv(.C) f80 {
170170 // TODO: more efficient implementation
171 return @floatCast(f80, log10q(a));
171 return @as(f80, @floatCast(log10q(a)));
172172}
173173
174174pub fn log10q(a: f128) callconv(.C) f128 {
175175 // TODO: more correct implementation
176 return log10(@floatCast(f64, a));
176 return log10(@as(f64, @floatCast(a)));
177177}
178178
179179pub fn log10l(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/log2.zig+18-18
......@@ -28,7 +28,7 @@ comptime {
2828
2929pub fn __log2h(a: f16) callconv(.C) f16 {
3030 // TODO: more efficient implementation
31 return @floatCast(f16, log2f(a));
31 return @as(f16, @floatCast(log2f(a)));
3232}
3333
3434pub fn log2f(x_: f32) callconv(.C) f32 {
......@@ -40,7 +40,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 {
4040 const Lg4: f32 = 0xf89e26.0p-26;
4141
4242 var x = x_;
43 var u = @bitCast(u32, x);
43 var u = @as(u32, @bitCast(x));
4444 var ix = u;
4545 var k: i32 = 0;
4646
......@@ -57,7 +57,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 {
5757
5858 k -= 25;
5959 x *= 0x1.0p25;
60 ix = @bitCast(u32, x);
60 ix = @as(u32, @bitCast(x));
6161 } else if (ix >= 0x7F800000) {
6262 return x;
6363 } else if (ix == 0x3F800000) {
......@@ -66,9 +66,9 @@ pub fn log2f(x_: f32) callconv(.C) f32 {
6666
6767 // x into [sqrt(2) / 2, sqrt(2)]
6868 ix += 0x3F800000 - 0x3F3504F3;
69 k += @intCast(i32, ix >> 23) - 0x7F;
69 k += @as(i32, @intCast(ix >> 23)) - 0x7F;
7070 ix = (ix & 0x007FFFFF) + 0x3F3504F3;
71 x = @bitCast(f32, ix);
71 x = @as(f32, @bitCast(ix));
7272
7373 const f = x - 1.0;
7474 const s = f / (2.0 + f);
......@@ -80,11 +80,11 @@ pub fn log2f(x_: f32) callconv(.C) f32 {
8080 const hfsq = 0.5 * f * f;
8181
8282 var hi = f - hfsq;
83 u = @bitCast(u32, hi);
83 u = @as(u32, @bitCast(hi));
8484 u &= 0xFFFFF000;
85 hi = @bitCast(f32, u);
85 hi = @as(f32, @bitCast(u));
8686 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));
8888}
8989
9090pub fn log2(x_: f64) callconv(.C) f64 {
......@@ -99,8 +99,8 @@ pub fn log2(x_: f64) callconv(.C) f64 {
9999 const Lg7: f64 = 1.479819860511658591e-01;
100100
101101 var x = x_;
102 var ix = @bitCast(u64, x);
103 var hx = @intCast(u32, ix >> 32);
102 var ix = @as(u64, @bitCast(x));
103 var hx = @as(u32, @intCast(ix >> 32));
104104 var k: i32 = 0;
105105
106106 if (hx < 0x00100000 or hx >> 31 != 0) {
......@@ -116,7 +116,7 @@ pub fn log2(x_: f64) callconv(.C) f64 {
116116 // subnormal, scale x
117117 k -= 54;
118118 x *= 0x1.0p54;
119 hx = @intCast(u32, @bitCast(u64, x) >> 32);
119 hx = @as(u32, @intCast(@as(u64, @bitCast(x)) >> 32));
120120 } else if (hx >= 0x7FF00000) {
121121 return x;
122122 } else if (hx == 0x3FF00000 and ix << 32 == 0) {
......@@ -125,10 +125,10 @@ pub fn log2(x_: f64) callconv(.C) f64 {
125125
126126 // x into [sqrt(2) / 2, sqrt(2)]
127127 hx += 0x3FF00000 - 0x3FE6A09E;
128 k += @intCast(i32, hx >> 20) - 0x3FF;
128 k += @as(i32, @intCast(hx >> 20)) - 0x3FF;
129129 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
130130 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
131 x = @bitCast(f64, ix);
131 x = @as(f64, @bitCast(ix));
132132
133133 const f = x - 1.0;
134134 const hfsq = 0.5 * f * f;
......@@ -141,16 +141,16 @@ pub fn log2(x_: f64) callconv(.C) f64 {
141141
142142 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
143143 var hi = f - hfsq;
144 var hii = @bitCast(u64, hi);
144 var hii = @as(u64, @bitCast(hi));
145145 hii &= @as(u64, maxInt(u64)) << 32;
146 hi = @bitCast(f64, hii);
146 hi = @as(f64, @bitCast(hii));
147147 const lo = f - hi - hfsq + s * (hfsq + R);
148148
149149 var val_hi = hi * ivln2hi;
150150 var val_lo = (lo + hi) * ivln2lo + lo * ivln2hi;
151151
152152 // spadd(val_hi, val_lo, y)
153 const y = @floatFromInt(f64, k);
153 const y = @as(f64, @floatFromInt(k));
154154 const ww = y + val_hi;
155155 val_lo += (y - ww) + val_hi;
156156 val_hi = ww;
......@@ -160,12 +160,12 @@ pub fn log2(x_: f64) callconv(.C) f64 {
160160
161161pub fn __log2x(a: f80) callconv(.C) f80 {
162162 // TODO: more efficient implementation
163 return @floatCast(f80, log2q(a));
163 return @as(f80, @floatCast(log2q(a)));
164164}
165165
166166pub fn log2q(a: f128) callconv(.C) f128 {
167167 // TODO: more correct implementation
168 return log2(@floatCast(f64, a));
168 return log2(@as(f64, @floatCast(a)));
169169}
170170
171171pub 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 {
2424const v2u64 = @Vector(2, u64);
2525
2626fn __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)))));
2828}
2929
3030inline fn mod(a: i128, b: i128) i128 {
......@@ -35,8 +35,8 @@ inline fn mod(a: i128, b: i128) i128 {
3535 const bn = (b ^ s_b) -% s_b; // negate if s == -1
3636
3737 var r: u128 = undefined;
38 _ = udivmod(u128, @bitCast(u128, an), @bitCast(u128, bn), &r);
39 return (@bitCast(i128, r) ^ s_a) -% s_a; // negate if s == -1
38 _ = udivmod(u128, @as(u128, @bitCast(an)), @as(u128, @bitCast(bn)), &r);
39 return (@as(i128, @bitCast(r)) ^ s_a) -% s_a; // negate if s == -1
4040}
4141
4242test {
lib/compiler_rt/modti3_test.zig+1-1
......@@ -33,5 +33,5 @@ fn make_ti(high: u64, low: u64) i128 {
3333 var result: u128 = high;
3434 result <<= 64;
3535 result |= low;
36 return @bitCast(i128, result);
36 return @as(i128, @bitCast(result));
3737}
lib/compiler_rt/mulXi3.zig+4-4
......@@ -21,8 +21,8 @@ comptime {
2121}
2222
2323pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
24 var ua = @bitCast(u32, a);
25 var ub = @bitCast(u32, b);
24 var ua = @as(u32, @bitCast(a));
25 var ub = @as(u32, @bitCast(b));
2626 var r: u32 = 0;
2727
2828 while (ua > 0) {
......@@ -31,7 +31,7 @@ pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
3131 ub <<= 1;
3232 }
3333
34 return @bitCast(i32, r);
34 return @as(i32, @bitCast(r));
3535}
3636
3737pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 {
......@@ -93,7 +93,7 @@ pub fn __multi3(a: i128, b: i128) callconv(.C) i128 {
9393const v2u64 = @Vector(2, u64);
9494
9595fn __multi3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {
96 return @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)))));
9797}
9898
9999test {
lib/compiler_rt/mulXi3_test.zig+8-8
......@@ -46,14 +46,14 @@ test "mulsi3" {
4646 try test_one_mulsi3(-46340, 46340, -2147395600);
4747 try test_one_mulsi3(46340, -46340, -2147395600);
4848 try test_one_mulsi3(-46340, -46340, 2147395600);
49 try test_one_mulsi3(4194303, 8192, @truncate(i32, 34359730176));
50 try test_one_mulsi3(-4194303, 8192, @truncate(i32, -34359730176));
51 try test_one_mulsi3(4194303, -8192, @truncate(i32, -34359730176));
52 try test_one_mulsi3(-4194303, -8192, @truncate(i32, 34359730176));
53 try test_one_mulsi3(8192, 4194303, @truncate(i32, 34359730176));
54 try test_one_mulsi3(-8192, 4194303, @truncate(i32, -34359730176));
55 try test_one_mulsi3(8192, -4194303, @truncate(i32, -34359730176));
56 try test_one_mulsi3(-8192, -4194303, @truncate(i32, 34359730176));
49 try test_one_mulsi3(4194303, 8192, @as(i32, @truncate(34359730176)));
50 try test_one_mulsi3(-4194303, 8192, @as(i32, @truncate(-34359730176)));
51 try test_one_mulsi3(4194303, -8192, @as(i32, @truncate(-34359730176)));
52 try test_one_mulsi3(-4194303, -8192, @as(i32, @truncate(34359730176)));
53 try test_one_mulsi3(8192, 4194303, @as(i32, @truncate(34359730176)));
54 try test_one_mulsi3(-8192, 4194303, @as(i32, @truncate(-34359730176)));
55 try test_one_mulsi3(8192, -4194303, @as(i32, @truncate(-34359730176)));
56 try test_one_mulsi3(-8192, -4194303, @as(i32, @truncate(34359730176)));
5757}
5858
5959test "muldi3" {
lib/compiler_rt/mulf3.zig+30-30
......@@ -28,53 +28,53 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
2828 const significandMask = (@as(Z, 1) << significandBits) - 1;
2929
3030 const absMask = signBit - 1;
31 const qnanRep = @bitCast(Z, math.nan(T)) | quietBit;
32 const infRep = @bitCast(Z, math.inf(T));
33 const minNormalRep = @bitCast(Z, math.floatMin(T));
31 const qnanRep = @as(Z, @bitCast(math.nan(T))) | quietBit;
32 const infRep = @as(Z, @bitCast(math.inf(T)));
33 const minNormalRep = @as(Z, @bitCast(math.floatMin(T)));
3434
3535 const ZExp = if (typeWidth >= 32) u32 else Z;
36 const aExponent = @truncate(ZExp, (@bitCast(Z, a) >> significandBits) & maxExponent);
37 const bExponent = @truncate(ZExp, (@bitCast(Z, b) >> significandBits) & maxExponent);
38 const productSign: Z = (@bitCast(Z, a) ^ @bitCast(Z, b)) & signBit;
36 const aExponent = @as(ZExp, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));
37 const bExponent = @as(ZExp, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));
38 const productSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
3939
40 var aSignificand: ZSignificand = @intCast(ZSignificand, @bitCast(Z, a) & significandMask);
41 var bSignificand: ZSignificand = @intCast(ZSignificand, @bitCast(Z, b) & significandMask);
40 var aSignificand: ZSignificand = @as(ZSignificand, @intCast(@as(Z, @bitCast(a)) & significandMask));
41 var bSignificand: ZSignificand = @as(ZSignificand, @intCast(@as(Z, @bitCast(b)) & significandMask));
4242 var scale: i32 = 0;
4343
4444 // Detect if a or b is zero, denormal, infinity, or NaN.
4545 if (aExponent -% 1 >= maxExponent - 1 or bExponent -% 1 >= maxExponent - 1) {
46 const aAbs: Z = @bitCast(Z, a) & absMask;
47 const bAbs: Z = @bitCast(Z, b) & absMask;
46 const aAbs: Z = @as(Z, @bitCast(a)) & absMask;
47 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
4848
4949 // 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));
5151 // 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
5454 if (aAbs == infRep) {
5555 // infinity * non-zero = +/- infinity
5656 if (bAbs != 0) {
57 return @bitCast(T, aAbs | productSign);
57 return @as(T, @bitCast(aAbs | productSign));
5858 } else {
5959 // infinity * zero = NaN
60 return @bitCast(T, qnanRep);
60 return @as(T, @bitCast(qnanRep));
6161 }
6262 }
6363
6464 if (bAbs == infRep) {
6565 //? non-zero * infinity = +/- infinity
6666 if (aAbs != 0) {
67 return @bitCast(T, bAbs | productSign);
67 return @as(T, @bitCast(bAbs | productSign));
6868 } else {
6969 // zero * infinity = NaN
70 return @bitCast(T, qnanRep);
70 return @as(T, @bitCast(qnanRep));
7171 }
7272 }
7373
7474 // zero * anything = +/- zero
75 if (aAbs == 0) return @bitCast(T, productSign);
75 if (aAbs == 0) return @as(T, @bitCast(productSign));
7676 // anything * zero = +/- zero
77 if (bAbs == 0) return @bitCast(T, productSign);
77 if (bAbs == 0) return @as(T, @bitCast(productSign));
7878
7979 // one or both of a or b is denormal, the other (if applicable) is a
8080 // normal number. Renormalize one or both of a and b, and set scale to
......@@ -99,7 +99,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
9999 const left_align_shift = ZSignificandBits - fractionalBits - 1;
100100 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
104104 // Normalize the significand, adjust exponent if needed.
105105 if ((productHi & integerBit) != 0) {
......@@ -110,7 +110,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
110110 }
111111
112112 // If we have overflowed the type, return +/- infinity.
113 if (productExponent >= maxExponent) return @bitCast(T, infRep | productSign);
113 if (productExponent >= maxExponent) return @as(T, @bitCast(infRep | productSign));
114114
115115 var result: Z = undefined;
116116 if (productExponent <= 0) {
......@@ -120,8 +120,8 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
120120 // a zero of the appropriate sign. Mathematically there is no need to
121121 // handle this case separately, but we make it a special case to
122122 // simplify the shift logic.
123 const shift: u32 = @truncate(u32, @as(Z, 1) -% @bitCast(u32, productExponent));
124 if (shift >= ZSignificandBits) return @bitCast(T, productSign);
123 const shift: u32 = @as(u32, @truncate(@as(Z, 1) -% @as(u32, @bitCast(productExponent))));
124 if (shift >= ZSignificandBits) return @as(T, @bitCast(productSign));
125125
126126 // Otherwise, shift the significand of the result so that the round
127127 // bit is the high bit of productLo.
......@@ -135,7 +135,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
135135 } else {
136136 // Result is normal before rounding; insert the exponent.
137137 result = productHi & significandMask;
138 result |= @intCast(Z, productExponent) << significandBits;
138 result |= @as(Z, @intCast(productExponent)) << significandBits;
139139 }
140140
141141 // 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 {
156156 // Insert the sign of the result:
157157 result |= productSign;
158158
159 return @bitCast(T, result);
159 return @as(T, @bitCast(result));
160160}
161161
162162/// 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 {
168168 const S = math.Log2Int(Z);
169169 var inexact = false;
170170 if (count < typeWidth) {
171 inexact = (lo.* << @intCast(S, typeWidth -% count)) != 0;
172 lo.* = (hi.* << @intCast(S, typeWidth -% count)) | (lo.* >> @intCast(S, count));
173 hi.* = hi.* >> @intCast(S, count);
171 inexact = (lo.* << @as(S, @intCast(typeWidth -% count))) != 0;
172 lo.* = (hi.* << @as(S, @intCast(typeWidth -% count))) | (lo.* >> @as(S, @intCast(count)));
173 hi.* = hi.* >> @as(S, @intCast(count));
174174 } else if (count < 2 * typeWidth) {
175 inexact = (hi.* << @intCast(S, 2 * typeWidth -% count) | lo.*) != 0;
176 lo.* = hi.* >> @intCast(S, count -% typeWidth);
175 inexact = (hi.* << @as(S, @intCast(2 * typeWidth -% count)) | lo.*) != 0;
176 lo.* = hi.* >> @as(S, @intCast(count -% typeWidth));
177177 hi.* = 0;
178178 } else {
179179 inexact = (hi.* | lo.*) != 0;
......@@ -188,7 +188,7 @@ fn normalize(comptime T: type, significand: *PowerOfTwoSignificandZ(T)) i32 {
188188 const integerBit = @as(Z, 1) << math.floatFractionalBits(T);
189189
190190 const shift = @clz(significand.*) - @clz(integerBit);
191 significand.* <<= @intCast(math.Log2Int(Z), shift);
191 significand.* <<= @as(math.Log2Int(Z), @intCast(shift));
192192 return @as(i32, 1) - shift;
193193}
194194
lib/compiler_rt/mulf3_test.zig+26-26
......@@ -4,8 +4,8 @@
44
55const std = @import("std");
66const math = std.math;
7const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64);
8const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64);
7const qnan128 = @as(f128, @bitCast(@as(u128, 0x7fff800000000000) << 64));
8const inf128 = @as(f128, @bitCast(@as(u128, 0x7fff000000000000) << 64));
99
1010const __multf3 = @import("multf3.zig").__multf3;
1111const __mulxf3 = @import("mulxf3.zig").__mulxf3;
......@@ -16,9 +16,9 @@ const __mulsf3 = @import("mulsf3.zig").__mulsf3;
1616// use two 64-bit integers intead of one 128-bit integer
1717// because 128-bit integer constant can't be assigned directly
1818fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
19 const rep = @bitCast(u128, result);
20 const hi = @intCast(u64, rep >> 64);
21 const lo = @truncate(u64, rep);
19 const rep = @as(u128, @bitCast(result));
20 const hi = @as(u64, @intCast(rep >> 64));
21 const lo = @as(u64, @truncate(rep));
2222
2323 if (hi == expectedHi and lo == expectedLo) {
2424 return true;
......@@ -45,7 +45,7 @@ fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
4545
4646fn makeNaN128(rand: u64) f128 {
4747 const int_result = @as(u128, 0x7fff000000000000 | (rand & 0xffffffffffff)) << 64;
48 const float_result = @bitCast(f128, int_result);
48 const float_result = @as(f128, @bitCast(int_result));
4949 return float_result;
5050}
5151test "multf3" {
......@@ -60,15 +60,15 @@ test "multf3" {
6060
6161 // any * any
6262 try test__multf3(
63 @bitCast(f128, @as(u128, 0x40042eab345678439abcdefea5678234)),
64 @bitCast(f128, @as(u128, 0x3ffeedcb34a235253948765432134675)),
63 @as(f128, @bitCast(@as(u128, 0x40042eab345678439abcdefea5678234))),
64 @as(f128, @bitCast(@as(u128, 0x3ffeedcb34a235253948765432134675))),
6565 0x400423e7f9e3c9fc,
6666 0xd906c2c2a85777c4,
6767 );
6868
6969 try test__multf3(
70 @bitCast(f128, @as(u128, 0x3fcd353e45674d89abacc3a2ebf3ff50)),
71 @bitCast(f128, @as(u128, 0x3ff6ed8764648369535adf4be3214568)),
70 @as(f128, @bitCast(@as(u128, 0x3fcd353e45674d89abacc3a2ebf3ff50))),
71 @as(f128, @bitCast(@as(u128, 0x3ff6ed8764648369535adf4be3214568))),
7272 0x3fc52a163c6223fc,
7373 0xc94c4bf0430768b4,
7474 );
......@@ -81,8 +81,8 @@ test "multf3" {
8181 );
8282
8383 try test__multf3(
84 @bitCast(f128, @as(u128, 0x3f154356473c82a9fabf2d22ace345df)),
85 @bitCast(f128, @as(u128, 0x3e38eda98765476743ab21da23d45679)),
84 @as(f128, @bitCast(@as(u128, 0x3f154356473c82a9fabf2d22ace345df))),
85 @as(f128, @bitCast(@as(u128, 0x3e38eda98765476743ab21da23d45679))),
8686 0x3d4f37c1a3137cae,
8787 0xfc6807048bc2836a,
8888 );
......@@ -108,16 +108,16 @@ test "multf3" {
108108 try test__multf3(2.0, math.floatTrueMin(f128), 0x0000_0000_0000_0000, 0x0000_0000_0000_0002);
109109}
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
113113fn test__mulxf3(a: f80, b: f80, expected: u80) !void {
114114 const x = __mulxf3(a, b);
115 const rep = @bitCast(u80, x);
115 const rep = @as(u80, @bitCast(x));
116116
117117 if (rep == expected)
118118 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))
121121 return; // We don't currently test NaN payload propagation
122122
123123 return error.TestFailed;
......@@ -125,33 +125,33 @@ fn test__mulxf3(a: f80, b: f80, expected: u80) !void {
125125
126126test "mulxf3" {
127127 // NaN * any = NaN
128 try test__mulxf3(qnan80, 0x1.23456789abcdefp+5, @bitCast(u80, qnan80));
129 try test__mulxf3(@bitCast(f80, @as(u80, 0x7fff_8000_8000_3000_0000)), 0x1.23456789abcdefp+5, @bitCast(u80, qnan80));
128 try test__mulxf3(qnan80, 0x1.23456789abcdefp+5, @as(u80, @bitCast(qnan80)));
129 try test__mulxf3(@as(f80, @bitCast(@as(u80, 0x7fff_8000_8000_3000_0000))), 0x1.23456789abcdefp+5, @as(u80, @bitCast(qnan80)));
130130
131131 // any * NaN = NaN
132 try test__mulxf3(0x1.23456789abcdefp+5, qnan80, @bitCast(u80, qnan80));
133 try test__mulxf3(0x1.23456789abcdefp+5, @bitCast(f80, @as(u80, 0x7fff_8000_8000_3000_0000)), @bitCast(u80, qnan80));
132 try test__mulxf3(0x1.23456789abcdefp+5, qnan80, @as(u80, @bitCast(qnan80)));
133 try test__mulxf3(0x1.23456789abcdefp+5, @as(f80, @bitCast(@as(u80, 0x7fff_8000_8000_3000_0000))), @as(u80, @bitCast(qnan80)));
134134
135135 // 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
138138 // 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
141141 // 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
144144 // 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
147147 // -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
150150 // 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
153153 // 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
156156 // any * any
157157 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)
4545 //invariant: -2^{bitwidth(EST)} < res < 2^{bitwidth(EST)-1}
4646 if (res < min or max < res)
4747 overflow.* = 1;
48 return @truncate(ST, res);
48 return @as(ST, @truncate(res));
4949}
5050
5151pub 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" {
5454
5555 try test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1);
5656 try test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1);
57 try test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
58 try test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @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, @as(i64, @bitCast(@as(u64, 0x8000000000000001))), 0);
5959 try test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0);
6060 try test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0);
6161 try test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0);
6262 try test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0);
63 try test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
64 try test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @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, @as(i64, @bitCast(@as(u64, 0x8000000000000001))), 1);
6565
66 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
67 try test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
68 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
69 try test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
70 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0, 0);
71 try test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0);
72 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)), 0);
73 try test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 0);
74 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
75 try test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000000)), @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, @as(i64, @bitCast(@as(u64, 0x8000000000000000))), @as(i64, @bitCast(@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, @as(i64, @bitCast(@as(u64, 0x8000000000000000))), @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1);
70 try test__mulodi4(@as(i64, @bitCast(@as(u64, 0x8000000000000000))), 0, 0, 0);
71 try test__mulodi4(0, @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 0, 0);
72 try test__mulodi4(@as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1, @as(i64, @bitCast(@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(@as(i64, @bitCast(@as(u64, 0x8000000000000000))), 2, @as(i64, @bitCast(@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);
78 try test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
79 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0);
80 try test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0);
81 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0, 0);
82 try test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0);
83 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
84 try test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
85 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
86 try test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
77 try test__mulodi4(@as(i64, @bitCast(@as(u64, 0x8000000000000001))), -2, @as(i64, @bitCast(@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(@as(i64, @bitCast(@as(u64, 0x8000000000000001))), -1, 0x7FFFFFFFFFFFFFFF, 0);
80 try test__mulodi4(-1, @as(i64, @bitCast(@as(u64, 0x8000000000000001))), 0x7FFFFFFFFFFFFFFF, 0);
81 try test__mulodi4(@as(i64, @bitCast(@as(u64, 0x8000000000000001))), 0, 0, 0);
82 try test__mulodi4(0, @as(i64, @bitCast(@as(u64, 0x8000000000000001))), 0, 0);
83 try test__mulodi4(@as(i64, @bitCast(@as(u64, 0x8000000000000001))), 1, @as(i64, @bitCast(@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(@as(i64, @bitCast(@as(u64, 0x8000000000000001))), 2, @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1);
86 try test__mulodi4(2, @as(i64, @bitCast(@as(u64, 0x8000000000000001))), @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1);
8787}
lib/compiler_rt/mulosi4_test.zig+26-26
......@@ -37,36 +37,36 @@ test "mulosi4" {
3737 try test__mulosi4(1, -0x1234567, -0x1234567, 0);
3838 try test__mulosi4(-0x1234567, 1, -0x1234567, 0);
3939
40 try test__mulosi4(0x7FFFFFFF, -2, @bitCast(i32, @as(u32, 0x80000001)), 1);
41 try test__mulosi4(-2, 0x7FFFFFFF, @bitCast(i32, @as(u32, 0x80000001)), 1);
42 try test__mulosi4(0x7FFFFFFF, -1, @bitCast(i32, @as(u32, 0x80000001)), 0);
43 try test__mulosi4(-1, 0x7FFFFFFF, @bitCast(i32, @as(u32, 0x80000001)), 0);
40 try test__mulosi4(0x7FFFFFFF, -2, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
41 try test__mulosi4(-2, 0x7FFFFFFF, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
42 try test__mulosi4(0x7FFFFFFF, -1, @as(i32, @bitCast(@as(u32, 0x80000001))), 0);
43 try test__mulosi4(-1, 0x7FFFFFFF, @as(i32, @bitCast(@as(u32, 0x80000001))), 0);
4444 try test__mulosi4(0x7FFFFFFF, 0, 0, 0);
4545 try test__mulosi4(0, 0x7FFFFFFF, 0, 0);
4646 try test__mulosi4(0x7FFFFFFF, 1, 0x7FFFFFFF, 0);
4747 try test__mulosi4(1, 0x7FFFFFFF, 0x7FFFFFFF, 0);
48 try test__mulosi4(0x7FFFFFFF, 2, @bitCast(i32, @as(u32, 0x80000001)), 1);
49 try test__mulosi4(2, 0x7FFFFFFF, @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, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
5050
51 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000000)), -2, @bitCast(i32, @as(u32, 0x80000000)), 1);
52 try test__mulosi4(-2, @bitCast(i32, @as(u32, 0x80000000)), @bitCast(i32, @as(u32, 0x80000000)), 1);
53 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000000)), -1, @bitCast(i32, @as(u32, 0x80000000)), 1);
54 try test__mulosi4(-1, @bitCast(i32, @as(u32, 0x80000000)), @bitCast(i32, @as(u32, 0x80000000)), 1);
55 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000000)), 0, 0, 0);
56 try test__mulosi4(0, @bitCast(i32, @as(u32, 0x80000000)), 0, 0);
57 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000000)), 1, @bitCast(i32, @as(u32, 0x80000000)), 0);
58 try test__mulosi4(1, @bitCast(i32, @as(u32, 0x80000000)), @bitCast(i32, @as(u32, 0x80000000)), 0);
59 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000000)), 2, @bitCast(i32, @as(u32, 0x80000000)), 1);
60 try test__mulosi4(2, @bitCast(i32, @as(u32, 0x80000000)), @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, @as(i32, @bitCast(@as(u32, 0x80000000))), @as(i32, @bitCast(@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, @as(i32, @bitCast(@as(u32, 0x80000000))), @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
55 try test__mulosi4(@as(i32, @bitCast(@as(u32, 0x80000000))), 0, 0, 0);
56 try test__mulosi4(0, @as(i32, @bitCast(@as(u32, 0x80000000))), 0, 0);
57 try test__mulosi4(@as(i32, @bitCast(@as(u32, 0x80000000))), 1, @as(i32, @bitCast(@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(@as(i32, @bitCast(@as(u32, 0x80000000))), 2, @as(i32, @bitCast(@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);
63 try test__mulosi4(-2, @bitCast(i32, @as(u32, 0x80000001)), @bitCast(i32, @as(u32, 0x80000001)), 1);
64 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000001)), -1, 0x7FFFFFFF, 0);
65 try test__mulosi4(-1, @bitCast(i32, @as(u32, 0x80000001)), 0x7FFFFFFF, 0);
66 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000001)), 0, 0, 0);
67 try test__mulosi4(0, @bitCast(i32, @as(u32, 0x80000001)), 0, 0);
68 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000001)), 1, @bitCast(i32, @as(u32, 0x80000001)), 0);
69 try test__mulosi4(1, @bitCast(i32, @as(u32, 0x80000001)), @bitCast(i32, @as(u32, 0x80000001)), 0);
70 try test__mulosi4(@bitCast(i32, @as(u32, 0x80000001)), 2, @bitCast(i32, @as(u32, 0x80000000)), 1);
71 try test__mulosi4(2, @bitCast(i32, @as(u32, 0x80000001)), @bitCast(i32, @as(u32, 0x80000000)), 1);
62 try test__mulosi4(@as(i32, @bitCast(@as(u32, 0x80000001))), -2, @as(i32, @bitCast(@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(@as(i32, @bitCast(@as(u32, 0x80000001))), -1, 0x7FFFFFFF, 0);
65 try test__mulosi4(-1, @as(i32, @bitCast(@as(u32, 0x80000001))), 0x7FFFFFFF, 0);
66 try test__mulosi4(@as(i32, @bitCast(@as(u32, 0x80000001))), 0, 0, 0);
67 try test__mulosi4(0, @as(i32, @bitCast(@as(u32, 0x80000001))), 0, 0);
68 try test__mulosi4(@as(i32, @bitCast(@as(u32, 0x80000001))), 1, @as(i32, @bitCast(@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(@as(i32, @bitCast(@as(u32, 0x80000001))), 2, @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
71 try test__mulosi4(2, @as(i32, @bitCast(@as(u32, 0x80000001))), @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
7272}
lib/compiler_rt/muloti4_test.zig+31-31
......@@ -52,38 +52,38 @@ test "muloti4" {
5252 try test__muloti4(2097152, -4398046511103, -9223372036852678656, 0);
5353 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);
56 try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
57 try test__muloti4(-2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
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(@as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), -2, @as(i128, @bitCast(@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);
60 try test__muloti4(-1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
61 try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0);
62 try test__muloti4(0, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0);
63 try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
64 try test__muloti4(1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
65 try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
66 try test__muloti4(2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
59 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), -1, @as(i128, @bitCast(@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(@as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), 0, 0, 0);
62 try test__muloti4(0, @as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), 0, 0);
63 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), 1, @as(i128, @bitCast(@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(@as(i128, @bitCast(@as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), 2, @as(i128, @bitCast(@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);
69 try test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
70 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
71 try test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
72 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0, 0);
73 try test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0);
74 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);
75 try test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);
76 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
77 try test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @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, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), @as(i128, @bitCast(@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, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 1);
72 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 0, 0, 0);
73 try test__muloti4(0, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 0, 0);
74 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 1, @as(i128, @bitCast(@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(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 2, @as(i128, @bitCast(@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);
80 try test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
81 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
82 try test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
83 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0, 0);
84 try test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0);
85 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
86 try test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
87 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
88 try test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
79 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), -2, @as(i128, @bitCast(@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(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), -1, @as(i128, @bitCast(@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(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 0, 0, 0);
84 try test__muloti4(0, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 0, 0);
85 try test__muloti4(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 1, @as(i128, @bitCast(@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(@as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), 2, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 1);
88 try test__muloti4(2, @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000001))), @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 1);
8989}
lib/compiler_rt/negv.zig+1-1
......@@ -33,7 +33,7 @@ inline fn negvXi(comptime ST: type, a: ST) ST {
3333 else => unreachable,
3434 };
3535 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))));
3737 if (a == min)
3838 @panic("compiler_rt negv: overflow");
3939 return -a;
lib/compiler_rt/parity.zig+4-4
......@@ -27,9 +27,9 @@ pub fn __parityti2(a: i128) callconv(.C) i32 {
2727
2828inline fn parityXi2(comptime T: type, a: T) i32 {
2929 var x = switch (@bitSizeOf(T)) {
30 32 => @bitCast(u32, a),
31 64 => @bitCast(u64, a),
32 128 => @bitCast(u128, a),
30 32 => @as(u32, @bitCast(a)),
31 64 => @as(u64, @bitCast(a)),
32 128 => @as(u128, @bitCast(a)),
3333 else => unreachable,
3434 };
3535 // Bit Twiddling Hacks: Compute parity in parallel
......@@ -39,7 +39,7 @@ inline fn parityXi2(comptime T: type, a: T) i32 {
3939 shift = shift >> 1;
4040 }
4141 x &= 0xf;
42 return (@intCast(u16, 0x6996) >> @intCast(u4, x)) & 1; // optimization for >>2 and >>1
42 return (@as(u16, @intCast(0x6996)) >> @as(u4, @intCast(x))) & 1; // optimization for >>2 and >>1
4343}
4444
4545test {
lib/compiler_rt/paritydi2_test.zig+5-5
......@@ -3,13 +3,13 @@ const parity = @import("parity.zig");
33const testing = std.testing;
44
55fn paritydi2Naive(a: i64) i32 {
6 var x = @bitCast(u64, a);
6 var x = @as(u64, @bitCast(a));
77 var has_parity: bool = false;
88 while (x > 0) {
99 has_parity = !has_parity;
1010 x = x & (x - 1);
1111 }
12 return @intCast(i32, @intFromBool(has_parity));
12 return @as(i32, @intCast(@intFromBool(has_parity)));
1313}
1414
1515fn test__paritydi2(a: i64) !void {
......@@ -22,9 +22,9 @@ test "paritydi2" {
2222 try test__paritydi2(0);
2323 try test__paritydi2(1);
2424 try test__paritydi2(2);
25 try test__paritydi2(@bitCast(i64, @as(u64, 0xffffffff_fffffffd)));
26 try test__paritydi2(@bitCast(i64, @as(u64, 0xffffffff_fffffffe)));
27 try test__paritydi2(@bitCast(i64, @as(u64, 0xffffffff_ffffffff)));
25 try test__paritydi2(@as(i64, @bitCast(@as(u64, 0xffffffff_fffffffd))));
26 try test__paritydi2(@as(i64, @bitCast(@as(u64, 0xffffffff_fffffffe))));
27 try test__paritydi2(@as(i64, @bitCast(@as(u64, 0xffffffff_ffffffff))));
2828
2929 const RndGen = std.rand.DefaultPrng;
3030 var rnd = RndGen.init(42);
lib/compiler_rt/paritysi2_test.zig+5-5
......@@ -3,13 +3,13 @@ const parity = @import("parity.zig");
33const testing = std.testing;
44
55fn paritysi2Naive(a: i32) i32 {
6 var x = @bitCast(u32, a);
6 var x = @as(u32, @bitCast(a));
77 var has_parity: bool = false;
88 while (x > 0) {
99 has_parity = !has_parity;
1010 x = x & (x - 1);
1111 }
12 return @intCast(i32, @intFromBool(has_parity));
12 return @as(i32, @intCast(@intFromBool(has_parity)));
1313}
1414
1515fn test__paritysi2(a: i32) !void {
......@@ -22,9 +22,9 @@ test "paritysi2" {
2222 try test__paritysi2(0);
2323 try test__paritysi2(1);
2424 try test__paritysi2(2);
25 try test__paritysi2(@bitCast(i32, @as(u32, 0xfffffffd)));
26 try test__paritysi2(@bitCast(i32, @as(u32, 0xfffffffe)));
27 try test__paritysi2(@bitCast(i32, @as(u32, 0xffffffff)));
25 try test__paritysi2(@as(i32, @bitCast(@as(u32, 0xfffffffd))));
26 try test__paritysi2(@as(i32, @bitCast(@as(u32, 0xfffffffe))));
27 try test__paritysi2(@as(i32, @bitCast(@as(u32, 0xffffffff))));
2828
2929 const RndGen = std.rand.DefaultPrng;
3030 var rnd = RndGen.init(42);
lib/compiler_rt/parityti2_test.zig+5-5
......@@ -3,13 +3,13 @@ const parity = @import("parity.zig");
33const testing = std.testing;
44
55fn parityti2Naive(a: i128) i32 {
6 var x = @bitCast(u128, a);
6 var x = @as(u128, @bitCast(a));
77 var has_parity: bool = false;
88 while (x > 0) {
99 has_parity = !has_parity;
1010 x = x & (x - 1);
1111 }
12 return @intCast(i32, @intFromBool(has_parity));
12 return @as(i32, @intCast(@intFromBool(has_parity)));
1313}
1414
1515fn test__parityti2(a: i128) !void {
......@@ -22,9 +22,9 @@ test "parityti2" {
2222 try test__parityti2(0);
2323 try test__parityti2(1);
2424 try test__parityti2(2);
25 try test__parityti2(@bitCast(i128, @as(u128, 0xffffffff_ffffffff_ffffffff_fffffffd)));
26 try test__parityti2(@bitCast(i128, @as(u128, 0xffffffff_ffffffff_ffffffff_fffffffe)));
27 try test__parityti2(@bitCast(i128, @as(u128, 0xffffffff_ffffffff_ffffffff_ffffffff)));
25 try test__parityti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffd))));
26 try test__parityti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffe))));
27 try test__parityti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_ffffffff))));
2828
2929 const RndGen = std.rand.DefaultPrng;
3030 var rnd = RndGen.init(42);
lib/compiler_rt/popcount.zig+2-2
......@@ -37,7 +37,7 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 {
3737 i128 => u128,
3838 else => unreachable,
3939 };
40 var x = @bitCast(UT, a);
40 var x = @as(UT, @bitCast(a));
4141 x -= (x >> 1) & (~@as(UT, 0) / 3); // 0x55...55, aggregate duos
4242 x = ((x >> 2) & (~@as(UT, 0) / 5)) // 0x33...33, aggregate nibbles
4343 + (x & (~@as(UT, 0) / 5));
......@@ -46,7 +46,7 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 {
4646 // 8 most significant bits of x + (x<<8) + (x<<16) + ..
4747 x *%= ~@as(UT, 0) / 255; // 0x01...01
4848 x >>= (@bitSizeOf(ST) - 8);
49 return @intCast(i32, x);
49 return @as(i32, @intCast(x));
5050}
5151
5252test {
lib/compiler_rt/popcountdi2_test.zig+5-5
......@@ -5,8 +5,8 @@ const testing = std.testing;
55fn popcountdi2Naive(a: i64) i32 {
66 var x = a;
77 var r: i32 = 0;
8 while (x != 0) : (x = @bitCast(i64, @bitCast(u64, x) >> 1)) {
9 r += @intCast(i32, x & 1);
8 while (x != 0) : (x = @as(i64, @bitCast(@as(u64, @bitCast(x)) >> 1))) {
9 r += @as(i32, @intCast(x & 1));
1010 }
1111 return r;
1212}
......@@ -21,9 +21,9 @@ test "popcountdi2" {
2121 try test__popcountdi2(0);
2222 try test__popcountdi2(1);
2323 try test__popcountdi2(2);
24 try test__popcountdi2(@bitCast(i64, @as(u64, 0xffffffff_fffffffd)));
25 try test__popcountdi2(@bitCast(i64, @as(u64, 0xffffffff_fffffffe)));
26 try test__popcountdi2(@bitCast(i64, @as(u64, 0xffffffff_ffffffff)));
24 try test__popcountdi2(@as(i64, @bitCast(@as(u64, 0xffffffff_fffffffd))));
25 try test__popcountdi2(@as(i64, @bitCast(@as(u64, 0xffffffff_fffffffe))));
26 try test__popcountdi2(@as(i64, @bitCast(@as(u64, 0xffffffff_ffffffff))));
2727
2828 const RndGen = std.rand.DefaultPrng;
2929 var rnd = RndGen.init(42);
lib/compiler_rt/popcountsi2_test.zig+5-5
......@@ -5,8 +5,8 @@ const testing = std.testing;
55fn popcountsi2Naive(a: i32) i32 {
66 var x = a;
77 var r: i32 = 0;
8 while (x != 0) : (x = @bitCast(i32, @bitCast(u32, x) >> 1)) {
9 r += @intCast(i32, x & 1);
8 while (x != 0) : (x = @as(i32, @bitCast(@as(u32, @bitCast(x)) >> 1))) {
9 r += @as(i32, @intCast(x & 1));
1010 }
1111 return r;
1212}
......@@ -21,9 +21,9 @@ test "popcountsi2" {
2121 try test__popcountsi2(0);
2222 try test__popcountsi2(1);
2323 try test__popcountsi2(2);
24 try test__popcountsi2(@bitCast(i32, @as(u32, 0xfffffffd)));
25 try test__popcountsi2(@bitCast(i32, @as(u32, 0xfffffffe)));
26 try test__popcountsi2(@bitCast(i32, @as(u32, 0xffffffff)));
24 try test__popcountsi2(@as(i32, @bitCast(@as(u32, 0xfffffffd))));
25 try test__popcountsi2(@as(i32, @bitCast(@as(u32, 0xfffffffe))));
26 try test__popcountsi2(@as(i32, @bitCast(@as(u32, 0xffffffff))));
2727
2828 const RndGen = std.rand.DefaultPrng;
2929 var rnd = RndGen.init(42);
lib/compiler_rt/popcountti2_test.zig+5-5
......@@ -5,8 +5,8 @@ const testing = std.testing;
55fn popcountti2Naive(a: i128) i32 {
66 var x = a;
77 var r: i32 = 0;
8 while (x != 0) : (x = @bitCast(i128, @bitCast(u128, x) >> 1)) {
9 r += @intCast(i32, x & 1);
8 while (x != 0) : (x = @as(i128, @bitCast(@as(u128, @bitCast(x)) >> 1))) {
9 r += @as(i32, @intCast(x & 1));
1010 }
1111 return r;
1212}
......@@ -21,9 +21,9 @@ test "popcountti2" {
2121 try test__popcountti2(0);
2222 try test__popcountti2(1);
2323 try test__popcountti2(2);
24 try test__popcountti2(@bitCast(i128, @as(u128, 0xffffffff_ffffffff_ffffffff_fffffffd)));
25 try test__popcountti2(@bitCast(i128, @as(u128, 0xffffffff_ffffffff_ffffffff_fffffffe)));
26 try test__popcountti2(@bitCast(i128, @as(u128, 0xffffffff_ffffffff_ffffffff_ffffffff)));
24 try test__popcountti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffd))));
25 try test__popcountti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffe))));
26 try test__popcountti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_ffffffff))));
2727
2828 const RndGen = std.rand.DefaultPrng;
2929 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 {
2525 const is_recip: bool = b < 0;
2626 var r: FT = 1.0;
2727 while (true) {
28 if (@bitCast(u32, x_b) & @as(u32, 1) != 0) {
28 if (@as(u32, @bitCast(x_b)) & @as(u32, 1) != 0) {
2929 r *= x_a;
3030 }
3131 x_b = @divTrunc(x_b, @as(i32, 2));
lib/compiler_rt/powiXf2_test.zig+124-124
......@@ -49,76 +49,76 @@ test "powihf2" {
4949 try test__powihf2(0, 2, 0);
5050 try test__powihf2(0, 3, 0);
5151 try test__powihf2(0, 4, 0);
52 try test__powihf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
53 try test__powihf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 0);
52 try test__powihf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
53 try test__powihf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 0);
5454
5555 try test__powihf2(-0.0, 1, -0.0);
5656 try test__powihf2(-0.0, 2, 0);
5757 try test__powihf2(-0.0, 3, -0.0);
5858 try test__powihf2(-0.0, 4, 0);
59 try test__powihf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
60 try test__powihf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -0.0);
59 try test__powihf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
60 try test__powihf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -0.0);
6161
6262 try test__powihf2(1, 1, 1);
6363 try test__powihf2(1, 2, 1);
6464 try test__powihf2(1, 3, 1);
6565 try test__powihf2(1, 4, 1);
66 try test__powihf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 1);
67 try test__powihf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 1);
66 try test__powihf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 1);
67 try test__powihf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 1);
6868
6969 try test__powihf2(inf_f16, 1, inf_f16);
7070 try test__powihf2(inf_f16, 2, inf_f16);
7171 try test__powihf2(inf_f16, 3, inf_f16);
7272 try test__powihf2(inf_f16, 4, inf_f16);
73 try test__powihf2(inf_f16, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f16);
74 try test__powihf2(inf_f16, @bitCast(i32, @as(u32, 0x7FFFFFFF)), inf_f16);
73 try test__powihf2(inf_f16, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f16);
74 try test__powihf2(inf_f16, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), inf_f16);
7575
7676 try test__powihf2(-inf_f16, 1, -inf_f16);
7777 try test__powihf2(-inf_f16, 2, inf_f16);
7878 try test__powihf2(-inf_f16, 3, -inf_f16);
7979 try test__powihf2(-inf_f16, 4, inf_f16);
80 try test__powihf2(-inf_f16, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f16);
81 try test__powihf2(-inf_f16, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -inf_f16);
80 try test__powihf2(-inf_f16, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f16);
81 try test__powihf2(-inf_f16, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -inf_f16);
8282 //
8383 try test__powihf2(0, -1, inf_f16);
8484 try test__powihf2(0, -2, inf_f16);
8585 try test__powihf2(0, -3, inf_f16);
8686 try test__powihf2(0, -4, inf_f16);
87 try test__powihf2(0, @bitCast(i32, @as(u32, 0x80000002)), inf_f16); // 0 ^ anything = +inf
88 try test__powihf2(0, @bitCast(i32, @as(u32, 0x80000001)), inf_f16);
89 try test__powihf2(0, @bitCast(i32, @as(u32, 0x80000000)), inf_f16);
87 try test__powihf2(0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f16); // 0 ^ anything = +inf
88 try test__powihf2(0, @as(i32, @bitCast(@as(u32, 0x80000001))), inf_f16);
89 try test__powihf2(0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f16);
9090
9191 try test__powihf2(-0.0, -1, -inf_f16);
9292 try test__powihf2(-0.0, -2, inf_f16);
9393 try test__powihf2(-0.0, -3, -inf_f16);
9494 try test__powihf2(-0.0, -4, inf_f16);
95 try test__powihf2(-0.0, @bitCast(i32, @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 = -inf
97 try test__powihf2(-0.0, @bitCast(i32, @as(u32, 0x80000000)), inf_f16);
95 try test__powihf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f16); // -0 ^ anything even = +inf
96 try test__powihf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000001))), -inf_f16); // -0 ^ anything odd = -inf
97 try test__powihf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f16);
9898
9999 try test__powihf2(1, -1, 1);
100100 try test__powihf2(1, -2, 1);
101101 try test__powihf2(1, -3, 1);
102102 try test__powihf2(1, -4, 1);
103 try test__powihf2(1, @bitCast(i32, @as(u32, 0x80000002)), 1); // 1.0 ^ anything = 1
104 try test__powihf2(1, @bitCast(i32, @as(u32, 0x80000001)), 1);
105 try test__powihf2(1, @bitCast(i32, @as(u32, 0x80000000)), 1);
103 try test__powihf2(1, @as(i32, @bitCast(@as(u32, 0x80000002))), 1); // 1.0 ^ anything = 1
104 try test__powihf2(1, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
105 try test__powihf2(1, @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
106106
107107 try test__powihf2(inf_f16, -1, 0);
108108 try test__powihf2(inf_f16, -2, 0);
109109 try test__powihf2(inf_f16, -3, 0);
110110 try test__powihf2(inf_f16, -4, 0);
111 try test__powihf2(inf_f16, @bitCast(i32, @as(u32, 0x80000002)), 0);
112 try test__powihf2(inf_f16, @bitCast(i32, @as(u32, 0x80000001)), 0);
113 try test__powihf2(inf_f16, @bitCast(i32, @as(u32, 0x80000000)), 0);
111 try test__powihf2(inf_f16, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
112 try test__powihf2(inf_f16, @as(i32, @bitCast(@as(u32, 0x80000001))), 0);
113 try test__powihf2(inf_f16, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
114114 //
115115 try test__powihf2(-inf_f16, -1, -0.0);
116116 try test__powihf2(-inf_f16, -2, 0);
117117 try test__powihf2(-inf_f16, -3, -0.0);
118118 try test__powihf2(-inf_f16, -4, 0);
119 try test__powihf2(-inf_f16, @bitCast(i32, @as(u32, 0x80000002)), 0);
120 try test__powihf2(-inf_f16, @bitCast(i32, @as(u32, 0x80000001)), -0.0);
121 try test__powihf2(-inf_f16, @bitCast(i32, @as(u32, 0x80000000)), 0);
119 try test__powihf2(-inf_f16, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
120 try test__powihf2(-inf_f16, @as(i32, @bitCast(@as(u32, 0x80000001))), -0.0);
121 try test__powihf2(-inf_f16, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
122122
123123 try test__powihf2(2, 10, 1024.0);
124124 try test__powihf2(-2, 10, 1024.0);
......@@ -158,76 +158,76 @@ test "powisf2" {
158158 try test__powisf2(0, 2, 0);
159159 try test__powisf2(0, 3, 0);
160160 try test__powisf2(0, 4, 0);
161 try test__powisf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
162 try test__powisf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 0);
161 try test__powisf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
162 try test__powisf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 0);
163163
164164 try test__powisf2(-0.0, 1, -0.0);
165165 try test__powisf2(-0.0, 2, 0);
166166 try test__powisf2(-0.0, 3, -0.0);
167167 try test__powisf2(-0.0, 4, 0);
168 try test__powisf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
169 try test__powisf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -0.0);
168 try test__powisf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
169 try test__powisf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -0.0);
170170
171171 try test__powisf2(1, 1, 1);
172172 try test__powisf2(1, 2, 1);
173173 try test__powisf2(1, 3, 1);
174174 try test__powisf2(1, 4, 1);
175 try test__powisf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 1);
176 try test__powisf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 1);
175 try test__powisf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 1);
176 try test__powisf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 1);
177177
178178 try test__powisf2(inf_f32, 1, inf_f32);
179179 try test__powisf2(inf_f32, 2, inf_f32);
180180 try test__powisf2(inf_f32, 3, inf_f32);
181181 try test__powisf2(inf_f32, 4, inf_f32);
182 try test__powisf2(inf_f32, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f32);
183 try test__powisf2(inf_f32, @bitCast(i32, @as(u32, 0x7FFFFFFF)), inf_f32);
182 try test__powisf2(inf_f32, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f32);
183 try test__powisf2(inf_f32, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), inf_f32);
184184
185185 try test__powisf2(-inf_f32, 1, -inf_f32);
186186 try test__powisf2(-inf_f32, 2, inf_f32);
187187 try test__powisf2(-inf_f32, 3, -inf_f32);
188188 try test__powisf2(-inf_f32, 4, inf_f32);
189 try test__powisf2(-inf_f32, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f32);
190 try test__powisf2(-inf_f32, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -inf_f32);
189 try test__powisf2(-inf_f32, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f32);
190 try test__powisf2(-inf_f32, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -inf_f32);
191191
192192 try test__powisf2(0, -1, inf_f32);
193193 try test__powisf2(0, -2, inf_f32);
194194 try test__powisf2(0, -3, inf_f32);
195195 try test__powisf2(0, -4, inf_f32);
196 try test__powisf2(0, @bitCast(i32, @as(u32, 0x80000002)), inf_f32);
197 try test__powisf2(0, @bitCast(i32, @as(u32, 0x80000001)), inf_f32);
198 try test__powisf2(0, @bitCast(i32, @as(u32, 0x80000000)), inf_f32);
196 try test__powisf2(0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f32);
197 try test__powisf2(0, @as(i32, @bitCast(@as(u32, 0x80000001))), inf_f32);
198 try test__powisf2(0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f32);
199199
200200 try test__powisf2(-0.0, -1, -inf_f32);
201201 try test__powisf2(-0.0, -2, inf_f32);
202202 try test__powisf2(-0.0, -3, -inf_f32);
203203 try test__powisf2(-0.0, -4, inf_f32);
204 try test__powisf2(-0.0, @bitCast(i32, @as(u32, 0x80000002)), inf_f32);
205 try test__powisf2(-0.0, @bitCast(i32, @as(u32, 0x80000001)), -inf_f32);
206 try test__powisf2(-0.0, @bitCast(i32, @as(u32, 0x80000000)), inf_f32);
204 try test__powisf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f32);
205 try test__powisf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000001))), -inf_f32);
206 try test__powisf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f32);
207207
208208 try test__powisf2(1, -1, 1);
209209 try test__powisf2(1, -2, 1);
210210 try test__powisf2(1, -3, 1);
211211 try test__powisf2(1, -4, 1);
212 try test__powisf2(1, @bitCast(i32, @as(u32, 0x80000002)), 1);
213 try test__powisf2(1, @bitCast(i32, @as(u32, 0x80000001)), 1);
214 try test__powisf2(1, @bitCast(i32, @as(u32, 0x80000000)), 1);
212 try test__powisf2(1, @as(i32, @bitCast(@as(u32, 0x80000002))), 1);
213 try test__powisf2(1, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
214 try test__powisf2(1, @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
215215
216216 try test__powisf2(inf_f32, -1, 0);
217217 try test__powisf2(inf_f32, -2, 0);
218218 try test__powisf2(inf_f32, -3, 0);
219219 try test__powisf2(inf_f32, -4, 0);
220 try test__powisf2(inf_f32, @bitCast(i32, @as(u32, 0x80000002)), 0);
221 try test__powisf2(inf_f32, @bitCast(i32, @as(u32, 0x80000001)), 0);
222 try test__powisf2(inf_f32, @bitCast(i32, @as(u32, 0x80000000)), 0);
220 try test__powisf2(inf_f32, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
221 try test__powisf2(inf_f32, @as(i32, @bitCast(@as(u32, 0x80000001))), 0);
222 try test__powisf2(inf_f32, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
223223
224224 try test__powisf2(-inf_f32, -1, -0.0);
225225 try test__powisf2(-inf_f32, -2, 0);
226226 try test__powisf2(-inf_f32, -3, -0.0);
227227 try test__powisf2(-inf_f32, -4, 0);
228 try test__powisf2(-inf_f32, @bitCast(i32, @as(u32, 0x80000002)), 0);
229 try test__powisf2(-inf_f32, @bitCast(i32, @as(u32, 0x80000001)), -0.0);
230 try test__powisf2(-inf_f32, @bitCast(i32, @as(u32, 0x80000000)), 0);
228 try test__powisf2(-inf_f32, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
229 try test__powisf2(-inf_f32, @as(i32, @bitCast(@as(u32, 0x80000001))), -0.0);
230 try test__powisf2(-inf_f32, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
231231
232232 try test__powisf2(2.0, 10, 1024.0);
233233 try test__powisf2(-2, 10, 1024.0);
......@@ -263,76 +263,76 @@ test "powidf2" {
263263 try test__powidf2(0, 2, 0);
264264 try test__powidf2(0, 3, 0);
265265 try test__powidf2(0, 4, 0);
266 try test__powidf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
267 try test__powidf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 0);
266 try test__powidf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
267 try test__powidf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 0);
268268
269269 try test__powidf2(-0.0, 1, -0.0);
270270 try test__powidf2(-0.0, 2, 0);
271271 try test__powidf2(-0.0, 3, -0.0);
272272 try test__powidf2(-0.0, 4, 0);
273 try test__powidf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
274 try test__powidf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -0.0);
273 try test__powidf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
274 try test__powidf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -0.0);
275275
276276 try test__powidf2(1, 1, 1);
277277 try test__powidf2(1, 2, 1);
278278 try test__powidf2(1, 3, 1);
279279 try test__powidf2(1, 4, 1);
280 try test__powidf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 1);
281 try test__powidf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 1);
280 try test__powidf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 1);
281 try test__powidf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 1);
282282
283283 try test__powidf2(inf_f64, 1, inf_f64);
284284 try test__powidf2(inf_f64, 2, inf_f64);
285285 try test__powidf2(inf_f64, 3, inf_f64);
286286 try test__powidf2(inf_f64, 4, inf_f64);
287 try test__powidf2(inf_f64, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f64);
288 try test__powidf2(inf_f64, @bitCast(i32, @as(u32, 0x7FFFFFFF)), inf_f64);
287 try test__powidf2(inf_f64, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f64);
288 try test__powidf2(inf_f64, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), inf_f64);
289289
290290 try test__powidf2(-inf_f64, 1, -inf_f64);
291291 try test__powidf2(-inf_f64, 2, inf_f64);
292292 try test__powidf2(-inf_f64, 3, -inf_f64);
293293 try test__powidf2(-inf_f64, 4, inf_f64);
294 try test__powidf2(-inf_f64, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f64);
295 try test__powidf2(-inf_f64, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -inf_f64);
294 try test__powidf2(-inf_f64, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f64);
295 try test__powidf2(-inf_f64, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -inf_f64);
296296
297297 try test__powidf2(0, -1, inf_f64);
298298 try test__powidf2(0, -2, inf_f64);
299299 try test__powidf2(0, -3, inf_f64);
300300 try test__powidf2(0, -4, inf_f64);
301 try test__powidf2(0, @bitCast(i32, @as(u32, 0x80000002)), inf_f64);
302 try test__powidf2(0, @bitCast(i32, @as(u32, 0x80000001)), inf_f64);
303 try test__powidf2(0, @bitCast(i32, @as(u32, 0x80000000)), inf_f64);
301 try test__powidf2(0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f64);
302 try test__powidf2(0, @as(i32, @bitCast(@as(u32, 0x80000001))), inf_f64);
303 try test__powidf2(0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f64);
304304
305305 try test__powidf2(-0.0, -1, -inf_f64);
306306 try test__powidf2(-0.0, -2, inf_f64);
307307 try test__powidf2(-0.0, -3, -inf_f64);
308308 try test__powidf2(-0.0, -4, inf_f64);
309 try test__powidf2(-0.0, @bitCast(i32, @as(u32, 0x80000002)), inf_f64);
310 try test__powidf2(-0.0, @bitCast(i32, @as(u32, 0x80000001)), -inf_f64);
311 try test__powidf2(-0.0, @bitCast(i32, @as(u32, 0x80000000)), inf_f64);
309 try test__powidf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f64);
310 try test__powidf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000001))), -inf_f64);
311 try test__powidf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f64);
312312
313313 try test__powidf2(1, -1, 1);
314314 try test__powidf2(1, -2, 1);
315315 try test__powidf2(1, -3, 1);
316316 try test__powidf2(1, -4, 1);
317 try test__powidf2(1, @bitCast(i32, @as(u32, 0x80000002)), 1);
318 try test__powidf2(1, @bitCast(i32, @as(u32, 0x80000001)), 1);
319 try test__powidf2(1, @bitCast(i32, @as(u32, 0x80000000)), 1);
317 try test__powidf2(1, @as(i32, @bitCast(@as(u32, 0x80000002))), 1);
318 try test__powidf2(1, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
319 try test__powidf2(1, @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
320320
321321 try test__powidf2(inf_f64, -1, 0);
322322 try test__powidf2(inf_f64, -2, 0);
323323 try test__powidf2(inf_f64, -3, 0);
324324 try test__powidf2(inf_f64, -4, 0);
325 try test__powidf2(inf_f64, @bitCast(i32, @as(u32, 0x80000002)), 0);
326 try test__powidf2(inf_f64, @bitCast(i32, @as(u32, 0x80000001)), 0);
327 try test__powidf2(inf_f64, @bitCast(i32, @as(u32, 0x80000000)), 0);
325 try test__powidf2(inf_f64, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
326 try test__powidf2(inf_f64, @as(i32, @bitCast(@as(u32, 0x80000001))), 0);
327 try test__powidf2(inf_f64, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
328328
329329 try test__powidf2(-inf_f64, -1, -0.0);
330330 try test__powidf2(-inf_f64, -2, 0);
331331 try test__powidf2(-inf_f64, -3, -0.0);
332332 try test__powidf2(-inf_f64, -4, 0);
333 try test__powidf2(-inf_f64, @bitCast(i32, @as(u32, 0x80000002)), 0);
334 try test__powidf2(-inf_f64, @bitCast(i32, @as(u32, 0x80000001)), -0.0);
335 try test__powidf2(-inf_f64, @bitCast(i32, @as(u32, 0x80000000)), 0);
333 try test__powidf2(-inf_f64, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
334 try test__powidf2(-inf_f64, @as(i32, @bitCast(@as(u32, 0x80000001))), -0.0);
335 try test__powidf2(-inf_f64, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
336336
337337 try test__powidf2(2, 10, 1024.0);
338338 try test__powidf2(-2, 10, 1024.0);
......@@ -368,76 +368,76 @@ test "powitf2" {
368368 try test__powitf2(0, 2, 0);
369369 try test__powitf2(0, 3, 0);
370370 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);
372372 try test__powitf2(0, 0x7FFFFFFF, 0);
373373
374374 try test__powitf2(-0.0, 1, -0.0);
375375 try test__powitf2(-0.0, 2, 0);
376376 try test__powitf2(-0.0, 3, -0.0);
377377 try test__powitf2(-0.0, 4, 0);
378 try test__powitf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
379 try test__powitf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -0.0);
378 try test__powitf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
379 try test__powitf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -0.0);
380380
381381 try test__powitf2(1, 1, 1);
382382 try test__powitf2(1, 2, 1);
383383 try test__powitf2(1, 3, 1);
384384 try test__powitf2(1, 4, 1);
385 try test__powitf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 1);
386 try test__powitf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 1);
385 try test__powitf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 1);
386 try test__powitf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 1);
387387
388388 try test__powitf2(inf_f128, 1, inf_f128);
389389 try test__powitf2(inf_f128, 2, inf_f128);
390390 try test__powitf2(inf_f128, 3, inf_f128);
391391 try test__powitf2(inf_f128, 4, inf_f128);
392 try test__powitf2(inf_f128, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f128);
393 try test__powitf2(inf_f128, @bitCast(i32, @as(u32, 0x7FFFFFFF)), inf_f128);
392 try test__powitf2(inf_f128, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f128);
393 try test__powitf2(inf_f128, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), inf_f128);
394394
395395 try test__powitf2(-inf_f128, 1, -inf_f128);
396396 try test__powitf2(-inf_f128, 2, inf_f128);
397397 try test__powitf2(-inf_f128, 3, -inf_f128);
398398 try test__powitf2(-inf_f128, 4, inf_f128);
399 try test__powitf2(-inf_f128, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f128);
400 try test__powitf2(-inf_f128, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -inf_f128);
399 try test__powitf2(-inf_f128, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f128);
400 try test__powitf2(-inf_f128, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -inf_f128);
401401
402402 try test__powitf2(0, -1, inf_f128);
403403 try test__powitf2(0, -2, inf_f128);
404404 try test__powitf2(0, -3, inf_f128);
405405 try test__powitf2(0, -4, inf_f128);
406 try test__powitf2(0, @bitCast(i32, @as(u32, 0x80000002)), inf_f128);
407 try test__powitf2(0, @bitCast(i32, @as(u32, 0x80000001)), inf_f128);
408 try test__powitf2(0, @bitCast(i32, @as(u32, 0x80000000)), inf_f128);
406 try test__powitf2(0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f128);
407 try test__powitf2(0, @as(i32, @bitCast(@as(u32, 0x80000001))), inf_f128);
408 try test__powitf2(0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f128);
409409
410410 try test__powitf2(-0.0, -1, -inf_f128);
411411 try test__powitf2(-0.0, -2, inf_f128);
412412 try test__powitf2(-0.0, -3, -inf_f128);
413413 try test__powitf2(-0.0, -4, inf_f128);
414 try test__powitf2(-0.0, @bitCast(i32, @as(u32, 0x80000002)), inf_f128);
415 try test__powitf2(-0.0, @bitCast(i32, @as(u32, 0x80000001)), -inf_f128);
416 try test__powitf2(-0.0, @bitCast(i32, @as(u32, 0x80000000)), inf_f128);
414 try test__powitf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f128);
415 try test__powitf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000001))), -inf_f128);
416 try test__powitf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f128);
417417
418418 try test__powitf2(1, -1, 1);
419419 try test__powitf2(1, -2, 1);
420420 try test__powitf2(1, -3, 1);
421421 try test__powitf2(1, -4, 1);
422 try test__powitf2(1, @bitCast(i32, @as(u32, 0x80000002)), 1);
423 try test__powitf2(1, @bitCast(i32, @as(u32, 0x80000001)), 1);
424 try test__powitf2(1, @bitCast(i32, @as(u32, 0x80000000)), 1);
422 try test__powitf2(1, @as(i32, @bitCast(@as(u32, 0x80000002))), 1);
423 try test__powitf2(1, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
424 try test__powitf2(1, @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
425425
426426 try test__powitf2(inf_f128, -1, 0);
427427 try test__powitf2(inf_f128, -2, 0);
428428 try test__powitf2(inf_f128, -3, 0);
429429 try test__powitf2(inf_f128, -4, 0);
430 try test__powitf2(inf_f128, @bitCast(i32, @as(u32, 0x80000002)), 0);
431 try test__powitf2(inf_f128, @bitCast(i32, @as(u32, 0x80000001)), 0);
432 try test__powitf2(inf_f128, @bitCast(i32, @as(u32, 0x80000000)), 0);
430 try test__powitf2(inf_f128, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
431 try test__powitf2(inf_f128, @as(i32, @bitCast(@as(u32, 0x80000001))), 0);
432 try test__powitf2(inf_f128, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
433433
434434 try test__powitf2(-inf_f128, -1, -0.0);
435435 try test__powitf2(-inf_f128, -2, 0);
436436 try test__powitf2(-inf_f128, -3, -0.0);
437437 try test__powitf2(-inf_f128, -4, 0);
438 try test__powitf2(-inf_f128, @bitCast(i32, @as(u32, 0x80000002)), 0);
439 try test__powitf2(-inf_f128, @bitCast(i32, @as(u32, 0x80000001)), -0.0);
440 try test__powitf2(-inf_f128, @bitCast(i32, @as(u32, 0x80000000)), 0);
438 try test__powitf2(-inf_f128, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
439 try test__powitf2(-inf_f128, @as(i32, @bitCast(@as(u32, 0x80000001))), -0.0);
440 try test__powitf2(-inf_f128, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
441441
442442 try test__powitf2(2, 10, 1024.0);
443443 try test__powitf2(-2, 10, 1024.0);
......@@ -473,76 +473,76 @@ test "powixf2" {
473473 try test__powixf2(0, 2, 0);
474474 try test__powixf2(0, 3, 0);
475475 try test__powixf2(0, 4, 0);
476 try test__powixf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
477 try test__powixf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 0);
476 try test__powixf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
477 try test__powixf2(0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 0);
478478
479479 try test__powixf2(-0.0, 1, -0.0);
480480 try test__powixf2(-0.0, 2, 0);
481481 try test__powixf2(-0.0, 3, -0.0);
482482 try test__powixf2(-0.0, 4, 0);
483 try test__powixf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
484 try test__powixf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -0.0);
483 try test__powixf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 0);
484 try test__powixf2(-0.0, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -0.0);
485485
486486 try test__powixf2(1, 1, 1);
487487 try test__powixf2(1, 2, 1);
488488 try test__powixf2(1, 3, 1);
489489 try test__powixf2(1, 4, 1);
490 try test__powixf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 1);
491 try test__powixf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 1);
490 try test__powixf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), 1);
491 try test__powixf2(1, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), 1);
492492
493493 try test__powixf2(inf_f80, 1, inf_f80);
494494 try test__powixf2(inf_f80, 2, inf_f80);
495495 try test__powixf2(inf_f80, 3, inf_f80);
496496 try test__powixf2(inf_f80, 4, inf_f80);
497 try test__powixf2(inf_f80, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f80);
498 try test__powixf2(inf_f80, @bitCast(i32, @as(u32, 0x7FFFFFFF)), inf_f80);
497 try test__powixf2(inf_f80, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f80);
498 try test__powixf2(inf_f80, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), inf_f80);
499499
500500 try test__powixf2(-inf_f80, 1, -inf_f80);
501501 try test__powixf2(-inf_f80, 2, inf_f80);
502502 try test__powixf2(-inf_f80, 3, -inf_f80);
503503 try test__powixf2(-inf_f80, 4, inf_f80);
504 try test__powixf2(-inf_f80, @bitCast(i32, @as(u32, 0x7FFFFFFE)), inf_f80);
505 try test__powixf2(-inf_f80, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -inf_f80);
504 try test__powixf2(-inf_f80, @as(i32, @bitCast(@as(u32, 0x7FFFFFFE))), inf_f80);
505 try test__powixf2(-inf_f80, @as(i32, @bitCast(@as(u32, 0x7FFFFFFF))), -inf_f80);
506506
507507 try test__powixf2(0, -1, inf_f80);
508508 try test__powixf2(0, -2, inf_f80);
509509 try test__powixf2(0, -3, inf_f80);
510510 try test__powixf2(0, -4, inf_f80);
511 try test__powixf2(0, @bitCast(i32, @as(u32, 0x80000002)), inf_f80);
512 try test__powixf2(0, @bitCast(i32, @as(u32, 0x80000001)), inf_f80);
513 try test__powixf2(0, @bitCast(i32, @as(u32, 0x80000000)), inf_f80);
511 try test__powixf2(0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f80);
512 try test__powixf2(0, @as(i32, @bitCast(@as(u32, 0x80000001))), inf_f80);
513 try test__powixf2(0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f80);
514514
515515 try test__powixf2(-0.0, -1, -inf_f80);
516516 try test__powixf2(-0.0, -2, inf_f80);
517517 try test__powixf2(-0.0, -3, -inf_f80);
518518 try test__powixf2(-0.0, -4, inf_f80);
519 try test__powixf2(-0.0, @bitCast(i32, @as(u32, 0x80000002)), inf_f80);
520 try test__powixf2(-0.0, @bitCast(i32, @as(u32, 0x80000001)), -inf_f80);
521 try test__powixf2(-0.0, @bitCast(i32, @as(u32, 0x80000000)), inf_f80);
519 try test__powixf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000002))), inf_f80);
520 try test__powixf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000001))), -inf_f80);
521 try test__powixf2(-0.0, @as(i32, @bitCast(@as(u32, 0x80000000))), inf_f80);
522522
523523 try test__powixf2(1, -1, 1);
524524 try test__powixf2(1, -2, 1);
525525 try test__powixf2(1, -3, 1);
526526 try test__powixf2(1, -4, 1);
527 try test__powixf2(1, @bitCast(i32, @as(u32, 0x80000002)), 1);
528 try test__powixf2(1, @bitCast(i32, @as(u32, 0x80000001)), 1);
529 try test__powixf2(1, @bitCast(i32, @as(u32, 0x80000000)), 1);
527 try test__powixf2(1, @as(i32, @bitCast(@as(u32, 0x80000002))), 1);
528 try test__powixf2(1, @as(i32, @bitCast(@as(u32, 0x80000001))), 1);
529 try test__powixf2(1, @as(i32, @bitCast(@as(u32, 0x80000000))), 1);
530530
531531 try test__powixf2(inf_f80, -1, 0);
532532 try test__powixf2(inf_f80, -2, 0);
533533 try test__powixf2(inf_f80, -3, 0);
534534 try test__powixf2(inf_f80, -4, 0);
535 try test__powixf2(inf_f80, @bitCast(i32, @as(u32, 0x80000002)), 0);
536 try test__powixf2(inf_f80, @bitCast(i32, @as(u32, 0x80000001)), 0);
537 try test__powixf2(inf_f80, @bitCast(i32, @as(u32, 0x80000000)), 0);
535 try test__powixf2(inf_f80, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
536 try test__powixf2(inf_f80, @as(i32, @bitCast(@as(u32, 0x80000001))), 0);
537 try test__powixf2(inf_f80, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
538538
539539 try test__powixf2(-inf_f80, -1, -0.0);
540540 try test__powixf2(-inf_f80, -2, 0);
541541 try test__powixf2(-inf_f80, -3, -0.0);
542542 try test__powixf2(-inf_f80, -4, 0);
543 try test__powixf2(-inf_f80, @bitCast(i32, @as(u32, 0x80000002)), 0);
544 try test__powixf2(-inf_f80, @bitCast(i32, @as(u32, 0x80000001)), -0.0);
545 try test__powixf2(-inf_f80, @bitCast(i32, @as(u32, 0x80000000)), 0);
543 try test__powixf2(-inf_f80, @as(i32, @bitCast(@as(u32, 0x80000002))), 0);
544 try test__powixf2(-inf_f80, @as(i32, @bitCast(@as(u32, 0x80000001))), -0.0);
545 try test__powixf2(-inf_f80, @as(i32, @bitCast(@as(u32, 0x80000000))), 0);
546546
547547 try test__powixf2(2, 10, 1024.0);
548548 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
2626const pio2_3t = 8.47842766036889956997e-32; // 0x397B839A, 0x252049C1
2727
2828fn U(x: anytype) usize {
29 return @intCast(usize, x);
29 return @as(usize, @intCast(x));
3030}
3131
3232fn medium(ix: u32, x: f64, y: *[2]f64) i32 {
......@@ -41,7 +41,7 @@ fn medium(ix: u32, x: f64, y: *[2]f64) i32 {
4141
4242 // rint(x/(pi/2))
4343 @"fn" = x * invpio2 + toint - toint;
44 n = @intFromFloat(i32, @"fn");
44 n = @as(i32, @intFromFloat(@"fn"));
4545 r = x - @"fn" * pio2_1;
4646 w = @"fn" * pio2_1t; // 1st round, good to 85 bits
4747 // Matters with directed rounding.
......@@ -57,17 +57,17 @@ fn medium(ix: u32, x: f64, y: *[2]f64) i32 {
5757 w = @"fn" * pio2_1t;
5858 }
5959 y[0] = r - w;
60 ui = @bitCast(u64, y[0]);
61 ey = @intCast(i32, (ui >> 52) & 0x7ff);
62 ex = @intCast(i32, ix >> 20);
60 ui = @as(u64, @bitCast(y[0]));
61 ey = @as(i32, @intCast((ui >> 52) & 0x7ff));
62 ex = @as(i32, @intCast(ix >> 20));
6363 if (ex - ey > 16) { // 2nd round, good to 118 bits
6464 t = r;
6565 w = @"fn" * pio2_2;
6666 r = t - w;
6767 w = @"fn" * pio2_2t - ((t - r) - w);
6868 y[0] = r - w;
69 ui = @bitCast(u64, y[0]);
70 ey = @intCast(i32, (ui >> 52) & 0x7ff);
69 ui = @as(u64, @bitCast(y[0]));
70 ey = @as(i32, @intCast((ui >> 52) & 0x7ff));
7171 if (ex - ey > 49) { // 3rd round, good to 151 bits, covers all cases
7272 t = r;
7373 w = @"fn" * pio2_3;
......@@ -95,9 +95,9 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 {
9595 var i: i32 = undefined;
9696 var ui: u64 = undefined;
9797
98 ui = @bitCast(u64, x);
98 ui = @as(u64, @bitCast(x));
9999 sign = ui >> 63 != 0;
100 ix = @truncate(u32, (ui >> 32) & 0x7fffffff);
100 ix = @as(u32, @truncate((ui >> 32) & 0x7fffffff));
101101 if (ix <= 0x400f6a7a) { // |x| ~<= 5pi/4
102102 if ((ix & 0xfffff) == 0x921fb) { // |x| ~= pi/2 or 2pi/2
103103 return medium(ix, x, y);
......@@ -171,14 +171,14 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 {
171171 return 0;
172172 }
173173 // set z = scalbn(|x|,-ilogb(x)+23)
174 ui = @bitCast(u64, x);
174 ui = @as(u64, @bitCast(x));
175175 ui &= std.math.maxInt(u64) >> 12;
176176 ui |= @as(u64, 0x3ff + 23) << 52;
177 z = @bitCast(f64, ui);
177 z = @as(f64, @bitCast(ui));
178178
179179 i = 0;
180180 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))));
182182 z = (z - tx[U(i)]) * 0x1p24;
183183 }
184184 tx[U(i)] = z;
......@@ -186,7 +186,7 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 {
186186 while (tx[U(i)] == 0.0) {
187187 i -= 1;
188188 }
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);
190190 if (sign) {
191191 y[0] = -ty[0];
192192 y[1] = -ty[1];
lib/compiler_rt/rem_pio2_large.zig+15-15
......@@ -150,7 +150,7 @@ const PIo2 = [_]f64{
150150};
151151
152152fn U(x: anytype) usize {
153 return @intCast(usize, x);
153 return @as(usize, @intCast(x));
154154}
155155
156156/// 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 {
295295 i += 1;
296296 j += 1;
297297 }) {
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)]));
299299 }
300300
301301 // 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 {
322322 i += 1;
323323 j -= 1;
324324 }) {
325 fw = @floatFromInt(f64, @intFromFloat(i32, 0x1p-24 * z));
326 iq[U(i)] = @intFromFloat(i32, z - 0x1p24 * fw);
325 fw = @as(f64, @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z))));
326 iq[U(i)] = @as(i32, @intFromFloat(z - 0x1p24 * fw));
327327 z = q[U(j - 1)] + fw;
328328 }
329329
330330 // compute n
331331 z = math.scalbn(z, q0); // actual value of z
332332 z -= 8.0 * @floor(z * 0.125); // trim off integer >= 8
333 n = @intFromFloat(i32, z);
334 z -= @floatFromInt(f64, n);
333 n = @as(i32, @intFromFloat(z));
334 z -= @as(f64, @floatFromInt(n));
335335 ih = 0;
336336 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));
338338 n += i;
339 iq[U(jz - 1)] -= i << @intCast(u5, 24 - q0);
340 ih = iq[U(jz - 1)] >> @intCast(u5, 23 - q0);
339 iq[U(jz - 1)] -= i << @as(u5, @intCast(24 - q0));
340 ih = iq[U(jz - 1)] >> @as(u5, @intCast(23 - q0));
341341 } else if (q0 == 0) {
342342 ih = iq[U(jz - 1)] >> 23;
343343 } 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 {
390390
391391 i = jz + 1;
392392 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)]));
394394 j = 0;
395395 fw = 0;
396396 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 {
414414 } else { // break z into 24-bit if necessary
415415 z = math.scalbn(z, -q0);
416416 if (z >= 0x1p24) {
417 fw = @floatFromInt(f64, @intFromFloat(i32, 0x1p-24 * z));
418 iq[U(jz)] = @intFromFloat(i32, z - 0x1p24 * fw);
417 fw = @as(f64, @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z))));
418 iq[U(jz)] = @as(i32, @intFromFloat(z - 0x1p24 * fw));
419419 jz += 1;
420420 q0 += 24;
421 iq[U(jz)] = @intFromFloat(i32, fw);
421 iq[U(jz)] = @as(i32, @intFromFloat(fw));
422422 } else {
423 iq[U(jz)] = @intFromFloat(i32, z);
423 iq[U(jz)] = @as(i32, @intFromFloat(z));
424424 }
425425 }
426426
......@@ -428,7 +428,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
428428 fw = math.scalbn(@as(f64, 1.0), q0);
429429 i = jz;
430430 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)]));
432432 fw *= 0x1p-24;
433433 }
434434
lib/compiler_rt/rem_pio2f.zig+5-5
......@@ -30,14 +30,14 @@ pub fn rem_pio2f(x: f32, y: *f64) i32 {
3030 var e0: u32 = undefined;
3131 var ui: u32 = undefined;
3232
33 ui = @bitCast(u32, x);
33 ui = @as(u32, @bitCast(x));
3434 ix = ui & 0x7fffffff;
3535
3636 // 25+53 bit pi is good enough for medium size
3737 if (ix < 0x4dc90fdb) { // |x| ~< 2^28*(pi/2), medium size
3838 // Use a specialized rint() to get fn.
39 @"fn" = @floatCast(f64, x) * invpio2 + toint - toint;
40 n = @intFromFloat(i32, @"fn");
39 @"fn" = @as(f64, @floatCast(x)) * invpio2 + toint - toint;
40 n = @as(i32, @intFromFloat(@"fn"));
4141 y.* = x - @"fn" * pio2_1 - @"fn" * pio2_1t;
4242 // Matters with directed rounding.
4343 if (y.* < -pio4) {
......@@ -59,8 +59,8 @@ pub fn rem_pio2f(x: f32, y: *f64) i32 {
5959 sign = ui >> 31 != 0;
6060 e0 = (ix >> 23) - (0x7f + 23); // e0 = ilogb(|x|)-23, positive
6161 ui = ix - (e0 << 23);
62 tx[0] = @bitCast(f32, ui);
63 n = rem_pio2_large(&tx, &ty, @intCast(i32, e0), 1, 0);
62 tx[0] = @as(f32, @bitCast(ui));
63 n = rem_pio2_large(&tx, &ty, @as(i32, @intCast(e0)), 1, 0);
6464 if (sign) {
6565 y.* = -ty[0];
6666 return -n;
lib/compiler_rt/round.zig+8-8
......@@ -27,14 +27,14 @@ comptime {
2727
2828pub fn __roundh(x: f16) callconv(.C) f16 {
2929 // TODO: more efficient implementation
30 return @floatCast(f16, roundf(x));
30 return @as(f16, @floatCast(roundf(x)));
3131}
3232
3333pub fn roundf(x_: f32) callconv(.C) f32 {
3434 const f32_toint = 1.0 / math.floatEps(f32);
3535
3636 var x = x_;
37 const u = @bitCast(u32, x);
37 const u = @as(u32, @bitCast(x));
3838 const e = (u >> 23) & 0xFF;
3939 var y: f32 = undefined;
4040
......@@ -46,7 +46,7 @@ pub fn roundf(x_: f32) callconv(.C) f32 {
4646 }
4747 if (e < 0x7F - 1) {
4848 math.doNotOptimizeAway(x + f32_toint);
49 return 0 * @bitCast(f32, u);
49 return 0 * @as(f32, @bitCast(u));
5050 }
5151
5252 y = x + f32_toint - f32_toint - x;
......@@ -69,7 +69,7 @@ pub fn round(x_: f64) callconv(.C) f64 {
6969 const f64_toint = 1.0 / math.floatEps(f64);
7070
7171 var x = x_;
72 const u = @bitCast(u64, x);
72 const u = @as(u64, @bitCast(x));
7373 const e = (u >> 52) & 0x7FF;
7474 var y: f64 = undefined;
7575
......@@ -81,7 +81,7 @@ pub fn round(x_: f64) callconv(.C) f64 {
8181 }
8282 if (e < 0x3ff - 1) {
8383 math.doNotOptimizeAway(x + f64_toint);
84 return 0 * @bitCast(f64, u);
84 return 0 * @as(f64, @bitCast(u));
8585 }
8686
8787 y = x + f64_toint - f64_toint - x;
......@@ -102,14 +102,14 @@ pub fn round(x_: f64) callconv(.C) f64 {
102102
103103pub fn __roundx(x: f80) callconv(.C) f80 {
104104 // TODO: more efficient implementation
105 return @floatCast(f80, roundq(x));
105 return @as(f80, @floatCast(roundq(x)));
106106}
107107
108108pub fn roundq(x_: f128) callconv(.C) f128 {
109109 const f128_toint = 1.0 / math.floatEps(f128);
110110
111111 var x = x_;
112 const u = @bitCast(u128, x);
112 const u = @as(u128, @bitCast(x));
113113 const e = (u >> 112) & 0x7FFF;
114114 var y: f128 = undefined;
115115
......@@ -121,7 +121,7 @@ pub fn roundq(x_: f128) callconv(.C) f128 {
121121 }
122122 if (e < 0x3FFF - 1) {
123123 math.doNotOptimizeAway(x + f128_toint);
124 return 0 * @bitCast(f128, u);
124 return 0 * @as(f128, @bitCast(u));
125125 }
126126
127127 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 {
3737
3838 if (b >= word_t.bits) {
3939 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));
4141 } else if (b == 0) {
4242 return a;
4343 } else {
44 output.s.low = input.s.low << @intCast(S, b);
45 output.s.high = input.s.high << @intCast(S, b);
46 output.s.high |= input.s.low >> @intCast(S, word_t.bits - b);
44 output.s.low = input.s.low << @as(S, @intCast(b));
45 output.s.high = input.s.high << @as(S, @intCast(b));
46 output.s.high |= input.s.low >> @as(S, @intCast(word_t.bits - b));
4747 }
4848
4949 return output.all;
......@@ -60,16 +60,16 @@ inline fn ashrXi3(comptime T: type, a: T, b: i32) T {
6060
6161 if (b >= word_t.bits) {
6262 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));
6464 } else if (b == 0) {
6565 return a;
6666 } else {
67 output.s.high = input.s.high >> @intCast(S, b);
68 output.s.low = input.s.high << @intCast(S, word_t.bits - b);
67 output.s.high = input.s.high >> @as(S, @intCast(b));
68 output.s.low = input.s.high << @as(S, @intCast(word_t.bits - b));
6969 // Avoid sign-extension here
70 output.s.low |= @bitCast(
70 output.s.low |= @as(
7171 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))),
7373 );
7474 }
7575
......@@ -87,13 +87,13 @@ inline fn lshrXi3(comptime T: type, a: T, b: i32) T {
8787
8888 if (b >= word_t.bits) {
8989 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));
9191 } else if (b == 0) {
9292 return a;
9393 } else {
94 output.s.high = input.s.high >> @intCast(S, b);
95 output.s.low = input.s.high << @intCast(S, word_t.bits - b);
96 output.s.low |= input.s.low >> @intCast(S, b);
94 output.s.high = input.s.high >> @as(S, @intCast(b));
95 output.s.low = input.s.high << @as(S, @intCast(word_t.bits - b));
96 output.s.low |= input.s.low >> @as(S, @intCast(b));
9797 }
9898
9999 return output.all;
lib/compiler_rt/shift_test.zig+289-289
......@@ -18,346 +18,346 @@ const __lshrti3 = shift.__lshrti3;
1818
1919fn test__ashlsi3(a: i32, b: i32, expected: u32) !void {
2020 const x = __ashlsi3(a, b);
21 try testing.expectEqual(expected, @bitCast(u32, x));
21 try testing.expectEqual(expected, @as(u32, @bitCast(x)));
2222}
2323fn test__ashldi3(a: i64, b: i32, expected: u64) !void {
2424 const x = __ashldi3(a, b);
25 try testing.expectEqual(expected, @bitCast(u64, x));
25 try testing.expectEqual(expected, @as(u64, @bitCast(x)));
2626}
2727fn test__ashlti3(a: i128, b: i32, expected: u128) !void {
2828 const x = __ashlti3(a, b);
29 try testing.expectEqual(expected, @bitCast(u128, x));
29 try testing.expectEqual(expected, @as(u128, @bitCast(x)));
3030}
3131
3232test "ashlsi3" {
33 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 0, 0x12ABCDEF);
34 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 1, 0x25579BDE);
35 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 2, 0x4AAF37BC);
36 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 3, 0x955E6F78);
37 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 4, 0x2ABCDEF0);
38
39 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 28, 0xF0000000);
40 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 29, 0xE0000000);
41 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 30, 0xC0000000);
42 try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 31, 0x80000000);
33 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 0, 0x12ABCDEF);
34 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 1, 0x25579BDE);
35 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 2, 0x4AAF37BC);
36 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 3, 0x955E6F78);
37 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 4, 0x2ABCDEF0);
38
39 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 28, 0xF0000000);
40 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 29, 0xE0000000);
41 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 30, 0xC0000000);
42 try test__ashlsi3(@as(i32, @bitCast(@as(u32, 0x12ABCDEF))), 31, 0x80000000);
4343}
4444
4545test "ashldi3" {
46 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
47 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x2468ACF13579BDE);
48 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37BC);
49 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x91A2B3C4D5E6F78);
50 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDEF0);
51
52 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x789ABCDEF0000000);
53 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0xF13579BDE0000000);
54 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0xE26AF37BC0000000);
55 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0xC4D5E6F780000000);
56
57 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x89ABCDEF00000000);
58
59 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x13579BDE00000000);
60 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x26AF37BC00000000);
61 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x4D5E6F7800000000);
62 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x9ABCDEF000000000);
63
64 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0xF000000000000000);
65 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0xE000000000000000);
66 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0xC000000000000000);
67 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0x8000000000000000);
46 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 0, 0x123456789ABCDEF);
47 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 1, 0x2468ACF13579BDE);
48 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 2, 0x48D159E26AF37BC);
49 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 3, 0x91A2B3C4D5E6F78);
50 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 4, 0x123456789ABCDEF0);
51
52 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 28, 0x789ABCDEF0000000);
53 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 29, 0xF13579BDE0000000);
54 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 30, 0xE26AF37BC0000000);
55 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 31, 0xC4D5E6F780000000);
56
57 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 32, 0x89ABCDEF00000000);
58
59 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 33, 0x13579BDE00000000);
60 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 34, 0x26AF37BC00000000);
61 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 35, 0x4D5E6F7800000000);
62 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 36, 0x9ABCDEF000000000);
63
64 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 60, 0xF000000000000000);
65 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 61, 0xE000000000000000);
66 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 62, 0xC000000000000000);
67 try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 63, 0x8000000000000000);
6868}
6969
7070test "ashlti3" {
71 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, 0xFEDCBA9876543215FEDCBA9876543215);
72 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, 0xFDB97530ECA8642BFDB97530ECA8642A);
73 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, 0xFB72EA61D950C857FB72EA61D950C854);
74 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, 0xF6E5D4C3B2A190AFF6E5D4C3B2A190A8);
75 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, 0xEDCBA9876543215FEDCBA98765432150);
76 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, 0x876543215FEDCBA98765432150000000);
77 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, 0x0ECA8642BFDB97530ECA8642A0000000);
78 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, 0x1D950C857FB72EA61D950C8540000000);
79 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, 0x3B2A190AFF6E5D4C3B2A190A80000000);
80 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, 0x76543215FEDCBA987654321500000000);
81 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, 0xECA8642BFDB97530ECA8642A00000000);
82 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, 0xD950C857FB72EA61D950C85400000000);
83 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, 0xB2A190AFF6E5D4C3B2A190A800000000);
84 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, 0x6543215FEDCBA9876543215000000000);
85 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, 0x5FEDCBA9876543215000000000000000);
86 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, 0xBFDB97530ECA8642A000000000000000);
87 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, 0x7FB72EA61D950C854000000000000000);
88 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, 0xFF6E5D4C3B2A190A8000000000000000);
89 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, 0xFEDCBA98765432150000000000000000);
90 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, 0xFDB97530ECA8642A0000000000000000);
91 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, 0xFB72EA61D950C8540000000000000000);
92 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, 0xF6E5D4C3B2A190A80000000000000000);
93 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, 0xEDCBA987654321500000000000000000);
94 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, 0x87654321500000000000000000000000);
95 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, 0x0ECA8642A00000000000000000000000);
96 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, 0x1D950C85400000000000000000000000);
97 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, 0x3B2A190A800000000000000000000000);
98 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, 0x76543215000000000000000000000000);
99 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, 0xECA8642A000000000000000000000000);
100 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, 0xD950C854000000000000000000000000);
101 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, 0xB2A190A8000000000000000000000000);
102 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, 0x65432150000000000000000000000000);
103 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, 0x50000000000000000000000000000000);
104 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, 0xA0000000000000000000000000000000);
105 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, 0x40000000000000000000000000000000);
106 try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, 0x80000000000000000000000000000000);
71 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 0, 0xFEDCBA9876543215FEDCBA9876543215);
72 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 1, 0xFDB97530ECA8642BFDB97530ECA8642A);
73 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 2, 0xFB72EA61D950C857FB72EA61D950C854);
74 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 3, 0xF6E5D4C3B2A190AFF6E5D4C3B2A190A8);
75 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 4, 0xEDCBA9876543215FEDCBA98765432150);
76 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 28, 0x876543215FEDCBA98765432150000000);
77 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 29, 0x0ECA8642BFDB97530ECA8642A0000000);
78 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 30, 0x1D950C857FB72EA61D950C8540000000);
79 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 31, 0x3B2A190AFF6E5D4C3B2A190A80000000);
80 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 32, 0x76543215FEDCBA987654321500000000);
81 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 33, 0xECA8642BFDB97530ECA8642A00000000);
82 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 34, 0xD950C857FB72EA61D950C85400000000);
83 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 35, 0xB2A190AFF6E5D4C3B2A190A800000000);
84 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 36, 0x6543215FEDCBA9876543215000000000);
85 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 60, 0x5FEDCBA9876543215000000000000000);
86 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 61, 0xBFDB97530ECA8642A000000000000000);
87 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 62, 0x7FB72EA61D950C854000000000000000);
88 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 63, 0xFF6E5D4C3B2A190A8000000000000000);
89 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 64, 0xFEDCBA98765432150000000000000000);
90 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 65, 0xFDB97530ECA8642A0000000000000000);
91 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 66, 0xFB72EA61D950C8540000000000000000);
92 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 67, 0xF6E5D4C3B2A190A80000000000000000);
93 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 68, 0xEDCBA987654321500000000000000000);
94 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 92, 0x87654321500000000000000000000000);
95 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 93, 0x0ECA8642A00000000000000000000000);
96 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 94, 0x1D950C85400000000000000000000000);
97 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 95, 0x3B2A190A800000000000000000000000);
98 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 96, 0x76543215000000000000000000000000);
99 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 97, 0xECA8642A000000000000000000000000);
100 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 98, 0xD950C854000000000000000000000000);
101 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 99, 0xB2A190A8000000000000000000000000);
102 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 100, 0x65432150000000000000000000000000);
103 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 124, 0x50000000000000000000000000000000);
104 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 125, 0xA0000000000000000000000000000000);
105 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 126, 0x40000000000000000000000000000000);
106 try test__ashlti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 127, 0x80000000000000000000000000000000);
107107}
108108
109109fn test__ashrsi3(a: i32, b: i32, expected: u32) !void {
110110 const x = __ashrsi3(a, b);
111 try testing.expectEqual(expected, @bitCast(u32, x));
111 try testing.expectEqual(expected, @as(u32, @bitCast(x)));
112112}
113113fn test__ashrdi3(a: i64, b: i32, expected: u64) !void {
114114 const x = __ashrdi3(a, b);
115 try testing.expectEqual(expected, @bitCast(u64, x));
115 try testing.expectEqual(expected, @as(u64, @bitCast(x)));
116116}
117117fn test__ashrti3(a: i128, b: i32, expected: u128) !void {
118118 const x = __ashrti3(a, b);
119 try testing.expectEqual(expected, @bitCast(u128, x));
119 try testing.expectEqual(expected, @as(u128, @bitCast(x)));
120120}
121121
122122test "ashrsi3" {
123 try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 0, 0xFEDBCA98);
124 try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 1, 0xFF6DE54C);
125 try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 2, 0xFFB6F2A6);
126 try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 3, 0xFFDB7953);
127 try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 4, 0xFFEDBCA9);
128
129 try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 28, 0xFFFFFFFF);
130 try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 31, 0xFFFFFFFF);
131
132 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 0, 0x8CEF8CEF);
133 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 1, 0xC677C677);
134 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 2, 0xE33BE33B);
135 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 3, 0xF19DF19D);
136 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 4, 0xF8CEF8CE);
137
138 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 28, 0xFFFFFFF8);
139 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 29, 0xFFFFFFFC);
140 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 30, 0xFFFFFFFE);
141 try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 31, 0xFFFFFFFF);
123 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 0, 0xFEDBCA98);
124 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 1, 0xFF6DE54C);
125 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 2, 0xFFB6F2A6);
126 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 3, 0xFFDB7953);
127 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 4, 0xFFEDBCA9);
128
129 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 28, 0xFFFFFFFF);
130 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 31, 0xFFFFFFFF);
131
132 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 0, 0x8CEF8CEF);
133 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 1, 0xC677C677);
134 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 2, 0xE33BE33B);
135 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 3, 0xF19DF19D);
136 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 4, 0xF8CEF8CE);
137
138 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 28, 0xFFFFFFF8);
139 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 29, 0xFFFFFFFC);
140 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 30, 0xFFFFFFFE);
141 try test__ashrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 31, 0xFFFFFFFF);
142142}
143143
144144test "ashrdi3" {
145 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
146 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
147 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
148 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
149 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
150
151 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
152 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
153 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
154 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
155
156 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
157
158 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
159 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
160 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
161 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
162
163 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
164 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
165 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
166 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
167
168 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
169 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0xFF6E5D4C3B2A1908);
170 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0xFFB72EA61D950C84);
171 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0xFFDB97530ECA8642);
172 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFFEDCBA987654321);
173
174 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFFFFFFFFEDCBA987);
175 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0xFFFFFFFFF6E5D4C3);
176 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0xFFFFFFFFFB72EA61);
177 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0xFFFFFFFFFDB97530);
178
179 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFFFFFFFFFEDCBA98);
180
181 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0xFFFFFFFFFF6E5D4C);
182 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0xFFFFFFFFFFB72EA6);
183 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0xFFFFFFFFFFDB9753);
184 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFFFFFFFFFFEDCBA9);
185
186 try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xFFFFFFFFFFFFFFFA);
187 try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0xFFFFFFFFFFFFFFFD);
188 try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0xFFFFFFFFFFFFFFFE);
189 try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0xFFFFFFFFFFFFFFFF);
145 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 0, 0x123456789ABCDEF);
146 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 1, 0x91A2B3C4D5E6F7);
147 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 2, 0x48D159E26AF37B);
148 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 3, 0x2468ACF13579BD);
149 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 4, 0x123456789ABCDE);
150
151 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 28, 0x12345678);
152 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 29, 0x91A2B3C);
153 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 30, 0x48D159E);
154 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 31, 0x2468ACF);
155
156 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 32, 0x1234567);
157
158 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 33, 0x91A2B3);
159 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 34, 0x48D159);
160 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 35, 0x2468AC);
161 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 36, 0x123456);
162
163 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 60, 0);
164 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 61, 0);
165 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 62, 0);
166 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 63, 0);
167
168 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 0, 0xFEDCBA9876543210);
169 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 1, 0xFF6E5D4C3B2A1908);
170 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 2, 0xFFB72EA61D950C84);
171 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 3, 0xFFDB97530ECA8642);
172 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 4, 0xFFEDCBA987654321);
173
174 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 28, 0xFFFFFFFFEDCBA987);
175 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 29, 0xFFFFFFFFF6E5D4C3);
176 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 30, 0xFFFFFFFFFB72EA61);
177 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 31, 0xFFFFFFFFFDB97530);
178
179 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 32, 0xFFFFFFFFFEDCBA98);
180
181 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 33, 0xFFFFFFFFFF6E5D4C);
182 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 34, 0xFFFFFFFFFFB72EA6);
183 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 35, 0xFFFFFFFFFFDB9753);
184 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 36, 0xFFFFFFFFFFEDCBA9);
185
186 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xAEDCBA9876543210))), 60, 0xFFFFFFFFFFFFFFFA);
187 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xAEDCBA9876543210))), 61, 0xFFFFFFFFFFFFFFFD);
188 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xAEDCBA9876543210))), 62, 0xFFFFFFFFFFFFFFFE);
189 try test__ashrdi3(@as(i64, @bitCast(@as(u64, 0xAEDCBA9876543210))), 63, 0xFFFFFFFFFFFFFFFF);
190190}
191191
192192test "ashrti3" {
193 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, 0xFEDCBA9876543215FEDCBA9876543215);
194 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, 0xFF6E5D4C3B2A190AFF6E5D4C3B2A190A);
195 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, 0xFFB72EA61D950C857FB72EA61D950C85);
196 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, 0xFFDB97530ECA8642BFDB97530ECA8642);
197 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, 0xFFEDCBA9876543215FEDCBA987654321);
198
199 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, 0xFFFFFFFFEDCBA9876543215FEDCBA987);
200 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, 0xFFFFFFFFF6E5D4C3B2A190AFF6E5D4C3);
201 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, 0xFFFFFFFFFB72EA61D950C857FB72EA61);
202 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, 0xFFFFFFFFFDB97530ECA8642BFDB97530);
203
204 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, 0xFFFFFFFFFEDCBA9876543215FEDCBA98);
205
206 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, 0xFFFFFFFFFF6E5D4C3B2A190AFF6E5D4C);
207 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, 0xFFFFFFFFFFB72EA61D950C857FB72EA6);
208 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, 0xFFFFFFFFFFDB97530ECA8642BFDB9753);
209 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, 0xFFFFFFFFFFEDCBA9876543215FEDCBA9);
210
211 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, 0xFFFFFFFFFFFFFFFFEDCBA9876543215F);
212 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, 0xFFFFFFFFFFFFFFFFF6E5D4C3B2A190AF);
213 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, 0xFFFFFFFFFFFFFFFFFB72EA61D950C857);
214 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, 0xFFFFFFFFFFFFFFFFFDB97530ECA8642B);
215
216 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, 0xFFFFFFFFFFFFFFFFFEDCBA9876543215);
217
218 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, 0xFFFFFFFFFFFFFFFFFF6E5D4C3B2A190A);
219 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, 0xFFFFFFFFFFFFFFFFFFB72EA61D950C85);
220 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, 0xFFFFFFFFFFFFFFFFFFDB97530ECA8642);
221 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, 0xFFFFFFFFFFFFFFFFFFEDCBA987654321);
222
223 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, 0xFFFFFFFFFFFFFFFFFFFFFFFFEDCBA987);
224 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, 0xFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C3);
225 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, 0xFFFFFFFFFFFFFFFFFFFFFFFFFB72EA61);
226 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, 0xFFFFFFFFFFFFFFFFFFFFFFFFFDB97530);
227
228 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA98);
229
230 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, 0xFFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C);
231 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFB72EA6);
232 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFDB9753);
233 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA9);
234
235 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
236 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
237 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
238 try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
193 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 0, 0xFEDCBA9876543215FEDCBA9876543215);
194 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 1, 0xFF6E5D4C3B2A190AFF6E5D4C3B2A190A);
195 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 2, 0xFFB72EA61D950C857FB72EA61D950C85);
196 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 3, 0xFFDB97530ECA8642BFDB97530ECA8642);
197 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 4, 0xFFEDCBA9876543215FEDCBA987654321);
198
199 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 28, 0xFFFFFFFFEDCBA9876543215FEDCBA987);
200 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 29, 0xFFFFFFFFF6E5D4C3B2A190AFF6E5D4C3);
201 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 30, 0xFFFFFFFFFB72EA61D950C857FB72EA61);
202 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 31, 0xFFFFFFFFFDB97530ECA8642BFDB97530);
203
204 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 32, 0xFFFFFFFFFEDCBA9876543215FEDCBA98);
205
206 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 33, 0xFFFFFFFFFF6E5D4C3B2A190AFF6E5D4C);
207 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 34, 0xFFFFFFFFFFB72EA61D950C857FB72EA6);
208 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 35, 0xFFFFFFFFFFDB97530ECA8642BFDB9753);
209 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 36, 0xFFFFFFFFFFEDCBA9876543215FEDCBA9);
210
211 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 60, 0xFFFFFFFFFFFFFFFFEDCBA9876543215F);
212 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 61, 0xFFFFFFFFFFFFFFFFF6E5D4C3B2A190AF);
213 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 62, 0xFFFFFFFFFFFFFFFFFB72EA61D950C857);
214 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 63, 0xFFFFFFFFFFFFFFFFFDB97530ECA8642B);
215
216 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 64, 0xFFFFFFFFFFFFFFFFFEDCBA9876543215);
217
218 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 65, 0xFFFFFFFFFFFFFFFFFF6E5D4C3B2A190A);
219 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 66, 0xFFFFFFFFFFFFFFFFFFB72EA61D950C85);
220 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 67, 0xFFFFFFFFFFFFFFFFFFDB97530ECA8642);
221 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 68, 0xFFFFFFFFFFFFFFFFFFEDCBA987654321);
222
223 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 92, 0xFFFFFFFFFFFFFFFFFFFFFFFFEDCBA987);
224 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 93, 0xFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C3);
225 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 94, 0xFFFFFFFFFFFFFFFFFFFFFFFFFB72EA61);
226 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 95, 0xFFFFFFFFFFFFFFFFFFFFFFFFFDB97530);
227
228 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA98);
229
230 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 97, 0xFFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C);
231 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 98, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFB72EA6);
232 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 99, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFDB9753);
233 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 100, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA9);
234
235 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 124, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
236 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 125, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
237 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 126, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
238 try test__ashrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA9876543215))), 127, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
239239}
240240
241241fn test__lshrsi3(a: i32, b: i32, expected: u32) !void {
242242 const x = __lshrsi3(a, b);
243 try testing.expectEqual(expected, @bitCast(u32, x));
243 try testing.expectEqual(expected, @as(u32, @bitCast(x)));
244244}
245245fn test__lshrdi3(a: i64, b: i32, expected: u64) !void {
246246 const x = __lshrdi3(a, b);
247 try testing.expectEqual(expected, @bitCast(u64, x));
247 try testing.expectEqual(expected, @as(u64, @bitCast(x)));
248248}
249249fn test__lshrti3(a: i128, b: i32, expected: u128) !void {
250250 const x = __lshrti3(a, b);
251 try testing.expectEqual(expected, @bitCast(u128, x));
251 try testing.expectEqual(expected, @as(u128, @bitCast(x)));
252252}
253253
254254test "lshrsi3" {
255 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 0, 0xFEDBCA98);
256 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 1, 0x7F6DE54C);
257 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 2, 0x3FB6F2A6);
258 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 3, 0x1FDB7953);
259 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 4, 0xFEDBCA9);
260
261 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 28, 0xF);
262 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 29, 0x7);
263 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 30, 0x3);
264 try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 31, 0x1);
265
266 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 0, 0x8CEF8CEF);
267 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 1, 0x4677C677);
268 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 2, 0x233BE33B);
269 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 3, 0x119DF19D);
270 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 4, 0x8CEF8CE);
271
272 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 28, 0x8);
273 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 29, 0x4);
274 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 30, 0x2);
275 try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 31, 0x1);
255 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 0, 0xFEDBCA98);
256 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 1, 0x7F6DE54C);
257 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 2, 0x3FB6F2A6);
258 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 3, 0x1FDB7953);
259 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 4, 0xFEDBCA9);
260
261 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 28, 0xF);
262 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 29, 0x7);
263 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 30, 0x3);
264 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0xFEDBCA98))), 31, 0x1);
265
266 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 0, 0x8CEF8CEF);
267 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 1, 0x4677C677);
268 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 2, 0x233BE33B);
269 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 3, 0x119DF19D);
270 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 4, 0x8CEF8CE);
271
272 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 28, 0x8);
273 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 29, 0x4);
274 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 30, 0x2);
275 try test__lshrsi3(@as(i32, @bitCast(@as(u32, 0x8CEF8CEF))), 31, 0x1);
276276}
277277
278278test "lshrdi3" {
279 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
280 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
281 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
282 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
283 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
284
285 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
286 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
287 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
288 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
289
290 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
291
292 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
293 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
294 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
295 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
296
297 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
298 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
299 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
300 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
301
302 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
303 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0x7F6E5D4C3B2A1908);
304 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0x3FB72EA61D950C84);
305 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0x1FDB97530ECA8642);
306 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFEDCBA987654321);
307
308 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFEDCBA987);
309 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0x7F6E5D4C3);
310 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0x3FB72EA61);
311 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0x1FDB97530);
312
313 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFEDCBA98);
314
315 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0x7F6E5D4C);
316 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0x3FB72EA6);
317 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0x1FDB9753);
318 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFEDCBA9);
319
320 try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xA);
321 try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0x5);
322 try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0x2);
323 try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0x1);
279 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 0, 0x123456789ABCDEF);
280 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 1, 0x91A2B3C4D5E6F7);
281 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 2, 0x48D159E26AF37B);
282 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 3, 0x2468ACF13579BD);
283 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 4, 0x123456789ABCDE);
284
285 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 28, 0x12345678);
286 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 29, 0x91A2B3C);
287 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 30, 0x48D159E);
288 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 31, 0x2468ACF);
289
290 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 32, 0x1234567);
291
292 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 33, 0x91A2B3);
293 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 34, 0x48D159);
294 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 35, 0x2468AC);
295 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 36, 0x123456);
296
297 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 60, 0);
298 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 61, 0);
299 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 62, 0);
300 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 63, 0);
301
302 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 0, 0xFEDCBA9876543210);
303 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 1, 0x7F6E5D4C3B2A1908);
304 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 2, 0x3FB72EA61D950C84);
305 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 3, 0x1FDB97530ECA8642);
306 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 4, 0xFEDCBA987654321);
307
308 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 28, 0xFEDCBA987);
309 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 29, 0x7F6E5D4C3);
310 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 30, 0x3FB72EA61);
311 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 31, 0x1FDB97530);
312
313 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 32, 0xFEDCBA98);
314
315 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 33, 0x7F6E5D4C);
316 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 34, 0x3FB72EA6);
317 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 35, 0x1FDB9753);
318 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xFEDCBA9876543210))), 36, 0xFEDCBA9);
319
320 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xAEDCBA9876543210))), 60, 0xA);
321 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xAEDCBA9876543210))), 61, 0x5);
322 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xAEDCBA9876543210))), 62, 0x2);
323 try test__lshrdi3(@as(i64, @bitCast(@as(u64, 0xAEDCBA9876543210))), 63, 0x1);
324324}
325325
326326test "lshrti3" {
327 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 0, 0xFEDCBA9876543215FEDCBA987654321F);
328 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 1, 0x7F6E5D4C3B2A190AFF6E5D4C3B2A190F);
329 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 2, 0x3FB72EA61D950C857FB72EA61D950C87);
330 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 3, 0x1FDB97530ECA8642BFDB97530ECA8643);
331 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 4, 0xFEDCBA9876543215FEDCBA987654321);
332 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 28, 0xFEDCBA9876543215FEDCBA987);
333 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 29, 0x7F6E5D4C3B2A190AFF6E5D4C3);
334 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 30, 0x3FB72EA61D950C857FB72EA61);
335 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 31, 0x1FDB97530ECA8642BFDB97530);
336 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 32, 0xFEDCBA9876543215FEDCBA98);
337 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 33, 0x7F6E5D4C3B2A190AFF6E5D4C);
338 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 34, 0x3FB72EA61D950C857FB72EA6);
339 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 35, 0x1FDB97530ECA8642BFDB9753);
340 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 36, 0xFEDCBA9876543215FEDCBA9);
341 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 60, 0xFEDCBA9876543215F);
342 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 61, 0x7F6E5D4C3B2A190AF);
343 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 62, 0x3FB72EA61D950C857);
344 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 63, 0x1FDB97530ECA8642B);
345 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 64, 0xFEDCBA9876543215);
346 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 65, 0x7F6E5D4C3B2A190A);
347 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 66, 0x3FB72EA61D950C85);
348 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 67, 0x1FDB97530ECA8642);
349 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 68, 0xFEDCBA987654321);
350 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 92, 0xFEDCBA987);
351 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 93, 0x7F6E5D4C3);
352 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 94, 0x3FB72EA61);
353 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 95, 0x1FDB97530);
354 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 96, 0xFEDCBA98);
355 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 97, 0x7F6E5D4C);
356 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 98, 0x3FB72EA6);
357 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 99, 0x1FDB9753);
358 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 100, 0xFEDCBA9);
359 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 124, 0xF);
360 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 125, 0x7);
361 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 126, 0x3);
362 try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 127, 0x1);
327 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 0, 0xFEDCBA9876543215FEDCBA987654321F);
328 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 1, 0x7F6E5D4C3B2A190AFF6E5D4C3B2A190F);
329 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 2, 0x3FB72EA61D950C857FB72EA61D950C87);
330 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 3, 0x1FDB97530ECA8642BFDB97530ECA8643);
331 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 4, 0xFEDCBA9876543215FEDCBA987654321);
332 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 28, 0xFEDCBA9876543215FEDCBA987);
333 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 29, 0x7F6E5D4C3B2A190AFF6E5D4C3);
334 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 30, 0x3FB72EA61D950C857FB72EA61);
335 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 31, 0x1FDB97530ECA8642BFDB97530);
336 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 32, 0xFEDCBA9876543215FEDCBA98);
337 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 33, 0x7F6E5D4C3B2A190AFF6E5D4C);
338 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 34, 0x3FB72EA61D950C857FB72EA6);
339 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 35, 0x1FDB97530ECA8642BFDB9753);
340 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 36, 0xFEDCBA9876543215FEDCBA9);
341 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 60, 0xFEDCBA9876543215F);
342 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 61, 0x7F6E5D4C3B2A190AF);
343 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 62, 0x3FB72EA61D950C857);
344 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 63, 0x1FDB97530ECA8642B);
345 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 64, 0xFEDCBA9876543215);
346 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 65, 0x7F6E5D4C3B2A190A);
347 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 66, 0x3FB72EA61D950C85);
348 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 67, 0x1FDB97530ECA8642);
349 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 68, 0xFEDCBA987654321);
350 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 92, 0xFEDCBA987);
351 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 93, 0x7F6E5D4C3);
352 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 94, 0x3FB72EA61);
353 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 95, 0x1FDB97530);
354 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 96, 0xFEDCBA98);
355 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 97, 0x7F6E5D4C);
356 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 98, 0x3FB72EA6);
357 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 99, 0x1FDB9753);
358 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 100, 0xFEDCBA9);
359 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 124, 0xF);
360 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 125, 0x7);
361 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 126, 0x3);
362 try test__lshrti3(@as(i128, @bitCast(@as(u128, 0xFEDCBA9876543215FEDCBA987654321F))), 127, 0x1);
363363}
lib/compiler_rt/sin.zig+7-7
......@@ -31,7 +31,7 @@ comptime {
3131
3232pub fn __sinh(x: f16) callconv(.C) f16 {
3333 // TODO: more efficient implementation
34 return @floatCast(f16, sinf(x));
34 return @as(f16, @floatCast(sinf(x)));
3535}
3636
3737pub fn sinf(x: f32) callconv(.C) f32 {
......@@ -41,7 +41,7 @@ pub fn sinf(x: f32) callconv(.C) f32 {
4141 const s3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2
4242 const s4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18
4343
44 var ix = @bitCast(u32, x);
44 var ix = @as(u32, @bitCast(x));
4545 const sign = ix >> 31 != 0;
4646 ix &= 0x7fffffff;
4747
......@@ -90,7 +90,7 @@ pub fn sinf(x: f32) callconv(.C) f32 {
9090}
9191
9292pub fn sin(x: f64) callconv(.C) f64 {
93 var ix = @bitCast(u64, x) >> 32;
93 var ix = @as(u64, @bitCast(x)) >> 32;
9494 ix &= 0x7fffffff;
9595
9696 // |x| ~< pi/4
......@@ -120,12 +120,12 @@ pub fn sin(x: f64) callconv(.C) f64 {
120120
121121pub fn __sinx(x: f80) callconv(.C) f80 {
122122 // TODO: more efficient implementation
123 return @floatCast(f80, sinq(x));
123 return @as(f80, @floatCast(sinq(x)));
124124}
125125
126126pub fn sinq(x: f128) callconv(.C) f128 {
127127 // TODO: more correct implementation
128 return sin(@floatCast(f64, x));
128 return sin(@as(f64, @floatCast(x)));
129129}
130130
131131pub fn sinl(x: c_longdouble) callconv(.C) c_longdouble {
......@@ -180,11 +180,11 @@ test "sin64.special" {
180180}
181181
182182test "sin32 #9901" {
183 const float = @bitCast(f32, @as(u32, 0b11100011111111110000000000000000));
183 const float = @as(f32, @bitCast(@as(u32, 0b11100011111111110000000000000000)));
184184 _ = sinf(float);
185185}
186186
187187test "sin64 #9901" {
188 const float = @bitCast(f64, @as(u64, 0b1111111101000001000000001111110111111111100000000000000000000001));
188 const float = @as(f64, @bitCast(@as(u64, 0b1111111101000001000000001111110111111111100000000000000000000001)));
189189 _ = sin(float);
190190}
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 {
2626 var big_sin: f32 = undefined;
2727 var big_cos: f32 = undefined;
2828 sincosf(x, &big_sin, &big_cos);
29 r_sin.* = @floatCast(f16, big_sin);
30 r_cos.* = @floatCast(f16, big_cos);
29 r_sin.* = @as(f16, @floatCast(big_sin));
30 r_cos.* = @as(f16, @floatCast(big_cos));
3131}
3232
3333pub 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 {
3636 const sc3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2
3737 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));
4040 const sign = pre_ix >> 31 != 0;
4141 const ix = pre_ix & 0x7fffffff;
4242
......@@ -126,7 +126,7 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.C) void {
126126}
127127
128128pub 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
131131 // |x| ~< pi/4
132132 if (ix <= 0x3fe921fb) {
......@@ -182,8 +182,8 @@ pub fn __sincosx(x: f80, r_sin: *f80, r_cos: *f80) callconv(.C) void {
182182 var big_sin: f128 = undefined;
183183 var big_cos: f128 = undefined;
184184 sincosq(x, &big_sin, &big_cos);
185 r_sin.* = @floatCast(f80, big_sin);
186 r_cos.* = @floatCast(f80, big_cos);
185 r_sin.* = @as(f80, @floatCast(big_sin));
186 r_cos.* = @as(f80, @floatCast(big_cos));
187187}
188188
189189pub 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 {
191191 //return sincos_generic(f128, x, r_sin, r_cos);
192192 var small_sin: f64 = undefined;
193193 var small_cos: f64 = undefined;
194 sincos(@floatCast(f64, x), &small_sin, &small_cos);
194 sincos(@as(f64, @floatCast(x)), &small_sin, &small_cos);
195195 r_sin.* = small_sin;
196196 r_cos.* = small_cos;
197197}
......@@ -217,8 +217,8 @@ inline fn sincos_generic(comptime F: type, x: F, r_sin: *F, r_cos: *F) void {
217217 const sc1pio4: F = 1.0 * math.pi / 4.0;
218218 const bits = @typeInfo(F).Float.bits;
219219 const I = std.meta.Int(.unsigned, bits);
220 const ix = @bitCast(I, x) & (math.maxInt(I) >> 1);
221 const se = @truncate(u16, ix >> (bits - 16));
220 const ix = @as(I, @bitCast(x)) & (math.maxInt(I) >> 1);
221 const se = @as(u16, @truncate(ix >> (bits - 16)));
222222
223223 if (se == 0x7fff) {
224224 const result = x - x;
......@@ -227,7 +227,7 @@ inline fn sincos_generic(comptime F: type, x: F, r_sin: *F, r_cos: *F) void {
227227 return;
228228 }
229229
230 if (@bitCast(F, ix) < sc1pio4) {
230 if (@as(F, @bitCast(ix)) < sc1pio4) {
231231 if (se < 0x3fff - math.floatFractionalBits(F) - 1) {
232232 // raise underflow if subnormal
233233 if (se == 0) {
lib/compiler_rt/sqrt.zig+16-16
......@@ -20,13 +20,13 @@ comptime {
2020
2121pub fn __sqrth(x: f16) callconv(.C) f16 {
2222 // TODO: more efficient implementation
23 return @floatCast(f16, sqrtf(x));
23 return @as(f16, @floatCast(sqrtf(x)));
2424}
2525
2626pub fn sqrtf(x: f32) callconv(.C) f32 {
2727 const tiny: f32 = 1.0e-30;
28 const sign: i32 = @bitCast(i32, @as(u32, 0x80000000));
29 var ix: i32 = @bitCast(i32, x);
28 const sign: i32 = @as(i32, @bitCast(@as(u32, 0x80000000)));
29 var ix: i32 = @as(i32, @bitCast(x));
3030
3131 if ((ix & 0x7F800000) == 0x7F800000) {
3232 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 {
9696
9797 ix = (q >> 1) + 0x3f000000;
9898 ix += m << 23;
99 return @bitCast(f32, ix);
99 return @as(f32, @bitCast(ix));
100100}
101101
102102/// NOTE: The original code is full of implicit signed -> unsigned assumptions and u32 wraparound
......@@ -105,10 +105,10 @@ pub fn sqrtf(x: f32) callconv(.C) f32 {
105105pub fn sqrt(x: f64) callconv(.C) f64 {
106106 const tiny: f64 = 1.0e-300;
107107 const sign: u32 = 0x80000000;
108 const u = @bitCast(u64, x);
108 const u = @as(u64, @bitCast(x));
109109
110 var ix0 = @intCast(u32, u >> 32);
111 var ix1 = @intCast(u32, u & 0xFFFFFFFF);
110 var ix0 = @as(u32, @intCast(u >> 32));
111 var ix1 = @as(u32, @intCast(u & 0xFFFFFFFF));
112112
113113 // sqrt(nan) = nan, sqrt(+inf) = +inf, sqrt(-inf) = nan
114114 if (ix0 & 0x7FF00000 == 0x7FF00000) {
......@@ -125,7 +125,7 @@ pub fn sqrt(x: f64) callconv(.C) f64 {
125125 }
126126
127127 // normalize x
128 var m = @intCast(i32, ix0 >> 20);
128 var m = @as(i32, @intCast(ix0 >> 20));
129129 if (m == 0) {
130130 // subnormal
131131 while (ix0 == 0) {
......@@ -139,9 +139,9 @@ pub fn sqrt(x: f64) callconv(.C) f64 {
139139 while (ix0 & 0x00100000 == 0) : (i += 1) {
140140 ix0 <<= 1;
141141 }
142 m -= @intCast(i32, i) - 1;
143 ix0 |= ix1 >> @intCast(u5, 32 - i);
144 ix1 <<= @intCast(u5, i);
142 m -= @as(i32, @intCast(i)) - 1;
143 ix0 |= ix1 >> @as(u5, @intCast(32 - i));
144 ix1 <<= @as(u5, @intCast(i));
145145 }
146146
147147 // unbias exponent
......@@ -225,21 +225,21 @@ pub fn sqrt(x: f64) callconv(.C) f64 {
225225
226226 // NOTE: musl here appears to rely on signed twos-complement wraparound. +% has the same
227227 // behaviour at least.
228 var iix0 = @intCast(i32, ix0);
228 var iix0 = @as(i32, @intCast(ix0));
229229 iix0 = iix0 +% (m << 20);
230230
231 const uz = (@intCast(u64, iix0) << 32) | ix1;
232 return @bitCast(f64, uz);
231 const uz = (@as(u64, @intCast(iix0)) << 32) | ix1;
232 return @as(f64, @bitCast(uz));
233233}
234234
235235pub fn __sqrtx(x: f80) callconv(.C) f80 {
236236 // TODO: more efficient implementation
237 return @floatCast(f80, sqrtq(x));
237 return @as(f80, @floatCast(sqrtq(x)));
238238}
239239
240240pub fn sqrtq(x: f128) callconv(.C) f128 {
241241 // TODO: more correct implementation
242 return sqrt(@floatCast(f64, x));
242 return sqrt(@as(f64, @floatCast(x)));
243243}
244244
245245pub fn sqrtl(x: c_longdouble) callconv(.C) c_longdouble {
lib/compiler_rt/subdf3.zig+2-2
......@@ -11,11 +11,11 @@ comptime {
1111}
1212
1313fn __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)));
1515 return a + neg_b;
1616}
1717
1818fn __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)));
2020 return a + neg_b;
2121}
lib/compiler_rt/subhf3.zig+1-1
......@@ -7,6 +7,6 @@ comptime {
77}
88
99fn __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)));
1111 return a + neg_b;
1212}
lib/compiler_rt/subsf3.zig+2-2
......@@ -11,11 +11,11 @@ comptime {
1111}
1212
1313fn __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)));
1515 return a + neg_b;
1616}
1717
1818fn __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)));
2020 return a + neg_b;
2121}
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 {
2020}
2121
2222inline 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)));
2424 return a + neg_b;
2525}
lib/compiler_rt/tan.zig+5-5
......@@ -33,7 +33,7 @@ comptime {
3333
3434pub fn __tanh(x: f16) callconv(.C) f16 {
3535 // TODO: more efficient implementation
36 return @floatCast(f16, tanf(x));
36 return @as(f16, @floatCast(tanf(x)));
3737}
3838
3939pub fn tanf(x: f32) callconv(.C) f32 {
......@@ -43,7 +43,7 @@ pub fn tanf(x: f32) callconv(.C) f32 {
4343 const t3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2
4444 const t4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18
4545
46 var ix = @bitCast(u32, x);
46 var ix = @as(u32, @bitCast(x));
4747 const sign = ix >> 31 != 0;
4848 ix &= 0x7fffffff;
4949
......@@ -81,7 +81,7 @@ pub fn tanf(x: f32) callconv(.C) f32 {
8181}
8282
8383pub fn tan(x: f64) callconv(.C) f64 {
84 var ix = @bitCast(u64, x) >> 32;
84 var ix = @as(u64, @bitCast(x)) >> 32;
8585 ix &= 0x7fffffff;
8686
8787 // |x| ~< pi/4
......@@ -106,12 +106,12 @@ pub fn tan(x: f64) callconv(.C) f64 {
106106
107107pub fn __tanx(x: f80) callconv(.C) f80 {
108108 // TODO: more efficient implementation
109 return @floatCast(f80, tanq(x));
109 return @as(f80, @floatCast(tanq(x)));
110110}
111111
112112pub fn tanq(x: f128) callconv(.C) f128 {
113113 // TODO: more correct implementation
114 return tan(@floatCast(f64, x));
114 return tan(@as(f64, @floatCast(x)));
115115}
116116
117117pub 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 {
7070 const z = x * x;
7171 const w = z * z;
7272 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));
7474}
7575
7676/// kernel sin function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854
......@@ -131,7 +131,7 @@ pub fn __sindf(x: f64) f32 {
131131 const w = z * z;
132132 const r = S3 + z * S4;
133133 const s = z * x;
134 return @floatCast(f32, (x + s * (S1 + z * S2)) + s * w * r);
134 return @as(f32, @floatCast((x + s * (S1 + z * S2)) + s * w * r));
135135}
136136
137137/// kernel tan function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854
......@@ -199,7 +199,7 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 {
199199 var hx: u32 = undefined;
200200 var sign: bool = undefined;
201201
202 hx = @intCast(u32, @bitCast(u64, x) >> 32);
202 hx = @as(u32, @intCast(@as(u64, @bitCast(x)) >> 32));
203203 const big = (hx & 0x7fffffff) >= 0x3FE59428; // |x| >= 0.6744
204204 if (big) {
205205 sign = hx >> 31 != 0;
......@@ -222,7 +222,7 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 {
222222 r = y + z * (s * (r + v) + y) + s * T[0];
223223 w = x + r;
224224 if (big) {
225 s = 1 - 2 * @floatFromInt(f64, @intFromBool(odd));
225 s = 1 - 2 * @as(f64, @floatFromInt(@intFromBool(odd)));
226226 v = s - 2.0 * (x + (r - w * w / (w + s)));
227227 return if (sign) -v else v;
228228 }
......@@ -231,11 +231,11 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 {
231231 }
232232 // -1.0/(x+r) has up to 2ulp error, so compute it accurately
233233 w0 = w;
234 w0 = @bitCast(f64, @bitCast(u64, w0) & 0xffffffff00000000);
234 w0 = @as(f64, @bitCast(@as(u64, @bitCast(w0)) & 0xffffffff00000000));
235235 v = r - (w0 - x); // w0+v = r+x
236236 a = -1.0 / w;
237237 a0 = a;
238 a0 = @bitCast(f64, @bitCast(u64, a0) & 0xffffffff00000000);
238 a0 = @as(f64, @bitCast(@as(u64, @bitCast(a0)) & 0xffffffff00000000));
239239 return a0 + a * (1.0 + a0 * w0 + a0 * v);
240240}
241241
......@@ -269,5 +269,5 @@ pub fn __tandf(x: f64, odd: bool) f32 {
269269 const s = z * x;
270270 const u = T[0] + z * T[1];
271271 const r0 = (x + s * u) + (s * w) * (t + w * r);
272 return @floatCast(f32, if (odd) -1.0 / r0 else r0);
272 return @as(f32, @floatCast(if (odd) -1.0 / r0 else r0));
273273}
lib/compiler_rt/trunc.zig+14-14
......@@ -27,12 +27,12 @@ comptime {
2727
2828pub fn __trunch(x: f16) callconv(.C) f16 {
2929 // TODO: more efficient implementation
30 return @floatCast(f16, truncf(x));
30 return @as(f16, @floatCast(truncf(x)));
3131}
3232
3333pub fn truncf(x: f32) callconv(.C) f32 {
34 const u = @bitCast(u32, x);
35 var e = @intCast(i32, ((u >> 23) & 0xFF)) - 0x7F + 9;
34 const u = @as(u32, @bitCast(x));
35 var e = @as(i32, @intCast(((u >> 23) & 0xFF))) - 0x7F + 9;
3636 var m: u32 = undefined;
3737
3838 if (e >= 23 + 9) {
......@@ -42,18 +42,18 @@ pub fn truncf(x: f32) callconv(.C) f32 {
4242 e = 1;
4343 }
4444
45 m = @as(u32, math.maxInt(u32)) >> @intCast(u5, e);
45 m = @as(u32, math.maxInt(u32)) >> @as(u5, @intCast(e));
4646 if (u & m == 0) {
4747 return x;
4848 } else {
4949 math.doNotOptimizeAway(x + 0x1p120);
50 return @bitCast(f32, u & ~m);
50 return @as(f32, @bitCast(u & ~m));
5151 }
5252}
5353
5454pub fn trunc(x: f64) callconv(.C) f64 {
55 const u = @bitCast(u64, x);
56 var e = @intCast(i32, ((u >> 52) & 0x7FF)) - 0x3FF + 12;
55 const u = @as(u64, @bitCast(x));
56 var e = @as(i32, @intCast(((u >> 52) & 0x7FF))) - 0x3FF + 12;
5757 var m: u64 = undefined;
5858
5959 if (e >= 52 + 12) {
......@@ -63,23 +63,23 @@ pub fn trunc(x: f64) callconv(.C) f64 {
6363 e = 1;
6464 }
6565
66 m = @as(u64, math.maxInt(u64)) >> @intCast(u6, e);
66 m = @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(e));
6767 if (u & m == 0) {
6868 return x;
6969 } else {
7070 math.doNotOptimizeAway(x + 0x1p120);
71 return @bitCast(f64, u & ~m);
71 return @as(f64, @bitCast(u & ~m));
7272 }
7373}
7474
7575pub fn __truncx(x: f80) callconv(.C) f80 {
7676 // TODO: more efficient implementation
77 return @floatCast(f80, truncq(x));
77 return @as(f80, @floatCast(truncq(x)));
7878}
7979
8080pub fn truncq(x: f128) callconv(.C) f128 {
81 const u = @bitCast(u128, x);
82 var e = @intCast(i32, ((u >> 112) & 0x7FFF)) - 0x3FFF + 16;
81 const u = @as(u128, @bitCast(x));
82 var e = @as(i32, @intCast(((u >> 112) & 0x7FFF))) - 0x3FFF + 16;
8383 var m: u128 = undefined;
8484
8585 if (e >= 112 + 16) {
......@@ -89,12 +89,12 @@ pub fn truncq(x: f128) callconv(.C) f128 {
8989 e = 1;
9090 }
9191
92 m = @as(u128, math.maxInt(u128)) >> @intCast(u7, e);
92 m = @as(u128, math.maxInt(u128)) >> @as(u7, @intCast(e));
9393 if (u & m == 0) {
9494 return x;
9595 } else {
9696 math.doNotOptimizeAway(x + 0x1p120);
97 return @bitCast(f128, u & ~m);
97 return @as(f128, @bitCast(u & ~m));
9898 }
9999}
100100
lib/compiler_rt/truncdfhf2.zig+2-2
......@@ -12,9 +12,9 @@ comptime {
1212}
1313
1414pub fn __truncdfhf2(a: f64) callconv(.C) common.F16T(f64) {
15 return @bitCast(common.F16T(f64), truncf(f16, f64, a));
15 return @as(common.F16T(f64), @bitCast(truncf(f16, f64, a)));
1616}
1717
1818fn __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)));
2020}
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
3838 const dstNaNCode = dstQNaN - 1;
3939
4040 // 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));
4242 const aAbs: src_rep_t = aRep & srcAbsMask;
4343 const sign: src_rep_t = aRep & srcSignMask;
4444 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
4747 // The exponent of a is within the range of normal numbers in the
4848 // destination format. We can convert by simply right-shifting with
4949 // rounding and adjusting the exponent.
50 absResult = @truncate(dst_rep_t, aAbs >> (srcSigBits - dstSigBits));
50 absResult = @as(dst_rep_t, @truncate(aAbs >> (srcSigBits - dstSigBits)));
5151 absResult -%= @as(dst_rep_t, srcExpBias - dstExpBias) << dstSigBits;
5252
5353 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
6262 // a is NaN.
6363 // Conjure the result by beginning with infinity, setting the qNaN
6464 // 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;
6666 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));
6868 } else if (aAbs >= overflow) {
6969 // a overflows to infinity.
70 absResult = @intCast(dst_rep_t, dstInfExp) << dstSigBits;
70 absResult = @as(dst_rep_t, @intCast(dstInfExp)) << dstSigBits;
7171 } else {
7272 // a underflows on conversion to the destination type or is an exact
7373 // zero. The result may be a denormal or zero. Extract the exponent
7474 // to get the shift amount for the denormalization.
75 const aExp = @intCast(u32, aAbs >> srcSigBits);
76 const shift = @intCast(u32, srcExpBias - dstExpBias - aExp + 1);
75 const aExp = @as(u32, @intCast(aAbs >> srcSigBits));
76 const shift = @as(u32, @intCast(srcExpBias - dstExpBias - aExp + 1));
7777
7878 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
8181 if (shift > srcSigBits) {
8282 absResult = 0;
8383 } else {
84 const sticky: src_rep_t = @intFromBool(significand << @intCast(SrcShift, srcBits - shift) != 0);
85 const denormalizedSignificand: src_rep_t = significand >> @intCast(SrcShift, shift) | sticky;
86 absResult = @intCast(dst_rep_t, denormalizedSignificand >> (srcSigBits - dstSigBits));
84 const sticky: src_rep_t = @intFromBool(significand << @as(SrcShift, @intCast(srcBits - shift)) != 0);
85 const denormalizedSignificand: src_rep_t = significand >> @as(SrcShift, @intCast(shift)) | sticky;
86 absResult = @as(dst_rep_t, @intCast(denormalizedSignificand >> (srcSigBits - dstSigBits)));
8787 const roundBits: src_rep_t = denormalizedSignificand & roundMask;
8888 if (roundBits > halfway) {
8989 // Round to nearest
......@@ -96,8 +96,8 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
9696 }
9797
9898 const result: dst_rep_t align(@alignOf(dst_t)) = absResult |
99 @truncate(dst_rep_t, sign >> @intCast(SrcShift, srcBits - dstBits));
100 return @bitCast(dst_t, result);
99 @as(dst_rep_t, @truncate(sign >> @as(SrcShift, @intCast(srcBits - dstBits))));
100 return @as(dst_t, @bitCast(result));
101101}
102102
103103pub 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 {
133133 // destination format. We can convert by simply right-shifting with
134134 // rounding and adjusting the exponent.
135135 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)));
137137 abs_result -%= @as(dst_rep_t, src_exp_bias - dst_exp_bias) << dst_sig_bits;
138138
139139 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 {
148148 // a is NaN.
149149 // Conjure the result by beginning with infinity, setting the qNaN
150150 // 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;
152152 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));
154154 } else if (a_rep.exp >= overflow) {
155155 // 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;
157157 } else {
158158 // a underflows on conversion to the destination type or is an exact
159159 // 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 {
164164 if (shift > src_sig_bits) {
165165 abs_result = 0;
166166 } else {
167 const sticky = @intFromBool(a_rep.fraction << @intCast(u6, shift) != 0);
168 const denormalized_significand = a_rep.fraction >> @intCast(u6, shift) | sticky;
169 abs_result = @intCast(dst_rep_t, denormalized_significand >> (src_sig_bits - dst_sig_bits));
167 const sticky = @intFromBool(a_rep.fraction << @as(u6, @intCast(shift)) != 0);
168 const denormalized_significand = a_rep.fraction >> @as(u6, @intCast(shift)) | sticky;
169 abs_result = @as(dst_rep_t, @intCast(denormalized_significand >> (src_sig_bits - dst_sig_bits)));
170170 const round_bits = denormalized_significand & round_mask;
171171 if (round_bits > halfway) {
172172 // Round to nearest
......@@ -179,7 +179,7 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
179179 }
180180
181181 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));
183183}
184184
185185test {
lib/compiler_rt/truncf_test.zig+21-21
......@@ -10,7 +10,7 @@ const __trunctfdf2 = @import("trunctfdf2.zig").__trunctfdf2;
1010const __trunctfxf2 = @import("trunctfxf2.zig").__trunctfxf2;
1111
1212fn test__truncsfhf2(a: u32, expected: u16) !void {
13 const actual = @bitCast(u16, __truncsfhf2(@bitCast(f32, a)));
13 const actual = @as(u16, @bitCast(__truncsfhf2(@as(f32, @bitCast(a)))));
1414
1515 if (actual == expected) {
1616 return;
......@@ -73,7 +73,7 @@ test "truncsfhf2" {
7373}
7474
7575fn test__truncdfhf2(a: f64, expected: u16) void {
76 const rep = @bitCast(u16, __truncdfhf2(a));
76 const rep = @as(u16, @bitCast(__truncdfhf2(a)));
7777
7878 if (rep == expected) {
7979 return;
......@@ -89,7 +89,7 @@ fn test__truncdfhf2(a: f64, expected: u16) void {
8989}
9090
9191fn test__truncdfhf2_raw(a: u64, expected: u16) void {
92 const actual = @bitCast(u16, __truncdfhf2(@bitCast(f64, a)));
92 const actual = @as(u16, @bitCast(__truncdfhf2(@as(f64, @bitCast(a)))));
9393
9494 if (actual == expected) {
9595 return;
......@@ -141,7 +141,7 @@ test "truncdfhf2" {
141141fn test__trunctfsf2(a: f128, expected: u32) void {
142142 const x = __trunctfsf2(a);
143143
144 const rep = @bitCast(u32, x);
144 const rep = @as(u32, @bitCast(x));
145145 if (rep == expected) {
146146 return;
147147 }
......@@ -157,11 +157,11 @@ fn test__trunctfsf2(a: f128, expected: u32) void {
157157
158158test "trunctfsf2" {
159159 // qnan
160 test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7fc00000);
160 test__trunctfsf2(@as(f128, @bitCast(@as(u128, 0x7fff800000000000 << 64))), 0x7fc00000);
161161 // 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);
163163 // inf
164 test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff000000000000 << 64)), 0x7f800000);
164 test__trunctfsf2(@as(f128, @bitCast(@as(u128, 0x7fff000000000000 << 64))), 0x7f800000);
165165 // zero
166166 test__trunctfsf2(0.0, 0x0);
167167
......@@ -174,7 +174,7 @@ test "trunctfsf2" {
174174fn test__trunctfdf2(a: f128, expected: u64) void {
175175 const x = __trunctfdf2(a);
176176
177 const rep = @bitCast(u64, x);
177 const rep = @as(u64, @bitCast(x));
178178 if (rep == expected) {
179179 return;
180180 }
......@@ -190,11 +190,11 @@ fn test__trunctfdf2(a: f128, expected: u64) void {
190190
191191test "trunctfdf2" {
192192 // qnan
193 test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7ff8000000000000);
193 test__trunctfdf2(@as(f128, @bitCast(@as(u128, 0x7fff800000000000 << 64))), 0x7ff8000000000000);
194194 // 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);
196196 // inf
197 test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff000000000000 << 64)), 0x7ff0000000000000);
197 test__trunctfdf2(@as(f128, @bitCast(@as(u128, 0x7fff000000000000 << 64))), 0x7ff0000000000000);
198198 // zero
199199 test__trunctfdf2(0.0, 0x0);
200200
......@@ -207,7 +207,7 @@ test "trunctfdf2" {
207207fn test__truncdfsf2(a: f64, expected: u32) void {
208208 const x = __truncdfsf2(a);
209209
210 const rep = @bitCast(u32, x);
210 const rep = @as(u32, @bitCast(x));
211211 if (rep == expected) {
212212 return;
213213 }
......@@ -225,11 +225,11 @@ fn test__truncdfsf2(a: f64, expected: u32) void {
225225
226226test "truncdfsf2" {
227227 // nan & qnan
228 test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff8000000000000)), 0x7fc00000);
229 test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff0000000000001)), 0x7fc00000);
228 test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0x7ff8000000000000))), 0x7fc00000);
229 test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0x7ff0000000000001))), 0x7fc00000);
230230 // inf
231 test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff0000000000000)), 0x7f800000);
232 test__truncdfsf2(@bitCast(f64, @as(u64, 0xfff0000000000000)), 0xff800000);
231 test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0x7ff0000000000000))), 0x7f800000);
232 test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0xfff0000000000000))), 0xff800000);
233233
234234 test__truncdfsf2(0.0, 0x0);
235235 test__truncdfsf2(1.0, 0x3f800000);
......@@ -242,7 +242,7 @@ test "truncdfsf2" {
242242fn test__trunctfhf2(a: f128, expected: u16) void {
243243 const x = __trunctfhf2(a);
244244
245 const rep = @bitCast(u16, x);
245 const rep = @as(u16, @bitCast(x));
246246 if (rep == expected) {
247247 return;
248248 }
......@@ -254,12 +254,12 @@ fn test__trunctfhf2(a: f128, expected: u16) void {
254254
255255test "trunctfhf2" {
256256 // qNaN
257 test__trunctfhf2(@bitCast(f128, @as(u128, 0x7fff8000000000000000000000000000)), 0x7e00);
257 test__trunctfhf2(@as(f128, @bitCast(@as(u128, 0x7fff8000000000000000000000000000))), 0x7e00);
258258 // NaN
259 test__trunctfhf2(@bitCast(f128, @as(u128, 0x7fff0000000000000000000000000001)), 0x7e00);
259 test__trunctfhf2(@as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000001))), 0x7e00);
260260 // inf
261 test__trunctfhf2(@bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000)), 0x7c00);
262 test__trunctfhf2(-@bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000)), 0xfc00);
261 test__trunctfhf2(@as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000000))), 0x7c00);
262 test__trunctfhf2(-@as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000000))), 0xfc00);
263263 // zero
264264 test__trunctfhf2(0.0, 0x0);
265265 test__trunctfhf2(-0.0, 0x8000);
lib/compiler_rt/truncsfhf2.zig+3-3
......@@ -13,13 +13,13 @@ comptime {
1313}
1414
1515pub fn __truncsfhf2(a: f32) callconv(.C) common.F16T(f32) {
16 return @bitCast(common.F16T(f32), truncf(f16, f32, a));
16 return @as(common.F16T(f32), @bitCast(truncf(f16, f32, a)));
1717}
1818
1919fn __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)));
2121}
2222
2323fn __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)));
2525}
lib/compiler_rt/trunctfhf2.zig+1-1
......@@ -8,5 +8,5 @@ comptime {
88}
99
1010pub fn __trunctfhf2(a: f128) callconv(.C) common.F16T(f128) {
11 return @bitCast(common.F16T(f128), truncf(f16, f128, a));
11 return @as(common.F16T(f128), @bitCast(truncf(f16, f128, a)));
1212}
lib/compiler_rt/trunctfxf2.zig+4-4
......@@ -25,7 +25,7 @@ pub fn __trunctfxf2(a: f128) callconv(.C) f80 {
2525 const halfway = 1 << (src_sig_bits - dst_sig_bits - 1);
2626
2727 // 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));
2929 const a_abs = a_rep & src_abs_mask;
3030 const sign: u16 = if (a_rep & src_sign_mask != 0) 0x8000 else 0;
3131 const integer_bit = 1 << 63;
......@@ -38,13 +38,13 @@ pub fn __trunctfxf2(a: f128) callconv(.C) f80 {
3838 // bit and inserting the (truncated) trailing NaN field.
3939 res.exp = 0x7fff;
4040 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)));
4242 } else {
4343 // The exponent of a is within the range of normal numbers in the
4444 // destination format. We can convert by simply right-shifting with
4545 // 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;
47 res.exp = @truncate(u16, a_abs >> src_sig_bits);
46 res.fraction = @as(u64, @truncate(a_abs >> (src_sig_bits - dst_sig_bits))) | integer_bit;
47 res.exp = @as(u16, @truncate(a_abs >> src_sig_bits));
4848
4949 const round_bits = a_abs & round_mask;
5050 if (round_bits > halfway) {
lib/compiler_rt/truncxfhf2.zig+1-1
......@@ -8,5 +8,5 @@ comptime {
88}
99
1010fn __truncxfhf2(a: f80) callconv(.C) common.F16T(f80) {
11 return @bitCast(common.F16T(f80), trunc_f80(f16, a));
11 return @as(common.F16T(f80), @bitCast(trunc_f80(f16, a)));
1212}
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 {
2121 var un64: T = undefined;
2222 var un10: T = undefined;
2323
24 const s = @intCast(Log2Int(T), @clz(v));
24 const s = @as(Log2Int(T), @intCast(@clz(v)));
2525 if (s > 0) {
2626 // Normalize divisor
2727 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))))));
2929 un10 = _u0 << s;
3030 } else {
3131 // Avoid undefined behavior of (u0 >> @bitSizeOf(T))
......@@ -101,8 +101,8 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
101101 return 0;
102102 }
103103
104 var a = @bitCast([2]HalfT, a_);
105 var b = @bitCast([2]HalfT, b_);
104 var a = @as([2]HalfT, @bitCast(a_));
105 var b = @as([2]HalfT, @bitCast(b_));
106106 var q: [2]HalfT = undefined;
107107 var r: [2]HalfT = undefined;
108108
......@@ -119,16 +119,16 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
119119 q[lo] = divwide(HalfT, a[hi] % b[lo], a[lo], b[lo], &r[lo]);
120120 }
121121 if (maybe_rem) |rem| {
122 rem.* = @bitCast(T, r);
122 rem.* = @as(T, @bitCast(r));
123123 }
124 return @bitCast(T, q);
124 return @as(T, @bitCast(q));
125125 }
126126
127127 // 0 <= shift <= 63
128128 var shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]);
129 var af = @bitCast(T, a);
130 var bf = @bitCast(T, b) << shift;
131 q = @bitCast([2]HalfT, @as(T, 0));
129 var af = @as(T, @bitCast(a));
130 var bf = @as(T, @bitCast(b)) << shift;
131 q = @as([2]HalfT, @bitCast(@as(T, 0)));
132132
133133 for (0..shift + 1) |_| {
134134 q[lo] <<= 1;
......@@ -137,13 +137,13 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
137137 // af -= bf;
138138 // q[lo] |= 1;
139139 // }
140 const s = @bitCast(SignedT, bf -% af -% 1) >> (@bitSizeOf(T) - 1);
141 q[lo] |= @intCast(HalfT, s & 1);
142 af -= bf & @bitCast(T, s);
140 const s = @as(SignedT, @bitCast(bf -% af -% 1)) >> (@bitSizeOf(T) - 1);
141 q[lo] |= @as(HalfT, @intCast(s & 1));
142 af -= bf & @as(T, @bitCast(s));
143143 bf >>= 1;
144144 }
145145 if (maybe_rem) |rem| {
146 rem.* = @bitCast(T, af);
146 rem.* = @as(T, @bitCast(af));
147147 }
148 return @bitCast(T, q);
148 return @as(T, @bitCast(q));
149149}
lib/compiler_rt/udivmodei4.zig+7-7
......@@ -83,23 +83,23 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
8383 i = 0;
8484 while (i <= n) : (i += 1) {
8585 const p = qhat * limb(&vn, i);
86 const t = limb(&un, i + j) - carry - @truncate(u32, p);
87 limb_set(&un, i + j, @truncate(u32, @bitCast(u64, t)));
88 carry = @intCast(i64, p >> 32) - @intCast(i64, t >> 32);
86 const t = limb(&un, i + j) - carry - @as(u32, @truncate(p));
87 limb_set(&un, i + j, @as(u32, @truncate(@as(u64, @bitCast(t)))));
88 carry = @as(i64, @intCast(p >> 32)) - @as(i64, @intCast(t >> 32));
8989 }
9090 const t = limb(&un, j + n + 1) -% carry;
91 limb_set(&un, j + n + 1, @truncate(u32, @bitCast(u64, t)));
92 if (q) |q_| limb_set(q_, j, @truncate(u32, qhat));
91 limb_set(&un, j + n + 1, @as(u32, @truncate(@as(u64, @bitCast(t)))));
92 if (q) |q_| limb_set(q_, j, @as(u32, @truncate(qhat)));
9393 if (t < 0) {
9494 if (q) |q_| limb_set(q_, j, limb(q_, j) - 1);
9595 var carry2: u64 = 0;
9696 i = 0;
9797 while (i <= n) : (i += 1) {
9898 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)));
100100 carry2 = t2 >> 32;
101101 }
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)));
103103 }
104104 if (j == 0) break;
105105 }
lib/compiler_rt/udivmodti4.zig+1-1
......@@ -20,7 +20,7 @@ pub fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) callconv(.C) u128 {
2020const v2u64 = @Vector(2, u64);
2121
2222fn __udivmodti4_windows_x86_64(a: v2u64, b: v2u64, maybe_rem: ?*u128) callconv(.C) v2u64 {
23 return @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)));
2424}
2525
2626test {
lib/compiler_rt/udivti3.zig+1-1
......@@ -20,5 +20,5 @@ pub fn __udivti3(a: u128, b: u128) callconv(.C) u128 {
2020const v2u64 = @Vector(2, u64);
2121
2222fn __udivti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {
23 return @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)));
2424}
lib/compiler_rt/umodti3.zig+2-2
......@@ -23,6 +23,6 @@ const v2u64 = @Vector(2, u64);
2323
2424fn __umodti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {
2525 var r: u128 = undefined;
26 _ = udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), &r);
27 return @bitCast(v2u64, r);
26 _ = udivmod(u128, @as(u128, @bitCast(a)), @as(u128, @bitCast(b)), &r);
27 return @as(v2u64, @bitCast(r));
2828}
lib/ssp.zig+1-1
......@@ -46,7 +46,7 @@ export var __stack_chk_guard: usize = blk: {
4646 var buf = [1]u8{0} ** @sizeOf(usize);
4747 buf[@sizeOf(usize) - 1] = 255;
4848 buf[@sizeOf(usize) - 2] = '\n';
49 break :blk @bitCast(usize, buf);
49 break :blk @as(usize, @bitCast(buf));
5050};
5151
5252export 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
11111111 var populated_cpu_features = whitelist_cpu.model.features;
11121112 populated_cpu_features.populateDependencies(all_features);
11131113 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));
11151115 const in_cpu_set = populated_cpu_features.isEnabled(i);
11161116 if (in_cpu_set) {
11171117 log.err("{s} ", .{feature.name});
......@@ -1119,7 +1119,7 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros
11191119 }
11201120 log.err(" Remove: ", .{});
11211121 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));
11231123 const in_cpu_set = populated_cpu_features.isEnabled(i);
11241124 const in_actual_set = selected_cpu.features.isEnabled(i);
11251125 if (in_actual_set and !in_cpu_set) {
......@@ -1442,13 +1442,13 @@ pub fn execAllowFail(
14421442 switch (term) {
14431443 .Exited => |code| {
14441444 if (code != 0) {
1445 out_code.* = @truncate(u8, code);
1445 out_code.* = @as(u8, @truncate(code));
14461446 return error.ExitCodeFailure;
14471447 }
14481448 return stdout;
14491449 },
14501450 .Signal, .Stopped, .Unknown => |code| {
1451 out_code.* = @truncate(u8, code);
1451 out_code.* = @as(u8, @truncate(code));
14521452 return error.ProcessTerminated;
14531453 },
14541454 }
......@@ -1815,7 +1815,7 @@ pub fn serializeCpu(allocator: Allocator, cpu: std.Target.Cpu) ![]const u8 {
18151815 try mcpu_buffer.appendSlice(cpu.model.name);
18161816
18171817 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));
18191819 const in_cpu_set = populated_cpu_features.isEnabled(i);
18201820 const in_actual_set = cpu.features.isEnabled(i);
18211821 if (in_cpu_set and !in_actual_set) {
......@@ -1852,7 +1852,7 @@ pub fn hex64(x: u64) [16]u8 {
18521852 var result: [16]u8 = undefined;
18531853 var i: usize = 0;
18541854 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))));
18561856 result[i * 2 + 0] = hex_charset[byte >> 4];
18571857 result[i * 2 + 1] = hex_charset[byte & 15];
18581858 }
lib/std/Build/Cache.zig+2-2
......@@ -128,7 +128,7 @@ fn findPrefixResolved(cache: *const Cache, resolved_path: []u8) !PrefixedPath {
128128 const sub_path = try gpa.dupe(u8, resolved_path[p.len + 1 ..]);
129129 gpa.free(resolved_path);
130130 return PrefixedPath{
131 .prefix = @intCast(u8, i),
131 .prefix = @as(u8, @intCast(i)),
132132 .sub_path = sub_path,
133133 };
134134 }
......@@ -653,7 +653,7 @@ pub const Manifest = struct {
653653 return error.FileTooBig;
654654 }
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)));
657657 errdefer self.cache.gpa.free(contents);
658658
659659 // 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(
355355 },
356356 .error_bundle => {
357357 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));
359359 const extra_bytes =
360360 body[@sizeOf(EbHdr)..][0 .. @sizeOf(u32) * eb_hdr.extra_len];
361361 const string_bytes =
......@@ -377,7 +377,7 @@ pub fn evalZigProcess(
377377 },
378378 .emit_bin_path => {
379379 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));
381381 s.result_cached = ebp_hdr.flags.cache_hit;
382382 result = try arena.dupe(u8, body[@sizeOf(EbpHdr)..]);
383383 },
lib/std/Build/Step/CheckObject.zig+7-7
......@@ -449,9 +449,9 @@ const MachODumper = struct {
449449 },
450450 .SYMTAB => if (opts.dump_symtab) {
451451 const lc = cmd.cast(macho.symtab_command).?;
452 symtab = @ptrCast(
452 symtab = @as(
453453 [*]const macho.nlist_64,
454 @alignCast(@alignOf(macho.nlist_64), &bytes[lc.symoff]),
454 @ptrCast(@alignCast(&bytes[lc.symoff])),
455455 )[0..lc.nsyms];
456456 strtab = bytes[lc.stroff..][0..lc.strsize];
457457 },
......@@ -474,7 +474,7 @@ const MachODumper = struct {
474474 try writer.print("{s}\n", .{symtab_label});
475475 for (symtab) |sym| {
476476 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);
478478 if (sym.sect()) {
479479 const sect = sections.items[sym.n_sect - 1];
480480 try writer.print("{x} ({s},{s})", .{
......@@ -487,7 +487,7 @@ const MachODumper = struct {
487487 }
488488 try writer.print(" {s}\n", .{sym_name});
489489 } 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);
491491 const import_name = blk: {
492492 if (ordinal <= 0) {
493493 if (ordinal == macho.BIND_SPECIAL_DYLIB_SELF)
......@@ -498,7 +498,7 @@ const MachODumper = struct {
498498 break :blk "flat lookup";
499499 unreachable;
500500 }
501 const full_path = imports.items[@bitCast(u16, ordinal) - 1];
501 const full_path = imports.items[@as(u16, @bitCast(ordinal)) - 1];
502502 const basename = fs.path.basename(full_path);
503503 assert(basename.len > 0);
504504 const ext = mem.lastIndexOfScalar(u8, basename, '.') orelse basename.len;
......@@ -950,8 +950,8 @@ const WasmDumper = struct {
950950 switch (opcode) {
951951 .i32_const => try writer.print("i32.const {x}\n", .{try std.leb.readILEB128(i32, reader)}),
952952 .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))}),
954 .f64_const => try writer.print("f64.const {x}\n", .{@bitCast(f64, try reader.readIntLittle(u64))}),
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", .{@as(f64, @bitCast(try reader.readIntLittle(u64)))}),
955955 .global_get => try writer.print("global.get {x}\n", .{try std.leb.readULEB128(u32, reader)}),
956956 else => unreachable,
957957 }
lib/std/Build/Step/Compile.zig+3-3
......@@ -321,7 +321,7 @@ pub const BuildId = union(enum) {
321321 pub fn initHexString(bytes: []const u8) BuildId {
322322 var result: BuildId = .{ .hexstring = .{
323323 .bytes = undefined,
324 .len = @intCast(u8, bytes.len),
324 .len = @as(u8, @intCast(bytes.len)),
325325 } };
326326 @memcpy(result.hexstring.bytes[0..bytes.len], bytes);
327327 return result;
......@@ -342,7 +342,7 @@ pub const BuildId = union(enum) {
342342 } else if (mem.startsWith(u8, text, "0x")) {
343343 var result: BuildId = .{ .hexstring = undefined };
344344 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));
346346 return result;
347347 }
348348 return error.InvalidBuildIdStyle;
......@@ -2059,7 +2059,7 @@ fn findVcpkgRoot(allocator: Allocator) !?[]const u8 {
20592059 const file = fs.cwd().openFile(path_file, .{}) catch return null;
20602060 defer file.close();
20612061
2062 const size = @intCast(usize, try file.getEndPos());
2062 const size = @as(usize, @intCast(try file.getEndPos()));
20632063 const vcpkg_path = try allocator.alloc(u8, size);
20642064 const size_read = try file.read(vcpkg_path);
20652065 std.debug.assert(size == size_read);
lib/std/Build/Step/Run.zig+2-2
......@@ -998,7 +998,7 @@ fn evalZigTest(
998998 },
999999 .test_metadata => {
10001000 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));
10021002 test_count = tm_hdr.tests_len;
10031003
10041004 const names_bytes = body[@sizeOf(TmHdr)..][0 .. test_count * @sizeOf(u32)];
......@@ -1034,7 +1034,7 @@ fn evalZigTest(
10341034 const md = metadata.?;
10351035
10361036 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));
10381038 fail_count += @intFromBool(tr_hdr.flags.fail);
10391039 skip_count += @intFromBool(tr_hdr.flags.skip);
10401040 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 {
232232 }
233233
234234 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)),
236236 .Y = info.dwCursorPosition.Y,
237237 };
238238
239239 if (cursor_pos.X < 0)
240240 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
244244 var written: windows.DWORD = undefined;
245245 if (windows.kernel32.FillConsoleOutputAttribute(
lib/std/Thread.zig+21-21
......@@ -66,7 +66,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
6666 if (self.getHandle() == std.c.pthread_self()) {
6767 // Set the name of the calling thread (no thread id required).
6868 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))) {
7070 .SUCCESS => return,
7171 else => |e| return os.unexpectedErrno(e),
7272 }
......@@ -176,7 +176,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
176176 if (self.getHandle() == std.c.pthread_self()) {
177177 // Get the name of the calling thread (no thread id required).
178178 const err = try os.prctl(.GET_NAME, .{@intFromPtr(buffer.ptr)});
179 switch (@enumFromInt(os.E, err)) {
179 switch (@as(os.E, @enumFromInt(err))) {
180180 .SUCCESS => return std.mem.sliceTo(buffer, 0),
181181 else => |e| return os.unexpectedErrno(e),
182182 }
......@@ -211,7 +211,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
211211 null,
212212 )) {
213213 .SUCCESS => {
214 const string = @ptrCast(*const os.windows.UNICODE_STRING, &buf);
214 const string = @as(*const os.windows.UNICODE_STRING, @ptrCast(&buf));
215215 const len = try std.unicode.utf16leToUtf8(buffer, string.Buffer[0 .. string.Length / 2]);
216216 return if (len > 0) buffer[0..len] else null;
217217 },
......@@ -510,7 +510,7 @@ const WindowsThreadImpl = struct {
510510 thread: ThreadCompletion,
511511
512512 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));
514514 defer switch (self.thread.completion.swap(.completed, .SeqCst)) {
515515 .running => {},
516516 .completed => unreachable,
......@@ -525,7 +525,7 @@ const WindowsThreadImpl = struct {
525525 const alloc_ptr = windows.kernel32.HeapAlloc(heap_handle, 0, alloc_bytes) orelse return error.OutOfMemory;
526526 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];
529529 var fba = std.heap.FixedBufferAllocator.init(instance_bytes);
530530 const instance = fba.allocator().create(Instance) catch unreachable;
531531 instance.* = .{
......@@ -547,7 +547,7 @@ const WindowsThreadImpl = struct {
547547 null,
548548 stack_size,
549549 Instance.entryFn,
550 @ptrCast(*anyopaque, instance),
550 @as(*anyopaque, @ptrCast(instance)),
551551 0,
552552 null,
553553 ) orelse {
......@@ -596,19 +596,19 @@ const PosixThreadImpl = struct {
596596 return thread_id;
597597 },
598598 .dragonfly => {
599 return @bitCast(u32, c.lwp_gettid());
599 return @as(u32, @bitCast(c.lwp_gettid()));
600600 },
601601 .netbsd => {
602 return @bitCast(u32, c._lwp_self());
602 return @as(u32, @bitCast(c._lwp_self()));
603603 },
604604 .freebsd => {
605 return @bitCast(u32, c.pthread_getthreadid_np());
605 return @as(u32, @bitCast(c.pthread_getthreadid_np()));
606606 },
607607 .openbsd => {
608 return @bitCast(u32, c.getthrid());
608 return @as(u32, @bitCast(c.getthrid()));
609609 },
610610 .haiku => {
611 return @bitCast(u32, c.find_thread(null));
611 return @as(u32, @bitCast(c.find_thread(null)));
612612 },
613613 else => {
614614 return @intFromPtr(c.pthread_self());
......@@ -629,7 +629,7 @@ const PosixThreadImpl = struct {
629629 error.NameTooLong, error.UnknownName => unreachable,
630630 else => |e| return e,
631631 };
632 return @intCast(usize, count);
632 return @as(usize, @intCast(count));
633633 },
634634 .solaris => {
635635 // The "proper" way to get the cpu count would be to query
......@@ -637,7 +637,7 @@ const PosixThreadImpl = struct {
637637 // cpu.
638638 const rc = c.sysconf(os._SC.NPROCESSORS_ONLN);
639639 return switch (os.errno(rc)) {
640 .SUCCESS => @intCast(usize, rc),
640 .SUCCESS => @as(usize, @intCast(rc)),
641641 else => |err| os.unexpectedErrno(err),
642642 };
643643 },
......@@ -645,7 +645,7 @@ const PosixThreadImpl = struct {
645645 var system_info: os.system.system_info = undefined;
646646 const rc = os.system.get_system_info(&system_info); // always returns B_OK
647647 return switch (os.errno(rc)) {
648 .SUCCESS => @intCast(usize, system_info.cpu_count),
648 .SUCCESS => @as(usize, @intCast(system_info.cpu_count)),
649649 else => |err| os.unexpectedErrno(err),
650650 };
651651 },
......@@ -657,7 +657,7 @@ const PosixThreadImpl = struct {
657657 error.NameTooLong, error.UnknownName => unreachable,
658658 else => |e| return e,
659659 };
660 return @intCast(usize, count);
660 return @as(usize, @intCast(count));
661661 },
662662 }
663663 }
......@@ -675,7 +675,7 @@ const PosixThreadImpl = struct {
675675 return callFn(f, @as(Args, undefined));
676676 }
677677
678 const args_ptr = @ptrCast(*Args, @alignCast(@alignOf(Args), raw_arg));
678 const args_ptr: *Args = @ptrCast(@alignCast(raw_arg));
679679 defer allocator.destroy(args_ptr);
680680 return callFn(f, args_ptr.*);
681681 }
......@@ -699,7 +699,7 @@ const PosixThreadImpl = struct {
699699 &handle,
700700 &attr,
701701 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,
703703 )) {
704704 .SUCCESS => return Impl{ .handle = handle },
705705 .AGAIN => return error.SystemResources,
......@@ -742,7 +742,7 @@ const LinuxThreadImpl = struct {
742742
743743 fn getCurrentId() Id {
744744 return tls_thread_id orelse {
745 const tid = @bitCast(u32, linux.gettid());
745 const tid = @as(u32, @bitCast(linux.gettid()));
746746 tls_thread_id = tid;
747747 return tid;
748748 };
......@@ -911,7 +911,7 @@ const LinuxThreadImpl = struct {
911911 thread: ThreadCompletion,
912912
913913 fn entryFn(raw_arg: usize) callconv(.C) u8 {
914 const self = @ptrFromInt(*@This(), raw_arg);
914 const self = @as(*@This(), @ptrFromInt(raw_arg));
915915 defer switch (self.thread.completion.swap(.completed, .SeqCst)) {
916916 .running => {},
917917 .completed => unreachable,
......@@ -969,7 +969,7 @@ const LinuxThreadImpl = struct {
969969
970970 // map everything but the guard page as read/write
971971 os.mprotect(
972 @alignCast(page_size, mapped[guard_offset..]),
972 @alignCast(mapped[guard_offset..]),
973973 os.PROT.READ | os.PROT.WRITE,
974974 ) catch |err| switch (err) {
975975 error.AccessDenied => unreachable,
......@@ -994,7 +994,7 @@ const LinuxThreadImpl = struct {
994994 };
995995 }
996996
997 const instance = @ptrCast(*Instance, @alignCast(@alignOf(Instance), &mapped[instance_offset]));
997 const instance: *Instance = @ptrCast(@alignCast(&mapped[instance_offset]));
998998 instance.* = .{
999999 .fn_args = args,
10001000 .thread = .{ .mapped = mapped },
lib/std/Thread/Futex.zig+25-25
......@@ -128,14 +128,14 @@ const WindowsImpl = struct {
128128 // NTDLL functions work with time in units of 100 nanoseconds.
129129 // Positive values are absolute deadlines while negative values are relative durations.
130130 if (timeout) |delay| {
131 timeout_value = @intCast(os.windows.LARGE_INTEGER, delay / 100);
131 timeout_value = @as(os.windows.LARGE_INTEGER, @intCast(delay / 100));
132132 timeout_value = -timeout_value;
133133 timeout_ptr = &timeout_value;
134134 }
135135
136136 const rc = os.windows.ntdll.RtlWaitOnAddress(
137 @ptrCast(?*const anyopaque, ptr),
138 @ptrCast(?*const anyopaque, &expect),
137 @as(?*const anyopaque, @ptrCast(ptr)),
138 @as(?*const anyopaque, @ptrCast(&expect)),
139139 @sizeOf(@TypeOf(expect)),
140140 timeout_ptr,
141141 );
......@@ -151,7 +151,7 @@ const WindowsImpl = struct {
151151 }
152152
153153 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));
155155 assert(max_waiters != 0);
156156
157157 switch (max_waiters) {
......@@ -186,7 +186,7 @@ const DarwinImpl = struct {
186186 // true so that we we know to ignore the ETIMEDOUT result.
187187 var timeout_overflowed = false;
188188
189 const addr = @ptrCast(*const anyopaque, ptr);
189 const addr = @as(*const anyopaque, @ptrCast(ptr));
190190 const flags = os.darwin.UL_COMPARE_AND_WAIT | os.darwin.ULF_NO_ERRNO;
191191 const status = blk: {
192192 if (supports_ulock_wait2) {
......@@ -202,7 +202,7 @@ const DarwinImpl = struct {
202202 };
203203
204204 if (status >= 0) return;
205 switch (@enumFromInt(std.os.E, -status)) {
205 switch (@as(std.os.E, @enumFromInt(-status))) {
206206 // Wait was interrupted by the OS or other spurious signalling.
207207 .INTR => {},
208208 // Address of the futex was paged out. This is unlikely, but possible in theory, and
......@@ -225,11 +225,11 @@ const DarwinImpl = struct {
225225 }
226226
227227 while (true) {
228 const addr = @ptrCast(*const anyopaque, ptr);
228 const addr = @as(*const anyopaque, @ptrCast(ptr));
229229 const status = os.darwin.__ulock_wake(flags, addr, 0);
230230
231231 if (status >= 0) return;
232 switch (@enumFromInt(std.os.E, -status)) {
232 switch (@as(std.os.E, @enumFromInt(-status))) {
233233 .INTR => continue, // spurious wake()
234234 .FAULT => unreachable, // __ulock_wake doesn't generate EFAULT according to darwin pthread_cond_t
235235 .NOENT => return, // nothing was woken up
......@@ -245,14 +245,14 @@ const LinuxImpl = struct {
245245 fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{Timeout}!void {
246246 var ts: os.timespec = undefined;
247247 if (timeout) |timeout_ns| {
248 ts.tv_sec = @intCast(@TypeOf(ts.tv_sec), timeout_ns / std.time.ns_per_s);
249 ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), 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 = @as(@TypeOf(ts.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
250250 }
251251
252252 const rc = os.linux.futex_wait(
253 @ptrCast(*const i32, &ptr.value),
253 @as(*const i32, @ptrCast(&ptr.value)),
254254 os.linux.FUTEX.PRIVATE_FLAG | os.linux.FUTEX.WAIT,
255 @bitCast(i32, expect),
255 @as(i32, @bitCast(expect)),
256256 if (timeout != null) &ts else null,
257257 );
258258
......@@ -272,7 +272,7 @@ const LinuxImpl = struct {
272272
273273 fn wake(ptr: *const Atomic(u32), max_waiters: u32) void {
274274 const rc = os.linux.futex_wake(
275 @ptrCast(*const i32, &ptr.value),
275 @as(*const i32, @ptrCast(&ptr.value)),
276276 os.linux.FUTEX.PRIVATE_FLAG | os.linux.FUTEX.WAKE,
277277 std.math.cast(i32, max_waiters) orelse std.math.maxInt(i32),
278278 );
......@@ -299,8 +299,8 @@ const FreebsdImpl = struct {
299299
300300 tm._flags = 0; // use relative time not UMTX_ABSTIME
301301 tm._clockid = os.CLOCK.MONOTONIC;
302 tm._timeout.tv_sec = @intCast(@TypeOf(tm._timeout.tv_sec), 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);
302 tm._timeout.tv_sec = @as(@TypeOf(tm._timeout.tv_sec), @intCast(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));
304304 }
305305
306306 const rc = os.freebsd._umtx_op(
......@@ -347,14 +347,14 @@ const OpenbsdImpl = struct {
347347 fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{Timeout}!void {
348348 var ts: os.timespec = undefined;
349349 if (timeout) |timeout_ns| {
350 ts.tv_sec = @intCast(@TypeOf(ts.tv_sec), timeout_ns / std.time.ns_per_s);
351 ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), 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 = @as(@TypeOf(ts.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
352352 }
353353
354354 const rc = os.openbsd.futex(
355 @ptrCast(*const volatile u32, &ptr.value),
355 @as(*const volatile u32, @ptrCast(&ptr.value)),
356356 os.openbsd.FUTEX_WAIT | os.openbsd.FUTEX_PRIVATE_FLAG,
357 @bitCast(c_int, expect),
357 @as(c_int, @bitCast(expect)),
358358 if (timeout != null) &ts else null,
359359 null, // FUTEX_WAIT takes no requeue address
360360 );
......@@ -377,7 +377,7 @@ const OpenbsdImpl = struct {
377377
378378 fn wake(ptr: *const Atomic(u32), max_waiters: u32) void {
379379 const rc = os.openbsd.futex(
380 @ptrCast(*const volatile u32, &ptr.value),
380 @as(*const volatile u32, @ptrCast(&ptr.value)),
381381 os.openbsd.FUTEX_WAKE | os.openbsd.FUTEX_PRIVATE_FLAG,
382382 std.math.cast(c_int, max_waiters) orelse std.math.maxInt(c_int),
383383 null, // FUTEX_WAKE takes no timeout ptr
......@@ -411,8 +411,8 @@ const DragonflyImpl = struct {
411411 }
412412 }
413413
414 const value = @bitCast(c_int, expect);
415 const addr = @ptrCast(*const volatile c_int, &ptr.value);
414 const value = @as(c_int, @bitCast(expect));
415 const addr = @as(*const volatile c_int, @ptrCast(&ptr.value));
416416 const rc = os.dragonfly.umtx_sleep(addr, value, timeout_us);
417417
418418 switch (os.errno(rc)) {
......@@ -441,7 +441,7 @@ const DragonflyImpl = struct {
441441 // https://man.dragonflybsd.org/?command=umtx&section=2
442442 // > umtx_wakeup() will generally return 0 unless the address is bad.
443443 // 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));
445445 _ = os.dragonfly.umtx_wakeup(addr, to_wake);
446446 }
447447};
......@@ -488,8 +488,8 @@ const PosixImpl = struct {
488488 var ts: os.timespec = undefined;
489489 if (timeout) |timeout_ns| {
490490 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);
492 ts.tv_nsec += @intCast(@TypeOf(ts.tv_nsec), 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 += @as(@TypeOf(ts.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
493493
494494 if (ts.tv_nsec >= std.time.ns_per_s) {
495495 ts.tv_sec +|= 1;
lib/std/Thread/Mutex.zig+3-3
......@@ -242,12 +242,12 @@ const NonAtomicCounter = struct {
242242 value: [2]u64 = [_]u64{ 0, 0 },
243243
244244 fn get(self: NonAtomicCounter) u128 {
245 return @bitCast(u128, self.value);
245 return @as(u128, @bitCast(self.value));
246246 }
247247
248248 fn inc(self: *NonAtomicCounter) void {
249 for (@bitCast([2]u64, self.get() + 1), 0..) |v, i| {
250 @ptrCast(*volatile u64, &self.value[i]).* = v;
249 for (@as([2]u64, @bitCast(self.get() + 1)), 0..) |v, i| {
250 @as(*volatile u64, @ptrCast(&self.value[i])).* = v;
251251 }
252252 }
253253};
lib/std/array_hash_map.zig+23-23
......@@ -49,7 +49,7 @@ pub fn eqlString(a: []const u8, b: []const u8) bool {
4949}
5050
5151pub 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)));
5353}
5454
5555/// Insertion order is preserved.
......@@ -617,7 +617,7 @@ pub fn ArrayHashMapUnmanaged(
617617 return .{
618618 .keys = slice.items(.key).ptr,
619619 .values = slice.items(.value).ptr,
620 .len = @intCast(u32, slice.len),
620 .len = @as(u32, @intCast(slice.len)),
621621 };
622622 }
623623 pub const Iterator = struct {
......@@ -1409,7 +1409,7 @@ pub fn ArrayHashMapUnmanaged(
14091409 indexes: []Index(I),
14101410 ) void {
14111411 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));
14131413 }
14141414
14151415 fn removeFromIndexByIndex(self: *Self, entry_index: usize, ctx: ByIndexContext, header: *IndexHeader) void {
......@@ -1508,7 +1508,7 @@ pub fn ArrayHashMapUnmanaged(
15081508 const new_index = self.entries.addOneAssumeCapacity();
15091509 indexes[slot] = .{
15101510 .distance_from_start_index = distance_from_start_index,
1511 .entry_index = @intCast(I, new_index),
1511 .entry_index = @as(I, @intCast(new_index)),
15121512 };
15131513
15141514 // update the hash if applicable
......@@ -1549,7 +1549,7 @@ pub fn ArrayHashMapUnmanaged(
15491549 const new_index = self.entries.addOneAssumeCapacity();
15501550 if (store_hash) hashes_array.ptr[new_index] = h;
15511551 indexes[slot] = .{
1552 .entry_index = @intCast(I, new_index),
1552 .entry_index = @as(I, @intCast(new_index)),
15531553 .distance_from_start_index = distance_from_start_index,
15541554 };
15551555 distance_from_start_index = slot_data.distance_from_start_index;
......@@ -1639,7 +1639,7 @@ pub fn ArrayHashMapUnmanaged(
16391639 const start_index = safeTruncate(usize, h);
16401640 const end_index = start_index +% indexes.len;
16411641 var index = start_index;
1642 var entry_index = @intCast(I, i);
1642 var entry_index = @as(I, @intCast(i));
16431643 var distance_from_start_index: I = 0;
16441644 while (index != end_index) : ({
16451645 index +%= 1;
......@@ -1776,7 +1776,7 @@ fn capacityIndexSize(bit_index: u8) usize {
17761776fn safeTruncate(comptime T: type, val: anytype) T {
17771777 if (@bitSizeOf(T) >= @bitSizeOf(@TypeOf(val)))
17781778 return val;
1779 return @truncate(T, val);
1779 return @as(T, @truncate(val));
17801780}
17811781
17821782/// A single entry in the lookup acceleration structure. These structs
......@@ -1852,13 +1852,13 @@ const IndexHeader = struct {
18521852 fn constrainIndex(header: IndexHeader, i: usize) usize {
18531853 // This is an optimization for modulo of power of two integers;
18541854 // 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()));
18561856 }
18571857
18581858 /// Returns the attached array of indexes. I must match the type
18591859 /// returned by capacityIndexType.
18601860 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)));
18621862 return start_ptr[0..header.length()];
18631863 }
18641864
......@@ -1871,15 +1871,15 @@ const IndexHeader = struct {
18711871 return index_capacities[self.bit_index];
18721872 }
18731873 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));
18751875 }
18761876 fn mask(self: IndexHeader) u32 {
1877 return @intCast(u32, self.length() - 1);
1877 return @as(u32, @intCast(self.length() - 1));
18781878 }
18791879
18801880 fn findBitIndex(desired_capacity: usize) !u8 {
18811881 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)));
18831883 if (desired_capacity > index_capacities[new_bit_index]) new_bit_index += 1;
18841884 if (new_bit_index < min_bit_index) new_bit_index = min_bit_index;
18851885 assert(desired_capacity <= index_capacities[new_bit_index]);
......@@ -1889,12 +1889,12 @@ const IndexHeader = struct {
18891889 /// Allocates an index header, and fills the entryIndexes array with empty.
18901890 /// The distance array contents are undefined.
18911891 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));
18931893 const index_size = hash_map.capacityIndexSize(new_bit_index);
18941894 const nbytes = @sizeOf(IndexHeader) + index_size * len;
18951895 const bytes = try allocator.alignedAlloc(u8, @alignOf(IndexHeader), nbytes);
18961896 @memset(bytes[@sizeOf(IndexHeader)..], 0xff);
1897 const result = @ptrCast(*IndexHeader, bytes.ptr);
1897 const result: *IndexHeader = @alignCast(@ptrCast(bytes.ptr));
18981898 result.* = .{
18991899 .bit_index = new_bit_index,
19001900 };
......@@ -1904,7 +1904,7 @@ const IndexHeader = struct {
19041904 /// Releases the memory for a header and its associated arrays.
19051905 fn free(header: *IndexHeader, allocator: Allocator) void {
19061906 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);
19081908 const slice = ptr[0 .. @sizeOf(IndexHeader) + header.length() * index_size];
19091909 allocator.free(slice);
19101910 }
......@@ -1912,7 +1912,7 @@ const IndexHeader = struct {
19121912 /// Puts an IndexHeader into the state that it would be in after being freshly allocated.
19131913 fn reset(header: *IndexHeader) void {
19141914 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);
19161916 const nbytes = @sizeOf(IndexHeader) + header.length() * index_size;
19171917 @memset(ptr[@sizeOf(IndexHeader)..nbytes], 0xff);
19181918 }
......@@ -2020,25 +2020,25 @@ test "iterator hash map" {
20202020
20212021 var count: usize = 0;
20222022 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.*;
20242024 }
20252025 try testing.expect(count == 3);
20262026 try testing.expect(it.next() == null);
20272027
20282028 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]);
20302030 }
20312031
20322032 it.reset();
20332033 count = 0;
20342034 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.*;
20362036 count += 1;
20372037 if (count >= 2) break;
20382038 }
20392039
20402040 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]);
20422042 }
20432043
20442044 it.reset();
......@@ -2336,11 +2336,11 @@ pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K)
23362336 fn hash(ctx: Context, key: K) u32 {
23372337 _ = ctx;
23382338 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))));
23402340 } else {
23412341 var hasher = Wyhash.init(0);
23422342 autoHash(&hasher, key);
2343 return @truncate(u32, hasher.final());
2343 return @as(u32, @truncate(hasher.final()));
23442344 }
23452345 }
23462346 }.hash;
......@@ -2380,7 +2380,7 @@ pub fn getAutoHashStratFn(comptime K: type, comptime Context: type, comptime str
23802380 _ = ctx;
23812381 var hasher = Wyhash.init(0);
23822382 std.hash.autoHashStrat(&hasher, key, strategy);
2383 return @truncate(u32, hasher.final());
2383 return @as(u32, @truncate(hasher.final()));
23842384 }
23852385 }.hash;
23862386}
lib/std/array_list.zig+6-6
......@@ -1123,19 +1123,19 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
11231123 {
11241124 var i: usize = 0;
11251125 while (i < 10) : (i += 1) {
1126 list.append(@intCast(i32, i + 1)) catch unreachable;
1126 list.append(@as(i32, @intCast(i + 1))) catch unreachable;
11271127 }
11281128 }
11291129
11301130 {
11311131 var i: usize = 0;
11321132 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)));
11341134 }
11351135 }
11361136
11371137 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)));
11391139 }
11401140
11411141 try testing.expect(list.pop() == 10);
......@@ -1173,19 +1173,19 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
11731173 {
11741174 var i: usize = 0;
11751175 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;
11771177 }
11781178 }
11791179
11801180 {
11811181 var i: usize = 0;
11821182 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)));
11841184 }
11851185 }
11861186
11871187 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)));
11891189 }
11901190
11911191 try testing.expect(list.pop() == 10);
lib/std/atomic/Atomic.zig+10-10
......@@ -46,7 +46,7 @@ pub fn Atomic(comptime T: type) type {
4646 extern "c" fn __tsan_release(addr: *anyopaque) void;
4747 };
4848
49 const addr = @ptrCast(*anyopaque, self);
49 const addr = @as(*anyopaque, @ptrCast(self));
5050 return switch (ordering) {
5151 .Unordered, .Monotonic => @compileError(@tagName(ordering) ++ " only applies to atomic loads and stores"),
5252 .Acquire => tsan.__tsan_acquire(addr),
......@@ -307,7 +307,7 @@ pub fn Atomic(comptime T: type) type {
307307 // TODO: emit appropriate tsan fence if compiling with tsan
308308 _ = ordering;
309309
310 return @intCast(u1, old_bit);
310 return @as(u1, @intCast(old_bit));
311311 }
312312 });
313313 };
......@@ -392,8 +392,8 @@ test "Atomic.swap" {
392392 try testing.expectEqual(a.load(.SeqCst), true);
393393
394394 var b = Atomic(?*u8).init(null);
395 try testing.expectEqual(b.swap(@ptrFromInt(?*u8, @alignOf(u8)), ordering), null);
396 try testing.expectEqual(b.load(.SeqCst), @ptrFromInt(?*u8, @alignOf(u8)));
395 try testing.expectEqual(b.swap(@as(?*u8, @ptrFromInt(@alignOf(u8))), ordering), null);
396 try testing.expectEqual(b.load(.SeqCst), @as(?*u8, @ptrFromInt(@alignOf(u8))));
397397 }
398398}
399399
......@@ -544,7 +544,7 @@ test "Atomic.bitSet" {
544544 var x = Atomic(Int).init(0);
545545
546546 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));
548548 const mask = @as(Int, 1) << bit;
549549
550550 // setting the bit should change the bit
......@@ -558,7 +558,7 @@ test "Atomic.bitSet" {
558558
559559 // all the previous bits should have not changed (still be set)
560560 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));
562562 const prev_mask = @as(Int, 1) << prev_bit;
563563 try testing.expect(x.load(.SeqCst) & prev_mask != 0);
564564 }
......@@ -573,7 +573,7 @@ test "Atomic.bitReset" {
573573 var x = Atomic(Int).init(0);
574574
575575 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));
577577 const mask = @as(Int, 1) << bit;
578578 x.storeUnchecked(x.loadUnchecked() | mask);
579579
......@@ -588,7 +588,7 @@ test "Atomic.bitReset" {
588588
589589 // all the previous bits should have not changed (still be reset)
590590 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));
592592 const prev_mask = @as(Int, 1) << prev_bit;
593593 try testing.expect(x.load(.SeqCst) & prev_mask == 0);
594594 }
......@@ -603,7 +603,7 @@ test "Atomic.bitToggle" {
603603 var x = Atomic(Int).init(0);
604604
605605 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));
607607 const mask = @as(Int, 1) << bit;
608608
609609 // toggling the bit should change the bit
......@@ -617,7 +617,7 @@ test "Atomic.bitToggle" {
617617
618618 // all the previous bits should have not changed (still be toggled back)
619619 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));
621621 const prev_mask = @as(Int, 1) << prev_bit;
622622 try testing.expect(x.load(.SeqCst) & prev_mask == 0);
623623 }
lib/std/atomic/queue.zig+1-1
......@@ -248,7 +248,7 @@ fn startPuts(ctx: *Context) u8 {
248248 const random = prng.random();
249249 while (put_count != 0) : (put_count -= 1) {
250250 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)));
252252 const node = ctx.allocator.create(Queue(i32).Node) catch unreachable;
253253 node.* = .{
254254 .prev = undefined,
lib/std/atomic/stack.zig+1-1
......@@ -151,7 +151,7 @@ fn startPuts(ctx: *Context) u8 {
151151 const random = prng.random();
152152 while (put_count != 0) : (put_count -= 1) {
153153 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)));
155155 const node = ctx.allocator.create(Stack(i32).Node) catch unreachable;
156156 node.* = Stack(i32).Node{
157157 .next = undefined,
lib/std/base64.zig+5-5
......@@ -108,12 +108,12 @@ pub const Base64Encoder = struct {
108108 acc_len += 8;
109109 while (acc_len >= 6) {
110110 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)))];
112112 out_idx += 1;
113113 }
114114 }
115115 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)))];
117117 out_idx += 1;
118118 }
119119 if (encoder.pad_char) |pad_char| {
......@@ -144,7 +144,7 @@ pub const Base64Decoder = struct {
144144 assert(!char_in_alphabet[c]);
145145 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));
148148 char_in_alphabet[c] = true;
149149 }
150150 return result;
......@@ -196,7 +196,7 @@ pub const Base64Decoder = struct {
196196 acc_len += 6;
197197 if (acc_len >= 8) {
198198 acc_len -= 8;
199 dest[dest_idx] = @truncate(u8, acc >> acc_len);
199 dest[dest_idx] = @as(u8, @truncate(acc >> acc_len));
200200 dest_idx += 1;
201201 }
202202 }
......@@ -271,7 +271,7 @@ pub const Base64DecoderWithIgnore = struct {
271271 if (acc_len >= 8) {
272272 if (dest_idx == dest.len) return error.NoSpaceLeft;
273273 acc_len -= 8;
274 dest[dest_idx] = @truncate(u8, acc >> acc_len);
274 dest[dest_idx] = @as(u8, @truncate(acc >> acc_len));
275275 dest_idx += 1;
276276 }
277277 }
lib/std/bit_set.zig+21-21
......@@ -119,19 +119,19 @@ pub fn IntegerBitSet(comptime size: u16) type {
119119 if (range.start == range.end) return;
120120 if (MaskInt == u0) return;
121121
122 const start_bit = @intCast(ShiftInt, range.start);
122 const start_bit = @as(ShiftInt, @intCast(range.start));
123123
124124 var mask = std.math.boolMask(MaskInt, true) << start_bit;
125125 if (range.end != bit_length) {
126 const end_bit = @intCast(ShiftInt, range.end);
127 mask &= std.math.boolMask(MaskInt, true) >> @truncate(ShiftInt, @as(usize, @bitSizeOf(MaskInt)) - @as(usize, end_bit));
126 const end_bit = @as(ShiftInt, @intCast(range.end));
127 mask &= std.math.boolMask(MaskInt, true) >> @as(ShiftInt, @truncate(@as(usize, @bitSizeOf(MaskInt)) - @as(usize, end_bit)));
128128 }
129129 self.mask &= ~mask;
130130
131131 mask = std.math.boolMask(MaskInt, value) << start_bit;
132132 if (range.end != bit_length) {
133 const end_bit = @intCast(ShiftInt, range.end);
134 mask &= std.math.boolMask(MaskInt, value) >> @truncate(ShiftInt, @as(usize, @bitSizeOf(MaskInt)) - @as(usize, end_bit));
133 const end_bit = @as(ShiftInt, @intCast(range.end));
134 mask &= std.math.boolMask(MaskInt, value) >> @as(ShiftInt, @truncate(@as(usize, @bitSizeOf(MaskInt)) - @as(usize, end_bit)));
135135 }
136136 self.mask |= mask;
137137 }
......@@ -292,7 +292,7 @@ pub fn IntegerBitSet(comptime size: u16) type {
292292 .reverse => {
293293 const leading_zeroes = @clz(self.bits_remain);
294294 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;
296296 return top_bit;
297297 },
298298 }
......@@ -302,11 +302,11 @@ pub fn IntegerBitSet(comptime size: u16) type {
302302
303303 fn maskBit(index: usize) MaskInt {
304304 if (MaskInt == u0) return 0;
305 return @as(MaskInt, 1) << @intCast(ShiftInt, index);
305 return @as(MaskInt, 1) << @as(ShiftInt, @intCast(index));
306306 }
307307 fn boolMaskBit(index: usize, value: bool) MaskInt {
308308 if (MaskInt == u0) return 0;
309 return @as(MaskInt, @intFromBool(value)) << @intCast(ShiftInt, index);
309 return @as(MaskInt, @intFromBool(value)) << @as(ShiftInt, @intCast(index));
310310 }
311311 };
312312}
......@@ -442,10 +442,10 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {
442442 if (num_masks == 0) return;
443443
444444 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
447447 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
450450 if (start_mask_index == end_mask_index) {
451451 var mask1 = std.math.boolMask(MaskInt, true) << start_bit;
......@@ -634,13 +634,13 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {
634634 }
635635
636636 fn maskBit(index: usize) MaskInt {
637 return @as(MaskInt, 1) << @truncate(ShiftInt, index);
637 return @as(MaskInt, 1) << @as(ShiftInt, @truncate(index));
638638 }
639639 fn maskIndex(index: usize) usize {
640640 return index >> @bitSizeOf(ShiftInt);
641641 }
642642 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));
644644 }
645645 };
646646}
......@@ -731,7 +731,7 @@ pub const DynamicBitSetUnmanaged = struct {
731731 // set the padding bits in the old last item to 1
732732 if (fill and old_masks > 0) {
733733 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));
735735 self.masks[old_masks - 1] |= ~old_mask;
736736 }
737737
......@@ -745,7 +745,7 @@ pub const DynamicBitSetUnmanaged = struct {
745745 // Zero out the padding bits
746746 if (new_len > 0) {
747747 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));
749749 self.masks[new_masks - 1] &= last_item_mask;
750750 }
751751
......@@ -816,10 +816,10 @@ pub const DynamicBitSetUnmanaged = struct {
816816 if (range.start == range.end) return;
817817
818818 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
821821 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
824824 if (start_mask_index == end_mask_index) {
825825 var mask1 = std.math.boolMask(MaskInt, true) << start_bit;
......@@ -887,7 +887,7 @@ pub const DynamicBitSetUnmanaged = struct {
887887 }
888888
889889 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));
891891 self.masks[num_masks - 1] &= last_item_mask;
892892 }
893893
......@@ -996,7 +996,7 @@ pub const DynamicBitSetUnmanaged = struct {
996996 pub fn iterator(self: *const Self, comptime options: IteratorOptions) Iterator(options) {
997997 const num_masks = numMasks(self.bit_length);
998998 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));
10001000 return Iterator(options).init(self.masks[0..num_masks], last_item_mask);
10011001 }
10021002
......@@ -1005,13 +1005,13 @@ pub const DynamicBitSetUnmanaged = struct {
10051005 }
10061006
10071007 fn maskBit(index: usize) MaskInt {
1008 return @as(MaskInt, 1) << @truncate(ShiftInt, index);
1008 return @as(MaskInt, 1) << @as(ShiftInt, @truncate(index));
10091009 }
10101010 fn maskIndex(index: usize) usize {
10111011 return index >> @bitSizeOf(ShiftInt);
10121012 }
10131013 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));
10151015 }
10161016 fn numMasks(bit_length: usize) usize {
10171017 return (bit_length + (@bitSizeOf(MaskInt) - 1)) / @bitSizeOf(MaskInt);
......@@ -1255,7 +1255,7 @@ fn BitSetIterator(comptime MaskInt: type, comptime options: IteratorOptions) typ
12551255 .reverse => {
12561256 const leading_zeroes = @clz(self.bits_remain);
12571257 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;
12591259 self.bits_remain &= no_top_bit_mask;
12601260 return top_bit + self.bit_offset;
12611261 },
lib/std/bounded_array.zig+1-1
......@@ -394,7 +394,7 @@ test "BoundedArrayAligned" {
394394 try a.append(255);
395395 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));
398398 try testing.expectEqual(@as(u16, 0), b[0]);
399399 try testing.expectEqual(@as(u16, 65535), b[1]);
400400}
lib/std/builtin.zig+1-1
......@@ -784,7 +784,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr
784784
785785 exit_size.* = 256;
786786
787 return @ptrCast([*:0]u16, utf16.ptr);
787 return @as([*:0]u16, @ptrCast(utf16.ptr));
788788 }
789789 };
790790
lib/std/c.zig+1-1
......@@ -113,7 +113,7 @@ pub usingnamespace switch (builtin.os.tag) {
113113
114114pub fn getErrno(rc: anytype) c.E {
115115 if (rc == -1) {
116 return @enumFromInt(c.E, c._errno().*);
116 return @as(c.E, @enumFromInt(c._errno().*));
117117 } else {
118118 return .SUCCESS;
119119 }
lib/std/c/darwin.zig+34-34
......@@ -1177,10 +1177,10 @@ pub const sigset_t = u32;
11771177pub const empty_sigset: sigset_t = 0;
11781178
11791179pub const SIG = struct {
1180 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));
1181 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);
1182 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);
1183 pub const HOLD = @ptrFromInt(?Sigaction.handler_fn, 5);
1180 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
1181 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
1182 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
1183 pub const HOLD = @as(?Sigaction.handler_fn, @ptrFromInt(5));
11841184
11851185 /// block specified signal set
11861186 pub const _BLOCK = 1;
......@@ -1411,7 +1411,7 @@ pub const MAP = struct {
14111411 pub const NOCACHE = 0x0400;
14121412 /// don't reserve needed swap area
14131413 pub const NORESERVE = 0x0040;
1414 pub const FAILED = @ptrFromInt(*anyopaque, maxInt(usize));
1414 pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
14151415};
14161416
14171417pub const MSF = struct {
......@@ -1879,7 +1879,7 @@ pub const W = struct {
18791879 pub const UNTRACED = 0x00000002;
18801880
18811881 pub fn EXITSTATUS(x: u32) u8 {
1882 return @intCast(u8, x >> 8);
1882 return @as(u8, @intCast(x >> 8));
18831883 }
18841884 pub fn TERMSIG(x: u32) u32 {
18851885 return status(x);
......@@ -2463,7 +2463,7 @@ pub const KernE = enum(u32) {
24632463pub const mach_msg_return_t = kern_return_t;
24642464
24652465pub 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))))));
24672467}
24682468
24692469/// All special error code bits defined below.
......@@ -2665,10 +2665,10 @@ pub const RTLD = struct {
26652665 pub const NODELETE = 0x80;
26662666 pub const FIRST = 0x100;
26672667
2668 pub const NEXT = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -1)));
2669 pub const DEFAULT = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -2)));
2670 pub const SELF = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -3)));
2671 pub const MAIN_ONLY = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -5)));
2668 pub const NEXT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))));
2669 pub const DEFAULT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -2)))));
2670 pub const SELF = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))));
2671 pub const MAIN_ONLY = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -5)))));
26722672};
26732673
26742674pub const F = struct {
......@@ -3238,14 +3238,14 @@ pub const PosixSpawn = struct {
32383238 pub fn get(self: Attr) Error!u16 {
32393239 var flags: c_short = undefined;
32403240 switch (errno(posix_spawnattr_getflags(&self.attr, &flags))) {
3241 .SUCCESS => return @bitCast(u16, flags),
3241 .SUCCESS => return @as(u16, @bitCast(flags)),
32423242 .INVAL => unreachable,
32433243 else => |err| return unexpectedErrno(err),
32443244 }
32453245 }
32463246
32473247 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))))) {
32493249 .SUCCESS => return,
32503250 .INVAL => unreachable,
32513251 else => |err| return unexpectedErrno(err),
......@@ -3281,7 +3281,7 @@ pub const PosixSpawn = struct {
32813281 }
32823282
32833283 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))) {
32853285 .SUCCESS => return,
32863286 .BADF => return error.InvalidFileDescriptor,
32873287 .NOMEM => return error.SystemResources,
......@@ -3402,11 +3402,11 @@ pub const PosixSpawn = struct {
34023402 pub fn waitpid(pid: pid_t, flags: u32) Error!std.os.WaitPidResult {
34033403 var status: c_int = undefined;
34043404 while (true) {
3405 const rc = waitpid(pid, &status, @intCast(c_int, flags));
3405 const rc = waitpid(pid, &status, @as(c_int, @intCast(flags)));
34063406 switch (errno(rc)) {
34073407 .SUCCESS => return std.os.WaitPidResult{
3408 .pid = @intCast(pid_t, rc),
3409 .status = @bitCast(u32, status),
3408 .pid = @as(pid_t, @intCast(rc)),
3409 .status = @as(u32, @bitCast(status)),
34103410 },
34113411 .INTR => continue,
34123412 .CHILD => return error.ChildExecFailed,
......@@ -3418,7 +3418,7 @@ pub const PosixSpawn = struct {
34183418};
34193419
34203420pub 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))))));
34223422}
34233423
34243424pub fn unexpectedKernError(err: KernE) std.os.UnexpectedError {
......@@ -3585,9 +3585,9 @@ pub const MachTask = extern struct {
35853585 .top => VM_REGION_TOP_INFO,
35863586 },
35873587 switch (tag) {
3588 .basic => @ptrCast(vm_region_info_t, &info.info.basic),
3589 .extended => @ptrCast(vm_region_info_t, &info.info.extended),
3590 .top => @ptrCast(vm_region_info_t, &info.info.top),
3588 .basic => @as(vm_region_info_t, @ptrCast(&info.info.basic)),
3589 .extended => @as(vm_region_info_t, @ptrCast(&info.info.extended)),
3590 .top => @as(vm_region_info_t, @ptrCast(&info.info.top)),
35913591 },
35923592 &count,
35933593 &objname,
......@@ -3640,8 +3640,8 @@ pub const MachTask = extern struct {
36403640 &base_len,
36413641 &nesting,
36423642 switch (tag) {
3643 .short => @ptrCast(vm_region_recurse_info_t, &info.info.short),
3644 .full => @ptrCast(vm_region_recurse_info_t, &info.info.full),
3643 .short => @as(vm_region_recurse_info_t, @ptrCast(&info.info.short)),
3644 .full => @as(vm_region_recurse_info_t, @ptrCast(&info.info.full)),
36453645 },
36463646 &count,
36473647 ))) {
......@@ -3701,7 +3701,7 @@ pub const MachTask = extern struct {
37013701 task.port,
37023702 curr_addr,
37033703 @intFromPtr(out_buf.ptr),
3704 @intCast(mach_msg_type_number_t, curr_size),
3704 @as(mach_msg_type_number_t, @intCast(curr_size)),
37053705 ))) {
37063706 .SUCCESS => {},
37073707 .FAILURE => return error.PermissionDenied,
......@@ -3752,7 +3752,7 @@ pub const MachTask = extern struct {
37523752 else => |err| return unexpectedKernError(err),
37533753 }
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)));
37563756 _ = vm_deallocate(mach_task_self(), vm_memory, curr_bytes_read);
37573757
37583758 out_buf = out_buf[curr_bytes_read..];
......@@ -3782,10 +3782,10 @@ pub const MachTask = extern struct {
37823782 switch (getKernError(task_info(
37833783 task.port,
37843784 TASK_VM_INFO,
3785 @ptrCast(task_info_t, &vm_info),
3785 @as(task_info_t, @ptrCast(&vm_info)),
37863786 &info_count,
37873787 ))) {
3788 .SUCCESS => return @intCast(usize, vm_info.page_size),
3788 .SUCCESS => return @as(usize, @intCast(vm_info.page_size)),
37893789 else => {},
37903790 }
37913791 }
......@@ -3802,7 +3802,7 @@ pub const MachTask = extern struct {
38023802 switch (getKernError(task_info(
38033803 task.port,
38043804 MACH_TASK_BASIC_INFO,
3805 @ptrCast(task_info_t, &info),
3805 @as(task_info_t, @ptrCast(&info)),
38063806 &count,
38073807 ))) {
38083808 .SUCCESS => return info,
......@@ -3832,7 +3832,7 @@ pub const MachTask = extern struct {
38323832 _ = vm_deallocate(
38333833 self_task.port,
38343834 @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))),
38363836 );
38373837 }
38383838 };
......@@ -3841,7 +3841,7 @@ pub const MachTask = extern struct {
38413841 var thread_list: mach_port_array_t = undefined;
38423842 var thread_count: mach_msg_type_number_t = undefined;
38433843 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] },
38453845 else => |err| return unexpectedKernError(err),
38463846 }
38473847 }
......@@ -3860,7 +3860,7 @@ pub const MachThread = extern struct {
38603860 switch (getKernError(thread_info(
38613861 thread.port,
38623862 THREAD_BASIC_INFO,
3863 @ptrCast(thread_info_t, &info),
3863 @as(thread_info_t, @ptrCast(&info)),
38643864 &count,
38653865 ))) {
38663866 .SUCCESS => return info,
......@@ -3874,7 +3874,7 @@ pub const MachThread = extern struct {
38743874 switch (getKernError(thread_info(
38753875 thread.port,
38763876 THREAD_IDENTIFIER_INFO,
3877 @ptrCast(thread_info_t, &info),
3877 @as(thread_info_t, @ptrCast(&info)),
38783878 &count,
38793879 ))) {
38803880 .SUCCESS => return info,
......@@ -3962,7 +3962,7 @@ pub const thread_affinity_policy_t = [*]thread_affinity_policy;
39623962
39633963pub const THREAD_AFFINITY = struct {
39643964 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)));
39663966};
39673967
39683968/// cpu affinity api
......@@ -4041,7 +4041,7 @@ pub const host_preferred_user_arch_data_t = host_preferred_user_arch;
40414041pub const host_preferred_user_arch_t = *host_preferred_user_arch;
40424042
40434043fn 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)));
40454045}
40464046
40474047pub const HOST = struct {
lib/std/c/dragonfly.zig+10-10
......@@ -172,7 +172,7 @@ pub const PROT = struct {
172172
173173pub const MAP = struct {
174174 pub const FILE = 0;
175 pub const FAILED = @ptrFromInt(*anyopaque, maxInt(usize));
175 pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
176176 pub const ANONYMOUS = ANON;
177177 pub const COPY = PRIVATE;
178178 pub const SHARED = 1;
......@@ -208,7 +208,7 @@ pub const W = struct {
208208 pub const TRAPPED = 0x0020;
209209
210210 pub fn EXITSTATUS(s: u32) u8 {
211 return @intCast(u8, (s & 0xff00) >> 8);
211 return @as(u8, @intCast((s & 0xff00) >> 8));
212212 }
213213 pub fn TERMSIG(s: u32) u32 {
214214 return s & 0x7f;
......@@ -220,7 +220,7 @@ pub const W = struct {
220220 return TERMSIG(s) == 0;
221221 }
222222 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;
224224 }
225225 pub fn IFSIGNALED(s: u32) bool {
226226 return (s & 0xffff) -% 1 < 0xff;
......@@ -620,9 +620,9 @@ pub const S = struct {
620620pub const BADSIG = SIG.ERR;
621621
622622pub const SIG = struct {
623 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);
624 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);
625 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));
623 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
624 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
625 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
626626
627627 pub const BLOCK = 1;
628628 pub const UNBLOCK = 2;
......@@ -871,10 +871,10 @@ pub const RTLD = struct {
871871 pub const NODELETE = 0x01000;
872872 pub const NOLOAD = 0x02000;
873873
874 pub const NEXT = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -1)));
875 pub const DEFAULT = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -2)));
876 pub const SELF = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -3)));
877 pub const ALL = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -4)));
874 pub const NEXT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))));
875 pub const DEFAULT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -2)))));
876 pub const SELF = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))));
877 pub const ALL = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -4)))));
878878};
879879
880880pub 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 {
2020
2121fn __BIT_MASK(s: usize) c_long {
2222 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))));
2424}
2525
2626pub 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..])));
2828}
2929
3030pub fn CPU_ZERO(set: *cpuset_t) void {
......@@ -529,7 +529,7 @@ pub const cap_rights_t = extern struct {
529529
530530pub const CAP = struct {
531531 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;
533533 }
534534 pub const READ = CAP.RIGHT(0, 0x0000000000000001);
535535 pub const WRITE = CAP.RIGHT(0, 0x0000000000000002);
......@@ -961,7 +961,7 @@ pub const CLOCK = struct {
961961};
962962
963963pub const MAP = struct {
964 pub const FAILED = @ptrFromInt(*anyopaque, maxInt(usize));
964 pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
965965 pub const SHARED = 0x0001;
966966 pub const PRIVATE = 0x0002;
967967 pub const FIXED = 0x0010;
......@@ -1013,7 +1013,7 @@ pub const W = struct {
10131013 pub const TRAPPED = 32;
10141014
10151015 pub fn EXITSTATUS(s: u32) u8 {
1016 return @intCast(u8, (s & 0xff00) >> 8);
1016 return @as(u8, @intCast((s & 0xff00) >> 8));
10171017 }
10181018 pub fn TERMSIG(s: u32) u32 {
10191019 return s & 0x7f;
......@@ -1025,7 +1025,7 @@ pub const W = struct {
10251025 return TERMSIG(s) == 0;
10261026 }
10271027 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;
10291029 }
10301030 pub fn IFSIGNALED(s: u32) bool {
10311031 return (s & 0xffff) -% 1 < 0xff;
......@@ -1086,9 +1086,9 @@ pub const SIG = struct {
10861086 pub const UNBLOCK = 2;
10871087 pub const SETMASK = 3;
10881088
1089 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);
1090 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);
1091 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));
1089 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
1090 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
1091 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
10921092
10931093 pub const WORDS = 4;
10941094 pub const MAXSIG = 128;
......@@ -2626,7 +2626,7 @@ pub const domainset_t = extern struct {
26262626};
26272627
26282628pub 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..])));
26302630}
26312631
26322632pub const domainset = extern struct {
......@@ -2650,7 +2650,7 @@ const ioctl_cmd = enum(u32) {
26502650};
26512651
26522652fn 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));
26542654}
26552655
26562656pub fn IO(op: u8, nr: u8) u32 {
lib/std/c/haiku.zig+5-5
......@@ -414,7 +414,7 @@ pub const CLOCK = struct {
414414
415415pub const MAP = struct {
416416 /// mmap() error return code
417 pub const FAILED = @ptrFromInt(*anyopaque, maxInt(usize));
417 pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
418418 /// changes are seen by others
419419 pub const SHARED = 0x01;
420420 /// changes are only seen by caller
......@@ -443,7 +443,7 @@ pub const W = struct {
443443 pub const NOWAIT = 0x20;
444444
445445 pub fn EXITSTATUS(s: u32) u8 {
446 return @intCast(u8, s & 0xff);
446 return @as(u8, @intCast(s & 0xff));
447447 }
448448
449449 pub fn TERMSIG(s: u32) u32 {
......@@ -481,9 +481,9 @@ pub const SA = struct {
481481};
482482
483483pub const SIG = struct {
484 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));
485 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);
486 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);
484 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
485 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
486 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
487487
488488 pub const HUP = 1;
489489 pub const INT = 2;
lib/std/c/linux.zig+1-1
......@@ -32,7 +32,7 @@ pub const MADV = linux.MADV;
3232pub const MAP = struct {
3333 pub usingnamespace linux.MAP;
3434 /// Only used by libc to communicate failure.
35 pub const FAILED = @ptrFromInt(*anyopaque, maxInt(usize));
35 pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
3636};
3737pub const MSF = linux.MSF;
3838pub const MMAP2_UNIT = linux.MMAP2_UNIT;
lib/std/c/netbsd.zig+8-8
......@@ -172,9 +172,9 @@ pub const RTLD = struct {
172172 pub const NODELETE = 0x01000;
173173 pub const NOLOAD = 0x02000;
174174
175 pub const NEXT = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -1)));
176 pub const DEFAULT = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -2)));
177 pub const SELF = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -3)));
175 pub const NEXT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))));
176 pub const DEFAULT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -2)))));
177 pub const SELF = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))));
178178};
179179
180180pub const dl_phdr_info = extern struct {
......@@ -597,7 +597,7 @@ pub const CLOCK = struct {
597597};
598598
599599pub const MAP = struct {
600 pub const FAILED = @ptrFromInt(*anyopaque, maxInt(usize));
600 pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
601601 pub const SHARED = 0x0001;
602602 pub const PRIVATE = 0x0002;
603603 pub const REMAPDUP = 0x0004;
......@@ -653,7 +653,7 @@ pub const W = struct {
653653 pub const TRAPPED = 0x00000040;
654654
655655 pub fn EXITSTATUS(s: u32) u8 {
656 return @intCast(u8, (s >> 8) & 0xff);
656 return @as(u8, @intCast((s >> 8) & 0xff));
657657 }
658658 pub fn TERMSIG(s: u32) u32 {
659659 return s & 0x7f;
......@@ -1106,9 +1106,9 @@ pub const winsize = extern struct {
11061106const NSIG = 32;
11071107
11081108pub const SIG = struct {
1109 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);
1110 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);
1111 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));
1109 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
1110 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
1111 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
11121112
11131113 pub const WORDS = 4;
11141114 pub const MAXSIG = 128;
lib/std/c/openbsd.zig+7-7
......@@ -449,7 +449,7 @@ pub const CLOCK = struct {
449449};
450450
451451pub const MAP = struct {
452 pub const FAILED = @ptrFromInt(*anyopaque, maxInt(usize));
452 pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
453453 pub const SHARED = 0x0001;
454454 pub const PRIVATE = 0x0002;
455455 pub const FIXED = 0x0010;
......@@ -488,7 +488,7 @@ pub const W = struct {
488488 pub const CONTINUED = 8;
489489
490490 pub fn EXITSTATUS(s: u32) u8 {
491 return @intCast(u8, (s >> 8) & 0xff);
491 return @as(u8, @intCast((s >> 8) & 0xff));
492492 }
493493 pub fn TERMSIG(s: u32) u32 {
494494 return (s & 0x7f);
......@@ -1000,11 +1000,11 @@ pub const winsize = extern struct {
10001000const NSIG = 33;
10011001
10021002pub const SIG = struct {
1003 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);
1004 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);
1005 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));
1006 pub const CATCH = @ptrFromInt(?Sigaction.handler_fn, 2);
1007 pub const HOLD = @ptrFromInt(?Sigaction.handler_fn, 3);
1003 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
1004 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
1005 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
1006 pub const CATCH = @as(?Sigaction.handler_fn, @ptrFromInt(2));
1007 pub const HOLD = @as(?Sigaction.handler_fn, @ptrFromInt(3));
10081008
10091009 pub const HUP = 1;
10101010 pub const INT = 2;
lib/std/c/solaris.zig+14-14
......@@ -111,10 +111,10 @@ pub const RTLD = struct {
111111 pub const FIRST = 0x02000;
112112 pub const CONFGEN = 0x10000;
113113
114 pub const NEXT = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -1)));
115 pub const DEFAULT = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -2)));
116 pub const SELF = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -3)));
117 pub const PROBE = @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -4)));
114 pub const NEXT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))));
115 pub const DEFAULT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -2)))));
116 pub const SELF = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))));
117 pub const PROBE = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -4)))));
118118};
119119
120120pub const Flock = extern struct {
......@@ -524,7 +524,7 @@ pub const CLOCK = struct {
524524};
525525
526526pub const MAP = struct {
527 pub const FAILED = @ptrFromInt(*anyopaque, maxInt(usize));
527 pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
528528 pub const SHARED = 0x0001;
529529 pub const PRIVATE = 0x0002;
530530 pub const TYPE = 0x000f;
......@@ -583,7 +583,7 @@ pub const W = struct {
583583 pub const NOWAIT = 0o200;
584584
585585 pub fn EXITSTATUS(s: u32) u8 {
586 return @intCast(u8, (s >> 8) & 0xff);
586 return @as(u8, @intCast((s >> 8) & 0xff));
587587 }
588588 pub fn TERMSIG(s: u32) u32 {
589589 return s & 0x7f;
......@@ -886,10 +886,10 @@ pub const winsize = extern struct {
886886const NSIG = 75;
887887
888888pub const SIG = struct {
889 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);
890 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));
891 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);
892 pub const HOLD = @ptrFromInt(?Sigaction.handler_fn, 2);
889 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
890 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
891 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
892 pub const HOLD = @as(?Sigaction.handler_fn, @ptrFromInt(2));
893893
894894 pub const WORDS = 4;
895895 pub const MAXSIG = 75;
......@@ -1441,7 +1441,7 @@ pub const AT = struct {
14411441 /// Magic value that specify the use of the current working directory
14421442 /// to determine the target of relative file paths in the openat() and
14431443 /// similar syscalls.
1444 pub const FDCWD = @bitCast(fd_t, @as(u32, 0xffd19553));
1444 pub const FDCWD = @as(fd_t, @bitCast(@as(u32, 0xffd19553)));
14451445
14461446 /// Do not follow symbolic links
14471447 pub const SYMLINK_NOFOLLOW = 0x1000;
......@@ -1907,9 +1907,9 @@ const IoCtlCommand = enum(u32) {
19071907};
19081908
19091909fn ioImpl(cmd: IoCtlCommand, io_type: u8, nr: u8, comptime IOT: type) i32 {
1910 const size = @intCast(u32, @truncate(u8, @sizeOf(IOT))) << 16;
1911 const t = @intCast(u32, io_type) << 8;
1912 return @bitCast(i32, @intFromEnum(cmd) | size | t | nr);
1910 const size = @as(u32, @intCast(@as(u8, @truncate(@sizeOf(IOT))))) << 16;
1911 const t = @as(u32, @intCast(io_type)) << 8;
1912 return @as(i32, @bitCast(@intFromEnum(cmd) | size | t | nr));
19131913}
19141914
19151915pub fn IO(io_type: u8, nr: u8) i32 {
lib/std/child_process.zig+13-13
......@@ -93,7 +93,7 @@ pub const ChildProcess = struct {
9393 switch (builtin.os.tag) {
9494 .linux => {
9595 if (rus.rusage) |ru| {
96 return @intCast(usize, ru.maxrss) * 1024;
96 return @as(usize, @intCast(ru.maxrss)) * 1024;
9797 } else {
9898 return null;
9999 }
......@@ -108,7 +108,7 @@ pub const ChildProcess = struct {
108108 .macos, .ios => {
109109 if (rus.rusage) |ru| {
110110 // Darwin oddly reports in bytes instead of kilobytes.
111 return @intCast(usize, ru.maxrss);
111 return @as(usize, @intCast(ru.maxrss));
112112 } else {
113113 return null;
114114 }
......@@ -376,7 +376,7 @@ pub const ChildProcess = struct {
376376 if (windows.kernel32.GetExitCodeProcess(self.id, &exit_code) == 0) {
377377 break :x Term{ .Unknown = 0 };
378378 } else {
379 break :x Term{ .Exited = @truncate(u8, exit_code) };
379 break :x Term{ .Exited = @as(u8, @truncate(exit_code)) };
380380 }
381381 });
382382
......@@ -449,7 +449,7 @@ pub const ChildProcess = struct {
449449 // has a value greater than 0
450450 if ((fd[0].revents & std.os.POLL.IN) != 0) {
451451 const err_int = try readIntFd(err_pipe[0]);
452 return @errSetCast(SpawnError, @errorFromInt(err_int));
452 return @as(SpawnError, @errSetCast(@errorFromInt(err_int)));
453453 }
454454 } else {
455455 // Write maxInt(ErrInt) to the write end of the err_pipe. This is after
......@@ -462,7 +462,7 @@ pub const ChildProcess = struct {
462462 // Here we potentially return the fork child's error from the parent
463463 // pid.
464464 if (err_int != maxInt(ErrInt)) {
465 return @errSetCast(SpawnError, @errorFromInt(err_int));
465 return @as(SpawnError, @errSetCast(@errorFromInt(err_int)));
466466 }
467467 }
468468 }
......@@ -542,7 +542,7 @@ pub const ChildProcess = struct {
542542 } else if (builtin.output_mode == .Exe) {
543543 // Then we have Zig start code and this works.
544544 // 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));
546546 } else {
547547 // TODO come up with a solution for this.
548548 @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 {
605605 }
606606
607607 // we are the parent
608 const pid = @intCast(i32, pid_result);
608 const pid = @as(i32, @intCast(pid_result));
609609 if (self.stdin_behavior == StdIo.Pipe) {
610610 self.stdin = File{ .handle = stdin_pipe[1] };
611611 } else {
......@@ -1015,11 +1015,11 @@ fn windowsCreateProcessPathExt(
10151015 else => return windows.unexpectedStatus(rc),
10161016 }
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));
10191019 if (dir_info.FileAttributes & windows.FILE_ATTRIBUTE_DIRECTORY != 0) {
10201020 break :found_name null;
10211021 }
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];
10231023 };
10241024
10251025 const unappended_err = unappended: {
......@@ -1104,7 +1104,7 @@ fn windowsCreateProcessPathExt(
11041104 else => return windows.unexpectedStatus(rc),
11051105 }
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));
11081108 // Skip directories
11091109 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
11641164 null,
11651165 windows.TRUE,
11661166 windows.CREATE_UNICODE_ENVIRONMENT,
1167 @ptrCast(?*anyopaque, envp_ptr),
1167 @as(?*anyopaque, @ptrCast(envp_ptr)),
11681168 cwd_ptr,
11691169 lpStartupInfo,
11701170 lpProcessInformation,
......@@ -1376,7 +1376,7 @@ fn writeIntFd(fd: i32, value: ErrInt) !void {
13761376 .capable_io_mode = .blocking,
13771377 .intended_io_mode = .blocking,
13781378 };
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;
13801380}
13811381
13821382fn readIntFd(fd: i32) !ErrInt {
......@@ -1385,7 +1385,7 @@ fn readIntFd(fd: i32) !ErrInt {
13851385 .capable_io_mode = .blocking,
13861386 .intended_io_mode = .blocking,
13871387 };
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));
13891389}
13901390
13911391/// Caller must free result.
lib/std/coff.zig+16-16
......@@ -457,12 +457,12 @@ pub const ImportLookupEntry32 = struct {
457457
458458 pub fn getImportByName(raw: u32) ?ByName {
459459 if (mask & raw != 0) return null;
460 return @bitCast(ByName, raw);
460 return @as(ByName, @bitCast(raw));
461461 }
462462
463463 pub fn getImportByOrdinal(raw: u32) ?ByOrdinal {
464464 if (mask & raw == 0) return null;
465 return @bitCast(ByOrdinal, raw);
465 return @as(ByOrdinal, @bitCast(raw));
466466 }
467467};
468468
......@@ -483,12 +483,12 @@ pub const ImportLookupEntry64 = struct {
483483
484484 pub fn getImportByName(raw: u64) ?ByName {
485485 if (mask & raw != 0) return null;
486 return @bitCast(ByName, raw);
486 return @as(ByName, @bitCast(raw));
487487 }
488488
489489 pub fn getImportByOrdinal(raw: u64) ?ByOrdinal {
490490 if (mask & raw == 0) return null;
491 return @bitCast(ByOrdinal, raw);
491 return @as(ByOrdinal, @bitCast(raw));
492492 }
493493};
494494
......@@ -1146,25 +1146,25 @@ pub const Coff = struct {
11461146 }
11471147
11481148 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)])).*;
11501150 }
11511151
11521152 pub fn getOptionalHeader(self: Coff) OptionalHeader {
11531153 assert(self.is_image);
11541154 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)])).*;
11561156 }
11571157
11581158 pub fn getOptionalHeader32(self: Coff) OptionalHeaderPE32 {
11591159 assert(self.is_image);
11601160 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)])).*;
11621162 }
11631163
11641164 pub fn getOptionalHeader64(self: Coff) OptionalHeaderPE64 {
11651165 assert(self.is_image);
11661166 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)])).*;
11681168 }
11691169
11701170 pub fn getImageBase(self: Coff) u64 {
......@@ -1193,7 +1193,7 @@ pub const Coff = struct {
11931193 else => unreachable, // We assume we have validated the header already
11941194 };
11951195 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()];
11971197 }
11981198
11991199 pub fn getSymtab(self: *const Coff) ?Symtab {
......@@ -1217,7 +1217,7 @@ pub const Coff = struct {
12171217 pub fn getSectionHeaders(self: *const Coff) []align(1) const SectionHeader {
12181218 const coff_header = self.getCoffHeader();
12191219 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];
12211221 }
12221222
12231223 pub fn getSectionHeadersAlloc(self: *const Coff, allocator: mem.Allocator) ![]SectionHeader {
......@@ -1303,9 +1303,9 @@ pub const Symtab = struct {
13031303 return .{
13041304 .name = raw[0..8].*,
13051305 .value = mem.readIntLittle(u32, raw[8..12]),
1306 .section_number = @enumFromInt(SectionNumber, mem.readIntLittle(u16, raw[12..14])),
1307 .type = @bitCast(SymType, mem.readIntLittle(u16, raw[14..16])),
1308 .storage_class = @enumFromInt(StorageClass, raw[16]),
1306 .section_number = @as(SectionNumber, @enumFromInt(mem.readIntLittle(u16, raw[12..14]))),
1307 .type = @as(SymType, @bitCast(mem.readIntLittle(u16, raw[14..16]))),
1308 .storage_class = @as(StorageClass, @enumFromInt(raw[16])),
13091309 .number_of_aux_symbols = raw[17],
13101310 };
13111311 }
......@@ -1333,7 +1333,7 @@ pub const Symtab = struct {
13331333 fn asWeakExtDef(raw: []const u8) WeakExternalDefinition {
13341334 return .{
13351335 .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]))),
13371337 .unused = raw[8..18].*,
13381338 };
13391339 }
......@@ -1351,7 +1351,7 @@ pub const Symtab = struct {
13511351 .number_of_linenumbers = mem.readIntLittle(u16, raw[6..8]),
13521352 .checksum = mem.readIntLittle(u32, raw[8..12]),
13531353 .number = mem.readIntLittle(u16, raw[12..14]),
1354 .selection = @enumFromInt(ComdatSelection, raw[14]),
1354 .selection = @as(ComdatSelection, @enumFromInt(raw[14])),
13551355 .unused = raw[15..18].*,
13561356 };
13571357 }
......@@ -1384,6 +1384,6 @@ pub const Strtab = struct {
13841384
13851385 pub fn get(self: Strtab, off: u32) []const u8 {
13861386 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);
13881388 }
13891389};
lib/std/compress/deflate/bits_utils.zig+1-1
......@@ -3,7 +3,7 @@ const math = @import("std").math;
33// Reverse bit-by-bit a N-bit code.
44pub fn bitReverse(comptime T: type, value: T, N: usize) T {
55 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));
77}
88
99test "bitReverse" {
lib/std/compress/deflate/compressor.zig+19-19
......@@ -160,7 +160,7 @@ fn matchLen(a: []u8, b: []u8, max: u32) u32 {
160160 var bounded_b = b[0..max];
161161 for (bounded_a, 0..) |av, i| {
162162 if (bounded_b[i] != av) {
163 return @intCast(u32, i);
163 return @as(u32, @intCast(i));
164164 }
165165 }
166166 return max;
......@@ -313,14 +313,14 @@ pub fn Compressor(comptime WriterType: anytype) type {
313313 // the entire table onto the stack (https://golang.org/issue/18625).
314314 for (self.hash_prev, 0..) |v, i| {
315315 if (v > delta) {
316 self.hash_prev[i] = @intCast(u32, v - delta);
316 self.hash_prev[i] = @as(u32, @intCast(v - delta));
317317 } else {
318318 self.hash_prev[i] = 0;
319319 }
320320 }
321321 for (self.hash_head, 0..) |v, i| {
322322 if (v > delta) {
323 self.hash_head[i] = @intCast(u32, v - delta);
323 self.hash_head[i] = @as(u32, @intCast(v - delta));
324324 } else {
325325 self.hash_head[i] = 0;
326326 }
......@@ -329,7 +329,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
329329 }
330330 const n = std.compress.deflate.copy(self.window[self.window_end..], b);
331331 self.window_end += n;
332 return @intCast(u32, n);
332 return @as(u32, @intCast(n));
333333 }
334334
335335 fn writeBlock(self: *Self, tokens: []token.Token, index: usize) !void {
......@@ -398,13 +398,13 @@ pub fn Compressor(comptime WriterType: anytype) type {
398398 // Our chain should point to the previous value.
399399 self.hash_prev[di & window_mask] = hh.*;
400400 // 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));
402402 }
403403 self.hash = new_h;
404404 }
405405 // Update window information.
406406 self.window_end = n;
407 self.index = @intCast(u32, n);
407 self.index = @as(u32, @intCast(n));
408408 }
409409
410410 const Match = struct {
......@@ -471,11 +471,11 @@ pub fn Compressor(comptime WriterType: anytype) type {
471471 break;
472472 }
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) {
475475 break;
476476 }
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;
479479 if (i < min_index) {
480480 break;
481481 }
......@@ -576,7 +576,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
576576 // Flush current output block if any.
577577 if (self.byte_available) {
578578 // 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])));
580580 self.tokens_count += 1;
581581 self.byte_available = false;
582582 }
......@@ -591,9 +591,9 @@ pub fn Compressor(comptime WriterType: anytype) type {
591591 // Update the hash
592592 self.hash = hash4(self.window[self.index .. self.index + min_match_length]);
593593 var hh = &self.hash_head[self.hash & hash_mask];
594 self.chain_head = @intCast(u32, hh.*);
595 self.hash_prev[self.index & window_mask] = @intCast(u32, self.chain_head);
596 hh.* = @intCast(u32, self.index + self.hash_offset);
594 self.chain_head = @as(u32, @intCast(hh.*));
595 self.hash_prev[self.index & window_mask] = @as(u32, @intCast(self.chain_head));
596 hh.* = @as(u32, @intCast(self.index + self.hash_offset));
597597 }
598598 var prev_length = self.length;
599599 var prev_offset = self.offset;
......@@ -614,7 +614,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
614614 self.index,
615615 self.chain_head -| self.hash_offset,
616616 min_match_length - 1,
617 @intCast(u32, lookahead),
617 @as(u32, @intCast(lookahead)),
618618 );
619619 if (fmatch.ok) {
620620 self.length = fmatch.length;
......@@ -631,12 +631,12 @@ pub fn Compressor(comptime WriterType: anytype) type {
631631 // There was a match at the previous step, and the current match is
632632 // not better. Output the previous match.
633633 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)));
635635 self.tokens_count += 1;
636636 } else {
637637 self.tokens[self.tokens_count] = token.matchToken(
638 @intCast(u32, prev_length - base_match_length),
639 @intCast(u32, prev_offset -| base_match_offset),
638 @as(u32, @intCast(prev_length - base_match_length)),
639 @as(u32, @intCast(prev_offset -| base_match_offset)),
640640 );
641641 self.tokens_count += 1;
642642 }
......@@ -661,7 +661,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
661661 var hh = &self.hash_head[self.hash & hash_mask];
662662 self.hash_prev[index & window_mask] = hh.*;
663663 // 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));
665665 }
666666 }
667667 self.index = index;
......@@ -689,7 +689,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
689689 if (self.compression_level.fast_skip_hashshing != skip_never) {
690690 i = self.index;
691691 }
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])));
693693 self.tokens_count += 1;
694694 if (self.tokens_count == max_flate_block_tokens) {
695695 try self.writeBlock(self.tokens[0..self.tokens_count], i + 1);
......@@ -707,7 +707,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
707707 fn fillStore(self: *Self, b: []const u8) u32 {
708708 const n = std.compress.deflate.copy(self.window[self.window_end..], b);
709709 self.window_end += n;
710 return @intCast(u32, n);
710 return @as(u32, @intCast(n));
711711 }
712712
713713 fn store(self: *Self) !void {
lib/std/compress/deflate/compressor_test.zig+1-1
......@@ -172,7 +172,7 @@ test "deflate/inflate" {
172172 defer testing.allocator.free(large_data_chunk);
173173 // fill with random data
174174 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));
176176 }
177177 try testToFromWithLimit(large_data_chunk, limits);
178178}
lib/std/compress/deflate/decompressor.zig+43-43
......@@ -130,30 +130,30 @@ const HuffmanDecoder = struct {
130130 // Exception: To be compatible with zlib, we also need to
131131 // accept degenerate single-code codings. See also
132132 // 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)) {
134134 return false;
135135 }
136136
137137 self.min = min;
138138 if (max > huffman_chunk_bits) {
139 var num_links = @as(u32, 1) << @intCast(u5, max - huffman_chunk_bits);
140 self.link_mask = @intCast(u32, num_links - 1);
139 var num_links = @as(u32, 1) << @as(u5, @intCast(max - huffman_chunk_bits));
140 self.link_mask = @as(u32, @intCast(num_links - 1));
141141
142142 // create link tables
143143 var link = next_code[huffman_chunk_bits + 1] >> 1;
144144 self.links = try self.allocator.alloc([]u16, huffman_num_chunks - link);
145145 self.sub_chunks = ArrayList(u32).init(self.allocator);
146146 self.initialized = true;
147 var j = @intCast(u32, link);
147 var j = @as(u32, @intCast(link));
148148 while (j < huffman_num_chunks) : (j += 1) {
149 var reverse = @intCast(u32, bu.bitReverse(u16, @intCast(u16, j), 16));
150 reverse >>= @intCast(u32, 16 - huffman_chunk_bits);
151 var off = j - @intCast(u32, link);
149 var reverse = @as(u32, @intCast(bu.bitReverse(u16, @as(u16, @intCast(j)), 16)));
150 reverse >>= @as(u32, @intCast(16 - huffman_chunk_bits));
151 var off = j - @as(u32, @intCast(link));
152152 if (sanity) {
153153 // check we are not overwriting an existing chunk
154154 assert(self.chunks[reverse] == 0);
155155 }
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)));
157157 self.links[off] = try self.allocator.alloc(u16, num_links);
158158 if (sanity) {
159159 // initialize to a known invalid chunk code (0) to see if we overwrite
......@@ -170,12 +170,12 @@ const HuffmanDecoder = struct {
170170 }
171171 var ncode = next_code[n];
172172 next_code[n] += 1;
173 var chunk = @intCast(u16, (li << huffman_value_shift) | n);
174 var reverse = @intCast(u16, bu.bitReverse(u16, @intCast(u16, ncode), 16));
175 reverse >>= @intCast(u4, 16 - n);
173 var chunk = @as(u16, @intCast((li << huffman_value_shift) | n));
174 var reverse = @as(u16, @intCast(bu.bitReverse(u16, @as(u16, @intCast(ncode)), 16)));
175 reverse >>= @as(u4, @intCast(16 - n));
176176 if (n <= huffman_chunk_bits) {
177177 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))) {
179179 // We should never need to overwrite
180180 // an existing chunk. Also, 0 is
181181 // never a valid chunk, because the
......@@ -198,12 +198,12 @@ const HuffmanDecoder = struct {
198198 var link_tab = self.links[value];
199199 reverse >>= huffman_chunk_bits;
200200 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))) {
202202 if (sanity) {
203203 // check we are not overwriting an existing chunk
204204 assert(link_tab[off] == 0);
205205 }
206 link_tab[off] = @intCast(u16, chunk);
206 link_tab[off] = @as(u16, @intCast(chunk));
207207 }
208208 }
209209 }
......@@ -494,21 +494,21 @@ pub fn Decompressor(comptime ReaderType: type) type {
494494 while (self.nb < 5 + 5 + 4) {
495495 try self.moreBits();
496496 }
497 var nlit = @intCast(u32, self.b & 0x1F) + 257;
497 var nlit = @as(u32, @intCast(self.b & 0x1F)) + 257;
498498 if (nlit > max_num_lit) {
499499 corrupt_input_error_offset = self.roffset;
500500 self.err = InflateError.CorruptInput;
501501 return InflateError.CorruptInput;
502502 }
503503 self.b >>= 5;
504 var ndist = @intCast(u32, self.b & 0x1F) + 1;
504 var ndist = @as(u32, @intCast(self.b & 0x1F)) + 1;
505505 if (ndist > max_num_dist) {
506506 corrupt_input_error_offset = self.roffset;
507507 self.err = InflateError.CorruptInput;
508508 return InflateError.CorruptInput;
509509 }
510510 self.b >>= 5;
511 var nclen = @intCast(u32, self.b & 0xF) + 4;
511 var nclen = @as(u32, @intCast(self.b & 0xF)) + 4;
512512 // num_codes is 19, so nclen is always valid.
513513 self.b >>= 4;
514514 self.nb -= 5 + 5 + 4;
......@@ -519,7 +519,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
519519 while (self.nb < 3) {
520520 try self.moreBits();
521521 }
522 self.codebits[code_order[i]] = @intCast(u32, self.b & 0x7);
522 self.codebits[code_order[i]] = @as(u32, @intCast(self.b & 0x7));
523523 self.b >>= 3;
524524 self.nb -= 3;
525525 }
......@@ -575,8 +575,8 @@ pub fn Decompressor(comptime ReaderType: type) type {
575575 while (self.nb < nb) {
576576 try self.moreBits();
577577 }
578 rep += @intCast(u32, self.b & (@as(u32, 1) << @intCast(u5, nb)) - 1);
579 self.b >>= @intCast(u5, nb);
578 rep += @as(u32, @intCast(self.b & (@as(u32, 1) << @as(u5, @intCast(nb))) - 1));
579 self.b >>= @as(u5, @intCast(nb));
580580 self.nb -= nb;
581581 if (i + rep > n) {
582582 corrupt_input_error_offset = self.roffset;
......@@ -623,7 +623,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
623623 var length: u32 = 0;
624624 switch (v) {
625625 0...255 => {
626 self.dict.writeByte(@intCast(u8, v));
626 self.dict.writeByte(@as(u8, @intCast(v)));
627627 if (self.dict.availWrite() == 0) {
628628 self.to_read = self.dict.readFlush();
629629 self.step = huffmanBlock;
......@@ -676,8 +676,8 @@ pub fn Decompressor(comptime ReaderType: type) type {
676676 while (self.nb < n) {
677677 try self.moreBits();
678678 }
679 length += @intCast(u32, self.b) & ((@as(u32, 1) << @intCast(u5, n)) - 1);
680 self.b >>= @intCast(u5, n);
679 length += @as(u32, @intCast(self.b)) & ((@as(u32, 1) << @as(u5, @intCast(n))) - 1);
680 self.b >>= @as(u5, @intCast(n));
681681 self.nb -= n;
682682 }
683683
......@@ -686,9 +686,9 @@ pub fn Decompressor(comptime ReaderType: type) type {
686686 while (self.nb < 5) {
687687 try self.moreBits();
688688 }
689 dist = @intCast(
689 dist = @as(
690690 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)),
692692 );
693693 self.b >>= 5;
694694 self.nb -= 5;
......@@ -699,16 +699,16 @@ pub fn Decompressor(comptime ReaderType: type) type {
699699 switch (dist) {
700700 0...3 => dist += 1,
701701 4...max_num_dist - 1 => { // 4...29
702 var nb = @intCast(u32, dist - 2) >> 1;
702 var nb = @as(u32, @intCast(dist - 2)) >> 1;
703703 // 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));
705705 while (self.nb < nb) {
706706 try self.moreBits();
707707 }
708 extra |= @intCast(u32, self.b & (@as(u32, 1) << @intCast(u5, nb)) - 1);
709 self.b >>= @intCast(u5, nb);
708 extra |= @as(u32, @intCast(self.b & (@as(u32, 1) << @as(u5, @intCast(nb))) - 1));
709 self.b >>= @as(u5, @intCast(nb));
710710 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;
712712 },
713713 else => {
714714 corrupt_input_error_offset = self.roffset;
......@@ -762,10 +762,10 @@ pub fn Decompressor(comptime ReaderType: type) type {
762762 self.err = InflateError.UnexpectedEndOfStream;
763763 return InflateError.UnexpectedEndOfStream;
764764 };
765 self.roffset += @intCast(u64, nr);
766 var n = @intCast(u32, self.buf[0]) | @intCast(u32, self.buf[1]) << 8;
767 var nn = @intCast(u32, self.buf[2]) | @intCast(u32, self.buf[3]) << 8;
768 if (@intCast(u16, nn) != @truncate(u16, ~n)) {
765 self.roffset += @as(u64, @intCast(nr));
766 var n = @as(u32, @intCast(self.buf[0])) | @as(u32, @intCast(self.buf[1])) << 8;
767 var nn = @as(u32, @intCast(self.buf[2])) | @as(u32, @intCast(self.buf[3])) << 8;
768 if (@as(u16, @intCast(nn)) != @as(u16, @truncate(~n))) {
769769 corrupt_input_error_offset = self.roffset;
770770 self.err = InflateError.CorruptInput;
771771 return InflateError.CorruptInput;
......@@ -793,9 +793,9 @@ pub fn Decompressor(comptime ReaderType: type) type {
793793 if (cnt < buf.len) {
794794 self.err = InflateError.UnexpectedEndOfStream;
795795 }
796 self.roffset += @intCast(u64, cnt);
797 self.copy_len -= @intCast(u32, cnt);
798 self.dict.writeMark(@intCast(u32, cnt));
796 self.roffset += @as(u64, @intCast(cnt));
797 self.copy_len -= @as(u32, @intCast(cnt));
798 self.dict.writeMark(@as(u32, @intCast(cnt)));
799799 if (self.err != null) {
800800 return InflateError.UnexpectedEndOfStream;
801801 }
......@@ -826,7 +826,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
826826 return InflateError.BadReaderState;
827827 };
828828 self.roffset += 1;
829 self.b |= @as(u32, c) << @intCast(u5, self.nb);
829 self.b |= @as(u32, c) << @as(u5, @intCast(self.nb));
830830 self.nb += 8;
831831 return;
832832 }
......@@ -854,14 +854,14 @@ pub fn Decompressor(comptime ReaderType: type) type {
854854 return InflateError.BadReaderState;
855855 };
856856 self.roffset += 1;
857 b |= @intCast(u32, c) << @intCast(u5, nb & 31);
857 b |= @as(u32, @intCast(c)) << @as(u5, @intCast(nb & 31));
858858 nb += 8;
859859 }
860860 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));
862862 if (n > huffman_chunk_bits) {
863863 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));
865865 }
866866 if (n <= nb) {
867867 if (n == 0) {
......@@ -871,9 +871,9 @@ pub fn Decompressor(comptime ReaderType: type) type {
871871 self.err = InflateError.CorruptInput;
872872 return InflateError.CorruptInput;
873873 }
874 self.b = b >> @intCast(u5, n & 31);
874 self.b = b >> @as(u5, @intCast(n & 31));
875875 self.nb = nb - n;
876 return @intCast(u32, chunk >> huffman_value_shift);
876 return @as(u32, @intCast(chunk >> huffman_value_shift));
877877 }
878878 }
879879 }
lib/std/compress/deflate/deflate_fast.zig+46-46
......@@ -30,23 +30,23 @@ const table_size = 1 << table_bits; // Size of the table.
3030const buffer_reset = math.maxInt(i32) - max_store_block_size * 2;
3131
3232fn load32(b: []u8, i: i32) u32 {
33 var s = b[@intCast(usize, i) .. @intCast(usize, i) + 4];
34 return @intCast(u32, s[0]) |
35 @intCast(u32, s[1]) << 8 |
36 @intCast(u32, s[2]) << 16 |
37 @intCast(u32, s[3]) << 24;
33 var s = b[@as(usize, @intCast(i)) .. @as(usize, @intCast(i)) + 4];
34 return @as(u32, @intCast(s[0])) |
35 @as(u32, @intCast(s[1])) << 8 |
36 @as(u32, @intCast(s[2])) << 16 |
37 @as(u32, @intCast(s[3])) << 24;
3838}
3939
4040fn load64(b: []u8, i: i32) u64 {
41 var s = b[@intCast(usize, i)..@intCast(usize, i + 8)];
42 return @intCast(u64, s[0]) |
43 @intCast(u64, s[1]) << 8 |
44 @intCast(u64, s[2]) << 16 |
45 @intCast(u64, s[3]) << 24 |
46 @intCast(u64, s[4]) << 32 |
47 @intCast(u64, s[5]) << 40 |
48 @intCast(u64, s[6]) << 48 |
49 @intCast(u64, s[7]) << 56;
41 var s = b[@as(usize, @intCast(i))..@as(usize, @intCast(i + 8))];
42 return @as(u64, @intCast(s[0])) |
43 @as(u64, @intCast(s[1])) << 8 |
44 @as(u64, @intCast(s[2])) << 16 |
45 @as(u64, @intCast(s[3])) << 24 |
46 @as(u64, @intCast(s[4])) << 32 |
47 @as(u64, @intCast(s[5])) << 40 |
48 @as(u64, @intCast(s[6])) << 48 |
49 @as(u64, @intCast(s[7])) << 56;
5050}
5151
5252fn hash(u: u32) u32 {
......@@ -117,7 +117,7 @@ pub const DeflateFast = struct {
117117 // s_limit is when to stop looking for offset/length copies. The input_margin
118118 // lets us use a fast path for emitLiteral in the main loop, while we are
119119 // 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
122122 // next_emit is where in src the next emitLiteral should start from.
123123 var next_emit: i32 = 0;
......@@ -170,7 +170,7 @@ pub const DeflateFast = struct {
170170 // A 4-byte match has been found. We'll later see if more than 4 bytes
171171 // match. But, prior to the match, src[next_emit..s] are unmatched. Emit
172172 // 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
175175 // Call emitCopy, and then see if another emitCopy could be our next
176176 // move. Repeat until we find no match for the input immediately after
......@@ -192,8 +192,8 @@ pub const DeflateFast = struct {
192192
193193 // matchToken is flate's equivalent of Snappy's emitCopy. (length,offset)
194194 dst[tokens_count.*] = token.matchToken(
195 @intCast(u32, l + 4 - base_match_length),
196 @intCast(u32, s - t - base_match_offset),
195 @as(u32, @intCast(l + 4 - base_match_length)),
196 @as(u32, @intCast(s - t - base_match_offset)),
197197 );
198198 tokens_count.* += 1;
199199 s += l;
......@@ -209,22 +209,22 @@ pub const DeflateFast = struct {
209209 // are faster as one load64 call (with some shifts) instead of
210210 // three load32 calls.
211211 var x = load64(src, s - 1);
212 var prev_hash = hash(@truncate(u32, x));
212 var prev_hash = hash(@as(u32, @truncate(x)));
213213 self.table[prev_hash & table_mask] = TableEntry{
214214 .offset = self.cur + s - 1,
215 .val = @truncate(u32, x),
215 .val = @as(u32, @truncate(x)),
216216 };
217217 x >>= 8;
218 var curr_hash = hash(@truncate(u32, x));
218 var curr_hash = hash(@as(u32, @truncate(x)));
219219 candidate = self.table[curr_hash & table_mask];
220220 self.table[curr_hash & table_mask] = TableEntry{
221221 .offset = self.cur + s,
222 .val = @truncate(u32, x),
222 .val = @as(u32, @truncate(x)),
223223 };
224224
225225 var offset = s - (candidate.offset - self.cur);
226 if (offset > max_match_offset or @truncate(u32, x) != candidate.val) {
227 cv = @truncate(u32, x >> 8);
226 if (offset > max_match_offset or @as(u32, @truncate(x)) != candidate.val) {
227 cv = @as(u32, @truncate(x >> 8));
228228 next_hash = hash(cv);
229229 s += 1;
230230 break;
......@@ -232,18 +232,18 @@ pub const DeflateFast = struct {
232232 }
233233 }
234234
235 if (@intCast(u32, next_emit) < src.len) {
236 emitLiteral(dst, tokens_count, src[@intCast(usize, next_emit)..]);
235 if (@as(u32, @intCast(next_emit)) < src.len) {
236 emitLiteral(dst, tokens_count, src[@as(usize, @intCast(next_emit))..]);
237237 }
238 self.cur += @intCast(i32, src.len);
239 self.prev_len = @intCast(u32, src.len);
238 self.cur += @as(i32, @intCast(src.len));
239 self.prev_len = @as(u32, @intCast(src.len));
240240 @memcpy(self.prev[0..self.prev_len], src);
241241 return;
242242 }
243243
244244 fn emitLiteral(dst: []token.Token, tokens_count: *u16, lit: []u8) void {
245245 for (lit) |v| {
246 dst[tokens_count.*] = token.literalToken(@intCast(u32, v));
246 dst[tokens_count.*] = token.literalToken(@as(u32, @intCast(v)));
247247 tokens_count.* += 1;
248248 }
249249 return;
......@@ -253,60 +253,60 @@ pub const DeflateFast = struct {
253253 // t can be negative to indicate the match is starting in self.prev.
254254 // We assume that src[s-4 .. s] and src[t-4 .. t] already match.
255255 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;
257257 if (s1 > src.len) {
258 s1 = @intCast(u32, src.len);
258 s1 = @as(u32, @intCast(src.len));
259259 }
260260
261261 // If we are inside the current block
262262 if (t >= 0) {
263 var b = src[@intCast(usize, t)..];
264 var a = src[@intCast(usize, s)..@intCast(usize, s1)];
263 var b = src[@as(usize, @intCast(t))..];
264 var a = src[@as(usize, @intCast(s))..@as(usize, @intCast(s1))];
265265 b = b[0..a.len];
266266 // Extend the match to be as long as possible.
267267 for (a, 0..) |_, i| {
268268 if (a[i] != b[i]) {
269 return @intCast(i32, i);
269 return @as(i32, @intCast(i));
270270 }
271271 }
272 return @intCast(i32, a.len);
272 return @as(i32, @intCast(a.len));
273273 }
274274
275275 // 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;
277277 if (tp < 0) {
278278 return 0;
279279 }
280280
281281 // Extend the match to be as long as possible.
282 var a = src[@intCast(usize, s)..@intCast(usize, s1)];
283 var b = self.prev[@intCast(usize, tp)..@intCast(usize, self.prev_len)];
282 var a = src[@as(usize, @intCast(s))..@as(usize, @intCast(s1))];
283 var b = self.prev[@as(usize, @intCast(tp))..@as(usize, @intCast(self.prev_len))];
284284 if (b.len > a.len) {
285285 b = b[0..a.len];
286286 }
287287 a = a[0..b.len];
288288 for (b, 0..) |_, i| {
289289 if (a[i] != b[i]) {
290 return @intCast(i32, i);
290 return @as(i32, @intCast(i));
291291 }
292292 }
293293
294294 // If we reached our limit, we matched everything we are
295295 // allowed to in the previous block and we return.
296 var n = @intCast(i32, b.len);
297 if (@intCast(u32, s + n) == s1) {
296 var n = @as(i32, @intCast(b.len));
297 if (@as(u32, @intCast(s + n)) == s1) {
298298 return n;
299299 }
300300
301301 // 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))];
303303 b = src[0..a.len];
304304 for (a, 0..) |_, i| {
305305 if (a[i] != b[i]) {
306 return @intCast(i32, i) + n;
306 return @as(i32, @intCast(i)) + n;
307307 }
308308 }
309 return @intCast(i32, a.len) + n;
309 return @as(i32, @intCast(a.len)) + n;
310310 }
311311
312312 // Reset resets the encoding history.
......@@ -574,7 +574,7 @@ test "best speed match 2/2" {
574574
575575 var e = DeflateFast{
576576 .prev = previous,
577 .prev_len = @intCast(u32, previous.len),
577 .prev_len = @as(u32, @intCast(previous.len)),
578578 .table = undefined,
579579 .allocator = undefined,
580580 .cur = 0,
......@@ -617,7 +617,7 @@ test "best speed shift offsets" {
617617 try expect(want_first_tokens > want_second_tokens);
618618
619619 // 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
622622 // Part 1 before wrap, should match clean state.
623623 tokens_count = 0;
lib/std/compress/deflate/deflate_fast_test.zig+4-4
......@@ -19,7 +19,7 @@ test "best speed" {
1919 defer testing.allocator.free(abcabc);
2020
2121 for (abcabc, 0..) |_, i| {
22 abcabc[i] = @intCast(u8, i % 128);
22 abcabc[i] = @as(u8, @intCast(i % 128));
2323 }
2424
2525 var tc_01 = [_]u32{ 65536, 0 };
......@@ -119,16 +119,16 @@ test "best speed max match offset" {
119119 // zeros1 is between 0 and 30 zeros.
120120 // The difference between the two abc's will be offset, which
121121 // 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))));
123123 var src = try testing.allocator.alloc(u8, src_len);
124124 defer testing.allocator.free(src);
125125
126126 @memcpy(src[0..abc.len], abc);
127127 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)));
129129 @memcpy(src[src_offset..][0..xyz.len], xyz);
130130 }
131 const src_offset: usize = @intCast(usize, offset);
131 const src_offset: usize = @as(usize, @intCast(offset));
132132 @memcpy(src[src_offset..][0..abc.len], abc);
133133
134134 var compressed = ArrayList(u8).init(testing.allocator);
lib/std/compress/deflate/dict_decoder.zig+10-10
......@@ -49,7 +49,7 @@ pub const DictDecoder = struct {
4949 if (dict != null) {
5050 const src = dict.?[dict.?.len -| self.hist.len..];
5151 @memcpy(self.hist[0..src.len], src);
52 self.wr_pos = @intCast(u32, dict.?.len);
52 self.wr_pos = @as(u32, @intCast(dict.?.len));
5353 }
5454
5555 if (self.wr_pos == self.hist.len) {
......@@ -66,7 +66,7 @@ pub const DictDecoder = struct {
6666 // Reports the total amount of historical data in the dictionary.
6767 pub fn histSize(self: *Self) u32 {
6868 if (self.full) {
69 return @intCast(u32, self.hist.len);
69 return @as(u32, @intCast(self.hist.len));
7070 }
7171 return self.wr_pos;
7272 }
......@@ -78,7 +78,7 @@ pub const DictDecoder = struct {
7878
7979 // Reports the available amount of output buffer space.
8080 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));
8282 }
8383
8484 // Returns a slice of the available buffer to write data to.
......@@ -110,10 +110,10 @@ pub const DictDecoder = struct {
110110 fn copy(dst: []u8, src: []const u8) u32 {
111111 if (src.len > dst.len) {
112112 mem.copyForwards(u8, dst, src[0..dst.len]);
113 return @intCast(u32, dst.len);
113 return @as(u32, @intCast(dst.len));
114114 }
115115 mem.copyForwards(u8, dst[0..src.len], src);
116 return @intCast(u32, src.len);
116 return @as(u32, @intCast(src.len));
117117 }
118118
119119 // Copies a string at a given (dist, length) to the output.
......@@ -125,10 +125,10 @@ pub const DictDecoder = struct {
125125 assert(0 < dist and dist <= self.histSize());
126126 var dst_base = self.wr_pos;
127127 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));
129129 var end_pos = dst_pos + length;
130130 if (end_pos > self.hist.len) {
131 end_pos = @intCast(u32, self.hist.len);
131 end_pos = @as(u32, @intCast(self.hist.len));
132132 }
133133
134134 // Copy non-overlapping section after destination position.
......@@ -139,8 +139,8 @@ pub const DictDecoder = struct {
139139 // Thus, a backwards copy is performed here; that is, the exact bytes in
140140 // the source prior to the copy is placed in the destination.
141141 if (src_pos < 0) {
142 src_pos += @intCast(i32, self.hist.len);
143 dst_pos += copy(self.hist[dst_pos..end_pos], self.hist[@intCast(usize, src_pos)..]);
142 src_pos += @as(i32, @intCast(self.hist.len));
143 dst_pos += copy(self.hist[dst_pos..end_pos], self.hist[@as(usize, @intCast(src_pos))..]);
144144 src_pos = 0;
145145 }
146146
......@@ -160,7 +160,7 @@ pub const DictDecoder = struct {
160160 // dst_pos = end_pos;
161161 //
162162 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]);
164164 }
165165
166166 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 {
107107 }
108108 var n = self.nbytes;
109109 while (self.nbits != 0) {
110 self.bytes[n] = @truncate(u8, self.bits);
110 self.bytes[n] = @as(u8, @truncate(self.bits));
111111 self.bits >>= 8;
112112 if (self.nbits > 8) { // Avoid underflow
113113 self.nbits -= 8;
......@@ -132,7 +132,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
132132 if (self.err) {
133133 return;
134134 }
135 self.bits |= @intCast(u64, b) << @intCast(u6, self.nbits);
135 self.bits |= @as(u64, @intCast(b)) << @as(u6, @intCast(self.nbits));
136136 self.nbits += nb;
137137 if (self.nbits >= 48) {
138138 var bits = self.bits;
......@@ -140,12 +140,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
140140 self.nbits -= 48;
141141 var n = self.nbytes;
142142 var bytes = self.bytes[n..][0..6];
143 bytes[0] = @truncate(u8, bits);
144 bytes[1] = @truncate(u8, bits >> 8);
145 bytes[2] = @truncate(u8, bits >> 16);
146 bytes[3] = @truncate(u8, bits >> 24);
147 bytes[4] = @truncate(u8, bits >> 32);
148 bytes[5] = @truncate(u8, bits >> 40);
143 bytes[0] = @as(u8, @truncate(bits));
144 bytes[1] = @as(u8, @truncate(bits >> 8));
145 bytes[2] = @as(u8, @truncate(bits >> 16));
146 bytes[3] = @as(u8, @truncate(bits >> 24));
147 bytes[4] = @as(u8, @truncate(bits >> 32));
148 bytes[5] = @as(u8, @truncate(bits >> 40));
149149 n += 6;
150150 if (n >= buffer_flush_size) {
151151 try self.write(self.bytes[0..n]);
......@@ -165,7 +165,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
165165 return;
166166 }
167167 while (self.nbits != 0) {
168 self.bytes[n] = @truncate(u8, self.bits);
168 self.bytes[n] = @as(u8, @truncate(self.bits));
169169 self.bits >>= 8;
170170 self.nbits -= 8;
171171 n += 1;
......@@ -209,12 +209,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
209209 // Copy the concatenated code sizes to codegen. Put a marker at the end.
210210 var cgnl = codegen[0..num_literals];
211211 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));
213213 }
214214
215215 cgnl = codegen[num_literals .. num_literals + num_offsets];
216216 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));
218218 }
219219 codegen[num_literals + num_offsets] = bad_code;
220220
......@@ -243,7 +243,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
243243 }
244244 codegen[out_index] = 16;
245245 out_index += 1;
246 codegen[out_index] = @intCast(u8, n - 3);
246 codegen[out_index] = @as(u8, @intCast(n - 3));
247247 out_index += 1;
248248 self.codegen_freq[16] += 1;
249249 count -= n;
......@@ -256,7 +256,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
256256 }
257257 codegen[out_index] = 18;
258258 out_index += 1;
259 codegen[out_index] = @intCast(u8, n - 11);
259 codegen[out_index] = @as(u8, @intCast(n - 11));
260260 out_index += 1;
261261 self.codegen_freq[18] += 1;
262262 count -= n;
......@@ -265,7 +265,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
265265 // 3 <= count <= 10
266266 codegen[out_index] = 17;
267267 out_index += 1;
268 codegen[out_index] = @intCast(u8, count - 3);
268 codegen[out_index] = @as(u8, @intCast(count - 3));
269269 out_index += 1;
270270 self.codegen_freq[17] += 1;
271271 count = 0;
......@@ -307,8 +307,8 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
307307 extra_bits;
308308
309309 return DynamicSize{
310 .size = @intCast(u32, size),
311 .num_codegens = @intCast(u32, num_codegens),
310 .size = @as(u32, @intCast(size)),
311 .num_codegens = @as(u32, @intCast(num_codegens)),
312312 };
313313 }
314314
......@@ -328,7 +328,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
328328 return .{ .size = 0, .storable = false };
329329 }
330330 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 };
332332 }
333333 return .{ .size = 0, .storable = false };
334334 }
......@@ -337,20 +337,20 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
337337 if (self.err) {
338338 return;
339339 }
340 self.bits |= @intCast(u64, c.code) << @intCast(u6, self.nbits);
341 self.nbits += @intCast(u32, c.len);
340 self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits));
341 self.nbits += @as(u32, @intCast(c.len));
342342 if (self.nbits >= 48) {
343343 var bits = self.bits;
344344 self.bits >>= 48;
345345 self.nbits -= 48;
346346 var n = self.nbytes;
347347 var bytes = self.bytes[n..][0..6];
348 bytes[0] = @truncate(u8, bits);
349 bytes[1] = @truncate(u8, bits >> 8);
350 bytes[2] = @truncate(u8, bits >> 16);
351 bytes[3] = @truncate(u8, bits >> 24);
352 bytes[4] = @truncate(u8, bits >> 32);
353 bytes[5] = @truncate(u8, bits >> 40);
348 bytes[0] = @as(u8, @truncate(bits));
349 bytes[1] = @as(u8, @truncate(bits >> 8));
350 bytes[2] = @as(u8, @truncate(bits >> 16));
351 bytes[3] = @as(u8, @truncate(bits >> 24));
352 bytes[4] = @as(u8, @truncate(bits >> 32));
353 bytes[5] = @as(u8, @truncate(bits >> 40));
354354 n += 6;
355355 if (n >= buffer_flush_size) {
356356 try self.write(self.bytes[0..n]);
......@@ -381,36 +381,36 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
381381 first_bits = 5;
382382 }
383383 try self.writeBits(first_bits, 3);
384 try self.writeBits(@intCast(u32, num_literals - 257), 5);
385 try self.writeBits(@intCast(u32, num_offsets - 1), 5);
386 try self.writeBits(@intCast(u32, num_codegens - 4), 4);
384 try self.writeBits(@as(u32, @intCast(num_literals - 257)), 5);
385 try self.writeBits(@as(u32, @intCast(num_offsets - 1)), 5);
386 try self.writeBits(@as(u32, @intCast(num_codegens - 4)), 4);
387387
388388 var i: u32 = 0;
389389 while (i < num_codegens) : (i += 1) {
390 var value = @intCast(u32, self.codegen_encoding.codes[codegen_order[i]].len);
391 try self.writeBits(@intCast(u32, value), 3);
390 var value = @as(u32, @intCast(self.codegen_encoding.codes[codegen_order[i]].len));
391 try self.writeBits(@as(u32, @intCast(value)), 3);
392392 }
393393
394394 i = 0;
395395 while (true) {
396 var code_word: u32 = @intCast(u32, self.codegen[i]);
396 var code_word: u32 = @as(u32, @intCast(self.codegen[i]));
397397 i += 1;
398398 if (code_word == bad_code) {
399399 break;
400400 }
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
403403 switch (code_word) {
404404 16 => {
405 try self.writeBits(@intCast(u32, self.codegen[i]), 2);
405 try self.writeBits(@as(u32, @intCast(self.codegen[i])), 2);
406406 i += 1;
407407 },
408408 17 => {
409 try self.writeBits(@intCast(u32, self.codegen[i]), 3);
409 try self.writeBits(@as(u32, @intCast(self.codegen[i])), 3);
410410 i += 1;
411411 },
412412 18 => {
413 try self.writeBits(@intCast(u32, self.codegen[i]), 7);
413 try self.writeBits(@as(u32, @intCast(self.codegen[i])), 7);
414414 i += 1;
415415 },
416416 else => {},
......@@ -428,8 +428,8 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
428428 }
429429 try self.writeBits(flag, 3);
430430 try self.flush();
431 try self.writeBits(@intCast(u32, length), 16);
432 try self.writeBits(@intCast(u32, ~@intCast(u16, length)), 16);
431 try self.writeBits(@as(u32, @intCast(length)), 16);
432 try self.writeBits(@as(u32, @intCast(~@as(u16, @intCast(length)))), 16);
433433 }
434434
435435 fn writeFixedHeader(self: *Self, is_eof: bool) Error!void {
......@@ -476,14 +476,14 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
476476 var length_code: u32 = length_codes_start + 8;
477477 while (length_code < num_literals) : (length_code += 1) {
478478 // First eight length codes have extra size = 0.
479 extra_bits += @intCast(u32, self.literal_freq[length_code]) *
480 @intCast(u32, length_extra_bits[length_code - length_codes_start]);
479 extra_bits += @as(u32, @intCast(self.literal_freq[length_code])) *
480 @as(u32, @intCast(length_extra_bits[length_code - length_codes_start]));
481481 }
482482 var offset_code: u32 = 4;
483483 while (offset_code < num_offsets) : (offset_code += 1) {
484484 // First four offset codes have extra size = 0.
485 extra_bits += @intCast(u32, self.offset_freq[offset_code]) *
486 @intCast(u32, offset_extra_bits[offset_code]);
485 extra_bits += @as(u32, @intCast(self.offset_freq[offset_code])) *
486 @as(u32, @intCast(offset_extra_bits[offset_code]));
487487 }
488488 }
489489
......@@ -621,12 +621,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
621621 self.literal_freq[token.literal(deflate_const.end_block_marker)] += 1;
622622
623623 // get the number of literals
624 num_literals = @intCast(u32, self.literal_freq.len);
624 num_literals = @as(u32, @intCast(self.literal_freq.len));
625625 while (self.literal_freq[num_literals - 1] == 0) {
626626 num_literals -= 1;
627627 }
628628 // get the number of offsets
629 num_offsets = @intCast(u32, self.offset_freq.len);
629 num_offsets = @as(u32, @intCast(self.offset_freq.len));
630630 while (num_offsets > 0 and self.offset_freq[num_offsets - 1] == 0) {
631631 num_offsets -= 1;
632632 }
......@@ -664,18 +664,18 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
664664 var length = token.length(t);
665665 var length_code = token.lengthCode(length);
666666 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]));
668668 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]));
670670 try self.writeBits(extra_length, extra_length_bits);
671671 }
672672 // Write the offset
673673 var offset = token.offset(t);
674674 var offset_code = token.offsetCode(offset);
675675 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]));
677677 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]));
679679 try self.writeBits(extra_offset, extra_offset_bits);
680680 }
681681 }
......@@ -742,8 +742,8 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
742742 for (input) |t| {
743743 // Bitwriting inlined, ~30% speedup
744744 var c = encoding[t];
745 self.bits |= @intCast(u64, c.code) << @intCast(u6, self.nbits);
746 self.nbits += @intCast(u32, c.len);
745 self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits));
746 self.nbits += @as(u32, @intCast(c.len));
747747 if (self.nbits < 48) {
748748 continue;
749749 }
......@@ -752,12 +752,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
752752 self.bits >>= 48;
753753 self.nbits -= 48;
754754 var bytes = self.bytes[n..][0..6];
755 bytes[0] = @truncate(u8, bits);
756 bytes[1] = @truncate(u8, bits >> 8);
757 bytes[2] = @truncate(u8, bits >> 16);
758 bytes[3] = @truncate(u8, bits >> 24);
759 bytes[4] = @truncate(u8, bits >> 32);
760 bytes[5] = @truncate(u8, bits >> 40);
755 bytes[0] = @as(u8, @truncate(bits));
756 bytes[1] = @as(u8, @truncate(bits >> 8));
757 bytes[2] = @as(u8, @truncate(bits >> 16));
758 bytes[3] = @as(u8, @truncate(bits >> 24));
759 bytes[4] = @as(u8, @truncate(bits >> 32));
760 bytes[5] = @as(u8, @truncate(bits >> 40));
761761 n += 6;
762762 if (n < buffer_flush_size) {
763763 continue;
lib/std/compress/deflate/huffman_code.zig+10-10
......@@ -73,7 +73,7 @@ pub const HuffmanEncoder = struct {
7373 // Set list to be the set of all non-zero literals and their frequencies
7474 for (freq, 0..) |f, i| {
7575 if (f != 0) {
76 list[count] = LiteralNode{ .literal = @intCast(u16, i), .freq = f };
76 list[count] = LiteralNode{ .literal = @as(u16, @intCast(i)), .freq = f };
7777 count += 1;
7878 } else {
7979 list[count] = LiteralNode{ .literal = 0x00, .freq = 0 };
......@@ -88,7 +88,7 @@ pub const HuffmanEncoder = struct {
8888 // two or fewer literals, everything has bit length 1.
8989 for (list, 0..) |node, i| {
9090 // "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);
9292 }
9393 return;
9494 }
......@@ -105,7 +105,7 @@ pub const HuffmanEncoder = struct {
105105 var total: u32 = 0;
106106 for (freq, 0..) |f, i| {
107107 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));
109109 }
110110 }
111111 return total;
......@@ -167,7 +167,7 @@ pub const HuffmanEncoder = struct {
167167 }
168168
169169 // 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
172172 {
173173 var level = max_bits;
......@@ -267,19 +267,19 @@ pub const HuffmanEncoder = struct {
267267 // are encoded using "bits" bits, and get the values
268268 // code, code + 1, .... The code values are
269269 // 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
272272 self.lns = chunk;
273273 mem.sort(LiteralNode, self.lns, {}, byLiteral);
274274
275275 for (chunk) |node| {
276276 self.codes[node.literal] = HuffCode{
277 .code = bu.bitReverse(u16, code, @intCast(u5, n)),
278 .len = @intCast(u16, n),
277 .code = bu.bitReverse(u16, code, @as(u5, @intCast(n))),
278 .len = @as(u16, @intCast(n)),
279279 };
280280 code += 1;
281281 }
282 list = list[0 .. list.len - @intCast(u32, bits)];
282 list = list[0 .. list.len - @as(u32, @intCast(bits))];
283283 }
284284 }
285285};
......@@ -332,7 +332,7 @@ pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder {
332332 size = 8;
333333 },
334334 }
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 };
336336 }
337337 return h;
338338}
......@@ -341,7 +341,7 @@ pub fn generateFixedOffsetEncoding(allocator: Allocator) !HuffmanEncoder {
341341 var h = try newHuffmanEncoder(allocator, 30);
342342 var codes = h.codes;
343343 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 };
345345 }
346346 return h;
347347}
lib/std/compress/deflate/token.zig+5-5
......@@ -70,16 +70,16 @@ pub fn matchToken(xlength: u32, xoffset: u32) Token {
7070
7171// Returns the literal of a literal token
7272pub fn literal(t: Token) u32 {
73 return @intCast(u32, t - literal_type);
73 return @as(u32, @intCast(t - literal_type));
7474}
7575
7676// Returns the extra offset of a match token
7777pub fn offset(t: Token) u32 {
78 return @intCast(u32, t) & offset_mask;
78 return @as(u32, @intCast(t)) & offset_mask;
7979}
8080
8181pub fn length(t: Token) u32 {
82 return @intCast(u32, (t - match_type) >> length_shift);
82 return @as(u32, @intCast((t - match_type) >> length_shift));
8383}
8484
8585pub fn lengthCode(len: u32) u32 {
......@@ -88,10 +88,10 @@ pub fn lengthCode(len: u32) u32 {
8888
8989// Returns the offset code corresponding to a specific offset
9090pub fn offsetCode(off: u32) u32 {
91 if (off < @intCast(u32, offset_codes.len)) {
91 if (off < @as(u32, @intCast(offset_codes.len))) {
9292 return offset_codes[off];
9393 }
94 if (off >> 7 < @intCast(u32, offset_codes.len)) {
94 if (off >> 7 < @as(u32, @intCast(offset_codes.len))) {
9595 return offset_codes[off >> 7] + 14;
9696 }
9797 return offset_codes[off >> 14] + 28;
lib/std/compress/gzip.zig+1-1
......@@ -89,7 +89,7 @@ pub fn Decompress(comptime ReaderType: type) type {
8989
9090 if (FLG & FHCRC != 0) {
9191 const hash = try source.readIntLittle(u16);
92 if (hash != @truncate(u16, hasher.hasher.final()))
92 if (hash != @as(u16, @truncate(hasher.hasher.final())))
9393 return error.WrongChecksum;
9494 }
9595
lib/std/compress/lzma/decode.zig+5-5
......@@ -52,11 +52,11 @@ pub const Params = struct {
5252 return error.CorruptInput;
5353 }
5454
55 const lc = @intCast(u4, props % 9);
55 const lc = @as(u4, @intCast(props % 9));
5656 props /= 9;
57 const lp = @intCast(u3, props % 5);
57 const lp = @as(u3, @intCast(props % 5));
5858 props /= 5;
59 const pb = @intCast(u3, props);
59 const pb = @as(u3, @intCast(props));
6060
6161 const dict_size_provided = try reader.readIntLittle(u32);
6262 const dict_size = @max(0x1000, dict_size_provided);
......@@ -342,7 +342,7 @@ pub const DecoderState = struct {
342342 result = (result << 1) ^ @intFromBool(try decoder.decodeBit(reader, &probs[result], update));
343343 }
344344
345 return @truncate(u8, result - 0x100);
345 return @as(u8, @truncate(result - 0x100));
346346 }
347347
348348 fn decodeDistance(
......@@ -358,7 +358,7 @@ pub const DecoderState = struct {
358358 if (pos_slot < 4)
359359 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));
362362 var result = (2 ^ (pos_slot & 1)) << num_direct_bits;
363363
364364 if (pos_slot < 14) {
lib/std/compress/lzma2/decode.zig+3-3
......@@ -119,11 +119,11 @@ pub const Decoder = struct {
119119 return error.CorruptInput;
120120 }
121121
122 const lc = @intCast(u4, props % 9);
122 const lc = @as(u4, @intCast(props % 9));
123123 props /= 9;
124 const lp = @intCast(u3, props % 5);
124 const lp = @as(u3, @intCast(props % 5));
125125 props /= 5;
126 const pb = @intCast(u3, props);
126 const pb = @as(u3, @intCast(props));
127127
128128 if (lc + lp > 4) {
129129 return error.CorruptInput;
lib/std/compress/xz.zig+1-1
......@@ -18,7 +18,7 @@ fn readStreamFlags(reader: anytype, check: *Check) !void {
1818 if (reserved1 != 0)
1919 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
2323 const reserved2 = try bit_reader.readBitsNoEof(u4, 4);
2424 if (reserved2 != 0)
lib/std/compress/xz/block.zig+3-3
......@@ -108,7 +108,7 @@ pub fn Decoder(comptime ReaderType: type) type {
108108 has_unpacked_size: bool,
109109 };
110110
111 const flags = @bitCast(Flags, try header_reader.readByte());
111 const flags = @as(Flags, @bitCast(try header_reader.readByte()));
112112 const filter_count = @as(u3, flags.last_filter_index) + 1;
113113 if (filter_count > 1)
114114 return error.Unsupported;
......@@ -124,9 +124,9 @@ pub fn Decoder(comptime ReaderType: type) type {
124124 _,
125125 };
126126
127 const filter_id = @enumFromInt(
127 const filter_id = @as(
128128 FilterId,
129 try std.leb.readULEB128(u64, header_reader),
129 @enumFromInt(try std.leb.readULEB128(u64, header_reader)),
130130 );
131131
132132 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 {
4141 // verify the header checksum
4242 if (header_u16 % 31 != 0)
4343 return error.BadHeader;
44 const header = @bitCast(ZLibHeader, header_u16);
44 const header = @as(ZLibHeader, @bitCast(header_u16));
4545
4646 // The CM field must be 8 to indicate the use of DEFLATE
4747 if (header.compression_method != ZLibHeader.DEFLATE)
......@@ -130,9 +130,9 @@ pub fn CompressStream(comptime WriterType: type) type {
130130 .preset_dict = 0,
131131 .checksum = 0,
132132 };
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
137137 const compression_level: deflate.Compression = switch (options.level) {
138138 .no_compression => .no_compression,
lib/std/compress/zstandard/decode/block.zig+7-7
......@@ -894,7 +894,7 @@ pub fn decodeBlockReader(
894894/// Decode the header of a block.
895895pub fn decodeBlockHeader(src: *const [3]u8) frame.Zstandard.Block.Header {
896896 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));
898898 const block_size = ((src[0] & 0b11111000) >> 3) + (@as(u21, src[1]) << 5) + (@as(u21, src[2]) << 13);
899899 return .{
900900 .last_block = last_block,
......@@ -1008,7 +1008,7 @@ pub fn decodeLiteralsSection(
10081008 try huffman.decodeHuffmanTree(counting_reader.reader(), buffer)
10091009 else
10101010 null;
1011 const huffman_tree_size = @intCast(usize, counting_reader.bytes_read);
1011 const huffman_tree_size = @as(usize, @intCast(counting_reader.bytes_read));
10121012 const total_streams_size = std.math.sub(usize, header.compressed_size.?, huffman_tree_size) catch
10131013 return error.MalformedLiteralsSection;
10141014
......@@ -1058,8 +1058,8 @@ fn decodeStreams(size_format: u2, stream_data: []const u8) !LiteralsSection.Stre
10581058/// - `error.EndOfStream` if there are not enough bytes in `source`
10591059pub fn decodeLiteralsHeader(source: anytype) !LiteralsSection.Header {
10601060 const byte0 = try source.readByte();
1061 const block_type = @enumFromInt(LiteralsSection.BlockType, byte0 & 0b11);
1062 const size_format = @intCast(u2, (byte0 & 0b1100) >> 2);
1061 const block_type = @as(LiteralsSection.BlockType, @enumFromInt(byte0 & 0b11));
1062 const size_format = @as(u2, @intCast((byte0 & 0b1100) >> 2));
10631063 var regenerated_size: u20 = undefined;
10641064 var compressed_size: ?u18 = null;
10651065 switch (block_type) {
......@@ -1132,9 +1132,9 @@ pub fn decodeSequencesHeader(
11321132
11331133 const compression_modes = try source.readByte();
11341134
1135 const matches_mode = @enumFromInt(SequencesSection.Header.Mode, (compression_modes & 0b00001100) >> 2);
1136 const offsets_mode = @enumFromInt(SequencesSection.Header.Mode, (compression_modes & 0b00110000) >> 4);
1137 const literal_mode = @enumFromInt(SequencesSection.Header.Mode, (compression_modes & 0b11000000) >> 6);
1135 const matches_mode = @as(SequencesSection.Header.Mode, @enumFromInt((compression_modes & 0b00001100) >> 2));
1136 const offsets_mode = @as(SequencesSection.Header.Mode, @enumFromInt((compression_modes & 0b00110000) >> 4));
1137 const literal_mode = @as(SequencesSection.Header.Mode, @enumFromInt((compression_modes & 0b11000000) >> 6));
11381138 if (compression_modes & 0b11 != 0) return error.ReservedBitSet;
11391139
11401140 return SequencesSection.Header{
lib/std/compress/zstandard/decode/fse.zig+7-7
......@@ -69,7 +69,7 @@ pub fn decodeFseTable(
6969}
7070
7171fn 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));
7373 const accuracy_log = std.math.log2_int(u16, total_probability);
7474 assert(total_probability <= 1 << 9);
7575
......@@ -77,7 +77,7 @@ fn buildFseTable(values: []const u16, entries: []Table.Fse) !void {
7777 for (values, 0..) |value, i| {
7878 if (value == 0) {
7979 entries[entries.len - 1 - less_than_one_count] = Table.Fse{
80 .symbol = @intCast(u8, i),
80 .symbol = @as(u8, @intCast(i)),
8181 .baseline = 0,
8282 .bits = accuracy_log,
8383 };
......@@ -99,7 +99,7 @@ fn buildFseTable(values: []const u16, entries: []Table.Fse) !void {
9999 const share_size_log = std.math.log2_int(u16, share_size);
100100
101101 for (0..probability) |i| {
102 temp_states[i] = @intCast(u16, position);
102 temp_states[i] = @as(u16, @intCast(position));
103103 position += (entries.len >> 1) + (entries.len >> 3) + 3;
104104 position &= entries.len - 1;
105105 while (position >= entries.len - less_than_one_count) {
......@@ -110,13 +110,13 @@ fn buildFseTable(values: []const u16, entries: []Table.Fse) !void {
110110 std.mem.sort(u16, temp_states[0..probability], {}, std.sort.asc(u16));
111111 for (0..probability) |i| {
112112 entries[temp_states[i]] = if (i < double_state_count) Table.Fse{
113 .symbol = @intCast(u8, symbol),
113 .symbol = @as(u8, @intCast(symbol)),
114114 .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,
116116 } else Table.Fse{
117 .symbol = @intCast(u8, symbol),
117 .symbol = @as(u8, @intCast(symbol)),
118118 .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,
120120 };
121121 }
122122 }
lib/std/compress/zstandard/decode/huffman.zig+5-5
......@@ -109,8 +109,8 @@ fn decodeDirectHuffmanTree(source: anytype, encoded_symbol_count: usize, weights
109109 const weights_byte_count = (encoded_symbol_count + 1) / 2;
110110 for (0..weights_byte_count) |i| {
111111 const byte = try source.readByte();
112 weights[2 * i] = @intCast(u4, byte >> 4);
113 weights[2 * i + 1] = @intCast(u4, byte & 0xF);
112 weights[2 * i] = @as(u4, @intCast(byte >> 4));
113 weights[2 * i + 1] = @as(u4, @intCast(byte & 0xF));
114114 }
115115 return encoded_symbol_count + 1;
116116}
......@@ -118,7 +118,7 @@ fn decodeDirectHuffmanTree(source: anytype, encoded_symbol_count: usize, weights
118118fn assignSymbols(weight_sorted_prefixed_symbols: []LiteralsSection.HuffmanTree.PrefixedSymbol, weights: [256]u4) usize {
119119 for (0..weight_sorted_prefixed_symbols.len) |i| {
120120 weight_sorted_prefixed_symbols[i] = .{
121 .symbol = @intCast(u8, i),
121 .symbol = @as(u8, @intCast(i)),
122122 .weight = undefined,
123123 .prefix = undefined,
124124 };
......@@ -167,7 +167,7 @@ fn buildHuffmanTree(weights: *[256]u4, symbol_count: usize) error{MalformedHuffm
167167 weight_power_sum_big += (@as(u16, 1) << value) >> 1;
168168 }
169169 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
172172 // advance to next power of two (even if weight_power_sum is a power of 2)
173173 // TODO: is it valid to have weight_power_sum == 0?
......@@ -179,7 +179,7 @@ fn buildHuffmanTree(weights: *[256]u4, symbol_count: usize) error{MalformedHuffm
179179 const prefixed_symbol_count = assignSymbols(weight_sorted_prefixed_symbols[0..symbol_count], weights.*);
180180 const tree = LiteralsSection.HuffmanTree{
181181 .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)),
183183 .nodes = weight_sorted_prefixed_symbols,
184184 };
185185 return tree;
lib/std/compress/zstandard/decompress.zig+4-4
......@@ -260,7 +260,7 @@ pub fn decodeFrameArrayList(
260260/// Returns the frame checksum corresponding to the data fed into `hasher`
261261pub fn computeChecksum(hasher: *std.hash.XxHash64) u32 {
262262 const hash = hasher.final();
263 return @intCast(u32, hash & 0xFFFFFFFF);
263 return @as(u32, @intCast(hash & 0xFFFFFFFF));
264264}
265265
266266const FrameError = error{
......@@ -398,7 +398,7 @@ pub const FrameContext = struct {
398398 const window_size = if (window_size_raw > window_size_max)
399399 return error.WindowTooLarge
400400 else
401 @intCast(usize, window_size_raw);
401 @as(usize, @intCast(window_size_raw));
402402
403403 const should_compute_checksum =
404404 frame_header.descriptor.content_checksum_flag and verify_checksum;
......@@ -585,7 +585,7 @@ pub fn frameWindowSize(header: ZstandardHeader) ?u64 {
585585 const exponent = (descriptor & 0b11111000) >> 3;
586586 const mantissa = descriptor & 0b00000111;
587587 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));
589589 const window_add = (window_base / 8) * mantissa;
590590 return window_base + window_add;
591591 } else return header.content_size;
......@@ -599,7 +599,7 @@ pub fn frameWindowSize(header: ZstandardHeader) ?u64 {
599599pub fn decodeZstandardHeader(
600600 source: anytype,
601601) (@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
604604 if (descriptor.reserved) return error.ReservedBitSet;
605605
lib/std/crypto/25519/curve25519.zig+1-1
......@@ -54,7 +54,7 @@ pub const Curve25519 = struct {
5454 var swap: u8 = 0;
5555 var pos: usize = bits - 1;
5656 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;
5858 swap ^= bit;
5959 Fe.cSwap2(&x2, &x3, &z2, &z3, swap);
6060 swap = bit;
lib/std/crypto/25519/edwards25519.zig+12-12
......@@ -162,8 +162,8 @@ pub const Edwards25519 = struct {
162162 const reduced = if ((s[s.len - 1] & 0x80) == 0) s else scalar.reduce(s);
163163 var e: [2 * 32]i8 = undefined;
164164 for (reduced, 0..) |x, i| {
165 e[i * 2 + 0] = @as(i8, @truncate(u4, x));
166 e[i * 2 + 1] = @as(i8, @truncate(u4, x >> 4));
165 e[i * 2 + 0] = @as(i8, @as(u4, @truncate(x)));
166 e[i * 2 + 1] = @as(i8, @as(u4, @truncate(x >> 4)));
167167 }
168168 // Now, e[0..63] is between 0 and 15, e[63] is between 0 and 7
169169 var carry: i8 = 0;
......@@ -190,9 +190,9 @@ pub const Edwards25519 = struct {
190190 while (true) : (pos -= 1) {
191191 const slot = e[pos];
192192 if (slot > 0) {
193 q = q.add(pc[@intCast(usize, slot)]);
193 q = q.add(pc[@as(usize, @intCast(slot))]);
194194 } else if (slot < 0) {
195 q = q.sub(pc[@intCast(usize, -slot)]);
195 q = q.sub(pc[@as(usize, @intCast(-slot))]);
196196 }
197197 if (pos == 0) break;
198198 q = q.dbl().dbl().dbl().dbl();
......@@ -206,7 +206,7 @@ pub const Edwards25519 = struct {
206206 var q = Edwards25519.identityElement;
207207 var pos: usize = 252;
208208 while (true) : (pos -= 4) {
209 const slot = @truncate(u4, (s[pos >> 3] >> @truncate(u3, pos)));
209 const slot = @as(u4, @truncate((s[pos >> 3] >> @as(u3, @truncate(pos)))));
210210 if (vartime) {
211211 if (slot != 0) {
212212 q = q.add(pc[slot]);
......@@ -283,15 +283,15 @@ pub const Edwards25519 = struct {
283283 while (true) : (pos -= 1) {
284284 const slot1 = e1[pos];
285285 if (slot1 > 0) {
286 q = q.add(pc1[@intCast(usize, slot1)]);
286 q = q.add(pc1[@as(usize, @intCast(slot1))]);
287287 } else if (slot1 < 0) {
288 q = q.sub(pc1[@intCast(usize, -slot1)]);
288 q = q.sub(pc1[@as(usize, @intCast(-slot1))]);
289289 }
290290 const slot2 = e2[pos];
291291 if (slot2 > 0) {
292 q = q.add(pc2[@intCast(usize, slot2)]);
292 q = q.add(pc2[@as(usize, @intCast(slot2))]);
293293 } else if (slot2 < 0) {
294 q = q.sub(pc2[@intCast(usize, -slot2)]);
294 q = q.sub(pc2[@as(usize, @intCast(-slot2))]);
295295 }
296296 if (pos == 0) break;
297297 q = q.dbl().dbl().dbl().dbl();
......@@ -326,9 +326,9 @@ pub const Edwards25519 = struct {
326326 for (es, 0..) |e, i| {
327327 const slot = e[pos];
328328 if (slot > 0) {
329 q = q.add(pcs[i][@intCast(usize, slot)]);
329 q = q.add(pcs[i][@as(usize, @intCast(slot))]);
330330 } else if (slot < 0) {
331 q = q.sub(pcs[i][@intCast(usize, -slot)]);
331 q = q.sub(pcs[i][@as(usize, @intCast(-slot))]);
332332 }
333333 }
334334 if (pos == 0) break;
......@@ -427,7 +427,7 @@ pub const Edwards25519 = struct {
427427 }
428428 const empty_block = [_]u8{0} ** H.block_length;
429429 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))};
431431 var st = H.init(.{});
432432 st.update(empty_block[0..]);
433433 st.update(s);
lib/std/crypto/25519/field.zig+11-11
......@@ -254,11 +254,11 @@ pub const Fe = struct {
254254 var rs: [5]u64 = undefined;
255255 comptime var i = 0;
256256 inline while (i < 4) : (i += 1) {
257 rs[i] = @truncate(u64, r[i]) & MASK51;
258 r[i + 1] += @intCast(u64, r[i] >> 51);
257 rs[i] = @as(u64, @truncate(r[i])) & MASK51;
258 r[i + 1] += @as(u64, @intCast(r[i] >> 51));
259259 }
260 rs[4] = @truncate(u64, r[4]) & MASK51;
261 var carry = @intCast(u64, r[4] >> 51);
260 rs[4] = @as(u64, @truncate(r[4])) & MASK51;
261 var carry = @as(u64, @intCast(r[4] >> 51));
262262 rs[0] += 19 * carry;
263263 carry = rs[0] >> 51;
264264 rs[0] &= MASK51;
......@@ -278,8 +278,8 @@ pub const Fe = struct {
278278 var r: [5]u128 = undefined;
279279 comptime var i = 0;
280280 inline while (i < 5) : (i += 1) {
281 ax[i] = @intCast(u128, a.limbs[i]);
282 bx[i] = @intCast(u128, b.limbs[i]);
281 ax[i] = @as(u128, @intCast(a.limbs[i]));
282 bx[i] = @as(u128, @intCast(b.limbs[i]));
283283 }
284284 i = 1;
285285 inline while (i < 5) : (i += 1) {
......@@ -299,7 +299,7 @@ pub const Fe = struct {
299299 var r: [5]u128 = undefined;
300300 comptime var i = 0;
301301 inline while (i < 5) : (i += 1) {
302 ax[i] = @intCast(u128, a.limbs[i]);
302 ax[i] = @as(u128, @intCast(a.limbs[i]));
303303 }
304304 const a0_2 = 2 * ax[0];
305305 const a1_2 = 2 * ax[1];
......@@ -334,15 +334,15 @@ pub const Fe = struct {
334334
335335 /// Multiply a field element with a small (32-bit) integer
336336 pub inline fn mul32(a: Fe, comptime n: u32) Fe {
337 const sn = @intCast(u128, n);
337 const sn = @as(u128, @intCast(n));
338338 var fe: Fe = undefined;
339339 var x: u128 = 0;
340340 comptime var i = 0;
341341 inline while (i < 5) : (i += 1) {
342342 x = a.limbs[i] * sn + (x >> 51);
343 fe.limbs[i] = @truncate(u64, x) & MASK51;
343 fe.limbs[i] = @as(u64, @truncate(x)) & MASK51;
344344 }
345 fe.limbs[0] += @intCast(u64, x >> 51) * 19;
345 fe.limbs[0] += @as(u64, @intCast(x >> 51)) * 19;
346346
347347 return fe;
348348 }
......@@ -402,7 +402,7 @@ pub const Fe = struct {
402402 const t2 = t.sqn(30).mul(t);
403403 const t3 = t2.sqn(60).mul(t2);
404404 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)))));
406406 }
407407
408408 fn uncheckedSqrt(x2: Fe) Fe {
lib/std/crypto/25519/scalar.zig+37-37
......@@ -27,8 +27,8 @@ pub fn rejectNonCanonical(s: CompressedScalar) NonCanonicalError!void {
2727 while (true) : (i -= 1) {
2828 const xs = @as(u16, s[i]);
2929 const xfield_order_s = @as(u16, field_order_s[i]);
30 c |= @intCast(u8, ((xs -% xfield_order_s) >> 8) & n);
31 n &= @intCast(u8, ((xs ^ xfield_order_s) -% 1) >> 8);
30 c |= @as(u8, @intCast(((xs -% xfield_order_s) >> 8) & n));
31 n &= @as(u8, @intCast(((xs ^ xfield_order_s) -% 1) >> 8));
3232 if (i == 0) break;
3333 }
3434 if (c == 0) {
......@@ -89,7 +89,7 @@ pub fn neg(s: CompressedScalar) CompressedScalar {
8989 var i: usize = 0;
9090 while (i < 64) : (i += 1) {
9191 carry = @as(u32, fs[i]) -% sx[i] -% @as(u32, carry);
92 sx[i] = @truncate(u8, carry);
92 sx[i] = @as(u8, @truncate(carry));
9393 carry = (carry >> 8) & 1;
9494 }
9595 return reduce64(sx);
......@@ -129,7 +129,7 @@ pub const Scalar = struct {
129129 while (i < 4) : (i += 1) {
130130 mem.writeIntLittle(u64, bytes[i * 7 ..][0..8], expanded.limbs[i]);
131131 }
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])));
133133 return bytes;
134134 }
135135
......@@ -234,42 +234,42 @@ pub const Scalar = struct {
234234 const z80 = xy440;
235235
236236 const carry0 = z00 >> 56;
237 const t10 = @truncate(u64, z00) & 0xffffffffffffff;
237 const t10 = @as(u64, @truncate(z00)) & 0xffffffffffffff;
238238 const c00 = carry0;
239239 const t00 = t10;
240240 const carry1 = (z10 + c00) >> 56;
241 const t11 = @truncate(u64, (z10 + c00)) & 0xffffffffffffff;
241 const t11 = @as(u64, @truncate((z10 + c00))) & 0xffffffffffffff;
242242 const c10 = carry1;
243243 const t12 = t11;
244244 const carry2 = (z20 + c10) >> 56;
245 const t13 = @truncate(u64, (z20 + c10)) & 0xffffffffffffff;
245 const t13 = @as(u64, @truncate((z20 + c10))) & 0xffffffffffffff;
246246 const c20 = carry2;
247247 const t20 = t13;
248248 const carry3 = (z30 + c20) >> 56;
249 const t14 = @truncate(u64, (z30 + c20)) & 0xffffffffffffff;
249 const t14 = @as(u64, @truncate((z30 + c20))) & 0xffffffffffffff;
250250 const c30 = carry3;
251251 const t30 = t14;
252252 const carry4 = (z40 + c30) >> 56;
253 const t15 = @truncate(u64, (z40 + c30)) & 0xffffffffffffff;
253 const t15 = @as(u64, @truncate((z40 + c30))) & 0xffffffffffffff;
254254 const c40 = carry4;
255255 const t40 = t15;
256256 const carry5 = (z50 + c40) >> 56;
257 const t16 = @truncate(u64, (z50 + c40)) & 0xffffffffffffff;
257 const t16 = @as(u64, @truncate((z50 + c40))) & 0xffffffffffffff;
258258 const c50 = carry5;
259259 const t50 = t16;
260260 const carry6 = (z60 + c50) >> 56;
261 const t17 = @truncate(u64, (z60 + c50)) & 0xffffffffffffff;
261 const t17 = @as(u64, @truncate((z60 + c50))) & 0xffffffffffffff;
262262 const c60 = carry6;
263263 const t60 = t17;
264264 const carry7 = (z70 + c60) >> 56;
265 const t18 = @truncate(u64, (z70 + c60)) & 0xffffffffffffff;
265 const t18 = @as(u64, @truncate((z70 + c60))) & 0xffffffffffffff;
266266 const c70 = carry7;
267267 const t70 = t18;
268268 const carry8 = (z80 + c70) >> 56;
269 const t19 = @truncate(u64, (z80 + c70)) & 0xffffffffffffff;
269 const t19 = @as(u64, @truncate((z80 + c70))) & 0xffffffffffffff;
270270 const c80 = carry8;
271271 const t80 = t19;
272 const t90 = (@truncate(u64, c80));
272 const t90 = (@as(u64, @truncate(c80)));
273273 const r0 = t00;
274274 const r1 = t12;
275275 const r2 = t20;
......@@ -356,26 +356,26 @@ pub const Scalar = struct {
356356 const carry12 = (z32 + c21) >> 56;
357357 const c31 = carry12;
358358 const carry13 = (z42 + c31) >> 56;
359 const t24 = @truncate(u64, z42 + c31) & 0xffffffffffffff;
359 const t24 = @as(u64, @truncate(z42 + c31)) & 0xffffffffffffff;
360360 const c41 = carry13;
361361 const t41 = t24;
362362 const carry14 = (z5 + c41) >> 56;
363 const t25 = @truncate(u64, z5 + c41) & 0xffffffffffffff;
363 const t25 = @as(u64, @truncate(z5 + c41)) & 0xffffffffffffff;
364364 const c5 = carry14;
365365 const t5 = t25;
366366 const carry15 = (z6 + c5) >> 56;
367 const t26 = @truncate(u64, z6 + c5) & 0xffffffffffffff;
367 const t26 = @as(u64, @truncate(z6 + c5)) & 0xffffffffffffff;
368368 const c6 = carry15;
369369 const t6 = t26;
370370 const carry16 = (z7 + c6) >> 56;
371 const t27 = @truncate(u64, z7 + c6) & 0xffffffffffffff;
371 const t27 = @as(u64, @truncate(z7 + c6)) & 0xffffffffffffff;
372372 const c7 = carry16;
373373 const t7 = t27;
374374 const carry17 = (z8 + c7) >> 56;
375 const t28 = @truncate(u64, z8 + c7) & 0xffffffffffffff;
375 const t28 = @as(u64, @truncate(z8 + c7)) & 0xffffffffffffff;
376376 const c8 = carry17;
377377 const t8 = t28;
378 const t9 = @truncate(u64, c8);
378 const t9 = @as(u64, @truncate(c8));
379379
380380 const qmu4_ = t41;
381381 const qmu5_ = t5;
......@@ -425,22 +425,22 @@ pub const Scalar = struct {
425425 const xy31 = @as(u128, qdiv3) * @as(u128, m1);
426426 const xy40 = @as(u128, qdiv4) * @as(u128, m0);
427427 const carry18 = xy00 >> 56;
428 const t29 = @truncate(u64, xy00) & 0xffffffffffffff;
428 const t29 = @as(u64, @truncate(xy00)) & 0xffffffffffffff;
429429 const c0 = carry18;
430430 const t01 = t29;
431431 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;
433433 const c12 = carry19;
434434 const t110 = t31;
435435 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;
437437 const c22 = carry20;
438438 const t210 = t32;
439439 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;
441441 const c32 = carry;
442442 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
445445 const qmul0 = t01;
446446 const qmul1 = t110;
......@@ -498,7 +498,7 @@ pub const Scalar = struct {
498498 const t = ((b << 56) + s4) -% (y41 + b3);
499499 const b4 = b;
500500 const t4 = t;
501 const mask = (b4 -% @intCast(u64, ((1))));
501 const mask = (b4 -% @as(u64, @intCast(((1)))));
502502 const z04 = s0 ^ (mask & (s0 ^ t0));
503503 const z14 = s1 ^ (mask & (s1 ^ t1));
504504 const z24 = s2 ^ (mask & (s2 ^ t2));
......@@ -691,26 +691,26 @@ const ScalarDouble = struct {
691691 const carry3 = (z31 + c20) >> 56;
692692 const c30 = carry3;
693693 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;
695695 const c40 = carry4;
696696 const t410 = t103;
697697 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;
699699 const c5 = carry5;
700700 const t51 = t104;
701701 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;
703703 const c6 = carry6;
704704 const t61 = t105;
705705 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;
707707 const c7 = carry7;
708708 const t71 = t106;
709709 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;
711711 const c8 = carry8;
712712 const t81 = t107;
713 const t91 = @as(u64, @truncate(u64, c8));
713 const t91 = @as(u64, @as(u64, @truncate(c8)));
714714
715715 const qmu4_ = t410;
716716 const qmu5_ = t51;
......@@ -760,22 +760,22 @@ const ScalarDouble = struct {
760760 const xy31 = @as(u128, qdiv3) * @as(u128, m1);
761761 const xy40 = @as(u128, qdiv4) * @as(u128, m0);
762762 const carry9 = xy00 >> 56;
763 const t108 = @truncate(u64, xy00) & 0xffffffffffffff;
763 const t108 = @as(u64, @truncate(xy00)) & 0xffffffffffffff;
764764 const c0 = carry9;
765765 const t010 = t108;
766766 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;
768768 const c11 = carry10;
769769 const t110 = t109;
770770 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;
772772 const c21 = carry11;
773773 const t210 = t1010;
774774 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;
776776 const c31 = carry;
777777 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
780780 const qmul0 = t010;
781781 const qmul1 = t110;
lib/std/crypto/Certificate.zig+11-11
......@@ -312,7 +312,7 @@ pub const Parsed = struct {
312312 while (name_i < general_names.slice.end) {
313313 const general_name = try der.Element.parse(subject_alt_name, name_i);
314314 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)))) {
316316 .dNSName => {
317317 const dns_name = subject_alt_name[general_name.slice.start..general_name.slice.end];
318318 if (checkHostName(host_name, dns_name)) return;
......@@ -379,7 +379,7 @@ pub fn parse(cert: Certificate) ParseError!Parsed {
379379 const tbs_certificate = try der.Element.parse(cert_bytes, certificate.slice.start);
380380 const version_elem = try der.Element.parse(cert_bytes, tbs_certificate.slice.start);
381381 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)
383383 try der.Element.parse(cert_bytes, version_elem.slice.end)
384384 else
385385 version_elem;
......@@ -597,8 +597,8 @@ const Date = struct {
597597 var month: u4 = 1;
598598 while (month < date.month) : (month += 1) {
599599 const days: u64 = std.time.epoch.getDaysInMonth(
600 @enumFromInt(std.time.epoch.YearLeapKind, @intFromBool(is_leap)),
601 @enumFromInt(std.time.epoch.Month, month),
600 @as(std.time.epoch.YearLeapKind, @enumFromInt(@intFromBool(is_leap))),
601 @as(std.time.epoch.Month, @enumFromInt(month)),
602602 );
603603 sec += days * std.time.epoch.secs_per_day;
604604 }
......@@ -685,7 +685,7 @@ fn parseEnum(comptime E: type, bytes: []const u8, element: der.Element) ParseEnu
685685pub const ParseVersionError = error{ UnsupportedCertificateVersion, CertificateFieldHasInvalidLength };
686686
687687pub 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)
689689 return .v1;
690690
691691 if (version_elem.slice.end - version_elem.slice.start != 3)
......@@ -864,7 +864,7 @@ pub const der = struct {
864864
865865 pub fn parse(bytes: []const u8, index: u32) ParseElementError!Element {
866866 var i = index;
867 const identifier = @bitCast(Identifier, bytes[i]);
867 const identifier = @as(Identifier, @bitCast(bytes[i]));
868868 i += 1;
869869 const size_byte = bytes[i];
870870 i += 1;
......@@ -878,7 +878,7 @@ pub const der = struct {
878878 };
879879 }
880880
881 const len_size = @truncate(u7, size_byte);
881 const len_size = @as(u7, @truncate(size_byte));
882882 if (len_size > @sizeOf(u32)) {
883883 return error.CertificateFieldHasInvalidLength;
884884 }
......@@ -1042,10 +1042,10 @@ pub const rsa = struct {
10421042 var hashed: [Hash.digest_length]u8 = undefined;
10431043
10441044 while (idx < len) {
1045 c[0] = @intCast(u8, (counter >> 24) & 0xFF);
1046 c[1] = @intCast(u8, (counter >> 16) & 0xFF);
1047 c[2] = @intCast(u8, (counter >> 8) & 0xFF);
1048 c[3] = @intCast(u8, counter & 0xFF);
1045 c[0] = @as(u8, @intCast((counter >> 24) & 0xFF));
1046 c[1] = @as(u8, @intCast((counter >> 16) & 0xFF));
1047 c[2] = @as(u8, @intCast((counter >> 8) & 0xFF));
1048 c[3] = @as(u8, @intCast(counter & 0xFF));
10491049
10501050 std.mem.copyForwards(u8, hash[seed.len..], &c);
10511051 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 {
131131
132132 var ctx = w.crypt32.CertEnumCertificatesInStore(store, null);
133133 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));
135135 const encoded_cert = context.pbCertEncoded[0..context.cbCertEncoded];
136136 try cb.bytes.appendSlice(gpa, encoded_cert);
137137 try cb.parseCert(gpa, decoded_start, now_sec);
......@@ -213,7 +213,7 @@ pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file: fs.File) AddCertsFrom
213213 const needed_capacity = std.math.cast(u32, decoded_size_upper_bound + size) orelse
214214 return error.CertificateAuthorityBundleTooBig;
215215 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));
217217 const buffer = cb.bytes.allocatedSlice()[end_reserved..];
218218 const end_index = try file.readAll(buffer);
219219 const encoded_bytes = buffer[0..end_index];
......@@ -230,7 +230,7 @@ pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file: fs.File) AddCertsFrom
230230 return error.MissingEndCertificateMarker;
231231 start_index = cert_end + end_marker.len;
232232 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));
234234 const dest_buf = cb.bytes.allocatedSlice()[decoded_start..];
235235 cb.bytes.items.len += try base64.decode(dest_buf, encoded_cert);
236236 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 {
2121 const reader = stream.reader();
2222
2323 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
2626 try stream.seekTo(db_header.schema_offset);
2727
......@@ -42,7 +42,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
4242
4343 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) {
4646 continue;
4747 }
4848
......@@ -61,7 +61,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
6161
6262 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));
6565 const dest_buf = cb.bytes.allocatedSlice()[cert_start..];
6666 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" {
625625 const key = [_]u8{0x00} ** Aegis128LMac.key_length;
626626 var msg: [64]u8 = undefined;
627627 for (&msg, 0..) |*m, i| {
628 m.* = @truncate(u8, i);
628 m.* = @as(u8, @truncate(i));
629629 }
630630 const st_init = Aegis128LMac.init(&key);
631631 var st = st_init;
lib/std/crypto/aes/soft.zig+51-51
......@@ -51,13 +51,13 @@ pub const Block = struct {
5151 const s3 = block.repr[3];
5252
5353 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)));
5555 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)));
5757 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)));
5959 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)));
6161 var t3 = x[0] ^ x[1] ^ x[2] ^ x[3];
6262
6363 t0 ^= round_key.repr[0];
......@@ -77,31 +77,31 @@ pub const Block = struct {
7777
7878 var x: [4]u32 = undefined;
7979 x = .{
80 table_encrypt[0][@truncate(u8, s0)],
81 table_encrypt[1][@truncate(u8, s1 >> 8)],
82 table_encrypt[2][@truncate(u8, s2 >> 16)],
83 table_encrypt[3][@truncate(u8, s3 >> 24)],
80 table_encrypt[0][@as(u8, @truncate(s0))],
81 table_encrypt[1][@as(u8, @truncate(s1 >> 8))],
82 table_encrypt[2][@as(u8, @truncate(s2 >> 16))],
83 table_encrypt[3][@as(u8, @truncate(s3 >> 24))],
8484 };
8585 var t0 = x[0] ^ x[1] ^ x[2] ^ x[3];
8686 x = .{
87 table_encrypt[0][@truncate(u8, s1)],
88 table_encrypt[1][@truncate(u8, s2 >> 8)],
89 table_encrypt[2][@truncate(u8, s3 >> 16)],
90 table_encrypt[3][@truncate(u8, s0 >> 24)],
87 table_encrypt[0][@as(u8, @truncate(s1))],
88 table_encrypt[1][@as(u8, @truncate(s2 >> 8))],
89 table_encrypt[2][@as(u8, @truncate(s3 >> 16))],
90 table_encrypt[3][@as(u8, @truncate(s0 >> 24))],
9191 };
9292 var t1 = x[0] ^ x[1] ^ x[2] ^ x[3];
9393 x = .{
94 table_encrypt[0][@truncate(u8, s2)],
95 table_encrypt[1][@truncate(u8, s3 >> 8)],
96 table_encrypt[2][@truncate(u8, s0 >> 16)],
97 table_encrypt[3][@truncate(u8, s1 >> 24)],
94 table_encrypt[0][@as(u8, @truncate(s2))],
95 table_encrypt[1][@as(u8, @truncate(s3 >> 8))],
96 table_encrypt[2][@as(u8, @truncate(s0 >> 16))],
97 table_encrypt[3][@as(u8, @truncate(s1 >> 24))],
9898 };
9999 var t2 = x[0] ^ x[1] ^ x[2] ^ x[3];
100100 x = .{
101 table_encrypt[0][@truncate(u8, s3)],
102 table_encrypt[1][@truncate(u8, s0 >> 8)],
103 table_encrypt[2][@truncate(u8, s1 >> 16)],
104 table_encrypt[3][@truncate(u8, s2 >> 24)],
101 table_encrypt[0][@as(u8, @truncate(s3))],
102 table_encrypt[1][@as(u8, @truncate(s0 >> 8))],
103 table_encrypt[2][@as(u8, @truncate(s1 >> 16))],
104 table_encrypt[3][@as(u8, @truncate(s2 >> 24))],
105105 };
106106 var t3 = x[0] ^ x[1] ^ x[2] ^ x[3];
107107
......@@ -122,13 +122,13 @@ pub const Block = struct {
122122
123123 // Last round uses s-box directly and XORs to produce output.
124124 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)));
126126 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)));
128128 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)));
130130 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)));
132132 var t3 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);
133133
134134 t0 ^= round_key.repr[0];
......@@ -147,13 +147,13 @@ pub const Block = struct {
147147 const s3 = block.repr[3];
148148
149149 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)));
151151 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)));
153153 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)));
155155 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)));
157157 var t3 = x[0] ^ x[1] ^ x[2] ^ x[3];
158158
159159 t0 ^= round_key.repr[0];
......@@ -173,31 +173,31 @@ pub const Block = struct {
173173
174174 var x: [4]u32 = undefined;
175175 x = .{
176 table_decrypt[0][@truncate(u8, s0)],
177 table_decrypt[1][@truncate(u8, s3 >> 8)],
178 table_decrypt[2][@truncate(u8, s2 >> 16)],
179 table_decrypt[3][@truncate(u8, s1 >> 24)],
176 table_decrypt[0][@as(u8, @truncate(s0))],
177 table_decrypt[1][@as(u8, @truncate(s3 >> 8))],
178 table_decrypt[2][@as(u8, @truncate(s2 >> 16))],
179 table_decrypt[3][@as(u8, @truncate(s1 >> 24))],
180180 };
181181 var t0 = x[0] ^ x[1] ^ x[2] ^ x[3];
182182 x = .{
183 table_decrypt[0][@truncate(u8, s1)],
184 table_decrypt[1][@truncate(u8, s0 >> 8)],
185 table_decrypt[2][@truncate(u8, s3 >> 16)],
186 table_decrypt[3][@truncate(u8, s2 >> 24)],
183 table_decrypt[0][@as(u8, @truncate(s1))],
184 table_decrypt[1][@as(u8, @truncate(s0 >> 8))],
185 table_decrypt[2][@as(u8, @truncate(s3 >> 16))],
186 table_decrypt[3][@as(u8, @truncate(s2 >> 24))],
187187 };
188188 var t1 = x[0] ^ x[1] ^ x[2] ^ x[3];
189189 x = .{
190 table_decrypt[0][@truncate(u8, s2)],
191 table_decrypt[1][@truncate(u8, s1 >> 8)],
192 table_decrypt[2][@truncate(u8, s0 >> 16)],
193 table_decrypt[3][@truncate(u8, s3 >> 24)],
190 table_decrypt[0][@as(u8, @truncate(s2))],
191 table_decrypt[1][@as(u8, @truncate(s1 >> 8))],
192 table_decrypt[2][@as(u8, @truncate(s0 >> 16))],
193 table_decrypt[3][@as(u8, @truncate(s3 >> 24))],
194194 };
195195 var t2 = x[0] ^ x[1] ^ x[2] ^ x[3];
196196 x = .{
197 table_decrypt[0][@truncate(u8, s3)],
198 table_decrypt[1][@truncate(u8, s2 >> 8)],
199 table_decrypt[2][@truncate(u8, s1 >> 16)],
200 table_decrypt[3][@truncate(u8, s0 >> 24)],
197 table_decrypt[0][@as(u8, @truncate(s3))],
198 table_decrypt[1][@as(u8, @truncate(s2 >> 8))],
199 table_decrypt[2][@as(u8, @truncate(s1 >> 16))],
200 table_decrypt[3][@as(u8, @truncate(s0 >> 24))],
201201 };
202202 var t3 = x[0] ^ x[1] ^ x[2] ^ x[3];
203203
......@@ -218,13 +218,13 @@ pub const Block = struct {
218218
219219 // Last round uses s-box directly and XORs to produce output.
220220 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)));
222222 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)));
224224 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)));
226226 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)));
228228 var t3 = @as(u32, x[0]) << 24 | @as(u32, x[1]) << 16 | @as(u32, x[2]) << 8 | @as(u32, x[3]);
229229
230230 t0 ^= round_key.repr[0];
......@@ -348,7 +348,7 @@ fn KeySchedule(comptime Aes: type) type {
348348 const subw = struct {
349349 // Apply sbox_encrypt to each byte in w.
350350 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)));
352352 return @as(u32, x[3]) << 24 | @as(u32, x[2]) << 16 | @as(u32, x[1]) << 8 | @as(u32, x[0]);
353353 }
354354 }.func;
......@@ -386,7 +386,7 @@ fn KeySchedule(comptime Aes: type) type {
386386 inline while (j < 4) : (j += 1) {
387387 var rk = round_keys[(ei + j) / 4].repr[(ei + j) % 4];
388388 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)));
390390 const y = table_lookup(&table_decrypt, x[3], x[2], x[1], x[0]);
391391 rk = y[0] ^ y[1] ^ y[2] ^ y[3];
392392 }
......@@ -664,7 +664,7 @@ fn mul(a: u8, b: u8) u8 {
664664 }
665665 }
666666
667 return @truncate(u8, s);
667 return @as(u8, @truncate(s));
668668}
669669
670670const cache_line_bytes = 64;
lib/std/crypto/aes_ocb.zig+4-4
......@@ -86,18 +86,18 @@ fn AesOcb(comptime Aes: anytype) type {
8686
8787 fn getOffset(aes_enc_ctx: EncryptCtx, npub: [nonce_length]u8) Block {
8888 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));
9090 nx[16 - nonce_length - 1] = 1;
9191 nx[nx.len - nonce_length ..].* = npub;
9292
93 const bottom = @truncate(u6, nx[15]);
93 const bottom = @as(u6, @truncate(nx[15]));
9494 nx[15] &= 0xc0;
9595 var ktop_: Block = undefined;
9696 aes_enc_ctx.encrypt(&ktop_, &nx);
9797 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)));
9999 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)))));
101101 return offset;
102102 }
103103
lib/std/crypto/argon2.zig+11-11
......@@ -95,7 +95,7 @@ pub const Params = struct {
9595 pub fn fromLimits(ops_limit: u32, mem_limit: usize) Self {
9696 const m = mem_limit / 1024;
9797 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 };
9999 }
100100};
101101
......@@ -111,26 +111,26 @@ fn initHash(
111111 var tmp: [4]u8 = undefined;
112112 var b2 = Blake2b512.init(.{});
113113 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)));
115115 mem.writeIntLittle(u32, parameters[8..12], params.m);
116116 mem.writeIntLittle(u32, parameters[12..16], params.t);
117117 mem.writeIntLittle(u32, parameters[16..20], version);
118118 mem.writeIntLittle(u32, parameters[20..24], @intFromEnum(mode));
119119 b2.update(&parameters);
120 mem.writeIntLittle(u32, &tmp, @intCast(u32, password.len));
120 mem.writeIntLittle(u32, &tmp, @as(u32, @intCast(password.len)));
121121 b2.update(&tmp);
122122 b2.update(password);
123 mem.writeIntLittle(u32, &tmp, @intCast(u32, salt.len));
123 mem.writeIntLittle(u32, &tmp, @as(u32, @intCast(salt.len)));
124124 b2.update(&tmp);
125125 b2.update(salt);
126126 const secret = params.secret orelse "";
127127 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)));
129129 b2.update(&tmp);
130130 b2.update(secret);
131131 const ad = params.ad orelse "";
132132 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)));
134134 b2.update(&tmp);
135135 b2.update(ad);
136136 b2.final(h0[0..Blake2b512.digest_length]);
......@@ -140,7 +140,7 @@ fn initHash(
140140fn blake2bLong(out: []u8, in: []const u8) void {
141141 const H = Blake2b512;
142142 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
145145 var out_buf: [H.digest_length]u8 = undefined;
146146
......@@ -391,7 +391,7 @@ fn Rp(a: usize, b: usize, c: usize, d: usize) QuarterRound {
391391}
392392
393393fn 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)));
395395 return x +% y +% 2 *% xy;
396396}
397397
......@@ -448,7 +448,7 @@ fn indexAlpha(
448448 lane: u24,
449449 index: u32,
450450) u32 {
451 var ref_lane = @intCast(u32, rand >> 32) % threads;
451 var ref_lane = @as(u32, @intCast(rand >> 32)) % threads;
452452 if (n == 0 and slice == 0) {
453453 ref_lane = lane;
454454 }
......@@ -467,10 +467,10 @@ fn indexAlpha(
467467 if (index == 0 or lane == ref_lane) {
468468 m -= 1;
469469 }
470 var p = @as(u64, @truncate(u32, rand));
470 var p = @as(u64, @as(u32, @truncate(rand)));
471471 p = (p * p) >> 32;
472472 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)));
474474}
475475
476476/// 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 {
9595 /// XOR a byte into the state at a given offset.
9696 pub fn addByte(self: *Self, byte: u8, offset: usize) void {
9797 const z = switch (endian) {
98 .Big => 64 - 8 - 8 * @truncate(u6, offset % 8),
99 .Little => 8 * @truncate(u6, offset % 8),
98 .Big => 64 - 8 - 8 * @as(u6, @truncate(offset % 8)),
99 .Little => 8 * @as(u6, @truncate(offset % 8)),
100100 };
101101 self.st[offset / 8] ^= @as(u64, byte) << z;
102102 }
lib/std/crypto/bcrypt.zig+4-4
......@@ -376,10 +376,10 @@ pub const State = struct {
376376 const Halves = struct { l: u32, r: u32 };
377377
378378 fn halfRound(state: *const State, i: u32, j: u32, n: usize) u32 {
379 var r = state.sboxes[0][@truncate(u8, j >> 24)];
380 r +%= state.sboxes[1][@truncate(u8, j >> 16)];
381 r ^= state.sboxes[2][@truncate(u8, j >> 8)];
382 r +%= state.sboxes[3][@truncate(u8, j)];
379 var r = state.sboxes[0][@as(u8, @truncate(j >> 24))];
380 r +%= state.sboxes[1][@as(u8, @truncate(j >> 16))];
381 r ^= state.sboxes[2][@as(u8, @truncate(j >> 8))];
382 r +%= state.sboxes[3][@as(u8, @truncate(j))];
383383 return i ^ r ^ state.subkeys[n];
384384 }
385385
lib/std/crypto/benchmark.zig+26-26
......@@ -54,8 +54,8 @@ pub fn benchmarkHash(comptime Hash: anytype, comptime bytes: comptime_int) !u64
5454
5555 const end = timer.read();
5656
57 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;
58 const throughput = @intFromFloat(u64, bytes / elapsed_s);
57 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
58 const throughput = @as(u64, @intFromFloat(bytes / elapsed_s));
5959
6060 return throughput;
6161}
......@@ -95,8 +95,8 @@ pub fn benchmarkMac(comptime Mac: anytype, comptime bytes: comptime_int) !u64 {
9595 }
9696 const end = timer.read();
9797
98 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;
99 const throughput = @intFromFloat(u64, bytes / elapsed_s);
98 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
99 const throughput = @as(u64, @intFromFloat(bytes / elapsed_s));
100100
101101 return throughput;
102102}
......@@ -125,8 +125,8 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c
125125 }
126126 const end = timer.read();
127127
128 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;
129 const throughput = @intFromFloat(u64, exchange_count / elapsed_s);
128 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
129 const throughput = @as(u64, @intFromFloat(exchange_count / elapsed_s));
130130
131131 return throughput;
132132}
......@@ -148,8 +148,8 @@ pub fn benchmarkSignature(comptime Signature: anytype, comptime signatures_count
148148 }
149149 const end = timer.read();
150150
151 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;
152 const throughput = @intFromFloat(u64, signatures_count / elapsed_s);
151 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
152 const throughput = @as(u64, @intFromFloat(signatures_count / elapsed_s));
153153
154154 return throughput;
155155}
......@@ -172,8 +172,8 @@ pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime sign
172172 }
173173 const end = timer.read();
174174
175 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;
176 const throughput = @intFromFloat(u64, signatures_count / elapsed_s);
175 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
176 const throughput = @as(u64, @intFromFloat(signatures_count / elapsed_s));
177177
178178 return throughput;
179179}
......@@ -201,8 +201,8 @@ pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime
201201 }
202202 const end = timer.read();
203203
204 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;
205 const throughput = batch.len * @intFromFloat(u64, signatures_count / elapsed_s);
204 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
205 const throughput = batch.len * @as(u64, @intFromFloat(signatures_count / elapsed_s));
206206
207207 return throughput;
208208}
......@@ -227,8 +227,8 @@ pub fn benchmarkKem(comptime Kem: anytype, comptime kems_count: comptime_int) !u
227227 }
228228 const end = timer.read();
229229
230 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;
231 const throughput = @intFromFloat(u64, kems_count / elapsed_s);
230 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
231 const throughput = @as(u64, @intFromFloat(kems_count / elapsed_s));
232232
233233 return throughput;
234234}
......@@ -249,8 +249,8 @@ pub fn benchmarkKemDecaps(comptime Kem: anytype, comptime kems_count: comptime_i
249249 }
250250 const end = timer.read();
251251
252 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;
253 const throughput = @intFromFloat(u64, kems_count / elapsed_s);
252 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
253 const throughput = @as(u64, @intFromFloat(kems_count / elapsed_s));
254254
255255 return throughput;
256256}
......@@ -267,8 +267,8 @@ pub fn benchmarkKemKeyGen(comptime Kem: anytype, comptime kems_count: comptime_i
267267 }
268268 const end = timer.read();
269269
270 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;
271 const throughput = @intFromFloat(u64, kems_count / elapsed_s);
270 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
271 const throughput = @as(u64, @intFromFloat(kems_count / elapsed_s));
272272
273273 return throughput;
274274}
......@@ -309,8 +309,8 @@ pub fn benchmarkAead(comptime Aead: anytype, comptime bytes: comptime_int) !u64
309309 mem.doNotOptimizeAway(&in);
310310 const end = timer.read();
311311
312 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;
313 const throughput = @intFromFloat(u64, 2 * bytes / elapsed_s);
312 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
313 const throughput = @as(u64, @intFromFloat(2 * bytes / elapsed_s));
314314
315315 return throughput;
316316}
......@@ -338,8 +338,8 @@ pub fn benchmarkAes(comptime Aes: anytype, comptime count: comptime_int) !u64 {
338338 mem.doNotOptimizeAway(&in);
339339 const end = timer.read();
340340
341 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;
342 const throughput = @intFromFloat(u64, count / elapsed_s);
341 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
342 const throughput = @as(u64, @intFromFloat(count / elapsed_s));
343343
344344 return throughput;
345345}
......@@ -367,8 +367,8 @@ pub fn benchmarkAes8(comptime Aes: anytype, comptime count: comptime_int) !u64 {
367367 mem.doNotOptimizeAway(&in);
368368 const end = timer.read();
369369
370 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;
371 const throughput = @intFromFloat(u64, 8 * count / elapsed_s);
370 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
371 const throughput = @as(u64, @intFromFloat(8 * count / elapsed_s));
372372
373373 return throughput;
374374}
......@@ -406,7 +406,7 @@ fn benchmarkPwhash(
406406 const password = "testpass" ** 2;
407407 const opts = .{
408408 .allocator = allocator,
409 .params = @ptrCast(*const ty.Params, @alignCast(std.meta.alignment(ty.Params), params)).*,
409 .params = @as(*const ty.Params, @ptrCast(@alignCast(params))).*,
410410 .encoding = .phc,
411411 };
412412 var buf: [256]u8 = undefined;
......@@ -422,7 +422,7 @@ fn benchmarkPwhash(
422422 }
423423 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;
426426 const throughput = elapsed_s / count;
427427
428428 return throughput;
lib/std/crypto/blake2.zig+9-9
......@@ -80,7 +80,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
8080
8181 const key_len = if (options.key) |key| key.len else 0;
8282 // 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));
8484 d.t = 0;
8585 d.buf_len = 0;
8686
......@@ -127,7 +127,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
127127 // Copy any remainder for next pass.
128128 const b_slice = b[off..];
129129 @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));
131131 }
132132
133133 pub fn final(d: *Self, out: *[digest_length]u8) void {
......@@ -135,7 +135,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
135135 d.t += d.buf_len;
136136 d.round(d.buf[0..], true);
137137 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)).*;
139139 }
140140
141141 fn round(d: *Self, b: *const [64]u8, last: bool) void {
......@@ -152,8 +152,8 @@ pub fn Blake2s(comptime out_bits: usize) type {
152152 v[k + 8] = iv[k];
153153 }
154154
155 v[12] ^= @truncate(u32, d.t);
156 v[13] ^= @intCast(u32, d.t >> 32);
155 v[12] ^= @as(u32, @truncate(d.t));
156 v[13] ^= @as(u32, @intCast(d.t >> 32));
157157 if (last) v[14] = ~v[14];
158158
159159 const rounds = comptime [_]RoundParam{
......@@ -563,7 +563,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
563563 // Copy any remainder for next pass.
564564 const b_slice = b[off..];
565565 @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));
567567 }
568568
569569 pub fn final(d: *Self, out: *[digest_length]u8) void {
......@@ -571,7 +571,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
571571 d.t += d.buf_len;
572572 d.round(d.buf[0..], true);
573573 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)).*;
575575 }
576576
577577 fn round(d: *Self, b: *const [128]u8, last: bool) void {
......@@ -588,8 +588,8 @@ pub fn Blake2b(comptime out_bits: usize) type {
588588 v[k + 8] = iv[k];
589589 }
590590
591 v[12] ^= @truncate(u64, d.t);
592 v[13] ^= @intCast(u64, d.t >> 64);
591 v[12] ^= @as(u64, @truncate(d.t));
592 v[13] ^= @as(u64, @intCast(d.t >> 64));
593593 if (last) v[14] = ~v[14];
594594
595595 const rounds = comptime [_]RoundParam{
lib/std/crypto/blake3.zig+7-7
......@@ -89,7 +89,7 @@ const CompressVectorized = struct {
8989 counter: u64,
9090 flags: u8,
9191 ) [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) };
9393 var rows = Rows{ chaining_value[0..4].*, chaining_value[4..8].*, IV[0..4].*, md };
9494
9595 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 {
134134 rows[2] ^= @Vector(4, u32){ chaining_value[0], chaining_value[1], chaining_value[2], chaining_value[3] };
135135 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));
138138 }
139139};
140140
......@@ -184,8 +184,8 @@ const CompressGeneric = struct {
184184 IV[1],
185185 IV[2],
186186 IV[3],
187 @truncate(u32, counter),
188 @truncate(u32, counter >> 32),
187 @as(u32, @truncate(counter)),
188 @as(u32, @truncate(counter >> 32)),
189189 block_len,
190190 flags,
191191 };
......@@ -206,7 +206,7 @@ else
206206 CompressGeneric.compress;
207207
208208fn first8Words(words: [16]u32) [8]u32 {
209 return @ptrCast(*const [8]u32, &words).*;
209 return @as(*const [8]u32, @ptrCast(&words)).*;
210210}
211211
212212fn wordsFromLittleEndianBytes(comptime count: usize, bytes: [count * 4]u8) [count]u32 {
......@@ -285,7 +285,7 @@ const ChunkState = struct {
285285 const want = BLOCK_LEN - self.block_len;
286286 const take = @min(want, input.len);
287287 @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));
289289 return input[take..];
290290 }
291291
......@@ -658,7 +658,7 @@ fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) !void {
658658
659659 // Setup input pattern
660660 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
663663 // Write repeating input pattern to hasher
664664 var input_counter = input_len;
lib/std/crypto/chacha20.zig+4-4
......@@ -587,8 +587,8 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type {
587587
588588 const k = keyToWords(key);
589589 var c: [4]u32 = undefined;
590 c[0] = @truncate(u32, counter);
591 c[1] = @truncate(u32, counter >> 32);
590 c[0] = @as(u32, @truncate(counter));
591 c[1] = @as(u32, @truncate(counter >> 32));
592592 c[2] = mem.readIntLittle(u32, nonce[0..4]);
593593 c[3] = mem.readIntLittle(u32, nonce[4..8]);
594594 ChaChaImpl(rounds_nb).chacha20Xor(out, in, k, c, true);
......@@ -600,8 +600,8 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type {
600600
601601 const k = keyToWords(key);
602602 var c: [4]u32 = undefined;
603 c[0] = @truncate(u32, counter);
604 c[1] = @truncate(u32, counter >> 32);
603 c[0] = @as(u32, @truncate(counter));
604 c[1] = @as(u32, @truncate(counter >> 32));
605605 c[2] = mem.readIntLittle(u32, nonce[0..4]);
606606 c[3] = mem.readIntLittle(u32, nonce[4..8]);
607607 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 {
122122 pub fn toDer(self: Signature, buf: *[der_encoded_max_length]u8) []u8 {
123123 var fb = io.fixedBufferStream(buf);
124124 const w = fb.writer();
125 const r_len = @intCast(u8, self.r.len + (self.r[0] >> 7));
126 const s_len = @intCast(u8, self.s.len + (self.s[0] >> 7));
127 const seq_len = @intCast(u8, 2 + r_len + 2 + s_len);
125 const r_len = @as(u8, @intCast(self.r.len + (self.r[0] >> 7)));
126 const s_len = @as(u8, @intCast(self.s.len + (self.s[0] >> 7)));
127 const seq_len = @as(u8, @intCast(2 + r_len + 2 + s_len));
128128 w.writeAll(&[_]u8{ 0x30, seq_len }) catch unreachable;
129129 w.writeAll(&[_]u8{ 0x02, r_len }) catch unreachable;
130130 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 {
100100 var x = x_;
101101 var out = Self.zero;
102102 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;
104104 out.limbs.set(i, t);
105105 x = math.shr(T, x, t_bits);
106106 }
......@@ -143,9 +143,9 @@ pub fn Uint(comptime max_bits: comptime_int) type {
143143 var remaining_bits = t_bits;
144144 var limb = self.limbs.get(i);
145145 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);
147147 const consumed = 8 - shift;
148 limb >>= @truncate(u4, consumed);
148 limb >>= @as(u4, @truncate(consumed));
149149 remaining_bits -= consumed;
150150 shift = 0;
151151 switch (endian) {
......@@ -169,7 +169,7 @@ pub fn Uint(comptime max_bits: comptime_int) type {
169169 },
170170 }
171171 }
172 bytes[out_i] |= @truncate(u8, limb);
172 bytes[out_i] |= @as(u8, @truncate(limb));
173173 shift = remaining_bits;
174174 }
175175 }
......@@ -190,7 +190,7 @@ pub fn Uint(comptime max_bits: comptime_int) type {
190190 shift += 8;
191191 if (shift >= t_bits) {
192192 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))));
194194 const overflow = math.shr(Limb, bi, 8 - shift);
195195 out_i += 1;
196196 if (out_i >= out.limbs.len) {
......@@ -242,7 +242,7 @@ pub fn Uint(comptime max_bits: comptime_int) type {
242242
243243 /// Returns `true` if the integer is odd.
244244 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)))));
246246 }
247247
248248 /// Adds `y` to `x`, and returns `true` if the operation overflowed.
......@@ -273,8 +273,8 @@ pub fn Uint(comptime max_bits: comptime_int) type {
273273 var carry: u1 = 0;
274274 for (0..x.limbs_count()) |i| {
275275 const res = x_limbs[i] + y_limbs[i] + carry;
276 x_limbs[i] = ct.select(on, @truncate(TLimb, res), x_limbs[i]);
277 carry = @truncate(u1, res >> t_bits);
276 x_limbs[i] = ct.select(on, @as(TLimb, @truncate(res)), x_limbs[i]);
277 carry = @as(u1, @truncate(res >> t_bits));
278278 }
279279 return carry;
280280 }
......@@ -288,8 +288,8 @@ pub fn Uint(comptime max_bits: comptime_int) type {
288288 var borrow: u1 = 0;
289289 for (0..x.limbs_count()) |i| {
290290 const res = x_limbs[i] -% y_limbs[i] -% borrow;
291 x_limbs[i] = ct.select(on, @truncate(TLimb, res), x_limbs[i]);
292 borrow = @truncate(u1, res >> t_bits);
291 x_limbs[i] = ct.select(on, @as(TLimb, @truncate(res)), x_limbs[i]);
292 borrow = @as(u1, @truncate(res >> t_bits));
293293 }
294294 return borrow;
295295 }
......@@ -432,7 +432,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
432432 inline for (0..comptime math.log2_int(usize, t_bits)) |_| {
433433 y = y *% (2 -% lo *% y);
434434 }
435 const m0inv = (@as(Limb, 1) << t_bits) - (@truncate(TLimb, y));
435 const m0inv = (@as(Limb, 1) << t_bits) - (@as(TLimb, @truncate(y)));
436436
437437 const zero = Fe{ .v = FeUint.zero };
438438
......@@ -508,18 +508,18 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
508508 var need_sub = false;
509509 var i: usize = t_bits - 1;
510510 while (true) : (i -= 1) {
511 var carry = @truncate(u1, math.shr(Limb, y, i));
511 var carry = @as(u1, @truncate(math.shr(Limb, y, i)));
512512 var borrow: u1 = 0;
513513 for (0..self.limbs_count()) |j| {
514514 const l = ct.select(need_sub, d_limbs[j], x_limbs[j]);
515515 var res = (l << 1) + carry;
516 x_limbs[j] = @truncate(TLimb, res);
517 carry = @truncate(u1, res >> t_bits);
516 x_limbs[j] = @as(TLimb, @truncate(res));
517 carry = @as(u1, @truncate(res >> t_bits));
518518
519519 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));
523523 }
524524 need_sub = ct.eql(carry, borrow);
525525 if (i == 0) break;
......@@ -531,7 +531,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
531531 pub fn add(self: Self, x: Fe, y: Fe) Fe {
532532 var out = x;
533533 const overflow = out.v.addWithOverflow(y.v);
534 const underflow = @bitCast(u1, ct.limbsCmpLt(out.v, self.v));
534 const underflow = @as(u1, @bitCast(ct.limbsCmpLt(out.v, self.v)));
535535 const need_sub = ct.eql(overflow, underflow);
536536 _ = out.v.conditionalSubWithOverflow(need_sub, self.v);
537537 return out;
......@@ -540,7 +540,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
540540 /// Subtracts two field elements (mod m).
541541 pub fn sub(self: Self, x: Fe, y: Fe) Fe {
542542 var out = x;
543 const underflow = @bitCast(bool, out.v.subWithOverflow(y.v));
543 const underflow = @as(bool, @bitCast(out.v.subWithOverflow(y.v)));
544544 _ = out.v.conditionalAddWithOverflow(underflow, self.v);
545545 return out;
546546 }
......@@ -601,7 +601,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
601601
602602 var wide = ct.mulWide(a_limbs[i], b_limbs[0]);
603603 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));
605605 var z_hi = wide.hi +% z_lo[1];
606606 wide = ct.mulWide(f, m_limbs[0]);
607607 z_lo = @addWithOverflow(z_lo[0], wide.lo);
......@@ -620,13 +620,13 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
620620 z_lo = @addWithOverflow(z_lo[0], carry);
621621 z_hi +%= z_lo[1];
622622 if (j > 0) {
623 d_limbs[j - 1] = @truncate(TLimb, z_lo[0]);
623 d_limbs[j - 1] = @as(TLimb, @truncate(z_lo[0]));
624624 }
625625 carry = (z_hi << 1) | (z_lo[0] >> t_bits);
626626 }
627627 const z = overflow + carry;
628 d_limbs[self.limbs_count() - 1] = @truncate(TLimb, z);
629 overflow = @truncate(u1, z >> t_bits);
628 d_limbs[self.limbs_count() - 1] = @as(TLimb, @truncate(z));
629 overflow = @as(u1, @truncate(z >> t_bits));
630630 }
631631 return overflow;
632632 }
......@@ -735,7 +735,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
735735 t0 = pc[k - 1];
736736 } else {
737737 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);
739739 }
740740 }
741741 const t1 = self.montgomeryMul(out, t0);
......@@ -771,7 +771,7 @@ const ct_protected = struct {
771771 fn eql(x: anytype, y: @TypeOf(x)) bool {
772772 const c1 = @subWithOverflow(x, y)[1];
773773 const c2 = @subWithOverflow(y, x)[1];
774 return @bitCast(bool, 1 - (c1 | c2));
774 return @as(bool, @bitCast(1 - (c1 | c2)));
775775 }
776776
777777 // Compares two big integers in constant time, returning true if x < y.
......@@ -782,28 +782,28 @@ const ct_protected = struct {
782782
783783 var c: u1 = 0;
784784 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));
786786 }
787 return @bitCast(bool, c);
787 return @as(bool, @bitCast(c));
788788 }
789789
790790 // Compares two big integers in constant time, returning true if x >= y.
791791 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))));
793793 }
794794
795795 // Multiplies two limbs and returns the result as a wide limb.
796796 fn mulWide(x: Limb, y: Limb) WideLimb {
797797 const half_bits = @typeInfo(Limb).Int.bits / 2;
798798 const Half = meta.Int(.unsigned, half_bits);
799 const x0 = @truncate(Half, x);
800 const x1 = @truncate(Half, x >> half_bits);
801 const y0 = @truncate(Half, y);
802 const y1 = @truncate(Half, y >> half_bits);
799 const x0 = @as(Half, @truncate(x));
800 const x1 = @as(Half, @truncate(x >> half_bits));
801 const y0 = @as(Half, @truncate(y));
802 const y1 = @as(Half, @truncate(y >> half_bits));
803803 const w0 = math.mulWide(Half, x0, y0);
804804 const t = math.mulWide(Half, x1, y0) + (w0 >> half_bits);
805 var w1: Limb = @truncate(Half, t);
806 const w2 = @truncate(Half, t >> half_bits);
805 var w1: Limb = @as(Half, @truncate(t));
806 const w2 = @as(Half, @truncate(t >> half_bits));
807807 w1 += math.mulWide(Half, x0, y1);
808808 const hi = math.mulWide(Half, x1, y1) + w2 + (w1 >> half_bits);
809809 const lo = x *% y;
......@@ -847,8 +847,8 @@ const ct_unprotected = struct {
847847 fn mulWide(x: Limb, y: Limb) WideLimb {
848848 const wide = math.mulWide(Limb, x, y);
849849 return .{
850 .hi = @truncate(Limb, wide >> @typeInfo(Limb).Int.bits),
851 .lo = @truncate(Limb, wide),
850 .hi = @as(Limb, @truncate(wide >> @typeInfo(Limb).Int.bits)),
851 .lo = @as(Limb, @truncate(wide)),
852852 };
853853 }
854854};
lib/std/crypto/ghash_polyval.zig+31-31
......@@ -96,28 +96,28 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
9696 const product = asm (
9797 \\ vpclmulqdq $0x11, %[x], %[y], %[out]
9898 : [out] "=x" (-> @Vector(2, u64)),
99 : [x] "x" (@bitCast(@Vector(2, u64), x)),
100 [y] "x" (@bitCast(@Vector(2, u64), y)),
99 : [x] "x" (@as(@Vector(2, u64), @bitCast(x))),
100 [y] "x" (@as(@Vector(2, u64), @bitCast(y))),
101101 );
102 return @bitCast(u128, product);
102 return @as(u128, @bitCast(product));
103103 },
104104 .lo => {
105105 const product = asm (
106106 \\ vpclmulqdq $0x00, %[x], %[y], %[out]
107107 : [out] "=x" (-> @Vector(2, u64)),
108 : [x] "x" (@bitCast(@Vector(2, u64), x)),
109 [y] "x" (@bitCast(@Vector(2, u64), y)),
108 : [x] "x" (@as(@Vector(2, u64), @bitCast(x))),
109 [y] "x" (@as(@Vector(2, u64), @bitCast(y))),
110110 );
111 return @bitCast(u128, product);
111 return @as(u128, @bitCast(product));
112112 },
113113 .hi_lo => {
114114 const product = asm (
115115 \\ vpclmulqdq $0x10, %[x], %[y], %[out]
116116 : [out] "=x" (-> @Vector(2, u64)),
117 : [x] "x" (@bitCast(@Vector(2, u64), x)),
118 [y] "x" (@bitCast(@Vector(2, u64), y)),
117 : [x] "x" (@as(@Vector(2, u64), @bitCast(x))),
118 [y] "x" (@as(@Vector(2, u64), @bitCast(y))),
119119 );
120 return @bitCast(u128, product);
120 return @as(u128, @bitCast(product));
121121 },
122122 }
123123 }
......@@ -129,28 +129,28 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
129129 const product = asm (
130130 \\ pmull2 %[out].1q, %[x].2d, %[y].2d
131131 : [out] "=w" (-> @Vector(2, u64)),
132 : [x] "w" (@bitCast(@Vector(2, u64), x)),
133 [y] "w" (@bitCast(@Vector(2, u64), y)),
132 : [x] "w" (@as(@Vector(2, u64), @bitCast(x))),
133 [y] "w" (@as(@Vector(2, u64), @bitCast(y))),
134134 );
135 return @bitCast(u128, product);
135 return @as(u128, @bitCast(product));
136136 },
137137 .lo => {
138138 const product = asm (
139139 \\ pmull %[out].1q, %[x].1d, %[y].1d
140140 : [out] "=w" (-> @Vector(2, u64)),
141 : [x] "w" (@bitCast(@Vector(2, u64), x)),
142 [y] "w" (@bitCast(@Vector(2, u64), y)),
141 : [x] "w" (@as(@Vector(2, u64), @bitCast(x))),
142 [y] "w" (@as(@Vector(2, u64), @bitCast(y))),
143143 );
144 return @bitCast(u128, product);
144 return @as(u128, @bitCast(product));
145145 },
146146 .hi_lo => {
147147 const product = asm (
148148 \\ pmull %[out].1q, %[x].1d, %[y].1d
149149 : [out] "=w" (-> @Vector(2, u64)),
150 : [x] "w" (@bitCast(@Vector(2, u64), x >> 64)),
151 [y] "w" (@bitCast(@Vector(2, u64), y)),
150 : [x] "w" (@as(@Vector(2, u64), @bitCast(x >> 64))),
151 [y] "w" (@as(@Vector(2, u64), @bitCast(y))),
152152 );
153 return @bitCast(u128, product);
153 return @as(u128, @bitCast(product));
154154 },
155155 }
156156 }
......@@ -167,8 +167,8 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
167167
168168 // Software carryless multiplication of two 64-bit integers using native 128-bit registers.
169169 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_);
171 const y = @truncate(u64, if (half == .hi) y_ >> 64 else y_);
170 const x = @as(u64, @truncate(if (half == .hi or half == .hi_lo) x_ >> 64 else x_));
171 const y = @as(u64, @truncate(if (half == .hi) y_ >> 64 else y_));
172172
173173 const x0 = x & 0x1111111111111110;
174174 const x1 = x & 0x2222222222222220;
......@@ -216,12 +216,12 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
216216
217217 // Software carryless multiplication of two 128-bit integers using 64-bit registers.
218218 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_);
220 const b = @truncate(u64, if (half == .hi) y_ >> 64 else y_);
221 const a0 = @truncate(u32, a);
222 const a1 = @truncate(u32, a >> 32);
223 const b0 = @truncate(u32, b);
224 const b1 = @truncate(u32, b >> 32);
219 const a = @as(u64, @truncate(if (half == .hi or half == .hi_lo) x_ >> 64 else x_));
220 const b = @as(u64, @truncate(if (half == .hi) y_ >> 64 else y_));
221 const a0 = @as(u32, @truncate(a));
222 const a1 = @as(u32, @truncate(a >> 32));
223 const b0 = @as(u32, @truncate(b));
224 const b1 = @as(u32, @truncate(b >> 32));
225225 const lo = clmulSoft32(a0, b0);
226226 const hi = clmulSoft32(a1, b1);
227227 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 {
256256 // Multiply two 128-bit integers in GF(2^128).
257257 inline fn clmul128(x: u128, y: u128) I256 {
258258 if (mul_algorithm == .karatsuba) {
259 const x_hi = @truncate(u64, x >> 64);
260 const y_hi = @truncate(u64, y >> 64);
259 const x_hi = @as(u64, @truncate(x >> 64));
260 const y_hi = @as(u64, @truncate(y >> 64));
261261 const r_lo = clmul(x, y, .lo);
262262 const r_hi = clmul(x, y, .hi);
263263 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 {
407407 st.pad();
408408 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)]);
411411 }
412412
413413 /// Compute the GHASH of a message.
......@@ -442,7 +442,7 @@ test "ghash2" {
442442 var key: [16]u8 = undefined;
443443 var i: usize = 0;
444444 while (i < key.len) : (i += 1) {
445 key[i] = @intCast(u8, i * 15 + 1);
445 key[i] = @as(u8, @intCast(i * 15 + 1));
446446 }
447447 const tvs = [_]struct { len: usize, hash: [:0]const u8 }{
448448 .{ .len = 5263, .hash = "b9395f37c131cd403a327ccf82ec016a" },
......@@ -461,7 +461,7 @@ test "ghash2" {
461461 var m: [tv.len]u8 = undefined;
462462 i = 0;
463463 while (i < m.len) : (i += 1) {
464 m[i] = @truncate(u8, i % 254 + 1);
464 m[i] = @as(u8, @truncate(i % 254 + 1));
465465 }
466466 var st = Ghash.init(&key);
467467 st.update(&m);
lib/std/crypto/isap.zig+1-1
......@@ -67,7 +67,7 @@ pub const IsapA128A = struct {
6767 var i: usize = 0;
6868 while (i < y.len * 8 - 1) : (i += 1) {
6969 const cur_byte_pos = i / 8;
70 const cur_bit_pos = @truncate(u3, 7 - (i % 8));
70 const cur_bit_pos = @as(u3, @truncate(7 - (i % 8)));
7171 const cur_bit = ((y[cur_byte_pos] >> cur_bit_pos) & 1) << 7;
7272 isap.st.addByte(cur_bit, 0);
7373 isap.st.permuteR(1);
lib/std/crypto/keccak_p.zig+2-2
......@@ -33,7 +33,7 @@ pub fn KeccakF(comptime f: u11) type {
3333 0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008,
3434 };
3535 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));
3737 break :rc rc;
3838 };
3939
......@@ -75,7 +75,7 @@ pub fn KeccakF(comptime f: u11) type {
7575
7676 /// XOR a byte into the state at a given offset.
7777 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)));
7979 self.st[offset / @sizeOf(T)] ^= @as(T, byte) << z;
8080 }
8181
lib/std/crypto/kyber_d00.zig+36-36
......@@ -579,7 +579,7 @@ test "invNTTReductions bounds" {
579579 if (j < 0) {
580580 break;
581581 }
582 xs[@intCast(usize, j)] = 1;
582 xs[@as(usize, @intCast(j))] = 1;
583583 }
584584 }
585585}
......@@ -615,7 +615,7 @@ fn invertMod(a: anytype, p: @TypeOf(a)) @TypeOf(a) {
615615
616616// Reduce mod q for testing.
617617fn 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))));
619619 if (y < 0) {
620620 y += Q;
621621 }
......@@ -638,7 +638,7 @@ fn montReduce(x: i32) i16 {
638638 // Note that x q' might be as big as 2³² and could overflow the int32
639639 // multiplication in the last line. However for any int32s a and b,
640640 // we have int32(int64(a)*int64(b)) = int32(a*b) and so the result is ok.
641 const m = @truncate(i16, @truncate(i32, x *% qInv));
641 const m = @as(i16, @truncate(@as(i32, @truncate(x *% qInv))));
642642
643643 // Note that x - m q is divisible by R; indeed modulo R we have
644644 //
......@@ -652,7 +652,7 @@ fn montReduce(x: i32) i16 {
652652 // and as both 2¹⁵ q ≤ m q, x < 2¹⁵ q, we have
653653 // 2¹⁶ q ≤ x - m q < 2¹⁶ and so q ≤ (x - m q) / R < q as desired.
654654 const yR = x - @as(i32, m) * @as(i32, Q);
655 return @bitCast(i16, @truncate(u16, @bitCast(u32, yR) >> 16));
655 return @as(i16, @bitCast(@as(u16, @truncate(@as(u32, @bitCast(yR)) >> 16))));
656656}
657657
658658test "Test montReduce" {
......@@ -676,7 +676,7 @@ fn feToMont(x: i16) i16 {
676676test "Test feToMont" {
677677 var x: i32 = -(1 << 15);
678678 while (x < 1 << 15) : (x += 1) {
679 const y = feToMont(@intCast(i16, x));
679 const y = feToMont(@as(i16, @intCast(x)));
680680 try testing.expectEqual(modQ32(@as(i32, y)), modQ32(x * r_mod_q));
681681 }
682682}
......@@ -703,14 +703,14 @@ fn feBarrettReduce(x: i16) i16 {
703703 // To actually compute this, note that
704704 //
705705 // ⌊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;
707707}
708708
709709test "Test Barrett reduction" {
710710 var x: i32 = -(1 << 15);
711711 while (x < 1 << 15) : (x += 1) {
712 var y1 = feBarrettReduce(@intCast(i16, x));
713 const y2 = @mod(@intCast(i16, x), Q);
712 var y1 = feBarrettReduce(@as(i16, @intCast(x)));
713 const y2 = @mod(@as(i16, @intCast(x)), Q);
714714 if (x < 0 and @rem(-x, Q) == 0) {
715715 y1 -= Q;
716716 }
......@@ -729,9 +729,9 @@ fn csubq(x: i16) i16 {
729729test "Test csubq" {
730730 var x: i32 = -29439;
731731 while (x < 1 << 15) : (x += 1) {
732 const y1 = csubq(@intCast(i16, x));
733 var y2 = @intCast(i16, x);
734 if (@intCast(i16, x) >= Q) {
732 const y1 = csubq(@as(i16, @intCast(x)));
733 var y2 = @as(i16, @intCast(x));
734 if (@as(i16, @intCast(x)) >= Q) {
735735 y2 -= Q;
736736 }
737737 try testing.expectEqual(y1, y2);
......@@ -762,7 +762,7 @@ fn computeZetas() [128]i16 {
762762 @setEvalBranchQuota(10000);
763763 var ret: [128]i16 = undefined;
764764 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)));
766766 r.* = csubq(feBarrettReduce(feToMont(t)));
767767 }
768768 return ret;
......@@ -945,7 +945,7 @@ const Poly = struct {
945945 if (i < 0) {
946946 break;
947947 }
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))]);
949949 }
950950 }
951951
......@@ -1020,8 +1020,8 @@ const Poly = struct {
10201020 // = ⌊(2ᵈ/q)x+½⌋ mod⁺ 2ᵈ
10211021 // = ⌊((x << d) + q/2) / q⌋ mod⁺ 2ᵈ
10221022 // = DIV((x << d) + q/2, q) & ((1<<d) - 1)
1023 const t = @intCast(u32, p.cs[in_off + i]) << d;
1024 in[i] = @intCast(u16, @divFloor(t + q_over_2, Q) & two_d_min_1);
1023 const t = @as(u32, @intCast(p.cs[in_off + i])) << d;
1024 in[i] = @as(u16, @intCast(@divFloor(t + q_over_2, Q) & two_d_min_1));
10251025 }
10261026
10271027 // Now we pack the d-bit integers from `in' into out as bytes.
......@@ -1032,7 +1032,7 @@ const Poly = struct {
10321032 comptime var todo: usize = 8;
10331033 inline while (todo > 0) {
10341034 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
10371037 const done = comptime @min(@min(d, todo), d - in_shift);
10381038 todo -= done;
......@@ -1094,7 +1094,7 @@ const Poly = struct {
10941094 // = ⌊(qx + 2ᵈ⁻¹)/2ᵈ⌋
10951095 // = (qx + (1<<(d-1))) >> d
10961096 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));
10981098 }
10991099
11001100 in_off += in_batch_size;
......@@ -1209,8 +1209,8 @@ const Poly = struct {
12091209 // Extract each a and b separately and set coefficient in polynomial.
12101210 inline for (0..batch_count) |j| {
12111211 const mask2 = comptime (1 << eta) - 1;
1212 const a = @intCast(i16, (d >> (comptime (2 * j * eta))) & mask2);
1213 const b = @intCast(i16, (d >> (comptime ((2 * j + 1) * eta))) & mask2);
1212 const a = @as(i16, @intCast((d >> (comptime (2 * j * eta))) & mask2));
1213 const b = @as(i16, @intCast((d >> (comptime ((2 * j + 1) * eta))) & mask2));
12141214 ret.cs[batch_count * i + j] = a - b;
12151215 }
12161216 }
......@@ -1246,7 +1246,7 @@ const Poly = struct {
12461246
12471247 inline for (ts) |t| {
12481248 if (t < Q) {
1249 ret.cs[i] = @intCast(i16, t);
1249 ret.cs[i] = @as(i16, @intCast(t));
12501250 i += 1;
12511251
12521252 if (i == N) {
......@@ -1266,11 +1266,11 @@ const Poly = struct {
12661266 fn toBytes(p: Poly) [bytes_length]u8 {
12671267 var ret: [bytes_length]u8 = undefined;
12681268 for (0..comptime N / 2) |i| {
1269 const t0 = @intCast(u16, p.cs[2 * i]);
1270 const t1 = @intCast(u16, p.cs[2 * i + 1]);
1271 ret[3 * i] = @truncate(u8, t0);
1272 ret[3 * i + 1] = @truncate(u8, (t0 >> 8) | (t1 << 4));
1273 ret[3 * i + 2] = @truncate(u8, t1 >> 4);
1269 const t0 = @as(u16, @intCast(p.cs[2 * i]));
1270 const t1 = @as(u16, @intCast(p.cs[2 * i + 1]));
1271 ret[3 * i] = @as(u8, @truncate(t0));
1272 ret[3 * i + 1] = @as(u8, @truncate((t0 >> 8) | (t1 << 4)));
1273 ret[3 * i + 2] = @as(u8, @truncate(t1 >> 4));
12741274 }
12751275 return ret;
12761276 }
......@@ -1356,7 +1356,7 @@ fn Vec(comptime K: u8) type {
13561356 fn noise(comptime eta: u8, nonce: u8, seed: *const [32]u8) Self {
13571357 var ret: Self = undefined;
13581358 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);
13601360 }
13611361 return ret;
13621362 }
......@@ -1534,7 +1534,7 @@ test "Compression" {
15341534test "noise" {
15351535 var seed: [32]u8 = undefined;
15361536 for (&seed, 0..) |*s, i| {
1537 s.* = @intCast(u8, i);
1537 s.* = @as(u8, @intCast(i));
15381538 }
15391539 try testing.expectEqual(Poly.noise(3, 37, &seed).cs, .{
15401540 0, 0, 1, -1, 0, 2, 0, -1, -1, 3, 0, 1, -2, -2, 0, 1, -2,
......@@ -1580,7 +1580,7 @@ test "noise" {
15801580test "uniform sampling" {
15811581 var seed: [32]u8 = undefined;
15821582 for (&seed, 0..) |*s, i| {
1583 s.* = @intCast(u8, i);
1583 s.* = @as(u8, @intCast(i));
15841584 }
15851585 try testing.expectEqual(Poly.uniform(seed, 1, 0).cs, .{
15861586 797, 993, 161, 6, 2608, 2385, 2096, 2661, 1676, 247, 2440,
......@@ -1623,17 +1623,17 @@ test "Test inner PKE" {
16231623 var seed: [32]u8 = undefined;
16241624 var pt: [32]u8 = undefined;
16251625 for (&seed, &pt, 0..) |*s, *p, i| {
1626 s.* = @intCast(u8, i);
1627 p.* = @intCast(u8, i + 32);
1626 s.* = @as(u8, @intCast(i));
1627 p.* = @as(u8, @intCast(i + 32));
16281628 }
16291629 inline for (modes) |mode| {
16301630 for (0..100) |i| {
16311631 var pk: mode.InnerPk = undefined;
16321632 var sk: mode.InnerSk = undefined;
1633 seed[0] = @intCast(u8, i);
1633 seed[0] = @as(u8, @intCast(i));
16341634 mode.innerKeyFromSeed(seed, &pk, &sk);
16351635 for (0..10) |j| {
1636 seed[1] = @intCast(u8, j);
1636 seed[1] = @as(u8, @intCast(j));
16371637 try testing.expectEqual(sk.decrypt(&pk.encrypt(&pt, &seed)), pt);
16381638 }
16391639 }
......@@ -1643,18 +1643,18 @@ test "Test inner PKE" {
16431643test "Test happy flow" {
16441644 var seed: [64]u8 = undefined;
16451645 for (&seed, 0..) |*s, i| {
1646 s.* = @intCast(u8, i);
1646 s.* = @as(u8, @intCast(i));
16471647 }
16481648 inline for (modes) |mode| {
16491649 for (0..100) |i| {
1650 seed[0] = @intCast(u8, i);
1650 seed[0] = @as(u8, @intCast(i));
16511651 const kp = try mode.KeyPair.create(seed);
16521652 const sk = try mode.SecretKey.fromBytes(&kp.secret_key.toBytes());
16531653 try testing.expectEqual(sk, kp.secret_key);
16541654 const pk = try mode.PublicKey.fromBytes(&kp.public_key.toBytes());
16551655 try testing.expectEqual(pk, kp.public_key);
16561656 for (0..10) |j| {
1657 seed[1] = @intCast(u8, j);
1657 seed[1] = @as(u8, @intCast(j));
16581658 const e = pk.encaps(seed[0..32].*);
16591659 try testing.expectEqual(e.shared_secret, try sk.decaps(&e.ciphertext));
16601660 }
......@@ -1675,7 +1675,7 @@ test "NIST KAT test" {
16751675 const mode = modeHash[0];
16761676 var seed: [48]u8 = undefined;
16771677 for (&seed, 0..) |*s, i| {
1678 s.* = @intCast(u8, i);
1678 s.* = @as(u8, @intCast(i));
16791679 }
16801680 var f = sha2.Sha256.init(.{});
16811681 const fw = f.writer();
lib/std/crypto/md5.zig+3-3
......@@ -80,7 +80,7 @@ pub const Md5 = struct {
8080 // Copy any remainder for next pass.
8181 const b_slice = b[off..];
8282 @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
8585 // Md5 uses the bottom 64-bits for length padding
8686 d.total_len +%= b.len;
......@@ -103,9 +103,9 @@ pub const Md5 = struct {
103103 // Append message length.
104104 var i: usize = 1;
105105 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;
107107 while (i < 8) : (i += 1) {
108 d.buf[56 + i] = @intCast(u8, len & 0xff);
108 d.buf[56 + i] = @as(u8, @intCast(len & 0xff));
109109 len >>= 8;
110110 }
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
7474 // block
7575 //
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));
7878 var r = dk_len % h_len;
7979 if (r == 0) {
8080 r = h_len;
lib/std/crypto/pcurves/common.zig+3-3
......@@ -120,7 +120,7 @@ pub fn Field(comptime params: FieldParams) type {
120120 /// Return true if the element is odd.
121121 pub fn isOdd(fe: Fe) bool {
122122 const s = fe.toBytes(.Little);
123 return @truncate(u1, s[0]) != 0;
123 return @as(u1, @truncate(s[0])) != 0;
124124 }
125125
126126 /// Conditonally replace a field element with `a` if `c` is positive.
......@@ -179,7 +179,7 @@ pub fn Field(comptime params: FieldParams) type {
179179 var x: T = n;
180180 var t = a;
181181 while (true) {
182 if (@truncate(u1, x) != 0) fe = fe.mul(t);
182 if (@as(u1, @truncate(x)) != 0) fe = fe.mul(t);
183183 x >>= 1;
184184 if (x == 0) break;
185185 t = t.sq();
......@@ -233,7 +233,7 @@ pub fn Field(comptime params: FieldParams) type {
233233 }
234234 var v_opp: Limbs = undefined;
235235 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
238238 const precomp = blk: {
239239 var precomp: Limbs = undefined;
lib/std/crypto/pcurves/p256.zig+10-10
......@@ -318,7 +318,7 @@ pub const P256 = struct {
318318 var t = P256.identityElement;
319319 comptime var i: u8 = 1;
320320 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)));
322322 }
323323 return t;
324324 }
......@@ -326,8 +326,8 @@ pub const P256 = struct {
326326 fn slide(s: [32]u8) [2 * 32 + 1]i8 {
327327 var e: [2 * 32 + 1]i8 = undefined;
328328 for (s, 0..) |x, i| {
329 e[i * 2 + 0] = @as(i8, @truncate(u4, x));
330 e[i * 2 + 1] = @as(i8, @truncate(u4, x >> 4));
329 e[i * 2 + 0] = @as(i8, @as(u4, @truncate(x)));
330 e[i * 2 + 1] = @as(i8, @as(u4, @truncate(x >> 4)));
331331 }
332332 // Now, e[0..63] is between 0 and 15, e[63] is between 0 and 7
333333 var carry: i8 = 0;
......@@ -351,9 +351,9 @@ pub const P256 = struct {
351351 while (true) : (pos -= 1) {
352352 const slot = e[pos];
353353 if (slot > 0) {
354 q = q.add(pc[@intCast(usize, slot)]);
354 q = q.add(pc[@as(usize, @intCast(slot))]);
355355 } else if (slot < 0) {
356 q = q.sub(pc[@intCast(usize, -slot)]);
356 q = q.sub(pc[@as(usize, @intCast(-slot))]);
357357 }
358358 if (pos == 0) break;
359359 q = q.dbl().dbl().dbl().dbl();
......@@ -366,7 +366,7 @@ pub const P256 = struct {
366366 var q = P256.identityElement;
367367 var pos: usize = 252;
368368 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)))));
370370 if (vartime) {
371371 if (slot != 0) {
372372 q = q.add(pc[slot]);
......@@ -445,15 +445,15 @@ pub const P256 = struct {
445445 while (true) : (pos -= 1) {
446446 const slot1 = e1[pos];
447447 if (slot1 > 0) {
448 q = q.add(pc1[@intCast(usize, slot1)]);
448 q = q.add(pc1[@as(usize, @intCast(slot1))]);
449449 } else if (slot1 < 0) {
450 q = q.sub(pc1[@intCast(usize, -slot1)]);
450 q = q.sub(pc1[@as(usize, @intCast(-slot1))]);
451451 }
452452 const slot2 = e2[pos];
453453 if (slot2 > 0) {
454 q = q.add(pc2[@intCast(usize, slot2)]);
454 q = q.add(pc2[@as(usize, @intCast(slot2))]);
455455 } else if (slot2 < 0) {
456 q = q.sub(pc2[@intCast(usize, -slot2)]);
456 q = q.sub(pc2[@as(usize, @intCast(-slot2))]);
457457 }
458458 if (pos == 0) break;
459459 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 {
119119 @setRuntimeSafety(mode == .Debug);
120120
121121 const x = @as(u128, arg1) * @as(u128, arg2);
122 out1.* = @truncate(u64, x);
123 out2.* = @truncate(u64, x >> 64);
122 out1.* = @as(u64, @truncate(x));
123 out2.* = @as(u64, @truncate(x >> 64));
124124}
125125
126126/// The function cmovznzU64 is a single-word conditional move.
......@@ -1355,62 +1355,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {
13551355 const x2 = (arg1[2]);
13561356 const x3 = (arg1[1]);
13571357 const x4 = (arg1[0]);
1358 const x5 = @truncate(u8, (x4 & @as(u64, 0xff)));
1358 const x5 = @as(u8, @truncate((x4 & @as(u64, 0xff))));
13591359 const x6 = (x4 >> 8);
1360 const x7 = @truncate(u8, (x6 & @as(u64, 0xff)));
1360 const x7 = @as(u8, @truncate((x6 & @as(u64, 0xff))));
13611361 const x8 = (x6 >> 8);
1362 const x9 = @truncate(u8, (x8 & @as(u64, 0xff)));
1362 const x9 = @as(u8, @truncate((x8 & @as(u64, 0xff))));
13631363 const x10 = (x8 >> 8);
1364 const x11 = @truncate(u8, (x10 & @as(u64, 0xff)));
1364 const x11 = @as(u8, @truncate((x10 & @as(u64, 0xff))));
13651365 const x12 = (x10 >> 8);
1366 const x13 = @truncate(u8, (x12 & @as(u64, 0xff)));
1366 const x13 = @as(u8, @truncate((x12 & @as(u64, 0xff))));
13671367 const x14 = (x12 >> 8);
1368 const x15 = @truncate(u8, (x14 & @as(u64, 0xff)));
1368 const x15 = @as(u8, @truncate((x14 & @as(u64, 0xff))));
13691369 const x16 = (x14 >> 8);
1370 const x17 = @truncate(u8, (x16 & @as(u64, 0xff)));
1371 const x18 = @truncate(u8, (x16 >> 8));
1372 const x19 = @truncate(u8, (x3 & @as(u64, 0xff)));
1370 const x17 = @as(u8, @truncate((x16 & @as(u64, 0xff))));
1371 const x18 = @as(u8, @truncate((x16 >> 8)));
1372 const x19 = @as(u8, @truncate((x3 & @as(u64, 0xff))));
13731373 const x20 = (x3 >> 8);
1374 const x21 = @truncate(u8, (x20 & @as(u64, 0xff)));
1374 const x21 = @as(u8, @truncate((x20 & @as(u64, 0xff))));
13751375 const x22 = (x20 >> 8);
1376 const x23 = @truncate(u8, (x22 & @as(u64, 0xff)));
1376 const x23 = @as(u8, @truncate((x22 & @as(u64, 0xff))));
13771377 const x24 = (x22 >> 8);
1378 const x25 = @truncate(u8, (x24 & @as(u64, 0xff)));
1378 const x25 = @as(u8, @truncate((x24 & @as(u64, 0xff))));
13791379 const x26 = (x24 >> 8);
1380 const x27 = @truncate(u8, (x26 & @as(u64, 0xff)));
1380 const x27 = @as(u8, @truncate((x26 & @as(u64, 0xff))));
13811381 const x28 = (x26 >> 8);
1382 const x29 = @truncate(u8, (x28 & @as(u64, 0xff)));
1382 const x29 = @as(u8, @truncate((x28 & @as(u64, 0xff))));
13831383 const x30 = (x28 >> 8);
1384 const x31 = @truncate(u8, (x30 & @as(u64, 0xff)));
1385 const x32 = @truncate(u8, (x30 >> 8));
1386 const x33 = @truncate(u8, (x2 & @as(u64, 0xff)));
1384 const x31 = @as(u8, @truncate((x30 & @as(u64, 0xff))));
1385 const x32 = @as(u8, @truncate((x30 >> 8)));
1386 const x33 = @as(u8, @truncate((x2 & @as(u64, 0xff))));
13871387 const x34 = (x2 >> 8);
1388 const x35 = @truncate(u8, (x34 & @as(u64, 0xff)));
1388 const x35 = @as(u8, @truncate((x34 & @as(u64, 0xff))));
13891389 const x36 = (x34 >> 8);
1390 const x37 = @truncate(u8, (x36 & @as(u64, 0xff)));
1390 const x37 = @as(u8, @truncate((x36 & @as(u64, 0xff))));
13911391 const x38 = (x36 >> 8);
1392 const x39 = @truncate(u8, (x38 & @as(u64, 0xff)));
1392 const x39 = @as(u8, @truncate((x38 & @as(u64, 0xff))));
13931393 const x40 = (x38 >> 8);
1394 const x41 = @truncate(u8, (x40 & @as(u64, 0xff)));
1394 const x41 = @as(u8, @truncate((x40 & @as(u64, 0xff))));
13951395 const x42 = (x40 >> 8);
1396 const x43 = @truncate(u8, (x42 & @as(u64, 0xff)));
1396 const x43 = @as(u8, @truncate((x42 & @as(u64, 0xff))));
13971397 const x44 = (x42 >> 8);
1398 const x45 = @truncate(u8, (x44 & @as(u64, 0xff)));
1399 const x46 = @truncate(u8, (x44 >> 8));
1400 const x47 = @truncate(u8, (x1 & @as(u64, 0xff)));
1398 const x45 = @as(u8, @truncate((x44 & @as(u64, 0xff))));
1399 const x46 = @as(u8, @truncate((x44 >> 8)));
1400 const x47 = @as(u8, @truncate((x1 & @as(u64, 0xff))));
14011401 const x48 = (x1 >> 8);
1402 const x49 = @truncate(u8, (x48 & @as(u64, 0xff)));
1402 const x49 = @as(u8, @truncate((x48 & @as(u64, 0xff))));
14031403 const x50 = (x48 >> 8);
1404 const x51 = @truncate(u8, (x50 & @as(u64, 0xff)));
1404 const x51 = @as(u8, @truncate((x50 & @as(u64, 0xff))));
14051405 const x52 = (x50 >> 8);
1406 const x53 = @truncate(u8, (x52 & @as(u64, 0xff)));
1406 const x53 = @as(u8, @truncate((x52 & @as(u64, 0xff))));
14071407 const x54 = (x52 >> 8);
1408 const x55 = @truncate(u8, (x54 & @as(u64, 0xff)));
1408 const x55 = @as(u8, @truncate((x54 & @as(u64, 0xff))));
14091409 const x56 = (x54 >> 8);
1410 const x57 = @truncate(u8, (x56 & @as(u64, 0xff)));
1410 const x57 = @as(u8, @truncate((x56 & @as(u64, 0xff))));
14111411 const x58 = (x56 >> 8);
1412 const x59 = @truncate(u8, (x58 & @as(u64, 0xff)));
1413 const x60 = @truncate(u8, (x58 >> 8));
1412 const x59 = @as(u8, @truncate((x58 & @as(u64, 0xff))));
1413 const x60 = @as(u8, @truncate((x58 >> 8)));
14141414 out1[0] = x5;
14151415 out1[1] = x7;
14161416 out1[2] = x9;
......@@ -1593,7 +1593,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
15931593 var x1: u64 = undefined;
15941594 var x2: u1 = undefined;
15951595 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)))));
15971597 var x4: u64 = undefined;
15981598 var x5: u1 = undefined;
15991599 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: *[
17071707 cmovznzU64(&x72, x3, (arg5[2]), x66);
17081708 var x73: u64 = undefined;
17091709 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))));
17111711 var x75: u64 = undefined;
17121712 cmovznzU64(&x75, x74, @as(u64, 0x0), x7);
17131713 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 {
119119 @setRuntimeSafety(mode == .Debug);
120120
121121 const x = @as(u128, arg1) * @as(u128, arg2);
122 out1.* = @truncate(u64, x);
123 out2.* = @truncate(u64, x >> 64);
122 out1.* = @as(u64, @truncate(x));
123 out2.* = @as(u64, @truncate(x >> 64));
124124}
125125
126126/// The function cmovznzU64 is a single-word conditional move.
......@@ -1559,62 +1559,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {
15591559 const x2 = (arg1[2]);
15601560 const x3 = (arg1[1]);
15611561 const x4 = (arg1[0]);
1562 const x5 = @truncate(u8, (x4 & @as(u64, 0xff)));
1562 const x5 = @as(u8, @truncate((x4 & @as(u64, 0xff))));
15631563 const x6 = (x4 >> 8);
1564 const x7 = @truncate(u8, (x6 & @as(u64, 0xff)));
1564 const x7 = @as(u8, @truncate((x6 & @as(u64, 0xff))));
15651565 const x8 = (x6 >> 8);
1566 const x9 = @truncate(u8, (x8 & @as(u64, 0xff)));
1566 const x9 = @as(u8, @truncate((x8 & @as(u64, 0xff))));
15671567 const x10 = (x8 >> 8);
1568 const x11 = @truncate(u8, (x10 & @as(u64, 0xff)));
1568 const x11 = @as(u8, @truncate((x10 & @as(u64, 0xff))));
15691569 const x12 = (x10 >> 8);
1570 const x13 = @truncate(u8, (x12 & @as(u64, 0xff)));
1570 const x13 = @as(u8, @truncate((x12 & @as(u64, 0xff))));
15711571 const x14 = (x12 >> 8);
1572 const x15 = @truncate(u8, (x14 & @as(u64, 0xff)));
1572 const x15 = @as(u8, @truncate((x14 & @as(u64, 0xff))));
15731573 const x16 = (x14 >> 8);
1574 const x17 = @truncate(u8, (x16 & @as(u64, 0xff)));
1575 const x18 = @truncate(u8, (x16 >> 8));
1576 const x19 = @truncate(u8, (x3 & @as(u64, 0xff)));
1574 const x17 = @as(u8, @truncate((x16 & @as(u64, 0xff))));
1575 const x18 = @as(u8, @truncate((x16 >> 8)));
1576 const x19 = @as(u8, @truncate((x3 & @as(u64, 0xff))));
15771577 const x20 = (x3 >> 8);
1578 const x21 = @truncate(u8, (x20 & @as(u64, 0xff)));
1578 const x21 = @as(u8, @truncate((x20 & @as(u64, 0xff))));
15791579 const x22 = (x20 >> 8);
1580 const x23 = @truncate(u8, (x22 & @as(u64, 0xff)));
1580 const x23 = @as(u8, @truncate((x22 & @as(u64, 0xff))));
15811581 const x24 = (x22 >> 8);
1582 const x25 = @truncate(u8, (x24 & @as(u64, 0xff)));
1582 const x25 = @as(u8, @truncate((x24 & @as(u64, 0xff))));
15831583 const x26 = (x24 >> 8);
1584 const x27 = @truncate(u8, (x26 & @as(u64, 0xff)));
1584 const x27 = @as(u8, @truncate((x26 & @as(u64, 0xff))));
15851585 const x28 = (x26 >> 8);
1586 const x29 = @truncate(u8, (x28 & @as(u64, 0xff)));
1586 const x29 = @as(u8, @truncate((x28 & @as(u64, 0xff))));
15871587 const x30 = (x28 >> 8);
1588 const x31 = @truncate(u8, (x30 & @as(u64, 0xff)));
1589 const x32 = @truncate(u8, (x30 >> 8));
1590 const x33 = @truncate(u8, (x2 & @as(u64, 0xff)));
1588 const x31 = @as(u8, @truncate((x30 & @as(u64, 0xff))));
1589 const x32 = @as(u8, @truncate((x30 >> 8)));
1590 const x33 = @as(u8, @truncate((x2 & @as(u64, 0xff))));
15911591 const x34 = (x2 >> 8);
1592 const x35 = @truncate(u8, (x34 & @as(u64, 0xff)));
1592 const x35 = @as(u8, @truncate((x34 & @as(u64, 0xff))));
15931593 const x36 = (x34 >> 8);
1594 const x37 = @truncate(u8, (x36 & @as(u64, 0xff)));
1594 const x37 = @as(u8, @truncate((x36 & @as(u64, 0xff))));
15951595 const x38 = (x36 >> 8);
1596 const x39 = @truncate(u8, (x38 & @as(u64, 0xff)));
1596 const x39 = @as(u8, @truncate((x38 & @as(u64, 0xff))));
15971597 const x40 = (x38 >> 8);
1598 const x41 = @truncate(u8, (x40 & @as(u64, 0xff)));
1598 const x41 = @as(u8, @truncate((x40 & @as(u64, 0xff))));
15991599 const x42 = (x40 >> 8);
1600 const x43 = @truncate(u8, (x42 & @as(u64, 0xff)));
1600 const x43 = @as(u8, @truncate((x42 & @as(u64, 0xff))));
16011601 const x44 = (x42 >> 8);
1602 const x45 = @truncate(u8, (x44 & @as(u64, 0xff)));
1603 const x46 = @truncate(u8, (x44 >> 8));
1604 const x47 = @truncate(u8, (x1 & @as(u64, 0xff)));
1602 const x45 = @as(u8, @truncate((x44 & @as(u64, 0xff))));
1603 const x46 = @as(u8, @truncate((x44 >> 8)));
1604 const x47 = @as(u8, @truncate((x1 & @as(u64, 0xff))));
16051605 const x48 = (x1 >> 8);
1606 const x49 = @truncate(u8, (x48 & @as(u64, 0xff)));
1606 const x49 = @as(u8, @truncate((x48 & @as(u64, 0xff))));
16071607 const x50 = (x48 >> 8);
1608 const x51 = @truncate(u8, (x50 & @as(u64, 0xff)));
1608 const x51 = @as(u8, @truncate((x50 & @as(u64, 0xff))));
16091609 const x52 = (x50 >> 8);
1610 const x53 = @truncate(u8, (x52 & @as(u64, 0xff)));
1610 const x53 = @as(u8, @truncate((x52 & @as(u64, 0xff))));
16111611 const x54 = (x52 >> 8);
1612 const x55 = @truncate(u8, (x54 & @as(u64, 0xff)));
1612 const x55 = @as(u8, @truncate((x54 & @as(u64, 0xff))));
16131613 const x56 = (x54 >> 8);
1614 const x57 = @truncate(u8, (x56 & @as(u64, 0xff)));
1614 const x57 = @as(u8, @truncate((x56 & @as(u64, 0xff))));
16151615 const x58 = (x56 >> 8);
1616 const x59 = @truncate(u8, (x58 & @as(u64, 0xff)));
1617 const x60 = @truncate(u8, (x58 >> 8));
1616 const x59 = @as(u8, @truncate((x58 & @as(u64, 0xff))));
1617 const x60 = @as(u8, @truncate((x58 >> 8)));
16181618 out1[0] = x5;
16191619 out1[1] = x7;
16201620 out1[2] = x9;
......@@ -1797,7 +1797,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
17971797 var x1: u64 = undefined;
17981798 var x2: u1 = undefined;
17991799 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))));
18011801 var x4: u64 = undefined;
18021802 var x5: u1 = undefined;
18031803 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: *[
19111911 cmovznzU64(&x72, x3, (arg5[2]), x66);
19121912 var x73: u64 = undefined;
19131913 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))));
19151915 var x75: u64 = undefined;
19161916 cmovznzU64(&x75, x74, @as(u64, 0x0), x7);
19171917 var x76: u64 = undefined;
lib/std/crypto/pcurves/p384.zig+10-10
......@@ -318,7 +318,7 @@ pub const P384 = struct {
318318 var t = P384.identityElement;
319319 comptime var i: u8 = 1;
320320 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)));
322322 }
323323 return t;
324324 }
......@@ -326,8 +326,8 @@ pub const P384 = struct {
326326 fn slide(s: [48]u8) [2 * 48 + 1]i8 {
327327 var e: [2 * 48 + 1]i8 = undefined;
328328 for (s, 0..) |x, i| {
329 e[i * 2 + 0] = @as(i8, @truncate(u4, x));
330 e[i * 2 + 1] = @as(i8, @truncate(u4, x >> 4));
329 e[i * 2 + 0] = @as(i8, @as(u4, @truncate(x)));
330 e[i * 2 + 1] = @as(i8, @as(u4, @truncate(x >> 4)));
331331 }
332332 // Now, e[0..63] is between 0 and 15, e[63] is between 0 and 7
333333 var carry: i8 = 0;
......@@ -351,9 +351,9 @@ pub const P384 = struct {
351351 while (true) : (pos -= 1) {
352352 const slot = e[pos];
353353 if (slot > 0) {
354 q = q.add(pc[@intCast(usize, slot)]);
354 q = q.add(pc[@as(usize, @intCast(slot))]);
355355 } else if (slot < 0) {
356 q = q.sub(pc[@intCast(usize, -slot)]);
356 q = q.sub(pc[@as(usize, @intCast(-slot))]);
357357 }
358358 if (pos == 0) break;
359359 q = q.dbl().dbl().dbl().dbl();
......@@ -366,7 +366,7 @@ pub const P384 = struct {
366366 var q = P384.identityElement;
367367 var pos: usize = 380;
368368 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)))));
370370 if (vartime) {
371371 if (slot != 0) {
372372 q = q.add(pc[slot]);
......@@ -445,15 +445,15 @@ pub const P384 = struct {
445445 while (true) : (pos -= 1) {
446446 const slot1 = e1[pos];
447447 if (slot1 > 0) {
448 q = q.add(pc1[@intCast(usize, slot1)]);
448 q = q.add(pc1[@as(usize, @intCast(slot1))]);
449449 } else if (slot1 < 0) {
450 q = q.sub(pc1[@intCast(usize, -slot1)]);
450 q = q.sub(pc1[@as(usize, @intCast(-slot1))]);
451451 }
452452 const slot2 = e2[pos];
453453 if (slot2 > 0) {
454 q = q.add(pc2[@intCast(usize, slot2)]);
454 q = q.add(pc2[@as(usize, @intCast(slot2))]);
455455 } else if (slot2 < 0) {
456 q = q.sub(pc2[@intCast(usize, -slot2)]);
456 q = q.sub(pc2[@as(usize, @intCast(-slot2))]);
457457 }
458458 if (pos == 0) break;
459459 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 {
8888 @setRuntimeSafety(mode == .Debug);
8989
9090 const x = @as(u128, arg1) * @as(u128, arg2);
91 out1.* = @truncate(u64, x);
92 out2.* = @truncate(u64, x >> 64);
91 out1.* = @as(u64, @truncate(x));
92 out2.* = @as(u64, @truncate(x >> 64));
9393}
9494
9595/// The function cmovznzU64 is a single-word conditional move.
......@@ -2928,90 +2928,90 @@ pub fn toBytes(out1: *[48]u8, arg1: [6]u64) void {
29282928 const x4 = (arg1[2]);
29292929 const x5 = (arg1[1]);
29302930 const x6 = (arg1[0]);
2931 const x7 = @truncate(u8, (x6 & 0xff));
2931 const x7 = @as(u8, @truncate((x6 & 0xff)));
29322932 const x8 = (x6 >> 8);
2933 const x9 = @truncate(u8, (x8 & 0xff));
2933 const x9 = @as(u8, @truncate((x8 & 0xff)));
29342934 const x10 = (x8 >> 8);
2935 const x11 = @truncate(u8, (x10 & 0xff));
2935 const x11 = @as(u8, @truncate((x10 & 0xff)));
29362936 const x12 = (x10 >> 8);
2937 const x13 = @truncate(u8, (x12 & 0xff));
2937 const x13 = @as(u8, @truncate((x12 & 0xff)));
29382938 const x14 = (x12 >> 8);
2939 const x15 = @truncate(u8, (x14 & 0xff));
2939 const x15 = @as(u8, @truncate((x14 & 0xff)));
29402940 const x16 = (x14 >> 8);
2941 const x17 = @truncate(u8, (x16 & 0xff));
2941 const x17 = @as(u8, @truncate((x16 & 0xff)));
29422942 const x18 = (x16 >> 8);
2943 const x19 = @truncate(u8, (x18 & 0xff));
2944 const x20 = @truncate(u8, (x18 >> 8));
2945 const x21 = @truncate(u8, (x5 & 0xff));
2943 const x19 = @as(u8, @truncate((x18 & 0xff)));
2944 const x20 = @as(u8, @truncate((x18 >> 8)));
2945 const x21 = @as(u8, @truncate((x5 & 0xff)));
29462946 const x22 = (x5 >> 8);
2947 const x23 = @truncate(u8, (x22 & 0xff));
2947 const x23 = @as(u8, @truncate((x22 & 0xff)));
29482948 const x24 = (x22 >> 8);
2949 const x25 = @truncate(u8, (x24 & 0xff));
2949 const x25 = @as(u8, @truncate((x24 & 0xff)));
29502950 const x26 = (x24 >> 8);
2951 const x27 = @truncate(u8, (x26 & 0xff));
2951 const x27 = @as(u8, @truncate((x26 & 0xff)));
29522952 const x28 = (x26 >> 8);
2953 const x29 = @truncate(u8, (x28 & 0xff));
2953 const x29 = @as(u8, @truncate((x28 & 0xff)));
29542954 const x30 = (x28 >> 8);
2955 const x31 = @truncate(u8, (x30 & 0xff));
2955 const x31 = @as(u8, @truncate((x30 & 0xff)));
29562956 const x32 = (x30 >> 8);
2957 const x33 = @truncate(u8, (x32 & 0xff));
2958 const x34 = @truncate(u8, (x32 >> 8));
2959 const x35 = @truncate(u8, (x4 & 0xff));
2957 const x33 = @as(u8, @truncate((x32 & 0xff)));
2958 const x34 = @as(u8, @truncate((x32 >> 8)));
2959 const x35 = @as(u8, @truncate((x4 & 0xff)));
29602960 const x36 = (x4 >> 8);
2961 const x37 = @truncate(u8, (x36 & 0xff));
2961 const x37 = @as(u8, @truncate((x36 & 0xff)));
29622962 const x38 = (x36 >> 8);
2963 const x39 = @truncate(u8, (x38 & 0xff));
2963 const x39 = @as(u8, @truncate((x38 & 0xff)));
29642964 const x40 = (x38 >> 8);
2965 const x41 = @truncate(u8, (x40 & 0xff));
2965 const x41 = @as(u8, @truncate((x40 & 0xff)));
29662966 const x42 = (x40 >> 8);
2967 const x43 = @truncate(u8, (x42 & 0xff));
2967 const x43 = @as(u8, @truncate((x42 & 0xff)));
29682968 const x44 = (x42 >> 8);
2969 const x45 = @truncate(u8, (x44 & 0xff));
2969 const x45 = @as(u8, @truncate((x44 & 0xff)));
29702970 const x46 = (x44 >> 8);
2971 const x47 = @truncate(u8, (x46 & 0xff));
2972 const x48 = @truncate(u8, (x46 >> 8));
2973 const x49 = @truncate(u8, (x3 & 0xff));
2971 const x47 = @as(u8, @truncate((x46 & 0xff)));
2972 const x48 = @as(u8, @truncate((x46 >> 8)));
2973 const x49 = @as(u8, @truncate((x3 & 0xff)));
29742974 const x50 = (x3 >> 8);
2975 const x51 = @truncate(u8, (x50 & 0xff));
2975 const x51 = @as(u8, @truncate((x50 & 0xff)));
29762976 const x52 = (x50 >> 8);
2977 const x53 = @truncate(u8, (x52 & 0xff));
2977 const x53 = @as(u8, @truncate((x52 & 0xff)));
29782978 const x54 = (x52 >> 8);
2979 const x55 = @truncate(u8, (x54 & 0xff));
2979 const x55 = @as(u8, @truncate((x54 & 0xff)));
29802980 const x56 = (x54 >> 8);
2981 const x57 = @truncate(u8, (x56 & 0xff));
2981 const x57 = @as(u8, @truncate((x56 & 0xff)));
29822982 const x58 = (x56 >> 8);
2983 const x59 = @truncate(u8, (x58 & 0xff));
2983 const x59 = @as(u8, @truncate((x58 & 0xff)));
29842984 const x60 = (x58 >> 8);
2985 const x61 = @truncate(u8, (x60 & 0xff));
2986 const x62 = @truncate(u8, (x60 >> 8));
2987 const x63 = @truncate(u8, (x2 & 0xff));
2985 const x61 = @as(u8, @truncate((x60 & 0xff)));
2986 const x62 = @as(u8, @truncate((x60 >> 8)));
2987 const x63 = @as(u8, @truncate((x2 & 0xff)));
29882988 const x64 = (x2 >> 8);
2989 const x65 = @truncate(u8, (x64 & 0xff));
2989 const x65 = @as(u8, @truncate((x64 & 0xff)));
29902990 const x66 = (x64 >> 8);
2991 const x67 = @truncate(u8, (x66 & 0xff));
2991 const x67 = @as(u8, @truncate((x66 & 0xff)));
29922992 const x68 = (x66 >> 8);
2993 const x69 = @truncate(u8, (x68 & 0xff));
2993 const x69 = @as(u8, @truncate((x68 & 0xff)));
29942994 const x70 = (x68 >> 8);
2995 const x71 = @truncate(u8, (x70 & 0xff));
2995 const x71 = @as(u8, @truncate((x70 & 0xff)));
29962996 const x72 = (x70 >> 8);
2997 const x73 = @truncate(u8, (x72 & 0xff));
2997 const x73 = @as(u8, @truncate((x72 & 0xff)));
29982998 const x74 = (x72 >> 8);
2999 const x75 = @truncate(u8, (x74 & 0xff));
3000 const x76 = @truncate(u8, (x74 >> 8));
3001 const x77 = @truncate(u8, (x1 & 0xff));
2999 const x75 = @as(u8, @truncate((x74 & 0xff)));
3000 const x76 = @as(u8, @truncate((x74 >> 8)));
3001 const x77 = @as(u8, @truncate((x1 & 0xff)));
30023002 const x78 = (x1 >> 8);
3003 const x79 = @truncate(u8, (x78 & 0xff));
3003 const x79 = @as(u8, @truncate((x78 & 0xff)));
30043004 const x80 = (x78 >> 8);
3005 const x81 = @truncate(u8, (x80 & 0xff));
3005 const x81 = @as(u8, @truncate((x80 & 0xff)));
30063006 const x82 = (x80 >> 8);
3007 const x83 = @truncate(u8, (x82 & 0xff));
3007 const x83 = @as(u8, @truncate((x82 & 0xff)));
30083008 const x84 = (x82 >> 8);
3009 const x85 = @truncate(u8, (x84 & 0xff));
3009 const x85 = @as(u8, @truncate((x84 & 0xff)));
30103010 const x86 = (x84 >> 8);
3011 const x87 = @truncate(u8, (x86 & 0xff));
3011 const x87 = @as(u8, @truncate((x86 & 0xff)));
30123012 const x88 = (x86 >> 8);
3013 const x89 = @truncate(u8, (x88 & 0xff));
3014 const x90 = @truncate(u8, (x88 >> 8));
3013 const x89 = @as(u8, @truncate((x88 & 0xff)));
3014 const x90 = @as(u8, @truncate((x88 >> 8)));
30153015 out1[0] = x7;
30163016 out1[1] = x9;
30173017 out1[2] = x11;
......@@ -3246,7 +3246,7 @@ pub fn divstep(out1: *u64, out2: *[7]u64, out3: *[7]u64, out4: *[6]u64, out5: *[
32463246 var x1: u64 = undefined;
32473247 var x2: u1 = undefined;
32483248 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))));
32503250 var x4: u64 = undefined;
32513251 var x5: u1 = undefined;
32523252 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: *[
34083408 cmovznzU64(&x102, x3, (arg5[4]), x94);
34093409 var x103: u64 = undefined;
34103410 cmovznzU64(&x103, x3, (arg5[5]), x96);
3411 const x104 = @truncate(u1, (x28 & 0x1));
3411 const x104 = @as(u1, @truncate((x28 & 0x1)));
34123412 var x105: u64 = undefined;
34133413 cmovznzU64(&x105, x104, 0x0, x7);
34143414 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 {
8888 @setRuntimeSafety(mode == .Debug);
8989
9090 const x = @as(u128, arg1) * @as(u128, arg2);
91 out1.* = @truncate(u64, x);
92 out2.* = @truncate(u64, x >> 64);
91 out1.* = @as(u64, @truncate(x));
92 out2.* = @as(u64, @truncate(x >> 64));
9393}
9494
9595/// The function cmovznzU64 is a single-word conditional move.
......@@ -2982,90 +2982,90 @@ pub fn toBytes(out1: *[48]u8, arg1: [6]u64) void {
29822982 const x4 = (arg1[2]);
29832983 const x5 = (arg1[1]);
29842984 const x6 = (arg1[0]);
2985 const x7 = @truncate(u8, (x6 & 0xff));
2985 const x7 = @as(u8, @truncate((x6 & 0xff)));
29862986 const x8 = (x6 >> 8);
2987 const x9 = @truncate(u8, (x8 & 0xff));
2987 const x9 = @as(u8, @truncate((x8 & 0xff)));
29882988 const x10 = (x8 >> 8);
2989 const x11 = @truncate(u8, (x10 & 0xff));
2989 const x11 = @as(u8, @truncate((x10 & 0xff)));
29902990 const x12 = (x10 >> 8);
2991 const x13 = @truncate(u8, (x12 & 0xff));
2991 const x13 = @as(u8, @truncate((x12 & 0xff)));
29922992 const x14 = (x12 >> 8);
2993 const x15 = @truncate(u8, (x14 & 0xff));
2993 const x15 = @as(u8, @truncate((x14 & 0xff)));
29942994 const x16 = (x14 >> 8);
2995 const x17 = @truncate(u8, (x16 & 0xff));
2995 const x17 = @as(u8, @truncate((x16 & 0xff)));
29962996 const x18 = (x16 >> 8);
2997 const x19 = @truncate(u8, (x18 & 0xff));
2998 const x20 = @truncate(u8, (x18 >> 8));
2999 const x21 = @truncate(u8, (x5 & 0xff));
2997 const x19 = @as(u8, @truncate((x18 & 0xff)));
2998 const x20 = @as(u8, @truncate((x18 >> 8)));
2999 const x21 = @as(u8, @truncate((x5 & 0xff)));
30003000 const x22 = (x5 >> 8);
3001 const x23 = @truncate(u8, (x22 & 0xff));
3001 const x23 = @as(u8, @truncate((x22 & 0xff)));
30023002 const x24 = (x22 >> 8);
3003 const x25 = @truncate(u8, (x24 & 0xff));
3003 const x25 = @as(u8, @truncate((x24 & 0xff)));
30043004 const x26 = (x24 >> 8);
3005 const x27 = @truncate(u8, (x26 & 0xff));
3005 const x27 = @as(u8, @truncate((x26 & 0xff)));
30063006 const x28 = (x26 >> 8);
3007 const x29 = @truncate(u8, (x28 & 0xff));
3007 const x29 = @as(u8, @truncate((x28 & 0xff)));
30083008 const x30 = (x28 >> 8);
3009 const x31 = @truncate(u8, (x30 & 0xff));
3009 const x31 = @as(u8, @truncate((x30 & 0xff)));
30103010 const x32 = (x30 >> 8);
3011 const x33 = @truncate(u8, (x32 & 0xff));
3012 const x34 = @truncate(u8, (x32 >> 8));
3013 const x35 = @truncate(u8, (x4 & 0xff));
3011 const x33 = @as(u8, @truncate((x32 & 0xff)));
3012 const x34 = @as(u8, @truncate((x32 >> 8)));
3013 const x35 = @as(u8, @truncate((x4 & 0xff)));
30143014 const x36 = (x4 >> 8);
3015 const x37 = @truncate(u8, (x36 & 0xff));
3015 const x37 = @as(u8, @truncate((x36 & 0xff)));
30163016 const x38 = (x36 >> 8);
3017 const x39 = @truncate(u8, (x38 & 0xff));
3017 const x39 = @as(u8, @truncate((x38 & 0xff)));
30183018 const x40 = (x38 >> 8);
3019 const x41 = @truncate(u8, (x40 & 0xff));
3019 const x41 = @as(u8, @truncate((x40 & 0xff)));
30203020 const x42 = (x40 >> 8);
3021 const x43 = @truncate(u8, (x42 & 0xff));
3021 const x43 = @as(u8, @truncate((x42 & 0xff)));
30223022 const x44 = (x42 >> 8);
3023 const x45 = @truncate(u8, (x44 & 0xff));
3023 const x45 = @as(u8, @truncate((x44 & 0xff)));
30243024 const x46 = (x44 >> 8);
3025 const x47 = @truncate(u8, (x46 & 0xff));
3026 const x48 = @truncate(u8, (x46 >> 8));
3027 const x49 = @truncate(u8, (x3 & 0xff));
3025 const x47 = @as(u8, @truncate((x46 & 0xff)));
3026 const x48 = @as(u8, @truncate((x46 >> 8)));
3027 const x49 = @as(u8, @truncate((x3 & 0xff)));
30283028 const x50 = (x3 >> 8);
3029 const x51 = @truncate(u8, (x50 & 0xff));
3029 const x51 = @as(u8, @truncate((x50 & 0xff)));
30303030 const x52 = (x50 >> 8);
3031 const x53 = @truncate(u8, (x52 & 0xff));
3031 const x53 = @as(u8, @truncate((x52 & 0xff)));
30323032 const x54 = (x52 >> 8);
3033 const x55 = @truncate(u8, (x54 & 0xff));
3033 const x55 = @as(u8, @truncate((x54 & 0xff)));
30343034 const x56 = (x54 >> 8);
3035 const x57 = @truncate(u8, (x56 & 0xff));
3035 const x57 = @as(u8, @truncate((x56 & 0xff)));
30363036 const x58 = (x56 >> 8);
3037 const x59 = @truncate(u8, (x58 & 0xff));
3037 const x59 = @as(u8, @truncate((x58 & 0xff)));
30383038 const x60 = (x58 >> 8);
3039 const x61 = @truncate(u8, (x60 & 0xff));
3040 const x62 = @truncate(u8, (x60 >> 8));
3041 const x63 = @truncate(u8, (x2 & 0xff));
3039 const x61 = @as(u8, @truncate((x60 & 0xff)));
3040 const x62 = @as(u8, @truncate((x60 >> 8)));
3041 const x63 = @as(u8, @truncate((x2 & 0xff)));
30423042 const x64 = (x2 >> 8);
3043 const x65 = @truncate(u8, (x64 & 0xff));
3043 const x65 = @as(u8, @truncate((x64 & 0xff)));
30443044 const x66 = (x64 >> 8);
3045 const x67 = @truncate(u8, (x66 & 0xff));
3045 const x67 = @as(u8, @truncate((x66 & 0xff)));
30463046 const x68 = (x66 >> 8);
3047 const x69 = @truncate(u8, (x68 & 0xff));
3047 const x69 = @as(u8, @truncate((x68 & 0xff)));
30483048 const x70 = (x68 >> 8);
3049 const x71 = @truncate(u8, (x70 & 0xff));
3049 const x71 = @as(u8, @truncate((x70 & 0xff)));
30503050 const x72 = (x70 >> 8);
3051 const x73 = @truncate(u8, (x72 & 0xff));
3051 const x73 = @as(u8, @truncate((x72 & 0xff)));
30523052 const x74 = (x72 >> 8);
3053 const x75 = @truncate(u8, (x74 & 0xff));
3054 const x76 = @truncate(u8, (x74 >> 8));
3055 const x77 = @truncate(u8, (x1 & 0xff));
3053 const x75 = @as(u8, @truncate((x74 & 0xff)));
3054 const x76 = @as(u8, @truncate((x74 >> 8)));
3055 const x77 = @as(u8, @truncate((x1 & 0xff)));
30563056 const x78 = (x1 >> 8);
3057 const x79 = @truncate(u8, (x78 & 0xff));
3057 const x79 = @as(u8, @truncate((x78 & 0xff)));
30583058 const x80 = (x78 >> 8);
3059 const x81 = @truncate(u8, (x80 & 0xff));
3059 const x81 = @as(u8, @truncate((x80 & 0xff)));
30603060 const x82 = (x80 >> 8);
3061 const x83 = @truncate(u8, (x82 & 0xff));
3061 const x83 = @as(u8, @truncate((x82 & 0xff)));
30623062 const x84 = (x82 >> 8);
3063 const x85 = @truncate(u8, (x84 & 0xff));
3063 const x85 = @as(u8, @truncate((x84 & 0xff)));
30643064 const x86 = (x84 >> 8);
3065 const x87 = @truncate(u8, (x86 & 0xff));
3065 const x87 = @as(u8, @truncate((x86 & 0xff)));
30663066 const x88 = (x86 >> 8);
3067 const x89 = @truncate(u8, (x88 & 0xff));
3068 const x90 = @truncate(u8, (x88 >> 8));
3067 const x89 = @as(u8, @truncate((x88 & 0xff)));
3068 const x90 = @as(u8, @truncate((x88 >> 8)));
30693069 out1[0] = x7;
30703070 out1[1] = x9;
30713071 out1[2] = x11;
......@@ -3300,7 +3300,7 @@ pub fn divstep(out1: *u64, out2: *[7]u64, out3: *[7]u64, out4: *[6]u64, out5: *[
33003300 var x1: u64 = undefined;
33013301 var x2: u1 = undefined;
33023302 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))));
33043304 var x4: u64 = undefined;
33053305 var x5: u1 = undefined;
33063306 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: *[
34623462 cmovznzU64(&x102, x3, (arg5[4]), x94);
34633463 var x103: u64 = undefined;
34643464 cmovznzU64(&x103, x3, (arg5[5]), x96);
3465 const x104 = @truncate(u1, (x28 & 0x1));
3465 const x104 = @as(u1, @truncate((x28 & 0x1)));
34663466 var x105: u64 = undefined;
34673467 cmovznzU64(&x105, x104, 0x0, x7);
34683468 var x106: u64 = undefined;
lib/std/crypto/pcurves/secp256k1.zig+16-16
......@@ -67,8 +67,8 @@ pub const Secp256k1 = struct {
6767 const t1 = math.mulWide(u256, k, 21949224512762693861512883645436906316123769664773102907882521278123970637873);
6868 const t2 = math.mulWide(u256, k, 103246583619904461035481197785446227098457807945486720222659797044629401272177);
6969
70 const c1 = @truncate(u128, t1 >> 384) + @truncate(u1, t1 >> 383);
71 const c2 = @truncate(u128, t2 >> 384) + @truncate(u1, t2 >> 383);
70 const c1 = @as(u128, @truncate(t1 >> 384)) + @as(u1, @truncate(t1 >> 383));
71 const c2 = @as(u128, @truncate(t2 >> 384)) + @as(u1, @truncate(t2 >> 383));
7272
7373 var buf: [32]u8 = undefined;
7474
......@@ -346,7 +346,7 @@ pub const Secp256k1 = struct {
346346 var t = Secp256k1.identityElement;
347347 comptime var i: u8 = 1;
348348 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)));
350350 }
351351 return t;
352352 }
......@@ -354,8 +354,8 @@ pub const Secp256k1 = struct {
354354 fn slide(s: [32]u8) [2 * 32 + 1]i8 {
355355 var e: [2 * 32 + 1]i8 = undefined;
356356 for (s, 0..) |x, i| {
357 e[i * 2 + 0] = @as(i8, @truncate(u4, x));
358 e[i * 2 + 1] = @as(i8, @truncate(u4, x >> 4));
357 e[i * 2 + 0] = @as(i8, @as(u4, @truncate(x)));
358 e[i * 2 + 1] = @as(i8, @as(u4, @truncate(x >> 4)));
359359 }
360360 // Now, e[0..63] is between 0 and 15, e[63] is between 0 and 7
361361 var carry: i8 = 0;
......@@ -379,9 +379,9 @@ pub const Secp256k1 = struct {
379379 while (true) : (pos -= 1) {
380380 const slot = e[pos];
381381 if (slot > 0) {
382 q = q.add(pc[@intCast(usize, slot)]);
382 q = q.add(pc[@as(usize, @intCast(slot))]);
383383 } else if (slot < 0) {
384 q = q.sub(pc[@intCast(usize, -slot)]);
384 q = q.sub(pc[@as(usize, @intCast(-slot))]);
385385 }
386386 if (pos == 0) break;
387387 q = q.dbl().dbl().dbl().dbl();
......@@ -394,7 +394,7 @@ pub const Secp256k1 = struct {
394394 var q = Secp256k1.identityElement;
395395 var pos: usize = 252;
396396 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)))));
398398 if (vartime) {
399399 if (slot != 0) {
400400 q = q.add(pc[slot]);
......@@ -482,15 +482,15 @@ pub const Secp256k1 = struct {
482482 while (true) : (pos -= 1) {
483483 const slot1 = e1[pos];
484484 if (slot1 > 0) {
485 q = q.add(pc1[@intCast(usize, slot1)]);
485 q = q.add(pc1[@as(usize, @intCast(slot1))]);
486486 } else if (slot1 < 0) {
487 q = q.sub(pc1[@intCast(usize, -slot1)]);
487 q = q.sub(pc1[@as(usize, @intCast(-slot1))]);
488488 }
489489 const slot2 = e2[pos];
490490 if (slot2 > 0) {
491 q = q.add(pc2[@intCast(usize, slot2)]);
491 q = q.add(pc2[@as(usize, @intCast(slot2))]);
492492 } else if (slot2 < 0) {
493 q = q.sub(pc2[@intCast(usize, -slot2)]);
493 q = q.sub(pc2[@as(usize, @intCast(-slot2))]);
494494 }
495495 if (pos == 0) break;
496496 q = q.dbl().dbl().dbl().dbl();
......@@ -523,15 +523,15 @@ pub const Secp256k1 = struct {
523523 while (true) : (pos -= 1) {
524524 const slot1 = e1[pos];
525525 if (slot1 > 0) {
526 q = q.add(pc1[@intCast(usize, slot1)]);
526 q = q.add(pc1[@as(usize, @intCast(slot1))]);
527527 } else if (slot1 < 0) {
528 q = q.sub(pc1[@intCast(usize, -slot1)]);
528 q = q.sub(pc1[@as(usize, @intCast(-slot1))]);
529529 }
530530 const slot2 = e2[pos];
531531 if (slot2 > 0) {
532 q = q.add(pc2[@intCast(usize, slot2)]);
532 q = q.add(pc2[@as(usize, @intCast(slot2))]);
533533 } else if (slot2 < 0) {
534 q = q.sub(pc2[@intCast(usize, -slot2)]);
534 q = q.sub(pc2[@as(usize, @intCast(-slot2))]);
535535 }
536536 if (pos == 0) break;
537537 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 {
8888 @setRuntimeSafety(mode == .Debug);
8989
9090 const x = @as(u128, arg1) * @as(u128, arg2);
91 out1.* = @truncate(u64, x);
92 out2.* = @truncate(u64, x >> 64);
91 out1.* = @as(u64, @truncate(x));
92 out2.* = @as(u64, @truncate(x >> 64));
9393}
9494
9595/// The function cmovznzU64 is a single-word conditional move.
......@@ -1488,62 +1488,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {
14881488 const x2 = (arg1[2]);
14891489 const x3 = (arg1[1]);
14901490 const x4 = (arg1[0]);
1491 const x5 = @truncate(u8, (x4 & 0xff));
1491 const x5 = @as(u8, @truncate((x4 & 0xff)));
14921492 const x6 = (x4 >> 8);
1493 const x7 = @truncate(u8, (x6 & 0xff));
1493 const x7 = @as(u8, @truncate((x6 & 0xff)));
14941494 const x8 = (x6 >> 8);
1495 const x9 = @truncate(u8, (x8 & 0xff));
1495 const x9 = @as(u8, @truncate((x8 & 0xff)));
14961496 const x10 = (x8 >> 8);
1497 const x11 = @truncate(u8, (x10 & 0xff));
1497 const x11 = @as(u8, @truncate((x10 & 0xff)));
14981498 const x12 = (x10 >> 8);
1499 const x13 = @truncate(u8, (x12 & 0xff));
1499 const x13 = @as(u8, @truncate((x12 & 0xff)));
15001500 const x14 = (x12 >> 8);
1501 const x15 = @truncate(u8, (x14 & 0xff));
1501 const x15 = @as(u8, @truncate((x14 & 0xff)));
15021502 const x16 = (x14 >> 8);
1503 const x17 = @truncate(u8, (x16 & 0xff));
1504 const x18 = @truncate(u8, (x16 >> 8));
1505 const x19 = @truncate(u8, (x3 & 0xff));
1503 const x17 = @as(u8, @truncate((x16 & 0xff)));
1504 const x18 = @as(u8, @truncate((x16 >> 8)));
1505 const x19 = @as(u8, @truncate((x3 & 0xff)));
15061506 const x20 = (x3 >> 8);
1507 const x21 = @truncate(u8, (x20 & 0xff));
1507 const x21 = @as(u8, @truncate((x20 & 0xff)));
15081508 const x22 = (x20 >> 8);
1509 const x23 = @truncate(u8, (x22 & 0xff));
1509 const x23 = @as(u8, @truncate((x22 & 0xff)));
15101510 const x24 = (x22 >> 8);
1511 const x25 = @truncate(u8, (x24 & 0xff));
1511 const x25 = @as(u8, @truncate((x24 & 0xff)));
15121512 const x26 = (x24 >> 8);
1513 const x27 = @truncate(u8, (x26 & 0xff));
1513 const x27 = @as(u8, @truncate((x26 & 0xff)));
15141514 const x28 = (x26 >> 8);
1515 const x29 = @truncate(u8, (x28 & 0xff));
1515 const x29 = @as(u8, @truncate((x28 & 0xff)));
15161516 const x30 = (x28 >> 8);
1517 const x31 = @truncate(u8, (x30 & 0xff));
1518 const x32 = @truncate(u8, (x30 >> 8));
1519 const x33 = @truncate(u8, (x2 & 0xff));
1517 const x31 = @as(u8, @truncate((x30 & 0xff)));
1518 const x32 = @as(u8, @truncate((x30 >> 8)));
1519 const x33 = @as(u8, @truncate((x2 & 0xff)));
15201520 const x34 = (x2 >> 8);
1521 const x35 = @truncate(u8, (x34 & 0xff));
1521 const x35 = @as(u8, @truncate((x34 & 0xff)));
15221522 const x36 = (x34 >> 8);
1523 const x37 = @truncate(u8, (x36 & 0xff));
1523 const x37 = @as(u8, @truncate((x36 & 0xff)));
15241524 const x38 = (x36 >> 8);
1525 const x39 = @truncate(u8, (x38 & 0xff));
1525 const x39 = @as(u8, @truncate((x38 & 0xff)));
15261526 const x40 = (x38 >> 8);
1527 const x41 = @truncate(u8, (x40 & 0xff));
1527 const x41 = @as(u8, @truncate((x40 & 0xff)));
15281528 const x42 = (x40 >> 8);
1529 const x43 = @truncate(u8, (x42 & 0xff));
1529 const x43 = @as(u8, @truncate((x42 & 0xff)));
15301530 const x44 = (x42 >> 8);
1531 const x45 = @truncate(u8, (x44 & 0xff));
1532 const x46 = @truncate(u8, (x44 >> 8));
1533 const x47 = @truncate(u8, (x1 & 0xff));
1531 const x45 = @as(u8, @truncate((x44 & 0xff)));
1532 const x46 = @as(u8, @truncate((x44 >> 8)));
1533 const x47 = @as(u8, @truncate((x1 & 0xff)));
15341534 const x48 = (x1 >> 8);
1535 const x49 = @truncate(u8, (x48 & 0xff));
1535 const x49 = @as(u8, @truncate((x48 & 0xff)));
15361536 const x50 = (x48 >> 8);
1537 const x51 = @truncate(u8, (x50 & 0xff));
1537 const x51 = @as(u8, @truncate((x50 & 0xff)));
15381538 const x52 = (x50 >> 8);
1539 const x53 = @truncate(u8, (x52 & 0xff));
1539 const x53 = @as(u8, @truncate((x52 & 0xff)));
15401540 const x54 = (x52 >> 8);
1541 const x55 = @truncate(u8, (x54 & 0xff));
1541 const x55 = @as(u8, @truncate((x54 & 0xff)));
15421542 const x56 = (x54 >> 8);
1543 const x57 = @truncate(u8, (x56 & 0xff));
1543 const x57 = @as(u8, @truncate((x56 & 0xff)));
15441544 const x58 = (x56 >> 8);
1545 const x59 = @truncate(u8, (x58 & 0xff));
1546 const x60 = @truncate(u8, (x58 >> 8));
1545 const x59 = @as(u8, @truncate((x58 & 0xff)));
1546 const x60 = @as(u8, @truncate((x58 >> 8)));
15471547 out1[0] = x5;
15481548 out1[1] = x7;
15491549 out1[2] = x9;
......@@ -1726,7 +1726,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
17261726 var x1: u64 = undefined;
17271727 var x2: u1 = undefined;
17281728 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))));
17301730 var x4: u64 = undefined;
17311731 var x5: u1 = undefined;
17321732 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: *[
18401840 cmovznzU64(&x72, x3, (arg5[2]), x66);
18411841 var x73: u64 = undefined;
18421842 cmovznzU64(&x73, x3, (arg5[3]), x68);
1843 const x74 = @truncate(u1, (x22 & 0x1));
1843 const x74 = @as(u1, @truncate((x22 & 0x1)));
18441844 var x75: u64 = undefined;
18451845 cmovznzU64(&x75, x74, 0x0, x7);
18461846 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 {
8888 @setRuntimeSafety(mode == .Debug);
8989
9090 const x = @as(u128, arg1) * @as(u128, arg2);
91 out1.* = @truncate(u64, x);
92 out2.* = @truncate(u64, x >> 64);
91 out1.* = @as(u64, @truncate(x));
92 out2.* = @as(u64, @truncate(x >> 64));
9393}
9494
9595/// The function cmovznzU64 is a single-word conditional move.
......@@ -1548,62 +1548,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {
15481548 const x2 = (arg1[2]);
15491549 const x3 = (arg1[1]);
15501550 const x4 = (arg1[0]);
1551 const x5 = @truncate(u8, (x4 & 0xff));
1551 const x5 = @as(u8, @truncate((x4 & 0xff)));
15521552 const x6 = (x4 >> 8);
1553 const x7 = @truncate(u8, (x6 & 0xff));
1553 const x7 = @as(u8, @truncate((x6 & 0xff)));
15541554 const x8 = (x6 >> 8);
1555 const x9 = @truncate(u8, (x8 & 0xff));
1555 const x9 = @as(u8, @truncate((x8 & 0xff)));
15561556 const x10 = (x8 >> 8);
1557 const x11 = @truncate(u8, (x10 & 0xff));
1557 const x11 = @as(u8, @truncate((x10 & 0xff)));
15581558 const x12 = (x10 >> 8);
1559 const x13 = @truncate(u8, (x12 & 0xff));
1559 const x13 = @as(u8, @truncate((x12 & 0xff)));
15601560 const x14 = (x12 >> 8);
1561 const x15 = @truncate(u8, (x14 & 0xff));
1561 const x15 = @as(u8, @truncate((x14 & 0xff)));
15621562 const x16 = (x14 >> 8);
1563 const x17 = @truncate(u8, (x16 & 0xff));
1564 const x18 = @truncate(u8, (x16 >> 8));
1565 const x19 = @truncate(u8, (x3 & 0xff));
1563 const x17 = @as(u8, @truncate((x16 & 0xff)));
1564 const x18 = @as(u8, @truncate((x16 >> 8)));
1565 const x19 = @as(u8, @truncate((x3 & 0xff)));
15661566 const x20 = (x3 >> 8);
1567 const x21 = @truncate(u8, (x20 & 0xff));
1567 const x21 = @as(u8, @truncate((x20 & 0xff)));
15681568 const x22 = (x20 >> 8);
1569 const x23 = @truncate(u8, (x22 & 0xff));
1569 const x23 = @as(u8, @truncate((x22 & 0xff)));
15701570 const x24 = (x22 >> 8);
1571 const x25 = @truncate(u8, (x24 & 0xff));
1571 const x25 = @as(u8, @truncate((x24 & 0xff)));
15721572 const x26 = (x24 >> 8);
1573 const x27 = @truncate(u8, (x26 & 0xff));
1573 const x27 = @as(u8, @truncate((x26 & 0xff)));
15741574 const x28 = (x26 >> 8);
1575 const x29 = @truncate(u8, (x28 & 0xff));
1575 const x29 = @as(u8, @truncate((x28 & 0xff)));
15761576 const x30 = (x28 >> 8);
1577 const x31 = @truncate(u8, (x30 & 0xff));
1578 const x32 = @truncate(u8, (x30 >> 8));
1579 const x33 = @truncate(u8, (x2 & 0xff));
1577 const x31 = @as(u8, @truncate((x30 & 0xff)));
1578 const x32 = @as(u8, @truncate((x30 >> 8)));
1579 const x33 = @as(u8, @truncate((x2 & 0xff)));
15801580 const x34 = (x2 >> 8);
1581 const x35 = @truncate(u8, (x34 & 0xff));
1581 const x35 = @as(u8, @truncate((x34 & 0xff)));
15821582 const x36 = (x34 >> 8);
1583 const x37 = @truncate(u8, (x36 & 0xff));
1583 const x37 = @as(u8, @truncate((x36 & 0xff)));
15841584 const x38 = (x36 >> 8);
1585 const x39 = @truncate(u8, (x38 & 0xff));
1585 const x39 = @as(u8, @truncate((x38 & 0xff)));
15861586 const x40 = (x38 >> 8);
1587 const x41 = @truncate(u8, (x40 & 0xff));
1587 const x41 = @as(u8, @truncate((x40 & 0xff)));
15881588 const x42 = (x40 >> 8);
1589 const x43 = @truncate(u8, (x42 & 0xff));
1589 const x43 = @as(u8, @truncate((x42 & 0xff)));
15901590 const x44 = (x42 >> 8);
1591 const x45 = @truncate(u8, (x44 & 0xff));
1592 const x46 = @truncate(u8, (x44 >> 8));
1593 const x47 = @truncate(u8, (x1 & 0xff));
1591 const x45 = @as(u8, @truncate((x44 & 0xff)));
1592 const x46 = @as(u8, @truncate((x44 >> 8)));
1593 const x47 = @as(u8, @truncate((x1 & 0xff)));
15941594 const x48 = (x1 >> 8);
1595 const x49 = @truncate(u8, (x48 & 0xff));
1595 const x49 = @as(u8, @truncate((x48 & 0xff)));
15961596 const x50 = (x48 >> 8);
1597 const x51 = @truncate(u8, (x50 & 0xff));
1597 const x51 = @as(u8, @truncate((x50 & 0xff)));
15981598 const x52 = (x50 >> 8);
1599 const x53 = @truncate(u8, (x52 & 0xff));
1599 const x53 = @as(u8, @truncate((x52 & 0xff)));
16001600 const x54 = (x52 >> 8);
1601 const x55 = @truncate(u8, (x54 & 0xff));
1601 const x55 = @as(u8, @truncate((x54 & 0xff)));
16021602 const x56 = (x54 >> 8);
1603 const x57 = @truncate(u8, (x56 & 0xff));
1603 const x57 = @as(u8, @truncate((x56 & 0xff)));
16041604 const x58 = (x56 >> 8);
1605 const x59 = @truncate(u8, (x58 & 0xff));
1606 const x60 = @truncate(u8, (x58 >> 8));
1605 const x59 = @as(u8, @truncate((x58 & 0xff)));
1606 const x60 = @as(u8, @truncate((x58 >> 8)));
16071607 out1[0] = x5;
16081608 out1[1] = x7;
16091609 out1[2] = x9;
......@@ -1786,7 +1786,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
17861786 var x1: u64 = undefined;
17871787 var x2: u1 = undefined;
17881788 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))));
17901790 var x4: u64 = undefined;
17911791 var x5: u1 = undefined;
17921792 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: *[
19001900 cmovznzU64(&x72, x3, (arg5[2]), x66);
19011901 var x73: u64 = undefined;
19021902 cmovznzU64(&x73, x3, (arg5[3]), x68);
1903 const x74 = @truncate(u1, (x22 & 0x1));
1903 const x74 = @as(u1, @truncate((x22 & 0x1)));
19041904 var x75: u64 = undefined;
19051905 cmovznzU64(&x75, x74, 0x0, x7);
19061906 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 {
193193pub fn calcSize(params: anytype) usize {
194194 var buf = io.countingWriter(io.null_writer);
195195 serializeTo(params, buf.writer()) catch unreachable;
196 return @intCast(usize, buf.bytes_written);
196 return @as(usize, @intCast(buf.bytes_written));
197197}
198198
199199fn serializeTo(params: anytype, out: anytype) !void {
lib/std/crypto/poly1305.zig+7-7
......@@ -76,12 +76,12 @@ pub const Poly1305 = struct {
7676 const m1 = h1r0 +% h0r1;
7777 const m2 = h2r0 +% h1r1;
7878
79 const t0 = @truncate(u64, m0);
80 v = @addWithOverflow(@truncate(u64, m1), @truncate(u64, m0 >> 64));
79 const t0 = @as(u64, @truncate(m0));
80 v = @addWithOverflow(@as(u64, @truncate(m1)), @as(u64, @truncate(m0 >> 64)));
8181 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]);
8383 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]);
8585 const t3 = v[0];
8686
8787 // Partial reduction
......@@ -98,9 +98,9 @@ pub const Poly1305 = struct {
9898 h1 = v[0];
9999 h2 +%= v[1];
100100 const cc = (cclo | (@as(u128, cchi) << 64)) >> 2;
101 v = @addWithOverflow(h0, @truncate(u64, cc));
101 v = @addWithOverflow(h0, @as(u64, @truncate(cc)));
102102 h0 = v[0];
103 v = add(h1, @truncate(u64, cc >> 64), v[1]);
103 v = add(h1, @as(u64, @truncate(cc >> 64)), v[1]);
104104 h1 = v[0];
105105 h2 +%= v[1];
106106 }
......@@ -185,7 +185,7 @@ pub const Poly1305 = struct {
185185 mem.writeIntLittle(u64, out[0..8], st.h[0]);
186186 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)]);
189189 }
190190
191191 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 {
337337 var d: [4]u32 = undefined;
338338 d[0] = mem.readIntLittle(u32, nonce[0..4]);
339339 d[1] = mem.readIntLittle(u32, nonce[4..8]);
340 d[2] = @truncate(u32, counter);
341 d[3] = @truncate(u32, counter >> 32);
340 d[2] = @as(u32, @truncate(counter));
341 d[3] = @as(u32, @truncate(counter >> 32));
342342 SalsaImpl(rounds).salsaXor(out, in, keyToWords(key), d);
343343 }
344344 };
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)
7373}
7474
7575fn 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);
7777 var i: usize = 0;
7878 while (i < 2 * r) : (i += 2) {
79 salsaXor(tmp, @alignCast(16, in[i * 16 ..]), @alignCast(16, out[i * 8 ..]));
80 salsaXor(tmp, @alignCast(16, in[i * 16 + 16 ..]), @alignCast(16, out[i * 8 + r * 16 ..]));
79 salsaXor(tmp, @alignCast(in[i * 16 ..]), @alignCast(out[i * 8 ..]));
80 salsaXor(tmp, @alignCast(in[i * 16 + 16 ..]), @alignCast(out[i * 8 + r * 16 ..]));
8181 }
8282}
8383
......@@ -87,8 +87,8 @@ fn integerify(b: []align(16) const u32, r: u30) u64 {
8787}
8888
8989fn 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]);
91 var y = @alignCast(16, xy[32 * r ..]);
90 var x: []align(16) u32 = @alignCast(xy[0 .. 32 * r]);
91 var y: []align(16) u32 = @alignCast(xy[32 * r ..]);
9292
9393 for (x, 0..) |*v1, j| {
9494 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)
9797 var tmp: [16]u32 align(16) = undefined;
9898 var i: usize = 0;
9999 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);
101101 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);
104104 blockMix(&tmp, y, x, r);
105105 }
106106
107107 i = 0;
108108 while (i < n) : (i += 2) {
109 var j = @intCast(usize, integerify(x, r) & (n - 1));
110 blockXor(x, @alignCast(16, v[j * (32 * r) ..]), 2 * r);
109 var j = @as(usize, @intCast(integerify(x, r) & (n - 1)));
110 blockXor(x, @alignCast(v[j * (32 * r) ..]), 2 * r);
111111 blockMix(&tmp, x, y, r);
112112
113 j = @intCast(usize, integerify(y, r) & (n - 1));
114 blockXor(y, @alignCast(16, v[j * (32 * r) ..]), 2 * r);
113 j = @as(usize, @intCast(integerify(y, r) & (n - 1)));
114 blockXor(y, @alignCast(v[j * (32 * r) ..]), 2 * r);
115115 blockMix(&tmp, y, x, r);
116116 }
117117
......@@ -147,12 +147,12 @@ pub const Params = struct {
147147 const r: u30 = 8;
148148 if (ops < mem_limit / 32) {
149149 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))) };
151151 } else {
152 const max_n = mem_limit / (@intCast(usize, r) * 128);
153 const ln = @intCast(u6, math.log2(max_n));
152 const max_n = mem_limit / (@as(usize, @intCast(r)) * 128);
153 const ln = @as(u6, @intCast(math.log2(max_n)));
154154 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 };
156156 }
157157 }
158158};
......@@ -185,7 +185,7 @@ pub fn kdf(
185185
186186 const n64 = @as(u64, 1) << params.ln;
187187 if (n64 > max_size) return KdfError.WeakParameters;
188 const n = @intCast(usize, n64);
188 const n = @as(usize, @intCast(n64));
189189 if (@as(u64, params.r) * @as(u64, params.p) >= 1 << 30 or
190190 params.r > max_int / 128 / @as(u64, params.p) or
191191 params.r > max_int / 256 or
......@@ -201,7 +201,7 @@ pub fn kdf(
201201 try pwhash.pbkdf2(dk, password, salt, 1, HmacSha256);
202202 var i: u32 = 0;
203203 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);
205205 }
206206 try pwhash.pbkdf2(derived_key, password, dk, 1, HmacSha256);
207207}
......@@ -309,7 +309,7 @@ const crypt_format = struct {
309309 pub fn calcSize(params: anytype) usize {
310310 var buf = io.countingWriter(io.null_writer);
311311 serializeTo(params, buf.writer()) catch unreachable;
312 return @intCast(usize, buf.bytes_written);
312 return @as(usize, @intCast(buf.bytes_written));
313313 }
314314
315315 fn serializeTo(params: anytype, out: anytype) !void {
......@@ -343,7 +343,7 @@ const crypt_format = struct {
343343 fn intEncode(dst: []u8, src: anytype) void {
344344 var n = src;
345345 for (dst) |*x| {
346 x.* = map64[@truncate(u6, n)];
346 x.* = map64[@as(u6, @truncate(n))];
347347 n = math.shr(@TypeOf(src), n, 6);
348348 }
349349 }
......@@ -352,7 +352,7 @@ const crypt_format = struct {
352352 var v: T = 0;
353353 for (src, 0..) |x, i| {
354354 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));
356356 }
357357 return v;
358358 }
......@@ -366,10 +366,10 @@ const crypt_format = struct {
366366 const leftover = src[i * 4 ..];
367367 var v: u24 = 0;
368368 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));
370370 }
371371 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))));
373373 }
374374 }
375375
......@@ -382,7 +382,7 @@ const crypt_format = struct {
382382 const leftover = src[i * 3 ..];
383383 var v: u24 = 0;
384384 for (leftover, 0..) |x, j| {
385 v |= @as(u24, x) << @intCast(u5, j * 8);
385 v |= @as(u24, x) << @as(u5, @intCast(j * 8));
386386 }
387387 intEncode(dst[i * 4 ..], v);
388388 }
lib/std/crypto/sha1.zig+3-3
......@@ -75,7 +75,7 @@ pub const Sha1 = struct {
7575
7676 // Copy any remainder for next pass.
7777 @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
8080 d.total_len += b.len;
8181 }
......@@ -97,9 +97,9 @@ pub const Sha1 = struct {
9797 // Append message length.
9898 var i: usize = 1;
9999 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;
101101 while (i < 8) : (i += 1) {
102 d.buf[63 - i] = @intCast(u8, len & 0xff);
102 d.buf[63 - i] = @as(u8, @intCast(len & 0xff));
103103 len >>= 8;
104104 }
105105
lib/std/crypto/sha2.zig+10-10
......@@ -132,7 +132,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
132132 // Copy any remainder for next pass.
133133 const b_slice = b[off..];
134134 @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
137137 d.total_len += b.len;
138138 }
......@@ -159,9 +159,9 @@ fn Sha2x32(comptime params: Sha2Params32) type {
159159 // Append message length.
160160 var i: usize = 1;
161161 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;
163163 while (i < 8) : (i += 1) {
164 d.buf[63 - i] = @intCast(u8, len & 0xff);
164 d.buf[63 - i] = @as(u8, @intCast(len & 0xff));
165165 len >>= 8;
166166 }
167167
......@@ -194,7 +194,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
194194
195195 fn round(d: *Self, b: *const [64]u8) void {
196196 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| {
198198 s[i] = mem.readIntBig(u32, mem.asBytes(elem));
199199 }
200200
......@@ -203,7 +203,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
203203 .aarch64 => if (builtin.zig_backend != .stage2_c and comptime std.Target.aarch64.featureSetHas(builtin.cpu.features, .sha2)) {
204204 var x: v4u32 = d.s[0..4].*;
205205 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
208208 comptime var k: u8 = 0;
209209 inline while (k < 16) : (k += 1) {
......@@ -241,7 +241,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
241241 .x86_64 => if (builtin.zig_backend != .stage2_c and comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sha)) {
242242 var x: v4u32 = [_]u32{ d.s[5], d.s[4], d.s[1], d.s[0] };
243243 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
246246 comptime var k: u8 = 0;
247247 inline while (k < 16) : (k += 1) {
......@@ -273,7 +273,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
273273 : [x] "=x" (-> v4u32),
274274 : [_] "0" (x),
275275 [y] "x" (y),
276 [_] "{xmm0}" (@bitCast(v4u32, @bitCast(u128, w) >> 64)),
276 [_] "{xmm0}" (@as(v4u32, @bitCast(@as(u128, @bitCast(w)) >> 64))),
277277 );
278278 }
279279
......@@ -624,7 +624,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
624624 // Copy any remainder for next pass.
625625 const b_slice = b[off..];
626626 @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
629629 d.total_len += b.len;
630630 }
......@@ -651,9 +651,9 @@ fn Sha2x64(comptime params: Sha2Params64) type {
651651 // Append message length.
652652 var i: usize = 1;
653653 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;
655655 while (i < 16) : (i += 1) {
656 d.buf[127 - i] = @intCast(u8, len & 0xff);
656 d.buf[127 - i] = @as(u8, @intCast(len & 0xff));
657657 len >>= 8;
658658 }
659659
lib/std/crypto/siphash.zig+6-6
......@@ -83,13 +83,13 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round
8383 @call(.always_inline, round, .{ self, blob });
8484 }
8585
86 self.msg_len +%= @truncate(u8, b.len);
86 self.msg_len +%= @as(u8, @truncate(b.len));
8787 }
8888
8989 fn final(self: *Self, b: []const u8) T {
9090 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
9494 var buf = [_]u8{0} ** 8;
9595 @memcpy(buf[0..b.len], b);
......@@ -202,7 +202,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
202202
203203 const b_slice = b[off + aligned_len ..];
204204 @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));
206206 }
207207
208208 pub fn peek(self: Self) [mac_length]u8 {
......@@ -329,7 +329,7 @@ test "siphash64-2-4 sanity" {
329329
330330 var buffer: [64]u8 = undefined;
331331 for (vectors, 0..) |vector, i| {
332 buffer[i] = @intCast(u8, i);
332 buffer[i] = @as(u8, @intCast(i));
333333
334334 var out: [siphash.mac_length]u8 = undefined;
335335 siphash.create(&out, buffer[0..i], test_key);
......@@ -409,7 +409,7 @@ test "siphash128-2-4 sanity" {
409409
410410 var buffer: [64]u8 = undefined;
411411 for (vectors, 0..) |vector, i| {
412 buffer[i] = @intCast(u8, i);
412 buffer[i] = @as(u8, @intCast(i));
413413
414414 var out: [siphash.mac_length]u8 = undefined;
415415 siphash.create(&out, buffer[0..i], test_key[0..]);
......@@ -420,7 +420,7 @@ test "siphash128-2-4 sanity" {
420420test "iterative non-divisible update" {
421421 var buf: [1024]u8 = undefined;
422422 for (&buf, 0..) |*e, i| {
423 e.* = @truncate(u8, i);
423 e.* = @as(u8, @truncate(i));
424424 }
425425
426426 const key = "0x128dad08f12307";
lib/std/crypto/tlcsprng.zig+3-3
......@@ -102,7 +102,7 @@ fn tlsCsprngFill(_: *anyopaque, buffer: []u8) void {
102102 wipe_mem = mem.asBytes(&S.buf);
103103 }
104104 }
105 const ctx = @ptrCast(*Context, wipe_mem.ptr);
105 const ctx = @as(*Context, @ptrCast(wipe_mem.ptr));
106106
107107 switch (ctx.init_state) {
108108 .uninitialized => {
......@@ -158,7 +158,7 @@ fn childAtForkHandler() callconv(.C) void {
158158}
159159
160160fn fillWithCsprng(buffer: []u8) void {
161 const ctx = @ptrCast(*Context, wipe_mem.ptr);
161 const ctx = @as(*Context, @ptrCast(wipe_mem.ptr));
162162 return ctx.rng.fill(buffer);
163163}
164164
......@@ -174,7 +174,7 @@ fn initAndFill(buffer: []u8) void {
174174 // the `std.options.cryptoRandomSeed` function is provided.
175175 std.options.cryptoRandomSeed(&seed);
176176
177 const ctx = @ptrCast(*Context, wipe_mem.ptr);
177 const ctx = @as(*Context, @ptrCast(wipe_mem.ptr));
178178 ctx.rng = Rng.init(seed);
179179 std.crypto.utils.secureZero(u8, &seed);
180180
lib/std/crypto/tls.zig+10-10
......@@ -371,12 +371,12 @@ pub fn hkdfExpandLabel(
371371 const tls13 = "tls13 ";
372372 var buf: [2 + 1 + tls13.len + max_label_len + 1 + max_context_len]u8 = undefined;
373373 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));
375375 buf[3..][0..tls13.len].* = tls13.*;
376376 var i: usize = 3 + tls13.len;
377377 @memcpy(buf[i..][0..label.len], label);
378378 i += label.len;
379 buf[i] = @intCast(u8, context.len);
379 buf[i] = @as(u8, @intCast(context.len));
380380 i += 1;
381381 @memcpy(buf[i..][0..context.len], context);
382382 i += context.len;
......@@ -411,24 +411,24 @@ pub inline fn enum_array(comptime E: type, comptime tags: []const E) [2 + @sizeO
411411 assert(@sizeOf(E) == 2);
412412 var result: [tags.len * 2]u8 = undefined;
413413 for (tags, 0..) |elem, i| {
414 result[i * 2] = @truncate(u8, @intFromEnum(elem) >> 8);
415 result[i * 2 + 1] = @truncate(u8, @intFromEnum(elem));
414 result[i * 2] = @as(u8, @truncate(@intFromEnum(elem) >> 8));
415 result[i * 2 + 1] = @as(u8, @truncate(@intFromEnum(elem)));
416416 }
417417 return array(2, result);
418418}
419419
420420pub inline fn int2(x: u16) [2]u8 {
421421 return .{
422 @truncate(u8, x >> 8),
423 @truncate(u8, x),
422 @as(u8, @truncate(x >> 8)),
423 @as(u8, @truncate(x)),
424424 };
425425}
426426
427427pub inline fn int3(x: u24) [3]u8 {
428428 return .{
429 @truncate(u8, x >> 16),
430 @truncate(u8, x >> 8),
431 @truncate(u8, x),
429 @as(u8, @truncate(x >> 16)),
430 @as(u8, @truncate(x >> 8)),
431 @as(u8, @truncate(x)),
432432 };
433433}
434434
......@@ -513,7 +513,7 @@ pub const Decoder = struct {
513513 .Enum => |info| {
514514 const int = d.decode(info.tag_type);
515515 if (info.is_exhaustive) @compileError("exhaustive enum cannot be used");
516 return @enumFromInt(T, int);
516 return @as(T, @enumFromInt(int));
517517 },
518518 else => @compileError("unsupported type: " ++ @typeName(T)),
519519 }
lib/std/crypto/tls/Client.zig+28-28
......@@ -140,7 +140,7 @@ pub fn InitError(comptime Stream: type) type {
140140///
141141/// `host` is only borrowed during this function call.
142142pub 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
145145 var random_buffer: [128]u8 = undefined;
146146 crypto.random.bytes(&random_buffer);
......@@ -194,7 +194,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
194194 int2(host_len);
195195
196196 const extensions_header =
197 int2(@intCast(u16, extensions_payload.len + host_len)) ++
197 int2(@as(u16, @intCast(extensions_payload.len + host_len))) ++
198198 extensions_payload;
199199
200200 const legacy_compression_methods = 0x0100;
......@@ -209,13 +209,13 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
209209
210210 const out_handshake =
211211 [_]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))) ++
213213 client_hello;
214214
215215 const plaintext_header = [_]u8{
216216 @intFromEnum(tls.ContentType.handshake),
217217 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
220220 {
221221 var iovecs = [_]std.os.iovec_const{
......@@ -457,7 +457,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
457457 const auth_tag = record_decoder.array(P.AEAD.tag_length).*;
458458 const V = @Vector(P.AEAD.nonce_length, u8);
459459 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)));
461461 read_seq += 1;
462462 const nonce = @as(V, p.server_handshake_iv) ^ operand;
463463 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
466466 },
467467 };
468468
469 const inner_ct = @enumFromInt(tls.ContentType, cleartext[cleartext.len - 1]);
469 const inner_ct = @as(tls.ContentType, @enumFromInt(cleartext[cleartext.len - 1]));
470470 if (inner_ct != .handshake) return error.TlsUnexpectedMessage;
471471
472472 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
520520
521521 const subject_cert: Certificate = .{
522522 .buffer = certd.buf,
523 .index = @intCast(u32, certd.idx),
523 .index = @as(u32, @intCast(certd.idx)),
524524 };
525525 const subject = try subject_cert.parse();
526526 if (cert_index == 0) {
......@@ -534,7 +534,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
534534 if (pub_key.len > main_cert_pub_key_buf.len)
535535 return error.CertificatePublicKeyInvalid;
536536 @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));
538538 } else {
539539 try prev_cert.verify(subject, now_sec);
540540 }
......@@ -679,7 +679,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
679679 .write_seq = 0,
680680 .partial_cleartext_idx = 0,
681681 .partial_ciphertext_idx = 0,
682 .partial_ciphertext_end = @intCast(u15, leftover.len),
682 .partial_ciphertext_end = @as(u15, @intCast(leftover.len)),
683683 .received_close_notify = false,
684684 .application_cipher = app_cipher,
685685 .partially_read_buffer = undefined,
......@@ -797,11 +797,11 @@ fn prepareCiphertextRecord(
797797 const overhead_len = tls.record_header_len + P.AEAD.tag_length + 1;
798798 const close_notify_alert_reserved = tls.close_notify_alert.len + overhead_len;
799799 while (true) {
800 const encrypted_content_len = @intCast(u16, @min(
800 const encrypted_content_len = @as(u16, @intCast(@min(
801801 @min(bytes.len - bytes_i, max_ciphertext_len - 1),
802802 ciphertext_buf.len - close_notify_alert_reserved -
803803 overhead_len - ciphertext_end,
804 ));
804 )));
805805 if (encrypted_content_len == 0) return .{
806806 .iovec_end = iovec_end,
807807 .ciphertext_end = ciphertext_end,
......@@ -826,7 +826,7 @@ fn prepareCiphertextRecord(
826826 const auth_tag = ciphertext_buf[ciphertext_end..][0..P.AEAD.tag_length];
827827 ciphertext_end += auth_tag.len;
828828 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)));
830830 c.write_seq += 1; // TODO send key_update on overflow
831831 const nonce = @as(V, p.client_iv) ^ operand;
832832 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)
920920 // Give away the buffered cleartext we have, if any.
921921 const partial_cleartext = c.partially_read_buffer[c.partial_cleartext_idx..c.partial_ciphertext_idx];
922922 if (partial_cleartext.len > 0) {
923 const amt = @intCast(u15, vp.put(partial_cleartext));
923 const amt = @as(u15, @intCast(vp.put(partial_cleartext)));
924924 c.partial_cleartext_idx += amt;
925925
926926 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)
10371037 in = 0;
10381038 continue;
10391039 }
1040 const ct = @enumFromInt(tls.ContentType, frag[in]);
1040 const ct = @as(tls.ContentType, @enumFromInt(frag[in]));
10411041 in += 1;
10421042 const legacy_version = mem.readIntBig(u16, frag[in..][0..2]);
10431043 in += 2;
......@@ -1070,8 +1070,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
10701070 switch (ct) {
10711071 .alert => {
10721072 if (in + 2 > frag.len) return error.TlsDecodeError;
1073 const level = @enumFromInt(tls.AlertLevel, frag[in]);
1074 const desc = @enumFromInt(tls.AlertDescription, frag[in + 1]);
1073 const level = @as(tls.AlertLevel, @enumFromInt(frag[in]));
1074 const desc = @as(tls.AlertDescription, @enumFromInt(frag[in + 1]));
10751075 _ = level;
10761076
10771077 try desc.toError();
......@@ -1089,7 +1089,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
10891089 in += ciphertext_len;
10901090 const auth_tag = frag[in..][0..P.AEAD.tag_length].*;
10911091 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)));
10931093 const nonce: [P.AEAD.nonce_length]u8 = @as(V, p.server_iv) ^ operand;
10941094 const out_buf = vp.peek();
10951095 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)
11051105
11061106 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]));
11091109 switch (inner_ct) {
11101110 .alert => {
1111 const level = @enumFromInt(tls.AlertLevel, cleartext[0]);
1112 const desc = @enumFromInt(tls.AlertDescription, cleartext[1]);
1111 const level = @as(tls.AlertLevel, @enumFromInt(cleartext[0]));
1112 const desc = @as(tls.AlertDescription, @enumFromInt(cleartext[1]));
11131113 if (desc == .close_notify) {
11141114 c.received_close_notify = true;
11151115 c.partial_ciphertext_end = c.partial_ciphertext_idx;
......@@ -1124,7 +1124,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
11241124 .handshake => {
11251125 var ct_i: usize = 0;
11261126 while (true) {
1127 const handshake_type = @enumFromInt(tls.HandshakeType, cleartext[ct_i]);
1127 const handshake_type = @as(tls.HandshakeType, @enumFromInt(cleartext[ct_i]));
11281128 ct_i += 1;
11291129 const handshake_len = mem.readIntBig(u24, cleartext[ct_i..][0..3]);
11301130 ct_i += 3;
......@@ -1148,7 +1148,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
11481148 }
11491149 c.read_seq = 0;
11501150
1151 switch (@enumFromInt(tls.KeyUpdateRequest, handshake[0])) {
1151 switch (@as(tls.KeyUpdateRequest, @enumFromInt(handshake[0]))) {
11521152 .update_requested => {
11531153 switch (c.application_cipher) {
11541154 inline else => |*p| {
......@@ -1186,13 +1186,13 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
11861186 c.partially_read_buffer[c.partial_ciphertext_idx..][0..msg.len],
11871187 msg,
11881188 );
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));
11901190 } else {
11911191 const amt = vp.put(msg);
11921192 if (amt < msg.len) {
11931193 const rest = msg[amt..];
11941194 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));
11961196 @memcpy(c.partially_read_buffer[0..rest.len], rest);
11971197 }
11981198 }
......@@ -1220,12 +1220,12 @@ fn finishRead(c: *Client, frag: []const u8, in: usize, out: usize) usize {
12201220 const saved_buf = frag[in..];
12211221 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {
12221222 // 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));
12241224 @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx..][0..saved_buf.len], saved_buf);
12251225 } else {
12261226 c.partial_cleartext_idx = 0;
12271227 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));
12291229 @memcpy(c.partially_read_buffer[0..saved_buf.len], saved_buf);
12301230 }
12311231 return out;
......@@ -1235,14 +1235,14 @@ fn finishRead(c: *Client, frag: []const u8, in: usize, out: usize) usize {
12351235fn finishRead2(c: *Client, first: []const u8, frag1: []const u8, out: usize) usize {
12361236 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {
12371237 // 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));
12391239 // TODO: eliminate this call to copyForwards
12401240 std.mem.copyForwards(u8, c.partially_read_buffer[c.partial_ciphertext_idx..][0..first.len], first);
12411241 @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx + first.len ..][0..frag1.len], frag1);
12421242 } else {
12431243 c.partial_cleartext_idx = 0;
12441244 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));
12461246 // TODO: eliminate this call to copyForwards
12471247 std.mem.copyForwards(u8, c.partially_read_buffer[0..first.len], first);
12481248 @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 {
2424 const s = @typeInfo(C).Int.bits;
2525 const Cu = std.meta.Int(.unsigned, s);
2626 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))));
2828 },
2929 .Vector => |info| {
3030 const C = info.child;
......@@ -35,7 +35,7 @@ pub fn timingSafeEql(comptime T: type, a: T, b: T) bool {
3535 const s = @typeInfo(C).Int.bits;
3636 const Cu = std.meta.Int(.unsigned, s);
3737 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))));
3939 },
4040 else => {
4141 @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
6060 i -= 1;
6161 const x1 = a[i];
6262 const x2 = b[i];
63 gt |= @truncate(T, (@as(Cext, x2) -% @as(Cext, x1)) >> bits) & eq;
64 eq &= @truncate(T, (@as(Cext, (x2 ^ x1)) -% 1) >> bits);
63 gt |= @as(T, @truncate((@as(Cext, x2) -% @as(Cext, x1)) >> bits)) & eq;
64 eq &= @as(T, @truncate((@as(Cext, (x2 ^ x1)) -% 1) >> bits));
6565 }
6666 } else {
6767 for (a, 0..) |x1, i| {
6868 const x2 = b[i];
69 gt |= @truncate(T, (@as(Cext, x2) -% @as(Cext, x1)) >> bits) & eq;
70 eq &= @truncate(T, (@as(Cext, (x2 ^ x1)) -% 1) >> bits);
69 gt |= @as(T, @truncate((@as(Cext, x2) -% @as(Cext, x1)) >> bits)) & eq;
70 eq &= @as(T, @truncate((@as(Cext, (x2 ^ x1)) -% 1) >> bits));
7171 }
7272 }
7373 if (gt != 0) {
......@@ -102,7 +102,7 @@ pub fn timingSafeAdd(comptime T: type, a: []const T, b: []const T, result: []T,
102102 carry = ov1[1] | ov2[1];
103103 }
104104 }
105 return @bitCast(bool, carry);
105 return @as(bool, @bitCast(carry));
106106}
107107
108108/// 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,
129129 borrow = ov1[1] | ov2[1];
130130 }
131131 }
132 return @bitCast(bool, borrow);
132 return @as(bool, @bitCast(borrow));
133133}
134134
135135/// Sets a slice to zeroes.
lib/std/cstr.zig+2-2
......@@ -89,12 +89,12 @@ pub const NullTerminated2DArray = struct {
8989 return NullTerminated2DArray{
9090 .allocator = allocator,
9191 .byte_count = byte_count,
92 .ptr = @ptrCast(?[*:null]?[*:0]u8, buf.ptr),
92 .ptr = @as(?[*:null]?[*:0]u8, @ptrCast(buf.ptr)),
9393 };
9494 }
9595
9696 pub fn deinit(self: *NullTerminated2DArray) void {
97 const buf = @ptrCast([*]u8, self.ptr);
97 const buf = @as([*]u8, @ptrCast(self.ptr));
9898 self.allocator.free(buf[0..self.byte_count]);
9999 }
100100};
lib/std/debug.zig+53-63
......@@ -460,8 +460,8 @@ pub const StackIterator = struct {
460460 // We are unable to determine validity of memory for freestanding targets
461461 if (native_os == .freestanding) return true;
462462
463 const aligned_address = address & ~@intCast(usize, (mem.page_size - 1));
464 const aligned_memory = @ptrFromInt([*]align(mem.page_size) u8, aligned_address)[0..mem.page_size];
463 const aligned_address = address & ~@as(usize, @intCast((mem.page_size - 1)));
464 const aligned_memory = @as([*]align(mem.page_size) u8, @ptrFromInt(aligned_address))[0..mem.page_size];
465465
466466 if (native_os != .windows) {
467467 if (native_os != .wasi) {
......@@ -511,7 +511,7 @@ pub const StackIterator = struct {
511511 if (fp == 0 or !mem.isAligned(fp, @alignOf(usize)) or !isValidMemory(fp))
512512 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
516516 // Sanity check: the stack grows down thus all the parent frames must be
517517 // be at addresses that are greater (or equal) than the previous one.
......@@ -520,9 +520,9 @@ pub const StackIterator = struct {
520520 if (new_fp != 0 and new_fp < self.fp)
521521 return null;
522522
523 const new_pc = @ptrFromInt(
523 const new_pc = @as(
524524 *const usize,
525 math.add(usize, fp, pc_offset) catch return null,
525 @ptrFromInt(math.add(usize, fp, pc_offset) catch return null),
526526 ).*;
527527
528528 self.fp = new_fp;
......@@ -555,10 +555,10 @@ pub fn writeCurrentStackTrace(
555555pub noinline fn walkStackWindows(addresses: []usize) usize {
556556 if (builtin.cpu.arch == .x86) {
557557 // 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);
559559 }
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
563563 var context: windows.CONTEXT = std.mem.zeroes(windows.CONTEXT);
564564 windows.ntdll.RtlCaptureContext(&context);
......@@ -584,7 +584,7 @@ pub noinline fn walkStackWindows(addresses: []usize) usize {
584584 );
585585 } else {
586586 // leaf function
587 context.setIp(@ptrFromInt(*u64, current_regs.sp).*);
587 context.setIp(@as(*u64, @ptrFromInt(current_regs.sp)).*);
588588 context.setSp(current_regs.sp + @sizeOf(usize));
589589 }
590590
......@@ -734,7 +734,7 @@ fn printLineInfo(
734734 if (printLineFromFile(out_stream, li)) {
735735 if (li.column > 0) {
736736 // 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
739739 try out_stream.writeByteNTimes(' ', space_needed);
740740 try tty_config.setColor(out_stream, .green);
......@@ -883,7 +883,7 @@ fn chopSlice(ptr: []const u8, offset: u64, size: u64) error{Overflow}![]const u8
883883pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugInfo {
884884 nosuspend {
885885 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]));
887887 if (!mem.eql(u8, hdr.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic;
888888 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
896896
897897 const shoff = hdr.e_shoff;
898898 const str_section_off = shoff + @as(u64, hdr.e_shentsize) * @as(u64, hdr.e_shstrndx);
899 const str_shdr = @ptrCast(
900 *const elf.Shdr,
901 @alignCast(@alignOf(elf.Shdr), &mapped_mem[math.cast(usize, str_section_off) orelse return error.Overflow]),
902 );
899 const str_shdr: *const elf.Shdr = @ptrCast(@alignCast(
900 &mapped_mem[math.cast(usize, str_section_off) orelse return error.Overflow],
901 ));
903902 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(
905904 [*]const elf.Shdr,
906 @alignCast(@alignOf(elf.Shdr), &mapped_mem[shoff]),
905 @ptrCast(@alignCast(&mapped_mem[shoff])),
907906 )[0..hdr.e_shnum];
908907
909908 var opt_debug_info: ?[]const u8 = null;
......@@ -982,10 +981,7 @@ pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugIn
982981fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugInfo {
983982 const mapped_mem = try mapWholeFile(macho_file);
984983
985 const hdr = @ptrCast(
986 *const macho.mach_header_64,
987 @alignCast(@alignOf(macho.mach_header_64), mapped_mem.ptr),
988 );
984 const hdr: *const macho.mach_header_64 = @ptrCast(@alignCast(mapped_mem.ptr));
989985 if (hdr.magic != macho.MH_MAGIC_64)
990986 return error.InvalidDebugInfo;
991987
......@@ -998,9 +994,9 @@ fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugIn
998994 else => {},
999995 } else return error.MissingDebugInfo;
1000996
1001 const syms = @ptrCast(
997 const syms = @as(
1002998 [*]const macho.nlist_64,
1003 @alignCast(@alignOf(macho.nlist_64), &mapped_mem[symtab.symoff]),
999 @ptrCast(@alignCast(&mapped_mem[symtab.symoff])),
10041000 )[0..symtab.nsyms];
10051001 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
10551051 },
10561052 .fun_strx => {
10571053 state = .fun_size;
1058 last_sym.size = @intCast(u32, sym.n_value);
1054 last_sym.size = @as(u32, @intCast(sym.n_value));
10591055 },
10601056 else => return error.InvalidDebugInfo,
10611057 }
......@@ -1283,10 +1279,10 @@ pub const DebugInfo = struct {
12831279
12841280 var it = macho.LoadCommandIterator{
12851281 .ncmds = header.ncmds,
1286 .buffer = @alignCast(@alignOf(u64), @ptrFromInt(
1282 .buffer = @alignCast(@as(
12871283 [*]u8,
1288 @intFromPtr(header) + @sizeOf(macho.mach_header_64),
1289 ))[0..header.sizeofcmds],
1284 @ptrFromInt(@intFromPtr(header) + @sizeOf(macho.mach_header_64)),
1285 )[0..header.sizeofcmds]),
12901286 };
12911287 while (it.next()) |cmd| switch (cmd.cmd()) {
12921288 .SEGMENT_64 => {
......@@ -1332,7 +1328,7 @@ pub const DebugInfo = struct {
13321328 return obj_di;
13331329 }
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];
13361332 const obj_di = try self.allocator.create(ModuleDebugInfo);
13371333 errdefer self.allocator.destroy(obj_di);
13381334
......@@ -1465,10 +1461,7 @@ pub const ModuleDebugInfo = switch (native_os) {
14651461 const o_file = try fs.cwd().openFile(o_file_path, .{ .intended_io_mode = .blocking });
14661462 const mapped_mem = try mapWholeFile(o_file);
14671463
1468 const hdr = @ptrCast(
1469 *const macho.mach_header_64,
1470 @alignCast(@alignOf(macho.mach_header_64), mapped_mem.ptr),
1471 );
1464 const hdr: *const macho.mach_header_64 = @ptrCast(@alignCast(mapped_mem.ptr));
14721465 if (hdr.magic != std.macho.MH_MAGIC_64)
14731466 return error.InvalidDebugInfo;
14741467
......@@ -1487,21 +1480,18 @@ pub const ModuleDebugInfo = switch (native_os) {
14871480 if (segcmd == null or symtabcmd == null) return error.MissingDebugInfo;
14881481
14891482 // Parse symbols
1490 const strtab = @ptrCast(
1483 const strtab = @as(
14911484 [*]const u8,
1492 &mapped_mem[symtabcmd.?.stroff],
1485 @ptrCast(&mapped_mem[symtabcmd.?.stroff]),
14931486 )[0 .. symtabcmd.?.strsize - 1 :0];
1494 const symtab = @ptrCast(
1487 const symtab = @as(
14951488 [*]const macho.nlist_64,
1496 @alignCast(
1497 @alignOf(macho.nlist_64),
1498 &mapped_mem[symtabcmd.?.symoff],
1499 ),
1489 @ptrCast(@alignCast(&mapped_mem[symtabcmd.?.symoff])),
15001490 )[0..symtabcmd.?.nsyms];
15011491
15021492 // TODO handle tentative (common) symbols
15031493 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)));
15051495 for (symtab) |sym| {
15061496 if (sym.n_strx == 0) continue;
15071497 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
19431933
19441934 switch (native_arch) {
19451935 .x86 => {
1946 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
1947 const ip = @intCast(usize, ctx.mcontext.gregs[os.REG.EIP]);
1948 const bp = @intCast(usize, ctx.mcontext.gregs[os.REG.EBP]);
1936 const ctx: *const os.ucontext_t = @ptrCast(@alignCast(ctx_ptr));
1937 const ip = @as(usize, @intCast(ctx.mcontext.gregs[os.REG.EIP]));
1938 const bp = @as(usize, @intCast(ctx.mcontext.gregs[os.REG.EBP]));
19491939 dumpStackTraceFromBase(bp, ip);
19501940 },
19511941 .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));
19531943 const ip = switch (native_os) {
1954 .linux, .netbsd, .solaris => @intCast(usize, ctx.mcontext.gregs[os.REG.RIP]),
1955 .freebsd => @intCast(usize, ctx.mcontext.rip),
1956 .openbsd => @intCast(usize, ctx.sc_rip),
1957 .macos => @intCast(usize, ctx.mcontext.ss.rip),
1944 .linux, .netbsd, .solaris => @as(usize, @intCast(ctx.mcontext.gregs[os.REG.RIP])),
1945 .freebsd => @as(usize, @intCast(ctx.mcontext.rip)),
1946 .openbsd => @as(usize, @intCast(ctx.sc_rip)),
1947 .macos => @as(usize, @intCast(ctx.mcontext.ss.rip)),
19581948 else => unreachable,
19591949 };
19601950 const bp = switch (native_os) {
1961 .linux, .netbsd, .solaris => @intCast(usize, ctx.mcontext.gregs[os.REG.RBP]),
1962 .openbsd => @intCast(usize, ctx.sc_rbp),
1963 .freebsd => @intCast(usize, ctx.mcontext.rbp),
1964 .macos => @intCast(usize, ctx.mcontext.ss.rbp),
1951 .linux, .netbsd, .solaris => @as(usize, @intCast(ctx.mcontext.gregs[os.REG.RBP])),
1952 .openbsd => @as(usize, @intCast(ctx.sc_rbp)),
1953 .freebsd => @as(usize, @intCast(ctx.mcontext.rbp)),
1954 .macos => @as(usize, @intCast(ctx.mcontext.ss.rbp)),
19651955 else => unreachable,
19661956 };
19671957 dumpStackTraceFromBase(bp, ip);
19681958 },
19691959 .arm => {
1970 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
1971 const ip = @intCast(usize, ctx.mcontext.arm_pc);
1972 const bp = @intCast(usize, ctx.mcontext.arm_fp);
1960 const ctx: *const os.ucontext_t = @ptrCast(@alignCast(ctx_ptr));
1961 const ip = @as(usize, @intCast(ctx.mcontext.arm_pc));
1962 const bp = @as(usize, @intCast(ctx.mcontext.arm_fp));
19731963 dumpStackTraceFromBase(bp, ip);
19741964 },
19751965 .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));
19771967 const ip = switch (native_os) {
1978 .macos => @intCast(usize, ctx.mcontext.ss.pc),
1979 .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.PC]),
1980 .freebsd => @intCast(usize, ctx.mcontext.gpregs.elr),
1981 else => @intCast(usize, ctx.mcontext.pc),
1968 .macos => @as(usize, @intCast(ctx.mcontext.ss.pc)),
1969 .netbsd => @as(usize, @intCast(ctx.mcontext.gregs[os.REG.PC])),
1970 .freebsd => @as(usize, @intCast(ctx.mcontext.gpregs.elr)),
1971 else => @as(usize, @intCast(ctx.mcontext.pc)),
19821972 };
19831973 // x29 is the ABI-designated frame pointer
19841974 const bp = switch (native_os) {
1985 .macos => @intCast(usize, ctx.mcontext.ss.fp),
1986 .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.FP]),
1987 .freebsd => @intCast(usize, ctx.mcontext.gpregs.x[os.REG.FP]),
1988 else => @intCast(usize, ctx.mcontext.regs[29]),
1975 .macos => @as(usize, @intCast(ctx.mcontext.ss.fp)),
1976 .netbsd => @as(usize, @intCast(ctx.mcontext.gregs[os.REG.FP])),
1977 .freebsd => @as(usize, @intCast(ctx.mcontext.gpregs.x[os.REG.FP])),
1978 else => @as(usize, @intCast(ctx.mcontext.regs[29])),
19891979 };
19901980 dumpStackTraceFromBase(bp, ip);
19911981 },
lib/std/dwarf.zig+6-6
......@@ -462,7 +462,7 @@ const LineNumberProgram = struct {
462462 });
463463
464464 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,
466466 .column = self.prev_column,
467467 .file_name = file_name,
468468 };
......@@ -533,7 +533,7 @@ fn parseFormValueConstant(in_stream: anytype, signed: bool, endian: std.builtin.
533533 -1 => blk: {
534534 if (signed) {
535535 const x = try nosuspend leb.readILEB128(i64, in_stream);
536 break :blk @bitCast(u64, x);
536 break :blk @as(u64, @bitCast(x));
537537 } else {
538538 const x = try nosuspend leb.readULEB128(u64, in_stream);
539539 break :blk x;
......@@ -939,12 +939,12 @@ pub const DwarfInfo = struct {
939939 .Const => |c| try c.asUnsignedLe(),
940940 .RangeListOffset => |idx| off: {
941941 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));
943943 if (offset_loc + 8 > debug_ranges.len) return badDwarf();
944944 const offset = mem.readInt(u64, debug_ranges[offset_loc..][0..8], di.endian);
945945 break :off compile_unit.rnglists_base + offset;
946946 } 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));
948948 if (offset_loc + 4 > debug_ranges.len) return badDwarf();
949949 const offset = mem.readInt(u32, debug_ranges[offset_loc..][0..4], di.endian);
950950 break :off compile_unit.rnglists_base + offset;
......@@ -1134,7 +1134,7 @@ pub const DwarfInfo = struct {
11341134 ),
11351135 };
11361136 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));
11381138 }
11391139 }
11401140 return result;
......@@ -1438,7 +1438,7 @@ pub const DwarfInfo = struct {
14381438 const addr_size = debug_addr[compile_unit.addr_base - 2];
14391439 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));
14421442 if (byte_offset + addr_size > debug_addr.len) return badDwarf();
14431443 return switch (addr_size) {
14441444 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 {
7171 while (_DYNAMIC[i].d_tag != elf.DT_NULL) : (i += 1) {
7272 switch (_DYNAMIC[i].d_tag) {
7373 elf.DT_DEBUG => {
74 const ptr = @ptrFromInt(?*RDebug, _DYNAMIC[i].d_val);
74 const ptr = @as(?*RDebug, @ptrFromInt(_DYNAMIC[i].d_val));
7575 if (ptr) |r_debug| {
7676 if (r_debug.r_version != 1) return error.InvalidExe;
7777 break :init r_debug.r_map;
7878 }
7979 },
8080 elf.DT_PLTGOT => {
81 const ptr = @ptrFromInt(?[*]usize, _DYNAMIC[i].d_val);
81 const ptr = @as(?[*]usize, @ptrFromInt(_DYNAMIC[i].d_val));
8282 if (ptr) |got_table| {
8383 // The address to the link_map structure is stored in
8484 // the second slot
85 break :init @ptrFromInt(?*LinkMap, got_table[1]);
85 break :init @as(?*LinkMap, @ptrFromInt(got_table[1]));
8686 }
8787 },
8888 else => {},
......@@ -132,7 +132,7 @@ pub const ElfDynLib = struct {
132132 );
133133 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));
136136 if (!mem.eql(u8, eh.e_ident[0..4], elf.MAGIC)) return error.NotElfFile;
137137 if (eh.e_type != elf.ET.DYN) return error.NotDynamicLibrary;
138138
......@@ -149,10 +149,10 @@ pub const ElfDynLib = struct {
149149 i += 1;
150150 ph_addr += eh.e_phentsize;
151151 }) {
152 const ph = @ptrFromInt(*elf.Phdr, ph_addr);
152 const ph = @as(*elf.Phdr, @ptrFromInt(ph_addr));
153153 switch (ph.p_type) {
154154 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)),
156156 else => {},
157157 }
158158 }
......@@ -180,7 +180,7 @@ pub const ElfDynLib = struct {
180180 i += 1;
181181 ph_addr += eh.e_phentsize;
182182 }) {
183 const ph = @ptrFromInt(*elf.Phdr, ph_addr);
183 const ph = @as(*elf.Phdr, @ptrFromInt(ph_addr));
184184 switch (ph.p_type) {
185185 elf.PT_LOAD => {
186186 // The VirtAddr may not be page-aligned; in such case there will be
......@@ -188,7 +188,7 @@ pub const ElfDynLib = struct {
188188 const aligned_addr = (base + ph.p_vaddr) & ~(@as(usize, mem.page_size) - 1);
189189 const extra_bytes = (base + ph.p_vaddr) - aligned_addr;
190190 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));
192192 const prot = elfToMmapProt(ph.p_flags);
193193 if ((ph.p_flags & elf.PF_W) == 0) {
194194 // If it does not need write access, it can be mapped from the fd.
......@@ -228,11 +228,11 @@ pub const ElfDynLib = struct {
228228 while (dynv[i] != 0) : (i += 2) {
229229 const p = base + dynv[i + 1];
230230 switch (dynv[i]) {
231 elf.DT_STRTAB => maybe_strings = @ptrFromInt([*:0]u8, p),
232 elf.DT_SYMTAB => maybe_syms = @ptrFromInt([*]elf.Sym, p),
233 elf.DT_HASH => maybe_hashtab = @ptrFromInt([*]os.Elf_Symndx, p),
234 elf.DT_VERSYM => maybe_versym = @ptrFromInt([*]u16, p),
235 elf.DT_VERDEF => maybe_verdef = @ptrFromInt(*elf.Verdef, p),
231 elf.DT_STRTAB => maybe_strings = @as([*:0]u8, @ptrFromInt(p)),
232 elf.DT_SYMTAB => maybe_syms = @as([*]elf.Sym, @ptrFromInt(p)),
233 elf.DT_HASH => maybe_hashtab = @as([*]os.Elf_Symndx, @ptrFromInt(p)),
234 elf.DT_VERSYM => maybe_versym = @as([*]u16, @ptrFromInt(p)),
235 elf.DT_VERDEF => maybe_verdef = @as(*elf.Verdef, @ptrFromInt(p)),
236236 else => {},
237237 }
238238 }
......@@ -261,7 +261,7 @@ pub const ElfDynLib = struct {
261261
262262 pub fn lookup(self: *ElfDynLib, comptime T: type, name: [:0]const u8) ?T {
263263 if (self.lookupAddress("", name)) |symbol| {
264 return @ptrFromInt(T, symbol);
264 return @as(T, @ptrFromInt(symbol));
265265 } else {
266266 return null;
267267 }
......@@ -276,8 +276,8 @@ pub const ElfDynLib = struct {
276276
277277 var i: usize = 0;
278278 while (i < self.hashtab[1]) : (i += 1) {
279 if (0 == (@as(u32, 1) << @intCast(u5, 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;
279 if (0 == (@as(u32, 1) << @as(u5, @intCast(self.syms[i].st_info & 0xf)) & OK_TYPES)) continue;
280 if (0 == (@as(u32, 1) << @as(u5, @intCast(self.syms[i].st_info >> 4)) & OK_BINDS)) continue;
281281 if (0 == self.syms[i].st_shndx) continue;
282282 if (!mem.eql(u8, name, mem.sliceTo(self.strings + self.syms[i].st_name, 0))) continue;
283283 if (maybe_versym) |versym| {
......@@ -301,15 +301,15 @@ pub const ElfDynLib = struct {
301301
302302fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [*:0]u8) bool {
303303 var def = def_arg;
304 const vsym = @bitCast(u32, vsym_arg) & 0x7fff;
304 const vsym = @as(u32, @bitCast(vsym_arg)) & 0x7fff;
305305 while (true) {
306306 if (0 == (def.vd_flags & elf.VER_FLG_BASE) and (def.vd_ndx & 0x7fff) == vsym)
307307 break;
308308 if (def.vd_next == 0)
309309 return false;
310 def = @ptrFromInt(*elf.Verdef, @intFromPtr(def) + def.vd_next);
310 def = @as(*elf.Verdef, @ptrFromInt(@intFromPtr(def) + def.vd_next));
311311 }
312 const aux = @ptrFromInt(*elf.Verdaux, @intFromPtr(def) + def.vd_aux);
312 const aux = @as(*elf.Verdaux, @ptrFromInt(@intFromPtr(def) + def.vd_aux));
313313 return mem.eql(u8, vername, mem.sliceTo(strings + aux.vda_name, 0));
314314}
315315
......@@ -347,7 +347,7 @@ pub const WindowsDynLib = struct {
347347
348348 pub fn lookup(self: *WindowsDynLib, comptime T: type, name: [:0]const u8) ?T {
349349 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)));
351351 } else {
352352 return null;
353353 }
......@@ -381,7 +381,7 @@ pub const DlDynlib = struct {
381381 // dlsym (and other dl-functions) secretly take shadow parameter - return address on stack
382382 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66826
383383 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)));
385385 } else {
386386 return null;
387387 }
lib/std/elf.zig+15-15
......@@ -434,8 +434,8 @@ pub const Header = struct {
434434 }
435435
436436 pub fn parse(hdr_buf: *align(@alignOf(Elf64_Ehdr)) const [@sizeOf(Elf64_Ehdr)]u8) !Header {
437 const hdr32 = @ptrCast(*const Elf32_Ehdr, hdr_buf);
438 const hdr64 = @ptrCast(*const Elf64_Ehdr, hdr_buf);
437 const hdr32 = @as(*const Elf32_Ehdr, @ptrCast(hdr_buf));
438 const hdr64 = @as(*const Elf64_Ehdr, @ptrCast(hdr_buf));
439439 if (!mem.eql(u8, hdr32.e_ident[0..4], MAGIC)) return error.InvalidElfMagic;
440440 if (hdr32.e_ident[EI_VERSION] != 1) return error.InvalidElfVersion;
441441
......@@ -454,7 +454,7 @@ pub const Header = struct {
454454
455455 const machine = if (need_bswap) blk: {
456456 const value = @intFromEnum(hdr32.e_machine);
457 break :blk @enumFromInt(EM, @byteSwap(value));
457 break :blk @as(EM, @enumFromInt(@byteSwap(value)));
458458 } else hdr32.e_machine;
459459
460460 return @as(Header, .{
......@@ -725,10 +725,10 @@ pub const Elf32_Sym = extern struct {
725725 st_shndx: Elf32_Section,
726726
727727 pub inline fn st_type(self: @This()) u4 {
728 return @truncate(u4, self.st_info);
728 return @as(u4, @truncate(self.st_info));
729729 }
730730 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));
732732 }
733733};
734734pub const Elf64_Sym = extern struct {
......@@ -740,10 +740,10 @@ pub const Elf64_Sym = extern struct {
740740 st_size: Elf64_Xword,
741741
742742 pub inline fn st_type(self: @This()) u4 {
743 return @truncate(u4, self.st_info);
743 return @as(u4, @truncate(self.st_info));
744744 }
745745 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));
747747 }
748748};
749749pub const Elf32_Syminfo = extern struct {
......@@ -759,10 +759,10 @@ pub const Elf32_Rel = extern struct {
759759 r_info: Elf32_Word,
760760
761761 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));
763763 }
764764 pub inline fn r_type(self: @This()) u8 {
765 return @truncate(u8, self.r_info);
765 return @as(u8, @truncate(self.r_info));
766766 }
767767};
768768pub const Elf64_Rel = extern struct {
......@@ -770,10 +770,10 @@ pub const Elf64_Rel = extern struct {
770770 r_info: Elf64_Xword,
771771
772772 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));
774774 }
775775 pub inline fn r_type(self: @This()) u32 {
776 return @truncate(u32, self.r_info);
776 return @as(u32, @truncate(self.r_info));
777777 }
778778};
779779pub const Elf32_Rela = extern struct {
......@@ -782,10 +782,10 @@ pub const Elf32_Rela = extern struct {
782782 r_addend: Elf32_Sword,
783783
784784 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));
786786 }
787787 pub inline fn r_type(self: @This()) u8 {
788 return @truncate(u8, self.r_info);
788 return @as(u8, @truncate(self.r_info));
789789 }
790790};
791791pub const Elf64_Rela = extern struct {
......@@ -794,10 +794,10 @@ pub const Elf64_Rela = extern struct {
794794 r_addend: Elf64_Sxword,
795795
796796 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));
798798 }
799799 pub inline fn r_type(self: @This()) u32 {
800 return @truncate(u32, self.r_info);
800 return @as(u32, @truncate(self.r_info));
801801 }
802802};
803803pub 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
1616 fields = fields ++ &[_]StructField{.{
1717 .name = field.name,
1818 .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,
2020 .is_comptime = false,
2121 .alignment = if (@sizeOf(Data) > 0) @alignOf(Data) else 0,
2222 }};
......@@ -61,7 +61,7 @@ test tagName {
6161 const E = enum(u8) { a, b, _ };
6262 try testing.expect(tagName(E, .a) != null);
6363 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);
6565}
6666
6767/// Determines the length of a direct-mapped enum array, indexed by
......@@ -156,7 +156,7 @@ pub fn directEnumArrayDefault(
156156 var result: [len]Data = if (default) |d| [_]Data{d} ** len else undefined;
157157 inline for (@typeInfo(@TypeOf(init_values)).Struct.fields) |f| {
158158 const enum_value = @field(E, f.name);
159 const index = @intCast(usize, @intFromEnum(enum_value));
159 const index = @as(usize, @intCast(@intFromEnum(enum_value)));
160160 result[index] = @field(init_values, f.name);
161161 }
162162 return result;
......@@ -341,7 +341,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
341341 var self = initWithCount(0);
342342 inline for (@typeInfo(E).Enum.fields) |field| {
343343 const c = @field(init_counts, field.name);
344 const key = @enumFromInt(E, field.value);
344 const key = @as(E, @enumFromInt(field.value));
345345 self.counts.set(key, c);
346346 }
347347 return self;
......@@ -412,7 +412,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
412412 /// asserts operation will not overflow any key.
413413 pub fn addSetAssertSafe(self: *Self, other: Self) void {
414414 inline for (@typeInfo(E).Enum.fields) |field| {
415 const key = @enumFromInt(E, field.value);
415 const key = @as(E, @enumFromInt(field.value));
416416 self.addAssertSafe(key, other.getCount(key));
417417 }
418418 }
......@@ -420,7 +420,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
420420 /// Increases the all key counts by given multiset.
421421 pub fn addSet(self: *Self, other: Self) error{Overflow}!void {
422422 inline for (@typeInfo(E).Enum.fields) |field| {
423 const key = @enumFromInt(E, field.value);
423 const key = @as(E, @enumFromInt(field.value));
424424 try self.add(key, other.getCount(key));
425425 }
426426 }
......@@ -430,7 +430,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
430430 /// then that key will have a key count of zero.
431431 pub fn removeSet(self: *Self, other: Self) void {
432432 inline for (@typeInfo(E).Enum.fields) |field| {
433 const key = @enumFromInt(E, field.value);
433 const key = @as(E, @enumFromInt(field.value));
434434 self.remove(key, other.getCount(key));
435435 }
436436 }
......@@ -439,7 +439,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
439439 /// given multiset.
440440 pub fn eql(self: Self, other: Self) bool {
441441 inline for (@typeInfo(E).Enum.fields) |field| {
442 const key = @enumFromInt(E, field.value);
442 const key = @as(E, @enumFromInt(field.value));
443443 if (self.getCount(key) != other.getCount(key)) {
444444 return false;
445445 }
......@@ -451,7 +451,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
451451 /// equal to the given multiset.
452452 pub fn subsetOf(self: Self, other: Self) bool {
453453 inline for (@typeInfo(E).Enum.fields) |field| {
454 const key = @enumFromInt(E, field.value);
454 const key = @as(E, @enumFromInt(field.value));
455455 if (self.getCount(key) > other.getCount(key)) {
456456 return false;
457457 }
......@@ -463,7 +463,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
463463 /// equal to the given multiset.
464464 pub fn supersetOf(self: Self, other: Self) bool {
465465 inline for (@typeInfo(E).Enum.fields) |field| {
466 const key = @enumFromInt(E, field.value);
466 const key = @as(E, @enumFromInt(field.value));
467467 if (self.getCount(key) < other.getCount(key)) {
468468 return false;
469469 }
......@@ -1281,10 +1281,10 @@ test "std.enums.ensureIndexer" {
12811281 pub const Key = u32;
12821282 pub const count: usize = 8;
12831283 pub fn indexOf(k: Key) usize {
1284 return @intCast(usize, k);
1284 return @as(usize, @intCast(k));
12851285 }
12861286 pub fn keyForIndex(index: usize) Key {
1287 return @intCast(Key, index);
1287 return @as(Key, @intCast(index));
12881288 }
12891289 });
12901290}
......@@ -1323,14 +1323,14 @@ pub fn EnumIndexer(comptime E: type) type {
13231323 pub const Key = E;
13241324 pub const count = fields_len;
13251325 pub fn indexOf(e: E) usize {
1326 return @intCast(usize, @intFromEnum(e) - min);
1326 return @as(usize, @intCast(@intFromEnum(e) - min));
13271327 }
13281328 pub fn keyForIndex(i: usize) E {
13291329 // TODO fix addition semantics. This calculation
13301330 // gives up some safety to avoid artificially limiting
13311331 // the range of signed enum values to max_isize.
1332 const enum_value = if (min < 0) @bitCast(isize, i) +% min else i + min;
1333 return @enumFromInt(E, @intCast(std.meta.Tag(E), enum_value));
1332 const enum_value = if (min < 0) @as(isize, @bitCast(i)) +% min else i + min;
1333 return @as(E, @enumFromInt(@as(std.meta.Tag(E), @intCast(enum_value))));
13341334 }
13351335 };
13361336 }
lib/std/event/lock.zig+3-3
......@@ -55,7 +55,7 @@ pub const Lock = struct {
5555 const head = switch (self.head) {
5656 UNLOCKED => unreachable,
5757 LOCKED => null,
58 else => @ptrFromInt(*Waiter, self.head),
58 else => @as(*Waiter, @ptrFromInt(self.head)),
5959 };
6060
6161 if (head) |h| {
......@@ -102,7 +102,7 @@ pub const Lock = struct {
102102 break :blk null;
103103 },
104104 else => {
105 const waiter = @ptrFromInt(*Waiter, self.lock.head);
105 const waiter = @as(*Waiter, @ptrFromInt(self.lock.head));
106106 self.lock.head = if (waiter.next == null) LOCKED else @intFromPtr(waiter.next);
107107 if (waiter.next) |next|
108108 next.tail = waiter.tail;
......@@ -130,7 +130,7 @@ test "std.event.Lock" {
130130 var lock = Lock{};
131131 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;
134134 try testing.expectEqualSlices(i32, &expected_result, &shared_test_data);
135135}
136136fn testLock(lock: *Lock) void {
lib/std/event/loop.zig+6-6
......@@ -556,7 +556,7 @@ pub const Loop = struct {
556556 self.linuxWaitFd(fd, os.linux.EPOLL.ET | os.linux.EPOLL.ONESHOT | os.linux.EPOLL.IN);
557557 },
558558 .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);
560560 },
561561 else => @compileError("Unsupported OS"),
562562 }
......@@ -568,7 +568,7 @@ pub const Loop = struct {
568568 self.linuxWaitFd(fd, os.linux.EPOLL.ET | os.linux.EPOLL.ONESHOT | os.linux.EPOLL.OUT);
569569 },
570570 .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);
572572 },
573573 else => @compileError("Unsupported OS"),
574574 }
......@@ -580,8 +580,8 @@ pub const Loop = struct {
580580 self.linuxWaitFd(fd, os.linux.EPOLL.ET | os.linux.EPOLL.ONESHOT | os.linux.EPOLL.OUT | os.linux.EPOLL.IN);
581581 },
582582 .macos, .ios, .tvos, .watchos, .freebsd, .netbsd, .dragonfly, .openbsd => {
583 self.bsdWaitKev(@intCast(usize, fd), os.system.EVFILT_READ, os.system.EV_ONESHOT);
584 self.bsdWaitKev(@intCast(usize, fd), os.system.EVFILT_WRITE, os.system.EV_ONESHOT);
583 self.bsdWaitKev(@as(usize, @intCast(fd)), os.system.EVFILT_READ, os.system.EV_ONESHOT);
584 self.bsdWaitKev(@as(usize, @intCast(fd)), os.system.EVFILT_WRITE, os.system.EV_ONESHOT);
585585 },
586586 else => @compileError("Unsupported OS"),
587587 }
......@@ -1415,7 +1415,7 @@ pub const Loop = struct {
14151415 var events: [1]os.linux.epoll_event = undefined;
14161416 const count = os.epoll_wait(self.os_data.epollfd, events[0..], -1);
14171417 for (events[0..count]) |ev| {
1418 const resume_node = @ptrFromInt(*ResumeNode, ev.data.ptr);
1418 const resume_node = @as(*ResumeNode, @ptrFromInt(ev.data.ptr));
14191419 const handle = resume_node.handle;
14201420 const resume_node_id = resume_node.id;
14211421 switch (resume_node_id) {
......@@ -1439,7 +1439,7 @@ pub const Loop = struct {
14391439 const empty_kevs = &[0]os.Kevent{};
14401440 const count = os.kevent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;
14411441 for (eventlist[0..count]) |ev| {
1442 const resume_node = @ptrFromInt(*ResumeNode, ev.udata);
1442 const resume_node = @as(*ResumeNode, @ptrFromInt(ev.udata));
14431443 const handle = resume_node.handle;
14441444 const resume_node_id = resume_node.id;
14451445 switch (resume_node_id) {
lib/std/event/rwlock.zig+4-4
......@@ -223,7 +223,7 @@ test "std.event.RwLock" {
223223
224224 _ = 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;
227227 try testing.expectEqualSlices(i32, expected_result, shared_test_data);
228228}
229229fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void {
......@@ -244,12 +244,12 @@ fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void {
244244 }
245245
246246 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));
248248 await casted;
249249 allocator.destroy(casted);
250250 }
251251 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));
253253 await casted;
254254 allocator.destroy(casted);
255255 }
......@@ -287,6 +287,6 @@ fn readRunner(lock: *RwLock) callconv(.Async) void {
287287 defer handle.release();
288288
289289 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)));
291291 }
292292}
lib/std/fmt.zig+35-35
......@@ -396,7 +396,7 @@ pub const ArgState = struct {
396396 }
397397
398398 // 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));
400400 return next_index;
401401 }
402402};
......@@ -1056,7 +1056,7 @@ pub fn formatFloatScientific(
10561056 options: FormatOptions,
10571057 writer: anytype,
10581058) !void {
1059 var x = @floatCast(f64, value);
1059 var x = @as(f64, @floatCast(value));
10601060
10611061 // Errol doesn't handle these special cases.
10621062 if (math.signbit(x)) {
......@@ -1167,9 +1167,9 @@ pub fn formatFloatHexadecimal(
11671167 const exponent_mask = (1 << exponent_bits) - 1;
11681168 const exponent_bias = (1 << (exponent_bits - 1)) - 1;
11691169
1170 const as_bits = @bitCast(TU, value);
1170 const as_bits = @as(TU, @bitCast(value));
11711171 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
11741174 const is_denormal = exponent == 0 and mantissa != 0;
11751175 const is_zero = exponent == 0 and mantissa == 0;
......@@ -1218,7 +1218,7 @@ pub fn formatFloatHexadecimal(
12181218 // Drop the excess bits.
12191219 mantissa >>= 2;
12201220 // 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
12231223 const overflow = mantissa & (1 << 1 + mantissa_digits * 4) != 0;
12241224 // Prefer a normalized result in case of overflow.
......@@ -1296,7 +1296,7 @@ pub fn formatFloatDecimal(
12961296 errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Decimal);
12971297
12981298 // 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
13011301 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.
13021302 var num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);
......@@ -1325,7 +1325,7 @@ pub fn formatFloatDecimal(
13251325
13261326 // Zero-fill until we reach significant digits or run out of precision.
13271327 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));
13291329 const zeros_to_print = @min(zero_digit_count, precision);
13301330
13311331 var i: usize = 0;
......@@ -1354,7 +1354,7 @@ pub fn formatFloatDecimal(
13541354 }
13551355 } else {
13561356 // 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
13591359 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.
13601360 var num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);
......@@ -1380,7 +1380,7 @@ pub fn formatFloatDecimal(
13801380
13811381 // Zero-fill until we reach significant digits or run out of precision.
13821382 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
13851385 var i: usize = 0;
13861386 while (i < zero_digit_count) : (i += 1) {
......@@ -1423,21 +1423,21 @@ pub fn formatInt(
14231423 if (base == 10) {
14241424 while (a >= 100) : (a = @divTrunc(a, 100)) {
14251425 index -= 2;
1426 buf[index..][0..2].* = digits2(@intCast(usize, a % 100));
1426 buf[index..][0..2].* = digits2(@as(usize, @intCast(a % 100)));
14271427 }
14281428
14291429 if (a < 10) {
14301430 index -= 1;
1431 buf[index] = '0' + @intCast(u8, a);
1431 buf[index] = '0' + @as(u8, @intCast(a));
14321432 } else {
14331433 index -= 2;
1434 buf[index..][0..2].* = digits2(@intCast(usize, a));
1434 buf[index..][0..2].* = digits2(@as(usize, @intCast(a)));
14351435 }
14361436 } else {
14371437 while (true) {
14381438 const digit = a % base;
14391439 index -= 1;
1440 buf[index] = digitToChar(@intCast(u8, digit), case);
1440 buf[index] = digitToChar(@as(u8, @intCast(digit)), case);
14411441 a /= base;
14421442 if (a == 0) break;
14431443 }
......@@ -1595,10 +1595,10 @@ test "fmtDuration" {
15951595
15961596fn formatDurationSigned(ns: i64, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
15971597 if (ns < 0) {
1598 const data = FormatDurationData{ .ns = @intCast(u64, -ns), .negative = true };
1598 const data = FormatDurationData{ .ns = @as(u64, @intCast(-ns)), .negative = true };
15991599 try formatDuration(data, fmt, options, writer);
16001600 } else {
1601 const data = FormatDurationData{ .ns = @intCast(u64, ns) };
1601 const data = FormatDurationData{ .ns = @as(u64, @intCast(ns)) };
16021602 try formatDuration(data, fmt, options, writer);
16031603 }
16041604}
......@@ -1846,7 +1846,7 @@ fn parseWithSign(
18461846 // The first digit of a negative number.
18471847 // Consider parsing "-4" as an i3.
18481848 // 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;
18501850 continue;
18511851 }
18521852 x = try add(T, x, math.cast(T, digit) orelse return error.Overflow);
......@@ -2099,7 +2099,7 @@ test "optional" {
20992099 try expectFmt("optional: null\n", "optional: {?}\n", .{value});
21002100 }
21012101 {
2102 const value = @ptrFromInt(?*i32, 0xf000d000);
2102 const value = @as(?*i32, @ptrFromInt(0xf000d000));
21032103 try expectFmt("optional: *i32@f000d000\n", "optional: {*}\n", .{value});
21042104 }
21052105}
......@@ -2218,7 +2218,7 @@ test "slice" {
22182218 }
22192219 {
22202220 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];
22222222 try expectFmt("slice: []const u8@deadbeef\n", "slice: {*}\n", .{value});
22232223 }
22242224 {
......@@ -2248,17 +2248,17 @@ test "escape non-printable" {
22482248
22492249test "pointer" {
22502250 {
2251 const value = @ptrFromInt(*align(1) i32, 0xdeadbeef);
2251 const value = @as(*align(1) i32, @ptrFromInt(0xdeadbeef));
22522252 try expectFmt("pointer: i32@deadbeef\n", "pointer: {}\n", .{value});
22532253 try expectFmt("pointer: i32@deadbeef\n", "pointer: {*}\n", .{value});
22542254 }
22552255 const FnPtr = *align(1) const fn () void;
22562256 {
2257 const value = @ptrFromInt(FnPtr, 0xdeadbeef);
2257 const value = @as(FnPtr, @ptrFromInt(0xdeadbeef));
22582258 try expectFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value});
22592259 }
22602260 {
2261 const value = @ptrFromInt(FnPtr, 0xdeadbeef);
2261 const value = @as(FnPtr, @ptrFromInt(0xdeadbeef));
22622262 try expectFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value});
22632263 }
22642264}
......@@ -2267,12 +2267,12 @@ test "cstr" {
22672267 try expectFmt(
22682268 "cstr: Test C\n",
22692269 "cstr: {s}\n",
2270 .{@ptrCast([*c]const u8, "Test C")},
2270 .{@as([*c]const u8, @ptrCast("Test C"))},
22712271 );
22722272 try expectFmt(
22732273 "cstr: Test C\n",
22742274 "cstr: {s:10}\n",
2275 .{@ptrCast([*c]const u8, "Test C")},
2275 .{@as([*c]const u8, @ptrCast("Test C"))},
22762276 );
22772277}
22782278
......@@ -2360,11 +2360,11 @@ test "non-exhaustive enum" {
23602360 };
23612361 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.One\n", "enum: {}\n", .{Enum.One});
23622362 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))});
23642364 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.One\n", "enum: {x}\n", .{Enum.One});
23652365 try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.Two\n", "enum: {x}\n", .{Enum.Two});
23662366 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))});
23682368}
23692369
23702370test "float.scientific" {
......@@ -2376,11 +2376,11 @@ test "float.scientific" {
23762376
23772377test "float.scientific.precision" {
23782378 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)))});
2380 try expectFmt("f64: 7.81250e-03", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1006632960)))});
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, @as(f32, @bitCast(@as(u32, 1006632960))))});
23812381 // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.
23822382 // 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))))});
23842384}
23852385
23862386test "float.special" {
......@@ -2472,22 +2472,22 @@ test "float.decimal" {
24722472}
24732473
24742474test "float.libc.sanity" {
2475 try expectFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 916964781)))});
2476 try expectFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 925353389)))});
2477 try expectFmt("f64: 0.10000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1036831278)))});
2478 try expectFmt("f64: 1.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1065353133)))});
2479 try expectFmt("f64: 10.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1092616192)))});
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, @as(f32, @bitCast(@as(u32, 925353389))))});
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, @as(f32, @bitCast(@as(u32, 1065353133))))});
2479 try expectFmt("f64: 10.00000", "f64: {d:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 1092616192))))});
24802480
24812481 // libc differences
24822482 //
24832483 // This is 0.015625 exactly according to gdb. We thus round down,
24842484 // however glibc rounds up for some reason. This occurs for all
24852485 // 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))))});
24872487 // errol3 rounds to ... 630 but libc rounds to ...632. Grisu3
24882488 // also rounds to 630 so I'm inclined to believe libc is not
24892489 // 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))))});
24912491}
24922492
24932493test "custom" {
lib/std/fmt/errol.zig+49-49
......@@ -29,11 +29,11 @@ pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: Ro
2929 switch (mode) {
3030 RoundMode.Decimal => {
3131 if (float_decimal.exp >= 0) {
32 round_digit = precision + @intCast(usize, float_decimal.exp);
32 round_digit = precision + @as(usize, @intCast(float_decimal.exp));
3333 } else {
3434 // if a small negative exp, then adjust we need to offset by the number
3535 // 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));
3737 if (precision > min_exp_required) {
3838 round_digit = precision - min_exp_required;
3939 }
......@@ -59,7 +59,7 @@ pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: Ro
5959 float_decimal.exp += 1;
6060
6161 // 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));
6363 float_decimal.digits = one_before[0 .. float_decimal.digits.len + 1];
6464 float_decimal.digits[0] = '1';
6565 return;
......@@ -80,7 +80,7 @@ pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: Ro
8080
8181/// Corrected Errol3 double to ASCII conversion.
8282pub fn errol3(value: f64, buffer: []u8) FloatDecimal {
83 const bits = @bitCast(u64, value);
83 const bits = @as(u64, @bitCast(value));
8484 const i = tableLowerBound(bits);
8585 if (i < enum3.len and enum3[i] == bits) {
8686 const data = enum3_data[i];
......@@ -113,16 +113,16 @@ fn errolSlow(val: f64, buffer: []u8) FloatDecimal {
113113 // normalize the midpoint
114114
115115 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)));
117117 if (exp < 20) {
118118 exp = 20;
119 } else if (@intCast(usize, exp) >= lookup_table.len) {
120 exp = @intCast(i16, lookup_table.len - 1);
119 } else if (@as(usize, @intCast(exp)) >= lookup_table.len) {
120 exp = @as(i16, @intCast(lookup_table.len - 1));
121121 }
122122
123 var mid = lookup_table[@intCast(usize, exp)];
123 var mid = lookup_table[@as(usize, @intCast(exp))];
124124 mid = hpProd(mid, val);
125 const lten = lookup_table[@intCast(usize, exp)].val;
125 const lten = lookup_table[@as(usize, @intCast(exp))].val;
126126
127127 exp -= 307;
128128
......@@ -171,25 +171,25 @@ fn errolSlow(val: f64, buffer: []u8) FloatDecimal {
171171 var buf_index: usize = 0;
172172 const bound = buffer.len - 1;
173173 while (buf_index < bound) {
174 var hdig = @intFromFloat(u8, @floor(high.val));
175 if ((high.val == @floatFromInt(f64, hdig)) and (high.off < 0)) hdig -= 1;
174 var hdig = @as(u8, @intFromFloat(@floor(high.val)));
175 if ((high.val == @as(f64, @floatFromInt(hdig))) and (high.off < 0)) hdig -= 1;
176176
177 var ldig = @intFromFloat(u8, @floor(low.val));
178 if ((low.val == @floatFromInt(f64, ldig)) and (low.off < 0)) ldig -= 1;
177 var ldig = @as(u8, @intFromFloat(@floor(low.val)));
178 if ((low.val == @as(f64, @floatFromInt(ldig))) and (low.off < 0)) ldig -= 1;
179179
180180 if (ldig != hdig) break;
181181
182182 buffer[buf_index] = hdig + '0';
183183 buf_index += 1;
184 high.val -= @floatFromInt(f64, hdig);
185 low.val -= @floatFromInt(f64, ldig);
184 high.val -= @as(f64, @floatFromInt(hdig));
185 low.val -= @as(f64, @floatFromInt(ldig));
186186 hpMul10(&high);
187187 hpMul10(&low);
188188 }
189189
190190 const tmp = (high.val + low.val) / 2.0;
191 var mdig = @intFromFloat(u8, @floor(tmp + 0.5));
192 if ((@floatFromInt(f64, mdig) - tmp) == 0.5 and (mdig & 0x1) != 0) mdig -= 1;
191 var mdig = @as(u8, @intFromFloat(@floor(tmp + 0.5)));
192 if ((@as(f64, @floatFromInt(mdig)) - tmp) == 0.5 and (mdig & 0x1) != 0) mdig -= 1;
193193
194194 buffer[buf_index] = mdig + '0';
195195 buf_index += 1;
......@@ -248,9 +248,9 @@ fn split(val: f64, hi: *f64, lo: *f64) void {
248248}
249249
250250fn gethi(in: f64) f64 {
251 const bits = @bitCast(u64, in);
251 const bits = @as(u64, @bitCast(in));
252252 const new_bits = bits & 0xFFFFFFFFF8000000;
253 return @bitCast(f64, new_bits);
253 return @as(f64, @bitCast(new_bits));
254254}
255255
256256/// Normalize the number by factoring in the error.
......@@ -303,21 +303,21 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
303303
304304 assert((val > 9.007199254740992e15) and val < (3.40282366920938e38));
305305
306 var mid = @intFromFloat(u128, val);
306 var mid = @as(u128, @intFromFloat(val));
307307 var low: u128 = mid - fpeint((fpnext(val) - val) / 2.0);
308308 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) {
311311 high -= 1;
312312 } else {
313313 low -= 1;
314314 }
315315
316 var l64 = @intCast(u64, low % pow19);
317 const lf = @intCast(u64, (low / pow19) % pow19);
316 var l64 = @as(u64, @intCast(low % pow19));
317 const lf = @as(u64, @intCast((low / pow19) % pow19));
318318
319 var h64 = @intCast(u64, high % pow19);
320 const hf = @intCast(u64, (high / pow19) % pow19);
319 var h64 = @as(u64, @intCast(high % pow19));
320 const hf = @as(u64, @intCast((high / pow19) % pow19));
321321
322322 if (lf != hf) {
323323 l64 = lf;
......@@ -333,7 +333,7 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
333333 x *= 10;
334334 }
335335 }
336 const m64 = @truncate(u64, @divTrunc(mid, x));
336 const m64 = @as(u64, @truncate(@divTrunc(mid, x)));
337337
338338 if (lf != hf) mi += 19;
339339
......@@ -349,7 +349,7 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
349349
350350 return FloatDecimal{
351351 .digits = buffer[0..buf_index],
352 .exp = @intCast(i32, buf_index) + mi,
352 .exp = @as(i32, @intCast(buf_index)) + mi,
353353 };
354354}
355355
......@@ -360,33 +360,33 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
360360fn errolFixed(val: f64, buffer: []u8) FloatDecimal {
361361 assert((val >= 16.0) and (val < 9.007199254740992e15));
362362
363 const u = @intFromFloat(u64, val);
364 const n = @floatFromInt(f64, u);
363 const u = @as(u64, @intFromFloat(val));
364 const n = @as(f64, @floatFromInt(u));
365365
366366 var mid = val - n;
367367 var lo = ((fpprev(val) - n) + mid) / 2.0;
368368 var hi = ((fpnext(val) - n) + mid) / 2.0;
369369
370370 var buf_index = u64toa(u, buffer);
371 var exp = @intCast(i32, buf_index);
371 var exp = @as(i32, @intCast(buf_index));
372372 var j = buf_index;
373373 buffer[j] = 0;
374374
375375 if (mid != 0.0) {
376376 while (mid != 0.0) {
377377 lo *= 10.0;
378 const ldig = @intFromFloat(i32, lo);
379 lo -= @floatFromInt(f64, ldig);
378 const ldig = @as(i32, @intFromFloat(lo));
379 lo -= @as(f64, @floatFromInt(ldig));
380380
381381 mid *= 10.0;
382 const mdig = @intFromFloat(i32, mid);
383 mid -= @floatFromInt(f64, mdig);
382 const mdig = @as(i32, @intFromFloat(mid));
383 mid -= @as(f64, @floatFromInt(mdig));
384384
385385 hi *= 10.0;
386 const hdig = @intFromFloat(i32, hi);
387 hi -= @floatFromInt(f64, hdig);
386 const hdig = @as(i32, @intFromFloat(hi));
387 hi -= @as(f64, @floatFromInt(hdig));
388388
389 buffer[j] = @intCast(u8, mdig + '0');
389 buffer[j] = @as(u8, @intCast(mdig + '0'));
390390 j += 1;
391391
392392 if (hdig != ldig or j > 50) break;
......@@ -413,11 +413,11 @@ fn errolFixed(val: f64, buffer: []u8) FloatDecimal {
413413}
414414
415415fn fpnext(val: f64) f64 {
416 return @bitCast(f64, @bitCast(u64, val) +% 1);
416 return @as(f64, @bitCast(@as(u64, @bitCast(val)) +% 1));
417417}
418418
419419fn fpprev(val: f64) f64 {
420 return @bitCast(f64, @bitCast(u64, val) -% 1);
420 return @as(f64, @bitCast(@as(u64, @bitCast(val)) -% 1));
421421}
422422
423423pub const c_digits_lut = [_]u8{
......@@ -453,7 +453,7 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
453453 var buf_index: usize = 0;
454454
455455 if (value < kTen8) {
456 const v = @intCast(u32, value);
456 const v = @as(u32, @intCast(value));
457457 if (v < 10000) {
458458 const d1: u32 = (v / 100) << 1;
459459 const d2: u32 = (v % 100) << 1;
......@@ -508,8 +508,8 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
508508 buf_index += 1;
509509 }
510510 } else if (value < kTen16) {
511 const v0: u32 = @intCast(u32, value / kTen8);
512 const v1: u32 = @intCast(u32, value % kTen8);
511 const v0: u32 = @as(u32, @intCast(value / kTen8));
512 const v1: u32 = @as(u32, @intCast(value % kTen8));
513513
514514 const b0: u32 = v0 / 10000;
515515 const c0: u32 = v0 % 10000;
......@@ -579,11 +579,11 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
579579 buffer[buf_index] = c_digits_lut[d8 + 1];
580580 buf_index += 1;
581581 } else {
582 const a = @intCast(u32, value / kTen16); // 1 to 1844
582 const a = @as(u32, @intCast(value / kTen16)); // 1 to 1844
583583 value %= kTen16;
584584
585585 if (a < 10) {
586 buffer[buf_index] = '0' + @intCast(u8, a);
586 buffer[buf_index] = '0' + @as(u8, @intCast(a));
587587 buf_index += 1;
588588 } else if (a < 100) {
589589 const i: u32 = a << 1;
......@@ -592,7 +592,7 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
592592 buffer[buf_index] = c_digits_lut[i + 1];
593593 buf_index += 1;
594594 } else if (a < 1000) {
595 buffer[buf_index] = '0' + @intCast(u8, a / 100);
595 buffer[buf_index] = '0' + @as(u8, @intCast(a / 100));
596596 buf_index += 1;
597597
598598 const i: u32 = (a % 100) << 1;
......@@ -613,8 +613,8 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
613613 buf_index += 1;
614614 }
615615
616 const v0 = @intCast(u32, value / kTen8);
617 const v1 = @intCast(u32, value % kTen8);
616 const v0 = @as(u32, @intCast(value / kTen8));
617 const v1 = @as(u32, @intCast(value % kTen8));
618618
619619 const b0: u32 = v0 / 10000;
620620 const c0: u32 = v0 % 10000;
......@@ -672,10 +672,10 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
672672}
673673
674674fn fpeint(from: f64) u128 {
675 const bits = @bitCast(u64, from);
675 const bits = @as(u64, @bitCast(from));
676676 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));
679679}
680680
681681/// 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" {
7878 inline for ([_]type{ f16, f32, f64, f128 }) |T| {
7979 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))));
8282 try expectEqual(try parseFloat(T, "inF"), std.math.inf(T));
8383 try expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T));
8484 }
lib/std/fmt/parse_float/common.zig+5-5
......@@ -32,7 +32,7 @@ pub fn BiasedFp(comptime T: type) type {
3232
3333 pub fn toFloat(self: Self, comptime FloatT: type, negative: bool) FloatT {
3434 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);
3636 var f = floatFromUnsigned(FloatT, MantissaT, word);
3737 if (negative) f = -f;
3838 return f;
......@@ -42,10 +42,10 @@ pub fn BiasedFp(comptime T: type) type {
4242
4343pub fn floatFromUnsigned(comptime T: type, comptime MantissaT: type, v: MantissaT) T {
4444 return switch (T) {
45 f16 => @bitCast(f16, @truncate(u16, v)),
46 f32 => @bitCast(f32, @truncate(u32, v)),
47 f64 => @bitCast(f64, @truncate(u64, v)),
48 f128 => @bitCast(f128, v),
45 f16 => @as(f16, @bitCast(@as(u16, @truncate(v)))),
46 f32 => @as(f32, @bitCast(@as(u32, @truncate(v)))),
47 f64 => @as(f64, @bitCast(@as(u64, @truncate(v)))),
48 f128 => @as(f128, @bitCast(v)),
4949 else => unreachable,
5050 };
5151}
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) {
3636 }
3737
3838 // 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)));
4040 w = math.shl(u64, w, lz);
4141
4242 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) {
6262 }
6363 }
6464
65 const upper_bit = @intCast(i32, r.hi >> 63);
66 var mantissa = math.shr(u64, r.hi, upper_bit + 64 - @intCast(i32, float_info.mantissa_explicit_bits) - 3);
67 var power2 = power(@intCast(i32, q)) + upper_bit - @intCast(i32, lz) - float_info.minimum_exponent;
65 const upper_bit = @as(i32, @intCast(r.hi >> 63));
66 var mantissa = math.shr(u64, r.hi, upper_bit + 64 - @as(i32, @intCast(float_info.mantissa_explicit_bits)) - 3);
67 var power2 = power(@as(i32, @intCast(q))) + upper_bit - @as(i32, @intCast(lz)) - float_info.minimum_exponent;
6868 if (power2 <= 0) {
6969 if (-power2 + 1 >= 64) {
7070 // 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) {
9393 q >= float_info.min_exponent_round_to_even and
9494 q <= float_info.max_exponent_round_to_even and
9595 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)
9797 {
9898 // Zero the lowest bit, so we don't round up.
9999 mantissa &= ~@as(u64, 1);
......@@ -139,8 +139,8 @@ const U128 = struct {
139139 pub fn mul(a: u64, b: u64) U128 {
140140 const x = @as(u128, a) * b;
141141 return .{
142 .hi = @truncate(u64, x >> 64),
143 .lo = @truncate(u64, x),
142 .hi = @as(u64, @truncate(x >> 64)),
143 .lo = @as(u64, @truncate(x)),
144144 };
145145 }
146146};
......@@ -161,7 +161,7 @@ fn computeProductApprox(q: i64, w: u64, comptime precision: usize) U128 {
161161 // 5^q < 2^64, then the multiplication always provides an exact value.
162162 // That means whenever we need to round ties to even, we always have
163163 // 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))));
165165 const pow5 = eisel_lemire_table_powers_of_five_128[index];
166166
167167 // 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 {
108108 var value: T = 0;
109109 if (n.exponent <= info.max_exponent_fast_path) {
110110 // normal fast path
111 value = @floatFromInt(T, n.mantissa);
111 value = @as(T, @floatFromInt(n.mantissa));
112112 value = if (n.exponent < 0)
113 value / fastPow10(T, @intCast(usize, -n.exponent))
113 value / fastPow10(T, @as(usize, @intCast(-n.exponent)))
114114 else
115 value * fastPow10(T, @intCast(usize, n.exponent));
115 value * fastPow10(T, @as(usize, @intCast(n.exponent)));
116116 } else {
117117 // disguised fast path
118118 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;
120120 if (mantissa > info.max_mantissa_fast_path) {
121121 return null;
122122 }
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);
124124 }
125125
126126 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 {
8181 }
8282
8383 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;
8585 if (n.negative) {
8686 bits |= 1 << (mantissa_bits + exp_bits);
8787 }
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) {
4848 var exp2: i32 = 0;
4949 // Shift right toward (1/2 .. 1]
5050 while (d.decimal_point > 0) {
51 const n = @intCast(usize, d.decimal_point);
51 const n = @as(usize, @intCast(d.decimal_point));
5252 const shift = getShift(n);
5353 d.rightShift(shift);
5454 if (d.decimal_point < -Decimal(T).decimal_point_range) {
5555 return BiasedFp(T).zero();
5656 }
57 exp2 += @intCast(i32, shift);
57 exp2 += @as(i32, @intCast(shift));
5858 }
5959 // Shift left toward (1/2 .. 1]
6060 while (d.decimal_point <= 0) {
......@@ -66,7 +66,7 @@ pub fn convertSlow(comptime T: type, s: []const u8) BiasedFp(T) {
6666 else => 1,
6767 };
6868 } else {
69 const n = @intCast(usize, -d.decimal_point);
69 const n = @as(usize, @intCast(-d.decimal_point));
7070 break :blk getShift(n);
7171 }
7272 };
......@@ -74,17 +74,17 @@ pub fn convertSlow(comptime T: type, s: []const u8) BiasedFp(T) {
7474 if (d.decimal_point > Decimal(T).decimal_point_range) {
7575 return BiasedFp(T).inf(T);
7676 }
77 exp2 -= @intCast(i32, shift);
77 exp2 -= @as(i32, @intCast(shift));
7878 }
7979 // We are now in the range [1/2 .. 1] but the binary format uses [1 .. 2]
8080 exp2 -= 1;
8181 while (min_exponent + 1 > exp2) {
82 var n = @intCast(usize, (min_exponent + 1) - exp2);
82 var n = @as(usize, @intCast((min_exponent + 1) - exp2));
8383 if (n > max_shift) {
8484 n = max_shift;
8585 }
8686 d.rightShift(n);
87 exp2 += @intCast(i32, n);
87 exp2 += @as(i32, @intCast(n));
8888 }
8989 if (exp2 - min_exponent >= infinite_power) {
9090 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 {
114114 return math.maxInt(MantissaT);
115115 }
116116
117 const dp = @intCast(usize, self.decimal_point);
117 const dp = @as(usize, @intCast(self.decimal_point));
118118 var n: MantissaT = 0;
119119
120120 var i: usize = 0;
......@@ -155,7 +155,7 @@ pub fn Decimal(comptime T: type) type {
155155 const quotient = n / 10;
156156 const remainder = n - (10 * quotient);
157157 if (write_index < max_digits) {
158 self.digits[write_index] = @intCast(u8, remainder);
158 self.digits[write_index] = @as(u8, @intCast(remainder));
159159 } else if (remainder > 0) {
160160 self.truncated = true;
161161 }
......@@ -167,7 +167,7 @@ pub fn Decimal(comptime T: type) type {
167167 const quotient = n / 10;
168168 const remainder = n - (10 * quotient);
169169 if (write_index < max_digits) {
170 self.digits[write_index] = @intCast(u8, remainder);
170 self.digits[write_index] = @as(u8, @intCast(remainder));
171171 } else if (remainder > 0) {
172172 self.truncated = true;
173173 }
......@@ -178,7 +178,7 @@ pub fn Decimal(comptime T: type) type {
178178 if (self.num_digits > max_digits) {
179179 self.num_digits = max_digits;
180180 }
181 self.decimal_point += @intCast(i32, num_new_digits);
181 self.decimal_point += @as(i32, @intCast(num_new_digits));
182182 self.trim();
183183 }
184184
......@@ -202,7 +202,7 @@ pub fn Decimal(comptime T: type) type {
202202 }
203203 }
204204
205 self.decimal_point -= @intCast(i32, read_index) - 1;
205 self.decimal_point -= @as(i32, @intCast(read_index)) - 1;
206206 if (self.decimal_point < -decimal_point_range) {
207207 self.num_digits = 0;
208208 self.decimal_point = 0;
......@@ -212,14 +212,14 @@ pub fn Decimal(comptime T: type) type {
212212
213213 const mask = math.shl(MantissaT, 1, shift) - 1;
214214 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)));
216216 n = (10 * (n & mask)) + self.digits[read_index];
217217 read_index += 1;
218218 self.digits[write_index] = new_digit;
219219 write_index += 1;
220220 }
221221 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)));
223223 n = 10 * (n & mask);
224224 if (write_index < max_digits) {
225225 self.digits[write_index] = new_digit;
......@@ -268,7 +268,7 @@ pub fn Decimal(comptime T: type) type {
268268 while (stream.scanDigit(10)) |digit| {
269269 d.tryAddDigit(digit);
270270 }
271 d.decimal_point = @intCast(i32, marker) - @intCast(i32, stream.offsetTrue());
271 d.decimal_point = @as(i32, @intCast(marker)) - @as(i32, @intCast(stream.offsetTrue()));
272272 }
273273 if (d.num_digits != 0) {
274274 // Ignore trailing zeros if any
......@@ -284,9 +284,9 @@ pub fn Decimal(comptime T: type) type {
284284 i -= 1;
285285 if (i == 0) break;
286286 }
287 d.decimal_point += @intCast(i32, n_trailing_zeros);
287 d.decimal_point += @as(i32, @intCast(n_trailing_zeros));
288288 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));
290290 if (d.num_digits > max_digits) {
291291 d.truncated = true;
292292 d.num_digits = max_digits;
lib/std/fmt/parse_float/parse.zig+7-7
......@@ -21,7 +21,7 @@ fn parse8Digits(v_: u64) u64 {
2121 v = (v * 10) + (v >> 8); // will not overflow, fits in 63 bits
2222 const v1 = (v & mask) *% mul1;
2323 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)));
2525}
2626
2727/// Parse digits until a non-digit character is found.
......@@ -106,7 +106,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
106106 var mantissa: MantissaT = 0;
107107 tryParseDigits(MantissaT, stream, &mantissa, info.base);
108108 var int_end = stream.offsetTrue();
109 var n_digits = @intCast(isize, stream.offsetTrue());
109 var n_digits = @as(isize, @intCast(stream.offsetTrue()));
110110 // the base being 16 implies a 0x prefix, which shouldn't be included in the digit count
111111 if (info.base == 16) n_digits -= 2;
112112
......@@ -117,8 +117,8 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
117117 const marker = stream.offsetTrue();
118118 tryParseDigits(MantissaT, stream, &mantissa, info.base);
119119 const n_after_dot = stream.offsetTrue() - marker;
120 exponent = -@intCast(i64, n_after_dot);
121 n_digits += @intCast(isize, n_after_dot);
120 exponent = -@as(i64, @intCast(n_after_dot));
121 n_digits += @as(isize, @intCast(n_after_dot));
122122 }
123123
124124 // adjust required shift to offset mantissa for base-16 (2^4)
......@@ -163,7 +163,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
163163 // '0' = '.' + 2
164164 const next = stream.firstUnchecked();
165165 if (next != '_') {
166 n_digits -= @intCast(isize, next -| ('0' - 1));
166 n_digits -= @as(isize, @intCast(next -| ('0' - 1)));
167167 } else {
168168 stream.underscore_count += 1;
169169 }
......@@ -179,7 +179,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
179179 exponent = blk: {
180180 if (mantissa >= min_n_digit_int(MantissaT, info.max_mantissa_digits)) {
181181 // 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()));
183183 } else {
184184 // the next byte must be present and be '.'
185185 // We know this is true because we had more than 19
......@@ -190,7 +190,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
190190 stream.advance(1);
191191 var marker = stream.offsetTrue();
192192 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()));
194194 }
195195 };
196196 // add back the explicit part
lib/std/fs.zig+18-19
......@@ -373,13 +373,13 @@ pub const IterableDir = struct {
373373 }
374374 }
375375 self.index = 0;
376 self.end_index = @intCast(usize, rc);
376 self.end_index = @as(usize, @intCast(rc));
377377 }
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]));
379379 const next_index = self.index + darwin_entry.reclen();
380380 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
384384 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or (darwin_entry.d_ino == 0)) {
385385 continue :start_over;
......@@ -421,13 +421,13 @@ pub const IterableDir = struct {
421421 }
422422 if (rc == 0) return null;
423423 self.index = 0;
424 self.end_index = @intCast(usize, rc);
424 self.end_index = @as(usize, @intCast(rc));
425425 }
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]));
427427 const next_index = self.index + entry.reclen();
428428 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);
431431 if (mem.eql(u8, name, ".") or mem.eql(u8, name, ".."))
432432 continue :start_over;
433433
......@@ -485,13 +485,13 @@ pub const IterableDir = struct {
485485 }
486486 if (rc == 0) return null;
487487 self.index = 0;
488 self.end_index = @intCast(usize, rc);
488 self.end_index = @as(usize, @intCast(rc));
489489 }
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]));
491491 const next_index = self.index + bsd_entry.reclen();
492492 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
496496 const skip_zero_fileno = switch (builtin.os.tag) {
497497 // d_fileno=0 is used to mark invalid entries or deleted files.
......@@ -567,12 +567,12 @@ pub const IterableDir = struct {
567567 }
568568 }
569569 self.index = 0;
570 self.end_index = @intCast(usize, rc);
570 self.end_index = @as(usize, @intCast(rc));
571571 }
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]));
573573 const next_index = self.index + haiku_entry.reclen();
574574 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
577577 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or (haiku_entry.d_ino == 0)) {
578578 continue :start_over;
......@@ -672,11 +672,11 @@ pub const IterableDir = struct {
672672 self.index = 0;
673673 self.end_index = rc;
674674 }
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]));
676676 const next_index = self.index + linux_entry.reclen();
677677 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
681681 // skip . and .. entries
682682 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {
......@@ -750,15 +750,14 @@ pub const IterableDir = struct {
750750 }
751751 }
752752
753 const aligned_ptr = @alignCast(@alignOf(w.FILE_BOTH_DIR_INFORMATION), &self.buf[self.index]);
754 const dir_info = @ptrCast(*w.FILE_BOTH_DIR_INFORMATION, aligned_ptr);
753 const dir_info: *w.FILE_BOTH_DIR_INFORMATION = @ptrCast(@alignCast(&self.buf[self.index]));
755754 if (dir_info.NextEntryOffset != 0) {
756755 self.index += dir_info.NextEntryOffset;
757756 } else {
758757 self.index = self.buf.len;
759758 }
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
763762 if (mem.eql(u16, name_utf16le, &[_]u16{'.'}) or mem.eql(u16, name_utf16le, &[_]u16{ '.', '.' }))
764763 continue;
......@@ -835,7 +834,7 @@ pub const IterableDir = struct {
835834 self.index = 0;
836835 self.end_index = bufused;
837836 }
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]));
839838 const entry_size = @sizeOf(w.dirent_t);
840839 const name_index = self.index + entry_size;
841840 if (name_index + entry.d_namlen > self.end_index) {
......@@ -1789,7 +1788,7 @@ pub const Dir = struct {
17891788 .fd = undefined,
17901789 };
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));
17931792 var nt_name = w.UNICODE_STRING{
17941793 .Length = path_len_bytes,
17951794 .MaximumLength = path_len_bytes,
lib/std/fs/file.zig+9-9
......@@ -368,7 +368,7 @@ pub const File = struct {
368368
369369 return Stat{
370370 .inode = st.ino,
371 .size = @bitCast(u64, st.size),
371 .size = @as(u64, @bitCast(st.size)),
372372 .mode = st.mode,
373373 .kind = kind,
374374 .atime = @as(i128, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
......@@ -398,7 +398,7 @@ pub const File = struct {
398398 }
399399 return Stat{
400400 .inode = info.InternalInformation.IndexNumber,
401 .size = @bitCast(u64, info.StandardInformation.EndOfFile),
401 .size = @as(u64, @bitCast(info.StandardInformation.EndOfFile)),
402402 .mode = 0,
403403 .kind = if (info.StandardInformation.Directory == 0) .file else .directory,
404404 .atime = windows.fromSysTime(info.BasicInformation.LastAccessTime),
......@@ -650,7 +650,7 @@ pub const File = struct {
650650
651651 /// Returns the size of the file
652652 pub fn size(self: Self) u64 {
653 return @intCast(u64, self.stat.size);
653 return @as(u64, @intCast(self.stat.size));
654654 }
655655
656656 /// Returns a `Permissions` struct, representing the permissions on the file
......@@ -855,7 +855,7 @@ pub const File = struct {
855855 if (info.BasicInformation.FileAttributes & windows.FILE_ATTRIBUTE_REPARSE_POINT != 0) {
856856 var reparse_buf: [windows.MAXIMUM_REPARSE_DATA_BUFFER_SIZE]u8 = undefined;
857857 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]));
859859 break :reparse_blk reparse_struct.ReparseTag;
860860 }
861861 break :reparse_blk 0;
......@@ -864,7 +864,7 @@ pub const File = struct {
864864 break :blk MetadataWindows{
865865 .attributes = info.BasicInformation.FileAttributes,
866866 .reparse_tag = reparse_tag,
867 ._size = @bitCast(u64, info.StandardInformation.EndOfFile),
867 ._size = @as(u64, @bitCast(info.StandardInformation.EndOfFile)),
868868 .access_time = windows.fromSysTime(info.BasicInformation.LastAccessTime),
869869 .modified_time = windows.fromSysTime(info.BasicInformation.LastWriteTime),
870870 .creation_time = windows.fromSysTime(info.BasicInformation.CreationTime),
......@@ -881,16 +881,16 @@ pub const File = struct {
881881 .NOSYS => {
882882 const st = try os.fstat(self.handle);
883883
884 stx.mode = @intCast(u16, st.mode);
884 stx.mode = @as(u16, @intCast(st.mode));
885885
886886 // Hacky conversion from timespec to statx_timestamp
887887 stx.atime = std.mem.zeroes(os.linux.statx_timestamp);
888888 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
891891 stx.mtime = std.mem.zeroes(os.linux.statx_timestamp);
892892 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
895895 stx.mask = os.linux.STATX_BASIC_STATS | os.linux.STATX_MTIME;
896896 },
......@@ -1414,7 +1414,7 @@ pub const File = struct {
14141414 amt = try os.sendfile(out_fd, in_fd, offset + off, count - off, zero_iovec, trailers, flags);
14151415 off += amt;
14161416 }
1417 amt = @intCast(usize, off - count);
1417 amt = @as(usize, @intCast(off - count));
14181418 }
14191419 var i: usize = 0;
14201420 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
2323 &dir_path_ptr,
2424 )) {
2525 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)));
2727 const global_dir = unicode.utf16leToUtf8Alloc(allocator, mem.sliceTo(dir_path_ptr, 0)) catch |err| switch (err) {
2828 error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
2929 error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
lib/std/fs/wasi.zig+2-2
......@@ -17,7 +17,7 @@ pub const Preopens = struct {
1717 pub fn find(p: Preopens, name: []const u8) ?os.fd_t {
1818 for (p.names, 0..) |elem_name, i| {
1919 if (mem.eql(u8, elem_name, name)) {
20 return @intCast(os.fd_t, i);
20 return @as(os.fd_t, @intCast(i));
2121 }
2222 }
2323 return null;
......@@ -34,7 +34,7 @@ pub fn preopensAlloc(gpa: Allocator) Allocator.Error!Preopens {
3434 names.appendAssumeCapacity("stdout"); // 1
3535 names.appendAssumeCapacity("stderr"); // 2
3636 while (true) {
37 const fd = @intCast(wasi.fd_t, names.items.len);
37 const fd = @as(wasi.fd_t, @intCast(names.items.len));
3838 var prestat: prestat_t = undefined;
3939 switch (wasi.fd_prestat_get(fd, &prestat)) {
4040 .SUCCESS => {},
lib/std/fs/watch.zig+8-8
......@@ -279,7 +279,7 @@ pub fn Watch(comptime V: type) type {
279279
280280 while (!put.cancelled) {
281281 kev.* = os.Kevent{
282 .ident = @intCast(usize, fd),
282 .ident = @as(usize, @intCast(fd)),
283283 .filter = os.EVFILT_VNODE,
284284 .flags = os.EV_ADD | os.EV_ENABLE | os.EV_CLEAR | os.EV_ONESHOT |
285285 os.NOTE_WRITE | os.NOTE_DELETE | os.NOTE_REVOKE,
......@@ -487,14 +487,14 @@ pub fn Watch(comptime V: type) type {
487487 var ptr: [*]u8 = &event_buf;
488488 const end_ptr = ptr + bytes_transferred;
489489 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));
491491 const emit = switch (ev.Action) {
492492 windows.FILE_ACTION_REMOVED => WatchEventId.Delete,
493493 windows.FILE_ACTION_MODIFIED => .CloseWrite,
494494 else => null,
495495 };
496496 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)));
498498 const basename_utf16le = basename_ptr[0 .. ev.FileNameLength / 2];
499499 var basename_data: [std.fs.MAX_PATH_BYTES]u8 = undefined;
500500 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 {
510510 }
511511
512512 if (ev.NextEntryOffset == 0) break;
513 ptr = @alignCast(@alignOf(windows.FILE_NOTIFY_INFORMATION), ptr + ev.NextEntryOffset);
513 ptr = @alignCast(ptr + ev.NextEntryOffset);
514514 }
515515 }
516516 }
......@@ -586,10 +586,10 @@ pub fn Watch(comptime V: type) type {
586586 var ptr: [*]u8 = &event_buf;
587587 const end_ptr = ptr + bytes_read;
588588 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));
590590 if (ev.mask & os.linux.IN_CLOSE_WRITE == os.linux.IN_CLOSE_WRITE) {
591591 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
594594 const dir = &self.os_data.wd_table.get(ev.wd).?;
595595 if (dir.file_table.getEntry(basename)) |file_value| {
......@@ -615,7 +615,7 @@ pub fn Watch(comptime V: type) type {
615615 } else if (ev.mask & os.linux.IN_DELETE == os.linux.IN_DELETE) {
616616 // File or directory was removed or deleted
617617 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
620620 const dir = &self.os_data.wd_table.get(ev.wd).?;
621621 if (dir.file_table.getEntry(basename)) |file_value| {
......@@ -628,7 +628,7 @@ pub fn Watch(comptime V: type) type {
628628 }
629629 }
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);
632632 }
633633 }
634634 }
lib/std/hash/adler.zig+1-1
......@@ -118,7 +118,7 @@ test "adler32 very long with variation" {
118118
119119 var i: usize = 0;
120120 while (i < result.len) : (i += 1) {
121 result[i] = @truncate(u8, i);
121 result[i] = @as(u8, @truncate(i));
122122 }
123123
124124 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 {
9292 // Help the optimizer see that hashing an int is easy by inlining!
9393 // TODO Check if the situation is better after #561 is resolved.
9494 .Int => |int| switch (int.signedness) {
95 .signed => hash(hasher, @bitCast(@Type(.{ .Int = .{
95 .signed => hash(hasher, @as(@Type(.{ .Int = .{
9696 .bits = int.bits,
9797 .signedness = .unsigned,
98 } }), key), strat),
98 } }), @bitCast(key)), strat),
9999 .unsigned => {
100100 if (comptime meta.trait.hasUniqueRepresentation(Key)) {
101101 @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
122122 for (0..blocks_count) |i| {
123123 h.update(blocks[i * alignment ..][0..block_size]);
124124 }
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();
126126 std.mem.doNotOptimizeAway(final);
127127
128128 const end = timer.read();
129129
130 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;
131 const throughput = @intFromFloat(u64, @floatFromInt(f64, bytes) / elapsed_s);
130 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
131 const throughput = @as(u64, @intFromFloat(@as(f64, @floatFromInt(bytes)) / elapsed_s));
132132
133133 return Result{
134134 .hash = final,
......@@ -152,7 +152,7 @@ pub fn benchmarkHashSmallKeys(comptime H: anytype, key_size: usize, bytes: usize
152152 const final = blk: {
153153 if (H.init_u8s) |init| {
154154 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])));
156156 } else {
157157 break :blk H.ty.hash(init, small_key);
158158 }
......@@ -166,8 +166,8 @@ pub fn benchmarkHashSmallKeys(comptime H: anytype, key_size: usize, bytes: usize
166166 }
167167 const end = timer.read();
168168
169 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;
170 const throughput = @intFromFloat(u64, @floatFromInt(f64, bytes) / elapsed_s);
169 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
170 const throughput = @as(u64, @intFromFloat(@as(f64, @floatFromInt(bytes)) / elapsed_s));
171171
172172 std.mem.doNotOptimizeAway(sum);
173173
lib/std/hash/cityhash.zig+13-13
......@@ -2,7 +2,7 @@ const std = @import("std");
22
33inline fn offsetPtr(ptr: [*]const u8, offset: usize) [*]const u8 {
44 // 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]));
66}
77
88fn fetch32(ptr: [*]const u8, offset: usize) u32 {
......@@ -49,18 +49,18 @@ pub const CityHash32 = struct {
4949 }
5050
5151 fn hash32Len0To4(str: []const u8) u32 {
52 const len: u32 = @truncate(u32, str.len);
52 const len: u32 = @as(u32, @truncate(str.len));
5353 var b: u32 = 0;
5454 var c: u32 = 9;
5555 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))))));
5757 c ^= b;
5858 }
5959 return fmix(mur(b, mur(len, c)));
6060 }
6161
6262 fn hash32Len5To12(str: []const u8) u32 {
63 var a: u32 = @truncate(u32, str.len);
63 var a: u32 = @as(u32, @truncate(str.len));
6464 var b: u32 = a *% 5;
6565 var c: u32 = 9;
6666 const d: u32 = b;
......@@ -73,7 +73,7 @@ pub const CityHash32 = struct {
7373 }
7474
7575 fn hash32Len13To24(str: []const u8) u32 {
76 const len: u32 = @truncate(u32, str.len);
76 const len: u32 = @as(u32, @truncate(str.len));
7777 const a: u32 = fetch32(str.ptr, (str.len >> 1) - 4);
7878 const b: u32 = fetch32(str.ptr, 4);
7979 const c: u32 = fetch32(str.ptr, str.len - 8);
......@@ -95,7 +95,7 @@ pub const CityHash32 = struct {
9595 }
9696 }
9797
98 const len: u32 = @truncate(u32, str.len);
98 const len: u32 = @as(u32, @truncate(str.len));
9999 var h: u32 = len;
100100 var g: u32 = c1 *% len;
101101 var f: u32 = g;
......@@ -220,9 +220,9 @@ pub const CityHash64 = struct {
220220 const a: u8 = str[0];
221221 const b: u8 = str[str.len >> 1];
222222 const c: u8 = str[str.len - 1];
223 const y: u32 = @intCast(u32, a) +% (@intCast(u32, b) << 8);
224 const z: u32 = @truncate(u32, str.len) +% (@intCast(u32, c) << 2);
225 return shiftmix(@intCast(u64, y) *% k2 ^ @intCast(u64, z) *% k0) *% k2;
223 const y: u32 = @as(u32, @intCast(a)) +% (@as(u32, @intCast(b)) << 8);
224 const z: u32 = @as(u32, @truncate(str.len)) +% (@as(u32, @intCast(c)) << 2);
225 return shiftmix(@as(u64, @intCast(y)) *% k2 ^ @as(u64, @intCast(z)) *% k0) *% k2;
226226 }
227227 return k2;
228228 }
......@@ -309,7 +309,7 @@ pub const CityHash64 = struct {
309309 var w: WeakPair = weakHashLen32WithSeeds(offsetPtr(str.ptr, str.len - 32), y +% k1, x);
310310
311311 x = x *% k1 +% fetch64(str.ptr, 0);
312 len = (len - 1) & ~@intCast(u64, 63);
312 len = (len - 1) & ~@as(u64, @intCast(63));
313313
314314 var ptr: [*]const u8 = str.ptr;
315315 while (true) {
......@@ -353,19 +353,19 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {
353353
354354 var i: u32 = 0;
355355 while (i < 256) : (i += 1) {
356 key[i] = @intCast(u8, i);
356 key[i] = @as(u8, @intCast(i));
357357
358358 var h: HashResult = hash_fn(key[0..i], 256 - i);
359359
360360 // comptime can't really do reinterpret casting yet,
361361 // so we need to write the bytes manually.
362362 for (hashes_bytes[i * @sizeOf(HashResult) ..][0..@sizeOf(HashResult)]) |*byte| {
363 byte.* = @truncate(u8, h);
363 byte.* = @as(u8, @truncate(h));
364364 h = h >> 8;
365365 }
366366 }
367367
368 return @truncate(u32, hash_fn(&hashes_bytes, 0));
368 return @as(u32, @truncate(hash_fn(&hashes_bytes, 0)));
369369}
370370
371371fn 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 {
6565 }
6666
6767 inline fn tableEntry(index: I) I {
68 return lookup_table[@intCast(u8, index & 0xFF)];
68 return lookup_table[@as(u8, @intCast(index & 0xFF))];
6969 }
7070
7171 pub fn update(self: *Self, bytes: []const u8) void {
......@@ -95,7 +95,7 @@ pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type {
9595 if (!algorithm.reflect_output) {
9696 c >>= @bitSizeOf(I) - @bitSizeOf(W);
9797 }
98 return @intCast(W, c ^ algorithm.xor_output);
98 return @as(W, @intCast(c ^ algorithm.xor_output));
9999 }
100100
101101 pub fn hash(bytes: []const u8) W {
......@@ -125,7 +125,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type {
125125 var tables: [8][256]u32 = undefined;
126126
127127 for (&tables[0], 0..) |*e, i| {
128 var crc = @intCast(u32, i);
128 var crc = @as(u32, @intCast(i));
129129 var j: usize = 0;
130130 while (j < 8) : (j += 1) {
131131 if (crc & 1 == 1) {
......@@ -142,7 +142,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type {
142142 var crc = tables[0][i];
143143 var j: usize = 1;
144144 while (j < 8) : (j += 1) {
145 const index = @truncate(u8, crc);
145 const index = @as(u8, @truncate(crc));
146146 crc = tables[0][index] ^ (crc >> 8);
147147 tables[j][i] = crc;
148148 }
......@@ -170,14 +170,14 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type {
170170 lookup_tables[1][p[6]] ^
171171 lookup_tables[2][p[5]] ^
172172 lookup_tables[3][p[4]] ^
173 lookup_tables[4][@truncate(u8, self.crc >> 24)] ^
174 lookup_tables[5][@truncate(u8, self.crc >> 16)] ^
175 lookup_tables[6][@truncate(u8, self.crc >> 8)] ^
176 lookup_tables[7][@truncate(u8, self.crc >> 0)];
173 lookup_tables[4][@as(u8, @truncate(self.crc >> 24))] ^
174 lookup_tables[5][@as(u8, @truncate(self.crc >> 16))] ^
175 lookup_tables[6][@as(u8, @truncate(self.crc >> 8))] ^
176 lookup_tables[7][@as(u8, @truncate(self.crc >> 0))];
177177 }
178178
179179 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];
181181 self.crc = (self.crc >> 8) ^ lookup_tables[0][index];
182182 }
183183 }
......@@ -218,7 +218,7 @@ pub fn Crc32SmallWithPoly(comptime poly: Polynomial) type {
218218 var table: [16]u32 = undefined;
219219
220220 for (&table, 0..) |*e, i| {
221 var crc = @intCast(u32, i * 16);
221 var crc = @as(u32, @intCast(i * 16));
222222 var j: usize = 0;
223223 while (j < 8) : (j += 1) {
224224 if (crc & 1 == 1) {
......@@ -241,8 +241,8 @@ pub fn Crc32SmallWithPoly(comptime poly: Polynomial) type {
241241
242242 pub fn update(self: *Self, input: []const u8) void {
243243 for (input) |b| {
244 self.crc = lookup_table[@truncate(u4, self.crc ^ (b >> 0))] ^ (self.crc >> 4);
245 self.crc = lookup_table[@truncate(u4, self.crc ^ (b >> 4))] ^ (self.crc >> 4);
244 self.crc = lookup_table[@as(u4, @truncate(self.crc ^ (b >> 0)))] ^ (self.crc >> 4);
245 self.crc = lookup_table[@as(u4, @truncate(self.crc ^ (b >> 4)))] ^ (self.crc >> 4);
246246 }
247247 }
248248
lib/std/hash/murmur.zig+25-25
......@@ -14,9 +14,9 @@ pub const Murmur2_32 = struct {
1414
1515 pub fn hashWithSeed(str: []const u8, seed: u32) u32 {
1616 const m: u32 = 0x5bd1e995;
17 const len = @truncate(u32, str.len);
17 const len = @as(u32, @truncate(str.len));
1818 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| {
2020 var k1: u32 = v;
2121 if (native_endian == .Big)
2222 k1 = @byteSwap(k1);
......@@ -29,13 +29,13 @@ pub const Murmur2_32 = struct {
2929 const offset = len & 0xfffffffc;
3030 const rest = len & 3;
3131 if (rest >= 3) {
32 h1 ^= @intCast(u32, str[offset + 2]) << 16;
32 h1 ^= @as(u32, @intCast(str[offset + 2])) << 16;
3333 }
3434 if (rest >= 2) {
35 h1 ^= @intCast(u32, str[offset + 1]) << 8;
35 h1 ^= @as(u32, @intCast(str[offset + 1])) << 8;
3636 }
3737 if (rest >= 1) {
38 h1 ^= @intCast(u32, str[offset + 0]);
38 h1 ^= @as(u32, @intCast(str[offset + 0]));
3939 h1 *%= m;
4040 }
4141 h1 ^= h1 >> 13;
......@@ -73,12 +73,12 @@ pub const Murmur2_32 = struct {
7373 const len: u32 = 8;
7474 var h1: u32 = seed ^ len;
7575 var k1: u32 = undefined;
76 k1 = @truncate(u32, v) *% m;
76 k1 = @as(u32, @truncate(v)) *% m;
7777 k1 ^= k1 >> 24;
7878 k1 *%= m;
7979 h1 *%= m;
8080 h1 ^= k1;
81 k1 = @truncate(u32, v >> 32) *% m;
81 k1 = @as(u32, @truncate(v >> 32)) *% m;
8282 k1 ^= k1 >> 24;
8383 k1 *%= m;
8484 h1 *%= m;
......@@ -100,7 +100,7 @@ pub const Murmur2_64 = struct {
100100 pub fn hashWithSeed(str: []const u8, seed: u64) u64 {
101101 const m: u64 = 0xc6a4a7935bd1e995;
102102 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| {
104104 var k1: u64 = v;
105105 if (native_endian == .Big)
106106 k1 = @byteSwap(k1);
......@@ -114,7 +114,7 @@ pub const Murmur2_64 = struct {
114114 const offset = str.len - rest;
115115 if (rest > 0) {
116116 var k1: u64 = 0;
117 @memcpy(@ptrCast([*]u8, &k1)[0..rest], str[offset..]);
117 @memcpy(@as([*]u8, @ptrCast(&k1))[0..rest], str[offset..]);
118118 if (native_endian == .Big)
119119 k1 = @byteSwap(k1);
120120 h1 ^= k1;
......@@ -178,9 +178,9 @@ pub const Murmur3_32 = struct {
178178 pub fn hashWithSeed(str: []const u8, seed: u32) u32 {
179179 const c1: u32 = 0xcc9e2d51;
180180 const c2: u32 = 0x1b873593;
181 const len = @truncate(u32, str.len);
181 const len = @as(u32, @truncate(str.len));
182182 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| {
184184 var k1: u32 = v;
185185 if (native_endian == .Big)
186186 k1 = @byteSwap(k1);
......@@ -197,13 +197,13 @@ pub const Murmur3_32 = struct {
197197 const offset = len & 0xfffffffc;
198198 const rest = len & 3;
199199 if (rest == 3) {
200 k1 ^= @intCast(u32, str[offset + 2]) << 16;
200 k1 ^= @as(u32, @intCast(str[offset + 2])) << 16;
201201 }
202202 if (rest >= 2) {
203 k1 ^= @intCast(u32, str[offset + 1]) << 8;
203 k1 ^= @as(u32, @intCast(str[offset + 1])) << 8;
204204 }
205205 if (rest >= 1) {
206 k1 ^= @intCast(u32, str[offset + 0]);
206 k1 ^= @as(u32, @intCast(str[offset + 0]));
207207 k1 *%= c1;
208208 k1 = rotl32(k1, 15);
209209 k1 *%= c2;
......@@ -255,14 +255,14 @@ pub const Murmur3_32 = struct {
255255 const len: u32 = 8;
256256 var h1: u32 = seed;
257257 var k1: u32 = undefined;
258 k1 = @truncate(u32, v) *% c1;
258 k1 = @as(u32, @truncate(v)) *% c1;
259259 k1 = rotl32(k1, 15);
260260 k1 *%= c2;
261261 h1 ^= k1;
262262 h1 = rotl32(h1, 13);
263263 h1 *%= 5;
264264 h1 +%= 0xe6546b64;
265 k1 = @truncate(u32, v >> 32) *% c1;
265 k1 = @as(u32, @truncate(v >> 32)) *% c1;
266266 k1 = rotl32(k1, 15);
267267 k1 *%= c2;
268268 h1 ^= k1;
......@@ -286,15 +286,15 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {
286286
287287 var i: u32 = 0;
288288 while (i < 256) : (i += 1) {
289 key[i] = @truncate(u8, i);
289 key[i] = @as(u8, @truncate(i));
290290
291291 var h = hash_fn(key[0..i], 256 - i);
292292 if (native_endian == .Big)
293293 h = @byteSwap(h);
294 @memcpy(hashes[i * hashbytes ..][0..hashbytes], @ptrCast([*]u8, &h));
294 @memcpy(hashes[i * hashbytes ..][0..hashbytes], @as([*]u8, @ptrCast(&h)));
295295 }
296296
297 return @truncate(u32, hash_fn(&hashes, 0));
297 return @as(u32, @truncate(hash_fn(&hashes, 0)));
298298}
299299
300300test "murmur2_32" {
......@@ -307,8 +307,8 @@ test "murmur2_32" {
307307 v0le = @byteSwap(v0le);
308308 v1le = @byteSwap(v1le);
309309 }
310 try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0));
311 try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1));
310 try testing.expectEqual(Murmur2_32.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur2_32.hashUint32(v0));
311 try testing.expectEqual(Murmur2_32.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur2_32.hashUint64(v1));
312312}
313313
314314test "murmur2_64" {
......@@ -321,8 +321,8 @@ test "murmur2_64" {
321321 v0le = @byteSwap(v0le);
322322 v1le = @byteSwap(v1le);
323323 }
324 try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0));
325 try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1));
324 try testing.expectEqual(Murmur2_64.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur2_64.hashUint32(v0));
325 try testing.expectEqual(Murmur2_64.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur2_64.hashUint64(v1));
326326}
327327
328328test "murmur3_32" {
......@@ -335,6 +335,6 @@ test "murmur3_32" {
335335 v0le = @byteSwap(v0le);
336336 v1le = @byteSwap(v1le);
337337 }
338 try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0));
339 try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur3_32.hashUint64(v1));
338 try testing.expectEqual(Murmur3_32.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur3_32.hashUint32(v0));
339 try testing.expectEqual(Murmur3_32.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur3_32.hashUint64(v1));
340340}
lib/std/hash/wyhash.zig+3-3
......@@ -132,8 +132,8 @@ pub const Wyhash = struct {
132132
133133 inline fn mum(a: *u64, b: *u64) void {
134134 const x = @as(u128, a.*) *% b.*;
135 a.* = @truncate(u64, x);
136 b.* = @truncate(u64, x >> 64);
135 a.* = @as(u64, @truncate(x));
136 b.* = @as(u64, @truncate(x >> 64));
137137 }
138138
139139 inline fn mix(a_: u64, b_: u64) u64 {
......@@ -252,7 +252,7 @@ test "test ensure idempotent final call" {
252252test "iterative non-divisible update" {
253253 var buf: [8192]u8 = undefined;
254254 for (&buf, 0..) |*e, i| {
255 e.* = @truncate(u8, i);
255 e.* = @as(u8, @truncate(i));
256256 }
257257
258258 const seed = 0x128dad08f;
lib/std/hash/xxhash.zig+1-1
......@@ -212,7 +212,7 @@ pub const XxHash32 = struct {
212212 rotl(u32, self.acc3, 12) +% rotl(u32, self.acc4, 18);
213213 }
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
217217 var pos: usize = 0;
218218 while (pos + 4 <= self.buf_len) : (pos += 4) {
lib/std/hash_map.zig+22-22
......@@ -101,7 +101,7 @@ pub const StringIndexContext = struct {
101101 }
102102
103103 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);
105105 return hashString(x_slice);
106106 }
107107};
......@@ -110,7 +110,7 @@ pub const StringIndexAdapter = struct {
110110 bytes: *std.ArrayListUnmanaged(u8),
111111
112112 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);
114114 return mem.eql(u8, a_slice, b_slice);
115115 }
116116
......@@ -777,25 +777,25 @@ pub fn HashMapUnmanaged(
777777 fingerprint: FingerPrint = free,
778778 used: u1 = 0,
779779
780 const slot_free = @bitCast(u8, Metadata{ .fingerprint = free });
781 const slot_tombstone = @bitCast(u8, Metadata{ .fingerprint = tombstone });
780 const slot_free = @as(u8, @bitCast(Metadata{ .fingerprint = free }));
781 const slot_tombstone = @as(u8, @bitCast(Metadata{ .fingerprint = tombstone }));
782782
783783 pub fn isUsed(self: Metadata) bool {
784784 return self.used == 1;
785785 }
786786
787787 pub fn isTombstone(self: Metadata) bool {
788 return @bitCast(u8, self) == slot_tombstone;
788 return @as(u8, @bitCast(self)) == slot_tombstone;
789789 }
790790
791791 pub fn isFree(self: Metadata) bool {
792 return @bitCast(u8, self) == slot_free;
792 return @as(u8, @bitCast(self)) == slot_free;
793793 }
794794
795795 pub fn takeFingerprint(hash: Hash) FingerPrint {
796796 const hash_bits = @typeInfo(Hash).Int.bits;
797797 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)));
799799 }
800800
801801 pub fn fill(self: *Metadata, fp: FingerPrint) void {
......@@ -899,7 +899,7 @@ pub fn HashMapUnmanaged(
899899 }
900900
901901 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));
903903 new_cap = math.ceilPowerOfTwo(u32, new_cap) catch unreachable;
904904 return new_cap;
905905 }
......@@ -927,7 +927,7 @@ pub fn HashMapUnmanaged(
927927 if (self.metadata) |_| {
928928 self.initMetadatas();
929929 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));
931931 }
932932 }
933933
......@@ -942,7 +942,7 @@ pub fn HashMapUnmanaged(
942942 }
943943
944944 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);
946946 }
947947
948948 fn keys(self: *const Self) [*]K {
......@@ -1033,7 +1033,7 @@ pub fn HashMapUnmanaged(
10331033
10341034 const hash = ctx.hash(key);
10351035 const mask = self.capacity() - 1;
1036 var idx = @truncate(usize, hash & mask);
1036 var idx = @as(usize, @truncate(hash & mask));
10371037
10381038 var metadata = self.metadata.? + idx;
10391039 while (metadata[0].isUsed()) {
......@@ -1147,7 +1147,7 @@ pub fn HashMapUnmanaged(
11471147 const fingerprint = Metadata.takeFingerprint(hash);
11481148 // Don't loop indefinitely when there are no empty slots.
11491149 var limit = self.capacity();
1150 var idx = @truncate(usize, hash & mask);
1150 var idx = @as(usize, @truncate(hash & mask));
11511151
11521152 var metadata = self.metadata.? + idx;
11531153 while (!metadata[0].isFree() and limit != 0) {
......@@ -1325,7 +1325,7 @@ pub fn HashMapUnmanaged(
13251325 const mask = self.capacity() - 1;
13261326 const fingerprint = Metadata.takeFingerprint(hash);
13271327 var limit = self.capacity();
1328 var idx = @truncate(usize, hash & mask);
1328 var idx = @as(usize, @truncate(hash & mask));
13291329
13301330 var first_tombstone_idx: usize = self.capacity(); // invalid index
13311331 var metadata = self.metadata.? + idx;
......@@ -1450,7 +1450,7 @@ pub fn HashMapUnmanaged(
14501450 }
14511451
14521452 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);
14541454 }
14551455
14561456 // This counts the number of occupied slots (not counting tombstones), which is
......@@ -1458,7 +1458,7 @@ pub fn HashMapUnmanaged(
14581458 fn load(self: *const Self) Size {
14591459 const max_load = (self.capacity() * max_load_percentage) / 100;
14601460 assert(max_load >= self.available);
1461 return @truncate(Size, max_load - self.available);
1461 return @as(Size, @truncate(max_load - self.available));
14621462 }
14631463
14641464 fn growIfNeeded(self: *Self, allocator: Allocator, new_count: Size, ctx: Context) Allocator.Error!void {
......@@ -1480,7 +1480,7 @@ pub fn HashMapUnmanaged(
14801480 const new_cap = capacityForSize(self.size);
14811481 try other.allocate(allocator, new_cap);
14821482 other.initMetadatas();
1483 other.available = @truncate(u32, (new_cap * max_load_percentage) / 100);
1483 other.available = @as(u32, @truncate((new_cap * max_load_percentage) / 100));
14841484
14851485 var i: Size = 0;
14861486 var metadata = self.metadata.?;
......@@ -1515,7 +1515,7 @@ pub fn HashMapUnmanaged(
15151515 defer map.deinit(allocator);
15161516 try map.allocate(allocator, new_cap);
15171517 map.initMetadatas();
1518 map.available = @truncate(u32, (new_cap * max_load_percentage) / 100);
1518 map.available = @as(u32, @truncate((new_cap * max_load_percentage) / 100));
15191519
15201520 if (self.size != 0) {
15211521 const old_capacity = self.capacity();
......@@ -1558,15 +1558,15 @@ pub fn HashMapUnmanaged(
15581558
15591559 const metadata = ptr + @sizeOf(Header);
15601560
1561 const hdr = @ptrFromInt(*Header, ptr);
1561 const hdr = @as(*Header, @ptrFromInt(ptr));
15621562 if (@sizeOf([*]V) != 0) {
1563 hdr.values = @ptrFromInt([*]V, ptr + vals_start);
1563 hdr.values = @as([*]V, @ptrFromInt(ptr + vals_start));
15641564 }
15651565 if (@sizeOf([*]K) != 0) {
1566 hdr.keys = @ptrFromInt([*]K, ptr + keys_start);
1566 hdr.keys = @as([*]K, @ptrFromInt(ptr + keys_start));
15671567 }
15681568 hdr.capacity = new_capacity;
1569 self.metadata = @ptrFromInt([*]Metadata, metadata);
1569 self.metadata = @as([*]Metadata, @ptrFromInt(metadata));
15701570 }
15711571
15721572 fn deallocate(self: *Self, allocator: Allocator) void {
......@@ -1589,7 +1589,7 @@ pub fn HashMapUnmanaged(
15891589
15901590 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];
15931593 allocator.free(slice);
15941594
15951595 self.metadata = null;
lib/std/heap.zig+25-25
......@@ -61,11 +61,11 @@ const CAllocator = struct {
6161 pub const supports_posix_memalign = @hasDecl(c, "posix_memalign");
6262
6363 fn getHeader(ptr: [*]u8) *[*]u8 {
64 return @ptrFromInt(*[*]u8, @intFromPtr(ptr) - @sizeOf(usize));
64 return @as(*[*]u8, @ptrFromInt(@intFromPtr(ptr) - @sizeOf(usize)));
6565 }
6666
6767 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));
6969 if (supports_posix_memalign) {
7070 // The posix_memalign only accepts alignment values that are a
7171 // multiple of the pointer size
......@@ -75,13 +75,13 @@ const CAllocator = struct {
7575 if (c.posix_memalign(&aligned_ptr, eff_alignment, len) != 0)
7676 return null;
7777
78 return @ptrCast([*]u8, aligned_ptr);
78 return @as([*]u8, @ptrCast(aligned_ptr));
7979 }
8080
8181 // Thin wrapper around regular malloc, overallocate to account for
8282 // alignment padding and store the original malloc()'ed pointer before
8383 // 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));
8585 const unaligned_addr = @intFromPtr(unaligned_ptr);
8686 const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), alignment);
8787 var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
......@@ -195,7 +195,7 @@ fn rawCAlloc(
195195 // type in C that is size 8 and has 16 byte alignment, so the alignment may
196196 // be 8 bytes rather than 16. Similarly if only 1 byte is requested, malloc
197197 // is allowed to return a 1-byte aligned pointer.
198 return @ptrCast(?[*]u8, c.malloc(len));
198 return @as(?[*]u8, @ptrCast(c.malloc(len)));
199199}
200200
201201fn rawCResize(
......@@ -283,7 +283,7 @@ pub const HeapAllocator = switch (builtin.os.tag) {
283283 }
284284
285285 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));
287287 }
288288
289289 fn alloc(
......@@ -293,9 +293,9 @@ pub const HeapAllocator = switch (builtin.os.tag) {
293293 return_address: usize,
294294 ) ?[*]u8 {
295295 _ = 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));
299299 const amt = n + ptr_align - 1 + @sizeOf(usize);
300300 const optional_heap_handle = @atomicLoad(?HeapHandle, &self.heap_handle, .SeqCst);
301301 const heap_handle = optional_heap_handle orelse blk: {
......@@ -308,7 +308,7 @@ pub const HeapAllocator = switch (builtin.os.tag) {
308308 const ptr = os.windows.kernel32.HeapAlloc(heap_handle, 0, amt) orelse return null;
309309 const root_addr = @intFromPtr(ptr);
310310 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];
312312 getRecordPtr(buf).* = root_addr;
313313 return buf.ptr;
314314 }
......@@ -322,7 +322,7 @@ pub const HeapAllocator = switch (builtin.os.tag) {
322322 ) bool {
323323 _ = log2_buf_align;
324324 _ = return_address;
325 const self = @ptrCast(*HeapAllocator, @alignCast(@alignOf(HeapAllocator), ctx));
325 const self: *HeapAllocator = @ptrCast(@alignCast(ctx));
326326
327327 const root_addr = getRecordPtr(buf).*;
328328 const align_offset = @intFromPtr(buf.ptr) - root_addr;
......@@ -330,10 +330,10 @@ pub const HeapAllocator = switch (builtin.os.tag) {
330330 const new_ptr = os.windows.kernel32.HeapReAlloc(
331331 self.heap_handle.?,
332332 os.windows.HEAP_REALLOC_IN_PLACE_ONLY,
333 @ptrFromInt(*anyopaque, root_addr),
333 @as(*anyopaque, @ptrFromInt(root_addr)),
334334 amt,
335335 ) orelse return false;
336 assert(new_ptr == @ptrFromInt(*anyopaque, root_addr));
336 assert(new_ptr == @as(*anyopaque, @ptrFromInt(root_addr)));
337337 getRecordPtr(buf.ptr[0..new_size]).* = root_addr;
338338 return true;
339339 }
......@@ -346,8 +346,8 @@ pub const HeapAllocator = switch (builtin.os.tag) {
346346 ) void {
347347 _ = log2_buf_align;
348348 _ = return_address;
349 const self = @ptrCast(*HeapAllocator, @alignCast(@alignOf(HeapAllocator), ctx));
350 os.windows.HeapFree(self.heap_handle.?, 0, @ptrFromInt(*anyopaque, getRecordPtr(buf).*));
349 const self: *HeapAllocator = @ptrCast(@alignCast(ctx));
350 os.windows.HeapFree(self.heap_handle.?, 0, @as(*anyopaque, @ptrFromInt(getRecordPtr(buf).*)));
351351 }
352352 },
353353 else => @compileError("Unsupported OS"),
......@@ -415,9 +415,9 @@ pub const FixedBufferAllocator = struct {
415415 }
416416
417417 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));
419419 _ = 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));
421421 const adjust_off = mem.alignPointerOffset(self.buffer.ptr + self.end_index, ptr_align) orelse return null;
422422 const adjusted_index = self.end_index + adjust_off;
423423 const new_end_index = adjusted_index + n;
......@@ -433,7 +433,7 @@ pub const FixedBufferAllocator = struct {
433433 new_size: usize,
434434 return_address: usize,
435435 ) bool {
436 const self = @ptrCast(*FixedBufferAllocator, @alignCast(@alignOf(FixedBufferAllocator), ctx));
436 const self: *FixedBufferAllocator = @ptrCast(@alignCast(ctx));
437437 _ = log2_buf_align;
438438 _ = return_address;
439439 assert(self.ownsSlice(buf)); // sanity check
......@@ -462,7 +462,7 @@ pub const FixedBufferAllocator = struct {
462462 log2_buf_align: u8,
463463 return_address: usize,
464464 ) void {
465 const self = @ptrCast(*FixedBufferAllocator, @alignCast(@alignOf(FixedBufferAllocator), ctx));
465 const self: *FixedBufferAllocator = @ptrCast(@alignCast(ctx));
466466 _ = log2_buf_align;
467467 _ = return_address;
468468 assert(self.ownsSlice(buf)); // sanity check
......@@ -473,9 +473,9 @@ pub const FixedBufferAllocator = struct {
473473 }
474474
475475 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));
477477 _ = 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));
479479 var end_index = @atomicLoad(usize, &self.end_index, .SeqCst);
480480 while (true) {
481481 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 {
537537 log2_ptr_align: u8,
538538 ra: usize,
539539 ) ?[*]u8 {
540 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
540 const self: *Self = @ptrCast(@alignCast(ctx));
541541 return FixedBufferAllocator.alloc(&self.fixed_buffer_allocator, len, log2_ptr_align, ra) orelse
542542 return self.fallback_allocator.rawAlloc(len, log2_ptr_align, ra);
543543 }
......@@ -549,7 +549,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type {
549549 new_len: usize,
550550 ra: usize,
551551 ) bool {
552 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
552 const self: *Self = @ptrCast(@alignCast(ctx));
553553 if (self.fixed_buffer_allocator.ownsPtr(buf.ptr)) {
554554 return FixedBufferAllocator.resize(&self.fixed_buffer_allocator, buf, log2_buf_align, new_len, ra);
555555 } else {
......@@ -563,7 +563,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type {
563563 log2_buf_align: u8,
564564 ra: usize,
565565 ) void {
566 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
566 const self: *Self = @ptrCast(@alignCast(ctx));
567567 if (self.fixed_buffer_allocator.ownsPtr(buf.ptr)) {
568568 return FixedBufferAllocator.free(&self.fixed_buffer_allocator, buf, log2_buf_align, ra);
569569 } else {
......@@ -728,14 +728,14 @@ pub fn testAllocator(base_allocator: mem.Allocator) !void {
728728 try testing.expect(slice.len == 100);
729729 for (slice, 0..) |*item, i| {
730730 item.* = try allocator.create(i32);
731 item.*.* = @intCast(i32, i);
731 item.*.* = @as(i32, @intCast(i));
732732 }
733733
734734 slice = try allocator.realloc(slice, 20000);
735735 try testing.expect(slice.len == 20000);
736736
737737 for (slice[0..100], 0..) |item, i| {
738 try testing.expect(item.* == @intCast(i32, i));
738 try testing.expect(item.* == @as(i32, @intCast(i)));
739739 allocator.destroy(item);
740740 }
741741
lib/std/heap/PageAllocator.zig+6-7
......@@ -27,7 +27,7 @@ fn alloc(_: *anyopaque, n: usize, log2_align: u8, ra: usize) ?[*]u8 {
2727 w.MEM_COMMIT | w.MEM_RESERVE,
2828 w.PAGE_READWRITE,
2929 ) catch return null;
30 return @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, addr));
30 return @ptrCast(addr);
3131 }
3232
3333 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 {
4040 0,
4141 ) catch return null;
4242 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);
4444 _ = @cmpxchgStrong(@TypeOf(std.heap.next_mmap_addr_hint), &std.heap.next_mmap_addr_hint, hint, new_hint, .Monotonic, .Monotonic);
4545 return slice.ptr;
4646}
......@@ -66,7 +66,7 @@ fn resize(
6666 // For shrinking that is not releasing, we will only
6767 // decommit the pages not needed anymore.
6868 w.VirtualFree(
69 @ptrFromInt(*anyopaque, new_addr_end),
69 @as(*anyopaque, @ptrFromInt(new_addr_end)),
7070 old_addr_end - new_addr_end,
7171 w.MEM_DECOMMIT,
7272 );
......@@ -85,9 +85,9 @@ fn resize(
8585 return true;
8686
8787 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;
8989 // 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]));
9191 return true;
9292 }
9393
......@@ -104,7 +104,6 @@ fn free(_: *anyopaque, slice: []u8, log2_buf_align: u8, return_address: usize) v
104104 os.windows.VirtualFree(slice.ptr, 0, os.windows.MEM_RELEASE);
105105 } else {
106106 const buf_aligned_len = mem.alignForward(usize, slice.len, mem.page_size);
107 const ptr = @alignCast(mem.page_size, slice.ptr);
108 os.munmap(ptr[0..buf_aligned_len]);
107 os.munmap(@alignCast(slice.ptr[0..buf_aligned_len]));
109108 }
110109}
lib/std/heap/ThreadSafeAllocator.zig+3-3
......@@ -15,7 +15,7 @@ pub fn allocator(self: *ThreadSafeAllocator) Allocator {
1515}
1616
1717fn 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));
1919 self.mutex.lock();
2020 defer self.mutex.unlock();
2121
......@@ -23,7 +23,7 @@ fn alloc(ctx: *anyopaque, n: usize, log2_ptr_align: u8, ra: usize) ?[*]u8 {
2323}
2424
2525fn 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
2828 self.mutex.lock();
2929 defer self.mutex.unlock();
......@@ -32,7 +32,7 @@ fn resize(ctx: *anyopaque, buf: []u8, log2_buf_align: u8, new_len: usize, ret_ad
3232}
3333
3434fn 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
3737 self.mutex.lock();
3838 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) ?[*
4747 _ = ctx;
4848 _ = return_address;
4949 // 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));
5151 const actual_len = @max(len +| @sizeOf(usize), alignment);
5252 const slot_size = math.ceilPowerOfTwo(usize, actual_len) catch return null;
5353 const class = math.log2(slot_size) - min_class;
......@@ -55,7 +55,7 @@ fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, return_address: usize) ?[*
5555 const addr = a: {
5656 const top_free_ptr = frees[class];
5757 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))));
5959 frees[class] = node.*;
6060 break :a top_free_ptr;
6161 }
......@@ -74,11 +74,11 @@ fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, return_address: usize) ?[*
7474 break :a next_addr;
7575 }
7676 };
77 return @ptrFromInt([*]u8, addr);
77 return @as([*]u8, @ptrFromInt(addr));
7878 }
7979 const bigpages_needed = bigPagesNeeded(actual_len);
8080 const addr = allocBigPages(bigpages_needed);
81 return @ptrFromInt([*]u8, addr);
81 return @as([*]u8, @ptrFromInt(addr));
8282}
8383
8484fn resize(
......@@ -92,7 +92,7 @@ fn resize(
9292 _ = return_address;
9393 // We don't want to move anything from one size class to another, but we
9494 // 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));
9696 const old_actual_len = @max(buf.len + @sizeOf(usize), buf_align);
9797 const new_actual_len = @max(new_len +| @sizeOf(usize), buf_align);
9898 const old_small_slot_size = math.ceilPowerOfTwoAssert(usize, old_actual_len);
......@@ -117,20 +117,20 @@ fn free(
117117) void {
118118 _ = ctx;
119119 _ = 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));
121121 const actual_len = @max(buf.len + @sizeOf(usize), buf_align);
122122 const slot_size = math.ceilPowerOfTwoAssert(usize, actual_len);
123123 const class = math.log2(slot_size) - min_class;
124124 const addr = @intFromPtr(buf.ptr);
125125 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))));
127127 node.* = frees[class];
128128 frees[class] = addr;
129129 } else {
130130 const bigpages_needed = bigPagesNeeded(actual_len);
131131 const pow2_pages = math.ceilPowerOfTwoAssert(usize, bigpages_needed);
132132 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))));
134134 const big_class = math.log2(pow2_pages);
135135 node.* = big_frees[big_class];
136136 big_frees[big_class] = addr;
......@@ -148,14 +148,14 @@ fn allocBigPages(n: usize) usize {
148148
149149 const top_free_ptr = big_frees[class];
150150 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))));
152152 big_frees[class] = node.*;
153153 return top_free_ptr;
154154 }
155155
156156 const page_index = @wasmMemoryGrow(0, pow2_pages * pages_per_bigpage);
157157 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;
159159 return addr;
160160}
161161
lib/std/heap/WasmPageAllocator.zig+6-6
......@@ -40,7 +40,7 @@ const FreeBlock = struct {
4040
4141 fn getBit(self: FreeBlock, idx: usize) PageStatus {
4242 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)));
4444 }
4545
4646 fn setBits(self: FreeBlock, start_idx: usize, len: usize, val: PageStatus) void {
......@@ -63,7 +63,7 @@ const FreeBlock = struct {
6363 fn useRecycled(self: FreeBlock, num_pages: usize, log2_align: u8) usize {
6464 @setCold(true);
6565 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;
6767 const has_enough_bits = @popCount(segment) >= num_pages;
6868
6969 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 {
109109 if (len > maxInt(usize) - (mem.page_size - 1)) return null;
110110 const page_count = nPages(len);
111111 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));
113113}
114114
115115fn allocPages(page_count: usize, log2_align: u8) !usize {
......@@ -129,7 +129,7 @@ fn allocPages(page_count: usize, log2_align: u8) !usize {
129129 const next_page_addr = next_page_idx * mem.page_size;
130130 const aligned_addr = mem.alignForwardLog2(next_page_addr, log2_align);
131131 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)));
133133 if (result <= 0)
134134 return error.OutOfMemory;
135135 assert(result == next_page_idx);
......@@ -137,7 +137,7 @@ fn allocPages(page_count: usize, log2_align: u8) !usize {
137137 if (drop_page_count > 0) {
138138 freePages(next_page_idx, aligned_page_idx);
139139 }
140 return @intCast(usize, aligned_page_idx);
140 return @as(usize, @intCast(aligned_page_idx));
141141}
142142
143143fn freePages(start: usize, end: usize) void {
......@@ -151,7 +151,7 @@ fn freePages(start: usize, end: usize) void {
151151 // TODO: would it be better if we use the first page instead?
152152 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)];
155155 // Since this is the first page being freed and we consume it, assume *nothing* is free.
156156 @memset(extended.data, PageStatus.none_free);
157157 }
lib/std/heap/arena_allocator.zig+12-12
......@@ -48,7 +48,7 @@ pub const ArenaAllocator = struct {
4848 // this has to occur before the free because the free frees node
4949 const next_it = node.next;
5050 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];
5252 self.child_allocator.rawFree(alloc_buf, align_bits, @returnAddress());
5353 it = next_it;
5454 }
......@@ -128,7 +128,7 @@ pub const ArenaAllocator = struct {
128128 const next_it = node.next;
129129 if (next_it == null)
130130 break node;
131 const alloc_buf = @ptrCast([*]u8, node)[0..node.data];
131 const alloc_buf = @as([*]u8, @ptrCast(node))[0..node.data];
132132 self.child_allocator.rawFree(alloc_buf, align_bits, @returnAddress());
133133 it = next_it;
134134 } else null;
......@@ -140,7 +140,7 @@ pub const ArenaAllocator = struct {
140140 // perfect, no need to invoke the child_allocator
141141 if (first_node.data == total_size)
142142 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];
144144 if (self.child_allocator.rawResize(first_alloc_buf, align_bits, total_size, @returnAddress())) {
145145 // successful resize
146146 first_node.data = total_size;
......@@ -151,7 +151,7 @@ pub const ArenaAllocator = struct {
151151 return false;
152152 };
153153 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));
155155 node.* = .{ .data = total_size };
156156 self.state.buffer_list.first = node;
157157 }
......@@ -166,7 +166,7 @@ pub const ArenaAllocator = struct {
166166 const log2_align = comptime std.math.log2_int(usize, @alignOf(BufNode));
167167 const ptr = self.child_allocator.rawAlloc(len, log2_align, @returnAddress()) orelse
168168 return null;
169 const buf_node = @ptrCast(*BufNode, @alignCast(@alignOf(BufNode), ptr));
169 const buf_node: *BufNode = @ptrCast(@alignCast(ptr));
170170 buf_node.* = .{ .data = len };
171171 self.state.buffer_list.prepend(buf_node);
172172 self.state.end_index = 0;
......@@ -174,16 +174,16 @@ pub const ArenaAllocator = struct {
174174 }
175175
176176 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));
178178 _ = 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));
181181 var cur_node = if (self.state.buffer_list.first) |first_node|
182182 first_node
183183 else
184184 (self.createNode(0, n + ptr_align) orelse return null);
185185 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];
187187 const cur_buf = cur_alloc_buf[@sizeOf(BufNode)..];
188188 const addr = @intFromPtr(cur_buf.ptr) + self.state.end_index;
189189 const adjusted_addr = mem.alignForward(usize, addr, ptr_align);
......@@ -208,12 +208,12 @@ pub const ArenaAllocator = struct {
208208 }
209209
210210 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));
212212 _ = log2_buf_align;
213213 _ = ret_addr;
214214
215215 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];
217217 if (@intFromPtr(cur_buf.ptr) + self.state.end_index != @intFromPtr(buf.ptr) + buf.len) {
218218 // It's not the most recent allocation, so it cannot be expanded,
219219 // but it's fine if they want to make it smaller.
......@@ -235,10 +235,10 @@ pub const ArenaAllocator = struct {
235235 _ = log2_buf_align;
236236 _ = ret_addr;
237237
238 const self = @ptrCast(*ArenaAllocator, @alignCast(@alignOf(ArenaAllocator), ctx));
238 const self: *ArenaAllocator = @ptrCast(@alignCast(ctx));
239239
240240 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
243243 if (@intFromPtr(cur_buf.ptr) + self.state.end_index == @intFromPtr(buf.ptr) + buf.len) {
244244 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 {
250250 used_count: SlotIndex,
251251
252252 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));
254254 }
255255
256256 fn stackTracePtr(
......@@ -259,10 +259,10 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
259259 slot_index: SlotIndex,
260260 trace_kind: TraceKind,
261261 ) *[stack_n]usize {
262 const start_ptr = @ptrCast([*]u8, bucket) + bucketStackFramesStart(size_class);
262 const start_ptr = @as([*]u8, @ptrCast(bucket)) + bucketStackFramesStart(size_class);
263263 const addr = start_ptr + one_trace_size * traces_per_slot * slot_index +
264264 @intFromEnum(trace_kind) * @as(usize, one_trace_size);
265 return @ptrCast(*[stack_n]usize, @alignCast(@alignOf(usize), addr));
265 return @ptrCast(@alignCast(addr));
266266 }
267267
268268 fn captureStackTrace(
......@@ -338,9 +338,9 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
338338 if (used_byte != 0) {
339339 var bit_index: u3 = 0;
340340 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;
342342 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));
344344 const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);
345345 const addr = bucket.page + slot_index * size_class;
346346 log.err("memory address 0x{x} leaked: {}", .{
......@@ -361,7 +361,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
361361 var leaks = false;
362362 for (self.buckets, 0..) |optional_bucket, bucket_i| {
363363 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));
365365 const used_bits_count = usedBitsCount(size_class);
366366 var bucket = first_bucket;
367367 while (true) {
......@@ -385,7 +385,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
385385
386386 fn freeBucket(self: *Self, bucket: *BucketHeader, size_class: usize) void {
387387 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];
389389 self.backing_allocator.free(bucket_slice);
390390 }
391391
......@@ -444,7 +444,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
444444 self.small_allocations.deinit(self.backing_allocator);
445445 }
446446 self.* = undefined;
447 return @enumFromInt(Check, @intFromBool(leaks));
447 return @as(Check, @enumFromInt(@intFromBool(leaks)));
448448 }
449449
450450 fn collectStackTrace(first_trace_addr: usize, addresses: *[stack_n]usize) void {
......@@ -496,7 +496,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
496496 bucket.alloc_cursor += 1;
497497
498498 var used_bits_byte = bucket.usedBits(slot_index / 8);
499 const used_bit_index: u3 = @intCast(u3, slot_index % 8); // TODO cast should be unnecessary
499 const used_bit_index: u3 = @as(u3, @intCast(slot_index % 8)); // TODO cast should be unnecessary
500500 used_bits_byte.* |= (@as(u8, 1) << used_bit_index);
501501 bucket.used_count += 1;
502502 bucket.captureStackTrace(trace_addr, size_class, slot_index, .alloc);
......@@ -667,8 +667,8 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
667667 new_size: usize,
668668 ret_addr: usize,
669669 ) bool {
670 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
671 const log2_old_align = @intCast(Allocator.Log2Align, log2_old_align_u8);
670 const self: *Self = @ptrCast(@alignCast(ctx));
671 const log2_old_align = @as(Allocator.Log2Align, @intCast(log2_old_align_u8));
672672 self.mutex.lock();
673673 defer self.mutex.unlock();
674674
......@@ -704,11 +704,11 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
704704 return self.resizeLarge(old_mem, log2_old_align, new_size, ret_addr);
705705 };
706706 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));
708708 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));
710710 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;
712712 if (!is_used) {
713713 if (config.safety) {
714714 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 {
739739 }
740740 if (log2_old_align != entry.value_ptr.log2_ptr_align) {
741741 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),
743 @as(usize, 1) << @intCast(math.Log2Int(usize), log2_old_align),
742 @as(usize, 1) << @as(math.Log2Int(usize), @intCast(entry.value_ptr.log2_ptr_align)),
743 @as(usize, 1) << @as(math.Log2Int(usize), @intCast(log2_old_align)),
744744 bucketStackTrace(bucket, size_class, slot_index, .alloc),
745745 free_stack_trace,
746746 });
......@@ -786,8 +786,8 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
786786 log2_old_align_u8: u8,
787787 ret_addr: usize,
788788 ) void {
789 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
790 const log2_old_align = @intCast(Allocator.Log2Align, log2_old_align_u8);
789 const self: *Self = @ptrCast(@alignCast(ctx));
790 const log2_old_align = @as(Allocator.Log2Align, @intCast(log2_old_align_u8));
791791 self.mutex.lock();
792792 defer self.mutex.unlock();
793793
......@@ -825,11 +825,11 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
825825 return;
826826 };
827827 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));
829829 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));
831831 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;
833833 if (!is_used) {
834834 if (config.safety) {
835835 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 {
861861 }
862862 if (log2_old_align != entry.value_ptr.log2_ptr_align) {
863863 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),
865 @as(usize, 1) << @intCast(math.Log2Int(usize), log2_old_align),
864 @as(usize, 1) << @as(math.Log2Int(usize), @intCast(entry.value_ptr.log2_ptr_align)),
865 @as(usize, 1) << @as(math.Log2Int(usize), @intCast(log2_old_align)),
866866 bucketStackTrace(bucket, size_class, slot_index, .alloc),
867867 free_stack_trace,
868868 });
......@@ -896,7 +896,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
896896 } else {
897897 // move alloc_cursor to end so we can tell size_class later
898898 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));
900900 if (self.empty_buckets) |prev_bucket| {
901901 // empty_buckets is ordered newest to oldest through prev so that if
902902 // config.never_unmap is false and backing_allocator reuses freed memory
......@@ -936,11 +936,11 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
936936 }
937937
938938 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));
940940 self.mutex.lock();
941941 defer self.mutex.unlock();
942942 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;
944944 }
945945
946946 fn allocInner(
......@@ -949,7 +949,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
949949 log2_ptr_align: Allocator.Log2Align,
950950 ret_addr: usize,
951951 ) 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)));
953953 if (new_aligned_size > largest_bucket_object_size) {
954954 try self.large_allocations.ensureUnusedCapacity(self.backing_allocator, 1);
955955 const ptr = self.backing_allocator.rawAlloc(len, log2_ptr_align, ret_addr) orelse
......@@ -1002,7 +1002,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
10021002
10031003 const bucket_size = bucketSize(size_class);
10041004 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));
10061006 ptr.* = BucketHeader{
10071007 .prev = ptr,
10081008 .next = ptr,
lib/std/heap/log_to_writer_allocator.zig+3-3
......@@ -34,7 +34,7 @@ pub fn LogToWriterAllocator(comptime Writer: type) type {
3434 log2_ptr_align: u8,
3535 ra: usize,
3636 ) ?[*]u8 {
37 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
37 const self: *Self = @ptrCast(@alignCast(ctx));
3838 self.writer.print("alloc : {}", .{len}) catch {};
3939 const result = self.parent_allocator.rawAlloc(len, log2_ptr_align, ra);
4040 if (result != null) {
......@@ -52,7 +52,7 @@ pub fn LogToWriterAllocator(comptime Writer: type) type {
5252 new_len: usize,
5353 ra: usize,
5454 ) bool {
55 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
55 const self: *Self = @ptrCast(@alignCast(ctx));
5656 if (new_len <= buf.len) {
5757 self.writer.print("shrink: {} to {}\n", .{ buf.len, new_len }) catch {};
5858 } else {
......@@ -77,7 +77,7 @@ pub fn LogToWriterAllocator(comptime Writer: type) type {
7777 log2_buf_align: u8,
7878 ra: usize,
7979 ) void {
80 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
80 const self: *Self = @ptrCast(@alignCast(ctx));
8181 self.writer.print("free : {}\n", .{buf.len}) catch {};
8282 self.parent_allocator.rawFree(buf, log2_buf_align, ra);
8383 }
lib/std/heap/logging_allocator.zig+3-3
......@@ -59,7 +59,7 @@ pub fn ScopedLoggingAllocator(
5959 log2_ptr_align: u8,
6060 ra: usize,
6161 ) ?[*]u8 {
62 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
62 const self: *Self = @ptrCast(@alignCast(ctx));
6363 const result = self.parent_allocator.rawAlloc(len, log2_ptr_align, ra);
6464 if (result != null) {
6565 logHelper(
......@@ -84,7 +84,7 @@ pub fn ScopedLoggingAllocator(
8484 new_len: usize,
8585 ra: usize,
8686 ) bool {
87 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
87 const self: *Self = @ptrCast(@alignCast(ctx));
8888 if (self.parent_allocator.rawResize(buf, log2_buf_align, new_len, ra)) {
8989 if (new_len <= buf.len) {
9090 logHelper(
......@@ -118,7 +118,7 @@ pub fn ScopedLoggingAllocator(
118118 log2_buf_align: u8,
119119 ra: usize,
120120 ) void {
121 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
121 const self: *Self = @ptrCast(@alignCast(ctx));
122122 self.parent_allocator.rawFree(buf, log2_buf_align, ra);
123123 logHelper(success_log_level, "free - len: {}", .{buf.len});
124124 }
lib/std/heap/memory_pool.zig+4-4
......@@ -70,7 +70,7 @@ pub fn MemoryPoolExtra(comptime Item: type, comptime pool_options: Options) type
7070 var i: usize = 0;
7171 while (i < initial_size) : (i += 1) {
7272 const raw_mem = try pool.allocNew();
73 const free_node = @ptrCast(NodePtr, raw_mem);
73 const free_node = @as(NodePtr, @ptrCast(raw_mem));
7474 free_node.* = Node{
7575 .next = pool.free_list,
7676 };
......@@ -106,11 +106,11 @@ pub fn MemoryPoolExtra(comptime Item: type, comptime pool_options: Options) type
106106 pool.free_list = item.next;
107107 break :blk item;
108108 } else if (pool_options.growable)
109 @ptrCast(NodePtr, try pool.allocNew())
109 @as(NodePtr, @ptrCast(try pool.allocNew()))
110110 else
111111 return error.OutOfMemory;
112112
113 const ptr = @ptrCast(ItemPtr, node);
113 const ptr = @as(ItemPtr, @ptrCast(node));
114114 ptr.* = undefined;
115115 return ptr;
116116 }
......@@ -120,7 +120,7 @@ pub fn MemoryPoolExtra(comptime Item: type, comptime pool_options: Options) type
120120 pub fn destroy(pool: *Pool, ptr: ItemPtr) void {
121121 ptr.* = undefined;
122122
123 const node = @ptrCast(NodePtr, ptr);
123 const node = @as(NodePtr, @ptrCast(ptr));
124124 node.* = Node{
125125 .next = pool.free_list,
126126 };
lib/std/http/Client.zig+7-7
......@@ -187,7 +187,7 @@ pub const Connection = struct {
187187 const nread = try conn.rawReadAtLeast(conn.read_buf[0..], 1);
188188 if (nread == 0) return error.EndOfStream;
189189 conn.read_start = 0;
190 conn.read_end = @intCast(u16, nread);
190 conn.read_end = @as(u16, @intCast(nread));
191191 }
192192
193193 pub fn peek(conn: *Connection) []const u8 {
......@@ -208,8 +208,8 @@ pub const Connection = struct {
208208
209209 if (available_read > available_buffer) { // partially read buffered data
210210 @memcpy(buffer[out_index..], conn.read_buf[conn.read_start..conn.read_end][0..available_buffer]);
211 out_index += @intCast(u16, available_buffer);
212 conn.read_start += @intCast(u16, available_buffer);
211 out_index += @as(u16, @intCast(available_buffer));
212 conn.read_start += @as(u16, @intCast(available_buffer));
213213
214214 break;
215215 } else if (available_read > 0) { // fully read buffered data
......@@ -343,7 +343,7 @@ pub const Response = struct {
343343 else => return error.HttpHeadersInvalid,
344344 };
345345 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].*)));
347347 const reason = mem.trimLeft(u8, first_line[12..], " ");
348348
349349 res.version = version;
......@@ -415,7 +415,7 @@ pub const Response = struct {
415415 }
416416
417417 inline fn int64(array: *const [8]u8) u64 {
418 return @bitCast(u64, array.*);
418 return @as(u64, @bitCast(array.*));
419419 }
420420
421421 fn parseInt3(nnn: @Vector(3, u8)) u10 {
......@@ -649,7 +649,7 @@ pub const Request = struct {
649649 try req.connection.?.data.fill();
650650
651651 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
654654 if (req.response.parser.state.isContent()) break;
655655 }
......@@ -768,7 +768,7 @@ pub const Request = struct {
768768 try req.connection.?.data.fill();
769769
770770 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)));
772772 }
773773
774774 if (has_trail) {
lib/std/http/Server.zig+6-6
......@@ -46,7 +46,7 @@ pub const Connection = struct {
4646 const nread = try conn.rawReadAtLeast(conn.read_buf[0..], 1);
4747 if (nread == 0) return error.EndOfStream;
4848 conn.read_start = 0;
49 conn.read_end = @intCast(u16, nread);
49 conn.read_end = @as(u16, @intCast(nread));
5050 }
5151
5252 pub fn peek(conn: *Connection) []const u8 {
......@@ -67,8 +67,8 @@ pub const Connection = struct {
6767
6868 if (available_read > available_buffer) { // partially read buffered data
6969 @memcpy(buffer[out_index..], conn.read_buf[conn.read_start..conn.read_end][0..available_buffer]);
70 out_index += @intCast(u16, available_buffer);
71 conn.read_start += @intCast(u16, available_buffer);
70 out_index += @as(u16, @intCast(available_buffer));
71 conn.read_start += @as(u16, @intCast(available_buffer));
7272
7373 break;
7474 } else if (available_read > 0) { // fully read buffered data
......@@ -268,7 +268,7 @@ pub const Request = struct {
268268 }
269269
270270 inline fn int64(array: *const [8]u8) u64 {
271 return @bitCast(u64, array.*);
271 return @as(u64, @bitCast(array.*));
272272 }
273273
274274 method: http.Method,
......@@ -493,7 +493,7 @@ pub const Response = struct {
493493 try res.connection.fill();
494494
495495 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
498498 if (res.request.parser.state.isContent()) break;
499499 }
......@@ -560,7 +560,7 @@ pub const Response = struct {
560560 try res.connection.fill();
561561
562562 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)));
564564 }
565565
566566 if (has_trail) {
lib/std/http/protocol.zig+24-24
......@@ -83,7 +83,7 @@ pub const HeadersParser = struct {
8383 /// first byte of content is located at `bytes[result]`.
8484 pub fn findHeadersEnd(r: *HeadersParser, bytes: []const u8) u32 {
8585 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));
8787 var index: u32 = 0;
8888
8989 while (true) {
......@@ -182,8 +182,8 @@ pub const HeadersParser = struct {
182182
183183 const chunk = bytes[index..][0..vector_len];
184184 const v: Vector = chunk.*;
185 const matches_r = @bitCast(BitVector, v == @splat(vector_len, @as(u8, '\r')));
186 const matches_n = @bitCast(BitVector, v == @splat(vector_len, @as(u8, '\n')));
185 const matches_r = @as(BitVector, @bitCast(v == @splat(vector_len, @as(u8, '\r'))));
186 const matches_n = @as(BitVector, @bitCast(v == @splat(vector_len, @as(u8, '\n'))));
187187 const matches_or: SizeVector = matches_r | matches_n;
188188
189189 const matches = @reduce(.Add, matches_or);
......@@ -234,7 +234,7 @@ pub const HeadersParser = struct {
234234 },
235235 4...vector_len => {
236236 inline for (0..vector_len - 3) |i_usize| {
237 const i = @truncate(u32, i_usize);
237 const i = @as(u32, @truncate(i_usize));
238238
239239 const b32 = int32(chunk[i..][0..4]);
240240 const b16 = intShift(u16, b32);
......@@ -405,10 +405,10 @@ pub const HeadersParser = struct {
405405 /// If the amount returned is less than `bytes.len`, you may assume that the parser is in the `chunk_data` state
406406 /// and that the first byte of the chunk is at `bytes[result]`.
407407 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
410410 for (bytes[0..], 0..) |c, i| {
411 const index = @intCast(u32, i);
411 const index = @as(u32, @intCast(i));
412412 switch (r.state) {
413413 .chunk_data_suffix => switch (c) {
414414 '\r' => r.state = .chunk_data_suffix_r,
......@@ -529,7 +529,7 @@ pub const HeadersParser = struct {
529529 try conn.fill();
530530
531531 const nread = @min(conn.peek().len, data_avail);
532 conn.drop(@intCast(u16, nread));
532 conn.drop(@as(u16, @intCast(nread)));
533533 r.next_chunk_length -= nread;
534534
535535 if (r.next_chunk_length == 0) r.done = true;
......@@ -538,7 +538,7 @@ pub const HeadersParser = struct {
538538 } else {
539539 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)));
542542 const nread = try conn.read(buffer[0..can_read]);
543543 r.next_chunk_length -= nread;
544544
......@@ -551,7 +551,7 @@ pub const HeadersParser = struct {
551551 try conn.fill();
552552
553553 const i = r.findChunkedLen(conn.peek());
554 conn.drop(@intCast(u16, i));
554 conn.drop(@as(u16, @intCast(i)));
555555
556556 switch (r.state) {
557557 .invalid => return error.HttpChunkInvalid,
......@@ -579,10 +579,10 @@ pub const HeadersParser = struct {
579579 try conn.fill();
580580
581581 const nread = @min(conn.peek().len, data_avail);
582 conn.drop(@intCast(u16, nread));
582 conn.drop(@as(u16, @intCast(nread)));
583583 r.next_chunk_length -= nread;
584584 } 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));
586586 const nread = try conn.read(buffer[out_index..][0..can_read]);
587587 r.next_chunk_length -= nread;
588588 out_index += nread;
......@@ -601,21 +601,21 @@ pub const HeadersParser = struct {
601601};
602602
603603inline fn int16(array: *const [2]u8) u16 {
604 return @bitCast(u16, array.*);
604 return @as(u16, @bitCast(array.*));
605605}
606606
607607inline fn int24(array: *const [3]u8) u24 {
608 return @bitCast(u24, array.*);
608 return @as(u24, @bitCast(array.*));
609609}
610610
611611inline fn int32(array: *const [4]u8) u32 {
612 return @bitCast(u32, array.*);
612 return @as(u32, @bitCast(array.*));
613613}
614614
615615inline fn intShift(comptime T: type, x: anytype) T {
616616 switch (@import("builtin").cpu.arch.endian()) {
617 .Little => return @truncate(T, x >> (@bitSizeOf(@TypeOf(x)) - @bitSizeOf(T))),
618 .Big => return @truncate(T, x),
617 .Little => return @as(T, @truncate(x >> (@bitSizeOf(@TypeOf(x)) - @bitSizeOf(T)))),
618 .Big => return @as(T, @truncate(x)),
619619 }
620620}
621621
......@@ -634,7 +634,7 @@ const MockBufferedConnection = struct {
634634 const nread = try conn.conn.read(conn.buf[0..]);
635635 if (nread == 0) return error.EndOfStream;
636636 conn.start = 0;
637 conn.end = @truncate(u16, nread);
637 conn.end = @as(u16, @truncate(nread));
638638 }
639639
640640 pub fn peek(conn: *MockBufferedConnection) []const u8 {
......@@ -652,7 +652,7 @@ const MockBufferedConnection = struct {
652652 const left = buffer.len - out_index;
653653
654654 if (available > 0) {
655 const can_read = @truncate(u16, @min(available, left));
655 const can_read = @as(u16, @truncate(@min(available, left)));
656656
657657 @memcpy(buffer[out_index..][0..can_read], conn.buf[conn.start..][0..can_read]);
658658 out_index += can_read;
......@@ -705,8 +705,8 @@ test "HeadersParser.findHeadersEnd" {
705705
706706 for (0..36) |i| {
707707 r = HeadersParser.initDynamic(0);
708 try std.testing.expectEqual(@intCast(u32, i), r.findHeadersEnd(data[0..i]));
709 try std.testing.expectEqual(@intCast(u32, 35 - i), r.findHeadersEnd(data[i..]));
708 try std.testing.expectEqual(@as(u32, @intCast(i)), r.findHeadersEnd(data[0..i]));
709 try std.testing.expectEqual(@as(u32, @intCast(35 - i)), r.findHeadersEnd(data[i..]));
710710 }
711711}
712712
......@@ -761,7 +761,7 @@ test "HeadersParser.read length" {
761761 try conn.fill();
762762
763763 const nchecked = try r.checkCompleteHead(std.testing.allocator, conn.peek());
764 conn.drop(@intCast(u16, nchecked));
764 conn.drop(@as(u16, @intCast(nchecked)));
765765
766766 if (r.state.isContent()) break;
767767 }
......@@ -792,7 +792,7 @@ test "HeadersParser.read chunked" {
792792 try conn.fill();
793793
794794 const nchecked = try r.checkCompleteHead(std.testing.allocator, conn.peek());
795 conn.drop(@intCast(u16, nchecked));
795 conn.drop(@as(u16, @intCast(nchecked)));
796796
797797 if (r.state.isContent()) break;
798798 }
......@@ -822,7 +822,7 @@ test "HeadersParser.read chunked trailer" {
822822 try conn.fill();
823823
824824 const nchecked = try r.checkCompleteHead(std.testing.allocator, conn.peek());
825 conn.drop(@intCast(u16, nchecked));
825 conn.drop(@as(u16, @intCast(nchecked)));
826826
827827 if (r.state.isContent()) break;
828828 }
......@@ -837,7 +837,7 @@ test "HeadersParser.read chunked trailer" {
837837 try conn.fill();
838838
839839 const nchecked = try r.checkCompleteHead(std.testing.allocator, conn.peek());
840 conn.drop(@intCast(u16, nchecked));
840 conn.drop(@as(u16, @intCast(nchecked)));
841841
842842 if (r.state.isContent()) break;
843843 }
lib/std/io.zig+1-1
......@@ -275,7 +275,7 @@ pub fn Poller(comptime StreamEnum: type) type {
275275 )) {
276276 .pending => {
277277 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));
279279 self.windows.active.count += 1;
280280 },
281281 .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)
6060 var out_buffer = @as(Buf, 0);
6161
6262 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;
6464 const shift = u7_bit_count - n;
6565 switch (endian) {
6666 .Big => {
......@@ -88,45 +88,45 @@ pub fn BitReader(comptime endian: std.builtin.Endian, comptime ReaderType: type)
8888 while (out_bits.* < bits) {
8989 const n = bits - out_bits.*;
9090 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)),
9292 else => |e| return e,
9393 };
9494
9595 switch (endian) {
9696 .Big => {
9797 if (n >= u8_bit_count) {
98 out_buffer <<= @intCast(u3, u8_bit_count - 1);
98 out_buffer <<= @as(u3, @intCast(u8_bit_count - 1));
9999 out_buffer <<= 1;
100100 out_buffer |= @as(Buf, next_byte);
101101 out_bits.* += u8_bit_count;
102102 continue;
103103 }
104104
105 const shift = @intCast(u3, u8_bit_count - n);
106 out_buffer <<= @intCast(BufShift, n);
105 const shift = @as(u3, @intCast(u8_bit_count - n));
106 out_buffer <<= @as(BufShift, @intCast(n));
107107 out_buffer |= @as(Buf, next_byte >> shift);
108108 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))));
110110 self.bit_count = shift;
111111 },
112112 .Little => {
113113 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.*));
115115 out_bits.* += u8_bit_count;
116116 continue;
117117 }
118118
119 const shift = @intCast(u3, u8_bit_count - n);
119 const shift = @as(u3, @intCast(u8_bit_count - n));
120120 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.*));
122122 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))));
124124 self.bit_count = shift;
125125 },
126126 }
127127 }
128128
129 return @intCast(U, out_buffer);
129 return @as(U, @intCast(out_buffer));
130130 }
131131
132132 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)
4747 const Buf = std.meta.Int(.unsigned, buf_bit_count);
4848 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));
5353 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)),
5555 .Little => buf_value,
5656 };
5757 var in_bits = bits;
5858
5959 if (self.bit_count > 0) {
6060 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));
6262 switch (endian) {
6363 .Big => {
64 const shift = @intCast(BufShift, high_byte_shift + self.bit_count);
65 const v = @intCast(u8, in_buffer >> shift);
64 const shift = @as(BufShift, @intCast(high_byte_shift + self.bit_count));
65 const v = @as(u8, @intCast(in_buffer >> shift));
6666 self.bit_buffer |= v;
6767 in_buffer <<= n;
6868 },
6969 .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));
7171 self.bit_buffer |= v;
7272 in_buffer >>= n;
7373 },
......@@ -87,15 +87,15 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type)
8787 while (in_bits >= u8_bit_count) {
8888 switch (endian) {
8989 .Big => {
90 const v = @intCast(u8, in_buffer >> high_byte_shift);
90 const v = @as(u8, @intCast(in_buffer >> high_byte_shift));
9191 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));
9393 in_buffer <<= 1;
9494 },
9595 .Little => {
96 const v = @truncate(u8, in_buffer);
96 const v = @as(u8, @truncate(in_buffer));
9797 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));
9999 in_buffer >>= 1;
100100 },
101101 }
......@@ -103,10 +103,10 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type)
103103 }
104104
105105 if (in_bits > 0) {
106 self.bit_count = @intCast(u4, in_bits);
106 self.bit_count = @as(u4, @intCast(in_bits));
107107 self.bit_buffer = switch (endian) {
108 .Big => @truncate(u8, in_buffer >> high_byte_shift),
109 .Little => @truncate(u8, in_buffer),
108 .Big => @as(u8, @truncate(in_buffer >> high_byte_shift)),
109 .Little => @as(u8, @truncate(in_buffer)),
110110 };
111111 }
112112 }
lib/std/io/c_writer.zig+1-1
......@@ -13,7 +13,7 @@ pub fn cWriter(c_file: *std.c.FILE) CWriter {
1313fn cWriterWrite(c_file: *std.c.FILE, bytes: []const u8) std.fs.File.WriteError!usize {
1414 const amt_written = std.c.fwrite(bytes.ptr, 1, bytes.len, c_file);
1515 if (amt_written >= 0) return amt_written;
16 switch (@enumFromInt(os.E, std.c._errno().*)) {
16 switch (@as(os.E, @enumFromInt(std.c._errno().*))) {
1717 .SUCCESS => unreachable,
1818 .INVAL => unreachable,
1919 .FAULT => unreachable,
lib/std/io/reader.zig+1-1
......@@ -246,7 +246,7 @@ pub fn Reader(
246246
247247 /// Same as `readByte` except the returned byte is signed.
248248 pub fn readByteSigned(self: Self) (Error || error{EndOfStream})!i8 {
249 return @bitCast(i8, try self.readByte());
249 return @as(i8, @bitCast(try self.readByte()));
250250 }
251251
252252 /// 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 {
193193/// to get meaningful information from this.
194194pub const Diagnostics = struct {
195195 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.
197197 total_bytes_before_current_input: u64 = 0,
198198 cursor_pointer: *const usize = undefined,
199199
......@@ -1719,7 +1719,7 @@ const BitStack = struct {
17191719
17201720 pub fn push(self: *@This(), b: u1) Allocator.Error!void {
17211721 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
17241724 if (self.bytes.items.len <= byte_index) {
17251725 try self.bytes.append(0);
......@@ -1733,8 +1733,8 @@ const BitStack = struct {
17331733
17341734 pub fn peek(self: *const @This()) u1 {
17351735 const byte_index = (self.bit_len - 1) >> 3;
1736 const bit_index = @intCast(u3, (self.bit_len - 1) & 7);
1737 return @intCast(u1, (self.bytes.items[byte_index] >> bit_index) & 1);
1736 const bit_index = @as(u3, @intCast((self.bit_len - 1) & 7));
1737 return @as(u1, @intCast((self.bytes.items[byte_index] >> bit_index) & 1));
17381738 }
17391739
17401740 pub fn pop(self: *@This()) u1 {
lib/std/json/static.zig+10-10
......@@ -442,7 +442,7 @@ fn internalParse(
442442 }
443443
444444 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)).*;
446446 return try arraylist.toOwnedSliceSentinel(sentinel_value);
447447 }
448448
......@@ -456,7 +456,7 @@ fn internalParse(
456456 // Use our own array list so we can append the sentinel.
457457 var value_list = ArrayList(u8).init(allocator);
458458 _ = 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)).*);
460460 }
461461 if (ptrInfo.is_const) {
462462 switch (try source.nextAllocMax(allocator, .alloc_if_needed, options.max_value_len.?)) {
......@@ -518,8 +518,8 @@ fn internalParseFromValue(
518518 },
519519 .Float, .ComptimeFloat => {
520520 switch (source) {
521 .float => |f| return @floatCast(T, f),
522 .integer => |i| return @floatFromInt(T, i),
521 .float => |f| return @as(T, @floatCast(f)),
522 .integer => |i| return @as(T, @floatFromInt(i)),
523523 .number_string, .string => |s| return std.fmt.parseFloat(T, s),
524524 else => return error.UnexpectedToken,
525525 }
......@@ -530,12 +530,12 @@ fn internalParseFromValue(
530530 if (@round(f) != f) return error.InvalidNumber;
531531 if (f > std.math.maxInt(T)) return error.Overflow;
532532 if (f < std.math.minInt(T)) return error.Overflow;
533 return @intFromFloat(T, f);
533 return @as(T, @intFromFloat(f));
534534 },
535535 .integer => |i| {
536536 if (i > std.math.maxInt(T)) return error.Overflow;
537537 if (i < std.math.minInt(T)) return error.Overflow;
538 return @intCast(T, i);
538 return @as(T, @intCast(i));
539539 },
540540 .number_string, .string => |s| {
541541 return sliceToInt(T, s);
......@@ -686,7 +686,7 @@ fn internalParseFromValue(
686686 switch (source) {
687687 .array => |array| {
688688 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)).*)
690690 else
691691 try allocator.alloc(ptrInfo.child, array.items.len);
692692
......@@ -701,7 +701,7 @@ fn internalParseFromValue(
701701 // Dynamic length string.
702702
703703 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)).*)
705705 else
706706 try allocator.alloc(ptrInfo.child, s.len);
707707 @memcpy(r[0..], s);
......@@ -743,7 +743,7 @@ fn sliceToInt(comptime T: type, slice: []const u8) !T {
743743 const float = try std.fmt.parseFloat(f128, slice);
744744 if (@round(float) != float) return error.InvalidNumber;
745745 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))));
747747}
748748
749749fn sliceToEnum(comptime T: type, slice: []const u8) !T {
......@@ -759,7 +759,7 @@ fn fillDefaultStructValues(comptime T: type, r: *T, fields_seen: *[@typeInfo(T).
759759 inline for (@typeInfo(T).Struct.fields, 0..) |field, i| {
760760 if (!fields_seen[i]) {
761761 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)).*;
763763 @field(r, field.name) = default;
764764 } else {
765765 return error.MissingField;
lib/std/json/stringify.zig+2-2
......@@ -78,8 +78,8 @@ fn outputUnicodeEscape(
7878 assert(codepoint <= 0x10FFFF);
7979 // To escape an extended character that is not in the Basic Multilingual Plane,
8080 // the character is represented as a 12-character sequence, encoding the UTF-16 surrogate pair.
81 const high = @intCast(u16, (codepoint - 0x10000) >> 10) + 0xD800;
82 const low = @intCast(u16, codepoint & 0x3FF) + 0xDC00;
81 const high = @as(u16, @intCast((codepoint - 0x10000) >> 10)) + 0xD800;
82 const low = @as(u16, @intCast(codepoint & 0x3FF)) + 0xDC00;
8383 try out_stream.writeAll("\\u");
8484 try std.fmt.formatIntValue(high, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream);
8585 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 {
176176 .ComptimeInt => {
177177 return self.emitNumber(@as(std.math.IntFittingRange(value, value), value));
178178 },
179 .Float, .ComptimeFloat => if (@floatCast(f64, value) == value) {
180 try self.stream.print("{}", .{@floatCast(f64, value)});
179 .Float, .ComptimeFloat => if (@as(f64, @floatCast(value)) == value) {
180 try self.stream.print("{}", .{@as(f64, @floatCast(value))});
181181 self.popState();
182182 return;
183183 },
......@@ -294,7 +294,7 @@ test "json write stream" {
294294
295295fn getJsonObject(allocator: std.mem.Allocator) !Value {
296296 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)) });
298298 try value.object.put("two", Value{ .float = 2.0 });
299299 return value;
300300}
lib/std/leb128.zig+21-21
......@@ -30,17 +30,17 @@ pub fn readULEB128(comptime T: type, reader: anytype) !T {
3030 if (value > std.math.maxInt(T)) return error.Overflow;
3131 }
3232
33 return @truncate(T, value);
33 return @as(T, @truncate(value));
3434}
3535
3636/// Write a single unsigned integer as unsigned LEB128 to the given writer.
3737pub fn writeULEB128(writer: anytype, uint_value: anytype) !void {
3838 const T = @TypeOf(uint_value);
3939 const U = if (@typeInfo(T).Int.bits < 8) u8 else T;
40 var value = @intCast(U, uint_value);
40 var value = @as(U, @intCast(uint_value));
4141
4242 while (true) {
43 const byte = @truncate(u8, value & 0x7f);
43 const byte = @as(u8, @truncate(value & 0x7f));
4444 value >>= 7;
4545 if (value == 0) {
4646 try writer.writeByte(byte);
......@@ -71,18 +71,18 @@ pub fn readILEB128(comptime T: type, reader: anytype) !T {
7171 if (ov[1] != 0) {
7272 // Overflow is ok so long as the sign bit is set and this is the last byte
7373 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
7676 // and all the overflowed bits are 1
77 const remaining_shift = @intCast(u3, @typeInfo(U).Int.bits - @as(u16, shift));
78 const remaining_bits = @bitCast(i8, byte | 0x80) >> remaining_shift;
77 const remaining_shift = @as(u3, @intCast(@typeInfo(U).Int.bits - @as(u16, shift)));
78 const remaining_bits = @as(i8, @bitCast(byte | 0x80)) >> remaining_shift;
7979 if (remaining_bits != -1) return error.Overflow;
8080 } else {
8181 // If we don't overflow and this is the last byte and the number being decoded
8282 // is negative, check that the remaining bits are 1
83 if ((byte & 0x80 == 0) and (@bitCast(S, ov[0]) < 0)) {
84 const remaining_shift = @intCast(u3, @typeInfo(U).Int.bits - @as(u16, shift));
85 const remaining_bits = @bitCast(i8, byte | 0x80) >> remaining_shift;
83 if ((byte & 0x80 == 0) and (@as(S, @bitCast(ov[0])) < 0)) {
84 const remaining_shift = @as(u3, @intCast(@typeInfo(U).Int.bits - @as(u16, shift)));
85 const remaining_bits = @as(i8, @bitCast(byte | 0x80)) >> remaining_shift;
8686 if (remaining_bits != -1) return error.Overflow;
8787 }
8888 }
......@@ -92,7 +92,7 @@ pub fn readILEB128(comptime T: type, reader: anytype) !T {
9292 const needs_sign_ext = group + 1 < max_group;
9393 if (byte & 0x40 != 0 and needs_sign_ext) {
9494 const ones = @as(S, -1);
95 value |= @bitCast(U, ones) << (shift + 7);
95 value |= @as(U, @bitCast(ones)) << (shift + 7);
9696 }
9797 break;
9898 }
......@@ -100,13 +100,13 @@ pub fn readILEB128(comptime T: type, reader: anytype) !T {
100100 return error.Overflow;
101101 }
102102
103 const result = @bitCast(S, value);
103 const result = @as(S, @bitCast(value));
104104 // Only applies if we extended to i8
105105 if (S != T) {
106106 if (result > std.math.maxInt(T) or result < std.math.minInt(T)) return error.Overflow;
107107 }
108108
109 return @truncate(T, result);
109 return @as(T, @truncate(result));
110110}
111111
112112/// 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 {
115115 const S = if (@typeInfo(T).Int.bits < 8) i8 else T;
116116 const U = std.meta.Int(.unsigned, @typeInfo(S).Int.bits);
117117
118 var value = @intCast(S, int_value);
118 var value = @as(S, @intCast(int_value));
119119
120120 while (true) {
121 const uvalue = @bitCast(U, value);
122 const byte = @truncate(u8, uvalue);
121 const uvalue = @as(U, @bitCast(value));
122 const byte = @as(u8, @truncate(uvalue));
123123 value >>= 6;
124124 if (value == -1 or value == 0) {
125125 try writer.writeByte(byte & 0x7F);
......@@ -141,15 +141,15 @@ pub fn writeILEB128(writer: anytype, int_value: anytype) !void {
141141pub fn writeUnsignedFixed(comptime l: usize, ptr: *[l]u8, int: std.meta.Int(.unsigned, l * 7)) void {
142142 const T = @TypeOf(int);
143143 const U = if (@typeInfo(T).Int.bits < 8) u8 else T;
144 var value = @intCast(U, int);
144 var value = @as(U, @intCast(int));
145145
146146 comptime var i = 0;
147147 inline while (i < (l - 1)) : (i += 1) {
148 const byte = @truncate(u8, value) | 0b1000_0000;
148 const byte = @as(u8, @truncate(value)) | 0b1000_0000;
149149 value >>= 7;
150150 ptr[i] = byte;
151151 }
152 ptr[i] = @truncate(u8, value);
152 ptr[i] = @as(u8, @truncate(value));
153153}
154154
155155test "writeUnsignedFixed" {
......@@ -245,7 +245,7 @@ test "deserialize signed LEB128" {
245245 try testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1);
246246 try testing.expect((try test_read_ileb128(i32, "\xff\xff\xff\xff\x7f")) == -1);
247247 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)))));
249249 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000);
250250 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" {
356356 const max = std.math.maxInt(T);
357357 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)));
360360 }
361361}
362362
......@@ -374,6 +374,6 @@ test "serialize signed LEB128" {
374374 const max = std.math.maxInt(T);
375375 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)));
378378 }
379379}
lib/std/macho.zig+7-7
......@@ -787,7 +787,7 @@ pub const section_64 = extern struct {
787787 }
788788
789789 pub fn @"type"(sect: section_64) u8 {
790 return @truncate(u8, sect.flags & 0xff);
790 return @as(u8, @truncate(sect.flags & 0xff));
791791 }
792792
793793 pub fn attrs(sect: section_64) u32 {
......@@ -1870,7 +1870,7 @@ pub const LoadCommandIterator = struct {
18701870
18711871 pub fn cast(lc: LoadCommand, comptime Cmd: type) ?Cmd {
18721872 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]))).*;
18741874 }
18751875
18761876 /// Asserts LoadCommand is of type segment_command_64.
......@@ -1878,9 +1878,9 @@ pub const LoadCommandIterator = struct {
18781878 const segment_lc = lc.cast(segment_command_64).?;
18791879 if (segment_lc.nsects == 0) return &[0]section_64{};
18801880 const data = lc.data[@sizeOf(segment_command_64)..];
1881 const sections = @ptrCast(
1881 const sections = @as(
18821882 [*]const section_64,
1883 @alignCast(@alignOf(section_64), &data[0]),
1883 @ptrCast(@alignCast(&data[0])),
18841884 )[0..segment_lc.nsects];
18851885 return sections;
18861886 }
......@@ -1903,16 +1903,16 @@ pub const LoadCommandIterator = struct {
19031903 pub fn next(it: *LoadCommandIterator) ?LoadCommand {
19041904 if (it.index >= it.ncmds) return null;
19051905
1906 const hdr = @ptrCast(
1906 const hdr = @as(
19071907 *const load_command,
1908 @alignCast(@alignOf(load_command), &it.buffer[0]),
1908 @ptrCast(@alignCast(&it.buffer[0])),
19091909 ).*;
19101910 const cmd = LoadCommand{
19111911 .hdr = hdr,
19121912 .data = it.buffer[0..hdr.cmdsize],
19131913 };
19141914
1915 it.buffer = @alignCast(@alignOf(u64), it.buffer[hdr.cmdsize..]);
1915 it.buffer = @alignCast(it.buffer[hdr.cmdsize..]);
19161916 it.index += 1;
19171917
19181918 return cmd;
lib/std/math.zig+46-40
......@@ -85,31 +85,31 @@ pub const inf_f128 = @compileError("Deprecated: use `inf(f128)` instead");
8585pub const epsilon = @compileError("Deprecated: use `floatEps` instead");
8686
8787pub const nan_u16 = @as(u16, 0x7C01);
88pub const nan_f16 = @bitCast(f16, nan_u16);
88pub const nan_f16 = @as(f16, @bitCast(nan_u16));
8989
9090pub const qnan_u16 = @as(u16, 0x7E00);
91pub const qnan_f16 = @bitCast(f16, qnan_u16);
91pub const qnan_f16 = @as(f16, @bitCast(qnan_u16));
9292
9393pub const nan_u32 = @as(u32, 0x7F800001);
94pub const nan_f32 = @bitCast(f32, nan_u32);
94pub const nan_f32 = @as(f32, @bitCast(nan_u32));
9595
9696pub const qnan_u32 = @as(u32, 0x7FC00000);
97pub const qnan_f32 = @bitCast(f32, qnan_u32);
97pub const qnan_f32 = @as(f32, @bitCast(qnan_u32));
9898
9999pub 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
102102pub const qnan_u64 = @as(u64, 0x7ff8000000000000);
103pub const qnan_f64 = @bitCast(f64, qnan_u64);
103pub const qnan_f64 = @as(f64, @bitCast(qnan_u64));
104104
105105pub const nan_f80 = make_f80(F80{ .fraction = 0xA000000000000000, .exp = 0x7fff });
106106pub const qnan_f80 = make_f80(F80{ .fraction = 0xC000000000000000, .exp = 0x7fff });
107107
108108pub const nan_u128 = @as(u128, 0x7fff0000000000000000000000000001);
109pub const nan_f128 = @bitCast(f128, nan_u128);
109pub const nan_f128 = @as(f128, @bitCast(nan_u128));
110110
111111pub const qnan_u128 = @as(u128, 0x7fff8000000000000000000000000000);
112pub const qnan_f128 = @bitCast(f128, qnan_u128);
112pub const qnan_f128 = @as(f128, @bitCast(qnan_u128));
113113
114114pub const nan = @import("math/nan.zig").nan;
115115pub const snan = @import("math/nan.zig").snan;
......@@ -508,10 +508,10 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
508508 const C = @typeInfo(T).Vector.child;
509509 const len = @typeInfo(T).Vector.len;
510510 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)));
512512 } else {
513513 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));
515515 }
516516 };
517517
......@@ -552,10 +552,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
552552 const C = @typeInfo(T).Vector.child;
553553 const len = @typeInfo(T).Vector.len;
554554 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)));
556556 } else {
557557 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));
559559 }
560560 };
561561
......@@ -596,7 +596,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
596596 if (@typeInfo(C).Int.signedness == .signed) {
597597 @compileError("cannot rotate signed integers");
598598 }
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)));
600600 return (x >> @splat(@typeInfo(T).Vector.len, ar)) | (x << @splat(@typeInfo(T).Vector.len, 1 + ~ar));
601601 } else if (@typeInfo(T).Int.signedness == .signed) {
602602 @compileError("cannot rotate signed integer");
......@@ -604,7 +604,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
604604 if (T == u0) return 0;
605605
606606 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)));
608608 return x >> ar | x << (1 +% ~ar);
609609 } else {
610610 const ar = @mod(r, @typeInfo(T).Int.bits);
......@@ -640,7 +640,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
640640 if (@typeInfo(C).Int.signedness == .signed) {
641641 @compileError("cannot rotate signed integers");
642642 }
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)));
644644 return (x << @splat(@typeInfo(T).Vector.len, ar)) | (x >> @splat(@typeInfo(T).Vector.len, 1 +% ~ar));
645645 } else if (@typeInfo(T).Int.signedness == .signed) {
646646 @compileError("cannot rotate signed integer");
......@@ -648,7 +648,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
648648 if (T == u0) return 0;
649649
650650 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)));
652652 return x << ar | x >> 1 +% ~ar;
653653 } else {
654654 const ar = @mod(r, @typeInfo(T).Int.bits);
......@@ -1029,9 +1029,9 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
10291029 if (int_info.signedness == .unsigned) return x;
10301030 const Uint = std.meta.Int(.unsigned, int_info.bits);
10311031 if (x < 0) {
1032 return ~@bitCast(Uint, x +% -1);
1032 return ~@as(Uint, @bitCast(x +% -1));
10331033 } else {
1034 return @intCast(Uint, x);
1034 return @as(Uint, @intCast(x));
10351035 }
10361036 },
10371037 else => unreachable,
......@@ -1056,7 +1056,7 @@ pub fn negateCast(x: anytype) !std.meta.Int(.signed, @bitSizeOf(@TypeOf(x))) {
10561056
10571057 if (x == -minInt(int)) return minInt(int);
10581058
1059 return -@intCast(int, x);
1059 return -@as(int, @intCast(x));
10601060}
10611061
10621062test "negateCast" {
......@@ -1080,7 +1080,7 @@ pub fn cast(comptime T: type, x: anytype) ?T {
10801080 } else if ((is_comptime or minInt(@TypeOf(x)) < minInt(T)) and x < minInt(T)) {
10811081 return null;
10821082 } else {
1083 return @intCast(T, x);
1083 return @as(T, @intCast(x));
10841084 }
10851085}
10861086
......@@ -1102,13 +1102,19 @@ test "cast" {
11021102
11031103pub 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
11051111/// 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)) {
11071113 const addr = @intFromPtr(ptr);
11081114 if (addr % alignment != 0) {
11091115 return error.UnalignedMemory;
11101116 }
1111 return @alignCast(alignment, ptr);
1117 return @alignCast(ptr);
11121118}
11131119
11141120/// Asserts `int > 0`.
......@@ -1172,7 +1178,7 @@ pub inline fn floor(value: anytype) @TypeOf(value) {
11721178pub fn floorPowerOfTwo(comptime T: type, value: T) T {
11731179 const uT = std.meta.Int(.unsigned, @typeInfo(T).Int.bits);
11741180 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)));
11761182}
11771183
11781184test "floorPowerOfTwo" {
......@@ -1211,7 +1217,7 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(@typeInfo(
12111217 assert(value != 0);
12121218 const PromotedType = std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits + 1);
12131219 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)));
12151221}
12161222
12171223/// 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) {
12271233 if (overflowBit & x != 0) {
12281234 return error.Overflow;
12291235 }
1230 return @intCast(T, x);
1236 return @as(T, @intCast(x));
12311237}
12321238
12331239/// 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) {
12771283 if (@typeInfo(T) != .Int or @typeInfo(T).Int.signedness != .unsigned)
12781284 @compileError("log2_int requires an unsigned integer, found " ++ @typeName(T));
12791285 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)));
12811287}
12821288
12831289/// 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 {
13111317 switch (@typeInfo(T)) {
13121318 .Float => {
13131319 switch (@typeInfo(@TypeOf(value))) {
1314 .Int => return @floatFromInt(T, value),
1315 .Float => return @floatCast(T, value),
1320 .Int => return @as(T, @floatFromInt(value)),
1321 .Float => return @as(T, @floatCast(value)),
13161322 .ComptimeInt => return @as(T, value),
13171323 .ComptimeFloat => return @as(T, value),
13181324 else => @compileError("bad type"),
......@@ -1326,7 +1332,7 @@ pub fn lossyCast(comptime T: type, value: anytype) T {
13261332 } else if (value <= minInt(T)) {
13271333 return @as(T, minInt(T));
13281334 } else {
1329 return @intCast(T, value);
1335 return @as(T, @intCast(value));
13301336 }
13311337 },
13321338 .Float, .ComptimeFloat => {
......@@ -1335,7 +1341,7 @@ pub fn lossyCast(comptime T: type, value: anytype) T {
13351341 } else if (value <= minInt(T)) {
13361342 return @as(T, minInt(T));
13371343 } else {
1338 return @intFromFloat(T, value);
1344 return @as(T, @intFromFloat(value));
13391345 }
13401346 },
13411347 else => @compileError("bad type"),
......@@ -1594,7 +1600,7 @@ test "compare between signed and unsigned" {
15941600 try testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1)));
15951601 try testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1)));
15961602 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));
15981604 try testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1)));
15991605 try testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));
16001606}
......@@ -1624,7 +1630,7 @@ test "order.compare" {
16241630
16251631test "compare.reverse" {
16261632 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));
16281634 try testing.expect(compare(2, op, 3) == compare(3, op.reverse(), 2));
16291635 try testing.expect(compare(3, op, 3) == compare(3, op.reverse(), 3));
16301636 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 {
16461652 if (MaskInt == u1) return @intFromBool(value);
16471653 if (MaskInt == i1) {
16481654 // 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))));
16501656 }
16511657
1652 return -%@intCast(MaskInt, @intFromBool(value));
1658 return -%@as(MaskInt, @intCast(@intFromBool(value)));
16531659}
16541660
16551661test "boolMask" {
......@@ -1680,7 +1686,7 @@ test "boolMask" {
16801686
16811687/// Return the mod of `num` with the smallest integer type
16821688pub 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)));
16841690}
16851691
16861692pub const F80 = struct {
......@@ -1690,14 +1696,14 @@ pub const F80 = struct {
16901696
16911697pub fn make_f80(repr: F80) f80 {
16921698 const int = (@as(u80, repr.exp) << 64) | repr.fraction;
1693 return @bitCast(f80, int);
1699 return @as(f80, @bitCast(int));
16941700}
16951701
16961702pub fn break_f80(x: f80) F80 {
1697 const int = @bitCast(u80, x);
1703 const int = @as(u80, @bitCast(x));
16981704 return .{
1699 .fraction = @truncate(u64, int),
1700 .exp = @truncate(u16, int >> 64),
1705 .fraction = @as(u64, @truncate(int)),
1706 .exp = @as(u16, @truncate(int >> 64)),
17011707 };
17021708}
17031709
......@@ -1709,7 +1715,7 @@ pub inline fn sign(i: anytype) @TypeOf(i) {
17091715 const T = @TypeOf(i);
17101716 return switch (@typeInfo(T)) {
17111717 .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))),
17131719 .Vector => |vinfo| blk: {
17141720 switch (@typeInfo(vinfo.child)) {
17151721 .Int, .Float => {
lib/std/math/acos.zig+8-8
......@@ -36,7 +36,7 @@ fn acos32(x: f32) f32 {
3636 const pio2_hi = 1.5707962513e+00;
3737 const pio2_lo = 7.5497894159e-08;
3838
39 const hx: u32 = @bitCast(u32, x);
39 const hx: u32 = @as(u32, @bitCast(x));
4040 const ix: u32 = hx & 0x7FFFFFFF;
4141
4242 // |x| >= 1 or nan
......@@ -72,8 +72,8 @@ fn acos32(x: f32) f32 {
7272 // x > 0.5
7373 const z = (1.0 - x) * 0.5;
7474 const s = @sqrt(z);
75 const jx = @bitCast(u32, s);
76 const df = @bitCast(f32, jx & 0xFFFFF000);
75 const jx = @as(u32, @bitCast(s));
76 const df = @as(f32, @bitCast(jx & 0xFFFFF000));
7777 const c = (z - df * df) / (s + df);
7878 const w = r32(z) * s + c;
7979 return 2 * (df + w);
......@@ -100,13 +100,13 @@ fn acos64(x: f64) f64 {
100100 const pio2_hi: f64 = 1.57079632679489655800e+00;
101101 const pio2_lo: f64 = 6.12323399573676603587e-17;
102102
103 const ux = @bitCast(u64, x);
104 const hx = @intCast(u32, ux >> 32);
103 const ux = @as(u64, @bitCast(x));
104 const hx = @as(u32, @intCast(ux >> 32));
105105 const ix = hx & 0x7FFFFFFF;
106106
107107 // |x| >= 1 or nan
108108 if (ix >= 0x3FF00000) {
109 const lx = @intCast(u32, ux & 0xFFFFFFFF);
109 const lx = @as(u32, @intCast(ux & 0xFFFFFFFF));
110110
111111 // acos(1) = 0, acos(-1) = pi
112112 if ((ix - 0x3FF00000) | lx == 0) {
......@@ -141,8 +141,8 @@ fn acos64(x: f64) f64 {
141141 // x > 0.5
142142 const z = (1.0 - x) * 0.5;
143143 const s = @sqrt(z);
144 const jx = @bitCast(u64, s);
145 const df = @bitCast(f64, jx & 0xFFFFFFFF00000000);
144 const jx = @as(u64, @bitCast(s));
145 const df = @as(f64, @bitCast(jx & 0xFFFFFFFF00000000));
146146 const c = (z - df * df) / (s + df);
147147 const w = r64(z) * s + c;
148148 return 2 * (df + w);
lib/std/math/acosh.zig+2-2
......@@ -24,7 +24,7 @@ pub fn acosh(x: anytype) @TypeOf(x) {
2424
2525// acosh(x) = log(x + sqrt(x * x - 1))
2626fn acosh32(x: f32) f32 {
27 const u = @bitCast(u32, x);
27 const u = @as(u32, @bitCast(x));
2828 const i = u & 0x7FFFFFFF;
2929
3030 // |x| < 2, invalid if x < 1 or nan
......@@ -42,7 +42,7 @@ fn acosh32(x: f32) f32 {
4242}
4343
4444fn acosh64(x: f64) f64 {
45 const u = @bitCast(u64, x);
45 const u = @as(u64, @bitCast(x));
4646 const e = (u >> 52) & 0x7FF;
4747
4848 // |x| < 2, invalid if x < 1 or nan
lib/std/math/asin.zig+6-6
......@@ -36,7 +36,7 @@ fn r32(z: f32) f32 {
3636fn asin32(x: f32) f32 {
3737 const pio2 = 1.570796326794896558e+00;
3838
39 const hx: u32 = @bitCast(u32, x);
39 const hx: u32 = @as(u32, @bitCast(x));
4040 const ix: u32 = hx & 0x7FFFFFFF;
4141
4242 // |x| >= 1
......@@ -92,13 +92,13 @@ fn asin64(x: f64) f64 {
9292 const pio2_hi: f64 = 1.57079632679489655800e+00;
9393 const pio2_lo: f64 = 6.12323399573676603587e-17;
9494
95 const ux = @bitCast(u64, x);
96 const hx = @intCast(u32, ux >> 32);
95 const ux = @as(u64, @bitCast(x));
96 const hx = @as(u32, @intCast(ux >> 32));
9797 const ix = hx & 0x7FFFFFFF;
9898
9999 // |x| >= 1 or nan
100100 if (ix >= 0x3FF00000) {
101 const lx = @intCast(u32, ux & 0xFFFFFFFF);
101 const lx = @as(u32, @intCast(ux & 0xFFFFFFFF));
102102
103103 // asin(1) = +-pi/2 with inexact
104104 if ((ix - 0x3FF00000) | lx == 0) {
......@@ -128,8 +128,8 @@ fn asin64(x: f64) f64 {
128128 if (ix >= 0x3FEF3333) {
129129 fx = pio2_hi - 2 * (s + s * r);
130130 } else {
131 const jx = @bitCast(u64, s);
132 const df = @bitCast(f64, jx & 0xFFFFFFFF00000000);
131 const jx = @as(u64, @bitCast(s));
132 const df = @as(f64, @bitCast(jx & 0xFFFFFFFF00000000));
133133 const c = (z - df * df) / (s + df);
134134 fx = 0.5 * pio2_hi - (2 * s * r - (pio2_lo - 2 * c) - (0.5 * pio2_hi - 2 * df));
135135 }
lib/std/math/asinh.zig+4-4
......@@ -26,11 +26,11 @@ pub fn asinh(x: anytype) @TypeOf(x) {
2626
2727// asinh(x) = sign(x) * log(|x| + sqrt(x * x + 1)) ~= x - x^3/6 + o(x^5)
2828fn asinh32(x: f32) f32 {
29 const u = @bitCast(u32, x);
29 const u = @as(u32, @bitCast(x));
3030 const i = u & 0x7FFFFFFF;
3131 const s = i >> 31;
3232
33 var rx = @bitCast(f32, i); // |x|
33 var rx = @as(f32, @bitCast(i)); // |x|
3434
3535 // TODO: Shouldn't need this explicit check.
3636 if (math.isNegativeInf(x)) {
......@@ -58,11 +58,11 @@ fn asinh32(x: f32) f32 {
5858}
5959
6060fn asinh64(x: f64) f64 {
61 const u = @bitCast(u64, x);
61 const u = @as(u64, @bitCast(x));
6262 const e = (u >> 52) & 0x7FF;
6363 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
6767 if (math.isNegativeInf(x)) {
6868 return x;
lib/std/math/atan.zig+5-5
......@@ -46,7 +46,7 @@ fn atan32(x_: f32) f32 {
4646 };
4747
4848 var x = x_;
49 var ix: u32 = @bitCast(u32, x);
49 var ix: u32 = @as(u32, @bitCast(x));
5050 const sign = ix >> 31;
5151 ix &= 0x7FFFFFFF;
5252
......@@ -143,8 +143,8 @@ fn atan64(x_: f64) f64 {
143143 };
144144
145145 var x = x_;
146 var ux = @bitCast(u64, x);
147 var ix = @intCast(u32, ux >> 32);
146 var ux = @as(u64, @bitCast(x));
147 var ix = @as(u32, @intCast(ux >> 32));
148148 const sign = ix >> 31;
149149 ix &= 0x7FFFFFFF;
150150
......@@ -165,7 +165,7 @@ fn atan64(x_: f64) f64 {
165165 // |x| < 2^(-27)
166166 if (ix < 0x3E400000) {
167167 if (ix < 0x00100000) {
168 math.doNotOptimizeAway(@floatCast(f32, x));
168 math.doNotOptimizeAway(@as(f32, @floatCast(x)));
169169 }
170170 return x;
171171 }
......@@ -212,7 +212,7 @@ fn atan64(x_: f64) f64 {
212212}
213213
214214test "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))));
216216 try expect(atan(@as(f64, 0.2)) == atan64(0.2));
217217}
218218
lib/std/math/atan2.zig+8-8
......@@ -44,8 +44,8 @@ fn atan2_32(y: f32, x: f32) f32 {
4444 return x + y;
4545 }
4646
47 var ix = @bitCast(u32, x);
48 var iy = @bitCast(u32, y);
47 var ix = @as(u32, @bitCast(x));
48 var iy = @as(u32, @bitCast(y));
4949
5050 // x = 1.0
5151 if (ix == 0x3F800000) {
......@@ -129,13 +129,13 @@ fn atan2_64(y: f64, x: f64) f64 {
129129 return x + y;
130130 }
131131
132 var ux = @bitCast(u64, x);
133 var ix = @intCast(u32, ux >> 32);
134 var lx = @intCast(u32, ux & 0xFFFFFFFF);
132 var ux = @as(u64, @bitCast(x));
133 var ix = @as(u32, @intCast(ux >> 32));
134 var lx = @as(u32, @intCast(ux & 0xFFFFFFFF));
135135
136 var uy = @bitCast(u64, y);
137 var iy = @intCast(u32, uy >> 32);
138 var ly = @intCast(u32, uy & 0xFFFFFFFF);
136 var uy = @as(u64, @bitCast(y));
137 var iy = @as(u32, @intCast(uy >> 32));
138 var ly = @as(u32, @intCast(uy & 0xFFFFFFFF));
139139
140140 // x = 1.0
141141 if ((ix -% 0x3FF00000) | lx == 0) {
lib/std/math/atanh.zig+5-5
......@@ -26,11 +26,11 @@ pub fn atanh(x: anytype) @TypeOf(x) {
2626
2727// atanh(x) = log((1 + x) / (1 - x)) / 2 = log1p(2x / (1 - x)) / 2 ~= x + x^3 / 3 + o(x^5)
2828fn atanh_32(x: f32) f32 {
29 const u = @bitCast(u32, x);
29 const u = @as(u32, @bitCast(x));
3030 const i = u & 0x7FFFFFFF;
3131 const s = u >> 31;
3232
33 var y = @bitCast(f32, i); // |x|
33 var y = @as(f32, @bitCast(i)); // |x|
3434
3535 if (y == 1.0) {
3636 return math.copysign(math.inf(f32), x);
......@@ -55,11 +55,11 @@ fn atanh_32(x: f32) f32 {
5555}
5656
5757fn atanh_64(x: f64) f64 {
58 const u = @bitCast(u64, x);
58 const u = @as(u64, @bitCast(x));
5959 const e = (u >> 52) & 0x7FF;
6060 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
6464 if (y == 1.0) {
6565 return math.copysign(math.inf(f64), x);
......@@ -69,7 +69,7 @@ fn atanh_64(x: f64) f64 {
6969 if (e < 0x3FF - 32) {
7070 // underflow
7171 if (e == 0) {
72 math.doNotOptimizeAway(@floatCast(f32, y));
72 math.doNotOptimizeAway(@as(f32, @floatCast(y)));
7373 }
7474 }
7575 // |x| < 0.5
lib/std/math/big/int.zig+32-32
......@@ -30,7 +30,7 @@ pub fn calcLimbLen(scalar: anytype) usize {
3030 }
3131
3232 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));
3434}
3535
3636pub fn calcToStringLimbsBufferLen(a_len: usize, base: u8) usize {
......@@ -87,8 +87,8 @@ pub fn addMulLimbWithCarry(a: Limb, b: Limb, c: Limb, carry: *Limb) Limb {
8787
8888 // r2 = b * c
8989 const bc = @as(DoubleLimb, math.mulWide(Limb, b, c));
90 const r2 = @truncate(Limb, bc);
91 const c2 = @truncate(Limb, bc >> limb_bits);
90 const r2 = @as(Limb, @truncate(bc));
91 const c2 = @as(Limb, @truncate(bc >> limb_bits));
9292
9393 // ov2[0] = ov1[0] + r2
9494 const ov2 = @addWithOverflow(ov1[0], r2);
......@@ -107,8 +107,8 @@ fn subMulLimbWithBorrow(a: Limb, b: Limb, c: Limb, carry: *Limb) Limb {
107107
108108 // r2 = b * c
109109 const bc = @as(DoubleLimb, std.math.mulWide(Limb, b, c));
110 const r2 = @truncate(Limb, bc);
111 const c2 = @truncate(Limb, bc >> limb_bits);
110 const r2 = @as(Limb, @truncate(bc));
111 const c2 = @as(Limb, @truncate(bc >> limb_bits));
112112
113113 // ov2[0] = ov1[0] - r2
114114 const ov2 = @subWithOverflow(ov1[0], r2);
......@@ -244,7 +244,7 @@ pub const Mutable = struct {
244244 } else {
245245 var i: usize = 0;
246246 while (true) : (i += 1) {
247 self.limbs[i] = @truncate(Limb, w_value);
247 self.limbs[i] = @as(Limb, @truncate(w_value));
248248 w_value >>= limb_bits;
249249
250250 if (w_value == 0) break;
......@@ -340,7 +340,7 @@ pub const Mutable = struct {
340340 }
341341
342342 const req_limbs = calcTwosCompLimbCount(bit_count);
343 const bit = @truncate(Log2Limb, bit_count - 1);
343 const bit = @as(Log2Limb, @truncate(bit_count - 1));
344344 const signmask = @as(Limb, 1) << bit; // 0b0..010..0 where 1 is the sign bit.
345345 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 {
365365 r.set(0);
366366 } else {
367367 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));
369369 const new_signmask = @as(Limb, 1) << msb; // 0b0..010..0 where 1 is the sign bit.
370370 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 {
11531153 // const msb = @truncate(Log2Limb, checkbit);
11541154 // 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) {
11571157 // Need to saturate.
11581158 r.setTwosCompIntLimit(if (a.positive) .max else .min, signedness, bit_count);
11591159 return;
......@@ -1554,7 +1554,7 @@ pub const Mutable = struct {
15541554 // Optimization for small divisor. By using a half limb we can avoid requiring DoubleLimb
15551555 // divisions in the hot code path. This may often require compiler_rt software-emulation.
15561556 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)));
15581558 } else {
15591559 lldiv1(q.limbs, &r.limbs[0], x.limbs[xy_trailing..x.len], divisor);
15601560 }
......@@ -1671,7 +1671,7 @@ pub const Mutable = struct {
16711671 } else {
16721672 const q0 = (@as(DoubleLimb, x.limbs[i]) << limb_bits) | @as(DoubleLimb, x.limbs[i - 1]);
16731673 const n0 = @as(DoubleLimb, y.limbs[t]);
1674 q.limbs[k] = @intCast(Limb, q0 / n0);
1674 q.limbs[k] = @as(Limb, @intCast(q0 / n0));
16751675 }
16761676
16771677 // 3.2
......@@ -1750,7 +1750,7 @@ pub const Mutable = struct {
17501750 return;
17511751 }
17521752
1753 const bit = @truncate(Log2Limb, bit_count - 1);
1753 const bit = @as(Log2Limb, @truncate(bit_count - 1));
17541754 const signmask = @as(Limb, 1) << bit;
17551755 const mask = (signmask << 1) -% 1;
17561756
......@@ -1781,7 +1781,7 @@ pub const Mutable = struct {
17811781 return;
17821782 }
17831783
1784 const bit = @truncate(Log2Limb, bit_count - 1);
1784 const bit = @as(Log2Limb, @truncate(bit_count - 1));
17851785 const signmask = @as(Limb, 1) << bit; // 0b0..010...0 where 1 is the sign bit.
17861786 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 {
19121912 .Big => buffer.len - ((total_bits + 7) / 8),
19131913 };
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));
19161916 positive = ((buffer[last_byte] & sign_bit) == 0);
19171917 }
19181918
......@@ -1942,7 +1942,7 @@ pub const Mutable = struct {
19421942 .signed => b: {
19431943 const SLimb = std.meta.Int(.signed, @bitSizeOf(Limb));
19441944 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));
19461946 },
19471947 };
19481948
......@@ -2170,7 +2170,7 @@ pub const Const = struct {
21702170 var r: UT = 0;
21712171
21722172 if (@sizeOf(UT) <= @sizeOf(Limb)) {
2173 r = @intCast(UT, self.limbs[0]);
2173 r = @as(UT, @intCast(self.limbs[0]));
21742174 } else {
21752175 for (self.limbs[0..self.limbs.len], 0..) |_, ri| {
21762176 const limb = self.limbs[self.limbs.len - ri - 1];
......@@ -2180,10 +2180,10 @@ pub const Const = struct {
21802180 }
21812181
21822182 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;
21842184 } else {
21852185 if (self.positive) {
2186 return @intCast(T, r);
2186 return @as(T, @intCast(r));
21872187 } else {
21882188 if (math.cast(T, r)) |ok| {
21892189 return -ok;
......@@ -2292,7 +2292,7 @@ pub const Const = struct {
22922292 outer: for (self.limbs[0..self.limbs.len]) |limb| {
22932293 var shift: usize = 0;
22942294 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)));
22962296 const ch = std.fmt.digitToChar(r, case);
22972297 string[digits_len] = ch;
22982298 digits_len += 1;
......@@ -2340,7 +2340,7 @@ pub const Const = struct {
23402340 var r_word = r.limbs[0];
23412341 var i: usize = 0;
23422342 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);
23442344 r_word /= base;
23452345 string[digits_len] = ch;
23462346 digits_len += 1;
......@@ -2352,7 +2352,7 @@ pub const Const = struct {
23522352
23532353 var r_word = q.limbs[0];
23542354 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);
23562356 r_word /= base;
23572357 string[digits_len] = ch;
23582358 digits_len += 1;
......@@ -3680,13 +3680,13 @@ fn lldiv1(quo: []Limb, rem: *Limb, a: []const Limb, b: Limb) void {
36803680 rem.* = 0;
36813681 } else if (pdiv < b) {
36823682 quo[i] = 0;
3683 rem.* = @truncate(Limb, pdiv);
3683 rem.* = @as(Limb, @truncate(pdiv));
36843684 } else if (pdiv == b) {
36853685 quo[i] = 1;
36863686 rem.* = 0;
36873687 } else {
3688 quo[i] = @truncate(Limb, @divTrunc(pdiv, b));
3689 rem.* = @truncate(Limb, pdiv - (quo[i] *% b));
3688 quo[i] = @as(Limb, @truncate(@divTrunc(pdiv, b)));
3689 rem.* = @as(Limb, @truncate(pdiv - (quo[i] *% b)));
36903690 }
36913691 }
36923692}
......@@ -3719,7 +3719,7 @@ fn llshl(r: []Limb, a: []const Limb, shift: usize) void {
37193719 @setRuntimeSafety(debug_safety);
37203720 assert(a.len >= 1);
37213721
3722 const interior_limb_shift = @truncate(Log2Limb, shift);
3722 const interior_limb_shift = @as(Log2Limb, @truncate(shift));
37233723
37243724 // We only need the extra limb if the shift of the last element overflows.
37253725 // This is useful for the implementation of `shiftLeftSat`.
......@@ -3741,7 +3741,7 @@ fn llshl(r: []Limb, a: []const Limb, shift: usize) void {
37413741 r[dst_i] = carry | @call(.always_inline, math.shr, .{
37423742 Limb,
37433743 src_digit,
3744 limb_bits - @intCast(Limb, interior_limb_shift),
3744 limb_bits - @as(Limb, @intCast(interior_limb_shift)),
37453745 });
37463746 carry = (src_digit << interior_limb_shift);
37473747 }
......@@ -3756,7 +3756,7 @@ fn llshr(r: []Limb, a: []const Limb, shift: usize) void {
37563756 assert(r.len >= a.len - (shift / limb_bits));
37573757
37583758 const limb_shift = shift / limb_bits;
3759 const interior_limb_shift = @truncate(Log2Limb, shift);
3759 const interior_limb_shift = @as(Log2Limb, @truncate(shift));
37603760
37613761 var carry: Limb = 0;
37623762 var i: usize = 0;
......@@ -3769,7 +3769,7 @@ fn llshr(r: []Limb, a: []const Limb, shift: usize) void {
37693769 carry = @call(.always_inline, math.shl, .{
37703770 Limb,
37713771 src_digit,
3772 limb_bits - @intCast(Limb, interior_limb_shift),
3772 limb_bits - @as(Limb, @intCast(interior_limb_shift)),
37733773 });
37743774 }
37753775}
......@@ -4150,7 +4150,7 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {
41504150 // Square the result if the current bit is zero, square and multiply by a if
41514151 // it is one.
41524152 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
41554155 var i: usize = 0;
41564156 while (i < exp_bits) : (i += 1) {
......@@ -4174,9 +4174,9 @@ fn fixedIntFromSignedDoubleLimb(A: SignedDoubleLimb, storage: []Limb) Mutable {
41744174 assert(storage.len >= 2);
41754175
41764176 const A_is_positive = A >= 0;
4177 const Au = @intCast(DoubleLimb, if (A < 0) -A else A);
4178 storage[0] = @truncate(Limb, Au);
4179 storage[1] = @truncate(Limb, Au >> limb_bits);
4177 const Au = @as(DoubleLimb, @intCast(if (A < 0) -A else A));
4178 storage[0] = @as(Limb, @truncate(Au));
4179 storage[1] = @as(Limb, @truncate(Au >> limb_bits));
41804180 return .{
41814181 .limbs = storage[0..2],
41824182 .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" {
28982898
28992899 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa };
29002900 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
29032903 buffer = &[_]u8{ 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };
29042904 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
29072907 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa, 0xaa, 0xaa, 0xaa };
29082908 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
29112911 buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };
29122912 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
29152915 bit_count = 12 * 8 + 2;
29162916
......@@ -3014,20 +3014,20 @@ test "big int bit reverse" {
30143014 try bitReverseTest(u96, 0x123456789abcdef111213141, 0x828c84888f7b3d591e6a2c48);
30153015 try bitReverseTest(u128, 0x123456789abcdef11121314151617181, 0x818e868a828c84888f7b3d591e6a2c48);
30163016
3017 try bitReverseTest(i8, @bitCast(i8, @as(u8, 0x92)), @bitCast(i8, @as(u8, 0x49)));
3018 try bitReverseTest(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x2c48)));
3019 try bitReverseTest(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x6a2c48)));
3020 try bitReverseTest(i24, @bitCast(i24, @as(u24, 0x12345f)), @bitCast(i24, @as(u24, 0xfa2c48)));
3021 try bitReverseTest(i24, @bitCast(i24, @as(u24, 0xf23456)), @bitCast(i24, @as(u24, 0x6a2c4f)));
3022 try bitReverseTest(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x1e6a2c48)));
3023 try bitReverseTest(i32, @bitCast(i32, @as(u32, 0xf2345678)), @bitCast(i32, @as(u32, 0x1e6a2c4f)));
3024 try bitReverseTest(i32, @bitCast(i32, @as(u32, 0x1234567f)), @bitCast(i32, @as(u32, 0xfe6a2c48)));
3025 try bitReverseTest(i40, @bitCast(i40, @as(u40, 0x123456789a)), @bitCast(i40, @as(u40, 0x591e6a2c48)));
3026 try bitReverseTest(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0x3d591e6a2c48)));
3027 try bitReverseTest(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0x7b3d591e6a2c48)));
3028 try bitReverseTest(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48)));
3029 try bitReverseTest(i96, @bitCast(i96, @as(u96, 0x123456789abcdef111213141)), @bitCast(i96, @as(u96, 0x828c84888f7b3d591e6a2c48)));
3030 try bitReverseTest(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)), @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48)));
3017 try bitReverseTest(i8, @as(i8, @bitCast(@as(u8, 0x92))), @as(i8, @bitCast(@as(u8, 0x49))));
3018 try bitReverseTest(i16, @as(i16, @bitCast(@as(u16, 0x1234))), @as(i16, @bitCast(@as(u16, 0x2c48))));
3019 try bitReverseTest(i24, @as(i24, @bitCast(@as(u24, 0x123456))), @as(i24, @bitCast(@as(u24, 0x6a2c48))));
3020 try bitReverseTest(i24, @as(i24, @bitCast(@as(u24, 0x12345f))), @as(i24, @bitCast(@as(u24, 0xfa2c48))));
3021 try bitReverseTest(i24, @as(i24, @bitCast(@as(u24, 0xf23456))), @as(i24, @bitCast(@as(u24, 0x6a2c4f))));
3022 try bitReverseTest(i32, @as(i32, @bitCast(@as(u32, 0x12345678))), @as(i32, @bitCast(@as(u32, 0x1e6a2c48))));
3023 try bitReverseTest(i32, @as(i32, @bitCast(@as(u32, 0xf2345678))), @as(i32, @bitCast(@as(u32, 0x1e6a2c4f))));
3024 try bitReverseTest(i32, @as(i32, @bitCast(@as(u32, 0x1234567f))), @as(i32, @bitCast(@as(u32, 0xfe6a2c48))));
3025 try bitReverseTest(i40, @as(i40, @bitCast(@as(u40, 0x123456789a))), @as(i40, @bitCast(@as(u40, 0x591e6a2c48))));
3026 try bitReverseTest(i48, @as(i48, @bitCast(@as(u48, 0x123456789abc))), @as(i48, @bitCast(@as(u48, 0x3d591e6a2c48))));
3027 try bitReverseTest(i56, @as(i56, @bitCast(@as(u56, 0x123456789abcde))), @as(i56, @bitCast(@as(u56, 0x7b3d591e6a2c48))));
3028 try bitReverseTest(i64, @as(i64, @bitCast(@as(u64, 0x123456789abcdef1))), @as(i64, @bitCast(@as(u64, 0x8f7b3d591e6a2c48))));
3029 try bitReverseTest(i96, @as(i96, @bitCast(@as(u96, 0x123456789abcdef111213141))), @as(i96, @bitCast(@as(u96, 0x828c84888f7b3d591e6a2c48))));
3030 try bitReverseTest(i128, @as(i128, @bitCast(@as(u128, 0x123456789abcdef11121314151617181))), @as(i128, @bitCast(@as(u128, 0x818e868a828c84888f7b3d591e6a2c48))));
30313031}
30323032
30333033fn byteSwapTest(comptime T: type, comptime input: comptime_int, comptime expected_output: comptime_int) !void {
......@@ -3063,16 +3063,16 @@ test "big int byte swap" {
30633063 try byteSwapTest(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412);
30643064
30653065 try byteSwapTest(i8, -50, -50);
3066 try byteSwapTest(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412)));
3067 try byteSwapTest(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x563412)));
3068 try byteSwapTest(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412)));
3069 try byteSwapTest(i40, @bitCast(i40, @as(u40, 0x123456789a)), @bitCast(i40, @as(u40, 0x9a78563412)));
3070 try byteSwapTest(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412)));
3071 try byteSwapTest(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0xdebc9a78563412)));
3072 try byteSwapTest(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412)));
3073 try byteSwapTest(i88, @bitCast(i88, @as(u88, 0x123456789abcdef1112131)), @bitCast(i88, @as(u88, 0x312111f1debc9a78563412)));
3074 try byteSwapTest(i96, @bitCast(i96, @as(u96, 0x123456789abcdef111213141)), @bitCast(i96, @as(u96, 0x41312111f1debc9a78563412)));
3075 try byteSwapTest(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)), @bitCast(i128, @as(u128, 0x8171615141312111f1debc9a78563412)));
3066 try byteSwapTest(i16, @as(i16, @bitCast(@as(u16, 0x1234))), @as(i16, @bitCast(@as(u16, 0x3412))));
3067 try byteSwapTest(i24, @as(i24, @bitCast(@as(u24, 0x123456))), @as(i24, @bitCast(@as(u24, 0x563412))));
3068 try byteSwapTest(i32, @as(i32, @bitCast(@as(u32, 0x12345678))), @as(i32, @bitCast(@as(u32, 0x78563412))));
3069 try byteSwapTest(i40, @as(i40, @bitCast(@as(u40, 0x123456789a))), @as(i40, @bitCast(@as(u40, 0x9a78563412))));
3070 try byteSwapTest(i48, @as(i48, @bitCast(@as(u48, 0x123456789abc))), @as(i48, @bitCast(@as(u48, 0xbc9a78563412))));
3071 try byteSwapTest(i56, @as(i56, @bitCast(@as(u56, 0x123456789abcde))), @as(i56, @bitCast(@as(u56, 0xdebc9a78563412))));
3072 try byteSwapTest(i64, @as(i64, @bitCast(@as(u64, 0x123456789abcdef1))), @as(i64, @bitCast(@as(u64, 0xf1debc9a78563412))));
3073 try byteSwapTest(i88, @as(i88, @bitCast(@as(u88, 0x123456789abcdef1112131))), @as(i88, @bitCast(@as(u88, 0x312111f1debc9a78563412))));
3074 try byteSwapTest(i96, @as(i96, @bitCast(@as(u96, 0x123456789abcdef111213141))), @as(i96, @bitCast(@as(u96, 0x41312111f1debc9a78563412))));
3075 try byteSwapTest(i128, @as(i128, @bitCast(@as(u128, 0x123456789abcdef11121314151617181))), @as(i128, @bitCast(@as(u128, 0x8171615141312111f1debc9a78563412))));
30763076
30773077 try byteSwapTest(u512, 0x80, 1 << 511);
30783078 try byteSwapTest(i512, 0x80, minInt(i512));
......@@ -3080,11 +3080,11 @@ test "big int byte swap" {
30803080 try byteSwapTest(i512, -0x100, (1 << 504) - 1);
30813081 try byteSwapTest(i400, -0x100, (1 << 392) - 1);
30823082 try byteSwapTest(i400, -0x2, -(1 << 392) - 1);
3083 try byteSwapTest(i24, @bitCast(i24, @as(u24, 0xf23456)), 0x5634f2);
3084 try byteSwapTest(i24, 0x1234f6, @bitCast(i24, @as(u24, 0xf63412)));
3085 try byteSwapTest(i32, @bitCast(i32, @as(u32, 0xf2345678)), 0x785634f2);
3086 try byteSwapTest(i32, 0x123456f8, @bitCast(i32, @as(u32, 0xf8563412)));
3087 try byteSwapTest(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412)));
3083 try byteSwapTest(i24, @as(i24, @bitCast(@as(u24, 0xf23456))), 0x5634f2);
3084 try byteSwapTest(i24, 0x1234f6, @as(i24, @bitCast(@as(u24, 0xf63412))));
3085 try byteSwapTest(i32, @as(i32, @bitCast(@as(u32, 0xf2345678))), 0x785634f2);
3086 try byteSwapTest(i32, 0x123456f8, @as(i32, @bitCast(@as(u32, 0xf8563412))));
3087 try byteSwapTest(i48, 0x123456789abc, @as(i48, @bitCast(@as(u48, 0xbc9a78563412))));
30883088}
30893089
30903090test "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 {
137137 debug.assert(@typeInfo(T) == .Float);
138138
139139 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
142142 const exponent_bits = math.floatExponentBits(T);
143143 const exponent_bias = (1 << (exponent_bits - 1)) - 1;
......@@ -146,7 +146,7 @@ pub const Rational = struct {
146146 const exponent_mask = (1 << exponent_bits) - 1;
147147 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));
150150 var mantissa = f_bits & mantissa_mask;
151151
152152 switch (exponent) {
......@@ -177,9 +177,9 @@ pub const Rational = struct {
177177
178178 try self.q.set(1);
179179 if (shift >= 0) {
180 try self.q.shiftLeft(&self.q, @intCast(usize, shift));
180 try self.q.shiftLeft(&self.q, @as(usize, @intCast(shift)));
181181 } else {
182 try self.p.shiftLeft(&self.p, @intCast(usize, -shift));
182 try self.p.shiftLeft(&self.p, @as(usize, @intCast(-shift)));
183183 }
184184
185185 try self.reduce();
......@@ -210,7 +210,7 @@ pub const Rational = struct {
210210 }
211211
212212 // 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
215215 var a2 = try self.p.clone();
216216 defer a2.deinit();
......@@ -220,9 +220,9 @@ pub const Rational = struct {
220220
221221 const shift = msize2 - exp;
222222 if (shift >= 0) {
223 try a2.shiftLeft(&a2, @intCast(usize, shift));
223 try a2.shiftLeft(&a2, @as(usize, @intCast(shift)));
224224 } else {
225 try b2.shiftLeft(&b2, @intCast(usize, -shift));
225 try b2.shiftLeft(&b2, @as(usize, @intCast(-shift)));
226226 }
227227
228228 // 2. compute quotient and remainder
......@@ -254,8 +254,8 @@ pub const Rational = struct {
254254 // 4. Rounding
255255 if (emin - msize <= exp and exp <= emin) {
256256 // denormal
257 const shift1 = @intCast(math.Log2Int(BitReprType), emin - (exp - 1));
258 const lost_bits = mantissa & ((@intCast(BitReprType, 1) << shift1) - 1);
257 const shift1 = @as(math.Log2Int(BitReprType), @intCast(emin - (exp - 1)));
258 const lost_bits = mantissa & ((@as(BitReprType, @intCast(1)) << shift1) - 1);
259259 have_rem = have_rem or lost_bits != 0;
260260 mantissa >>= shift1;
261261 exp = 2 - ebias;
......@@ -276,7 +276,7 @@ pub const Rational = struct {
276276 }
277277 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)));
280280 if (math.isInf(f)) {
281281 exact = false;
282282 }
......@@ -477,7 +477,7 @@ fn extractLowBits(a: Int, comptime T: type) T {
477477 const t_bits = @typeInfo(T).Int.bits;
478478 const limb_bits = @typeInfo(Limb).Int.bits;
479479 if (t_bits <= limb_bits) {
480 return @truncate(T, a.limbs[0]);
480 return @as(T, @truncate(a.limbs[0]));
481481 } else {
482482 var r: T = 0;
483483 comptime var i: usize = 0;
lib/std/math/cbrt.zig+11-11
......@@ -27,7 +27,7 @@ fn cbrt32(x: f32) f32 {
2727 const B1: u32 = 709958130; // (127 - 127.0 / 3 - 0.03306235651) * 2^23
2828 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));
3131 var hx = u & 0x7FFFFFFF;
3232
3333 // cbrt(nan, inf) = itself
......@@ -41,7 +41,7 @@ fn cbrt32(x: f32) f32 {
4141 if (hx == 0) {
4242 return x;
4343 }
44 u = @bitCast(u32, x * 0x1.0p24);
44 u = @as(u32, @bitCast(x * 0x1.0p24));
4545 hx = u & 0x7FFFFFFF;
4646 hx = hx / 3 + B2;
4747 } else {
......@@ -52,7 +52,7 @@ fn cbrt32(x: f32) f32 {
5252 u |= hx;
5353
5454 // first step newton to 16 bits
55 var t: f64 = @bitCast(f32, u);
55 var t: f64 = @as(f32, @bitCast(u));
5656 var r: f64 = t * t * t;
5757 t = t * (@as(f64, x) + x + r) / (x + r + r);
5858
......@@ -60,7 +60,7 @@ fn cbrt32(x: f32) f32 {
6060 r = t * t * t;
6161 t = t * (@as(f64, x) + x + r) / (x + r + r);
6262
63 return @floatCast(f32, t);
63 return @as(f32, @floatCast(t));
6464}
6565
6666fn cbrt64(x: f64) f64 {
......@@ -74,8 +74,8 @@ fn cbrt64(x: f64) f64 {
7474 const P3: f64 = -0.758397934778766047437;
7575 const P4: f64 = 0.145996192886612446982;
7676
77 var u = @bitCast(u64, x);
78 var hx = @intCast(u32, u >> 32) & 0x7FFFFFFF;
77 var u = @as(u64, @bitCast(x));
78 var hx = @as(u32, @intCast(u >> 32)) & 0x7FFFFFFF;
7979
8080 // cbrt(nan, inf) = itself
8181 if (hx >= 0x7FF00000) {
......@@ -84,8 +84,8 @@ fn cbrt64(x: f64) f64 {
8484
8585 // cbrt to ~5bits
8686 if (hx < 0x00100000) {
87 u = @bitCast(u64, x * 0x1.0p54);
88 hx = @intCast(u32, u >> 32) & 0x7FFFFFFF;
87 u = @as(u64, @bitCast(x * 0x1.0p54));
88 hx = @as(u32, @intCast(u >> 32)) & 0x7FFFFFFF;
8989
9090 // cbrt(0) is itself
9191 if (hx == 0) {
......@@ -98,7 +98,7 @@ fn cbrt64(x: f64) f64 {
9898
9999 u &= 1 << 63;
100100 u |= @as(u64, hx) << 32;
101 var t = @bitCast(f64, u);
101 var t = @as(f64, @bitCast(u));
102102
103103 // cbrt to 23 bits
104104 // cbrt(x) = t * cbrt(x / t^3) ~= t * P(t^3 / x)
......@@ -106,9 +106,9 @@ fn cbrt64(x: f64) f64 {
106106 t = t * ((P0 + r * (P1 + r * P2)) + ((r * r) * r) * (P3 + r * P4));
107107
108108 // Round t away from 0 to 23 bits
109 u = @bitCast(u64, t);
109 u = @as(u64, @bitCast(t));
110110 u = (u + 0x80000000) & 0xFFFFFFFFC0000000;
111 t = @bitCast(f64, u);
111 t = @as(f64, @bitCast(u));
112112
113113 // one step newton to 53 bits
114114 const s = t * t;
lib/std/math/complex/atan.zig+2-2
......@@ -32,7 +32,7 @@ fn redupif32(x: f32) f32 {
3232 t -= 0.5;
3333 }
3434
35 const u = @floatFromInt(f32, @intFromFloat(i32, t));
35 const u = @as(f32, @floatFromInt(@as(i32, @intFromFloat(t))));
3636 return ((x - u * DP1) - u * DP2) - t * DP3;
3737}
3838
......@@ -81,7 +81,7 @@ fn redupif64(x: f64) f64 {
8181 t -= 0.5;
8282 }
8383
84 const u = @floatFromInt(f64, @intFromFloat(i64, t));
84 const u = @as(f64, @floatFromInt(@as(i64, @intFromFloat(t))));
8585 return ((x - u * DP1) - u * DP2) - t * DP3;
8686}
8787
lib/std/math/complex/cosh.zig+8-8
......@@ -26,10 +26,10 @@ fn cosh32(z: Complex(f32)) Complex(f32) {
2626 const x = z.re;
2727 const y = z.im;
2828
29 const hx = @bitCast(u32, x);
29 const hx = @as(u32, @bitCast(x));
3030 const ix = hx & 0x7fffffff;
3131
32 const hy = @bitCast(u32, y);
32 const hy = @as(u32, @bitCast(y));
3333 const iy = hy & 0x7fffffff;
3434
3535 if (ix < 0x7f800000 and iy < 0x7f800000) {
......@@ -89,14 +89,14 @@ fn cosh64(z: Complex(f64)) Complex(f64) {
8989 const x = z.re;
9090 const y = z.im;
9191
92 const fx = @bitCast(u64, x);
93 const hx = @intCast(u32, fx >> 32);
94 const lx = @truncate(u32, fx);
92 const fx = @as(u64, @bitCast(x));
93 const hx = @as(u32, @intCast(fx >> 32));
94 const lx = @as(u32, @truncate(fx));
9595 const ix = hx & 0x7fffffff;
9696
97 const fy = @bitCast(u64, y);
98 const hy = @intCast(u32, fy >> 32);
99 const ly = @truncate(u32, fy);
97 const fy = @as(u64, @bitCast(y));
98 const hy = @as(u32, @intCast(fy >> 32));
99 const ly = @as(u32, @truncate(fy));
100100 const iy = hy & 0x7fffffff;
101101
102102 // nearly non-exceptional case where x, y are finite
lib/std/math/complex/exp.zig+8-8
......@@ -30,13 +30,13 @@ fn exp32(z: Complex(f32)) Complex(f32) {
3030 const x = z.re;
3131 const y = z.im;
3232
33 const hy = @bitCast(u32, y) & 0x7fffffff;
33 const hy = @as(u32, @bitCast(y)) & 0x7fffffff;
3434 // cexp(x + i0) = exp(x) + i0
3535 if (hy == 0) {
3636 return Complex(f32).init(@exp(x), y);
3737 }
3838
39 const hx = @bitCast(u32, x);
39 const hx = @as(u32, @bitCast(x));
4040 // cexp(0 + iy) = cos(y) + isin(y)
4141 if ((hx & 0x7fffffff) == 0) {
4242 return Complex(f32).init(@cos(y), @sin(y));
......@@ -75,18 +75,18 @@ fn exp64(z: Complex(f64)) Complex(f64) {
7575 const x = z.re;
7676 const y = z.im;
7777
78 const fy = @bitCast(u64, y);
79 const hy = @intCast(u32, (fy >> 32) & 0x7fffffff);
80 const ly = @truncate(u32, fy);
78 const fy = @as(u64, @bitCast(y));
79 const hy = @as(u32, @intCast((fy >> 32) & 0x7fffffff));
80 const ly = @as(u32, @truncate(fy));
8181
8282 // cexp(x + i0) = exp(x) + i0
8383 if (hy | ly == 0) {
8484 return Complex(f64).init(@exp(x), y);
8585 }
8686
87 const fx = @bitCast(u64, x);
88 const hx = @intCast(u32, fx >> 32);
89 const lx = @truncate(u32, fx);
87 const fx = @as(u64, @bitCast(x));
88 const hx = @as(u32, @intCast(fx >> 32));
89 const lx = @as(u32, @truncate(fx));
9090
9191 // cexp(0 + iy) = cos(y) + isin(y)
9292 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 {
2727 const kln2 = 162.88958740; // k * ln2
2828
2929 const exp_x = @exp(x - kln2);
30 const hx = @bitCast(u32, exp_x);
30 const hx = @as(u32, @bitCast(exp_x));
3131 // 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;
33 return @bitCast(f32, (hx & 0x7fffff) | ((0x7f + 127) << 23));
32 expt.* = @as(i32, @intCast(hx >> 23)) - (0x7f + 127) + k;
33 return @as(f32, @bitCast((hx & 0x7fffff) | ((0x7f + 127) << 23)));
3434}
3535
3636fn ldexp_cexp32(z: Complex(f32), expt: i32) Complex(f32) {
......@@ -39,10 +39,10 @@ fn ldexp_cexp32(z: Complex(f32), expt: i32) Complex(f32) {
3939 const exptf = expt + ex_expt;
4040
4141 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
4444 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
4747 return Complex(f32).init(
4848 @cos(z.im) * exp_x * scale1 * scale2,
......@@ -56,14 +56,14 @@ fn frexp_exp64(x: f64, expt: *i32) f64 {
5656
5757 const exp_x = @exp(x - kln2);
5858
59 const fx = @bitCast(u64, exp_x);
60 const hx = @intCast(u32, fx >> 32);
61 const lx = @truncate(u32, fx);
59 const fx = @as(u64, @bitCast(exp_x));
60 const hx = @as(u32, @intCast(fx >> 32));
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
6565 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));
6767}
6868
6969fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {
......@@ -72,10 +72,10 @@ fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {
7272 const exptf = @as(i64, expt + ex_expt);
7373
7474 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
7777 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
8080 return Complex(f64).init(
8181 @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) {
2626 const x = z.re;
2727 const y = z.im;
2828
29 const hx = @bitCast(u32, x);
29 const hx = @as(u32, @bitCast(x));
3030 const ix = hx & 0x7fffffff;
3131
32 const hy = @bitCast(u32, y);
32 const hy = @as(u32, @bitCast(y));
3333 const iy = hy & 0x7fffffff;
3434
3535 if (ix < 0x7f800000 and iy < 0x7f800000) {
......@@ -89,14 +89,14 @@ fn sinh64(z: Complex(f64)) Complex(f64) {
8989 const x = z.re;
9090 const y = z.im;
9191
92 const fx = @bitCast(u64, x);
93 const hx = @intCast(u32, fx >> 32);
94 const lx = @truncate(u32, fx);
92 const fx = @as(u64, @bitCast(x));
93 const hx = @as(u32, @intCast(fx >> 32));
94 const lx = @as(u32, @truncate(fx));
9595 const ix = hx & 0x7fffffff;
9696
97 const fy = @bitCast(u64, y);
98 const hy = @intCast(u32, fy >> 32);
99 const ly = @truncate(u32, fy);
97 const fy = @as(u64, @bitCast(y));
98 const hy = @as(u32, @intCast(fy >> 32));
99 const ly = @as(u32, @truncate(fy));
100100 const iy = hy & 0x7fffffff;
101101
102102 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) {
5858 if (dx >= 0) {
5959 const t = @sqrt((dx + math.hypot(f64, dx, dy)) * 0.5);
6060 return Complex(f32).init(
61 @floatCast(f32, t),
62 @floatCast(f32, dy / (2.0 * t)),
61 @as(f32, @floatCast(t)),
62 @as(f32, @floatCast(dy / (2.0 * t))),
6363 );
6464 } else {
6565 const t = @sqrt((-dx + math.hypot(f64, dx, dy)) * 0.5);
6666 return Complex(f32).init(
67 @floatCast(f32, @fabs(y) / (2.0 * t)),
68 @floatCast(f32, math.copysign(t, y)),
67 @as(f32, @floatCast(@fabs(y) / (2.0 * t))),
68 @as(f32, @floatCast(math.copysign(t, y))),
6969 );
7070 }
7171}
lib/std/math/complex/tanh.zig+6-6
......@@ -24,7 +24,7 @@ fn tanh32(z: Complex(f32)) Complex(f32) {
2424 const x = z.re;
2525 const y = z.im;
2626
27 const hx = @bitCast(u32, x);
27 const hx = @as(u32, @bitCast(x));
2828 const ix = hx & 0x7fffffff;
2929
3030 if (ix >= 0x7f800000) {
......@@ -32,7 +32,7 @@ fn tanh32(z: Complex(f32)) Complex(f32) {
3232 const r = if (y == 0) y else x * y;
3333 return Complex(f32).init(x, r);
3434 }
35 const xx = @bitCast(f32, hx - 0x40000000);
35 const xx = @as(f32, @bitCast(hx - 0x40000000));
3636 const r = if (math.isInf(y)) y else @sin(y) * @cos(y);
3737 return Complex(f32).init(xx, math.copysign(@as(f32, 0.0), r));
3838 }
......@@ -62,11 +62,11 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
6262 const x = z.re;
6363 const y = z.im;
6464
65 const fx = @bitCast(u64, x);
65 const fx = @as(u64, @bitCast(x));
6666 // TODO: zig should allow this conversion implicitly because it can notice that the value necessarily
6767 // fits in range.
68 const hx = @intCast(u32, fx >> 32);
69 const lx = @truncate(u32, fx);
68 const hx = @as(u32, @intCast(fx >> 32));
69 const lx = @as(u32, @truncate(fx));
7070 const ix = hx & 0x7fffffff;
7171
7272 if (ix >= 0x7ff00000) {
......@@ -75,7 +75,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
7575 return Complex(f64).init(x, r);
7676 }
7777
78 const xx = @bitCast(f64, (@as(u64, hx - 0x40000000) << 32) | lx);
78 const xx = @as(f64, @bitCast((@as(u64, hx - 0x40000000) << 32) | lx));
7979 const r = if (math.isInf(y)) y else @sin(y) * @cos(y);
8080 return Complex(f64).init(xx, math.copysign(@as(f64, 0.0), r));
8181 }
lib/std/math/copysign.zig+3-3
......@@ -7,9 +7,9 @@ pub fn copysign(magnitude: anytype, sign: @TypeOf(magnitude)) @TypeOf(magnitude)
77 const T = @TypeOf(magnitude);
88 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
99 const sign_bit_mask = @as(TBits, 1) << (@bitSizeOf(T) - 1);
10 const mag = @bitCast(TBits, magnitude) & ~sign_bit_mask;
11 const sgn = @bitCast(TBits, sign) & sign_bit_mask;
12 return @bitCast(T, mag | sgn);
10 const mag = @as(TBits, @bitCast(magnitude)) & ~sign_bit_mask;
11 const sgn = @as(TBits, @bitCast(sign)) & sign_bit_mask;
12 return @as(T, @bitCast(mag | sgn));
1313}
1414
1515test "math.copysign" {
lib/std/math/cosh.zig+5-5
......@@ -29,9 +29,9 @@ pub fn cosh(x: anytype) @TypeOf(x) {
2929// = 1 + 0.5 * (exp(x) - 1) * (exp(x) - 1) / exp(x)
3030// = 1 + (x * x) / 2 + o(x^4)
3131fn cosh32(x: f32) f32 {
32 const u = @bitCast(u32, x);
32 const u = @as(u32, @bitCast(x));
3333 const ux = u & 0x7FFFFFFF;
34 const ax = @bitCast(f32, ux);
34 const ax = @as(f32, @bitCast(ux));
3535
3636 // |x| < log(2)
3737 if (ux < 0x3F317217) {
......@@ -54,9 +54,9 @@ fn cosh32(x: f32) f32 {
5454}
5555
5656fn cosh64(x: f64) f64 {
57 const u = @bitCast(u64, x);
58 const w = @intCast(u32, u >> 32) & (maxInt(u32) >> 1);
59 const ax = @bitCast(f64, u & (maxInt(u64) >> 1));
57 const u = @as(u64, @bitCast(x));
58 const w = @as(u32, @intCast(u >> 32)) & (maxInt(u32) >> 1);
59 const ax = @as(f64, @bitCast(u & (maxInt(u64) >> 1)));
6060
6161 // TODO: Shouldn't need this explicit check.
6262 if (x == 0.0) {
lib/std/math/expm1.zig+12-12
......@@ -38,7 +38,7 @@ fn expm1_32(x_: f32) f32 {
3838 const Q2: f32 = 1.5807170421e-3;
3939
4040 var x = x_;
41 const ux = @bitCast(u32, x);
41 const ux = @as(u32, @bitCast(x));
4242 const hx = ux & 0x7FFFFFFF;
4343 const sign = hx >> 31;
4444
......@@ -88,8 +88,8 @@ fn expm1_32(x_: f32) f32 {
8888 kf += 0.5;
8989 }
9090
91 k = @intFromFloat(i32, kf);
92 const t = @floatFromInt(f32, k);
91 k = @as(i32, @intFromFloat(kf));
92 const t = @as(f32, @floatFromInt(k));
9393 hi = x - t * ln2_hi;
9494 lo = t * ln2_lo;
9595 }
......@@ -133,7 +133,7 @@ fn expm1_32(x_: f32) f32 {
133133 }
134134 }
135135
136 const twopk = @bitCast(f32, @intCast(u32, (0x7F +% k) << 23));
136 const twopk = @as(f32, @bitCast(@as(u32, @intCast((0x7F +% k) << 23))));
137137
138138 if (k < 0 or k > 56) {
139139 var y = x - e + 1.0;
......@@ -146,7 +146,7 @@ fn expm1_32(x_: f32) f32 {
146146 return y - 1.0;
147147 }
148148
149 const uf = @bitCast(f32, @intCast(u32, 0x7F -% k) << 23);
149 const uf = @as(f32, @bitCast(@as(u32, @intCast(0x7F -% k)) << 23));
150150 if (k < 23) {
151151 return (x - e + (1 - uf)) * twopk;
152152 } else {
......@@ -169,8 +169,8 @@ fn expm1_64(x_: f64) f64 {
169169 const Q5: f64 = -2.01099218183624371326e-07;
170170
171171 var x = x_;
172 const ux = @bitCast(u64, x);
173 const hx = @intCast(u32, ux >> 32) & 0x7FFFFFFF;
172 const ux = @as(u64, @bitCast(x));
173 const hx = @as(u32, @intCast(ux >> 32)) & 0x7FFFFFFF;
174174 const sign = ux >> 63;
175175
176176 if (math.isNegativeInf(x)) {
......@@ -219,8 +219,8 @@ fn expm1_64(x_: f64) f64 {
219219 kf += 0.5;
220220 }
221221
222 k = @intFromFloat(i32, kf);
223 const t = @floatFromInt(f64, k);
222 k = @as(i32, @intFromFloat(kf));
223 const t = @as(f64, @floatFromInt(k));
224224 hi = x - t * ln2_hi;
225225 lo = t * ln2_lo;
226226 }
......@@ -231,7 +231,7 @@ fn expm1_64(x_: f64) f64 {
231231 // |x| < 2^(-54)
232232 else if (hx < 0x3C900000) {
233233 if (hx < 0x00100000) {
234 math.doNotOptimizeAway(@floatCast(f32, x));
234 math.doNotOptimizeAway(@as(f32, @floatCast(x)));
235235 }
236236 return x;
237237 } else {
......@@ -264,7 +264,7 @@ fn expm1_64(x_: f64) f64 {
264264 }
265265 }
266266
267 const twopk = @bitCast(f64, @intCast(u64, 0x3FF +% k) << 52);
267 const twopk = @as(f64, @bitCast(@as(u64, @intCast(0x3FF +% k)) << 52));
268268
269269 if (k < 0 or k > 56) {
270270 var y = x - e + 1.0;
......@@ -277,7 +277,7 @@ fn expm1_64(x_: f64) f64 {
277277 return y - 1.0;
278278 }
279279
280 const uf = @bitCast(f64, @intCast(u64, 0x3FF -% k) << 52);
280 const uf = @as(f64, @bitCast(@as(u64, @intCast(0x3FF -% k)) << 52));
281281 if (k < 20) {
282282 return (x - e + (1 - uf)) * twopk;
283283 } else {
lib/std/math/expo2.zig+2-2
......@@ -21,7 +21,7 @@ fn expo2f(x: f32) f32 {
2121 const kln2 = 0x1.45C778p+7;
2222
2323 const u = (0x7F + k / 2) << 23;
24 const scale = @bitCast(f32, u);
24 const scale = @as(f32, @bitCast(u));
2525 return @exp(x - kln2) * scale * scale;
2626}
2727
......@@ -30,6 +30,6 @@ fn expo2d(x: f64) f64 {
3030 const kln2 = 0x1.62066151ADD8BP+10;
3131
3232 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));
3434 return @exp(x - kln2) * scale * scale;
3535}
lib/std/math/float.zig+1-1
......@@ -11,7 +11,7 @@ inline fn mantissaOne(comptime T: type) comptime_int {
1111inline fn reconstructFloat(comptime T: type, comptime exponent: comptime_int, comptime mantissa: comptime_int) T {
1212 const TBits = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = @bitSizeOf(T) } });
1313 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)));
1515}
1616
1717/// 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)) {
3838fn frexp32(x: f32) Frexp(f32) {
3939 var result: Frexp(f32) = undefined;
4040
41 var y = @bitCast(u32, x);
42 const e = @intCast(i32, y >> 23) & 0xFF;
41 var y = @as(u32, @bitCast(x));
42 const e = @as(i32, @intCast(y >> 23)) & 0xFF;
4343
4444 if (e == 0) {
4545 if (x != 0) {
......@@ -68,15 +68,15 @@ fn frexp32(x: f32) Frexp(f32) {
6868 result.exponent = e - 0x7E;
6969 y &= 0x807FFFFF;
7070 y |= 0x3F000000;
71 result.significand = @bitCast(f32, y);
71 result.significand = @as(f32, @bitCast(y));
7272 return result;
7373}
7474
7575fn frexp64(x: f64) Frexp(f64) {
7676 var result: Frexp(f64) = undefined;
7777
78 var y = @bitCast(u64, x);
79 const e = @intCast(i32, y >> 52) & 0x7FF;
78 var y = @as(u64, @bitCast(x));
79 const e = @as(i32, @intCast(y >> 52)) & 0x7FF;
8080
8181 if (e == 0) {
8282 if (x != 0) {
......@@ -105,15 +105,15 @@ fn frexp64(x: f64) Frexp(f64) {
105105 result.exponent = e - 0x3FE;
106106 y &= 0x800FFFFFFFFFFFFF;
107107 y |= 0x3FE0000000000000;
108 result.significand = @bitCast(f64, y);
108 result.significand = @as(f64, @bitCast(y));
109109 return result;
110110}
111111
112112fn frexp128(x: f128) Frexp(f128) {
113113 var result: Frexp(f128) = undefined;
114114
115 var y = @bitCast(u128, x);
116 const e = @intCast(i32, y >> 112) & 0x7FFF;
115 var y = @as(u128, @bitCast(x));
116 const e = @as(i32, @intCast(y >> 112)) & 0x7FFF;
117117
118118 if (e == 0) {
119119 if (x != 0) {
......@@ -142,7 +142,7 @@ fn frexp128(x: f128) Frexp(f128) {
142142 result.exponent = e - 0x3FFE;
143143 y &= 0x8000FFFFFFFFFFFFFFFFFFFFFFFFFFFF;
144144 y |= 0x3FFE0000000000000000000000000000;
145 result.significand = @bitCast(f128, y);
145 result.significand = @as(f128, @bitCast(y));
146146 return result;
147147}
148148
lib/std/math/hypot.zig+9-9
......@@ -25,8 +25,8 @@ pub fn hypot(comptime T: type, x: T, y: T) T {
2525}
2626
2727fn hypot32(x: f32, y: f32) f32 {
28 var ux = @bitCast(u32, x);
29 var uy = @bitCast(u32, y);
28 var ux = @as(u32, @bitCast(x));
29 var uy = @as(u32, @bitCast(y));
3030
3131 ux &= maxInt(u32) >> 1;
3232 uy &= maxInt(u32) >> 1;
......@@ -36,8 +36,8 @@ fn hypot32(x: f32, y: f32) f32 {
3636 uy = tmp;
3737 }
3838
39 var xx = @bitCast(f32, ux);
40 var yy = @bitCast(f32, uy);
39 var xx = @as(f32, @bitCast(ux));
40 var yy = @as(f32, @bitCast(uy));
4141 if (uy == 0xFF << 23) {
4242 return yy;
4343 }
......@@ -56,7 +56,7 @@ fn hypot32(x: f32, y: f32) f32 {
5656 yy *= 0x1.0p-90;
5757 }
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)));
6060}
6161
6262fn sq(hi: *f64, lo: *f64, x: f64) void {
......@@ -69,8 +69,8 @@ fn sq(hi: *f64, lo: *f64, x: f64) void {
6969}
7070
7171fn hypot64(x: f64, y: f64) f64 {
72 var ux = @bitCast(u64, x);
73 var uy = @bitCast(u64, y);
72 var ux = @as(u64, @bitCast(x));
73 var uy = @as(u64, @bitCast(y));
7474
7575 ux &= maxInt(u64) >> 1;
7676 uy &= maxInt(u64) >> 1;
......@@ -82,8 +82,8 @@ fn hypot64(x: f64, y: f64) f64 {
8282
8383 const ex = ux >> 52;
8484 const ey = uy >> 52;
85 var xx = @bitCast(f64, ux);
86 var yy = @bitCast(f64, uy);
85 var xx = @as(f64, @bitCast(ux));
86 var yy = @as(f64, @bitCast(uy));
8787
8888 // hypot(inf, nan) == inf
8989 if (ey == 0x7FF) {
lib/std/math/ilogb.zig+4-4
......@@ -38,8 +38,8 @@ fn ilogbX(comptime T: type, x: T) i32 {
3838
3939 const absMask = signBit - 1;
4040
41 var u = @bitCast(Z, x) & absMask;
42 var e = @intCast(i32, u >> significandBits);
41 var u = @as(Z, @bitCast(x)) & absMask;
42 var e = @as(i32, @intCast(u >> significandBits));
4343
4444 if (e == 0) {
4545 if (u == 0) {
......@@ -49,12 +49,12 @@ fn ilogbX(comptime T: type, x: T) i32 {
4949
5050 // offset sign bit, exponent bits, and integer bit (if present) + bias
5151 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)));
5353 }
5454
5555 if (e == maxExponent) {
5656 math.raiseInvalid();
57 if (u > @bitCast(Z, math.inf(T))) {
57 if (u > @as(Z, @bitCast(math.inf(T)))) {
5858 return fp_ilogbnan; // u is a NaN
5959 } else return maxInt(i32);
6060 }
lib/std/math/isfinite.zig+1-1
......@@ -7,7 +7,7 @@ pub fn isFinite(x: anytype) bool {
77 const T = @TypeOf(x);
88 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
99 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)));
1111}
1212
1313test "math.isFinite" {
lib/std/math/isinf.zig+1-1
......@@ -7,7 +7,7 @@ pub inline fn isInf(x: anytype) bool {
77 const T = @TypeOf(x);
88 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
99 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)));
1111}
1212
1313/// 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 {
1515 // The sign bit is removed because all ones would overflow into it.
1616 // For f80, even though it has an explicit integer part stored,
1717 // the exponent effectively takes priority if mismatching.
18 const value = @bitCast(TBits, x) +% increment_exp;
18 const value = @as(TBits, @bitCast(x)) +% increment_exp;
1919 return value & remove_sign >= (increment_exp << 1);
2020}
2121
......@@ -35,7 +35,7 @@ test "math.isNormal" {
3535 try expect(!isNormal(@as(T, math.floatTrueMin(T))));
3636
3737 // 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
4040 // non-finite numbers
4141 try expect(!isNormal(-math.inf(T)));
......@@ -43,6 +43,6 @@ test "math.isNormal" {
4343 try expect(!isNormal(math.nan(T)));
4444
4545 // 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)))));
4747 }
4848}
lib/std/math/ldexp.zig+15-15
......@@ -16,53 +16,53 @@ pub fn ldexp(x: anytype, n: i32) @TypeOf(x) {
1616 const max_biased_exponent = 2 * math.floatExponentMax(T);
1717 const mantissa_mask = @as(TBits, (1 << mantissa_bits) - 1);
1818
19 const repr = @bitCast(TBits, x);
19 const repr = @as(TBits, @bitCast(x));
2020 const sign_bit = repr & (1 << (exponent_bits + mantissa_bits));
2121
2222 if (math.isNan(x) or !math.isFinite(x))
2323 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)));
2626 if (exponent == 0)
2727 exponent += (@as(i32, exponent_bits) + @intFromBool(T == f80)) - @clz(repr << 1);
2828
2929 if (n >= 0) {
3030 if (n > max_biased_exponent - exponent) {
3131 // 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));
3333 } else if (exponent + n <= 0) {
3434 // 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));
3636 } else if (exponent <= 0) {
3737 // Result is normal, but needs shifting
38 var result = @intCast(TBits, n + exponent) << mantissa_bits;
39 result |= (repr << @intCast(Log2Int(TBits), 1 - exponent)) & mantissa_mask;
40 return @bitCast(T, result | sign_bit);
38 var result = @as(TBits, @intCast(n + exponent)) << mantissa_bits;
39 result |= (repr << @as(Log2Int(TBits), @intCast(1 - exponent))) & mantissa_mask;
40 return @as(T, @bitCast(result | sign_bit));
4141 }
4242
4343 // 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)));
4545 } else {
4646 if (n <= -exponent) {
4747 if (n < -(mantissa_bits + exponent))
48 return @bitCast(T, sign_bit); // Severe underflow. Return +/- 0
48 return @as(T, @bitCast(sign_bit)); // Severe underflow. Return +/- 0
4949
5050 // 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)));
5252 const exact_tie: bool = @ctz(repr) == shift - 1;
5353 var result = repr & mantissa_mask;
5454
5555 if (T != f80) // Include integer bit
5656 result |= @as(TBits, @intFromBool(exponent > 0)) << fractional_bits;
57 result = @intCast(TBits, (result >> (shift - 1)));
57 result = @as(TBits, @intCast((result >> (shift - 1))));
5858
5959 // Round result, including round-to-even for exact ties
6060 result = ((result + 1) >> 1) & ~@as(TBits, @intFromBool(exact_tie));
61 return @bitCast(T, result | sign_bit);
61 return @as(T, @bitCast(result | sign_bit));
6262 }
6363
6464 // 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)));
6666 }
6767}
6868
......@@ -105,8 +105,8 @@ test "math.ldexp" {
105105 // Multiplications might flush the denormals to zero, esp. at
106106 // runtime, so we manually construct the constants here instead.
107107 const Z = std.meta.Int(.unsigned, @bitSizeOf(T));
108 const EightTimesTrueMin = @bitCast(T, @as(Z, 8));
109 const TwoTimesTrueMin = @bitCast(T, @as(Z, 2));
108 const EightTimesTrueMin = @as(T, @bitCast(@as(Z, 8)));
109 const TwoTimesTrueMin = @as(T, @bitCast(@as(Z, 2)));
110110
111111 // subnormals -> subnormals
112112 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 {
3030 // TODO implement integer log without using float math
3131 .Int => |IntType| switch (IntType.signedness) {
3232 .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)))),
3434 },
3535
3636 .Float => {
3737 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))),
3939 f64 => return @log(x) / @log(float_base),
4040 else => @compileError("log not implemented for " ++ @typeName(T)),
4141 }
lib/std/math/log10.zig+7-7
......@@ -49,9 +49,9 @@ pub fn log10_int(x: anytype) Log2Int(@TypeOf(x)) {
4949 const bit_size = @typeInfo(T).Int.bits;
5050
5151 if (bit_size <= 8) {
52 return @intCast(OutT, log10_int_u8(x));
52 return @as(OutT, @intCast(log10_int_u8(x)));
5353 } else if (bit_size <= 16) {
54 return @intCast(OutT, less_than_5(x));
54 return @as(OutT, @intCast(less_than_5(x)));
5555 }
5656
5757 var val = x;
......@@ -71,7 +71,7 @@ pub fn log10_int(x: anytype) Log2Int(@TypeOf(x)) {
7171 log += 5;
7272 }
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)))));
7575}
7676
7777fn pow10(comptime y: comptime_int) comptime_int {
......@@ -134,7 +134,7 @@ inline fn less_than_5(x: u32) u32 {
134134}
135135
136136fn oldlog10(x: anytype) u8 {
137 return @intFromFloat(u8, @log10(@floatFromInt(f64, x)));
137 return @as(u8, @intFromFloat(@log10(@as(f64, @floatFromInt(x)))));
138138}
139139
140140test "oldlog10 doesn't work" {
......@@ -158,7 +158,7 @@ test "log10_int vs old implementation" {
158158 inline for (int_types) |T| {
159159 const last = @min(maxInt(T), 100_000);
160160 for (1..last) |i| {
161 const x = @intCast(T, i);
161 const x = @as(T, @intCast(i));
162162 try testing.expectEqual(oldlog10(x), log10_int(x));
163163 }
164164
......@@ -185,10 +185,10 @@ test "log10_int close to powers of 10" {
185185 try testing.expectEqual(expected_max_ilog, log10_int(max_val));
186186
187187 for (0..(expected_max_ilog + 1)) |idx| {
188 const i = @intCast(T, idx);
188 const i = @as(T, @intCast(idx));
189189 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
193193 if (p >= 10) {
194194 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 {
3333 const Lg3: f32 = 0x91e9ee.0p-25;
3434 const Lg4: f32 = 0xf89e26.0p-26;
3535
36 const u = @bitCast(u32, x);
36 const u = @as(u32, @bitCast(x));
3737 var ix = u;
3838 var k: i32 = 1;
3939 var f: f32 = undefined;
......@@ -72,9 +72,9 @@ fn log1p_32(x: f32) f32 {
7272
7373 if (k != 0) {
7474 const uf = 1 + x;
75 var iu = @bitCast(u32, uf);
75 var iu = @as(u32, @bitCast(uf));
7676 iu += 0x3F800000 - 0x3F3504F3;
77 k = @intCast(i32, iu >> 23) - 0x7F;
77 k = @as(i32, @intCast(iu >> 23)) - 0x7F;
7878
7979 // correction to avoid underflow in c / u
8080 if (k < 25) {
......@@ -86,7 +86,7 @@ fn log1p_32(x: f32) f32 {
8686
8787 // u into [sqrt(2)/2, sqrt(2)]
8888 iu = (iu & 0x007FFFFF) + 0x3F3504F3;
89 f = @bitCast(f32, iu) - 1;
89 f = @as(f32, @bitCast(iu)) - 1;
9090 }
9191
9292 const s = f / (2.0 + f);
......@@ -96,7 +96,7 @@ fn log1p_32(x: f32) f32 {
9696 const t2 = z * (Lg1 + w * Lg3);
9797 const R = t2 + t1;
9898 const hfsq = 0.5 * f * f;
99 const dk = @floatFromInt(f32, k);
99 const dk = @as(f32, @floatFromInt(k));
100100
101101 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
102102}
......@@ -112,8 +112,8 @@ fn log1p_64(x: f64) f64 {
112112 const Lg6: f64 = 1.531383769920937332e-01;
113113 const Lg7: f64 = 1.479819860511658591e-01;
114114
115 var ix = @bitCast(u64, x);
116 var hx = @intCast(u32, ix >> 32);
115 var ix = @as(u64, @bitCast(x));
116 var hx = @as(u32, @intCast(ix >> 32));
117117 var k: i32 = 1;
118118 var c: f64 = undefined;
119119 var f: f64 = undefined;
......@@ -150,10 +150,10 @@ fn log1p_64(x: f64) f64 {
150150
151151 if (k != 0) {
152152 const uf = 1 + x;
153 const hu = @bitCast(u64, uf);
154 var iu = @intCast(u32, hu >> 32);
153 const hu = @as(u64, @bitCast(uf));
154 var iu = @as(u32, @intCast(hu >> 32));
155155 iu += 0x3FF00000 - 0x3FE6A09E;
156 k = @intCast(i32, iu >> 20) - 0x3FF;
156 k = @as(i32, @intCast(iu >> 20)) - 0x3FF;
157157
158158 // correction to avoid underflow in c / u
159159 if (k < 54) {
......@@ -166,7 +166,7 @@ fn log1p_64(x: f64) f64 {
166166 // u into [sqrt(2)/2, sqrt(2)]
167167 iu = (iu & 0x000FFFFF) + 0x3FE6A09E;
168168 const iq = (@as(u64, iu) << 32) | (hu & 0xFFFFFFFF);
169 f = @bitCast(f64, iq) - 1;
169 f = @as(f64, @bitCast(iq)) - 1;
170170 }
171171
172172 const hfsq = 0.5 * f * f;
......@@ -176,7 +176,7 @@ fn log1p_64(x: f64) f64 {
176176 const t1 = w * (Lg2 + w * (Lg4 + w * Lg6));
177177 const t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));
178178 const R = t2 + t1;
179 const dk = @floatFromInt(f64, k);
179 const dk = @as(f64, @floatFromInt(k));
180180
181181 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
182182}
lib/std/math/modf.zig+14-14
......@@ -37,8 +37,8 @@ pub fn modf(x: anytype) modf_result(@TypeOf(x)) {
3737fn modf32(x: f32) modf32_result {
3838 var result: modf32_result = undefined;
3939
40 const u = @bitCast(u32, x);
41 const e = @intCast(i32, (u >> 23) & 0xFF) - 0x7F;
40 const u = @as(u32, @bitCast(x));
41 const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;
4242 const us = u & 0x80000000;
4343
4444 // TODO: Shouldn't need this.
......@@ -54,26 +54,26 @@ fn modf32(x: f32) modf32_result {
5454 if (e == 0x80 and u << 9 != 0) { // nan
5555 result.fpart = x;
5656 } else {
57 result.fpart = @bitCast(f32, us);
57 result.fpart = @as(f32, @bitCast(us));
5858 }
5959 return result;
6060 }
6161
6262 // no integral part
6363 if (e < 0) {
64 result.ipart = @bitCast(f32, us);
64 result.ipart = @as(f32, @bitCast(us));
6565 result.fpart = x;
6666 return result;
6767 }
6868
69 const mask = @as(u32, 0x007FFFFF) >> @intCast(u5, e);
69 const mask = @as(u32, 0x007FFFFF) >> @as(u5, @intCast(e));
7070 if (u & mask == 0) {
7171 result.ipart = x;
72 result.fpart = @bitCast(f32, us);
72 result.fpart = @as(f32, @bitCast(us));
7373 return result;
7474 }
7575
76 const uf = @bitCast(f32, u & ~mask);
76 const uf = @as(f32, @bitCast(u & ~mask));
7777 result.ipart = uf;
7878 result.fpart = x - uf;
7979 return result;
......@@ -82,8 +82,8 @@ fn modf32(x: f32) modf32_result {
8282fn modf64(x: f64) modf64_result {
8383 var result: modf64_result = undefined;
8484
85 const u = @bitCast(u64, x);
86 const e = @intCast(i32, (u >> 52) & 0x7FF) - 0x3FF;
85 const u = @as(u64, @bitCast(x));
86 const e = @as(i32, @intCast((u >> 52) & 0x7FF)) - 0x3FF;
8787 const us = u & (1 << 63);
8888
8989 if (math.isInf(x)) {
......@@ -98,26 +98,26 @@ fn modf64(x: f64) modf64_result {
9898 if (e == 0x400 and u << 12 != 0) { // nan
9999 result.fpart = x;
100100 } else {
101 result.fpart = @bitCast(f64, us);
101 result.fpart = @as(f64, @bitCast(us));
102102 }
103103 return result;
104104 }
105105
106106 // no integral part
107107 if (e < 0) {
108 result.ipart = @bitCast(f64, us);
108 result.ipart = @as(f64, @bitCast(us));
109109 result.fpart = x;
110110 return result;
111111 }
112112
113 const mask = @as(u64, maxInt(u64) >> 12) >> @intCast(u6, e);
113 const mask = @as(u64, maxInt(u64) >> 12) >> @as(u6, @intCast(e));
114114 if (u & mask == 0) {
115115 result.ipart = x;
116 result.fpart = @bitCast(f64, us);
116 result.fpart = @as(f64, @bitCast(us));
117117 return result;
118118 }
119119
120 const uf = @bitCast(f64, u & ~mask);
120 const uf = @as(f64, @bitCast(u & ~mask));
121121 result.ipart = uf;
122122 result.fpart = x - uf;
123123 return result;
lib/std/math/pow.zig+2-2
......@@ -144,7 +144,7 @@ pub fn pow(comptime T: type, x: T, y: T) T {
144144 var xe = r2.exponent;
145145 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));
148148 while (i != 0) : (i >>= 1) {
149149 const overflow_shift = math.floatExponentBits(T) + 1;
150150 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 {
179179
180180fn isOddInteger(x: f64) bool {
181181 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;
183183}
184184
185185test "math.pow" {
lib/std/math/signbit.zig+1-1
......@@ -6,7 +6,7 @@ const expect = std.testing.expect;
66pub fn signbit(x: anytype) bool {
77 const T = @TypeOf(x);
88 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;
1010}
1111
1212test "math.signbit" {
lib/std/math/sinh.zig+5-5
......@@ -29,9 +29,9 @@ pub fn sinh(x: anytype) @TypeOf(x) {
2929// = (exp(x) - 1 + (exp(x) - 1) / exp(x)) / 2
3030// = x + x^3 / 6 + o(x^5)
3131fn sinh32(x: f32) f32 {
32 const u = @bitCast(u32, x);
32 const u = @as(u32, @bitCast(x));
3333 const ux = u & 0x7FFFFFFF;
34 const ax = @bitCast(f32, ux);
34 const ax = @as(f32, @bitCast(ux));
3535
3636 if (x == 0.0 or math.isNan(x)) {
3737 return x;
......@@ -60,9 +60,9 @@ fn sinh32(x: f32) f32 {
6060}
6161
6262fn sinh64(x: f64) f64 {
63 const u = @bitCast(u64, x);
64 const w = @intCast(u32, u >> 32) & (maxInt(u32) >> 1);
65 const ax = @bitCast(f64, u & (maxInt(u64) >> 1));
63 const u = @as(u64, @bitCast(x));
64 const w = @as(u32, @intCast(u >> 32)) & (maxInt(u32) >> 1);
65 const ax = @as(f64, @bitCast(u & (maxInt(u64) >> 1)));
6666
6767 if (x == 0.0 or math.isNan(x)) {
6868 return x;
lib/std/math/sqrt.zig+1-1
......@@ -57,7 +57,7 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {
5757 one >>= 2;
5858 }
5959
60 return @intCast(Sqrt(T), res);
60 return @as(Sqrt(T), @intCast(res));
6161 }
6262}
6363
lib/std/math/tanh.zig+6-6
......@@ -29,9 +29,9 @@ pub fn tanh(x: anytype) @TypeOf(x) {
2929// = (exp(2x) - 1) / (exp(2x) - 1 + 2)
3030// = (1 - exp(-2x)) / (exp(-2x) - 1 + 2)
3131fn tanh32(x: f32) f32 {
32 const u = @bitCast(u32, x);
32 const u = @as(u32, @bitCast(x));
3333 const ux = u & 0x7FFFFFFF;
34 const ax = @bitCast(f32, ux);
34 const ax = @as(f32, @bitCast(ux));
3535 const sign = (u >> 31) != 0;
3636
3737 var t: f32 = undefined;
......@@ -66,10 +66,10 @@ fn tanh32(x: f32) f32 {
6666}
6767
6868fn tanh64(x: f64) f64 {
69 const u = @bitCast(u64, x);
69 const u = @as(u64, @bitCast(x));
7070 const ux = u & 0x7FFFFFFFFFFFFFFF;
71 const w = @intCast(u32, ux >> 32);
72 const ax = @bitCast(f64, ux);
71 const w = @as(u32, @intCast(ux >> 32));
72 const ax = @as(f64, @bitCast(ux));
7373 const sign = (u >> 63) != 0;
7474
7575 var t: f64 = undefined;
......@@ -96,7 +96,7 @@ fn tanh64(x: f64) f64 {
9696 }
9797 // |x| is subnormal
9898 else {
99 math.doNotOptimizeAway(@floatCast(f32, ax));
99 math.doNotOptimizeAway(@as(f32, @floatCast(ax)));
100100 t = ax;
101101 }
102102
lib/std/mem.zig+110-113
......@@ -69,7 +69,7 @@ pub fn ValidationAllocator(comptime T: type) type {
6969 ret_addr: usize,
7070 ) ?[*]u8 {
7171 assert(n > 0);
72 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
72 const self: *Self = @ptrCast(@alignCast(ctx));
7373 const underlying = self.getUnderlyingAllocatorPtr();
7474 const result = underlying.rawAlloc(n, log2_ptr_align, ret_addr) orelse
7575 return null;
......@@ -84,7 +84,7 @@ pub fn ValidationAllocator(comptime T: type) type {
8484 new_len: usize,
8585 ret_addr: usize,
8686 ) bool {
87 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
87 const self: *Self = @ptrCast(@alignCast(ctx));
8888 assert(buf.len > 0);
8989 const underlying = self.getUnderlyingAllocatorPtr();
9090 return underlying.rawResize(buf, log2_buf_align, new_len, ret_addr);
......@@ -96,7 +96,7 @@ pub fn ValidationAllocator(comptime T: type) type {
9696 log2_buf_align: u8,
9797 ret_addr: usize,
9898 ) void {
99 const self = @ptrCast(*Self, @alignCast(@alignOf(Self), ctx));
99 const self: *Self = @ptrCast(@alignCast(ctx));
100100 assert(buf.len > 0);
101101 const underlying = self.getUnderlyingAllocatorPtr();
102102 underlying.rawFree(buf, log2_buf_align, ret_addr);
......@@ -169,7 +169,7 @@ test "Allocator.resize" {
169169 var values = try testing.allocator.alloc(T, 100);
170170 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));
173173 if (!testing.allocator.resize(values, values.len + 10)) return error.OutOfMemory;
174174 values = values.ptr[0 .. values.len + 10];
175175 try testing.expect(values.len == 110);
......@@ -185,7 +185,7 @@ test "Allocator.resize" {
185185 var values = try testing.allocator.alloc(T, 100);
186186 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));
189189 if (!testing.allocator.resize(values, values.len + 10)) return error.OutOfMemory;
190190 values = values.ptr[0 .. values.len + 10];
191191 try testing.expect(values.len == 110);
......@@ -233,7 +233,7 @@ pub fn zeroes(comptime T: type) T {
233233 return @as(T, 0);
234234 },
235235 .Enum, .EnumLiteral => {
236 return @enumFromInt(T, 0);
236 return @as(T, @enumFromInt(0));
237237 },
238238 .Void => {
239239 return {};
......@@ -264,7 +264,7 @@ pub fn zeroes(comptime T: type) T {
264264 switch (ptr_info.size) {
265265 .Slice => {
266266 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) {
268268 return ""; // A special case for the most common use-case: null-terminated strings.
269269 }
270270 @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 {
282282 },
283283 .Array => |info| {
284284 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)).*;
286286 return [_:sentinel]info.child{zeroes(info.child)} ** info.len;
287287 }
288288 return [_]info.child{zeroes(info.child)} ** info.len;
......@@ -456,7 +456,7 @@ pub fn zeroInit(comptime T: type, init: anytype) T {
456456 },
457457 }
458458 } 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)).*;
460460 @field(value, field.name) = default_value;
461461 } else {
462462 switch (@typeInfo(field.type)) {
......@@ -709,7 +709,7 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {
709709 const l = len(ptr);
710710 const ptr_info = @typeInfo(Result).Pointer;
711711 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)).*;
713713 return ptr[0..l :s];
714714 } else {
715715 return ptr[0..l];
......@@ -740,7 +740,7 @@ fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {
740740 // to find the value searched for, which is only the case if it matches
741741 // the sentinel of the type passed.
742742 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)).*;
744744 if (end == sentinel) {
745745 new_ptr_info.sentinel = &end;
746746 } else {
......@@ -755,7 +755,7 @@ fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {
755755 // to find the value searched for, which is only the case if it matches
756756 // the sentinel of the type passed.
757757 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)).*;
759759 if (end == sentinel) {
760760 new_ptr_info.sentinel = &end;
761761 } else {
......@@ -793,7 +793,7 @@ pub fn sliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) SliceTo(@Typ
793793 const length = lenSliceTo(ptr, end);
794794 const ptr_info = @typeInfo(Result).Pointer;
795795 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)).*;
797797 return ptr[0..length :s];
798798 } else {
799799 return ptr[0..length];
......@@ -810,11 +810,11 @@ test "sliceTo" {
810810 try testing.expectEqualSlices(u16, array[0..2], sliceTo(&array, 3));
811811 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));
814814 try testing.expectEqualSlices(u16, array[0..2], sliceTo(sentinel_ptr, 3));
815815 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));
818818 try testing.expectEqualSlices(u16, array[0..2], sliceTo(optional_sentinel_ptr, 3).?);
819819 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 {
846846 .One => switch (@typeInfo(ptr_info.child)) {
847847 .Array => |array_info| {
848848 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)).*;
850850 if (sentinel == end) {
851851 return indexOfSentinel(array_info.child, end, ptr);
852852 }
......@@ -856,7 +856,7 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {
856856 else => {},
857857 },
858858 .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)).*;
860860 // We may be looking for something other than the sentinel,
861861 // but iterating past the sentinel would be a bug so we need
862862 // to check for both.
......@@ -870,7 +870,7 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {
870870 },
871871 .Slice => {
872872 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)).*;
874874 if (sentinel == end) {
875875 return indexOfSentinel(ptr_info.child, sentinel, ptr);
876876 }
......@@ -893,7 +893,7 @@ test "lenSliceTo" {
893893 try testing.expectEqual(@as(usize, 2), lenSliceTo(&array, 3));
894894 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));
897897 try testing.expectEqual(@as(usize, 2), lenSliceTo(sentinel_ptr, 3));
898898 try testing.expectEqual(@as(usize, 4), lenSliceTo(sentinel_ptr, 99));
899899
......@@ -925,7 +925,7 @@ pub fn len(value: anytype) usize {
925925 .Many => {
926926 const sentinel_ptr = info.sentinel orelse
927927 @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)).*;
929929 return indexOfSentinel(info.child, sentinel, value);
930930 },
931931 .C => {
......@@ -1331,7 +1331,7 @@ pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: Endian)
13311331 .Little => {
13321332 const ShiftType = math.Log2Int(ReturnType);
13331333 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)));
13351335 }
13361336 },
13371337 }
......@@ -1359,8 +1359,8 @@ pub fn readVarPackedInt(
13591359 const Log2N = std.math.Log2Int(T);
13601360
13611361 const read_size = (bit_count + (bit_offset % 8) + 7) / 8;
1362 const bit_shift = @intCast(u3, bit_offset % 8);
1363 const pad = @intCast(Log2N, @bitSizeOf(T) - bit_count);
1362 const bit_shift = @as(u3, @intCast(bit_offset % 8));
1363 const pad = @as(Log2N, @intCast(@bitSizeOf(T) - bit_count));
13641364
13651365 const lowest_byte = switch (endian) {
13661366 .Big => bytes.len - (bit_offset / 8) - read_size,
......@@ -1372,17 +1372,17 @@ pub fn readVarPackedInt(
13721372 // These are the same shifts/masks we perform below, but adds `@truncate`/`@intCast`
13731373 // where needed since int is smaller than a byte.
13741374 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));
13761376 } else b: {
13771377 const i: u1 = @intFromBool(endian == .Big);
1378 const head = @truncate(uN, read_bytes[i] >> bit_shift);
1379 const tail_shift = @intCast(Log2N, @as(u4, 8) - bit_shift);
1380 const tail = @truncate(uN, read_bytes[1 - i]);
1378 const head = @as(uN, @truncate(read_bytes[i] >> bit_shift));
1379 const tail_shift = @as(Log2N, @intCast(@as(u4, 8) - bit_shift));
1380 const tail = @as(uN, @truncate(read_bytes[1 - i]));
13811381 break :b (tail << tail_shift) | head;
13821382 };
13831383 switch (signedness) {
1384 .signed => return @intCast(T, (@bitCast(iN, value) << pad) >> pad),
1385 .unsigned => return @intCast(T, (@bitCast(uN, value) << pad) >> pad),
1384 .signed => return @as(T, @intCast((@as(iN, @bitCast(value)) << pad) >> pad)),
1385 .unsigned => return @as(T, @intCast((@as(uN, @bitCast(value)) << pad) >> pad)),
13861386 }
13871387 }
13881388
......@@ -1398,13 +1398,13 @@ pub fn readVarPackedInt(
13981398 .Little => {
13991399 int = read_bytes[0] >> bit_shift;
14001400 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))));
14021402 }
14031403 },
14041404 }
14051405 switch (signedness) {
1406 .signed => return @intCast(T, (@bitCast(iN, int) << pad) >> pad),
1407 .unsigned => return @intCast(T, (@bitCast(uN, int) << pad) >> pad),
1406 .signed => return @as(T, @intCast((@as(iN, @bitCast(int)) << pad) >> pad)),
1407 .unsigned => return @as(T, @intCast((@as(uN, @bitCast(int)) << pad) >> pad)),
14081408 }
14091409}
14101410
......@@ -1414,7 +1414,7 @@ pub fn readVarPackedInt(
14141414/// Assumes the endianness of memory is native. This means the function can
14151415/// simply pointer cast memory.
14161416pub 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)).*;
14181418}
14191419
14201420/// 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
14801480 const Log2N = std.math.Log2Int(T);
14811481
14821482 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
14851485 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));
14871487 const LoadInt = std.meta.Int(.unsigned, load_size * 8);
14881488
14891489 if (bit_count == 0)
......@@ -1492,13 +1492,13 @@ fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T
14921492 // Read by loading a LoadInt, and then follow it up with a 1-byte read
14931493 // of the tail if bit_offset pushed us over a byte boundary.
14941494 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));
14961496 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));
14981498 const tail_byte = read_bytes[load_size];
1499 const tail_truncated = if (bit_count < 8) @truncate(uN, tail_byte) else @as(uN, tail_byte);
1500 return @bitCast(T, val | (tail_truncated << (@truncate(Log2N, bit_count) -% tail_bits)));
1501 } else return @bitCast(T, val);
1499 const tail_truncated = if (bit_count < 8) @as(uN, @truncate(tail_byte)) else @as(uN, tail_byte);
1500 return @as(T, @bitCast(val | (tail_truncated << (@as(Log2N, @truncate(bit_count)) -% tail_bits))));
1501 } else return @as(T, @bitCast(val));
15021502}
15031503
15041504fn 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 {
15061506 const Log2N = std.math.Log2Int(T);
15071507
15081508 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));
15101510 const byte_count = (@as(usize, bit_shift) + bit_count + 7) / 8;
15111511
15121512 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));
15141514 const LoadInt = std.meta.Int(.unsigned, load_size * 8);
15151515
15161516 if (bit_count == 0)
......@@ -1520,12 +1520,12 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T {
15201520 // of the tail if bit_offset pushed us over a byte boundary.
15211521 const end = bytes.len - (bit_offset / 8);
15221522 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));
15241524 if (bit_shift > load_tail_bits) {
1525 const tail_bits = @intCast(Log2N, bit_shift - load_tail_bits);
1526 const tail_byte = if (bit_count < 8) @truncate(uN, read_bytes[0]) else @as(uN, read_bytes[0]);
1527 return @bitCast(T, val | (tail_byte << (@truncate(Log2N, bit_count) -% tail_bits)));
1528 } else return @bitCast(T, val);
1525 const tail_bits = @as(Log2N, @intCast(bit_shift - load_tail_bits));
1526 const tail_byte = if (bit_count < 8) @as(uN, @truncate(read_bytes[0])) else @as(uN, read_bytes[0]);
1527 return @as(T, @bitCast(val | (tail_byte << (@as(Log2N, @truncate(bit_count)) -% tail_bits))));
1528 } else return @as(T, @bitCast(val));
15291529}
15301530
15311531pub const readPackedIntNative = switch (native_endian) {
......@@ -1605,7 +1605,7 @@ test "readIntBig and readIntLittle" {
16051605/// This function stores in native endian, which means it is implemented as a simple
16061606/// memory store.
16071607pub 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;
16091609}
16101610
16111611/// 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:
16421642 const Log2N = std.math.Log2Int(T);
16431643
16441644 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
16471647 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));
16491649 const StoreInt = std.meta.Int(.unsigned, store_size * 8);
16501650
16511651 if (bit_count == 0)
......@@ -1656,11 +1656,11 @@ fn writePackedIntLittle(comptime T: type, bytes: []u8, bit_offset: usize, value:
16561656 const write_bytes = bytes[bit_offset / 8 ..];
16571657 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));
16601660 if (bit_shift > store_tail_bits) {
1661 const tail_len = @intCast(Log2N, bit_shift - store_tail_bits);
1662 write_bytes[store_size] &= ~((@as(u8, 1) << @intCast(u3, tail_len)) - 1);
1663 write_bytes[store_size] |= @intCast(u8, (@bitCast(uN, value) >> (@truncate(Log2N, bit_count) -% tail_len)));
1661 const tail_len = @as(Log2N, @intCast(bit_shift - store_tail_bits));
1662 write_bytes[store_size] &= ~((@as(u8, 1) << @as(u3, @intCast(tail_len))) - 1);
1663 write_bytes[store_size] |= @as(u8, @intCast((@as(uN, @bitCast(value)) >> (@as(Log2N, @truncate(bit_count)) -% tail_len))));
16641664 } else if (bit_shift < store_tail_bits) {
16651665 const tail_len = store_tail_bits - bit_shift;
16661666 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)
16751675 const Log2N = std.math.Log2Int(T);
16761676
16771677 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));
16791679 const byte_count = (bit_shift + bit_count + 7) / 8;
16801680
16811681 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));
16831683 const StoreInt = std.meta.Int(.unsigned, store_size * 8);
16841684
16851685 if (bit_count == 0)
......@@ -1691,11 +1691,11 @@ fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T)
16911691 const write_bytes = bytes[(end - byte_count)..end];
16921692 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));
16951695 if (bit_shift > store_tail_bits) {
1696 const tail_len = @intCast(Log2N, bit_shift - store_tail_bits);
1697 write_bytes[0] &= ~((@as(u8, 1) << @intCast(u3, tail_len)) - 1);
1698 write_bytes[0] |= @intCast(u8, (@bitCast(uN, value) >> (@truncate(Log2N, bit_count) -% tail_len)));
1696 const tail_len = @as(Log2N, @intCast(bit_shift - store_tail_bits));
1697 write_bytes[0] &= ~((@as(u8, 1) << @as(u3, @intCast(tail_len))) - 1);
1698 write_bytes[0] |= @as(u8, @intCast((@as(uN, @bitCast(value)) >> (@as(Log2N, @truncate(bit_count)) -% tail_len))));
16991699 } else if (bit_shift < store_tail_bits) {
17001700 const tail_len = store_tail_bits - bit_shift;
17011701 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 {
17441744 return @memset(buffer, 0);
17451745 } else if (@typeInfo(T).Int.bits == 8) {
17461746 @memset(buffer, 0);
1747 buffer[0] = @bitCast(u8, value);
1747 buffer[0] = @as(u8, @bitCast(value));
17481748 return;
17491749 }
17501750 // TODO I want to call writeIntLittle here but comptime eval facilities aren't good enough
17511751 const uint = std.meta.Int(.unsigned, @typeInfo(T).Int.bits);
1752 var bits = @bitCast(uint, value);
1752 var bits = @as(uint, @bitCast(value));
17531753 for (buffer) |*b| {
1754 b.* = @truncate(u8, bits);
1754 b.* = @as(u8, @truncate(bits));
17551755 bits >>= 8;
17561756 }
17571757}
......@@ -1768,17 +1768,17 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
17681768 return @memset(buffer, 0);
17691769 } else if (@typeInfo(T).Int.bits == 8) {
17701770 @memset(buffer, 0);
1771 buffer[buffer.len - 1] = @bitCast(u8, value);
1771 buffer[buffer.len - 1] = @as(u8, @bitCast(value));
17721772 return;
17731773 }
17741774
17751775 // TODO I want to call writeIntBig here but comptime eval facilities aren't good enough
17761776 const uint = std.meta.Int(.unsigned, @typeInfo(T).Int.bits);
1777 var bits = @bitCast(uint, value);
1777 var bits = @as(uint, @bitCast(value));
17781778 var index: usize = buffer.len;
17791779 while (index != 0) {
17801780 index -= 1;
1781 buffer[index] = @truncate(u8, bits);
1781 buffer[index] = @as(u8, @truncate(bits));
17821782 bits >>= 8;
17831783 }
17841784}
......@@ -1822,7 +1822,7 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value
18221822 const uN = std.meta.Int(.unsigned, @bitSizeOf(T));
18231823 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));
18261826 const write_size = (bit_count + bit_shift + 7) / 8;
18271827 const lowest_byte = switch (endian) {
18281828 .Big => bytes.len - (bit_offset / 8) - write_size,
......@@ -1833,8 +1833,8 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value
18331833 if (write_size == 1) {
18341834 // Single byte writes are handled specially, since we need to mask bits
18351835 // on both ends of the byte.
1836 const mask = (@as(u8, 0xff) >> @intCast(u3, 8 - bit_count));
1837 const new_bits = @intCast(u8, @bitCast(uN, value) & mask) << bit_shift;
1836 const mask = (@as(u8, 0xff) >> @as(u3, @intCast(8 - bit_count)));
1837 const new_bits = @as(u8, @intCast(@as(uN, @bitCast(value)) & mask)) << bit_shift;
18381838 write_bytes[0] = (write_bytes[0] & ~(mask << bit_shift)) | new_bits;
18391839 return;
18401840 }
......@@ -1843,31 +1843,31 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value
18431843
18441844 // Iterate bytes forward for Little-endian, backward for Big-endian
18451845 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
18481848 var i: isize = start; // isize for signed index arithmetic
18491849
18501850 // Write first byte, using a mask to protects bits preceding bit_offset
18511851 const head_mask = @as(u8, 0xff) >> bit_shift;
1852 write_bytes[@intCast(usize, i)] &= ~(head_mask << bit_shift);
1853 write_bytes[@intCast(usize, i)] |= @intCast(u8, @bitCast(uN, remaining) & head_mask) << bit_shift;
1854 remaining >>= @intCast(Log2N, @as(u4, 8) - bit_shift);
1852 write_bytes[@as(usize, @intCast(i))] &= ~(head_mask << bit_shift);
1853 write_bytes[@as(usize, @intCast(i))] |= @as(u8, @intCast(@as(uN, @bitCast(remaining)) & head_mask)) << bit_shift;
1854 remaining >>= @as(Log2N, @intCast(@as(u4, 8) - bit_shift));
18551855 i += delta;
18561856
18571857 // Write bytes[1..bytes.len - 1]
18581858 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);
18601860 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))));
18621862 remaining >>= 8;
18631863 }
18641864 }
18651865
18661866 // 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));
18681868 const tail_mask = (@as(u8, 0xff) << following_bits) >> following_bits;
1869 write_bytes[@intCast(usize, i)] &= ~tail_mask;
1870 write_bytes[@intCast(usize, i)] |= @intCast(u8, @bitCast(uN, remaining) & tail_mask);
1869 write_bytes[@as(usize, @intCast(i))] &= ~tail_mask;
1870 write_bytes[@as(usize, @intCast(i))] |= @as(u8, @intCast(@as(uN, @bitCast(remaining)) & tail_mask));
18711871}
18721872
18731873test "writeIntBig and writeIntLittle" {
......@@ -3799,15 +3799,14 @@ pub fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize {
37993799/// type.
38003800pub fn alignPointer(ptr: anytype, align_to: usize) ?@TypeOf(ptr) {
38013801 const adjust_off = alignPointerOffset(ptr, align_to) orelse return null;
3802 const T = @TypeOf(ptr);
38033802 // 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);
38053804}
38063805
38073806test "alignPointer" {
38083807 const S = struct {
38093808 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));
38113810 var aligned = alignPointer(ptr, align_to);
38123811 try testing.expectEqual(expected, @intFromPtr(aligned));
38133812 }
......@@ -3854,9 +3853,7 @@ fn AsBytesReturnType(comptime P: type) type {
38543853
38553854/// Given a pointer to a single item, returns a slice of the underlying bytes, preserving pointer attributes.
38563855pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr)) {
3857 const P = @TypeOf(ptr);
3858 const T = AsBytesReturnType(P);
3859 return @ptrCast(T, @alignCast(meta.alignment(T), ptr));
3856 return @ptrCast(@alignCast(ptr));
38603857}
38613858
38623859test "asBytes" {
......@@ -3902,7 +3899,7 @@ test "asBytes" {
39023899
39033900test "asBytes preserves pointer attributes" {
39043901 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));
39063903 const outSlice = asBytes(inPtr);
39073904
39083905 const in = @typeInfo(@TypeOf(inPtr)).Pointer;
......@@ -3948,7 +3945,7 @@ fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
39483945/// Given a pointer to an array of bytes, returns a pointer to a value of the specified type
39493946/// backed by those bytes, preserving pointer attributes.
39503947pub 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));
39523949}
39533950
39543951test "bytesAsValue" {
......@@ -3993,7 +3990,7 @@ test "bytesAsValue" {
39933990
39943991test "bytesAsValue preserves pointer attributes" {
39953992 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..];
39973994 const outPtr = bytesAsValue(u32, inSlice);
39983995
39993996 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
......@@ -4043,7 +4040,7 @@ pub fn bytesAsSlice(comptime T: type, bytes: anytype) BytesAsSliceReturnType(T,
40434040
40444041 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))];
40474044}
40484045
40494046test "bytesAsSlice" {
......@@ -4101,7 +4098,7 @@ test "bytesAsSlice with specified alignment" {
41014098
41024099test "bytesAsSlice preserves pointer attributes" {
41034100 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..];
41054102 const outSlice = bytesAsSlice(u16, inSlice);
41064103
41074104 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
......@@ -4133,7 +4130,7 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) {
41334130
41344131 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))];
41374134}
41384135
41394136test "sliceAsBytes" {
......@@ -4197,7 +4194,7 @@ test "sliceAsBytes and bytesAsSlice back" {
41974194
41984195test "sliceAsBytes preserves pointer attributes" {
41994196 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..];
42014198 const outSlice = sliceAsBytes(inSlice);
42024199
42034200 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
......@@ -4218,7 +4215,7 @@ pub fn alignForward(comptime T: type, addr: T, alignment: T) T {
42184215}
42194216
42204217pub 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));
42224219 return alignForward(usize, addr, alignment);
42234220}
42244221
......@@ -4282,7 +4279,7 @@ pub fn doNotOptimizeAway(val: anytype) void {
42824279/// .stage2_c doesn't support asm blocks yet, so use volatile stores instead
42834280var deopt_target: if (builtin.zig_backend == .stage2_c) u8 else void = undefined;
42844281fn doNotOptimizeAwayC(ptr: anytype) void {
4285 const dest = @ptrCast(*volatile u8, &deopt_target);
4282 const dest = @as(*volatile u8, @ptrCast(&deopt_target));
42864283 for (asBytes(ptr)) |b| {
42874284 dest.* = b;
42884285 }
......@@ -4433,7 +4430,7 @@ pub fn alignInBytes(bytes: []u8, comptime new_alignment: usize) ?[]align(new_ali
44334430 error.Overflow => return null,
44344431 };
44354432 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]);
44374434}
44384435
44394436/// 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
44454442 const Element = @TypeOf(slice[0]);
44464443 const slice_length_bytes = aligned_bytes.len - (aligned_bytes.len % @sizeOf(Element));
44474444 const aligned_slice = bytesAsSlice(Element, aligned_bytes[0..slice_length_bytes]);
4448 return @alignCast(new_alignment, aligned_slice);
4445 return @alignCast(aligned_slice);
44494446}
44504447
44514448test "read/write(Var)PackedInt" {
......@@ -4490,8 +4487,8 @@ test "read/write(Var)PackedInt" {
44904487 for ([_]PackedType{
44914488 ~@as(PackedType, 0), // all ones: -1 iN / maxInt uN
44924489 @as(PackedType, 0), // all zeros: 0 iN / 0 uN
4493 @bitCast(PackedType, @as(iPackedType, math.maxInt(iPackedType))), // maxInt iN
4494 @bitCast(PackedType, @as(iPackedType, math.minInt(iPackedType))), // maxInt iN
4490 @as(PackedType, @bitCast(@as(iPackedType, math.maxInt(iPackedType)))), // maxInt iN
4491 @as(PackedType, @bitCast(@as(iPackedType, math.minInt(iPackedType)))), // maxInt iN
44954492 random.int(PackedType), // random
44964493 random.int(PackedType), // random
44974494 }) |write_value| {
......@@ -4502,11 +4499,11 @@ test "read/write(Var)PackedInt" {
45024499
45034500 // Read
45044501 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
45074504 // Write
45084505 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
45114508 // Read again
45124509 const read_value2 = readPackedInt(PackedType, asBytes(&value), offset, native_endian);
......@@ -4515,9 +4512,9 @@ test "read/write(Var)PackedInt" {
45154512 // Verify bits outside of the target integer are unmodified
45164513 const diff_bits = init_value ^ value;
45174514 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);
45194516 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);
45214518 }
45224519
45234520 { // Fixed-size Read/Write (Foreign-endian)
......@@ -4527,11 +4524,11 @@ test "read/write(Var)PackedInt" {
45274524
45284525 // Read
45294526 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
45324529 // Write
45334530 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
45364533 // Read again
45374534 const read_value2 = readPackedInt(PackedType, asBytes(&value), offset, foreign_endian);
......@@ -4540,9 +4537,9 @@ test "read/write(Var)PackedInt" {
45404537 // Verify bits outside of the target integer are unmodified
45414538 const diff_bits = init_value ^ @byteSwap(value);
45424539 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);
45444541 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);
45464543 }
45474544
45484545 const signedness = @typeInfo(PackedType).Int.signedness;
......@@ -4559,11 +4556,11 @@ test "read/write(Var)PackedInt" {
45594556
45604557 // Read
45614558 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
45644561 // Write
45654562 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
45684565 // Read again
45694566 const read_value2 = readVarPackedInt(U, asBytes(&value), offset, @bitSizeOf(PackedType), native_endian, signedness);
......@@ -4572,9 +4569,9 @@ test "read/write(Var)PackedInt" {
45724569 // Verify bits outside of the target integer are unmodified
45734570 const diff_bits = init_value ^ value;
45744571 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);
45764573 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);
45784575 }
45794576
45804577 { // Variable-size Read/Write (Foreign-endian)
......@@ -4587,11 +4584,11 @@ test "read/write(Var)PackedInt" {
45874584
45884585 // Read
45894586 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
45924589 // Write
45934590 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
45964593 // Read again
45974594 const read_value2 = readVarPackedInt(U, asBytes(&value), offset, @bitSizeOf(PackedType), foreign_endian, signedness);
......@@ -4600,9 +4597,9 @@ test "read/write(Var)PackedInt" {
46004597 // Verify bits outside of the target integer are unmodified
46014598 const diff_bits = init_value ^ @byteSwap(value);
46024599 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);
46044601 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);
46064603 }
46074604 }
46084605 }
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:
101101/// Returns a pointer to undefined memory.
102102/// Call `destroy` with the result to free the memory.
103103pub 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)));
105105 const slice = try self.allocAdvancedWithRetAddr(T, null, 1, @returnAddress());
106106 return &slice[0];
107107}
......@@ -112,7 +112,7 @@ pub fn destroy(self: Allocator, ptr: anytype) void {
112112 const info = @typeInfo(@TypeOf(ptr)).Pointer;
113113 const T = info.child;
114114 if (@sizeOf(T) == 0) return;
115 const non_const_ptr = @ptrCast([*]u8, @constCast(ptr));
115 const non_const_ptr = @as([*]u8, @ptrCast(@constCast(ptr)));
116116 self.rawFree(non_const_ptr[0..@sizeOf(T)], math.log2(info.alignment), @returnAddress());
117117}
118118
......@@ -209,15 +209,15 @@ pub fn allocAdvancedWithRetAddr(
209209
210210 if (n == 0) {
211211 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];
213213 }
214214
215215 const byte_count = math.mul(usize, @sizeOf(T), n) catch return Error.OutOfMemory;
216216 const byte_ptr = self.rawAlloc(byte_count, log2a(a), return_address) orelse return Error.OutOfMemory;
217217 // TODO: https://github.com/ziglang/zig/issues/4298
218218 @memset(byte_ptr[0..byte_count], undefined);
219 const byte_slice = byte_ptr[0..byte_count];
220 return mem.bytesAsSlice(T, @alignCast(a, byte_slice));
219 const byte_slice: []align(a) u8 = @alignCast(byte_ptr[0..byte_count]);
220 return mem.bytesAsSlice(T, byte_slice);
221221}
222222
223223/// Requests to modify the size of an allocation. It is guaranteed to not move
......@@ -268,7 +268,7 @@ pub fn reallocAdvanced(
268268 if (new_n == 0) {
269269 self.free(old_mem);
270270 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];
272272 }
273273
274274 const old_byte_slice = mem.sliceAsBytes(old_mem);
......@@ -276,7 +276,8 @@ pub fn reallocAdvanced(
276276 // Note: can't set shrunk memory to undefined as memory shouldn't be modified on realloc failure
277277 if (mem.isAligned(@intFromPtr(old_byte_slice.ptr), Slice.alignment)) {
278278 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);
280281 }
281282 }
282283
......@@ -288,7 +289,8 @@ pub fn reallocAdvanced(
288289 @memset(old_byte_slice, undefined);
289290 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);
292294}
293295
294296/// 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) {
185185 switch (@typeInfo(T)) {
186186 .Array => |info| {
187187 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)).*;
189189 },
190190 .Pointer => |info| {
191191 switch (info.size) {
192192 .Many, .Slice => {
193193 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)).*;
195195 },
196196 .One => switch (@typeInfo(info.child)) {
197197 .Array => |array_info| {
198198 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)).*;
200200 },
201201 else => {},
202202 },
......@@ -241,7 +241,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
241241 .Array = .{
242242 .len = array_info.len,
243243 .child = array_info.child,
244 .sentinel = @ptrCast(?*const anyopaque, &sentinel_val),
244 .sentinel = @as(?*const anyopaque, @ptrCast(&sentinel_val)),
245245 },
246246 }),
247247 .is_allowzero = info.is_allowzero,
......@@ -259,7 +259,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
259259 .address_space = info.address_space,
260260 .child = info.child,
261261 .is_allowzero = info.is_allowzero,
262 .sentinel = @ptrCast(?*const anyopaque, &sentinel_val),
262 .sentinel = @as(?*const anyopaque, @ptrCast(&sentinel_val)),
263263 },
264264 }),
265265 else => {},
......@@ -277,7 +277,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
277277 .address_space = ptr_info.address_space,
278278 .child = ptr_info.child,
279279 .is_allowzero = ptr_info.is_allowzero,
280 .sentinel = @ptrCast(?*const anyopaque, &sentinel_val),
280 .sentinel = @as(?*const anyopaque, @ptrCast(&sentinel_val)),
281281 },
282282 }),
283283 },
......@@ -929,8 +929,8 @@ test "intToEnum with error return" {
929929 try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
930930 try testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
931931 try testing.expect(intToEnum(E3, zero) catch unreachable == E3.A);
932 try testing.expect(intToEnum(E3, 127) catch unreachable == @enumFromInt(E3, 127));
933 try testing.expect(intToEnum(E3, -128) catch unreachable == @enumFromInt(E3, -128));
932 try testing.expect(intToEnum(E3, 127) catch unreachable == @as(E3, @enumFromInt(127)));
933 try testing.expect(intToEnum(E3, -128) catch unreachable == @as(E3, @enumFromInt(-128)));
934934 try testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));
935935 try testing.expectError(error.InvalidEnumTag, intToEnum(E3, 128));
936936 try testing.expectError(error.InvalidEnumTag, intToEnum(E3, -129));
......@@ -943,7 +943,7 @@ pub fn intToEnum(comptime EnumTag: type, tag_int: anytype) IntToEnumError!EnumTa
943943
944944 if (!enum_info.is_exhaustive) {
945945 if (std.math.cast(enum_info.tag_type, tag_int)) |tag| {
946 return @enumFromInt(EnumTag, tag);
946 return @as(EnumTag, @enumFromInt(tag));
947947 }
948948 return error.InvalidEnumTag;
949949 }
lib/std/meta/trailer_flags.zig+3-3
......@@ -72,7 +72,7 @@ pub fn TrailerFlags(comptime Fields: type) type {
7272 pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: FieldValues) void {
7373 inline for (@typeInfo(Fields).Struct.fields, 0..) |field, i| {
7474 if (@field(fields, field.name)) |value|
75 self.set(p, @enumFromInt(FieldEnum, i), value);
75 self.set(p, @as(FieldEnum, @enumFromInt(i)), value);
7676 }
7777 }
7878
......@@ -89,14 +89,14 @@ pub fn TrailerFlags(comptime Fields: type) type {
8989 if (@sizeOf(Field(field)) == 0)
9090 return undefined;
9191 const off = self.offset(field);
92 return @ptrCast(*Field(field), @alignCast(@alignOf(Field(field)), p + off));
92 return @ptrCast(@alignCast(p + off));
9393 }
9494
9595 pub fn ptrConst(self: Self, p: [*]align(@alignOf(Fields)) const u8, comptime field: FieldEnum) *const Field(field) {
9696 if (@sizeOf(Field(field)) == 0)
9797 return undefined;
9898 const off = self.offset(field);
99 return @ptrCast(*const Field(field), @alignCast(@alignOf(Field(field)), p + off));
99 return @ptrCast(@alignCast(p + off));
100100 }
101101
102102 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 {
237237
238238test "isManyItemPtr" {
239239 const array = [_]u8{0} ** 10;
240 const mip = @ptrCast([*]const u8, &array[0]);
240 const mip = @as([*]const u8, @ptrCast(&array[0]));
241241 try testing.expect(isManyItemPtr(@TypeOf(mip)));
242242 try testing.expect(!isManyItemPtr(@TypeOf(array)));
243243 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 {
7878 const casted_ptr: [*]F = if (@sizeOf(F) == 0)
7979 undefined
8080 else
81 @ptrCast([*]F, @alignCast(@alignOf(F), byte_ptr));
81 @ptrCast(@alignCast(byte_ptr));
8282 return casted_ptr[0..self.len];
8383 }
8484
......@@ -89,14 +89,14 @@ pub fn MultiArrayList(comptime T: type) type {
8989 else => unreachable,
9090 };
9191 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);
9393 }
9494 }
9595
9696 pub fn get(self: Slice, index: usize) T {
9797 var result: Elem = undefined;
9898 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];
100100 }
101101 return switch (@typeInfo(T)) {
102102 .Struct => result,
......@@ -110,10 +110,9 @@ pub fn MultiArrayList(comptime T: type) type {
110110 return .{};
111111 }
112112 const unaligned_ptr = self.ptrs[sizes.fields[0]];
113 const aligned_ptr = @alignCast(@alignOf(Elem), unaligned_ptr);
114 const casted_ptr = @ptrCast([*]align(@alignOf(Elem)) u8, aligned_ptr);
113 const aligned_ptr: [*]align(@alignOf(Elem)) u8 = @alignCast(unaligned_ptr);
115114 return .{
116 .bytes = casted_ptr,
115 .bytes = aligned_ptr,
117116 .len = self.len,
118117 .capacity = self.capacity,
119118 };
......@@ -294,7 +293,7 @@ pub fn MultiArrayList(comptime T: type) type {
294293 };
295294 const slices = self.slice();
296295 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)));
298297 var i: usize = self.len - 1;
299298 while (i > index) : (i -= 1) {
300299 field_slice[i] = field_slice[i - 1];
......@@ -309,7 +308,7 @@ pub fn MultiArrayList(comptime T: type) type {
309308 pub fn swapRemove(self: *Self, index: usize) void {
310309 const slices = self.slice();
311310 inline for (fields, 0..) |_, i| {
312 const field_slice = slices.items(@enumFromInt(Field, i));
311 const field_slice = slices.items(@as(Field, @enumFromInt(i)));
313312 field_slice[index] = field_slice[self.len - 1];
314313 field_slice[self.len - 1] = undefined;
315314 }
......@@ -321,7 +320,7 @@ pub fn MultiArrayList(comptime T: type) type {
321320 pub fn orderedRemove(self: *Self, index: usize) void {
322321 const slices = self.slice();
323322 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)));
325324 var i = index;
326325 while (i < self.len - 1) : (i += 1) {
327326 field_slice[i] = field_slice[i + 1];
......@@ -358,7 +357,7 @@ pub fn MultiArrayList(comptime T: type) type {
358357 const self_slice = self.slice();
359358 inline for (fields, 0..) |field_info, i| {
360359 if (@sizeOf(field_info.type) != 0) {
361 const field = @enumFromInt(Field, i);
360 const field = @as(Field, @enumFromInt(i));
362361 const dest_slice = self_slice.items(field)[new_len..];
363362 // We use memset here for more efficient codegen in safety-checked,
364363 // valgrind-enabled builds. Otherwise the valgrind client request
......@@ -379,7 +378,7 @@ pub fn MultiArrayList(comptime T: type) type {
379378 const other_slice = other.slice();
380379 inline for (fields, 0..) |field_info, i| {
381380 if (@sizeOf(field_info.type) != 0) {
382 const field = @enumFromInt(Field, i);
381 const field = @as(Field, @enumFromInt(i));
383382 @memcpy(other_slice.items(field), self_slice.items(field));
384383 }
385384 }
......@@ -440,7 +439,7 @@ pub fn MultiArrayList(comptime T: type) type {
440439 const other_slice = other.slice();
441440 inline for (fields, 0..) |field_info, i| {
442441 if (@sizeOf(field_info.type) != 0) {
443 const field = @enumFromInt(Field, i);
442 const field = @as(Field, @enumFromInt(i));
444443 @memcpy(other_slice.items(field), self_slice.items(field));
445444 }
446445 }
......@@ -459,7 +458,7 @@ pub fn MultiArrayList(comptime T: type) type {
459458 const result_slice = result.slice();
460459 inline for (fields, 0..) |field_info, i| {
461460 if (@sizeOf(field_info.type) != 0) {
462 const field = @enumFromInt(Field, i);
461 const field = @as(Field, @enumFromInt(i));
463462 @memcpy(result_slice.items(field), self_slice.items(field));
464463 }
465464 }
......@@ -476,7 +475,7 @@ pub fn MultiArrayList(comptime T: type) type {
476475 pub fn swap(sc: @This(), a_index: usize, b_index: usize) void {
477476 inline for (fields, 0..) |field_info, i| {
478477 if (@sizeOf(field_info.type) != 0) {
479 const field = @enumFromInt(Field, i);
478 const field = @as(Field, @enumFromInt(i));
480479 const ptr = sc.slice.items(field);
481480 mem.swap(field_info.type, &ptr[a_index], &ptr[b_index]);
482481 }
......@@ -592,9 +591,9 @@ test "basic usage" {
592591 var i: usize = 0;
593592 while (i < 6) : (i += 1) {
594593 try list.append(ally, .{
595 .a = @intCast(u32, 4 + i),
594 .a = @as(u32, @intCast(4 + i)),
596595 .b = "whatever",
597 .c = @intCast(u8, 'd' + i),
596 .c = @as(u8, @intCast('d' + i)),
598597 });
599598 }
600599
......@@ -791,7 +790,7 @@ test "union" {
791790
792791 // Add 6 more things to force a capacity increase.
793792 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)) });
795794 }
796795
797796 try testing.expectEqualSlices(
lib/std/net.zig+39-39
......@@ -137,8 +137,8 @@ pub const Address = extern union {
137137 /// on the address family.
138138 pub fn initPosix(addr: *align(4) const os.sockaddr) Address {
139139 switch (addr.family) {
140 os.AF.INET => return Address{ .in = Ip4Address{ .sa = @ptrCast(*const os.sockaddr.in, addr).* } },
141 os.AF.INET6 => return Address{ .in6 = Ip6Address{ .sa = @ptrCast(*const os.sockaddr.in6, 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 = @as(*const os.sockaddr.in6, @ptrCast(addr)).* } },
142142 else => unreachable,
143143 }
144144 }
......@@ -165,8 +165,8 @@ pub const Address = extern union {
165165 }
166166
167167 pub fn eql(a: Address, b: Address) bool {
168 const a_bytes = @ptrCast([*]const u8, &a.any)[0..a.getOsSockLen()];
169 const b_bytes = @ptrCast([*]const u8, &b.any)[0..b.getOsSockLen()];
168 const a_bytes = @as([*]const u8, @ptrCast(&a.any))[0..a.getOsSockLen()];
169 const b_bytes = @as([*]const u8, @ptrCast(&b.any))[0..b.getOsSockLen()];
170170 return mem.eql(u8, a_bytes, b_bytes);
171171 }
172172
......@@ -187,7 +187,7 @@ pub const Address = extern union {
187187 // provide the full buffer size (e.g. getsockname, getpeername, recvfrom, accept).
188188 //
189189 // 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)));
191191 },
192192
193193 else => unreachable,
......@@ -260,7 +260,7 @@ pub const Ip4Address = extern struct {
260260 return Ip4Address{
261261 .sa = os.sockaddr.in{
262262 .port = mem.nativeToBig(u16, port),
263 .addr = @ptrCast(*align(1) const u32, &addr).*,
263 .addr = @as(*align(1) const u32, @ptrCast(&addr)).*,
264264 },
265265 };
266266 }
......@@ -285,7 +285,7 @@ pub const Ip4Address = extern struct {
285285 ) !void {
286286 if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
287287 _ = options;
288 const bytes = @ptrCast(*const [4]u8, &self.sa.addr);
288 const bytes = @as(*const [4]u8, @ptrCast(&self.sa.addr));
289289 try std.fmt.format(out_stream, "{}.{}.{}.{}:{}", .{
290290 bytes[0],
291291 bytes[1],
......@@ -354,9 +354,9 @@ pub const Ip6Address = extern struct {
354354 if (index == 14) {
355355 return error.InvalidEnd;
356356 }
357 ip_slice[index] = @truncate(u8, x >> 8);
357 ip_slice[index] = @as(u8, @truncate(x >> 8));
358358 index += 1;
359 ip_slice[index] = @truncate(u8, x);
359 ip_slice[index] = @as(u8, @truncate(x));
360360 index += 1;
361361
362362 x = 0;
......@@ -408,13 +408,13 @@ pub const Ip6Address = extern struct {
408408 }
409409
410410 if (index == 14) {
411 ip_slice[14] = @truncate(u8, x >> 8);
412 ip_slice[15] = @truncate(u8, x);
411 ip_slice[14] = @as(u8, @truncate(x >> 8));
412 ip_slice[15] = @as(u8, @truncate(x));
413413 return result;
414414 } else {
415 ip_slice[index] = @truncate(u8, x >> 8);
415 ip_slice[index] = @as(u8, @truncate(x >> 8));
416416 index += 1;
417 ip_slice[index] = @truncate(u8, x);
417 ip_slice[index] = @as(u8, @truncate(x));
418418 index += 1;
419419 @memcpy(result.sa.addr[16 - index ..][0..index], ip_slice[0..index]);
420420 return result;
......@@ -473,9 +473,9 @@ pub const Ip6Address = extern struct {
473473 if (index == 14) {
474474 return error.InvalidEnd;
475475 }
476 ip_slice[index] = @truncate(u8, x >> 8);
476 ip_slice[index] = @as(u8, @truncate(x >> 8));
477477 index += 1;
478 ip_slice[index] = @truncate(u8, x);
478 ip_slice[index] = @as(u8, @truncate(x));
479479 index += 1;
480480
481481 x = 0;
......@@ -542,13 +542,13 @@ pub const Ip6Address = extern struct {
542542 result.sa.scope_id = resolved_scope_id;
543543
544544 if (index == 14) {
545 ip_slice[14] = @truncate(u8, x >> 8);
546 ip_slice[15] = @truncate(u8, x);
545 ip_slice[14] = @as(u8, @truncate(x >> 8));
546 ip_slice[15] = @as(u8, @truncate(x));
547547 return result;
548548 } else {
549 ip_slice[index] = @truncate(u8, x >> 8);
549 ip_slice[index] = @as(u8, @truncate(x >> 8));
550550 index += 1;
551 ip_slice[index] = @truncate(u8, x);
551 ip_slice[index] = @as(u8, @truncate(x));
552552 index += 1;
553553 @memcpy(result.sa.addr[16 - index ..][0..index], ip_slice[0..index]);
554554 return result;
......@@ -597,7 +597,7 @@ pub const Ip6Address = extern struct {
597597 });
598598 return;
599599 }
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));
601601 const native_endian_parts = switch (native_endian) {
602602 .Big => big_endian_parts.*,
603603 .Little => blk: {
......@@ -668,7 +668,7 @@ fn if_nametoindex(name: []const u8) !u32 {
668668 // TODO investigate if this needs to be integrated with evented I/O.
669669 try os.ioctl_SIOCGIFINDEX(sockfd, &ifr);
670670
671 return @bitCast(u32, ifr.ifru.ivalue);
671 return @as(u32, @bitCast(ifr.ifru.ivalue));
672672 }
673673
674674 if (comptime builtin.target.os.tag.isDarwin()) {
......@@ -682,7 +682,7 @@ fn if_nametoindex(name: []const u8) !u32 {
682682 const index = os.system.if_nametoindex(if_slice);
683683 if (index == 0)
684684 return error.InterfaceNotFound;
685 return @bitCast(u32, index);
685 return @as(u32, @bitCast(index));
686686 }
687687
688688 @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
804804 var first = true;
805805 while (true) {
806806 const rc = ws2_32.getaddrinfo(name_c.ptr, port_c.ptr, &hints, &res);
807 switch (@enumFromInt(os.windows.ws2_32.WinsockError, @intCast(u16, rc))) {
808 @enumFromInt(os.windows.ws2_32.WinsockError, 0) => break,
807 switch (@as(os.windows.ws2_32.WinsockError, @enumFromInt(@as(u16, @intCast(rc))))) {
808 @as(os.windows.ws2_32.WinsockError, @enumFromInt(0)) => break,
809809 .WSATRY_AGAIN => return error.TemporaryNameServerFailure,
810810 .WSANO_RECOVERY => return error.NameServerFailure,
811811 .WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported,
......@@ -841,7 +841,7 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get
841841 var i: usize = 0;
842842 while (it) |info| : (it = info.next) {
843843 const addr = info.addr orelse continue;
844 result.addrs[i] = Address.initPosix(@alignCast(4, addr));
844 result.addrs[i] = Address.initPosix(@alignCast(addr));
845845
846846 if (info.canonname) |n| {
847847 if (result.canon_name == null) {
......@@ -874,7 +874,7 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get
874874 };
875875 var res: ?*os.addrinfo = null;
876876 switch (sys.getaddrinfo(name_c.ptr, port_c.ptr, &hints, &res)) {
877 @enumFromInt(sys.EAI, 0) => {},
877 @as(sys.EAI, @enumFromInt(0)) => {},
878878 .ADDRFAMILY => return error.HostLacksNetworkAddresses,
879879 .AGAIN => return error.TemporaryNameServerFailure,
880880 .BADFLAGS => unreachable, // Invalid hints
......@@ -908,7 +908,7 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get
908908 var i: usize = 0;
909909 while (it) |info| : (it = info.next) {
910910 const addr = info.addr orelse continue;
911 result.addrs[i] = Address.initPosix(@alignCast(4, addr));
911 result.addrs[i] = Address.initPosix(@alignCast(addr));
912912
913913 if (info.canonname) |n| {
914914 if (result.canon_name == null) {
......@@ -1020,7 +1020,7 @@ fn linuxLookupName(
10201020 for (addrs.items, 0..) |*addr, i| {
10211021 var key: i32 = 0;
10221022 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);
10241024 var da6 = os.sockaddr.in6{
10251025 .family = os.AF.INET6,
10261026 .scope_id = addr.addr.in6.sa.scope_id,
......@@ -1029,7 +1029,7 @@ fn linuxLookupName(
10291029 .addr = [1]u8{0} ** 16,
10301030 };
10311031 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);
10331033 var da4 = os.sockaddr.in{
10341034 .family = os.AF.INET,
10351035 .port = 65535,
......@@ -1042,18 +1042,18 @@ fn linuxLookupName(
10421042 var dalen: os.socklen_t = undefined;
10431043 if (addr.addr.any.family == os.AF.INET6) {
10441044 da6.addr = addr.addr.in6.sa.addr;
1045 da = @ptrCast(*os.sockaddr, &da6);
1045 da = @ptrCast(&da6);
10461046 dalen = @sizeOf(os.sockaddr.in6);
1047 sa = @ptrCast(*os.sockaddr, &sa6);
1047 sa = @ptrCast(&sa6);
10481048 salen = @sizeOf(os.sockaddr.in6);
10491049 } else {
10501050 sa6.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;
10511051 da6.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;
10521052 mem.writeIntNative(u32, da6.addr[12..], addr.addr.in.sa.addr);
10531053 da4.addr = addr.addr.in.sa.addr;
1054 da = @ptrCast(*os.sockaddr, &da4);
1054 da = @ptrCast(&da4);
10551055 dalen = @sizeOf(os.sockaddr.in);
1056 sa = @ptrCast(*os.sockaddr, &sa4);
1056 sa = @ptrCast(&sa4);
10571057 salen = @sizeOf(os.sockaddr.in);
10581058 }
10591059 const dpolicy = policyOf(da6.addr);
......@@ -1070,7 +1070,7 @@ fn linuxLookupName(
10701070 os.getsockname(fd, sa, &salen) catch break :syscalls;
10711071 if (addr.addr.any.family == os.AF.INET) {
10721072 // 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);
10741074 }
10751075 if (dscope == @as(i32, scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE;
10761076 if (dlabel == labelOf(sa6.addr)) key |= DAS_MATCHINGLABEL;
......@@ -1079,7 +1079,7 @@ fn linuxLookupName(
10791079 key |= dprec << DAS_PREC_SHIFT;
10801080 key |= (15 - dscope) << DAS_SCOPE_SHIFT;
10811081 key |= prefixlen << DAS_PREFIX_SHIFT;
1082 key |= (MAXADDRS - @intCast(i32, i)) << DAS_ORDER_SHIFT;
1082 key |= (MAXADDRS - @as(i32, @intCast(i))) << DAS_ORDER_SHIFT;
10831083 addr.sortkey = key;
10841084 }
10851085 mem.sort(LookupAddr, addrs.items, {}, addrCmpLessThan);
......@@ -1171,7 +1171,7 @@ fn prefixMatch(s: [16]u8, d: [16]u8) u8 {
11711171 // address. However the definition of the source prefix length is
11721172 // not clear and thus this limiting is not yet implemented.
11731173 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) {}
11751175 return i;
11761176}
11771177
......@@ -1577,7 +1577,7 @@ fn resMSendRc(
15771577
15781578 // Get local address and open/bind a socket
15791579 var sa: Address = undefined;
1580 @memset(@ptrCast([*]u8, &sa)[0..@sizeOf(Address)], 0);
1580 @memset(@as([*]u8, @ptrCast(&sa))[0..@sizeOf(Address)], 0);
15811581 sa.any.family = family;
15821582 try os.bind(fd, &sa.any, sl);
15831583
......@@ -1588,13 +1588,13 @@ fn resMSendRc(
15881588 }};
15891589 const retry_interval = timeout / attempts;
15901590 var next: u32 = 0;
1591 var t2: u64 = @bitCast(u64, std.time.milliTimestamp());
1591 var t2: u64 = @as(u64, @bitCast(std.time.milliTimestamp()));
15921592 var t0 = t2;
15931593 var t1 = t2 - retry_interval;
15941594
15951595 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()))) {
15981598 if (t2 - t1 >= retry_interval) {
15991599 // Query all configured nameservers in parallel
16001600 var i: usize = 0;
lib/std/os.zig+125-125
......@@ -494,7 +494,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
494494 const res = if (use_c) blk: {
495495 const rc = std.c.getrandom(buf.ptr, buf.len, 0);
496496 break :blk .{
497 .num_read = @bitCast(usize, rc),
497 .num_read = @as(usize, @bitCast(rc)),
498498 .err = std.c.getErrno(rc),
499499 };
500500 } else blk: {
......@@ -608,7 +608,7 @@ pub fn abort() noreturn {
608608 sigprocmask(SIG.UNBLOCK, &sigabrtmask, null);
609609
610610 // Beyond this point should be unreachable.
611 @ptrFromInt(*allowzero volatile u8, 0).* = 0;
611 @as(*allowzero volatile u8, @ptrFromInt(0)).* = 0;
612612 raise(SIG.KILL) catch {};
613613 exit(127); // Pid 1 might not be signalled in some containers.
614614 }
......@@ -678,10 +678,10 @@ pub fn exit(status: u8) noreturn {
678678 // exit() is only available if exitBootServices() has not been called yet.
679679 // This call to exit should not fail, so we don't care about its return value.
680680 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);
682682 }
683683 // 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);
685685 }
686686 system.exit(status);
687687}
......@@ -759,7 +759,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
759759 while (true) {
760760 const rc = system.read(fd, buf.ptr, adjusted_len);
761761 switch (errno(rc)) {
762 .SUCCESS => return @intCast(usize, rc),
762 .SUCCESS => return @as(usize, @intCast(rc)),
763763 .INTR => continue,
764764 .INVAL => unreachable,
765765 .FAULT => unreachable,
......@@ -818,7 +818,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
818818 // TODO handle the case when iov_len is too large and get rid of this @intCast
819819 const rc = system.readv(fd, iov.ptr, iov_count);
820820 switch (errno(rc)) {
821 .SUCCESS => return @intCast(usize, rc),
821 .SUCCESS => return @as(usize, @intCast(rc)),
822822 .INTR => continue,
823823 .INVAL => unreachable,
824824 .FAULT => unreachable,
......@@ -892,11 +892,11 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
892892
893893 const pread_sym = if (lfs64_abi) system.pread64 else system.pread;
894894
895 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
895 const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
896896 while (true) {
897897 const rc = pread_sym(fd, buf.ptr, adjusted_len, ioffset);
898898 switch (errno(rc)) {
899 .SUCCESS => return @intCast(usize, rc),
899 .SUCCESS => return @as(usize, @intCast(rc)),
900900 .INTR => continue,
901901 .INVAL => unreachable,
902902 .FAULT => unreachable,
......@@ -929,7 +929,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
929929 if (builtin.os.tag == .windows) {
930930 var io_status_block: windows.IO_STATUS_BLOCK = undefined;
931931 var eof_info = windows.FILE_END_OF_FILE_INFORMATION{
932 .EndOfFile = @bitCast(windows.LARGE_INTEGER, length),
932 .EndOfFile = @as(windows.LARGE_INTEGER, @bitCast(length)),
933933 };
934934
935935 const rc = windows.ntdll.NtSetInformationFile(
......@@ -965,7 +965,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
965965 while (true) {
966966 const ftruncate_sym = if (lfs64_abi) system.ftruncate64 else system.ftruncate;
967967
968 const ilen = @bitCast(i64, length); // the OS treats this as unsigned
968 const ilen = @as(i64, @bitCast(length)); // the OS treats this as unsigned
969969 switch (errno(ftruncate_sym(fd, ilen))) {
970970 .SUCCESS => return,
971971 .INTR => continue,
......@@ -1001,7 +1001,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
10011001 if (have_pread_but_not_preadv) {
10021002 // We could loop here; but proper usage of `preadv` must handle partial reads anyway.
10031003 // 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));
10051005 const first = iov[0];
10061006 return pread(fd, first.iov_base[0..first.iov_len], offset);
10071007 }
......@@ -1030,11 +1030,11 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
10301030
10311031 const preadv_sym = if (lfs64_abi) system.preadv64 else system.preadv;
10321032
1033 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
1033 const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
10341034 while (true) {
10351035 const rc = preadv_sym(fd, iov.ptr, iov_count, ioffset);
10361036 switch (errno(rc)) {
1037 .SUCCESS => return @bitCast(usize, rc),
1037 .SUCCESS => return @as(usize, @bitCast(rc)),
10381038 .INTR => continue,
10391039 .INVAL => unreachable,
10401040 .FAULT => unreachable,
......@@ -1143,7 +1143,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
11431143 while (true) {
11441144 const rc = system.write(fd, bytes.ptr, adjusted_len);
11451145 switch (errno(rc)) {
1146 .SUCCESS => return @intCast(usize, rc),
1146 .SUCCESS => return @as(usize, @intCast(rc)),
11471147 .INTR => continue,
11481148 .INVAL => return error.InvalidArgument,
11491149 .FAULT => unreachable,
......@@ -1212,11 +1212,11 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
12121212 }
12131213 }
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));
12161216 while (true) {
12171217 const rc = system.writev(fd, iov.ptr, iov_count);
12181218 switch (errno(rc)) {
1219 .SUCCESS => return @intCast(usize, rc),
1219 .SUCCESS => return @as(usize, @intCast(rc)),
12201220 .INTR => continue,
12211221 .INVAL => return error.InvalidArgument,
12221222 .FAULT => unreachable,
......@@ -1304,11 +1304,11 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
13041304
13051305 const pwrite_sym = if (lfs64_abi) system.pwrite64 else system.pwrite;
13061306
1307 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
1307 const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
13081308 while (true) {
13091309 const rc = pwrite_sym(fd, bytes.ptr, adjusted_len, ioffset);
13101310 switch (errno(rc)) {
1311 .SUCCESS => return @intCast(usize, rc),
1311 .SUCCESS => return @as(usize, @intCast(rc)),
13121312 .INTR => continue,
13131313 .INVAL => return error.InvalidArgument,
13141314 .FAULT => unreachable,
......@@ -1390,12 +1390,12 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
13901390
13911391 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);
1394 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
1393 const iov_count = if (iov.len > IOV_MAX) IOV_MAX else @as(u31, @intCast(iov.len));
1394 const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
13951395 while (true) {
13961396 const rc = pwritev_sym(fd, iov.ptr, iov_count, ioffset);
13971397 switch (errno(rc)) {
1398 .SUCCESS => return @intCast(usize, rc),
1398 .SUCCESS => return @as(usize, @intCast(rc)),
13991399 .INTR => continue,
14001400 .INVAL => return error.InvalidArgument,
14011401 .FAULT => unreachable,
......@@ -1504,7 +1504,7 @@ pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t
15041504 while (true) {
15051505 const rc = open_sym(file_path, flags, perm);
15061506 switch (errno(rc)) {
1507 .SUCCESS => return @intCast(fd_t, rc),
1507 .SUCCESS => return @as(fd_t, @intCast(rc)),
15081508 .INTR => continue,
15091509
15101510 .FAULT => unreachable,
......@@ -1653,11 +1653,11 @@ fn openOptionsFromFlagsWasi(fd: fd_t, oflag: u32) OpenError!WasiOpenOptions {
16531653 rights &= fsb_cur.fs_rights_inheriting;
16541654
16551655 return WasiOpenOptions{
1656 .oflags = @truncate(w.oflags_t, (oflag >> 12)) & 0xfff,
1656 .oflags = @as(w.oflags_t, @truncate((oflag >> 12))) & 0xfff,
16571657 .lookup_flags = if (oflag & O.NOFOLLOW == 0) w.LOOKUP_SYMLINK_FOLLOW else 0,
16581658 .fs_rights_base = rights,
16591659 .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)),
16611661 };
16621662}
16631663
......@@ -1717,7 +1717,7 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t)
17171717 while (true) {
17181718 const rc = openat_sym(dir_fd, file_path, flags, mode);
17191719 switch (errno(rc)) {
1720 .SUCCESS => return @intCast(fd_t, rc),
1720 .SUCCESS => return @as(fd_t, @intCast(rc)),
17211721 .INTR => continue,
17221722
17231723 .FAULT => unreachable,
......@@ -1765,7 +1765,7 @@ pub fn openatW(dir_fd: fd_t, file_path_w: []const u16, flags: u32, mode: mode_t)
17651765pub fn dup(old_fd: fd_t) !fd_t {
17661766 const rc = system.dup(old_fd);
17671767 return switch (errno(rc)) {
1768 .SUCCESS => return @intCast(fd_t, rc),
1768 .SUCCESS => return @as(fd_t, @intCast(rc)),
17691769 .MFILE => error.ProcessFdQuotaExceeded,
17701770 .BADF => unreachable, // invalid file descriptor
17711771 else => |err| return unexpectedErrno(err),
......@@ -2024,7 +2024,7 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
20242024
20252025 const err = if (builtin.link_libc) blk: {
20262026 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));
20282028 } else blk: {
20292029 break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len));
20302030 };
......@@ -2661,12 +2661,12 @@ pub fn renameatW(
26612661 const struct_len = @sizeOf(windows.FILE_RENAME_INFORMATION) - 1 + new_path_w.len * 2;
26622662 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
26662666 rename_info.* = .{
26672667 .ReplaceIfExists = ReplaceIfExists,
26682668 .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.NameTooLong
2669 .FileNameLength = @as(u32, @intCast(new_path_w.len * 2)), // already checked error.NameTooLong
26702670 .FileName = undefined,
26712671 };
26722672 @memcpy(@as([*]u16, &rename_info.FileName)[0..new_path_w.len], new_path_w);
......@@ -2677,7 +2677,7 @@ pub fn renameatW(
26772677 src_fd,
26782678 &io_status_block,
26792679 rename_info,
2680 @intCast(u32, struct_len), // already checked for error.NameTooLong
2680 @as(u32, @intCast(struct_len)), // already checked for error.NameTooLong
26812681 .FileRenameInformation,
26822682 );
26832683
......@@ -3049,7 +3049,7 @@ pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8
30493049 }
30503050 const rc = system.readlink(file_path, out_buffer.ptr, out_buffer.len);
30513051 switch (errno(rc)) {
3052 .SUCCESS => return out_buffer[0..@bitCast(usize, rc)],
3052 .SUCCESS => return out_buffer[0..@as(usize, @bitCast(rc))],
30533053 .ACCES => return error.AccessDenied,
30543054 .FAULT => unreachable,
30553055 .INVAL => return error.NotLink,
......@@ -3115,7 +3115,7 @@ pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) Read
31153115 }
31163116 const rc = system.readlinkat(dirfd, file_path, out_buffer.ptr, out_buffer.len);
31173117 switch (errno(rc)) {
3118 .SUCCESS => return out_buffer[0..@bitCast(usize, rc)],
3118 .SUCCESS => return out_buffer[0..@as(usize, @bitCast(rc))],
31193119 .ACCES => return error.AccessDenied,
31203120 .FAULT => unreachable,
31213121 .INVAL => return error.NotLink,
......@@ -3227,7 +3227,7 @@ pub fn isatty(handle: fd_t) bool {
32273227 if (builtin.os.tag == .linux) {
32283228 while (true) {
32293229 var wsz: linux.winsize = undefined;
3230 const fd = @bitCast(usize, @as(isize, handle));
3230 const fd = @as(usize, @bitCast(@as(isize, handle)));
32313231 const rc = linux.syscall3(.ioctl, fd, linux.T.IOCGWINSZ, @intFromPtr(&wsz));
32323232 switch (linux.getErrno(rc)) {
32333233 .SUCCESS => return true,
......@@ -3271,14 +3271,14 @@ pub fn isCygwinPty(handle: fd_t) bool {
32713271 var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = [_]u8{0} ** (name_bytes_offset + num_name_bytes);
32723272
32733273 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);
32753275 switch (rc) {
32763276 .SUCCESS => {},
32773277 .INVALID_PARAMETER => unreachable,
32783278 else => return false,
32793279 }
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]));
32823282 const name_bytes = name_info_bytes[name_bytes_offset .. name_bytes_offset + @as(usize, name_info.FileNameLength)];
32833283 const name_wide = mem.bytesAsSlice(u16, name_bytes);
32843284 // 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
33253325 else
33263326 0;
33273327 const rc = try windows.WSASocketW(
3328 @bitCast(i32, domain),
3329 @bitCast(i32, filtered_sock_type),
3330 @bitCast(i32, protocol),
3328 @as(i32, @bitCast(domain)),
3329 @as(i32, @bitCast(filtered_sock_type)),
3330 @as(i32, @bitCast(protocol)),
33313331 null,
33323332 0,
33333333 flags,
......@@ -3353,7 +3353,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
33533353 const rc = system.socket(domain, filtered_sock_type, protocol);
33543354 switch (errno(rc)) {
33553355 .SUCCESS => {
3356 const fd = @intCast(fd_t, rc);
3356 const fd = @as(fd_t, @intCast(rc));
33573357 if (!have_sock_flags) {
33583358 try setSockFlags(fd, socket_type);
33593359 }
......@@ -3679,7 +3679,7 @@ pub fn accept(
36793679 } else {
36803680 switch (errno(rc)) {
36813681 .SUCCESS => {
3682 break @intCast(socket_t, rc);
3682 break @as(socket_t, @intCast(rc));
36833683 },
36843684 .INTR => continue,
36853685 .AGAIN => return error.WouldBlock,
......@@ -3723,7 +3723,7 @@ pub const EpollCreateError = error{
37233723pub fn epoll_create1(flags: u32) EpollCreateError!i32 {
37243724 const rc = system.epoll_create1(flags);
37253725 switch (errno(rc)) {
3726 .SUCCESS => return @intCast(i32, rc),
3726 .SUCCESS => return @as(i32, @intCast(rc)),
37273727 else => |err| return unexpectedErrno(err),
37283728
37293729 .INVAL => unreachable,
......@@ -3782,9 +3782,9 @@ pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*linux.epoll_event) EpollC
37823782pub fn epoll_wait(epfd: i32, events: []linux.epoll_event, timeout: i32) usize {
37833783 while (true) {
37843784 // 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);
37863786 switch (errno(rc)) {
3787 .SUCCESS => return @intCast(usize, rc),
3787 .SUCCESS => return @as(usize, @intCast(rc)),
37883788 .INTR => continue,
37893789 .BADF => unreachable,
37903790 .FAULT => unreachable,
......@@ -3803,7 +3803,7 @@ pub const EventFdError = error{
38033803pub fn eventfd(initval: u32, flags: u32) EventFdError!i32 {
38043804 const rc = system.eventfd(initval, flags);
38053805 switch (errno(rc)) {
3806 .SUCCESS => return @intCast(i32, rc),
3806 .SUCCESS => return @as(i32, @intCast(rc)),
38073807 else => |err| return unexpectedErrno(err),
38083808
38093809 .INVAL => unreachable, // invalid parameters
......@@ -3937,7 +3937,7 @@ pub const ConnectError = error{
39373937/// return error.WouldBlock when EAGAIN or EINPROGRESS is received.
39383938pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) ConnectError!void {
39393939 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)));
39413941 if (rc == 0) return;
39423942 switch (windows.ws2_32.WSAGetLastError()) {
39433943 .WSAEADDRINUSE => return error.AddressInUse,
......@@ -3992,10 +3992,10 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
39923992pub fn getsockoptError(sockfd: fd_t) ConnectError!void {
39933993 var err_code: i32 = undefined;
39943994 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);
39963996 assert(size == 4);
39973997 switch (errno(rc)) {
3998 .SUCCESS => switch (@enumFromInt(E, err_code)) {
3998 .SUCCESS => switch (@as(E, @enumFromInt(err_code))) {
39993999 .SUCCESS => return,
40004000 .ACCES => return error.PermissionDenied,
40014001 .PERM => return error.PermissionDenied,
......@@ -4035,13 +4035,13 @@ pub const WaitPidResult = struct {
40354035pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {
40364036 const Status = if (builtin.link_libc) c_int else u32;
40374037 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;
40394039 while (true) {
40404040 const rc = system.waitpid(pid, &status, coerced_flags);
40414041 switch (errno(rc)) {
40424042 .SUCCESS => return .{
4043 .pid = @intCast(pid_t, rc),
4044 .status = @bitCast(u32, status),
4043 .pid = @as(pid_t, @intCast(rc)),
4044 .status = @as(u32, @bitCast(status)),
40454045 },
40464046 .INTR => continue,
40474047 .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 {
40544054pub fn wait4(pid: pid_t, flags: u32, ru: ?*rusage) WaitPidResult {
40554055 const Status = if (builtin.link_libc) c_int else u32;
40564056 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;
40584058 while (true) {
40594059 const rc = system.wait4(pid, &status, coerced_flags, ru);
40604060 switch (errno(rc)) {
40614061 .SUCCESS => return .{
4062 .pid = @intCast(pid_t, rc),
4063 .status = @bitCast(u32, status),
4062 .pid = @as(pid_t, @intCast(rc)),
4063 .status = @as(u32, @bitCast(status)),
40644064 },
40654065 .INTR => continue,
40664066 .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{
41824182pub fn kqueue() KQueueError!i32 {
41834183 const rc = system.kqueue();
41844184 switch (errno(rc)) {
4185 .SUCCESS => return @intCast(i32, rc),
4185 .SUCCESS => return @as(i32, @intCast(rc)),
41864186 .MFILE => return error.ProcessFdQuotaExceeded,
41874187 .NFILE => return error.SystemFdQuotaExceeded,
41884188 else => |err| return unexpectedErrno(err),
......@@ -4223,7 +4223,7 @@ pub fn kevent(
42234223 timeout,
42244224 );
42254225 switch (errno(rc)) {
4226 .SUCCESS => return @intCast(usize, rc),
4226 .SUCCESS => return @as(usize, @intCast(rc)),
42274227 .ACCES => return error.AccessDenied,
42284228 .FAULT => unreachable,
42294229 .BADF => unreachable, // Always a race condition.
......@@ -4247,7 +4247,7 @@ pub const INotifyInitError = error{
42474247pub fn inotify_init1(flags: u32) INotifyInitError!i32 {
42484248 const rc = system.inotify_init1(flags);
42494249 switch (errno(rc)) {
4250 .SUCCESS => return @intCast(i32, rc),
4250 .SUCCESS => return @as(i32, @intCast(rc)),
42514251 .INVAL => unreachable,
42524252 .MFILE => return error.ProcessFdQuotaExceeded,
42534253 .NFILE => return error.SystemFdQuotaExceeded,
......@@ -4276,7 +4276,7 @@ pub fn inotify_add_watch(inotify_fd: i32, pathname: []const u8, mask: u32) INoti
42764276pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 {
42774277 const rc = system.inotify_add_watch(inotify_fd, pathname, mask);
42784278 switch (errno(rc)) {
4279 .SUCCESS => return @intCast(i32, rc),
4279 .SUCCESS => return @as(i32, @intCast(rc)),
42804280 .ACCES => return error.AccessDenied,
42814281 .BADF => unreachable,
42824282 .FAULT => unreachable,
......@@ -4319,7 +4319,7 @@ pub const MProtectError = error{
43194319pub fn mprotect(memory: []align(mem.page_size) u8, protection: u32) MProtectError!void {
43204320 assert(mem.isAligned(memory.len, mem.page_size));
43214321 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))) {
43234323 0b000 => windows.PAGE_NOACCESS,
43244324 0b001 => windows.PAGE_READONLY,
43254325 0b010 => unreachable, // +w -r not allowed
......@@ -4350,7 +4350,7 @@ pub const ForkError = error{SystemResources} || UnexpectedError;
43504350pub fn fork() ForkError!pid_t {
43514351 const rc = system.fork();
43524352 switch (errno(rc)) {
4353 .SUCCESS => return @intCast(pid_t, rc),
4353 .SUCCESS => return @as(pid_t, @intCast(rc)),
43544354 .AGAIN => return error.SystemResources,
43554355 .NOMEM => return error.SystemResources,
43564356 else => |err| return unexpectedErrno(err),
......@@ -4391,14 +4391,14 @@ pub fn mmap(
43914391) MMapError![]align(mem.page_size) u8 {
43924392 const mmap_sym = if (lfs64_abi) system.mmap64 else system.mmap;
43934393
4394 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
4394 const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
43954395 const rc = mmap_sym(ptr, length, prot, flags, fd, ioffset);
43964396 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];
4398 break :blk @enumFromInt(E, system._errno().*);
4397 if (rc != std.c.MAP.FAILED) return @as([*]align(mem.page_size) u8, @ptrCast(@alignCast(rc)))[0..length];
4398 break :blk @as(E, @enumFromInt(system._errno().*));
43994399 } else blk: {
44004400 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];
44024402 break :blk err;
44034403 };
44044404 switch (err) {
......@@ -4781,7 +4781,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
47814781 }
47824782 if (builtin.os.tag == .wasi and !builtin.link_libc) {
47834783 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)) {
47854785 .SUCCESS => return,
47864786 .BADF => unreachable, // always a race condition
47874787 .INVAL => return error.Unseekable,
......@@ -4795,7 +4795,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
47954795
47964796 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;
47974797
4798 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
4798 const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
47994799 switch (errno(lseek_sym(fd, ioffset, SEEK.SET))) {
48004800 .SUCCESS => return,
48014801 .BADF => unreachable, // always a race condition
......@@ -4811,7 +4811,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
48114811pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
48124812 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
48134813 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))) {
48154815 .SUCCESS => return,
48164816 .BADF => unreachable, // always a race condition
48174817 .INVAL => return error.Unseekable,
......@@ -4839,7 +4839,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
48394839 }
48404840 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;
48414841
4842 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
4842 const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
48434843 switch (errno(lseek_sym(fd, ioffset, SEEK.CUR))) {
48444844 .SUCCESS => return,
48454845 .BADF => unreachable, // always a race condition
......@@ -4855,7 +4855,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
48554855pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
48564856 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
48574857 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))) {
48594859 .SUCCESS => return,
48604860 .BADF => unreachable, // always a race condition
48614861 .INVAL => return error.Unseekable,
......@@ -4883,7 +4883,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
48834883 }
48844884 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;
48854885
4886 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
4886 const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
48874887 switch (errno(lseek_sym(fd, ioffset, SEEK.END))) {
48884888 .SUCCESS => return,
48894889 .BADF => unreachable, // always a race condition
......@@ -4929,7 +4929,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
49294929
49304930 const rc = lseek_sym(fd, 0, SEEK.CUR);
49314931 switch (errno(rc)) {
4932 .SUCCESS => return @bitCast(u64, rc),
4932 .SUCCESS => return @as(u64, @bitCast(rc)),
49334933 .BADF => unreachable, // always a race condition
49344934 .INVAL => return error.Unseekable,
49354935 .OVERFLOW => return error.Unseekable,
......@@ -4952,7 +4952,7 @@ pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) FcntlError!usize {
49524952 while (true) {
49534953 const rc = system.fcntl(fd, cmd, arg);
49544954 switch (errno(rc)) {
4955 .SUCCESS => return @intCast(usize, rc),
4955 .SUCCESS => return @as(usize, @intCast(rc)),
49564956 .INTR => continue,
49574957 .AGAIN, .ACCES => return error.Locked,
49584958 .BADF => unreachable,
......@@ -5122,7 +5122,7 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
51225122
51235123 return getFdPath(fd, out_buffer);
51245124 }
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().*))) {
51265126 .SUCCESS => unreachable,
51275127 .INVAL => unreachable,
51285128 .BADF => unreachable,
......@@ -5269,7 +5269,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
52695269 };
52705270 var i: usize = 0;
52715271 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]));
52735273 if (kf.fd == fd) {
52745274 len = mem.indexOfScalar(u8, &kf.path, 0) orelse MAX_PATH_BYTES;
52755275 if (len == 0) return error.NameTooLong;
......@@ -5277,7 +5277,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
52775277 @memcpy(result, kf.path[0..len]);
52785278 return result;
52795279 }
5280 i += @intCast(usize, kf.structsize);
5280 i += @as(usize, @intCast(kf.structsize));
52815281 }
52825282 return error.InvalidHandle;
52835283 }
......@@ -5357,22 +5357,22 @@ pub fn dl_iterate_phdr(
53575357 if (builtin.link_libc) {
53585358 switch (system.dl_iterate_phdr(struct {
53595359 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));
53615361 callback(info, size, context_ptr.*) catch |err| return @intFromError(err);
53625362 return 0;
53635363 }
5364 }.callbackC, @ptrFromInt(?*anyopaque, @intFromPtr(&context)))) {
5364 }.callbackC, @as(?*anyopaque, @ptrFromInt(@intFromPtr(&context))))) {
53655365 0 => return,
5366 else => |err| return @errSetCast(Error, @errorFromInt(@intCast(u16, err))), // TODO don't hardcode u16
5366 else => |err| return @as(Error, @errSetCast(@errorFromInt(@as(u16, @intCast(err))))), // TODO don't hardcode u16
53675367 }
53685368 }
53695369
53705370 const elf_base = std.process.getBaseAddress();
5371 const ehdr = @ptrFromInt(*elf.Ehdr, elf_base);
5371 const ehdr = @as(*elf.Ehdr, @ptrFromInt(elf_base));
53725372 // Make sure the base address points to an ELF image.
53735373 assert(mem.eql(u8, ehdr.e_ident[0..4], elf.MAGIC));
53745374 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
53775377 var it = dl.linkmap_iterator(phdrs) catch unreachable;
53785378
......@@ -5406,12 +5406,12 @@ pub fn dl_iterate_phdr(
54065406 var dlpi_phnum: u16 = undefined;
54075407
54085408 if (entry.l_addr != 0) {
5409 const elf_header = @ptrFromInt(*elf.Ehdr, entry.l_addr);
5410 dlpi_phdr = @ptrFromInt([*]elf.Phdr, entry.l_addr + elf_header.e_phoff);
5409 const elf_header = @as(*elf.Ehdr, @ptrFromInt(entry.l_addr));
5410 dlpi_phdr = @as([*]elf.Phdr, @ptrFromInt(entry.l_addr + elf_header.e_phoff));
54115411 dlpi_phnum = elf_header.e_phnum;
54125412 } else {
54135413 // 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));
54155415 dlpi_phnum = ehdr.e_phnum;
54165416 }
54175417
......@@ -5433,11 +5433,11 @@ pub const ClockGetTimeError = error{UnsupportedClock} || UnexpectedError;
54335433pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
54345434 if (builtin.os.tag == .wasi and !builtin.link_libc) {
54355435 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)) {
54375437 .SUCCESS => {
54385438 tp.* = .{
5439 .tv_sec = @intCast(i64, ts / std.time.ns_per_s),
5440 .tv_nsec = @intCast(isize, ts % std.time.ns_per_s),
5439 .tv_sec = @as(i64, @intCast(ts / std.time.ns_per_s)),
5440 .tv_nsec = @as(isize, @intCast(ts % std.time.ns_per_s)),
54415441 };
54425442 },
54435443 .INVAL => return error.UnsupportedClock,
......@@ -5453,8 +5453,8 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
54535453 const ft64 = (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
54545454 const ft_per_s = std.time.ns_per_s / 100;
54555455 tp.* = .{
5456 .tv_sec = @intCast(i64, ft64 / ft_per_s) + std.time.epoch.windows,
5457 .tv_nsec = @intCast(c_long, ft64 % ft_per_s) * 100,
5456 .tv_sec = @as(i64, @intCast(ft64 / ft_per_s)) + std.time.epoch.windows,
5457 .tv_nsec = @as(c_long, @intCast(ft64 % ft_per_s)) * 100,
54585458 };
54595459 return;
54605460 } else {
......@@ -5474,10 +5474,10 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
54745474pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
54755475 if (builtin.os.tag == .wasi and !builtin.link_libc) {
54765476 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)) {
54785478 .SUCCESS => res.* = .{
5479 .tv_sec = @intCast(i64, ts / std.time.ns_per_s),
5480 .tv_nsec = @intCast(isize, ts % std.time.ns_per_s),
5479 .tv_sec = @as(i64, @intCast(ts / std.time.ns_per_s)),
5480 .tv_nsec = @as(isize, @intCast(ts % std.time.ns_per_s)),
54815481 },
54825482 .INVAL => return error.UnsupportedClock,
54835483 else => |err| return unexpectedErrno(err),
......@@ -5747,7 +5747,7 @@ pub fn res_mkquery(
57475747 // TODO determine the circumstances for this and whether or
57485748 // not this should be an error.
57495749 if (j - i - 1 > 62) unreachable;
5750 q[i - 1] = @intCast(u8, j - i);
5750 q[i - 1] = @as(u8, @intCast(j - i));
57515751 }
57525752 q[i + 1] = ty;
57535753 q[i + 3] = class;
......@@ -5756,10 +5756,10 @@ pub fn res_mkquery(
57565756 var ts: timespec = undefined;
57575757 clock_gettime(CLOCK.REALTIME, &ts) catch {};
57585758 const UInt = std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(ts.tv_nsec)));
5759 const unsec = @bitCast(UInt, ts.tv_nsec);
5760 const id = @truncate(u32, unsec + unsec / 65536);
5761 q[0] = @truncate(u8, id / 256);
5762 q[1] = @truncate(u8, id);
5759 const unsec = @as(UInt, @bitCast(ts.tv_nsec));
5760 const id = @as(u32, @truncate(unsec + unsec / 65536));
5761 q[0] = @as(u8, @truncate(id / 256));
5762 q[1] = @as(u8, @truncate(id));
57635763
57645764 @memcpy(buf[0..n], q[0..n]);
57655765 return n;
......@@ -5865,11 +5865,11 @@ pub fn sendmsg(
58655865 else => |err| return windows.unexpectedWSAError(err),
58665866 }
58675867 } else {
5868 return @intCast(usize, rc);
5868 return @as(usize, @intCast(rc));
58695869 }
58705870 } else {
58715871 switch (errno(rc)) {
5872 .SUCCESS => return @intCast(usize, rc),
5872 .SUCCESS => return @as(usize, @intCast(rc)),
58735873
58745874 .ACCES => return error.AccessDenied,
58755875 .AGAIN => return error.WouldBlock,
......@@ -5965,13 +5965,13 @@ pub fn sendto(
59655965 .WSANOTINITIALISED => unreachable, // A successful WSAStartup call must occur before using this function.
59665966 else => |err| return windows.unexpectedWSAError(err),
59675967 },
5968 else => |rc| return @intCast(usize, rc),
5968 else => |rc| return @as(usize, @intCast(rc)),
59695969 }
59705970 }
59715971 while (true) {
59725972 const rc = system.sendto(sockfd, buf.ptr, buf.len, flags, dest_addr, addrlen);
59735973 switch (errno(rc)) {
5974 .SUCCESS => return @intCast(usize, rc),
5974 .SUCCESS => return @as(usize, @intCast(rc)),
59755975
59765976 .ACCES => return error.AccessDenied,
59775977 .AGAIN => return error.WouldBlock,
......@@ -6125,16 +6125,16 @@ pub fn sendfile(
61256125 // Here we match BSD behavior, making a zero count value send as many bytes as possible.
61266126 const adjusted_count_tmp = if (in_len == 0) max_count else @min(in_len, @as(size_t, max_count));
61276127 // 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
61306130 const sendfile_sym = if (lfs64_abi) system.sendfile64 else system.sendfile;
61316131
61326132 while (true) {
6133 var offset: off_t = @bitCast(off_t, in_offset);
6133 var offset: off_t = @as(off_t, @bitCast(in_offset));
61346134 const rc = sendfile_sym(out_fd, in_fd, &offset, adjusted_count);
61356135 switch (errno(rc)) {
61366136 .SUCCESS => {
6137 const amt = @bitCast(usize, rc);
6137 const amt = @as(usize, @bitCast(rc));
61386138 total_written += amt;
61396139 if (in_len == 0 and amt == 0) {
61406140 // We have detected EOF from `in_fd`.
......@@ -6209,9 +6209,9 @@ pub fn sendfile(
62096209
62106210 while (true) {
62116211 var sbytes: off_t = undefined;
6212 const offset = @bitCast(off_t, in_offset);
6212 const offset = @as(off_t, @bitCast(in_offset));
62136213 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));
62156215 switch (err) {
62166216 .SUCCESS => return amt,
62176217
......@@ -6286,13 +6286,13 @@ pub fn sendfile(
62866286
62876287 const adjusted_count_temporary = @min(in_len, @as(u63, max_count));
62886288 // 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
62916291 while (true) {
62926292 var sbytes: off_t = adjusted_count;
6293 const signed_offset = @bitCast(i64, in_offset);
6293 const signed_offset = @as(i64, @bitCast(in_offset));
62946294 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));
62966296 switch (err) {
62976297 .SUCCESS => return amt,
62986298
......@@ -6342,7 +6342,7 @@ pub fn sendfile(
63426342 // Here we match BSD behavior, making a zero count value send as many bytes as possible.
63436343 const adjusted_count_tmp = if (in_len == 0) buf.len else @min(buf.len, in_len);
63446344 // 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));
63466346 const amt_read = try pread(in_fd, buf[0..adjusted_count], in_offset);
63476347 if (amt_read == 0) {
63486348 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
64136413 std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok) and
64146414 has_copy_file_range_syscall.load(.Monotonic)))
64156415 {
6416 var off_in_copy = @bitCast(i64, off_in);
6417 var off_out_copy = @bitCast(i64, off_out);
6416 var off_in_copy = @as(i64, @bitCast(off_in));
6417 var off_out_copy = @as(i64, @bitCast(off_out));
64186418
64196419 while (true) {
64206420 const rc = system.copy_file_range(fd_in, &off_in_copy, fd_out, &off_out_copy, len, flags);
64216421 if (builtin.os.tag == .freebsd) {
64226422 switch (system.getErrno(rc)) {
6423 .SUCCESS => return @intCast(usize, rc),
6423 .SUCCESS => return @as(usize, @intCast(rc)),
64246424 .BADF => return error.FilesOpenedWithWrongFlags,
64256425 .FBIG => return error.FileTooBig,
64266426 .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
64336433 }
64346434 } else { // assume linux
64356435 switch (system.getErrno(rc)) {
6436 .SUCCESS => return @intCast(usize, rc),
6436 .SUCCESS => return @as(usize, @intCast(rc)),
64376437 .BADF => return error.FilesOpenedWithWrongFlags,
64386438 .FBIG => return error.FileTooBig,
64396439 .IO => return error.InputOutput,
......@@ -6486,11 +6486,11 @@ pub fn poll(fds: []pollfd, timeout: i32) PollError!usize {
64866486 else => |err| return windows.unexpectedWSAError(err),
64876487 }
64886488 } else {
6489 return @intCast(usize, rc);
6489 return @as(usize, @intCast(rc));
64906490 }
64916491 } else {
64926492 switch (errno(rc)) {
6493 .SUCCESS => return @intCast(usize, rc),
6493 .SUCCESS => return @as(usize, @intCast(rc)),
64946494 .FAULT => unreachable,
64956495 .INTR => continue,
64966496 .INVAL => unreachable,
......@@ -6520,7 +6520,7 @@ pub fn ppoll(fds: []pollfd, timeout: ?*const timespec, mask: ?*const sigset_t) P
65206520 const fds_count = math.cast(nfds_t, fds.len) orelse return error.SystemResources;
65216521 const rc = system.ppoll(fds.ptr, fds_count, ts_ptr, mask);
65226522 switch (errno(rc)) {
6523 .SUCCESS => return @intCast(usize, rc),
6523 .SUCCESS => return @as(usize, @intCast(rc)),
65246524 .FAULT => unreachable,
65256525 .INTR => return error.SignalInterrupt,
65266526 .INVAL => unreachable,
......@@ -6585,11 +6585,11 @@ pub fn recvfrom(
65856585 else => |err| return windows.unexpectedWSAError(err),
65866586 }
65876587 } else {
6588 return @intCast(usize, rc);
6588 return @as(usize, @intCast(rc));
65896589 }
65906590 } else {
65916591 switch (errno(rc)) {
6592 .SUCCESS => return @intCast(usize, rc),
6592 .SUCCESS => return @as(usize, @intCast(rc)),
65936593 .BADF => unreachable, // always a race condition
65946594 .FAULT => unreachable,
65956595 .INVAL => unreachable,
......@@ -6681,7 +6681,7 @@ pub const SetSockOptError = error{
66816681/// Set a socket's options.
66826682pub fn setsockopt(fd: socket_t, level: u32, optname: u32, opt: []const u8) SetSockOptError!void {
66836683 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)));
66856685 if (rc == windows.ws2_32.SOCKET_ERROR) {
66866686 switch (windows.ws2_32.WSAGetLastError()) {
66876687 .WSANOTINITIALISED => unreachable,
......@@ -6694,7 +6694,7 @@ pub fn setsockopt(fd: socket_t, level: u32, optname: u32, opt: []const u8) SetSo
66946694 }
66956695 return;
66966696 } 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))))) {
66986698 .SUCCESS => {},
66996699 .BADF => unreachable, // always a race condition
67006700 .NOTSOCK => unreachable, // always a race condition
......@@ -6731,7 +6731,7 @@ pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {
67316731 const getErrno = if (use_c) std.c.getErrno else linux.getErrno;
67326732 const rc = sys.memfd_create(name, flags);
67336733 switch (getErrno(rc)) {
6734 .SUCCESS => return @intCast(fd_t, rc),
6734 .SUCCESS => return @as(fd_t, @intCast(rc)),
67356735 .FAULT => unreachable, // name has invalid memory
67366736 .INVAL => unreachable, // name/flags are faulty
67376737 .NFILE => return error.SystemFdQuotaExceeded,
......@@ -6881,7 +6881,7 @@ pub fn ioctl_SIOCGIFINDEX(fd: fd_t, ifr: *ifreq) IoCtl_SIOCGIFINDEX_Error!void {
68816881pub fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) !fd_t {
68826882 const rc = system.signalfd(fd, mask, flags);
68836883 switch (errno(rc)) {
6884 .SUCCESS => return @intCast(fd_t, rc),
6884 .SUCCESS => return @as(fd_t, @intCast(rc)),
68856885 .BADF, .INVAL => unreachable,
68866886 .NFILE => return error.SystemFdQuotaExceeded,
68876887 .NOMEM => return error.SystemResources,
......@@ -6989,7 +6989,7 @@ pub fn prctl(option: PR, args: anytype) PrctlError!u31 {
69896989
69906990 const rc = system.prctl(@intFromEnum(option), buf[0], buf[1], buf[2], buf[3]);
69916991 switch (errno(rc)) {
6992 .SUCCESS => return @intCast(u31, rc),
6992 .SUCCESS => return @as(u31, @intCast(rc)),
69936993 .ACCES => return error.AccessDenied,
69946994 .BADF => return error.InvalidFileDescriptor,
69956995 .FAULT => return error.InvalidAddress,
......@@ -7170,7 +7170,7 @@ pub fn perf_event_open(
71707170) PerfEventOpenError!fd_t {
71717171 const rc = system.perf_event_open(attr, pid, cpu, group_fd, flags);
71727172 switch (errno(rc)) {
7173 .SUCCESS => return @intCast(fd_t, rc),
7173 .SUCCESS => return @as(fd_t, @intCast(rc)),
71747174 .@"2BIG" => return error.TooBig,
71757175 .ACCES => return error.PermissionDenied,
71767176 .BADF => unreachable, // group_fd file descriptor is not valid.
......@@ -7205,7 +7205,7 @@ pub const TimerFdSetError = TimerFdGetError || error{Canceled};
72057205pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t {
72067206 var rc = linux.timerfd_create(clokid, flags);
72077207 return switch (errno(rc)) {
7208 .SUCCESS => @intCast(fd_t, rc),
7208 .SUCCESS => @as(fd_t, @intCast(rc)),
72097209 .INVAL => unreachable,
72107210 .MFILE => return error.ProcessFdQuotaExceeded,
72117211 .NFILE => return error.SystemFdQuotaExceeded,
......@@ -7267,7 +7267,7 @@ pub fn ptrace(request: u32, pid: pid_t, addr: usize, signal: usize) PtraceError!
72677267 .macos, .ios, .tvos, .watchos => switch (errno(darwin.ptrace(
72687268 math.cast(i32, request) orelse return error.Overflow,
72697269 pid,
7270 @ptrFromInt(?[*]u8, addr),
7270 @as(?[*]u8, @ptrFromInt(addr)),
72717271 math.cast(i32, signal) orelse return error.Overflow,
72727272 ))) {
72737273 .SUCCESS => {},
lib/std/os/linux.zig+258-258
......@@ -175,62 +175,62 @@ const require_aligned_register_pair =
175175// Split a 64bit value into a {LSB,MSB} pair.
176176// The LE/BE variants specify the endianness to assume.
177177fn splitValueLE64(val: i64) [2]u32 {
178 const u = @bitCast(u64, val);
178 const u = @as(u64, @bitCast(val));
179179 return [2]u32{
180 @truncate(u32, u),
181 @truncate(u32, u >> 32),
180 @as(u32, @truncate(u)),
181 @as(u32, @truncate(u >> 32)),
182182 };
183183}
184184fn splitValueBE64(val: i64) [2]u32 {
185 const u = @bitCast(u64, val);
185 const u = @as(u64, @bitCast(val));
186186 return [2]u32{
187 @truncate(u32, u >> 32),
188 @truncate(u32, u),
187 @as(u32, @truncate(u >> 32)),
188 @as(u32, @truncate(u)),
189189 };
190190}
191191fn splitValue64(val: i64) [2]u32 {
192 const u = @bitCast(u64, val);
192 const u = @as(u64, @bitCast(val));
193193 switch (native_endian) {
194194 .Little => return [2]u32{
195 @truncate(u32, u),
196 @truncate(u32, u >> 32),
195 @as(u32, @truncate(u)),
196 @as(u32, @truncate(u >> 32)),
197197 },
198198 .Big => return [2]u32{
199 @truncate(u32, u >> 32),
200 @truncate(u32, u),
199 @as(u32, @truncate(u >> 32)),
200 @as(u32, @truncate(u)),
201201 },
202202 }
203203}
204204
205205/// Get the errno from a syscall return value, or 0 for no error.
206206pub fn getErrno(r: usize) E {
207 const signed_r = @bitCast(isize, r);
207 const signed_r = @as(isize, @bitCast(r));
208208 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));
210210}
211211
212212pub fn dup(old: i32) usize {
213 return syscall1(.dup, @bitCast(usize, @as(isize, old)));
213 return syscall1(.dup, @as(usize, @bitCast(@as(isize, old))));
214214}
215215
216216pub fn dup2(old: i32, new: i32) usize {
217217 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))));
219219 } else {
220220 if (old == new) {
221221 if (std.debug.runtime_safety) {
222 const rc = syscall2(.fcntl, @bitCast(usize, @as(isize, old)), F.GETFD);
223 if (@bitCast(isize, rc) < 0) return rc;
222 const rc = syscall2(.fcntl, @as(usize, @bitCast(@as(isize, old))), F.GETFD);
223 if (@as(isize, @bitCast(rc)) < 0) return rc;
224224 }
225 return @intCast(usize, old);
225 return @as(usize, @intCast(old));
226226 } 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);
228228 }
229229 }
230230}
231231
232232pub 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);
234234}
235235
236236pub fn chdir(path: [*:0]const u8) usize {
......@@ -238,7 +238,7 @@ pub fn chdir(path: [*:0]const u8) usize {
238238}
239239
240240pub 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))));
242242}
243243
244244pub fn chroot(path: [*:0]const u8) usize {
......@@ -273,7 +273,7 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize {
273273}
274274
275275pub 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);
277277}
278278
279279pub 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 {
282282 const length_halves = splitValue64(length);
283283 return syscall6(
284284 .fallocate,
285 @bitCast(usize, @as(isize, fd)),
286 @bitCast(usize, @as(isize, mode)),
285 @as(usize, @bitCast(@as(isize, fd))),
286 @as(usize, @bitCast(@as(isize, mode))),
287287 offset_halves[0],
288288 offset_halves[1],
289289 length_halves[0],
......@@ -292,20 +292,20 @@ pub fn fallocate(fd: i32, mode: i32, offset: i64, length: i64) usize {
292292 } else {
293293 return syscall4(
294294 .fallocate,
295 @bitCast(usize, @as(isize, fd)),
296 @bitCast(usize, @as(isize, mode)),
297 @bitCast(u64, offset),
298 @bitCast(u64, length),
295 @as(usize, @bitCast(@as(isize, fd))),
296 @as(usize, @bitCast(@as(isize, mode))),
297 @as(u64, @bitCast(offset)),
298 @as(u64, @bitCast(length)),
299299 );
300300 }
301301}
302302
303303pub 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));
305305}
306306
307307pub 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)));
309309}
310310
311311pub fn getcwd(buf: [*]u8, size: usize) usize {
......@@ -315,7 +315,7 @@ pub fn getcwd(buf: [*]u8, size: usize) usize {
315315pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {
316316 return syscall3(
317317 .getdents,
318 @bitCast(usize, @as(isize, fd)),
318 @as(usize, @bitCast(@as(isize, fd))),
319319 @intFromPtr(dirp),
320320 @min(len, maxInt(c_int)),
321321 );
......@@ -324,7 +324,7 @@ pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {
324324pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize {
325325 return syscall3(
326326 .getdents64,
327 @bitCast(usize, @as(isize, fd)),
327 @as(usize, @bitCast(@as(isize, fd))),
328328 @intFromPtr(dirp),
329329 @min(len, maxInt(c_int)),
330330 );
......@@ -335,35 +335,35 @@ pub fn inotify_init1(flags: u32) usize {
335335}
336336
337337pub 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);
339339}
340340
341341pub 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))));
343343}
344344
345345pub fn readlink(noalias path: [*:0]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
346346 if (@hasField(SYS, "readlink")) {
347347 return syscall3(.readlink, @intFromPtr(path), @intFromPtr(buf_ptr), buf_len);
348348 } 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);
350350 }
351351}
352352
353353pub 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);
355355}
356356
357357pub fn mkdir(path: [*:0]const u8, mode: u32) usize {
358358 if (@hasField(SYS, "mkdir")) {
359359 return syscall2(.mkdir, @intFromPtr(path), mode);
360360 } 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);
362362 }
363363}
364364
365365pub 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);
367367}
368368
369369pub 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 {
375375}
376376
377377pub 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);
379379}
380380
381381pub 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
394394 if (@hasField(SYS, "mmap2")) {
395395 // Make sure the offset is also specified in multiples of page size
396396 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
399399 return syscall6(
400400 .mmap2,
......@@ -402,8 +402,8 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
402402 length,
403403 prot,
404404 flags,
405 @bitCast(usize, @as(isize, fd)),
406 @truncate(usize, @bitCast(u64, offset) / MMAP2_UNIT),
405 @as(usize, @bitCast(@as(isize, fd))),
406 @as(usize, @truncate(@as(u64, @bitCast(offset)) / MMAP2_UNIT)),
407407 );
408408 } else {
409409 return syscall6(
......@@ -412,8 +412,8 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
412412 length,
413413 prot,
414414 flags,
415 @bitCast(usize, @as(isize, fd)),
416 @bitCast(u64, offset),
415 @as(usize, @bitCast(@as(isize, fd))),
416 @as(u64, @bitCast(offset)),
417417 );
418418 }
419419}
......@@ -429,7 +429,7 @@ pub const MSF = struct {
429429};
430430
431431pub 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)));
433433}
434434
435435pub fn munmap(address: [*]const u8, length: usize) usize {
......@@ -438,7 +438,7 @@ pub fn munmap(address: [*]const u8, length: usize) usize {
438438
439439pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {
440440 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)));
442442 } else {
443443 return syscall5(
444444 .ppoll,
......@@ -462,69 +462,69 @@ pub fn ppoll(fds: [*]pollfd, n: nfds_t, timeout: ?*timespec, sigmask: ?*const si
462462}
463463
464464pub 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);
466466}
467467
468468pub 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));
470470 return syscall5(
471471 .preadv,
472 @bitCast(usize, @as(isize, fd)),
472 @as(usize, @bitCast(@as(isize, fd))),
473473 @intFromPtr(iov),
474474 count,
475475 // Kernel expects the offset is split into largest natural word-size.
476476 // See following link for detail:
477477 // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=601cc11d054ae4b5e9b5babec3d8e4667a2cb9b5
478 @truncate(usize, offset_u),
479 if (usize_bits < 64) @truncate(usize, offset_u >> 32) else 0,
478 @as(usize, @truncate(offset_u)),
479 if (usize_bits < 64) @as(usize, @truncate(offset_u >> 32)) else 0,
480480 );
481481}
482482
483483pub 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));
485485 return syscall6(
486486 .preadv2,
487 @bitCast(usize, @as(isize, fd)),
487 @as(usize, @bitCast(@as(isize, fd))),
488488 @intFromPtr(iov),
489489 count,
490490 // See comments in preadv
491 @truncate(usize, offset_u),
492 if (usize_bits < 64) @truncate(usize, offset_u >> 32) else 0,
491 @as(usize, @truncate(offset_u)),
492 if (usize_bits < 64) @as(usize, @truncate(offset_u >> 32)) else 0,
493493 flags,
494494 );
495495}
496496
497497pub 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);
499499}
500500
501501pub 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);
503503}
504504
505505pub 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));
507507 return syscall5(
508508 .pwritev,
509 @bitCast(usize, @as(isize, fd)),
509 @as(usize, @bitCast(@as(isize, fd))),
510510 @intFromPtr(iov),
511511 count,
512512 // See comments in preadv
513 @truncate(usize, offset_u),
514 if (usize_bits < 64) @truncate(usize, offset_u >> 32) else 0,
513 @as(usize, @truncate(offset_u)),
514 if (usize_bits < 64) @as(usize, @truncate(offset_u >> 32)) else 0,
515515 );
516516}
517517
518518pub 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));
520520 return syscall6(
521521 .pwritev2,
522 @bitCast(usize, @as(isize, fd)),
522 @as(usize, @bitCast(@as(isize, fd))),
523523 @intFromPtr(iov),
524524 count,
525525 // See comments in preadv
526 @truncate(usize, offset_u),
527 if (usize_bits < 64) @truncate(usize, offset_u >> 32) else 0,
526 @as(usize, @truncate(offset_u)),
527 if (usize_bits < 64) @as(usize, @truncate(offset_u >> 32)) else 0,
528528 flags,
529529 );
530530}
......@@ -533,7 +533,7 @@ pub fn rmdir(path: [*:0]const u8) usize {
533533 if (@hasField(SYS, "rmdir")) {
534534 return syscall1(.rmdir, @intFromPtr(path));
535535 } 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);
537537 }
538538}
539539
......@@ -541,12 +541,12 @@ pub fn symlink(existing: [*:0]const u8, new: [*:0]const u8) usize {
541541 if (@hasField(SYS, "symlink")) {
542542 return syscall2(.symlink, @intFromPtr(existing), @intFromPtr(new));
543543 } 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));
545545 }
546546}
547547
548548pub 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));
550550}
551551
552552pub 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 {
555555 if (require_aligned_register_pair) {
556556 return syscall6(
557557 .pread64,
558 @bitCast(usize, @as(isize, fd)),
558 @as(usize, @bitCast(@as(isize, fd))),
559559 @intFromPtr(buf),
560560 count,
561561 0,
......@@ -565,7 +565,7 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: i64) usize {
565565 } else {
566566 return syscall5(
567567 .pread64,
568 @bitCast(usize, @as(isize, fd)),
568 @as(usize, @bitCast(@as(isize, fd))),
569569 @intFromPtr(buf),
570570 count,
571571 offset_halves[0],
......@@ -580,10 +580,10 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: i64) usize {
580580 .pread;
581581 return syscall4(
582582 syscall_number,
583 @bitCast(usize, @as(isize, fd)),
583 @as(usize, @bitCast(@as(isize, fd))),
584584 @intFromPtr(buf),
585585 count,
586 @bitCast(u64, offset),
586 @as(u64, @bitCast(offset)),
587587 );
588588 }
589589}
......@@ -592,12 +592,12 @@ pub fn access(path: [*:0]const u8, mode: u32) usize {
592592 if (@hasField(SYS, "access")) {
593593 return syscall2(.access, @intFromPtr(path), mode);
594594 } 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);
596596 }
597597}
598598
599599pub 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);
601601}
602602
603603pub fn pipe(fd: *[2]i32) usize {
......@@ -615,7 +615,7 @@ pub fn pipe2(fd: *[2]i32, flags: u32) usize {
615615}
616616
617617pub 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);
619619}
620620
621621pub fn ftruncate(fd: i32, length: i64) usize {
......@@ -624,7 +624,7 @@ pub fn ftruncate(fd: i32, length: i64) usize {
624624 if (require_aligned_register_pair) {
625625 return syscall4(
626626 .ftruncate64,
627 @bitCast(usize, @as(isize, fd)),
627 @as(usize, @bitCast(@as(isize, fd))),
628628 0,
629629 length_halves[0],
630630 length_halves[1],
......@@ -632,7 +632,7 @@ pub fn ftruncate(fd: i32, length: i64) usize {
632632 } else {
633633 return syscall3(
634634 .ftruncate64,
635 @bitCast(usize, @as(isize, fd)),
635 @as(usize, @bitCast(@as(isize, fd))),
636636 length_halves[0],
637637 length_halves[1],
638638 );
......@@ -640,8 +640,8 @@ pub fn ftruncate(fd: i32, length: i64) usize {
640640 } else {
641641 return syscall2(
642642 .ftruncate,
643 @bitCast(usize, @as(isize, fd)),
644 @bitCast(usize, length),
643 @as(usize, @bitCast(@as(isize, fd))),
644 @as(usize, @bitCast(length)),
645645 );
646646 }
647647}
......@@ -653,7 +653,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: i64) usize {
653653 if (require_aligned_register_pair) {
654654 return syscall6(
655655 .pwrite64,
656 @bitCast(usize, @as(isize, fd)),
656 @as(usize, @bitCast(@as(isize, fd))),
657657 @intFromPtr(buf),
658658 count,
659659 0,
......@@ -663,7 +663,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: i64) usize {
663663 } else {
664664 return syscall5(
665665 .pwrite64,
666 @bitCast(usize, @as(isize, fd)),
666 @as(usize, @bitCast(@as(isize, fd))),
667667 @intFromPtr(buf),
668668 count,
669669 offset_halves[0],
......@@ -678,10 +678,10 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: i64) usize {
678678 .pwrite;
679679 return syscall4(
680680 syscall_number,
681 @bitCast(usize, @as(isize, fd)),
681 @as(usize, @bitCast(@as(isize, fd))),
682682 @intFromPtr(buf),
683683 count,
684 @bitCast(u64, offset),
684 @as(u64, @bitCast(offset)),
685685 );
686686 }
687687}
......@@ -690,9 +690,9 @@ pub fn rename(old: [*:0]const u8, new: [*:0]const u8) usize {
690690 if (@hasField(SYS, "rename")) {
691691 return syscall2(.rename, @intFromPtr(old), @intFromPtr(new));
692692 } 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));
694694 } 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);
696696 }
697697}
698698
......@@ -700,17 +700,17 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
700700 if (@hasField(SYS, "renameat")) {
701701 return syscall4(
702702 .renameat,
703 @bitCast(usize, @as(isize, oldfd)),
703 @as(usize, @bitCast(@as(isize, oldfd))),
704704 @intFromPtr(oldpath),
705 @bitCast(usize, @as(isize, newfd)),
705 @as(usize, @bitCast(@as(isize, newfd))),
706706 @intFromPtr(newpath),
707707 );
708708 } else {
709709 return syscall5(
710710 .renameat2,
711 @bitCast(usize, @as(isize, oldfd)),
711 @as(usize, @bitCast(@as(isize, oldfd))),
712712 @intFromPtr(oldpath),
713 @bitCast(usize, @as(isize, newfd)),
713 @as(usize, @bitCast(@as(isize, newfd))),
714714 @intFromPtr(newpath),
715715 0,
716716 );
......@@ -720,9 +720,9 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
720720pub fn renameat2(oldfd: i32, oldpath: [*:0]const u8, newfd: i32, newpath: [*:0]const u8, flags: u32) usize {
721721 return syscall5(
722722 .renameat2,
723 @bitCast(usize, @as(isize, oldfd)),
723 @as(usize, @bitCast(@as(isize, oldfd))),
724724 @intFromPtr(oldpath),
725 @bitCast(usize, @as(isize, newfd)),
725 @as(usize, @bitCast(@as(isize, newfd))),
726726 @intFromPtr(newpath),
727727 flags,
728728 );
......@@ -734,7 +734,7 @@ pub fn open(path: [*:0]const u8, flags: u32, perm: mode_t) usize {
734734 } else {
735735 return syscall4(
736736 .openat,
737 @bitCast(usize, @as(isize, AT.FDCWD)),
737 @as(usize, @bitCast(@as(isize, AT.FDCWD))),
738738 @intFromPtr(path),
739739 flags,
740740 perm,
......@@ -748,7 +748,7 @@ pub fn create(path: [*:0]const u8, perm: mode_t) usize {
748748
749749pub fn openat(dirfd: i32, path: [*:0]const u8, flags: u32, mode: mode_t) usize {
750750 // 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);
752752}
753753
754754/// See also `clone` (from the arch-specific include)
......@@ -762,11 +762,11 @@ pub fn clone2(flags: u32, child_stack_ptr: usize) usize {
762762}
763763
764764pub fn close(fd: i32) usize {
765 return syscall1(.close, @bitCast(usize, @as(isize, fd)));
765 return syscall1(.close, @as(usize, @bitCast(@as(isize, fd))));
766766}
767767
768768pub 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);
770770}
771771
772772pub 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 {
775775 } else {
776776 return syscall4(
777777 .fchmodat,
778 @bitCast(usize, @as(isize, AT.FDCWD)),
778 @as(usize, @bitCast(@as(isize, AT.FDCWD))),
779779 @intFromPtr(path),
780780 mode,
781781 0,
......@@ -785,14 +785,14 @@ pub fn chmod(path: [*:0]const u8, mode: mode_t) usize {
785785
786786pub fn fchown(fd: i32, owner: uid_t, group: gid_t) usize {
787787 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);
789789 } else {
790 return syscall3(.fchown, @bitCast(usize, @as(isize, fd)), owner, group);
790 return syscall3(.fchown, @as(usize, @bitCast(@as(isize, fd))), owner, group);
791791 }
792792}
793793
794794pub 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);
796796}
797797
798798/// 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 {
801801 // endianness.
802802 return syscall5(
803803 ._llseek,
804 @bitCast(usize, @as(isize, fd)),
805 @truncate(usize, offset >> 32),
806 @truncate(usize, offset),
804 @as(usize, @bitCast(@as(isize, fd))),
805 @as(usize, @truncate(offset >> 32)),
806 @as(usize, @truncate(offset)),
807807 @intFromPtr(result),
808808 whence,
809809 );
......@@ -811,16 +811,16 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {
811811
812812/// Can only be called on 64 bit systems. For 32 bit see `llseek`.
813813pub 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);
815815}
816816
817817pub fn exit(status: i32) noreturn {
818 _ = syscall1(.exit, @bitCast(usize, @as(isize, status)));
818 _ = syscall1(.exit, @as(usize, @bitCast(@as(isize, status))));
819819 unreachable;
820820}
821821
822822pub 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))));
824824 unreachable;
825825}
826826
......@@ -886,15 +886,15 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
886886}
887887
888888pub 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))));
890890}
891891
892892pub 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))));
894894}
895895
896896pub 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))));
898898}
899899
900900pub 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 {
903903 .link,
904904 @intFromPtr(oldpath),
905905 @intFromPtr(newpath),
906 @bitCast(usize, @as(isize, flags)),
906 @as(usize, @bitCast(@as(isize, flags))),
907907 );
908908 } else {
909909 return syscall5(
910910 .linkat,
911 @bitCast(usize, @as(isize, AT.FDCWD)),
911 @as(usize, @bitCast(@as(isize, AT.FDCWD))),
912912 @intFromPtr(oldpath),
913 @bitCast(usize, @as(isize, AT.FDCWD)),
913 @as(usize, @bitCast(@as(isize, AT.FDCWD))),
914914 @intFromPtr(newpath),
915 @bitCast(usize, @as(isize, flags)),
915 @as(usize, @bitCast(@as(isize, flags))),
916916 );
917917 }
918918}
......@@ -920,11 +920,11 @@ pub fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) usize {
920920pub fn linkat(oldfd: fd_t, oldpath: [*:0]const u8, newfd: fd_t, newpath: [*:0]const u8, flags: i32) usize {
921921 return syscall5(
922922 .linkat,
923 @bitCast(usize, @as(isize, oldfd)),
923 @as(usize, @bitCast(@as(isize, oldfd))),
924924 @intFromPtr(oldpath),
925 @bitCast(usize, @as(isize, newfd)),
925 @as(usize, @bitCast(@as(isize, newfd))),
926926 @intFromPtr(newpath),
927 @bitCast(usize, @as(isize, flags)),
927 @as(usize, @bitCast(@as(isize, flags))),
928928 );
929929}
930930
......@@ -932,22 +932,22 @@ pub fn unlink(path: [*:0]const u8) usize {
932932 if (@hasField(SYS, "unlink")) {
933933 return syscall1(.unlink, @intFromPtr(path));
934934 } 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);
936936 }
937937}
938938
939939pub 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);
941941}
942942
943943pub 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);
945945}
946946
947947pub fn wait4(pid: pid_t, status: *u32, flags: u32, usage: ?*rusage) usize {
948948 return syscall4(
949949 .wait4,
950 @bitCast(usize, @as(isize, pid)),
950 @as(usize, @bitCast(@as(isize, pid))),
951951 @intFromPtr(status),
952952 flags,
953953 @intFromPtr(usage),
......@@ -955,18 +955,18 @@ pub fn wait4(pid: pid_t, status: *u32, flags: u32, usage: ?*rusage) usize {
955955}
956956
957957pub 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);
959959}
960960
961961pub 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);
963963}
964964
965965pub 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))));
967967}
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
971971// We must follow the C calling convention when we call into the VDSO
972972const 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 {
975975 if (@hasDecl(VDSO, "CGT_SYM")) {
976976 const ptr = @atomicLoad(?*const anyopaque, &vdso_clock_gettime, .Unordered);
977977 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));
979979 const rc = f(clk_id, tp);
980980 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,
982982 else => {},
983983 }
984984 }
985985 }
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));
987987}
988988
989989fn 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)));
991991 // Note that we may not have a VDSO at all, update the stub address anyway
992992 // so that clock_gettime will fall back on the good old (and slow) syscall
993993 @atomicStore(?*const anyopaque, &vdso_clock_gettime, ptr, .Monotonic);
994994 // Call into the VDSO if available
995995 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));
997997 return f(clk, ts);
998998 }
999 return @bitCast(usize, -@as(isize, @intFromEnum(E.NOSYS)));
999 return @as(usize, @bitCast(-@as(isize, @intFromEnum(E.NOSYS))));
10001000}
10011001
10021002pub 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));
10041004}
10051005
10061006pub 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));
10081008}
10091009
10101010pub fn gettimeofday(tv: *timeval, tz: *timezone) usize {
......@@ -1053,33 +1053,33 @@ pub fn setregid(rgid: gid_t, egid: gid_t) usize {
10531053
10541054pub fn getuid() uid_t {
10551055 if (@hasField(SYS, "getuid32")) {
1056 return @intCast(uid_t, syscall0(.getuid32));
1056 return @as(uid_t, @intCast(syscall0(.getuid32)));
10571057 } else {
1058 return @intCast(uid_t, syscall0(.getuid));
1058 return @as(uid_t, @intCast(syscall0(.getuid)));
10591059 }
10601060}
10611061
10621062pub fn getgid() gid_t {
10631063 if (@hasField(SYS, "getgid32")) {
1064 return @intCast(gid_t, syscall0(.getgid32));
1064 return @as(gid_t, @intCast(syscall0(.getgid32)));
10651065 } else {
1066 return @intCast(gid_t, syscall0(.getgid));
1066 return @as(gid_t, @intCast(syscall0(.getgid)));
10671067 }
10681068}
10691069
10701070pub fn geteuid() uid_t {
10711071 if (@hasField(SYS, "geteuid32")) {
1072 return @intCast(uid_t, syscall0(.geteuid32));
1072 return @as(uid_t, @intCast(syscall0(.geteuid32)));
10731073 } else {
1074 return @intCast(uid_t, syscall0(.geteuid));
1074 return @as(uid_t, @intCast(syscall0(.geteuid)));
10751075 }
10761076}
10771077
10781078pub fn getegid() gid_t {
10791079 if (@hasField(SYS, "getegid32")) {
1080 return @intCast(gid_t, syscall0(.getegid32));
1080 return @as(gid_t, @intCast(syscall0(.getegid32)));
10811081 } else {
1082 return @intCast(gid_t, syscall0(.getegid));
1082 return @as(gid_t, @intCast(syscall0(.getegid)));
10831083 }
10841084}
10851085
......@@ -1154,11 +1154,11 @@ pub fn setgroups(size: usize, list: [*]const gid_t) usize {
11541154}
11551155
11561156pub fn getpid() pid_t {
1157 return @bitCast(pid_t, @truncate(u32, syscall0(.getpid)));
1157 return @as(pid_t, @bitCast(@as(u32, @truncate(syscall0(.getpid)))));
11581158}
11591159
11601160pub fn gettid() pid_t {
1161 return @bitCast(pid_t, @truncate(u32, syscall0(.gettid)));
1161 return @as(pid_t, @bitCast(@as(u32, @truncate(syscall0(.gettid)))));
11621162}
11631163
11641164pub 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
11821182 .handler = new.handler.handler,
11831183 .flags = new.flags | SA.RESTORER,
11841184 .mask = undefined,
1185 .restorer = @ptrCast(k_sigaction_funcs.restorer, restorer_fn),
1185 .restorer = @as(k_sigaction_funcs.restorer, @ptrCast(restorer_fn)),
11861186 };
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)));
11881188 }
11891189
11901190 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
11991199
12001200 if (oact) |old| {
12011201 old.handler.handler = oldksa.handler;
1202 old.flags = @truncate(c_uint, oldksa.flags);
1203 @memcpy(@ptrCast([*]u8, &old.mask)[0..mask_size], @ptrCast([*]const u8, &oldksa.mask));
1202 old.flags = @as(c_uint, @truncate(oldksa.flags));
1203 @memcpy(@as([*]u8, @ptrCast(&old.mask))[0..mask_size], @as([*]const u8, @ptrCast(&oldksa.mask)));
12041204 }
12051205
12061206 return 0;
......@@ -1211,28 +1211,28 @@ const usize_bits = @typeInfo(usize).Int.bits;
12111211pub fn sigaddset(set: *sigset_t, sig: u6) void {
12121212 const s = sig - 1;
12131213 // shift in musl: s&8*sizeof *set->__bits-1
1214 const shift = @intCast(u5, s & (usize_bits - 1));
1215 const val = @intCast(u32, 1) << shift;
1216 (set.*)[@intCast(usize, s) / usize_bits] |= val;
1214 const shift = @as(u5, @intCast(s & (usize_bits - 1)));
1215 const val = @as(u32, @intCast(1)) << shift;
1216 (set.*)[@as(usize, @intCast(s)) / usize_bits] |= val;
12171217}
12181218
12191219pub fn sigismember(set: *const sigset_t, sig: u6) bool {
12201220 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;
12221222}
12231223
12241224pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
12251225 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) });
12271227 }
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));
12291229}
12301230
12311231pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
12321232 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) });
12341234 }
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));
12361236}
12371237
12381238pub 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
12451245pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
12461246 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)) });
12481248 }
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)));
12501250}
12511251
12521252pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
12531253 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) });
12551255 }
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));
12571257}
12581258
12591259pub 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)));
12611261 const msg_usize = @intFromPtr(msg);
12621262 if (native_arch == .x86) {
12631263 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
12751275 var next_unsent: usize = 0;
12761276 for (msgvec[0..kvlen], 0..) |*msg, i| {
12771277 var size: i32 = 0;
1278 const msg_iovlen = @intCast(usize, msg.msg_hdr.msg_iovlen); // kernel side this is treated as unsigned
1278 const msg_iovlen = @as(usize, @intCast(msg.msg_hdr.msg_iovlen)); // kernel side this is treated as unsigned
12791279 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) {
12811281 // batch-send all messages up to the current message
12821282 if (next_unsent < i) {
12831283 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);
12851285 if (getErrno(r) != 0) return next_unsent;
12861286 if (r < batch_size) return next_unsent + r;
12871287 }
......@@ -1289,7 +1289,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
12891289 const r = sendmsg(fd, &msg.msg_hdr, flags);
12901290 if (getErrno(r) != 0) return r;
12911291 // 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));
12931293 next_unsent = i + 1;
12941294 break;
12951295 }
......@@ -1297,17 +1297,17 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
12971297 }
12981298 if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG.EOR)
12991299 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);
13011301 if (getErrno(r) != 0) return r;
13021302 return next_unsent + r;
13031303 }
13041304 return kvlen;
13051305 }
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);
13071307}
13081308
13091309pub 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)));
13111311 const addr_usize = @intFromPtr(addr);
13121312 if (native_arch == .x86) {
13131313 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 {
13171317}
13181318
13191319pub 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)));
13211321 const msg_usize = @intFromPtr(msg);
13221322 if (native_arch == .x86) {
13231323 return socketcall(SC.recvmsg, &[3]usize{ fd_usize, msg_usize, flags });
......@@ -1334,7 +1334,7 @@ pub fn recvfrom(
13341334 noalias addr: ?*sockaddr,
13351335 noalias alen: ?*socklen_t,
13361336) usize {
1337 const fd_usize = @bitCast(usize, @as(isize, fd));
1337 const fd_usize = @as(usize, @bitCast(@as(isize, fd)));
13381338 const buf_usize = @intFromPtr(buf);
13391339 const addr_usize = @intFromPtr(addr);
13401340 const alen_usize = @intFromPtr(alen);
......@@ -1347,46 +1347,46 @@ pub fn recvfrom(
13471347
13481348pub fn shutdown(fd: i32, how: i32) usize {
13491349 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))) });
13511351 }
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))));
13531353}
13541354
13551355pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
13561356 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)) });
13581358 }
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)));
13601360}
13611361
13621362pub fn listen(fd: i32, backlog: u32) usize {
13631363 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 });
13651365 }
1366 return syscall2(.listen, @bitCast(usize, @as(isize, fd)), backlog);
1366 return syscall2(.listen, @as(usize, @bitCast(@as(isize, fd))), backlog);
13671367}
13681368
13691369pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {
13701370 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)) });
13721372 }
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)));
13741374}
13751375
13761376pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize {
13771377 if (@hasField(SYS, "sendfile64")) {
13781378 return syscall4(
13791379 .sendfile64,
1380 @bitCast(usize, @as(isize, outfd)),
1381 @bitCast(usize, @as(isize, infd)),
1380 @as(usize, @bitCast(@as(isize, outfd))),
1381 @as(usize, @bitCast(@as(isize, infd))),
13821382 @intFromPtr(offset),
13831383 count,
13841384 );
13851385 } else {
13861386 return syscall4(
13871387 .sendfile,
1388 @bitCast(usize, @as(isize, outfd)),
1389 @bitCast(usize, @as(isize, infd)),
1388 @as(usize, @bitCast(@as(isize, outfd))),
1389 @as(usize, @bitCast(@as(isize, infd))),
13901390 @intFromPtr(offset),
13911391 count,
13921392 );
......@@ -1395,9 +1395,9 @@ pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize {
13951395
13961396pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: *[2]i32) usize {
13971397 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) });
13991399 }
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));
14011401}
14021402
14031403pub 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
14101410pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flags: u32) usize {
14111411 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 });
14131413 }
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);
14151415}
14161416
14171417pub fn fstat(fd: i32, stat_buf: *Stat) usize {
14181418 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));
14201420 } 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));
14221422 }
14231423}
14241424
......@@ -1440,9 +1440,9 @@ pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize {
14401440
14411441pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *Stat, flags: u32) usize {
14421442 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);
14441444 } 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);
14461446 }
14471447}
14481448
......@@ -1450,14 +1450,14 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S
14501450 if (@hasField(SYS, "statx")) {
14511451 return syscall5(
14521452 .statx,
1453 @bitCast(usize, @as(isize, dirfd)),
1453 @as(usize, @bitCast(@as(isize, dirfd))),
14541454 @intFromPtr(path),
14551455 flags,
14561456 mask,
14571457 @intFromPtr(statx_buf),
14581458 );
14591459 }
1460 return @bitCast(usize, -@as(isize, @intFromEnum(E.NOSYS)));
1460 return @as(usize, @bitCast(-@as(isize, @intFromEnum(E.NOSYS))));
14611461}
14621462
14631463pub fn listxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize {
......@@ -1513,9 +1513,9 @@ pub fn sched_yield() usize {
15131513}
15141514
15151515pub 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));
1517 if (@bitCast(isize, rc) < 0) return rc;
1518 if (rc < size) @memset(@ptrCast([*]u8, set)[rc..size], 0);
1516 const rc = syscall3(.sched_getaffinity, @as(usize, @bitCast(@as(isize, pid))), size, @intFromPtr(set));
1517 if (@as(isize, @bitCast(rc)) < 0) return rc;
1518 if (rc < size) @memset(@as([*]u8, @ptrCast(set))[rc..size], 0);
15191519 return 0;
15201520}
15211521
......@@ -1526,18 +1526,18 @@ pub fn getcpu(cpu: *u32, node: *u32) usize {
15261526pub fn sched_getcpu() usize {
15271527 var cpu: u32 = undefined;
15281528 const rc = syscall3(.getcpu, @intFromPtr(&cpu), 0, 0);
1529 if (@bitCast(isize, rc) < 0) return rc;
1530 return @intCast(usize, cpu);
1529 if (@as(isize, @bitCast(rc)) < 0) return rc;
1530 return @as(usize, @intCast(cpu));
15311531}
15321532
15331533/// libc has no wrapper for this syscall
15341534pub 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);
15361536}
15371537
15381538pub 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));
1540 if (@bitCast(isize, rc) < 0) return rc;
1539 const rc = syscall3(.sched_setaffinity, @as(usize, @bitCast(@as(isize, pid))), size, @intFromPtr(set));
1540 if (@as(isize, @bitCast(rc)) < 0) return rc;
15411541 return 0;
15421542}
15431543
......@@ -1550,7 +1550,7 @@ pub fn epoll_create1(flags: usize) usize {
15501550}
15511551
15521552pub 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));
15541554}
15551555
15561556pub 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
15601560pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*const sigset_t) usize {
15611561 return syscall6(
15621562 .epoll_pwait,
1563 @bitCast(usize, @as(isize, epoll_fd)),
1563 @as(usize, @bitCast(@as(isize, epoll_fd))),
15641564 @intFromPtr(events),
1565 @intCast(usize, maxevents),
1566 @bitCast(usize, @as(isize, timeout)),
1565 @as(usize, @intCast(maxevents)),
1566 @as(usize, @bitCast(@as(isize, timeout))),
15671567 @intFromPtr(sigmask),
15681568 @sizeOf(sigset_t),
15691569 );
......@@ -1574,7 +1574,7 @@ pub fn eventfd(count: u32, flags: u32) usize {
15741574}
15751575
15761576pub 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);
15781578}
15791579
15801580pub const itimerspec = extern struct {
......@@ -1583,11 +1583,11 @@ pub const itimerspec = extern struct {
15831583};
15841584
15851585pub 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));
15871587}
15881588
15891589pub 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));
15911591}
15921592
15931593pub const sigevent = extern struct {
......@@ -1609,8 +1609,8 @@ pub const timer_t = ?*anyopaque;
16091609
16101610pub fn timer_create(clockid: i32, sevp: *sigevent, timerid: *timer_t) usize {
16111611 var t: timer_t = undefined;
1612 const rc = syscall3(.timer_create, @bitCast(usize, @as(isize, clockid)), @intFromPtr(sevp), @intFromPtr(&t));
1613 if (@bitCast(isize, rc) < 0) return rc;
1612 const rc = syscall3(.timer_create, @as(usize, @bitCast(@as(isize, clockid))), @intFromPtr(sevp), @intFromPtr(&t));
1613 if (@as(isize, @bitCast(rc)) < 0) return rc;
16141614 timerid.* = t;
16151615 return rc;
16161616}
......@@ -1624,7 +1624,7 @@ pub fn timer_gettime(timerid: timer_t, curr_value: *itimerspec) usize {
16241624}
16251625
16261626pub 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));
16281628}
16291629
16301630// Flags for the 'setitimer' system call
......@@ -1635,11 +1635,11 @@ pub const ITIMER = enum(i32) {
16351635};
16361636
16371637pub 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));
16391639}
16401640
16411641pub 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));
16431643}
16441644
16451645pub fn unshare(flags: usize) usize {
......@@ -1667,11 +1667,11 @@ pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize {
16671667}
16681668
16691669pub 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);
16711671}
16721672
16731673pub 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);
16751675}
16761676
16771677pub 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 {
16791679}
16801680
16811681pub 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));
16831683}
16841684
16851685pub 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));
16871687}
16881688
16891689pub 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));
16911691}
16921692
16931693pub 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));
16951695}
16961696
16971697pub 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));
16991699}
17001700
17011701pub 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);
17031703}
17041704
17051705pub 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);
17071707}
17081708
17091709pub 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);
17111711}
17121712
17131713pub fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, len: usize, flags: u32) usize {
17141714 return syscall6(
17151715 .copy_file_range,
1716 @bitCast(usize, @as(isize, fd_in)),
1716 @as(usize, @bitCast(@as(isize, fd_in))),
17171717 @intFromPtr(off_in),
1718 @bitCast(usize, @as(isize, fd_out)),
1718 @as(usize, @bitCast(@as(isize, fd_out))),
17191719 @intFromPtr(off_out),
17201720 len,
17211721 flags,
......@@ -1731,19 +1731,19 @@ pub fn sync() void {
17311731}
17321732
17331733pub 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))));
17351735}
17361736
17371737pub 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))));
17391739}
17401740
17411741pub 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))));
17431743}
17441744
17451745pub 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);
17471747}
17481748
17491749pub fn getrlimit(resource: rlimit_resource, rlim: *rlimit) usize {
......@@ -1759,8 +1759,8 @@ pub fn setrlimit(resource: rlimit_resource, rlim: *const rlimit) usize {
17591759pub fn prlimit(pid: pid_t, resource: rlimit_resource, new_limit: ?*const rlimit, old_limit: ?*rlimit) usize {
17601760 return syscall4(
17611761 .prlimit64,
1762 @bitCast(usize, @as(isize, pid)),
1763 @bitCast(usize, @as(isize, @intFromEnum(resource))),
1762 @as(usize, @bitCast(@as(isize, pid))),
1763 @as(usize, @bitCast(@as(isize, @intFromEnum(resource)))),
17641764 @intFromPtr(new_limit),
17651765 @intFromPtr(old_limit),
17661766 );
......@@ -1775,14 +1775,14 @@ pub fn madvise(address: [*]u8, len: usize, advice: u32) usize {
17751775}
17761776
17771777pub 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);
17791779}
17801780
17811781pub fn pidfd_getfd(pidfd: fd_t, targetfd: fd_t, flags: u32) usize {
17821782 return syscall3(
17831783 .pidfd_getfd,
1784 @bitCast(usize, @as(isize, pidfd)),
1785 @bitCast(usize, @as(isize, targetfd)),
1784 @as(usize, @bitCast(@as(isize, pidfd))),
1785 @as(usize, @bitCast(@as(isize, targetfd))),
17861786 flags,
17871787 );
17881788}
......@@ -1790,8 +1790,8 @@ pub fn pidfd_getfd(pidfd: fd_t, targetfd: fd_t, flags: u32) usize {
17901790pub fn pidfd_send_signal(pidfd: fd_t, sig: i32, info: ?*siginfo_t, flags: u32) usize {
17911791 return syscall4(
17921792 .pidfd_send_signal,
1793 @bitCast(usize, @as(isize, pidfd)),
1794 @bitCast(usize, @as(isize, sig)),
1793 @as(usize, @bitCast(@as(isize, pidfd))),
1794 @as(usize, @bitCast(@as(isize, sig))),
17951795 @intFromPtr(info),
17961796 flags,
17971797 );
......@@ -1800,7 +1800,7 @@ pub fn pidfd_send_signal(pidfd: fd_t, sig: i32, info: ?*siginfo_t, flags: u32) u
18001800pub fn process_vm_readv(pid: pid_t, local: []iovec, remote: []const iovec_const, flags: usize) usize {
18011801 return syscall6(
18021802 .process_vm_readv,
1803 @bitCast(usize, @as(isize, pid)),
1803 @as(usize, @bitCast(@as(isize, pid))),
18041804 @intFromPtr(local.ptr),
18051805 local.len,
18061806 @intFromPtr(remote.ptr),
......@@ -1812,7 +1812,7 @@ pub fn process_vm_readv(pid: pid_t, local: []iovec, remote: []const iovec_const,
18121812pub fn process_vm_writev(pid: pid_t, local: []const iovec_const, remote: []const iovec_const, flags: usize) usize {
18131813 return syscall6(
18141814 .process_vm_writev,
1815 @bitCast(usize, @as(isize, pid)),
1815 @as(usize, @bitCast(@as(isize, pid))),
18161816 @intFromPtr(local.ptr),
18171817 local.len,
18181818 @intFromPtr(remote.ptr),
......@@ -1830,7 +1830,7 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {
18301830
18311831 return syscall7(
18321832 .fadvise64,
1833 @bitCast(usize, @as(isize, fd)),
1833 @as(usize, @bitCast(@as(isize, fd))),
18341834 0,
18351835 offset_halves[0],
18361836 offset_halves[1],
......@@ -1846,7 +1846,7 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {
18461846
18471847 return syscall6(
18481848 .fadvise64_64,
1849 @bitCast(usize, @as(isize, fd)),
1849 @as(usize, @bitCast(@as(isize, fd))),
18501850 advice,
18511851 offset_halves[0],
18521852 offset_halves[1],
......@@ -1862,7 +1862,7 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {
18621862
18631863 return syscall6(
18641864 .fadvise64_64,
1865 @bitCast(usize, @as(isize, fd)),
1865 @as(usize, @bitCast(@as(isize, fd))),
18661866 offset_halves[0],
18671867 offset_halves[1],
18681868 length_halves[0],
......@@ -1872,9 +1872,9 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {
18721872 } else {
18731873 return syscall4(
18741874 .fadvise64,
1875 @bitCast(usize, @as(isize, fd)),
1876 @bitCast(usize, offset),
1877 @bitCast(usize, len),
1875 @as(usize, @bitCast(@as(isize, fd))),
1876 @as(usize, @bitCast(offset)),
1877 @as(usize, @bitCast(len)),
18781878 advice,
18791879 );
18801880 }
......@@ -1890,9 +1890,9 @@ pub fn perf_event_open(
18901890 return syscall5(
18911891 .perf_event_open,
18921892 @intFromPtr(attr),
1893 @bitCast(usize, @as(isize, pid)),
1894 @bitCast(usize, @as(isize, cpu)),
1895 @bitCast(usize, @as(isize, group_fd)),
1893 @as(usize, @bitCast(@as(isize, pid))),
1894 @as(usize, @bitCast(@as(isize, cpu))),
1895 @as(usize, @bitCast(@as(isize, group_fd))),
18961896 flags,
18971897 );
18981898}
......@@ -1911,7 +1911,7 @@ pub fn ptrace(
19111911 return syscall5(
19121912 .ptrace,
19131913 req,
1914 @bitCast(usize, @as(isize, pid)),
1914 @as(usize, @bitCast(@as(isize, pid))),
19151915 addr,
19161916 data,
19171917 addr2,
......@@ -2057,7 +2057,7 @@ pub const W = struct {
20572057 pub const NOWAIT = 0x1000000;
20582058
20592059 pub fn EXITSTATUS(s: u32) u8 {
2060 return @intCast(u8, (s & 0xff00) >> 8);
2060 return @as(u8, @intCast((s & 0xff00) >> 8));
20612061 }
20622062 pub fn TERMSIG(s: u32) u32 {
20632063 return s & 0x7f;
......@@ -2069,7 +2069,7 @@ pub const W = struct {
20692069 return TERMSIG(s) == 0;
20702070 }
20712071 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;
20732073 }
20742074 pub fn IFSIGNALED(s: u32) bool {
20752075 return (s & 0xffff) -% 1 < 0xff;
......@@ -2154,9 +2154,9 @@ pub const SIG = if (is_mips) struct {
21542154 pub const SYS = 31;
21552155 pub const UNUSED = SIG.SYS;
21562156
2157 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));
2158 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);
2159 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);
2157 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
2158 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
2159 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
21602160} else if (is_sparc) struct {
21612161 pub const BLOCK = 1;
21622162 pub const UNBLOCK = 2;
......@@ -2198,9 +2198,9 @@ pub const SIG = if (is_mips) struct {
21982198 pub const PWR = LOST;
21992199 pub const IO = SIG.POLL;
22002200
2201 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));
2202 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);
2203 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);
2201 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
2202 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
2203 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
22042204} else struct {
22052205 pub const BLOCK = 0;
22062206 pub const UNBLOCK = 1;
......@@ -2241,9 +2241,9 @@ pub const SIG = if (is_mips) struct {
22412241 pub const SYS = 31;
22422242 pub const UNUSED = SIG.SYS;
22432243
2244 pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize));
2245 pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0);
2246 pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1);
2244 pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
2245 pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
2246 pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
22472247};
22482248
22492249pub const kernel_rwf = u32;
......@@ -3541,7 +3541,7 @@ pub const CAP = struct {
35413541 }
35423542
35433543 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));
35453545 }
35463546
35473547 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));
35983598
35993599fn cpu_mask(s: usize) cpu_count_t {
36003600 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));
36023602}
36033603
36043604pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
......@@ -3999,7 +3999,7 @@ pub const io_uring_cqe = extern struct {
39993999
40004000 pub fn err(self: io_uring_cqe) E {
40014001 if (self.res > -4096 and self.res < 0) {
4002 return @enumFromInt(E, -self.res);
4002 return @as(E, @enumFromInt(-self.res));
40034003 }
40044004 return .SUCCESS;
40054005 }
lib/std/os/linux/bpf.zig+15-15
......@@ -643,7 +643,7 @@ pub const Insn = packed struct {
643643 .dst = @intFromEnum(dst),
644644 .src = @intFromEnum(src),
645645 .off = 0,
646 .imm = @intCast(i32, @truncate(u32, imm)),
646 .imm = @as(i32, @intCast(@as(u32, @truncate(imm)))),
647647 };
648648 }
649649
......@@ -653,7 +653,7 @@ pub const Insn = packed struct {
653653 .dst = 0,
654654 .src = 0,
655655 .off = 0,
656 .imm = @intCast(i32, @truncate(u32, imm >> 32)),
656 .imm = @as(i32, @intCast(@as(u32, @truncate(imm >> 32)))),
657657 };
658658 }
659659
......@@ -666,11 +666,11 @@ pub const Insn = packed struct {
666666 }
667667
668668 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)));
670670 }
671671
672672 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)));
674674 }
675675
676676 pub fn st(comptime size: Size, dst: Reg, off: i16, imm: i32) Insn {
......@@ -786,17 +786,17 @@ test "opcodes" {
786786
787787 // TODO: byteswap instructions
788788 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);
790790 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);
792792 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);
794794 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);
796796 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);
798798 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
801801 // memory instructions
802802 try expect_opcode(0x18, Insn.ld_dw1(.r1, 0));
......@@ -804,7 +804,7 @@ test "opcodes" {
804804
805805 // loading a map fd
806806 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);
808808 try expect_opcode(0x00, Insn.ld_map_fd2(0));
809809
810810 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
15181518
15191519 const rc = linux.bpf(.map_create, &attr, @sizeOf(MapCreateAttr));
15201520 switch (errno(rc)) {
1521 .SUCCESS => return @intCast(fd_t, rc),
1521 .SUCCESS => return @as(fd_t, @intCast(rc)),
15221522 .INVAL => return error.MapTypeOrAttrInvalid,
15231523 .NOMEM => return error.SystemResources,
15241524 .PERM => return error.AccessDenied,
......@@ -1668,20 +1668,20 @@ pub fn prog_load(
16681668
16691669 attr.prog_load.prog_type = @intFromEnum(prog_type);
16701670 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));
16721672 attr.prog_load.license = @intFromPtr(license.ptr);
16731673 attr.prog_load.kern_version = kern_version;
16741674 attr.prog_load.prog_flags = flags;
16751675
16761676 if (log) |l| {
16771677 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));
16791679 attr.prog_load.log_level = l.level;
16801680 }
16811681
16821682 const rc = linux.bpf(.prog_load, &attr, @sizeOf(ProgLoadAttr));
16831683 return switch (errno(rc)) {
1684 .SUCCESS => @intCast(fd_t, rc),
1684 .SUCCESS => @as(fd_t, @intCast(rc)),
16851685 .ACCES => error.UnsafeProgram,
16861686 .FAULT => unreachable,
16871687 .INVAL => error.InvalidProgram,
lib/std/os/linux/bpf/helpers.zig+141-141
......@@ -11,147 +11,147 @@ const SkFullSock = @compileError("TODO missing os bits: SkFullSock");
1111//
1212// Note, these function signatures were created from documentation found in
1313// '/usr/include/linux/bpf.h'
14pub const map_lookup_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, key: ?*const anyopaque) ?*anyopaque, 1);
15pub const map_update_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, key: ?*const anyopaque, value: ?*const anyopaque, flags: u64) c_long, 2);
16pub const map_delete_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, key: ?*const anyopaque) c_long, 3);
17pub const probe_read = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 4);
18pub const ktime_get_ns = @ptrFromInt(*const fn () u64, 5);
19pub const trace_printk = @ptrFromInt(*const fn (fmt: [*:0]const u8, fmt_size: u32, arg1: u64, arg2: u64, arg3: u64) c_long, 6);
20pub const get_prandom_u32 = @ptrFromInt(*const fn () u32, 7);
21pub const get_smp_processor_id = @ptrFromInt(*const fn () u32, 8);
22pub const skb_store_bytes = @ptrFromInt(*const fn (skb: *kern.SkBuff, offset: u32, from: ?*const anyopaque, len: u32, flags: u64) c_long, 9);
23pub const l3_csum_replace = @ptrFromInt(*const fn (skb: *kern.SkBuff, offset: u32, from: u64, to: u64, size: u64) c_long, 10);
24pub const l4_csum_replace = @ptrFromInt(*const fn (skb: *kern.SkBuff, offset: u32, from: u64, to: u64, flags: u64) c_long, 11);
25pub const tail_call = @ptrFromInt(*const fn (ctx: ?*anyopaque, prog_array_map: *const kern.MapDef, index: u32) c_long, 12);
26pub const clone_redirect = @ptrFromInt(*const fn (skb: *kern.SkBuff, ifindex: u32, flags: u64) c_long, 13);
27pub const get_current_pid_tgid = @ptrFromInt(*const fn () u64, 14);
28pub const get_current_uid_gid = @ptrFromInt(*const fn () u64, 15);
29pub const get_current_comm = @ptrFromInt(*const fn (buf: ?*anyopaque, size_of_buf: u32) c_long, 16);
30pub const get_cgroup_classid = @ptrFromInt(*const fn (skb: *kern.SkBuff) u32, 17);
14pub const map_lookup_elem = @as(*const fn (map: *const kern.MapDef, key: ?*const anyopaque) ?*anyopaque, @ptrFromInt(1));
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 = @as(*const fn (map: *const kern.MapDef, key: ?*const anyopaque) c_long, @ptrFromInt(3));
17pub const probe_read = @as(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, @ptrFromInt(4));
18pub const ktime_get_ns = @as(*const fn () u64, @ptrFromInt(5));
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 = @as(*const fn () u32, @ptrFromInt(7));
21pub const get_smp_processor_id = @as(*const fn () u32, @ptrFromInt(8));
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 = @as(*const fn (skb: *kern.SkBuff, offset: u32, from: u64, to: u64, size: u64) c_long, @ptrFromInt(10));
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 = @as(*const fn (ctx: ?*anyopaque, prog_array_map: *const kern.MapDef, index: u32) c_long, @ptrFromInt(12));
26pub const clone_redirect = @as(*const fn (skb: *kern.SkBuff, ifindex: u32, flags: u64) c_long, @ptrFromInt(13));
27pub const get_current_pid_tgid = @as(*const fn () u64, @ptrFromInt(14));
28pub const get_current_uid_gid = @as(*const fn () u64, @ptrFromInt(15));
29pub const get_current_comm = @as(*const fn (buf: ?*anyopaque, size_of_buf: u32) c_long, @ptrFromInt(16));
30pub const get_cgroup_classid = @as(*const fn (skb: *kern.SkBuff) u32, @ptrFromInt(17));
3131// 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);
33pub const skb_vlan_pop = @ptrFromInt(*const fn (skb: *kern.SkBuff) c_long, 19);
34pub const skb_get_tunnel_key = @ptrFromInt(*const fn (skb: *kern.SkBuff, key: *kern.TunnelKey, size: u32, flags: u64) c_long, 20);
35pub const skb_set_tunnel_key = @ptrFromInt(*const fn (skb: *kern.SkBuff, key: *kern.TunnelKey, size: u32, flags: u64) c_long, 21);
36pub const perf_event_read = @ptrFromInt(*const fn (map: *const kern.MapDef, flags: u64) u64, 22);
37pub const redirect = @ptrFromInt(*const fn (ifindex: u32, flags: u64) c_long, 23);
38pub const get_route_realm = @ptrFromInt(*const fn (skb: *kern.SkBuff) u32, 24);
39pub const perf_event_output = @ptrFromInt(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64, data: ?*anyopaque, size: u64) c_long, 25);
40pub const skb_load_bytes = @ptrFromInt(*const fn (skb: ?*anyopaque, offset: u32, to: ?*anyopaque, len: u32) c_long, 26);
41pub const get_stackid = @ptrFromInt(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64) c_long, 27);
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 = @as(*const fn (skb: *kern.SkBuff) c_long, @ptrFromInt(19));
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 = @as(*const fn (skb: *kern.SkBuff, key: *kern.TunnelKey, size: u32, flags: u64) c_long, @ptrFromInt(21));
36pub const perf_event_read = @as(*const fn (map: *const kern.MapDef, flags: u64) u64, @ptrFromInt(22));
37pub const redirect = @as(*const fn (ifindex: u32, flags: u64) c_long, @ptrFromInt(23));
38pub const get_route_realm = @as(*const fn (skb: *kern.SkBuff) u32, @ptrFromInt(24));
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 = @as(*const fn (skb: ?*anyopaque, offset: u32, to: ?*anyopaque, len: u32) c_long, @ptrFromInt(26));
41pub const get_stackid = @as(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64) c_long, @ptrFromInt(27));
4242// 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);
44pub const skb_get_tunnel_opt = @ptrFromInt(*const fn (skb: *kern.SkBuff, opt: ?*anyopaque, size: u32) c_long, 29);
45pub const skb_set_tunnel_opt = @ptrFromInt(*const fn (skb: *kern.SkBuff, opt: ?*anyopaque, size: u32) c_long, 30);
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 = @as(*const fn (skb: *kern.SkBuff, opt: ?*anyopaque, size: u32) c_long, @ptrFromInt(29));
45pub const skb_set_tunnel_opt = @as(*const fn (skb: *kern.SkBuff, opt: ?*anyopaque, size: u32) c_long, @ptrFromInt(30));
4646// proto is __be16
47pub const skb_change_proto = @ptrFromInt(*const fn (skb: *kern.SkBuff, proto: u16, flags: u64) c_long, 31);
48pub const skb_change_type = @ptrFromInt(*const fn (skb: *kern.SkBuff, skb_type: u32) c_long, 32);
49pub const skb_under_cgroup = @ptrFromInt(*const fn (skb: *kern.SkBuff, map: ?*const anyopaque, index: u32) c_long, 33);
50pub const get_hash_recalc = @ptrFromInt(*const fn (skb: *kern.SkBuff) u32, 34);
51pub const get_current_task = @ptrFromInt(*const fn () u64, 35);
52pub const probe_write_user = @ptrFromInt(*const fn (dst: ?*anyopaque, src: ?*const anyopaque, len: u32) c_long, 36);
53pub const current_task_under_cgroup = @ptrFromInt(*const fn (map: *const kern.MapDef, index: u32) c_long, 37);
54pub const skb_change_tail = @ptrFromInt(*const fn (skb: *kern.SkBuff, len: u32, flags: u64) c_long, 38);
55pub const skb_pull_data = @ptrFromInt(*const fn (skb: *kern.SkBuff, len: u32) c_long, 39);
56pub const csum_update = @ptrFromInt(*const fn (skb: *kern.SkBuff, csum: u32) i64, 40);
57pub const set_hash_invalid = @ptrFromInt(*const fn (skb: *kern.SkBuff) void, 41);
58pub const get_numa_node_id = @ptrFromInt(*const fn () c_long, 42);
59pub const skb_change_head = @ptrFromInt(*const fn (skb: *kern.SkBuff, len: u32, flags: u64) c_long, 43);
60pub const xdp_adjust_head = @ptrFromInt(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, 44);
61pub const probe_read_str = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 45);
62pub const get_socket_cookie = @ptrFromInt(*const fn (ctx: ?*anyopaque) u64, 46);
63pub const get_socket_uid = @ptrFromInt(*const fn (skb: *kern.SkBuff) u32, 47);
64pub const set_hash = @ptrFromInt(*const fn (skb: *kern.SkBuff, hash: u32) c_long, 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);
66pub const skb_adjust_room = @ptrFromInt(*const fn (skb: *kern.SkBuff, len_diff: i32, mode: u32, flags: u64) c_long, 50);
67pub const redirect_map = @ptrFromInt(*const fn (map: *const kern.MapDef, key: u32, flags: u64) c_long, 51);
68pub const sk_redirect_map = @ptrFromInt(*const fn (skb: *kern.SkBuff, map: *const kern.MapDef, key: u32, flags: u64) c_long, 52);
69pub const sock_map_update = @ptrFromInt(*const fn (skops: *kern.SockOps, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, 53);
70pub const xdp_adjust_meta = @ptrFromInt(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, 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);
72pub const perf_prog_read_value = @ptrFromInt(*const fn (ctx: *kern.PerfEventData, buf: *kern.PerfEventValue, buf_size: u32) c_long, 56);
73pub const getsockopt = @ptrFromInt(*const fn (bpf_socket: ?*anyopaque, level: c_int, optname: c_int, optval: ?*anyopaque, optlen: c_int) c_long, 57);
74pub const override_return = @ptrFromInt(*const fn (regs: *PtRegs, rc: u64) c_long, 58);
75pub const sock_ops_cb_flags_set = @ptrFromInt(*const fn (bpf_sock: *kern.SockOps, argval: c_int) c_long, 59);
76pub const msg_redirect_map = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, map: *const kern.MapDef, key: u32, flags: u64) c_long, 60);
77pub const msg_apply_bytes = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, bytes: u32) c_long, 61);
78pub const msg_cork_bytes = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, bytes: u32) c_long, 62);
79pub const msg_pull_data = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, start: u32, end: u32, flags: u64) c_long, 63);
80pub const bind = @ptrFromInt(*const fn (ctx: *kern.BpfSockAddr, addr: *kern.SockAddr, addr_len: c_int) c_long, 64);
81pub const xdp_adjust_tail = @ptrFromInt(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, 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);
83pub const get_stack = @ptrFromInt(*const fn (ctx: ?*anyopaque, buf: ?*anyopaque, size: u32, flags: u64) c_long, 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);
85pub const fib_lookup = @ptrFromInt(*const fn (ctx: ?*anyopaque, params: *kern.FibLookup, plen: c_int, flags: u32) c_long, 69);
86pub const sock_hash_update = @ptrFromInt(*const fn (skops: *kern.SockOps, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, 70);
87pub const msg_redirect_hash = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, 71);
88pub const sk_redirect_hash = @ptrFromInt(*const fn (skb: *kern.SkBuff, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, 72);
89pub const lwt_push_encap = @ptrFromInt(*const fn (skb: *kern.SkBuff, typ: u32, hdr: ?*anyopaque, len: u32) c_long, 73);
90pub const lwt_seg6_store_bytes = @ptrFromInt(*const fn (skb: *kern.SkBuff, offset: u32, from: ?*const anyopaque, len: u32) c_long, 74);
91pub const lwt_seg6_adjust_srh = @ptrFromInt(*const fn (skb: *kern.SkBuff, offset: u32, delta: i32) c_long, 75);
92pub const lwt_seg6_action = @ptrFromInt(*const fn (skb: *kern.SkBuff, action: u32, param: ?*anyopaque, param_len: u32) c_long, 76);
93pub const rc_repeat = @ptrFromInt(*const fn (ctx: ?*anyopaque) c_long, 77);
94pub const rc_keydown = @ptrFromInt(*const fn (ctx: ?*anyopaque, protocol: u32, scancode: u64, toggle: u32) c_long, 78);
95pub const skb_cgroup_id = @ptrFromInt(*const fn (skb: *kern.SkBuff) u64, 79);
96pub const get_current_cgroup_id = @ptrFromInt(*const fn () u64, 80);
97pub const get_local_storage = @ptrFromInt(*const fn (map: ?*anyopaque, flags: u64) ?*anyopaque, 81);
98pub const sk_select_reuseport = @ptrFromInt(*const fn (reuse: *kern.SkReusePortMd, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, 82);
99pub const skb_ancestor_cgroup_id = @ptrFromInt(*const fn (skb: *kern.SkBuff, ancestor_level: c_int) u64, 83);
100pub const sk_lookup_tcp = @ptrFromInt(*const fn (ctx: ?*anyopaque, tuple: *kern.SockTuple, tuple_size: u32, netns: u64, flags: u64) ?*kern.Sock, 84);
101pub const sk_lookup_udp = @ptrFromInt(*const fn (ctx: ?*anyopaque, tuple: *kern.SockTuple, tuple_size: u32, netns: u64, flags: u64) ?*kern.Sock, 85);
102pub const sk_release = @ptrFromInt(*const fn (sock: *kern.Sock) c_long, 86);
103pub const map_push_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, value: ?*const anyopaque, flags: u64) c_long, 87);
104pub const map_pop_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, value: ?*anyopaque) c_long, 88);
105pub const map_peek_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, value: ?*anyopaque) c_long, 89);
106pub const msg_push_data = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, start: u32, len: u32, flags: u64) c_long, 90);
107pub const msg_pop_data = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, start: u32, len: u32, flags: u64) c_long, 91);
108pub const rc_pointer_rel = @ptrFromInt(*const fn (ctx: ?*anyopaque, rel_x: i32, rel_y: i32) c_long, 92);
109pub const spin_lock = @ptrFromInt(*const fn (lock: *kern.SpinLock) c_long, 93);
110pub const spin_unlock = @ptrFromInt(*const fn (lock: *kern.SpinLock) c_long, 94);
111pub const sk_fullsock = @ptrFromInt(*const fn (sk: *kern.Sock) ?*SkFullSock, 95);
112pub const tcp_sock = @ptrFromInt(*const fn (sk: *kern.Sock) ?*kern.TcpSock, 96);
113pub const skb_ecn_set_ce = @ptrFromInt(*const fn (skb: *kern.SkBuff) c_long, 97);
114pub const get_listener_sock = @ptrFromInt(*const fn (sk: *kern.Sock) ?*kern.Sock, 98);
115pub const skc_lookup_tcp = @ptrFromInt(*const fn (ctx: ?*anyopaque, tuple: *kern.SockTuple, tuple_size: u32, netns: u64, flags: u64) ?*kern.Sock, 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);
117pub const sysctl_get_name = @ptrFromInt(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong, flags: u64) c_long, 101);
118pub const sysctl_get_current_value = @ptrFromInt(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong) c_long, 102);
119pub const sysctl_get_new_value = @ptrFromInt(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong) c_long, 103);
120pub const sysctl_set_new_value = @ptrFromInt(*const fn (ctx: *kern.SysCtl, buf: ?*const u8, buf_len: c_ulong) c_long, 104);
121pub const strtol = @ptrFromInt(*const fn (buf: *const u8, buf_len: c_ulong, flags: u64, res: *c_long) c_long, 105);
122pub const strtoul = @ptrFromInt(*const fn (buf: *const u8, buf_len: c_ulong, flags: u64, res: *c_ulong) c_long, 106);
123pub const sk_storage_get = @ptrFromInt(*const fn (map: *const kern.MapDef, sk: *kern.Sock, value: ?*anyopaque, flags: u64) ?*anyopaque, 107);
124pub const sk_storage_delete = @ptrFromInt(*const fn (map: *const kern.MapDef, sk: *kern.Sock) c_long, 108);
125pub const send_signal = @ptrFromInt(*const fn (sig: u32) c_long, 109);
126pub const tcp_gen_syncookie = @ptrFromInt(*const fn (sk: *kern.Sock, iph: ?*anyopaque, iph_len: u32, th: *TcpHdr, th_len: u32) i64, 110);
127pub const skb_output = @ptrFromInt(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64, data: ?*anyopaque, size: u64) c_long, 111);
128pub const probe_read_user = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 112);
129pub const probe_read_kernel = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 113);
130pub const probe_read_user_str = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 114);
131pub const probe_read_kernel_str = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 115);
132pub const tcp_send_ack = @ptrFromInt(*const fn (tp: ?*anyopaque, rcv_nxt: u32) c_long, 116);
133pub const send_signal_thread = @ptrFromInt(*const fn (sig: u32) c_long, 117);
134pub const jiffies64 = @ptrFromInt(*const fn () u64, 118);
135pub const read_branch_records = @ptrFromInt(*const fn (ctx: *kern.PerfEventData, buf: ?*anyopaque, size: u32, flags: u64) c_long, 119);
136pub const get_ns_current_pid_tgid = @ptrFromInt(*const fn (dev: u64, ino: u64, nsdata: *kern.PidNsInfo, size: u32) c_long, 120);
137pub const xdp_output = @ptrFromInt(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64, data: ?*anyopaque, size: u64) c_long, 121);
138pub const get_netns_cookie = @ptrFromInt(*const fn (ctx: ?*anyopaque) u64, 122);
139pub const get_current_ancestor_cgroup_id = @ptrFromInt(*const fn (ancestor_level: c_int) u64, 123);
140pub const sk_assign = @ptrFromInt(*const fn (skb: *kern.SkBuff, sk: *kern.Sock, flags: u64) c_long, 124);
141pub const ktime_get_boot_ns = @ptrFromInt(*const fn () u64, 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);
143pub const seq_write = @ptrFromInt(*const fn (m: *kern.SeqFile, data: ?*const u8, len: u32) c_long, 127);
144pub const sk_cgroup_id = @ptrFromInt(*const fn (sk: *kern.BpfSock) u64, 128);
145pub const sk_ancestor_cgroup_id = @ptrFromInt(*const fn (sk: *kern.BpfSock, ancestor_level: c_long) u64, 129);
146pub const ringbuf_output = @ptrFromInt(*const fn (ringbuf: ?*anyopaque, data: ?*anyopaque, size: u64, flags: u64) c_long, 130);
147pub const ringbuf_reserve = @ptrFromInt(*const fn (ringbuf: ?*anyopaque, size: u64, flags: u64) ?*anyopaque, 131);
148pub const ringbuf_submit = @ptrFromInt(*const fn (data: ?*anyopaque, flags: u64) void, 132);
149pub const ringbuf_discard = @ptrFromInt(*const fn (data: ?*anyopaque, flags: u64) void, 133);
150pub const ringbuf_query = @ptrFromInt(*const fn (ringbuf: ?*anyopaque, flags: u64) u64, 134);
151pub const csum_level = @ptrFromInt(*const fn (skb: *kern.SkBuff, level: u64) c_long, 135);
152pub const skc_to_tcp6_sock = @ptrFromInt(*const fn (sk: ?*anyopaque) ?*kern.Tcp6Sock, 136);
153pub const skc_to_tcp_sock = @ptrFromInt(*const fn (sk: ?*anyopaque) ?*kern.TcpSock, 137);
154pub const skc_to_tcp_timewait_sock = @ptrFromInt(*const fn (sk: ?*anyopaque) ?*kern.TcpTimewaitSock, 138);
155pub const skc_to_tcp_request_sock = @ptrFromInt(*const fn (sk: ?*anyopaque) ?*kern.TcpRequestSock, 139);
156pub const skc_to_udp6_sock = @ptrFromInt(*const fn (sk: ?*anyopaque) ?*kern.Udp6Sock, 140);
157pub const get_task_stack = @ptrFromInt(*const fn (task: ?*anyopaque, buf: ?*anyopaque, size: u32, flags: u64) c_long, 141);
47pub const skb_change_proto = @as(*const fn (skb: *kern.SkBuff, proto: u16, flags: u64) c_long, @ptrFromInt(31));
48pub const skb_change_type = @as(*const fn (skb: *kern.SkBuff, skb_type: u32) c_long, @ptrFromInt(32));
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 = @as(*const fn (skb: *kern.SkBuff) u32, @ptrFromInt(34));
51pub const get_current_task = @as(*const fn () u64, @ptrFromInt(35));
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 = @as(*const fn (map: *const kern.MapDef, index: u32) c_long, @ptrFromInt(37));
54pub const skb_change_tail = @as(*const fn (skb: *kern.SkBuff, len: u32, flags: u64) c_long, @ptrFromInt(38));
55pub const skb_pull_data = @as(*const fn (skb: *kern.SkBuff, len: u32) c_long, @ptrFromInt(39));
56pub const csum_update = @as(*const fn (skb: *kern.SkBuff, csum: u32) i64, @ptrFromInt(40));
57pub const set_hash_invalid = @as(*const fn (skb: *kern.SkBuff) void, @ptrFromInt(41));
58pub const get_numa_node_id = @as(*const fn () c_long, @ptrFromInt(42));
59pub const skb_change_head = @as(*const fn (skb: *kern.SkBuff, len: u32, flags: u64) c_long, @ptrFromInt(43));
60pub const xdp_adjust_head = @as(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, @ptrFromInt(44));
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 = @as(*const fn (ctx: ?*anyopaque) u64, @ptrFromInt(46));
63pub const get_socket_uid = @as(*const fn (skb: *kern.SkBuff) u32, @ptrFromInt(47));
64pub const set_hash = @as(*const fn (skb: *kern.SkBuff, hash: u32) c_long, @ptrFromInt(48));
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 = @as(*const fn (skb: *kern.SkBuff, len_diff: i32, mode: u32, flags: u64) c_long, @ptrFromInt(50));
67pub const redirect_map = @as(*const fn (map: *const kern.MapDef, key: u32, flags: u64) c_long, @ptrFromInt(51));
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 = @as(*const fn (skops: *kern.SockOps, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, @ptrFromInt(53));
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 = @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 = @as(*const fn (ctx: *kern.PerfEventData, buf: *kern.PerfEventValue, buf_size: u32) c_long, @ptrFromInt(56));
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 = @as(*const fn (regs: *PtRegs, rc: u64) c_long, @ptrFromInt(58));
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 = @as(*const fn (msg: *kern.SkMsgMd, map: *const kern.MapDef, key: u32, flags: u64) c_long, @ptrFromInt(60));
77pub const msg_apply_bytes = @as(*const fn (msg: *kern.SkMsgMd, bytes: u32) c_long, @ptrFromInt(61));
78pub const msg_cork_bytes = @as(*const fn (msg: *kern.SkMsgMd, bytes: u32) c_long, @ptrFromInt(62));
79pub const msg_pull_data = @as(*const fn (msg: *kern.SkMsgMd, start: u32, end: u32, flags: u64) c_long, @ptrFromInt(63));
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 = @as(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, @ptrFromInt(65));
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 = @as(*const fn (ctx: ?*anyopaque, buf: ?*anyopaque, size: u32, flags: u64) c_long, @ptrFromInt(67));
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 = @as(*const fn (ctx: ?*anyopaque, params: *kern.FibLookup, plen: c_int, flags: u32) c_long, @ptrFromInt(69));
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 = @as(*const fn (msg: *kern.SkMsgMd, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, @ptrFromInt(71));
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 = @as(*const fn (skb: *kern.SkBuff, typ: u32, hdr: ?*anyopaque, len: u32) c_long, @ptrFromInt(73));
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 = @as(*const fn (skb: *kern.SkBuff, offset: u32, delta: i32) c_long, @ptrFromInt(75));
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 = @as(*const fn (ctx: ?*anyopaque) c_long, @ptrFromInt(77));
94pub const rc_keydown = @as(*const fn (ctx: ?*anyopaque, protocol: u32, scancode: u64, toggle: u32) c_long, @ptrFromInt(78));
95pub const skb_cgroup_id = @as(*const fn (skb: *kern.SkBuff) u64, @ptrFromInt(79));
96pub const get_current_cgroup_id = @as(*const fn () u64, @ptrFromInt(80));
97pub const get_local_storage = @as(*const fn (map: ?*anyopaque, flags: u64) ?*anyopaque, @ptrFromInt(81));
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 = @as(*const fn (skb: *kern.SkBuff, ancestor_level: c_int) u64, @ptrFromInt(83));
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 = @as(*const fn (ctx: ?*anyopaque, tuple: *kern.SockTuple, tuple_size: u32, netns: u64, flags: u64) ?*kern.Sock, @ptrFromInt(85));
102pub const sk_release = @as(*const fn (sock: *kern.Sock) c_long, @ptrFromInt(86));
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 = @as(*const fn (map: *const kern.MapDef, value: ?*anyopaque) c_long, @ptrFromInt(88));
105pub const map_peek_elem = @as(*const fn (map: *const kern.MapDef, value: ?*anyopaque) c_long, @ptrFromInt(89));
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 = @as(*const fn (msg: *kern.SkMsgMd, start: u32, len: u32, flags: u64) c_long, @ptrFromInt(91));
108pub const rc_pointer_rel = @as(*const fn (ctx: ?*anyopaque, rel_x: i32, rel_y: i32) c_long, @ptrFromInt(92));
109pub const spin_lock = @as(*const fn (lock: *kern.SpinLock) c_long, @ptrFromInt(93));
110pub const spin_unlock = @as(*const fn (lock: *kern.SpinLock) c_long, @ptrFromInt(94));
111pub const sk_fullsock = @as(*const fn (sk: *kern.Sock) ?*SkFullSock, @ptrFromInt(95));
112pub const tcp_sock = @as(*const fn (sk: *kern.Sock) ?*kern.TcpSock, @ptrFromInt(96));
113pub const skb_ecn_set_ce = @as(*const fn (skb: *kern.SkBuff) c_long, @ptrFromInt(97));
114pub const get_listener_sock = @as(*const fn (sk: *kern.Sock) ?*kern.Sock, @ptrFromInt(98));
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 = @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 = @as(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong, flags: u64) c_long, @ptrFromInt(101));
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 = @as(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong) c_long, @ptrFromInt(103));
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 = @as(*const fn (buf: *const u8, buf_len: c_ulong, flags: u64, res: *c_long) c_long, @ptrFromInt(105));
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 = @as(*const fn (map: *const kern.MapDef, sk: *kern.Sock, value: ?*anyopaque, flags: u64) ?*anyopaque, @ptrFromInt(107));
124pub const sk_storage_delete = @as(*const fn (map: *const kern.MapDef, sk: *kern.Sock) c_long, @ptrFromInt(108));
125pub const send_signal = @as(*const fn (sig: u32) c_long, @ptrFromInt(109));
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 = @as(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64, data: ?*anyopaque, size: u64) c_long, @ptrFromInt(111));
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 = @as(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, @ptrFromInt(113));
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 = @as(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, @ptrFromInt(115));
132pub const tcp_send_ack = @as(*const fn (tp: ?*anyopaque, rcv_nxt: u32) c_long, @ptrFromInt(116));
133pub const send_signal_thread = @as(*const fn (sig: u32) c_long, @ptrFromInt(117));
134pub const jiffies64 = @as(*const fn () u64, @ptrFromInt(118));
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 = @as(*const fn (dev: u64, ino: u64, nsdata: *kern.PidNsInfo, size: u32) c_long, @ptrFromInt(120));
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 = @as(*const fn (ctx: ?*anyopaque) u64, @ptrFromInt(122));
139pub const get_current_ancestor_cgroup_id = @as(*const fn (ancestor_level: c_int) u64, @ptrFromInt(123));
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 = @as(*const fn () u64, @ptrFromInt(125));
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 = @as(*const fn (m: *kern.SeqFile, data: ?*const u8, len: u32) c_long, @ptrFromInt(127));
144pub const sk_cgroup_id = @as(*const fn (sk: *kern.BpfSock) u64, @ptrFromInt(128));
145pub const sk_ancestor_cgroup_id = @as(*const fn (sk: *kern.BpfSock, ancestor_level: c_long) u64, @ptrFromInt(129));
146pub const ringbuf_output = @as(*const fn (ringbuf: ?*anyopaque, data: ?*anyopaque, size: u64, flags: u64) c_long, @ptrFromInt(130));
147pub const ringbuf_reserve = @as(*const fn (ringbuf: ?*anyopaque, size: u64, flags: u64) ?*anyopaque, @ptrFromInt(131));
148pub const ringbuf_submit = @as(*const fn (data: ?*anyopaque, flags: u64) void, @ptrFromInt(132));
149pub const ringbuf_discard = @as(*const fn (data: ?*anyopaque, flags: u64) void, @ptrFromInt(133));
150pub const ringbuf_query = @as(*const fn (ringbuf: ?*anyopaque, flags: u64) u64, @ptrFromInt(134));
151pub const csum_level = @as(*const fn (skb: *kern.SkBuff, level: u64) c_long, @ptrFromInt(135));
152pub const skc_to_tcp6_sock = @as(*const fn (sk: ?*anyopaque) ?*kern.Tcp6Sock, @ptrFromInt(136));
153pub const skc_to_tcp_sock = @as(*const fn (sk: ?*anyopaque) ?*kern.TcpSock, @ptrFromInt(137));
154pub const skc_to_tcp_timewait_sock = @as(*const fn (sk: ?*anyopaque) ?*kern.TcpTimewaitSock, @ptrFromInt(138));
155pub const skc_to_tcp_request_sock = @as(*const fn (sk: ?*anyopaque) ?*kern.TcpRequestSock, @ptrFromInt(139));
156pub const skc_to_udp6_sock = @as(*const fn (sk: ?*anyopaque) ?*kern.Udp6Sock, @ptrFromInt(140));
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 {
6060 .NOSYS => return error.SystemOutdated,
6161 else => |errno| return os.unexpectedErrno(errno),
6262 }
63 const fd = @intCast(os.fd_t, res);
63 const fd = @as(os.fd_t, @intCast(res));
6464 assert(fd >= 0);
6565 errdefer os.close(fd);
6666
......@@ -198,7 +198,7 @@ pub const IO_Uring = struct {
198198 .INTR => return error.SignalInterrupt,
199199 else => |errno| return os.unexpectedErrno(errno),
200200 }
201 return @intCast(u32, res);
201 return @as(u32, @intCast(res));
202202 }
203203
204204 /// Sync internal state with kernel ring state on the SQ side.
......@@ -937,8 +937,8 @@ pub const IO_Uring = struct {
937937 const res = linux.io_uring_register(
938938 self.fd,
939939 .REGISTER_FILES,
940 @ptrCast(*const anyopaque, fds.ptr),
941 @intCast(u32, fds.len),
940 @as(*const anyopaque, @ptrCast(fds.ptr)),
941 @as(u32, @intCast(fds.len)),
942942 );
943943 try handle_registration_result(res);
944944 }
......@@ -968,8 +968,8 @@ pub const IO_Uring = struct {
968968 const res = linux.io_uring_register(
969969 self.fd,
970970 .REGISTER_FILES_UPDATE,
971 @ptrCast(*const anyopaque, &update),
972 @intCast(u32, fds.len),
971 @as(*const anyopaque, @ptrCast(&update)),
972 @as(u32, @intCast(fds.len)),
973973 );
974974 try handle_registration_result(res);
975975 }
......@@ -982,7 +982,7 @@ pub const IO_Uring = struct {
982982 const res = linux.io_uring_register(
983983 self.fd,
984984 .REGISTER_EVENTFD,
985 @ptrCast(*const anyopaque, &fd),
985 @as(*const anyopaque, @ptrCast(&fd)),
986986 1,
987987 );
988988 try handle_registration_result(res);
......@@ -997,7 +997,7 @@ pub const IO_Uring = struct {
997997 const res = linux.io_uring_register(
998998 self.fd,
999999 .REGISTER_EVENTFD_ASYNC,
1000 @ptrCast(*const anyopaque, &fd),
1000 @as(*const anyopaque, @ptrCast(&fd)),
10011001 1,
10021002 );
10031003 try handle_registration_result(res);
......@@ -1022,7 +1022,7 @@ pub const IO_Uring = struct {
10221022 self.fd,
10231023 .REGISTER_BUFFERS,
10241024 buffers.ptr,
1025 @intCast(u32, buffers.len),
1025 @as(u32, @intCast(buffers.len)),
10261026 );
10271027 try handle_registration_result(res);
10281028 }
......@@ -1122,20 +1122,17 @@ pub const SubmissionQueue = struct {
11221122 errdefer os.munmap(mmap_sqes);
11231123 assert(mmap_sqes.len == size_sqes);
11241124
1125 const array = @ptrCast([*]u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.array]));
1126 const sqes = @ptrCast([*]linux.io_uring_sqe, @alignCast(@alignOf(linux.io_uring_sqe), &mmap_sqes[0]));
1125 const array: [*]u32 = @ptrCast(@alignCast(&mmap[p.sq_off.array]));
1126 const sqes: [*]linux.io_uring_sqe = @ptrCast(@alignCast(&mmap_sqes[0]));
11271127 // We expect the kernel copies p.sq_entries to the u32 pointed to by p.sq_off.ring_entries,
11281128 // see https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L7843-L7844.
1129 assert(
1130 p.sq_entries ==
1131 @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.ring_entries])).*,
1132 );
1129 assert(p.sq_entries == @as(*u32, @ptrCast(@alignCast(&mmap[p.sq_off.ring_entries]))).*);
11331130 return SubmissionQueue{
1134 .head = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.head])),
1135 .tail = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.tail])),
1136 .mask = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.ring_mask])).*,
1137 .flags = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.flags])),
1138 .dropped = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.dropped])),
1131 .head = @ptrCast(@alignCast(&mmap[p.sq_off.head])),
1132 .tail = @ptrCast(@alignCast(&mmap[p.sq_off.tail])),
1133 .mask = @as(*u32, @ptrCast(@alignCast(&mmap[p.sq_off.ring_mask]))).*,
1134 .flags = @ptrCast(@alignCast(&mmap[p.sq_off.flags])),
1135 .dropped = @ptrCast(@alignCast(&mmap[p.sq_off.dropped])),
11391136 .array = array[0..p.sq_entries],
11401137 .sqes = sqes[0..p.sq_entries],
11411138 .mmap = mmap,
......@@ -1160,17 +1157,13 @@ pub const CompletionQueue = struct {
11601157 assert(fd >= 0);
11611158 assert((p.features & linux.IORING_FEAT_SINGLE_MMAP) != 0);
11621159 const mmap = sq.mmap;
1163 const cqes = @ptrCast(
1164 [*]linux.io_uring_cqe,
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])).*);
1160 const cqes: [*]linux.io_uring_cqe = @ptrCast(@alignCast(&mmap[p.cq_off.cqes]));
1161 assert(p.cq_entries == @as(*u32, @ptrCast(@alignCast(&mmap[p.cq_off.ring_entries]))).*);
11691162 return CompletionQueue{
1170 .head = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.head])),
1171 .tail = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.tail])),
1172 .mask = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.ring_mask])).*,
1173 .overflow = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.overflow])),
1163 .head = @ptrCast(@alignCast(&mmap[p.cq_off.head])),
1164 .tail = @ptrCast(@alignCast(&mmap[p.cq_off.tail])),
1165 .mask = @as(*u32, @ptrCast(@alignCast(&mmap[p.cq_off.ring_mask]))).*,
1166 .overflow = @ptrCast(@alignCast(&mmap[p.cq_off.overflow])),
11741167 .cqes = cqes[0..p.cq_entries],
11751168 };
11761169 }
......@@ -1233,7 +1226,7 @@ pub fn io_uring_prep_rw(
12331226 .fd = fd,
12341227 .off = offset,
12351228 .addr = addr,
1236 .len = @intCast(u32, len),
1229 .len = @as(u32, @intCast(len)),
12371230 .rw_flags = 0,
12381231 .user_data = 0,
12391232 .buf_index = 0,
......@@ -1319,7 +1312,7 @@ pub fn io_uring_prep_epoll_ctl(
13191312 op: u32,
13201313 ev: ?*linux.epoll_event,
13211314) 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)));
13231316}
13241317
13251318pub 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(
14591452 .fd = fd,
14601453 .off = offset,
14611454 .addr = len,
1462 .len = @intCast(u32, mode),
1455 .len = @as(u32, @intCast(mode)),
14631456 .rw_flags = 0,
14641457 .user_data = 0,
14651458 .buf_index = 0,
......@@ -1514,7 +1507,7 @@ pub fn io_uring_prep_renameat(
15141507 0,
15151508 @intFromPtr(new_path),
15161509 );
1517 sqe.len = @bitCast(u32, new_dir_fd);
1510 sqe.len = @as(u32, @bitCast(new_dir_fd));
15181511 sqe.rw_flags = flags;
15191512}
15201513
......@@ -1569,7 +1562,7 @@ pub fn io_uring_prep_linkat(
15691562 0,
15701563 @intFromPtr(new_path),
15711564 );
1572 sqe.len = @bitCast(u32, new_dir_fd);
1565 sqe.len = @as(u32, @bitCast(new_dir_fd));
15731566 sqe.rw_flags = flags;
15741567}
15751568
......@@ -1582,8 +1575,8 @@ pub fn io_uring_prep_provide_buffers(
15821575 buffer_id: usize,
15831576) void {
15841577 const ptr = @intFromPtr(buffers);
1585 io_uring_prep_rw(.PROVIDE_BUFFERS, sqe, @intCast(i32, num), ptr, buffer_len, buffer_id);
1586 sqe.buf_index = @intCast(u16, group_id);
1578 io_uring_prep_rw(.PROVIDE_BUFFERS, sqe, @as(i32, @intCast(num)), ptr, buffer_len, buffer_id);
1579 sqe.buf_index = @as(u16, @intCast(group_id));
15871580}
15881581
15891582pub fn io_uring_prep_remove_buffers(
......@@ -1591,8 +1584,8 @@ pub fn io_uring_prep_remove_buffers(
15911584 num: usize,
15921585 group_id: usize,
15931586) void {
1594 io_uring_prep_rw(.REMOVE_BUFFERS, sqe, @intCast(i32, num), 0, 0, 0);
1595 sqe.buf_index = @intCast(u16, group_id);
1587 io_uring_prep_rw(.REMOVE_BUFFERS, sqe, @as(i32, @intCast(num)), 0, 0, 0);
1588 sqe.buf_index = @as(u16, @intCast(group_id));
15961589}
15971590
15981591test "structs/offsets/entries" {
......@@ -1886,12 +1879,12 @@ test "write_fixed/read_fixed" {
18861879
18871880 try testing.expectEqual(linux.io_uring_cqe{
18881881 .user_data = 0x45454545,
1889 .res = @intCast(i32, buffers[0].iov_len),
1882 .res = @as(i32, @intCast(buffers[0].iov_len)),
18901883 .flags = 0,
18911884 }, cqe_write);
18921885 try testing.expectEqual(linux.io_uring_cqe{
18931886 .user_data = 0x12121212,
1894 .res = @intCast(i32, buffers[1].iov_len),
1887 .res = @as(i32, @intCast(buffers[1].iov_len)),
18951888 .flags = 0,
18961889 }, cqe_read);
18971890
......@@ -2145,7 +2138,7 @@ test "timeout (after a relative time)" {
21452138 }, cqe);
21462139
21472140 // 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;
21492142}
21502143
21512144test "timeout (after a number of completions)" {
......@@ -2637,7 +2630,7 @@ test "renameat" {
26372630 );
26382631 try testing.expectEqual(linux.IORING_OP.RENAMEAT, sqe.opcode);
26392632 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)));
26412634 try testing.expectEqual(@as(u32, 1), try ring.submit());
26422635
26432636 const cqe = try ring.copy_cqe();
......@@ -2850,7 +2843,7 @@ test "linkat" {
28502843 );
28512844 try testing.expectEqual(linux.IORING_OP.LINKAT, sqe.opcode);
28522845 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)));
28542847 try testing.expectEqual(@as(u32, 1), try ring.submit());
28552848
28562849 const cqe = try ring.copy_cqe();
......@@ -2898,7 +2891,7 @@ test "provide_buffers: read" {
28982891 // Provide 4 buffers
28992892
29002893 {
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);
29022895 try testing.expectEqual(linux.IORING_OP.PROVIDE_BUFFERS, sqe.opcode);
29032896 try testing.expectEqual(@as(i32, buffers.len), sqe.fd);
29042897 try testing.expectEqual(@as(u32, buffers[0].len), sqe.len);
......@@ -2939,7 +2932,7 @@ test "provide_buffers: read" {
29392932 try testing.expectEqual(@as(i32, buffer_len), cqe.res);
29402933
29412934 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))]);
29432936 }
29442937
29452938 // This read should fail
......@@ -2971,7 +2964,7 @@ test "provide_buffers: read" {
29712964 const reprovided_buffer_id = 2;
29722965
29732966 {
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);
29752968 try testing.expectEqual(@as(u32, 1), try ring.submit());
29762969
29772970 const cqe = try ring.copy_cqe();
......@@ -3003,7 +2996,7 @@ test "provide_buffers: read" {
30032996 try testing.expectEqual(used_buffer_id, reprovided_buffer_id);
30042997 try testing.expectEqual(@as(i32, buffer_len), cqe.res);
30052998 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))]);
30073000 }
30083001}
30093002
......@@ -3030,7 +3023,7 @@ test "remove_buffers" {
30303023 // Provide 4 buffers
30313024
30323025 {
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);
30343027 try testing.expectEqual(@as(u32, 1), try ring.submit());
30353028
30363029 const cqe = try ring.copy_cqe();
......@@ -3076,7 +3069,7 @@ test "remove_buffers" {
30763069 try testing.expect(used_buffer_id >= 0 and used_buffer_id < 4);
30773070 try testing.expectEqual(@as(i32, buffer_len), cqe.res);
30783071 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))]);
30803073 }
30813074
30823075 // Final read should _not_ work
......@@ -3119,7 +3112,7 @@ test "provide_buffers: accept/connect/send/recv" {
31193112 // Provide 4 buffers
31203113
31213114 {
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);
31233116 try testing.expectEqual(linux.IORING_OP.PROVIDE_BUFFERS, sqe.opcode);
31243117 try testing.expectEqual(@as(i32, buffers.len), sqe.fd);
31253118 try testing.expectEqual(@as(u32, buffer_len), sqe.len);
......@@ -3181,7 +3174,7 @@ test "provide_buffers: accept/connect/send/recv" {
31813174 try testing.expectEqual(@as(i32, buffer_len), cqe.res);
31823175
31833176 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))];
31853178 try testing.expectEqualSlices(u8, &([_]u8{'z'} ** buffer_len), buffer);
31863179 }
31873180
......@@ -3213,7 +3206,7 @@ test "provide_buffers: accept/connect/send/recv" {
32133206 const reprovided_buffer_id = 2;
32143207
32153208 {
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);
32173210 try testing.expectEqual(@as(u32, 1), try ring.submit());
32183211
32193212 const cqe = try ring.copy_cqe();
......@@ -3259,7 +3252,7 @@ test "provide_buffers: accept/connect/send/recv" {
32593252 try testing.expectEqual(used_buffer_id, reprovided_buffer_id);
32603253 try testing.expectEqual(@as(i32, buffer_len), cqe.res);
32613254 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))];
32633256 try testing.expectEqualSlices(u8, &([_]u8{'w'} ** buffer_len), buffer);
32643257 }
32653258}
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 {
3232 .io_type = io_type,
3333 .nr = nr,
3434 };
35 return @bitCast(u32, request);
35 return @as(u32, @bitCast(request));
3636}
3737
3838pub 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 {
103103
104104 // Apply the relocations.
105105 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]);
107107 for (rel) |r| {
108108 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;
110110 }
111111 }
112112 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]);
114114 for (rela) |r| {
115115 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));
117117 }
118118 }
119119}
lib/std/os/linux/test.zig+8-8
......@@ -50,7 +50,7 @@ test "timer" {
5050 .it_value = time_interval,
5151 };
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));
5454 try expect(err == .SUCCESS);
5555
5656 var event = linux.epoll_event{
......@@ -58,13 +58,13 @@ test "timer" {
5858 .data = linux.epoll_data{ .ptr = 0 },
5959 };
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));
6262 try expect(err == .SUCCESS);
6363
6464 const events_one: linux.epoll_event = undefined;
6565 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));
6868 try expect(err == .SUCCESS);
6969}
7070
......@@ -91,11 +91,11 @@ test "statx" {
9191 }
9292
9393 try expect(stat_buf.mode == statx_buf.mode);
94 try expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);
95 try expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);
96 try expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);
97 try expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
98 try expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
94 try expect(@as(u32, @bitCast(stat_buf.uid)) == statx_buf.uid);
95 try expect(@as(u32, @bitCast(stat_buf.gid)) == statx_buf.gid);
96 try expect(@as(u64, @bitCast(@as(i64, stat_buf.size))) == statx_buf.size);
97 try expect(@as(u64, @bitCast(@as(i64, stat_buf.blksize))) == statx_buf.blksize);
98 try expect(@as(u64, @bitCast(@as(i64, stat_buf.blocks))) == statx_buf.blocks);
9999}
100100
101101test "user and group ids" {
lib/std/os/linux/tls.zig+3-3
......@@ -205,7 +205,7 @@ fn initTLS(phdrs: []elf.Phdr) void {
205205 // the data stored in the PT_TLS segment is p_filesz and may be less
206206 // than the former
207207 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];
209209 tls_data_alloc_size = phdr.p_memsz;
210210 } else {
211211 tls_align_factor = @alignOf(usize);
......@@ -263,12 +263,12 @@ fn initTLS(phdrs: []elf.Phdr) void {
263263 .dtv_offset = dtv_offset,
264264 .data_offset = data_offset,
265265 .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))),
267267 };
268268}
269269
270270inline fn alignPtrCast(comptime T: type, ptr: [*]u8) *T {
271 return @ptrCast(*T, @alignCast(@alignOf(T), ptr));
271 return @ptrCast(@alignCast(ptr));
272272}
273273
274274/// 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 {
88 const vdso_addr = std.os.system.getauxval(std.elf.AT_SYSINFO_EHDR);
99 if (vdso_addr == 0) return 0;
1010
11 const eh = @ptrFromInt(*elf.Ehdr, vdso_addr);
11 const eh = @as(*elf.Ehdr, @ptrFromInt(vdso_addr));
1212 var ph_addr: usize = vdso_addr + eh.e_phoff;
1313
1414 var maybe_dynv: ?[*]usize = null;
......@@ -19,14 +19,14 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
1919 i += 1;
2020 ph_addr += eh.e_phentsize;
2121 }) {
22 const this_ph = @ptrFromInt(*elf.Phdr, ph_addr);
22 const this_ph = @as(*elf.Phdr, @ptrFromInt(ph_addr));
2323 switch (this_ph.p_type) {
2424 // On WSL1 as well as older kernels, the VDSO ELF image is pre-linked in the upper half
2525 // of the memory space (e.g. p_vaddr = 0xffffffffff700000 on WSL1).
2626 // Wrapping operations are used on this line as well as subsequent calculations relative to base
2727 // (lines 47, 78) to ensure no overflow check is tripped.
2828 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)),
3030 else => {},
3131 }
3232 }
......@@ -45,11 +45,11 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
4545 while (dynv[i] != 0) : (i += 2) {
4646 const p = base +% dynv[i + 1];
4747 switch (dynv[i]) {
48 elf.DT_STRTAB => maybe_strings = @ptrFromInt([*]u8, p),
49 elf.DT_SYMTAB => maybe_syms = @ptrFromInt([*]elf.Sym, p),
50 elf.DT_HASH => maybe_hashtab = @ptrFromInt([*]linux.Elf_Symndx, p),
51 elf.DT_VERSYM => maybe_versym = @ptrFromInt([*]u16, p),
52 elf.DT_VERDEF => maybe_verdef = @ptrFromInt(*elf.Verdef, p),
48 elf.DT_STRTAB => maybe_strings = @as([*]u8, @ptrFromInt(p)),
49 elf.DT_SYMTAB => maybe_syms = @as([*]elf.Sym, @ptrFromInt(p)),
50 elf.DT_HASH => maybe_hashtab = @as([*]linux.Elf_Symndx, @ptrFromInt(p)),
51 elf.DT_VERSYM => maybe_versym = @as([*]u16, @ptrFromInt(p)),
52 elf.DT_VERDEF => maybe_verdef = @as(*elf.Verdef, @ptrFromInt(p)),
5353 else => {},
5454 }
5555 }
......@@ -65,10 +65,10 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
6565
6666 var i: usize = 0;
6767 while (i < hashtab[1]) : (i += 1) {
68 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue;
69 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;
68 if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info & 0xf)) & OK_TYPES)) continue;
69 if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info >> 4)) & OK_BINDS)) continue;
7070 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));
7272 if (!mem.eql(u8, name, mem.sliceTo(sym_name, 0))) continue;
7373 if (maybe_versym) |versym| {
7474 if (!checkver(maybe_verdef.?, versym[i], vername, strings))
......@@ -82,15 +82,15 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
8282
8383fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [*]u8) bool {
8484 var def = def_arg;
85 const vsym = @bitCast(u32, vsym_arg) & 0x7fff;
85 const vsym = @as(u32, @bitCast(vsym_arg)) & 0x7fff;
8686 while (true) {
8787 if (0 == (def.vd_flags & elf.VER_FLG_BASE) and (def.vd_ndx & 0x7fff) == vsym)
8888 break;
8989 if (def.vd_next == 0)
9090 return false;
91 def = @ptrFromInt(*elf.Verdef, @intFromPtr(def) + def.vd_next);
91 def = @as(*elf.Verdef, @ptrFromInt(@intFromPtr(def) + def.vd_next));
9292 }
93 const aux = @ptrFromInt(*elf.Verdaux, @intFromPtr(def) + def.vd_aux);
94 const vda_name = @ptrCast([*:0]u8, strings + aux.vda_name);
93 const aux = @as(*elf.Verdaux, @ptrFromInt(@intFromPtr(def) + def.vd_aux));
94 const vda_name = @as([*:0]u8, @ptrCast(strings + aux.vda_name));
9595 return mem.eql(u8, vername, mem.sliceTo(vda_name, 0));
9696}
lib/std/os/plan9.zig+2-2
......@@ -8,9 +8,9 @@ pub const syscall_bits = switch (builtin.cpu.arch) {
88pub const E = @import("plan9/errno.zig").E;
99/// Get the errno from a syscall return value, or 0 for no error.
1010pub fn getErrno(r: usize) E {
11 const signed_r = @bitCast(isize, r);
11 const signed_r = @as(isize, @bitCast(r));
1212 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));
1414}
1515pub const SIG = struct {
1616 /// 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 {
488488
489489 const reloc_addr = info.dlpi_addr + phdr.p_vaddr;
490490 // 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));
492492 // Validate the magic
493493 if (!mem.eql(u8, elf_header.e_ident[0..4], elf.MAGIC)) return error.BadElfMagic;
494494 // Consistency check
......@@ -751,7 +751,7 @@ test "getrlimit and setrlimit" {
751751 }
752752
753753 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));
755755 const limit = try os.getrlimit(resource);
756756
757757 // 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 {};
143143test "GUID formatting" {
144144 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
148148 var str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid});
149149 defer std.testing.allocator.free(str);
lib/std/os/uefi/pool_allocator.zig+3-3
......@@ -9,7 +9,7 @@ const Allocator = mem.Allocator;
99
1010const UefiPoolAllocator = struct {
1111 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)));
1313 }
1414
1515 fn alloc(
......@@ -22,7 +22,7 @@ const UefiPoolAllocator = struct {
2222
2323 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
2727 const metadata_len = mem.alignForward(usize, @sizeOf(usize), ptr_align);
2828
......@@ -135,5 +135,5 @@ fn uefi_free(
135135) void {
136136 _ = log2_old_ptr_align;
137137 _ = ret_addr;
138 _ = uefi.system_table.boot_services.?.freePool(@alignCast(8, buf.ptr));
138 _ = uefi.system_table.boot_services.?.freePool(@alignCast(buf.ptr));
139139}
lib/std/os/uefi/protocols/device_path_protocol.zig+13-13
......@@ -23,10 +23,10 @@ pub const DevicePathProtocol = extern struct {
2323
2424 /// Returns the next DevicePathProtocol node in the sequence, if any.
2525 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)
2727 return null;
2828
29 return @ptrCast(*DevicePathProtocol, @ptrCast([*]u8, self) + self.length);
29 return @as(*DevicePathProtocol, @ptrCast(@as([*]u8, @ptrCast(self)) + self.length));
3030 }
3131
3232 /// 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 {
4848 // DevicePathProtocol for the extra node before the end
4949 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
5353 // Pointer to the copy of the end node of the current chain, which is - 4 from the buffer
5454 // 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
5757 new.type = .Media;
5858 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
6161 // 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
6464 for (path, 0..) |s, i|
6565 ptr[i] = s;
6666
6767 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().?));
7070 end.type = .End;
7171 end.subtype = .EndEntire;
7272 end.length = @sizeOf(EndDevicePath.EndEntireDevicePath);
7373
74 return @ptrCast(*DevicePathProtocol, buf.ptr);
74 return @as(*DevicePathProtocol, @ptrCast(buf.ptr));
7575 }
7676
7777 pub fn getDevicePath(self: *const DevicePathProtocol) ?DevicePath {
......@@ -103,7 +103,7 @@ pub const DevicePathProtocol = extern struct {
103103
104104 if (self.subtype == tag_val) {
105105 // 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)));
107107 }
108108 }
109109
......@@ -332,7 +332,7 @@ pub const AcpiDevicePath = union(Subtype) {
332332 pub fn adrs(self: *const AdrDevicePath) []align(1) const u32 {
333333 // self.length is a minimum of 8 with one adr which is size 4.
334334 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];
336336 }
337337 };
338338
......@@ -550,7 +550,7 @@ pub const MessagingDevicePath = union(Subtype) {
550550
551551 pub fn serial_number(self: *const UsbWwidDevicePath) []align(1) const u16 {
552552 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];
554554 }
555555 };
556556
......@@ -943,7 +943,7 @@ pub const MediaDevicePath = union(Subtype) {
943943 length: u16 align(1),
944944
945945 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)));
947947 }
948948 };
949949
......@@ -1068,7 +1068,7 @@ pub const BiosBootSpecificationDevicePath = union(Subtype) {
10681068 status_flag: u16 align(1),
10691069
10701070 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);
10721072 }
10731073 };
10741074
lib/std/os/uefi/protocols/file_protocol.zig+2-2
......@@ -152,7 +152,7 @@ pub const FileInfo = extern struct {
152152 attribute: u64,
153153
154154 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)));
156156 }
157157
158158 pub const efi_file_read_only: u64 = 0x0000000000000001;
......@@ -182,7 +182,7 @@ pub const FileSystemInfo = extern struct {
182182 _volume_label: u16,
183183
184184 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));
186186 }
187187
188188 pub const guid align(8) = Guid{
lib/std/os/uefi/protocols/hii.zig+1-1
......@@ -39,7 +39,7 @@ pub const HIISimplifiedFontPackage = extern struct {
3939 number_of_wide_glyphs: u16,
4040
4141 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];
4343 }
4444};
4545
lib/std/os/uefi/protocols/managed_network_protocol.zig+1-1
......@@ -118,7 +118,7 @@ pub const ManagedNetworkTransmitData = extern struct {
118118 fragment_count: u16,
119119
120120 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];
122122 }
123123};
124124
lib/std/os/uefi/protocols/udp6_protocol.zig+2-2
......@@ -87,7 +87,7 @@ pub const Udp6ReceiveData = extern struct {
8787 fragment_count: u32,
8888
8989 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];
9191 }
9292};
9393
......@@ -97,7 +97,7 @@ pub const Udp6TransmitData = extern struct {
9797 fragment_count: u32,
9898
9999 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];
101101 }
102102};
103103
lib/std/os/uefi/tables/boot_services.zig+1-1
......@@ -165,7 +165,7 @@ pub const BootServices = extern struct {
165165 try self.openProtocol(
166166 handle,
167167 &protocol.guid,
168 @ptrCast(*?*anyopaque, &ptr),
168 @as(*?*anyopaque, @ptrCast(&ptr)),
169169 // Invoking handle (loaded image)
170170 uefi.handle,
171171 // Control handle (null as not a driver)
lib/std/os/wasi.zig+3-3
......@@ -103,13 +103,13 @@ pub const timespec = extern struct {
103103 const tv_sec: timestamp_t = tm / 1_000_000_000;
104104 const tv_nsec = tm - tv_sec * 1_000_000_000;
105105 return timespec{
106 .tv_sec = @intCast(time_t, tv_sec),
107 .tv_nsec = @intCast(isize, tv_nsec),
106 .tv_sec = @as(time_t, @intCast(tv_sec)),
107 .tv_nsec = @as(isize, @intCast(tv_nsec)),
108108 };
109109 }
110110
111111 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));
113113 return tm;
114114 }
115115};
lib/std/os/windows.zig+83-83
......@@ -30,7 +30,7 @@ pub const gdi32 = @import("windows/gdi32.zig");
3030pub const winmm = @import("windows/winmm.zig");
3131pub 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
3535const Self = @This();
3636
......@@ -198,9 +198,9 @@ pub fn DeviceIoControl(
198198
199199 var io: IO_STATUS_BLOCK = undefined;
200200 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;
202202 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
205205 const rc = blk: {
206206 if (is_fsctl) {
......@@ -307,7 +307,7 @@ pub fn WaitForSingleObjectEx(handle: HANDLE, milliseconds: DWORD, alertable: boo
307307
308308pub fn WaitForMultipleObjectsEx(handles: []const HANDLE, waitAll: bool, milliseconds: DWORD, alertable: bool) !u32 {
309309 assert(handles.len < MAXIMUM_WAIT_OBJECTS);
310 const nCount: DWORD = @intCast(DWORD, handles.len);
310 const nCount: DWORD = @as(DWORD, @intCast(handles.len));
311311 switch (kernel32.WaitForMultipleObjectsEx(
312312 nCount,
313313 handles.ptr,
......@@ -419,7 +419,7 @@ pub fn GetQueuedCompletionStatusEx(
419419 const success = kernel32.GetQueuedCompletionStatusEx(
420420 completion_port,
421421 completion_port_entries.ptr,
422 @intCast(ULONG, completion_port_entries.len),
422 @as(ULONG, @intCast(completion_port_entries.len)),
423423 &num_entries_removed,
424424 timeout_ms orelse INFINITE,
425425 @intFromBool(alertable),
......@@ -469,8 +469,8 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo
469469 .InternalHigh = 0,
470470 .DUMMYUNIONNAME = .{
471471 .DUMMYSTRUCTNAME = .{
472 .Offset = @truncate(u32, off),
473 .OffsetHigh = @truncate(u32, off >> 32),
472 .Offset = @as(u32, @truncate(off)),
473 .OffsetHigh = @as(u32, @truncate(off >> 32)),
474474 },
475475 },
476476 .hEvent = null,
......@@ -480,7 +480,7 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo
480480 loop.beginOneEvent();
481481 suspend {
482482 // 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);
484484 }
485485 var bytes_transferred: DWORD = undefined;
486486 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
496496 if (offset == null) {
497497 // TODO make setting the file position non-blocking
498498 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)));
500500 }
501501 return @as(usize, bytes_transferred);
502502 } else {
......@@ -510,8 +510,8 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo
510510 .InternalHigh = 0,
511511 .DUMMYUNIONNAME = .{
512512 .DUMMYSTRUCTNAME = .{
513 .Offset = @truncate(u32, off),
514 .OffsetHigh = @truncate(u32, off >> 32),
513 .Offset = @as(u32, @truncate(off)),
514 .OffsetHigh = @as(u32, @truncate(off >> 32)),
515515 },
516516 },
517517 .hEvent = null,
......@@ -563,8 +563,8 @@ pub fn WriteFile(
563563 .InternalHigh = 0,
564564 .DUMMYUNIONNAME = .{
565565 .DUMMYSTRUCTNAME = .{
566 .Offset = @truncate(u32, off),
567 .OffsetHigh = @truncate(u32, off >> 32),
566 .Offset = @as(u32, @truncate(off)),
567 .OffsetHigh = @as(u32, @truncate(off >> 32)),
568568 },
569569 },
570570 .hEvent = null,
......@@ -591,7 +591,7 @@ pub fn WriteFile(
591591 if (offset == null) {
592592 // TODO make setting the file position non-blocking
593593 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)));
595595 }
596596 return bytes_transferred;
597597 } else {
......@@ -603,8 +603,8 @@ pub fn WriteFile(
603603 .InternalHigh = 0,
604604 .DUMMYUNIONNAME = .{
605605 .DUMMYSTRUCTNAME = .{
606 .Offset = @truncate(u32, off),
607 .OffsetHigh = @truncate(u32, off >> 32),
606 .Offset = @as(u32, @truncate(off)),
607 .OffsetHigh = @as(u32, @truncate(off >> 32)),
608608 },
609609 },
610610 .hEvent = null,
......@@ -745,19 +745,19 @@ pub fn CreateSymbolicLink(
745745 const header_len = @sizeOf(ULONG) + @sizeOf(USHORT) * 2;
746746 const symlink_data = SYMLINK_DATA{
747747 .ReparseTag = IO_REPARSE_TAG_SYMLINK,
748 .ReparseDataLength = @intCast(u16, buf_len - header_len),
748 .ReparseDataLength = @as(u16, @intCast(buf_len - header_len)),
749749 .Reserved = 0,
750 .SubstituteNameOffset = @intCast(u16, target_path.len * 2),
751 .SubstituteNameLength = @intCast(u16, target_path.len * 2),
750 .SubstituteNameOffset = @as(u16, @intCast(target_path.len * 2)),
751 .SubstituteNameLength = @as(u16, @intCast(target_path.len * 2)),
752752 .PrintNameOffset = 0,
753 .PrintNameLength = @intCast(u16, target_path.len * 2),
753 .PrintNameLength = @as(u16, @intCast(target_path.len * 2)),
754754 .Flags = if (dir) |_| SYMLINK_FLAG_RELATIVE else 0,
755755 };
756756
757757 @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)));
759759 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)));
761761 _ = try DeviceIoControl(symlink_handle, FSCTL_SET_REPARSE_POINT, buffer[0..buf_len], null);
762762}
763763
......@@ -827,10 +827,10 @@ pub fn ReadLink(dir: ?HANDLE, sub_path_w: []const u16, out_buffer: []u8) ReadLin
827827 else => |e| return e,
828828 };
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]));
831831 switch (reparse_struct.ReparseTag) {
832832 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]));
834834 const offset = buf.SubstituteNameOffset >> 1;
835835 const len = buf.SubstituteNameLength >> 1;
836836 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
838838 return parseReadlinkPath(path_buf[offset..][0..len], is_relative, out_buffer);
839839 },
840840 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]));
842842 const offset = buf.SubstituteNameOffset >> 1;
843843 const len = buf.SubstituteNameLength >> 1;
844844 const path_buf = @as([*]const u16, &buf.PathBuffer);
......@@ -884,7 +884,7 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil
884884 else
885885 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));
888888 var nt_name = UNICODE_STRING{
889889 .Length = path_len_bytes,
890890 .MaximumLength = path_len_bytes,
......@@ -1020,7 +1020,7 @@ pub fn SetFilePointerEx_BEGIN(handle: HANDLE, offset: u64) SetFilePointerError!v
10201020 // "The starting point is zero or the beginning of the file. If [FILE_BEGIN]
10211021 // is specified, then the liDistanceToMove parameter is interpreted as an unsigned value."
10221022 // 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));
10241024 if (kernel32.SetFilePointerEx(handle, ipos, null, FILE_BEGIN) == 0) {
10251025 switch (kernel32.GetLastError()) {
10261026 .INVALID_PARAMETER => unreachable,
......@@ -1064,7 +1064,7 @@ pub fn SetFilePointerEx_CURRENT_get(handle: HANDLE) SetFilePointerError!u64 {
10641064 }
10651065 // Based on the docs for FILE_BEGIN, it seems that the returned signed integer
10661066 // should be interpreted as an unsigned integer.
1067 return @bitCast(u64, result);
1067 return @as(u64, @bitCast(result));
10681068}
10691069
10701070pub fn QueryObjectName(
......@@ -1073,7 +1073,7 @@ pub fn QueryObjectName(
10731073) ![]u16 {
10741074 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));
10771077 //buffer size is specified in bytes
10781078 const out_buffer_len = std.math.cast(ULONG, out_buffer_aligned.len * 2) orelse std.math.maxInt(ULONG);
10791079 //last argument would return the length required for full_buffer, not exposed here
......@@ -1197,26 +1197,26 @@ pub fn GetFinalPathNameByHandle(
11971197 };
11981198 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]));
12011201 input_struct.DeviceNameOffset = @sizeOf(MOUNTMGR_MOUNT_POINT);
1202 input_struct.DeviceNameLength = @intCast(USHORT, 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));
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], @as([*]const u8, @ptrCast(volume_name_u16.ptr)));
12041204
12051205 DeviceIoControl(mgmt_handle, IOCTL_MOUNTMGR_QUERY_POINTS, &input_buf, &output_buf) catch |err| switch (err) {
12061206 error.AccessDenied => unreachable,
12071207 else => |e| return e,
12081208 };
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(
12121212 [*]const MOUNTMGR_MOUNT_POINT,
1213 &mount_points_struct.MountPoints[0],
1213 @ptrCast(&mount_points_struct.MountPoints[0]),
12141214 )[0..mount_points_struct.NumberOfMountPoints];
12151215
12161216 for (mount_points) |mount_point| {
1217 const symlink = @ptrCast(
1217 const symlink = @as(
12181218 [*]const u16,
1219 @alignCast(@alignOf(u16), &output_buf[mount_point.SymbolicLinkNameOffset]),
1219 @ptrCast(@alignCast(&output_buf[mount_point.SymbolicLinkNameOffset])),
12201220 )[0 .. mount_point.SymbolicLinkNameLength / 2];
12211221
12221222 // 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 {
12821282 else => |err| return unexpectedError(err),
12831283 }
12841284 }
1285 return @bitCast(u64, file_size);
1285 return @as(u64, @bitCast(file_size));
12861286}
12871287
12881288pub const GetFileAttributesError = error{
......@@ -1313,7 +1313,7 @@ pub fn WSAStartup(majorVersion: u8, minorVersion: u8) !ws2_32.WSADATA {
13131313 var wsadata: ws2_32.WSADATA = undefined;
13141314 return switch (ws2_32.WSAStartup((@as(WORD, minorVersion) << 8) | majorVersion, &wsadata)) {
13151315 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))))) {
13171317 .WSASYSNOTREADY => return error.SystemNotAvailable,
13181318 .WSAVERNOTSUPPORTED => return error.VersionNotSupported,
13191319 .WSAEINPROGRESS => return error.BlockingOperationInProgress,
......@@ -1408,7 +1408,7 @@ pub fn WSASocketW(
14081408}
14091409
14101410pub 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)));
14121412}
14131413
14141414pub fn listen(s: ws2_32.SOCKET, backlog: u31) i32 {
......@@ -1427,15 +1427,15 @@ pub fn closesocket(s: ws2_32.SOCKET) !void {
14271427
14281428pub fn accept(s: ws2_32.SOCKET, name: ?*ws2_32.sockaddr, namelen: ?*ws2_32.socklen_t) ws2_32.SOCKET {
14291429 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)));
14311431}
14321432
14331433pub 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)));
14351435}
14361436
14371437pub 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)));
14391439}
14401440
14411441pub fn sendmsg(
......@@ -1447,28 +1447,28 @@ pub fn sendmsg(
14471447 if (ws2_32.WSASendMsg(s, msg, flags, &bytes_send, null, null) == ws2_32.SOCKET_ERROR) {
14481448 return ws2_32.SOCKET_ERROR;
14491449 } else {
1450 return @as(i32, @intCast(u31, bytes_send));
1450 return @as(i32, @as(u31, @intCast(bytes_send)));
14511451 }
14521452}
14531453
14541454pub 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) };
14561456 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) {
14581458 return ws2_32.SOCKET_ERROR;
14591459 } else {
1460 return @as(i32, @intCast(u31, bytes_send));
1460 return @as(i32, @as(u31, @intCast(bytes_send)));
14611461 }
14621462}
14631463
14641464pub 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 };
14661466 var bytes_received: DWORD = undefined;
14671467 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) {
14691469 return ws2_32.SOCKET_ERROR;
14701470 } else {
1471 return @as(i32, @intCast(u31, bytes_received));
1471 return @as(i32, @as(u31, @intCast(bytes_received)));
14721472 }
14731473}
14741474
......@@ -1489,9 +1489,9 @@ pub fn WSAIoctl(
14891489 s,
14901490 dwIoControlCode,
14911491 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,
14931493 outBuffer.ptr,
1494 @intCast(DWORD, outBuffer.len),
1494 @as(DWORD, @intCast(outBuffer.len)),
14951495 &bytes,
14961496 overlapped,
14971497 completionRoutine,
......@@ -1741,7 +1741,7 @@ pub fn QueryPerformanceFrequency() u64 {
17411741 var result: LARGE_INTEGER = undefined;
17421742 assert(kernel32.QueryPerformanceFrequency(&result) != 0);
17431743 // The kernel treats this integer as unsigned.
1744 return @bitCast(u64, result);
1744 return @as(u64, @bitCast(result));
17451745}
17461746
17471747pub fn QueryPerformanceCounter() u64 {
......@@ -1750,7 +1750,7 @@ pub fn QueryPerformanceCounter() u64 {
17501750 var result: LARGE_INTEGER = undefined;
17511751 assert(kernel32.QueryPerformanceCounter(&result) != 0);
17521752 // The kernel treats this integer as unsigned.
1753 return @bitCast(u64, result);
1753 return @as(u64, @bitCast(result));
17541754}
17551755
17561756pub fn InitOnceExecuteOnce(InitOnce: *INIT_ONCE, InitFn: INIT_ONCE_FN, Parameter: ?*anyopaque, Context: ?*anyopaque) void {
......@@ -1852,7 +1852,7 @@ pub fn teb() *TEB {
18521852 return switch (native_arch) {
18531853 .x86 => blk: {
18541854 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()));
18561856 } else {
18571857 break :blk asm volatile (
18581858 \\ movl %%fs:0x18, %[ptr]
......@@ -1862,7 +1862,7 @@ pub fn teb() *TEB {
18621862 },
18631863 .x86_64 => blk: {
18641864 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()));
18661866 } else {
18671867 break :blk asm volatile (
18681868 \\ movq %%gs:0x30, %[ptr]
......@@ -1894,7 +1894,7 @@ pub fn fromSysTime(hns: i64) i128 {
18941894
18951895pub fn toSysTime(ns: i128) i64 {
18961896 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);
18981898}
18991899
19001900pub fn fileTimeToNanoSeconds(ft: FILETIME) i128 {
......@@ -1904,22 +1904,22 @@ pub fn fileTimeToNanoSeconds(ft: FILETIME) i128 {
19041904
19051905/// Converts a number of nanoseconds since the POSIX epoch to a Windows FILETIME.
19061906pub fn nanoSecondsToFileTime(ns: i128) FILETIME {
1907 const adjusted = @bitCast(u64, toSysTime(ns));
1907 const adjusted = @as(u64, @bitCast(toSysTime(ns)));
19081908 return FILETIME{
1909 .dwHighDateTime = @truncate(u32, adjusted >> 32),
1910 .dwLowDateTime = @truncate(u32, adjusted),
1909 .dwHighDateTime = @as(u32, @truncate(adjusted >> 32)),
1910 .dwLowDateTime = @as(u32, @truncate(adjusted)),
19111911 };
19121912}
19131913
19141914/// Compares two WTF16 strings using RtlEqualUnicodeString
19151915pub 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));
19171917 const a_string = UNICODE_STRING{
19181918 .Length = a_bytes,
19191919 .MaximumLength = a_bytes,
19201920 .Buffer = @constCast(a.ptr),
19211921 };
1922 const b_bytes = @intCast(u16, b.len * 2);
1922 const b_bytes = @as(u16, @intCast(b.len * 2));
19231923 const b_string = UNICODE_STRING{
19241924 .Length = b_bytes,
19251925 .MaximumLength = b_bytes,
......@@ -2117,7 +2117,7 @@ pub fn wToPrefixedFileW(path: [:0]const u16) !PathSpace {
21172117 .unc_absolute => nt_prefix.len + 2,
21182118 else => nt_prefix.len,
21192119 };
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));
21212121 const path_byte_len = ntdll.RtlGetFullPathName_U(
21222122 path.ptr,
21232123 buf_len * 2,
......@@ -2263,7 +2263,7 @@ test getUnprefixedPathType {
22632263}
22642264
22652265fn 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);
22672267 if (result == 0) {
22682268 switch (kernel32.GetLastError()) {
22692269 else => |err| return unexpectedError(err),
......@@ -2284,9 +2284,9 @@ pub fn loadWinsockExtensionFunction(comptime T: type, sock: ws2_32.SOCKET, guid:
22842284 const rc = ws2_32.WSAIoctl(
22852285 sock,
22862286 ws2_32.SIO_GET_EXTENSION_FUNCTION_POINTER,
2287 @ptrCast(*const anyopaque, &guid),
2287 @as(*const anyopaque, @ptrCast(&guid)),
22882288 @sizeOf(GUID),
2289 @ptrFromInt(?*anyopaque, @intFromPtr(&function)),
2289 @as(?*anyopaque, @ptrFromInt(@intFromPtr(&function))),
22902290 @sizeOf(T),
22912291 &num_bytes,
22922292 null,
......@@ -2332,7 +2332,7 @@ pub fn unexpectedError(err: Win32Error) std.os.UnexpectedError {
23322332}
23332333
23342334pub fn unexpectedWSAError(err: ws2_32.WinsockError) std.os.UnexpectedError {
2335 return unexpectedError(@enumFromInt(Win32Error, @intFromEnum(err)));
2335 return unexpectedError(@as(Win32Error, @enumFromInt(@intFromEnum(err))));
23362336}
23372337
23382338/// 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
25302530 @intFromEnum(method);
25312531}
25322532
2533pub const INVALID_HANDLE_VALUE = @ptrFromInt(HANDLE, maxInt(usize));
2533pub const INVALID_HANDLE_VALUE = @as(HANDLE, @ptrFromInt(maxInt(usize)));
25342534
25352535pub const INVALID_FILE_ATTRIBUTES = @as(DWORD, maxInt(DWORD));
25362536
......@@ -3119,7 +3119,7 @@ pub const GUID = extern struct {
31193119 bytes[i] = (try std.fmt.charToDigit(s[hex_offset], 16)) << 4 |
31203120 try std.fmt.charToDigit(s[hex_offset + 1], 16);
31213121 }
3122 return @bitCast(GUID, bytes);
3122 return @as(GUID, @bitCast(bytes));
31233123 }
31243124};
31253125
......@@ -3150,16 +3150,16 @@ pub const KF_FLAG_SIMPLE_IDLIST = 256;
31503150pub const KF_FLAG_ALIAS_ONLY = -2147483648;
31513151
31523152pub const S_OK = 0;
3153pub const E_NOTIMPL = @bitCast(c_long, @as(c_ulong, 0x80004001));
3154pub const E_NOINTERFACE = @bitCast(c_long, @as(c_ulong, 0x80004002));
3155pub const E_POINTER = @bitCast(c_long, @as(c_ulong, 0x80004003));
3156pub const E_ABORT = @bitCast(c_long, @as(c_ulong, 0x80004004));
3157pub const E_FAIL = @bitCast(c_long, @as(c_ulong, 0x80004005));
3158pub const E_UNEXPECTED = @bitCast(c_long, @as(c_ulong, 0x8000FFFF));
3159pub const E_ACCESSDENIED = @bitCast(c_long, @as(c_ulong, 0x80070005));
3160pub const E_HANDLE = @bitCast(c_long, @as(c_ulong, 0x80070006));
3161pub const E_OUTOFMEMORY = @bitCast(c_long, @as(c_ulong, 0x8007000E));
3162pub const E_INVALIDARG = @bitCast(c_long, @as(c_ulong, 0x80070057));
3153pub const E_NOTIMPL = @as(c_long, @bitCast(@as(c_ulong, 0x80004001)));
3154pub const E_NOINTERFACE = @as(c_long, @bitCast(@as(c_ulong, 0x80004002)));
3155pub const E_POINTER = @as(c_long, @bitCast(@as(c_ulong, 0x80004003)));
3156pub const E_ABORT = @as(c_long, @bitCast(@as(c_ulong, 0x80004004)));
3157pub const E_FAIL = @as(c_long, @bitCast(@as(c_ulong, 0x80004005)));
3158pub const E_UNEXPECTED = @as(c_long, @bitCast(@as(c_ulong, 0x8000FFFF)));
3159pub const E_ACCESSDENIED = @as(c_long, @bitCast(@as(c_ulong, 0x80070005)));
3160pub const E_HANDLE = @as(c_long, @bitCast(@as(c_ulong, 0x80070006)));
3161pub const E_OUTOFMEMORY = @as(c_long, @bitCast(@as(c_ulong, 0x8007000E)));
3162pub const E_INVALIDARG = @as(c_long, @bitCast(@as(c_ulong, 0x80070057)));
31633163
31643164pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
31653165pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000;
......@@ -3221,7 +3221,7 @@ pub const LSTATUS = LONG;
32213221
32223222pub const HKEY = *opaque {};
32233223
3224pub const HKEY_LOCAL_MACHINE: HKEY = @ptrFromInt(HKEY, 0x80000002);
3224pub const HKEY_LOCAL_MACHINE: HKEY = @as(HKEY, @ptrFromInt(0x80000002));
32253225
32263226/// Combines the STANDARD_RIGHTS_REQUIRED, KEY_QUERY_VALUE, KEY_SET_VALUE, KEY_CREATE_SUB_KEY,
32273227/// KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY, and KEY_CREATE_LINK access rights.
......@@ -4685,7 +4685,7 @@ pub const KUSER_SHARED_DATA = extern struct {
46854685/// Read-only user-mode address for the shared data.
46864686/// https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/ntexapi_x/kuser_shared_data/index.htm
46874687/// 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
46904690pub fn IsProcessorFeaturePresent(feature: PF) bool {
46914691 if (@intFromEnum(feature) >= PROCESSOR_FEATURE_MAX) return false;
......@@ -4886,7 +4886,7 @@ pub fn WriteProcessMemory(handle: HANDLE, addr: ?LPVOID, buffer: []const u8) Wri
48864886 switch (ntdll.NtWriteVirtualMemory(
48874887 handle,
48884888 addr,
4889 @ptrCast(*const anyopaque, buffer.ptr),
4889 @as(*const anyopaque, @ptrCast(buffer.ptr)),
48904890 buffer.len,
48914891 &nwritten,
48924892 )) {
......@@ -4919,6 +4919,6 @@ pub fn ProcessBaseAddress(handle: HANDLE) ProcessBaseAddressError!HMODULE {
49194919
49204920 var peb_buf: [@sizeOf(PEB)]u8 align(@alignOf(PEB)) = undefined;
49214921 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));
49234923 return ppeb.ImageBaseAddress;
49244924}
lib/std/os/windows/user32.zig+1-1
......@@ -1275,7 +1275,7 @@ pub const WS_EX_LAYERED = 0x00080000;
12751275pub const WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE;
12761276pub const WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
12771277
1278pub const CW_USEDEFAULT = @bitCast(i32, @as(u32, 0x80000000));
1278pub const CW_USEDEFAULT = @as(i32, @bitCast(@as(u32, 0x80000000)));
12791279
12801280pub extern "user32" fn CreateWindowExA(dwExStyle: DWORD, lpClassName: [*:0]const u8, lpWindowName: [*:0]const u8, dwStyle: DWORD, X: i32, Y: i32, nWidth: i32, nHeight: i32, hWindParent: ?HWND, hMenu: ?HMENU, hInstance: HINSTANCE, lpParam: ?LPVOID) callconv(WINAPI) ?HWND;
12811281pub fn createWindowExA(dwExStyle: u32, lpClassName: [*:0]const u8, lpWindowName: [*:0]const u8, dwStyle: u32, X: i32, Y: i32, nWidth: i32, nHeight: i32, hWindParent: ?HWND, hMenu: ?HMENU, hInstance: HINSTANCE, lpParam: ?*anyopaque) !HWND {
lib/std/os/windows/ws2_32.zig+1-1
......@@ -21,7 +21,7 @@ const LPARAM = windows.LPARAM;
2121const FARPROC = windows.FARPROC;
2222
2323pub const SOCKET = *opaque {};
24pub const INVALID_SOCKET = @ptrFromInt(SOCKET, ~@as(usize, 0));
24pub const INVALID_SOCKET = @as(SOCKET, @ptrFromInt(~@as(usize, 0)));
2525
2626pub const GROUP = u32;
2727pub 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 {
7373 const tail_keep_bits = container_bits - (int_bits + head_keep_bits);
7474
7575 //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]));
7777 var value = value_ptr.*;
7878
7979 if (endian != native_endian) value = @byteSwap(value);
8080
8181 switch (endian) {
8282 .Big => {
83 value <<= @intCast(Shift, head_keep_bits);
84 value >>= @intCast(Shift, head_keep_bits);
85 value >>= @intCast(Shift, tail_keep_bits);
83 value <<= @as(Shift, @intCast(head_keep_bits));
84 value >>= @as(Shift, @intCast(head_keep_bits));
85 value >>= @as(Shift, @intCast(tail_keep_bits));
8686 },
8787 .Little => {
88 value <<= @intCast(Shift, tail_keep_bits);
89 value >>= @intCast(Shift, tail_keep_bits);
90 value >>= @intCast(Shift, head_keep_bits);
88 value <<= @as(Shift, @intCast(tail_keep_bits));
89 value >>= @as(Shift, @intCast(tail_keep_bits));
90 value >>= @as(Shift, @intCast(head_keep_bits));
9191 },
9292 }
9393
94 return @bitCast(Int, @truncate(UnInt, value));
94 return @as(Int, @bitCast(@as(UnInt, @truncate(value))));
9595 }
9696
9797 /// 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 {
115115 const head_keep_bits = bit_index - (start_byte * 8);
116116 const tail_keep_bits = container_bits - (int_bits + head_keep_bits);
117117 const keep_shift = switch (endian) {
118 .Big => @intCast(Shift, tail_keep_bits),
119 .Little => @intCast(Shift, head_keep_bits),
118 .Big => @as(Shift, @intCast(tail_keep_bits)),
119 .Little => @as(Shift, @intCast(head_keep_bits)),
120120 };
121121
122122 //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
125125 //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]));
127127 var target = target_ptr.*;
128128
129129 if (endian != native_endian) target = @byteSwap(target);
130130
131131 //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;
133133 const mask = ~inv_mask;
134134 target &= mask;
135135
......@@ -156,7 +156,7 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {
156156 if (length == 0) return PackedIntSliceEndian(Int, endian).init(new_bytes[0..0], 0);
157157
158158 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))));
160160 return new_slice;
161161 }
162162
......@@ -398,7 +398,7 @@ test "PackedIntArray init" {
398398 const PackedArray = PackedIntArray(u3, 8);
399399 var packed_array = PackedArray.init([_]u3{ 0, 1, 2, 3, 4, 5, 6, 7 });
400400 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));
402402}
403403
404404test "PackedIntArray initAllTo" {
......@@ -469,7 +469,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
469469
470470 var i = @as(usize, 0);
471471 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)));
473473 }
474474
475475 //slice of array
lib/std/pdb.zig+15-15
......@@ -573,7 +573,7 @@ pub const Pdb = struct {
573573 if (this_record_len % 4 != 0) {
574574 const round_to_next_4 = (this_record_len | 0x3) + 1;
575575 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)));
577577 this_record_len += march_forward_bytes;
578578 }
579579
......@@ -689,14 +689,14 @@ pub const Pdb = struct {
689689
690690 var symbol_i: usize = 0;
691691 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]));
693693 if (prefix.RecordLen < 2)
694694 return null;
695695 switch (prefix.RecordKind) {
696696 .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)]));
698698 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);
700700 }
701701 },
702702 else => {},
......@@ -715,7 +715,7 @@ pub const Pdb = struct {
715715 var skip_len: usize = undefined;
716716 const checksum_offset = module.checksum_offset orelse return error.MissingDebugInfo;
717717 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]));
719719 skip_len = subsect_hdr.Length;
720720 sect_offset += @sizeOf(DebugSubsectionHeader);
721721
......@@ -723,7 +723,7 @@ pub const Pdb = struct {
723723 .Lines => {
724724 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]));
727727 if (line_hdr.RelocSegment == 0)
728728 return error.MissingDebugInfo;
729729 line_index += @sizeOf(LineFragmentHeader);
......@@ -737,7 +737,7 @@ pub const Pdb = struct {
737737 const subsection_end_index = sect_offset + subsect_hdr.Length;
738738
739739 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]));
741741 line_index += @sizeOf(LineBlockFragmentHeader);
742742 const start_line_index = line_index;
743743
......@@ -749,7 +749,7 @@ pub const Pdb = struct {
749749 // This is done with a simple linear search.
750750 var line_i: u32 = 0;
751751 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]));
753753 line_index += @sizeOf(LineNumberEntry);
754754
755755 const vaddr_start = frag_vaddr_start + line_num_entry.Offset;
......@@ -761,7 +761,7 @@ pub const Pdb = struct {
761761 // line_i == 0 would mean that no matching LineNumberEntry was found.
762762 if (line_i > 0) {
763763 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]));
765765 const strtab_offset = @sizeOf(PDBStringTableHeader) + chksum_hdr.FileNameOffset;
766766 try self.string_table.?.seekTo(strtab_offset);
767767 const source_file_name = try self.string_table.?.reader().readUntilDelimiterAlloc(self.allocator, 0, 1024);
......@@ -771,13 +771,13 @@ pub const Pdb = struct {
771771 const column = if (has_column) blk: {
772772 const start_col_index = start_line_index + @sizeOf(LineNumberEntry) * block_hdr.NumLines;
773773 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]));
775775 break :blk col_num_entry.StartColumn;
776776 } else 0;
777777
778778 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]);
780 const flags = @ptrCast(*LineNumberEntry.Flags, &line_num_entry.Flags);
779 const line_num_entry = @as(*align(1) LineNumberEntry, @ptrCast(&subsect_info[found_line_index]));
780 const flags = @as(*LineNumberEntry.Flags, @ptrCast(&line_num_entry.Flags));
781781
782782 return debug.LineInfo{
783783 .file_name = source_file_name,
......@@ -836,7 +836,7 @@ pub const Pdb = struct {
836836 var sect_offset: usize = 0;
837837 var skip_len: usize = undefined;
838838 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]));
840840 skip_len = subsect_hdr.Length;
841841 sect_offset += @sizeOf(DebugSubsectionHeader);
842842
......@@ -1038,7 +1038,7 @@ const MsfStream = struct {
10381038 }
10391039
10401040 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));
10421042 if (block_id >= self.blocks.len) return 0; // End of Stream
10431043 var block = self.blocks[block_id];
10441044 var offset = self.pos % self.block_size;
......@@ -1069,7 +1069,7 @@ const MsfStream = struct {
10691069 }
10701070
10711071 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));
10731073 if (self.pos >= self.blocks.len * self.block_size)
10741074 return error.EOF;
10751075 }
lib/std/process.zig+9-9
......@@ -68,7 +68,7 @@ pub const EnvMap = struct {
6868 pub const EnvNameHashContext = struct {
6969 fn upcase(c: u21) u21 {
7070 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)));
7272 return c;
7373 }
7474
......@@ -80,9 +80,9 @@ pub const EnvMap = struct {
8080 while (it.nextCodepoint()) |cp| {
8181 const cp_upper = upcase(cp);
8282 h.update(&[_]u8{
83 @intCast(u8, (cp_upper >> 16) & 0xff),
84 @intCast(u8, (cp_upper >> 8) & 0xff),
85 @intCast(u8, (cp_upper >> 0) & 0xff),
83 @as(u8, @intCast((cp_upper >> 16) & 0xff)),
84 @as(u8, @intCast((cp_upper >> 8) & 0xff)),
85 @as(u8, @intCast((cp_upper >> 0) & 0xff)),
8686 });
8787 }
8888 return h.final();
......@@ -872,8 +872,8 @@ pub fn argsFree(allocator: Allocator, args_alloc: []const [:0]u8) void {
872872 for (args_alloc) |arg| {
873873 total_bytes += @sizeOf([]u8) + arg.len + 1;
874874 }
875 const unaligned_allocated_buf = @ptrCast([*]const u8, args_alloc.ptr)[0..total_bytes];
876 const aligned_allocated_buf = @alignCast(@alignOf([]u8), unaligned_allocated_buf);
875 const unaligned_allocated_buf = @as([*]const u8, @ptrCast(args_alloc.ptr))[0..total_bytes];
876 const aligned_allocated_buf: []align(@alignOf([]u8)) const u8 = @alignCast(unaligned_allocated_buf);
877877 return allocator.free(aligned_allocated_buf);
878878}
879879
......@@ -1143,7 +1143,7 @@ pub fn execve(
11431143 } else if (builtin.output_mode == .Exe) {
11441144 // Then we have Zig start code and this works.
11451145 // 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));
11471147 } else {
11481148 // TODO come up with a solution for this.
11491149 @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 {
11751175 error.NameTooLong, error.UnknownName => unreachable,
11761176 else => return error.UnknownTotalSystemMemory,
11771177 };
1178 return @intCast(usize, physmem);
1178 return @as(usize, @intCast(physmem));
11791179 },
11801180 .openbsd => {
11811181 const mib: [2]c_int = [_]c_int{
......@@ -1192,7 +1192,7 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {
11921192 else => return error.UnknownTotalSystemMemory,
11931193 };
11941194 assert(physmem >= 0);
1195 return @bitCast(usize, physmem);
1195 return @as(usize, @bitCast(physmem));
11961196 },
11971197 .windows => {
11981198 var sbi: std.os.windows.SYSTEM_BASIC_INFORMATION = undefined;
lib/std/rand.zig+29-30
......@@ -41,8 +41,7 @@ pub const Random = struct {
4141 assert(@typeInfo(@typeInfo(Ptr).Pointer.child) == .Struct); // Must point to a struct
4242 const gen = struct {
4343 fn fill(ptr: *anyopaque, buf: []u8) void {
44 const alignment = @typeInfo(Ptr).Pointer.alignment;
45 const self = @ptrCast(Ptr, @alignCast(alignment, ptr));
44 const self: Ptr = @ptrCast(@alignCast(ptr));
4645 fillFn(self, buf);
4746 }
4847 };
......@@ -97,7 +96,7 @@ pub const Random = struct {
9796 r.uintLessThan(Index, values.len);
9897
9998 const MinInt = MinArrayIndex(Index);
100 return values[@intCast(MinInt, index)];
99 return values[@as(MinInt, @intCast(index))];
101100 }
102101
103102 /// Returns a random int `i` such that `minInt(T) <= i <= maxInt(T)`.
......@@ -114,8 +113,8 @@ pub const Random = struct {
114113 // TODO: endian portability is pointless if the underlying prng isn't endian portable.
115114 // TODO: document the endian portability of this library.
116115 const byte_aligned_result = mem.readIntSliceLittle(ByteAlignedT, &rand_bytes);
117 const unsigned_result = @truncate(UnsignedT, byte_aligned_result);
118 return @bitCast(T, unsigned_result);
116 const unsigned_result = @as(UnsignedT, @truncate(byte_aligned_result));
117 return @as(T, @bitCast(unsigned_result));
119118 }
120119
121120 /// Constant-time implementation off `uintLessThan`.
......@@ -126,9 +125,9 @@ pub const Random = struct {
126125 comptime assert(bits <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!
127126 assert(0 < less_than);
128127 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)));
130129 } else {
131 return @intCast(T, limitRangeBiased(u64, r.int(u64), less_than));
130 return @as(T, @intCast(limitRangeBiased(u64, r.int(u64), less_than)));
132131 }
133132 }
134133
......@@ -156,7 +155,7 @@ pub const Random = struct {
156155 // "Lemire's (with an extra tweak from me)"
157156 var x: Small = r.int(Small);
158157 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));
160159 if (l < less_than) {
161160 var t: Small = -%less_than;
162161
......@@ -169,10 +168,10 @@ pub const Random = struct {
169168 while (l < t) {
170169 x = r.int(Small);
171170 m = @as(Large, x) * @as(Large, less_than);
172 l = @truncate(Small, m);
171 l = @as(Small, @truncate(m));
173172 }
174173 }
175 return @intCast(T, m >> small_bits);
174 return @as(T, @intCast(m >> small_bits));
176175 }
177176
178177 /// Constant-time implementation off `uintAtMost`.
......@@ -206,10 +205,10 @@ pub const Random = struct {
206205 if (info.signedness == .signed) {
207206 // Two's complement makes this math pretty easy.
208207 const UnsignedT = std.meta.Int(.unsigned, info.bits);
209 const lo = @bitCast(UnsignedT, at_least);
210 const hi = @bitCast(UnsignedT, less_than);
208 const lo = @as(UnsignedT, @bitCast(at_least));
209 const hi = @as(UnsignedT, @bitCast(less_than));
211210 const result = lo +% r.uintLessThanBiased(UnsignedT, hi -% lo);
212 return @bitCast(T, result);
211 return @as(T, @bitCast(result));
213212 } else {
214213 // The signed implementation would work fine, but we can use stricter arithmetic operators here.
215214 return at_least + r.uintLessThanBiased(T, less_than - at_least);
......@@ -225,10 +224,10 @@ pub const Random = struct {
225224 if (info.signedness == .signed) {
226225 // Two's complement makes this math pretty easy.
227226 const UnsignedT = std.meta.Int(.unsigned, info.bits);
228 const lo = @bitCast(UnsignedT, at_least);
229 const hi = @bitCast(UnsignedT, less_than);
227 const lo = @as(UnsignedT, @bitCast(at_least));
228 const hi = @as(UnsignedT, @bitCast(less_than));
230229 const result = lo +% r.uintLessThan(UnsignedT, hi -% lo);
231 return @bitCast(T, result);
230 return @as(T, @bitCast(result));
232231 } else {
233232 // The signed implementation would work fine, but we can use stricter arithmetic operators here.
234233 return at_least + r.uintLessThan(T, less_than - at_least);
......@@ -243,10 +242,10 @@ pub const Random = struct {
243242 if (info.signedness == .signed) {
244243 // Two's complement makes this math pretty easy.
245244 const UnsignedT = std.meta.Int(.unsigned, info.bits);
246 const lo = @bitCast(UnsignedT, at_least);
247 const hi = @bitCast(UnsignedT, at_most);
245 const lo = @as(UnsignedT, @bitCast(at_least));
246 const hi = @as(UnsignedT, @bitCast(at_most));
248247 const result = lo +% r.uintAtMostBiased(UnsignedT, hi -% lo);
249 return @bitCast(T, result);
248 return @as(T, @bitCast(result));
250249 } else {
251250 // The signed implementation would work fine, but we can use stricter arithmetic operators here.
252251 return at_least + r.uintAtMostBiased(T, at_most - at_least);
......@@ -262,10 +261,10 @@ pub const Random = struct {
262261 if (info.signedness == .signed) {
263262 // Two's complement makes this math pretty easy.
264263 const UnsignedT = std.meta.Int(.unsigned, info.bits);
265 const lo = @bitCast(UnsignedT, at_least);
266 const hi = @bitCast(UnsignedT, at_most);
264 const lo = @as(UnsignedT, @bitCast(at_least));
265 const hi = @as(UnsignedT, @bitCast(at_most));
267266 const result = lo +% r.uintAtMost(UnsignedT, hi -% lo);
268 return @bitCast(T, result);
267 return @as(T, @bitCast(result));
269268 } else {
270269 // The signed implementation would work fine, but we can use stricter arithmetic operators here.
271270 return at_least + r.uintAtMost(T, at_most - at_least);
......@@ -294,9 +293,9 @@ pub const Random = struct {
294293 rand_lz += @clz(r.int(u32) | 0x7FF);
295294 }
296295 }
297 const mantissa = @truncate(u23, rand);
296 const mantissa = @as(u23, @truncate(rand));
298297 const exponent = @as(u32, 126 - rand_lz) << 23;
299 return @bitCast(f32, exponent | mantissa);
298 return @as(f32, @bitCast(exponent | mantissa));
300299 },
301300 f64 => {
302301 // Use 52 random bits for the mantissa, and the rest for the exponent.
......@@ -321,7 +320,7 @@ pub const Random = struct {
321320 }
322321 const mantissa = rand & 0xFFFFFFFFFFFFF;
323322 const exponent = (1022 - rand_lz) << 52;
324 return @bitCast(f64, exponent | mantissa);
323 return @as(f64, @bitCast(exponent | mantissa));
325324 },
326325 else => @compileError("unknown floating point type"),
327326 }
......@@ -333,7 +332,7 @@ pub const Random = struct {
333332 pub fn floatNorm(r: Random, comptime T: type) T {
334333 const value = ziggurat.next_f64(r, ziggurat.NormDist);
335334 switch (T) {
336 f32 => return @floatCast(f32, value),
335 f32 => return @as(f32, @floatCast(value)),
337336 f64 => return value,
338337 else => @compileError("unknown floating point type"),
339338 }
......@@ -345,7 +344,7 @@ pub const Random = struct {
345344 pub fn floatExp(r: Random, comptime T: type) T {
346345 const value = ziggurat.next_f64(r, ziggurat.ExpDist);
347346 switch (T) {
348 f32 => return @floatCast(f32, value),
347 f32 => return @as(f32, @floatCast(value)),
349348 f64 => return value,
350349 else => @compileError("unknown floating point type"),
351350 }
......@@ -379,10 +378,10 @@ pub const Random = struct {
379378 }
380379
381380 // `i <= j < max <= maxInt(MinInt)`
382 const max = @intCast(MinInt, buf.len);
381 const max = @as(MinInt, @intCast(buf.len));
383382 var i: MinInt = 0;
384383 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)));
386385 mem.swap(T, &buf[i], &buf[j]);
387386 }
388387 }
......@@ -445,7 +444,7 @@ pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T {
445444 // http://www.pcg-random.org/posts/bounded-rands.html
446445 // "Integer Multiplication (Biased)"
447446 var m: T2 = @as(T2, random_int) * @as(T2, less_than);
448 return @intCast(T, m >> bits);
447 return @as(T, @intCast(m >> bits));
449448}
450449
451450// 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:
3838 const x = self.m[base + m1];
3939 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))];
4242 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))];
4545 self.r[self.r.len - 1 - base - m1] = self.b;
4646}
4747
......@@ -159,7 +159,7 @@ pub fn fill(self: *Isaac64, buf: []u8) void {
159159 var n = self.next();
160160 comptime var j: usize = 0;
161161 inline while (j < 8) : (j += 1) {
162 buf[i + j] = @truncate(u8, n);
162 buf[i + j] = @as(u8, @truncate(n));
163163 n >>= 8;
164164 }
165165 }
......@@ -168,7 +168,7 @@ pub fn fill(self: *Isaac64, buf: []u8) void {
168168 if (i != buf.len) {
169169 var n = self.next();
170170 while (i < buf.len) : (i += 1) {
171 buf[i] = @truncate(u8, n);
171 buf[i] = @as(u8, @truncate(n));
172172 n >>= 8;
173173 }
174174 }
lib/std/rand/Pcg.zig+5-5
......@@ -29,10 +29,10 @@ fn next(self: *Pcg) u32 {
2929 const l = self.s;
3030 self.s = l *% default_multiplier +% (self.i | 1);
3131
32 const xor_s = @truncate(u32, ((l >> 18) ^ l) >> 27);
33 const rot = @intCast(u32, l >> 59);
32 const xor_s = @as(u32, @truncate(((l >> 18) ^ l) >> 27));
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)));
3636}
3737
3838fn seed(self: *Pcg, init_s: u64) void {
......@@ -58,7 +58,7 @@ pub fn fill(self: *Pcg, buf: []u8) void {
5858 var n = self.next();
5959 comptime var j: usize = 0;
6060 inline while (j < 4) : (j += 1) {
61 buf[i + j] = @truncate(u8, n);
61 buf[i + j] = @as(u8, @truncate(n));
6262 n >>= 8;
6363 }
6464 }
......@@ -67,7 +67,7 @@ pub fn fill(self: *Pcg, buf: []u8) void {
6767 if (i != buf.len) {
6868 var n = self.next();
6969 while (i < buf.len) : (i += 1) {
70 buf[i] = @truncate(u8, n);
70 buf[i] = @as(u8, @truncate(n));
7171 n >>= 8;
7272 }
7373 }
lib/std/rand/RomuTrio.zig+4-4
......@@ -34,7 +34,7 @@ fn next(self: *RomuTrio) u64 {
3434}
3535
3636pub 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));
3838 self.x_state = seed_buf[0];
3939 self.y_state = seed_buf[1];
4040 self.z_state = seed_buf[2];
......@@ -58,7 +58,7 @@ pub fn fill(self: *RomuTrio, buf: []u8) void {
5858 var n = self.next();
5959 comptime var j: usize = 0;
6060 inline while (j < 8) : (j += 1) {
61 buf[i + j] = @truncate(u8, n);
61 buf[i + j] = @as(u8, @truncate(n));
6262 n >>= 8;
6363 }
6464 }
......@@ -67,7 +67,7 @@ pub fn fill(self: *RomuTrio, buf: []u8) void {
6767 if (i != buf.len) {
6868 var n = self.next();
6969 while (i < buf.len) : (i += 1) {
70 buf[i] = @truncate(u8, n);
70 buf[i] = @as(u8, @truncate(n));
7171 n >>= 8;
7272 }
7373 }
......@@ -122,7 +122,7 @@ test "RomuTrio fill" {
122122}
123123
124124test "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 }));
126126 const resulting_state = .{ .x = 16294208416658607535, .y = 13964609475759908645, .z = 4703697494102998476 };
127127 var r = RomuTrio.init(0);
128128 r.seedWithBuf(buf0);
lib/std/rand/Sfc64.zig+2-2
......@@ -56,7 +56,7 @@ pub fn fill(self: *Sfc64, buf: []u8) void {
5656 var n = self.next();
5757 comptime var j: usize = 0;
5858 inline while (j < 8) : (j += 1) {
59 buf[i + j] = @truncate(u8, n);
59 buf[i + j] = @as(u8, @truncate(n));
6060 n >>= 8;
6161 }
6262 }
......@@ -65,7 +65,7 @@ pub fn fill(self: *Sfc64, buf: []u8) void {
6565 if (i != buf.len) {
6666 var n = self.next();
6767 while (i < buf.len) : (i += 1) {
68 buf[i] = @truncate(u8, n);
68 buf[i] = @as(u8, @truncate(n));
6969 n >>= 8;
7070 }
7171 }
lib/std/rand/Xoroshiro128.zig+3-3
......@@ -45,7 +45,7 @@ pub fn jump(self: *Xoroshiro128) void {
4545 inline for (table) |entry| {
4646 var b: usize = 0;
4747 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) {
4949 s0 ^= self.s[0];
5050 s1 ^= self.s[1];
5151 }
......@@ -74,7 +74,7 @@ pub fn fill(self: *Xoroshiro128, buf: []u8) void {
7474 var n = self.next();
7575 comptime var j: usize = 0;
7676 inline while (j < 8) : (j += 1) {
77 buf[i + j] = @truncate(u8, n);
77 buf[i + j] = @as(u8, @truncate(n));
7878 n >>= 8;
7979 }
8080 }
......@@ -83,7 +83,7 @@ pub fn fill(self: *Xoroshiro128, buf: []u8) void {
8383 if (i != buf.len) {
8484 var n = self.next();
8585 while (i < buf.len) : (i += 1) {
86 buf[i] = @truncate(u8, n);
86 buf[i] = @as(u8, @truncate(n));
8787 n >>= 8;
8888 }
8989 }
lib/std/rand/Xoshiro256.zig+5-5
......@@ -46,13 +46,13 @@ pub fn jump(self: *Xoshiro256) void {
4646 var table: u256 = 0x39abdc4529b1661ca9582618e03fc9aad5a61266f0c9392c180ec6d33cfd0aba;
4747
4848 while (table != 0) : (table >>= 1) {
49 if (@truncate(u1, table) != 0) {
50 s ^= @bitCast(u256, self.s);
49 if (@as(u1, @truncate(table)) != 0) {
50 s ^= @as(u256, @bitCast(self.s));
5151 }
5252 _ = self.next();
5353 }
5454
55 self.s = @bitCast([4]u64, s);
55 self.s = @as([4]u64, @bitCast(s));
5656}
5757
5858pub fn seed(self: *Xoshiro256, init_s: u64) void {
......@@ -74,7 +74,7 @@ pub fn fill(self: *Xoshiro256, buf: []u8) void {
7474 var n = self.next();
7575 comptime var j: usize = 0;
7676 inline while (j < 8) : (j += 1) {
77 buf[i + j] = @truncate(u8, n);
77 buf[i + j] = @as(u8, @truncate(n));
7878 n >>= 8;
7979 }
8080 }
......@@ -83,7 +83,7 @@ pub fn fill(self: *Xoshiro256, buf: []u8) void {
8383 if (i != buf.len) {
8484 var n = self.next();
8585 while (i < buf.len) : (i += 1) {
86 buf[i] = @truncate(u8, n);
86 buf[i] = @as(u8, @truncate(n));
8787 n >>= 8;
8888 }
8989 }
lib/std/rand/benchmark.zig+2-2
......@@ -91,8 +91,8 @@ pub fn benchmark(comptime H: anytype, bytes: usize, comptime block_size: usize)
9191 }
9292 const end = timer.read();
9393
94 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;
95 const throughput = @intFromFloat(u64, @floatFromInt(f64, bytes) / elapsed_s);
94 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
95 const throughput = @as(u64, @intFromFloat(@as(f64, @floatFromInt(bytes)) / elapsed_s));
9696
9797 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" {
332332 while (i < num_numbers) : (i += 1) {
333333 const rand_f32 = random.float(f32);
334334 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)))));
336336 if (f32_put.found_existing) {
337337 f32_put.value_ptr.* += 1;
338338 } else {
339339 f32_put.value_ptr.* = 1;
340340 }
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)))));
342342 if (f64_put.found_existing) {
343343 f64_put.value_ptr.* += 1;
344344 } else {
......@@ -352,8 +352,8 @@ test "Random float chi-square goodness of fit" {
352352 {
353353 var j: u32 = 0;
354354 while (j < num_buckets) : (j += 1) {
355 const count = @floatFromInt(f64, (if (f32_hist.get(j)) |v| v else 0));
356 const expected = @floatFromInt(f64, num_numbers) / @floatFromInt(f64, num_buckets);
355 const count = @as(f64, @floatFromInt((if (f32_hist.get(j)) |v| v else 0)));
356 const expected = @as(f64, @floatFromInt(num_numbers)) / @as(f64, @floatFromInt(num_buckets));
357357 const delta = count - expected;
358358 const variance = (delta * delta) / expected;
359359 f32_total_variance += variance;
......@@ -363,8 +363,8 @@ test "Random float chi-square goodness of fit" {
363363 {
364364 var j: u64 = 0;
365365 while (j < num_buckets) : (j += 1) {
366 const count = @floatFromInt(f64, (if (f64_hist.get(j)) |v| v else 0));
367 const expected = @floatFromInt(f64, num_numbers) / @floatFromInt(f64, num_buckets);
366 const count = @as(f64, @floatFromInt((if (f64_hist.get(j)) |v| v else 0)));
367 const expected = @as(f64, @floatFromInt(num_numbers)) / @as(f64, @floatFromInt(num_buckets));
368368 const delta = count - expected;
369369 const variance = (delta * delta) / expected;
370370 f64_total_variance += variance;
......@@ -421,13 +421,13 @@ fn testRange(r: Random, start: i8, end: i8) !void {
421421 try testRangeBias(r, start, end, false);
422422}
423423fn 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)));
425425 var values_buffer = [_]bool{false} ** 0x100;
426426 const values = values_buffer[0..count];
427427 var i: usize = 0;
428428 while (i < count) {
429429 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));
431431 if (!values[index]) {
432432 i += 1;
433433 values[index] = true;
lib/std/rand/ziggurat.zig+3-3
......@@ -18,17 +18,17 @@ pub fn next_f64(random: Random, comptime tables: ZigTable) f64 {
1818 // We manually construct a float from parts as we can avoid an extra random lookup here by
1919 // using the unused exponent for the lookup table entry.
2020 const bits = random.int(u64);
21 const i = @as(usize, @truncate(u8, bits));
21 const i = @as(usize, @as(u8, @truncate(bits)));
2222
2323 const u = blk: {
2424 if (tables.is_symmetric) {
2525 // Generate a value in the range [2, 4) and scale into [-1, 1)
2626 const repr = ((0x3ff + 1) << 52) | (bits >> 12);
27 break :blk @bitCast(f64, repr) - 3.0;
27 break :blk @as(f64, @bitCast(repr)) - 3.0;
2828 } else {
2929 // Generate a value in the range [1, 2) and scale into (0, 1)
3030 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);
3232 }
3333 };
3434
lib/std/segmented_list.zig+8-8
......@@ -107,7 +107,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
107107 }
108108
109109 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);
111111 allocator.free(self.dynamic_segments);
112112 self.* = undefined;
113113 }
......@@ -171,7 +171,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
171171 /// TODO update this and related methods to match the conventions set by ArrayList
172172 pub fn setCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
173173 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)))) {
175175 return self.shrinkCapacity(allocator, new_capacity);
176176 }
177177 }
......@@ -181,7 +181,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
181181 /// Only grows capacity, or retains current capacity.
182182 pub fn growCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
183183 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));
185185 if (new_cap_shelf_count <= old_shelf_count) return;
186186
187187 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
206206 /// It may fail to reduce the capacity in which case the capacity will remain unchanged.
207207 pub fn shrinkCapacity(self: *Self, allocator: Allocator, new_capacity: usize) void {
208208 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));
210210 self.freeShelves(allocator, len, 0);
211211 allocator.free(self.dynamic_segments);
212212 self.dynamic_segments = &[_][*]T{};
......@@ -214,7 +214,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
214214 }
215215
216216 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));
218218 assert(new_cap_shelf_count <= old_shelf_count);
219219 if (new_cap_shelf_count == old_shelf_count) return;
220220
......@@ -424,7 +424,7 @@ fn testSegmentedList(comptime prealloc: usize) !void {
424424 {
425425 var i: usize = 0;
426426 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)));
428428 try testing.expect(list.len == i + 1);
429429 }
430430 }
......@@ -432,7 +432,7 @@ fn testSegmentedList(comptime prealloc: usize) !void {
432432 {
433433 var i: usize = 0;
434434 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)));
436436 }
437437 }
438438
......@@ -492,7 +492,7 @@ fn testSegmentedList(comptime prealloc: usize) !void {
492492 var i: i32 = 0;
493493 while (i < 100) : (i += 1) {
494494 try list.append(testing.allocator, i + 1);
495 control[@intCast(usize, i)] = i + 1;
495 control[@as(usize, @intCast(i))] = i + 1;
496496 }
497497
498498 @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) {
9393 var out: [len]T = undefined;
9494 for (&out, 0..) |*element, i| {
9595 element.* = switch (@typeInfo(T)) {
96 .Int => @intCast(T, i),
97 .Float => @floatFromInt(T, i),
96 .Int => @as(T, @intCast(i)),
97 .Float => @as(T, @floatFromInt(i)),
9898 else => @compileError("Can't use type " ++ @typeName(T) ++ " in iota."),
9999 };
100100 }
......@@ -107,7 +107,7 @@ pub inline fn iota(comptime T: type, comptime len: usize) @Vector(len, T) {
107107pub fn repeat(comptime len: usize, vec: anytype) @Vector(len, std.meta.Child(@TypeOf(vec))) {
108108 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))))));
111111}
112112
113113/// 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
139139 const a_vec_count = (1 + vecs_arr.len) >> 1;
140140 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]).*);
143 const b = interlace(@ptrCast(*const [b_vec_count]VecType, vecs_arr[a_vec_count..]).*);
142 const a = interlace(@as(*const [a_vec_count]VecType, @ptrCast(vecs_arr[0..a_vec_count])).*);
143 const b = interlace(@as(*const [b_vec_count]VecType, @ptrCast(vecs_arr[a_vec_count..])).*);
144144
145145 const a_len = vectorLength(@TypeOf(a));
146146 const b_len = vectorLength(@TypeOf(b));
......@@ -148,10 +148,10 @@ pub fn interlace(vecs: anytype) @Vector(vectorLength(@TypeOf(vecs[0])) * vecs.le
148148
149149 const indices = comptime blk: {
150150 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))));
152152 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));
154 const b_indices = shiftElementsRight(count_up - cycle * @splat(len, @intCast(i32, a_vec_count)), a_vec_count, 0);
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, @as(i32, @intCast(a_vec_count))), a_vec_count, 0);
155155 break :blk @select(i32, select_mask, a_indices, ~b_indices);
156156 };
157157
......@@ -174,7 +174,7 @@ pub fn deinterlace(
174174
175175 comptime var i: usize = 0; // for-loops don't work for this, apparently.
176176 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)));
178178 out[i] = @shuffle(Child, interlaced, undefined, indices);
179179 }
180180
......@@ -189,9 +189,9 @@ pub fn extract(
189189 const Child = std.meta.Child(@TypeOf(vec));
190190 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))));
195195}
196196
197197test "vector patterns" {
......@@ -263,7 +263,7 @@ pub fn reverseOrder(vec: anytype) @TypeOf(vec) {
263263 const Child = std.meta.Child(@TypeOf(vec));
264264 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));
267267}
268268
269269test "vector shifting" {
lib/std/sort/pdq.zig+2-2
......@@ -251,7 +251,7 @@ fn breakPatterns(a: usize, b: usize, context: anytype) void {
251251 const len = b - a;
252252 if (len < 8) return;
253253
254 var rand = @intCast(u64, len);
254 var rand = @as(u64, @intCast(len));
255255 const modulus = math.ceilPowerOfTwoAssert(u64, len);
256256
257257 var i = a + (len / 4) * 2 - 1;
......@@ -261,7 +261,7 @@ fn breakPatterns(a: usize, b: usize, context: anytype) void {
261261 rand ^= rand >> 7;
262262 rand ^= rand << 17;
263263
264 var other = @intCast(usize, rand & (modulus - 1));
264 var other = @as(usize, @intCast(rand & (modulus - 1)));
265265 if (other >= len) other -= len;
266266 context.swap(i, a + other);
267267 }
lib/std/start.zig+12-12
......@@ -190,7 +190,7 @@ fn exit2(code: usize) noreturn {
190190 else => @compileError("TODO"),
191191 },
192192 .windows => {
193 ExitProcess(@truncate(u32, code));
193 ExitProcess(@as(u32, @truncate(code)));
194194 },
195195 else => @compileError("TODO"),
196196 }
......@@ -387,23 +387,23 @@ fn wWinMainCRTStartup() callconv(std.os.windows.WINAPI) noreturn {
387387 std.debug.maybeEnableSegfaultHandler();
388388
389389 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)));
391391}
392392
393393fn posixCallMainAndExit() callconv(.C) noreturn {
394394 @setAlignStack(16);
395395
396396 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));
400400 var envp_count: usize = 0;
401401 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
404404 if (native_os == .linux) {
405405 // 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));
407407 std.os.linux.elf_aux_maybe = auxv;
408408
409409 var at_hwcap: usize = 0;
......@@ -419,7 +419,7 @@ fn posixCallMainAndExit() callconv(.C) noreturn {
419419 else => continue,
420420 }
421421 }
422 break :init @ptrFromInt([*]elf.Phdr, at_phdr)[0..at_phnum];
422 break :init @as([*]elf.Phdr, @ptrFromInt(at_phdr))[0..at_phnum];
423423 };
424424
425425 // 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 {
495495fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) callconv(.C) c_int {
496496 var env_count: usize = 0;
497497 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
500500 if (builtin.os.tag == .linux) {
501501 const at_phdr = std.c.getauxval(elf.AT_PHDR);
502502 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];
504504 expandStackSize(phdrs);
505505 }
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 });
508508}
509509
510510fn 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))];
512512 return @call(.always_inline, callMain, .{});
513513}
514514
......@@ -629,7 +629,7 @@ pub fn callMain() u8 {
629629
630630pub fn call_wWinMain() std.os.windows.INT {
631631 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).?));
633633 const lpCmdLine = std.os.windows.kernel32.GetCommandLineW();
634634
635635 // 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{
4242 .StartAddressOfRawData = &_tls_start,
4343 .EndAddressOfRawData = &_tls_end,
4444 .AddressOfIndex = &_tls_index,
45 .AddressOfCallBacks = @ptrCast(*anyopaque, &__xl_a),
45 .AddressOfCallBacks = @as(*anyopaque, @ptrCast(&__xl_a)),
4646 .SizeOfZeroFill = 0,
4747 .Characteristics = 0,
4848};
lib/std/tar.zig+7-7
......@@ -70,8 +70,8 @@ pub const Header = struct {
7070 }
7171
7272 pub fn fileType(header: Header) FileType {
73 const result = @enumFromInt(FileType, header.bytes[156]);
74 return if (result == @enumFromInt(FileType, 0)) .normal else result;
73 const result = @as(FileType, @enumFromInt(header.bytes[156]));
74 return if (result == @as(FileType, @enumFromInt(0))) .normal else result;
7575 }
7676
7777 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
117117 start += 512;
118118 const file_size = try header.fileSize();
119119 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));
121121 const unstripped_file_name = try header.fullFileName(&file_name_buffer);
122122 switch (header.fileType()) {
123123 .directory => {
......@@ -146,14 +146,14 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
146146 }
147147 // Ask for the rounded up file size + 512 for the next header.
148148 // TODO: https://github.com/ziglang/zig/issues/14039
149 const ask = @intCast(usize, @min(
149 const ask = @as(usize, @intCast(@min(
150150 buffer.len - end,
151151 rounded_file_size + 512 - file_off -| (end - start),
152 ));
152 )));
153153 end += try reader.readAtLeast(buffer[end..], ask);
154154 if (end - start < ask) return error.UnexpectedEndOfStream;
155155 // 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)))];
157157 try file.writeAll(slice);
158158 file_off += slice.len;
159159 start += slice.len;
......@@ -167,7 +167,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
167167 },
168168 .global_extended_header, .extended_header => {
169169 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));
171171 },
172172 .hard_link => return error.TarUnsupportedFileType,
173173 .symbolic_link => return error.TarUnsupportedFileType,
lib/std/target.zig+9-9
......@@ -711,14 +711,14 @@ pub const Target = struct {
711711
712712 pub fn isEnabled(set: Set, arch_feature_index: Index) bool {
713713 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)));
715715 return (set.ints[usize_index] & (@as(usize, 1) << bit_index)) != 0;
716716 }
717717
718718 /// Adds the specified feature but not its dependencies.
719719 pub fn addFeature(set: *Set, arch_feature_index: Index) void {
720720 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)));
722722 set.ints[usize_index] |= @as(usize, 1) << bit_index;
723723 }
724724
......@@ -730,7 +730,7 @@ pub const Target = struct {
730730 /// Removes the specified feature but not its dependents.
731731 pub fn removeFeature(set: *Set, arch_feature_index: Index) void {
732732 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)));
734734 set.ints[usize_index] &= ~(@as(usize, 1) << bit_index);
735735 }
736736
......@@ -745,7 +745,7 @@ pub const Target = struct {
745745 var old = set.ints;
746746 while (true) {
747747 for (all_features_list, 0..) |feature, index_usize| {
748 const index = @intCast(Index, index_usize);
748 const index = @as(Index, @intCast(index_usize));
749749 if (set.isEnabled(index)) {
750750 set.addFeatureSet(feature.dependencies);
751751 }
......@@ -757,7 +757,7 @@ pub const Target = struct {
757757 }
758758
759759 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));
761761 }
762762
763763 pub fn eql(set: Set, other_set: Set) bool {
......@@ -1526,7 +1526,7 @@ pub const Target = struct {
15261526 pub fn set(self: *DynamicLinker, dl_or_null: ?[]const u8) void {
15271527 if (dl_or_null) |dl| {
15281528 @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));
15301530 } else {
15311531 self.max_byte = null;
15321532 }
......@@ -1537,12 +1537,12 @@ pub const Target = struct {
15371537 var result: DynamicLinker = .{};
15381538 const S = struct {
15391539 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));
15411541 return r.*;
15421542 }
15431543 fn copy(r: *DynamicLinker, s: []const u8) DynamicLinker {
15441544 @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));
15461546 return r.*;
15471547 }
15481548 };
......@@ -1970,7 +1970,7 @@ pub const Target = struct {
19701970 16 => 2,
19711971 32 => 4,
19721972 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)))),
19741974 128 => 16,
19751975 else => unreachable,
19761976 },
lib/std/testing/failing_allocator.zig+3-3
......@@ -63,7 +63,7 @@ pub const FailingAllocator = struct {
6363 log2_ptr_align: u8,
6464 return_address: usize,
6565 ) ?[*]u8 {
66 const self = @ptrCast(*FailingAllocator, @alignCast(@alignOf(FailingAllocator), ctx));
66 const self: *FailingAllocator = @ptrCast(@alignCast(ctx));
6767 if (self.index == self.fail_index) {
6868 if (!self.has_induced_failure) {
6969 @memset(&self.stack_addresses, 0);
......@@ -91,7 +91,7 @@ pub const FailingAllocator = struct {
9191 new_len: usize,
9292 ra: usize,
9393 ) bool {
94 const self = @ptrCast(*FailingAllocator, @alignCast(@alignOf(FailingAllocator), ctx));
94 const self: *FailingAllocator = @ptrCast(@alignCast(ctx));
9595 if (!self.internal_allocator.rawResize(old_mem, log2_old_align, new_len, ra))
9696 return false;
9797 if (new_len < old_mem.len) {
......@@ -108,7 +108,7 @@ pub const FailingAllocator = struct {
108108 log2_old_align: u8,
109109 ra: usize,
110110 ) void {
111 const self = @ptrCast(*FailingAllocator, @alignCast(@alignOf(FailingAllocator), ctx));
111 const self: *FailingAllocator = @ptrCast(@alignCast(ctx));
112112 self.internal_allocator.rawFree(old_mem, log2_old_align, ra);
113113 self.deallocations += 1;
114114 self.freed_bytes += old_mem.len;
lib/std/time.zig+8-8
......@@ -70,7 +70,7 @@ pub fn timestamp() i64 {
7070/// before the epoch.
7171/// See `std.os.clock_gettime` for a POSIX timestamp.
7272pub fn milliTimestamp() i64 {
73 return @intCast(i64, @divFloor(nanoTimestamp(), ns_per_ms));
73 return @as(i64, @intCast(@divFloor(nanoTimestamp(), ns_per_ms)));
7474}
7575
7676/// Get a calendar timestamp, in microseconds, relative to UTC 1970-01-01.
......@@ -79,7 +79,7 @@ pub fn milliTimestamp() i64 {
7979/// before the epoch.
8080/// See `std.os.clock_gettime` for a POSIX timestamp.
8181pub fn microTimestamp() i64 {
82 return @intCast(i64, @divFloor(nanoTimestamp(), ns_per_us));
82 return @as(i64, @intCast(@divFloor(nanoTimestamp(), ns_per_us)));
8383}
8484
8585/// Get a calendar timestamp, in nanoseconds, relative to UTC 1970-01-01.
......@@ -96,7 +96,7 @@ pub fn nanoTimestamp() i128 {
9696 var ft: os.windows.FILETIME = undefined;
9797 os.windows.kernel32.GetSystemTimeAsFileTime(&ft);
9898 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;
100100 }
101101
102102 if (builtin.os.tag == .wasi and !builtin.link_libc) {
......@@ -239,9 +239,9 @@ pub const Instant = struct {
239239 }
240240
241241 // 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));
243243 const result = (@as(u96, qpc) * scale) >> 32;
244 return @truncate(u64, result);
244 return @as(u64, @truncate(result));
245245 }
246246
247247 // WASI timestamps are directly in nanoseconds
......@@ -250,9 +250,9 @@ pub const Instant = struct {
250250 }
251251
252252 // Convert timespec diff to ns
253 const seconds = @intCast(u64, self.timestamp.tv_sec - earlier.timestamp.tv_sec);
254 const elapsed = (seconds * ns_per_s) + @intCast(u32, self.timestamp.tv_nsec);
255 return elapsed - @intCast(u32, earlier.timestamp.tv_nsec);
253 const seconds = @as(u64, @intCast(self.timestamp.tv_sec - earlier.timestamp.tv_sec));
254 const elapsed = (seconds * ns_per_s) + @as(u32, @intCast(self.timestamp.tv_nsec));
255 return elapsed - @as(u32, @intCast(earlier.timestamp.tv_nsec));
256256 }
257257};
258258
lib/std/time/epoch.zig+6-6
......@@ -122,9 +122,9 @@ pub const YearAndDay = struct {
122122 if (days_left < days_in_month)
123123 break;
124124 days_left -= days_in_month;
125 month = @enumFromInt(Month, @intFromEnum(month) + 1);
125 month = @as(Month, @enumFromInt(@intFromEnum(month) + 1));
126126 }
127 return .{ .month = month, .day_index = @intCast(u5, days_left) };
127 return .{ .month = month, .day_index = @as(u5, @intCast(days_left)) };
128128 }
129129};
130130
......@@ -146,7 +146,7 @@ pub const EpochDay = struct {
146146 year_day -= year_size;
147147 year += 1;
148148 }
149 return .{ .year = year, .day = @intCast(u9, year_day) };
149 return .{ .year = year, .day = @as(u9, @intCast(year_day)) };
150150 }
151151};
152152
......@@ -156,11 +156,11 @@ pub const DaySeconds = struct {
156156
157157 /// the number of hours past the start of the day (0 to 23)
158158 pub fn getHoursIntoDay(self: DaySeconds) u5 {
159 return @intCast(u5, @divTrunc(self.secs, 3600));
159 return @as(u5, @intCast(@divTrunc(self.secs, 3600)));
160160 }
161161 /// the number of minutes past the hour (0 to 59)
162162 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)));
164164 }
165165 /// the number of seconds past the start of the minute (0 to 59)
166166 pub fn getSecondsIntoMinute(self: DaySeconds) u6 {
......@@ -175,7 +175,7 @@ pub const EpochSeconds = struct {
175175 /// Returns the number of days since the epoch as an EpochDay.
176176 /// Use EpochDay to get information about the day of this time.
177177 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))) };
179179 }
180180
181181 /// Returns the number of seconds into the day as DaySeconds.
lib/std/tz.zig+2-2
......@@ -155,8 +155,8 @@ pub const Tz = struct {
155155 if (corr > std.math.maxInt(i16)) return error.Malformed; // Unreasonably large correction
156156
157157 leapseconds[i] = .{
158 .occurrence = @intCast(i48, occur),
159 .correction = @intCast(i16, corr),
158 .occurrence = @as(i48, @intCast(occur)),
159 .correction = @as(i16, @intCast(corr)),
160160 };
161161 }
162162
lib/std/unicode.zig+16-16
......@@ -45,22 +45,22 @@ pub fn utf8Encode(c: u21, out: []u8) !u3 {
4545 // - Increasing the initial shift by 6 each time
4646 // - Each time after the first shorten the shifted
4747 // value to a max of 0b111111 (63)
48 1 => out[0] = @intCast(u8, c), // Can just do 0 + codepoint for initial range
48 1 => out[0] = @as(u8, @intCast(c)), // Can just do 0 + codepoint for initial range
4949 2 => {
50 out[0] = @intCast(u8, 0b11000000 | (c >> 6));
51 out[1] = @intCast(u8, 0b10000000 | (c & 0b111111));
50 out[0] = @as(u8, @intCast(0b11000000 | (c >> 6)));
51 out[1] = @as(u8, @intCast(0b10000000 | (c & 0b111111)));
5252 },
5353 3 => {
5454 if (0xd800 <= c and c <= 0xdfff) return error.Utf8CannotEncodeSurrogateHalf;
55 out[0] = @intCast(u8, 0b11100000 | (c >> 12));
56 out[1] = @intCast(u8, 0b10000000 | ((c >> 6) & 0b111111));
57 out[2] = @intCast(u8, 0b10000000 | (c & 0b111111));
55 out[0] = @as(u8, @intCast(0b11100000 | (c >> 12)));
56 out[1] = @as(u8, @intCast(0b10000000 | ((c >> 6) & 0b111111)));
57 out[2] = @as(u8, @intCast(0b10000000 | (c & 0b111111)));
5858 },
5959 4 => {
60 out[0] = @intCast(u8, 0b11110000 | (c >> 18));
61 out[1] = @intCast(u8, 0b10000000 | ((c >> 12) & 0b111111));
62 out[2] = @intCast(u8, 0b10000000 | ((c >> 6) & 0b111111));
63 out[3] = @intCast(u8, 0b10000000 | (c & 0b111111));
60 out[0] = @as(u8, @intCast(0b11110000 | (c >> 18)));
61 out[1] = @as(u8, @intCast(0b10000000 | ((c >> 12) & 0b111111)));
62 out[2] = @as(u8, @intCast(0b10000000 | ((c >> 6) & 0b111111)));
63 out[3] = @as(u8, @intCast(0b10000000 | (c & 0b111111)));
6464 },
6565 else => unreachable,
6666 }
......@@ -695,11 +695,11 @@ pub fn utf8ToUtf16LeWithNull(allocator: mem.Allocator, utf8: []const u8) ![:0]u1
695695 var it = view.iterator();
696696 while (it.nextCodepoint()) |codepoint| {
697697 if (codepoint < 0x10000) {
698 const short = @intCast(u16, codepoint);
698 const short = @as(u16, @intCast(codepoint));
699699 try result.append(mem.nativeToLittle(u16, short));
700700 } else {
701 const high = @intCast(u16, (codepoint - 0x10000) >> 10) + 0xD800;
702 const low = @intCast(u16, codepoint & 0x3FF) + 0xDC00;
701 const high = @as(u16, @intCast((codepoint - 0x10000) >> 10)) + 0xD800;
702 const low = @as(u16, @intCast(codepoint & 0x3FF)) + 0xDC00;
703703 var out: [2]u16 = undefined;
704704 out[0] = mem.nativeToLittle(u16, high);
705705 out[1] = mem.nativeToLittle(u16, low);
......@@ -720,12 +720,12 @@ pub fn utf8ToUtf16Le(utf16le: []u16, utf8: []const u8) !usize {
720720 const next_src_i = src_i + n;
721721 const codepoint = utf8Decode(utf8[src_i..next_src_i]) catch return error.InvalidUtf8;
722722 if (codepoint < 0x10000) {
723 const short = @intCast(u16, codepoint);
723 const short = @as(u16, @intCast(codepoint));
724724 utf16le[dest_i] = mem.nativeToLittle(u16, short);
725725 dest_i += 1;
726726 } else {
727 const high = @intCast(u16, (codepoint - 0x10000) >> 10) + 0xD800;
728 const low = @intCast(u16, codepoint & 0x3FF) + 0xDC00;
727 const high = @as(u16, @intCast((codepoint - 0x10000) >> 10)) + 0xD800;
728 const low = @as(u16, @intCast(codepoint & 0x3FF)) + 0xDC00;
729729 utf16le[dest_i] = mem.nativeToLittle(u16, high);
730730 utf16le[dest_i + 1] = mem.nativeToLittle(u16, low);
731731 dest_i += 2;
lib/std/unicode/throughput_test.zig+2-2
......@@ -32,8 +32,8 @@ fn benchmarkCodepointCount(buf: []const u8) !ResultCount {
3232 }
3333 const end = timer.read();
3434
35 const elapsed_s = @floatFromInt(f64, end - start) / time.ns_per_s;
36 const throughput = @intFromFloat(u64, @floatFromInt(f64, bytes) / elapsed_s);
35 const elapsed_s = @as(f64, @floatFromInt(end - start)) / time.ns_per_s;
36 const throughput = @as(u64, @intFromFloat(@as(f64, @floatFromInt(bytes)) / elapsed_s));
3737
3838 return ResultCount{ .count = r, .throughput = throughput };
3939}
lib/std/valgrind.zig+1-1
......@@ -94,7 +94,7 @@ pub fn IsTool(base: [2]u8, code: usize) bool {
9494}
9595
9696fn 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);
9898}
9999
100100fn 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) {
1111};
1212
1313fn 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);
1515}
1616
1717fn 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) {
2121};
2222
2323fn 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);
2525}
2626
2727fn 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
3131/// Mark memory at qzz.ptr as unaddressable for qzz.len bytes.
3232/// This returns -1 when run on Valgrind and 0 otherwise.
3333pub fn makeMemNoAccess(qzz: []u8) i1 {
34 return @intCast(i1, doMemCheckClientRequestExpr(0, // default return
35 .MakeMemNoAccess, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0));
34 return @as(i1, @intCast(doMemCheckClientRequestExpr(0, // default return
35 .MakeMemNoAccess, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0)));
3636}
3737
3838/// Similarly, mark memory at qzz.ptr as addressable but undefined
3939/// for qzz.len bytes.
4040/// This returns -1 when run on Valgrind and 0 otherwise.
4141pub fn makeMemUndefined(qzz: []u8) i1 {
42 return @intCast(i1, doMemCheckClientRequestExpr(0, // default return
43 .MakeMemUndefined, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0));
42 return @as(i1, @intCast(doMemCheckClientRequestExpr(0, // default return
43 .MakeMemUndefined, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0)));
4444}
4545
4646/// Similarly, mark memory at qzz.ptr as addressable and defined
4747/// for qzz.len bytes.
4848pub fn makeMemDefined(qzz: []u8) i1 {
4949 // This returns -1 when run on Valgrind and 0 otherwise.
50 return @intCast(i1, doMemCheckClientRequestExpr(0, // default return
51 .MakeMemDefined, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0));
50 return @as(i1, @intCast(doMemCheckClientRequestExpr(0, // default return
51 .MakeMemDefined, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0)));
5252}
5353
5454/// Similar to makeMemDefined except that addressability is
......@@ -56,8 +56,8 @@ pub fn makeMemDefined(qzz: []u8) i1 {
5656/// but those which are not addressable are left unchanged.
5757/// This returns -1 when run on Valgrind and 0 otherwise.
5858pub fn makeMemDefinedIfAddressable(qzz: []u8) i1 {
59 return @intCast(i1, doMemCheckClientRequestExpr(0, // default return
60 .MakeMemDefinedIfAddressable, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0));
59 return @as(i1, @intCast(doMemCheckClientRequestExpr(0, // default return
60 .MakeMemDefinedIfAddressable, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0)));
6161}
6262
6363/// Create a block-description handle. The description is an ascii
......@@ -195,7 +195,7 @@ test "countLeakBlocks" {
195195/// impossible to segfault your system by using this call.
196196pub fn getVbits(zza: []u8, zzvbits: []u8) u2 {
197197 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)));
199199}
200200
201201/// Set the validity data for addresses zza, copying it
......@@ -208,7 +208,7 @@ pub fn getVbits(zza: []u8, zzvbits: []u8) u2 {
208208/// impossible to segfault your system by using this call.
209209pub fn setVbits(zzvbits: []u8, zza: []u8) u2 {
210210 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)));
212212}
213213
214214/// 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 {
3636}
3737
3838pub 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));
4040}
4141
4242pub 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
6262 const token = tokenizer.next();
6363 try tokens.append(gpa, .{
6464 .tag = token.tag,
65 .start = @intCast(u32, token.loc.start),
65 .start = @as(u32, @intCast(token.loc.start)),
6666 });
6767 if (token.tag == .eof) break;
6868 }
......@@ -123,7 +123,7 @@ pub fn renderToArrayList(tree: Ast, buffer: *std.ArrayList(u8)) RenderError!void
123123/// should point after the token in the error message.
124124pub fn errorOffset(tree: Ast, parse_error: Error) u32 {
125125 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))
127127 else
128128 0;
129129}
......@@ -772,7 +772,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
772772 var n = node;
773773 var end_offset: TokenIndex = 0;
774774 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
777777 .@"usingnamespace",
778778 .bool_not,
......@@ -1288,7 +1288,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
12881288 n = extra.else_expr;
12891289 },
12901290 .@"for" => {
1291 const extra = @bitCast(Node.For, datas[n].rhs);
1291 const extra = @as(Node.For, @bitCast(datas[n].rhs));
12921292 n = tree.extra_data[datas[n].lhs + extra.inputs + @intFromBool(extra.has_else)];
12931293 },
12941294 .@"suspend" => {
......@@ -1955,7 +1955,7 @@ pub fn forSimple(tree: Ast, node: Node.Index) full.For {
19551955
19561956pub fn forFull(tree: Ast, node: Node.Index) full.For {
19571957 const data = tree.nodes.items(.data)[node];
1958 const extra = @bitCast(Node.For, data.rhs);
1958 const extra = @as(Node.For, @bitCast(data.rhs));
19591959 const inputs = tree.extra_data[data.lhs..][0..extra.inputs];
19601960 const then_expr = tree.extra_data[data.lhs + extra.inputs];
19611961 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 {
317317 }
318318 const feature_name = cpu_features[start..index];
319319 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));
321321 if (mem.eql(u8, feature_name, feature.name)) {
322322 set.addFeature(feat_index);
323323 break;
lib/std/zig/ErrorBundle.zig+17-17
......@@ -94,7 +94,7 @@ pub fn getErrorMessageList(eb: ErrorBundle) ErrorMessageList {
9494
9595pub fn getMessages(eb: ErrorBundle) []const MessageIndex {
9696 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]));
9898}
9999
100100pub fn getErrorMessage(eb: ErrorBundle, index: MessageIndex) ErrorMessage {
......@@ -109,7 +109,7 @@ pub fn getSourceLocation(eb: ErrorBundle, index: SourceLocationIndex) SourceLoca
109109pub fn getNotes(eb: ErrorBundle, index: MessageIndex) []const MessageIndex {
110110 const notes_len = eb.getErrorMessage(index).notes_len;
111111 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]));
113113}
114114
115115pub fn getCompileLogOutput(eb: ErrorBundle) [:0]const u8 {
......@@ -125,8 +125,8 @@ fn extraData(eb: ErrorBundle, comptime T: type, index: usize) struct { data: T,
125125 inline for (fields) |field| {
126126 @field(result, field.name) = switch (field.type) {
127127 u32 => eb.extra[i],
128 MessageIndex => @enumFromInt(MessageIndex, eb.extra[i]),
129 SourceLocationIndex => @enumFromInt(SourceLocationIndex, eb.extra[i]),
128 MessageIndex => @as(MessageIndex, @enumFromInt(eb.extra[i])),
129 SourceLocationIndex => @as(SourceLocationIndex, @enumFromInt(eb.extra[i])),
130130 else => @compileError("bad field type"),
131131 };
132132 i += 1;
......@@ -202,7 +202,7 @@ fn renderErrorMessageToWriter(
202202 try counting_stderr.writeAll(": ");
203203 // This is the length of the part before the error message:
204204 // 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));
206206 try ttyconf.setColor(stderr, .reset);
207207 try ttyconf.setColor(stderr, .bold);
208208 if (err_msg.count == 1) {
......@@ -357,7 +357,7 @@ pub const Wip = struct {
357357 }
358358
359359 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));
361361 try wip.string_bytes.ensureUnusedCapacity(gpa, compile_log_text.len + 1);
362362 wip.string_bytes.appendSliceAssumeCapacity(compile_log_text);
363363 wip.string_bytes.appendAssumeCapacity(0);
......@@ -365,11 +365,11 @@ pub const Wip = struct {
365365 };
366366
367367 wip.setExtra(0, ErrorMessageList{
368 .len = @intCast(u32, wip.root_list.items.len),
369 .start = @intCast(u32, wip.extra.items.len),
368 .len = @as(u32, @intCast(wip.root_list.items.len)),
369 .start = @as(u32, @intCast(wip.extra.items.len)),
370370 .compile_log_text = compile_log_str_index,
371371 });
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)));
373373 wip.root_list.clearAndFree(gpa);
374374 return .{
375375 .string_bytes = try wip.string_bytes.toOwnedSlice(gpa),
......@@ -386,7 +386,7 @@ pub const Wip = struct {
386386
387387 pub fn addString(wip: *Wip, s: []const u8) !u32 {
388388 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));
390390 try wip.string_bytes.ensureUnusedCapacity(gpa, s.len + 1);
391391 wip.string_bytes.appendSliceAssumeCapacity(s);
392392 wip.string_bytes.appendAssumeCapacity(0);
......@@ -395,7 +395,7 @@ pub const Wip = struct {
395395
396396 pub fn printString(wip: *Wip, comptime fmt: []const u8, args: anytype) !u32 {
397397 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));
399399 try wip.string_bytes.writer(gpa).print(fmt, args);
400400 try wip.string_bytes.append(gpa, 0);
401401 return index;
......@@ -407,15 +407,15 @@ pub const Wip = struct {
407407 }
408408
409409 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)));
411411 }
412412
413413 pub fn addErrorMessageAssumeCapacity(wip: *Wip, em: ErrorMessage) MessageIndex {
414 return @enumFromInt(MessageIndex, addExtraAssumeCapacity(wip, em));
414 return @as(MessageIndex, @enumFromInt(addExtraAssumeCapacity(wip, em)));
415415 }
416416
417417 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)));
419419 }
420420
421421 pub fn addReferenceTrace(wip: *Wip, rt: ReferenceTrace) !void {
......@@ -431,7 +431,7 @@ pub const Wip = struct {
431431 const other_list = other.getMessages();
432432
433433 // 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;
435435 for (notes_start.., other_list) |note, message| {
436436 wip.extra.items[note] = @intFromEnum(wip.addOtherMessage(other, message) catch unreachable);
437437 }
......@@ -441,7 +441,7 @@ pub const Wip = struct {
441441 try wip.extra.ensureUnusedCapacity(wip.gpa, notes_len +
442442 notes_len * @typeInfo(ErrorBundle.ErrorMessage).Struct.fields.len);
443443 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));
445445 }
446446
447447 fn addOtherMessage(wip: *Wip, other: ErrorBundle, msg_index: MessageIndex) !MessageIndex {
......@@ -493,7 +493,7 @@ pub const Wip = struct {
493493
494494 fn addExtraAssumeCapacity(wip: *Wip, extra: anytype) u32 {
495495 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));
497497 wip.extra.items.len += fields.len;
498498 setExtra(wip, result, extra);
499499 return result;
lib/std/zig/Parse.zig+15-15
......@@ -36,20 +36,20 @@ const Members = struct {
3636fn listToSpan(p: *Parse, list: []const Node.Index) !Node.SubRange {
3737 try p.extra_data.appendSlice(p.gpa, list);
3838 return Node.SubRange{
39 .start = @intCast(Node.Index, p.extra_data.items.len - list.len),
40 .end = @intCast(Node.Index, p.extra_data.items.len),
39 .start = @as(Node.Index, @intCast(p.extra_data.items.len - list.len)),
40 .end = @as(Node.Index, @intCast(p.extra_data.items.len)),
4141 };
4242}
4343
4444fn 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));
4646 try p.nodes.append(p.gpa, elem);
4747 return result;
4848}
4949
5050fn setNode(p: *Parse, i: usize, elem: Ast.Node) Node.Index {
5151 p.nodes.set(i, elem);
52 return @intCast(Node.Index, i);
52 return @as(Node.Index, @intCast(i));
5353}
5454
5555fn reserveNode(p: *Parse, tag: Ast.Node.Tag) !usize {
......@@ -72,7 +72,7 @@ fn unreserveNode(p: *Parse, node_index: usize) void {
7272fn addExtra(p: *Parse, extra: anytype) Allocator.Error!Node.Index {
7373 const fields = std.meta.fields(@TypeOf(extra));
7474 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));
7676 inline for (fields) |field| {
7777 comptime assert(field.type == Node.Index);
7878 p.extra_data.appendAssumeCapacity(@field(extra, field.name));
......@@ -1202,10 +1202,10 @@ fn parseForStatement(p: *Parse) !Node.Index {
12021202 .main_token = for_token,
12031203 .data = .{
12041204 .lhs = (try p.listToSpan(p.scratch.items[scratch_top..])).start,
1205 .rhs = @bitCast(u32, Node.For{
1206 .inputs = @intCast(u31, inputs),
1205 .rhs = @as(u32, @bitCast(Node.For{
1206 .inputs = @as(u31, @intCast(inputs)),
12071207 .has_else = has_else,
1208 }),
1208 })),
12091209 },
12101210 });
12111211}
......@@ -1486,7 +1486,7 @@ fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!Node.Index {
14861486
14871487 while (true) {
14881488 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)))];
14901490 if (info.prec < min_prec) {
14911491 break;
14921492 }
......@@ -2087,10 +2087,10 @@ fn parseForExpr(p: *Parse) !Node.Index {
20872087 .main_token = for_token,
20882088 .data = .{
20892089 .lhs = (try p.listToSpan(p.scratch.items[scratch_top..])).start,
2090 .rhs = @bitCast(u32, Node.For{
2091 .inputs = @intCast(u31, inputs),
2090 .rhs = @as(u32, @bitCast(Node.For{
2091 .inputs = @as(u31, @intCast(inputs)),
20922092 .has_else = has_else,
2093 }),
2093 })),
20942094 },
20952095 });
20962096}
......@@ -2862,10 +2862,10 @@ fn parseForTypeExpr(p: *Parse) !Node.Index {
28622862 .main_token = for_token,
28632863 .data = .{
28642864 .lhs = (try p.listToSpan(p.scratch.items[scratch_top..])).start,
2865 .rhs = @bitCast(u32, Node.For{
2866 .inputs = @intCast(u31, inputs),
2865 .rhs = @as(u32, @bitCast(Node.For{
2866 .inputs = @as(u31, @intCast(inputs)),
28672867 .has_else = has_else,
2868 }),
2868 })),
28692869 },
28702870 });
28712871}
lib/std/zig/Server.zig+14-14
......@@ -132,7 +132,7 @@ pub fn receiveMessage(s: *Server) !InMessage.Header {
132132pub fn receiveBody_u32(s: *Server) !u32 {
133133 const fifo = &s.receive_fifo;
134134 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])).*;
136136 fifo.discard(4);
137137 return bswap(result);
138138}
......@@ -140,7 +140,7 @@ pub fn receiveBody_u32(s: *Server) !u32 {
140140pub fn serveStringMessage(s: *Server, tag: OutMessage.Tag, msg: []const u8) !void {
141141 return s.serveMessage(.{
142142 .tag = tag,
143 .bytes_len = @intCast(u32, msg.len),
143 .bytes_len = @as(u32, @intCast(msg.len)),
144144 }, &.{msg});
145145}
146146
......@@ -152,7 +152,7 @@ pub fn serveMessage(
152152 var iovecs: [10]std.os.iovec_const = undefined;
153153 const header_le = bswap(header);
154154 iovecs[0] = .{
155 .iov_base = @ptrCast([*]const u8, &header_le),
155 .iov_base = @as([*]const u8, @ptrCast(&header_le)),
156156 .iov_len = @sizeOf(OutMessage.Header),
157157 };
158158 for (bufs, iovecs[1 .. bufs.len + 1]) |buf, *iovec| {
......@@ -171,7 +171,7 @@ pub fn serveEmitBinPath(
171171) !void {
172172 try s.serveMessage(.{
173173 .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))),
175175 }, &.{
176176 std.mem.asBytes(&header),
177177 fs_path,
......@@ -185,7 +185,7 @@ pub fn serveTestResults(
185185 const msg_le = bswap(msg);
186186 try s.serveMessage(.{
187187 .tag = .test_results,
188 .bytes_len = @intCast(u32, @sizeOf(OutMessage.TestResults)),
188 .bytes_len = @as(u32, @intCast(@sizeOf(OutMessage.TestResults))),
189189 }, &.{
190190 std.mem.asBytes(&msg_le),
191191 });
......@@ -193,14 +193,14 @@ pub fn serveTestResults(
193193
194194pub fn serveErrorBundle(s: *Server, error_bundle: std.zig.ErrorBundle) !void {
195195 const eb_hdr: OutMessage.ErrorBundle = .{
196 .extra_len = @intCast(u32, error_bundle.extra.len),
197 .string_bytes_len = @intCast(u32, error_bundle.string_bytes.len),
196 .extra_len = @as(u32, @intCast(error_bundle.extra.len)),
197 .string_bytes_len = @as(u32, @intCast(error_bundle.string_bytes.len)),
198198 };
199199 const bytes_len = @sizeOf(OutMessage.ErrorBundle) +
200200 4 * error_bundle.extra.len + error_bundle.string_bytes.len;
201201 try s.serveMessage(.{
202202 .tag = .error_bundle,
203 .bytes_len = @intCast(u32, bytes_len),
203 .bytes_len = @as(u32, @intCast(bytes_len)),
204204 }, &.{
205205 std.mem.asBytes(&eb_hdr),
206206 // TODO: implement @ptrCast between slices changing the length
......@@ -218,8 +218,8 @@ pub const TestMetadata = struct {
218218
219219pub fn serveTestMetadata(s: *Server, test_metadata: TestMetadata) !void {
220220 const header: OutMessage.TestMetadata = .{
221 .tests_len = bswap(@intCast(u32, test_metadata.names.len)),
222 .string_bytes_len = bswap(@intCast(u32, test_metadata.string_bytes.len)),
221 .tests_len = bswap(@as(u32, @intCast(test_metadata.names.len))),
222 .string_bytes_len = bswap(@as(u32, @intCast(test_metadata.string_bytes.len))),
223223 };
224224 const bytes_len = @sizeOf(OutMessage.TestMetadata) +
225225 3 * 4 * test_metadata.names.len + test_metadata.string_bytes.len;
......@@ -237,7 +237,7 @@ pub fn serveTestMetadata(s: *Server, test_metadata: TestMetadata) !void {
237237
238238 return s.serveMessage(.{
239239 .tag = .test_metadata,
240 .bytes_len = @intCast(u32, bytes_len),
240 .bytes_len = @as(u32, @intCast(bytes_len)),
241241 }, &.{
242242 std.mem.asBytes(&header),
243243 // TODO: implement @ptrCast between slices changing the length
......@@ -253,7 +253,7 @@ fn bswap(x: anytype) @TypeOf(x) {
253253
254254 const T = @TypeOf(x);
255255 switch (@typeInfo(T)) {
256 .Enum => return @enumFromInt(T, @byteSwap(@intFromEnum(x))),
256 .Enum => return @as(T, @enumFromInt(@byteSwap(@intFromEnum(x)))),
257257 .Int => return @byteSwap(x),
258258 .Struct => |info| switch (info.layout) {
259259 .Extern => {
......@@ -265,7 +265,7 @@ fn bswap(x: anytype) @TypeOf(x) {
265265 },
266266 .Packed => {
267267 const I = info.backing_integer.?;
268 return @bitCast(T, @byteSwap(@bitCast(I, x)));
268 return @as(T, @bitCast(@byteSwap(@as(I, @bitCast(x)))));
269269 },
270270 .Auto => @compileError("auto layout struct"),
271271 },
......@@ -286,7 +286,7 @@ fn bswap_and_workaround_u32(bytes_ptr: *const [4]u8) u32 {
286286/// workaround for https://github.com/ziglang/zig/issues/14904
287287fn bswap_and_workaround_tag(bytes_ptr: *const [4]u8) InMessage.Tag {
288288 const int = std.mem.readIntLittle(u32, bytes_ptr);
289 return @enumFromInt(InMessage.Tag, int);
289 return @as(InMessage.Tag, @enumFromInt(int));
290290}
291291
292292const 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 {
2020pub inline fn __builtin_popcount(val: c_uint) c_int {
2121 // popcount of a c_uint will never exceed the capacity of a c_int
2222 @setRuntimeSafety(false);
23 return @bitCast(c_int, @as(c_uint, @popCount(val)));
23 return @as(c_int, @bitCast(@as(c_uint, @popCount(val))));
2424}
2525pub inline fn __builtin_ctz(val: c_uint) c_int {
2626 // Returns the number of trailing 0-bits in val, starting at the least significant bit position.
2727 // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint
2828 @setRuntimeSafety(false);
29 return @bitCast(c_int, @as(c_uint, @ctz(val)));
29 return @as(c_int, @bitCast(@as(c_uint, @ctz(val))));
3030}
3131pub inline fn __builtin_clz(val: c_uint) c_int {
3232 // Returns the number of leading 0-bits in x, starting at the most significant bit position.
3333 // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint
3434 @setRuntimeSafety(false);
35 return @bitCast(c_int, @as(c_uint, @clz(val)));
35 return @as(c_int, @bitCast(@as(c_uint, @clz(val))));
3636}
3737
3838pub inline fn __builtin_sqrt(val: f64) f64 {
......@@ -135,7 +135,7 @@ pub inline fn __builtin_object_size(ptr: ?*const anyopaque, ty: c_int) usize {
135135 // If it is not possible to determine which objects ptr points to at compile time,
136136 // __builtin_object_size should return (size_t) -1 for type 0 or 1 and (size_t) 0
137137 // 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)));
139139 if (ty == 2 or ty == 3) return 0;
140140 unreachable;
141141}
......@@ -151,8 +151,8 @@ pub inline fn __builtin___memset_chk(
151151}
152152
153153pub inline fn __builtin_memset(dst: ?*anyopaque, val: c_int, len: usize) ?*anyopaque {
154 const dst_cast = @ptrCast([*c]u8, dst);
155 @memset(dst_cast[0..len], @bitCast(u8, @truncate(i8, val)));
154 const dst_cast = @as([*c]u8, @ptrCast(dst));
155 @memset(dst_cast[0..len], @as(u8, @bitCast(@as(i8, @truncate(val)))));
156156 return dst;
157157}
158158
......@@ -172,8 +172,8 @@ pub inline fn __builtin_memcpy(
172172 len: usize,
173173) ?*anyopaque {
174174 if (len > 0) @memcpy(
175 @ptrCast([*]u8, dst.?)[0..len],
176 @ptrCast([*]const u8, src.?),
175 @as([*]u8, @ptrCast(dst.?))[0..len],
176 @as([*]const u8, @ptrCast(src.?)),
177177 );
178178 return dst;
179179}
......@@ -202,8 +202,8 @@ pub inline fn __builtin_expect(expr: c_long, c: c_long) c_long {
202202/// If tagp is empty, the function returns a NaN whose significand is zero.
203203pub inline fn __builtin_nanf(tagp: []const u8) f32 {
204204 const parsed = std.fmt.parseUnsigned(c_ulong, tagp, 0) catch 0;
205 const bits = @truncate(u23, parsed); // single-precision float trailing significand is 23 bits
206 return @bitCast(f32, @as(u32, bits) | std.math.qnan_u32);
205 const bits = @as(u23, @truncate(parsed)); // single-precision float trailing significand is 23 bits
206 return @as(f32, @bitCast(@as(u32, bits) | std.math.qnan_u32));
207207}
208208
209209pub 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 {
4242 },
4343 .Float => {
4444 switch (@typeInfo(SourceType)) {
45 .Int => return @floatFromInt(DestType, target),
46 .Float => return @floatCast(DestType, target),
47 .Bool => return @floatFromInt(DestType, @intFromBool(target)),
45 .Int => return @as(DestType, @floatFromInt(target)),
46 .Float => return @as(DestType, @floatCast(target)),
47 .Bool => return @as(DestType, @floatFromInt(@intFromBool(target))),
4848 else => {},
4949 }
5050 },
......@@ -65,36 +65,25 @@ fn castInt(comptime DestType: type, target: anytype) DestType {
6565 const source = @typeInfo(@TypeOf(target)).Int;
6666
6767 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))))
6969 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)));
7171}
7272
7373fn castPtr(comptime DestType: type, target: anytype) DestType {
74 const dest = ptrInfo(DestType);
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));
74 return @constCast(@volatileCast(@alignCast(@ptrCast(target))));
8675}
8776
8877fn castToPtr(comptime DestType: type, comptime SourceType: type, target: anytype) DestType {
8978 switch (@typeInfo(SourceType)) {
9079 .Int => {
91 return @ptrFromInt(DestType, castInt(usize, target));
80 return @as(DestType, @ptrFromInt(castInt(usize, target)));
9281 },
9382 .ComptimeInt => {
9483 if (target < 0)
95 return @ptrFromInt(DestType, @bitCast(usize, @intCast(isize, target)))
84 return @as(DestType, @ptrFromInt(@as(usize, @bitCast(@as(isize, @intCast(target))))))
9685 else
97 return @ptrFromInt(DestType, @intCast(usize, target));
86 return @as(DestType, @ptrFromInt(@as(usize, @intCast(target))));
9887 },
9988 .Pointer => {
10089 return castPtr(DestType, target);
......@@ -120,34 +109,34 @@ fn ptrInfo(comptime PtrType: type) std.builtin.Type.Pointer {
120109test "cast" {
121110 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)));
124113 try testing.expect(cast(*u64, &i).* == @as(u64, 10));
125114 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)));
128117 try testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i);
129118 try testing.expect(cast(?*i64, @as(?*align(1) i64, &i)) == &i);
130119
131 try testing.expectEqual(@as(u32, 4), cast(u32, @ptrFromInt(*u32, 4)));
132 try testing.expectEqual(@as(u32, 4), cast(u32, @ptrFromInt(?*u32, 4)));
120 try testing.expectEqual(@as(u32, 4), cast(u32, @as(*u32, @ptrFromInt(4))));
121 try testing.expectEqual(@as(u32, 4), cast(u32, @as(?*u32, @ptrFromInt(4))));
133122 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)));
138 try testing.expectEqual(@ptrFromInt(*u8, 2), cast(*u8, @ptrFromInt(*volatile u8, 2)));
126 try testing.expectEqual(@as(*u8, @ptrFromInt(2)), cast(*u8, @as(*const u8, @ptrFromInt(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
142131 var foo: c_int = -1;
143 try testing.expect(cast(*anyopaque, -1) == @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -1))));
144 try testing.expect(cast(*anyopaque, foo) == @ptrFromInt(*anyopaque, @bitCast(usize, @as(isize, -1))));
145 try testing.expect(cast(?*anyopaque, -1) == @ptrFromInt(?*anyopaque, @bitCast(usize, @as(isize, -1))));
146 try testing.expect(cast(?*anyopaque, foo) == @ptrFromInt(?*anyopaque, @bitCast(usize, @as(isize, -1))));
132 try testing.expect(cast(*anyopaque, -1) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
133 try testing.expect(cast(*anyopaque, foo) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
134 try testing.expect(cast(?*anyopaque, -1) == @as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
135 try testing.expect(cast(?*anyopaque, foo) == @as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
147136
148137 const FnPtr = ?*align(1) const fn (*anyopaque) void;
149 try testing.expect(cast(FnPtr, 0) == @ptrFromInt(FnPtr, @as(usize, 0)));
150 try testing.expect(cast(FnPtr, foo) == @ptrFromInt(FnPtr, @bitCast(usize, @as(isize, -1))));
138 try testing.expect(cast(FnPtr, 0) == @as(FnPtr, @ptrFromInt(@as(usize, 0))));
139 try testing.expect(cast(FnPtr, foo) == @as(FnPtr, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
151140}
152141
153142/// Given a value returns its size as C's sizeof operator would.
......@@ -192,7 +181,7 @@ pub fn sizeof(target: anytype) usize {
192181 const array_info = @typeInfo(ptr.child).Array;
193182 if ((array_info.child == u8 or array_info.child == u16) and
194183 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)
196185 {
197186 // length of the string plus one for the null terminator.
198187 return (array_info.len + 1) * @sizeOf(array_info.child);
......@@ -325,10 +314,10 @@ test "promoteIntLiteral" {
325314pub fn shuffleVectorIndex(comptime this_index: c_int, comptime source_vector_len: usize) i32 {
326315 if (this_index <= 0) return 0;
327316
328 const positive_index = @intCast(usize, this_index);
329 if (positive_index < source_vector_len) return @intCast(i32, this_index);
317 const positive_index = @as(usize, @intCast(this_index));
318 if (positive_index < source_vector_len) return @as(i32, @intCast(this_index));
330319 const b_index = positive_index - source_vector_len;
331 return ~@intCast(i32, b_index);
320 return ~@as(i32, @intCast(b_index));
332321}
333322
334323test "shuffleVectorIndex" {
lib/std/zig/number_literal.zig+3-3
......@@ -141,7 +141,7 @@ pub fn parseNumberLiteral(bytes: []const u8) Result {
141141 'a'...'z' => c - 'a' + 10,
142142 else => return .{ .failure = .{ .invalid_character = i } },
143143 };
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)) } } };
145145 if (exponent and digit >= 10) return .{ .failure = .{ .invalid_digit_exponent = i } };
146146 underscore = false;
147147 special = 0;
......@@ -159,7 +159,7 @@ pub fn parseNumberLiteral(bytes: []const u8) Result {
159159 if (underscore) return .{ .failure = .{ .trailing_underscore = bytes.len - 1 } };
160160 if (special != 0) return .{ .failure = .{ .trailing_special = bytes.len - 1 } };
161161
162 if (float) return .{ .float = @enumFromInt(FloatBase, base) };
163 if (overflow) return .{ .big_int = @enumFromInt(Base, base) };
162 if (float) return .{ .float = @as(FloatBase, @enumFromInt(base)) };
163 if (overflow) return .{ .big_int = @as(Base, @enumFromInt(base)) };
164164 return .{ .int = x };
165165}
lib/std/zig/parser_test.zig+10-10
......@@ -166,10 +166,10 @@ test "zig fmt: respect line breaks after var declarations" {
166166 \\ lookup_tables[1][p[6]] ^
167167 \\ lookup_tables[2][p[5]] ^
168168 \\ lookup_tables[3][p[4]] ^
169 \\ lookup_tables[4][@truncate(u8, self.crc >> 24)] ^
170 \\ lookup_tables[5][@truncate(u8, self.crc >> 16)] ^
171 \\ lookup_tables[6][@truncate(u8, self.crc >> 8)] ^
172 \\ lookup_tables[7][@truncate(u8, self.crc >> 0)];
169 \\ lookup_tables[4][@as(u8, self.crc >> 24)] ^
170 \\ lookup_tables[5][@as(u8, self.crc >> 16)] ^
171 \\ lookup_tables[6][@as(u8, self.crc >> 8)] ^
172 \\ lookup_tables[7][@as(u8, self.crc >> 0)];
173173 \\
174174 );
175175}
......@@ -1108,7 +1108,7 @@ test "zig fmt: async function" {
11081108 \\ handleRequestFn: fn (*Server, *const std.net.Address, File) callconv(.Async) void,
11091109 \\};
11101110 \\test "hi" {
1111 \\ var ptr = @ptrCast(fn (i32) callconv(.Async) void, other);
1111 \\ var ptr: fn (i32) callconv(.Async) void = @ptrCast(other);
11121112 \\}
11131113 \\
11141114 );
......@@ -1825,10 +1825,10 @@ test "zig fmt: respect line breaks after infix operators" {
18251825 \\ lookup_tables[1][p[6]] ^
18261826 \\ lookup_tables[2][p[5]] ^
18271827 \\ lookup_tables[3][p[4]] ^
1828 \\ lookup_tables[4][@truncate(u8, self.crc >> 24)] ^
1829 \\ lookup_tables[5][@truncate(u8, self.crc >> 16)] ^
1830 \\ lookup_tables[6][@truncate(u8, self.crc >> 8)] ^
1831 \\ lookup_tables[7][@truncate(u8, self.crc >> 0)];
1828 \\ lookup_tables[4][@as(u8, self.crc >> 24)] ^
1829 \\ lookup_tables[5][@as(u8, self.crc >> 16)] ^
1830 \\ lookup_tables[6][@as(u8, self.crc >> 8)] ^
1831 \\ lookup_tables[7][@as(u8, self.crc >> 0)];
18321832 \\}
18331833 \\
18341834 );
......@@ -4814,7 +4814,7 @@ test "zig fmt: use of comments and multiline string literals may force the param
48144814 \\ \\ unknown-length pointers and C pointers cannot be hashed deeply.
48154815 \\ \\ Consider providing your own hash function.
48164816 \\ );
4817 \\ return @intCast(i1, doMemCheckClientRequestExpr(0, // default return
4817 \\ return @intCast(doMemCheckClientRequestExpr(0, // default return
48184818 \\ .MakeMemUndefined, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0));
48194819 \\}
48204820 \\
lib/std/zig/perf_test.zig+3-3
......@@ -18,9 +18,9 @@ pub fn main() !void {
1818 }
1919 const end = timer.read();
2020 memory_used /= iterations;
21 const elapsed_s = @floatFromInt(f64, end - start) / std.time.ns_per_s;
22 const bytes_per_sec_float = @floatFromInt(f64, source.len * iterations) / elapsed_s;
23 const bytes_per_sec = @intFromFloat(u64, @floor(bytes_per_sec_float));
21 const elapsed_s = @as(f64, @floatFromInt(end - start)) / std.time.ns_per_s;
22 const bytes_per_sec_float = @as(f64, @floatFromInt(source.len * iterations)) / elapsed_s;
23 const bytes_per_sec = @as(u64, @intFromFloat(@floor(bytes_per_sec_float)));
2424
2525 var stdout_file = std.io.getStdOut();
2626 const stdout = stdout_file.writer();
lib/std/zig/render.zig+58-4
......@@ -1390,14 +1390,51 @@ fn renderBuiltinCall(
13901390) Error!void {
13911391 const token_tags = tree.tokens.items(.tag);
13921392
1393 // TODO remove before release of 0.11.0
1393 // TODO remove before release of 0.12.0
13941394 const slice = tree.tokenSlice(builtin_token);
1395 const rewrite_two_param_cast = params.len == 2 and for ([_][]const u8{
1396 "@bitCast",
1397 "@errSetCast",
1398 "@floatCast",
1399 "@intCast",
1400 "@ptrCast",
1401 "@intFromFloat",
1402 "@floatToInt",
1403 "@enumFromInt",
1404 "@intToEnum",
1405 "@floatFromInt",
1406 "@intToFloat",
1407 "@ptrFromInt",
1408 "@intToPtr",
1409 "@truncate",
1410 }) |name| {
1411 if (mem.eql(u8, slice, name)) break true;
1412 } else false;
1413
1414 if (rewrite_two_param_cast) {
1415 const after_last_param_token = tree.lastToken(params[1]) + 1;
1416 if (token_tags[after_last_param_token] != .comma) {
1417 // Render all on one line, no trailing comma.
1418 try ais.writer().writeAll("@as");
1419 try renderToken(ais, tree, builtin_token + 1, .none); // (
1420 try renderExpression(gpa, ais, tree, params[0], .comma_space);
1421 } else {
1422 // Render one param per line.
1423 try ais.writer().writeAll("@as");
1424 ais.pushIndent();
1425 try renderToken(ais, tree, builtin_token + 1, .newline); // (
1426 try renderExpression(gpa, ais, tree, params[0], .comma);
1427 }
1428 }
1429 // Corresponding logic below builtin name rewrite below
1430
1431 // TODO remove before release of 0.11.0
13951432 if (mem.eql(u8, slice, "@maximum")) {
13961433 try ais.writer().writeAll("@max");
13971434 } else if (mem.eql(u8, slice, "@minimum")) {
13981435 try ais.writer().writeAll("@min");
13991436 }
1400 //
1437 // TODO remove before release of 0.12.0
14011438 else if (mem.eql(u8, slice, "@boolToInt")) {
14021439 try ais.writer().writeAll("@intFromBool");
14031440 } else if (mem.eql(u8, slice, "@enumToInt")) {
......@@ -1420,6 +1457,23 @@ fn renderBuiltinCall(
14201457 try renderToken(ais, tree, builtin_token, .none); // @name
14211458 }
14221459
1460 if (rewrite_two_param_cast) {
1461 // Matches with corresponding logic above builtin name rewrite
1462 const after_last_param_token = tree.lastToken(params[1]) + 1;
1463 try ais.writer().writeAll("(");
1464 try renderExpression(gpa, ais, tree, params[1], .none);
1465 try ais.writer().writeAll(")");
1466 if (token_tags[after_last_param_token] != .comma) {
1467 // Render all on one line, no trailing comma.
1468 return renderToken(ais, tree, after_last_param_token, space); // )
1469 } else {
1470 // Render one param per line.
1471 ais.popIndent();
1472 try renderToken(ais, tree, after_last_param_token, .newline); // ,
1473 return renderToken(ais, tree, after_last_param_token + 1, space); // )
1474 }
1475 }
1476
14231477 if (params.len == 0) {
14241478 try renderToken(ais, tree, builtin_token + 1, .none); // (
14251479 return renderToken(ais, tree, builtin_token + 2, space); // )
......@@ -2665,7 +2719,7 @@ fn renderIdentifier(ais: *Ais, tree: Ast, token_index: Ast.TokenIndex, space: Sp
26652719 while (contents_i < contents.len and buf_i < longest_keyword_or_primitive_len) {
26662720 if (contents[contents_i] == '\\') {
26672721 const res = std.zig.string_literal.parseEscapeSequence(contents, &contents_i).success;
2668 buf[buf_i] = @intCast(u8, res);
2722 buf[buf_i] = @as(u8, @intCast(res));
26692723 buf_i += 1;
26702724 } else {
26712725 buf[buf_i] = contents[contents_i];
......@@ -2719,7 +2773,7 @@ fn renderIdentifierContents(writer: anytype, bytes: []const u8) !void {
27192773 switch (res) {
27202774 .success => |codepoint| {
27212775 if (codepoint <= 0x7f) {
2722 const buf = [1]u8{@intCast(u8, codepoint)};
2776 const buf = [1]u8{@as(u8, @intCast(codepoint))};
27232777 try std.fmt.format(writer, "{}", .{std.zig.fmtEscapes(&buf)});
27242778 } else {
27252779 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
142142 return .{ .failure = .{ .expected_rbrace = i } };
143143 }
144144 offset.* = i;
145 return .{ .success = @intCast(u21, value) };
145 return .{ .success = @as(u21, @intCast(value)) };
146146 },
147147 else => return .{ .failure = .{ .invalid_escape_character = offset.* - 1 } },
148148 }
......@@ -253,7 +253,7 @@ pub fn parseWrite(writer: anytype, bytes: []const u8) error{OutOfMemory}!Result
253253 };
254254 try writer.writeAll(buf[0..len]);
255255 } else {
256 try writer.writeByte(@intCast(u8, codepoint));
256 try writer.writeByte(@as(u8, @intCast(codepoint)));
257257 }
258258 },
259259 .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 {
479479fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion {
480480 var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 align(@alignOf(elf.Elf64_Ehdr)) = undefined;
481481 _ = try preadMin(file, &hdr_buf, 0, hdr_buf.len);
482 const hdr32 = @ptrCast(*elf.Elf32_Ehdr, &hdr_buf);
483 const hdr64 = @ptrCast(*elf.Elf64_Ehdr, &hdr_buf);
482 const hdr32 = @as(*elf.Elf32_Ehdr, @ptrCast(&hdr_buf));
483 const hdr64 = @as(*elf.Elf64_Ehdr, @ptrCast(&hdr_buf));
484484 if (!mem.eql(u8, hdr32.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic;
485485 const elf_endian: std.builtin.Endian = switch (hdr32.e_ident[elf.EI_DATA]) {
486486 elf.ELFDATA2LSB => .Little,
......@@ -503,8 +503,8 @@ fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion {
503503 if (sh_buf.len < shentsize) return error.InvalidElfFile;
504504
505505 _ = try preadMin(file, &sh_buf, str_section_off, shentsize);
506 const shstr32 = @ptrCast(*elf.Elf32_Shdr, @alignCast(@alignOf(elf.Elf32_Shdr), &sh_buf));
507 const shstr64 = @ptrCast(*elf.Elf64_Shdr, @alignCast(@alignOf(elf.Elf64_Shdr), &sh_buf));
506 const shstr32: *elf.Elf32_Shdr = @ptrCast(@alignCast(&sh_buf));
507 const shstr64: *elf.Elf64_Shdr = @ptrCast(@alignCast(&sh_buf));
508508 const shstrtab_off = elfInt(is_64, need_bswap, shstr32.sh_offset, shstr64.sh_offset);
509509 const shstrtab_size = elfInt(is_64, need_bswap, shstr32.sh_size, shstr64.sh_size);
510510 var strtab_buf: [4096:0]u8 = undefined;
......@@ -529,14 +529,8 @@ fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion {
529529 shoff += shentsize;
530530 sh_buf_i += shentsize;
531531 }) {
532 const sh32 = @ptrCast(
533 *elf.Elf32_Shdr,
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 );
532 const sh32: *elf.Elf32_Shdr = @ptrCast(@alignCast(&sh_buf[sh_buf_i]));
533 const sh64: *elf.Elf64_Shdr = @ptrCast(@alignCast(&sh_buf[sh_buf_i]));
540534 const sh_name_off = elfInt(is_64, need_bswap, sh32.sh_name, sh64.sh_name);
541535 const sh_name = mem.sliceTo(shstrtab[sh_name_off..], 0);
542536 if (mem.eql(u8, sh_name, ".dynstr")) {
......@@ -558,7 +552,7 @@ fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion {
558552 var buf: [80000]u8 = undefined;
559553 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));
562556 const dynstr_bytes = buf[0..dynstr_size];
563557 _ = try preadMin(file, dynstr_bytes, dynstr.offset, dynstr_bytes.len);
564558 var it = mem.splitScalar(u8, dynstr_bytes, 0);
......@@ -621,8 +615,8 @@ pub fn abiAndDynamicLinkerFromFile(
621615) AbiAndDynamicLinkerFromFileError!NativeTargetInfo {
622616 var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 align(@alignOf(elf.Elf64_Ehdr)) = undefined;
623617 _ = try preadMin(file, &hdr_buf, 0, hdr_buf.len);
624 const hdr32 = @ptrCast(*elf.Elf32_Ehdr, &hdr_buf);
625 const hdr64 = @ptrCast(*elf.Elf64_Ehdr, &hdr_buf);
618 const hdr32 = @as(*elf.Elf32_Ehdr, @ptrCast(&hdr_buf));
619 const hdr64 = @as(*elf.Elf64_Ehdr, @ptrCast(&hdr_buf));
626620 if (!mem.eql(u8, hdr32.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic;
627621 const elf_endian: std.builtin.Endian = switch (hdr32.e_ident[elf.EI_DATA]) {
628622 elf.ELFDATA2LSB => .Little,
......@@ -668,21 +662,21 @@ pub fn abiAndDynamicLinkerFromFile(
668662 phoff += phentsize;
669663 ph_buf_i += phentsize;
670664 }) {
671 const ph32 = @ptrCast(*elf.Elf32_Phdr, @alignCast(@alignOf(elf.Elf32_Phdr), &ph_buf[ph_buf_i]));
672 const ph64 = @ptrCast(*elf.Elf64_Phdr, @alignCast(@alignOf(elf.Elf64_Phdr), &ph_buf[ph_buf_i]));
665 const ph32: *elf.Elf32_Phdr = @ptrCast(@alignCast(&ph_buf[ph_buf_i]));
666 const ph64: *elf.Elf64_Phdr = @ptrCast(@alignCast(&ph_buf[ph_buf_i]));
673667 const p_type = elfInt(is_64, need_bswap, ph32.p_type, ph64.p_type);
674668 switch (p_type) {
675669 elf.PT_INTERP => if (look_for_ld) {
676670 const p_offset = elfInt(is_64, need_bswap, ph32.p_offset, ph64.p_offset);
677671 const p_filesz = elfInt(is_64, need_bswap, ph32.p_filesz, ph64.p_filesz);
678672 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));
680674 _ = try preadMin(file, result.dynamic_linker.buffer[0..filesz], p_offset, filesz);
681675 // PT_INTERP includes a null byte in filesz.
682676 const len = filesz - 1;
683677 // dynamic_linker.max_byte is "max", not "len".
684678 // 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
687681 // Use it to determine ABI.
688682 const full_ld_path = result.dynamic_linker.buffer[0..len];
......@@ -720,14 +714,8 @@ pub fn abiAndDynamicLinkerFromFile(
720714 dyn_off += dyn_size;
721715 dyn_buf_i += dyn_size;
722716 }) {
723 const dyn32 = @ptrCast(
724 *elf.Elf32_Dyn,
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 );
717 const dyn32: *elf.Elf32_Dyn = @ptrCast(@alignCast(&dyn_buf[dyn_buf_i]));
718 const dyn64: *elf.Elf64_Dyn = @ptrCast(@alignCast(&dyn_buf[dyn_buf_i]));
731719 const tag = elfInt(is_64, need_bswap, dyn32.d_tag, dyn64.d_tag);
732720 const val = elfInt(is_64, need_bswap, dyn32.d_val, dyn64.d_val);
733721 if (tag == elf.DT_RUNPATH) {
......@@ -755,8 +743,8 @@ pub fn abiAndDynamicLinkerFromFile(
755743 if (sh_buf.len < shentsize) return error.InvalidElfFile;
756744
757745 _ = try preadMin(file, &sh_buf, str_section_off, shentsize);
758 const shstr32 = @ptrCast(*elf.Elf32_Shdr, @alignCast(@alignOf(elf.Elf32_Shdr), &sh_buf));
759 const shstr64 = @ptrCast(*elf.Elf64_Shdr, @alignCast(@alignOf(elf.Elf64_Shdr), &sh_buf));
746 const shstr32: *elf.Elf32_Shdr = @ptrCast(@alignCast(&sh_buf));
747 const shstr64: *elf.Elf64_Shdr = @ptrCast(@alignCast(&sh_buf));
760748 const shstrtab_off = elfInt(is_64, need_bswap, shstr32.sh_offset, shstr64.sh_offset);
761749 const shstrtab_size = elfInt(is_64, need_bswap, shstr32.sh_size, shstr64.sh_size);
762750 var strtab_buf: [4096:0]u8 = undefined;
......@@ -782,14 +770,8 @@ pub fn abiAndDynamicLinkerFromFile(
782770 shoff += shentsize;
783771 sh_buf_i += shentsize;
784772 }) {
785 const sh32 = @ptrCast(
786 *elf.Elf32_Shdr,
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 );
773 const sh32: *elf.Elf32_Shdr = @ptrCast(@alignCast(&sh_buf[sh_buf_i]));
774 const sh64: *elf.Elf64_Shdr = @ptrCast(@alignCast(&sh_buf[sh_buf_i]));
793775 const sh_name_off = elfInt(is_64, need_bswap, sh32.sh_name, sh64.sh_name);
794776 const sh_name = mem.sliceTo(shstrtab[sh_name_off..], 0);
795777 if (mem.eql(u8, sh_name, ".dynstr")) {
lib/std/zig/system/arm.zig+7-7
......@@ -141,7 +141,7 @@ pub const aarch64 = struct {
141141 }
142142
143143 inline fn bitField(input: u64, offset: u6) u4 {
144 return @truncate(u4, input >> offset);
144 return @as(u4, @truncate(input >> offset));
145145 }
146146
147147 /// Input array should consist of readouts from 12 system registers such that:
......@@ -176,23 +176,23 @@ pub const aarch64 = struct {
176176 /// Takes readout of MIDR_EL1 register as input.
177177 fn detectNativeCoreInfo(midr: u64) CoreInfo {
178178 var info = CoreInfo{
179 .implementer = @truncate(u8, midr >> 24),
180 .part = @truncate(u12, midr >> 4),
179 .implementer = @as(u8, @truncate(midr >> 24)),
180 .part = @as(u12, @truncate(midr >> 4)),
181181 };
182182
183183 blk: {
184184 if (info.implementer == 0x41) {
185185 // ARM Ltd.
186 const special_bits = @truncate(u4, info.part >> 8);
186 const special_bits = @as(u4, @truncate(info.part >> 8));
187187 if (special_bits == 0x0 or special_bits == 0x7) {
188188 // TODO Variant and arch encoded differently.
189189 break :blk;
190190 }
191191 }
192192
193 info.variant |= @intCast(u8, @truncate(u4, midr >> 20)) << 4;
194 info.variant |= @truncate(u4, midr);
195 info.architecture = @truncate(u4, midr >> 16);
193 info.variant |= @as(u8, @intCast(@as(u4, @truncate(midr >> 20)))) << 4;
194 info.variant |= @as(u4, @truncate(midr));
195 info.architecture = @as(u4, @truncate(midr >> 16));
196196 }
197197
198198 return info;
lib/std/zig/system/windows.zig+20-20
......@@ -26,8 +26,8 @@ pub fn detectRuntimeVersion() WindowsVersion {
2626 // `---` `` ``--> Sub-version (Starting from Windows 10 onwards)
2727 // \ `--> Service pack (Always zero in the constants defined)
2828 // `--> OS version (Major & minor)
29 const os_ver: u16 = @intCast(u16, version_info.dwMajorVersion & 0xff) << 8 |
30 @intCast(u16, version_info.dwMinorVersion & 0xff);
29 const os_ver: u16 = @as(u16, @intCast(version_info.dwMajorVersion & 0xff)) << 8 |
30 @as(u16, @intCast(version_info.dwMinorVersion & 0xff));
3131 const sp_ver: u8 = 0;
3232 const sub_ver: u8 = if (os_ver >= 0x0A00) subver: {
3333 // There's no other way to obtain this info beside
......@@ -38,12 +38,12 @@ pub fn detectRuntimeVersion() WindowsVersion {
3838 if (version_info.dwBuildNumber >= build)
3939 last_idx = i;
4040 }
41 break :subver @truncate(u8, last_idx);
41 break :subver @as(u8, @truncate(last_idx));
4242 } else 0;
4343
4444 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));
4747}
4848
4949// 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 {
100100 REG.MULTI_SZ,
101101 => {
102102 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]));
104104 unicode.* = .{
105105 .Length = 0,
106106 .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)..])),
108108 };
109109 break :blk unicode;
110110 },
......@@ -159,7 +159,7 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
159159 REG.MULTI_SZ,
160160 => {
161161 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));
163163 const len = try std.unicode.utf16leToUtf8(buf, entry.Buffer[0 .. entry.Length / 2]);
164164 buf[len] = 0;
165165 },
......@@ -168,7 +168,7 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
168168 REG.DWORD_BIG_ENDIAN,
169169 REG.QWORD,
170170 => {
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));
172172 switch (@field(args, field.name).value_type) {
173173 REG.DWORD, REG.DWORD_BIG_ENDIAN => {
174174 @memcpy(@field(args, field.name).value_buf[0..4], entry[0..4]);
......@@ -254,18 +254,18 @@ pub fn detectNativeCpuAndFeatures() ?Target.Cpu {
254254 // CP 4039 -> ID_AA64MMFR1_EL1
255255 // CP 403A -> ID_AA64MMFR2_EL1
256256 getCpuInfoFromRegistry(i, .{
257 .{ .key = "CP 4000", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[0]) },
258 .{ .key = "CP 4020", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[1]) },
259 .{ .key = "CP 4021", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[2]) },
260 .{ .key = "CP 4028", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[3]) },
261 .{ .key = "CP 4029", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[4]) },
262 .{ .key = "CP 402C", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[5]) },
263 .{ .key = "CP 402D", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[6]) },
264 .{ .key = "CP 4030", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[7]) },
265 .{ .key = "CP 4031", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[8]) },
266 .{ .key = "CP 4038", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[9]) },
267 .{ .key = "CP 4039", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[10]) },
268 .{ .key = "CP 403A", .value_type = REG.QWORD, .value_buf = @ptrCast(*[8]u8, &registers[11]) },
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 = @as(*[8]u8, @ptrCast(&registers[1])) },
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 = @as(*[8]u8, @ptrCast(&registers[3])) },
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 = @as(*[8]u8, @ptrCast(&registers[5])) },
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 = @as(*[8]u8, @ptrCast(&registers[7])) },
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 = @as(*[8]u8, @ptrCast(&registers[9])) },
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 = @as(*[8]u8, @ptrCast(&registers[11])) },
269269 }) catch break :blk null;
270270
271271 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 {
12901290 // check utf8-encoded character.
12911291 const length = std.unicode.utf8ByteSequenceLength(c0) catch return 1;
12921292 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));
12941294 }
12951295 const bytes = self.buffer[self.index .. self.index + length];
12961296 switch (length) {
lib/test_runner.zig+3-3
......@@ -70,12 +70,12 @@ fn mainServer() !void {
7070 defer std.testing.allocator.free(expected_panic_msgs);
7171
7272 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));
7474 try string_bytes.ensureUnusedCapacity(std.testing.allocator, test_fn.name.len + 1);
7575 string_bytes.appendSliceAssumeCapacity(test_fn.name);
7676 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));
7979 expected_panic_msg.* = 0;
8080 }
8181
......@@ -163,7 +163,7 @@ fn mainTerminal() void {
163163 std.heap.page_allocator.free(async_frame_buffer);
164164 async_frame_buffer = std.heap.page_allocator.alignedAlloc(u8, std.Target.stack_align, size) catch @panic("out of memory");
165165 }
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));
167167 break :blk await @asyncCall(async_frame_buffer, {}, casted_fn, .{});
168168 },
169169 .blocking => {
src/Air.zig+13-13
......@@ -1106,7 +1106,7 @@ pub const VectorCmp = struct {
11061106 op: u32,
11071107
11081108 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))));
11101110 }
11111111
11121112 pub fn encodeOp(compare_operator: std.math.CompareOperator) u32 {
......@@ -1151,11 +1151,11 @@ pub const Cmpxchg = struct {
11511151 flags: u32,
11521152
11531153 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))));
11551155 }
11561156
11571157 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))));
11591159 }
11601160};
11611161
......@@ -1166,11 +1166,11 @@ pub const AtomicRmw = struct {
11661166 flags: u32,
11671167
11681168 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))));
11701170 }
11711171
11721172 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))));
11741174 }
11751175};
11761176
......@@ -1451,7 +1451,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
14511451pub fn getRefType(air: Air, ref: Air.Inst.Ref) Type {
14521452 const ref_int = @intFromEnum(ref);
14531453 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));
14551455 return ip_index.toType();
14561456 }
14571457 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
14721472 inline for (fields) |field| {
14731473 @field(result, field.name) = switch (field.type) {
14741474 u32 => air.extra[i],
1475 Inst.Ref => @enumFromInt(Inst.Ref, air.extra[i]),
1476 i32 => @bitCast(i32, air.extra[i]),
1477 InternPool.Index => @enumFromInt(InternPool.Index, air.extra[i]),
1475 Inst.Ref => @as(Inst.Ref, @enumFromInt(air.extra[i])),
1476 i32 => @as(i32, @bitCast(air.extra[i])),
1477 InternPool.Index => @as(InternPool.Index, @enumFromInt(air.extra[i])),
14781478 else => @compileError("bad field type: " ++ @typeName(field.type)),
14791479 };
14801480 i += 1;
......@@ -1494,7 +1494,7 @@ pub fn deinit(air: *Air, gpa: std.mem.Allocator) void {
14941494pub const ref_start_index: u32 = InternPool.static_len;
14951495
14961496pub 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));
14981498}
14991499
15001500pub fn refToIndex(inst: Inst.Ref) ?Inst.Index {
......@@ -1516,10 +1516,10 @@ pub fn refToIndexAllowNone(inst: Inst.Ref) ?Inst.Index {
15161516pub fn value(air: Air, inst: Inst.Ref, mod: *Module) !?Value {
15171517 const ref_int = @intFromEnum(inst);
15181518 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));
15201520 return ip_index.toValue();
15211521 }
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));
15231523 const air_datas = air.instructions.items(.data);
15241524 switch (air.instructions.items(.tag)[inst_index]) {
15251525 .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 {
17471747 .work_group_id,
17481748 => 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,
17511751 .load => air.typeOf(data.ty_op.operand, ip).isVolatilePtrIp(ip),
17521752 .slice_elem_val, .ptr_elem_val => air.typeOf(data.bin_op.lhs, ip).isVolatilePtrIp(ip),
17531753 .atomic_load => air.typeOf(data.atomic_load.ptr, ip).isVolatilePtrIp(ip),
src/AstGen.zig+332-223
......@@ -70,7 +70,7 @@ fn addExtra(astgen: *AstGen, extra: anytype) Allocator.Error!u32 {
7070
7171fn addExtraAssumeCapacity(astgen: *AstGen, extra: anytype) u32 {
7272 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));
7474 astgen.extra.items.len += fields.len;
7575 setExtra(astgen, result, extra);
7676 return result;
......@@ -83,11 +83,11 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {
8383 astgen.extra.items[i] = switch (field.type) {
8484 u32 => @field(extra, field.name),
8585 Zir.Inst.Ref => @intFromEnum(@field(extra, field.name)),
86 i32 => @bitCast(u32, @field(extra, field.name)),
87 Zir.Inst.Call.Flags => @bitCast(u32, @field(extra, field.name)),
88 Zir.Inst.BuiltinCall.Flags => @bitCast(u32, @field(extra, field.name)),
89 Zir.Inst.SwitchBlock.Bits => @bitCast(u32, @field(extra, field.name)),
90 Zir.Inst.FuncFancy.Bits => @bitCast(u32, @field(extra, field.name)),
86 i32 => @as(u32, @bitCast(@field(extra, field.name))),
87 Zir.Inst.Call.Flags => @as(u32, @bitCast(@field(extra, field.name))),
88 Zir.Inst.BuiltinCall.Flags => @as(u32, @bitCast(@field(extra, field.name))),
89 Zir.Inst.SwitchBlock.Bits => @as(u32, @bitCast(@field(extra, field.name))),
90 Zir.Inst.FuncFancy.Bits => @as(u32, @bitCast(@field(extra, field.name))),
9191 else => @compileError("bad field type"),
9292 };
9393 i += 1;
......@@ -95,18 +95,18 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {
9595}
9696
9797fn 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));
9999 try astgen.extra.resize(astgen.gpa, result + size);
100100 return result;
101101}
102102
103103fn appendRefs(astgen: *AstGen, refs: []const Zir.Inst.Ref) !void {
104 const coerced = @ptrCast([]const u32, refs);
104 const coerced = @as([]const u32, @ptrCast(refs));
105105 return astgen.extra.appendSlice(astgen.gpa, coerced);
106106}
107107
108108fn appendRefsAssumeCapacity(astgen: *AstGen, refs: []const Zir.Inst.Ref) void {
109 const coerced = @ptrCast([]const u32, refs);
109 const coerced = @as([]const u32, @ptrCast(refs));
110110 astgen.extra.appendSliceAssumeCapacity(coerced);
111111}
112112
......@@ -176,7 +176,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
176176 @typeInfo(Zir.Inst.CompileErrors.Item).Struct.fields.len);
177177
178178 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)),
180180 });
181181
182182 for (astgen.compile_errors.items) |item| {
......@@ -192,7 +192,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
192192 astgen.imports.count() * @typeInfo(Zir.Inst.Imports.Item).Struct.fields.len);
193193
194194 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())),
196196 });
197197
198198 var it = astgen.imports.iterator();
......@@ -335,6 +335,32 @@ const ResultInfo = struct {
335335 },
336336 }
337337 }
338
339 /// Find the result type for a cast builtin given the result location.
340 /// If the location does not have a known result type, emits an error on
341 /// the given node.
342 fn resultType(rl: Loc, gz: *GenZir, node: Ast.Node.Index, builtin_name: []const u8) !Zir.Inst.Ref {
343 const astgen = gz.astgen;
344 switch (rl) {
345 .discard, .none, .ref, .inferred_ptr => {},
346 .ty, .coerced_ty => |ty_ref| return ty_ref,
347 .ptr => |ptr| {
348 const ptr_ty = try gz.addUnNode(.typeof, ptr.inst, node);
349 return gz.addUnNode(.elem_type, ptr_ty, node);
350 },
351 .block_ptr => |block_scope| {
352 if (block_scope.rl_ty_inst != .none) return block_scope.rl_ty_inst;
353 if (block_scope.break_result_info.rl == .ptr) {
354 const ptr_ty = try gz.addUnNode(.typeof, block_scope.break_result_info.rl.ptr.inst, node);
355 return gz.addUnNode(.elem_type, ptr_ty, node);
356 }
357 },
358 }
359
360 return astgen.failNodeNotes(node, "{s} must have a known result type", .{builtin_name}, &.{
361 try astgen.errNoteNode(node, "use @as to provide explicit result type", .{}),
362 });
363 }
338364 };
339365
340366 const Context = enum {
......@@ -1308,7 +1334,7 @@ fn fnProtoExpr(
13081334 var param_gz = block_scope.makeSubBlock(scope);
13091335 defer param_gz.unstack();
13101336 const param_type = try expr(&param_gz, scope, coerced_type_ri, param_type_node);
1311 const param_inst_expected = @intCast(u32, astgen.instructions.len + 1);
1337 const param_inst_expected = @as(u32, @intCast(astgen.instructions.len + 1));
13121338 _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node);
13131339 const main_tokens = tree.nodes.items(.main_token);
13141340 const name_token = param.name_token orelse main_tokens[param_type_node];
......@@ -1442,7 +1468,7 @@ fn arrayInitExpr(
14421468 const array_type_inst = try typeExpr(gz, scope, array_init.ast.type_expr);
14431469 _ = try gz.addPlNode(.validate_array_init_ty, node, Zir.Inst.ArrayInit{
14441470 .ty = array_type_inst,
1445 .init_count = @intCast(u32, array_init.ast.elements.len),
1471 .init_count = @as(u32, @intCast(array_init.ast.elements.len)),
14461472 });
14471473 break :inst .{
14481474 .array = array_type_inst,
......@@ -1507,7 +1533,7 @@ fn arrayInitExprRlNone(
15071533 const astgen = gz.astgen;
15081534
15091535 const payload_index = try addExtra(astgen, Zir.Inst.MultiOp{
1510 .operands_len = @intCast(u32, elements.len),
1536 .operands_len = @as(u32, @intCast(elements.len)),
15111537 });
15121538 var extra_index = try reserveExtra(astgen, elements.len);
15131539
......@@ -1532,7 +1558,7 @@ fn arrayInitExprInner(
15321558
15331559 const len = elements.len + @intFromBool(array_ty_inst != .none);
15341560 const payload_index = try addExtra(astgen, Zir.Inst.MultiOp{
1535 .operands_len = @intCast(u32, len),
1561 .operands_len = @as(u32, @intCast(len)),
15361562 });
15371563 var extra_index = try reserveExtra(astgen, len);
15381564 if (array_ty_inst != .none) {
......@@ -1548,7 +1574,7 @@ fn arrayInitExprInner(
15481574 .tag = .elem_type_index,
15491575 .data = .{ .bin = .{
15501576 .lhs = array_ty_inst,
1551 .rhs = @enumFromInt(Zir.Inst.Ref, i),
1577 .rhs = @as(Zir.Inst.Ref, @enumFromInt(i)),
15521578 } },
15531579 });
15541580 break :ri ResultInfo{ .rl = .{ .coerced_ty = ty_expr } };
......@@ -1593,14 +1619,14 @@ fn arrayInitExprRlPtrInner(
15931619 const astgen = gz.astgen;
15941620
15951621 const payload_index = try addExtra(astgen, Zir.Inst.Block{
1596 .body_len = @intCast(u32, elements.len),
1622 .body_len = @as(u32, @intCast(elements.len)),
15971623 });
15981624 var extra_index = try reserveExtra(astgen, elements.len);
15991625
16001626 for (elements, 0..) |elem_init, i| {
16011627 const elem_ptr = try gz.addPlNode(.elem_ptr_imm, elem_init, Zir.Inst.ElemPtrImm{
16021628 .ptr = result_ptr,
1603 .index = @intCast(u32, i),
1629 .index = @as(u32, @intCast(i)),
16041630 });
16051631 astgen.extra.items[extra_index] = refToIndex(elem_ptr).?;
16061632 extra_index += 1;
......@@ -1750,7 +1776,7 @@ fn structInitExprRlNone(
17501776 const tree = astgen.tree;
17511777
17521778 const payload_index = try addExtra(astgen, Zir.Inst.StructInitAnon{
1753 .fields_len = @intCast(u32, struct_init.ast.fields.len),
1779 .fields_len = @as(u32, @intCast(struct_init.ast.fields.len)),
17541780 });
17551781 const field_size = @typeInfo(Zir.Inst.StructInitAnon.Item).Struct.fields.len;
17561782 var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size);
......@@ -1808,7 +1834,7 @@ fn structInitExprRlPtrInner(
18081834 const tree = astgen.tree;
18091835
18101836 const payload_index = try addExtra(astgen, Zir.Inst.Block{
1811 .body_len = @intCast(u32, struct_init.ast.fields.len),
1837 .body_len = @as(u32, @intCast(struct_init.ast.fields.len)),
18121838 });
18131839 var extra_index = try reserveExtra(astgen, struct_init.ast.fields.len);
18141840
......@@ -1840,7 +1866,7 @@ fn structInitExprRlTy(
18401866 const tree = astgen.tree;
18411867
18421868 const payload_index = try addExtra(astgen, Zir.Inst.StructInit{
1843 .fields_len = @intCast(u32, struct_init.ast.fields.len),
1869 .fields_len = @as(u32, @intCast(struct_init.ast.fields.len)),
18441870 });
18451871 const field_size = @typeInfo(Zir.Inst.StructInit.Item).Struct.fields.len;
18461872 var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size);
......@@ -2079,7 +2105,7 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn
20792105 }
20802106
20812107 const operand = try reachableExpr(parent_gz, parent_scope, block_gz.break_result_info, rhs, node);
2082 const search_index = @intCast(Zir.Inst.Index, astgen.instructions.len);
2108 const search_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
20832109
20842110 try genDefers(parent_gz, scope, parent_scope, .normal_only);
20852111
......@@ -2485,17 +2511,17 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
24852511 .call, .field_call => {
24862512 const extra_index = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index;
24872513 const slot = &gz.astgen.extra.items[extra_index];
2488 var flags = @bitCast(Zir.Inst.Call.Flags, slot.*);
2514 var flags = @as(Zir.Inst.Call.Flags, @bitCast(slot.*));
24892515 flags.ensure_result_used = true;
2490 slot.* = @bitCast(u32, flags);
2516 slot.* = @as(u32, @bitCast(flags));
24912517 break :b true;
24922518 },
24932519 .builtin_call => {
24942520 const extra_index = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index;
24952521 const slot = &gz.astgen.extra.items[extra_index];
2496 var flags = @bitCast(Zir.Inst.BuiltinCall.Flags, slot.*);
2522 var flags = @as(Zir.Inst.BuiltinCall.Flags, @bitCast(slot.*));
24972523 flags.ensure_result_used = true;
2498 slot.* = @bitCast(u32, flags);
2524 slot.* = @as(u32, @bitCast(flags));
24992525 break :b true;
25002526 },
25012527
......@@ -2521,6 +2547,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
25212547 .array_type,
25222548 .array_type_sentinel,
25232549 .elem_type_index,
2550 .elem_type,
25242551 .vector_type,
25252552 .indexable_ptr_len,
25262553 .anyframe_type,
......@@ -2662,7 +2689,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
26622689 .int_cast,
26632690 .ptr_cast,
26642691 .truncate,
2665 .align_cast,
26662692 .has_decl,
26672693 .has_field,
26682694 .clz,
......@@ -2871,7 +2897,7 @@ fn genDefers(
28712897 .index = defer_scope.index,
28722898 .len = defer_scope.len,
28732899 });
2874 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
2900 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
28752901 gz.astgen.instructions.appendAssumeCapacity(.{
28762902 .tag = .defer_err_code,
28772903 .data = .{ .defer_err_code = .{
......@@ -2950,7 +2976,7 @@ fn deferStmt(
29502976 const sub_scope = if (!have_err_code) &defer_gen.base else blk: {
29512977 try gz.addDbgBlockBegin();
29522978 const ident_name = try gz.astgen.identAsString(payload_token);
2953 remapped_err_code = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
2979 remapped_err_code = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
29542980 try gz.astgen.instructions.append(gz.astgen.gpa, .{
29552981 .tag = .extended,
29562982 .data = .{ .extended = .{
......@@ -2990,7 +3016,7 @@ fn deferStmt(
29903016 break :blk gz.astgen.countBodyLenAfterFixups(body) + refs;
29913017 };
29923018
2993 const index = @intCast(u32, gz.astgen.extra.items.len);
3019 const index = @as(u32, @intCast(gz.astgen.extra.items.len));
29943020 try gz.astgen.extra.ensureUnusedCapacity(gz.astgen.gpa, body_len);
29953021 if (have_err_code) {
29963022 if (gz.astgen.ref_table.fetchRemove(remapped_err_code)) |kv| {
......@@ -3528,7 +3554,7 @@ fn ptrType(
35283554 gz.astgen.extra.appendAssumeCapacity(@intFromEnum(bit_end_ref));
35293555 }
35303556
3531 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
3557 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
35323558 const result = indexToRef(new_index);
35333559 gz.astgen.instructions.appendAssumeCapacity(.{ .tag = .ptr_type, .data = .{
35343560 .ptr_type = .{
......@@ -3619,7 +3645,7 @@ const WipMembers = struct {
36193645 const max_decl_size = 11;
36203646
36213647 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 {
3622 const payload_top = @intCast(u32, payload.items.len);
3648 const payload_top = @as(u32, @intCast(payload.items.len));
36233649 const decls_start = payload_top + (decl_count + decls_per_u32 - 1) / decls_per_u32;
36243650 const field_bits_start = decls_start + decl_count * max_decl_size;
36253651 const fields_start = field_bits_start + if (bits_per_field > 0) blk: {
......@@ -3674,7 +3700,7 @@ const WipMembers = struct {
36743700 fn appendToDeclSlice(self: *Self, data: []const u32) void {
36753701 assert(self.decls_end + data.len <= self.field_bits_start);
36763702 @memcpy(self.payload.items[self.decls_end..][0..data.len], data);
3677 self.decls_end += @intCast(u32, data.len);
3703 self.decls_end += @as(u32, @intCast(data.len));
36783704 }
36793705
36803706 fn appendToField(self: *Self, data: u32) void {
......@@ -3687,14 +3713,14 @@ const WipMembers = struct {
36873713 const empty_decl_slots = decls_per_u32 - (self.decl_index % decls_per_u32);
36883714 if (self.decl_index > 0 and empty_decl_slots < decls_per_u32) {
36893715 const index = self.payload_top + self.decl_index / decls_per_u32;
3690 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));
36913717 }
36923718 if (bits_per_field > 0) {
36933719 const fields_per_u32 = 32 / bits_per_field;
36943720 const empty_field_slots = fields_per_u32 - (self.field_index % fields_per_u32);
36953721 if (self.field_index > 0 and empty_field_slots < fields_per_u32) {
36963722 const index = self.field_bits_start + self.field_index / fields_per_u32;
3697 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));
36983724 }
36993725 }
37003726 }
......@@ -3856,7 +3882,7 @@ fn fnDecl(
38563882 var param_gz = decl_gz.makeSubBlock(scope);
38573883 defer param_gz.unstack();
38583884 const param_type = try expr(&param_gz, params_scope, coerced_type_ri, param_type_node);
3859 const param_inst_expected = @intCast(u32, astgen.instructions.len + 1);
3885 const param_inst_expected = @as(u32, @intCast(astgen.instructions.len + 1));
38603886 _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node);
38613887
38623888 const main_tokens = tree.nodes.items(.main_token);
......@@ -4071,7 +4097,7 @@ fn fnDecl(
40714097
40724098 {
40734099 const contents_hash = std.zig.hashSrc(tree.getNodeSource(decl_node));
4074 const casted = @bitCast([4]u32, contents_hash);
4100 const casted = @as([4]u32, @bitCast(contents_hash));
40754101 wip_members.appendToDeclSlice(&casted);
40764102 }
40774103 {
......@@ -4222,7 +4248,7 @@ fn globalVarDecl(
42224248
42234249 {
42244250 const contents_hash = std.zig.hashSrc(tree.getNodeSource(node));
4225 const casted = @bitCast([4]u32, contents_hash);
4251 const casted = @as([4]u32, @bitCast(contents_hash));
42264252 wip_members.appendToDeclSlice(&casted);
42274253 }
42284254 {
......@@ -4277,7 +4303,7 @@ fn comptimeDecl(
42774303
42784304 {
42794305 const contents_hash = std.zig.hashSrc(tree.getNodeSource(node));
4280 const casted = @bitCast([4]u32, contents_hash);
4306 const casted = @as([4]u32, @bitCast(contents_hash));
42814307 wip_members.appendToDeclSlice(&casted);
42824308 }
42834309 {
......@@ -4329,7 +4355,7 @@ fn usingnamespaceDecl(
43294355
43304356 {
43314357 const contents_hash = std.zig.hashSrc(tree.getNodeSource(node));
4332 const casted = @bitCast([4]u32, contents_hash);
4358 const casted = @as([4]u32, @bitCast(contents_hash));
43334359 wip_members.appendToDeclSlice(&casted);
43344360 }
43354361 {
......@@ -4516,7 +4542,7 @@ fn testDecl(
45164542
45174543 {
45184544 const contents_hash = std.zig.hashSrc(tree.getNodeSource(node));
4519 const casted = @bitCast([4]u32, contents_hash);
4545 const casted = @as([4]u32, @bitCast(contents_hash));
45204546 wip_members.appendToDeclSlice(&casted);
45214547 }
45224548 {
......@@ -4616,7 +4642,7 @@ fn structDeclInner(
46164642 };
46174643
46184644 const decl_count = try astgen.scanDecls(&namespace, container_decl.ast.members);
4619 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));
46204646
46214647 const bits_per_field = 4;
46224648 const max_field_size = 5;
......@@ -4724,7 +4750,7 @@ fn structDeclInner(
47244750 const old_scratch_len = astgen.scratch.items.len;
47254751 try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body));
47264752 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);
4727 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)));
47284754 block_scope.instructions.items.len = block_scope.instructions_top;
47294755 } else {
47304756 wip_members.appendToField(@intFromEnum(field_type));
......@@ -4742,7 +4768,7 @@ fn structDeclInner(
47424768 const old_scratch_len = astgen.scratch.items.len;
47434769 try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body));
47444770 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);
4745 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)));
47464772 block_scope.instructions.items.len = block_scope.instructions_top;
47474773 }
47484774
......@@ -4757,7 +4783,7 @@ fn structDeclInner(
47574783 const old_scratch_len = astgen.scratch.items.len;
47584784 try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body));
47594785 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);
4760 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)));
47614787 block_scope.instructions.items.len = block_scope.instructions_top;
47624788 } else if (member.comptime_token) |comptime_token| {
47634789 return astgen.failTok(comptime_token, "comptime field without default initialization value", .{});
......@@ -4770,7 +4796,7 @@ fn structDeclInner(
47704796 .fields_len = field_count,
47714797 .decls_len = decl_count,
47724798 .backing_int_ref = backing_int_ref,
4773 .backing_int_body_len = @intCast(u32, backing_int_body_len),
4799 .backing_int_body_len = @as(u32, @intCast(backing_int_body_len)),
47744800 .known_non_opv = known_non_opv,
47754801 .known_comptime_only = known_comptime_only,
47764802 .is_tuple = is_tuple,
......@@ -4830,7 +4856,7 @@ fn unionDeclInner(
48304856 defer block_scope.unstack();
48314857
48324858 const decl_count = try astgen.scanDecls(&namespace, members);
4833 const field_count = @intCast(u32, members.len - decl_count);
4859 const field_count = @as(u32, @intCast(members.len - decl_count));
48344860
48354861 if (layout != .Auto and (auto_enum_tok != null or arg_node != 0)) {
48364862 const layout_str = if (layout == .Extern) "extern" else "packed";
......@@ -5125,7 +5151,7 @@ fn containerDecl(
51255151
51265152 const bits_per_field = 1;
51275153 const max_field_size = 3;
5128 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);
51295155 defer wip_members.deinit();
51305156
51315157 for (container_decl.ast.members) |member_node| {
......@@ -5183,8 +5209,8 @@ fn containerDecl(
51835209 .nonexhaustive = nonexhaustive,
51845210 .tag_type = arg_inst,
51855211 .body_len = body_len,
5186 .fields_len = @intCast(u32, counts.total_fields),
5187 .decls_len = @intCast(u32, counts.decls),
5212 .fields_len = @as(u32, @intCast(counts.total_fields)),
5213 .decls_len = @as(u32, @intCast(counts.decls)),
51885214 });
51895215
51905216 wip_members.finishBits(bits_per_field);
......@@ -5374,7 +5400,7 @@ fn errorSetDecl(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zi
53745400 }
53755401
53765402 setExtra(astgen, payload_index, Zir.Inst.ErrorSetDecl{
5377 .fields_len = @intCast(u32, fields_len),
5403 .fields_len = @as(u32, @intCast(fields_len)),
53785404 });
53795405 const result = try gz.addPlNodePayloadIndex(.error_set_decl, node, payload_index);
53805406 return rvalue(gz, ri, result, node);
......@@ -6437,7 +6463,7 @@ fn forExpr(
64376463 {
64386464 var capture_token = for_full.payload_token;
64396465 for (for_full.ast.inputs, 0..) |input, i_usize| {
6440 const i = @intCast(u32, i_usize);
6466 const i = @as(u32, @intCast(i_usize));
64416467 const capture_is_ref = token_tags[capture_token] == .asterisk;
64426468 const ident_tok = capture_token + @intFromBool(capture_is_ref);
64436469 const is_discard = mem.eql(u8, tree.tokenSlice(ident_tok), "_");
......@@ -6495,7 +6521,7 @@ fn forExpr(
64956521 // We use a dedicated ZIR instruction to assert the lengths to assist with
64966522 // nicer error reporting as well as fewer ZIR bytes emitted.
64976523 const len: Zir.Inst.Ref = len: {
6498 const lens_len = @intCast(u32, lens.len);
6524 const lens_len = @as(u32, @intCast(lens.len));
64996525 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.MultiOp).Struct.fields.len + lens_len);
65006526 const len = try parent_gz.addPlNode(.for_len, node, Zir.Inst.MultiOp{
65016527 .operands_len = lens_len,
......@@ -6565,7 +6591,7 @@ fn forExpr(
65656591 var capture_token = for_full.payload_token;
65666592 var capture_sub_scope: *Scope = &then_scope.base;
65676593 for (for_full.ast.inputs, 0..) |input, i_usize| {
6568 const i = @intCast(u32, i_usize);
6594 const i = @as(u32, @intCast(i_usize));
65696595 const capture_is_ref = token_tags[capture_token] == .asterisk;
65706596 const ident_tok = capture_token + @intFromBool(capture_is_ref);
65716597 const capture_name = tree.tokenSlice(ident_tok);
......@@ -6865,7 +6891,7 @@ fn switchExpr(
68656891
68666892 // If any prong has an inline tag capture, allocate a shared dummy instruction for it
68676893 const tag_inst = if (any_has_tag_capture) tag_inst: {
6868 const inst = @intCast(Zir.Inst.Index, astgen.instructions.len);
6894 const inst = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
68696895 try astgen.instructions.append(astgen.gpa, .{
68706896 .tag = .extended,
68716897 .data = .{ .extended = .{
......@@ -6958,7 +6984,7 @@ fn switchExpr(
69586984 break :blk &tag_scope.base;
69596985 };
69606986
6961 const header_index = @intCast(u32, payloads.items.len);
6987 const header_index = @as(u32, @intCast(payloads.items.len));
69626988 const body_len_index = if (is_multi_case) blk: {
69636989 payloads.items[multi_case_table + multi_case_index] = header_index;
69646990 multi_case_index += 1;
......@@ -7048,12 +7074,12 @@ fn switchExpr(
70487074 };
70497075 const body_len = refs_len + astgen.countBodyLenAfterFixups(case_slice);
70507076 try payloads.ensureUnusedCapacity(gpa, body_len);
7051 payloads.items[body_len_index] = @bitCast(u32, Zir.Inst.SwitchBlock.ProngInfo{
7052 .body_len = @intCast(u28, body_len),
7077 payloads.items[body_len_index] = @as(u32, @bitCast(Zir.Inst.SwitchBlock.ProngInfo{
7078 .body_len = @as(u28, @intCast(body_len)),
70537079 .capture = capture,
70547080 .is_inline = case.inline_token != null,
70557081 .has_tag_capture = has_tag_capture,
7056 });
7082 }));
70577083 if (astgen.ref_table.fetchRemove(switch_block)) |kv| {
70587084 appendPossiblyRefdBodyInst(astgen, payloads, kv.value);
70597085 }
......@@ -7080,7 +7106,7 @@ fn switchExpr(
70807106 .has_else = special_prong == .@"else",
70817107 .has_under = special_prong == .under,
70827108 .any_has_tag_capture = any_has_tag_capture,
7083 .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)),
70847110 },
70857111 });
70867112
......@@ -7114,7 +7140,7 @@ fn switchExpr(
71147140 end_index += 3 + items_len + 2 * ranges_len;
71157141 }
71167142
7117 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;
71187144 end_index += body_len;
71197145
71207146 switch (strat.tag) {
......@@ -7553,7 +7579,7 @@ fn tunnelThroughClosure(
75537579 .src_tok = ns.?.declaring_gz.?.tokenIndexToRelative(token),
75547580 } },
75557581 });
7556 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));
75577583 }
75587584
75597585 // Add an instruction to get the value from the closure into
......@@ -7654,7 +7680,7 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node:
76547680 };
76557681 // If the value fits into a f64 without losing any precision, store it that way.
76567682 @setFloatMode(.Strict);
7657 const smaller_float = @floatCast(f64, float_number);
7683 const smaller_float = @as(f64, @floatCast(float_number));
76587684 const bigger_again: f128 = smaller_float;
76597685 if (bigger_again == float_number) {
76607686 const result = try gz.addFloat(smaller_float);
......@@ -7662,12 +7688,12 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node:
76627688 }
76637689 // We need to use 128 bits. Break the float into 4 u32 values so we can
76647690 // put it into the `extra` array.
7665 const int_bits = @bitCast(u128, float_number);
7691 const int_bits = @as(u128, @bitCast(float_number));
76667692 const result = try gz.addPlNode(.float128, node, Zir.Inst.Float128{
7667 .piece0 = @truncate(u32, int_bits),
7668 .piece1 = @truncate(u32, int_bits >> 32),
7669 .piece2 = @truncate(u32, int_bits >> 64),
7670 .piece3 = @truncate(u32, int_bits >> 96),
7693 .piece0 = @as(u32, @truncate(int_bits)),
7694 .piece1 = @as(u32, @truncate(int_bits >> 32)),
7695 .piece2 = @as(u32, @truncate(int_bits >> 64)),
7696 .piece3 = @as(u32, @truncate(int_bits >> 96)),
76717697 });
76727698 return rvalue(gz, ri, result, source_node);
76737699 },
......@@ -7693,22 +7719,22 @@ fn failWithNumberError(astgen: *AstGen, err: std.zig.number_literal.Error, token
76937719 });
76947720 },
76957721 .digit_after_base => return astgen.failTok(token, "expected a digit after base prefix", .{}),
7696 .upper_case_base => |i| return astgen.failOff(token, @intCast(u32, i), "base prefix must be lowercase", .{}),
7697 .invalid_float_base => |i| return astgen.failOff(token, @intCast(u32, i), "invalid base for float literal", .{}),
7698 .repeated_underscore => |i| return astgen.failOff(token, @intCast(u32, i), "repeated digit separator", .{}),
7699 .invalid_underscore_after_special => |i| return astgen.failOff(token, @intCast(u32, i), "expected digit before digit separator", .{}),
7700 .invalid_digit => |info| return astgen.failOff(token, @intCast(u32, info.i), "invalid digit '{c}' for {s} base", .{ bytes[info.i], @tagName(info.base) }),
7701 .invalid_digit_exponent => |i| return astgen.failOff(token, @intCast(u32, i), "invalid digit '{c}' in exponent", .{bytes[i]}),
7702 .duplicate_exponent => |i| return astgen.failOff(token, @intCast(u32, i), "duplicate exponent", .{}),
7703 .exponent_after_underscore => |i| return astgen.failOff(token, @intCast(u32, i), "expected digit before exponent", .{}),
7704 .special_after_underscore => |i| return astgen.failOff(token, @intCast(u32, i), "expected digit before '{c}'", .{bytes[i]}),
7705 .trailing_special => |i| return astgen.failOff(token, @intCast(u32, i), "expected digit after '{c}'", .{bytes[i - 1]}),
7706 .trailing_underscore => |i| return astgen.failOff(token, @intCast(u32, i), "trailing digit separator", .{}),
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, @as(u32, @intCast(i)), "invalid base for float literal", .{}),
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, @as(u32, @intCast(i)), "expected digit before digit separator", .{}),
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, @as(u32, @intCast(i)), "invalid digit '{c}' in exponent", .{bytes[i]}),
7728 .duplicate_exponent => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "duplicate 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, @as(u32, @intCast(i)), "expected digit before '{c}'", .{bytes[i]}),
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, @as(u32, @intCast(i)), "trailing digit separator", .{}),
77077733 .duplicate_period => unreachable, // Validated by tokenizer
77087734 .invalid_character => unreachable, // Validated by tokenizer
77097735 .invalid_exponent_sign => |i| {
77107736 assert(bytes.len >= 2 and bytes[0] == '0' and bytes[1] == 'x'); // Validated by tokenizer
7711 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] });
77127738 },
77137739 }
77147740}
......@@ -7775,7 +7801,7 @@ fn asmExpr(
77757801 if (output_type_bits != 0) {
77767802 return astgen.failNode(output_node, "inline assembly allows up to one output value", .{});
77777803 }
7778 output_type_bits |= @as(u32, 1) << @intCast(u5, i);
7804 output_type_bits |= @as(u32, 1) << @as(u5, @intCast(i));
77797805 const out_type_node = node_datas[output_node].lhs;
77807806 const out_type_inst = try typeExpr(gz, scope, out_type_node);
77817807 outputs[i] = .{
......@@ -7924,11 +7950,10 @@ fn bitCast(
79247950 scope: *Scope,
79257951 ri: ResultInfo,
79267952 node: Ast.Node.Index,
7927 lhs: Ast.Node.Index,
7928 rhs: Ast.Node.Index,
7953 operand_node: Ast.Node.Index,
79297954) InnerError!Zir.Inst.Ref {
7930 const dest_type = try reachableTypeExpr(gz, scope, lhs, node);
7931 const operand = try reachableExpr(gz, scope, .{ .rl = .none }, rhs, node);
7955 const dest_type = try ri.rl.resultType(gz, node, "@bitCast");
7956 const operand = try reachableExpr(gz, scope, .{ .rl = .none }, operand_node, node);
79327957 const result = try gz.addPlNode(.bitcast, node, Zir.Inst.Bin{
79337958 .lhs = dest_type,
79347959 .rhs = operand,
......@@ -7936,6 +7961,116 @@ fn bitCast(
79367961 return rvalue(gz, ri, result, node);
79377962}
79387963
7964/// Handle one or more nested pointer cast builtins:
7965/// * @ptrCast
7966/// * @alignCast
7967/// * @addrSpaceCast
7968/// * @constCast
7969/// * @volatileCast
7970/// Any sequence of such builtins is treated as a single operation. This allowed
7971/// for sequences like `@ptrCast(@alignCast(ptr))` to work correctly despite the
7972/// intermediate result type being unknown.
7973fn ptrCast(
7974 gz: *GenZir,
7975 scope: *Scope,
7976 ri: ResultInfo,
7977 root_node: Ast.Node.Index,
7978) InnerError!Zir.Inst.Ref {
7979 const astgen = gz.astgen;
7980 const tree = astgen.tree;
7981 const main_tokens = tree.nodes.items(.main_token);
7982 const node_datas = tree.nodes.items(.data);
7983 const node_tags = tree.nodes.items(.tag);
7984
7985 var flags: Zir.Inst.FullPtrCastFlags = .{};
7986
7987 // Note that all pointer cast builtins have one parameter, so we only need
7988 // to handle `builtin_call_two`.
7989 var node = root_node;
7990 while (true) {
7991 switch (node_tags[node]) {
7992 .builtin_call_two, .builtin_call_two_comma => {},
7993 .grouped_expression => {
7994 // Handle the chaining even with redundant parentheses
7995 node = node_datas[node].lhs;
7996 continue;
7997 },
7998 else => break,
7999 }
8000
8001 if (node_datas[node].lhs == 0) break; // 0 args
8002 if (node_datas[node].rhs != 0) break; // 2 args
8003
8004 const builtin_token = main_tokens[node];
8005 const builtin_name = tree.tokenSlice(builtin_token);
8006 const info = BuiltinFn.list.get(builtin_name) orelse break;
8007 if (info.param_count != 1) break;
8008
8009 switch (info.tag) {
8010 else => break,
8011 inline .ptr_cast,
8012 .align_cast,
8013 .addrspace_cast,
8014 .const_cast,
8015 .volatile_cast,
8016 => |tag| {
8017 if (@field(flags, @tagName(tag))) {
8018 return astgen.failNode(node, "redundant {s}", .{builtin_name});
8019 }
8020 @field(flags, @tagName(tag)) = true;
8021 },
8022 }
8023
8024 node = node_datas[node].lhs;
8025 }
8026
8027 const flags_i = @as(u5, @bitCast(flags));
8028 assert(flags_i != 0);
8029
8030 const ptr_only: Zir.Inst.FullPtrCastFlags = .{ .ptr_cast = true };
8031 if (flags_i == @as(u5, @bitCast(ptr_only))) {
8032 // Special case: simpler representation
8033 return typeCast(gz, scope, ri, root_node, node, .ptr_cast, "@ptrCast");
8034 }
8035
8036 const no_result_ty_flags: Zir.Inst.FullPtrCastFlags = .{
8037 .const_cast = true,
8038 .volatile_cast = true,
8039 };
8040 if ((flags_i & ~@as(u5, @bitCast(no_result_ty_flags))) == 0) {
8041 // Result type not needed
8042 const cursor = maybeAdvanceSourceCursorToMainToken(gz, root_node);
8043 const operand = try expr(gz, scope, .{ .rl = .none }, node);
8044 try emitDbgStmt(gz, cursor);
8045 const result = try gz.addExtendedPayloadSmall(.ptr_cast_no_dest, flags_i, Zir.Inst.UnNode{
8046 .node = gz.nodeIndexToRelative(root_node),
8047 .operand = operand,
8048 });
8049 return rvalue(gz, ri, result, root_node);
8050 }
8051
8052 // Full cast including result type
8053 const need_result_type_builtin = if (flags.ptr_cast)
8054 "@ptrCast"
8055 else if (flags.align_cast)
8056 "@alignCast"
8057 else if (flags.addrspace_cast)
8058 "@addrSpaceCast"
8059 else
8060 unreachable;
8061
8062 const cursor = maybeAdvanceSourceCursorToMainToken(gz, root_node);
8063 const result_type = try ri.rl.resultType(gz, root_node, need_result_type_builtin);
8064 const operand = try expr(gz, scope, .{ .rl = .none }, node);
8065 try emitDbgStmt(gz, cursor);
8066 const result = try gz.addExtendedPayloadSmall(.ptr_cast_full, flags_i, Zir.Inst.BinNode{
8067 .node = gz.nodeIndexToRelative(root_node),
8068 .lhs = result_type,
8069 .rhs = operand,
8070 });
8071 return rvalue(gz, ri, result, root_node);
8072}
8073
79398074fn typeOf(
79408075 gz: *GenZir,
79418076 scope: *Scope,
......@@ -7984,8 +8119,8 @@ fn typeOf(
79848119 const body = typeof_scope.instructionsSlice();
79858120 const body_len = astgen.countBodyLenAfterFixups(body);
79868121 astgen.setExtra(payload_index, Zir.Inst.TypeOfPeer{
7987 .body_len = @intCast(u32, body_len),
7988 .body_index = @intCast(u32, astgen.extra.items.len),
8122 .body_len = @as(u32, @intCast(body_len)),
8123 .body_index = @as(u32, @intCast(astgen.extra.items.len)),
79898124 .src_node = gz.nodeIndexToRelative(node),
79908125 });
79918126 try astgen.extra.ensureUnusedCapacity(gpa, body_len);
......@@ -8123,7 +8258,7 @@ fn builtinCall(
81238258
81248259 // zig fmt: off
81258260 .as => return as( gz, scope, ri, node, params[0], params[1]),
8126 .bit_cast => return bitCast( gz, scope, ri, node, params[0], params[1]),
8261 .bit_cast => return bitCast( gz, scope, ri, node, params[0]),
81278262 .TypeOf => return typeOf( gz, scope, ri, node, params),
81288263 .union_init => return unionInit(gz, scope, ri, node, params),
81298264 .c_import => return cImport( gz, scope, node, params[0]),
......@@ -8308,14 +8443,13 @@ fn builtinCall(
83088443 .Frame => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .frame_type),
83098444 .frame_size => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .frame_size),
83108445
8311 .int_from_float => return typeCast(gz, scope, ri, node, params[0], params[1], .int_from_float),
8312 .float_from_int => return typeCast(gz, scope, ri, node, params[0], params[1], .float_from_int),
8313 .ptr_from_int => return typeCast(gz, scope, ri, node, params[0], params[1], .ptr_from_int),
8314 .enum_from_int => return typeCast(gz, scope, ri, node, params[0], params[1], .enum_from_int),
8315 .float_cast => return typeCast(gz, scope, ri, node, params[0], params[1], .float_cast),
8316 .int_cast => return typeCast(gz, scope, ri, node, params[0], params[1], .int_cast),
8317 .ptr_cast => return typeCast(gz, scope, ri, node, params[0], params[1], .ptr_cast),
8318 .truncate => return typeCast(gz, scope, ri, node, params[0], params[1], .truncate),
8446 .int_from_float => return typeCast(gz, scope, ri, node, params[0], .int_from_float, builtin_name),
8447 .float_from_int => return typeCast(gz, scope, ri, node, params[0], .float_from_int, builtin_name),
8448 .ptr_from_int => return typeCast(gz, scope, ri, node, params[0], .ptr_from_int, builtin_name),
8449 .enum_from_int => return typeCast(gz, scope, ri, node, params[0], .enum_from_int, builtin_name),
8450 .float_cast => return typeCast(gz, scope, ri, node, params[0], .float_cast, builtin_name),
8451 .int_cast => return typeCast(gz, scope, ri, node, params[0], .int_cast, builtin_name),
8452 .truncate => return typeCast(gz, scope, ri, node, params[0], .truncate, builtin_name),
83198453 // zig fmt: on
83208454
83218455 .Type => {
......@@ -8330,7 +8464,7 @@ fn builtinCall(
83308464 .node = gz.nodeIndexToRelative(node),
83318465 .operand = operand,
83328466 });
8333 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
8467 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
83348468 gz.astgen.instructions.appendAssumeCapacity(.{
83358469 .tag = .extended,
83368470 .data = .{ .extended = .{
......@@ -8368,49 +8502,22 @@ fn builtinCall(
83688502 });
83698503 return rvalue(gz, ri, result, node);
83708504 },
8371 .align_cast => {
8372 const dest_align = try comptimeExpr(gz, scope, align_ri, params[0]);
8373 const rhs = try expr(gz, scope, .{ .rl = .none }, params[1]);
8374 const result = try gz.addPlNode(.align_cast, node, Zir.Inst.Bin{
8375 .lhs = dest_align,
8376 .rhs = rhs,
8377 });
8378 return rvalue(gz, ri, result, node);
8379 },
83808505 .err_set_cast => {
83818506 try emitDbgNode(gz, node);
83828507
83838508 const result = try gz.addExtendedPayload(.err_set_cast, Zir.Inst.BinNode{
8384 .lhs = try typeExpr(gz, scope, params[0]),
8385 .rhs = try expr(gz, scope, .{ .rl = .none }, params[1]),
8386 .node = gz.nodeIndexToRelative(node),
8387 });
8388 return rvalue(gz, ri, result, node);
8389 },
8390 .addrspace_cast => {
8391 const result = try gz.addExtendedPayload(.addrspace_cast, Zir.Inst.BinNode{
8392 .lhs = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .address_space_type } }, params[0]),
8393 .rhs = try expr(gz, scope, .{ .rl = .none }, params[1]),
8394 .node = gz.nodeIndexToRelative(node),
8395 });
8396 return rvalue(gz, ri, result, node);
8397 },
8398 .const_cast => {
8399 const operand = try expr(gz, scope, .{ .rl = .none }, params[0]);
8400 const result = try gz.addExtendedPayload(.const_cast, Zir.Inst.UnNode{
8509 .lhs = try ri.rl.resultType(gz, node, "@errSetCast"),
8510 .rhs = try expr(gz, scope, .{ .rl = .none }, params[0]),
84018511 .node = gz.nodeIndexToRelative(node),
8402 .operand = operand,
8403 });
8404 return rvalue(gz, ri, result, node);
8405 },
8406 .volatile_cast => {
8407 const operand = try expr(gz, scope, .{ .rl = .none }, params[0]);
8408 const result = try gz.addExtendedPayload(.volatile_cast, Zir.Inst.UnNode{
8409 .node = gz.nodeIndexToRelative(node),
8410 .operand = operand,
84118512 });
84128513 return rvalue(gz, ri, result, node);
84138514 },
8515 .ptr_cast,
8516 .align_cast,
8517 .addrspace_cast,
8518 .const_cast,
8519 .volatile_cast,
8520 => return ptrCast(gz, scope, ri, node),
84148521
84158522 // zig fmt: off
84168523 .has_decl => return hasDeclOrField(gz, scope, ri, node, params[0], params[1], .has_decl),
......@@ -8725,13 +8832,13 @@ fn typeCast(
87258832 scope: *Scope,
87268833 ri: ResultInfo,
87278834 node: Ast.Node.Index,
8728 lhs_node: Ast.Node.Index,
8729 rhs_node: Ast.Node.Index,
8835 operand_node: Ast.Node.Index,
87308836 tag: Zir.Inst.Tag,
8837 builtin_name: []const u8,
87318838) InnerError!Zir.Inst.Ref {
87328839 const cursor = maybeAdvanceSourceCursorToMainToken(gz, node);
8733 const result_type = try typeExpr(gz, scope, lhs_node);
8734 const operand = try expr(gz, scope, .{ .rl = .none }, rhs_node);
8840 const result_type = try ri.rl.resultType(gz, node, builtin_name);
8841 const operand = try expr(gz, scope, .{ .rl = .none }, operand_node);
87358842
87368843 try emitDbgStmt(gz, cursor);
87378844 const result = try gz.addPlNode(tag, node, Zir.Inst.Bin{
......@@ -9008,7 +9115,7 @@ fn callExpr(
90089115 }
90099116 assert(node != 0);
90109117
9011 const call_index = @intCast(Zir.Inst.Index, astgen.instructions.len);
9118 const call_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
90129119 const call_inst = Zir.indexToRef(call_index);
90139120 try gz.astgen.instructions.append(astgen.gpa, undefined);
90149121 try gz.instructions.append(astgen.gpa, call_index);
......@@ -9032,7 +9139,7 @@ fn callExpr(
90329139 try astgen.scratch.ensureUnusedCapacity(astgen.gpa, countBodyLenAfterFixups(astgen, body));
90339140 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);
90349141
9035 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));
90369143 scratch_index += 1;
90379144 }
90389145
......@@ -9050,8 +9157,8 @@ fn callExpr(
90509157 .callee = callee_obj,
90519158 .flags = .{
90529159 .pop_error_return_trace = !propagate_error_trace,
9053 .packed_modifier = @intCast(Zir.Inst.Call.Flags.PackedModifier, @intFromEnum(modifier)),
9054 .args_len = @intCast(Zir.Inst.Call.Flags.PackedArgsLen, call.ast.params.len),
9160 .packed_modifier = @as(Zir.Inst.Call.Flags.PackedModifier, @intCast(@intFromEnum(modifier))),
9161 .args_len = @as(Zir.Inst.Call.Flags.PackedArgsLen, @intCast(call.ast.params.len)),
90559162 },
90569163 });
90579164 if (call.ast.params.len != 0) {
......@@ -9071,8 +9178,8 @@ fn callExpr(
90719178 .field_name_start = callee_field.field_name_start,
90729179 .flags = .{
90739180 .pop_error_return_trace = !propagate_error_trace,
9074 .packed_modifier = @intCast(Zir.Inst.Call.Flags.PackedModifier, @intFromEnum(modifier)),
9075 .args_len = @intCast(Zir.Inst.Call.Flags.PackedArgsLen, call.ast.params.len),
9181 .packed_modifier = @as(Zir.Inst.Call.Flags.PackedModifier, @intCast(@intFromEnum(modifier))),
9182 .args_len = @as(Zir.Inst.Call.Flags.PackedArgsLen, @intCast(call.ast.params.len)),
90769183 },
90779184 });
90789185 if (call.ast.params.len != 0) {
......@@ -9432,6 +9539,7 @@ fn nodeMayNeedMemoryLocation(tree: *const Ast, start_node: Ast.Node.Index, have_
94329539 switch (builtin_info.needs_mem_loc) {
94339540 .never => return false,
94349541 .always => return true,
9542 .forward0 => node = node_datas[node].lhs,
94359543 .forward1 => node = node_datas[node].rhs,
94369544 }
94379545 // Missing builtin arg is not a parsing error, expect an error later.
......@@ -9448,6 +9556,7 @@ fn nodeMayNeedMemoryLocation(tree: *const Ast, start_node: Ast.Node.Index, have_
94489556 switch (builtin_info.needs_mem_loc) {
94499557 .never => return false,
94509558 .always => return true,
9559 .forward0 => node = params[0],
94519560 .forward1 => node = params[1],
94529561 }
94539562 // Missing builtin arg is not a parsing error, expect an error later.
......@@ -10443,7 +10552,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
1044310552 .invalid_escape_character => |bad_index| {
1044410553 return astgen.failOff(
1044510554 token,
10446 offset + @intCast(u32, bad_index),
10555 offset + @as(u32, @intCast(bad_index)),
1044710556 "invalid escape character: '{c}'",
1044810557 .{raw_string[bad_index]},
1044910558 );
......@@ -10451,7 +10560,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
1045110560 .expected_hex_digit => |bad_index| {
1045210561 return astgen.failOff(
1045310562 token,
10454 offset + @intCast(u32, bad_index),
10563 offset + @as(u32, @intCast(bad_index)),
1045510564 "expected hex digit, found '{c}'",
1045610565 .{raw_string[bad_index]},
1045710566 );
......@@ -10459,7 +10568,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
1045910568 .empty_unicode_escape_sequence => |bad_index| {
1046010569 return astgen.failOff(
1046110570 token,
10462 offset + @intCast(u32, bad_index),
10571 offset + @as(u32, @intCast(bad_index)),
1046310572 "empty unicode escape sequence",
1046410573 .{},
1046510574 );
......@@ -10467,7 +10576,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
1046710576 .expected_hex_digit_or_rbrace => |bad_index| {
1046810577 return astgen.failOff(
1046910578 token,
10470 offset + @intCast(u32, bad_index),
10579 offset + @as(u32, @intCast(bad_index)),
1047110580 "expected hex digit or '}}', found '{c}'",
1047210581 .{raw_string[bad_index]},
1047310582 );
......@@ -10475,7 +10584,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
1047510584 .invalid_unicode_codepoint => |bad_index| {
1047610585 return astgen.failOff(
1047710586 token,
10478 offset + @intCast(u32, bad_index),
10587 offset + @as(u32, @intCast(bad_index)),
1047910588 "unicode escape does not correspond to a valid codepoint",
1048010589 .{},
1048110590 );
......@@ -10483,7 +10592,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
1048310592 .expected_lbrace => |bad_index| {
1048410593 return astgen.failOff(
1048510594 token,
10486 offset + @intCast(u32, bad_index),
10595 offset + @as(u32, @intCast(bad_index)),
1048710596 "expected '{{', found '{c}",
1048810597 .{raw_string[bad_index]},
1048910598 );
......@@ -10491,7 +10600,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
1049110600 .expected_rbrace => |bad_index| {
1049210601 return astgen.failOff(
1049310602 token,
10494 offset + @intCast(u32, bad_index),
10603 offset + @as(u32, @intCast(bad_index)),
1049510604 "expected '}}', found '{c}",
1049610605 .{raw_string[bad_index]},
1049710606 );
......@@ -10499,7 +10608,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
1049910608 .expected_single_quote => |bad_index| {
1050010609 return astgen.failOff(
1050110610 token,
10502 offset + @intCast(u32, bad_index),
10611 offset + @as(u32, @intCast(bad_index)),
1050310612 "expected single quote ('), found '{c}",
1050410613 .{raw_string[bad_index]},
1050510614 );
......@@ -10507,7 +10616,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
1050710616 .invalid_character => |bad_index| {
1050810617 return astgen.failOff(
1050910618 token,
10510 offset + @intCast(u32, bad_index),
10619 offset + @as(u32, @intCast(bad_index)),
1051110620 "invalid byte in string or character literal: '{c}'",
1051210621 .{raw_string[bad_index]},
1051310622 );
......@@ -10542,14 +10651,14 @@ fn appendErrorNodeNotes(
1054210651) Allocator.Error!void {
1054310652 @setCold(true);
1054410653 const string_bytes = &astgen.string_bytes;
10545 const msg = @intCast(u32, string_bytes.items.len);
10654 const msg = @as(u32, @intCast(string_bytes.items.len));
1054610655 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
1054710656 const notes_index: u32 = if (notes.len != 0) blk: {
1054810657 const notes_start = astgen.extra.items.len;
1054910658 try astgen.extra.ensureTotalCapacity(astgen.gpa, notes_start + 1 + notes.len);
10550 astgen.extra.appendAssumeCapacity(@intCast(u32, notes.len));
10659 astgen.extra.appendAssumeCapacity(@as(u32, @intCast(notes.len)));
1055110660 astgen.extra.appendSliceAssumeCapacity(notes);
10552 break :blk @intCast(u32, notes_start);
10661 break :blk @as(u32, @intCast(notes_start));
1055310662 } else 0;
1055410663 try astgen.compile_errors.append(astgen.gpa, .{
1055510664 .msg = msg,
......@@ -10634,14 +10743,14 @@ fn appendErrorTokNotesOff(
1063410743 @setCold(true);
1063510744 const gpa = astgen.gpa;
1063610745 const string_bytes = &astgen.string_bytes;
10637 const msg = @intCast(u32, string_bytes.items.len);
10746 const msg = @as(u32, @intCast(string_bytes.items.len));
1063810747 try string_bytes.writer(gpa).print(format ++ "\x00", args);
1063910748 const notes_index: u32 = if (notes.len != 0) blk: {
1064010749 const notes_start = astgen.extra.items.len;
1064110750 try astgen.extra.ensureTotalCapacity(gpa, notes_start + 1 + notes.len);
10642 astgen.extra.appendAssumeCapacity(@intCast(u32, notes.len));
10751 astgen.extra.appendAssumeCapacity(@as(u32, @intCast(notes.len)));
1064310752 astgen.extra.appendSliceAssumeCapacity(notes);
10644 break :blk @intCast(u32, notes_start);
10753 break :blk @as(u32, @intCast(notes_start));
1064510754 } else 0;
1064610755 try astgen.compile_errors.append(gpa, .{
1064710756 .msg = msg,
......@@ -10670,7 +10779,7 @@ fn errNoteTokOff(
1067010779) Allocator.Error!u32 {
1067110780 @setCold(true);
1067210781 const string_bytes = &astgen.string_bytes;
10673 const msg = @intCast(u32, string_bytes.items.len);
10782 const msg = @as(u32, @intCast(string_bytes.items.len));
1067410783 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
1067510784 return astgen.addExtra(Zir.Inst.CompileErrors.Item{
1067610785 .msg = msg,
......@@ -10689,7 +10798,7 @@ fn errNoteNode(
1068910798) Allocator.Error!u32 {
1069010799 @setCold(true);
1069110800 const string_bytes = &astgen.string_bytes;
10692 const msg = @intCast(u32, string_bytes.items.len);
10801 const msg = @as(u32, @intCast(string_bytes.items.len));
1069310802 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
1069410803 return astgen.addExtra(Zir.Inst.CompileErrors.Item{
1069510804 .msg = msg,
......@@ -10703,7 +10812,7 @@ fn errNoteNode(
1070310812fn identAsString(astgen: *AstGen, ident_token: Ast.TokenIndex) !u32 {
1070410813 const gpa = astgen.gpa;
1070510814 const string_bytes = &astgen.string_bytes;
10706 const str_index = @intCast(u32, string_bytes.items.len);
10815 const str_index = @as(u32, @intCast(string_bytes.items.len));
1070710816 try astgen.appendIdentStr(ident_token, string_bytes);
1070810817 const key: []const u8 = string_bytes.items[str_index..];
1070910818 const gop = try astgen.string_table.getOrPutContextAdapted(gpa, key, StringIndexAdapter{
......@@ -10749,7 +10858,7 @@ fn docCommentAsStringFromFirst(
1074910858
1075010859 const gpa = astgen.gpa;
1075110860 const string_bytes = &astgen.string_bytes;
10752 const str_index = @intCast(u32, string_bytes.items.len);
10861 const str_index = @as(u32, @intCast(string_bytes.items.len));
1075310862 const token_starts = astgen.tree.tokens.items(.start);
1075410863 const token_tags = astgen.tree.tokens.items(.tag);
1075510864
......@@ -10792,7 +10901,7 @@ const IndexSlice = struct { index: u32, len: u32 };
1079210901fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {
1079310902 const gpa = astgen.gpa;
1079410903 const string_bytes = &astgen.string_bytes;
10795 const str_index = @intCast(u32, string_bytes.items.len);
10904 const str_index = @as(u32, @intCast(string_bytes.items.len));
1079610905 const token_bytes = astgen.tree.tokenSlice(str_lit_token);
1079710906 try astgen.parseStrLit(str_lit_token, string_bytes, token_bytes, 0);
1079810907 const key = string_bytes.items[str_index..];
......@@ -10805,7 +10914,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {
1080510914 string_bytes.shrinkRetainingCapacity(str_index);
1080610915 return IndexSlice{
1080710916 .index = gop.key_ptr.*,
10808 .len = @intCast(u32, key.len),
10917 .len = @as(u32, @intCast(key.len)),
1080910918 };
1081010919 } else {
1081110920 gop.key_ptr.* = str_index;
......@@ -10815,7 +10924,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {
1081510924 try string_bytes.append(gpa, 0);
1081610925 return IndexSlice{
1081710926 .index = str_index,
10818 .len = @intCast(u32, key.len),
10927 .len = @as(u32, @intCast(key.len)),
1081910928 };
1082010929 }
1082110930}
......@@ -10852,15 +10961,15 @@ fn strLitNodeAsString(astgen: *AstGen, node: Ast.Node.Index) !IndexSlice {
1085210961 const len = string_bytes.items.len - str_index;
1085310962 try string_bytes.append(gpa, 0);
1085410963 return IndexSlice{
10855 .index = @intCast(u32, str_index),
10856 .len = @intCast(u32, len),
10964 .index = @as(u32, @intCast(str_index)),
10965 .len = @as(u32, @intCast(len)),
1085710966 };
1085810967}
1085910968
1086010969fn testNameString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !u32 {
1086110970 const gpa = astgen.gpa;
1086210971 const string_bytes = &astgen.string_bytes;
10863 const str_index = @intCast(u32, string_bytes.items.len);
10972 const str_index = @as(u32, @intCast(string_bytes.items.len));
1086410973 const token_bytes = astgen.tree.tokenSlice(str_lit_token);
1086510974 try string_bytes.append(gpa, 0); // Indicates this is a test.
1086610975 try astgen.parseStrLit(str_lit_token, string_bytes, token_bytes, 0);
......@@ -11212,7 +11321,7 @@ const GenZir = struct {
1121211321 }
1121311322
1121411323 fn nodeIndexToRelative(gz: GenZir, node_index: Ast.Node.Index) i32 {
11215 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));
1121611325 }
1121711326
1121811327 fn tokenIndexToRelative(gz: GenZir, token: Ast.TokenIndex) u32 {
......@@ -11369,7 +11478,7 @@ const GenZir = struct {
1136911478 const astgen = gz.astgen;
1137011479 const gpa = astgen.gpa;
1137111480 const ret_ref = if (args.ret_ref == .void_type) .none else args.ret_ref;
11372 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);
11481 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
1137311482
1137411483 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
1137511484
......@@ -11387,8 +11496,8 @@ const GenZir = struct {
1138711496 const block = node_datas[fn_decl].rhs;
1138811497 const rbrace_start = token_starts[tree.lastToken(block)];
1138911498 astgen.advanceSourceCursor(rbrace_start);
11390 const rbrace_line = @intCast(u32, astgen.source_line - gz.decl_line);
11391 const rbrace_column = @intCast(u32, astgen.source_column);
11499 const rbrace_line = @as(u32, @intCast(astgen.source_line - gz.decl_line));
11500 const rbrace_column = @as(u32, @intCast(astgen.source_column));
1139211501
1139311502 const columns = args.lbrace_column | (rbrace_column << 16);
1139411503 src_locs_buffer[0] = args.lbrace_line;
......@@ -11624,18 +11733,18 @@ const GenZir = struct {
1162411733 astgen.extra.appendAssumeCapacity(@intFromEnum(args.init));
1162511734 }
1162611735
11627 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);
11736 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
1162811737 astgen.instructions.appendAssumeCapacity(.{
1162911738 .tag = .extended,
1163011739 .data = .{ .extended = .{
1163111740 .opcode = .variable,
11632 .small = @bitCast(u16, Zir.Inst.ExtendedVar.Small{
11741 .small = @as(u16, @bitCast(Zir.Inst.ExtendedVar.Small{
1163311742 .has_lib_name = args.lib_name != 0,
1163411743 .has_align = args.align_inst != .none,
1163511744 .has_init = args.init != .none,
1163611745 .is_extern = args.is_extern,
1163711746 .is_threadlocal = args.is_threadlocal,
11638 }),
11747 })),
1163911748 .operand = payload_index,
1164011749 } },
1164111750 });
......@@ -11655,7 +11764,7 @@ const GenZir = struct {
1165511764 try gz.instructions.ensureUnusedCapacity(gpa, 1);
1165611765 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1165711766
11658 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
11767 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
1165911768 gz.astgen.instructions.appendAssumeCapacity(.{
1166011769 .tag = tag,
1166111770 .data = .{ .bool_br = .{
......@@ -11681,12 +11790,12 @@ const GenZir = struct {
1168111790 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
1168211791 try astgen.string_bytes.ensureUnusedCapacity(gpa, @sizeOf(std.math.big.Limb) * limbs.len);
1168311792
11684 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);
11793 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
1168511794 astgen.instructions.appendAssumeCapacity(.{
1168611795 .tag = .int_big,
1168711796 .data = .{ .str = .{
11688 .start = @intCast(u32, astgen.string_bytes.items.len),
11689 .len = @intCast(u32, limbs.len),
11797 .start = @as(u32, @intCast(astgen.string_bytes.items.len)),
11798 .len = @as(u32, @intCast(limbs.len)),
1169011799 } },
1169111800 });
1169211801 gz.instructions.appendAssumeCapacity(new_index);
......@@ -11726,7 +11835,7 @@ const GenZir = struct {
1172611835 src_node: Ast.Node.Index,
1172711836 ) !Zir.Inst.Index {
1172811837 assert(operand != .none);
11729 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
11838 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
1173011839 try gz.astgen.instructions.append(gz.astgen.gpa, .{
1173111840 .tag = tag,
1173211841 .data = .{ .un_node = .{
......@@ -11749,7 +11858,7 @@ const GenZir = struct {
1174911858 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1175011859
1175111860 const payload_index = try gz.astgen.addExtra(extra);
11752 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
11861 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
1175311862 gz.astgen.instructions.appendAssumeCapacity(.{
1175411863 .tag = tag,
1175511864 .data = .{ .pl_node = .{
......@@ -11801,12 +11910,12 @@ const GenZir = struct {
1180111910 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{
1180211911 .name = name,
1180311912 .doc_comment = doc_comment_index,
11804 .body_len = @intCast(u32, body_len),
11913 .body_len = @as(u32, @intCast(body_len)),
1180511914 });
1180611915 gz.astgen.appendBodyWithFixups(param_body);
1180711916 param_gz.unstack();
1180811917
11809 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
11918 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
1181011919 gz.astgen.instructions.appendAssumeCapacity(.{
1181111920 .tag = tag,
1181211921 .data = .{ .pl_tok = .{
......@@ -11834,7 +11943,7 @@ const GenZir = struct {
1183411943 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1183511944
1183611945 const payload_index = try gz.astgen.addExtra(extra);
11837 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
11946 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
1183811947 gz.astgen.instructions.appendAssumeCapacity(.{
1183911948 .tag = .extended,
1184011949 .data = .{ .extended = .{
......@@ -11866,12 +11975,12 @@ const GenZir = struct {
1186611975 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.NodeMultiOp{
1186711976 .src_node = gz.nodeIndexToRelative(node),
1186811977 });
11869 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);
11978 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
1187011979 astgen.instructions.appendAssumeCapacity(.{
1187111980 .tag = .extended,
1187211981 .data = .{ .extended = .{
1187311982 .opcode = opcode,
11874 .small = @intCast(u16, operands.len),
11983 .small = @as(u16, @intCast(operands.len)),
1187511984 .operand = payload_index,
1187611985 } },
1187711986 });
......@@ -11891,12 +12000,12 @@ const GenZir = struct {
1189112000
1189212001 try gz.instructions.ensureUnusedCapacity(gpa, 1);
1189312002 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
11894 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);
12003 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
1189512004 astgen.instructions.appendAssumeCapacity(.{
1189612005 .tag = .extended,
1189712006 .data = .{ .extended = .{
1189812007 .opcode = opcode,
11899 .small = @intCast(u16, trailing_len),
12008 .small = @as(u16, @intCast(trailing_len)),
1190012009 .operand = payload_index,
1190112010 } },
1190212011 });
......@@ -11929,7 +12038,7 @@ const GenZir = struct {
1192912038 abs_tok_index: Ast.TokenIndex,
1193012039 ) !Zir.Inst.Index {
1193112040 const astgen = gz.astgen;
11932 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);
12041 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
1193312042 assert(operand != .none);
1193412043 try astgen.instructions.append(astgen.gpa, .{
1193512044 .tag = tag,
......@@ -12012,7 +12121,7 @@ const GenZir = struct {
1201212121 .operand_src_node = Zir.Inst.Break.no_src_node,
1201312122 };
1201412123 const payload_index = try gz.astgen.addExtra(extra);
12015 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
12124 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
1201612125 gz.astgen.instructions.appendAssumeCapacity(.{
1201712126 .tag = tag,
1201812127 .data = .{ .@"break" = .{
......@@ -12038,7 +12147,7 @@ const GenZir = struct {
1203812147 .operand_src_node = Zir.Inst.Break.no_src_node,
1203912148 };
1204012149 const payload_index = try gz.astgen.addExtra(extra);
12041 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
12150 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
1204212151 gz.astgen.instructions.appendAssumeCapacity(.{
1204312152 .tag = tag,
1204412153 .data = .{ .@"break" = .{
......@@ -12065,7 +12174,7 @@ const GenZir = struct {
1206512174 .operand_src_node = gz.nodeIndexToRelative(operand_src_node),
1206612175 };
1206712176 const payload_index = try gz.astgen.addExtra(extra);
12068 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
12177 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
1206912178 gz.astgen.instructions.appendAssumeCapacity(.{
1207012179 .tag = tag,
1207112180 .data = .{ .@"break" = .{
......@@ -12092,7 +12201,7 @@ const GenZir = struct {
1209212201 .operand_src_node = gz.nodeIndexToRelative(operand_src_node),
1209312202 };
1209412203 const payload_index = try gz.astgen.addExtra(extra);
12095 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
12204 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
1209612205 gz.astgen.instructions.appendAssumeCapacity(.{
1209712206 .tag = tag,
1209812207 .data = .{ .@"break" = .{
......@@ -12184,7 +12293,7 @@ const GenZir = struct {
1218412293 .data = .{ .extended = .{
1218512294 .opcode = opcode,
1218612295 .small = undefined,
12187 .operand = @bitCast(u32, gz.nodeIndexToRelative(src_node)),
12296 .operand = @as(u32, @bitCast(gz.nodeIndexToRelative(src_node))),
1218812297 } },
1218912298 });
1219012299 }
......@@ -12227,7 +12336,7 @@ const GenZir = struct {
1222712336 const is_comptime: u4 = @intFromBool(args.is_comptime);
1222812337 const small: u16 = has_type | (has_align << 1) | (is_const << 2) | (is_comptime << 3);
1222912338
12230 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);
12339 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
1223112340 astgen.instructions.appendAssumeCapacity(.{
1223212341 .tag = .extended,
1223312342 .data = .{ .extended = .{
......@@ -12281,12 +12390,12 @@ const GenZir = struct {
1228112390 // * 0b000000XX_XXX00000 - `inputs_len`.
1228212391 // * 0b0XXXXX00_00000000 - `clobbers_len`.
1228312392 // * 0bX0000000_00000000 - is volatile
12284 const small: u16 = @intCast(u16, args.outputs.len) |
12285 @intCast(u16, args.inputs.len << 5) |
12286 @intCast(u16, args.clobbers.len << 10) |
12393 const small: u16 = @as(u16, @intCast(args.outputs.len)) |
12394 @as(u16, @intCast(args.inputs.len << 5)) |
12395 @as(u16, @intCast(args.clobbers.len << 10)) |
1228712396 (@as(u16, @intFromBool(args.is_volatile)) << 15);
1228812397
12289 const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);
12398 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));
1229012399 astgen.instructions.appendAssumeCapacity(.{
1229112400 .tag = .extended,
1229212401 .data = .{ .extended = .{
......@@ -12303,7 +12412,7 @@ const GenZir = struct {
1230312412 /// Does *not* append the block instruction to the scope.
1230412413 /// Leaves the `payload_index` field undefined.
1230512414 fn makeBlockInst(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {
12306 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
12415 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
1230712416 const gpa = gz.astgen.gpa;
1230812417 try gz.astgen.instructions.append(gpa, .{
1230912418 .tag = tag,
......@@ -12320,7 +12429,7 @@ const GenZir = struct {
1232012429 fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {
1232112430 const gpa = gz.astgen.gpa;
1232212431 try gz.instructions.ensureUnusedCapacity(gpa, 1);
12323 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
12432 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
1232412433 try gz.astgen.instructions.append(gpa, .{
1232512434 .tag = tag,
1232612435 .data = .{ .pl_node = .{
......@@ -12347,11 +12456,11 @@ const GenZir = struct {
1234712456 const gpa = astgen.gpa;
1234812457
1234912458 try astgen.extra.ensureUnusedCapacity(gpa, 6);
12350 const payload_index = @intCast(u32, astgen.extra.items.len);
12459 const payload_index = @as(u32, @intCast(astgen.extra.items.len));
1235112460
1235212461 if (args.src_node != 0) {
1235312462 const node_offset = gz.nodeIndexToRelative(args.src_node);
12354 astgen.extra.appendAssumeCapacity(@bitCast(u32, node_offset));
12463 astgen.extra.appendAssumeCapacity(@as(u32, @bitCast(node_offset)));
1235512464 }
1235612465 if (args.fields_len != 0) {
1235712466 astgen.extra.appendAssumeCapacity(args.fields_len);
......@@ -12369,7 +12478,7 @@ const GenZir = struct {
1236912478 .tag = .extended,
1237012479 .data = .{ .extended = .{
1237112480 .opcode = .struct_decl,
12372 .small = @bitCast(u16, Zir.Inst.StructDecl.Small{
12481 .small = @as(u16, @bitCast(Zir.Inst.StructDecl.Small{
1237312482 .has_src_node = args.src_node != 0,
1237412483 .has_fields_len = args.fields_len != 0,
1237512484 .has_decls_len = args.decls_len != 0,
......@@ -12379,7 +12488,7 @@ const GenZir = struct {
1237912488 .is_tuple = args.is_tuple,
1238012489 .name_strategy = gz.anon_name_strategy,
1238112490 .layout = args.layout,
12382 }),
12491 })),
1238312492 .operand = payload_index,
1238412493 } },
1238512494 });
......@@ -12398,11 +12507,11 @@ const GenZir = struct {
1239812507 const gpa = astgen.gpa;
1239912508
1240012509 try astgen.extra.ensureUnusedCapacity(gpa, 5);
12401 const payload_index = @intCast(u32, astgen.extra.items.len);
12510 const payload_index = @as(u32, @intCast(astgen.extra.items.len));
1240212511
1240312512 if (args.src_node != 0) {
1240412513 const node_offset = gz.nodeIndexToRelative(args.src_node);
12405 astgen.extra.appendAssumeCapacity(@bitCast(u32, node_offset));
12514 astgen.extra.appendAssumeCapacity(@as(u32, @bitCast(node_offset)));
1240612515 }
1240712516 if (args.tag_type != .none) {
1240812517 astgen.extra.appendAssumeCapacity(@intFromEnum(args.tag_type));
......@@ -12420,7 +12529,7 @@ const GenZir = struct {
1242012529 .tag = .extended,
1242112530 .data = .{ .extended = .{
1242212531 .opcode = .union_decl,
12423 .small = @bitCast(u16, Zir.Inst.UnionDecl.Small{
12532 .small = @as(u16, @bitCast(Zir.Inst.UnionDecl.Small{
1242412533 .has_src_node = args.src_node != 0,
1242512534 .has_tag_type = args.tag_type != .none,
1242612535 .has_body_len = args.body_len != 0,
......@@ -12429,7 +12538,7 @@ const GenZir = struct {
1242912538 .name_strategy = gz.anon_name_strategy,
1243012539 .layout = args.layout,
1243112540 .auto_enum_tag = args.auto_enum_tag,
12432 }),
12541 })),
1243312542 .operand = payload_index,
1243412543 } },
1243512544 });
......@@ -12447,11 +12556,11 @@ const GenZir = struct {
1244712556 const gpa = astgen.gpa;
1244812557
1244912558 try astgen.extra.ensureUnusedCapacity(gpa, 5);
12450 const payload_index = @intCast(u32, astgen.extra.items.len);
12559 const payload_index = @as(u32, @intCast(astgen.extra.items.len));
1245112560
1245212561 if (args.src_node != 0) {
1245312562 const node_offset = gz.nodeIndexToRelative(args.src_node);
12454 astgen.extra.appendAssumeCapacity(@bitCast(u32, node_offset));
12563 astgen.extra.appendAssumeCapacity(@as(u32, @bitCast(node_offset)));
1245512564 }
1245612565 if (args.tag_type != .none) {
1245712566 astgen.extra.appendAssumeCapacity(@intFromEnum(args.tag_type));
......@@ -12469,7 +12578,7 @@ const GenZir = struct {
1246912578 .tag = .extended,
1247012579 .data = .{ .extended = .{
1247112580 .opcode = .enum_decl,
12472 .small = @bitCast(u16, Zir.Inst.EnumDecl.Small{
12581 .small = @as(u16, @bitCast(Zir.Inst.EnumDecl.Small{
1247312582 .has_src_node = args.src_node != 0,
1247412583 .has_tag_type = args.tag_type != .none,
1247512584 .has_body_len = args.body_len != 0,
......@@ -12477,7 +12586,7 @@ const GenZir = struct {
1247712586 .has_decls_len = args.decls_len != 0,
1247812587 .name_strategy = gz.anon_name_strategy,
1247912588 .nonexhaustive = args.nonexhaustive,
12480 }),
12589 })),
1248112590 .operand = payload_index,
1248212591 } },
1248312592 });
......@@ -12491,11 +12600,11 @@ const GenZir = struct {
1249112600 const gpa = astgen.gpa;
1249212601
1249312602 try astgen.extra.ensureUnusedCapacity(gpa, 2);
12494 const payload_index = @intCast(u32, astgen.extra.items.len);
12603 const payload_index = @as(u32, @intCast(astgen.extra.items.len));
1249512604
1249612605 if (args.src_node != 0) {
1249712606 const node_offset = gz.nodeIndexToRelative(args.src_node);
12498 astgen.extra.appendAssumeCapacity(@bitCast(u32, node_offset));
12607 astgen.extra.appendAssumeCapacity(@as(u32, @bitCast(node_offset)));
1249912608 }
1250012609 if (args.decls_len != 0) {
1250112610 astgen.extra.appendAssumeCapacity(args.decls_len);
......@@ -12504,11 +12613,11 @@ const GenZir = struct {
1250412613 .tag = .extended,
1250512614 .data = .{ .extended = .{
1250612615 .opcode = .opaque_decl,
12507 .small = @bitCast(u16, Zir.Inst.OpaqueDecl.Small{
12616 .small = @as(u16, @bitCast(Zir.Inst.OpaqueDecl.Small{
1250812617 .has_src_node = args.src_node != 0,
1250912618 .has_decls_len = args.decls_len != 0,
1251012619 .name_strategy = gz.anon_name_strategy,
12511 }),
12620 })),
1251212621 .operand = payload_index,
1251312622 } },
1251412623 });
......@@ -12523,7 +12632,7 @@ const GenZir = struct {
1252312632 try gz.instructions.ensureUnusedCapacity(gpa, 1);
1252412633 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1252512634
12526 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
12635 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
1252712636 gz.astgen.instructions.appendAssumeCapacity(inst);
1252812637 gz.instructions.appendAssumeCapacity(new_index);
1252912638 return new_index;
......@@ -12534,7 +12643,7 @@ const GenZir = struct {
1253412643 try gz.instructions.ensureUnusedCapacity(gpa, 1);
1253512644 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1253612645
12537 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
12646 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
1253812647 gz.astgen.instructions.len += 1;
1253912648 gz.instructions.appendAssumeCapacity(new_index);
1254012649 return new_index;
......@@ -12586,7 +12695,7 @@ const GenZir = struct {
1258612695 return;
1258712696 }
1258812697
12589 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
12698 const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len));
1259012699 try gz.astgen.instructions.append(gpa, .{ .tag = .dbg_block_end, .data = undefined });
1259112700 try gz.instructions.append(gpa, new_index);
1259212701 }
......@@ -12595,7 +12704,7 @@ const GenZir = struct {
1259512704/// This can only be for short-lived references; the memory becomes invalidated
1259612705/// when another string is added.
1259712706fn nullTerminatedString(astgen: AstGen, index: usize) [*:0]const u8 {
12598 return @ptrCast([*:0]const u8, astgen.string_bytes.items.ptr) + index;
12707 return @as([*:0]const u8, @ptrCast(astgen.string_bytes.items.ptr)) + index;
1259912708}
1260012709
1260112710/// Local variables shadowing detection, including function parameters.
......@@ -12874,7 +12983,7 @@ fn isInferred(astgen: *AstGen, ref: Zir.Inst.Ref) bool {
1287412983 .extended => {
1287512984 const zir_data = astgen.instructions.items(.data);
1287612985 if (zir_data[inst].extended.opcode != .alloc) return false;
12877 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));
1287812987 return !small.has_type;
1287912988 },
1288012989
......@@ -12918,7 +13027,7 @@ fn countBodyLenAfterFixups(astgen: *AstGen, body: []const Zir.Inst.Index) u32 {
1291813027 check_inst = ref_inst;
1291913028 }
1292013029 }
12921 return @intCast(u32, count);
13030 return @as(u32, @intCast(count));
1292213031}
1292313032
1292413033fn emitDbgStmt(gz: *GenZir, lc: LineColumn) !void {
......@@ -12950,7 +13059,7 @@ fn lowerAstErrors(astgen: *AstGen) !void {
1295013059
1295113060 if (token_tags[parse_err.token + @intFromBool(parse_err.token_is_prev)] == .invalid) {
1295213061 const tok = parse_err.token + @intFromBool(parse_err.token_is_prev);
12953 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));
1295413063 const byte_abs = token_starts[parse_err.token + @intFromBool(parse_err.token_is_prev)] + bad_off;
1295513064 try notes.append(gpa, try astgen.errNoteTokOff(tok, bad_off, "invalid byte: '{'}'", .{
1295613065 std.zig.fmtEscapes(tree.source[byte_abs..][0..1]),
src/Autodoc.zig+49-52
......@@ -110,7 +110,7 @@ pub fn generateZirData(self: *Autodoc) !void {
110110 comptime std.debug.assert(@intFromEnum(InternPool.Index.first_type) == 0);
111111 var i: u32 = 0;
112112 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));
114114 var tmpbuf = std.ArrayList(u8).init(self.arena);
115115 if (ip_index == .generic_poison_type) {
116116 // Not a real type, doesn't have a normal name
......@@ -1529,7 +1529,6 @@ fn walkInstruction(
15291529 .int_cast,
15301530 .ptr_cast,
15311531 .truncate,
1532 .align_cast,
15331532 .has_decl,
15341533 .has_field,
15351534 .div_exact,
......@@ -1670,7 +1669,7 @@ fn walkInstruction(
16701669 // present in json
16711670 var sentinel: ?DocData.Expr = null;
16721671 if (ptr.flags.has_sentinel) {
1673 const ref = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);
1672 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
16741673 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);
16751674 sentinel = ref_result.expr;
16761675 extra_index += 1;
......@@ -1678,21 +1677,21 @@ fn walkInstruction(
16781677
16791678 var @"align": ?DocData.Expr = null;
16801679 if (ptr.flags.has_align) {
1681 const ref = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);
1680 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
16821681 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);
16831682 @"align" = ref_result.expr;
16841683 extra_index += 1;
16851684 }
16861685 var address_space: ?DocData.Expr = null;
16871686 if (ptr.flags.has_addrspace) {
1688 const ref = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);
1687 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
16891688 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);
16901689 address_space = ref_result.expr;
16911690 extra_index += 1;
16921691 }
16931692 var bit_start: ?DocData.Expr = null;
16941693 if (ptr.flags.has_bit_range) {
1695 const ref = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);
1694 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
16961695 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);
16971696 address_space = ref_result.expr;
16981697 extra_index += 1;
......@@ -1700,7 +1699,7 @@ fn walkInstruction(
17001699
17011700 var host_size: ?DocData.Expr = null;
17021701 if (ptr.flags.has_bit_range) {
1703 const ref = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);
1702 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
17041703 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);
17051704 host_size = ref_result.expr;
17061705 }
......@@ -2550,11 +2549,11 @@ fn walkInstruction(
25502549 .enclosing_type = type_slot_index,
25512550 };
25522551
2553 const small = @bitCast(Zir.Inst.OpaqueDecl.Small, extended.small);
2552 const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small));
25542553 var extra_index: usize = extended.operand;
25552554
25562555 const src_node: ?i32 = if (small.has_src_node) blk: {
2557 const src_node = @bitCast(i32, file.zir.extra[extra_index]);
2556 const src_node = @as(i32, @bitCast(file.zir.extra[extra_index]));
25582557 extra_index += 1;
25592558 break :blk src_node;
25602559 } else null;
......@@ -2607,7 +2606,7 @@ fn walkInstruction(
26072606 .variable => {
26082607 const extra = file.zir.extraData(Zir.Inst.ExtendedVar, extended.operand);
26092608
2610 const small = @bitCast(Zir.Inst.ExtendedVar.Small, extended.small);
2609 const small = @as(Zir.Inst.ExtendedVar.Small, @bitCast(extended.small));
26112610 var extra_index: usize = extra.end;
26122611 if (small.has_lib_name) extra_index += 1;
26132612 if (small.has_align) extra_index += 1;
......@@ -2620,7 +2619,7 @@ fn walkInstruction(
26202619 };
26212620
26222621 if (small.has_init) {
2623 const var_init_ref = @enumFromInt(Ref, file.zir.extra[extra_index]);
2622 const var_init_ref = @as(Ref, @enumFromInt(file.zir.extra[extra_index]));
26242623 const var_init = try self.walkRef(file, parent_scope, parent_src, var_init_ref, need_type);
26252624 value.expr = var_init.expr;
26262625 value.typeRef = var_init.typeRef;
......@@ -2637,11 +2636,11 @@ fn walkInstruction(
26372636 .enclosing_type = type_slot_index,
26382637 };
26392638
2640 const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small);
2639 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));
26412640 var extra_index: usize = extended.operand;
26422641
26432642 const src_node: ?i32 = if (small.has_src_node) blk: {
2644 const src_node = @bitCast(i32, file.zir.extra[extra_index]);
2643 const src_node = @as(i32, @bitCast(file.zir.extra[extra_index]));
26452644 extra_index += 1;
26462645 break :blk src_node;
26472646 } else null;
......@@ -2656,7 +2655,7 @@ fn walkInstruction(
26562655 const tag_type_ref: ?Ref = if (small.has_tag_type) blk: {
26572656 const tag_type = file.zir.extra[extra_index];
26582657 extra_index += 1;
2659 const tag_ref = @enumFromInt(Ref, tag_type);
2658 const tag_ref = @as(Ref, @enumFromInt(tag_type));
26602659 break :blk tag_ref;
26612660 } else null;
26622661
......@@ -2764,11 +2763,11 @@ fn walkInstruction(
27642763 .enclosing_type = type_slot_index,
27652764 };
27662765
2767 const small = @bitCast(Zir.Inst.EnumDecl.Small, extended.small);
2766 const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small));
27682767 var extra_index: usize = extended.operand;
27692768
27702769 const src_node: ?i32 = if (small.has_src_node) blk: {
2771 const src_node = @bitCast(i32, file.zir.extra[extra_index]);
2770 const src_node = @as(i32, @bitCast(file.zir.extra[extra_index]));
27722771 extra_index += 1;
27732772 break :blk src_node;
27742773 } else null;
......@@ -2781,7 +2780,7 @@ fn walkInstruction(
27812780 const tag_type: ?DocData.Expr = if (small.has_tag_type) blk: {
27822781 const tag_type = file.zir.extra[extra_index];
27832782 extra_index += 1;
2784 const tag_ref = @enumFromInt(Ref, tag_type);
2783 const tag_ref = @as(Ref, @enumFromInt(tag_type));
27852784 const wr = try self.walkRef(file, parent_scope, parent_src, tag_ref, false);
27862785 break :blk wr.expr;
27872786 } else null;
......@@ -2827,7 +2826,7 @@ fn walkInstruction(
28272826 bit_bag_idx += 1;
28282827 }
28292828
2830 const has_value = @truncate(u1, cur_bit_bag) != 0;
2829 const has_value = @as(u1, @truncate(cur_bit_bag)) != 0;
28312830 cur_bit_bag >>= 1;
28322831
28332832 const field_name_index = file.zir.extra[extra_index];
......@@ -2839,7 +2838,7 @@ fn walkInstruction(
28392838 const value_expr: ?DocData.Expr = if (has_value) blk: {
28402839 const value_ref = file.zir.extra[extra_index];
28412840 extra_index += 1;
2842 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);
28432842 break :blk value.expr;
28442843 } else null;
28452844 try field_values.append(self.arena, value_expr);
......@@ -2900,11 +2899,11 @@ fn walkInstruction(
29002899 .enclosing_type = type_slot_index,
29012900 };
29022901
2903 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
2902 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
29042903 var extra_index: usize = extended.operand;
29052904
29062905 const src_node: ?i32 = if (small.has_src_node) blk: {
2907 const src_node = @bitCast(i32, file.zir.extra[extra_index]);
2906 const src_node = @as(i32, @bitCast(file.zir.extra[extra_index]));
29082907 extra_index += 1;
29092908 break :blk src_node;
29102909 } else null;
......@@ -2928,7 +2927,7 @@ fn walkInstruction(
29282927 const backing_int_body_len = file.zir.extra[extra_index];
29292928 extra_index += 1; // backing_int_body_len
29302929 if (backing_int_body_len == 0) {
2931 const backing_int_ref = @enumFromInt(Ref, file.zir.extra[extra_index]);
2930 const backing_int_ref = @as(Ref, @enumFromInt(file.zir.extra[extra_index]));
29322931 const backing_int_res = try self.walkRef(file, &scope, src_info, backing_int_ref, true);
29332932 backing_int = backing_int_res.expr;
29342933 extra_index += 1; // backing_int_ref
......@@ -3024,8 +3023,6 @@ fn walkInstruction(
30243023 .int_from_error,
30253024 .error_from_int,
30263025 .reify,
3027 .const_cast,
3028 .volatile_cast,
30293026 => {
30303027 const extra = file.zir.extraData(Zir.Inst.UnNode, extended.operand).data;
30313028 const bin_index = self.exprs.items.len;
......@@ -3157,7 +3154,7 @@ fn analyzeAllDecls(
31573154 priv_decl_indexes: *std.ArrayListUnmanaged(usize),
31583155) AutodocErrors!usize {
31593156 const first_decl_indexes_slot = decl_indexes.items.len;
3160 const original_it = file.zir.declIterator(@intCast(u32, parent_inst_index));
3157 const original_it = file.zir.declIterator(@as(u32, @intCast(parent_inst_index)));
31613158
31623159 // First loop to discover decl names
31633160 {
......@@ -3183,7 +3180,7 @@ fn analyzeAllDecls(
31833180 const decl_name_index = file.zir.extra[d.sub_index + 5];
31843181 switch (decl_name_index) {
31853182 0 => {
3186 const is_exported = @truncate(u1, d.flags >> 1);
3183 const is_exported = @as(u1, @truncate(d.flags >> 1));
31873184 switch (is_exported) {
31883185 0 => continue, // comptime decl
31893186 1 => {
......@@ -3258,10 +3255,10 @@ fn analyzeDecl(
32583255 d: Zir.DeclIterator.Item,
32593256) AutodocErrors!void {
32603257 const data = file.zir.instructions.items(.data);
3261 const is_pub = @truncate(u1, d.flags >> 0) != 0;
3258 const is_pub = @as(u1, @truncate(d.flags >> 0)) != 0;
32623259 // const is_exported = @truncate(u1, d.flags >> 1) != 0;
3263 const has_align = @truncate(u1, d.flags >> 2) != 0;
3264 const has_section_or_addrspace = @truncate(u1, d.flags >> 3) != 0;
3260 const has_align = @as(u1, @truncate(d.flags >> 2)) != 0;
3261 const has_section_or_addrspace = @as(u1, @truncate(d.flags >> 3)) != 0;
32653262
32663263 var extra_index = d.sub_index;
32673264 // const hash_u32s = file.zir.extra[extra_index..][0..4];
......@@ -3280,21 +3277,21 @@ fn analyzeDecl(
32803277
32813278 extra_index += 1;
32823279 const align_inst: Zir.Inst.Ref = if (!has_align) .none else inst: {
3283 const inst = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);
3280 const inst = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
32843281 extra_index += 1;
32853282 break :inst inst;
32863283 };
32873284 _ = align_inst;
32883285
32893286 const section_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: {
3290 const inst = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);
3287 const inst = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
32913288 extra_index += 1;
32923289 break :inst inst;
32933290 };
32943291 _ = section_inst;
32953292
32963293 const addrspace_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: {
3297 const inst = @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index]);
3294 const inst = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
32983295 extra_index += 1;
32993296 break :inst inst;
33003297 };
......@@ -3384,7 +3381,7 @@ fn analyzeUsingnamespaceDecl(
33843381) AutodocErrors!void {
33853382 const data = file.zir.instructions.items(.data);
33863383
3387 const is_pub = @truncate(u1, d.flags) != 0;
3384 const is_pub = @as(u1, @truncate(d.flags)) != 0;
33883385 const value_index = file.zir.extra[d.sub_index + 6];
33893386 const doc_comment_index = file.zir.extra[d.sub_index + 7];
33903387
......@@ -4031,7 +4028,7 @@ fn analyzeFancyFunction(
40314028) AutodocErrors!DocData.WalkResult {
40324029 const tags = file.zir.instructions.items(.tag);
40334030 const data = file.zir.instructions.items(.data);
4034 const fn_info = file.zir.getFnInfo(@intCast(u32, inst_index));
4031 const fn_info = file.zir.getFnInfo(@as(u32, @intCast(inst_index)));
40354032
40364033 try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len);
40374034 var param_type_refs = try std.ArrayListUnmanaged(DocData.Expr).initCapacity(
......@@ -4111,7 +4108,7 @@ fn analyzeFancyFunction(
41114108
41124109 var align_index: ?usize = null;
41134110 if (extra.data.bits.has_align_ref) {
4114 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]));
41154112 align_index = self.exprs.items.len;
41164113 _ = try self.walkRef(file, scope, parent_src, align_ref, false);
41174114 extra_index += 1;
......@@ -4128,7 +4125,7 @@ fn analyzeFancyFunction(
41284125
41294126 var addrspace_index: ?usize = null;
41304127 if (extra.data.bits.has_addrspace_ref) {
4131 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]));
41324129 addrspace_index = self.exprs.items.len;
41334130 _ = try self.walkRef(file, scope, parent_src, addrspace_ref, false);
41344131 extra_index += 1;
......@@ -4145,7 +4142,7 @@ fn analyzeFancyFunction(
41454142
41464143 var section_index: ?usize = null;
41474144 if (extra.data.bits.has_section_ref) {
4148 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]));
41494146 section_index = self.exprs.items.len;
41504147 _ = try self.walkRef(file, scope, parent_src, section_ref, false);
41514148 extra_index += 1;
......@@ -4162,7 +4159,7 @@ fn analyzeFancyFunction(
41624159
41634160 var cc_index: ?usize = null;
41644161 if (extra.data.bits.has_cc_ref and !extra.data.bits.has_cc_body) {
4165 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]));
41664163 const cc_expr = try self.walkRef(file, scope, parent_src, cc_ref, false);
41674164
41684165 cc_index = self.exprs.items.len;
......@@ -4265,7 +4262,7 @@ fn analyzeFunction(
42654262) AutodocErrors!DocData.WalkResult {
42664263 const tags = file.zir.instructions.items(.tag);
42674264 const data = file.zir.instructions.items(.data);
4268 const fn_info = file.zir.getFnInfo(@intCast(u32, inst_index));
4265 const fn_info = file.zir.getFnInfo(@as(u32, @intCast(inst_index)));
42694266
42704267 try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len);
42714268 var param_type_refs = try std.ArrayListUnmanaged(DocData.Expr).initCapacity(
......@@ -4452,13 +4449,13 @@ fn collectUnionFieldInfo(
44524449 cur_bit_bag = file.zir.extra[bit_bag_index];
44534450 bit_bag_index += 1;
44544451 }
4455 const has_type = @truncate(u1, cur_bit_bag) != 0;
4452 const has_type = @as(u1, @truncate(cur_bit_bag)) != 0;
44564453 cur_bit_bag >>= 1;
4457 const has_align = @truncate(u1, cur_bit_bag) != 0;
4454 const has_align = @as(u1, @truncate(cur_bit_bag)) != 0;
44584455 cur_bit_bag >>= 1;
4459 const has_tag = @truncate(u1, cur_bit_bag) != 0;
4456 const has_tag = @as(u1, @truncate(cur_bit_bag)) != 0;
44604457 cur_bit_bag >>= 1;
4461 const unused = @truncate(u1, cur_bit_bag) != 0;
4458 const unused = @as(u1, @truncate(cur_bit_bag)) != 0;
44624459 cur_bit_bag >>= 1;
44634460 _ = unused;
44644461
......@@ -4467,7 +4464,7 @@ fn collectUnionFieldInfo(
44674464 const doc_comment_index = file.zir.extra[extra_index];
44684465 extra_index += 1;
44694466 const field_type = if (has_type)
4470 @enumFromInt(Zir.Inst.Ref, file.zir.extra[extra_index])
4467 @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]))
44714468 else
44724469 .void_type;
44734470 if (has_type) extra_index += 1;
......@@ -4535,13 +4532,13 @@ fn collectStructFieldInfo(
45354532 cur_bit_bag = file.zir.extra[bit_bag_index];
45364533 bit_bag_index += 1;
45374534 }
4538 const has_align = @truncate(u1, cur_bit_bag) != 0;
4535 const has_align = @as(u1, @truncate(cur_bit_bag)) != 0;
45394536 cur_bit_bag >>= 1;
4540 const has_default = @truncate(u1, cur_bit_bag) != 0;
4537 const has_default = @as(u1, @truncate(cur_bit_bag)) != 0;
45414538 cur_bit_bag >>= 1;
45424539 // const is_comptime = @truncate(u1, cur_bit_bag) != 0;
45434540 cur_bit_bag >>= 1;
4544 const has_type_body = @truncate(u1, cur_bit_bag) != 0;
4541 const has_type_body = @as(u1, @truncate(cur_bit_bag)) != 0;
45454542 cur_bit_bag >>= 1;
45464543
45474544 const field_name: ?u32 = if (!is_tuple) blk: {
......@@ -4561,7 +4558,7 @@ fn collectStructFieldInfo(
45614558 if (has_type_body) {
45624559 fields[field_i].type_body_len = file.zir.extra[extra_index];
45634560 } else {
4564 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]));
45654562 }
45664563 extra_index += 1;
45674564
......@@ -4858,9 +4855,9 @@ fn srcLocInfo(
48584855 src_node: i32,
48594856 parent_src: SrcLocInfo,
48604857) !SrcLocInfo {
4861 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));
48624859 const tree = try file.getTree(self.comp_module.gpa);
4863 const node_idx = @bitCast(Ast.Node.Index, sn);
4860 const node_idx = @as(Ast.Node.Index, @bitCast(sn));
48644861 const tokens = tree.nodes.items(.main_token);
48654862
48664863 const tok_idx = tokens[node_idx];
......@@ -4879,9 +4876,9 @@ fn declIsVar(
48794876 src_node: i32,
48804877 parent_src: SrcLocInfo,
48814878) !bool {
4882 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));
48834880 const tree = try file.getTree(self.comp_module.gpa);
4884 const node_idx = @bitCast(Ast.Node.Index, sn);
4881 const node_idx = @as(Ast.Node.Index, @bitCast(sn));
48854882 const tokens = tree.nodes.items(.main_token);
48864883 const tags = tree.tokens.items(.tag);
48874884
src/BuiltinFn.zig+15-13
......@@ -129,6 +129,8 @@ pub const MemLocRequirement = enum {
129129 never,
130130 /// The builtin always needs a memory location.
131131 always,
132 /// The builtin forwards the question to argument at index 0.
133 forward0,
132134 /// The builtin forwards the question to argument at index 1.
133135 forward1,
134136};
......@@ -168,14 +170,14 @@ pub const list = list: {
168170 "@addrSpaceCast",
169171 .{
170172 .tag = .addrspace_cast,
171 .param_count = 2,
173 .param_count = 1,
172174 },
173175 },
174176 .{
175177 "@alignCast",
176178 .{
177179 .tag = .align_cast,
178 .param_count = 2,
180 .param_count = 1,
179181 },
180182 },
181183 .{
......@@ -226,8 +228,8 @@ pub const list = list: {
226228 "@bitCast",
227229 .{
228230 .tag = .bit_cast,
229 .needs_mem_loc = .forward1,
230 .param_count = 2,
231 .needs_mem_loc = .forward0,
232 .param_count = 1,
231233 },
232234 },
233235 .{
......@@ -457,7 +459,7 @@ pub const list = list: {
457459 .{
458460 .tag = .err_set_cast,
459461 .eval_to_error = .always,
460 .param_count = 2,
462 .param_count = 1,
461463 },
462464 },
463465 .{
......@@ -502,14 +504,14 @@ pub const list = list: {
502504 "@floatCast",
503505 .{
504506 .tag = .float_cast,
505 .param_count = 2,
507 .param_count = 1,
506508 },
507509 },
508510 .{
509511 "@intFromFloat",
510512 .{
511513 .tag = .int_from_float,
512 .param_count = 2,
514 .param_count = 1,
513515 },
514516 },
515517 .{
......@@ -572,14 +574,14 @@ pub const list = list: {
572574 "@intCast",
573575 .{
574576 .tag = .int_cast,
575 .param_count = 2,
577 .param_count = 1,
576578 },
577579 },
578580 .{
579581 "@enumFromInt",
580582 .{
581583 .tag = .enum_from_int,
582 .param_count = 2,
584 .param_count = 1,
583585 },
584586 },
585587 .{
......@@ -594,14 +596,14 @@ pub const list = list: {
594596 "@floatFromInt",
595597 .{
596598 .tag = .float_from_int,
597 .param_count = 2,
599 .param_count = 1,
598600 },
599601 },
600602 .{
601603 "@ptrFromInt",
602604 .{
603605 .tag = .ptr_from_int,
604 .param_count = 2,
606 .param_count = 1,
605607 },
606608 },
607609 .{
......@@ -685,7 +687,7 @@ pub const list = list: {
685687 "@ptrCast",
686688 .{
687689 .tag = .ptr_cast,
688 .param_count = 2,
690 .param_count = 1,
689691 },
690692 },
691693 .{
......@@ -938,7 +940,7 @@ pub const list = list: {
938940 "@truncate",
939941 .{
940942 .tag = .truncate,
941 .param_count = 2,
943 .param_count = 1,
942944 },
943945 },
944946 .{
src/Compilation.zig+20-20
......@@ -1046,7 +1046,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
10461046 const llvm_cpu_features: ?[*:0]const u8 = if (build_options.have_llvm and use_llvm) blk: {
10471047 var buf = std.ArrayList(u8).init(arena);
10481048 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));
10501050 const is_enabled = options.target.cpu.features.isEnabled(index);
10511051
10521052 if (feature.llvm_name) |llvm_name| {
......@@ -2562,7 +2562,7 @@ pub fn totalErrorCount(self: *Compilation) u32 {
25622562 }
25632563 }
25642564
2565 return @intCast(u32, total);
2565 return @as(u32, @intCast(total));
25662566}
25672567
25682568/// This function is temporally single-threaded.
......@@ -2596,7 +2596,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {
25962596 }
25972597
25982598 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
26012601 try bundle.addRootErrorMessage(.{
26022602 .msg = try bundle.addString(lld_error.msg),
......@@ -2753,7 +2753,7 @@ pub const ErrorNoteHashContext = struct {
27532753 std.hash.autoHash(&hasher, src.span_main);
27542754 }
27552755
2756 return @truncate(u32, hasher.final());
2756 return @as(u32, @truncate(hasher.final()));
27572757 }
27582758
27592759 pub fn eql(
......@@ -2830,8 +2830,8 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod
28302830 .span_start = span.start,
28312831 .span_main = span.main,
28322832 .span_end = span.end,
2833 .line = @intCast(u32, loc.line),
2834 .column = @intCast(u32, loc.column),
2833 .line = @as(u32, @intCast(loc.line)),
2834 .column = @as(u32, @intCast(loc.column)),
28352835 .source_line = 0,
28362836 }),
28372837 });
......@@ -2842,13 +2842,13 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod
28422842 .span_start = err_span.start,
28432843 .span_main = err_span.main,
28442844 .span_end = err_span.end,
2845 .line = @intCast(u32, err_loc.line),
2846 .column = @intCast(u32, err_loc.column),
2845 .line = @as(u32, @intCast(err_loc.line)),
2846 .column = @as(u32, @intCast(err_loc.column)),
28472847 .source_line = if (module_err_msg.src_loc.lazy == .entire_file)
28482848 0
28492849 else
28502850 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)),
28522852 });
28532853
28542854 for (ref_traces.items) |rt| {
......@@ -2874,8 +2874,8 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod
28742874 .span_start = span.start,
28752875 .span_main = span.main,
28762876 .span_end = span.end,
2877 .line = @intCast(u32, loc.line),
2878 .column = @intCast(u32, loc.column),
2877 .line = @as(u32, @intCast(loc.line)),
2878 .column = @as(u32, @intCast(loc.column)),
28792879 .source_line = if (err_loc.eql(loc)) 0 else try eb.addString(loc.source_line),
28802880 }),
28812881 }, .{ .eb = eb });
......@@ -2884,7 +2884,7 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod
28842884 }
28852885 }
28862886
2887 const notes_len = @intCast(u32, notes.entries.len);
2887 const notes_len = @as(u32, @intCast(notes.entries.len));
28882888
28892889 try eb.addRootErrorMessage(.{
28902890 .msg = try eb.addString(module_err_msg.msg),
......@@ -2919,7 +2919,7 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void {
29192919 }
29202920 const token_starts = file.tree.tokens.items(.start);
29212921 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;
29232923 break :blk Module.SrcLoc.Span{ .start = start, .end = end, .main = start };
29242924 };
29252925 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 {
29352935 .span_start = err_span.start,
29362936 .span_main = err_span.main,
29372937 .span_end = err_span.end,
2938 .line = @intCast(u32, err_loc.line),
2939 .column = @intCast(u32, err_loc.column),
2938 .line = @as(u32, @intCast(err_loc.line)),
2939 .column = @as(u32, @intCast(err_loc.column)),
29402940 .source_line = try eb.addString(err_loc.source_line),
29412941 }),
29422942 .notes_len = item.data.notesLen(file.zir),
......@@ -2956,7 +2956,7 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void {
29562956 }
29572957 const token_starts = file.tree.tokens.items(.start);
29582958 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;
29602960 break :blk Module.SrcLoc.Span{ .start = start, .end = end, .main = start };
29612961 };
29622962 const loc = std.zig.findLineColumn(file.source, span.main);
......@@ -2970,8 +2970,8 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void {
29702970 .span_start = span.start,
29712971 .span_main = span.main,
29722972 .span_end = span.end,
2973 .line = @intCast(u32, loc.line),
2974 .column = @intCast(u32, loc.column),
2973 .line = @as(u32, @intCast(loc.line)),
2974 .column = @as(u32, @intCast(loc.column)),
29752975 .source_line = if (loc.eql(err_loc))
29762976 0
29772977 else
......@@ -4302,7 +4302,7 @@ pub fn addCCArgs(
43024302 const all_features_list = target.cpu.arch.allFeaturesList();
43034303 try argv.ensureUnusedCapacity(all_features_list.len * 4);
43044304 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));
43064306 const is_enabled = target.cpu.features.isEnabled(index);
43074307
43084308 if (feature.llvm_name) |llvm_name| {
......@@ -5172,7 +5172,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca
51725172 });
51735173
51745174 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));
51765176 const is_enabled = target.cpu.features.isEnabled(index);
51775177 if (is_enabled) {
51785178 try buffer.writer().print(" .{},\n", .{std.zig.fmtId(feature.name)});
src/InternPool.zig+205-205
......@@ -80,7 +80,7 @@ const KeyAdapter = struct {
8080
8181 pub fn eql(ctx: @This(), a: Key, b_void: void, b_map_index: usize) bool {
8282 _ = 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);
8484 }
8585
8686 pub fn hash(ctx: @This(), a: Key) u32 {
......@@ -95,7 +95,7 @@ pub const OptionalMapIndex = enum(u32) {
9595
9696 pub fn unwrap(oi: OptionalMapIndex) ?MapIndex {
9797 if (oi == .none) return null;
98 return @enumFromInt(MapIndex, @intFromEnum(oi));
98 return @as(MapIndex, @enumFromInt(@intFromEnum(oi)));
9999 }
100100};
101101
......@@ -104,7 +104,7 @@ pub const MapIndex = enum(u32) {
104104 _,
105105
106106 pub fn toOptional(i: MapIndex) OptionalMapIndex {
107 return @enumFromInt(OptionalMapIndex, @intFromEnum(i));
107 return @as(OptionalMapIndex, @enumFromInt(@intFromEnum(i)));
108108 }
109109};
110110
......@@ -114,7 +114,7 @@ pub const RuntimeIndex = enum(u32) {
114114 _,
115115
116116 pub fn increment(ri: *RuntimeIndex) void {
117 ri.* = @enumFromInt(RuntimeIndex, @intFromEnum(ri.*) + 1);
117 ri.* = @as(RuntimeIndex, @enumFromInt(@intFromEnum(ri.*) + 1));
118118 }
119119};
120120
......@@ -130,11 +130,11 @@ pub const NullTerminatedString = enum(u32) {
130130 _,
131131
132132 pub fn toString(self: NullTerminatedString) String {
133 return @enumFromInt(String, @intFromEnum(self));
133 return @as(String, @enumFromInt(@intFromEnum(self)));
134134 }
135135
136136 pub fn toOptional(self: NullTerminatedString) OptionalNullTerminatedString {
137 return @enumFromInt(OptionalNullTerminatedString, @intFromEnum(self));
137 return @as(OptionalNullTerminatedString, @enumFromInt(@intFromEnum(self)));
138138 }
139139
140140 const Adapter = struct {
......@@ -196,7 +196,7 @@ pub const OptionalNullTerminatedString = enum(u32) {
196196
197197 pub fn unwrap(oi: OptionalNullTerminatedString) ?NullTerminatedString {
198198 if (oi == .none) return null;
199 return @enumFromInt(NullTerminatedString, @intFromEnum(oi));
199 return @as(NullTerminatedString, @enumFromInt(@intFromEnum(oi)));
200200 }
201201};
202202
......@@ -282,7 +282,7 @@ pub const Key = union(enum) {
282282 const map = &ip.maps.items[@intFromEnum(self.names_map.unwrap().?)];
283283 const adapter: NullTerminatedString.Adapter = .{ .strings = self.names };
284284 const field_index = map.getIndexAdapted(name, adapter) orelse return null;
285 return @intCast(u32, field_index);
285 return @as(u32, @intCast(field_index));
286286 }
287287 };
288288
......@@ -420,7 +420,7 @@ pub const Key = union(enum) {
420420 const map = &ip.maps.items[@intFromEnum(self.names_map.unwrap().?)];
421421 const adapter: NullTerminatedString.Adapter = .{ .strings = self.names };
422422 const field_index = map.getIndexAdapted(name, adapter) orelse return null;
423 return @intCast(u32, field_index);
423 return @as(u32, @intCast(field_index));
424424 }
425425
426426 /// Look up field index based on tag value.
......@@ -440,7 +440,7 @@ pub const Key = union(enum) {
440440 const map = &ip.maps.items[@intFromEnum(values_map)];
441441 const adapter: Index.Adapter = .{ .indexes = self.values };
442442 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));
444444 }
445445 // Auto-numbered enum. Convert `int_tag_val` to field index.
446446 const field_index = switch (ip.indexToKey(int_tag_val).int.storage) {
......@@ -511,12 +511,12 @@ pub const Key = union(enum) {
511511
512512 pub fn paramIsComptime(self: @This(), i: u5) bool {
513513 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;
515515 }
516516
517517 pub fn paramIsNoalias(self: @This(), i: u5) bool {
518518 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;
520520 }
521521 };
522522
......@@ -685,7 +685,7 @@ pub const Key = union(enum) {
685685 };
686686
687687 pub fn hash32(key: Key, ip: *const InternPool) u32 {
688 return @truncate(u32, key.hash64(ip));
688 return @as(u32, @truncate(key.hash64(ip)));
689689 }
690690
691691 pub fn hash64(key: Key, ip: *const InternPool) u64 {
......@@ -767,7 +767,7 @@ pub const Key = union(enum) {
767767 switch (float.storage) {
768768 inline else => |val| std.hash.autoHash(
769769 &hasher,
770 @bitCast(std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(val))), val),
770 @as(std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(val))), @bitCast(val)),
771771 ),
772772 }
773773 return hasher.final();
......@@ -812,18 +812,18 @@ pub const Key = union(enum) {
812812
813813 if (child == .u8_type) {
814814 switch (aggregate.storage) {
815 .bytes => |bytes| for (bytes[0..@intCast(usize, len)]) |byte| {
815 .bytes => |bytes| for (bytes[0..@as(usize, @intCast(len))]) |byte| {
816816 std.hash.autoHash(&hasher, KeyTag.int);
817817 std.hash.autoHash(&hasher, byte);
818818 },
819 .elems => |elems| for (elems[0..@intCast(usize, len)]) |elem| {
819 .elems => |elems| for (elems[0..@as(usize, @intCast(len))]) |elem| {
820820 const elem_key = ip.indexToKey(elem);
821821 std.hash.autoHash(&hasher, @as(KeyTag, elem_key));
822822 switch (elem_key) {
823823 .undef => {},
824824 .int => |int| std.hash.autoHash(
825825 &hasher,
826 @intCast(u8, int.storage.u64),
826 @as(u8, @intCast(int.storage.u64)),
827827 ),
828828 else => unreachable,
829829 }
......@@ -837,7 +837,7 @@ pub const Key = union(enum) {
837837 .undef => {},
838838 .int => |int| std.hash.autoHash(
839839 &hasher,
840 @intCast(u8, int.storage.u64),
840 @as(u8, @intCast(int.storage.u64)),
841841 ),
842842 else => unreachable,
843843 }
......@@ -849,7 +849,7 @@ pub const Key = union(enum) {
849849
850850 switch (aggregate.storage) {
851851 .bytes => unreachable,
852 .elems => |elems| for (elems[0..@intCast(usize, len)]) |elem|
852 .elems => |elems| for (elems[0..@as(usize, @intCast(len))]) |elem|
853853 std.hash.autoHash(&hasher, elem),
854854 .repeated_elem => |elem| {
855855 var remaining = len;
......@@ -1061,10 +1061,10 @@ pub const Key = union(enum) {
10611061 // These are strange: we'll sometimes represent them as f128, even if the
10621062 // underlying type is smaller. f80 is an exception: see float_c_longdouble_f80.
10631063 const a_val = switch (a_info.storage) {
1064 inline else => |val| @floatCast(f128, val),
1064 inline else => |val| @as(f128, @floatCast(val)),
10651065 };
10661066 const b_val = switch (b_info.storage) {
1067 inline else => |val| @floatCast(f128, val),
1067 inline else => |val| @as(f128, @floatCast(val)),
10681068 };
10691069 return a_val == b_val;
10701070 }
......@@ -1092,7 +1092,7 @@ pub const Key = union(enum) {
10921092 const len = ip.aggregateTypeLen(a_info.ty);
10931093 const StorageTag = @typeInfo(Key.Aggregate.Storage).Union.tag_type.?;
10941094 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| {
10961096 const a_elem = switch (a_info.storage) {
10971097 .bytes => |bytes| ip.getIfExists(.{ .int = .{
10981098 .ty = .u8_type,
......@@ -1119,16 +1119,16 @@ pub const Key = union(enum) {
11191119 const b_bytes = b_info.storage.bytes;
11201120 return std.mem.eql(
11211121 u8,
1122 a_bytes[0..@intCast(usize, len)],
1123 b_bytes[0..@intCast(usize, len)],
1122 a_bytes[0..@as(usize, @intCast(len))],
1123 b_bytes[0..@as(usize, @intCast(len))],
11241124 );
11251125 },
11261126 .elems => |a_elems| {
11271127 const b_elems = b_info.storage.elems;
11281128 return std.mem.eql(
11291129 Index,
1130 a_elems[0..@intCast(usize, len)],
1131 b_elems[0..@intCast(usize, len)],
1130 a_elems[0..@as(usize, @intCast(len))],
1131 b_elems[0..@as(usize, @intCast(len))],
11321132 );
11331133 },
11341134 .repeated_elem => |a_elem| {
......@@ -2291,7 +2291,7 @@ pub const Alignment = enum(u6) {
22912291 pub fn fromByteUnits(n: u64) Alignment {
22922292 if (n == 0) return .none;
22932293 assert(std.math.isPowerOfTwo(n));
2294 return @enumFromInt(Alignment, @ctz(n));
2294 return @as(Alignment, @enumFromInt(@ctz(n)));
22952295 }
22962296
22972297 pub fn fromNonzeroByteUnits(n: u64) Alignment {
......@@ -2368,11 +2368,11 @@ pub const PackedU64 = packed struct(u64) {
23682368 b: u32,
23692369
23702370 pub fn get(x: PackedU64) u64 {
2371 return @bitCast(u64, x);
2371 return @as(u64, @bitCast(x));
23722372 }
23732373
23742374 pub fn init(x: u64) PackedU64 {
2375 return @bitCast(PackedU64, x);
2375 return @as(PackedU64, @bitCast(x));
23762376 }
23772377};
23782378
......@@ -2435,14 +2435,14 @@ pub const Float64 = struct {
24352435
24362436 pub fn get(self: Float64) f64 {
24372437 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));
24392439 }
24402440
24412441 fn pack(val: f64) Float64 {
2442 const bits = @bitCast(u64, val);
2442 const bits = @as(u64, @bitCast(val));
24432443 return .{
2444 .piece0 = @truncate(u32, bits),
2445 .piece1 = @truncate(u32, bits >> 32),
2444 .piece0 = @as(u32, @truncate(bits)),
2445 .piece1 = @as(u32, @truncate(bits >> 32)),
24462446 };
24472447 }
24482448};
......@@ -2457,15 +2457,15 @@ pub const Float80 = struct {
24572457 const int_bits = @as(u80, self.piece0) |
24582458 (@as(u80, self.piece1) << 32) |
24592459 (@as(u80, self.piece2) << 64);
2460 return @bitCast(f80, int_bits);
2460 return @as(f80, @bitCast(int_bits));
24612461 }
24622462
24632463 fn pack(val: f80) Float80 {
2464 const bits = @bitCast(u80, val);
2464 const bits = @as(u80, @bitCast(val));
24652465 return .{
2466 .piece0 = @truncate(u32, bits),
2467 .piece1 = @truncate(u32, bits >> 32),
2468 .piece2 = @truncate(u16, bits >> 64),
2466 .piece0 = @as(u32, @truncate(bits)),
2467 .piece1 = @as(u32, @truncate(bits >> 32)),
2468 .piece2 = @as(u16, @truncate(bits >> 64)),
24692469 };
24702470 }
24712471};
......@@ -2482,16 +2482,16 @@ pub const Float128 = struct {
24822482 (@as(u128, self.piece1) << 32) |
24832483 (@as(u128, self.piece2) << 64) |
24842484 (@as(u128, self.piece3) << 96);
2485 return @bitCast(f128, int_bits);
2485 return @as(f128, @bitCast(int_bits));
24862486 }
24872487
24882488 fn pack(val: f128) Float128 {
2489 const bits = @bitCast(u128, val);
2489 const bits = @as(u128, @bitCast(val));
24902490 return .{
2491 .piece0 = @truncate(u32, bits),
2492 .piece1 = @truncate(u32, bits >> 32),
2493 .piece2 = @truncate(u32, bits >> 64),
2494 .piece3 = @truncate(u32, bits >> 96),
2491 .piece0 = @as(u32, @truncate(bits)),
2492 .piece1 = @as(u32, @truncate(bits >> 32)),
2493 .piece2 = @as(u32, @truncate(bits >> 64)),
2494 .piece3 = @as(u32, @truncate(bits >> 96)),
24952495 };
24962496 }
24972497};
......@@ -2575,13 +2575,13 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
25752575 .type_int_signed => .{
25762576 .int_type = .{
25772577 .signedness = .signed,
2578 .bits = @intCast(u16, data),
2578 .bits = @as(u16, @intCast(data)),
25792579 },
25802580 },
25812581 .type_int_unsigned => .{
25822582 .int_type = .{
25832583 .signedness = .unsigned,
2584 .bits = @intCast(u16, data),
2584 .bits = @as(u16, @intCast(data)),
25852585 },
25862586 },
25872587 .type_array_big => {
......@@ -2600,8 +2600,8 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
26002600 .sentinel = .none,
26012601 } };
26022602 },
2603 .simple_type => .{ .simple_type = @enumFromInt(SimpleType, data) },
2604 .simple_value => .{ .simple_value = @enumFromInt(SimpleValue, data) },
2603 .simple_type => .{ .simple_type = @as(SimpleType, @enumFromInt(data)) },
2604 .simple_value => .{ .simple_value = @as(SimpleValue, @enumFromInt(data)) },
26052605
26062606 .type_vector => {
26072607 const vector_info = ip.extraData(Vector, data);
......@@ -2620,8 +2620,8 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
26202620 return .{ .ptr_type = ptr_info };
26212621 },
26222622
2623 .type_optional => .{ .opt_type = @enumFromInt(Index, data) },
2624 .type_anyframe => .{ .anyframe_type = @enumFromInt(Index, data) },
2623 .type_optional => .{ .opt_type = @as(Index, @enumFromInt(data)) },
2624 .type_anyframe => .{ .anyframe_type = @as(Index, @enumFromInt(data)) },
26252625
26262626 .type_error_union => .{ .error_union_type = ip.extraData(Key.ErrorUnionType, data) },
26272627 .type_error_set => {
......@@ -2629,17 +2629,17 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
26292629 const names_len = error_set.data.names_len;
26302630 const names = ip.extra.items[error_set.end..][0..names_len];
26312631 return .{ .error_set_type = .{
2632 .names = @ptrCast([]const NullTerminatedString, names),
2632 .names = @as([]const NullTerminatedString, @ptrCast(names)),
26332633 .names_map = error_set.data.names_map.toOptional(),
26342634 } };
26352635 },
26362636 .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)),
26382638 },
26392639
26402640 .type_opaque => .{ .opaque_type = ip.extraData(Key.OpaqueType, data) },
26412641 .type_struct => {
2642 const struct_index = @enumFromInt(Module.Struct.OptionalIndex, data);
2642 const struct_index = @as(Module.Struct.OptionalIndex, @enumFromInt(data));
26432643 const namespace = if (struct_index.unwrap()) |i|
26442644 ip.structPtrConst(i).namespace.toOptional()
26452645 else
......@@ -2651,7 +2651,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
26512651 },
26522652 .type_struct_ns => .{ .struct_type = .{
26532653 .index = .none,
2654 .namespace = @enumFromInt(Module.Namespace.Index, data).toOptional(),
2654 .namespace = @as(Module.Namespace.Index, @enumFromInt(data)).toOptional(),
26552655 } },
26562656
26572657 .type_struct_anon => {
......@@ -2661,9 +2661,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
26612661 const values = ip.extra.items[type_struct_anon.end + fields_len ..][0..fields_len];
26622662 const names = ip.extra.items[type_struct_anon.end + 2 * fields_len ..][0..fields_len];
26632663 return .{ .anon_struct_type = .{
2664 .types = @ptrCast([]const Index, types),
2665 .values = @ptrCast([]const Index, values),
2666 .names = @ptrCast([]const NullTerminatedString, names),
2664 .types = @as([]const Index, @ptrCast(types)),
2665 .values = @as([]const Index, @ptrCast(values)),
2666 .names = @as([]const NullTerminatedString, @ptrCast(names)),
26672667 } };
26682668 },
26692669 .type_tuple_anon => {
......@@ -2672,30 +2672,30 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
26722672 const types = ip.extra.items[type_struct_anon.end..][0..fields_len];
26732673 const values = ip.extra.items[type_struct_anon.end + fields_len ..][0..fields_len];
26742674 return .{ .anon_struct_type = .{
2675 .types = @ptrCast([]const Index, types),
2676 .values = @ptrCast([]const Index, values),
2675 .types = @as([]const Index, @ptrCast(types)),
2676 .values = @as([]const Index, @ptrCast(values)),
26772677 .names = &.{},
26782678 } };
26792679 },
26802680
26812681 .type_union_untagged => .{ .union_type = .{
2682 .index = @enumFromInt(Module.Union.Index, data),
2682 .index = @as(Module.Union.Index, @enumFromInt(data)),
26832683 .runtime_tag = .none,
26842684 } },
26852685 .type_union_tagged => .{ .union_type = .{
2686 .index = @enumFromInt(Module.Union.Index, data),
2686 .index = @as(Module.Union.Index, @enumFromInt(data)),
26872687 .runtime_tag = .tagged,
26882688 } },
26892689 .type_union_safety => .{ .union_type = .{
2690 .index = @enumFromInt(Module.Union.Index, data),
2690 .index = @as(Module.Union.Index, @enumFromInt(data)),
26912691 .runtime_tag = .safety,
26922692 } },
26932693
26942694 .type_enum_auto => {
26952695 const enum_auto = ip.extraDataTrail(EnumAuto, data);
2696 const names = @ptrCast(
2696 const names = @as(
26972697 []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]),
26992699 );
27002700 return .{ .enum_type = .{
27012701 .decl = enum_auto.data.decl,
......@@ -2712,10 +2712,10 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
27122712 .type_enum_nonexhaustive => ip.indexToKeyEnum(data, .nonexhaustive),
27132713 .type_function => .{ .func_type = ip.indexToKeyFuncType(data) },
27142714
2715 .undef => .{ .undef = @enumFromInt(Index, data) },
2715 .undef => .{ .undef = @as(Index, @enumFromInt(data)) },
27162716 .runtime_value => .{ .runtime_value = ip.extraData(Tag.TypeValue, data) },
27172717 .opt_null => .{ .opt = .{
2718 .ty = @enumFromInt(Index, data),
2718 .ty = @as(Index, @enumFromInt(data)),
27192719 .val = .none,
27202720 } },
27212721 .opt_payload => {
......@@ -2877,7 +2877,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
28772877 } },
28782878 .int_i32 => .{ .int = .{
28792879 .ty = .i32_type,
2880 .storage = .{ .i64 = @bitCast(i32, data) },
2880 .storage = .{ .i64 = @as(i32, @bitCast(data)) },
28812881 } },
28822882 .int_usize => .{ .int = .{
28832883 .ty = .usize_type,
......@@ -2889,7 +2889,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
28892889 } },
28902890 .int_comptime_int_i32 => .{ .int = .{
28912891 .ty = .comptime_int_type,
2892 .storage = .{ .i64 = @bitCast(i32, data) },
2892 .storage = .{ .i64 = @as(i32, @bitCast(data)) },
28932893 } },
28942894 .int_positive => ip.indexToKeyBigInt(data, true),
28952895 .int_negative => ip.indexToKeyBigInt(data, false),
......@@ -2913,11 +2913,11 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
29132913 },
29142914 .float_f16 => .{ .float = .{
29152915 .ty = .f16_type,
2916 .storage = .{ .f16 = @bitCast(f16, @intCast(u16, data)) },
2916 .storage = .{ .f16 = @as(f16, @bitCast(@as(u16, @intCast(data)))) },
29172917 } },
29182918 .float_f32 => .{ .float = .{
29192919 .ty = .f32_type,
2920 .storage = .{ .f32 = @bitCast(f32, data) },
2920 .storage = .{ .f32 = @as(f32, @bitCast(data)) },
29212921 } },
29222922 .float_f64 => .{ .float = .{
29232923 .ty = .f64_type,
......@@ -2959,13 +2959,13 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
29592959 .extern_func => .{ .extern_func = ip.extraData(Tag.ExternFunc, data) },
29602960 .func => .{ .func = ip.extraData(Tag.Func, data) },
29612961 .only_possible_value => {
2962 const ty = @enumFromInt(Index, data);
2962 const ty = @as(Index, @enumFromInt(data));
29632963 const ty_item = ip.items.get(@intFromEnum(ty));
29642964 return switch (ty_item.tag) {
29652965 .type_array_big => {
2966 const sentinel = @ptrCast(
2966 const sentinel = @as(
29672967 *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").?]),
29692969 );
29702970 return .{ .aggregate = .{
29712971 .ty = ty,
......@@ -2994,7 +2994,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
29942994 const values = ip.extra.items[type_struct_anon.end + fields_len ..][0..fields_len];
29952995 return .{ .aggregate = .{
29962996 .ty = ty,
2997 .storage = .{ .elems = @ptrCast([]const Index, values) },
2997 .storage = .{ .elems = @as([]const Index, @ptrCast(values)) },
29982998 } };
29992999 },
30003000
......@@ -3010,7 +3010,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
30103010 },
30113011 .bytes => {
30123012 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)));
30143014 return .{ .aggregate = .{
30153015 .ty = extra.ty,
30163016 .storage = .{ .bytes = ip.string_bytes.items[@intFromEnum(extra.bytes)..][0..len] },
......@@ -3018,8 +3018,8 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
30183018 },
30193019 .aggregate => {
30203020 const extra = ip.extraDataTrail(Tag.Aggregate, data);
3021 const len = @intCast(u32, ip.aggregateTypeLenIncludingSentinel(extra.data.ty));
3022 const fields = @ptrCast([]const Index, ip.extra.items[extra.end..][0..len]);
3021 const len = @as(u32, @intCast(ip.aggregateTypeLenIncludingSentinel(extra.data.ty)));
3022 const fields = @as([]const Index, @ptrCast(ip.extra.items[extra.end..][0..len]));
30233023 return .{ .aggregate = .{
30243024 .ty = extra.data.ty,
30253025 .storage = .{ .elems = fields },
......@@ -3048,14 +3048,14 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
30483048 .val = .{ .payload = extra.val },
30493049 } };
30503050 },
3051 .enum_literal => .{ .enum_literal = @enumFromInt(NullTerminatedString, data) },
3051 .enum_literal => .{ .enum_literal = @as(NullTerminatedString, @enumFromInt(data)) },
30523052 .enum_tag => .{ .enum_tag = ip.extraData(Tag.EnumTag, data) },
30533053
30543054 .memoized_call => {
30553055 const extra = ip.extraDataTrail(MemoizedCall, data);
30563056 return .{ .memoized_call = .{
30573057 .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])),
30593059 .result = extra.data.result,
30603060 } };
30613061 },
......@@ -3064,9 +3064,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
30643064
30653065fn indexToKeyFuncType(ip: *const InternPool, data: u32) Key.FuncType {
30663066 const type_function = ip.extraDataTrail(TypeFunction, data);
3067 const param_types = @ptrCast(
3067 const param_types = @as(
30683068 []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]),
30703070 );
30713071 return .{
30723072 .param_types = param_types,
......@@ -3087,13 +3087,13 @@ fn indexToKeyFuncType(ip: *const InternPool, data: u32) Key.FuncType {
30873087
30883088fn indexToKeyEnum(ip: *const InternPool, data: u32, tag_mode: Key.EnumType.TagMode) Key {
30893089 const enum_explicit = ip.extraDataTrail(EnumExplicit, data);
3090 const names = @ptrCast(
3090 const names = @as(
30913091 []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]),
30933093 );
3094 const values = if (enum_explicit.data.values_map != .none) @ptrCast(
3094 const values = if (enum_explicit.data.values_map != .none) @as(
30953095 []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]),
30973097 ) else &[0]Index{};
30983098
30993099 return .{ .enum_type = .{
......@@ -3122,7 +3122,7 @@ fn indexToKeyBigInt(ip: *const InternPool, limb_index: u32, positive: bool) Key
31223122pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
31233123 const adapter: KeyAdapter = .{ .intern_pool = ip };
31243124 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));
31263126 try ip.items.ensureUnusedCapacity(gpa, 1);
31273127 switch (key) {
31283128 .int_type => |int_type| {
......@@ -3150,7 +3150,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
31503150 .tag = .type_slice,
31513151 .data = @intFromEnum(ptr_type_index),
31523152 });
3153 return @enumFromInt(Index, ip.items.len - 1);
3153 return @as(Index, @enumFromInt(ip.items.len - 1));
31543154 }
31553155
31563156 var ptr_type_adjusted = ptr_type;
......@@ -3174,7 +3174,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
31743174 .child = array_type.child,
31753175 }),
31763176 });
3177 return @enumFromInt(Index, ip.items.len - 1);
3177 return @as(Index, @enumFromInt(ip.items.len - 1));
31783178 }
31793179 }
31803180
......@@ -3223,7 +3223,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
32233223 assert(std.sort.isSorted(NullTerminatedString, error_set_type.names, {}, NullTerminatedString.indexLessThan));
32243224 const names_map = try ip.addMap(gpa);
32253225 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));
32273227 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(ErrorSet).Struct.fields.len + names_len);
32283228 ip.items.appendAssumeCapacity(.{
32293229 .tag = .type_error_set,
......@@ -3232,7 +3232,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
32323232 .names_map = names_map,
32333233 }),
32343234 });
3235 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, error_set_type.names));
3235 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(error_set_type.names)));
32363236 },
32373237 .inferred_error_set_type => |ies_index| {
32383238 ip.items.appendAssumeCapacity(.{
......@@ -3284,7 +3284,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
32843284 assert(anon_struct_type.types.len == anon_struct_type.values.len);
32853285 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));
32883288 if (anon_struct_type.names.len == 0) {
32893289 try ip.extra.ensureUnusedCapacity(
32903290 gpa,
......@@ -3296,9 +3296,9 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
32963296 .fields_len = fields_len,
32973297 }),
32983298 });
3299 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, anon_struct_type.types));
3300 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, anon_struct_type.values));
3301 return @enumFromInt(Index, ip.items.len - 1);
3299 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(anon_struct_type.types)));
3300 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(anon_struct_type.values)));
3301 return @as(Index, @enumFromInt(ip.items.len - 1));
33023302 }
33033303
33043304 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 {
33133313 .fields_len = fields_len,
33143314 }),
33153315 });
3316 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, anon_struct_type.types));
3317 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, anon_struct_type.values));
3318 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, anon_struct_type.names));
3319 return @enumFromInt(Index, ip.items.len - 1);
3316 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(anon_struct_type.types)));
3317 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(anon_struct_type.values)));
3318 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(anon_struct_type.names)));
3319 return @as(Index, @enumFromInt(ip.items.len - 1));
33203320 },
33213321
33223322 .union_type => |union_type| {
......@@ -3348,7 +3348,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
33483348 const names_map = try ip.addMap(gpa);
33493349 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));
33523352 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(EnumAuto).Struct.fields.len +
33533353 fields_len);
33543354 ip.items.appendAssumeCapacity(.{
......@@ -3361,8 +3361,8 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
33613361 .fields_len = fields_len,
33623362 }),
33633363 });
3364 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, enum_type.names));
3365 return @enumFromInt(Index, ip.items.len - 1);
3364 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(enum_type.names)));
3365 return @as(Index, @enumFromInt(ip.items.len - 1));
33663366 },
33673367 .explicit => return finishGetEnum(ip, gpa, enum_type, .type_enum_explicit),
33683368 .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 {
33733373 assert(func_type.return_type != .none);
33743374 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
33783378 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(TypeFunction).Struct.fields.len +
33793379 params_len);
......@@ -3397,7 +3397,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
33973397 },
33983398 }),
33993399 });
3400 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, func_type.param_types));
3400 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(func_type.param_types)));
34013401 },
34023402
34033403 .variable => |variable| {
......@@ -3559,7 +3559,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
35593559 });
35603560 },
35613561 }
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);
35633563 },
35643564
35653565 .opt => |opt| {
......@@ -3593,7 +3593,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
35933593 .lazy_ty = lazy_ty,
35943594 }),
35953595 });
3596 return @enumFromInt(Index, ip.items.len - 1);
3596 return @as(Index, @enumFromInt(ip.items.len - 1));
35973597 },
35983598 }
35993599 switch (int.ty) {
......@@ -3608,7 +3608,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
36083608 inline .u64, .i64 => |x| {
36093609 ip.items.appendAssumeCapacity(.{
36103610 .tag = .int_u8,
3611 .data = @intCast(u8, x),
3611 .data = @as(u8, @intCast(x)),
36123612 });
36133613 break :b;
36143614 },
......@@ -3625,7 +3625,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
36253625 inline .u64, .i64 => |x| {
36263626 ip.items.appendAssumeCapacity(.{
36273627 .tag = .int_u16,
3628 .data = @intCast(u16, x),
3628 .data = @as(u16, @intCast(x)),
36293629 });
36303630 break :b;
36313631 },
......@@ -3642,7 +3642,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
36423642 inline .u64, .i64 => |x| {
36433643 ip.items.appendAssumeCapacity(.{
36443644 .tag = .int_u32,
3645 .data = @intCast(u32, x),
3645 .data = @as(u32, @intCast(x)),
36463646 });
36473647 break :b;
36483648 },
......@@ -3653,14 +3653,14 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
36533653 const casted = big_int.to(i32) catch unreachable;
36543654 ip.items.appendAssumeCapacity(.{
36553655 .tag = .int_i32,
3656 .data = @bitCast(u32, casted),
3656 .data = @as(u32, @bitCast(casted)),
36573657 });
36583658 break :b;
36593659 },
36603660 inline .u64, .i64 => |x| {
36613661 ip.items.appendAssumeCapacity(.{
36623662 .tag = .int_i32,
3663 .data = @bitCast(u32, @intCast(i32, x)),
3663 .data = @as(u32, @bitCast(@as(i32, @intCast(x)))),
36643664 });
36653665 break :b;
36663666 },
......@@ -3699,7 +3699,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
36993699 if (big_int.to(i32)) |casted| {
37003700 ip.items.appendAssumeCapacity(.{
37013701 .tag = .int_comptime_int_i32,
3702 .data = @bitCast(u32, casted),
3702 .data = @as(u32, @bitCast(casted)),
37033703 });
37043704 break :b;
37053705 } else |_| {}
......@@ -3715,7 +3715,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
37153715 if (std.math.cast(i32, x)) |casted| {
37163716 ip.items.appendAssumeCapacity(.{
37173717 .tag = .int_comptime_int_i32,
3718 .data = @bitCast(u32, casted),
3718 .data = @as(u32, @bitCast(casted)),
37193719 });
37203720 break :b;
37213721 }
......@@ -3734,7 +3734,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
37343734 .value = casted,
37353735 }),
37363736 });
3737 return @enumFromInt(Index, ip.items.len - 1);
3737 return @as(Index, @enumFromInt(ip.items.len - 1));
37383738 } else |_| {}
37393739
37403740 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 {
37493749 .value = casted,
37503750 }),
37513751 });
3752 return @enumFromInt(Index, ip.items.len - 1);
3752 return @as(Index, @enumFromInt(ip.items.len - 1));
37533753 }
37543754
37553755 var buf: [2]Limb = undefined;
......@@ -3816,11 +3816,11 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
38163816 switch (float.ty) {
38173817 .f16_type => ip.items.appendAssumeCapacity(.{
38183818 .tag = .float_f16,
3819 .data = @bitCast(u16, float.storage.f16),
3819 .data = @as(u16, @bitCast(float.storage.f16)),
38203820 }),
38213821 .f32_type => ip.items.appendAssumeCapacity(.{
38223822 .tag = .float_f32,
3823 .data = @bitCast(u32, float.storage.f32),
3823 .data = @as(u32, @bitCast(float.storage.f32)),
38243824 }),
38253825 .f64_type => ip.items.appendAssumeCapacity(.{
38263826 .tag = .float_f64,
......@@ -3872,13 +3872,13 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
38723872 assert(child == .u8_type);
38733873 if (bytes.len != len) {
38743874 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);
38763876 }
38773877 },
38783878 .elems => |elems| {
38793879 if (elems.len != len) {
38803880 assert(elems.len == len_including_sentinel);
3881 assert(elems[@intCast(usize, len)] == sentinel);
3881 assert(elems[@as(usize, @intCast(len))] == sentinel);
38823882 }
38833883 },
38843884 .repeated_elem => |elem| {
......@@ -3912,7 +3912,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
39123912 .tag = .only_possible_value,
39133913 .data = @intFromEnum(aggregate.ty),
39143914 });
3915 return @enumFromInt(Index, ip.items.len - 1);
3915 return @as(Index, @enumFromInt(ip.items.len - 1));
39163916 }
39173917
39183918 switch (ty_key) {
......@@ -3940,16 +3940,16 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
39403940 .tag = .only_possible_value,
39413941 .data = @intFromEnum(aggregate.ty),
39423942 });
3943 return @enumFromInt(Index, ip.items.len - 1);
3943 return @as(Index, @enumFromInt(ip.items.len - 1));
39443944 },
39453945 else => {},
39463946 }
39473947
39483948 repeated: {
39493949 switch (aggregate.storage) {
3950 .bytes => |bytes| for (bytes[1..@intCast(usize, len)]) |byte|
3950 .bytes => |bytes| for (bytes[1..@as(usize, @intCast(len))]) |byte|
39513951 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|
39533953 if (elem != elems[0]) break :repeated,
39543954 .repeated_elem => {},
39553955 }
......@@ -3979,12 +3979,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
39793979 .elem_val = elem,
39803980 }),
39813981 });
3982 return @enumFromInt(Index, ip.items.len - 1);
3982 return @as(Index, @enumFromInt(ip.items.len - 1));
39833983 }
39843984
39853985 if (child == .u8_type) bytes: {
39863986 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)));
39883988 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Bytes).Struct.fields.len);
39893989 switch (aggregate.storage) {
39903990 .bytes => |bytes| ip.string_bytes.appendSliceAssumeCapacity(bytes),
......@@ -3994,15 +3994,15 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
39943994 break :bytes;
39953995 },
39963996 .int => |int| ip.string_bytes.appendAssumeCapacity(
3997 @intCast(u8, int.storage.u64),
3997 @as(u8, @intCast(int.storage.u64)),
39983998 ),
39993999 else => unreachable,
40004000 },
40014001 .repeated_elem => |elem| switch (ip.indexToKey(elem)) {
40024002 .undef => break :bytes,
40034003 .int => |int| @memset(
4004 ip.string_bytes.addManyAsSliceAssumeCapacity(@intCast(usize, len)),
4005 @intCast(u8, int.storage.u64),
4004 ip.string_bytes.addManyAsSliceAssumeCapacity(@as(usize, @intCast(len))),
4005 @as(u8, @intCast(int.storage.u64)),
40064006 ),
40074007 else => unreachable,
40084008 },
......@@ -4010,12 +4010,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
40104010 const has_internal_null =
40114011 std.mem.indexOfScalar(u8, ip.string_bytes.items[string_bytes_index..], 0) != null;
40124012 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)),
40144014 );
40154015 const string = if (has_internal_null)
4016 @enumFromInt(String, string_bytes_index)
4016 @as(String, @enumFromInt(string_bytes_index))
40174017 else
4018 (try ip.getOrPutTrailingString(gpa, @intCast(usize, len_including_sentinel))).toString();
4018 (try ip.getOrPutTrailingString(gpa, @as(usize, @intCast(len_including_sentinel)))).toString();
40194019 ip.items.appendAssumeCapacity(.{
40204020 .tag = .bytes,
40214021 .data = ip.addExtraAssumeCapacity(Bytes{
......@@ -4023,12 +4023,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
40234023 .bytes = string,
40244024 }),
40254025 });
4026 return @enumFromInt(Index, ip.items.len - 1);
4026 return @as(Index, @enumFromInt(ip.items.len - 1));
40274027 }
40284028
40294029 try ip.extra.ensureUnusedCapacity(
40304030 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)),
40324032 );
40334033 ip.items.appendAssumeCapacity(.{
40344034 .tag = .aggregate,
......@@ -4036,7 +4036,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
40364036 .ty = aggregate.ty,
40374037 }),
40384038 });
4039 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, aggregate.storage.elems));
4039 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(aggregate.storage.elems)));
40404040 if (sentinel != .none) ip.extra.appendAssumeCapacity(@intFromEnum(sentinel));
40414041 },
40424042
......@@ -4058,14 +4058,14 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
40584058 .tag = .memoized_call,
40594059 .data = ip.addExtraAssumeCapacity(MemoizedCall{
40604060 .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)),
40624062 .result = memoized_call.result,
40634063 }),
40644064 });
4065 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, memoized_call.arg_values));
4065 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(memoized_call.arg_values)));
40664066 },
40674067 }
4068 return @enumFromInt(Index, ip.items.len - 1);
4068 return @as(Index, @enumFromInt(ip.items.len - 1));
40694069}
40704070
40714071/// Provides API for completing an enum type after calling `getIncompleteEnum`.
......@@ -4093,10 +4093,10 @@ pub const IncompleteEnumType = struct {
40934093 const field_index = map.count();
40944094 const strings = ip.extra.items[self.names_start..][0..field_index];
40954095 const adapter: NullTerminatedString.Adapter = .{
4096 .strings = @ptrCast([]const NullTerminatedString, strings),
4096 .strings = @as([]const NullTerminatedString, @ptrCast(strings)),
40974097 };
40984098 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));
41004100 ip.extra.items[self.names_start + field_index] = @intFromEnum(name);
41014101 return null;
41024102 }
......@@ -4109,15 +4109,15 @@ pub const IncompleteEnumType = struct {
41094109 gpa: Allocator,
41104110 value: Index,
41114111 ) 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])));
41134113 const map = &ip.maps.items[@intFromEnum(self.values_map.unwrap().?)];
41144114 const field_index = map.count();
41154115 const indexes = ip.extra.items[self.values_start..][0..field_index];
41164116 const adapter: Index.Adapter = .{
4117 .indexes = @ptrCast([]const Index, indexes),
4117 .indexes = @as([]const Index, @ptrCast(indexes)),
41184118 };
41194119 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));
41214121 ip.extra.items[self.values_start + field_index] = @intFromEnum(value);
41224122 return null;
41234123 }
......@@ -4177,7 +4177,7 @@ fn getIncompleteEnumAuto(
41774177 });
41784178 ip.extra.appendNTimesAssumeCapacity(@intFromEnum(Index.none), enum_type.fields_len);
41794179 return .{
4180 .index = @enumFromInt(Index, ip.items.len - 1),
4180 .index = @as(Index, @enumFromInt(ip.items.len - 1)),
41814181 .tag_ty_index = extra_index + std.meta.fieldIndex(EnumAuto, "int_tag_type").?,
41824182 .names_map = names_map,
41834183 .names_start = extra_index + extra_fields_len,
......@@ -4228,7 +4228,7 @@ fn getIncompleteEnumExplicit(
42284228 // This is both fields and values (if present).
42294229 ip.extra.appendNTimesAssumeCapacity(@intFromEnum(Index.none), reserved_len);
42304230 return .{
4231 .index = @enumFromInt(Index, ip.items.len - 1),
4231 .index = @as(Index, @enumFromInt(ip.items.len - 1)),
42324232 .tag_ty_index = extra_index + std.meta.fieldIndex(EnumExplicit, "int_tag_type").?,
42334233 .names_map = names_map,
42344234 .names_start = extra_index + extra_fields_len,
......@@ -4251,7 +4251,7 @@ pub fn finishGetEnum(
42514251 try addIndexesToMap(ip, gpa, values_map, enum_type.values);
42524252 break :m values_map.toOptional();
42534253 };
4254 const fields_len = @intCast(u32, enum_type.names.len);
4254 const fields_len = @as(u32, @intCast(enum_type.names.len));
42554255 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(EnumExplicit).Struct.fields.len +
42564256 fields_len);
42574257 ip.items.appendAssumeCapacity(.{
......@@ -4265,15 +4265,15 @@ pub fn finishGetEnum(
42654265 .values_map = values_map,
42664266 }),
42674267 });
4268 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, enum_type.names));
4269 ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, enum_type.values));
4270 return @enumFromInt(Index, ip.items.len - 1);
4268 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(enum_type.names)));
4269 ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(enum_type.values)));
4270 return @as(Index, @enumFromInt(ip.items.len - 1));
42714271}
42724272
42734273pub fn getIfExists(ip: *const InternPool, key: Key) ?Index {
42744274 const adapter: KeyAdapter = .{ .intern_pool = ip };
42754275 const index = ip.map.getIndexAdapted(key, adapter) orelse return null;
4276 return @enumFromInt(Index, index);
4276 return @as(Index, @enumFromInt(index));
42774277}
42784278
42794279pub fn getAssumeExists(ip: *const InternPool, key: Key) Index {
......@@ -4311,7 +4311,7 @@ fn addIndexesToMap(
43114311fn addMap(ip: *InternPool, gpa: Allocator) Allocator.Error!MapIndex {
43124312 const ptr = try ip.maps.addOne(gpa);
43134313 ptr.* = .{};
4314 return @enumFromInt(MapIndex, ip.maps.items.len - 1);
4314 return @as(MapIndex, @enumFromInt(ip.maps.items.len - 1));
43154315}
43164316
43174317/// This operation only happens under compile error conditions.
......@@ -4320,7 +4320,7 @@ fn addMap(ip: *InternPool, gpa: Allocator) Allocator.Error!MapIndex {
43204320pub const remove = @compileError("InternPool.remove is not currently a supported operation; put a TODO there instead");
43214321
43224322fn 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));
43244324 try ip.reserveLimbs(gpa, @typeInfo(Int).Struct.fields.len + limbs_len);
43254325 ip.items.appendAssumeCapacity(.{
43264326 .tag = tag,
......@@ -4339,7 +4339,7 @@ fn addExtra(ip: *InternPool, gpa: Allocator, extra: anytype) Allocator.Error!u32
43394339}
43404340
43414341fn 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));
43434343 inline for (@typeInfo(@TypeOf(extra)).Struct.fields) |field| {
43444344 ip.extra.appendAssumeCapacity(switch (field.type) {
43454345 u32 => @field(extra, field.name),
......@@ -4354,12 +4354,12 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
43544354 String => @intFromEnum(@field(extra, field.name)),
43554355 NullTerminatedString => @intFromEnum(@field(extra, field.name)),
43564356 OptionalNullTerminatedString => @intFromEnum(@field(extra, field.name)),
4357 i32 => @bitCast(u32, @field(extra, field.name)),
4358 Tag.TypePointer.Flags => @bitCast(u32, @field(extra, field.name)),
4359 TypeFunction.Flags => @bitCast(u32, @field(extra, field.name)),
4360 Tag.TypePointer.PackedOffset => @bitCast(u32, @field(extra, field.name)),
4357 i32 => @as(u32, @bitCast(@field(extra, field.name))),
4358 Tag.TypePointer.Flags => @as(u32, @bitCast(@field(extra, field.name))),
4359 TypeFunction.Flags => @as(u32, @bitCast(@field(extra, field.name))),
4360 Tag.TypePointer.PackedOffset => @as(u32, @bitCast(@field(extra, field.name))),
43614361 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))),
43634363 else => @compileError("bad field type: " ++ @typeName(field.type)),
43644364 });
43654365 }
......@@ -4380,7 +4380,7 @@ fn addLimbsExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
43804380 @sizeOf(u64) => {},
43814381 else => @compileError("unsupported host"),
43824382 }
4383 const result = @intCast(u32, ip.limbs.items.len);
4383 const result = @as(u32, @intCast(ip.limbs.items.len));
43844384 inline for (@typeInfo(@TypeOf(extra)).Struct.fields, 0..) |field, i| {
43854385 const new: u32 = switch (field.type) {
43864386 u32 => @field(extra, field.name),
......@@ -4411,23 +4411,23 @@ fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct
44114411 const int32 = ip.extra.items[i + index];
44124412 @field(result, field.name) = switch (field.type) {
44134413 u32 => int32,
4414 Index => @enumFromInt(Index, int32),
4415 Module.Decl.Index => @enumFromInt(Module.Decl.Index, int32),
4416 Module.Namespace.Index => @enumFromInt(Module.Namespace.Index, int32),
4417 Module.Namespace.OptionalIndex => @enumFromInt(Module.Namespace.OptionalIndex, int32),
4418 Module.Fn.Index => @enumFromInt(Module.Fn.Index, int32),
4419 MapIndex => @enumFromInt(MapIndex, int32),
4420 OptionalMapIndex => @enumFromInt(OptionalMapIndex, int32),
4421 RuntimeIndex => @enumFromInt(RuntimeIndex, int32),
4422 String => @enumFromInt(String, int32),
4423 NullTerminatedString => @enumFromInt(NullTerminatedString, int32),
4424 OptionalNullTerminatedString => @enumFromInt(OptionalNullTerminatedString, int32),
4425 i32 => @bitCast(i32, int32),
4426 Tag.TypePointer.Flags => @bitCast(Tag.TypePointer.Flags, int32),
4427 TypeFunction.Flags => @bitCast(TypeFunction.Flags, int32),
4428 Tag.TypePointer.PackedOffset => @bitCast(Tag.TypePointer.PackedOffset, int32),
4429 Tag.TypePointer.VectorIndex => @enumFromInt(Tag.TypePointer.VectorIndex, int32),
4430 Tag.Variable.Flags => @bitCast(Tag.Variable.Flags, int32),
4414 Index => @as(Index, @enumFromInt(int32)),
4415 Module.Decl.Index => @as(Module.Decl.Index, @enumFromInt(int32)),
4416 Module.Namespace.Index => @as(Module.Namespace.Index, @enumFromInt(int32)),
4417 Module.Namespace.OptionalIndex => @as(Module.Namespace.OptionalIndex, @enumFromInt(int32)),
4418 Module.Fn.Index => @as(Module.Fn.Index, @enumFromInt(int32)),
4419 MapIndex => @as(MapIndex, @enumFromInt(int32)),
4420 OptionalMapIndex => @as(OptionalMapIndex, @enumFromInt(int32)),
4421 RuntimeIndex => @as(RuntimeIndex, @enumFromInt(int32)),
4422 String => @as(String, @enumFromInt(int32)),
4423 NullTerminatedString => @as(NullTerminatedString, @enumFromInt(int32)),
4424 OptionalNullTerminatedString => @as(OptionalNullTerminatedString, @enumFromInt(int32)),
4425 i32 => @as(i32, @bitCast(int32)),
4426 Tag.TypePointer.Flags => @as(Tag.TypePointer.Flags, @bitCast(int32)),
4427 TypeFunction.Flags => @as(TypeFunction.Flags, @bitCast(int32)),
4428 Tag.TypePointer.PackedOffset => @as(Tag.TypePointer.PackedOffset, @bitCast(int32)),
4429 Tag.TypePointer.VectorIndex => @as(Tag.TypePointer.VectorIndex, @enumFromInt(int32)),
4430 Tag.Variable.Flags => @as(Tag.Variable.Flags, @bitCast(int32)),
44314431 else => @compileError("bad field type: " ++ @typeName(field.type)),
44324432 };
44334433 }
......@@ -4452,13 +4452,13 @@ fn limbData(ip: *const InternPool, comptime T: type, index: usize) T {
44524452 inline for (@typeInfo(T).Struct.fields, 0..) |field, i| {
44534453 const host_int = ip.limbs.items[index + i / 2];
44544454 const int32 = if (i % 2 == 0)
4455 @truncate(u32, host_int)
4455 @as(u32, @truncate(host_int))
44564456 else
4457 @truncate(u32, host_int >> 32);
4457 @as(u32, @truncate(host_int >> 32));
44584458
44594459 @field(result, field.name) = switch (field.type) {
44604460 u32 => int32,
4461 Index => @enumFromInt(Index, int32),
4461 Index => @as(Index, @enumFromInt(int32)),
44624462 else => @compileError("bad field type: " ++ @typeName(field.type)),
44634463 };
44644464 }
......@@ -4494,8 +4494,8 @@ fn limbsSliceToIndex(ip: *const InternPool, limbs: []const Limb) LimbsAsIndexes
44944494 };
44954495 // TODO: https://github.com/ziglang/zig/issues/1738
44964496 return .{
4497 .start = @intCast(u32, @divExact(@intFromPtr(limbs.ptr) - @intFromPtr(host_slice.ptr), @sizeOf(Limb))),
4498 .len = @intCast(u32, limbs.len),
4497 .start = @as(u32, @intCast(@divExact(@intFromPtr(limbs.ptr) - @intFromPtr(host_slice.ptr), @sizeOf(Limb)))),
4498 .len = @as(u32, @intCast(limbs.len)),
44994499 };
45004500}
45014501
......@@ -4557,7 +4557,7 @@ pub fn slicePtrType(ip: *const InternPool, i: Index) Index {
45574557 }
45584558 const item = ip.items.get(@intFromEnum(i));
45594559 switch (item.tag) {
4560 .type_slice => return @enumFromInt(Index, item.data),
4560 .type_slice => return @as(Index, @enumFromInt(item.data)),
45614561 else => unreachable, // not a slice type
45624562 }
45634563}
......@@ -4727,7 +4727,7 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al
47274727 .val = error_union.val,
47284728 } }),
47294729 .aggregate => |aggregate| {
4730 const new_len = @intCast(usize, ip.aggregateTypeLen(new_ty));
4730 const new_len = @as(usize, @intCast(ip.aggregateTypeLen(new_ty)));
47314731 direct: {
47324732 const old_ty_child = switch (ip.indexToKey(old_ty)) {
47334733 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
48624862 const tags = ip.items.items(.tag);
48634863 if (tags[@intFromEnum(val)] != .type_struct) return .none;
48644864 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();
48664866}
48674867
48684868pub 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
48734873 else => return .none,
48744874 }
48754875 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();
48774877}
48784878
48794879pub fn indexToFuncType(ip: *const InternPool, val: Index) ?Key.FuncType {
......@@ -4899,7 +4899,7 @@ pub fn indexToInferredErrorSetType(ip: *const InternPool, val: Index) Module.Fn.
48994899 const tags = ip.items.items(.tag);
49004900 if (tags[@intFromEnum(val)] != .type_inferred_error_set) return .none;
49014901 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();
49034903}
49044904
49054905/// includes .comptime_int_type
......@@ -5057,7 +5057,7 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
50575057 .type_enum_auto => @sizeOf(EnumAuto),
50585058 .type_opaque => @sizeOf(Key.OpaqueType),
50595059 .type_struct => b: {
5060 const struct_index = @enumFromInt(Module.Struct.Index, data);
5060 const struct_index = @as(Module.Struct.Index, @enumFromInt(data));
50615061 const struct_obj = ip.structPtrConst(struct_index);
50625062 break :b @sizeOf(Module.Struct) +
50635063 @sizeOf(Module.Namespace) +
......@@ -5124,13 +5124,13 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
51245124
51255125 .bytes => b: {
51265126 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)));
51285128 break :b @sizeOf(Bytes) + len +
51295129 @intFromBool(ip.string_bytes.items[@intFromEnum(info.bytes) + len - 1] != 0);
51305130 },
51315131 .aggregate => b: {
51325132 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)));
51345134 break :b @sizeOf(Tag.Aggregate) + (@sizeOf(Index) * fields_len);
51355135 },
51365136 .repeated => @sizeOf(Repeated),
......@@ -5181,8 +5181,8 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void {
51815181 for (tags, datas, 0..) |tag, data, i| {
51825182 try w.print("${d} = {s}(", .{ i, @tagName(tag) });
51835183 switch (tag) {
5184 .simple_type => try w.print("{s}", .{@tagName(@enumFromInt(SimpleType, data))}),
5185 .simple_value => try w.print("{s}", .{@tagName(@enumFromInt(SimpleValue, data))}),
5184 .simple_type => try w.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(data)))}),
5185 .simple_value => try w.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(data)))}),
51865186
51875187 .type_int_signed,
51885188 .type_int_unsigned,
......@@ -5311,7 +5311,7 @@ pub fn createStruct(
53115311 }
53125312 const ptr = try ip.allocated_structs.addOne(gpa);
53135313 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));
53155315}
53165316
53175317pub fn destroyStruct(ip: *InternPool, gpa: Allocator, index: Module.Struct.Index) void {
......@@ -5333,7 +5333,7 @@ pub fn createUnion(
53335333 }
53345334 const ptr = try ip.allocated_unions.addOne(gpa);
53355335 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));
53375337}
53385338
53395339pub fn destroyUnion(ip: *InternPool, gpa: Allocator, index: Module.Union.Index) void {
......@@ -5355,7 +5355,7 @@ pub fn createFunc(
53555355 }
53565356 const ptr = try ip.allocated_funcs.addOne(gpa);
53575357 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));
53595359}
53605360
53615361pub fn destroyFunc(ip: *InternPool, gpa: Allocator, index: Module.Fn.Index) void {
......@@ -5377,7 +5377,7 @@ pub fn createInferredErrorSet(
53775377 }
53785378 const ptr = try ip.allocated_inferred_error_sets.addOne(gpa);
53795379 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));
53815381}
53825382
53835383pub fn destroyInferredErrorSet(ip: *InternPool, gpa: Allocator, index: Module.Fn.InferredErrorSet.Index) void {
......@@ -5406,7 +5406,7 @@ pub fn getOrPutStringFmt(
54065406 args: anytype,
54075407) Allocator.Error!NullTerminatedString {
54085408 // 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));
54105410 try ip.string_bytes.ensureUnusedCapacity(gpa, len);
54115411 ip.string_bytes.writer(undefined).print(format, args) catch unreachable;
54125412 ip.string_bytes.appendAssumeCapacity(0);
......@@ -5430,7 +5430,7 @@ pub fn getOrPutTrailingString(
54305430 len: usize,
54315431) Allocator.Error!NullTerminatedString {
54325432 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));
54345434 if (len > 0 and string_bytes.getLast() == 0) {
54355435 _ = string_bytes.pop();
54365436 } else {
......@@ -5444,11 +5444,11 @@ pub fn getOrPutTrailingString(
54445444 });
54455445 if (gop.found_existing) {
54465446 string_bytes.shrinkRetainingCapacity(str_index);
5447 return @enumFromInt(NullTerminatedString, gop.key_ptr.*);
5447 return @as(NullTerminatedString, @enumFromInt(gop.key_ptr.*));
54485448 } else {
54495449 gop.key_ptr.* = str_index;
54505450 string_bytes.appendAssumeCapacity(0);
5451 return @enumFromInt(NullTerminatedString, str_index);
5451 return @as(NullTerminatedString, @enumFromInt(str_index));
54525452 }
54535453}
54545454
......@@ -5456,7 +5456,7 @@ pub fn getString(ip: *InternPool, s: []const u8) OptionalNullTerminatedString {
54565456 if (ip.string_table.getKeyAdapted(s, std.hash_map.StringIndexAdapter{
54575457 .bytes = &ip.string_bytes,
54585458 })) |index| {
5459 return @enumFromInt(NullTerminatedString, index).toOptional();
5459 return @as(NullTerminatedString, @enumFromInt(index)).toOptional();
54605460 } else {
54615461 return .none;
54625462 }
......@@ -5596,7 +5596,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
55965596 .undef,
55975597 .opt_null,
55985598 .only_possible_value,
5599 => @enumFromInt(Index, ip.items.items(.data)[@intFromEnum(index)]),
5599 => @as(Index, @enumFromInt(ip.items.items(.data)[@intFromEnum(index)])),
56005600
56015601 .simple_value => unreachable, // handled via Index above
56025602
......@@ -5628,7 +5628,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
56285628 => |t| {
56295629 const extra_index = ip.items.items(.data)[@intFromEnum(index)];
56305630 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]));
56325632 },
56335633
56345634 .int_u8 => .u8_type,
......@@ -5670,7 +5670,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
56705670/// Assumes that the enum's field indexes equal its value tags.
56715671pub fn toEnum(ip: *const InternPool, comptime E: type, i: Index) E {
56725672 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));
56745674}
56755675
56765676pub fn aggregateTypeLen(ip: *const InternPool, ty: Index) u64 {
......@@ -5703,9 +5703,9 @@ pub fn funcReturnType(ip: *const InternPool, ty: Index) Index {
57035703 else => unreachable,
57045704 };
57055705 assert(child_item.tag == .type_function);
5706 return @enumFromInt(Index, ip.extra.items[
5706 return @as(Index, @enumFromInt(ip.extra.items[
57075707 child_item.data + std.meta.fieldIndex(TypeFunction, "return_type").?
5708 ]);
5708 ]));
57095709}
57105710
57115711pub fn isNoReturn(ip: *const InternPool, ty: Index) bool {
......@@ -5736,9 +5736,9 @@ pub fn getBackingDecl(ip: *const InternPool, val: Index) Module.Decl.OptionalInd
57365736 switch (ip.items.items(.tag)[base]) {
57375737 inline .ptr_decl,
57385738 .ptr_mut_decl,
5739 => |tag| return @enumFromInt(Module.Decl.OptionalIndex, ip.extra.items[
5739 => |tag| return @as(Module.Decl.OptionalIndex, @enumFromInt(ip.extra.items[
57405740 ip.items.items(.data)[base] + std.meta.fieldIndex(tag.Payload(), "decl").?
5741 ]),
5741 ])),
57425742 inline .ptr_eu_payload,
57435743 .ptr_opt_payload,
57445744 .ptr_elem,
src/Liveness.zig+34-34
......@@ -178,14 +178,14 @@ pub fn analyze(gpa: Allocator, air: Air, intern_pool: *const InternPool) Allocat
178178
179179pub fn getTombBits(l: Liveness, inst: Air.Inst.Index) Bpi {
180180 const usize_index = (inst * bpi) / @bitSizeOf(usize);
181 return @truncate(Bpi, l.tomb_bits[usize_index] >>
182 @intCast(Log2Int(usize), (inst % (@bitSizeOf(usize) / bpi)) * bpi));
181 return @as(Bpi, @truncate(l.tomb_bits[usize_index] >>
182 @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi))));
183183}
184184
185185pub fn isUnused(l: Liveness, inst: Air.Inst.Index) bool {
186186 const usize_index = (inst * bpi) / @bitSizeOf(usize);
187187 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)));
189189 return (l.tomb_bits[usize_index] & mask) != 0;
190190}
191191
......@@ -193,7 +193,7 @@ pub fn operandDies(l: Liveness, inst: Air.Inst.Index, operand: OperandInt) bool
193193 assert(operand < bpi - 1);
194194 const usize_index = (inst * bpi) / @bitSizeOf(usize);
195195 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));
197197 return (l.tomb_bits[usize_index] & mask) != 0;
198198}
199199
......@@ -201,7 +201,7 @@ pub fn clearOperandDeath(l: Liveness, inst: Air.Inst.Index, operand: OperandInt)
201201 assert(operand < bpi - 1);
202202 const usize_index = (inst * bpi) / @bitSizeOf(usize);
203203 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));
205205 l.tomb_bits[usize_index] &= ~mask;
206206}
207207
......@@ -484,11 +484,11 @@ pub fn categorizeOperand(
484484 const inst_data = air_datas[inst].pl_op;
485485 const callee = inst_data.operand;
486486 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]));
488488 if (args.len + 1 <= bpi - 1) {
489489 if (callee == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);
490490 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);
492492 }
493493 return .write;
494494 }
......@@ -535,12 +535,12 @@ pub fn categorizeOperand(
535535 .aggregate_init => {
536536 const ty_pl = air_datas[inst].ty_pl;
537537 const aggregate_ty = air.getRefType(ty_pl.ty);
538 const len = @intCast(usize, aggregate_ty.arrayLenIp(ip));
539 const elements = @ptrCast([]const Air.Inst.Ref, air.extra[ty_pl.payload..][0..len]);
538 const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip)));
539 const elements = @as([]const Air.Inst.Ref, @ptrCast(air.extra[ty_pl.payload..][0..len]));
540540
541541 if (elements.len <= bpi - 1) {
542542 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);
544544 }
545545 return .none;
546546 }
......@@ -808,20 +808,20 @@ pub const BigTomb = struct {
808808
809809 const small_tombs = bpi - 1;
810810 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;
812812 return dies;
813813 }
814814
815815 const big_bit_index = this_bit_index - small_tombs;
816816 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) {
818818 bt.reached_end = true;
819819 return false;
820820 }
821821 bt.extra_offset += 1;
822822 }
823 const dies = @truncate(u1, bt.extra[bt.extra_start + bt.extra_offset] >>
824 @intCast(u5, big_bit_index - bt.extra_offset * 31)) != 0;
823 const dies = @as(u1, @truncate(bt.extra[bt.extra_start + bt.extra_offset] >>
824 @as(u5, @intCast(big_bit_index - bt.extra_offset * 31)))) != 0;
825825 return dies;
826826 }
827827};
......@@ -838,7 +838,7 @@ const Analysis = struct {
838838 fn storeTombBits(a: *Analysis, inst: Air.Inst.Index, tomb_bits: Bpi) void {
839839 const usize_index = (inst * bpi) / @bitSizeOf(usize);
840840 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));
842842 }
843843
844844 fn addExtra(a: *Analysis, extra: anytype) Allocator.Error!u32 {
......@@ -849,7 +849,7 @@ const Analysis = struct {
849849
850850 fn addExtraAssumeCapacity(a: *Analysis, extra: anytype) u32 {
851851 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));
853853 inline for (fields) |field| {
854854 a.extra.appendAssumeCapacity(switch (field.type) {
855855 u32 => @field(extra, field.name),
......@@ -1108,7 +1108,7 @@ fn analyzeInst(
11081108 const inst_data = inst_datas[inst].pl_op;
11091109 const callee = inst_data.operand;
11101110 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]));
11121112 if (args.len + 1 <= bpi - 1) {
11131113 var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1);
11141114 buf[0] = callee;
......@@ -1146,8 +1146,8 @@ fn analyzeInst(
11461146 .aggregate_init => {
11471147 const ty_pl = inst_datas[inst].ty_pl;
11481148 const aggregate_ty = a.air.getRefType(ty_pl.ty);
1149 const len = @intCast(usize, aggregate_ty.arrayLenIp(ip));
1150 const elements = @ptrCast([]const Air.Inst.Ref, a.air.extra[ty_pl.payload..][0..len]);
1149 const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip)));
1150 const elements = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[ty_pl.payload..][0..len]));
11511151
11521152 if (elements.len <= bpi - 1) {
11531153 var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1);
......@@ -1200,9 +1200,9 @@ fn analyzeInst(
12001200 .assembly => {
12011201 const extra = a.air.extraData(Air.Asm, inst_datas[inst].ty_pl.payload);
12021202 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]));
12041204 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]));
12061206 extra_i += inputs.len;
12071207
12081208 const num_operands = simple: {
......@@ -1310,7 +1310,7 @@ fn analyzeOperands(
13101310 // Don't compute any liveness for constants
13111311 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
13151315 if ((try data.live_set.fetchPut(gpa, operand, {})) == null) {
13161316 log.debug("[{}] %{}: added %{} to live set (operand dies here)", .{ pass, inst, operand });
......@@ -1320,7 +1320,7 @@ fn analyzeOperands(
13201320 }
13211321
13221322 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));
13241324 },
13251325 }
13261326}
......@@ -1472,7 +1472,7 @@ fn analyzeInstLoop(
14721472 const num_breaks = data.breaks.count();
14731473 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));
14761476 a.extra.appendAssumeCapacity(num_breaks);
14771477
14781478 var it = data.breaks.keyIterator();
......@@ -1523,7 +1523,7 @@ fn analyzeInstLoop(
15231523 // This is necessarily not in the same control flow branch, because loops are noreturn
15241524 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)));
15271527 for (loop_live) |alive| {
15281528 data.live_set.putAssumeCapacity(alive, {});
15291529 }
......@@ -1647,8 +1647,8 @@ fn analyzeInstCondBr(
16471647 log.debug("[{}] %{}: new live set is {}", .{ pass, inst, fmtInstSet(&data.live_set) });
16481648
16491649 // Write the mirrored deaths to `extra`
1650 const then_death_count = @intCast(u32, then_mirrored_deaths.items.len);
1651 const else_death_count = @intCast(u32, else_mirrored_deaths.items.len);
1650 const then_death_count = @as(u32, @intCast(then_mirrored_deaths.items.len));
1651 const else_death_count = @as(u32, @intCast(else_mirrored_deaths.items.len));
16521652 try a.extra.ensureUnusedCapacity(gpa, std.meta.fields(CondBr).len + then_death_count + else_death_count);
16531653 const extra_index = a.addExtraAssumeCapacity(CondBr{
16541654 .then_death_count = then_death_count,
......@@ -1758,12 +1758,12 @@ fn analyzeInstSwitchBr(
17581758 log.debug("[{}] %{}: new live set is {}", .{ pass, inst, fmtInstSet(&data.live_set) });
17591759 }
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));
17621762 const extra_index = try a.addExtra(SwitchBr{
17631763 .else_death_count = else_death_count,
17641764 });
17651765 for (mirrored_deaths[0..ncases]) |mirrored| {
1766 const num = @intCast(u32, mirrored.items.len);
1766 const num = @as(u32, @intCast(mirrored.items.len));
17671767 try a.extra.ensureUnusedCapacity(gpa, num + 1);
17681768 a.extra.appendAssumeCapacity(num);
17691769 a.extra.appendSliceAssumeCapacity(mirrored.items);
......@@ -1798,7 +1798,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
17981798 inst: Air.Inst.Index,
17991799 total_operands: usize,
18001800 ) !Self {
1801 const extra_operands = @intCast(u32, total_operands) -| (bpi - 1);
1801 const extra_operands = @as(u32, @intCast(total_operands)) -| (bpi - 1);
18021802 const max_extra_tombs = (extra_operands + 30) / 31;
18031803
18041804 const extra_tombs: []u32 = switch (pass) {
......@@ -1818,7 +1818,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
18181818 .a = a,
18191819 .data = data,
18201820 .inst = inst,
1821 .operands_remaining = @intCast(u32, total_operands),
1821 .operands_remaining = @as(u32, @intCast(total_operands)),
18221822 .extra_tombs = extra_tombs,
18231823 .will_die_immediately = will_die_immediately,
18241824 };
......@@ -1847,7 +1847,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
18471847 if (big.will_die_immediately and !big.a.air.mustLower(big.inst, ip)) return;
18481848
18491849 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
18521852 const gpa = big.a.gpa;
18531853
......@@ -1881,7 +1881,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
18811881 // keep at least one.
18821882 var num: usize = big.extra_tombs.len;
18831883 while (num > 1) {
1884 if (@truncate(u31, big.extra_tombs[num - 1]) != 0) {
1884 if (@as(u31, @truncate(big.extra_tombs[num - 1])) != 0) {
18851885 // Some operand dies here
18861886 break;
18871887 }
......@@ -1892,7 +1892,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
18921892
18931893 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));
18961896 try big.a.extra.appendSlice(gpa, extra_tombs);
18971897 try big.a.special.put(gpa, big.inst, extra_index);
18981898 },
src/Liveness/Verify.zig+11-11
......@@ -325,8 +325,8 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
325325 .aggregate_init => {
326326 const ty_pl = data[inst].ty_pl;
327327 const aggregate_ty = self.air.getRefType(ty_pl.ty);
328 const len = @intCast(usize, aggregate_ty.arrayLenIp(ip));
329 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
328 const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip)));
329 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
330330
331331 var bt = self.liveness.iterateBigTomb(inst);
332332 for (elements) |element| {
......@@ -337,9 +337,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
337337 .call, .call_always_tail, .call_never_tail, .call_never_inline => {
338338 const pl_op = data[inst].pl_op;
339339 const extra = self.air.extraData(Air.Call, pl_op.payload);
340 const args = @ptrCast(
340 const args = @as(
341341 []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]),
343343 );
344344
345345 var bt = self.liveness.iterateBigTomb(inst);
......@@ -353,14 +353,14 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
353353 const ty_pl = data[inst].ty_pl;
354354 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
355355 var extra_i = extra.end;
356 const outputs = @ptrCast(
356 const outputs = @as(
357357 []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]),
359359 );
360360 extra_i += outputs.len;
361 const inputs = @ptrCast(
361 const inputs = @as(
362362 []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]),
364364 );
365365 extra_i += inputs.len;
366366
......@@ -521,9 +521,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
521521
522522 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
523523 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
524 const items = @ptrCast(
524 const items = @as(
525525 []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]),
527527 );
528528 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
529529 extra_index = case.end + items.len + case_body.len;
......@@ -576,7 +576,7 @@ fn verifyInstOperands(
576576 operands: [Liveness.bpi - 1]Air.Inst.Ref,
577577) Error!void {
578578 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)));
580580 try self.verifyOperand(inst, operand, dies);
581581 }
582582 try self.verifyInst(inst);
src/Manifest.zig+11-11
......@@ -102,7 +102,7 @@ pub fn hex64(x: u64) [16]u8 {
102102 var result: [16]u8 = undefined;
103103 var i: usize = 0;
104104 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))));
106106 result[i * 2 + 0] = hex_charset[byte >> 4];
107107 result[i * 2 + 1] = hex_charset[byte & 15];
108108 }
......@@ -284,7 +284,7 @@ const Parse = struct {
284284 @errorName(err),
285285 });
286286 };
287 if (@enumFromInt(MultihashFunction, their_multihash_func) != multihash_function) {
287 if (@as(MultihashFunction, @enumFromInt(their_multihash_func)) != multihash_function) {
288288 return fail(p, tok, "unsupported hash function: only sha2-256 is supported", .{});
289289 }
290290 }
......@@ -345,7 +345,7 @@ const Parse = struct {
345345 .invalid_escape_character => |bad_index| {
346346 try p.appendErrorOff(
347347 token,
348 offset + @intCast(u32, bad_index),
348 offset + @as(u32, @intCast(bad_index)),
349349 "invalid escape character: '{c}'",
350350 .{raw_string[bad_index]},
351351 );
......@@ -353,7 +353,7 @@ const Parse = struct {
353353 .expected_hex_digit => |bad_index| {
354354 try p.appendErrorOff(
355355 token,
356 offset + @intCast(u32, bad_index),
356 offset + @as(u32, @intCast(bad_index)),
357357 "expected hex digit, found '{c}'",
358358 .{raw_string[bad_index]},
359359 );
......@@ -361,7 +361,7 @@ const Parse = struct {
361361 .empty_unicode_escape_sequence => |bad_index| {
362362 try p.appendErrorOff(
363363 token,
364 offset + @intCast(u32, bad_index),
364 offset + @as(u32, @intCast(bad_index)),
365365 "empty unicode escape sequence",
366366 .{},
367367 );
......@@ -369,7 +369,7 @@ const Parse = struct {
369369 .expected_hex_digit_or_rbrace => |bad_index| {
370370 try p.appendErrorOff(
371371 token,
372 offset + @intCast(u32, bad_index),
372 offset + @as(u32, @intCast(bad_index)),
373373 "expected hex digit or '}}', found '{c}'",
374374 .{raw_string[bad_index]},
375375 );
......@@ -377,7 +377,7 @@ const Parse = struct {
377377 .invalid_unicode_codepoint => |bad_index| {
378378 try p.appendErrorOff(
379379 token,
380 offset + @intCast(u32, bad_index),
380 offset + @as(u32, @intCast(bad_index)),
381381 "unicode escape does not correspond to a valid codepoint",
382382 .{},
383383 );
......@@ -385,7 +385,7 @@ const Parse = struct {
385385 .expected_lbrace => |bad_index| {
386386 try p.appendErrorOff(
387387 token,
388 offset + @intCast(u32, bad_index),
388 offset + @as(u32, @intCast(bad_index)),
389389 "expected '{{', found '{c}",
390390 .{raw_string[bad_index]},
391391 );
......@@ -393,7 +393,7 @@ const Parse = struct {
393393 .expected_rbrace => |bad_index| {
394394 try p.appendErrorOff(
395395 token,
396 offset + @intCast(u32, bad_index),
396 offset + @as(u32, @intCast(bad_index)),
397397 "expected '}}', found '{c}",
398398 .{raw_string[bad_index]},
399399 );
......@@ -401,7 +401,7 @@ const Parse = struct {
401401 .expected_single_quote => |bad_index| {
402402 try p.appendErrorOff(
403403 token,
404 offset + @intCast(u32, bad_index),
404 offset + @as(u32, @intCast(bad_index)),
405405 "expected single quote ('), found '{c}",
406406 .{raw_string[bad_index]},
407407 );
......@@ -409,7 +409,7 @@ const Parse = struct {
409409 .invalid_character => |bad_index| {
410410 try p.appendErrorOff(
411411 token,
412 offset + @intCast(u32, bad_index),
412 offset + @as(u32, @intCast(bad_index)),
413413 "invalid byte in string or character literal: '{c}'",
414414 .{raw_string[bad_index]},
415415 );
src/Module.zig+83-83
......@@ -554,7 +554,7 @@ pub const Decl = struct {
554554 _,
555555
556556 pub fn toOptional(i: Index) OptionalIndex {
557 return @enumFromInt(OptionalIndex, @intFromEnum(i));
557 return @as(OptionalIndex, @enumFromInt(@intFromEnum(i)));
558558 }
559559 };
560560
......@@ -563,12 +563,12 @@ pub const Decl = struct {
563563 _,
564564
565565 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)));
567567 }
568568
569569 pub fn unwrap(oi: OptionalIndex) ?Index {
570570 if (oi == .none) return null;
571 return @enumFromInt(Index, @intFromEnum(oi));
571 return @as(Index, @enumFromInt(@intFromEnum(oi)));
572572 }
573573 };
574574
......@@ -619,7 +619,7 @@ pub const Decl = struct {
619619 pub fn contentsHashZir(decl: Decl, zir: Zir) std.zig.SrcHash {
620620 assert(decl.zir_decl_index != 0);
621621 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.*));
623623 return contents_hash;
624624 }
625625
......@@ -633,7 +633,7 @@ pub const Decl = struct {
633633 if (!decl.has_align) return .none;
634634 assert(decl.zir_decl_index != 0);
635635 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]));
637637 }
638638
639639 pub fn zirLinksectionRef(decl: Decl, mod: *Module) Zir.Inst.Ref {
......@@ -641,7 +641,7 @@ pub const Decl = struct {
641641 assert(decl.zir_decl_index != 0);
642642 const zir = decl.getFileScope(mod).zir;
643643 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]));
645645 }
646646
647647 pub fn zirAddrspaceRef(decl: Decl, mod: *Module) Zir.Inst.Ref {
......@@ -649,7 +649,7 @@ pub const Decl = struct {
649649 assert(decl.zir_decl_index != 0);
650650 const zir = decl.getFileScope(mod).zir;
651651 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]));
653653 }
654654
655655 pub fn relativeToLine(decl: Decl, offset: u32) u32 {
......@@ -657,11 +657,11 @@ pub const Decl = struct {
657657 }
658658
659659 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))));
661661 }
662662
663663 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));
665665 }
666666
667667 pub fn tokSrcLoc(decl: Decl, token_index: Ast.TokenIndex) LazySrcLoc {
......@@ -864,7 +864,7 @@ pub const Decl = struct {
864864
865865 pub fn getAlignment(decl: Decl, mod: *Module) u32 {
866866 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)));
868868 }
869869
870870 pub fn intern(decl: *Decl, mod: *Module) Allocator.Error!void {
......@@ -922,7 +922,7 @@ pub const Struct = struct {
922922 _,
923923
924924 pub fn toOptional(i: Index) OptionalIndex {
925 return @enumFromInt(OptionalIndex, @intFromEnum(i));
925 return @as(OptionalIndex, @enumFromInt(@intFromEnum(i)));
926926 }
927927 };
928928
......@@ -931,12 +931,12 @@ pub const Struct = struct {
931931 _,
932932
933933 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)));
935935 }
936936
937937 pub fn unwrap(oi: OptionalIndex) ?Index {
938938 if (oi == .none) return null;
939 return @enumFromInt(Index, @intFromEnum(oi));
939 return @as(Index, @enumFromInt(@intFromEnum(oi)));
940940 }
941941 };
942942
......@@ -964,7 +964,7 @@ pub const Struct = struct {
964964 ) u32 {
965965 if (field.abi_align.toByteUnitsOptional()) |abi_align| {
966966 assert(layout != .Packed);
967 return @intCast(u32, abi_align);
967 return @as(u32, @intCast(abi_align));
968968 }
969969
970970 const target = mod.getTarget();
......@@ -1042,7 +1042,7 @@ pub const Struct = struct {
10421042 var bit_sum: u64 = 0;
10431043 for (s.fields.values(), 0..) |field, i| {
10441044 if (i == index) {
1045 return @intCast(u16, bit_sum);
1045 return @as(u16, @intCast(bit_sum));
10461046 }
10471047 bit_sum += field.ty.bitSize(mod);
10481048 }
......@@ -1123,7 +1123,7 @@ pub const Union = struct {
11231123 _,
11241124
11251125 pub fn toOptional(i: Index) OptionalIndex {
1126 return @enumFromInt(OptionalIndex, @intFromEnum(i));
1126 return @as(OptionalIndex, @enumFromInt(@intFromEnum(i)));
11271127 }
11281128 };
11291129
......@@ -1132,12 +1132,12 @@ pub const Union = struct {
11321132 _,
11331133
11341134 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)));
11361136 }
11371137
11381138 pub fn unwrap(oi: OptionalIndex) ?Index {
11391139 if (oi == .none) return null;
1140 return @enumFromInt(Index, @intFromEnum(oi));
1140 return @as(Index, @enumFromInt(@intFromEnum(oi)));
11411141 }
11421142 };
11431143
......@@ -1151,7 +1151,7 @@ pub const Union = struct {
11511151 /// Keep implementation in sync with `Sema.unionFieldAlignment`.
11521152 /// Prefer to call that function instead of this one during Sema.
11531153 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)));
11551155 }
11561156 };
11571157
......@@ -1205,7 +1205,7 @@ pub const Union = struct {
12051205 most_index = i;
12061206 }
12071207 }
1208 return @intCast(u32, most_index);
1208 return @as(u32, @intCast(most_index));
12091209 }
12101210
12111211 /// Returns 0 if the union is represented with 0 bits at runtime.
......@@ -1267,11 +1267,11 @@ pub const Union = struct {
12671267 const field_size = field.ty.abiSize(mod);
12681268 if (field_size > payload_size) {
12691269 payload_size = field_size;
1270 biggest_field = @intCast(u32, i);
1270 biggest_field = @as(u32, @intCast(i));
12711271 }
12721272 if (field_align > payload_align) {
1273 payload_align = @intCast(u32, field_align);
1274 most_aligned_field = @intCast(u32, i);
1273 payload_align = @as(u32, @intCast(field_align));
1274 most_aligned_field = @as(u32, @intCast(i));
12751275 most_aligned_field_size = field_size;
12761276 }
12771277 }
......@@ -1303,7 +1303,7 @@ pub const Union = struct {
13031303 size += payload_size;
13041304 const prev_size = size;
13051305 size = std.mem.alignForward(u64, size, tag_align);
1306 padding = @intCast(u32, size - prev_size);
1306 padding = @as(u32, @intCast(size - prev_size));
13071307 } else {
13081308 // {Payload, Tag}
13091309 size += payload_size;
......@@ -1311,7 +1311,7 @@ pub const Union = struct {
13111311 size += tag_size;
13121312 const prev_size = size;
13131313 size = std.mem.alignForward(u64, size, payload_align);
1314 padding = @intCast(u32, size - prev_size);
1314 padding = @as(u32, @intCast(size - prev_size));
13151315 }
13161316 return .{
13171317 .abi_size = size,
......@@ -1409,7 +1409,7 @@ pub const Fn = struct {
14091409 _,
14101410
14111411 pub fn toOptional(i: Index) OptionalIndex {
1412 return @enumFromInt(OptionalIndex, @intFromEnum(i));
1412 return @as(OptionalIndex, @enumFromInt(@intFromEnum(i)));
14131413 }
14141414 };
14151415
......@@ -1418,12 +1418,12 @@ pub const Fn = struct {
14181418 _,
14191419
14201420 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)));
14221422 }
14231423
14241424 pub fn unwrap(oi: OptionalIndex) ?Index {
14251425 if (oi == .none) return null;
1426 return @enumFromInt(Index, @intFromEnum(oi));
1426 return @as(Index, @enumFromInt(@intFromEnum(oi)));
14271427 }
14281428 };
14291429
......@@ -1477,7 +1477,7 @@ pub const Fn = struct {
14771477 _,
14781478
14791479 pub fn toOptional(i: InferredErrorSet.Index) InferredErrorSet.OptionalIndex {
1480 return @enumFromInt(InferredErrorSet.OptionalIndex, @intFromEnum(i));
1480 return @as(InferredErrorSet.OptionalIndex, @enumFromInt(@intFromEnum(i)));
14811481 }
14821482 };
14831483
......@@ -1486,12 +1486,12 @@ pub const Fn = struct {
14861486 _,
14871487
14881488 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)));
14901490 }
14911491
14921492 pub fn unwrap(oi: InferredErrorSet.OptionalIndex) ?InferredErrorSet.Index {
14931493 if (oi == .none) return null;
1494 return @enumFromInt(InferredErrorSet.Index, @intFromEnum(oi));
1494 return @as(InferredErrorSet.Index, @enumFromInt(@intFromEnum(oi)));
14951495 }
14961496 };
14971497
......@@ -1613,7 +1613,7 @@ pub const Namespace = struct {
16131613 _,
16141614
16151615 pub fn toOptional(i: Index) OptionalIndex {
1616 return @enumFromInt(OptionalIndex, @intFromEnum(i));
1616 return @as(OptionalIndex, @enumFromInt(@intFromEnum(i)));
16171617 }
16181618 };
16191619
......@@ -1622,12 +1622,12 @@ pub const Namespace = struct {
16221622 _,
16231623
16241624 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)));
16261626 }
16271627
16281628 pub fn unwrap(oi: OptionalIndex) ?Index {
16291629 if (oi == .none) return null;
1630 return @enumFromInt(Index, @intFromEnum(oi));
1630 return @as(Index, @enumFromInt(@intFromEnum(oi)));
16311631 }
16321632 };
16331633
......@@ -1867,7 +1867,7 @@ pub const File = struct {
18671867 if (stat.size > std.math.maxInt(u32))
18681868 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);
18711871 defer if (!file.source_loaded) gpa.free(source);
18721872 const amt = try f.readAll(source);
18731873 if (amt != stat.size)
......@@ -2116,7 +2116,7 @@ pub const SrcLoc = struct {
21162116 }
21172117
21182118 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))));
21202120 }
21212121
21222122 pub const Span = struct {
......@@ -2135,7 +2135,7 @@ pub const SrcLoc = struct {
21352135 .token_abs => |tok_index| {
21362136 const tree = try src_loc.file_scope.getTree(gpa);
21372137 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));
21392139 return Span{ .start = start, .end = end, .main = start };
21402140 },
21412141 .node_abs => |node| {
......@@ -2146,14 +2146,14 @@ pub const SrcLoc = struct {
21462146 const tree = try src_loc.file_scope.getTree(gpa);
21472147 const tok_index = src_loc.declSrcToken();
21482148 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));
21502150 return Span{ .start = start, .end = end, .main = start };
21512151 },
21522152 .token_offset => |tok_off| {
21532153 const tree = try src_loc.file_scope.getTree(gpa);
21542154 const tok_index = src_loc.declSrcToken() + tok_off;
21552155 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));
21572157 return Span{ .start = start, .end = end, .main = start };
21582158 },
21592159 .node_offset => |traced_off| {
......@@ -2206,7 +2206,7 @@ pub const SrcLoc = struct {
22062206 }
22072207 const tok_index = full.ast.mut_token + 1; // the name token
22082208 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));
22102210 return Span{ .start = start, .end = end, .main = start };
22112211 },
22122212 .node_offset_var_decl_align => |node_off| {
......@@ -2292,7 +2292,7 @@ pub const SrcLoc = struct {
22922292 else => tree.firstToken(node) - 2,
22932293 };
22942294 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));
22962296 return Span{ .start = start, .end = end, .main = start };
22972297 },
22982298 .node_offset_deref_ptr => |node_off| {
......@@ -2359,7 +2359,7 @@ pub const SrcLoc = struct {
23592359 // that contains this input.
23602360 const node_tags = tree.nodes.items(.tag);
23612361 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));
23632363 switch (node_tag) {
23642364 .for_simple, .@"for" => {
23652365 const for_full = tree.fullFor(node).?;
......@@ -2479,7 +2479,7 @@ pub const SrcLoc = struct {
24792479 };
24802480 const start = tree.tokens.items(.start)[start_tok];
24812481 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));
24832483 return Span{ .start = start, .end = end, .main = start };
24842484 },
24852485 .node_offset_fn_type_align => |node_off| {
......@@ -2539,7 +2539,7 @@ pub const SrcLoc = struct {
25392539 const tree = try src_loc.file_scope.getTree(gpa);
25402540 const token_tags = tree.tokens.items(.tag);
25412541 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
25442544 var first_tok = tok_index;
25452545 while (true) switch (token_tags[first_tok - 1]) {
......@@ -2568,7 +2568,7 @@ pub const SrcLoc = struct {
25682568 const full = tree.fullFnProto(&buf, parent_node).?;
25692569 const tok_index = full.lib_name.?;
25702570 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));
25722572 return Span{ .start = start, .end = end, .main = start };
25732573 },
25742574
......@@ -2761,7 +2761,7 @@ pub const SrcLoc = struct {
27612761 end_tok = main;
27622762 }
27632763 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));
27652765 return Span{ .start = start_off, .end = end_off, .main = token_starts[main] };
27662766 }
27672767};
......@@ -3577,7 +3577,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
35773577 if (stat.size > std.math.maxInt(u32))
35783578 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);
35813581 defer if (!file.source_loaded) gpa.free(source);
35823582 const amt = try source_file.readAll(source);
35833583 if (amt != stat.size)
......@@ -3609,21 +3609,21 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
36093609 if (file.zir.instructions.len == 0)
36103610 @as([*]const u8, undefined)
36113611 else
3612 @ptrCast([*]const u8, safety_buffer.ptr)
3612 @as([*]const u8, @ptrCast(safety_buffer.ptr))
36133613 else
3614 @ptrCast([*]const u8, file.zir.instructions.items(.data).ptr);
3614 @as([*]const u8, @ptrCast(file.zir.instructions.items(.data).ptr));
36153615 if (data_has_safety_tag) {
36163616 // The `Data` union has a safety tag but in the file format we store it without.
36173617 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));
36193619 safety_buffer[i] = as_struct.data;
36203620 }
36213621 }
36223622
36233623 const header: Zir.Header = .{
3624 .instructions_len = @intCast(u32, file.zir.instructions.len),
3625 .string_bytes_len = @intCast(u32, file.zir.string_bytes.len),
3626 .extra_len = @intCast(u32, file.zir.extra.len),
3624 .instructions_len = @as(u32, @intCast(file.zir.instructions.len)),
3625 .string_bytes_len = @as(u32, @intCast(file.zir.string_bytes.len)),
3626 .extra_len = @as(u32, @intCast(file.zir.extra.len)),
36273627
36283628 .stat_size = stat.size,
36293629 .stat_inode = stat.inode,
......@@ -3631,11 +3631,11 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
36313631 };
36323632 var iovecs = [_]std.os.iovec_const{
36333633 .{
3634 .iov_base = @ptrCast([*]const u8, &header),
3634 .iov_base = @as([*]const u8, @ptrCast(&header)),
36353635 .iov_len = @sizeOf(Zir.Header),
36363636 },
36373637 .{
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)),
36393639 .iov_len = file.zir.instructions.len,
36403640 },
36413641 .{
......@@ -3647,7 +3647,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
36473647 .iov_len = file.zir.string_bytes.len,
36483648 },
36493649 .{
3650 .iov_base = @ptrCast([*]const u8, file.zir.extra.ptr),
3650 .iov_base = @as([*]const u8, @ptrCast(file.zir.extra.ptr)),
36513651 .iov_len = file.zir.extra.len * 4,
36523652 },
36533653 };
......@@ -3722,13 +3722,13 @@ fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File)
37223722 defer if (data_has_safety_tag) gpa.free(safety_buffer);
37233723
37243724 const data_ptr = if (data_has_safety_tag)
3725 @ptrCast([*]u8, safety_buffer.ptr)
3725 @as([*]u8, @ptrCast(safety_buffer.ptr))
37263726 else
3727 @ptrCast([*]u8, zir.instructions.items(.data).ptr);
3727 @as([*]u8, @ptrCast(zir.instructions.items(.data).ptr));
37283728
37293729 var iovecs = [_]std.os.iovec{
37303730 .{
3731 .iov_base = @ptrCast([*]u8, zir.instructions.items(.tag).ptr),
3731 .iov_base = @as([*]u8, @ptrCast(zir.instructions.items(.tag).ptr)),
37323732 .iov_len = header.instructions_len,
37333733 },
37343734 .{
......@@ -3740,7 +3740,7 @@ fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File)
37403740 .iov_len = header.string_bytes_len,
37413741 },
37423742 .{
3743 .iov_base = @ptrCast([*]u8, zir.extra.ptr),
3743 .iov_base = @as([*]u8, @ptrCast(zir.extra.ptr)),
37443744 .iov_len = header.extra_len * 4,
37453745 },
37463746 };
......@@ -3753,7 +3753,7 @@ fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File)
37533753 const tags = zir.instructions.items(.tag);
37543754 for (zir.instructions.items(.data), 0..) |*data, i| {
37553755 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));
37573757 as_struct.* = .{
37583758 .safety_tag = @intFromEnum(union_tag),
37593759 .data = safety_buffer[i],
......@@ -4394,7 +4394,7 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
43944394 const struct_obj = mod.structPtr(struct_index);
43954395 struct_obj.zir_index = main_struct_inst;
43964396 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));
43984398 struct_obj.is_tuple = small.is_tuple;
43994399
44004400 var sema_arena = std.heap.ArenaAllocator.init(gpa);
......@@ -5051,13 +5051,13 @@ pub fn scanNamespace(
50515051 cur_bit_bag = zir.extra[bit_bag_index];
50525052 bit_bag_index += 1;
50535053 }
5054 const flags = @truncate(u4, cur_bit_bag);
5054 const flags = @as(u4, @truncate(cur_bit_bag));
50555055 cur_bit_bag >>= 4;
50565056
50575057 const decl_sub_index = extra_index;
50585058 extra_index += 8; // src_hash(4) + line(1) + name(1) + value(1) + doc_comment(1)
5059 extra_index += @truncate(u1, flags >> 2); // Align
5060 extra_index += @as(u2, @truncate(u1, flags >> 3)) * 2; // Link section or address space, consists of 2 Refs
5059 extra_index += @as(u1, @truncate(flags >> 2)); // Align
5060 extra_index += @as(u2, @as(u1, @truncate(flags >> 3))) * 2; // Link section or address space, consists of 2 Refs
50615061
50625062 try scanDecl(&scan_decl_iter, decl_sub_index, flags);
50635063 }
......@@ -5195,7 +5195,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
51955195 new_decl.is_exported = is_exported;
51965196 new_decl.has_align = has_align;
51975197 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));
51995199 new_decl.alive = true; // This Decl corresponds to an AST node and therefore always alive.
52005200 return;
52015201 }
......@@ -5229,7 +5229,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
52295229 decl.kind = kind;
52305230 decl.has_align = has_align;
52315231 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));
52335233 if (decl.getOwnedFunctionIndex(mod) != .none) {
52345234 switch (comp.bin_file.tag) {
52355235 .coff, .elf, .macho, .plan9 => {
......@@ -5481,7 +5481,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: Fn.Index, arena: Allocator) SemaE
54815481 // This could be a generic function instantiation, however, in which case we need to
54825482 // map the comptime parameters to constant values and only emit arg AIR instructions
54835483 // 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));
54855485 try inner_block.instructions.ensureTotalCapacityPrecise(gpa, runtime_params_len);
54865486 try sema.air_instructions.ensureUnusedCapacity(gpa, fn_info.total_params_len * 2); // * 2 for the `addType`
54875487 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
55245524 continue;
55255525 }
55265526 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));
55285528 inner_block.instructions.appendAssumeCapacity(arg_index);
55295529 sema.air_instructions.appendAssumeCapacity(.{
55305530 .tag = .arg,
55315531 .data = .{ .arg = .{
55325532 .ty = air_ty,
5533 .src_index = @intCast(u32, total_param_index),
5533 .src_index = @as(u32, @intCast(total_param_index)),
55345534 } },
55355535 });
55365536 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
55935593 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +
55945594 inner_block.instructions.items.len);
55955595 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)),
55975597 });
55985598 sema.air_extra.appendSliceAssumeCapacity(inner_block.instructions.items);
55995599 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
56715671 }
56725672 const ptr = try mod.allocated_namespaces.addOne(mod.gpa);
56735673 ptr.* = initialization;
5674 return @enumFromInt(Namespace.Index, mod.allocated_namespaces.len - 1);
5674 return @as(Namespace.Index, @enumFromInt(mod.allocated_namespaces.len - 1));
56755675}
56765676
56775677pub fn destroyNamespace(mod: *Module, index: Namespace.Index) void {
......@@ -5729,7 +5729,7 @@ pub fn allocateNewDecl(
57295729 }
57305730 break :d .{
57315731 .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)),
57335733 };
57345734 };
57355735
......@@ -5767,7 +5767,7 @@ pub fn getErrorValue(
57675767 name: InternPool.NullTerminatedString,
57685768) Allocator.Error!ErrorInt {
57695769 const gop = try mod.global_error_set.getOrPut(mod.gpa, name);
5770 return @intCast(ErrorInt, gop.index);
5770 return @as(ErrorInt, @intCast(gop.index));
57715771}
57725772
57735773pub fn getErrorValueFromSlice(
......@@ -6139,7 +6139,7 @@ pub fn paramSrc(
61396139 if (i == param_i) {
61406140 if (param.anytype_ellipsis3) |some| {
61416141 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)) };
61436143 }
61446144 return .{ .node_offset_param = decl.nodeIndexToRelative(param.type_expr) };
61456145 }
......@@ -6892,11 +6892,11 @@ pub fn unionValue(mod: *Module, union_ty: Type, tag: Value, val: Value) Allocato
68926892/// losing data if the representation wasn't correct.
68936893pub fn floatValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {
68946894 const storage: InternPool.Key.Float.Storage = switch (ty.floatBits(mod.getTarget())) {
6895 16 => .{ .f16 = @floatCast(f16, x) },
6896 32 => .{ .f32 = @floatCast(f32, x) },
6897 64 => .{ .f64 = @floatCast(f64, x) },
6898 80 => .{ .f80 = @floatCast(f80, x) },
6899 128 => .{ .f128 = @floatCast(f128, x) },
6895 16 => .{ .f16 = @as(f16, @floatCast(x)) },
6896 32 => .{ .f32 = @as(f32, @floatCast(x)) },
6897 64 => .{ .f64 = @as(f64, @floatCast(x)) },
6898 80 => .{ .f80 = @as(f80, @floatCast(x)) },
6899 128 => .{ .f128 = @as(f128, @floatCast(x)) },
69006900 else => unreachable,
69016901 };
69026902 const i = try intern(mod, .{ .float = .{
......@@ -6956,18 +6956,18 @@ pub fn intBitsForValue(mod: *Module, val: Value, sign: bool) u16 {
69566956 assert(sign);
69576957 // Protect against overflow in the following negation.
69586958 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;
69606960 },
69616961 .u64 => |x| {
69626962 return Type.smallestUnsignedBits(x) + @intFromBool(sign);
69636963 },
69646964 .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
69676967 // Zero is still a possibility, in which case unsigned is fine
69686968 if (big.eqZero()) return 0;
69696969
6970 return @intCast(u16, big.bitCountTwosComp());
6970 return @as(u16, @intCast(big.bitCountTwosComp()));
69716971 },
69726972 .lazy_align => |lazy_ty| {
69736973 return Type.smallestUnsignedBits(lazy_ty.toType().abiAlignment(mod)) + @intFromBool(sign);
src/Package.zig+3-3
......@@ -390,10 +390,10 @@ const Report = struct {
390390 .src_loc = try eb.addSourceLocation(.{
391391 .src_path = try eb.addString(file_path),
392392 .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)),
394394 .span_main = token_starts[msg.tok] + msg.off,
395 .line = @intCast(u32, start_loc.line),
396 .column = @intCast(u32, start_loc.column),
395 .line = @as(u32, @intCast(start_loc.line)),
396 .column = @as(u32, @intCast(start_loc.column)),
397397 .source_line = try eb.addString(ast.source[start_loc.line_start..start_loc.line_end]),
398398 }),
399399 .notes_len = notes_len,
src/Sema.zig+736-557
......@@ -212,7 +212,7 @@ pub const InstMap = struct {
212212 while (true) {
213213 const extra_capacity = better_capacity / 2 + 16;
214214 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));
216216 if (better_start <= start and end < better_capacity + better_start)
217217 break;
218218 }
......@@ -225,7 +225,7 @@ pub const InstMap = struct {
225225
226226 allocator.free(map.items);
227227 map.items = new_items;
228 map.start = @intCast(Zir.Inst.Index, better_start);
228 map.start = @as(Zir.Inst.Index, @intCast(better_start));
229229 }
230230};
231231
......@@ -619,7 +619,7 @@ pub const Block = struct {
619619 const sema = block.sema;
620620 const ty_ref = try sema.addType(aggregate_ty);
621621 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));
623623 sema.appendRefsAssumeCapacity(elements);
624624
625625 return block.addInst(.{
......@@ -660,7 +660,7 @@ pub const Block = struct {
660660 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
661661 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));
664664 sema.air_instructions.appendAssumeCapacity(inst);
665665 block.instructions.appendAssumeCapacity(result_index);
666666 return result_index;
......@@ -678,7 +678,7 @@ pub const Block = struct {
678678
679679 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));
682682 sema.air_instructions.appendAssumeCapacity(inst);
683683
684684 try block.instructions.insert(gpa, index, result_index);
......@@ -960,6 +960,7 @@ fn analyzeBodyInner(
960960 .elem_val => try sema.zirElemVal(block, inst),
961961 .elem_val_node => try sema.zirElemValNode(block, inst),
962962 .elem_type_index => try sema.zirElemTypeIndex(block, inst),
963 .elem_type => try sema.zirElemType(block, inst),
963964 .enum_literal => try sema.zirEnumLiteral(block, inst),
964965 .int_from_enum => try sema.zirIntFromEnum(block, inst),
965966 .enum_from_int => try sema.zirEnumFromInt(block, inst),
......@@ -1044,7 +1045,6 @@ fn analyzeBodyInner(
10441045 .int_cast => try sema.zirIntCast(block, inst),
10451046 .ptr_cast => try sema.zirPtrCast(block, inst),
10461047 .truncate => try sema.zirTruncate(block, inst),
1047 .align_cast => try sema.zirAlignCast(block, inst),
10481048 .has_decl => try sema.zirHasDecl(block, inst),
10491049 .has_field => try sema.zirHasField(block, inst),
10501050 .byte_swap => try sema.zirByteSwap(block, inst),
......@@ -1172,13 +1172,12 @@ fn analyzeBodyInner(
11721172 .reify => try sema.zirReify( block, extended, inst),
11731173 .builtin_async_call => try sema.zirBuiltinAsyncCall( block, extended),
11741174 .cmpxchg => try sema.zirCmpxchg( block, extended),
1175 .addrspace_cast => try sema.zirAddrSpaceCast( block, extended),
11761175 .c_va_arg => try sema.zirCVaArg( block, extended),
11771176 .c_va_copy => try sema.zirCVaCopy( block, extended),
11781177 .c_va_end => try sema.zirCVaEnd( block, extended),
11791178 .c_va_start => try sema.zirCVaStart( block, extended),
1180 .const_cast, => try sema.zirConstCast( block, extended),
1181 .volatile_cast, => try sema.zirVolatileCast( block, extended),
1179 .ptr_cast_full => try sema.zirPtrCastFull( block, extended),
1180 .ptr_cast_no_dest => try sema.zirPtrCastNoDest( block, extended),
11821181 .work_item_id => try sema.zirWorkItem( block, extended, extended.opcode),
11831182 .work_group_size => try sema.zirWorkItem( block, extended, extended.opcode),
11841183 .work_group_id => try sema.zirWorkItem( block, extended, extended.opcode),
......@@ -1764,7 +1763,7 @@ pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref {
17641763 const i = @intFromEnum(zir_ref);
17651764 // First section of indexes correspond to a set number of constant values.
17661765 // We intentionally map the same indexes to the same values between ZIR and AIR.
1767 if (i < InternPool.static_len) return @enumFromInt(Air.Inst.Ref, i);
1766 if (i < InternPool.static_len) return @as(Air.Inst.Ref, @enumFromInt(i));
17681767 // The last section of indexes refers to the map of ZIR => AIR.
17691768 const inst = sema.inst_map.get(i - InternPool.static_len).?;
17701769 if (inst == .generic_poison) return error.GenericPoison;
......@@ -1821,6 +1820,24 @@ pub fn resolveType(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Ins
18211820 return ty;
18221821}
18231822
1823fn resolveCastDestType(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref, builtin_name: []const u8) !Type {
1824 return sema.resolveType(block, src, zir_ref) catch |err| switch (err) {
1825 error.GenericPoison => {
1826 // Cast builtins use their result type as the destination type, but
1827 // it could be an anytype argument, which we can't catch in AstGen.
1828 const msg = msg: {
1829 const msg = try sema.errMsg(block, src, "{s} must have a known result type", .{builtin_name});
1830 errdefer msg.destroy(sema.gpa);
1831 try sema.errNote(block, src, msg, "result type is unknown due to anytype parameter", .{});
1832 try sema.errNote(block, src, msg, "use @as to provide explicit result type", .{});
1833 break :msg msg;
1834 };
1835 return sema.failWithOwnedErrorMsg(msg);
1836 },
1837 else => |e| return e,
1838 };
1839}
1840
18241841fn analyzeAsType(
18251842 sema: *Sema,
18261843 block: *Block,
......@@ -2024,7 +2041,7 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime(
20242041 // First section of indexes correspond to a set number of constant values.
20252042 const int = @intFromEnum(inst);
20262043 if (int < InternPool.static_len) {
2027 return @enumFromInt(InternPool.Index, int).toValue();
2044 return @as(InternPool.Index, @enumFromInt(int)).toValue();
20282045 }
20292046
20302047 const i = int - InternPool.static_len;
......@@ -2413,7 +2430,7 @@ fn analyzeAsAlign(
24132430 air_ref: Air.Inst.Ref,
24142431) !Alignment {
24152432 const alignment_big = try sema.analyzeAsInt(block, src, air_ref, align_ty, "alignment must be comptime-known");
2416 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.
24172434 try sema.validateAlign(block, src, alignment);
24182435 return Alignment.fromNonzeroByteUnits(alignment);
24192436}
......@@ -2720,7 +2737,7 @@ pub fn analyzeStructDecl(
27202737 const struct_obj = mod.structPtr(struct_index);
27212738 const extended = sema.code.instructions.items(.data)[inst].extended;
27222739 assert(extended.opcode == .struct_decl);
2723 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
2740 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
27242741
27252742 struct_obj.known_non_opv = small.known_non_opv;
27262743 if (small.known_comptime_only) {
......@@ -2757,9 +2774,9 @@ fn zirStructDecl(
27572774) CompileError!Air.Inst.Ref {
27582775 const mod = sema.mod;
27592776 const gpa = sema.gpa;
2760 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
2777 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
27612778 const src: LazySrcLoc = if (small.has_src_node) blk: {
2762 const node_offset = @bitCast(i32, sema.code.extra[extended.operand]);
2779 const node_offset = @as(i32, @bitCast(sema.code.extra[extended.operand]));
27632780 break :blk LazySrcLoc.nodeOffset(node_offset);
27642781 } else sema.src;
27652782
......@@ -2920,18 +2937,18 @@ fn zirEnumDecl(
29202937
29212938 const mod = sema.mod;
29222939 const gpa = sema.gpa;
2923 const small = @bitCast(Zir.Inst.EnumDecl.Small, extended.small);
2940 const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small));
29242941 var extra_index: usize = extended.operand;
29252942
29262943 const src: LazySrcLoc = if (small.has_src_node) blk: {
2927 const node_offset = @bitCast(i32, sema.code.extra[extra_index]);
2944 const node_offset = @as(i32, @bitCast(sema.code.extra[extra_index]));
29282945 extra_index += 1;
29292946 break :blk LazySrcLoc.nodeOffset(node_offset);
29302947 } else sema.src;
29312948 const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x };
29322949
29332950 const tag_type_ref = if (small.has_tag_type) blk: {
2934 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]));
29352952 extra_index += 1;
29362953 break :blk tag_type_ref;
29372954 } else .none;
......@@ -3091,7 +3108,7 @@ fn zirEnumDecl(
30913108 cur_bit_bag = sema.code.extra[bit_bag_index];
30923109 bit_bag_index += 1;
30933110 }
3094 const has_tag_value = @truncate(u1, cur_bit_bag) != 0;
3111 const has_tag_value = @as(u1, @truncate(cur_bit_bag)) != 0;
30953112 cur_bit_bag >>= 1;
30963113
30973114 const field_name_zir = sema.code.nullTerminatedString(sema.code.extra[extra_index]);
......@@ -3114,7 +3131,7 @@ fn zirEnumDecl(
31143131 }
31153132
31163133 const tag_overflow = if (has_tag_value) overflow: {
3117 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]));
31183135 extra_index += 1;
31193136 const tag_inst = try sema.resolveInst(tag_val_ref);
31203137 last_tag_val = sema.resolveConstValue(block, .unneeded, tag_inst, "") catch |err| switch (err) {
......@@ -3196,11 +3213,11 @@ fn zirUnionDecl(
31963213
31973214 const mod = sema.mod;
31983215 const gpa = sema.gpa;
3199 const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small);
3216 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));
32003217 var extra_index: usize = extended.operand;
32013218
32023219 const src: LazySrcLoc = if (small.has_src_node) blk: {
3203 const node_offset = @bitCast(i32, sema.code.extra[extra_index]);
3220 const node_offset = @as(i32, @bitCast(sema.code.extra[extra_index]));
32043221 extra_index += 1;
32053222 break :blk LazySrcLoc.nodeOffset(node_offset);
32063223 } else sema.src;
......@@ -3281,11 +3298,11 @@ fn zirOpaqueDecl(
32813298 defer tracy.end();
32823299
32833300 const mod = sema.mod;
3284 const small = @bitCast(Zir.Inst.OpaqueDecl.Small, extended.small);
3301 const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small));
32853302 var extra_index: usize = extended.operand;
32863303
32873304 const src: LazySrcLoc = if (small.has_src_node) blk: {
3288 const node_offset = @bitCast(i32, sema.code.extra[extra_index]);
3305 const node_offset = @as(i32, @bitCast(sema.code.extra[extra_index]));
32893306 extra_index += 1;
32903307 break :blk LazySrcLoc.nodeOffset(node_offset);
32913308 } else sema.src;
......@@ -3352,7 +3369,7 @@ fn zirErrorSetDecl(
33523369 var names: Module.Fn.InferredErrorSet.NameMap = .{};
33533370 try names.ensureUnusedCapacity(sema.arena, extra.data.fields_len);
33543371
3355 var extra_index = @intCast(u32, extra.end);
3372 var extra_index = @as(u32, @intCast(extra.end));
33563373 const extra_index_end = extra_index + (extra.data.fields_len * 2);
33573374 while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string
33583375 const str_index = sema.code.extra[extra_index];
......@@ -3552,18 +3569,18 @@ fn zirAllocExtended(
35523569 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);
35533570 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node };
35543571 const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node };
3555 const small = @bitCast(Zir.Inst.AllocExtended.Small, extended.small);
3572 const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small));
35563573
35573574 var extra_index: usize = extra.end;
35583575
35593576 const var_ty: Type = if (small.has_type) blk: {
3560 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]));
35613578 extra_index += 1;
35623579 break :blk try sema.resolveType(block, ty_src, type_ref);
35633580 } else undefined;
35643581
35653582 const alignment = if (small.has_align) blk: {
3566 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]));
35673584 extra_index += 1;
35683585 const alignment = try sema.resolveAlign(block, align_src, align_ref);
35693586 break :blk alignment;
......@@ -3581,7 +3598,7 @@ fn zirAllocExtended(
35813598 .is_const = small.is_const,
35823599 } },
35833600 });
3584 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
3601 return Air.indexToRef(@as(u32, @intCast(sema.air_instructions.len - 1)));
35853602 }
35863603 }
35873604
......@@ -3713,7 +3730,7 @@ fn zirAllocInferredComptime(
37133730 .is_const = is_const,
37143731 } },
37153732 });
3716 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
3733 return Air.indexToRef(@as(u32, @intCast(sema.air_instructions.len - 1)));
37173734}
37183735
37193736fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -3778,7 +3795,7 @@ fn zirAllocInferred(
37783795 .is_const = is_const,
37793796 } },
37803797 });
3781 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
3798 return Air.indexToRef(@as(u32, @intCast(sema.air_instructions.len - 1)));
37823799 }
37833800
37843801 const result_index = try block.addInstAsIndex(.{
......@@ -4020,7 +4037,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
40204037 .data = .{ .ty_pl = .{
40214038 .ty = ty_inst,
40224039 .payload = sema.addExtraAssumeCapacity(Air.Block{
4023 .body_len = @intCast(u32, replacement_block.instructions.items.len),
4040 .body_len = @as(u32, @intCast(replacement_block.instructions.items.len)),
40244041 }),
40254042 } },
40264043 });
......@@ -4104,7 +4121,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
41044121
41054122 // First pass to look for comptime values.
41064123 for (args, 0..) |zir_arg, i_usize| {
4107 const i = @intCast(u32, i_usize);
4124 const i = @as(u32, @intCast(i_usize));
41084125 runtime_arg_lens[i] = .none;
41094126 if (zir_arg == .none) continue;
41104127 const object = try sema.resolveInst(zir_arg);
......@@ -4175,7 +4192,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
41754192 const msg = try sema.errMsg(block, src, "unbounded for loop", .{});
41764193 errdefer msg.destroy(gpa);
41774194 for (args, 0..) |zir_arg, i_usize| {
4178 const i = @intCast(u32, i_usize);
4195 const i = @as(u32, @intCast(i_usize));
41794196 if (zir_arg == .none) continue;
41804197 const object = try sema.resolveInst(zir_arg);
41814198 const object_ty = sema.typeOf(object);
......@@ -4418,7 +4435,7 @@ fn validateUnionInit(
44184435 }
44194436
44204437 const tag_ty = union_ty.unionTagTypeHypothetical(mod);
4421 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).?));
44224439 const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index);
44234440
44244441 if (init_val) |val| {
......@@ -4530,9 +4547,9 @@ fn validateStructInit(
45304547
45314548 const field_src = init_src; // TODO better source location
45324549 const default_field_ptr = if (struct_ty.isTuple(mod))
4533 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)
45344551 else
4535 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);
45364553 const init = try sema.addConstant(default_val);
45374554 try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store);
45384555 }
......@@ -4712,9 +4729,9 @@ fn validateStructInit(
47124729
47134730 const field_src = init_src; // TODO better source location
47144731 const default_field_ptr = if (struct_ty.isTuple(mod))
4715 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)
47164733 else
4717 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);
47184735 const init = try sema.addConstant(field_values[i].toValue());
47194736 try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store);
47204737 }
......@@ -5148,7 +5165,7 @@ fn storeToInferredAllocComptime(
51485165fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
51495166 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
51505167 const src = inst_data.src();
5151 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")));
51525169 sema.branch_quota = @max(sema.branch_quota, quota);
51535170}
51545171
......@@ -5371,7 +5388,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
53715388 // Reserve space for a Loop instruction so that generated Break instructions can
53725389 // point to it, even if it doesn't end up getting used because the code ends up being
53735390 // comptime evaluated.
5374 const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);
5391 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
53755392 const loop_inst = block_inst + 1;
53765393 try sema.air_instructions.ensureUnusedCapacity(gpa, 2);
53775394 sema.air_instructions.appendAssumeCapacity(.{
......@@ -5419,7 +5436,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
54195436
54205437 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + loop_block_len);
54215438 sema.air_instructions.items(.data)[loop_inst].ty_pl.payload = sema.addExtraAssumeCapacity(
5422 Air.Block{ .body_len = @intCast(u32, loop_block_len) },
5439 Air.Block{ .body_len = @as(u32, @intCast(loop_block_len)) },
54235440 );
54245441 sema.air_extra.appendSliceAssumeCapacity(loop_block.instructions.items);
54255442 }
......@@ -5569,7 +5586,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
55695586 // Reserve space for a Block instruction so that generated Break instructions can
55705587 // point to it, even if it doesn't end up getting used because the code ends up being
55715588 // comptime evaluated or is an unlabeled block.
5572 const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);
5589 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
55735590 try sema.air_instructions.append(gpa, .{
55745591 .tag = .block,
55755592 .data = undefined,
......@@ -5716,7 +5733,7 @@ fn analyzeBlockBody(
57165733 sema.air_instructions.items(.data)[merges.block_inst] = .{ .ty_pl = .{
57175734 .ty = ty_inst,
57185735 .payload = sema.addExtraAssumeCapacity(Air.Block{
5719 .body_len = @intCast(u32, child_block.instructions.items.len),
5736 .body_len = @as(u32, @intCast(child_block.instructions.items.len)),
57205737 }),
57215738 } };
57225739 sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items);
......@@ -5744,11 +5761,11 @@ fn analyzeBlockBody(
57445761
57455762 // Convert the br instruction to a block instruction that has the coercion
57465763 // and then a new br inside that returns the coerced instruction.
5747 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));
57485765 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +
57495766 sub_block_len);
57505767 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
5751 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));
57525769
57535770 sema.air_instructions.items(.tag)[br] = .block;
57545771 sema.air_instructions.items(.data)[br] = .{ .ty_pl = .{
......@@ -6097,7 +6114,7 @@ fn addDbgVar(
60976114 try sema.queueFullTypeResolution(operand_ty);
60986115
60996116 // Add the name to the AIR.
6100 const name_extra_index = @intCast(u32, sema.air_extra.items.len);
6117 const name_extra_index = @as(u32, @intCast(sema.air_extra.items.len));
61016118 const elements_used = name.len / 4 + 1;
61026119 try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements_used);
61036120 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
......@@ -6297,7 +6314,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
62976314 .tag = .save_err_return_trace_index,
62986315 .data = .{ .ty_pl = .{
62996316 .ty = try sema.addType(stack_trace_ty),
6300 .payload = @intCast(u32, field_index),
6317 .payload = @as(u32, @intCast(field_index)),
63016318 } },
63026319 });
63036320}
......@@ -6369,12 +6386,12 @@ fn popErrorReturnTrace(
63696386 then_block.instructions.items.len + else_block.instructions.items.len +
63706387 @typeInfo(Air.Block).Struct.fields.len + 1); // +1 for the sole .cond_br instruction in the .block
63716388
6372 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));
63736390 try sema.air_instructions.append(gpa, .{ .tag = .cond_br, .data = .{ .pl_op = .{
63746391 .operand = is_non_error_inst,
63756392 .payload = sema.addExtraAssumeCapacity(Air.CondBr{
6376 .then_body_len = @intCast(u32, then_block.instructions.items.len),
6377 .else_body_len = @intCast(u32, else_block.instructions.items.len),
6393 .then_body_len = @as(u32, @intCast(then_block.instructions.items.len)),
6394 .else_body_len = @as(u32, @intCast(else_block.instructions.items.len)),
63786395 }),
63796396 } } });
63806397 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);
......@@ -6405,7 +6422,7 @@ fn zirCall(
64056422 const extra = sema.code.extraData(ExtraType, inst_data.payload_index);
64066423 const args_len = extra.data.flags.args_len;
64076424
6408 const modifier = @enumFromInt(std.builtin.CallModifier, extra.data.flags.packed_modifier);
6425 const modifier = @as(std.builtin.CallModifier, @enumFromInt(extra.data.flags.packed_modifier));
64096426 const ensure_result_used = extra.data.flags.ensure_result_used;
64106427 const pop_error_return_trace = extra.data.flags.pop_error_return_trace;
64116428
......@@ -6443,7 +6460,7 @@ fn zirCall(
64436460 const args_body = sema.code.extra[extra.end..];
64446461
64456462 var input_is_error = false;
6446 const block_index = @intCast(Air.Inst.Index, block.instructions.items.len);
6463 const block_index = @as(Air.Inst.Index, @intCast(block.instructions.items.len));
64476464
64486465 const fn_params_len = mod.typeToFunc(func_ty).?.param_types.len;
64496466 const parent_comptime = block.is_comptime;
......@@ -6460,7 +6477,7 @@ fn zirCall(
64606477
64616478 // Generate args to comptime params in comptime block.
64626479 defer block.is_comptime = parent_comptime;
6463 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)))) {
64646481 block.is_comptime = true;
64656482 // TODO set comptime_reason
64666483 }
......@@ -6516,7 +6533,7 @@ fn zirCall(
65166533 .tag = .save_err_return_trace_index,
65176534 .data = .{ .ty_pl = .{
65186535 .ty = try sema.addType(stack_trace_ty),
6519 .payload = @intCast(u32, field_index),
6536 .payload = @as(u32, @intCast(field_index)),
65206537 } },
65216538 });
65226539
......@@ -6792,7 +6809,7 @@ fn analyzeCall(
67926809 // set to in the `Block`.
67936810 // This block instruction will be used to capture the return value from the
67946811 // inlined function.
6795 const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);
6812 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
67966813 try sema.air_instructions.append(gpa, .{
67976814 .tag = .block,
67986815 .data = undefined,
......@@ -7060,7 +7077,7 @@ fn analyzeCall(
70607077 if (i < fn_params_len) {
70617078 const opts: CoerceOpts = .{ .param_src = .{
70627079 .func_inst = func,
7063 .param_i = @intCast(u32, i),
7080 .param_i = @as(u32, @intCast(i)),
70647081 } };
70657082 const param_ty = mod.typeToFunc(func_ty).?.param_types[i].toType();
70667083 args[i] = sema.analyzeCallArg(
......@@ -7119,7 +7136,7 @@ fn analyzeCall(
71197136 .data = .{ .pl_op = .{
71207137 .operand = func,
71217138 .payload = sema.addExtraAssumeCapacity(Air.Call{
7122 .args_len = @intCast(u32, args.len),
7139 .args_len = @as(u32, @intCast(args.len)),
71237140 }),
71247141 } },
71257142 });
......@@ -7228,7 +7245,7 @@ fn analyzeInlineCallArg(
72287245 }
72297246 const casted_arg = sema.coerceExtra(arg_block, param_ty.toType(), uncasted_arg, arg_src, .{ .param_src = .{
72307247 .func_inst = func_inst,
7231 .param_i = @intCast(u32, arg_i.*),
7248 .param_i = @as(u32, @intCast(arg_i.*)),
72327249 } }) catch |err| switch (err) {
72337250 error.NotCoercible => unreachable,
72347251 else => |e| return e,
......@@ -7402,14 +7419,14 @@ fn instantiateGenericCall(
74027419 var is_anytype = false;
74037420 switch (zir_tags[inst]) {
74047421 .param => {
7405 is_comptime = generic_func_ty_info.paramIsComptime(@intCast(u5, arg_i));
7422 is_comptime = generic_func_ty_info.paramIsComptime(@as(u5, @intCast(arg_i)));
74067423 },
74077424 .param_comptime => {
74087425 is_comptime = true;
74097426 },
74107427 .param_anytype => {
74117428 is_anytype = true;
7412 is_comptime = generic_func_ty_info.paramIsComptime(@intCast(u5, arg_i));
7429 is_comptime = generic_func_ty_info.paramIsComptime(@as(u5, @intCast(arg_i)));
74137430 },
74147431 .param_anytype_comptime => {
74157432 is_anytype = true;
......@@ -7571,7 +7588,7 @@ fn instantiateGenericCall(
75717588 // Make a runtime call to the new function, making sure to omit the comptime args.
75727589 const comptime_args = callee.comptime_args.?;
75737590 const func_ty = mod.declPtr(callee.owner_decl).ty;
7574 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));
75757592 const runtime_args = try sema.arena.alloc(Air.Inst.Ref, runtime_args_len);
75767593 {
75777594 var runtime_i: u32 = 0;
......@@ -7721,14 +7738,14 @@ fn resolveGenericInstantiationType(
77217738 var is_anytype = false;
77227739 switch (zir_tags[inst]) {
77237740 .param => {
7724 is_comptime = generic_func_ty_info.paramIsComptime(@intCast(u5, arg_i));
7741 is_comptime = generic_func_ty_info.paramIsComptime(@as(u5, @intCast(arg_i)));
77257742 },
77267743 .param_comptime => {
77277744 is_comptime = true;
77287745 },
77297746 .param_anytype => {
77307747 is_anytype = true;
7731 is_comptime = generic_func_ty_info.paramIsComptime(@intCast(u5, arg_i));
7748 is_comptime = generic_func_ty_info.paramIsComptime(@as(u5, @intCast(arg_i)));
77327749 },
77337750 .param_anytype_comptime => {
77347751 is_anytype = true;
......@@ -7762,7 +7779,7 @@ fn resolveGenericInstantiationType(
77627779 .tag = .arg,
77637780 .data = .{ .arg = .{
77647781 .ty = try child_sema.addType(arg_ty),
7765 .src_index = @intCast(u32, arg_i),
7782 .src_index = @as(u32, @intCast(arg_i)),
77667783 } },
77677784 });
77687785 child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg);
......@@ -7782,7 +7799,7 @@ fn resolveGenericInstantiationType(
77827799 const new_func = new_func_val.getFunctionIndex(mod).unwrap().?;
77837800 assert(new_func == new_module_func);
77847801
7785 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));
77867803 const monomorphed_args = try mod.monomorphed_func_keys.addManyAsSlice(gpa, monomorphed_args_len);
77877804 var monomorphed_arg_i: u32 = 0;
77887805 try mod.monomorphed_funcs.ensureUnusedCapacityContext(gpa, monomorphed_args_len + 1, .{ .mod = mod });
......@@ -7794,14 +7811,14 @@ fn resolveGenericInstantiationType(
77947811 var is_anytype = false;
77957812 switch (zir_tags[inst]) {
77967813 .param => {
7797 is_comptime = generic_func_ty_info.paramIsComptime(@intCast(u5, arg_i));
7814 is_comptime = generic_func_ty_info.paramIsComptime(@as(u5, @intCast(arg_i)));
77987815 },
77997816 .param_comptime => {
78007817 is_comptime = true;
78017818 },
78027819 .param_anytype => {
78037820 is_anytype = true;
7804 is_comptime = generic_func_ty_info.paramIsComptime(@intCast(u5, arg_i));
7821 is_comptime = generic_func_ty_info.paramIsComptime(@as(u5, @intCast(arg_i)));
78057822 },
78067823 .param_anytype_comptime => {
78077824 is_anytype = true;
......@@ -7953,13 +7970,21 @@ fn zirElemTypeIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
79537970 }
79547971}
79557972
7973fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7974 const mod = sema.mod;
7975 const un_node = sema.code.instructions.items(.data)[inst].un_node;
7976 const ptr_ty = try sema.resolveType(block, .unneeded, un_node.operand);
7977 assert(ptr_ty.zigTypeTag(mod) == .Pointer); // validated by a previous instruction
7978 return sema.addType(ptr_ty.childType(mod));
7979}
7980
79567981fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
79577982 const mod = sema.mod;
79587983 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
79597984 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
79607985 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
79617986 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
7962 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")));
79637988 const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs);
79647989 try sema.checkVectorElemType(block, elem_type_src, elem_type);
79657990 const vector_type = try mod.vectorType(.{
......@@ -8115,7 +8140,7 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
81158140 switch (names.len) {
81168141 0 => return sema.addConstant(try mod.intValue(Type.err_int, 0)),
81178142 1 => {
8118 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]).?));
81198144 return sema.addIntUnsigned(Type.err_int, int);
81208145 },
81218146 else => {},
......@@ -8278,13 +8303,12 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
82788303 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
82798304 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
82808305 const src = inst_data.src();
8281 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
8282 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
8283 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
8306 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
8307 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, "@enumFromInt");
82848308 const operand = try sema.resolveInst(extra.rhs);
82858309
82868310 if (dest_ty.zigTypeTag(mod) != .Enum) {
8287 return sema.fail(block, dest_ty_src, "expected enum, found '{}'", .{dest_ty.fmt(mod)});
8311 return sema.fail(block, src, "expected enum, found '{}'", .{dest_ty.fmt(mod)});
82888312 }
82898313 _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand));
82908314
......@@ -8703,7 +8727,7 @@ fn zirFunc(
87038727 const ret_ty: Type = switch (extra.data.ret_body_len) {
87048728 0 => Type.void,
87058729 1 => blk: {
8706 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]));
87078731 extra_index += 1;
87088732 if (sema.resolveType(block, ret_ty_src, ret_ty_ref)) |ret_ty| {
87098733 break :blk ret_ty;
......@@ -8940,7 +8964,7 @@ fn funcCommon(
89408964 for (param_types, block.params.items, 0..) |*dest_param_ty, param, i| {
89418965 const is_noalias = blk: {
89428966 const index = std.math.cast(u5, i) orelse break :blk false;
8943 break :blk @truncate(u1, noalias_bits >> index) != 0;
8967 break :blk @as(u1, @truncate(noalias_bits >> index)) != 0;
89448968 };
89458969 dest_param_ty.* = param.ty.toIntern();
89468970 sema.analyzeParameter(
......@@ -9175,8 +9199,8 @@ fn funcCommon(
91759199 .hash = hash,
91769200 .lbrace_line = src_locs.lbrace_line,
91779201 .rbrace_line = src_locs.rbrace_line,
9178 .lbrace_column = @truncate(u16, src_locs.columns),
9179 .rbrace_column = @truncate(u16, src_locs.columns >> 16),
9202 .lbrace_column = @as(u16, @truncate(src_locs.columns)),
9203 .rbrace_column = @as(u16, @truncate(src_locs.columns >> 16)),
91809204 .branch_quota = default_branch_quota,
91819205 .is_noinline = is_noinline,
91829206 };
......@@ -9201,7 +9225,7 @@ fn analyzeParameter(
92019225 const mod = sema.mod;
92029226 const requires_comptime = try sema.typeRequiresComptime(param.ty);
92039227 if (param.is_comptime or requires_comptime) {
9204 comptime_bits.* |= @as(u32, 1) << @intCast(u5, i); // TODO: handle cast error
9228 comptime_bits.* |= @as(u32, 1) << @as(u5, @intCast(i)); // TODO: handle cast error
92059229 }
92069230 const this_generic = param.ty.isGenericPoison();
92079231 is_generic.* = is_generic.* or this_generic;
......@@ -9387,7 +9411,7 @@ fn zirParam(
93879411 sema.inst_map.putAssumeCapacityNoClobber(inst, result);
93889412 } else {
93899413 // Otherwise we need a dummy runtime instruction.
9390 const result_index = @intCast(Air.Inst.Index, sema.air_instructions.len);
9414 const result_index = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
93919415 try sema.air_instructions.append(sema.gpa, .{
93929416 .tag = .alloc,
93939417 .data = .{ .ty = param_ty },
......@@ -9572,14 +9596,14 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
95729596 defer tracy.end();
95739597
95749598 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9575 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
9576 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
9599 const src = inst_data.src();
9600 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
95779601 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
95789602
9579 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
9603 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, "@intCast");
95809604 const operand = try sema.resolveInst(extra.rhs);
95819605
9582 return sema.intCast(block, inst_data.src(), dest_ty, dest_ty_src, operand, operand_src, true);
9606 return sema.intCast(block, inst_data.src(), dest_ty, src, operand, operand_src, true);
95839607}
95849608
95859609fn intCast(
......@@ -9733,11 +9757,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
97339757
97349758 const mod = sema.mod;
97359759 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9736 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
9737 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
9760 const src = inst_data.src();
9761 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
97389762 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
97399763
9740 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
9764 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, "@bitCast");
97419765 const operand = try sema.resolveInst(extra.rhs);
97429766 const operand_ty = sema.typeOf(operand);
97439767 switch (dest_ty.zigTypeTag(mod)) {
......@@ -9756,14 +9780,14 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
97569780 .Type,
97579781 .Undefined,
97589782 .Void,
9759 => return sema.fail(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)}),
9783 => return sema.fail(block, src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)}),
97609784
97619785 .Enum => {
97629786 const msg = msg: {
9763 const msg = try sema.errMsg(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});
9787 const msg = try sema.errMsg(block, src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});
97649788 errdefer msg.destroy(sema.gpa);
97659789 switch (operand_ty.zigTypeTag(mod)) {
9766 .Int, .ComptimeInt => try sema.errNote(block, dest_ty_src, msg, "use @enumFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),
9790 .Int, .ComptimeInt => try sema.errNote(block, src, msg, "use @enumFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),
97679791 else => {},
97689792 }
97699793
......@@ -9774,11 +9798,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
97749798
97759799 .Pointer => {
97769800 const msg = msg: {
9777 const msg = try sema.errMsg(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});
9801 const msg = try sema.errMsg(block, src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});
97789802 errdefer msg.destroy(sema.gpa);
97799803 switch (operand_ty.zigTypeTag(mod)) {
9780 .Int, .ComptimeInt => try sema.errNote(block, dest_ty_src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),
9781 .Pointer => try sema.errNote(block, dest_ty_src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}),
9804 .Int, .ComptimeInt => try sema.errNote(block, src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),
9805 .Pointer => try sema.errNote(block, src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}),
97829806 else => {},
97839807 }
97849808
......@@ -9792,7 +9816,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
97929816 .Union => "union",
97939817 else => unreachable,
97949818 };
9795 return sema.fail(block, dest_ty_src, "cannot @bitCast to '{}'; {s} does not have a guaranteed in-memory layout", .{
9819 return sema.fail(block, src, "cannot @bitCast to '{}'; {s} does not have a guaranteed in-memory layout", .{
97969820 dest_ty.fmt(mod), container,
97979821 });
97989822 },
......@@ -9876,11 +9900,11 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
98769900
98779901 const mod = sema.mod;
98789902 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9879 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
9880 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
9903 const src = inst_data.src();
9904 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
98819905 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
98829906
9883 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
9907 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, "@floatCast");
98849908 const operand = try sema.resolveInst(extra.rhs);
98859909
98869910 const target = mod.getTarget();
......@@ -9889,7 +9913,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
98899913 .Float => false,
98909914 else => return sema.fail(
98919915 block,
9892 dest_ty_src,
9916 src,
98939917 "expected float type, found '{}'",
98949918 .{dest_ty.fmt(mod)},
98959919 ),
......@@ -10263,7 +10287,7 @@ const SwitchProngAnalysis = struct {
1026310287 if (inline_case_capture != .none) {
1026410288 const item_val = sema.resolveConstValue(block, .unneeded, inline_case_capture, "") catch unreachable;
1026510289 if (operand_ty.zigTypeTag(mod) == .Union) {
10266 const field_index = @intCast(u32, operand_ty.unionTagFieldIndex(item_val, mod).?);
10290 const field_index = @as(u32, @intCast(operand_ty.unionTagFieldIndex(item_val, mod).?));
1026710291 const union_obj = mod.typeToUnion(operand_ty).?;
1026810292 const field_ty = union_obj.fields.values()[field_index].ty;
1026910293 if (capture_byref) {
......@@ -10322,13 +10346,13 @@ const SwitchProngAnalysis = struct {
1032210346 const union_obj = mod.typeToUnion(operand_ty).?;
1032310347 const first_item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], "") catch unreachable;
1032410348
10325 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).?));
1032610350 const first_field = union_obj.fields.values()[first_field_index];
1032710351
1032810352 const field_tys = try sema.arena.alloc(Type, case_vals.len);
1032910353 for (case_vals, field_tys) |item, *field_ty| {
1033010354 const item_val = sema.resolveConstValue(block, .unneeded, item, "") catch unreachable;
10331 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).?));
1033210356 field_ty.* = union_obj.fields.values()[field_idx].ty;
1033310357 }
1033410358
......@@ -10354,7 +10378,7 @@ const SwitchProngAnalysis = struct {
1035410378 const multi_idx = raw_capture_src.multi_capture;
1035510379 const src_decl_ptr = sema.mod.declPtr(block.src_decl);
1035610380 for (case_srcs, 0..) |*case_src, i| {
10357 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)) } };
1035810382 case_src.* = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);
1035910383 }
1036010384 const capture_src = raw_capture_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);
......@@ -10402,7 +10426,7 @@ const SwitchProngAnalysis = struct {
1040210426 const multi_idx = raw_capture_src.multi_capture;
1040310427 const src_decl_ptr = sema.mod.declPtr(block.src_decl);
1040410428 const capture_src = raw_capture_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);
10405 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)) } };
1040610430 const case_src = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);
1040710431 const msg = msg: {
1040810432 const msg = try sema.errMsg(block, capture_src, "capture group with incompatible types", .{});
......@@ -10505,12 +10529,12 @@ const SwitchProngAnalysis = struct {
1050510529 var coerce_block = block.makeSubBlock();
1050610530 defer coerce_block.instructions.deinit(sema.gpa);
1050710531
10508 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]);
1050910533 const coerced = sema.coerce(&coerce_block, capture_ty, uncoerced, .unneeded) catch |err| switch (err) {
1051010534 error.NeededSourceLocation => {
1051110535 const multi_idx = raw_capture_src.multi_capture;
1051210536 const src_decl_ptr = sema.mod.declPtr(block.src_decl);
10513 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)) } };
1051410538 const case_src = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);
1051510539 _ = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);
1051610540 unreachable;
......@@ -10521,7 +10545,7 @@ const SwitchProngAnalysis = struct {
1052110545
1052210546 try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len);
1052310547 cases_extra.appendAssumeCapacity(1); // items_len
10524 cases_extra.appendAssumeCapacity(@intCast(u32, coerce_block.instructions.items.len)); // body_len
10548 cases_extra.appendAssumeCapacity(@as(u32, @intCast(coerce_block.instructions.items.len))); // body_len
1052510549 cases_extra.appendAssumeCapacity(@intFromEnum(case_vals[idx])); // item
1052610550 cases_extra.appendSliceAssumeCapacity(coerce_block.instructions.items); // body
1052710551 }
......@@ -10532,7 +10556,7 @@ const SwitchProngAnalysis = struct {
1053210556 defer coerce_block.instructions.deinit(sema.gpa);
1053310557
1053410558 const first_imc = in_mem_coercible.findFirstSet().?;
10535 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]);
1053610560 const coerced = try coerce_block.addBitCast(capture_ty, uncoerced);
1053710561 _ = try coerce_block.addBr(capture_block_inst, coerced);
1053810562
......@@ -10545,14 +10569,14 @@ const SwitchProngAnalysis = struct {
1054510569 @typeInfo(Air.Block).Struct.fields.len +
1054610570 1);
1054710571
10548 const switch_br_inst = @intCast(u32, sema.air_instructions.len);
10572 const switch_br_inst = @as(u32, @intCast(sema.air_instructions.len));
1054910573 try sema.air_instructions.append(sema.gpa, .{
1055010574 .tag = .switch_br,
1055110575 .data = .{ .pl_op = .{
1055210576 .operand = spa.cond,
1055310577 .payload = sema.addExtraAssumeCapacity(Air.SwitchBr{
10554 .cases_len = @intCast(u32, prong_count),
10555 .else_body_len = @intCast(u32, else_body_len),
10578 .cases_len = @as(u32, @intCast(prong_count)),
10579 .else_body_len = @as(u32, @intCast(else_body_len)),
1055610580 }),
1055710581 } },
1055810582 });
......@@ -10739,7 +10763,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1073910763 .has_tag_capture = false,
1074010764 },
1074110765 .under, .@"else" => blk: {
10742 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]));
1074310767 const extra_body_start = header_extra_index + 1;
1074410768 break :blk .{
1074510769 .body = sema.code.extra[extra_body_start..][0..info.body_len],
......@@ -10809,9 +10833,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1080910833 {
1081010834 var scalar_i: u32 = 0;
1081110835 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
10812 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]));
1081310837 extra_index += 1;
10814 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]));
1081510839 extra_index += 1 + info.body_len;
1081610840
1081710841 case_vals.appendAssumeCapacity(try sema.validateSwitchItemEnum(
......@@ -10832,7 +10856,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1083210856 extra_index += 1;
1083310857 const ranges_len = sema.code.extra[extra_index];
1083410858 extra_index += 1;
10835 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]));
1083610860 extra_index += 1;
1083710861 const items = sema.code.refSlice(extra_index, items_len);
1083810862 extra_index += items_len + info.body_len;
......@@ -10846,7 +10870,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1084610870 item_ref,
1084710871 operand_ty,
1084810872 src_node_offset,
10849 .{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } },
10873 .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } },
1085010874 ));
1085110875 }
1085210876
......@@ -10908,9 +10932,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1090810932 {
1090910933 var scalar_i: u32 = 0;
1091010934 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
10911 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]));
1091210936 extra_index += 1;
10913 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]));
1091410938 extra_index += 1 + info.body_len;
1091510939
1091610940 case_vals.appendAssumeCapacity(try sema.validateSwitchItemError(
......@@ -10930,7 +10954,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1093010954 extra_index += 1;
1093110955 const ranges_len = sema.code.extra[extra_index];
1093210956 extra_index += 1;
10933 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]));
1093410958 extra_index += 1;
1093510959 const items = sema.code.refSlice(extra_index, items_len);
1093610960 extra_index += items_len + info.body_len;
......@@ -10943,7 +10967,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1094310967 item_ref,
1094410968 operand_ty,
1094510969 src_node_offset,
10946 .{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } },
10970 .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } },
1094710971 ));
1094810972 }
1094910973
......@@ -11049,9 +11073,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1104911073 {
1105011074 var scalar_i: u32 = 0;
1105111075 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
11052 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]));
1105311077 extra_index += 1;
11054 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]));
1105511079 extra_index += 1 + info.body_len;
1105611080
1105711081 case_vals.appendAssumeCapacity(try sema.validateSwitchItemInt(
......@@ -11071,7 +11095,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1107111095 extra_index += 1;
1107211096 const ranges_len = sema.code.extra[extra_index];
1107311097 extra_index += 1;
11074 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]));
1107511099 extra_index += 1;
1107611100 const items = sema.code.refSlice(extra_index, items_len);
1107711101 extra_index += items_len;
......@@ -11084,16 +11108,16 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1108411108 item_ref,
1108511109 operand_ty,
1108611110 src_node_offset,
11087 .{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } },
11111 .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } },
1108811112 ));
1108911113 }
1109011114
1109111115 try case_vals.ensureUnusedCapacity(gpa, 2 * ranges_len);
1109211116 var range_i: u32 = 0;
1109311117 while (range_i < ranges_len) : (range_i += 1) {
11094 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]));
1109511119 extra_index += 1;
11096 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]));
1109711121 extra_index += 1;
1109811122
1109911123 const vals = try sema.validateSwitchRange(
......@@ -11144,9 +11168,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1114411168 {
1114511169 var scalar_i: u32 = 0;
1114611170 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
11147 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]));
1114811172 extra_index += 1;
11149 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]));
1115011174 extra_index += 1 + info.body_len;
1115111175
1115211176 case_vals.appendAssumeCapacity(try sema.validateSwitchItemBool(
......@@ -11166,7 +11190,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1116611190 extra_index += 1;
1116711191 const ranges_len = sema.code.extra[extra_index];
1116811192 extra_index += 1;
11169 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]));
1117011194 extra_index += 1;
1117111195 const items = sema.code.refSlice(extra_index, items_len);
1117211196 extra_index += items_len + info.body_len;
......@@ -11179,7 +11203,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1117911203 &false_count,
1118011204 item_ref,
1118111205 src_node_offset,
11182 .{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } },
11206 .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } },
1118311207 ));
1118411208 }
1118511209
......@@ -11226,9 +11250,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1122611250 {
1122711251 var scalar_i: u32 = 0;
1122811252 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
11229 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]));
1123011254 extra_index += 1;
11231 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]));
1123211256 extra_index += 1;
1123311257 extra_index += info.body_len;
1123411258
......@@ -11249,7 +11273,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1124911273 extra_index += 1;
1125011274 const ranges_len = sema.code.extra[extra_index];
1125111275 extra_index += 1;
11252 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]));
1125311277 extra_index += 1;
1125411278 const items = sema.code.refSlice(extra_index, items_len);
1125511279 extra_index += items_len + info.body_len;
......@@ -11262,7 +11286,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1126211286 item_ref,
1126311287 operand_ty,
1126411288 src_node_offset,
11265 .{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } },
11289 .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } },
1126611290 ));
1126711291 }
1126811292
......@@ -11300,7 +11324,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1130011324 .tag_capture_inst = tag_capture_inst,
1130111325 };
1130211326
11303 const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);
11327 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
1130411328 try sema.air_instructions.append(gpa, .{
1130511329 .tag = .block,
1130611330 .data = undefined,
......@@ -11344,7 +11368,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1134411368 var scalar_i: usize = 0;
1134511369 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
1134611370 extra_index += 1;
11347 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]));
1134811372 extra_index += 1;
1134911373 const body = sema.code.extra[extra_index..][0..info.body_len];
1135011374 extra_index += info.body_len;
......@@ -11358,7 +11382,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1135811382 .normal,
1135911383 body,
1136011384 info.capture,
11361 .{ .scalar_capture = @intCast(u32, scalar_i) },
11385 .{ .scalar_capture = @as(u32, @intCast(scalar_i)) },
1136211386 &.{item},
1136311387 if (info.is_inline) operand else .none,
1136411388 info.has_tag_capture,
......@@ -11375,7 +11399,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1137511399 extra_index += 1;
1137611400 const ranges_len = sema.code.extra[extra_index];
1137711401 extra_index += 1;
11378 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]));
1137911403 extra_index += 1 + items_len;
1138011404 const body = sema.code.extra[extra_index + 2 * ranges_len ..][0..info.body_len];
1138111405
......@@ -11392,7 +11416,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1139211416 .normal,
1139311417 body,
1139411418 info.capture,
11395 .{ .multi_capture = @intCast(u32, multi_i) },
11419 .{ .multi_capture = @as(u32, @intCast(multi_i)) },
1139611420 items,
1139711421 if (info.is_inline) operand else .none,
1139811422 info.has_tag_capture,
......@@ -11419,7 +11443,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1141911443 .normal,
1142011444 body,
1142111445 info.capture,
11422 .{ .multi_capture = @intCast(u32, multi_i) },
11446 .{ .multi_capture = @as(u32, @intCast(multi_i)) },
1142311447 undefined, // case_vals may be undefined for ranges
1142411448 if (info.is_inline) operand else .none,
1142511449 info.has_tag_capture,
......@@ -11504,7 +11528,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1150411528 var scalar_i: usize = 0;
1150511529 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
1150611530 extra_index += 1;
11507 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]));
1150811532 extra_index += 1;
1150911533 const body = sema.code.extra[extra_index..][0..info.body_len];
1151011534 extra_index += info.body_len;
......@@ -11532,7 +11556,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1153211556 .normal,
1153311557 body,
1153411558 info.capture,
11535 .{ .scalar_capture = @intCast(u32, scalar_i) },
11559 .{ .scalar_capture = @as(u32, @intCast(scalar_i)) },
1153611560 &.{item},
1153711561 if (info.is_inline) item else .none,
1153811562 info.has_tag_capture,
......@@ -11545,7 +11569,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1154511569
1154611570 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
1154711571 cases_extra.appendAssumeCapacity(1); // items_len
11548 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));
11572 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
1154911573 cases_extra.appendAssumeCapacity(@intFromEnum(item));
1155011574 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1155111575 }
......@@ -11565,7 +11589,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1156511589 extra_index += 1;
1156611590 const ranges_len = sema.code.extra[extra_index];
1156711591 extra_index += 1;
11568 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]));
1156911593 extra_index += 1 + items_len;
1157011594
1157111595 const items = case_vals.items[case_val_idx..][0..items_len];
......@@ -11630,7 +11654,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1163011654
1163111655 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
1163211656 cases_extra.appendAssumeCapacity(1); // items_len
11633 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));
11657 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
1163411658 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
1163511659 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1163611660
......@@ -11652,7 +11676,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1165211676
1165311677 if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) {
1165411678 error.NeededSourceLocation => {
11655 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)) } };
1165611680 const decl = mod.declPtr(case_block.src_decl);
1165711681 try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none));
1165811682 unreachable;
......@@ -11678,7 +11702,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1167811702
1167911703 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
1168011704 cases_extra.appendAssumeCapacity(1); // items_len
11681 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));
11705 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
1168211706 cases_extra.appendAssumeCapacity(@intFromEnum(item));
1168311707 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1168411708 }
......@@ -11726,8 +11750,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1172611750 try cases_extra.ensureUnusedCapacity(gpa, 2 + items.len +
1172711751 case_block.instructions.items.len);
1172811752
11729 cases_extra.appendAssumeCapacity(@intCast(u32, items.len));
11730 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));
11753 cases_extra.appendAssumeCapacity(@as(u32, @intCast(items.len)));
11754 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
1173111755
1173211756 for (items) |item| {
1173311757 cases_extra.appendAssumeCapacity(@intFromEnum(item));
......@@ -11822,8 +11846,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1182211846
1182311847 sema.air_instructions.items(.data)[prev_cond_br].pl_op.payload =
1182411848 sema.addExtraAssumeCapacity(Air.CondBr{
11825 .then_body_len = @intCast(u32, prev_then_body.len),
11826 .else_body_len = @intCast(u32, cond_body.len),
11849 .then_body_len = @as(u32, @intCast(prev_then_body.len)),
11850 .else_body_len = @as(u32, @intCast(cond_body.len)),
1182711851 });
1182811852 sema.air_extra.appendSliceAssumeCapacity(prev_then_body);
1182911853 sema.air_extra.appendSliceAssumeCapacity(cond_body);
......@@ -11848,7 +11872,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1184811872 if (f != null) continue;
1184911873 cases_len += 1;
1185011874
11851 const item_val = try mod.enumValueFieldIndex(operand_ty, @intCast(u32, i));
11875 const item_val = try mod.enumValueFieldIndex(operand_ty, @as(u32, @intCast(i)));
1185211876 const item_ref = try sema.addConstant(item_val);
1185311877
1185411878 case_block.instructions.shrinkRetainingCapacity(0);
......@@ -11879,7 +11903,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1187911903
1188011904 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
1188111905 cases_extra.appendAssumeCapacity(1); // items_len
11882 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));
11906 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
1188311907 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
1188411908 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1188511909 }
......@@ -11920,7 +11944,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1192011944
1192111945 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
1192211946 cases_extra.appendAssumeCapacity(1); // items_len
11923 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));
11947 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
1192411948 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
1192511949 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1192611950 }
......@@ -11951,7 +11975,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1195111975
1195211976 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
1195311977 cases_extra.appendAssumeCapacity(1); // items_len
11954 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));
11978 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
1195511979 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
1195611980 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1195711981 }
......@@ -11979,7 +12003,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1197912003
1198012004 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
1198112005 cases_extra.appendAssumeCapacity(1); // items_len
11982 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));
12006 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
1198312007 cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_true));
1198412008 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1198512009 }
......@@ -12005,7 +12029,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1200512029
1200612030 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
1200712031 cases_extra.appendAssumeCapacity(1); // items_len
12008 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));
12032 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
1200912033 cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_false));
1201012034 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1201112035 }
......@@ -12074,8 +12098,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1207412098
1207512099 sema.air_instructions.items(.data)[prev_cond_br].pl_op.payload =
1207612100 sema.addExtraAssumeCapacity(Air.CondBr{
12077 .then_body_len = @intCast(u32, prev_then_body.len),
12078 .else_body_len = @intCast(u32, case_block.instructions.items.len),
12101 .then_body_len = @as(u32, @intCast(prev_then_body.len)),
12102 .else_body_len = @as(u32, @intCast(case_block.instructions.items.len)),
1207912103 });
1208012104 sema.air_extra.appendSliceAssumeCapacity(prev_then_body);
1208112105 sema.air_extra.appendSliceAssumeCapacity(case_block.instructions.items);
......@@ -12089,8 +12113,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1208912113 _ = try child_block.addInst(.{ .tag = .switch_br, .data = .{ .pl_op = .{
1209012114 .operand = operand,
1209112115 .payload = sema.addExtraAssumeCapacity(Air.SwitchBr{
12092 .cases_len = @intCast(u32, cases_len),
12093 .else_body_len = @intCast(u32, final_else_body.len),
12116 .cases_len = @as(u32, @intCast(cases_len)),
12117 .else_body_len = @as(u32, @intCast(final_else_body.len)),
1209412118 }),
1209512119 } } });
1209612120 sema.air_extra.appendSliceAssumeCapacity(cases_extra.items);
......@@ -13503,7 +13527,7 @@ fn analyzeTupleMul(
1350313527 var i: u32 = 0;
1350413528 while (i < tuple_len) : (i += 1) {
1350513529 const operand_src = lhs_src; // TODO better source location
13506 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);
1350713531 }
1350813532 i = 1;
1350913533 while (i < factor) : (i += 1) {
......@@ -15569,10 +15593,10 @@ fn analyzePtrArithmetic(
1556915593 // The resulting pointer is aligned to the lcd between the offset (an
1557015594 // arbitrary number) and the alignment factor (always a power of two,
1557115595 // non zero).
15572 const new_align = @enumFromInt(Alignment, @min(
15596 const new_align = @as(Alignment, @enumFromInt(@min(
1557315597 @ctz(addend),
1557415598 @intFromEnum(ptr_info.flags.alignment),
15575 ));
15599 )));
1557615600 assert(new_align != .none);
1557715601
1557815602 break :t try mod.ptrType(.{
......@@ -15651,14 +15675,14 @@ fn zirAsm(
1565115675 const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand);
1565215676 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
1565315677 const ret_ty_src: LazySrcLoc = .{ .node_offset_asm_ret_ty = extra.data.src_node };
15654 const outputs_len = @truncate(u5, extended.small);
15655 const inputs_len = @truncate(u5, extended.small >> 5);
15656 const clobbers_len = @truncate(u5, extended.small >> 10);
15657 const is_volatile = @truncate(u1, extended.small >> 15) != 0;
15678 const outputs_len = @as(u5, @truncate(extended.small));
15679 const inputs_len = @as(u5, @truncate(extended.small >> 5));
15680 const clobbers_len = @as(u5, @truncate(extended.small >> 10));
15681 const is_volatile = @as(u1, @truncate(extended.small >> 15)) != 0;
1565815682 const is_global_assembly = sema.func_index == .none;
1565915683
1566015684 const asm_source: []const u8 = if (tmpl_is_expr) blk: {
15661 const tmpl = @enumFromInt(Zir.Inst.Ref, extra.data.asm_source);
15685 const tmpl = @as(Zir.Inst.Ref, @enumFromInt(extra.data.asm_source));
1566215686 const s: []const u8 = try sema.resolveConstString(block, src, tmpl, "assembly code must be comptime-known");
1566315687 break :blk s;
1566415688 } else sema.code.nullTerminatedString(extra.data.asm_source);
......@@ -15697,7 +15721,7 @@ fn zirAsm(
1569715721 const output = sema.code.extraData(Zir.Inst.Asm.Output, extra_i);
1569815722 extra_i = output.end;
1569915723
15700 const is_type = @truncate(u1, output_type_bits) != 0;
15724 const is_type = @as(u1, @truncate(output_type_bits)) != 0;
1570115725 output_type_bits >>= 1;
1570215726
1570315727 if (is_type) {
......@@ -15759,10 +15783,10 @@ fn zirAsm(
1575915783 .data = .{ .ty_pl = .{
1576015784 .ty = expr_ty,
1576115785 .payload = sema.addExtraAssumeCapacity(Air.Asm{
15762 .source_len = @intCast(u32, asm_source.len),
15786 .source_len = @as(u32, @intCast(asm_source.len)),
1576315787 .outputs_len = outputs_len,
15764 .inputs_len = @intCast(u32, args.len),
15765 .flags = (@as(u32, @intFromBool(is_volatile)) << 31) | @intCast(u32, clobbers.len),
15788 .inputs_len = @as(u32, @intCast(args.len)),
15789 .flags = (@as(u32, @intFromBool(is_volatile)) << 31) | @as(u32, @intCast(clobbers.len)),
1576615790 }),
1576715791 } },
1576815792 });
......@@ -16168,7 +16192,7 @@ fn zirThis(
1616816192) CompileError!Air.Inst.Ref {
1616916193 const mod = sema.mod;
1617016194 const this_decl_index = mod.namespaceDeclIndex(block.namespace);
16171 const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand));
16195 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
1617216196 return sema.analyzeDeclVal(block, src, this_decl_index);
1617316197}
1617416198
......@@ -16305,7 +16329,7 @@ fn zirFrameAddress(
1630516329 block: *Block,
1630616330 extended: Zir.Inst.Extended.InstData,
1630716331) CompileError!Air.Inst.Ref {
16308 const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand));
16332 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
1630916333 try sema.requireRuntimeBlock(block, src, null);
1631016334 return try block.addNoOp(.frame_addr);
1631116335}
......@@ -16458,7 +16482,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1645816482
1645916483 const is_noalias = blk: {
1646016484 const index = std.math.cast(u5, i) orelse break :blk false;
16461 break :blk @truncate(u1, info.noalias_bits >> index) != 0;
16485 break :blk @as(u1, @truncate(info.noalias_bits >> index)) != 0;
1646216486 };
1646316487
1646416488 const param_fields = .{
......@@ -16901,7 +16925,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1690116925 else
1690216926 try mod.intern(.{ .int = .{
1690316927 .ty = .comptime_int_type,
16904 .storage = .{ .u64 = @intCast(u64, i) },
16928 .storage = .{ .u64 = @as(u64, @intCast(i)) },
1690516929 } });
1690616930 // TODO: write something like getCoercedInts to avoid needing to dupe
1690716931 const name = try sema.arena.dupe(u8, ip.stringToSlice(enum_type.names[i]));
......@@ -17715,7 +17739,7 @@ fn zirBoolBr(
1771517739 return sema.resolveBody(parent_block, body, inst);
1771617740 }
1771717741
17718 const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);
17742 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
1771917743 try sema.air_instructions.append(gpa, .{
1772017744 .tag = .block,
1772117745 .data = .{ .ty_pl = .{
......@@ -17777,8 +17801,8 @@ fn finishCondBr(
1777717801 @typeInfo(Air.Block).Struct.fields.len + child_block.instructions.items.len + 1);
1777817802
1777917803 const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{
17780 .then_body_len = @intCast(u32, then_block.instructions.items.len),
17781 .else_body_len = @intCast(u32, else_block.instructions.items.len),
17804 .then_body_len = @as(u32, @intCast(then_block.instructions.items.len)),
17805 .else_body_len = @as(u32, @intCast(else_block.instructions.items.len)),
1778217806 });
1778317807 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);
1778417808 sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items);
......@@ -17789,7 +17813,7 @@ fn finishCondBr(
1778917813 } } });
1779017814
1779117815 sema.air_instructions.items(.data)[block_inst].ty_pl.payload = sema.addExtraAssumeCapacity(
17792 Air.Block{ .body_len = @intCast(u32, child_block.instructions.items.len) },
17816 Air.Block{ .body_len = @as(u32, @intCast(child_block.instructions.items.len)) },
1779317817 );
1779417818 sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items);
1779517819
......@@ -17952,8 +17976,8 @@ fn zirCondbr(
1795217976 .data = .{ .pl_op = .{
1795317977 .operand = cond,
1795417978 .payload = sema.addExtraAssumeCapacity(Air.CondBr{
17955 .then_body_len = @intCast(u32, true_instructions.len),
17956 .else_body_len = @intCast(u32, sub_block.instructions.items.len),
17979 .then_body_len = @as(u32, @intCast(true_instructions.len)),
17980 .else_body_len = @as(u32, @intCast(sub_block.instructions.items.len)),
1795717981 }),
1795817982 } },
1795917983 });
......@@ -18000,7 +18024,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
1800018024 .data = .{ .pl_op = .{
1800118025 .operand = err_union,
1800218026 .payload = sema.addExtraAssumeCapacity(Air.Try{
18003 .body_len = @intCast(u32, sub_block.instructions.items.len),
18027 .body_len = @as(u32, @intCast(sub_block.instructions.items.len)),
1800418028 }),
1800518029 } },
1800618030 });
......@@ -18060,7 +18084,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1806018084 .ty = res_ty_ref,
1806118085 .payload = sema.addExtraAssumeCapacity(Air.TryPtr{
1806218086 .ptr = operand,
18063 .body_len = @intCast(u32, sub_block.instructions.items.len),
18087 .body_len = @as(u32, @intCast(sub_block.instructions.items.len)),
1806418088 }),
1806518089 } },
1806618090 });
......@@ -18076,7 +18100,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi
1807618100 const labeled_block = if (!gop.found_existing) blk: {
1807718101 try sema.post_hoc_blocks.ensureUnusedCapacity(sema.gpa, 1);
1807818102
18079 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));
1808018104 gop.value_ptr.* = Air.indexToRef(new_block_inst);
1808118105 try sema.air_instructions.append(sema.gpa, .{
1808218106 .tag = .block,
......@@ -18272,8 +18296,8 @@ fn retWithErrTracing(
1827218296 @typeInfo(Air.Block).Struct.fields.len + 1);
1827318297
1827418298 const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{
18275 .then_body_len = @intCast(u32, then_block.instructions.items.len),
18276 .else_body_len = @intCast(u32, else_block.instructions.items.len),
18299 .then_body_len = @as(u32, @intCast(then_block.instructions.items.len)),
18300 .else_body_len = @as(u32, @intCast(else_block.instructions.items.len)),
1827718301 });
1827818302 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);
1827918303 sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items);
......@@ -18462,7 +18486,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1846218486 var extra_i = extra.end;
1846318487
1846418488 const sentinel = if (inst_data.flags.has_sentinel) blk: {
18465 const ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_i]);
18489 const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i]));
1846618490 extra_i += 1;
1846718491 const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src);
1846818492 const val = try sema.resolveConstValue(block, sentinel_src, coerced, "pointer sentinel value must be comptime-known");
......@@ -18470,7 +18494,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1847018494 } else .none;
1847118495
1847218496 const abi_align: Alignment = if (inst_data.flags.has_align) blk: {
18473 const ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_i]);
18497 const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i]));
1847418498 extra_i += 1;
1847518499 const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src);
1847618500 const val = try sema.resolveConstValue(block, align_src, coerced, "pointer alignment must be comptime-known");
......@@ -18483,29 +18507,29 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1848318507 },
1848418508 else => {},
1848518509 }
18486 const abi_align = @intCast(u32, (try val.getUnsignedIntAdvanced(mod, sema)).?);
18510 const abi_align = @as(u32, @intCast((try val.getUnsignedIntAdvanced(mod, sema)).?));
1848718511 try sema.validateAlign(block, align_src, abi_align);
1848818512 break :blk Alignment.fromByteUnits(abi_align);
1848918513 } else .none;
1849018514
1849118515 const address_space: std.builtin.AddressSpace = if (inst_data.flags.has_addrspace) blk: {
18492 const ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_i]);
18516 const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i]));
1849318517 extra_i += 1;
1849418518 break :blk try sema.analyzeAddressSpace(block, addrspace_src, ref, .pointer);
1849518519 } else if (elem_ty.zigTypeTag(mod) == .Fn and target.cpu.arch == .avr) .flash else .generic;
1849618520
1849718521 const bit_offset = if (inst_data.flags.has_bit_range) blk: {
18498 const ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_i]);
18522 const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i]));
1849918523 extra_i += 1;
1850018524 const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16, "pointer bit-offset must be comptime-known");
18501 break :blk @intCast(u16, bit_offset);
18525 break :blk @as(u16, @intCast(bit_offset));
1850218526 } else 0;
1850318527
1850418528 const host_size: u16 = if (inst_data.flags.has_bit_range) blk: {
18505 const ref = @enumFromInt(Zir.Inst.Ref, sema.code.extra[extra_i]);
18529 const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i]));
1850618530 extra_i += 1;
1850718531 const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16, "pointer host size must be comptime-known");
18508 break :blk @intCast(u16, host_size);
18532 break :blk @as(u16, @intCast(host_size));
1850918533 } else 0;
1851018534
1851118535 if (host_size != 0 and bit_offset >= host_size * 8) {
......@@ -18645,7 +18669,7 @@ fn unionInit(
1864518669
1864618670 if (try sema.resolveMaybeUndefVal(init)) |init_val| {
1864718671 const tag_ty = union_ty.unionTagTypeHypothetical(mod);
18648 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).?));
1864918673 const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index);
1865018674 return sema.addConstant((try mod.intern(.{ .un = .{
1865118675 .ty = union_ty.toIntern(),
......@@ -18747,7 +18771,7 @@ fn zirStructInit(
1874718771 const field_name = try mod.intern_pool.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start));
1874818772 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);
1874918773 const tag_ty = resolved_ty.unionTagTypeHypothetical(mod);
18750 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).?));
1875118775 const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index);
1875218776
1875318777 const init_inst = try sema.resolveInst(item.data.init);
......@@ -18891,7 +18915,7 @@ fn finishStructInit(
1889118915 });
1889218916 const alloc = try block.addTy(.alloc, alloc_ty);
1889318917 for (field_inits, 0..) |field_init, i_usize| {
18894 const i = @intCast(u32, i_usize);
18918 const i = @as(u32, @intCast(i_usize));
1889518919 const field_src = dest_src;
1889618920 const field_ptr = try sema.structFieldPtrByIndex(block, dest_src, alloc, i, field_src, struct_ty, true);
1889718921 try sema.storePtr(block, dest_src, field_ptr, field_init);
......@@ -18934,7 +18958,7 @@ fn zirStructInitAnon(
1893418958 var runtime_index: ?usize = null;
1893518959 var extra_index = extra.end;
1893618960 for (types, 0..) |*field_ty, i_usize| {
18937 const i = @intCast(u32, i_usize);
18961 const i = @as(u32, @intCast(i_usize));
1893818962 const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index);
1893918963 extra_index = item.end;
1894018964
......@@ -19013,7 +19037,7 @@ fn zirStructInitAnon(
1901319037 const alloc = try block.addTy(.alloc, alloc_ty);
1901419038 var extra_index = extra.end;
1901519039 for (types, 0..) |field_ty, i_usize| {
19016 const i = @intCast(u32, i_usize);
19040 const i = @as(u32, @intCast(i_usize));
1901719041 const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index);
1901819042 extra_index = item.end;
1901919043
......@@ -19085,7 +19109,7 @@ fn zirArrayInit(
1908519109
1908619110 const opt_runtime_index: ?u32 = for (resolved_args, 0..) |arg, i| {
1908719111 const comptime_known = try sema.isComptimeKnown(arg);
19088 if (!comptime_known) break @intCast(u32, i);
19112 if (!comptime_known) break @as(u32, @intCast(i));
1908919113 } else null;
1909019114
1909119115 const runtime_index = opt_runtime_index orelse {
......@@ -19220,7 +19244,7 @@ fn zirArrayInitAnon(
1922019244 });
1922119245 const alloc = try block.addTy(.alloc, alloc_ty);
1922219246 for (operands, 0..) |operand, i_usize| {
19223 const i = @intCast(u32, i_usize);
19247 const i = @as(u32, @intCast(i_usize));
1922419248 const field_ptr_ty = try mod.ptrType(.{
1922519249 .child = types[i],
1922619250 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
......@@ -19371,7 +19395,7 @@ fn zirFrame(
1937119395 block: *Block,
1937219396 extended: Zir.Inst.Extended.InstData,
1937319397) CompileError!Air.Inst.Ref {
19374 const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand));
19398 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
1937519399 return sema.failWithUseOfAsync(block, src);
1937619400}
1937719401
......@@ -19564,7 +19588,7 @@ fn zirReify(
1956419588 const mod = sema.mod;
1956519589 const gpa = sema.gpa;
1956619590 const ip = &mod.intern_pool;
19567 const name_strategy = @enumFromInt(Zir.Inst.NameStrategy, extended.small);
19591 const name_strategy = @as(Zir.Inst.NameStrategy, @enumFromInt(extended.small));
1956819592 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
1956919593 const src = LazySrcLoc.nodeOffset(extra.node);
1957019594 const type_info_ty = try sema.getBuiltinType("Type");
......@@ -19576,7 +19600,7 @@ fn zirReify(
1957619600 const target = mod.getTarget();
1957719601 if (try union_val.val.toValue().anyUndef(mod)) return sema.failWithUseOfUndef(block, src);
1957819602 const tag_index = type_info_ty.unionTagFieldIndex(union_val.tag.toValue(), mod).?;
19579 switch (@enumFromInt(std.builtin.TypeId, tag_index)) {
19603 switch (@as(std.builtin.TypeId, @enumFromInt(tag_index))) {
1958019604 .Type => return Air.Inst.Ref.type_type,
1958119605 .Void => return Air.Inst.Ref.void_type,
1958219606 .Bool => return Air.Inst.Ref.bool_type,
......@@ -19599,7 +19623,7 @@ fn zirReify(
1959919623 );
1960019624
1960119625 const signedness = mod.toEnum(std.builtin.Signedness, signedness_val);
19602 const bits = @intCast(u16, bits_val.toUnsignedInt(mod));
19626 const bits = @as(u16, @intCast(bits_val.toUnsignedInt(mod)));
1960319627 const ty = try mod.intType(signedness, bits);
1960419628 return sema.addType(ty);
1960519629 },
......@@ -19612,7 +19636,7 @@ fn zirReify(
1961219636 try ip.getOrPutString(gpa, "child"),
1961319637 ).?);
1961419638
19615 const len = @intCast(u32, len_val.toUnsignedInt(mod));
19639 const len = @as(u32, @intCast(len_val.toUnsignedInt(mod)));
1961619640 const child_ty = child_val.toType();
1961719641
1961819642 try sema.checkVectorElemType(block, src, child_ty);
......@@ -19629,7 +19653,7 @@ fn zirReify(
1962919653 try ip.getOrPutString(gpa, "bits"),
1963019654 ).?);
1963119655
19632 const bits = @intCast(u16, bits_val.toUnsignedInt(mod));
19656 const bits = @as(u16, @intCast(bits_val.toUnsignedInt(mod)));
1963319657 const ty = switch (bits) {
1963419658 16 => Type.f16,
1963519659 32 => Type.f32,
......@@ -19901,7 +19925,7 @@ fn zirReify(
1990119925 }
1990219926
1990319927 // Define our empty enum decl
19904 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))));
1990519929 const incomplete_enum = try ip.getIncompleteEnum(gpa, .{
1990619930 .decl = new_decl_index,
1990719931 .namespace = .none,
......@@ -20264,7 +20288,7 @@ fn zirReify(
2026420288 if (!try sema.intFitsInType(alignment_val, Type.u32, null)) {
2026520289 return sema.fail(block, src, "alignment must fit in 'u32'", .{});
2026620290 }
20267 const alignment = @intCast(u29, alignment_val.toUnsignedInt(mod));
20291 const alignment = @as(u29, @intCast(alignment_val.toUnsignedInt(mod)));
2026820292 if (alignment == target_util.defaultFunctionAlignment(target)) {
2026920293 break :alignment .none;
2027020294 } else {
......@@ -20541,7 +20565,7 @@ fn reifyStruct(
2054120565 try sema.checkBackingIntType(block, src, backing_int_ty, fields_bit_sum);
2054220566 struct_obj.backing_int_ty = backing_int_ty;
2054320567 } else {
20544 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)));
2054520569 }
2054620570
2054720571 struct_obj.status = .have_layout;
......@@ -20552,50 +20576,6 @@ fn reifyStruct(
2055220576 return decl_val;
2055320577}
2055420578
20555fn zirAddrSpaceCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
20556 const mod = sema.mod;
20557 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
20558 const src = LazySrcLoc.nodeOffset(extra.node);
20559 const addrspace_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
20560 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
20561
20562 const dest_addrspace = try sema.analyzeAddressSpace(block, addrspace_src, extra.lhs, .pointer);
20563 const ptr = try sema.resolveInst(extra.rhs);
20564 const ptr_ty = sema.typeOf(ptr);
20565
20566 try sema.checkPtrOperand(block, ptr_src, ptr_ty);
20567
20568 var ptr_info = ptr_ty.ptrInfo(mod);
20569 const src_addrspace = ptr_info.flags.address_space;
20570 if (!target_util.addrSpaceCastIsValid(sema.mod.getTarget(), src_addrspace, dest_addrspace)) {
20571 const msg = msg: {
20572 const msg = try sema.errMsg(block, src, "invalid address space cast", .{});
20573 errdefer msg.destroy(sema.gpa);
20574 try sema.errNote(block, src, msg, "address space '{s}' is not compatible with address space '{s}'", .{ @tagName(src_addrspace), @tagName(dest_addrspace) });
20575 break :msg msg;
20576 };
20577 return sema.failWithOwnedErrorMsg(msg);
20578 }
20579
20580 ptr_info.flags.address_space = dest_addrspace;
20581 const dest_ptr_ty = try mod.ptrType(ptr_info);
20582 const dest_ty = if (ptr_ty.zigTypeTag(mod) == .Optional)
20583 try mod.optionalType(dest_ptr_ty.toIntern())
20584 else
20585 dest_ptr_ty;
20586
20587 try sema.requireRuntimeBlock(block, src, ptr_src);
20588 // TODO: Address space cast safety?
20589
20590 return block.addInst(.{
20591 .tag = .addrspace_cast,
20592 .data = .{ .ty_op = .{
20593 .ty = try sema.addType(dest_ty),
20594 .operand = ptr,
20595 } },
20596 });
20597}
20598
2059920579fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) CompileError!Air.Inst.Ref {
2060020580 const va_list_ty = try sema.getBuiltinType("VaList");
2060120581 const va_list_ptr = try sema.mod.singleMutPtrType(va_list_ty);
......@@ -20656,7 +20636,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2065620636}
2065720637
2065820638fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
20659 const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand));
20639 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
2066020640
2066120641 const va_list_ty = try sema.getBuiltinType("VaList");
2066220642 try sema.requireRuntimeBlock(block, src, null);
......@@ -20711,14 +20691,14 @@ fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2071120691fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2071220692 const mod = sema.mod;
2071320693 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
20694 const src = inst_data.src();
2071420695 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
20715 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
20716 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
20717 const dest_ty = try sema.resolveType(block, ty_src, extra.lhs);
20696 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
20697 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, "@intFromFloat");
2071820698 const operand = try sema.resolveInst(extra.rhs);
2071920699 const operand_ty = sema.typeOf(operand);
2072020700
20721 _ = try sema.checkIntType(block, ty_src, dest_ty);
20701 _ = try sema.checkIntType(block, src, dest_ty);
2072220702 try sema.checkFloatType(block, operand_src, operand_ty);
2072320703
2072420704 if (try sema.resolveMaybeUndefVal(operand)) |val| {
......@@ -20751,14 +20731,14 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2075120731fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2075220732 const mod = sema.mod;
2075320733 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
20734 const src = inst_data.src();
2075420735 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
20755 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
20756 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
20757 const dest_ty = try sema.resolveType(block, ty_src, extra.lhs);
20736 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
20737 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, "@floatFromInt");
2075820738 const operand = try sema.resolveInst(extra.rhs);
2075920739 const operand_ty = sema.typeOf(operand);
2076020740
20761 try sema.checkFloatType(block, ty_src, dest_ty);
20741 try sema.checkFloatType(block, src, dest_ty);
2076220742 _ = try sema.checkIntType(block, operand_src, operand_ty);
2076320743
2076420744 if (try sema.resolveMaybeUndefVal(operand)) |val| {
......@@ -20779,21 +20759,20 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2077920759
2078020760 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2078120761
20782 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
20762 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2078320763 const operand_res = try sema.resolveInst(extra.rhs);
2078420764 const operand_coerced = try sema.coerce(block, Type.usize, operand_res, operand_src);
2078520765
20786 const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
20787 const ptr_ty = try sema.resolveType(block, src, extra.lhs);
20788 try sema.checkPtrType(block, type_src, ptr_ty);
20766 const ptr_ty = try sema.resolveCastDestType(block, src, extra.lhs, "@ptrFromInt");
20767 try sema.checkPtrType(block, src, ptr_ty);
2078920768 const elem_ty = ptr_ty.elemType2(mod);
2079020769 const ptr_align = try ptr_ty.ptrAlignmentAdvanced(mod, sema);
2079120770
2079220771 if (ptr_ty.isSlice(mod)) {
2079320772 const msg = msg: {
20794 const msg = try sema.errMsg(block, type_src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(sema.mod)});
20773 const msg = try sema.errMsg(block, src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(sema.mod)});
2079520774 errdefer msg.destroy(sema.gpa);
20796 try sema.errNote(block, type_src, msg, "slice length cannot be inferred from address", .{});
20775 try sema.errNote(block, src, msg, "slice length cannot be inferred from address", .{});
2079720776 break :msg msg;
2079820777 };
2079920778 return sema.failWithOwnedErrorMsg(msg);
......@@ -20841,12 +20820,11 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
2084120820 const ip = &mod.intern_pool;
2084220821 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
2084320822 const src = LazySrcLoc.nodeOffset(extra.node);
20844 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
20845 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
20846 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
20823 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
20824 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, "@errSetCast");
2084720825 const operand = try sema.resolveInst(extra.rhs);
2084820826 const operand_ty = sema.typeOf(operand);
20849 try sema.checkErrorSetType(block, dest_ty_src, dest_ty);
20827 try sema.checkErrorSetType(block, src, dest_ty);
2085020828 try sema.checkErrorSetType(block, operand_src, operand_ty);
2085120829
2085220830 // operand must be defined since it can be an invalid error value
......@@ -20869,7 +20847,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
2086920847 break :disjoint true;
2087020848 }
2087120849
20872 try sema.resolveInferredErrorSetTy(block, dest_ty_src, dest_ty);
20850 try sema.resolveInferredErrorSetTy(block, src, dest_ty);
2087320851 try sema.resolveInferredErrorSetTy(block, operand_src, operand_ty);
2087420852 for (dest_ty.errorSetNames(mod)) |dest_err_name| {
2087520853 if (Type.errorSetHasFieldIp(ip, operand_ty.toIntern(), dest_err_name))
......@@ -20924,159 +20902,415 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
2092420902 return block.addBitCast(dest_ty, operand);
2092520903}
2092620904
20905fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
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;
20908 const src = LazySrcLoc.nodeOffset(extra.node);
20909 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
20910 const operand = try sema.resolveInst(extra.rhs);
20911 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, "@ptrCast"); // TODO: better error message (builtin name)
20912 return sema.ptrCastFull(
20913 block,
20914 flags,
20915 src,
20916 operand,
20917 operand_src,
20918 dest_ty,
20919 );
20920}
20921
2092720922fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
20928 const mod = sema.mod;
2092920923 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2093020924 const src = inst_data.src();
20931 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
20932 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
20925 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2093320926 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
20934 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
20927 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, "@ptrCast");
2093520928 const operand = try sema.resolveInst(extra.rhs);
20929
20930 return sema.ptrCastFull(
20931 block,
20932 .{ .ptr_cast = true },
20933 src,
20934 operand,
20935 operand_src,
20936 dest_ty,
20937 );
20938}
20939
20940fn ptrCastFull(
20941 sema: *Sema,
20942 block: *Block,
20943 flags: Zir.Inst.FullPtrCastFlags,
20944 src: LazySrcLoc,
20945 operand: Air.Inst.Ref,
20946 operand_src: LazySrcLoc,
20947 dest_ty: Type,
20948) CompileError!Air.Inst.Ref {
20949 const mod = sema.mod;
2093620950 const operand_ty = sema.typeOf(operand);
2093720951
20938 try sema.checkPtrType(block, dest_ty_src, dest_ty);
20952 try sema.checkPtrType(block, src, dest_ty);
2093920953 try sema.checkPtrOperand(block, operand_src, operand_ty);
2094020954
20941 const operand_info = operand_ty.ptrInfo(mod);
20955 const src_info = operand_ty.ptrInfo(mod);
2094220956 const dest_info = dest_ty.ptrInfo(mod);
20943 if (operand_info.flags.is_const and !dest_info.flags.is_const) {
20944 const msg = msg: {
20945 const msg = try sema.errMsg(block, src, "cast discards const qualifier", .{});
20946 errdefer msg.destroy(sema.gpa);
2094720957
20948 try sema.errNote(block, src, msg, "consider using '@constCast'", .{});
20949 break :msg msg;
20950 };
20951 return sema.failWithOwnedErrorMsg(msg);
20952 }
20953 if (operand_info.flags.is_volatile and !dest_info.flags.is_volatile) {
20954 const msg = msg: {
20955 const msg = try sema.errMsg(block, src, "cast discards volatile qualifier", .{});
20956 errdefer msg.destroy(sema.gpa);
20958 try sema.resolveTypeLayout(src_info.child.toType());
20959 try sema.resolveTypeLayout(dest_info.child.toType());
2095720960
20958 try sema.errNote(block, src, msg, "consider using '@volatileCast'", .{});
20959 break :msg msg;
20960 };
20961 return sema.failWithOwnedErrorMsg(msg);
20961 const src_slice_like = src_info.flags.size == .Slice or
20962 (src_info.flags.size == .One and src_info.child.toType().zigTypeTag(mod) == .Array);
20963
20964 const dest_slice_like = dest_info.flags.size == .Slice or
20965 (dest_info.flags.size == .One and dest_info.child.toType().zigTypeTag(mod) == .Array);
20966
20967 if (dest_info.flags.size == .Slice and !src_slice_like) {
20968 return sema.fail(block, src, "illegal pointer cast to slice", .{});
2096220969 }
20963 if (operand_info.flags.address_space != dest_info.flags.address_space) {
20964 const msg = msg: {
20965 const msg = try sema.errMsg(block, src, "cast changes pointer address space", .{});
20966 errdefer msg.destroy(sema.gpa);
2096720970
20968 try sema.errNote(block, src, msg, "consider using '@addrSpaceCast'", .{});
20969 break :msg msg;
20971 if (dest_info.flags.size == .Slice) {
20972 const src_elem_size = switch (src_info.flags.size) {
20973 .Slice => src_info.child.toType().abiSize(mod),
20974 // pointer to array
20975 .One => src_info.child.toType().childType(mod).abiSize(mod),
20976 else => unreachable,
2097020977 };
20971 return sema.failWithOwnedErrorMsg(msg);
20978 const dest_elem_size = dest_info.child.toType().abiSize(mod);
20979 if (src_elem_size != dest_elem_size) {
20980 return sema.fail(block, src, "TODO: implement @ptrCast between slices changing the length", .{});
20981 }
2097220982 }
2097320983
20974 const dest_is_slice = dest_ty.isSlice(mod);
20975 const operand_is_slice = operand_ty.isSlice(mod);
20976 if (dest_is_slice and !operand_is_slice) {
20977 return sema.fail(block, dest_ty_src, "illegal pointer cast to slice", .{});
20978 }
20979 const ptr = if (operand_is_slice and !dest_is_slice)
20980 try sema.analyzeSlicePtr(block, operand_src, operand, operand_ty)
20981 else
20982 operand;
20984 // The checking logic in this function must stay in sync with Sema.coerceInMemoryAllowedPtrs
2098320985
20984 const dest_elem_ty = dest_ty.elemType2(mod);
20985 try sema.resolveTypeLayout(dest_elem_ty);
20986 const dest_align = dest_ty.ptrAlignment(mod);
20987
20988 const operand_elem_ty = operand_ty.elemType2(mod);
20989 try sema.resolveTypeLayout(operand_elem_ty);
20990 const operand_align = operand_ty.ptrAlignment(mod);
20991
20992 // If the destination is less aligned than the source, preserve the source alignment
20993 const aligned_dest_ty = if (operand_align <= dest_align) dest_ty else blk: {
20994 // Unwrap the pointer (or pointer-like optional) type, set alignment, and re-wrap into result
20995 var dest_ptr_info = dest_ty.ptrInfo(mod);
20996 dest_ptr_info.flags.alignment = Alignment.fromNonzeroByteUnits(operand_align);
20997 if (dest_ty.zigTypeTag(mod) == .Optional) {
20998 break :blk try mod.optionalType((try mod.ptrType(dest_ptr_info)).toIntern());
20999 } else {
21000 break :blk try mod.ptrType(dest_ptr_info);
20986 if (!flags.ptr_cast) {
20987 check_size: {
20988 if (src_info.flags.size == dest_info.flags.size) break :check_size;
20989 if (src_slice_like and dest_slice_like) break :check_size;
20990 if (src_info.flags.size == .C) break :check_size;
20991 if (dest_info.flags.size == .C) break :check_size;
20992 return sema.failWithOwnedErrorMsg(msg: {
20993 const msg = try sema.errMsg(block, src, "cannot implicitly convert {s} pointer to {s} pointer", .{
20994 pointerSizeString(src_info.flags.size),
20995 pointerSizeString(dest_info.flags.size),
20996 });
20997 errdefer msg.destroy(sema.gpa);
20998 if (dest_info.flags.size == .Many and
20999 (src_info.flags.size == .Slice or
21000 (src_info.flags.size == .One and src_info.child.toType().zigTypeTag(mod) == .Array)))
21001 {
21002 try sema.errNote(block, src, msg, "use 'ptr' field to convert slice to many pointer", .{});
21003 } else {
21004 try sema.errNote(block, src, msg, "use @ptrCast to change pointer size", .{});
21005 }
21006 break :msg msg;
21007 });
21008 }
21009
21010 check_child: {
21011 const src_child = if (dest_info.flags.size == .Slice and src_info.flags.size == .One) blk: {
21012 // *[n]T -> []T
21013 break :blk src_info.child.toType().childType(mod);
21014 } else src_info.child.toType();
21015
21016 const dest_child = dest_info.child.toType();
21017
21018 const imc_res = try sema.coerceInMemoryAllowed(
21019 block,
21020 dest_child,
21021 src_child,
21022 !dest_info.flags.is_const,
21023 mod.getTarget(),
21024 src,
21025 operand_src,
21026 );
21027 if (imc_res == .ok) break :check_child;
21028 return sema.failWithOwnedErrorMsg(msg: {
21029 const msg = try sema.errMsg(block, src, "pointer element type '{}' cannot coerce into element type '{}'", .{
21030 src_child.fmt(mod),
21031 dest_child.fmt(mod),
21032 });
21033 errdefer msg.destroy(sema.gpa);
21034 try imc_res.report(sema, block, src, msg);
21035 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer element type", .{});
21036 break :msg msg;
21037 });
21038 }
21039
21040 check_sent: {
21041 if (dest_info.sentinel == .none) break :check_sent;
21042 if (src_info.flags.size == .C) break :check_sent;
21043 if (src_info.sentinel != .none) {
21044 const coerced_sent = try mod.intern_pool.getCoerced(sema.gpa, src_info.sentinel, dest_info.child);
21045 if (dest_info.sentinel == coerced_sent) break :check_sent;
21046 }
21047 if (src_slice_like and src_info.flags.size == .One and dest_info.flags.size == .Slice) {
21048 // [*]nT -> []T
21049 const arr_ty = src_info.child.toType();
21050 if (arr_ty.sentinel(mod)) |src_sentinel| {
21051 const coerced_sent = try mod.intern_pool.getCoerced(sema.gpa, src_sentinel.toIntern(), dest_info.child);
21052 if (dest_info.sentinel == coerced_sent) break :check_sent;
21053 }
21054 }
21055 return sema.failWithOwnedErrorMsg(msg: {
21056 const msg = if (src_info.sentinel == .none) blk: {
21057 break :blk try sema.errMsg(block, src, "destination pointer requires '{}' sentinel", .{
21058 dest_info.sentinel.toValue().fmtValue(dest_info.child.toType(), mod),
21059 });
21060 } else blk: {
21061 break :blk try sema.errMsg(block, src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{
21062 src_info.sentinel.toValue().fmtValue(src_info.child.toType(), mod),
21063 dest_info.sentinel.toValue().fmtValue(dest_info.child.toType(), mod),
21064 });
21065 };
21066 errdefer msg.destroy(sema.gpa);
21067 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer sentinel", .{});
21068 break :msg msg;
21069 });
2100121070 }
21002 };
2100321071
21004 if (dest_is_slice) {
21005 const operand_elem_size = operand_elem_ty.abiSize(mod);
21006 const dest_elem_size = dest_elem_ty.abiSize(mod);
21007 if (operand_elem_size != dest_elem_size) {
21008 return sema.fail(block, dest_ty_src, "TODO: implement @ptrCast between slices changing the length", .{});
21072 if (src_info.packed_offset.host_size != dest_info.packed_offset.host_size) {
21073 return sema.failWithOwnedErrorMsg(msg: {
21074 const msg = try sema.errMsg(block, src, "pointer host size '{}' cannot coerce into pointer host size '{}'", .{
21075 src_info.packed_offset.host_size,
21076 dest_info.packed_offset.host_size,
21077 });
21078 errdefer msg.destroy(sema.gpa);
21079 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer host size", .{});
21080 break :msg msg;
21081 });
21082 }
21083
21084 if (src_info.packed_offset.bit_offset != dest_info.packed_offset.bit_offset) {
21085 return sema.failWithOwnedErrorMsg(msg: {
21086 const msg = try sema.errMsg(block, src, "pointer bit offset '{}' cannot coerce into pointer bit offset '{}'", .{
21087 src_info.packed_offset.bit_offset,
21088 dest_info.packed_offset.bit_offset,
21089 });
21090 errdefer msg.destroy(sema.gpa);
21091 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer bit offset", .{});
21092 break :msg msg;
21093 });
21094 }
21095
21096 check_allowzero: {
21097 const src_allows_zero = operand_ty.ptrAllowsZero(mod);
21098 const dest_allows_zero = dest_ty.ptrAllowsZero(mod);
21099 if (!src_allows_zero) break :check_allowzero;
21100 if (dest_allows_zero) break :check_allowzero;
21101
21102 return sema.failWithOwnedErrorMsg(msg: {
21103 const msg = try sema.errMsg(block, src, "'{}' could have null values which are illegal in type '{}'", .{
21104 operand_ty.fmt(mod),
21105 dest_ty.fmt(mod),
21106 });
21107 errdefer msg.destroy(sema.gpa);
21108 try sema.errNote(block, src, msg, "use @ptrCast to assert the pointer is not null", .{});
21109 break :msg msg;
21110 });
2100921111 }
21112
21113 // TODO: vector index?
2101021114 }
2101121115
21012 if (dest_align > operand_align) {
21013 const msg = msg: {
21014 const msg = try sema.errMsg(block, src, "cast increases pointer alignment", .{});
21015 errdefer msg.destroy(sema.gpa);
21116 const src_align = src_info.flags.alignment.toByteUnitsOptional() orelse src_info.child.toType().abiAlignment(mod);
21117 const dest_align = dest_info.flags.alignment.toByteUnitsOptional() orelse dest_info.child.toType().abiAlignment(mod);
21118 if (!flags.align_cast) {
21119 if (dest_align > src_align) {
21120 return sema.failWithOwnedErrorMsg(msg: {
21121 const msg = try sema.errMsg(block, src, "cast increases pointer alignment", .{});
21122 errdefer msg.destroy(sema.gpa);
21123 try sema.errNote(block, operand_src, msg, "'{}' has alignment '{d}'", .{
21124 operand_ty.fmt(mod), src_align,
21125 });
21126 try sema.errNote(block, src, msg, "'{}' has alignment '{d}'", .{
21127 dest_ty.fmt(mod), dest_align,
21128 });
21129 try sema.errNote(block, src, msg, "use @alignCast to assert pointer alignment", .{});
21130 break :msg msg;
21131 });
21132 }
21133 }
2101621134
21017 try sema.errNote(block, operand_src, msg, "'{}' has alignment '{d}'", .{
21018 operand_ty.fmt(mod), operand_align,
21135 if (!flags.addrspace_cast) {
21136 if (src_info.flags.address_space != dest_info.flags.address_space) {
21137 return sema.failWithOwnedErrorMsg(msg: {
21138 const msg = try sema.errMsg(block, src, "cast changes pointer address space", .{});
21139 errdefer msg.destroy(sema.gpa);
21140 try sema.errNote(block, operand_src, msg, "'{}' has address space '{s}'", .{
21141 operand_ty.fmt(mod), @tagName(src_info.flags.address_space),
21142 });
21143 try sema.errNote(block, src, msg, "'{}' has address space '{s}'", .{
21144 dest_ty.fmt(mod), @tagName(dest_info.flags.address_space),
21145 });
21146 try sema.errNote(block, src, msg, "use @addrSpaceCast to cast pointer address space", .{});
21147 break :msg msg;
21148 });
21149 }
21150 } else {
21151 // Some address space casts are always disallowed
21152 if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) {
21153 return sema.failWithOwnedErrorMsg(msg: {
21154 const msg = try sema.errMsg(block, src, "invalid address space cast", .{});
21155 errdefer msg.destroy(sema.gpa);
21156 try sema.errNote(block, operand_src, msg, "address space '{s}' is not compatible with address space '{s}'", .{
21157 @tagName(src_info.flags.address_space),
21158 @tagName(dest_info.flags.address_space),
21159 });
21160 break :msg msg;
2101921161 });
21020 try sema.errNote(block, dest_ty_src, msg, "'{}' has alignment '{d}'", .{
21021 dest_ty.fmt(mod), dest_align,
21162 }
21163 }
21164
21165 if (!flags.const_cast) {
21166 if (src_info.flags.is_const and !dest_info.flags.is_const) {
21167 return sema.failWithOwnedErrorMsg(msg: {
21168 const msg = try sema.errMsg(block, src, "cast discards const qualifier", .{});
21169 errdefer msg.destroy(sema.gpa);
21170 try sema.errNote(block, src, msg, "use @constCast to discard const qualifier", .{});
21171 break :msg msg;
2102221172 });
21173 }
21174 }
2102321175
21024 try sema.errNote(block, src, msg, "consider using '@alignCast'", .{});
21025 break :msg msg;
21026 };
21027 return sema.failWithOwnedErrorMsg(msg);
21176 if (!flags.volatile_cast) {
21177 if (src_info.flags.is_volatile and !dest_info.flags.is_volatile) {
21178 return sema.failWithOwnedErrorMsg(msg: {
21179 const msg = try sema.errMsg(block, src, "cast discards volatile qualifier", .{});
21180 errdefer msg.destroy(sema.gpa);
21181 try sema.errNote(block, src, msg, "use @volatileCast to discard volatile qualifier", .{});
21182 break :msg msg;
21183 });
21184 }
2102821185 }
2102921186
21030 if (try sema.resolveMaybeUndefVal(ptr)) |operand_val| {
21031 if (!dest_ty.ptrAllowsZero(mod) and operand_val.isUndef(mod)) {
21032 return sema.failWithUseOfUndef(block, operand_src);
21187 const ptr = if (src_info.flags.size == .Slice and dest_info.flags.size != .Slice) ptr: {
21188 break :ptr try sema.analyzeSlicePtr(block, operand_src, operand, operand_ty);
21189 } else operand;
21190
21191 const dest_ptr_ty = if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) blk: {
21192 // Only convert to a many-pointer at first
21193 var info = dest_info;
21194 info.flags.size = .Many;
21195 const ty = try mod.ptrType(info);
21196 if (dest_ty.zigTypeTag(mod) == .Optional) {
21197 break :blk try mod.optionalType(ty.toIntern());
21198 } else {
21199 break :blk ty;
2103321200 }
21034 if (!dest_ty.ptrAllowsZero(mod) and operand_val.isNull(mod)) {
21035 return sema.fail(block, operand_src, "null pointer casted to type '{}'", .{dest_ty.fmt(mod)});
21201 } else dest_ty;
21202
21203 // Cannot do @addrSpaceCast at comptime
21204 if (!flags.addrspace_cast) {
21205 if (try sema.resolveMaybeUndefVal(ptr)) |ptr_val| {
21206 if (!dest_ty.ptrAllowsZero(mod) and ptr_val.isUndef(mod)) {
21207 return sema.failWithUseOfUndef(block, operand_src);
21208 }
21209 if (!dest_ty.ptrAllowsZero(mod) and ptr_val.isNull(mod)) {
21210 return sema.fail(block, operand_src, "null pointer casted to type '{}'", .{dest_ty.fmt(mod)});
21211 }
21212 if (dest_align > src_align) {
21213 if (try ptr_val.getUnsignedIntAdvanced(mod, null)) |addr| {
21214 if (addr % dest_align != 0) {
21215 return sema.fail(block, operand_src, "pointer address 0x{X} is not aligned to {d} bytes", .{ addr, dest_align });
21216 }
21217 }
21218 }
21219 if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) {
21220 if (ptr_val.isUndef(mod)) return sema.addConstUndef(dest_ty);
21221 const arr_len = try mod.intValue(Type.usize, src_info.child.toType().arrayLen(mod));
21222 return sema.addConstant((try mod.intern(.{ .ptr = .{
21223 .ty = dest_ty.toIntern(),
21224 .addr = mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr.addr,
21225 .len = arr_len.toIntern(),
21226 } })).toValue());
21227 } else {
21228 assert(dest_ptr_ty.eql(dest_ty, mod));
21229 return sema.addConstant(try mod.getCoerced(ptr_val, dest_ty));
21230 }
2103621231 }
21037 return sema.addConstant(try mod.getCoerced(operand_val, aligned_dest_ty));
2103821232 }
2103921233
2104021234 try sema.requireRuntimeBlock(block, src, null);
21235
2104121236 if (block.wantSafety() and operand_ty.ptrAllowsZero(mod) and !dest_ty.ptrAllowsZero(mod) and
21042 (try sema.typeHasRuntimeBits(dest_ty.elemType2(mod)) or dest_ty.elemType2(mod).zigTypeTag(mod) == .Fn))
21237 (try sema.typeHasRuntimeBits(dest_info.child.toType()) or dest_info.child.toType().zigTypeTag(mod) == .Fn))
2104321238 {
2104421239 const ptr_int = try block.addUnOp(.int_from_ptr, ptr);
2104521240 const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize);
21046 const ok = if (operand_is_slice) ok: {
21047 const len = try sema.analyzeSliceLen(block, operand_src, operand);
21241 const ok = if (src_info.flags.size == .Slice and dest_info.flags.size == .Slice) ok: {
21242 const len = try sema.analyzeSliceLen(block, operand_src, ptr);
2104821243 const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize);
2104921244 break :ok try block.addBinOp(.bit_or, len_zero, is_non_zero);
2105021245 } else is_non_zero;
2105121246 try sema.addSafetyCheck(block, ok, .cast_to_null);
2105221247 }
2105321248
21054 return block.addBitCast(aligned_dest_ty, ptr);
21055}
21056
21057fn zirConstCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
21058 const mod = sema.mod;
21059 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
21060 const src = LazySrcLoc.nodeOffset(extra.node);
21061 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
21062 const operand = try sema.resolveInst(extra.operand);
21063 const operand_ty = sema.typeOf(operand);
21064 try sema.checkPtrOperand(block, operand_src, operand_ty);
21249 if (block.wantSafety() and dest_align > src_align and try sema.typeHasRuntimeBits(dest_info.child.toType())) {
21250 const align_minus_1 = try sema.addConstant(
21251 try mod.intValue(Type.usize, dest_align - 1),
21252 );
21253 const ptr_int = try block.addUnOp(.int_from_ptr, ptr);
21254 const remainder = try block.addBinOp(.bit_and, ptr_int, align_minus_1);
21255 const is_aligned = try block.addBinOp(.cmp_eq, remainder, .zero_usize);
21256 const ok = if (src_info.flags.size == .Slice and dest_info.flags.size == .Slice) ok: {
21257 const len = try sema.analyzeSliceLen(block, operand_src, ptr);
21258 const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize);
21259 break :ok try block.addBinOp(.bit_or, len_zero, is_aligned);
21260 } else is_aligned;
21261 try sema.addSafetyCheck(block, ok, .incorrect_alignment);
21262 }
2106521263
21066 var ptr_info = operand_ty.ptrInfo(mod);
21067 ptr_info.flags.is_const = false;
21068 const dest_ty = try mod.ptrType(ptr_info);
21264 // If we're going from an array pointer to a slice, this will only be the pointer part!
21265 const result_ptr = if (flags.addrspace_cast) ptr: {
21266 // We can't change address spaces with a bitcast, so this requires two instructions
21267 var intermediate_info = src_info;
21268 intermediate_info.flags.address_space = dest_info.flags.address_space;
21269 const intermediate_ptr_ty = try mod.ptrType(intermediate_info);
21270 const intermediate_ty = if (dest_ptr_ty.zigTypeTag(mod) == .Optional) blk: {
21271 break :blk try mod.optionalType(intermediate_ptr_ty.toIntern());
21272 } else intermediate_ptr_ty;
21273 const intermediate = try block.addInst(.{
21274 .tag = .addrspace_cast,
21275 .data = .{ .ty_op = .{
21276 .ty = try sema.addType(intermediate_ty),
21277 .operand = ptr,
21278 } },
21279 });
21280 if (intermediate_ty.eql(dest_ptr_ty, mod)) {
21281 // We only changed the address space, so no need for a bitcast
21282 break :ptr intermediate;
21283 }
21284 break :ptr try block.addBitCast(dest_ptr_ty, intermediate);
21285 } else ptr: {
21286 break :ptr try block.addBitCast(dest_ptr_ty, ptr);
21287 };
2106921288
21070 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
21071 return sema.addConstant(try mod.getCoerced(operand_val, dest_ty));
21289 if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) {
21290 // We have to construct a slice using the operand's child's array length
21291 // Note that we know from the check at the start of the function that operand_ty is slice-like
21292 const arr_len = try sema.addConstant(
21293 try mod.intValue(Type.usize, src_info.child.toType().arrayLen(mod)),
21294 );
21295 return block.addInst(.{
21296 .tag = .slice,
21297 .data = .{ .ty_pl = .{
21298 .ty = try sema.addType(dest_ty),
21299 .payload = try sema.addExtra(Air.Bin{
21300 .lhs = result_ptr,
21301 .rhs = arr_len,
21302 }),
21303 } },
21304 });
21305 } else {
21306 assert(dest_ptr_ty.eql(dest_ty, mod));
21307 return result_ptr;
2107221308 }
21073
21074 try sema.requireRuntimeBlock(block, src, null);
21075 return block.addBitCast(dest_ty, operand);
2107621309}
2107721310
21078fn zirVolatileCast(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 {
2107921312 const mod = sema.mod;
21313 const flags = @as(Zir.Inst.FullPtrCastFlags, @bitCast(@as(u5, @truncate(extended.small))));
2108021314 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
2108121315 const src = LazySrcLoc.nodeOffset(extra.node);
2108221316 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
......@@ -21085,11 +21319,12 @@ fn zirVolatileCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
2108521319 try sema.checkPtrOperand(block, operand_src, operand_ty);
2108621320
2108721321 var ptr_info = operand_ty.ptrInfo(mod);
21088 ptr_info.flags.is_volatile = false;
21322 if (flags.const_cast) ptr_info.flags.is_const = false;
21323 if (flags.volatile_cast) ptr_info.flags.is_volatile = false;
2108921324 const dest_ty = try mod.ptrType(ptr_info);
2109021325
2109121326 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
21092 return sema.addConstant(operand_val);
21327 return sema.addConstant(try mod.getCoerced(operand_val, dest_ty));
2109321328 }
2109421329
2109521330 try sema.requireRuntimeBlock(block, src, null);
......@@ -21100,24 +21335,21 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2110021335 const mod = sema.mod;
2110121336 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2110221337 const src = inst_data.src();
21103 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
21104 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
21338 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2110521339 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
21106 const dest_scalar_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
21340 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, "@truncate");
21341 const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, src);
2110721342 const operand = try sema.resolveInst(extra.rhs);
21108 const dest_is_comptime_int = try sema.checkIntType(block, dest_ty_src, dest_scalar_ty);
2110921343 const operand_ty = sema.typeOf(operand);
2111021344 const operand_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
21111 const is_vector = operand_ty.zigTypeTag(mod) == .Vector;
21112 const dest_ty = if (is_vector)
21113 try mod.vectorType(.{
21114 .len = operand_ty.vectorLen(mod),
21115 .child = dest_scalar_ty.toIntern(),
21116 })
21117 else
21118 dest_scalar_ty;
2111921345
21120 if (dest_is_comptime_int) {
21346 const operand_is_vector = operand_ty.zigTypeTag(mod) == .Vector;
21347 const dest_is_vector = dest_ty.zigTypeTag(mod) == .Vector;
21348 if (operand_is_vector != dest_is_vector) {
21349 return sema.fail(block, operand_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(mod), operand_ty.fmt(mod) });
21350 }
21351
21352 if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) {
2112121353 return sema.coerce(block, dest_ty, operand, operand_src);
2112221354 }
2112321355
......@@ -21147,7 +21379,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2114721379 .{ dest_ty.fmt(mod), operand_ty.fmt(mod) },
2114821380 );
2114921381 errdefer msg.destroy(sema.gpa);
21150 try sema.errNote(block, dest_ty_src, msg, "destination type has {d} bits", .{
21382 try sema.errNote(block, src, msg, "destination type has {d} bits", .{
2115121383 dest_info.bits,
2115221384 });
2115321385 try sema.errNote(block, operand_src, msg, "operand type has {d} bits", .{
......@@ -21161,7 +21393,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2116121393
2116221394 if (try sema.resolveMaybeUndefValIntable(operand)) |val| {
2116321395 if (val.isUndef(mod)) return sema.addConstUndef(dest_ty);
21164 if (!is_vector) {
21396 if (!dest_is_vector) {
2116521397 return sema.addConstant(try mod.getCoerced(
2116621398 try val.intTrunc(operand_ty, sema.arena, dest_info.signedness, dest_info.bits, mod),
2116721399 dest_ty,
......@@ -21182,59 +21414,6 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2118221414 return block.addTyOp(.trunc, dest_ty, operand);
2118321415}
2118421416
21185fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21186 const mod = sema.mod;
21187 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
21188 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
21189 const align_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
21190 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
21191 const dest_align = try sema.resolveAlign(block, align_src, extra.lhs);
21192 const ptr = try sema.resolveInst(extra.rhs);
21193 const ptr_ty = sema.typeOf(ptr);
21194
21195 try sema.checkPtrOperand(block, ptr_src, ptr_ty);
21196
21197 var ptr_info = ptr_ty.ptrInfo(mod);
21198 ptr_info.flags.alignment = dest_align;
21199 var dest_ty = try mod.ptrType(ptr_info);
21200 if (ptr_ty.zigTypeTag(mod) == .Optional) {
21201 dest_ty = try mod.optionalType(dest_ty.toIntern());
21202 }
21203
21204 if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |val| {
21205 if (try val.getUnsignedIntAdvanced(mod, null)) |addr| {
21206 const dest_align_bytes = dest_align.toByteUnitsOptional().?;
21207 if (addr % dest_align_bytes != 0) {
21208 return sema.fail(block, ptr_src, "pointer address 0x{X} is not aligned to {d} bytes", .{ addr, dest_align_bytes });
21209 }
21210 }
21211 return sema.addConstant(try mod.getCoerced(val, dest_ty));
21212 }
21213
21214 try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src);
21215 if (block.wantSafety() and dest_align.order(Alignment.fromNonzeroByteUnits(1)).compare(.gt) and
21216 try sema.typeHasRuntimeBits(ptr_info.child.toType()))
21217 {
21218 const align_minus_1 = try sema.addConstant(
21219 try mod.intValue(Type.usize, dest_align.toByteUnitsOptional().? - 1),
21220 );
21221 const actual_ptr = if (ptr_ty.isSlice(mod))
21222 try sema.analyzeSlicePtr(block, ptr_src, ptr, ptr_ty)
21223 else
21224 ptr;
21225 const ptr_int = try block.addUnOp(.int_from_ptr, actual_ptr);
21226 const remainder = try block.addBinOp(.bit_and, ptr_int, align_minus_1);
21227 const is_aligned = try block.addBinOp(.cmp_eq, remainder, .zero_usize);
21228 const ok = if (ptr_ty.isSlice(mod)) ok: {
21229 const len = try sema.analyzeSliceLen(block, ptr_src, ptr);
21230 const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize);
21231 break :ok try block.addBinOp(.bit_or, len_zero, is_aligned);
21232 } else is_aligned;
21233 try sema.addSafetyCheck(block, ok, .incorrect_alignment);
21234 }
21235 return sema.bitCast(block, dest_ty, ptr, ptr_src, null);
21236}
21237
2123821417fn zirBitCount(
2123921418 sema: *Sema,
2124021419 block: *Block,
......@@ -21546,7 +21725,7 @@ fn checkPtrOperand(
2154621725 };
2154721726 return sema.failWithOwnedErrorMsg(msg);
2154821727 },
21549 .Optional => if (ty.isPtrLikeOptional(mod)) return,
21728 .Optional => if (ty.childType(mod).zigTypeTag(mod) == .Pointer) return,
2155021729 else => {},
2155121730 }
2155221731 return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(mod)});
......@@ -21577,7 +21756,7 @@ fn checkPtrType(
2157721756 };
2157821757 return sema.failWithOwnedErrorMsg(msg);
2157921758 },
21580 .Optional => if (ty.isPtrLikeOptional(mod)) return,
21759 .Optional => if (ty.childType(mod).zigTypeTag(mod) == .Pointer) return,
2158121760 else => {},
2158221761 }
2158321762 return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(mod)});
......@@ -22092,7 +22271,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2209222271 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2209322272 const len_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
2209422273 const scalar_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
22095 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")));
2209622275 const scalar = try sema.resolveInst(extra.rhs);
2209722276 const scalar_ty = sema.typeOf(scalar);
2209822277 try sema.checkVectorElemType(block, scalar_src, scalar_ty);
......@@ -22197,12 +22376,12 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2219722376 else => return sema.fail(block, mask_src, "expected vector or array, found '{}'", .{sema.typeOf(mask).fmt(sema.mod)}),
2219822377 };
2219922378 mask_ty = try mod.vectorType(.{
22200 .len = @intCast(u32, mask_len),
22379 .len = @as(u32, @intCast(mask_len)),
2220122380 .child = .i32_type,
2220222381 });
2220322382 mask = try sema.coerce(block, mask_ty, mask, mask_src);
2220422383 const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask, "shuffle mask must be comptime-known");
22205 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)));
2220622385}
2220722386
2220822387fn analyzeShuffle(
......@@ -22246,8 +22425,8 @@ fn analyzeShuffle(
2224622425 if (maybe_a_len == null and maybe_b_len == null) {
2224722426 return sema.addConstUndef(res_ty);
2224822427 }
22249 const a_len = @intCast(u32, maybe_a_len orelse maybe_b_len.?);
22250 const b_len = @intCast(u32, maybe_b_len orelse a_len);
22428 const a_len = @as(u32, @intCast(maybe_a_len orelse maybe_b_len.?));
22429 const b_len = @as(u32, @intCast(maybe_b_len orelse a_len));
2225122430
2225222431 const a_ty = try mod.vectorType(.{
2225322432 .len = a_len,
......@@ -22266,17 +22445,17 @@ fn analyzeShuffle(
2226622445 .{ b_len, b_src, b_ty },
2226722446 };
2226822447
22269 for (0..@intCast(usize, mask_len)) |i| {
22448 for (0..@as(usize, @intCast(mask_len))) |i| {
2227022449 const elem = try mask.elemValue(sema.mod, i);
2227122450 if (elem.isUndef(mod)) continue;
2227222451 const int = elem.toSignedInt(mod);
2227322452 var unsigned: u32 = undefined;
2227422453 var chosen: u32 = undefined;
2227522454 if (int >= 0) {
22276 unsigned = @intCast(u32, int);
22455 unsigned = @as(u32, @intCast(int));
2227722456 chosen = 0;
2227822457 } else {
22279 unsigned = @intCast(u32, ~int);
22458 unsigned = @as(u32, @intCast(~int));
2228022459 chosen = 1;
2228122460 }
2228222461 if (unsigned >= operand_info[chosen][0]) {
......@@ -22309,7 +22488,7 @@ fn analyzeShuffle(
2230922488 continue;
2231022489 }
2231122490 const int = mask_elem_val.toSignedInt(mod);
22312 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));
2231322492 values[i] = try (try (if (int >= 0) a_val else b_val).elemValue(mod, unsigned)).intern(elem_ty, mod);
2231422493 }
2231522494 return sema.addConstant((try mod.intern(.{ .aggregate = .{
......@@ -22330,23 +22509,23 @@ fn analyzeShuffle(
2233022509 const max_len = try sema.usizeCast(block, max_src, @max(a_len, b_len));
2233122510
2233222511 const expand_mask_values = try sema.arena.alloc(InternPool.Index, max_len);
22333 for (@intCast(usize, 0)..@intCast(usize, min_len)) |i| {
22512 for (@as(usize, @intCast(0))..@as(usize, @intCast(min_len))) |i| {
2233422513 expand_mask_values[i] = (try mod.intValue(Type.comptime_int, i)).toIntern();
2233522514 }
22336 for (@intCast(usize, min_len)..@intCast(usize, max_len)) |i| {
22515 for (@as(usize, @intCast(min_len))..@as(usize, @intCast(max_len))) |i| {
2233722516 expand_mask_values[i] = (try mod.intValue(Type.comptime_int, -1)).toIntern();
2233822517 }
2233922518 const expand_mask = try mod.intern(.{ .aggregate = .{
22340 .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(),
2234122520 .storage = .{ .elems = expand_mask_values },
2234222521 } });
2234322522
2234422523 if (a_len < b_len) {
2234522524 const undef = try sema.addConstUndef(a_ty);
22346 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)));
2234722526 } else {
2234822527 const undef = try sema.addConstUndef(b_ty);
22349 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)));
2235022529 }
2235122530 }
2235222531
......@@ -22383,7 +22562,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2238322562 .Vector, .Array => pred_ty.arrayLen(mod),
2238422563 else => return sema.fail(block, pred_src, "expected vector or array, found '{}'", .{pred_ty.fmt(mod)}),
2238522564 };
22386 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)));
2238722566
2238822567 const bool_vec_ty = try mod.vectorType(.{
2238922568 .len = vec_len,
......@@ -22751,7 +22930,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2275122930
2275222931 var resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(mod));
2275322932 for (resolved_args, 0..) |*resolved, i| {
22754 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);
2275522934 }
2275622935
2275722936 const callee_ty = sema.typeOf(func);
......@@ -22869,7 +23048,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
2286923048 .ty = try sema.addType(result_ptr),
2287023049 .payload = try block.sema.addExtra(Air.FieldParentPtr{
2287123050 .field_ptr = casted_field_ptr,
22872 .field_index = @intCast(u32, field_index),
23051 .field_index = @as(u32, @intCast(field_index)),
2287323052 }),
2287423053 } },
2287523054 });
......@@ -23505,7 +23684,7 @@ fn zirVarExtended(
2350523684 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
2350623685 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };
2350723686 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };
23508 const small = @bitCast(Zir.Inst.ExtendedVar.Small, extended.small);
23687 const small = @as(Zir.Inst.ExtendedVar.Small, @bitCast(extended.small));
2350923688
2351023689 var extra_index: usize = extra.end;
2351123690
......@@ -23520,7 +23699,7 @@ fn zirVarExtended(
2352023699 assert(!small.has_align);
2352123700
2352223701 const uncasted_init: Air.Inst.Ref = if (small.has_init) blk: {
23523 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]));
2352423703 extra_index += 1;
2352523704 break :blk try sema.resolveInst(init_ref);
2352623705 } else .none;
......@@ -23597,7 +23776,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2359723776 if (val.isGenericPoison()) {
2359823777 break :blk null;
2359923778 }
23600 const alignment = @intCast(u32, val.toUnsignedInt(mod));
23779 const alignment = @as(u32, @intCast(val.toUnsignedInt(mod)));
2360123780 try sema.validateAlign(block, align_src, alignment);
2360223781 if (alignment == target_util.defaultFunctionAlignment(target)) {
2360323782 break :blk .none;
......@@ -23605,7 +23784,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2360523784 break :blk Alignment.fromNonzeroByteUnits(alignment);
2360623785 }
2360723786 } else if (extra.data.bits.has_align_ref) blk: {
23608 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]));
2360923788 extra_index += 1;
2361023789 const align_tv = sema.resolveInstConst(block, align_src, align_ref, "alignment must be comptime-known") catch |err| switch (err) {
2361123790 error.GenericPoison => {
......@@ -23613,7 +23792,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2361323792 },
2361423793 else => |e| return e,
2361523794 };
23616 const alignment = @intCast(u32, align_tv.val.toUnsignedInt(mod));
23795 const alignment = @as(u32, @intCast(align_tv.val.toUnsignedInt(mod)));
2361723796 try sema.validateAlign(block, align_src, alignment);
2361823797 if (alignment == target_util.defaultFunctionAlignment(target)) {
2361923798 break :blk .none;
......@@ -23635,7 +23814,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2363523814 }
2363623815 break :blk mod.toEnum(std.builtin.AddressSpace, val);
2363723816 } else if (extra.data.bits.has_addrspace_ref) blk: {
23638 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]));
2363923818 extra_index += 1;
2364023819 const addrspace_tv = sema.resolveInstConst(block, addrspace_src, addrspace_ref, "addrespace must be comptime-known") catch |err| switch (err) {
2364123820 error.GenericPoison => {
......@@ -23659,7 +23838,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2365923838 }
2366023839 break :blk FuncLinkSection{ .explicit = try val.toIpString(ty, mod) };
2366123840 } else if (extra.data.bits.has_section_ref) blk: {
23662 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]));
2366323842 extra_index += 1;
2366423843 const section_name = sema.resolveConstStringIntern(block, section_src, section_ref, "linksection must be comptime-known") catch |err| switch (err) {
2366523844 error.GenericPoison => {
......@@ -23683,7 +23862,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2368323862 }
2368423863 break :blk mod.toEnum(std.builtin.CallingConvention, val);
2368523864 } else if (extra.data.bits.has_cc_ref) blk: {
23686 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]));
2368723866 extra_index += 1;
2368823867 const cc_tv = sema.resolveInstConst(block, cc_src, cc_ref, "calling convention must be comptime-known") catch |err| switch (err) {
2368923868 error.GenericPoison => {
......@@ -23707,7 +23886,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2370723886 const ty = val.toType();
2370823887 break :blk ty;
2370923888 } else if (extra.data.bits.has_ret_ty_ref) blk: {
23710 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]));
2371123890 extra_index += 1;
2371223891 const ret_ty_tv = sema.resolveInstConst(block, ret_src, ret_ty_ref, "return type must be comptime-known") catch |err| switch (err) {
2371323892 error.GenericPoison => {
......@@ -23816,7 +23995,7 @@ fn zirWasmMemorySize(
2381623995 return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
2381723996 }
2381823997
23819 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")));
2382023999 try sema.requireRuntimeBlock(block, builtin_src, null);
2382124000 return block.addInst(.{
2382224001 .tag = .wasm_memory_size,
......@@ -23841,7 +24020,7 @@ fn zirWasmMemoryGrow(
2384124020 return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
2384224021 }
2384324022
23844 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")));
2384524024 const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src);
2384624025
2384724026 try sema.requireRuntimeBlock(block, builtin_src, null);
......@@ -23881,7 +24060,7 @@ fn resolvePrefetchOptions(
2388124060
2388224061 return std.builtin.PrefetchOptions{
2388324062 .rw = mod.toEnum(std.builtin.PrefetchOptions.Rw, rw_val),
23884 .locality = @intCast(u2, locality_val.toUnsignedInt(mod)),
24063 .locality = @as(u2, @intCast(locality_val.toUnsignedInt(mod))),
2388524064 .cache = mod.toEnum(std.builtin.PrefetchOptions.Cache, cache_val),
2388624065 };
2388724066}
......@@ -24080,7 +24259,7 @@ fn zirWorkItem(
2408024259 },
2408124260 }
2408224261
24083 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")));
2408424263 try sema.requireRuntimeBlock(block, builtin_src, null);
2408524264
2408624265 return block.addInst(.{
......@@ -24635,7 +24814,7 @@ fn addSafetyCheckExtra(
2463524814 fail_block.instructions.items.len);
2463624815
2463724816 try sema.air_instructions.ensureUnusedCapacity(gpa, 3);
24638 const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);
24817 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
2463924818 const cond_br_inst = block_inst + 1;
2464024819 const br_inst = cond_br_inst + 1;
2464124820 sema.air_instructions.appendAssumeCapacity(.{
......@@ -24655,7 +24834,7 @@ fn addSafetyCheckExtra(
2465524834 .operand = ok,
2465624835 .payload = sema.addExtraAssumeCapacity(Air.CondBr{
2465724836 .then_body_len = 1,
24658 .else_body_len = @intCast(u32, fail_block.instructions.items.len),
24837 .else_body_len = @as(u32, @intCast(fail_block.instructions.items.len)),
2465924838 }),
2466024839 } },
2466124840 });
......@@ -25031,7 +25210,7 @@ fn fieldVal(
2503125210 const union_ty = try sema.resolveTypeFields(child_type);
2503225211 if (union_ty.unionTagType(mod)) |enum_ty| {
2503325212 if (enum_ty.enumFieldIndex(field_name, mod)) |field_index_usize| {
25034 const field_index = @intCast(u32, field_index_usize);
25213 const field_index = @as(u32, @intCast(field_index_usize));
2503525214 return sema.addConstant(
2503625215 try mod.enumValueFieldIndex(enum_ty, field_index),
2503725216 );
......@@ -25047,7 +25226,7 @@ fn fieldVal(
2504725226 }
2504825227 const field_index_usize = child_type.enumFieldIndex(field_name, mod) orelse
2504925228 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
25050 const field_index = @intCast(u32, field_index_usize);
25229 const field_index = @as(u32, @intCast(field_index_usize));
2505125230 const enum_val = try mod.enumValueFieldIndex(child_type, field_index);
2505225231 return sema.addConstant(enum_val);
2505325232 },
......@@ -25259,7 +25438,7 @@ fn fieldPtr(
2525925438 const union_ty = try sema.resolveTypeFields(child_type);
2526025439 if (union_ty.unionTagType(mod)) |enum_ty| {
2526125440 if (enum_ty.enumFieldIndex(field_name, mod)) |field_index| {
25262 const field_index_u32 = @intCast(u32, field_index);
25441 const field_index_u32 = @as(u32, @intCast(field_index));
2526325442 var anon_decl = try block.startAnonDecl();
2526425443 defer anon_decl.deinit();
2526525444 return sema.analyzeDeclRef(try anon_decl.finish(
......@@ -25280,7 +25459,7 @@ fn fieldPtr(
2528025459 const field_index = child_type.enumFieldIndex(field_name, mod) orelse {
2528125460 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
2528225461 };
25283 const field_index_u32 = @intCast(u32, field_index);
25462 const field_index_u32 = @as(u32, @intCast(field_index));
2528425463 var anon_decl = try block.startAnonDecl();
2528525464 defer anon_decl.deinit();
2528625465 return sema.analyzeDeclRef(try anon_decl.finish(
......@@ -25365,7 +25544,7 @@ fn fieldCallBind(
2536525544 if (mod.typeToStruct(struct_ty)) |struct_obj| {
2536625545 const field_index_usize = struct_obj.fields.getIndex(field_name) orelse
2536725546 break :find_field;
25368 const field_index = @intCast(u32, field_index_usize);
25547 const field_index = @as(u32, @intCast(field_index_usize));
2536925548 const field = struct_obj.fields.values()[field_index];
2537025549
2537125550 return sema.finishFieldCallBind(block, src, ptr_ty, field.ty, field_index, object_ptr);
......@@ -25380,7 +25559,7 @@ fn fieldCallBind(
2538025559 } else {
2538125560 const max = struct_ty.structFieldCount(mod);
2538225561 for (0..max) |i_usize| {
25383 const i = @intCast(u32, i_usize);
25562 const i = @as(u32, @intCast(i_usize));
2538425563 if (field_name == struct_ty.structFieldName(i, mod)) {
2538525564 return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(i, mod), i, object_ptr);
2538625565 }
......@@ -25391,7 +25570,7 @@ fn fieldCallBind(
2539125570 const union_ty = try sema.resolveTypeFields(concrete_ty);
2539225571 const fields = union_ty.unionFields(mod);
2539325572 const field_index_usize = fields.getIndex(field_name) orelse break :find_field;
25394 const field_index = @intCast(u32, field_index_usize);
25573 const field_index = @as(u32, @intCast(field_index_usize));
2539525574 const field = fields.values()[field_index];
2539625575
2539725576 return sema.finishFieldCallBind(block, src, ptr_ty, field.ty, field_index, object_ptr);
......@@ -25613,7 +25792,7 @@ fn structFieldPtr(
2561325792
2561425793 const field_index_big = struct_obj.fields.getIndex(field_name) orelse
2561525794 return sema.failWithBadStructFieldAccess(block, struct_obj, field_name_src, field_name);
25616 const field_index = @intCast(u32, field_index_big);
25795 const field_index = @as(u32, @intCast(field_index_big));
2561725796
2561825797 return sema.structFieldPtrByIndex(block, src, struct_ptr, field_index, field_name_src, struct_ty, initializing);
2561925798}
......@@ -25659,7 +25838,7 @@ fn structFieldPtrByIndex(
2565925838 if (i == field_index) {
2566025839 ptr_ty_data.packed_offset.bit_offset = running_bits;
2566125840 }
25662 running_bits += @intCast(u16, f.ty.bitSize(mod));
25841 running_bits += @as(u16, @intCast(f.ty.bitSize(mod)));
2566325842 }
2566425843 ptr_ty_data.packed_offset.host_size = (running_bits + 7) / 8;
2566525844
......@@ -25689,7 +25868,7 @@ fn structFieldPtrByIndex(
2568925868 const elem_size_bits = ptr_ty_data.child.toType().bitSize(mod);
2569025869 if (elem_size_bytes * 8 == elem_size_bits) {
2569125870 const byte_offset = ptr_ty_data.packed_offset.bit_offset / 8;
25692 const new_align = @enumFromInt(Alignment, @ctz(byte_offset | parent_align));
25871 const new_align = @as(Alignment, @enumFromInt(@ctz(byte_offset | parent_align)));
2569325872 assert(new_align != .none);
2569425873 ptr_ty_data.flags.alignment = new_align;
2569525874 ptr_ty_data.packed_offset = .{ .host_size = 0, .bit_offset = 0 };
......@@ -25744,7 +25923,7 @@ fn structFieldVal(
2574425923
2574525924 const field_index_usize = struct_obj.fields.getIndex(field_name) orelse
2574625925 return sema.failWithBadStructFieldAccess(block, struct_obj, field_name_src, field_name);
25747 const field_index = @intCast(u32, field_index_usize);
25926 const field_index = @as(u32, @intCast(field_index_usize));
2574825927 const field = struct_obj.fields.values()[field_index];
2574925928
2575025929 if (field.is_comptime) {
......@@ -25879,7 +26058,7 @@ fn unionFieldPtr(
2587926058 .address_space = union_ptr_ty.ptrAddressSpace(mod),
2588026059 },
2588126060 });
25882 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).?));
2588326062
2588426063 if (initializing and field.ty.zigTypeTag(mod) == .NoReturn) {
2588526064 const msg = msg: {
......@@ -25967,7 +26146,7 @@ fn unionFieldVal(
2596726146 const union_obj = mod.typeToUnion(union_ty).?;
2596826147 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);
2596926148 const field = union_obj.fields.values()[field_index];
25970 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).?));
2597126150
2597226151 if (try sema.resolveMaybeUndefVal(union_byval)) |union_val| {
2597326152 if (union_val.isUndef(mod)) return sema.addConstUndef(field.ty);
......@@ -26047,7 +26226,7 @@ fn elemPtr(
2604726226 .Struct => {
2604826227 // Tuple field access.
2604926228 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known");
26050 const index = @intCast(u32, index_val.toUnsignedInt(mod));
26229 const index = @as(u32, @intCast(index_val.toUnsignedInt(mod)));
2605126230 return sema.tupleFieldPtr(block, src, indexable_ptr, elem_index_src, index, init);
2605226231 },
2605326232 else => {
......@@ -26082,7 +26261,7 @@ fn elemPtrOneLayerOnly(
2608226261 const runtime_src = rs: {
2608326262 const ptr_val = maybe_ptr_val orelse break :rs indexable_src;
2608426263 const index_val = maybe_index_val orelse break :rs elem_index_src;
26085 const index = @intCast(usize, index_val.toUnsignedInt(mod));
26264 const index = @as(usize, @intCast(index_val.toUnsignedInt(mod)));
2608626265 const result_ty = try sema.elemPtrType(indexable_ty, index);
2608726266 const elem_ptr = try ptr_val.elemPtr(result_ty, index, mod);
2608826267 return sema.addConstant(elem_ptr);
......@@ -26101,7 +26280,7 @@ fn elemPtrOneLayerOnly(
2610126280 .Struct => {
2610226281 assert(child_ty.isTuple(mod));
2610326282 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known");
26104 const index = @intCast(u32, index_val.toUnsignedInt(mod));
26283 const index = @as(u32, @intCast(index_val.toUnsignedInt(mod)));
2610526284 return sema.tupleFieldPtr(block, indexable_src, indexable, elem_index_src, index, false);
2610626285 },
2610726286 else => unreachable, // Guaranteed by checkIndexable
......@@ -26139,7 +26318,7 @@ fn elemVal(
2613926318 const runtime_src = rs: {
2614026319 const indexable_val = maybe_indexable_val orelse break :rs indexable_src;
2614126320 const index_val = maybe_index_val orelse break :rs elem_index_src;
26142 const index = @intCast(usize, index_val.toUnsignedInt(mod));
26321 const index = @as(usize, @intCast(index_val.toUnsignedInt(mod)));
2614326322 const elem_ty = indexable_ty.elemType2(mod);
2614426323 const many_ptr_ty = try mod.manyConstPtrType(elem_ty);
2614526324 const many_ptr_val = try mod.getCoerced(indexable_val, many_ptr_ty);
......@@ -26176,7 +26355,7 @@ fn elemVal(
2617626355 .Struct => {
2617726356 // Tuple field access.
2617826357 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known");
26179 const index = @intCast(u32, index_val.toUnsignedInt(mod));
26358 const index = @as(u32, @intCast(index_val.toUnsignedInt(mod)));
2618026359 return sema.tupleField(block, indexable_src, indexable, elem_index_src, index);
2618126360 },
2618226361 else => unreachable,
......@@ -26337,7 +26516,7 @@ fn elemValArray(
2633726516 const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index);
2633826517
2633926518 if (maybe_index_val) |index_val| {
26340 const index = @intCast(usize, index_val.toUnsignedInt(mod));
26519 const index = @as(usize, @intCast(index_val.toUnsignedInt(mod)));
2634126520 if (array_sent) |s| {
2634226521 if (index == array_len) {
2634326522 return sema.addConstant(s);
......@@ -26353,7 +26532,7 @@ fn elemValArray(
2635326532 return sema.addConstUndef(elem_ty);
2635426533 }
2635526534 if (maybe_index_val) |index_val| {
26356 const index = @intCast(usize, index_val.toUnsignedInt(mod));
26535 const index = @as(usize, @intCast(index_val.toUnsignedInt(mod)));
2635726536 const elem_val = try array_val.elemValue(mod, index);
2635826537 return sema.addConstant(elem_val);
2635926538 }
......@@ -26465,7 +26644,7 @@ fn elemValSlice(
2646526644 return sema.fail(block, slice_src, "indexing into empty slice is not allowed", .{});
2646626645 }
2646726646 if (maybe_index_val) |index_val| {
26468 const index = @intCast(usize, index_val.toUnsignedInt(mod));
26647 const index = @as(usize, @intCast(index_val.toUnsignedInt(mod)));
2646926648 if (index >= slice_len_s) {
2647026649 const sentinel_label: []const u8 = if (slice_sent) " +1 (sentinel)" else "";
2647126650 return sema.fail(block, elem_index_src, "index {d} outside slice of length {d}{s}", .{ index, slice_len, sentinel_label });
......@@ -27108,7 +27287,7 @@ fn coerceExtra(
2710827287 return sema.failWithOwnedErrorMsg(msg);
2710927288 };
2711027289 return sema.addConstant(
27111 try mod.enumValueFieldIndex(dest_ty, @intCast(u32, field_index)),
27290 try mod.enumValueFieldIndex(dest_ty, @as(u32, @intCast(field_index))),
2711227291 );
2711327292 },
2711427293 .Union => blk: {
......@@ -27513,8 +27692,8 @@ const InMemoryCoercionResult = union(enum) {
2751327692 var index: u6 = 0;
2751427693 var actual_noalias = false;
2751527694 while (true) : (index += 1) {
27516 const actual = @truncate(u1, param.actual >> index);
27517 const wanted = @truncate(u1, param.wanted >> index);
27695 const actual = @as(u1, @truncate(param.actual >> index));
27696 const wanted = @as(u1, @truncate(param.wanted >> index));
2751827697 if (actual != wanted) {
2751927698 actual_noalias = actual == 1;
2752027699 break;
......@@ -28039,7 +28218,7 @@ fn coerceInMemoryAllowedFns(
2803928218 const dest_param_ty = dest_info.param_types[param_i].toType();
2804028219 const src_param_ty = src_info.param_types[param_i].toType();
2804128220
28042 const param_i_small = @intCast(u5, param_i);
28221 const param_i_small = @as(u5, @intCast(param_i));
2804328222 if (dest_info.paramIsComptime(param_i_small) != src_info.paramIsComptime(param_i_small)) {
2804428223 return InMemoryCoercionResult{ .fn_param_comptime = .{
2804528224 .index = param_i,
......@@ -28653,7 +28832,7 @@ fn beginComptimePtrMutation(
2865328832 // bytes.len may be one greater than dest_len because of the case when
2865428833 // assigning `[N:S]T` to `[N]T`. This is allowed; the sentinel is omitted.
2865528834 assert(bytes.len >= dest_len);
28656 const elems = try arena.alloc(Value, @intCast(usize, dest_len));
28835 const elems = try arena.alloc(Value, @as(usize, @intCast(dest_len)));
2865728836 for (elems, 0..) |*elem, i| {
2865828837 elem.* = try mod.intValue(elem_ty, bytes[i]);
2865928838 }
......@@ -28665,7 +28844,7 @@ fn beginComptimePtrMutation(
2866528844 block,
2866628845 src,
2866728846 elem_ty,
28668 &elems[@intCast(usize, elem_ptr.index)],
28847 &elems[@as(usize, @intCast(elem_ptr.index))],
2866928848 ptr_elem_ty,
2867028849 parent.mut_decl,
2867128850 );
......@@ -28693,7 +28872,7 @@ fn beginComptimePtrMutation(
2869328872 block,
2869428873 src,
2869528874 elem_ty,
28696 &elems[@intCast(usize, elem_ptr.index)],
28875 &elems[@as(usize, @intCast(elem_ptr.index))],
2869728876 ptr_elem_ty,
2869828877 parent.mut_decl,
2869928878 );
......@@ -28704,7 +28883,7 @@ fn beginComptimePtrMutation(
2870428883 block,
2870528884 src,
2870628885 elem_ty,
28707 &val_ptr.castTag(.aggregate).?.data[@intCast(usize, elem_ptr.index)],
28886 &val_ptr.castTag(.aggregate).?.data[@as(usize, @intCast(elem_ptr.index))],
2870828887 ptr_elem_ty,
2870928888 parent.mut_decl,
2871028889 ),
......@@ -28730,7 +28909,7 @@ fn beginComptimePtrMutation(
2873028909 block,
2873128910 src,
2873228911 elem_ty,
28733 &elems[@intCast(usize, elem_ptr.index)],
28912 &elems[@as(usize, @intCast(elem_ptr.index))],
2873428913 ptr_elem_ty,
2873528914 parent.mut_decl,
2873628915 );
......@@ -28785,7 +28964,7 @@ fn beginComptimePtrMutation(
2878528964 },
2878628965 .field => |field_ptr| {
2878728966 const base_child_ty = mod.intern_pool.typeOf(field_ptr.base).toType().childType(mod);
28788 const field_index = @intCast(u32, field_ptr.index);
28967 const field_index = @as(u32, @intCast(field_ptr.index));
2878928968
2879028969 var parent = try sema.beginComptimePtrMutation(block, src, field_ptr.base.toValue(), base_child_ty);
2879128970 switch (parent.pointee) {
......@@ -29222,12 +29401,12 @@ fn beginComptimePtrLoad(
2922229401 }
2922329402 deref.pointee = TypedValue{
2922429403 .ty = elem_ty,
29225 .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))),
2922629405 };
2922729406 break :blk deref;
2922829407 },
2922929408 .field => |field_ptr| blk: {
29230 const field_index = @intCast(u32, field_ptr.index);
29409 const field_index = @as(u32, @intCast(field_ptr.index));
2923129410 const container_ty = mod.intern_pool.typeOf(field_ptr.base).toType().childType(mod);
2923229411 var deref = try sema.beginComptimePtrLoad(block, src, field_ptr.base.toValue(), container_ty);
2923329412
......@@ -29811,7 +29990,7 @@ fn coerceTupleToArray(
2981129990
2981229991 var runtime_src: ?LazySrcLoc = null;
2981329992 for (element_vals, element_refs, 0..) |*val, *ref, i_usize| {
29814 const i = @intCast(u32, i_usize);
29993 const i = @as(u32, @intCast(i_usize));
2981529994 if (i_usize == inst_len) {
2981629995 const sentinel_val = dest_ty.sentinel(mod).?;
2981729996 val.* = sentinel_val.toIntern();
......@@ -29922,7 +30101,7 @@ fn coerceTupleToStruct(
2992230101 else => unreachable,
2992330102 };
2992430103 for (0..field_count) |field_index_usize| {
29925 const field_i = @intCast(u32, field_index_usize);
30104 const field_i = @as(u32, @intCast(field_index_usize));
2992630105 const field_src = inst_src; // TODO better source location
2992730106 // https://github.com/ziglang/zig/issues/15709
2992830107 const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) {
......@@ -30038,7 +30217,7 @@ fn coerceTupleToTuple(
3003830217
3003930218 var runtime_src: ?LazySrcLoc = null;
3004030219 for (0..dest_field_count) |field_index_usize| {
30041 const field_i = @intCast(u32, field_index_usize);
30220 const field_i = @as(u32, @intCast(field_index_usize));
3004230221 const field_src = inst_src; // TODO better source location
3004330222 // https://github.com/ziglang/zig/issues/15709
3004430223 const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) {
......@@ -31353,7 +31532,7 @@ fn compareIntsOnlyPossibleResult(
3135331532
3135431533 const ty = try mod.intType(
3135531534 if (is_negative) .signed else .unsigned,
31356 @intCast(u16, req_bits),
31535 @as(u16, @intCast(req_bits)),
3135731536 );
3135831537 const pop_count = lhs_val.popCount(ty, mod);
3135931538
......@@ -32115,7 +32294,7 @@ fn resolvePeerTypesInner(
3211532294 };
3211632295
3211732296 return .{ .success = try mod.vectorType(.{
32118 .len = @intCast(u32, len.?),
32297 .len = @as(u32, @intCast(len.?)),
3211932298 .child = child_ty.toIntern(),
3212032299 }) };
3212132300 },
......@@ -33223,7 +33402,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
3322333402
3322433403 for (struct_obj.fields.values(), 0..) |field, i| {
3322533404 optimized_order[i] = if (try sema.typeHasRuntimeBits(field.ty))
33226 @intCast(u32, i)
33405 @as(u32, @intCast(i))
3322733406 else
3322833407 Module.Struct.omitted_field;
3322933408 }
......@@ -33264,7 +33443,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
3326433443 const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir;
3326533444 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;
3326633445 assert(extended.opcode == .struct_decl);
33267 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
33446 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
3326833447
3326933448 if (small.has_backing_int) {
3327033449 var extra_index: usize = extended.operand;
......@@ -33318,7 +33497,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
3331833497 const backing_int_src: LazySrcLoc = .{ .node_offset_container_tag = 0 };
3331933498 const backing_int_ty = blk: {
3332033499 if (backing_int_body_len == 0) {
33321 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]));
3332233501 break :blk try sema.resolveType(&block, backing_int_src, backing_int_ref);
3332333502 } else {
3332433503 const body = zir.extra[extra_index..][0..backing_int_body_len];
......@@ -33364,7 +33543,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
3336433543 };
3336533544 return sema.fail(&block, LazySrcLoc.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});
3336633545 }
33367 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)));
3336833547 }
3336933548}
3337033549
......@@ -33999,7 +34178,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
3399934178 const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir;
3400034179 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;
3400134180 assert(extended.opcode == .struct_decl);
34002 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
34181 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
3400334182 var extra_index: usize = extended.operand;
3400434183
3400534184 const src = LazySrcLoc.nodeOffset(0);
......@@ -34109,13 +34288,13 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
3410934288 cur_bit_bag = zir.extra[bit_bag_index];
3411034289 bit_bag_index += 1;
3411134290 }
34112 const has_align = @truncate(u1, cur_bit_bag) != 0;
34291 const has_align = @as(u1, @truncate(cur_bit_bag)) != 0;
3411334292 cur_bit_bag >>= 1;
34114 const has_init = @truncate(u1, cur_bit_bag) != 0;
34293 const has_init = @as(u1, @truncate(cur_bit_bag)) != 0;
3411534294 cur_bit_bag >>= 1;
34116 const is_comptime = @truncate(u1, cur_bit_bag) != 0;
34295 const is_comptime = @as(u1, @truncate(cur_bit_bag)) != 0;
3411734296 cur_bit_bag >>= 1;
34118 const has_type_body = @truncate(u1, cur_bit_bag) != 0;
34297 const has_type_body = @as(u1, @truncate(cur_bit_bag)) != 0;
3411934298 cur_bit_bag >>= 1;
3412034299
3412134300 var field_name_zir: ?[:0]const u8 = null;
......@@ -34130,7 +34309,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
3413034309 if (has_type_body) {
3413134310 fields[field_i].type_body_len = zir.extra[extra_index];
3413234311 } else {
34133 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]));
3413434313 }
3413534314 extra_index += 1;
3413634315
......@@ -34350,14 +34529,14 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
3435034529 const zir = mod.namespacePtr(union_obj.namespace).file_scope.zir;
3435134530 const extended = zir.instructions.items(.data)[union_obj.zir_index].extended;
3435234531 assert(extended.opcode == .union_decl);
34353 const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small);
34532 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));
3435434533 var extra_index: usize = extended.operand;
3435534534
3435634535 const src = LazySrcLoc.nodeOffset(0);
3435734536 extra_index += @intFromBool(small.has_src_node);
3435834537
3435934538 const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: {
34360 const ty_ref = @enumFromInt(Zir.Inst.Ref, zir.extra[extra_index]);
34539 const ty_ref = @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index]));
3436134540 extra_index += 1;
3436234541 break :blk ty_ref;
3436334542 } else .none;
......@@ -34505,13 +34684,13 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
3450534684 cur_bit_bag = zir.extra[bit_bag_index];
3450634685 bit_bag_index += 1;
3450734686 }
34508 const has_type = @truncate(u1, cur_bit_bag) != 0;
34687 const has_type = @as(u1, @truncate(cur_bit_bag)) != 0;
3450934688 cur_bit_bag >>= 1;
34510 const has_align = @truncate(u1, cur_bit_bag) != 0;
34689 const has_align = @as(u1, @truncate(cur_bit_bag)) != 0;
3451134690 cur_bit_bag >>= 1;
34512 const has_tag = @truncate(u1, cur_bit_bag) != 0;
34691 const has_tag = @as(u1, @truncate(cur_bit_bag)) != 0;
3451334692 cur_bit_bag >>= 1;
34514 const unused = @truncate(u1, cur_bit_bag) != 0;
34693 const unused = @as(u1, @truncate(cur_bit_bag)) != 0;
3451534694 cur_bit_bag >>= 1;
3451634695 _ = unused;
3451734696
......@@ -34522,19 +34701,19 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
3452234701 extra_index += 1;
3452334702
3452434703 const field_type_ref: Zir.Inst.Ref = if (has_type) blk: {
34525 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]));
3452634705 extra_index += 1;
3452734706 break :blk field_type_ref;
3452834707 } else .none;
3452934708
3453034709 const align_ref: Zir.Inst.Ref = if (has_align) blk: {
34531 const align_ref = @enumFromInt(Zir.Inst.Ref, zir.extra[extra_index]);
34710 const align_ref = @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index]));
3453234711 extra_index += 1;
3453334712 break :blk align_ref;
3453434713 } else .none;
3453534714
3453634715 const tag_ref: Air.Inst.Ref = if (has_tag) blk: {
34537 const tag_ref = @enumFromInt(Zir.Inst.Ref, zir.extra[extra_index]);
34716 const tag_ref = @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index]));
3453834717 extra_index += 1;
3453934718 break :blk try sema.resolveInst(tag_ref);
3454034719 } else .none;
......@@ -35248,12 +35427,12 @@ pub fn getTmpAir(sema: Sema) Air {
3524835427
3524935428pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
3525035429 if (@intFromEnum(ty.toIntern()) < Air.ref_start_index)
35251 return @enumFromInt(Air.Inst.Ref, @intFromEnum(ty.toIntern()));
35430 return @as(Air.Inst.Ref, @enumFromInt(@intFromEnum(ty.toIntern())));
3525235431 try sema.air_instructions.append(sema.gpa, .{
3525335432 .tag = .interned,
3525435433 .data = .{ .interned = ty.toIntern() },
3525535434 });
35256 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
35435 return Air.indexToRef(@as(u32, @intCast(sema.air_instructions.len - 1)));
3525735436}
3525835437
3525935438fn addIntUnsigned(sema: *Sema, ty: Type, int: u64) CompileError!Air.Inst.Ref {
......@@ -35267,12 +35446,12 @@ fn addConstUndef(sema: *Sema, ty: Type) CompileError!Air.Inst.Ref {
3526735446
3526835447pub fn addConstant(sema: *Sema, val: Value) SemaError!Air.Inst.Ref {
3526935448 if (@intFromEnum(val.toIntern()) < Air.ref_start_index)
35270 return @enumFromInt(Air.Inst.Ref, @intFromEnum(val.toIntern()));
35449 return @as(Air.Inst.Ref, @enumFromInt(@intFromEnum(val.toIntern())));
3527135450 try sema.air_instructions.append(sema.gpa, .{
3527235451 .tag = .interned,
3527335452 .data = .{ .interned = val.toIntern() },
3527435453 });
35275 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
35454 return Air.indexToRef(@as(u32, @intCast(sema.air_instructions.len - 1)));
3527635455}
3527735456
3527835457pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 {
......@@ -35283,12 +35462,12 @@ pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 {
3528335462
3528435463pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 {
3528535464 const fields = std.meta.fields(@TypeOf(extra));
35286 const result = @intCast(u32, sema.air_extra.items.len);
35465 const result = @as(u32, @intCast(sema.air_extra.items.len));
3528735466 inline for (fields) |field| {
3528835467 sema.air_extra.appendAssumeCapacity(switch (field.type) {
3528935468 u32 => @field(extra, field.name),
3529035469 Air.Inst.Ref => @intFromEnum(@field(extra, field.name)),
35291 i32 => @bitCast(u32, @field(extra, field.name)),
35470 i32 => @as(u32, @bitCast(@field(extra, field.name))),
3529235471 InternPool.Index => @intFromEnum(@field(extra, field.name)),
3529335472 else => @compileError("bad field type: " ++ @typeName(field.type)),
3529435473 });
......@@ -35297,7 +35476,7 @@ pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 {
3529735476}
3529835477
3529935478fn appendRefsAssumeCapacity(sema: *Sema, refs: []const Air.Inst.Ref) void {
35300 const coerced = @ptrCast([]const u32, refs);
35479 const coerced = @as([]const u32, @ptrCast(refs));
3530135480 sema.air_extra.appendSliceAssumeCapacity(coerced);
3530235481}
3530335482
......@@ -35737,10 +35916,10 @@ fn typeAbiAlignment(sema: *Sema, ty: Type) CompileError!u32 {
3573735916/// Not valid to call for packed unions.
3573835917/// Keep implementation in sync with `Module.Union.Field.normalAlignment`.
3573935918fn unionFieldAlignment(sema: *Sema, field: Module.Union.Field) !u32 {
35740 return @intCast(u32, if (field.ty.isNoReturn(sema.mod))
35919 return @as(u32, @intCast(if (field.ty.isNoReturn(sema.mod))
3574135920 0
3574235921 else
35743 field.abi_align.toByteUnitsOptional() orelse try sema.typeAbiAlignment(field.ty));
35922 field.abi_align.toByteUnitsOptional() orelse try sema.typeAbiAlignment(field.ty)));
3574435923}
3574535924
3574635925/// Synchronize logic with `Type.isFnOrHasRuntimeBits`.
......@@ -35772,7 +35951,7 @@ fn unionFieldIndex(
3577235951 const union_obj = mod.typeToUnion(union_ty).?;
3577335952 const field_index_usize = union_obj.fields.getIndex(field_name) orelse
3577435953 return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name);
35775 return @intCast(u32, field_index_usize);
35954 return @as(u32, @intCast(field_index_usize));
3577635955}
3577735956
3577835957fn structFieldIndex(
......@@ -35790,7 +35969,7 @@ fn structFieldIndex(
3579035969 const struct_obj = mod.typeToStruct(struct_ty).?;
3579135970 const field_index_usize = struct_obj.fields.getIndex(field_name) orelse
3579235971 return sema.failWithBadStructFieldAccess(block, struct_obj, field_src, field_name);
35793 return @intCast(u32, field_index_usize);
35972 return @as(u32, @intCast(field_index_usize));
3579435973 }
3579535974}
3579635975
......@@ -35804,12 +35983,12 @@ fn anonStructFieldIndex(
3580435983 const mod = sema.mod;
3580535984 switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) {
3580635985 .anon_struct_type => |anon_struct_type| for (anon_struct_type.names, 0..) |name, i| {
35807 if (name == field_name) return @intCast(u32, i);
35986 if (name == field_name) return @as(u32, @intCast(i));
3580835987 },
3580935988 .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| {
3581035989 for (struct_obj.fields.keys(), 0..) |name, i| {
3581135990 if (name == field_name) {
35812 return @intCast(u32, i);
35991 return @as(u32, @intCast(i));
3581335992 }
3581435993 }
3581535994 },
......@@ -36407,9 +36586,9 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {
3640736586 if (!is_packed) break :blk .{};
3640836587
3640936588 break :blk .{
36410 .host_size = @intCast(u16, parent_ty.arrayLen(mod)),
36411 .alignment = @intCast(u32, parent_ty.abiAlignment(mod)),
36412 .vector_index = if (offset) |some| @enumFromInt(VI, some) else .runtime,
36589 .host_size = @as(u16, @intCast(parent_ty.arrayLen(mod))),
36590 .alignment = @as(u32, @intCast(parent_ty.abiAlignment(mod))),
36591 .vector_index = if (offset) |some| @as(VI, @enumFromInt(some)) else .runtime,
3641336592 };
3641436593 } else .{};
3641536594
......@@ -36428,10 +36607,10 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {
3642836607 // The resulting pointer is aligned to the lcd between the offset (an
3642936608 // arbitrary number) and the alignment factor (always a power of two,
3643036609 // non zero).
36431 const new_align = @enumFromInt(Alignment, @min(
36610 const new_align = @as(Alignment, @enumFromInt(@min(
3643236611 @ctz(addend),
3643336612 @intFromEnum(ptr_info.flags.alignment),
36434 ));
36613 )));
3643536614 assert(new_align != .none);
3643636615 break :a new_align;
3643736616 };
src/TypedValue.zig+4-9
......@@ -241,11 +241,6 @@ pub fn print(
241241 return;
242242 }
243243 try writer.writeAll("@enumFromInt(");
244 try print(.{
245 .ty = Type.type,
246 .val = enum_tag.ty.toValue(),
247 }, writer, level - 1, mod);
248 try writer.writeAll(", ");
249244 try print(.{
250245 .ty = ip.typeOf(enum_tag.int).toType(),
251246 .val = enum_tag.int.toValue(),
......@@ -255,7 +250,7 @@ pub fn print(
255250 },
256251 .empty_enum_value => return writer.writeAll("(empty enum value)"),
257252 .float => |float| switch (float.storage) {
258 inline else => |x| return writer.print("{d}", .{@floatCast(f64, x)}),
253 inline else => |x| return writer.print("{d}", .{@as(f64, @floatCast(x))}),
259254 },
260255 .ptr => |ptr| {
261256 if (ptr.addr == .int) {
......@@ -278,7 +273,7 @@ pub fn print(
278273 for (buf[0..max_len], 0..) |*c, i| {
279274 const elem = try val.elemValue(mod, i);
280275 if (elem.isUndef(mod)) break :str;
281 c.* = @intCast(u8, elem.toUnsignedInt(mod));
276 c.* = @as(u8, @intCast(elem.toUnsignedInt(mod)));
282277 }
283278 const truncated = if (len > max_string_len) " (truncated)" else "";
284279 return writer.print("\"{}{s}\"", .{ std.zig.fmtEscapes(buf[0..max_len]), truncated });
......@@ -357,11 +352,11 @@ pub fn print(
357352 if (container_ty.isTuple(mod)) {
358353 try writer.print("[{d}]", .{field.index});
359354 }
360 const field_name = container_ty.structFieldName(@intCast(usize, field.index), mod);
355 const field_name = container_ty.structFieldName(@as(usize, @intCast(field.index)), mod);
361356 try writer.print(".{i}", .{field_name.fmt(ip)});
362357 },
363358 .Union => {
364 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))];
365360 try writer.print(".{i}", .{field_name.fmt(ip)});
366361 },
367362 .Pointer => {
src/Zir.zig+52-36
......@@ -74,12 +74,12 @@ pub fn extraData(code: Zir, comptime T: type, index: usize) struct { data: T, en
7474 inline for (fields) |field| {
7575 @field(result, field.name) = switch (field.type) {
7676 u32 => code.extra[i],
77 Inst.Ref => @enumFromInt(Inst.Ref, code.extra[i]),
78 i32 => @bitCast(i32, code.extra[i]),
79 Inst.Call.Flags => @bitCast(Inst.Call.Flags, code.extra[i]),
80 Inst.BuiltinCall.Flags => @bitCast(Inst.BuiltinCall.Flags, code.extra[i]),
81 Inst.SwitchBlock.Bits => @bitCast(Inst.SwitchBlock.Bits, code.extra[i]),
82 Inst.FuncFancy.Bits => @bitCast(Inst.FuncFancy.Bits, code.extra[i]),
77 Inst.Ref => @as(Inst.Ref, @enumFromInt(code.extra[i])),
78 i32 => @as(i32, @bitCast(code.extra[i])),
79 Inst.Call.Flags => @as(Inst.Call.Flags, @bitCast(code.extra[i])),
80 Inst.BuiltinCall.Flags => @as(Inst.BuiltinCall.Flags, @bitCast(code.extra[i])),
81 Inst.SwitchBlock.Bits => @as(Inst.SwitchBlock.Bits, @bitCast(code.extra[i])),
82 Inst.FuncFancy.Bits => @as(Inst.FuncFancy.Bits, @bitCast(code.extra[i])),
8383 else => @compileError("bad field type"),
8484 };
8585 i += 1;
......@@ -101,7 +101,7 @@ pub fn nullTerminatedString(code: Zir, index: usize) [:0]const u8 {
101101
102102pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {
103103 const raw_slice = code.extra[start..][0..len];
104 return @ptrCast([]Inst.Ref, raw_slice);
104 return @as([]Inst.Ref, @ptrCast(raw_slice));
105105}
106106
107107pub fn hasCompileErrors(code: Zir) bool {
......@@ -230,6 +230,9 @@ pub const Inst = struct {
230230 /// Given an indexable type, returns the type of the element at given index.
231231 /// Uses the `bin` union field. lhs is the indexable type, rhs is the index.
232232 elem_type_index,
233 /// Given a pointer type, returns its element type.
234 /// Uses the `un_node` field.
235 elem_type,
233236 /// Given a pointer to an indexable object, returns the len property. This is
234237 /// used by for loops. This instruction also emits a for-loop specific compile
235238 /// error if the indexable object is not indexable.
......@@ -838,13 +841,12 @@ pub const Inst = struct {
838841 int_cast,
839842 /// Implements the `@ptrCast` builtin.
840843 /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand.
844 /// Not every `@ptrCast` will correspond to this instruction - see also
845 /// `ptr_cast_full` in `Extended`.
841846 ptr_cast,
842847 /// Implements the `@truncate` builtin.
843848 /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand.
844849 truncate,
845 /// Implements the `@alignCast` builtin.
846 /// Uses `pl_node` with payload `Bin`. `lhs` is dest alignment, `rhs` is operand.
847 align_cast,
848850
849851 /// Implements the `@hasDecl` builtin.
850852 /// Uses the `pl_node` union field. Payload is `Bin`.
......@@ -1005,6 +1007,7 @@ pub const Inst = struct {
10051007 .array_type_sentinel,
10061008 .vector_type,
10071009 .elem_type_index,
1010 .elem_type,
10081011 .indexable_ptr_len,
10091012 .anyframe_type,
10101013 .as,
......@@ -1172,7 +1175,6 @@ pub const Inst = struct {
11721175 .int_cast,
11731176 .ptr_cast,
11741177 .truncate,
1175 .align_cast,
11761178 .has_field,
11771179 .clz,
11781180 .ctz,
......@@ -1309,6 +1311,7 @@ pub const Inst = struct {
13091311 .array_type_sentinel,
13101312 .vector_type,
13111313 .elem_type_index,
1314 .elem_type,
13121315 .indexable_ptr_len,
13131316 .anyframe_type,
13141317 .as,
......@@ -1454,7 +1457,6 @@ pub const Inst = struct {
14541457 .int_cast,
14551458 .ptr_cast,
14561459 .truncate,
1457 .align_cast,
14581460 .has_field,
14591461 .clz,
14601462 .ctz,
......@@ -1539,6 +1541,7 @@ pub const Inst = struct {
15391541 .array_type_sentinel = .pl_node,
15401542 .vector_type = .pl_node,
15411543 .elem_type_index = .bin,
1544 .elem_type = .un_node,
15421545 .indexable_ptr_len = .un_node,
15431546 .anyframe_type = .un_node,
15441547 .as = .bin,
......@@ -1717,7 +1720,6 @@ pub const Inst = struct {
17171720 .int_cast = .pl_node,
17181721 .ptr_cast = .pl_node,
17191722 .truncate = .pl_node,
1720 .align_cast = .pl_node,
17211723 .typeof_builtin = .pl_node,
17221724
17231725 .has_decl = .pl_node,
......@@ -1948,9 +1950,6 @@ pub const Inst = struct {
19481950 /// `small` 0=>weak 1=>strong
19491951 /// `operand` is payload index to `Cmpxchg`.
19501952 cmpxchg,
1951 /// Implement the builtin `@addrSpaceCast`
1952 /// `operand` is payload index to `BinNode`. `lhs` is dest type, `rhs` is operand.
1953 addrspace_cast,
19541953 /// Implement builtin `@cVaArg`.
19551954 /// `operand` is payload index to `BinNode`.
19561955 c_va_arg,
......@@ -1963,12 +1962,21 @@ pub const Inst = struct {
19631962 /// Implement builtin `@cVaStart`.
19641963 /// `operand` is `src_node: i32`.
19651964 c_va_start,
1966 /// Implements the `@constCast` builtin.
1967 /// `operand` is payload index to `UnNode`.
1968 const_cast,
1969 /// Implements the `@volatileCast` builtin.
1965 /// Implements the following builtins:
1966 /// `@ptrCast`, `@alignCast`, `@addrSpaceCast`, `@constCast`, `@volatileCast`.
1967 /// Represents an arbitrary nesting of the above builtins. Such a nesting is treated as a
1968 /// single operation which can modify multiple components of a pointer type.
1969 /// `operand` is payload index to `BinNode`.
1970 /// `small` contains `FullPtrCastFlags`.
1971 /// AST node is the root of the nested casts.
1972 /// `lhs` is dest type, `rhs` is operand.
1973 ptr_cast_full,
19701974 /// `operand` is payload index to `UnNode`.
1971 volatile_cast,
1975 /// `small` contains `FullPtrCastFlags`.
1976 /// Guaranteed to only have flags where no explicit destination type is
1977 /// required (const_cast and volatile_cast).
1978 /// AST node is the root of the nested casts.
1979 ptr_cast_no_dest,
19721980 /// Implements the `@workItemId` builtin.
19731981 /// `operand` is payload index to `UnNode`.
19741982 work_item_id,
......@@ -2806,6 +2814,14 @@ pub const Inst = struct {
28062814 dbg_var,
28072815 };
28082816
2817 pub const FullPtrCastFlags = packed struct(u5) {
2818 ptr_cast: bool = false,
2819 align_cast: bool = false,
2820 addrspace_cast: bool = false,
2821 const_cast: bool = false,
2822 volatile_cast: bool = false,
2823 };
2824
28092825 /// Trailing:
28102826 /// 0. src_node: i32, // if has_src_node
28112827 /// 1. tag_type: Ref, // if has_tag_type
......@@ -2976,7 +2992,7 @@ pub const Inst = struct {
29762992 (@as(u128, self.piece1) << 32) |
29772993 (@as(u128, self.piece2) << 64) |
29782994 (@as(u128, self.piece3) << 96);
2979 return @bitCast(f128, int_bits);
2995 return @as(f128, @bitCast(int_bits));
29802996 }
29812997 };
29822998
......@@ -3212,15 +3228,15 @@ pub const DeclIterator = struct {
32123228 }
32133229 it.decl_i += 1;
32143230
3215 const flags = @truncate(u4, it.cur_bit_bag);
3231 const flags = @as(u4, @truncate(it.cur_bit_bag));
32163232 it.cur_bit_bag >>= 4;
32173233
3218 const sub_index = @intCast(u32, it.extra_index);
3234 const sub_index = @as(u32, @intCast(it.extra_index));
32193235 it.extra_index += 5; // src_hash(4) + line(1)
32203236 const name = it.zir.nullTerminatedString(it.zir.extra[it.extra_index]);
32213237 it.extra_index += 3; // name(1) + value(1) + doc_comment(1)
3222 it.extra_index += @truncate(u1, flags >> 2);
3223 it.extra_index += @truncate(u1, flags >> 3);
3238 it.extra_index += @as(u1, @truncate(flags >> 2));
3239 it.extra_index += @as(u1, @truncate(flags >> 3));
32243240
32253241 return Item{
32263242 .sub_index = sub_index,
......@@ -3242,7 +3258,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
32423258 const extended = datas[decl_inst].extended;
32433259 switch (extended.opcode) {
32443260 .struct_decl => {
3245 const small = @bitCast(Inst.StructDecl.Small, extended.small);
3261 const small = @as(Inst.StructDecl.Small, @bitCast(extended.small));
32463262 var extra_index: usize = extended.operand;
32473263 extra_index += @intFromBool(small.has_src_node);
32483264 extra_index += @intFromBool(small.has_fields_len);
......@@ -3265,7 +3281,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
32653281 return declIteratorInner(zir, extra_index, decls_len);
32663282 },
32673283 .enum_decl => {
3268 const small = @bitCast(Inst.EnumDecl.Small, extended.small);
3284 const small = @as(Inst.EnumDecl.Small, @bitCast(extended.small));
32693285 var extra_index: usize = extended.operand;
32703286 extra_index += @intFromBool(small.has_src_node);
32713287 extra_index += @intFromBool(small.has_tag_type);
......@@ -3280,7 +3296,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
32803296 return declIteratorInner(zir, extra_index, decls_len);
32813297 },
32823298 .union_decl => {
3283 const small = @bitCast(Inst.UnionDecl.Small, extended.small);
3299 const small = @as(Inst.UnionDecl.Small, @bitCast(extended.small));
32843300 var extra_index: usize = extended.operand;
32853301 extra_index += @intFromBool(small.has_src_node);
32863302 extra_index += @intFromBool(small.has_tag_type);
......@@ -3295,7 +3311,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
32953311 return declIteratorInner(zir, extra_index, decls_len);
32963312 },
32973313 .opaque_decl => {
3298 const small = @bitCast(Inst.OpaqueDecl.Small, extended.small);
3314 const small = @as(Inst.OpaqueDecl.Small, @bitCast(extended.small));
32993315 var extra_index: usize = extended.operand;
33003316 extra_index += @intFromBool(small.has_src_node);
33013317 const decls_len = if (small.has_decls_len) decls_len: {
......@@ -3491,7 +3507,7 @@ fn findDeclsSwitch(
34913507
34923508 const special_prong = extra.data.bits.specialProng();
34933509 if (special_prong != .none) {
3494 const body_len = @truncate(u31, zir.extra[extra_index]);
3510 const body_len = @as(u31, @truncate(zir.extra[extra_index]));
34953511 extra_index += 1;
34963512 const body = zir.extra[extra_index..][0..body_len];
34973513 extra_index += body.len;
......@@ -3504,7 +3520,7 @@ fn findDeclsSwitch(
35043520 var scalar_i: usize = 0;
35053521 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
35063522 extra_index += 1;
3507 const body_len = @truncate(u31, zir.extra[extra_index]);
3523 const body_len = @as(u31, @truncate(zir.extra[extra_index]));
35083524 extra_index += 1;
35093525 const body = zir.extra[extra_index..][0..body_len];
35103526 extra_index += body_len;
......@@ -3519,7 +3535,7 @@ fn findDeclsSwitch(
35193535 extra_index += 1;
35203536 const ranges_len = zir.extra[extra_index];
35213537 extra_index += 1;
3522 const body_len = @truncate(u31, zir.extra[extra_index]);
3538 const body_len = @as(u31, @truncate(zir.extra[extra_index]));
35233539 extra_index += 1;
35243540 const items = zir.refSlice(extra_index, items_len);
35253541 extra_index += items_len;
......@@ -3601,7 +3617,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
36013617 ret_ty_ref = .void_type;
36023618 },
36033619 1 => {
3604 ret_ty_ref = @enumFromInt(Inst.Ref, zir.extra[extra_index]);
3620 ret_ty_ref = @as(Inst.Ref, @enumFromInt(zir.extra[extra_index]));
36053621 extra_index += 1;
36063622 },
36073623 else => {
......@@ -3655,7 +3671,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
36553671 ret_ty_body = zir.extra[extra_index..][0..body_len];
36563672 extra_index += ret_ty_body.len;
36573673 } else if (extra.data.bits.has_ret_ty_ref) {
3658 ret_ty_ref = @enumFromInt(Inst.Ref, zir.extra[extra_index]);
3674 ret_ty_ref = @as(Inst.Ref, @enumFromInt(zir.extra[extra_index]));
36593675 extra_index += 1;
36603676 }
36613677
......@@ -3699,7 +3715,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
36993715pub const ref_start_index: u32 = InternPool.static_len;
37003716
37013717pub fn indexToRef(inst: Inst.Index) Inst.Ref {
3702 return @enumFromInt(Inst.Ref, ref_start_index + inst);
3718 return @as(Inst.Ref, @enumFromInt(ref_start_index + inst));
37033719}
37043720
37053721pub fn refToIndex(inst: Inst.Ref) ?Inst.Index {
src/arch/aarch64/CodeGen.zig+88-88
......@@ -187,8 +187,8 @@ const DbgInfoReloc = struct {
187187 .stack_argument_offset,
188188 => |offset| blk: {
189189 const adjusted_offset = switch (reloc.mcv) {
190 .stack_offset => -@intCast(i32, offset),
191 .stack_argument_offset => @intCast(i32, function.saved_regs_stack_space + offset),
190 .stack_offset => -@as(i32, @intCast(offset)),
191 .stack_argument_offset => @as(i32, @intCast(function.saved_regs_stack_space + offset)),
192192 else => unreachable,
193193 };
194194 break :blk .{ .stack = .{
......@@ -224,8 +224,8 @@ const DbgInfoReloc = struct {
224224 const adjusted_offset = switch (reloc.mcv) {
225225 .ptr_stack_offset,
226226 .stack_offset,
227 => -@intCast(i32, offset),
228 .stack_argument_offset => @intCast(i32, function.saved_regs_stack_space + offset),
227 => -@as(i32, @intCast(offset)),
228 .stack_argument_offset => @as(i32, @intCast(function.saved_regs_stack_space + offset)),
229229 else => unreachable,
230230 };
231231 break :blk .{
......@@ -440,7 +440,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
440440
441441 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));
444444 self.mir_instructions.appendAssumeCapacity(inst);
445445 return result_index;
446446}
......@@ -460,11 +460,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {
460460
461461pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
462462 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));
464464 inline for (fields) |field| {
465465 self.mir_extra.appendAssumeCapacity(switch (field.type) {
466466 u32 => @field(extra, field.name),
467 i32 => @bitCast(u32, @field(extra, field.name)),
467 i32 => @as(u32, @bitCast(@field(extra, field.name))),
468468 else => @compileError("bad field type"),
469469 });
470470 }
......@@ -524,7 +524,7 @@ fn gen(self: *Self) !void {
524524
525525 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)));
528528 const abi_align = ty.abiAlignment(mod);
529529 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
530530 try self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
......@@ -547,7 +547,7 @@ fn gen(self: *Self) !void {
547547 self.saved_regs_stack_space = 16;
548548 inline for (callee_preserved_regs) |reg| {
549549 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()));
551551 self.saved_regs_stack_space += 8;
552552 }
553553 }
......@@ -597,14 +597,14 @@ fn gen(self: *Self) !void {
597597 for (self.exitlude_jump_relocs.items) |jmp_reloc| {
598598 self.mir_instructions.set(jmp_reloc, .{
599599 .tag = .b,
600 .data = .{ .inst = @intCast(u32, self.mir_instructions.len) },
600 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len)) },
601601 });
602602 }
603603
604604 // add sp, sp, #stack_size
605605 _ = try self.addInst(.{
606606 .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)) } },
608608 });
609609
610610 // <load other registers>
......@@ -948,15 +948,15 @@ fn finishAirBookkeeping(self: *Self) void {
948948fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void {
949949 var tomb_bits = self.liveness.getTombBits(inst);
950950 for (operands) |op| {
951 const dies = @truncate(u1, tomb_bits) != 0;
951 const dies = @as(u1, @truncate(tomb_bits)) != 0;
952952 tomb_bits >>= 1;
953953 if (!dies) continue;
954954 const op_int = @intFromEnum(op);
955955 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));
957957 self.processDeath(op_index);
958958 }
959 const is_used = @truncate(u1, tomb_bits) == 0;
959 const is_used = @as(u1, @truncate(tomb_bits)) == 0;
960960 if (is_used) {
961961 log.debug("%{d} => {}", .{ inst, result });
962962 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
......@@ -1232,7 +1232,7 @@ fn truncRegister(
12321232 .rd = dest_reg,
12331233 .rn = operand_reg,
12341234 .lsb = 0,
1235 .width = @intCast(u6, int_bits),
1235 .width = @as(u6, @intCast(int_bits)),
12361236 } },
12371237 });
12381238 },
......@@ -1877,7 +1877,7 @@ fn binOpImmediate(
18771877 => .{ .rr_imm12_sh = .{
18781878 .rd = dest_reg,
18791879 .rn = lhs_reg,
1880 .imm12 = @intCast(u12, rhs_immediate),
1880 .imm12 = @as(u12, @intCast(rhs_immediate)),
18811881 } },
18821882 .lsl_immediate,
18831883 .asr_immediate,
......@@ -1885,7 +1885,7 @@ fn binOpImmediate(
18851885 => .{ .rr_shift = .{
18861886 .rd = dest_reg,
18871887 .rn = lhs_reg,
1888 .shift = @intCast(u6, rhs_immediate),
1888 .shift = @as(u6, @intCast(rhs_immediate)),
18891889 } },
18901890 else => unreachable,
18911891 };
......@@ -2526,9 +2526,9 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
25262526 const rhs_ty = self.typeOf(extra.rhs);
25272527
25282528 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)));
25302530 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
25332533 switch (lhs_ty.zigTypeTag(mod)) {
25342534 .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 {
26542654 const rhs_ty = self.typeOf(extra.rhs);
26552655
26562656 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)));
26582658 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
26612661 switch (lhs_ty.zigTypeTag(mod)) {
26622662 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
......@@ -2777,7 +2777,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
27772777 } },
27782778 });
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))));
27812781 if (shift > 0) {
27822782 // lsl dest_high, dest, #shift
27832783 _ = try self.addInst(.{
......@@ -2837,7 +2837,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
28372837 .data = .{ .rr_shift = .{
28382838 .rd = dest_high_reg,
28392839 .rn = dest_reg,
2840 .shift = @intCast(u6, int_info.bits),
2840 .shift = @as(u6, @intCast(int_info.bits)),
28412841 } },
28422842 });
28432843
......@@ -2878,9 +2878,9 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
28782878 const rhs_ty = self.typeOf(extra.rhs);
28792879
28802880 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)));
28822882 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
28852885 switch (lhs_ty.zigTypeTag(mod)) {
28862886 .Vector => return self.fail("TODO implement shl_with_overflow for vectors", .{}),
......@@ -2917,7 +2917,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
29172917 .data = .{ .rr_shift = .{
29182918 .rd = dest_reg,
29192919 .rn = lhs_reg,
2920 .shift = @intCast(u6, imm),
2920 .shift = @as(u6, @intCast(imm)),
29212921 } },
29222922 });
29232923
......@@ -2932,7 +2932,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
29322932 .data = .{ .rr_shift = .{
29332933 .rd = reconstructed_reg,
29342934 .rn = dest_reg,
2935 .shift = @intCast(u6, imm),
2935 .shift = @as(u6, @intCast(imm)),
29362936 } },
29372937 });
29382938 } else {
......@@ -3072,7 +3072,7 @@ fn errUnionErr(
30723072 return try error_union_bind.resolveToMcv(self);
30733073 }
30743074
3075 const err_offset = @intCast(u32, errUnionErrorOffset(payload_ty, mod));
3075 const err_offset = @as(u32, @intCast(errUnionErrorOffset(payload_ty, mod)));
30763076 switch (try error_union_bind.resolveToMcv(self)) {
30773077 .register => {
30783078 var operand_reg: Register = undefined;
......@@ -3094,7 +3094,7 @@ fn errUnionErr(
30943094 );
30953095
30963096 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
30993099 _ = try self.addInst(.{
31003100 .tag = .ubfx, // errors are unsigned integers
......@@ -3103,8 +3103,8 @@ fn errUnionErr(
31033103 // Set both registers to the X variant to get the full width
31043104 .rd = dest_reg.toX(),
31053105 .rn = operand_reg.toX(),
3106 .lsb = @intCast(u6, err_bit_offset),
3107 .width = @intCast(u7, err_bit_size),
3106 .lsb = @as(u6, @intCast(err_bit_offset)),
3107 .width = @as(u7, @intCast(err_bit_size)),
31083108 },
31093109 },
31103110 });
......@@ -3152,7 +3152,7 @@ fn errUnionPayload(
31523152 return MCValue.none;
31533153 }
31543154
3155 const payload_offset = @intCast(u32, errUnionPayloadOffset(payload_ty, mod));
3155 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, mod)));
31563156 switch (try error_union_bind.resolveToMcv(self)) {
31573157 .register => {
31583158 var operand_reg: Register = undefined;
......@@ -3174,7 +3174,7 @@ fn errUnionPayload(
31743174 );
31753175
31763176 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
31793179 _ = try self.addInst(.{
31803180 .tag = if (payload_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,
......@@ -3183,8 +3183,8 @@ fn errUnionPayload(
31833183 // Set both registers to the X variant to get the full width
31843184 .rd = dest_reg.toX(),
31853185 .rn = operand_reg.toX(),
3186 .lsb = @intCast(u5, payload_bit_offset),
3187 .width = @intCast(u6, payload_bit_size),
3186 .lsb = @as(u5, @intCast(payload_bit_offset)),
3187 .width = @as(u6, @intCast(payload_bit_size)),
31883188 },
31893189 },
31903190 });
......@@ -3283,9 +3283,9 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
32833283 break :result MCValue{ .register = reg };
32843284 }
32853285
3286 const optional_abi_size = @intCast(u32, optional_ty.abiSize(mod));
3286 const optional_abi_size = @as(u32, @intCast(optional_ty.abiSize(mod)));
32873287 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
32903290 const stack_offset = try self.allocMem(optional_abi_size, optional_abi_align, inst);
32913291 try self.genSetStack(payload_ty, stack_offset, operand);
......@@ -3308,13 +3308,13 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
33083308 const operand = try self.resolveInst(ty_op.operand);
33093309 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)));
33123312 const abi_align = error_union_ty.abiAlignment(mod);
33133313 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
33143314 const payload_off = errUnionPayloadOffset(payload_ty, mod);
33153315 const err_off = errUnionErrorOffset(payload_ty, mod);
3316 try self.genSetStack(payload_ty, stack_offset - @intCast(u32, payload_off), operand);
3317 try self.genSetStack(error_ty, stack_offset - @intCast(u32, err_off), .{ .immediate = 0 });
3316 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), operand);
3317 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), .{ .immediate = 0 });
33183318
33193319 break :result MCValue{ .stack_offset = stack_offset };
33203320 };
......@@ -3332,13 +3332,13 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
33323332 const operand = try self.resolveInst(ty_op.operand);
33333333 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)));
33363336 const abi_align = error_union_ty.abiAlignment(mod);
33373337 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
33383338 const payload_off = errUnionPayloadOffset(payload_ty, mod);
33393339 const err_off = errUnionErrorOffset(payload_ty, mod);
3340 try self.genSetStack(error_ty, stack_offset - @intCast(u32, err_off), operand);
3341 try self.genSetStack(payload_ty, stack_offset - @intCast(u32, payload_off), .undef);
3340 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), operand);
3341 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), .undef);
33423342
33433343 break :result MCValue{ .stack_offset = stack_offset };
33443344 };
......@@ -3454,7 +3454,7 @@ fn ptrElemVal(
34543454) !MCValue {
34553455 const mod = self.bin_file.options.module.?;
34563456 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
34593459 // TODO optimize for elem_sizes of 1, 2, 4, 8
34603460 switch (elem_size) {
......@@ -3716,7 +3716,7 @@ fn genInlineMemcpy(
37163716 _ = try self.addInst(.{
37173717 .tag = .b_cond,
37183718 .data = .{ .inst_cond = .{
3719 .inst = @intCast(u32, self.mir_instructions.len + 5),
3719 .inst = @as(u32, @intCast(self.mir_instructions.len + 5)),
37203720 .cond = .ge,
37213721 } },
37223722 });
......@@ -3754,7 +3754,7 @@ fn genInlineMemcpy(
37543754 // b loop
37553755 _ = try self.addInst(.{
37563756 .tag = .b,
3757 .data = .{ .inst = @intCast(u32, self.mir_instructions.len - 5) },
3757 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len - 5)) },
37583758 });
37593759
37603760 // end:
......@@ -3824,7 +3824,7 @@ fn genInlineMemsetCode(
38243824 _ = try self.addInst(.{
38253825 .tag = .b_cond,
38263826 .data = .{ .inst_cond = .{
3827 .inst = @intCast(u32, self.mir_instructions.len + 4),
3827 .inst = @as(u32, @intCast(self.mir_instructions.len + 4)),
38283828 .cond = .ge,
38293829 } },
38303830 });
......@@ -3852,7 +3852,7 @@ fn genInlineMemsetCode(
38523852 // b loop
38533853 _ = try self.addInst(.{
38543854 .tag = .b,
3855 .data = .{ .inst = @intCast(u32, self.mir_instructions.len - 4) },
3855 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len - 4)) },
38563856 });
38573857
38583858 // end:
......@@ -4002,7 +4002,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
40024002 } },
40034003 });
40044004 },
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)) }),
40064006 .linker_load => |load_struct| {
40074007 const tag: Mir.Inst.Tag = switch (load_struct.type) {
40084008 .got => .load_memory_ptr_got,
......@@ -4092,7 +4092,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
40924092 const mcv = try self.resolveInst(operand);
40934093 const ptr_ty = self.typeOf(operand);
40944094 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)));
40964096 switch (mcv) {
40974097 .ptr_stack_offset => |off| {
40984098 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };
......@@ -4117,7 +4117,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
41174117 const mcv = try self.resolveInst(operand);
41184118 const struct_ty = self.typeOf(operand);
41194119 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
41224122 switch (mcv) {
41234123 .dead, .unreach => unreachable,
......@@ -4169,7 +4169,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
41694169 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
41704170 const field_ptr = try self.resolveInst(extra.field_ptr);
41714171 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)));
41734173 switch (field_ptr) {
41744174 .ptr_stack_offset => |off| {
41754175 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
42434243 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
42444244 const callee = pl_op.operand;
42454245 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]));
42474247 const ty = self.typeOf(callee);
42484248 const mod = self.bin_file.options.module.?;
42494249
......@@ -4269,8 +4269,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42694269 if (info.return_value == .stack_offset) {
42704270 log.debug("airCall: return by reference", .{});
42714271 const ret_ty = fn_ty.fnReturnType(mod);
4272 const ret_abi_size = @intCast(u32, ret_ty.abiSize(mod));
4273 const ret_abi_align = @intCast(u32, ret_ty.abiAlignment(mod));
4272 const ret_abi_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
4273 const ret_abi_align = @as(u32, @intCast(ret_ty.abiAlignment(mod)));
42744274 const stack_offset = try self.allocMem(ret_abi_size, ret_abi_align, inst);
42754275
42764276 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
43144314 const atom_index = try elf_file.getOrCreateAtomForDecl(func.owner_decl);
43154315 const atom = elf_file.getAtom(atom_index);
43164316 _ = 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)));
43184318 try self.genSetReg(Type.usize, .x30, .{ .memory = got_addr });
43194319 } else if (self.bin_file.cast(link.File.MachO)) |macho_file| {
43204320 const atom = try macho_file.getOrCreateAtomForDecl(func.owner_decl);
......@@ -4473,7 +4473,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
44734473 // location.
44744474 const op_inst = Air.refToIndex(un_op).?;
44754475 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)));
44774477 const abi_align = ret_ty.abiAlignment(mod);
44784478
44794479 const offset = try self.allocMem(abi_size, abi_align, null);
......@@ -4554,7 +4554,7 @@ fn cmp(
45544554 .tag = .cmp_immediate,
45554555 .data = .{ .r_imm12_sh = .{
45564556 .rn = lhs_reg,
4557 .imm12 = @intCast(u12, rhs_immediate.?),
4557 .imm12 = @as(u12, @intCast(rhs_immediate.?)),
45584558 } },
45594559 });
45604560 } else {
......@@ -4696,7 +4696,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
46964696 if (self.liveness.operandDies(inst, 0)) {
46974697 const op_int = @intFromEnum(pl_op.operand);
46984698 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));
47004700 self.processDeath(op_index);
47014701 }
47024702 }
......@@ -4833,7 +4833,7 @@ fn isNull(self: *Self, operand_bind: ReadArg.Bind, operand_ty: Type) !MCValue {
48334833 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod))
48344834 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)));
48374837 const operand_mcv = try operand_bind.resolveToMcv(self);
48384838 const new_mcv: MCValue = switch (operand_mcv) {
48394839 .register => |source_reg| new: {
......@@ -4841,7 +4841,7 @@ fn isNull(self: *Self, operand_bind: ReadArg.Bind, operand_ty: Type) !MCValue {
48414841 const raw_reg = try self.register_manager.allocReg(null, gp);
48424842 const dest_reg = raw_reg.toX();
48434843
4844 const shift = @intCast(u6, offset * 8);
4844 const shift = @as(u6, @intCast(offset * 8));
48454845 if (shift == 0) {
48464846 try self.genSetReg(payload_ty, dest_reg, operand_mcv);
48474847 } else {
......@@ -5026,7 +5026,7 @@ fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
50265026 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
50275027 const loop = self.air.extraData(Air.Block, ty_pl.payload);
50285028 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
50315031 try self.genBody(body);
50325032 try self.jump(start_index);
......@@ -5091,7 +5091,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
50915091 var case_i: u32 = 0;
50925092 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
50935093 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]));
50955095 assert(items.len > 0);
50965096 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
50975097 extra_index = case.end + items.len + case_body.len;
......@@ -5209,9 +5209,9 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
52095209fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {
52105210 const tag = self.mir_instructions.items(.tag)[inst];
52115211 switch (tag) {
5212 .cbz => self.mir_instructions.items(.data)[inst].r_inst.inst = @intCast(Mir.Inst.Index, self.mir_instructions.len),
5213 .b_cond => self.mir_instructions.items(.data)[inst].inst_cond.inst = @intCast(Mir.Inst.Index, self.mir_instructions.len),
5214 .b => self.mir_instructions.items(.data)[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 = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len)),
5214 .b => self.mir_instructions.items(.data)[inst].inst = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len)),
52155215 else => unreachable,
52165216 }
52175217}
......@@ -5262,12 +5262,12 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {
52625262fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
52635263 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
52645264 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
5265 const is_volatile = @truncate(u1, extra.data.flags >> 31) != 0;
5266 const clobbers_len = @truncate(u31, extra.data.flags);
5265 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
5266 const clobbers_len = @as(u31, @truncate(extra.data.flags));
52675267 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]));
52695269 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]));
52715271 extra_i += inputs.len;
52725272
52735273 const dead = !is_volatile and self.liveness.isUnused(inst);
......@@ -5401,7 +5401,7 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {
54015401
54025402fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
54035403 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)));
54055405 switch (mcv) {
54065406 .dead => unreachable,
54075407 .unreach, .none => return, // Nothing to do.
......@@ -5460,7 +5460,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
54605460 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = rwo.reg });
54615461
54625462 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)));
54645464 const raw_cond_reg = try self.register_manager.allocReg(null, gp);
54655465 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
55895589 .tag = .ldr_ptr_stack,
55905590 .data = .{ .load_store_stack = .{
55915591 .rt = reg,
5592 .offset = @intCast(u32, off),
5592 .offset = @as(u32, @intCast(off)),
55935593 } },
55945594 });
55955595 },
......@@ -5605,13 +5605,13 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56055605 .immediate => |x| {
56065606 _ = try self.addInst(.{
56075607 .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)) } },
56095609 });
56105610
56115611 if (x & 0x0000_0000_ffff_0000 != 0) {
56125612 _ = try self.addInst(.{
56135613 .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 } },
56155615 });
56165616 }
56175617
......@@ -5619,13 +5619,13 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56195619 if (x & 0x0000_ffff_0000_0000 != 0) {
56205620 _ = try self.addInst(.{
56215621 .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 } },
56235623 });
56245624 }
56255625 if (x & 0xffff_0000_0000_0000 != 0) {
56265626 _ = try self.addInst(.{
56275627 .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 } },
56295629 });
56305630 }
56315631 }
......@@ -5696,7 +5696,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56965696 .tag = tag,
56975697 .data = .{ .load_store_stack = .{
56985698 .rt = reg,
5699 .offset = @intCast(u32, off),
5699 .offset = @as(u32, @intCast(off)),
57005700 } },
57015701 });
57025702 },
......@@ -5720,7 +5720,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
57205720 .tag = tag,
57215721 .data = .{ .load_store_stack = .{
57225722 .rt = reg,
5723 .offset = @intCast(u32, off),
5723 .offset = @as(u32, @intCast(off)),
57245724 } },
57255725 });
57265726 },
......@@ -5733,7 +5733,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
57335733
57345734fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
57355735 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)));
57375737 switch (mcv) {
57385738 .dead => unreachable,
57395739 .none, .unreach => return,
......@@ -5840,7 +5840,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
58405840 } },
58415841 });
58425842 },
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)) }),
58445844 .linker_load => |load_struct| {
58455845 const tag: Mir.Inst.Tag = switch (load_struct.type) {
58465846 .got => .load_memory_ptr_got,
......@@ -5937,7 +5937,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
59375937 const ptr_ty = self.typeOf(ty_op.operand);
59385938 const ptr = try self.resolveInst(ty_op.operand);
59395939 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
59425942 const ptr_bits = self.target.ptrBitWidth();
59435943 const ptr_bytes = @divExact(ptr_bits, 8);
......@@ -6058,7 +6058,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
60586058 const vector_ty = self.typeOfIndex(inst);
60596059 const len = vector_ty.vectorLen(mod);
60606060 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]));
60626062 const result: MCValue = res: {
60636063 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
60646064 return self.fail("TODO implement airAggregateInit for {}", .{self.target.cpu.arch});
......@@ -6105,7 +6105,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
61056105 const result: MCValue = result: {
61066106 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };
61076107 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)));
61096109 const error_union_align = error_union_ty.abiAlignment(mod);
61106110
61116111 // The error union will die in the body. However, we need the
......@@ -6247,7 +6247,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62476247 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod) and !ret_ty.isError(mod)) {
62486248 result.return_value = .{ .none = {} };
62496249 } else {
6250 const ret_ty_size = @intCast(u32, ret_ty.abiSize(mod));
6250 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
62516251 if (ret_ty_size == 0) {
62526252 assert(ret_ty.isError(mod));
62536253 result.return_value = .{ .immediate = 0 };
......@@ -6259,7 +6259,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62596259 }
62606260
62616261 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)));
62636263 if (param_size == 0) {
62646264 result.args[i] = .{ .none = {} };
62656265 continue;
......@@ -6305,7 +6305,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
63056305 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod) and !ret_ty.isError(mod)) {
63066306 result.return_value = .{ .none = {} };
63076307 } else {
6308 const ret_ty_size = @intCast(u32, ret_ty.abiSize(mod));
6308 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
63096309 if (ret_ty_size == 0) {
63106310 assert(ret_ty.isError(mod));
63116311 result.return_value = .{ .immediate = 0 };
......@@ -6325,7 +6325,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
63256325
63266326 for (fn_info.param_types, 0..) |ty, i| {
63276327 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)));
63296329 const param_alignment = ty.toType().abiAlignment(mod);
63306330
63316331 stack_offset = std.mem.alignForward(u32, stack_offset, param_alignment);
src/arch/aarch64/Emit.zig+22-22
......@@ -81,7 +81,7 @@ pub fn emitMir(
8181
8282 // Emit machine code
8383 for (mir_tags, 0..) |tag, index| {
84 const inst = @intCast(u32, index);
84 const inst = @as(u32, @intCast(index));
8585 switch (tag) {
8686 .add_immediate => try emit.mirAddSubtractImmediate(inst),
8787 .adds_immediate => try emit.mirAddSubtractImmediate(inst),
......@@ -324,7 +324,7 @@ fn lowerBranches(emit: *Emit) !void {
324324 // TODO optimization opportunity: do this in codegen while
325325 // generating MIR
326326 for (mir_tags, 0..) |tag, index| {
327 const inst = @intCast(u32, index);
327 const inst = @as(u32, @intCast(index));
328328 if (isBranch(tag)) {
329329 const target_inst = emit.branchTarget(inst);
330330
......@@ -369,7 +369,7 @@ fn lowerBranches(emit: *Emit) !void {
369369 var current_code_offset: usize = 0;
370370
371371 for (mir_tags, 0..) |tag, index| {
372 const inst = @intCast(u32, index);
372 const inst = @as(u32, @intCast(index));
373373
374374 // If this instruction contained in the code offset
375375 // mapping (when it is a target of a branch or if it is a
......@@ -384,7 +384,7 @@ fn lowerBranches(emit: *Emit) !void {
384384 const target_inst = emit.branchTarget(inst);
385385 if (target_inst < inst) {
386386 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));
388388 const branch_type = emit.branch_types.getPtr(inst).?;
389389 const optimal_branch_type = try emit.optimalBranchType(tag, offset);
390390 if (branch_type.* != optimal_branch_type) {
......@@ -403,7 +403,7 @@ fn lowerBranches(emit: *Emit) !void {
403403 for (origin_list.items) |forward_branch_inst| {
404404 const branch_tag = emit.mir.instructions.items(.tag)[forward_branch_inst];
405405 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));
407407 const branch_type = emit.branch_types.getPtr(forward_branch_inst).?;
408408 const optimal_branch_type = try emit.optimalBranchType(branch_tag, offset);
409409 if (branch_type.* != optimal_branch_type) {
......@@ -434,7 +434,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
434434}
435435
436436fn 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));
438438 const delta_pc: usize = self.code.items.len - self.prev_di_pc;
439439 switch (self.debug_output) {
440440 .dwarf => |dw| {
......@@ -451,13 +451,13 @@ fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {
451451 // increasing the line number
452452 try @import("../../link/Plan9.zig").changeLine(dbg_out.dbg_line, delta_line);
453453 // increasing the pc
454 const d_pc_p9 = @intCast(i64, delta_pc) - quant;
454 const d_pc_p9 = @as(i64, @intCast(delta_pc)) - quant;
455455 if (d_pc_p9 > 0) {
456456 // 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);
458458 if (dbg_out.pcop_change_index.*) |pci|
459459 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));
461461 } else if (d_pc_p9 == 0) {
462462 // we don't need to do anything, because adding the quant does it for us
463463 } else unreachable;
......@@ -548,13 +548,13 @@ fn mirConditionalBranchImmediate(emit: *Emit, inst: Mir.Inst.Index) !void {
548548 const tag = emit.mir.instructions.items(.tag)[inst];
549549 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));
552552 const branch_type = emit.branch_types.get(inst).?;
553553 log.debug("mirConditionalBranchImmediate: {} offset={}", .{ inst, offset });
554554
555555 switch (branch_type) {
556556 .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)))),
558558 else => unreachable,
559559 },
560560 else => unreachable,
......@@ -572,14 +572,14 @@ fn mirBranch(emit: *Emit, inst: Mir.Inst.Index) !void {
572572 emit.mir.instructions.items(.tag)[target_inst],
573573 });
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));
576576 const branch_type = emit.branch_types.get(inst).?;
577577 log.debug("mirBranch: {} offset={}", .{ inst, offset });
578578
579579 switch (branch_type) {
580580 .unconditional_branch_immediate => switch (tag) {
581 .b => try emit.writeInstruction(Instruction.b(@intCast(i28, offset))),
582 .bl => try emit.writeInstruction(Instruction.bl(@intCast(i28, offset))),
581 .b => try emit.writeInstruction(Instruction.b(@as(i28, @intCast(offset)))),
582 .bl => try emit.writeInstruction(Instruction.bl(@as(i28, @intCast(offset)))),
583583 else => unreachable,
584584 },
585585 else => unreachable,
......@@ -590,13 +590,13 @@ fn mirCompareAndBranch(emit: *Emit, inst: Mir.Inst.Index) !void {
590590 const tag = emit.mir.instructions.items(.tag)[inst];
591591 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));
594594 const branch_type = emit.branch_types.get(inst).?;
595595 log.debug("mirCompareAndBranch: {} offset={}", .{ inst, offset });
596596
597597 switch (branch_type) {
598598 .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)))),
600600 else => unreachable,
601601 },
602602 else => unreachable,
......@@ -662,7 +662,7 @@ fn mirCallExtern(emit: *Emit, inst: Mir.Inst.Index) !void {
662662 const relocation = emit.mir.instructions.items(.data)[inst].relocation;
663663
664664 const offset = blk: {
665 const offset = @intCast(u32, emit.code.items.len);
665 const offset = @as(u32, @intCast(emit.code.items.len));
666666 // bl
667667 try emit.writeInstruction(Instruction.bl(0));
668668 break :blk offset;
......@@ -837,11 +837,11 @@ fn mirLoadMemoryPie(emit: *Emit, inst: Mir.Inst.Index) !void {
837837 const tag = emit.mir.instructions.items(.tag)[inst];
838838 const payload = emit.mir.instructions.items(.data)[inst].payload;
839839 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
842842 // PC-relative displacement to the entry in memory.
843843 // adrp
844 const offset = @intCast(u32, emit.code.items.len);
844 const offset = @as(u32, @intCast(emit.code.items.len));
845845 try emit.writeInstruction(Instruction.adrp(reg.toX(), 0));
846846
847847 switch (tag) {
......@@ -1220,7 +1220,7 @@ fn mirNop(emit: *Emit) !void {
12201220}
12211221
12221222fn 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;
12241224}
12251225
12261226fn mirPushPopRegs(emit: *Emit, inst: Mir.Inst.Index) !void {
......@@ -1245,7 +1245,7 @@ fn mirPushPopRegs(emit: *Emit, inst: Mir.Inst.Index) !void {
12451245 var count: u6 = 0;
12461246 var other_reg: ?Register = null;
12471247 while (i > 0) : (i -= 1) {
1248 const reg = @enumFromInt(Register, i - 1);
1248 const reg = @as(Register, @enumFromInt(i - 1));
12491249 if (regListIsSet(reg_list, reg)) {
12501250 if (count == 0 and odd_number_of_regs) {
12511251 try emit.writeInstruction(Instruction.ldr(
......@@ -1274,7 +1274,7 @@ fn mirPushPopRegs(emit: *Emit, inst: Mir.Inst.Index) !void {
12741274 var count: u6 = 0;
12751275 var other_reg: ?Register = null;
12761276 while (i < 32) : (i += 1) {
1277 const reg = @enumFromInt(Register, i);
1277 const reg = @as(Register, @enumFromInt(i));
12781278 if (regListIsSet(reg_list, reg)) {
12791279 if (count == number_of_regs - 1 and odd_number_of_regs) {
12801280 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
507507 inline for (fields) |field| {
508508 @field(result, field.name) = switch (field.type) {
509509 u32 => mir.extra[i],
510 i32 => @bitCast(i32, mir.extra[i]),
510 i32 => @as(i32, @bitCast(mir.extra[i])),
511511 else => @compileError("bad field type"),
512512 };
513513 i += 1;
src/arch/aarch64/bits.zig+109-109
......@@ -80,34 +80,34 @@ pub const Register = enum(u8) {
8080
8181 pub fn id(self: Register) u6 {
8282 return switch (@intFromEnum(self)) {
83 @intFromEnum(Register.x0)...@intFromEnum(Register.xzr) => @intCast(u6, @intFromEnum(self) - @intFromEnum(Register.x0)),
84 @intFromEnum(Register.w0)...@intFromEnum(Register.wzr) => @intCast(u6, @intFromEnum(self) - @intFromEnum(Register.w0)),
83 @intFromEnum(Register.x0)...@intFromEnum(Register.xzr) => @as(u6, @intCast(@intFromEnum(self) - @intFromEnum(Register.x0))),
84 @intFromEnum(Register.w0)...@intFromEnum(Register.wzr) => @as(u6, @intCast(@intFromEnum(self) - @intFromEnum(Register.w0))),
8585
8686 @intFromEnum(Register.sp) => 32,
8787 @intFromEnum(Register.wsp) => 32,
8888
89 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @intCast(u6, @intFromEnum(self) - @intFromEnum(Register.q0) + 33),
90 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @intCast(u6, @intFromEnum(self) - @intFromEnum(Register.d0) + 33),
91 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @intCast(u6, @intFromEnum(self) - @intFromEnum(Register.s0) + 33),
92 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @intCast(u6, @intFromEnum(self) - @intFromEnum(Register.h0) + 33),
93 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @intCast(u6, @intFromEnum(self) - @intFromEnum(Register.b0) + 33),
89 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @as(u6, @intCast(@intFromEnum(self) - @intFromEnum(Register.q0) + 33)),
90 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @as(u6, @intCast(@intFromEnum(self) - @intFromEnum(Register.d0) + 33)),
91 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @as(u6, @intCast(@intFromEnum(self) - @intFromEnum(Register.s0) + 33)),
92 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @as(u6, @intCast(@intFromEnum(self) - @intFromEnum(Register.h0) + 33)),
93 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @as(u6, @intCast(@intFromEnum(self) - @intFromEnum(Register.b0) + 33)),
9494 else => unreachable,
9595 };
9696 }
9797
9898 pub fn enc(self: Register) u5 {
9999 return switch (@intFromEnum(self)) {
100 @intFromEnum(Register.x0)...@intFromEnum(Register.xzr) => @intCast(u5, @intFromEnum(self) - @intFromEnum(Register.x0)),
101 @intFromEnum(Register.w0)...@intFromEnum(Register.wzr) => @intCast(u5, @intFromEnum(self) - @intFromEnum(Register.w0)),
100 @intFromEnum(Register.x0)...@intFromEnum(Register.xzr) => @as(u5, @intCast(@intFromEnum(self) - @intFromEnum(Register.x0))),
101 @intFromEnum(Register.w0)...@intFromEnum(Register.wzr) => @as(u5, @intCast(@intFromEnum(self) - @intFromEnum(Register.w0))),
102102
103103 @intFromEnum(Register.sp) => 31,
104104 @intFromEnum(Register.wsp) => 31,
105105
106 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @intCast(u5, @intFromEnum(self) - @intFromEnum(Register.q0)),
107 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @intCast(u5, @intFromEnum(self) - @intFromEnum(Register.d0)),
108 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @intCast(u5, @intFromEnum(self) - @intFromEnum(Register.s0)),
109 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @intCast(u5, @intFromEnum(self) - @intFromEnum(Register.h0)),
110 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @intCast(u5, @intFromEnum(self) - @intFromEnum(Register.b0)),
106 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @as(u5, @intCast(@intFromEnum(self) - @intFromEnum(Register.q0))),
107 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @as(u5, @intCast(@intFromEnum(self) - @intFromEnum(Register.d0))),
108 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @as(u5, @intCast(@intFromEnum(self) - @intFromEnum(Register.s0))),
109 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @as(u5, @intCast(@intFromEnum(self) - @intFromEnum(Register.h0))),
110 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @as(u5, @intCast(@intFromEnum(self) - @intFromEnum(Register.b0))),
111111 else => unreachable,
112112 };
113113 }
......@@ -133,13 +133,13 @@ pub const Register = enum(u8) {
133133 /// Convert from a general-purpose register to its 64 bit alias.
134134 pub fn toX(self: Register) Register {
135135 return switch (@intFromEnum(self)) {
136 @intFromEnum(Register.x0)...@intFromEnum(Register.xzr) => @enumFromInt(
136 @intFromEnum(Register.x0)...@intFromEnum(Register.xzr) => @as(
137137 Register,
138 @intFromEnum(self) - @intFromEnum(Register.x0) + @intFromEnum(Register.x0),
138 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.x0) + @intFromEnum(Register.x0)),
139139 ),
140 @intFromEnum(Register.w0)...@intFromEnum(Register.wzr) => @enumFromInt(
140 @intFromEnum(Register.w0)...@intFromEnum(Register.wzr) => @as(
141141 Register,
142 @intFromEnum(self) - @intFromEnum(Register.w0) + @intFromEnum(Register.x0),
142 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.w0) + @intFromEnum(Register.x0)),
143143 ),
144144 else => unreachable,
145145 };
......@@ -148,13 +148,13 @@ pub const Register = enum(u8) {
148148 /// Convert from a general-purpose register to its 32 bit alias.
149149 pub fn toW(self: Register) Register {
150150 return switch (@intFromEnum(self)) {
151 @intFromEnum(Register.x0)...@intFromEnum(Register.xzr) => @enumFromInt(
151 @intFromEnum(Register.x0)...@intFromEnum(Register.xzr) => @as(
152152 Register,
153 @intFromEnum(self) - @intFromEnum(Register.x0) + @intFromEnum(Register.w0),
153 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.x0) + @intFromEnum(Register.w0)),
154154 ),
155 @intFromEnum(Register.w0)...@intFromEnum(Register.wzr) => @enumFromInt(
155 @intFromEnum(Register.w0)...@intFromEnum(Register.wzr) => @as(
156156 Register,
157 @intFromEnum(self) - @intFromEnum(Register.w0) + @intFromEnum(Register.w0),
157 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.w0) + @intFromEnum(Register.w0)),
158158 ),
159159 else => unreachable,
160160 };
......@@ -163,25 +163,25 @@ pub const Register = enum(u8) {
163163 /// Convert from a floating-point register to its 128 bit alias.
164164 pub fn toQ(self: Register) Register {
165165 return switch (@intFromEnum(self)) {
166 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @enumFromInt(
166 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @as(
167167 Register,
168 @intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.q0),
168 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.q0)),
169169 ),
170 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @enumFromInt(
170 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @as(
171171 Register,
172 @intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.q0),
172 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.q0)),
173173 ),
174 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @enumFromInt(
174 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @as(
175175 Register,
176 @intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.q0),
176 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.q0)),
177177 ),
178 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @enumFromInt(
178 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @as(
179179 Register,
180 @intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.q0),
180 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.q0)),
181181 ),
182 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @enumFromInt(
182 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @as(
183183 Register,
184 @intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.q0),
184 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.q0)),
185185 ),
186186 else => unreachable,
187187 };
......@@ -190,25 +190,25 @@ pub const Register = enum(u8) {
190190 /// Convert from a floating-point register to its 64 bit alias.
191191 pub fn toD(self: Register) Register {
192192 return switch (@intFromEnum(self)) {
193 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @enumFromInt(
193 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @as(
194194 Register,
195 @intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.d0),
195 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.d0)),
196196 ),
197 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @enumFromInt(
197 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @as(
198198 Register,
199 @intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.d0),
199 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.d0)),
200200 ),
201 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @enumFromInt(
201 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @as(
202202 Register,
203 @intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.d0),
203 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.d0)),
204204 ),
205 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @enumFromInt(
205 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @as(
206206 Register,
207 @intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.d0),
207 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.d0)),
208208 ),
209 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @enumFromInt(
209 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @as(
210210 Register,
211 @intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.d0),
211 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.d0)),
212212 ),
213213 else => unreachable,
214214 };
......@@ -217,25 +217,25 @@ pub const Register = enum(u8) {
217217 /// Convert from a floating-point register to its 32 bit alias.
218218 pub fn toS(self: Register) Register {
219219 return switch (@intFromEnum(self)) {
220 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @enumFromInt(
220 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @as(
221221 Register,
222 @intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.s0),
222 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.s0)),
223223 ),
224 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @enumFromInt(
224 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @as(
225225 Register,
226 @intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.s0),
226 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.s0)),
227227 ),
228 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @enumFromInt(
228 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @as(
229229 Register,
230 @intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.s0),
230 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.s0)),
231231 ),
232 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @enumFromInt(
232 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @as(
233233 Register,
234 @intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.s0),
234 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.s0)),
235235 ),
236 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @enumFromInt(
236 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @as(
237237 Register,
238 @intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.s0),
238 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.s0)),
239239 ),
240240 else => unreachable,
241241 };
......@@ -244,25 +244,25 @@ pub const Register = enum(u8) {
244244 /// Convert from a floating-point register to its 16 bit alias.
245245 pub fn toH(self: Register) Register {
246246 return switch (@intFromEnum(self)) {
247 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @enumFromInt(
247 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @as(
248248 Register,
249 @intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.h0),
249 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.h0)),
250250 ),
251 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @enumFromInt(
251 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @as(
252252 Register,
253 @intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.h0),
253 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.h0)),
254254 ),
255 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @enumFromInt(
255 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @as(
256256 Register,
257 @intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.h0),
257 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.h0)),
258258 ),
259 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @enumFromInt(
259 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @as(
260260 Register,
261 @intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.h0),
261 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.h0)),
262262 ),
263 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @enumFromInt(
263 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @as(
264264 Register,
265 @intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.h0),
265 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.h0)),
266266 ),
267267 else => unreachable,
268268 };
......@@ -271,25 +271,25 @@ pub const Register = enum(u8) {
271271 /// Convert from a floating-point register to its 8 bit alias.
272272 pub fn toB(self: Register) Register {
273273 return switch (@intFromEnum(self)) {
274 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @enumFromInt(
274 @intFromEnum(Register.q0)...@intFromEnum(Register.q31) => @as(
275275 Register,
276 @intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.b0),
276 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.q0) + @intFromEnum(Register.b0)),
277277 ),
278 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @enumFromInt(
278 @intFromEnum(Register.d0)...@intFromEnum(Register.d31) => @as(
279279 Register,
280 @intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.b0),
280 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.d0) + @intFromEnum(Register.b0)),
281281 ),
282 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @enumFromInt(
282 @intFromEnum(Register.s0)...@intFromEnum(Register.s31) => @as(
283283 Register,
284 @intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.b0),
284 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.s0) + @intFromEnum(Register.b0)),
285285 ),
286 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @enumFromInt(
286 @intFromEnum(Register.h0)...@intFromEnum(Register.h31) => @as(
287287 Register,
288 @intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.b0),
288 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.h0) + @intFromEnum(Register.b0)),
289289 ),
290 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @enumFromInt(
290 @intFromEnum(Register.b0)...@intFromEnum(Register.b31) => @as(
291291 Register,
292 @intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.b0),
292 @enumFromInt(@intFromEnum(self) - @intFromEnum(Register.b0) + @intFromEnum(Register.b0)),
293293 ),
294294 else => unreachable,
295295 };
......@@ -612,27 +612,27 @@ pub const Instruction = union(enum) {
612612
613613 pub fn toU32(self: Instruction) u32 {
614614 return switch (self) {
615 .move_wide_immediate => |v| @bitCast(u32, v),
616 .pc_relative_address => |v| @bitCast(u32, v),
617 .load_store_register => |v| @bitCast(u32, v),
618 .load_store_register_pair => |v| @bitCast(u32, v),
619 .load_literal => |v| @bitCast(u32, v),
620 .exception_generation => |v| @bitCast(u32, v),
621 .unconditional_branch_register => |v| @bitCast(u32, v),
622 .unconditional_branch_immediate => |v| @bitCast(u32, v),
623 .no_operation => |v| @bitCast(u32, v),
624 .logical_shifted_register => |v| @bitCast(u32, v),
625 .add_subtract_immediate => |v| @bitCast(u32, v),
626 .logical_immediate => |v| @bitCast(u32, v),
627 .bitfield => |v| @bitCast(u32, v),
628 .add_subtract_shifted_register => |v| @bitCast(u32, v),
629 .add_subtract_extended_register => |v| @bitCast(u32, v),
615 .move_wide_immediate => |v| @as(u32, @bitCast(v)),
616 .pc_relative_address => |v| @as(u32, @bitCast(v)),
617 .load_store_register => |v| @as(u32, @bitCast(v)),
618 .load_store_register_pair => |v| @as(u32, @bitCast(v)),
619 .load_literal => |v| @as(u32, @bitCast(v)),
620 .exception_generation => |v| @as(u32, @bitCast(v)),
621 .unconditional_branch_register => |v| @as(u32, @bitCast(v)),
622 .unconditional_branch_immediate => |v| @as(u32, @bitCast(v)),
623 .no_operation => |v| @as(u32, @bitCast(v)),
624 .logical_shifted_register => |v| @as(u32, @bitCast(v)),
625 .add_subtract_immediate => |v| @as(u32, @bitCast(v)),
626 .logical_immediate => |v| @as(u32, @bitCast(v)),
627 .bitfield => |v| @as(u32, @bitCast(v)),
628 .add_subtract_shifted_register => |v| @as(u32, @bitCast(v)),
629 .add_subtract_extended_register => |v| @as(u32, @bitCast(v)),
630630 // TODO once packed structs work, this can be refactored
631631 .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),
632632 .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),
633633 .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),
635 .data_processing_2_source => |v| @bitCast(u32, v),
634 .data_processing_3_source => |v| @as(u32, @bitCast(v)),
635 .data_processing_2_source => |v| @as(u32, @bitCast(v)),
636636 };
637637 }
638638
......@@ -650,7 +650,7 @@ pub const Instruction = union(enum) {
650650 .move_wide_immediate = .{
651651 .rd = rd.enc(),
652652 .imm16 = imm16,
653 .hw = @intCast(u2, shift / 16),
653 .hw = @as(u2, @intCast(shift / 16)),
654654 .opc = opc,
655655 .sf = switch (rd.size()) {
656656 32 => 0,
......@@ -663,12 +663,12 @@ pub const Instruction = union(enum) {
663663
664664 fn pcRelativeAddress(rd: Register, imm21: i21, op: u1) Instruction {
665665 assert(rd.size() == 64);
666 const imm21_u = @bitCast(u21, imm21);
666 const imm21_u = @as(u21, @bitCast(imm21));
667667 return Instruction{
668668 .pc_relative_address = .{
669669 .rd = rd.enc(),
670 .immlo = @truncate(u2, imm21_u),
671 .immhi = @truncate(u19, imm21_u >> 2),
670 .immlo = @as(u2, @truncate(imm21_u)),
671 .immhi = @as(u19, @truncate(imm21_u >> 2)),
672672 .op = op,
673673 },
674674 };
......@@ -704,15 +704,15 @@ pub const Instruction = union(enum) {
704704 pub fn toU12(self: LoadStoreOffset) u12 {
705705 return switch (self) {
706706 .immediate => |imm_type| switch (imm_type) {
707 .post_index => |v| (@intCast(u12, @bitCast(u9, v)) << 2) + 1,
708 .pre_index => |v| (@intCast(u12, @bitCast(u9, v)) << 2) + 3,
707 .post_index => |v| (@as(u12, @intCast(@as(u9, @bitCast(v)))) << 2) + 1,
708 .pre_index => |v| (@as(u12, @intCast(@as(u9, @bitCast(v)))) << 2) + 3,
709709 .unsigned => |v| v,
710710 },
711711 .register => |r| switch (r.shift) {
712 .uxtw => |v| (@intCast(u12, r.rm) << 6) + (@intCast(u12, v) << 2) + 16 + 2050,
713 .lsl => |v| (@intCast(u12, r.rm) << 6) + (@intCast(u12, v) << 2) + 24 + 2050,
714 .sxtw => |v| (@intCast(u12, r.rm) << 6) + (@intCast(u12, v) << 2) + 48 + 2050,
715 .sxtx => |v| (@intCast(u12, r.rm) << 6) + (@intCast(u12, v) << 2) + 56 + 2050,
712 .uxtw => |v| (@as(u12, @intCast(r.rm)) << 6) + (@as(u12, @intCast(v)) << 2) + 16 + 2050,
713 .lsl => |v| (@as(u12, @intCast(r.rm)) << 6) + (@as(u12, @intCast(v)) << 2) + 24 + 2050,
714 .sxtw => |v| (@as(u12, @intCast(r.rm)) << 6) + (@as(u12, @intCast(v)) << 2) + 48 + 2050,
715 .sxtx => |v| (@as(u12, @intCast(r.rm)) << 6) + (@as(u12, @intCast(v)) << 2) + 56 + 2050,
716716 },
717717 };
718718 }
......@@ -894,7 +894,7 @@ pub const Instruction = union(enum) {
894894 switch (rt1.size()) {
895895 32 => {
896896 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))));
898898 return Instruction{
899899 .load_store_register_pair = .{
900900 .rt1 = rt1.enc(),
......@@ -909,7 +909,7 @@ pub const Instruction = union(enum) {
909909 },
910910 64 => {
911911 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))));
913913 return Instruction{
914914 .load_store_register_pair = .{
915915 .rt1 = rt1.enc(),
......@@ -982,7 +982,7 @@ pub const Instruction = union(enum) {
982982 ) Instruction {
983983 return Instruction{
984984 .unconditional_branch_immediate = .{
985 .imm26 = @bitCast(u26, @intCast(i26, offset >> 2)),
985 .imm26 = @as(u26, @bitCast(@as(i26, @intCast(offset >> 2)))),
986986 .op = op,
987987 },
988988 };
......@@ -1188,7 +1188,7 @@ pub const Instruction = union(enum) {
11881188 .conditional_branch = .{
11891189 .cond = @intFromEnum(cond),
11901190 .o0 = o0,
1191 .imm19 = @bitCast(u19, @intCast(i19, offset >> 2)),
1191 .imm19 = @as(u19, @bitCast(@as(i19, @intCast(offset >> 2)))),
11921192 .o1 = o1,
11931193 },
11941194 };
......@@ -1204,7 +1204,7 @@ pub const Instruction = union(enum) {
12041204 return Instruction{
12051205 .compare_and_branch = .{
12061206 .rt = rt.enc(),
1207 .imm19 = @bitCast(u19, @intCast(i19, offset >> 2)),
1207 .imm19 = @as(u19, @bitCast(@as(i19, @intCast(offset >> 2)))),
12081208 .op = op,
12091209 .sf = switch (rt.size()) {
12101210 32 => 0b0,
......@@ -1609,12 +1609,12 @@ pub const Instruction = union(enum) {
16091609 }
16101610
16111611 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));
16131613 return sbfm(rd, rn, shift, imms);
16141614 }
16151615
16161616 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)));
16181618 }
16191619
16201620 pub fn sxtb(rd: Register, rn: Register) Instruction {
......@@ -1631,17 +1631,17 @@ pub const Instruction = union(enum) {
16311631 }
16321632
16331633 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));
16351635 return ubfm(rd, rn, size - shift + 1, size - shift);
16361636 }
16371637
16381638 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));
16401640 return ubfm(rd, rn, shift, imms);
16411641 }
16421642
16431643 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)));
16451645 }
16461646
16471647 pub fn uxtb(rd: Register, rn: Register) Instruction {
src/arch/arm/CodeGen.zig+96-96
......@@ -266,8 +266,8 @@ const DbgInfoReloc = struct {
266266 .stack_argument_offset,
267267 => blk: {
268268 const adjusted_stack_offset = switch (reloc.mcv) {
269 .stack_offset => |offset| -@intCast(i32, offset),
270 .stack_argument_offset => |offset| @intCast(i32, function.saved_regs_stack_space + offset),
269 .stack_offset => |offset| -@as(i32, @intCast(offset)),
270 .stack_argument_offset => |offset| @as(i32, @intCast(function.saved_regs_stack_space + offset)),
271271 else => unreachable,
272272 };
273273 break :blk .{ .stack = .{
......@@ -303,8 +303,8 @@ const DbgInfoReloc = struct {
303303 const adjusted_offset = switch (reloc.mcv) {
304304 .ptr_stack_offset,
305305 .stack_offset,
306 => -@intCast(i32, offset),
307 .stack_argument_offset => @intCast(i32, function.saved_regs_stack_space + offset),
306 => -@as(i32, @intCast(offset)),
307 .stack_argument_offset => @as(i32, @intCast(function.saved_regs_stack_space + offset)),
308308 else => unreachable,
309309 };
310310 break :blk .{ .stack = .{
......@@ -446,7 +446,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
446446
447447 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));
450450 self.mir_instructions.appendAssumeCapacity(inst);
451451 return result_index;
452452}
......@@ -466,11 +466,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {
466466
467467pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
468468 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));
470470 inline for (fields) |field| {
471471 self.mir_extra.appendAssumeCapacity(switch (field.type) {
472472 u32 => @field(extra, field.name),
473 i32 => @bitCast(u32, @field(extra, field.name)),
473 i32 => @as(u32, @bitCast(@field(extra, field.name))),
474474 else => @compileError("bad field type"),
475475 });
476476 }
......@@ -522,7 +522,7 @@ fn gen(self: *Self) !void {
522522
523523 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)));
526526 const abi_align = ty.abiAlignment(mod);
527527 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
528528 try self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
......@@ -588,7 +588,7 @@ fn gen(self: *Self) !void {
588588 for (self.exitlude_jump_relocs.items) |jmp_reloc| {
589589 self.mir_instructions.set(jmp_reloc, .{
590590 .tag = .b,
591 .data = .{ .inst = @intCast(u32, self.mir_instructions.len) },
591 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len)) },
592592 });
593593 }
594594
......@@ -934,15 +934,15 @@ fn finishAirBookkeeping(self: *Self) void {
934934fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void {
935935 var tomb_bits = self.liveness.getTombBits(inst);
936936 for (operands) |op| {
937 const dies = @truncate(u1, tomb_bits) != 0;
937 const dies = @as(u1, @truncate(tomb_bits)) != 0;
938938 tomb_bits >>= 1;
939939 if (!dies) continue;
940940 const op_int = @intFromEnum(op);
941941 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));
943943 self.processDeath(op_index);
944944 }
945 const is_used = @truncate(u1, tomb_bits) == 0;
945 const is_used = @as(u1, @truncate(tomb_bits)) == 0;
946946 if (is_used) {
947947 log.debug("%{d} => {}", .{ inst, result });
948948 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
......@@ -1201,7 +1201,7 @@ fn truncRegister(
12011201 .rd = dest_reg,
12021202 .rn = operand_reg,
12031203 .lsb = 0,
1204 .width = @intCast(u6, int_bits),
1204 .width = @as(u6, @intCast(int_bits)),
12051205 } },
12061206 });
12071207}
......@@ -1591,9 +1591,9 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
15911591 const rhs_ty = self.typeOf(extra.rhs);
15921592
15931593 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)));
15951595 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
15981598 switch (lhs_ty.zigTypeTag(mod)) {
15991599 .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 {
17041704 const rhs_ty = self.typeOf(extra.rhs);
17051705
17061706 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)));
17081708 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
17111711 switch (lhs_ty.zigTypeTag(mod)) {
17121712 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
......@@ -1866,9 +1866,9 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
18661866 const rhs_ty = self.typeOf(extra.rhs);
18671867
18681868 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)));
18701870 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
18731873 switch (lhs_ty.zigTypeTag(mod)) {
18741874 .Vector => return self.fail("TODO implement shl_with_overflow for vectors", .{}),
......@@ -1915,7 +1915,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
19151915 .data = .{ .rr_shift = .{
19161916 .rd = dest_reg,
19171917 .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))),
19191919 } },
19201920 });
19211921
......@@ -1927,7 +1927,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
19271927 .data = .{ .rr_shift = .{
19281928 .rd = reconstructed_reg,
19291929 .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))),
19311931 } },
19321932 });
19331933 } else {
......@@ -2020,7 +2020,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
20202020 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
20212021 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
20222022 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
20252025 // Optional with a zero-bit payload type is just a boolean true
20262026 if (abi_size == 1) {
......@@ -2049,7 +2049,7 @@ fn errUnionErr(
20492049 return try error_union_bind.resolveToMcv(self);
20502050 }
20512051
2052 const err_offset = @intCast(u32, errUnionErrorOffset(payload_ty, mod));
2052 const err_offset = @as(u32, @intCast(errUnionErrorOffset(payload_ty, mod)));
20532053 switch (try error_union_bind.resolveToMcv(self)) {
20542054 .register => {
20552055 var operand_reg: Register = undefined;
......@@ -2071,15 +2071,15 @@ fn errUnionErr(
20712071 );
20722072
20732073 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
20762076 _ = try self.addInst(.{
20772077 .tag = .ubfx, // errors are unsigned integers
20782078 .data = .{ .rr_lsb_width = .{
20792079 .rd = dest_reg,
20802080 .rn = operand_reg,
2081 .lsb = @intCast(u5, err_bit_offset),
2082 .width = @intCast(u6, err_bit_size),
2081 .lsb = @as(u5, @intCast(err_bit_offset)),
2082 .width = @as(u6, @intCast(err_bit_size)),
20832083 } },
20842084 });
20852085
......@@ -2126,7 +2126,7 @@ fn errUnionPayload(
21262126 return MCValue.none;
21272127 }
21282128
2129 const payload_offset = @intCast(u32, errUnionPayloadOffset(payload_ty, mod));
2129 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, mod)));
21302130 switch (try error_union_bind.resolveToMcv(self)) {
21312131 .register => {
21322132 var operand_reg: Register = undefined;
......@@ -2148,15 +2148,15 @@ fn errUnionPayload(
21482148 );
21492149
21502150 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
21532153 _ = try self.addInst(.{
21542154 .tag = if (payload_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,
21552155 .data = .{ .rr_lsb_width = .{
21562156 .rd = dest_reg,
21572157 .rn = operand_reg,
2158 .lsb = @intCast(u5, payload_bit_offset),
2159 .width = @intCast(u6, payload_bit_size),
2158 .lsb = @as(u5, @intCast(payload_bit_offset)),
2159 .width = @as(u6, @intCast(payload_bit_size)),
21602160 } },
21612161 });
21622162
......@@ -2235,13 +2235,13 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
22352235 const operand = try self.resolveInst(ty_op.operand);
22362236 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)));
22392239 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)));
22412241 const payload_off = errUnionPayloadOffset(payload_ty, mod);
22422242 const err_off = errUnionErrorOffset(payload_ty, mod);
2243 try self.genSetStack(payload_ty, stack_offset - @intCast(u32, payload_off), operand);
2244 try self.genSetStack(error_ty, stack_offset - @intCast(u32, err_off), .{ .immediate = 0 });
2243 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), operand);
2244 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), .{ .immediate = 0 });
22452245
22462246 break :result MCValue{ .stack_offset = stack_offset };
22472247 };
......@@ -2259,13 +2259,13 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
22592259 const operand = try self.resolveInst(ty_op.operand);
22602260 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)));
22632263 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)));
22652265 const payload_off = errUnionPayloadOffset(payload_ty, mod);
22662266 const err_off = errUnionErrorOffset(payload_ty, mod);
2267 try self.genSetStack(error_ty, stack_offset - @intCast(u32, err_off), operand);
2268 try self.genSetStack(payload_ty, stack_offset - @intCast(u32, payload_off), .undef);
2267 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), operand);
2268 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), .undef);
22692269
22702270 break :result MCValue{ .stack_offset = stack_offset };
22712271 };
......@@ -2369,7 +2369,7 @@ fn ptrElemVal(
23692369) !MCValue {
23702370 const mod = self.bin_file.options.module.?;
23712371 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
23742374 switch (elem_size) {
23752375 1, 4 => {
......@@ -2480,7 +2480,7 @@ fn arrayElemVal(
24802480 => {
24812481 const ptr_to_mcv = switch (mcv) {
24822482 .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)) },
24842484 .stack_argument_offset => |off| blk: {
24852485 const reg = try self.register_manager.allocReg(null, gp);
24862486
......@@ -2654,7 +2654,7 @@ fn reuseOperand(
26542654fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {
26552655 const mod = self.bin_file.options.module.?;
26562656 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
26592659 switch (ptr) {
26602660 .none => unreachable,
......@@ -2759,7 +2759,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
27592759
27602760fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {
27612761 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
27642764 switch (ptr) {
27652765 .none => unreachable,
......@@ -2814,7 +2814,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
28142814 // sub src_reg, fp, #off
28152815 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });
28162816 },
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)) }),
28182818 .stack_argument_offset => |off| {
28192819 _ = try self.addInst(.{
28202820 .tag = .ldr_ptr_stack_argument,
......@@ -2882,7 +2882,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
28822882 const mcv = try self.resolveInst(operand);
28832883 const ptr_ty = self.typeOf(operand);
28842884 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)));
28862886 switch (mcv) {
28872887 .ptr_stack_offset => |off| {
28882888 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };
......@@ -2906,7 +2906,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
29062906 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
29072907 const mcv = try self.resolveInst(operand);
29082908 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)));
29102910 const struct_field_ty = struct_ty.structFieldType(index, mod);
29112911
29122912 switch (mcv) {
......@@ -2970,15 +2970,15 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
29702970 );
29712971
29722972 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
29752975 _ = try self.addInst(.{
29762976 .tag = if (struct_field_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,
29772977 .data = .{ .rr_lsb_width = .{
29782978 .rd = dest_reg,
29792979 .rn = operand_reg,
2980 .lsb = @intCast(u5, field_bit_offset),
2981 .width = @intCast(u6, field_bit_size),
2980 .lsb = @as(u5, @intCast(field_bit_offset)),
2981 .width = @as(u6, @intCast(field_bit_size)),
29822982 } },
29832983 });
29842984
......@@ -3003,7 +3003,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
30033003 return self.fail("TODO implement @fieldParentPtr codegen for unions", .{});
30043004 }
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)));
30073007 switch (field_ptr) {
30083008 .ptr_stack_offset => |off| {
30093009 break :result MCValue{ .ptr_stack_offset = off + struct_field_offset };
......@@ -3364,7 +3364,7 @@ fn binOpImmediate(
33643364 => .{ .rr_shift = .{
33653365 .rd = dest_reg,
33663366 .rm = lhs_reg,
3367 .shift_amount = Instruction.ShiftAmount.imm(@intCast(u5, rhs_immediate)),
3367 .shift_amount = Instruction.ShiftAmount.imm(@as(u5, @intCast(rhs_immediate))),
33683368 } },
33693369 else => unreachable,
33703370 };
......@@ -3895,7 +3895,7 @@ fn ptrArithmetic(
38953895 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type
38963896 else => ptr_ty.childType(mod),
38973897 };
3898 const elem_size = @intCast(u32, elem_ty.abiSize(mod));
3898 const elem_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
38993899
39003900 const base_tag: Air.Inst.Tag = switch (tag) {
39013901 .ptr_add => .add,
......@@ -4022,7 +4022,7 @@ fn genInlineMemcpy(
40224022 _ = try self.addInst(.{
40234023 .tag = .b,
40244024 .cond = .ge,
4025 .data = .{ .inst = @intCast(u32, self.mir_instructions.len + 5) },
4025 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len + 5)) },
40264026 });
40274027
40284028 // ldrb tmp, [src, count]
......@@ -4058,7 +4058,7 @@ fn genInlineMemcpy(
40584058 // b loop
40594059 _ = try self.addInst(.{
40604060 .tag = .b,
4061 .data = .{ .inst = @intCast(u32, self.mir_instructions.len - 5) },
4061 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len - 5)) },
40624062 });
40634063
40644064 // end:
......@@ -4126,7 +4126,7 @@ fn genInlineMemsetCode(
41264126 _ = try self.addInst(.{
41274127 .tag = .b,
41284128 .cond = .ge,
4129 .data = .{ .inst = @intCast(u32, self.mir_instructions.len + 4) },
4129 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len + 4)) },
41304130 });
41314131
41324132 // strb val, [src, count]
......@@ -4152,7 +4152,7 @@ fn genInlineMemsetCode(
41524152 // b loop
41534153 _ = try self.addInst(.{
41544154 .tag = .b,
4155 .data = .{ .inst = @intCast(u32, self.mir_instructions.len - 4) },
4155 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len - 4)) },
41564156 });
41574157
41584158 // end:
......@@ -4216,7 +4216,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42164216 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
42174217 const callee = pl_op.operand;
42184218 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]));
42204220 const ty = self.typeOf(callee);
42214221 const mod = self.bin_file.options.module.?;
42224222
......@@ -4248,8 +4248,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42484248 const r0_lock: ?RegisterLock = if (info.return_value == .stack_offset) blk: {
42494249 log.debug("airCall: return by reference", .{});
42504250 const ret_ty = fn_ty.fnReturnType(mod);
4251 const ret_abi_size = @intCast(u32, ret_ty.abiSize(mod));
4252 const ret_abi_align = @intCast(u32, ret_ty.abiAlignment(mod));
4251 const ret_abi_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
4252 const ret_abi_align = @as(u32, @intCast(ret_ty.abiAlignment(mod)));
42534253 const stack_offset = try self.allocMem(ret_abi_size, ret_abi_align, inst);
42544254
42554255 const ptr_ty = try mod.singleMutPtrType(ret_ty);
......@@ -4294,7 +4294,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42944294 const atom_index = try elf_file.getOrCreateAtomForDecl(func.owner_decl);
42954295 const atom = elf_file.getAtom(atom_index);
42964296 _ = 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)));
42984298 try self.genSetReg(Type.usize, .lr, .{ .memory = got_addr });
42994299 } else if (self.bin_file.cast(link.File.MachO)) |_| {
43004300 unreachable; // unsupported architecture for MachO
......@@ -4425,7 +4425,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
44254425 // location.
44264426 const op_inst = Air.refToIndex(un_op).?;
44274427 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)));
44294429 const abi_align = ret_ty.abiAlignment(mod);
44304430
44314431 const offset = try self.allocMem(abi_size, abi_align, null);
......@@ -4651,7 +4651,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
46514651 if (self.liveness.operandDies(inst, 0)) {
46524652 const op_int = @intFromEnum(pl_op.operand);
46534653 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));
46554655 self.processDeath(op_index);
46564656 }
46574657 }
......@@ -4956,7 +4956,7 @@ fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
49564956 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
49574957 const loop = self.air.extraData(Air.Block, ty_pl.payload);
49584958 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
49614961 try self.genBody(body);
49624962 try self.jump(start_index);
......@@ -5021,7 +5021,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
50215021 var case_i: u32 = 0;
50225022 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
50235023 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]));
50255025 assert(items.len > 0);
50265026 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
50275027 extra_index = case.end + items.len + case_body.len;
......@@ -5139,7 +5139,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
51395139fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {
51405140 const tag = self.mir_instructions.items(.tag)[inst];
51415141 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)),
51435143 else => unreachable,
51445144 }
51455145}
......@@ -5188,12 +5188,12 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {
51885188fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
51895189 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
51905190 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
5191 const is_volatile = @truncate(u1, extra.data.flags >> 31) != 0;
5192 const clobbers_len = @truncate(u31, extra.data.flags);
5191 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
5192 const clobbers_len = @as(u31, @truncate(extra.data.flags));
51935193 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]));
51955195 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]));
51975197 extra_i += inputs.len;
51985198
51995199 const dead = !is_volatile and self.liveness.isUnused(inst);
......@@ -5323,7 +5323,7 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {
53235323
53245324fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
53255325 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)));
53275327 switch (mcv) {
53285328 .dead => unreachable,
53295329 .unreach, .none => return, // Nothing to do.
......@@ -5376,7 +5376,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
53765376 },
53775377 2 => {
53785378 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)));
53805380 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset }));
53815381
53825382 _ = try self.addInst(.{
......@@ -5404,7 +5404,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
54045404 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = reg });
54055405
54065406 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)));
54085408 const cond_reg = try self.register_manager.allocReg(null, gp);
54095409
54105410 // C flag: movcs reg, #1
......@@ -5457,7 +5457,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
54575457 // sub src_reg, fp, #off
54585458 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });
54595459 },
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)) }),
54615461 .stack_argument_offset => |off| {
54625462 _ = try self.addInst(.{
54635463 .tag = .ldr_ptr_stack_argument,
......@@ -5554,7 +5554,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
55545554 .tag = .movw,
55555555 .data = .{ .r_imm16 = .{
55565556 .rd = reg,
5557 .imm16 = @intCast(u16, x),
5557 .imm16 = @as(u16, @intCast(x)),
55585558 } },
55595559 });
55605560 } else {
......@@ -5562,7 +5562,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
55625562 .tag = .mov,
55635563 .data = .{ .r_op_mov = .{
55645564 .rd = reg,
5565 .op = Instruction.Operand.imm(@truncate(u8, x), 0),
5565 .op = Instruction.Operand.imm(@as(u8, @truncate(x)), 0),
55665566 } },
55675567 });
55685568 _ = try self.addInst(.{
......@@ -5570,7 +5570,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
55705570 .data = .{ .rr_op = .{
55715571 .rd = reg,
55725572 .rn = reg,
5573 .op = Instruction.Operand.imm(@truncate(u8, x >> 8), 12),
5573 .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 8)), 12),
55745574 } },
55755575 });
55765576 }
......@@ -5585,14 +5585,14 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
55855585 .tag = .movw,
55865586 .data = .{ .r_imm16 = .{
55875587 .rd = reg,
5588 .imm16 = @truncate(u16, x),
5588 .imm16 = @as(u16, @truncate(x)),
55895589 } },
55905590 });
55915591 _ = try self.addInst(.{
55925592 .tag = .movt,
55935593 .data = .{ .r_imm16 = .{
55945594 .rd = reg,
5595 .imm16 = @truncate(u16, x >> 16),
5595 .imm16 = @as(u16, @truncate(x >> 16)),
55965596 } },
55975597 });
55985598 } else {
......@@ -5605,7 +5605,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56055605 .tag = .mov,
56065606 .data = .{ .r_op_mov = .{
56075607 .rd = reg,
5608 .op = Instruction.Operand.imm(@truncate(u8, x), 0),
5608 .op = Instruction.Operand.imm(@as(u8, @truncate(x)), 0),
56095609 } },
56105610 });
56115611 _ = try self.addInst(.{
......@@ -5613,7 +5613,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56135613 .data = .{ .rr_op = .{
56145614 .rd = reg,
56155615 .rn = reg,
5616 .op = Instruction.Operand.imm(@truncate(u8, x >> 8), 12),
5616 .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 8)), 12),
56175617 } },
56185618 });
56195619 _ = try self.addInst(.{
......@@ -5621,7 +5621,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56215621 .data = .{ .rr_op = .{
56225622 .rd = reg,
56235623 .rn = reg,
5624 .op = Instruction.Operand.imm(@truncate(u8, x >> 16), 8),
5624 .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 16)), 8),
56255625 } },
56265626 });
56275627 _ = try self.addInst(.{
......@@ -5629,7 +5629,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56295629 .data = .{ .rr_op = .{
56305630 .rd = reg,
56315631 .rn = reg,
5632 .op = Instruction.Operand.imm(@truncate(u8, x >> 24), 4),
5632 .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 24)), 4),
56335633 } },
56345634 });
56355635 }
......@@ -5654,12 +5654,12 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56545654 .memory => |addr| {
56555655 // The value is in memory at a hard-coded address.
56565656 // 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)) });
56585658 try self.genLdrRegister(reg, reg, ty);
56595659 },
56605660 .stack_offset => |off| {
56615661 // 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
56645664 const tag: Mir.Inst.Tag = switch (abi_size) {
56655665 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
56775677
56785678 if (extra_offset) {
56795679 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)));
56815681 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.usize, MCValue{ .immediate = off }));
56825682
56835683 _ = try self.addInst(.{
......@@ -5693,7 +5693,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56935693 });
56945694 } else {
56955695 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)));
56975697 } else Instruction.Offset.reg(try self.copyToTmpRegister(Type.usize, MCValue{ .immediate = off }), .none);
56985698
56995699 _ = try self.addInst(.{
......@@ -5732,7 +5732,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
57325732
57335733fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
57345734 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)));
57365736 switch (mcv) {
57375737 .dead => unreachable,
57385738 .none, .unreach => return,
......@@ -5771,7 +5771,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
57715771 },
57725772 2 => {
57735773 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)));
57755775 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset }));
57765776
57775777 _ = try self.addInst(.{
......@@ -5814,7 +5814,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
58145814 // sub src_reg, fp, #off
58155815 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });
58165816 },
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)) }),
58185818 .stack_argument_offset => |off| {
58195819 _ = try self.addInst(.{
58205820 .tag = .ldr_ptr_stack_argument,
......@@ -5893,7 +5893,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
58935893 const ptr_ty = self.typeOf(ty_op.operand);
58945894 const ptr = try self.resolveInst(ty_op.operand);
58955895 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
58985898 const stack_offset = try self.allocMem(8, 8, inst);
58995899 try self.genSetStack(ptr_ty, stack_offset, ptr);
......@@ -6010,7 +6010,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
60106010 const vector_ty = self.typeOfIndex(inst);
60116011 const len = vector_ty.vectorLen(mod);
60126012 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]));
60146014 const result: MCValue = res: {
60156015 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
60166016 return self.fail("TODO implement airAggregateInit for arm", .{});
......@@ -6058,7 +6058,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
60586058 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };
60596059 const error_union_ty = self.typeOf(pl_op.operand);
60606060 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)));
60626062 const error_union_align = error_union_ty.abiAlignment(mod);
60636063
60646064 // 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 {
61416141 .none => .none,
61426142 .undef => .undef,
61436143 .load_got, .load_direct, .load_tlv => unreachable, // TODO
6144 .immediate => |imm| .{ .immediate = @truncate(u32, imm) },
6144 .immediate => |imm| .{ .immediate = @as(u32, @truncate(imm)) },
61456145 .memory => |addr| .{ .memory = addr },
61466146 },
61476147 .fail => |msg| {
......@@ -6198,7 +6198,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
61986198 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
61996199 result.return_value = .{ .none = {} };
62006200 } else {
6201 const ret_ty_size = @intCast(u32, ret_ty.abiSize(mod));
6201 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
62026202 // TODO handle cases where multiple registers are used
62036203 if (ret_ty_size <= 4) {
62046204 result.return_value = .{ .register = c_abi_int_return_regs[0] };
......@@ -6216,7 +6216,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62166216 if (ty.toType().abiAlignment(mod) == 8)
62176217 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)));
62206220 if (std.math.divCeil(u32, param_size, 4) catch unreachable <= 4 - ncrn) {
62216221 if (param_size <= 4) {
62226222 result.args[i] = .{ .register = c_abi_int_param_regs[ncrn] };
......@@ -6245,7 +6245,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62456245 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod) and !ret_ty.isError(mod)) {
62466246 result.return_value = .{ .none = {} };
62476247 } else {
6248 const ret_ty_size = @intCast(u32, ret_ty.abiSize(mod));
6248 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
62496249 if (ret_ty_size == 0) {
62506250 assert(ret_ty.isError(mod));
62516251 result.return_value = .{ .immediate = 0 };
......@@ -6264,7 +6264,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62646264
62656265 for (fn_info.param_types, 0..) |ty, i| {
62666266 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)));
62686268 const param_alignment = ty.toType().abiAlignment(mod);
62696269
62706270 stack_offset = std.mem.alignForward(u32, stack_offset, param_alignment);
src/arch/arm/Emit.zig+19-19
......@@ -78,7 +78,7 @@ pub fn emitMir(
7878
7979 // Emit machine code
8080 for (mir_tags, 0..) |tag, index| {
81 const inst = @intCast(u32, index);
81 const inst = @as(u32, @intCast(index));
8282 switch (tag) {
8383 .add => try emit.mirDataProcessing(inst),
8484 .adds => try emit.mirDataProcessing(inst),
......@@ -241,7 +241,7 @@ fn lowerBranches(emit: *Emit) !void {
241241 // TODO optimization opportunity: do this in codegen while
242242 // generating MIR
243243 for (mir_tags, 0..) |tag, index| {
244 const inst = @intCast(u32, index);
244 const inst = @as(u32, @intCast(index));
245245 if (isBranch(tag)) {
246246 const target_inst = emit.branchTarget(inst);
247247
......@@ -286,7 +286,7 @@ fn lowerBranches(emit: *Emit) !void {
286286 var current_code_offset: usize = 0;
287287
288288 for (mir_tags, 0..) |tag, index| {
289 const inst = @intCast(u32, index);
289 const inst = @as(u32, @intCast(index));
290290
291291 // If this instruction contained in the code offset
292292 // mapping (when it is a target of a branch or if it is a
......@@ -301,7 +301,7 @@ fn lowerBranches(emit: *Emit) !void {
301301 const target_inst = emit.branchTarget(inst);
302302 if (target_inst < inst) {
303303 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));
305305 const branch_type = emit.branch_types.getPtr(inst).?;
306306 const optimal_branch_type = try emit.optimalBranchType(tag, offset);
307307 if (branch_type.* != optimal_branch_type) {
......@@ -320,7 +320,7 @@ fn lowerBranches(emit: *Emit) !void {
320320 for (origin_list.items) |forward_branch_inst| {
321321 const branch_tag = emit.mir.instructions.items(.tag)[forward_branch_inst];
322322 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));
324324 const branch_type = emit.branch_types.getPtr(forward_branch_inst).?;
325325 const optimal_branch_type = try emit.optimalBranchType(branch_tag, offset);
326326 if (branch_type.* != optimal_branch_type) {
......@@ -351,7 +351,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
351351}
352352
353353fn 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));
355355 const delta_pc: usize = self.code.items.len - self.prev_di_pc;
356356 switch (self.debug_output) {
357357 .dwarf => |dw| {
......@@ -368,13 +368,13 @@ fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {
368368 // increasing the line number
369369 try @import("../../link/Plan9.zig").changeLine(dbg_out.dbg_line, delta_line);
370370 // increasing the pc
371 const d_pc_p9 = @intCast(i64, delta_pc) - quant;
371 const d_pc_p9 = @as(i64, @intCast(delta_pc)) - quant;
372372 if (d_pc_p9 > 0) {
373373 // 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);
375375 if (dbg_out.pcop_change_index.*) |pci|
376376 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));
378378 } else if (d_pc_p9 == 0) {
379379 // we don't need to do anything, because adding the quant does it for us
380380 } else unreachable;
......@@ -448,13 +448,13 @@ fn mirSubStackPointer(emit: *Emit, inst: Mir.Inst.Index) !void {
448448 const scratch: Register = .r4;
449449
450450 if (Target.arm.featureSetHas(emit.target.cpu.features, .has_v7)) {
451 try emit.writeInstruction(Instruction.movw(cond, scratch, @truncate(u16, imm32)));
452 try emit.writeInstruction(Instruction.movt(cond, scratch, @truncate(u16, imm32 >> 16)));
451 try emit.writeInstruction(Instruction.movw(cond, scratch, @as(u16, @truncate(imm32))));
452 try emit.writeInstruction(Instruction.movt(cond, scratch, @as(u16, @truncate(imm32 >> 16))));
453453 } else {
454 try emit.writeInstruction(Instruction.mov(cond, scratch, Instruction.Operand.imm(@truncate(u8, imm32), 0)));
455 try emit.writeInstruction(Instruction.orr(cond, scratch, scratch, Instruction.Operand.imm(@truncate(u8, imm32 >> 8), 12)));
456 try emit.writeInstruction(Instruction.orr(cond, scratch, scratch, Instruction.Operand.imm(@truncate(u8, imm32 >> 16), 8)));
457 try emit.writeInstruction(Instruction.orr(cond, scratch, scratch, Instruction.Operand.imm(@truncate(u8, imm32 >> 24), 4)));
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(@as(u8, @truncate(imm32 >> 8)), 12)));
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(@as(u8, @truncate(imm32 >> 24)), 4)));
458458 }
459459
460460 break :blk Instruction.Operand.reg(scratch, Instruction.Operand.Shift.none);
......@@ -484,12 +484,12 @@ fn mirBranch(emit: *Emit, inst: Mir.Inst.Index) !void {
484484 const cond = emit.mir.instructions.items(.cond)[inst];
485485 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));
488488 const branch_type = emit.branch_types.get(inst).?;
489489
490490 switch (branch_type) {
491491 .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)))),
493493 else => unreachable,
494494 },
495495 }
......@@ -585,7 +585,7 @@ fn mirLoadStackArgument(emit: *Emit, inst: Mir.Inst.Index) !void {
585585 .ldrb_stack_argument,
586586 => {
587587 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)));
589589 } else return emit.fail("TODO mirLoadStack larger offsets", .{});
590590
591591 switch (tag) {
......@@ -599,7 +599,7 @@ fn mirLoadStackArgument(emit: *Emit, inst: Mir.Inst.Index) !void {
599599 .ldrsh_stack_argument,
600600 => {
601601 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)));
603603 } else return emit.fail("TODO mirLoadStack larger offsets", .{});
604604
605605 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
287287 inline for (fields) |field| {
288288 @field(result, field.name) = switch (field.type) {
289289 u32 => mir.extra[i],
290 i32 => @bitCast(i32, mir.extra[i]),
290 i32 => @as(i32, @bitCast(mir.extra[i])),
291291 else => @compileError("bad field type"),
292292 };
293293 i += 1;
src/arch/arm/abi.zig+1-1
......@@ -13,7 +13,7 @@ pub const Class = union(enum) {
1313 i64_array: u8,
1414
1515 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));
1717 if (arr_size == 32) {
1818 return .{ .i32_array = count };
1919 } else {
src/arch/arm/bits.zig+32-32
......@@ -159,7 +159,7 @@ pub const Register = enum(u5) {
159159 /// Returns the unique 4-bit ID of this register which is used in
160160 /// the machine code
161161 pub fn id(self: Register) u4 {
162 return @truncate(u4, @intFromEnum(self));
162 return @as(u4, @truncate(@intFromEnum(self)));
163163 }
164164
165165 pub fn dwarfLocOp(self: Register) u8 {
......@@ -399,8 +399,8 @@ pub const Instruction = union(enum) {
399399
400400 pub fn toU8(self: Shift) u8 {
401401 return switch (self) {
402 .register => |v| @bitCast(u8, v),
403 .immediate => |v| @bitCast(u8, v),
402 .register => |v| @as(u8, @bitCast(v)),
403 .immediate => |v| @as(u8, @bitCast(v)),
404404 };
405405 }
406406
......@@ -425,8 +425,8 @@ pub const Instruction = union(enum) {
425425
426426 pub fn toU12(self: Operand) u12 {
427427 return switch (self) {
428 .register => |v| @bitCast(u12, v),
429 .immediate => |v| @bitCast(u12, v),
428 .register => |v| @as(u12, @bitCast(v)),
429 .immediate => |v| @as(u12, @bitCast(v)),
430430 };
431431 }
432432
......@@ -463,8 +463,8 @@ pub const Instruction = union(enum) {
463463 if (x & mask == x) {
464464 break Operand{
465465 .immediate = .{
466 .imm = @intCast(u8, std.math.rotl(u32, x, 2 * i)),
467 .rotate = @intCast(u4, i),
466 .imm = @as(u8, @intCast(std.math.rotl(u32, x, 2 * i))),
467 .rotate = @as(u4, @intCast(i)),
468468 },
469469 };
470470 }
......@@ -522,7 +522,7 @@ pub const Instruction = union(enum) {
522522
523523 pub fn toU12(self: Offset) u12 {
524524 return switch (self) {
525 .register => |v| @bitCast(u12, v),
525 .register => |v| @as(u12, @bitCast(v)),
526526 .immediate => |v| v,
527527 };
528528 }
......@@ -604,20 +604,20 @@ pub const Instruction = union(enum) {
604604
605605 pub fn toU32(self: Instruction) u32 {
606606 return switch (self) {
607 .data_processing => |v| @bitCast(u32, v),
608 .multiply => |v| @bitCast(u32, v),
609 .multiply_long => |v| @bitCast(u32, v),
610 .signed_multiply_halfwords => |v| @bitCast(u32, v),
611 .integer_saturating_arithmetic => |v| @bitCast(u32, v),
612 .bit_field_extract => |v| @bitCast(u32, v),
613 .single_data_transfer => |v| @bitCast(u32, v),
614 .extra_load_store => |v| @bitCast(u32, v),
615 .block_data_transfer => |v| @bitCast(u32, v),
616 .branch => |v| @bitCast(u32, v),
617 .branch_exchange => |v| @bitCast(u32, v),
618 .supervisor_call => |v| @bitCast(u32, v),
607 .data_processing => |v| @as(u32, @bitCast(v)),
608 .multiply => |v| @as(u32, @bitCast(v)),
609 .multiply_long => |v| @as(u32, @bitCast(v)),
610 .signed_multiply_halfwords => |v| @as(u32, @bitCast(v)),
611 .integer_saturating_arithmetic => |v| @as(u32, @bitCast(v)),
612 .bit_field_extract => |v| @as(u32, @bitCast(v)),
613 .single_data_transfer => |v| @as(u32, @bitCast(v)),
614 .extra_load_store => |v| @as(u32, @bitCast(v)),
615 .block_data_transfer => |v| @as(u32, @bitCast(v)),
616 .branch => |v| @as(u32, @bitCast(v)),
617 .branch_exchange => |v| @as(u32, @bitCast(v)),
618 .supervisor_call => |v| @as(u32, @bitCast(v)),
619619 .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),
621621 };
622622 }
623623
......@@ -656,9 +656,9 @@ pub const Instruction = union(enum) {
656656 .i = 1,
657657 .opcode = if (top) 0b1010 else 0b1000,
658658 .s = 0,
659 .rn = @truncate(u4, imm >> 12),
659 .rn = @as(u4, @truncate(imm >> 12)),
660660 .rd = rd.id(),
661 .op2 = @truncate(u12, imm),
661 .op2 = @as(u12, @truncate(imm)),
662662 },
663663 };
664664 }
......@@ -760,7 +760,7 @@ pub const Instruction = union(enum) {
760760 .rn = rn.id(),
761761 .lsb = lsb,
762762 .rd = rd.id(),
763 .widthm1 = @intCast(u5, width - 1),
763 .widthm1 = @as(u5, @intCast(width - 1)),
764764 .unsigned = unsigned,
765765 .cond = @intFromEnum(cond),
766766 },
......@@ -810,11 +810,11 @@ pub const Instruction = union(enum) {
810810 offset: ExtraLoadStoreOffset,
811811 ) Instruction {
812812 const imm4l: u4 = switch (offset) {
813 .immediate => |imm| @truncate(u4, imm),
813 .immediate => |imm| @as(u4, @truncate(imm)),
814814 .register => |reg| reg,
815815 };
816816 const imm4h: u4 = switch (offset) {
817 .immediate => |imm| @truncate(u4, imm >> 4),
817 .immediate => |imm| @as(u4, @truncate(imm >> 4)),
818818 .register => 0b0000,
819819 };
820820
......@@ -853,7 +853,7 @@ pub const Instruction = union(enum) {
853853 ) Instruction {
854854 return Instruction{
855855 .block_data_transfer = .{
856 .register_list = @bitCast(u16, reg_list),
856 .register_list = @as(u16, @bitCast(reg_list)),
857857 .rn = rn.id(),
858858 .load_store = load_store,
859859 .write_back = @intFromBool(write_back),
......@@ -870,7 +870,7 @@ pub const Instruction = union(enum) {
870870 .branch = .{
871871 .cond = @intFromEnum(cond),
872872 .link = link,
873 .offset = @bitCast(u24, @intCast(i24, offset >> 2)),
873 .offset = @as(u24, @bitCast(@as(i24, @intCast(offset >> 2)))),
874874 },
875875 };
876876 }
......@@ -904,8 +904,8 @@ pub const Instruction = union(enum) {
904904 fn breakpoint(imm: u16) Instruction {
905905 return Instruction{
906906 .breakpoint = .{
907 .imm12 = @truncate(u12, imm >> 4),
908 .imm4 = @truncate(u4, imm),
907 .imm12 = @as(u12, @truncate(imm >> 4)),
908 .imm4 = @as(u4, @truncate(imm)),
909909 },
910910 };
911911 }
......@@ -1319,7 +1319,7 @@ pub const Instruction = union(enum) {
13191319 const reg = @as(Register, arg);
13201320 register_list |= @as(u16, 1) << reg.id();
13211321 }
1322 return ldm(cond, .sp, true, @bitCast(RegisterList, register_list));
1322 return ldm(cond, .sp, true, @as(RegisterList, @bitCast(register_list)));
13231323 }
13241324 }
13251325
......@@ -1343,7 +1343,7 @@ pub const Instruction = union(enum) {
13431343 const reg = @as(Register, arg);
13441344 register_list |= @as(u16, 1) << reg.id();
13451345 }
1346 return stmdb(cond, .sp, true, @bitCast(RegisterList, register_list));
1346 return stmdb(cond, .sp, true, @as(RegisterList, @bitCast(register_list)));
13471347 }
13481348 }
13491349
src/arch/riscv64/CodeGen.zig+19-19
......@@ -323,7 +323,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
323323
324324 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));
327327 self.mir_instructions.appendAssumeCapacity(inst);
328328 return result_index;
329329}
......@@ -336,11 +336,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {
336336
337337pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
338338 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));
340340 inline for (fields) |field| {
341341 self.mir_extra.appendAssumeCapacity(switch (field.type) {
342342 u32 => @field(extra, field.name),
343 i32 => @bitCast(u32, @field(extra, field.name)),
343 i32 => @as(u32, @bitCast(@field(extra, field.name))),
344344 else => @compileError("bad field type"),
345345 });
346346 }
......@@ -752,15 +752,15 @@ fn finishAirBookkeeping(self: *Self) void {
752752fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void {
753753 var tomb_bits = self.liveness.getTombBits(inst);
754754 for (operands) |op| {
755 const dies = @truncate(u1, tomb_bits) != 0;
755 const dies = @as(u1, @truncate(tomb_bits)) != 0;
756756 tomb_bits >>= 1;
757757 if (!dies) continue;
758758 const op_int = @intFromEnum(op);
759759 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));
761761 self.processDeath(op_index);
762762 }
763 const is_used = @truncate(u1, tomb_bits) == 0;
763 const is_used = @as(u1, @truncate(tomb_bits)) == 0;
764764 if (is_used) {
765765 log.debug("%{d} => {}", .{ inst, result });
766766 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
17091709 const fn_ty = self.typeOf(pl_op.operand);
17101710 const callee = pl_op.operand;
17111711 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
17141714 var info = try self.resolveCallingConventionValues(fn_ty);
17151715 defer info.deinit(self);
......@@ -1747,7 +1747,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
17471747 const atom_index = try elf_file.getOrCreateAtomForDecl(func.owner_decl);
17481748 const atom = elf_file.getAtom(atom_index);
17491749 _ = 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)));
17511751 try self.genSetReg(Type.usize, .ra, .{ .memory = got_addr });
17521752 _ = try self.addInst(.{
17531753 .tag = .jalr,
......@@ -2139,12 +2139,12 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {
21392139fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
21402140 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
21412141 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
2142 const is_volatile = @truncate(u1, extra.data.flags >> 31) != 0;
2143 const clobbers_len = @truncate(u31, extra.data.flags);
2142 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
2143 const clobbers_len = @as(u31, @truncate(extra.data.flags));
21442144 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]));
21462146 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]));
21482148 extra_i += inputs.len;
21492149
21502150 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
22892289 return self.genSetReg(ty, reg, .{ .immediate = 0xaaaaaaaaaaaaaaaa });
22902290 },
22912291 .immediate => |unsigned_x| {
2292 const x = @bitCast(i64, unsigned_x);
2292 const x = @as(i64, @bitCast(unsigned_x));
22932293 if (math.minInt(i12) <= x and x <= math.maxInt(i12)) {
22942294 _ = try self.addInst(.{
22952295 .tag = .addi,
22962296 .data = .{ .i_type = .{
22972297 .rd = reg,
22982298 .rs1 = .zero,
2299 .imm12 = @intCast(i12, x),
2299 .imm12 = @as(i12, @intCast(x)),
23002300 } },
23012301 });
23022302 } else if (math.minInt(i32) <= x and x <= math.maxInt(i32)) {
2303 const lo12 = @truncate(i12, x);
2303 const lo12 = @as(i12, @truncate(x));
23042304 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
23072307 // TODO: add test case for 32-bit immediate
23082308 _ = try self.addInst(.{
......@@ -2501,7 +2501,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
25012501 const vector_ty = self.typeOfIndex(inst);
25022502 const len = vector_ty.vectorLen(mod);
25032503 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]));
25052505 const result: MCValue = res: {
25062506 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
25072507 return self.fail("TODO implement airAggregateInit for riscv64", .{});
......@@ -2653,7 +2653,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
26532653 const argument_registers = [_]Register{ .a0, .a1, .a2, .a3, .a4, .a5, .a6, .a7 };
26542654
26552655 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)));
26572657 if (param_size <= 8) {
26582658 if (next_register < argument_registers.len) {
26592659 result.args[i] = .{ .register = argument_registers[next_register] };
......@@ -2690,7 +2690,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
26902690 } else switch (cc) {
26912691 .Naked => unreachable,
26922692 .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)));
26942694 if (ret_ty_size <= 8) {
26952695 result.return_value = .{ .register = .a0 };
26962696 } else if (ret_ty_size <= 16) {
src/arch/riscv64/Emit.zig+5-5
......@@ -39,7 +39,7 @@ pub fn emitMir(
3939
4040 // Emit machine code
4141 for (mir_tags, 0..) |tag, index| {
42 const inst = @intCast(u32, index);
42 const inst = @as(u32, @intCast(index));
4343 switch (tag) {
4444 .add => try emit.mirRType(inst),
4545 .sub => try emit.mirRType(inst),
......@@ -85,7 +85,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
8585}
8686
8787fn 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));
8989 const delta_pc: usize = self.code.items.len - self.prev_di_pc;
9090 switch (self.debug_output) {
9191 .dwarf => |dw| {
......@@ -102,13 +102,13 @@ fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {
102102 // increasing the line number
103103 try @import("../../link/Plan9.zig").changeLine(dbg_out.dbg_line, delta_line);
104104 // increasing the pc
105 const d_pc_p9 = @intCast(i64, delta_pc) - quant;
105 const d_pc_p9 = @as(i64, @intCast(delta_pc)) - quant;
106106 if (d_pc_p9 > 0) {
107107 // 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);
109109 if (dbg_out.pcop_change_index.*) |pci|
110110 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));
112112 } else if (d_pc_p9 == 0) {
113113 // we don't need to do anything, because adding the quant does it for us
114114 } 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
135135 inline for (fields) |field| {
136136 @field(result, field.name) = switch (field.type) {
137137 u32 => mir.extra[i],
138 i32 => @bitCast(i32, mir.extra[i]),
138 i32 => @as(i32, @bitCast(mir.extra[i])),
139139 else => @compileError("bad field type"),
140140 };
141141 i += 1;
src/arch/riscv64/bits.zig+23-23
......@@ -56,12 +56,12 @@ pub const Instruction = union(enum) {
5656 // TODO: once packed structs work we can remove this monstrosity.
5757 pub fn toU32(self: Instruction) u32 {
5858 return switch (self) {
59 .R => |v| @bitCast(u32, v),
60 .I => |v| @bitCast(u32, v),
61 .S => |v| @bitCast(u32, 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),
63 .U => |v| @bitCast(u32, v),
64 .J => |v| @bitCast(u32, v),
59 .R => |v| @as(u32, @bitCast(v)),
60 .I => |v| @as(u32, @bitCast(v)),
61 .S => |v| @as(u32, @bitCast(v)),
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| @as(u32, @bitCast(v)),
64 .J => |v| @as(u32, @bitCast(v)),
6565 };
6666 }
6767
......@@ -80,7 +80,7 @@ pub const Instruction = union(enum) {
8080
8181 // RISC-V is all signed all the time -- convert immediates to unsigned for processing
8282 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
8585 return Instruction{
8686 .I = .{
......@@ -94,7 +94,7 @@ pub const Instruction = union(enum) {
9494 }
9595
9696 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
9999 return Instruction{
100100 .S = .{
......@@ -102,8 +102,8 @@ pub const Instruction = union(enum) {
102102 .funct3 = fn3,
103103 .rs1 = r1.id(),
104104 .rs2 = r2.id(),
105 .imm0_4 = @truncate(u5, umm),
106 .imm5_11 = @truncate(u7, umm >> 5),
105 .imm0_4 = @as(u5, @truncate(umm)),
106 .imm5_11 = @as(u7, @truncate(umm >> 5)),
107107 },
108108 };
109109 }
......@@ -111,7 +111,7 @@ pub const Instruction = union(enum) {
111111 // Use significance value rather than bit value, same for J-type
112112 // -- less burden on callsite, bonus semantic checking
113113 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));
115115 assert(umm % 2 == 0); // misaligned branch target
116116
117117 return Instruction{
......@@ -120,17 +120,17 @@ pub const Instruction = union(enum) {
120120 .funct3 = fn3,
121121 .rs1 = r1.id(),
122122 .rs2 = r2.id(),
123 .imm1_4 = @truncate(u4, umm >> 1),
124 .imm5_10 = @truncate(u6, umm >> 5),
125 .imm11 = @truncate(u1, umm >> 11),
126 .imm12 = @truncate(u1, umm >> 12),
123 .imm1_4 = @as(u4, @truncate(umm >> 1)),
124 .imm5_10 = @as(u6, @truncate(umm >> 5)),
125 .imm11 = @as(u1, @truncate(umm >> 11)),
126 .imm12 = @as(u1, @truncate(umm >> 12)),
127127 },
128128 };
129129 }
130130
131131 // We have to extract the 20 bits anyway -- let's not make it more painful
132132 fn uType(op: u7, rd: Register, imm: i20) Instruction {
133 const umm = @bitCast(u20, imm);
133 const umm = @as(u20, @bitCast(imm));
134134
135135 return Instruction{
136136 .U = .{
......@@ -142,17 +142,17 @@ pub const Instruction = union(enum) {
142142 }
143143
144144 fn jType(op: u7, rd: Register, imm: i21) Instruction {
145 const umm = @bitCast(u21, imm);
145 const umm = @as(u21, @bitCast(imm));
146146 assert(umm % 2 == 0); // misaligned jump target
147147
148148 return Instruction{
149149 .J = .{
150150 .opcode = op,
151151 .rd = rd.id(),
152 .imm1_10 = @truncate(u10, umm >> 1),
153 .imm11 = @truncate(u1, umm >> 11),
154 .imm12_19 = @truncate(u8, umm >> 12),
155 .imm20 = @truncate(u1, umm >> 20),
152 .imm1_10 = @as(u10, @truncate(umm >> 1)),
153 .imm11 = @as(u1, @truncate(umm >> 11)),
154 .imm12_19 = @as(u8, @truncate(umm >> 12)),
155 .imm20 = @as(u1, @truncate(umm >> 20)),
156156 },
157157 };
158158 }
......@@ -258,7 +258,7 @@ pub const Instruction = union(enum) {
258258 }
259259
260260 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)));
262262 }
263263
264264 // Arithmetic/Logical, Register-Immediate (32-bit)
......@@ -407,7 +407,7 @@ pub const Register = enum(u6) {
407407 /// Returns the unique 4-bit ID of this register which is used in
408408 /// the machine code
409409 pub fn id(self: Register) u5 {
410 return @truncate(u5, @intFromEnum(self));
410 return @as(u5, @truncate(@intFromEnum(self)));
411411 }
412412
413413 pub fn dwarfLocOp(reg: Register) u8 {
src/arch/sparc64/CodeGen.zig+43-43
......@@ -415,7 +415,7 @@ fn gen(self: *Self) !void {
415415 .branch_predict_int = .{
416416 .ccr = .xcc,
417417 .cond = .al,
418 .inst = @intCast(u32, self.mir_instructions.len),
418 .inst = @as(u32, @intCast(self.mir_instructions.len)),
419419 },
420420 },
421421 });
......@@ -840,7 +840,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
840840 const vector_ty = self.typeOfIndex(inst);
841841 const len = vector_ty.vectorLen(mod);
842842 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]));
844844 const result: MCValue = res: {
845845 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
846846 return self.fail("TODO implement airAggregateInit for {}", .{self.target.cpu.arch});
......@@ -876,7 +876,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
876876 const ptr_ty = self.typeOf(ty_op.operand);
877877 const ptr = try self.resolveInst(ty_op.operand);
878878 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
881881 const ptr_bits = self.target.ptrBitWidth();
882882 const ptr_bytes = @divExact(ptr_bits, 8);
......@@ -893,11 +893,11 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
893893 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
894894 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
895895 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));
897897 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]));
899899 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]));
901901 extra_i += inputs.len;
902902
903903 const dead = !is_volatile and self.liveness.isUnused(inst);
......@@ -1237,13 +1237,13 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
12371237 switch (operand) {
12381238 .immediate => |imm| {
12391239 const swapped = switch (int_info.bits) {
1240 16 => @byteSwap(@intCast(u16, imm)),
1241 24 => @byteSwap(@intCast(u24, imm)),
1242 32 => @byteSwap(@intCast(u32, imm)),
1243 40 => @byteSwap(@intCast(u40, imm)),
1244 48 => @byteSwap(@intCast(u48, imm)),
1245 56 => @byteSwap(@intCast(u56, imm)),
1246 64 => @byteSwap(@intCast(u64, imm)),
1240 16 => @byteSwap(@as(u16, @intCast(imm))),
1241 24 => @byteSwap(@as(u24, @intCast(imm))),
1242 32 => @byteSwap(@as(u32, @intCast(imm))),
1243 40 => @byteSwap(@as(u40, @intCast(imm))),
1244 48 => @byteSwap(@as(u48, @intCast(imm))),
1245 56 => @byteSwap(@as(u56, @intCast(imm))),
1246 64 => @byteSwap(@as(u64, @intCast(imm))),
12471247 else => return self.fail("TODO synthesize SPARCv9 byteswap for other integer sizes", .{}),
12481248 };
12491249 break :result .{ .immediate = swapped };
......@@ -1295,7 +1295,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
12951295 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
12961296 const callee = pl_op.operand;
12971297 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]));
12991299 const ty = self.typeOf(callee);
13001300 const mod = self.bin_file.options.module.?;
13011301 const fn_ty = switch (ty.zigTypeTag(mod)) {
......@@ -1348,7 +1348,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
13481348 const atom_index = try elf_file.getOrCreateAtomForDecl(func.owner_decl);
13491349 const atom = elf_file.getAtom(atom_index);
13501350 _ = try atom.getOrCreateOffsetTableEntry(elf_file);
1351 break :blk @intCast(u32, atom.getOffsetTableAddress(elf_file));
1351 break :blk @as(u32, @intCast(atom.getOffsetTableAddress(elf_file)));
13521352 } else unreachable;
13531353
13541354 try self.genSetReg(Type.usize, .o7, .{ .memory = got_addr });
......@@ -1515,7 +1515,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
15151515 if (self.liveness.operandDies(inst, 0)) {
15161516 const op_int = @intFromEnum(pl_op.operand);
15171517 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));
15191519 self.processDeath(op_index);
15201520 }
15211521 }
......@@ -1851,7 +1851,7 @@ fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
18511851 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
18521852 const loop = self.air.extraData(Air.Block, ty_pl.payload);
18531853 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
18561856 try self.genBody(body);
18571857 try self.jump(start);
......@@ -2574,7 +2574,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
25742574 const mod = self.bin_file.options.module.?;
25752575 const mcv = try self.resolveInst(operand);
25762576 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
25792579 switch (mcv) {
25802580 .dead, .unreach => unreachable,
......@@ -2772,7 +2772,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
27722772fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
27732773 const gpa = self.gpa;
27742774 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));
27762776 self.mir_instructions.appendAssumeCapacity(inst);
27772777 return result_index;
27782778}
......@@ -3207,7 +3207,7 @@ fn binOpImmediate(
32073207 .is_imm = true,
32083208 .rd = dest_reg,
32093209 .rs1 = lhs_reg,
3210 .rs2_or_imm = .{ .imm = @intCast(u12, rhs.immediate) },
3210 .rs2_or_imm = .{ .imm = @as(u12, @intCast(rhs.immediate)) },
32113211 },
32123212 },
32133213 .sll,
......@@ -3218,7 +3218,7 @@ fn binOpImmediate(
32183218 .is_imm = true,
32193219 .rd = dest_reg,
32203220 .rs1 = lhs_reg,
3221 .rs2_or_imm = .{ .imm = @intCast(u5, rhs.immediate) },
3221 .rs2_or_imm = .{ .imm = @as(u5, @intCast(rhs.immediate)) },
32223222 },
32233223 },
32243224 .sllx,
......@@ -3229,14 +3229,14 @@ fn binOpImmediate(
32293229 .is_imm = true,
32303230 .rd = dest_reg,
32313231 .rs1 = lhs_reg,
3232 .rs2_or_imm = .{ .imm = @intCast(u6, rhs.immediate) },
3232 .rs2_or_imm = .{ .imm = @as(u6, @intCast(rhs.immediate)) },
32333233 },
32343234 },
32353235 .cmp => .{
32363236 .arithmetic_2op = .{
32373237 .is_imm = true,
32383238 .rs1 = lhs_reg,
3239 .rs2_or_imm = .{ .imm = @intCast(u12, rhs.immediate) },
3239 .rs2_or_imm = .{ .imm = @as(u12, @intCast(rhs.immediate)) },
32403240 },
32413241 },
32423242 else => unreachable,
......@@ -3535,7 +3535,7 @@ fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type)
35353535 return MCValue.none;
35363536 }
35373537
3538 const payload_offset = @intCast(u32, errUnionPayloadOffset(payload_ty, mod));
3538 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, mod)));
35393539 switch (error_union_mcv) {
35403540 .register => return self.fail("TODO errUnionPayload for registers", .{}),
35413541 .stack_offset => |off| {
......@@ -3565,15 +3565,15 @@ fn finishAirBookkeeping(self: *Self) void {
35653565fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void {
35663566 var tomb_bits = self.liveness.getTombBits(inst);
35673567 for (operands) |op| {
3568 const dies = @truncate(u1, tomb_bits) != 0;
3568 const dies = @as(u1, @truncate(tomb_bits)) != 0;
35693569 tomb_bits >>= 1;
35703570 if (!dies) continue;
35713571 const op_int = @intFromEnum(op);
35723572 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));
35743574 self.processDeath(op_index);
35753575 }
3576 const is_used = @truncate(u1, tomb_bits) == 0;
3576 const is_used = @as(u1, @truncate(tomb_bits)) == 0;
35773577 if (is_used) {
35783578 log.debug("%{d} => {}", .{ inst, result });
35793579 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
......@@ -3663,7 +3663,7 @@ fn genInlineMemcpy(
36633663 .data = .{ .branch_predict_reg = .{
36643664 .cond = .ne_zero,
36653665 .rs1 = len,
3666 .inst = @intCast(u32, self.mir_instructions.len - 2),
3666 .inst = @as(u32, @intCast(self.mir_instructions.len - 2)),
36673667 } },
36683668 });
36693669
......@@ -3838,7 +3838,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
38383838 .arithmetic_2op = .{
38393839 .is_imm = true,
38403840 .rs1 = reg,
3841 .rs2_or_imm = .{ .imm = @truncate(u12, x) },
3841 .rs2_or_imm = .{ .imm = @as(u12, @truncate(x)) },
38423842 },
38433843 },
38443844 });
......@@ -3848,7 +3848,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
38483848 .data = .{
38493849 .sethi = .{
38503850 .rd = reg,
3851 .imm = @truncate(u22, x >> 10),
3851 .imm = @as(u22, @truncate(x >> 10)),
38523852 },
38533853 },
38543854 });
......@@ -3860,12 +3860,12 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
38603860 .is_imm = true,
38613861 .rd = reg,
38623862 .rs1 = reg,
3863 .rs2_or_imm = .{ .imm = @truncate(u10, x) },
3863 .rs2_or_imm = .{ .imm = @as(u10, @truncate(x)) },
38643864 },
38653865 },
38663866 });
38673867 } 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
38703870 _ = try self.addInst(.{
38713871 .tag = .sllx,
......@@ -3886,7 +3886,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
38863886 .is_imm = true,
38873887 .rd = reg,
38883888 .rs1 = reg,
3889 .rs2_or_imm = .{ .imm = @truncate(u12, x) },
3889 .rs2_or_imm = .{ .imm = @as(u12, @truncate(x)) },
38903890 },
38913891 },
38923892 });
......@@ -3894,8 +3894,8 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
38943894 // Need to allocate a temporary register to load 64-bit immediates.
38953895 const tmp_reg = try self.register_manager.allocReg(null, gp);
38963896
3897 try self.genSetReg(ty, tmp_reg, .{ .immediate = @truncate(u32, x) });
3898 try self.genSetReg(ty, reg, .{ .immediate = @truncate(u32, x >> 32) });
3897 try self.genSetReg(ty, tmp_reg, .{ .immediate = @as(u32, @truncate(x)) });
3898 try self.genSetReg(ty, reg, .{ .immediate = @as(u32, @truncate(x >> 32)) });
38993899
39003900 _ = try self.addInst(.{
39013901 .tag = .sllx,
......@@ -3994,7 +3994,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
39943994 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = rwo.reg });
39953995
39963996 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)));
39983998 const cond_reg = try self.register_manager.allocReg(null, gp);
39993999
40004000 // TODO handle floating point CCRs
......@@ -4412,8 +4412,8 @@ fn parseRegName(name: []const u8) ?Register {
44124412fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {
44134413 const tag = self.mir_instructions.items(.tag)[inst];
44144414 switch (tag) {
4415 .bpcc => self.mir_instructions.items(.data)[inst].branch_predict_int.inst = @intCast(Mir.Inst.Index, self.mir_instructions.len),
4416 .bpr => self.mir_instructions.items(.data)[inst].branch_predict_reg.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 = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len)),
44174417 else => unreachable,
44184418 }
44194419}
......@@ -4490,7 +4490,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
44904490 };
44914491
44924492 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)));
44944494 if (param_size <= 8) {
44954495 if (next_register < argument_registers.len) {
44964496 result.args[i] = .{ .register = argument_registers[next_register] };
......@@ -4522,7 +4522,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
45224522 } else if (!ret_ty.hasRuntimeBits(mod)) {
45234523 result.return_value = .{ .none = {} };
45244524 } else {
4525 const ret_ty_size = @intCast(u32, ret_ty.abiSize(mod));
4525 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
45264526 // The callee puts the return values in %i0-%i3, which becomes %o0-%o3 inside the caller.
45274527 if (ret_ty_size <= 8) {
45284528 result.return_value = switch (role) {
......@@ -4721,7 +4721,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
47214721 const mcv = try self.resolveInst(operand);
47224722 const ptr_ty = self.typeOf(operand);
47234723 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)));
47254725 switch (mcv) {
47264726 .ptr_stack_offset => |off| {
47274727 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };
......@@ -4816,7 +4816,7 @@ fn truncRegister(
48164816 .is_imm = true,
48174817 .rd = dest_reg,
48184818 .rs1 = operand_reg,
4819 .rs2_or_imm = .{ .imm = @intCast(u6, 64 - int_bits) },
4819 .rs2_or_imm = .{ .imm = @as(u6, @intCast(64 - int_bits)) },
48204820 },
48214821 },
48224822 });
......@@ -4830,7 +4830,7 @@ fn truncRegister(
48304830 .is_imm = true,
48314831 .rd = dest_reg,
48324832 .rs1 = dest_reg,
4833 .rs2_or_imm = .{ .imm = @intCast(u6, int_bits) },
4833 .rs2_or_imm = .{ .imm = @as(u6, @intCast(int_bits)) },
48344834 },
48354835 },
48364836 });
src/arch/sparc64/Emit.zig+13-13
......@@ -70,7 +70,7 @@ pub fn emitMir(
7070
7171 // Emit machine code
7272 for (mir_tags, 0..) |tag, index| {
73 const inst = @intCast(u32, index);
73 const inst = @as(u32, @intCast(index));
7474 switch (tag) {
7575 .dbg_line => try emit.mirDbgLine(inst),
7676 .dbg_prologue_end => try emit.mirDebugPrologueEnd(),
......@@ -294,7 +294,7 @@ fn mirConditionalBranch(emit: *Emit, inst: Mir.Inst.Index) !void {
294294 .bpcc => switch (tag) {
295295 .bpcc => {
296296 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));
298298 log.debug("mirConditionalBranch: {} offset={}", .{ inst, offset });
299299
300300 try emit.writeInstruction(
......@@ -303,7 +303,7 @@ fn mirConditionalBranch(emit: *Emit, inst: Mir.Inst.Index) !void {
303303 branch_predict_int.annul,
304304 branch_predict_int.pt,
305305 branch_predict_int.ccr,
306 @intCast(i21, offset),
306 @as(i21, @intCast(offset)),
307307 ),
308308 );
309309 },
......@@ -312,7 +312,7 @@ fn mirConditionalBranch(emit: *Emit, inst: Mir.Inst.Index) !void {
312312 .bpr => switch (tag) {
313313 .bpr => {
314314 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));
316316 log.debug("mirConditionalBranch: {} offset={}", .{ inst, offset });
317317
318318 try emit.writeInstruction(
......@@ -321,7 +321,7 @@ fn mirConditionalBranch(emit: *Emit, inst: Mir.Inst.Index) !void {
321321 branch_predict_reg.annul,
322322 branch_predict_reg.pt,
323323 branch_predict_reg.rs1,
324 @intCast(i18, offset),
324 @as(i18, @intCast(offset)),
325325 ),
326326 );
327327 },
......@@ -437,9 +437,9 @@ fn mirShift(emit: *Emit, inst: Mir.Inst.Index) !void {
437437 if (data.is_imm) {
438438 const imm = data.rs2_or_imm.imm;
439439 switch (tag) {
440 .sll => try emit.writeInstruction(Instruction.sll(u5, rs1, @truncate(u5, imm), rd)),
441 .srl => try emit.writeInstruction(Instruction.srl(u5, rs1, @truncate(u5, imm), rd)),
442 .sra => try emit.writeInstruction(Instruction.sra(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, @as(u5, @truncate(imm)), rd)),
442 .sra => try emit.writeInstruction(Instruction.sra(u5, rs1, @as(u5, @truncate(imm)), rd)),
443443 .sllx => try emit.writeInstruction(Instruction.sllx(u6, rs1, imm, rd)),
444444 .srlx => try emit.writeInstruction(Instruction.srlx(u6, rs1, imm, rd)),
445445 .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 {
495495}
496496
497497fn 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));
499499 const delta_pc: usize = emit.code.items.len - emit.prev_di_pc;
500500 switch (emit.debug_output) {
501501 .dwarf => |dbg_out| {
......@@ -547,7 +547,7 @@ fn lowerBranches(emit: *Emit) !void {
547547 // TODO optimization opportunity: do this in codegen while
548548 // generating MIR
549549 for (mir_tags, 0..) |tag, index| {
550 const inst = @intCast(u32, index);
550 const inst = @as(u32, @intCast(index));
551551 if (isBranch(tag)) {
552552 const target_inst = emit.branchTarget(inst);
553553
......@@ -592,7 +592,7 @@ fn lowerBranches(emit: *Emit) !void {
592592 var current_code_offset: usize = 0;
593593
594594 for (mir_tags, 0..) |tag, index| {
595 const inst = @intCast(u32, index);
595 const inst = @as(u32, @intCast(index));
596596
597597 // If this instruction contained in the code offset
598598 // mapping (when it is a target of a branch or if it is a
......@@ -607,7 +607,7 @@ fn lowerBranches(emit: *Emit) !void {
607607 const target_inst = emit.branchTarget(inst);
608608 if (target_inst < inst) {
609609 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));
611611 const branch_type = emit.branch_types.getPtr(inst).?;
612612 const optimal_branch_type = try emit.optimalBranchType(tag, offset);
613613 if (branch_type.* != optimal_branch_type) {
......@@ -626,7 +626,7 @@ fn lowerBranches(emit: *Emit) !void {
626626 for (origin_list.items) |forward_branch_inst| {
627627 const branch_tag = emit.mir.instructions.items(.tag)[forward_branch_inst];
628628 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));
630630 const branch_type = emit.branch_types.getPtr(forward_branch_inst).?;
631631 const optimal_branch_type = try emit.optimalBranchType(branch_tag, offset);
632632 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
379379 inline for (fields) |field| {
380380 @field(result, field.name) = switch (field.type) {
381381 u32 => mir.extra[i],
382 i32 => @bitCast(i32, mir.extra[i]),
382 i32 => @as(i32, @bitCast(mir.extra[i])),
383383 else => @compileError("bad field type"),
384384 };
385385 i += 1;
src/arch/sparc64/bits.zig+40-40
......@@ -16,7 +16,7 @@ pub const Register = enum(u6) {
1616 // zig fmt: on
1717
1818 pub fn id(self: Register) u5 {
19 return @truncate(u5, @intFromEnum(self));
19 return @as(u5, @truncate(@intFromEnum(self)));
2020 }
2121
2222 pub fn enc(self: Register) u5 {
......@@ -96,9 +96,9 @@ pub const FloatingPointRegister = enum(u7) {
9696
9797 pub fn id(self: FloatingPointRegister) u6 {
9898 return switch (self.size()) {
99 32 => @truncate(u6, @intFromEnum(self)),
100 64 => @truncate(u6, (@intFromEnum(self) - 32) * 2),
101 128 => @truncate(u6, (@intFromEnum(self) - 64) * 4),
99 32 => @as(u6, @truncate(@intFromEnum(self))),
100 64 => @as(u6, @truncate((@intFromEnum(self) - 32) * 2)),
101 128 => @as(u6, @truncate((@intFromEnum(self) - 64) * 4)),
102102 else => unreachable,
103103 };
104104 }
......@@ -109,7 +109,7 @@ pub const FloatingPointRegister = enum(u7) {
109109 // (See section 5.1.4.1 of SPARCv9 ISA specification)
110110
111111 const reg_id = self.id();
112 return @truncate(u5, reg_id | (reg_id >> 5));
112 return @as(u5, @truncate(reg_id | (reg_id >> 5)));
113113 }
114114
115115 /// Returns the bit-width of the register.
......@@ -752,13 +752,13 @@ pub const Instruction = union(enum) {
752752 // See section 6.2 of the SPARCv9 ISA manual.
753753
754754 fn format1(disp: i32) Instruction {
755 const udisp = @bitCast(u32, disp);
755 const udisp = @as(u32, @bitCast(disp));
756756
757757 // In SPARC, branch target needs to be aligned to 4 bytes.
758758 assert(udisp % 4 == 0);
759759
760760 // 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));
762762 return Instruction{
763763 .format_1 = .{
764764 .disp30 = udisp_truncated,
......@@ -777,13 +777,13 @@ pub const Instruction = union(enum) {
777777 }
778778
779779 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
782782 // In SPARC, branch target needs to be aligned to 4 bytes.
783783 assert(udisp % 4 == 0);
784784
785785 // 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));
787787 return Instruction{
788788 .format_2b = .{
789789 .a = @intFromBool(annul),
......@@ -795,16 +795,16 @@ pub const Instruction = union(enum) {
795795 }
796796
797797 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
800800 // In SPARC, branch target needs to be aligned to 4 bytes.
801801 assert(udisp % 4 == 0);
802802
803803 // 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);
807 const ccr_cc0 = @truncate(u1, @intFromEnum(ccr));
806 const ccr_cc1 = @as(u1, @truncate(@intFromEnum(ccr) >> 1));
807 const ccr_cc0 = @as(u1, @truncate(@intFromEnum(ccr)));
808808 return Instruction{
809809 .format_2c = .{
810810 .a = @intFromBool(annul),
......@@ -819,16 +819,16 @@ pub const Instruction = union(enum) {
819819 }
820820
821821 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
824824 // In SPARC, branch target needs to be aligned to 4 bytes.
825825 assert(udisp % 4 == 0);
826826
827827 // Discard the last two bits since those are implicitly zero,
828828 // and split it into low and high parts.
829 const udisp_truncated = @truncate(u16, udisp >> 2);
830 const udisp_hi = @truncate(u2, (udisp_truncated & 0b1100_0000_0000_0000) >> 14);
831 const udisp_lo = @truncate(u14, udisp_truncated & 0b0011_1111_1111_1111);
829 const udisp_truncated = @as(u16, @truncate(udisp >> 2));
830 const udisp_hi = @as(u2, @truncate((udisp_truncated & 0b1100_0000_0000_0000) >> 14));
831 const udisp_lo = @as(u14, @truncate(udisp_truncated & 0b0011_1111_1111_1111));
832832 return Instruction{
833833 .format_2d = .{
834834 .a = @intFromBool(annul),
......@@ -860,7 +860,7 @@ pub const Instruction = union(enum) {
860860 .rd = rd.enc(),
861861 .op3 = op3,
862862 .rs1 = rs1.enc(),
863 .simm13 = @bitCast(u13, imm),
863 .simm13 = @as(u13, @bitCast(imm)),
864864 },
865865 };
866866 }
......@@ -880,7 +880,7 @@ pub const Instruction = union(enum) {
880880 .op = op,
881881 .op3 = op3,
882882 .rs1 = rs1.enc(),
883 .simm13 = @bitCast(u13, imm),
883 .simm13 = @as(u13, @bitCast(imm)),
884884 },
885885 };
886886 }
......@@ -904,7 +904,7 @@ pub const Instruction = union(enum) {
904904 .op3 = op3,
905905 .rs1 = rs1.enc(),
906906 .rcond = @intFromEnum(rcond),
907 .simm10 = @bitCast(u10, imm),
907 .simm10 = @as(u10, @bitCast(imm)),
908908 },
909909 };
910910 }
......@@ -922,8 +922,8 @@ pub const Instruction = union(enum) {
922922 fn format3h(cmask: MemCompletionConstraint, mmask: MemOrderingConstraint) Instruction {
923923 return Instruction{
924924 .format_3h = .{
925 .cmask = @bitCast(u3, cmask),
926 .mmask = @bitCast(u4, mmask),
925 .cmask = @as(u3, @bitCast(cmask)),
926 .mmask = @as(u4, @bitCast(mmask)),
927927 },
928928 };
929929 }
......@@ -995,8 +995,8 @@ pub const Instruction = union(enum) {
995995 };
996996 }
997997 fn format3o(op: u2, op3: u6, opf: u9, ccr: CCR, rs1: Register, rs2: Register) Instruction {
998 const ccr_cc1 = @truncate(u1, @intFromEnum(ccr) >> 1);
999 const ccr_cc0 = @truncate(u1, @intFromEnum(ccr));
998 const ccr_cc1 = @as(u1, @truncate(@intFromEnum(ccr) >> 1));
999 const ccr_cc0 = @as(u1, @truncate(@intFromEnum(ccr)));
10001000 return Instruction{
10011001 .format_3o = .{
10021002 .op = op,
......@@ -1051,8 +1051,8 @@ pub const Instruction = union(enum) {
10511051 }
10521052
10531053 fn format4a(op3: u6, ccr: CCR, rs1: Register, rs2: Register, rd: Register) Instruction {
1054 const ccr_cc1 = @truncate(u1, @intFromEnum(ccr) >> 1);
1055 const ccr_cc0 = @truncate(u1, @intFromEnum(ccr));
1054 const ccr_cc1 = @as(u1, @truncate(@intFromEnum(ccr) >> 1));
1055 const ccr_cc0 = @as(u1, @truncate(@intFromEnum(ccr)));
10561056 return Instruction{
10571057 .format_4a = .{
10581058 .rd = rd.enc(),
......@@ -1066,8 +1066,8 @@ pub const Instruction = union(enum) {
10661066 }
10671067
10681068 fn format4b(op3: u6, ccr: CCR, rs1: Register, imm: i11, rd: Register) Instruction {
1069 const ccr_cc1 = @truncate(u1, @intFromEnum(ccr) >> 1);
1070 const ccr_cc0 = @truncate(u1, @intFromEnum(ccr));
1069 const ccr_cc1 = @as(u1, @truncate(@intFromEnum(ccr) >> 1));
1070 const ccr_cc0 = @as(u1, @truncate(@intFromEnum(ccr)));
10711071 return Instruction{
10721072 .format_4b = .{
10731073 .rd = rd.enc(),
......@@ -1075,15 +1075,15 @@ pub const Instruction = union(enum) {
10751075 .rs1 = rs1.enc(),
10761076 .cc1 = ccr_cc1,
10771077 .cc0 = ccr_cc0,
1078 .simm11 = @bitCast(u11, imm),
1078 .simm11 = @as(u11, @bitCast(imm)),
10791079 },
10801080 };
10811081 }
10821082
10831083 fn format4c(op3: u6, cond: Condition, ccr: CCR, rs2: Register, rd: Register) Instruction {
1084 const ccr_cc2 = @truncate(u1, @intFromEnum(ccr) >> 2);
1085 const ccr_cc1 = @truncate(u1, @intFromEnum(ccr) >> 1);
1086 const ccr_cc0 = @truncate(u1, @intFromEnum(ccr));
1084 const ccr_cc2 = @as(u1, @truncate(@intFromEnum(ccr) >> 2));
1085 const ccr_cc1 = @as(u1, @truncate(@intFromEnum(ccr) >> 1));
1086 const ccr_cc0 = @as(u1, @truncate(@intFromEnum(ccr)));
10871087 return Instruction{
10881088 .format_4c = .{
10891089 .rd = rd.enc(),
......@@ -1098,9 +1098,9 @@ pub const Instruction = union(enum) {
10981098 }
10991099
11001100 fn format4d(op3: u6, cond: Condition, ccr: CCR, imm: i11, rd: Register) Instruction {
1101 const ccr_cc2 = @truncate(u1, @intFromEnum(ccr) >> 2);
1102 const ccr_cc1 = @truncate(u1, @intFromEnum(ccr) >> 1);
1103 const ccr_cc0 = @truncate(u1, @intFromEnum(ccr));
1101 const ccr_cc2 = @as(u1, @truncate(@intFromEnum(ccr) >> 2));
1102 const ccr_cc1 = @as(u1, @truncate(@intFromEnum(ccr) >> 1));
1103 const ccr_cc0 = @as(u1, @truncate(@intFromEnum(ccr)));
11041104 return Instruction{
11051105 .format_4d = .{
11061106 .rd = rd.enc(),
......@@ -1109,14 +1109,14 @@ pub const Instruction = union(enum) {
11091109 .cond = cond.enc(),
11101110 .cc1 = ccr_cc1,
11111111 .cc0 = ccr_cc0,
1112 .simm11 = @bitCast(u11, imm),
1112 .simm11 = @as(u11, @bitCast(imm)),
11131113 },
11141114 };
11151115 }
11161116
11171117 fn format4e(op3: u6, ccr: CCR, rs1: Register, rd: Register, sw_trap: u7) Instruction {
1118 const ccr_cc1 = @truncate(u1, @intFromEnum(ccr) >> 1);
1119 const ccr_cc0 = @truncate(u1, @intFromEnum(ccr));
1118 const ccr_cc1 = @as(u1, @truncate(@intFromEnum(ccr) >> 1));
1119 const ccr_cc0 = @as(u1, @truncate(@intFromEnum(ccr)));
11201120 return Instruction{
11211121 .format_4e = .{
11221122 .rd = rd.enc(),
......@@ -1468,8 +1468,8 @@ pub const Instruction = union(enum) {
14681468 pub fn trap(comptime s2: type, cond: ICondition, ccr: CCR, rs1: Register, rs2: s2) Instruction {
14691469 // Tcc instructions abuse the rd field to store the conditionals.
14701470 return switch (s2) {
1471 Register => format4a(0b11_1010, ccr, rs1, rs2, @enumFromInt(Register, @intFromEnum(cond))),
1472 u7 => format4e(0b11_1010, ccr, rs1, @enumFromInt(Register, @intFromEnum(cond)), rs2),
1471 Register => format4a(0b11_1010, ccr, rs1, rs2, @as(Register, @enumFromInt(@intFromEnum(cond)))),
1472 u7 => format4e(0b11_1010, ccr, rs1, @as(Register, @enumFromInt(@intFromEnum(cond))), rs2),
14731473 else => unreachable,
14741474 };
14751475 }
src/arch/wasm/CodeGen.zig+164-164
......@@ -120,7 +120,7 @@ const WValue = union(enum) {
120120 if (local_value < reserved + 2) return; // reserved locals may never be re-used. Also accounts for 2 stack locals.
121121
122122 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]));
124124 switch (valtype) {
125125 .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
126126 .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
817817 assert(operands.len <= Liveness.bpi - 1);
818818 var tomb_bits = func.liveness.getTombBits(inst);
819819 for (operands) |operand| {
820 const dies = @truncate(u1, tomb_bits) != 0;
820 const dies = @as(u1, @truncate(tomb_bits)) != 0;
821821 tomb_bits >>= 1;
822822 if (!dies) continue;
823823 processDeath(func, operand);
......@@ -910,7 +910,7 @@ fn addTag(func: *CodeGen, tag: Mir.Inst.Tag) error{OutOfMemory}!void {
910910}
911911
912912fn 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));
914914 try func.mir_extra.append(func.gpa, @intFromEnum(opcode));
915915 try func.addInst(.{ .tag = .misc_prefix, .data = .{ .payload = extra_index } });
916916}
......@@ -934,11 +934,11 @@ fn addImm64(func: *CodeGen, imm: u64) error{OutOfMemory}!void {
934934/// Accepts the index into the list of 128bit-immediates
935935fn addImm128(func: *CodeGen, index: u32) error{OutOfMemory}!void {
936936 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));
938938 // tag + 128bit value
939939 try func.mir_extra.ensureUnusedCapacity(func.gpa, 5);
940940 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)));
942942 try func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });
943943}
944944
......@@ -979,7 +979,7 @@ fn addExtra(func: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {
979979/// Returns the index into `mir_extra`
980980fn addExtraAssumeCapacity(func: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {
981981 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));
983983 inline for (fields) |field| {
984984 func.mir_extra.appendAssumeCapacity(switch (field.type) {
985985 u32 => @field(extra, field.name),
......@@ -1020,7 +1020,7 @@ fn typeToValtype(ty: Type, mod: *Module) wasm.Valtype {
10201020 },
10211021 .Union => switch (ty.containerLayout(mod)) {
10221022 .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");
10241024 return typeToValtype(int_ty, mod);
10251025 },
10261026 else => wasm.Valtype.i32,
......@@ -1050,7 +1050,7 @@ fn emitWValue(func: *CodeGen, value: WValue) InnerError!void {
10501050 .dead => unreachable, // reference to free'd `WValue` (missing reuseOperand?)
10511051 .none, .stack => {}, // no-op
10521052 .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))),
10541054 .imm64 => |val| try func.addImm64(val),
10551055 .imm128 => |val| try func.addImm128(val),
10561056 .float32 => |val| try func.addInst(.{ .tag = .f32_const, .data = .{ .float32 = val } }),
......@@ -1264,7 +1264,7 @@ fn genFunc(func: *CodeGen) InnerError!void {
12641264 // In case we have a return value, but the last instruction is a noreturn (such as a while loop)
12651265 // we emit an unreachable instruction to tell the stack validator that part will never be reached.
12661266 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));
12681268 const last_inst_ty = func.typeOfIndex(inst);
12691269 if (!last_inst_ty.hasRuntimeBitsIgnoreComptime(mod) or last_inst_ty.isNoReturn(mod)) {
12701270 try func.addTag(.@"unreachable");
......@@ -1287,11 +1287,11 @@ fn genFunc(func: *CodeGen) InnerError!void {
12871287 try prologue.append(.{ .tag = .local_tee, .data = .{ .label = func.initial_stack_value.local.value } });
12881288 // get the total stack size
12891289 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)) } });
12911291 // substract it from the current stack pointer
12921292 try prologue.append(.{ .tag = .i32_sub, .data = .{ .tag = {} } });
12931293 // 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 } });
12951295 // Bitwise-and the value to get the new stack pointer to ensure the pointers are aligned with the abi alignment
12961296 try prologue.append(.{ .tag = .i32_and, .data = .{ .tag = {} } });
12971297 // 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:
14321432 if (value != .imm32 and value != .imm64) {
14331433 const opcode = buildOpcode(.{
14341434 .op = .load,
1435 .width = @intCast(u8, abi_size),
1435 .width = @as(u8, @intCast(abi_size)),
14361436 .signedness = if (scalar_type.isSignedInt(mod)) .signed else .unsigned,
14371437 .valtype1 = typeToValtype(scalar_type, mod),
14381438 });
......@@ -1468,7 +1468,7 @@ fn lowerToStack(func: *CodeGen, value: WValue) !void {
14681468 if (offset.value > 0) {
14691469 switch (func.arch()) {
14701470 .wasm32 => {
1471 try func.addImm32(@bitCast(i32, offset.value));
1471 try func.addImm32(@as(i32, @bitCast(offset.value)));
14721472 try func.addTag(.i32_add);
14731473 },
14741474 .wasm64 => {
......@@ -1815,7 +1815,7 @@ fn buildPointerOffset(func: *CodeGen, ptr_value: WValue, offset: u64, action: en
18151815 if (offset + ptr_value.offset() > 0) {
18161816 switch (func.arch()) {
18171817 .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())))));
18191819 try func.addTag(.i32_add);
18201820 },
18211821 .wasm64 => {
......@@ -2111,7 +2111,7 @@ fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21112111 try func.emitWValue(operand);
21122112 const opcode = buildOpcode(.{
21132113 .op = .load,
2114 .width = @intCast(u8, scalar_type.abiSize(mod) * 8),
2114 .width = @as(u8, @intCast(scalar_type.abiSize(mod) * 8)),
21152115 .signedness = if (scalar_type.isSignedInt(mod)) .signed else .unsigned,
21162116 .valtype1 = typeToValtype(scalar_type, mod),
21172117 });
......@@ -2180,7 +2180,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
21802180 if (modifier == .always_tail) return func.fail("TODO implement tail calls for wasm", .{});
21812181 const pl_op = func.air.instructions.items(.data)[inst].pl_op;
21822182 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]));
21842184 const ty = func.typeOf(pl_op.operand);
21852185
21862186 const mod = func.bin_file.base.options.module.?;
......@@ -2319,15 +2319,15 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
23192319 return func.fail("TODO: airStore for pointers to bitfields with backing type larger than 64bits", .{});
23202320 }
23212321
2322 var mask = @intCast(u64, (@as(u65, 1) << @intCast(u7, ty.bitSize(mod))) - 1);
2323 mask <<= @intCast(u6, ptr_info.packed_offset.bit_offset);
2322 var mask = @as(u64, @intCast((@as(u65, 1) << @as(u7, @intCast(ty.bitSize(mod)))) - 1));
2323 mask <<= @as(u6, @intCast(ptr_info.packed_offset.bit_offset));
23242324 mask ^= ~@as(u64, 0);
23252325 const shift_val = if (ptr_info.packed_offset.host_size <= 4)
23262326 WValue{ .imm32 = ptr_info.packed_offset.bit_offset }
23272327 else
23282328 WValue{ .imm64 = ptr_info.packed_offset.bit_offset };
23292329 const mask_val = if (ptr_info.packed_offset.host_size <= 4)
2330 WValue{ .imm32 = @truncate(u32, mask) }
2330 WValue{ .imm32 = @as(u32, @truncate(mask)) }
23312331 else
23322332 WValue{ .imm64 = mask };
23332333
......@@ -2357,7 +2357,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
23572357 return func.store(lhs, rhs, Type.anyerror, 0);
23582358 }
23592359
2360 const len = @intCast(u32, abi_size);
2360 const len = @as(u32, @intCast(abi_size));
23612361 return func.memcpy(lhs, rhs, .{ .imm32 = len });
23622362 },
23632363 .Optional => {
......@@ -2372,23 +2372,23 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
23722372 return func.store(lhs, rhs, Type.anyerror, 0);
23732373 }
23742374
2375 const len = @intCast(u32, abi_size);
2375 const len = @as(u32, @intCast(abi_size));
23762376 return func.memcpy(lhs, rhs, .{ .imm32 = len });
23772377 },
23782378 .Struct, .Array, .Union => if (isByRef(ty, mod)) {
2379 const len = @intCast(u32, abi_size);
2379 const len = @as(u32, @intCast(abi_size));
23802380 return func.memcpy(lhs, rhs, .{ .imm32 = len });
23812381 },
23822382 .Vector => switch (determineSimdStoreStrategy(ty, mod)) {
23832383 .unrolled => {
2384 const len = @intCast(u32, abi_size);
2384 const len = @as(u32, @intCast(abi_size));
23852385 return func.memcpy(lhs, rhs, .{ .imm32 = len });
23862386 },
23872387 .direct => {
23882388 try func.emitWValue(lhs);
23892389 try func.lowerToStack(rhs);
23902390 // 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));
23922392 // stores as := opcode, offset, alignment (opcode::memarg)
23932393 try func.mir_extra.appendSlice(func.gpa, &[_]u32{
23942394 std.wasm.simdOpcode(.v128_store),
......@@ -2423,7 +2423,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
24232423 try func.store(.{ .stack = {} }, msb, Type.u64, 8 + lhs.offset());
24242424 return;
24252425 } 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))) });
24272427 },
24282428 else => if (abi_size > 8) {
24292429 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
24402440 const valtype = typeToValtype(ty, mod);
24412441 const opcode = buildOpcode(.{
24422442 .valtype1 = valtype,
2443 .width = @intCast(u8, abi_size * 8),
2443 .width = @as(u8, @intCast(abi_size * 8)),
24442444 .op = .store,
24452445 });
24462446
......@@ -2501,7 +2501,7 @@ fn load(func: *CodeGen, operand: WValue, ty: Type, offset: u32) InnerError!WValu
25012501
25022502 if (ty.zigTypeTag(mod) == .Vector) {
25032503 // 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));
25052505 // stores as := opcode, offset, alignment (opcode::memarg)
25062506 try func.mir_extra.appendSlice(func.gpa, &[_]u32{
25072507 std.wasm.simdOpcode(.v128_load),
......@@ -2512,7 +2512,7 @@ fn load(func: *CodeGen, operand: WValue, ty: Type, offset: u32) InnerError!WValu
25122512 return WValue{ .stack = {} };
25132513 }
25142514
2515 const abi_size = @intCast(u8, ty.abiSize(mod));
2515 const abi_size = @as(u8, @intCast(ty.abiSize(mod)));
25162516 const opcode = buildOpcode(.{
25172517 .valtype1 = typeToValtype(ty, mod),
25182518 .width = abi_size * 8,
......@@ -2589,10 +2589,10 @@ fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
25892589 // For big integers we can ignore this as we will call into compiler-rt which handles this.
25902590 const result = switch (op) {
25912591 .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 {
25932593 return func.fail("TODO: implement '{s}' for types larger than 128 bits", .{@tagName(op)});
25942594 };
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)))).?;
25962596 const new_rhs = if (lhs_wasm_bits != rhs_wasm_bits and lhs_wasm_bits != 128) blk: {
25972597 const tmp = try func.intcast(rhs, rhs_ty, lhs_ty);
25982598 break :blk try tmp.toLocal(func, lhs_ty);
......@@ -2868,10 +2868,10 @@ fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
28682868 // For big integers we can ignore this as we will call into compiler-rt which handles this.
28692869 const result = switch (op) {
28702870 .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 {
28722872 return func.fail("TODO: implement '{s}' for types larger than 128 bits", .{@tagName(op)});
28732873 };
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)))).?;
28752875 const new_rhs = if (lhs_wasm_bits != rhs_wasm_bits and lhs_wasm_bits != 128) blk: {
28762876 const tmp = try func.intcast(rhs, rhs_ty, lhs_ty);
28772877 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
29022902fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
29032903 const mod = func.bin_file.base.options.module.?;
29042904 assert(ty.abiSize(mod) <= 16);
2905 const bitsize = @intCast(u16, ty.bitSize(mod));
2905 const bitsize = @as(u16, @intCast(ty.bitSize(mod)));
29062906 const wasm_bits = toWasmBits(bitsize) orelse {
29072907 return func.fail("TODO: Implement wrapOperand for bitsize '{d}'", .{bitsize});
29082908 };
......@@ -2916,7 +2916,7 @@ fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
29162916 const result_ptr = try func.allocStack(ty);
29172917 try func.emitWValue(result_ptr);
29182918 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;
29202920 try func.emitWValue(result_ptr);
29212921 _ = try func.load(operand, Type.u64, 0);
29222922 try func.addImm64(result);
......@@ -2925,10 +2925,10 @@ fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
29252925 return result_ptr;
29262926 }
29272927
2928 const result = (@as(u64, 1) << @intCast(u6, bitsize)) - 1;
2928 const result = (@as(u64, 1) << @as(u6, @intCast(bitsize))) - 1;
29292929 try func.emitWValue(operand);
29302930 if (bitsize <= 32) {
2931 try func.addImm32(@bitCast(i32, @intCast(u32, result)));
2931 try func.addImm32(@as(i32, @bitCast(@as(u32, @intCast(result)))));
29322932 try func.addTag(.i32_and);
29332933 } else if (bitsize <= 64) {
29342934 try func.addImm64(result);
......@@ -2957,15 +2957,15 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue
29572957 const index = elem.index;
29582958 const elem_type = mod.intern_pool.typeOf(elem.base).toType().elemType2(mod);
29592959 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)));
29612961 },
29622962 .field => |field| {
29632963 const parent_ty = mod.intern_pool.typeOf(field.base).toType().childType(mod);
29642964
29652965 const field_offset = switch (parent_ty.zigTypeTag(mod)) {
29662966 .Struct => switch (parent_ty.containerLayout(mod)) {
2967 .Packed => parent_ty.packedStructFieldByteOffset(@intCast(usize, field.index), mod),
2968 else => parent_ty.structFieldOffset(@intCast(usize, field.index), mod),
2967 .Packed => parent_ty.packedStructFieldByteOffset(@as(usize, @intCast(field.index)), mod),
2968 else => parent_ty.structFieldOffset(@as(usize, @intCast(field.index)), mod),
29692969 },
29702970 .Union => switch (parent_ty.containerLayout(mod)) {
29712971 .Packed => 0,
......@@ -2975,7 +2975,7 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue
29752975 if (layout.payload_align > layout.tag_align) break :blk 0;
29762976
29772977 // 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)));
29792979 },
29802980 },
29812981 .Pointer => switch (parent_ty.ptrSize(mod)) {
......@@ -2988,7 +2988,7 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue
29882988 },
29892989 else => unreachable,
29902990 };
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)));
29922992 },
29932993 }
29942994}
......@@ -3045,11 +3045,11 @@ fn toTwosComplement(value: anytype, bits: u7) std.meta.Int(.unsigned, @typeInfo(
30453045 comptime assert(@typeInfo(T).Int.signedness == .signed);
30463046 assert(bits <= 64);
30473047 const WantedT = std.meta.Int(.unsigned, @typeInfo(T).Int.bits);
3048 if (value >= 0) return @bitCast(WantedT, value);
3049 const max_value = @intCast(u64, (@as(u65, 1) << bits) - 1);
3050 const flipped = @intCast(T, (~-@as(i65, value)) + 1);
3051 const result = @bitCast(WantedT, flipped) & max_value;
3052 return @intCast(WantedT, result);
3048 if (value >= 0) return @as(WantedT, @bitCast(value));
3049 const max_value = @as(u64, @intCast((@as(u65, 1) << bits) - 1));
3050 const flipped = @as(T, @intCast((~-@as(i65, value)) + 1));
3051 const result = @as(WantedT, @bitCast(flipped)) & max_value;
3052 return @as(WantedT, @intCast(result));
30533053}
30543054
30553055fn 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 {
31503150 const int_info = ty.intInfo(mod);
31513151 switch (int_info.signedness) {
31523152 .signed => switch (int_info.bits) {
3153 0...32 => return WValue{ .imm32 = @intCast(u32, toTwosComplement(
3153 0...32 => return WValue{ .imm32 = @as(u32, @intCast(toTwosComplement(
31543154 val.toSignedInt(mod),
3155 @intCast(u6, int_info.bits),
3156 )) },
3155 @as(u6, @intCast(int_info.bits)),
3156 ))) },
31573157 33...64 => return WValue{ .imm64 = toTwosComplement(
31583158 val.toSignedInt(mod),
3159 @intCast(u7, int_info.bits),
3159 @as(u7, @intCast(int_info.bits)),
31603160 ) },
31613161 else => unreachable,
31623162 },
31633163 .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))) },
31653165 33...64 => return WValue{ .imm64 = val.toUnsignedInt(mod) },
31663166 else => unreachable,
31673167 },
......@@ -3198,7 +3198,7 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
31983198 return func.lowerConstant(enum_tag.int.toValue(), int_tag_ty.toType());
31993199 },
32003200 .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)) },
32023202 .f32 => |f32_val| return WValue{ .float32 = f32_val },
32033203 .f64 => |f64_val| return WValue{ .float64 = f64_val },
32043204 else => unreachable,
......@@ -3254,7 +3254,7 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
32543254/// Stores the value as a 128bit-immediate value by storing it inside
32553255/// the list and returning the index into this list as `WValue`.
32563256fn 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));
32583258 try func.simd_immediates.append(func.gpa, value);
32593259 return WValue{ .imm128 = index };
32603260}
......@@ -3270,8 +3270,8 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
32703270 },
32713271 .Float => switch (ty.floatBits(func.target)) {
32723272 16 => return WValue{ .imm32 = 0xaaaaaaaa },
3273 32 => return WValue{ .float32 = @bitCast(f32, @as(u32, 0xaaaaaaaa)) },
3274 64 => return WValue{ .float64 = @bitCast(f64, @as(u64, 0xaaaaaaaaaaaaaaaa)) },
3273 32 => return WValue{ .float32 = @as(f32, @bitCast(@as(u32, 0xaaaaaaaa))) },
3274 64 => return WValue{ .float64 = @as(f64, @bitCast(@as(u64, 0xaaaaaaaaaaaaaaaa))) },
32753275 else => unreachable,
32763276 },
32773277 .Pointer => switch (func.arch()) {
......@@ -3312,13 +3312,13 @@ fn valueAsI32(func: *const CodeGen, val: Value, ty: Type) i32 {
33123312 .enum_tag => |enum_tag| intIndexAsI32(&mod.intern_pool, enum_tag.int, mod),
33133313 .int => |int| intStorageAsI32(int.storage, mod),
33143314 .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).?)))),
33163316 else => unreachable,
33173317 },
33183318 }
33193319
33203320 return switch (ty.zigTypeTag(mod)) {
3321 .ErrorSet => @bitCast(i32, val.getErrorInt(mod)),
3321 .ErrorSet => @as(i32, @bitCast(val.getErrorInt(mod))),
33223322 else => unreachable, // Programmer called this function for an illegal type
33233323 };
33243324}
......@@ -3329,11 +3329,11 @@ fn intIndexAsI32(ip: *const InternPool, int: InternPool.Index, mod: *Module) i32
33293329
33303330fn intStorageAsI32(storage: InternPool.Key.Int.Storage, mod: *Module) i32 {
33313331 return switch (storage) {
3332 .i64 => |x| @intCast(i32, x),
3333 .u64 => |x| @bitCast(i32, @intCast(u32, x)),
3332 .i64 => |x| @as(i32, @intCast(x)),
3333 .u64 => |x| @as(i32, @bitCast(@as(u32, @intCast(x)))),
33343334 .big_int => unreachable,
3335 .lazy_align => |ty| @bitCast(i32, ty.toType().abiAlignment(mod)),
3336 .lazy_size => |ty| @bitCast(i32, @intCast(u32, ty.toType().abiSize(mod))),
3335 .lazy_align => |ty| @as(i32, @bitCast(ty.toType().abiAlignment(mod))),
3336 .lazy_size => |ty| @as(i32, @bitCast(@as(u32, @intCast(ty.toType().abiSize(mod))))),
33373337 };
33383338}
33393339
......@@ -3421,7 +3421,7 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
34213421 try func.branches.ensureUnusedCapacity(func.gpa, 2);
34223422 {
34233423 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)));
34253425 defer {
34263426 var else_stack = func.branches.pop();
34273427 else_stack.deinit(func.gpa);
......@@ -3433,7 +3433,7 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
34333433 // Outer block that matches the condition
34343434 {
34353435 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)));
34373437 defer {
34383438 var then_stack = func.branches.pop();
34393439 then_stack.deinit(func.gpa);
......@@ -3715,7 +3715,7 @@ fn structFieldPtr(
37153715 }
37163716 switch (struct_ptr) {
37173717 .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 } };
37193719 },
37203720 else => return func.buildPointerOffset(struct_ptr, offset, .new),
37213721 }
......@@ -3755,7 +3755,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
37553755 try func.binOp(operand, const_wvalue, backing_ty, .shr);
37563756
37573757 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))));
37593759 const truncated = try func.trunc(shifted_value, int_type, backing_ty);
37603760 const bitcasted = try func.bitcast(field_ty, int_type, truncated);
37613761 break :result try bitcasted.toLocal(func, field_ty);
......@@ -3764,7 +3764,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
37643764 // we can simply reuse the operand.
37653765 break :result func.reuseOperand(struct_field.struct_operand, operand);
37663766 } 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))));
37683768 const truncated = try func.trunc(shifted_value, int_type, backing_ty);
37693769 break :result try truncated.toLocal(func, field_ty);
37703770 }
......@@ -3783,14 +3783,14 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
37833783 }
37843784 }
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))));
37873787 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))));
37893789 const truncated = try func.trunc(operand, int_type, union_int_type);
37903790 const bitcasted = try func.bitcast(field_ty, int_type, truncated);
37913791 break :result try bitcasted.toLocal(func, field_ty);
37923792 } 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))));
37943794 const truncated = try func.trunc(operand, int_type, union_int_type);
37953795 break :result try truncated.toLocal(func, field_ty);
37963796 }
......@@ -3847,7 +3847,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
38473847 var highest_maybe: ?i32 = null;
38483848 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
38493849 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]));
38513851 const case_body = func.air.extra[case.end + items.len ..][0..case.data.body_len];
38523852 extra_index = case.end + items.len + case_body.len;
38533853 const values = try func.gpa.alloc(CaseValue, items.len);
......@@ -3904,7 +3904,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
39043904 }
39053905
39063906 // 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;
39083908 const jump_table: Mir.JumpTable = .{ .length = depth };
39093909 const table_extra_index = try func.addExtra(jump_table);
39103910 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 {
39153915 const idx = blk: {
39163916 for (case_list.items, 0..) |case, idx| {
39173917 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));
39193919 }
39203920 }
39213921 // 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
40184018 try func.emitWValue(operand);
40194019 if (pl_ty.hasRuntimeBitsIgnoreComptime(mod)) {
40204020 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))),
40224022 .alignment = Type.anyerror.abiAlignment(mod),
40234023 });
40244024 }
......@@ -4051,7 +4051,7 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo
40514051 break :result WValue{ .none = {} };
40524052 }
40534053
4054 const pl_offset = @intCast(u32, errUnionPayloadOffset(payload_ty, mod));
4054 const pl_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, mod)));
40554055 if (op_is_ptr or isByRef(payload_ty, mod)) {
40564056 break :result try func.buildPointerOffset(operand, pl_offset, .new);
40574057 }
......@@ -4080,7 +4080,7 @@ fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)
40804080 break :result func.reuseOperand(ty_op.operand, operand);
40814081 }
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))));
40844084 break :result try error_val.toLocal(func, Type.anyerror);
40854085 };
40864086 func.finishAir(inst, result, &.{ty_op.operand});
......@@ -4100,13 +4100,13 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void
41004100 }
41014101
41024102 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);
41044104 try func.store(payload_ptr, operand, pl_ty, 0);
41054105
41064106 // ensure we also write '0' to the error part, so any present stack value gets overwritten by it.
41074107 try func.emitWValue(err_union);
41084108 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)));
41104110 try func.addMemArg(.i32_store16, .{ .offset = err_union.offset() + err_val_offset, .alignment = 2 });
41114111 break :result err_union;
41124112 };
......@@ -4128,11 +4128,11 @@ fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41284128
41294129 const err_union = try func.allocStack(err_ty);
41304130 // 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
41334133 // write 'undefined' to the payload
4134 const payload_ptr = try func.buildPointerOffset(err_union, @intCast(u32, errUnionPayloadOffset(pl_ty, mod)), .new);
4135 const len = @intCast(u32, err_ty.errorUnionPayload(mod).abiSize(mod));
4134 const payload_ptr = try func.buildPointerOffset(err_union, @as(u32, @intCast(errUnionPayloadOffset(pl_ty, mod))), .new);
4135 const len = @as(u32, @intCast(err_ty.errorUnionPayload(mod).abiSize(mod)));
41364136 try func.memset(Type.u8, payload_ptr, .{ .imm32 = len }, .{ .imm32 = 0xaa });
41374137
41384138 break :result err_union;
......@@ -4154,8 +4154,8 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41544154 return func.fail("todo Wasm intcast for bitsize > 128", .{});
41554155 }
41564156
4157 const op_bits = toWasmBits(@intCast(u16, operand_ty.bitSize(mod))).?;
4158 const wanted_bits = toWasmBits(@intCast(u16, ty.bitSize(mod))).?;
4157 const op_bits = toWasmBits(@as(u16, @intCast(operand_ty.bitSize(mod)))).?;
4158 const wanted_bits = toWasmBits(@as(u16, @intCast(ty.bitSize(mod)))).?;
41594159 const result = if (op_bits == wanted_bits)
41604160 func.reuseOperand(ty_op.operand, operand)
41614161 else
......@@ -4170,8 +4170,8 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41704170/// NOTE: May leave the result on the top of the stack.
41714171fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!WValue {
41724172 const mod = func.bin_file.base.options.module.?;
4173 const given_bitsize = @intCast(u16, given.bitSize(mod));
4174 const wanted_bitsize = @intCast(u16, wanted.bitSize(mod));
4173 const given_bitsize = @as(u16, @intCast(given.bitSize(mod)));
4174 const wanted_bitsize = @as(u16, @intCast(wanted.bitSize(mod)));
41754175 assert(given_bitsize <= 128);
41764176 assert(wanted_bitsize <= 128);
41774177
......@@ -4396,7 +4396,7 @@ fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43964396
43974397 // calculate index into slice
43984398 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)))));
44004400 try func.addTag(.i32_mul);
44014401 try func.addTag(.i32_add);
44024402
......@@ -4426,7 +4426,7 @@ fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44264426
44274427 // calculate index into slice
44284428 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)))));
44304430 try func.addTag(.i32_mul);
44314431 try func.addTag(.i32_add);
44324432
......@@ -4466,13 +4466,13 @@ fn airTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44664466/// NOTE: Resulting value is left on the stack.
44674467fn trunc(func: *CodeGen, operand: WValue, wanted_ty: Type, given_ty: Type) InnerError!WValue {
44684468 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)));
44704470 if (toWasmBits(given_bits) == null) {
44714471 return func.fail("TODO: Implement wasm integer truncation for integer bitsize: {d}", .{given_bits});
44724472 }
44734473
44744474 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)));
44764476 const wasm_bits = toWasmBits(wanted_bits).?;
44774477 if (wasm_bits != wanted_bits) {
44784478 result = try func.wrapOperand(result, wanted_ty);
......@@ -4505,7 +4505,7 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45054505 }
45064506
45074507 // 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))) };
45094509 try func.store(slice_local, len, Type.usize, func.ptrSize());
45104510
45114511 func.finishAir(inst, slice_local, &.{ty_op.operand});
......@@ -4545,7 +4545,7 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45454545
45464546 // calculate index into slice
45474547 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)))));
45494549 try func.addTag(.i32_mul);
45504550 try func.addTag(.i32_add);
45514551
......@@ -4584,7 +4584,7 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45844584
45854585 // calculate index into ptr
45864586 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)))));
45884588 try func.addTag(.i32_mul);
45894589 try func.addTag(.i32_add);
45904590
......@@ -4612,7 +4612,7 @@ fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
46124612
46134613 try func.lowerToStack(ptr);
46144614 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))))));
46164616 try func.addTag(Mir.Inst.Tag.fromOpcode(mul_opcode));
46174617 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
46354635 const value = try func.resolveInst(bin_op.rhs);
46364636 const len = switch (ptr_ty.ptrSize(mod)) {
46374637 .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))) }),
46394639 .C, .Many => unreachable,
46404640 };
46414641
......@@ -4656,7 +4656,7 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
46564656/// we implement it manually.
46574657fn memset(func: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue) InnerError!void {
46584658 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
46614661 // When bulk_memory is enabled, we lower it to wasm's memset instruction.
46624662 // If not, we lower it ourselves.
......@@ -4756,7 +4756,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47564756 if (isByRef(array_ty, mod)) {
47574757 try func.lowerToStack(array);
47584758 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)))));
47604760 try func.addTag(.i32_mul);
47614761 try func.addTag(.i32_add);
47624762 } else {
......@@ -4772,11 +4772,11 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47724772 else => unreachable,
47734773 };
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
47774777 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));
47804780 try func.mir_extra.appendSlice(func.gpa, &operands);
47814781 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 {
47894789 // Is a non-unrolled vector (v128)
47904790 try func.lowerToStack(stack_vec);
47914791 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)))));
47934793 try func.addTag(.i32_mul);
47944794 try func.addTag(.i32_add);
47954795 },
......@@ -4886,7 +4886,7 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
48864886 const result = try func.allocLocal(ty);
48874887 try func.emitWValue(operand);
48884888 // 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));
48904890 // stores as := opcode, offset, alignment (opcode::memarg)
48914891 try func.mir_extra.appendSlice(func.gpa, &[_]u32{
48924892 opcode,
......@@ -4907,7 +4907,7 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49074907 };
49084908 const result = try func.allocLocal(ty);
49094909 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));
49114911 try func.mir_extra.append(func.gpa, opcode);
49124912 try func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });
49134913 try func.addLabel(.local_set, result.local.value);
......@@ -4917,13 +4917,13 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49174917 }
49184918 }
49194919 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)));
49214921 if ((!std.math.isPowerOfTwo(elem_size) or elem_size % 8 != 0) and vector_len > 1) {
49224922 return func.fail("TODO: WebAssembly `@splat` for arbitrary element bitsize {d}", .{elem_size});
49234923 }
49244924
49254925 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)));
49274927 var index: usize = 0;
49284928 var offset: u32 = 0;
49294929 while (index < vector_len) : (index += 1) {
......@@ -4966,11 +4966,11 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49664966 try func.emitWValue(result);
49674967
49684968 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)))
49704970 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)));
49744974 }
49754975
49764976 return func.finishAir(inst, result, &.{ extra.a, extra.b });
......@@ -4980,22 +4980,22 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49804980 } ++ [1]u32{undefined} ** 4;
49814981
49824982 var lanes = std.mem.asBytes(operands[1..]);
4983 for (0..@intCast(usize, mask_len)) |index| {
4983 for (0..@as(usize, @intCast(mask_len))) |index| {
49844984 const mask_elem = (try mask.elemValue(mod, index)).toSignedInt(mod);
49854985 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))
49874987 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| {
4991 lanes[index * @intCast(usize, elem_size) + byte_offset] = base_index + @intCast(u8, byte_offset);
4990 for (0..@as(usize, @intCast(elem_size))) |byte_offset| {
4991 lanes[index * @as(usize, @intCast(elem_size)) + byte_offset] = base_index + @as(u8, @intCast(byte_offset));
49924992 }
49934993 }
49944994
49954995 try func.emitWValue(a);
49964996 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));
49994999 try func.mir_extra.appendSlice(func.gpa, &operands);
50005000 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 {
50155015 const mod = func.bin_file.base.options.module.?;
50165016 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
50175017 const result_ty = func.typeOfIndex(inst);
5018 const len = @intCast(usize, result_ty.arrayLen(mod));
5019 const elements = @ptrCast([]const Air.Inst.Ref, func.air.extra[ty_pl.payload..][0..len]);
5018 const len = @as(usize, @intCast(result_ty.arrayLen(mod)));
5019 const elements = @as([]const Air.Inst.Ref, @ptrCast(func.air.extra[ty_pl.payload..][0..len]));
50205020
50215021 const result: WValue = result_value: {
50225022 switch (result_ty.zigTypeTag(mod)) {
50235023 .Array => {
50245024 const result = try func.allocStack(result_ty);
50255025 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)));
50275027 const sentinel = if (result_ty.sentinel(mod)) |sent| blk: {
50285028 break :blk try func.lowerConstant(sent, elem_ty);
50295029 } else null;
......@@ -5087,7 +5087,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50875087 WValue{ .imm64 = current_bit };
50885088
50895089 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)));
50915091 const int_ty = try mod.intType(.unsigned, value_bit_size);
50925092
50935093 // 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 {
51135113 if ((try result_ty.structFieldValueComptime(mod, elem_index)) != null) continue;
51145114
51155115 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)));
51175117 const value = try func.resolveInst(elem);
51185118 try func.store(offset, value, elem_ty, 0);
51195119
......@@ -5174,7 +5174,7 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51745174 const payload_ptr = try func.buildPointerOffset(result_ptr, layout.tag_size, .new);
51755175 try func.store(payload_ptr, payload, field.ty, 0);
51765176 } 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)));
51785178 }
51795179
51805180 if (layout.tag_size > 0) {
......@@ -5187,21 +5187,21 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51875187 result_ptr,
51885188 tag_int,
51895189 union_obj.tag_ty,
5190 @intCast(u32, layout.payload_size),
5190 @as(u32, @intCast(layout.payload_size)),
51915191 );
51925192 }
51935193 }
51945194 break :result result_ptr;
51955195 } else {
51965196 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))));
51985198 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))));
52005200 const bitcasted = try func.bitcast(field.ty, int_type, operand);
52015201 const casted = try func.trunc(bitcasted, int_type, union_int_type);
52025202 break :result try casted.toLocal(func, field.ty);
52035203 } 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))));
52055205 const casted = try func.intcast(operand, int_type, union_int_type);
52065206 break :result try casted.toLocal(func, field.ty);
52075207 }
......@@ -5334,7 +5334,7 @@ fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53345334 // when the tag alignment is smaller than the payload, the field will be stored
53355335 // after the payload.
53365336 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));
53385338 } else @as(u32, 0);
53395339 try func.store(union_ptr, new_tag, tag_ty, offset);
53405340 func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
......@@ -5353,7 +5353,7 @@ fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53535353 // when the tag alignment is smaller than the payload, the field will be stored
53545354 // after the payload.
53555355 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));
53575357 } else @as(u32, 0);
53585358 const tag = try func.load(operand, tag_ty, offset);
53595359 const result = try tag.toLocal(func, tag_ty);
......@@ -5458,7 +5458,7 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
54585458 operand,
54595459 .{ .imm32 = 0 },
54605460 Type.anyerror,
5461 @intCast(u32, errUnionErrorOffset(payload_ty, mod)),
5461 @as(u32, @intCast(errUnionErrorOffset(payload_ty, mod))),
54625462 );
54635463
54645464 const result = result: {
......@@ -5466,7 +5466,7 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
54665466 break :result func.reuseOperand(ty_op.operand, operand);
54675467 }
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);
54705470 };
54715471 func.finishAir(inst, result, &.{ty_op.operand});
54725472}
......@@ -5483,7 +5483,7 @@ fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54835483 const result = if (field_offset != 0) result: {
54845484 const base = try func.buildPointerOffset(field_ptr, 0, .new);
54855485 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)))));
54875487 try func.addTag(.i32_sub);
54885488 try func.addLabel(.local_set, base.local.value);
54895489 break :result base;
......@@ -5514,14 +5514,14 @@ fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
55145514 const slice_len = try func.sliceLen(dst);
55155515 if (ptr_elem_ty.abiSize(mod) != 1) {
55165516 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))) });
55185518 try func.addTag(.i32_mul);
55195519 try func.addLabel(.local_set, slice_len.local.value);
55205520 }
55215521 break :blk slice_len;
55225522 },
55235523 .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))),
55255525 }),
55265526 .C, .Many => unreachable,
55275527 };
......@@ -5611,7 +5611,7 @@ fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
56115611 try func.emitWValue(operand);
56125612 switch (func.arch()) {
56135613 .wasm32 => {
5614 try func.addImm32(@bitCast(i32, @intCast(u32, abi_size)));
5614 try func.addImm32(@as(i32, @bitCast(@as(u32, @intCast(abi_size)))));
56155615 try func.addTag(.i32_mul);
56165616 try func.addTag(.i32_add);
56175617 },
......@@ -5708,7 +5708,7 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro
57085708
57095709 const result_ptr = try func.allocStack(func.typeOfIndex(inst));
57105710 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)));
57125712 try func.store(result_ptr, overflow_local, Type.u1, offset);
57135713
57145714 func.finishAir(inst, result_ptr, &.{ extra.lhs, extra.rhs });
......@@ -5830,7 +5830,7 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58305830
58315831 const result_ptr = try func.allocStack(func.typeOfIndex(inst));
58325832 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)));
58345834 try func.store(result_ptr, overflow_local, Type.u1, offset);
58355835
58365836 func.finishAir(inst, result_ptr, &.{ extra.lhs, extra.rhs });
......@@ -6005,7 +6005,7 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
60056005
60066006 const result_ptr = try func.allocStack(func.typeOfIndex(inst));
60076007 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)));
60096009 try func.store(result_ptr, overflow_bit, Type.u1, offset);
60106010
60116011 func.finishAir(inst, result_ptr, &.{ extra.lhs, extra.rhs });
......@@ -6149,7 +6149,7 @@ fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
61496149 switch (wasm_bits) {
61506150 32 => {
61516151 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));
61536153 // leave value on the stack
61546154 _ = try func.binOp(operand, .{ .imm32 = val }, ty, .@"or");
61556155 } else try func.emitWValue(operand);
......@@ -6157,7 +6157,7 @@ fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
61576157 },
61586158 64 => {
61596159 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));
61616161 // leave value on the stack
61626162 _ = try func.binOp(operand, .{ .imm64 = val }, ty, .@"or");
61636163 } else try func.emitWValue(operand);
......@@ -6172,7 +6172,7 @@ fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
61726172 try func.addTag(.i64_ctz);
61736173 _ = try func.load(operand, Type.u64, 8);
61746174 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)));
61766176 try func.addTag(.i64_or);
61776177 }
61786178 try func.addTag(.i64_ctz);
......@@ -6275,7 +6275,7 @@ fn lowerTry(
62756275 // check if the error tag is set for the error union.
62766276 try func.emitWValue(err_union);
62776277 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)));
62796279 try func.addMemArg(.i32_load16_u, .{
62806280 .offset = err_union.offset() + err_offset,
62816281 .alignment = Type.anyerror.abiAlignment(mod),
......@@ -6300,7 +6300,7 @@ fn lowerTry(
63006300 return WValue{ .none = {} };
63016301 }
63026302
6303 const pl_offset = @intCast(u32, errUnionPayloadOffset(pl_ty, mod));
6303 const pl_offset = @as(u32, @intCast(errUnionPayloadOffset(pl_ty, mod)));
63046304 if (isByRef(pl_ty, mod)) {
63056305 return buildPointerOffset(func, err_union, pl_offset, .new);
63066306 }
......@@ -6590,9 +6590,9 @@ fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
65906590 var bin_result = try (try func.binOp(lhs, rhs, ty, op)).toLocal(func, ty);
65916591 defer bin_result.free(func);
65926592 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));
65946594 const imm_val = switch (wasm_bits) {
6595 32 => WValue{ .imm32 = @intCast(u32, val) },
6595 32 => WValue{ .imm32 = @as(u32, @intCast(val)) },
65966596 64 => WValue{ .imm64 = val },
65976597 else => unreachable,
65986598 };
......@@ -6603,7 +6603,7 @@ fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
66036603 } else {
66046604 switch (wasm_bits) {
66056605 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),
66076607 else => unreachable,
66086608 }
66096609 try func.emitWValue(bin_result);
......@@ -6629,16 +6629,16 @@ fn signedSat(func: *CodeGen, lhs_operand: WValue, rhs_operand: WValue, ty: Type,
66296629 break :rhs try (try func.signAbsValue(rhs_operand, ty)).toLocal(func, ty);
66306630 } else rhs_operand;
66316631
6632 const max_val: u64 = @intCast(u64, (@as(u65, 1) << @intCast(u7, int_info.bits - 1)) - 1);
6633 const min_val: i64 = (-@intCast(i64, @intCast(u63, max_val))) - 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 = (-@as(i64, @intCast(@as(u63, @intCast(max_val))))) - 1;
66346634 const max_wvalue = switch (wasm_bits) {
6635 32 => WValue{ .imm32 = @truncate(u32, max_val) },
6635 32 => WValue{ .imm32 = @as(u32, @truncate(max_val)) },
66366636 64 => WValue{ .imm64 = max_val },
66376637 else => unreachable,
66386638 };
66396639 const min_wvalue = switch (wasm_bits) {
6640 32 => WValue{ .imm32 = @bitCast(u32, @truncate(i32, min_val)) },
6641 64 => WValue{ .imm64 = @bitCast(u64, min_val) },
6640 32 => WValue{ .imm32 = @as(u32, @bitCast(@as(i32, @truncate(min_val)))) },
6641 64 => WValue{ .imm64 = @as(u64, @bitCast(min_val)) },
66426642 else => unreachable,
66436643 };
66446644
......@@ -6715,11 +6715,11 @@ fn airShlSat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
67156715 },
67166716 64 => blk: {
67176717 if (!is_signed) {
6718 try func.addImm64(@bitCast(u64, @as(i64, -1)));
6718 try func.addImm64(@as(u64, @bitCast(@as(i64, -1))));
67196719 break :blk;
67206720 }
6721 try func.addImm64(@bitCast(u64, @as(i64, std.math.minInt(i64))));
6722 try func.addImm64(@bitCast(u64, @as(i64, std.math.maxInt(i64))));
6721 try func.addImm64(@as(u64, @bitCast(@as(i64, std.math.minInt(i64)))));
6722 try func.addImm64(@as(u64, @bitCast(@as(i64, std.math.maxInt(i64)))));
67236723 _ = try func.cmp(lhs, .{ .imm64 = 0 }, ty, .lt);
67246724 try func.addTag(.select);
67256725 },
......@@ -6759,12 +6759,12 @@ fn airShlSat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
67596759 },
67606760 64 => blk: {
67616761 if (!is_signed) {
6762 try func.addImm64(@bitCast(u64, @as(i64, -1)));
6762 try func.addImm64(@as(u64, @bitCast(@as(i64, -1))));
67636763 break :blk;
67646764 }
67656765
6766 try func.addImm64(@bitCast(u64, @as(i64, std.math.minInt(i64))));
6767 try func.addImm64(@bitCast(u64, @as(i64, std.math.maxInt(i64))));
6766 try func.addImm64(@as(u64, @bitCast(@as(i64, std.math.minInt(i64)))));
6767 try func.addImm64(@as(u64, @bitCast(@as(i64, std.math.maxInt(i64)))));
67686768 _ = try func.cmp(shl_res, .{ .imm64 = 0 }, ty, .lt);
67696769 try func.addTag(.select);
67706770 },
......@@ -6894,7 +6894,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
68946894 // TODO: Make switch implementation generic so we can use a jump table for this when the tags are not sparse.
68956895 // generate an if-else chain for each tag value as well as constant.
68966896 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));
68986898 const tag_name = mod.intern_pool.stringToSlice(tag_name_ip);
68996899 // for each tag name, create an unnamed const,
69006900 // and then get a pointer to its value.
......@@ -6953,7 +6953,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
69536953 try writer.writeByte(std.wasm.opcode(.i32_const));
69546954 try relocs.append(.{
69556955 .relocation_type = .R_WASM_MEMORY_ADDR_LEB,
6956 .offset = @intCast(u32, body_list.items.len),
6956 .offset = @as(u32, @intCast(body_list.items.len)),
69576957 .index = tag_sym_index,
69586958 });
69596959 try writer.writeAll(&[_]u8{0} ** 5); // will be relocated
......@@ -6965,7 +6965,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
69656965
69666966 // store length
69676967 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)));
69696969 try writer.writeByte(std.wasm.opcode(.i32_store));
69706970 try leb.writeULEB128(writer, encoded_alignment);
69716971 try leb.writeULEB128(writer, @as(u32, 4));
......@@ -6974,7 +6974,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
69746974 try writer.writeByte(std.wasm.opcode(.i64_const));
69756975 try relocs.append(.{
69766976 .relocation_type = .R_WASM_MEMORY_ADDR_LEB64,
6977 .offset = @intCast(u32, body_list.items.len),
6977 .offset = @as(u32, @intCast(body_list.items.len)),
69786978 .index = tag_sym_index,
69796979 });
69806980 try writer.writeAll(&[_]u8{0} ** 10); // will be relocated
......@@ -6986,7 +6986,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
69866986
69876987 // store length
69886988 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)));
69906990 try writer.writeByte(std.wasm.opcode(.i64_store));
69916991 try leb.writeULEB128(writer, encoded_alignment);
69926992 try leb.writeULEB128(writer, @as(u32, 8));
......@@ -7026,7 +7026,7 @@ fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
70267026 var lowest: ?u32 = null;
70277027 var highest: ?u32 = null;
70287028 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).?));
70307030 if (lowest) |*l| {
70317031 if (err_int < l.*) {
70327032 l.* = err_int;
......@@ -7054,11 +7054,11 @@ fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
70547054
70557055 // lower operand to determine jump table target
70567056 try func.emitWValue(operand);
7057 try func.addImm32(@intCast(i32, lowest.?));
7057 try func.addImm32(@as(i32, @intCast(lowest.?)));
70587058 try func.addTag(.i32_sub);
70597059
70607060 // 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));
70627062 const jump_table: Mir.JumpTable = .{ .length = depth };
70637063 const table_extra_index = try func.addExtra(jump_table);
70647064 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 {
71557155 try func.addTag(.i32_and);
71567156 const and_result = try WValue.toLocal(.stack, func, Type.bool);
71577157 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))));
71597159 try func.store(result_ptr, ptr_val, ty, 0);
71607160 break :val result_ptr;
71617161 } else val: {
......@@ -7221,13 +7221,13 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
72217221 try func.emitWValue(ptr);
72227222 try func.emitWValue(value);
72237223 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
72267226 const and_res = try func.binOp(value, operand, ty, .@"and");
72277227 if (wasm_bits == 32)
72287228 try func.addImm32(-1)
72297229 else if (wasm_bits == 64)
7230 try func.addImm64(@bitCast(u64, @as(i64, -1)))
7230 try func.addImm64(@as(u64, @bitCast(@as(i64, -1))))
72317231 else
72327232 return func.fail("TODO: `@atomicRmw` with operator `Nand` for types larger than 64 bits", .{});
72337233 _ = try func.binOp(and_res, .stack, ty, .xor);
......@@ -7352,14 +7352,14 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
73527352 try func.store(.stack, .stack, ty, ptr.offset());
73537353 },
73547354 .Nand => {
7355 const wasm_bits = toWasmBits(@intCast(u16, ty.bitSize(mod))).?;
7355 const wasm_bits = toWasmBits(@as(u16, @intCast(ty.bitSize(mod)))).?;
73567356
73577357 try func.emitWValue(ptr);
73587358 const and_res = try func.binOp(result, operand, ty, .@"and");
73597359 if (wasm_bits == 32)
73607360 try func.addImm32(-1)
73617361 else if (wasm_bits == 64)
7362 try func.addImm64(@bitCast(u64, @as(i64, -1)))
7362 try func.addImm64(@as(u64, @bitCast(@as(i64, -1))))
73637363 else
73647364 return func.fail("TODO: `@atomicRmw` with operator `Nand` for types larger than 64 bits", .{});
73657365 _ = 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 {
4545 try emit.emitLocals();
4646
4747 for (mir_tags, 0..) |tag, index| {
48 const inst = @intCast(u32, index);
48 const inst = @as(u32, @intCast(index));
4949 switch (tag) {
5050 // block instructions
5151 .block => try emit.emitBlock(tag, inst),
......@@ -247,7 +247,7 @@ pub fn emitMir(emit: *Emit) InnerError!void {
247247}
248248
249249fn offset(self: Emit) u32 {
250 return @intCast(u32, self.code.items.len);
250 return @as(u32, @intCast(self.code.items.len));
251251}
252252
253253fn 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
261261fn emitLocals(emit: *Emit) !void {
262262 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)));
264264 // emit the actual locals amount
265265 for (emit.locals) |local| {
266266 try leb128.writeULEB128(writer, @as(u32, 1));
......@@ -324,13 +324,13 @@ fn emitImm64(emit: *Emit, inst: Mir.Inst.Index) !void {
324324 const extra_index = emit.mir.instructions.items(.data)[inst].payload;
325325 const value = emit.mir.extraData(Mir.Imm64, extra_index);
326326 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())));
328328}
329329
330330fn emitFloat32(emit: *Emit, inst: Mir.Inst.Index) !void {
331331 const value: f32 = emit.mir.instructions.items(.data)[inst].float32;
332332 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)));
334334}
335335
336336fn emitFloat64(emit: *Emit, inst: Mir.Inst.Index) !void {
......@@ -425,7 +425,7 @@ fn emitMemAddress(emit: *Emit, inst: Mir.Inst.Index) !void {
425425 .offset = mem_offset,
426426 .index = mem.pointer,
427427 .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)),
429429 });
430430 }
431431}
......@@ -436,7 +436,7 @@ fn emitExtended(emit: *Emit, inst: Mir.Inst.Index) !void {
436436 const writer = emit.code.writer();
437437 try emit.code.append(std.wasm.opcode(.misc_prefix));
438438 try leb128.writeULEB128(writer, opcode);
439 switch (@enumFromInt(std.wasm.MiscOpcode, opcode)) {
439 switch (@as(std.wasm.MiscOpcode, @enumFromInt(opcode))) {
440440 // bulk-memory opcodes
441441 .data_drop => {
442442 const segment = emit.mir.extra[extra_index + 1];
......@@ -475,7 +475,7 @@ fn emitSimd(emit: *Emit, inst: Mir.Inst.Index) !void {
475475 const writer = emit.code.writer();
476476 try emit.code.append(std.wasm.opcode(.simd_prefix));
477477 try leb128.writeULEB128(writer, opcode);
478 switch (@enumFromInt(std.wasm.SimdOpcode, opcode)) {
478 switch (@as(std.wasm.SimdOpcode, @enumFromInt(opcode))) {
479479 .v128_store,
480480 .v128_load,
481481 .v128_load8_splat,
......@@ -507,7 +507,7 @@ fn emitSimd(emit: *Emit, inst: Mir.Inst.Index) !void {
507507 .f64x2_extract_lane,
508508 .f64x2_replace_lane,
509509 => {
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])));
511511 },
512512 .i8x16_splat,
513513 .i16x8_splat,
......@@ -526,7 +526,7 @@ fn emitAtomic(emit: *Emit, inst: Mir.Inst.Index) !void {
526526 const writer = emit.code.writer();
527527 try emit.code.append(std.wasm.opcode(.atomics_prefix));
528528 try leb128.writeULEB128(writer, opcode);
529 switch (@enumFromInt(std.wasm.AtomicsOpcode, opcode)) {
529 switch (@as(std.wasm.AtomicsOpcode, @enumFromInt(opcode))) {
530530 .i32_atomic_load,
531531 .i64_atomic_load,
532532 .i32_atomic_load8_u,
......@@ -623,7 +623,7 @@ fn emitDbgLine(emit: *Emit, inst: Mir.Inst.Index) !void {
623623fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) !void {
624624 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));
627627 const delta_pc = emit.offset() - emit.prev_di_offset;
628628 // TODO: This must emit a relocation to calculate the offset relative
629629 // to the code section start.
src/arch/wasm/Mir.zig+8-8
......@@ -544,12 +544,12 @@ pub const Inst = struct {
544544
545545 /// From a given wasm opcode, returns a MIR tag.
546546 pub fn fromOpcode(opcode: std.wasm.Opcode) Tag {
547 return @enumFromInt(Tag, @intFromEnum(opcode)); // Given `Opcode` is not present as a tag for MIR yet
547 return @as(Tag, @enumFromInt(@intFromEnum(opcode))); // Given `Opcode` is not present as a tag for MIR yet
548548 }
549549
550550 /// Returns a wasm opcode from a given MIR tag.
551551 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)));
553553 }
554554 };
555555
......@@ -621,8 +621,8 @@ pub const Imm64 = struct {
621621
622622 pub fn fromU64(imm: u64) Imm64 {
623623 return .{
624 .msb = @truncate(u32, imm >> 32),
625 .lsb = @truncate(u32, imm),
624 .msb = @as(u32, @truncate(imm >> 32)),
625 .lsb = @as(u32, @truncate(imm)),
626626 };
627627 }
628628
......@@ -639,15 +639,15 @@ pub const Float64 = struct {
639639 lsb: u32,
640640
641641 pub fn fromFloat64(float: f64) Float64 {
642 const tmp = @bitCast(u64, float);
642 const tmp = @as(u64, @bitCast(float));
643643 return .{
644 .msb = @truncate(u32, tmp >> 32),
645 .lsb = @truncate(u32, tmp),
644 .msb = @as(u32, @truncate(tmp >> 32)),
645 .lsb = @as(u32, @truncate(tmp)),
646646 };
647647 }
648648
649649 pub fn toF64(self: Float64) f64 {
650 @bitCast(f64, self.toU64());
650 @as(f64, @bitCast(self.toU64()));
651651 }
652652
653653 pub fn toU64(self: Float64) u64 {
src/arch/x86_64/CodeGen.zig+229-229
......@@ -329,7 +329,7 @@ pub const MCValue = union(enum) {
329329 .load_frame,
330330 .reserved_frame,
331331 => 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)) },
333333 .register => |reg| .{ .register_offset = .{ .reg = reg, .off = off } },
334334 .register_offset => |reg_off| .{
335335 .register_offset = .{ .reg = reg_off.reg, .off = reg_off.off + off },
......@@ -360,7 +360,7 @@ pub const MCValue = union(enum) {
360360 .lea_frame,
361361 .reserved_frame,
362362 => 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|
364364 Memory.sib(ptr_size, .{ .base = .{ .reg = .ds }, .disp = small_addr })
365365 else
366366 Memory.moffs(.ds, addr),
......@@ -606,7 +606,7 @@ const FrameAlloc = struct {
606606 fn init(alloc_abi: struct { size: u64, alignment: u32 }) FrameAlloc {
607607 assert(math.isPowerOfTwo(alloc_abi.alignment));
608608 return .{
609 .abi_size = @intCast(u31, alloc_abi.size),
609 .abi_size = @as(u31, @intCast(alloc_abi.size)),
610610 .abi_align = math.log2_int(u32, alloc_abi.alignment),
611611 .ref_count = 0,
612612 };
......@@ -694,7 +694,7 @@ pub fn generate(
694694 FrameAlloc.init(.{
695695 .size = 0,
696696 .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().?))
698698 else
699699 1,
700700 }),
......@@ -979,7 +979,7 @@ fn fmtTracking(self: *Self) std.fmt.Formatter(formatTracking) {
979979fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
980980 const gpa = self.gpa;
981981 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));
983983 self.mir_instructions.appendAssumeCapacity(inst);
984984 if (inst.tag != .pseudo or switch (inst.ops) {
985985 else => true,
......@@ -1000,11 +1000,11 @@ fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {
10001000
10011001fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
10021002 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));
10041004 inline for (fields) |field| {
10051005 self.mir_extra.appendAssumeCapacity(switch (field.type) {
10061006 u32 => @field(extra, field.name),
1007 i32 => @bitCast(u32, @field(extra, field.name)),
1007 i32 => @as(u32, @bitCast(@field(extra, field.name))),
10081008 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
10091009 });
10101010 }
......@@ -1214,8 +1214,8 @@ fn asmImmediate(self: *Self, tag: Mir.Inst.FixedTag, imm: Immediate) !void {
12141214 .data = .{ .i = .{
12151215 .fixes = tag[0],
12161216 .i = switch (imm) {
1217 .signed => |s| @bitCast(u32, s),
1218 .unsigned => |u| @intCast(u32, u),
1217 .signed => |s| @as(u32, @bitCast(s)),
1218 .unsigned => |u| @as(u32, @intCast(u)),
12191219 },
12201220 } },
12211221 });
......@@ -1246,8 +1246,8 @@ fn asmRegisterImmediate(self: *Self, tag: Mir.Inst.FixedTag, reg: Register, imm:
12461246 .fixes = tag[0],
12471247 .r1 = reg,
12481248 .i = switch (imm) {
1249 .signed => |s| @bitCast(u32, s),
1250 .unsigned => |u| @intCast(u32, u),
1249 .signed => |s| @as(u32, @bitCast(s)),
1250 .unsigned => |u| @as(u32, @intCast(u)),
12511251 },
12521252 } },
12531253 .ri64 => .{ .rx = .{
......@@ -1316,7 +1316,7 @@ fn asmRegisterRegisterRegisterImmediate(
13161316 .r1 = reg1,
13171317 .r2 = reg2,
13181318 .r3 = reg3,
1319 .i = @intCast(u8, imm.unsigned),
1319 .i = @as(u8, @intCast(imm.unsigned)),
13201320 } },
13211321 });
13221322}
......@@ -1339,8 +1339,8 @@ fn asmRegisterRegisterImmediate(
13391339 .r1 = reg1,
13401340 .r2 = reg2,
13411341 .i = switch (imm) {
1342 .signed => |s| @bitCast(u32, s),
1343 .unsigned => |u| @intCast(u32, u),
1342 .signed => |s| @as(u32, @bitCast(s)),
1343 .unsigned => |u| @as(u32, @intCast(u)),
13441344 },
13451345 } },
13461346 });
......@@ -1429,7 +1429,7 @@ fn asmRegisterMemoryImmediate(
14291429 .data = .{ .rix = .{
14301430 .fixes = tag[0],
14311431 .r1 = reg,
1432 .i = @intCast(u8, imm.unsigned),
1432 .i = @as(u8, @intCast(imm.unsigned)),
14331433 .payload = switch (m) {
14341434 .sib => try self.addExtra(Mir.MemorySib.encode(m)),
14351435 .rip => try self.addExtra(Mir.MemoryRip.encode(m)),
......@@ -1458,7 +1458,7 @@ fn asmRegisterRegisterMemoryImmediate(
14581458 .fixes = tag[0],
14591459 .r1 = reg1,
14601460 .r2 = reg2,
1461 .i = @intCast(u8, imm.unsigned),
1461 .i = @as(u8, @intCast(imm.unsigned)),
14621462 .payload = switch (m) {
14631463 .sib => try self.addExtra(Mir.MemorySib.encode(m)),
14641464 .rip => try self.addExtra(Mir.MemoryRip.encode(m)),
......@@ -1490,8 +1490,8 @@ fn asmMemoryRegister(self: *Self, tag: Mir.Inst.FixedTag, m: Memory, reg: Regist
14901490
14911491fn asmMemoryImmediate(self: *Self, tag: Mir.Inst.FixedTag, m: Memory, imm: Immediate) !void {
14921492 const payload = try self.addExtra(Mir.Imm32{ .imm = switch (imm) {
1493 .signed => |s| @bitCast(u32, s),
1494 .unsigned => |u| @intCast(u32, u),
1493 .signed => |s| @as(u32, @bitCast(s)),
1494 .unsigned => |u| @as(u32, @intCast(u)),
14951495 } });
14961496 assert(payload + 1 == switch (m) {
14971497 .sib => try self.addExtra(Mir.MemorySib.encode(m)),
......@@ -1562,7 +1562,7 @@ fn asmMemoryRegisterImmediate(
15621562 .data = .{ .rix = .{
15631563 .fixes = tag[0],
15641564 .r1 = reg,
1565 .i = @intCast(u8, imm.unsigned),
1565 .i = @as(u8, @intCast(imm.unsigned)),
15661566 .payload = switch (m) {
15671567 .sib => try self.addExtra(Mir.MemorySib.encode(m)),
15681568 .rip => try self.addExtra(Mir.MemoryRip.encode(m)),
......@@ -1617,7 +1617,7 @@ fn gen(self: *Self) InnerError!void {
16171617 // Eliding the reloc will cause a miscompilation in this case.
16181618 for (self.exitlude_jump_relocs.items) |jmp_reloc| {
16191619 self.mir_instructions.items(.data)[jmp_reloc].inst.inst =
1620 @intCast(u32, self.mir_instructions.len);
1620 @as(u32, @intCast(self.mir_instructions.len));
16211621 }
16221622
16231623 try self.asmPseudo(.pseudo_dbg_epilogue_begin_none);
......@@ -1739,7 +1739,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
17391739
17401740 for (body) |inst| {
17411741 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));
17431743 try self.mir_to_air_map.put(self.gpa, mir_inst, inst);
17441744 }
17451745
......@@ -2032,7 +2032,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {
20322032
20332033 var data_off: i32 = 0;
20342034 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));
20362036 const tag_name = mod.intern_pool.stringToSlice(enum_ty.enumFields(mod)[index_usize]);
20372037 const tag_val = try mod.enumValueFieldIndex(enum_ty, index);
20382038 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 {
20502050 exitlude_jump_reloc.* = try self.asmJmpReloc(undefined);
20512051 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));
20542054 }
20552055
20562056 try self.airTrap();
......@@ -2126,7 +2126,7 @@ fn finishAirResult(self: *Self, inst: Air.Inst.Index, result: MCValue) void {
21262126fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void {
21272127 var tomb_bits = self.liveness.getTombBits(inst);
21282128 for (operands) |op| {
2129 const dies = @truncate(u1, tomb_bits) != 0;
2129 const dies = @as(u1, @truncate(tomb_bits)) != 0;
21302130 tomb_bits >>= 1;
21312131 if (!dies) continue;
21322132 self.processDeath(Air.refToIndexAllowNone(op) orelse continue);
......@@ -2167,7 +2167,7 @@ fn computeFrameLayout(self: *Self) !FrameLayout {
21672167 const frame_offset = self.frame_locs.items(.disp);
21682168
21692169 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));
21712171 {
21722172 const SortContext = struct {
21732173 frame_align: @TypeOf(frame_align),
......@@ -2195,7 +2195,7 @@ fn computeFrameLayout(self: *Self) !FrameLayout {
21952195 }
21962196 }
21972197
2198 var rbp_offset = @intCast(i32, save_reg_list.count() * 8);
2198 var rbp_offset = @as(i32, @intCast(save_reg_list.count() * 8));
21992199 self.setFrameLoc(.base_ptr, .rbp, &rbp_offset, false);
22002200 self.setFrameLoc(.ret_addr, .rbp, &rbp_offset, false);
22012201 self.setFrameLoc(.args_frame, .rbp, &rbp_offset, false);
......@@ -2210,22 +2210,22 @@ fn computeFrameLayout(self: *Self) !FrameLayout {
22102210 rsp_offset = mem.alignForward(i32, rsp_offset, @as(i32, 1) << needed_align);
22112211 rsp_offset -= stack_frame_align_offset;
22122212 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
22152215 return .{
22162216 .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)])),
22182218 .save_reg_list = save_reg_list,
22192219 };
22202220}
22212221
22222222fn getFrameAddrAlignment(self: *Self, frame_addr: FrameAddr) u32 {
22232223 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));
22252225}
22262226
22272227fn 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));
22292229}
22302230
22312231fn allocFrameIndex(self: *Self, alloc: FrameAlloc) !FrameIndex {
......@@ -2245,7 +2245,7 @@ fn allocFrameIndex(self: *Self, alloc: FrameAlloc) !FrameIndex {
22452245 _ = self.free_frame_indices.swapRemoveAt(free_i);
22462246 return frame_index;
22472247 }
2248 const frame_index = @enumFromInt(FrameIndex, self.frame_allocs.len);
2248 const frame_index = @as(FrameIndex, @enumFromInt(self.frame_allocs.len));
22492249 try self.frame_allocs.append(self.gpa, alloc);
22502250 return frame_index;
22512251}
......@@ -2321,7 +2321,7 @@ const State = struct {
23212321
23222322fn initRetroactiveState(self: *Self) State {
23232323 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()));
23252325 state.scope_generation = self.scope_generation;
23262326 return state;
23272327}
......@@ -2393,7 +2393,7 @@ fn restoreState(self: *Self, state: State, deaths: []const Air.Inst.Index, compt
23932393 }
23942394 {
23952395 const reg = RegisterManager.regAtTrackedIndex(
2396 @intCast(RegisterManager.RegisterBitSet.ShiftInt, index),
2396 @as(RegisterManager.RegisterBitSet.ShiftInt, @intCast(index)),
23972397 );
23982398 self.register_manager.freeReg(reg);
23992399 self.register_manager.getRegAssumeFree(reg, target_maybe_inst);
......@@ -2628,7 +2628,7 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
26282628
26292629 const dst_ty = self.typeOfIndex(inst);
26302630 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
26332633 const min_ty = if (dst_int_info.bits < src_int_info.bits) dst_ty else src_ty;
26342634 const extend = switch (src_int_info.signedness) {
......@@ -2706,9 +2706,9 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
27062706 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
27072707
27082708 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)));
27102710 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
27132713 const result = result: {
27142714 const src_mcv = try self.resolveInst(ty_op.operand);
......@@ -2753,13 +2753,13 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
27532753 });
27542754
27552755 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
27582758 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))),
27602760 .child = elem_ty.ip_index,
27612761 });
2762 const splat_abi_size = @intCast(u32, splat_ty.abiSize(mod));
2762 const splat_abi_size = @as(u32, @intCast(splat_ty.abiSize(mod)));
27632763
27642764 const splat_val = try mod.intern(.{ .aggregate = .{
27652765 .ty = splat_ty.ip_index,
......@@ -2834,7 +2834,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
28342834 try self.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr);
28352835 try self.genSetMem(
28362836 .{ .frame = frame_index },
2837 @intCast(i32, ptr_ty.abiSize(mod)),
2837 @as(i32, @intCast(ptr_ty.abiSize(mod))),
28382838 len_ty,
28392839 len,
28402840 );
......@@ -2875,7 +2875,7 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
28752875 const src_val = air_data[inst].interned.toValue();
28762876 var space: Value.BigIntSpace = undefined;
28772877 const src_int = src_val.toBigInt(&space, mod);
2878 return @intCast(u16, src_int.bitCountTwosComp()) +
2878 return @as(u16, @intCast(src_int.bitCountTwosComp())) +
28792879 @intFromBool(src_int.positive and dst_info.signedness == .signed);
28802880 },
28812881 .intcast => {
......@@ -2964,7 +2964,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
29642964 try self.genSetReg(limit_reg, ty, dst_mcv);
29652965 try self.genShiftBinOpMir(.{ ._r, .sa }, ty, limit_mcv, .{ .immediate = reg_bits - 1 });
29662966 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,
29682968 });
29692969 if (reg_extra_bits > 0) {
29702970 const shifted_rhs_reg = try self.copyToTmpRegister(ty, rhs_mcv);
......@@ -2983,7 +2983,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
29832983 break :cc .o;
29842984 } else cc: {
29852985 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))),
29872987 });
29882988
29892989 try self.genBinOpMir(.{ ._, .add }, ty, dst_mcv, rhs_mcv);
......@@ -2994,7 +2994,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
29942994 break :cc .c;
29952995 };
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);
29982998 try self.asmCmovccRegisterRegister(
29992999 registerAlias(dst_reg, cmov_abi_size),
30003000 registerAlias(limit_reg, cmov_abi_size),
......@@ -3043,7 +3043,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
30433043 try self.genSetReg(limit_reg, ty, dst_mcv);
30443044 try self.genShiftBinOpMir(.{ ._r, .sa }, ty, limit_mcv, .{ .immediate = reg_bits - 1 });
30453045 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,
30473047 });
30483048 if (reg_extra_bits > 0) {
30493049 const shifted_rhs_reg = try self.copyToTmpRegister(ty, rhs_mcv);
......@@ -3066,7 +3066,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
30663066 break :cc .c;
30673067 };
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);
30703070 try self.asmCmovccRegisterRegister(
30713071 registerAlias(dst_reg, cmov_abi_size),
30723072 registerAlias(limit_reg, cmov_abi_size),
......@@ -3114,18 +3114,18 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
31143114 try self.genBinOpMir(.{ ._, .xor }, ty, limit_mcv, rhs_mcv);
31153115 try self.genShiftBinOpMir(.{ ._, .sa }, ty, limit_mcv, .{ .immediate = reg_bits - 1 });
31163116 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,
31183118 });
31193119 break :cc .o;
31203120 } else cc: {
31213121 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)),
31233123 });
31243124 break :cc .c;
31253125 };
31263126
31273127 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);
31293129 try self.asmCmovccRegisterRegister(
31303130 registerAlias(dst_mcv.register, cmov_abi_size),
31313131 registerAlias(limit_reg, cmov_abi_size),
......@@ -3172,13 +3172,13 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
31723172 try self.allocFrameIndex(FrameAlloc.initType(tuple_ty, mod));
31733173 try self.genSetMem(
31743174 .{ .frame = frame_index },
3175 @intCast(i32, tuple_ty.structFieldOffset(1, mod)),
3175 @as(i32, @intCast(tuple_ty.structFieldOffset(1, mod))),
31763176 Type.u1,
31773177 .{ .eflags = cc },
31783178 );
31793179 try self.genSetMem(
31803180 .{ .frame = frame_index },
3181 @intCast(i32, tuple_ty.structFieldOffset(0, mod)),
3181 @as(i32, @intCast(tuple_ty.structFieldOffset(0, mod))),
31823182 ty,
31833183 partial_mcv,
31843184 );
......@@ -3245,13 +3245,13 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
32453245 try self.allocFrameIndex(FrameAlloc.initType(tuple_ty, mod));
32463246 try self.genSetMem(
32473247 .{ .frame = frame_index },
3248 @intCast(i32, tuple_ty.structFieldOffset(1, mod)),
3248 @as(i32, @intCast(tuple_ty.structFieldOffset(1, mod))),
32493249 tuple_ty.structFieldType(1, mod),
32503250 .{ .eflags = cc },
32513251 );
32523252 try self.genSetMem(
32533253 .{ .frame = frame_index },
3254 @intCast(i32, tuple_ty.structFieldOffset(0, mod)),
3254 @as(i32, @intCast(tuple_ty.structFieldOffset(0, mod))),
32553255 tuple_ty.structFieldType(0, mod),
32563256 partial_mcv,
32573257 );
......@@ -3319,7 +3319,7 @@ fn genSetFrameTruncatedOverflowCompare(
33193319 );
33203320 }
33213321
3322 const payload_off = @intCast(i32, tuple_ty.structFieldOffset(0, mod));
3322 const payload_off = @as(i32, @intCast(tuple_ty.structFieldOffset(0, mod)));
33233323 if (hi_limb_off > 0) try self.genSetMem(.{ .frame = frame_index }, payload_off, rest_ty, src_mcv);
33243324 try self.genSetMem(
33253325 .{ .frame = frame_index },
......@@ -3329,7 +3329,7 @@ fn genSetFrameTruncatedOverflowCompare(
33293329 );
33303330 try self.genSetMem(
33313331 .{ .frame = frame_index },
3332 @intCast(i32, tuple_ty.structFieldOffset(1, mod)),
3332 @as(i32, @intCast(tuple_ty.structFieldOffset(1, mod))),
33333333 tuple_ty.structFieldType(1, mod),
33343334 if (overflow_cc) |_| .{ .register = overflow_reg.to8() } else .{ .eflags = .ne },
33353335 );
......@@ -3386,13 +3386,13 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
33863386 if (dst_info.bits >= lhs_active_bits + rhs_active_bits) {
33873387 try self.genSetMem(
33883388 .{ .frame = frame_index },
3389 @intCast(i32, tuple_ty.structFieldOffset(0, mod)),
3389 @as(i32, @intCast(tuple_ty.structFieldOffset(0, mod))),
33903390 tuple_ty.structFieldType(0, mod),
33913391 partial_mcv,
33923392 );
33933393 try self.genSetMem(
33943394 .{ .frame = frame_index },
3395 @intCast(i32, tuple_ty.structFieldOffset(1, mod)),
3395 @as(i32, @intCast(tuple_ty.structFieldOffset(1, mod))),
33963396 tuple_ty.structFieldType(1, mod),
33973397 .{ .immediate = 0 }, // cc being set is impossible
33983398 );
......@@ -3416,7 +3416,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
34163416/// Quotient is saved in .rax and remainder in .rdx.
34173417fn genIntMulDivOpMir(self: *Self, tag: Mir.Inst.FixedTag, ty: Type, lhs: MCValue, rhs: MCValue) !void {
34183418 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)));
34203420 if (abi_size > 8) {
34213421 return self.fail("TODO implement genIntMulDivOpMir for ABI size larger than 8", .{});
34223422 }
......@@ -3456,7 +3456,7 @@ fn genIntMulDivOpMir(self: *Self, tag: Mir.Inst.FixedTag, ty: Type, lhs: MCValue
34563456/// Clobbers .rax and .rdx registers.
34573457fn genInlineIntDivFloor(self: *Self, ty: Type, lhs: MCValue, rhs: MCValue) !MCValue {
34583458 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)));
34603460 const int_info = ty.intInfo(mod);
34613461 const dividend: Register = switch (lhs) {
34623462 .register => |reg| reg,
......@@ -3595,7 +3595,7 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
35953595 try self.copyToRegisterWithInstTracking(inst, dst_ty, src_mcv);
35963596
35973597 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)));
35993599 try self.genSetMem(.{ .reg = dst_mcv.getReg().? }, pl_abi_size, Type.bool, .{ .immediate = 1 });
36003600 break :result if (self.liveness.isUnused(inst)) .unreach else dst_mcv;
36013601 };
......@@ -3628,7 +3628,7 @@ fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
36283628
36293629 const result = try self.copyToRegisterWithInstTracking(inst, err_union_ty, operand);
36303630 if (err_off > 0) {
3631 const shift = @intCast(u6, err_off * 8);
3631 const shift = @as(u6, @intCast(err_off * 8));
36323632 try self.genShiftBinOpMir(
36333633 .{ ._r, .sh },
36343634 err_union_ty,
......@@ -3642,7 +3642,7 @@ fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
36423642 },
36433643 .load_frame => |frame_addr| break :result .{ .load_frame = .{
36443644 .index = frame_addr.index,
3645 .off = frame_addr.off + @intCast(i32, err_off),
3645 .off = frame_addr.off + @as(i32, @intCast(err_off)),
36463646 } },
36473647 else => return self.fail("TODO implement unwrap_err_err for {}", .{operand}),
36483648 }
......@@ -3674,7 +3674,7 @@ fn genUnwrapErrorUnionPayloadMir(
36743674 switch (err_union) {
36753675 .load_frame => |frame_addr| break :result .{ .load_frame = .{
36763676 .index = frame_addr.index,
3677 .off = frame_addr.off + @intCast(i32, payload_off),
3677 .off = frame_addr.off + @as(i32, @intCast(payload_off)),
36783678 } },
36793679 .register => |reg| {
36803680 // TODO reuse operand
......@@ -3686,7 +3686,7 @@ fn genUnwrapErrorUnionPayloadMir(
36863686 else
36873687 .{ .register = try self.copyToTmpRegister(err_union_ty, err_union) };
36883688 if (payload_off > 0) {
3689 const shift = @intCast(u6, payload_off * 8);
3689 const shift = @as(u6, @intCast(payload_off * 8));
36903690 try self.genShiftBinOpMir(
36913691 .{ ._r, .sh },
36923692 err_union_ty,
......@@ -3727,8 +3727,8 @@ fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {
37273727 const eu_ty = src_ty.childType(mod);
37283728 const pl_ty = eu_ty.errorUnionPayload(mod);
37293729 const err_ty = eu_ty.errorUnionSet(mod);
3730 const err_off = @intCast(i32, errUnionErrorOffset(pl_ty, mod));
3731 const err_abi_size = @intCast(u32, err_ty.abiSize(mod));
3730 const err_off = @as(i32, @intCast(errUnionErrorOffset(pl_ty, mod)));
3731 const err_abi_size = @as(u32, @intCast(err_ty.abiSize(mod)));
37323732 try self.asmRegisterMemory(
37333733 .{ ._, .mov },
37343734 registerAlias(dst_reg, err_abi_size),
......@@ -3766,8 +3766,8 @@ fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
37663766
37673767 const eu_ty = src_ty.childType(mod);
37683768 const pl_ty = eu_ty.errorUnionPayload(mod);
3769 const pl_off = @intCast(i32, errUnionPayloadOffset(pl_ty, mod));
3770 const dst_abi_size = @intCast(u32, dst_ty.abiSize(mod));
3769 const pl_off = @as(i32, @intCast(errUnionPayloadOffset(pl_ty, mod)));
3770 const dst_abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
37713771 try self.asmRegisterMemory(
37723772 .{ ._, .lea },
37733773 registerAlias(dst_reg, dst_abi_size),
......@@ -3793,8 +3793,8 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
37933793 const eu_ty = src_ty.childType(mod);
37943794 const pl_ty = eu_ty.errorUnionPayload(mod);
37953795 const err_ty = eu_ty.errorUnionSet(mod);
3796 const err_off = @intCast(i32, errUnionErrorOffset(pl_ty, mod));
3797 const err_abi_size = @intCast(u32, err_ty.abiSize(mod));
3796 const err_off = @as(i32, @intCast(errUnionErrorOffset(pl_ty, mod)));
3797 const err_abi_size = @as(u32, @intCast(err_ty.abiSize(mod)));
37983798 try self.asmMemoryImmediate(
37993799 .{ ._, .mov },
38003800 Memory.sib(Memory.PtrSize.fromSize(err_abi_size), .{
......@@ -3814,8 +3814,8 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
38143814 const dst_lock = self.register_manager.lockReg(dst_reg);
38153815 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
38163816
3817 const pl_off = @intCast(i32, errUnionPayloadOffset(pl_ty, mod));
3818 const dst_abi_size = @intCast(u32, dst_ty.abiSize(mod));
3817 const pl_off = @as(i32, @intCast(errUnionPayloadOffset(pl_ty, mod)));
3818 const dst_abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
38193819 try self.asmRegisterMemory(
38203820 .{ ._, .lea },
38213821 registerAlias(dst_reg, dst_abi_size),
......@@ -3864,14 +3864,14 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
38643864 try self.genCopy(pl_ty, opt_mcv, pl_mcv);
38653865
38663866 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)));
38683868 switch (opt_mcv) {
38693869 else => unreachable,
38703870
38713871 .register => |opt_reg| try self.asmRegisterImmediate(
38723872 .{ ._s, .bt },
38733873 opt_reg,
3874 Immediate.u(@intCast(u6, pl_abi_size * 8)),
3874 Immediate.u(@as(u6, @intCast(pl_abi_size * 8))),
38753875 ),
38763876
38773877 .load_frame => |frame_addr| try self.asmMemoryImmediate(
......@@ -3903,8 +3903,8 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
39033903 if (!pl_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result .{ .immediate = 0 };
39043904
39053905 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(eu_ty, mod));
3906 const pl_off = @intCast(i32, errUnionPayloadOffset(pl_ty, mod));
3907 const err_off = @intCast(i32, errUnionErrorOffset(pl_ty, mod));
3906 const pl_off = @as(i32, @intCast(errUnionPayloadOffset(pl_ty, mod)));
3907 const err_off = @as(i32, @intCast(errUnionErrorOffset(pl_ty, mod)));
39083908 try self.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, operand);
39093909 try self.genSetMem(.{ .frame = frame_index }, err_off, err_ty, .{ .immediate = 0 });
39103910 break :result .{ .load_frame = .{ .index = frame_index } };
......@@ -3925,8 +3925,8 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
39253925 if (!pl_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result try self.resolveInst(ty_op.operand);
39263926
39273927 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(eu_ty, mod));
3928 const pl_off = @intCast(i32, errUnionPayloadOffset(pl_ty, mod));
3929 const err_off = @intCast(i32, errUnionErrorOffset(pl_ty, mod));
3928 const pl_off = @as(i32, @intCast(errUnionPayloadOffset(pl_ty, mod)));
3929 const err_off = @as(i32, @intCast(errUnionErrorOffset(pl_ty, mod)));
39303930 try self.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, .undef);
39313931 const operand = try self.resolveInst(ty_op.operand);
39323932 try self.genSetMem(.{ .frame = frame_index }, err_off, err_ty, operand);
......@@ -3988,7 +3988,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
39883988 const dst_lock = self.register_manager.lockReg(dst_reg);
39893989 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)));
39923992 try self.asmRegisterMemory(
39933993 .{ ._, .lea },
39943994 registerAlias(dst_reg, dst_abi_size),
......@@ -4165,7 +4165,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
41654165 // additional `mov` is needed at the end to get the actual value
41664166
41674167 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)));
41694169 const index_ty = self.typeOf(bin_op.rhs);
41704170 const index_mcv = try self.resolveInst(bin_op.rhs);
41714171 const index_lock = switch (index_mcv) {
......@@ -4305,7 +4305,7 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
43054305 .load_frame => |frame_addr| {
43064306 if (tag_abi_size <= 8) {
43074307 const off: i32 = if (layout.tag_align < layout.payload_align)
4308 @intCast(i32, layout.payload_size)
4308 @as(i32, @intCast(layout.payload_size))
43094309 else
43104310 0;
43114311 break :blk try self.copyToRegisterWithInstTracking(inst, tag_ty, .{
......@@ -4317,13 +4317,13 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
43174317 },
43184318 .register => {
43194319 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))
43214321 else
43224322 0;
43234323 const result = try self.copyToRegisterWithInstTracking(inst, union_ty, operand);
43244324 try self.genShiftBinOpMir(.{ ._r, .sh }, Type.usize, result, .{ .immediate = shift });
43254325 break :blk MCValue{
4326 .register = registerAlias(result.register, @intCast(u32, layout.tag_size)),
4326 .register = registerAlias(result.register, @as(u32, @intCast(layout.tag_size))),
43274327 };
43284328 },
43294329 else => return self.fail("TODO implement get_union_tag for {}", .{operand}),
......@@ -4420,7 +4420,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
44204420 try self.genBinOpMir(.{ ._, .bsr }, Type.u16, dst_mcv, .{ .register = wide_reg });
44214421 } 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);
44244424 try self.asmCmovccRegisterRegister(
44254425 registerAlias(dst_reg, cmov_abi_size),
44264426 registerAlias(imm_reg, cmov_abi_size),
......@@ -4430,7 +4430,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
44304430 try self.genBinOpMir(.{ ._, .xor }, dst_ty, dst_mcv, .{ .immediate = src_bits - 1 });
44314431 } else {
44324432 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))),
44344434 });
44354435 const imm_lock = self.register_manager.lockRegAssumeUnused(imm_reg);
44364436 defer self.register_manager.unlockReg(imm_lock);
......@@ -4447,7 +4447,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
44474447 .{ .register = wide_reg },
44484448 );
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);
44514451 try self.asmCmovccRegisterRegister(
44524452 registerAlias(imm_reg, cmov_abi_size),
44534453 registerAlias(dst_reg, cmov_abi_size),
......@@ -4501,8 +4501,8 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
45014501 .{ ._, .@"or" },
45024502 wide_ty,
45034503 tmp_mcv,
4504 .{ .immediate = (@as(u64, math.maxInt(u64)) >> @intCast(u6, 64 - extra_bits)) <<
4505 @intCast(u6, src_bits) },
4504 .{ .immediate = (@as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - extra_bits))) <<
4505 @as(u6, @intCast(src_bits)) },
45064506 );
45074507 break :masked tmp_mcv;
45084508 } else mat_src_mcv;
......@@ -4519,7 +4519,7 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
45194519 .{ ._, .@"or" },
45204520 Type.u64,
45214521 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)) },
45234523 );
45244524 break :masked dst_mcv;
45254525 } else mat_src_mcv.address().offset(8).deref();
......@@ -4547,7 +4547,7 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
45474547 try self.genBinOpMir(.{ ._, .bsf }, Type.u16, dst_mcv, .{ .register = wide_reg });
45484548 } 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);
45514551 try self.asmCmovccRegisterRegister(
45524552 registerAlias(dst_reg, cmov_abi_size),
45534553 registerAlias(width_reg, cmov_abi_size),
......@@ -4563,7 +4563,7 @@ fn airPopcount(self: *Self, inst: Air.Inst.Index) !void {
45634563 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
45644564 const result: MCValue = result: {
45654565 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)));
45674567 const src_mcv = try self.resolveInst(ty_op.operand);
45684568
45694569 if (self.hasFeature(.popcnt)) {
......@@ -4588,7 +4588,7 @@ fn airPopcount(self: *Self, inst: Air.Inst.Index) !void {
45884588 break :result dst_mcv;
45894589 }
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));
45924592 const imm_0_1 = Immediate.u(mask / 0b1_1);
45934593 const imm_00_11 = Immediate.u(mask / 0b01_01);
45944594 const imm_0000_1111 = Immediate.u(mask / 0b0001_0001);
......@@ -4754,7 +4754,7 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
47544754 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
47554755
47564756 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)));
47584758 const src_mcv = try self.resolveInst(ty_op.operand);
47594759
47604760 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 {
47744774 else
47754775 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));
47784778 const imm_0000_1111 = Immediate.u(mask / 0b0001_0001);
47794779 const imm_00_11 = Immediate.u(mask / 0b01_01);
47804780 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
50175017 })) |tag| tag else return self.fail("TODO implement genRound for {}", .{
50185018 ty.fmt(self.bin_file.options.module.?),
50195019 });
5020 const abi_size = @intCast(u32, ty.abiSize(mod));
5020 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
50215021 const dst_alias = registerAlias(dst_reg, abi_size);
50225022 switch (mir_tag[0]) {
50235023 .v_ss, .v_sd => if (src_mcv.isMemory()) try self.asmRegisterRegisterMemoryImmediate(
......@@ -5057,7 +5057,7 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
50575057 const mod = self.bin_file.options.module.?;
50585058 const un_op = self.air.instructions.items(.data)[inst].un_op;
50595059 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
50625062 const src_mcv = try self.resolveInst(un_op);
50635063 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 {
51235123 .{ .v_ps, .cvtph2 },
51245124 wide_reg,
51255125 src_mcv.mem(Memory.PtrSize.fromSize(
5126 @intCast(u32, @divExact(wide_reg.bitSize(), 16)),
5126 @as(u32, @intCast(@divExact(wide_reg.bitSize(), 16))),
51275127 )),
51285128 ) else try self.asmRegisterRegister(
51295129 .{ .v_ps, .cvtph2 },
......@@ -5255,10 +5255,10 @@ fn packedLoad(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) Inn
52555255 const ptr_info = ptr_ty.ptrInfo(mod);
52565256
52575257 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)));
52595259 const limb_abi_size: u32 = @min(val_abi_size, 8);
52605260 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));
52625262 const val_bit_off = ptr_info.packed_offset.bit_offset % limb_abi_bits;
52635263 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
54045404 const limb_abi_bits = limb_abi_size * 8;
54055405
54065406 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));
54085408 const src_bit_off = ptr_info.packed_offset.bit_offset % limb_abi_bits;
54095409
54105410 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
54215421 .disp = src_byte_off + limb_i * limb_abi_bits,
54225422 });
54235423
5424 const part_mask = (@as(u64, math.maxInt(u64)) >> @intCast(u6, 64 - part_bit_size)) <<
5425 @intCast(u6, part_bit_off);
5424 const part_mask = (@as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - part_bit_size))) <<
5425 @as(u6, @intCast(part_bit_off));
54265426 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)));
54285428 if (limb_abi_size <= 4) {
54295429 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| {
54315431 try self.asmMemoryImmediate(.{ ._, .@"and" }, limb_mem, Immediate.s(small));
54325432 } else {
54335433 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
55425542 const ptr_field_ty = self.typeOfIndex(inst);
55435543 const ptr_container_ty = self.typeOf(operand);
55445544 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)) {
55465546 .Auto, .Extern => container_ty.structFieldOffset(index, mod),
55475547 .Packed => if (container_ty.zigTypeTag(mod) == .Struct and
55485548 ptr_field_ty.ptrInfo(mod).packed_offset.host_size == 0)
55495549 container_ty.packedStructFieldByteOffset(index, mod)
55505550 else
55515551 0,
5552 });
5552 }));
55535553
55545554 const src_mcv = try self.resolveInst(operand);
55555555 const dst_mcv = if (switch (src_mcv) {
......@@ -5577,7 +5577,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
55775577
55785578 const src_mcv = try self.resolveInst(operand);
55795579 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)),
55815581 .Packed => if (mod.typeToStruct(container_ty)) |struct_obj|
55825582 struct_obj.packedFieldBitOffset(mod, index)
55835583 else
......@@ -5588,7 +5588,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
55885588 .load_frame => |frame_addr| {
55895589 if (field_off % 8 == 0) {
55905590 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();
55925592 if (self.reuseOperand(inst, operand, 0, src_mcv)) break :result off_mcv;
55935593
55945594 const dst_mcv = try self.allocRegOrMem(inst, true);
......@@ -5596,10 +5596,10 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
55965596 break :result dst_mcv;
55975597 }
55985598
5599 const field_abi_size = @intCast(u32, field_ty.abiSize(mod));
5599 const field_abi_size = @as(u32, @intCast(field_ty.abiSize(mod)));
56005600 const limb_abi_size: u32 = @min(field_abi_size, 8);
56015601 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));
56035603 const field_bit_off = field_off % limb_abi_bits;
56045604
56055605 if (field_abi_size > 8) {
......@@ -5643,7 +5643,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
56435643 tmp_reg,
56445644 Memory.sib(Memory.PtrSize.fromSize(field_abi_size), .{
56455645 .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)),
56475647 }),
56485648 );
56495649 try self.asmRegisterRegisterImmediate(
......@@ -5724,7 +5724,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
57245724
57255725 const inst_ty = self.typeOfIndex(inst);
57265726 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
57295729 const src_mcv = try self.resolveInst(extra.field_ptr);
57305730 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:
57735773
57745774 switch (tag) {
57755775 .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)));
57775777 const int_info = if (src_ty.ip_index == .bool_type)
57785778 std.builtin.Type.Int{ .signedness = .unsigned, .bits = 1 }
57795779 else
57805780 src_ty.intInfo(mod);
57815781 var byte_off: i32 = 0;
57825782 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)));
57845784 const limb_ty = try mod.intType(int_info.signedness, limb_bits);
57855785 const limb_mcv = switch (byte_off) {
57865786 0 => dst_mcv,
......@@ -5788,7 +5788,7 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:
57885788 };
57895789
57905790 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));
57925792 try self.genBinOpMir(.{ ._, .xor }, limb_ty, limb_mcv, .{ .immediate = mask });
57935793 } else try self.genUnOpMir(.{ ._, .not }, limb_ty, limb_mcv);
57945794 }
......@@ -5801,7 +5801,7 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:
58015801
58025802fn genUnOpMir(self: *Self, mir_tag: Mir.Inst.FixedTag, dst_ty: Type, dst_mcv: MCValue) !void {
58035803 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)));
58055805 if (abi_size > 8) return self.fail("TODO implement {} for {}", .{
58065806 mir_tag,
58075807 dst_ty.fmt(self.bin_file.options.module.?),
......@@ -5863,7 +5863,7 @@ fn genShiftBinOpMir(
58635863 break :rhs .{ .register = .rcx };
58645864 };
58655865
5866 const abi_size = @intCast(u32, ty.abiSize(mod));
5866 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
58675867 if (abi_size <= 8) {
58685868 switch (lhs_mcv) {
58695869 .register => |lhs_reg| switch (rhs_mcv) {
......@@ -5886,7 +5886,7 @@ fn genShiftBinOpMir(
58865886 const lhs_mem = Memory.sib(Memory.PtrSize.fromSize(abi_size), switch (lhs_mcv) {
58875887 .memory => |addr| .{
58885888 .base = .{ .reg = .ds },
5889 .disp = math.cast(i32, @bitCast(i64, addr)) orelse
5889 .disp = math.cast(i32, @as(i64, @bitCast(addr))) orelse
58905890 return self.fail("TODO genShiftBinOpMir between {s} and {s}", .{
58915891 @tagName(lhs_mcv),
58925892 @tagName(rhs_mcv),
......@@ -6151,8 +6151,8 @@ fn genMulDivBinOp(
61516151 if (dst_ty.zigTypeTag(mod) == .Vector or dst_ty.zigTypeTag(mod) == .Float) {
61526152 return self.fail("TODO implement genMulDivBinOp for {}", .{dst_ty.fmtDebug()});
61536153 }
6154 const dst_abi_size = @intCast(u32, dst_ty.abiSize(mod));
6155 const src_abi_size = @intCast(u32, src_ty.abiSize(mod));
6154 const dst_abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
6155 const src_abi_size = @as(u32, @intCast(src_ty.abiSize(mod)));
61566156 if (switch (tag) {
61576157 else => unreachable,
61586158 .mul, .mulwrap => dst_abi_size != src_abi_size and dst_abi_size != src_abi_size * 2,
......@@ -6326,7 +6326,7 @@ fn genBinOp(
63266326 const mod = self.bin_file.options.module.?;
63276327 const lhs_ty = self.typeOf(lhs_air);
63286328 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
63316331 const maybe_mask_reg = switch (air_tag) {
63326332 else => null,
......@@ -6481,7 +6481,7 @@ fn genBinOp(
64816481 .lea_tlv,
64826482 .lea_frame,
64836483 => true,
6484 .memory => |addr| math.cast(i32, @bitCast(i64, addr)) == null,
6484 .memory => |addr| math.cast(i32, @as(i64, @bitCast(addr))) == null,
64856485 else => false,
64866486 }) .{ .register = try self.copyToTmpRegister(rhs_ty, src_mcv) } else src_mcv;
64876487 const mat_mcv_lock = switch (mat_src_mcv) {
......@@ -6506,7 +6506,7 @@ fn genBinOp(
65066506 },
65076507 };
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);
65106510 const tmp_reg = switch (dst_mcv) {
65116511 .register => |reg| reg,
65126512 else => try self.copyToTmpRegister(lhs_ty, dst_mcv),
......@@ -6541,7 +6541,7 @@ fn genBinOp(
65416541 Memory.sib(Memory.PtrSize.fromSize(cmov_abi_size), switch (mat_src_mcv) {
65426542 .memory => |addr| .{
65436543 .base = .{ .reg = .ds },
6544 .disp = @intCast(i32, @bitCast(i64, addr)),
6544 .disp = @as(i32, @intCast(@as(i64, @bitCast(addr)))),
65456545 },
65466546 .indirect => |reg_off| .{
65476547 .base = .{ .reg = reg_off.reg },
......@@ -7429,7 +7429,7 @@ fn genBinOpMir(
74297429 src_mcv: MCValue,
74307430) !void {
74317431 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)));
74337433 switch (dst_mcv) {
74347434 .none,
74357435 .unreach,
......@@ -7465,28 +7465,28 @@ fn genBinOpMir(
74657465 8 => try self.asmRegisterImmediate(
74667466 mir_tag,
74677467 dst_alias,
7468 if (math.cast(i8, @bitCast(i64, imm))) |small|
7468 if (math.cast(i8, @as(i64, @bitCast(imm)))) |small|
74697469 Immediate.s(small)
74707470 else
7471 Immediate.u(@intCast(u8, imm)),
7471 Immediate.u(@as(u8, @intCast(imm))),
74727472 ),
74737473 16 => try self.asmRegisterImmediate(
74747474 mir_tag,
74757475 dst_alias,
7476 if (math.cast(i16, @bitCast(i64, imm))) |small|
7476 if (math.cast(i16, @as(i64, @bitCast(imm)))) |small|
74777477 Immediate.s(small)
74787478 else
7479 Immediate.u(@intCast(u16, imm)),
7479 Immediate.u(@as(u16, @intCast(imm))),
74807480 ),
74817481 32 => try self.asmRegisterImmediate(
74827482 mir_tag,
74837483 dst_alias,
7484 if (math.cast(i32, @bitCast(i64, imm))) |small|
7484 if (math.cast(i32, @as(i64, @bitCast(imm)))) |small|
74857485 Immediate.s(small)
74867486 else
7487 Immediate.u(@intCast(u32, imm)),
7487 Immediate.u(@as(u32, @intCast(imm))),
74887488 ),
7489 64 => if (math.cast(i32, @bitCast(i64, imm))) |small|
7489 64 => if (math.cast(i32, @as(i64, @bitCast(imm)))) |small|
74907490 try self.asmRegisterImmediate(mir_tag, dst_alias, Immediate.s(small))
74917491 else
74927492 try self.asmRegisterRegister(mir_tag, dst_alias, registerAlias(
......@@ -7602,8 +7602,8 @@ fn genBinOpMir(
76027602 => null,
76037603 .memory, .load_got, .load_direct, .load_tlv => src: {
76047604 switch (src_mcv) {
7605 .memory => |addr| if (math.cast(i32, @bitCast(i64, addr)) != null and
7606 math.cast(i32, @bitCast(i64, addr) + abi_size - limb_abi_size) != null)
7605 .memory => |addr| if (math.cast(i32, @as(i64, @bitCast(addr))) != null and
7606 math.cast(i32, @as(i64, @bitCast(addr)) + abi_size - limb_abi_size) != null)
76077607 break :src null,
76087608 .load_got, .load_direct, .load_tlv => {},
76097609 else => unreachable,
......@@ -7680,7 +7680,7 @@ fn genBinOpMir(
76807680 const imm = switch (off) {
76817681 0 => src_imm,
76827682 else => switch (ty_signedness) {
7683 .signed => @bitCast(u64, @bitCast(i64, src_imm) >> 63),
7683 .signed => @as(u64, @bitCast(@as(i64, @bitCast(src_imm)) >> 63)),
76847684 .unsigned => 0,
76857685 },
76867686 };
......@@ -7688,28 +7688,28 @@ fn genBinOpMir(
76887688 8 => try self.asmMemoryImmediate(
76897689 mir_limb_tag,
76907690 dst_limb_mem,
7691 if (math.cast(i8, @bitCast(i64, imm))) |small|
7691 if (math.cast(i8, @as(i64, @bitCast(imm)))) |small|
76927692 Immediate.s(small)
76937693 else
7694 Immediate.u(@intCast(u8, imm)),
7694 Immediate.u(@as(u8, @intCast(imm))),
76957695 ),
76967696 16 => try self.asmMemoryImmediate(
76977697 mir_limb_tag,
76987698 dst_limb_mem,
7699 if (math.cast(i16, @bitCast(i64, imm))) |small|
7699 if (math.cast(i16, @as(i64, @bitCast(imm)))) |small|
77007700 Immediate.s(small)
77017701 else
7702 Immediate.u(@intCast(u16, imm)),
7702 Immediate.u(@as(u16, @intCast(imm))),
77037703 ),
77047704 32 => try self.asmMemoryImmediate(
77057705 mir_limb_tag,
77067706 dst_limb_mem,
7707 if (math.cast(i32, @bitCast(i64, imm))) |small|
7707 if (math.cast(i32, @as(i64, @bitCast(imm)))) |small|
77087708 Immediate.s(small)
77097709 else
7710 Immediate.u(@intCast(u32, imm)),
7710 Immediate.u(@as(u32, @intCast(imm))),
77117711 ),
7712 64 => if (math.cast(i32, @bitCast(i64, imm))) |small|
7712 64 => if (math.cast(i32, @as(i64, @bitCast(imm)))) |small|
77137713 try self.asmMemoryImmediate(
77147714 mir_limb_tag,
77157715 dst_limb_mem,
......@@ -7753,7 +7753,7 @@ fn genBinOpMir(
77537753 0 => src_mcv,
77547754 else => .{ .immediate = 0 },
77557755 },
7756 .memory => |addr| .{ .memory = @bitCast(u64, @bitCast(i64, addr) + off) },
7756 .memory => |addr| .{ .memory = @as(u64, @bitCast(@as(i64, @bitCast(addr)) + off)) },
77577757 .indirect => |reg_off| .{ .indirect = .{
77587758 .reg = reg_off.reg,
77597759 .off = reg_off.off + off,
......@@ -7780,7 +7780,7 @@ fn genBinOpMir(
77807780/// Does not support byte-size operands.
77817781fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError!void {
77827782 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)));
77847784 switch (dst_mcv) {
77857785 .none,
77867786 .unreach,
......@@ -7847,7 +7847,7 @@ fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: M
78477847 Memory.sib(Memory.PtrSize.fromSize(abi_size), switch (src_mcv) {
78487848 .memory => |addr| .{
78497849 .base = .{ .reg = .ds },
7850 .disp = math.cast(i32, @bitCast(i64, addr)) orelse
7850 .disp = math.cast(i32, @as(i64, @bitCast(addr))) orelse
78517851 return self.asmRegisterRegister(
78527852 .{ .i_, .mul },
78537853 dst_alias,
......@@ -8014,7 +8014,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
80148014 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
80158015 const callee = pl_op.operand;
80168016 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]));
80188018 const ty = self.typeOf(callee);
80198019
80208020 const fn_ty = switch (ty.zigTypeTag(mod)) {
......@@ -8107,7 +8107,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
81078107 const got_addr = atom.getOffsetTableAddress(elf_file);
81088108 try self.asmMemory(.{ ._, .call }, Memory.sib(.qword, .{
81098109 .base = .{ .reg = .ds },
8110 .disp = @intCast(i32, got_addr),
8110 .disp = @as(i32, @intCast(got_addr)),
81118111 }));
81128112 } else if (self.bin_file.cast(link.File.Coff)) |coff_file| {
81138113 const atom = try coff_file.getOrCreateAtomForDecl(owner_decl);
......@@ -8124,7 +8124,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
81248124 const atom = p9.getAtom(atom_index);
81258125 try self.asmMemory(.{ ._, .call }, Memory.sib(.qword, .{
81268126 .base = .{ .reg = .ds },
8127 .disp = @intCast(i32, atom.getOffsetTableAddress(p9)),
8127 .disp = @as(i32, @intCast(atom.getOffsetTableAddress(p9))),
81288128 }));
81298129 } else unreachable;
81308130 } else if (func_value.getExternFunc(mod)) |extern_func| {
......@@ -8244,7 +8244,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
82448244 const result = MCValue{
82458245 .eflags = switch (ty.zigTypeTag(mod)) {
82468246 else => result: {
8247 const abi_size = @intCast(u16, ty.abiSize(mod));
8247 const abi_size = @as(u16, @intCast(ty.abiSize(mod)));
82488248 const may_flip: enum {
82498249 may_flip,
82508250 must_flip,
......@@ -8441,7 +8441,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
84418441 self.eflags_inst = inst;
84428442
84438443 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)));
84458445 const op_mcv = try self.resolveInst(un_op);
84468446 const dst_reg = switch (op_mcv) {
84478447 .register => |reg| reg,
......@@ -8650,7 +8650,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
86508650 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))
86518651 .{ .off = 0, .ty = if (pl_ty.isSlice(mod)) pl_ty.slicePtrFieldType(mod) else pl_ty }
86528652 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
86558655 switch (opt_mcv) {
86568656 .none,
......@@ -8670,18 +8670,18 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
86708670
86718671 .register => |opt_reg| {
86728672 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)));
86748674 const alias_reg = registerAlias(opt_reg, some_abi_size);
86758675 assert(some_abi_size * 8 == alias_reg.bitSize());
86768676 try self.asmRegisterRegister(.{ ._, .@"test" }, alias_reg, alias_reg);
86778677 return .{ .eflags = .z };
86788678 }
86798679 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)));
86818681 try self.asmRegisterImmediate(
86828682 .{ ._, .bt },
86838683 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))),
86858685 );
86868686 return .{ .eflags = .nc };
86878687 },
......@@ -8696,7 +8696,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
86968696 defer self.register_manager.unlockReg(addr_reg_lock);
86978697
86988698 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)));
87008700 try self.asmMemoryImmediate(
87018701 .{ ._, .cmp },
87028702 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
87098709 },
87108710
87118711 .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)));
87138713 try self.asmMemoryImmediate(
87148714 .{ ._, .cmp },
87158715 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)
87418741 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))
87428742 .{ .off = 0, .ty = if (pl_ty.isSlice(mod)) pl_ty.slicePtrFieldType(mod) else pl_ty }
87438743 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
87468746 const ptr_reg = switch (ptr_mcv) {
87478747 .register => |reg| reg,
......@@ -8750,7 +8750,7 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue)
87508750 const ptr_lock = self.register_manager.lockReg(ptr_reg);
87518751 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)));
87548754 try self.asmMemoryImmediate(
87558755 .{ ._, .cmp },
87568756 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) !
87838783
87848784 const tmp_reg = try self.copyToTmpRegister(ty, operand);
87858785 if (err_off > 0) {
8786 const shift = @intCast(u6, err_off * 8);
8786 const shift = @as(u6, @intCast(err_off * 8));
87878787 try self.genShiftBinOpMir(
87888788 .{ ._r, .sh },
87898789 ty,
......@@ -8805,7 +8805,7 @@ fn isErr(self: *Self, maybe_inst: ?Air.Inst.Index, ty: Type, operand: MCValue) !
88058805 Type.anyerror,
88068806 .{ .load_frame = .{
88078807 .index = frame_addr.index,
8808 .off = frame_addr.off + @intCast(i32, err_off),
8808 .off = frame_addr.off + @as(i32, @intCast(err_off)),
88098809 } },
88108810 .{ .immediate = 0 },
88118811 ),
......@@ -8943,7 +8943,7 @@ fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
89438943 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
89448944 const loop = self.air.extraData(Air.Block, ty_pl.payload);
89458945 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
89488948 self.scope_generation += 1;
89498949 const state = try self.saveState();
......@@ -9015,9 +9015,9 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {
90159015
90169016 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
90179017 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
9018 const items = @ptrCast(
9018 const items = @as(
90199019 []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]),
90219021 );
90229022 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
90239023 extra_index = case.end + items.len + case_body.len;
......@@ -9066,7 +9066,7 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {
90669066}
90679067
90689068fn 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));
90709070 switch (self.mir_instructions.items(.tag)[reloc]) {
90719071 .j, .jmp => {},
90729072 .pseudo => switch (self.mir_instructions.items(.ops)[reloc]) {
......@@ -9141,11 +9141,11 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {
91419141fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
91429142 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
91439143 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));
91459145 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]));
91479147 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]));
91499149 extra_i += inputs.len;
91509150
91519151 var result: MCValue = .none;
......@@ -9281,7 +9281,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
92819281 if (std.fmt.parseInt(i32, op_str["$".len..], 0)) |s| {
92829282 if (mnem_size) |size| {
92839283 const max = @as(u64, math.maxInt(u64)) >>
9284 @intCast(u6, 64 - (size.bitSize() - 1));
9284 @as(u6, @intCast(64 - (size.bitSize() - 1)));
92859285 if ((if (s < 0) ~s else s) > max)
92869286 return self.fail("Invalid immediate size: '{s}'", .{op_str});
92879287 }
......@@ -9289,7 +9289,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
92899289 } else |_| if (std.fmt.parseInt(u64, op_str["$".len..], 0)) |u| {
92909290 if (mnem_size) |size| {
92919291 const max = @as(u64, math.maxInt(u64)) >>
9292 @intCast(u6, 64 - size.bitSize());
9292 @as(u6, @intCast(64 - size.bitSize()));
92939293 if (u > max)
92949294 return self.fail("Invalid immediate size: '{s}'", .{op_str});
92959295 }
......@@ -9618,7 +9618,7 @@ fn genCopy(self: *Self, ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError
96189618 .indirect => |reg_off| try self.genSetMem(.{ .reg = reg_off.reg }, reg_off.off, ty, src_mcv),
96199619 .memory, .load_direct, .load_got, .load_tlv => {
96209620 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|
96229622 return self.genSetMem(.{ .reg = .ds }, small_addr, ty, src_mcv),
96239623 .load_direct, .load_got, .load_tlv => {},
96249624 else => unreachable,
......@@ -9641,7 +9641,7 @@ fn genCopy(self: *Self, ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError
96419641
96429642fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerError!void {
96439643 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)));
96459645 if (abi_size * 8 > dst_reg.bitSize())
96469646 return self.fail("genSetReg called with a value larger than dst_reg", .{});
96479647 switch (src_mcv) {
......@@ -9662,11 +9662,11 @@ fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerEr
96629662 } else if (abi_size > 4 and math.cast(u32, imm) != null) {
96639663 // 32-bit moves zero-extend to 64-bit.
96649664 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) {
96669666 try self.asmRegisterImmediate(
96679667 .{ ._, .mov },
96689668 registerAlias(dst_reg, abi_size),
9669 Immediate.s(@intCast(i32, @bitCast(i64, imm))),
9669 Immediate.s(@as(i32, @intCast(@as(i64, @bitCast(imm))))),
96709670 );
96719671 } else {
96729672 try self.asmRegisterImmediate(
......@@ -9806,7 +9806,7 @@ fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerEr
98069806 },
98079807 .memory, .load_direct, .load_got, .load_tlv => {
98089808 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| {
98109810 const dst_alias = registerAlias(dst_reg, abi_size);
98119811 const src_mem = Memory.sib(Memory.PtrSize.fromSize(abi_size), .{
98129812 .base = .{ .reg = .ds },
......@@ -9814,7 +9814,7 @@ fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerEr
98149814 });
98159815 switch (try self.moveStrategy(ty, mem.isAlignedGeneric(
98169816 u32,
9817 @bitCast(u32, small_addr),
9817 @as(u32, @bitCast(small_addr)),
98189818 ty.abiAlignment(mod),
98199819 ))) {
98209820 .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
99289928
99299929fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCValue) InnerError!void {
99309930 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)));
99329932 const dst_ptr_mcv: MCValue = switch (base) {
9933 .none => .{ .immediate = @bitCast(u64, @as(i64, disp)) },
9933 .none => .{ .immediate = @as(u64, @bitCast(@as(i64, disp))) },
99349934 .reg => |base_reg| .{ .register_offset = .{ .reg = base_reg, .off = disp } },
99359935 .frame => |base_frame_index| .{ .lea_frame = .{ .index = base_frame_index, .off = disp } },
99369936 };
......@@ -9941,9 +9941,9 @@ fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCVal
99419941 .immediate => |imm| switch (abi_size) {
99429942 1, 2, 4 => {
99439943 const immediate = if (ty.isSignedInt(mod))
9944 Immediate.s(@truncate(i32, @bitCast(i64, imm)))
9944 Immediate.s(@as(i32, @truncate(@as(i64, @bitCast(imm)))))
99459945 else
9946 Immediate.u(@intCast(u32, imm));
9946 Immediate.u(@as(u32, @intCast(imm)));
99479947 try self.asmMemoryImmediate(
99489948 .{ ._, .mov },
99499949 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
99519951 );
99529952 },
99539953 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| {
99559955 try self.asmMemoryImmediate(
99569956 .{ ._, .mov },
99579957 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
99639963 .{ ._, .mov },
99649964 Memory.sib(.dword, .{ .base = base, .disp = disp + offset }),
99659965 if (ty.isSignedInt(mod))
9966 Immediate.s(@truncate(
9966 Immediate.s(@as(
99679967 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)),
99699969 ))
99709970 else
9971 Immediate.u(@truncate(
9971 Immediate.u(@as(
99729972 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),
99749974 )),
99759975 );
99769976 },
......@@ -9985,13 +9985,13 @@ fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCVal
99859985 switch (try self.moveStrategy(ty, switch (base) {
99869986 .none => mem.isAlignedGeneric(
99879987 u32,
9988 @bitCast(u32, disp),
9988 @as(u32, @bitCast(disp)),
99899989 ty.abiAlignment(mod),
99909990 ),
99919991 .reg => |reg| switch (reg) {
99929992 .es, .cs, .ss, .ds => mem.isAlignedGeneric(
99939993 u32,
9994 @bitCast(u32, disp),
9994 @as(u32, @bitCast(disp)),
99959995 ty.abiAlignment(mod),
99969996 ),
99979997 else => false,
......@@ -10012,13 +10012,13 @@ fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCVal
1001210012 .register_overflow => |ro| {
1001310013 try self.genSetMem(
1001410014 base,
10015 disp + @intCast(i32, ty.structFieldOffset(0, mod)),
10015 disp + @as(i32, @intCast(ty.structFieldOffset(0, mod))),
1001610016 ty.structFieldType(0, mod),
1001710017 .{ .register = ro.reg },
1001810018 );
1001910019 try self.genSetMem(
1002010020 base,
10021 disp + @intCast(i32, ty.structFieldOffset(1, mod)),
10021 disp + @as(i32, @intCast(ty.structFieldOffset(1, mod))),
1002210022 ty.structFieldType(1, mod),
1002310023 .{ .eflags = ro.eflags },
1002410024 );
......@@ -10077,7 +10077,7 @@ fn genLazySymbolRef(
1007710077 _ = try atom.getOrCreateOffsetTableEntry(elf_file);
1007810078 const got_addr = atom.getOffsetTableAddress(elf_file);
1007910079 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)) });
1008110081 switch (tag) {
1008210082 .lea, .mov => try self.asmRegisterMemory(.{ ._, .mov }, reg.to64(), got_mem),
1008310083 .call => try self.asmMemory(.{ ._, .call }, got_mem),
......@@ -10099,7 +10099,7 @@ fn genLazySymbolRef(
1009910099 _ = atom.getOrCreateOffsetTableEntry(p9_file);
1010010100 const got_addr = atom.getOffsetTableAddress(p9_file);
1010110101 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)) });
1010310103 switch (tag) {
1010410104 .lea, .mov => try self.asmRegisterMemory(.{ ._, .mov }, reg.to64(), got_mem),
1010510105 .call => try self.asmMemory(.{ ._, .call }, got_mem),
......@@ -10195,8 +10195,8 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
1019510195 if (src_ty.isAbiInt(mod)) src_ty.intInfo(mod).signedness else .unsigned;
1019610196 if (dst_signedness == src_signedness) break :result dst_mcv;
1019710197
10198 const abi_size = @intCast(u16, dst_ty.abiSize(mod));
10199 const bit_size = @intCast(u16, dst_ty.bitSize(mod));
10198 const abi_size = @as(u16, @intCast(dst_ty.abiSize(mod)));
10199 const bit_size = @as(u16, @intCast(dst_ty.bitSize(mod)));
1020010200 if (abi_size * 8 <= bit_size) break :result dst_mcv;
1020110201
1020210202 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 {
1023710237 try self.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr);
1023810238 try self.genSetMem(
1023910239 .{ .frame = frame_index },
10240 @intCast(i32, ptr_ty.abiSize(mod)),
10240 @as(i32, @intCast(ptr_ty.abiSize(mod))),
1024110241 Type.usize,
1024210242 .{ .immediate = array_len },
1024310243 );
......@@ -10251,7 +10251,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
1025110251 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1025210252
1025310253 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)));
1025510255 const src_signedness =
1025610256 if (src_ty.isAbiInt(mod)) src_ty.intInfo(mod).signedness else .unsigned;
1025710257 const dst_ty = self.typeOfIndex(inst);
......@@ -10306,7 +10306,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
1030610306
1030710307 const src_ty = self.typeOf(ty_op.operand);
1030810308 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)));
1031010310 const dst_signedness =
1031110311 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 {
1035910359
1036010360 const ptr_ty = self.typeOf(extra.ptr);
1036110361 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
1036410364 try self.spillRegisters(&.{ .rax, .rdx, .rbx, .rcx });
1036510365 const regs_lock = self.register_manager.lockRegsAssumeUnused(4, .{ .rax, .rdx, .rbx, .rcx });
......@@ -10461,7 +10461,7 @@ fn atomicOp(
1046110461 };
1046210462 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)));
1046510465 const ptr_size = Memory.PtrSize.fromSize(val_abi_size);
1046610466 const ptr_mem = switch (ptr_mcv) {
1046710467 .immediate, .register, .register_offset, .lea_frame => ptr_mcv.deref().mem(ptr_size),
......@@ -10539,7 +10539,7 @@ fn atomicOp(
1053910539 defer self.register_manager.unlockReg(tmp_lock);
1054010540
1054110541 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));
1054310543 if (rmw_op != std.builtin.AtomicRmwOp.Xchg) {
1054410544 try self.genSetReg(tmp_reg, val_ty, .{ .register = .rax });
1054510545 }
......@@ -10613,7 +10613,7 @@ fn atomicOp(
1061310613 .scale_index = ptr_mem.scaleIndex(),
1061410614 .disp = ptr_mem.sib.disp + 8,
1061510615 }));
10616 const loop = @intCast(u32, self.mir_instructions.len);
10616 const loop = @as(u32, @intCast(self.mir_instructions.len));
1061710617 const val_mem_mcv: MCValue = switch (val_mcv) {
1061810618 .memory, .indirect, .load_frame => val_mcv,
1061910619 else => .{ .indirect = .{
......@@ -10769,7 +10769,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1076910769 };
1077010770 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
1077410774 if (elem_abi_size == 1) {
1077510775 const ptr: MCValue = switch (dst_ptr_ty.ptrSize(mod)) {
......@@ -11249,9 +11249,9 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
1124911249fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1125011250 const mod = self.bin_file.options.module.?;
1125111251 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)));
1125311253 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]));
1125511255 const result: MCValue = result: {
1125611256 switch (result_ty.zigTypeTag(mod)) {
1125711257 .Struct => {
......@@ -11268,17 +11268,17 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1126811268 if ((try result_ty.structFieldValueComptime(mod, elem_i)) != null) continue;
1126911269
1127011270 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)));
1127211272 if (elem_bit_size > 64) {
1127311273 return self.fail(
1127411274 "TODO airAggregateInit implement packed structs with large fields",
1127511275 .{},
1127611276 );
1127711277 }
11278 const elem_abi_size = @intCast(u32, elem_ty.abiSize(mod));
11278 const elem_abi_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
1127911279 const elem_abi_bits = elem_abi_size * 8;
1128011280 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));
1128211282 const elem_bit_off = elem_off % elem_abi_bits;
1128311283 const elem_mcv = try self.resolveInst(elem);
1128411284 const mat_elem_mcv = switch (elem_mcv) {
......@@ -11330,7 +11330,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1133011330 elem_ty,
1133111331 .{ .load_frame = .{
1133211332 .index = frame_index,
11333 .off = elem_byte_off + @intCast(i32, elem_abi_size),
11333 .off = elem_byte_off + @as(i32, @intCast(elem_abi_size)),
1133411334 } },
1133511335 .{ .register = reg },
1133611336 );
......@@ -11340,7 +11340,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1134011340 if ((try result_ty.structFieldValueComptime(mod, elem_i)) != null) continue;
1134111341
1134211342 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)));
1134411344 const elem_mcv = try self.resolveInst(elem);
1134511345 const mat_elem_mcv = switch (elem_mcv) {
1134611346 .load_tlv => |sym_index| MCValue{ .lea_tlv = sym_index },
......@@ -11354,7 +11354,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1135411354 const frame_index =
1135511355 try self.allocFrameIndex(FrameAlloc.initType(result_ty, mod));
1135611356 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
1135911359 for (elements, 0..) |elem, elem_i| {
1136011360 const elem_mcv = try self.resolveInst(elem);
......@@ -11362,12 +11362,12 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1136211362 .load_tlv => |sym_index| MCValue{ .lea_tlv = sym_index },
1136311363 else => elem_mcv,
1136411364 };
11365 const elem_off = @intCast(i32, elem_size * elem_i);
11365 const elem_off = @as(i32, @intCast(elem_size * elem_i));
1136611366 try self.genSetMem(.{ .frame = frame_index }, elem_off, elem_ty, mat_elem_mcv);
1136711367 }
1136811368 if (result_ty.sentinel(mod)) |sentinel| try self.genSetMem(
1136911369 .{ .frame = frame_index },
11370 @intCast(i32, elem_size * elements.len),
11370 @as(i32, @intCast(elem_size * elements.len)),
1137111371 elem_ty,
1137211372 try self.genTypedValue(.{ .ty = elem_ty, .val = sentinel }),
1137311373 );
......@@ -11416,7 +11416,7 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
1141611416 const tag_int_val = try tag_val.intFromEnum(tag_ty, mod);
1141711417 const tag_int = tag_int_val.toUnsignedInt(mod);
1141811418 const tag_off = if (layout.tag_align < layout.payload_align)
11419 @intCast(i32, layout.payload_size)
11419 @as(i32, @intCast(layout.payload_size))
1142011420 else
1142111421 0;
1142211422 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 {
1142411424 const pl_off = if (layout.tag_align < layout.payload_align)
1142511425 0
1142611426 else
11427 @intCast(i32, layout.tag_size);
11427 @as(i32, @intCast(layout.tag_size));
1142811428 try self.genCopy(src_ty, dst_mcv.address().offset(pl_off).deref(), src_mcv);
1142911429
1143011430 break :result dst_mcv;
......@@ -11454,7 +11454,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1145411454 var order = [1]u2{0} ** 3;
1145511455 var unused = std.StaticBitSet(3).initFull();
1145611456 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));
1145811458 mcv.* = try self.resolveInst(op);
1145911459 if (unused.isSet(0) and mcv.isRegister() and self.reuseOperand(inst, op, op_index, mcv.*)) {
1146011460 order[op_index] = 1;
......@@ -11470,7 +11470,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1147011470 }
1147111471 for (&order, &mcvs, &locks) |*mop_index, *mcv, *lock| {
1147211472 if (mop_index.* != 0) continue;
11473 mop_index.* = 1 + @intCast(u2, unused.toggleFirstSet().?);
11473 mop_index.* = 1 + @as(u2, @intCast(unused.toggleFirstSet().?));
1147411474 if (mop_index.* > 1 and mcv.isRegister()) continue;
1147511475 const reg = try self.copyToTmpRegister(ty, mcv.*);
1147611476 mcv.* = .{ .register = reg };
......@@ -11570,7 +11570,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1157011570 var mops: [3]MCValue = undefined;
1157111571 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)));
1157411574 const mop1_reg = registerAlias(mops[0].getReg().?, abi_size);
1157511575 const mop2_reg = registerAlias(mops[1].getReg().?, abi_size);
1157611576 if (mops[2].isRegister()) try self.asmRegisterRegisterRegister(
......@@ -11723,7 +11723,7 @@ fn resolveCallingConventionValues(
1172311723 switch (self.target.os.tag) {
1172411724 .windows => {
1172511725 // 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)));
1172711727 },
1172811728 else => {},
1172911729 }
......@@ -11746,7 +11746,7 @@ fn resolveCallingConventionValues(
1174611746 result.return_value = switch (classes[0]) {
1174711747 .integer => InstTracking.init(.{ .register = registerAlias(
1174811748 ret_reg,
11749 @intCast(u32, ret_ty.abiSize(mod)),
11749 @as(u32, @intCast(ret_ty.abiSize(mod))),
1175011750 ) }),
1175111751 .float, .sse => InstTracking.init(.{ .register = .xmm0 }),
1175211752 .memory => ret: {
......@@ -11782,17 +11782,17 @@ fn resolveCallingConventionValues(
1178211782 },
1178311783 .float, .sse => switch (self.target.os.tag) {
1178411784 .windows => if (param_reg_i < 4) {
11785 arg.* = .{ .register = @enumFromInt(
11785 arg.* = .{ .register = @as(
1178611786 Register,
11787 @intFromEnum(Register.xmm0) + param_reg_i,
11787 @enumFromInt(@intFromEnum(Register.xmm0) + param_reg_i),
1178811788 ) };
1178911789 param_reg_i += 1;
1179011790 continue;
1179111791 },
1179211792 else => if (param_sse_reg_i < 8) {
11793 arg.* = .{ .register = @enumFromInt(
11793 arg.* = .{ .register = @as(
1179411794 Register,
11795 @intFromEnum(Register.xmm0) + param_sse_reg_i,
11795 @enumFromInt(@intFromEnum(Register.xmm0) + param_sse_reg_i),
1179611796 ) };
1179711797 param_sse_reg_i += 1;
1179811798 continue;
......@@ -11804,8 +11804,8 @@ fn resolveCallingConventionValues(
1180411804 }),
1180511805 }
1180611806
11807 const param_size = @intCast(u31, ty.abiSize(mod));
11808 const param_align = @intCast(u31, ty.abiAlignment(mod));
11807 const param_size = @as(u31, @intCast(ty.abiSize(mod)));
11808 const param_align = @as(u31, @intCast(ty.abiAlignment(mod)));
1180911809 result.stack_byte_count =
1181011810 mem.alignForward(u31, result.stack_byte_count, param_align);
1181111811 arg.* = .{ .load_frame = .{
......@@ -11825,7 +11825,7 @@ fn resolveCallingConventionValues(
1182511825 result.return_value = InstTracking.init(.none);
1182611826 } else {
1182711827 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)));
1182911829 if (ret_ty_size <= 8 and !ret_ty.isRuntimeFloat()) {
1183011830 const aliased_reg = registerAlias(ret_reg, ret_ty_size);
1183111831 result.return_value = .{ .short = .{ .register = aliased_reg }, .long = .none };
......@@ -11844,8 +11844,8 @@ fn resolveCallingConventionValues(
1184411844 arg.* = .none;
1184511845 continue;
1184611846 }
11847 const param_size = @intCast(u31, ty.abiSize(mod));
11848 const param_align = @intCast(u31, ty.abiAlignment(mod));
11847 const param_size = @as(u31, @intCast(ty.abiSize(mod)));
11848 const param_align = @as(u31, @intCast(ty.abiAlignment(mod)));
1184911849 result.stack_byte_count =
1185011850 mem.alignForward(u31, result.stack_byte_count, param_align);
1185111851 arg.* = .{ .load_frame = .{
......@@ -11932,12 +11932,12 @@ fn truncateRegister(self: *Self, ty: Type, reg: Register) !void {
1193211932 const mod = self.bin_file.options.module.?;
1193311933 const int_info = if (ty.isAbiInt(mod)) ty.intInfo(mod) else std.builtin.Type.Int{
1193411934 .signedness = .unsigned,
11935 .bits = @intCast(u16, ty.bitSize(mod)),
11935 .bits = @as(u16, @intCast(ty.bitSize(mod))),
1193611936 };
1193711937 const max_reg_bit_width = Register.rax.bitSize();
1193811938 switch (int_info.signedness) {
1193911939 .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));
1194111941 try self.genShiftBinOpMir(
1194211942 .{ ._l, .sa },
1194311943 Type.isize,
......@@ -11952,7 +11952,7 @@ fn truncateRegister(self: *Self, ty: Type, reg: Register) !void {
1195211952 );
1195311953 },
1195411954 .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));
1195611956 const mask = (~@as(u64, 0)) >> shift;
1195711957 if (int_info.bits <= 32) {
1195811958 try self.genBinOpMir(
src/arch/x86_64/Emit.zig+14-14
......@@ -19,18 +19,18 @@ pub const Error = Lower.Error || error{
1919
2020pub fn emitMir(emit: *Emit) Error!void {
2121 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));
2323 try emit.code_offset_mapping.putNoClobber(
2424 emit.lower.allocator,
2525 mir_index,
26 @intCast(u32, emit.code.items.len),
26 @as(u32, @intCast(emit.code.items.len)),
2727 );
2828 const lowered = try emit.lower.lowerMir(mir_index);
2929 var lowered_relocs = lowered.relocs;
3030 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));
3232 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));
3434 while (lowered_relocs.len > 0 and
3535 lowered_relocs[0].lowered_inst_index == lowered_index) : ({
3636 lowered_relocs = lowered_relocs[1..];
......@@ -39,7 +39,7 @@ pub fn emitMir(emit: *Emit) Error!void {
3939 .source = start_offset,
4040 .target = target,
4141 .offset = end_offset - 4,
42 .length = @intCast(u5, end_offset - start_offset),
42 .length = @as(u5, @intCast(end_offset - start_offset)),
4343 }),
4444 .linker_extern_fn => |symbol| if (emit.bin_file.cast(link.File.MachO)) |macho_file| {
4545 // Add relocation to the decl.
......@@ -89,7 +89,7 @@ pub fn emitMir(emit: *Emit) Error!void {
8989 else => unreachable,
9090 },
9191 .target = .{ .sym_index = symbol.sym_index, .file = null },
92 .offset = @intCast(u32, end_offset - 4),
92 .offset = @as(u32, @intCast(end_offset - 4)),
9393 .addend = 0,
9494 .pcrel = true,
9595 .length = 2,
......@@ -113,7 +113,7 @@ pub fn emitMir(emit: *Emit) Error!void {
113113 .linker_import => coff_file.getGlobalByIndex(symbol.sym_index),
114114 else => unreachable,
115115 },
116 .offset = @intCast(u32, end_offset - 4),
116 .offset = @as(u32, @intCast(end_offset - 4)),
117117 .addend = 0,
118118 .pcrel = true,
119119 .length = 2,
......@@ -122,7 +122,7 @@ pub fn emitMir(emit: *Emit) Error!void {
122122 const atom_index = symbol.atom_index;
123123 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
124124 .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)),
126126 .addend = 0,
127127 .pcrel = true,
128128 });
......@@ -209,13 +209,13 @@ fn fixupRelocs(emit: *Emit) Error!void {
209209 for (emit.relocs.items) |reloc| {
210210 const target = emit.code_offset_mapping.get(reloc.target) orelse
211211 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))));
213213 mem.writeIntLittle(i32, emit.code.items[reloc.offset..][0..4], disp);
214214 }
215215}
216216
217217fn 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));
219219 const delta_pc: usize = emit.code.items.len - emit.prev_di_pc;
220220 log.debug(" (advance pc={d} and line={d})", .{ delta_line, delta_pc });
221221 switch (emit.debug_output) {
......@@ -233,22 +233,22 @@ fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) Error!void {
233233 // increasing the line number
234234 try @import("../../link/Plan9.zig").changeLine(dbg_out.dbg_line, delta_line);
235235 // increasing the pc
236 const d_pc_p9 = @intCast(i64, delta_pc) - quant;
236 const d_pc_p9 = @as(i64, @intCast(delta_pc)) - quant;
237237 if (d_pc_p9 > 0) {
238238 // minus one because if its the last one, we want to leave space to change the line which is one quanta
239239 var diff = @divExact(d_pc_p9, quant) - quant;
240240 while (diff > 0) {
241241 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)));
243243 diff = 0;
244244 } else {
245 try dbg_out.dbg_line.append(@intCast(u8, 64 + 128));
245 try dbg_out.dbg_line.append(@as(u8, @intCast(64 + 128)));
246246 diff -= 64;
247247 }
248248 }
249249 if (dbg_out.pcop_change_index.*) |pci|
250250 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));
252252 } else if (d_pc_p9 == 0) {
253253 // we don't need to do anything, because adding the quant does it for us
254254 } else unreachable;
src/arch/x86_64/Encoding.zig+2-2
......@@ -85,7 +85,7 @@ pub fn findByOpcode(opc: []const u8, prefixes: struct {
8585 rex: Rex,
8686}, modrm_ext: ?u3) ?Encoding {
8787 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 };
8989 if (modrm_ext) |ext| if (ext != data.modrm_ext) continue;
9090 if (!std.mem.eql(u8, opc, enc.opcode())) continue;
9191 if (prefixes.rex.w) {
......@@ -763,7 +763,7 @@ fn estimateInstructionLength(prefix: Prefix, encoding: Encoding, ops: []const Op
763763
764764 var cwriter = std.io.countingWriter(std.io.null_writer);
765765 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));
767767}
768768
769769const 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 {
188188 .pseudo_probe_align_ri_s => {
189189 try lower.emit(.none, .@"test", &.{
190190 .{ .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))) },
192192 });
193193 try lower.emit(.none, .jz, &.{
194194 .{ .imm = lower.reloc(.{ .inst = index + 1 }) },
......@@ -213,7 +213,7 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index) Error!struct {
213213 },
214214 .pseudo_probe_adjust_unrolled_ri_s => {
215215 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) {
217217 try lower.emit(.none, .@"test", &.{
218218 .{ .mem = Memory.sib(.dword, .{
219219 .base = .{ .reg = inst.data.ri.r1 },
......@@ -224,14 +224,14 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index) Error!struct {
224224 }
225225 try lower.emit(.none, .sub, &.{
226226 .{ .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))) },
228228 });
229229 assert(lower.result_insts_len <= pseudo_probe_adjust_unrolled_max_insts);
230230 },
231231 .pseudo_probe_adjust_setup_rri_s => {
232232 try lower.emit(.none, .mov, &.{
233233 .{ .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))) },
235235 });
236236 try lower.emit(.none, .sub, &.{
237237 .{ .reg = inst.data.rri.r1 },
......@@ -289,7 +289,7 @@ fn imm(lower: Lower, ops: Mir.Inst.Ops, i: u32) Immediate {
289289 .i_s,
290290 .mi_sib_s,
291291 .mi_rip_s,
292 => Immediate.s(@bitCast(i32, i)),
292 => Immediate.s(@as(i32, @bitCast(i))),
293293
294294 .rrri,
295295 .rri_u,
src/arch/x86_64/Mir.zig+17-17
......@@ -989,7 +989,7 @@ pub const RegisterList = struct {
989989
990990 fn getIndexForReg(registers: []const Register, reg: Register) BitSet.MaskInt {
991991 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));
993993 }
994994 unreachable; // register not in input register list!
995995 }
......@@ -1009,7 +1009,7 @@ pub const RegisterList = struct {
10091009 }
10101010
10111011 pub fn count(self: Self) u32 {
1012 return @intCast(u32, self.bitset.count());
1012 return @as(u32, @intCast(self.bitset.count()));
10131013 }
10141014};
10151015
......@@ -1023,15 +1023,15 @@ pub const Imm64 = struct {
10231023
10241024 pub fn encode(v: u64) Imm64 {
10251025 return .{
1026 .msb = @truncate(u32, v >> 32),
1027 .lsb = @truncate(u32, v),
1026 .msb = @as(u32, @truncate(v >> 32)),
1027 .lsb = @as(u32, @truncate(v)),
10281028 };
10291029 }
10301030
10311031 pub fn decode(imm: Imm64) u64 {
10321032 var res: u64 = 0;
1033 res |= (@intCast(u64, imm.msb) << 32);
1034 res |= @intCast(u64, imm.lsb);
1033 res |= (@as(u64, @intCast(imm.msb)) << 32);
1034 res |= @as(u64, @intCast(imm.lsb));
10351035 return res;
10361036 }
10371037};
......@@ -1070,18 +1070,18 @@ pub const MemorySib = struct {
10701070 }
10711071
10721072 pub fn decode(msib: MemorySib) Memory {
1073 const scale = @truncate(u4, msib.scale_index);
1073 const scale = @as(u4, @truncate(msib.scale_index));
10741074 assert(scale == 0 or std.math.isPowerOfTwo(scale));
10751075 return .{ .sib = .{
1076 .ptr_size = @enumFromInt(Memory.PtrSize, msib.ptr_size),
1077 .base = switch (@enumFromInt(Memory.Base.Tag, msib.base_tag)) {
1076 .ptr_size = @as(Memory.PtrSize, @enumFromInt(msib.ptr_size)),
1077 .base = switch (@as(Memory.Base.Tag, @enumFromInt(msib.base_tag))) {
10781078 .none => .none,
1079 .reg => .{ .reg = @enumFromInt(Register, msib.base) },
1080 .frame => .{ .frame = @enumFromInt(bits.FrameIndex, msib.base) },
1079 .reg => .{ .reg = @as(Register, @enumFromInt(msib.base)) },
1080 .frame => .{ .frame = @as(bits.FrameIndex, @enumFromInt(msib.base)) },
10811081 },
10821082 .scale_index = .{
10831083 .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,
10851085 },
10861086 .disp = msib.disp,
10871087 } };
......@@ -1103,7 +1103,7 @@ pub const MemoryRip = struct {
11031103
11041104 pub fn decode(mrip: MemoryRip) Memory {
11051105 return .{ .rip = .{
1106 .ptr_size = @enumFromInt(Memory.PtrSize, mrip.ptr_size),
1106 .ptr_size = @as(Memory.PtrSize, @enumFromInt(mrip.ptr_size)),
11071107 .disp = mrip.disp,
11081108 } };
11091109 }
......@@ -1120,14 +1120,14 @@ pub const MemoryMoffs = struct {
11201120 pub fn encode(seg: Register, offset: u64) MemoryMoffs {
11211121 return .{
11221122 .seg = @intFromEnum(seg),
1123 .msb = @truncate(u32, offset >> 32),
1124 .lsb = @truncate(u32, offset >> 0),
1123 .msb = @as(u32, @truncate(offset >> 32)),
1124 .lsb = @as(u32, @truncate(offset >> 0)),
11251125 };
11261126 }
11271127
11281128 pub fn decode(moffs: MemoryMoffs) Memory {
11291129 return .{ .moffs = .{
1130 .seg = @enumFromInt(Register, moffs.seg),
1130 .seg = @as(Register, @enumFromInt(moffs.seg)),
11311131 .offset = @as(u64, moffs.msb) << 32 | @as(u64, moffs.lsb) << 0,
11321132 } };
11331133 }
......@@ -1147,7 +1147,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: u32) struct { data: T, end:
11471147 inline for (fields) |field| {
11481148 @field(result, field.name) = switch (field.type) {
11491149 u32 => mir.extra[i],
1150 i32 => @bitCast(i32, mir.extra[i]),
1150 i32 => @as(i32, @bitCast(mir.extra[i])),
11511151 else => @compileError("bad field type"),
11521152 };
11531153 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 {
278278 // "Otherwise class SSE is used."
279279 result[result_i] = .sse;
280280 }
281 byte_i += @intCast(usize, field_size);
281 byte_i += @as(usize, @intCast(field_size));
282282 if (byte_i == 8) {
283283 byte_i = 0;
284284 result_i += 1;
......@@ -293,7 +293,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {
293293 result_i += field_class.len;
294294 // If there are any bytes leftover, we have to try to combine
295295 // the next field with them.
296 byte_i = @intCast(usize, field_size % 8);
296 byte_i = @as(usize, @intCast(field_size % 8));
297297 if (byte_i != 0) result_i -= 1;
298298 }
299299 }
src/arch/x86_64/bits.zig+16-16
......@@ -232,7 +232,7 @@ pub const Register = enum(u7) {
232232 else => unreachable,
233233 // zig fmt: on
234234 };
235 return @intCast(u6, @intFromEnum(reg) - base);
235 return @as(u6, @intCast(@intFromEnum(reg) - base));
236236 }
237237
238238 pub fn bitSize(reg: Register) u64 {
......@@ -291,11 +291,11 @@ pub const Register = enum(u7) {
291291 else => unreachable,
292292 // zig fmt: on
293293 };
294 return @truncate(u4, @intFromEnum(reg) - base);
294 return @as(u4, @truncate(@intFromEnum(reg) - base));
295295 }
296296
297297 pub fn lowEnc(reg: Register) u3 {
298 return @truncate(u3, reg.enc());
298 return @as(u3, @truncate(reg.enc()));
299299 }
300300
301301 pub fn toBitSize(reg: Register, bit_size: u64) Register {
......@@ -325,19 +325,19 @@ pub const Register = enum(u7) {
325325 }
326326
327327 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)));
329329 }
330330
331331 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)));
333333 }
334334
335335 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)));
337337 }
338338
339339 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)));
341341 }
342342
343343 fn sseBase(reg: Register) u7 {
......@@ -350,11 +350,11 @@ pub const Register = enum(u7) {
350350 }
351351
352352 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)));
354354 }
355355
356356 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)));
358358 }
359359
360360 /// DWARF register encoding
......@@ -363,7 +363,7 @@ pub const Register = enum(u7) {
363363 .general_purpose => if (reg.isExtended())
364364 reg.enc()
365365 else
366 @truncate(u3, @as(u24, 0o54673120) >> @as(u5, reg.enc()) * 3),
366 @as(u3, @truncate(@as(u24, 0o54673120) >> @as(u5, reg.enc()) * 3)),
367367 .sse => 17 + @as(u6, reg.enc()),
368368 .x87 => 33 + @as(u6, reg.enc()),
369369 .mmx => 41 + @as(u6, reg.enc()),
......@@ -610,15 +610,15 @@ pub const Immediate = union(enum) {
610610 pub fn asUnsigned(imm: Immediate, bit_size: u64) u64 {
611611 return switch (imm) {
612612 .signed => |x| switch (bit_size) {
613 1, 8 => @bitCast(u8, @intCast(i8, x)),
614 16 => @bitCast(u16, @intCast(i16, x)),
615 32, 64 => @bitCast(u32, x),
613 1, 8 => @as(u8, @bitCast(@as(i8, @intCast(x)))),
614 16 => @as(u16, @bitCast(@as(i16, @intCast(x)))),
615 32, 64 => @as(u32, @bitCast(x)),
616616 else => unreachable,
617617 },
618618 .unsigned => |x| switch (bit_size) {
619 1, 8 => @intCast(u8, x),
620 16 => @intCast(u16, x),
621 32 => @intCast(u32, x),
619 1, 8 => @as(u8, @intCast(x)),
620 16 => @as(u16, @intCast(x)),
621 32 => @as(u32, @intCast(x)),
622622 64 => x,
623623 else => unreachable,
624624 },
src/arch/x86_64/encoder.zig+7-7
......@@ -471,7 +471,7 @@ pub const Instruction = struct {
471471 } else {
472472 try encoder.sib_baseDisp8(dst);
473473 }
474 try encoder.disp8(@truncate(i8, sib.disp));
474 try encoder.disp8(@as(i8, @truncate(sib.disp)));
475475 } else {
476476 try encoder.modRm_SIBDisp32(src);
477477 if (mem.scaleIndex()) |si| {
......@@ -487,7 +487,7 @@ pub const Instruction = struct {
487487 try encoder.modRm_indirectDisp0(src, dst);
488488 } else if (math.cast(i8, sib.disp)) |_| {
489489 try encoder.modRm_indirectDisp8(src, dst);
490 try encoder.disp8(@truncate(i8, sib.disp));
490 try encoder.disp8(@as(i8, @truncate(sib.disp)));
491491 } else {
492492 try encoder.modRm_indirectDisp32(src, dst);
493493 try encoder.disp32(sib.disp);
......@@ -509,9 +509,9 @@ pub const Instruction = struct {
509509 fn encodeImm(imm: Immediate, kind: Encoding.Op, encoder: anytype) !void {
510510 const raw = imm.asUnsigned(kind.immBitSize());
511511 switch (kind.immBitSize()) {
512 8 => try encoder.imm8(@intCast(u8, raw)),
513 16 => try encoder.imm16(@intCast(u16, raw)),
514 32 => try encoder.imm32(@intCast(u32, raw)),
512 8 => try encoder.imm8(@as(u8, @intCast(raw))),
513 16 => try encoder.imm16(@as(u16, @intCast(raw))),
514 32 => try encoder.imm32(@as(u32, @intCast(raw))),
515515 64 => try encoder.imm64(raw),
516516 else => unreachable,
517517 }
......@@ -581,7 +581,7 @@ fn Encoder(comptime T: type, comptime opts: Options) type {
581581
582582 /// Encodes legacy prefixes
583583 pub fn legacyPrefixes(self: Self, prefixes: LegacyPrefixes) !void {
584 if (@bitCast(u16, prefixes) != 0) {
584 if (@as(u16, @bitCast(prefixes)) != 0) {
585585 // Hopefully this path isn't taken very often, so we'll do it the slow way for now
586586
587587 // LOCK
......@@ -891,7 +891,7 @@ fn Encoder(comptime T: type, comptime opts: Options) type {
891891 ///
892892 /// It is sign-extended to 64 bits by the cpu.
893893 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)));
895895 }
896896
897897 /// Encode an 32 bit displacement
src/clang.zig+1-1
......@@ -117,7 +117,7 @@ pub const APFloatBaseSemantics = enum(c_int) {
117117
118118pub const APInt = opaque {
119119 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))));
121121 }
122122 extern fn ZigClangAPInt_getLimitedValue(*const APInt, limit: u64) u64;
123123};
src/codegen.zig+19-19
......@@ -108,7 +108,7 @@ fn writeFloat(comptime F: type, f: F, target: Target, endian: std.builtin.Endian
108108 _ = target;
109109 const bits = @typeInfo(F).Float.bits;
110110 const Int = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = bits } });
111 const int = @bitCast(Int, f);
111 const int = @as(Int, @bitCast(f));
112112 mem.writeInt(Int, code[0..@divExact(bits, 8)], int, endian);
113113}
114114
......@@ -143,18 +143,18 @@ pub fn generateLazySymbol(
143143 if (lazy_sym.ty.isAnyError(mod)) {
144144 alignment.* = 4;
145145 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);
147147 var offset = code.items.len;
148148 try code.resize((1 + err_names.len + 1) * 4);
149149 for (err_names) |err_name_nts| {
150150 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);
152152 offset += 4;
153153 try code.ensureUnusedCapacity(err_name.len + 1);
154154 code.appendSliceAssumeCapacity(err_name);
155155 code.appendAssumeCapacity(0);
156156 }
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);
158158 return Result.ok;
159159 } else if (lazy_sym.ty.zigTypeTag(mod) == .Enum) {
160160 alignment.* = 1;
......@@ -253,12 +253,12 @@ pub fn generateSymbol(
253253 },
254254 .err => |err| {
255255 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);
257257 },
258258 .error_union => |error_union| {
259259 const payload_ty = typed_value.ty.errorUnionPayload(mod);
260260 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))),
262262 .payload => @as(u16, 0),
263263 };
264264
......@@ -397,7 +397,7 @@ pub fn generateSymbol(
397397 .ty = array_type.child.toType(),
398398 .val = switch (aggregate.storage) {
399399 .bytes => unreachable,
400 .elems => |elems| elems[@intCast(usize, index)],
400 .elems => |elems| elems[@as(usize, @intCast(index))],
401401 .repeated_elem => |elem| elem,
402402 }.toValue(),
403403 }, code, debug_output, reloc_info)) {
......@@ -417,7 +417,7 @@ pub fn generateSymbol(
417417 .ty = vector_type.child.toType(),
418418 .val = switch (aggregate.storage) {
419419 .bytes => unreachable,
420 .elems => |elems| elems[@intCast(usize, index)],
420 .elems => |elems| elems[@as(usize, @intCast(index))],
421421 .repeated_elem => |elem| elem,
422422 }.toValue(),
423423 }, code, debug_output, reloc_info)) {
......@@ -509,7 +509,7 @@ pub fn generateSymbol(
509509 } else {
510510 field_val.toValue().writeToPackedMemory(field_ty, mod, code.items[current_pos..], bits) catch unreachable;
511511 }
512 bits += @intCast(u16, field_ty.bitSize(mod));
512 bits += @as(u16, @intCast(field_ty.bitSize(mod)));
513513 }
514514 } else {
515515 const struct_begin = code.items.len;
......@@ -642,10 +642,10 @@ fn lowerParentPtr(
642642 eu_payload,
643643 code,
644644 debug_output,
645 reloc_info.offset(@intCast(u32, errUnionPayloadOffset(
645 reloc_info.offset(@as(u32, @intCast(errUnionPayloadOffset(
646646 mod.intern_pool.typeOf(eu_payload).toType(),
647647 mod,
648 ))),
648 )))),
649649 ),
650650 .opt_payload => |opt_payload| try lowerParentPtr(
651651 bin_file,
......@@ -661,8 +661,8 @@ fn lowerParentPtr(
661661 elem.base,
662662 code,
663663 debug_output,
664 reloc_info.offset(@intCast(u32, elem.index *
665 mod.intern_pool.typeOf(elem.base).toType().elemType2(mod).abiSize(mod))),
664 reloc_info.offset(@as(u32, @intCast(elem.index *
665 mod.intern_pool.typeOf(elem.base).toType().elemType2(mod).abiSize(mod)))),
666666 ),
667667 .field => |field| {
668668 const base_type = mod.intern_pool.indexToKey(mod.intern_pool.typeOf(field.base)).ptr_type.child;
......@@ -684,10 +684,10 @@ fn lowerParentPtr(
684684 .struct_type,
685685 .anon_struct_type,
686686 .union_type,
687 => @intCast(u32, base_type.toType().structFieldOffset(
688 @intCast(u32, field.index),
687 => @as(u32, @intCast(base_type.toType().structFieldOffset(
688 @as(u32, @intCast(field.index)),
689689 mod,
690 )),
690 ))),
691691 else => unreachable,
692692 }),
693693 );
......@@ -735,8 +735,8 @@ fn lowerDeclRef(
735735 });
736736 const endian = target.cpu.arch.endian();
737737 switch (ptr_width) {
738 16 => mem.writeInt(u16, try code.addManyAsArray(2), @intCast(u16, vaddr), endian),
739 32 => mem.writeInt(u32, try code.addManyAsArray(4), @intCast(u32, 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), @as(u32, @intCast(vaddr)), endian),
740740 64 => mem.writeInt(u64, try code.addManyAsArray(8), vaddr, endian),
741741 else => unreachable,
742742 }
......@@ -945,7 +945,7 @@ pub fn genTypedValue(
945945 const info = typed_value.ty.intInfo(mod);
946946 if (info.bits <= ptr_bits) {
947947 const unsigned = switch (info.signedness) {
948 .signed => @bitCast(u64, typed_value.val.toSignedInt(mod)),
948 .signed => @as(u64, @bitCast(typed_value.val.toSignedInt(mod))),
949949 .unsigned => typed_value.val.toUnsignedInt(mod),
950950 };
951951 return GenResult.mcv(.{ .immediate = unsigned });
src/codegen/c.zig+52-52
......@@ -326,7 +326,7 @@ pub const Function = struct {
326326 .cty_idx = try f.typeToIndex(ty, .complete),
327327 .alignas = CType.AlignAs.init(alignment, ty.abiAlignment(mod)),
328328 });
329 return .{ .new_local = @intCast(LocalIndex, f.locals.items.len - 1) };
329 return .{ .new_local = @as(LocalIndex, @intCast(f.locals.items.len - 1)) };
330330 }
331331
332332 fn allocLocal(f: *Function, inst: Air.Inst.Index, ty: Type) !CValue {
......@@ -644,7 +644,7 @@ pub const DeclGen = struct {
644644 // Ensure complete type definition is visible before accessing fields.
645645 _ = try dg.typeToIndex(base_ty, .complete);
646646 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),
648648 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
649649 .One, .Many, .C => unreachable,
650650 .Slice => switch (field.index) {
......@@ -662,7 +662,7 @@ pub const DeclGen = struct {
662662 try dg.renderCType(writer, ptr_cty);
663663 try writer.writeByte(')');
664664 }
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)) {
666666 .begin => try dg.renderParentPtr(writer, field.base, location),
667667 .field => |name| {
668668 try writer.writeAll("&(");
......@@ -740,11 +740,11 @@ pub const DeclGen = struct {
740740 try dg.renderTypeForBuiltinFnName(writer, ty);
741741 try writer.writeByte('(');
742742 switch (bits) {
743 16 => try writer.print("{x}", .{@bitCast(f16, undefPattern(i16))}),
744 32 => try writer.print("{x}", .{@bitCast(f32, undefPattern(i32))}),
745 64 => try writer.print("{x}", .{@bitCast(f64, undefPattern(i64))}),
746 80 => try writer.print("{x}", .{@bitCast(f80, undefPattern(i80))}),
747 128 => try writer.print("{x}", .{@bitCast(f128, undefPattern(i128))}),
743 16 => try writer.print("{x}", .{@as(f16, @bitCast(undefPattern(i16)))}),
744 32 => try writer.print("{x}", .{@as(f32, @bitCast(undefPattern(i32)))}),
745 64 => try writer.print("{x}", .{@as(f64, @bitCast(undefPattern(i64)))}),
746 80 => try writer.print("{x}", .{@as(f80, @bitCast(undefPattern(i80)))}),
747 128 => try writer.print("{x}", .{@as(f128, @bitCast(undefPattern(i128)))}),
748748 else => unreachable,
749749 }
750750 try writer.writeAll(", ");
......@@ -1041,11 +1041,11 @@ pub const DeclGen = struct {
10411041 };
10421042
10431043 switch (bits) {
1044 16 => repr_val_big.set(@bitCast(u16, val.toFloat(f16, mod))),
1045 32 => repr_val_big.set(@bitCast(u32, val.toFloat(f32, mod))),
1046 64 => repr_val_big.set(@bitCast(u64, val.toFloat(f64, mod))),
1047 80 => repr_val_big.set(@bitCast(u80, val.toFloat(f80, mod))),
1048 128 => repr_val_big.set(@bitCast(u128, f128_val)),
1044 16 => repr_val_big.set(@as(u16, @bitCast(val.toFloat(f16, mod)))),
1045 32 => repr_val_big.set(@as(u32, @bitCast(val.toFloat(f32, mod)))),
1046 64 => repr_val_big.set(@as(u64, @bitCast(val.toFloat(f64, mod)))),
1047 80 => repr_val_big.set(@as(u80, @bitCast(val.toFloat(f80, mod)))),
1048 128 => repr_val_big.set(@as(u128, @bitCast(f128_val))),
10491049 else => unreachable,
10501050 }
10511051
......@@ -1103,11 +1103,11 @@ pub const DeclGen = struct {
11031103 if (std.math.isNan(f128_val)) switch (bits) {
11041104 // We only actually need to pass the significand, but it will get
11051105 // properly masked anyway, so just pass the whole value.
1106 16 => try writer.print("\"0x{x}\"", .{@bitCast(u16, val.toFloat(f16, mod))}),
1107 32 => try writer.print("\"0x{x}\"", .{@bitCast(u32, val.toFloat(f32, mod))}),
1108 64 => try writer.print("\"0x{x}\"", .{@bitCast(u64, val.toFloat(f64, mod))}),
1109 80 => try writer.print("\"0x{x}\"", .{@bitCast(u80, val.toFloat(f80, mod))}),
1110 128 => try writer.print("\"0x{x}\"", .{@bitCast(u128, f128_val)}),
1106 16 => try writer.print("\"0x{x}\"", .{@as(u16, @bitCast(val.toFloat(f16, mod)))}),
1107 32 => try writer.print("\"0x{x}\"", .{@as(u32, @bitCast(val.toFloat(f32, mod)))}),
1108 64 => try writer.print("\"0x{x}\"", .{@as(u64, @bitCast(val.toFloat(f64, mod)))}),
1109 80 => try writer.print("\"0x{x}\"", .{@as(u80, @bitCast(val.toFloat(f80, mod)))}),
1110 128 => try writer.print("\"0x{x}\"", .{@as(u128, @bitCast(f128_val))}),
11111111 else => unreachable,
11121112 };
11131113 try writer.writeAll(", ");
......@@ -1225,11 +1225,11 @@ pub const DeclGen = struct {
12251225 var index: usize = 0;
12261226 while (index < ai.len) : (index += 1) {
12271227 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)));
12291229 try literal.writeChar(elem_val_u8);
12301230 }
12311231 if (ai.sentinel) |s| {
1232 const s_u8 = @intCast(u8, s.toUnsignedInt(mod));
1232 const s_u8 = @as(u8, @intCast(s.toUnsignedInt(mod)));
12331233 if (s_u8 != 0) try literal.writeChar(s_u8);
12341234 }
12351235 try literal.end();
......@@ -1239,7 +1239,7 @@ pub const DeclGen = struct {
12391239 while (index < ai.len) : (index += 1) {
12401240 if (index != 0) try writer.writeByte(',');
12411241 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)));
12431243 try writer.print("'\\x{x}'", .{elem_val_u8});
12441244 }
12451245 if (ai.sentinel) |s| {
......@@ -1840,7 +1840,7 @@ pub const DeclGen = struct {
18401840 decl.ty,
18411841 .{ .decl = decl_index },
18421842 CQualifiers.init(.{ .@"const" = variable.is_const }),
1843 @intCast(u32, decl.alignment.toByteUnits(0)),
1843 @as(u32, @intCast(decl.alignment.toByteUnits(0))),
18441844 .complete,
18451845 );
18461846 try fwd_decl_writer.writeAll(";\n");
......@@ -1907,7 +1907,7 @@ pub const DeclGen = struct {
19071907 const mod = dg.module;
19081908 const int_info = if (ty.isAbiInt(mod)) ty.intInfo(mod) else std.builtin.Type.Int{
19091909 .signedness = .unsigned,
1910 .bits = @intCast(u16, ty.bitSize(mod)),
1910 .bits = @as(u16, @intCast(ty.bitSize(mod))),
19111911 };
19121912
19131913 if (is_big) try writer.print(", {}", .{int_info.signedness == .signed});
......@@ -2481,7 +2481,7 @@ fn genExports(o: *Object) !void {
24812481 if (mod.decl_exports.get(o.dg.decl_index.unwrap().?)) |exports| {
24822482 for (exports.items[1..], 1..) |@"export", i| {
24832483 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)) });
24852485 try fwd_decl_writer.print(", {s}, {s});\n", .{
24862486 fmtStringLiteral(ip.stringToSlice(exports.items[0].opts.name), null),
24872487 fmtStringLiteral(ip.stringToSlice(@"export".opts.name), null),
......@@ -2510,7 +2510,7 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void {
25102510 try o.dg.renderTypeAndName(w, enum_ty, .{ .identifier = "tag" }, Const, 0, .complete);
25112511 try w.writeAll(") {\n switch (tag) {\n");
25122512 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));
25142514 const name = mod.intern_pool.stringToSlice(name_ip);
25152515 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
27832783 // Remember how many locals there were before entering the body so that we can free any that
27842784 // were newly introduced. Any new locals must necessarily be logically free after the then
27852785 // 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
27882788 for (leading_deaths) |death| {
27892789 try die(f, inst, Air.indexToRef(death));
......@@ -2804,7 +2804,7 @@ fn genBodyResolveState(f: *Function, inst: Air.Inst.Index, leading_deaths: []con
28042804 // them, unless they were used to store allocs.
28052805
28062806 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));
28082808 if (f.allocs.contains(local_index)) {
28092809 continue;
28102810 }
......@@ -3364,7 +3364,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
33643364 const bit_offset_ty = try mod.intType(.unsigned, Type.smallestUnsignedBits(host_bits - 1));
33653365 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
33693369 try f.writeCValue(writer, local, .Other);
33703370 try v.elem(f, writer);
......@@ -3667,7 +3667,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
36673667 var mask = try BigInt.Managed.initCapacity(stack.get(), BigInt.calcTwosCompLimbCount(host_bits));
36683668 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)));
36713671 try mask.shiftLeft(&mask, ptr_info.packed_offset.bit_offset);
36723672 try mask.bitNotWrap(&mask, .unsigned, host_bits);
36733673
......@@ -4096,7 +4096,7 @@ fn airCall(
40964096
40974097 const pl_op = f.air.instructions.items(.data)[inst].pl_op;
40984098 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
41014101 const resolved_args = try gpa.alloc(CValue, args.len);
41024102 defer gpa.free(resolved_args);
......@@ -4537,7 +4537,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca
45374537 wrap_cty = elem_cty.toSignedness(dest_info.signedness);
45384538 need_bitcasts = wrap_cty.?.tag() == .zig_i128;
45394539 bits -= 1;
4540 bits %= @intCast(u16, f.byteSize(elem_cty) * 8);
4540 bits %= @as(u16, @intCast(f.byteSize(elem_cty) * 8));
45414541 bits += 1;
45424542 }
45434543 try writer.writeAll(" = ");
......@@ -4711,7 +4711,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
47114711 var extra_index: usize = switch_br.end;
47124712 for (0..switch_br.data.cases_len) |case_i| {
47134713 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]));
47154715 const case_body = f.air.extra[case.end + items.len ..][0..case.data.body_len];
47164716 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 {
47714771 const mod = f.object.dg.module;
47724772 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
47734773 const extra = f.air.extraData(Air.Asm, ty_pl.payload);
4774 const is_volatile = @truncate(u1, extra.data.flags >> 31) != 0;
4775 const clobbers_len = @truncate(u31, extra.data.flags);
4774 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
4775 const clobbers_len = @as(u31, @truncate(extra.data.flags));
47764776 const gpa = f.object.dg.gpa;
47774777 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]));
47794779 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]));
47814781 extra_i += inputs.len;
47824782
47834783 const result = result: {
......@@ -4794,7 +4794,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
47944794 break :local local;
47954795 } else .none;
47964796
4797 const locals_begin = @intCast(LocalIndex, f.locals.items.len);
4797 const locals_begin = @as(LocalIndex, @intCast(f.locals.items.len));
47984798 const constraints_extra_begin = extra_i;
47994799 for (outputs) |output| {
48004800 const extra_bytes = mem.sliceAsBytes(f.air.extra[extra_i..]);
......@@ -5402,7 +5402,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
54025402 inst_ty.intInfo(mod).signedness
54035403 else
54045404 .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
54075407 const temp_local = try f.allocLocal(inst, field_int_ty);
54085408 try f.writeCValue(writer, temp_local, .Other);
......@@ -5855,7 +5855,7 @@ fn airIntFromPtr(f: *Function, inst: Air.Inst.Index) !CValue {
58555855 try f.renderType(writer, inst_ty);
58565856 try writer.writeByte(')');
58575857 if (operand_ty.isSlice(mod)) {
5858 try f.writeCValueMember(writer, operand, .{ .identifier = "len" });
5858 try f.writeCValueMember(writer, operand, .{ .identifier = "ptr" });
58595859 } else {
58605860 try f.writeCValue(writer, operand, .Other);
58615861 }
......@@ -6033,7 +6033,7 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue
60336033 try reap(f, inst, &.{ extra.ptr, extra.expected_value, extra.new_value });
60346034
60356035 const repr_ty = if (ty.isRuntimeFloat())
6036 mod.intType(.unsigned, @intCast(u16, ty.abiSize(mod) * 8)) catch unreachable
6036 mod.intType(.unsigned, @as(u16, @intCast(ty.abiSize(mod) * 8))) catch unreachable
60376037 else
60386038 ty;
60396039
......@@ -6136,7 +6136,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {
61366136 const operand_mat = try Materialize.start(f, inst, writer, ty, operand);
61376137 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));
61406140 const is_float = ty.isRuntimeFloat();
61416141 const is_128 = repr_bits == 128;
61426142 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 {
61866186 const ty = ptr_ty.childType(mod);
61876187
61886188 const repr_ty = if (ty.isRuntimeFloat())
6189 mod.intType(.unsigned, @intCast(u16, ty.abiSize(mod) * 8)) catch unreachable
6189 mod.intType(.unsigned, @as(u16, @intCast(ty.abiSize(mod) * 8))) catch unreachable
61906190 else
61916191 ty;
61926192
......@@ -6226,7 +6226,7 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa
62266226 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
62276227
62286228 const repr_ty = if (ty.isRuntimeFloat())
6229 mod.intType(.unsigned, @intCast(u16, ty.abiSize(mod) * 8)) catch unreachable
6229 mod.intType(.unsigned, @as(u16, @intCast(ty.abiSize(mod) * 8))) catch unreachable
62306230 else
62316231 ty;
62326232
......@@ -6574,7 +6574,7 @@ fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {
65746574 try writer.writeAll("] = ");
65756575
65766576 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
65796579 try f.writeCValue(writer, if (mask_elem >= 0) lhs else rhs, .Other);
65806580 try writer.writeByte('[');
......@@ -6745,8 +6745,8 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
67456745 const ip = &mod.intern_pool;
67466746 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
67476747 const inst_ty = f.typeOfIndex(inst);
6748 const len = @intCast(usize, inst_ty.arrayLen(mod));
6749 const elements = @ptrCast([]const Air.Inst.Ref, f.air.extra[ty_pl.payload..][0..len]);
6748 const len = @as(usize, @intCast(inst_ty.arrayLen(mod)));
6749 const elements = @as([]const Air.Inst.Ref, @ptrCast(f.air.extra[ty_pl.payload..][0..len]));
67506750 const gpa = f.object.dg.gpa;
67516751 const resolved_elements = try gpa.alloc(CValue, elements.len);
67526752 defer gpa.free(resolved_elements);
......@@ -7387,7 +7387,7 @@ fn fmtStringLiteral(str: []const u8, sentinel: ?u8) std.fmt.Formatter(formatStri
73877387fn undefPattern(comptime IntType: type) IntType {
73887388 const int_info = @typeInfo(IntType).Int;
73897389 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)));
73917391}
73927392
73937393const FormatIntLiteralContext = struct {
......@@ -7438,7 +7438,7 @@ fn formatIntLiteral(
74387438 } else data.val.toBigInt(&int_buf, mod);
74397439 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));
74427442 var one_limbs: [BigInt.calcLimbLen(1)]BigIntLimb = undefined;
74437443 const one = BigInt.Mutable.init(&one_limbs, 1).toConst();
74447444
......@@ -7471,7 +7471,7 @@ fn formatIntLiteral(
74717471 const array_data = data.cty.castTag(.array).?.data;
74727472 break :info .{
74737473 .cty = data.dg.indexToCType(array_data.elem_type),
7474 .count = @intCast(usize, array_data.len),
7474 .count = @as(usize, @intCast(array_data.len)),
74757475 .endian = target.cpu.arch.endian(),
74767476 .homogeneous = true,
74777477 };
......@@ -7527,7 +7527,7 @@ fn formatIntLiteral(
75277527
75287528 var c_limb_int_info = std.builtin.Type.Int{
75297529 .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))),
75317531 };
75327532 var c_limb_cty: CType = undefined;
75337533
......@@ -7727,7 +7727,7 @@ fn lowerFnRetTy(ret_ty: Type, mod: *Module) !Type {
77277727fn lowersToArray(ty: Type, mod: *Module) bool {
77287728 return switch (ty.zigTypeTag(mod)) {
77297729 .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,
77317731 };
77327732}
77337733
......@@ -7735,7 +7735,7 @@ fn reap(f: *Function, inst: Air.Inst.Index, operands: []const Air.Inst.Ref) !voi
77357735 assert(operands.len <= Liveness.bpi - 1);
77367736 var tomb_bits = f.liveness.getTombBits(inst);
77377737 for (operands) |operand| {
7738 const dies = @truncate(u1, tomb_bits) != 0;
7738 const dies = @as(u1, @truncate(tomb_bits)) != 0;
77397739 tomb_bits >>= 1;
77407740 if (!dies) continue;
77417741 try die(f, inst, operand);
src/codegen/c/type.zig+10-10
......@@ -138,7 +138,7 @@ pub const CType = extern union {
138138
139139 pub fn toIndex(self: Tag) Index {
140140 assert(!self.hasPayload());
141 return @intCast(Index, @intFromEnum(self));
141 return @as(Index, @intCast(@intFromEnum(self)));
142142 }
143143
144144 pub fn Type(comptime self: Tag) type {
......@@ -330,7 +330,7 @@ pub const CType = extern union {
330330 store: *const Set,
331331
332332 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.*)));
334334 }
335335 pub fn eql(_: @This(), lhs: CType, rhs: CType, _: usize) bool {
336336 return lhs.eql(rhs);
......@@ -340,7 +340,7 @@ pub const CType = extern union {
340340 map: Map = .{},
341341
342342 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)));
344344 return self.map.keys()[index - Tag.no_payload_count];
345345 }
346346
......@@ -362,7 +362,7 @@ pub const CType = extern union {
362362 return if (self.map.getIndexAdapted(
363363 ty,
364364 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;
366366 }
367367 };
368368
......@@ -376,7 +376,7 @@ pub const CType = extern union {
376376
377377 pub fn cTypeToIndex(self: *Promoted, cty: CType) Allocator.Error!Index {
378378 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
381381 const gop = try self.set.map.getOrPutContext(self.gpa(), cty, .{ .store = &self.set });
382382 if (!gop.found_existing) gop.key_ptr.* = cty;
......@@ -386,7 +386,7 @@ pub const CType = extern union {
386386 assert(cty.eql(key.*));
387387 assert(cty.hash(self.set) == key.hash(self.set));
388388 }
389 return @intCast(Index, Tag.no_payload_count + gop.index);
389 return @as(Index, @intCast(Tag.no_payload_count + gop.index));
390390 }
391391
392392 pub fn typeToIndex(
......@@ -424,7 +424,7 @@ pub const CType = extern union {
424424 assert(adapter.eql(ty, cty.*));
425425 assert(adapter.hash(ty) == cty.hash(self.set));
426426 }
427 return @intCast(Index, Tag.no_payload_count + gop.index);
427 return @as(Index, @intCast(Tag.no_payload_count + gop.index));
428428 }
429429 };
430430
......@@ -1388,7 +1388,7 @@ pub const CType = extern union {
13881388 .len = @divExact(abi_size, abi_align),
13891389 .elem_type = tagFromIntInfo(.{
13901390 .signedness = .unsigned,
1391 .bits = @intCast(u16, abi_align * 8),
1391 .bits = @as(u16, @intCast(abi_align * 8)),
13921392 }).toIndex(),
13931393 } } };
13941394 self.value = .{ .cty = initPayload(&self.storage.seq) };
......@@ -1492,7 +1492,7 @@ pub const CType = extern union {
14921492 if (mod.typeToStruct(ty)) |struct_obj| {
14931493 try self.initType(struct_obj.backing_int_ty, kind, lookup);
14941494 } else {
1495 const bits = @intCast(u16, ty.bitSize(mod));
1495 const bits = @as(u16, @intCast(ty.bitSize(mod)));
14961496 const int_ty = try mod.intType(.unsigned, bits);
14971497 try self.initType(int_ty, kind, lookup);
14981498 }
......@@ -2299,7 +2299,7 @@ pub const CType = extern union {
22992299 }
23002300
23012301 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)));
23032303 }
23042304 };
23052305};
src/codegen/llvm.zig+132-132
......@@ -592,7 +592,7 @@ pub const Object = struct {
592592 llvm_errors[0] = llvm_slice_ty.getUndef();
593593 for (llvm_errors[1..], error_name_list[1..]) |*llvm_error, name_nts| {
594594 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);
596596 const str_global = o.llvm_module.addGlobal(str_init.typeOf(), "");
597597 str_global.setInitializer(str_init);
598598 str_global.setLinkage(.Private);
......@@ -607,7 +607,7 @@ pub const Object = struct {
607607 llvm_error.* = llvm_slice_ty.constNamedStruct(&slice_fields, slice_fields.len);
608608 }
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
612612 const error_name_table_global = o.llvm_module.addGlobal(error_name_table_init.typeOf(), "");
613613 error_name_table_global.setInitializer(error_name_table_init);
......@@ -1027,7 +1027,7 @@ pub const Object = struct {
10271027 llvm_arg_i += 1;
10281028
10291029 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)));
10311031 const int_llvm_ty = o.context.intType(abi_size * 8);
10321032 const alignment = @max(
10331033 param_ty.abiAlignment(mod),
......@@ -1053,7 +1053,7 @@ pub const Object = struct {
10531053 const ptr_info = param_ty.ptrInfo(mod);
10541054
10551055 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) {
10571057 o.addArgAttr(llvm_func, llvm_arg_i, "noalias");
10581058 }
10591059 }
......@@ -1083,9 +1083,9 @@ pub const Object = struct {
10831083 const param_llvm_ty = try o.lowerType(param_ty);
10841084 const param_alignment = param_ty.abiAlignment(mod);
10851085 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);
10871087 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));
10891089 const param = llvm_func.getParam(llvm_arg_i);
10901090 llvm_arg_i += 1;
10911091 const field_ptr = builder.buildStructGEP(llvm_ty, arg_ptr, field_i, "");
......@@ -1289,11 +1289,11 @@ pub const Object = struct {
12891289 if (mod.wantDllExports()) llvm_global.setDLLStorageClass(.Default);
12901290 if (self.di_map.get(decl)) |di_node| {
12911291 if (try decl.isFunction(mod)) {
1292 const di_func = @ptrCast(*llvm.DISubprogram, di_node);
1292 const di_func = @as(*llvm.DISubprogram, @ptrCast(di_node));
12931293 const linkage_name = llvm.MDString.get(self.context, decl_name.ptr, decl_name.len);
12941294 di_func.replaceLinkageName(linkage_name);
12951295 } else {
1296 const di_global = @ptrCast(*llvm.DIGlobalVariable, di_node);
1296 const di_global = @as(*llvm.DIGlobalVariable, @ptrCast(di_node));
12971297 const linkage_name = llvm.MDString.get(self.context, decl_name.ptr, decl_name.len);
12981298 di_global.replaceLinkageName(linkage_name);
12991299 }
......@@ -1315,11 +1315,11 @@ pub const Object = struct {
13151315 if (mod.wantDllExports()) llvm_global.setDLLStorageClass(.DLLExport);
13161316 if (self.di_map.get(decl)) |di_node| {
13171317 if (try decl.isFunction(mod)) {
1318 const di_func = @ptrCast(*llvm.DISubprogram, di_node);
1318 const di_func = @as(*llvm.DISubprogram, @ptrCast(di_node));
13191319 const linkage_name = llvm.MDString.get(self.context, exp_name.ptr, exp_name.len);
13201320 di_func.replaceLinkageName(linkage_name);
13211321 } else {
1322 const di_global = @ptrCast(*llvm.DIGlobalVariable, di_node);
1322 const di_global = @as(*llvm.DIGlobalVariable, @ptrCast(di_node));
13231323 const linkage_name = llvm.MDString.get(self.context, exp_name.ptr, exp_name.len);
13241324 di_global.replaceLinkageName(linkage_name);
13251325 }
......@@ -1390,7 +1390,7 @@ pub const Object = struct {
13901390 const gop = try o.di_map.getOrPut(gpa, file);
13911391 errdefer assert(o.di_map.remove(file));
13921392 if (gop.found_existing) {
1393 return @ptrCast(*llvm.DIFile, gop.value_ptr.*);
1393 return @as(*llvm.DIFile, @ptrCast(gop.value_ptr.*));
13941394 }
13951395 const dir_path_z = d: {
13961396 var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
......@@ -1514,7 +1514,7 @@ pub const Object = struct {
15141514 if (@sizeOf(usize) == @sizeOf(u64)) {
15151515 enumerators[i] = dib.createEnumerator2(
15161516 field_name_z,
1517 @intCast(c_uint, bigint.limbs.len),
1517 @as(c_uint, @intCast(bigint.limbs.len)),
15181518 bigint.limbs.ptr,
15191519 int_info.bits,
15201520 int_info.signedness == .unsigned,
......@@ -1538,7 +1538,7 @@ pub const Object = struct {
15381538 ty.abiSize(mod) * 8,
15391539 ty.abiAlignment(mod) * 8,
15401540 enumerators.ptr,
1541 @intCast(c_int, enumerators.len),
1541 @as(c_int, @intCast(enumerators.len)),
15421542 try o.lowerDebugType(int_ty, .full),
15431543 "",
15441544 );
......@@ -1713,7 +1713,7 @@ pub const Object = struct {
17131713 ty.abiSize(mod) * 8,
17141714 ty.abiAlignment(mod) * 8,
17151715 try o.lowerDebugType(ty.childType(mod), .full),
1716 @intCast(i64, ty.arrayLen(mod)),
1716 @as(i64, @intCast(ty.arrayLen(mod))),
17171717 );
17181718 // The recursive call to `lowerDebugType` means we can't use `gop` anymore.
17191719 try o.di_type_map.put(gpa, ty.toIntern(), AnnotatedDITypePtr.initFull(array_di_ty));
......@@ -2018,7 +2018,7 @@ pub const Object = struct {
20182018 0, // flags
20192019 null, // derived from
20202020 di_fields.items.ptr,
2021 @intCast(c_int, di_fields.items.len),
2021 @as(c_int, @intCast(di_fields.items.len)),
20222022 0, // run time lang
20232023 null, // vtable holder
20242024 "", // unique id
......@@ -2105,7 +2105,7 @@ pub const Object = struct {
21052105 0, // flags
21062106 null, // derived from
21072107 di_fields.items.ptr,
2108 @intCast(c_int, di_fields.items.len),
2108 @as(c_int, @intCast(di_fields.items.len)),
21092109 0, // run time lang
21102110 null, // vtable holder
21112111 "", // unique id
......@@ -2217,7 +2217,7 @@ pub const Object = struct {
22172217 ty.abiAlignment(mod) * 8, // align in bits
22182218 0, // flags
22192219 di_fields.items.ptr,
2220 @intCast(c_int, di_fields.items.len),
2220 @as(c_int, @intCast(di_fields.items.len)),
22212221 0, // run time lang
22222222 "", // unique id
22232223 );
......@@ -2330,7 +2330,7 @@ pub const Object = struct {
23302330
23312331 const fn_di_ty = dib.createSubroutineType(
23322332 param_di_types.items.ptr,
2333 @intCast(c_int, param_di_types.items.len),
2333 @as(c_int, @intCast(param_di_types.items.len)),
23342334 0,
23352335 );
23362336 // The recursive call to `lowerDebugType` means we can't use `gop` anymore.
......@@ -2487,7 +2487,7 @@ pub const Object = struct {
24872487 }
24882488
24892489 if (fn_info.alignment.toByteUnitsOptional()) |a| {
2490 llvm_fn.setAlignment(@intCast(c_uint, a));
2490 llvm_fn.setAlignment(@as(c_uint, @intCast(a)));
24912491 }
24922492
24932493 // Function attributes that are independent of analysis results of the function body.
......@@ -2710,7 +2710,7 @@ pub const Object = struct {
27102710 if (std.debug.runtime_safety) assert((try elem_ty.onePossibleValue(mod)) == null);
27112711 const elem_llvm_ty = try o.lowerType(elem_ty);
27122712 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)));
27142714 },
27152715 .Vector => {
27162716 const elem_type = try o.lowerType(t.childType(mod));
......@@ -2732,7 +2732,7 @@ pub const Object = struct {
27322732 };
27332733 const offset = child_ty.abiSize(mod) + 1;
27342734 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));
27362736 if (padding == 0) {
27372737 return o.context.structType(&fields_buf, 2, .False);
27382738 }
......@@ -2761,7 +2761,7 @@ pub const Object = struct {
27612761 std.mem.alignForward(u64, error_size, payload_align) +
27622762 payload_size;
27632763 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));
27652765 if (padding == 0) {
27662766 return o.context.structType(&fields_buf, 2, .False);
27672767 }
......@@ -2774,7 +2774,7 @@ pub const Object = struct {
27742774 std.mem.alignForward(u64, payload_size, error_align) +
27752775 error_size;
27762776 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));
27782778 if (padding == 0) {
27792779 return o.context.structType(&fields_buf, 2, .False);
27802780 }
......@@ -2811,7 +2811,7 @@ pub const Object = struct {
28112811
28122812 const padding_len = offset - prev_offset;
28132813 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)));
28152815 try llvm_field_types.append(gpa, llvm_array_ty);
28162816 }
28172817 const field_llvm_ty = try o.lowerType(field_ty.toType());
......@@ -2824,14 +2824,14 @@ pub const Object = struct {
28242824 offset = std.mem.alignForward(u64, offset, big_align);
28252825 const padding_len = offset - prev_offset;
28262826 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)));
28282828 try llvm_field_types.append(gpa, llvm_array_ty);
28292829 }
28302830 }
28312831
28322832 llvm_struct_ty.structSetBody(
28332833 llvm_field_types.items.ptr,
2834 @intCast(c_uint, llvm_field_types.items.len),
2834 @as(c_uint, @intCast(llvm_field_types.items.len)),
28352835 .False,
28362836 );
28372837
......@@ -2880,7 +2880,7 @@ pub const Object = struct {
28802880
28812881 const padding_len = offset - prev_offset;
28822882 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)));
28842884 try llvm_field_types.append(gpa, llvm_array_ty);
28852885 }
28862886 const field_llvm_ty = try o.lowerType(field.ty);
......@@ -2893,14 +2893,14 @@ pub const Object = struct {
28932893 offset = std.mem.alignForward(u64, offset, big_align);
28942894 const padding_len = offset - prev_offset;
28952895 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)));
28972897 try llvm_field_types.append(gpa, llvm_array_ty);
28982898 }
28992899 }
29002900
29012901 llvm_struct_ty.structSetBody(
29022902 llvm_field_types.items.ptr,
2903 @intCast(c_uint, llvm_field_types.items.len),
2903 @as(c_uint, @intCast(llvm_field_types.items.len)),
29042904 llvm.Bool.fromBool(any_underaligned_fields),
29052905 );
29062906
......@@ -2914,7 +2914,7 @@ pub const Object = struct {
29142914 const union_obj = mod.typeToUnion(t).?;
29152915
29162916 if (union_obj.layout == .Packed) {
2917 const bitsize = @intCast(c_uint, t.bitSize(mod));
2917 const bitsize = @as(c_uint, @intCast(t.bitSize(mod)));
29182918 const int_llvm_ty = o.context.intType(bitsize);
29192919 gop.value_ptr.* = int_llvm_ty;
29202920 return int_llvm_ty;
......@@ -2939,9 +2939,9 @@ pub const Object = struct {
29392939 break :t llvm_aligned_field_ty;
29402940 }
29412941 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))
29432943 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));
29452945 const fields: [2]*llvm.Type = .{
29462946 llvm_aligned_field_ty,
29472947 o.context.intType(8).arrayType(padding_len),
......@@ -3020,7 +3020,7 @@ pub const Object = struct {
30203020 },
30213021 .abi_sized_int => {
30223022 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)));
30243024 try llvm_params.append(o.context.intType(abi_size * 8));
30253025 },
30263026 .slice => {
......@@ -3045,7 +3045,7 @@ pub const Object = struct {
30453045 .float_array => |count| {
30463046 const param_ty = fn_info.param_types[it.zig_index - 1].toType();
30473047 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));
30493049 const arr_ty = float_ty.arrayType(field_count);
30503050 try llvm_params.append(arr_ty);
30513051 },
......@@ -3059,7 +3059,7 @@ pub const Object = struct {
30593059 return llvm.functionType(
30603060 llvm_ret_ty,
30613061 llvm_params.items.ptr,
3062 @intCast(c_uint, llvm_params.items.len),
3062 @as(c_uint, @intCast(llvm_params.items.len)),
30633063 llvm.Bool.fromBool(fn_info.is_var_args),
30643064 );
30653065 }
......@@ -3219,7 +3219,7 @@ pub const Object = struct {
32193219 }
32203220 if (@sizeOf(usize) == @sizeOf(u64)) {
32213221 break :v llvm_type.constIntOfArbitraryPrecision(
3222 @intCast(c_uint, bigint.limbs.len),
3222 @as(c_uint, @intCast(bigint.limbs.len)),
32233223 bigint.limbs.ptr,
32243224 );
32253225 }
......@@ -3234,19 +3234,19 @@ pub const Object = struct {
32343234 const llvm_ty = try o.lowerType(tv.ty);
32353235 switch (tv.ty.floatBits(target)) {
32363236 16 => {
3237 const repr = @bitCast(u16, tv.val.toFloat(f16, mod));
3237 const repr = @as(u16, @bitCast(tv.val.toFloat(f16, mod)));
32383238 const llvm_i16 = o.context.intType(16);
32393239 const int = llvm_i16.constInt(repr, .False);
32403240 return int.constBitCast(llvm_ty);
32413241 },
32423242 32 => {
3243 const repr = @bitCast(u32, tv.val.toFloat(f32, mod));
3243 const repr = @as(u32, @bitCast(tv.val.toFloat(f32, mod)));
32443244 const llvm_i32 = o.context.intType(32);
32453245 const int = llvm_i32.constInt(repr, .False);
32463246 return int.constBitCast(llvm_ty);
32473247 },
32483248 64 => {
3249 const repr = @bitCast(u64, tv.val.toFloat(f64, mod));
3249 const repr = @as(u64, @bitCast(tv.val.toFloat(f64, mod)));
32503250 const llvm_i64 = o.context.intType(64);
32513251 const int = llvm_i64.constInt(repr, .False);
32523252 return int.constBitCast(llvm_ty);
......@@ -3265,7 +3265,7 @@ pub const Object = struct {
32653265 }
32663266 },
32673267 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)));
32693269 // LLVM seems to require that the lower half of the f128 be placed first
32703270 // in the buffer.
32713271 if (native_endian == .Big) {
......@@ -3343,7 +3343,7 @@ pub const Object = struct {
33433343 .array_type => switch (aggregate.storage) {
33443344 .bytes => |bytes| return o.context.constString(
33453345 bytes.ptr,
3346 @intCast(c_uint, tv.ty.arrayLenIncludingSentinel(mod)),
3346 @as(c_uint, @intCast(tv.ty.arrayLenIncludingSentinel(mod))),
33473347 .True, // Don't null terminate. Bytes has the sentinel, if any.
33483348 ),
33493349 .elems => |elem_vals| {
......@@ -3358,21 +3358,21 @@ pub const Object = struct {
33583358 if (need_unnamed) {
33593359 return o.context.constStruct(
33603360 llvm_elems.ptr,
3361 @intCast(c_uint, llvm_elems.len),
3361 @as(c_uint, @intCast(llvm_elems.len)),
33623362 .True,
33633363 );
33643364 } else {
33653365 const llvm_elem_ty = try o.lowerType(elem_ty);
33663366 return llvm_elem_ty.constArray(
33673367 llvm_elems.ptr,
3368 @intCast(c_uint, llvm_elems.len),
3368 @as(c_uint, @intCast(llvm_elems.len)),
33693369 );
33703370 }
33713371 },
33723372 .repeated_elem => |val| {
33733373 const elem_ty = tv.ty.childType(mod);
33743374 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)));
33763376 const len_including_sent = len + @intFromBool(sentinel != null);
33773377 const llvm_elems = try gpa.alloc(*llvm.Value, len_including_sent);
33783378 defer gpa.free(llvm_elems);
......@@ -3393,14 +3393,14 @@ pub const Object = struct {
33933393 if (need_unnamed) {
33943394 return o.context.constStruct(
33953395 llvm_elems.ptr,
3396 @intCast(c_uint, llvm_elems.len),
3396 @as(c_uint, @intCast(llvm_elems.len)),
33973397 .True,
33983398 );
33993399 } else {
34003400 const llvm_elem_ty = try o.lowerType(elem_ty);
34013401 return llvm_elem_ty.constArray(
34023402 llvm_elems.ptr,
3403 @intCast(c_uint, llvm_elems.len),
3403 @as(c_uint, @intCast(llvm_elems.len)),
34043404 );
34053405 }
34063406 },
......@@ -3425,7 +3425,7 @@ pub const Object = struct {
34253425 }
34263426 return llvm.constVector(
34273427 llvm_elems.ptr,
3428 @intCast(c_uint, llvm_elems.len),
3428 @as(c_uint, @intCast(llvm_elems.len)),
34293429 );
34303430 },
34313431 .anon_struct_type => |tuple| {
......@@ -3450,7 +3450,7 @@ pub const Object = struct {
34503450
34513451 const padding_len = offset - prev_offset;
34523452 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)));
34543454 // TODO make this and all other padding elsewhere in debug
34553455 // builds be 0xaa not undef.
34563456 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());
......@@ -3472,7 +3472,7 @@ pub const Object = struct {
34723472 offset = std.mem.alignForward(u64, offset, big_align);
34733473 const padding_len = offset - prev_offset;
34743474 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)));
34763476 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());
34773477 }
34783478 }
......@@ -3480,14 +3480,14 @@ pub const Object = struct {
34803480 if (need_unnamed) {
34813481 return o.context.constStruct(
34823482 llvm_fields.items.ptr,
3483 @intCast(c_uint, llvm_fields.items.len),
3483 @as(c_uint, @intCast(llvm_fields.items.len)),
34843484 .False,
34853485 );
34863486 } else {
34873487 const llvm_struct_ty = try o.lowerType(tv.ty);
34883488 return llvm_struct_ty.constNamedStruct(
34893489 llvm_fields.items.ptr,
3490 @intCast(c_uint, llvm_fields.items.len),
3490 @as(c_uint, @intCast(llvm_fields.items.len)),
34913491 );
34923492 }
34933493 },
......@@ -3498,7 +3498,7 @@ pub const Object = struct {
34983498 if (struct_obj.layout == .Packed) {
34993499 assert(struct_obj.haveLayout());
35003500 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)));
35023502 const fields = struct_obj.fields.values();
35033503 comptime assert(Type.packed_struct_layout_version == 2);
35043504 var running_int: *llvm.Value = int_llvm_ty.constNull();
......@@ -3510,7 +3510,7 @@ pub const Object = struct {
35103510 .ty = field.ty,
35113511 .val = try tv.val.fieldValue(mod, i),
35123512 });
3513 const ty_bit_size = @intCast(u16, field.ty.bitSize(mod));
3513 const ty_bit_size = @as(u16, @intCast(field.ty.bitSize(mod)));
35143514 const small_int_ty = o.context.intType(ty_bit_size);
35153515 const small_int_val = if (field.ty.isPtrAtRuntime(mod))
35163516 non_int_val.constPtrToInt(small_int_ty)
......@@ -3547,7 +3547,7 @@ pub const Object = struct {
35473547
35483548 const padding_len = offset - prev_offset;
35493549 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)));
35513551 // TODO make this and all other padding elsewhere in debug
35523552 // builds be 0xaa not undef.
35533553 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());
......@@ -3569,7 +3569,7 @@ pub const Object = struct {
35693569 offset = std.mem.alignForward(u64, offset, big_align);
35703570 const padding_len = offset - prev_offset;
35713571 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)));
35733573 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());
35743574 }
35753575 }
......@@ -3577,13 +3577,13 @@ pub const Object = struct {
35773577 if (need_unnamed) {
35783578 return o.context.constStruct(
35793579 llvm_fields.items.ptr,
3580 @intCast(c_uint, llvm_fields.items.len),
3580 @as(c_uint, @intCast(llvm_fields.items.len)),
35813581 .False,
35823582 );
35833583 } else {
35843584 return llvm_struct_ty.constNamedStruct(
35853585 llvm_fields.items.ptr,
3586 @intCast(c_uint, llvm_fields.items.len),
3586 @as(c_uint, @intCast(llvm_fields.items.len)),
35873587 );
35883588 }
35893589 },
......@@ -3616,7 +3616,7 @@ pub const Object = struct {
36163616 if (!field_ty.hasRuntimeBits(mod))
36173617 return llvm_union_ty.constNull();
36183618 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)));
36203620 const small_int_ty = o.context.intType(ty_bit_size);
36213621 const small_int_val = if (field_ty.isPtrAtRuntime(mod))
36223622 non_int_val.constPtrToInt(small_int_ty)
......@@ -3632,7 +3632,7 @@ pub const Object = struct {
36323632 var need_unnamed: bool = layout.most_aligned_field != field_index;
36333633 const payload = p: {
36343634 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));
36363636 break :p o.context.intType(8).arrayType(padding_len).getUndef();
36373637 }
36383638 const field = try lowerValue(o, .{ .ty = field_ty, .val = tag_and_val.val });
......@@ -3641,7 +3641,7 @@ pub const Object = struct {
36413641 if (field_size == layout.payload_size) {
36423642 break :p field;
36433643 }
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));
36453645 const fields: [2]*llvm.Value = .{
36463646 field, o.context.intType(8).arrayType(padding_len).getUndef(),
36473647 };
......@@ -3706,7 +3706,7 @@ pub const Object = struct {
37063706 }
37073707 if (@sizeOf(usize) == @sizeOf(u64)) {
37083708 break :v llvm_type.constIntOfArbitraryPrecision(
3709 @intCast(c_uint, bigint.limbs.len),
3709 @as(c_uint, @intCast(bigint.limbs.len)),
37103710 bigint.limbs.ptr,
37113711 );
37123712 }
......@@ -3799,7 +3799,7 @@ pub const Object = struct {
37993799 const parent_llvm_ptr = try o.lowerParentPtr(field_ptr.base.toValue(), byte_aligned);
38003800 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));
38033803 const llvm_u32 = o.context.intType(32);
38043804 switch (parent_ty.zigTypeTag(mod)) {
38053805 .Union => {
......@@ -3834,7 +3834,7 @@ pub const Object = struct {
38343834 var b: usize = 0;
38353835 for (parent_ty.structFields(mod).values()[0..field_index]) |field| {
38363836 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)));
38383838 }
38393839 break :b b;
38403840 };
......@@ -3992,9 +3992,9 @@ pub const Object = struct {
39923992 ) void {
39933993 const llvm_attr = o.context.createStringAttribute(
39943994 name.ptr,
3995 @intCast(c_uint, name.len),
3995 @as(c_uint, @intCast(name.len)),
39963996 value.ptr,
3997 @intCast(c_uint, value.len),
3997 @as(c_uint, @intCast(value.len)),
39983998 );
39993999 val.addAttributeAtIndex(index, llvm_attr);
40004000 }
......@@ -4026,14 +4026,14 @@ pub const Object = struct {
40264026 .Enum => ty.intTagType(mod),
40274027 .Float => {
40284028 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)));
40304030 },
40314031 .Bool => return o.context.intType(8),
40324032 else => return null,
40334033 };
40344034 const bit_count = int_ty.intInfo(mod).bits;
40354035 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)));
40374037 } else {
40384038 return null;
40394039 }
......@@ -4051,7 +4051,7 @@ pub const Object = struct {
40514051 if (param_ty.isPtrAtRuntime(mod)) {
40524052 const ptr_info = param_ty.ptrInfo(mod);
40534053 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) {
40554055 o.addArgAttr(llvm_fn, llvm_arg_i, "noalias");
40564056 }
40574057 }
......@@ -4550,7 +4550,7 @@ pub const FuncGen = struct {
45504550 fn airCall(self: *FuncGen, inst: Air.Inst.Index, attr: llvm.CallAttr) !?*llvm.Value {
45514551 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
45524552 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]));
45544554 const o = self.dg.object;
45554555 const mod = o.module;
45564556 const callee_ty = self.typeOf(pl_op.operand);
......@@ -4638,7 +4638,7 @@ pub const FuncGen = struct {
46384638 const arg = args[it.zig_index - 1];
46394639 const param_ty = self.typeOf(arg);
46404640 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)));
46424642 const int_llvm_ty = self.context.intType(abi_size * 8);
46434643
46444644 if (isByRef(param_ty, mod)) {
......@@ -4683,10 +4683,10 @@ pub const FuncGen = struct {
46834683 break :p p;
46844684 };
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);
46874687 try llvm_args.ensureUnusedCapacity(it.llvm_types_len);
46884688 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));
46904690 const field_ptr = self.builder.buildStructGEP(llvm_ty, arg_ptr, i, "");
46914691 const load_inst = self.builder.buildLoad(field_ty, field_ptr, "");
46924692 load_inst.setAlignment(target.ptrBitWidth() / 8);
......@@ -4742,7 +4742,7 @@ pub const FuncGen = struct {
47424742 try o.lowerType(zig_fn_ty),
47434743 llvm_fn,
47444744 llvm_args.items.ptr,
4745 @intCast(c_uint, llvm_args.items.len),
4745 @as(c_uint, @intCast(llvm_args.items.len)),
47464746 toLlvmCallConv(fn_info.cc, target),
47474747 attr,
47484748 "",
......@@ -4788,7 +4788,7 @@ pub const FuncGen = struct {
47884788 const llvm_arg_i = it.llvm_index - 2;
47894789
47904790 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) {
47924792 o.addArgAttr(call, llvm_arg_i, "noalias");
47934793 }
47944794 }
......@@ -5213,7 +5213,7 @@ pub const FuncGen = struct {
52135213 phi_node.addIncoming(
52145214 breaks.items(.val).ptr,
52155215 breaks.items(.bb).ptr,
5216 @intCast(c_uint, breaks.len),
5216 @as(c_uint, @intCast(breaks.len)),
52175217 );
52185218 return phi_node;
52195219 }
......@@ -5379,7 +5379,7 @@ pub const FuncGen = struct {
53795379
53805380 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
53815381 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]));
53835383 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
53845384 extra_index = case.end + case.data.items_len + case_body.len;
53855385
......@@ -5479,7 +5479,7 @@ pub const FuncGen = struct {
54795479 }
54805480 }
54815481
5482 const operand_bits = @intCast(u16, operand_scalar_ty.bitSize(mod));
5482 const operand_bits = @as(u16, @intCast(operand_scalar_ty.bitSize(mod)));
54835483 const rt_int_bits = compilerRtIntBits(operand_bits);
54845484 const rt_int_ty = self.context.intType(rt_int_bits);
54855485 var extended = e: {
......@@ -5540,7 +5540,7 @@ pub const FuncGen = struct {
55405540 }
55415541 }
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))));
55445544 const ret_ty = self.context.intType(rt_int_bits);
55455545 const libc_ret_ty = if (rt_int_bits == 128 and (target.os.tag == .windows and target.cpu.arch == .x86_64)) b: {
55465546 // On Windows x86-64, "ti" functions must use Vector(2, u64) instead of the standard
......@@ -5806,12 +5806,12 @@ pub const FuncGen = struct {
58065806 const shifted_value = self.builder.buildLShr(containing_int, shift_amt, "");
58075807 const elem_llvm_ty = try o.lowerType(field_ty);
58085808 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)));
58105810 const same_size_int = self.context.intType(elem_bits);
58115811 const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, "");
58125812 return self.builder.buildBitCast(truncated_int, elem_llvm_ty, "");
58135813 } 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)));
58155815 const same_size_int = self.context.intType(elem_bits);
58165816 const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, "");
58175817 return self.builder.buildIntToPtr(truncated_int, elem_llvm_ty, "");
......@@ -5828,12 +5828,12 @@ pub const FuncGen = struct {
58285828 const containing_int = struct_llvm_val;
58295829 const elem_llvm_ty = try o.lowerType(field_ty);
58305830 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)));
58325832 const same_size_int = self.context.intType(elem_bits);
58335833 const truncated_int = self.builder.buildTrunc(containing_int, same_size_int, "");
58345834 return self.builder.buildBitCast(truncated_int, elem_llvm_ty, "");
58355835 } 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)));
58375837 const same_size_int = self.context.intType(elem_bits);
58385838 const truncated_int = self.builder.buildTrunc(containing_int, same_size_int, "");
58395839 return self.builder.buildIntToPtr(truncated_int, elem_llvm_ty, "");
......@@ -5924,8 +5924,8 @@ pub const FuncGen = struct {
59245924 fn airDbgStmt(self: *FuncGen, inst: Air.Inst.Index) ?*llvm.Value {
59255925 const di_scope = self.di_scope orelse return null;
59265926 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);
5928 self.prev_dbg_column = @intCast(c_uint, dbg_stmt.column + 1);
5927 self.prev_dbg_line = @as(c_uint, @intCast(self.base_line + dbg_stmt.line + 1));
5928 self.prev_dbg_column = @as(c_uint, @intCast(dbg_stmt.column + 1));
59295929 const inlined_at = if (self.dbg_inlined.items.len > 0)
59305930 self.dbg_inlined.items[self.dbg_inlined.items.len - 1].loc
59315931 else
......@@ -5949,7 +5949,7 @@ pub const FuncGen = struct {
59495949 const cur_debug_location = self.builder.getCurrentDebugLocation2();
59505950
59515951 try self.dbg_inlined.append(self.gpa, .{
5952 .loc = @ptrCast(*llvm.DILocation, cur_debug_location),
5952 .loc = @as(*llvm.DILocation, @ptrCast(cur_debug_location)),
59535953 .scope = self.di_scope.?,
59545954 .base_line = self.base_line,
59555955 });
......@@ -6107,13 +6107,13 @@ pub const FuncGen = struct {
61076107 const o = self.dg.object;
61086108 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
61096109 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
6110 const is_volatile = @truncate(u1, extra.data.flags >> 31) != 0;
6111 const clobbers_len = @truncate(u31, extra.data.flags);
6110 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
6111 const clobbers_len = @as(u31, @truncate(extra.data.flags));
61126112 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]));
61156115 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]));
61176117 extra_i += inputs.len;
61186118
61196119 var llvm_constraints: std.ArrayListUnmanaged(u8) = .{};
......@@ -6390,7 +6390,7 @@ pub const FuncGen = struct {
63906390 1 => llvm_ret_types[0],
63916391 else => self.context.structType(
63926392 llvm_ret_types.ptr,
6393 @intCast(c_uint, return_count),
6393 @as(c_uint, @intCast(return_count)),
63946394 .False,
63956395 ),
63966396 };
......@@ -6398,7 +6398,7 @@ pub const FuncGen = struct {
63986398 const llvm_fn_ty = llvm.functionType(
63996399 ret_llvm_ty,
64006400 llvm_param_types.ptr,
6401 @intCast(c_uint, param_count),
6401 @as(c_uint, @intCast(param_count)),
64026402 .False,
64036403 );
64046404 const asm_fn = llvm.getInlineAsm(
......@@ -6416,7 +6416,7 @@ pub const FuncGen = struct {
64166416 llvm_fn_ty,
64176417 asm_fn,
64186418 llvm_param_values.ptr,
6419 @intCast(c_uint, param_count),
6419 @as(c_uint, @intCast(param_count)),
64206420 .C,
64216421 .Auto,
64226422 "",
......@@ -6433,7 +6433,7 @@ pub const FuncGen = struct {
64336433 if (llvm_ret_indirect[i]) continue;
64346434
64356435 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)), "");
64376437 } else call;
64386438
64396439 if (output != .none) {
......@@ -7315,7 +7315,7 @@ pub const FuncGen = struct {
73157315 result_vector: *llvm.Value,
73167316 vector_len: usize,
73177317 ) !*llvm.Value {
7318 const args_len = @intCast(c_uint, args_vectors.len);
7318 const args_len = @as(c_uint, @intCast(args_vectors.len));
73197319 const llvm_i32 = self.context.intType(32);
73207320 assert(args_len <= 3);
73217321
......@@ -7345,7 +7345,7 @@ pub const FuncGen = struct {
73457345 const alias = o.llvm_module.getNamedGlobalAlias(fn_name.ptr, fn_name.len);
73467346 break :b if (alias) |a| a.getAliasee() else null;
73477347 } orelse b: {
7348 const params_len = @intCast(c_uint, param_types.len);
7348 const params_len = @as(c_uint, @intCast(param_types.len));
73497349 const fn_type = llvm.functionType(return_type, param_types.ptr, params_len, .False);
73507350 const f = o.llvm_module.addFunction(fn_name, fn_type);
73517351 break :b f;
......@@ -8319,8 +8319,8 @@ pub const FuncGen = struct {
83198319 return null;
83208320 const ordering = toLlvmAtomicOrdering(atomic_load.order);
83218321 const opt_abi_llvm_ty = o.getAtomicAbiType(elem_ty, false);
8322 const ptr_alignment = @intCast(u32, ptr_info.flags.alignment.toByteUnitsOptional() orelse
8323 ptr_info.child.toType().abiAlignment(mod));
8322 const ptr_alignment = @as(u32, @intCast(ptr_info.flags.alignment.toByteUnitsOptional() orelse
8323 ptr_info.child.toType().abiAlignment(mod)));
83248324 const ptr_volatile = llvm.Bool.fromBool(ptr_info.flags.is_volatile);
83258325 const elem_llvm_ty = try o.lowerType(elem_ty);
83268326
......@@ -8696,10 +8696,10 @@ pub const FuncGen = struct {
86968696 const valid_block = self.context.appendBasicBlock(self.llvm_func, "Valid");
86978697 const invalid_block = self.context.appendBasicBlock(self.llvm_func, "Invalid");
86988698 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
87018701 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).?));
87038703 const this_tag_int_value = try o.lowerValue(.{
87048704 .ty = Type.err_int,
87058705 .val = try mod.intValue(Type.err_int, err_int),
......@@ -8779,10 +8779,10 @@ pub const FuncGen = struct {
87798779 const named_block = self.context.appendBasicBlock(fn_val, "Named");
87808780 const unnamed_block = self.context.appendBasicBlock(fn_val, "Unnamed");
87818781 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
87848784 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));
87868786 const this_tag_int_value = int: {
87878787 break :int try o.lowerValue(.{
87888788 .ty = enum_ty,
......@@ -8855,16 +8855,16 @@ pub const FuncGen = struct {
88558855
88568856 const bad_value_block = self.context.appendBasicBlock(fn_val, "BadValue");
88578857 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
88608860 const array_ptr_indices = [_]*llvm.Value{
88618861 usize_llvm_ty.constNull(), usize_llvm_ty.constNull(),
88628862 };
88638863
88648864 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));
88668866 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);
88688868 const str_init_llvm_ty = str_init.typeOf();
88698869 const str_global = o.llvm_module.addGlobal(str_init_llvm_ty, "");
88708870 str_global.setInitializer(str_init);
......@@ -8986,7 +8986,7 @@ pub const FuncGen = struct {
89868986 val.* = llvm_i32.getUndef();
89878987 } else {
89888988 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));
89908990 val.* = llvm_i32.constInt(unsigned, .False);
89918991 }
89928992 }
......@@ -9150,8 +9150,8 @@ pub const FuncGen = struct {
91509150 const mod = o.module;
91519151 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
91529152 const result_ty = self.typeOfIndex(inst);
9153 const len = @intCast(usize, result_ty.arrayLen(mod));
9154 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
9153 const len = @as(usize, @intCast(result_ty.arrayLen(mod)));
9154 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
91559155 const llvm_result_ty = try o.lowerType(result_ty);
91569156
91579157 switch (result_ty.zigTypeTag(mod)) {
......@@ -9171,7 +9171,7 @@ pub const FuncGen = struct {
91719171 const struct_obj = mod.typeToStruct(result_ty).?;
91729172 assert(struct_obj.haveLayout());
91739173 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)));
91759175 const fields = struct_obj.fields.values();
91769176 comptime assert(Type.packed_struct_layout_version == 2);
91779177 var running_int: *llvm.Value = int_llvm_ty.constNull();
......@@ -9181,7 +9181,7 @@ pub const FuncGen = struct {
91819181 if (!field.ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
91829182
91839183 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)));
91859185 const small_int_ty = self.context.intType(ty_bit_size);
91869186 const small_int_val = if (field.ty.isPtrAtRuntime(mod))
91879187 self.builder.buildPtrToInt(non_int_val, small_int_ty, "")
......@@ -9251,7 +9251,7 @@ pub const FuncGen = struct {
92519251 for (elements, 0..) |elem, i| {
92529252 const indices: [2]*llvm.Value = .{
92539253 llvm_usize.constNull(),
9254 llvm_usize.constInt(@intCast(c_uint, i), .False),
9254 llvm_usize.constInt(@as(c_uint, @intCast(i)), .False),
92559255 };
92569256 const elem_ptr = self.builder.buildInBoundsGEP(llvm_result_ty, alloca_inst, &indices, indices.len, "");
92579257 const llvm_elem = try self.resolveInst(elem);
......@@ -9260,7 +9260,7 @@ pub const FuncGen = struct {
92609260 if (array_info.sentinel) |sent_val| {
92619261 const indices: [2]*llvm.Value = .{
92629262 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),
92649264 };
92659265 const elem_ptr = self.builder.buildInBoundsGEP(llvm_result_ty, alloca_inst, &indices, indices.len, "");
92669266 const llvm_elem = try self.resolveValue(.{
......@@ -9289,10 +9289,10 @@ pub const FuncGen = struct {
92899289
92909290 if (union_obj.layout == .Packed) {
92919291 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)));
92939293 const field = union_obj.fields.values()[extra.field_index];
92949294 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)));
92969296 const small_int_ty = self.context.intType(ty_bit_size);
92979297 const small_int_val = if (field.ty.isPtrAtRuntime(mod))
92989298 self.builder.buildPtrToInt(non_int_val, small_int_ty, "")
......@@ -9332,13 +9332,13 @@ pub const FuncGen = struct {
93329332 const llvm_union_ty = t: {
93339333 const payload = p: {
93349334 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));
93369336 break :p self.context.intType(8).arrayType(padding_len);
93379337 }
93389338 if (field_size == layout.payload_size) {
93399339 break :p field_llvm_ty;
93409340 }
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));
93429342 const fields: [2]*llvm.Type = .{
93439343 field_llvm_ty, self.context.intType(8).arrayType(padding_len),
93449344 };
......@@ -9766,8 +9766,8 @@ pub const FuncGen = struct {
97669766 const elem_ty = info.child.toType();
97679767 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) return null;
97689768
9769 const ptr_alignment = @intCast(u32, info.flags.alignment.toByteUnitsOptional() orelse
9770 elem_ty.abiAlignment(mod));
9769 const ptr_alignment = @as(u32, @intCast(info.flags.alignment.toByteUnitsOptional() orelse
9770 elem_ty.abiAlignment(mod)));
97719771 const ptr_volatile = llvm.Bool.fromBool(info.flags.is_volatile);
97729772
97739773 assert(info.flags.vector_index != .runtime);
......@@ -9799,7 +9799,7 @@ pub const FuncGen = struct {
97999799 containing_int.setAlignment(ptr_alignment);
98009800 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)));
98039803 const shift_amt = containing_int.typeOf().constInt(info.packed_offset.bit_offset, .False);
98049804 const shifted_value = self.builder.buildLShr(containing_int, shift_amt, "");
98059805 const elem_llvm_ty = try o.lowerType(elem_ty);
......@@ -9872,7 +9872,7 @@ pub const FuncGen = struct {
98729872 assert(ordering == .NotAtomic);
98739873 containing_int.setAlignment(ptr_alignment);
98749874 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)));
98769876 const containing_int_ty = containing_int.typeOf();
98779877 const shift_amt = containing_int_ty.constInt(info.packed_offset.bit_offset, .False);
98789878 // Convert to equally-sized integer type in order to perform the bit
......@@ -9945,7 +9945,7 @@ pub const FuncGen = struct {
99459945 if (!target_util.hasValgrindSupport(target)) return default_value;
99469946
99479947 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
99509950 const array_llvm_ty = usize_llvm_ty.arrayType(6);
99519951 const array_ptr = fg.valgrind_client_request_array orelse a: {
......@@ -9957,7 +9957,7 @@ pub const FuncGen = struct {
99579957 const zero = usize_llvm_ty.constInt(0, .False);
99589958 for (array_elements, 0..) |elem, i| {
99599959 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),
99619961 };
99629962 const elem_ptr = fg.builder.buildInBoundsGEP(array_llvm_ty, array_ptr, &indexes, indexes.len, "");
99639963 const store_inst = fg.builder.buildStore(elem, elem_ptr);
......@@ -10530,7 +10530,7 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) !*llvm.Type {
1053010530 assert(classes[0] == .direct and classes[1] == .none);
1053110531 const scalar_type = wasm_c_abi.scalarType(return_type, mod);
1053210532 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)));
1053410534 },
1053510535 .aarch64, .aarch64_be => {
1053610536 switch (aarch64_c_abi.classifyType(return_type, mod)) {
......@@ -10539,7 +10539,7 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) !*llvm.Type {
1053910539 .byval => return o.lowerType(return_type),
1054010540 .integer => {
1054110541 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)));
1054310543 },
1054410544 .double_integer => return o.context.intType(64).arrayType(2),
1054510545 }
......@@ -10560,7 +10560,7 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) !*llvm.Type {
1056010560 .memory => return o.context.voidType(),
1056110561 .integer => {
1056210562 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)));
1056410564 },
1056510565 .double_integer => {
1056610566 var llvm_types_buffer: [2]*llvm.Type = .{
......@@ -10598,7 +10598,7 @@ fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) !*llvm.Type {
1059810598 return o.lowerType(return_type);
1059910599 } else {
1060010600 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)));
1060210602 }
1060310603 },
1060410604 .win_i128 => return o.context.intType(64).vectorType(2),
......@@ -10656,7 +10656,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) !*llvm.Type
1065610656 }
1065710657 if (classes[0] == .integer and classes[1] == .none) {
1065810658 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)));
1066010660 }
1066110661 return o.context.structType(&llvm_types_buffer, llvm_types_index, .False);
1066210662}
......@@ -11145,28 +11145,28 @@ const AnnotatedDITypePtr = enum(usize) {
1114511145
1114611146 fn initFwd(di_type: *llvm.DIType) AnnotatedDITypePtr {
1114711147 const addr = @intFromPtr(di_type);
11148 assert(@truncate(u1, addr) == 0);
11149 return @enumFromInt(AnnotatedDITypePtr, addr | 1);
11148 assert(@as(u1, @truncate(addr)) == 0);
11149 return @as(AnnotatedDITypePtr, @enumFromInt(addr | 1));
1115011150 }
1115111151
1115211152 fn initFull(di_type: *llvm.DIType) AnnotatedDITypePtr {
1115311153 const addr = @intFromPtr(di_type);
11154 return @enumFromInt(AnnotatedDITypePtr, addr);
11154 return @as(AnnotatedDITypePtr, @enumFromInt(addr));
1115511155 }
1115611156
1115711157 fn init(di_type: *llvm.DIType, resolve: Object.DebugResolveStatus) AnnotatedDITypePtr {
1115811158 const addr = @intFromPtr(di_type);
1115911159 const bit = @intFromBool(resolve == .fwd);
11160 return @enumFromInt(AnnotatedDITypePtr, addr | bit);
11160 return @as(AnnotatedDITypePtr, @enumFromInt(addr | bit));
1116111161 }
1116211162
1116311163 fn toDIType(self: AnnotatedDITypePtr) *llvm.DIType {
1116411164 const fixed_addr = @intFromEnum(self) & ~@as(usize, 1);
11165 return @ptrFromInt(*llvm.DIType, fixed_addr);
11165 return @as(*llvm.DIType, @ptrFromInt(fixed_addr));
1116611166 }
1116711167
1116811168 fn isFwdOnly(self: AnnotatedDITypePtr) bool {
11169 return @truncate(u1, @intFromEnum(self)) != 0;
11169 return @as(u1, @truncate(@intFromEnum(self))) != 0;
1117011170 }
1117111171};
1117211172
src/codegen/llvm/bindings.zig+1-1
......@@ -8,7 +8,7 @@ pub const Bool = enum(c_int) {
88 _,
99
1010 pub fn fromBool(b: bool) Bool {
11 return @enumFromInt(Bool, @intFromBool(b));
11 return @as(Bool, @enumFromInt(@intFromBool(b)));
1212 }
1313
1414 pub fn toBool(b: Bool) bool {
src/codegen/spirv.zig+25-25
......@@ -466,7 +466,7 @@ pub const DeclGen = struct {
466466 unused.* = undef;
467467 }
468468
469 const word = @bitCast(Word, self.partial_word.buffer);
469 const word = @as(Word, @bitCast(self.partial_word.buffer));
470470 const result_id = try self.dg.spv.constInt(self.u32_ty_ref, word);
471471 try self.members.append(self.u32_ty_ref);
472472 try self.initializers.append(result_id);
......@@ -482,7 +482,7 @@ pub const DeclGen = struct {
482482 }
483483
484484 fn addUndef(self: *@This(), amt: u64) !void {
485 for (0..@intCast(usize, amt)) |_| {
485 for (0..@as(usize, @intCast(amt))) |_| {
486486 try self.addByte(undef);
487487 }
488488 }
......@@ -539,13 +539,13 @@ pub const DeclGen = struct {
539539 const mod = self.dg.module;
540540 const int_info = ty.intInfo(mod);
541541 const int_bits = switch (int_info.signedness) {
542 .signed => @bitCast(u64, val.toSignedInt(mod)),
542 .signed => @as(u64, @bitCast(val.toSignedInt(mod))),
543543 .unsigned => val.toUnsignedInt(mod),
544544 };
545545
546546 // TODO: Swap endianess if the compiler is big endian.
547547 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))]);
549549 }
550550
551551 fn addFloat(self: *@This(), ty: Type, val: Value) !void {
......@@ -557,15 +557,15 @@ pub const DeclGen = struct {
557557 switch (ty.floatBits(target)) {
558558 16 => {
559559 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))]);
561561 },
562562 32 => {
563563 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))]);
565565 },
566566 64 => {
567567 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))]);
569569 },
570570 else => unreachable,
571571 }
......@@ -664,7 +664,7 @@ pub const DeclGen = struct {
664664 .int => try self.addInt(ty, val),
665665 .err => |err| {
666666 const int = try mod.getErrorValue(err.name);
667 try self.addConstInt(u16, @intCast(u16, int));
667 try self.addConstInt(u16, @as(u16, @intCast(int)));
668668 },
669669 .error_union => |error_union| {
670670 const payload_ty = ty.errorUnionPayload(mod);
......@@ -755,10 +755,10 @@ pub const DeclGen = struct {
755755 switch (aggregate.storage) {
756756 .bytes => |bytes| try self.addBytes(bytes),
757757 .elems, .repeated_elem => {
758 for (0..@intCast(usize, array_type.len)) |i| {
758 for (0..@as(usize, @intCast(array_type.len))) |i| {
759759 try self.lower(elem_ty, switch (aggregate.storage) {
760760 .bytes => unreachable,
761 .elems => |elem_vals| elem_vals[@intCast(usize, i)].toValue(),
761 .elems => |elem_vals| elem_vals[@as(usize, @intCast(i))].toValue(),
762762 .repeated_elem => |elem_val| elem_val.toValue(),
763763 });
764764 }
......@@ -1132,7 +1132,7 @@ pub const DeclGen = struct {
11321132
11331133 const payload_padding_len = layout.payload_size - active_field_size;
11341134 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);
11361136 member_types.appendAssumeCapacity(payload_padding_ty_ref);
11371137 member_names.appendAssumeCapacity(try self.spv.resolveString("payload_padding"));
11381138 }
......@@ -1259,7 +1259,7 @@ pub const DeclGen = struct {
12591259
12601260 return try self.spv.resolve(.{ .vector_type = .{
12611261 .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))),
12631263 } });
12641264 },
12651265 .Struct => {
......@@ -1588,7 +1588,7 @@ pub const DeclGen = struct {
15881588 init_val,
15891589 actual_storage_class,
15901590 final_storage_class == .Generic,
1591 @intCast(u32, decl.alignment.toByteUnits(0)),
1591 @as(u32, @intCast(decl.alignment.toByteUnits(0))),
15921592 );
15931593 }
15941594 }
......@@ -1856,7 +1856,7 @@ pub const DeclGen = struct {
18561856 }
18571857
18581858 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;
18601860 const result_id = self.spv.allocId();
18611861 const mask_id = try self.spv.constInt(ty_ref, mask_value);
18621862 try self.func.body.emit(self.spv.gpa, .OpBitwiseAnd, .{
......@@ -2063,7 +2063,7 @@ pub const DeclGen = struct {
20632063 self.func.body.writeOperand(spec.LiteralInteger, 0xFFFF_FFFF);
20642064 } else {
20652065 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));
20672067 self.func.body.writeOperand(spec.LiteralInteger, unsigned);
20682068 }
20692069 }
......@@ -2689,7 +2689,7 @@ pub const DeclGen = struct {
26892689 // are not allowed to be created from a phi node, and throw an error for those.
26902690 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...
26932693 self.func.body.writeOperand(spec.IdResultType, result_type_id);
26942694 self.func.body.writeOperand(spec.IdRef, result_id);
26952695
......@@ -3105,7 +3105,7 @@ pub const DeclGen = struct {
31053105 while (case_i < num_cases) : (case_i += 1) {
31063106 // SPIR-V needs a literal here, which' width depends on the case condition.
31073107 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]));
31093109 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
31103110 extra_index = case.end + case.data.items_len + case_body.len;
31113111
......@@ -3116,7 +3116,7 @@ pub const DeclGen = struct {
31163116 return self.todo("switch on runtime value???", .{});
31173117 };
31183118 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),
31203120 .Enum => blk: {
31213121 // TODO: figure out of cond_ty is correct (something with enum literals)
31223122 break :blk (try value.intFromEnum(cond_ty, mod)).toUnsignedInt(mod); // TODO: composite integer constants
......@@ -3124,7 +3124,7 @@ pub const DeclGen = struct {
31243124 else => unreachable,
31253125 };
31263126 const int_lit: spec.LiteralContextDependentNumber = switch (cond_words) {
3127 1 => .{ .uint32 = @intCast(u32, int_val) },
3127 1 => .{ .uint32 = @as(u32, @intCast(int_val)) },
31283128 2 => .{ .uint64 = int_val },
31293129 else => unreachable,
31303130 };
......@@ -3139,7 +3139,7 @@ pub const DeclGen = struct {
31393139 var case_i: u32 = 0;
31403140 while (case_i < num_cases) : (case_i += 1) {
31413141 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]));
31433143 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
31443144 extra_index = case.end + case.data.items_len + case_body.len;
31453145
......@@ -3167,15 +3167,15 @@ pub const DeclGen = struct {
31673167 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
31683168 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
31693169
3170 const is_volatile = @truncate(u1, extra.data.flags >> 31) != 0;
3171 const clobbers_len = @truncate(u31, extra.data.flags);
3170 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
3171 const clobbers_len = @as(u31, @truncate(extra.data.flags));
31723172
31733173 if (!is_volatile and self.liveness.isUnused(inst)) return null;
31743174
31753175 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]));
31773177 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]));
31793179 extra_i += inputs.len;
31803180
31813181 if (outputs.len > 1) {
......@@ -3297,7 +3297,7 @@ pub const DeclGen = struct {
32973297 const mod = self.module;
32983298 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
32993299 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]));
33013301 const callee_ty = self.typeOf(pl_op.operand);
33023302 const zig_fn_ty = switch (callee_ty.zigTypeTag(mod)) {
33033303 .Fn => callee_ty,
src/codegen/spirv/Assembler.zig+12-12
......@@ -293,7 +293,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {
293293 return self.fail(0, "{} is not a valid bit count for floats (expected 16, 32 or 64)", .{bits});
294294 },
295295 }
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)) } });
297297 },
298298 .OpTypeVector => try self.spv.resolve(.{ .vector_type = .{
299299 .component_type = try self.resolveTypeRef(operands[1].ref_id),
......@@ -306,7 +306,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {
306306 },
307307 .OpTypePointer => try self.spv.ptrType(
308308 try self.resolveTypeRef(operands[2].ref_id),
309 @enumFromInt(spec.StorageClass, operands[1].value),
309 @as(spec.StorageClass, @enumFromInt(operands[1].value)),
310310 ),
311311 .OpTypeFunction => blk: {
312312 const param_operands = operands[2..];
......@@ -340,7 +340,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
340340 else => switch (self.inst.opcode) {
341341 .OpEntryPoint => unreachable,
342342 .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))) {
344344 .Function => &self.func.prologue,
345345 else => {
346346 // This is currently disabled because global variables are required to be
......@@ -391,7 +391,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
391391 }
392392
393393 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
396396 if (maybe_result_id) |result| {
397397 return AsmValue{ .value = result };
......@@ -458,7 +458,7 @@ fn parseInstruction(self: *Assembler) !void {
458458 if (!entry.found_existing) {
459459 entry.value_ptr.* = .just_declared;
460460 }
461 break :blk @intCast(AsmValue.Ref, entry.index);
461 break :blk @as(AsmValue.Ref, @intCast(entry.index));
462462 } else null;
463463
464464 const opcode_tok = self.currentToken();
......@@ -613,7 +613,7 @@ fn parseRefId(self: *Assembler) !void {
613613 entry.value_ptr.* = .unresolved_forward_reference;
614614 }
615615
616 const index = @intCast(AsmValue.Ref, entry.index);
616 const index = @as(AsmValue.Ref, @intCast(entry.index));
617617 try self.inst.operands.append(self.gpa, .{ .ref_id = index });
618618}
619619
......@@ -645,7 +645,7 @@ fn parseString(self: *Assembler) !void {
645645 else
646646 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));
649649 try self.inst.string_bytes.ensureUnusedCapacity(self.gpa, literal.len + 1);
650650 self.inst.string_bytes.appendSliceAssumeCapacity(literal);
651651 self.inst.string_bytes.appendAssumeCapacity(0);
......@@ -693,18 +693,18 @@ fn parseContextDependentInt(self: *Assembler, signedness: std.builtin.Signedness
693693 const int = std.fmt.parseInt(i128, text, 0) catch break :invalid;
694694 const min = switch (signedness) {
695695 .unsigned => 0,
696 .signed => -(@as(i128, 1) << (@intCast(u7, width) - 1)),
696 .signed => -(@as(i128, 1) << (@as(u7, @intCast(width)) - 1)),
697697 };
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;
699699 if (int < min or int > max) {
700700 break :invalid;
701701 }
702702
703703 // Note, we store the sign-extended version here.
704704 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)))) });
706706 } 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)))) });
708708 }
709709 return;
710710 }
......@@ -725,7 +725,7 @@ fn parseContextDependentFloat(self: *Assembler, comptime width: u16) !void {
725725 return self.fail(tok.start, "'{s}' is not a valid {}-bit float literal", .{ text, width });
726726 };
727727
728 const float_bits = @bitCast(Int, value);
728 const float_bits = @as(Int, @bitCast(value));
729729 if (width <= @bitSizeOf(spec.Word)) {
730730 try self.inst.operands.append(self.gpa, .{ .literal32 = float_bits });
731731 } else {
src/codegen/spirv/Cache.zig+62-62
......@@ -158,16 +158,16 @@ const Tag = enum {
158158 high: u32,
159159
160160 fn encode(value: f64) Float64 {
161 const bits = @bitCast(u64, value);
161 const bits = @as(u64, @bitCast(value));
162162 return .{
163 .low = @truncate(u32, bits),
164 .high = @truncate(u32, bits >> 32),
163 .low = @as(u32, @truncate(bits)),
164 .high = @as(u32, @truncate(bits >> 32)),
165165 };
166166 }
167167
168168 fn decode(self: Float64) f64 {
169169 const bits = @as(u64, self.low) | (@as(u64, self.high) << 32);
170 return @bitCast(f64, bits);
170 return @as(f64, @bitCast(bits));
171171 }
172172 };
173173
......@@ -189,8 +189,8 @@ const Tag = enum {
189189 fn encode(ty: Ref, value: u64) Int64 {
190190 return .{
191191 .ty = ty,
192 .low = @truncate(u32, value),
193 .high = @truncate(u32, value >> 32),
192 .low = @as(u32, @truncate(value)),
193 .high = @as(u32, @truncate(value >> 32)),
194194 };
195195 }
196196
......@@ -207,13 +207,13 @@ const Tag = enum {
207207 fn encode(ty: Ref, value: i64) Int64 {
208208 return .{
209209 .ty = ty,
210 .low = @truncate(u32, @bitCast(u64, value)),
211 .high = @truncate(u32, @bitCast(u64, value) >> 32),
210 .low = @as(u32, @truncate(@as(u64, @bitCast(value)))),
211 .high = @as(u32, @truncate(@as(u64, @bitCast(value)) >> 32)),
212212 };
213213 }
214214
215215 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)));
217217 }
218218 };
219219};
......@@ -305,21 +305,21 @@ pub const Key = union(enum) {
305305 /// Turns this value into the corresponding 32-bit literal, 2s complement signed.
306306 fn toBits32(self: Int) u32 {
307307 return switch (self.value) {
308 .uint64 => |val| @intCast(u32, val),
309 .int64 => |val| if (val < 0) @bitCast(u32, @intCast(i32, val)) else @intCast(u32, val),
308 .uint64 => |val| @as(u32, @intCast(val)),
309 .int64 => |val| if (val < 0) @as(u32, @bitCast(@as(i32, @intCast(val)))) else @as(u32, @intCast(val)),
310310 };
311311 }
312312
313313 fn toBits64(self: Int) u64 {
314314 return switch (self.value) {
315315 .uint64 => |val| val,
316 .int64 => |val| @bitCast(u64, val),
316 .int64 => |val| @as(u64, @bitCast(val)),
317317 };
318318 }
319319
320320 fn to(self: Int, comptime T: type) T {
321321 return switch (self.value) {
322 inline else => |val| @intCast(T, val),
322 inline else => |val| @as(T, @intCast(val)),
323323 };
324324 }
325325 };
......@@ -357,9 +357,9 @@ pub const Key = union(enum) {
357357 .float => |float| {
358358 std.hash.autoHash(&hasher, float.ty);
359359 switch (float.value) {
360 .float16 => |value| std.hash.autoHash(&hasher, @bitCast(u16, value)),
361 .float32 => |value| std.hash.autoHash(&hasher, @bitCast(u32, value)),
362 .float64 => |value| std.hash.autoHash(&hasher, @bitCast(u64, value)),
360 .float16 => |value| std.hash.autoHash(&hasher, @as(u16, @bitCast(value))),
361 .float32 => |value| std.hash.autoHash(&hasher, @as(u32, @bitCast(value))),
362 .float64 => |value| std.hash.autoHash(&hasher, @as(u64, @bitCast(value))),
363363 }
364364 },
365365 .function_type => |func| {
......@@ -379,7 +379,7 @@ pub const Key = union(enum) {
379379 },
380380 inline else => |key| std.hash.autoHash(&hasher, key),
381381 }
382 return @truncate(u32, hasher.final());
382 return @as(u32, @truncate(hasher.final()));
383383 }
384384
385385 fn eql(a: Key, b: Key) bool {
......@@ -411,7 +411,7 @@ pub const Key = union(enum) {
411411
412412 pub fn eql(ctx: @This(), a: Key, b_void: void, b_index: usize) bool {
413413 _ = 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);
415415 }
416416
417417 pub fn hash(ctx: @This(), a: Key) u32 {
......@@ -445,7 +445,7 @@ pub fn materialize(self: *const Self, spv: *Module) !Section {
445445 var section = Section{};
446446 errdefer section.deinit(spv.gpa);
447447 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);
449449 }
450450 return section;
451451}
......@@ -534,7 +534,7 @@ fn emit(
534534 }
535535 for (struct_type.memberNames(), 0..) |member_name, i| {
536536 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});
538538 }
539539 }
540540 // TODO: Decorations?
......@@ -557,7 +557,7 @@ fn emit(
557557 .float => |float| {
558558 const ty_id = self.resultId(float.ty);
559559 const lit: Lit = switch (float.value) {
560 .float16 => |value| .{ .uint32 = @bitCast(u16, value) },
560 .float16 => |value| .{ .uint32 = @as(u16, @bitCast(value)) },
561561 .float32 => |value| .{ .float32 = value },
562562 .float64 => |value| .{ .float64 = value },
563563 };
......@@ -603,7 +603,7 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
603603 const adapter: Key.Adapter = .{ .self = self };
604604 const entry = try self.map.getOrPutAdapted(spv.gpa, key, adapter);
605605 if (entry.found_existing) {
606 return @enumFromInt(Ref, entry.index);
606 return @as(Ref, @enumFromInt(entry.index));
607607 }
608608 const result_id = spv.allocId();
609609 const item: Item = switch (key) {
......@@ -640,10 +640,10 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
640640 },
641641 .function_type => |function| blk: {
642642 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)),
644644 .return_type = function.return_type,
645645 });
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)));
647647 break :blk .{
648648 .tag = .type_function,
649649 .result_id = result_id,
......@@ -678,12 +678,12 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
678678 .struct_type => |struct_type| blk: {
679679 const extra = try self.addExtra(spv, Tag.SimpleStructType{
680680 .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)),
682682 });
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
685685 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)));
687687 break :blk Item{
688688 .tag = .type_struct_simple_with_member_names,
689689 .result_id = result_id,
......@@ -721,7 +721,7 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
721721 .result_id = result_id,
722722 .data = try self.addExtra(spv, Tag.UInt32{
723723 .ty = int.ty,
724 .value = @intCast(u32, val),
724 .value = @as(u32, @intCast(val)),
725725 }),
726726 };
727727 } 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 {
730730 .result_id = result_id,
731731 .data = try self.addExtra(spv, Tag.Int32{
732732 .ty = int.ty,
733 .value = @intCast(i32, val),
733 .value = @as(i32, @intCast(val)),
734734 }),
735735 };
736736 } else if (val < 0) {
737737 break :blk .{
738738 .tag = .int_large,
739739 .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)))),
741741 };
742742 } else {
743743 break :blk .{
744744 .tag = .uint_large,
745745 .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)))),
747747 };
748748 }
749749 },
......@@ -753,12 +753,12 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
753753 16 => .{
754754 .tag = .float16,
755755 .result_id = result_id,
756 .data = @bitCast(u16, float.value.float16),
756 .data = @as(u16, @bitCast(float.value.float16)),
757757 },
758758 32 => .{
759759 .tag = .float32,
760760 .result_id = result_id,
761 .data = @bitCast(u32, float.value.float32),
761 .data = @as(u32, @bitCast(float.value.float32)),
762762 },
763763 64 => .{
764764 .tag = .float64,
......@@ -788,7 +788,7 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
788788 };
789789 try self.items.append(spv.gpa, item);
790790
791 return @enumFromInt(Ref, entry.index);
791 return @as(Ref, @enumFromInt(entry.index));
792792}
793793
794794/// Turn a Ref back into a Key.
......@@ -797,20 +797,20 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
797797 const item = self.items.get(@intFromEnum(ref));
798798 const data = item.data;
799799 return switch (item.tag) {
800 .type_simple => switch (@enumFromInt(Tag.SimpleType, data)) {
800 .type_simple => switch (@as(Tag.SimpleType, @enumFromInt(data))) {
801801 .void => .void_type,
802802 .bool => .bool_type,
803803 },
804804 .type_int_signed => .{ .int_type = .{
805805 .signedness = .signed,
806 .bits = @intCast(u16, data),
806 .bits = @as(u16, @intCast(data)),
807807 } },
808808 .type_int_unsigned => .{ .int_type = .{
809809 .signedness = .unsigned,
810 .bits = @intCast(u16, data),
810 .bits = @as(u16, @intCast(data)),
811811 } },
812812 .type_float => .{ .float_type = .{
813 .bits = @intCast(u16, data),
813 .bits = @as(u16, @intCast(data)),
814814 } },
815815 .type_vector => .{ .vector_type = self.extraData(Tag.VectorType, data) },
816816 .type_array => .{ .array_type = self.extraData(Tag.ArrayType, data) },
......@@ -819,26 +819,26 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
819819 return .{
820820 .function_type = .{
821821 .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])),
823823 },
824824 };
825825 },
826826 .type_ptr_generic => .{
827827 .ptr_type = .{
828828 .storage_class = .Generic,
829 .child_type = @enumFromInt(Ref, data),
829 .child_type = @as(Ref, @enumFromInt(data)),
830830 },
831831 },
832832 .type_ptr_crosswgp => .{
833833 .ptr_type = .{
834834 .storage_class = .CrossWorkgroup,
835 .child_type = @enumFromInt(Ref, data),
835 .child_type = @as(Ref, @enumFromInt(data)),
836836 },
837837 },
838838 .type_ptr_function => .{
839839 .ptr_type = .{
840840 .storage_class = .Function,
841 .child_type = @enumFromInt(Ref, data),
841 .child_type = @as(Ref, @enumFromInt(data)),
842842 },
843843 },
844844 .type_ptr_simple => {
......@@ -852,7 +852,7 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
852852 },
853853 .type_struct_simple => {
854854 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]));
856856 return .{
857857 .struct_type = .{
858858 .name = payload.data.name,
......@@ -864,8 +864,8 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
864864 .type_struct_simple_with_member_names => {
865865 const payload = self.extraDataTrail(Tag.SimpleStructType, data);
866866 const trailing = self.extra.items[payload.trail..];
867 const member_types = @ptrCast([]const Ref, trailing[0..payload.data.members_len]);
868 const member_names = @ptrCast([]const String, trailing[payload.data.members_len..][0..payload.data.members_len]);
867 const member_types = @as([]const Ref, @ptrCast(trailing[0..payload.data.members_len]));
868 const member_names = @as([]const String, @ptrCast(trailing[payload.data.members_len..][0..payload.data.members_len]));
869869 return .{
870870 .struct_type = .{
871871 .name = payload.data.name,
......@@ -876,11 +876,11 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
876876 },
877877 .float16 => .{ .float = .{
878878 .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)))) },
880880 } },
881881 .float32 => .{ .float = .{
882882 .ty = self.get(.{ .float_type = .{ .bits = 32 } }),
883 .value = .{ .float32 = @bitCast(f32, data) },
883 .value = .{ .float32 = @as(f32, @bitCast(data)) },
884884 } },
885885 .float64 => .{ .float = .{
886886 .ty = self.get(.{ .float_type = .{ .bits = 64 } }),
......@@ -923,17 +923,17 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
923923 } };
924924 },
925925 .undef => .{ .undef = .{
926 .ty = @enumFromInt(Ref, data),
926 .ty = @as(Ref, @enumFromInt(data)),
927927 } },
928928 .null => .{ .null = .{
929 .ty = @enumFromInt(Ref, data),
929 .ty = @as(Ref, @enumFromInt(data)),
930930 } },
931931 .bool_true => .{ .bool = .{
932 .ty = @enumFromInt(Ref, data),
932 .ty = @as(Ref, @enumFromInt(data)),
933933 .value = true,
934934 } },
935935 .bool_false => .{ .bool = .{
936 .ty = @enumFromInt(Ref, data),
936 .ty = @as(Ref, @enumFromInt(data)),
937937 .value = false,
938938 } },
939939 };
......@@ -949,7 +949,7 @@ pub fn resultId(self: Self, ref: Ref) IdResult {
949949fn get(self: *const Self, key: Key) Ref {
950950 const adapter: Key.Adapter = .{ .self = self };
951951 const index = self.map.getIndexAdapted(key, adapter).?;
952 return @enumFromInt(Ref, index);
952 return @as(Ref, @enumFromInt(index));
953953}
954954
955955fn addExtra(self: *Self, spv: *Module, extra: anytype) !u32 {
......@@ -959,12 +959,12 @@ fn addExtra(self: *Self, spv: *Module, extra: anytype) !u32 {
959959}
960960
961961fn 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));
963963 inline for (@typeInfo(@TypeOf(extra)).Struct.fields) |field| {
964964 const field_val = @field(extra, field.name);
965965 const word = switch (field.type) {
966966 u32 => field_val,
967 i32 => @bitCast(u32, field_val),
967 i32 => @as(u32, @bitCast(field_val)),
968968 Ref => @intFromEnum(field_val),
969969 StorageClass => @intFromEnum(field_val),
970970 String => @intFromEnum(field_val),
......@@ -986,16 +986,16 @@ fn extraDataTrail(self: Self, comptime T: type, offset: u32) struct { data: T, t
986986 const word = self.extra.items[offset + i];
987987 @field(result, field.name) = switch (field.type) {
988988 u32 => word,
989 i32 => @bitCast(i32, word),
990 Ref => @enumFromInt(Ref, word),
991 StorageClass => @enumFromInt(StorageClass, word),
992 String => @enumFromInt(String, word),
989 i32 => @as(i32, @bitCast(word)),
990 Ref => @as(Ref, @enumFromInt(word)),
991 StorageClass => @as(StorageClass, @enumFromInt(word)),
992 String => @as(String, @enumFromInt(word)),
993993 else => @compileError("Invalid type: " ++ @typeName(field.type)),
994994 };
995995 }
996996 return .{
997997 .data = result,
998 .trail = offset + @intCast(u32, fields.len),
998 .trail = offset + @as(u32, @intCast(fields.len)),
999999 };
10001000}
10011001
......@@ -1017,7 +1017,7 @@ pub const String = enum(u32) {
10171017 _ = ctx;
10181018 var hasher = std.hash.Wyhash.init(0);
10191019 hasher.update(a);
1020 return @truncate(u32, hasher.final());
1020 return @as(u32, @truncate(hasher.final()));
10211021 }
10221022 };
10231023};
......@@ -1032,10 +1032,10 @@ pub fn addString(self: *Self, spv: *Module, str: []const u8) !String {
10321032 try self.string_bytes.ensureUnusedCapacity(spv.gpa, 1 + str.len);
10331033 self.string_bytes.appendSliceAssumeCapacity(str);
10341034 self.string_bytes.appendAssumeCapacity(0);
1035 entry.value_ptr.* = @intCast(u32, offset);
1035 entry.value_ptr.* = @as(u32, @intCast(offset));
10361036 }
10371037
1038 return @enumFromInt(String, entry.index);
1038 return @as(String, @enumFromInt(entry.index));
10391039}
10401040
10411041pub 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 {
451451 return try self.resolveId(.{ .int = .{
452452 .ty = ty_ref,
453453 .value = switch (ty.signedness) {
454 .signed => Value{ .int64 = @intCast(i64, value) },
455 .unsigned => Value{ .uint64 = @intCast(u64, value) },
454 .signed => Value{ .int64 = @as(i64, @intCast(value)) },
455 .unsigned => Value{ .uint64 = @as(u64, @intCast(value)) },
456456 },
457457 } });
458458}
......@@ -516,7 +516,7 @@ pub fn allocDecl(self: *Module, kind: DeclKind) !Decl.Index {
516516 .begin_dep = undefined,
517517 .end_dep = undefined,
518518 });
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))));
520520 switch (kind) {
521521 .func => {},
522522 // If the decl represents a global, also allocate a global node.
......@@ -540,9 +540,9 @@ pub fn globalPtr(self: *Module, index: Decl.Index) ?*Global {
540540
541541/// Declare ALL dependencies for a decl.
542542pub 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));
544544 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
547547 const decl = self.declPtr(decl_index);
548548 decl.begin_dep = begin_dep;
......@@ -550,13 +550,13 @@ pub fn declareDeclDeps(self: *Module, decl_index: Decl.Index, deps: []const Decl
550550}
551551
552552pub 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));
554554}
555555
556556pub fn endGlobal(self: *Module, global_index: Decl.Index, begin_inst: u32) void {
557557 const global = self.globalPtr(global_index).?;
558558 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));
560560}
561561
562562pub 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(
5050) !void {
5151 const word_count = 1 + operand_words;
5252 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));
5454}
5555
5656pub fn emit(
......@@ -61,7 +61,7 @@ pub fn emit(
6161) !void {
6262 const word_count = instructionSize(opcode, operands);
6363 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));
6565 section.writeOperands(opcode.Operands(), operands);
6666}
6767
......@@ -94,8 +94,8 @@ pub fn writeWords(section: *Section, words: []const Word) void {
9494
9595pub fn writeDoubleWord(section: *Section, dword: DoubleWord) void {
9696 section.writeWords(&.{
97 @truncate(Word, dword),
98 @truncate(Word, dword >> @bitSizeOf(Word)),
97 @as(Word, @truncate(dword)),
98 @as(Word, @truncate(dword >> @bitSizeOf(Word))),
9999 });
100100}
101101
......@@ -145,7 +145,7 @@ pub fn writeOperand(section: *Section, comptime Operand: type, operand: Operand)
145145 },
146146 .Struct => |info| {
147147 if (info.layout == .Packed) {
148 section.writeWord(@bitCast(Word, operand));
148 section.writeWord(@as(Word, @bitCast(operand)));
149149 } else {
150150 section.writeExtendedMask(Operand, operand);
151151 }
......@@ -166,7 +166,7 @@ fn writeString(section: *Section, str: []const u8) void {
166166
167167 var j: usize = 0;
168168 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)));
170170 }
171171
172172 section.instructions.appendAssumeCapacity(word);
......@@ -175,12 +175,12 @@ fn writeString(section: *Section, str: []const u8) void {
175175
176176fn writeContextDependentNumber(section: *Section, operand: spec.LiteralContextDependentNumber) void {
177177 switch (operand) {
178 .int32 => |int| section.writeWord(@bitCast(Word, int)),
179 .uint32 => |int| section.writeWord(@bitCast(Word, int)),
180 .int64 => |int| section.writeDoubleWord(@bitCast(DoubleWord, int)),
181 .uint64 => |int| section.writeDoubleWord(@bitCast(DoubleWord, int)),
182 .float32 => |float| section.writeWord(@bitCast(Word, float)),
183 .float64 => |float| section.writeDoubleWord(@bitCast(DoubleWord, float)),
178 .int32 => |int| section.writeWord(@as(Word, @bitCast(int))),
179 .uint32 => |int| section.writeWord(@as(Word, @bitCast(int))),
180 .int64 => |int| section.writeDoubleWord(@as(DoubleWord, @bitCast(int))),
181 .uint64 => |int| section.writeDoubleWord(@as(DoubleWord, @bitCast(int))),
182 .float32 => |float| section.writeWord(@as(Word, @bitCast(float))),
183 .float64 => |float| section.writeDoubleWord(@as(DoubleWord, @bitCast(float))),
184184 }
185185}
186186
......@@ -189,10 +189,10 @@ fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand
189189 inline for (@typeInfo(Operand).Struct.fields, 0..) |field, bit| {
190190 switch (@typeInfo(field.type)) {
191191 .Optional => if (@field(operand, field.name) != null) {
192 mask |= 1 << @intCast(u5, bit);
192 mask |= 1 << @as(u5, @intCast(bit));
193193 },
194194 .Bool => if (@field(operand, field.name)) {
195 mask |= 1 << @intCast(u5, bit);
195 mask |= 1 << @as(u5, @intCast(bit));
196196 },
197197 else => unreachable,
198198 }
......@@ -392,7 +392,7 @@ test "SPIR-V Section emit() - extended mask" {
392392 (@as(Word, 5) << 16) | @intFromEnum(Opcode.OpLoopMerge),
393393 10,
394394 20,
395 @bitCast(Word, spec.LoopControl{ .Unroll = true, .DependencyLength = true }),
395 @as(Word, @bitCast(spec.LoopControl{ .Unroll = true, .DependencyLength = true })),
396396 2,
397397 }, section.instructions.items);
398398}
src/crash_report.zig+24-24
......@@ -204,49 +204,49 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any
204204
205205 const stack_ctx: StackContext = switch (builtin.cpu.arch) {
206206 .x86 => ctx: {
207 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
208 const ip = @intCast(usize, ctx.mcontext.gregs[os.REG.EIP]);
209 const bp = @intCast(usize, ctx.mcontext.gregs[os.REG.EBP]);
207 const ctx: *const os.ucontext_t = @ptrCast(@alignCast(ctx_ptr));
208 const ip = @as(usize, @intCast(ctx.mcontext.gregs[os.REG.EIP]));
209 const bp = @as(usize, @intCast(ctx.mcontext.gregs[os.REG.EBP]));
210210 break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };
211211 },
212212 .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));
214214 const ip = switch (builtin.os.tag) {
215 .linux, .netbsd, .solaris => @intCast(usize, ctx.mcontext.gregs[os.REG.RIP]),
216 .freebsd => @intCast(usize, ctx.mcontext.rip),
217 .openbsd => @intCast(usize, ctx.sc_rip),
218 .macos => @intCast(usize, ctx.mcontext.ss.rip),
215 .linux, .netbsd, .solaris => @as(usize, @intCast(ctx.mcontext.gregs[os.REG.RIP])),
216 .freebsd => @as(usize, @intCast(ctx.mcontext.rip)),
217 .openbsd => @as(usize, @intCast(ctx.sc_rip)),
218 .macos => @as(usize, @intCast(ctx.mcontext.ss.rip)),
219219 else => unreachable,
220220 };
221221 const bp = switch (builtin.os.tag) {
222 .linux, .netbsd, .solaris => @intCast(usize, ctx.mcontext.gregs[os.REG.RBP]),
223 .openbsd => @intCast(usize, ctx.sc_rbp),
224 .freebsd => @intCast(usize, ctx.mcontext.rbp),
225 .macos => @intCast(usize, ctx.mcontext.ss.rbp),
222 .linux, .netbsd, .solaris => @as(usize, @intCast(ctx.mcontext.gregs[os.REG.RBP])),
223 .openbsd => @as(usize, @intCast(ctx.sc_rbp)),
224 .freebsd => @as(usize, @intCast(ctx.mcontext.rbp)),
225 .macos => @as(usize, @intCast(ctx.mcontext.ss.rbp)),
226226 else => unreachable,
227227 };
228228 break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };
229229 },
230230 .arm => ctx: {
231 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
232 const ip = @intCast(usize, ctx.mcontext.arm_pc);
233 const bp = @intCast(usize, ctx.mcontext.arm_fp);
231 const ctx: *const os.ucontext_t = @ptrCast(@alignCast(ctx_ptr));
232 const ip = @as(usize, @intCast(ctx.mcontext.arm_pc));
233 const bp = @as(usize, @intCast(ctx.mcontext.arm_fp));
234234 break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };
235235 },
236236 .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));
238238 const ip = switch (native_os) {
239 .macos => @intCast(usize, ctx.mcontext.ss.pc),
240 .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.PC]),
241 .freebsd => @intCast(usize, ctx.mcontext.gpregs.elr),
242 else => @intCast(usize, ctx.mcontext.pc),
239 .macos => @as(usize, @intCast(ctx.mcontext.ss.pc)),
240 .netbsd => @as(usize, @intCast(ctx.mcontext.gregs[os.REG.PC])),
241 .freebsd => @as(usize, @intCast(ctx.mcontext.gpregs.elr)),
242 else => @as(usize, @intCast(ctx.mcontext.pc)),
243243 };
244244 // x29 is the ABI-designated frame pointer
245245 const bp = switch (native_os) {
246 .macos => @intCast(usize, ctx.mcontext.ss.fp),
247 .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.FP]),
248 .freebsd => @intCast(usize, ctx.mcontext.gpregs.x[os.REG.FP]),
249 else => @intCast(usize, ctx.mcontext.regs[29]),
246 .macos => @as(usize, @intCast(ctx.mcontext.ss.fp)),
247 .netbsd => @as(usize, @intCast(ctx.mcontext.gregs[os.REG.FP])),
248 .freebsd => @as(usize, @intCast(ctx.mcontext.gpregs.x[os.REG.FP])),
249 else => @as(usize, @intCast(ctx.mcontext.regs[29])),
250250 };
251251 break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };
252252 },
src/glibc.zig+4-4
......@@ -779,13 +779,13 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo
779779 // Test whether the inclusion applies to our current library and target.
780780 const ok_lib_and_target =
781781 (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
784784 while (true) {
785785 const byte = metadata.inclusions[inc_i];
786786 inc_i += 1;
787787 const last = (byte & 0b1000_0000) != 0;
788 const ver_i = @truncate(u7, byte);
788 const ver_i = @as(u7, @truncate(byte));
789789 if (ok_lib_and_target and ver_i <= target_ver_index) {
790790 versions_buffer[versions_len] = ver_i;
791791 versions_len += 1;
......@@ -913,13 +913,13 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo
913913 // Test whether the inclusion applies to our current library and target.
914914 const ok_lib_and_target =
915915 (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
918918 while (true) {
919919 const byte = metadata.inclusions[inc_i];
920920 inc_i += 1;
921921 const last = (byte & 0b1000_0000) != 0;
922 const ver_i = @truncate(u7, byte);
922 const ver_i = @as(u7, @truncate(byte));
923923 if (ok_lib_and_target and ver_i <= target_ver_index) {
924924 versions_buffer[versions_len] = ver_i;
925925 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
292292 {
293293 var export_names: std.AutoHashMapUnmanaged(InternPool.NullTerminatedString, void) = .{};
294294 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)));
296296 for (module.decl_exports.values()) |exports| for (exports.items) |@"export"|
297297 try export_names.put(gpa, @"export".opts.name, {});
298298
......@@ -426,7 +426,7 @@ fn flushCTypes(
426426 return ctx.ctypes_map[idx - codegen.CType.Tag.no_payload_count];
427427 }
428428 };
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));
430430 const ctx = Context{
431431 .arena = global_ctypes.arena.allocator(),
432432 .ctypes_map = f.ctypes_map.items,
......@@ -437,7 +437,7 @@ fn flushCTypes(
437437 .store = &global_ctypes.set,
438438 });
439439 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));
441441 f.ctypes_map.appendAssumeCapacity(global_idx);
442442 if (!gop.found_existing) {
443443 errdefer _ = global_ctypes.set.map.pop();
......@@ -538,7 +538,7 @@ fn flushLazyFn(self: *C, db: *DeclBlock, lazy_fn: codegen.LazyFnMap.Entry) Flush
538538
539539fn flushLazyFns(self: *C, f: *Flush, lazy_fns: codegen.LazyFnMap) FlushDeclError!void {
540540 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
543543 var it = lazy_fns.iterator();
544544 while (it.next()) |entry| {
src/link/Coff.zig+55-55
......@@ -358,7 +358,7 @@ fn populateMissingMetadata(self: *Coff) !void {
358358 });
359359
360360 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));
362362 self.text_section_index = try self.allocateSection(".text", file_size, .{
363363 .CNT_CODE = 1,
364364 .MEM_EXECUTE = 1,
......@@ -367,7 +367,7 @@ fn populateMissingMetadata(self: *Coff) !void {
367367 }
368368
369369 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();
371371 self.got_section_index = try self.allocateSection(".got", file_size, .{
372372 .CNT_INITIALIZED_DATA = 1,
373373 .MEM_READ = 1,
......@@ -392,7 +392,7 @@ fn populateMissingMetadata(self: *Coff) !void {
392392 }
393393
394394 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();
396396 self.idata_section_index = try self.allocateSection(".idata", file_size, .{
397397 .CNT_INITIALIZED_DATA = 1,
398398 .MEM_READ = 1,
......@@ -400,7 +400,7 @@ fn populateMissingMetadata(self: *Coff) !void {
400400 }
401401
402402 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);
404404 self.reloc_section_index = try self.allocateSection(".reloc", file_size, .{
405405 .CNT_INITIALIZED_DATA = 1,
406406 .MEM_DISCARDABLE = 1,
......@@ -409,7 +409,7 @@ fn populateMissingMetadata(self: *Coff) !void {
409409 }
410410
411411 if (self.strtab_offset == null) {
412 const file_size = @intCast(u32, self.strtab.len());
412 const file_size = @as(u32, @intCast(self.strtab.len()));
413413 self.strtab_offset = self.findFreeSpace(file_size, @alignOf(u32)); // 4bytes aligned seems like a good idea here
414414 log.debug("found strtab free space 0x{x} to 0x{x}", .{ self.strtab_offset.?, self.strtab_offset.? + file_size });
415415 }
......@@ -430,7 +430,7 @@ fn populateMissingMetadata(self: *Coff) !void {
430430}
431431
432432fn 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));
434434 const off = self.findFreeSpace(size, default_file_alignment);
435435 // Memory is always allocated in sequence
436436 // 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 {
652652 break :blk index;
653653 } else {
654654 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));
656656 _ = self.locals.addOneAssumeCapacity();
657657 break :blk index;
658658 }
......@@ -680,7 +680,7 @@ fn allocateGlobal(self: *Coff) !u32 {
680680 break :blk index;
681681 } else {
682682 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));
684684 _ = self.globals.addOneAssumeCapacity();
685685 break :blk index;
686686 }
......@@ -704,7 +704,7 @@ fn addGotEntry(self: *Coff, target: SymbolWithLoc) !void {
704704
705705pub fn createAtom(self: *Coff) !Atom.Index {
706706 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));
708708 const atom = try self.atoms.addOne(gpa);
709709 const sym_index = try self.allocateSymbol();
710710 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 {
776776 self.resolveRelocs(atom_index, relocs.items, mem_code, slide);
777777
778778 const vaddr = sym.value + slide;
779 const pvaddr = @ptrFromInt(*anyopaque, vaddr);
779 const pvaddr = @as(*anyopaque, @ptrFromInt(vaddr));
780780
781781 log.debug("writing to memory at address {x}", .{vaddr});
782782
......@@ -830,7 +830,7 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void {
830830 const sect_id = self.got_section_index.?;
831831
832832 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()));
834834 try self.growSection(sect_id, needed_size);
835835 self.got_table_count_dirty = false;
836836 }
......@@ -847,7 +847,7 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void {
847847 switch (self.ptr_width) {
848848 .p32 => {
849849 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())));
851851 try self.base.file.?.pwriteAll(&buf, file_offset);
852852 },
853853 .p64 => {
......@@ -862,7 +862,7 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void {
862862 const gpa = self.base.allocator;
863863 const slide = @intFromPtr(self.hot_state.loaded_base_address.?);
864864 const actual_vmaddr = vmaddr + slide;
865 const pvaddr = @ptrFromInt(*anyopaque, actual_vmaddr);
865 const pvaddr = @as(*anyopaque, @ptrFromInt(actual_vmaddr));
866866 log.debug("writing GOT entry to memory at address {x}", .{actual_vmaddr});
867867 if (build_options.enable_logging) {
868868 switch (self.ptr_width) {
......@@ -880,7 +880,7 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void {
880880 switch (self.ptr_width) {
881881 .p32 => {
882882 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)));
884884 writeMem(handle, pvaddr, &buf) catch |err| {
885885 log.warn("writing to protected memory failed with error: {s}", .{@errorName(err)});
886886 };
......@@ -1107,7 +1107,7 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In
11071107 const atom = self.getAtom(atom_index);
11081108 const sym = atom.getSymbolPtr(self);
11091109 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));
11111111 }
11121112
11131113 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
11251125
11261126 const required_alignment = tv.ty.abiAlignment(mod);
11271127 const atom = self.getAtomPtr(atom_index);
1128 atom.size = @intCast(u32, code.len);
1128 atom.size = @as(u32, @intCast(code.len));
11291129 atom.getSymbolPtr(self).value = try self.allocateAtom(atom_index, atom.size, required_alignment);
11301130 errdefer self.freeAtom(atom_index);
11311131
......@@ -1241,10 +1241,10 @@ fn updateLazySymbolAtom(
12411241 },
12421242 };
12431243
1244 const code_len = @intCast(u32, code.len);
1244 const code_len = @as(u32, @intCast(code.len));
12451245 const symbol = atom.getSymbolPtr(self);
12461246 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));
12481248 symbol.type = .{ .complex_type = .NULL, .base_type = .NULL };
12491249
12501250 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
13361336 const atom = self.getAtom(atom_index);
13371337 const sym_index = atom.getSymbolIndex().?;
13381338 const sect_index = decl_metadata.section;
1339 const code_len = @intCast(u32, code.len);
1339 const code_len = @as(u32, @intCast(code.len));
13401340
13411341 if (atom.size != 0) {
13421342 const sym = atom.getSymbolPtr(self);
13431343 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));
13451345 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };
13461346
13471347 const capacity = atom.capacity(self);
......@@ -1365,7 +1365,7 @@ fn updateDeclCode(self: *Coff, decl_index: Module.Decl.Index, code: []u8, comple
13651365 } else {
13661366 const sym = atom.getSymbolPtr(self);
13671367 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));
13691369 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };
13701370
13711371 const vaddr = try self.allocateAtom(atom_index, code_len, required_alignment);
......@@ -1502,7 +1502,7 @@ pub fn updateDeclExports(
15021502 const sym = self.getSymbolPtr(sym_loc);
15031503 try self.setSymbolName(sym, mod.intern_pool.stringToSlice(exp.opts.name));
15041504 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));
15061506 sym.type = .{ .complex_type = .FUNCTION, .base_type = .NULL };
15071507
15081508 switch (exp.opts.linkage) {
......@@ -1728,12 +1728,12 @@ pub fn getDeclVAddr(self: *Coff, decl_index: Module.Decl.Index, reloc_info: link
17281728 try Atom.addRelocation(self, atom_index, .{
17291729 .type = .direct,
17301730 .target = target,
1731 .offset = @intCast(u32, reloc_info.offset),
1731 .offset = @as(u32, @intCast(reloc_info.offset)),
17321732 .addend = reloc_info.addend,
17331733 .pcrel = false,
17341734 .length = 3,
17351735 });
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
17381738 return 0;
17391739}
......@@ -1804,7 +1804,7 @@ fn writeBaseRelocations(self: *Coff) !void {
18041804 gop.value_ptr.* = std.ArrayList(coff.BaseRelocation).init(gpa);
18051805 }
18061806 try gop.value_ptr.append(.{
1807 .offset = @intCast(u12, rva - page),
1807 .offset = @as(u12, @intCast(rva - page)),
18081808 .type = .DIR64,
18091809 });
18101810 }
......@@ -1818,14 +1818,14 @@ fn writeBaseRelocations(self: *Coff) !void {
18181818 const sym = self.getSymbol(entry);
18191819 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()));
18221822 const page = mem.alignBackward(u32, rva, self.page_size);
18231823 const gop = try page_table.getOrPut(page);
18241824 if (!gop.found_existing) {
18251825 gop.value_ptr.* = std.ArrayList(coff.BaseRelocation).init(gpa);
18261826 }
18271827 try gop.value_ptr.append(.{
1828 .offset = @intCast(u12, rva - page),
1828 .offset = @as(u12, @intCast(rva - page)),
18291829 .type = .DIR64,
18301830 });
18311831 }
......@@ -1860,9 +1860,9 @@ fn writeBaseRelocations(self: *Coff) !void {
18601860 });
18611861 }
18621862
1863 const block_size = @intCast(
1863 const block_size = @as(
18641864 u32,
1865 entries.items.len * @sizeOf(coff.BaseRelocation) + @sizeOf(coff.BaseRelocationDirectoryEntry),
1865 @intCast(entries.items.len * @sizeOf(coff.BaseRelocation) + @sizeOf(coff.BaseRelocationDirectoryEntry)),
18661866 );
18671867 try buffer.ensureUnusedCapacity(block_size);
18681868 buffer.appendSliceAssumeCapacity(mem.asBytes(&coff.BaseRelocationDirectoryEntry{
......@@ -1873,7 +1873,7 @@ fn writeBaseRelocations(self: *Coff) !void {
18731873 }
18741874
18751875 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));
18771877 try self.growSection(self.reloc_section_index.?, needed_size);
18781878
18791879 try self.base.file.?.pwriteAll(buffer.items, header.pointer_to_raw_data);
......@@ -1904,12 +1904,12 @@ fn writeImportTables(self: *Coff) !void {
19041904 const itable = self.import_tables.values()[i];
19051905 iat_size += itable.size() + 8;
19061906 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);
19081908 for (itable.entries.items) |entry| {
19091909 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);
19111911 }
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));
19131913 }
19141914
19151915 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 {
19481948 const import_name = self.getSymbolName(entry);
19491949
19501950 // 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)) };
19521952 @memcpy(
19531953 buffer.items[iat_offset..][0..@sizeOf(coff.ImportLookupEntry64.ByName)],
19541954 mem.asBytes(&lookup),
......@@ -1964,7 +1964,7 @@ fn writeImportTables(self: *Coff) !void {
19641964 mem.writeIntLittle(u16, buffer.items[names_table_offset..][0..2], 0); // Hint set to 0 until we learn how to parse DLLs
19651965 names_table_offset += 2;
19661966 @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));
19681968 buffer.items[names_table_offset] = 0;
19691969 names_table_offset += 1;
19701970 if (!mem.isAlignedGeneric(usize, names_table_offset, @sizeOf(u16))) {
......@@ -1986,9 +1986,9 @@ fn writeImportTables(self: *Coff) !void {
19861986
19871987 // DLL name
19881988 @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));
19901990 @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));
19921992 buffer.items[dll_names_offset] = 0;
19931993 dll_names_offset += 1;
19941994 }
......@@ -2027,11 +2027,11 @@ fn writeStrtab(self: *Coff) !void {
20272027 if (self.strtab_offset == null) return;
20282028
20292029 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
20322032 if (needed_size > allocated_size) {
20332033 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))));
20352035 }
20362036
20372037 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 {
20422042 buffer.appendSliceAssumeCapacity(self.strtab.items());
20432043 // Here, we do a trick in that we do not commit the size of the strtab to strtab buffer, instead
20442044 // 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
20472047 try self.base.file.?.pwriteAll(buffer.items, self.strtab_offset.?);
20482048}
......@@ -2081,11 +2081,11 @@ fn writeHeader(self: *Coff) !void {
20812081 }
20822082
20832083 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()));
20852085 var coff_header = coff.CoffHeader{
20862086 .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 section
2088 .time_date_stamp = @truncate(u32, @bitCast(u64, timestamp)),
2087 .number_of_sections = @as(u16, @intCast(self.sections.slice().len)), // TODO what if we prune a section
2088 .time_date_stamp = @as(u32, @truncate(@as(u64, @bitCast(timestamp)))),
20892089 .pointer_to_symbol_table = self.strtab_offset orelse 0,
20902090 .number_of_symbols = 0,
20912091 .size_of_optional_header = size_of_optional_header,
......@@ -2135,7 +2135,7 @@ fn writeHeader(self: *Coff) !void {
21352135 .address_of_entry_point = self.entry_addr orelse 0,
21362136 .base_of_code = base_of_code,
21372137 .base_of_data = base_of_data,
2138 .image_base = @intCast(u32, image_base),
2138 .image_base = @as(u32, @intCast(image_base)),
21392139 .section_alignment = self.page_size,
21402140 .file_alignment = default_file_alignment,
21412141 .major_operating_system_version = 6,
......@@ -2155,7 +2155,7 @@ fn writeHeader(self: *Coff) !void {
21552155 .size_of_heap_reserve = default_size_of_heap_reserve,
21562156 .size_of_heap_commit = default_size_of_heap_commit,
21572157 .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)),
21592159 };
21602160 writer.writeAll(mem.asBytes(&opt_header)) catch unreachable;
21612161 },
......@@ -2189,7 +2189,7 @@ fn writeHeader(self: *Coff) !void {
21892189 .size_of_heap_reserve = default_size_of_heap_reserve,
21902190 .size_of_heap_commit = default_size_of_heap_commit,
21912191 .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)),
21932193 };
21942194 writer.writeAll(mem.asBytes(&opt_header)) catch unreachable;
21952195 },
......@@ -2210,7 +2210,7 @@ fn detectAllocCollision(self: *Coff, start: u32, size: u32) ?u32 {
22102210 const end = start + padToIdeal(size);
22112211
22122212 if (self.strtab_offset) |off| {
2213 const tight_size = @intCast(u32, self.strtab.len());
2213 const tight_size = @as(u32, @intCast(self.strtab.len()));
22142214 const increased_size = padToIdeal(tight_size);
22152215 const test_end = off + increased_size;
22162216 if (end > off and start < test_end) {
......@@ -2265,28 +2265,28 @@ fn allocatedVirtualSize(self: *Coff, start: u32) u32 {
22652265
22662266inline fn getSizeOfHeaders(self: Coff) u32 {
22672267 const msdos_hdr_size = msdos_stub.len + 4;
2268 return @intCast(u32, msdos_hdr_size + @sizeOf(coff.CoffHeader) + self.getOptionalHeaderSize() +
2269 self.getDataDirectoryHeadersSize() + self.getSectionHeadersSize());
2268 return @as(u32, @intCast(msdos_hdr_size + @sizeOf(coff.CoffHeader) + self.getOptionalHeaderSize() +
2269 self.getDataDirectoryHeadersSize() + self.getSectionHeadersSize()));
22702270}
22712271
22722272inline fn getOptionalHeaderSize(self: Coff) u32 {
22732273 return switch (self.ptr_width) {
2274 .p32 => @intCast(u32, @sizeOf(coff.OptionalHeaderPE32)),
2275 .p64 => @intCast(u32, @sizeOf(coff.OptionalHeaderPE64)),
2274 .p32 => @as(u32, @intCast(@sizeOf(coff.OptionalHeaderPE32))),
2275 .p64 => @as(u32, @intCast(@sizeOf(coff.OptionalHeaderPE64))),
22762276 };
22772277}
22782278
22792279inline 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)));
22812281}
22822282
22832283inline 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)));
22852285}
22862286
22872287inline fn getDataDirectoryHeadersOffset(self: Coff) u32 {
22882288 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()));
22902290}
22912291
22922292inline fn getSectionHeadersOffset(self: Coff) u32 {
......@@ -2473,7 +2473,7 @@ fn logSymtab(self: *Coff) void {
24732473 };
24742474 log.debug(" %{d}: {?s} @{x} in {s}({d}), {s}", .{
24752475 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 }),
24772477 sym.value,
24782478 where,
24792479 def_index,
src/link/Coff/ImportTable.zig+3-3
......@@ -38,7 +38,7 @@ pub fn deinit(itab: *ImportTable, allocator: Allocator) void {
3838
3939/// Size of the import table does not include the sentinel.
4040pub 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);
4242}
4343
4444pub fn addImport(itab: *ImportTable, allocator: Allocator, target: SymbolWithLoc) !ImportIndex {
......@@ -49,7 +49,7 @@ pub fn addImport(itab: *ImportTable, allocator: Allocator, target: SymbolWithLoc
4949 break :blk index;
5050 } else {
5151 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));
5353 _ = itab.entries.addOneAssumeCapacity();
5454 break :blk index;
5555 }
......@@ -73,7 +73,7 @@ fn getBaseAddress(ctx: Context) u32 {
7373 var addr = header.virtual_address;
7474 for (ctx.coff_file.import_tables.values(), 0..) |other_itab, i| {
7575 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;
7777 }
7878 return addr;
7979}
src/link/Coff/Relocation.zig+12-12
......@@ -126,23 +126,23 @@ fn resolveAarch64(self: Relocation, ctx: Context) void {
126126 var buffer = ctx.code[self.offset..];
127127 switch (self.type) {
128128 .got_page, .import_page, .page => {
129 const source_page = @intCast(i32, ctx.source_vaddr >> 12);
130 const target_page = @intCast(i32, ctx.target_vaddr >> 12);
131 const pages = @bitCast(u21, @intCast(i21, target_page - source_page));
129 const source_page = @as(i32, @intCast(ctx.source_vaddr >> 12));
130 const target_page = @as(i32, @intCast(ctx.target_vaddr >> 12));
131 const pages = @as(u21, @bitCast(@as(i21, @intCast(target_page - source_page))));
132132 var inst = aarch64.Instruction{
133133 .pc_relative_address = mem.bytesToValue(meta.TagPayload(
134134 aarch64.Instruction,
135135 aarch64.Instruction.pc_relative_address,
136136 ), buffer[0..4]),
137137 };
138 inst.pc_relative_address.immhi = @truncate(u19, pages >> 2);
139 inst.pc_relative_address.immlo = @truncate(u2, pages);
138 inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2));
139 inst.pc_relative_address.immlo = @as(u2, @truncate(pages));
140140 mem.writeIntLittle(u32, buffer[0..4], inst.toU32());
141141 },
142142 .got_pageoff, .import_pageoff, .pageoff => {
143143 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))));
146146 if (isArithmeticOp(buffer[0..4])) {
147147 var inst = aarch64.Instruction{
148148 .add_subtract_immediate = mem.bytesToValue(meta.TagPayload(
......@@ -182,7 +182,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void {
182182 2 => mem.writeIntLittle(
183183 u32,
184184 buffer[0..4],
185 @truncate(u32, ctx.target_vaddr + ctx.image_base),
185 @as(u32, @truncate(ctx.target_vaddr + ctx.image_base)),
186186 ),
187187 3 => mem.writeIntLittle(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base),
188188 else => unreachable,
......@@ -206,17 +206,17 @@ fn resolveX86(self: Relocation, ctx: Context) void {
206206
207207 .got, .import => {
208208 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;
210210 mem.writeIntLittle(i32, buffer[0..4], disp);
211211 },
212212 .direct => {
213213 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;
215215 mem.writeIntLittle(i32, buffer[0..4], disp);
216216 } 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))),
218218 .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))),
220220 3 => mem.writeIntLittle(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base),
221221 else => unreachable,
222222 },
......@@ -226,6 +226,6 @@ fn resolveX86(self: Relocation, ctx: Context) void {
226226}
227227
228228inline fn isArithmeticOp(inst: *const [4]u8) bool {
229 const group_decode = @truncate(u5, inst[3]);
229 const group_decode = @as(u5, @truncate(inst[3]));
230230 return ((group_decode >> 2) == 4);
231231}
src/link/Dwarf.zig+58-58
......@@ -138,7 +138,7 @@ pub const DeclState = struct {
138138 /// which we use as our target of the relocation.
139139 fn addTypeRelocGlobal(self: *DeclState, atom_index: Atom.Index, ty: Type, offset: u32) !void {
140140 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));
142142 try self.abbrev_table.append(self.gpa, .{
143143 .atom_index = atom_index,
144144 .type = ty,
......@@ -225,7 +225,7 @@ pub const DeclState = struct {
225225 // DW.AT.type, DW.FORM.ref4
226226 var index = dbg_info_buffer.items.len;
227227 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)));
229229 // DW.AT.data_member_location, DW.FORM.udata
230230 try dbg_info_buffer.ensureUnusedCapacity(6);
231231 dbg_info_buffer.appendAssumeCapacity(0);
......@@ -237,7 +237,7 @@ pub const DeclState = struct {
237237 // DW.AT.type, DW.FORM.ref4
238238 index = dbg_info_buffer.items.len;
239239 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)));
241241 // DW.AT.data_member_location, DW.FORM.udata
242242 const offset = abi_size - payload_ty.abiSize(mod);
243243 try leb128.writeULEB128(dbg_info_buffer.writer(), offset);
......@@ -249,7 +249,7 @@ pub const DeclState = struct {
249249 if (ty.isSlice(mod)) {
250250 // Slices are structs: struct { .ptr = *, .len = N }
251251 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)));
253253 // DW.AT.structure_type
254254 try dbg_info_buffer.ensureUnusedCapacity(2);
255255 dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevKind.struct_type));
......@@ -267,7 +267,7 @@ pub const DeclState = struct {
267267 var index = dbg_info_buffer.items.len;
268268 try dbg_info_buffer.resize(index + 4);
269269 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)));
271271 // DW.AT.data_member_location, DW.FORM.udata
272272 try dbg_info_buffer.ensureUnusedCapacity(6);
273273 dbg_info_buffer.appendAssumeCapacity(0);
......@@ -279,7 +279,7 @@ pub const DeclState = struct {
279279 // DW.AT.type, DW.FORM.ref4
280280 index = dbg_info_buffer.items.len;
281281 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)));
283283 // DW.AT.data_member_location, DW.FORM.udata
284284 try dbg_info_buffer.ensureUnusedCapacity(2);
285285 dbg_info_buffer.appendAssumeCapacity(ptr_bytes);
......@@ -291,7 +291,7 @@ pub const DeclState = struct {
291291 // DW.AT.type, DW.FORM.ref4
292292 const index = dbg_info_buffer.items.len;
293293 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)));
295295 }
296296 },
297297 .Array => {
......@@ -302,13 +302,13 @@ pub const DeclState = struct {
302302 // DW.AT.type, DW.FORM.ref4
303303 var index = dbg_info_buffer.items.len;
304304 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)));
306306 // DW.AT.subrange_type
307307 try dbg_info_buffer.append(@intFromEnum(AbbrevKind.array_dim));
308308 // DW.AT.type, DW.FORM.ref4
309309 index = dbg_info_buffer.items.len;
310310 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)));
312312 // DW.AT.count, DW.FORM.udata
313313 const len = ty.arrayLenIncludingSentinel(mod);
314314 try leb128.writeULEB128(dbg_info_buffer.writer(), len);
......@@ -334,7 +334,7 @@ pub const DeclState = struct {
334334 // DW.AT.type, DW.FORM.ref4
335335 var index = dbg_info_buffer.items.len;
336336 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)));
338338 // DW.AT.data_member_location, DW.FORM.udata
339339 const field_off = ty.structFieldOffset(field_index, mod);
340340 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);
......@@ -367,7 +367,7 @@ pub const DeclState = struct {
367367 // DW.AT.type, DW.FORM.ref4
368368 var index = dbg_info_buffer.items.len;
369369 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)));
371371 // DW.AT.data_member_location, DW.FORM.udata
372372 const field_off = ty.structFieldOffset(field_index, mod);
373373 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);
......@@ -404,7 +404,7 @@ pub const DeclState = struct {
404404 // TODO do not assume a 64bit enum value - could be bigger.
405405 // See https://github.com/ziglang/zig/issues/645
406406 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)));
408408 };
409409 mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), value, target_endian);
410410 }
......@@ -439,7 +439,7 @@ pub const DeclState = struct {
439439 // DW.AT.type, DW.FORM.ref4
440440 const inner_union_index = dbg_info_buffer.items.len;
441441 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);
443443 // DW.AT.data_member_location, DW.FORM.udata
444444 try leb128.writeULEB128(dbg_info_buffer.writer(), payload_offset);
445445 }
......@@ -468,7 +468,7 @@ pub const DeclState = struct {
468468 // DW.AT.type, DW.FORM.ref4
469469 const index = dbg_info_buffer.items.len;
470470 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)));
472472 // DW.AT.data_member_location, DW.FORM.udata
473473 try dbg_info_buffer.append(0);
474474 }
......@@ -485,7 +485,7 @@ pub const DeclState = struct {
485485 // DW.AT.type, DW.FORM.ref4
486486 const index = dbg_info_buffer.items.len;
487487 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)));
489489 // DW.AT.data_member_location, DW.FORM.udata
490490 try leb128.writeULEB128(dbg_info_buffer.writer(), tag_offset);
491491
......@@ -521,7 +521,7 @@ pub const DeclState = struct {
521521 // DW.AT.type, DW.FORM.ref4
522522 const index = dbg_info_buffer.items.len;
523523 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)));
525525 // DW.AT.data_member_location, DW.FORM.udata
526526 try leb128.writeULEB128(dbg_info_buffer.writer(), payload_off);
527527 }
......@@ -536,7 +536,7 @@ pub const DeclState = struct {
536536 // DW.AT.type, DW.FORM.ref4
537537 const index = dbg_info_buffer.items.len;
538538 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)));
540540 // DW.AT.data_member_location, DW.FORM.udata
541541 try leb128.writeULEB128(dbg_info_buffer.writer(), error_off);
542542 }
......@@ -640,7 +640,7 @@ pub const DeclState = struct {
640640 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
641641 const index = dbg_info.items.len;
642642 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.ref4
643 try self.addTypeRelocGlobal(atom_index, ty, @as(u32, @intCast(index))); // DW.AT.type, DW.FORM.ref4
644644 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
645645 }
646646
......@@ -723,20 +723,20 @@ pub const DeclState = struct {
723723 .memory,
724724 .linker_load,
725725 => {
726 const ptr_width = @intCast(u8, @divExact(target.ptrBitWidth(), 8));
726 const ptr_width = @as(u8, @intCast(@divExact(target.ptrBitWidth(), 8)));
727727 try dbg_info.ensureUnusedCapacity(2 + ptr_width);
728728 dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc
729729 1 + ptr_width + @intFromBool(is_ptr),
730730 DW.OP.addr, // literal address
731731 });
732 const offset = @intCast(u32, dbg_info.items.len);
732 const offset = @as(u32, @intCast(dbg_info.items.len));
733733 const addr = switch (loc) {
734734 .memory => |x| x,
735735 else => 0,
736736 };
737737 switch (ptr_width) {
738738 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);
740740 },
741741 5...8 => {
742742 try dbg_info.writer().writeInt(u64, addr, endian);
......@@ -765,19 +765,19 @@ pub const DeclState = struct {
765765 if (child_ty.isSignedInt(mod)) DW.OP.consts else DW.OP.constu,
766766 });
767767 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)));
769769 } else {
770770 try leb128.writeULEB128(dbg_info.writer(), x);
771771 }
772772 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));
774774 },
775775
776776 .undef => {
777777 // DW.AT.location, DW.FORM.exprloc
778778 // uleb128(exprloc_len)
779779 // 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)));
781781 var implicit_value_len = std.ArrayList(u8).init(self.gpa);
782782 defer implicit_value_len.deinit();
783783 try leb128.writeULEB128(implicit_value_len.writer(), abi_size);
......@@ -807,7 +807,7 @@ pub const DeclState = struct {
807807 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
808808 const index = dbg_info.items.len;
809809 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)));
811811 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
812812 }
813813
......@@ -963,7 +963,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index)
963963 func.lbrace_line,
964964 func.rbrace_line,
965965 });
966 const line = @intCast(u28, decl.src_line + func.lbrace_line);
966 const line = @as(u28, @intCast(decl.src_line + func.lbrace_line));
967967
968968 const ptr_width_bytes = self.ptrWidthBytes();
969969 dbg_line_buffer.appendSliceAssumeCapacity(&[_]u8{
......@@ -1013,7 +1013,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index)
10131013 dbg_info_buffer.items.len += 4; // DW.AT.high_pc, DW.FORM.data4
10141014 //
10151015 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)));
10171017 dbg_info_buffer.items.len += 4; // DW.AT.type, DW.FORM.ref4
10181018 }
10191019
......@@ -1055,11 +1055,11 @@ pub fn commitDeclState(
10551055 .p32 => {
10561056 {
10571057 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);
10591059 }
10601060 {
10611061 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);
10631063 }
10641064 },
10651065 .p64 => {
......@@ -1079,7 +1079,7 @@ pub fn commitDeclState(
10791079 sym_size,
10801080 });
10811081 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);
10831083 }
10841084
10851085 try dbg_line_buffer.appendSlice(&[_]u8{ DW.LNS.extended_op, 1, DW.LNE.end_sequence });
......@@ -1091,7 +1091,7 @@ pub fn commitDeclState(
10911091 // probably need to edit that logic too.
10921092 const src_fn_index = self.src_fn_decls.get(decl_index).?;
10931093 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
10961096 if (self.src_fn_last_index) |last_index| blk: {
10971097 if (src_fn_index == last_index) break :blk;
......@@ -1254,12 +1254,12 @@ pub fn commitDeclState(
12541254 };
12551255 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));
12581258 try decl_state.addDbgInfoType(mod, di_atom_index, ty);
12591259 }
12601260 }
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
12641264 while (decl_state.abbrev_relocs.popOrNull()) |reloc| {
12651265 if (reloc.target) |target| {
......@@ -1402,7 +1402,7 @@ fn updateDeclDebugInfoAllocation(self: *Dwarf, atom_index: Atom.Index, len: u32)
14021402 self.di_atom_first_index = atom_index;
14031403 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())));
14061406 }
14071407}
14081408
......@@ -1513,7 +1513,7 @@ pub fn updateDeclLineNumber(self: *Dwarf, mod: *Module, decl_index: Module.Decl.
15131513 func.lbrace_line,
15141514 func.rbrace_line,
15151515 });
1516 const line = @intCast(u28, decl.src_line + func.lbrace_line);
1516 const line = @as(u28, @intCast(decl.src_line + func.lbrace_line));
15171517 var data: [4]u8 = undefined;
15181518 leb128.writeUnsignedFixed(4, &data, line);
15191519
......@@ -1791,10 +1791,10 @@ pub fn writeDbgInfoHeader(self: *Dwarf, module: *Module, low_pc: u64, high_pc: u
17911791 const dbg_info_end = self.getDebugInfoEnd().? + 1;
17921792 const init_len = dbg_info_end - after_init_len;
17931793 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)));
17951795 } else switch (self.ptr_width) {
17961796 .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);
17981798 },
17991799 .p64 => {
18001800 di_buf.appendNTimesAssumeCapacity(0xff, 4);
......@@ -1804,11 +1804,11 @@ pub fn writeDbgInfoHeader(self: *Dwarf, module: *Module, low_pc: u64, high_pc: u
18041804 mem.writeInt(u16, di_buf.addManyAsArrayAssumeCapacity(2), 4, target_endian); // DWARF version
18051805 const abbrev_offset = self.abbrev_table_offset.?;
18061806 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)));
18081808 di_buf.appendAssumeCapacity(8); // address size
18091809 } else switch (self.ptr_width) {
18101810 .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);
18121812 di_buf.appendAssumeCapacity(4); // address size
18131813 },
18141814 .p64 => {
......@@ -1828,9 +1828,9 @@ pub fn writeDbgInfoHeader(self: *Dwarf, module: *Module, low_pc: u64, high_pc: u
18281828 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), 0); // DW.AT.stmt_list, DW.FORM.sec_offset
18291829 mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), low_pc);
18301830 mem.writeIntLittle(u64, di_buf.addManyAsArrayAssumeCapacity(8), high_pc);
1831 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, name_strp));
1832 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, comp_dir_strp));
1833 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @intCast(u32, producer_strp));
1831 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @as(u32, @intCast(name_strp)));
1832 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @as(u32, @intCast(comp_dir_strp)));
1833 mem.writeIntLittle(u32, di_buf.addManyAsArrayAssumeCapacity(4), @as(u32, @intCast(producer_strp)));
18341834 } else {
18351835 self.writeAddrAssumeCapacity(&di_buf, 0); // DW.AT.stmt_list, DW.FORM.sec_offset
18361836 self.writeAddrAssumeCapacity(&di_buf, low_pc);
......@@ -1885,7 +1885,7 @@ fn resolveCompilationDir(module: *Module, buffer: *[std.fs.MAX_PATH_BYTES]u8) []
18851885fn writeAddrAssumeCapacity(self: *Dwarf, buf: *std.ArrayList(u8), addr: u64) void {
18861886 const target_endian = self.target.cpu.arch.endian();
18871887 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),
18891889 .p64 => mem.writeInt(u64, buf.addManyAsArrayAssumeCapacity(8), addr, target_endian),
18901890 }
18911891}
......@@ -2152,10 +2152,10 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void {
21522152 // Go back and populate the initial length.
21532153 const init_len = di_buf.items.len - after_init_len;
21542154 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)));
21562156 } else switch (self.ptr_width) {
21572157 .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);
21592159 },
21602160 .p64 => {
21612161 // 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 {
21652165 },
21662166 }
21672167
2168 const needed_size = @intCast(u32, di_buf.items.len);
2168 const needed_size = @as(u32, @intCast(di_buf.items.len));
21692169 switch (self.bin_file.tag) {
21702170 .elf => {
21712171 const elf_file = self.bin_file.cast(File.Elf).?;
......@@ -2293,7 +2293,7 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {
22932293 di_buf.appendSliceAssumeCapacity(file);
22942294 di_buf.appendSliceAssumeCapacity(&[_]u8{
22952295 0, // null byte for the relative path name
2296 @intCast(u8, dir_index), // directory_index
2296 @as(u8, @intCast(dir_index)), // directory_index
22972297 0, // mtime (TODO supply this)
22982298 0, // file size bytes (TODO supply this)
22992299 });
......@@ -2304,11 +2304,11 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {
23042304
23052305 switch (self.bin_file.tag) {
23062306 .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)));
23082308 },
23092309 else => switch (self.ptr_width) {
23102310 .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);
23122312 },
23132313 .p64 => {
23142314 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 {
23482348 .macho => {
23492349 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
23502350 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));
23522352 try d_sym.growSection(sect_index, needed_size, true);
23532353 const file_pos = d_sym.getSection(sect_index).offset + first_fn.off;
23542354
......@@ -2384,11 +2384,11 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {
23842384 const init_len = self.getDebugLineProgramEnd().? - before_init_len - init_len_size;
23852385 switch (self.bin_file.tag) {
23862386 .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)));
23882388 },
23892389 else => switch (self.ptr_width) {
23902390 .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);
23922392 },
23932393 .p64 => {
23942394 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
24772477 }
24782478 size += 1; // file names sentinel
24792479
2480 return @intCast(u32, size);
2480 return @as(u32, @intCast(size));
24812481}
24822482
24832483/// 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 {
25162516
25172517 const di_atom_index = try self.createAtom(.di_atom);
25182518 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)));
25202520 log.debug("writeDeclDebugInfo in flushModule", .{});
25212521 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 {
25812581 else => unreachable,
25822582 }
25832583 }
2584 return @intCast(u28, gop.index + 1);
2584 return @as(u28, @intCast(gop.index + 1));
25852585}
25862586
25872587fn genIncludeDirsAndFileNames(self: *Dwarf, arena: Allocator) !struct {
......@@ -2614,7 +2614,7 @@ fn genIncludeDirsAndFileNames(self: *Dwarf, arena: Allocator) !struct {
26142614
26152615 const dir_index: u28 = blk: {
26162616 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));
26182618 };
26192619
26202620 files_dir_indexes.appendAssumeCapacity(dir_index);
......@@ -2679,12 +2679,12 @@ fn createAtom(self: *Dwarf, comptime kind: Kind) !Atom.Index {
26792679 const index = blk: {
26802680 switch (kind) {
26812681 .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));
26832683 _ = try self.src_fns.addOne(self.allocator);
26842684 break :blk index;
26852685 },
26862686 .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));
26882688 _ = try self.di_atoms.addOne(self.allocator);
26892689 break :blk index;
26902690 },
src/link/Elf.zig+52-52
......@@ -455,7 +455,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
455455 const ptr_size: u8 = self.ptrWidthBytes();
456456
457457 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));
459459 const p_align: u16 = switch (self.ptr_width) {
460460 .p32 => @alignOf(elf.Elf32_Phdr),
461461 .p64 => @alignOf(elf.Elf64_Phdr),
......@@ -474,7 +474,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
474474 }
475475
476476 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));
478478 // TODO Same as for GOT
479479 const phdr_addr: u64 = if (self.base.options.target.ptrBitWidth() >= 32) 0x1000000 else 0x1000;
480480 const p_align = self.page_size;
......@@ -492,7 +492,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
492492 }
493493
494494 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));
496496 const file_size = self.base.options.program_code_size_hint;
497497 const p_align = self.page_size;
498498 const off = self.findFreeSpace(file_size, p_align);
......@@ -513,7 +513,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
513513 }
514514
515515 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));
517517 const file_size = @as(u64, ptr_size) * self.base.options.symbol_count_hint;
518518 // We really only need ptr alignment but since we are using PROGBITS, linux requires
519519 // page align.
......@@ -538,7 +538,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
538538 }
539539
540540 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));
542542 // TODO Find a hint about how much data need to be in rodata ?
543543 const file_size = 1024;
544544 // Same reason as for GOT
......@@ -561,7 +561,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
561561 }
562562
563563 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));
565565 // TODO Find a hint about how much data need to be in data ?
566566 const file_size = 1024;
567567 // Same reason as for GOT
......@@ -584,7 +584,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
584584 }
585585
586586 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));
588588 assert(self.shstrtab.buffer.items.len == 0);
589589 try self.shstrtab.buffer.append(gpa, 0); // need a 0 at position 0
590590 const off = self.findFreeSpace(self.shstrtab.buffer.items.len, 1);
......@@ -609,7 +609,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
609609 }
610610
611611 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));
613613 const phdr = &self.program_headers.items[self.phdr_load_re_index.?];
614614
615615 try self.sections.append(gpa, .{
......@@ -631,7 +631,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
631631 }
632632
633633 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));
635635 const phdr = &self.program_headers.items[self.phdr_got_index.?];
636636
637637 try self.sections.append(gpa, .{
......@@ -653,7 +653,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
653653 }
654654
655655 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));
657657 const phdr = &self.program_headers.items[self.phdr_load_ro_index.?];
658658
659659 try self.sections.append(gpa, .{
......@@ -675,7 +675,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
675675 }
676676
677677 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));
679679 const phdr = &self.program_headers.items[self.phdr_load_rw_index.?];
680680
681681 try self.sections.append(gpa, .{
......@@ -697,7 +697,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
697697 }
698698
699699 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));
701701 const min_align: u16 = if (small_ptr) @alignOf(elf.Elf32_Sym) else @alignOf(elf.Elf64_Sym);
702702 const each_size: u64 = if (small_ptr) @sizeOf(elf.Elf32_Sym) else @sizeOf(elf.Elf64_Sym);
703703 const file_size = self.base.options.symbol_count_hint * each_size;
......@@ -714,7 +714,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
714714 .sh_size = file_size,
715715 // The section header index of the associated string table.
716716 .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)),
718718 .sh_addralign = min_align,
719719 .sh_entsize = each_size,
720720 },
......@@ -726,7 +726,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
726726
727727 if (self.dwarf) |*dw| {
728728 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));
730730 assert(dw.strtab.buffer.items.len == 0);
731731 try dw.strtab.buffer.append(gpa, 0);
732732 try self.sections.append(gpa, .{
......@@ -749,7 +749,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
749749 }
750750
751751 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
754754 const file_size_hint = 200;
755755 const p_align = 1;
......@@ -778,7 +778,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
778778 }
779779
780780 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
783783 const file_size_hint = 128;
784784 const p_align = 1;
......@@ -807,7 +807,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
807807 }
808808
809809 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
812812 const file_size_hint = 160;
813813 const p_align = 16;
......@@ -836,7 +836,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
836836 }
837837
838838 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
841841 const file_size_hint = 250;
842842 const p_align = 1;
......@@ -1100,7 +1100,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
11001100 });
11011101
11021102 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),
11041104 .p64 => try self.base.file.?.pwriteAll(mem.asBytes(&target_vaddr), file_offset),
11051105 }
11061106
......@@ -1170,7 +1170,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
11701170
11711171 if (needed_size > allocated_size) {
11721172 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)));
11741174 }
11751175
11761176 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
20042004fn writeDwarfAddrAssumeCapacity(self: *Elf, buf: *std.ArrayList(u8), addr: u64) void {
20052005 const target_endian = self.base.options.target.cpu.arch.endian();
20062006 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),
20082008 .p64 => mem.writeInt(u64, buf.addManyAsArrayAssumeCapacity(8), addr, target_endian),
20092009 }
20102010}
......@@ -2064,15 +2064,15 @@ fn writeElfHeader(self: *Elf) !void {
20642064 const phdr_table_offset = self.program_headers.items[self.phdr_table_index.?].p_offset;
20652065 switch (self.ptr_width) {
20662066 .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);
20682068 index += 4;
20692069
20702070 // 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);
20722072 index += 4;
20732073
20742074 // 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);
20762076 index += 4;
20772077 },
20782078 .p64 => {
......@@ -2108,7 +2108,7 @@ fn writeElfHeader(self: *Elf) !void {
21082108 mem.writeInt(u16, hdr_buf[index..][0..2], e_phentsize, endian);
21092109 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));
21122112 mem.writeInt(u16, hdr_buf[index..][0..2], e_phnum, endian);
21132113 index += 2;
21142114
......@@ -2119,7 +2119,7 @@ fn writeElfHeader(self: *Elf) !void {
21192119 mem.writeInt(u16, hdr_buf[index..][0..2], e_shentsize, endian);
21202120 index += 2;
21212121
2122 const e_shnum = @intCast(u16, self.sections.slice().len);
2122 const e_shnum = @as(u16, @intCast(self.sections.slice().len));
21232123 mem.writeInt(u16, hdr_buf[index..][0..2], e_shnum, endian);
21242124 index += 2;
21252125
......@@ -2223,7 +2223,7 @@ fn growAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64, alignment:
22232223
22242224pub fn createAtom(self: *Elf) !Atom.Index {
22252225 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));
22272227 const atom = try self.atoms.addOne(gpa);
22282228 const local_sym_index = try self.allocateLocalSymbol();
22292229 try self.atom_by_index_table.putNoClobber(gpa, local_sym_index, atom_index);
......@@ -2367,7 +2367,7 @@ pub fn allocateLocalSymbol(self: *Elf) !u32 {
23672367 break :blk index;
23682368 } else {
23692369 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));
23712371 _ = self.local_symbols.addOneAssumeCapacity();
23722372 break :blk index;
23732373 }
......@@ -2557,7 +2557,7 @@ fn updateDeclCode(self: *Elf, decl_index: Module.Decl.Index, code: []const u8, s
25572557 .iov_len = code.len,
25582558 }};
25592559 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)))),
25612561 .iov_len = code.len,
25622562 }};
25632563 const rc = std.os.linux.process_vm_writev(pid, &code_vec, &remote_vec, 0);
......@@ -2910,7 +2910,7 @@ pub fn updateDeclExports(
29102910 continue;
29112911 },
29122912 };
2913 const stt_bits: u8 = @truncate(u4, decl_sym.st_info);
2913 const stt_bits: u8 = @as(u4, @truncate(decl_sym.st_info));
29142914 if (decl_metadata.getExport(self, exp_name)) |i| {
29152915 const sym = &self.global_symbols.items[i];
29162916 sym.* = .{
......@@ -2926,7 +2926,7 @@ pub fn updateDeclExports(
29262926 _ = self.global_symbols.addOneAssumeCapacity();
29272927 break :blk self.global_symbols.items.len - 1;
29282928 };
2929 try decl_metadata.exports.append(gpa, @intCast(u32, i));
2929 try decl_metadata.exports.append(gpa, @as(u32, @intCast(i)));
29302930 self.global_symbols.items[i] = .{
29312931 .st_name = try self.shstrtab.insert(gpa, exp_name),
29322932 .st_info = (stb_bits << 4) | stt_bits,
......@@ -3030,12 +3030,12 @@ fn writeOffsetTableEntry(self: *Elf, index: @TypeOf(self.got_table).Index) !void
30303030 switch (entry_size) {
30313031 2 => {
30323032 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);
30343034 try self.base.file.?.pwriteAll(&buf, off);
30353035 },
30363036 4 => {
30373037 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);
30393039 try self.base.file.?.pwriteAll(&buf, off);
30403040 },
30413041 8 => {
......@@ -3051,7 +3051,7 @@ fn writeOffsetTableEntry(self: *Elf, index: @TypeOf(self.got_table).Index) !void
30513051 .iov_len = buf.len,
30523052 }};
30533053 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)))),
30553055 .iov_len = buf.len,
30563056 }};
30573057 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 {
30863086 };
30873087 const needed_size = (self.local_symbols.items.len + self.global_symbols.items.len) * sym_size;
30883088 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));
30903090 }
30913091 const foreign_endian = self.base.options.target.cpu.arch.endian() != builtin.cpu.arch.endian();
30923092 const off = switch (self.ptr_width) {
......@@ -3101,8 +3101,8 @@ fn writeSymbol(self: *Elf, index: usize) !void {
31013101 var sym = [1]elf.Elf32_Sym{
31023102 .{
31033103 .st_name = local.st_name,
3104 .st_value = @intCast(u32, local.st_value),
3105 .st_size = @intCast(u32, local.st_size),
3104 .st_value = @as(u32, @intCast(local.st_value)),
3105 .st_size = @as(u32, @intCast(local.st_size)),
31063106 .st_info = local.st_info,
31073107 .st_other = local.st_other,
31083108 .st_shndx = local.st_shndx,
......@@ -3148,8 +3148,8 @@ fn writeAllGlobalSymbols(self: *Elf) !void {
31483148 const global = self.global_symbols.items[i];
31493149 sym.* = .{
31503150 .st_name = global.st_name,
3151 .st_value = @intCast(u32, global.st_value),
3152 .st_size = @intCast(u32, global.st_size),
3151 .st_value = @as(u32, @intCast(global.st_value)),
3152 .st_size = @as(u32, @intCast(global.st_size)),
31533153 .st_info = global.st_info,
31543154 .st_other = global.st_other,
31553155 .st_shndx = global.st_shndx,
......@@ -3194,19 +3194,19 @@ fn ptrWidthBytes(self: Elf) u8 {
31943194/// Does not necessarily match `ptrWidthBytes` for example can be 2 bytes
31953195/// in a 32-bit ELF file.
31963196fn 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));
31983198}
31993199
32003200fn progHeaderTo32(phdr: elf.Elf64_Phdr) elf.Elf32_Phdr {
32013201 return .{
32023202 .p_type = phdr.p_type,
32033203 .p_flags = phdr.p_flags,
3204 .p_offset = @intCast(u32, phdr.p_offset),
3205 .p_vaddr = @intCast(u32, phdr.p_vaddr),
3206 .p_paddr = @intCast(u32, phdr.p_paddr),
3207 .p_filesz = @intCast(u32, phdr.p_filesz),
3208 .p_memsz = @intCast(u32, phdr.p_memsz),
3209 .p_align = @intCast(u32, phdr.p_align),
3204 .p_offset = @as(u32, @intCast(phdr.p_offset)),
3205 .p_vaddr = @as(u32, @intCast(phdr.p_vaddr)),
3206 .p_paddr = @as(u32, @intCast(phdr.p_paddr)),
3207 .p_filesz = @as(u32, @intCast(phdr.p_filesz)),
3208 .p_memsz = @as(u32, @intCast(phdr.p_memsz)),
3209 .p_align = @as(u32, @intCast(phdr.p_align)),
32103210 };
32113211}
32123212
......@@ -3214,14 +3214,14 @@ fn sectHeaderTo32(shdr: elf.Elf64_Shdr) elf.Elf32_Shdr {
32143214 return .{
32153215 .sh_name = shdr.sh_name,
32163216 .sh_type = shdr.sh_type,
3217 .sh_flags = @intCast(u32, shdr.sh_flags),
3218 .sh_addr = @intCast(u32, shdr.sh_addr),
3219 .sh_offset = @intCast(u32, shdr.sh_offset),
3220 .sh_size = @intCast(u32, shdr.sh_size),
3217 .sh_flags = @as(u32, @intCast(shdr.sh_flags)),
3218 .sh_addr = @as(u32, @intCast(shdr.sh_addr)),
3219 .sh_offset = @as(u32, @intCast(shdr.sh_offset)),
3220 .sh_size = @as(u32, @intCast(shdr.sh_size)),
32213221 .sh_link = shdr.sh_link,
32223222 .sh_info = shdr.sh_info,
3223 .sh_addralign = @intCast(u32, shdr.sh_addralign),
3224 .sh_entsize = @intCast(u32, shdr.sh_entsize),
3223 .sh_addralign = @as(u32, @intCast(shdr.sh_addralign)),
3224 .sh_entsize = @as(u32, @intCast(shdr.sh_entsize)),
32253225 };
32263226}
32273227
src/link/MachO.zig+49-49
......@@ -741,7 +741,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
741741 };
742742 const sym = self.getSymbol(global);
743743 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)),
745745 .stacksize = self.base.options.stack_size_override orelse 0,
746746 });
747747 },
......@@ -757,7 +757,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
757757 });
758758 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));
761761 try lc_writer.writeStruct(self.uuid_cmd);
762762
763763 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
768768
769769 const ncmds = load_commands.calcNumOfLCs(lc_buffer.items);
770770 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)));
772772 try self.writeUuid(comp, uuid_cmd_offset, requires_codesig);
773773
774774 if (codesig) |*csig| {
......@@ -992,7 +992,7 @@ pub fn parseDylib(
992992 const contents = try file.readToEndAllocOptions(gpa, file_size, file_size, @alignOf(u64), null);
993993 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));
996996 var dylib = Dylib{ .weak = opts.weak };
997997
998998 dylib.parseFromBinary(
......@@ -1412,7 +1412,7 @@ pub fn allocateSpecialSymbols(self: *MachO) !void {
14121412
14131413pub fn createAtom(self: *MachO) !Atom.Index {
14141414 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));
14161416 const atom = try self.atoms.addOne(gpa);
14171417 const sym_index = try self.allocateSymbol();
14181418 try self.atom_by_index_table.putNoClobber(gpa, sym_index, atom_index);
......@@ -1588,14 +1588,14 @@ fn resolveSymbolsInDylibs(self: *MachO, actions: *std.ArrayList(ResolveAction))
15881588 for (self.dylibs.items, 0..) |dylib, id| {
15891589 if (!dylib.symbols.contains(sym_name)) continue;
15901590
1591 const dylib_id = @intCast(u16, id);
1591 const dylib_id = @as(u16, @intCast(id));
15921592 if (!self.referenced_dylibs.contains(dylib_id)) {
15931593 try self.referenced_dylibs.putNoClobber(gpa, dylib_id, {});
15941594 }
15951595
15961596 const ordinal = self.referenced_dylibs.getIndex(dylib_id) orelse unreachable;
15971597 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
16001600 if (dylib.weak) {
16011601 sym.n_desc |= macho.N_WEAK_REF;
......@@ -1789,7 +1789,7 @@ fn allocateSymbol(self: *MachO) !u32 {
17891789 break :blk index;
17901790 } else {
17911791 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));
17931793 _ = self.locals.addOneAssumeCapacity();
17941794 break :blk index;
17951795 }
......@@ -1815,7 +1815,7 @@ fn allocateGlobal(self: *MachO) !u32 {
18151815 break :blk index;
18161816 } else {
18171817 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));
18191819 _ = self.globals.addOneAssumeCapacity();
18201820 break :blk index;
18211821 }
......@@ -2563,12 +2563,12 @@ pub fn getDeclVAddr(self: *MachO, decl_index: Module.Decl.Index, reloc_info: Fil
25632563 try Atom.addRelocation(self, atom_index, .{
25642564 .type = .unsigned,
25652565 .target = .{ .sym_index = sym_index, .file = null },
2566 .offset = @intCast(u32, reloc_info.offset),
2566 .offset = @as(u32, @intCast(reloc_info.offset)),
25672567 .addend = reloc_info.addend,
25682568 .pcrel = false,
25692569 .length = 3,
25702570 });
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
25732573 return 0;
25742574}
......@@ -2582,7 +2582,7 @@ fn populateMissingMetadata(self: *MachO) !void {
25822582
25832583 if (self.pagezero_segment_cmd_index == null) {
25842584 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));
25862586 try self.segments.append(gpa, .{
25872587 .segname = makeStaticString("__PAGEZERO"),
25882588 .vmsize = pagezero_vmsize,
......@@ -2593,7 +2593,7 @@ fn populateMissingMetadata(self: *MachO) !void {
25932593
25942594 if (self.header_segment_cmd_index == null) {
25952595 // 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));
25972597 const ideal_size = @max(self.base.options.headerpad_size orelse 0, default_headerpad_size);
25982598 const needed_size = mem.alignForward(u64, padToIdeal(ideal_size), self.page_size);
25992599
......@@ -2719,7 +2719,7 @@ fn populateMissingMetadata(self: *MachO) !void {
27192719 }
27202720
27212721 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
27242724 try self.segments.append(gpa, .{
27252725 .segname = makeStaticString("__LINKEDIT"),
......@@ -2752,8 +2752,8 @@ fn allocateSection(self: *MachO, segname: []const u8, sectname: []const u8, opts
27522752 const gpa = self.base.allocator;
27532753 // In incremental context, we create one section per segment pairing. This way,
27542754 // we can move the segment in raw file as we please.
2755 const segment_id = @intCast(u8, self.segments.items.len);
2756 const section_id = @intCast(u8, self.sections.slice().len);
2755 const segment_id = @as(u8, @intCast(self.segments.items.len));
2756 const section_id = @as(u8, @intCast(self.sections.slice().len));
27572757 const vmaddr = blk: {
27582758 const prev_segment = self.segments.items[segment_id - 1];
27592759 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
27882788 .sectname = makeStaticString(sectname),
27892789 .segname = makeStaticString(segname),
27902790 .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),
27922792 .size = opts.size,
27932793 .@"align" = math.log2(opts.alignment),
27942794 .flags = opts.flags,
......@@ -2832,7 +2832,7 @@ fn growSection(self: *MachO, sect_id: u8, needed_size: u64) !void {
28322832 current_size,
28332833 );
28342834 if (amt != current_size) return error.InputOutput;
2835 header.offset = @intCast(u32, new_offset);
2835 header.offset = @as(u32, @intCast(new_offset));
28362836 segment.fileoff = new_offset;
28372837 }
28382838
......@@ -2862,7 +2862,7 @@ fn growSectionVirtualMemory(self: *MachO, sect_id: u8, needed_size: u64) !void {
28622862
28632863 // TODO: enforce order by increasing VM addresses in self.sections container.
28642864 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));
28662866 const next_segment = self.getSegmentPtr(index);
28672867 next_header.addr += diff;
28682868 next_segment.vmaddr += diff;
......@@ -2972,7 +2972,7 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm
29722972 self.segment_table_dirty = true;
29732973 }
29742974
2975 const align_pow = @intCast(u32, math.log2(alignment));
2975 const align_pow = @as(u32, @intCast(math.log2(alignment)));
29762976 if (header.@"align" < align_pow) {
29772977 header.@"align" = align_pow;
29782978 }
......@@ -3015,7 +3015,7 @@ pub fn getGlobalSymbol(self: *MachO, name: []const u8, lib_name: ?[]const u8) !u
30153015
30163016fn writeSegmentHeaders(self: *MachO, writer: anytype) !void {
30173017 for (self.segments.items, 0..) |seg, i| {
3018 const indexes = self.getSectionIndexes(@intCast(u8, i));
3018 const indexes = self.getSectionIndexes(@as(u8, @intCast(i)));
30193019 try writer.writeStruct(seg);
30203020 for (self.sections.items(.header)[indexes.start..indexes.end]) |header| {
30213021 try writer.writeStruct(header);
......@@ -3029,7 +3029,7 @@ fn writeLinkeditSegmentData(self: *MachO) !void {
30293029 seg.vmsize = 0;
30303030
30313031 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;
30333033 if (seg.vmaddr < segment.vmaddr + segment.vmsize) {
30343034 seg.vmaddr = mem.alignForward(u64, segment.vmaddr + segment.vmsize, self.page_size);
30353035 }
......@@ -3115,7 +3115,7 @@ fn collectBindDataFromTableSection(self: *MachO, sect_id: u8, bind: anytype, tab
31153115 log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{
31163116 base_offset + offset,
31173117 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),
31193119 });
31203120 if (bind_sym.weakRef()) {
31213121 log.debug(" | marking as weak ref ", .{});
......@@ -3150,7 +3150,7 @@ fn collectBindData(self: *MachO, bind: anytype, raw_bindings: anytype) !void {
31503150 const bind_sym = self.getSymbol(binding.target);
31513151 const bind_sym_name = self.getSymbolName(binding.target);
31523152 const dylib_ordinal = @divTrunc(
3153 @bitCast(i16, bind_sym.n_desc),
3153 @as(i16, @bitCast(bind_sym.n_desc)),
31543154 macho.N_SYMBOL_RESOLVER,
31553155 );
31563156 log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{
......@@ -3285,14 +3285,14 @@ fn writeDyldInfoData(self: *MachO) !void {
32853285 try self.base.file.?.pwriteAll(buffer, rebase_off);
32863286 try self.populateLazyBindOffsetsInStubHelper(lazy_bind);
32873287
3288 self.dyld_info_cmd.rebase_off = @intCast(u32, rebase_off);
3289 self.dyld_info_cmd.rebase_size = @intCast(u32, rebase_size_aligned);
3290 self.dyld_info_cmd.bind_off = @intCast(u32, bind_off);
3291 self.dyld_info_cmd.bind_size = @intCast(u32, bind_size_aligned);
3292 self.dyld_info_cmd.lazy_bind_off = @intCast(u32, lazy_bind_off);
3293 self.dyld_info_cmd.lazy_bind_size = @intCast(u32, lazy_bind_size_aligned);
3294 self.dyld_info_cmd.export_off = @intCast(u32, export_off);
3295 self.dyld_info_cmd.export_size = @intCast(u32, export_size_aligned);
3288 self.dyld_info_cmd.rebase_off = @as(u32, @intCast(rebase_off));
3289 self.dyld_info_cmd.rebase_size = @as(u32, @intCast(rebase_size_aligned));
3290 self.dyld_info_cmd.bind_off = @as(u32, @intCast(bind_off));
3291 self.dyld_info_cmd.bind_size = @as(u32, @intCast(bind_size_aligned));
3292 self.dyld_info_cmd.lazy_bind_off = @as(u32, @intCast(lazy_bind_off));
3293 self.dyld_info_cmd.lazy_bind_size = @as(u32, @intCast(lazy_bind_size_aligned));
3294 self.dyld_info_cmd.export_off = @as(u32, @intCast(export_off));
3295 self.dyld_info_cmd.export_size = @as(u32, @intCast(export_size_aligned));
32963296}
32973297
32983298fn populateLazyBindOffsetsInStubHelper(self: *MachO, lazy_bind: LazyBind) !void {
......@@ -3337,7 +3337,7 @@ fn writeSymtab(self: *MachO) !SymtabCtx {
33373337
33383338 for (self.locals.items, 0..) |sym, sym_id| {
33393339 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 };
33413341 if (self.symbolIsTemp(sym_loc)) continue; // local temp symbol, skip
33423342 if (self.getGlobal(self.getSymbolName(sym_loc)) != null) continue; // global symbol is either an export or import, skip
33433343 try locals.append(sym);
......@@ -3363,16 +3363,16 @@ fn writeSymtab(self: *MachO) !SymtabCtx {
33633363 const sym = self.getSymbol(global);
33643364 if (sym.n_strx == 0) continue; // no name, skip
33653365 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));
33673367 var out_sym = sym;
33683368 out_sym.n_strx = try self.strtab.insert(gpa, self.getSymbolName(global));
33693369 try imports.append(out_sym);
33703370 try imports_table.putNoClobber(global, new_index);
33713371 }
33723372
3373 const nlocals = @intCast(u32, locals.items.len);
3374 const nexports = @intCast(u32, exports.items.len);
3375 const nimports = @intCast(u32, imports.items.len);
3373 const nlocals = @as(u32, @intCast(locals.items.len));
3374 const nexports = @as(u32, @intCast(exports.items.len));
3375 const nimports = @as(u32, @intCast(imports.items.len));
33763376 const nsyms = nlocals + nexports + nimports;
33773377
33783378 const seg = self.getLinkeditSegmentPtr();
......@@ -3392,7 +3392,7 @@ fn writeSymtab(self: *MachO) !SymtabCtx {
33923392 log.debug("writing symtab from 0x{x} to 0x{x}", .{ offset, offset + needed_size });
33933393 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));
33963396 self.symtab_cmd.nsyms = nsyms;
33973397
33983398 return SymtabCtx{
......@@ -3421,8 +3421,8 @@ fn writeStrtab(self: *MachO) !void {
34213421
34223422 try self.base.file.?.pwriteAll(buffer, offset);
34233423
3424 self.symtab_cmd.stroff = @intCast(u32, offset);
3425 self.symtab_cmd.strsize = @intCast(u32, needed_size_aligned);
3424 self.symtab_cmd.stroff = @as(u32, @intCast(offset));
3425 self.symtab_cmd.strsize = @as(u32, @intCast(needed_size_aligned));
34263426}
34273427
34283428const SymtabCtx = struct {
......@@ -3434,8 +3434,8 @@ const SymtabCtx = struct {
34343434
34353435fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void {
34363436 const gpa = self.base.allocator;
3437 const nstubs = @intCast(u32, self.stub_table.lookup.count());
3438 const ngot_entries = @intCast(u32, self.got_table.lookup.count());
3437 const nstubs = @as(u32, @intCast(self.stub_table.lookup.count()));
3438 const ngot_entries = @as(u32, @intCast(self.got_table.lookup.count()));
34393439 const nindirectsyms = nstubs * 2 + ngot_entries;
34403440 const iextdefsym = ctx.nlocalsym;
34413441 const iundefsym = iextdefsym + ctx.nextdefsym;
......@@ -3503,7 +3503,7 @@ fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void {
35033503 self.dysymtab_cmd.nextdefsym = ctx.nextdefsym;
35043504 self.dysymtab_cmd.iundefsym = iundefsym;
35053505 self.dysymtab_cmd.nundefsym = ctx.nundefsym;
3506 self.dysymtab_cmd.indirectsymoff = @intCast(u32, offset);
3506 self.dysymtab_cmd.indirectsymoff = @as(u32, @intCast(offset));
35073507 self.dysymtab_cmd.nindirectsyms = nindirectsyms;
35083508}
35093509
......@@ -3530,8 +3530,8 @@ fn writeCodeSignaturePadding(self: *MachO, code_sig: *CodeSignature) !void {
35303530 // except for code signature data.
35313531 try self.base.file.?.pwriteAll(&[_]u8{0}, offset + needed_size - 1);
35323532
3533 self.codesig_cmd.dataoff = @intCast(u32, offset);
3534 self.codesig_cmd.datasize = @intCast(u32, needed_size);
3533 self.codesig_cmd.dataoff = @as(u32, @intCast(offset));
3534 self.codesig_cmd.datasize = @as(u32, @intCast(needed_size));
35353535}
35363536
35373537fn writeCodeSignature(self: *MachO, comp: *const Compilation, code_sig: *CodeSignature) !void {
......@@ -3711,7 +3711,7 @@ pub fn makeStaticString(bytes: []const u8) [16]u8 {
37113711
37123712fn getSegmentByName(self: MachO, segname: []const u8) ?u8 {
37133713 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));
37153715 } else return null;
37163716}
37173717
......@@ -3734,15 +3734,15 @@ pub fn getSectionByName(self: MachO, segname: []const u8, sectname: []const u8)
37343734 // TODO investigate caching with a hashmap
37353735 for (self.sections.items(.header), 0..) |header, i| {
37363736 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));
37383738 } else return null;
37393739}
37403740
37413741pub fn getSectionIndexes(self: MachO, segment_index: u8) struct { start: u8, end: u8 } {
37423742 var start: u8 = 0;
37433743 const nsects = for (self.segments.items, 0..) |seg, i| {
3744 if (i == segment_index) break @intCast(u8, seg.nsects);
3745 start += @intCast(u8, seg.nsects);
3744 if (i == segment_index) break @as(u8, @intCast(seg.nsects));
3745 start += @as(u8, @intCast(seg.nsects));
37463746 } else 0;
37473747 return .{ .start = start, .end = start + nsects };
37483748}
src/link/MachO/Archive.zig+1-1
......@@ -169,7 +169,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !
169169 };
170170 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);
173173 const owned_name = try allocator.dupe(u8, sym_name);
174174 const res = try self.toc.getOrPut(allocator, owned_name);
175175 defer if (res.found_existing) allocator.free(owned_name);
src/link/MachO/CodeSignature.zig+9-9
......@@ -72,7 +72,7 @@ const CodeDirectory = struct {
7272 .hashSize = hash_size,
7373 .hashType = macho.CS_HASHTYPE_SHA256,
7474 .platform = 0,
75 .pageSize = @truncate(u8, std.math.log2(page_size)),
75 .pageSize = @as(u8, @truncate(std.math.log2(page_size))),
7676 .spare2 = 0,
7777 .scatterOffset = 0,
7878 .teamOffset = 0,
......@@ -110,7 +110,7 @@ const CodeDirectory = struct {
110110 fn size(self: CodeDirectory) u32 {
111111 const code_slots = self.inner.nCodeSlots * hash_size;
112112 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));
114114 }
115115
116116 fn write(self: CodeDirectory, writer: anytype) !void {
......@@ -139,9 +139,9 @@ const CodeDirectory = struct {
139139 try writer.writeAll(self.ident);
140140 try writer.writeByte(0);
141141
142 var i: isize = @intCast(isize, self.inner.nSpecialSlots);
142 var i: isize = @as(isize, @intCast(self.inner.nSpecialSlots));
143143 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))]);
145145 }
146146
147147 for (self.code_slots.items) |slot| {
......@@ -186,7 +186,7 @@ const Entitlements = struct {
186186 }
187187
188188 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);
190190 }
191191
192192 fn write(self: Entitlements, writer: anytype) !void {
......@@ -281,7 +281,7 @@ pub fn writeAdhocSignature(
281281 self.code_directory.inner.execSegFlags = if (opts.output_mode == .Exe) macho.CS_EXECSEG_MAIN_BINARY else 0;
282282 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
286286 try self.code_directory.code_slots.ensureTotalCapacityPrecise(gpa, total_pages);
287287 self.code_directory.code_slots.items.len = total_pages;
......@@ -331,7 +331,7 @@ pub fn writeAdhocSignature(
331331 }
332332
333333 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));
335335 self.code_directory.inner.length = self.code_directory.size();
336336 header.length += self.code_directory.size();
337337
......@@ -339,7 +339,7 @@ pub fn writeAdhocSignature(
339339 try writer.writeIntBig(u32, header.length);
340340 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));
343343 for (blobs.items) |blob| {
344344 try writer.writeIntBig(u32, blob.slotType());
345345 try writer.writeIntBig(u32, offset);
......@@ -383,7 +383,7 @@ pub fn estimateSize(self: CodeSignature, file_size: u64) u32 {
383383 ssize += @sizeOf(macho.BlobIndex) + sig.size();
384384 }
385385 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))));
387387}
388388
389389pub fn clear(self: *CodeSignature, allocator: Allocator) void {
src/link/MachO/DebugSymbols.zig+21-21
......@@ -64,9 +64,9 @@ pub const Reloc = struct {
6464/// has been called to get a viable debug symbols output.
6565pub fn populateMissingMetadata(self: *DebugSymbols) !void {
6666 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));
7070 const ideal_size: u16 = 200 + 128 + 160 + 250;
7171 const needed_size = mem.alignForward(u64, padToIdeal(ideal_size), self.page_size);
7272
......@@ -86,7 +86,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols) !void {
8686 try self.dwarf.strtab.buffer.append(self.allocator, 0);
8787 self.debug_str_section_index = try self.allocateSection(
8888 "__debug_str",
89 @intCast(u32, self.dwarf.strtab.buffer.items.len),
89 @as(u32, @intCast(self.dwarf.strtab.buffer.items.len)),
9090 0,
9191 );
9292 self.debug_string_table_dirty = true;
......@@ -113,7 +113,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols) !void {
113113 }
114114
115115 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));
117117 try self.segments.append(self.allocator, .{
118118 .segname = makeStaticString("__LINKEDIT"),
119119 .maxprot = macho.PROT.READ,
......@@ -128,7 +128,7 @@ fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignme
128128 var sect = macho.section_64{
129129 .sectname = makeStaticString(sectname),
130130 .segname = segment.segname,
131 .size = @intCast(u32, size),
131 .size = @as(u32, @intCast(size)),
132132 .@"align" = alignment,
133133 };
134134 const alignment_pow_2 = try math.powi(u32, 2, alignment);
......@@ -141,9 +141,9 @@ fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignme
141141 off + size,
142142 });
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));
147147 try self.sections.append(self.allocator, sect);
148148 segment.cmdsize += @sizeOf(macho.section_64);
149149 segment.nsects += 1;
......@@ -176,7 +176,7 @@ pub fn growSection(self: *DebugSymbols, sect_index: u8, needed_size: u32, requir
176176 if (amt != existing_size) return error.InputOutput;
177177 }
178178
179 sect.offset = @intCast(u32, new_offset);
179 sect.offset = @as(u32, @intCast(new_offset));
180180 }
181181
182182 sect.size = needed_size;
......@@ -286,7 +286,7 @@ pub fn flushModule(self: *DebugSymbols, macho_file: *MachO) !void {
286286 {
287287 const sect_index = self.debug_str_section_index.?;
288288 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));
290290 try self.growSection(sect_index, needed_size, false);
291291 try self.file.pwriteAll(self.dwarf.strtab.buffer.items, self.getSection(sect_index).offset);
292292 self.debug_string_table_dirty = false;
......@@ -307,7 +307,7 @@ pub fn flushModule(self: *DebugSymbols, macho_file: *MachO) !void {
307307
308308 const ncmds = load_commands.calcNumOfLCs(lc_buffer.items);
309309 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
312312 assert(!self.debug_abbrev_section_dirty);
313313 assert(!self.debug_aranges_section_dirty);
......@@ -378,7 +378,7 @@ fn writeSegmentHeaders(self: *DebugSymbols, macho_file: *MachO, writer: anytype)
378378 // Write segment/section headers from the binary file first.
379379 const end = macho_file.linkedit_segment_cmd_index.?;
380380 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)));
382382 var out_seg = seg;
383383 out_seg.fileoff = 0;
384384 out_seg.filesize = 0;
......@@ -407,7 +407,7 @@ fn writeSegmentHeaders(self: *DebugSymbols, macho_file: *MachO, writer: anytype)
407407 }
408408 // Next, commit DSYM's __LINKEDIT and __DWARF segments headers.
409409 for (self.segments.items, 0..) |seg, i| {
410 const indexes = self.getSectionIndexes(@intCast(u8, i));
410 const indexes = self.getSectionIndexes(@as(u8, @intCast(i)));
411411 try writer.writeStruct(seg);
412412 for (self.sections.items[indexes.start..indexes.end]) |header| {
413413 try writer.writeStruct(header);
......@@ -473,7 +473,7 @@ fn writeSymtab(self: *DebugSymbols, macho_file: *MachO) !void {
473473
474474 for (macho_file.locals.items, 0..) |sym, sym_id| {
475475 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 };
477477 if (macho_file.symbolIsTemp(sym_loc)) continue; // local temp symbol, skip
478478 if (macho_file.getGlobal(macho_file.getSymbolName(sym_loc)) != null) continue; // global symbol is either an export or import, skip
479479 var out_sym = sym;
......@@ -501,10 +501,10 @@ fn writeSymtab(self: *DebugSymbols, macho_file: *MachO) !void {
501501 const needed_size = nsyms * @sizeOf(macho.nlist_64);
502502 seg.filesize = offset + needed_size - seg.fileoff;
503503
504 self.symtab_cmd.symoff = @intCast(u32, offset);
505 self.symtab_cmd.nsyms = @intCast(u32, nsyms);
504 self.symtab_cmd.symoff = @as(u32, @intCast(offset));
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));
508508 const locals_size = nlocals * @sizeOf(macho.nlist_64);
509509 const exports_off = locals_off + locals_size;
510510 const exports_size = nexports * @sizeOf(macho.nlist_64);
......@@ -521,13 +521,13 @@ fn writeStrtab(self: *DebugSymbols) !void {
521521 defer tracy.end();
522522
523523 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)));
525525 const offset = mem.alignForward(u64, self.symtab_cmd.symoff + symtab_size, @alignOf(u64));
526526 const needed_size = mem.alignForward(u64, self.strtab.buffer.items.len, @alignOf(u64));
527527
528528 seg.filesize = offset + needed_size - seg.fileoff;
529 self.symtab_cmd.stroff = @intCast(u32, offset);
530 self.symtab_cmd.strsize = @intCast(u32, needed_size);
529 self.symtab_cmd.stroff = @as(u32, @intCast(offset));
530 self.symtab_cmd.strsize = @as(u32, @intCast(needed_size));
531531
532532 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 {
542542pub fn getSectionIndexes(self: *DebugSymbols, segment_index: u8) struct { start: u8, end: u8 } {
543543 var start: u8 = 0;
544544 const nsects = for (self.segments.items, 0..) |seg, i| {
545 if (i == segment_index) break @intCast(u8, seg.nsects);
546 start += @intCast(u8, seg.nsects);
545 if (i == segment_index) break @as(u8, @intCast(seg.nsects));
546 start += @as(u8, @intCast(seg.nsects));
547547 } else 0;
548548 return .{ .start = start, .end = start + nsects };
549549}
src/link/MachO/DwarfInfo.zig+4-4
......@@ -70,7 +70,7 @@ pub fn genSubprogramLookupByName(
7070 low_pc = addr;
7171 }
7272 if (try attr.getConstant(self)) |constant| {
73 low_pc = @intCast(u64, constant);
73 low_pc = @as(u64, @intCast(constant));
7474 }
7575 },
7676 dwarf.AT.high_pc => {
......@@ -78,7 +78,7 @@ pub fn genSubprogramLookupByName(
7878 high_pc = addr;
7979 }
8080 if (try attr.getConstant(self)) |constant| {
81 high_pc = @intCast(u64, constant);
81 high_pc = @as(u64, @intCast(constant));
8282 }
8383 },
8484 else => {},
......@@ -261,7 +261,7 @@ pub const Attribute = struct {
261261
262262 switch (self.form) {
263263 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);
265265 },
266266 dwarf.FORM.strp => {
267267 const off = if (cuh.is_64bit)
......@@ -499,5 +499,5 @@ fn findAbbrevEntrySize(self: DwarfInfo, da_off: usize, da_len: usize, di_off: us
499499
500500fn getString(self: DwarfInfo, off: u64) []const u8 {
501501 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);
503503}
src/link/MachO/Dylib.zig+6-6
......@@ -75,7 +75,7 @@ pub const Id = struct {
7575 .int => |int| {
7676 var out: u32 = 0;
7777 const major = math.cast(u16, int) orelse return error.Overflow;
78 out += @intCast(u32, major) << 16;
78 out += @as(u32, @intCast(major)) << 16;
7979 return out;
8080 },
8181 .float => |float| {
......@@ -106,9 +106,9 @@ pub const Id = struct {
106106 out += try fmt.parseInt(u8, values[2], 10);
107107 }
108108 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;
110110 }
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
113113 return out;
114114 }
......@@ -164,11 +164,11 @@ pub fn parseFromBinary(
164164 switch (cmd.cmd()) {
165165 .SYMTAB => {
166166 const symtab_cmd = cmd.cast(macho.symtab_command).?;
167 const symtab = @ptrCast(
167 const symtab = @as(
168168 [*]const macho.nlist_64,
169169 // Alignment is guaranteed as a dylib is a final linked image and has to have sections
170170 // 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])),
172172 )[0..symtab_cmd.nsyms];
173173 const strtab = data[symtab_cmd.stroff..][0..symtab_cmd.strsize];
174174
......@@ -176,7 +176,7 @@ pub fn parseFromBinary(
176176 const add_to_symtab = sym.ext() and (sym.sect() or sym.indr());
177177 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);
180180 try self.symbols.putNoClobber(allocator, try allocator.dupe(u8, sym_name), false);
181181 }
182182 },
src/link/MachO/Object.zig+32-32
......@@ -164,7 +164,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
164164 else => {},
165165 } 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];
168168 self.in_strtab = self.contents[symtab.stroff..][0..symtab.strsize];
169169
170170 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)
202202 defer sorted_all_syms.deinit();
203203
204204 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)) });
206206 }
207207
208208 // We sort by type: defined < undefined, and
......@@ -225,18 +225,18 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
225225 }
226226 }
227227 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 };
229229 }
230230
231231 prev_sect_id = sym.n_sect;
232232
233233 self.symtab[i] = sym;
234234 self.source_symtab_lookup[i] = sym_id.index;
235 self.reverse_symtab_lookup[sym_id.index] = @intCast(u32, i);
236 self.source_address_lookup[i] = if (sym.undf()) -1 else @intCast(i64, sym.n_value);
235 self.reverse_symtab_lookup[sym_id.index] = @as(u32, @intCast(i));
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;
239 self.strtab_lookup[i] = @intCast(u32, sym_name_len);
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] = @as(u32, @intCast(sym_name_len));
240240 }
241241
242242 // If there were no undefined symbols, make sure we populate the
......@@ -267,7 +267,7 @@ const SymbolAtIndex = struct {
267267
268268 fn getSymbolName(self: SymbolAtIndex, ctx: Context) []const u8 {
269269 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);
271271 }
272272
273273 fn getSymbolSeniority(self: SymbolAtIndex, ctx: Context) u2 {
......@@ -338,7 +338,7 @@ fn filterSymbolsBySection(symbols: []macho.nlist_64, n_sect: u8) struct {
338338 .n_sect = n_sect,
339339 });
340340
341 return .{ .index = @intCast(u32, index), .len = @intCast(u32, len) };
341 return .{ .index = @as(u32, @intCast(index)), .len = @as(u32, @intCast(len)) };
342342}
343343
344344fn 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:
360360 .addr = end_addr,
361361 });
362362
363 return .{ .index = @intCast(u32, index), .len = @intCast(u32, len) };
363 return .{ .index = @as(u32, @intCast(index)), .len = @as(u32, @intCast(len)) };
364364}
365365
366366const SortedSection = struct {
......@@ -400,7 +400,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void {
400400 };
401401 if (sect.size == 0) continue;
402402
403 const sect_id = @intCast(u8, id);
403 const sect_id = @as(u8, @intCast(id));
404404 const sym = self.getSectionAliasSymbolPtr(sect_id);
405405 sym.* = .{
406406 .n_strx = 0,
......@@ -417,7 +417,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void {
417417 const out_sect_id = (try zld.getOutputSection(sect)) orelse continue;
418418 if (sect.size == 0) continue;
419419
420 const sect_id = @intCast(u8, id);
420 const sect_id = @as(u8, @intCast(id));
421421 const sym_index = self.getSectionAliasSymbolIndex(sect_id);
422422 const atom_index = try self.createAtomFromSubsection(
423423 zld,
......@@ -459,7 +459,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void {
459459 defer gpa.free(sorted_sections);
460460
461461 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)) };
463463 }
464464
465465 mem.sort(SortedSection, sorted_sections, {}, sectionLessThanByAddress);
......@@ -651,7 +651,7 @@ fn filterRelocs(
651651 const start = @import("zld.zig").bsearch(macho.relocation_info, relocs, Predicate{ .addr = end_addr });
652652 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)) };
655655}
656656
657657/// Parse all relocs for the input section, and sort in descending order.
......@@ -659,7 +659,7 @@ fn filterRelocs(
659659/// section in a sorted manner which is simply not true.
660660fn parseRelocs(self: *Object, gpa: Allocator, sect_id: u8) !void {
661661 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));
663663 if (self.getSourceRelocs(section)) |relocs| {
664664 try self.relocations.ensureUnusedCapacity(gpa, relocs.len);
665665 self.relocations.appendUnalignedSliceAssumeCapacity(relocs);
......@@ -677,8 +677,8 @@ fn cacheRelocs(self: *Object, zld: *Zld, atom_index: AtomIndex) !void {
677677 // If there was no matching symbol present in the source symtab, this means
678678 // we are dealing with either an entire section, or part of it, but also
679679 // starting at the beginning.
680 const nbase = @intCast(u32, self.in_symtab.?.len);
681 const sect_id = @intCast(u8, atom.sym_index - nbase);
680 const nbase = @as(u32, @intCast(self.in_symtab.?.len));
681 const sect_id = @as(u8, @intCast(atom.sym_index - nbase));
682682 break :blk sect_id;
683683 };
684684 const source_sect = self.getSourceSection(source_sect_id);
......@@ -745,7 +745,7 @@ fn parseEhFrameSection(self: *Object, zld: *Zld, object_id: u32) !void {
745745 .object_id = object_id,
746746 .rel = rel,
747747 .code = it.data[offset..],
748 .base_offset = @intCast(i32, offset),
748 .base_offset = @as(i32, @intCast(offset)),
749749 });
750750 break :blk target;
751751 },
......@@ -798,7 +798,7 @@ fn parseUnwindInfo(self: *Object, zld: *Zld, object_id: u32) !void {
798798 _ = try zld.initSection("__TEXT", "__unwind_info", .{});
799799 }
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
803803 const unwind_records = self.getUnwindRecords();
804804
......@@ -834,14 +834,14 @@ fn parseUnwindInfo(self: *Object, zld: *Zld, object_id: u32) !void {
834834 .object_id = object_id,
835835 .rel = rel,
836836 .code = mem.asBytes(&record),
837 .base_offset = @intCast(i32, offset),
837 .base_offset = @as(i32, @intCast(offset)),
838838 });
839839 log.debug("unwind record {d} tracks {s}", .{ record_id, zld.getSymbolName(target) });
840840 if (target.getFile() != object_id) {
841841 self.unwind_relocs_lookup[record_id].dead = true;
842842 } else {
843843 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)));
845845 }
846846 }
847847}
......@@ -869,7 +869,7 @@ pub fn getSourceSectionIndexByName(self: Object, segname: []const u8, sectname:
869869 const sections = self.getSourceSections();
870870 for (sections, 0..) |sect, i| {
871871 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));
873873 } else return null;
874874}
875875
......@@ -898,7 +898,7 @@ pub fn parseDataInCode(self: *Object, gpa: Allocator) !void {
898898 }
899899 } else return;
900900 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];
902902 try self.data_in_code.ensureTotalCapacityPrecise(gpa, dice.len);
903903 self.data_in_code.appendUnalignedSliceAssumeCapacity(dice);
904904 mem.sort(macho.data_in_code_entry, self.data_in_code.items, {}, diceLessThan);
......@@ -945,12 +945,12 @@ pub fn parseDwarfInfo(self: Object) DwarfInfo {
945945}
946946
947947pub 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));
949949 return self.contents[sect.offset..][0..size];
950950}
951951
952952pub 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));
954954 return start + sect_id;
955955}
956956
......@@ -964,7 +964,7 @@ pub fn getSectionAliasSymbolPtr(self: *Object, sect_id: u8) *macho.nlist_64 {
964964
965965fn getSourceRelocs(self: Object, sect: macho.section_64) ?[]align(1) const macho.relocation_info {
966966 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];
968968}
969969
970970pub 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 {
10051005 const target_sym_index = @import("zld.zig").lsearch(
10061006 i64,
10071007 self.source_address_lookup[lookup.start..][0..lookup.len],
1008 Predicate{ .addr = @intCast(i64, addr) },
1008 Predicate{ .addr = @as(i64, @intCast(addr)) },
10091009 );
10101010 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));
10121012 }
10131013 }
10141014 return self.getSectionAliasSymbolIndex(sect_id);
10151015 }
10161016
10171017 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)),
10191019 });
10201020 assert(target_sym_index > 0);
1021 return @intCast(u32, target_sym_index - 1);
1021 return @as(u32, @intCast(target_sym_index - 1));
10221022}
10231023
10241024pub fn getGlobal(self: Object, sym_index: u32) ?u32 {
10251025 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]));
10271027}
10281028
10291029pub fn getAtomIndexForSymbol(self: Object, sym_index: u32) ?AtomIndex {
......@@ -1041,7 +1041,7 @@ pub fn getUnwindRecords(self: Object) []align(1) const macho.compact_unwind_entr
10411041 const sect = self.getSourceSection(sect_id);
10421042 const data = self.getSectionContents(sect);
10431043 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];
10451045}
10461046
10471047pub 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
9494 .tlv_initializer => blk: {
9595 assert(self.addend == 0); // Addend here makes no sense.
9696 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));
9898 },
99 else => @intCast(i64, target_base_addr) + self.addend,
99 else => @as(i64, @intCast(target_base_addr)) + self.addend,
100100 };
101101
102102 log.debug(" ({x}: [() => 0x{x} ({s})) ({s})", .{
......@@ -119,7 +119,7 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: []
119119 .branch => {
120120 const displacement = math.cast(
121121 i28,
122 @intCast(i64, target_addr) - @intCast(i64, source_addr),
122 @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr)),
123123 ) orelse unreachable; // TODO codegen should never allow for jump larger than i28 displacement
124124 var inst = aarch64.Instruction{
125125 .unconditional_branch_immediate = mem.bytesToValue(meta.TagPayload(
......@@ -127,25 +127,25 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: []
127127 aarch64.Instruction.unconditional_branch_immediate,
128128 ), buffer[0..4]),
129129 };
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))));
131131 mem.writeIntLittle(u32, buffer[0..4], inst.toU32());
132132 },
133133 .page, .got_page => {
134 const source_page = @intCast(i32, source_addr >> 12);
135 const target_page = @intCast(i32, target_addr >> 12);
136 const pages = @bitCast(u21, @intCast(i21, target_page - source_page));
134 const source_page = @as(i32, @intCast(source_addr >> 12));
135 const target_page = @as(i32, @intCast(target_addr >> 12));
136 const pages = @as(u21, @bitCast(@as(i21, @intCast(target_page - source_page))));
137137 var inst = aarch64.Instruction{
138138 .pc_relative_address = mem.bytesToValue(meta.TagPayload(
139139 aarch64.Instruction,
140140 aarch64.Instruction.pc_relative_address,
141141 ), buffer[0..4]),
142142 };
143 inst.pc_relative_address.immhi = @truncate(u19, pages >> 2);
144 inst.pc_relative_address.immlo = @truncate(u2, pages);
143 inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2));
144 inst.pc_relative_address.immlo = @as(u2, @truncate(pages));
145145 mem.writeIntLittle(u32, buffer[0..4], inst.toU32());
146146 },
147147 .pageoff, .got_pageoff => {
148 const narrowed = @truncate(u12, @intCast(u64, target_addr));
148 const narrowed = @as(u12, @truncate(@as(u64, @intCast(target_addr))));
149149 if (isArithmeticOp(buffer[0..4])) {
150150 var inst = aarch64.Instruction{
151151 .add_subtract_immediate = mem.bytesToValue(meta.TagPayload(
......@@ -180,8 +180,8 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: []
180180 }
181181 },
182182 .tlv_initializer, .unsigned => switch (self.length) {
183 2 => mem.writeIntLittle(u32, buffer[0..4], @truncate(u32, @bitCast(u64, target_addr))),
184 3 => mem.writeIntLittle(u64, buffer[0..8], @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], @as(u64, @bitCast(target_addr))),
185185 else => unreachable,
186186 },
187187 .got, .signed, .tlv => unreachable, // Invalid target architecture.
......@@ -191,16 +191,16 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: []
191191fn resolveX8664(self: Relocation, source_addr: u64, target_addr: i64, code: []u8) void {
192192 switch (self.type) {
193193 .branch, .got, .tlv, .signed => {
194 const displacement = @intCast(i32, @intCast(i64, target_addr) - @intCast(i64, source_addr) - 4);
195 mem.writeIntLittle(u32, code[self.offset..][0..4], @bitCast(u32, displacement));
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], @as(u32, @bitCast(displacement)));
196196 },
197197 .tlv_initializer, .unsigned => {
198198 switch (self.length) {
199199 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)))));
201201 },
202202 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)));
204204 },
205205 else => unreachable,
206206 }
......@@ -210,24 +210,24 @@ fn resolveX8664(self: Relocation, source_addr: u64, target_addr: i64, code: []u8
210210}
211211
212212pub 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]));
214214 return ((group_decode >> 2) == 4);
215215}
216216
217217pub 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));
219219 return math.cast(i32, disp) orelse error.Overflow;
220220}
221221
222222pub 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));
224224 return math.cast(i28, disp) orelse error.Overflow;
225225}
226226
227227pub fn calcNumberOfPages(source_addr: u64, target_addr: u64) i21 {
228 const source_page = @intCast(i32, source_addr >> 12);
229 const target_page = @intCast(i32, target_addr >> 12);
230 const pages = @intCast(i21, target_page - source_page);
228 const source_page = @as(i32, @intCast(source_addr >> 12));
229 const target_page = @as(i32, @intCast(target_addr >> 12));
230 const pages = @as(i21, @intCast(target_page - source_page));
231231 return pages;
232232}
233233
......@@ -241,7 +241,7 @@ pub const PageOffsetInstKind = enum {
241241};
242242
243243pub fn calcPageOffset(target_addr: u64, kind: PageOffsetInstKind) !u12 {
244 const narrowed = @truncate(u12, target_addr);
244 const narrowed = @as(u12, @truncate(target_addr));
245245 return switch (kind) {
246246 .arithmetic, .load_store_8 => narrowed,
247247 .load_store_16 => try math.divExact(u12, narrowed, 2),
src/link/MachO/Trie.zig+1-1
......@@ -220,7 +220,7 @@ pub const Node = struct {
220220 try writer.writeByte(0);
221221 }
222222 // 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
225225 for (self.edges.items) |edge| {
226226 // Write edge label and offset to next node in trie.
src/link/MachO/UnwindInfo.zig+54-54
......@@ -87,7 +87,7 @@ const Page = struct {
8787 const record_id = page.page_encodings[index];
8888 const record = info.records.items[record_id];
8989 if (record.compactUnwindEncoding == enc) {
90 return @intCast(u8, index);
90 return @as(u8, @intCast(index));
9191 }
9292 }
9393 return null;
......@@ -150,14 +150,14 @@ const Page = struct {
150150
151151 for (info.records.items[page.start..][0..page.count]) |record| {
152152 try writer.writeStruct(macho.unwind_info_regular_second_level_entry{
153 .functionOffset = @intCast(u32, record.rangeStart),
153 .functionOffset = @as(u32, @intCast(record.rangeStart)),
154154 .encoding = record.compactUnwindEncoding,
155155 });
156156 }
157157 },
158158 .compressed => {
159159 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);
161161 try writer.writeStruct(macho.unwind_info_compressed_second_level_page_header{
162162 .entryPageOffset = entry_offset,
163163 .entryCount = page.count,
......@@ -183,8 +183,8 @@ const Page = struct {
183183 break :blk ncommon + page.getPageEncoding(info, record.compactUnwindEncoding).?;
184184 };
185185 const compressed = macho.UnwindInfoCompressedEntry{
186 .funcOffset = @intCast(u24, record.rangeStart - first_entry.rangeStart),
187 .encodingIndex = @intCast(u8, enc_index),
186 .funcOffset = @as(u24, @intCast(record.rangeStart - first_entry.rangeStart)),
187 .encodingIndex = @as(u8, @intCast(enc_index)),
188188 };
189189 try writer.writeStruct(compressed);
190190 }
......@@ -214,15 +214,15 @@ pub fn scanRelocs(zld: *Zld) !void {
214214 if (!UnwindEncoding.isDwarf(record.compactUnwindEncoding, cpu_arch)) {
215215 if (getPersonalityFunctionReloc(
216216 zld,
217 @intCast(u32, object_id),
217 @as(u32, @intCast(object_id)),
218218 record_id,
219219 )) |rel| {
220220 // Personality function; add GOT pointer.
221221 const target = Atom.parseRelocTarget(zld, .{
222 .object_id = @intCast(u32, object_id),
222 .object_id = @as(u32, @intCast(object_id)),
223223 .rel = rel,
224224 .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))),
226226 });
227227 try Atom.addGotEntry(zld, target);
228228 }
......@@ -258,18 +258,18 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
258258 var record = unwind_records[record_id];
259259
260260 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);
262262 } else {
263263 if (getPersonalityFunctionReloc(
264264 zld,
265 @intCast(u32, object_id),
265 @as(u32, @intCast(object_id)),
266266 record_id,
267267 )) |rel| {
268268 const target = Atom.parseRelocTarget(zld, .{
269 .object_id = @intCast(u32, object_id),
269 .object_id = @as(u32, @intCast(object_id)),
270270 .rel = rel,
271271 .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))),
273273 });
274274 const personality_index = info.getPersonalityFunction(target) orelse inner: {
275275 const personality_index = info.personalities_count;
......@@ -282,14 +282,14 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
282282 UnwindEncoding.setPersonalityIndex(&record.compactUnwindEncoding, personality_index + 1);
283283 }
284284
285 if (getLsdaReloc(zld, @intCast(u32, object_id), record_id)) |rel| {
285 if (getLsdaReloc(zld, @as(u32, @intCast(object_id)), record_id)) |rel| {
286286 const target = Atom.parseRelocTarget(zld, .{
287 .object_id = @intCast(u32, object_id),
287 .object_id = @as(u32, @intCast(object_id)),
288288 .rel = rel,
289289 .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))),
291291 });
292 record.lsda = @bitCast(u64, target);
292 record.lsda = @as(u64, @bitCast(target));
293293 }
294294 }
295295 break :blk record;
......@@ -302,7 +302,7 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
302302 if (object.eh_frame_records_lookup.get(atom_index)) |fde_offset| {
303303 if (object.eh_frame_relocs_lookup.get(fde_offset).?.dead) continue;
304304 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);
306306 switch (cpu_arch) {
307307 .aarch64 => UnwindEncoding.setMode(&record.compactUnwindEncoding, macho.UNWIND_ARM64_MODE.DWARF),
308308 .x86_64 => UnwindEncoding.setMode(&record.compactUnwindEncoding, macho.UNWIND_X86_64_MODE.DWARF),
......@@ -320,7 +320,7 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
320320 const sym = zld.getSymbol(sym_loc);
321321 assert(sym.n_desc != N_DEAD);
322322 record.rangeStart = sym.n_value;
323 record.rangeLength = @intCast(u32, atom.size);
323 record.rangeLength = @as(u32, @intCast(atom.size));
324324
325325 records.appendAssumeCapacity(record);
326326 atom_indexes.appendAssumeCapacity(atom_index);
......@@ -329,7 +329,7 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
329329
330330 // Fold records
331331 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
334334 var maybe_prev: ?macho.compact_unwind_entry = null;
335335 for (records.items, 0..) |record, i| {
......@@ -341,15 +341,15 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
341341 (prev.personalityFunction != record.personalityFunction) or
342342 record.lsda > 0)
343343 {
344 const record_id = @intCast(RecordIndex, info.records.items.len);
344 const record_id = @as(RecordIndex, @intCast(info.records.items.len));
345345 info.records.appendAssumeCapacity(record);
346346 maybe_prev = record;
347347 break :blk record_id;
348348 } else {
349 break :blk @intCast(RecordIndex, info.records.items.len - 1);
349 break :blk @as(RecordIndex, @intCast(info.records.items.len - 1));
350350 }
351351 } else {
352 const record_id = @intCast(RecordIndex, info.records.items.len);
352 const record_id = @as(RecordIndex, @intCast(info.records.items.len));
353353 info.records.appendAssumeCapacity(record);
354354 maybe_prev = record;
355355 break :blk record_id;
......@@ -459,14 +459,14 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
459459 }
460460 }
461461
462 page.count = @intCast(u16, i - page.start);
462 page.count = @as(u16, @intCast(i - page.start));
463463
464464 if (i < info.records.items.len and page.count < max_regular_second_level_entries) {
465465 page.kind = .regular;
466 page.count = @intCast(u16, @min(
466 page.count = @as(u16, @intCast(@min(
467467 max_regular_second_level_entries,
468468 info.records.items.len - page.start,
469 ));
469 )));
470470 i = page.start + page.count;
471471 } else {
472472 page.kind = .compressed;
......@@ -479,11 +479,11 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void {
479479 }
480480
481481 // 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)));
483483 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)));
485485 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)));
487487 }
488488}
489489
......@@ -506,7 +506,7 @@ fn collectPersonalityFromDwarf(
506506
507507 if (cie.getPersonalityPointerReloc(
508508 zld,
509 @intCast(u32, object_id),
509 @as(u32, @intCast(object_id)),
510510 cie_offset,
511511 )) |target| {
512512 const personality_index = info.getPersonalityFunction(target) orelse inner: {
......@@ -532,8 +532,8 @@ fn calcRequiredSize(info: UnwindInfo) usize {
532532 var total_size: usize = 0;
533533 total_size += @sizeOf(macho.unwind_info_section_header);
534534 total_size +=
535 @intCast(usize, info.common_encodings_count) * @sizeOf(macho.compact_unwind_encoding_t);
536 total_size += @intCast(usize, info.personalities_count) * @sizeOf(u32);
535 @as(usize, @intCast(info.common_encodings_count)) * @sizeOf(macho.compact_unwind_encoding_t);
536 total_size += @as(usize, @intCast(info.personalities_count)) * @sizeOf(u32);
537537 total_size += (info.pages.items.len + 1) * @sizeOf(macho.unwind_info_section_header_index_entry);
538538 total_size += info.lsdas.items.len * @sizeOf(macho.unwind_info_section_header_lsda_index_entry);
539539 total_size += info.pages.items.len * second_level_page_bytes;
......@@ -557,7 +557,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {
557557 const atom_index = zld.getGotAtomIndexForSymbol(target).?;
558558 const atom = zld.getAtom(atom_index);
559559 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));
561561 log.debug(" {d}: 0x{x} ({s})", .{ i, personalities[i], zld.getSymbolName(target) });
562562 }
563563
......@@ -570,7 +570,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {
570570 }
571571
572572 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));
574574 if (lsda_target.getFile()) |_| {
575575 const sym = zld.getSymbol(lsda_target);
576576 rec.lsda = sym.n_value - seg.vmaddr;
......@@ -601,7 +601,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {
601601 const personalities_offset: u32 = common_encodings_offset + common_encodings_count * @sizeOf(u32);
602602 const personalities_count: u32 = info.personalities_count;
603603 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
606606 try writer.writeStruct(macho.unwind_info_section_header{
607607 .commonEncodingsArraySectionOffset = common_encodings_offset,
......@@ -615,34 +615,34 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {
615615 try writer.writeAll(mem.sliceAsBytes(info.common_encodings[0..info.common_encodings_count]));
616616 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));
619 const lsda_base_offset = @intCast(u32, pages_base_offset -
620 (info.lsdas.items.len * @sizeOf(macho.unwind_info_section_header_lsda_index_entry)));
618 const pages_base_offset = @as(u32, @intCast(size - (info.pages.items.len * second_level_page_bytes)));
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))));
621621 for (info.pages.items, 0..) |page, i| {
622622 assert(page.count > 0);
623623 const first_entry = info.records.items[page.start];
624624 try writer.writeStruct(macho.unwind_info_section_header_index_entry{
625 .functionOffset = @intCast(u32, first_entry.rangeStart),
626 .secondLevelPagesSectionOffset = @intCast(u32, pages_base_offset + i * second_level_page_bytes),
625 .functionOffset = @as(u32, @intCast(first_entry.rangeStart)),
626 .secondLevelPagesSectionOffset = @as(u32, @intCast(pages_base_offset + i * second_level_page_bytes)),
627627 .lsdaIndexArraySectionOffset = lsda_base_offset +
628628 info.lsdas_lookup.get(page.start).? * @sizeOf(macho.unwind_info_section_header_lsda_index_entry),
629629 });
630630 }
631631
632632 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));
634634 try writer.writeStruct(macho.unwind_info_section_header_index_entry{
635635 .functionOffset = sentinel_address,
636636 .secondLevelPagesSectionOffset = 0,
637637 .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),
639639 });
640640
641641 for (info.lsdas.items) |record_id| {
642642 const record = info.records.items[record_id];
643643 try writer.writeStruct(macho.unwind_info_section_header_lsda_index_entry{
644 .functionOffset = @intCast(u32, record.rangeStart),
645 .lsdaOffset = @intCast(u32, record.lsda),
644 .functionOffset = @as(u32, @intCast(record.rangeStart)),
645 .lsdaOffset = @as(u32, @intCast(record.lsda)),
646646 });
647647 }
648648
......@@ -674,7 +674,7 @@ fn getRelocs(zld: *Zld, object_id: u32, record_id: usize) []const macho.relocati
674674}
675675
676676fn 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)));
678678 const rel_offset = rel.r_address - base_offset;
679679 return rel_offset == 16;
680680}
......@@ -703,7 +703,7 @@ fn getPersonalityFunction(info: UnwindInfo, global_index: SymbolWithLoc) ?u2 {
703703}
704704
705705fn 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)));
707707 const rel_offset = rel.r_address - base_offset;
708708 return rel_offset == 24;
709709}
......@@ -754,45 +754,45 @@ fn getCommonEncoding(info: UnwindInfo, enc: macho.compact_unwind_encoding_t) ?u7
754754pub const UnwindEncoding = struct {
755755 pub fn getMode(enc: macho.compact_unwind_encoding_t) u4 {
756756 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));
758758 }
759759
760760 pub fn isDwarf(enc: macho.compact_unwind_encoding_t, cpu_arch: std.Target.Cpu.Arch) bool {
761761 const mode = getMode(enc);
762762 return switch (cpu_arch) {
763 .aarch64 => @enumFromInt(macho.UNWIND_ARM64_MODE, mode) == .DWARF,
764 .x86_64 => @enumFromInt(macho.UNWIND_X86_64_MODE, mode) == .DWARF,
763 .aarch64 => @as(macho.UNWIND_ARM64_MODE, @enumFromInt(mode)) == .DWARF,
764 .x86_64 => @as(macho.UNWIND_X86_64_MODE, @enumFromInt(mode)) == .DWARF,
765765 else => unreachable,
766766 };
767767 }
768768
769769 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;
771771 }
772772
773773 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));
775775 return has_lsda == 1;
776776 }
777777
778778 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;
780780 enc.* |= mask;
781781 }
782782
783783 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));
785785 return index;
786786 }
787787
788788 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;
790790 enc.* |= mask;
791791 }
792792
793793 pub fn getDwarfSectionOffset(enc: macho.compact_unwind_encoding_t, cpu_arch: std.Target.Cpu.Arch) u24 {
794794 assert(isDwarf(enc, cpu_arch));
795 const offset = @truncate(u24, enc);
795 const offset = @as(u24, @truncate(enc));
796796 return offset;
797797 }
798798
src/link/MachO/ZldAtom.zig+60-60
......@@ -117,8 +117,8 @@ pub fn getSectionAlias(zld: *Zld, atom_index: AtomIndex) ?SymbolWithLoc {
117117 assert(atom.getFile() != null);
118118
119119 const object = zld.objects.items[atom.getFile().?];
120 const nbase = @intCast(u32, object.in_symtab.?.len);
121 const ntotal = @intCast(u32, object.symtab.len);
120 const nbase = @as(u32, @intCast(object.in_symtab.?.len));
121 const ntotal = @as(u32, @intCast(object.symtab.len));
122122 var sym_index: u32 = nbase;
123123 while (sym_index < ntotal) : (sym_index += 1) {
124124 if (object.getAtomIndexForSymbol(sym_index)) |other_atom_index| {
......@@ -144,8 +144,8 @@ pub fn calcInnerSymbolOffset(zld: *Zld, atom_index: AtomIndex, sym_index: u32) u
144144 const base_addr = if (object.getSourceSymbol(atom.sym_index)) |sym|
145145 sym.n_value
146146 else blk: {
147 const nbase = @intCast(u32, object.in_symtab.?.len);
148 const sect_id = @intCast(u8, atom.sym_index - nbase);
147 const nbase = @as(u32, @intCast(object.in_symtab.?.len));
148 const sect_id = @as(u8, @intCast(atom.sym_index - nbase));
149149 const source_sect = object.getSourceSection(sect_id);
150150 break :blk source_sect.addr;
151151 };
......@@ -177,15 +177,15 @@ pub fn getRelocContext(zld: *Zld, atom_index: AtomIndex) RelocContext {
177177 if (object.getSourceSymbol(atom.sym_index)) |source_sym| {
178178 const source_sect = object.getSourceSection(source_sym.n_sect - 1);
179179 return .{
180 .base_addr = @intCast(i64, source_sect.addr),
181 .base_offset = @intCast(i32, source_sym.n_value - source_sect.addr),
180 .base_addr = @as(i64, @intCast(source_sect.addr)),
181 .base_offset = @as(i32, @intCast(source_sym.n_value - source_sect.addr)),
182182 };
183183 }
184 const nbase = @intCast(u32, object.in_symtab.?.len);
185 const sect_id = @intCast(u8, atom.sym_index - nbase);
184 const nbase = @as(u32, @intCast(object.in_symtab.?.len));
185 const sect_id = @as(u8, @intCast(atom.sym_index - nbase));
186186 const source_sect = object.getSourceSection(sect_id);
187187 return .{
188 .base_addr = @intCast(i64, source_sect.addr),
188 .base_addr = @as(i64, @intCast(source_sect.addr)),
189189 .base_offset = 0,
190190 };
191191}
......@@ -204,8 +204,8 @@ pub fn parseRelocTarget(zld: *Zld, ctx: struct {
204204 log.debug("parsing reloc target in object({d}) '{s}' ", .{ ctx.object_id, object.name });
205205
206206 const sym_index = if (ctx.rel.r_extern == 0) sym_index: {
207 const sect_id = @intCast(u8, ctx.rel.r_symbolnum - 1);
208 const rel_offset = @intCast(u32, ctx.rel.r_address - ctx.base_offset);
207 const sect_id = @as(u8, @intCast(ctx.rel.r_symbolnum - 1));
208 const rel_offset = @as(u32, @intCast(ctx.rel.r_address - ctx.base_offset));
209209
210210 const address_in_section = if (ctx.rel.r_pcrel == 0) blk: {
211211 break :blk if (ctx.rel.r_length == 3)
......@@ -214,7 +214,7 @@ pub fn parseRelocTarget(zld: *Zld, ctx: struct {
214214 mem.readIntLittle(u32, ctx.code[rel_offset..][0..4]);
215215 } else blk: {
216216 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))) {
218218 .X86_64_RELOC_SIGNED => 0,
219219 .X86_64_RELOC_SIGNED_1 => 1,
220220 .X86_64_RELOC_SIGNED_2 => 2,
......@@ -222,8 +222,8 @@ pub fn parseRelocTarget(zld: *Zld, ctx: struct {
222222 else => unreachable,
223223 };
224224 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;
226 break :blk @intCast(u64, target_address);
225 const target_address = @as(i64, @intCast(ctx.base_addr)) + ctx.rel.r_address + 4 + correction + addend;
226 break :blk @as(u64, @intCast(target_address));
227227 };
228228
229229 // Find containing atom
......@@ -272,7 +272,7 @@ pub fn getRelocTargetAtomIndex(zld: *Zld, target: SymbolWithLoc, is_via_got: boo
272272
273273fn scanAtomRelocsArm64(zld: *Zld, atom_index: AtomIndex, relocs: []align(1) const macho.relocation_info) !void {
274274 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
277277 switch (rel_type) {
278278 .ARM64_RELOC_ADDEND, .ARM64_RELOC_SUBTRACTOR => continue,
......@@ -318,7 +318,7 @@ fn scanAtomRelocsArm64(zld: *Zld, atom_index: AtomIndex, relocs: []align(1) cons
318318
319319fn scanAtomRelocsX86(zld: *Zld, atom_index: AtomIndex, relocs: []align(1) const macho.relocation_info) !void {
320320 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
323323 switch (rel_type) {
324324 .X86_64_RELOC_SUBTRACTOR => continue,
......@@ -364,7 +364,7 @@ fn addTlvPtrEntry(zld: *Zld, target: SymbolWithLoc) !void {
364364
365365 const gpa = zld.gpa;
366366 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));
368368 try zld.tlv_ptr_entries.append(gpa, .{
369369 .target = target,
370370 .atom_index = atom_index,
......@@ -376,7 +376,7 @@ pub fn addGotEntry(zld: *Zld, target: SymbolWithLoc) !void {
376376 if (zld.got_table.contains(target)) return;
377377 const gpa = zld.gpa;
378378 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));
380380 try zld.got_entries.append(gpa, .{
381381 .target = target,
382382 .atom_index = atom_index,
......@@ -393,7 +393,7 @@ pub fn addStub(zld: *Zld, target: SymbolWithLoc) !void {
393393 _ = try zld.createStubHelperAtom();
394394 _ = try zld.createLazyPointerAtom();
395395 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));
397397 try zld.stubs.append(gpa, .{
398398 .target = target,
399399 .atom_index = atom_index,
......@@ -489,7 +489,7 @@ fn resolveRelocsArm64(
489489 var subtractor: ?SymbolWithLoc = null;
490490
491491 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
494494 switch (rel_type) {
495495 .ARM64_RELOC_ADDEND => {
......@@ -529,7 +529,7 @@ fn resolveRelocsArm64(
529529 .base_addr = context.base_addr,
530530 .base_offset = context.base_offset,
531531 });
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
534534 log.debug(" RELA({s}) @ {x} => %{d} ('{s}') in object({?})", .{
535535 @tagName(rel_type),
......@@ -590,7 +590,7 @@ fn resolveRelocsArm64(
590590 aarch64.Instruction.unconditional_branch_immediate,
591591 ), code),
592592 };
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))));
594594 mem.writeIntLittle(u32, code, inst.toU32());
595595 },
596596
......@@ -598,11 +598,11 @@ fn resolveRelocsArm64(
598598 .ARM64_RELOC_GOT_LOAD_PAGE21,
599599 .ARM64_RELOC_TLVP_LOAD_PAGE21,
600600 => {
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
603603 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)));
606606 const code = atom_code[rel_offset..][0..4];
607607 var inst = aarch64.Instruction{
608608 .pc_relative_address = mem.bytesToValue(meta.TagPayload(
......@@ -610,14 +610,14 @@ fn resolveRelocsArm64(
610610 aarch64.Instruction.pc_relative_address,
611611 ), code),
612612 };
613 inst.pc_relative_address.immhi = @truncate(u19, pages >> 2);
614 inst.pc_relative_address.immlo = @truncate(u2, pages);
613 inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2));
614 inst.pc_relative_address.immlo = @as(u2, @truncate(pages));
615615 mem.writeIntLittle(u32, code, inst.toU32());
616616 addend = null;
617617 },
618618
619619 .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
622622 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
623623
......@@ -656,7 +656,7 @@ fn resolveRelocsArm64(
656656
657657 .ARM64_RELOC_GOT_LOAD_PAGEOFF12 => {
658658 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
661661 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
662662
......@@ -674,7 +674,7 @@ fn resolveRelocsArm64(
674674
675675 .ARM64_RELOC_TLVP_LOAD_PAGEOFF12 => {
676676 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
679679 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
680680
......@@ -725,7 +725,7 @@ fn resolveRelocsArm64(
725725 .sh = 0,
726726 .s = 0,
727727 .op = 0,
728 .sf = @truncate(u1, reg_info.size),
728 .sf = @as(u1, @truncate(reg_info.size)),
729729 },
730730 };
731731 mem.writeIntLittle(u32, code, inst.toU32());
......@@ -734,9 +734,9 @@ fn resolveRelocsArm64(
734734
735735 .ARM64_RELOC_POINTER_TO_GOT => {
736736 log.debug(" | target_addr = 0x{x}", .{target_addr});
737 const result = math.cast(i32, @intCast(i64, target_addr) - @intCast(i64, source_addr)) orelse
737 const result = math.cast(i32, @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr))) orelse
738738 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)));
740740 },
741741
742742 .ARM64_RELOC_UNSIGNED => {
......@@ -747,7 +747,7 @@ fn resolveRelocsArm64(
747747
748748 if (rel.r_extern == 0) {
749749 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))
751751 else
752752 object.source_address_lookup[target.sym_index];
753753 ptr_addend -= base_addr;
......@@ -756,17 +756,17 @@ fn resolveRelocsArm64(
756756 const result = blk: {
757757 if (subtractor) |sub| {
758758 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;
760760 } else {
761 break :blk @intCast(i64, target_addr) + ptr_addend;
761 break :blk @as(i64, @intCast(target_addr)) + ptr_addend;
762762 }
763763 };
764764 log.debug(" | target_addr = 0x{x}", .{result});
765765
766766 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)));
768768 } 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)))));
770770 }
771771
772772 subtractor = null;
......@@ -791,7 +791,7 @@ fn resolveRelocsX86(
791791 var subtractor: ?SymbolWithLoc = null;
792792
793793 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
796796 switch (rel_type) {
797797 .X86_64_RELOC_SUBTRACTOR => {
......@@ -823,7 +823,7 @@ fn resolveRelocsX86(
823823 .base_addr = context.base_addr,
824824 .base_offset = context.base_offset,
825825 });
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
828828 log.debug(" RELA({s}) @ {x} => %{d} ('{s}') in object({?})", .{
829829 @tagName(rel_type),
......@@ -851,7 +851,7 @@ fn resolveRelocsX86(
851851 switch (rel_type) {
852852 .X86_64_RELOC_BRANCH => {
853853 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));
855855 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
856856 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);
857857 mem.writeIntLittle(i32, atom_code[rel_offset..][0..4], disp);
......@@ -861,7 +861,7 @@ fn resolveRelocsX86(
861861 .X86_64_RELOC_GOT_LOAD,
862862 => {
863863 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));
865865 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
866866 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);
867867 mem.writeIntLittle(i32, atom_code[rel_offset..][0..4], disp);
......@@ -869,7 +869,7 @@ fn resolveRelocsX86(
869869
870870 .X86_64_RELOC_TLV => {
871871 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));
873873 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
874874 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);
875875
......@@ -897,14 +897,14 @@ fn resolveRelocsX86(
897897
898898 if (rel.r_extern == 0) {
899899 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))
901901 else
902902 object.source_address_lookup[target.sym_index];
903 addend += @intCast(i32, @intCast(i64, context.base_addr) + rel.r_address + 4 -
904 @intCast(i64, base_addr));
903 addend += @as(i32, @intCast(@as(i64, @intCast(context.base_addr)) + rel.r_address + 4 -
904 @as(i64, @intCast(base_addr))));
905905 }
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
909909 log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
910910
......@@ -920,7 +920,7 @@ fn resolveRelocsX86(
920920
921921 if (rel.r_extern == 0) {
922922 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))
924924 else
925925 object.source_address_lookup[target.sym_index];
926926 addend -= base_addr;
......@@ -929,17 +929,17 @@ fn resolveRelocsX86(
929929 const result = blk: {
930930 if (subtractor) |sub| {
931931 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;
933933 } else {
934 break :blk @intCast(i64, target_addr) + addend;
934 break :blk @as(i64, @intCast(target_addr)) + addend;
935935 }
936936 };
937937 log.debug(" | target_addr = 0x{x}", .{result});
938938
939939 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)));
941941 } 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)))));
943943 }
944944
945945 subtractor = null;
......@@ -958,19 +958,19 @@ pub fn getAtomCode(zld: *Zld, atom_index: AtomIndex) []const u8 {
958958 // If there was no matching symbol present in the source symtab, this means
959959 // we are dealing with either an entire section, or part of it, but also
960960 // starting at the beginning.
961 const nbase = @intCast(u32, object.in_symtab.?.len);
962 const sect_id = @intCast(u8, atom.sym_index - nbase);
961 const nbase = @as(u32, @intCast(object.in_symtab.?.len));
962 const sect_id = @as(u8, @intCast(atom.sym_index - nbase));
963963 const source_sect = object.getSourceSection(sect_id);
964964 assert(!source_sect.isZerofill());
965965 const code = object.getSectionContents(source_sect);
966 const code_len = @intCast(usize, atom.size);
966 const code_len = @as(usize, @intCast(atom.size));
967967 return code[0..code_len];
968968 };
969969 const source_sect = object.getSourceSection(source_sym.n_sect - 1);
970970 assert(!source_sect.isZerofill());
971971 const code = object.getSectionContents(source_sect);
972 const offset = @intCast(usize, source_sym.n_value - source_sect.addr);
973 const code_len = @intCast(usize, atom.size);
972 const offset = @as(usize, @intCast(source_sym.n_value - source_sect.addr));
973 const code_len = @as(usize, @intCast(atom.size));
974974 return code[offset..][0..code_len];
975975}
976976
......@@ -986,8 +986,8 @@ pub fn getAtomRelocs(zld: *Zld, atom_index: AtomIndex) []const macho.relocation_
986986 // If there was no matching symbol present in the source symtab, this means
987987 // we are dealing with either an entire section, or part of it, but also
988988 // starting at the beginning.
989 const nbase = @intCast(u32, object.in_symtab.?.len);
990 const sect_id = @intCast(u8, atom.sym_index - nbase);
989 const nbase = @as(u32, @intCast(object.in_symtab.?.len));
990 const sect_id = @as(u8, @intCast(atom.sym_index - nbase));
991991 break :blk sect_id;
992992 };
993993 const source_sect = object.getSourceSection(source_sect_id);
......@@ -998,14 +998,14 @@ pub fn getAtomRelocs(zld: *Zld, atom_index: AtomIndex) []const macho.relocation_
998998
999999pub fn relocRequiresGot(zld: *Zld, rel: macho.relocation_info) bool {
10001000 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))) {
10021002 .ARM64_RELOC_GOT_LOAD_PAGE21,
10031003 .ARM64_RELOC_GOT_LOAD_PAGEOFF12,
10041004 .ARM64_RELOC_POINTER_TO_GOT,
10051005 => return true,
10061006 else => return false,
10071007 },
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))) {
10091009 .X86_64_RELOC_GOT,
10101010 .X86_64_RELOC_GOT_LOAD,
10111011 => return true,
src/link/MachO/dead_strip.zig+12-12
......@@ -27,10 +27,10 @@ pub fn gcAtoms(zld: *Zld, resolver: *const SymbolResolver) !void {
2727 defer arena.deinit();
2828
2929 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
3232 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
3535 try collectRoots(zld, &roots, resolver);
3636 try mark(zld, roots, &alive);
......@@ -99,8 +99,8 @@ fn collectRoots(zld: *Zld, roots: *AtomTable, resolver: *const SymbolResolver) !
9999 const sect_id = if (object.getSourceSymbol(atom.sym_index)) |source_sym|
100100 source_sym.n_sect - 1
101101 else sect_id: {
102 const nbase = @intCast(u32, object.in_symtab.?.len);
103 const sect_id = @intCast(u8, atom.sym_index - nbase);
102 const nbase = @as(u32, @intCast(object.in_symtab.?.len));
103 const sect_id = @as(u8, @intCast(atom.sym_index - nbase));
104104 break :sect_id sect_id;
105105 };
106106 const source_sect = object.getSourceSection(sect_id);
......@@ -148,7 +148,7 @@ fn markLive(zld: *Zld, atom_index: AtomIndex, alive: *AtomTable) void {
148148
149149 for (relocs) |rel| {
150150 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))) {
152152 .ARM64_RELOC_ADDEND => continue,
153153 else => Atom.parseRelocTarget(zld, .{
154154 .object_id = atom.getFile().?,
......@@ -208,7 +208,7 @@ fn refersLive(zld: *Zld, atom_index: AtomIndex, alive: AtomTable) bool {
208208
209209 for (relocs) |rel| {
210210 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))) {
212212 .ARM64_RELOC_ADDEND => continue,
213213 else => Atom.parseRelocTarget(zld, .{
214214 .object_id = atom.getFile().?,
......@@ -264,8 +264,8 @@ fn mark(zld: *Zld, roots: AtomTable, alive: *AtomTable) !void {
264264 const sect_id = if (object.getSourceSymbol(atom.sym_index)) |source_sym|
265265 source_sym.n_sect - 1
266266 else blk: {
267 const nbase = @intCast(u32, object.in_symtab.?.len);
268 const sect_id = @intCast(u8, atom.sym_index - nbase);
267 const nbase = @as(u32, @intCast(object.in_symtab.?.len));
268 const sect_id = @as(u8, @intCast(atom.sym_index - nbase));
269269 break :blk sect_id;
270270 };
271271 const source_sect = object.getSourceSection(sect_id);
......@@ -283,7 +283,7 @@ fn mark(zld: *Zld, roots: AtomTable, alive: *AtomTable) !void {
283283 for (zld.objects.items, 0..) |_, object_id| {
284284 // Traverse unwind and eh_frame records noting if the source symbol has been marked, and if so,
285285 // marking all references as live.
286 try markUnwindRecords(zld, @intCast(u32, object_id), alive);
286 try markUnwindRecords(zld, @as(u32, @intCast(object_id)), alive);
287287 }
288288}
289289
......@@ -329,7 +329,7 @@ fn markUnwindRecords(zld: *Zld, object_id: u32, alive: *AtomTable) !void {
329329 .object_id = object_id,
330330 .rel = rel,
331331 .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))),
333333 });
334334 const target_sym = zld.getSymbol(target);
335335 if (!target_sym.undf()) {
......@@ -344,7 +344,7 @@ fn markUnwindRecords(zld: *Zld, object_id: u32, alive: *AtomTable) !void {
344344 .object_id = object_id,
345345 .rel = rel,
346346 .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))),
348348 });
349349 const target_object = zld.objects.items[target.getFile().?];
350350 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
377377 .object_id = object_id,
378378 .rel = rel,
379379 .code = fde.data,
380 .base_offset = @intCast(i32, fde_offset) + 4,
380 .base_offset = @as(i32, @intCast(fde_offset)) + 4,
381381 });
382382 const target_sym = zld.getSymbol(target);
383383 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 {
3131}
3232
3333pub fn size(rebase: Rebase) u64 {
34 return @intCast(u64, rebase.buffer.items.len);
34 return @as(u64, @intCast(rebase.buffer.items.len));
3535}
3636
3737pub fn finalize(rebase: *Rebase, gpa: Allocator) !void {
......@@ -145,12 +145,12 @@ fn finalizeSegment(entries: []const Entry, writer: anytype) !void {
145145
146146fn setTypePointer(writer: anytype) !void {
147147 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)));
149149}
150150
151151fn setSegmentOffset(segment_id: u8, offset: u64, writer: anytype) !void {
152152 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)));
154154 try std.leb.writeULEB128(writer, offset);
155155}
156156
......@@ -163,7 +163,7 @@ fn rebaseAddAddr(addr: u64, writer: anytype) !void {
163163fn rebaseTimes(count: usize, writer: anytype) !void {
164164 log.debug(">>> rebase with count: {d}", .{count});
165165 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)));
167167 } else {
168168 try writer.writeByte(macho.REBASE_OPCODE_DO_REBASE_ULEB_TIMES);
169169 try std.leb.writeULEB128(writer, count);
......@@ -182,7 +182,7 @@ fn addAddr(addr: u64, writer: anytype) !void {
182182 if (std.mem.isAlignedGeneric(u64, addr, @sizeOf(u64))) {
183183 const imm = @divExact(addr, @sizeOf(u64));
184184 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)));
186186 return;
187187 }
188188 }
src/link/MachO/dyld_info/bind.zig+18-18
......@@ -39,7 +39,7 @@ pub fn Bind(comptime Ctx: type, comptime Target: type) type {
3939 }
4040
4141 pub fn size(self: Self) u64 {
42 return @intCast(u64, self.buffer.items.len);
42 return @as(u64, @intCast(self.buffer.items.len));
4343 }
4444
4545 pub fn finalize(self: *Self, gpa: Allocator, ctx: Ctx) !void {
......@@ -95,7 +95,7 @@ pub fn Bind(comptime Ctx: type, comptime Target: type) type {
9595 const sym = ctx.getSymbol(current.target);
9696 const name = ctx.getSymbolName(current.target);
9797 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
100100 try setSymbol(name, flags, writer);
101101 try setTypePointer(writer);
......@@ -112,7 +112,7 @@ pub fn Bind(comptime Ctx: type, comptime Target: type) type {
112112 switch (state) {
113113 .start => {
114114 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);
116116 offset = offset - (offset - current.offset);
117117 } else if (current.offset > offset) {
118118 const delta = current.offset - offset;
......@@ -130,7 +130,7 @@ pub fn Bind(comptime Ctx: type, comptime Target: type) type {
130130 } else if (current.offset > offset) {
131131 const delta = current.offset - offset;
132132 state = .bind_times_skip;
133 skip = @intCast(u64, delta);
133 skip = @as(u64, @intCast(delta));
134134 offset += skip;
135135 } else unreachable;
136136 i -= 1;
......@@ -194,7 +194,7 @@ pub fn LazyBind(comptime Ctx: type, comptime Target: type) type {
194194 }
195195
196196 pub fn size(self: Self) u64 {
197 return @intCast(u64, self.buffer.items.len);
197 return @as(u64, @intCast(self.buffer.items.len));
198198 }
199199
200200 pub fn finalize(self: *Self, gpa: Allocator, ctx: Ctx) !void {
......@@ -208,12 +208,12 @@ pub fn LazyBind(comptime Ctx: type, comptime Target: type) type {
208208 var addend: i64 = 0;
209209
210210 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
213213 const sym = ctx.getSymbol(entry.target);
214214 const name = ctx.getSymbolName(entry.target);
215215 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
218218 try setSegmentOffset(entry.segment_id, entry.offset, writer);
219219 try setSymbol(name, flags, writer);
......@@ -238,20 +238,20 @@ pub fn LazyBind(comptime Ctx: type, comptime Target: type) type {
238238
239239fn setSegmentOffset(segment_id: u8, offset: u64, writer: anytype) !void {
240240 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)));
242242 try std.leb.writeULEB128(writer, offset);
243243}
244244
245245fn setSymbol(name: []const u8, flags: u8, writer: anytype) !void {
246246 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)));
248248 try writer.writeAll(name);
249249 try writer.writeByte(0);
250250}
251251
252252fn setTypePointer(writer: anytype) !void {
253253 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)));
255255}
256256
257257fn setDylibOrdinal(ordinal: i16, writer: anytype) !void {
......@@ -264,13 +264,13 @@ fn setDylibOrdinal(ordinal: i16, writer: anytype) !void {
264264 else => unreachable, // Invalid dylib special binding
265265 }
266266 log.debug(">>> set dylib special: {d}", .{ordinal});
267 const cast = @bitCast(u16, ordinal);
268 try writer.writeByte(macho.BIND_OPCODE_SET_DYLIB_SPECIAL_IMM | @truncate(u4, cast));
267 const cast = @as(u16, @bitCast(ordinal));
268 try writer.writeByte(macho.BIND_OPCODE_SET_DYLIB_SPECIAL_IMM | @as(u4, @truncate(cast)));
269269 } else {
270 const cast = @bitCast(u16, ordinal);
270 const cast = @as(u16, @bitCast(ordinal));
271271 log.debug(">>> set dylib ordinal: {d}", .{ordinal});
272272 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)));
274274 } else {
275275 try writer.writeByte(macho.BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB);
276276 try std.leb.writeULEB128(writer, cast);
......@@ -295,7 +295,7 @@ fn doBindAddAddr(addr: u64, writer: anytype) !void {
295295 const imm = @divExact(addr, @sizeOf(u64));
296296 if (imm <= 0xf) {
297297 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)),
299299 );
300300 return;
301301 }
......@@ -341,7 +341,7 @@ const TestContext = struct {
341341
342342 fn addSymbol(ctx: *TestContext, gpa: Allocator, name: []const u8, ordinal: i16, flags: u16) !void {
343343 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));
345345 n_desc |= flags;
346346 try ctx.symbols.append(gpa, .{
347347 .n_value = 0,
......@@ -353,7 +353,7 @@ const TestContext = struct {
353353 }
354354
355355 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));
357357 try ctx.strtab.appendSlice(gpa, name);
358358 try ctx.strtab.append(gpa, 0);
359359 return n_strx;
......@@ -366,7 +366,7 @@ const TestContext = struct {
366366 fn getSymbolName(ctx: TestContext, target: Target) []const u8 {
367367 const sym = ctx.getSymbol(target);
368368 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);
370370 }
371371};
372372
src/link/MachO/eh_frame.zig+36-36
......@@ -36,7 +36,7 @@ pub fn scanRelocs(zld: *Zld) !void {
3636 try cies.putNoClobber(cie_offset, {});
3737 it.seekTo(cie_offset);
3838 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);
4040 }
4141 }
4242 }
......@@ -110,7 +110,7 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void {
110110 var eh_frame_offset: u32 = 0;
111111
112112 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
115115 var cies = std.AutoHashMap(u32, u32).init(gpa);
116116 defer cies.deinit();
......@@ -139,7 +139,7 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void {
139139 eh_it.seekTo(cie_offset);
140140 const source_cie_record = (try eh_it.next()).?;
141141 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)), .{
143143 .source_offset = cie_offset,
144144 .out_offset = eh_frame_offset,
145145 .sect_addr = sect.addr,
......@@ -151,7 +151,7 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void {
151151
152152 var fde_record = try source_fde_record.toOwned(gpa);
153153 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)), .{
155155 .source_offset = fde_record_offset,
156156 .out_offset = eh_frame_offset,
157157 .sect_addr = sect.addr,
......@@ -194,7 +194,7 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void {
194194 UnwindInfo.UnwindEncoding.setDwarfSectionOffset(
195195 &record.compactUnwindEncoding,
196196 cpu_arch,
197 @intCast(u24, eh_frame_offset),
197 @as(u24, @intCast(eh_frame_offset)),
198198 );
199199
200200 const cie_record = eh_records.get(
......@@ -268,7 +268,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
268268 }) u64 {
269269 assert(rec.tag == .fde);
270270 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));
272272 }
273273
274274 pub fn setTargetSymbolAddress(rec: *Record, value: u64, ctx: struct {
......@@ -276,7 +276,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
276276 base_offset: u64,
277277 }) !void {
278278 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));
280280 mem.writeIntLittle(i64, rec.data[4..][0..8], addend);
281281 }
282282
......@@ -291,7 +291,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
291291 for (relocs) |rel| {
292292 switch (cpu_arch) {
293293 .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));
295295 switch (rel_type) {
296296 .ARM64_RELOC_SUBTRACTOR,
297297 .ARM64_RELOC_UNSIGNED,
......@@ -301,7 +301,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
301301 }
302302 },
303303 .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));
305305 switch (rel_type) {
306306 .X86_64_RELOC_GOT => {},
307307 else => unreachable,
......@@ -313,7 +313,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
313313 .object_id = object_id,
314314 .rel = rel,
315315 .code = rec.data,
316 .base_offset = @intCast(i32, source_offset) + 4,
316 .base_offset = @as(i32, @intCast(source_offset)) + 4,
317317 });
318318 return target;
319319 }
......@@ -335,40 +335,40 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
335335 .object_id = object_id,
336336 .rel = rel,
337337 .code = rec.data,
338 .base_offset = @intCast(i32, ctx.source_offset) + 4,
338 .base_offset = @as(i32, @intCast(ctx.source_offset)) + 4,
339339 });
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));
341341 const source_addr = ctx.sect_addr + rel_offset + ctx.out_offset + 4;
342342
343343 switch (cpu_arch) {
344344 .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));
346346 switch (rel_type) {
347347 .ARM64_RELOC_SUBTRACTOR => {
348348 // Address of the __eh_frame in the source object file
349349 },
350350 .ARM64_RELOC_POINTER_TO_GOT => {
351351 const target_addr = try Atom.getRelocTargetAddress(zld, target, true, false);
352 const result = math.cast(i32, @intCast(i64, target_addr) - @intCast(i64, source_addr)) orelse
352 const result = math.cast(i32, @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr))) orelse
353353 return error.Overflow;
354354 mem.writeIntLittle(i32, rec.data[rel_offset..][0..4], result);
355355 },
356356 .ARM64_RELOC_UNSIGNED => {
357357 assert(rel.r_extern == 1);
358358 const target_addr = try Atom.getRelocTargetAddress(zld, target, false, false);
359 const result = @intCast(i64, target_addr) - @intCast(i64, source_addr);
360 mem.writeIntLittle(i64, rec.data[rel_offset..][0..8], @intCast(i64, result));
359 const result = @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr));
360 mem.writeIntLittle(i64, rec.data[rel_offset..][0..8], @as(i64, @intCast(result)));
361361 },
362362 else => unreachable,
363363 }
364364 },
365365 .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));
367367 switch (rel_type) {
368368 .X86_64_RELOC_GOT => {
369369 const target_addr = try Atom.getRelocTargetAddress(zld, target, true, false);
370370 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));
372372 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);
373373 mem.writeIntLittle(i32, rec.data[rel_offset..][0..4], disp);
374374 },
......@@ -392,7 +392,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
392392
393393 pub fn getAugmentationString(rec: Record) []const u8 {
394394 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);
396396 }
397397
398398 pub fn getPersonalityPointer(rec: Record, ctx: struct {
......@@ -418,7 +418,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
418418 'P' => {
419419 const enc = try reader.readByte();
420420 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);
422422 return ptr;
423423 },
424424 'L' => {
......@@ -441,7 +441,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
441441 const reader = stream.reader();
442442 _ = try reader.readByte();
443443 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);
445445 return ptr;
446446 }
447447
......@@ -454,7 +454,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
454454 var stream = std.io.fixedBufferStream(rec.data[21..]);
455455 const writer = stream.writer();
456456 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);
458458 }
459459
460460 fn getLsdaEncoding(rec: Record) !?u8 {
......@@ -494,11 +494,11 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
494494 if (enc == EH_PE.omit) return null;
495495
496496 var ptr: i64 = switch (enc & 0x0F) {
497 EH_PE.absptr => @bitCast(i64, try reader.readIntLittle(u64)),
498 EH_PE.udata2 => @bitCast(i16, try reader.readIntLittle(u16)),
499 EH_PE.udata4 => @bitCast(i32, try reader.readIntLittle(u32)),
500 EH_PE.udata8 => @bitCast(i64, try reader.readIntLittle(u64)),
501 EH_PE.uleb128 => @bitCast(i64, try leb.readULEB128(u64, reader)),
497 EH_PE.absptr => @as(i64, @bitCast(try reader.readIntLittle(u64))),
498 EH_PE.udata2 => @as(i16, @bitCast(try reader.readIntLittle(u16))),
499 EH_PE.udata4 => @as(i32, @bitCast(try reader.readIntLittle(u32))),
500 EH_PE.udata8 => @as(i64, @bitCast(try reader.readIntLittle(u64))),
501 EH_PE.uleb128 => @as(i64, @bitCast(try leb.readULEB128(u64, reader))),
502502 EH_PE.sdata2 => try reader.readIntLittle(i16),
503503 EH_PE.sdata4 => try reader.readIntLittle(i32),
504504 EH_PE.sdata8 => try reader.readIntLittle(i64),
......@@ -517,13 +517,13 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
517517 else => return null,
518518 }
519519
520 return @bitCast(u64, ptr);
520 return @as(u64, @bitCast(ptr));
521521 }
522522
523523 fn setEncodedPointer(enc: u8, pcrel_offset: i64, value: u64, writer: anytype) !void {
524524 if (enc == EH_PE.omit) return;
525525
526 var actual = @intCast(i64, value);
526 var actual = @as(i64, @intCast(value));
527527
528528 switch (enc & 0x70) {
529529 EH_PE.absptr => {},
......@@ -537,13 +537,13 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
537537 }
538538
539539 switch (enc & 0x0F) {
540 EH_PE.absptr => try writer.writeIntLittle(u64, @bitCast(u64, actual)),
541 EH_PE.udata2 => try writer.writeIntLittle(u16, @bitCast(u16, @intCast(i16, actual))),
542 EH_PE.udata4 => try writer.writeIntLittle(u32, @bitCast(u32, @intCast(i32, actual))),
543 EH_PE.udata8 => try writer.writeIntLittle(u64, @bitCast(u64, actual)),
544 EH_PE.uleb128 => try leb.writeULEB128(writer, @bitCast(u64, actual)),
545 EH_PE.sdata2 => try writer.writeIntLittle(i16, @intCast(i16, actual)),
546 EH_PE.sdata4 => try writer.writeIntLittle(i32, @intCast(i32, actual)),
540 EH_PE.absptr => try writer.writeIntLittle(u64, @as(u64, @bitCast(actual))),
541 EH_PE.udata2 => try writer.writeIntLittle(u16, @as(u16, @bitCast(@as(i16, @intCast(actual))))),
542 EH_PE.udata4 => try writer.writeIntLittle(u32, @as(u32, @bitCast(@as(i32, @intCast(actual))))),
543 EH_PE.udata8 => try writer.writeIntLittle(u64, @as(u64, @bitCast(actual))),
544 EH_PE.uleb128 => try leb.writeULEB128(writer, @as(u64, @bitCast(actual))),
545 EH_PE.sdata2 => try writer.writeIntLittle(i16, @as(i16, @intCast(actual))),
546 EH_PE.sdata4 => try writer.writeIntLittle(i32, @as(i32, @intCast(actual))),
547547 EH_PE.sdata8 => try writer.writeIntLittle(i64, actual),
548548 EH_PE.sleb128 => try leb.writeILEB128(writer, actual),
549549 else => unreachable,
src/link/MachO/load_commands.zig+12-12
......@@ -114,7 +114,7 @@ fn calcLCsSize(gpa: Allocator, options: *const link.Options, ctx: CalcLCsSizeCtx
114114 }
115115 }
116116
117 return @intCast(u32, sizeofcmds);
117 return @as(u32, @intCast(sizeofcmds));
118118}
119119
120120pub fn calcMinHeaderPad(gpa: Allocator, options: *const link.Options, ctx: CalcLCsSizeCtx) !u64 {
......@@ -140,7 +140,7 @@ pub fn calcNumOfLCs(lc_buffer: []const u8) u32 {
140140 var pos: usize = 0;
141141 while (true) {
142142 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)).*;
144144 ncmds += 1;
145145 pos += cmd.cmdsize;
146146 }
......@@ -149,11 +149,11 @@ pub fn calcNumOfLCs(lc_buffer: []const u8) u32 {
149149
150150pub fn writeDylinkerLC(lc_writer: anytype) !void {
151151 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(
153153 u64,
154154 @sizeOf(macho.dylinker_command) + name_len,
155155 @sizeOf(u64),
156 ));
156 )));
157157 try lc_writer.writeStruct(macho.dylinker_command{
158158 .cmd = .LOAD_DYLINKER,
159159 .cmdsize = cmdsize,
......@@ -176,11 +176,11 @@ const WriteDylibLCCtx = struct {
176176
177177fn writeDylibLC(ctx: WriteDylibLCCtx, lc_writer: anytype) !void {
178178 const name_len = ctx.name.len + 1;
179 const cmdsize = @intCast(u32, mem.alignForward(
179 const cmdsize = @as(u32, @intCast(mem.alignForward(
180180 u64,
181181 @sizeOf(macho.dylib_command) + name_len,
182182 @sizeOf(u64),
183 ));
183 )));
184184 try lc_writer.writeStruct(macho.dylib_command{
185185 .cmd = ctx.cmd,
186186 .cmdsize = cmdsize,
......@@ -217,8 +217,8 @@ pub fn writeDylibIdLC(gpa: Allocator, options: *const link.Options, lc_writer: a
217217 try writeDylibLC(.{
218218 .cmd = .ID_DYLIB,
219219 .name = install_name,
220 .current_version = @intCast(u32, curr.major << 16 | curr.minor << 8 | curr.patch),
221 .compatibility_version = @intCast(u32, compat.major << 16 | compat.minor << 8 | compat.patch),
220 .current_version = @as(u32, @intCast(curr.major << 16 | curr.minor << 8 | curr.patch)),
221 .compatibility_version = @as(u32, @intCast(compat.major << 16 | compat.minor << 8 | compat.patch)),
222222 }, lc_writer);
223223}
224224
......@@ -253,11 +253,11 @@ pub fn writeRpathLCs(gpa: Allocator, options: *const link.Options, lc_writer: an
253253
254254 while (try it.next()) |rpath| {
255255 const rpath_len = rpath.len + 1;
256 const cmdsize = @intCast(u32, mem.alignForward(
256 const cmdsize = @as(u32, @intCast(mem.alignForward(
257257 u64,
258258 @sizeOf(macho.rpath_command) + rpath_len,
259259 @sizeOf(u64),
260 ));
260 )));
261261 try lc_writer.writeStruct(macho.rpath_command{
262262 .cmdsize = cmdsize,
263263 .path = @sizeOf(macho.rpath_command),
......@@ -275,12 +275,12 @@ pub fn writeBuildVersionLC(options: *const link.Options, lc_writer: anytype) !vo
275275 const cmdsize = @sizeOf(macho.build_version_command) + @sizeOf(macho.build_tool_version);
276276 const platform_version = blk: {
277277 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));
279279 break :blk platform_version;
280280 };
281281 const sdk_version = if (options.native_darwin_sdk) |sdk| blk: {
282282 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));
284284 break :blk sdk_version;
285285 } else platform_version;
286286 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 {
131131 log.debug("GROUP END at {d}", .{group_end});
132132
133133 // 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));
135135 try zld.thunks.append(gpa, .{ .start_index = undefined, .len = 0 });
136136
137137 // 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 {
174174 }
175175 }
176176
177 header.size = @intCast(u32, offset);
177 header.size = @as(u32, @intCast(offset));
178178}
179179
180180fn allocateThunk(
......@@ -223,7 +223,7 @@ fn scanRelocs(
223223
224224 const base_offset = if (object.getSourceSymbol(atom.sym_index)) |source_sym| blk: {
225225 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));
227227 } else 0;
228228
229229 const code = Atom.getAtomCode(zld, atom_index);
......@@ -289,7 +289,7 @@ fn scanRelocs(
289289}
290290
291291inline 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));
293293 return rel_type == .ARM64_RELOC_BRANCH26;
294294}
295295
......@@ -315,7 +315,7 @@ fn isReachable(
315315
316316 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));
319319 const is_via_got = Atom.relocRequiresGot(zld, rel);
320320 const target_addr = Atom.getRelocTargetAddress(zld, target, is_via_got, false) catch unreachable;
321321 _ = Relocation.calcPcRelativeDisplacementArm64(source_addr, target_addr) catch
......@@ -349,7 +349,7 @@ fn getThunkIndex(zld: *Zld, atom_index: AtomIndex) ?ThunkIndex {
349349 const end_addr = start_addr + thunk.getSize();
350350
351351 if (start_addr <= sym.n_value and sym.n_value < end_addr) {
352 return @intCast(u32, i);
352 return @as(u32, @intCast(i));
353353 }
354354 }
355355 return null;
src/link/MachO/zld.zig+72-72
......@@ -103,7 +103,7 @@ pub const Zld = struct {
103103 const cpu_arch = self.options.target.cpu.arch;
104104 const mtime: u64 = mtime: {
105105 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)));
107107 };
108108 const file_stat = try file.stat();
109109 const file_size = math.cast(usize, file_stat.size) orelse return error.Overflow;
......@@ -220,7 +220,7 @@ pub const Zld = struct {
220220 const contents = try file.readToEndAllocOptions(gpa, file_size, file_size, @alignOf(u64), null);
221221 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));
224224 var dylib = Dylib{ .weak = opts.weak };
225225
226226 dylib.parseFromBinary(
......@@ -535,7 +535,7 @@ pub const Zld = struct {
535535
536536 pub fn createEmptyAtom(self: *Zld, sym_index: u32, size: u64, alignment: u32) !AtomIndex {
537537 const gpa = self.gpa;
538 const index = @intCast(AtomIndex, self.atoms.items.len);
538 const index = @as(AtomIndex, @intCast(self.atoms.items.len));
539539 const atom = try self.atoms.addOne(gpa);
540540 atom.* = Atom.empty;
541541 atom.sym_index = sym_index;
......@@ -596,7 +596,7 @@ pub const Zld = struct {
596596 const global_index = self.dyld_stub_binder_index orelse return;
597597 const target = self.globals.items[global_index];
598598 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));
600600 try self.got_entries.append(gpa, .{
601601 .target = target,
602602 .atom_index = atom_index,
......@@ -874,7 +874,7 @@ pub const Zld = struct {
874874 }
875875
876876 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);
878878 }
879879
880880 try self.resolveSymbolsInArchives(resolver);
......@@ -1024,7 +1024,7 @@ pub const Zld = struct {
10241024 };
10251025 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));
10281028 const object = archive.parseObject(gpa, cpu_arch, offsets.items[0]) catch |e| switch (e) {
10291029 error.MismatchedCpuArchitecture => {
10301030 log.err("CPU architecture mismatch found in {s}", .{archive.name});
......@@ -1055,14 +1055,14 @@ pub const Zld = struct {
10551055 for (self.dylibs.items, 0..) |dylib, id| {
10561056 if (!dylib.symbols.contains(sym_name)) continue;
10571057
1058 const dylib_id = @intCast(u16, id);
1058 const dylib_id = @as(u16, @intCast(id));
10591059 if (!self.referenced_dylibs.contains(dylib_id)) {
10601060 try self.referenced_dylibs.putNoClobber(self.gpa, dylib_id, {});
10611061 }
10621062
10631063 const ordinal = self.referenced_dylibs.getIndex(dylib_id) orelse unreachable;
10641064 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
10671067 if (dylib.weak) {
10681068 sym.n_desc |= macho.N_WEAK_REF;
......@@ -1099,9 +1099,9 @@ pub const Zld = struct {
10991099 _ = resolver.unresolved.swapRemove(global_index);
11001100 continue;
11011101 } else if (allow_undef) {
1102 const n_desc = @bitCast(
1102 const n_desc = @as(
11031103 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))),
11051105 );
11061106 sym.n_type = macho.N_EXT;
11071107 sym.n_desc = n_desc;
......@@ -1238,7 +1238,7 @@ pub const Zld = struct {
12381238 const segname = header.segName();
12391239 const segment_id = self.getSegmentByName(segname) orelse blk: {
12401240 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));
12421242 const protection = getSegmentMemoryProtection(segname);
12431243 try self.segments.append(self.gpa, .{
12441244 .cmdsize = @sizeOf(macho.segment_command_64),
......@@ -1269,7 +1269,7 @@ pub const Zld = struct {
12691269 pub fn allocateSymbol(self: *Zld) !u32 {
12701270 try self.locals.ensureUnusedCapacity(self.gpa, 1);
12711271 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));
12731273 _ = self.locals.addOneAssumeCapacity();
12741274 self.locals.items[index] = .{
12751275 .n_strx = 0,
......@@ -1282,7 +1282,7 @@ pub const Zld = struct {
12821282 }
12831283
12841284 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));
12861286 try self.globals.append(self.gpa, sym_loc);
12871287 return global_index;
12881288 }
......@@ -1489,7 +1489,7 @@ pub const Zld = struct {
14891489 if (mem.eql(u8, header.sectName(), "__stub_helper")) continue;
14901490
14911491 // 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)));
14931493 }
14941494 }
14951495 }
......@@ -1502,7 +1502,7 @@ pub const Zld = struct {
15021502 .dylibs = self.dylibs.items,
15031503 .referenced_dylibs = self.referenced_dylibs.keys(),
15041504 }) else 0;
1505 try self.allocateSegment(@intCast(u8, segment_index), base_size);
1505 try self.allocateSegment(@as(u8, @intCast(segment_index)), base_size);
15061506 }
15071507 }
15081508
......@@ -1536,12 +1536,12 @@ pub const Zld = struct {
15361536 for (slice.items(.header)[indexes.start..indexes.end], 0..) |*header, sect_id| {
15371537 const alignment = try math.powi(u32, 2, header.@"align");
15381538 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
15411541 header.offset = if (header.isZerofill())
15421542 0
15431543 else
1544 @intCast(u32, segment.fileoff + start_aligned);
1544 @as(u32, @intCast(segment.fileoff + start_aligned));
15451545 header.addr = segment.vmaddr + start_aligned;
15461546
15471547 var atom_index = slice.items(.first_atom_index)[indexes.start + sect_id];
......@@ -1617,7 +1617,7 @@ pub const Zld = struct {
16171617 ) !u8 {
16181618 const gpa = self.gpa;
16191619 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));
16211621 try self.sections.append(gpa, .{
16221622 .segment_index = undefined, // Segments will be created automatically later down the pipeline
16231623 .header = .{
......@@ -1673,12 +1673,12 @@ pub const Zld = struct {
16731673 },
16741674 }
16751675 };
1676 return (@intCast(u8, segment_precedence) << 4) + section_precedence;
1676 return (@as(u8, @intCast(segment_precedence)) << 4) + section_precedence;
16771677 }
16781678
16791679 fn writeSegmentHeaders(self: *Zld, writer: anytype) !void {
16801680 for (self.segments.items, 0..) |seg, i| {
1681 const indexes = self.getSectionIndexes(@intCast(u8, i));
1681 const indexes = self.getSectionIndexes(@as(u8, @intCast(i)));
16821682 var out_seg = seg;
16831683 out_seg.cmdsize = @sizeOf(macho.segment_command_64);
16841684 out_seg.nsects = 0;
......@@ -1790,7 +1790,7 @@ pub const Zld = struct {
17901790 }
17911791
17921792 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)));
17941794 if (segment.maxprot & macho.PROT.WRITE == 0) continue;
17951795
17961796 log.debug("{s},{s}", .{ header.segName(), header.sectName() });
......@@ -1820,12 +1820,12 @@ pub const Zld = struct {
18201820 for (relocs) |rel| {
18211821 switch (cpu_arch) {
18221822 .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));
18241824 if (rel_type != .ARM64_RELOC_UNSIGNED) continue;
18251825 if (rel.r_length != 3) continue;
18261826 },
18271827 .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));
18291829 if (rel_type != .X86_64_RELOC_UNSIGNED) continue;
18301830 if (rel.r_length != 3) continue;
18311831 },
......@@ -1841,9 +1841,9 @@ pub const Zld = struct {
18411841 const target_sym = self.getSymbol(target);
18421842 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));
18451845 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));
18471847 log.debug(" | rebase at {x}", .{offset});
18481848
18491849 try rebase.entries.append(self.gpa, .{
......@@ -1882,7 +1882,7 @@ pub const Zld = struct {
18821882 const sym = entry.getAtomSymbol(self);
18831883 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);
18861886 log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{
18871887 base_offset,
18881888 bind_sym_name,
......@@ -1929,7 +1929,7 @@ pub const Zld = struct {
19291929 }
19301930
19311931 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)));
19331933 if (segment.maxprot & macho.PROT.WRITE == 0) continue;
19341934
19351935 const cpu_arch = self.options.target.cpu.arch;
......@@ -1959,12 +1959,12 @@ pub const Zld = struct {
19591959 for (relocs) |rel| {
19601960 switch (cpu_arch) {
19611961 .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));
19631963 if (rel_type != .ARM64_RELOC_UNSIGNED) continue;
19641964 if (rel.r_length != 3) continue;
19651965 },
19661966 .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));
19681968 if (rel_type != .X86_64_RELOC_UNSIGNED) continue;
19691969 if (rel.r_length != 3) continue;
19701970 },
......@@ -1983,11 +1983,11 @@ pub const Zld = struct {
19831983 if (!bind_sym.undf()) continue;
19841984
19851985 const base_offset = sym.n_value - segment.vmaddr;
1986 const rel_offset = @intCast(u32, rel.r_address - ctx.base_offset);
1987 const offset = @intCast(u64, base_offset + rel_offset);
1986 const rel_offset = @as(u32, @intCast(rel.r_address - ctx.base_offset));
1987 const offset = @as(u64, @intCast(base_offset + rel_offset));
19881988 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);
19911991 log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{
19921992 base_offset,
19931993 bind_sym_name,
......@@ -2039,7 +2039,7 @@ pub const Zld = struct {
20392039 const stub_entry = self.stubs.items[count];
20402040 const bind_sym = stub_entry.getTargetSymbol(self);
20412041 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);
20432043 log.debug(" | lazy bind at {x}, import('{s}') in dylib({d})", .{
20442044 base_offset,
20452045 bind_sym_name,
......@@ -2165,14 +2165,14 @@ pub const Zld = struct {
21652165 try self.file.pwriteAll(buffer, rebase_off);
21662166 try self.populateLazyBindOffsetsInStubHelper(lazy_bind);
21672167
2168 self.dyld_info_cmd.rebase_off = @intCast(u32, rebase_off);
2169 self.dyld_info_cmd.rebase_size = @intCast(u32, rebase_size_aligned);
2170 self.dyld_info_cmd.bind_off = @intCast(u32, bind_off);
2171 self.dyld_info_cmd.bind_size = @intCast(u32, bind_size_aligned);
2172 self.dyld_info_cmd.lazy_bind_off = @intCast(u32, lazy_bind_off);
2173 self.dyld_info_cmd.lazy_bind_size = @intCast(u32, lazy_bind_size_aligned);
2174 self.dyld_info_cmd.export_off = @intCast(u32, export_off);
2175 self.dyld_info_cmd.export_size = @intCast(u32, export_size_aligned);
2168 self.dyld_info_cmd.rebase_off = @as(u32, @intCast(rebase_off));
2169 self.dyld_info_cmd.rebase_size = @as(u32, @intCast(rebase_size_aligned));
2170 self.dyld_info_cmd.bind_off = @as(u32, @intCast(bind_off));
2171 self.dyld_info_cmd.bind_size = @as(u32, @intCast(bind_size_aligned));
2172 self.dyld_info_cmd.lazy_bind_off = @as(u32, @intCast(lazy_bind_off));
2173 self.dyld_info_cmd.lazy_bind_size = @as(u32, @intCast(lazy_bind_size_aligned));
2174 self.dyld_info_cmd.export_off = @as(u32, @intCast(export_off));
2175 self.dyld_info_cmd.export_size = @as(u32, @intCast(export_size_aligned));
21762176 }
21772177
21782178 fn populateLazyBindOffsetsInStubHelper(self: *Zld, lazy_bind: LazyBind) !void {
......@@ -2246,7 +2246,7 @@ pub const Zld = struct {
22462246
22472247 var last_off: u32 = 0;
22482248 for (addresses.items) |addr| {
2249 const offset = @intCast(u32, addr - text_seg.vmaddr);
2249 const offset = @as(u32, @intCast(addr - text_seg.vmaddr));
22502250 const diff = offset - last_off;
22512251
22522252 if (diff == 0) continue;
......@@ -2258,7 +2258,7 @@ pub const Zld = struct {
22582258 var buffer = std.ArrayList(u8).init(gpa);
22592259 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)));
22622262 try buffer.ensureTotalCapacity(max_size);
22632263
22642264 for (offsets.items) |offset| {
......@@ -2281,8 +2281,8 @@ pub const Zld = struct {
22812281
22822282 try self.file.pwriteAll(buffer.items, offset);
22832283
2284 self.function_starts_cmd.dataoff = @intCast(u32, offset);
2285 self.function_starts_cmd.datasize = @intCast(u32, needed_size_aligned);
2284 self.function_starts_cmd.dataoff = @as(u32, @intCast(offset));
2285 self.function_starts_cmd.datasize = @as(u32, @intCast(needed_size_aligned));
22862286 }
22872287
22882288 fn filterDataInCode(
......@@ -2324,8 +2324,8 @@ pub const Zld = struct {
23242324 const source_addr = if (object.getSourceSymbol(atom.sym_index)) |source_sym|
23252325 source_sym.n_value
23262326 else blk: {
2327 const nbase = @intCast(u32, object.in_symtab.?.len);
2328 const source_sect_id = @intCast(u8, atom.sym_index - nbase);
2327 const nbase = @as(u32, @intCast(object.in_symtab.?.len));
2328 const source_sect_id = @as(u8, @intCast(atom.sym_index - nbase));
23292329 break :blk object.getSourceSection(source_sect_id).addr;
23302330 };
23312331 const filtered_dice = filterDataInCode(dice, source_addr, source_addr + atom.size);
......@@ -2363,8 +2363,8 @@ pub const Zld = struct {
23632363
23642364 try self.file.pwriteAll(buffer, offset);
23652365
2366 self.data_in_code_cmd.dataoff = @intCast(u32, offset);
2367 self.data_in_code_cmd.datasize = @intCast(u32, needed_size_aligned);
2366 self.data_in_code_cmd.dataoff = @as(u32, @intCast(offset));
2367 self.data_in_code_cmd.datasize = @as(u32, @intCast(needed_size_aligned));
23682368 }
23692369
23702370 fn writeSymtabs(self: *Zld) !void {
......@@ -2428,7 +2428,7 @@ pub const Zld = struct {
24282428 if (!sym.undf()) continue; // not an import, skip
24292429 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));
24322432 var out_sym = sym;
24332433 out_sym.n_strx = try self.strtab.insert(gpa, self.getSymbolName(global));
24342434 try imports.append(out_sym);
......@@ -2443,9 +2443,9 @@ pub const Zld = struct {
24432443 }
24442444 }
24452445
2446 const nlocals = @intCast(u32, locals.items.len);
2447 const nexports = @intCast(u32, exports.items.len);
2448 const nimports = @intCast(u32, imports.items.len);
2446 const nlocals = @as(u32, @intCast(locals.items.len));
2447 const nexports = @as(u32, @intCast(exports.items.len));
2448 const nimports = @as(u32, @intCast(imports.items.len));
24492449 const nsyms = nlocals + nexports + nimports;
24502450
24512451 const seg = self.getLinkeditSegmentPtr();
......@@ -2465,7 +2465,7 @@ pub const Zld = struct {
24652465 log.debug("writing symtab from 0x{x} to 0x{x}", .{ offset, offset + needed_size });
24662466 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));
24692469 self.symtab_cmd.nsyms = nsyms;
24702470
24712471 return SymtabCtx{
......@@ -2493,8 +2493,8 @@ pub const Zld = struct {
24932493
24942494 try self.file.pwriteAll(buffer, offset);
24952495
2496 self.symtab_cmd.stroff = @intCast(u32, offset);
2497 self.symtab_cmd.strsize = @intCast(u32, needed_size_aligned);
2496 self.symtab_cmd.stroff = @as(u32, @intCast(offset));
2497 self.symtab_cmd.strsize = @as(u32, @intCast(needed_size_aligned));
24982498 }
24992499
25002500 const SymtabCtx = struct {
......@@ -2506,8 +2506,8 @@ pub const Zld = struct {
25062506
25072507 fn writeDysymtab(self: *Zld, ctx: SymtabCtx) !void {
25082508 const gpa = self.gpa;
2509 const nstubs = @intCast(u32, self.stubs.items.len);
2510 const ngot_entries = @intCast(u32, self.got_entries.items.len);
2509 const nstubs = @as(u32, @intCast(self.stubs.items.len));
2510 const ngot_entries = @as(u32, @intCast(self.got_entries.items.len));
25112511 const nindirectsyms = nstubs * 2 + ngot_entries;
25122512 const iextdefsym = ctx.nlocalsym;
25132513 const iundefsym = iextdefsym + ctx.nextdefsym;
......@@ -2572,7 +2572,7 @@ pub const Zld = struct {
25722572 self.dysymtab_cmd.nextdefsym = ctx.nextdefsym;
25732573 self.dysymtab_cmd.iundefsym = iundefsym;
25742574 self.dysymtab_cmd.nundefsym = ctx.nundefsym;
2575 self.dysymtab_cmd.indirectsymoff = @intCast(u32, offset);
2575 self.dysymtab_cmd.indirectsymoff = @as(u32, @intCast(offset));
25762576 self.dysymtab_cmd.nindirectsyms = nindirectsyms;
25772577 }
25782578
......@@ -2599,8 +2599,8 @@ pub const Zld = struct {
25992599 // except for code signature data.
26002600 try self.file.pwriteAll(&[_]u8{0}, offset + needed_size - 1);
26012601
2602 self.codesig_cmd.dataoff = @intCast(u32, offset);
2603 self.codesig_cmd.datasize = @intCast(u32, needed_size);
2602 self.codesig_cmd.dataoff = @as(u32, @intCast(offset));
2603 self.codesig_cmd.datasize = @as(u32, @intCast(needed_size));
26042604 }
26052605
26062606 fn writeCodeSignature(self: *Zld, comp: *const Compilation, code_sig: *CodeSignature) !void {
......@@ -2689,7 +2689,7 @@ pub const Zld = struct {
26892689
26902690 fn getSegmentByName(self: Zld, segname: []const u8) ?u8 {
26912691 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));
26932693 } else return null;
26942694 }
26952695
......@@ -2714,15 +2714,15 @@ pub const Zld = struct {
27142714 // TODO investigate caching with a hashmap
27152715 for (self.sections.items(.header), 0..) |header, i| {
27162716 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));
27182718 } else return null;
27192719 }
27202720
27212721 pub fn getSectionIndexes(self: Zld, segment_index: u8) struct { start: u8, end: u8 } {
27222722 var start: u8 = 0;
27232723 const nsects = for (self.segments.items, 0..) |seg, i| {
2724 if (i == segment_index) break @intCast(u8, seg.nsects);
2725 start += @intCast(u8, seg.nsects);
2724 if (i == segment_index) break @as(u8, @intCast(seg.nsects));
2725 start += @as(u8, @intCast(seg.nsects));
27262726 } else 0;
27272727 return .{ .start = start, .end = start + nsects };
27282728 }
......@@ -2879,7 +2879,7 @@ pub const Zld = struct {
28792879 var name_lookup: ?DwarfInfo.SubprogramLookupByName = if (object.header.flags & macho.MH_SUBSECTIONS_VIA_SYMBOLS == 0) blk: {
28802880 var name_lookup = DwarfInfo.SubprogramLookupByName.init(gpa);
28812881 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)));
28832883 try debug_info.genSubprogramLookupByName(compile_unit, lookup, &name_lookup);
28842884 break :blk name_lookup;
28852885 } else null;
......@@ -3069,7 +3069,7 @@ pub const Zld = struct {
30693069 @memset(&buf, '_');
30703070 scoped_log.debug(" %{d}: {s} @{x} in sect({d}), {s}", .{
30713071 sym_id,
3072 object.getSymbolName(@intCast(u32, sym_id)),
3072 object.getSymbolName(@as(u32, @intCast(sym_id))),
30733073 sym.n_value,
30743074 sym.n_sect,
30753075 logSymAttributes(sym, &buf),
......@@ -3252,7 +3252,7 @@ pub const Zld = struct {
32523252 }
32533253};
32543254
3255pub const N_DEAD: u16 = @bitCast(u16, @as(i16, -1));
3255pub const N_DEAD: u16 = @as(u16, @bitCast(@as(i16, -1)));
32563256
32573257const Section = struct {
32583258 header: macho.section_64,
......@@ -3791,7 +3791,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
37913791 }
37923792
37933793 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)));
37953795 }
37963796
37973797 if (gc_sections) {
......@@ -3929,7 +3929,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
39293929 } else sym.n_value;
39303930
39313931 try lc_writer.writeStruct(macho.entry_point_command{
3932 .entryoff = @intCast(u32, addr - seg.vmaddr),
3932 .entryoff = @as(u32, @intCast(addr - seg.vmaddr)),
39333933 .stacksize = options.stack_size_override orelse 0,
39343934 });
39353935 } else {
......@@ -3943,7 +3943,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
39433943 });
39443944 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));
39473947 try lc_writer.writeStruct(zld.uuid_cmd);
39483948
39493949 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
39543954
39553955 const ncmds = load_commands.calcNumOfLCs(lc_buffer.items);
39563956 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)));
39583958 try zld.writeUuid(comp, uuid_cmd_offset, requires_codesig);
39593959
39603960 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 {
295295 .sym_index = blk: {
296296 try self.syms.append(gpa, undefined);
297297 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));
299299 },
300300 };
301301 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
485485 .ty = decl.ty,
486486 .val = decl_val,
487487 }, &code_buffer, .{ .none = {} }, .{
488 .parent_atom_index = @intCast(Atom.Index, atom_idx),
488 .parent_atom_index = @as(Atom.Index, @intCast(atom_idx)),
489489 });
490490 const code = switch (res) {
491491 .ok => code_buffer.items,
......@@ -562,10 +562,10 @@ pub fn flush(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.Node) li
562562
563563pub fn changeLine(l: *std.ArrayList(u8), delta_line: i32) !void {
564564 if (delta_line > 0 and delta_line < 65) {
565 const toappend = @intCast(u8, delta_line);
565 const toappend = @as(u8, @intCast(delta_line));
566566 try l.append(toappend);
567567 } 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));
569569 try l.append(toadd);
570570 } else if (delta_line != 0) {
571571 try l.append(0);
......@@ -675,7 +675,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
675675 const out = entry.value_ptr.*;
676676 {
677677 // 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
680680 try changeLine(&linecountinfo, delta_line);
681681 // TODO change the pc too (maybe?)
......@@ -692,7 +692,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
692692 atom.offset = off;
693693 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 });
694694 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());
696696 } else {
697697 mem.writeInt(u64, got_table[atom.got_index.? * 8 ..][0..8], off, self.base.options.target.cpu.arch.endian());
698698 }
......@@ -721,7 +721,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
721721 text_i += code.len;
722722 text_atom.offset = off;
723723 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());
725725 } else {
726726 mem.writeInt(u64, got_table[text_atom.got_index.? * 8 ..][0..8], off, self.base.options.target.cpu.arch.endian());
727727 }
......@@ -749,7 +749,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
749749 data_i += code.len;
750750 atom.offset = off;
751751 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());
753753 } else {
754754 mem.writeInt(u64, got_table[atom.got_index.? * 8 ..][0..8], off, self.base.options.target.cpu.arch.endian());
755755 }
......@@ -772,7 +772,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
772772 data_i += code.len;
773773 atom.offset = off;
774774 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());
776776 } else {
777777 mem.writeInt(u64, got_table[atom.got_index.? * 8 ..][0..8], off, self.base.options.target.cpu.arch.endian());
778778 }
......@@ -792,7 +792,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
792792 data_i += code.len;
793793 data_atom.offset = off;
794794 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());
796796 } else {
797797 mem.writeInt(u64, got_table[data_atom.got_index.? * 8 ..][0..8], off, self.base.options.target.cpu.arch.endian());
798798 }
......@@ -815,13 +815,13 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
815815 // generate the header
816816 self.hdr = .{
817817 .magic = self.magic,
818 .text = @intCast(u32, text_i),
819 .data = @intCast(u32, data_i),
820 .syms = @intCast(u32, syms.len),
818 .text = @as(u32, @intCast(text_i)),
819 .data = @as(u32, @intCast(data_i)),
820 .syms = @as(u32, @intCast(syms.len)),
821821 .bss = 0,
822822 .spsz = 0,
823 .pcsz = @intCast(u32, linecountinfo.items.len),
824 .entry = @intCast(u32, self.entry_val.?),
823 .pcsz = @as(u32, @intCast(linecountinfo.items.len)),
824 .entry = @as(u32, @intCast(self.entry_val.?)),
825825 };
826826 @memcpy(hdr_slice, self.hdr.toU8s()[0..hdr_size]);
827827 // 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
847847 const code = source_atom.code.getCode(self);
848848
849849 if (reloc.pcrel) {
850 const disp = @intCast(i32, target_offset) - @intCast(i32, source_atom.offset.?) - 4 - @intCast(i32, offset);
851 mem.writeInt(i32, code[@intCast(usize, offset)..][0..4], @intCast(i32, disp), self.base.options.target.cpu.arch.endian());
850 const disp = @as(i32, @intCast(target_offset)) - @as(i32, @intCast(source_atom.offset.?)) - 4 - @as(i32, @intCast(offset));
851 mem.writeInt(i32, code[@as(usize, @intCast(offset))..][0..4], @as(i32, @intCast(disp)), self.base.options.target.cpu.arch.endian());
852852 } else {
853853 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());
855855 } 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());
857857 }
858858 }
859859 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 {
960960
961961fn createAtom(self: *Plan9) !Atom.Index {
962962 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));
964964 const atom = try self.atoms.addOne(gpa);
965965 atom.* = .{
966966 .type = .t,
......@@ -1060,7 +1060,7 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind
10601060 &required_alignment,
10611061 &code_buffer,
10621062 .none,
1063 .{ .parent_atom_index = @intCast(Atom.Index, atom_index) },
1063 .{ .parent_atom_index = @as(Atom.Index, @intCast(atom_index)) },
10641064 );
10651065 const code = switch (res) {
10661066 .ok => code_buffer.items,
......@@ -1188,7 +1188,7 @@ pub fn writeSym(self: *Plan9, w: anytype, sym: aout.Sym) !void {
11881188 // log.debug("write sym{{name: {s}, value: {x}}}", .{ sym.name, sym.value });
11891189 if (sym.type == .bad) return; // we don't want to write free'd symbols
11901190 if (!self.sixtyfour_bit) {
1191 try w.writeIntBig(u32, @intCast(u32, sym.value));
1191 try w.writeIntBig(u32, @as(u32, @intCast(sym.value)));
11921192 } else {
11931193 try w.writeIntBig(u64, sym.value);
11941194 }
src/link/Wasm.zig+138-138
......@@ -317,7 +317,7 @@ pub const StringTable = struct {
317317 }
318318
319319 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
322322 log.debug("writing new string '{s}' at offset 0x{x}", .{ string, offset });
323323
......@@ -333,7 +333,7 @@ pub const StringTable = struct {
333333 /// Asserts offset does not exceed bounds.
334334 pub fn get(table: StringTable, off: u32) []const u8 {
335335 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);
337337 }
338338
339339 /// 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
396396 // For object files we will import the stack pointer symbol
397397 if (options.output_mode == .Obj) {
398398 symbol.setUndefined(true);
399 symbol.index = @intCast(u32, wasm_bin.imported_globals_count);
399 symbol.index = @as(u32, @intCast(wasm_bin.imported_globals_count));
400400 wasm_bin.imported_globals_count += 1;
401401 try wasm_bin.imports.putNoClobber(
402402 allocator,
......@@ -408,7 +408,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
408408 },
409409 );
410410 } 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));
412412 symbol.setFlag(.WASM_SYM_VISIBILITY_HIDDEN);
413413 const global = try wasm_bin.wasm_globals.addOne(allocator);
414414 global.* = .{
......@@ -431,7 +431,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
431431 };
432432 if (options.output_mode == .Obj or options.import_table) {
433433 symbol.setUndefined(true);
434 symbol.index = @intCast(u32, wasm_bin.imported_tables_count);
434 symbol.index = @as(u32, @intCast(wasm_bin.imported_tables_count));
435435 wasm_bin.imported_tables_count += 1;
436436 try wasm_bin.imports.put(allocator, loc, .{
437437 .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
439439 .kind = .{ .table = table },
440440 });
441441 } 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));
443443 try wasm_bin.tables.append(allocator, table);
444444 if (options.export_table) {
445445 symbol.setFlag(.WASM_SYM_EXPORTED);
......@@ -519,7 +519,7 @@ fn createSyntheticSymbol(wasm: *Wasm, name: []const u8, tag: Symbol.Tag) !Symbol
519519}
520520
521521fn 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));
523523 const loc: SymbolLoc = .{ .index = sym_index, .file = null };
524524 try wasm.symbols.append(wasm.base.allocator, .{
525525 .name = name_offset,
......@@ -588,7 +588,7 @@ pub fn getOrCreateAtomForDecl(wasm: *Wasm, decl_index: Module.Decl.Index) !Atom.
588588
589589/// Creates a new empty `Atom` and returns its `Atom.Index`
590590fn 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));
592592 const atom = try wasm.managed_atoms.addOne(wasm.base.allocator);
593593 atom.* = Atom.empty;
594594 atom.sym_index = try wasm.allocateSymbol();
......@@ -669,7 +669,7 @@ fn resolveSymbolsInObject(wasm: *Wasm, object_index: u16) !void {
669669 log.debug("Resolving symbols in object: '{s}'", .{object.name});
670670
671671 for (object.symtable, 0..) |symbol, i| {
672 const sym_index = @intCast(u32, i);
672 const sym_index = @as(u32, @intCast(i));
673673 const location: SymbolLoc = .{
674674 .file = object_index,
675675 .index = sym_index,
......@@ -830,7 +830,7 @@ fn resolveSymbolsInArchives(wasm: *Wasm) !void {
830830 // Symbol is found in unparsed object file within current archive.
831831 // Parse object and and resolve symbols again before we check remaining
832832 // 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));
834834 var object = try archive.parseObject(wasm.base.allocator, offset.items[0]);
835835 try wasm.objects.append(wasm.base.allocator, object);
836836 try wasm.resolveSymbolsInObject(object_file_index);
......@@ -1046,7 +1046,7 @@ fn setupTLSRelocationsFunction(wasm: *Wasm) !void {
10461046
10471047 try writer.writeByte(std.wasm.opcode(.i32_add));
10481048 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)));
10501050 }
10511051 try writer.writeByte(std.wasm.opcode(.end));
10521052
......@@ -1091,7 +1091,7 @@ fn validateFeatures(
10911091 // linked object file so we can test them.
10921092 for (wasm.objects.items, 0..) |object, object_index| {
10931093 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);
10951095 switch (feature.prefix) {
10961096 .used => {
10971097 used[@intFromEnum(feature.tag)] = value;
......@@ -1117,12 +1117,12 @@ fn validateFeatures(
11171117 // and insert it into the 'allowed' set. When features are not inferred,
11181118 // we validate that a used feature is allowed.
11191119 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;
11211121 if (infer) {
11221122 allowed[used_index] = is_enabled;
11231123 emit_features_count.* += @intFromBool(is_enabled);
11241124 } 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))});
11261126 log.err(" defined in '{s}'", .{wasm.objects.items[used_set >> 1].name});
11271127 valid_feature_set = false;
11281128 }
......@@ -1134,7 +1134,7 @@ fn validateFeatures(
11341134
11351135 if (wasm.base.options.shared_memory) {
11361136 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) {
11381138 log.err(
11391139 "shared-memory is disallowed by '{s}' because it wasn't compiled with 'atomics' and 'bulk-memory' features enabled",
11401140 .{wasm.objects.items[disallowed_feature >> 1].name},
......@@ -1163,7 +1163,7 @@ fn validateFeatures(
11631163 if (feature.prefix == .disallowed) continue; // already defined in 'disallowed' set.
11641164 // from here a feature is always used
11651165 const disallowed_feature = disallowed[@intFromEnum(feature.tag)];
1166 if (@truncate(u1, disallowed_feature) != 0) {
1166 if (@as(u1, @truncate(disallowed_feature)) != 0) {
11671167 log.err("feature '{}' is disallowed, but used by linked object", .{feature.tag});
11681168 log.err(" disallowed by '{s}'", .{wasm.objects.items[disallowed_feature >> 1].name});
11691169 log.err(" used in '{s}'", .{object.name});
......@@ -1175,9 +1175,9 @@ fn validateFeatures(
11751175
11761176 // validate the linked object file has each required feature
11771177 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;
11791179 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))});
11811181 log.err(" required by '{s}'", .{wasm.objects.items[required_feature >> 1].name});
11821182 log.err(" missing in '{s}'", .{object.name});
11831183 valid_feature_set = false;
......@@ -1333,7 +1333,7 @@ pub fn allocateSymbol(wasm: *Wasm) !u32 {
13331333 wasm.symbols.items[index] = symbol;
13341334 return index;
13351335 }
1336 const index = @intCast(u32, wasm.symbols.items.len);
1336 const index = @as(u32, @intCast(wasm.symbols.items.len));
13371337 wasm.symbols.appendAssumeCapacity(symbol);
13381338 return index;
13391339}
......@@ -1485,7 +1485,7 @@ fn finishUpdateDecl(wasm: *Wasm, decl_index: Module.Decl.Index, code: []const u8
14851485 try atom.code.appendSlice(wasm.base.allocator, code);
14861486 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));
14891489 if (code.len == 0) return;
14901490 atom.alignment = decl.getAlignment(mod);
14911491}
......@@ -1589,7 +1589,7 @@ pub fn lowerUnnamedConst(wasm: *Wasm, tv: TypedValue, decl_index: Module.Decl.In
15891589 };
15901590
15911591 const atom = wasm.getAtomPtr(atom_index);
1592 atom.size = @intCast(u32, code.len);
1592 atom.size = @as(u32, @intCast(code.len));
15931593 try atom.code.appendSlice(wasm.base.allocator, code);
15941594 return atom.sym_index;
15951595}
......@@ -1617,7 +1617,7 @@ pub fn getGlobalSymbol(wasm: *Wasm, name: []const u8, lib_name: ?[]const u8) !u3
16171617 symbol.setUndefined(true);
16181618
16191619 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));
16211621 try wasm.symbols.ensureUnusedCapacity(wasm.base.allocator, 1);
16221622 wasm.symbols.items.len += 1;
16231623 break :blk index;
......@@ -1654,15 +1654,15 @@ pub fn getDeclVAddr(
16541654 try wasm.addTableFunction(target_symbol_index);
16551655 try atom.relocs.append(wasm.base.allocator, .{
16561656 .index = target_symbol_index,
1657 .offset = @intCast(u32, reloc_info.offset),
1657 .offset = @as(u32, @intCast(reloc_info.offset)),
16581658 .relocation_type = if (is_wasm32) .R_WASM_TABLE_INDEX_I32 else .R_WASM_TABLE_INDEX_I64,
16591659 });
16601660 } else {
16611661 try atom.relocs.append(wasm.base.allocator, .{
16621662 .index = target_symbol_index,
1663 .offset = @intCast(u32, reloc_info.offset),
1663 .offset = @as(u32, @intCast(reloc_info.offset)),
16641664 .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)),
16661666 });
16671667 }
16681668 // 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 {
18401840
18411841/// Appends a new entry to the indirect function table
18421842pub 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()));
18441844 try wasm.function_table.put(wasm.base.allocator, .{ .file = null, .index = symbol_index }, index);
18451845}
18461846
......@@ -1971,7 +1971,7 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {
19711971 const symbol = (SymbolLoc{ .file = null, .index = atom.sym_index }).getSymbol(wasm);
19721972 const final_index: u32 = switch (kind) {
19731973 .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));
19751975 const type_index = wasm.atom_types.get(atom_index).?;
19761976 try wasm.functions.putNoClobber(
19771977 wasm.base.allocator,
......@@ -1982,7 +1982,7 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {
19821982 symbol.index = index;
19831983
19841984 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));
19861986 try wasm.segments.append(wasm.base.allocator, .{
19871987 .alignment = atom.alignment,
19881988 .size = atom.size,
......@@ -2020,12 +2020,12 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {
20202020 const index = gop.value_ptr.*;
20212021 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).?));
20242024 // segment info already exists, so free its memory
20252025 wasm.base.allocator.free(segment_name);
20262026 break :result index;
20272027 } else {
2028 const index = @intCast(u32, wasm.segments.items.len);
2028 const index = @as(u32, @intCast(wasm.segments.items.len));
20292029 var flags: u32 = 0;
20302030 if (wasm.base.options.shared_memory) {
20312031 flags |= @intFromEnum(Segment.Flag.WASM_DATA_SEGMENT_IS_PASSIVE);
......@@ -2038,7 +2038,7 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {
20382038 });
20392039 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()));
20422042 try wasm.segment_info.put(wasm.base.allocator, index, segment_info);
20432043 symbol.index = info_index;
20442044 break :result index;
......@@ -2074,13 +2074,13 @@ fn allocateDebugAtoms(wasm: *Wasm) !void {
20742074 const allocAtom = struct {
20752075 fn f(bin: *Wasm, maybe_index: *?u32, atom_index: Atom.Index) !void {
20762076 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));
20782078 try bin.appendDummySegment();
20792079 maybe_index.* = index;
20802080 break :idx index;
20812081 };
20822082 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));
20842084 bin.symbols.items[atom.sym_index].index = index;
20852085 try bin.appendAtomAtIndex(index, atom_index);
20862086 }
......@@ -2215,7 +2215,7 @@ fn setupInitFunctions(wasm: *Wasm) !void {
22152215 log.debug("appended init func '{s}'\n", .{object.string_table.get(symbol.name)});
22162216 wasm.init_funcs.appendAssumeCapacity(.{
22172217 .index = init_func.symbol_index,
2218 .file = @intCast(u16, file_index),
2218 .file = @as(u16, @intCast(file_index)),
22192219 .priority = init_func.priority,
22202220 });
22212221 }
......@@ -2248,7 +2248,7 @@ fn setupErrorsLen(wasm: *Wasm) !void {
22482248 atom.deinit(wasm);
22492249 break :blk index;
22502250 } 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));
22522252 try wasm.symbol_atom.put(wasm.base.allocator, loc, atom_index);
22532253 try wasm.managed_atoms.append(wasm.base.allocator, undefined);
22542254 break :new_atom atom_index;
......@@ -2257,7 +2257,7 @@ fn setupErrorsLen(wasm: *Wasm) !void {
22572257 atom.* = Atom.empty;
22582258 atom.sym_index = loc.index;
22592259 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
22622262 try wasm.parseAtom(atom_index, .{ .data = .read_only });
22632263}
......@@ -2325,7 +2325,7 @@ fn createSyntheticFunction(
23252325 const symbol = loc.getSymbol(wasm);
23262326 const ty_index = try wasm.putOrGetFuncType(func_ty);
23272327 // 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()));
23292329 try wasm.functions.putNoClobber(
23302330 wasm.base.allocator,
23312331 .{ .file = null, .index = func_index },
......@@ -2334,10 +2334,10 @@ fn createSyntheticFunction(
23342334 symbol.index = func_index;
23352335
23362336 // 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));
23382338 const atom = try wasm.managed_atoms.addOne(wasm.base.allocator);
23392339 atom.* = .{
2340 .size = @intCast(u32, function_body.items.len),
2340 .size = @as(u32, @intCast(function_body.items.len)),
23412341 .offset = 0,
23422342 .sym_index = loc.index,
23432343 .file = null,
......@@ -2369,10 +2369,10 @@ pub fn createFunction(
23692369) !u32 {
23702370 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));
23732373 const atom = try wasm.managed_atoms.addOne(wasm.base.allocator);
23742374 atom.* = .{
2375 .size = @intCast(u32, function_body.items.len),
2375 .size = @as(u32, @intCast(function_body.items.len)),
23762376 .offset = 0,
23772377 .sym_index = loc.index,
23782378 .file = null,
......@@ -2386,7 +2386,7 @@ pub fn createFunction(
23862386 symbol.setFlag(.WASM_SYM_VISIBILITY_HIDDEN); // ensure function does not get exported
23872387
23882388 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));
23902390 try wasm.appendDummySegment();
23912391 break :idx index;
23922392 };
......@@ -2438,7 +2438,7 @@ fn initializeTLSFunction(wasm: *Wasm) !void {
24382438 try writer.writeByte(std.wasm.opcode(.misc_prefix));
24392439 try leb.writeULEB128(writer, std.wasm.miscOpcode(.memory_init));
24402440 // segment immediate
2441 try leb.writeULEB128(writer, @intCast(u32, data_index));
2441 try leb.writeULEB128(writer, @as(u32, @intCast(data_index)));
24422442 // memory index immediate (always 0)
24432443 try leb.writeULEB128(writer, @as(u32, 0));
24442444 }
......@@ -2567,16 +2567,16 @@ fn mergeSections(wasm: *Wasm) !void {
25672567 if (!gop.found_existing) {
25682568 gop.value_ptr.* = object.functions[index];
25692569 }
2570 symbol.index = @intCast(u32, gop.index) + wasm.imported_functions_count;
2570 symbol.index = @as(u32, @intCast(gop.index)) + wasm.imported_functions_count;
25712571 },
25722572 .global => {
25732573 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;
25752575 try wasm.wasm_globals.append(wasm.base.allocator, original_global);
25762576 },
25772577 .table => {
25782578 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;
25802580 try wasm.tables.append(wasm.base.allocator, original_table);
25812581 },
25822582 else => unreachable,
......@@ -2596,7 +2596,7 @@ fn mergeTypes(wasm: *Wasm) !void {
25962596 // type inserted. If we do this for the same function multiple times,
25972597 // it will be overwritten with the incorrect type.
25982598 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())));
26002600 defer dirty.deinit();
26012601
26022602 for (wasm.resolved_symbols.keys()) |sym_loc| {
......@@ -2660,10 +2660,10 @@ fn setupExports(wasm: *Wasm) !void {
26602660 break :blk try wasm.string_table.put(wasm.base.allocator, sym_name);
26612661 };
26622662 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));
26642664 try wasm.wasm_globals.append(wasm.base.allocator, .{
26652665 .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)) },
26672667 });
26682668 break :exp .{
26692669 .name = export_name,
......@@ -2734,10 +2734,10 @@ fn setupMemory(wasm: *Wasm) !void {
27342734 memory_ptr = std.mem.alignForward(u64, memory_ptr, stack_alignment);
27352735 memory_ptr += stack_size;
27362736 // 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))));
27382738 }
27392739
2740 var offset: u32 = @intCast(u32, memory_ptr);
2740 var offset: u32 = @as(u32, @intCast(memory_ptr));
27412741 var data_seg_it = wasm.data_segments.iterator();
27422742 while (data_seg_it.next()) |entry| {
27432743 const segment = &wasm.segments.items[entry.value_ptr.*];
......@@ -2747,26 +2747,26 @@ fn setupMemory(wasm: *Wasm) !void {
27472747 if (mem.eql(u8, entry.key_ptr.*, ".tdata")) {
27482748 if (wasm.findGlobalSymbol("__tls_size")) |loc| {
27492749 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;
27512751 try wasm.wasm_globals.append(wasm.base.allocator, .{
27522752 .global_type = .{ .valtype = .i32, .mutable = false },
2753 .init = .{ .i32_const = @intCast(i32, segment.size) },
2753 .init = .{ .i32_const = @as(i32, @intCast(segment.size)) },
27542754 });
27552755 }
27562756 if (wasm.findGlobalSymbol("__tls_align")) |loc| {
27572757 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;
27592759 try wasm.wasm_globals.append(wasm.base.allocator, .{
27602760 .global_type = .{ .valtype = .i32, .mutable = false },
2761 .init = .{ .i32_const = @intCast(i32, segment.alignment) },
2761 .init = .{ .i32_const = @as(i32, @intCast(segment.alignment)) },
27622762 });
27632763 }
27642764 if (wasm.findGlobalSymbol("__tls_base")) |loc| {
27652765 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;
27672767 try wasm.wasm_globals.append(wasm.base.allocator, .{
27682768 .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)) },
27702770 });
27712771 }
27722772 }
......@@ -2782,21 +2782,21 @@ fn setupMemory(wasm: *Wasm) !void {
27822782 memory_ptr = mem.alignForward(u64, memory_ptr, 4);
27832783 const loc = try wasm.createSyntheticSymbol("__wasm_init_memory_flag", .data);
27842784 const sym = loc.getSymbol(wasm);
2785 sym.virtual_address = @intCast(u32, memory_ptr);
2785 sym.virtual_address = @as(u32, @intCast(memory_ptr));
27862786 memory_ptr += 4;
27872787 }
27882788
27892789 if (!place_stack_first and !is_obj) {
27902790 memory_ptr = std.mem.alignForward(u64, memory_ptr, stack_alignment);
27912791 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))));
27932793 }
27942794
27952795 // One of the linked object files has a reference to the __heap_base symbol.
27962796 // We must set its virtual address so it can be used in relocations.
27972797 if (wasm.findGlobalSymbol("__heap_base")) |loc| {
27982798 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)));
28002800 }
28012801
28022802 // Setup the max amount of pages
......@@ -2821,12 +2821,12 @@ fn setupMemory(wasm: *Wasm) !void {
28212821 memory_ptr = mem.alignForward(u64, memory_ptr, std.wasm.page_size);
28222822 // In case we do not import memory, but define it ourselves,
28232823 // 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));
28252825 log.debug("Total memory pages: {d}", .{wasm.memories.limits.min});
28262826
28272827 if (wasm.findGlobalSymbol("__heap_end")) |loc| {
28282828 const symbol = loc.getSymbol(wasm);
2829 symbol.virtual_address = @intCast(u32, memory_ptr);
2829 symbol.virtual_address = @as(u32, @intCast(memory_ptr));
28302830 }
28312831
28322832 if (wasm.base.options.max_memory) |max_memory| {
......@@ -2842,7 +2842,7 @@ fn setupMemory(wasm: *Wasm) !void {
28422842 log.err("Maximum memory exceeds maxmium amount {d}", .{max_memory_allowed});
28432843 return error.MemoryTooBig;
28442844 }
2845 wasm.memories.limits.max = @intCast(u32, max_memory / page_size);
2845 wasm.memories.limits.max = @as(u32, @intCast(max_memory / page_size));
28462846 wasm.memories.limits.setFlag(.WASM_LIMITS_FLAG_HAS_MAX);
28472847 if (wasm.base.options.shared_memory) {
28482848 wasm.memories.limits.setFlag(.WASM_LIMITS_FLAG_IS_SHARED);
......@@ -2857,7 +2857,7 @@ fn setupMemory(wasm: *Wasm) !void {
28572857pub fn getMatchingSegment(wasm: *Wasm, object_index: u16, relocatable_index: u32) !?u32 {
28582858 const object: Object = wasm.objects.items[object_index];
28592859 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
28622862 switch (relocatable_data.type) {
28632863 .data => {
......@@ -3023,10 +3023,10 @@ fn populateErrorNameTable(wasm: *Wasm) !void {
30233023 const mod = wasm.base.options.module.?;
30243024 for (mod.global_error_set.keys()) |error_name_nts| {
30253025 const error_name = mod.intern_pool.stringToSlice(error_name_nts);
3026 const len = @intCast(u32, error_name.len + 1); // names are 0-termianted
3026 const len = @as(u32, @intCast(error_name.len + 1)); // names are 0-termianted
30273027
30283028 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));
30303030 // first we create the data for the slice of the name
30313031 try atom.code.appendNTimes(wasm.base.allocator, 0, 4); // ptr to name, will be relocated
30323032 try atom.code.writer(wasm.base.allocator).writeIntLittle(u32, len - 1);
......@@ -3035,9 +3035,9 @@ fn populateErrorNameTable(wasm: *Wasm) !void {
30353035 .index = names_atom.sym_index,
30363036 .relocation_type = .R_WASM_MEMORY_ADDR_I32,
30373037 .offset = offset,
3038 .addend = @intCast(i32, addend),
3038 .addend = @as(i32, @intCast(addend)),
30393039 });
3040 atom.size += @intCast(u32, slice_ty.abiSize(mod));
3040 atom.size += @as(u32, @intCast(slice_ty.abiSize(mod)));
30413041 addend += len;
30423042
30433043 // 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 {
30633063/// This initializes the index, appends a new segment,
30643064/// and finally, creates a managed `Atom`.
30653065pub 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));
30673067 index.* = new_index;
30683068 try wasm.appendDummySegment();
30693069
......@@ -3294,7 +3294,7 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
32943294 try wasm.parseInputFiles(positionals.items);
32953295
32963296 for (wasm.objects.items, 0..) |_, object_index| {
3297 try wasm.resolveSymbolsInObject(@intCast(u16, object_index));
3297 try wasm.resolveSymbolsInObject(@as(u16, @intCast(object_index)));
32983298 }
32993299
33003300 var emit_features_count: u32 = 0;
......@@ -3309,7 +3309,7 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
33093309 try wasm.setupImports();
33103310
33113311 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);
33133313 }
33143314
33153315 try wasm.allocateAtoms();
......@@ -3382,7 +3382,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
33823382 try wasm.parseInputFiles(positionals.items);
33833383
33843384 for (wasm.objects.items, 0..) |_, object_index| {
3385 try wasm.resolveSymbolsInObject(@intCast(u16, object_index));
3385 try wasm.resolveSymbolsInObject(@as(u16, @intCast(object_index)));
33863386 }
33873387
33883388 var emit_features_count: u32 = 0;
......@@ -3446,7 +3446,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
34463446 }
34473447
34483448 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);
34503450 }
34513451
34523452 try wasm.allocateAtoms();
......@@ -3497,11 +3497,11 @@ fn writeToFile(
34973497 log.debug("Writing type section. Count: ({d})", .{wasm.func_types.items.len});
34983498 for (wasm.func_types.items) |func_type| {
34993499 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)));
35013501 for (func_type.params) |param_ty| {
35023502 try leb.writeULEB128(binary_writer, std.wasm.valtype(param_ty));
35033503 }
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)));
35053505 for (func_type.returns) |ret_ty| {
35063506 try leb.writeULEB128(binary_writer, std.wasm.valtype(ret_ty));
35073507 }
......@@ -3511,8 +3511,8 @@ fn writeToFile(
35113511 binary_bytes.items,
35123512 header_offset,
35133513 .type,
3514 @intCast(u32, binary_bytes.items.len - header_offset - header_size),
3515 @intCast(u32, wasm.func_types.items.len),
3514 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3515 @as(u32, @intCast(wasm.func_types.items.len)),
35163516 );
35173517 section_count += 1;
35183518 }
......@@ -3543,8 +3543,8 @@ fn writeToFile(
35433543 binary_bytes.items,
35443544 header_offset,
35453545 .import,
3546 @intCast(u32, binary_bytes.items.len - header_offset - header_size),
3547 @intCast(u32, wasm.imports.count() + @intFromBool(import_memory)),
3546 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3547 @as(u32, @intCast(wasm.imports.count() + @intFromBool(import_memory))),
35483548 );
35493549 section_count += 1;
35503550 }
......@@ -3560,8 +3560,8 @@ fn writeToFile(
35603560 binary_bytes.items,
35613561 header_offset,
35623562 .function,
3563 @intCast(u32, binary_bytes.items.len - header_offset - header_size),
3564 @intCast(u32, wasm.functions.count()),
3563 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3564 @as(u32, @intCast(wasm.functions.count())),
35653565 );
35663566 section_count += 1;
35673567 }
......@@ -3579,8 +3579,8 @@ fn writeToFile(
35793579 binary_bytes.items,
35803580 header_offset,
35813581 .table,
3582 @intCast(u32, binary_bytes.items.len - header_offset - header_size),
3583 @intCast(u32, wasm.tables.items.len),
3582 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3583 @as(u32, @intCast(wasm.tables.items.len)),
35843584 );
35853585 section_count += 1;
35863586 }
......@@ -3594,7 +3594,7 @@ fn writeToFile(
35943594 binary_bytes.items,
35953595 header_offset,
35963596 .memory,
3597 @intCast(u32, binary_bytes.items.len - header_offset - header_size),
3597 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
35983598 @as(u32, 1), // wasm currently only supports 1 linear memory segment
35993599 );
36003600 section_count += 1;
......@@ -3614,8 +3614,8 @@ fn writeToFile(
36143614 binary_bytes.items,
36153615 header_offset,
36163616 .global,
3617 @intCast(u32, binary_bytes.items.len - header_offset - header_size),
3618 @intCast(u32, wasm.wasm_globals.items.len),
3617 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3618 @as(u32, @intCast(wasm.wasm_globals.items.len)),
36193619 );
36203620 section_count += 1;
36213621 }
......@@ -3626,14 +3626,14 @@ fn writeToFile(
36263626
36273627 for (wasm.exports.items) |exp| {
36283628 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)));
36303630 try binary_writer.writeAll(name);
36313631 try leb.writeULEB128(binary_writer, @intFromEnum(exp.kind));
36323632 try leb.writeULEB128(binary_writer, exp.index);
36333633 }
36343634
36353635 if (!import_memory) {
3636 try leb.writeULEB128(binary_writer, @intCast(u32, "memory".len));
3636 try leb.writeULEB128(binary_writer, @as(u32, @intCast("memory".len)));
36373637 try binary_writer.writeAll("memory");
36383638 try binary_writer.writeByte(std.wasm.externalKind(.memory));
36393639 try leb.writeULEB128(binary_writer, @as(u32, 0));
......@@ -3643,8 +3643,8 @@ fn writeToFile(
36433643 binary_bytes.items,
36443644 header_offset,
36453645 .@"export",
3646 @intCast(u32, binary_bytes.items.len - header_offset - header_size),
3647 @intCast(u32, wasm.exports.items.len) + @intFromBool(!import_memory),
3646 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3647 @as(u32, @intCast(wasm.exports.items.len)) + @intFromBool(!import_memory),
36483648 );
36493649 section_count += 1;
36503650 }
......@@ -3665,7 +3665,7 @@ fn writeToFile(
36653665 if (flags == 0x02) {
36663666 try leb.writeULEB128(binary_writer, @as(u8, 0)); // represents funcref
36673667 }
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())));
36693669 var symbol_it = wasm.function_table.keyIterator();
36703670 while (symbol_it.next()) |symbol_loc_ptr| {
36713671 try leb.writeULEB128(binary_writer, symbol_loc_ptr.*.getSymbol(wasm).index);
......@@ -3675,7 +3675,7 @@ fn writeToFile(
36753675 binary_bytes.items,
36763676 header_offset,
36773677 .element,
3678 @intCast(u32, binary_bytes.items.len - header_offset - header_size),
3678 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
36793679 @as(u32, 1),
36803680 );
36813681 section_count += 1;
......@@ -3689,8 +3689,8 @@ fn writeToFile(
36893689 binary_bytes.items,
36903690 header_offset,
36913691 .data_count,
3692 @intCast(u32, binary_bytes.items.len - header_offset - header_size),
3693 @intCast(u32, data_segments_count),
3692 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3693 @as(u32, @intCast(data_segments_count)),
36943694 );
36953695 }
36963696
......@@ -3731,13 +3731,13 @@ fn writeToFile(
37313731 try binary_writer.writeAll(sorted_atom.code.items);
37323732 }
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));
37353735 try writeVecSectionHeader(
37363736 binary_bytes.items,
37373737 header_offset,
37383738 .code,
37393739 code_section_size,
3740 @intCast(u32, wasm.functions.count()),
3740 @as(u32, @intCast(wasm.functions.count())),
37413741 );
37423742 code_section_index = section_count;
37433743 section_count += 1;
......@@ -3765,7 +3765,7 @@ fn writeToFile(
37653765 }
37663766 // when a segment is passive, it's initialized during runtime.
37673767 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)) });
37693769 }
37703770 // offset into data section
37713771 try leb.writeULEB128(binary_writer, segment.size);
......@@ -3808,8 +3808,8 @@ fn writeToFile(
38083808 binary_bytes.items,
38093809 header_offset,
38103810 .data,
3811 @intCast(u32, binary_bytes.items.len - header_offset - header_size),
3812 @intCast(u32, segment_count),
3811 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3812 @as(u32, @intCast(segment_count)),
38133813 );
38143814 data_section_index = section_count;
38153815 section_count += 1;
......@@ -3927,7 +3927,7 @@ fn emitDebugSection(binary_bytes: *std.ArrayList(u8), data: []const u8, name: []
39273927 if (data.len == 0) return;
39283928 const header_offset = try reserveCustomSectionHeader(binary_bytes);
39293929 const writer = binary_bytes.writer();
3930 try leb.writeULEB128(writer, @intCast(u32, name.len));
3930 try leb.writeULEB128(writer, @as(u32, @intCast(name.len)));
39313931 try writer.writeAll(name);
39323932
39333933 const start = binary_bytes.items.len - header_offset;
......@@ -3937,7 +3937,7 @@ fn emitDebugSection(binary_bytes: *std.ArrayList(u8), data: []const u8, name: []
39373937 try writeCustomSectionHeader(
39383938 binary_bytes.items,
39393939 header_offset,
3940 @intCast(u32, binary_bytes.items.len - header_offset - 6),
3940 @as(u32, @intCast(binary_bytes.items.len - header_offset - 6)),
39413941 );
39423942}
39433943
......@@ -3946,7 +3946,7 @@ fn emitProducerSection(binary_bytes: *std.ArrayList(u8)) !void {
39463946
39473947 const writer = binary_bytes.writer();
39483948 const producers = "producers";
3949 try leb.writeULEB128(writer, @intCast(u32, producers.len));
3949 try leb.writeULEB128(writer, @as(u32, @intCast(producers.len)));
39503950 try writer.writeAll(producers);
39513951
39523952 try leb.writeULEB128(writer, @as(u32, 2)); // 2 fields: Language + processed-by
......@@ -3958,7 +3958,7 @@ fn emitProducerSection(binary_bytes: *std.ArrayList(u8)) !void {
39583958 // language field
39593959 {
39603960 const language = "language";
3961 try leb.writeULEB128(writer, @intCast(u32, language.len));
3961 try leb.writeULEB128(writer, @as(u32, @intCast(language.len)));
39623962 try writer.writeAll(language);
39633963
39643964 // 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 {
39693969 try leb.writeULEB128(writer, @as(u32, 3)); // len of "Zig"
39703970 try writer.writeAll("Zig");
39713971
3972 try leb.writeULEB128(writer, @intCast(u32, version.len));
3972 try leb.writeULEB128(writer, @as(u32, @intCast(version.len)));
39733973 try writer.writeAll(version);
39743974 }
39753975 }
......@@ -3977,7 +3977,7 @@ fn emitProducerSection(binary_bytes: *std.ArrayList(u8)) !void {
39773977 // processed-by field
39783978 {
39793979 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)));
39813981 try writer.writeAll(processed_by);
39823982
39833983 // 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 {
39883988 try leb.writeULEB128(writer, @as(u32, 3)); // len of "Zig"
39893989 try writer.writeAll("Zig");
39903990
3991 try leb.writeULEB128(writer, @intCast(u32, version.len));
3991 try leb.writeULEB128(writer, @as(u32, @intCast(version.len)));
39923992 try writer.writeAll(version);
39933993 }
39943994 }
......@@ -3996,7 +3996,7 @@ fn emitProducerSection(binary_bytes: *std.ArrayList(u8)) !void {
39963996 try writeCustomSectionHeader(
39973997 binary_bytes.items,
39983998 header_offset,
3999 @intCast(u32, binary_bytes.items.len - header_offset - 6),
3999 @as(u32, @intCast(binary_bytes.items.len - header_offset - 6)),
40004000 );
40014001}
40024002
......@@ -4005,17 +4005,17 @@ fn emitBuildIdSection(binary_bytes: *std.ArrayList(u8), build_id: []const u8) !v
40054005
40064006 const writer = binary_bytes.writer();
40074007 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)));
40094009 try writer.writeAll(hdr_build_id);
40104010
40114011 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)));
40134013 try writer.writeAll(build_id);
40144014
40154015 try writeCustomSectionHeader(
40164016 binary_bytes.items,
40174017 header_offset,
4018 @intCast(u32, binary_bytes.items.len - header_offset - 6),
4018 @as(u32, @intCast(binary_bytes.items.len - header_offset - 6)),
40194019 );
40204020}
40214021
......@@ -4024,17 +4024,17 @@ fn emitFeaturesSection(binary_bytes: *std.ArrayList(u8), enabled_features: []con
40244024
40254025 const writer = binary_bytes.writer();
40264026 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)));
40284028 try writer.writeAll(target_features);
40294029
40304030 try leb.writeULEB128(writer, features_count);
40314031 for (enabled_features, 0..) |enabled, feature_index| {
40324032 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)) };
40344034 try leb.writeULEB128(writer, @intFromEnum(feature.prefix));
40354035 var buf: [100]u8 = undefined;
40364036 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)));
40384038 try writer.writeAll(string);
40394039 }
40404040 }
......@@ -4042,7 +4042,7 @@ fn emitFeaturesSection(binary_bytes: *std.ArrayList(u8), enabled_features: []con
40424042 try writeCustomSectionHeader(
40434043 binary_bytes.items,
40444044 header_offset,
4045 @intCast(u32, binary_bytes.items.len - header_offset - 6),
4045 @as(u32, @intCast(binary_bytes.items.len - header_offset - 6)),
40464046 );
40474047}
40484048
......@@ -4092,7 +4092,7 @@ fn emitNameSection(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), arena: std.mem
40924092
40934093 const header_offset = try reserveCustomSectionHeader(binary_bytes);
40944094 const writer = binary_bytes.writer();
4095 try leb.writeULEB128(writer, @intCast(u32, "name".len));
4095 try leb.writeULEB128(writer, @as(u32, @intCast("name".len)));
40964096 try writer.writeAll("name");
40974097
40984098 try wasm.emitNameSubsection(.function, funcs.values(), writer);
......@@ -4102,7 +4102,7 @@ fn emitNameSection(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), arena: std.mem
41024102 try writeCustomSectionHeader(
41034103 binary_bytes.items,
41044104 header_offset,
4105 @intCast(u32, binary_bytes.items.len - header_offset - 6),
4105 @as(u32, @intCast(binary_bytes.items.len - header_offset - 6)),
41064106 );
41074107}
41084108
......@@ -4112,17 +4112,17 @@ fn emitNameSubsection(wasm: *Wasm, section_id: std.wasm.NameSubsection, names: a
41124112 defer section_list.deinit();
41134113 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)));
41164116 for (names) |name| {
41174117 log.debug("Emit symbol '{s}' type({s})", .{ name.name, @tagName(section_id) });
41184118 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)));
41204120 try sub_writer.writeAll(name.name);
41214121 }
41224122
41234123 // From now, write to the actual writer
41244124 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)));
41264126 try writer.writeAll(section_list.items);
41274127}
41284128
......@@ -4146,11 +4146,11 @@ fn emitInit(writer: anytype, init_expr: std.wasm.InitExpression) !void {
41464146 },
41474147 .f32_const => |val| {
41484148 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)));
41504150 },
41514151 .f64_const => |val| {
41524152 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)));
41544154 },
41554155 .global_get => |val| {
41564156 try writer.writeByte(std.wasm.opcode(.global_get));
......@@ -4162,11 +4162,11 @@ fn emitInit(writer: anytype, init_expr: std.wasm.InitExpression) !void {
41624162
41634163fn emitImport(wasm: *Wasm, writer: anytype, import: types.Import) !void {
41644164 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)));
41664166 try writer.writeAll(module_name);
41674167
41684168 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)));
41704170 try writer.writeAll(name);
41714171
41724172 try writer.writeByte(@intFromEnum(import.kind));
......@@ -4594,7 +4594,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
45944594fn reserveVecSectionHeader(bytes: *std.ArrayList(u8)) !u32 {
45954595 // section id + fixed leb contents size + fixed leb vector length
45964596 const header_size = 1 + 5 + 5;
4597 const offset = @intCast(u32, bytes.items.len);
4597 const offset = @as(u32, @intCast(bytes.items.len));
45984598 try bytes.appendSlice(&[_]u8{0} ** header_size);
45994599 return offset;
46004600}
......@@ -4602,7 +4602,7 @@ fn reserveVecSectionHeader(bytes: *std.ArrayList(u8)) !u32 {
46024602fn reserveCustomSectionHeader(bytes: *std.ArrayList(u8)) !u32 {
46034603 // unlike regular section, we don't emit the count
46044604 const header_size = 1 + 5;
4605 const offset = @intCast(u32, bytes.items.len);
4605 const offset = @as(u32, @intCast(bytes.items.len));
46064606 try bytes.appendSlice(&[_]u8{0} ** header_size);
46074607 return offset;
46084608}
......@@ -4638,7 +4638,7 @@ fn emitLinkSection(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), symbol_table:
46384638 try wasm.emitSymbolTable(binary_bytes, symbol_table);
46394639 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));
46424642 try writeCustomSectionHeader(binary_bytes.items, offset, size);
46434643}
46444644
......@@ -4661,7 +4661,7 @@ fn emitSymbolTable(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), symbol_table:
46614661 const sym_name = if (wasm.export_names.get(sym_loc)) |exp_name| wasm.string_table.get(exp_name) else sym_loc.getName(wasm);
46624662 switch (symbol.tag) {
46634663 .data => {
4664 try leb.writeULEB128(writer, @intCast(u32, sym_name.len));
4664 try leb.writeULEB128(writer, @as(u32, @intCast(sym_name.len)));
46654665 try writer.writeAll(sym_name);
46664666
46674667 if (symbol.isDefined()) {
......@@ -4678,7 +4678,7 @@ fn emitSymbolTable(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), symbol_table:
46784678 else => {
46794679 try leb.writeULEB128(writer, symbol.index);
46804680 if (symbol.isDefined()) {
4681 try leb.writeULEB128(writer, @intCast(u32, sym_name.len));
4681 try leb.writeULEB128(writer, @as(u32, @intCast(sym_name.len)));
46824682 try writer.writeAll(sym_name);
46834683 }
46844684 },
......@@ -4686,7 +4686,7 @@ fn emitSymbolTable(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), symbol_table:
46864686 }
46874687
46884688 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)));
46904690 leb.writeUnsignedFixed(5, buf[5..], symbol_count);
46914691 try binary_bytes.insertSlice(table_offset, &buf);
46924692}
......@@ -4696,28 +4696,28 @@ fn emitSegmentInfo(wasm: *Wasm, binary_bytes: *std.ArrayList(u8)) !void {
46964696 try leb.writeULEB128(writer, @intFromEnum(types.SubsectionType.WASM_SEGMENT_INFO));
46974697 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())));
47004700 for (wasm.segment_info.values()) |segment_info| {
47014701 log.debug("Emit segment: {s} align({d}) flags({b})", .{
47024702 segment_info.name,
47034703 @ctz(segment_info.alignment),
47044704 segment_info.flags,
47054705 });
4706 try leb.writeULEB128(writer, @intCast(u32, segment_info.name.len));
4706 try leb.writeULEB128(writer, @as(u32, @intCast(segment_info.name.len)));
47074707 try writer.writeAll(segment_info.name);
47084708 try leb.writeULEB128(writer, @ctz(segment_info.alignment));
47094709 try leb.writeULEB128(writer, segment_info.flags);
47104710 }
47114711
47124712 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)));
47144714 try binary_bytes.insertSlice(segment_offset, &buf);
47154715}
47164716
47174717pub fn getULEB128Size(uint_value: anytype) u32 {
47184718 const T = @TypeOf(uint_value);
47194719 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
47224722 var size: u32 = 0;
47234723 while (value != 0) : (size += 1) {
......@@ -4739,7 +4739,7 @@ fn emitCodeRelocations(
47394739
47404740 // write custom section information
47414741 const name = "reloc.CODE";
4742 try leb.writeULEB128(writer, @intCast(u32, name.len));
4742 try leb.writeULEB128(writer, @as(u32, @intCast(name.len)));
47434743 try writer.writeAll(name);
47444744 try leb.writeULEB128(writer, section_index);
47454745 const reloc_start = binary_bytes.items.len;
......@@ -4769,7 +4769,7 @@ fn emitCodeRelocations(
47694769 var buf: [5]u8 = undefined;
47704770 leb.writeUnsignedFixed(5, &buf, count);
47714771 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));
47734773 try writeCustomSectionHeader(binary_bytes.items, header_offset, size);
47744774}
47754775
......@@ -4785,7 +4785,7 @@ fn emitDataRelocations(
47854785
47864786 // write custom section information
47874787 const name = "reloc.DATA";
4788 try leb.writeULEB128(writer, @intCast(u32, name.len));
4788 try leb.writeULEB128(writer, @as(u32, @intCast(name.len)));
47894789 try writer.writeAll(name);
47904790 try leb.writeULEB128(writer, section_index);
47914791 const reloc_start = binary_bytes.items.len;
......@@ -4821,7 +4821,7 @@ fn emitDataRelocations(
48214821 var buf: [5]u8 = undefined;
48224822 leb.writeUnsignedFixed(5, &buf, count);
48234823 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));
48254825 try writeCustomSectionHeader(binary_bytes.items, header_offset, size);
48264826}
48274827
......@@ -4852,7 +4852,7 @@ pub fn putOrGetFuncType(wasm: *Wasm, func_type: std.wasm.Type) !u32 {
48524852 }
48534853
48544854 // 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));
48564856 const params = try wasm.base.allocator.dupe(std.wasm.Valtype, func_type.params);
48574857 errdefer wasm.base.allocator.free(params);
48584858 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 {
114114 .R_WASM_GLOBAL_INDEX_I32,
115115 .R_WASM_MEMORY_ADDR_I32,
116116 .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))),
118118 .R_WASM_TABLE_INDEX_I64,
119119 .R_WASM_MEMORY_ADDR_I64,
120120 => 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 {
127127 .R_WASM_TABLE_NUMBER_LEB,
128128 .R_WASM_TYPE_INDEX_LEB,
129129 .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))),
131131 .R_WASM_MEMORY_ADDR_LEB64,
132132 .R_WASM_MEMORY_ADDR_SLEB64,
133133 .R_WASM_TABLE_INDEX_SLEB64,
......@@ -173,24 +173,24 @@ fn relocationValue(atom: Atom, relocation: types.Relocation, wasm_bin: *const Wa
173173 if (symbol.isUndefined()) {
174174 return 0;
175175 }
176 const va = @intCast(i64, symbol.virtual_address);
177 return @intCast(u32, va + relocation.addend);
176 const va = @as(i64, @intCast(symbol.virtual_address));
177 return @as(u32, @intCast(va + relocation.addend));
178178 },
179179 .R_WASM_EVENT_INDEX_LEB => return symbol.index,
180180 .R_WASM_SECTION_OFFSET_I32 => {
181181 const target_atom_index = wasm_bin.symbol_atom.get(target_loc).?;
182182 const target_atom = wasm_bin.getAtom(target_atom_index);
183 const rel_value = @intCast(i32, target_atom.offset) + relocation.addend;
184 return @intCast(u32, rel_value);
183 const rel_value = @as(i32, @intCast(target_atom.offset)) + relocation.addend;
184 return @as(u32, @intCast(rel_value));
185185 },
186186 .R_WASM_FUNCTION_OFFSET_I32 => {
187187 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)));
189189 };
190190 const target_atom = wasm_bin.getAtom(target_atom_index);
191191 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;
193 return @intCast(u32, rel_value);
192 const rel_value = @as(i32, @intCast(target_atom.offset + offset)) + relocation.addend;
193 return @as(u32, @intCast(rel_value));
194194 },
195195 .R_WASM_MEMORY_ADDR_TLS_SLEB,
196196 .R_WASM_MEMORY_ADDR_TLS_SLEB64,
src/link/Wasm/Object.zig+16-16
......@@ -93,7 +93,7 @@ const RelocatableData = struct {
9393 const data_alignment = object.segment_info[relocatable_data.index].alignment;
9494 if (data_alignment == 0) return 1;
9595 // 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));
9797 }
9898
9999 /// 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
130130 const size = maybe_max_size orelse size: {
131131 errdefer gpa.free(object.name);
132132 const stat = try file.stat();
133 break :size @intCast(usize, stat.size);
133 break :size @as(usize, @intCast(stat.size));
134134 };
135135
136136 const file_contents = try gpa.alloc(u8, size);
......@@ -365,7 +365,7 @@ fn Parser(comptime ReaderType: type) type {
365365 const len = try readLeb(u32, parser.reader.reader());
366366 var limited_reader = std.io.limitedReader(parser.reader.reader(), len);
367367 const reader = limited_reader.reader();
368 switch (@enumFromInt(std.wasm.Section, byte)) {
368 switch (@as(std.wasm.Section, @enumFromInt(byte))) {
369369 .custom => {
370370 const name_len = try readLeb(u32, reader);
371371 const name = try gpa.alloc(u8, name_len);
......@@ -375,13 +375,13 @@ fn Parser(comptime ReaderType: type) type {
375375 if (std.mem.eql(u8, name, "linking")) {
376376 is_object_file.* = true;
377377 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)));
379379 } else if (std.mem.startsWith(u8, name, "reloc")) {
380380 try parser.parseRelocations(gpa);
381381 } else if (std.mem.eql(u8, name, "target_features")) {
382382 try parser.parseFeatures(gpa);
383383 } 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));
385385 const debug_content = try gpa.alloc(u8, debug_size);
386386 errdefer gpa.free(debug_content);
387387 try reader.readNoEof(debug_content);
......@@ -514,7 +514,7 @@ fn Parser(comptime ReaderType: type) type {
514514 const count = try readLeb(u32, reader);
515515 while (index < count) : (index += 1) {
516516 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));
518518 const data = try gpa.alloc(u8, code_len);
519519 errdefer gpa.free(data);
520520 try reader.readNoEof(data);
......@@ -538,7 +538,7 @@ fn Parser(comptime ReaderType: type) type {
538538 _ = flags; // TODO: Do we need to check flags to detect passive/active memory?
539539 _ = data_offset;
540540 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));
542542 const data = try gpa.alloc(u8, data_len);
543543 errdefer gpa.free(data);
544544 try reader.readNoEof(data);
......@@ -645,7 +645,7 @@ fn Parser(comptime ReaderType: type) type {
645645 /// such as access to the `import` section to find the name of a symbol.
646646 fn parseSubsection(parser: *ObjectParser, gpa: Allocator, reader: anytype) !void {
647647 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)))});
649649 const payload_len = try leb.readULEB128(u32, reader);
650650 if (payload_len == 0) return;
651651
......@@ -655,7 +655,7 @@ fn Parser(comptime ReaderType: type) type {
655655 // every subsection contains a 'count' field
656656 const count = try leb.readULEB128(u32, limited_reader);
657657
658 switch (@enumFromInt(types.SubsectionType, sub_type)) {
658 switch (@as(types.SubsectionType, @enumFromInt(sub_type))) {
659659 .WASM_SEGMENT_INFO => {
660660 const segments = try gpa.alloc(types.Segment, count);
661661 errdefer gpa.free(segments);
......@@ -714,7 +714,7 @@ fn Parser(comptime ReaderType: type) type {
714714 errdefer gpa.free(symbols);
715715 for (symbols) |*symbol| {
716716 symbol.* = .{
717 .kind = @enumFromInt(types.ComdatSym.Type, try leb.readULEB128(u8, reader)),
717 .kind = @as(types.ComdatSym.Type, @enumFromInt(try leb.readULEB128(u8, reader))),
718718 .index = try leb.readULEB128(u32, reader),
719719 };
720720 }
......@@ -758,7 +758,7 @@ fn Parser(comptime ReaderType: type) type {
758758 /// requires access to `Object` to find the name of a symbol when it's
759759 /// an import and flag `WASM_SYM_EXPLICIT_NAME` is not set.
760760 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)));
762762 const flags = try leb.readULEB128(u32, reader);
763763 var symbol: Symbol = .{
764764 .flags = flags,
......@@ -846,7 +846,7 @@ fn readLeb(comptime T: type, reader: anytype) !T {
846846/// Asserts `T` is an enum
847847fn readEnum(comptime T: type, reader: anytype) !T {
848848 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))),
850850 else => @compileError("T must be an enum. Instead was given type " ++ @typeName(T)),
851851 }
852852}
......@@ -867,7 +867,7 @@ fn readLimits(reader: anytype) !std.wasm.Limits {
867867
868868fn readInit(reader: anytype) !std.wasm.InitExpression {
869869 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))) {
871871 .i32_const => .{ .i32_const = try readLeb(i32, reader) },
872872 .global_get => .{ .global_get = try readLeb(u32, reader) },
873873 else => @panic("TODO: initexpression for other opcodes"),
......@@ -899,7 +899,7 @@ pub fn parseIntoAtoms(object: *Object, gpa: Allocator, object_index: u16, wasm_b
899899 switch (symbol.tag) {
900900 .function, .data, .section => if (!symbol.isUndefined()) {
901901 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));
903903 if (!gop.found_existing) {
904904 gop.value_ptr.* = std.ArrayList(u32).init(gpa);
905905 }
......@@ -910,11 +910,11 @@ pub fn parseIntoAtoms(object: *Object, gpa: Allocator, object_index: u16, wasm_b
910910 }
911911
912912 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 {
914914 continue; // found unknown section, so skip parsing into atom as we do not know how to handle it.
915915 };
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));
918918 const atom = try wasm_bin.managed_atoms.addOne(gpa);
919919 atom.* = Atom.empty;
920920 atom.file = object_index;
src/link/Wasm/types.zig+1-1
......@@ -205,7 +205,7 @@ pub const Feature = struct {
205205
206206 /// From a given cpu feature, returns its linker feature
207207 pub fn fromCpuFeature(feature: std.Target.wasm.Feature) Tag {
208 return @enumFromInt(Tag, @intFromEnum(feature));
208 return @as(Tag, @enumFromInt(@intFromEnum(feature)));
209209 }
210210
211211 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 {
4545 const off = entry.key_ptr.*;
4646 const save = entry.value_ptr.*;
4747 if (!save) continue;
48 const new_off = @intCast(u32, buffer.items.len);
48 const new_off = @as(u32, @intCast(buffer.items.len));
4949 buffer.appendSliceAssumeCapacity(self.getAssumeExists(off));
5050 idx_map.putAssumeCapacityNoClobber(off, new_off);
5151 }
......@@ -73,7 +73,7 @@ pub fn StringTable(comptime log_scope: @Type(.EnumLiteral)) type {
7373 }
7474
7575 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
7878 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 {
103103 pub fn get(self: Self, off: u32) ?[]const u8 {
104104 log.debug("getting string at 0x{x}", .{off});
105105 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);
107107 }
108108
109109 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 {
1818 break :blk index;
1919 } else {
2020 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));
2222 _ = self.entries.addOneAssumeCapacity();
2323 break :blk index;
2424 }
src/link/tapi/Tokenizer.zig+2-2
......@@ -67,11 +67,11 @@ pub const TokenIterator = struct {
6767 }
6868
6969 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;
7171 if (new_pos < 0) {
7272 self.pos = 0;
7373 } else {
74 self.pos = @intCast(usize, new_pos);
74 self.pos = @as(usize, @intCast(new_pos));
7575 }
7676 }
7777};
src/main.zig+9-9
......@@ -3523,7 +3523,7 @@ fn progressThread(progress: *std.Progress, server: *const Server, reset: *std.Th
35233523
35243524 server.serveMessage(.{
35253525 .tag = .progress,
3526 .bytes_len = @intCast(u32, progress_string.len),
3526 .bytes_len = @as(u32, @intCast(progress_string.len)),
35273527 }, &.{
35283528 progress_string,
35293529 }) catch |err| {
......@@ -5020,8 +5020,8 @@ pub fn clangMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}!
50205020
50215021 // Convert the args to the null-terminated format Clang expects.
50225022 const argv = try argsCopyZ(arena, args);
5023 const exit_code = ZigClang_main(@intCast(c_int, argv.len), argv.ptr);
5024 return @bitCast(u8, @truncate(i8, exit_code));
5023 const exit_code = ZigClang_main(@as(c_int, @intCast(argv.len)), argv.ptr);
5024 return @as(u8, @bitCast(@as(i8, @truncate(exit_code))));
50255025}
50265026
50275027pub 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}
50355035 // Convert the args to the format llvm-ar expects.
50365036 // We intentionally shave off the zig binary at args[0].
50375037 const argv = try argsCopyZ(arena, args[1..]);
5038 const exit_code = ZigLlvmAr_main(@intCast(c_int, argv.len), argv.ptr);
5039 return @bitCast(u8, @truncate(i8, exit_code));
5038 const exit_code = ZigLlvmAr_main(@as(c_int, @intCast(argv.len)), argv.ptr);
5039 return @as(u8, @bitCast(@as(i8, @truncate(exit_code))));
50405040}
50415041
50425042/// The first argument determines which backend is invoked. The options are:
......@@ -5072,7 +5072,7 @@ pub fn lldMain(
50725072 // "If an error occurs, false will be returned."
50735073 const ok = rc: {
50745074 const llvm = @import("codegen/llvm/bindings.zig");
5075 const argc = @intCast(c_int, argv.len);
5075 const argc = @as(c_int, @intCast(argv.len));
50765076 if (mem.eql(u8, args[1], "ld.lld")) {
50775077 break :rc llvm.LinkELF(argc, argv.ptr, can_exit_early, false);
50785078 } else if (mem.eql(u8, args[1], "lld-link")) {
......@@ -5507,7 +5507,7 @@ pub fn cmdAstCheck(
55075507 if (stat.size > max_src_size)
55085508 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);
55115511 const amt = try f.readAll(source);
55125512 if (amt != stat.size)
55135513 return error.UnexpectedEndOfFile;
......@@ -5703,7 +5703,7 @@ pub fn cmdChangelist(
57035703 file.pkg = try Package.create(gpa, null, file.sub_file_path);
57045704 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);
57075707 const amt = try f.readAll(source);
57085708 if (amt != stat.size)
57095709 return error.UnexpectedEndOfFile;
......@@ -5739,7 +5739,7 @@ pub fn cmdChangelist(
57395739 if (new_stat.size > max_src_size)
57405740 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);
57435743 const new_amt = try new_f.readAll(new_source);
57445744 if (new_amt != new_stat.size)
57455745 return error.UnexpectedEndOfFile;
src/objcopy.zig+27-27
......@@ -345,7 +345,7 @@ const BinaryElfOutput = struct {
345345
346346 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)));
349349 errdefer allocator.free(buffer);
350350
351351 const num_read = try elf_file.preadAll(buffer, shstrtab_shdr.sh_offset);
......@@ -363,11 +363,11 @@ const BinaryElfOutput = struct {
363363
364364 newSection.binaryOffset = 0;
365365 newSection.elfOffset = section.sh_offset;
366 newSection.fileSize = @intCast(usize, section.sh_size);
366 newSection.fileSize = @as(usize, @intCast(section.sh_size));
367367 newSection.segment = null;
368368
369369 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])))
371371 else
372372 null;
373373
......@@ -382,7 +382,7 @@ const BinaryElfOutput = struct {
382382
383383 newSegment.physicalAddress = if (phdr.p_paddr != 0) phdr.p_paddr else phdr.p_vaddr;
384384 newSegment.virtualAddress = phdr.p_vaddr;
385 newSegment.fileSize = @intCast(usize, phdr.p_filesz);
385 newSegment.fileSize = @as(usize, @intCast(phdr.p_filesz));
386386 newSegment.elfOffset = phdr.p_offset;
387387 newSegment.binaryOffset = 0;
388388 newSegment.firstSection = null;
......@@ -478,8 +478,8 @@ const HexWriter = struct {
478478 const MAX_PAYLOAD_LEN: u8 = 16;
479479
480480 fn addressParts(address: u16) [2]u8 {
481 const msb = @truncate(u8, address >> 8);
482 const lsb = @truncate(u8, address);
481 const msb = @as(u8, @truncate(address >> 8));
482 const lsb = @as(u8, @truncate(address));
483483 return [2]u8{ msb, lsb };
484484 }
485485
......@@ -508,14 +508,14 @@ const HexWriter = struct {
508508
509509 fn Data(address: u32, data: []const u8) Record {
510510 return Record{
511 .address = @intCast(u16, address % 0x10000),
511 .address = @as(u16, @intCast(address % 0x10000)),
512512 .payload = .{ .Data = data },
513513 };
514514 }
515515
516516 fn Address(address: u32) Record {
517517 assert(address > 0xFFFF);
518 const segment = @intCast(u16, address / 0x10000);
518 const segment = @as(u16, @intCast(address / 0x10000));
519519 if (address > 0xFFFFF) {
520520 return Record{
521521 .address = 0,
......@@ -540,7 +540,7 @@ const HexWriter = struct {
540540 fn checksum(self: Record) u8 {
541541 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));
544544 const parts = addressParts(self.address);
545545 sum +%= parts[0];
546546 sum +%= parts[1];
......@@ -560,7 +560,7 @@ const HexWriter = struct {
560560 assert(payload_bytes.len <= MAX_PAYLOAD_LEN);
561561
562562 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)),
564564 self.address,
565565 @intFromEnum(self.payload),
566566 std.fmt.fmtSliceHexUpper(payload_bytes),
......@@ -574,10 +574,10 @@ const HexWriter = struct {
574574 var buf: [MAX_PAYLOAD_LEN]u8 = undefined;
575575 var bytes_read: usize = 0;
576576 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
579579 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)));
581581 const did_read = try elf_file.preadAll(buf[0..to_read], segment.elfOffset + bytes_read);
582582 if (did_read < to_read) return error.UnexpectedEOF;
583583
......@@ -593,7 +593,7 @@ const HexWriter = struct {
593593 try Record.Address(address).write(self.out_file);
594594 }
595595 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));
597597 }
598598
599599 fn writeEOF(self: HexWriter) File.WriteError!void {
......@@ -814,7 +814,7 @@ fn ElfFile(comptime is_64: bool) type {
814814 const need_strings = (idx == header.shstrndx);
815815
816816 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)));
818818 const bytes_read = try in_file.preadAll(buffer, section.section.sh_offset);
819819 if (bytes_read != section.section.sh_size) return error.TRUNCATED_ELF;
820820 section.payload = buffer;
......@@ -831,7 +831,7 @@ fn ElfFile(comptime is_64: bool) type {
831831 } else null;
832832
833833 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
836836 const category_from_program: SectionCategory = if (section.segment != null) .exe else .debug;
837837 section.category = switch (section.section.sh_type) {
......@@ -935,7 +935,7 @@ fn ElfFile(comptime is_64: bool) type {
935935 const update = &sections_update[self.raw_elf_header.e_shstrndx];
936936
937937 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));
939939 const buf = try allocator.alignedAlloc(u8, section_memory_align, new_offset + name.len + 1);
940940 @memcpy(buf[0..new_offset], strtab.payload.?);
941941 @memcpy(buf[new_offset..][0..name.len], name);
......@@ -965,7 +965,7 @@ fn ElfFile(comptime is_64: bool) type {
965965 update.payload = payload;
966966 update.section = section.section;
967967 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));
969969 update.section.?.sh_flags |= elf.SHF_COMPRESSED;
970970 }
971971 }
......@@ -991,7 +991,7 @@ fn ElfFile(comptime is_64: bool) type {
991991 const data = std.mem.sliceAsBytes(self.program_segments);
992992 assert(data.len == @as(usize, updated_elf_header.e_phentsize) * updated_elf_header.e_phnum);
993993 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));
995995 }
996996
997997 // update sections and queue payload writes
......@@ -1032,7 +1032,7 @@ fn ElfFile(comptime is_64: bool) type {
10321032 dest.sh_info = sections_update[src.sh_info].remap_idx;
10331033
10341034 if (payload) |data|
1035 dest.sh_size = @intCast(Elf_OffSize, data.len);
1035 dest.sh_size = @as(Elf_OffSize, @intCast(data.len));
10361036
10371037 const addralign = if (src.sh_addralign == 0 or dest.sh_type == elf.SHT_NOBITS) 1 else src.sh_addralign;
10381038 dest.sh_offset = std.mem.alignForward(Elf_OffSize, eof_offset, addralign);
......@@ -1056,7 +1056,7 @@ fn ElfFile(comptime is_64: bool) type {
10561056 const data = try allocator.alignedAlloc(u8, section_memory_align, src_data.len);
10571057 @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)];
10601060 for (defs) |*def| {
10611061 if (def.vd_ndx != elf.SHN_UNDEF)
10621062 def.vd_ndx = sections_update[src.sh_info].remap_idx;
......@@ -1068,7 +1068,7 @@ fn ElfFile(comptime is_64: bool) type {
10681068 const data = try allocator.alignedAlloc(u8, section_memory_align, src_data.len);
10691069 @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)];
10721072 for (syms) |*sym| {
10731073 if (sym.st_shndx != elf.SHN_UNDEF and sym.st_shndx < elf.SHN_LORESERVE)
10741074 sym.st_shndx = sections_update[sym.st_shndx].remap_idx;
......@@ -1110,7 +1110,7 @@ fn ElfFile(comptime is_64: bool) type {
11101110 .sh_flags = 0,
11111111 .sh_addr = 0,
11121112 .sh_offset = eof_offset,
1113 .sh_size = @intCast(Elf_OffSize, payload.len),
1113 .sh_size = @as(Elf_OffSize, @intCast(payload.len)),
11141114 .sh_link = elf.SHN_UNDEF,
11151115 .sh_info = elf.SHN_UNDEF,
11161116 .sh_addralign = 4,
......@@ -1119,7 +1119,7 @@ fn ElfFile(comptime is_64: bool) type {
11191119 dest_section_idx += 1;
11201120
11211121 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));
11231123 }
11241124
11251125 assert(dest_section_idx == new_shnum);
......@@ -1232,7 +1232,7 @@ const ElfFileHelper = struct {
12321232 fused_cmd = null;
12331233 }
12341234 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 } });
12361236 }
12371237 consolidated.appendAssumeCapacity(cmd);
12381238 offset = data.out_offset + data.data.len;
......@@ -1249,7 +1249,7 @@ const ElfFileHelper = struct {
12491249 } else {
12501250 consolidated.appendAssumeCapacity(prev);
12511251 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 } });
12531253 }
12541254 fused_cmd = cmd;
12551255 }
......@@ -1286,7 +1286,7 @@ const ElfFileHelper = struct {
12861286 var section_reader = std.io.limitedReader(in_file.reader(), size);
12871287
12881288 // 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)));
12901290 var compressed_stream = std.io.fixedBufferStream(compressed_data);
12911291
12921292 try compressed_stream.writer().writeAll(prefix);
......@@ -1317,7 +1317,7 @@ const ElfFileHelper = struct {
13171317 };
13181318 }
13191319
1320 const compressed_len = @intCast(usize, compressed_stream.getPos() catch unreachable);
1320 const compressed_len = @as(usize, @intCast(compressed_stream.getPos() catch unreachable));
13211321 const data = allocator.realloc(compressed_data, compressed_len) catch compressed_data;
13221322 return data[0..compressed_len];
13231323 }
src/print_air.zig+11-11
......@@ -91,7 +91,7 @@ const Writer = struct {
9191 fn writeAllConstants(w: *Writer, s: anytype) @TypeOf(s).Error!void {
9292 for (w.air.instructions.items(.tag), 0..) |tag, i| {
9393 if (tag != .interned) continue;
94 const inst = @intCast(Air.Inst.Index, i);
94 const inst = @as(Air.Inst.Index, @intCast(i));
9595 try w.writeInst(s, inst);
9696 try s.writeByte('\n');
9797 }
......@@ -424,8 +424,8 @@ const Writer = struct {
424424 const mod = w.module;
425425 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
426426 const vector_ty = w.air.getRefType(ty_pl.ty);
427 const len = @intCast(usize, vector_ty.arrayLen(mod));
428 const elements = @ptrCast([]const Air.Inst.Ref, w.air.extra[ty_pl.payload..][0..len]);
427 const len = @as(usize, @intCast(vector_ty.arrayLen(mod)));
428 const elements = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[ty_pl.payload..][0..len]));
429429
430430 try w.writeType(s, vector_ty);
431431 try s.writeAll(", [");
......@@ -607,8 +607,8 @@ const Writer = struct {
607607 fn writeAssembly(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
608608 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
609609 const extra = w.air.extraData(Air.Asm, ty_pl.payload);
610 const is_volatile = @truncate(u1, extra.data.flags >> 31) != 0;
611 const clobbers_len = @truncate(u31, extra.data.flags);
610 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
611 const clobbers_len = @as(u31, @truncate(extra.data.flags));
612612 var extra_i: usize = extra.end;
613613 var op_index: usize = 0;
614614
......@@ -619,9 +619,9 @@ const Writer = struct {
619619 try s.writeAll(", volatile");
620620 }
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]));
623623 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]));
625625 extra_i += inputs.len;
626626
627627 for (outputs) |output| {
......@@ -699,7 +699,7 @@ const Writer = struct {
699699 fn writeCall(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
700700 const pl_op = w.air.instructions.items(.data)[inst].pl_op;
701701 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]));
703703 try w.writeOperand(s, inst, 0, pl_op.operand);
704704 try s.writeAll(", [");
705705 for (args, 0..) |arg, i| {
......@@ -855,7 +855,7 @@ const Writer = struct {
855855
856856 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
857857 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]));
859859 const case_body = w.air.extra[case.end + items.len ..][0..case.data.body_len];
860860 extra_index = case.end + case.data.items_len + case_body.len;
861861
......@@ -934,13 +934,13 @@ const Writer = struct {
934934 const small_tomb_bits = Liveness.bpi - 1;
935935 const dies = if (w.liveness) |liveness| blk: {
936936 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)));
938938 var extra_index = liveness.special.get(inst).?;
939939 var tomb_op_index: usize = small_tomb_bits;
940940 while (true) {
941941 const bits = liveness.extra[extra_index];
942942 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;
944944 }
945945 if ((bits >> 31) != 0) break :blk false;
946946 extra_index += 1;
src/print_targets.zig+2-2
......@@ -100,7 +100,7 @@ pub fn cmdTargets(
100100 try jws.objectField(model.name);
101101 try jws.beginArray();
102102 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));
104104 if (model.features.isEnabled(index)) {
105105 try jws.arrayElem();
106106 try jws.emitString(feature.name);
......@@ -147,7 +147,7 @@ pub fn cmdTargets(
147147 try jws.objectField("features");
148148 try jws.beginArray();
149149 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));
151151 if (cpu.features.isEnabled(index)) {
152152 try jws.arrayElem();
153153 try jws.emitString(feature.name);
src/print_zir.zig+100-74
......@@ -131,7 +131,7 @@ const Writer = struct {
131131 recurse_blocks: bool,
132132
133133 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))));
135135 }
136136
137137 fn writeInstToStream(
......@@ -154,6 +154,7 @@ const Writer = struct {
154154 .alloc,
155155 .alloc_mut,
156156 .alloc_comptime_mut,
157 .elem_type,
157158 .indexable_ptr_len,
158159 .anyframe_type,
159160 .bit_not,
......@@ -329,7 +330,6 @@ const Writer = struct {
329330 .int_cast,
330331 .ptr_cast,
331332 .truncate,
332 .align_cast,
333333 .div_exact,
334334 .div_floor,
335335 .div_trunc,
......@@ -507,8 +507,6 @@ const Writer = struct {
507507 .reify,
508508 .c_va_copy,
509509 .c_va_end,
510 .const_cast,
511 .volatile_cast,
512510 .work_item_id,
513511 .work_group_size,
514512 .work_group_id,
......@@ -525,7 +523,6 @@ const Writer = struct {
525523 .err_set_cast,
526524 .wasm_memory_grow,
527525 .prefetch,
528 .addrspace_cast,
529526 .c_va_arg,
530527 => {
531528 const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
......@@ -539,11 +536,13 @@ const Writer = struct {
539536
540537 .builtin_async_call => try self.writeBuiltinAsyncCall(stream, extended),
541538 .cmpxchg => try self.writeCmpxchg(stream, extended),
539 .ptr_cast_full => try self.writePtrCastFull(stream, extended),
540 .ptr_cast_no_dest => try self.writePtrCastNoDest(stream, extended),
542541 }
543542 }
544543
545544 fn writeExtNode(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
546 const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand));
545 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
547546 try stream.writeAll(")) ");
548547 try self.writeSrc(stream, src);
549548 }
......@@ -632,25 +631,25 @@ const Writer = struct {
632631 var extra_index = extra.end;
633632 if (inst_data.flags.has_sentinel) {
634633 try stream.writeAll(", ");
635 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])));
636635 extra_index += 1;
637636 }
638637 if (inst_data.flags.has_align) {
639638 try stream.writeAll(", align(");
640 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])));
641640 extra_index += 1;
642641 if (inst_data.flags.has_bit_range) {
643642 const bit_start = extra_index + @intFromBool(inst_data.flags.has_addrspace);
644643 try stream.writeAll(":");
645 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])));
646645 try stream.writeAll(":");
647 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])));
648647 }
649648 try stream.writeAll(")");
650649 }
651650 if (inst_data.flags.has_addrspace) {
652651 try stream.writeAll(", addrspace(");
653 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])));
654653 try stream.writeAll(")");
655654 }
656655 try stream.writeAll(") ");
......@@ -692,7 +691,7 @@ const Writer = struct {
692691 const src = inst_data.src();
693692 const number = extra.get();
694693 // TODO improve std.format to be able to print f128 values
695 try stream.print("{d}) ", .{@floatCast(f64, number)});
694 try stream.print("{d}) ", .{@as(f64, @floatCast(number))});
696695 try self.writeSrc(stream, src);
697696 }
698697
......@@ -964,6 +963,33 @@ const Writer = struct {
964963 try self.writeSrc(stream, src);
965964 }
966965
966 fn writePtrCastFull(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
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;
969 const src = LazySrcLoc.nodeOffset(extra.node);
970 if (flags.ptr_cast) try stream.writeAll("ptr_cast, ");
971 if (flags.align_cast) try stream.writeAll("align_cast, ");
972 if (flags.addrspace_cast) try stream.writeAll("addrspace_cast, ");
973 if (flags.const_cast) try stream.writeAll("const_cast, ");
974 if (flags.volatile_cast) try stream.writeAll("volatile_cast, ");
975 try self.writeInstRef(stream, extra.lhs);
976 try stream.writeAll(", ");
977 try self.writeInstRef(stream, extra.rhs);
978 try stream.writeAll(")) ");
979 try self.writeSrc(stream, src);
980 }
981
982 fn writePtrCastNoDest(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
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;
985 const src = LazySrcLoc.nodeOffset(extra.node);
986 if (flags.const_cast) try stream.writeAll("const_cast, ");
987 if (flags.volatile_cast) try stream.writeAll("volatile_cast, ");
988 try self.writeInstRef(stream, extra.operand);
989 try stream.writeAll(")) ");
990 try self.writeSrc(stream, src);
991 }
992
967993 fn writeAtomicLoad(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
968994 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
969995 const extra = self.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data;
......@@ -1077,14 +1103,14 @@ const Writer = struct {
10771103 ) !void {
10781104 const extra = self.code.extraData(Zir.Inst.Asm, extended.operand);
10791105 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
1080 const outputs_len = @truncate(u5, extended.small);
1081 const inputs_len = @truncate(u5, extended.small >> 5);
1082 const clobbers_len = @truncate(u5, extended.small >> 10);
1083 const is_volatile = @truncate(u1, extended.small >> 15) != 0;
1106 const outputs_len = @as(u5, @truncate(extended.small));
1107 const inputs_len = @as(u5, @truncate(extended.small >> 5));
1108 const clobbers_len = @as(u5, @truncate(extended.small >> 10));
1109 const is_volatile = @as(u1, @truncate(extended.small >> 15)) != 0;
10841110
10851111 try self.writeFlag(stream, "volatile, ", is_volatile);
10861112 if (tmpl_is_expr) {
1087 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)));
10881114 try stream.writeAll(", ");
10891115 } else {
10901116 const asm_source = self.code.nullTerminatedString(extra.data.asm_source);
......@@ -1100,7 +1126,7 @@ const Writer = struct {
11001126 const output = self.code.extraData(Zir.Inst.Asm.Output, extra_i);
11011127 extra_i = output.end;
11021128
1103 const is_type = @truncate(u1, output_type_bits) != 0;
1129 const is_type = @as(u1, @truncate(output_type_bits)) != 0;
11041130 output_type_bits >>= 1;
11051131
11061132 const name = self.code.nullTerminatedString(output.data.name);
......@@ -1179,7 +1205,7 @@ const Writer = struct {
11791205 if (extra.data.flags.ensure_result_used) {
11801206 try stream.writeAll("nodiscard ");
11811207 }
1182 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)))});
11831209 switch (kind) {
11841210 .direct => try self.writeInstRef(stream, extra.data.callee),
11851211 .field => {
......@@ -1254,12 +1280,12 @@ const Writer = struct {
12541280 }
12551281
12561282 fn writeStructDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1257 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
1283 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
12581284
12591285 var extra_index: usize = extended.operand;
12601286
12611287 const src_node: ?i32 = if (small.has_src_node) blk: {
1262 const src_node = @bitCast(i32, self.code.extra[extra_index]);
1288 const src_node = @as(i32, @bitCast(self.code.extra[extra_index]));
12631289 extra_index += 1;
12641290 break :blk src_node;
12651291 } else null;
......@@ -1287,7 +1313,7 @@ const Writer = struct {
12871313 extra_index += 1;
12881314 try stream.writeAll("Packed(");
12891315 if (backing_int_body_len == 0) {
1290 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]));
12911317 extra_index += 1;
12921318 try self.writeInstRef(stream, backing_int_ref);
12931319 } else {
......@@ -1343,13 +1369,13 @@ const Writer = struct {
13431369 cur_bit_bag = self.code.extra[bit_bag_index];
13441370 bit_bag_index += 1;
13451371 }
1346 const has_align = @truncate(u1, cur_bit_bag) != 0;
1372 const has_align = @as(u1, @truncate(cur_bit_bag)) != 0;
13471373 cur_bit_bag >>= 1;
1348 const has_default = @truncate(u1, cur_bit_bag) != 0;
1374 const has_default = @as(u1, @truncate(cur_bit_bag)) != 0;
13491375 cur_bit_bag >>= 1;
1350 const is_comptime = @truncate(u1, cur_bit_bag) != 0;
1376 const is_comptime = @as(u1, @truncate(cur_bit_bag)) != 0;
13511377 cur_bit_bag >>= 1;
1352 const has_type_body = @truncate(u1, cur_bit_bag) != 0;
1378 const has_type_body = @as(u1, @truncate(cur_bit_bag)) != 0;
13531379 cur_bit_bag >>= 1;
13541380
13551381 var field_name: u32 = 0;
......@@ -1369,7 +1395,7 @@ const Writer = struct {
13691395 if (has_type_body) {
13701396 fields[field_i].type_len = self.code.extra[extra_index];
13711397 } else {
1372 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]));
13731399 }
13741400 extra_index += 1;
13751401
......@@ -1443,18 +1469,18 @@ const Writer = struct {
14431469 }
14441470
14451471 fn writeUnionDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1446 const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small);
1472 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));
14471473
14481474 var extra_index: usize = extended.operand;
14491475
14501476 const src_node: ?i32 = if (small.has_src_node) blk: {
1451 const src_node = @bitCast(i32, self.code.extra[extra_index]);
1477 const src_node = @as(i32, @bitCast(self.code.extra[extra_index]));
14521478 extra_index += 1;
14531479 break :blk src_node;
14541480 } else null;
14551481
14561482 const tag_type_ref = if (small.has_tag_type) blk: {
1457 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]));
14581484 extra_index += 1;
14591485 break :blk tag_type_ref;
14601486 } else .none;
......@@ -1531,13 +1557,13 @@ const Writer = struct {
15311557 cur_bit_bag = self.code.extra[bit_bag_index];
15321558 bit_bag_index += 1;
15331559 }
1534 const has_type = @truncate(u1, cur_bit_bag) != 0;
1560 const has_type = @as(u1, @truncate(cur_bit_bag)) != 0;
15351561 cur_bit_bag >>= 1;
1536 const has_align = @truncate(u1, cur_bit_bag) != 0;
1562 const has_align = @as(u1, @truncate(cur_bit_bag)) != 0;
15371563 cur_bit_bag >>= 1;
1538 const has_value = @truncate(u1, cur_bit_bag) != 0;
1564 const has_value = @as(u1, @truncate(cur_bit_bag)) != 0;
15391565 cur_bit_bag >>= 1;
1540 const unused = @truncate(u1, cur_bit_bag) != 0;
1566 const unused = @as(u1, @truncate(cur_bit_bag)) != 0;
15411567 cur_bit_bag >>= 1;
15421568
15431569 _ = unused;
......@@ -1552,14 +1578,14 @@ const Writer = struct {
15521578 try stream.print("{}", .{std.zig.fmtId(field_name)});
15531579
15541580 if (has_type) {
1555 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]));
15561582 extra_index += 1;
15571583
15581584 try stream.writeAll(": ");
15591585 try self.writeInstRef(stream, field_type);
15601586 }
15611587 if (has_align) {
1562 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]));
15631589 extra_index += 1;
15641590
15651591 try stream.writeAll(" align(");
......@@ -1567,7 +1593,7 @@ const Writer = struct {
15671593 try stream.writeAll(")");
15681594 }
15691595 if (has_value) {
1570 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]));
15711597 extra_index += 1;
15721598
15731599 try stream.writeAll(" = ");
......@@ -1595,13 +1621,13 @@ const Writer = struct {
15951621 cur_bit_bag = self.code.extra[bit_bag_index];
15961622 bit_bag_index += 1;
15971623 }
1598 const is_pub = @truncate(u1, cur_bit_bag) != 0;
1624 const is_pub = @as(u1, @truncate(cur_bit_bag)) != 0;
15991625 cur_bit_bag >>= 1;
1600 const is_exported = @truncate(u1, cur_bit_bag) != 0;
1626 const is_exported = @as(u1, @truncate(cur_bit_bag)) != 0;
16011627 cur_bit_bag >>= 1;
1602 const has_align = @truncate(u1, cur_bit_bag) != 0;
1628 const has_align = @as(u1, @truncate(cur_bit_bag)) != 0;
16031629 cur_bit_bag >>= 1;
1604 const has_section_or_addrspace = @truncate(u1, cur_bit_bag) != 0;
1630 const has_section_or_addrspace = @as(u1, @truncate(cur_bit_bag)) != 0;
16051631 cur_bit_bag >>= 1;
16061632
16071633 const sub_index = extra_index;
......@@ -1618,23 +1644,23 @@ const Writer = struct {
16181644 extra_index += 1;
16191645
16201646 const align_inst: Zir.Inst.Ref = if (!has_align) .none else inst: {
1621 const inst = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);
1647 const inst = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
16221648 extra_index += 1;
16231649 break :inst inst;
16241650 };
16251651 const section_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: {
1626 const inst = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);
1652 const inst = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
16271653 extra_index += 1;
16281654 break :inst inst;
16291655 };
16301656 const addrspace_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: {
1631 const inst = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);
1657 const inst = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
16321658 extra_index += 1;
16331659 break :inst inst;
16341660 };
16351661
16361662 const pub_str = if (is_pub) "pub " else "";
1637 const hash_bytes = @bitCast([16]u8, hash_u32s.*);
1663 const hash_bytes = @as([16]u8, @bitCast(hash_u32s.*));
16381664 if (decl_name_index == 0) {
16391665 try stream.writeByteNTimes(' ', self.indent);
16401666 const name = if (is_exported) "usingnamespace" else "comptime";
......@@ -1702,17 +1728,17 @@ const Writer = struct {
17021728 }
17031729
17041730 fn writeEnumDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1705 const small = @bitCast(Zir.Inst.EnumDecl.Small, extended.small);
1731 const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small));
17061732 var extra_index: usize = extended.operand;
17071733
17081734 const src_node: ?i32 = if (small.has_src_node) blk: {
1709 const src_node = @bitCast(i32, self.code.extra[extra_index]);
1735 const src_node = @as(i32, @bitCast(self.code.extra[extra_index]));
17101736 extra_index += 1;
17111737 break :blk src_node;
17121738 } else null;
17131739
17141740 const tag_type_ref = if (small.has_tag_type) blk: {
1715 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]));
17161742 extra_index += 1;
17171743 break :blk tag_type_ref;
17181744 } else .none;
......@@ -1782,7 +1808,7 @@ const Writer = struct {
17821808 cur_bit_bag = self.code.extra[bit_bag_index];
17831809 bit_bag_index += 1;
17841810 }
1785 const has_tag_value = @truncate(u1, cur_bit_bag) != 0;
1811 const has_tag_value = @as(u1, @truncate(cur_bit_bag)) != 0;
17861812 cur_bit_bag >>= 1;
17871813
17881814 const field_name = self.code.nullTerminatedString(self.code.extra[extra_index]);
......@@ -1797,7 +1823,7 @@ const Writer = struct {
17971823 try stream.print("{}", .{std.zig.fmtId(field_name)});
17981824
17991825 if (has_tag_value) {
1800 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]));
18011827 extra_index += 1;
18021828
18031829 try stream.writeAll(" = ");
......@@ -1818,11 +1844,11 @@ const Writer = struct {
18181844 stream: anytype,
18191845 extended: Zir.Inst.Extended.InstData,
18201846 ) !void {
1821 const small = @bitCast(Zir.Inst.OpaqueDecl.Small, extended.small);
1847 const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small));
18221848 var extra_index: usize = extended.operand;
18231849
18241850 const src_node: ?i32 = if (small.has_src_node) blk: {
1825 const src_node = @bitCast(i32, self.code.extra[extra_index]);
1851 const src_node = @as(i32, @bitCast(self.code.extra[extra_index]));
18261852 extra_index += 1;
18271853 break :blk src_node;
18281854 } else null;
......@@ -1866,7 +1892,7 @@ const Writer = struct {
18661892 try stream.writeAll("{\n");
18671893 self.indent += 2;
18681894
1869 var extra_index = @intCast(u32, extra.end);
1895 var extra_index = @as(u32, @intCast(extra.end));
18701896 const extra_index_end = extra_index + (extra.data.fields_len * 2);
18711897 while (extra_index < extra_index_end) : (extra_index += 2) {
18721898 const str_index = self.code.extra[extra_index];
......@@ -1919,7 +1945,7 @@ const Writer = struct {
19191945 else => break :else_prong,
19201946 };
19211947
1922 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]));
19231949 const capture_text = switch (info.capture) {
19241950 .none => "",
19251951 .by_val => "by_val ",
......@@ -1940,9 +1966,9 @@ const Writer = struct {
19401966 const scalar_cases_len = extra.data.bits.scalar_cases_len;
19411967 var scalar_i: usize = 0;
19421968 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
1943 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]));
19441970 extra_index += 1;
1945 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]));
19461972 extra_index += 1;
19471973 const body = self.code.extra[extra_index..][0..info.body_len];
19481974 extra_index += info.body_len;
......@@ -1967,7 +1993,7 @@ const Writer = struct {
19671993 extra_index += 1;
19681994 const ranges_len = self.code.extra[extra_index];
19691995 extra_index += 1;
1970 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]));
19711997 extra_index += 1;
19721998 const items = self.code.refSlice(extra_index, items_len);
19731999 extra_index += items_len;
......@@ -1988,9 +2014,9 @@ const Writer = struct {
19882014
19892015 var range_i: usize = 0;
19902016 while (range_i < ranges_len) : (range_i += 1) {
1991 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]));
19922018 extra_index += 1;
1993 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]));
19942020 extra_index += 1;
19952021
19962022 if (range_i != 0 or items.len != 0) {
......@@ -2091,7 +2117,7 @@ const Writer = struct {
20912117 ret_ty_ref = .void_type;
20922118 },
20932119 1 => {
2094 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]));
20952121 extra_index += 1;
20962122 },
20972123 else => {
......@@ -2162,7 +2188,7 @@ const Writer = struct {
21622188 align_body = self.code.extra[extra_index..][0..body_len];
21632189 extra_index += align_body.len;
21642190 } else if (extra.data.bits.has_align_ref) {
2165 align_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);
2191 align_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
21662192 extra_index += 1;
21672193 }
21682194 if (extra.data.bits.has_addrspace_body) {
......@@ -2171,7 +2197,7 @@ const Writer = struct {
21712197 addrspace_body = self.code.extra[extra_index..][0..body_len];
21722198 extra_index += addrspace_body.len;
21732199 } else if (extra.data.bits.has_addrspace_ref) {
2174 addrspace_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);
2200 addrspace_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
21752201 extra_index += 1;
21762202 }
21772203 if (extra.data.bits.has_section_body) {
......@@ -2180,7 +2206,7 @@ const Writer = struct {
21802206 section_body = self.code.extra[extra_index..][0..body_len];
21812207 extra_index += section_body.len;
21822208 } else if (extra.data.bits.has_section_ref) {
2183 section_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);
2209 section_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
21842210 extra_index += 1;
21852211 }
21862212 if (extra.data.bits.has_cc_body) {
......@@ -2189,7 +2215,7 @@ const Writer = struct {
21892215 cc_body = self.code.extra[extra_index..][0..body_len];
21902216 extra_index += cc_body.len;
21912217 } else if (extra.data.bits.has_cc_ref) {
2192 cc_ref = @enumFromInt(Zir.Inst.Ref, self.code.extra[extra_index]);
2218 cc_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
21932219 extra_index += 1;
21942220 }
21952221 if (extra.data.bits.has_ret_ty_body) {
......@@ -2198,7 +2224,7 @@ const Writer = struct {
21982224 ret_ty_body = self.code.extra[extra_index..][0..body_len];
21992225 extra_index += ret_ty_body.len;
22002226 } else if (extra.data.bits.has_ret_ty_ref) {
2201 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]));
22022228 extra_index += 1;
22032229 }
22042230
......@@ -2240,7 +2266,7 @@ const Writer = struct {
22402266
22412267 fn writeVarExtended(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
22422268 const extra = self.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
2243 const small = @bitCast(Zir.Inst.ExtendedVar.Small, extended.small);
2269 const small = @as(Zir.Inst.ExtendedVar.Small, @bitCast(extended.small));
22442270
22452271 try self.writeInstRef(stream, extra.data.var_type);
22462272
......@@ -2251,12 +2277,12 @@ const Writer = struct {
22512277 try stream.print(", lib_name=\"{}\"", .{std.zig.fmtEscapes(lib_name)});
22522278 }
22532279 const align_inst: Zir.Inst.Ref = if (!small.has_align) .none else blk: {
2254 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]));
22552281 extra_index += 1;
22562282 break :blk align_inst;
22572283 };
22582284 const init_inst: Zir.Inst.Ref = if (!small.has_init) .none else blk: {
2259 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]));
22602286 extra_index += 1;
22612287 break :blk init_inst;
22622288 };
......@@ -2269,17 +2295,17 @@ const Writer = struct {
22692295
22702296 fn writeAllocExtended(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
22712297 const extra = self.code.extraData(Zir.Inst.AllocExtended, extended.operand);
2272 const small = @bitCast(Zir.Inst.AllocExtended.Small, extended.small);
2298 const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small));
22732299 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
22742300
22752301 var extra_index: usize = extra.end;
22762302 const type_inst: Zir.Inst.Ref = if (!small.has_type) .none else blk: {
2277 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]));
22782304 extra_index += 1;
22792305 break :blk type_inst;
22802306 };
22812307 const align_inst: Zir.Inst.Ref = if (!small.has_align) .none else blk: {
2282 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]));
22832309 extra_index += 1;
22842310 break :blk align_inst;
22852311 };
......@@ -2447,8 +2473,8 @@ const Writer = struct {
24472473 try stream.writeAll(") ");
24482474 if (body.len != 0) {
24492475 try stream.print("(lbrace={d}:{d},rbrace={d}:{d}) ", .{
2450 src_locs.lbrace_line + 1, @truncate(u16, src_locs.columns) + 1,
2451 src_locs.rbrace_line + 1, @truncate(u16, src_locs.columns >> 16) + 1,
2476 src_locs.lbrace_line + 1, @as(u16, @truncate(src_locs.columns)) + 1,
2477 src_locs.rbrace_line + 1, @as(u16, @truncate(src_locs.columns >> 16)) + 1,
24522478 });
24532479 }
24542480 try self.writeSrc(stream, src);
......@@ -2481,7 +2507,7 @@ const Writer = struct {
24812507
24822508 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {
24832509 const i = @intFromEnum(ref);
2484 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))});
24852511 return self.writeInstIndex(stream, i - InternPool.static_len);
24862512 }
24872513
src/register_manager.zig+2-2
......@@ -427,13 +427,13 @@ const MockRegister3 = enum(u3) {
427427
428428 pub fn id(reg: MockRegister3) u3 {
429429 return switch (@intFromEnum(reg)) {
430 0...3 => @as(u3, @truncate(u2, @intFromEnum(reg))),
430 0...3 => @as(u3, @as(u2, @truncate(@intFromEnum(reg)))),
431431 4...7 => @intFromEnum(reg),
432432 };
433433 }
434434
435435 pub fn enc(reg: MockRegister3) u2 {
436 return @truncate(u2, @intFromEnum(reg));
436 return @as(u2, @truncate(@intFromEnum(reg)));
437437 }
438438
439439 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 {
132132 }
133133
134134 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));
136136 const result = self.parent_allocator.rawAlloc(len, ptr_align, ret_addr);
137137 if (result) |data| {
138138 if (len != 0) {
......@@ -149,7 +149,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type {
149149 }
150150
151151 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));
153153 if (self.parent_allocator.rawResize(buf, buf_align, new_len, ret_addr)) {
154154 if (name) |n| {
155155 freeNamed(buf.ptr, n);
......@@ -168,7 +168,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type {
168168 }
169169
170170 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));
172172 self.parent_allocator.rawFree(buf, buf_align, ret_addr);
173173 // this condition is to handle free being called on an empty slice that was never even allocated
174174 // example case: `std.process.getSelfExeSharedLibPaths` can return `&[_][:0]u8{}`
src/translate_c.zig+323-297
......@@ -467,7 +467,7 @@ fn prepopulateGlobalNameTable(ast_unit: *clang.ASTUnit, c: *Context) !void {
467467 const entity = it.deref();
468468 switch (entity.getKind()) {
469469 .MacroDefinitionKind => {
470 const macro = @ptrCast(*clang.MacroDefinitionRecord, entity);
470 const macro = @as(*clang.MacroDefinitionRecord, @ptrCast(entity));
471471 const raw_name = macro.getName_getNameStart();
472472 const name = try c.str(raw_name);
473473
......@@ -481,13 +481,13 @@ fn prepopulateGlobalNameTable(ast_unit: *clang.ASTUnit, c: *Context) !void {
481481}
482482
483483fn 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));
485485 declVisitorNamesOnly(c, decl) catch return false;
486486 return true;
487487}
488488
489489fn 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));
491491 declVisitor(c, decl) catch return false;
492492 return true;
493493}
......@@ -499,37 +499,37 @@ fn declVisitorNamesOnly(c: *Context, decl: *const clang.Decl) Error!void {
499499
500500 // Check for typedefs with unnamed enum/record child types.
501501 if (decl.getKind() == .Typedef) {
502 const typedef_decl = @ptrCast(*const clang.TypedefNameDecl, decl);
502 const typedef_decl = @as(*const clang.TypedefNameDecl, @ptrCast(decl));
503503 var child_ty = typedef_decl.getUnderlyingType().getTypePtr();
504504 const addr: usize = while (true) switch (child_ty.getTypeClass()) {
505505 .Enum => {
506 const enum_ty = @ptrCast(*const clang.EnumType, child_ty);
506 const enum_ty = @as(*const clang.EnumType, @ptrCast(child_ty));
507507 const enum_decl = enum_ty.getDecl();
508508 // 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;
510510 break @intFromPtr(enum_decl.getCanonicalDecl());
511511 },
512512 .Record => {
513 const record_ty = @ptrCast(*const clang.RecordType, child_ty);
513 const record_ty = @as(*const clang.RecordType, @ptrCast(child_ty));
514514 const record_decl = record_ty.getDecl();
515515 // 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;
517517 break @intFromPtr(record_decl.getCanonicalDecl());
518518 },
519519 .Elaborated => {
520 const elaborated_ty = @ptrCast(*const clang.ElaboratedType, child_ty);
520 const elaborated_ty = @as(*const clang.ElaboratedType, @ptrCast(child_ty));
521521 child_ty = elaborated_ty.getNamedType().getTypePtr();
522522 },
523523 .Decayed => {
524 const decayed_ty = @ptrCast(*const clang.DecayedType, child_ty);
524 const decayed_ty = @as(*const clang.DecayedType, @ptrCast(child_ty));
525525 child_ty = decayed_ty.getDecayedType().getTypePtr();
526526 },
527527 .Attributed => {
528 const attributed_ty = @ptrCast(*const clang.AttributedType, child_ty);
528 const attributed_ty = @as(*const clang.AttributedType, @ptrCast(child_ty));
529529 child_ty = attributed_ty.getEquivalentType().getTypePtr();
530530 },
531531 .MacroQualified => {
532 const macroqualified_ty = @ptrCast(*const clang.MacroQualifiedType, child_ty);
532 const macroqualified_ty = @as(*const clang.MacroQualifiedType, @ptrCast(child_ty));
533533 child_ty = macroqualified_ty.getModifiedType().getTypePtr();
534534 },
535535 else => return,
......@@ -552,25 +552,25 @@ fn declVisitorNamesOnly(c: *Context, decl: *const clang.Decl) Error!void {
552552fn declVisitor(c: *Context, decl: *const clang.Decl) Error!void {
553553 switch (decl.getKind()) {
554554 .Function => {
555 return visitFnDecl(c, @ptrCast(*const clang.FunctionDecl, decl));
555 return visitFnDecl(c, @as(*const clang.FunctionDecl, @ptrCast(decl)));
556556 },
557557 .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)));
559559 },
560560 .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)));
562562 },
563563 .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)));
565565 },
566566 .Var => {
567 return visitVarDecl(c, @ptrCast(*const clang.VarDecl, decl), null);
567 return visitVarDecl(c, @as(*const clang.VarDecl, @ptrCast(decl)), null);
568568 },
569569 .Empty => {
570570 // Do nothing
571571 },
572572 .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)));
574574 },
575575 else => {
576576 const decl_name = try c.str(decl.getDeclKindName());
......@@ -595,7 +595,7 @@ fn transFileScopeAsm(c: *Context, scope: *Scope, file_scope_asm: *const clang.Fi
595595}
596596
597597fn 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());
599599 if (c.global_scope.sym_table.contains(fn_name))
600600 return; // Avoid processing this decl twice
601601
......@@ -630,22 +630,22 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {
630630
631631 switch (fn_type.getTypeClass()) {
632632 .Attributed => {
633 const attr_type = @ptrCast(*const clang.AttributedType, fn_type);
633 const attr_type = @as(*const clang.AttributedType, @ptrCast(fn_type));
634634 fn_qt = attr_type.getEquivalentType();
635635 },
636636 .Paren => {
637 const paren_type = @ptrCast(*const clang.ParenType, fn_type);
637 const paren_type = @as(*const clang.ParenType, @ptrCast(fn_type));
638638 fn_qt = paren_type.getInnerType();
639639 },
640640 else => break fn_type,
641641 }
642642 };
643 const fn_ty = @ptrCast(*const clang.FunctionType, fn_type);
643 const fn_ty = @as(*const clang.FunctionType, @ptrCast(fn_type));
644644 const return_qt = fn_ty.getReturnType();
645645
646646 const proto_node = switch (fn_type.getTypeClass()) {
647647 .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));
649649 if (has_body and fn_proto_type.isVariadic()) {
650650 decl_ctx.has_body = false;
651651 decl_ctx.storage_class = .Extern;
......@@ -661,7 +661,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {
661661 };
662662 },
663663 .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));
665665 break :blk transFnNoProto(c, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) {
666666 error.UnsupportedType => {
667667 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 {
714714 param_id += 1;
715715 }
716716
717 const casted_body = @ptrCast(*const clang.CompoundStmt, body_stmt);
717 const casted_body = @as(*const clang.CompoundStmt, @ptrCast(body_stmt));
718718 transCompoundStmtInline(c, casted_body, &block_scope) catch |err| switch (err) {
719719 error.OutOfMemory => |e| return e,
720720 error.UnsupportedTranslation,
......@@ -788,7 +788,7 @@ fn stringLiteralToCharStar(c: *Context, str: Node) Error!Node {
788788
789789/// if mangled_name is not null, this var decl was declared in a block scope.
790790fn 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());
792792 if (c.global_scope.sym_table.contains(var_name))
793793 return; // Avoid processing this decl twice
794794
......@@ -830,7 +830,7 @@ fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]co
830830 if (has_init) trans_init: {
831831 if (decl_init) |expr| {
832832 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)
834834 else
835835 transExprCoercing(c, scope, expr, .used);
836836 init_node = node_or_error catch |err| switch (err) {
......@@ -918,7 +918,7 @@ fn transTypeDef(c: *Context, scope: *Scope, typedef_decl: *const clang.TypedefNa
918918 const toplevel = scope.id == .root;
919919 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());
922922 try c.typedefs.put(c.gpa, name, {});
923923
924924 if (builtin_typedef_map.get(name)) |builtin| {
......@@ -981,7 +981,7 @@ fn buildFlexibleArrayFn(
981981 .is_noalias = false,
982982 };
983983
984 const array_type = @ptrCast(*const clang.ArrayType, field_qt.getTypePtr());
984 const array_type = @as(*const clang.ArrayType, @ptrCast(field_qt.getTypePtr()));
985985 const element_qt = array_type.getElementType();
986986 const element_type = try transQualType(c, scope, element_qt, field_decl.getLocation());
987987
......@@ -1010,17 +1010,23 @@ fn buildFlexibleArrayFn(
10101010 const bit_offset = layout.getFieldOffset(field_index); // this is a target-specific constant based on the struct layout
10111011 const byte_offset = bit_offset / 8;
10121012
1013 const casted_self = try Tag.ptr_cast.create(c.arena, .{
1013 const casted_self = try Tag.as.create(c.arena, .{
10141014 .lhs = intermediate_type_ident,
1015 .rhs = self_param,
1015 .rhs = try Tag.ptr_cast.create(c.arena, self_param),
10161016 });
10171017 const field_offset = try transCreateNodeNumber(c, byte_offset, .int);
10181018 const field_ptr = try Tag.add.create(c.arena, .{ .lhs = casted_self, .rhs = field_offset });
10191019
1020 const alignment = try Tag.alignof.create(c.arena, element_type);
1021
1022 const ptr_val = try Tag.align_cast.create(c.arena, .{ .lhs = alignment, .rhs = field_ptr });
1023 const ptr_cast = try Tag.ptr_cast.create(c.arena, .{ .lhs = return_type_ident, .rhs = ptr_val });
1020 const ptr_cast = try Tag.as.create(c.arena, .{
1021 .lhs = return_type_ident,
1022 .rhs = try Tag.ptr_cast.create(
1023 c.arena,
1024 try Tag.align_cast.create(
1025 c.arena,
1026 field_ptr,
1027 ),
1028 ),
1029 });
10241030 const return_stmt = try Tag.@"return".create(c.arena, ptr_cast);
10251031 try block_scope.statements.append(return_stmt);
10261032
......@@ -1071,7 +1077,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD
10711077
10721078 var is_union = false;
10731079 var container_kind_name: []const u8 = undefined;
1074 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());
10751081
10761082 if (record_decl.isUnion()) {
10771083 container_kind_name = "union";
......@@ -1132,7 +1138,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD
11321138 }
11331139
11341140 var is_anon = false;
1135 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());
11361142 if (field_decl.isAnonymousStructOrUnion() or field_name.len == 0) {
11371143 // Context.getMangle() is not used here because doing so causes unpredictable field names for anonymous fields.
11381144 field_name = try std.fmt.allocPrint(c.arena, "unnamed_{d}", .{unnamed_field_count});
......@@ -1161,7 +1167,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD
11611167 };
11621168
11631169 const alignment = if (has_flexible_array and field_decl.getFieldIndex() == 0)
1164 @intCast(c_uint, record_alignment)
1170 @as(c_uint, @intCast(record_alignment))
11651171 else
11661172 ClangAlignment.forField(c, field_decl, record_def).zigAlignment();
11671173
......@@ -1218,7 +1224,7 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const clang.EnumDecl) E
12181224 const bs: *Scope.Block = if (!toplevel) try scope.findBlockScope(c) else undefined;
12191225
12201226 var is_unnamed = false;
1221 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());
12221228 var name = bare_name;
12231229 if (c.unnamed_typedefs.get(@intFromPtr(enum_decl.getCanonicalDecl()))) |typedef_name| {
12241230 bare_name = typedef_name;
......@@ -1238,13 +1244,13 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const clang.EnumDecl) E
12381244 const end_it = enum_def.enumerator_end();
12391245 while (it.neq(end_it)) : (it = it.next()) {
12401246 const enum_const = it.deref();
1241 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());
12421248 if (!toplevel) {
12431249 enum_val_name = try bs.makeMangledName(c, enum_val_name);
12441250 }
12451251
1246 const enum_const_qt = @ptrCast(*const clang.ValueDecl, enum_const).getType();
1247 const enum_const_loc = @ptrCast(*const clang.Decl, enum_const).getLocation();
1252 const enum_const_qt = @as(*const clang.ValueDecl, @ptrCast(enum_const)).getType();
1253 const enum_const_loc = @as(*const clang.Decl, @ptrCast(enum_const)).getLocation();
12481254 const enum_const_type_node: ?Node = transQualType(c, scope, enum_const_qt, enum_const_loc) catch |err| switch (err) {
12491255 error.UnsupportedType => null,
12501256 else => |e| return e,
......@@ -1319,77 +1325,77 @@ fn transStmt(
13191325) TransError!Node {
13201326 const sc = stmt.getStmtClass();
13211327 switch (sc) {
1322 .BinaryOperatorClass => return transBinaryOperator(c, scope, @ptrCast(*const clang.BinaryOperator, stmt), result_used),
1323 .CompoundStmtClass => return transCompoundStmt(c, scope, @ptrCast(*const clang.CompoundStmt, stmt)),
1324 .CStyleCastExprClass => return transCStyleCastExprClass(c, scope, @ptrCast(*const clang.CStyleCastExpr, stmt), result_used),
1325 .DeclStmtClass => return transDeclStmt(c, scope, @ptrCast(*const clang.DeclStmt, stmt)),
1326 .DeclRefExprClass => return transDeclRefExpr(c, scope, @ptrCast(*const clang.DeclRefExpr, stmt)),
1327 .ImplicitCastExprClass => return transImplicitCastExpr(c, scope, @ptrCast(*const clang.ImplicitCastExpr, stmt), result_used),
1328 .IntegerLiteralClass => return transIntegerLiteral(c, scope, @ptrCast(*const clang.IntegerLiteral, stmt), result_used, .with_as),
1329 .ReturnStmtClass => return transReturnStmt(c, scope, @ptrCast(*const clang.ReturnStmt, stmt)),
1330 .StringLiteralClass => return transStringLiteral(c, scope, @ptrCast(*const clang.StringLiteral, stmt), result_used),
1328 .BinaryOperatorClass => return transBinaryOperator(c, scope, @as(*const clang.BinaryOperator, @ptrCast(stmt)), result_used),
1329 .CompoundStmtClass => return transCompoundStmt(c, scope, @as(*const clang.CompoundStmt, @ptrCast(stmt))),
1330 .CStyleCastExprClass => return transCStyleCastExprClass(c, scope, @as(*const clang.CStyleCastExpr, @ptrCast(stmt)), result_used),
1331 .DeclStmtClass => return transDeclStmt(c, scope, @as(*const clang.DeclStmt, @ptrCast(stmt))),
1332 .DeclRefExprClass => return transDeclRefExpr(c, scope, @as(*const clang.DeclRefExpr, @ptrCast(stmt))),
1333 .ImplicitCastExprClass => return transImplicitCastExpr(c, scope, @as(*const clang.ImplicitCastExpr, @ptrCast(stmt)), result_used),
1334 .IntegerLiteralClass => return transIntegerLiteral(c, scope, @as(*const clang.IntegerLiteral, @ptrCast(stmt)), result_used, .with_as),
1335 .ReturnStmtClass => return transReturnStmt(c, scope, @as(*const clang.ReturnStmt, @ptrCast(stmt))),
1336 .StringLiteralClass => return transStringLiteral(c, scope, @as(*const clang.StringLiteral, @ptrCast(stmt)), result_used),
13311337 .ParenExprClass => {
1332 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);
13331339 return maybeSuppressResult(c, result_used, expr);
13341340 },
1335 .InitListExprClass => return transInitListExpr(c, scope, @ptrCast(*const clang.InitListExpr, stmt), result_used),
1336 .ImplicitValueInitExprClass => return transImplicitValueInitExpr(c, scope, @ptrCast(*const clang.Expr, stmt)),
1337 .IfStmtClass => return transIfStmt(c, scope, @ptrCast(*const clang.IfStmt, stmt)),
1338 .WhileStmtClass => return transWhileLoop(c, scope, @ptrCast(*const clang.WhileStmt, stmt)),
1339 .DoStmtClass => return transDoWhileLoop(c, scope, @ptrCast(*const clang.DoStmt, stmt)),
1341 .InitListExprClass => return transInitListExpr(c, scope, @as(*const clang.InitListExpr, @ptrCast(stmt)), result_used),
1342 .ImplicitValueInitExprClass => return transImplicitValueInitExpr(c, scope, @as(*const clang.Expr, @ptrCast(stmt))),
1343 .IfStmtClass => return transIfStmt(c, scope, @as(*const clang.IfStmt, @ptrCast(stmt))),
1344 .WhileStmtClass => return transWhileLoop(c, scope, @as(*const clang.WhileStmt, @ptrCast(stmt))),
1345 .DoStmtClass => return transDoWhileLoop(c, scope, @as(*const clang.DoStmt, @ptrCast(stmt))),
13401346 .NullStmtClass => {
13411347 return Tag.empty_block.init();
13421348 },
13431349 .ContinueStmtClass => return Tag.@"continue".init(),
13441350 .BreakStmtClass => return Tag.@"break".init(),
1345 .ForStmtClass => return transForLoop(c, scope, @ptrCast(*const clang.ForStmt, stmt)),
1346 .FloatingLiteralClass => return transFloatingLiteral(c, @ptrCast(*const clang.FloatingLiteral, stmt), result_used),
1351 .ForStmtClass => return transForLoop(c, scope, @as(*const clang.ForStmt, @ptrCast(stmt))),
1352 .FloatingLiteralClass => return transFloatingLiteral(c, @as(*const clang.FloatingLiteral, @ptrCast(stmt)), result_used),
13471353 .ConditionalOperatorClass => {
1348 return transConditionalOperator(c, scope, @ptrCast(*const clang.ConditionalOperator, stmt), result_used);
1354 return transConditionalOperator(c, scope, @as(*const clang.ConditionalOperator, @ptrCast(stmt)), result_used);
13491355 },
13501356 .BinaryConditionalOperatorClass => {
1351 return transBinaryConditionalOperator(c, scope, @ptrCast(*const clang.BinaryConditionalOperator, stmt), result_used);
1357 return transBinaryConditionalOperator(c, scope, @as(*const clang.BinaryConditionalOperator, @ptrCast(stmt)), result_used);
13521358 },
1353 .SwitchStmtClass => return transSwitch(c, scope, @ptrCast(*const clang.SwitchStmt, stmt)),
1359 .SwitchStmtClass => return transSwitch(c, scope, @as(*const clang.SwitchStmt, @ptrCast(stmt))),
13541360 .CaseStmtClass, .DefaultStmtClass => {
13551361 return fail(c, error.UnsupportedTranslation, stmt.getBeginLoc(), "TODO complex switch", .{});
13561362 },
1357 .ConstantExprClass => return transConstantExpr(c, scope, @ptrCast(*const clang.Expr, stmt), result_used),
1358 .PredefinedExprClass => return transPredefinedExpr(c, scope, @ptrCast(*const clang.PredefinedExpr, stmt), result_used),
1359 .CharacterLiteralClass => return transCharLiteral(c, scope, @ptrCast(*const clang.CharacterLiteral, stmt), result_used, .with_as),
1360 .StmtExprClass => return transStmtExpr(c, scope, @ptrCast(*const clang.StmtExpr, stmt), result_used),
1361 .MemberExprClass => return transMemberExpr(c, scope, @ptrCast(*const clang.MemberExpr, stmt), result_used),
1362 .ArraySubscriptExprClass => return transArrayAccess(c, scope, @ptrCast(*const clang.ArraySubscriptExpr, stmt), result_used),
1363 .CallExprClass => return transCallExpr(c, scope, @ptrCast(*const clang.CallExpr, stmt), result_used),
1364 .UnaryExprOrTypeTraitExprClass => return transUnaryExprOrTypeTraitExpr(c, scope, @ptrCast(*const clang.UnaryExprOrTypeTraitExpr, stmt), result_used),
1365 .UnaryOperatorClass => return transUnaryOperator(c, scope, @ptrCast(*const clang.UnaryOperator, stmt), result_used),
1366 .CompoundAssignOperatorClass => return transCompoundAssignOperator(c, scope, @ptrCast(*const clang.CompoundAssignOperator, stmt), result_used),
1363 .ConstantExprClass => return transConstantExpr(c, scope, @as(*const clang.Expr, @ptrCast(stmt)), result_used),
1364 .PredefinedExprClass => return transPredefinedExpr(c, scope, @as(*const clang.PredefinedExpr, @ptrCast(stmt)), result_used),
1365 .CharacterLiteralClass => return transCharLiteral(c, scope, @as(*const clang.CharacterLiteral, @ptrCast(stmt)), result_used, .with_as),
1366 .StmtExprClass => return transStmtExpr(c, scope, @as(*const clang.StmtExpr, @ptrCast(stmt)), result_used),
1367 .MemberExprClass => return transMemberExpr(c, scope, @as(*const clang.MemberExpr, @ptrCast(stmt)), result_used),
1368 .ArraySubscriptExprClass => return transArrayAccess(c, scope, @as(*const clang.ArraySubscriptExpr, @ptrCast(stmt)), result_used),
1369 .CallExprClass => return transCallExpr(c, scope, @as(*const clang.CallExpr, @ptrCast(stmt)), result_used),
1370 .UnaryExprOrTypeTraitExprClass => return transUnaryExprOrTypeTraitExpr(c, scope, @as(*const clang.UnaryExprOrTypeTraitExpr, @ptrCast(stmt)), result_used),
1371 .UnaryOperatorClass => return transUnaryOperator(c, scope, @as(*const clang.UnaryOperator, @ptrCast(stmt)), result_used),
1372 .CompoundAssignOperatorClass => return transCompoundAssignOperator(c, scope, @as(*const clang.CompoundAssignOperator, @ptrCast(stmt)), result_used),
13671373 .OpaqueValueExprClass => {
1368 const source_expr = @ptrCast(*const clang.OpaqueValueExpr, stmt).getSourceExpr().?;
1374 const source_expr = @as(*const clang.OpaqueValueExpr, @ptrCast(stmt)).getSourceExpr().?;
13691375 const expr = try transExpr(c, scope, source_expr, .used);
13701376 return maybeSuppressResult(c, result_used, expr);
13711377 },
1372 .OffsetOfExprClass => return transOffsetOfExpr(c, @ptrCast(*const clang.OffsetOfExpr, stmt), result_used),
1378 .OffsetOfExprClass => return transOffsetOfExpr(c, @as(*const clang.OffsetOfExpr, @ptrCast(stmt)), result_used),
13731379 .CompoundLiteralExprClass => {
1374 const compound_literal = @ptrCast(*const clang.CompoundLiteralExpr, stmt);
1380 const compound_literal = @as(*const clang.CompoundLiteralExpr, @ptrCast(stmt));
13751381 return transExpr(c, scope, compound_literal.getInitializer(), result_used);
13761382 },
13771383 .GenericSelectionExprClass => {
1378 const gen_sel = @ptrCast(*const clang.GenericSelectionExpr, stmt);
1384 const gen_sel = @as(*const clang.GenericSelectionExpr, @ptrCast(stmt));
13791385 return transExpr(c, scope, gen_sel.getResultExpr(), result_used);
13801386 },
13811387 .ConvertVectorExprClass => {
1382 const conv_vec = @ptrCast(*const clang.ConvertVectorExpr, stmt);
1388 const conv_vec = @as(*const clang.ConvertVectorExpr, @ptrCast(stmt));
13831389 const conv_vec_node = try transConvertVectorExpr(c, scope, conv_vec);
13841390 return maybeSuppressResult(c, result_used, conv_vec_node);
13851391 },
13861392 .ShuffleVectorExprClass => {
1387 const shuffle_vec_expr = @ptrCast(*const clang.ShuffleVectorExpr, stmt);
1393 const shuffle_vec_expr = @as(*const clang.ShuffleVectorExpr, @ptrCast(stmt));
13881394 const shuffle_vec_node = try transShuffleVectorExpr(c, scope, shuffle_vec_expr);
13891395 return maybeSuppressResult(c, result_used, shuffle_vec_node);
13901396 },
13911397 .ChooseExprClass => {
1392 const choose_expr = @ptrCast(*const clang.ChooseExpr, stmt);
1398 const choose_expr = @as(*const clang.ChooseExpr, @ptrCast(stmt));
13931399 return transExpr(c, scope, choose_expr.getChosenSubExpr(), result_used);
13941400 },
13951401 // When adding new cases here, see comment for maybeBlockify()
......@@ -1415,21 +1421,21 @@ fn transConvertVectorExpr(
14151421 scope: *Scope,
14161422 expr: *const clang.ConvertVectorExpr,
14171423) TransError!Node {
1418 const base_stmt = @ptrCast(*const clang.Stmt, expr);
1424 const base_stmt = @as(*const clang.Stmt, @ptrCast(expr));
14191425
14201426 var block_scope = try Scope.Block.init(c, scope, true);
14211427 defer block_scope.deinit();
14221428
14231429 const src_expr = expr.getSrcExpr();
14241430 const src_type = qualTypeCanon(src_expr.getType());
1425 const src_vector_ty = @ptrCast(*const clang.VectorType, src_type);
1431 const src_vector_ty = @as(*const clang.VectorType, @ptrCast(src_type));
14261432 const src_element_qt = src_vector_ty.getElementType();
14271433
14281434 const src_expr_node = try transExpr(c, &block_scope.base, src_expr, .used);
14291435
14301436 const dst_qt = expr.getTypeSourceInfo_getType();
14311437 const dst_type_node = try transQualType(c, &block_scope.base, dst_qt, base_stmt.getBeginLoc());
1432 const dst_vector_ty = @ptrCast(*const clang.VectorType, qualTypeCanon(dst_qt));
1438 const dst_vector_ty = @as(*const clang.VectorType, @ptrCast(qualTypeCanon(dst_qt)));
14331439 const num_elements = dst_vector_ty.getNumElements();
14341440 const dst_element_qt = dst_vector_ty.getElementType();
14351441
......@@ -1484,7 +1490,7 @@ fn makeShuffleMask(c: *Context, scope: *Scope, expr: *const clang.ShuffleVectorE
14841490 const init_list = try c.arena.alloc(Node, mask_len);
14851491
14861492 for (init_list, 0..) |*init, i| {
1487 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);
14881494 const converted_index = try Tag.helpers_shuffle_vector_index.create(c.arena, .{ .lhs = index_expr, .rhs = vector_len });
14891495 init.* = converted_index;
14901496 }
......@@ -1508,7 +1514,7 @@ fn transShuffleVectorExpr(
15081514 scope: *Scope,
15091515 expr: *const clang.ShuffleVectorExpr,
15101516) TransError!Node {
1511 const base_expr = @ptrCast(*const clang.Expr, expr);
1517 const base_expr = @as(*const clang.Expr, @ptrCast(expr));
15121518 const num_subexprs = expr.getNumSubExprs();
15131519 if (num_subexprs < 3) return fail(c, error.UnsupportedTranslation, base_expr.getBeginLoc(), "ShuffleVector needs at least 1 index", .{});
15141520
......@@ -1539,7 +1545,7 @@ fn transSimpleOffsetOfExpr(c: *Context, expr: *const clang.OffsetOfExpr) TransEr
15391545 if (c.decl_table.get(@intFromPtr(record_decl.getCanonicalDecl()))) |type_name| {
15401546 const type_node = try Tag.type.create(c.arena, type_name);
15411547
1542 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());
15431549 const quoted_field_name = try std.fmt.allocPrint(c.arena, "\"{s}\"", .{raw_field_name});
15441550 const field_name_node = try Tag.string_literal.create(c.arena, quoted_field_name);
15451551
......@@ -1579,14 +1585,14 @@ fn transOffsetOfExpr(
15791585/// pointer arithmetic expressions, where wraparound will ensure we get the correct value.
15801586/// node -> @bitCast(usize, @intCast(isize, node))
15811587fn usizeCastForWrappingPtrArithmetic(gpa: mem.Allocator, node: Node) TransError!Node {
1582 const intcast_node = try Tag.int_cast.create(gpa, .{
1588 const intcast_node = try Tag.as.create(gpa, .{
15831589 .lhs = try Tag.type.create(gpa, "isize"),
1584 .rhs = node,
1590 .rhs = try Tag.int_cast.create(gpa, node),
15851591 });
15861592
1587 return Tag.bit_cast.create(gpa, .{
1593 return Tag.as.create(gpa, .{
15881594 .lhs = try Tag.type.create(gpa, "usize"),
1589 .rhs = intcast_node,
1595 .rhs = try Tag.bit_cast.create(gpa, intcast_node),
15901596 });
15911597}
15921598
......@@ -1781,7 +1787,10 @@ fn transBinaryOperator(
17811787 const elem_type = c_pointer.castTag(.c_pointer).?.data.elem_type;
17821788 const sizeof = try Tag.sizeof.create(c.arena, elem_type);
17831789
1784 const bitcast = try Tag.bit_cast.create(c.arena, .{ .lhs = ptrdiff_type, .rhs = infixOpNode });
1790 const bitcast = try Tag.as.create(c.arena, .{
1791 .lhs = ptrdiff_type,
1792 .rhs = try Tag.bit_cast.create(c.arena, infixOpNode),
1793 });
17851794
17861795 return Tag.div_exact.create(c.arena, .{
17871796 .lhs = bitcast,
......@@ -1820,7 +1829,7 @@ fn transCStyleCastExprClass(
18201829 stmt: *const clang.CStyleCastExpr,
18211830 result_used: ResultUsed,
18221831) TransError!Node {
1823 const cast_expr = @ptrCast(*const clang.CastExpr, stmt);
1832 const cast_expr = @as(*const clang.CastExpr, @ptrCast(stmt));
18241833 const sub_expr = stmt.getSubExpr();
18251834 const dst_type = stmt.getType();
18261835 const src_type = sub_expr.getType();
......@@ -1829,7 +1838,7 @@ fn transCStyleCastExprClass(
18291838
18301839 const cast_node = if (cast_expr.getCastKind() == .ToUnion) blk: {
18311840 const field_decl = cast_expr.getTargetFieldForToUnionCast(dst_type, src_type).?; // C syntax error if target field is null
1832 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());
18331842
18341843 const union_ty = try transQualType(c, scope, dst_type, loc);
18351844
......@@ -1914,12 +1923,12 @@ fn transDeclStmtOne(
19141923) TransError!void {
19151924 switch (decl.getKind()) {
19161925 .Var => {
1917 const var_decl = @ptrCast(*const clang.VarDecl, decl);
1926 const var_decl = @as(*const clang.VarDecl, @ptrCast(decl));
19181927 const decl_init = var_decl.getInit();
19191928 const loc = decl.getLocation();
19201929
19211930 const qual_type = var_decl.getTypeSourceInfo_getType();
1922 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());
19231932 const mangled_name = try block_scope.makeMangledName(c, name);
19241933
19251934 if (var_decl.getStorageClass() == .Extern) {
......@@ -1936,7 +1945,7 @@ fn transDeclStmtOne(
19361945
19371946 var init_node = if (decl_init) |expr|
19381947 if (expr.getStmtClass() == .StringLiteralClass)
1939 try transStringLiteralInitializer(c, @ptrCast(*const clang.StringLiteral, expr), type_node)
1948 try transStringLiteralInitializer(c, @as(*const clang.StringLiteral, @ptrCast(expr)), type_node)
19401949 else
19411950 try transExprCoercing(c, scope, expr, .used)
19421951 else if (is_static_local)
......@@ -1971,7 +1980,7 @@ fn transDeclStmtOne(
19711980
19721981 const cleanup_attr = var_decl.getCleanupAttribute();
19731982 if (cleanup_attr) |fn_decl| {
1974 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());
19751984 const fn_id = try Tag.identifier.create(c.arena, cleanup_fn_name);
19761985
19771986 const varname = try Tag.identifier.create(c.arena, mangled_name);
......@@ -1986,16 +1995,16 @@ fn transDeclStmtOne(
19861995 }
19871996 },
19881997 .Typedef => {
1989 try transTypeDef(c, scope, @ptrCast(*const clang.TypedefNameDecl, decl));
1998 try transTypeDef(c, scope, @as(*const clang.TypedefNameDecl, @ptrCast(decl)));
19901999 },
19912000 .Record => {
1992 try transRecordDecl(c, scope, @ptrCast(*const clang.RecordDecl, decl));
2001 try transRecordDecl(c, scope, @as(*const clang.RecordDecl, @ptrCast(decl)));
19932002 },
19942003 .Enum => {
1995 try transEnumDecl(c, scope, @ptrCast(*const clang.EnumDecl, decl));
2004 try transEnumDecl(c, scope, @as(*const clang.EnumDecl, @ptrCast(decl)));
19962005 },
19972006 .Function => {
1998 try visitFnDecl(c, @ptrCast(*const clang.FunctionDecl, decl));
2007 try visitFnDecl(c, @as(*const clang.FunctionDecl, @ptrCast(decl)));
19992008 },
20002009 else => {
20012010 const decl_name = try c.str(decl.getDeclKindName());
......@@ -2021,15 +2030,15 @@ fn transDeclRefExpr(
20212030 expr: *const clang.DeclRefExpr,
20222031) TransError!Node {
20232032 const value_decl = expr.getDecl();
2024 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());
20252034 const mangled_name = scope.getAlias(name);
2026 var ref_expr = if (cIsFunctionDeclRef(@ptrCast(*const clang.Expr, expr)))
2035 var ref_expr = if (cIsFunctionDeclRef(@as(*const clang.Expr, @ptrCast(expr))))
20272036 try Tag.fn_identifier.create(c.arena, mangled_name)
20282037 else
20292038 try Tag.identifier.create(c.arena, mangled_name);
20302039
2031 if (@ptrCast(*const clang.Decl, value_decl).getKind() == .Var) {
2032 const var_decl = @ptrCast(*const clang.VarDecl, value_decl);
2040 if (@as(*const clang.Decl, @ptrCast(value_decl)).getKind() == .Var) {
2041 const var_decl = @as(*const clang.VarDecl, @ptrCast(value_decl));
20332042 if (var_decl.isStaticLocal()) {
20342043 ref_expr = try Tag.field_access.create(c.arena, .{
20352044 .lhs = ref_expr,
......@@ -2048,7 +2057,7 @@ fn transImplicitCastExpr(
20482057 result_used: ResultUsed,
20492058) TransError!Node {
20502059 const sub_expr = expr.getSubExpr();
2051 const dest_type = getExprQualType(c, @ptrCast(*const clang.Expr, expr));
2060 const dest_type = getExprQualType(c, @as(*const clang.Expr, @ptrCast(expr)));
20522061 const src_type = getExprQualType(c, sub_expr);
20532062 switch (expr.getCastKind()) {
20542063 .BitCast, .FloatingCast, .FloatingToIntegral, .IntegralToFloating, .IntegralCast, .PointerToIntegral, .IntegralToPointer => {
......@@ -2102,7 +2111,7 @@ fn transImplicitCastExpr(
21022111 else => |kind| return fail(
21032112 c,
21042113 error.UnsupportedTranslation,
2105 @ptrCast(*const clang.Stmt, expr).getBeginLoc(),
2114 @as(*const clang.Stmt, @ptrCast(expr)).getBeginLoc(),
21062115 "unsupported CastKind {s}",
21072116 .{@tagName(kind)},
21082117 ),
......@@ -2132,9 +2141,9 @@ fn transBoolExpr(
21322141 expr: *const clang.Expr,
21332142 used: ResultUsed,
21342143) TransError!Node {
2135 if (@ptrCast(*const clang.Stmt, expr).getStmtClass() == .IntegerLiteralClass) {
2144 if (@as(*const clang.Stmt, @ptrCast(expr)).getStmtClass() == .IntegerLiteralClass) {
21362145 var signum: c_int = undefined;
2137 if (!(@ptrCast(*const clang.IntegerLiteral, expr).getSignum(&signum, c.clang_context))) {
2146 if (!(@as(*const clang.IntegerLiteral, @ptrCast(expr)).getSignum(&signum, c.clang_context))) {
21382147 return fail(c, error.UnsupportedTranslation, expr.getBeginLoc(), "invalid integer literal", .{});
21392148 }
21402149 const is_zero = signum == 0;
......@@ -2159,20 +2168,20 @@ fn exprIsBooleanType(expr: *const clang.Expr) bool {
21592168fn exprIsNarrowStringLiteral(expr: *const clang.Expr) bool {
21602169 switch (expr.getStmtClass()) {
21612170 .StringLiteralClass => {
2162 const string_lit = @ptrCast(*const clang.StringLiteral, expr);
2171 const string_lit = @as(*const clang.StringLiteral, @ptrCast(expr));
21632172 return string_lit.getCharByteWidth() == 1;
21642173 },
21652174 .PredefinedExprClass => return true,
21662175 .UnaryOperatorClass => {
2167 const op_expr = @ptrCast(*const clang.UnaryOperator, expr).getSubExpr();
2176 const op_expr = @as(*const clang.UnaryOperator, @ptrCast(expr)).getSubExpr();
21682177 return exprIsNarrowStringLiteral(op_expr);
21692178 },
21702179 .ParenExprClass => {
2171 const op_expr = @ptrCast(*const clang.ParenExpr, expr).getSubExpr();
2180 const op_expr = @as(*const clang.ParenExpr, @ptrCast(expr)).getSubExpr();
21722181 return exprIsNarrowStringLiteral(op_expr);
21732182 },
21742183 .GenericSelectionExprClass => {
2175 const gen_sel = @ptrCast(*const clang.GenericSelectionExpr, expr);
2184 const gen_sel = @as(*const clang.GenericSelectionExpr, @ptrCast(expr));
21762185 return exprIsNarrowStringLiteral(gen_sel.getResultExpr());
21772186 },
21782187 else => return false,
......@@ -2181,11 +2190,11 @@ fn exprIsNarrowStringLiteral(expr: *const clang.Expr) bool {
21812190
21822191fn exprIsFlexibleArrayRef(c: *Context, expr: *const clang.Expr) bool {
21832192 if (expr.getStmtClass() == .MemberExprClass) {
2184 const member_expr = @ptrCast(*const clang.MemberExpr, expr);
2193 const member_expr = @as(*const clang.MemberExpr, @ptrCast(expr));
21852194 const member_decl = member_expr.getMemberDecl();
2186 const decl_kind = @ptrCast(*const clang.Decl, member_decl).getKind();
2195 const decl_kind = @as(*const clang.Decl, @ptrCast(member_decl)).getKind();
21872196 if (decl_kind == .Field) {
2188 const field_decl = @ptrCast(*const clang.FieldDecl, member_decl);
2197 const field_decl = @as(*const clang.FieldDecl, @ptrCast(member_decl));
21892198 return isFlexibleArrayFieldDecl(c, field_decl);
21902199 }
21912200 }
......@@ -2220,7 +2229,7 @@ fn finishBoolExpr(
22202229) TransError!Node {
22212230 switch (ty.getTypeClass()) {
22222231 .Builtin => {
2223 const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);
2232 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(ty));
22242233
22252234 switch (builtin_ty.getKind()) {
22262235 .Bool => return node,
......@@ -2264,7 +2273,7 @@ fn finishBoolExpr(
22642273 return Tag.not_equal.create(c.arena, .{ .lhs = node, .rhs = Tag.null_literal.init() });
22652274 },
22662275 .Typedef => {
2267 const typedef_ty = @ptrCast(*const clang.TypedefType, ty);
2276 const typedef_ty = @as(*const clang.TypedefType, @ptrCast(ty));
22682277 const typedef_decl = typedef_ty.getDecl();
22692278 const underlying_type = typedef_decl.getUnderlyingType();
22702279 return finishBoolExpr(c, scope, loc, underlying_type.getTypePtr(), node, used);
......@@ -2274,7 +2283,7 @@ fn finishBoolExpr(
22742283 return Tag.not_equal.create(c.arena, .{ .lhs = node, .rhs = Tag.zero_literal.init() });
22752284 },
22762285 .Elaborated => {
2277 const elaborated_ty = @ptrCast(*const clang.ElaboratedType, ty);
2286 const elaborated_ty = @as(*const clang.ElaboratedType, @ptrCast(ty));
22782287 const named_type = elaborated_ty.getNamedType();
22792288 return finishBoolExpr(c, scope, loc, named_type.getTypePtr(), node, used);
22802289 },
......@@ -2310,13 +2319,13 @@ fn transIntegerLiteral(
23102319 // unsigned char y = 256;
23112320 // How this gets evaluated is the 256 is an integer, which gets truncated to signed char, then bit-casted
23122321 // to unsigned char, resulting in 0. In order for this to work, we have to emit this zig code:
2313 // var y = @bitCast(u8, @truncate(i8, @as(c_int, 256)));
2322 // var y = @as(u8, @bitCast(@as(i8, @truncate(@as(c_int, 256)))));
23142323 // Ideally in translate-c we could flatten this out to simply:
23152324 // var y: u8 = 0;
23162325 // But the first step is to be correct, and the next step is to make the output more elegant.
23172326
23182327 // @as(T, x)
2319 const expr_base = @ptrCast(*const clang.Expr, expr);
2328 const expr_base = @as(*const clang.Expr, @ptrCast(expr));
23202329 const ty_node = try transQualType(c, scope, expr_base.getType(), expr_base.getBeginLoc());
23212330 const rhs = try transCreateNodeAPInt(c, eval_result.Val.getInt());
23222331 const as = try Tag.as.create(c.arena, .{ .lhs = ty_node, .rhs = rhs });
......@@ -2365,7 +2374,7 @@ fn transStringLiteral(
23652374 const str_type = @tagName(stmt.getKind());
23662375 const name = try std.fmt.allocPrint(c.arena, "zig.{s}_string_{d}", .{ str_type, c.getMangle() });
23672376
2368 const expr_base = @ptrCast(*const clang.Expr, stmt);
2377 const expr_base = @as(*const clang.Expr, @ptrCast(stmt));
23692378 const array_type = try transQualTypeInitialized(c, scope, expr_base.getType(), expr_base, expr_base.getBeginLoc());
23702379 const lit_array = try transStringLiteralInitializer(c, stmt, array_type);
23712380 const decl = try Tag.var_simple.create(c.arena, .{ .name = name, .init = lit_array });
......@@ -2442,11 +2451,11 @@ fn transStringLiteralInitializer(
24422451/// both operands resolve to addresses. The C standard requires that both operands
24432452/// point to elements of the same array object, but we do not verify that here.
24442453fn cIsPointerDiffExpr(stmt: *const clang.BinaryOperator) bool {
2445 const lhs = @ptrCast(*const clang.Stmt, stmt.getLHS());
2446 const rhs = @ptrCast(*const clang.Stmt, stmt.getRHS());
2454 const lhs = @as(*const clang.Stmt, @ptrCast(stmt.getLHS()));
2455 const rhs = @as(*const clang.Stmt, @ptrCast(stmt.getRHS()));
24472456 return stmt.getOpcode() == .Sub and
2448 qualTypeIsPtr(@ptrCast(*const clang.Expr, lhs).getType()) and
2449 qualTypeIsPtr(@ptrCast(*const clang.Expr, rhs).getType());
2457 qualTypeIsPtr(@as(*const clang.Expr, @ptrCast(lhs)).getType()) and
2458 qualTypeIsPtr(@as(*const clang.Expr, @ptrCast(rhs)).getType());
24502459}
24512460
24522461fn cIsEnum(qt: clang.QualType) bool {
......@@ -2463,7 +2472,7 @@ fn cIsVector(qt: clang.QualType) bool {
24632472fn cIntTypeForEnum(enum_qt: clang.QualType) clang.QualType {
24642473 assert(cIsEnum(enum_qt));
24652474 const ty = enum_qt.getCanonicalType().getTypePtr();
2466 const enum_ty = @ptrCast(*const clang.EnumType, ty);
2475 const enum_ty = @as(*const clang.EnumType, @ptrCast(ty));
24672476 const enum_decl = enum_ty.getDecl();
24682477 return enum_decl.getIntegerType();
24692478}
......@@ -2501,7 +2510,10 @@ fn transCCast(
25012510 .lt => {
25022511 // @truncate(SameSignSmallerInt, src_int_expr)
25032512 const ty_node = try transQualTypeIntWidthOf(c, dst_type, src_type_is_signed);
2504 src_int_expr = try Tag.truncate.create(c.arena, .{ .lhs = ty_node, .rhs = src_int_expr });
2513 src_int_expr = try Tag.as.create(c.arena, .{
2514 .lhs = ty_node,
2515 .rhs = try Tag.truncate.create(c.arena, src_int_expr),
2516 });
25052517 },
25062518 .gt => {
25072519 // @as(SameSignBiggerInt, src_int_expr)
......@@ -2512,36 +2524,57 @@ fn transCCast(
25122524 // src_int_expr = src_int_expr
25132525 },
25142526 }
2515 // @bitCast(dest_type, intermediate_value)
2516 return Tag.bit_cast.create(c.arena, .{ .lhs = dst_node, .rhs = src_int_expr });
2527 // @as(dest_type, @bitCast(intermediate_value))
2528 return Tag.as.create(c.arena, .{
2529 .lhs = dst_node,
2530 .rhs = try Tag.bit_cast.create(c.arena, src_int_expr),
2531 });
25172532 }
25182533 if (cIsVector(src_type) or cIsVector(dst_type)) {
25192534 // C cast where at least 1 operand is a vector requires them to be same size
2520 // @bitCast(dest_type, val)
2521 return Tag.bit_cast.create(c.arena, .{ .lhs = dst_node, .rhs = expr });
2535 // @as(dest_type, @bitCast(val))
2536 return Tag.as.create(c.arena, .{
2537 .lhs = dst_node,
2538 .rhs = try Tag.bit_cast.create(c.arena, expr),
2539 });
25222540 }
25232541 if (cIsInteger(dst_type) and qualTypeIsPtr(src_type)) {
25242542 // @intCast(dest_type, @intFromPtr(val))
25252543 const int_from_ptr = try Tag.int_from_ptr.create(c.arena, expr);
2526 return Tag.int_cast.create(c.arena, .{ .lhs = dst_node, .rhs = int_from_ptr });
2544 return Tag.as.create(c.arena, .{
2545 .lhs = dst_node,
2546 .rhs = try Tag.int_cast.create(c.arena, int_from_ptr),
2547 });
25272548 }
25282549 if (cIsInteger(src_type) and qualTypeIsPtr(dst_type)) {
2529 // @ptrFromInt(dest_type, val)
2530 return Tag.ptr_from_int.create(c.arena, .{ .lhs = dst_node, .rhs = expr });
2550 // @as(dest_type, @ptrFromInt(val))
2551 return Tag.as.create(c.arena, .{
2552 .lhs = dst_node,
2553 .rhs = try Tag.ptr_from_int.create(c.arena, expr),
2554 });
25312555 }
25322556 if (cIsFloating(src_type) and cIsFloating(dst_type)) {
2533 // @floatCast(dest_type, val)
2534 return Tag.float_cast.create(c.arena, .{ .lhs = dst_node, .rhs = expr });
2557 // @as(dest_type, @floatCast(val))
2558 return Tag.as.create(c.arena, .{
2559 .lhs = dst_node,
2560 .rhs = try Tag.float_cast.create(c.arena, expr),
2561 });
25352562 }
25362563 if (cIsFloating(src_type) and !cIsFloating(dst_type)) {
2537 // @intFromFloat(dest_type, val)
2538 return Tag.int_from_float.create(c.arena, .{ .lhs = dst_node, .rhs = expr });
2564 // @as(dest_type, @intFromFloat(val))
2565 return Tag.as.create(c.arena, .{
2566 .lhs = dst_node,
2567 .rhs = try Tag.int_from_float.create(c.arena, expr),
2568 });
25392569 }
25402570 if (!cIsFloating(src_type) and cIsFloating(dst_type)) {
25412571 var rhs = expr;
25422572 if (qualTypeIsBoolean(src_type)) rhs = try Tag.int_from_bool.create(c.arena, expr);
2543 // @floatFromInt(dest_type, val)
2544 return Tag.float_from_int.create(c.arena, .{ .lhs = dst_node, .rhs = rhs });
2573 // @as(dest_type, @floatFromInt(val))
2574 return Tag.as.create(c.arena, .{
2575 .lhs = dst_node,
2576 .rhs = try Tag.float_from_int.create(c.arena, rhs),
2577 });
25452578 }
25462579 if (qualTypeIsBoolean(src_type) and !qualTypeIsBoolean(dst_type)) {
25472580 // @intFromBool returns a u1
......@@ -2555,29 +2588,29 @@ fn transCCast(
25552588}
25562589
25572590fn transExpr(c: *Context, scope: *Scope, expr: *const clang.Expr, used: ResultUsed) TransError!Node {
2558 return transStmt(c, scope, @ptrCast(*const clang.Stmt, expr), used);
2591 return transStmt(c, scope, @as(*const clang.Stmt, @ptrCast(expr)), used);
25592592}
25602593
25612594/// Same as `transExpr` but with the knowledge that the operand will be type coerced, and therefore
25622595/// an `@as` would be redundant. This is used to prevent redundant `@as` in integer literals.
25632596fn transExprCoercing(c: *Context, scope: *Scope, expr: *const clang.Expr, used: ResultUsed) TransError!Node {
2564 switch (@ptrCast(*const clang.Stmt, expr).getStmtClass()) {
2597 switch (@as(*const clang.Stmt, @ptrCast(expr)).getStmtClass()) {
25652598 .IntegerLiteralClass => {
2566 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);
25672600 },
25682601 .CharacterLiteralClass => {
2569 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);
25702603 },
25712604 .UnaryOperatorClass => {
2572 const un_expr = @ptrCast(*const clang.UnaryOperator, expr);
2605 const un_expr = @as(*const clang.UnaryOperator, @ptrCast(expr));
25732606 if (un_expr.getOpcode() == .Extension) {
25742607 return transExprCoercing(c, scope, un_expr.getSubExpr(), used);
25752608 }
25762609 },
25772610 .ImplicitCastExprClass => {
2578 const cast_expr = @ptrCast(*const clang.ImplicitCastExpr, expr);
2611 const cast_expr = @as(*const clang.ImplicitCastExpr, @ptrCast(expr));
25792612 const sub_expr = cast_expr.getSubExpr();
2580 switch (@ptrCast(*const clang.Stmt, sub_expr).getStmtClass()) {
2613 switch (@as(*const clang.Stmt, @ptrCast(sub_expr)).getStmtClass()) {
25812614 .IntegerLiteralClass, .CharacterLiteralClass => switch (cast_expr.getCastKind()) {
25822615 .IntegralToFloating => return transExprCoercing(c, scope, sub_expr, used),
25832616 .IntegralCast => {
......@@ -2601,15 +2634,15 @@ fn literalFitsInType(c: *Context, expr: *const clang.Expr, qt: clang.QualType) b
26012634 const is_signed = cIsSignedInteger(qt);
26022635 const width_max_int = (@as(u64, 1) << math.lossyCast(u6, width - @intFromBool(is_signed))) - 1;
26032636
2604 switch (@ptrCast(*const clang.Stmt, expr).getStmtClass()) {
2637 switch (@as(*const clang.Stmt, @ptrCast(expr)).getStmtClass()) {
26052638 .CharacterLiteralClass => {
2606 const char_lit = @ptrCast(*const clang.CharacterLiteral, expr);
2639 const char_lit = @as(*const clang.CharacterLiteral, @ptrCast(expr));
26072640 const val = char_lit.getValue();
26082641 // If the val is less than the max int then it fits.
26092642 return val <= width_max_int;
26102643 },
26112644 .IntegerLiteralClass => {
2612 const int_lit = @ptrCast(*const clang.IntegerLiteral, expr);
2645 const int_lit = @as(*const clang.IntegerLiteral, @ptrCast(expr));
26132646 var eval_result: clang.ExprEvalResult = undefined;
26142647 if (!int_lit.EvaluateAsInt(&eval_result, c.clang_context)) {
26152648 return false;
......@@ -2662,7 +2695,7 @@ fn transInitListExprRecord(
26622695
26632696 // Generate the field assignment expression:
26642697 // .field_name = expr
2665 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());
26662699 if (field_decl.isAnonymousStructOrUnion()) {
26672700 const name = c.decl_table.get(@intFromPtr(field_decl.getCanonicalDecl())).?;
26682701 raw_name = try c.arena.dupe(u8, name);
......@@ -2703,8 +2736,8 @@ fn transInitListExprArray(
27032736 const child_qt = arr_type.getElementType();
27042737 const child_type = try transQualType(c, scope, child_qt, loc);
27052738 const init_count = expr.getNumInits();
2706 assert(@ptrCast(*const clang.Type, arr_type).isConstantArrayType());
2707 const const_arr_ty = @ptrCast(*const clang.ConstantArrayType, arr_type);
2739 assert(@as(*const clang.Type, @ptrCast(arr_type)).isConstantArrayType());
2740 const const_arr_ty = @as(*const clang.ConstantArrayType, @ptrCast(arr_type));
27082741 const size_ap_int = const_arr_ty.getSize();
27092742 const all_count = size_ap_int.getLimitedValue(usize);
27102743 const leftover_count = all_count - init_count;
......@@ -2724,7 +2757,7 @@ fn transInitListExprArray(
27242757 const init_list = try c.arena.alloc(Node, init_count);
27252758
27262759 for (init_list, 0..) |*init, i| {
2727 const elem_expr = expr.getInit(@intCast(c_uint, i));
2760 const elem_expr = expr.getInit(@as(c_uint, @intCast(i)));
27282761 init.* = try transExprCoercing(c, scope, elem_expr, .used);
27292762 }
27302763 const init_node = try Tag.array_init.create(c.arena, .{
......@@ -2758,8 +2791,8 @@ fn transInitListExprVector(
27582791 loc: clang.SourceLocation,
27592792 expr: *const clang.InitListExpr,
27602793) TransError!Node {
2761 const qt = getExprQualType(c, @ptrCast(*const clang.Expr, expr));
2762 const vector_ty = @ptrCast(*const clang.VectorType, qualTypeCanon(qt));
2794 const qt = getExprQualType(c, @as(*const clang.Expr, @ptrCast(expr)));
2795 const vector_ty = @as(*const clang.VectorType, @ptrCast(qualTypeCanon(qt)));
27632796
27642797 const init_count = expr.getNumInits();
27652798 const num_elements = vector_ty.getNumElements();
......@@ -2789,7 +2822,7 @@ fn transInitListExprVector(
27892822 var i: usize = 0;
27902823 while (i < init_count) : (i += 1) {
27912824 const mangled_name = try block_scope.makeMangledName(c, "tmp");
2792 const init_expr = expr.getInit(@intCast(c_uint, i));
2825 const init_expr = expr.getInit(@as(c_uint, @intCast(i)));
27932826 const tmp_decl_node = try Tag.var_simple.create(c.arena, .{
27942827 .name = mangled_name,
27952828 .init = try transExpr(c, &block_scope.base, init_expr, .used),
......@@ -2827,9 +2860,9 @@ fn transInitListExpr(
28272860 expr: *const clang.InitListExpr,
28282861 used: ResultUsed,
28292862) TransError!Node {
2830 const qt = getExprQualType(c, @ptrCast(*const clang.Expr, expr));
2863 const qt = getExprQualType(c, @as(*const clang.Expr, @ptrCast(expr)));
28312864 var qual_type = qt.getTypePtr();
2832 const source_loc = @ptrCast(*const clang.Expr, expr).getBeginLoc();
2865 const source_loc = @as(*const clang.Expr, @ptrCast(expr)).getBeginLoc();
28332866
28342867 if (qualTypeWasDemotedToOpaque(c, qt)) {
28352868 return fail(c, error.UnsupportedTranslation, source_loc, "cannot initialize opaque type", .{});
......@@ -2867,7 +2900,7 @@ fn transZeroInitExpr(
28672900) TransError!Node {
28682901 switch (ty.getTypeClass()) {
28692902 .Builtin => {
2870 const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);
2903 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(ty));
28712904 switch (builtin_ty.getKind()) {
28722905 .Bool => return Tag.false_literal.init(),
28732906 .Char_U,
......@@ -2896,7 +2929,7 @@ fn transZeroInitExpr(
28962929 },
28972930 .Pointer => return Tag.null_literal.init(),
28982931 .Typedef => {
2899 const typedef_ty = @ptrCast(*const clang.TypedefType, ty);
2932 const typedef_ty = @as(*const clang.TypedefType, @ptrCast(ty));
29002933 const typedef_decl = typedef_ty.getDecl();
29012934 return transZeroInitExpr(
29022935 c,
......@@ -2965,7 +2998,7 @@ fn transIfStmt(
29652998 },
29662999 };
29673000 defer cond_scope.deinit();
2968 const cond_expr = @ptrCast(*const clang.Expr, stmt.getCond());
3001 const cond_expr = @as(*const clang.Expr, @ptrCast(stmt.getCond()));
29693002 const cond = try transBoolExpr(c, &cond_scope.base, cond_expr, .used);
29703003
29713004 const then_stmt = stmt.getThen();
......@@ -3001,7 +3034,7 @@ fn transWhileLoop(
30013034 },
30023035 };
30033036 defer cond_scope.deinit();
3004 const cond_expr = @ptrCast(*const clang.Expr, stmt.getCond());
3037 const cond_expr = @as(*const clang.Expr, @ptrCast(stmt.getCond()));
30053038 const cond = try transBoolExpr(c, &cond_scope.base, cond_expr, .used);
30063039
30073040 var loop_scope = Scope{
......@@ -3030,7 +3063,7 @@ fn transDoWhileLoop(
30303063 },
30313064 };
30323065 defer cond_scope.deinit();
3033 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);
30343067 const if_not_break = switch (cond.tag()) {
30353068 .true_literal => {
30363069 const body_node = try maybeBlockify(c, scope, stmt.getBody());
......@@ -3151,7 +3184,7 @@ fn transSwitch(
31513184
31523185 const body = stmt.getBody();
31533186 assert(body.getStmtClass() == .CompoundStmtClass);
3154 const compound_stmt = @ptrCast(*const clang.CompoundStmt, body);
3187 const compound_stmt = @as(*const clang.CompoundStmt, @ptrCast(body));
31553188 var it = compound_stmt.body_begin();
31563189 const end_it = compound_stmt.body_end();
31573190 // Iterate over switch body and collect all cases.
......@@ -3178,12 +3211,12 @@ fn transSwitch(
31783211 },
31793212 .DefaultStmtClass => {
31803213 has_default = true;
3181 const default_stmt = @ptrCast(*const clang.DefaultStmt, it[0]);
3214 const default_stmt = @as(*const clang.DefaultStmt, @ptrCast(it[0]));
31823215
31833216 var sub = default_stmt.getSubStmt();
31843217 while (true) switch (sub.getStmtClass()) {
3185 .CaseStmtClass => sub = @ptrCast(*const clang.CaseStmt, sub).getSubStmt(),
3186 .DefaultStmtClass => sub = @ptrCast(*const clang.DefaultStmt, sub).getSubStmt(),
3218 .CaseStmtClass => sub = @as(*const clang.CaseStmt, @ptrCast(sub)).getSubStmt(),
3219 .DefaultStmtClass => sub = @as(*const clang.DefaultStmt, @ptrCast(sub)).getSubStmt(),
31873220 else => break,
31883221 };
31893222
......@@ -3222,11 +3255,11 @@ fn transCaseStmt(c: *Context, scope: *Scope, stmt: *const clang.Stmt, items: *st
32223255 .DefaultStmtClass => {
32233256 seen_default = true;
32243257 items.items.len = 0;
3225 const default_stmt = @ptrCast(*const clang.DefaultStmt, sub);
3258 const default_stmt = @as(*const clang.DefaultStmt, @ptrCast(sub));
32263259 sub = default_stmt.getSubStmt();
32273260 },
32283261 .CaseStmtClass => {
3229 const case_stmt = @ptrCast(*const clang.CaseStmt, sub);
3262 const case_stmt = @as(*const clang.CaseStmt, @ptrCast(sub));
32303263
32313264 if (seen_default) {
32323265 items.items.len = 0;
......@@ -3293,10 +3326,10 @@ fn transSwitchProngStmtInline(
32933326 return;
32943327 },
32953328 .CaseStmtClass => {
3296 var sub = @ptrCast(*const clang.CaseStmt, it[0]).getSubStmt();
3329 var sub = @as(*const clang.CaseStmt, @ptrCast(it[0])).getSubStmt();
32973330 while (true) switch (sub.getStmtClass()) {
3298 .CaseStmtClass => sub = @ptrCast(*const clang.CaseStmt, sub).getSubStmt(),
3299 .DefaultStmtClass => sub = @ptrCast(*const clang.DefaultStmt, sub).getSubStmt(),
3331 .CaseStmtClass => sub = @as(*const clang.CaseStmt, @ptrCast(sub)).getSubStmt(),
3332 .DefaultStmtClass => sub = @as(*const clang.DefaultStmt, @ptrCast(sub)).getSubStmt(),
33003333 else => break,
33013334 };
33023335 const result = try transStmt(c, &block.base, sub, .unused);
......@@ -3307,10 +3340,10 @@ fn transSwitchProngStmtInline(
33073340 }
33083341 },
33093342 .DefaultStmtClass => {
3310 var sub = @ptrCast(*const clang.DefaultStmt, it[0]).getSubStmt();
3343 var sub = @as(*const clang.DefaultStmt, @ptrCast(it[0])).getSubStmt();
33113344 while (true) switch (sub.getStmtClass()) {
3312 .CaseStmtClass => sub = @ptrCast(*const clang.CaseStmt, sub).getSubStmt(),
3313 .DefaultStmtClass => sub = @ptrCast(*const clang.DefaultStmt, sub).getSubStmt(),
3345 .CaseStmtClass => sub = @as(*const clang.CaseStmt, @ptrCast(sub)).getSubStmt(),
3346 .DefaultStmtClass => sub = @as(*const clang.DefaultStmt, @ptrCast(sub)).getSubStmt(),
33143347 else => break,
33153348 };
33163349 const result = try transStmt(c, &block.base, sub, .unused);
......@@ -3321,7 +3354,7 @@ fn transSwitchProngStmtInline(
33213354 }
33223355 },
33233356 .CompoundStmtClass => {
3324 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])));
33253358 try block.statements.append(result);
33263359 if (result.isNoreturn(true)) {
33273360 return;
......@@ -3348,7 +3381,7 @@ fn transConstantExpr(c: *Context, scope: *Scope, expr: *const clang.Expr, used:
33483381 .Int => {
33493382 // See comment in `transIntegerLiteral` for why this code is here.
33503383 // @as(T, x)
3351 const expr_base = @ptrCast(*const clang.Expr, expr);
3384 const expr_base = @as(*const clang.Expr, @ptrCast(expr));
33523385 const as_node = try Tag.as.create(c.arena, .{
33533386 .lhs = try transQualType(c, scope, expr_base.getType(), expr_base.getBeginLoc()),
33543387 .rhs = try transCreateNodeAPInt(c, result.Val.getInt()),
......@@ -3367,7 +3400,7 @@ fn transPredefinedExpr(c: *Context, scope: *Scope, expr: *const clang.Predefined
33673400
33683401fn transCreateCharLitNode(c: *Context, narrow: bool, val: u32) TransError!Node {
33693402 return Tag.char_literal.create(c.arena, if (narrow)
3370 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))})})
33713404 else
33723405 try std.fmt.allocPrint(c.arena, "'\\u{{{x}}}'", .{val}));
33733406}
......@@ -3394,7 +3427,7 @@ fn transCharLiteral(
33943427 }
33953428 // See comment in `transIntegerLiteral` for why this code is here.
33963429 // @as(T, x)
3397 const expr_base = @ptrCast(*const clang.Expr, stmt);
3430 const expr_base = @as(*const clang.Expr, @ptrCast(stmt));
33983431 const as_node = try Tag.as.create(c.arena, .{
33993432 .lhs = try transQualType(c, scope, expr_base.getType(), expr_base.getBeginLoc()),
34003433 .rhs = int_lit_node,
......@@ -3436,22 +3469,22 @@ fn transMemberExpr(c: *Context, scope: *Scope, stmt: *const clang.MemberExpr, re
34363469
34373470 const member_decl = stmt.getMemberDecl();
34383471 const name = blk: {
3439 const decl_kind = @ptrCast(*const clang.Decl, member_decl).getKind();
3472 const decl_kind = @as(*const clang.Decl, @ptrCast(member_decl)).getKind();
34403473 // If we're referring to a anonymous struct/enum find the bogus name
34413474 // we've assigned to it during the RecordDecl translation
34423475 if (decl_kind == .Field) {
3443 const field_decl = @ptrCast(*const clang.FieldDecl, member_decl);
3476 const field_decl = @as(*const clang.FieldDecl, @ptrCast(member_decl));
34443477 if (field_decl.isAnonymousStructOrUnion()) {
34453478 const name = c.decl_table.get(@intFromPtr(field_decl.getCanonicalDecl())).?;
34463479 break :blk try c.arena.dupe(u8, name);
34473480 }
34483481 }
3449 const decl = @ptrCast(*const clang.NamedDecl, member_decl);
3482 const decl = @as(*const clang.NamedDecl, @ptrCast(member_decl));
34503483 break :blk try c.str(decl.getName_bytes_begin());
34513484 };
34523485
34533486 var node = try Tag.field_access.create(c.arena, .{ .lhs = container_node, .field_name = name });
3454 if (exprIsFlexibleArrayRef(c, @ptrCast(*const clang.Expr, stmt))) {
3487 if (exprIsFlexibleArrayRef(c, @as(*const clang.Expr, @ptrCast(stmt)))) {
34553488 node = try Tag.call.create(c.arena, .{ .lhs = node, .args = &.{} });
34563489 }
34573490 return maybeSuppressResult(c, result_used, node);
......@@ -3487,9 +3520,9 @@ fn transSignedArrayAccess(
34873520
34883521 const then_value = try Tag.add.create(c.arena, .{
34893522 .lhs = container_node,
3490 .rhs = try Tag.int_cast.create(c.arena, .{
3523 .rhs = try Tag.as.create(c.arena, .{
34913524 .lhs = try Tag.type.create(c.arena, "usize"),
3492 .rhs = tmp_ref,
3525 .rhs = try Tag.int_cast.create(c.arena, tmp_ref),
34933526 }),
34943527 });
34953528
......@@ -3499,17 +3532,17 @@ fn transSignedArrayAccess(
34993532 });
35003533
35013534 const minuend = container_node;
3502 const signed_size = try Tag.int_cast.create(c.arena, .{
3535 const signed_size = try Tag.as.create(c.arena, .{
35033536 .lhs = try Tag.type.create(c.arena, "isize"),
3504 .rhs = tmp_ref,
3537 .rhs = try Tag.int_cast.create(c.arena, tmp_ref),
35053538 });
35063539 const to_cast = try Tag.add_wrap.create(c.arena, .{
35073540 .lhs = signed_size,
35083541 .rhs = try Tag.negate.create(c.arena, Tag.one_literal.init()),
35093542 });
3510 const bitcast_node = try Tag.bit_cast.create(c.arena, .{
3543 const bitcast_node = try Tag.as.create(c.arena, .{
35113544 .lhs = try Tag.type.create(c.arena, "usize"),
3512 .rhs = to_cast,
3545 .rhs = try Tag.bit_cast.create(c.arena, to_cast),
35133546 });
35143547 const subtrahend = try Tag.bit_not.create(c.arena, bitcast_node);
35153548 const difference = try Tag.sub.create(c.arena, .{
......@@ -3549,8 +3582,8 @@ fn transArrayAccess(c: *Context, scope: *Scope, stmt: *const clang.ArraySubscrip
35493582 // Unwrap the base statement if it's an array decayed to a bare pointer type
35503583 // so that we index the array itself
35513584 var unwrapped_base = base_stmt;
3552 if (@ptrCast(*const clang.Stmt, base_stmt).getStmtClass() == .ImplicitCastExprClass) {
3553 const implicit_cast = @ptrCast(*const clang.ImplicitCastExpr, base_stmt);
3585 if (@as(*const clang.Stmt, @ptrCast(base_stmt)).getStmtClass() == .ImplicitCastExprClass) {
3586 const implicit_cast = @as(*const clang.ImplicitCastExpr, @ptrCast(base_stmt));
35543587
35553588 if (implicit_cast.getCastKind() == .ArrayToPointerDecay) {
35563589 unwrapped_base = implicit_cast.getSubExpr();
......@@ -3566,7 +3599,13 @@ fn transArrayAccess(c: *Context, scope: *Scope, stmt: *const clang.ArraySubscrip
35663599 const rhs = if (is_longlong or is_signed) blk: {
35673600 // check if long long first so that signed long long doesn't just become unsigned long long
35683601 const typeid_node = if (is_longlong) try Tag.type.create(c.arena, "usize") else try transQualTypeIntWidthOf(c, subscr_qt, false);
3569 break :blk try Tag.int_cast.create(c.arena, .{ .lhs = typeid_node, .rhs = try transExpr(c, scope, subscr_expr, .used) });
3602 break :blk try Tag.as.create(c.arena, .{
3603 .lhs = typeid_node,
3604 .rhs = try Tag.int_cast.create(
3605 c.arena,
3606 try transExpr(c, scope, subscr_expr, .used),
3607 ),
3608 });
35703609 } else try transExpr(c, scope, subscr_expr, .used);
35713610
35723611 const node = try Tag.array_access.create(c.arena, .{
......@@ -3581,17 +3620,17 @@ fn transArrayAccess(c: *Context, scope: *Scope, stmt: *const clang.ArraySubscrip
35813620fn cIsFunctionDeclRef(expr: *const clang.Expr) bool {
35823621 switch (expr.getStmtClass()) {
35833622 .ParenExprClass => {
3584 const op_expr = @ptrCast(*const clang.ParenExpr, expr).getSubExpr();
3623 const op_expr = @as(*const clang.ParenExpr, @ptrCast(expr)).getSubExpr();
35853624 return cIsFunctionDeclRef(op_expr);
35863625 },
35873626 .DeclRefExprClass => {
3588 const decl_ref = @ptrCast(*const clang.DeclRefExpr, expr);
3627 const decl_ref = @as(*const clang.DeclRefExpr, @ptrCast(expr));
35893628 const value_decl = decl_ref.getDecl();
35903629 const qt = value_decl.getType();
35913630 return qualTypeChildIsFnProto(qt);
35923631 },
35933632 .ImplicitCastExprClass => {
3594 const implicit_cast = @ptrCast(*const clang.ImplicitCastExpr, expr);
3633 const implicit_cast = @as(*const clang.ImplicitCastExpr, @ptrCast(expr));
35953634 const cast_kind = implicit_cast.getCastKind();
35963635 if (cast_kind == .BuiltinFnToFnPtr) return true;
35973636 if (cast_kind == .FunctionToPointerDecay) {
......@@ -3600,12 +3639,12 @@ fn cIsFunctionDeclRef(expr: *const clang.Expr) bool {
36003639 return false;
36013640 },
36023641 .UnaryOperatorClass => {
3603 const un_op = @ptrCast(*const clang.UnaryOperator, expr);
3642 const un_op = @as(*const clang.UnaryOperator, @ptrCast(expr));
36043643 const opcode = un_op.getOpcode();
36053644 return (opcode == .AddrOf or opcode == .Deref) and cIsFunctionDeclRef(un_op.getSubExpr());
36063645 },
36073646 .GenericSelectionExprClass => {
3608 const gen_sel = @ptrCast(*const clang.GenericSelectionExpr, expr);
3647 const gen_sel = @as(*const clang.GenericSelectionExpr, @ptrCast(expr));
36093648 return cIsFunctionDeclRef(gen_sel.getResultExpr());
36103649 },
36113650 else => return false,
......@@ -3640,11 +3679,11 @@ fn transCallExpr(c: *Context, scope: *Scope, stmt: *const clang.CallExpr, result
36403679 .Proto => |fn_proto| {
36413680 const param_count = fn_proto.getNumParams();
36423681 if (i < param_count) {
3643 const param_qt = fn_proto.getParamType(@intCast(c_uint, i));
3682 const param_qt = fn_proto.getParamType(@as(c_uint, @intCast(i)));
36443683 if (isBoolRes(arg) and cIsNativeInt(param_qt)) {
36453684 arg = try Tag.int_from_bool.create(c.arena, arg);
36463685 } else if (arg.tag() == .string_literal and qualTypeIsCharStar(param_qt)) {
3647 const loc = @ptrCast(*const clang.Stmt, stmt).getBeginLoc();
3686 const loc = @as(*const clang.Stmt, @ptrCast(stmt)).getBeginLoc();
36483687 const dst_type_node = try transQualType(c, scope, param_qt, loc);
36493688 arg = try removeCVQualifiers(c, dst_type_node, arg);
36503689 }
......@@ -3690,10 +3729,10 @@ fn qualTypeGetFnProto(qt: clang.QualType, is_ptr: *bool) ?ClangFunctionType {
36903729 ty = child_qt.getTypePtr();
36913730 }
36923731 if (ty.getTypeClass() == .FunctionProto) {
3693 return ClangFunctionType{ .Proto = @ptrCast(*const clang.FunctionProtoType, ty) };
3732 return ClangFunctionType{ .Proto = @as(*const clang.FunctionProtoType, @ptrCast(ty)) };
36943733 }
36953734 if (ty.getTypeClass() == .FunctionNoProto) {
3696 return ClangFunctionType{ .NoProto = @ptrCast(*const clang.FunctionType, ty) };
3735 return ClangFunctionType{ .NoProto = @as(*const clang.FunctionType, @ptrCast(ty)) };
36973736 }
36983737 return null;
36993738}
......@@ -3968,8 +4007,7 @@ fn transCreateCompoundAssign(
39684007 }
39694008
39704009 if (is_shift) {
3971 const cast_to_type = try qualTypeToLog2IntRef(c, scope, rhs_qt, loc);
3972 rhs_node = try Tag.int_cast.create(c.arena, .{ .lhs = cast_to_type, .rhs = rhs_node });
4010 rhs_node = try Tag.int_cast.create(c.arena, rhs_node);
39734011 } else if (requires_int_cast) {
39744012 rhs_node = try transCCast(c, scope, loc, lhs_qt, rhs_qt, rhs_node);
39754013 }
......@@ -4008,8 +4046,7 @@ fn transCreateCompoundAssign(
40084046 try block_scope.statements.append(assign);
40094047 } else {
40104048 if (is_shift) {
4011 const cast_to_type = try qualTypeToLog2IntRef(c, &block_scope.base, rhs_qt, loc);
4012 rhs_node = try Tag.int_cast.create(c.arena, .{ .lhs = cast_to_type, .rhs = rhs_node });
4049 rhs_node = try Tag.int_cast.create(c.arena, rhs_node);
40134050 } else if (requires_int_cast) {
40144051 rhs_node = try transCCast(c, &block_scope.base, loc, lhs_qt, rhs_qt, rhs_node);
40154052 }
......@@ -4029,7 +4066,10 @@ fn transCreateCompoundAssign(
40294066// Casting away const or volatile requires us to use @ptrFromInt
40304067fn removeCVQualifiers(c: *Context, dst_type_node: Node, expr: Node) Error!Node {
40314068 const int_from_ptr = try Tag.int_from_ptr.create(c.arena, expr);
4032 return Tag.ptr_from_int.create(c.arena, .{ .lhs = dst_type_node, .rhs = int_from_ptr });
4069 return Tag.as.create(c.arena, .{
4070 .lhs = dst_type_node,
4071 .rhs = try Tag.ptr_from_int.create(c.arena, int_from_ptr),
4072 });
40334073}
40344074
40354075fn transCPtrCast(
......@@ -4062,11 +4102,12 @@ fn transCPtrCast(
40624102 // For opaque types a ptrCast is enough
40634103 expr
40644104 else blk: {
4065 const alignof = try Tag.std_meta_alignment.create(c.arena, dst_type_node);
4066 const align_cast = try Tag.align_cast.create(c.arena, .{ .lhs = alignof, .rhs = expr });
4067 break :blk align_cast;
4105 break :blk try Tag.align_cast.create(c.arena, expr);
40684106 };
4069 return Tag.ptr_cast.create(c.arena, .{ .lhs = dst_type_node, .rhs = rhs });
4107 return Tag.as.create(c.arena, .{
4108 .lhs = dst_type_node,
4109 .rhs = try Tag.ptr_cast.create(c.arena, rhs),
4110 });
40704111 }
40714112}
40724113
......@@ -4100,9 +4141,9 @@ fn transFloatingLiteral(c: *Context, expr: *const clang.FloatingLiteral, used: R
41004141fn transBinaryConditionalOperator(c: *Context, scope: *Scope, stmt: *const clang.BinaryConditionalOperator, used: ResultUsed) TransError!Node {
41014142 // GNU extension of the ternary operator where the middle expression is
41024143 // omitted, the condition itself is returned if it evaluates to true
4103 const qt = @ptrCast(*const clang.Expr, stmt).getType();
4144 const qt = @as(*const clang.Expr, @ptrCast(stmt)).getType();
41044145 const res_is_bool = qualTypeIsBoolean(qt);
4105 const casted_stmt = @ptrCast(*const clang.AbstractConditionalOperator, stmt);
4146 const casted_stmt = @as(*const clang.AbstractConditionalOperator, @ptrCast(stmt));
41064147 const cond_expr = casted_stmt.getCond();
41074148 const false_expr = casted_stmt.getFalseExpr();
41084149
......@@ -4162,9 +4203,9 @@ fn transConditionalOperator(c: *Context, scope: *Scope, stmt: *const clang.Condi
41624203 };
41634204 defer cond_scope.deinit();
41644205
4165 const qt = @ptrCast(*const clang.Expr, stmt).getType();
4206 const qt = @as(*const clang.Expr, @ptrCast(stmt)).getType();
41664207 const res_is_bool = qualTypeIsBoolean(qt);
4167 const casted_stmt = @ptrCast(*const clang.AbstractConditionalOperator, stmt);
4208 const casted_stmt = @as(*const clang.AbstractConditionalOperator, @ptrCast(stmt));
41684209 const cond_expr = casted_stmt.getCond();
41694210 const true_expr = casted_stmt.getTrueExpr();
41704211 const false_expr = casted_stmt.getFalseExpr();
......@@ -4205,7 +4246,7 @@ fn addTopLevelDecl(c: *Context, name: []const u8, decl_node: Node) !void {
42054246
42064247fn transQualTypeInitializedStringLiteral(c: *Context, elem_ty: Node, string_lit: *const clang.StringLiteral) TypeError!Node {
42074248 const string_lit_size = string_lit.getLength();
4208 const array_size = @intCast(usize, string_lit_size);
4249 const array_size = @as(usize, @intCast(string_lit_size));
42094250
42104251 // incomplete array initialized with empty string, will be translated as [1]T{0}
42114252 // see https://github.com/ziglang/zig/issues/8256
......@@ -4225,16 +4266,16 @@ fn transQualTypeInitialized(
42254266) TypeError!Node {
42264267 const ty = qt.getTypePtr();
42274268 if (ty.getTypeClass() == .IncompleteArray) {
4228 const incomplete_array_ty = @ptrCast(*const clang.IncompleteArrayType, ty);
4269 const incomplete_array_ty = @as(*const clang.IncompleteArrayType, @ptrCast(ty));
42294270 const elem_ty = try transType(c, scope, incomplete_array_ty.getElementType().getTypePtr(), source_loc);
42304271
42314272 switch (decl_init.getStmtClass()) {
42324273 .StringLiteralClass => {
4233 const string_lit = @ptrCast(*const clang.StringLiteral, decl_init);
4274 const string_lit = @as(*const clang.StringLiteral, @ptrCast(decl_init));
42344275 return transQualTypeInitializedStringLiteral(c, elem_ty, string_lit);
42354276 },
42364277 .InitListExprClass => {
4237 const init_expr = @ptrCast(*const clang.InitListExpr, decl_init);
4278 const init_expr = @as(*const clang.InitListExpr, @ptrCast(decl_init));
42384279 const size = init_expr.getNumInits();
42394280
42404281 if (init_expr.isStringLiteralInit()) {
......@@ -4265,7 +4306,7 @@ fn transQualTypeIntWidthOf(c: *Context, ty: clang.QualType, is_signed: bool) Typ
42654306/// Asserts the type is an integer.
42664307fn transTypeIntWidthOf(c: *Context, ty: *const clang.Type, is_signed: bool) TypeError!Node {
42674308 assert(ty.getTypeClass() == .Builtin);
4268 const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);
4309 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(ty));
42694310 return Tag.type.create(c.arena, switch (builtin_ty.getKind()) {
42704311 .Char_U, .Char_S, .UChar, .SChar, .Char8 => if (is_signed) "i8" else "u8",
42714312 .UShort, .Short => if (is_signed) "c_short" else "c_ushort",
......@@ -4283,7 +4324,7 @@ fn isCBuiltinType(qt: clang.QualType, kind: clang.BuiltinTypeKind) bool {
42834324 const c_type = qualTypeCanon(qt);
42844325 if (c_type.getTypeClass() != .Builtin)
42854326 return false;
4286 const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);
4327 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(c_type));
42874328 return builtin_ty.getKind() == kind;
42884329}
42894330
......@@ -4300,7 +4341,7 @@ fn qualTypeIntBitWidth(c: *Context, qt: clang.QualType) !u32 {
43004341
43014342 switch (ty.getTypeClass()) {
43024343 .Builtin => {
4303 const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);
4344 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(ty));
43044345
43054346 switch (builtin_ty.getKind()) {
43064347 .Char_U,
......@@ -4317,9 +4358,9 @@ fn qualTypeIntBitWidth(c: *Context, qt: clang.QualType) !u32 {
43174358 unreachable;
43184359 },
43194360 .Typedef => {
4320 const typedef_ty = @ptrCast(*const clang.TypedefType, ty);
4361 const typedef_ty = @as(*const clang.TypedefType, @ptrCast(ty));
43214362 const typedef_decl = typedef_ty.getDecl();
4322 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());
43234364
43244365 if (mem.eql(u8, type_name, "uint8_t") or mem.eql(u8, type_name, "int8_t")) {
43254366 return 8;
......@@ -4337,19 +4378,6 @@ fn qualTypeIntBitWidth(c: *Context, qt: clang.QualType) !u32 {
43374378 }
43384379}
43394380
4340fn qualTypeToLog2IntRef(c: *Context, scope: *Scope, qt: clang.QualType, source_loc: clang.SourceLocation) !Node {
4341 const int_bit_width = try qualTypeIntBitWidth(c, qt);
4342
4343 if (int_bit_width != 0) {
4344 // we can perform the log2 now.
4345 const cast_bit_width = math.log2_int(u64, int_bit_width);
4346 return Tag.log2_int_type.create(c.arena, cast_bit_width);
4347 }
4348
4349 const zig_type = try transQualType(c, scope, qt, source_loc);
4350 return Tag.std_math_Log2Int.create(c.arena, zig_type);
4351}
4352
43534381fn qualTypeChildIsFnProto(qt: clang.QualType) bool {
43544382 const ty = qualTypeCanon(qt);
43554383
......@@ -4368,12 +4396,12 @@ fn getExprQualType(c: *Context, expr: *const clang.Expr) clang.QualType {
43684396 blk: {
43694397 // If this is a C `char *`, turn it into a `const char *`
43704398 if (expr.getStmtClass() != .ImplicitCastExprClass) break :blk;
4371 const cast_expr = @ptrCast(*const clang.ImplicitCastExpr, expr);
4399 const cast_expr = @as(*const clang.ImplicitCastExpr, @ptrCast(expr));
43724400 if (cast_expr.getCastKind() != .ArrayToPointerDecay) break :blk;
43734401 const sub_expr = cast_expr.getSubExpr();
43744402 if (sub_expr.getStmtClass() != .StringLiteralClass) break :blk;
43754403 const array_qt = sub_expr.getType();
4376 const array_type = @ptrCast(*const clang.ArrayType, array_qt.getTypePtr());
4404 const array_type = @as(*const clang.ArrayType, @ptrCast(array_qt.getTypePtr()));
43774405 var pointee_qt = array_type.getElementType();
43784406 pointee_qt.addConst();
43794407 return c.clang_context.getPointerType(pointee_qt);
......@@ -4384,11 +4412,11 @@ fn getExprQualType(c: *Context, expr: *const clang.Expr) clang.QualType {
43844412fn typeIsOpaque(c: *Context, ty: *const clang.Type, loc: clang.SourceLocation) bool {
43854413 switch (ty.getTypeClass()) {
43864414 .Builtin => {
4387 const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);
4415 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(ty));
43884416 return builtin_ty.getKind() == .Void;
43894417 },
43904418 .Record => {
4391 const record_ty = @ptrCast(*const clang.RecordType, ty);
4419 const record_ty = @as(*const clang.RecordType, @ptrCast(ty));
43924420 const record_decl = record_ty.getDecl();
43934421 const record_def = record_decl.getDefinition() orelse
43944422 return true;
......@@ -4404,12 +4432,12 @@ fn typeIsOpaque(c: *Context, ty: *const clang.Type, loc: clang.SourceLocation) b
44044432 return false;
44054433 },
44064434 .Elaborated => {
4407 const elaborated_ty = @ptrCast(*const clang.ElaboratedType, ty);
4435 const elaborated_ty = @as(*const clang.ElaboratedType, @ptrCast(ty));
44084436 const qt = elaborated_ty.getNamedType();
44094437 return typeIsOpaque(c, qt.getTypePtr(), loc);
44104438 },
44114439 .Typedef => {
4412 const typedef_ty = @ptrCast(*const clang.TypedefType, ty);
4440 const typedef_ty = @as(*const clang.TypedefType, @ptrCast(ty));
44134441 const typedef_decl = typedef_ty.getDecl();
44144442 const underlying_type = typedef_decl.getUnderlyingType();
44154443 return typeIsOpaque(c, underlying_type.getTypePtr(), loc);
......@@ -4431,7 +4459,7 @@ fn qualTypeIsCharStar(qt: clang.QualType) bool {
44314459fn cIsUnqualifiedChar(qt: clang.QualType) bool {
44324460 const c_type = qualTypeCanon(qt);
44334461 if (c_type.getTypeClass() != .Builtin) return false;
4434 const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);
4462 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(c_type));
44354463 return switch (builtin_ty.getKind()) {
44364464 .Char_S, .Char_U => true,
44374465 else => false,
......@@ -4445,7 +4473,7 @@ fn cIsInteger(qt: clang.QualType) bool {
44454473fn cIsUnsignedInteger(qt: clang.QualType) bool {
44464474 const c_type = qualTypeCanon(qt);
44474475 if (c_type.getTypeClass() != .Builtin) return false;
4448 const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);
4476 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(c_type));
44494477 return switch (builtin_ty.getKind()) {
44504478 .Char_U,
44514479 .UChar,
......@@ -4464,7 +4492,7 @@ fn cIsUnsignedInteger(qt: clang.QualType) bool {
44644492fn cIntTypeToIndex(qt: clang.QualType) u8 {
44654493 const c_type = qualTypeCanon(qt);
44664494 assert(c_type.getTypeClass() == .Builtin);
4467 const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);
4495 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(c_type));
44684496 return switch (builtin_ty.getKind()) {
44694497 .Bool, .Char_U, .Char_S, .UChar, .SChar, .Char8 => 1,
44704498 .WChar_U, .WChar_S => 2,
......@@ -4485,9 +4513,9 @@ fn cIntTypeCmp(a: clang.QualType, b: clang.QualType) math.Order {
44854513
44864514/// Checks if expr is an integer literal >= 0
44874515fn cIsNonNegativeIntLiteral(c: *Context, expr: *const clang.Expr) bool {
4488 if (@ptrCast(*const clang.Stmt, expr).getStmtClass() == .IntegerLiteralClass) {
4516 if (@as(*const clang.Stmt, @ptrCast(expr)).getStmtClass() == .IntegerLiteralClass) {
44894517 var signum: c_int = undefined;
4490 if (!(@ptrCast(*const clang.IntegerLiteral, expr).getSignum(&signum, c.clang_context))) {
4518 if (!(@as(*const clang.IntegerLiteral, @ptrCast(expr)).getSignum(&signum, c.clang_context))) {
44914519 return false;
44924520 }
44934521 return signum >= 0;
......@@ -4498,7 +4526,7 @@ fn cIsNonNegativeIntLiteral(c: *Context, expr: *const clang.Expr) bool {
44984526fn cIsSignedInteger(qt: clang.QualType) bool {
44994527 const c_type = qualTypeCanon(qt);
45004528 if (c_type.getTypeClass() != .Builtin) return false;
4501 const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);
4529 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(c_type));
45024530 return switch (builtin_ty.getKind()) {
45034531 .SChar,
45044532 .Short,
......@@ -4515,14 +4543,14 @@ fn cIsSignedInteger(qt: clang.QualType) bool {
45154543fn cIsNativeInt(qt: clang.QualType) bool {
45164544 const c_type = qualTypeCanon(qt);
45174545 if (c_type.getTypeClass() != .Builtin) return false;
4518 const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);
4546 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(c_type));
45194547 return builtin_ty.getKind() == .Int;
45204548}
45214549
45224550fn cIsFloating(qt: clang.QualType) bool {
45234551 const c_type = qualTypeCanon(qt);
45244552 if (c_type.getTypeClass() != .Builtin) return false;
4525 const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);
4553 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(c_type));
45264554 return switch (builtin_ty.getKind()) {
45274555 .Float,
45284556 .Double,
......@@ -4536,7 +4564,7 @@ fn cIsFloating(qt: clang.QualType) bool {
45364564fn cIsLongLongInteger(qt: clang.QualType) bool {
45374565 const c_type = qualTypeCanon(qt);
45384566 if (c_type.getTypeClass() != .Builtin) return false;
4539 const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type);
4567 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(c_type));
45404568 return switch (builtin_ty.getKind()) {
45414569 .LongLong, .ULongLong, .Int128, .UInt128 => true,
45424570 else => false,
......@@ -4653,8 +4681,8 @@ fn transCreateNodeAPInt(c: *Context, int: *const clang.APSInt) !Node {
46534681 limb_i += 2;
46544682 data_i += 1;
46554683 }) {
4656 limbs[limb_i] = @truncate(u32, data[data_i]);
4657 limbs[limb_i + 1] = @truncate(u32, data[data_i] >> 32);
4684 limbs[limb_i] = @as(u32, @truncate(data[data_i]));
4685 limbs[limb_i + 1] = @as(u32, @truncate(data[data_i] >> 32));
46584686 }
46594687 },
46604688 else => @compileError("unimplemented"),
......@@ -4731,14 +4759,12 @@ fn transCreateNodeShiftOp(
47314759
47324760 const lhs_expr = stmt.getLHS();
47334761 const rhs_expr = stmt.getRHS();
4734 const rhs_location = rhs_expr.getBeginLoc();
47354762 // lhs >> @as(u5, rh)
47364763
47374764 const lhs = try transExpr(c, scope, lhs_expr, .used);
47384765
4739 const rhs_type = try qualTypeToLog2IntRef(c, scope, stmt.getType(), rhs_location);
47404766 const rhs = try transExprCoercing(c, scope, rhs_expr, .used);
4741 const rhs_casted = try Tag.int_cast.create(c.arena, .{ .lhs = rhs_type, .rhs = rhs });
4767 const rhs_casted = try Tag.int_cast.create(c.arena, rhs);
47424768
47434769 return transCreateNodeInfixOp(c, op, lhs, rhs_casted, used);
47444770}
......@@ -4746,7 +4772,7 @@ fn transCreateNodeShiftOp(
47464772fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clang.SourceLocation) TypeError!Node {
47474773 switch (ty.getTypeClass()) {
47484774 .Builtin => {
4749 const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);
4775 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(ty));
47504776 return Tag.type.create(c.arena, switch (builtin_ty.getKind()) {
47514777 .Void => "anyopaque",
47524778 .Bool => "bool",
......@@ -4771,17 +4797,17 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
47714797 });
47724798 },
47734799 .FunctionProto => {
4774 const fn_proto_ty = @ptrCast(*const clang.FunctionProtoType, ty);
4800 const fn_proto_ty = @as(*const clang.FunctionProtoType, @ptrCast(ty));
47754801 const fn_proto = try transFnProto(c, null, fn_proto_ty, source_loc, null, false);
47764802 return Node.initPayload(&fn_proto.base);
47774803 },
47784804 .FunctionNoProto => {
4779 const fn_no_proto_ty = @ptrCast(*const clang.FunctionType, ty);
4805 const fn_no_proto_ty = @as(*const clang.FunctionType, @ptrCast(ty));
47804806 const fn_proto = try transFnNoProto(c, fn_no_proto_ty, source_loc, null, false);
47814807 return Node.initPayload(&fn_proto.base);
47824808 },
47834809 .Paren => {
4784 const paren_ty = @ptrCast(*const clang.ParenType, ty);
4810 const paren_ty = @as(*const clang.ParenType, @ptrCast(ty));
47854811 return transQualType(c, scope, paren_ty.getInnerType(), source_loc);
47864812 },
47874813 .Pointer => {
......@@ -4806,7 +4832,7 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
48064832 return Tag.c_pointer.create(c.arena, ptr_info);
48074833 },
48084834 .ConstantArray => {
4809 const const_arr_ty = @ptrCast(*const clang.ConstantArrayType, ty);
4835 const const_arr_ty = @as(*const clang.ConstantArrayType, @ptrCast(ty));
48104836
48114837 const size_ap_int = const_arr_ty.getSize();
48124838 const size = size_ap_int.getLimitedValue(usize);
......@@ -4815,7 +4841,7 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
48154841 return Tag.array_type.create(c.arena, .{ .len = size, .elem_type = elem_type });
48164842 },
48174843 .IncompleteArray => {
4818 const incomplete_array_ty = @ptrCast(*const clang.IncompleteArrayType, ty);
4844 const incomplete_array_ty = @as(*const clang.IncompleteArrayType, @ptrCast(ty));
48194845
48204846 const child_qt = incomplete_array_ty.getElementType();
48214847 const is_const = child_qt.isConstQualified();
......@@ -4825,11 +4851,11 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
48254851 return Tag.c_pointer.create(c.arena, .{ .is_const = is_const, .is_volatile = is_volatile, .elem_type = elem_type });
48264852 },
48274853 .Typedef => {
4828 const typedef_ty = @ptrCast(*const clang.TypedefType, ty);
4854 const typedef_ty = @as(*const clang.TypedefType, @ptrCast(ty));
48294855
48304856 const typedef_decl = typedef_ty.getDecl();
48314857 var trans_scope = scope;
4832 if (@ptrCast(*const clang.Decl, typedef_decl).castToNamedDecl()) |named_decl| {
4858 if (@as(*const clang.Decl, @ptrCast(typedef_decl)).castToNamedDecl()) |named_decl| {
48334859 const decl_name = try c.str(named_decl.getName_bytes_begin());
48344860 if (c.global_names.get(decl_name)) |_| trans_scope = &c.global_scope.base;
48354861 if (builtin_typedef_map.get(decl_name)) |builtin| return Tag.type.create(c.arena, builtin);
......@@ -4839,11 +4865,11 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
48394865 return Tag.identifier.create(c.arena, name);
48404866 },
48414867 .Record => {
4842 const record_ty = @ptrCast(*const clang.RecordType, ty);
4868 const record_ty = @as(*const clang.RecordType, @ptrCast(ty));
48434869
48444870 const record_decl = record_ty.getDecl();
48454871 var trans_scope = scope;
4846 if (@ptrCast(*const clang.Decl, record_decl).castToNamedDecl()) |named_decl| {
4872 if (@as(*const clang.Decl, @ptrCast(record_decl)).castToNamedDecl()) |named_decl| {
48474873 const decl_name = try c.str(named_decl.getName_bytes_begin());
48484874 if (c.global_names.get(decl_name)) |_| trans_scope = &c.global_scope.base;
48494875 }
......@@ -4852,11 +4878,11 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
48524878 return Tag.identifier.create(c.arena, name);
48534879 },
48544880 .Enum => {
4855 const enum_ty = @ptrCast(*const clang.EnumType, ty);
4881 const enum_ty = @as(*const clang.EnumType, @ptrCast(ty));
48564882
48574883 const enum_decl = enum_ty.getDecl();
48584884 var trans_scope = scope;
4859 if (@ptrCast(*const clang.Decl, enum_decl).castToNamedDecl()) |named_decl| {
4885 if (@as(*const clang.Decl, @ptrCast(enum_decl)).castToNamedDecl()) |named_decl| {
48604886 const decl_name = try c.str(named_decl.getName_bytes_begin());
48614887 if (c.global_names.get(decl_name)) |_| trans_scope = &c.global_scope.base;
48624888 }
......@@ -4865,27 +4891,27 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
48654891 return Tag.identifier.create(c.arena, name);
48664892 },
48674893 .Elaborated => {
4868 const elaborated_ty = @ptrCast(*const clang.ElaboratedType, ty);
4894 const elaborated_ty = @as(*const clang.ElaboratedType, @ptrCast(ty));
48694895 return transQualType(c, scope, elaborated_ty.getNamedType(), source_loc);
48704896 },
48714897 .Decayed => {
4872 const decayed_ty = @ptrCast(*const clang.DecayedType, ty);
4898 const decayed_ty = @as(*const clang.DecayedType, @ptrCast(ty));
48734899 return transQualType(c, scope, decayed_ty.getDecayedType(), source_loc);
48744900 },
48754901 .Attributed => {
4876 const attributed_ty = @ptrCast(*const clang.AttributedType, ty);
4902 const attributed_ty = @as(*const clang.AttributedType, @ptrCast(ty));
48774903 return transQualType(c, scope, attributed_ty.getEquivalentType(), source_loc);
48784904 },
48794905 .MacroQualified => {
4880 const macroqualified_ty = @ptrCast(*const clang.MacroQualifiedType, ty);
4906 const macroqualified_ty = @as(*const clang.MacroQualifiedType, @ptrCast(ty));
48814907 return transQualType(c, scope, macroqualified_ty.getModifiedType(), source_loc);
48824908 },
48834909 .TypeOf => {
4884 const typeof_ty = @ptrCast(*const clang.TypeOfType, ty);
4910 const typeof_ty = @as(*const clang.TypeOfType, @ptrCast(ty));
48854911 return transQualType(c, scope, typeof_ty.getUnmodifiedType(), source_loc);
48864912 },
48874913 .TypeOfExpr => {
4888 const typeofexpr_ty = @ptrCast(*const clang.TypeOfExprType, ty);
4914 const typeofexpr_ty = @as(*const clang.TypeOfExprType, @ptrCast(ty));
48894915 const underlying_expr = transExpr(c, scope, typeofexpr_ty.getUnderlyingExpr(), .used) catch |err| switch (err) {
48904916 error.UnsupportedTranslation => {
48914917 return fail(c, error.UnsupportedType, source_loc, "unsupported underlying expression for TypeOfExpr", .{});
......@@ -4895,7 +4921,7 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
48954921 return Tag.typeof.create(c.arena, underlying_expr);
48964922 },
48974923 .Vector => {
4898 const vector_ty = @ptrCast(*const clang.VectorType, ty);
4924 const vector_ty = @as(*const clang.VectorType, @ptrCast(ty));
48994925 const num_elements = vector_ty.getNumElements();
49004926 const element_qt = vector_ty.getElementType();
49014927 return Tag.vector.create(c.arena, .{
......@@ -4918,14 +4944,14 @@ fn qualTypeWasDemotedToOpaque(c: *Context, qt: clang.QualType) bool {
49184944 const ty = qt.getTypePtr();
49194945 switch (qt.getTypeClass()) {
49204946 .Typedef => {
4921 const typedef_ty = @ptrCast(*const clang.TypedefType, ty);
4947 const typedef_ty = @as(*const clang.TypedefType, @ptrCast(ty));
49224948
49234949 const typedef_decl = typedef_ty.getDecl();
49244950 const underlying_type = typedef_decl.getUnderlyingType();
49254951 return qualTypeWasDemotedToOpaque(c, underlying_type);
49264952 },
49274953 .Record => {
4928 const record_ty = @ptrCast(*const clang.RecordType, ty);
4954 const record_ty = @as(*const clang.RecordType, @ptrCast(ty));
49294955
49304956 const record_decl = record_ty.getDecl();
49314957 const canonical = @intFromPtr(record_decl.getCanonicalDecl());
......@@ -4941,26 +4967,26 @@ fn qualTypeWasDemotedToOpaque(c: *Context, qt: clang.QualType) bool {
49414967 return false;
49424968 },
49434969 .Enum => {
4944 const enum_ty = @ptrCast(*const clang.EnumType, ty);
4970 const enum_ty = @as(*const clang.EnumType, @ptrCast(ty));
49454971
49464972 const enum_decl = enum_ty.getDecl();
49474973 const canonical = @intFromPtr(enum_decl.getCanonicalDecl());
49484974 return c.opaque_demotes.contains(canonical);
49494975 },
49504976 .Elaborated => {
4951 const elaborated_ty = @ptrCast(*const clang.ElaboratedType, ty);
4977 const elaborated_ty = @as(*const clang.ElaboratedType, @ptrCast(ty));
49524978 return qualTypeWasDemotedToOpaque(c, elaborated_ty.getNamedType());
49534979 },
49544980 .Decayed => {
4955 const decayed_ty = @ptrCast(*const clang.DecayedType, ty);
4981 const decayed_ty = @as(*const clang.DecayedType, @ptrCast(ty));
49564982 return qualTypeWasDemotedToOpaque(c, decayed_ty.getDecayedType());
49574983 },
49584984 .Attributed => {
4959 const attributed_ty = @ptrCast(*const clang.AttributedType, ty);
4985 const attributed_ty = @as(*const clang.AttributedType, @ptrCast(ty));
49604986 return qualTypeWasDemotedToOpaque(c, attributed_ty.getEquivalentType());
49614987 },
49624988 .MacroQualified => {
4963 const macroqualified_ty = @ptrCast(*const clang.MacroQualifiedType, ty);
4989 const macroqualified_ty = @as(*const clang.MacroQualifiedType, @ptrCast(ty));
49644990 return qualTypeWasDemotedToOpaque(c, macroqualified_ty.getModifiedType());
49654991 },
49664992 else => return false,
......@@ -4971,28 +4997,28 @@ fn isAnyopaque(qt: clang.QualType) bool {
49714997 const ty = qt.getTypePtr();
49724998 switch (ty.getTypeClass()) {
49734999 .Builtin => {
4974 const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);
5000 const builtin_ty = @as(*const clang.BuiltinType, @ptrCast(ty));
49755001 return builtin_ty.getKind() == .Void;
49765002 },
49775003 .Typedef => {
4978 const typedef_ty = @ptrCast(*const clang.TypedefType, ty);
5004 const typedef_ty = @as(*const clang.TypedefType, @ptrCast(ty));
49795005 const typedef_decl = typedef_ty.getDecl();
49805006 return isAnyopaque(typedef_decl.getUnderlyingType());
49815007 },
49825008 .Elaborated => {
4983 const elaborated_ty = @ptrCast(*const clang.ElaboratedType, ty);
5009 const elaborated_ty = @as(*const clang.ElaboratedType, @ptrCast(ty));
49845010 return isAnyopaque(elaborated_ty.getNamedType().getCanonicalType());
49855011 },
49865012 .Decayed => {
4987 const decayed_ty = @ptrCast(*const clang.DecayedType, ty);
5013 const decayed_ty = @as(*const clang.DecayedType, @ptrCast(ty));
49885014 return isAnyopaque(decayed_ty.getDecayedType().getCanonicalType());
49895015 },
49905016 .Attributed => {
4991 const attributed_ty = @ptrCast(*const clang.AttributedType, ty);
5017 const attributed_ty = @as(*const clang.AttributedType, @ptrCast(ty));
49925018 return isAnyopaque(attributed_ty.getEquivalentType().getCanonicalType());
49935019 },
49945020 .MacroQualified => {
4995 const macroqualified_ty = @ptrCast(*const clang.MacroQualifiedType, ty);
5021 const macroqualified_ty = @as(*const clang.MacroQualifiedType, @ptrCast(ty));
49965022 return isAnyopaque(macroqualified_ty.getModifiedType().getCanonicalType());
49975023 },
49985024 else => return false,
......@@ -5040,7 +5066,7 @@ fn transFnProto(
50405066 fn_decl_context: ?FnDeclContext,
50415067 is_pub: bool,
50425068) !*ast.Payload.Func {
5043 const fn_ty = @ptrCast(*const clang.FunctionType, fn_proto_ty);
5069 const fn_ty = @as(*const clang.FunctionType, @ptrCast(fn_proto_ty));
50445070 const cc = try transCC(c, fn_ty, source_loc);
50455071 const is_var_args = fn_proto_ty.isVariadic();
50465072 return finishTransFnProto(c, fn_decl, fn_proto_ty, fn_ty, source_loc, fn_decl_context, is_var_args, cc, is_pub);
......@@ -5082,14 +5108,14 @@ fn finishTransFnProto(
50825108
50835109 var i: usize = 0;
50845110 while (i < param_count) : (i += 1) {
5085 const param_qt = fn_proto_ty.?.getParamType(@intCast(c_uint, i));
5111 const param_qt = fn_proto_ty.?.getParamType(@as(c_uint, @intCast(i)));
50865112 const is_noalias = param_qt.isRestrictQualified();
50875113
50885114 const param_name: ?[]const u8 =
50895115 if (fn_decl) |decl|
50905116 blk: {
5091 const param = decl.getParamDecl(@intCast(c_uint, i));
5092 const param_name: []const u8 = try c.str(@ptrCast(*const clang.NamedDecl, param).getName_bytes_begin());
5117 const param = decl.getParamDecl(@as(c_uint, @intCast(i)));
5118 const param_name: []const u8 = try c.str(@as(*const clang.NamedDecl, @ptrCast(param)).getName_bytes_begin());
50935119 if (param_name.len < 1)
50945120 break :blk null;
50955121
......@@ -5550,7 +5576,7 @@ fn transPreprocessorEntities(c: *Context, unit: *clang.ASTUnit) Error!void {
55505576 tok_list.items.len = 0;
55515577 switch (entity.getKind()) {
55525578 .MacroDefinitionKind => {
5553 const macro = @ptrCast(*clang.MacroDefinitionRecord, entity);
5579 const macro = @as(*clang.MacroDefinitionRecord, @ptrCast(entity));
55545580 const raw_name = macro.getName_getNameStart();
55555581 const begin_loc = macro.getSourceRange_getBegin();
55565582
......@@ -6020,7 +6046,7 @@ fn escapeUnprintables(ctx: *Context, m: *MacroCtx) ![]const u8 {
60206046 if (std.unicode.utf8ValidateSlice(zigified)) return zigified;
60216047
60226048 const formatter = std.fmt.fmtSliceEscapeLower(zigified);
6023 const encoded_size = @intCast(usize, std.fmt.count("{s}", .{formatter}));
6049 const encoded_size = @as(usize, @intCast(std.fmt.count("{s}", .{formatter})));
60246050 var output = try ctx.arena.alloc(u8, encoded_size);
60256051 return std.fmt.bufPrint(output, "{s}", .{formatter}) catch |err| switch (err) {
60266052 error.NoSpaceLeft => unreachable,
......@@ -6513,9 +6539,9 @@ fn parseCPostfixExpr(c: *Context, m: *MacroCtx, scope: *Scope, type_name: ?Node)
65136539 },
65146540 .LBracket => {
65156541 const index_val = try macroIntFromBool(c, try parseCExpr(c, m, scope));
6516 const index = try Tag.int_cast.create(c.arena, .{
6542 const index = try Tag.as.create(c.arena, .{
65176543 .lhs = try Tag.type.create(c.arena, "usize"),
6518 .rhs = index_val,
6544 .rhs = try Tag.int_cast.create(c.arena, index_val),
65196545 });
65206546 node = try Tag.array_access.create(c.arena, .{ .lhs = node, .rhs = index });
65216547 try m.skip(c, .RBracket);
src/translate_c/ast.zig+35-69
......@@ -115,15 +115,10 @@ pub const Node = extern union {
115115
116116 /// @import("std").zig.c_builtins.<name>
117117 import_c_builtin,
118 log2_int_type,
119 /// @import("std").math.Log2Int(operand)
120 std_math_Log2Int,
121 /// @intCast(lhs, rhs)
118 /// @intCast(operand)
122119 int_cast,
123120 /// @import("std").zig.c_translation.promoteIntLiteral(value, type, base)
124121 helpers_promoteIntLiteral,
125 /// @import("std").meta.alignment(value)
126 std_meta_alignment,
127122 /// @import("std").zig.c_translation.signedRemainder(lhs, rhs)
128123 signed_remainder,
129124 /// @divTrunc(lhs, rhs)
......@@ -132,23 +127,23 @@ pub const Node = extern union {
132127 int_from_bool,
133128 /// @as(lhs, rhs)
134129 as,
135 /// @truncate(lhs, rhs)
130 /// @truncate(operand)
136131 truncate,
137 /// @bitCast(lhs, rhs)
132 /// @bitCast(operand)
138133 bit_cast,
139 /// @floatCast(lhs, rhs)
134 /// @floatCast(operand)
140135 float_cast,
141 /// @intFromFloat(lhs, rhs)
136 /// @intFromFloat(operand)
142137 int_from_float,
143 /// @floatFromInt(lhs, rhs)
138 /// @floatFromInt(operand)
144139 float_from_int,
145 /// @ptrFromInt(lhs, rhs)
140 /// @ptrFromInt(operand)
146141 ptr_from_int,
147142 /// @intFromPtr(operand)
148143 int_from_ptr,
149 /// @alignCast(lhs, rhs)
144 /// @alignCast(operand)
150145 align_cast,
151 /// @ptrCast(lhs, rhs)
146 /// @ptrCast(operand)
152147 ptr_cast,
153148 /// @divExact(lhs, rhs)
154149 div_exact,
......@@ -254,7 +249,6 @@ pub const Node = extern union {
254249 .@"comptime",
255250 .@"defer",
256251 .asm_simple,
257 .std_math_Log2Int,
258252 .negate,
259253 .negate_wrap,
260254 .bit_not,
......@@ -270,12 +264,20 @@ pub const Node = extern union {
270264 .switch_else,
271265 .block_single,
272266 .helpers_sizeof,
273 .std_meta_alignment,
274267 .int_from_bool,
275268 .sizeof,
276269 .alignof,
277270 .typeof,
278271 .typeinfo,
272 .align_cast,
273 .truncate,
274 .bit_cast,
275 .float_cast,
276 .int_from_float,
277 .float_from_int,
278 .ptr_from_int,
279 .ptr_cast,
280 .int_cast,
279281 => Payload.UnOp,
280282
281283 .add,
......@@ -314,24 +316,15 @@ pub const Node = extern union {
314316 .bit_xor_assign,
315317 .div_trunc,
316318 .signed_remainder,
317 .int_cast,
318319 .as,
319 .truncate,
320 .bit_cast,
321 .float_cast,
322 .int_from_float,
323 .float_from_int,
324 .ptr_from_int,
325320 .array_cat,
326321 .ellipsis3,
327322 .assign,
328 .align_cast,
329323 .array_access,
330324 .std_mem_zeroinit,
331325 .helpers_flexible_array_type,
332326 .helpers_shuffle_vector_index,
333327 .vector,
334 .ptr_cast,
335328 .div_exact,
336329 .offset_of,
337330 .helpers_cast,
......@@ -367,7 +360,6 @@ pub const Node = extern union {
367360 .c_pointer, .single_pointer => Payload.Pointer,
368361 .array_type, .null_sentinel_array_type => Payload.Array,
369362 .arg_redecl, .alias, .fail_decl => Payload.ArgRedecl,
370 .log2_int_type => Payload.Log2IntType,
371363 .var_simple, .pub_var_simple, .static_local_var, .mut_str => Payload.SimpleVarDecl,
372364 .enum_constant => Payload.EnumConstant,
373365 .array_filler => Payload.ArrayFiller,
......@@ -401,7 +393,7 @@ pub const Node = extern union {
401393
402394 pub fn tag(self: Node) Tag {
403395 if (self.tag_if_small_enough < Tag.no_payload_count) {
404 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))));
405397 } else {
406398 return self.ptr_otherwise.tag;
407399 }
......@@ -644,11 +636,6 @@ pub const Payload = struct {
644636 },
645637 };
646638
647 pub const Log2IntType = struct {
648 base: Payload,
649 data: std.math.Log2Int(u64),
650 };
651
652639 pub const SimpleVarDecl = struct {
653640 base: Payload,
654641 data: struct {
......@@ -791,7 +778,7 @@ pub fn render(gpa: Allocator, nodes: []const Node) !std.zig.Ast {
791778
792779 try ctx.tokens.append(gpa, .{
793780 .tag = .eof,
794 .start = @intCast(u32, ctx.buf.items.len),
781 .start = @as(u32, @intCast(ctx.buf.items.len)),
795782 });
796783
797784 return std.zig.Ast{
......@@ -821,10 +808,10 @@ const Context = struct {
821808
822809 try c.tokens.append(c.gpa, .{
823810 .tag = tag,
824 .start = @intCast(u32, start_index),
811 .start = @as(u32, @intCast(start_index)),
825812 });
826813
827 return @intCast(u32, c.tokens.len - 1);
814 return @as(u32, @intCast(c.tokens.len - 1));
828815 }
829816
830817 fn addToken(c: *Context, tag: TokenTag, bytes: []const u8) Allocator.Error!TokenIndex {
......@@ -840,13 +827,13 @@ const Context = struct {
840827 fn listToSpan(c: *Context, list: []const NodeIndex) Allocator.Error!NodeSubRange {
841828 try c.extra_data.appendSlice(c.gpa, list);
842829 return NodeSubRange{
843 .start = @intCast(NodeIndex, c.extra_data.items.len - list.len),
844 .end = @intCast(NodeIndex, c.extra_data.items.len),
830 .start = @as(NodeIndex, @intCast(c.extra_data.items.len - list.len)),
831 .end = @as(NodeIndex, @intCast(c.extra_data.items.len)),
845832 };
846833 }
847834
848835 fn addNode(c: *Context, elem: std.zig.Ast.Node) Allocator.Error!NodeIndex {
849 const result = @intCast(NodeIndex, c.nodes.len);
836 const result = @as(NodeIndex, @intCast(c.nodes.len));
850837 try c.nodes.append(c.gpa, elem);
851838 return result;
852839 }
......@@ -854,7 +841,7 @@ const Context = struct {
854841 fn addExtra(c: *Context, extra: anytype) Allocator.Error!NodeIndex {
855842 const fields = std.meta.fields(@TypeOf(extra));
856843 try c.extra_data.ensureUnusedCapacity(c.gpa, fields.len);
857 const result = @intCast(u32, c.extra_data.items.len);
844 const result = @as(u32, @intCast(c.extra_data.items.len));
858845 inline for (fields) |field| {
859846 comptime std.debug.assert(field.type == NodeIndex);
860847 c.extra_data.appendAssumeCapacity(@field(extra, field.name));
......@@ -885,11 +872,6 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
885872 try c.buf.append('\n');
886873 return @as(NodeIndex, 0); // error: integer value 0 cannot be coerced to type 'std.mem.Allocator.Error!u32'
887874 },
888 .std_math_Log2Int => {
889 const payload = node.castTag(.std_math_Log2Int).?.data;
890 const import_node = try renderStdImport(c, &.{ "math", "Log2Int" });
891 return renderCall(c, import_node, &.{payload});
892 },
893875 .helpers_cast => {
894876 const payload = node.castTag(.helpers_cast).?.data;
895877 const import_node = try renderStdImport(c, &.{ "zig", "c_translation", "cast" });
......@@ -900,11 +882,6 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
900882 const import_node = try renderStdImport(c, &.{ "zig", "c_translation", "promoteIntLiteral" });
901883 return renderCall(c, import_node, &.{ payload.type, payload.value, payload.base });
902884 },
903 .std_meta_alignment => {
904 const payload = node.castTag(.std_meta_alignment).?.data;
905 const import_node = try renderStdImport(c, &.{ "meta", "alignment" });
906 return renderCall(c, import_node, &.{payload});
907 },
908885 .helpers_sizeof => {
909886 const payload = node.castTag(.helpers_sizeof).?.data;
910887 const import_node = try renderStdImport(c, &.{ "zig", "c_translation", "sizeof" });
......@@ -1081,14 +1058,6 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
10811058 .data = undefined,
10821059 });
10831060 },
1084 .log2_int_type => {
1085 const payload = node.castTag(.log2_int_type).?.data;
1086 return c.addNode(.{
1087 .tag = .identifier,
1088 .main_token = try c.addTokenFmt(.identifier, "u{d}", .{payload}),
1089 .data = undefined,
1090 });
1091 },
10921061 .identifier => {
10931062 const payload = node.castTag(.identifier).?.data;
10941063 return c.addNode(.{
......@@ -1344,7 +1313,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
13441313 },
13451314 .int_cast => {
13461315 const payload = node.castTag(.int_cast).?.data;
1347 return renderBuiltinCall(c, "@intCast", &.{ payload.lhs, payload.rhs });
1316 return renderBuiltinCall(c, "@intCast", &.{payload});
13481317 },
13491318 .signed_remainder => {
13501319 const payload = node.castTag(.signed_remainder).?.data;
......@@ -1365,27 +1334,27 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
13651334 },
13661335 .truncate => {
13671336 const payload = node.castTag(.truncate).?.data;
1368 return renderBuiltinCall(c, "@truncate", &.{ payload.lhs, payload.rhs });
1337 return renderBuiltinCall(c, "@truncate", &.{payload});
13691338 },
13701339 .bit_cast => {
13711340 const payload = node.castTag(.bit_cast).?.data;
1372 return renderBuiltinCall(c, "@bitCast", &.{ payload.lhs, payload.rhs });
1341 return renderBuiltinCall(c, "@bitCast", &.{payload});
13731342 },
13741343 .float_cast => {
13751344 const payload = node.castTag(.float_cast).?.data;
1376 return renderBuiltinCall(c, "@floatCast", &.{ payload.lhs, payload.rhs });
1345 return renderBuiltinCall(c, "@floatCast", &.{payload});
13771346 },
13781347 .int_from_float => {
13791348 const payload = node.castTag(.int_from_float).?.data;
1380 return renderBuiltinCall(c, "@intFromFloat", &.{ payload.lhs, payload.rhs });
1349 return renderBuiltinCall(c, "@intFromFloat", &.{payload});
13811350 },
13821351 .float_from_int => {
13831352 const payload = node.castTag(.float_from_int).?.data;
1384 return renderBuiltinCall(c, "@floatFromInt", &.{ payload.lhs, payload.rhs });
1353 return renderBuiltinCall(c, "@floatFromInt", &.{payload});
13851354 },
13861355 .ptr_from_int => {
13871356 const payload = node.castTag(.ptr_from_int).?.data;
1388 return renderBuiltinCall(c, "@ptrFromInt", &.{ payload.lhs, payload.rhs });
1357 return renderBuiltinCall(c, "@ptrFromInt", &.{payload});
13891358 },
13901359 .int_from_ptr => {
13911360 const payload = node.castTag(.int_from_ptr).?.data;
......@@ -1393,11 +1362,11 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
13931362 },
13941363 .align_cast => {
13951364 const payload = node.castTag(.align_cast).?.data;
1396 return renderBuiltinCall(c, "@alignCast", &.{ payload.lhs, payload.rhs });
1365 return renderBuiltinCall(c, "@alignCast", &.{payload});
13971366 },
13981367 .ptr_cast => {
13991368 const payload = node.castTag(.ptr_cast).?.data;
1400 return renderBuiltinCall(c, "@ptrCast", &.{ payload.lhs, payload.rhs });
1369 return renderBuiltinCall(c, "@ptrCast", &.{payload});
14011370 },
14021371 .div_exact => {
14031372 const payload = node.castTag(.div_exact).?.data;
......@@ -2330,14 +2299,11 @@ fn renderNodeGrouped(c: *Context, node: Node) !NodeIndex {
23302299 .float_from_int,
23312300 .ptr_from_int,
23322301 .std_mem_zeroes,
2333 .std_math_Log2Int,
2334 .log2_int_type,
23352302 .int_from_ptr,
23362303 .sizeof,
23372304 .alignof,
23382305 .typeof,
23392306 .typeinfo,
2340 .std_meta_alignment,
23412307 .vector,
23422308 .helpers_sizeof,
23432309 .helpers_cast,
src/type.zig+14-14
......@@ -807,7 +807,7 @@ pub const Type = struct {
807807 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
808808 .ptr_type => |ptr_type| {
809809 if (ptr_type.flags.alignment.toByteUnitsOptional()) |a| {
810 return @intCast(u32, a);
810 return @as(u32, @intCast(a));
811811 } else if (opt_sema) |sema| {
812812 const res = try ptr_type.child.toType().abiAlignmentAdvanced(mod, .{ .sema = sema });
813813 return res.scalar;
......@@ -886,7 +886,7 @@ pub const Type = struct {
886886 },
887887 .vector_type => |vector_type| {
888888 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));
890890 const bytes = ((bits * vector_type.len) + 7) / 8;
891891 const alignment = std.math.ceilPowerOfTwoAssert(u32, bytes);
892892 return AbiAlignmentAdvanced{ .scalar = alignment };
......@@ -901,7 +901,7 @@ pub const Type = struct {
901901 // represents machine code; not a pointer
902902 .func_type => |func_type| return AbiAlignmentAdvanced{
903903 .scalar = if (func_type.alignment.toByteUnitsOptional()) |a|
904 @intCast(u32, a)
904 @as(u32, @intCast(a))
905905 else
906906 target_util.defaultFunctionAlignment(target),
907907 },
......@@ -1015,7 +1015,7 @@ pub const Type = struct {
10151015 else => |e| return e,
10161016 })) continue;
10171017
1018 const field_align = @intCast(u32, field.abi_align.toByteUnitsOptional() orelse
1018 const field_align = @as(u32, @intCast(field.abi_align.toByteUnitsOptional() orelse
10191019 switch (try field.ty.abiAlignmentAdvanced(mod, strat)) {
10201020 .scalar => |a| a,
10211021 .val => switch (strat) {
......@@ -1026,7 +1026,7 @@ pub const Type = struct {
10261026 .storage = .{ .lazy_align = ty.toIntern() },
10271027 } })).toValue() },
10281028 },
1029 });
1029 }));
10301030 big_align = @max(big_align, field_align);
10311031
10321032 // This logic is duplicated in Module.Struct.Field.alignment.
......@@ -1221,7 +1221,7 @@ pub const Type = struct {
12211221 else => |e| return e,
12221222 })) continue;
12231223
1224 const field_align = @intCast(u32, field.abi_align.toByteUnitsOptional() orelse
1224 const field_align = @as(u32, @intCast(field.abi_align.toByteUnitsOptional() orelse
12251225 switch (try field.ty.abiAlignmentAdvanced(mod, strat)) {
12261226 .scalar => |a| a,
12271227 .val => switch (strat) {
......@@ -1232,7 +1232,7 @@ pub const Type = struct {
12321232 .storage = .{ .lazy_align = ty.toIntern() },
12331233 } })).toValue() },
12341234 },
1235 });
1235 }));
12361236 max_align = @max(max_align, field_align);
12371237 }
12381238 return AbiAlignmentAdvanced{ .scalar = max_align };
......@@ -1307,7 +1307,7 @@ pub const Type = struct {
13071307 } })).toValue() },
13081308 };
13091309 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));
13111311 const total_bits = elem_bits * vector_type.len;
13121312 const total_bytes = (total_bits + 7) / 8;
13131313 const alignment = switch (try ty.abiAlignmentAdvanced(mod, strat)) {
......@@ -1573,12 +1573,12 @@ pub const Type = struct {
15731573
15741574 fn intAbiSize(bits: u16, target: Target) u64 {
15751575 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);
15771577 }
15781578
15791579 fn intAbiAlignment(bits: u16, target: Target) u32 {
15801580 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))),
15821582 target.maxIntAlignment(),
15831583 );
15841584 }
......@@ -2166,7 +2166,7 @@ pub const Type = struct {
21662166 pub fn vectorLen(ty: Type, mod: *const Module) u32 {
21672167 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
21682168 .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)),
21702170 else => unreachable,
21712171 };
21722172 }
......@@ -3124,7 +3124,7 @@ pub const Type = struct {
31243124 for (struct_obj.fields.values(), 0..) |f, i| {
31253125 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)));
31283128 if (i == field_index) {
31293129 bit_offset = running_bits;
31303130 elem_size_bits = field_bits;
......@@ -3385,8 +3385,8 @@ pub const Type = struct {
33853385 pub fn smallestUnsignedBits(max: u64) u16 {
33863386 if (max == 0) return 0;
33873387 const base = std.math.log2(max);
3388 const upper = (@as(u64, 1) << @intCast(u6, base)) - 1;
3389 return @intCast(u16, base + @intFromBool(upper < max));
3388 const upper = (@as(u64, 1) << @as(u6, @intCast(base))) - 1;
3389 return @as(u16, @intCast(base + @intFromBool(upper < max)));
33903390 }
33913391
33923392 /// 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 {
112112 return self.castTag(T.base_tag);
113113 }
114114 inline for (@typeInfo(Tag).Enum.fields) |field| {
115 const t = @enumFromInt(Tag, field.value);
115 const t = @as(Tag, @enumFromInt(field.value));
116116 if (self.legacy.ptr_otherwise.tag == t) {
117117 if (T == t.Type()) {
118118 return @fieldParentPtr(T, "base", self.legacy.ptr_otherwise);
......@@ -203,8 +203,8 @@ pub const Value = struct {
203203 .bytes => |bytes| try ip.getOrPutString(mod.gpa, bytes),
204204 .elems => try arrayToIpString(val, ty.arrayLen(mod), mod),
205205 .repeated_elem => |elem| {
206 const byte = @intCast(u8, elem.toValue().toUnsignedInt(mod));
207 const len = @intCast(usize, ty.arrayLen(mod));
206 const byte = @as(u8, @intCast(elem.toValue().toUnsignedInt(mod)));
207 const len = @as(usize, @intCast(ty.arrayLen(mod)));
208208 try ip.string_bytes.appendNTimes(mod.gpa, byte, len);
209209 return ip.getOrPutTrailingString(mod.gpa, len);
210210 },
......@@ -226,8 +226,8 @@ pub const Value = struct {
226226 .bytes => |bytes| try allocator.dupe(u8, bytes),
227227 .elems => try arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, mod),
228228 .repeated_elem => |elem| {
229 const byte = @intCast(u8, elem.toValue().toUnsignedInt(mod));
230 const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen(mod)));
229 const byte = @as(u8, @intCast(elem.toValue().toUnsignedInt(mod)));
230 const result = try allocator.alloc(u8, @as(usize, @intCast(ty.arrayLen(mod))));
231231 @memset(result, byte);
232232 return result;
233233 },
......@@ -237,10 +237,10 @@ pub const Value = struct {
237237 }
238238
239239 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)));
241241 for (result, 0..) |*elem, i| {
242242 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)));
244244 }
245245 return result;
246246 }
......@@ -248,7 +248,7 @@ pub const Value = struct {
248248 fn arrayToIpString(val: Value, len_u64: u64, mod: *Module) !InternPool.NullTerminatedString {
249249 const gpa = mod.gpa;
250250 const ip = &mod.intern_pool;
251 const len = @intCast(usize, len_u64);
251 const len = @as(usize, @intCast(len_u64));
252252 try ip.string_bytes.ensureUnusedCapacity(gpa, len);
253253 for (0..len) |i| {
254254 // I don't think elemValue has the possibility to affect ip.string_bytes. Let's
......@@ -256,7 +256,7 @@ pub const Value = struct {
256256 const prev = ip.string_bytes.items.len;
257257 const elem_val = try val.elemValue(mod, i);
258258 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)));
260260 ip.string_bytes.appendAssumeCapacity(byte);
261261 }
262262 return ip.getOrPutTrailingString(gpa, len);
......@@ -303,7 +303,7 @@ pub const Value = struct {
303303 } });
304304 },
305305 .aggregate => {
306 const len = @intCast(usize, ty.arrayLen(mod));
306 const len = @as(usize, @intCast(ty.arrayLen(mod)));
307307 const old_elems = val.castTag(.aggregate).?.data[0..len];
308308 const new_elems = try mod.gpa.alloc(InternPool.Index, old_elems.len);
309309 defer mod.gpa.free(new_elems);
......@@ -534,7 +534,7 @@ pub const Value = struct {
534534 const base_addr = (try field.base.toValue().getUnsignedIntAdvanced(mod, opt_sema)) orelse return null;
535535 const struct_ty = mod.intern_pool.typeOf(field.base).toType().childType(mod);
536536 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);
538538 },
539539 else => null,
540540 },
......@@ -561,9 +561,9 @@ pub const Value = struct {
561561 .int => |int| switch (int.storage) {
562562 .big_int => |big_int| big_int.to(i64) catch unreachable,
563563 .i64 => |x| x,
564 .u64 => |x| @intCast(i64, x),
565 .lazy_align => |ty| @intCast(i64, ty.toType().abiAlignment(mod)),
566 .lazy_size => |ty| @intCast(i64, ty.toType().abiSize(mod)),
564 .u64 => |x| @as(i64, @intCast(x)),
565 .lazy_align => |ty| @as(i64, @intCast(ty.toType().abiAlignment(mod))),
566 .lazy_size => |ty| @as(i64, @intCast(ty.toType().abiSize(mod))),
567567 },
568568 else => unreachable,
569569 },
......@@ -604,7 +604,7 @@ pub const Value = struct {
604604 const target = mod.getTarget();
605605 const endian = target.cpu.arch.endian();
606606 if (val.isUndef(mod)) {
607 const size = @intCast(usize, ty.abiSize(mod));
607 const size = @as(usize, @intCast(ty.abiSize(mod)));
608608 @memset(buffer[0..size], 0xaa);
609609 return;
610610 }
......@@ -623,17 +623,17 @@ pub const Value = struct {
623623 bigint.writeTwosComplement(buffer[0..byte_count], endian);
624624 },
625625 .Float => switch (ty.floatBits(target)) {
626 16 => std.mem.writeInt(u16, buffer[0..2], @bitCast(u16, val.toFloat(f16, mod)), endian),
627 32 => std.mem.writeInt(u32, buffer[0..4], @bitCast(u32, val.toFloat(f32, mod)), endian),
628 64 => std.mem.writeInt(u64, buffer[0..8], @bitCast(u64, val.toFloat(f64, mod)), endian),
629 80 => std.mem.writeInt(u80, buffer[0..10], @bitCast(u80, val.toFloat(f80, mod)), endian),
630 128 => std.mem.writeInt(u128, buffer[0..16], @bitCast(u128, val.toFloat(f128, 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], @as(u32, @bitCast(val.toFloat(f32, 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], @as(u80, @bitCast(val.toFloat(f80, mod))), endian),
630 128 => std.mem.writeInt(u128, buffer[0..16], @as(u128, @bitCast(val.toFloat(f128, mod))), endian),
631631 else => unreachable,
632632 },
633633 .Array => {
634634 const len = ty.arrayLen(mod);
635635 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)));
637637 var elem_i: usize = 0;
638638 var buf_off: usize = 0;
639639 while (elem_i < len) : (elem_i += 1) {
......@@ -645,13 +645,13 @@ pub const Value = struct {
645645 .Vector => {
646646 // We use byte_count instead of abi_size here, so that any padding bytes
647647 // 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;
649649 return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0);
650650 },
651651 .Struct => switch (ty.containerLayout(mod)) {
652652 .Auto => return error.IllDefinedMemoryLayout,
653653 .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)));
655655 const field_val = switch (val.ip_index) {
656656 .none => switch (val.tag()) {
657657 .bytes => {
......@@ -674,7 +674,7 @@ pub const Value = struct {
674674 try writeToMemory(field_val, field.ty, mod, buffer[off..]);
675675 },
676676 .Packed => {
677 const byte_count = (@intCast(usize, ty.bitSize(mod)) + 7) / 8;
677 const byte_count = (@as(usize, @intCast(ty.bitSize(mod))) + 7) / 8;
678678 return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0);
679679 },
680680 },
......@@ -686,14 +686,14 @@ pub const Value = struct {
686686 .error_union => |error_union| error_union.val.err_name,
687687 else => unreachable,
688688 };
689 const int = @intCast(Module.ErrorInt, mod.global_error_set.getIndex(name).?);
690 std.mem.writeInt(Int, buffer[0..@sizeOf(Int)], @intCast(Int, int), endian);
689 const int = @as(Module.ErrorInt, @intCast(mod.global_error_set.getIndex(name).?));
690 std.mem.writeInt(Int, buffer[0..@sizeOf(Int)], @as(Int, @intCast(int)), endian);
691691 },
692692 .Union => switch (ty.containerLayout(mod)) {
693693 .Auto => return error.IllDefinedMemoryLayout,
694694 .Extern => return error.Unimplemented,
695695 .Packed => {
696 const byte_count = (@intCast(usize, ty.bitSize(mod)) + 7) / 8;
696 const byte_count = (@as(usize, @intCast(ty.bitSize(mod))) + 7) / 8;
697697 return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0);
698698 },
699699 },
......@@ -730,7 +730,7 @@ pub const Value = struct {
730730 const target = mod.getTarget();
731731 const endian = target.cpu.arch.endian();
732732 if (val.isUndef(mod)) {
733 const bit_size = @intCast(usize, ty.bitSize(mod));
733 const bit_size = @as(usize, @intCast(ty.bitSize(mod)));
734734 std.mem.writeVarPackedInt(buffer, bit_offset, bit_size, @as(u1, 0), endian);
735735 return;
736736 }
......@@ -742,9 +742,9 @@ pub const Value = struct {
742742 .Big => buffer.len - bit_offset / 8 - 1,
743743 };
744744 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)));
746746 } 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)));
748748 }
749749 },
750750 .Int, .Enum => {
......@@ -759,17 +759,17 @@ pub const Value = struct {
759759 }
760760 },
761761 .Float => switch (ty.floatBits(target)) {
762 16 => std.mem.writePackedInt(u16, buffer, bit_offset, @bitCast(u16, val.toFloat(f16, mod)), endian),
763 32 => std.mem.writePackedInt(u32, buffer, bit_offset, @bitCast(u32, val.toFloat(f32, mod)), endian),
764 64 => std.mem.writePackedInt(u64, buffer, bit_offset, @bitCast(u64, val.toFloat(f64, mod)), endian),
765 80 => std.mem.writePackedInt(u80, buffer, bit_offset, @bitCast(u80, val.toFloat(f80, mod)), endian),
766 128 => std.mem.writePackedInt(u128, buffer, bit_offset, @bitCast(u128, val.toFloat(f128, 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, @as(u32, @bitCast(val.toFloat(f32, 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, @as(u80, @bitCast(val.toFloat(f80, mod))), endian),
766 128 => std.mem.writePackedInt(u128, buffer, bit_offset, @as(u128, @bitCast(val.toFloat(f128, mod))), endian),
767767 else => unreachable,
768768 },
769769 .Vector => {
770770 const elem_ty = ty.childType(mod);
771 const elem_bit_size = @intCast(u16, elem_ty.bitSize(mod));
772 const len = @intCast(usize, ty.arrayLen(mod));
771 const elem_bit_size = @as(u16, @intCast(elem_ty.bitSize(mod)));
772 const len = @as(usize, @intCast(ty.arrayLen(mod)));
773773
774774 var bits: u16 = 0;
775775 var elem_i: usize = 0;
......@@ -789,7 +789,7 @@ pub const Value = struct {
789789 const fields = ty.structFields(mod).values();
790790 const storage = mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage;
791791 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)));
793793 const field_val = switch (storage) {
794794 .bytes => unreachable,
795795 .elems => |elems| elems[i],
......@@ -865,12 +865,12 @@ pub const Value = struct {
865865 if (bits <= 64) switch (int_info.signedness) { // Fast path for integers <= u64
866866 .signed => {
867867 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));
869869 return mod.getCoerced(try mod.intValue(int_ty, result), ty);
870870 },
871871 .unsigned => {
872872 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));
874874 return mod.getCoerced(try mod.intValue(int_ty, result), ty);
875875 },
876876 } else { // Slow path, we have to construct a big-int
......@@ -886,22 +886,22 @@ pub const Value = struct {
886886 .Float => return (try mod.intern(.{ .float = .{
887887 .ty = ty.toIntern(),
888888 .storage = switch (ty.floatBits(target)) {
889 16 => .{ .f16 = @bitCast(f16, std.mem.readInt(u16, buffer[0..2], endian)) },
890 32 => .{ .f32 = @bitCast(f32, std.mem.readInt(u32, buffer[0..4], endian)) },
891 64 => .{ .f64 = @bitCast(f64, std.mem.readInt(u64, buffer[0..8], endian)) },
892 80 => .{ .f80 = @bitCast(f80, std.mem.readInt(u80, buffer[0..10], endian)) },
893 128 => .{ .f128 = @bitCast(f128, std.mem.readInt(u128, buffer[0..16], endian)) },
889 16 => .{ .f16 = @as(f16, @bitCast(std.mem.readInt(u16, buffer[0..2], endian))) },
890 32 => .{ .f32 = @as(f32, @bitCast(std.mem.readInt(u32, buffer[0..4], endian))) },
891 64 => .{ .f64 = @as(f64, @bitCast(std.mem.readInt(u64, buffer[0..8], endian))) },
892 80 => .{ .f80 = @as(f80, @bitCast(std.mem.readInt(u80, buffer[0..10], endian))) },
893 128 => .{ .f128 = @as(f128, @bitCast(std.mem.readInt(u128, buffer[0..16], endian))) },
894894 else => unreachable,
895895 },
896896 } })).toValue(),
897897 .Array => {
898898 const elem_ty = ty.childType(mod);
899899 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))));
901901 var offset: usize = 0;
902902 for (elems) |*elem| {
903903 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));
905905 }
906906 return (try mod.intern(.{ .aggregate = .{
907907 .ty = ty.toIntern(),
......@@ -911,7 +911,7 @@ pub const Value = struct {
911911 .Vector => {
912912 // We use byte_count instead of abi_size here, so that any padding bytes
913913 // 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;
915915 return readFromPackedMemory(ty, mod, buffer[0..byte_count], 0, arena);
916916 },
917917 .Struct => switch (ty.containerLayout(mod)) {
......@@ -920,8 +920,8 @@ pub const Value = struct {
920920 const fields = ty.structFields(mod).values();
921921 const field_vals = try arena.alloc(InternPool.Index, fields.len);
922922 for (field_vals, fields, 0..) |*field_val, field, i| {
923 const off = @intCast(usize, ty.structFieldOffset(i, mod));
924 const sz = @intCast(usize, field.ty.abiSize(mod));
923 const off = @as(usize, @intCast(ty.structFieldOffset(i, mod)));
924 const sz = @as(usize, @intCast(field.ty.abiSize(mod)));
925925 field_val.* = try (try readFromMemory(field.ty, mod, buffer[off..(off + sz)], arena)).intern(field.ty, mod);
926926 }
927927 return (try mod.intern(.{ .aggregate = .{
......@@ -930,7 +930,7 @@ pub const Value = struct {
930930 } })).toValue();
931931 },
932932 .Packed => {
933 const byte_count = (@intCast(usize, ty.bitSize(mod)) + 7) / 8;
933 const byte_count = (@as(usize, @intCast(ty.bitSize(mod))) + 7) / 8;
934934 return readFromPackedMemory(ty, mod, buffer[0..byte_count], 0, arena);
935935 },
936936 },
......@@ -938,7 +938,7 @@ pub const Value = struct {
938938 // TODO revisit this when we have the concept of the error tag type
939939 const Int = u16;
940940 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))];
942942 return (try mod.intern(.{ .err = .{
943943 .ty = ty.toIntern(),
944944 .name = name,
......@@ -977,7 +977,7 @@ pub const Value = struct {
977977 .Big => buffer[buffer.len - bit_offset / 8 - 1],
978978 .Little => buffer[bit_offset / 8],
979979 };
980 if (((byte >> @intCast(u3, bit_offset % 8)) & 1) == 0) {
980 if (((byte >> @as(u3, @intCast(bit_offset % 8))) & 1) == 0) {
981981 return Value.false;
982982 } else {
983983 return Value.true;
......@@ -1009,7 +1009,7 @@ pub const Value = struct {
10091009 }
10101010
10111011 // 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)));
10131013 const Limb = std.math.big.Limb;
10141014 const limb_count = (abi_size + @sizeOf(Limb) - 1) / @sizeOf(Limb);
10151015 const limbs_buffer = try arena.alloc(Limb, limb_count);
......@@ -1021,20 +1021,20 @@ pub const Value = struct {
10211021 .Float => return (try mod.intern(.{ .float = .{
10221022 .ty = ty.toIntern(),
10231023 .storage = switch (ty.floatBits(target)) {
1024 16 => .{ .f16 = @bitCast(f16, std.mem.readPackedInt(u16, buffer, bit_offset, endian)) },
1025 32 => .{ .f32 = @bitCast(f32, std.mem.readPackedInt(u32, buffer, bit_offset, endian)) },
1026 64 => .{ .f64 = @bitCast(f64, std.mem.readPackedInt(u64, buffer, bit_offset, endian)) },
1027 80 => .{ .f80 = @bitCast(f80, std.mem.readPackedInt(u80, buffer, bit_offset, endian)) },
1028 128 => .{ .f128 = @bitCast(f128, std.mem.readPackedInt(u128, buffer, bit_offset, endian)) },
1024 16 => .{ .f16 = @as(f16, @bitCast(std.mem.readPackedInt(u16, buffer, bit_offset, endian))) },
1025 32 => .{ .f32 = @as(f32, @bitCast(std.mem.readPackedInt(u32, buffer, bit_offset, endian))) },
1026 64 => .{ .f64 = @as(f64, @bitCast(std.mem.readPackedInt(u64, buffer, bit_offset, endian))) },
1027 80 => .{ .f80 = @as(f80, @bitCast(std.mem.readPackedInt(u80, buffer, bit_offset, endian))) },
1028 128 => .{ .f128 = @as(f128, @bitCast(std.mem.readPackedInt(u128, buffer, bit_offset, endian))) },
10291029 else => unreachable,
10301030 },
10311031 } })).toValue(),
10321032 .Vector => {
10331033 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
10361036 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)));
10381038 for (elems, 0..) |_, i| {
10391039 // On big-endian systems, LLVM reverses the element order of vectors by default
10401040 const tgt_elem_i = if (endian == .Big) elems.len - i - 1 else i;
......@@ -1054,7 +1054,7 @@ pub const Value = struct {
10541054 const fields = ty.structFields(mod).values();
10551055 const field_vals = try arena.alloc(InternPool.Index, fields.len);
10561056 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)));
10581058 field_vals[i] = try (try readFromPackedMemory(field.ty, mod, buffer, bit_offset + bits, arena)).intern(field.ty, mod);
10591059 bits += field_bits;
10601060 }
......@@ -1081,18 +1081,18 @@ pub const Value = struct {
10811081 pub fn toFloat(val: Value, comptime T: type, mod: *Module) T {
10821082 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
10831083 .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))),
10851085 inline .u64, .i64 => |x| {
10861086 if (T == f80) {
10871087 @panic("TODO we can't lower this properly on non-x86 llvm backend yet");
10881088 }
1089 return @floatFromInt(T, x);
1089 return @as(T, @floatFromInt(x));
10901090 },
1091 .lazy_align => |ty| @floatFromInt(T, ty.toType().abiAlignment(mod)),
1092 .lazy_size => |ty| @floatFromInt(T, ty.toType().abiSize(mod)),
1091 .lazy_align => |ty| @as(T, @floatFromInt(ty.toType().abiAlignment(mod))),
1092 .lazy_size => |ty| @as(T, @floatFromInt(ty.toType().abiSize(mod))),
10931093 },
10941094 .float => |float| switch (float.storage) {
1095 inline else => |x| @floatCast(T, x),
1095 inline else => |x| @as(T, @floatCast(x)),
10961096 },
10971097 else => unreachable,
10981098 };
......@@ -1107,7 +1107,7 @@ pub const Value = struct {
11071107 var i: usize = limbs.len;
11081108 while (i != 0) {
11091109 i -= 1;
1110 const limb: f128 = @floatFromInt(f128, limbs[i]);
1110 const limb: f128 = @as(f128, @floatFromInt(limbs[i]));
11111111 result = @mulAdd(f128, base, result, limb);
11121112 }
11131113 if (positive) {
......@@ -1132,7 +1132,7 @@ pub const Value = struct {
11321132 pub fn popCount(val: Value, ty: Type, mod: *Module) u64 {
11331133 var bigint_buf: BigIntSpace = undefined;
11341134 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)));
11361136 }
11371137
11381138 pub fn bitReverse(val: Value, ty: Type, mod: *Module, arena: Allocator) !Value {
......@@ -1505,10 +1505,10 @@ pub const Value = struct {
15051505 .int, .eu_payload => unreachable,
15061506 .opt_payload => |base| base.toValue().elemValue(mod, index),
15071507 .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))),
15091509 .field => |field| if (field.base.toValue().pointerDecl(mod)) |decl_index| {
15101510 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)));
15121512 return field_val.elemValue(mod, index);
15131513 } else unreachable,
15141514 },
......@@ -1604,18 +1604,18 @@ pub const Value = struct {
16041604 .comptime_field => |comptime_field| comptime_field.toValue()
16051605 .sliceArray(mod, arena, start, end),
16061606 .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))),
16081608 else => unreachable,
16091609 },
16101610 .aggregate => |aggregate| (try mod.intern(.{ .aggregate = .{
16111611 .ty = switch (mod.intern_pool.indexToKey(mod.intern_pool.typeOf(val.toIntern()))) {
16121612 .array_type => |array_type| try mod.arrayType(.{
1613 .len = @intCast(u32, end - start),
1613 .len = @as(u32, @intCast(end - start)),
16141614 .child = array_type.child,
16151615 .sentinel = if (end == array_type.len) array_type.sentinel else .none,
16161616 }),
16171617 .vector_type => |vector_type| try mod.vectorType(.{
1618 .len = @intCast(u32, end - start),
1618 .len = @as(u32, @intCast(end - start)),
16191619 .child = vector_type.child,
16201620 }),
16211621 else => unreachable,
......@@ -1734,7 +1734,7 @@ pub const Value = struct {
17341734 .simple_value => |v| v == .undefined,
17351735 .ptr => |ptr| switch (ptr.len) {
17361736 .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| {
17381738 if (try (try val.elemValue(mod, index)).anyUndef(mod)) break true;
17391739 } else false,
17401740 },
......@@ -1783,7 +1783,7 @@ pub const Value = struct {
17831783
17841784 pub fn getErrorInt(val: Value, mod: *const Module) Module.ErrorInt {
17851785 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).?))
17871787 else
17881788 0;
17891789 }
......@@ -1868,11 +1868,11 @@ pub const Value = struct {
18681868 fn floatFromIntInner(x: anytype, dest_ty: Type, mod: *Module) !Value {
18691869 const target = mod.getTarget();
18701870 const storage: InternPool.Key.Float.Storage = switch (dest_ty.floatBits(target)) {
1871 16 => .{ .f16 = @floatFromInt(f16, x) },
1872 32 => .{ .f32 = @floatFromInt(f32, x) },
1873 64 => .{ .f64 = @floatFromInt(f64, x) },
1874 80 => .{ .f80 = @floatFromInt(f80, x) },
1875 128 => .{ .f128 = @floatFromInt(f128, x) },
1871 16 => .{ .f16 = @as(f16, @floatFromInt(x)) },
1872 32 => .{ .f32 = @as(f32, @floatFromInt(x)) },
1873 64 => .{ .f64 = @as(f64, @floatFromInt(x)) },
1874 80 => .{ .f80 = @as(f80, @floatFromInt(x)) },
1875 128 => .{ .f128 = @as(f128, @floatFromInt(x)) },
18761876 else => unreachable,
18771877 };
18781878 return (try mod.intern(.{ .float = .{
......@@ -1887,7 +1887,7 @@ pub const Value = struct {
18871887 }
18881888
18891889 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;
18911891 }
18921892
18931893 pub const OverflowArithmeticResult = struct {
......@@ -2738,14 +2738,14 @@ pub const Value = struct {
27382738 for (result_data, 0..) |*scalar, i| {
27392739 const elem_val = try val.elemValue(mod, i);
27402740 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);
27422742 }
27432743 return (try mod.intern(.{ .aggregate = .{
27442744 .ty = ty.toIntern(),
27452745 .storage = .{ .elems = result_data },
27462746 } })).toValue();
27472747 }
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);
27492749 }
27502750
27512751 pub fn intTruncScalar(
......@@ -2793,7 +2793,7 @@ pub const Value = struct {
27932793 // resorting to BigInt first.
27942794 var lhs_space: Value.BigIntSpace = undefined;
27952795 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)));
27972797 const limbs = try allocator.alloc(
27982798 std.math.big.Limb,
27992799 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,
......@@ -2855,7 +2855,7 @@ pub const Value = struct {
28552855 const info = ty.intInfo(mod);
28562856 var lhs_space: Value.BigIntSpace = undefined;
28572857 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)));
28592859 const limbs = try allocator.alloc(
28602860 std.math.big.Limb,
28612861 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,
......@@ -2912,7 +2912,7 @@ pub const Value = struct {
29122912
29132913 var lhs_space: Value.BigIntSpace = undefined;
29142914 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)));
29162916 const limbs = try arena.alloc(
29172917 std.math.big.Limb,
29182918 std.math.big.int.calcTwosCompLimbCount(info.bits) + 1,
......@@ -2984,7 +2984,7 @@ pub const Value = struct {
29842984 // resorting to BigInt first.
29852985 var lhs_space: Value.BigIntSpace = undefined;
29862986 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
29892989 const result_limbs = lhs_bigint.limbs.len -| (shift / (@sizeOf(std.math.big.Limb) * 8));
29902990 if (result_limbs == 0) {
stage1/zig1.wasm
Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ
test/behavior/align.zig+12-16
......@@ -24,7 +24,7 @@ test "slicing array of length 1 can not assume runtime index is always zero" {
2424 const slice = @as(*align(4) [1]u8, &foo)[runtime_index..];
2525 try expect(@TypeOf(slice) == []u8);
2626 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);
2828}
2929
3030test "default alignment allows unspecified in type syntax" {
......@@ -47,7 +47,7 @@ test "@alignCast pointers" {
4747 try expect(x == 2);
4848}
4949fn expectsOnly1(x: *align(1) u32) void {
50 expects4(@alignCast(4, x));
50 expects4(@alignCast(x));
5151}
5252fn expects4(x: *align(4) u32) void {
5353 x.* += 1;
......@@ -213,12 +213,6 @@ test "alignment and size of structs with 128-bit fields" {
213213 }
214214}
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
222216test "alignstack" {
223217 try expect(fnWithAlignedStack() == 1234);
224218}
......@@ -249,7 +243,7 @@ test "specifying alignment allows pointer cast" {
249243}
250244fn testBytesAlign(b: u8) !void {
251245 var bytes align(4) = [_]u8{ b, b, b, b };
252 const ptr = @ptrCast(*u32, &bytes[0]);
246 const ptr = @as(*u32, @ptrCast(&bytes[0]));
253247 try expect(ptr.* == 0x33333333);
254248}
255249
......@@ -265,7 +259,7 @@ test "@alignCast slices" {
265259 try expect(slice[0] == 2);
266260}
267261fn sliceExpectsOnly1(slice: []align(1) u32) void {
268 sliceExpects4(@alignCast(4, slice));
262 sliceExpects4(@alignCast(slice));
269263}
270264fn sliceExpects4(slice: []align(4) u32) void {
271265 slice[0] += 1;
......@@ -302,8 +296,8 @@ test "page aligned array on stack" {
302296 try expect(@intFromPtr(&array[0]) & 0xFFF == 0);
303297 try expect(array[3] == 4);
304298
305 try expect(@truncate(u4, @intFromPtr(&number1)) == 0);
306 try expect(@truncate(u4, @intFromPtr(&number2)) == 0);
299 try expect(@as(u4, @truncate(@intFromPtr(&number1))) == 0);
300 try expect(@as(u4, @truncate(@intFromPtr(&number2))) == 0);
307301 try expect(number1 == 42);
308302 try expect(number2 == 43);
309303}
......@@ -366,7 +360,7 @@ test "@alignCast functions" {
366360 try expect(fnExpectsOnly1(simple4) == 0x19);
367361}
368362fn fnExpectsOnly1(ptr: *const fn () align(1) i32) i32 {
369 return fnExpects4(@alignCast(4, ptr));
363 return fnExpects4(@alignCast(ptr));
370364}
371365fn fnExpects4(ptr: *const fn () align(4) i32) i32 {
372366 return ptr();
......@@ -461,9 +455,11 @@ fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) !void {
461455test "alignment of function with c calling convention" {
462456 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
463457
458 const a = @alignOf(@TypeOf(nothing));
459
464460 var runtime_nothing = &nothing;
465 const casted1 = @ptrCast(*const u8, runtime_nothing);
466 const casted2 = @ptrCast(*const fn () callconv(.C) void, casted1);
461 const casted1: *align(a) const u8 = @ptrCast(runtime_nothing);
462 const casted2: *const fn () callconv(.C) void = @ptrCast(casted1);
467463 casted2();
468464}
469465
......@@ -588,7 +584,7 @@ test "@alignCast null" {
588584 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
589585
590586 var ptr: ?*anyopaque = null;
591 const aligned: ?*anyopaque = @alignCast(@alignOf(?*anyopaque), ptr);
587 const aligned: ?*anyopaque = @alignCast(ptr);
592588 try expect(aligned == null);
593589}
594590
test/behavior/array.zig+2-2
......@@ -170,7 +170,7 @@ test "array with sentinels" {
170170 {
171171 var zero_sized: [0:0xde]u8 = [_:0xde]u8{};
172172 try expect(zero_sized[0] == 0xde);
173 var reinterpreted = @ptrCast(*[1]u8, &zero_sized);
173 var reinterpreted = @as(*[1]u8, @ptrCast(&zero_sized));
174174 try expect(reinterpreted[0] == 0xde);
175175 }
176176 var arr: [3:0x55]u8 = undefined;
......@@ -694,7 +694,7 @@ test "array init of container level array variable" {
694694test "runtime initialized sentinel-terminated array literal" {
695695 var c: u16 = 300;
696696 const f = &[_:0x9999]u16{c};
697 const g = @ptrCast(*const [4]u8, f);
697 const g = @as(*const [4]u8, @ptrCast(f));
698698 try std.testing.expect(g[2] == 0x99);
699699 try std.testing.expect(g[3] == 0x99);
700700}
test/behavior/async_fn.zig+5-5
......@@ -136,12 +136,12 @@ test "@frameSize" {
136136 const S = struct {
137137 fn doTheTest() !void {
138138 {
139 var ptr = @ptrCast(fn (i32) callconv(.Async) void, other);
139 var ptr = @as(fn (i32) callconv(.Async) void, @ptrCast(other));
140140 const size = @frameSize(ptr);
141141 try expect(size == @sizeOf(@Frame(other)));
142142 }
143143 {
144 var ptr = @ptrCast(fn () callconv(.Async) void, first);
144 var ptr = @as(fn () callconv(.Async) void, @ptrCast(first));
145145 const size = @frameSize(ptr);
146146 try expect(size == @sizeOf(@Frame(first)));
147147 }
......@@ -1184,7 +1184,7 @@ test "using @TypeOf on a generic function call" {
11841184 global_frame = @frame();
11851185 }
11861186 const F = @TypeOf(async amain(x - 1));
1187 const frame = @ptrFromInt(*F, @intFromPtr(&buf));
1187 const frame = @as(*F, @ptrFromInt(@intFromPtr(&buf)));
11881188 return await @asyncCall(frame, {}, amain, .{x - 1});
11891189 }
11901190 };
......@@ -1212,7 +1212,7 @@ test "recursive call of await @asyncCall with struct return type" {
12121212 global_frame = @frame();
12131213 }
12141214 const F = @TypeOf(async amain(x - 1));
1215 const frame = @ptrFromInt(*F, @intFromPtr(&buf));
1215 const frame = @as(*F, @ptrFromInt(@intFromPtr(&buf)));
12161216 return await @asyncCall(frame, {}, amain, .{x - 1});
12171217 }
12181218
......@@ -1833,7 +1833,7 @@ test "avoid forcing frame alignment resolution implicit cast to *anyopaque" {
18331833 }
18341834 };
18351835 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)));
18371837 try expect(nosuspend await frame);
18381838}
18391839
test/behavior/atomics.zig+1-1
......@@ -326,7 +326,7 @@ fn testAtomicRmwInt128(comptime signedness: std.builtin.Signedness) !void {
326326 const uint = std.meta.Int(.unsigned, 128);
327327 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)));
330330 const replacement: int = 0x00000000_00000005_00000000_00000003;
331331
332332 var x: int align(16) = initial;
test/behavior/basic.zig+11-11
......@@ -20,7 +20,7 @@ test "truncate" {
2020 try comptime expect(testTruncate(0x10fd) == 0xfd);
2121}
2222fn testTruncate(x: u32) u8 {
23 return @truncate(u8, x);
23 return @as(u8, @truncate(x));
2424}
2525
2626test "truncate to non-power-of-two integers" {
......@@ -56,7 +56,7 @@ test "truncate to non-power-of-two integers from 128-bit" {
5656}
5757
5858fn 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);
6060}
6161
6262const g1: i32 = 1233 + 1;
......@@ -229,9 +229,9 @@ test "opaque types" {
229229
230230const global_a: i32 = 1234;
231231const 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));
233233test "compile time global reinterpret" {
234 const d = @ptrCast(*const i32, global_c);
234 const d = @as(*const i32, @ptrCast(global_c));
235235 try expect(d.* == 1234);
236236}
237237
......@@ -362,7 +362,7 @@ test "variable is allowed to be a pointer to an opaque type" {
362362 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
363363
364364 var x: i32 = 1234;
365 _ = hereIsAnOpaqueType(@ptrCast(*OpaqueA, &x));
365 _ = hereIsAnOpaqueType(@as(*OpaqueA, @ptrCast(&x)));
366366}
367367fn hereIsAnOpaqueType(ptr: *OpaqueA) *OpaqueA {
368368 var a = ptr;
......@@ -442,7 +442,7 @@ test "array 3D const double ptr with offset" {
442442}
443443
444444fn testArray2DConstDoublePtr(ptr: *const f32) !void {
445 const ptr2 = @ptrCast([*]const f32, ptr);
445 const ptr2 = @as([*]const f32, @ptrCast(ptr));
446446 try expect(ptr2[0] == 1.0);
447447 try expect(ptr2[1] == 2.0);
448448}
......@@ -574,9 +574,9 @@ test "constant equal function pointers" {
574574
575575fn emptyFn() void {}
576576
577const addr1 = @ptrCast(*const u8, &emptyFn);
577const addr1 = @as(*const u8, @ptrCast(&emptyFn));
578578test "comptime cast fn to ptr" {
579 const addr2 = @ptrCast(*const u8, &emptyFn);
579 const addr2 = @as(*const u8, @ptrCast(&emptyFn));
580580 try comptime expect(addr1 == addr2);
581581}
582582
......@@ -667,7 +667,7 @@ test "string escapes" {
667667
668668test "explicit cast optional pointers" {
669669 const a: ?*i32 = undefined;
670 const b: ?*f32 = @ptrCast(?*f32, a);
670 const b: ?*f32 = @as(?*f32, @ptrCast(a));
671671 _ = b;
672672}
673673
......@@ -752,7 +752,7 @@ test "auto created variables have correct alignment" {
752752
753753 const S = struct {
754754 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| {
756756 return v;
757757 }
758758 return 0;
......@@ -772,7 +772,7 @@ test "extern variable with non-pointer opaque type" {
772772 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
773773
774774 @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);
776776}
777777extern var opaque_extern_var: opaque {};
778778var 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
2828 // TODO: https://github.com/ziglang/zig/issues/1544
2929 // This cast could be implicit if we teach the compiler that
3030 // u32 >> 30 -> u2
31 return @intCast(ShardKey, shard_key);
31 return @as(ShardKey, @intCast(shard_key));
3232 }
3333
3434 pub fn put(self: *Self, node: *Node) void {
......@@ -85,14 +85,14 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c
8585 var table = Table.create();
8686 var node_buffer: [node_count]Table.Node = undefined;
8787 for (&node_buffer, 0..) |*node, i| {
88 const key = @intCast(Key, i);
88 const key = @as(Key, @intCast(i));
8989 try expect(table.get(key) == null);
9090 node.init(key, {});
9191 table.put(node);
9292 }
9393
9494 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);
9696 }
9797}
9898
test/behavior/bitcast.zig+37-37
......@@ -71,11 +71,11 @@ fn testBitCast(comptime N: usize) !void {
7171}
7272
7373fn 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));
7575}
7676
7777fn 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));
7979}
8080
8181test "bitcast uX to bytes" {
......@@ -114,14 +114,14 @@ fn testBitCastuXToBytes(comptime N: usize) !void {
114114 while (byte_i < (byte_count - 1)) : (byte_i += 1) {
115115 try expect(bytes[byte_i] == 0xff);
116116 }
117 try expect(((bytes[byte_i] ^ 0xff) << -%@truncate(u3, N)) == 0);
117 try expect(((bytes[byte_i] ^ 0xff) << -%@as(u3, @truncate(N))) == 0);
118118 },
119119 .Big => {
120120 var byte_i = byte_count - 1;
121121 while (byte_i > 0) : (byte_i -= 1) {
122122 try expect(bytes[byte_i] == 0xff);
123123 }
124 try expect(((bytes[byte_i] ^ 0xff) << -%@truncate(u3, N)) == 0);
124 try expect(((bytes[byte_i] ^ 0xff) << -%@as(u3, @truncate(N))) == 0);
125125 },
126126 }
127127 }
......@@ -130,12 +130,12 @@ fn testBitCastuXToBytes(comptime N: usize) !void {
130130test "nested bitcast" {
131131 const S = struct {
132132 fn moo(x: isize) !void {
133 try expect(@intCast(isize, 42) == x);
133 try expect(@as(isize, @intCast(42)) == x);
134134 }
135135
136136 fn foo(x: isize) !void {
137137 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)))),
139139 );
140140 }
141141 };
......@@ -146,7 +146,7 @@ test "nested bitcast" {
146146
147147// issue #3010: compiler segfault
148148test "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 }));
150150 try expect(ip == maxInt(u32));
151151}
152152
......@@ -154,7 +154,7 @@ test "bitcast generates a temporary value" {
154154 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
155155
156156 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))));
158158 try expect(y == x);
159159}
160160
......@@ -175,7 +175,7 @@ test "@bitCast packed structs at runtime and comptime" {
175175 const S = struct {
176176 fn doTheTest() !void {
177177 var full = Full{ .number = 0x1234 };
178 var two_halves = @bitCast(Divided, full);
178 var two_halves = @as(Divided, @bitCast(full));
179179 try expect(two_halves.half1 == 0x34);
180180 try expect(two_halves.quarter3 == 0x2);
181181 try expect(two_halves.quarter4 == 0x1);
......@@ -200,7 +200,7 @@ test "@bitCast extern structs at runtime and comptime" {
200200 const S = struct {
201201 fn doTheTest() !void {
202202 var full = Full{ .number = 0x1234 };
203 var two_halves = @bitCast(TwoHalves, full);
203 var two_halves = @as(TwoHalves, @bitCast(full));
204204 switch (native_endian) {
205205 .Big => {
206206 try expect(two_halves.half1 == 0x12);
......@@ -230,8 +230,8 @@ test "bitcast packed struct to integer and back" {
230230 const S = struct {
231231 fn doTheTest() !void {
232232 var move = LevelUpMove{ .move_id = 1, .level = 2 };
233 var v = @bitCast(u16, move);
234 var back_to_a_move = @bitCast(LevelUpMove, v);
233 var v = @as(u16, @bitCast(move));
234 var back_to_a_move = @as(LevelUpMove, @bitCast(v));
235235 try expect(back_to_a_move.move_id == 1);
236236 try expect(back_to_a_move.level == 2);
237237 }
......@@ -250,7 +250,7 @@ test "implicit cast to error union by returning" {
250250 try expect((func(-1) catch unreachable) == maxInt(u64));
251251 }
252252 pub fn func(sz: i64) anyerror!u64 {
253 return @bitCast(u64, sz);
253 return @as(u64, @bitCast(sz));
254254 }
255255 };
256256 try S.entry();
......@@ -261,7 +261,7 @@ test "bitcast packed struct literal to byte" {
261261 const Foo = packed struct {
262262 value: u8,
263263 };
264 const casted = @bitCast(u8, Foo{ .value = 0xF });
264 const casted = @as(u8, @bitCast(Foo{ .value = 0xF }));
265265 try expect(casted == 0xf);
266266}
267267
......@@ -269,7 +269,7 @@ test "comptime bitcast used in expression has the correct type" {
269269 const Foo = packed struct {
270270 value: u8,
271271 };
272 try expect(@bitCast(u8, Foo{ .value = 0xF }) == 0xf);
272 try expect(@as(u8, @bitCast(Foo{ .value = 0xF })) == 0xf);
273273}
274274
275275test "bitcast passed as tuple element" {
......@@ -279,7 +279,7 @@ test "bitcast passed as tuple element" {
279279 try expect(args[0] == 12.34);
280280 }
281281 };
282 try S.foo(.{@bitCast(f32, @as(u32, 0x414570A4))});
282 try S.foo(.{@as(f32, @bitCast(@as(u32, 0x414570A4)))});
283283}
284284
285285test "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
289289 try expect(args[0] > 12.33 and args[0] < 12.35);
290290 }
291291 };
292 try S.foo(.{@as(f64, @bitCast(f32, @as(u32, 0x414570A4)))});
292 try S.foo(.{@as(f64, @as(f32, @bitCast(@as(u32, 0x414570A4))))});
293293}
294294
295295test "@bitCast packed struct of floats" {
......@@ -318,7 +318,7 @@ test "@bitCast packed struct of floats" {
318318 const S = struct {
319319 fn doTheTest() !void {
320320 var foo = Foo{};
321 var v = @bitCast(Foo2, foo);
321 var v = @as(Foo2, @bitCast(foo));
322322 try expect(v.a == foo.a);
323323 try expect(v.b == foo.b);
324324 try expect(v.c == foo.c);
......@@ -360,12 +360,12 @@ test "comptime @bitCast packed struct to int and back" {
360360
361361 // S -> Int
362362 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
365365 // Int -> S
366366 var i: Int = 0;
367 const rt_cast = @bitCast(S, i);
368 const ct_cast = comptime @bitCast(S, @as(Int, 0));
367 const rt_cast = @as(S, @bitCast(i));
368 const ct_cast = comptime @as(S, @bitCast(@as(Int, 0)));
369369 inline for (@typeInfo(S).Struct.fields) |field| {
370370 try expectEqual(@field(rt_cast, field.name), @field(ct_cast, field.name));
371371 }
......@@ -381,10 +381,10 @@ test "comptime bitcast with fields following f80" {
381381
382382 const FloatT = extern struct { f: f80, x: u128 align(16) };
383383 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);
387 try expect(x.x == @bitCast(FloatT, x_as_uint).x);
386 try expect(x.f == @as(FloatT, @bitCast(x_as_uint)).f);
387 try expect(x.x == @as(FloatT, @bitCast(x_as_uint)).x);
388388}
389389
390390test "bitcast vector to integer and back" {
......@@ -398,20 +398,20 @@ test "bitcast vector to integer and back" {
398398 const arr: [16]bool = [_]bool{ true, false } ++ [_]bool{true} ** 14;
399399 var x = @splat(16, true);
400400 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))));
402402}
403403
404404fn bitCastWrapper16(x: f16) u16 {
405 return @bitCast(u16, x);
405 return @as(u16, @bitCast(x));
406406}
407407fn bitCastWrapper32(x: f32) u32 {
408 return @bitCast(u32, x);
408 return @as(u32, @bitCast(x));
409409}
410410fn bitCastWrapper64(x: f64) u64 {
411 return @bitCast(u64, x);
411 return @as(u64, @bitCast(x));
412412}
413413fn bitCastWrapper128(x: f128) u128 {
414 return @bitCast(u128, x);
414 return @as(u128, @bitCast(x));
415415}
416416test "bitcast nan float does modify signaling bit" {
417417 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
......@@ -425,37 +425,37 @@ test "bitcast nan float does modify signaling bit" {
425425
426426 // 16 bit
427427 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)));
429429 try expectEqual(math.nan_u16, bitCastWrapper16(snan_f16_const));
430430
431431 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)));
433433 try expectEqual(math.nan_u16, bitCastWrapper16(snan_f16_var));
434434
435435 // 32 bit
436436 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)));
438438 try expectEqual(math.nan_u32, bitCastWrapper32(snan_f32_const));
439439
440440 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)));
442442 try expectEqual(math.nan_u32, bitCastWrapper32(snan_f32_var));
443443
444444 // 64 bit
445445 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)));
447447 try expectEqual(math.nan_u64, bitCastWrapper64(snan_f64_const));
448448
449449 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)));
451451 try expectEqual(math.nan_u64, bitCastWrapper64(snan_f64_var));
452452
453453 // 128 bit
454454 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)));
456456 try expectEqual(math.nan_u128, bitCastWrapper128(snan_f128_const));
457457
458458 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)));
460460 try expectEqual(math.nan_u128, bitCastWrapper128(snan_f128_var));
461461}
test/behavior/bitreverse.zig+14-14
......@@ -62,20 +62,20 @@ fn testBitReverse() !void {
6262
6363 // using comptime_ints, signed, positive
6464 try expect(@bitReverse(@as(u8, 0)) == 0);
65 try expect(@bitReverse(@bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49)));
66 try expect(@bitReverse(@bitCast(i16, @as(u16, 0x1234))) == @bitCast(i16, @as(u16, 0x2c48)));
67 try expect(@bitReverse(@bitCast(i24, @as(u24, 0x123456))) == @bitCast(i24, @as(u24, 0x6a2c48)));
68 try expect(@bitReverse(@bitCast(i24, @as(u24, 0x12345f))) == @bitCast(i24, @as(u24, 0xfa2c48)));
69 try expect(@bitReverse(@bitCast(i24, @as(u24, 0xf23456))) == @bitCast(i24, @as(u24, 0x6a2c4f)));
70 try expect(@bitReverse(@bitCast(i32, @as(u32, 0x12345678))) == @bitCast(i32, @as(u32, 0x1e6a2c48)));
71 try expect(@bitReverse(@bitCast(i32, @as(u32, 0xf2345678))) == @bitCast(i32, @as(u32, 0x1e6a2c4f)));
72 try expect(@bitReverse(@bitCast(i32, @as(u32, 0x1234567f))) == @bitCast(i32, @as(u32, 0xfe6a2c48)));
73 try expect(@bitReverse(@bitCast(i40, @as(u40, 0x123456789a))) == @bitCast(i40, @as(u40, 0x591e6a2c48)));
74 try expect(@bitReverse(@bitCast(i48, @as(u48, 0x123456789abc))) == @bitCast(i48, @as(u48, 0x3d591e6a2c48)));
75 try expect(@bitReverse(@bitCast(i56, @as(u56, 0x123456789abcde))) == @bitCast(i56, @as(u56, 0x7b3d591e6a2c48)));
76 try expect(@bitReverse(@bitCast(i64, @as(u64, 0x123456789abcdef1))) == @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48)));
77 try expect(@bitReverse(@bitCast(i96, @as(u96, 0x123456789abcdef111213141))) == @bitCast(i96, @as(u96, 0x828c84888f7b3d591e6a2c48)));
78 try expect(@bitReverse(@bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48)));
65 try expect(@bitReverse(@as(i8, @bitCast(@as(u8, 0x92)))) == @as(i8, @bitCast(@as(u8, 0x49))));
66 try expect(@bitReverse(@as(i16, @bitCast(@as(u16, 0x1234)))) == @as(i16, @bitCast(@as(u16, 0x2c48))));
67 try expect(@bitReverse(@as(i24, @bitCast(@as(u24, 0x123456)))) == @as(i24, @bitCast(@as(u24, 0x6a2c48))));
68 try expect(@bitReverse(@as(i24, @bitCast(@as(u24, 0x12345f)))) == @as(i24, @bitCast(@as(u24, 0xfa2c48))));
69 try expect(@bitReverse(@as(i24, @bitCast(@as(u24, 0xf23456)))) == @as(i24, @bitCast(@as(u24, 0x6a2c4f))));
70 try expect(@bitReverse(@as(i32, @bitCast(@as(u32, 0x12345678)))) == @as(i32, @bitCast(@as(u32, 0x1e6a2c48))));
71 try expect(@bitReverse(@as(i32, @bitCast(@as(u32, 0xf2345678)))) == @as(i32, @bitCast(@as(u32, 0x1e6a2c4f))));
72 try expect(@bitReverse(@as(i32, @bitCast(@as(u32, 0x1234567f)))) == @as(i32, @bitCast(@as(u32, 0xfe6a2c48))));
73 try expect(@bitReverse(@as(i40, @bitCast(@as(u40, 0x123456789a)))) == @as(i40, @bitCast(@as(u40, 0x591e6a2c48))));
74 try expect(@bitReverse(@as(i48, @bitCast(@as(u48, 0x123456789abc)))) == @as(i48, @bitCast(@as(u48, 0x3d591e6a2c48))));
75 try expect(@bitReverse(@as(i56, @bitCast(@as(u56, 0x123456789abcde)))) == @as(i56, @bitCast(@as(u56, 0x7b3d591e6a2c48))));
76 try expect(@bitReverse(@as(i64, @bitCast(@as(u64, 0x123456789abcdef1)))) == @as(i64, @bitCast(@as(u64, 0x8f7b3d591e6a2c48))));
77 try expect(@bitReverse(@as(i96, @bitCast(@as(u96, 0x123456789abcdef111213141)))) == @as(i96, @bitCast(@as(u96, 0x828c84888f7b3d591e6a2c48))));
78 try expect(@bitReverse(@as(i128, @bitCast(@as(u128, 0x123456789abcdef11121314151617181)))) == @as(i128, @bitCast(@as(u128, 0x818e868a828c84888f7b3d591e6a2c48))));
7979
8080 // using signed, negative. Compare to runtime ints returned from llvm.
8181 var neg8: i8 = -18;
test/behavior/bool.zig+4-4
......@@ -15,8 +15,8 @@ test "cast bool to int" {
1515 const f = false;
1616 try expectEqual(@as(u32, 1), @intFromBool(t));
1717 try expectEqual(@as(u32, 0), @intFromBool(f));
18 try expectEqual(-1, @bitCast(i1, @intFromBool(t)));
19 try expectEqual(0, @bitCast(i1, @intFromBool(f)));
18 try expectEqual(-1, @as(i1, @bitCast(@intFromBool(t))));
19 try expectEqual(0, @as(i1, @bitCast(@intFromBool(f))));
2020 try expectEqual(u1, @TypeOf(@intFromBool(t)));
2121 try expectEqual(u1, @TypeOf(@intFromBool(f)));
2222 try nonConstCastIntFromBool(t, f);
......@@ -25,8 +25,8 @@ test "cast bool to int" {
2525fn nonConstCastIntFromBool(t: bool, f: bool) !void {
2626 try expectEqual(@as(u32, 1), @intFromBool(t));
2727 try expectEqual(@as(u32, 0), @intFromBool(f));
28 try expectEqual(@as(i1, -1), @bitCast(i1, @intFromBool(t)));
29 try expectEqual(@as(i1, 0), @bitCast(i1, @intFromBool(f)));
28 try expectEqual(@as(i1, -1), @as(i1, @bitCast(@intFromBool(t))));
29 try expectEqual(@as(i1, 0), @as(i1, @bitCast(@intFromBool(f))));
3030 try expectEqual(u1, @TypeOf(@intFromBool(t)));
3131 try expectEqual(u1, @TypeOf(@intFromBool(f)));
3232}
test/behavior/bugs/11995.zig+1-1
......@@ -25,7 +25,7 @@ test {
2525 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
2626
2727 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 };
2929 var arg_meta = wuffs_base__io_buffer_meta{ .wi = 1, .ri = 2, .pos = 3, .closed = true };
3030 wuffs_base__make_io_buffer(arg_data, &arg_meta);
3131 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 {
3030 return .{
3131 .a = 0,
3232 .b = false,
33 .c = @bitCast(Z, @as(u32, 0)),
34 .d = @bitCast(Z, @as(u32, 0)),
33 .c = @as(Z, @bitCast(@as(u32, 0))),
34 .d = @as(Z, @bitCast(@as(u32, 0))),
3535 };
3636 }
3737};
test/behavior/bugs/12119.zig+1-1
......@@ -12,6 +12,6 @@ test {
1212 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1313
1414 const zerox32: u8x32 = [_]u8{0} ** 32;
15 const bigsum: u32x8 = @bitCast(u32x8, zerox32);
15 const bigsum: u32x8 = @as(u32x8, @bitCast(zerox32));
1616 try std.testing.expectEqual(0, @reduce(.Add, bigsum));
1717}
test/behavior/bugs/12450.zig+1-1
......@@ -16,7 +16,7 @@ test {
1616 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1717 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])));
2020 try expect(@typeInfo(@TypeOf(f1)).Pointer.alignment == 16);
2121 try expect(@intFromPtr(f1) == @intFromPtr(&f1.a));
2222 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;
33test "Non-exhaustive enum backed by comptime_int" {
44 const E = enum(comptime_int) { a, b, c, _ };
55 comptime var e: E = .a;
6 e = @enumFromInt(E, 378089457309184723749);
6 e = @as(E, @enumFromInt(378089457309184723749));
77 try expect(@intFromEnum(e) == 378089457309184723749);
88}
test/behavior/bugs/13664.zig+1-1
......@@ -21,7 +21,7 @@ test {
2121
2222 const timestamp: i64 = value();
2323 const id = ID{ .fields = Fields{
24 .timestamp = @intCast(u50, timestamp),
24 .timestamp = @as(u50, @intCast(timestamp)),
2525 .random_bits = 420,
2626 } };
2727 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 {
1616}
1717
1818fn extractOne64(a: u128) u64 {
19 const x = @bitCast([2]u64, a);
19 const x = @as([2]u64, @bitCast(a));
2020 return x[1];
2121}
test/behavior/bugs/6781.zig+4-4
......@@ -23,7 +23,7 @@ pub const JournalHeader = packed struct {
2323
2424 var target: [32]u8 = undefined;
2525 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].*));
2727 }
2828
2929 pub fn calculate_hash_chain_root(self: *const JournalHeader) u128 {
......@@ -42,16 +42,16 @@ pub const JournalHeader = packed struct {
4242
4343 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.*));
4646 const source = header[prev_hash_chain_root_offset .. checksum_offset + checksum_size];
4747 assert(source.len == prev_hash_chain_root_size + checksum_size);
4848 var target: [32]u8 = undefined;
4949 std.crypto.hash.Blake3.hash(source, target[0..], .{});
5050 if (segfault) {
51 return @bitCast(u128, target[0..hash_chain_root_size].*);
51 return @as(u128, @bitCast(target[0..hash_chain_root_size].*));
5252 } else {
5353 var array = target[0..hash_chain_root_size].*;
54 return @bitCast(u128, array);
54 return @as(u128, @bitCast(array));
5555 }
5656 }
5757
test/behavior/bugs/718.zig+1-1
......@@ -15,7 +15,7 @@ test "zero keys with @memset" {
1515 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1616 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);
1919 try expect(!keys.up);
2020 try expect(!keys.down);
2121 try expect(!keys.left);
test/behavior/bugs/726.zig+2-2
......@@ -8,7 +8,7 @@ test "@ptrCast from const to nullable" {
88 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
99
1010 const c: u8 = 4;
11 var x: ?*const u8 = @ptrCast(?*const u8, &c);
11 var x: ?*const u8 = @as(?*const u8, @ptrCast(&c));
1212 try expect(x.?.* == 4);
1313}
1414
......@@ -21,6 +21,6 @@ test "@ptrCast from var in empty struct to nullable" {
2121 const container = struct {
2222 var c: u8 = 4;
2323 };
24 var x: ?*const u8 = @ptrCast(?*const u8, &container.c);
24 var x: ?*const u8 = @as(?*const u8, @ptrCast(&container.c));
2525 try expect(x.?.* == 4);
2626}
test/behavior/builtin_functions_returning_void_or_noreturn.zig+2-2
......@@ -17,8 +17,8 @@ test {
1717 try testing.expectEqual(void, @TypeOf(@breakpoint()));
1818 try testing.expectEqual({}, @export(x, .{ .name = "x" }));
1919 try testing.expectEqual({}, @fence(.Acquire));
20 try testing.expectEqual({}, @memcpy(@ptrFromInt([*]u8, 1)[0..0], @ptrFromInt([*]u8, 1)[0..0]));
21 try testing.expectEqual({}, @memset(@ptrFromInt([*]u8, 1)[0..0], undefined));
20 try testing.expectEqual({}, @memcpy(@as([*]u8, @ptrFromInt(1))[0..0], @as([*]u8, @ptrFromInt(1))[0..0]));
21 try testing.expectEqual({}, @memset(@as([*]u8, @ptrFromInt(1))[0..0], undefined));
2222 try testing.expectEqual(noreturn, @TypeOf(if (true) @panic("") else {}));
2323 try testing.expectEqual({}, @prefetch(&val, .{}));
2424 try testing.expectEqual({}, @setAlignStack(16));
test/behavior/byteswap.zig+16-16
......@@ -16,13 +16,13 @@ test "@byteSwap integers" {
1616 try t(u8, 0x12, 0x12);
1717 try t(u16, 0x1234, 0x3412);
1818 try t(u24, 0x123456, 0x563412);
19 try t(i24, @bitCast(i24, @as(u24, 0xf23456)), 0x5634f2);
20 try t(i24, 0x1234f6, @bitCast(i24, @as(u24, 0xf63412)));
19 try t(i24, @as(i24, @bitCast(@as(u24, 0xf23456))), 0x5634f2);
20 try t(i24, 0x1234f6, @as(i24, @bitCast(@as(u24, 0xf63412))));
2121 try t(u32, 0x12345678, 0x78563412);
22 try t(i32, @bitCast(i32, @as(u32, 0xf2345678)), 0x785634f2);
23 try t(i32, 0x123456f8, @bitCast(i32, @as(u32, 0xf8563412)));
22 try t(i32, @as(i32, @bitCast(@as(u32, 0xf2345678))), 0x785634f2);
23 try t(i32, 0x123456f8, @as(i32, @bitCast(@as(u32, 0xf8563412))));
2424 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))));
2626 try t(u56, 0x123456789abcde, 0xdebc9a78563412);
2727 try t(u64, 0x123456789abcdef1, 0xf1debc9a78563412);
2828 try t(u88, 0x123456789abcdef1112131, 0x312111f1debc9a78563412);
......@@ -31,19 +31,19 @@ test "@byteSwap integers" {
3131
3232 try t(u0, @as(u0, 0), 0);
3333 try t(i8, @as(i8, -50), -50);
34 try t(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412)));
35 try t(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x563412)));
36 try t(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412)));
37 try t(u40, @bitCast(i40, @as(u40, 0x123456789a)), @as(u40, 0x9a78563412));
38 try t(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412)));
39 try t(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0xdebc9a78563412)));
40 try t(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412)));
41 try t(i88, @bitCast(i88, @as(u88, 0x123456789abcdef1112131)), @bitCast(i88, @as(u88, 0x312111f1debc9a78563412)));
42 try t(i96, @bitCast(i96, @as(u96, 0x123456789abcdef111213141)), @bitCast(i96, @as(u96, 0x41312111f1debc9a78563412)));
34 try t(i16, @as(i16, @bitCast(@as(u16, 0x1234))), @as(i16, @bitCast(@as(u16, 0x3412))));
35 try t(i24, @as(i24, @bitCast(@as(u24, 0x123456))), @as(i24, @bitCast(@as(u24, 0x563412))));
36 try t(i32, @as(i32, @bitCast(@as(u32, 0x12345678))), @as(i32, @bitCast(@as(u32, 0x78563412))));
37 try t(u40, @as(i40, @bitCast(@as(u40, 0x123456789a))), @as(u40, 0x9a78563412));
38 try t(i48, @as(i48, @bitCast(@as(u48, 0x123456789abc))), @as(i48, @bitCast(@as(u48, 0xbc9a78563412))));
39 try t(i56, @as(i56, @bitCast(@as(u56, 0x123456789abcde))), @as(i56, @bitCast(@as(u56, 0xdebc9a78563412))));
40 try t(i64, @as(i64, @bitCast(@as(u64, 0x123456789abcdef1))), @as(i64, @bitCast(@as(u64, 0xf1debc9a78563412))));
41 try t(i88, @as(i88, @bitCast(@as(u88, 0x123456789abcdef1112131))), @as(i88, @bitCast(@as(u88, 0x312111f1debc9a78563412))));
42 try t(i96, @as(i96, @bitCast(@as(u96, 0x123456789abcdef111213141))), @as(i96, @bitCast(@as(u96, 0x41312111f1debc9a78563412))));
4343 try t(
4444 i128,
45 @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)),
46 @bitCast(i128, @as(u128, 0x8171615141312111f1debc9a78563412)),
45 @as(i128, @bitCast(@as(u128, 0x123456789abcdef11121314151617181))),
46 @as(i128, @bitCast(@as(u128, 0x8171615141312111f1debc9a78563412))),
4747 );
4848 }
4949 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" {
368368 }
369369 };
370370 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);
372372 }
373373}
374374
test/behavior/cast.zig+60-60
......@@ -10,13 +10,13 @@ const native_endian = builtin.target.cpu.arch.endian();
1010
1111test "int to ptr cast" {
1212 const x = @as(usize, 13);
13 const y = @ptrFromInt(*u8, x);
13 const y = @as(*u8, @ptrFromInt(x));
1414 const z = @intFromPtr(y);
1515 try expect(z == 13);
1616}
1717
1818test "integer literal to pointer cast" {
19 const vga_mem = @ptrFromInt(*u16, 0xB8000);
19 const vga_mem = @as(*u16, @ptrFromInt(0xB8000));
2020 try expect(@intFromPtr(vga_mem) == 0xB8000);
2121}
2222
......@@ -52,7 +52,7 @@ fn testResolveUndefWithInt(b: bool, x: i32) !void {
5252}
5353
5454test "@intCast to comptime_int" {
55 try expect(@intCast(comptime_int, 0) == 0);
55 try expect(@as(comptime_int, @intCast(0)) == 0);
5656}
5757
5858test "implicit cast comptime numbers to any type when the value fits" {
......@@ -68,29 +68,29 @@ test "implicit cast comptime_int to comptime_float" {
6868
6969test "comptime_int @floatFromInt" {
7070 {
71 const result = @floatFromInt(f16, 1234);
71 const result = @as(f16, @floatFromInt(1234));
7272 try expect(@TypeOf(result) == f16);
7373 try expect(result == 1234.0);
7474 }
7575 {
76 const result = @floatFromInt(f32, 1234);
76 const result = @as(f32, @floatFromInt(1234));
7777 try expect(@TypeOf(result) == f32);
7878 try expect(result == 1234.0);
7979 }
8080 {
81 const result = @floatFromInt(f64, 1234);
81 const result = @as(f64, @floatFromInt(1234));
8282 try expect(@TypeOf(result) == f64);
8383 try expect(result == 1234.0);
8484 }
8585
8686 {
87 const result = @floatFromInt(f128, 1234);
87 const result = @as(f128, @floatFromInt(1234));
8888 try expect(@TypeOf(result) == f128);
8989 try expect(result == 1234.0);
9090 }
9191 // big comptime_int (> 64 bits) to f128 conversion
9292 {
93 const result = @floatFromInt(f128, 0x1_0000_0000_0000_0000);
93 const result = @as(f128, @floatFromInt(0x1_0000_0000_0000_0000));
9494 try expect(@TypeOf(result) == f128);
9595 try expect(result == 0x1_0000_0000_0000_0000.0);
9696 }
......@@ -107,8 +107,8 @@ test "@floatFromInt" {
107107 }
108108
109109 fn testIntToFloat(k: i32) !void {
110 const f = @floatFromInt(f32, k);
111 const i = @intFromFloat(i32, f);
110 const f = @as(f32, @floatFromInt(k));
111 const i = @as(i32, @intFromFloat(f));
112112 try expect(i == k);
113113 }
114114 };
......@@ -131,8 +131,8 @@ test "@floatFromInt(f80)" {
131131
132132 fn testIntToFloat(comptime Int: type, k: Int) !void {
133133 @setRuntimeSafety(false); // TODO
134 const f = @floatFromInt(f80, k);
135 const i = @intFromFloat(Int, f);
134 const f = @as(f80, @floatFromInt(k));
135 const i = @as(Int, @intFromFloat(f));
136136 try expect(i == k);
137137 }
138138 };
......@@ -165,7 +165,7 @@ test "@intFromFloat" {
165165fn testIntFromFloats() !void {
166166 const x = @as(i32, 1e4);
167167 try expect(x == 10000);
168 const y = @intFromFloat(i32, @as(f32, 1e4));
168 const y = @as(i32, @intFromFloat(@as(f32, 1e4)));
169169 try expect(y == 10000);
170170 try expectIntFromFloat(f32, 255.1, u8, 255);
171171 try expectIntFromFloat(f32, 127.2, i8, 127);
......@@ -173,7 +173,7 @@ fn testIntFromFloats() !void {
173173}
174174
175175fn 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);
177177}
178178
179179test "implicitly cast indirect pointer to maybe-indirect pointer" {
......@@ -208,29 +208,29 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
208208}
209209
210210test "@intCast comptime_int" {
211 const result = @intCast(i32, 1234);
211 const result = @as(i32, @intCast(1234));
212212 try expect(@TypeOf(result) == i32);
213213 try expect(result == 1234);
214214}
215215
216216test "@floatCast comptime_int and comptime_float" {
217217 {
218 const result = @floatCast(f16, 1234);
218 const result = @as(f16, @floatCast(1234));
219219 try expect(@TypeOf(result) == f16);
220220 try expect(result == 1234.0);
221221 }
222222 {
223 const result = @floatCast(f16, 1234.0);
223 const result = @as(f16, @floatCast(1234.0));
224224 try expect(@TypeOf(result) == f16);
225225 try expect(result == 1234.0);
226226 }
227227 {
228 const result = @floatCast(f32, 1234);
228 const result = @as(f32, @floatCast(1234));
229229 try expect(@TypeOf(result) == f32);
230230 try expect(result == 1234.0);
231231 }
232232 {
233 const result = @floatCast(f32, 1234.0);
233 const result = @as(f32, @floatCast(1234.0));
234234 try expect(@TypeOf(result) == f32);
235235 try expect(result == 1234.0);
236236 }
......@@ -276,21 +276,21 @@ test "*usize to *void" {
276276 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
277277
278278 var i = @as(usize, 0);
279 var v = @ptrCast(*void, &i);
279 var v = @as(*void, @ptrCast(&i));
280280 v.* = {};
281281}
282282
283283test "@enumFromInt passed a comptime_int to an enum with one item" {
284284 const E = enum { A };
285 const x = @enumFromInt(E, 0);
285 const x = @as(E, @enumFromInt(0));
286286 try expect(x == E.A);
287287}
288288
289289test "@intCast to u0 and use the result" {
290290 const S = struct {
291291 fn doTheTest(zero: u1, one: u1, bigzero: i32) !void {
292 try expect((one << @intCast(u0, bigzero)) == 1);
293 try expect((zero << @intCast(u0, bigzero)) == 0);
292 try expect((one << @as(u0, @intCast(bigzero))) == 1);
293 try expect((zero << @as(u0, @intCast(bigzero))) == 0);
294294 }
295295 };
296296 try S.doTheTest(0, 1, 0);
......@@ -605,7 +605,7 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
605605
606606 const window_name = [1][*]const u8{"window name"};
607607 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"));
609609}
610610
611611test "vector casts" {
......@@ -625,9 +625,9 @@ test "vector casts" {
625625 var up3 = @as(@Vector(2, u64), up0);
626626 // Downcast (safety-checked)
627627 var down0 = up3;
628 var down1 = @intCast(@Vector(2, u32), down0);
629 var down2 = @intCast(@Vector(2, u16), down0);
630 var down3 = @intCast(@Vector(2, u8), down0);
628 var down1 = @as(@Vector(2, u32), @intCast(down0));
629 var down2 = @as(@Vector(2, u16), @intCast(down0));
630 var down3 = @as(@Vector(2, u8), @intCast(down0));
631631
632632 try expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa }));
633633 try expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa }));
......@@ -660,12 +660,12 @@ test "@floatCast cast down" {
660660
661661 {
662662 var double: f64 = 0.001534;
663 var single = @floatCast(f32, double);
663 var single = @as(f32, @floatCast(double));
664664 try expect(single == 0.001534);
665665 }
666666 {
667667 const double: f64 = 0.001534;
668 const single = @floatCast(f32, double);
668 const single = @as(f32, @floatCast(double));
669669 try expect(single == 0.001534);
670670 }
671671}
......@@ -1041,7 +1041,7 @@ test "cast between C pointer with different but compatible types" {
10411041 }
10421042 fn doTheTest() !void {
10431043 var x = [_]u16{ 4, 2, 1, 3 };
1044 try expect(foo(@ptrCast([*]u16, &x)) == 4);
1044 try expect(foo(@as([*]u16, @ptrCast(&x))) == 4);
10451045 }
10461046 };
10471047 try S.doTheTest();
......@@ -1093,10 +1093,10 @@ test "peer type resolve array pointer and unknown pointer" {
10931093test "comptime float casts" {
10941094 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));
10971097 try expect(a == 1);
10981098 try expect(@TypeOf(a) == comptime_float);
1099 const b = @intFromFloat(comptime_int, 2);
1099 const b = @as(comptime_int, @intFromFloat(2));
11001100 try expect(b == 2);
11011101 try expect(@TypeOf(b) == comptime_int);
11021102
......@@ -1111,7 +1111,7 @@ test "pointer reinterpret const float to int" {
11111111 // The hex representation is 0x3fe3333333333303.
11121112 const float: f64 = 5.99999999999994648725e-01;
11131113 const float_ptr = &float;
1114 const int_ptr = @ptrCast(*const i32, float_ptr);
1114 const int_ptr = @as(*const i32, @ptrCast(float_ptr));
11151115 const int_val = int_ptr.*;
11161116 if (native_endian == .Little)
11171117 try expect(int_val == 0x33333303)
......@@ -1134,7 +1134,7 @@ test "implicit cast from [*]T to ?*anyopaque" {
11341134fn incrementVoidPtrArray(array: ?*anyopaque, len: usize) void {
11351135 var n: usize = 0;
11361136 while (n < len) : (n += 1) {
1137 @ptrCast([*]u8, array.?)[n] += 1;
1137 @as([*]u8, @ptrCast(array.?))[n] += 1;
11381138 }
11391139}
11401140
......@@ -1146,7 +1146,7 @@ test "compile time int to ptr of function" {
11461146
11471147// On some architectures function pointers must be aligned.
11481148const 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));
11501150pub const PFN_void = *const fn (*anyopaque) callconv(.C) void;
11511151
11521152fn foobar(func: PFN_void) !void {
......@@ -1161,10 +1161,10 @@ test "implicit ptr to *anyopaque" {
11611161
11621162 var a: u32 = 1;
11631163 var ptr: *align(@alignOf(u32)) anyopaque = &a;
1164 var b: *u32 = @ptrCast(*u32, ptr);
1164 var b: *u32 = @as(*u32, @ptrCast(ptr));
11651165 try expect(b.* == 1);
11661166 var ptr2: ?*align(@alignOf(u32)) anyopaque = &a;
1167 var c: *u32 = @ptrCast(*u32, ptr2.?);
1167 var c: *u32 = @as(*u32, @ptrCast(ptr2.?));
11681168 try expect(c.* == 1);
11691169}
11701170
......@@ -1235,11 +1235,11 @@ fn testCast128() !void {
12351235}
12361236
12371237fn cast128Int(x: f128) u128 {
1238 return @bitCast(u128, x);
1238 return @as(u128, @bitCast(x));
12391239}
12401240
12411241fn cast128Float(x: u128) f128 {
1242 return @bitCast(f128, x);
1242 return @as(f128, @bitCast(x));
12431243}
12441244
12451245test "implicit cast from *[N]T to ?[*]T" {
......@@ -1270,7 +1270,7 @@ test "implicit cast from *T to ?*anyopaque" {
12701270}
12711271
12721272fn incrementVoidPtrValue(value: ?*anyopaque) void {
1273 @ptrCast(*u8, value.?).* += 1;
1273 @as(*u8, @ptrCast(value.?)).* += 1;
12741274}
12751275
12761276test "implicit cast *[0]T to E![]const u8" {
......@@ -1284,11 +1284,11 @@ test "implicit cast *[0]T to E![]const u8" {
12841284
12851285var global_array: [4]u8 = undefined;
12861286test "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));
12881288 try expect(@intFromPtr(f) == @intFromPtr(&global_array));
12891289}
12901290test "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));
12921292 try expect(@intFromPtr(f) == @intFromPtr(&global_array));
12931293}
12941294
......@@ -1337,7 +1337,7 @@ test "assignment to optional pointer result loc" {
13371337 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
13381338
13391339 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)));
13411341}
13421342
13431343test "cast between *[N]void and []void" {
......@@ -1393,9 +1393,9 @@ test "cast f128 to narrower types" {
13931393 const S = struct {
13941394 fn doTheTest() !void {
13951395 var x: f128 = 1234.0;
1396 try expect(@as(f16, 1234.0) == @floatCast(f16, x));
1397 try expect(@as(f32, 1234.0) == @floatCast(f32, x));
1398 try expect(@as(f64, 1234.0) == @floatCast(f64, x));
1396 try expect(@as(f16, 1234.0) == @as(f16, @floatCast(x)));
1397 try expect(@as(f32, 1234.0) == @as(f32, @floatCast(x)));
1398 try expect(@as(f64, 1234.0) == @as(f64, @floatCast(x)));
13991399 }
14001400 };
14011401 try S.doTheTest();
......@@ -1500,8 +1500,8 @@ test "coerce between pointers of compatible differently-named floats" {
15001500}
15011501
15021502test "peer type resolution of const and non-const pointer to array" {
1503 const a = @ptrFromInt(*[1024]u8, 42);
1504 const b = @ptrFromInt(*const [1024]u8, 42);
1503 const a = @as(*[1024]u8, @ptrFromInt(42));
1504 const b = @as(*const [1024]u8, @ptrFromInt(42));
15051505 try std.testing.expect(@TypeOf(a, b) == *const [1024]u8);
15061506 try std.testing.expect(a == b);
15071507}
......@@ -1512,7 +1512,7 @@ test "intFromFloat to zero-bit int" {
15121512 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
15131513
15141514 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);
15161516}
15171517
15181518test "peer type resolution of function pointer and function body" {
......@@ -1547,10 +1547,10 @@ test "bitcast packed struct with u0" {
15471547 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
15481548
15491549 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)));
15511551 try expect(s.a == 0);
15521552 try expect(s.b == 2);
1553 const i = @bitCast(u2, s);
1553 const i = @as(u2, @bitCast(s));
15541554 try expect(i == 2);
15551555}
15561556
......@@ -1560,7 +1560,7 @@ test "optional pointer coerced to optional allowzero pointer" {
15601560
15611561 var p: ?*u32 = undefined;
15621562 var q: ?*allowzero u32 = undefined;
1563 p = @ptrFromInt(*u32, 4);
1563 p = @as(*u32, @ptrFromInt(4));
15641564 q = p;
15651565 try expect(@intFromPtr(q.?) == 4);
15661566}
......@@ -1583,7 +1583,7 @@ test "peer type resolution forms error union" {
15831583 0 => unreachable,
15841584 42 => error.AccessDenied,
15851585 else => unreachable,
1586 } else @intCast(u32, foo);
1586 } else @as(u32, @intCast(foo));
15871587 try expect(try result == 123);
15881588}
15891589
......@@ -1623,8 +1623,8 @@ test "peer type resolution: const sentinel slice and mutable non-sentinel slice"
16231623
16241624 const S = struct {
16251625 fn doTheTest(comptime T: type, comptime s: T) !void {
1626 var a: [:s]const T = @ptrFromInt(*const [2:s]T, 0x1000);
1627 var b: []T = @ptrFromInt(*[3]T, 0x2000);
1626 var a: [:s]const T = @as(*const [2:s]T, @ptrFromInt(0x1000));
1627 var b: []T = @as(*[3]T, @ptrFromInt(0x2000));
16281628 comptime assert(@TypeOf(a, b) == []const T);
16291629 comptime assert(@TypeOf(b, a) == []const T);
16301630
......@@ -1634,8 +1634,8 @@ test "peer type resolution: const sentinel slice and mutable non-sentinel slice"
16341634
16351635 const R = @TypeOf(r1);
16361636
1637 try expectEqual(@as(R, @ptrFromInt(*const [2:s]T, 0x1000)), r1);
1638 try expectEqual(@as(R, @ptrFromInt(*const [3]T, 0x2000)), r2);
1637 try expectEqual(@as(R, @as(*const [2:s]T, @ptrFromInt(0x1000))), r1);
1638 try expectEqual(@as(R, @as(*const [3]T, @ptrFromInt(0x2000))), r2);
16391639 }
16401640 };
16411641
......@@ -1815,7 +1815,7 @@ test "peer type resolution: three-way resolution combines error set and optional
18151815
18161816 const E = error{Foo};
18171817 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));
18191819 var c: ?[*:0]u8 = null;
18201820 comptime assert(@TypeOf(a, b, c) == E!?[*:0]const u8);
18211821 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
18441844 const T = @TypeOf(r1);
18451845
18461846 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);
18481848 try expectEqual(@as(T, null), r3);
18491849}
18501850
......@@ -2114,7 +2114,7 @@ test "peer type resolution: many compatible pointers" {
21142114 4 => "foo-4",
21152115 else => unreachable,
21162116 };
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))));
21182118 }
21192119}
21202120
test/behavior/cast_int.zig+1-1
......@@ -11,6 +11,6 @@ test "@intCast i32 to u7" {
1111
1212 var x: u128 = maxInt(u128);
1313 var y: i32 = 120;
14 var z = x >> @intCast(u7, y);
14 var z = x >> @as(u7, @intCast(y));
1515 try expect(z == 0xff);
1616}
test/behavior/comptime_memory.zig+34-34
......@@ -6,7 +6,7 @@ const ptr_size = @sizeOf(usize);
66test "type pun signed and unsigned as single pointer" {
77 comptime {
88 var x: u32 = 0;
9 const y = @ptrCast(*i32, &x);
9 const y = @as(*i32, @ptrCast(&x));
1010 y.* = -1;
1111 try testing.expectEqual(@as(u32, 0xFFFFFFFF), x);
1212 }
......@@ -15,7 +15,7 @@ test "type pun signed and unsigned as single pointer" {
1515test "type pun signed and unsigned as many pointer" {
1616 comptime {
1717 var x: u32 = 0;
18 const y = @ptrCast([*]i32, &x);
18 const y = @as([*]i32, @ptrCast(&x));
1919 y[0] = -1;
2020 try testing.expectEqual(@as(u32, 0xFFFFFFFF), x);
2121 }
......@@ -24,7 +24,7 @@ test "type pun signed and unsigned as many pointer" {
2424test "type pun signed and unsigned as array pointer" {
2525 comptime {
2626 var x: u32 = 0;
27 const y = @ptrCast(*[1]i32, &x);
27 const y = @as(*[1]i32, @ptrCast(&x));
2828 y[0] = -1;
2929 try testing.expectEqual(@as(u32, 0xFFFFFFFF), x);
3030 }
......@@ -38,7 +38,7 @@ test "type pun signed and unsigned as offset many pointer" {
3838
3939 comptime {
4040 var x: u32 = 0;
41 var y = @ptrCast([*]i32, &x);
41 var y = @as([*]i32, @ptrCast(&x));
4242 y -= 10;
4343 y[10] = -1;
4444 try testing.expectEqual(@as(u32, 0xFFFFFFFF), x);
......@@ -53,7 +53,7 @@ test "type pun signed and unsigned as array pointer with pointer arithemtic" {
5353
5454 comptime {
5555 var x: u32 = 0;
56 const y = @ptrCast([*]i32, &x) - 10;
56 const y = @as([*]i32, @ptrCast(&x)) - 10;
5757 const z: *[15]i32 = y[0..15];
5858 z[10] = -1;
5959 try testing.expectEqual(@as(u32, 0xFFFFFFFF), x);
......@@ -64,9 +64,9 @@ test "type pun value and struct" {
6464 comptime {
6565 const StructOfU32 = extern struct { x: u32 };
6666 var inst: StructOfU32 = .{ .x = 0 };
67 @ptrCast(*i32, &inst.x).* = -1;
67 @as(*i32, @ptrCast(&inst.x)).* = -1;
6868 try testing.expectEqual(@as(u32, 0xFFFFFFFF), inst.x);
69 @ptrCast(*i32, &inst).* = -2;
69 @as(*i32, @ptrCast(&inst)).* = -2;
7070 try testing.expectEqual(@as(u32, 0xFFFFFFFE), inst.x);
7171 }
7272}
......@@ -81,8 +81,8 @@ test "type pun endianness" {
8181 comptime {
8282 const StructOfBytes = extern struct { x: [4]u8 };
8383 var inst: StructOfBytes = .{ .x = [4]u8{ 0, 0, 0, 0 } };
84 const structPtr = @ptrCast(*align(1) u32, &inst);
85 const arrayPtr = @ptrCast(*align(1) u32, &inst.x);
84 const structPtr = @as(*align(1) u32, @ptrCast(&inst));
85 const arrayPtr = @as(*align(1) u32, @ptrCast(&inst.x));
8686 inst.x[0] = 0xFE;
8787 inst.x[2] = 0xBE;
8888 try testing.expectEqual(bigToNativeEndian(u32, 0xFE00BE00), structPtr.*);
......@@ -124,8 +124,8 @@ fn shuffle(ptr: usize, comptime From: type, comptime To: type) usize {
124124 @compileError("Mismatched sizes! " ++ @typeName(From) ++ " and " ++ @typeName(To) ++ " must have the same size!");
125125 const array_len = @divExact(ptr_size, @sizeOf(From));
126126 var result: usize = 0;
127 const pSource = @ptrCast(*align(1) const [array_len]From, &ptr);
128 const pResult = @ptrCast(*align(1) [array_len]To, &result);
127 const pSource = @as(*align(1) const [array_len]From, @ptrCast(&ptr));
128 const pResult = @as(*align(1) [array_len]To, @ptrCast(&result));
129129 var i: usize = 0;
130130 while (i < array_len) : (i += 1) {
131131 inline for (@typeInfo(To).Struct.fields) |f| {
......@@ -136,8 +136,8 @@ fn shuffle(ptr: usize, comptime From: type, comptime To: type) usize {
136136}
137137
138138fn doTypePunBitsTest(as_bits: *Bits) !void {
139 const as_u32 = @ptrCast(*align(1) u32, as_bits);
140 const as_bytes = @ptrCast(*[4]u8, as_bits);
139 const as_u32 = @as(*align(1) u32, @ptrCast(as_bits));
140 const as_bytes = @as(*[4]u8, @ptrCast(as_bits));
141141 as_u32.* = bigToNativeEndian(u32, 0xB0A7DEED);
142142 try testing.expectEqual(@as(u1, 0x00), as_bits.p0);
143143 try testing.expectEqual(@as(u4, 0x08), as_bits.p1);
......@@ -176,7 +176,7 @@ test "type pun bits" {
176176
177177 comptime {
178178 var v: u32 = undefined;
179 try doTypePunBitsTest(@ptrCast(*Bits, &v));
179 try doTypePunBitsTest(@as(*Bits, @ptrCast(&v)));
180180 }
181181}
182182
......@@ -194,7 +194,7 @@ test "basic pointer preservation" {
194194 comptime {
195195 const lazy_address = @intFromPtr(&imports.global_u32);
196196 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)));
198198 }
199199}
200200
......@@ -207,8 +207,8 @@ test "byte copy preserves linker value" {
207207 const ct_value = comptime blk: {
208208 const lazy = &imports.global_u32;
209209 var result: *u32 = undefined;
210 const pSource = @ptrCast(*const [ptr_size]u8, &lazy);
211 const pResult = @ptrCast(*[ptr_size]u8, &result);
210 const pSource = @as(*const [ptr_size]u8, @ptrCast(&lazy));
211 const pResult = @as(*[ptr_size]u8, @ptrCast(&result));
212212 var i: usize = 0;
213213 while (i < ptr_size) : (i += 1) {
214214 pResult[i] = pSource[i];
......@@ -230,8 +230,8 @@ test "unordered byte copy preserves linker value" {
230230 const ct_value = comptime blk: {
231231 const lazy = &imports.global_u32;
232232 var result: *u32 = undefined;
233 const pSource = @ptrCast(*const [ptr_size]u8, &lazy);
234 const pResult = @ptrCast(*[ptr_size]u8, &result);
233 const pSource = @as(*const [ptr_size]u8, @ptrCast(&lazy));
234 const pResult = @as(*[ptr_size]u8, @ptrCast(&result));
235235 if (ptr_size > 8) @compileError("This array needs to be expanded for platform with very big pointers");
236236 const shuffled_indices = [_]usize{ 4, 5, 2, 6, 1, 3, 0, 7 };
237237 for (shuffled_indices) |i| {
......@@ -274,12 +274,12 @@ test "dance on linker values" {
274274 arr[0] = @intFromPtr(&imports.global_u32);
275275 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));
278278 try doTypePunBitsTest(&weird_ptr[0]);
279279 if (ptr_size > @sizeOf(Bits))
280280 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
284284 var rebuilt_bytes: [ptr_size]u8 = undefined;
285285 var i: usize = 0;
......@@ -290,7 +290,7 @@ test "dance on linker values" {
290290 rebuilt_bytes[i] = arr_bytes[1][i];
291291 }
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)))));
294294 }
295295}
296296
......@@ -316,7 +316,7 @@ test "offset array ptr by element size" {
316316 try testing.expectEqual(@intFromPtr(&arr[2]), address + 2 * @sizeOf(VirtualStruct));
317317 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)));
320320 try testing.expectEqual(bigToNativeEndian(u32, 0x02060a0e), secondElement.x);
321321 }
322322}
......@@ -334,15 +334,15 @@ test "offset instance by field size" {
334334 var ptr = @intFromPtr(&inst);
335335 ptr -= 4;
336336 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]);
338338 ptr -= @offsetOf(VirtualStruct, "x");
339339 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]);
341341 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]);
343343 ptr = @intFromPtr(&inst.z) - 4 - @offsetOf(VirtualStruct, "z");
344344 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)).*);
346346 }
347347}
348348
......@@ -363,13 +363,13 @@ test "offset field ptr by enclosing array element size" {
363363
364364 var i: usize = 0;
365365 while (i < 4) : (i += 1) {
366 var ptr: [*]u8 = @ptrCast([*]u8, &arr[0]);
366 var ptr: [*]u8 = @as([*]u8, @ptrCast(&arr[0]));
367367 ptr += i;
368368 ptr += @offsetOf(VirtualStruct, "x");
369369 var j: usize = 0;
370370 while (j < 4) : (j += 1) {
371371 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]);
373373 }
374374 }
375375 }
......@@ -393,7 +393,7 @@ test "accessing reinterpreted memory of parent object" {
393393 .c = 2.6,
394394 };
395395 const ptr = &x.b[0];
396 const b = @ptrCast([*c]const u8, ptr)[5];
396 const b = @as([*c]const u8, @ptrCast(ptr))[5];
397397 try testing.expect(b == expected);
398398 }
399399}
......@@ -407,11 +407,11 @@ test "bitcast packed union to integer" {
407407 comptime {
408408 const a = U{ .x = 1 };
409409 const b = U{ .y = 2 };
410 const cast_a = @bitCast(u2, a);
411 const cast_b = @bitCast(u2, b);
410 const cast_a = @as(u2, @bitCast(a));
411 const cast_b = @as(u2, @bitCast(b));
412412
413413 // 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)));
415415 try testing.expectEqual(@as(u2, 2), cast_b);
416416 }
417417}
......@@ -435,6 +435,6 @@ test "dereference undefined pointer to zero-bit type" {
435435test "type pun extern struct" {
436436 const S = extern struct { f: u8 };
437437 comptime var s = S{ .f = 123 };
438 @ptrCast(*u8, &s).* = 72;
438 @as(*u8, @ptrCast(&s)).* = 72;
439439 try testing.expectEqual(@as(u8, 72), s.f);
440440}
test/behavior/enum.zig+18-18
......@@ -20,7 +20,7 @@ test "enum to int" {
2020}
2121
2222fn testIntToEnumEval(x: i32) !void {
23 try expect(@enumFromInt(IntToEnumNumber, x) == IntToEnumNumber.Three);
23 try expect(@as(IntToEnumNumber, @enumFromInt(x)) == IntToEnumNumber.Three);
2424}
2525const IntToEnumNumber = enum { Zero, One, Two, Three, Four };
2626
......@@ -629,7 +629,7 @@ test "non-exhaustive enum" {
629629 .b => true,
630630 _ => false,
631631 });
632 e = @enumFromInt(E, 12);
632 e = @as(E, @enumFromInt(12));
633633 try expect(switch (e) {
634634 .a => false,
635635 .b => false,
......@@ -648,9 +648,9 @@ test "non-exhaustive enum" {
648648 });
649649
650650 try expect(@typeInfo(E).Enum.fields.len == 2);
651 e = @enumFromInt(E, 12);
651 e = @as(E, @enumFromInt(12));
652652 try expect(@intFromEnum(e) == 12);
653 e = @enumFromInt(E, y);
653 e = @as(E, @enumFromInt(y));
654654 try expect(@intFromEnum(e) == 52);
655655 try expect(@typeInfo(E).Enum.is_exhaustive == false);
656656 }
......@@ -666,7 +666,7 @@ test "empty non-exhaustive enum" {
666666 const E = enum(u8) { _ };
667667
668668 fn doTheTest(y: u8) !void {
669 var e = @enumFromInt(E, y);
669 var e = @as(E, @enumFromInt(y));
670670 try expect(switch (e) {
671671 _ => true,
672672 });
......@@ -693,7 +693,7 @@ test "single field non-exhaustive enum" {
693693 .a => true,
694694 _ => false,
695695 });
696 e = @enumFromInt(E, 12);
696 e = @as(E, @enumFromInt(12));
697697 try expect(switch (e) {
698698 .a => false,
699699 _ => true,
......@@ -709,7 +709,7 @@ test "single field non-exhaustive enum" {
709709 else => false,
710710 });
711711
712 try expect(@intFromEnum(@enumFromInt(E, y)) == y);
712 try expect(@intFromEnum(@as(E, @enumFromInt(y))) == y);
713713 try expect(@typeInfo(E).Enum.fields.len == 1);
714714 try expect(@typeInfo(E).Enum.is_exhaustive == false);
715715 }
......@@ -741,8 +741,8 @@ const MultipleChoice2 = enum(u32) {
741741};
742742
743743test "cast integer literal to enum" {
744 try expect(@enumFromInt(MultipleChoice2, 0) == MultipleChoice2.Unspecified1);
745 try expect(@enumFromInt(MultipleChoice2, 40) == MultipleChoice2.B);
744 try expect(@as(MultipleChoice2, @enumFromInt(0)) == MultipleChoice2.Unspecified1);
745 try expect(@as(MultipleChoice2, @enumFromInt(40)) == MultipleChoice2.B);
746746}
747747
748748test "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" {
11551155 var s1: S1 = undefined;
11561156 s1.e = .nope;
11571157 try expect(s1.e == .nope);
1158 const ptr = @ptrCast(*u8, &s1);
1158 const ptr = @as(*u8, @ptrCast(&s1));
11591159 try expect(ptr.* == 10);
11601160
11611161 var s0: S0 = undefined;
......@@ -1183,7 +1183,7 @@ test "Non-exhaustive enum with nonstandard int size behaves correctly" {
11831183test "runtime int to enum with one possible value" {
11841184 const E = enum { one };
11851185 var runtime: usize = 0;
1186 if (@enumFromInt(E, runtime) != .one) {
1186 if (@as(E, @enumFromInt(runtime)) != .one) {
11871187 @compileError("test failed");
11881188 }
11891189}
......@@ -1194,7 +1194,7 @@ test "enum tag from a local variable" {
11941194 return enum(Inner) { _ };
11951195 }
11961196 };
1197 const i = @enumFromInt(S.Int(u32), 0);
1197 const i = @as(S.Int(u32), @enumFromInt(0));
11981198 try std.testing.expect(@intFromEnum(i) == 0);
11991199}
12001200
......@@ -1203,12 +1203,12 @@ test "auto-numbered enum with signed tag type" {
12031203
12041204 try std.testing.expectEqual(@as(i32, 0), @intFromEnum(E.a));
12051205 try std.testing.expectEqual(@as(i32, 1), @intFromEnum(E.b));
1206 try std.testing.expectEqual(E.a, @enumFromInt(E, 0));
1207 try std.testing.expectEqual(E.b, @enumFromInt(E, 1));
1208 try std.testing.expectEqual(E.a, @enumFromInt(E, @as(i32, 0)));
1209 try std.testing.expectEqual(E.b, @enumFromInt(E, @as(i32, 1)));
1210 try std.testing.expectEqual(E.a, @enumFromInt(E, @as(u32, 0)));
1211 try std.testing.expectEqual(E.b, @enumFromInt(E, @as(u32, 1)));
1206 try std.testing.expectEqual(E.a, @as(E, @enumFromInt(0)));
1207 try std.testing.expectEqual(E.b, @as(E, @enumFromInt(1)));
1208 try std.testing.expectEqual(E.a, @as(E, @enumFromInt(@as(i32, 0))));
1209 try std.testing.expectEqual(E.b, @as(E, @enumFromInt(@as(i32, 1))));
1210 try std.testing.expectEqual(E.a, @as(E, @enumFromInt(@as(u32, 0))));
1211 try std.testing.expectEqual(E.b, @as(E, @enumFromInt(@as(u32, 1))));
12121212 try std.testing.expectEqualStrings("a", @tagName(E.a));
12131213 try std.testing.expectEqualStrings("b", @tagName(E.b));
12141214}
test/behavior/error.zig+2-2
......@@ -234,9 +234,9 @@ const Set1 = error{ A, B };
234234const Set2 = error{ A, C };
235235
236236fn testExplicitErrorSetCast(set1: Set1) !void {
237 var x = @errSetCast(Set2, set1);
237 var x = @as(Set2, @errSetCast(set1));
238238 try expect(@TypeOf(x) == Set2);
239 var y = @errSetCast(Set1, x);
239 var y = @as(Set1, @errSetCast(x));
240240 try expect(@TypeOf(y) == Set1);
241241 try expect(y == error.A);
242242}
test/behavior/eval.zig+10-10
......@@ -9,7 +9,7 @@ test "compile time recursion" {
99
1010 try expect(some_data.len == 21);
1111}
12var some_data: [@intCast(usize, fibonacci(7))]u8 = undefined;
12var some_data: [@as(usize, @intCast(fibonacci(7)))]u8 = undefined;
1313fn fibonacci(x: i32) i32 {
1414 if (x <= 1) return 1;
1515 return fibonacci(x - 1) + fibonacci(x - 2);
......@@ -123,7 +123,7 @@ fn fnWithSetRuntimeSafety() i32 {
123123test "compile-time downcast when the bits fit" {
124124 comptime {
125125 const spartan_count: u16 = 255;
126 const byte = @intCast(u8, spartan_count);
126 const byte = @as(u8, @intCast(spartan_count));
127127 try expect(byte == 255);
128128 }
129129}
......@@ -149,7 +149,7 @@ test "a type constructed in a global expression" {
149149 l.array[0] = 10;
150150 l.array[1] = 11;
151151 l.array[2] = 12;
152 const ptr = @ptrCast([*]u8, &l.array);
152 const ptr = @as([*]u8, @ptrCast(&l.array));
153153 try expect(ptr[0] == 10);
154154 try expect(ptr[1] == 11);
155155 try expect(ptr[2] == 12);
......@@ -332,7 +332,7 @@ fn generateTable(comptime T: type) [1010]T {
332332 var res: [1010]T = undefined;
333333 var i: usize = 0;
334334 while (i < 1010) : (i += 1) {
335 res[i] = @intCast(T, i);
335 res[i] = @as(T, @intCast(i));
336336 }
337337 return res;
338338}
......@@ -460,7 +460,7 @@ test "binary math operator in partially inlined function" {
460460 var b: [16]u8 = undefined;
461461
462462 for (&b, 0..) |*r, i|
463 r.* = @intCast(u8, i + 1);
463 r.* = @as(u8, @intCast(i + 1));
464464
465465 copyWithPartialInline(s[0..], b[0..]);
466466 try expect(s[0] == 0x1020304);
......@@ -942,7 +942,7 @@ test "comptime pointer load through elem_ptr" {
942942 .x = i,
943943 };
944944 }
945 var ptr = @ptrCast([*]S, &array);
945 var ptr = @as([*]S, @ptrCast(&array));
946946 var x = ptr[0].x;
947947 assert(x == 0);
948948 ptr += 1;
......@@ -1281,9 +1281,9 @@ test "comptime write through extern struct reinterpreted as array" {
12811281 c: u8,
12821282 };
12831283 var s: S = undefined;
1284 @ptrCast(*[3]u8, &s)[0] = 1;
1285 @ptrCast(*[3]u8, &s)[1] = 2;
1286 @ptrCast(*[3]u8, &s)[2] = 3;
1284 @as(*[3]u8, @ptrCast(&s))[0] = 1;
1285 @as(*[3]u8, @ptrCast(&s))[1] = 2;
1286 @as(*[3]u8, @ptrCast(&s))[2] = 3;
12871287 assert(s.a == 1);
12881288 assert(s.b == 2);
12891289 assert(s.c == 3);
......@@ -1371,7 +1371,7 @@ test "lazy value is resolved as slice operand" {
13711371 var a: [512]u64 = undefined;
13721372
13731373 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)];
13751375 try expect(@intFromPtr(ptr1) == @intFromPtr(ptr2));
13761376 try expect(ptr1.len == ptr2.len);
13771377}
test/behavior/export.zig+1-1
......@@ -7,7 +7,7 @@ const builtin = @import("builtin");
77
88// can't really run this test but we can make sure it has no compile error
99// and generates code
10const vram = @ptrFromInt([*]volatile u8, 0x20000000)[0..0x8000];
10const vram = @as([*]volatile u8, @ptrFromInt(0x20000000))[0..0x8000];
1111export fn writeToVRam() void {
1212 vram[0] = 'X';
1313}
test/behavior/floatop.zig+3-3
......@@ -94,7 +94,7 @@ test "negative f128 intFromFloat at compile-time" {
9494 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
9595
9696 const a: f128 = -2;
97 var b = @intFromFloat(i64, a);
97 var b = @as(i64, @intFromFloat(a));
9898 try expect(@as(i64, -2) == b);
9999}
100100
......@@ -387,11 +387,11 @@ fn testLog() !void {
387387 }
388388 {
389389 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))));
391391 }
392392 {
393393 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))));
395395 }
396396 inline for ([_]type{ f16, f32, f64 }) |ty| {
397397 const eps = epsForType(ty);
test/behavior/fn.zig+4-4
......@@ -326,7 +326,7 @@ test "function pointers" {
326326 &fn4,
327327 };
328328 for (fns, 0..) |f, i| {
329 try expect(f() == @intCast(u32, i) + 5);
329 try expect(f() == @as(u32, @intCast(i)) + 5);
330330 }
331331}
332332fn fn1() u32 {
......@@ -512,8 +512,8 @@ test "using @ptrCast on function pointers" {
512512
513513 fn run() !void {
514514 const a = A{ .data = "abcd".* };
515 const casted_fn = @ptrCast(*const fn (*const anyopaque, usize) *const u8, &at);
516 const casted_impl = @ptrCast(*const anyopaque, &a);
515 const casted_fn = @as(*const fn (*const anyopaque, usize) *const u8, @ptrCast(&at));
516 const casted_impl = @as(*const anyopaque, @ptrCast(&a));
517517 const ptr = casted_fn(casted_impl, 2);
518518 try expect(ptr.* == 'c');
519519 }
......@@ -575,7 +575,7 @@ test "lazy values passed to anytype parameter" {
575575 try B.foo(.{ .x = @sizeOf(B) });
576576
577577 const C = struct {};
578 try expect(@truncate(u32, @sizeOf(C)) == 0);
578 try expect(@as(u32, @truncate(@sizeOf(C))) == 0);
579579
580580 const D = struct {};
581581 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 {
1414
1515test "define a function in an anonymous struct in comptime" {
1616 const foo = get_foo();
17 try expect(foo(@ptrFromInt(*u8, 12345)) == 12345);
17 try expect(foo(@as(*u8, @ptrFromInt(12345))) == 12345);
1818}
test/behavior/for.zig+5-5
......@@ -84,7 +84,7 @@ test "basic for loop" {
8484 }
8585 for (array, 0..) |item, index| {
8686 _ = item;
87 buffer[buf_index] = @intCast(u8, index);
87 buffer[buf_index] = @as(u8, @intCast(index));
8888 buf_index += 1;
8989 }
9090 const array_ptr = &array;
......@@ -94,7 +94,7 @@ test "basic for loop" {
9494 }
9595 for (array_ptr, 0..) |item, index| {
9696 _ = item;
97 buffer[buf_index] = @intCast(u8, index);
97 buffer[buf_index] = @as(u8, @intCast(index));
9898 buf_index += 1;
9999 }
100100 const unknown_size: []const u8 = &array;
......@@ -103,7 +103,7 @@ test "basic for loop" {
103103 buf_index += 1;
104104 }
105105 for (unknown_size, 0..) |_, index| {
106 buffer[buf_index] = @intCast(u8, index);
106 buffer[buf_index] = @as(u8, @intCast(index));
107107 buf_index += 1;
108108 }
109109
......@@ -208,7 +208,7 @@ test "for on slice with allowzero ptr" {
208208
209209 const S = struct {
210210 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];
212212 for (ptr, 0..) |x, i| try expect(x == i + 1);
213213 for (ptr, 0..) |*x, i| try expect(x.* == i + 1);
214214 }
......@@ -393,7 +393,7 @@ test "raw pointer and counter" {
393393 const ptr: [*]u8 = &buf;
394394
395395 for (ptr, 0..4) |*a, b| {
396 a.* = @intCast(u8, 'A' + b);
396 a.* = @as(u8, @intCast('A' + b));
397397 }
398398
399399 try expect(buf[0] == 'A');
test/behavior/generics.zig+3-3
......@@ -97,7 +97,7 @@ test "type constructed by comptime function call" {
9797 l.array[0] = 10;
9898 l.array[1] = 11;
9999 l.array[2] = 12;
100 const ptr = @ptrCast([*]u8, &l.array);
100 const ptr = @as([*]u8, @ptrCast(&l.array));
101101 try expect(ptr[0] == 10);
102102 try expect(ptr[1] == 11);
103103 try expect(ptr[2] == 12);
......@@ -171,7 +171,7 @@ fn getByte(ptr: ?*const u8) u8 {
171171 return ptr.?.*;
172172}
173173fn 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])));
175175}
176176
177177test "generic fn keeps non-generic parameter types" {
......@@ -428,7 +428,7 @@ test "null sentinel pointer passed as generic argument" {
428428 try std.testing.expect(@intFromPtr(a) == 8);
429429 }
430430 };
431 try S.doTheTest((@ptrFromInt([*:null]const [*c]const u8, 8)));
431 try S.doTheTest((@as([*:null]const [*c]const u8, @ptrFromInt(8))));
432432}
433433
434434test "generic function passed as comptime argument" {
test/behavior/int128.zig+8-8
......@@ -38,7 +38,7 @@ test "undefined 128 bit int" {
3838
3939 var undef: u128 = undefined;
4040 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);
4242}
4343
4444test "int128" {
......@@ -49,7 +49,7 @@ test "int128" {
4949
5050 var buff: i128 = -1;
5151 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
5454 buff = minInt(i128);
5555 try expect(buff < 0);
......@@ -73,16 +73,16 @@ test "truncate int128" {
7373
7474 {
7575 var buff: u128 = maxInt(u128);
76 try expect(@truncate(u64, buff) == maxInt(u64));
77 try expect(@truncate(u90, buff) == maxInt(u90));
78 try expect(@truncate(u128, buff) == maxInt(u128));
76 try expect(@as(u64, @truncate(buff)) == maxInt(u64));
77 try expect(@as(u90, @truncate(buff)) == maxInt(u90));
78 try expect(@as(u128, @truncate(buff)) == maxInt(u128));
7979 }
8080
8181 {
8282 var buff: i128 = maxInt(i128);
83 try expect(@truncate(i64, buff) == -1);
84 try expect(@truncate(i90, buff) == -1);
85 try expect(@truncate(i128, buff) == maxInt(i128));
83 try expect(@as(i64, @truncate(buff)) == -1);
84 try expect(@as(i90, @truncate(buff)) == -1);
85 try expect(@as(i128, @truncate(buff)) == maxInt(i128));
8686 }
8787}
8888
test/behavior/math.zig+10-10
......@@ -391,11 +391,11 @@ test "binary not 128-bit" {
391391 break :x ~@as(u128, 0x55555555_55555555_55555555_55555555) == 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa;
392392 });
393393 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)));
395395 });
396396
397397 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))));
399399}
400400
401401fn testBinaryNot128(comptime Type: type, x: Type) !void {
......@@ -1156,29 +1156,29 @@ test "quad hex float literal parsing accurate" {
11561156
11571157 // implied 1 is dropped, with an exponent of 0 (0x3fff) after biasing.
11581158 const expected: u128 = 0x3fff1111222233334444555566667777;
1159 try expect(@bitCast(u128, a) == expected);
1159 try expect(@as(u128, @bitCast(a)) == expected);
11601160
11611161 // non-normalized
11621162 const b: f128 = 0x11.111222233334444555566667777p-4;
1163 try expect(@bitCast(u128, b) == expected);
1163 try expect(@as(u128, @bitCast(b)) == expected);
11641164
11651165 const S = struct {
11661166 fn doTheTest() !void {
11671167 {
11681168 var f: f128 = 0x1.2eab345678439abcdefea56782346p+5;
1169 try expect(@bitCast(u128, f) == 0x40042eab345678439abcdefea5678234);
1169 try expect(@as(u128, @bitCast(f)) == 0x40042eab345678439abcdefea5678234);
11701170 }
11711171 {
11721172 var f: f128 = 0x1.edcb34a235253948765432134674fp-1;
1173 try expect(@bitCast(u128, f) == 0x3ffeedcb34a235253948765432134675); // round-to-even
1173 try expect(@as(u128, @bitCast(f)) == 0x3ffeedcb34a235253948765432134675); // round-to-even
11741174 }
11751175 {
11761176 var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50;
1177 try expect(@bitCast(u128, f) == 0x3fcd353e45674d89abacc3a2ebf3ff50);
1177 try expect(@as(u128, @bitCast(f)) == 0x3fcd353e45674d89abacc3a2ebf3ff50);
11781178 }
11791179 {
11801180 var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9;
1181 try expect(@bitCast(u128, f) == 0x3ff6ed8764648369535adf4be3214568);
1181 try expect(@as(u128, @bitCast(f)) == 0x3ff6ed8764648369535adf4be3214568);
11821182 }
11831183 const exp2ft = [_]f64{
11841184 0x1.6a09e667f3bcdp-1,
......@@ -1233,7 +1233,7 @@ test "quad hex float literal parsing accurate" {
12331233 };
12341234
12351235 for (exp2ft, 0..) |x, i| {
1236 try expect(@bitCast(u64, x) == answers[i]);
1236 try expect(@as(u64, @bitCast(x)) == answers[i]);
12371237 }
12381238 }
12391239 };
......@@ -1586,7 +1586,7 @@ test "signed zeros are represented properly" {
15861586 fn testOne(comptime T: type) !void {
15871587 const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
15881588 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));
15901590 // Ensure the sign bit is set.
15911591 try expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1);
15921592 }
test/behavior/memcpy.zig+1-1
......@@ -59,7 +59,7 @@ fn testMemcpyDestManyPtr() !void {
5959 var str = "hello".*;
6060 var buf: [5]u8 = undefined;
6161 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]);
6363 try expect(buf[0] == 'h');
6464 try expect(buf[1] == 'e');
6565 try expect(buf[2] == 'l');
test/behavior/packed-struct.zig+5-5
......@@ -166,7 +166,7 @@ test "correct sizeOf and offsets in packed structs" {
166166 try expectEqual(4, @sizeOf(PStruct));
167167
168168 if (native_endian == .Little) {
169 const s1 = @bitCast(PStruct, @as(u32, 0x12345678));
169 const s1 = @as(PStruct, @bitCast(@as(u32, 0x12345678)));
170170 try expectEqual(false, s1.bool_a);
171171 try expectEqual(false, s1.bool_b);
172172 try expectEqual(false, s1.bool_c);
......@@ -180,7 +180,7 @@ test "correct sizeOf and offsets in packed structs" {
180180 try expectEqual(@as(u10, 0b1101000101), s1.u10_a);
181181 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)));
184184 try expectEqual(@as(u1, 0), s2.x);
185185 try expectEqual(@as(u7, 0b1111010), s2.y);
186186 try expectEqual(@as(u24, 0xd5c71f), s2.z);
......@@ -207,7 +207,7 @@ test "nested packed structs" {
207207 try expectEqual(24, @bitOffsetOf(S3, "y"));
208208
209209 if (native_endian == .Little) {
210 const s3 = @bitCast(S3Padded, @as(u64, 0xe952d5c71ff4)).s3;
210 const s3 = @as(S3Padded, @bitCast(@as(u64, 0xe952d5c71ff4))).s3;
211211 try expectEqual(@as(u8, 0xf4), s3.x.a);
212212 try expectEqual(@as(u8, 0x1f), s3.x.b);
213213 try expectEqual(@as(u8, 0xc7), s3.x.c);
......@@ -600,7 +600,7 @@ test "packed struct initialized in bitcast" {
600600
601601 const T = packed struct { val: u8 };
602602 var val: u8 = 123;
603 const t = @bitCast(u8, T{ .val = val });
603 const t = @as(u8, @bitCast(T{ .val = val }));
604604 try expect(t == val);
605605}
606606
......@@ -627,7 +627,7 @@ test "pointer to container level packed struct field" {
627627 },
628628 var arr = [_]u32{0} ** 2;
629629 };
630 @ptrCast(*S, &S.arr[0]).other_bits.enable_3 = true;
630 @as(*S, @ptrCast(&S.arr[0])).other_bits.enable_3 = true;
631631 try expect(S.arr[0] == 0x10000000);
632632}
633633
test/behavior/packed_struct_explicit_backing_int.zig+1-1
......@@ -25,7 +25,7 @@ test "packed struct explicit backing integer" {
2525 try expectEqual(24, @bitOffsetOf(S3, "y"));
2626
2727 if (native_endian == .Little) {
28 const s3 = @bitCast(S3Padded, @as(u64, 0xe952d5c71ff4)).s3;
28 const s3 = @as(S3Padded, @bitCast(@as(u64, 0xe952d5c71ff4))).s3;
2929 try expectEqual(@as(u8, 0xf4), s3.x.a);
3030 try expectEqual(@as(u8, 0x1f), s3.x.b);
3131 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" {
184184}
185185
186186test "compare equality of optional and non-optional pointer" {
187 const a = @ptrFromInt(*const usize, 0x12345678);
188 const b = @ptrFromInt(?*usize, 0x12345678);
187 const a = @as(*const usize, @ptrFromInt(0x12345678));
188 const b = @as(?*usize, @ptrFromInt(0x12345678));
189189 try expect(a == b);
190190 try expect(b == a);
191191}
......@@ -197,7 +197,7 @@ test "allowzero pointer and slice" {
197197 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
198198 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));
201201 var opt_ptr: ?[*]allowzero i32 = ptr;
202202 try expect(opt_ptr != null);
203203 try expect(@intFromPtr(ptr) == 0);
......@@ -286,9 +286,9 @@ test "null terminated pointer" {
286286 const S = struct {
287287 fn doTheTest() !void {
288288 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));
290290 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));
292292 try expect(std.mem.eql(u8, std.mem.sliceTo(zero_ptr_again, 0), "hello"));
293293 }
294294 };
......@@ -367,7 +367,7 @@ test "pointer sentinel with +inf" {
367367}
368368
369369test "pointer to array at fixed address" {
370 const array = @ptrFromInt(*volatile [2]u32, 0x10);
370 const array = @as(*volatile [2]u32, @ptrFromInt(0x10));
371371 // Silly check just to reference `array`
372372 try expect(@intFromPtr(&array[0]) == 0x10);
373373 try expect(@intFromPtr(&array[1]) == 0x14);
......@@ -406,13 +406,13 @@ test "pointer arithmetic affects the alignment" {
406406
407407test "@intFromPtr on null optional at comptime" {
408408 {
409 const pointer = @ptrFromInt(?*u8, 0x000);
409 const pointer = @as(?*u8, @ptrFromInt(0x000));
410410 const x = @intFromPtr(pointer);
411411 _ = x;
412412 try comptime expect(0 == @intFromPtr(pointer));
413413 }
414414 {
415 const pointer = @ptrFromInt(?*u8, 0xf00);
415 const pointer = @as(?*u8, @ptrFromInt(0xf00));
416416 try comptime expect(0xf00 == @intFromPtr(pointer));
417417 }
418418}
......@@ -463,8 +463,8 @@ test "element pointer arithmetic to slice" {
463463 };
464464
465465 const elem_ptr = &cases[0]; // *[2]i32
466 const many = @ptrCast([*][2]i32, elem_ptr);
467 const many_elem = @ptrCast(*[2]i32, &many[1]);
466 const many = @as([*][2]i32, @ptrCast(elem_ptr));
467 const many_elem = @as(*[2]i32, @ptrCast(&many[1]));
468468 const items: []i32 = many_elem;
469469 try testing.expect(items.len == 2);
470470 try testing.expect(items[1] == 3);
......@@ -512,7 +512,7 @@ test "ptrCast comptime known slice to C pointer" {
512512 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
513513
514514 const s: [:0]const u8 = "foo";
515 var p = @ptrCast([*c]const u8, s);
515 var p = @as([*c]const u8, @ptrCast(s));
516516 try std.testing.expectEqualStrings(s, std.mem.sliceTo(p, 0));
517517}
518518
......@@ -550,7 +550,7 @@ test "pointer to array has explicit alignment" {
550550 const Base = extern struct { a: u8 };
551551 const Base2 = extern struct { a: u8 };
552552 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)));
554554 }
555555 };
556556 var bases = [_]S.Base{.{ .a = 2 }} ** 4;
test/behavior/popcount.zig+1-1
......@@ -63,7 +63,7 @@ fn testPopCountIntegers() !void {
6363 try expect(@popCount(x) == 2);
6464 }
6565 comptime {
66 try expect(@popCount(@bitCast(u8, @as(i8, -120))) == 2);
66 try expect(@popCount(@as(u8, @bitCast(@as(i8, -120)))) == 2);
6767 }
6868}
6969
test/behavior/ptrcast.zig+17-27
......@@ -16,7 +16,7 @@ fn testReinterpretBytesAsInteger() !void {
1616 .Little => 0xab785634,
1717 .Big => 0x345678ab,
1818 };
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);
2020}
2121
2222test "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"
3232fn testReinterpretWithOffsetAndNoWellDefinedLayout() !void {
3333 const bytes: ?[5]?u8 = [5]?u8{ 0x12, 0x34, 0x56, 0x78, 0x9a };
3434 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)).*;
3636 _ = copy;
3737 //try expect(@ptrCast(*align(1)?u8, bytes[1..5]).* == );
3838}
......@@ -51,7 +51,7 @@ fn testReinterpretStructWrappedBytesAsInteger() !void {
5151 .Little => 0xab785634,
5252 .Big => 0x345678ab,
5353 };
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);
5555}
5656
5757test "reinterpret bytes of an array into an extern struct" {
......@@ -71,7 +71,7 @@ fn testReinterpretBytesAsExternStruct() !void {
7171 c: u8,
7272 };
7373
74 var ptr = @ptrCast(*const S, &bytes);
74 var ptr = @as(*const S, @ptrCast(&bytes));
7575 var val = ptr.c;
7676 try expect(val == 5);
7777}
......@@ -95,7 +95,7 @@ fn testReinterpretExternStructAsExternStruct() !void {
9595 a: u32 align(2),
9696 c: u8,
9797 };
98 var ptr = @ptrCast(*const S2, &bytes);
98 var ptr = @as(*const S2, @ptrCast(&bytes));
9999 var val = ptr.c;
100100 try expect(val == 5);
101101}
......@@ -121,7 +121,7 @@ fn testReinterpretOverAlignedExternStructAsExternStruct() !void {
121121 a2: u16,
122122 c: u8,
123123 };
124 var ptr = @ptrCast(*const S2, &bytes);
124 var ptr = @as(*const S2, @ptrCast(&bytes));
125125 var val = ptr.c;
126126 try expect(val == 5);
127127}
......@@ -138,13 +138,13 @@ test "lower reinterpreted comptime field ptr (with under-aligned fields)" {
138138 a: u32 align(2),
139139 c: u8,
140140 };
141 comptime var ptr = @ptrCast(*const S, &bytes);
141 comptime var ptr = @as(*const S, @ptrCast(&bytes));
142142 var val = &ptr.c;
143143 try expect(val.* == 5);
144144
145145 // Test lowering an elem ptr
146146 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));
148148 var val2 = &ptr2[4];
149149 try expect(val2.* == 5);
150150}
......@@ -161,13 +161,13 @@ test "lower reinterpreted comptime field ptr" {
161161 a: u32,
162162 c: u8,
163163 };
164 comptime var ptr = @ptrCast(*const S, &bytes);
164 comptime var ptr = @as(*const S, @ptrCast(&bytes));
165165 var val = &ptr.c;
166166 try expect(val.* == 5);
167167
168168 // Test lowering an elem ptr
169169 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));
171171 var val2 = &ptr2[4];
172172 try expect(val2.* == 5);
173173}
......@@ -190,27 +190,17 @@ const Bytes = struct {
190190
191191 pub fn init(v: u32) Bytes {
192192 var res: Bytes = undefined;
193 @ptrCast(*align(1) u32, &res.bytes).* = v;
193 @as(*align(1) u32, @ptrCast(&res.bytes)).* = v;
194194
195195 return res;
196196 }
197197};
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
209199test "ptrcast of const integer has the correct object size" {
210200 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
211201
212 const is_value = ~@intCast(isize, std.math.minInt(isize));
213 const is_bytes = @ptrCast([*]const u8, &is_value)[0..@sizeOf(isize)];
202 const is_value = ~@as(isize, @intCast(std.math.minInt(isize)));
203 const is_bytes = @as([*]const u8, @ptrCast(&is_value))[0..@sizeOf(isize)];
214204 if (@sizeOf(isize) == 8) {
215205 switch (native_endian) {
216206 .Little => {
......@@ -248,7 +238,7 @@ test "implicit optional pointer to optional anyopaque pointer" {
248238 var buf: [4]u8 = "aoeu".*;
249239 var x: ?[*]u8 = &buf;
250240 var y: ?*anyopaque = x;
251 var z = @ptrCast(*[4]u8, y);
241 var z = @as(*[4]u8, @ptrCast(y));
252242 try expect(std.mem.eql(u8, z, "aoeu"));
253243}
254244
......@@ -260,7 +250,7 @@ test "@ptrCast slice to slice" {
260250
261251 const S = struct {
262252 fn foo(slice: []u32) []i32 {
263 return @ptrCast([]i32, slice);
253 return @as([]i32, @ptrCast(slice));
264254 }
265255 };
266256 var buf: [4]u32 = .{ 0, 0, 0, 0 };
......@@ -277,7 +267,7 @@ test "comptime @ptrCast a subset of an array, then write through it" {
277267
278268 comptime {
279269 var buff: [16]u8 align(4) = undefined;
280 const len_bytes = @ptrCast(*u32, &buff);
270 const len_bytes = @as(*u32, @ptrCast(&buff));
281271 len_bytes.* = 16;
282272 std.mem.copy(u8, buff[4..], "abcdef");
283273 }
......@@ -286,7 +276,7 @@ test "comptime @ptrCast a subset of an array, then write through it" {
286276test "@ptrCast undefined value at comptime" {
287277 const S = struct {
288278 fn transmute(comptime T: type, comptime U: type, value: T) U {
289 return @ptrCast(*const U, &value).*;
279 return @as(*const U, @ptrCast(&value)).*;
290280 }
291281 };
292282 comptime {
test/behavior/ptrfromint.zig+4-4
......@@ -9,7 +9,7 @@ test "casting integer address to function pointer" {
99
1010fn addressToFunction() void {
1111 var addr: usize = 0xdeadbee0;
12 _ = @ptrFromInt(*const fn () void, addr);
12 _ = @as(*const fn () void, @ptrFromInt(addr));
1313}
1414
1515test "mutate through ptr initialized with constant ptrFromInt value" {
......@@ -21,7 +21,7 @@ test "mutate through ptr initialized with constant ptrFromInt value" {
2121}
2222
2323fn forceCompilerAnalyzeBranchHardCodedPtrDereference(x: bool) void {
24 const hardCodedP = @ptrFromInt(*volatile u8, 0xdeadbeef);
24 const hardCodedP = @as(*volatile u8, @ptrFromInt(0xdeadbeef));
2525 if (x) {
2626 hardCodedP.* = hardCodedP.* | 10;
2727 } else {
......@@ -34,7 +34,7 @@ test "@ptrFromInt creates null pointer" {
3434 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
3535 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
3636
37 const ptr = @ptrFromInt(?*u32, 0);
37 const ptr = @as(?*u32, @ptrFromInt(0));
3838 try expectEqual(@as(?*u32, null), ptr);
3939}
4040
......@@ -43,6 +43,6 @@ test "@ptrFromInt creates allowzero zero pointer" {
4343 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
4444 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));
4747 try expectEqual(@as(usize, 0), @intFromPtr(ptr));
4848}
test/behavior/sizeof_and_typeof.zig+2-2
......@@ -231,7 +231,7 @@ test "@sizeOf comparison against zero" {
231231
232232test "hardcoded address in typeof expression" {
233233 const S = struct {
234 fn func() @TypeOf(@ptrFromInt(*[]u8, 0x10).*[0]) {
234 fn func() @TypeOf(@as(*[]u8, @ptrFromInt(0x10)).*[0]) {
235235 return 0;
236236 }
237237 };
......@@ -252,7 +252,7 @@ test "array access of generic param in typeof expression" {
252252test "lazy size cast to float" {
253253 {
254254 const S = struct { a: u8 };
255 try expect(@floatFromInt(f32, @sizeOf(S)) == 1.0);
255 try expect(@as(f32, @floatFromInt(@sizeOf(S))) == 1.0);
256256 }
257257 {
258258 const S = struct { a: u8 };
test/behavior/slice.zig+10-10
......@@ -129,7 +129,7 @@ test "generic malloc free" {
129129}
130130var some_mem: [100]u8 = undefined;
131131fn 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];
133133}
134134fn memFree(comptime T: type, memory: []T) void {
135135 _ = memory;
......@@ -138,7 +138,7 @@ fn memFree(comptime T: type, memory: []T) void {
138138test "slice of hardcoded address to pointer" {
139139 const S = struct {
140140 fn doTheTest() !void {
141 const pointer = @ptrFromInt([*]u8, 0x04)[0..2];
141 const pointer = @as([*]u8, @ptrFromInt(0x04))[0..2];
142142 try comptime expect(@TypeOf(pointer) == *[2]u8);
143143 const slice: []const u8 = pointer;
144144 try expect(@intFromPtr(slice.ptr) == 4);
......@@ -152,7 +152,7 @@ test "slice of hardcoded address to pointer" {
152152test "comptime slice of pointer preserves comptime var" {
153153 comptime {
154154 var buff: [10]u8 = undefined;
155 var a = @ptrCast([*]u8, &buff);
155 var a = @as([*]u8, @ptrCast(&buff));
156156 a[0..1][0] = 1;
157157 try expect(buff[0..][0..][0] == 1);
158158 }
......@@ -161,7 +161,7 @@ test "comptime slice of pointer preserves comptime var" {
161161test "comptime pointer cast array and then slice" {
162162 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));
165165 const sliceA: []const u8 = ptrA[0..2];
166166
167167 const ptrB: [*]const u8 = &array;
......@@ -188,7 +188,7 @@ test "slicing pointer by length" {
188188 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
189189
190190 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));
192192 const slice = ptr[1..][0..5];
193193 try expect(slice.len == 5);
194194 var i: usize = 0;
......@@ -197,7 +197,7 @@ test "slicing pointer by length" {
197197 }
198198}
199199
200const x = @ptrFromInt([*]i32, 0x1000)[0..0x500];
200const x = @as([*]i32, @ptrFromInt(0x1000))[0..0x500];
201201const y = x[0x100..];
202202test "compile time slice of pointer to hard coded address" {
203203 try expect(@intFromPtr(x) == 0x1000);
......@@ -262,7 +262,7 @@ test "C pointer slice access" {
262262 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
263263
264264 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
267267 var runtime_zero: usize = 0;
268268 try comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1]));
......@@ -352,7 +352,7 @@ test "@ptrCast slice to pointer" {
352352 fn doTheTest() !void {
353353 var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff };
354354 var slice: []align(@alignOf(u16)) u8 = &array;
355 var ptr = @ptrCast(*u16, slice);
355 var ptr = @as(*u16, @ptrCast(slice));
356356 try expect(ptr.* == 65535);
357357 }
358358 };
......@@ -837,13 +837,13 @@ test "empty slice ptr is non null" {
837837 {
838838 const empty_slice: []u8 = &[_]u8{};
839839 const p: [*]u8 = empty_slice.ptr + 0;
840 const t = @ptrCast([*]i8, p);
840 const t = @as([*]i8, @ptrCast(p));
841841 try expect(@intFromPtr(t) == @intFromPtr(empty_slice.ptr));
842842 }
843843 {
844844 const empty_slice: []u8 = &.{};
845845 const p: [*]u8 = empty_slice.ptr + 0;
846 const t = @ptrCast([*]i8, p);
846 const t = @as([*]i8, @ptrCast(p));
847847 try expect(@intFromPtr(t) == @intFromPtr(empty_slice.ptr));
848848 }
849849}
test/behavior/slice_sentinel_comptime.zig+8-8
......@@ -25,7 +25,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
2525 // vector_ConstPtrSpecialRef
2626 comptime {
2727 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));
2929 const slice = target[0..3 :'d'];
3030 _ = slice;
3131 }
......@@ -41,7 +41,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
4141 // cvector_ConstPtrSpecialRef
4242 comptime {
4343 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));
4545 const slice = target[0..3 :'d'];
4646 _ = slice;
4747 }
......@@ -82,7 +82,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
8282 // vector_ConstPtrSpecialRef
8383 comptime {
8484 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));
8686 const slice = target[0..13 :0xff];
8787 _ = slice;
8888 }
......@@ -98,7 +98,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
9898 // cvector_ConstPtrSpecialRef
9999 comptime {
100100 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));
102102 const slice = target[0..13 :0xff];
103103 _ = slice;
104104 }
......@@ -139,7 +139,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
139139 // vector_ConstPtrSpecialRef
140140 comptime {
141141 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));
143143 const slice = target[0..3 :'d'];
144144 _ = slice;
145145 }
......@@ -155,7 +155,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
155155 // cvector_ConstPtrSpecialRef
156156 comptime {
157157 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));
159159 const slice = target[0..3 :'d'];
160160 _ = slice;
161161 }
......@@ -196,7 +196,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
196196 // vector_ConstPtrSpecialRef
197197 comptime {
198198 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));
200200 const slice = target[0..14 :0];
201201 _ = slice;
202202 }
......@@ -212,7 +212,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
212212 // cvector_ConstPtrSpecialRef
213213 comptime {
214214 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));
216216 const slice = target[0..14 :0];
217217 _ = slice;
218218 }
test/behavior/struct.zig+10-10
......@@ -92,7 +92,7 @@ test "structs" {
9292 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
9393
9494 var foo: StructFoo = undefined;
95 @memset(@ptrCast([*]u8, &foo)[0..@sizeOf(StructFoo)], 0);
95 @memset(@as([*]u8, @ptrCast(&foo))[0..@sizeOf(StructFoo)], 0);
9696 foo.a += 1;
9797 foo.b = foo.a == 1;
9898 try testFoo(foo);
......@@ -479,14 +479,14 @@ test "runtime struct initialization of bitfield" {
479479 .y = x1,
480480 };
481481 const s2 = Nibbles{
482 .x = @intCast(u4, x2),
483 .y = @intCast(u4, x2),
482 .x = @as(u4, @intCast(x2)),
483 .y = @as(u4, @intCast(x2)),
484484 };
485485
486486 try expect(s1.x == x1);
487487 try expect(s1.y == x1);
488 try expect(s2.x == @intCast(u4, x2));
489 try expect(s2.y == @intCast(u4, x2));
488 try expect(s2.x == @as(u4, @intCast(x2)));
489 try expect(s2.y == @as(u4, @intCast(x2)));
490490}
491491
492492var x1 = @as(u4, 1);
......@@ -515,8 +515,8 @@ test "packed struct fields are ordered from LSB to MSB" {
515515
516516 var all: u64 = 0x7765443322221111;
517517 var bytes: [8]u8 align(@alignOf(Bitfields)) = undefined;
518 @memcpy(bytes[0..8], @ptrCast([*]u8, &all));
519 var bitfields = @ptrCast(*Bitfields, &bytes).*;
518 @memcpy(bytes[0..8], @as([*]u8, @ptrCast(&all)));
519 var bitfields = @as(*Bitfields, @ptrCast(&bytes)).*;
520520
521521 try expect(bitfields.f1 == 0x1111);
522522 try expect(bitfields.f2 == 0x2222);
......@@ -1281,7 +1281,7 @@ test "packed struct aggregate init" {
12811281
12821282 const S = struct {
12831283 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 }));
12851285 }
12861286
12871287 const P = packed struct {
......@@ -1289,7 +1289,7 @@ test "packed struct aggregate init" {
12891289 b: i6,
12901290 };
12911291 };
1292 const result = @bitCast(u8, S.foo(1, 2));
1292 const result = @as(u8, @bitCast(S.foo(1, 2)));
12931293 try expect(result == 9);
12941294}
12951295
......@@ -1365,7 +1365,7 @@ test "under-aligned struct field" {
13651365 };
13661366 var runtime: usize = 1234;
13671367 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));
13691369 const result = std.mem.readIntNative(u64, array[4..12]);
13701370 try expect(result == 1234);
13711371}
test/behavior/switch.zig+5-5
......@@ -590,9 +590,9 @@ test "switch on pointer type" {
590590 field: u32,
591591 };
592592
593 const P1 = @ptrFromInt(*X, 0x400);
594 const P2 = @ptrFromInt(*X, 0x800);
595 const P3 = @ptrFromInt(*X, 0xC00);
593 const P1 = @as(*X, @ptrFromInt(0x400));
594 const P2 = @as(*X, @ptrFromInt(0x800));
595 const P3 = @as(*X, @ptrFromInt(0xC00));
596596
597597 fn doTheTest(arg: *X) i32 {
598598 switch (arg) {
......@@ -682,9 +682,9 @@ test "enum value without tag name used as switch item" {
682682 b = 2,
683683 _,
684684 };
685 var e: E = @enumFromInt(E, 0);
685 var e: E = @as(E, @enumFromInt(0));
686686 switch (e) {
687 @enumFromInt(E, 0) => {},
687 @as(E, @enumFromInt(0)) => {},
688688 .a => return error.TestFailed,
689689 .b => return error.TestFailed,
690690 _ => return error.TestFailed,
test/behavior/translate_c_macros.zig+2-2
......@@ -60,7 +60,7 @@ test "cast negative integer to pointer" {
6060 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
6161 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);
6464}
6565
6666test "casting to union with a macro" {
......@@ -89,7 +89,7 @@ test "casting or calling a value with a paren-surrounded macro" {
8989
9090 const l: c_long = 42;
9191 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
9494 const Helper = struct {
9595 fn foo(n: c_int) !void {
test/behavior/truncate.zig+13-13
......@@ -4,58 +4,58 @@ const expect = std.testing.expect;
44
55test "truncate u0 to larger integer allowed and has comptime-known result" {
66 var x: u0 = 0;
7 const y = @truncate(u8, x);
7 const y = @as(u8, @truncate(x));
88 try comptime expect(y == 0);
99}
1010
1111test "truncate.u0.literal" {
12 var z = @truncate(u0, 0);
12 var z = @as(u0, @truncate(0));
1313 try expect(z == 0);
1414}
1515
1616test "truncate.u0.const" {
1717 const c0: usize = 0;
18 var z = @truncate(u0, c0);
18 var z = @as(u0, @truncate(c0));
1919 try expect(z == 0);
2020}
2121
2222test "truncate.u0.var" {
2323 var d: u8 = 2;
24 var z = @truncate(u0, d);
24 var z = @as(u0, @truncate(d));
2525 try expect(z == 0);
2626}
2727
2828test "truncate i0 to larger integer allowed and has comptime-known result" {
2929 var x: i0 = 0;
30 const y = @truncate(i8, x);
30 const y = @as(i8, @truncate(x));
3131 try comptime expect(y == 0);
3232}
3333
3434test "truncate.i0.literal" {
35 var z = @truncate(i0, 0);
35 var z = @as(i0, @truncate(0));
3636 try expect(z == 0);
3737}
3838
3939test "truncate.i0.const" {
4040 const c0: isize = 0;
41 var z = @truncate(i0, c0);
41 var z = @as(i0, @truncate(c0));
4242 try expect(z == 0);
4343}
4444
4545test "truncate.i0.var" {
4646 var d: i8 = 2;
47 var z = @truncate(i0, d);
47 var z = @as(i0, @truncate(d));
4848 try expect(z == 0);
4949}
5050
5151test "truncate on comptime integer" {
52 var x = @truncate(u16, 9999);
52 var x = @as(u16, @truncate(9999));
5353 try expect(x == 9999);
54 var y = @truncate(u16, -21555);
54 var y = @as(u16, @truncate(-21555));
5555 try expect(y == 0xabcd);
56 var z = @truncate(i16, -65537);
56 var z = @as(i16, @truncate(-65537));
5757 try expect(z == -1);
58 var w = @truncate(u1, 1 << 100);
58 var w = @as(u1, @truncate(1 << 100));
5959 try expect(w == 0);
6060}
6161
......@@ -69,7 +69,7 @@ test "truncate on vectors" {
6969 const S = struct {
7070 fn doTheTest() !void {
7171 var v1: @Vector(4, u16) = .{ 0xaabb, 0xccdd, 0xeeff, 0x1122 };
72 var v2 = @truncate(u8, v1);
72 var v2: @Vector(4, u8) = @truncate(v1);
7373 try expect(std.mem.eql(u8, &@as([4]u8, v2), &[4]u8{ 0xbb, 0xdd, 0xff, 0x22 }));
7474 }
7575 };
test/behavior/tuple.zig+1-1
......@@ -403,7 +403,7 @@ test "nested runtime conditionals in tuple initializer" {
403403
404404 var data: u8 = 0;
405405 const x = .{
406 if (data != 0) "" else switch (@truncate(u1, data)) {
406 if (data != 0) "" else switch (@as(u1, @truncate(data))) {
407407 0 => "up",
408408 1 => "down",
409409 },
test/behavior/tuple_declarations.zig+1-1
......@@ -21,7 +21,7 @@ test "tuple declaration type info" {
2121
2222 try expectEqualStrings(info.fields[0].name, "0");
2323 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);
2525 try expect(info.fields[0].is_comptime);
2626 try expect(info.fields[0].alignment == 2);
2727
test/behavior/type.zig+8-8
......@@ -289,7 +289,7 @@ test "Type.Struct" {
289289 try testing.expectEqual(@as(?*const anyopaque, null), infoB.fields[0].default_value);
290290 try testing.expectEqualSlices(u8, "y", infoB.fields[1].name);
291291 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.?)).*);
293293 try testing.expectEqual(@as(usize, 0), infoB.decls.len);
294294 try testing.expectEqual(@as(bool, false), infoB.is_tuple);
295295
......@@ -298,10 +298,10 @@ test "Type.Struct" {
298298 try testing.expectEqual(Type.ContainerLayout.Packed, infoC.layout);
299299 try testing.expectEqualSlices(u8, "x", infoC.fields[0].name);
300300 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.?)).*);
302302 try testing.expectEqualSlices(u8, "y", infoC.fields[1].name);
303303 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.?)).*);
305305 try testing.expectEqual(@as(usize, 0), infoC.decls.len);
306306 try testing.expectEqual(@as(bool, false), infoC.is_tuple);
307307
......@@ -311,10 +311,10 @@ test "Type.Struct" {
311311 try testing.expectEqual(Type.ContainerLayout.Auto, infoD.layout);
312312 try testing.expectEqualSlices(u8, "x", infoD.fields[0].name);
313313 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.?)).*);
315315 try testing.expectEqualSlices(u8, "y", infoD.fields[1].name);
316316 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.?)).*);
318318 try testing.expectEqual(@as(usize, 0), infoD.decls.len);
319319 try testing.expectEqual(@as(bool, false), infoD.is_tuple);
320320
......@@ -324,10 +324,10 @@ test "Type.Struct" {
324324 try testing.expectEqual(Type.ContainerLayout.Auto, infoE.layout);
325325 try testing.expectEqualSlices(u8, "0", infoE.fields[0].name);
326326 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.?)).*);
328328 try testing.expectEqualSlices(u8, "1", infoE.fields[1].name);
329329 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.?)).*);
331331 try testing.expectEqual(@as(usize, 0), infoE.decls.len);
332332 try testing.expectEqual(@as(bool, true), infoE.is_tuple);
333333
......@@ -379,7 +379,7 @@ test "Type.Enum" {
379379 try testing.expectEqual(false, @typeInfo(Bar).Enum.is_exhaustive);
380380 try testing.expectEqual(@as(u32, 1), @intFromEnum(Bar.a));
381381 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))));
383383}
384384
385385test "Type.Union" {
test/behavior/type_info.zig+8-8
......@@ -113,7 +113,7 @@ fn testNullTerminatedPtr() !void {
113113 try expect(ptr_info.Pointer.size == .Many);
114114 try expect(ptr_info.Pointer.is_const == false);
115115 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
118118 try expect(@typeInfo([:0]u8).Pointer.sentinel != null);
119119}
......@@ -151,7 +151,7 @@ fn testArray() !void {
151151 const info = @typeInfo([10:0]u8);
152152 try expect(info.Array.len == 10);
153153 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));
155155 try expect(@sizeOf([10:0]u8) == info.Array.len + 1);
156156 }
157157}
......@@ -295,8 +295,8 @@ fn testStruct() !void {
295295 try expect(unpacked_struct_info.Struct.is_tuple == false);
296296 try expect(unpacked_struct_info.Struct.backing_integer == null);
297297 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);
299 try expect(mem.eql(u8, "foobar", @ptrCast(*align(1) const *const [6:0]u8, unpacked_struct_info.Struct.fields[1].default_value.?).*));
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", @as(*align(1) const *const [6:0]u8, @ptrCast(unpacked_struct_info.Struct.fields[1].default_value.?)).*));
300300}
301301
302302const TestStruct = struct {
......@@ -319,7 +319,7 @@ fn testPackedStruct() !void {
319319 try expect(struct_info.Struct.fields[0].alignment == 0);
320320 try expect(struct_info.Struct.fields[2].type == f32);
321321 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);
323323 try expect(struct_info.Struct.fields[3].alignment == 0);
324324 try expect(struct_info.Struct.decls.len == 2);
325325 try expect(struct_info.Struct.decls[0].is_pub);
......@@ -504,7 +504,7 @@ test "type info for async frames" {
504504
505505 switch (@typeInfo(@Frame(add))) {
506506 .Frame => |frame| {
507 try expect(@ptrCast(@TypeOf(add), frame.function) == add);
507 try expect(@as(@TypeOf(add), @ptrCast(frame.function)) == add);
508508 },
509509 else => unreachable,
510510 }
......@@ -564,7 +564,7 @@ test "typeInfo resolves usingnamespace declarations" {
564564test "value from struct @typeInfo default_value can be loaded at comptime" {
565565 comptime {
566566 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);
568568 }
569569}
570570
......@@ -607,6 +607,6 @@ test "@typeInfo decls ignore dependency loops" {
607607
608608test "type info of tuple of string literal default value" {
609609 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.?)).*;
611611 comptime std.debug.assert(value[0] == 'h');
612612}
test/behavior/vector.zig+1-1
......@@ -1244,7 +1244,7 @@ test "@intCast to u0" {
12441244 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
12451245
12461246 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
12491249 _ = casted[0];
12501250}
test/c_abi/main.zig+9-9
......@@ -143,7 +143,7 @@ export fn zig_longdouble(x: c_longdouble) void {
143143extern fn c_ptr(*anyopaque) void;
144144
145145test "C ABI pointer" {
146 c_ptr(@ptrFromInt(*anyopaque, 0xdeadbeef));
146 c_ptr(@as(*anyopaque, @ptrFromInt(0xdeadbeef)));
147147}
148148
149149export fn zig_ptr(x: *anyopaque) void {
......@@ -1058,14 +1058,14 @@ test "C function that takes byval struct called via function pointer" {
10581058
10591059 var fn_ptr = &c_func_ptr_byval;
10601060 fn_ptr(
1061 @ptrFromInt(*anyopaque, 1),
1062 @ptrFromInt(*anyopaque, 2),
1061 @as(*anyopaque, @ptrFromInt(1)),
1062 @as(*anyopaque, @ptrFromInt(2)),
10631063 ByVal{
10641064 .origin = .{ .x = 9, .y = 10, .z = 11 },
10651065 .size = .{ .width = 12, .height = 13, .depth = 14 },
10661066 },
10671067 @as(c_ulong, 3),
1068 @ptrFromInt(*anyopaque, 4),
1068 @as(*anyopaque, @ptrFromInt(4)),
10691069 @as(c_ulong, 5),
10701070 );
10711071}
......@@ -1098,7 +1098,7 @@ test "f80 bare" {
10981098 if (!has_f80) return error.SkipZigTest;
10991099
11001100 const a = c_f80(12.34);
1101 try expect(@floatCast(f64, a) == 56.78);
1101 try expect(@as(f64, @floatCast(a)) == 56.78);
11021102}
11031103
11041104const f80_struct = extern struct {
......@@ -1111,7 +1111,7 @@ test "f80 struct" {
11111111 if (builtin.mode != .Debug) return error.SkipZigTest;
11121112
11131113 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);
11151115}
11161116
11171117const f80_extra_struct = extern struct {
......@@ -1124,7 +1124,7 @@ test "f80 extra struct" {
11241124 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
11251125
11261126 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);
11281128 try expect(a.b == 24);
11291129}
11301130
......@@ -1133,7 +1133,7 @@ test "f128 bare" {
11331133 if (!has_f128) return error.SkipZigTest;
11341134
11351135 const a = c_f128(12.34);
1136 try expect(@floatCast(f64, a) == 56.78);
1136 try expect(@as(f64, @floatCast(a)) == 56.78);
11371137}
11381138
11391139const f128_struct = extern struct {
......@@ -1144,7 +1144,7 @@ test "f128 struct" {
11441144 if (!has_f128) return error.SkipZigTest;
11451145
11461146 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);
11481148}
11491149
11501150// 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 @@
11export fn entry() void {
2 @alignCast(4, @as(u32, 3));
2 const x: *align(8) u32 = @alignCast(@as(u32, 3));
3 _ = x;
34}
45
56// error
67// backend=stage2
78// target=native
89//
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 @@
11comptime {
2 const ptr = @ptrFromInt(*align(1) i32, 0x1);
3 const aligned = @alignCast(4, ptr);
2 const ptr: *align(1) i32 = @ptrFromInt(0x1);
3 const aligned: *align(4) i32 = @alignCast(ptr);
44 _ = aligned;
55}
66
......@@ -8,4 +8,4 @@ comptime {
88// backend=stage2
99// target=native
1010//
11// :3:35: error: pointer address 0x1 is not aligned to 4 bytes
11// :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 @@
11export fn entry(byte: u8) void {
2 var oops = @bitCast(u7, byte);
2 var oops: u7 = @bitCast(byte);
33 _ = oops;
44}
55
......@@ -7,4 +7,4 @@ export fn entry(byte: u8) void {
77// backend=stage2
88// target=native
99//
10// :2:16: error: @bitCast size mismatch: destination type 'u7' has 7 bits but source type 'u8' has 8 bits
10// :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 @@
11export fn entry() void {
22 const E = enum(u32) { a, b };
3 const y = @bitCast(E, @as(u32, 3));
3 const y: E = @bitCast(@as(u32, 3));
44 _ = y;
55}
66
......@@ -8,5 +8,5 @@ export fn entry() void {
88// backend=stage2
99// target=native
1010//
11// :3:24: error: cannot @bitCast to 'tmp.entry.E'
12// :3:24: note: use @enumFromInt to cast from 'u32'
11// :3:18: error: cannot @bitCast to 'tmp.entry.E'
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 @@
11export fn entry() void {
2 var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf);
2 var foo = (@as(u8, @bitCast(@as(f32, 1.0))) == 0xf);
33 _ = foo;
44}
55
......@@ -7,4 +7,4 @@ export fn entry() void {
77// backend=stage2
88// target=native
99//
10// :2:16: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'f32' has 32 bits
10// :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 @@
11comptime {
22 const value: i32 = -1;
3 const unsigned = @intCast(u32, value);
3 const unsigned: u32 = @intCast(value);
44 _ = unsigned;
55}
66export fn entry1() void {
test/cases/compile_errors/compile_log_a_pointer_to_an_opaque_value.zig+1-1
......@@ -1,5 +1,5 @@
11export fn entry() void {
2 @compileLog(@as(*align(1) const anyopaque, @ptrCast(*const anyopaque, &entry)));
2 @compileLog(@as(*const anyopaque, @ptrCast(&entry)));
33}
44
55// error
test/cases/compile_errors/compile_time_null_ptr_cast.zig+1-1
......@@ -1,6 +1,6 @@
11comptime {
22 var opt_ptr: ?*i32 = null;
3 const ptr = @ptrCast(*i32, opt_ptr);
3 const ptr: *i32 = @ptrCast(opt_ptr);
44 _ = ptr;
55}
66
test/cases/compile_errors/compile_time_undef_ptr_cast.zig+1-1
......@@ -1,6 +1,6 @@
11comptime {
22 var undef_ptr: *i32 = undefined;
3 const ptr = @ptrCast(*i32, undef_ptr);
3 const ptr: *i32 = @ptrCast(undef_ptr);
44 _ = ptr;
55}
66
test/cases/compile_errors/comptime_call_of_function_pointer.zig+1-1
......@@ -1,5 +1,5 @@
11export fn entry() void {
2 const fn_ptr = @ptrFromInt(*align(1) fn () void, 0xffd2);
2 const fn_ptr: *align(1) fn () void = @ptrFromInt(0xffd2);
33 comptime fn_ptr();
44}
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 {
2424export fn foo_vector_ConstPtrSpecialRef() void {
2525 comptime {
2626 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
27 var target: [*]u8 = @ptrCast(&buf);
2828 const slice = target[0..3 :0];
2929 _ = slice;
3030 }
......@@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {
4040export fn foo_cvector_ConstPtrSpecialRef() void {
4141 comptime {
4242 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);
4444 const slice = target[0..3 :0];
4545 _ = slice;
4646 }
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 {
2424export fn foo_vector_ConstPtrSpecialRef() void {
2525 comptime {
2626 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
27 var target: [*]u8 = @ptrCast(&buf);
2828 const slice = target[0..3 :0];
2929 _ = slice;
3030 }
......@@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {
4040export fn foo_cvector_ConstPtrSpecialRef() void {
4141 comptime {
4242 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);
4444 const slice = target[0..3 :0];
4545 _ = slice;
4646 }
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 {
2424export fn foo_vector_ConstPtrSpecialRef() void {
2525 comptime {
2626 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
27 var target: [*]u8 = @ptrCast(&buf);
2828 const slice = target[0..14 :255];
2929 _ = slice;
3030 }
......@@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {
4040export fn foo_cvector_ConstPtrSpecialRef() void {
4141 comptime {
4242 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);
4444 const slice = target[0..14 :255];
4545 _ = slice;
4646 }
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 {
2424export fn foo_vector_ConstPtrSpecialRef() void {
2525 comptime {
2626 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
27 var target: [*]u8 = @ptrCast(&buf);
2828 const slice = target[0..15 :0];
2929 _ = slice;
3030 }
......@@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {
4040export fn foo_cvector_ConstPtrSpecialRef() void {
4141 comptime {
4242 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);
4444 const slice = target[0..15 :0];
4545 _ = slice;
4646 }
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 {
2424export fn foo_vector_ConstPtrSpecialRef() void {
2525 comptime {
2626 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
27 var target: [*]u8 = @ptrCast(&buf);
2828 const slice = target[0..14 :0];
2929 _ = slice;
3030 }
......@@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {
4040export fn foo_cvector_ConstPtrSpecialRef() void {
4141 comptime {
4242 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);
4444 const slice = target[0..14 :0];
4545 _ = slice;
4646 }
test/cases/compile_errors/enumFromInt_on_non-exhaustive_enums_checks_int_in_range.zig+2-2
......@@ -1,11 +1,11 @@
11pub export fn entry() void {
22 const E = enum(u3) { a, b, c, _ };
3 @compileLog(@enumFromInt(E, 100));
3 @compileLog(@as(E, @enumFromInt(100)));
44}
55
66// error
77// target=native
88// backend=stage2
99//
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'
1111// :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) {
33 B = 11,
44};
55export fn entry() void {
6 var x = @enumFromInt(Foo, 0);
6 var x: Foo = @enumFromInt(0);
77 _ = x;
88}
99
......@@ -11,5 +11,5 @@ export fn entry() void {
1111// backend=stage2
1212// target=native
1313//
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'
1515// :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 };
22const Set2 = error{ A, C };
33comptime {
44 var x = Set1.B;
5 var y = @errSetCast(Set2, x);
5 var y: Set2 = @errSetCast(x);
66 _ = y;
77}
88
......@@ -10,4 +10,4 @@ comptime {
1010// backend=stage2
1111// target=native
1212//
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) {
77
88export fn entry() void {
99 var y = @as(f32, 3);
10 var x = @enumFromInt(Small, y);
10 var x: Small = @enumFromInt(y);
1111 _ = x;
1212}
1313
test/cases/compile_errors/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig+1-1
......@@ -8,7 +8,7 @@ const foo = Foo{
88};
99
1010comptime {
11 const field_ptr = @ptrFromInt(*i32, 0x1234);
11 const field_ptr: *i32 = @ptrFromInt(0x1234);
1212 const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr);
1313 _ = another_foo_ptr;
1414}
test/cases/compile_errors/field_access_of_opaque_type.zig+1-1
......@@ -2,7 +2,7 @@ const MyType = opaque {};
22
33export fn entry() bool {
44 var x: i32 = 1;
5 return bar(@ptrCast(*MyType, &x));
5 return bar(@ptrCast(&x));
66}
77
88fn 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 {
22 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
33 var slice: []u8 = &buf;
44 const a: u32 = 1234;
5 @memcpy(slice.ptr, @ptrCast([*]const u8, &a));
5 @memcpy(slice.ptr, @as([*]const u8, @ptrCast(&a)));
66}
77pub export fn entry1() void {
88 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
......@@ -39,7 +39,7 @@ pub export fn memset_array() void {
3939//
4040// :5:5: error: unknown @memcpy length
4141// :5:18: note: destination type '[*]u8' provides no length
42// :5:24: note: source type '[*]align(4) const u8' provides no length
42// :5:24: note: source type '[*]const u8' provides no length
4343// :10:13: error: type '*u8' is not an indexable pointer
4444// :10:13: note: operand must be a slice, a many pointer or a pointer to an array
4545// :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 @@
11export fn entry() u32 {
22 var bytes: [4]u8 = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
3 const ptr = @ptrCast(*u32, &bytes[0]);
3 const ptr: *u32 = @ptrCast(&bytes[0]);
44 return ptr.*;
55}
66
......@@ -8,7 +8,7 @@ export fn entry() u32 {
88// backend=stage2
99// target=native
1010//
11// :3:17: error: cast increases pointer alignment
11// :3:23: error: cast increases pointer alignment
1212// :3:32: note: '*u8' has alignment '1'
13// :3:26: note: '*u32' has alignment '4'
14// :3:17: note: consider using '@alignCast'
13// :3:23: note: '*u32' has alignment '4'
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 @@
11export fn foo() void {
22 var a: f32 = 2;
3 _ = @intFromFloat(comptime_int, a);
3 _ = @as(comptime_int, @intFromFloat(a));
44}
55export fn bar() void {
66 var a: u32 = 2;
7 _ = @floatFromInt(comptime_float, a);
7 _ = @as(comptime_float, @floatFromInt(a));
88}
99
1010// error
1111// backend=stage2
1212// target=native
1313//
14// :3:37: error: unable to resolve comptime value
15// :3:37: note: value being casted to 'comptime_int' must be comptime-known
16// :7:39: error: unable to resolve comptime value
17// :7:39: note: value being casted to 'comptime_float' must be comptime-known
14// :3:41: error: unable to resolve comptime value
15// :3:41: note: value being casted to 'comptime_int' must be comptime-known
16// :7:43: error: unable to resolve comptime value
17// :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 @@
11comptime {
2 _ = @intFromFloat(i8, @as(f32, -129.1));
2 _ = @as(i8, @intFromFloat(@as(f32, -129.1)));
33}
44comptime {
5 _ = @intFromFloat(u8, @as(f32, -1.1));
5 _ = @as(u8, @intFromFloat(@as(f32, -1.1)));
66}
77comptime {
8 _ = @intFromFloat(u8, @as(f32, 256.1));
8 _ = @as(u8, @intFromFloat(@as(f32, 256.1)));
99}
1010
1111// error
1212// backend=stage2
1313// target=native
1414//
15// :2:27: 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'
17// :8:27: error: float value '256.1000061035156' cannot be stored in integer type 'u8'
15// :2:31: error: float value '-129.10000610351562' cannot be stored in integer type 'i8'
16// :5:31: error: float value '-1.100000023841858' 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 @@
11export fn entry() void {
2 var b = @ptrFromInt(*i32, 0);
2 var b: *i32 = @ptrFromInt(0);
33 _ = b;
44}
55
test/cases/compile_errors/int_to_err_non_global_invalid_number.zig+2-2
......@@ -8,7 +8,7 @@ const Set2 = error{
88};
99comptime {
1010 var x = @intFromError(Set1.B);
11 var y = @errSetCast(Set2, @errorFromInt(x));
11 var y: Set2 = @errSetCast(@errorFromInt(x));
1212 _ = y;
1313}
1414
......@@ -16,4 +16,4 @@ comptime {
1616// backend=llvm
1717// target=native
1818//
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 @@
11export fn entry1() void {
22 const spartan_count: u16 = 300;
3 const byte = @intCast(u8, spartan_count);
3 const byte: u8 = @intCast(spartan_count);
44 _ = byte;
55}
66export fn entry2() void {
test/cases/compile_errors/integer_underflow_error.zig+2-2
......@@ -1,9 +1,9 @@
11export 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));
33}
44
55// error
66// backend=stage2
77// target=native
88//
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 @@
11export fn foo() void {
22 var a: f32 = 2;
3 _ = @floatCast(comptime_float, a);
3 _ = @as(comptime_float, @floatCast(a));
44}
55export fn bar() void {
66 var a: f32 = 2;
7 _ = @intFromFloat(f32, a);
7 _ = @as(f32, @intFromFloat(a));
88}
99export fn baz() void {
1010 var a: f32 = 2;
11 _ = @floatFromInt(f32, a);
11 _ = @as(f32, @floatFromInt(a));
1212}
1313export fn qux() void {
1414 var a: u32 = 2;
15 _ = @floatCast(f32, a);
15 _ = @as(f32, @floatCast(a));
1616}
1717
1818// error
1919// backend=stage2
2020// target=native
2121//
22// :3:36: error: unable to cast runtime value to 'comptime_float'
23// :7:23: error: expected integer type, found 'f32'
24// :11:28: error: expected integer type, found 'f32'
25// :15:25: error: expected float type, found 'u32'
22// :3:40: error: unable to cast runtime value to 'comptime_float'
23// :7:18: error: expected integer type, found 'f32'
24// :11:32: error: expected integer type, found 'f32'
25// :15:29: error: expected float type, found 'u32'
test/cases/compile_errors/invalid_int_casts.zig+8-8
......@@ -1,25 +1,25 @@
11export fn foo() void {
22 var a: u32 = 2;
3 _ = @intCast(comptime_int, a);
3 _ = @as(comptime_int, @intCast(a));
44}
55export fn bar() void {
66 var a: u32 = 2;
7 _ = @floatFromInt(u32, a);
7 _ = @as(u32, @floatFromInt(a));
88}
99export fn baz() void {
1010 var a: u32 = 2;
11 _ = @intFromFloat(u32, a);
11 _ = @as(u32, @intFromFloat(a));
1212}
1313export fn qux() void {
1414 var a: f32 = 2;
15 _ = @intCast(u32, a);
15 _ = @as(u32, @intCast(a));
1616}
1717
1818// error
1919// backend=stage2
2020// target=native
2121//
22// :3:32: error: unable to cast runtime value to 'comptime_int'
23// :7:23: error: expected float type, found 'u32'
24// :11:28: error: expected float type, found 'u32'
25// :15:23: error: expected integer or vector, found 'f32'
22// :3:36: error: unable to cast runtime value to 'comptime_int'
23// :7:18: error: expected float type, found 'u32'
24// :11:32: error: expected float type, found 'u32'
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) {
88 b,
99};
1010export fn foo() void {
11 var e = @enumFromInt(E, 15);
11 var e: E = @enumFromInt(15);
1212 var u: U = e;
1313 _ = u;
1414}
1515export fn bar() void {
16 const e = @enumFromInt(E, 15);
16 const e: E = @enumFromInt(15);
1717 var u: U = e;
1818 _ = u;
1919}
......@@ -24,5 +24,5 @@ export fn bar() void {
2424//
2525// :12:16: error: runtime coercion to union 'tmp.U' from non-exhaustive enum
2626// :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)'
2828// :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 @@
11export fn foo1() void {
22 var bytes = [_]u8{ 1, 2 };
3 const word: u16 = @bitCast(u16, bytes[0..]);
3 const word: u16 = @bitCast(bytes[0..]);
44 _ = word;
55}
66export fn foo2() void {
77 var bytes: []const u8 = &[_]u8{ 1, 2 };
8 const word: u16 = @bitCast(u16, bytes);
8 const word: u16 = @bitCast(bytes);
99 _ = word;
1010}
1111
......@@ -13,7 +13,7 @@ export fn foo2() void {
1313// backend=stage2
1414// target=native
1515//
16// :3:42: error: cannot @bitCast from '*[2]u8'
17// :3:42: note: use @intFromPtr to cast to 'u16'
18// :8:37: error: cannot @bitCast from '[]const u8'
19// :8:37: note: use @intFromPtr to cast to 'u16'
16// :3:37: error: cannot @bitCast from '*[2]u8'
17// :3:37: note: use @intFromPtr to cast to 'u16'
18// :8:32: error: cannot @bitCast from '[]const u8'
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 @@
11export fn entry() void {
22 const float: f32 align(@alignOf(i64)) = 5.99999999999994648725e-01;
33 const float_ptr = &float;
4 const int_ptr = @ptrCast(*const i64, float_ptr);
4 const int_ptr: *const i64 = @ptrCast(float_ptr);
55 const int_val = int_ptr.*;
66 _ = int_val;
77}
test/cases/compile_errors/missing_builtin_arg_in_initializer.zig+7-3
......@@ -1,8 +1,11 @@
11comptime {
2 const v = @as();
2 const a = @as();
33}
44comptime {
5 const u = @bitCast(u32);
5 const b = @bitCast();
6}
7comptime {
8 const c = @as(u32);
69}
710
811// error
......@@ -10,4 +13,5 @@ comptime {
1013// target=native
1114//
1215// :2:15: error: expected 2 arguments, found 0
13// :5:15: error: expected 2 arguments, found 1
16// :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 @@
11export fn entry() void {
2 const x = @intFromFloat(i32, @as(i32, 54));
2 const x: i32 = @intFromFloat(@as(i32, 54));
33 _ = x;
44}
55
test/cases/compile_errors/non_int_passed_to_floatFromInt.zig+1-1
......@@ -1,5 +1,5 @@
11export fn entry() void {
2 const x = @floatFromInt(f32, 1.1);
2 const x: f32 = @floatFromInt(1.1);
33 _ = x;
44}
55
test/cases/compile_errors/out_of_int_range_comptime_float_passed_to_intFromFloat.zig+1-1
......@@ -1,5 +1,5 @@
11export fn entry() void {
2 const x = @intFromFloat(i8, 200);
2 const x: i8 = @intFromFloat(200);
33 _ = x;
44}
55
test/cases/compile_errors/ptrCast_discards_const_qualifier.zig+3-3
......@@ -1,6 +1,6 @@
11export fn entry() void {
22 const x: i32 = 1234;
3 const y = @ptrCast(*i32, &x);
3 const y: *i32 = @ptrCast(&x);
44 _ = y;
55}
66
......@@ -8,5 +8,5 @@ export fn entry() void {
88// backend=stage2
99// target=native
1010//
11// :3:15: error: cast discards const qualifier
12// :3:15: note: consider using '@constCast'
11// :3:21: error: cast discards const qualifier
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 @@
11pub export fn entry() void {
2 _ = @ptrFromInt(i32, 10);
2 _ = @as(i32, @ptrFromInt(10));
33}
44
55pub export fn entry2() void {
6 _ = @ptrFromInt([]u8, 20);
6 _ = @as([]u8, @ptrFromInt(20));
77}
88
99// error
1010// backend=stage2
1111// target=native
1212//
13// :2:21: error: expected pointer type, found 'i32'
14// :6:21: error: integer cannot be converted to slice type '[]u8'
15// :6:21: note: slice length cannot be inferred from address
13// :2:18: error: expected pointer type, found 'i32'
14// :6:19: error: integer cannot be converted to slice type '[]u8'
15// :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 @@
11pub export fn entry() void {
2 var y = @ptrFromInt([*]align(4) u8, 5);
2 var y: [*]align(4) u8 = @ptrFromInt(5);
33 _ = y;
44}
55
test/cases/compile_errors/ptrcast_to_non-pointer.zig+2-2
......@@ -1,9 +1,9 @@
11export fn entry(a: *i32) usize {
2 return @ptrCast(usize, a);
2 return @ptrCast(a);
33}
44
55// error
66// backend=llvm
77// target=native
88//
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 @@
11comptime {
22 const array: [4]u8 = "aoeu".*;
33 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));
55 const deref = int_ptr.*;
66 _ = deref;
77}
test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig+1-1
......@@ -7,7 +7,7 @@ const Tag = @Type(.{
77 },
88});
99export fn entry() void {
10 _ = @enumFromInt(Tag, 0);
10 _ = @as(Tag, @enumFromInt(0));
1111}
1212
1313// error
test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig+1-1
......@@ -7,7 +7,7 @@ const Tag = @Type(.{
77 },
88});
99export fn entry() void {
10 _ = @enumFromInt(Tag, 0);
10 _ = @as(Tag, @enumFromInt(0));
1111}
1212
1313// error
test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig+2-2
......@@ -1,6 +1,6 @@
11export fn foo() void {
22 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)).*;
44 _ = value;
55}
66
......@@ -8,4 +8,4 @@ export fn foo() void {
88// backend=stage2
99// target=native
1010//
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 @@
11test "enum" {
22 const E = enum(u8) { A, B, _ };
3 _ = @tagName(@enumFromInt(E, 5));
3 _ = @tagName(@as(E, @enumFromInt(5)));
44}
55
66// error
......@@ -8,5 +8,5 @@ test "enum" {
88// target=native
99// is_test=1
1010//
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'
1212// :2:15: note: declared here
test/cases/compile_errors/truncate_sign_mismatch.zig+8-8
......@@ -1,25 +1,25 @@
11export fn entry1() i8 {
22 var x: u32 = 10;
3 return @truncate(i8, x);
3 return @truncate(x);
44}
55export fn entry2() u8 {
66 var x: i32 = -10;
7 return @truncate(u8, x);
7 return @truncate(x);
88}
99export fn entry3() i8 {
1010 comptime var x: u32 = 10;
11 return @truncate(i8, x);
11 return @truncate(x);
1212}
1313export fn entry4() u8 {
1414 comptime var x: i32 = -10;
15 return @truncate(u8, x);
15 return @truncate(x);
1616}
1717
1818// error
1919// backend=stage2
2020// target=native
2121//
22// :3:26: error: expected signed integer type, found 'u32'
23// :7:26: error: expected unsigned integer type, found 'i32'
24// :11:26: error: expected signed integer type, found 'u32'
25// :15:26: error: expected unsigned integer type, found 'i32'
22// :3:22: error: expected signed integer type, found 'u32'
23// :7:22: error: expected unsigned integer type, found 'i32'
24// :11:22: error: expected signed integer type, found 'u32'
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 {};
22extern fn bar(d: *Derp) void;
33export fn foo() void {
44 var x = @as(u8, 1);
5 bar(@ptrCast(*anyopaque, &x));
5 bar(@as(*anyopaque, @ptrCast(&x)));
66}
77
88// error
test/cases/enum_values.0.zig+1-1
......@@ -7,7 +7,7 @@ pub fn main() void {
77 number1;
88 number2;
99 }
10 const number3 = @enumFromInt(Number, 2);
10 const number3: Number = @enumFromInt(2);
1111 if (@intFromEnum(number3) != 2) {
1212 unreachable;
1313 }
test/cases/enum_values.1.zig+1-1
......@@ -3,7 +3,7 @@ const Number = enum { One, Two, Three };
33pub fn main() void {
44 var number1 = Number.One;
55 var number2: Number = .Two;
6 const number3 = @enumFromInt(Number, 2);
6 const number3: Number = @enumFromInt(2);
77 assert(number1 != number2);
88 assert(number2 != number3);
99 assert(@intFromEnum(number1) == 0);
test/cases/error_in_nested_declaration.zig+3-3
......@@ -3,7 +3,7 @@ const S = struct {
33 c: i32,
44 a: struct {
55 pub fn str(_: @This(), extra: []u32) []i32 {
6 return @bitCast([]i32, extra);
6 return @bitCast(extra);
77 }
88 },
99};
......@@ -27,5 +27,5 @@ pub export fn entry2() void {
2727// target=native
2828//
2929// :17:12: error: C pointers cannot point to opaque types
30// :6:29: error: cannot @bitCast to '[]i32'
31// :6:29: note: use @ptrCast to cast from '[]u32'
30// :6:20: error: cannot @bitCast to '[]i32'
31// :6:20: note: use @ptrCast to cast from '[]u32'
test/cases/int_to_ptr.0.zig+2-2
......@@ -1,8 +1,8 @@
11pub fn main() void {
2 _ = @ptrFromInt(*u8, 0);
2 _ = @as(*u8, @ptrFromInt(0));
33}
44
55// error
66// output_mode=Exe
77//
8// :2:24: error: pointer type '*u8' does not allow address zero
8// :2:18: error: pointer type '*u8' does not allow address zero
test/cases/int_to_ptr.1.zig+2-2
......@@ -1,7 +1,7 @@
11pub fn main() void {
2 _ = @ptrFromInt(*u32, 2);
2 _ = @as(*u32, @ptrFromInt(2));
33}
44
55// error
66//
7// :2:25: error: pointer type '*u32' requires aligned address
7// :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 {
3434 setFs(@intFromPtr(&test_value));
3535 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);
3838 assert(test_ptr.* == 12345);
3939 test_ptr.* = 98765;
4040 assert(test_value == 98765);
test/cases/llvm/large_slices.zig+1-1
......@@ -1,5 +1,5 @@
11pub 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)];
33 _ = large_slice;
44}
55
test/cases/safety/@alignCast misaligned.zig +2-1
......@@ -16,7 +16,8 @@ pub fn main() !void {
1616}
1717fn foo(bytes: []u8) u32 {
1818 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);
2021 return int_slice[0];
2122}
2223// run
test/cases/safety/@enumFromInt - no matching tag value.zig +1-1
......@@ -17,7 +17,7 @@ pub fn main() !void {
1717 return error.TestFailed;
1818}
1919fn bar(a: u2) Foo {
20 return @enumFromInt(Foo, a);
20 return @enumFromInt(a);
2121}
2222fn baz(_: Foo) void {}
2323
test/cases/safety/@errSetCast error not present in destination.zig +1-1
......@@ -14,7 +14,7 @@ pub fn main() !void {
1414 return error.TestFailed;
1515}
1616fn foo(set1: Set1) Set2 {
17 return @errSetCast(Set2, set1);
17 return @errSetCast(set1);
1818}
1919// run
2020// backend=llvm
test/cases/safety/@intCast to u0.zig +1-1
......@@ -14,7 +14,7 @@ pub fn main() !void {
1414}
1515
1616fn bar(one: u1, not_zero: i32) void {
17 var x = one << @intCast(u0, not_zero);
17 var x = one << @as(u0, @intCast(not_zero));
1818 _ = x;
1919}
2020// run
test/cases/safety/@intFromFloat cannot fit - negative out of range.zig +1-1
......@@ -12,7 +12,7 @@ pub fn main() !void {
1212 return error.TestFailed;
1313}
1414fn bar(a: f32) i8 {
15 return @intFromFloat(i8, a);
15 return @intFromFloat(a);
1616}
1717fn baz(_: i8) void {}
1818// run
test/cases/safety/@intFromFloat cannot fit - negative to unsigned.zig +1-1
......@@ -12,7 +12,7 @@ pub fn main() !void {
1212 return error.TestFailed;
1313}
1414fn bar(a: f32) u8 {
15 return @intFromFloat(u8, a);
15 return @intFromFloat(a);
1616}
1717fn baz(_: u8) void {}
1818// run
test/cases/safety/@intFromFloat cannot fit - positive out of range.zig +1-1
......@@ -12,7 +12,7 @@ pub fn main() !void {
1212 return error.TestFailed;
1313}
1414fn bar(a: f32) u8 {
15 return @intFromFloat(u8, a);
15 return @intFromFloat(a);
1616}
1717fn baz(_: u8) void {}
1818// 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
99}
1010pub fn main() !void {
1111 var zero: usize = 0;
12 var b = @ptrFromInt(*u8, zero);
12 var b: *u8 = @ptrFromInt(zero);
1313 _ = b;
1414 return error.TestFailed;
1515}
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
99}
1010pub fn main() !void {
1111 var zero: usize = 0;
12 var b = @ptrFromInt(*i32, zero);
12 var b: *i32 = @ptrFromInt(zero);
1313 _ = b;
1414 return error.TestFailed;
1515}
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
99}
1010pub fn main() !void {
1111 var x: usize = 5;
12 var y = @ptrFromInt([*]align(4) u8, x);
12 var y: [*]align(4) u8 = @ptrFromInt(x);
1313 _ = y;
1414 return error.TestFailed;
1515}
test/cases/safety/@tagName on corrupted enum value.zig +1-1
......@@ -15,7 +15,7 @@ const E = enum(u32) {
1515
1616pub fn main() !void {
1717 var e: E = undefined;
18 @memset(@ptrCast([*]u8, &e)[0..@sizeOf(E)], 0x55);
18 @memset(@as([*]u8, @ptrCast(&e))[0..@sizeOf(E)], 0x55);
1919 var n = @tagName(e);
2020 _ = n;
2121 return error.TestFailed;
test/cases/safety/@tagName on corrupted union value.zig +1-1
......@@ -15,7 +15,7 @@ const U = union(enum(u32)) {
1515
1616pub fn main() !void {
1717 var u: U = undefined;
18 @memset(@ptrCast([*]u8, &u)[0..@sizeOf(U)], 0x55);
18 @memset(@as([*]u8, @ptrCast(&u))[0..@sizeOf(U)], 0x55);
1919 var t: @typeInfo(U).Union.tag_type.? = u;
2020 var n = @tagName(t);
2121 _ = n;
test/cases/safety/pointer casting to null function pointer.zig +1-1
......@@ -13,7 +13,7 @@ fn getNullPtr() ?*const anyopaque {
1313}
1414pub fn main() !void {
1515 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);
1717 _ = required_ptr;
1818 return error.TestFailed;
1919}
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
99}
1010pub fn main() !void {
1111 var value: c_short = -1;
12 var casted = @intCast(u32, value);
12 var casted: u32 = @intCast(value);
1313 _ = casted;
1414 return error.TestFailed;
1515}
test/cases/safety/signed integer not fitting in cast to unsigned integer.zig +1-1
......@@ -13,7 +13,7 @@ pub fn main() !void {
1313 return error.TestFailed;
1414}
1515fn unsigned_cast(x: i32) u32 {
16 return @intCast(u32, x);
16 return @intCast(x);
1717}
1818// run
1919// 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
1010
1111pub fn main() !void {
1212 var x = @splat(4, @as(i32, -2147483647));
13 var y = @intCast(@Vector(4, u32), x);
13 var y: @Vector(4, u32) = @intCast(x);
1414 _ = y;
1515 return error.TestFailed;
1616}
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
99}
1010
1111pub 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) };
1313 const slice = buf[0..3 :null];
1414 _ = slice;
1515 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) {
1313};
1414pub fn main() !void {
1515 var a: E = undefined;
16 @ptrCast(*u32, &a).* = 255;
16 @as(*u32, @ptrCast(&a)).* = 255;
1717 switch (a) {
1818 .one => @panic("one"),
1919 else => @panic("else"),
test/cases/safety/switch else on corrupt enum value - union.zig +1-1
......@@ -18,7 +18,7 @@ const U = union(E) {
1818};
1919pub fn main() !void {
2020 var a: U = undefined;
21 @ptrCast(*align(@alignOf(U)) u32, &a).* = 0xFFFF_FFFF;
21 @as(*align(@alignOf(U)) u32, @ptrCast(&a)).* = 0xFFFF_FFFF;
2222 switch (a) {
2323 .one => @panic("one"),
2424 else => @panic("else"),
test/cases/safety/switch else on corrupt enum value.zig +1-1
......@@ -13,7 +13,7 @@ const E = enum(u32) {
1313};
1414pub fn main() !void {
1515 var a: E = undefined;
16 @ptrCast(*u32, &a).* = 255;
16 @as(*u32, @ptrCast(&a)).* = 255;
1717 switch (a) {
1818 else => @panic("else"),
1919 }
test/cases/safety/switch on corrupted enum value.zig +1-1
......@@ -15,7 +15,7 @@ const E = enum(u32) {
1515
1616pub fn main() !void {
1717 var e: E = undefined;
18 @memset(@ptrCast([*]u8, &e)[0..@sizeOf(E)], 0x55);
18 @memset(@as([*]u8, @ptrCast(&e))[0..@sizeOf(E)], 0x55);
1919 switch (e) {
2020 .X, .Y => @breakpoint(),
2121 }
test/cases/safety/switch on corrupted union value.zig +1-1
......@@ -15,7 +15,7 @@ const U = union(enum(u32)) {
1515
1616pub fn main() !void {
1717 var u: U = undefined;
18 @memset(@ptrCast([*]u8, &u)[0..@sizeOf(U)], 0x55);
18 @memset(@as([*]u8, @ptrCast(&u))[0..@sizeOf(U)], 0x55);
1919 switch (u) {
2020 .X, .Y => @breakpoint(),
2121 }
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
1010
1111pub fn main() !void {
1212 var x = @splat(4, @as(u32, 0xdeadbeef));
13 var y = @intCast(@Vector(4, u16), x);
13 var y: @Vector(4, u16) = @intCast(x);
1414 _ = y;
1515 return error.TestFailed;
1616}
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
99}
1010pub fn main() !void {
1111 var value: u8 = 245;
12 var casted = @intCast(i8, value);
12 var casted: i8 = @intCast(value);
1313 _ = casted;
1414 return error.TestFailed;
1515}
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
1010
1111pub fn main() !void {
1212 var x = @splat(4, @as(u32, 0x80000000));
13 var y = @intCast(@Vector(4, i32), x);
13 var y: @Vector(4, i32) = @intCast(x);
1414 _ = y;
1515 return error.TestFailed;
1616}
test/cases/safety/value does not fit in shortening cast - u0.zig +1-1
......@@ -14,7 +14,7 @@ pub fn main() !void {
1414 return error.TestFailed;
1515}
1616fn shorten_cast(x: u8) u0 {
17 return @intCast(u0, x);
17 return @intCast(x);
1818}
1919// run
2020// backend=llvm
test/cases/safety/value does not fit in shortening cast.zig +1-1
......@@ -14,7 +14,7 @@ pub fn main() !void {
1414 return error.TestFailed;
1515}
1616fn shorten_cast(x: i32) i8 {
17 return @intCast(i8, x);
17 return @intCast(x);
1818}
1919// run
2020// backend=llvm
test/cbe.zig+5-5
......@@ -642,7 +642,7 @@ pub fn addCases(ctx: *Cases) !void {
642642 \\pub export fn main() c_int {
643643 \\ var number1 = Number.One;
644644 \\ var number2: Number = .Two;
645 \\ const number3 = @enumFromInt(Number, 2);
645 \\ const number3: Number = @enumFromInt(2);
646646 \\ if (number1 == number2) return 1;
647647 \\ if (number2 == number3) return 1;
648648 \\ if (@intFromEnum(number1) != 0) return 1;
......@@ -737,19 +737,19 @@ pub fn addCases(ctx: *Cases) !void {
737737 case.addError(
738738 \\pub export fn main() c_int {
739739 \\ const a = 1;
740 \\ _ = @enumFromInt(bool, a);
740 \\ _ = @as(bool, @enumFromInt(a));
741741 \\}
742742 , &.{
743 ":3:20: error: expected enum, found 'bool'",
743 ":3:19: error: expected enum, found 'bool'",
744744 });
745745
746746 case.addError(
747747 \\const E = enum { a, b, c };
748748 \\pub export fn main() c_int {
749 \\ _ = @enumFromInt(E, 3);
749 \\ _ = @as(E, @enumFromInt(3));
750750 \\}
751751 , &.{
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'",
753753 ":1:11: note: enum declared here",
754754 });
755755
test/compare_output.zig+5-5
......@@ -180,8 +180,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
180180 \\const c = @cImport(@cInclude("stdlib.h"));
181181 \\
182182 \\export fn compare_fn(a: ?*const anyopaque, b: ?*const anyopaque) c_int {
183 \\ const a_int = @ptrCast(*const i32, @alignCast(@alignOf(i32), a));
184 \\ const b_int = @ptrCast(*const i32, @alignCast(@alignOf(i32), b));
183 \\ const a_int: *const i32 = @ptrCast(@alignCast(a));
184 \\ const b_int: *const i32 = @ptrCast(@alignCast(b));
185185 \\ if (a_int.* < b_int.*) {
186186 \\ return -1;
187187 \\ } else if (a_int.* > b_int.*) {
......@@ -194,7 +194,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
194194 \\pub export fn main() c_int {
195195 \\ var array = [_]u32{ 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 };
196196 \\
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);
198198 \\
199199 \\ for (array, 0..) |item, i| {
200200 \\ if (item != i) {
......@@ -229,8 +229,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
229229 \\ }
230230 \\ const small: f32 = 3.25;
231231 \\ const x: f64 = small;
232 \\ const y = @intFromFloat(i32, x);
233 \\ const z = @floatFromInt(f64, y);
232 \\ const y: i32 = @intFromFloat(x);
233 \\ const z: f64 = @floatFromInt(y);
234234 \\ _ = c.printf("%.2f\n%d\n%.2f\n%.2f\n", x, y, z, @as(f64, -0.4));
235235 \\ return 0;
236236 \\}
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
3737 exe.dead_strip_dylibs = true;
3838
3939 const run_cmd = b.addRunArtifact(exe);
40 run_cmd.expectExitCode(@bitCast(u8, @as(i8, -2))); // should fail
40 run_cmd.expectExitCode(@as(u8, @bitCast(@as(i8, -2)))); // should fail
4141 test_step.dependOn(&run_cmd.step);
4242 }
4343}
test/nvptx.zig+1-1
......@@ -60,7 +60,7 @@ pub fn addCases(ctx: *Cases) !void {
6060 \\
6161 \\ var _sdata: [1024]f32 addrspace(.shared) = undefined;
6262 \\ 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);
6464 \\ const tid: u32 = threadIdX();
6565 \\ var sum = d_x[tid];
6666 \\ sdata[tid] = sum;
test/standalone/hello_world/hello_libc.zig+1-1
......@@ -10,6 +10,6 @@ const msg = "Hello, world!\n";
1010pub export fn main(argc: c_int, argv: **u8) c_int {
1111 _ = argv;
1212 _ = 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;
1414 return 0;
1515}
test/standalone/issue_11595/main.zig+1-1
......@@ -1,5 +1,5 @@
11extern fn check() c_int;
22
33pub fn main() u8 {
4 return @intCast(u8, check());
4 return @as(u8, @intCast(check()));
55}
test/standalone/main_return_error/error_u8_non_zero.zig+1-1
......@@ -1,7 +1,7 @@
11const Err = error{Foo};
22
33fn foo() u8 {
4 var x = @intCast(u8, 9);
4 var x = @as(u8, @intCast(9));
55 return x;
66}
77
test/standalone/mix_c_files/main.zig+1-1
......@@ -25,6 +25,6 @@ pub fn main() anyerror!void {
2525 x = add_C(x);
2626 x = add_C_zig(x);
2727
28 const u = @intCast(u32, x);
28 const u = @as(u32, @intCast(x));
2929 try std.testing.expect(u / 100 == u % 100);
3030}
test/standalone/pie/main.zig+1-1
......@@ -5,7 +5,7 @@ threadlocal var foo: u8 = 42;
55
66test "Check ELF header" {
77 // 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()));
99 try std.testing.expectEqual(elf.ET.DYN, header.e_type);
1010}
1111
test/translate_c.zig+70-70
......@@ -351,7 +351,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
351351 \\}
352352 , &[_][]const u8{
353353 \\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)))));
355355 \\ _ = @TypeOf(a);
356356 \\}
357357 });
......@@ -465,7 +465,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
465465 \\ pub fn y(self: anytype) @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int) {
466466 \\ const Intermediate = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8);
467467 \\ 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)));
469469 \\ }
470470 \\};
471471 \\pub const struct_bar = extern struct {
......@@ -473,7 +473,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
473473 \\ pub fn y(self: anytype) @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int) {
474474 \\ const Intermediate = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8);
475475 \\ 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)));
477477 \\ }
478478 \\};
479479 });
......@@ -635,7 +635,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
635635 \\};
636636 \\pub export fn foo(arg_x: [*c]outer) void {
637637 \\ 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)));
639639 \\}
640640 });
641641
......@@ -721,7 +721,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
721721 \\pub const struct_opaque_2 = opaque {};
722722 \\pub export fn function(arg_opaque_1: ?*struct_opaque) void {
723723 \\ 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));
725725 \\ _ = @TypeOf(cast);
726726 \\}
727727 });
......@@ -799,7 +799,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
799799 \\ _ = @TypeOf(b);
800800 \\ const c: c_int = undefined;
801801 \\ _ = @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)));
803803 \\ _ = @TypeOf(d);
804804 \\ var e: c_int = 10;
805805 \\ _ = @TypeOf(e);
......@@ -904,8 +904,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
904904 , &[_][]const u8{
905905 \\pub extern fn foo() void;
906906 \\pub export fn bar() void {
907 \\ var func_ptr: ?*anyopaque = @ptrCast(?*anyopaque, &foo);
908 \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @ptrFromInt(?*const fn () callconv(.C) void, @intCast(c_ulong, @intFromPtr(func_ptr)));
907 \\ var func_ptr: ?*anyopaque = @as(?*anyopaque, @ptrCast(&foo));
908 \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @as(?*const fn () callconv(.C) void, @ptrFromInt(@as(c_ulong, @intCast(@intFromPtr(func_ptr)))));
909909 \\ _ = @TypeOf(typed_func_ptr);
910910 \\}
911911 });
......@@ -1353,7 +1353,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13531353 , &[_][]const u8{
13541354 \\pub export fn foo() ?*anyopaque {
13551355 \\ var x: [*c]c_ushort = undefined;
1356 \\ return @ptrCast(?*anyopaque, x);
1356 \\ return @as(?*anyopaque, @ptrCast(x));
13571357 \\}
13581358 });
13591359
......@@ -1543,7 +1543,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15431543 , &[_][]const u8{
15441544 \\pub export fn ptrcast() [*c]f32 {
15451545 \\ 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)));
15471547 \\}
15481548 });
15491549
......@@ -1555,7 +1555,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15551555 , &[_][]const u8{
15561556 \\pub export fn ptrptrcast() [*c][*c]f32 {
15571557 \\ 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)));
15591559 \\}
15601560 });
15611561
......@@ -1579,23 +1579,23 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15791579 \\pub export fn test_ptr_cast() void {
15801580 \\ var p: ?*anyopaque = undefined;
15811581 \\ {
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)));
15831583 \\ _ = @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)));
15851585 \\ _ = @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)));
15871587 \\ _ = @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)));
15891589 \\ _ = @TypeOf(to_longlong);
15901590 \\ }
15911591 \\ {
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)));
15931593 \\ _ = @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)));
15951595 \\ _ = @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)));
15971597 \\ _ = @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)));
15991599 \\ _ = @TypeOf(to_longlong);
16001600 \\ }
16011601 \\}
......@@ -1651,7 +1651,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16511651 \\}
16521652 , &[_][]const u8{
16531653 \\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);
16551655 \\}
16561656 });
16571657
......@@ -1885,7 +1885,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
18851885 \\const enum_unnamed_1 =
18861886 ++ " " ++ default_enum_type ++
18871887 \\;
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));
18891889 \\pub const i: c_int = 0;
18901890 \\pub const j: c_int = 1;
18911891 \\pub const k: c_int = 2;
......@@ -2091,12 +2091,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
20912091 \\ _ = @TypeOf(c_1);
20922092 \\ var a_2: c_int = undefined;
20932093 \\ 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))));
20952095 \\ {
20962096 \\ var d: c_int = 5;
20972097 \\ _ = @TypeOf(d);
20982098 \\ }
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)));
21002100 \\ _ = @TypeOf(d);
21012101 \\}
21022102 });
......@@ -2236,9 +2236,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
22362236 \\int c = 3.1415;
22372237 \\double d = 3;
22382238 , &[_][]const u8{
2239 \\pub export var a: f32 = @floatCast(f32, 3.1415);
2239 \\pub export var a: f32 = @as(f32, @floatCast(3.1415));
22402240 \\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));
22422242 \\pub export var d: f64 = 3;
22432243 });
22442244
......@@ -2423,7 +2423,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
24232423 , &[_][]const u8{
24242424 \\pub export fn int_from_float(arg_a: f32) c_int {
24252425 \\ var a = arg_a;
2426 \\ return @intFromFloat(c_int, a);
2426 \\ return @as(c_int, @intFromFloat(a));
24272427 \\}
24282428 });
24292429
......@@ -2533,15 +2533,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
25332533 \\ var a = arg_a;
25342534 \\ var b = arg_b;
25352535 \\ var c = arg_c;
2536 \\ var d: enum_Foo = @bitCast(c_uint, FooA);
2536 \\ var d: enum_Foo = @as(c_uint, @bitCast(FooA));
25372537 \\ var e: c_int = @intFromBool((a != 0) and (b != 0));
25382538 \\ var f: c_int = @intFromBool((b != 0) and (c != null));
25392539 \\ var g: c_int = @intFromBool((a != 0) and (c != null));
25402540 \\ var h: c_int = @intFromBool((a != 0) or (b != 0));
25412541 \\ var i: c_int = @intFromBool((b != 0) or (c != null));
25422542 \\ var j: c_int = @intFromBool((a != 0) or (c != null));
2543 \\ var k: c_int = @intFromBool((a != 0) or (@bitCast(c_int, d) != 0));
2544 \\ var l: c_int = @intFromBool((@bitCast(c_int, d) != 0) and (b != 0));
2543 \\ var k: c_int = @intFromBool((a != 0) or (@as(c_int, @bitCast(d)) != 0));
2544 \\ var l: c_int = @intFromBool((@as(c_int, @bitCast(d)) != 0) and (b != 0));
25452545 \\ var m: c_int = @intFromBool((c != null) or (d != 0));
25462546 \\ var td: SomeTypedef = 44;
25472547 \\ var o: c_int = @intFromBool((td != 0) or (b != 0));
......@@ -2707,10 +2707,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
27072707 \\pub export var array: [100]c_int = [1]c_int{0} ** 100;
27082708 \\pub export fn foo(arg_index: c_int) c_int {
27092709 \\ var index = arg_index;
2710 \\ return array[@intCast(c_uint, index)];
2710 \\ return array[@as(c_uint, @intCast(index))];
27112711 \\}
27122712 ,
2713 \\pub const ACCESS = array[@intCast(usize, @as(c_int, 2))];
2713 \\pub const ACCESS = array[@as(usize, @intCast(@as(c_int, 2)))];
27142714 });
27152715
27162716 cases.add("cast signed array index to unsigned",
......@@ -2722,7 +2722,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
27222722 \\pub export fn foo() void {
27232723 \\ var a: [10]c_int = undefined;
27242724 \\ var i: c_int = 0;
2725 \\ a[@intCast(c_uint, i)] = 0;
2725 \\ a[@as(c_uint, @intCast(i))] = 0;
27262726 \\}
27272727 });
27282728
......@@ -2735,7 +2735,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
27352735 \\pub export fn foo() void {
27362736 \\ var a: [10]c_longlong = undefined;
27372737 \\ var i: c_longlong = 0;
2738 \\ a[@intCast(usize, i)] = 0;
2738 \\ a[@as(usize, @intCast(i))] = 0;
27392739 \\}
27402740 });
27412741
......@@ -3006,8 +3006,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
30063006 \\pub export fn log2(arg_a: c_uint) c_int {
30073007 \\ var a = arg_a;
30083008 \\ var i: c_int = 0;
3009 \\ while (a > @bitCast(c_uint, @as(c_int, 0))) {
3010 \\ a >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
3009 \\ while (a > @as(c_uint, @bitCast(@as(c_int, 0)))) {
3010 \\ a >>= @intCast(@as(c_int, 1));
30113011 \\ }
30123012 \\ return i;
30133013 \\}
......@@ -3026,8 +3026,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
30263026 \\pub export fn log2(arg_a: u32) c_int {
30273027 \\ var a = arg_a;
30283028 \\ var i: c_int = 0;
3029 \\ while (a > @bitCast(u32, @as(c_int, 0))) {
3030 \\ a >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
3029 \\ while (a > @as(u32, @bitCast(@as(c_int, 0)))) {
3030 \\ a >>= @intCast(@as(c_int, 1));
30313031 \\ }
30323032 \\ return i;
30333033 \\}
......@@ -3084,14 +3084,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
30843084 \\ ref.* ^= @as(c_int, 1);
30853085 \\ break :blk ref.*;
30863086 \\ };
3087 \\ a >>= @intCast(@import("std").math.Log2Int(c_int), blk: {
3087 \\ a >>= @intCast(blk: {
30883088 \\ const ref = &a;
3089 \\ ref.* >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
3089 \\ ref.* >>= @intCast(@as(c_int, 1));
30903090 \\ break :blk ref.*;
30913091 \\ });
3092 \\ a <<= @intCast(@import("std").math.Log2Int(c_int), blk: {
3092 \\ a <<= @intCast(blk: {
30933093 \\ const ref = &a;
3094 \\ ref.* <<= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
3094 \\ ref.* <<= @intCast(@as(c_int, 1));
30953095 \\ break :blk ref.*;
30963096 \\ });
30973097 \\ a = @divTrunc(a, blk: {
......@@ -3106,12 +3106,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
31063106 \\ });
31073107 \\ b /= blk: {
31083108 \\ const ref = &b;
3109 \\ ref.* /= @bitCast(c_uint, @as(c_int, 1));
3109 \\ ref.* /= @as(c_uint, @bitCast(@as(c_int, 1)));
31103110 \\ break :blk ref.*;
31113111 \\ };
31123112 \\ b %= blk: {
31133113 \\ const ref = &b;
3114 \\ ref.* %= @bitCast(c_uint, @as(c_int, 1));
3114 \\ ref.* %= @as(c_uint, @bitCast(@as(c_int, 1)));
31153115 \\ break :blk ref.*;
31163116 \\ };
31173117 \\}
......@@ -3134,42 +3134,42 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
31343134 \\ var a: c_uint = 0;
31353135 \\ a +%= blk: {
31363136 \\ const ref = &a;
3137 \\ ref.* +%= @bitCast(c_uint, @as(c_int, 1));
3137 \\ ref.* +%= @as(c_uint, @bitCast(@as(c_int, 1)));
31383138 \\ break :blk ref.*;
31393139 \\ };
31403140 \\ a -%= blk: {
31413141 \\ const ref = &a;
3142 \\ ref.* -%= @bitCast(c_uint, @as(c_int, 1));
3142 \\ ref.* -%= @as(c_uint, @bitCast(@as(c_int, 1)));
31433143 \\ break :blk ref.*;
31443144 \\ };
31453145 \\ a *%= blk: {
31463146 \\ const ref = &a;
3147 \\ ref.* *%= @bitCast(c_uint, @as(c_int, 1));
3147 \\ ref.* *%= @as(c_uint, @bitCast(@as(c_int, 1)));
31483148 \\ break :blk ref.*;
31493149 \\ };
31503150 \\ a &= blk: {
31513151 \\ const ref = &a;
3152 \\ ref.* &= @bitCast(c_uint, @as(c_int, 1));
3152 \\ ref.* &= @as(c_uint, @bitCast(@as(c_int, 1)));
31533153 \\ break :blk ref.*;
31543154 \\ };
31553155 \\ a |= blk: {
31563156 \\ const ref = &a;
3157 \\ ref.* |= @bitCast(c_uint, @as(c_int, 1));
3157 \\ ref.* |= @as(c_uint, @bitCast(@as(c_int, 1)));
31583158 \\ break :blk ref.*;
31593159 \\ };
31603160 \\ a ^= blk: {
31613161 \\ const ref = &a;
3162 \\ ref.* ^= @bitCast(c_uint, @as(c_int, 1));
3162 \\ ref.* ^= @as(c_uint, @bitCast(@as(c_int, 1)));
31633163 \\ break :blk ref.*;
31643164 \\ };
3165 \\ a >>= @intCast(@import("std").math.Log2Int(c_uint), blk: {
3165 \\ a >>= @intCast(blk: {
31663166 \\ const ref = &a;
3167 \\ ref.* >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
3167 \\ ref.* >>= @intCast(@as(c_int, 1));
31683168 \\ break :blk ref.*;
31693169 \\ });
3170 \\ a <<= @intCast(@import("std").math.Log2Int(c_uint), blk: {
3170 \\ a <<= @intCast(blk: {
31713171 \\ const ref = &a;
3172 \\ ref.* <<= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
3172 \\ ref.* <<= @intCast(@as(c_int, 1));
31733173 \\ break :blk ref.*;
31743174 \\ });
31753175 \\}
......@@ -3258,21 +3258,21 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
32583258 \\pub extern fn fn_bool(x: bool) void;
32593259 \\pub extern fn fn_ptr(x: ?*anyopaque) void;
32603260 \\pub export fn call() void {
3261 \\ fn_int(@intFromFloat(c_int, 3.0));
3262 \\ fn_int(@intFromFloat(c_int, 3.0));
3261 \\ fn_int(@as(c_int, @intFromFloat(3.0)));
3262 \\ fn_int(@as(c_int, @intFromFloat(3.0)));
32633263 \\ fn_int(@as(c_int, 1094861636));
3264 \\ fn_f32(@floatFromInt(f32, @as(c_int, 3)));
3265 \\ fn_f64(@floatFromInt(f64, @as(c_int, 3)));
3266 \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '3'))));
3267 \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '\x01'))));
3268 \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, 0))));
3264 \\ fn_f32(@as(f32, @floatFromInt(@as(c_int, 3))));
3265 \\ fn_f64(@as(f64, @floatFromInt(@as(c_int, 3))));
3266 \\ fn_char(@as(u8, @bitCast(@as(i8, @truncate(@as(c_int, '3'))))));
3267 \\ fn_char(@as(u8, @bitCast(@as(i8, @truncate(@as(c_int, '\x01'))))));
3268 \\ fn_char(@as(u8, @bitCast(@as(i8, @truncate(@as(c_int, 0))))));
32693269 \\ fn_f32(3.0);
32703270 \\ fn_f64(3.0);
32713271 \\ fn_bool(@as(c_int, 123) != 0);
32723272 \\ fn_bool(@as(c_int, 0) != 0);
32733273 \\ fn_bool(@intFromPtr(&fn_int) != 0);
3274 \\ fn_int(@intCast(c_int, @intFromPtr(&fn_int)));
3275 \\ fn_ptr(@ptrFromInt(?*anyopaque, @as(c_int, 42)));
3274 \\ fn_int(@as(c_int, @intCast(@intFromPtr(&fn_int))));
3275 \\ fn_ptr(@as(?*anyopaque, @ptrFromInt(@as(c_int, 42))));
32763276 \\}
32773277 });
32783278
......@@ -3411,11 +3411,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
34113411 \\}
34123412 , &[_][]const u8{
34133413 \\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))));
34153415 \\}
34163416 \\pub export fn bar(arg_x: c_long) c_ushort {
34173417 \\ var x = arg_x;
3418 \\ return @bitCast(c_ushort, @truncate(c_short, x));
3418 \\ return @as(c_ushort, @bitCast(@as(c_short, @truncate(x))));
34193419 \\}
34203420 });
34213421
......@@ -3473,11 +3473,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
34733473 \\}
34743474 \\pub export fn bar(arg_a: [*c]const c_int) void {
34753475 \\ var a = arg_a;
3476 \\ foo(@ptrFromInt([*c]c_int, @intFromPtr(a)));
3476 \\ foo(@as([*c]c_int, @ptrFromInt(@intFromPtr(a))));
34773477 \\}
34783478 \\pub export fn baz(arg_a: [*c]volatile c_int) void {
34793479 \\ var a = arg_a;
3480 \\ foo(@ptrFromInt([*c]c_int, @intFromPtr(a)));
3480 \\ foo(@as([*c]c_int, @ptrFromInt(@intFromPtr(a))));
34813481 \\}
34823482 });
34833483
......@@ -3860,9 +3860,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
38603860 \\ p[1];
38613861 \\}
38623862 , &[_][]const u8{
3863 \\_ = p[@intCast(c_uint, @as(c_int, 0))];
3863 \\_ = p[@as(c_uint, @intCast(@as(c_int, 0)))];
38643864 ,
3865 \\_ = p[@intCast(c_uint, @as(c_int, 1))];
3865 \\_ = p[@as(c_uint, @intCast(@as(c_int, 1)))];
38663866 });
38673867
38683868 cases.add("Undefined macro identifier",
......@@ -3928,7 +3928,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
39283928 \\pub export fn foo() void {
39293929 \\ var a: S = undefined;
39303930 \\ 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));
39323932 \\ _ = @TypeOf(c);
39333933 \\}
39343934 });
......@@ -3943,7 +3943,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
39433943 \\pub export fn foo() void {
39443944 \\ var a: S = undefined;
39453945 \\ 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));
39473947 \\ _ = @TypeOf(c);
39483948 \\}
39493949 });
tools/extract-grammar.zig+1-1
......@@ -90,7 +90,7 @@ fn read(path: []const u8, allocator: mem.Allocator) ![:0]const u8 {
9090 const st = try f.stat();
9191 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);
9494 const n = try f.readAll(src);
9595 if (n != st.size) return error.UnexpectedEndOfFile;
9696
tools/gen_spirv_spec.zig+1-1
......@@ -40,7 +40,7 @@ fn extendedStructs(
4040 kinds: []const g.OperandKind,
4141) !ExtendedStructSet {
4242 var map = ExtendedStructSet.init(arena);
43 try map.ensureTotalCapacity(@intCast(u32, kinds.len));
43 try map.ensureTotalCapacity(@as(u32, @intCast(kinds.len)));
4444
4545 for (kinds) |kind| {
4646 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)
441441 const sh_name = try arena.dupe(u8, mem.sliceTo(shstrtab[s(shdr.sh_name)..], 0));
442442 log.debug("found section: {s}", .{sh_name});
443443 if (mem.eql(u8, sh_name, ".dynsym")) {
444 dynsym_index = @intCast(u16, i);
444 dynsym_index = @as(u16, @intCast(i));
445445 }
446446 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));
448448 }
449449 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)
470470 for (copied_dyn_syms) |sym| {
471471 const this_section = s(sym.st_shndx);
472472 const name = try arena.dupe(u8, mem.sliceTo(dynstr[s(sym.st_name)..], 0));
473 const ty = @truncate(u4, sym.st_info);
474 const binding = @truncate(u4, sym.st_info >> 4);
475 const visib = @enumFromInt(elf.STV, @truncate(u2, sym.st_other));
473 const ty = @as(u4, @truncate(sym.st_info));
474 const binding = @as(u4, @truncate(sym.st_info >> 4));
475 const visib = @as(elf.STV, @enumFromInt(@as(u2, @truncate(sym.st_other))));
476476 const size = s(sym.st_size);
477477
478478 if (parse.blacklist.contains(name)) continue;
tools/update-linux-headers.zig+1-1
......@@ -112,7 +112,7 @@ const DestTarget = struct {
112112 _ = self;
113113 var hasher = std.hash.Wyhash.init(0);
114114 std.hash.autoHash(&hasher, a.arch);
115 return @truncate(u32, hasher.final());
115 return @as(u32, @truncate(hasher.final()));
116116 }
117117
118118 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 {
591591
592592 for (all_features, 0..) |feat, i| {
593593 const llvm_name = feat.llvm_name orelse continue;
594 const zig_feat = @enumFromInt(Feature, i);
594 const zig_feat = @as(Feature, @enumFromInt(i));
595595 const zig_name = @tagName(zig_feat);
596596 try llvm_to_zig_cpu_features.put(llvm_name, zig_name);
597597 }
......@@ -790,7 +790,7 @@ const Syntax = union(enum) {
790790};
791791
792792fn 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));
794794 for (obj.get("!superclasses").?.array.items) |superclass_json| {
795795 const superclass = superclass_json.string;
796796 if (std.mem.eql(u8, superclass, "Joined")) {