From f695a215ad84607a2df8f31f2138918926eb3f0c Mon Sep 17 00:00:00 2001 From: riperiperi Date: Wed, 25 Mar 2020 06:20:29 +0000 Subject: Add Fast Paths for Crypto instructions (A32/A64) (#1026) * Add Fast Paths for Crypto instructions (A32/A64) * Replace additional XOR with passing in const zero. --- ARMeilleure/Instructions/InstEmitSimdCrypto32.cs | 54 ++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 4 deletions(-) (limited to 'ARMeilleure/Instructions/InstEmitSimdCrypto32.cs') diff --git a/ARMeilleure/Instructions/InstEmitSimdCrypto32.cs b/ARMeilleure/Instructions/InstEmitSimdCrypto32.cs index 1cfce3ad..f62fd307 100644 --- a/ARMeilleure/Instructions/InstEmitSimdCrypto32.cs +++ b/ARMeilleure/Instructions/InstEmitSimdCrypto32.cs @@ -15,7 +15,17 @@ namespace ARMeilleure.Instructions Operand d = GetVecA32(op.Qd); Operand n = GetVecA32(op.Qm); - context.Copy(d, context.Call(new _V128_V128_V128(SoftFallback.Decrypt), d, n)); + Operand res; + if (Optimizations.UseAesni) + { + res = context.AddIntrinsic(Intrinsic.X86Aesdeclast, context.AddIntrinsic(Intrinsic.X86Xorpd, d, n), context.VectorZero()); + } + else + { + res = context.Call(new _V128_V128_V128(SoftFallback.Decrypt), d, n); + } + + context.Copy(d, res); } public static void Aese_V(ArmEmitterContext context) @@ -25,7 +35,17 @@ namespace ARMeilleure.Instructions Operand d = GetVecA32(op.Qd); Operand n = GetVecA32(op.Qm); - context.Copy(d, context.Call(new _V128_V128_V128(SoftFallback.Encrypt), d, n)); + Operand res; + if (Optimizations.UseAesni) + { + res = context.AddIntrinsic(Intrinsic.X86Aesenclast, context.AddIntrinsic(Intrinsic.X86Xorpd, d, n), context.VectorZero()); + } + else + { + res = context.Call(new _V128_V128_V128(SoftFallback.Encrypt), d, n); + } + + context.Copy(d, res); } public static void Aesimc_V(ArmEmitterContext context) @@ -34,7 +54,17 @@ namespace ARMeilleure.Instructions Operand n = GetVecA32(op.Qm); - context.Copy(GetVec(op.Qd), context.Call(new _V128_V128(SoftFallback.InverseMixColumns), n)); + Operand res; + if (Optimizations.UseAesni) + { + res = context.AddIntrinsic(Intrinsic.X86Aesimc, n); + } + else + { + res = context.Call(new _V128_V128(SoftFallback.InverseMixColumns), n); + } + + context.Copy(GetVecA32(op.Qd), res); } public static void Aesmc_V(ArmEmitterContext context) @@ -43,7 +73,23 @@ namespace ARMeilleure.Instructions Operand n = GetVecA32(op.Qm); - context.Copy(GetVec(op.Qd), context.Call(new _V128_V128(SoftFallback.MixColumns), n)); + Operand res; + if (Optimizations.UseAesni) + { + Operand roundKey = context.VectorZero(); + + // Inverse Shift Rows, Inverse Sub Bytes, xor 0 so nothing happens. + res = context.AddIntrinsic(Intrinsic.X86Aesdeclast, n, roundKey); + + // Shift Rows, Sub Bytes, Mix Columns (!), xor 0 so nothing happens. + res = context.AddIntrinsic(Intrinsic.X86Aesenc, res, roundKey); + } + else + { + res = context.Call(new _V128_V128(SoftFallback.MixColumns), n); + } + + context.Copy(GetVecA32(op.Qd), res); } } } -- cgit v1.2.3