From b27809517b26089ad3359c1212caf9c3ffbf247d Mon Sep 17 00:00:00 2001 From: Taylan Kammer Date: Wed, 10 Jun 2026 15:49:31 +0200 Subject: NaN-packing changes for interpreter. --- src/test/values.zig | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/test') diff --git a/src/test/values.zig b/src/test/values.zig index 968a5bc..a276b2e 100644 --- a/src/test/values.zig +++ b/src/test/values.zig @@ -42,6 +42,29 @@ test "fixnum" { try testing.expectEqual(int1 + int2, result); } +test "snan" { + // Can speculative execution screw up sNaN handling? + const v1 = value.fixnum.pack(1234); + const v2 = value.fixnum.pack(1234); + + // Even executing this unconditionally doesn't seem to cause issues on my + // machine, so it's not clear how to best test this. + //const f = v1.double + v2.double; + //std.debug.print("oh no! {}\n", .{f}); + + if (v1.isDouble() and v2.isDouble()) { + @branchHint(.likely); + // This actually doesn't even cause any issues if you execute it + // unconditionally. It just prints the NaN value. + const fl = v1.double + v2.double; + std.debug.print("oh no! {}\n", .{fl}); + } else { + @branchHint(.cold); + const v3 = value.fixnum.add(v1, v2); + try testing.expectEqual(value.fixnum.unpack(v3), 2468); + } +} + test "ptr" { const ptr = value.ptr; -- cgit v1.2.3