2018-10-31 02:43:02 +01:00
|
|
|
using ChocolArm64.Decoders;
|
|
|
|
using ChocolArm64.State;
|
|
|
|
using ChocolArm64.Translation;
|
|
|
|
using System;
|
|
|
|
using System.Reflection.Emit;
|
|
|
|
using System.Runtime.Intrinsics;
|
|
|
|
using System.Runtime.Intrinsics.X86;
|
|
|
|
|
|
|
|
using static ChocolArm64.Instructions.InstEmitSimdHelper;
|
|
|
|
|
|
|
|
namespace ChocolArm64.Instructions
|
|
|
|
{
|
|
|
|
static partial class InstEmit
|
|
|
|
{
|
|
|
|
public static void Fcvt_S(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
|
|
|
|
|
|
|
|
if (Optimizations.UseSse2)
|
|
|
|
{
|
|
|
|
if (op.Size == 1 && op.Opc == 0)
|
|
|
|
{
|
|
|
|
//Double -> Single.
|
2019-03-13 09:23:52 +01:00
|
|
|
Type[] typesCvt = new Type[] { typeof(Vector128<float>), typeof(Vector128<double>) };
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-03-13 09:23:52 +01:00
|
|
|
VectorHelper.EmitCall(context, nameof(VectorHelper.VectorSingleZero));
|
2019-02-26 00:46:34 +01:00
|
|
|
context.EmitLdvec(op.Rn);
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-03-13 09:23:52 +01:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertScalarToVector128Single), typesCvt));
|
2018-10-31 02:43:02 +01:00
|
|
|
|
|
|
|
context.EmitStvec(op.Rd);
|
|
|
|
}
|
|
|
|
else if (op.Size == 0 && op.Opc == 1)
|
|
|
|
{
|
|
|
|
//Single -> Double.
|
2019-03-13 09:23:52 +01:00
|
|
|
Type[] typesCvt = new Type[] { typeof(Vector128<double>), typeof(Vector128<float>) };
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-04-03 14:21:22 +02:00
|
|
|
VectorHelper.EmitCall(context, nameof(VectorHelper.VectorSingleZero));
|
2018-10-31 02:43:02 +01:00
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
|
2019-03-13 09:23:52 +01:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertScalarToVector128Double), typesCvt));
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-02-26 00:46:34 +01:00
|
|
|
context.EmitStvec(op.Rd);
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Invalid encoding.
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitVectorExtractF(context, op.Rn, 0, op.Size);
|
|
|
|
|
|
|
|
EmitFloatCast(context, op.Opc);
|
|
|
|
|
|
|
|
EmitScalarSetF(context, op.Rd, op.Opc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtas_Gp(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
EmitFcvt_s_Gp(context, () => EmitRoundMathCall(context, MidpointRounding.AwayFromZero));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtau_Gp(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
EmitFcvt_u_Gp(context, () => EmitRoundMathCall(context, MidpointRounding.AwayFromZero));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtl_V(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
|
|
|
|
|
|
|
|
int sizeF = op.Size & 1;
|
|
|
|
|
2018-11-18 03:41:16 +01:00
|
|
|
if (Optimizations.UseSse2 && sizeF == 1)
|
|
|
|
{
|
|
|
|
Type[] typesCvt = new Type[] { typeof(Vector128<float>) };
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2018-11-18 03:41:16 +01:00
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
|
2019-03-13 09:23:52 +01:00
|
|
|
if (op.RegisterSize == RegisterSize.Simd128)
|
|
|
|
{
|
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MoveHighToLow)));
|
|
|
|
}
|
2018-11-18 03:41:16 +01:00
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Double), typesCvt));
|
|
|
|
|
2019-02-26 00:46:34 +01:00
|
|
|
context.EmitStvec(op.Rd);
|
2018-11-18 03:41:16 +01:00
|
|
|
}
|
|
|
|
else
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
2018-11-18 03:41:16 +01:00
|
|
|
int elems = 4 >> sizeF;
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2018-11-18 03:41:16 +01:00
|
|
|
int part = op.RegisterSize == RegisterSize.Simd128 ? elems : 0;
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2018-11-18 03:41:16 +01:00
|
|
|
for (int index = 0; index < elems; index++)
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
2018-11-18 03:41:16 +01:00
|
|
|
if (sizeF == 0)
|
|
|
|
{
|
|
|
|
EmitVectorExtractZx(context, op.Rn, part + index, 1);
|
|
|
|
context.Emit(OpCodes.Conv_U2);
|
|
|
|
|
|
|
|
context.EmitLdarg(TranslatedSub.StateArgIdx);
|
|
|
|
|
|
|
|
context.EmitCall(typeof(SoftFloat16_32), nameof(SoftFloat16_32.FPConvert));
|
|
|
|
}
|
|
|
|
else /* if (sizeF == 1) */
|
|
|
|
{
|
|
|
|
EmitVectorExtractF(context, op.Rn, part + index, 0);
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2018-11-18 03:41:16 +01:00
|
|
|
context.Emit(OpCodes.Conv_R8);
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitVectorInsertTmpF(context, index, sizeF);
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
2018-11-18 03:41:16 +01:00
|
|
|
context.EmitLdvectmp();
|
|
|
|
context.EmitStvec(op.Rd);
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtms_Gp(ILEmitterCtx context)
|
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
EmitFcvt_s_Gp(context, () => EmitUnaryMathCall(context, nameof(Math.Floor)));
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtmu_Gp(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
EmitFcvt_u_Gp(context, () => EmitUnaryMathCall(context, nameof(Math.Floor)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtn_V(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
|
|
|
|
|
|
|
|
int sizeF = op.Size & 1;
|
|
|
|
|
2018-11-18 03:41:16 +01:00
|
|
|
if (Optimizations.UseSse2 && sizeF == 1)
|
|
|
|
{
|
|
|
|
Type[] typesCvt = new Type[] { typeof(Vector128<double>) };
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2018-11-18 03:41:16 +01:00
|
|
|
string nameMov = op.RegisterSize == RegisterSize.Simd128
|
|
|
|
? nameof(Sse.MoveLowToHigh)
|
|
|
|
: nameof(Sse.MoveHighToLow);
|
2018-10-31 02:43:02 +01:00
|
|
|
|
|
|
|
context.EmitLdvec(op.Rd);
|
2018-11-18 03:41:16 +01:00
|
|
|
VectorHelper.EmitCall(context, nameof(VectorHelper.VectorSingleZero));
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-01-29 14:54:39 +01:00
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MoveLowToHigh)));
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-02-26 00:46:34 +01:00
|
|
|
context.EmitLdvec(op.Rn);
|
2018-11-18 03:41:16 +01:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Single), typesCvt));
|
|
|
|
context.Emit(OpCodes.Dup);
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-01-29 14:54:39 +01:00
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MoveLowToHigh)));
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-01-29 14:54:39 +01:00
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameMov));
|
2018-11-18 03:41:16 +01:00
|
|
|
|
|
|
|
context.EmitStvec(op.Rd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int elems = 4 >> sizeF;
|
|
|
|
|
|
|
|
int part = op.RegisterSize == RegisterSize.Simd128 ? elems : 0;
|
|
|
|
|
|
|
|
if (part != 0)
|
|
|
|
{
|
|
|
|
context.EmitLdvec(op.Rd);
|
|
|
|
context.EmitStvectmp();
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
2018-11-18 03:41:16 +01:00
|
|
|
|
|
|
|
for (int index = 0; index < elems; index++)
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
2018-11-18 03:41:16 +01:00
|
|
|
EmitVectorExtractF(context, op.Rn, index, sizeF);
|
|
|
|
|
|
|
|
if (sizeF == 0)
|
|
|
|
{
|
|
|
|
context.EmitLdarg(TranslatedSub.StateArgIdx);
|
|
|
|
|
|
|
|
context.EmitCall(typeof(SoftFloat32_16), nameof(SoftFloat32_16.FPConvert));
|
|
|
|
|
|
|
|
context.Emit(OpCodes.Conv_U8);
|
|
|
|
EmitVectorInsertTmp(context, part + index, 1);
|
|
|
|
}
|
|
|
|
else /* if (sizeF == 1) */
|
|
|
|
{
|
|
|
|
context.Emit(OpCodes.Conv_R4);
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2018-11-18 03:41:16 +01:00
|
|
|
EmitVectorInsertTmpF(context, part + index, 0);
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
2018-11-18 03:41:16 +01:00
|
|
|
context.EmitLdvectmp();
|
|
|
|
context.EmitStvec(op.Rd);
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2018-11-18 03:41:16 +01:00
|
|
|
if (part == 0)
|
|
|
|
{
|
|
|
|
EmitVectorZeroUpper(context, op.Rd);
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtns_S(ILEmitterCtx context)
|
|
|
|
{
|
2019-04-03 14:21:22 +02:00
|
|
|
if (Optimizations.UseSse41)
|
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
EmitSse41Fcvt_Signed(context, RoundMode.ToNearest, scalar: true);
|
2019-04-03 14:21:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitFcvtn(context, signed: true, scalar: true);
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtns_V(ILEmitterCtx context)
|
|
|
|
{
|
2019-04-03 14:21:22 +02:00
|
|
|
if (Optimizations.UseSse41)
|
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
EmitSse41Fcvt_Signed(context, RoundMode.ToNearest, scalar: false);
|
2019-04-03 14:21:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitFcvtn(context, signed: true, scalar: false);
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtnu_S(ILEmitterCtx context)
|
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
if (Optimizations.UseSse41)
|
|
|
|
{
|
|
|
|
EmitSse41Fcvt_Unsigned(context, RoundMode.ToNearest, scalar: true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitFcvtn(context, signed: false, scalar: true);
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtnu_V(ILEmitterCtx context)
|
|
|
|
{
|
2019-04-03 14:21:22 +02:00
|
|
|
if (Optimizations.UseSse41)
|
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
EmitSse41Fcvt_Unsigned(context, RoundMode.ToNearest, scalar: false);
|
2019-04-03 14:21:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
EmitFcvtn(context, signed: false, scalar: false);
|
2019-04-03 14:21:22 +02:00
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
public static void Fcvtps_Gp(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
EmitFcvt_s_Gp(context, () => EmitUnaryMathCall(context, nameof(Math.Ceiling)));
|
|
|
|
}
|
|
|
|
|
2018-10-31 02:43:02 +01:00
|
|
|
public static void Fcvtpu_Gp(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
EmitFcvt_u_Gp(context, () => EmitUnaryMathCall(context, nameof(Math.Ceiling)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtzs_Gp(ILEmitterCtx context)
|
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
EmitFcvt_s_Gp(context, () => { });
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
2018-12-11 01:58:52 +01:00
|
|
|
public static void Fcvtzs_Gp_Fixed(ILEmitterCtx context)
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
EmitFcvtzs_Gp_Fixed(context);
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtzs_S(ILEmitterCtx context)
|
|
|
|
{
|
2019-04-03 14:21:22 +02:00
|
|
|
if (Optimizations.UseSse41)
|
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
EmitSse41Fcvt_Signed(context, RoundMode.TowardsZero, scalar: true);
|
2019-04-03 14:21:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitFcvtz(context, signed: true, scalar: true);
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtzs_V(ILEmitterCtx context)
|
|
|
|
{
|
2019-04-03 14:21:22 +02:00
|
|
|
if (Optimizations.UseSse41)
|
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
EmitSse41Fcvt_Signed(context, RoundMode.TowardsZero, scalar: false);
|
2019-04-03 14:21:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitFcvtz(context, signed: true, scalar: false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtzs_V_Fixed(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
if (Optimizations.UseSse41)
|
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
EmitSse41Fcvt_Signed(context, RoundMode.TowardsZero, scalar: false);
|
2019-04-03 14:21:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitFcvtz(context, signed: true, scalar: false);
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtzu_Gp(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
EmitFcvt_u_Gp(context, () => { });
|
|
|
|
}
|
|
|
|
|
2018-12-11 01:58:52 +01:00
|
|
|
public static void Fcvtzu_Gp_Fixed(ILEmitterCtx context)
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
2019-02-24 00:52:48 +01:00
|
|
|
EmitFcvtzu_Gp_Fixed(context);
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtzu_S(ILEmitterCtx context)
|
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
if (Optimizations.UseSse41)
|
|
|
|
{
|
|
|
|
EmitSse41Fcvt_Unsigned(context, RoundMode.TowardsZero, scalar: true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitFcvtz(context, signed: false, scalar: true);
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void Fcvtzu_V(ILEmitterCtx context)
|
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
if (Optimizations.UseSse41)
|
|
|
|
{
|
|
|
|
EmitSse41Fcvt_Unsigned(context, RoundMode.TowardsZero, scalar: false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitFcvtz(context, signed: false, scalar: false);
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
2019-04-03 14:21:22 +02:00
|
|
|
public static void Fcvtzu_V_Fixed(ILEmitterCtx context)
|
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
if (Optimizations.UseSse41)
|
|
|
|
{
|
|
|
|
EmitSse41Fcvt_Unsigned(context, RoundMode.TowardsZero, scalar: false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitFcvtz(context, signed: false, scalar: false);
|
|
|
|
}
|
2019-04-03 14:21:22 +02:00
|
|
|
}
|
|
|
|
|
2018-10-31 02:43:02 +01:00
|
|
|
public static void Scvtf_Gp(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
OpCodeSimdCvt64 op = (OpCodeSimdCvt64)context.CurrOp;
|
|
|
|
|
|
|
|
context.EmitLdintzr(op.Rn);
|
|
|
|
|
|
|
|
if (context.CurrOp.RegisterSize == RegisterSize.Int32)
|
|
|
|
{
|
2019-04-21 04:07:35 +02:00
|
|
|
context.Emit(OpCodes.Conv_I4);
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EmitFloatCast(context, op.Size);
|
|
|
|
|
|
|
|
EmitScalarSetF(context, op.Rd, op.Size);
|
|
|
|
}
|
|
|
|
|
2019-02-24 00:52:48 +01:00
|
|
|
public static void Scvtf_Gp_Fixed(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
OpCodeSimdCvt64 op = (OpCodeSimdCvt64)context.CurrOp;
|
|
|
|
|
|
|
|
context.EmitLdintzr(op.Rn);
|
|
|
|
|
|
|
|
if (context.CurrOp.RegisterSize == RegisterSize.Int32)
|
|
|
|
{
|
|
|
|
context.Emit(OpCodes.Conv_I4);
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitFloatCast(context, op.Size);
|
|
|
|
|
|
|
|
EmitI2fFBitsMul(context, op.Size, op.FBits);
|
|
|
|
|
|
|
|
EmitScalarSetF(context, op.Rd, op.Size);
|
|
|
|
}
|
|
|
|
|
2018-10-31 02:43:02 +01:00
|
|
|
public static void Scvtf_S(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
|
|
|
|
|
2019-04-21 04:07:35 +02:00
|
|
|
int sizeF = op.Size & 1;
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-04-21 04:07:35 +02:00
|
|
|
if (Optimizations.UseSse2 && sizeF == 0)
|
|
|
|
{
|
|
|
|
EmitSse2cvtF_Signed(context, scalar: true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitVectorExtractSx(context, op.Rn, 0, sizeF + 2);
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-04-21 04:07:35 +02:00
|
|
|
EmitFloatCast(context, sizeF);
|
|
|
|
|
|
|
|
EmitScalarSetF(context, op.Rd, sizeF);
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void Scvtf_V(ILEmitterCtx context)
|
|
|
|
{
|
2018-11-18 03:41:16 +01:00
|
|
|
OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
|
|
|
|
|
|
|
|
int sizeF = op.Size & 1;
|
|
|
|
|
|
|
|
if (Optimizations.UseSse2 && sizeF == 0)
|
|
|
|
{
|
2019-04-21 04:07:35 +02:00
|
|
|
EmitSse2cvtF_Signed(context, scalar: false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitVectorCvtf(context, signed: true);
|
|
|
|
}
|
|
|
|
}
|
2018-11-18 03:41:16 +01:00
|
|
|
|
2019-04-21 04:07:35 +02:00
|
|
|
public static void Scvtf_V_Fixed(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
|
2018-11-18 03:41:16 +01:00
|
|
|
|
2019-04-21 04:07:35 +02:00
|
|
|
// sizeF == ((OpCodeSimdShImm64)op).Size - 2
|
|
|
|
int sizeF = op.Size & 1;
|
2018-11-18 03:41:16 +01:00
|
|
|
|
2019-04-21 04:07:35 +02:00
|
|
|
if (Optimizations.UseSse2 && sizeF == 0)
|
|
|
|
{
|
|
|
|
EmitSse2cvtF_Signed(context, scalar: false);
|
2018-11-18 03:41:16 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitVectorCvtf(context, signed: true);
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void Ucvtf_Gp(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
OpCodeSimdCvt64 op = (OpCodeSimdCvt64)context.CurrOp;
|
|
|
|
|
|
|
|
context.EmitLdintzr(op.Rn);
|
|
|
|
|
|
|
|
if (context.CurrOp.RegisterSize == RegisterSize.Int32)
|
|
|
|
{
|
|
|
|
context.Emit(OpCodes.Conv_U4);
|
|
|
|
}
|
|
|
|
|
|
|
|
context.Emit(OpCodes.Conv_R_Un);
|
|
|
|
|
|
|
|
EmitFloatCast(context, op.Size);
|
|
|
|
|
|
|
|
EmitScalarSetF(context, op.Rd, op.Size);
|
|
|
|
}
|
|
|
|
|
2019-02-24 00:52:48 +01:00
|
|
|
public static void Ucvtf_Gp_Fixed(ILEmitterCtx context)
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
2019-02-24 00:52:48 +01:00
|
|
|
OpCodeSimdCvt64 op = (OpCodeSimdCvt64)context.CurrOp;
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-02-24 00:52:48 +01:00
|
|
|
context.EmitLdintzr(op.Rn);
|
|
|
|
|
|
|
|
if (context.CurrOp.RegisterSize == RegisterSize.Int32)
|
|
|
|
{
|
|
|
|
context.Emit(OpCodes.Conv_U4);
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
|
|
|
|
context.Emit(OpCodes.Conv_R_Un);
|
|
|
|
|
|
|
|
EmitFloatCast(context, op.Size);
|
|
|
|
|
2019-02-24 00:52:48 +01:00
|
|
|
EmitI2fFBitsMul(context, op.Size, op.FBits);
|
|
|
|
|
2018-10-31 02:43:02 +01:00
|
|
|
EmitScalarSetF(context, op.Rd, op.Size);
|
|
|
|
}
|
|
|
|
|
2019-02-24 00:52:48 +01:00
|
|
|
public static void Ucvtf_S(ILEmitterCtx context)
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
2019-02-24 00:52:48 +01:00
|
|
|
OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-04-21 04:07:35 +02:00
|
|
|
int sizeF = op.Size & 1;
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-04-21 04:07:35 +02:00
|
|
|
if (Optimizations.UseSse2 && sizeF == 0)
|
|
|
|
{
|
|
|
|
EmitSse2cvtF_Unsigned(context, scalar: true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitVectorExtractZx(context, op.Rn, 0, sizeF + 2);
|
2019-02-24 00:52:48 +01:00
|
|
|
|
2019-04-21 04:07:35 +02:00
|
|
|
context.Emit(OpCodes.Conv_R_Un);
|
2019-02-24 00:52:48 +01:00
|
|
|
|
2019-04-21 04:07:35 +02:00
|
|
|
EmitFloatCast(context, sizeF);
|
|
|
|
|
|
|
|
EmitScalarSetF(context, op.Rd, sizeF);
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
2019-02-24 00:52:48 +01:00
|
|
|
public static void Ucvtf_V(ILEmitterCtx context)
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
2019-04-21 04:07:35 +02:00
|
|
|
OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
|
|
|
|
|
|
|
|
int sizeF = op.Size & 1;
|
|
|
|
|
|
|
|
if (Optimizations.UseSse2 && sizeF == 0)
|
|
|
|
{
|
|
|
|
EmitSse2cvtF_Unsigned(context, scalar: false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitVectorCvtf(context, signed: false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Ucvtf_V_Fixed(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
|
|
|
|
|
|
|
|
// sizeF == ((OpCodeSimdShImm64)op).Size - 2
|
|
|
|
int sizeF = op.Size & 1;
|
|
|
|
|
|
|
|
if (Optimizations.UseSse2 && sizeF == 0)
|
|
|
|
{
|
|
|
|
EmitSse2cvtF_Unsigned(context, scalar: false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitVectorCvtf(context, signed: false);
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitFcvtn(ILEmitterCtx context, bool signed, bool scalar)
|
|
|
|
{
|
|
|
|
OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
|
|
|
|
|
|
|
|
int sizeF = op.Size & 1;
|
|
|
|
int sizeI = sizeF + 2;
|
|
|
|
|
|
|
|
int bytes = op.GetBitsCount() >> 3;
|
|
|
|
int elems = !scalar ? bytes >> sizeI : 1;
|
|
|
|
|
2019-03-13 09:23:52 +01:00
|
|
|
for (int index = 0; index < elems; index++)
|
|
|
|
{
|
|
|
|
EmitVectorExtractF(context, op.Rn, index, sizeF);
|
|
|
|
|
|
|
|
EmitRoundMathCall(context, MidpointRounding.ToEven);
|
|
|
|
|
|
|
|
if (sizeF == 0)
|
|
|
|
{
|
|
|
|
VectorHelper.EmitCall(context, signed
|
|
|
|
? nameof(VectorHelper.SatF32ToS32)
|
|
|
|
: nameof(VectorHelper.SatF32ToU32));
|
|
|
|
|
|
|
|
context.Emit(OpCodes.Conv_U8);
|
|
|
|
}
|
|
|
|
else /* if (sizeF == 1) */
|
|
|
|
{
|
|
|
|
VectorHelper.EmitCall(context, signed
|
|
|
|
? nameof(VectorHelper.SatF64ToS64)
|
|
|
|
: nameof(VectorHelper.SatF64ToU64));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scalar)
|
|
|
|
{
|
|
|
|
EmitVectorZeroAll(context, op.Rd);
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitVectorInsert(context, op.Rd, index, sizeI);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op.RegisterSize == RegisterSize.Simd64)
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
2019-03-13 09:23:52 +01:00
|
|
|
EmitVectorZeroUpper(context, op.Rd);
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
2019-03-13 09:23:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitFcvtz(ILEmitterCtx context, bool signed, bool scalar)
|
|
|
|
{
|
|
|
|
OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
|
|
|
|
|
|
|
|
int sizeF = op.Size & 1;
|
|
|
|
int sizeI = sizeF + 2;
|
|
|
|
|
|
|
|
int fBits = GetFBits(context);
|
|
|
|
|
|
|
|
int bytes = op.GetBitsCount() >> 3;
|
|
|
|
int elems = !scalar ? bytes >> sizeI : 1;
|
2018-10-31 02:43:02 +01:00
|
|
|
|
|
|
|
for (int index = 0; index < elems; index++)
|
|
|
|
{
|
|
|
|
EmitVectorExtractF(context, op.Rn, index, sizeF);
|
|
|
|
|
2019-03-13 09:23:52 +01:00
|
|
|
EmitF2iFBitsMul(context, sizeF, fBits);
|
2018-10-31 02:43:02 +01:00
|
|
|
|
|
|
|
if (sizeF == 0)
|
|
|
|
{
|
|
|
|
VectorHelper.EmitCall(context, signed
|
|
|
|
? nameof(VectorHelper.SatF32ToS32)
|
|
|
|
: nameof(VectorHelper.SatF32ToU32));
|
|
|
|
|
|
|
|
context.Emit(OpCodes.Conv_U8);
|
|
|
|
}
|
2018-11-01 05:22:09 +01:00
|
|
|
else /* if (sizeF == 1) */
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
|
|
|
VectorHelper.EmitCall(context, signed
|
|
|
|
? nameof(VectorHelper.SatF64ToS64)
|
|
|
|
: nameof(VectorHelper.SatF64ToU64));
|
|
|
|
}
|
|
|
|
|
2019-03-13 09:23:52 +01:00
|
|
|
if (scalar)
|
|
|
|
{
|
|
|
|
EmitVectorZeroAll(context, op.Rd);
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-03-13 09:23:52 +01:00
|
|
|
EmitVectorInsert(context, op.Rd, index, sizeI);
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-03-13 09:23:52 +01:00
|
|
|
if (op.RegisterSize == RegisterSize.Simd64)
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
|
|
|
EmitVectorZeroUpper(context, op.Rd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitFcvt_s_Gp(ILEmitterCtx context, Action emit)
|
|
|
|
{
|
|
|
|
EmitFcvt___Gp(context, emit, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitFcvt_u_Gp(ILEmitterCtx context, Action emit)
|
|
|
|
{
|
|
|
|
EmitFcvt___Gp(context, emit, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitFcvt___Gp(ILEmitterCtx context, Action emit, bool signed)
|
|
|
|
{
|
|
|
|
OpCodeSimdCvt64 op = (OpCodeSimdCvt64)context.CurrOp;
|
|
|
|
|
|
|
|
EmitVectorExtractF(context, op.Rn, 0, op.Size);
|
|
|
|
|
|
|
|
emit();
|
|
|
|
|
|
|
|
if (signed)
|
|
|
|
{
|
|
|
|
EmitScalarFcvts(context, op.Size, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitScalarFcvtu(context, op.Size, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context.CurrOp.RegisterSize == RegisterSize.Int32)
|
|
|
|
{
|
|
|
|
context.Emit(OpCodes.Conv_U8);
|
|
|
|
}
|
|
|
|
|
|
|
|
context.EmitStintzr(op.Rd);
|
|
|
|
}
|
|
|
|
|
2019-02-24 00:52:48 +01:00
|
|
|
private static void EmitFcvtzs_Gp_Fixed(ILEmitterCtx context)
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
2019-02-24 00:52:48 +01:00
|
|
|
EmitFcvtz__Gp_Fixed(context, true);
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
2019-02-24 00:52:48 +01:00
|
|
|
private static void EmitFcvtzu_Gp_Fixed(ILEmitterCtx context)
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
2019-02-24 00:52:48 +01:00
|
|
|
EmitFcvtz__Gp_Fixed(context, false);
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
|
2019-02-24 00:52:48 +01:00
|
|
|
private static void EmitFcvtz__Gp_Fixed(ILEmitterCtx context, bool signed)
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
|
|
|
OpCodeSimdCvt64 op = (OpCodeSimdCvt64)context.CurrOp;
|
|
|
|
|
|
|
|
EmitVectorExtractF(context, op.Rn, 0, op.Size);
|
|
|
|
|
|
|
|
if (signed)
|
|
|
|
{
|
|
|
|
EmitScalarFcvts(context, op.Size, op.FBits);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EmitScalarFcvtu(context, op.Size, op.FBits);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context.CurrOp.RegisterSize == RegisterSize.Int32)
|
|
|
|
{
|
|
|
|
context.Emit(OpCodes.Conv_U8);
|
|
|
|
}
|
|
|
|
|
|
|
|
context.EmitStintzr(op.Rd);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitVectorCvtf(ILEmitterCtx context, bool signed)
|
|
|
|
{
|
|
|
|
OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
|
|
|
|
|
|
|
|
int sizeF = op.Size & 1;
|
|
|
|
int sizeI = sizeF + 2;
|
|
|
|
|
|
|
|
int fBits = GetFBits(context);
|
|
|
|
|
|
|
|
int bytes = op.GetBitsCount() >> 3;
|
|
|
|
int elems = bytes >> sizeI;
|
|
|
|
|
|
|
|
for (int index = 0; index < elems; index++)
|
|
|
|
{
|
|
|
|
EmitVectorExtract(context, op.Rn, index, sizeI, signed);
|
|
|
|
|
|
|
|
if (!signed)
|
|
|
|
{
|
|
|
|
context.Emit(OpCodes.Conv_R_Un);
|
|
|
|
}
|
|
|
|
|
2019-02-24 00:52:48 +01:00
|
|
|
EmitFloatCast(context, sizeF);
|
2018-10-31 02:43:02 +01:00
|
|
|
|
|
|
|
EmitI2fFBitsMul(context, sizeF, fBits);
|
|
|
|
|
|
|
|
EmitVectorInsertF(context, op.Rd, index, sizeF);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op.RegisterSize == RegisterSize.Simd64)
|
|
|
|
{
|
|
|
|
EmitVectorZeroUpper(context, op.Rd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-24 00:52:48 +01:00
|
|
|
private static int GetFBits(ILEmitterCtx context)
|
|
|
|
{
|
|
|
|
if (context.CurrOp is OpCodeSimdShImm64 op)
|
|
|
|
{
|
|
|
|
return GetImmShr(op);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitFloatCast(ILEmitterCtx context, int size)
|
|
|
|
{
|
|
|
|
if (size == 0)
|
|
|
|
{
|
|
|
|
context.Emit(OpCodes.Conv_R4);
|
|
|
|
}
|
|
|
|
else if (size == 1)
|
|
|
|
{
|
|
|
|
context.Emit(OpCodes.Conv_R8);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(size));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-31 02:43:02 +01:00
|
|
|
private static void EmitScalarFcvts(ILEmitterCtx context, int size, int fBits)
|
|
|
|
{
|
|
|
|
if (size < 0 || size > 1)
|
|
|
|
{
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(size));
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitF2iFBitsMul(context, size, fBits);
|
|
|
|
|
|
|
|
if (context.CurrOp.RegisterSize == RegisterSize.Int32)
|
|
|
|
{
|
|
|
|
if (size == 0)
|
|
|
|
{
|
|
|
|
VectorHelper.EmitCall(context, nameof(VectorHelper.SatF32ToS32));
|
|
|
|
}
|
2018-11-01 05:22:09 +01:00
|
|
|
else /* if (size == 1) */
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
|
|
|
VectorHelper.EmitCall(context, nameof(VectorHelper.SatF64ToS32));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (size == 0)
|
|
|
|
{
|
|
|
|
VectorHelper.EmitCall(context, nameof(VectorHelper.SatF32ToS64));
|
|
|
|
}
|
2018-11-01 05:22:09 +01:00
|
|
|
else /* if (size == 1) */
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
|
|
|
VectorHelper.EmitCall(context, nameof(VectorHelper.SatF64ToS64));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitScalarFcvtu(ILEmitterCtx context, int size, int fBits)
|
|
|
|
{
|
|
|
|
if (size < 0 || size > 1)
|
|
|
|
{
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(size));
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitF2iFBitsMul(context, size, fBits);
|
|
|
|
|
|
|
|
if (context.CurrOp.RegisterSize == RegisterSize.Int32)
|
|
|
|
{
|
|
|
|
if (size == 0)
|
|
|
|
{
|
|
|
|
VectorHelper.EmitCall(context, nameof(VectorHelper.SatF32ToU32));
|
|
|
|
}
|
2018-11-01 05:22:09 +01:00
|
|
|
else /* if (size == 1) */
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
|
|
|
VectorHelper.EmitCall(context, nameof(VectorHelper.SatF64ToU32));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (size == 0)
|
|
|
|
{
|
|
|
|
VectorHelper.EmitCall(context, nameof(VectorHelper.SatF32ToU64));
|
|
|
|
}
|
2018-11-01 05:22:09 +01:00
|
|
|
else /* if (size == 1) */
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
|
|
|
VectorHelper.EmitCall(context, nameof(VectorHelper.SatF64ToU64));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitF2iFBitsMul(ILEmitterCtx context, int size, int fBits)
|
|
|
|
{
|
|
|
|
if (fBits != 0)
|
|
|
|
{
|
|
|
|
if (size == 0)
|
|
|
|
{
|
|
|
|
context.EmitLdc_R4(MathF.Pow(2f, fBits));
|
|
|
|
}
|
|
|
|
else if (size == 1)
|
|
|
|
{
|
|
|
|
context.EmitLdc_R8(Math.Pow(2d, fBits));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(size));
|
|
|
|
}
|
|
|
|
|
|
|
|
context.Emit(OpCodes.Mul);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitI2fFBitsMul(ILEmitterCtx context, int size, int fBits)
|
|
|
|
{
|
|
|
|
if (fBits != 0)
|
|
|
|
{
|
|
|
|
if (size == 0)
|
|
|
|
{
|
|
|
|
context.EmitLdc_R4(1f / MathF.Pow(2f, fBits));
|
|
|
|
}
|
|
|
|
else if (size == 1)
|
|
|
|
{
|
|
|
|
context.EmitLdc_R8(1d / Math.Pow(2d, fBits));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(size));
|
|
|
|
}
|
|
|
|
|
|
|
|
context.Emit(OpCodes.Mul);
|
|
|
|
}
|
|
|
|
}
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
private static void EmitSse41Fcvt_Signed(ILEmitterCtx context, RoundMode roundMode, bool scalar)
|
2019-04-03 14:21:22 +02:00
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
// sizeF == ((OpCodeSimdShImm64)op).Size - 2
|
|
|
|
int sizeF = op.Size & 1;
|
|
|
|
|
|
|
|
if (sizeF == 0)
|
2019-04-03 14:21:22 +02:00
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
Type[] types = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
|
2019-04-03 14:21:22 +02:00
|
|
|
Type[] typesRndCvt = new Type[] { typeof(Vector128<float>) };
|
|
|
|
Type[] typesSav = new Type[] { typeof(int) };
|
|
|
|
|
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.CompareOrdered), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.And), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
if (op is OpCodeSimdShImm64 fixedOp)
|
2019-04-03 14:21:22 +02:00
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
int fBits = GetImmShr(fixedOp);
|
|
|
|
|
|
|
|
// BitConverter.Int32BitsToSingle(fpScaled) == MathF.Pow(2f, fBits)
|
2019-04-21 04:07:35 +02:00
|
|
|
int fpScaled = 0x3F800000 + fBits * 0x800000;
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
context.EmitLdc_I4(fpScaled);
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
}
|
|
|
|
|
2019-04-26 00:58:29 +02:00
|
|
|
context.EmitCall(typeof(Sse41).GetMethod(GetVectorSse41NameRnd(roundMode), typesRndCvt));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
context.EmitStvectmp();
|
|
|
|
context.EmitLdvectmp();
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Int32), typesRndCvt));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
context.EmitLdvectmp();
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitLdc_I4(0x4F000000); // 2.14748365E9f (2147483648)
|
2019-04-03 14:21:22 +02:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrEqual), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Xor), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitStvec(op.Rd);
|
|
|
|
|
|
|
|
if (scalar)
|
2019-04-03 14:21:22 +02:00
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
EmitVectorZero32_128(context, op.Rd);
|
2019-04-03 14:21:22 +02:00
|
|
|
}
|
2019-04-12 18:14:16 +02:00
|
|
|
else if (op.RegisterSize == RegisterSize.Simd64)
|
2019-04-03 14:21:22 +02:00
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
EmitVectorZeroUpper(context, op.Rd);
|
2019-04-03 14:21:22 +02:00
|
|
|
}
|
|
|
|
}
|
2019-04-12 18:14:16 +02:00
|
|
|
else /* if (sizeF == 1) */
|
2019-04-03 14:21:22 +02:00
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
Type[] types = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
|
2019-04-03 14:21:22 +02:00
|
|
|
Type[] typesRndCvt = new Type[] { typeof(Vector128<double>) };
|
2019-04-12 18:14:16 +02:00
|
|
|
Type[] typesSv = new Type[] { typeof(long), typeof(long) };
|
2019-04-03 14:21:22 +02:00
|
|
|
Type[] typesSav = new Type[] { typeof(long) };
|
|
|
|
|
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.CompareOrdered), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.And), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
if (op is OpCodeSimdShImm64 fixedOp)
|
2019-04-03 14:21:22 +02:00
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
int fBits = GetImmShr(fixedOp);
|
|
|
|
|
|
|
|
// BitConverter.Int64BitsToDouble(fpScaled) == Math.Pow(2d, fBits)
|
2019-04-21 04:07:35 +02:00
|
|
|
long fpScaled = 0x3FF0000000000000L + fBits * 0x10000000000000L;
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
context.EmitLdc_I8(fpScaled);
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
}
|
|
|
|
|
2019-04-26 00:58:29 +02:00
|
|
|
context.EmitCall(typeof(Sse41).GetMethod(GetVectorSse41NameRnd(roundMode), typesRndCvt));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
context.EmitStvectmp();
|
2019-04-12 18:14:16 +02:00
|
|
|
|
|
|
|
if (!scalar)
|
|
|
|
{
|
|
|
|
context.EmitLdvectmp();
|
|
|
|
context.EmitLdvectmp();
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.UnpackHigh), types));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToInt64), typesRndCvt));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
context.EmitLdc_I8(0L);
|
|
|
|
}
|
|
|
|
|
2019-04-03 14:21:22 +02:00
|
|
|
context.EmitLdvectmp();
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToInt64), typesRndCvt));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetVector128), typesSv));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
context.EmitLdvectmp();
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitLdc_I8(0x43E0000000000000L); // 9.2233720368547760E18d (9223372036854775808)
|
2019-04-03 14:21:22 +02:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.CompareGreaterThanOrEqual), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Xor), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitStvec(op.Rd);
|
|
|
|
|
|
|
|
if (scalar)
|
2019-04-03 14:21:22 +02:00
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
EmitVectorZeroUpper(context, op.Rd);
|
2019-04-03 14:21:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
private static void EmitSse41Fcvt_Unsigned(ILEmitterCtx context, RoundMode roundMode, bool scalar)
|
2019-04-03 14:21:22 +02:00
|
|
|
{
|
|
|
|
OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
|
|
|
|
|
|
|
|
// sizeF == ((OpCodeSimdShImm64)op).Size - 2
|
|
|
|
int sizeF = op.Size & 1;
|
|
|
|
|
|
|
|
if (sizeF == 0)
|
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
Type[] types = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
|
|
|
|
Type[] typesAdd = new Type[] { typeof(Vector128<int>), typeof(Vector128<int>) };
|
2019-04-03 14:21:22 +02:00
|
|
|
Type[] typesRndCvt = new Type[] { typeof(Vector128<float>) };
|
|
|
|
Type[] typesSav = new Type[] { typeof(int) };
|
|
|
|
|
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.CompareOrdered), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.And), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
if (op is OpCodeSimdShImm64 fixedOp)
|
2019-04-03 14:21:22 +02:00
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
int fBits = GetImmShr(fixedOp);
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
// BitConverter.Int32BitsToSingle(fpScaled) == MathF.Pow(2f, fBits)
|
2019-04-21 04:07:35 +02:00
|
|
|
int fpScaled = 0x3F800000 + fBits * 0x800000;
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
context.EmitLdc_I4(fpScaled);
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
}
|
|
|
|
|
2019-04-26 00:58:29 +02:00
|
|
|
context.EmitCall(typeof(Sse41).GetMethod(GetVectorSse41NameRnd(roundMode), typesRndCvt));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.Emit(OpCodes.Dup);
|
|
|
|
|
|
|
|
VectorHelper.EmitCall(context, nameof(VectorHelper.VectorSingleZero));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThan), types));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.And), types));
|
|
|
|
|
2019-04-03 14:21:22 +02:00
|
|
|
context.EmitStvectmp();
|
|
|
|
context.EmitLdvectmp();
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Int32), typesRndCvt));
|
|
|
|
|
|
|
|
context.EmitLdvectmp();
|
|
|
|
|
|
|
|
context.EmitLdc_I4(0x4F000000); // 2.14748365E9f (2147483648)
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitStvectmp2();
|
|
|
|
context.EmitLdvectmp2();
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Subtract), types));
|
|
|
|
|
|
|
|
context.Emit(OpCodes.Dup);
|
|
|
|
|
|
|
|
VectorHelper.EmitCall(context, nameof(VectorHelper.VectorSingleZero));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThan), types));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.And), types));
|
|
|
|
|
|
|
|
context.EmitStvectmp();
|
|
|
|
context.EmitLdvectmp();
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Int32), typesRndCvt));
|
|
|
|
|
|
|
|
context.EmitLdvectmp();
|
|
|
|
context.EmitLdvectmp2();
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrEqual), types));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Xor), types));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAdd));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
context.EmitStvec(op.Rd);
|
|
|
|
|
|
|
|
if (scalar)
|
|
|
|
{
|
|
|
|
EmitVectorZero32_128(context, op.Rd);
|
|
|
|
}
|
|
|
|
else if (op.RegisterSize == RegisterSize.Simd64)
|
|
|
|
{
|
|
|
|
EmitVectorZeroUpper(context, op.Rd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* if (sizeF == 1) */
|
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
Type[] types = new Type[] { typeof(Vector128<double>), typeof(Vector128<double>) };
|
|
|
|
Type[] typesAdd = new Type[] { typeof(Vector128<long>), typeof(Vector128<long>) };
|
|
|
|
Type[] typesRndCvt = new Type[] { typeof(Vector128<double>) };
|
|
|
|
Type[] typesSv = new Type[] { typeof(long), typeof(long) };
|
|
|
|
Type[] typesSav = new Type[] { typeof(long) };
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.CompareOrdered), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.And), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
if (op is OpCodeSimdShImm64 fixedOp)
|
2019-04-03 14:21:22 +02:00
|
|
|
{
|
2019-04-12 18:14:16 +02:00
|
|
|
int fBits = GetImmShr(fixedOp);
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
// BitConverter.Int64BitsToDouble(fpScaled) == Math.Pow(2d, fBits)
|
2019-04-21 04:07:35 +02:00
|
|
|
long fpScaled = 0x3FF0000000000000L + fBits * 0x10000000000000L;
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
context.EmitLdc_I8(fpScaled);
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
}
|
|
|
|
|
2019-04-26 00:58:29 +02:00
|
|
|
context.EmitCall(typeof(Sse41).GetMethod(GetVectorSse41NameRnd(roundMode), typesRndCvt));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.Emit(OpCodes.Dup);
|
|
|
|
|
|
|
|
VectorHelper.EmitCall(context, nameof(VectorHelper.VectorSingleZero));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.CompareGreaterThan), types));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.And), types));
|
|
|
|
|
2019-04-03 14:21:22 +02:00
|
|
|
context.EmitStvectmp();
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
if (!scalar)
|
|
|
|
{
|
|
|
|
context.EmitLdvectmp();
|
|
|
|
context.EmitLdvectmp();
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.UnpackHigh), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToInt64), typesRndCvt));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
context.EmitLdc_I8(0L);
|
|
|
|
}
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
context.EmitLdvectmp();
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToInt64), typesRndCvt));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetVector128), typesSv));
|
|
|
|
|
|
|
|
context.EmitLdvectmp();
|
|
|
|
|
|
|
|
context.EmitLdc_I8(0x43E0000000000000L); // 9.2233720368547760E18d (9223372036854775808)
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
|
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitStvectmp2();
|
|
|
|
context.EmitLdvectmp2();
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Subtract), types));
|
|
|
|
|
|
|
|
context.Emit(OpCodes.Dup);
|
|
|
|
|
|
|
|
VectorHelper.EmitCall(context, nameof(VectorHelper.VectorSingleZero));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.CompareGreaterThan), types));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.And), types));
|
|
|
|
|
|
|
|
context.EmitStvectmp();
|
|
|
|
|
|
|
|
if (!scalar)
|
|
|
|
{
|
|
|
|
context.EmitLdvectmp();
|
|
|
|
context.EmitLdvectmp();
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.UnpackHigh), types));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToInt64), typesRndCvt));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
context.EmitLdc_I8(0L);
|
|
|
|
}
|
|
|
|
|
|
|
|
context.EmitLdvectmp();
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToInt64), typesRndCvt));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetVector128), typesSv));
|
|
|
|
|
|
|
|
context.EmitLdvectmp();
|
|
|
|
context.EmitLdvectmp2();
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.CompareGreaterThanOrEqual), types));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Xor), types));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-12 18:14:16 +02:00
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Add), typesAdd));
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
context.EmitStvec(op.Rd);
|
|
|
|
|
|
|
|
if (scalar)
|
|
|
|
{
|
|
|
|
EmitVectorZeroUpper(context, op.Rd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-21 04:07:35 +02:00
|
|
|
private static void EmitSse2cvtF_Signed(ILEmitterCtx context, bool scalar)
|
|
|
|
{
|
|
|
|
OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
|
|
|
|
|
|
|
|
Type[] typesMul = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
|
|
|
|
Type[] typesCvt = new Type[] { typeof(Vector128<int>) };
|
|
|
|
Type[] typesSav = new Type[] { typeof(int) };
|
|
|
|
|
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Single), typesCvt));
|
|
|
|
|
|
|
|
if (op is OpCodeSimdShImm64 fixedOp)
|
|
|
|
{
|
|
|
|
int fBits = GetImmShr(fixedOp);
|
|
|
|
|
|
|
|
// BitConverter.Int32BitsToSingle(fpScaled) == 1f / MathF.Pow(2f, fBits)
|
|
|
|
int fpScaled = 0x3F800000 - fBits * 0x800000;
|
|
|
|
|
|
|
|
context.EmitLdc_I4(fpScaled);
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMul));
|
|
|
|
}
|
|
|
|
|
|
|
|
context.EmitStvec(op.Rd);
|
|
|
|
|
|
|
|
if (scalar)
|
|
|
|
{
|
|
|
|
EmitVectorZero32_128(context, op.Rd);
|
|
|
|
}
|
|
|
|
else if (op.RegisterSize == RegisterSize.Simd64)
|
|
|
|
{
|
|
|
|
EmitVectorZeroUpper(context, op.Rd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitSse2cvtF_Unsigned(ILEmitterCtx context, bool scalar)
|
|
|
|
{
|
|
|
|
OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;
|
|
|
|
|
|
|
|
Type[] typesMulAdd = new Type[] { typeof(Vector128<float>), typeof(Vector128<float>) };
|
|
|
|
Type[] typesSrlSll = new Type[] { typeof(Vector128<int>), typeof(byte) };
|
|
|
|
Type[] typesCvt = new Type[] { typeof(Vector128<int>) };
|
|
|
|
Type[] typesSav = new Type[] { typeof(int) };
|
|
|
|
|
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
|
|
|
|
context.EmitLdc_I4(16);
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical), typesSrlSll));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Single), typesCvt));
|
|
|
|
|
|
|
|
context.EmitLdc_I4(0x47800000); // 65536.0f (1 << 16)
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMulAdd));
|
|
|
|
|
|
|
|
context.EmitLdvec(op.Rn);
|
|
|
|
|
|
|
|
context.EmitLdc_I4(16);
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftLeftLogical), typesSrlSll));
|
|
|
|
|
|
|
|
context.EmitLdc_I4(16);
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical), typesSrlSll));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Single), typesCvt));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Add), typesMulAdd));
|
|
|
|
|
|
|
|
if (op is OpCodeSimdShImm64 fixedOp)
|
|
|
|
{
|
|
|
|
int fBits = GetImmShr(fixedOp);
|
|
|
|
|
|
|
|
// BitConverter.Int32BitsToSingle(fpScaled) == 1f / MathF.Pow(2f, fBits)
|
|
|
|
int fpScaled = 0x3F800000 - fBits * 0x800000;
|
|
|
|
|
|
|
|
context.EmitLdc_I4(fpScaled);
|
|
|
|
context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));
|
|
|
|
|
|
|
|
context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesMulAdd));
|
|
|
|
}
|
|
|
|
|
|
|
|
context.EmitStvec(op.Rd);
|
|
|
|
|
|
|
|
if (scalar)
|
|
|
|
{
|
|
|
|
EmitVectorZero32_128(context, op.Rd);
|
|
|
|
}
|
|
|
|
else if (op.RegisterSize == RegisterSize.Simd64)
|
|
|
|
{
|
|
|
|
EmitVectorZeroUpper(context, op.Rd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-26 00:58:29 +02:00
|
|
|
private static string GetScalarSse41NameRnd(RoundMode roundMode)
|
2019-04-03 14:21:22 +02:00
|
|
|
{
|
|
|
|
switch (roundMode)
|
|
|
|
{
|
|
|
|
case RoundMode.ToNearest:
|
2019-04-26 00:58:29 +02:00
|
|
|
return nameof(Sse41.RoundToNearestIntegerScalar); // even
|
|
|
|
|
|
|
|
case RoundMode.TowardsPlusInfinity:
|
|
|
|
return nameof(Sse41.RoundToPositiveInfinityScalar);
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
case RoundMode.TowardsMinusInfinity:
|
2019-04-26 00:58:29 +02:00
|
|
|
return nameof(Sse41.RoundToNegativeInfinityScalar);
|
|
|
|
|
|
|
|
default: /* case RoundMode.TowardsZero: */
|
|
|
|
return nameof(Sse41.RoundToZeroScalar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static string GetVectorSse41NameRnd(RoundMode roundMode)
|
|
|
|
{
|
|
|
|
switch (roundMode)
|
|
|
|
{
|
|
|
|
case RoundMode.ToNearest:
|
|
|
|
return nameof(Sse41.RoundToNearestInteger); // even
|
2019-04-03 14:21:22 +02:00
|
|
|
|
|
|
|
case RoundMode.TowardsPlusInfinity:
|
|
|
|
return nameof(Sse41.RoundToPositiveInfinity);
|
|
|
|
|
2019-04-26 00:58:29 +02:00
|
|
|
case RoundMode.TowardsMinusInfinity:
|
|
|
|
return nameof(Sse41.RoundToNegativeInfinity);
|
2019-04-03 14:21:22 +02:00
|
|
|
|
2019-04-26 00:58:29 +02:00
|
|
|
default: /* case RoundMode.TowardsZero: */
|
|
|
|
return nameof(Sse41.RoundToZero);
|
2019-04-03 14:21:22 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
}
|