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