Esempio n. 1
0
        private static void EmitLoad(AILEmitterCtx Context, AccessType AccType, bool Pair)
        {
            AOpCodeMemEx Op = (AOpCodeMemEx)Context.CurrOp;

            if (AccType.HasFlag(AccessType.Ordered))
            {
                EmitBarrier(Context);
            }

            if (AccType.HasFlag(AccessType.Exclusive))
            {
                EmitMemoryCall(Context, nameof(AMemory.SetExclusive), Op.Rn);
            }

            Context.EmitLdarg(ATranslatedSub.MemoryArgIdx);
            Context.EmitLdint(Op.Rn);

            EmitReadZxCall(Context, Op.Size);

            Context.EmitStintzr(Op.Rt);

            if (Pair)
            {
                Context.EmitLdarg(ATranslatedSub.MemoryArgIdx);
                Context.EmitLdint(Op.Rn);
                Context.EmitLdc_I(8 << Op.Size);

                Context.Emit(OpCodes.Add);

                EmitReadZxCall(Context, Op.Size);

                Context.EmitStintzr(Op.Rt2);
            }
        }
Esempio n. 2
0
        private static void EmitStore(AILEmitterCtx Context, AccessType AccType, bool Pair)
        {
            AOpCodeMemEx Op = (AOpCodeMemEx)Context.CurrOp;

            bool Ordered   = (AccType & AccessType.Ordered) != 0;
            bool Exclusive = (AccType & AccessType.Exclusive) != 0;

            if (Ordered)
            {
                EmitBarrier(Context);
            }

            AILLabel LblEx  = new AILLabel();
            AILLabel LblEnd = new AILLabel();

            if (Exclusive)
            {
                EmitMemoryCall(Context, nameof(AMemory.TestExclusive), Op.Rn);

                Context.Emit(OpCodes.Brtrue_S, LblEx);

                Context.EmitLdc_I8(1);
                Context.EmitStintzr(Op.Rs);

                Context.Emit(OpCodes.Br_S, LblEnd);
            }

            Context.MarkLabel(LblEx);

            Context.EmitLdarg(ATranslatedSub.MemoryArgIdx);
            Context.EmitLdint(Op.Rn);
            Context.EmitLdintzr(Op.Rt);

            EmitWriteCall(Context, Op.Size);

            if (Pair)
            {
                Context.EmitLdarg(ATranslatedSub.MemoryArgIdx);
                Context.EmitLdint(Op.Rn);
                Context.EmitLdc_I8(1 << Op.Size);

                Context.Emit(OpCodes.Add);

                Context.EmitLdintzr(Op.Rt2);

                EmitWriteCall(Context, Op.Size);
            }

            if (Exclusive)
            {
                Context.EmitLdc_I8(0);
                Context.EmitStintzr(Op.Rs);

                EmitMemoryCall(Context, nameof(AMemory.ClearExclusiveForStore));
            }

            Context.MarkLabel(LblEnd);
        }
Esempio n. 3
0
        public static void Sbfm(AILEmitterCtx Context)
        {
            AOpCodeBfm Op = (AOpCodeBfm)Context.CurrOp;

            int BitsCount = Op.GetBitsCount();

            if (Op.Pos + 1 == BitsCount)
            {
                EmitSbfmShift(Context);
            }
            else if (Op.Pos < Op.Shift)
            {
                EmitSbfiz(Context);
            }
            else if (Op.Pos == 7 && Op.Shift == 0)
            {
                EmitSbfmCast(Context, OpCodes.Conv_I1);
            }
            else if (Op.Pos == 15 && Op.Shift == 0)
            {
                EmitSbfmCast(Context, OpCodes.Conv_I2);
            }
            else if (Op.Pos == 31 && Op.Shift == 0)
            {
                EmitSbfmCast(Context, OpCodes.Conv_I4);
            }
            else if (Op.Shift == 0)
            {
                Context.EmitLdintzr(Op.Rn);

                Context.EmitLsl(BitsCount - 1 - Op.Pos);
                Context.EmitAsr(BitsCount - 1);

                Context.EmitStintzr(Op.Rd);
            }
            else
            {
                EmitBfmLoadRn(Context);

                Context.EmitLdintzr(Op.Rn);

                Context.EmitLsl(BitsCount - 1 - Op.Pos);
                Context.EmitAsr(BitsCount - 1);

                Context.EmitLdc_I(~Op.TMask);

                Context.Emit(OpCodes.And);
                Context.Emit(OpCodes.Or);

                Context.EmitStintzr(Op.Rd);
            }
        }
Esempio n. 4
0
        public static void Movz(AILEmitterCtx Context)
        {
            AOpCodeMov Op = (AOpCodeMov)Context.CurrOp;

            Context.EmitLdc_I(Op.Imm);
            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 5
0
        public static void Fmov_Ftoi(AILEmitterCtx Context)
        {
            AOpCodeSimdCvt Op = (AOpCodeSimdCvt)Context.CurrOp;

            Context.EmitLdvecsi(Op.Rn);
            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 6
0
        public static void EmitLdr(AILEmitterCtx Context, bool Signed)
        {
            AOpCodeMem Op = (AOpCodeMem)Context.CurrOp;

            Context.EmitLdarg(ATranslatedSub.MemoryArgIdx);

            EmitLoadAddress(Context);

            if (Signed && Op.Extend64)
            {
                EmitReadSx64Call(Context, Op.Size);
            }
            else if (Signed)
            {
                EmitReadSx32Call(Context, Op.Size);
            }
            else
            {
                EmitReadZxCall(Context, Op.Size);
            }

            if (Op is IAOpCodeSimd)
            {
                Context.EmitStvec(Op.Rt);
            }
            else
            {
                Context.EmitStintzr(Op.Rt);
            }

            EmitWBackIfNeeded(Context);
        }
Esempio n. 7
0
        public static void Adr(AILEmitterCtx Context)
        {
            AOpCodeAdr Op = (AOpCodeAdr)Context.CurrOp;

            Context.EmitLdc_I(Op.Position + Op.Imm);
            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 8
0
        public static void Ubfm(AILEmitterCtx Context)
        {
            AOpCodeBfm Op = (AOpCodeBfm)Context.CurrOp;

            if (Op.Pos + 1 == Op.GetBitsCount())
            {
                EmitUbfmShift(Context);
            }
            else if (Op.Pos < Op.Shift)
            {
                EmitUbfiz(Context);
            }
            else if (Op.Pos + 1 == Op.Shift)
            {
                EmitBfmLsl(Context);
            }
            else if (Op.Pos == 7 && Op.Shift == 0)
            {
                EmitUbfmCast(Context, OpCodes.Conv_U1);
            }
            else if (Op.Pos == 15 && Op.Shift == 0)
            {
                EmitUbfmCast(Context, OpCodes.Conv_U2);
            }
            else
            {
                EmitBfmLoadRn(Context);

                Context.EmitStintzr(Op.Rd);
            }
        }
Esempio n. 9
0
        private static void EmitCsel(AILEmitterCtx Context, CselOperation CselOp)
        {
            AOpCodeCsel Op = (AOpCodeCsel)Context.CurrOp;

            AILLabel LblTrue = new AILLabel();
            AILLabel LblEnd  = new AILLabel();

            Context.EmitCondBranch(LblTrue, Op.Cond);
            Context.EmitLdintzr(Op.Rm);

            if (CselOp == CselOperation.Increment)
            {
                Context.EmitLdc_I(1);

                Context.Emit(OpCodes.Add);
            }
            else if (CselOp == CselOperation.Invert)
            {
                Context.Emit(OpCodes.Not);
            }
            else if (CselOp == CselOperation.Negate)
            {
                Context.Emit(OpCodes.Neg);
            }

            Context.Emit(OpCodes.Br_S, LblEnd);

            Context.MarkLabel(LblTrue);

            Context.EmitLdintzr(Op.Rn);

            Context.MarkLabel(LblEnd);

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 10
0
        public static void Adrp(AILEmitterCtx Context)
        {
            AOpCodeAdr Op = (AOpCodeAdr)Context.CurrOp;

            Context.EmitLdc_I((Op.Position & ~0xfff) + (Op.Imm << 12));
            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 11
0
        public static void Umov_S(AILEmitterCtx Context)
        {
            AOpCodeSimdIns Op = (AOpCodeSimdIns)Context.CurrOp;

            EmitVectorExtractZx(Context, Op.Rn, Op.DstIndex, Op.Size);

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 12
0
        public static void Rev64(AILEmitterCtx Context)
        {
            AOpCodeAlu Op = (AOpCodeAlu)Context.CurrOp;

            Context.EmitLdintzr(Op.Rn);

            ASoftFallback.EmitCall(Context, nameof(ASoftFallback.ReverseBytes64));

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 13
0
        public static void Fmov_Ftoi1(AILEmitterCtx Context)
        {
            AOpCodeSimdCvt Op = (AOpCodeSimdCvt)Context.CurrOp;

            EmitVectorExtractZx(Context, Op.Rn, 1, 3);

            EmitIntZeroUpperIfNeeded(Context);

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 14
0
        private static void EmitBfmLsl(AILEmitterCtx Context)
        {
            AOpCodeBfm Op = (AOpCodeBfm)Context.CurrOp;

            Context.EmitLdintzr(Op.Rn);

            Context.EmitLsl(Op.GetBitsCount() - Op.Shift);

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 15
0
        public static void Smov_S(AILEmitterCtx Context)
        {
            AOpCodeSimdIns Op = (AOpCodeSimdIns)Context.CurrOp;

            EmitVectorExtractSx(Context, Op.Rn, Op.DstIndex, Op.Size);

            EmitIntZeroUpperIfNeeded(Context);

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 16
0
        public static void Umulh(AILEmitterCtx Context)
        {
            AOpCodeMul Op = (AOpCodeMul)Context.CurrOp;

            Context.EmitLdintzr(Op.Rn);
            Context.EmitLdintzr(Op.Rm);

            ASoftFallback.EmitCall(Context, nameof(ASoftFallback.UMulHi128));

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 17
0
        private static void EmitSse42Crc32(AILEmitterCtx Context, Type TCrc, Type TData)
        {
            AOpCodeAluRs Op = (AOpCodeAluRs)Context.CurrOp;

            Context.EmitLdintzr(Op.Rn);
            Context.EmitLdintzr(Op.Rm);

            Context.EmitCall(typeof(Sse42).GetMethod(nameof(Sse42.Crc32), new Type[] { TCrc, TData }));

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 18
0
        public static void Fmov_Ftoi1(AILEmitterCtx Context)
        {
            AOpCodeSimdCvt Op = (AOpCodeSimdCvt)Context.CurrOp;

            Context.EmitLdvec(Op.Rn);
            Context.EmitLdc_I4(1);
            Context.EmitLdc_I4(3);

            ASoftFallback.EmitCall(Context, nameof(ASoftFallback.ExtractVec));

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 19
0
        public static void Umov_S(AILEmitterCtx Context)
        {
            AOpCodeSimdIns Op = (AOpCodeSimdIns)Context.CurrOp;

            Context.EmitLdvec(Op.Rn);
            Context.EmitLdc_I4(Op.DstIndex);
            Context.EmitLdc_I4(Op.Size);

            ASoftFallback.EmitCall(Context, nameof(ASoftFallback.ExtractVec));

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 20
0
        public static void EmitMathOpCvtToInt(AILEmitterCtx Context, string Name)
        {
            AOpCodeSimdCvt Op = (AOpCodeSimdCvt)Context.CurrOp;

            Context.EmitLdvecsf(Op.Rn);

            EmitMathOpCall(Context, Name);

            EmitCvtToInt(Context, Op.Size);

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 21
0
        public static void Clz(AILEmitterCtx Context)
        {
            AOpCodeAlu Op = (AOpCodeAlu)Context.CurrOp;

            Context.EmitLdintzr(Op.Rn);

            Context.EmitLdc_I4(Op.RegisterSize == ARegisterSize.Int32 ? 32 : 64);

            ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CountLeadingZeros));

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 22
0
        public static void EmitDataStore(AILEmitterCtx Context, bool SetFlags)
        {
            IAOpCodeAlu Op = (IAOpCodeAlu)Context.CurrOp;

            if (SetFlags || Op is IAOpCodeAluRs)
            {
                Context.EmitStintzr(Op.Rd);
            }
            else
            {
                Context.EmitStint(Op.Rd);
            }
        }
Esempio n. 23
0
        private static void EmitMul(AILEmitterCtx Context, OpCode ILOp)
        {
            AOpCodeMul Op = (AOpCodeMul)Context.CurrOp;

            Context.EmitLdintzr(Op.Ra);
            Context.EmitLdintzr(Op.Rn);
            Context.EmitLdintzr(Op.Rm);

            Context.Emit(OpCodes.Mul);
            Context.Emit(ILOp);

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 24
0
        private static void EmitBfmShift(AILEmitterCtx Context, bool Signed)
        {
            AOpCodeBfm Op = (AOpCodeBfm)Context.CurrOp;

            Context.EmitLdintzr(Op.Rn);
            Context.EmitLdc_I4(Op.Shift);

            Context.Emit(Signed
                ? OpCodes.Shr
                : OpCodes.Shr_Un);

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 25
0
        private static void EmitBfmShift(AILEmitterCtx Context, OpCode ILOp)
        {
            AOpCodeBfm Op = (AOpCodeBfm)Context.CurrOp;

            if (Op.Shift > 0)
            {
                Context.EmitLdintzr(Op.Rn);
                Context.EmitLdc_I4(Op.Shift);

                Context.Emit(ILOp);

                Context.EmitStintzr(Op.Rd);
            }
        }
Esempio n. 26
0
        public static void Movk(AILEmitterCtx Context)
        {
            AOpCodeMov Op = (AOpCodeMov)Context.CurrOp;

            Context.EmitLdintzr(Op.Rd);
            Context.EmitLdc_I(~(0xffffL << Op.Pos));

            Context.Emit(OpCodes.And);

            Context.EmitLdc_I(Op.Imm);

            Context.Emit(OpCodes.Or);

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 27
0
        private static void EmitFcvt_s_Gp(AILEmitterCtx Context, string Name)
        {
            AOpCodeSimdCvt Op = (AOpCodeSimdCvt)Context.CurrOp;

            EmitVectorExtractF(Context, Op.Rn, 0, Op.Size);

            EmitUnaryMathCall(Context, Name);

            EmitScalarFcvts(Context, Op.Size, 0);

            if (Context.CurrOp.RegisterSize == ARegisterSize.Int32)
            {
                Context.Emit(OpCodes.Conv_U8);
            }

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 28
0
        private static void EmitFcvtz_(AILEmitterCtx Context, bool Signed)
        {
            AOpCodeSimdCvt Op = (AOpCodeSimdCvt)Context.CurrOp;

            Context.EmitLdvecsf(Op.Rn);

            if (Signed)
            {
                EmitCvtToInt(Context, Op.Size);
            }
            else
            {
                EmitCvtToUInt(Context, Op.Size);
            }

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 29
0
        private static void EmitFallback32_64(AILEmitterCtx Context, string Name32, string Name64)
        {
            AOpCodeAlu Op = (AOpCodeAlu)Context.CurrOp;

            Context.EmitLdintzr(Op.Rn);

            if (Op.RegisterSize == ARegisterSize.Int32)
            {
                ASoftFallback.EmitCall(Context, Name32);
            }
            else
            {
                ASoftFallback.EmitCall(Context, Name64);
            }

            Context.EmitStintzr(Op.Rd);
        }
Esempio n. 30
0
        private static void EmitBfmCast(AILEmitterCtx Context, OpCode ILOp, bool Signed)
        {
            AOpCodeBfm Op = (AOpCodeBfm)Context.CurrOp;

            Context.EmitLdintzr(Op.Rn);

            Context.Emit(ILOp);

            if (Op.RegisterSize != ARegisterSize.Int32)
            {
                Context.Emit(Signed
                    ? OpCodes.Conv_I8
                    : OpCodes.Conv_U8);
            }

            Context.EmitStintzr(Op.Rd);
        }