aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/math.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2025-03-26 14:17:10 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2025-04-09 20:14:12 -0400
commitbc10131db11fad281163a53c4702873047cb9223 (patch)
tree9ace16c4420a1f6c14bfd9c74b792d6605212538 /test/behavior/math.zig
parent55ce756868fbe2cfc6cec956122d27af762b78f6 (diff)
downloadzig-bc10131db11fad281163a53c4702873047cb9223.tar.gz
zig-bc10131db11fad281163a53c4702873047cb9223.zip
x86_64: rewrite scalar `@mulWithOverflow`
Closes #19607
Diffstat (limited to 'test/behavior/math.zig')
-rw-r--r--test/behavior/math.zig15
1 files changed, 12 insertions, 3 deletions
diff --git a/test/behavior/math.zig b/test/behavior/math.zig
index 76c55c2549..f68d446bc5 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 {