From a52dcdd3c5ebd3a1d5a0189ded830dadd253193c Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Tue, 20 Dec 2022 21:31:44 -0500 Subject: CBE: fix bitwise not Closes #13911 --- test/behavior/math.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/behavior/math.zig') diff --git a/test/behavior/math.zig b/test/behavior/math.zig index d819743390..763c249c50 100644 --- a/test/behavior/math.zig +++ b/test/behavior/math.zig @@ -532,6 +532,19 @@ fn testUnsignedNegationWrappingEval(x: u16) !void { try expect(neg == maxInt(u16)); } +test "negation wrapping" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO + + try expectEqual(@as(u1, 1), negateWrap(u1, 1)); +} + +fn negateWrap(comptime T: type, x: T) T { + // This is specifically testing a safety-checked add, so + // special case minInt(T) which would overflow otherwise. + return if (x == minInt(T)) minInt(T) else ~x + 1; +} + test "unsigned 64-bit division" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO -- cgit v1.2.3