Coverage Report

Created: 2025-07-04 06:11

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