예제 #1
0
        static OpCodeHandlers()
        {
            var info     = GetData();
            var handlers = new OpCodeHandler[IcedConstants.NumberOfCodeValues];
            int j        = 0;

            for (int i = 0; i < info.Length; i += 3, j++)
            {
                uint          dword1 = info[i];
                OpCodeHandler handler;
                switch ((EncodingKind)((dword1 >> (int)EncFlags1.EncodingShift) & (uint)EncFlags1.EncodingMask))
                {
                case EncodingKind.Legacy:
                    var code = (Code)j;
                    if (code == Code.INVALID)
                    {
                        handler = new InvalidHandler();
                    }
                    else if (code <= Code.DeclareQword)
                    {
                        handler = new DeclareDataHandler(code);
                    }
                    else
                    {
                        handler = new LegacyHandler(dword1, info[i + 1], info[i + 2]);
                    }
                    break;

                case EncodingKind.VEX:
                    handler = new VexHandler(dword1, info[i + 1], info[i + 2]);
                    break;

                case EncodingKind.EVEX:
                    handler = new EvexHandler(dword1, info[i + 1], info[i + 2]);
                    break;

                case EncodingKind.XOP:
                    handler = new XopHandler(dword1, info[i + 1], info[i + 2]);
                    break;

                case EncodingKind.D3NOW:
                    handler = new D3nowHandler(dword1, info[i + 1], info[i + 2]);
                    break;

                default:
                    throw new InvalidOperationException();
                }
                handlers[j] = handler;
            }
            if (j != handlers.Length)
            {
                throw new InvalidOperationException();
            }
            Handlers = handlers;
        }
예제 #2
0
            public bool TryConvertToDisp8N(Encoder encoder, ref Instruction instr, OpCodeHandler handler, int displ, out sbyte compressedValue)
            {
                var evexHandler = (EvexHandler)handler;
                int n;

                switch (evexHandler.tupleType)
                {
                case TupleType.None:
                    n = 1;
                    break;

                case TupleType.Full_128:
                    if ((encoder.EncoderFlags & EncoderFlags.b) != 0)
                    {
                        n = (evexHandler.flags & EvexFlags.EVEX_W1) != 0 ? 8 : 4;
                    }
                    else
                    {
                        n = 16;
                    }
                    break;

                case TupleType.Full_256:
                    if ((encoder.EncoderFlags & EncoderFlags.b) != 0)
                    {
                        n = (evexHandler.flags & EvexFlags.EVEX_W1) != 0 ? 8 : 4;
                    }
                    else
                    {
                        n = 32;
                    }
                    break;

                case TupleType.Full_512:
                    if ((encoder.EncoderFlags & EncoderFlags.b) != 0)
                    {
                        n = (evexHandler.flags & EvexFlags.EVEX_W1) != 0 ? 8 : 4;
                    }
                    else
                    {
                        n = 64;
                    }
                    break;

                case TupleType.Half_128:
                    n = (encoder.EncoderFlags & EncoderFlags.b) != 0 ? 4 : 8;
                    break;

                case TupleType.Half_256:
                    n = (encoder.EncoderFlags & EncoderFlags.b) != 0 ? 4 : 16;
                    break;

                case TupleType.Half_512:
                    n = (encoder.EncoderFlags & EncoderFlags.b) != 0 ? 4 : 32;
                    break;

                case TupleType.Full_Mem_128:
                    n = 16;
                    break;

                case TupleType.Full_Mem_256:
                    n = 32;
                    break;

                case TupleType.Full_Mem_512:
                    n = 64;
                    break;

                case TupleType.Tuple1_Scalar:
                    n = (evexHandler.flags & EvexFlags.EVEX_W1) != 0 ? 8 : 4;
                    break;

                case TupleType.Tuple1_Scalar_1:
                    n = 1;
                    break;

                case TupleType.Tuple1_Scalar_2:
                    n = 2;
                    break;

                case TupleType.Tuple1_Scalar_4:
                    n = 4;
                    break;

                case TupleType.Tuple1_Scalar_8:
                    n = 8;
                    break;

                case TupleType.Tuple1_Fixed:
                    n = (evexHandler.flags & EvexFlags.EVEX_W1) != 0 ? 8 : 4;
                    break;

                case TupleType.Tuple1_Fixed_4:
                    n = 4;
                    break;

                case TupleType.Tuple1_Fixed_8:
                    n = 8;
                    break;

                case TupleType.Tuple2:
                    n = (evexHandler.flags & EvexFlags.EVEX_W1) != 0 ? 16 : 8;
                    break;

                case TupleType.Tuple4:
                    n = (evexHandler.flags & EvexFlags.EVEX_W1) != 0 ? 32 : 16;
                    break;

                case TupleType.Tuple8:
                    Debug.Assert((evexHandler.flags & EvexFlags.EVEX_W1) == 0);
                    n = 32;
                    break;

                case TupleType.Tuple1_4X:
                    n = 16;
                    break;

                case TupleType.Half_Mem_128:
                    n = 8;
                    break;

                case TupleType.Half_Mem_256:
                    n = 16;
                    break;

                case TupleType.Half_Mem_512:
                    n = 32;
                    break;

                case TupleType.Quarter_Mem_128:
                    n = 4;
                    break;

                case TupleType.Quarter_Mem_256:
                    n = 8;
                    break;

                case TupleType.Quarter_Mem_512:
                    n = 16;
                    break;

                case TupleType.Eighth_Mem_128:
                    n = 2;
                    break;

                case TupleType.Eighth_Mem_256:
                    n = 4;
                    break;

                case TupleType.Eighth_Mem_512:
                    n = 8;
                    break;

                case TupleType.Mem128:
                    n = 16;
                    break;

                case TupleType.MOVDDUP_128:
                    n = 8;
                    break;

                case TupleType.MOVDDUP_256:
                    n = 32;
                    break;

                case TupleType.MOVDDUP_512:
                    n = 64;
                    break;

                default:
                    throw new InvalidOperationException();
                }

                int res = displ / n;

                if (res * n == displ && sbyte.MinValue <= res && res <= sbyte.MaxValue)
                {
                    compressedValue = (sbyte)res;
                    return(true);
                }

                compressedValue = 0;
                return(false);
            }
예제 #3
0
        static OpCodeHandlers()
        {
            var encFlags1      = EncoderData.EncFlags1;
            var encFlags2      = EncoderData.EncFlags2;
            var encFlags3Data  = EncoderData.EncFlags3;
            var handlers       = new OpCodeHandler[IcedConstants.CodeEnumCount];
            int i              = 0;
            var invalidHandler = new InvalidHandler();

            for (; i < encFlags1.Length; i++)
            {
                var           encFlags3 = (EncFlags3)encFlags3Data[i];
                OpCodeHandler handler;
                switch ((EncodingKind)(((uint)encFlags3 >> (int)EncFlags3.EncodingShift) & (uint)EncFlags3.EncodingMask))
                {
                case EncodingKind.Legacy:
                    var code = (Code)i;
                    if (code == Code.INVALID)
                    {
                        handler = invalidHandler;
                    }
                    else if (code <= Code.DeclareQword)
                    {
                        handler = new DeclareDataHandler(code);
                    }
                    else
                    {
                        handler = new LegacyHandler((EncFlags1)encFlags1[i], (EncFlags2)encFlags2[i], encFlags3);
                    }
                    break;

                case EncodingKind.VEX:
#if !NO_VEX
                    handler = new VexHandler((EncFlags1)encFlags1[i], (EncFlags2)encFlags2[i], encFlags3);
#else
                    handler = invalidHandler;
#endif
                    break;

                case EncodingKind.EVEX:
#if !NO_EVEX
                    handler = new EvexHandler((EncFlags1)encFlags1[i], (EncFlags2)encFlags2[i], encFlags3);
#else
                    handler = invalidHandler;
#endif
                    break;

                case EncodingKind.XOP:
#if !NO_XOP
                    handler = new XopHandler((EncFlags1)encFlags1[i], (EncFlags2)encFlags2[i], encFlags3);
#else
                    handler = invalidHandler;
#endif
                    break;

                case EncodingKind.D3NOW:
#if !NO_D3NOW
                    handler = new D3nowHandler((EncFlags2)encFlags2[i], encFlags3);
#else
                    handler = invalidHandler;
#endif
                    break;

                default:
                    throw new InvalidOperationException();
                }
                handlers[i] = handler;
            }
            if (i != handlers.Length)
            {
                throw new InvalidOperationException();
            }
            Handlers = handlers;
        }