| ... | @@ -693,7 +693,7 @@ test shr { | ... | @@ -693,7 +693,7 @@ test shr { |
| 693 | pub fn rotr(comptime T: type, x: T, r: anytype) T { | 693 | pub fn rotr(comptime T: type, x: T, r: anytype) T { |
| 694 | if (@typeInfo(T) == .vector) { | 694 | if (@typeInfo(T) == .vector) { |
| 695 | const C = @typeInfo(T).vector.child; | 695 | const C = @typeInfo(T).vector.child; |
| 696 | if (C == u0) return 0; | 696 | if (C == u0) return @splat(0); |
| 697 | | 697 | |
| 698 | if (@typeInfo(C).int.signedness == .signed) { | 698 | if (@typeInfo(C).int.signedness == .signed) { |
| 699 | @compileError("cannot rotate signed integers"); | 699 | @compileError("cannot rotate signed integers"); |
| ... | @@ -725,8 +725,10 @@ test rotr { | ... | @@ -725,8 +725,10 @@ test rotr { |
| 725 | try testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000); | 725 | try testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000); |
| 726 | try testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010); | 726 | try testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010); |
| 727 | try testing.expect(rotr(u12, 0o7777, 1) == 0o7777); | 727 | try testing.expect(rotr(u12, 0o7777, 1) == 0o7777); |
| 728 | try testing.expect(rotr(@Vector(1, u32), @Vector(1, u32){1}, @as(usize, 1))[0] == @as(u32, 1) << 31); | 728 | try testing.expect(rotr(@Vector(1, u32), .{1}, @as(usize, 1))[0] == @as(u32, 1) << 31); |
| 729 | try testing.expect(rotr(@Vector(1, u32), @Vector(1, u32){1}, @as(isize, -1))[0] == @as(u32, 1) << 1); | 729 | try testing.expect(rotr(@Vector(1, u32), .{1}, @as(isize, -1))[0] == @as(u32, 1) << 1); |
| | 730 | try std.testing.expect(@reduce(.And, rotr(@Vector(2, u0), .{ 0, 0 }, @as(usize, 42)) == |
| | 731 | @Vector(2, u0){ 0, 0 })); |
| 730 | } | 732 | } |
| 731 | | 733 | |
| 732 | /// Rotates left. Only unsigned values can be rotated. Negative shift | 734 | /// Rotates left. Only unsigned values can be rotated. Negative shift |
| ... | @@ -734,7 +736,7 @@ test rotr { | ... | @@ -734,7 +736,7 @@ test rotr { |
| 734 | pub fn rotl(comptime T: type, x: T, r: anytype) T { | 736 | pub fn rotl(comptime T: type, x: T, r: anytype) T { |
| 735 | if (@typeInfo(T) == .vector) { | 737 | if (@typeInfo(T) == .vector) { |
| 736 | const C = @typeInfo(T).vector.child; | 738 | const C = @typeInfo(T).vector.child; |
| 737 | if (C == u0) return 0; | 739 | if (C == u0) return @splat(0); |
| 738 | | 740 | |
| 739 | if (@typeInfo(C).int.signedness == .signed) { | 741 | if (@typeInfo(C).int.signedness == .signed) { |
| 740 | @compileError("cannot rotate signed integers"); | 742 | @compileError("cannot rotate signed integers"); |
| ... | @@ -766,8 +768,10 @@ test rotl { | ... | @@ -766,8 +768,10 @@ test rotl { |
| 766 | try testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000); | 768 | try testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000); |
| 767 | try testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000); | 769 | try testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000); |
| 768 | try testing.expect(rotl(u12, 0o7777, 1) == 0o7777); | 770 | try testing.expect(rotl(u12, 0o7777, 1) == 0o7777); |
| 769 | try testing.expect(rotl(@Vector(1, u32), @Vector(1, u32){1 << 31}, @as(usize, 1))[0] == 1); | 771 | try testing.expect(rotl(@Vector(1, u32), .{1 << 31}, @as(usize, 1))[0] == 1); |
| 770 | try testing.expect(rotl(@Vector(1, u32), @Vector(1, u32){1 << 31}, @as(isize, -1))[0] == @as(u32, 1) << 30); | 772 | try testing.expect(rotl(@Vector(1, u32), .{1 << 31}, @as(isize, -1))[0] == @as(u32, 1) << 30); |
| | 773 | try std.testing.expect(@reduce(.And, rotl(@Vector(2, u0), .{ 0, 0 }, @as(usize, 42)) == |
| | 774 | @Vector(2, u0){ 0, 0 })); |
| 771 | } | 775 | } |
| 772 | | 776 | |
| 773 | /// Returns an unsigned int type that can hold the number of bits in T - 1. | 777 | /// Returns an unsigned int type that can hold the number of bits in T - 1. |