aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorFrank Denis <github@pureftpd.org>2020-10-02 21:16:18 +0200
committerAndrew Kelley <andrew@ziglang.org>2020-10-08 18:09:23 -0400
commit1bc2b68916a193975af8d8f4d648a8df9bdb5593 (patch)
tree4040948c0848d287d859e8fe629a7b3dd6d609e2 /lib/std
parent83eda214882e33e65794cee1e7c0d87777b31bf4 (diff)
downloadzig-1bc2b68916a193975af8d8f4d648a8df9bdb5593.tar.gz
zig-1bc2b68916a193975af8d8f4d648a8df9bdb5593.zip
ghash: add pmull support on aarch64
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/crypto/ghash.zig20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/std/crypto/ghash.zig b/lib/std/crypto/ghash.zig
index 04bc6a8275..83446f280b 100644
--- a/lib/std/crypto/ghash.zig
+++ b/lib/std/crypto/ghash.zig
@@ -105,6 +105,17 @@ pub const Ghash = struct {
return product[0];
}
+ inline fn clmul_pmull(x: u64, y: u64) u64 {
+ const Vector = std.meta.Vector;
+ const product = asm (
+ \\ pmull %[out].1q, %[x].1d, %[y].1d
+ : [out] "=w" (-> Vector(2, u64))
+ : [x] "w" (@bitCast(Vector(2, u64), @as(u128, x))),
+ [y] "w" (@bitCast(Vector(2, u64), @as(u128, y)))
+ );
+ return product[0];
+ }
+
fn clmul_soft(x: u64, y: u64) u64 {
const x0 = x & 0x1111111111111111;
const x1 = x & 0x2222222222222222;
@@ -127,7 +138,14 @@ pub const Ghash = struct {
const has_pclmul = comptime std.Target.x86.featureSetHas(std.Target.current.cpu.features, .pclmul);
const has_avx = comptime std.Target.x86.featureSetHas(std.Target.current.cpu.features, .avx);
- const clmul = if (std.Target.current.cpu.arch == .x86_64 and has_pclmul and has_avx) clmul_pclmul else clmul_soft;
+ const has_armaes = comptime std.Target.aarch64.featureSetHas(std.Target.current.cpu.features, .aes);
+ const clmul = if (std.Target.current.cpu.arch == .x86_64 and has_pclmul and has_avx) impl: {
+ break :impl clmul_pclmul;
+ } else if (std.Target.current.cpu.arch == .aarch64 and has_armaes) impl: {
+ break :impl clmul_pmull;
+ } else impl: {
+ break :impl clmul_soft;
+ };
fn blocks(st: *Ghash, msg: []const u8) void {
assert(msg.len % 16 == 0); // GHASH blocks() expects full blocks