From abb65750cd37fce313e9ddba725400a6a99915bb Mon Sep 17 00:00:00 2001 From: LDj3SNuD Date: Fri, 10 Jan 2020 02:52:31 +0100 Subject: [PATCH] Use MethodInfo for managed method calls. Use IR methods instead of managed methods about Max/Min (S/U). Follow-ups & Nits. --- ARMeilleure/Instructions/InstEmitException.cs | 4 +- ARMeilleure/Instructions/InstEmitHash.cs | 2 +- ARMeilleure/Instructions/InstEmitMemoryEx.cs | 53 +-- .../Instructions/InstEmitMemoryHelper.cs | 53 +-- .../Instructions/InstEmitSimdArithmetic.cs | 142 +++--- ARMeilleure/Instructions/InstEmitSimdCmp.cs | 24 +- .../Instructions/InstEmitSimdCrypto.cs | 8 +- ARMeilleure/Instructions/InstEmitSimdCvt.cs | 97 ++-- ARMeilleure/Instructions/InstEmitSimdHash.cs | 20 +- .../Instructions/InstEmitSimdHelper.cs | 53 ++- ARMeilleure/Instructions/InstEmitSimdMove.cs | 58 ++- ARMeilleure/Instructions/InstEmitSimdShift.cs | 21 +- ARMeilleure/Instructions/InstEmitSystem.cs | 37 +- ARMeilleure/Instructions/SoftFallback.cs | 7 - ARMeilleure/Translation/DelegateHelpers.cs | 44 +- ARMeilleure/Translation/Delegates.cs | 440 +++++++----------- ARMeilleure/Translation/EmitterContext.cs | 35 +- ARMeilleure/Translation/Translator.cs | 2 +- 18 files changed, 481 insertions(+), 619 deletions(-) diff --git a/ARMeilleure/Instructions/InstEmitException.cs b/ARMeilleure/Instructions/InstEmitException.cs index f2bd1e6bc3..8972b8035e 100644 --- a/ARMeilleure/Instructions/InstEmitException.cs +++ b/ARMeilleure/Instructions/InstEmitException.cs @@ -23,7 +23,7 @@ namespace ARMeilleure.Instructions context.StoreToContext(); - context.NativeInterfaceCall(name, Const(op.Address), Const(op.Id)); + context.Call(typeof(NativeInterface).GetMethod(name), Const(op.Address), Const(op.Id)); context.LoadFromContext(); @@ -41,7 +41,7 @@ namespace ARMeilleure.Instructions context.StoreToContext(); - context.NativeInterfaceCall(name, Const(op.Address), Const(op.RawOpCode)); + context.Call(typeof(NativeInterface).GetMethod(name), Const(op.Address), Const(op.RawOpCode)); context.LoadFromContext(); diff --git a/ARMeilleure/Instructions/InstEmitHash.cs b/ARMeilleure/Instructions/InstEmitHash.cs index 3edfff4109..e03d54357e 100644 --- a/ARMeilleure/Instructions/InstEmitHash.cs +++ b/ARMeilleure/Instructions/InstEmitHash.cs @@ -55,7 +55,7 @@ namespace ARMeilleure.Instructions Operand n = GetIntOrZR(context, op.Rn); Operand m = GetIntOrZR(context, op.Rm); - Operand d = context.SoftFallbackCall(name, n, m); + Operand d = context.Call(typeof(SoftFallback).GetMethod(name), n, m); SetIntOrZR(context, op.Rd, d); } diff --git a/ARMeilleure/Instructions/InstEmitMemoryEx.cs b/ARMeilleure/Instructions/InstEmitMemoryEx.cs index 1a6ca082b1..3e4c91b747 100644 --- a/ARMeilleure/Instructions/InstEmitMemoryEx.cs +++ b/ARMeilleure/Instructions/InstEmitMemoryEx.cs @@ -3,6 +3,7 @@ using ARMeilleure.IntermediateRepresentation; using ARMeilleure.Translation; using System; using System.Diagnostics; +using System.Reflection; using static ARMeilleure.Instructions.InstEmitHelper; using static ARMeilleure.IntermediateRepresentation.OperandHelper; @@ -22,7 +23,7 @@ namespace ARMeilleure.Instructions public static void Clrex(ArmEmitterContext context) { - context.NativeInterfaceCall(nameof(NativeInterface.ClearExclusive)); + context.Call(typeof(NativeInterface).GetMethod(nameof(NativeInterface.ClearExclusive))); } public static void Dmb(ArmEmitterContext context) => EmitBarrier(context); @@ -107,32 +108,32 @@ namespace ARMeilleure.Instructions bool exclusive, int size) { - string fallbackMethodName = null; + MethodInfo info = null; if (exclusive) { switch (size) { - case 0: fallbackMethodName = nameof(NativeInterface.ReadByteExclusive); break; - case 1: fallbackMethodName = nameof(NativeInterface.ReadUInt16Exclusive); break; - case 2: fallbackMethodName = nameof(NativeInterface.ReadUInt32Exclusive); break; - case 3: fallbackMethodName = nameof(NativeInterface.ReadUInt64Exclusive); break; - case 4: fallbackMethodName = nameof(NativeInterface.ReadVector128Exclusive); break; + case 0: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadByteExclusive)); break; + case 1: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt16Exclusive)); break; + case 2: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt32Exclusive)); break; + case 3: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt64Exclusive)); break; + case 4: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadVector128Exclusive)); break; } } else { switch (size) { - case 0: fallbackMethodName = nameof(NativeInterface.ReadByte); break; - case 1: fallbackMethodName = nameof(NativeInterface.ReadUInt16); break; - case 2: fallbackMethodName = nameof(NativeInterface.ReadUInt32); break; - case 3: fallbackMethodName = nameof(NativeInterface.ReadUInt64); break; - case 4: fallbackMethodName = nameof(NativeInterface.ReadVector128); break; + case 0: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadByte)); break; + case 1: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt16)); break; + case 2: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt32)); break; + case 3: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt64)); break; + case 4: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadVector128)); break; } } - return context.NativeInterfaceCall(fallbackMethodName, address); + return context.Call(info, address); } public static void Pfrm(ArmEmitterContext context) @@ -219,33 +220,33 @@ namespace ARMeilleure.Instructions value = context.ConvertI64ToI32(value); } - string fallbackMethodName = null; + MethodInfo info = null; if (exclusive) { switch (size) { - case 0: fallbackMethodName = nameof(NativeInterface.WriteByteExclusive); break; - case 1: fallbackMethodName = nameof(NativeInterface.WriteUInt16Exclusive); break; - case 2: fallbackMethodName = nameof(NativeInterface.WriteUInt32Exclusive); break; - case 3: fallbackMethodName = nameof(NativeInterface.WriteUInt64Exclusive); break; - case 4: fallbackMethodName = nameof(NativeInterface.WriteVector128Exclusive); break; + case 0: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteByteExclusive)); break; + case 1: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt16Exclusive)); break; + case 2: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt32Exclusive)); break; + case 3: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt64Exclusive)); break; + case 4: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteVector128Exclusive)); break; } - return context.NativeInterfaceCall(fallbackMethodName, address, value); + return context.Call(info, address, value); } else { switch (size) { - case 0: fallbackMethodName = nameof(NativeInterface.WriteByte); break; - case 1: fallbackMethodName = nameof(NativeInterface.WriteUInt16); break; - case 2: fallbackMethodName = nameof(NativeInterface.WriteUInt32); break; - case 3: fallbackMethodName = nameof(NativeInterface.WriteUInt64); break; - case 4: fallbackMethodName = nameof(NativeInterface.WriteVector128); break; + case 0: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteByte)); break; + case 1: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt16)); break; + case 2: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt32)); break; + case 3: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt64)); break; + case 4: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteVector128)); break; } - context.NativeInterfaceCall(fallbackMethodName, address, value); + context.Call(info, address, value); return null; } diff --git a/ARMeilleure/Instructions/InstEmitMemoryHelper.cs b/ARMeilleure/Instructions/InstEmitMemoryHelper.cs index 98ae54290b..3e6d80fad3 100644 --- a/ARMeilleure/Instructions/InstEmitMemoryHelper.cs +++ b/ARMeilleure/Instructions/InstEmitMemoryHelper.cs @@ -4,6 +4,7 @@ using ARMeilleure.Memory; using ARMeilleure.Translation; using ARMeilleure.Translation.AOT; using System; +using System.Reflection; using static ARMeilleure.Instructions.InstEmitHelper; using static ARMeilleure.IntermediateRepresentation.OperandHelper; @@ -340,17 +341,17 @@ namespace ARMeilleure.Instructions private static void EmitReadIntFallback(ArmEmitterContext context, Operand address, int rt, int size) { - string fallbackMethodName = null; + MethodInfo info = null; switch (size) { - case 0: fallbackMethodName = nameof(NativeInterface.ReadByte); break; - case 1: fallbackMethodName = nameof(NativeInterface.ReadUInt16); break; - case 2: fallbackMethodName = nameof(NativeInterface.ReadUInt32); break; - case 3: fallbackMethodName = nameof(NativeInterface.ReadUInt64); break; + case 0: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadByte)); break; + case 1: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt16)); break; + case 2: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt32)); break; + case 3: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt64)); break; } - SetInt(context, rt, context.NativeInterfaceCall(fallbackMethodName, address)); + SetInt(context, rt, context.Call(info, address)); } private static void EmitReadVectorFallback( @@ -361,18 +362,18 @@ namespace ARMeilleure.Instructions int elem, int size) { - string fallbackMethodName = null; + MethodInfo info = null; switch (size) { - case 0: fallbackMethodName = nameof(NativeInterface.ReadByte); break; - case 1: fallbackMethodName = nameof(NativeInterface.ReadUInt16); break; - case 2: fallbackMethodName = nameof(NativeInterface.ReadUInt32); break; - case 3: fallbackMethodName = nameof(NativeInterface.ReadUInt64); break; - case 4: fallbackMethodName = nameof(NativeInterface.ReadVector128); break; + case 0: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadByte)); break; + case 1: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt16)); break; + case 2: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt32)); break; + case 3: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt64)); break; + case 4: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadVector128)); break; } - Operand value = context.NativeInterfaceCall(fallbackMethodName, address); + Operand value = context.Call(info, address); switch (size) { @@ -387,14 +388,14 @@ namespace ARMeilleure.Instructions private static void EmitWriteIntFallback(ArmEmitterContext context, Operand address, int rt, int size) { - string fallbackMethodName = null; + MethodInfo info = null; switch (size) { - case 0: fallbackMethodName = nameof(NativeInterface.WriteByte); break; - case 1: fallbackMethodName = nameof(NativeInterface.WriteUInt16); break; - case 2: fallbackMethodName = nameof(NativeInterface.WriteUInt32); break; - case 3: fallbackMethodName = nameof(NativeInterface.WriteUInt64); break; + case 0: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteByte)); break; + case 1: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt16)); break; + case 2: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt32)); break; + case 3: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt64)); break; } Operand value = GetInt(context, rt); @@ -404,7 +405,7 @@ namespace ARMeilleure.Instructions value = context.ConvertI64ToI32(value); } - context.NativeInterfaceCall(fallbackMethodName, address, value); + context.Call(info, address, value); } private static void EmitWriteVectorFallback( @@ -414,15 +415,15 @@ namespace ARMeilleure.Instructions int elem, int size) { - string fallbackMethodName = null; + MethodInfo info = null; switch (size) { - case 0: fallbackMethodName = nameof(NativeInterface.WriteByte); break; - case 1: fallbackMethodName = nameof(NativeInterface.WriteUInt16); break; - case 2: fallbackMethodName = nameof(NativeInterface.WriteUInt32); break; - case 3: fallbackMethodName = nameof(NativeInterface.WriteUInt64); break; - case 4: fallbackMethodName = nameof(NativeInterface.WriteVector128); break; + case 0: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteByte)); break; + case 1: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt16)); break; + case 2: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt32)); break; + case 3: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt64)); break; + case 4: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteVector128)); break; } Operand value = null; @@ -442,7 +443,7 @@ namespace ARMeilleure.Instructions value = GetVec(rt); } - context.NativeInterfaceCall(fallbackMethodName, address, value); + context.Call(info, address, value); } private static Operand GetInt(ArmEmitterContext context, int rt) diff --git a/ARMeilleure/Instructions/InstEmitSimdArithmetic.cs b/ARMeilleure/Instructions/InstEmitSimdArithmetic.cs index f9e014a3d2..db5728ad8f 100644 --- a/ARMeilleure/Instructions/InstEmitSimdArithmetic.cs +++ b/ARMeilleure/Instructions/InstEmitSimdArithmetic.cs @@ -6,6 +6,8 @@ using ARMeilleure.IntermediateRepresentation; using ARMeilleure.State; using ARMeilleure.Translation; using System; +using System.Diagnostics; +using System.Reflection; using static ARMeilleure.Instructions.InstEmitHelper; using static ARMeilleure.Instructions.InstEmitSimdHelper; @@ -106,7 +108,7 @@ namespace ARMeilleure.Instructions { Operand ne = EmitVectorExtractZx(context, op.Rn, index, op.Size); - Operand de = context.SoftFallbackCall(nameof(SoftFallback.CountLeadingSigns), ne, Const(eSize)); + Operand de = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.CountLeadingSigns)), ne, Const(eSize)); res = EmitVectorInsert(context, res, de, index, op.Size); } @@ -128,7 +130,7 @@ namespace ARMeilleure.Instructions { Operand ne = EmitVectorExtractZx(context, op.Rn, index, op.Size); - Operand de = context.SoftFallbackCall(nameof(SoftFallback.CountLeadingZeros), ne, Const(eSize)); + Operand de = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.CountLeadingZeros)), ne, Const(eSize)); res = EmitVectorInsert(context, res, de, index, op.Size); } @@ -156,7 +158,7 @@ namespace ARMeilleure.Instructions } else { - de = context.SoftFallbackCall(nameof(SoftFallback.CountSetBits8), ne); + de = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.CountSetBits8)), ne); } res = EmitVectorInsert(context, res, de, index, 0); @@ -1298,11 +1300,11 @@ namespace ARMeilleure.Instructions { if (op.Size == 0) { - return context.SoftFallbackCall(nameof(SoftFallback.RoundF), op1); + return context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.RoundF)), op1); } else /* if (op.Size == 1) */ { - return context.SoftFallbackCall(nameof(SoftFallback.Round), op1); + return context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Round)), op1); } }); } @@ -1317,11 +1319,11 @@ namespace ARMeilleure.Instructions { if (sizeF == 0) { - return context.SoftFallbackCall(nameof(SoftFallback.RoundF), op1); + return context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.RoundF)), op1); } else /* if (sizeF == 1) */ { - return context.SoftFallbackCall(nameof(SoftFallback.Round), op1); + return context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Round)), op1); } }); } @@ -1424,11 +1426,11 @@ namespace ARMeilleure.Instructions { if (op.Size == 0) { - return context.SoftFallbackCall(nameof(SoftFallback.RoundF), op1); + return context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.RoundF)), op1); } else /* if (op.Size == 1) */ { - return context.SoftFallbackCall(nameof(SoftFallback.Round), op1); + return context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Round)), op1); } }); } @@ -1443,11 +1445,11 @@ namespace ARMeilleure.Instructions { if (sizeF == 0) { - return context.SoftFallbackCall(nameof(SoftFallback.RoundF), op1); + return context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.RoundF)), op1); } else /* if (sizeF == 1) */ { - return context.SoftFallbackCall(nameof(SoftFallback.Round), op1); + return context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Round)), op1); } }); } @@ -1681,7 +1683,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse41) { - EmitSse41Mul_AddSub(context, AddSub.Add); + EmitSse41VectorMul_AddSub(context, AddSub.Add); } else { @@ -1704,7 +1706,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse41) { - EmitSse41Mul_AddSub(context, AddSub.Subtract); + EmitSse41VectorMul_AddSub(context, AddSub.Subtract); } else { @@ -1727,7 +1729,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse41) { - EmitSse41Mul_AddSub(context, AddSub.None); + EmitSse41VectorMul_AddSub(context, AddSub.None); } else { @@ -1796,14 +1798,14 @@ namespace ARMeilleure.Instructions public static void Sabd_V(ArmEmitterContext context) { - if (Optimizations.UseSse2) + if (Optimizations.UseSse41) { OpCodeSimdReg op = (OpCodeSimdReg)context.CurrOp; Operand n = GetVec(op.Rn); Operand m = GetVec(op.Rm); - EmitSse41Sabd(context, op, n, m, isLong: false); + EmitSse41VectorSabdOp(context, op, n, m, isLong: false); } else { @@ -1836,7 +1838,7 @@ namespace ARMeilleure.Instructions n = context.AddIntrinsic(movInst, n); m = context.AddIntrinsic(movInst, m); - EmitSse41Sabd(context, op, n, m, isLong: true); + EmitSse41VectorSabdOp(context, op, n, m, isLong: true); } else { @@ -2018,9 +2020,7 @@ namespace ARMeilleure.Instructions } else { - string name = nameof(SoftFallback.MaxS64); - - EmitVectorBinaryOpSx(context, (op1, op2) => context.SoftFallbackCall(name, op1, op2)); + EmitVectorBinaryOpSx(context, (op1, op2) => EmitMax64Op(context, op1, op2, signed: true)); } } @@ -2032,17 +2032,13 @@ namespace ARMeilleure.Instructions } else { - string name = nameof(SoftFallback.MaxS64); - - EmitVectorPairwiseOpSx(context, (op1, op2) => context.SoftFallbackCall(name, op1, op2)); + EmitVectorPairwiseOpSx(context, (op1, op2) => EmitMax64Op(context, op1, op2, signed: true)); } } public static void Smaxv_V(ArmEmitterContext context) { - string name = nameof(SoftFallback.MaxS64); - - EmitVectorAcrossVectorOpSx(context, (op1, op2) => context.SoftFallbackCall(name, op1, op2)); + EmitVectorAcrossVectorOpSx(context, (op1, op2) => EmitMax64Op(context, op1, op2, signed: true)); } public static void Smin_V(ArmEmitterContext context) @@ -2067,9 +2063,7 @@ namespace ARMeilleure.Instructions } else { - string name = nameof(SoftFallback.MinS64); - - EmitVectorBinaryOpSx(context, (op1, op2) => context.SoftFallbackCall(name, op1, op2)); + EmitVectorBinaryOpSx(context, (op1, op2) => EmitMin64Op(context, op1, op2, signed: true)); } } @@ -2081,17 +2075,13 @@ namespace ARMeilleure.Instructions } else { - string name = nameof(SoftFallback.MinS64); - - EmitVectorPairwiseOpSx(context, (op1, op2) => context.SoftFallbackCall(name, op1, op2)); + EmitVectorPairwiseOpSx(context, (op1, op2) => EmitMin64Op(context, op1, op2, signed: true)); } } public static void Sminv_V(ArmEmitterContext context) { - string name = nameof(SoftFallback.MinS64); - - EmitVectorAcrossVectorOpSx(context, (op1, op2) => context.SoftFallbackCall(name, op1, op2)); + EmitVectorAcrossVectorOpSx(context, (op1, op2) => EmitMin64Op(context, op1, op2, signed: true)); } public static void Smlal_V(ArmEmitterContext context) @@ -2449,7 +2439,7 @@ namespace ARMeilleure.Instructions Operand n = GetVec(op.Rn); Operand m = GetVec(op.Rm); - EmitSse41Uabd(context, op, n, m, isLong: false); + EmitSse41VectorUabdOp(context, op, n, m, isLong: false); } else { @@ -2482,7 +2472,7 @@ namespace ARMeilleure.Instructions n = context.AddIntrinsic(movInst, n); m = context.AddIntrinsic(movInst, m); - EmitSse41Uabd(context, op, n, m, isLong: true); + EmitSse41VectorUabdOp(context, op, n, m, isLong: true); } else { @@ -2657,9 +2647,7 @@ namespace ARMeilleure.Instructions } else { - string name = nameof(SoftFallback.MaxU64); - - EmitVectorBinaryOpZx(context, (op1, op2) => context.SoftFallbackCall(name, op1, op2)); + EmitVectorBinaryOpZx(context, (op1, op2) => EmitMax64Op(context, op1, op2, signed: false)); } } @@ -2671,17 +2659,13 @@ namespace ARMeilleure.Instructions } else { - string name = nameof(SoftFallback.MaxU64); - - EmitVectorPairwiseOpZx(context, (op1, op2) => context.SoftFallbackCall(name, op1, op2)); + EmitVectorPairwiseOpZx(context, (op1, op2) => EmitMax64Op(context, op1, op2, signed: false)); } } public static void Umaxv_V(ArmEmitterContext context) { - string name = nameof(SoftFallback.MaxU64); - - EmitVectorAcrossVectorOpZx(context, (op1, op2) => context.SoftFallbackCall(name, op1, op2)); + EmitVectorAcrossVectorOpZx(context, (op1, op2) => EmitMax64Op(context, op1, op2, signed: false)); } public static void Umin_V(ArmEmitterContext context) @@ -2706,9 +2690,7 @@ namespace ARMeilleure.Instructions } else { - string name = nameof(SoftFallback.MinU64); - - EmitVectorBinaryOpZx(context, (op1, op2) => context.SoftFallbackCall(name, op1, op2)); + EmitVectorBinaryOpZx(context, (op1, op2) => EmitMin64Op(context, op1, op2, signed: false)); } } @@ -2720,17 +2702,13 @@ namespace ARMeilleure.Instructions } else { - string name = nameof(SoftFallback.MinU64); - - EmitVectorPairwiseOpZx(context, (op1, op2) => context.SoftFallbackCall(name, op1, op2)); + EmitVectorPairwiseOpZx(context, (op1, op2) => EmitMin64Op(context, op1, op2, signed: false)); } } public static void Uminv_V(ArmEmitterContext context) { - string name = nameof(SoftFallback.MinU64); - - EmitVectorAcrossVectorOpZx(context, (op1, op2) => context.SoftFallbackCall(name, op1, op2)); + EmitVectorAcrossVectorOpZx(context, (op1, op2) => EmitMin64Op(context, op1, op2, signed: false)); } public static void Umlal_V(ArmEmitterContext context) @@ -3072,7 +3050,29 @@ namespace ARMeilleure.Instructions context.Copy(d, res); } - public static void EmitScalarRoundOpF(ArmEmitterContext context, FPRoundingMode roundMode) + private static Operand EmitMax64Op(ArmEmitterContext context, Operand op1, Operand op2, bool signed) + { + Debug.Assert(op1.Type == OperandType.I64 && op2.Type == OperandType.I64); + + Operand cmp = signed + ? context.ICompareGreaterOrEqual (op1, op2) + : context.ICompareGreaterOrEqualUI(op1, op2); + + return context.ConditionalSelect(cmp, op1, op2); + } + + private static Operand EmitMin64Op(ArmEmitterContext context, Operand op1, Operand op2, bool signed) + { + Debug.Assert(op1.Type == OperandType.I64 && op2.Type == OperandType.I64); + + Operand cmp = signed + ? context.ICompareLessOrEqual (op1, op2) + : context.ICompareLessOrEqualUI(op1, op2); + + return context.ConditionalSelect(cmp, op1, op2); + } + + private static void EmitScalarRoundOpF(ArmEmitterContext context, FPRoundingMode roundMode) { OpCodeSimd op = (OpCodeSimd)context.CurrOp; @@ -3094,7 +3094,7 @@ namespace ARMeilleure.Instructions context.Copy(GetVec(op.Rd), res); } - public static void EmitVectorRoundOpF(ArmEmitterContext context, FPRoundingMode roundMode) + private static void EmitVectorRoundOpF(ArmEmitterContext context, FPRoundingMode roundMode) { OpCodeSimd op = (OpCodeSimd)context.CurrOp; @@ -3211,14 +3211,14 @@ namespace ARMeilleure.Instructions Subtract } - private static void EmitSse41Mul_AddSub(ArmEmitterContext context, AddSub addSub) + private static void EmitSse41VectorMul_AddSub(ArmEmitterContext context, AddSub addSub) { OpCodeSimdReg op = (OpCodeSimdReg)context.CurrOp; Operand n = GetVec(op.Rn); Operand m = GetVec(op.Rm); - Operand res = null; + Operand res; if (op.Size == 0) { @@ -3248,23 +3248,15 @@ namespace ARMeilleure.Instructions if (addSub == AddSub.Add) { - switch (op.Size) - { - case 0: res = context.AddIntrinsic(Intrinsic.X86Paddb, d, res); break; - case 1: res = context.AddIntrinsic(Intrinsic.X86Paddw, d, res); break; - case 2: res = context.AddIntrinsic(Intrinsic.X86Paddd, d, res); break; - case 3: res = context.AddIntrinsic(Intrinsic.X86Paddq, d, res); break; - } + Intrinsic addInst = X86PaddInstruction[op.Size]; + + res = context.AddIntrinsic(addInst, d, res); } else if (addSub == AddSub.Subtract) { - switch (op.Size) - { - case 0: res = context.AddIntrinsic(Intrinsic.X86Psubb, d, res); break; - case 1: res = context.AddIntrinsic(Intrinsic.X86Psubw, d, res); break; - case 2: res = context.AddIntrinsic(Intrinsic.X86Psubd, d, res); break; - case 3: res = context.AddIntrinsic(Intrinsic.X86Psubq, d, res); break; - } + Intrinsic subInst = X86PsubInstruction[op.Size]; + + res = context.AddIntrinsic(subInst, d, res); } if (op.RegisterSize == RegisterSize.Simd64) @@ -3275,7 +3267,7 @@ namespace ARMeilleure.Instructions context.Copy(d, res); } - private static void EmitSse41Sabd( + private static void EmitSse41VectorSabdOp( ArmEmitterContext context, OpCodeSimdReg op, Operand n, @@ -3308,7 +3300,7 @@ namespace ARMeilleure.Instructions context.Copy(GetVec(op.Rd), res); } - private static void EmitSse41Uabd( + private static void EmitSse41VectorUabdOp( ArmEmitterContext context, OpCodeSimdReg op, Operand n, diff --git a/ARMeilleure/Instructions/InstEmitSimdCmp.cs b/ARMeilleure/Instructions/InstEmitSimdCmp.cs index 49c0b80ba6..74597258cc 100644 --- a/ARMeilleure/Instructions/InstEmitSimdCmp.cs +++ b/ARMeilleure/Instructions/InstEmitSimdCmp.cs @@ -300,7 +300,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.FastFP && Optimizations.UseSse2) { - EmitSse2CmpOpF(context, CmpCondition.Equal, scalar: true); + EmitSse2OrAvxCmpOpF(context, CmpCondition.Equal, scalar: true); } else { @@ -312,7 +312,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.FastFP && Optimizations.UseSse2) { - EmitSse2CmpOpF(context, CmpCondition.Equal, scalar: false); + EmitSse2OrAvxCmpOpF(context, CmpCondition.Equal, scalar: false); } else { @@ -324,7 +324,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.FastFP && Optimizations.UseAvx) { - EmitSse2CmpOpF(context, CmpCondition.GreaterThanOrEqual, scalar: true); + EmitSse2OrAvxCmpOpF(context, CmpCondition.GreaterThanOrEqual, scalar: true); } else { @@ -336,7 +336,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.FastFP && Optimizations.UseAvx) { - EmitSse2CmpOpF(context, CmpCondition.GreaterThanOrEqual, scalar: false); + EmitSse2OrAvxCmpOpF(context, CmpCondition.GreaterThanOrEqual, scalar: false); } else { @@ -348,7 +348,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.FastFP && Optimizations.UseAvx) { - EmitSse2CmpOpF(context, CmpCondition.GreaterThan, scalar: true); + EmitSse2OrAvxCmpOpF(context, CmpCondition.GreaterThan, scalar: true); } else { @@ -360,7 +360,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.FastFP && Optimizations.UseAvx) { - EmitSse2CmpOpF(context, CmpCondition.GreaterThan, scalar: false); + EmitSse2OrAvxCmpOpF(context, CmpCondition.GreaterThan, scalar: false); } else { @@ -372,7 +372,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.FastFP && Optimizations.UseSse2) { - EmitSse2CmpOpF(context, CmpCondition.LessThanOrEqual, scalar: true); + EmitSse2OrAvxCmpOpF(context, CmpCondition.LessThanOrEqual, scalar: true); } else { @@ -384,7 +384,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.FastFP && Optimizations.UseSse2) { - EmitSse2CmpOpF(context, CmpCondition.LessThanOrEqual, scalar: false); + EmitSse2OrAvxCmpOpF(context, CmpCondition.LessThanOrEqual, scalar: false); } else { @@ -396,7 +396,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.FastFP && Optimizations.UseSse2) { - EmitSse2CmpOpF(context, CmpCondition.LessThan, scalar: true); + EmitSse2OrAvxCmpOpF(context, CmpCondition.LessThan, scalar: true); } else { @@ -408,7 +408,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.FastFP && Optimizations.UseSse2) { - EmitSse2CmpOpF(context, CmpCondition.LessThan, scalar: false); + EmitSse2OrAvxCmpOpF(context, CmpCondition.LessThan, scalar: false); } else { @@ -544,7 +544,7 @@ namespace ARMeilleure.Instructions me = context.VectorExtract(type, GetVec(op.Rm), 0); } - Operand nzcv = context.SoftFloatCall(op.Size == 0 ? nameof(SoftFloat32) : nameof(SoftFloat64), nameof(SoftFloat32.FPCompare), ne, me, Const(signalNaNs)); + Operand nzcv = EmitSoftFloatCall(context, nameof(SoftFloat32.FPCompare), ne, me, Const(signalNaNs)); EmitSetNzcv(context, nzcv); } @@ -665,7 +665,7 @@ namespace ARMeilleure.Instructions context.Copy(GetVec(op.Rd), res); } - private static void EmitSse2CmpOpF(ArmEmitterContext context, CmpCondition cond, bool scalar) + private static void EmitSse2OrAvxCmpOpF(ArmEmitterContext context, CmpCondition cond, bool scalar) { OpCodeSimd op = (OpCodeSimd)context.CurrOp; diff --git a/ARMeilleure/Instructions/InstEmitSimdCrypto.cs b/ARMeilleure/Instructions/InstEmitSimdCrypto.cs index f7be3e76e6..0026709447 100644 --- a/ARMeilleure/Instructions/InstEmitSimdCrypto.cs +++ b/ARMeilleure/Instructions/InstEmitSimdCrypto.cs @@ -15,7 +15,7 @@ namespace ARMeilleure.Instructions Operand d = GetVec(op.Rd); Operand n = GetVec(op.Rn); - context.Copy(d, context.SoftFallbackCall(nameof(SoftFallback.Decrypt), d, n)); + context.Copy(d, context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Decrypt)), d, n)); } public static void Aese_V(ArmEmitterContext context) @@ -25,7 +25,7 @@ namespace ARMeilleure.Instructions Operand d = GetVec(op.Rd); Operand n = GetVec(op.Rn); - context.Copy(d, context.SoftFallbackCall(nameof(SoftFallback.Encrypt), d, n)); + context.Copy(d, context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Encrypt)), d, n)); } public static void Aesimc_V(ArmEmitterContext context) @@ -34,7 +34,7 @@ namespace ARMeilleure.Instructions Operand n = GetVec(op.Rn); - context.Copy(GetVec(op.Rd), context.SoftFallbackCall(nameof(SoftFallback.InverseMixColumns), n)); + context.Copy(GetVec(op.Rd), context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.InverseMixColumns)), n)); } public static void Aesmc_V(ArmEmitterContext context) @@ -43,7 +43,7 @@ namespace ARMeilleure.Instructions Operand n = GetVec(op.Rn); - context.Copy(GetVec(op.Rd), context.SoftFallbackCall(nameof(SoftFallback.MixColumns), n)); + context.Copy(GetVec(op.Rd), context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.MixColumns)), n)); } } } diff --git a/ARMeilleure/Instructions/InstEmitSimdCvt.cs b/ARMeilleure/Instructions/InstEmitSimdCvt.cs index 0069a5ddf1..0c902a37bf 100644 --- a/ARMeilleure/Instructions/InstEmitSimdCvt.cs +++ b/ARMeilleure/Instructions/InstEmitSimdCvt.cs @@ -4,6 +4,7 @@ using ARMeilleure.State; using ARMeilleure.Translation; using System; using System.Diagnostics; +using System.Reflection; using static ARMeilleure.Instructions.InstEmitHelper; using static ARMeilleure.Instructions.InstEmitSimdHelper; @@ -61,7 +62,7 @@ namespace ARMeilleure.Instructions { Operand ne = context.VectorExtract(OperandType.FP32, GetVec(op.Rn), 0); - Operand res = context.SoftFloatCall(nameof(SoftFloat32_16), nameof(SoftFloat32_16.FPConvert), ne); + Operand res = context.Call(typeof(SoftFloat32_16).GetMethod(nameof(SoftFloat32_16.FPConvert)), ne); res = context.ZeroExtend16(OperandType.I64, res); @@ -71,7 +72,7 @@ namespace ARMeilleure.Instructions { Operand ne = EmitVectorExtractZx(context, op.Rn, 0, 1); - Operand res = context.SoftFloatCall(nameof(SoftFloat16_32), nameof(SoftFloat16_32.FPConvert), ne); + Operand res = context.Call(typeof(SoftFloat16_32).GetMethod(nameof(SoftFloat16_32.FPConvert)), ne); context.Copy(GetVec(op.Rd), context.VectorInsert(context.VectorZero(), res, 0)); } @@ -137,7 +138,7 @@ namespace ARMeilleure.Instructions { Operand ne = EmitVectorExtractZx(context, op.Rn, part + index, 1); - Operand e = context.SoftFloatCall(nameof(SoftFloat16_32), nameof(SoftFloat16_32.FPConvert), ne); + Operand e = context.Call(typeof(SoftFloat16_32).GetMethod(nameof(SoftFloat16_32.FPConvert)), ne); res = context.VectorInsert(res, e, index); } @@ -221,7 +222,7 @@ namespace ARMeilleure.Instructions if (sizeF == 0) { - Operand e = context.SoftFloatCall(nameof(SoftFloat32_16), nameof(SoftFloat32_16.FPConvert), ne); + Operand e = context.Call(typeof(SoftFloat32_16).GetMethod(nameof(SoftFloat32_16.FPConvert)), ne); e = context.ZeroExtend16(OperandType.I64, e); @@ -243,7 +244,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse41) { - EmitSse41Fcvts(context, FPRoundingMode.ToNearest, scalar: true); + EmitSse41FcvtsOpF(context, FPRoundingMode.ToNearest, scalar: true); } else { @@ -255,7 +256,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse41) { - EmitSse41Fcvts(context, FPRoundingMode.ToNearest, scalar: false); + EmitSse41FcvtsOpF(context, FPRoundingMode.ToNearest, scalar: false); } else { @@ -267,7 +268,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse41) { - EmitSse41Fcvtu(context, FPRoundingMode.ToNearest, scalar: true); + EmitSse41FcvtuOpF(context, FPRoundingMode.ToNearest, scalar: true); } else { @@ -279,7 +280,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse41) { - EmitSse41Fcvtu(context, FPRoundingMode.ToNearest, scalar: false); + EmitSse41FcvtuOpF(context, FPRoundingMode.ToNearest, scalar: false); } else { @@ -339,7 +340,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse41) { - EmitSse41Fcvts(context, FPRoundingMode.TowardsZero, scalar: true); + EmitSse41FcvtsOpF(context, FPRoundingMode.TowardsZero, scalar: true); } else { @@ -351,7 +352,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse41) { - EmitSse41Fcvts(context, FPRoundingMode.TowardsZero, scalar: false); + EmitSse41FcvtsOpF(context, FPRoundingMode.TowardsZero, scalar: false); } else { @@ -363,7 +364,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse41) { - EmitSse41Fcvts(context, FPRoundingMode.TowardsZero, scalar: false); + EmitSse41FcvtsOpF(context, FPRoundingMode.TowardsZero, scalar: false); } else { @@ -399,7 +400,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse41) { - EmitSse41Fcvtu(context, FPRoundingMode.TowardsZero, scalar: true); + EmitSse41FcvtuOpF(context, FPRoundingMode.TowardsZero, scalar: true); } else { @@ -411,7 +412,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse41) { - EmitSse41Fcvtu(context, FPRoundingMode.TowardsZero, scalar: false); + EmitSse41FcvtuOpF(context, FPRoundingMode.TowardsZero, scalar: false); } else { @@ -423,7 +424,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse41) { - EmitSse41Fcvtu(context, FPRoundingMode.TowardsZero, scalar: false); + EmitSse41FcvtuOpF(context, FPRoundingMode.TowardsZero, scalar: false); } else { @@ -469,7 +470,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse2) { - EmitSse2Scvtf(context, scalar: true); + EmitSse2ScvtfOp(context, scalar: true); } else { @@ -489,7 +490,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse2) { - EmitSse2Scvtf(context, scalar: false); + EmitSse2ScvtfOp(context, scalar: false); } else { @@ -501,7 +502,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse2) { - EmitSse2Scvtf(context, scalar: false); + EmitSse2ScvtfOp(context, scalar: false); } else { @@ -537,7 +538,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse2) { - EmitSse2Ucvtf(context, scalar: true); + EmitSse2UcvtfOp(context, scalar: true); } else { @@ -557,7 +558,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse2) { - EmitSse2Ucvtf(context, scalar: false); + EmitSse2UcvtfOp(context, scalar: false); } else { @@ -569,7 +570,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse2) { - EmitSse2Ucvtf(context, scalar: false); + EmitSse2UcvtfOp(context, scalar: false); } else { @@ -600,17 +601,21 @@ namespace ARMeilleure.Instructions if (sizeF == 0) { - string name = signed ? nameof(SoftFallback.SatF32ToS32) : nameof(SoftFallback.SatF32ToU32); + MethodInfo info = signed + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF32ToS32)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF32ToU32)); - e = context.SoftFallbackCall(name, e); + e = context.Call(info, e); e = context.ZeroExtend32(OperandType.I64, e); } else /* if (sizeF == 1) */ { - string name = signed ? nameof(SoftFallback.SatF64ToS64) : nameof(SoftFallback.SatF64ToU64); + MethodInfo info = signed + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF64ToS64)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF64ToU64)); - e = context.SoftFallbackCall(name, e); + e = context.Call(info, e); } res = EmitVectorInsert(context, res, e, index, sizeI); @@ -644,17 +649,21 @@ namespace ARMeilleure.Instructions if (sizeF == 0) { - string name = signed ? nameof(SoftFallback.SatF32ToS32) : nameof(SoftFallback.SatF32ToU32); + MethodInfo info = signed + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF32ToS32)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF32ToU32)); - e = context.SoftFallbackCall(name, e); + e = context.Call(info, e); e = context.ZeroExtend32(OperandType.I64, e); } else /* if (sizeF == 1) */ { - string name = signed ? nameof(SoftFallback.SatF64ToS64) : nameof(SoftFallback.SatF64ToU64); + MethodInfo info = signed + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF64ToS64)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF64ToU64)); - e = context.SoftFallbackCall(name, e); + e = context.Call(info, e); } res = EmitVectorInsert(context, res, e, index, sizeI); @@ -773,18 +782,22 @@ namespace ARMeilleure.Instructions value = EmitF2iFBitsMul(context, value, fBits); - string name; + MethodInfo info; if (context.CurrOp.RegisterSize == RegisterSize.Int32) { - name = value.Type == OperandType.FP32 ? nameof(SoftFallback.SatF32ToS32) : nameof(SoftFallback.SatF64ToS32); + info = value.Type == OperandType.FP32 + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF32ToS32)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF64ToS32)); } else { - name = value.Type == OperandType.FP32 ? nameof(SoftFallback.SatF32ToS64) : nameof(SoftFallback.SatF64ToS64); + info = value.Type == OperandType.FP32 + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF32ToS64)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF64ToS64)); } - return context.SoftFallbackCall(name, value); + return context.Call(info, value); } private static Operand EmitScalarFcvtu(ArmEmitterContext context, Operand value, int fBits) @@ -793,18 +806,22 @@ namespace ARMeilleure.Instructions value = EmitF2iFBitsMul(context, value, fBits); - string name; + MethodInfo info; if (context.CurrOp.RegisterSize == RegisterSize.Int32) { - name = value.Type == OperandType.FP32 ? nameof(SoftFallback.SatF32ToU32) : nameof(SoftFallback.SatF64ToU32); + info = value.Type == OperandType.FP32 + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF32ToU32)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF64ToU32)); } else { - name = value.Type == OperandType.FP32 ? nameof(SoftFallback.SatF32ToU64) : nameof(SoftFallback.SatF64ToU64); + info = value.Type == OperandType.FP32 + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF32ToU64)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF64ToU64)); } - return context.SoftFallbackCall(name, value); + return context.Call(info, value); } private static Operand EmitF2iFBitsMul(ArmEmitterContext context, Operand value, int fBits) @@ -881,7 +898,7 @@ namespace ARMeilleure.Instructions return res; } - private static void EmitSse2Scvtf(ArmEmitterContext context, bool scalar) + private static void EmitSse2ScvtfOp(ArmEmitterContext context, bool scalar) { OpCodeSimd op = (OpCodeSimd)context.CurrOp; @@ -946,7 +963,7 @@ namespace ARMeilleure.Instructions } } - private static void EmitSse2Ucvtf(ArmEmitterContext context, bool scalar) + private static void EmitSse2UcvtfOp(ArmEmitterContext context, bool scalar) { OpCodeSimd op = (OpCodeSimd)context.CurrOp; @@ -1035,7 +1052,7 @@ namespace ARMeilleure.Instructions } } - private static void EmitSse41Fcvts(ArmEmitterContext context, FPRoundingMode roundMode, bool scalar) + private static void EmitSse41FcvtsOpF(ArmEmitterContext context, FPRoundingMode roundMode, bool scalar) { OpCodeSimd op = (OpCodeSimd)context.CurrOp; @@ -1126,7 +1143,7 @@ namespace ARMeilleure.Instructions } } - private static void EmitSse41Fcvtu(ArmEmitterContext context, FPRoundingMode roundMode, bool scalar) + private static void EmitSse41FcvtuOpF(ArmEmitterContext context, FPRoundingMode roundMode, bool scalar) { OpCodeSimd op = (OpCodeSimd)context.CurrOp; diff --git a/ARMeilleure/Instructions/InstEmitSimdHash.cs b/ARMeilleure/Instructions/InstEmitSimdHash.cs index f24938a759..ed8b4afdce 100644 --- a/ARMeilleure/Instructions/InstEmitSimdHash.cs +++ b/ARMeilleure/Instructions/InstEmitSimdHash.cs @@ -19,7 +19,7 @@ namespace ARMeilleure.Instructions Operand m = GetVec(op.Rm); - Operand res = context.SoftFallbackCall(nameof(SoftFallback.HashChoose), d, ne, m); + Operand res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.HashChoose)), d, ne, m); context.Copy(GetVec(op.Rd), res); } @@ -30,7 +30,7 @@ namespace ARMeilleure.Instructions Operand ne = context.VectorExtract(OperandType.I32, GetVec(op.Rn), 0); - Operand res = context.SoftFallbackCall(nameof(SoftFallback.FixedRotate), ne); + Operand res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.FixedRotate)), ne); context.Copy(GetVec(op.Rd), context.VectorCreateScalar(res)); } @@ -45,7 +45,7 @@ namespace ARMeilleure.Instructions Operand m = GetVec(op.Rm); - Operand res = context.SoftFallbackCall(nameof(SoftFallback.HashMajority), d, ne, m); + Operand res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.HashMajority)), d, ne, m); context.Copy(GetVec(op.Rd), res); } @@ -60,7 +60,7 @@ namespace ARMeilleure.Instructions Operand m = GetVec(op.Rm); - Operand res = context.SoftFallbackCall(nameof(SoftFallback.HashParity), d, ne, m); + Operand res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.HashParity)), d, ne, m); context.Copy(GetVec(op.Rd), res); } @@ -73,7 +73,7 @@ namespace ARMeilleure.Instructions Operand n = GetVec(op.Rn); Operand m = GetVec(op.Rm); - Operand res = context.SoftFallbackCall(nameof(SoftFallback.Sha1SchedulePart1), d, n, m); + Operand res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Sha1SchedulePart1)), d, n, m); context.Copy(GetVec(op.Rd), res); } @@ -85,7 +85,7 @@ namespace ARMeilleure.Instructions Operand d = GetVec(op.Rd); Operand n = GetVec(op.Rn); - Operand res = context.SoftFallbackCall(nameof(SoftFallback.Sha1SchedulePart2), d, n); + Operand res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Sha1SchedulePart2)), d, n); context.Copy(GetVec(op.Rd), res); } @@ -100,7 +100,7 @@ namespace ARMeilleure.Instructions Operand n = GetVec(op.Rn); Operand m = GetVec(op.Rm); - Operand res = context.SoftFallbackCall(nameof(SoftFallback.HashLower), d, n, m); + Operand res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.HashLower)), d, n, m); context.Copy(GetVec(op.Rd), res); } @@ -113,7 +113,7 @@ namespace ARMeilleure.Instructions Operand n = GetVec(op.Rn); Operand m = GetVec(op.Rm); - Operand res = context.SoftFallbackCall(nameof(SoftFallback.HashUpper), d, n, m); + Operand res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.HashUpper)), d, n, m); context.Copy(GetVec(op.Rd), res); } @@ -125,7 +125,7 @@ namespace ARMeilleure.Instructions Operand d = GetVec(op.Rd); Operand n = GetVec(op.Rn); - Operand res = context.SoftFallbackCall(nameof(SoftFallback.Sha256SchedulePart1), d, n); + Operand res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Sha256SchedulePart1)), d, n); context.Copy(GetVec(op.Rd), res); } @@ -138,7 +138,7 @@ namespace ARMeilleure.Instructions Operand n = GetVec(op.Rn); Operand m = GetVec(op.Rm); - Operand res = context.SoftFallbackCall(nameof(SoftFallback.Sha256SchedulePart2), d, n, m); + Operand res = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Sha256SchedulePart2)), d, n, m); context.Copy(GetVec(op.Rd), res); } diff --git a/ARMeilleure/Instructions/InstEmitSimdHelper.cs b/ARMeilleure/Instructions/InstEmitSimdHelper.cs index 4155569de4..d8bdd6df34 100644 --- a/ARMeilleure/Instructions/InstEmitSimdHelper.cs +++ b/ARMeilleure/Instructions/InstEmitSimdHelper.cs @@ -4,6 +4,7 @@ using ARMeilleure.State; using ARMeilleure.Translation; using System; using System.Diagnostics; +using System.Reflection; using static ARMeilleure.Instructions.InstEmitHelper; using static ARMeilleure.IntermediateRepresentation.OperandHelper; @@ -314,21 +315,35 @@ namespace ARMeilleure.Instructions { IOpCodeSimd op = (IOpCodeSimd)context.CurrOp; - return context.MathCall((op.Size & 1) == 0 ? nameof(MathF) : nameof(Math), name, n); + MethodInfo info = (op.Size & 1) == 0 + ? typeof(MathF).GetMethod(name, new Type[] { typeof(float) }) + : typeof(Math). GetMethod(name, new Type[] { typeof(double) }); + + return context.Call(info, n); } public static Operand EmitRoundMathCall(ArmEmitterContext context, MidpointRounding roundMode, Operand n) { IOpCodeSimd op = (IOpCodeSimd)context.CurrOp; - return context.MathCall((op.Size & 1) == 0 ? nameof(MathF) : nameof(Math), nameof(Math.Round), n, Const((int)roundMode)); + string name = nameof(Math.Round); + + MethodInfo info = (op.Size & 1) == 0 + ? typeof(MathF).GetMethod(name, new Type[] { typeof(float), typeof(MidpointRounding) }) + : typeof(Math). GetMethod(name, new Type[] { typeof(double), typeof(MidpointRounding) }); + + return context.Call(info, n, Const((int)roundMode)); } public static Operand EmitSoftFloatCall(ArmEmitterContext context, string name, params Operand[] callArgs) { IOpCodeSimd op = (IOpCodeSimd)context.CurrOp; - return context.SoftFloatCall((op.Size & 1) == 0 ? nameof(SoftFloat32) : nameof(SoftFloat64), name, callArgs); + MethodInfo info = (op.Size & 1) == 0 + ? typeof(SoftFloat32).GetMethod(name) + : typeof(SoftFloat64).GetMethod(name); + + return context.Call(info, callArgs); } public static void EmitScalarBinaryOpByElemF(ArmEmitterContext context, Func2I emit) @@ -1362,18 +1377,22 @@ namespace ARMeilleure.Instructions throw new ArgumentOutOfRangeException(nameof(sizeDst)); } - string name; + MethodInfo info; if (signedSrc) { - name = signedDst ? nameof(SoftFallback.SignedSrcSignedDstSatQ) : nameof(SoftFallback.SignedSrcUnsignedDstSatQ); + info = signedDst + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.SignedSrcSignedDstSatQ)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.SignedSrcUnsignedDstSatQ)); } else { - name = signedDst ? nameof(SoftFallback.UnsignedSrcSignedDstSatQ) : nameof(SoftFallback.UnsignedSrcUnsignedDstSatQ); + info = signedDst + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnsignedSrcSignedDstSatQ)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnsignedSrcUnsignedDstSatQ)); } - return context.SoftFallbackCall(name, op, Const(sizeDst)); + return context.Call(info, op, Const(sizeDst)); } // TSrc (64bit) == TDst (64bit); signed. @@ -1381,7 +1400,7 @@ namespace ARMeilleure.Instructions { Debug.Assert(((OpCodeSimd)context.CurrOp).Size == 3, "Invalid element size."); - return context.SoftFallbackCall(nameof(SoftFallback.UnarySignedSatQAbsOrNeg), op); + return context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnarySignedSatQAbsOrNeg)), op); } // TSrcs (64bit) == TDst (64bit); signed, unsigned. @@ -1389,9 +1408,11 @@ namespace ARMeilleure.Instructions { Debug.Assert(((OpCodeSimd)context.CurrOp).Size == 3, "Invalid element size."); - string name = signed ? nameof(SoftFallback.BinarySignedSatQAdd) : nameof(SoftFallback.BinaryUnsignedSatQAdd); + MethodInfo info = signed + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinarySignedSatQAdd)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinaryUnsignedSatQAdd)); - return context.SoftFallbackCall(name, op1, op2); + return context.Call(info, op1, op2); } // TSrcs (64bit) == TDst (64bit); signed, unsigned. @@ -1399,9 +1420,11 @@ namespace ARMeilleure.Instructions { Debug.Assert(((OpCodeSimd)context.CurrOp).Size == 3, "Invalid element size."); - string name = signed ? nameof(SoftFallback.BinarySignedSatQSub) : nameof(SoftFallback.BinaryUnsignedSatQSub); + MethodInfo info = signed + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinarySignedSatQSub)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinaryUnsignedSatQSub)); - return context.SoftFallbackCall(name, op1, op2); + return context.Call(info, op1, op2); } // TSrcs (64bit) == TDst (64bit); signed, unsigned. @@ -1409,9 +1432,11 @@ namespace ARMeilleure.Instructions { Debug.Assert(((OpCodeSimd)context.CurrOp).Size == 3, "Invalid element size."); - string name = signed ? nameof(SoftFallback.BinarySignedSatQAcc) : nameof(SoftFallback.BinaryUnsignedSatQAcc); + MethodInfo info = signed + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinarySignedSatQAcc)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinaryUnsignedSatQAcc)); - return context.SoftFallbackCall(name, op1, op2); + return context.Call(info, op1, op2); } public static Operand EmitVectorExtractSx(ArmEmitterContext context, int reg, int index, int size) diff --git a/ARMeilleure/Instructions/InstEmitSimdMove.cs b/ARMeilleure/Instructions/InstEmitSimdMove.cs index 31d40fda3f..b93936fbba 100644 --- a/ARMeilleure/Instructions/InstEmitSimdMove.cs +++ b/ARMeilleure/Instructions/InstEmitSimdMove.cs @@ -2,6 +2,7 @@ using ARMeilleure.Decoders; using ARMeilleure.IntermediateRepresentation; using ARMeilleure.Translation; using System.Collections.Generic; +using System.Reflection; using static ARMeilleure.Instructions.InstEmitHelper; using static ARMeilleure.Instructions.InstEmitSimdHelper; @@ -297,31 +298,13 @@ namespace ARMeilleure.Instructions { OpCodeSimdImm op = (OpCodeSimdImm)context.CurrOp; - if (Optimizations.UseSse2) + if (op.RegisterSize == RegisterSize.Simd128) { - if (op.RegisterSize == RegisterSize.Simd128) - { - context.Copy(GetVec(op.Rd), X86GetAllElements(context, op.Immediate)); - } - else - { - context.Copy(GetVec(op.Rd), X86GetScalar(context, op.Immediate)); - } + context.Copy(GetVec(op.Rd), X86GetAllElements(context, op.Immediate)); } else { - Operand e = Const(op.Immediate); - - Operand res = context.VectorZero(); - - int elems = op.RegisterSize == RegisterSize.Simd128 ? 2 : 1; - - for (int index = 0; index < elems; index++) - { - res = EmitVectorInsert(context, res, e, index, 3); - } - - context.Copy(GetVec(op.Rd), res); + context.Copy(GetVec(op.Rd), X86GetScalar(context, op.Immediate)); } } @@ -349,7 +332,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse2) { - EmitSse2MoviMvni(context, not: false); + EmitSse2VectorMoviMvniOp(context, not: false); } else { @@ -361,7 +344,7 @@ namespace ARMeilleure.Instructions { if (Optimizations.UseSse2) { - EmitSse2MoviMvni(context, not: true); + EmitSse2VectorMoviMvniOp(context, not: true); } else { @@ -475,7 +458,7 @@ namespace ARMeilleure.Instructions EmitVectorZip(context, part: 1); } - private static void EmitSse2MoviMvni(ArmEmitterContext context, bool not) + private static void EmitSse2VectorMoviMvniOp(ArmEmitterContext context, bool not) { OpCodeSimdImm op = (OpCodeSimdImm)context.CurrOp; @@ -592,17 +575,30 @@ namespace ARMeilleure.Instructions args.Add(GetVec((op.Rn + index) & 0x1F)); } - string name = null; + MethodInfo info = null; - switch (op.Size) + if (isTbl) { - case 1: name = isTbl ? nameof(SoftFallback.Tbl1) : nameof(SoftFallback.Tbx1); break; - case 2: name = isTbl ? nameof(SoftFallback.Tbl2) : nameof(SoftFallback.Tbx2); break; - case 3: name = isTbl ? nameof(SoftFallback.Tbl3) : nameof(SoftFallback.Tbx3); break; - case 4: name = isTbl ? nameof(SoftFallback.Tbl4) : nameof(SoftFallback.Tbx4); break; + switch (op.Size) + { + case 1: info = typeof(SoftFallback).GetMethod(nameof(SoftFallback.Tbl1)); break; + case 2: info = typeof(SoftFallback).GetMethod(nameof(SoftFallback.Tbl2)); break; + case 3: info = typeof(SoftFallback).GetMethod(nameof(SoftFallback.Tbl3)); break; + case 4: info = typeof(SoftFallback).GetMethod(nameof(SoftFallback.Tbl4)); break; + } + } + else + { + switch (op.Size) + { + case 1: info = typeof(SoftFallback).GetMethod(nameof(SoftFallback.Tbx1)); break; + case 2: info = typeof(SoftFallback).GetMethod(nameof(SoftFallback.Tbx2)); break; + case 3: info = typeof(SoftFallback).GetMethod(nameof(SoftFallback.Tbx3)); break; + case 4: info = typeof(SoftFallback).GetMethod(nameof(SoftFallback.Tbx4)); break; + } } - context.Copy(d, context.SoftFallbackCall(name, args.ToArray())); + context.Copy(d, context.Call(info, args.ToArray())); } } diff --git a/ARMeilleure/Instructions/InstEmitSimdShift.cs b/ARMeilleure/Instructions/InstEmitSimdShift.cs index 6dbe66531e..0b3d85aebb 100644 --- a/ARMeilleure/Instructions/InstEmitSimdShift.cs +++ b/ARMeilleure/Instructions/InstEmitSimdShift.cs @@ -5,6 +5,7 @@ using ARMeilleure.IntermediateRepresentation; using ARMeilleure.Translation; using System; using System.Diagnostics; +using System.Reflection; using static ARMeilleure.Instructions.InstEmitHelper; using static ARMeilleure.Instructions.InstEmitSimdHelper; @@ -198,7 +199,7 @@ namespace ARMeilleure.Instructions Operand ne = EmitVectorExtractSx(context, op.Rn, index, op.Size); Operand me = EmitVectorExtractSx(context, op.Rm, index, op.Size); - Operand e = context.SoftFallbackCall(nameof(SoftFallback.SignedShlRegSatQ), ne, me, Const(1), Const(op.Size)); + Operand e = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SignedShlRegSatQ)), ne, me, Const(1), Const(op.Size)); res = EmitVectorInsert(context, res, e, index, op.Size); } @@ -239,7 +240,7 @@ namespace ARMeilleure.Instructions Operand ne = EmitVectorExtractSx(context, op.Rn, index, op.Size); Operand me = EmitVectorExtractSx(context, op.Rm, index, op.Size); - Operand e = context.SoftFallbackCall(nameof(SoftFallback.SignedShlRegSatQ), ne, me, Const(0), Const(op.Size)); + Operand e = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SignedShlRegSatQ)), ne, me, Const(0), Const(op.Size)); res = EmitVectorInsert(context, res, e, index, op.Size); } @@ -290,7 +291,7 @@ namespace ARMeilleure.Instructions Operand ne = EmitVectorExtractSx(context, op.Rn, index, op.Size); Operand me = EmitVectorExtractSx(context, op.Rm, index, op.Size); - Operand e = context.SoftFallbackCall(nameof(SoftFallback.SignedShlReg), ne, me, Const(1), Const(op.Size)); + Operand e = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SignedShlReg)), ne, me, Const(1), Const(op.Size)); res = EmitVectorInsert(context, res, e, index, op.Size); } @@ -403,7 +404,7 @@ namespace ARMeilleure.Instructions Operand ne = EmitVectorExtractSx(context, op.Rn, index, op.Size); Operand me = EmitVectorExtractSx(context, op.Rm, index, op.Size); - Operand e = context.SoftFallbackCall(nameof(SoftFallback.SignedShlReg), ne, me, Const(0), Const(op.Size)); + Operand e = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SignedShlReg)), ne, me, Const(0), Const(op.Size)); res = EmitVectorInsert(context, res, e, index, op.Size); } @@ -527,7 +528,7 @@ namespace ARMeilleure.Instructions Operand ne = EmitVectorExtractZx(context, op.Rn, index, op.Size); Operand me = EmitVectorExtractZx(context, op.Rm, index, op.Size); - Operand e = context.SoftFallbackCall(nameof(SoftFallback.UnsignedShlRegSatQ), ne, me, Const(1), Const(op.Size)); + Operand e = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnsignedShlRegSatQ)), ne, me, Const(1), Const(op.Size)); res = EmitVectorInsert(context, res, e, index, op.Size); } @@ -558,7 +559,7 @@ namespace ARMeilleure.Instructions Operand ne = EmitVectorExtractZx(context, op.Rn, index, op.Size); Operand me = EmitVectorExtractZx(context, op.Rm, index, op.Size); - Operand e = context.SoftFallbackCall(nameof(SoftFallback.UnsignedShlRegSatQ), ne, me, Const(0), Const(op.Size)); + Operand e = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnsignedShlRegSatQ)), ne, me, Const(0), Const(op.Size)); res = EmitVectorInsert(context, res, e, index, op.Size); } @@ -589,7 +590,7 @@ namespace ARMeilleure.Instructions Operand ne = EmitVectorExtractZx(context, op.Rn, index, op.Size); Operand me = EmitVectorExtractZx(context, op.Rm, index, op.Size); - Operand e = context.SoftFallbackCall(nameof(SoftFallback.UnsignedShlReg), ne, me, Const(1), Const(op.Size)); + Operand e = context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnsignedShlReg)), ne, me, Const(1), Const(op.Size)); res = EmitVectorInsert(context, res, e, index, op.Size); } @@ -1026,9 +1027,11 @@ namespace ARMeilleure.Instructions long roundConst, int shift) { - string name = signed ? nameof(SoftFallback.SignedShrImm64) : nameof(SoftFallback.UnsignedShrImm64); + MethodInfo info = signed + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.SignedShrImm64)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnsignedShrImm64)); - return context.SoftFallbackCall(name, value, Const(roundConst), Const(shift)); + return context.Call(info, value, Const(roundConst), Const(shift)); } private static void EmitVectorShImmWidenBinarySx(ArmEmitterContext context, Func2I emit, int imm) diff --git a/ARMeilleure/Instructions/InstEmitSystem.cs b/ARMeilleure/Instructions/InstEmitSystem.cs index 9650b1e5e1..848ccbf219 100644 --- a/ARMeilleure/Instructions/InstEmitSystem.cs +++ b/ARMeilleure/Instructions/InstEmitSystem.cs @@ -3,6 +3,7 @@ using ARMeilleure.IntermediateRepresentation; using ARMeilleure.State; using ARMeilleure.Translation; using System; +using System.Reflection; using static ARMeilleure.Instructions.InstEmitHelper; using static ARMeilleure.IntermediateRepresentation.OperandHelper; @@ -27,43 +28,43 @@ namespace ARMeilleure.Instructions { OpCodeSystem op = (OpCodeSystem)context.CurrOp; - string name; + MethodInfo info; switch (GetPackedId(op)) { - case 0b11_011_0000_0000_001: name = nameof(NativeInterface.GetCtrEl0); break; - case 0b11_011_0000_0000_111: name = nameof(NativeInterface.GetDczidEl0); break; - case 0b11_011_0100_0010_000: EmitGetNzcv(context); return; - case 0b11_011_0100_0100_000: name = nameof(NativeInterface.GetFpcr); break; - case 0b11_011_0100_0100_001: name = nameof(NativeInterface.GetFpsr); break; - case 0b11_011_1101_0000_010: name = nameof(NativeInterface.GetTpidrEl0); break; - case 0b11_011_1101_0000_011: name = nameof(NativeInterface.GetTpidr); break; - case 0b11_011_1110_0000_000: name = nameof(NativeInterface.GetCntfrqEl0); break; - case 0b11_011_1110_0000_001: name = nameof(NativeInterface.GetCntpctEl0); break; + case 0b11_011_0000_0000_001: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetCtrEl0)); break; + case 0b11_011_0000_0000_111: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetDczidEl0)); break; + case 0b11_011_0100_0010_000: EmitGetNzcv(context); return; + case 0b11_011_0100_0100_000: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetFpcr)); break; + case 0b11_011_0100_0100_001: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetFpsr)); break; + case 0b11_011_1101_0000_010: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetTpidrEl0)); break; + case 0b11_011_1101_0000_011: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetTpidr)); break; + case 0b11_011_1110_0000_000: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetCntfrqEl0)); break; + case 0b11_011_1110_0000_001: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetCntpctEl0)); break; default: throw new NotImplementedException($"Unknown MRS 0x{op.RawOpCode:X8} at 0x{op.Address:X16}."); } - SetIntOrZR(context, op.Rt, context.NativeInterfaceCall(name)); + SetIntOrZR(context, op.Rt, context.Call(info)); } public static void Msr(ArmEmitterContext context) { OpCodeSystem op = (OpCodeSystem)context.CurrOp; - string name; + MethodInfo info; switch (GetPackedId(op)) { - case 0b11_011_0100_0010_000: EmitSetNzcv(context); return; - case 0b11_011_0100_0100_000: name = nameof(NativeInterface.SetFpcr); break; - case 0b11_011_0100_0100_001: name = nameof(NativeInterface.SetFpsr); break; - case 0b11_011_1101_0000_010: name = nameof(NativeInterface.SetTpidrEl0); break; + case 0b11_011_0100_0010_000: EmitSetNzcv(context); return; + case 0b11_011_0100_0100_000: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.SetFpcr)); break; + case 0b11_011_0100_0100_001: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.SetFpsr)); break; + case 0b11_011_1101_0000_010: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.SetTpidrEl0)); break; default: throw new NotImplementedException($"Unknown MSR 0x{op.RawOpCode:X8} at 0x{op.Address:X16}."); } - context.NativeInterfaceCall(name, GetIntOrZR(context, op.Rt)); + context.Call(info, GetIntOrZR(context, op.Rt)); } public static void Nop(ArmEmitterContext context) @@ -89,7 +90,7 @@ namespace ARMeilleure.Instructions { Operand address = context.Add(t, Const(offset)); - context.NativeInterfaceCall(nameof(NativeInterface.WriteUInt64), address, Const(0L)); + context.Call(typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt64)), address, Const(0L)); } break; diff --git a/ARMeilleure/Instructions/SoftFallback.cs b/ARMeilleure/Instructions/SoftFallback.cs index 50e43bc010..10bb47df54 100644 --- a/ARMeilleure/Instructions/SoftFallback.cs +++ b/ARMeilleure/Instructions/SoftFallback.cs @@ -1240,12 +1240,5 @@ namespace ARMeilleure.Instructions : (uint)(value >> 32); } #endregion - -#region "MaxMin" - public static long MaxS64(long val1, long val2) => (val1 >= val2) ? val1 : val2; - public static ulong MaxU64(ulong val1, ulong val2) => (val1 >= val2) ? val1 : val2; - public static long MinS64(long val1, long val2) => (val1 <= val2) ? val1 : val2; - public static ulong MinU64(ulong val1, ulong val2) => (val1 <= val2) ? val1 : val2; -#endregion } } diff --git a/ARMeilleure/Translation/DelegateHelpers.cs b/ARMeilleure/Translation/DelegateHelpers.cs index 47101aeccf..2d4292548a 100644 --- a/ARMeilleure/Translation/DelegateHelpers.cs +++ b/ARMeilleure/Translation/DelegateHelpers.cs @@ -23,53 +23,19 @@ namespace ARMeilleure.Translation _delegateTypesCache = new Dictionary(); } - public static Delegate GetDelegate(Type type, string name) + public static Delegate GetDelegate(MethodInfo info) { - if (type == null) + if (info == null) { throw new ArgumentNullException(); } - if (name == null) - { - throw new ArgumentNullException(); - } - - MethodInfo methodInfo = type.GetMethod(name); - - return GetDelegate(methodInfo); - } - - public static Delegate GetDelegate(Type type, string name, Type[] types) - { - if (type == null) - { - throw new ArgumentNullException(); - } - - if (name == null) - { - throw new ArgumentNullException(); - } - - if (types == null) - { - throw new ArgumentNullException(); - } - - MethodInfo methodInfo = type.GetMethod(name, types); - - return GetDelegate(methodInfo); - } - - private static Delegate GetDelegate(MethodInfo methodInfo) - { - Type[] parameters = methodInfo.GetParameters().Select(pI => pI.ParameterType).ToArray(); - Type returnType = methodInfo.ReturnType; + Type[] parameters = info.GetParameters().Select(pI => pI.ParameterType).ToArray(); + Type returnType = info.ReturnType; Type delegateType = GetDelegateType(parameters, returnType); - return Delegate.CreateDelegate(delegateType, methodInfo); + return Delegate.CreateDelegate(delegateType, info); } private static Type GetDelegateType(Type[] parameters, Type returnType) diff --git a/ARMeilleure/Translation/Delegates.cs b/ARMeilleure/Translation/Delegates.cs index 3728672eb6..35f3ca223e 100644 --- a/ARMeilleure/Translation/Delegates.cs +++ b/ARMeilleure/Translation/Delegates.cs @@ -14,25 +14,7 @@ namespace ARMeilleure.Translation throw new ArgumentNullException(); } - if (_nativeInterfaceDelegates.TryGetValue(key, out DelegateInfo dlgInfo)) - { - funcPtr = dlgInfo.FuncPtr; - - return true; - } - else if (_softFallbackDelegates.TryGetValue(key, out dlgInfo)) - { - funcPtr = dlgInfo.FuncPtr; - - return true; - } - else if (_mathDelegates.TryGetValue(key, out dlgInfo)) - { - funcPtr = dlgInfo.FuncPtr; - - return true; - } - else if (_softFloatDelegates.TryGetValue(key, out dlgInfo)) + if (_delegates.TryGetValue(key, out DelegateInfo dlgInfo)) { funcPtr = dlgInfo.FuncPtr; @@ -46,14 +28,14 @@ namespace ARMeilleure.Translation } } - public static DelegateInfo GetMathDelegateInfo(string key) + public static DelegateInfo GetDelegateInfo(string key) { if (key == null) { throw new ArgumentNullException(); } - if (!_mathDelegates.TryGetValue(key, out DelegateInfo dlgInfo)) + if (!_delegates.TryGetValue(key, out DelegateInfo dlgInfo)) { throw new Exception(); } @@ -61,277 +43,189 @@ namespace ARMeilleure.Translation return dlgInfo; } - public static DelegateInfo GetNativeInterfaceDelegateInfo(string key) + private static void SetDelegateInfo(MethodInfo info) { - if (key == null) - { - throw new ArgumentNullException(); - } + string key = $"{info.DeclaringType.Name}.{info.Name}"; - if (!_nativeInterfaceDelegates.TryGetValue(key, out DelegateInfo dlgInfo)) - { - throw new Exception(); - } + Delegate dlg = DelegateHelpers.GetDelegate(info); - return dlgInfo; - } - - public static DelegateInfo GetSoftFallbackDelegateInfo(string key) - { - if (key == null) - { - throw new ArgumentNullException(); - } - - if (!_softFallbackDelegates.TryGetValue(key, out DelegateInfo dlgInfo)) - { - throw new Exception(); - } - - return dlgInfo; - } - - public static DelegateInfo GetSoftFloatDelegateInfo(string key) - { - if (key == null) - { - throw new ArgumentNullException(); - } - - if (!_softFloatDelegates.TryGetValue(key, out DelegateInfo dlgInfo)) - { - throw new Exception(); - } - - return dlgInfo; - } - - private static void SetMathDelegateInfo(Type type, string name, Type[] types) - { - Delegate dlg = DelegateHelpers.GetDelegate(type, name, types); - - if (!_mathDelegates.TryAdd(GetKey(dlg.Method), new DelegateInfo(dlg))) + if (!_delegates.TryAdd(key, new DelegateInfo(dlg))) { throw new Exception(); } } - private static void SetNativeInterfaceDelegateInfo(string name) - { - Delegate dlg = DelegateHelpers.GetDelegate(typeof(NativeInterface), name); - - if (!_nativeInterfaceDelegates.TryAdd(GetKey(dlg.Method), new DelegateInfo(dlg))) - { - throw new Exception(); - } - } - - private static void SetSoftFallbackDelegateInfo(string name) - { - Delegate dlg = DelegateHelpers.GetDelegate(typeof(SoftFallback), name); - - if (!_softFallbackDelegates.TryAdd(GetKey(dlg.Method), new DelegateInfo(dlg))) - { - throw new Exception(); - } - } - - private static void SetSoftFloatDelegateInfo(Type type, string name) - { - Delegate dlg = DelegateHelpers.GetDelegate(type, name); - - if (!_softFloatDelegates.TryAdd(GetKey(dlg.Method), new DelegateInfo(dlg))) - { - throw new Exception(); - } - } - - private static string GetKey(MethodInfo info) - { - return $"{info.DeclaringType.Name}.{info.Name}"; - } - - private static readonly Dictionary _mathDelegates; - private static readonly Dictionary _nativeInterfaceDelegates; - private static readonly Dictionary _softFallbackDelegates; - private static readonly Dictionary _softFloatDelegates; + private static readonly Dictionary _delegates; static Delegates() { - _mathDelegates = new Dictionary(); - _nativeInterfaceDelegates = new Dictionary(); - _softFallbackDelegates = new Dictionary(); - _softFloatDelegates = new Dictionary(); + _delegates = new Dictionary(); - SetMathDelegateInfo(typeof(Math), nameof(Math.Abs), new Type[] { typeof(double) }); - SetMathDelegateInfo(typeof(Math), nameof(Math.Ceiling), new Type[] { typeof(double) }); - SetMathDelegateInfo(typeof(Math), nameof(Math.Floor), new Type[] { typeof(double) }); - SetMathDelegateInfo(typeof(Math), nameof(Math.Round), new Type[] { typeof(double), typeof(MidpointRounding) }); - SetMathDelegateInfo(typeof(Math), nameof(Math.Truncate), new Type[] { typeof(double) }); + SetDelegateInfo(typeof(Math).GetMethod(nameof(Math.Abs), new Type[] { typeof(double) })); + SetDelegateInfo(typeof(Math).GetMethod(nameof(Math.Ceiling), new Type[] { typeof(double) })); + SetDelegateInfo(typeof(Math).GetMethod(nameof(Math.Floor), new Type[] { typeof(double) })); + SetDelegateInfo(typeof(Math).GetMethod(nameof(Math.Round), new Type[] { typeof(double), typeof(MidpointRounding) })); + SetDelegateInfo(typeof(Math).GetMethod(nameof(Math.Truncate), new Type[] { typeof(double) })); - SetMathDelegateInfo(typeof(MathF), nameof(MathF.Abs), new Type[] { typeof(float) }); - SetMathDelegateInfo(typeof(MathF), nameof(MathF.Ceiling), new Type[] { typeof(float) }); - SetMathDelegateInfo(typeof(MathF), nameof(MathF.Floor), new Type[] { typeof(float) }); - SetMathDelegateInfo(typeof(MathF), nameof(MathF.Round), new Type[] { typeof(float), typeof(MidpointRounding) }); - SetMathDelegateInfo(typeof(MathF), nameof(MathF.Truncate), new Type[] { typeof(float) }); + SetDelegateInfo(typeof(MathF).GetMethod(nameof(MathF.Abs), new Type[] { typeof(float) })); + SetDelegateInfo(typeof(MathF).GetMethod(nameof(MathF.Ceiling), new Type[] { typeof(float) })); + SetDelegateInfo(typeof(MathF).GetMethod(nameof(MathF.Floor), new Type[] { typeof(float) })); + SetDelegateInfo(typeof(MathF).GetMethod(nameof(MathF.Round), new Type[] { typeof(float), typeof(MidpointRounding) })); + SetDelegateInfo(typeof(MathF).GetMethod(nameof(MathF.Truncate), new Type[] { typeof(float) })); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.Break)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.CheckSynchronization)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.ClearExclusive)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.GetCntfrqEl0)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.GetCntpctEl0)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.GetCtrEl0)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.GetDczidEl0)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.GetFpcr)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.GetFpsr)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.GetTpidr)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.GetTpidrEl0)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.ReadByte)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.ReadByteExclusive)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.ReadUInt16)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.ReadUInt16Exclusive)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.ReadUInt32)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.ReadUInt32Exclusive)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.ReadUInt64)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.ReadUInt64Exclusive)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.ReadVector128)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.ReadVector128Exclusive)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.SetFpcr)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.SetFpsr)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.SetTpidrEl0)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.SupervisorCall)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.Undefined)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.WriteByte)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.WriteByteExclusive)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.WriteUInt16)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.WriteUInt16Exclusive)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.WriteUInt32)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.WriteUInt32Exclusive)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.WriteUInt64)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.WriteUInt64Exclusive)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.WriteVector128)); - SetNativeInterfaceDelegateInfo(nameof(NativeInterface.WriteVector128Exclusive)); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.Break))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.CheckSynchronization))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.ClearExclusive))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetCntfrqEl0))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetCntpctEl0))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetCtrEl0))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetDczidEl0))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetFpcr))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetFpsr))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetTpidr))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.GetTpidrEl0))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadByte))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadByteExclusive))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt16))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt16Exclusive))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt32))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt32Exclusive))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt64))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt64Exclusive))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadVector128))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadVector128Exclusive))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.SetFpcr))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.SetFpsr))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.SetTpidrEl0))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.SupervisorCall))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.Undefined))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteByte))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteByteExclusive))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt16))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt16Exclusive))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt32))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt32Exclusive))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt64))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt64Exclusive))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteVector128))); + SetDelegateInfo(typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteVector128Exclusive))); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.BinarySignedSatQAcc)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.BinarySignedSatQAdd)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.BinarySignedSatQSub)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.BinaryUnsignedSatQAcc)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.BinaryUnsignedSatQAdd)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.BinaryUnsignedSatQSub)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.CountLeadingSigns)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.CountLeadingZeros)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.CountSetBits8)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Crc32b)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Crc32cb)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Crc32ch)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Crc32cw)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Crc32cx)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Crc32h)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Crc32w)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Crc32x)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Decrypt)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Encrypt)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.FixedRotate)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.HashChoose)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.HashLower)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.HashMajority)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.HashParity)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.HashUpper)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.InverseMixColumns)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.MaxS64)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.MaxU64)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.MinS64)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.MinU64)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.MixColumns)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Round)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.RoundF)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.SatF32ToS32)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.SatF32ToS64)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.SatF32ToU32)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.SatF32ToU64)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.SatF64ToS32)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.SatF64ToS64)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.SatF64ToU32)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.SatF64ToU64)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Sha1SchedulePart1)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Sha1SchedulePart2)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Sha256SchedulePart1)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Sha256SchedulePart2)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.SignedShlReg)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.SignedShlRegSatQ)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.SignedShrImm64)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.SignedSrcSignedDstSatQ)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.SignedSrcUnsignedDstSatQ)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Tbl1)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Tbl2)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Tbl3)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Tbl4)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Tbx1)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Tbx2)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Tbx3)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.Tbx4)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.UnarySignedSatQAbsOrNeg)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.UnsignedShlReg)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.UnsignedShlRegSatQ)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.UnsignedShrImm64)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.UnsignedSrcSignedDstSatQ)); - SetSoftFallbackDelegateInfo(nameof(SoftFallback.UnsignedSrcUnsignedDstSatQ)); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinarySignedSatQAcc))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinarySignedSatQAdd))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinarySignedSatQSub))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinaryUnsignedSatQAcc))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinaryUnsignedSatQAdd))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinaryUnsignedSatQSub))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.CountLeadingSigns))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.CountLeadingZeros))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.CountSetBits8))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Crc32b))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Crc32cb))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Crc32ch))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Crc32cw))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Crc32cx))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Crc32h))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Crc32w))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Crc32x))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Decrypt))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Encrypt))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.FixedRotate))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.HashChoose))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.HashLower))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.HashMajority))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.HashParity))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.HashUpper))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.InverseMixColumns))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.MixColumns))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Round))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.RoundF))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF32ToS32))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF32ToS64))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF32ToU32))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF32ToU64))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF64ToS32))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF64ToS64))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF64ToU32))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SatF64ToU64))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Sha1SchedulePart1))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Sha1SchedulePart2))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Sha256SchedulePart1))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Sha256SchedulePart2))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SignedShlReg))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SignedShlRegSatQ))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SignedShrImm64))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SignedSrcSignedDstSatQ))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.SignedSrcUnsignedDstSatQ))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Tbl1))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Tbl2))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Tbl3))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Tbl4))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Tbx1))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Tbx2))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Tbx3))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Tbx4))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnarySignedSatQAbsOrNeg))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnsignedShlReg))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnsignedShlRegSatQ))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnsignedShrImm64))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnsignedSrcSignedDstSatQ))); + SetDelegateInfo(typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnsignedSrcUnsignedDstSatQ))); - SetSoftFloatDelegateInfo(typeof(SoftFloat16_32), nameof(SoftFloat16_32.FPConvert)); + SetDelegateInfo(typeof(SoftFloat16_32).GetMethod(nameof(SoftFloat16_32.FPConvert))); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPAdd)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPCompare)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPCompareEQ)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPCompareGE)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPCompareGT)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPCompareLE)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPCompareLT)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPDiv)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPMax)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPMaxNum)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPMin)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPMinNum)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPMul)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPMulAdd)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPMulSub)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPMulX)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPNegMulAdd)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPNegMulSub)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPRecipEstimate)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPRecipStepFused)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPRecpX)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPRSqrtEstimate)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPRSqrtStepFused)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPSqrt)); - SetSoftFloatDelegateInfo(typeof(SoftFloat32), nameof(SoftFloat32.FPSub)); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPAdd))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPCompare))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPCompareEQ))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPCompareGE))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPCompareGT))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPCompareLE))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPCompareLT))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPDiv))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPMax))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPMaxNum))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPMin))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPMinNum))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPMul))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPMulAdd))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPMulSub))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPMulX))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPNegMulAdd))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPNegMulSub))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPRecipEstimate))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPRecipStepFused))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPRecpX))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPRSqrtEstimate))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPRSqrtStepFused))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPSqrt))); + SetDelegateInfo(typeof(SoftFloat32).GetMethod(nameof(SoftFloat32.FPSub))); - SetSoftFloatDelegateInfo(typeof(SoftFloat32_16), nameof(SoftFloat32_16.FPConvert)); + SetDelegateInfo(typeof(SoftFloat32_16).GetMethod(nameof(SoftFloat32_16.FPConvert))); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPAdd)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPCompare)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPCompareEQ)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPCompareGE)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPCompareGT)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPCompareLE)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPCompareLT)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPDiv)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPMax)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPMaxNum)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPMin)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPMinNum)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPMul)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPMulAdd)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPMulSub)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPMulX)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPNegMulAdd)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPNegMulSub)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPRecipEstimate)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPRecipStepFused)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPRecpX)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPRSqrtEstimate)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPRSqrtStepFused)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPSqrt)); - SetSoftFloatDelegateInfo(typeof(SoftFloat64), nameof(SoftFloat64.FPSub)); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPAdd))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPCompare))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPCompareEQ))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPCompareGE))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPCompareGT))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPCompareLE))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPCompareLT))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPDiv))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPMax))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPMaxNum))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPMin))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPMinNum))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPMul))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPMulAdd))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPMulSub))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPMulX))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPNegMulAdd))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPNegMulSub))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPRecipEstimate))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPRecipStepFused))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPRecpX))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPRSqrtEstimate))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPRSqrtStepFused))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPSqrt))); + SetDelegateInfo(typeof(SoftFloat64).GetMethod(nameof(SoftFloat64.FPSub))); } } } diff --git a/ARMeilleure/Translation/EmitterContext.cs b/ARMeilleure/Translation/EmitterContext.cs index dc6101995f..9baba0e6d3 100644 --- a/ARMeilleure/Translation/EmitterContext.cs +++ b/ARMeilleure/Translation/EmitterContext.cs @@ -1,7 +1,7 @@ -using ARMeilleure.Instructions; using ARMeilleure.IntermediateRepresentation; using System; using System.Collections.Generic; +using System.Reflection; using static ARMeilleure.IntermediateRepresentation.OperandHelper; @@ -79,38 +79,11 @@ namespace ARMeilleure.Translation return Add(Instruction.ByteSwap, Local(op1.Type), op1); } - public Operand MathCall(string className, string funcName, params Operand[] callArgs) + public Operand Call(MethodInfo info, params Operand[] callArgs) { - string name = $"{className}.{funcName}"; + string name = $"{info.DeclaringType.Name}.{info.Name}"; - DelegateInfo dlgInfo = Delegates.GetMathDelegateInfo(name); - - return Call(Const(dlgInfo.FuncPtr.ToInt64(), Aot.Enabled, name), dlgInfo.RetType, callArgs); - } - - public Operand NativeInterfaceCall(string funcName, params Operand[] callArgs) - { - string name = $"{nameof(NativeInterface)}.{funcName}"; - - DelegateInfo dlgInfo = Delegates.GetNativeInterfaceDelegateInfo(name); - - return Call(Const(dlgInfo.FuncPtr.ToInt64(), Aot.Enabled, name), dlgInfo.RetType, callArgs); - } - - public Operand SoftFallbackCall(string funcName, params Operand[] callArgs) - { - string name = $"{nameof(SoftFallback)}.{funcName}"; - - DelegateInfo dlgInfo = Delegates.GetSoftFallbackDelegateInfo(name); - - return Call(Const(dlgInfo.FuncPtr.ToInt64(), Aot.Enabled, name), dlgInfo.RetType, callArgs); - } - - public Operand SoftFloatCall(string className, string funcName, params Operand[] callArgs) - { - string name = $"{className}.{funcName}"; - - DelegateInfo dlgInfo = Delegates.GetSoftFloatDelegateInfo(name); + DelegateInfo dlgInfo = Delegates.GetDelegateInfo(name); return Call(Const(dlgInfo.FuncPtr.ToInt64(), Aot.Enabled, name), dlgInfo.RetType, callArgs); } diff --git a/ARMeilleure/Translation/Translator.cs b/ARMeilleure/Translation/Translator.cs index da67b0afb5..d7b28d0b16 100644 --- a/ARMeilleure/Translation/Translator.cs +++ b/ARMeilleure/Translation/Translator.cs @@ -289,7 +289,7 @@ namespace ARMeilleure.Translation context.BranchIfTrue(lblNonZero, count); - context.NativeInterfaceCall(nameof(NativeInterface.CheckSynchronization)); + context.Call(typeof(NativeInterface).GetMethod(nameof(NativeInterface.CheckSynchronization))); context.Branch(lblExit);