feat: use riscv atomic immediate instructions for interrupt enable/disable#868
Merged
Grazfather merged 2 commits intoZigEmbeddedGroup:mainfrom Jan 22, 2026
Merged
Conversation
mattnite
approved these changes
Jan 19, 2026
tact1m4n3
approved these changes
Jan 19, 2026
caeea33 to
990c234
Compare
Updating with new lint results
Grazfather
reviewed
Jan 22, 2026
990c234 to
d6ec193
Compare
Collaborator
|
Can you rebase/merge in main? #864 might need an update since you added a type to mpp EDIT: Not needed |
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.
The existing Csr.write(), Csr.set() and Csr.clear() functions only allow the "r" register constraint, so always generate as two instructions e.g.
By refining the implementation a bit to detect when the value is comptime known and small enough to fit in the u5 immediate, this change allows the compiler to generate single atomic instructions for small immediates, like when setting the global interrupt enable bits.
The interface is changed slightly, to accept the packed struct T directly for set/clear instead of an anonymous struct. This has some benefits like a known result type, and allows detection of whether the passed in value is comptime known which the get_bits() necessary for .modify() to work obscures.
A before/after of the codegen can be observed in: https://godbolt.org/z/sKeboeoWv
CSRs that are meant to be used with these interfaces should have default field values of 0, so that the set/clear mask can be generated without providing all of the fields.