| ... | @@ -1085,8 +1085,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -1085,8 +1085,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 1085 | // when truncating a `u16` to `u5`, for example, those top 3 bits in the result | 1085 | // when truncating a `u16` to `u5`, for example, those top 3 bits in the result |
| 1086 | // have to be removed. this only happens if the dst if not a power-of-two size. | 1086 | // have to be removed. this only happens if the dst if not a power-of-two size. |
| 1087 | const dst_bit_size = dst_ty.bitSize(self.target.*); | 1087 | const dst_bit_size = dst_ty.bitSize(self.target.*); |
| 1088 | const is_power_of_two = (dst_bit_size & (dst_bit_size - 1)) == 0; | 1088 | if (!math.isPowerOfTwo(dst_bit_size) or dst_bit_size < 8) { |
| 1089 | if (!is_power_of_two or dst_bit_size < 8) { | | |
| 1090 | const max_reg_bit_width = Register.rax.size(); | 1089 | const max_reg_bit_width = Register.rax.size(); |
| 1091 | const shift = @intCast(u6, max_reg_bit_width - dst_ty.bitSize(self.target.*)); | 1090 | const shift = @intCast(u6, max_reg_bit_width - dst_ty.bitSize(self.target.*)); |
| 1092 | const mask = (~@as(u64, 0)) >> shift; | 1091 | const mask = (~@as(u64, 0)) >> shift; |
| ... | @@ -5125,8 +5124,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue, opts: Inl | ... | @@ -5125,8 +5124,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue, opts: Inl |
| 5125 | } | 5124 | } |
| 5126 | | 5125 | |
| 5127 | const base_reg = opts.dest_stack_base orelse .rbp; | 5126 | const base_reg = opts.dest_stack_base orelse .rbp; |
| 5128 | const is_power_of_two = (abi_size % 2) == 0; | 5127 | if (!math.isPowerOfTwo(abi_size)) { |
| 5129 | if (!is_power_of_two) { | | |
| 5130 | self.register_manager.freezeRegs(&.{reg}); | 5128 | self.register_manager.freezeRegs(&.{reg}); |
| 5131 | defer self.register_manager.unfreezeRegs(&.{reg}); | 5129 | defer self.register_manager.unfreezeRegs(&.{reg}); |
| 5132 | | 5130 | |
| ... | @@ -5135,31 +5133,31 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue, opts: Inl | ... | @@ -5135,31 +5133,31 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue, opts: Inl |
| 5135 | var next_offset = stack_offset; | 5133 | var next_offset = stack_offset; |
| 5136 | var remainder = abi_size; | 5134 | var remainder = abi_size; |
| 5137 | while (remainder > 0) { | 5135 | while (remainder > 0) { |
| 5138 | const closest_power_of_two = @as(u6, 1) << @intCast(u3, math.log2(remainder)); | 5136 | const nearest_power_of_two = @as(u6, 1) << math.log2_int(u3, @intCast(u3, remainder)); |
| 5139 | | 5137 | |
| 5140 | _ = try self.addInst(.{ | 5138 | _ = try self.addInst(.{ |
| 5141 | .tag = .mov, | 5139 | .tag = .mov, |
| 5142 | .ops = (Mir.Ops{ | 5140 | .ops = (Mir.Ops{ |
| 5143 | .reg1 = base_reg, | 5141 | .reg1 = base_reg, |
| 5144 | .reg2 = registerAlias(tmp_reg, closest_power_of_two), | 5142 | .reg2 = registerAlias(tmp_reg, nearest_power_of_two), |
| 5145 | .flags = 0b10, | 5143 | .flags = 0b10, |
| 5146 | }).encode(), | 5144 | }).encode(), |
| 5147 | .data = .{ .imm = @bitCast(u32, -next_offset) }, | 5145 | .data = .{ .imm = @bitCast(u32, -next_offset) }, |
| 5148 | }); | 5146 | }); |
| 5149 | | 5147 | |
| 5150 | if (closest_power_of_two > 1) { | 5148 | if (nearest_power_of_two > 1) { |
| 5151 | _ = try self.addInst(.{ | 5149 | _ = try self.addInst(.{ |
| 5152 | .tag = .shr, | 5150 | .tag = .shr, |
| 5153 | .ops = (Mir.Ops{ | 5151 | .ops = (Mir.Ops{ |
| 5154 | .reg1 = tmp_reg, | 5152 | .reg1 = tmp_reg, |
| 5155 | .flags = 0b10, | 5153 | .flags = 0b10, |
| 5156 | }).encode(), | 5154 | }).encode(), |
| 5157 | .data = .{ .imm = closest_power_of_two * 8 }, | 5155 | .data = .{ .imm = nearest_power_of_two * 8 }, |
| 5158 | }); | 5156 | }); |
| 5159 | } | 5157 | } |
| 5160 | | 5158 | |
| 5161 | remainder -= closest_power_of_two; | 5159 | remainder -= nearest_power_of_two; |
| 5162 | next_offset -= closest_power_of_two; | 5160 | next_offset -= nearest_power_of_two; |
| 5163 | } | 5161 | } |
| 5164 | } else { | 5162 | } else { |
| 5165 | _ = try self.addInst(.{ | 5163 | _ = try self.addInst(.{ |