feat: use riscv atomic immediate instructions for interrupt enable/disable #868
+103
−29
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.