-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disassembler: Core Optimization 1-1 (Hash table and Caching) #88
Open
a4lg
wants to merge
3
commits into
riscv-dis-opt1-req-reorganize
Choose a base branch
from
riscv-dis-opt1-1-hashtable-and-caching
base: riscv-dis-opt1-req-reorganize
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Disassembler: Core Optimization 1-1 (Hash table and Caching) #88
a4lg
wants to merge
3
commits into
riscv-dis-opt1-req-reorganize
from
riscv-dis-opt1-1-hashtable-and-caching
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
November 18, 2022 00:12
6c23d80
to
992c0f5
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
2 times, most recently
from
November 18, 2022 04:58
444fbaa
to
b83e54a
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
November 19, 2022 02:38
76a3a4e
to
d312be0
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
2 times, most recently
from
November 19, 2022 07:15
9fdf0f8
to
f99c8ca
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
November 19, 2022 11:57
68d5006
to
452c070
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
from
November 19, 2022 11:57
f99c8ca
to
297008a
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
November 20, 2022 01:02
452c070
to
f3fcf98
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
2 times, most recently
from
November 21, 2022 02:21
844db36
to
f3378df
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
November 22, 2022 01:32
8712c11
to
d4b20c6
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
from
November 22, 2022 01:32
f3378df
to
a452e06
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
November 22, 2022 09:00
d4b20c6
to
9b08b66
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
2 times, most recently
from
November 23, 2022 03:04
515d02e
to
29236db
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
November 23, 2022 08:44
1e28527
to
5d5bbd6
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
from
November 23, 2022 08:44
29236db
to
3ddff53
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
November 24, 2022 03:38
5d5bbd6
to
d98213b
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
5 times, most recently
from
November 25, 2022 02:39
8c9fc20
to
340fee3
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
November 25, 2022 12:46
0cd8ace
to
fe45631
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
from
November 25, 2022 12:46
340fee3
to
8478c28
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
November 26, 2022 00:28
fe45631
to
7c9633c
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
2 times, most recently
from
November 27, 2022 09:10
0e92186
to
e679d61
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
3 times, most recently
from
August 7, 2023 01:23
f8d4788
to
d08c88a
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
August 7, 2023 02:55
1ad9136
to
899020c
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
from
August 7, 2023 02:56
d08c88a
to
3c7f4fd
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
August 8, 2023 03:19
899020c
to
cbd4e63
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
from
August 8, 2023 03:19
3c7f4fd
to
3795893
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
August 8, 2023 04:11
cbd4e63
to
44387b5
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
from
August 8, 2023 04:11
3795893
to
36bfa28
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
August 11, 2023 01:53
44387b5
to
ce839d4
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
2 times, most recently
from
August 11, 2023 03:56
6921cd1
to
ebdb18b
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
August 15, 2023 06:37
58f4e93
to
612847a
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
from
August 15, 2023 06:37
ebdb18b
to
28513f5
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
August 15, 2023 07:27
612847a
to
7d54ac5
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
from
August 15, 2023 07:27
28513f5
to
491c911
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
from
September 3, 2023 02:26
491c911
to
f1b6d8a
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
September 3, 2023 02:41
43c246b
to
da19323
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
from
September 3, 2023 02:42
f1b6d8a
to
b83efe1
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
September 5, 2023 07:58
da19323
to
fe6fd92
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
from
September 5, 2023 07:58
b83efe1
to
03c8645
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
September 7, 2023 09:35
fe6fd92
to
a170be4
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
from
September 7, 2023 09:35
03c8645
to
37af5cd
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
from
October 16, 2023 09:05
37af5cd
to
84734db
Compare
a4lg
force-pushed
the
riscv-dis-opt1-req-reorganize
branch
from
October 19, 2023 03:17
58372fa
to
537ca14
Compare
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
from
October 19, 2023 03:17
84734db
to
30b8505
Compare
This commit improves performance on disassembling RISC-V code. It replaces riscv_hash (in opcodes/riscv-dis.c) with much faster data structure: a sorted and partitioned hash table. This is a technique actually used on SPARC architecture (opcodes/sparc-dis.c) and the author simplified the algorithm even further. Unlike SPARC, RISC-V's hashed opcode table is not a table to linked lists, it's just a table, pointing "start" elements in the sorted opcode list (per hash code) and a global tail. It is expected to have 20-40% performance improvements when disassembling linked RISC-V ELF programs using objdump. That is a significant improvement and pretty nice for such a small modification (with about 12KB 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"). The author tested on various binary files including random one and big vmlinux images and confirmed significant performance improvements (>70% on many cases). This is partially 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). Another reason for this significance is it doesn't have various ELF overhead. opcodes/ChangeLog: * riscv-dis.c (init_riscv_dis_state_for_arch_and_options): Build the hash table on the first run. (OP_HASH_LEN): Move from riscv_disassemble_insn. (OP_HASH_IDX): Move from riscv_disassemble_insn and mask by OP_MASK_OP2 == 0x03 for only real 16-bit instructions. (riscv_hash): New sorted and partitioned hash table. (riscv_opcodes_sorted): New sorted opcode table. (compare_opcodes): New function to compare RISC-V opcode entries. (build_riscv_opcodes_hash_table): New function to build faster hash table to disassemble. (riscv_disassemble_insn): Use sorted and partitioned hash table.
Although it does not have a problem on current GNU Binutils implementation, if the custom vendor implements an instruction which spans across multiple major opcodes (e.g. uses both CUSTOM_0 and CUSTOM_1 in a *single* custom instruction), the original assumption of the sorted hash table breaks. In this case, this commit enables the fallback mode to disable all optimizations except filtering macros out. Note that, if a such instruction (that disables this disassembler optimization) is upstreamed to Binutils, a separate solution will be required to avoid major performance degradation when such instruction is not used. The intent of this commit is to make a room for custom vendors to implement such instructions in *their* tree without causing disassembler problems. opcodes/ChangeLog: * riscv-dis.c (is_riscv_hash_fallback) New. (build_riscv_opcodes_hash_table): If an instruction spans across multiple major opcodes, enable fallback mode and disable sorting. (riscv_disassemble_insn): If the fallback mode is enabled, scan through all instructions instead of scanning only instruction entries matching the hash value.
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.
a4lg
force-pushed
the
riscv-dis-opt1-1-hashtable-and-caching
branch
from
October 19, 2023 07:01
30b8505
to
496ea7d
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Wiki Page (details): https://github.com/a4lg/binutils-gdb/wiki/riscv_dis_opt1_1_hashtable_and_caching