aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Cpu/LightningJit/Arm32/Target/Arm64/InstEmitBit.cs
blob: 3f91d45f225d9b9a2cb85f084e3fbdd89ccb6cda (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
98
99
100
101
102
103
using Ryujinx.Cpu.LightningJit.CodeGen;

namespace Ryujinx.Cpu.LightningJit.Arm32.Target.Arm64
{
    static class InstEmitBit
    {
        public static void Bfc(CodeGenContext context, uint rd, uint lsb, uint msb)
        {
            // This is documented as "unpredictable".
            if (msb < lsb)
            {
                return;
            }

            Operand rdOperand = InstEmitCommon.GetOutputGpr(context, rd);

            context.Arm64Assembler.Bfc(rdOperand, (int)lsb, (int)(msb - lsb + 1));
        }

        public static void Bfi(CodeGenContext context, uint rd, uint rn, uint lsb, uint msb)
        {
            // This is documented as "unpredictable".
            if (msb < lsb)
            {
                return;
            }

            Operand rdOperand = InstEmitCommon.GetOutputGpr(context, rd);
            Operand rnOperand = InstEmitCommon.GetInputGpr(context, rn);

            context.Arm64Assembler.Bfi(rdOperand, rnOperand, (int)lsb, (int)(msb - lsb + 1));
        }

        public static void Clz(CodeGenContext context, uint rd, uint rm)
        {
            Operand rdOperand = InstEmitCommon.GetOutputGpr(context, rd);
            Operand rmOperand = InstEmitCommon.GetInputGpr(context, rm);

            context.Arm64Assembler.Clz(rdOperand, rmOperand);
        }

        public static void Rbit(CodeGenContext context, uint rd, uint rm)
        {
            Operand rdOperand = InstEmitCommon.GetOutputGpr(context, rd);
            Operand rmOperand = InstEmitCommon.GetInputGpr(context, rm);

            context.Arm64Assembler.Rbit(rdOperand, rmOperand);
        }

        public static void Rev(CodeGenContext context, uint rd, uint rm)
        {
            Operand rdOperand = InstEmitCommon.GetOutputGpr(context, rd);
            Operand rmOperand = InstEmitCommon.GetInputGpr(context, rm);

            context.Arm64Assembler.Rev(rdOperand, rmOperand);
        }

        public static void Rev16(CodeGenContext context, uint rd, uint rm)
        {
            Operand rdOperand = InstEmitCommon.GetOutputGpr(context, rd);
            Operand rmOperand = InstEmitCommon.GetInputGpr(context, rm);

            context.Arm64Assembler.Rev16(rdOperand, rmOperand);
        }

        public static void Revsh(CodeGenContext context, uint rd, uint rm)
        {
            Operand rdOperand = InstEmitCommon.GetOutputGpr(context, rd);
            Operand rmOperand = InstEmitCommon.GetInputGpr(context, rm);

            context.Arm64Assembler.Rev16(rdOperand, rmOperand);
            context.Arm64Assembler.Sxth(rdOperand, rdOperand);
        }

        public static void Sbfx(CodeGenContext context, uint rd, uint rn, uint lsb, uint widthMinus1)
        {
            // This is documented as "unpredictable".
            if (lsb + widthMinus1 > 31)
            {
                return;
            }

            Operand rdOperand = InstEmitCommon.GetOutputGpr(context, rd);
            Operand rnOperand = InstEmitCommon.GetInputGpr(context, rn);

            context.Arm64Assembler.Sbfx(rdOperand, rnOperand, (int)lsb, (int)widthMinus1 + 1);
        }

        public static void Ubfx(CodeGenContext context, uint rd, uint rn, uint lsb, uint widthMinus1)
        {
            // This is documented as "unpredictable".
            if (lsb + widthMinus1 > 31)
            {
                return;
            }

            Operand rdOperand = InstEmitCommon.GetOutputGpr(context, rd);
            Operand rnOperand = InstEmitCommon.GetInputGpr(context, rn);

            context.Arm64Assembler.Ubfx(rdOperand, rnOperand, (int)lsb, (int)widthMinus1 + 1);
        }
    }
}