xref: /llvm-project/lldb/source/Plugins/Instruction/RISCV/RISCVCInstructions.h (revision 0ef58c66c6e4652ff3582bf0972673708afb912e)
105ae747aSEmmmer //===-- RISCVCInstructions.h ----------------------------------------------===//
205ae747aSEmmmer //
305ae747aSEmmmer // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
405ae747aSEmmmer // See https://llvm.org/LICENSE.txt for license information.
505ae747aSEmmmer // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
605ae747aSEmmmer //
705ae747aSEmmmer //===----------------------------------------------------------------------===//
805ae747aSEmmmer 
905ae747aSEmmmer #ifndef LLDB_SOURCE_PLUGINS_INSTRUCTION_RISCV_RISCVCINSTRUCTION_H
1005ae747aSEmmmer #define LLDB_SOURCE_PLUGINS_INSTRUCTION_RISCV_RISCVCINSTRUCTION_H
1105ae747aSEmmmer 
1205ae747aSEmmmer #include <cstdint>
1305ae747aSEmmmer #include <variant>
1405ae747aSEmmmer 
15cd02e78cSJordan Rupprecht #include "Plugins/Process/Utility/lldb-riscv-register-enums.h"
1605ae747aSEmmmer #include "RISCVInstructions.h"
1705ae747aSEmmmer 
1805ae747aSEmmmer namespace lldb_private {
1905ae747aSEmmmer 
2005ae747aSEmmmer /// Unified RISC-V C register encoding.
2105ae747aSEmmmer struct RxC {
2205ae747aSEmmmer   uint32_t rd;
2305ae747aSEmmmer   bool shift = true;
2405ae747aSEmmmer   operator int() { return rd; }
RdRxC2505ae747aSEmmmer   operator Rd() { return Rd{rd + (shift ? 8 : 0)}; }
RsRxC2605ae747aSEmmmer   operator Rs() { return Rs{rd + (shift ? 8 : 0)}; }
2705ae747aSEmmmer };
2805ae747aSEmmmer 
2905ae747aSEmmmer // decode register for RVC
DecodeCR_RD(uint32_t inst)3005ae747aSEmmmer constexpr RxC DecodeCR_RD(uint32_t inst) { return RxC{DecodeRD(inst), false}; }
DecodeCI_RD(uint32_t inst)3105ae747aSEmmmer constexpr RxC DecodeCI_RD(uint32_t inst) { return RxC{DecodeRD(inst), false}; }
DecodeCR_RS1(uint32_t inst)3205ae747aSEmmmer constexpr RxC DecodeCR_RS1(uint32_t inst) { return RxC{DecodeRD(inst), false}; }
DecodeCI_RS1(uint32_t inst)3305ae747aSEmmmer constexpr RxC DecodeCI_RS1(uint32_t inst) { return RxC{DecodeRD(inst), false}; }
DecodeCR_RS2(uint32_t inst)3405ae747aSEmmmer constexpr RxC DecodeCR_RS2(uint32_t inst) {
3505ae747aSEmmmer   return RxC{(inst & 0x7C) >> 2, false};
3605ae747aSEmmmer }
3705ae747aSEmmmer 
DecodeCIW_RD(uint32_t inst)3805ae747aSEmmmer constexpr RxC DecodeCIW_RD(uint32_t inst) { return RxC{(inst & 0x1C) >> 2}; }
DecodeCL_RD(uint32_t inst)3905ae747aSEmmmer constexpr RxC DecodeCL_RD(uint32_t inst) { return RxC{DecodeCIW_RD(inst)}; }
DecodeCA_RD(uint32_t inst)4005ae747aSEmmmer constexpr RxC DecodeCA_RD(uint32_t inst) { return RxC{(inst & 0x380) >> 7}; }
DecodeCB_RD(uint32_t inst)4105ae747aSEmmmer constexpr RxC DecodeCB_RD(uint32_t inst) { return RxC{DecodeCA_RD(inst)}; }
4205ae747aSEmmmer 
DecodeCL_RS1(uint32_t inst)4305ae747aSEmmmer constexpr RxC DecodeCL_RS1(uint32_t inst) { return RxC{DecodeCA_RD(inst)}; }
DecodeCS_RS1(uint32_t inst)4405ae747aSEmmmer constexpr RxC DecodeCS_RS1(uint32_t inst) { return RxC{DecodeCA_RD(inst)}; }
DecodeCA_RS1(uint32_t inst)4505ae747aSEmmmer constexpr RxC DecodeCA_RS1(uint32_t inst) { return RxC{DecodeCA_RD(inst)}; }
DecodeCB_RS1(uint32_t inst)4605ae747aSEmmmer constexpr RxC DecodeCB_RS1(uint32_t inst) { return RxC{DecodeCA_RD(inst)}; }
4705ae747aSEmmmer 
DecodeCSS_RS2(uint32_t inst)4805ae747aSEmmmer constexpr RxC DecodeCSS_RS2(uint32_t inst) { return DecodeCR_RS2(inst); }
DecodeCS_RS2(uint32_t inst)4905ae747aSEmmmer constexpr RxC DecodeCS_RS2(uint32_t inst) { return RxC{DecodeCIW_RD(inst)}; }
DecodeCA_RS2(uint32_t inst)5005ae747aSEmmmer constexpr RxC DecodeCA_RS2(uint32_t inst) { return RxC{DecodeCIW_RD(inst)}; }
5105ae747aSEmmmer 
DecodeC_LWSP(uint32_t inst)5205ae747aSEmmmer RISCVInst DecodeC_LWSP(uint32_t inst) {
5305ae747aSEmmmer   auto rd = DecodeCI_RD(inst);
5405ae747aSEmmmer   uint16_t offset = ((inst << 4) & 0xc0)    // offset[7:6]
5505ae747aSEmmmer                     | ((inst >> 7) & 0x20)  // offset[5]
5605ae747aSEmmmer                     | ((inst >> 2) & 0x1c); // offset[4:2]
5705ae747aSEmmmer   if (rd == 0)
5805ae747aSEmmmer     return RESERVED{inst};
5905ae747aSEmmmer   return LW{rd, Rs{gpr_sp_riscv}, uint32_t(offset)};
6005ae747aSEmmmer }
6105ae747aSEmmmer 
DecodeC_LDSP(uint32_t inst)6205ae747aSEmmmer RISCVInst DecodeC_LDSP(uint32_t inst) {
6305ae747aSEmmmer   auto rd = DecodeCI_RD(inst);
6405ae747aSEmmmer   uint16_t offset = ((inst << 4) & 0x1c0)   // offset[8:6]
6505ae747aSEmmmer                     | ((inst >> 7) & 0x20)  // offset[5]
6605ae747aSEmmmer                     | ((inst >> 2) & 0x18); // offset[4:3]
6705ae747aSEmmmer   if (rd == 0)
6805ae747aSEmmmer     return RESERVED{inst};
6905ae747aSEmmmer   return LD{rd, Rs{gpr_sp_riscv}, uint32_t(offset)};
7005ae747aSEmmmer }
7105ae747aSEmmmer 
DecodeC_SWSP(uint32_t inst)7205ae747aSEmmmer RISCVInst DecodeC_SWSP(uint32_t inst) {
7305ae747aSEmmmer   uint16_t offset = ((inst >> 1) & 0xc0)    // offset[7:6]
7405ae747aSEmmmer                     | ((inst >> 7) & 0x3c); // offset[5:2]
7505ae747aSEmmmer   return SW{Rs{gpr_sp_riscv}, DecodeCSS_RS2(inst), uint32_t(offset)};
7605ae747aSEmmmer }
7705ae747aSEmmmer 
DecodeC_SDSP(uint32_t inst)7805ae747aSEmmmer RISCVInst DecodeC_SDSP(uint32_t inst) {
7905ae747aSEmmmer   uint16_t offset = ((inst >> 1) & 0x1c0)   // offset[8:6]
8005ae747aSEmmmer                     | ((inst >> 7) & 0x38); // offset[5:3]
8105ae747aSEmmmer   return SD{Rs{gpr_sp_riscv}, DecodeCSS_RS2(inst), uint32_t(offset)};
8205ae747aSEmmmer }
8305ae747aSEmmmer 
DecodeC_LW(uint32_t inst)8405ae747aSEmmmer RISCVInst DecodeC_LW(uint32_t inst) {
8505ae747aSEmmmer   uint16_t offset = ((inst << 1) & 0x40)   // imm[6]
8605ae747aSEmmmer                     | ((inst >> 7) & 0x38) // imm[5:3]
8705ae747aSEmmmer                     | ((inst >> 4) & 0x4); // imm[2]
8805ae747aSEmmmer   return LW{DecodeCL_RD(inst), DecodeCL_RS1(inst), uint32_t(offset)};
8905ae747aSEmmmer }
9005ae747aSEmmmer 
DecodeC_LD(uint32_t inst)9105ae747aSEmmmer RISCVInst DecodeC_LD(uint32_t inst) {
9205ae747aSEmmmer   uint16_t offset = ((inst << 1) & 0xc0)    // imm[7:6]
9305ae747aSEmmmer                     | ((inst >> 7) & 0x38); // imm[5:3]
9405ae747aSEmmmer   return LD{DecodeCL_RD(inst), DecodeCL_RS1(inst), uint32_t(offset)};
9505ae747aSEmmmer }
9605ae747aSEmmmer 
DecodeC_SW(uint32_t inst)9705ae747aSEmmmer RISCVInst DecodeC_SW(uint32_t inst) {
9805ae747aSEmmmer   uint16_t offset = ((inst << 1) & 0x40)   // imm[6]
9905ae747aSEmmmer                     | ((inst >> 7) & 0x38) // imm[5:3]
10005ae747aSEmmmer                     | ((inst >> 4) & 0x4); // imm[2]
10105ae747aSEmmmer   return SW{DecodeCS_RS1(inst), DecodeCS_RS2(inst), uint32_t(offset)};
10205ae747aSEmmmer }
10305ae747aSEmmmer 
DecodeC_SD(uint32_t inst)10405ae747aSEmmmer RISCVInst DecodeC_SD(uint32_t inst) {
10505ae747aSEmmmer   uint16_t offset = ((inst << 1) & 0xc0)    // imm[7:6]
10605ae747aSEmmmer                     | ((inst >> 7) & 0x38); // imm[5:3]
10705ae747aSEmmmer   return SD{DecodeCS_RS1(inst), DecodeCS_RS2(inst), uint32_t(offset)};
10805ae747aSEmmmer }
10905ae747aSEmmmer 
DecodeC_J(uint32_t inst)11005ae747aSEmmmer RISCVInst DecodeC_J(uint32_t inst) {
11105ae747aSEmmmer   uint16_t offset = ((inst >> 1) & 0x800)   // offset[11]
11205ae747aSEmmmer                     | ((inst << 2) & 0x400) // offset[10]
11305ae747aSEmmmer                     | ((inst >> 1) & 0x300) // offset[9:8]
11405ae747aSEmmmer                     | ((inst << 1) & 0x80)  // offset[7]
11505ae747aSEmmmer                     | ((inst >> 1) & 0x40)  // offset[6]
11605ae747aSEmmmer                     | ((inst << 3) & 0x20)  // offset[5]
11705ae747aSEmmmer                     | ((inst >> 7) & 0x10)  // offset[4]
11805ae747aSEmmmer                     | ((inst >> 2) & 0xe);  // offset[3:1]
11905ae747aSEmmmer   if ((offset & 0x800) == 0)
12005ae747aSEmmmer     return JAL{Rd{0}, uint32_t(offset)};
12105ae747aSEmmmer   return JAL{Rd{0}, uint32_t(int32_t(int16_t(offset | 0xf000)))};
12205ae747aSEmmmer }
12305ae747aSEmmmer 
DecodeC_JR(uint32_t inst)12405ae747aSEmmmer RISCVInst DecodeC_JR(uint32_t inst) {
12505ae747aSEmmmer   auto rs1 = DecodeCR_RS1(inst);
12605ae747aSEmmmer   if (rs1 == 0)
12705ae747aSEmmmer     return RESERVED{inst};
12805ae747aSEmmmer   return JALR{Rd{0}, rs1, 0};
12905ae747aSEmmmer }
13005ae747aSEmmmer 
DecodeC_JALR(uint32_t inst)13105ae747aSEmmmer RISCVInst DecodeC_JALR(uint32_t inst) {
13205ae747aSEmmmer   auto rs1 = DecodeCR_RS1(inst);
13305ae747aSEmmmer   if (rs1 == 0)
13405ae747aSEmmmer     return EBREAK{inst};
13505ae747aSEmmmer   return JALR{Rd{1}, rs1, 0};
13605ae747aSEmmmer }
13705ae747aSEmmmer 
BOffset(uint32_t inst)13805ae747aSEmmmer constexpr uint16_t BOffset(uint32_t inst) {
13905ae747aSEmmmer   return ((inst >> 4) & 0x100)  // offset[8]
14005ae747aSEmmmer          | ((inst << 1) & 0xc0) // offset[7:6]
14105ae747aSEmmmer          | ((inst << 3) & 0x20) // offset[5]
14205ae747aSEmmmer          | ((inst >> 7) & 0x18) // offset[4:3]
14305ae747aSEmmmer          | ((inst >> 2) & 0x6); // offset[2:1]
14405ae747aSEmmmer }
14505ae747aSEmmmer 
DecodeC_BNEZ(uint32_t inst)14605ae747aSEmmmer RISCVInst DecodeC_BNEZ(uint32_t inst) {
14705ae747aSEmmmer   auto rs1 = DecodeCB_RS1(inst);
14805ae747aSEmmmer   uint16_t offset = BOffset(inst);
14905ae747aSEmmmer   if ((offset & 0x100) == 0)
15005ae747aSEmmmer     return B{rs1, Rs{0}, uint32_t(offset), 0b001};
15105ae747aSEmmmer   return B{rs1, Rs{0}, uint32_t(int32_t(int16_t(offset | 0xfe00))), 0b001};
15205ae747aSEmmmer }
15305ae747aSEmmmer 
DecodeC_BEQZ(uint32_t inst)15405ae747aSEmmmer RISCVInst DecodeC_BEQZ(uint32_t inst) {
15505ae747aSEmmmer   auto rs1 = DecodeCB_RS1(inst);
15605ae747aSEmmmer   uint16_t offset = BOffset(inst);
15705ae747aSEmmmer   if ((offset & 0x100) == 0)
15805ae747aSEmmmer     return B{rs1, Rs{0}, uint32_t(offset), 0b000};
15905ae747aSEmmmer   return B{rs1, Rs{0}, uint32_t(int32_t(int16_t(offset | 0xfe00))), 0b000};
16005ae747aSEmmmer }
16105ae747aSEmmmer 
DecodeC_LI(uint32_t inst)16205ae747aSEmmmer RISCVInst DecodeC_LI(uint32_t inst) {
16305ae747aSEmmmer   auto rd = DecodeCI_RD(inst);
16405ae747aSEmmmer   uint16_t imm = ((inst >> 7) & 0x20) | ((inst >> 2) & 0x1f);
16505ae747aSEmmmer   if ((imm & 0x20) == 0)
16605ae747aSEmmmer     return ADDI{rd, Rs{0}, uint32_t(imm)};
16705ae747aSEmmmer   return ADDI{rd, Rs{0}, uint32_t(int32_t(int8_t(imm | 0xc0)))};
16805ae747aSEmmmer }
16905ae747aSEmmmer 
DecodeC_LUI_ADDI16SP(uint32_t inst)17005ae747aSEmmmer RISCVInst DecodeC_LUI_ADDI16SP(uint32_t inst) {
17105ae747aSEmmmer   auto rd = DecodeCI_RD(inst);
17205ae747aSEmmmer   if (rd == 0)
17305ae747aSEmmmer     return HINT{inst};
17405ae747aSEmmmer   if (rd == 2) {
17505ae747aSEmmmer     uint16_t nzimm = ((inst >> 3) & 0x200)   // nzimm[9]
17605ae747aSEmmmer                      | ((inst >> 2) & 0x10)  // nzimm[4]
17705ae747aSEmmmer                      | ((inst << 1) & 0x40)  // nzimm[6]
17805ae747aSEmmmer                      | ((inst << 4) & 0x180) // nzimm[8:7]
17905ae747aSEmmmer                      | ((inst << 3) & 0x20); // nzimm[5]
18005ae747aSEmmmer     if (nzimm == 0)
18105ae747aSEmmmer       return RESERVED{inst};
18205ae747aSEmmmer     if ((nzimm & 0x200) == 0)
18305ae747aSEmmmer       return ADDI{Rd{gpr_sp_riscv}, Rs{gpr_sp_riscv}, uint32_t(nzimm)};
18405ae747aSEmmmer     return ADDI{Rd{gpr_sp_riscv}, Rs{gpr_sp_riscv},
18505ae747aSEmmmer                 uint32_t(int32_t(int16_t(nzimm | 0xfc00)))};
18605ae747aSEmmmer   }
18705ae747aSEmmmer   uint32_t imm =
18805ae747aSEmmmer       ((uint32_t(inst) << 5) & 0x20000) | ((uint32_t(inst) << 10) & 0x1f000);
18905ae747aSEmmmer   if ((imm & 0x20000) == 0)
19005ae747aSEmmmer     return LUI{rd, imm};
19105ae747aSEmmmer   return LUI{rd, uint32_t(int32_t(imm | 0xfffc0000))};
19205ae747aSEmmmer }
19305ae747aSEmmmer 
DecodeC_ADDI(uint32_t inst)19405ae747aSEmmmer RISCVInst DecodeC_ADDI(uint32_t inst) {
19505ae747aSEmmmer   auto rd = DecodeCI_RD(inst);
19605ae747aSEmmmer   if (rd == 0)
19705ae747aSEmmmer     return NOP{inst};
19805ae747aSEmmmer   uint16_t imm = ((inst >> 7) & 0x20) | ((inst >> 2) & 0x1f);
19905ae747aSEmmmer   if ((imm & 0x20) == 0)
20005ae747aSEmmmer     return ADDI{rd, rd, uint32_t(imm)};
20105ae747aSEmmmer   return ADDI{rd, rd, uint32_t(int32_t(int8_t(imm | 0xc0)))};
20205ae747aSEmmmer }
20305ae747aSEmmmer 
DecodeC_ADDIW(uint32_t inst)20405ae747aSEmmmer RISCVInst DecodeC_ADDIW(uint32_t inst) {
20505ae747aSEmmmer   auto rd = DecodeCI_RD(inst);
20605ae747aSEmmmer   if (rd == 0)
20705ae747aSEmmmer     return RESERVED{inst};
20805ae747aSEmmmer   uint16_t imm = ((inst >> 7) & 0x20) | ((inst >> 2) & 0x1f);
20905ae747aSEmmmer   if ((imm & 0x20) == 0)
21005ae747aSEmmmer     return ADDIW{rd, rd, uint32_t(imm)};
21105ae747aSEmmmer   return ADDIW{rd, rd, uint32_t(int32_t(int8_t(imm | 0xc0)))};
21205ae747aSEmmmer }
21305ae747aSEmmmer 
DecodeC_ADDI4SPN(uint32_t inst)21405ae747aSEmmmer RISCVInst DecodeC_ADDI4SPN(uint32_t inst) {
21505ae747aSEmmmer   auto rd = DecodeCIW_RD(inst);
21605ae747aSEmmmer   uint16_t nzuimm = ((inst >> 1) & 0x3c0)  // nzuimm[9:6]
21705ae747aSEmmmer                     | ((inst >> 7) & 0x30) // nzuimm[5:4]
21805ae747aSEmmmer                     | ((inst >> 2) & 0x8)  // nzuimm[3]
21905ae747aSEmmmer                     | ((inst >> 4) & 0x4); // nzuimm[2]
22005ae747aSEmmmer 
22105ae747aSEmmmer   if (rd == 0 && nzuimm == 0)
22205ae747aSEmmmer     return INVALID{inst};
22305ae747aSEmmmer   if (nzuimm == 0)
22405ae747aSEmmmer     return RESERVED{inst};
22505ae747aSEmmmer   return ADDI{rd, Rs{gpr_sp_riscv}, uint32_t(nzuimm)};
22605ae747aSEmmmer }
22705ae747aSEmmmer 
DecodeC_SLLI(uint32_t inst)22805ae747aSEmmmer RISCVInst DecodeC_SLLI(uint32_t inst) {
22905ae747aSEmmmer   auto rd = DecodeCI_RD(inst);
23005ae747aSEmmmer   uint16_t shamt = ((inst >> 7) & 0x20) | ((inst >> 2) & 0x1f);
23105ae747aSEmmmer   if (rd == 0 || shamt == 0)
23205ae747aSEmmmer     return HINT{inst};
23305ae747aSEmmmer   return SLLI{rd, rd, uint8_t(shamt)};
23405ae747aSEmmmer }
23505ae747aSEmmmer 
DecodeC_SRLI(uint32_t inst)23605ae747aSEmmmer RISCVInst DecodeC_SRLI(uint32_t inst) {
23705ae747aSEmmmer   auto rd = DecodeCB_RD(inst);
23805ae747aSEmmmer   uint16_t shamt = ((inst >> 7) & 0x20) | ((inst >> 2) & 0x1f);
23905ae747aSEmmmer   if (shamt == 0)
24005ae747aSEmmmer     return HINT{inst};
24105ae747aSEmmmer   return SRLI{rd, rd, uint8_t(shamt)};
24205ae747aSEmmmer }
24305ae747aSEmmmer 
DecodeC_SRAI(uint32_t inst)24405ae747aSEmmmer RISCVInst DecodeC_SRAI(uint32_t inst) {
24505ae747aSEmmmer   auto rd = DecodeCB_RD(inst);
24605ae747aSEmmmer   uint16_t shamt = ((inst >> 7) & 0x20) | ((inst >> 2) & 0x1f);
24705ae747aSEmmmer   if (shamt == 0)
24805ae747aSEmmmer     return HINT{inst};
24905ae747aSEmmmer   return SRAI{rd, rd, uint8_t(shamt)};
25005ae747aSEmmmer }
25105ae747aSEmmmer 
DecodeC_ANDI(uint32_t inst)25205ae747aSEmmmer RISCVInst DecodeC_ANDI(uint32_t inst) {
25305ae747aSEmmmer   auto rd = DecodeCB_RD(inst);
25405ae747aSEmmmer   uint16_t imm = ((inst >> 7) & 0x20) | ((inst >> 2) & 0x1f);
25505ae747aSEmmmer   if ((imm & 0x20) == 0)
25605ae747aSEmmmer     return ANDI{rd, rd, uint32_t(imm)};
25705ae747aSEmmmer   return ANDI{rd, rd, uint32_t(int32_t(int8_t(imm | 0xc0)))};
25805ae747aSEmmmer }
25905ae747aSEmmmer 
DecodeC_MV(uint32_t inst)26005ae747aSEmmmer RISCVInst DecodeC_MV(uint32_t inst) {
26105ae747aSEmmmer   auto rd = DecodeCR_RD(inst);
26205ae747aSEmmmer   auto rs2 = DecodeCR_RS2(inst);
26305ae747aSEmmmer   if (rd == 0)
26405ae747aSEmmmer     return HINT{inst};
26505ae747aSEmmmer   return ADD{rd, Rs{0}, rs2};
26605ae747aSEmmmer }
26705ae747aSEmmmer 
DecodeC_ADD(uint32_t inst)26805ae747aSEmmmer RISCVInst DecodeC_ADD(uint32_t inst) {
26905ae747aSEmmmer   auto rd = DecodeCR_RD(inst);
27005ae747aSEmmmer   return ADD{rd, rd, DecodeCR_RS2(inst)};
27105ae747aSEmmmer }
27205ae747aSEmmmer 
DecodeC_AND(uint32_t inst)27305ae747aSEmmmer RISCVInst DecodeC_AND(uint32_t inst) {
27405ae747aSEmmmer   auto rd = DecodeCA_RD(inst);
27505ae747aSEmmmer   return AND{rd, rd, DecodeCA_RS2(inst)};
27605ae747aSEmmmer }
27705ae747aSEmmmer 
DecodeC_OR(uint32_t inst)27805ae747aSEmmmer RISCVInst DecodeC_OR(uint32_t inst) {
27905ae747aSEmmmer   auto rd = DecodeCA_RD(inst);
28005ae747aSEmmmer   return OR{rd, rd, DecodeCA_RS2(inst)};
28105ae747aSEmmmer }
28205ae747aSEmmmer 
DecodeC_XOR(uint32_t inst)28305ae747aSEmmmer RISCVInst DecodeC_XOR(uint32_t inst) {
28405ae747aSEmmmer   auto rd = DecodeCA_RD(inst);
28505ae747aSEmmmer   return XOR{rd, rd, DecodeCA_RS2(inst)};
28605ae747aSEmmmer }
28705ae747aSEmmmer 
DecodeC_SUB(uint32_t inst)28805ae747aSEmmmer RISCVInst DecodeC_SUB(uint32_t inst) {
28905ae747aSEmmmer   auto rd = DecodeCA_RD(inst);
29005ae747aSEmmmer   return SUB{rd, rd, DecodeCA_RS2(inst)};
29105ae747aSEmmmer }
29205ae747aSEmmmer 
DecodeC_SUBW(uint32_t inst)29305ae747aSEmmmer RISCVInst DecodeC_SUBW(uint32_t inst) {
29405ae747aSEmmmer   auto rd = DecodeCA_RD(inst);
29505ae747aSEmmmer   return SUBW{rd, rd, DecodeCA_RS2(inst)};
29605ae747aSEmmmer }
29705ae747aSEmmmer 
DecodeC_ADDW(uint32_t inst)29805ae747aSEmmmer RISCVInst DecodeC_ADDW(uint32_t inst) {
29905ae747aSEmmmer   auto rd = DecodeCA_RD(inst);
30005ae747aSEmmmer   return ADDW{rd, rd, DecodeCA_RS2(inst)};
30105ae747aSEmmmer }
DecodeC_FLW(uint32_t inst)302d3628823SEmmmer RISCVInst DecodeC_FLW(uint32_t inst) {
303d3628823SEmmmer   uint16_t offset = ((inst << 1) & 0x40)   // imm[6]
304d3628823SEmmmer                     | ((inst >> 7) & 0x38) // imm[5:3]
305d3628823SEmmmer                     | ((inst >> 4) & 0x4); // imm[2]
306d3628823SEmmmer   return FLW{DecodeCL_RD(inst), DecodeCL_RS1(inst), uint32_t(offset)};
307d3628823SEmmmer }
308d3628823SEmmmer 
DecodeC_FSW(uint32_t inst)309d3628823SEmmmer RISCVInst DecodeC_FSW(uint32_t inst) {
310d3628823SEmmmer   uint16_t offset = ((inst << 1) & 0x40)   // imm[6]
311d3628823SEmmmer                     | ((inst >> 7) & 0x38) // imm[5:3]
312d3628823SEmmmer                     | ((inst >> 4) & 0x4); // imm[2]
313d3628823SEmmmer   return FSW{DecodeCS_RS1(inst), DecodeCS_RS2(inst), uint32_t(offset)};
314d3628823SEmmmer }
315d3628823SEmmmer 
DecodeC_FLWSP(uint32_t inst)316d3628823SEmmmer RISCVInst DecodeC_FLWSP(uint32_t inst) {
317d3628823SEmmmer   auto rd = DecodeCI_RD(inst);
318d3628823SEmmmer   uint16_t offset = ((inst << 4) & 0xc0)    // offset[7:6]
319d3628823SEmmmer                     | ((inst >> 7) & 0x20)  // offset[5]
320d3628823SEmmmer                     | ((inst >> 2) & 0x1c); // offset[4:2]
321d3628823SEmmmer   return FLW{rd, Rs{gpr_sp_riscv}, uint32_t(offset)};
322d3628823SEmmmer }
323d3628823SEmmmer 
DecodeC_FSWSP(uint32_t inst)324d3628823SEmmmer RISCVInst DecodeC_FSWSP(uint32_t inst) {
325d3628823SEmmmer   uint16_t offset = ((inst >> 1) & 0xc0)    // offset[7:6]
326d3628823SEmmmer                     | ((inst >> 7) & 0x3c); // offset[5:2]
327d3628823SEmmmer   return FSW{Rs{gpr_sp_riscv}, DecodeCSS_RS2(inst), uint32_t(offset)};
328d3628823SEmmmer }
32905ae747aSEmmmer 
DecodeC_FLDSP(uint32_t inst)330*0ef58c66SEmmmer RISCVInst DecodeC_FLDSP(uint32_t inst) {
331*0ef58c66SEmmmer   auto rd = DecodeCI_RD(inst);
332*0ef58c66SEmmmer   uint16_t offset = ((inst << 4) & 0x1c0)   // offset[8:6]
333*0ef58c66SEmmmer                     | ((inst >> 7) & 0x20)  // offset[5]
334*0ef58c66SEmmmer                     | ((inst >> 2) & 0x18); // offset[4:3]
335*0ef58c66SEmmmer   return FLD{rd, Rs{gpr_sp_riscv}, uint32_t(offset)};
336*0ef58c66SEmmmer }
337*0ef58c66SEmmmer 
DecodeC_FSDSP(uint32_t inst)338*0ef58c66SEmmmer RISCVInst DecodeC_FSDSP(uint32_t inst) {
339*0ef58c66SEmmmer   uint16_t offset = ((inst >> 1) & 0x1c0)   // offset[8:6]
340*0ef58c66SEmmmer                     | ((inst >> 7) & 0x38); // offset[5:3]
341*0ef58c66SEmmmer   return FSD{Rs{gpr_sp_riscv}, DecodeCSS_RS2(inst), uint32_t(offset)};
342*0ef58c66SEmmmer }
343*0ef58c66SEmmmer 
DecodeC_FLD(uint32_t inst)344*0ef58c66SEmmmer RISCVInst DecodeC_FLD(uint32_t inst) {
345*0ef58c66SEmmmer   uint16_t offset = ((inst << 1) & 0xc0)    // imm[7:6]
346*0ef58c66SEmmmer                     | ((inst >> 7) & 0x38); // imm[5:3]
347*0ef58c66SEmmmer   return FLD{DecodeCL_RD(inst), DecodeCL_RS1(inst), uint32_t(offset)};
348*0ef58c66SEmmmer }
349*0ef58c66SEmmmer 
DecodeC_FSD(uint32_t inst)350*0ef58c66SEmmmer RISCVInst DecodeC_FSD(uint32_t inst) {
351*0ef58c66SEmmmer   uint16_t offset = ((inst << 1) & 0xc0)    // imm[7:6]
352*0ef58c66SEmmmer                     | ((inst >> 7) & 0x38); // imm[5:3]
353*0ef58c66SEmmmer   return FSD{DecodeCS_RS1(inst), DecodeCS_RS2(inst), uint32_t(offset)};
354*0ef58c66SEmmmer }
355*0ef58c66SEmmmer 
35605ae747aSEmmmer } // namespace lldb_private
35705ae747aSEmmmer #endif // LLDB_SOURCE_PLUGINS_INSTRUCTION_RISCV_RISCVCINSTRUCTION_H
358