Skip to content

Commit 6921cd1

Browse files
committed
RISC-V: Cache instruction support
Calling riscv_subset_supports repeatedly harms the performance in a measurable way (about 3-13% in total on the most cases). As a simple solution, this commit now caches instruction class support (whether specific instruction class is supported) as a signed char array. It is expected to have 5-7% performance improvements when disassembling linked RISC-V ELF programs using objdump but this is particularly effective with programs with many CSR instructions (up to ~42% on the author's PC). include/ChangeLog: * opcode/riscv.h (enum riscv_insn_class): Add NUM_INSN_CLASSES. opcodes/ChangeLog: * riscv-dis.c (riscv_insn_support_cache) New. (init_riscv_dis_state_for_arch): Clear the instruction support cache. (riscv_disassemble_insn): Cache the instruction support.
1 parent 3ed5e58 commit 6921cd1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

include/opcode/riscv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ enum riscv_insn_class
453453
INSN_CLASS_XTHEADMEMPAIR,
454454
INSN_CLASS_XTHEADSYNC,
455455
INSN_CLASS_XVENTANACONDOPS,
456+
457+
NUM_INSN_CLASSES,
456458
};
457459

458460
/* This structure holds information for a particular instruction. */

opcodes/riscv-dis.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ static bool no_aliases = false;
110110

111111
/* If set, disassemble with numeric register names. */
112112
static bool is_numeric = false;
113+
114+
/* Instruction support cache. */
115+
static signed char riscv_insn_support_cache[NUM_INSN_CLASSES];
113116

114117

115118
/* Set current disassembler context (dis_arch_context_current).
@@ -214,6 +217,9 @@ static void
214217
init_riscv_dis_state_for_arch (void)
215218
{
216219
is_arch_changed = true;
220+
/* Clear instruction support cache. */
221+
for (size_t i = 0; i < NUM_INSN_CLASSES; i++)
222+
riscv_insn_support_cache[i] = 0;
217223
}
218224

219225
/* Initialization (for arch and options). */
@@ -1023,7 +1029,14 @@ riscv_disassemble_insn (bfd_vma memaddr,
10231029
if ((op->xlen_requirement != 0) && (op->xlen_requirement != xlen))
10241030
continue;
10251031
/* Is this instruction supported by the current architecture? */
1026-
if (!riscv_multi_subset_supports (&riscv_rps_dis, op->insn_class))
1032+
if (riscv_insn_support_cache[op->insn_class] == 0)
1033+
{
1034+
riscv_insn_support_cache[op->insn_class]
1035+
= riscv_multi_subset_supports (&riscv_rps_dis, op->insn_class)
1036+
? +1
1037+
: -1;
1038+
}
1039+
if (riscv_insn_support_cache[op->insn_class] < 0)
10271040
continue;
10281041

10291042
matched_op = op;

0 commit comments

Comments
 (0)