| ... | @@ -75,20 +75,28 @@ test "cmpxchg with ptr" { | ... | @@ -75,20 +75,28 @@ test "cmpxchg with ptr" { |
| 75 | } | 75 | } |
| 76 | | 76 | |
| 77 | test "128-bit cmpxchg" { | 77 | test "128-bit cmpxchg" { |
| 78 | var x: u128 = 1234; | 78 | try test_u128_cmpxchg(); |
| 79 | if (@cmpxchgWeak(u128, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| { | 79 | comptime try test_u128_cmpxchg(); |
| 80 | try expect(x1 == 1234); | 80 | } |
| 81 | } else { | 81 | |
| 82 | @panic("cmpxchg should have failed"); | 82 | fn test_u128_cmpxchg() !void { |
| 83 | } | 83 | if (std.Target.current.cpu.arch != .x86_64) return error.SkipZigTest; |
| 84 | | 84 | if (comptime !std.Target.x86.featureSetHas(std.Target.current.cpu.features, .cx16)) return error.SkipZigTest; |
| 85 | while (@cmpxchgWeak(u128, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| { | 85 | |
| 86 | try expect(x1 == 1234); | 86 | var x: u128 = 1234; |
| 87 | } | 87 | if (@cmpxchgWeak(u128, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| { |
| 88 | try expect(x == 5678); | 88 | try expect(x1 == 1234); |
| 89 | | 89 | } else { |
| 90 | try expect(@cmpxchgStrong(u128, &x, 5678, 42, .SeqCst, .SeqCst) == null); | 90 | @panic("cmpxchg should have failed"); |
| 91 | try expect(x == 42); | 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); |
| 92 | } | 100 | } |
| 93 | | 101 | |
| 94 | test "cmpxchg with ignored result" { | 102 | test "cmpxchg with ignored result" { |