netlist: Minor optimization to remove sqrt from inner loop.

This commit is contained in:
Aaron Giles 2020-07-29 15:41:18 -07:00 committed by couriersud
parent d8733b9f25
commit cfcae647d5

View File

@ -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>