diff options
Diffstat (limited to 'ARMeilleure/Instructions/InstEmitSimdHelper.cs')
-rw-r--r-- | ARMeilleure/Instructions/InstEmitSimdHelper.cs | 106 |
1 files changed, 39 insertions, 67 deletions
diff --git a/ARMeilleure/Instructions/InstEmitSimdHelper.cs b/ARMeilleure/Instructions/InstEmitSimdHelper.cs index bf8d54c1..912c2260 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; @@ -310,68 +311,39 @@ namespace ARMeilleure.Instructions context.Copy(GetVec(op.Rd), res); } - public static Operand EmitUnaryMathCall(ArmEmitterContext context, _F32_F32 f32, _F64_F64 f64, Operand n) + public static Operand EmitUnaryMathCall(ArmEmitterContext context, string name, Operand n) { IOpCodeSimd op = (IOpCodeSimd)context.CurrOp; - return (op.Size & 1) == 0 ? context.Call(f32, n) : context.Call(f64, n); - } - - public static Operand EmitRoundMathCall(ArmEmitterContext context, MidpointRounding roundMode, Operand n) - { - IOpCodeSimd op = (IOpCodeSimd)context.CurrOp; - - Delegate dlg; - - if ((op.Size & 1) == 0) - { - dlg = new _F32_F32_MidpointRounding(MathF.Round); - } - else /* if ((op.Size & 1) == 1) */ - { - dlg = new _F64_F64_MidpointRounding(Math.Round); - } + 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(dlg, n, Const((int)roundMode)); + return context.Call(info, n); } - public static Operand EmitSoftFloatCall( - ArmEmitterContext context, - _F32_F32 f32, - _F64_F64 f64, - params Operand[] callArgs) + public static Operand EmitRoundMathCall(ArmEmitterContext context, MidpointRounding roundMode, Operand n) { IOpCodeSimd op = (IOpCodeSimd)context.CurrOp; - Delegate dlg = (op.Size & 1) == 0 ? (Delegate)f32 : (Delegate)f64; - - return context.Call(dlg, callArgs); - } - - public static Operand EmitSoftFloatCall( - ArmEmitterContext context, - _F32_F32_F32 f32, - _F64_F64_F64 f64, - params Operand[] callArgs) - { - IOpCodeSimd op = (IOpCodeSimd)context.CurrOp; + string name = nameof(Math.Round); - Delegate dlg = (op.Size & 1) == 0 ? (Delegate)f32 : (Delegate)f64; + 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(dlg, callArgs); + return context.Call(info, n, Const((int)roundMode)); } - public static Operand EmitSoftFloatCall( - ArmEmitterContext context, - _F32_F32_F32_F32 f32, - _F64_F64_F64_F64 f64, - params Operand[] callArgs) + public static Operand EmitSoftFloatCall(ArmEmitterContext context, string name, params Operand[] callArgs) { IOpCodeSimd op = (IOpCodeSimd)context.CurrOp; - Delegate dlg = (op.Size & 1) == 0 ? (Delegate)f32 : (Delegate)f64; + MethodInfo info = (op.Size & 1) == 0 + ? typeof(SoftFloat32).GetMethod(name) + : typeof(SoftFloat64).GetMethod(name); - return context.Call(dlg, callArgs); + return context.Call(info, callArgs); } public static void EmitScalarBinaryOpByElemF(ArmEmitterContext context, Func2I emit) @@ -1425,22 +1397,22 @@ namespace ARMeilleure.Instructions throw new ArgumentOutOfRangeException(nameof(sizeDst)); } - Delegate dlg; + MethodInfo info; if (signedSrc) { - dlg = signedDst - ? (Delegate)new _S64_S64_S32(SoftFallback.SignedSrcSignedDstSatQ) - : (Delegate)new _U64_S64_S32(SoftFallback.SignedSrcUnsignedDstSatQ); + info = signedDst + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.SignedSrcSignedDstSatQ)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.SignedSrcUnsignedDstSatQ)); } else { - dlg = signedDst - ? (Delegate)new _S64_U64_S32(SoftFallback.UnsignedSrcSignedDstSatQ) - : (Delegate)new _U64_U64_S32(SoftFallback.UnsignedSrcUnsignedDstSatQ); + info = signedDst + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnsignedSrcSignedDstSatQ)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnsignedSrcUnsignedDstSatQ)); } - return context.Call(dlg, op, Const(sizeDst)); + return context.Call(info, op, Const(sizeDst)); } // TSrc (64bit) == TDst (64bit); signed. @@ -1448,7 +1420,7 @@ namespace ARMeilleure.Instructions { Debug.Assert(((OpCodeSimd)context.CurrOp).Size == 3, "Invalid element size."); - return context.Call(new _S64_S64(SoftFallback.UnarySignedSatQAbsOrNeg), op); + return context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnarySignedSatQAbsOrNeg)), op); } // TSrcs (64bit) == TDst (64bit); signed, unsigned. @@ -1456,11 +1428,11 @@ namespace ARMeilleure.Instructions { Debug.Assert(((OpCodeSimd)context.CurrOp).Size == 3, "Invalid element size."); - Delegate dlg = signed - ? (Delegate)new _S64_S64_S64(SoftFallback.BinarySignedSatQAdd) - : (Delegate)new _U64_U64_U64(SoftFallback.BinaryUnsignedSatQAdd); + MethodInfo info = signed + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinarySignedSatQAdd)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinaryUnsignedSatQAdd)); - return context.Call(dlg, op1, op2); + return context.Call(info, op1, op2); } // TSrcs (64bit) == TDst (64bit); signed, unsigned. @@ -1468,11 +1440,11 @@ namespace ARMeilleure.Instructions { Debug.Assert(((OpCodeSimd)context.CurrOp).Size == 3, "Invalid element size."); - Delegate dlg = signed - ? (Delegate)new _S64_S64_S64(SoftFallback.BinarySignedSatQSub) - : (Delegate)new _U64_U64_U64(SoftFallback.BinaryUnsignedSatQSub); + MethodInfo info = signed + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinarySignedSatQSub)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinaryUnsignedSatQSub)); - return context.Call(dlg, op1, op2); + return context.Call(info, op1, op2); } // TSrcs (64bit) == TDst (64bit); signed, unsigned. @@ -1480,11 +1452,11 @@ namespace ARMeilleure.Instructions { Debug.Assert(((OpCodeSimd)context.CurrOp).Size == 3, "Invalid element size."); - Delegate dlg = signed - ? (Delegate)new _S64_U64_S64(SoftFallback.BinarySignedSatQAcc) - : (Delegate)new _U64_S64_U64(SoftFallback.BinaryUnsignedSatQAcc); + MethodInfo info = signed + ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinarySignedSatQAcc)) + : typeof(SoftFallback).GetMethod(nameof(SoftFallback.BinaryUnsignedSatQAcc)); - return context.Call(dlg, op1, op2); + return context.Call(info, op1, op2); } public static Operand EmitFloatAbs(ArmEmitterContext context, Operand value, bool single, bool vector) @@ -1493,7 +1465,7 @@ namespace ARMeilleure.Instructions if (single) { mask = vector ? X86GetAllElements(context, -0f) : X86GetScalar(context, -0f); - } + } else { mask = vector ? X86GetAllElements(context, -0d) : X86GetScalar(context, -0d); |