[v2,05/11] RISC-V: One time CSR hash table initialization

Message ID 72c8e56861fccff6720a9b6ccefcecfd80e1adba.1669610611.git.research_trasio@irq.a4lg.com
State Accepted
Headers
Series RISC-V: Requirements for disassembler optimizations batch 1 |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

Tsukasa OI Nov. 28, 2022, 4:43 a.m. UTC
  From: Tsukasa OI <research_trasio@irq.a4lg.com>

The current disassembler intends to initialize the CSR hash table when CSR
name parsing is required at the first time. This is managed by a function-
scope static variable init_csr but... there's a problem.

It's never set to true.

Because of this issue, current disassembler actually initializes the CSR
hash table every time when CSR name parsing is required.  This commit sets
init_csr to true once the CSR hash table is initialized.

It is expected to have about 30% performance improvements alone when
thousands of only CSR instructions are disassembled (CSR instructions are
rare in general so real world performance improvement is not that high).

This commit alone will not affect real world performance that much but
after the efficient opcode hash is implemented, it will be much effective
(sometimes >x10 effect than this commit alone) so that even some regular
programs can benefit from it.

opcodes/ChangeLog:

	* riscv-dis.c (print_insn_args): Make sure that CSR hash table
	initialization occurs only once.
---
 opcodes/riscv-dis.c | 1 +
 1 file changed, 1 insertion(+)
  

Patch

diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index 38eb91349d9a..51a08d847b10 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -564,6 +564,7 @@  print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info
 		DECLARE_CSR (name, num, class, define_version, abort_version)
 #include "opcode/riscv-opc.h"
 #undef DECLARE_CSR
+		init_csr = true;
 	      }
 
 	    if (riscv_csr_hash[csr] != NULL)