| ... | @@ -251,31 +251,61 @@ test "atomicrmw with ints" { | ... | @@ -251,31 +251,61 @@ test "atomicrmw with ints" { |
| 251 | return error.SkipZigTest; | 251 | return error.SkipZigTest; |
| 252 | } | 252 | } |
| 253 | | 253 | |
| 254 | try testAtomicRmwInt(); | 254 | // TODO: https://github.com/ziglang/zig/issues/13989 |
| 255 | comptime try testAtomicRmwInt(); | 255 | const bit_values = [_]usize{ 8, 16, 32, 64 };// ++ if (builtin.zig_backend != .stage2_c) [_]usize{ } else [_]usize{ 128 }; |
| | 256 | inline for (bit_values) |bits| { |
| | 257 | try testAtomicRmwInt(.unsigned, bits); |
| | 258 | comptime try testAtomicRmwInt(.unsigned, bits); |
| | 259 | } |
| 256 | } | 260 | } |
| 257 | | 261 | |
| 258 | fn testAtomicRmwInt() !void { | 262 | fn testAtomicRmwInt(comptime signedness: std.builtin.Signedness, comptime N: usize) !void { |
| 259 | var x: u8 = 1; | 263 | const int = std.meta.Int(signedness, N); |
| 260 | var res = @atomicRmw(u8, &x, .Xchg, 3, .SeqCst); | 264 | |
| | 265 | var x: int = 1; |
| | 266 | var res = @atomicRmw(int, &x, .Xchg, 3, .SeqCst); |
| 261 | try expect(x == 3 and res == 1); | 267 | try expect(x == 3 and res == 1); |
| 262 | _ = @atomicRmw(u8, &x, .Add, 3, .SeqCst); | 268 | |
| 263 | try expect(x == 6); | 269 | res = @atomicRmw(int, &x, .Add, 3, .SeqCst); |
| 264 | _ = @atomicRmw(u8, &x, .Sub, 1, .SeqCst); | 270 | var y: int = 3; |
| 265 | try expect(x == 5); | 271 | try expect(res == y); |
| 266 | _ = @atomicRmw(u8, &x, .And, 4, .SeqCst); | 272 | y = y + 3; |
| 267 | try expect(x == 4); | 273 | try expect(x == y); |
| 268 | _ = @atomicRmw(u8, &x, .Nand, 4, .SeqCst); | 274 | |
| 269 | try expect(x == 0xfb); | 275 | res = @atomicRmw(int, &x, .Sub, 1, .SeqCst); |
| 270 | _ = @atomicRmw(u8, &x, .Or, 6, .SeqCst); | 276 | try expect(res == y); |
| 271 | try expect(x == 0xff); | 277 | y = y - 1; |
| 272 | _ = @atomicRmw(u8, &x, .Xor, 2, .SeqCst); | 278 | try expect(x == y); |
| 273 | try expect(x == 0xfd); | 279 | |
| 274 | | 280 | res = @atomicRmw(int, &x, .And, 4, .SeqCst); |
| 275 | _ = @atomicRmw(u8, &x, .Max, 1, .SeqCst); | 281 | try expect(res == y); |
| 276 | try expect(x == 0xfd); | 282 | y = y & 4; |
| 277 | _ = @atomicRmw(u8, &x, .Min, 1, .SeqCst); | 283 | try expect(x == y); |
| 278 | try expect(x == 1); | 284 | |
| | 285 | res = @atomicRmw(int, &x, .Nand, 4, .SeqCst); |
| | 286 | try expect(res == y); |
| | 287 | y = ~(y & 4); |
| | 288 | try expect(x == y); |
| | 289 | |
| | 290 | res = @atomicRmw(int, &x, .Or, 6, .SeqCst); |
| | 291 | try expect(res == y); |
| | 292 | y = y | 6; |
| | 293 | try expect(x == y); |
| | 294 | |
| | 295 | res = @atomicRmw(int, &x, .Xor, 2, .SeqCst); |
| | 296 | try expect(res == y); |
| | 297 | y = y ^ 2; |
| | 298 | try expect(x == y); |
| | 299 | |
| | 300 | res = @atomicRmw(int, &x, .Max, 1, .SeqCst); |
| | 301 | try expect(res == y); |
| | 302 | y = @max(y, 1); |
| | 303 | try expect(x == y); |
| | 304 | |
| | 305 | res = @atomicRmw(int, &x, .Min, 1, .SeqCst); |
| | 306 | try expect(res == y); |
| | 307 | y = @min(y, 1); |
| | 308 | try expect(x == y); |
| 279 | } | 309 | } |
| 280 | | 310 | |
| 281 | test "atomics with different types" { | 311 | test "atomics with different types" { |