diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/netlist/nl_base.cpp | 31 | ||||
-rw-r--r-- | src/lib/netlist/nl_base.h | 12 | ||||
-rw-r--r-- | src/lib/netlist/nl_factory.h | 1 | ||||
-rw-r--r-- | src/lib/netlist/nl_setup.cpp | 30 | ||||
-rw-r--r-- | src/lib/netlist/nl_setup.h | 1 | ||||
-rw-r--r-- | src/lib/netlist/plib/palloc.cpp | 8 | ||||
-rw-r--r-- | src/lib/netlist/plib/palloc.h | 24 | ||||
-rw-r--r-- | src/lib/netlist/plib/plists.h | 1 | ||||
-rw-r--r-- | src/lib/netlist/plib/pparser.cpp | 1 | ||||
-rw-r--r-- | src/lib/netlist/plib/pstate.cpp | 1 | ||||
-rw-r--r-- | src/lib/netlist/plib/pstream.h | 1 | ||||
-rw-r--r-- | src/lib/netlist/solver/nld_solver.cpp | 80 | ||||
-rw-r--r-- | src/lib/netlist/tools/nl_convert.cpp | 1 |
13 files changed, 99 insertions, 93 deletions
diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index c4d402ff3ee..cc500693dd2 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -803,37 +803,6 @@ analog_net_t::analog_net_t(netlist_t &nl, const pstring &aname, detail::core_ter { } -bool analog_net_t::already_processed(std::vector<list_t> &groups) -{ - if (isRailNet()) - return true; - for (auto & grp : groups) - { - if (plib::container::contains(grp, this)) - return true; - } - return false; -} - -void analog_net_t::process_net(std::vector<list_t> &groups) -{ - if (num_cons() == 0) - return; - /* add the net */ - groups.back().push_back(this); - for (auto &p : m_core_terms) - { - if (p->is_type(terminal_t::TERMINAL)) - { - terminal_t *pt = static_cast<terminal_t *>(p); - analog_net_t *other_net = &pt->m_otherterm->net(); - if (!other_net->already_processed(groups)) - other_net->process_net(groups); - } - } -} - - // ---------------------------------------------------------------------------------------- // core_terminal_t // ---------------------------------------------------------------------------------------- diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index fbd67862dd7..d10c11839a3 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -17,6 +17,7 @@ #include "nl_lists.h" #include "nl_time.h" +#include "plib/palloc.h" #include "plib/pdynlib.h" #include "plib/pstate.h" #include "plib/pfmtlog.h" @@ -694,8 +695,6 @@ namespace netlist void rebuild_list(); /* rebuild m_list after a load */ - void move_connections(net_t *new_net); - std::vector<core_terminal_t *> m_core_terms; // save post-start m_list ... protected: @@ -707,6 +706,8 @@ namespace netlist state_var_u8 m_in_queue; /* 0: not in queue, 1: in queue, 2: last was taken */ private: + void move_connections(net_t *new_net); + plib::linkedlist_t<core_terminal_t> m_list_active; core_terminal_t * m_railterminal; @@ -750,7 +751,7 @@ namespace netlist /* internal state support * FIXME: get rid of this and implement export/import in MAME */ - netlist_sig_t &Q_state_ptr() { return m_cur_Q; } + netlist_sig_t &Q_state_ptr() { return m_cur_Q; } protected: private: @@ -772,12 +773,9 @@ namespace netlist nl_double &Q_Analog_state_ptr() { return m_cur_Analog; } //FIXME: needed by current solver code - devices::matrix_solver_t *solver() { return m_solver; } + devices::matrix_solver_t *solver() const { return m_solver; } void set_solver(devices::matrix_solver_t *solver) { m_solver = solver; } - bool already_processed(std::vector<list_t> &groups); - void process_net(std::vector<list_t> &groups); - private: devices::matrix_solver_t *m_solver; }; diff --git a/src/lib/netlist/nl_factory.h b/src/lib/netlist/nl_factory.h index d1dac190f30..6a53797d0d8 100644 --- a/src/lib/netlist/nl_factory.h +++ b/src/lib/netlist/nl_factory.h @@ -12,6 +12,7 @@ #include <type_traits> #include "nl_config.h" +#include "plib/palloc.h" #include "plib/plists.h" #include "plib/putil.h" #include "nl_base.h" diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 8048b7db46a..f02d7d7871a 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -678,8 +678,8 @@ void setup_t::resolve_inputs() int tries = 100; while (m_links.size() > 0 && tries > 0) // FIXME: convert into constant { - auto li = m_links.begin(); - while (li != m_links.end()) + + for (auto li = m_links.begin(); li != m_links.end(); ) { const pstring t1s = li->first; const pstring t2s = li->second; @@ -703,18 +703,20 @@ void setup_t::resolve_inputs() log().verbose("deleting empty nets ..."); - // delete empty nets ... and save m_list ... - - for (auto net = netlist().m_nets.begin(); net != netlist().m_nets.end();) - { - if (net->get()->num_cons() == 0) - { - log().verbose("Deleting net {1} ...", net->get()->name()); - net = netlist().m_nets.erase(net); - } - else - ++net; - } + // delete empty nets + + netlist().m_nets.erase( + std::remove_if(netlist().m_nets.begin(), netlist().m_nets.end(), + [](plib::owned_ptr<detail::net_t> &x) + { + if (x->num_cons() == 0) + { + x->netlist().log().verbose("Deleting net {1} ...", x->name()); + return true; + } + else + return false; + }), netlist().m_nets.end()); pstring errstr(""); diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 86de48e81ce..155ccc259c6 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -14,7 +14,6 @@ #include <vector> #include "plib/pstring.h" -#include "plib/palloc.h" #include "plib/pfmtlog.h" #include "plib/pstream.h" #include "plib/putil.h" diff --git a/src/lib/netlist/plib/palloc.cpp b/src/lib/netlist/plib/palloc.cpp index c89c2ed7e63..be987b5014b 100644 --- a/src/lib/netlist/plib/palloc.cpp +++ b/src/lib/netlist/plib/palloc.cpp @@ -64,7 +64,9 @@ mempool::~mempool() for (auto & b : m_blocks) { if (b.m_num_alloc != 0) - fprintf(stderr, "Found block with dangling allocations\n"); + { + fprintf(stderr, "Found block with %d dangling allocations\n", (int) b.m_num_alloc); + } delete b.data; } m_blocks.clear(); @@ -122,8 +124,8 @@ void mempool::free(void *ptr) fprintf(stderr, "Argh .. double free\n"); else { - b->m_free = m_min_alloc; - b->cur_ptr = b->data; + //b->m_free = m_min_alloc; + //b->cur_ptr = b->data; } b->m_num_alloc--; } diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h index fb467fbe173..088320fa7e3 100644 --- a/src/lib/netlist/plib/palloc.h +++ b/src/lib/netlist/plib/palloc.h @@ -117,14 +117,19 @@ public: { } owned_ptr(const owned_ptr &r) = delete; owned_ptr & operator =(owned_ptr &r) = delete; - owned_ptr & operator =(owned_ptr &&r) + + template<typename DC> + owned_ptr & operator =(owned_ptr<DC> &&r) { + if (m_is_owned && (m_ptr != nullptr)) + delete m_ptr; m_is_owned = r.m_is_owned; m_ptr = r.m_ptr; r.m_is_owned = false; r.m_ptr = nullptr; return *this; } + owned_ptr(owned_ptr &&r) { m_is_owned = r.m_is_owned; @@ -143,7 +148,7 @@ public: ~owned_ptr() { - if (m_is_owned && m_ptr != nullptr) + if (m_is_owned && (m_ptr != nullptr)) delete m_ptr; m_is_owned = false; m_ptr = nullptr; @@ -164,25 +169,16 @@ public: a.m_ptr = new SC(std::forward<Args>(args)...); return std::move(a); } - void release() + SC * release() { + SC *tmp = m_ptr; m_is_owned = false; m_ptr = nullptr; + return tmp; } bool is_owned() const { return m_is_owned; } -#if 1 - template<typename DC> - owned_ptr & operator =(owned_ptr<DC> &&r) - { - m_is_owned = r.m_is_owned; - m_ptr = r.m_ptr; - r.m_is_owned = false; - r.m_ptr = nullptr; - return *this; - } -#endif SC * operator ->() const { return m_ptr; } SC & operator *() const { return *m_ptr; } SC * get() const { return m_ptr; } diff --git a/src/lib/netlist/plib/plists.h b/src/lib/netlist/plib/plists.h index 16cb2f9e686..0bb83750874 100644 --- a/src/lib/netlist/plib/plists.h +++ b/src/lib/netlist/plib/plists.h @@ -15,7 +15,6 @@ #include <type_traits> #include <cmath> -#include "palloc.h" #include "pstring.h" namespace plib { diff --git a/src/lib/netlist/plib/pparser.cpp b/src/lib/netlist/plib/pparser.cpp index be52b27dc30..4f41c73d6f8 100644 --- a/src/lib/netlist/plib/pparser.cpp +++ b/src/lib/netlist/plib/pparser.cpp @@ -8,6 +8,7 @@ #include <cstdarg> #include "pparser.h" +#include "plib/palloc.h" namespace plib { // ---------------------------------------------------------------------------------------- diff --git a/src/lib/netlist/plib/pstate.cpp b/src/lib/netlist/plib/pstate.cpp index 61535acac09..ddfe0a37bc8 100644 --- a/src/lib/netlist/plib/pstate.cpp +++ b/src/lib/netlist/plib/pstate.cpp @@ -6,6 +6,7 @@ */ #include "pstate.h" +#include "palloc.h" namespace plib { state_manager_t::state_manager_t() diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h index 68ab55ca58b..20aaab83a3a 100644 --- a/src/lib/netlist/plib/pstream.h +++ b/src/lib/netlist/plib/pstream.h @@ -12,7 +12,6 @@ #include "pconfig.h" #include "pstring.h" -#include "palloc.h" #include "pfmtlog.h" namespace plib { diff --git a/src/lib/netlist/solver/nld_solver.cpp b/src/lib/netlist/solver/nld_solver.cpp index b26b7525b40..bc63cbf434a 100644 --- a/src/lib/netlist/solver/nld_solver.cpp +++ b/src/lib/netlist/solver/nld_solver.cpp @@ -157,9 +157,6 @@ void matrix_solver_t::setup_base(analog_net_t::list_t &nets) if (net_proxy_output == nullptr) { - //net_proxy_output = palloc(analog_output_t(*this, - // this->name() + "." + plib::pfmt("m{1}")(m_inps.size()))); - auto net_proxy_output_u = plib::make_unique<proxied_analog_output_t>(*this, this->name() + "." + plib::pfmt("m{1}")(m_inps.size())); net_proxy_output = net_proxy_output_u.get(); m_inps.push_back(std::move(net_proxy_output_u)); @@ -691,9 +688,61 @@ std::unique_ptr<matrix_solver_t> NETLIB_NAME(solver)::create_solver(unsigned siz } } -void NETLIB_NAME(solver)::post_start() +struct net_splitter { + + bool already_processed(analog_net_t *n) + { + if (n->isRailNet()) + return true; + for (auto & grp : groups) + if (plib::container::contains(grp, n)) + return true; + return false; + } + + void process_net(analog_net_t *n) + { + if (n->num_cons() == 0) + return; + /* add the net */ + groups.back().push_back(n); + for (auto &p : n->m_core_terms) + { + if (p->is_type(terminal_t::TERMINAL)) + { + terminal_t *pt = static_cast<terminal_t *>(p); + analog_net_t *other_net = &pt->m_otherterm->net(); + if (!already_processed(other_net)) + process_net(other_net); + } + } + } + + void run(netlist_t &netlist) + { + for (auto & net : netlist.m_nets) + { + netlist.log().debug("processing {1}\n", net->name()); + if (!net->isRailNet() && net->num_cons() > 0) + { + netlist.log().debug(" ==> not a rail net\n"); + /* Must be an analog net */ + analog_net_t *n = static_cast<analog_net_t *>(net.get()); + if (!already_processed(n)) + { + groups.push_back(analog_net_t::list_t()); + process_net(n); + } + } + } + } + std::vector<analog_net_t::list_t> groups; +}; + +void NETLIB_NAME(solver)::post_start() +{ const bool use_specific = true; m_params.m_pivot = m_pivot(); @@ -729,25 +778,14 @@ void NETLIB_NAME(solver)::post_start() netlist().log().verbose("Scanning net groups ..."); // determine net groups - for (auto & net : netlist().m_nets) - { - netlist().log().debug("processing {1}\n", net->name()); - if (!net->isRailNet()) - { - netlist().log().debug(" ==> not a rail net\n"); - /* Must be an analog net */ - analog_net_t *n = static_cast<analog_net_t *>(net.get()); - if (!n->already_processed(groups)) - { - groups.push_back(analog_net_t::list_t()); - n->process_net(groups); - } - } - } + + net_splitter splitter; + + splitter.run(netlist()); // setup the solvers - netlist().log().verbose("Found {1} net groups in {2} nets\n", groups.size(), netlist().m_nets.size()); - for (auto & grp : groups) + netlist().log().verbose("Found {1} net groups in {2} nets\n", splitter.groups.size(), netlist().m_nets.size()); + for (auto & grp : splitter.groups) { std::unique_ptr<matrix_solver_t> ms; unsigned net_count = static_cast<unsigned>(grp.size()); diff --git a/src/lib/netlist/tools/nl_convert.cpp b/src/lib/netlist/tools/nl_convert.cpp index 5a238bfe9ba..b0ca5fe3c0d 100644 --- a/src/lib/netlist/tools/nl_convert.cpp +++ b/src/lib/netlist/tools/nl_convert.cpp @@ -9,6 +9,7 @@ #include <cstdio> #include <cmath> #include "nl_convert.h" +#include "plib/palloc.h" /*------------------------------------------------- |