| ... | @@ -1032,7 +1032,8 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -1032,7 +1032,8 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 1032 | const dst_bit_size = dst_ty.bitSize(self.target.*); | 1032 | const dst_bit_size = dst_ty.bitSize(self.target.*); |
| 1033 | const is_power_of_two = (dst_bit_size & (dst_bit_size - 1)) == 0; | 1033 | const is_power_of_two = (dst_bit_size & (dst_bit_size - 1)) == 0; |
| 1034 | if (!is_power_of_two or dst_bit_size < 8) { | 1034 | if (!is_power_of_two or dst_bit_size < 8) { |
| 1035 | const shift = @intCast(u6, 64 - dst_ty.bitSize(self.target.*)); | 1035 | const max_reg_bit_width = Register.rax.size(); |
| | 1036 | const shift = @intCast(u6, max_reg_bit_width - dst_ty.bitSize(self.target.*)); |
| 1036 | const mask = (~@as(u64, 0)) >> shift; | 1037 | const mask = (~@as(u64, 0)) >> shift; |
| 1037 | try self.genBinMathOpMir(.@"and", Type.usize, .{ .register = reg }, .{ .immediate = mask }); | 1038 | try self.genBinMathOpMir(.@"and", Type.usize, .{ .register = reg }, .{ .immediate = mask }); |
| 1038 | | 1039 | |
| ... | @@ -1739,7 +1740,7 @@ fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -1739,7 +1740,7 @@ fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 1739 | .register => { | 1740 | .register => { |
| 1740 | // TODO reuse the operand | 1741 | // TODO reuse the operand |
| 1741 | const result = try self.copyToRegisterWithInstTracking(inst, optional_ty, operand); | 1742 | const result = try self.copyToRegisterWithInstTracking(inst, optional_ty, operand); |
| 1742 | const shift = @intCast(u8, offset * 8); | 1743 | const shift = @intCast(u8, offset * @sizeOf(usize)); |
| 1743 | try self.shiftRegister(result.register, @intCast(u8, shift)); | 1744 | try self.shiftRegister(result.register, @intCast(u8, shift)); |
| 1744 | break :result result; | 1745 | break :result result; |
| 1745 | }, | 1746 | }, |
| ... | @@ -1809,16 +1810,17 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -1809,16 +1810,17 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 1809 | operand.freezeIfRegister(&self.register_manager); | 1810 | operand.freezeIfRegister(&self.register_manager); |
| 1810 | defer operand.unfreezeIfRegister(&self.register_manager); | 1811 | defer operand.unfreezeIfRegister(&self.register_manager); |
| 1811 | | 1812 | |
| | 1813 | const abi_align = err_union_ty.abiAlignment(self.target.*); |
| 1812 | const err_ty = err_union_ty.errorUnionSet(); | 1814 | const err_ty = err_union_ty.errorUnionSet(); |
| | 1815 | const err_abi_size = mem.alignForwardGeneric(u32, @intCast(u32, err_ty.abiSize(self.target.*)), abi_align); |
| 1813 | switch (operand) { | 1816 | switch (operand) { |
| 1814 | .stack_offset => |off| { | 1817 | .stack_offset => |off| { |
| 1815 | const err_abi_size = @intCast(u32, err_ty.abiSize(self.target.*)); | | |
| 1816 | const offset = off - @intCast(i32, err_abi_size); | 1818 | const offset = off - @intCast(i32, err_abi_size); |
| 1817 | break :result MCValue{ .stack_offset = offset }; | 1819 | break :result MCValue{ .stack_offset = offset }; |
| 1818 | }, | 1820 | }, |
| 1819 | .register => { | 1821 | .register => { |
| 1820 | // TODO reuse operand | 1822 | // TODO reuse operand |
| 1821 | const shift = @intCast(u6, err_ty.bitSize(self.target.*)); | 1823 | const shift = @intCast(u6, err_abi_size * @sizeOf(usize)); |
| 1822 | const result = try self.copyToRegisterWithInstTracking(inst, err_union_ty, operand); | 1824 | const result = try self.copyToRegisterWithInstTracking(inst, err_union_ty, operand); |
| 1823 | try self.shiftRegister(result.register.to64(), shift); | 1825 | try self.shiftRegister(result.register.to64(), shift); |
| 1824 | break :result MCValue{ | 1826 | break :result MCValue{ |
| ... | @@ -1914,8 +1916,9 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -1914,8 +1916,9 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 1914 | const abi_align = error_union_ty.abiAlignment(self.target.*); | 1916 | const abi_align = error_union_ty.abiAlignment(self.target.*); |
| 1915 | const err_abi_size = @intCast(u32, error_ty.abiSize(self.target.*)); | 1917 | const err_abi_size = @intCast(u32, error_ty.abiSize(self.target.*)); |
| 1916 | const stack_offset = @intCast(i32, try self.allocMem(inst, abi_size, abi_align)); | 1918 | const stack_offset = @intCast(i32, try self.allocMem(inst, abi_size, abi_align)); |
| | 1919 | const offset = mem.alignForwardGeneric(u32, err_abi_size, abi_align); |
| 1917 | try self.genSetStack(error_ty, stack_offset, .{ .immediate = 0 }, .{}); | 1920 | try self.genSetStack(error_ty, stack_offset, .{ .immediate = 0 }, .{}); |
| 1918 | try self.genSetStack(payload_ty, stack_offset - @intCast(i32, err_abi_size), operand, .{}); | 1921 | try self.genSetStack(payload_ty, stack_offset - @intCast(i32, offset), operand, .{}); |
| 1919 | | 1922 | |
| 1920 | return self.finishAir(inst, .{ .stack_offset = stack_offset }, .{ ty_op.operand, .none, .none }); | 1923 | return self.finishAir(inst, .{ .stack_offset = stack_offset }, .{ ty_op.operand, .none, .none }); |
| 1921 | } | 1924 | } |
| ... | @@ -1937,8 +1940,9 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -1937,8 +1940,9 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void { |
| 1937 | const abi_align = error_union_ty.abiAlignment(self.target.*); | 1940 | const abi_align = error_union_ty.abiAlignment(self.target.*); |
| 1938 | const err_abi_size = @intCast(u32, error_ty.abiSize(self.target.*)); | 1941 | const err_abi_size = @intCast(u32, error_ty.abiSize(self.target.*)); |
| 1939 | const stack_offset = @intCast(i32, try self.allocMem(inst, abi_size, abi_align)); | 1942 | const stack_offset = @intCast(i32, try self.allocMem(inst, abi_size, abi_align)); |
| | 1943 | const offset = mem.alignForwardGeneric(u32, err_abi_size, abi_align); |
| 1940 | try self.genSetStack(error_ty, stack_offset, err, .{}); | 1944 | try self.genSetStack(error_ty, stack_offset, err, .{}); |
| 1941 | try self.genSetStack(payload_ty, stack_offset - @intCast(i32, err_abi_size), .undef, .{}); | 1945 | try self.genSetStack(payload_ty, stack_offset - @intCast(i32, offset), .undef, .{}); |
| 1942 | break :result MCValue{ .stack_offset = stack_offset }; | 1946 | break :result MCValue{ .stack_offset = stack_offset }; |
| 1943 | }; | 1947 | }; |
| 1944 | | 1948 | |
| ... | @@ -2243,7 +2247,7 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -2243,7 +2247,7 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void { |
| 2243 | }, | 2247 | }, |
| 2244 | .register => { | 2248 | .register => { |
| 2245 | const shift: u6 = if (layout.tag_align < layout.payload_align) | 2249 | const shift: u6 = if (layout.tag_align < layout.payload_align) |
| 2246 | @intCast(u6, layout.payload_size * 8) | 2250 | @intCast(u6, layout.payload_size * @sizeOf(usize)) |
| 2247 | else | 2251 | else |
| 2248 | 0; | 2252 | 0; |
| 2249 | const result = try self.copyToRegisterWithInstTracking(inst, union_ty, operand); | 2253 | const result = try self.copyToRegisterWithInstTracking(inst, union_ty, operand); |
| ... | @@ -2819,11 +2823,12 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -2819,11 +2823,12 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2819 | }; | 2823 | }; |
| 2820 | | 2824 | |
| 2821 | // Shift by struct_field_offset. | 2825 | // Shift by struct_field_offset. |
| 2822 | const shift = @intCast(u8, struct_field_offset * 8); | 2826 | const shift = @intCast(u8, struct_field_offset * @sizeOf(usize)); |
| 2823 | try self.shiftRegister(dst_mcv.register, shift); | 2827 | try self.shiftRegister(dst_mcv.register, shift); |
| 2824 | | 2828 | |
| 2825 | // Mask with reg.size() - struct_field_size | 2829 | // Mask with reg.size() - struct_field_size |
| 2826 | const mask_shift = @intCast(u6, (64 - struct_field_ty.bitSize(self.target.*))); | 2830 | const max_reg_bit_width = Register.rax.size(); |
| | 2831 | const mask_shift = @intCast(u6, (max_reg_bit_width - struct_field_ty.bitSize(self.target.*))); |
| 2827 | const mask = (~@as(u64, 0)) >> mask_shift; | 2832 | const mask = (~@as(u64, 0)) >> mask_shift; |
| 2828 | try self.genBinMathOpMir(.@"and", Type.usize, dst_mcv, .{ .immediate = mask }); | 2833 | try self.genBinMathOpMir(.@"and", Type.usize, dst_mcv, .{ .immediate = mask }); |
| 2829 | | 2834 | |