aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Cpu/LightningJit/Arm64/SysUtils.cs
blob: 69689a3910bf9bc097ce7f582d7444aa087f8590 (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
using System.Diagnostics;

namespace Ryujinx.Cpu.LightningJit.Arm64
{
    static class SysUtils
    {
        public static (uint, uint, uint, uint) UnpackOp1CRnCRmOp2(uint encoding)
        {
            uint op1 = (encoding >> 16) & 7;
            uint crn = (encoding >> 12) & 0xf;
            uint crm = (encoding >> 8) & 0xf;
            uint op2 = (encoding >> 5) & 7;

            return (op1, crn, crm, op2);
        }

        public static bool IsCacheInstEl0(uint encoding)
        {
            (uint op1, uint crn, uint crm, uint op2) = UnpackOp1CRnCRmOp2(encoding);

            return ((op1 << 11) | (crn << 7) | (crm << 3) | op2) switch
            {
                0b011_0111_0100_001 => true, // DC ZVA
                0b011_0111_1010_001 => true, // DC CVAC
                0b011_0111_1100_001 => true, // DC CVAP
                0b011_0111_1011_001 => true, // DC CVAU
                0b011_0111_1110_001 => true, // DC CIVAC
                0b011_0111_0101_001 => true, // IC IVAU
                _ => false,
            };
        }

        public static bool IsCacheInstUciTrapped(uint encoding)
        {
            (uint op1, uint crn, uint crm, uint op2) = UnpackOp1CRnCRmOp2(encoding);

            return ((op1 << 11) | (crn << 7) | (crm << 3) | op2) switch
            {
                0b011_0111_1010_001 => true, // DC CVAC
                0b011_0111_1100_001 => true, // DC CVAP
                0b011_0111_1011_001 => true, // DC CVAU
                0b011_0111_1110_001 => true, // DC CIVAC
                0b011_0111_0101_001 => true, // IC IVAU
                _ => false,
            };
        }
    }
}