Skip to content
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

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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) and
  2. Does not disrupt current Rust's feature handling mechanism.

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

This is based on those two 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:

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).

Note that absence of non-experimental Supm extension on LLVM 19 should not affect the codegen because of this extension's position: unlike most of the RISC-V extensions, the Supm extension defines some mechanism to control pointer masking behavior but provides none of additional instructions, CSRs nor some architectural behaviors/constraints (i.e. it tells the existence of an external mechanism such like a system call of an operating system which changes the behavior of the pointer masking using features defined by Ssnpm and/or Smnpm extensions, not Supm).


Related:

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

a4lg added 2 commits April 6, 2025 03:36
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 2 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.

Notes:

*   Because this commit adds the "Zca" extension (an integer subset of the
    "C" extension), the "C" extension is modified to imply "Zca".
*   The "Supm" extension requires LLVM 20 yet it should not affect codegen
    on LLVM 19 because this extension does not specify any mechanism to
    control pointer masking (just tells the availability from the user mode
    and *some* way to control pointer masking like a system call).
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"))]`
@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
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-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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants