aboutsummaryrefslogtreecommitdiff
path: root/src/ARMeilleure/Decoders/OpCodeSimdMemSs.cs
blob: 5bc614e1933679fc13f053c33c2a37ef305b43f3 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
namespace ARMeilleure.Decoders
{
    class OpCodeSimdMemSs : OpCodeMemReg, IOpCodeSimd
    {
        public int SElems { get; }
        public int Index { get; }
        public bool Replicate { get; }
        public bool WBack { get; }

        public new static OpCode Create(InstDescriptor inst, ulong address, int opCode) => new OpCodeSimdMemSs(inst, address, opCode);

        public OpCodeSimdMemSs(InstDescriptor inst, ulong address, int opCode) : base(inst, address, opCode)
        {
            int size = (opCode >> 10) & 3;
            int s = (opCode >> 12) & 1;
            int sElems = (opCode >> 12) & 2;
            int scale = (opCode >> 14) & 3;
            int l = (opCode >> 22) & 1;
            int q = (opCode >> 30) & 1;

            sElems |= (opCode >> 21) & 1;

            sElems++;

            int index = (q << 3) | (s << 2) | size;

            switch (scale)
            {
                case 1:
                    {
                        if ((size & 1) != 0)
                        {
                            Instruction = InstDescriptor.Undefined;

                            return;
                        }

                        index >>= 1;

                        break;
                    }

                case 2:
                    {
                        if ((size & 2) != 0 ||
                           ((size & 1) != 0 && s != 0))
                        {
                            Instruction = InstDescriptor.Undefined;

                            return;
                        }

                        if ((size & 1) != 0)
                        {
                            index >>= 3;

                            scale = 3;
                        }
                        else
                        {
                            index >>= 2;
                        }

                        break;
                    }

                case 3:
                    {
                        if (l == 0 || s != 0)
                        {
                            Instruction = InstDescriptor.Undefined;

                            return;
                        }

                        scale = size;

                        Replicate = true;

                        break;
                    }
            }

            Index = index;
            SElems = sElems;
            Size = scale;

            Extend64 = false;

            WBack = ((opCode >> 23) & 1) != 0;

            RegisterSize = q != 0
                ? RegisterSize.Simd128
                : RegisterSize.Simd64;
        }
    }
}