zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 394d287778971c3d06fc401e688fc048cdf9860a (tree)
parent f49aa960a93b401b8e33292cf37a0de1eec312c0
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Thu, 12 Aug 2021 16:42:37 +0200

Merge pull request #9535 from FnControlOption/128-bit-cmpxchg-test

Re-enable 128-bit cmpxchg test
Diffstat:
Mtest/behavior/atomics.zig | 44++++++++++++++++++++++++--------------------
1 file changed, 24 insertions(+), 20 deletions(-)

diff --git a/test/behavior/atomics.zig b/test/behavior/atomics.zig @@ -74,26 +74,30 @@ test "cmpxchg with ptr" { try expect(x == &data2); } -// TODO this test is disabled until this issue is resolved: -// https://github.com/ziglang/zig/issues/2883 -// otherwise cross compiling will result in: -// lld: error: undefined symbol: __sync_val_compare_and_swap_16 -//test "128-bit cmpxchg" { -// var x: u128 align(16) = 1234; // TODO: https://github.com/ziglang/zig/issues/2987 -// if (@cmpxchgWeak(u128, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| { -// try expect(x1 == 1234); -// } else { -// @panic("cmpxchg should have failed"); -// } -// -// while (@cmpxchgWeak(u128, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| { -// try expect(x1 == 1234); -// } -// try expect(x == 5678); -// -// try expect(@cmpxchgStrong(u128, &x, 5678, 42, .SeqCst, .SeqCst) == null); -// try expect(x == 42); -//} +test "128-bit cmpxchg" { + try test_u128_cmpxchg(); + comptime try test_u128_cmpxchg(); +} + +fn test_u128_cmpxchg() !void { + if (std.Target.current.cpu.arch != .x86_64) return error.SkipZigTest; + if (comptime !std.Target.x86.featureSetHas(std.Target.current.cpu.features, .cx16)) return error.SkipZigTest; + + var x: u128 = 1234; + if (@cmpxchgWeak(u128, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| { + try expect(x1 == 1234); + } else { + @panic("cmpxchg should have failed"); + } + + while (@cmpxchgWeak(u128, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| { + try expect(x1 == 1234); + } + try expect(x == 5678); + + try expect(@cmpxchgStrong(u128, &x, 5678, 42, .SeqCst, .SeqCst) == null); + try expect(x == 42); +} test "cmpxchg with ignored result" { var x: i32 = 1234;