| ... | @@ -251,8 +251,7 @@ test "atomicrmw with ints" { | ... | @@ -251,8 +251,7 @@ test "atomicrmw with ints" { |
| 251 | return error.SkipZigTest; | 251 | return error.SkipZigTest; |
| 252 | } | 252 | } |
| 253 | | 253 | |
| 254 | // TODO: https://github.com/ziglang/zig/issues/13989 | 254 | const bit_values = [_]usize{ 8, 16, 32, 64 }; |
| 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| { | 255 | inline for (bit_values) |bits| { |
| 257 | try testAtomicRmwInt(.unsigned, bits); | 256 | try testAtomicRmwInt(.unsigned, bits); |
| 258 | comptime try testAtomicRmwInt(.unsigned, bits); | 257 | comptime try testAtomicRmwInt(.unsigned, bits); |
| ... | @@ -308,6 +307,80 @@ fn testAtomicRmwInt(comptime signedness: std.builtin.Signedness, comptime N: usi | ... | @@ -308,6 +307,80 @@ fn testAtomicRmwInt(comptime signedness: std.builtin.Signedness, comptime N: usi |
| 308 | try expect(x == y); | 307 | try expect(x == y); |
| 309 | } | 308 | } |
| 310 | | 309 | |
| | 310 | test "atomicrmw with 128-bit ints" { |
| | 311 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| | 312 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| | 313 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| | 314 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| | 315 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| | 316 | |
| | 317 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch == .aarch64) { |
| | 318 | return error.SkipZigTest; |
| | 319 | } |
| | 320 | |
| | 321 | try testAtomicRmwInt128(.unsigned); |
| | 322 | comptime try testAtomicRmwInt128(.unsigned); |
| | 323 | } |
| | 324 | |
| | 325 | fn testAtomicRmwInt128(comptime signedness: std.builtin.Signedness) !void { |
| | 326 | const int = std.meta.Int(signedness, 128); |
| | 327 | |
| | 328 | const initial: int = 0xaaaaaaaa_bbbbbbbb_cccccccc_dddddddd; |
| | 329 | const replacement: int = 0x00000000_00000005_00000000_00000003; |
| | 330 | |
| | 331 | var x: int align(16) = initial; |
| | 332 | var res = @atomicRmw(int, &x, .Xchg, replacement, .SeqCst); |
| | 333 | try expect(x == replacement and res == initial); |
| | 334 | |
| | 335 | var operator: int = 0x00000001_00000000_20000000_00000000; |
| | 336 | res = @atomicRmw(int, &x, .Add, operator, .SeqCst); |
| | 337 | var y: int = replacement; |
| | 338 | try expect(res == y); |
| | 339 | y = y + operator; |
| | 340 | try expect(x == y); |
| | 341 | |
| | 342 | operator = 0x00000000_10000000_00000000_20000000; |
| | 343 | res = @atomicRmw(int, &x, .Sub, operator, .SeqCst); |
| | 344 | try expect(res == y); |
| | 345 | y = y - operator; |
| | 346 | try expect(x == y); |
| | 347 | |
| | 348 | operator = 0x12345678_87654321_12345678_87654321; |
| | 349 | res = @atomicRmw(int, &x, .And, operator, .SeqCst); |
| | 350 | try expect(res == y); |
| | 351 | y = y & operator; |
| | 352 | try expect(x == y); |
| | 353 | |
| | 354 | operator = 0x00000000_10000000_00000000_20000000; |
| | 355 | res = @atomicRmw(int, &x, .Nand, operator, .SeqCst); |
| | 356 | try expect(res == y); |
| | 357 | y = ~(y & operator); |
| | 358 | try expect(x == y); |
| | 359 | |
| | 360 | operator = 0x12340000_56780000_67890000_98760000; |
| | 361 | res = @atomicRmw(int, &x, .Or, operator, .SeqCst); |
| | 362 | try expect(res == y); |
| | 363 | y = y | operator; |
| | 364 | try expect(x == y); |
| | 365 | |
| | 366 | operator = 0x0a0b0c0d_0e0f0102_03040506_0708090a; |
| | 367 | res = @atomicRmw(int, &x, .Xor, operator, .SeqCst); |
| | 368 | try expect(res == y); |
| | 369 | y = y ^ operator; |
| | 370 | try expect(x == y); |
| | 371 | |
| | 372 | operator = 0x00000000_10000000_00000000_20000000; |
| | 373 | res = @atomicRmw(int, &x, .Max, operator, .SeqCst); |
| | 374 | try expect(res == y); |
| | 375 | y = @max(y, operator); |
| | 376 | try expect(x == y); |
| | 377 | |
| | 378 | res = @atomicRmw(int, &x, .Min, operator, .SeqCst); |
| | 379 | try expect(res == y); |
| | 380 | y = @min(y, operator); |
| | 381 | try expect(x == y); |
| | 382 | } |
| | 383 | |
| 311 | test "atomics with different types" { | 384 | test "atomics with different types" { |
| 312 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | 385 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 313 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 386 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |