authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-11-14 18:10:29-05:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-11-14 22:50:05-05:00
log0c6cb8d8c80f0a316a77eddfebaa42cb77c8bf7d
tree62180725bccf579b7e33bc8dfdc7983ff0f1d85a
parent6fd1c64f23807993246515b93eb14978cff0e5da

x86_64: actually track state during `@divFloor` of `i128`

Closes #17998

2 files changed, 9 insertions(+), 4 deletions(-)

lib/std/math/big/int_test.zig-3
...@@ -1443,9 +1443,6 @@ test "big.int divFloor #11166" {...@@ -1443,9 +1443,6 @@ test "big.int divFloor #11166" {
1443}1443}
14441444
1445test "big.int gcd #10932" {1445test "big.int gcd #10932" {
1446 // TODO https://github.com/ziglang/zig/issues/17998
1447 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1448
1449 var a = try Managed.init(testing.allocator);1446 var a = try Managed.init(testing.allocator);
1450 defer a.deinit();1447 defer a.deinit();
14511448
src/arch/x86_64/CodeGen.zig+9-1
...@@ -3235,6 +3235,7 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -3235,6 +3235,7 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
3235 var callee_buf: ["__udiv?i3".len]u8 = undefined;3235 var callee_buf: ["__udiv?i3".len]u8 = undefined;
3236 const signed_div_floor_state: struct {3236 const signed_div_floor_state: struct {
3237 frame_index: FrameIndex,3237 frame_index: FrameIndex,
3238 state: State,
3238 reloc: Mir.Inst.Index,3239 reloc: Mir.Inst.Index,
3239 } = if (signed and tag == .div_floor) state: {3240 } = if (signed and tag == .div_floor) state: {
3240 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(Type.usize, mod));3241 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(Type.usize, mod));
...@@ -3295,9 +3296,10 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -3295,9 +3296,10 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
3295 tmp_reg,3296 tmp_reg,
3296 mat_rhs_mcv.register_pair[1],3297 mat_rhs_mcv.register_pair[1],
3297 );3298 );
3299 const state = try self.saveState();
3298 const reloc = try self.asmJccReloc(.ns, undefined);3300 const reloc = try self.asmJccReloc(.ns, undefined);
32993301
3300 break :state .{ .frame_index = frame_index, .reloc = reloc };3302 break :state .{ .frame_index = frame_index, .state = state, .reloc = reloc };
3301 } else undefined;3303 } else undefined;
3302 const call_mcv = try self.genCall(3304 const call_mcv = try self.genCall(
3303 .{ .lib = .{3305 .{ .lib = .{
...@@ -3328,6 +3330,12 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -3328,6 +3330,12 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
3328 .base = .{ .frame = signed_div_floor_state.frame_index },3330 .base = .{ .frame = signed_div_floor_state.frame_index },
3329 .mod = .{ .rm = .{ .size = .byte } },3331 .mod = .{ .rm = .{ .size = .byte } },
3330 });3332 });
3333 try self.restoreState(signed_div_floor_state.state, &.{}, .{
3334 .emit_instructions = true,
3335 .update_tracking = true,
3336 .resurrect = true,
3337 .close_scope = true,
3338 });
3331 try self.performReloc(signed_div_floor_state.reloc);3339 try self.performReloc(signed_div_floor_state.reloc);
3332 const dst_mcv = try self.genCall(3340 const dst_mcv = try self.genCall(
3333 .{ .lib = .{3341 .{ .lib = .{