aboutsummaryrefslogtreecommitdiff
path: root/src/ARMeilleure/Decoders/OpCode32SimdShImm.cs
blob: 040dce6f1a32723e364f49b80606cc3ef090fa61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
namespace ARMeilleure.Decoders
{
    class OpCode32SimdShImm : OpCode32Simd
    {
        public int Shift { get; }

        public new static OpCode Create(InstDescriptor inst, ulong address, int opCode) => new OpCode32SimdShImm(inst, address, opCode, false);
        public new static OpCode CreateT32(InstDescriptor inst, ulong address, int opCode) => new OpCode32SimdShImm(inst, address, opCode, true);

        public OpCode32SimdShImm(InstDescriptor inst, ulong address, int opCode, bool isThumb) : base(inst, address, opCode, isThumb)
        {
            int imm6 = (opCode >> 16) & 0x3f;
            int limm6 = ((opCode >> 1) & 0x40) | imm6;

            if ((limm6 & 0x40) == 0b1000000)
            {
                Size = 3;
                Shift = imm6;
            }
            else if ((limm6 & 0x60) == 0b0100000)
            {
                Size = 2;
                Shift = imm6 - 32;
            }
            else if ((limm6 & 0x70) == 0b0010000)
            {
                Size = 1;
                Shift = imm6 - 16;
            }
            else if ((limm6 & 0x78) == 0b0001000)
            {
                Size = 0;
                Shift = imm6 - 8;
            }
            else
            {
                Instruction = InstDescriptor.Undefined;
            }

            if (GetType() == typeof(OpCode32SimdShImm) && DecoderHelper.VectorArgumentsInvalid(Q, Vd, Vm))
            {
                Instruction = InstDescriptor.Undefined;
            }
        }
    }
}