authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-06-25 19:13:47-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-06-25 19:14:26-04:00
log85902115d4fde6120b6cea610cd6f79baede5aaa
tree50bac6719a89a52f51efb1b0ec4b42b905868024
parent7013567f8abde19e5176d902ce88abc754fc9a3e

x86_64: cleanup `@as` invasion


1 files changed, 287 insertions(+), 309 deletions(-)

src/arch/x86_64/CodeGen.zig+287-309
......@@ -329,7 +329,7 @@ pub const MCValue = union(enum) {
329329 .load_frame,
330330 .reserved_frame,
331331 => unreachable, // not offsettable
332 .immediate => |imm| .{ .immediate = @as(u64, @bitCast(@as(i64, @bitCast(imm)) +% off)) },
332 .immediate => |imm| .{ .immediate = @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 },
......@@ -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 = @as(u31, @intCast(alloc_abi.size)),
609 .abi_size = @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 @as(u32, @intCast(set_align_stack.alignment.toByteUnitsOptional().?))
697 @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 = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len));
982 const result_index: 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 = @as(u32, @intCast(self.mir_extra.items.len));
1003 const result: 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 => @as(u32, @bitCast(@field(extra, field.name))),
1007 i32 => @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| @as(u32, @bitCast(s)),
1218 .unsigned => |u| @as(u32, @intCast(u)),
1217 .signed => |s| @bitCast(s),
1218 .unsigned => |u| @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| @as(u32, @bitCast(s)),
1250 .unsigned => |u| @as(u32, @intCast(u)),
1249 .signed => |s| @bitCast(s),
1250 .unsigned => |u| @intCast(u),
12511251 },
12521252 } },
12531253 .ri64 => .{ .rx = .{
......@@ -1339,8 +1339,8 @@ fn asmRegisterRegisterImmediate(
13391339 .r1 = reg1,
13401340 .r2 = reg2,
13411341 .i = switch (imm) {
1342 .signed => |s| @as(u32, @bitCast(s)),
1343 .unsigned => |u| @as(u32, @intCast(u)),
1342 .signed => |s| @bitCast(s),
1343 .unsigned => |u| @intCast(u),
13441344 },
13451345 } },
13461346 });
......@@ -1458,7 +1458,7 @@ fn asmRegisterRegisterMemoryImmediate(
14581458 .fixes = tag[0],
14591459 .r1 = reg1,
14601460 .r2 = reg2,
1461 .i = @as(u8, @intCast(imm.unsigned)),
1461 .i = @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| @as(u32, @bitCast(s)),
1494 .unsigned => |u| @as(u32, @intCast(u)),
1493 .signed => |s| @bitCast(s),
1494 .unsigned => |u| @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 = @as(u8, @intCast(imm.unsigned)),
1565 .i = @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 @as(u32, @intCast(self.mir_instructions.len));
1620 @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 = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len));
1742 const mir_inst: Mir.Inst.Index = @intCast(self.mir_instructions.len);
17431743 try self.mir_to_air_map.put(self.gpa, mir_inst, inst);
17441744 }
17451745
......@@ -2034,7 +2034,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {
20342034
20352035 var data_off: i32 = 0;
20362036 for (exitlude_jump_relocs, 0..) |*exitlude_jump_reloc, index_usize| {
2037 const index = @as(u32, @intCast(index_usize));
2037 const index: u32 = @intCast(index_usize);
20382038 const tag_name = mod.intern_pool.stringToSlice(enum_ty.enumFields(mod)[index_usize]);
20392039 const tag_val = try mod.enumValueFieldIndex(enum_ty, index);
20402040 const tag_mcv = try self.genTypedValue(.{ .ty = enum_ty, .val = tag_val });
......@@ -2052,7 +2052,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {
20522052 exitlude_jump_reloc.* = try self.asmJmpReloc(undefined);
20532053 try self.performReloc(skip_reloc);
20542054
2055 data_off += @as(i32, @intCast(tag_name.len + 1));
2055 data_off += @intCast(tag_name.len + 1);
20562056 }
20572057
20582058 try self.airTrap();
......@@ -2169,7 +2169,7 @@ fn computeFrameLayout(self: *Self) !FrameLayout {
21692169 const frame_offset = self.frame_locs.items(.disp);
21702170
21712171 for (stack_frame_order, FrameIndex.named_count..) |*frame_order, frame_index|
2172 frame_order.* = @as(FrameIndex, @enumFromInt(frame_index));
2172 frame_order.* = @enumFromInt(frame_index);
21732173 {
21742174 const SortContext = struct {
21752175 frame_align: @TypeOf(frame_align),
......@@ -2197,7 +2197,7 @@ fn computeFrameLayout(self: *Self) !FrameLayout {
21972197 }
21982198 }
21992199
2200 var rbp_offset = @as(i32, @intCast(save_reg_list.count() * 8));
2200 var rbp_offset: i32 = @intCast(save_reg_list.count() * 8);
22012201 self.setFrameLoc(.base_ptr, .rbp, &rbp_offset, false);
22022202 self.setFrameLoc(.ret_addr, .rbp, &rbp_offset, false);
22032203 self.setFrameLoc(.args_frame, .rbp, &rbp_offset, false);
......@@ -2212,11 +2212,11 @@ fn computeFrameLayout(self: *Self) !FrameLayout {
22122212 rsp_offset = mem.alignForward(i32, rsp_offset, @as(i32, 1) << needed_align);
22132213 rsp_offset -= stack_frame_align_offset;
22142214 frame_size[@intFromEnum(FrameIndex.call_frame)] =
2215 @as(u31, @intCast(rsp_offset - frame_offset[@intFromEnum(FrameIndex.stack_frame)]));
2215 @intCast(rsp_offset - frame_offset[@intFromEnum(FrameIndex.stack_frame)]);
22162216
22172217 return .{
22182218 .stack_mask = @as(u32, math.maxInt(u32)) << (if (need_align_stack) needed_align else 0),
2219 .stack_adjust = @as(u32, @intCast(rsp_offset - frame_offset[@intFromEnum(FrameIndex.call_frame)])),
2219 .stack_adjust = @intCast(rsp_offset - frame_offset[@intFromEnum(FrameIndex.call_frame)]),
22202220 .save_reg_list = save_reg_list,
22212221 };
22222222}
......@@ -2247,7 +2247,7 @@ fn allocFrameIndex(self: *Self, alloc: FrameAlloc) !FrameIndex {
22472247 _ = self.free_frame_indices.swapRemoveAt(free_i);
22482248 return frame_index;
22492249 }
2250 const frame_index = @as(FrameIndex, @enumFromInt(self.frame_allocs.len));
2250 const frame_index: FrameIndex = @enumFromInt(self.frame_allocs.len);
22512251 try self.frame_allocs.append(self.gpa, alloc);
22522252 return frame_index;
22532253}
......@@ -2323,7 +2323,7 @@ const State = struct {
23232323
23242324fn initRetroactiveState(self: *Self) State {
23252325 var state: State = undefined;
2326 state.inst_tracking_len = @as(u32, @intCast(self.inst_tracking.count()));
2326 state.inst_tracking_len = @intCast(self.inst_tracking.count());
23272327 state.scope_generation = self.scope_generation;
23282328 return state;
23292329}
......@@ -2394,9 +2394,7 @@ fn restoreState(self: *Self, state: State, deaths: []const Air.Inst.Index, compt
23942394 self.inst_tracking.getPtr(current_inst).?.trackSpill(self, current_inst);
23952395 }
23962396 {
2397 const reg = RegisterManager.regAtTrackedIndex(
2398 @as(RegisterManager.RegisterBitSet.ShiftInt, @intCast(index)),
2399 );
2397 const reg = RegisterManager.regAtTrackedIndex(@intCast(index));
24002398 self.register_manager.freeReg(reg);
24012399 self.register_manager.getRegAssumeFree(reg, target_maybe_inst);
24022400 }
......@@ -2630,7 +2628,7 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
26302628
26312629 const dst_ty = self.typeOfIndex(inst);
26322630 const dst_int_info = dst_ty.intInfo(mod);
2633 const abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
2631 const abi_size: u32 = @intCast(dst_ty.abiSize(mod));
26342632
26352633 const min_ty = if (dst_int_info.bits < src_int_info.bits) dst_ty else src_ty;
26362634 const extend = switch (src_int_info.signedness) {
......@@ -2708,9 +2706,9 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
27082706 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
27092707
27102708 const dst_ty = self.typeOfIndex(inst);
2711 const dst_abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
2709 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(mod));
27122710 const src_ty = self.typeOf(ty_op.operand);
2713 const src_abi_size = @as(u32, @intCast(src_ty.abiSize(mod)));
2711 const src_abi_size: u32 = @intCast(src_ty.abiSize(mod));
27142712
27152713 const result = result: {
27162714 const src_mcv = try self.resolveInst(ty_op.operand);
......@@ -2727,7 +2725,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
27272725 assert(src_ty.zigTypeTag(mod) == .Vector and dst_ty.vectorLen(mod) == src_ty.vectorLen(mod));
27282726 const dst_info = dst_ty.childType(mod).intInfo(mod);
27292727 const src_info = src_ty.childType(mod).intInfo(mod);
2730 const mir_tag = if (@as(?Mir.Inst.FixedTag, switch (dst_info.bits) {
2728 const mir_tag = @as(?Mir.Inst.FixedTag, switch (dst_info.bits) {
27312729 8 => switch (src_info.bits) {
27322730 16 => switch (dst_ty.vectorLen(mod)) {
27332731 1...8 => if (self.hasFeature(.avx)) .{ .vp_b, .ackusw } else .{ .p_b, .ackusw },
......@@ -2750,18 +2748,18 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
27502748 else => null,
27512749 },
27522750 else => null,
2753 })) |tag| tag else return self.fail("TODO implement airTrunc for {}", .{
2751 }) orelse return self.fail("TODO implement airTrunc for {}", .{
27542752 dst_ty.fmt(self.bin_file.options.module.?),
27552753 });
27562754
27572755 const elem_ty = src_ty.childType(mod);
2758 const mask_val = try mod.intValue(elem_ty, @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - dst_info.bits)));
2756 const mask_val = try mod.intValue(elem_ty, @as(u64, math.maxInt(u64)) >> @intCast(64 - dst_info.bits));
27592757
27602758 const splat_ty = try mod.vectorType(.{
2761 .len = @as(u32, @intCast(@divExact(@as(u64, if (src_abi_size > 16) 256 else 128), src_info.bits))),
2759 .len = @intCast(@divExact(@as(u64, if (src_abi_size > 16) 256 else 128), src_info.bits)),
27622760 .child = elem_ty.ip_index,
27632761 });
2764 const splat_abi_size = @as(u32, @intCast(splat_ty.abiSize(mod)));
2762 const splat_abi_size: u32 = @intCast(splat_ty.abiSize(mod));
27652763
27662764 const splat_val = try mod.intern(.{ .aggregate = .{
27672765 .ty = splat_ty.ip_index,
......@@ -2836,7 +2834,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
28362834 try self.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr);
28372835 try self.genSetMem(
28382836 .{ .frame = frame_index },
2839 @as(i32, @intCast(ptr_ty.abiSize(mod))),
2837 @intCast(ptr_ty.abiSize(mod)),
28402838 len_ty,
28412839 len,
28422840 );
......@@ -2970,7 +2968,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
29702968 try self.genSetReg(limit_reg, ty, dst_mcv);
29712969 try self.genShiftBinOpMir(.{ ._r, .sa }, ty, limit_mcv, .{ .immediate = reg_bits - 1 });
29722970 try self.genBinOpMir(.{ ._, .xor }, ty, limit_mcv, .{
2973 .immediate = (@as(u64, 1) << @as(u6, @intCast(reg_bits - 1))) - 1,
2971 .immediate = (@as(u64, 1) << @intCast(reg_bits - 1)) - 1,
29742972 });
29752973 if (reg_extra_bits > 0) {
29762974 const shifted_rhs_reg = try self.copyToTmpRegister(ty, rhs_mcv);
......@@ -2989,7 +2987,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
29892987 break :cc .o;
29902988 } else cc: {
29912989 try self.genSetReg(limit_reg, ty, .{
2992 .immediate = @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - ty.bitSize(mod))),
2990 .immediate = @as(u64, math.maxInt(u64)) >> @intCast(64 - ty.bitSize(mod)),
29932991 });
29942992
29952993 try self.genBinOpMir(.{ ._, .add }, ty, dst_mcv, rhs_mcv);
......@@ -3053,7 +3051,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
30533051 try self.genSetReg(limit_reg, ty, dst_mcv);
30543052 try self.genShiftBinOpMir(.{ ._r, .sa }, ty, limit_mcv, .{ .immediate = reg_bits - 1 });
30553053 try self.genBinOpMir(.{ ._, .xor }, ty, limit_mcv, .{
3056 .immediate = (@as(u64, 1) << @as(u6, @intCast(reg_bits - 1))) - 1,
3054 .immediate = (@as(u64, 1) << @intCast(reg_bits - 1)) - 1,
30573055 });
30583056 if (reg_extra_bits > 0) {
30593057 const shifted_rhs_reg = try self.copyToTmpRegister(ty, rhs_mcv);
......@@ -3128,12 +3126,12 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
31283126 try self.genBinOpMir(.{ ._, .xor }, ty, limit_mcv, rhs_mcv);
31293127 try self.genShiftBinOpMir(.{ ._, .sa }, ty, limit_mcv, .{ .immediate = reg_bits - 1 });
31303128 try self.genBinOpMir(.{ ._, .xor }, ty, limit_mcv, .{
3131 .immediate = (@as(u64, 1) << @as(u6, @intCast(reg_bits - 1))) - 1,
3129 .immediate = (@as(u64, 1) << @intCast(reg_bits - 1)) - 1,
31323130 });
31333131 break :cc .o;
31343132 } else cc: {
31353133 try self.genSetReg(limit_reg, ty, .{
3136 .immediate = @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - reg_bits)),
3134 .immediate = @as(u64, math.maxInt(u64)) >> @intCast(64 - reg_bits),
31373135 });
31383136 break :cc .c;
31393137 };
......@@ -3186,13 +3184,13 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
31863184 try self.allocFrameIndex(FrameAlloc.initType(tuple_ty, mod));
31873185 try self.genSetMem(
31883186 .{ .frame = frame_index },
3189 @as(i32, @intCast(tuple_ty.structFieldOffset(1, mod))),
3187 @intCast(tuple_ty.structFieldOffset(1, mod)),
31903188 Type.u1,
31913189 .{ .eflags = cc },
31923190 );
31933191 try self.genSetMem(
31943192 .{ .frame = frame_index },
3195 @as(i32, @intCast(tuple_ty.structFieldOffset(0, mod))),
3193 @intCast(tuple_ty.structFieldOffset(0, mod)),
31963194 ty,
31973195 partial_mcv,
31983196 );
......@@ -3259,13 +3257,13 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
32593257 try self.allocFrameIndex(FrameAlloc.initType(tuple_ty, mod));
32603258 try self.genSetMem(
32613259 .{ .frame = frame_index },
3262 @as(i32, @intCast(tuple_ty.structFieldOffset(1, mod))),
3260 @intCast(tuple_ty.structFieldOffset(1, mod)),
32633261 tuple_ty.structFieldType(1, mod),
32643262 .{ .eflags = cc },
32653263 );
32663264 try self.genSetMem(
32673265 .{ .frame = frame_index },
3268 @as(i32, @intCast(tuple_ty.structFieldOffset(0, mod))),
3266 @intCast(tuple_ty.structFieldOffset(0, mod)),
32693267 tuple_ty.structFieldType(0, mod),
32703268 partial_mcv,
32713269 );
......@@ -3333,7 +3331,7 @@ fn genSetFrameTruncatedOverflowCompare(
33333331 );
33343332 }
33353333
3336 const payload_off = @as(i32, @intCast(tuple_ty.structFieldOffset(0, mod)));
3334 const payload_off: i32 = @intCast(tuple_ty.structFieldOffset(0, mod));
33373335 if (hi_limb_off > 0) try self.genSetMem(.{ .frame = frame_index }, payload_off, rest_ty, src_mcv);
33383336 try self.genSetMem(
33393337 .{ .frame = frame_index },
......@@ -3343,7 +3341,7 @@ fn genSetFrameTruncatedOverflowCompare(
33433341 );
33443342 try self.genSetMem(
33453343 .{ .frame = frame_index },
3346 @as(i32, @intCast(tuple_ty.structFieldOffset(1, mod))),
3344 @intCast(tuple_ty.structFieldOffset(1, mod)),
33473345 tuple_ty.structFieldType(1, mod),
33483346 if (overflow_cc) |_| .{ .register = overflow_reg.to8() } else .{ .eflags = .ne },
33493347 );
......@@ -3400,13 +3398,13 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
34003398 if (dst_info.bits >= lhs_active_bits + rhs_active_bits) {
34013399 try self.genSetMem(
34023400 .{ .frame = frame_index },
3403 @as(i32, @intCast(tuple_ty.structFieldOffset(0, mod))),
3401 @intCast(tuple_ty.structFieldOffset(0, mod)),
34043402 tuple_ty.structFieldType(0, mod),
34053403 partial_mcv,
34063404 );
34073405 try self.genSetMem(
34083406 .{ .frame = frame_index },
3409 @as(i32, @intCast(tuple_ty.structFieldOffset(1, mod))),
3407 @intCast(tuple_ty.structFieldOffset(1, mod)),
34103408 tuple_ty.structFieldType(1, mod),
34113409 .{ .immediate = 0 }, // cc being set is impossible
34123410 );
......@@ -3430,7 +3428,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
34303428/// Quotient is saved in .rax and remainder in .rdx.
34313429fn genIntMulDivOpMir(self: *Self, tag: Mir.Inst.FixedTag, ty: Type, lhs: MCValue, rhs: MCValue) !void {
34323430 const mod = self.bin_file.options.module.?;
3433 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
3431 const abi_size: u32 = @intCast(ty.abiSize(mod));
34343432 if (abi_size > 8) {
34353433 return self.fail("TODO implement genIntMulDivOpMir for ABI size larger than 8", .{});
34363434 }
......@@ -3470,7 +3468,7 @@ fn genIntMulDivOpMir(self: *Self, tag: Mir.Inst.FixedTag, ty: Type, lhs: MCValue
34703468/// Clobbers .rax and .rdx registers.
34713469fn genInlineIntDivFloor(self: *Self, ty: Type, lhs: MCValue, rhs: MCValue) !MCValue {
34723470 const mod = self.bin_file.options.module.?;
3473 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
3471 const abi_size: u32 = @intCast(ty.abiSize(mod));
34743472 const int_info = ty.intInfo(mod);
34753473 const dividend: Register = switch (lhs) {
34763474 .register => |reg| reg,
......@@ -3609,7 +3607,7 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
36093607 try self.copyToRegisterWithInstTracking(inst, dst_ty, src_mcv);
36103608
36113609 const pl_ty = dst_ty.childType(mod);
3612 const pl_abi_size = @as(i32, @intCast(pl_ty.abiSize(mod)));
3610 const pl_abi_size: i32 = @intCast(pl_ty.abiSize(mod));
36133611 try self.genSetMem(.{ .reg = dst_mcv.getReg().? }, pl_abi_size, Type.bool, .{ .immediate = 1 });
36143612 break :result if (self.liveness.isUnused(inst)) .unreach else dst_mcv;
36153613 };
......@@ -3641,17 +3639,12 @@ fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
36413639 defer if (eu_lock) |lock| self.register_manager.unlockReg(lock);
36423640
36433641 const result = try self.copyToRegisterWithInstTracking(inst, err_union_ty, operand);
3644 if (err_off > 0) {
3645 const shift = @as(u6, @intCast(err_off * 8));
3646 try self.genShiftBinOpMir(
3647 .{ ._r, .sh },
3648 err_union_ty,
3649 result,
3650 .{ .immediate = shift },
3651 );
3652 } else {
3653 try self.truncateRegister(Type.anyerror, result.register);
3654 }
3642 if (err_off > 0) try self.genShiftBinOpMir(
3643 .{ ._r, .sh },
3644 err_union_ty,
3645 result,
3646 .{ .immediate = @as(u6, @intCast(err_off * 8)) },
3647 ) else try self.truncateRegister(Type.anyerror, result.register);
36553648 break :result result;
36563649 },
36573650 .load_frame => |frame_addr| break :result .{ .load_frame = .{
......@@ -3699,17 +3692,12 @@ fn genUnwrapErrorUnionPayloadMir(
36993692 try self.copyToRegisterWithInstTracking(inst, err_union_ty, err_union)
37003693 else
37013694 .{ .register = try self.copyToTmpRegister(err_union_ty, err_union) };
3702 if (payload_off > 0) {
3703 const shift = @as(u6, @intCast(payload_off * 8));
3704 try self.genShiftBinOpMir(
3705 .{ ._r, .sh },
3706 err_union_ty,
3707 result_mcv,
3708 .{ .immediate = shift },
3709 );
3710 } else {
3711 try self.truncateRegister(payload_ty, result_mcv.register);
3712 }
3695 if (payload_off > 0) try self.genShiftBinOpMir(
3696 .{ ._r, .sh },
3697 err_union_ty,
3698 result_mcv,
3699 .{ .immediate = @as(u6, @intCast(payload_off * 8)) },
3700 ) else try self.truncateRegister(payload_ty, result_mcv.register);
37133701 break :result result_mcv;
37143702 },
37153703 else => return self.fail("TODO implement genUnwrapErrorUnionPayloadMir for {}", .{err_union}),
......@@ -3741,8 +3729,8 @@ fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {
37413729 const eu_ty = src_ty.childType(mod);
37423730 const pl_ty = eu_ty.errorUnionPayload(mod);
37433731 const err_ty = eu_ty.errorUnionSet(mod);
3744 const err_off = @as(i32, @intCast(errUnionErrorOffset(pl_ty, mod)));
3745 const err_abi_size = @as(u32, @intCast(err_ty.abiSize(mod)));
3732 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, mod));
3733 const err_abi_size: u32 = @intCast(err_ty.abiSize(mod));
37463734 try self.asmRegisterMemory(
37473735 .{ ._, .mov },
37483736 registerAlias(dst_reg, err_abi_size),
......@@ -3780,8 +3768,8 @@ fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
37803768
37813769 const eu_ty = src_ty.childType(mod);
37823770 const pl_ty = eu_ty.errorUnionPayload(mod);
3783 const pl_off = @as(i32, @intCast(errUnionPayloadOffset(pl_ty, mod)));
3784 const dst_abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
3771 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, mod));
3772 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(mod));
37853773 try self.asmRegisterMemory(
37863774 .{ ._, .lea },
37873775 registerAlias(dst_reg, dst_abi_size),
......@@ -3807,8 +3795,8 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
38073795 const eu_ty = src_ty.childType(mod);
38083796 const pl_ty = eu_ty.errorUnionPayload(mod);
38093797 const err_ty = eu_ty.errorUnionSet(mod);
3810 const err_off = @as(i32, @intCast(errUnionErrorOffset(pl_ty, mod)));
3811 const err_abi_size = @as(u32, @intCast(err_ty.abiSize(mod)));
3798 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, mod));
3799 const err_abi_size: u32 = @intCast(err_ty.abiSize(mod));
38123800 try self.asmMemoryImmediate(
38133801 .{ ._, .mov },
38143802 Memory.sib(Memory.PtrSize.fromSize(err_abi_size), .{
......@@ -3828,8 +3816,8 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
38283816 const dst_lock = self.register_manager.lockReg(dst_reg);
38293817 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
38303818
3831 const pl_off = @as(i32, @intCast(errUnionPayloadOffset(pl_ty, mod)));
3832 const dst_abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
3819 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, mod));
3820 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(mod));
38333821 try self.asmRegisterMemory(
38343822 .{ ._, .lea },
38353823 registerAlias(dst_reg, dst_abi_size),
......@@ -3878,7 +3866,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
38783866 try self.genCopy(pl_ty, opt_mcv, pl_mcv);
38793867
38803868 if (!same_repr) {
3881 const pl_abi_size = @as(i32, @intCast(pl_ty.abiSize(mod)));
3869 const pl_abi_size: i32 = @intCast(pl_ty.abiSize(mod));
38823870 switch (opt_mcv) {
38833871 else => unreachable,
38843872
......@@ -3917,8 +3905,8 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
39173905 if (!pl_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result .{ .immediate = 0 };
39183906
39193907 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(eu_ty, mod));
3920 const pl_off = @as(i32, @intCast(errUnionPayloadOffset(pl_ty, mod)));
3921 const err_off = @as(i32, @intCast(errUnionErrorOffset(pl_ty, mod)));
3908 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, mod));
3909 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, mod));
39223910 try self.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, operand);
39233911 try self.genSetMem(.{ .frame = frame_index }, err_off, err_ty, .{ .immediate = 0 });
39243912 break :result .{ .load_frame = .{ .index = frame_index } };
......@@ -3939,8 +3927,8 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
39393927 if (!pl_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result try self.resolveInst(ty_op.operand);
39403928
39413929 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(eu_ty, mod));
3942 const pl_off = @as(i32, @intCast(errUnionPayloadOffset(pl_ty, mod)));
3943 const err_off = @as(i32, @intCast(errUnionErrorOffset(pl_ty, mod)));
3930 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, mod));
3931 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, mod));
39443932 try self.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, .undef);
39453933 const operand = try self.resolveInst(ty_op.operand);
39463934 try self.genSetMem(.{ .frame = frame_index }, err_off, err_ty, operand);
......@@ -4002,7 +3990,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
40023990 const dst_lock = self.register_manager.lockReg(dst_reg);
40033991 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
40043992
4005 const dst_abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
3993 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(mod));
40063994 try self.asmRegisterMemory(
40073995 .{ ._, .lea },
40083996 registerAlias(dst_reg, dst_abi_size),
......@@ -4179,7 +4167,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
41794167 // additional `mov` is needed at the end to get the actual value
41804168
41814169 const elem_ty = ptr_ty.elemType2(mod);
4182 const elem_abi_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
4170 const elem_abi_size: u32 = @intCast(elem_ty.abiSize(mod));
41834171 const index_ty = self.typeOf(bin_op.rhs);
41844172 const index_mcv = try self.resolveInst(bin_op.rhs);
41854173 const index_lock = switch (index_mcv) {
......@@ -4319,7 +4307,7 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
43194307 .load_frame => |frame_addr| {
43204308 if (tag_abi_size <= 8) {
43214309 const off: i32 = if (layout.tag_align < layout.payload_align)
4322 @as(i32, @intCast(layout.payload_size))
4310 @intCast(layout.payload_size)
43234311 else
43244312 0;
43254313 break :blk try self.copyToRegisterWithInstTracking(inst, tag_ty, .{
......@@ -4331,13 +4319,13 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
43314319 },
43324320 .register => {
43334321 const shift: u6 = if (layout.tag_align < layout.payload_align)
4334 @as(u6, @intCast(layout.payload_size * 8))
4322 @intCast(layout.payload_size * 8)
43354323 else
43364324 0;
43374325 const result = try self.copyToRegisterWithInstTracking(inst, union_ty, operand);
43384326 try self.genShiftBinOpMir(.{ ._r, .sh }, Type.usize, result, .{ .immediate = shift });
43394327 break :blk MCValue{
4340 .register = registerAlias(result.register, @as(u32, @intCast(layout.tag_size))),
4328 .register = registerAlias(result.register, @intCast(layout.tag_size)),
43414329 };
43424330 },
43434331 else => return self.fail("TODO implement get_union_tag for {}", .{operand}),
......@@ -4447,7 +4435,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
44474435 try self.genBinOpMir(.{ ._, .xor }, dst_ty, dst_mcv, .{ .immediate = src_bits - 1 });
44484436 } else {
44494437 const imm_reg = try self.copyToTmpRegister(dst_ty, .{
4450 .immediate = @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - self.regBitSize(dst_ty))),
4438 .immediate = @as(u64, math.maxInt(u64)) >> @intCast(64 - self.regBitSize(dst_ty)),
44514439 });
44524440 const imm_lock = self.register_manager.lockRegAssumeUnused(imm_reg);
44534441 defer self.register_manager.unlockReg(imm_lock);
......@@ -4518,8 +4506,8 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
45184506 .{ ._, .@"or" },
45194507 wide_ty,
45204508 tmp_mcv,
4521 .{ .immediate = (@as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - extra_bits))) <<
4522 @as(u6, @intCast(src_bits)) },
4509 .{ .immediate = (@as(u64, math.maxInt(u64)) >> @intCast(64 - extra_bits)) <<
4510 @intCast(src_bits) },
45234511 );
45244512 break :masked tmp_mcv;
45254513 } else mat_src_mcv;
......@@ -4536,7 +4524,7 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
45364524 .{ ._, .@"or" },
45374525 Type.u64,
45384526 dst_mcv,
4539 .{ .immediate = @as(u64, math.maxInt(u64)) << @as(u6, @intCast(src_bits - 64)) },
4527 .{ .immediate = @as(u64, math.maxInt(u64)) << @intCast(src_bits - 64) },
45404528 );
45414529 break :masked dst_mcv;
45424530 } else mat_src_mcv.address().offset(8).deref();
......@@ -4607,7 +4595,7 @@ fn airPopcount(self: *Self, inst: Air.Inst.Index) !void {
46074595 break :result dst_mcv;
46084596 }
46094597
4610 const mask = @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - src_abi_size * 8));
4598 const mask = @as(u64, math.maxInt(u64)) >> @intCast(64 - src_abi_size * 8);
46114599 const imm_0_1 = Immediate.u(mask / 0b1_1);
46124600 const imm_00_11 = Immediate.u(mask / 0b01_01);
46134601 const imm_0000_1111 = Immediate.u(mask / 0b0001_0001);
......@@ -4780,7 +4768,7 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
47804768 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
47814769
47824770 const src_ty = self.typeOf(ty_op.operand);
4783 const src_abi_size = @as(u32, @intCast(src_ty.abiSize(mod)));
4771 const src_abi_size: u32 = @intCast(src_ty.abiSize(mod));
47844772 const src_mcv = try self.resolveInst(ty_op.operand);
47854773
47864774 const dst_mcv = try self.byteSwap(inst, src_ty, src_mcv, false);
......@@ -4800,7 +4788,7 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
48004788 else
48014789 undefined;
48024790
4803 const mask = @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - src_abi_size * 8));
4791 const mask = @as(u64, math.maxInt(u64)) >> @intCast(64 - src_abi_size * 8);
48044792 const imm_0000_1111 = Immediate.u(mask / 0b0001_0001);
48054793 const imm_00_11 = Immediate.u(mask / 0b01_01);
48064794 const imm_0_1 = Immediate.u(mask / 0b1_1);
......@@ -5016,7 +5004,7 @@ fn genRound(self: *Self, ty: Type, dst_reg: Register, src_mcv: MCValue, mode: u4
50165004 if (!self.hasFeature(.sse4_1))
50175005 return self.fail("TODO implement genRound without sse4_1 feature", .{});
50185006
5019 const mir_tag = if (@as(?Mir.Inst.FixedTag, switch (ty.zigTypeTag(mod)) {
5007 const mir_tag = @as(?Mir.Inst.FixedTag, switch (ty.zigTypeTag(mod)) {
50205008 .Float => switch (ty.floatBits(self.target.*)) {
50215009 32 => if (self.hasFeature(.avx)) .{ .v_ss, .round } else .{ ._ss, .round },
50225010 64 => if (self.hasFeature(.avx)) .{ .v_sd, .round } else .{ ._sd, .round },
......@@ -5043,10 +5031,10 @@ fn genRound(self: *Self, ty: Type, dst_reg: Register, src_mcv: MCValue, mode: u4
50435031 else => null,
50445032 },
50455033 else => unreachable,
5046 })) |tag| tag else return self.fail("TODO implement genRound for {}", .{
5034 }) orelse return self.fail("TODO implement genRound for {}", .{
50475035 ty.fmt(self.bin_file.options.module.?),
50485036 });
5049 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
5037 const abi_size: u32 = @intCast(ty.abiSize(mod));
50505038 const dst_alias = registerAlias(dst_reg, abi_size);
50515039 switch (mir_tag[0]) {
50525040 .v_ss, .v_sd => if (src_mcv.isMemory()) try self.asmRegisterRegisterMemoryImmediate(
......@@ -5086,7 +5074,7 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
50865074 const mod = self.bin_file.options.module.?;
50875075 const un_op = self.air.instructions.items(.data)[inst].un_op;
50885076 const ty = self.typeOf(un_op);
5089 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
5077 const abi_size: u32 = @intCast(ty.abiSize(mod));
50905078
50915079 const src_mcv = try self.resolveInst(un_op);
50925080 const dst_mcv = if (src_mcv.isRegister() and self.reuseOperand(inst, un_op, 0, src_mcv))
......@@ -5098,7 +5086,7 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
50985086 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
50995087
51005088 const result: MCValue = result: {
5101 const mir_tag = if (@as(?Mir.Inst.FixedTag, switch (ty.zigTypeTag(mod)) {
5089 const mir_tag = @as(?Mir.Inst.FixedTag, switch (ty.zigTypeTag(mod)) {
51025090 .Float => switch (ty.floatBits(self.target.*)) {
51035091 16 => if (self.hasFeature(.f16c)) {
51045092 const mat_src_reg = if (src_mcv.isRegister())
......@@ -5152,7 +5140,7 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
51525140 .{ .v_ps, .cvtph2 },
51535141 wide_reg,
51545142 src_mcv.mem(Memory.PtrSize.fromSize(
5155 @as(u32, @intCast(@divExact(wide_reg.bitSize(), 16))),
5143 @intCast(@divExact(wide_reg.bitSize(), 16)),
51565144 )),
51575145 ) else try self.asmRegisterRegister(
51585146 .{ .v_ps, .cvtph2 },
......@@ -5191,7 +5179,7 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
51915179 else => unreachable,
51925180 },
51935181 else => unreachable,
5194 })) |tag| tag else return self.fail("TODO implement airSqrt for {}", .{
5182 }) orelse return self.fail("TODO implement airSqrt for {}", .{
51955183 ty.fmt(mod),
51965184 });
51975185 switch (mir_tag[0]) {
......@@ -5284,10 +5272,10 @@ fn packedLoad(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) Inn
52845272 const ptr_info = ptr_ty.ptrInfo(mod);
52855273
52865274 const val_ty = ptr_info.child.toType();
5287 const val_abi_size = @as(u32, @intCast(val_ty.abiSize(mod)));
5275 const val_abi_size: u32 = @intCast(val_ty.abiSize(mod));
52885276 const limb_abi_size: u32 = @min(val_abi_size, 8);
52895277 const limb_abi_bits = limb_abi_size * 8;
5290 const val_byte_off = @as(i32, @intCast(ptr_info.packed_offset.bit_offset / limb_abi_bits * limb_abi_size));
5278 const val_byte_off: i32 = @intCast(ptr_info.packed_offset.bit_offset / limb_abi_bits * limb_abi_size);
52915279 const val_bit_off = ptr_info.packed_offset.bit_offset % limb_abi_bits;
52925280 const val_extra_bits = self.regExtraBits(val_ty);
52935281
......@@ -5434,7 +5422,7 @@ fn packedStore(self: *Self, ptr_ty: Type, ptr_mcv: MCValue, src_mcv: MCValue) In
54345422 const limb_ty = try mod.intType(.unsigned, limb_abi_bits);
54355423
54365424 const src_bit_size = src_ty.bitSize(mod);
5437 const src_byte_off = @as(i32, @intCast(ptr_info.packed_offset.bit_offset / limb_abi_bits * limb_abi_size));
5425 const src_byte_off: i32 = @intCast(ptr_info.packed_offset.bit_offset / limb_abi_bits * limb_abi_size);
54385426 const src_bit_off = ptr_info.packed_offset.bit_offset % limb_abi_bits;
54395427
54405428 const ptr_reg = try self.copyToTmpRegister(ptr_ty, ptr_mcv);
......@@ -5451,10 +5439,9 @@ fn packedStore(self: *Self, ptr_ty: Type, ptr_mcv: MCValue, src_mcv: MCValue) In
54515439 .disp = src_byte_off + limb_i * limb_abi_bits,
54525440 });
54535441
5454 const part_mask = (@as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - part_bit_size))) <<
5455 @as(u6, @intCast(part_bit_off));
5456 const part_mask_not = part_mask ^
5457 (@as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - limb_abi_bits)));
5442 const part_mask = (@as(u64, math.maxInt(u64)) >> @intCast(64 - part_bit_size)) <<
5443 @intCast(part_bit_off);
5444 const part_mask_not = part_mask ^ (@as(u64, math.maxInt(u64)) >> @intCast(64 - limb_abi_bits));
54585445 if (limb_abi_size <= 4) {
54595446 try self.asmMemoryImmediate(.{ ._, .@"and" }, limb_mem, Immediate.u(part_mask_not));
54605447 } else if (math.cast(i32, @as(i64, @bitCast(part_mask_not)))) |small| {
......@@ -5572,14 +5559,14 @@ fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32
55725559 const ptr_field_ty = self.typeOfIndex(inst);
55735560 const ptr_container_ty = self.typeOf(operand);
55745561 const container_ty = ptr_container_ty.childType(mod);
5575 const field_offset = @as(i32, @intCast(switch (container_ty.containerLayout(mod)) {
5562 const field_offset: i32 = @intCast(switch (container_ty.containerLayout(mod)) {
55765563 .Auto, .Extern => container_ty.structFieldOffset(index, mod),
55775564 .Packed => if (container_ty.zigTypeTag(mod) == .Struct and
55785565 ptr_field_ty.ptrInfo(mod).packed_offset.host_size == 0)
55795566 container_ty.packedStructFieldByteOffset(index, mod)
55805567 else
55815568 0,
5582 }));
5569 });
55835570
55845571 const src_mcv = try self.resolveInst(operand);
55855572 const dst_mcv = if (switch (src_mcv) {
......@@ -5606,8 +5593,8 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
56065593 const field_is_gp = field_rc.supersetOf(gp);
56075594
56085595 const src_mcv = try self.resolveInst(operand);
5609 const field_off = switch (container_ty.containerLayout(mod)) {
5610 .Auto, .Extern => @as(u32, @intCast(container_ty.structFieldOffset(index, mod) * 8)),
5596 const field_off: u32 = switch (container_ty.containerLayout(mod)) {
5597 .Auto, .Extern => @intCast(container_ty.structFieldOffset(index, mod) * 8),
56115598 .Packed => if (mod.typeToStruct(container_ty)) |struct_obj|
56125599 struct_obj.packedFieldBitOffset(mod, index)
56135600 else
......@@ -5650,7 +5637,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
56505637
56515638 const limb_abi_size: u32 = @min(field_abi_size, 8);
56525639 const limb_abi_bits = limb_abi_size * 8;
5653 const field_byte_off = @as(i32, @intCast(field_off / limb_abi_bits * limb_abi_size));
5640 const field_byte_off: i32 = @intCast(field_off / limb_abi_bits * limb_abi_size);
56545641 const field_bit_off = field_off % limb_abi_bits;
56555642
56565643 if (field_abi_size > 8) {
......@@ -5775,7 +5762,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
57755762
57765763 const inst_ty = self.typeOfIndex(inst);
57775764 const parent_ty = inst_ty.childType(mod);
5778 const field_offset = @as(i32, @intCast(parent_ty.structFieldOffset(extra.field_index, mod)));
5765 const field_offset: i32 = @intCast(parent_ty.structFieldOffset(extra.field_index, mod));
57795766
57805767 const src_mcv = try self.resolveInst(extra.field_ptr);
57815768 const dst_mcv = if (src_mcv.isRegisterOffset() and
......@@ -5824,14 +5811,14 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:
58245811
58255812 switch (tag) {
58265813 .not => {
5827 const limb_abi_size = @as(u16, @intCast(@min(src_ty.abiSize(mod), 8)));
5814 const limb_abi_size: u16 = @intCast(@min(src_ty.abiSize(mod), 8));
58285815 const int_info = if (src_ty.ip_index == .bool_type)
58295816 std.builtin.Type.Int{ .signedness = .unsigned, .bits = 1 }
58305817 else
58315818 src_ty.intInfo(mod);
58325819 var byte_off: i32 = 0;
58335820 while (byte_off * 8 < int_info.bits) : (byte_off += limb_abi_size) {
5834 const limb_bits = @as(u16, @intCast(@min(int_info.bits - byte_off * 8, limb_abi_size * 8)));
5821 const limb_bits: u16 = @intCast(@min(int_info.bits - byte_off * 8, limb_abi_size * 8));
58355822 const limb_ty = try mod.intType(int_info.signedness, limb_bits);
58365823 const limb_mcv = switch (byte_off) {
58375824 0 => dst_mcv,
......@@ -5839,7 +5826,7 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:
58395826 };
58405827
58415828 if (int_info.signedness == .unsigned and self.regExtraBits(limb_ty) > 0) {
5842 const mask = @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(64 - limb_bits));
5829 const mask = @as(u64, math.maxInt(u64)) >> @intCast(64 - limb_bits);
58435830 try self.genBinOpMir(.{ ._, .xor }, limb_ty, limb_mcv, .{ .immediate = mask });
58445831 } else try self.genUnOpMir(.{ ._, .not }, limb_ty, limb_mcv);
58455832 }
......@@ -5852,7 +5839,7 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:
58525839
58535840fn genUnOpMir(self: *Self, mir_tag: Mir.Inst.FixedTag, dst_ty: Type, dst_mcv: MCValue) !void {
58545841 const mod = self.bin_file.options.module.?;
5855 const abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
5842 const abi_size: u32 = @intCast(dst_ty.abiSize(mod));
58565843 if (abi_size > 8) return self.fail("TODO implement {} for {}", .{
58575844 mir_tag,
58585845 dst_ty.fmt(self.bin_file.options.module.?),
......@@ -5914,7 +5901,7 @@ fn genShiftBinOpMir(
59145901 break :rhs .{ .register = .rcx };
59155902 };
59165903
5917 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
5904 const abi_size: u32 = @intCast(ty.abiSize(mod));
59185905 if (abi_size <= 8) {
59195906 switch (lhs_mcv) {
59205907 .register => |lhs_reg| switch (rhs_mcv) {
......@@ -6602,7 +6589,7 @@ fn genBinOp(
66026589 Memory.sib(Memory.PtrSize.fromSize(cmov_abi_size), switch (mat_src_mcv) {
66036590 .memory => |addr| .{
66046591 .base = .{ .reg = .ds },
6605 .disp = @as(i32, @intCast(@as(i64, @bitCast(addr)))),
6592 .disp = @intCast(@as(i64, @bitCast(addr))),
66066593 },
66076594 .indirect => |reg_off| .{
66086595 .base = .{ .reg = reg_off.reg },
......@@ -6628,7 +6615,7 @@ fn genBinOp(
66286615 }
66296616
66306617 const dst_reg = registerAlias(dst_mcv.getReg().?, abi_size);
6631 const mir_tag = if (@as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
6618 const mir_tag = @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
66326619 else => unreachable,
66336620 .Float => switch (lhs_ty.floatBits(self.target.*)) {
66346621 16 => if (self.hasFeature(.f16c)) {
......@@ -7190,7 +7177,7 @@ fn genBinOp(
71907177 else => unreachable,
71917178 },
71927179 },
7193 })) |tag| tag else return self.fail("TODO implement genBinOp for {s} {}", .{
7180 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{
71947181 @tagName(air_tag), lhs_ty.fmt(self.bin_file.options.module.?),
71957182 });
71967183
......@@ -7253,7 +7240,7 @@ fn genBinOp(
72537240 const rhs_copy_reg = registerAlias(src_mcv.getReg().?, abi_size);
72547241
72557242 try self.asmRegisterRegisterRegisterImmediate(
7256 if (@as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
7243 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
72577244 .Float => switch (lhs_ty.floatBits(self.target.*)) {
72587245 32 => .{ .v_ss, .cmp },
72597246 64 => .{ .v_sd, .cmp },
......@@ -7278,7 +7265,7 @@ fn genBinOp(
72787265 else => unreachable,
72797266 },
72807267 else => unreachable,
7281 })) |tag| tag else return self.fail("TODO implement genBinOp for {s} {}", .{
7268 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{
72827269 @tagName(air_tag), lhs_ty.fmt(self.bin_file.options.module.?),
72837270 }),
72847271 mask_reg,
......@@ -7287,7 +7274,7 @@ fn genBinOp(
72877274 Immediate.u(3), // unord
72887275 );
72897276 try self.asmRegisterRegisterRegisterRegister(
7290 if (@as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
7277 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
72917278 .Float => switch (lhs_ty.floatBits(self.target.*)) {
72927279 32 => .{ .v_ps, .blendv },
72937280 64 => .{ .v_pd, .blendv },
......@@ -7310,7 +7297,7 @@ fn genBinOp(
73107297 else => unreachable,
73117298 },
73127299 else => unreachable,
7313 })) |tag| tag else return self.fail("TODO implement genBinOp for {s} {}", .{
7300 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{
73147301 @tagName(air_tag), lhs_ty.fmt(self.bin_file.options.module.?),
73157302 }),
73167303 dst_reg,
......@@ -7321,7 +7308,7 @@ fn genBinOp(
73217308 } else {
73227309 const has_blend = self.hasFeature(.sse4_1);
73237310 try self.asmRegisterRegisterImmediate(
7324 if (@as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
7311 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
73257312 .Float => switch (lhs_ty.floatBits(self.target.*)) {
73267313 32 => .{ ._ss, .cmp },
73277314 64 => .{ ._sd, .cmp },
......@@ -7346,7 +7333,7 @@ fn genBinOp(
73467333 else => unreachable,
73477334 },
73487335 else => unreachable,
7349 })) |tag| tag else return self.fail("TODO implement genBinOp for {s} {}", .{
7336 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{
73507337 @tagName(air_tag), lhs_ty.fmt(self.bin_file.options.module.?),
73517338 }),
73527339 mask_reg,
......@@ -7354,7 +7341,7 @@ fn genBinOp(
73547341 Immediate.u(if (has_blend) 3 else 7), // unord, ord
73557342 );
73567343 if (has_blend) try self.asmRegisterRegisterRegister(
7357 if (@as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
7344 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
73587345 .Float => switch (lhs_ty.floatBits(self.target.*)) {
73597346 32 => .{ ._ps, .blendv },
73607347 64 => .{ ._pd, .blendv },
......@@ -7377,7 +7364,7 @@ fn genBinOp(
73777364 else => unreachable,
73787365 },
73797366 else => unreachable,
7380 })) |tag| tag else return self.fail("TODO implement genBinOp for {s} {}", .{
7367 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{
73817368 @tagName(air_tag), lhs_ty.fmt(self.bin_file.options.module.?),
73827369 }),
73837370 dst_reg,
......@@ -7385,7 +7372,7 @@ fn genBinOp(
73857372 mask_reg,
73867373 ) else {
73877374 try self.asmRegisterRegister(
7388 if (@as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
7375 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
73897376 .Float => switch (lhs_ty.floatBits(self.target.*)) {
73907377 32 => .{ ._ps, .@"and" },
73917378 64 => .{ ._pd, .@"and" },
......@@ -7408,14 +7395,14 @@ fn genBinOp(
74087395 else => unreachable,
74097396 },
74107397 else => unreachable,
7411 })) |tag| tag else return self.fail("TODO implement genBinOp for {s} {}", .{
7398 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{
74127399 @tagName(air_tag), lhs_ty.fmt(self.bin_file.options.module.?),
74137400 }),
74147401 dst_reg,
74157402 mask_reg,
74167403 );
74177404 try self.asmRegisterRegister(
7418 if (@as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
7405 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
74197406 .Float => switch (lhs_ty.floatBits(self.target.*)) {
74207407 32 => .{ ._ps, .andn },
74217408 64 => .{ ._pd, .andn },
......@@ -7438,14 +7425,14 @@ fn genBinOp(
74387425 else => unreachable,
74397426 },
74407427 else => unreachable,
7441 })) |tag| tag else return self.fail("TODO implement genBinOp for {s} {}", .{
7428 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{
74427429 @tagName(air_tag), lhs_ty.fmt(self.bin_file.options.module.?),
74437430 }),
74447431 mask_reg,
74457432 lhs_copy_reg.?,
74467433 );
74477434 try self.asmRegisterRegister(
7448 if (@as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
7435 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
74497436 .Float => switch (lhs_ty.floatBits(self.target.*)) {
74507437 32 => .{ ._ps, .@"or" },
74517438 64 => .{ ._pd, .@"or" },
......@@ -7468,7 +7455,7 @@ fn genBinOp(
74687455 else => unreachable,
74697456 },
74707457 else => unreachable,
7471 })) |tag| tag else return self.fail("TODO implement genBinOp for {s} {}", .{
7458 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{
74727459 @tagName(air_tag), lhs_ty.fmt(self.bin_file.options.module.?),
74737460 }),
74747461 dst_reg,
......@@ -7490,7 +7477,7 @@ fn genBinOpMir(
74907477 src_mcv: MCValue,
74917478) !void {
74927479 const mod = self.bin_file.options.module.?;
7493 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
7480 const abi_size: u32 = @intCast(ty.abiSize(mod));
74947481 switch (dst_mcv) {
74957482 .none,
74967483 .unreach,
......@@ -7738,10 +7725,10 @@ fn genBinOpMir(
77387725 else => unreachable,
77397726 },
77407727 .immediate => |src_imm| {
7741 const imm = switch (off) {
7728 const imm: u64 = switch (off) {
77427729 0 => src_imm,
77437730 else => switch (ty_signedness) {
7744 .signed => @as(u64, @bitCast(@as(i64, @bitCast(src_imm)) >> 63)),
7731 .signed => @bitCast(@as(i64, @bitCast(src_imm)) >> 63),
77457732 .unsigned => 0,
77467733 },
77477734 };
......@@ -7814,7 +7801,7 @@ fn genBinOpMir(
78147801 0 => src_mcv,
78157802 else => .{ .immediate = 0 },
78167803 },
7817 .memory => |addr| .{ .memory = @as(u64, @bitCast(@as(i64, @bitCast(addr)) + off)) },
7804 .memory => |addr| .{ .memory = @bitCast(@as(i64, @bitCast(addr)) + off) },
78187805 .indirect => |reg_off| .{ .indirect = .{
78197806 .reg = reg_off.reg,
78207807 .off = reg_off.off + off,
......@@ -7841,7 +7828,7 @@ fn genBinOpMir(
78417828/// Does not support byte-size operands.
78427829fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError!void {
78437830 const mod = self.bin_file.options.module.?;
7844 const abi_size = @as(u32, @intCast(dst_ty.abiSize(mod)));
7831 const abi_size: u32 = @intCast(dst_ty.abiSize(mod));
78457832 switch (dst_mcv) {
78467833 .none,
78477834 .unreach,
......@@ -8075,7 +8062,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
80758062 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
80768063 const callee = pl_op.operand;
80778064 const extra = self.air.extraData(Air.Call, pl_op.payload);
8078 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));
8065 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);
80798066 const ty = self.typeOf(callee);
80808067
80818068 const fn_ty = switch (ty.zigTypeTag(mod)) {
......@@ -8168,7 +8155,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
81688155 const got_addr = atom.getOffsetTableAddress(elf_file);
81698156 try self.asmMemory(.{ ._, .call }, Memory.sib(.qword, .{
81708157 .base = .{ .reg = .ds },
8171 .disp = @as(i32, @intCast(got_addr)),
8158 .disp = @intCast(got_addr),
81728159 }));
81738160 } else if (self.bin_file.cast(link.File.Coff)) |coff_file| {
81748161 const atom = try coff_file.getOrCreateAtomForDecl(owner_decl);
......@@ -8185,7 +8172,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
81858172 const atom = p9.getAtom(atom_index);
81868173 try self.asmMemory(.{ ._, .call }, Memory.sib(.qword, .{
81878174 .base = .{ .reg = .ds },
8188 .disp = @as(i32, @intCast(atom.getOffsetTableAddress(p9))),
8175 .disp = @intCast(atom.getOffsetTableAddress(p9)),
81898176 }));
81908177 } else unreachable;
81918178 } else if (func_value.getExternFunc(mod)) |extern_func| {
......@@ -8305,7 +8292,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
83058292 const result = MCValue{
83068293 .eflags = switch (ty.zigTypeTag(mod)) {
83078294 else => result: {
8308 const abi_size = @as(u16, @intCast(ty.abiSize(mod)));
8295 const abi_size: u16 = @intCast(ty.abiSize(mod));
83098296 const may_flip: enum {
83108297 may_flip,
83118298 must_flip,
......@@ -8502,7 +8489,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
85028489 self.eflags_inst = inst;
85038490
85048491 const op_ty = self.typeOf(un_op);
8505 const op_abi_size = @as(u32, @intCast(op_ty.abiSize(mod)));
8492 const op_abi_size: u32 = @intCast(op_ty.abiSize(mod));
85068493 const op_mcv = try self.resolveInst(un_op);
85078494 const dst_reg = switch (op_mcv) {
85088495 .register => |reg| reg,
......@@ -8711,7 +8698,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
87118698 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))
87128699 .{ .off = 0, .ty = if (pl_ty.isSlice(mod)) pl_ty.slicePtrFieldType(mod) else pl_ty }
87138700 else
8714 .{ .off = @as(i32, @intCast(pl_ty.abiSize(mod))), .ty = Type.bool };
8701 .{ .off = @intCast(pl_ty.abiSize(mod)), .ty = Type.bool };
87158702
87168703 switch (opt_mcv) {
87178704 .none,
......@@ -8731,14 +8718,14 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
87318718
87328719 .register => |opt_reg| {
87338720 if (some_info.off == 0) {
8734 const some_abi_size = @as(u32, @intCast(some_info.ty.abiSize(mod)));
8721 const some_abi_size: u32 = @intCast(some_info.ty.abiSize(mod));
87358722 const alias_reg = registerAlias(opt_reg, some_abi_size);
87368723 assert(some_abi_size * 8 == alias_reg.bitSize());
87378724 try self.asmRegisterRegister(.{ ._, .@"test" }, alias_reg, alias_reg);
87388725 return .{ .eflags = .z };
87398726 }
87408727 assert(some_info.ty.ip_index == .bool_type);
8741 const opt_abi_size = @as(u32, @intCast(opt_ty.abiSize(mod)));
8728 const opt_abi_size: u32 = @intCast(opt_ty.abiSize(mod));
87428729 try self.asmRegisterImmediate(
87438730 .{ ._, .bt },
87448731 registerAlias(opt_reg, opt_abi_size),
......@@ -8757,7 +8744,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
87578744 defer self.register_manager.unlockReg(addr_reg_lock);
87588745
87598746 try self.genSetReg(addr_reg, Type.usize, opt_mcv.address());
8760 const some_abi_size = @as(u32, @intCast(some_info.ty.abiSize(mod)));
8747 const some_abi_size: u32 = @intCast(some_info.ty.abiSize(mod));
87618748 try self.asmMemoryImmediate(
87628749 .{ ._, .cmp },
87638750 Memory.sib(Memory.PtrSize.fromSize(some_abi_size), .{
......@@ -8770,7 +8757,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
87708757 },
87718758
87728759 .indirect, .load_frame => {
8773 const some_abi_size = @as(u32, @intCast(some_info.ty.abiSize(mod)));
8760 const some_abi_size: u32 = @intCast(some_info.ty.abiSize(mod));
87748761 try self.asmMemoryImmediate(
87758762 .{ ._, .cmp },
87768763 Memory.sib(Memory.PtrSize.fromSize(some_abi_size), switch (opt_mcv) {
......@@ -8802,7 +8789,7 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue)
88028789 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))
88038790 .{ .off = 0, .ty = if (pl_ty.isSlice(mod)) pl_ty.slicePtrFieldType(mod) else pl_ty }
88048791 else
8805 .{ .off = @as(i32, @intCast(pl_ty.abiSize(mod))), .ty = Type.bool };
8792 .{ .off = @intCast(pl_ty.abiSize(mod)), .ty = Type.bool };
88068793
88078794 const ptr_reg = switch (ptr_mcv) {
88088795 .register => |reg| reg,
......@@ -8811,7 +8798,7 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue)
88118798 const ptr_lock = self.register_manager.lockReg(ptr_reg);
88128799 defer if (ptr_lock) |lock| self.register_manager.unlockReg(lock);
88138800
8814 const some_abi_size = @as(u32, @intCast(some_info.ty.abiSize(mod)));
8801 const some_abi_size: u32 = @intCast(some_info.ty.abiSize(mod));
88158802 try self.asmMemoryImmediate(
88168803 .{ ._, .cmp },
88178804 Memory.sib(Memory.PtrSize.fromSize(some_abi_size), .{
......@@ -8844,12 +8831,11 @@ fn isErr(self: *Self, maybe_inst: ?Air.Inst.Index, ty: Type, operand: MCValue) !
88448831
88458832 const tmp_reg = try self.copyToTmpRegister(ty, operand);
88468833 if (err_off > 0) {
8847 const shift = @as(u6, @intCast(err_off * 8));
88488834 try self.genShiftBinOpMir(
88498835 .{ ._r, .sh },
88508836 ty,
88518837 .{ .register = tmp_reg },
8852 .{ .immediate = shift },
8838 .{ .immediate = @as(u6, @intCast(err_off * 8)) },
88538839 );
88548840 } else {
88558841 try self.truncateRegister(Type.anyerror, tmp_reg);
......@@ -9004,7 +8990,7 @@ fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
90048990 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
90058991 const loop = self.air.extraData(Air.Block, ty_pl.payload);
90068992 const body = self.air.extra[loop.end..][0..loop.data.body_len];
9007 const jmp_target = @as(u32, @intCast(self.mir_instructions.len));
8993 const jmp_target: u32 = @intCast(self.mir_instructions.len);
90088994
90098995 self.scope_generation += 1;
90108996 const state = try self.saveState();
......@@ -9076,10 +9062,8 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {
90769062
90779063 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
90789064 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
9079 const items = @as(
9080 []const Air.Inst.Ref,
9081 @ptrCast(self.air.extra[case.end..][0..case.data.items_len]),
9082 );
9065 const items: []const Air.Inst.Ref =
9066 @ptrCast(self.air.extra[case.end..][0..case.data.items_len]);
90839067 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
90849068 extra_index = case.end + items.len + case_body.len;
90859069
......@@ -9127,7 +9111,7 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {
91279111}
91289112
91299113fn performReloc(self: *Self, reloc: Mir.Inst.Index) !void {
9130 const next_inst = @as(u32, @intCast(self.mir_instructions.len));
9114 const next_inst: u32 = @intCast(self.mir_instructions.len);
91319115 switch (self.mir_instructions.items(.tag)[reloc]) {
91329116 .j, .jmp => {},
91339117 .pseudo => switch (self.mir_instructions.items(.ops)[reloc]) {
......@@ -9202,11 +9186,12 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {
92029186fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
92039187 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
92049188 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
9205 const clobbers_len = @as(u31, @truncate(extra.data.flags));
9189 const clobbers_len: u31 = @truncate(extra.data.flags);
92069190 var extra_i: usize = extra.end;
9207 const outputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]));
9191 const outputs: []const Air.Inst.Ref =
9192 @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]);
92089193 extra_i += outputs.len;
9209 const inputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]));
9194 const inputs: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]);
92109195 extra_i += inputs.len;
92119196
92129197 var result: MCValue = .none;
......@@ -9341,16 +9326,14 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
93419326 } else if (mem.startsWith(u8, op_str, "$")) {
93429327 if (std.fmt.parseInt(i32, op_str["$".len..], 0)) |s| {
93439328 if (mnem_size) |size| {
9344 const max = @as(u64, math.maxInt(u64)) >>
9345 @as(u6, @intCast(64 - (size.bitSize() - 1)));
9329 const max = @as(u64, math.maxInt(u64)) >> @intCast(64 - (size.bitSize() - 1));
93469330 if ((if (s < 0) ~s else s) > max)
93479331 return self.fail("Invalid immediate size: '{s}'", .{op_str});
93489332 }
93499333 op.* = .{ .imm = Immediate.s(s) };
93509334 } else |_| if (std.fmt.parseInt(u64, op_str["$".len..], 0)) |u| {
93519335 if (mnem_size) |size| {
9352 const max = @as(u64, math.maxInt(u64)) >>
9353 @as(u6, @intCast(64 - size.bitSize()));
9336 const max = @as(u64, math.maxInt(u64)) >> @intCast(64 - size.bitSize());
93549337 if (u > max)
93559338 return self.fail("Invalid immediate size: '{s}'", .{op_str});
93569339 }
......@@ -9702,7 +9685,7 @@ fn genCopy(self: *Self, ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError
97029685
97039686fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerError!void {
97049687 const mod = self.bin_file.options.module.?;
9705 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
9688 const abi_size: u32 = @intCast(ty.abiSize(mod));
97069689 if (abi_size * 8 > dst_reg.bitSize())
97079690 return self.fail("genSetReg called with a value larger than dst_reg", .{});
97089691 switch (src_mcv) {
......@@ -9727,7 +9710,7 @@ fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerEr
97279710 try self.asmRegisterImmediate(
97289711 .{ ._, .mov },
97299712 registerAlias(dst_reg, abi_size),
9730 Immediate.s(@as(i32, @intCast(@as(i64, @bitCast(imm))))),
9713 Immediate.s(@intCast(@as(i64, @bitCast(imm)))),
97319714 );
97329715 } else {
97339716 try self.asmRegisterImmediate(
......@@ -9785,7 +9768,7 @@ fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerEr
97859768 .{ .register = try self.copyToTmpRegister(ty, src_mcv) },
97869769 ),
97879770 .sse => try self.asmRegisterRegister(
9788 if (@as(?Mir.Inst.FixedTag, switch (ty.scalarType(mod).zigTypeTag(mod)) {
9771 @as(?Mir.Inst.FixedTag, switch (ty.scalarType(mod).zigTypeTag(mod)) {
97899772 else => switch (abi_size) {
97909773 1...4 => if (self.hasFeature(.avx)) .{ .v_d, .mov } else .{ ._d, .mov },
97919774 5...8 => if (self.hasFeature(.avx)) .{ .v_q, .mov } else .{ ._q, .mov },
......@@ -9809,7 +9792,7 @@ fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerEr
98099792 80 => null,
98109793 else => unreachable,
98119794 },
9812 })) |tag| tag else return self.fail("TODO implement genSetReg for {}", .{
9795 }) orelse return self.fail("TODO implement genSetReg for {}", .{
98139796 ty.fmt(self.bin_file.options.module.?),
98149797 }),
98159798 registerAlias(dst_reg, abi_size),
......@@ -9989,9 +9972,9 @@ fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerEr
99899972
99909973fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCValue) InnerError!void {
99919974 const mod = self.bin_file.options.module.?;
9992 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
9975 const abi_size: u32 = @intCast(ty.abiSize(mod));
99939976 const dst_ptr_mcv: MCValue = switch (base) {
9994 .none => .{ .immediate = @as(u64, @bitCast(@as(i64, disp))) },
9977 .none => .{ .immediate = @bitCast(@as(i64, disp)) },
99959978 .reg => |base_reg| .{ .register_offset = .{ .reg = base_reg, .off = disp } },
99969979 .frame => |base_frame_index| .{ .lea_frame = .{ .index = base_frame_index, .off = disp } },
99979980 };
......@@ -10002,7 +9985,7 @@ fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCVal
100029985 .immediate => |imm| switch (abi_size) {
100039986 1, 2, 4 => {
100049987 const immediate = if (ty.isSignedInt(mod))
10005 Immediate.s(@as(i32, @truncate(@as(i64, @bitCast(imm)))))
9988 Immediate.s(@truncate(@as(i64, @bitCast(imm))))
100069989 else
100079990 Immediate.u(@as(u32, @intCast(imm)));
100089991 try self.asmMemoryImmediate(
......@@ -10024,10 +10007,9 @@ fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCVal
1002410007 .{ ._, .mov },
1002510008 Memory.sib(.dword, .{ .base = base, .disp = disp + offset }),
1002610009 if (ty.isSignedInt(mod))
10027 Immediate.s(@as(
10028 i32,
10010 Immediate.s(
1002910011 @truncate(@as(i64, @bitCast(imm)) >> (math.cast(u6, offset * 8) orelse 63)),
10030 ))
10012 )
1003110013 else
1003210014 Immediate.u(@as(
1003310015 u32,
......@@ -10138,7 +10120,7 @@ fn genLazySymbolRef(
1013810120 _ = try atom.getOrCreateOffsetTableEntry(elf_file);
1013910121 const got_addr = atom.getOffsetTableAddress(elf_file);
1014010122 const got_mem =
10141 Memory.sib(.qword, .{ .base = .{ .reg = .ds }, .disp = @as(i32, @intCast(got_addr)) });
10123 Memory.sib(.qword, .{ .base = .{ .reg = .ds }, .disp = @intCast(got_addr) });
1014210124 switch (tag) {
1014310125 .lea, .mov => try self.asmRegisterMemory(.{ ._, .mov }, reg.to64(), got_mem),
1014410126 .call => try self.asmMemory(.{ ._, .call }, got_mem),
......@@ -10160,7 +10142,7 @@ fn genLazySymbolRef(
1016010142 _ = atom.getOrCreateOffsetTableEntry(p9_file);
1016110143 const got_addr = atom.getOffsetTableAddress(p9_file);
1016210144 const got_mem =
10163 Memory.sib(.qword, .{ .base = .{ .reg = .ds }, .disp = @as(i32, @intCast(got_addr)) });
10145 Memory.sib(.qword, .{ .base = .{ .reg = .ds }, .disp = @intCast(got_addr) });
1016410146 switch (tag) {
1016510147 .lea, .mov => try self.asmRegisterMemory(.{ ._, .mov }, reg.to64(), got_mem),
1016610148 .call => try self.asmMemory(.{ ._, .call }, got_mem),
......@@ -10256,8 +10238,8 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
1025610238 if (src_ty.isAbiInt(mod)) src_ty.intInfo(mod).signedness else .unsigned;
1025710239 if (dst_signedness == src_signedness) break :result dst_mcv;
1025810240
10259 const abi_size = @as(u16, @intCast(dst_ty.abiSize(mod)));
10260 const bit_size = @as(u16, @intCast(dst_ty.bitSize(mod)));
10241 const abi_size: u16 = @intCast(dst_ty.abiSize(mod));
10242 const bit_size: u16 = @intCast(dst_ty.bitSize(mod));
1026110243 if (abi_size * 8 <= bit_size) break :result dst_mcv;
1026210244
1026310245 const dst_limbs_len = math.divCeil(i32, bit_size, 64) catch unreachable;
......@@ -10298,7 +10280,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
1029810280 try self.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr);
1029910281 try self.genSetMem(
1030010282 .{ .frame = frame_index },
10301 @as(i32, @intCast(ptr_ty.abiSize(mod))),
10283 @intCast(ptr_ty.abiSize(mod)),
1030210284 Type.usize,
1030310285 .{ .immediate = array_len },
1030410286 );
......@@ -10312,7 +10294,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
1031210294 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1031310295
1031410296 const src_ty = self.typeOf(ty_op.operand);
10315 const src_bits = @as(u32, @intCast(src_ty.bitSize(mod)));
10297 const src_bits: u32 = @intCast(src_ty.bitSize(mod));
1031610298 const src_signedness =
1031710299 if (src_ty.isAbiInt(mod)) src_ty.intInfo(mod).signedness else .unsigned;
1031810300 const dst_ty = self.typeOfIndex(inst);
......@@ -10340,7 +10322,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
1034010322 const dst_lock = self.register_manager.lockRegAssumeUnused(dst_reg);
1034110323 defer self.register_manager.unlockReg(dst_lock);
1034210324
10343 const mir_tag = if (@as(?Mir.Inst.FixedTag, switch (dst_ty.zigTypeTag(mod)) {
10325 const mir_tag = @as(?Mir.Inst.FixedTag, switch (dst_ty.zigTypeTag(mod)) {
1034410326 .Float => switch (dst_ty.floatBits(self.target.*)) {
1034510327 32 => if (self.hasFeature(.avx)) .{ .v_ss, .cvtsi2 } else .{ ._ss, .cvtsi2 },
1034610328 64 => if (self.hasFeature(.avx)) .{ .v_sd, .cvtsi2 } else .{ ._sd, .cvtsi2 },
......@@ -10348,7 +10330,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
1034810330 else => unreachable,
1034910331 },
1035010332 else => null,
10351 })) |tag| tag else return self.fail("TODO implement airFloatFromInt from {} to {}", .{
10333 }) orelse return self.fail("TODO implement airFloatFromInt from {} to {}", .{
1035210334 src_ty.fmt(mod), dst_ty.fmt(mod),
1035310335 });
1035410336 const dst_alias = dst_reg.to128();
......@@ -10367,7 +10349,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
1036710349
1036810350 const src_ty = self.typeOf(ty_op.operand);
1036910351 const dst_ty = self.typeOfIndex(inst);
10370 const dst_bits = @as(u32, @intCast(dst_ty.bitSize(mod)));
10352 const dst_bits: u32 = @intCast(dst_ty.bitSize(mod));
1037110353 const dst_signedness =
1037210354 if (dst_ty.isAbiInt(mod)) dst_ty.intInfo(mod).signedness else .unsigned;
1037310355
......@@ -10393,7 +10375,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
1039310375 defer self.register_manager.unlockReg(dst_lock);
1039410376
1039510377 try self.asmRegisterRegister(
10396 if (@as(?Mir.Inst.FixedTag, switch (src_ty.zigTypeTag(mod)) {
10378 @as(?Mir.Inst.FixedTag, switch (src_ty.zigTypeTag(mod)) {
1039710379 .Float => switch (src_ty.floatBits(self.target.*)) {
1039810380 32 => if (self.hasFeature(.avx)) .{ .v_, .cvttss2si } else .{ ._, .cvttss2si },
1039910381 64 => if (self.hasFeature(.avx)) .{ .v_, .cvttsd2si } else .{ ._, .cvttsd2si },
......@@ -10401,7 +10383,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
1040110383 else => unreachable,
1040210384 },
1040310385 else => null,
10404 })) |tag| tag else return self.fail("TODO implement airIntFromFloat from {} to {}", .{
10386 }) orelse return self.fail("TODO implement airIntFromFloat from {} to {}", .{
1040510387 src_ty.fmt(self.bin_file.options.module.?), dst_ty.fmt(self.bin_file.options.module.?),
1040610388 }),
1040710389 registerAlias(dst_reg, dst_size),
......@@ -10420,7 +10402,7 @@ fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {
1042010402
1042110403 const ptr_ty = self.typeOf(extra.ptr);
1042210404 const val_ty = self.typeOf(extra.expected_value);
10423 const val_abi_size = @as(u32, @intCast(val_ty.abiSize(mod)));
10405 const val_abi_size: u32 = @intCast(val_ty.abiSize(mod));
1042410406
1042510407 try self.spillRegisters(&.{ .rax, .rdx, .rbx, .rcx });
1042610408 const regs_lock = self.register_manager.lockRegsAssumeUnused(4, .{ .rax, .rdx, .rbx, .rcx });
......@@ -10522,7 +10504,7 @@ fn atomicOp(
1052210504 };
1052310505 defer if (val_lock) |lock| self.register_manager.unlockReg(lock);
1052410506
10525 const val_abi_size = @as(u32, @intCast(val_ty.abiSize(mod)));
10507 const val_abi_size: u32 = @intCast(val_ty.abiSize(mod));
1052610508 const ptr_size = Memory.PtrSize.fromSize(val_abi_size);
1052710509 const ptr_mem = switch (ptr_mcv) {
1052810510 .immediate, .register, .register_offset, .lea_frame => ptr_mcv.deref().mem(ptr_size),
......@@ -10600,7 +10582,7 @@ fn atomicOp(
1060010582 defer self.register_manager.unlockReg(tmp_lock);
1060110583
1060210584 try self.asmRegisterMemory(.{ ._, .mov }, registerAlias(.rax, val_abi_size), ptr_mem);
10603 const loop = @as(u32, @intCast(self.mir_instructions.len));
10585 const loop: u32 = @intCast(self.mir_instructions.len);
1060410586 if (rmw_op != std.builtin.AtomicRmwOp.Xchg) {
1060510587 try self.genSetReg(tmp_reg, val_ty, .{ .register = .rax });
1060610588 }
......@@ -10674,7 +10656,7 @@ fn atomicOp(
1067410656 .scale_index = ptr_mem.scaleIndex(),
1067510657 .disp = ptr_mem.sib.disp + 8,
1067610658 }));
10677 const loop = @as(u32, @intCast(self.mir_instructions.len));
10659 const loop: u32 = @intCast(self.mir_instructions.len);
1067810660 const val_mem_mcv: MCValue = switch (val_mcv) {
1067910661 .memory, .indirect, .load_frame => val_mcv,
1068010662 else => .{ .indirect = .{
......@@ -10830,7 +10812,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1083010812 };
1083110813 defer if (src_val_lock) |lock| self.register_manager.unlockReg(lock);
1083210814
10833 const elem_abi_size = @as(u31, @intCast(elem_ty.abiSize(mod)));
10815 const elem_abi_size: u31 = @intCast(elem_ty.abiSize(mod));
1083410816
1083510817 if (elem_abi_size == 1) {
1083610818 const ptr: MCValue = switch (dst_ptr_ty.ptrSize(mod)) {
......@@ -11310,9 +11292,9 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
1131011292fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1131111293 const mod = self.bin_file.options.module.?;
1131211294 const result_ty = self.typeOfIndex(inst);
11313 const len = @as(usize, @intCast(result_ty.arrayLen(mod)));
11295 const len: usize = @intCast(result_ty.arrayLen(mod));
1131411296 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
11315 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
11297 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
1131611298 const result: MCValue = result: {
1131711299 switch (result_ty.zigTypeTag(mod)) {
1131811300 .Struct => {
......@@ -11329,17 +11311,17 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1132911311 if ((try result_ty.structFieldValueComptime(mod, elem_i)) != null) continue;
1133011312
1133111313 const elem_ty = result_ty.structFieldType(elem_i, mod);
11332 const elem_bit_size = @as(u32, @intCast(elem_ty.bitSize(mod)));
11314 const elem_bit_size: u32 = @intCast(elem_ty.bitSize(mod));
1133311315 if (elem_bit_size > 64) {
1133411316 return self.fail(
1133511317 "TODO airAggregateInit implement packed structs with large fields",
1133611318 .{},
1133711319 );
1133811320 }
11339 const elem_abi_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
11321 const elem_abi_size: u32 = @intCast(elem_ty.abiSize(mod));
1134011322 const elem_abi_bits = elem_abi_size * 8;
1134111323 const elem_off = struct_obj.packedFieldBitOffset(mod, elem_i);
11342 const elem_byte_off = @as(i32, @intCast(elem_off / elem_abi_bits * elem_abi_size));
11324 const elem_byte_off: i32 = @intCast(elem_off / elem_abi_bits * elem_abi_size);
1134311325 const elem_bit_off = elem_off % elem_abi_bits;
1134411326 const elem_mcv = try self.resolveInst(elem);
1134511327 const mat_elem_mcv = switch (elem_mcv) {
......@@ -11401,7 +11383,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1140111383 if ((try result_ty.structFieldValueComptime(mod, elem_i)) != null) continue;
1140211384
1140311385 const elem_ty = result_ty.structFieldType(elem_i, mod);
11404 const elem_off = @as(i32, @intCast(result_ty.structFieldOffset(elem_i, mod)));
11386 const elem_off: i32 = @intCast(result_ty.structFieldOffset(elem_i, mod));
1140511387 const elem_mcv = try self.resolveInst(elem);
1140611388 const mat_elem_mcv = switch (elem_mcv) {
1140711389 .load_tlv => |sym_index| MCValue{ .lea_tlv = sym_index },
......@@ -11415,7 +11397,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1141511397 const frame_index =
1141611398 try self.allocFrameIndex(FrameAlloc.initType(result_ty, mod));
1141711399 const elem_ty = result_ty.childType(mod);
11418 const elem_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
11400 const elem_size: u32 = @intCast(elem_ty.abiSize(mod));
1141911401
1142011402 for (elements, 0..) |elem, elem_i| {
1142111403 const elem_mcv = try self.resolveInst(elem);
......@@ -11423,12 +11405,12 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1142311405 .load_tlv => |sym_index| MCValue{ .lea_tlv = sym_index },
1142411406 else => elem_mcv,
1142511407 };
11426 const elem_off = @as(i32, @intCast(elem_size * elem_i));
11408 const elem_off: i32 = @intCast(elem_size * elem_i);
1142711409 try self.genSetMem(.{ .frame = frame_index }, elem_off, elem_ty, mat_elem_mcv);
1142811410 }
1142911411 if (result_ty.sentinel(mod)) |sentinel| try self.genSetMem(
1143011412 .{ .frame = frame_index },
11431 @as(i32, @intCast(elem_size * elements.len)),
11413 @intCast(elem_size * elements.len),
1143211414 elem_ty,
1143311415 try self.genTypedValue(.{ .ty = elem_ty, .val = sentinel }),
1143411416 );
......@@ -11476,16 +11458,16 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
1147611458 const tag_val = try mod.enumValueFieldIndex(tag_ty, field_index);
1147711459 const tag_int_val = try tag_val.intFromEnum(tag_ty, mod);
1147811460 const tag_int = tag_int_val.toUnsignedInt(mod);
11479 const tag_off = if (layout.tag_align < layout.payload_align)
11480 @as(i32, @intCast(layout.payload_size))
11461 const tag_off: i32 = if (layout.tag_align < layout.payload_align)
11462 @intCast(layout.payload_size)
1148111463 else
1148211464 0;
1148311465 try self.genCopy(tag_ty, dst_mcv.address().offset(tag_off).deref(), .{ .immediate = tag_int });
1148411466
11485 const pl_off = if (layout.tag_align < layout.payload_align)
11467 const pl_off: i32 = if (layout.tag_align < layout.payload_align)
1148611468 0
1148711469 else
11488 @as(i32, @intCast(layout.tag_size));
11470 @intCast(layout.tag_size);
1148911471 try self.genCopy(src_ty, dst_mcv.address().offset(pl_off).deref(), src_mcv);
1149011472
1149111473 break :result dst_mcv;
......@@ -11515,7 +11497,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1151511497 var order = [1]u2{0} ** 3;
1151611498 var unused = std.StaticBitSet(3).initFull();
1151711499 for (ops, &mcvs, &locks, 0..) |op, *mcv, *lock, op_i| {
11518 const op_index = @as(u2, @intCast(op_i));
11500 const op_index: u2 = @intCast(op_i);
1151911501 mcv.* = try self.resolveInst(op);
1152011502 if (unused.isSet(0) and mcv.isRegister() and self.reuseOperand(inst, op, op_index, mcv.*)) {
1152111503 order[op_index] = 1;
......@@ -11539,99 +11521,97 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1153911521 lock.* = self.register_manager.lockRegAssumeUnused(reg);
1154011522 }
1154111523
11542 const mir_tag = if (@as(
11543 ?Mir.Inst.FixedTag,
11544 if (mem.eql(u2, &order, &.{ 1, 3, 2 }) or mem.eql(u2, &order, &.{ 3, 1, 2 }))
11545 switch (ty.zigTypeTag(mod)) {
11546 .Float => switch (ty.floatBits(self.target.*)) {
11547 32 => .{ .v_ss, .fmadd132 },
11548 64 => .{ .v_sd, .fmadd132 },
11549 16, 80, 128 => null,
11550 else => unreachable,
11551 },
11552 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
11553 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
11554 32 => switch (ty.vectorLen(mod)) {
11555 1 => .{ .v_ss, .fmadd132 },
11556 2...8 => .{ .v_ps, .fmadd132 },
11557 else => null,
11558 },
11559 64 => switch (ty.vectorLen(mod)) {
11560 1 => .{ .v_sd, .fmadd132 },
11561 2...4 => .{ .v_pd, .fmadd132 },
11562 else => null,
11563 },
11564 16, 80, 128 => null,
11565 else => unreachable,
11566 },
11567 else => unreachable,
11568 },
11524 const mir_tag = @as(?Mir.Inst.FixedTag, if (mem.eql(u2, &order, &.{ 1, 3, 2 }) or
11525 mem.eql(u2, &order, &.{ 3, 1, 2 }))
11526 switch (ty.zigTypeTag(mod)) {
11527 .Float => switch (ty.floatBits(self.target.*)) {
11528 32 => .{ .v_ss, .fmadd132 },
11529 64 => .{ .v_sd, .fmadd132 },
11530 16, 80, 128 => null,
1156911531 else => unreachable,
11570 }
11571 else if (mem.eql(u2, &order, &.{ 2, 1, 3 }) or mem.eql(u2, &order, &.{ 1, 2, 3 }))
11572 switch (ty.zigTypeTag(mod)) {
11573 .Float => switch (ty.floatBits(self.target.*)) {
11574 32 => .{ .v_ss, .fmadd213 },
11575 64 => .{ .v_sd, .fmadd213 },
11576 16, 80, 128 => null,
11577 else => unreachable,
11578 },
11579 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
11580 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
11581 32 => switch (ty.vectorLen(mod)) {
11582 1 => .{ .v_ss, .fmadd213 },
11583 2...8 => .{ .v_ps, .fmadd213 },
11584 else => null,
11585 },
11586 64 => switch (ty.vectorLen(mod)) {
11587 1 => .{ .v_sd, .fmadd213 },
11588 2...4 => .{ .v_pd, .fmadd213 },
11589 else => null,
11590 },
11591 16, 80, 128 => null,
11592 else => unreachable,
11532 },
11533 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
11534 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
11535 32 => switch (ty.vectorLen(mod)) {
11536 1 => .{ .v_ss, .fmadd132 },
11537 2...8 => .{ .v_ps, .fmadd132 },
11538 else => null,
1159311539 },
11540 64 => switch (ty.vectorLen(mod)) {
11541 1 => .{ .v_sd, .fmadd132 },
11542 2...4 => .{ .v_pd, .fmadd132 },
11543 else => null,
11544 },
11545 16, 80, 128 => null,
1159411546 else => unreachable,
1159511547 },
1159611548 else => unreachable,
11597 }
11598 else if (mem.eql(u2, &order, &.{ 2, 3, 1 }) or mem.eql(u2, &order, &.{ 3, 2, 1 }))
11599 switch (ty.zigTypeTag(mod)) {
11600 .Float => switch (ty.floatBits(self.target.*)) {
11601 32 => .{ .v_ss, .fmadd231 },
11602 64 => .{ .v_sd, .fmadd231 },
11549 },
11550 else => unreachable,
11551 }
11552 else if (mem.eql(u2, &order, &.{ 2, 1, 3 }) or mem.eql(u2, &order, &.{ 1, 2, 3 }))
11553 switch (ty.zigTypeTag(mod)) {
11554 .Float => switch (ty.floatBits(self.target.*)) {
11555 32 => .{ .v_ss, .fmadd213 },
11556 64 => .{ .v_sd, .fmadd213 },
11557 16, 80, 128 => null,
11558 else => unreachable,
11559 },
11560 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
11561 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
11562 32 => switch (ty.vectorLen(mod)) {
11563 1 => .{ .v_ss, .fmadd213 },
11564 2...8 => .{ .v_ps, .fmadd213 },
11565 else => null,
11566 },
11567 64 => switch (ty.vectorLen(mod)) {
11568 1 => .{ .v_sd, .fmadd213 },
11569 2...4 => .{ .v_pd, .fmadd213 },
11570 else => null,
11571 },
1160311572 16, 80, 128 => null,
1160411573 else => unreachable,
1160511574 },
11606 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
11607 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
11608 32 => switch (ty.vectorLen(mod)) {
11609 1 => .{ .v_ss, .fmadd231 },
11610 2...8 => .{ .v_ps, .fmadd231 },
11611 else => null,
11612 },
11613 64 => switch (ty.vectorLen(mod)) {
11614 1 => .{ .v_sd, .fmadd231 },
11615 2...4 => .{ .v_pd, .fmadd231 },
11616 else => null,
11617 },
11618 16, 80, 128 => null,
11619 else => unreachable,
11575 else => unreachable,
11576 },
11577 else => unreachable,
11578 }
11579 else if (mem.eql(u2, &order, &.{ 2, 3, 1 }) or mem.eql(u2, &order, &.{ 3, 2, 1 }))
11580 switch (ty.zigTypeTag(mod)) {
11581 .Float => switch (ty.floatBits(self.target.*)) {
11582 32 => .{ .v_ss, .fmadd231 },
11583 64 => .{ .v_sd, .fmadd231 },
11584 16, 80, 128 => null,
11585 else => unreachable,
11586 },
11587 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
11588 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
11589 32 => switch (ty.vectorLen(mod)) {
11590 1 => .{ .v_ss, .fmadd231 },
11591 2...8 => .{ .v_ps, .fmadd231 },
11592 else => null,
11593 },
11594 64 => switch (ty.vectorLen(mod)) {
11595 1 => .{ .v_sd, .fmadd231 },
11596 2...4 => .{ .v_pd, .fmadd231 },
11597 else => null,
1162011598 },
11599 16, 80, 128 => null,
1162111600 else => unreachable,
1162211601 },
1162311602 else => unreachable,
11624 }
11625 else
11626 unreachable,
11627 )) |tag| tag else return self.fail("TODO implement airMulAdd for {}", .{
11603 },
11604 else => unreachable,
11605 }
11606 else
11607 unreachable) orelse return self.fail("TODO implement airMulAdd for {}", .{
1162811608 ty.fmt(self.bin_file.options.module.?),
1162911609 });
1163011610
1163111611 var mops: [3]MCValue = undefined;
1163211612 for (order, mcvs) |mop_index, mcv| mops[mop_index - 1] = mcv;
1163311613
11634 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));
11614 const abi_size: u32 = @intCast(ty.abiSize(mod));
1163511615 const mop1_reg = registerAlias(mops[0].getReg().?, abi_size);
1163611616 const mop2_reg = registerAlias(mops[1].getReg().?, abi_size);
1163711617 if (mops[2].isRegister()) try self.asmRegisterRegisterRegister(
......@@ -11784,7 +11764,7 @@ fn resolveCallingConventionValues(
1178411764 switch (self.target.os.tag) {
1178511765 .windows => {
1178611766 // Align the stack to 16bytes before allocating shadow stack space (if any).
11787 result.stack_byte_count += @as(u31, @intCast(4 * Type.usize.abiSize(mod)));
11767 result.stack_byte_count += @intCast(4 * Type.usize.abiSize(mod));
1178811768 },
1178911769 else => {},
1179011770 }
......@@ -11807,7 +11787,7 @@ fn resolveCallingConventionValues(
1180711787 result.return_value = switch (classes[0]) {
1180811788 .integer => InstTracking.init(.{ .register = registerAlias(
1180911789 ret_reg,
11810 @as(u32, @intCast(ret_ty.abiSize(mod))),
11790 @intCast(ret_ty.abiSize(mod)),
1181111791 ) }),
1181211792 .float, .sse => InstTracking.init(.{ .register = .xmm0 }),
1181311793 .memory => ret: {
......@@ -11843,18 +11823,16 @@ fn resolveCallingConventionValues(
1184311823 },
1184411824 .float, .sse => switch (self.target.os.tag) {
1184511825 .windows => if (param_reg_i < 4) {
11846 arg.* = .{ .register = @as(
11847 Register,
11848 @enumFromInt(@intFromEnum(Register.xmm0) + param_reg_i),
11849 ) };
11826 arg.* = .{
11827 .register = @enumFromInt(@intFromEnum(Register.xmm0) + param_reg_i),
11828 };
1185011829 param_reg_i += 1;
1185111830 continue;
1185211831 },
1185311832 else => if (param_sse_reg_i < 8) {
11854 arg.* = .{ .register = @as(
11855 Register,
11856 @enumFromInt(@intFromEnum(Register.xmm0) + param_sse_reg_i),
11857 ) };
11833 arg.* = .{
11834 .register = @enumFromInt(@intFromEnum(Register.xmm0) + param_sse_reg_i),
11835 };
1185811836 param_sse_reg_i += 1;
1185911837 continue;
1186011838 },
......@@ -11865,8 +11843,8 @@ fn resolveCallingConventionValues(
1186511843 }),
1186611844 }
1186711845
11868 const param_size = @as(u31, @intCast(ty.abiSize(mod)));
11869 const param_align = @as(u31, @intCast(ty.abiAlignment(mod)));
11846 const param_size: u31 = @intCast(ty.abiSize(mod));
11847 const param_align: u31 = @intCast(ty.abiAlignment(mod));
1187011848 result.stack_byte_count =
1187111849 mem.alignForward(u31, result.stack_byte_count, param_align);
1187211850 arg.* = .{ .load_frame = .{
......@@ -11886,7 +11864,7 @@ fn resolveCallingConventionValues(
1188611864 result.return_value = InstTracking.init(.none);
1188711865 } else {
1188811866 const ret_reg = abi.getCAbiIntReturnRegs(self.target.*)[0];
11889 const ret_ty_size = @as(u31, @intCast(ret_ty.abiSize(mod)));
11867 const ret_ty_size: u31 = @intCast(ret_ty.abiSize(mod));
1189011868 if (ret_ty_size <= 8 and !ret_ty.isRuntimeFloat()) {
1189111869 const aliased_reg = registerAlias(ret_reg, ret_ty_size);
1189211870 result.return_value = .{ .short = .{ .register = aliased_reg }, .long = .none };
......@@ -11905,8 +11883,8 @@ fn resolveCallingConventionValues(
1190511883 arg.* = .none;
1190611884 continue;
1190711885 }
11908 const param_size = @as(u31, @intCast(ty.abiSize(mod)));
11909 const param_align = @as(u31, @intCast(ty.abiAlignment(mod)));
11886 const param_size: u31 = @intCast(ty.abiSize(mod));
11887 const param_align: u31 = @intCast(ty.abiAlignment(mod));
1191011888 result.stack_byte_count =
1191111889 mem.alignForward(u31, result.stack_byte_count, param_align);
1191211890 arg.* = .{ .load_frame = .{
......@@ -11993,12 +11971,12 @@ fn truncateRegister(self: *Self, ty: Type, reg: Register) !void {
1199311971 const mod = self.bin_file.options.module.?;
1199411972 const int_info = if (ty.isAbiInt(mod)) ty.intInfo(mod) else std.builtin.Type.Int{
1199511973 .signedness = .unsigned,
11996 .bits = @as(u16, @intCast(ty.bitSize(mod))),
11974 .bits = @intCast(ty.bitSize(mod)),
1199711975 };
1199811976 const max_reg_bit_width = Register.rax.bitSize();
1199911977 switch (int_info.signedness) {
1200011978 .signed => {
12001 const shift = @as(u6, @intCast(max_reg_bit_width - int_info.bits));
11979 const shift: u6 = @intCast(max_reg_bit_width - int_info.bits);
1200211980 try self.genShiftBinOpMir(
1200311981 .{ ._l, .sa },
1200411982 Type.isize,
......@@ -12013,8 +11991,8 @@ fn truncateRegister(self: *Self, ty: Type, reg: Register) !void {
1201311991 );
1201411992 },
1201511993 .unsigned => {
12016 const shift = @as(u6, @intCast(max_reg_bit_width - int_info.bits));
12017 const mask = (~@as(u64, 0)) >> shift;
11994 const shift: u6 = @intCast(max_reg_bit_width - int_info.bits);
11995 const mask = ~@as(u64, 0) >> shift;
1201811996 if (int_info.bits <= 32) {
1201911997 try self.genBinOpMir(
1202011998 .{ ._, .@"and" },