authorgravatar for fncontroloption@noreply.codeberg.orgFnControlOption <fncontroloption@noreply.codeberg.org> 2021-08-08 09:21:30-07:00
committergravatar for fncontroloption@noreply.codeberg.orgFnControlOption <fncontroloption@noreply.codeberg.org> 2021-08-08 09:21:30-07:00
logf91782c6d1f7a8ef1ee3196147bb33c9e1ac059d
treea8b5e2446193e8f57e32fafd4663b0c1246052ac
parentd19e1709b315d03d32138211140108308e540e3e

Skip 128-bit cmpxchg test if CMPXCHG16B is not supported


1 files changed, 22 insertions(+), 14 deletions(-)

test/behavior/atomics.zig+22-14
......@@ -75,20 +75,28 @@ test "cmpxchg with ptr" {
7575}
7676
7777test "128-bit cmpxchg" {
78 var x: u128 = 1234;
79 if (@cmpxchgWeak(u128, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| {
80 try expect(x1 == 1234);
81 } else {
82 @panic("cmpxchg should have failed");
83 }
84
85 while (@cmpxchgWeak(u128, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| {
86 try expect(x1 == 1234);
87 }
88 try expect(x == 5678);
89
90 try expect(@cmpxchgStrong(u128, &x, 5678, 42, .SeqCst, .SeqCst) == null);
91 try expect(x == 42);
78 try test_u128_cmpxchg();
79 comptime try test_u128_cmpxchg();
80}
81
82fn test_u128_cmpxchg() !void {
83 if (std.Target.current.cpu.arch != .x86_64) return error.SkipZigTest;
84 if (comptime !std.Target.x86.featureSetHas(std.Target.current.cpu.features, .cx16)) return error.SkipZigTest;
85
86 var x: u128 = 1234;
87 if (@cmpxchgWeak(u128, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| {
88 try expect(x1 == 1234);
89 } else {
90 @panic("cmpxchg should have failed");
91 }
92
93 while (@cmpxchgWeak(u128, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| {
94 try expect(x1 == 1234);
95 }
96 try expect(x == 5678);
97
98 try expect(@cmpxchgStrong(u128, &x, 5678, 42, .SeqCst, .SeqCst) == null);
99 try expect(x == 42);
92100}
93101
94102test "cmpxchg with ignored result" {