/src/capstonenext/arch/PowerPC/PPCInstrInfo.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* Capstone Disassembly Engine, http://www.capstone-engine.org */ |
2 | | /* By Rot127 <unisono@quyllur.org> 2022-2023 */ |
3 | | |
4 | | #ifndef CS_PPC_INSTRINFO_H |
5 | | #define CS_PPC_INSTRINFO_H |
6 | | |
7 | | #include "PPCMCTargetDesc.h" |
8 | | |
9 | | extern const MCInstrDesc PPCInsts[]; |
10 | | |
11 | | static bool isVFRegister(unsigned Reg) |
12 | 6.68k | { |
13 | 6.68k | return Reg >= PPC_VF0 && Reg <= PPC_VF31; |
14 | 6.68k | } |
15 | | static bool isVRRegister(unsigned Reg) |
16 | 6.08k | { |
17 | 6.08k | return Reg >= PPC_V0 && Reg <= PPC_V31; |
18 | 6.08k | } |
19 | | |
20 | | /// getRegNumForOperand - some operands use different numbering schemes |
21 | | /// for the same registers. For example, a VSX instruction may have any of |
22 | | /// vs0-vs63 allocated whereas an Altivec instruction could only have |
23 | | /// vs32-vs63 allocated (numbered as v0-v31). This function returns the actual |
24 | | /// register number needed for the opcode/operand number combination. |
25 | | /// The operand number argument will be useful when we need to extend this |
26 | | /// to instructions that use both Altivec and VSX numbering (for different |
27 | | /// operands). |
28 | | static unsigned PPCInstrInfo_getRegNumForOperand(const MCInstrDesc *Desc, |
29 | | unsigned Reg, unsigned OpNo) |
30 | 99.8k | { |
31 | 99.8k | int16_t regClass = Desc->OpInfo[OpNo].RegClass; |
32 | 99.8k | switch (regClass) { |
33 | | // We store F0-F31, VF0-VF31 in MCOperand and it should be F0-F31, |
34 | | // VSX32-VSX63 during encoding/disassembling |
35 | 4.97k | case PPC_VSSRCRegClassID: |
36 | 6.68k | case PPC_VSFRCRegClassID: |
37 | 6.68k | if (isVFRegister(Reg)) |
38 | 1.05k | return PPC_VSX32 + (Reg - PPC_VF0); |
39 | 5.63k | break; |
40 | | // We store VSL0-VSL31, V0-V31 in MCOperand and it should be VSL0-VSL31, |
41 | | // VSX32-VSX63 during encoding/disassembling |
42 | 6.08k | case PPC_VSRCRegClassID: |
43 | 6.08k | if (isVRRegister(Reg)) |
44 | 2.23k | return PPC_VSX32 + (Reg - PPC_V0); |
45 | 3.84k | break; |
46 | | // Other RegClass doesn't need mapping |
47 | 87.0k | default: |
48 | 87.0k | break; |
49 | 99.8k | } |
50 | 96.5k | return Reg; |
51 | 99.8k | } |
52 | | |
53 | | #endif // CS_PPC_INSTRINFO_H |