| ... | ... | @@ -48,7 +48,14 @@ pub const State = struct { |
| 48 | 48 | return mem.asBytes(&self.data); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | inline fn endianSwap(self: *Self) void { |
| 52 | for (self.data) |*w| { |
| 53 | w.* = mem.littleToNative(u32, w.*); |
| 54 | } |
| 55 | } |
| 56 | |
| 51 | 57 | fn permute_unrolled(self: *Self) void { |
| 58 | self.endianSwap(); |
| 52 | 59 | const state = &self.data; |
| 53 | 60 | comptime var round = @as(u32, 24); |
| 54 | 61 | inline while (round > 0) : (round -= 1) { |
| ... | ... | @@ -74,9 +81,11 @@ pub const State = struct { |
| 74 | 81 | else => {}, |
| 75 | 82 | } |
| 76 | 83 | } |
| 84 | self.endianSwap(); |
| 77 | 85 | } |
| 78 | 86 | |
| 79 | 87 | fn permute_small(self: *Self) void { |
| 88 | self.endianSwap(); |
| 80 | 89 | const state = &self.data; |
| 81 | 90 | var round = @as(u32, 24); |
| 82 | 91 | while (round > 0) : (round -= 1) { |
| ... | ... | @@ -102,6 +111,7 @@ pub const State = struct { |
| 102 | 111 | else => {}, |
| 103 | 112 | } |
| 104 | 113 | } |
| 114 | self.endianSwap(); |
| 105 | 115 | } |
| 106 | 116 | |
| 107 | 117 | const Lane = Vector(4, u32); |
| ... | ... | @@ -115,6 +125,7 @@ pub const State = struct { |
| 115 | 125 | } |
| 116 | 126 | |
| 117 | 127 | fn permute_vectorized(self: *Self) void { |
| 128 | self.endianSwap(); |
| 118 | 129 | const state = &self.data; |
| 119 | 130 | var x = Lane{ state[0], state[1], state[2], state[3] }; |
| 120 | 131 | var y = Lane{ state[4], state[5], state[6], state[7] }; |
| ... | ... | @@ -146,6 +157,7 @@ pub const State = struct { |
| 146 | 157 | state[4 + i] = y[i]; |
| 147 | 158 | state[8 + i] = z[i]; |
| 148 | 159 | } |
| 160 | self.endianSwap(); |
| 149 | 161 | } |
| 150 | 162 | |
| 151 | 163 | pub const permute = if (std.Target.current.cpu.arch == .x86_64) impl: { |