Refactor/riscv32 decoder #133
Open
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.
refactor(isa/riscv32): 使用 X-Macro 重构指令译码器,提升代码清晰度
本次提交对 RISC-V 的指令译码器进行了一次深度的架构重构,旨在解决旧有实现的可维护性、扩展性以及代码清晰度问题。
旧代码在
INSTPAT宏中统一使用了src1,src2这样含义模糊的通用变量名。这使得指令的执行逻辑可读性很差,无法一眼看出变量究竟是源寄存器的值,还是用于访存的基地址。除此以外,zimm与shamt等操作数的译码逻辑也和标准的I类型指令不同,需要专门实现。而新的架构让添加这些不同的译码逻辑变得前所未有的方便。为了解决这些问题,新的设计引入了 X-Macro 技术,将译码器改造为一个模块化、声明式的分发系统:
code_type_listX-Macro 在一个统一的位置集中定义所有指令格式,并为操作数赋予了更具描述性的名称,如vrs1(value of rs1),vrs2,shamt等。struct,其成员名即为这些描述性名称。Dvrs1,DimmI)。值得注意的是,本次重构利用了在 #131 号 PR 中引入的
BIT_CAST宏,在不同译码结构体之间进行安全的类型转换。因此,本 PR 应在 #131 号 PR 之后合入。总而言之,这次重构不仅提升了译码器的可扩展性和可维护性,更重要的是,通过用
vrs1等清晰的命名代替src1,使得指令的执行逻辑变得更加自明 (self-documenting),极大地提升了代码的可读性,为后续的开发和维护打下了坚实的基础。