public static void Cmlt_V(ILEmitterCtx context) { if (Optimizations.UseSse42) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; Type[] typesCmp = new Type[] { VectorIntTypesPerSizeLog2[op.Size], VectorIntTypesPerSizeLog2[op.Size] }; Type typeSse = op.Size != 3 ? typeof(Sse2) : typeof(Sse42); VectorHelper.EmitCall(context, nameof(VectorHelper.VectorSingleZero)); context.EmitLdvec(op.Rn); context.EmitCall(typeSse.GetMethod(nameof(Sse2.CompareGreaterThan), typesCmp)); context.EmitStvec(op.Rd); if (op.RegisterSize == RegisterSize.Simd64) { EmitVectorZeroUpper(context, op.Rd); } } else { EmitCmpOp(context, OpCodes.Blt_S, scalar: false); } }
private static void EmitSseOp(ILEmitterCtx context, string name, Type type) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; context.EmitLdvec(op.Rn); Type baseType = VectorIntTypesPerSizeLog2[op.Size]; if (op is OpCodeSimdReg64 binOp) { context.EmitLdvec(binOp.Rm); context.EmitCall(type.GetMethod(name, new Type[] { baseType, baseType })); } else { context.EmitCall(type.GetMethod(name, new Type[] { baseType })); } context.EmitStvec(op.Rd); if (op.RegisterSize == RegisterSize.Simd64) { EmitVectorZeroUpper(context, op.Rd); } }
public static void Fcvtl_V(ILEmitterCtx context) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; int sizeF = op.Size & 1; int elems = 4 >> sizeF; int part = op.RegisterSize == RegisterSize.Simd128 ? elems : 0; for (int index = 0; index < elems; index++) { 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); context.Emit(OpCodes.Conv_R8); } EmitVectorInsertTmpF(context, index, sizeF); } context.EmitLdvectmp(); context.EmitStvec(op.Rd); }
public static void Shll_V(ILEmitterCtx context) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; int shift = 8 << op.Size; if (Optimizations.UseSse41) { Type[] typesSll = new Type[] { VectorUIntTypesPerSizeLog2[op.Size + 1], typeof(byte) }; Type[] typesCvt = new Type[] { VectorUIntTypesPerSizeLog2[op.Size] }; string[] namesCvt = new string[] { nameof(Sse41.ConvertToVector128Int16), nameof(Sse41.ConvertToVector128Int32), nameof(Sse41.ConvertToVector128Int64) }; context.EmitLdvec(op.Rn); if (op.RegisterSize == RegisterSize.Simd128) { context.Emit(OpCodes.Ldc_I4_8); context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftRightLogical128BitLane), typesSll)); } context.EmitCall(typeof(Sse41).GetMethod(namesCvt[op.Size], typesCvt)); context.EmitLdc_I4(shift); context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ShiftLeftLogical), typesSll)); context.EmitStvec(op.Rd); } else { EmitVectorShImmWidenBinaryZx(context, () => context.Emit(OpCodes.Shl), shift); } }
public static void EmitScalarOpF(ILEmitterCtx context, Action emit, OperFlags opers) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; int sizeF = op.Size & 1; bool ra = (opers & OperFlags.Ra) != 0; bool rn = (opers & OperFlags.Rn) != 0; bool rm = (opers & OperFlags.Rm) != 0; if (ra) { EmitVectorExtractF(context, ((OpCodeSimdReg64)op).Ra, 0, sizeF); } if (rn) { EmitVectorExtractF(context, op.Rn, 0, sizeF); } if (rm) { EmitVectorExtractF(context, ((OpCodeSimdReg64)op).Rm, 0, sizeF); } emit(); EmitScalarSetF(context, op.Rd, sizeF); }
private static void EmitScalarFcvtz(ILEmitterCtx context, bool signed) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; int sizeF = op.Size & 1; int sizeI = sizeF + 2; int fBits = GetFBits(context); EmitVectorExtractF(context, op.Rn, 0, sizeF); EmitF2iFBitsMul(context, sizeF, fBits); if (sizeF == 0) { VectorHelper.EmitCall(context, signed ? nameof(VectorHelper.SatF32ToS32) : nameof(VectorHelper.SatF32ToU32)); } else /* if (sizeF == 1) */ { VectorHelper.EmitCall(context, signed ? nameof(VectorHelper.SatF64ToS64) : nameof(VectorHelper.SatF64ToU64)); } if (sizeF == 0) { context.Emit(OpCodes.Conv_U8); } EmitScalarSet(context, op.Rd, sizeI); }
public static void EmitScalarOp(ILEmitterCtx context, Action emit, OperFlags opers, bool signed) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; bool rd = (opers & OperFlags.Rd) != 0; bool rn = (opers & OperFlags.Rn) != 0; bool rm = (opers & OperFlags.Rm) != 0; if (rd) { EmitVectorExtract(context, op.Rd, 0, op.Size, signed); } if (rn) { EmitVectorExtract(context, op.Rn, 0, op.Size, signed); } if (rm) { EmitVectorExtract(context, ((OpCodeSimdReg64)op).Rm, 0, op.Size, signed); } emit(); EmitScalarSet(context, op.Rd, op.Size); }
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); } EmitFloatCast(context, sizeF); EmitI2fFBitsMul(context, sizeF, fBits); EmitVectorInsertF(context, op.Rd, index, sizeF); } if (op.RegisterSize == RegisterSize.Simd64) { EmitVectorZeroUpper(context, op.Rd); } }
private static void EmitRev_V(ILEmitterCtx context, int containerSize) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; int bytes = op.GetBitsCount() >> 3; int elems = bytes >> op.Size; int containerMask = (1 << (containerSize - op.Size)) - 1; for (int index = 0; index < elems; index++) { int revIndex = index ^ containerMask; EmitVectorExtractZx(context, op.Rn, revIndex, op.Size); EmitVectorInsertTmp(context, index, op.Size); } context.EmitLdvectmp(); context.EmitStvec(op.Rd); if (op.RegisterSize == RegisterSize.Simd64) { EmitVectorZeroUpper(context, op.Rd); } }
public static void Scvtf_V(ILEmitterCtx context) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; int sizeF = op.Size & 1; if (Optimizations.UseSse2 && sizeF == 0) { Type[] typesCvt = new Type[] { typeof(Vector128 <int>) }; EmitLdvecWithSignedCast(context, op.Rn, 2); context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Single), typesCvt)); context.EmitStvec(op.Rd); if (op.RegisterSize == RegisterSize.Simd64) { EmitVectorZeroUpper(context, op.Rd); } } else { EmitVectorCvtf(context, signed: true); } }
public static void Rev16_V(ILEmitterCtx context) { if (Optimizations.UseSsse3) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; Type[] typesSve = new Type[] { typeof(long), typeof(long) }; Type[] typesSfl = new Type[] { typeof(Vector128 <sbyte>), typeof(Vector128 <sbyte>) }; context.EmitLdvec(op.Rn); // value context.EmitLdc_I8(14L << 56 | 15L << 48 | 12L << 40 | 13L << 32 | 10L << 24 | 11L << 16 | 08L << 8 | 09L << 0); // maskE1 context.EmitLdc_I8(06L << 56 | 07L << 48 | 04L << 40 | 05L << 32 | 02L << 24 | 03L << 16 | 00L << 8 | 01L << 0); // maskE0 context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetVector128), typesSve)); context.EmitCall(typeof(Ssse3).GetMethod(nameof(Ssse3.Shuffle), typesSfl)); context.EmitStvec(op.Rd); if (op.RegisterSize == RegisterSize.Simd64) { EmitVectorZeroUpper(context, op.Rd); } } else { EmitRev_V(context, containerSize: 1); } }
public static void Not_V(ILEmitterCtx context) { if (Optimizations.UseSse2) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; Type[] typesSav = new Type[] { typeof(byte) }; Type[] typesAndNot = new Type[] { typeof(Vector128 <byte>), typeof(Vector128 <byte>) }; context.EmitLdvec(op.Rn); context.EmitLdc_I4(byte.MaxValue); context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav)); context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.AndNot), typesAndNot)); context.EmitStvec(op.Rd); if (op.RegisterSize == RegisterSize.Simd64) { EmitVectorZeroUpper(context, op.Rd); } } else { EmitVectorUnaryOpZx(context, () => context.Emit(OpCodes.Not)); } }
public static void Fmov_S(ILEmitterCtx context) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; EmitVectorExtractF(context, op.Rn, 0, op.Size); EmitScalarSetF(context, op.Rd, op.Size); }
public static void Shll_V(ILEmitterCtx context) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; int shift = 8 << op.Size; EmitVectorShImmWidenBinaryZx(context, () => context.Emit(OpCodes.Shl), shift); }
public static void Fmov_Itof(ILEmitterCtx context) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; context.EmitLdintzr(op.Rn); EmitScalarSet(context, op.Rd, op.Size + 2); }
public static void Fmov_Itof1(ILEmitterCtx context) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; context.EmitLdintzr(op.Rn); EmitVectorInsert(context, op.Rd, 1, 3); }
public static void Fmov_Ftoi1(ILEmitterCtx context) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; EmitVectorExtractZx(context, op.Rn, 1, 3); context.EmitStintzr(op.Rd); }
public static void Xtn_V(ILEmitterCtx context) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; if (Optimizations.UseSsse3) { Type[] typesSve = new Type[] { typeof(long), typeof(long) }; string nameMov = op.RegisterSize == RegisterSize.Simd128 ? nameof(Sse.MoveLowToHigh) : nameof(Sse.MoveHighToLow); context.EmitLdvec(op.Rd); VectorHelper.EmitCall(context, nameof(VectorHelper.VectorSingleZero)); context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.MoveLowToHigh))); context.EmitLdvec(op.Rn); // value context.EmitLdc_I8(_masksE0_TrnUzpXtn[op.Size]); // mask context.Emit(OpCodes.Dup); // mask context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetVector128), typesSve)); context.EmitCall(typeof(Ssse3).GetMethod(nameof(Ssse3.Shuffle), GetTypesSflUpk(0))); context.EmitCall(typeof(Sse).GetMethod(nameMov)); context.EmitStvec(op.Rd); } else { int elems = 8 >> op.Size; int part = op.RegisterSize == RegisterSize.Simd128 ? elems : 0; if (part != 0) { context.EmitLdvec(op.Rd); context.EmitStvectmp(); } for (int index = 0; index < elems; index++) { EmitVectorExtractZx(context, op.Rn, index, op.Size + 1); EmitVectorInsertTmp(context, part + index, op.Size); } context.EmitLdvectmp(); context.EmitStvec(op.Rd); if (part == 0) { 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); } }
public static void Aesmc_V(ILEmitterCtx context) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; context.EmitLdvec(op.Rn); SoftFallback.EmitCall(context, nameof(SoftFallback.MixColumns)); context.EmitStvec(op.Rd); }
public static void Sha1h_V(ILEmitterCtx context) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; EmitVectorExtractZx(context, op.Rn, 0, 2); SoftFallback.EmitCall(context, nameof(SoftFallback.FixedRotate)); EmitScalarSet(context, op.Rd, 2); }
public static void Scvtf_S(ILEmitterCtx context) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; EmitVectorExtractSx(context, op.Rn, 0, op.Size + 2); EmitFloatCast(context, op.Size); EmitScalarSetF(context, op.Rd, op.Size); }
public static void Fcvtl_V(ILEmitterCtx context) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; int sizeF = op.Size & 1; if (Optimizations.UseSse2 && sizeF == 1) { Type[] typesMov = new Type[] { typeof(Vector128 <float>), typeof(Vector128 <float>) }; Type[] typesCvt = new Type[] { typeof(Vector128 <float>) }; string nameMov = op.RegisterSize == RegisterSize.Simd128 ? nameof(Sse.MoveHighToLow) : nameof(Sse.MoveLowToHigh); context.EmitLdvec(op.Rn); context.Emit(OpCodes.Dup); context.EmitCall(typeof(Sse).GetMethod(nameMov, typesMov)); context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Double), typesCvt)); EmitStvecWithCastFromDouble(context, op.Rd); } else { int elems = 4 >> sizeF; int part = op.RegisterSize == RegisterSize.Simd128 ? elems : 0; for (int index = 0; index < elems; index++) { 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); context.Emit(OpCodes.Conv_R8); } EmitVectorInsertTmpF(context, index, sizeF); } context.EmitLdvectmp(); context.EmitStvec(op.Rd); } }
public static void Sha1su1_V(ILEmitterCtx context) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; context.EmitLdvec(op.Rd); context.EmitLdvec(op.Rn); SoftFallback.EmitCall(context, nameof(SoftFallback.Sha1SchedulePart2)); context.EmitStvec(op.Rd); }
private static void EmitFcmp(ILEmitterCtx context, OpCode ilOp, int index, bool scalar) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; int sizeF = op.Size & 1; ulong szMask = ulong.MaxValue >> (64 - (32 << sizeF)); EmitVectorExtractF(context, op.Rn, index, sizeF); if (op is OpCodeSimdReg64 binOp) { EmitVectorExtractF(context, binOp.Rm, index, sizeF); } else if (sizeF == 0) { context.EmitLdc_R4(0f); } else /* if (SizeF == 1) */ { context.EmitLdc_R8(0d); } ILLabel lblTrue = new ILLabel(); ILLabel lblEnd = new ILLabel(); context.Emit(ilOp, lblTrue); if (scalar) { EmitVectorZeroAll(context, op.Rd); } else { EmitVectorInsert(context, op.Rd, index, sizeF + 2, 0); } context.Emit(OpCodes.Br_S, lblEnd); context.MarkLabel(lblTrue); if (scalar) { EmitVectorInsert(context, op.Rd, index, 3, (long)szMask); EmitVectorZeroUpper(context, op.Rd); } else { EmitVectorInsert(context, op.Rd, index, sizeF + 2, (long)szMask); } context.MarkLabel(lblEnd); }
private static void EmitCmpOpF(ILEmitterCtx context, string name, bool scalar) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; int sizeF = op.Size & 1; int bytes = op.GetBitsCount() >> 3; int elems = !scalar ? bytes >> sizeF + 2 : 1; for (int index = 0; index < elems; index++) { EmitVectorExtractF(context, op.Rn, index, sizeF); if (op is OpCodeSimdReg64 binOp) { EmitVectorExtractF(context, binOp.Rm, index, sizeF); } else { if (sizeF == 0) { context.EmitLdc_R4(0f); } else /* if (sizeF == 1) */ { context.EmitLdc_R8(0d); } } EmitSoftFloatCall(context, name); EmitVectorInsertF(context, op.Rd, index, sizeF); } if (!scalar) { if (op.RegisterSize == RegisterSize.Simd64) { EmitVectorZeroUpper(context, op.Rd); } } else { if (sizeF == 0) { EmitVectorZero32_128(context, op.Rd); } else /* if (sizeF == 1) */ { EmitVectorZeroUpper(context, op.Rd); } } }
public static void EmitSseOrSse2OpF(ILEmitterCtx context, string name, bool scalar) { OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp; int sizeF = op.Size & 1; context.EmitLdvec(op.Rn); Type type; Type baseType; if (sizeF == 0) { type = typeof(Sse); baseType = typeof(Vector128 <float>); } else /* if (sizeF == 1) */ { type = typeof(Sse2); baseType = typeof(Vector128 <double>); } if (op is OpCodeSimdReg64 binOp) { context.EmitLdvec(binOp.Rm); context.EmitCall(type.GetMethod(name, new Type[] { baseType, baseType })); } else { context.EmitCall(type.GetMethod(name, new Type[] { baseType })); } context.EmitStvec(op.Rd); if (scalar) { if (sizeF == 0) { EmitVectorZero32_128(context, op.Rd); } else /* if (sizeF == 1) */ { EmitVectorZeroUpper(context, op.Rd); } } else if (op.RegisterSize == RegisterSize.Simd64) { EmitVectorZeroUpper(context, op.Rd); } }
public static void Ucvtf_V(ILEmitterCtx context) { 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 Scvtf_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_Signed(context, scalar: false); } else { EmitVectorCvtf(context, signed: true); } }
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; if (scalar && (sizeF == 0)) { EmitVectorZeroLowerTmp(context); } 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)); } EmitVectorInsertTmp(context, index, sizeI); } context.EmitLdvectmp(); context.EmitStvec(op.Rd); if ((op.RegisterSize == RegisterSize.Simd64) || scalar) { EmitVectorZeroUpper(context, op.Rd); } }