From 75338698a440b9c59a6c6ea29b9b3eb94fda90cf Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Fri, 26 Mar 2021 15:57:15 +0100 Subject: [PATCH] Conditionally use fma --- utils/constmatrix/Cargo.toml | 1 + utils/constmatrix/src/lib.rs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/utils/constmatrix/Cargo.toml b/utils/constmatrix/Cargo.toml index 524e7b3..7ece053 100644 --- a/utils/constmatrix/Cargo.toml +++ b/utils/constmatrix/Cargo.toml @@ -6,5 +6,6 @@ edition = "2018" [dependencies] approx = { version = "0.4.0", optional = true } +cfg-if = "1.0.0" float = { path = "../float" } num-traits = "0.2.14" diff --git a/utils/constmatrix/src/lib.rs b/utils/constmatrix/src/lib.rs index 71ecfa7..74ce369 100644 --- a/utils/constmatrix/src/lib.rs +++ b/utils/constmatrix/src/lib.rs @@ -131,7 +131,13 @@ impl Matrix { lhs[(i, 0)] * rhs[(0, j)] }; 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; }