| ... | ... | @@ -71,6 +71,12 @@ const Sha256Params = Sha2Params32{ |
| 71 | 71 | |
| 72 | 72 | const v4u32 = @Vector(4, u32); |
| 73 | 73 | |
| 74 | // TODO: Remove once https://github.com/ziglang/zig/issues/868 is resolved. |
| 75 | fn isComptime() bool { |
| 76 | var a: u8 = 0; |
| 77 | return @typeInfo(@TypeOf(.{a})).Struct.fields[0].is_comptime; |
| 78 | } |
| 79 | |
| 74 | 80 | /// SHA-224 |
| 75 | 81 | pub const Sha224 = Sha2x32(Sha224Params); |
| 76 | 82 | |
| ... | ... | @@ -187,7 +193,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { |
| 187 | 193 | } |
| 188 | 194 | |
| 189 | 195 | switch (builtin.cpu.arch) { |
| 190 | | .aarch64 => if (comptime builtin.cpu.features.isEnabled(@enumToInt(std.Target.aarch64.Feature.sha2))) { |
| 196 | .aarch64 => if (!isComptime() and comptime builtin.cpu.features.isEnabled(@enumToInt(std.Target.aarch64.Feature.sha2))) { |
| 191 | 197 | var x: v4u32 = d.s[0..4].*; |
| 192 | 198 | var y: v4u32 = d.s[4..8].*; |
| 193 | 199 | const s_v = @ptrCast(*[16]v4u32, &s); |
| ... | ... | @@ -224,7 +230,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { |
| 224 | 230 | d.s[4..8].* = y +% @as(v4u32, d.s[4..8].*); |
| 225 | 231 | return; |
| 226 | 232 | }, |
| 227 | | .x86_64 => if (comptime builtin.cpu.features.isEnabled(@enumToInt(std.Target.x86.Feature.sha))) { |
| 233 | .x86_64 => if (!isComptime() and comptime builtin.cpu.features.isEnabled(@enumToInt(std.Target.x86.Feature.sha))) { |
| 228 | 234 | var x: v4u32 = [_]u32{ d.s[5], d.s[4], d.s[1], d.s[0] }; |
| 229 | 235 | var y: v4u32 = [_]u32{ d.s[7], d.s[6], d.s[3], d.s[2] }; |
| 230 | 236 | const s_v = @ptrCast(*[16]v4u32, &s); |