aboutsummaryrefslogtreecommitdiff
path: root/ARMeilleure/Instructions
diff options
context:
space:
mode:
authorriperiperi <rhy3756547@hotmail.com>2020-03-25 06:20:29 +0000
committerGitHub <noreply@github.com>2020-03-25 17:20:29 +1100
commitf695a215ad84607a2df8f31f2138918926eb3f0c (patch)
tree0dac9798da61e20fb984e81745b3ce195058bb93 /ARMeilleure/Instructions
parenta40d8d4a174ae9ec7c2900b7064625a366ae14ad (diff)
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.
Diffstat (limited to 'ARMeilleure/Instructions')
-rw-r--r--ARMeilleure/Instructions/InstEmitSimdCrypto.cs54
-rw-r--r--ARMeilleure/Instructions/InstEmitSimdCrypto32.cs54
2 files changed, 100 insertions, 8 deletions
diff --git a/ARMeilleure/Instructions/InstEmitSimdCrypto.cs b/ARMeilleure/Instructions/InstEmitSimdCrypto.cs
index 2b61fada..5b470567 100644
--- a/ARMeilleure/Instructions/InstEmitSimdCrypto.cs
+++ b/ARMeilleure/Instructions/InstEmitSimdCrypto.cs
@@ -15,7 +15,17 @@ namespace ARMeilleure.Instructions
Operand d = GetVec(op.Rd);
Operand n = GetVec(op.Rn);
- 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 = GetVec(op.Rd);
Operand n = GetVec(op.Rn);
- 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 = GetVec(op.Rn);
- context.Copy(GetVec(op.Rd), 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(GetVec(op.Rd), res);
}
public static void Aesmc_V(ArmEmitterContext context)
@@ -43,7 +73,23 @@ namespace ARMeilleure.Instructions
Operand n = GetVec(op.Rn);
- context.Copy(GetVec(op.Rd), 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(GetVec(op.Rd), res);
}
}
}
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);
}
}
}