Skip to content

rustc_target: RISC-V: feature addition batch 2 #139440

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

Merged
merged 2 commits into from
Apr 17, 2025

Conversation

a4lg
Copy link
Contributor

@a4lg a4lg commented Apr 6, 2025

Of ratified RISC-V extensions, this commit adds ones satisfying following criteria:

  1. Either discoverable through a riscv_hwprobe system call on Linux 6.14
    or should be very helpful even on basic needs (the B extension),
  2. Does not disrupt current Rust's feature handling mechanism and
  3. Not too OS-dependent (the Supm extension)

Due to 2., the author excluded Zcf (RV32 only) and Zcd from the list despite that they are discoverable from Linux 6.14.

Due to 3., the author excluded the Supm extension on the PR version 2.

This is based on the specification:

Linux Definition: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/riscv/include/uapi/asm/hwprobe.h

LLVM Definitions:

The author also adds required implication: C implies Zca.

Android RISC-V target is also updated to include the B extension (this is just a shorthand combination of Zba, Zbb and Zbs extensions but possibly simplifies target_feature handling).

History

Version 1 → 2

  • Remove the Supm extension from the Rust target features (thanks, @Amanieu).

Related:

@rustbot r? @Amanieu
@rustbot label +T-compiler +O-riscv +A-target-feature

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 6, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 6, 2025

These commits modify compiler targets.
(See the Target Tier Policy.)

@rustbot rustbot added A-target-feature Area: Enabling/disabling target features like AVX, Neon, etc. O-riscv Target: RISC-V architecture labels Apr 6, 2025
@a4lg a4lg force-pushed the riscv-feature-addition-batch-2 branch from 6e10c31 to d2a3049 Compare April 12, 2025 01:04
@a4lg a4lg requested a review from Amanieu April 12, 2025 08:20
a4lg added 2 commits April 16, 2025 01:20
This commit adds unprivileged ratified extensions that are either
dicoverable from the `riscv_hwprobe` syscall of the Linux kernel (as of
version 6.14) plus 1 minus 3 extensions.

Plus 1:

*   "B"
    This is a combination of "Zba", "Zbb" and "Zbs".
    Note:
    Although not required by the RISC-V specification, it is convenient to
    imply "B" from its three members (will be implemented in LLVM 21/22) but
    this is not yet implemented in Rust due to current implication handling.
    It still implies three members *from* "B".

Minus 2:

*   "Zcf" (target_arch = "riscv32" only)
    This is the compression instruction subset corresponding "F".
    This is implied from RV32 + "C" + "F" but this complex handling is
    not yet supported by Rust's feature handling.
*   "Zcd"
    This is the compression instruction subset corresponding "D".
    This is implied from "C" + "D" but this complex handling is
    not yet supported by Rust's feature handling.
*   "Supm"
    Unlike regular RISC-V extensions, "Supm" and "Sspm" extensions do not
    provide any specific architectural features / constraints but requires
    *some* mechanisms to control pointer masking for the current mode.
    For instance, reported existence of the "Supm" extension in Linux means
    that `prctl` system call to control pointer masking is available and
    there are alternative ways to detect the existence.

Notes:

*   Because this commit adds the "Zca" extension (an integer subset of the
    "C" extension), the "C" extension is modified to imply "Zca".
The "B" extension is ratified as a combination of three extensions: "Zba",
"Zbb" and "Zbs".  To maximize discoverability of the RISC-V target features,
this commit makes use of the "B" extension instead of its three members.

This way, `#[cfg(target_feature = "b")]` can also be used instead of:
`#[cfg(all(target_feature = "zba", target_feature = "zbb", target_feature = "zbs"))]`
@Amanieu
Copy link
Member

Amanieu commented Apr 16, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 16, 2025

📌 Commit 52392ec has been approved by Amanieu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 16, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 17, 2025
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#135340 (Add `explicit_extern_abis` Feature and Enforce Explicit ABIs)
 - rust-lang#139440 (rustc_target: RISC-V: feature addition batch 2)
 - rust-lang#139667 (cfi: Remove #[no_sanitize(cfi)] for extern weak functions)
 - rust-lang#139828 (Don't require rigid alias's trait to hold)
 - rust-lang#139854 (Improve parse errors for stray lifetimes in type position)
 - rust-lang#139889 (Clean UI tests 3 of n)
 - rust-lang#139894 (Fix `opt-dist` CLI flag and make it work without LLD)
 - rust-lang#139900 (stepping into impls for normalization is unproductive)
 - rust-lang#139915 (replace some #[rustc_intrinsic] usage with use of the libcore declarations)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ff55f2a into rust-lang:master Apr 17, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 17, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 17, 2025
Rollup merge of rust-lang#139440 - a4lg:riscv-feature-addition-batch-2, r=Amanieu

rustc_target: RISC-V: feature addition batch 2

Of ratified RISC-V extensions, this commit adds ones satisfying following criteria:

1.  Either discoverable through a `riscv_hwprobe` system call on Linux 6.14
    or should be very helpful even on basic needs (the `B` extension),
2.  Does not disrupt current Rust's feature handling mechanism and
3.  Not too OS-dependent (the `Supm` extension)

Due to 2., the author excluded `Zcf` (RV32 only) and `Zcd` from the list despite that they are discoverable from Linux 6.14.

Due to 3., the author excluded the `Supm` extension on the PR version 2.

This is based on the specification:
*   [The latest ratified ISA Manuals (version 20240411)](https://lf-riscv.atlassian.net/wiki/spaces/HOME/pages/16154769/RISC-V+Technical+Specifications)

Linux Definition: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/riscv/include/uapi/asm/hwprobe.h

LLVM Definitions:

*   [`B`](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L507-L510)
*   [`Zca`](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L395-L398)
*   [`Zcb`](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L407-L410)
*   [`Zcmop`](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L460-L463)
*   [`Zfa`](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L335-L338)
*   [`Zicboz`](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L89-L92)
*   [`Zicond`](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L125-L128)
*   [`Zihintntl`](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L148-L151)
*   [`Zimop`](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L161-L162)
*   [`Ztso`](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L214-L217)

The author also adds required implication: `C` implies `Zca`.

Android RISC-V target is also updated to include the `B` extension (this is just a shorthand combination of `Zba`, `Zbb` and `Zbs` extensions but possibly simplifies `target_feature` handling).

# History

## Version 1 → 2

*   Remove the `Supm` extension from the Rust target features (thanks, `@Amanieu).`

--------

Related:
*   rust-lang#44839
    (`riscv_target_feature`)
*   rust-lang#138823
    (my previous batch)
*   rust-lang#132618
    (stabilization of the `Zfa` extension is blocked by this)

`@rustbot` r? `@Amanieu`
`@rustbot` label +T-compiler +O-riscv +A-target-feature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-target-feature Area: Enabling/disabling target features like AVX, Neon, etc. O-riscv Target: RISC-V architecture S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants