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
@traviscross traviscross added P-lang-drag-2 Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang. and removed P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang labels Nov 11, 2026
@TechnoPorg

Copy link
Copy Markdown
Contributor Author

Hello @davidtwco and @BoxyUwU! Gentle ping about this :)

@davidtwco

Copy link
Copy Markdown
Member

I think T-compiler should be on target modifier stabilisations, just as a sanity check for any ABI issues or anything else we might be aware of

@beetrees

Copy link
Copy Markdown
Contributor

@davidtwco this target feature isn't a target modifier (as it's sound to link things with it enabled and disabled together). Should T-compiler be included in the FCP of target features that aren't target modifiers?

@RalfJung

RalfJung commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Yeah I think the general conclusion was that t-lang and t-compiler should both be included to make sure nothing is missed regarding ABI interactions or similar.

EDIT: oh wait that was the message David wrote just above. I didn't realize he wrote "target modifier". Likely a typo?

@beetrees

Copy link
Copy Markdown
Contributor

@rfcbot merge

@beetrees

Copy link
Copy Markdown
Contributor

@rfcbot fcp merge compiler,lang

@rust-rfcbot

rust-rfcbot commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

@beetrees has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. and removed needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. labels Nov 23, 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

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. 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. O-riscv Target: RISC-V architecture P-lang-drag-2 Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. 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.

7 participants