Add mul_add_relaxed methods for floating-point types#151793
Add mul_add_relaxed methods for floating-point types#151793landsharkiest wants to merge 9 commits intorust-lang:mainfrom
Conversation
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: rust-lang#151770
|
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.
- Use core::intrinsics::fmuladd* directly in std impl - Remove trailing whitespace from test file
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
These doc tests require platform-specific f16/f128 support and should not be run during standard doc builds.
This comment has been minimized.
This comment has been minimized.
| @@ -0,0 +1,49 @@ | |||
| //@ run-pass | |||
There was a problem hiding this comment.
f16 and f128 should be covered here too. They just need to be gated behing #[cfg(target_has_reliable_f16_math)] / target_has_reliable_f128_math
- Fix test: 0.0 * INFINITY = NaN, not 1.0 (IEEE 754) - Add #[cfg(target_has_reliable_f16_math)] gate for f16 - Add #[cfg(target_has_reliable_f128_math)] gate for f128 - Remove 'ignore' from doc tests as they now have proper cfg gates
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| /// // - (m * x) + b with separate roundings | ||
| /// let result = m.mul_add_relaxed(x, b); | ||
| /// | ||
| /// // For simple values, both approaches give the same result |
There was a problem hiding this comment.
Can we please include at least one example where they don't give the same result, and the assert has to be "well it's either this or that"?
Here's one I tossed together; there are probably better ones:
let r = 0.1_f32.mul_add_relaxed(0.1_f32, -0.01_f32);
assert!(r == 9.313226e-10 || r == 5.2154064e-10);
Self::mul_add instead of f32::mul_add/f64::mul_add + added examples
This comment has been minimized.
This comment has been minimized.
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
☔ The latest upstream changes (presumably #152624) made this pull request unmergeable. Please resolve the merge conflicts. |
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
#151770