Conditionally use fma

This commit is contained in:
Magnus Ulimoen 2021-03-26 15:57:15 +01:00
parent 7ab6f311c1
commit 75338698a4
2 changed files with 8 additions and 1 deletions

View File

@ -6,5 +6,6 @@ edition = "2018"
[dependencies] [dependencies]
approx = { version = "0.4.0", optional = true } approx = { version = "0.4.0", optional = true }
cfg-if = "1.0.0"
float = { path = "../float" } float = { path = "../float" }
num-traits = "0.2.14" num-traits = "0.2.14"

View File

@ -131,7 +131,13 @@ impl<const M: usize, const P: usize> Matrix<Float, M, P> {
lhs[(i, 0)] * rhs[(0, j)] lhs[(i, 0)] * rhs[(0, j)]
}; };
for k in 1..N { for k in 1..N {
t = Float::mul_add(lhs[(i, k)], rhs[(k, j)], t); cfg_if::cfg_if!(
if #[cfg(target_feature="fma")] {
t = Float::mul_add(lhs[(i, k)], rhs[(k, j)], t);
} else {
t = t + lhs[(i, k)]*rhs[(k, j)];
}
);
} }
self[(i, j)] = t; self[(i, j)] = t;
} }