Add mul_add_relaxed methods for floating-point types - #151793
landsharkiest wants to merge 3 commits into
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@landsharkiest friendly reminder that this PR is waiting for you to react to the reviewer's feedback and to fix CI. :) |
|
Another thing, please update the doc comment of the intrinsics to point to the public methods, like here rust/library/core/src/intrinsics/mod.rs Lines 1459 to 1480 in a6050b7 We use the prasing of "stabilized" here even if the methods are not actually stable. |
0ca5122 to
174bea7
Compare
This comment has been minimized.
This comment has been minimized.
Sorry got caught up in school and job searching, will finally put this away! :) |
This comment has been minimized.
This comment has been minimized.
174bea7 to
67e0947
Compare
|
|
|
Yeah some tests were already skipped since the last CI failure, seems like a bit more ignoring is needed. |
This comment has been minimized.
This comment has been minimized.
|
Yeah if you check precise results then it's not surprising to see failures on that target. |
| /// # #[cfg(target_has_reliable_f16)] { | ||
| /// | ||
| /// let result = 1.0f16.mul_add_relaxed(2.0, 3.0); | ||
| /// assert_eq!(result, 5.0); |
There was a problem hiding this comment.
Could you add the (0.1, 0.1, -0.01) example for f16 and f128 too? Answers should be either -7.6e-6 or -7.03e-6 for f16, 1.5046327690525280101999827676444745E-36 or 7.824090399073145653039910391751267E-37 for f128.
This comment has been minimized.
This comment has been minimized.
On 32-bit x86 without SSE2, x87 rounds the f64 product to a 64-bit significand rather than keeping it exact or rounding it to 53 bits, so the doc example can produce a value (9.0209e-19) that is neither the fused nor the unfused result. Skip that check there, like other float doctests do for i586. The f32 example is unaffected: its intermediate values fit in the x87 significand, so it always yields one of the two allowed results. Also add the fused-or-unfused example to f16 and f128, as requested in review.
ace8a46 to
335e78f
Compare
|
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. |
|
r? @folkertdev @landsharkiest remember to post |
|
@bors try |
This comment has been minimized.
This comment has been minimized.
…r=<try> Add mul_add_relaxed methods for floating-point types
Say that even two invocations with the same inputs may produce different results, and remove the `1.0.mul_add_relaxed(2.0, 3.0)` example: it is atypical, since the fused and unfused results are the same there. The fused-or-unfused example remains.
|
@bors try |
This comment has been minimized.
This comment has been minimized.
…r=<try> Add mul_add_relaxed methods for floating-point types
|
It seems to ignore try-jobs in the PR description? Strange. @bors try jobs=dist-i586-gnu-i586-i686-musl |
This comment has been minimized.
This comment has been minimized.
…r=<try> Add mul_add_relaxed methods for floating-point types try-job: dist-i586-gnu-i586-i686-musl
|
@rustbot ready |
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
try-job: dist-i586-gnu-i586-i686-musl