-
Notifications
You must be signed in to change notification settings - Fork 299
RISC-V: Use symbolic instructions on inline assembly (part 1) #1927
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
Conversation
r? @folkertdev rustbot has assigned @folkertdev. Use |
The changes look fine (you could consider a macro, but it's not that important). In many other cases a |
It works because |
What I'm asking is why not guarding these intrinsics with a target feature is OK. In most other cases, intrinsics are annotated with some target feature, and then the caller must somehow guarantee that the target feature is actually available in practice. If the caller lies and the target feature is not actually available, you might run into an invalid instruction (SIGILL or similar). So, why is there no target feature required here? is the |
Ah, I completely misunderstood your question. For the For others... honestly, I don't know (I just made minimum changes to improve readability). |
It looks like llvm does support these features https://godbolt.org/z/hbdvbPY65, so we can just add them to rust, and then explicitly pushing/popping the environment in the assembly should not be needed. That does mean that the target feature must go through the standard process for stabilization, yes.
My knowledge of RISC-V is insufficient to understand the implications here. From my perspective, if an instruction requires a target feature, it should be marked as such, otherwise we're introducing holes in safe rust. |
I agree that. To note, I once strongly objected to adding supervisor/hypervisor extensions like Unfortunately, I'm not interested in such use cases for now and I won't make a PR to add I'm going to minimize this PR to contain |
Again I can't really judge the situation, but so long as the "h" extension is rooted in some sort of specification (and it seems to be), then adding a rust target feature that just defers to the LLVM target feature of the same name is fine. We should not stabilize these intrinsics until the target feature situation is resolved, because adding a target feature later is a breaking change. So, I think the target features should be added. I'd be happy to do that though if you don't feel like it. |
Okay, that's reasonable. Still, I'd like to split this PR to EDIT: Considering your comment, I will need to add a comment why |
While many intrinsics use `.insn` to generate raw machine code from numbers, all ratified instructions can be symbolic using `.option` directives. By saving the assembler environment with `.option push` then modifying the architecture with `.option arch`, we can temporarily enable certain extensions (as we use `.option pop` immediately after the target instruction, surrounding environment is completely intact in this commit; *almost* completely intact in general). This commit modifies the `pause` *hint* intrinsic to use symbolic *instruction* because we want to expose it even if the Zihintpause extension is unavailable on the target.
fbeac86
to
4ce1446
Compare
Split the original PR into two (now this is the part 1; // Use `.option` directives to expose this HINT instruction
// (no-op if not supported by the hardware) without `#[target_feature]`. |
While many intrinsics use
.insn
to generate raw machine code from numbers, all ratified instructions can be symbolic using.option
directives.By saving the assembler environment with
.option push
then modifying the architecture with.option arch
, we can temporarily enable certain extensions (as we use.option pop
immediately after the target instruction, surrounding environment is completely intact in this commit; almost completely intact in general).This PR (part 1) modifies the
pause
hint intrinsic to use symbolic instruction because we want to expose it even if the Zihintpause extension is unavailable on the target.This is the technique as the author used in rust-lang/rust#146798.