RISC-V: add note about target features vs. misa extensions - #2354
Open
TechnoPorg wants to merge 1 commit into
Open
RISC-V: add note about target features vs. misa extensions#2354TechnoPorg wants to merge 1 commit into
TechnoPorg wants to merge 1 commit into
Conversation
RalfJung
reviewed
Sep 12, 2026
Comment on lines
+566
to
+571
| > [!NOTE] | ||
| > Some RISC-V standard extensions can be enabled (1) or disabled (0) via their corresponding bits in the [Machine ISA][rv-machine] (`misa`) register. | ||
| > For example, the [A][rv-a] and [M][rv-m] bits being cleared means atomic instructions and integer multiplication/division instructions are unimplemented. | ||
| > | ||
| > Rust code compiled with a RISC-V target feature of the same name as an extension assumes the extension will always be available. | ||
| > It is undefined behaviour to execute it in an environment where the extension is disabled (bit is 0 in `misa`). |
Member
There was a problem hiding this comment.
I think a note (which is not normative) is not enough here. We need to say, normatively, that code compiled with a "single-letter target feature" (or whatever they are called) is UB to invoke unless the corresponding bit is actually set in the misa register.
Author
There was a problem hiding this comment.
Would that go in the same part of the document, just not as a note?
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.
As per the discussion in rust-lang/rust#162552 and #t-compiler/risc-v > RISC-V extensions vs. Rust target features, this clarifies that enabling a target feature means the
misabit of the same name (if any) is assumed to always be set. Although this originally came up in the context of theMextension, it applies to many others as well, which are listed in the linked Machine ISA manual page.cc @RalfJung