diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2022-05-03 11:48:30 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2022-05-03 16:39:21 +0200 |
| commit | d48789467d95ddf0582c855d01f32bef48726e29 (patch) | |
| tree | 6eb72560902e0b44b189e35311b437fc3507daa5 /src | |
| parent | 098bee0e5657bb6dcd92b2b2fa8056ffce893ffc (diff) | |
| download | zig-d48789467d95ddf0582c855d01f32bef48726e29.tar.gz zig-d48789467d95ddf0582c855d01f32bef48726e29.zip | |
x86_64: use math.zig to check isPowerOfTwo and calc log2_int
Diffstat (limited to 'src')
| -rw-r--r-- | src/arch/x86_64/CodeGen.zig | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index 0103f5382f..ed85874413 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -1085,8 +1085,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void { // when truncating a `u16` to `u5`, for example, those top 3 bits in the result // have to be removed. this only happens if the dst if not a power-of-two size. const dst_bit_size = dst_ty.bitSize(self.target.*); - const is_power_of_two = (dst_bit_size & (dst_bit_size - 1)) == 0; - if (!is_power_of_two or dst_bit_size < 8) { + if (!math.isPowerOfTwo(dst_bit_size) or dst_bit_size < 8) { const max_reg_bit_width = Register.rax.size(); const shift = @intCast(u6, max_reg_bit_width - dst_ty.bitSize(self.target.*)); const mask = (~@as(u64, 0)) >> shift; @@ -5125,8 +5124,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue, opts: Inl } const base_reg = opts.dest_stack_base orelse .rbp; - const is_power_of_two = (abi_size % 2) == 0; - if (!is_power_of_two) { + if (!math.isPowerOfTwo(abi_size)) { self.register_manager.freezeRegs(&.{reg}); defer self.register_manager.unfreezeRegs(&.{reg}); @@ -5135,31 +5133,31 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue, opts: Inl var next_offset = stack_offset; var remainder = abi_size; while (remainder > 0) { - const closest_power_of_two = @as(u6, 1) << @intCast(u3, math.log2(remainder)); + const nearest_power_of_two = @as(u6, 1) << math.log2_int(u3, @intCast(u3, remainder)); _ = try self.addInst(.{ .tag = .mov, .ops = (Mir.Ops{ .reg1 = base_reg, - .reg2 = registerAlias(tmp_reg, closest_power_of_two), + .reg2 = registerAlias(tmp_reg, nearest_power_of_two), .flags = 0b10, }).encode(), .data = .{ .imm = @bitCast(u32, -next_offset) }, }); - if (closest_power_of_two > 1) { + if (nearest_power_of_two > 1) { _ = try self.addInst(.{ .tag = .shr, .ops = (Mir.Ops{ .reg1 = tmp_reg, .flags = 0b10, }).encode(), - .data = .{ .imm = closest_power_of_two * 8 }, + .data = .{ .imm = nearest_power_of_two * 8 }, }); } - remainder -= closest_power_of_two; - next_offset -= closest_power_of_two; + remainder -= nearest_power_of_two; + next_offset -= nearest_power_of_two; } } else { _ = try self.addInst(.{ |
