Skip to content

Commit 0ef58c6

Browse files
author
Emmmer
committed
[LLDB][RISCV] Add RVDC instruction support for EmulateInstructionRISCV
RVC is the RISC-V standard compressed instruction-set extension, named "C", which reduces static and dynamic code size by adding short 16-bit instruction encodings for common operations, and RVCD is the compressed "D extension". And "D extension" is a double-precision floating-point instruction-set extension, which adds double-precision floating-point computational instructions compliant with the IEEE 754-2008 arithmetic standard. Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D140961
1 parent 8c77c01 commit 0ef58c6

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,11 @@ static const InstrPattern PATTERNS[] = {
541541
{"FSW", 0xE003, 0xE000, DecodeC_FSW, RV32},
542542
{"FLWSP", 0xE003, 0x6002, DecodeC_FLWSP, RV32},
543543
{"FSWSP", 0xE003, 0xE002, DecodeC_FSWSP, RV32},
544+
// RVDC //
545+
{"FLDSP", 0xE003, 0x2002, DecodeC_FLDSP, RV32 | RV64},
546+
{"FSDSP", 0xE003, 0xA002, DecodeC_FSDSP, RV32 | RV64},
547+
{"FLD", 0xE003, 0x2000, DecodeC_FLD, RV32 | RV64},
548+
{"FSD", 0xE003, 0xA000, DecodeC_FSD, RV32 | RV64},
544549

545550
// RV32F (Extension for Single-Precision Floating-Point) //
546551
{"FLW", 0x707F, 0x2007, DecodeIType<FLW>},

lldb/source/Plugins/Instruction/RISCV/RISCVCInstructions.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,5 +327,31 @@ RISCVInst DecodeC_FSWSP(uint32_t inst) {
327327
return FSW{Rs{gpr_sp_riscv}, DecodeCSS_RS2(inst), uint32_t(offset)};
328328
}
329329

330+
RISCVInst DecodeC_FLDSP(uint32_t inst) {
331+
auto rd = DecodeCI_RD(inst);
332+
uint16_t offset = ((inst << 4) & 0x1c0) // offset[8:6]
333+
| ((inst >> 7) & 0x20) // offset[5]
334+
| ((inst >> 2) & 0x18); // offset[4:3]
335+
return FLD{rd, Rs{gpr_sp_riscv}, uint32_t(offset)};
336+
}
337+
338+
RISCVInst DecodeC_FSDSP(uint32_t inst) {
339+
uint16_t offset = ((inst >> 1) & 0x1c0) // offset[8:6]
340+
| ((inst >> 7) & 0x38); // offset[5:3]
341+
return FSD{Rs{gpr_sp_riscv}, DecodeCSS_RS2(inst), uint32_t(offset)};
342+
}
343+
344+
RISCVInst DecodeC_FLD(uint32_t inst) {
345+
uint16_t offset = ((inst << 1) & 0xc0) // imm[7:6]
346+
| ((inst >> 7) & 0x38); // imm[5:3]
347+
return FLD{DecodeCL_RD(inst), DecodeCL_RS1(inst), uint32_t(offset)};
348+
}
349+
350+
RISCVInst DecodeC_FSD(uint32_t inst) {
351+
uint16_t offset = ((inst << 1) & 0xc0) // imm[7:6]
352+
| ((inst >> 7) & 0x38); // imm[5:3]
353+
return FSD{DecodeCS_RS1(inst), DecodeCS_RS2(inst), uint32_t(offset)};
354+
}
355+
330356
} // namespace lldb_private
331357
#endif // LLDB_SOURCE_PLUGINS_INSTRUCTION_RISCV_RISCVCINSTRUCTION_H

lldb/unittests/Instruction/RISCV/TestRISCVEmulator.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,10 @@ TEST_F(RISCVEmulatorTester, TestCDecode) {
287287
{0x0010, RESERVED{0x0010}},
288288
// ADDI4SPN here, decode as ADDI
289289
{0x0024, ADDI{Rd{9}, Rs{2}, 8}},
290+
{0x2084, FLD{Rd{9}, Rs{9}, 0}},
290291
{0x4488, LW{Rd{10}, Rs{9}, 8}},
291292
{0x6488, LD{Rd{10}, Rs{9}, 8}},
293+
{0xA084, FSD{Rs{9}, Rs{9}, 0}},
292294
{0xC488, SW{Rs{9}, Rs{10}, 8}},
293295
{0xE488, SD{Rs{9}, Rs{10}, 8}},
294296
{0x1001, NOP{0x1001}},
@@ -315,6 +317,8 @@ TEST_F(RISCVEmulatorTester, TestCDecode) {
315317
{0x1002, HINT{0x1002}},
316318
// SLLI64 here, decoded as HINT if not in RV128
317319
{0x0082, HINT{0x0082}},
320+
// FLDSP here, decoded as FLD
321+
{0x2082, FLD{Rd{1}, Rs{2}, 0}},
318322
// LWSP here, decoded as LW
319323
{0x4082, LW{Rd{1}, Rs{2}, 0}},
320324
// LDSP here, decoded as LD
@@ -326,6 +330,8 @@ TEST_F(RISCVEmulatorTester, TestCDecode) {
326330
{0x9002, EBREAK{0x9002}},
327331
{0x9082, JALR{Rd{1}, Rs{1}, 0}},
328332
{0x9086, ADD{Rd{1}, Rs{1}, Rs{1}}},
333+
// C.FSDSP here, decoded as FSD
334+
{0xA006, FSD{Rs{2}, Rs{1}, 0}},
329335
// C.SWSP here, decoded as SW
330336
{0xC006, SW{Rs{2}, Rs{1}, 0}},
331337
// C.SDSP here, decoded as SD
@@ -350,6 +356,11 @@ TEST_F(RISCVEmulatorTester32, TestCDecodeRV32) {
350356
{0xE006, FSW{Rs{2}, Rs{1}, 0}},
351357
{0x6000, FLW{Rd{8}, Rs{8}, 0}},
352358
{0xE000, FSW{Rs{8}, Rs{8}, 0}},
359+
360+
{0x2084, FLD{Rd{9}, Rs{9}, 0}},
361+
{0xA084, FSD{Rs{9}, Rs{9}, 0}},
362+
{0x2082, FLD{Rd{1}, Rs{2}, 0}},
363+
{0xA006, FSD{Rs{2}, Rs{1}, 0}},
353364
};
354365

355366
for (auto i : tests) {

0 commit comments

Comments
 (0)