You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enable fused multiply-subtract in complex mul_add #148
The reason was that LLVM could optimize the negation to use fused multiply-subtract.
I tested this in Rust with the function:
fn mul_add_new<T: Clone + Num + MulAdd<Output = T> + Neg<Output = T>>(
this: Complex<T>,
other: Complex<T>,
add: Complex<T>,
) -> Complex<T> {
let re = this.re.clone().mul_add(
other.re.clone(),
-this.im.clone().mul_add(other.im.clone(), -add.re),
);
let im = this.re.mul_add(other.im, this.im.mul_add(other.re, add.im));
Complex::new(re, im)
}
When compiling with fma enabled in release mode, it is optimized in the same way to use fused multiply-subtract.
A potential drawback is that it requires an additional Neg bound. It is not possible to change the negation to subtraction from zero, since the optimization no longer works.
Activity
recommended impl from rust-num#148