2020-03-14 00:29:58 +01:00
|
|
|
|
using ARMeilleure.Decoders;
|
|
|
|
|
using ARMeilleure.IntermediateRepresentation;
|
|
|
|
|
using ARMeilleure.Translation;
|
|
|
|
|
|
|
|
|
|
using static ARMeilleure.Instructions.InstEmitHelper;
|
|
|
|
|
|
|
|
|
|
namespace ARMeilleure.Instructions
|
|
|
|
|
{
|
|
|
|
|
partial class InstEmit32
|
|
|
|
|
{
|
|
|
|
|
public static void Aesd_V(ArmEmitterContext context)
|
|
|
|
|
{
|
|
|
|
|
OpCode32Simd op = (OpCode32Simd)context.CurrOp;
|
|
|
|
|
|
|
|
|
|
Operand d = GetVecA32(op.Qd);
|
|
|
|
|
Operand n = GetVecA32(op.Qm);
|
|
|
|
|
|
2020-03-25 07:20:29 +01:00
|
|
|
|
Operand res;
|
2020-06-16 20:28:02 +02:00
|
|
|
|
|
2023-06-11 02:51:35 +02:00
|
|
|
|
if (Optimizations.UseArm64Aes)
|
|
|
|
|
{
|
|
|
|
|
res = context.AddIntrinsic(Intrinsic.Arm64AesdV, d, n);
|
|
|
|
|
}
|
|
|
|
|
else if (Optimizations.UseAesni)
|
2020-03-25 07:20:29 +01:00
|
|
|
|
{
|
|
|
|
|
res = context.AddIntrinsic(Intrinsic.X86Aesdeclast, context.AddIntrinsic(Intrinsic.X86Xorpd, d, n), context.VectorZero());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-06-16 20:28:02 +02:00
|
|
|
|
res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Decrypt)), d, n);
|
2020-03-25 07:20:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.Copy(d, res);
|
2020-03-14 00:29:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Aese_V(ArmEmitterContext context)
|
|
|
|
|
{
|
|
|
|
|
OpCode32Simd op = (OpCode32Simd)context.CurrOp;
|
|
|
|
|
|
|
|
|
|
Operand d = GetVecA32(op.Qd);
|
|
|
|
|
Operand n = GetVecA32(op.Qm);
|
|
|
|
|
|
2020-03-25 07:20:29 +01:00
|
|
|
|
Operand res;
|
2020-06-16 20:28:02 +02:00
|
|
|
|
|
2023-06-11 02:51:35 +02:00
|
|
|
|
if (Optimizations.UseArm64Aes)
|
|
|
|
|
{
|
|
|
|
|
res = context.AddIntrinsic(Intrinsic.Arm64AeseV, d, n);
|
|
|
|
|
}
|
|
|
|
|
else if (Optimizations.UseAesni)
|
2020-03-25 07:20:29 +01:00
|
|
|
|
{
|
|
|
|
|
res = context.AddIntrinsic(Intrinsic.X86Aesenclast, context.AddIntrinsic(Intrinsic.X86Xorpd, d, n), context.VectorZero());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-06-16 20:28:02 +02:00
|
|
|
|
res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Encrypt)), d, n);
|
2020-03-25 07:20:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.Copy(d, res);
|
2020-03-14 00:29:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Aesimc_V(ArmEmitterContext context)
|
|
|
|
|
{
|
|
|
|
|
OpCode32Simd op = (OpCode32Simd)context.CurrOp;
|
|
|
|
|
|
|
|
|
|
Operand n = GetVecA32(op.Qm);
|
|
|
|
|
|
2020-03-25 07:20:29 +01:00
|
|
|
|
Operand res;
|
2020-06-16 20:28:02 +02:00
|
|
|
|
|
2023-06-11 02:51:35 +02:00
|
|
|
|
if (Optimizations.UseArm64Aes)
|
|
|
|
|
{
|
|
|
|
|
res = context.AddIntrinsic(Intrinsic.Arm64AesimcV, n);
|
|
|
|
|
}
|
|
|
|
|
else if (Optimizations.UseAesni)
|
2020-03-25 07:20:29 +01:00
|
|
|
|
{
|
|
|
|
|
res = context.AddIntrinsic(Intrinsic.X86Aesimc, n);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-06-16 20:28:02 +02:00
|
|
|
|
res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.InverseMixColumns)), n);
|
2020-03-25 07:20:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.Copy(GetVecA32(op.Qd), res);
|
2020-03-14 00:29:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Aesmc_V(ArmEmitterContext context)
|
|
|
|
|
{
|
|
|
|
|
OpCode32Simd op = (OpCode32Simd)context.CurrOp;
|
|
|
|
|
|
|
|
|
|
Operand n = GetVecA32(op.Qm);
|
|
|
|
|
|
2020-03-25 07:20:29 +01:00
|
|
|
|
Operand res;
|
2020-06-16 20:28:02 +02:00
|
|
|
|
|
2023-06-11 02:51:35 +02:00
|
|
|
|
if (Optimizations.UseArm64Aes)
|
|
|
|
|
{
|
|
|
|
|
res = context.AddIntrinsic(Intrinsic.Arm64AesmcV, n);
|
|
|
|
|
}
|
|
|
|
|
else if (Optimizations.UseAesni)
|
2020-03-25 07:20:29 +01:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
{
|
2020-06-16 20:28:02 +02:00
|
|
|
|
res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.MixColumns)), n);
|
2020-03-25 07:20:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.Copy(GetVecA32(op.Qd), res);
|
2020-03-14 00:29:58 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|