/src/capstonenext/arch/PowerPC/PPCInstrInfo.h
Line  | Count  | Source  | 
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  |  | static bool isVFRegister(unsigned Reg)  | 
10  | 11.6k  | { | 
11  | 11.6k  |   return Reg >= PPC_VF0 && Reg <= PPC_VF31;  | 
12  | 11.6k  | }  | 
13  |  | static bool isVRRegister(unsigned Reg)  | 
14  | 11.6k  | { | 
15  | 11.6k  |   return Reg >= PPC_V0 && Reg <= PPC_V31;  | 
16  | 11.6k  | }  | 
17  |  |  | 
18  |  | /// getRegNumForOperand - some operands use different numbering schemes  | 
19  |  | /// for the same registers. For example, a VSX instruction may have any of  | 
20  |  | /// vs0-vs63 allocated whereas an Altivec instruction could only have  | 
21  |  | /// vs32-vs63 allocated (numbered as v0-v31). This function returns the actual  | 
22  |  | /// register number needed for the opcode/operand number combination.  | 
23  |  | /// The operand number argument will be useful when we need to extend this  | 
24  |  | /// to instructions that use both Altivec and VSX numbering (for different  | 
25  |  | /// operands).  | 
26  |  | static unsigned PPCInstrInfo_getRegNumForOperand(const MCInstrDesc *Desc,  | 
27  |  |              unsigned Reg, unsigned OpNo)  | 
28  | 138k  | { | 
29  | 138k  |   int16_t regClass = Desc->OpInfo[OpNo].RegClass;  | 
30  | 138k  |   switch (regClass) { | 
31  |  |   // We store F0-F31, VF0-VF31 in MCOperand and it should be F0-F31,  | 
32  |  |   // VSX32-VSX63 during encoding/disassembling  | 
33  | 7.19k  |   case PPC_VSSRCRegClassID:  | 
34  | 11.6k  |   case PPC_VSFRCRegClassID:  | 
35  | 11.6k  |     if (isVFRegister(Reg))  | 
36  | 2.82k  |       return PPC_VSX32 + (Reg - PPC_VF0);  | 
37  | 8.86k  |     break;  | 
38  |  |   // We store VSL0-VSL31, V0-V31 in MCOperand and it should be VSL0-VSL31,  | 
39  |  |   // VSX32-VSX63 during encoding/disassembling  | 
40  | 11.6k  |   case PPC_VSRCRegClassID:  | 
41  | 11.6k  |     if (isVRRegister(Reg))  | 
42  | 4.03k  |       return PPC_VSX32 + (Reg - PPC_V0);  | 
43  | 7.56k  |     break;  | 
44  |  |   // Other RegClass doesn't need mapping  | 
45  | 115k  |   default:  | 
46  | 115k  |     break;  | 
47  | 138k  |   }  | 
48  | 131k  |   return Reg;  | 
49  | 138k  | }  | 
50  |  |  | 
51  |  | #endif // CS_PPC_INSTRINFO_H  |