Coverage Report

Created: 2025-07-18 06:43

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