Coverage Report

Created: 2024-09-08 06:22

/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
5.72k
{
13
5.72k
  return Reg >= PPC_VF0 && Reg <= PPC_VF31;
14
5.72k
}
15
static bool isVRRegister(unsigned Reg)
16
6.92k
{
17
6.92k
  return Reg >= PPC_V0 && Reg <= PPC_V31;
18
6.92k
}
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
141k
{
31
141k
  int16_t regClass = Desc->OpInfo[OpNo].RegClass;
32
141k
  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.43k
  case PPC_VSSRCRegClassID:
36
5.72k
  case PPC_VSFRCRegClassID:
37
5.72k
    if (isVFRegister(Reg))
38
1.24k
      return PPC_VSX32 + (Reg - PPC_VF0);
39
4.47k
    break;
40
  // We store VSL0-VSL31, V0-V31 in MCOperand and it should be VSL0-VSL31,
41
  // VSX32-VSX63 during encoding/disassembling
42
6.92k
  case PPC_VSRCRegClassID:
43
6.92k
    if (isVRRegister(Reg))
44
2.49k
      return PPC_VSX32 + (Reg - PPC_V0);
45
4.42k
    break;
46
  // Other RegClass doesn't need mapping
47
128k
  default:
48
128k
    break;
49
141k
  }
50
137k
  return Reg;
51
141k
}
52
53
#endif // CS_PPC_INSTRINFO_H