Skip to content
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

refactor(csrrw): rewrite csr read/write using switch-case instead of multiple if-else. #573

Merged
merged 2 commits into from
Nov 15, 2024

Conversation

NewPaulWalker
Copy link
Contributor

The previous csr_read and csr_write functions contained a lot of if-else-if structures, making maintenance difficult.
I have rewritten these two functions using switch-case statements, including:

  • For specific CSR, all related operations are placed under the corresponding case, while the typical CSRs are handled using the default case.
  • For a series of consecutive CSRs, like pmpaddr, using switch-case was less convenient, so I kept the original if checks.
  • Additionally, I removed some always-true code, dead code and the read-write code for some typical CSRs that were occupying a separate case.

@NewPaulWalker NewPaulWalker added the do not merge please do not merge it until something label Oct 11, 2024
NewPaulWalker added a commit to NewPaulWalker/ready-to-run that referenced this pull request Oct 11, 2024
* NEMU commit: OpenXiangShan/NEMU#573
* NEMU configs:
  * riscv64-xs-ref_defconfig
  * riscv64-dual-xs-ref_defconfig

Including:
  * refactor(csrrw): rewrite csr read/write using switch-case instead of multiple if-else.
NewPaulWalker added a commit to NewPaulWalker/XiangShan that referenced this pull request Oct 11, 2024
* NEMU commit: OpenXiangShan/NEMU#573
* NEMU configs:
  * riscv64-xs-ref_defconfig
  * riscv64-dual-xs-ref_defconfig

Including:
  * refactor(csrrw): rewrite csr read/write using switch-case instead of multiple if-else.
@NewPaulWalker
Copy link
Contributor Author

Using case range to handle a contiguous address range of CSR instead of if.

@huxuan0307 huxuan0307 merged commit b9507fb into OpenXiangShan:master Nov 15, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants