Skip to content

riscv_dis_opts_hashtable

Tsukasa OI edited this page Jul 16, 2022 · 20 revisions

Disassembler: Use faster hash table

Conflicts With

Feature Description

This patchset intends to improve performance on disassembling RISC-V code (which may possibly contain invalid data). It replaces riscv_hash (on opcodes/riscv-dis.c) with much faster data structure: sorted and partitioned hash table.

This is a technique actually used on SPARC architecture (opcodes/sparc-dis.c) and I simplified the algorithm even further. Unlike SPARC, RISC-V hashed opcode table is not a table to linked lists, it's just a table, pointing "start" elements of the sorted opcode list (sorted by hash code) and a global tail.

I benchmarked some of the programs and I measure somewhat between 2-10% performance increase while disassembling code section of RISC-V ELF files (objdump -d $FILE). That is not significant but not bad for such a small modification (with about 11KB heap memory allocation on 64-bit environment).

This is not the end. This structure significantly improves plain binary file handling (on objdump, objdump -b binary -m riscv:rv[32|64] -D $FILE). I tested on a big vmlinux image with debug symbols and I got over 50% performance improvements. This is due to the fact that, disassembling about one quarter of invalid "instruction" words required iterating over one thousand opcode entries (348 or more being vector instructions with OP-V, that can be easily skipped with this new data structure).

Other Fixes

Performance Improvements

On disassembling linked RISC-V ELF files using objdump, performance improvements achieved by this patchset is about 15-20%. Pretty good for such a simple change.

objdump (ELF)

Program Improvements Notes
Busybox 1.35.1 (RV64GC) 17.5-19.8%
OpenSBI 1.1 (generic fw_*.elf) 18.2-19.1%
Linux kernel 5.18 (vmlinux) 15.6-16.7%
Linux kernel 5.18 (vmlinux.o) 0.4-6.7% Not finally linked
glibc (libc.so.6) 15.1-18.9%

objdump (ELF-based archive)

Program Improvements
glibc (libc.a) 1.5-1.9%
newlib (libc.a) 0.7-3.9%

objdump (binary)

Program Improvements
Linux kernel 5.18 (vmlinux) 70.9-92.7%
Random files (/dev/urandom) 96.0-97.9%
1M (1048576) CSR instructions 104.5%

gdb: disas of near all code region

Program Improvements
Linux kernel 5.18 (vmlinux) with debug info 0.9%
Linux kernel 5.18 (vmlinux) without debug info 2.1%
OpenSBI 1.1 (generic fw_*.elf) 2.2-3.4%
Clone this wiki locally