rustc_target: RISC-V: Add two supervisor extensions for intrinsics #147439
+7
−0
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.
This commit adds two ratified privileged RISC-V extensions corresponding to 35 existing intrinsics in
core::arch::riscv{32,64}
.Because they semantically require the H and/or Svinval privileged extensions, we'd better to have those new target features to use them as a part of the
#[target_feature(enable = ...)]
attribute.It also adds a note about a conflict between
e
andh
(no code changes for now but should be rejected in the future).Background
In
stdarch
, there are 35 unique intrinsics corresponding ratified instructions incore::arch::riscv{32,64}
(35 inriscv64
, 32 inriscv32
) that require an ISA extension to work (note: the supervisor/machine architectures are not extensions so privileged intrinsics likewfi
are excluded from the list).In general, we require
#[target_feature(enable = ...)]
attribute to denote what target features are truly required but those 35 intrinsics didn't have that (there is one intentional exception: thepause
HINT that behaves as a pause operation when the Zihintpause extension is implemented but otherwise executed as a no-op).As you can see below, there are two missing extensions: H (hypervisor) and Svinval (efficient address-translation cache invalidation).
Required: Svinval
sinval_vma
sinval_vma_vaddr
sinval_vma_asid
sinval_vma_all
sfence_w_inval
sfence_inval_ir
Required: H
hfence_vvma
hfence_vvma_vaddr
hfence_vvma_asid
hfence_vvma_all
hfence_gvma
hfence_gvma_gaddr
hfence_gvma_vmid
hfence_gvma_all
hlv_b
hlv_h
hlv_w
hlv_d
(riscv64
only)hlv_bu
hlv_hu
hlv_wu
(riscv64
only)hlvx_hu
hlvx_wu
hsv_b
hsv_h
hsv_w
hsv_d
(riscv64
only)Required: H + Svinval
Note that LLVM only requires the Svinval extension but the RISC-V documentation states that corresponding instructions are implemented only when the hypervisor extension (H) is enabled.
hinval_vvma
hinval_vvma_vaddr
hinval_vvma_asid
hinval_vvma_all
hinval_gvma
hinval_gvma_gaddr
hinval_gvma_vmid
hinval_gvma_all
About this PR
There are multiple ways to make all implemented intrinsics more consistent:
#[target_feature(enable = ...)]
to focus on the user mode (note that there are only three architectures with privileged-only intrinsics:riscv{32,64}
andarm
).To be honest, I personally don't like implement a new feature only because we can thing like those intrinsics but removing them seems to be... too extreme.
#[target_feature(enable = ...)]
to intrinsics above.That requires adding two RISC-V target features:
h
andsvinval
(which I didn't want to do that but at least it makes intrinsics more consistent and safer).This is a preparation for the option 2 (on the Rust compiler side) and adds two extensions as two target features:
h
(which implieszicsr
) andsvinval
.There is an additional change: describe why ILP32E and LP64E ABIs are not declared incompatible with the H extension (
h
target feature in this PR) due to this extension's special dependency: a base integer ISA with 32 general purpose registers.That means, target features
e
(a virtual extension denoting a base integer ISA with 16 general purpose registers, not 32) andh
are truly incompatible (and should be rejected later) but for ABIs, there's no reason to declare incompatibility (ase
is not required by those ABIs).Related
stdarch
to be applied once this PR is merged)Cc: @folkertdev
r? @Amanieu
@rustbot label +O-riscv +A-target-feature