Generate decoder from ISA descriptor#725
Open
yc199911 wants to merge 1 commit intosysprog21:masterfrom
Open
Conversation
Introduce gen-decoder.py that reads src/instructions.in and generates src/decode.c, replacing the hand-written decoder with an auto-generated one. - src/instructions.in: ISA descriptor covering 161 instructions (RV32I/M/A/F/C, Zifencei, Zicsr, Zba/Zbb/Zbc/Zbs) - scripts/gen-decoder.py: decision-tree builder and C code generator with full RVC operand decoding (register mapping + immediate bit-extraction) - scripts/verify-tree.py: validates all 161 instructions are reachable in the generated decision tree - Makefile: auto-regenerate decode.c when inputs change - docs/decoder-generator.md: describes the descriptor format and how to add new instructions/extensions Close sysprog21#103
jserv
reviewed
Apr 9, 2026
Contributor
jserv
left a comment
There was a problem hiding this comment.
Benchmarks
Details
| Benchmark suite | Current: 8ef6e5d | Previous: 2138efe | Ratio |
|---|---|---|---|
Dhrystone |
1521.667 DMIPS |
1558.667 DMIPS |
1.02 |
CoreMark |
1103.066 iterations/sec |
1103.567 iterations/sec |
1.00 |
This comment was automatically generated by workflow using github-action-benchmark.
This file contains hidden or 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
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.
Summary
Introduce
scripts/gen-decoder.pyto automatically generatesrc/decode.cfromsrc/instructions.in, replacing the hand-writtendecoder.
Changes
src/instructions.in: ISA descriptor for 161 instructionsscripts/gen-decoder.py: decision-tree builder and C code generatorscripts/verify-tree.py: validates all instructions are reachableMakefile: auto-regenerate decode.c when inputs changedocs/decoder-generator.md: format documentationTest Results
RISCV_DEVICE=IMACFZicsrZifencei: all tests passed
(I, M, A, F, C, Zifencei, privilege extensions verified)
Close #103
Summary by cubic
Replaced the hand-written instruction decoder with an auto-generated one built from an ISA descriptor. This makes adding instructions simple and keeps decoding consistent and verifiable across 161 ops.
New Features
scripts/gen-decoder.pybuilds a decision tree and emitssrc/decode.c(includes full RVC operand decoding and extension guards).scripts/verify-tree.pyvalidates reachability for every instruction (current descriptor: 161/161).src/instructions.indefines the ISA;docs/decoder-generator.mddocuments the format and how to extend it.src/decode.cand runsclang-format.Migration
src/decode.cstays committed for normal builds.src/instructions.inand runmake. For new RVC immediates, add a decoder in_RVC_OPERAND_DECODERSinscripts/gen-decoder.py.Written for commit 8ef6e5d. Summary will update on new commits.