Coverage Report

Created: 2025-07-01 07:03

/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
static bool isVFRegister(unsigned Reg)
10
4.68k
{
11
4.68k
  return Reg >= PPC_VF0 && Reg <= PPC_VF31;
12
4.68k
}
13
static bool isVRRegister(unsigned Reg)
14
4.64k
{
15
4.64k
  return Reg >= PPC_V0 && Reg <= PPC_V31;
16
4.64k
}
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
75.3k
{
29
75.3k
  int16_t regClass = Desc->OpInfo[OpNo].RegClass;
30
75.3k
  switch (regClass) {
31
  // We store F0-F31, VF0-VF31 in MCOperand and it should be F0-F31,
32
  // VSX32-VSX63 during encoding/disassembling
33
3.05k
  case PPC_VSSRCRegClassID:
34
4.68k
  case PPC_VSFRCRegClassID:
35
4.68k
    if (isVFRegister(Reg))
36
1.37k
      return PPC_VSX32 + (Reg - PPC_VF0);
37
3.30k
    break;
38
  // We store VSL0-VSL31, V0-V31 in MCOperand and it should be VSL0-VSL31,
39
  // VSX32-VSX63 during encoding/disassembling
40
4.64k
  case PPC_VSRCRegClassID:
41
4.64k
    if (isVRRegister(Reg))
42
1.84k
      return PPC_VSX32 + (Reg - PPC_V0);
43
2.79k
    break;
44
  // Other RegClass doesn't need mapping
45
65.9k
  default:
46
65.9k
    break;
47
75.3k
  }
48
72.1k
  return Reg;
49
75.3k
}
50
51
#endif // CS_PPC_INSTRINFO_H