summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2020-07-29 15:41:18 -0700
committer couriersud <couriersud@gmx.org>2020-08-02 13:04:59 +0200
commitcfcae647d548fca2f823812e8ac7ef288672e350 (patch)
tree36879c43d44a1ea55fcefa124bee916ea8151e68
parentd8733b9f25d23273b7eeaabf10786aef74e0082a (diff)
netlist: Minor optimization to remove sqrt from inner loop.
-rw-r--r--src/lib/netlist/solver/nld_matrix_solver_ext.h18
1 files 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<fptype>::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 <typename M>