From cfcae647d548fca2f823812e8ac7ef288672e350 Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Wed, 29 Jul 2020 15:41:18 -0700 Subject: netlist: Minor optimization to remove sqrt from inner loop. --- src/lib/netlist/solver/nld_matrix_solver_ext.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lib/netlist/solver/nld_matrix_solver_ext.h b/src/lib/netlist/solver/nld_matrix_solver_ext.h index d308f1cf7c1..8938d7c25e4 100644 --- a/src/lib/netlist/solver/nld_matrix_solver_ext.h +++ b/src/lib/netlist/solver/nld_matrix_solver_ext.h @@ -171,7 +171,7 @@ namespace solver netlist_time compute_next_timestep(fptype cur_ts, fptype min_ts, fptype max_ts) override { - fptype new_solver_timestep(max_ts); + fptype new_solver_timestep_sq(max_ts * max_ts); for (std::size_t k = 0; k < size(); k++) { @@ -185,21 +185,21 @@ namespace solver const fptype hn = cur_ts; fptype DD2 = (DD_n / hn - m_DD_n_m_1[k] / m_h_n_m_1[k]) / (hn + m_h_n_m_1[k]); - fptype new_net_timestep(0); m_h_n_m_1[k] = hn; m_DD_n_m_1[k] = DD_n; if (plib::abs(DD2) > fp_constants::TIMESTEP_MINDIV()) // avoid div-by-zero - new_net_timestep = plib::sqrt(m_params.m_dynamic_lte / plib::abs(nlconst::half()*DD2)); - else - new_net_timestep = max_ts; - - new_solver_timestep = std::min(new_net_timestep, new_solver_timestep); + { + // save the sqrt for the end + const fptype new_net_timestep_sq = m_params.m_dynamic_lte / plib::abs(nlconst::half()*DD2); + new_solver_timestep_sq = std::min(new_net_timestep_sq, new_solver_timestep_sq); + } } - new_solver_timestep = std::max(new_solver_timestep, min_ts); + + new_solver_timestep_sq = std::max(plib::sqrt(new_solver_timestep_sq), min_ts); // FIXME: Factor 2 below is important. Without, we get timing issues. This must be a bug elsewhere. - return std::max(netlist_time::from_fp(new_solver_timestep), netlist_time::quantum() * 2); + return std::max(netlist_time::from_fp(new_solver_timestep_sq), netlist_time::quantum() * 2); } template -- cgit v1.2.3