aboutsummaryrefslogtreecommitdiff
path: root/ChocolArm64/Decoders/OpCodeAluImm64.cs
blob: 64ac08a7a645b0eeed3f249d91aaa65e7907b3a1 (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
using ChocolArm64.Instructions;
using System;

namespace ChocolArm64.Decoders
{
    class OpCodeAluImm64 : OpCodeAlu64, IOpCodeAluImm64
    {
        public long Imm { get; private set; }

        public OpCodeAluImm64(Inst inst, long position, int opCode) : base(inst, position, opCode)
        {
            if (DataOp == DataOp.Arithmetic)
            {
                Imm = (opCode >> 10) & 0xfff;

                int shift = (opCode >> 22) & 3;

                Imm <<= shift * 12;
            }
            else if (DataOp == DataOp.Logical)
            {
                var bm = DecoderHelper.DecodeBitMask(opCode, true);

                if (bm.IsUndefined)
                {
                    Emitter = InstEmit.Und;

                    return;
                }

                Imm = bm.WMask;
            }
            else
            {
                throw new ArgumentException(nameof(opCode));
            }
        }
    }
}