Skip to content

Add mul_add_relaxed methods for floating-point types#151793

Open
landsharkiest wants to merge 1 commit into
rust-lang:mainfrom
landsharkiest:float_mul_add_relaxed-#151770
Open

Add mul_add_relaxed methods for floating-point types#151793
landsharkiest wants to merge 1 commit into
rust-lang:mainfrom
landsharkiest:float_mul_add_relaxed-#151770

Conversation

@landsharkiest

@landsharkiest landsharkiest commented Jan 28, 2026

Copy link
Copy Markdown

View all comments

Implements mul_add_relaxed for f16, f32, f64, and f128, which computes (self * a) + b with relaxed precision semantics. Unlike mul_add which guarantees a fused operation, this variant allows the compiler to choose between fused or separate operations based on target performance.

This fills the gap between the precision-guaranteed mul_add and the fully-optimizable algebraic operators, providing target-specific optimization while maintaining reasonable floating-point semantics.

Tracking issue: #151770

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 28, 2026
@rustbot

rustbot commented Jan 28, 2026

Copy link
Copy Markdown
Collaborator

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

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Comment thread tests/ui/intrinsics/float-mul-add-relaxed.rs
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Comment thread library/core/src/num/f32.rs Outdated
@rust-log-analyzer

This comment has been minimized.

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 1, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@RalfJung

RalfJung commented Jul 16, 2026

Copy link
Copy Markdown
Member

@landsharkiest friendly reminder that this PR is waiting for you to react to the reviewer's feedback and to fix CI. :)
if you no longer have time to work on this, that's fine -- just let us know so the task can be picked up by someone else.

@folkertdev

Copy link
Copy Markdown
Contributor

Another thing, please update the doc comment of the intrinsics to point to the public methods, like here

/// The stabilized version of this intrinsic is 
/// [`f128::mul_add`](../../std/primitive.f128.html#method.mul_add) 

/// Returns `a * b + c` for `f128` values.
///
/// The stabilized version of this intrinsic is
/// [`f128::mul_add`](../../std/primitive.f128.html#method.mul_add)
#[rustc_intrinsic_const_stable_indirect]
#[rustc_intrinsic]
#[rustc_nounwind]
pub const fn fmaf128(a: f128, b: f128, c: f128) -> f128;
/// Returns `a * b + c` for `f16` values, non-deterministically executing
/// either a fused multiply-add or two operations with rounding of the
/// intermediate result.
///
/// The operation is fused if the code generator determines that target
/// instruction set has support for a fused operation, and that the fused
/// operation is more efficient than the equivalent, separate pair of mul
/// and add instructions. It is unspecified whether or not a fused operation
/// is selected, and that may depend on optimization level and context, for
/// example.
#[rustc_intrinsic]
#[rustc_nounwind]
pub const fn fmuladdf16(a: f16, b: f16, c: f16) -> f16;

We use the prasing of "stabilized" here even if the methods are not actually stable.

@landsharkiest
landsharkiest force-pushed the float_mul_add_relaxed-#151770 branch from 0ca5122 to 174bea7 Compare July 18, 2026 01:25
@rustbot

rustbot commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

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 commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@landsharkiest

Copy link
Copy Markdown
Author

@landsharkiest friendly reminder that this PR is waiting for you to react to the reviewer's feedback and to fix CI. :) if you no longer have time to work on this, that's fine -- just let us know so the task can be picked up by someone else.

Sorry got caught up in school and job searching, will finally put this away! :)

@rust-log-analyzer

This comment has been minimized.

@landsharkiest
landsharkiest force-pushed the float_mul_add_relaxed-#151770 branch from 174bea7 to 67e0947 Compare July 18, 2026 02:44
rust-bors Bot pushed a commit that referenced this pull request Jul 19, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #159188 (Always generate private and hidden items in JSON docs of the stdlib)
 - #159567 (Update rustc crate crossbeam-epoch to 0.9.20)
 - #150732 (Convert `-Ctarget-cpu` into a target-modifier for AVR, AMDGCN and NVPTX )
 - #151793 (Add mul_add_relaxed methods for floating-point types)
 - #159549 (restrict const-eval-related 'content' triggers to library/ folder)
 - #159570 (fix ICE in opsem inhabitedness check)
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

💔 I suspect this PR failed tests as part of a rollup
@bors r-

After fixing the problem, consider running a try job for the failed job before re-approving.

Link to failure: #159573 (comment)

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 19, 2026
@rust-bors

rust-bors Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#159573), which was unapproved.

View changes since this unapproval

Comment thread tests/ui/intrinsics/float-mul-add-relaxed.rs Outdated
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 23, 2026
@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors squash msg="Add mul_add_relaxed methods for floating-point types"

@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

🔨 2 commits were squashed into ace8a46.

@rust-bors
rust-bors Bot force-pushed the float_mul_add_relaxed-#151770 branch from f117ad7 to ace8a46 Compare July 25, 2026 22:46
@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

📌 Commit ace8a46 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

Reason for tree closure: spurious failures

@rust-bors rust-bors Bot 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 Jul 25, 2026
@folkertdev

Copy link
Copy Markdown
Contributor

We may as well try

@bors try jobs=dist-i586-gnu-i586-i686-musl

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 25, 2026
…r=<try>

Add mul_add_relaxed methods for floating-point types


try-job: dist-i586-gnu-i586-i686-musl
@rust-bors rust-bors Bot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 26, 2026
@rust-bors

rust-bors Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 2e2b7e3 failed: CI. Failed job:

@folkertdev

Copy link
Copy Markdown
Contributor

Looks like the fix was not quite sufficient

@bors r-

@rust-bors rust-bors Bot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jul 26, 2026
@rust-bors

rust-bors Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

View changes since this unapproval

@scottmcm

Copy link
Copy Markdown
Member

i586 is known sketchy for floats always, right? Could potentially just skip them for that...

@folkertdev

Copy link
Copy Markdown
Contributor

Yeah some tests were already skipped since the last CI failure, seems like a bit more ignoring is needed.

https://triagebot.infra.rust-lang.org/gh-changes-since/rust-lang/rust/151793/234c31cd674e11703f15d290cba7ff81dfe8b4b8..3b7025f3a35e74943089a7e2dfe139bf2f821a89

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job dist-i586-gnu-i586-i686-musl failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

stderr:

thread 'main' (464263) panicked at library/core/src/num/f64.rs:16:1:
assertion failed: r == 9.020562075079397e-19 || r == 1.734723475976807e-18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- library/core/src/num/f64.rs - f64::f64::mul_add_relaxed (line 1749) stdout end ----

failures:

@RalfJung

Copy link
Copy Markdown
Member

Yeah if you check precise results then it's not surprising to see failures on that target.

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

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants