InstEmitSimdCrypto32.cs
1 using ARMeilleure.Decoders; 2 using ARMeilleure.IntermediateRepresentation; 3 using ARMeilleure.Translation; 4 5 using static ARMeilleure.Instructions.InstEmitHelper; 6 7 namespace ARMeilleure.Instructions 8 { 9 partial class InstEmit32 10 { 11 public static void Aesd_V(ArmEmitterContext context) 12 { 13 OpCode32Simd op = (OpCode32Simd)context.CurrOp; 14 15 Operand d = GetVecA32(op.Qd); 16 Operand n = GetVecA32(op.Qm); 17 18 Operand res; 19 20 if (Optimizations.UseArm64Aes) 21 { 22 res = context.AddIntrinsic(Intrinsic.Arm64AesdV, d, n); 23 } 24 else if (Optimizations.UseAesni) 25 { 26 res = context.AddIntrinsic(Intrinsic.X86Aesdeclast, context.AddIntrinsic(Intrinsic.X86Xorpd, d, n), context.VectorZero()); 27 } 28 else 29 { 30 res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Decrypt)), d, n); 31 } 32 33 context.Copy(d, res); 34 } 35 36 public static void Aese_V(ArmEmitterContext context) 37 { 38 OpCode32Simd op = (OpCode32Simd)context.CurrOp; 39 40 Operand d = GetVecA32(op.Qd); 41 Operand n = GetVecA32(op.Qm); 42 43 Operand res; 44 45 if (Optimizations.UseArm64Aes) 46 { 47 res = context.AddIntrinsic(Intrinsic.Arm64AeseV, d, n); 48 } 49 else if (Optimizations.UseAesni) 50 { 51 res = context.AddIntrinsic(Intrinsic.X86Aesenclast, context.AddIntrinsic(Intrinsic.X86Xorpd, d, n), context.VectorZero()); 52 } 53 else 54 { 55 res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Encrypt)), d, n); 56 } 57 58 context.Copy(d, res); 59 } 60 61 public static void Aesimc_V(ArmEmitterContext context) 62 { 63 OpCode32Simd op = (OpCode32Simd)context.CurrOp; 64 65 Operand n = GetVecA32(op.Qm); 66 67 Operand res; 68 69 if (Optimizations.UseArm64Aes) 70 { 71 res = context.AddIntrinsic(Intrinsic.Arm64AesimcV, n); 72 } 73 else if (Optimizations.UseAesni) 74 { 75 res = context.AddIntrinsic(Intrinsic.X86Aesimc, n); 76 } 77 else 78 { 79 res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.InverseMixColumns)), n); 80 } 81 82 context.Copy(GetVecA32(op.Qd), res); 83 } 84 85 public static void Aesmc_V(ArmEmitterContext context) 86 { 87 OpCode32Simd op = (OpCode32Simd)context.CurrOp; 88 89 Operand n = GetVecA32(op.Qm); 90 91 Operand res; 92 93 if (Optimizations.UseArm64Aes) 94 { 95 res = context.AddIntrinsic(Intrinsic.Arm64AesmcV, n); 96 } 97 else if (Optimizations.UseAesni) 98 { 99 Operand roundKey = context.VectorZero(); 100 101 // Inverse Shift Rows, Inverse Sub Bytes, xor 0 so nothing happens. 102 res = context.AddIntrinsic(Intrinsic.X86Aesdeclast, n, roundKey); 103 104 // Shift Rows, Sub Bytes, Mix Columns (!), xor 0 so nothing happens. 105 res = context.AddIntrinsic(Intrinsic.X86Aesenc, res, roundKey); 106 } 107 else 108 { 109 res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.MixColumns)), n); 110 } 111 112 context.Copy(GetVecA32(op.Qd), res); 113 } 114 } 115 }