Skip to content

RISC-V: stabilize Zmmul target feature - #164992

Open
TechnoPorg wants to merge 1 commit into
rust-lang:mainfrom
TechnoPorg:push-xrxnqpmsvmou
Open

TechnoPorg wants to merge 1 commit into
rust-lang:mainfrom
TechnoPorg:push-xrxnqpmsvmou

Conversation

@TechnoPorg

Copy link
Copy Markdown
Contributor

Stabilization report

Summary

Zmmul is the integer multiplication subset of the RISC-V M extension. It enables LLVM to lower multiplications to the "MUL, MULH, MULHU, MULHSU, and (for RV64 only) MULW"1 instructions, while keeping divisions implemented in software.

This is useful for constrained embedded applications where multiplication operations are important enough for performance to warrant a hardware implementation, but division is rarely ever performed and so the extra cost of a hardware divider cannot be justified.

Using the m target feature could result in undefined behaviour by lowering to unimplemented division instructions, but excluding it leads to noticeably worse performance because hardware multiplication can't be used. Zmmul fixes this problem by enabling only multiplication.

Tracking issue:

  • None

Reference PRs:

What is stabilized

-Ctarget-feature=+zmmul can now be passed without a warning. #[cfg(target_feature = "zmmul")] and #[target_feature(enable = "zmmul")] are accepted.

Feedback

Nightly use

This has been in use at $INTERNSHIP for our riscv32i-unknown-none-elf embedded project for a few months now and works as expected: LLVM lowers to multiplication instructions but not division instructions.

Coverage

There is currently no test coverage in rust-lang/rust. Given that this is just forwarded to LLVM, I think it's fair to put the test burden on LLVM and not rustc.

Tool changes

  • rust-analyzer
    • Thanks to the recent addition of a target feature auto-sync, we don't need to worry about this

Type system, opsem

Sound by default?

Code with this target feature enabled is sound unless it is executed in an environment where integer multiplication instructions are not available. See some of the discussion in #162552 about whether M implies Zmmul and the guidelines around the misa register for more details on this.

It is the responsibility of the user to guarantee that the instructions are implemented.

History

r? beetrees
cc @RalfJung, @kraj, @sweiglbosker as participants on the previous thread
@rustbot label O-riscv

Footnotes

  1. Spec: https://github.com/riscv/riscv-isa-manual/blob/20250508/src/m-st-ext.adoc#zmmul-extension-version-10 ↩

@rustbot

rustbot commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Target features are being changed; ensure all ABI effects are being accounted for

cc @RalfJung

Some changes occurred in std_detect

cc @Amanieu, @folkertdev, @sayantn

@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 Oct 26, 2026
@rustbot

rustbot commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

beetrees is currently at their maximum review capacity.
They may take a while to respond.

@RalfJung

Copy link
Copy Markdown
Member

Would M impying Zmmul make sense?

It already does imply Zmmul.
(Please don't just delete comments, it's very confusing as email notifications have already been sent.)

@RalfJung RalfJung added the I-lang-nominated Nominated for discussion during a lang team meeting. label Oct 27, 2026
@RalfJung

Copy link
Copy Markdown
Member

Seems like a no-brainer. Nominating for t-lang.
(We have been discussing in rust-lang/rust-forge#1122 what the stabilization process for target features should be, so far without clear conclusions.)

Cc @Amanieu
@rustbot ping risc-v

@rustbot

rustbot commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Hey RISC-V Group! This issue has been identified as a good "RISC-V candidate".
In case it's useful, here are some instructions for tackling these sorts of
issues. Maybe take a look?
Thanks! <3

cc @denisvasilik @kraj @sweiglbosker @TechnoPorg

@RalfJung

RalfJung commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

@davidtwco / @BoxyUwU do you want t-compiler to be included in this FCP? We have been inconsistent about this in the past; sometimes t-compiler was included but often it was not.

@traviscross traviscross added T-lang Relevant to the language team needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang labels Oct 28, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

I-lang-nominated Nominated for discussion during a lang team meeting. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. O-riscv Target: RISC-V architecture P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang 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. T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants