Skip to content

Commit

Permalink
RISC-V: Cache instruction class support
Browse files Browse the repository at this point in the history
It caches instruction class support values to suppress many per-
instruction calls to the riscv_multi_subset_supports function.

include/ChangeLog:

	* opcode/riscv.h (enum riscv_insn_class): Add NUM_INSN_CLASSES.

opcodes/ChangeLog:

	* riscv-dis.c (init_riscv_dis_state_for_arch): Clear insn class
	cache. (riscv_disassemble_insn): Cache support results.
  • Loading branch information
a4lg committed Jul 13, 2022
1 parent 3d14647 commit b821418
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/opcode/riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ enum riscv_insn_class
INSN_CLASS_ZICBOP,
INSN_CLASS_ZICBOZ,
INSN_CLASS_H,

NUM_INSN_CLASSES,
};

/* This structure holds information for a particular instruction. */
Expand Down
14 changes: 13 additions & 1 deletion opcodes/riscv-dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ static enum riscv_seg_mstate last_map_state;
static const char * const *riscv_gpr_names;
static const char * const *riscv_fpr_names;

/* Instruction class support cache. */
static signed char riscv_insn_class_support_cache[NUM_INSN_CLASSES];

/* If set, disassemble as most general instruction. */
static bool no_aliases = false;

Expand All @@ -79,6 +82,8 @@ static bool is_init_csr = false;
static void
init_riscv_dis_state_for_arch (void)
{
for (size_t i = 0; i < NUM_INSN_CLASSES; i++)
riscv_insn_class_support_cache[i] = 0;
}

static void
Expand Down Expand Up @@ -759,7 +764,14 @@ riscv_disassemble_insn (bfd_vma memaddr, insn_t word, disassemble_info *info)
if ((op->xlen_requirement != 0) && (op->xlen_requirement != xlen))
continue;
/* Is this instruction supported by the current architecture? */
if (!riscv_multi_subset_supports (&riscv_rps_dis, op->insn_class))
if (riscv_insn_class_support_cache[op->insn_class] == 0)
{
riscv_insn_class_support_cache[op->insn_class]
= riscv_multi_subset_supports (&riscv_rps_dis, op->insn_class)
? +1
: -1;
}
if (riscv_insn_class_support_cache[op->insn_class] < 0)
continue;

matched_op = op;
Expand Down

0 comments on commit b821418

Please sign in to comment.