diff options
| author | Jacob Young <15544577+jacobly0@users.noreply.github.com> | 2025-04-11 05:21:44 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-11 05:21:44 -0400 |
| commit | c82e1fe880629beea5660c675cfc698807205601 (patch) | |
| tree | 33180acf7aafbf0d5352ecd4f8dffe187cbb9138 /test/behavior/math.zig | |
| parent | 9e21ba12d55c638cbc4898ae0f88f63821004f74 (diff) | |
| parent | 73498737a2da4f43002783da4755a67aba42344e (diff) | |
| download | zig-c82e1fe880629beea5660c675cfc698807205601.tar.gz zig-c82e1fe880629beea5660c675cfc698807205601.zip | |
Merge pull request #23355 from jacobly0/x86_64-rewrite
x86_64: start rewriting overflow operations
Diffstat (limited to 'test/behavior/math.zig')
| -rw-r--r-- | test/behavior/math.zig | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/test/behavior/math.zig b/test/behavior/math.zig index 28d7ec0488..2d95407a8e 100644 --- a/test/behavior/math.zig +++ b/test/behavior/math.zig @@ -787,7 +787,6 @@ fn should_not_be_zero(x: f128) !void { test "umax wrapped squaring" { if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; - if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; { @@ -1050,13 +1049,13 @@ test "@mulWithOverflow bitsize > 32" { } test "@mulWithOverflow bitsize 128 bits" { - if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; try testMulWithOverflow(u128, 3, 0x5555555555555555_5555555555555555, 0xffffffffffffffff_ffffffffffffffff, 0); try testMulWithOverflow(u128, 3, 0x5555555555555555_5555555555555556, 2, 1); @@ -1070,13 +1069,19 @@ test "@mulWithOverflow bitsize 128 bits" { try testMulWithOverflow(i128, 3, -0x2aaaaaaaaaaaaaaa_aaaaaaaaaaaaaaab, 0x7fffffffffffffff_ffffffffffffffff, 1); try testMulWithOverflow(i128, -1, -1, 1, 0); try testMulWithOverflow(i128, minInt(i128), minInt(i128), 0, 1); + + try testMulWithOverflow(i128, 1 << 126, 1 << 1, -1 << 127, 1); + try testMulWithOverflow(i128, -1 << 105, 1 << 22, -1 << 127, 0); + try testMulWithOverflow(i128, 1 << 84, -1 << 43, -1 << 127, 0); + try testMulWithOverflow(i128, -1 << 63, -1 << 64, -1 << 127, 1); } -test "@mulWithOverflow u256" { +test "@mulWithOverflow bitsize 256 bits" { if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; { const const_lhs: u256 = 8035709466408580321693645878924206181189; @@ -1106,6 +1111,10 @@ test "@mulWithOverflow u256" { try std.testing.expect(var_result[0] == const_result[0]); try std.testing.expect(var_result[1] == const_result[1]); } + try testMulWithOverflow(i256, 1 << 254, 1 << 1, -1 << 255, 1); + try testMulWithOverflow(i256, -1 << 212, 1 << 43, -1 << 255, 0); + try testMulWithOverflow(i256, 1 << 170, -1 << 85, -1 << 255, 0); + try testMulWithOverflow(i256, -1 << 128, -1 << 127, -1 << 255, 1); } fn testSubWithOverflow(comptime T: type, a: T, b: T, sub: T, bit: u1) !void { |
