authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-03-28 17:45:50+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-03-28 17:45:50+02:00
loge6729036e44af2a52c52ce9f1f99e01d1e642cf3
treededc9ad09cc815f11a4ca72f31c43caef240ed3e
parent107052aded5dc1666c687838e8e2995654f17a45

x64: partially fix genImul, enable overflow tests


2 files changed, 12 insertions(+), 12 deletions(-)

src/arch/x86_64/CodeGen.zig+6-5
...@@ -3254,6 +3254,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC...@@ -3254,6 +3254,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
32543254
3255// Performs integer multiplication between dst_mcv and src_mcv, storing the result in dst_mcv.3255// Performs integer multiplication between dst_mcv and src_mcv, storing the result in dst_mcv.
3256fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !void {3256fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !void {
3257 const abi_size = @intCast(u32, dst_ty.abiSize(self.target.*));
3257 switch (dst_mcv) {3258 switch (dst_mcv) {
3258 .none => unreachable,3259 .none => unreachable,
3259 .undef => unreachable,3260 .undef => unreachable,
...@@ -3276,8 +3277,8 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !...@@ -3276,8 +3277,8 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !
3276 _ = try self.addInst(.{3277 _ = try self.addInst(.{
3277 .tag = .imul_complex,3278 .tag = .imul_complex,
3278 .ops = (Mir.Ops{3279 .ops = (Mir.Ops{
3279 .reg1 = registerAlias(dst_reg, @divExact(src_reg.size(), 8)),3280 .reg1 = registerAlias(dst_reg, abi_size),
3280 .reg2 = src_reg,3281 .reg2 = registerAlias(src_reg, abi_size),
3281 }).encode(),3282 }).encode(),
3282 .data = undefined,3283 .data = undefined,
3283 });3284 });
...@@ -3305,7 +3306,7 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !...@@ -3305,7 +3306,7 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !
3305 _ = try self.addInst(.{3306 _ = try self.addInst(.{
3306 .tag = .imul_complex,3307 .tag = .imul_complex,
3307 .ops = (Mir.Ops{3308 .ops = (Mir.Ops{
3308 .reg1 = registerAlias(dst_reg, @intCast(u32, dst_ty.abiSize(self.target.*))),3309 .reg1 = registerAlias(dst_reg, abi_size),
3309 .reg2 = .rbp,3310 .reg2 = .rbp,
3310 .flags = 0b01,3311 .flags = 0b01,
3311 }).encode(),3312 }).encode(),
...@@ -3342,8 +3343,8 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !...@@ -3342,8 +3343,8 @@ fn genIMulOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !
3342 _ = try self.addInst(.{3343 _ = try self.addInst(.{
3343 .tag = .imul_complex,3344 .tag = .imul_complex,
3344 .ops = (Mir.Ops{3345 .ops = (Mir.Ops{
3345 .reg1 = registerAlias(dst_reg, @divExact(src_reg.size(), 8)),3346 .reg1 = registerAlias(dst_reg, abi_size),
3346 .reg2 = src_reg,3347 .reg2 = registerAlias(src_reg, abi_size),
3347 }).encode(),3348 }).encode(),
3348 .data = undefined,3349 .data = undefined,
3349 });3350 });
test/behavior/math.zig+6-7
...@@ -639,7 +639,6 @@ test "128-bit multiplication" {...@@ -639,7 +639,6 @@ test "128-bit multiplication" {
639639
640test "@addWithOverflow" {640test "@addWithOverflow" {
641 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO641 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
642 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
643 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO642 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
644 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO643 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
645644
...@@ -684,7 +683,6 @@ test "small int addition" {...@@ -684,7 +683,6 @@ test "small int addition" {
684683
685test "@mulWithOverflow" {684test "@mulWithOverflow" {
686 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO685 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
687 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
688 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO686 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
689 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO687 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
690688
...@@ -698,14 +696,16 @@ test "@mulWithOverflow" {...@@ -698,14 +696,16 @@ test "@mulWithOverflow" {
698 var b: u8 = 2;696 var b: u8 = 2;
699 try expect(!@mulWithOverflow(u8, a, b, &result));697 try expect(!@mulWithOverflow(u8, a, b, &result));
700 try expect(result == 246);698 try expect(result == 246);
701 b = 4;699
702 try expect(@mulWithOverflow(u8, a, b, &result));700 if (builtin.zig_backend != .stage2_x86_64) { // TODO fix mul/imul on x86_64
703 try expect(result == 236);701 b = 4;
702 try expect(@mulWithOverflow(u8, a, b, &result));
703 try expect(result == 236);
704 }
704}705}
705706
706test "@subWithOverflow" {707test "@subWithOverflow" {
707 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO708 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
708 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
709 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO709 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
710 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO710 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
711711
...@@ -747,7 +747,6 @@ test "@shlWithOverflow" {...@@ -747,7 +747,6 @@ test "@shlWithOverflow" {
747747
748test "overflow arithmetic with u0 values" {748test "overflow arithmetic with u0 values" {
749 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO749 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
750 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
751750
752 var result: u0 = undefined;751 var result: u0 = undefined;
753 try expect(!@addWithOverflow(u0, 0, 0, &result));752 try expect(!@addWithOverflow(u0, 0, 0, &result));