diff options
Diffstat (limited to 'ARMeilleure/Instructions')
| -rw-r--r-- | ARMeilleure/Instructions/InstEmitSimdCrypto.cs | 54 | ||||
| -rw-r--r-- | ARMeilleure/Instructions/InstEmitSimdCrypto32.cs | 54 |
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); } } } |
