Optimize queue save state. (nw)

This commit is contained in:
couriersud 2017-02-11 21:58:27 +01:00
parent 132cc8fe76
commit d7f420ccf7
3 changed files with 24 additions and 15 deletions

View File

@ -183,8 +183,11 @@ public:
, m_channel(*this, "CHAN", 0) , m_channel(*this, "CHAN", 0)
, m_mult(*this, "MULT", 1000.0) , m_mult(*this, "MULT", 1000.0)
, m_offset(*this, "OFFSET", 0.0) , m_offset(*this, "OFFSET", 0.0)
, m_buffer(nullptr)
, m_sample(netlist::netlist_time::from_hz(1)) //sufficiently big enough , m_sample(netlist::netlist_time::from_hz(1)) //sufficiently big enough
, m_in(*this, "IN") , m_in(*this, "IN")
, m_cur(0.0)
, m_last_pos(0)
, m_last_buffer(*this, "m_last_buffer", netlist::netlist_time::zero()) , m_last_buffer(*this, "m_last_buffer", netlist::netlist_time::zero())
{ {
} }
@ -255,6 +258,8 @@ public:
: netlist::device_t(anetlist, name) : netlist::device_t(anetlist, name)
, m_feedback(*this, "FB") // clock part , m_feedback(*this, "FB") // clock part
, m_Q(*this, "Q") , m_Q(*this, "Q")
, m_pos(0)
, m_num_channel(0)
{ {
connect(m_feedback, m_Q); connect(m_feedback, m_Q);
m_inc = netlist::netlist_time::from_nsec(1); m_inc = netlist::netlist_time::from_nsec(1);
@ -266,7 +271,6 @@ public:
m_param_mult[i] = std::make_unique<netlist::param_double_t>(*this, plib::pfmt("MULT{1}")(i), 1.0); m_param_mult[i] = std::make_unique<netlist::param_double_t>(*this, plib::pfmt("MULT{1}")(i), 1.0);
m_param_offset[i] = std::make_unique<netlist::param_double_t>(*this, plib::pfmt("OFFSET{1}")(i), 0.0); m_param_offset[i] = std::make_unique<netlist::param_double_t>(*this, plib::pfmt("OFFSET{1}")(i), 0.0);
} }
m_num_channel = 0;
} }
static const int MAX_INPUT_CHANNELS = 10; static const int MAX_INPUT_CHANNELS = 10;

View File

@ -20,6 +20,7 @@
#include <cstring> #include <cstring>
#include <cmath> #include <cmath>
#include <limits>
namespace netlist namespace netlist
{ {
@ -151,7 +152,7 @@ detail::queue_t::queue_t(netlist_t &nl)
, plib::state_manager_t::callback_t() , plib::state_manager_t::callback_t()
, m_qsize(0) , m_qsize(0)
, m_times(512) , m_times(512)
, m_names(512) , m_net_ids(512)
{ {
} }
@ -160,7 +161,7 @@ void detail::queue_t::register_state(plib::state_manager_t &manager, const pstri
netlist().log().debug("register_state\n"); netlist().log().debug("register_state\n");
manager.save_item(this, m_qsize, module + "." + "qsize"); manager.save_item(this, m_qsize, module + "." + "qsize");
manager.save_item(this, &m_times[0], module + "." + "times", m_times.size()); manager.save_item(this, &m_times[0], module + "." + "times", m_times.size());
manager.save_item(this, &(m_names[0].m_buf[0]), module + "." + "names", m_names.size() * sizeof(names_t)); manager.save_item(this, &m_net_ids[0], module + "." + "names", m_net_ids.size());
} }
void detail::queue_t::on_pre_save() void detail::queue_t::on_pre_save()
@ -171,11 +172,7 @@ void detail::queue_t::on_pre_save()
for (std::size_t i = 0; i < m_qsize; i++ ) for (std::size_t i = 0; i < m_qsize; i++ )
{ {
m_times[i] = this->listptr()[i].m_exec_time.as_raw(); m_times[i] = this->listptr()[i].m_exec_time.as_raw();
pstring p = this->listptr()[i].m_object->name(); m_net_ids[i] = netlist().find_net_id(this->listptr()[i].m_object);
std::size_t n = p.len();
if (n > 63) n = 63;
std::strncpy(m_names[i].m_buf, p.c_str(), n);
m_names[i].m_buf[n] = 0;
} }
} }
@ -186,9 +183,7 @@ void detail::queue_t::on_post_load()
netlist().log().debug("current time {1} qsize {2}\n", netlist().time().as_double(), m_qsize); netlist().log().debug("current time {1} qsize {2}\n", netlist().time().as_double(), m_qsize);
for (std::size_t i = 0; i < m_qsize; i++ ) for (std::size_t i = 0; i < m_qsize; i++ )
{ {
detail::net_t *n = netlist().find_net(pstring(m_names[i].m_buf, pstring::UTF8)); detail::net_t *n = netlist().m_nets[m_net_ids[i]].get();
//log().debug("Got {1} ==> {2}\n", qtemp[i].m_name, n));
//log().debug("schedule time {1} ({2})\n", n->time().as_double(), netlist_time::from_raw(m_times[i]).as_double()));
this->push(queue_t::entry_t(netlist_time::from_raw(m_times[i]),n)); this->push(queue_t::entry_t(netlist_time::from_raw(m_times[i]),n));
} }
} }
@ -408,7 +403,7 @@ void netlist_t::stop()
m_solver->stop(); m_solver->stop();
} }
detail::net_t *netlist_t::find_net(const pstring &name) detail::net_t *netlist_t::find_net(const pstring &name) const
{ {
for (auto & net : m_nets) for (auto & net : m_nets)
if (net->name() == name) if (net->name() == name)
@ -417,6 +412,16 @@ detail::net_t *netlist_t::find_net(const pstring &name)
return nullptr; return nullptr;
} }
std::size_t netlist_t::find_net_id(const detail::net_t *net) const
{
for (std::size_t i = 0; i < m_nets.size(); i++)
if (m_nets[i].get() == net)
return i;
return std::numeric_limits<std::size_t>::max();
}
void netlist_t::rebuild_lists() void netlist_t::rebuild_lists()
{ {
for (auto & net : m_nets) for (auto & net : m_nets)

View File

@ -1163,10 +1163,9 @@ namespace netlist
void on_post_load() override; void on_post_load() override;
private: private:
struct names_t { char m_buf[64]; };
std::size_t m_qsize; std::size_t m_qsize;
std::vector<netlist_time::internal_type> m_times; std::vector<netlist_time::internal_type> m_times;
std::vector<names_t> m_names; std::vector<std::size_t> m_net_ids;
}; };
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -1208,7 +1207,8 @@ namespace netlist
void register_dev(plib::owned_ptr<core_device_t> dev); void register_dev(plib::owned_ptr<core_device_t> dev);
void remove_dev(core_device_t *dev); void remove_dev(core_device_t *dev);
detail::net_t *find_net(const pstring &name); detail::net_t *find_net(const pstring &name) const;
std::size_t find_net_id(const detail::net_t *net) const;
template<class device_class> template<class device_class>
std::vector<device_class *> get_device_list() std::vector<device_class *> get_device_list()