authorgravatar for bratishkaerik@getgoogleoff.meEric Joldasov <bratishkaerik@getgoogleoff.me> 2023-06-14 17:22:43+06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-14 18:25:56-07:00
log610b02c432072c85f079f3ddf315cb864aa5dbf5
tree833383b2af44cfc1d485f14215590107d68d7924
parentb975701a4d98f2bf124fd4e66ca57e337827ec5a

std.atomic.Atomic: update tests to new for-loop syntax, re-enable test with isel

Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>

1 files changed, 6 insertions(+), 13 deletions(-)

lib/std/atomic/Atomic.zig+6-13
...@@ -374,10 +374,6 @@ const atomic_rmw_orderings = [_]Ordering{...@@ -374,10 +374,6 @@ const atomic_rmw_orderings = [_]Ordering{
374};374};
375375
376test "Atomic.swap" {376test "Atomic.swap" {
377 // TODO: Re-enable when LLVM is released with a bugfix for isel of
378 // atomic load (currently fixed on trunk, broken on 15.0.2)
379 if (builtin.cpu.arch == .powerpc64le) return error.SkipZigTest;
380
381 inline for (atomic_rmw_orderings) |ordering| {377 inline for (atomic_rmw_orderings) |ordering| {
382 var x = Atomic(usize).init(5);378 var x = Atomic(usize).init(5);
383 try testing.expectEqual(x.swap(10, ordering), 5);379 try testing.expectEqual(x.swap(10, ordering), 5);
...@@ -546,9 +542,8 @@ test "Atomic.bitSet" {...@@ -546,9 +542,8 @@ test "Atomic.bitSet" {
546 inline for (atomicIntTypes()) |Int| {542 inline for (atomicIntTypes()) |Int| {
547 inline for (atomic_rmw_orderings) |ordering| {543 inline for (atomic_rmw_orderings) |ordering| {
548 var x = Atomic(Int).init(0);544 var x = Atomic(Int).init(0);
549 const bit_array = @as([@bitSizeOf(Int)]void, undefined);
550545
551 for (bit_array, 0..) |_, bit_index| {546 for (0..@bitSizeOf(Int)) |bit_index| {
552 const bit = @intCast(std.math.Log2Int(Int), bit_index);547 const bit = @intCast(std.math.Log2Int(Int), bit_index);
553 const mask = @as(Int, 1) << bit;548 const mask = @as(Int, 1) << bit;
554549
...@@ -562,7 +557,7 @@ test "Atomic.bitSet" {...@@ -562,7 +557,7 @@ test "Atomic.bitSet" {
562 try testing.expect(x.load(.SeqCst) & mask != 0);557 try testing.expect(x.load(.SeqCst) & mask != 0);
563558
564 // all the previous bits should have not changed (still be set)559 // all the previous bits should have not changed (still be set)
565 for (bit_array[0..bit_index], 0..) |_, prev_bit_index| {560 for (0..bit_index) |prev_bit_index| {
566 const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index);561 const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index);
567 const prev_mask = @as(Int, 1) << prev_bit;562 const prev_mask = @as(Int, 1) << prev_bit;
568 try testing.expect(x.load(.SeqCst) & prev_mask != 0);563 try testing.expect(x.load(.SeqCst) & prev_mask != 0);
...@@ -576,9 +571,8 @@ test "Atomic.bitReset" {...@@ -576,9 +571,8 @@ test "Atomic.bitReset" {
576 inline for (atomicIntTypes()) |Int| {571 inline for (atomicIntTypes()) |Int| {
577 inline for (atomic_rmw_orderings) |ordering| {572 inline for (atomic_rmw_orderings) |ordering| {
578 var x = Atomic(Int).init(0);573 var x = Atomic(Int).init(0);
579 const bit_array = @as([@bitSizeOf(Int)]void, undefined);
580574
581 for (bit_array, 0..) |_, bit_index| {575 for (0..@bitSizeOf(Int)) |bit_index| {
582 const bit = @intCast(std.math.Log2Int(Int), bit_index);576 const bit = @intCast(std.math.Log2Int(Int), bit_index);
583 const mask = @as(Int, 1) << bit;577 const mask = @as(Int, 1) << bit;
584 x.storeUnchecked(x.loadUnchecked() | mask);578 x.storeUnchecked(x.loadUnchecked() | mask);
...@@ -593,7 +587,7 @@ test "Atomic.bitReset" {...@@ -593,7 +587,7 @@ test "Atomic.bitReset" {
593 try testing.expect(x.load(.SeqCst) & mask == 0);587 try testing.expect(x.load(.SeqCst) & mask == 0);
594588
595 // all the previous bits should have not changed (still be reset)589 // all the previous bits should have not changed (still be reset)
596 for (bit_array[0..bit_index], 0..) |_, prev_bit_index| {590 for (0..bit_index) |prev_bit_index| {
597 const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index);591 const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index);
598 const prev_mask = @as(Int, 1) << prev_bit;592 const prev_mask = @as(Int, 1) << prev_bit;
599 try testing.expect(x.load(.SeqCst) & prev_mask == 0);593 try testing.expect(x.load(.SeqCst) & prev_mask == 0);
...@@ -607,9 +601,8 @@ test "Atomic.bitToggle" {...@@ -607,9 +601,8 @@ test "Atomic.bitToggle" {
607 inline for (atomicIntTypes()) |Int| {601 inline for (atomicIntTypes()) |Int| {
608 inline for (atomic_rmw_orderings) |ordering| {602 inline for (atomic_rmw_orderings) |ordering| {
609 var x = Atomic(Int).init(0);603 var x = Atomic(Int).init(0);
610 const bit_array = @as([@bitSizeOf(Int)]void, undefined);
611604
612 for (bit_array, 0..) |_, bit_index| {605 for (0..@bitSizeOf(Int)) |bit_index| {
613 const bit = @intCast(std.math.Log2Int(Int), bit_index);606 const bit = @intCast(std.math.Log2Int(Int), bit_index);
614 const mask = @as(Int, 1) << bit;607 const mask = @as(Int, 1) << bit;
615608
...@@ -623,7 +616,7 @@ test "Atomic.bitToggle" {...@@ -623,7 +616,7 @@ test "Atomic.bitToggle" {
623 try testing.expect(x.load(.SeqCst) & mask == 0);616 try testing.expect(x.load(.SeqCst) & mask == 0);
624617
625 // all the previous bits should have not changed (still be toggled back)618 // all the previous bits should have not changed (still be toggled back)
626 for (bit_array[0..bit_index], 0..) |_, prev_bit_index| {619 for (0..bit_index) |prev_bit_index| {
627 const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index);620 const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index);
628 const prev_mask = @as(Int, 1) << prev_bit;621 const prev_mask = @as(Int, 1) << prev_bit;
629 try testing.expect(x.load(.SeqCst) & prev_mask == 0);622 try testing.expect(x.load(.SeqCst) & prev_mask == 0);