Skip to content

Conversation

@tgross35
Copy link
Contributor

@tgross35 tgross35 commented Oct 23, 2025

Newly stable API:

impl {f32, f64} {
    pub const fn mul_add(self, a: Self, b: Self) -> Self;
}

This includes making the intrinsics fmaf{16,32,64,128} const stable for indirect use, matching similar intrinsics.

Closes: #146724

Newly stable API:

    impl {f32, f64} {
        pub const fn mul_add(self, a: Self, b: Self) -> Self;
    }

This includes making the intrinsics `fmaf{16,32,64,128}` const stable
for indirect use, matching similar intrinsics.

Closes: rust-lang#146724
@rustbot
Copy link
Collaborator

rustbot commented Oct 23, 2025

⚠️ #[rustc_intrinsic_const_stable_indirect] controls whether intrinsics can be exposed to stable const
code; adding it needs t-lang approval.

cc @rust-lang/wg-const-eval

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

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

rustbot commented Oct 23, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@tgross35 tgross35 added T-lang Relevant to the language team T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 23, 2025
@tgross35 tgross35 mentioned this pull request Oct 23, 2025
3 tasks
@traviscross traviscross added I-lang-nominated Nominated for discussion during a lang team meeting. I-lang-easy-decision Issue: The decision needed by the team is conjectured to be easy; this does not imply nomination 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 and removed T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Oct 23, 2025
@traviscross
Copy link
Contributor

Over on #146724, @RalfJung said:

Under the hood this is an intrinsic which needs to be const-stabilized to complete this... However the intrinsic just computes a pure function on scalar values so there's nothing really interesting happening on the language level.

@scottmcm noted that there are

no new NAN questions or new table-maker dilemna issues with mul_add that don't already exist for *+, as far as I could come up with.

@tgross35 noted that:

From a quick check I tried, I'm getting some iffy results e.g. fma(0.0000015, 15.36, 0.01563) for f16. I need to verify my methodology though.

However, we can probably start the lang-side proposed FCP while this matter is investigated.

@rfcbot fcp merge

@rust-rfcbot
Copy link
Collaborator

rust-rfcbot commented Oct 23, 2025

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

Concerns:

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. labels Oct 23, 2025
@tmandry
Copy link
Member

tmandry commented Oct 29, 2025

@rfcbot reviewed

@rust-rfcbot rust-rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Oct 29, 2025
@rust-rfcbot
Copy link
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

@nikomatsakis
Copy link
Contributor

@rfcbot reviewed

@traviscross traviscross removed I-lang-nominated Nominated for discussion during a lang team meeting. I-lang-easy-decision Issue: The decision needed by the team is conjectured to be easy; this does not imply nomination P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang labels Oct 29, 2025
@Mark-Simulacrum
Copy link
Member

From a quick check I tried, I'm getting some iffy results e.g. fma(0.0000015, 15.36, 0.01563) for f16. I need to verify my methodology though.

My assumption is that this is not a blocker for merging, because f16 remains unstable. If so, r=me.

@RalfJung
Copy link
Member

RalfJung commented Nov 2, 2025

As I explained in the tracking issue:

The const implementation of this intrinsic is one uniform function that handles all sizes. So if f16 is wrong, chances are the other types have the same bug -- f16 is just much easier to exhaustively test.

@RalfJung
Copy link
Member

RalfJung commented Nov 2, 2025

As a lang team advisor, could I please get this registered as a concern, so we avoid completing FCP until this is figured out?

AFAIK the bot still won't let me register concerns myself, but I guess I can try...
@rfcbot concern iffy-results

@tgross35
Copy link
Contributor Author

Thanks for checking this, I never got the chance to circle back here. If that was an f16-specific problem then, I don't think there is anything to block on: @scottmcm (or somebody else) would you mind resolving the concern?

@traviscross traviscross added I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang labels Nov 30, 2025
@scottmcm
Copy link
Member

It has to be me, so
@rfcbot resolve iffy-results

@RalfJung, if it wasn't actually answered to your satisfaction please let me know and I'll re-register a concern.

@rust-rfcbot rust-rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Nov 30, 2025
@rust-rfcbot
Copy link
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

@RalfJung
Copy link
Member

RalfJung commented Nov 30, 2025

@tgross35

If that was an f16-specific problem then, I don't think there is anything to block on

How do you conclude it was f16-specific? I don't even know what the bug was, all we have is your vague "fma(0.0000015, 15.36, 0.01563) is iffy for f16". What does "iffy" mean? What results do you get, what would you have expected instead? Should we open an issue to track this?

OTOH, worst-case we have a const-time mul_add that gives slightly wrong results, and we just fix that. 🤷

@quaternic
Copy link
Contributor

quaternic commented Nov 30, 2025

@RalfJung
What very likely must have happened before is that @tgross35 saw that as a test case where f16::mul_add differs between const-eval and runtime. But it turned out that it is the runtime evaluation that is incorrect (due to an LLVM bug, which is specific to f16, see the link in my previous message).

@tgross35
Copy link
Contributor Author

I don't even know what the bug was, all we have is your vague "fma(0.0000015, 15.36, 0.01563) is iffy for f16". What does "iffy" mean? What results do you get, what would you have expected instead? Should we open an issue to track this?

I was intentionally vague because this was a test of rustc_apfloat vs. f16::mul_add that I wrote way too quick. Just noted that was a specific value to check, if I or somebody showed a correct result against MPFR then I'd happily attribute the mismatch to a bug in the test I wrote. But @quaternic went beyond that and pointed to the well-known f16-specific bug.

How do you conclude it was f16-specific?

I'm deferring to @quaternic's analysis here but if (1) the values I mentioned match a known f16-specific bug and (2) apfloat actually has the correct answer, I have no reason to believe there is a bug in rustc_apfloat.

@RalfJung
Copy link
Member

Ah, I didn't properly understand your earlier message before, @quaternic. Now it all makes sense :)

@traviscross traviscross removed I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang labels Dec 1, 2025
@rust-rfcbot rust-rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Dec 10, 2025
@rust-rfcbot
Copy link
Collaborator

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

@RalfJung
Copy link
Member

LGTM, thanks!

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Dec 10, 2025

📌 Commit 033711c has been approved by RalfJung

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 10, 2025
bors added a commit that referenced this pull request Dec 10, 2025
Rollup of 7 pull requests

Successful merges:

 - #148052 (Stabilize `const_mul_add`)
 - #149386 (Display funding link in the github overview)
 - #149489 (Experimentally add *heterogeneous* `try` blocks)
 - #149764 (Make `--print=backend-has-zstd` work by default on any backend)
 - #149838 (Build auxiliary in pretty tests)
 - #149839 (Use `PointeeSized` bound for `TrivialClone` impls)
 - #149846 (Statically require links to an issue or the edition guide for all FCWs)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Dec 10, 2025
Rollup of 7 pull requests

Successful merges:

 - #148052 (Stabilize `const_mul_add`)
 - #149386 (Display funding link in the github overview)
 - #149489 (Experimentally add *heterogeneous* `try` blocks)
 - #149764 (Make `--print=backend-has-zstd` work by default on any backend)
 - #149838 (Build auxiliary in pretty tests)
 - #149839 (Use `PointeeSized` bound for `TrivialClone` impls)
 - #149846 (Statically require links to an issue or the edition guide for all FCWs)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 26ae475 into rust-lang:main Dec 10, 2025
11 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Dec 10, 2025
rust-timer added a commit that referenced this pull request Dec 10, 2025
Rollup merge of #148052 - tgross35:stabilize-const_mul_add, r=RalfJung

Stabilize `const_mul_add`

Newly stable API:

```rust
impl {f32, f64} {
    pub const fn mul_add(self, a: Self, b: Self) -> Self;
}
```

This includes making the intrinsics `fmaf{16,32,64,128}` const stable for indirect use, matching similar intrinsics.

Closes: #146724
@tgross35 tgross35 deleted the stabilize-const_mul_add branch December 11, 2025 16:42
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. finished-final-comment-period The final comment period is finished for this PR / Issue. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team to-announce Announce this issue on triage meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracking Issue for const_mul_add