diff options
Diffstat (limited to 'src/lib/netlist/devices/nlid_system.h')
-rw-r--r-- | src/lib/netlist/devices/nlid_system.h | 137 |
1 files changed, 73 insertions, 64 deletions
diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index c1c44e764e1..fee4fad0333 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -1,4 +1,4 @@ -// license:GPL-2.0+ +// license:BSD-3-Clause // copyright-holders:Couriersud #ifndef NLID_SYSTEM_H_ #define NLID_SYSTEM_H_ @@ -16,10 +16,8 @@ #include <random> -namespace netlist -{ -namespace devices -{ +namespace netlist::devices { + // ----------------------------------------------------------------------------- // clock // ----------------------------------------------------------------------------- @@ -58,7 +56,7 @@ namespace devices }; // ----------------------------------------------------------------------------- - // varclock + // variable clock // ----------------------------------------------------------------------------- NETLIB_OBJECT(varclock) @@ -73,17 +71,24 @@ namespace devices { if (!m_func().empty()) { - std::vector<pstring> inps; - inps.emplace_back("T"); + std::vector<pstring> inputs; + + m_I.reserve(m_N()); + inputs.reserve(m_N() + 1); + m_vals.reserve(m_N() + 1); + + // add time parameter to the front + inputs.emplace_back("T"); m_vals.push_back(nlconst::zero()); - for (int i=0; i < m_N(); i++) + + for (std::uint64_t i=0; i < m_N(); i++) { - pstring inpname = plib::pfmt("A{1}")(i); - m_I.push_back(owner.template make_pool_object<analog_input_t>(*this, inpname, NETLIB_DELEGATE(fb))); - inps.push_back(inpname); + pstring input_name = plib::pfmt("A{1}")(i); + m_I.push_back(state().make_pool_object<analog_input_t>(*this, input_name, NETLIB_DELEGATE(fb))); + inputs.push_back(input_name); m_vals.push_back(nlconst::zero()); } - m_compiled->compile(m_func(), inps); + m_compiled->compile(m_func(), inputs); } connect("FB", "Q"); } @@ -103,7 +108,7 @@ namespace devices } using pf_type = plib::pfunction<nl_fptype>; - param_int_t m_N; + param_num_t<std::uint64_t> m_N; param_str_t m_func; logic_input_t m_feedback; logic_output_t m_Q; @@ -244,12 +249,12 @@ namespace devices , m_p_ROUT(*this, "ROUT", nlconst::magic(50.0)) { - register_subalias("I", "m_RIN.1"); - register_subalias("G", "m_RIN.2"); + register_sub_alias("I", "m_RIN.1"); + register_sub_alias("G", "m_RIN.2"); connect("_I", "m_RIN.1"); - register_subalias("_OP", "m_ROUT.1"); - register_subalias("Q", "m_ROUT.2"); + register_sub_alias("_OP", "m_ROUT.1"); + register_sub_alias("Q", "m_ROUT.2"); connect("_Q", "m_ROUT.1"); } @@ -266,8 +271,8 @@ namespace devices m_Q.push(m_I()); } - analog::NETLIB_NAME(twoterm) m_RIN; - analog::NETLIB_NAME(twoterm) m_ROUT; + analog::NETLIB_NAME(two_terminal) m_RIN; + analog::NETLIB_NAME(two_terminal) m_ROUT; analog_input_t m_I; analog_output_t m_Q; @@ -283,21 +288,26 @@ namespace devices { NETLIB_CONSTRUCTOR(function) , m_N(*this, "N", 1) - , m_func(*this, "FUNC", "A0") + , m_function(*this, "FUNC", "A0") , m_thresh(*this, "THRESH", nlconst::zero()) , m_Q(*this, "Q") , m_compiled(*this, "m_compiled") , m_last(*this, "m_last") { - std::vector<pstring> inps; - for (int i=0; i < m_N(); i++) + std::vector<pstring> inputs; + + m_I.reserve(m_N()); + inputs.reserve(m_N()); + m_values.reserve(m_N()); + + for (uint64_t i=0; i < m_N(); i++) { - pstring inpname = plib::pfmt("A{1}")(i); - m_I.push_back(owner.template make_pool_object<analog_input_t>(*this, inpname, NETLIB_DELEGATE(inputs))); - inps.push_back(inpname); - m_vals.push_back(nlconst::zero()); + pstring input_name = plib::pfmt("A{1}")(i); + m_I.push_back(state().make_pool_object<analog_input_t>(*this, input_name, NETLIB_DELEGATE(inputs))); + inputs.push_back(input_name); + m_values.push_back(nlconst::zero()); } - m_compiled->compile(m_func(), inps); + m_compiled->compile(m_function(), inputs); } protected: @@ -310,9 +320,9 @@ namespace devices { for (std::size_t i = 0; i < static_cast<unsigned>(m_N()); i++) { - m_vals[i] = (*m_I[i])(); + m_values[i] = (*m_I[i])(); } - auto result = m_compiled->evaluate(m_vals); + auto result = m_compiled->evaluate(m_values); if (plib::abs(m_last - result) >= m_thresh) { m_Q.push(result); @@ -322,13 +332,13 @@ namespace devices private: using pf_type = plib::pfunction<nl_fptype>; - param_int_t m_N; - param_str_t m_func; + param_num_t<std::uint64_t> m_N; + param_str_t m_function; param_fp_t m_thresh; analog_output_t m_Q; std::vector<device_arena::unique_ptr<analog_input_t>> m_I; - pf_type::values_container m_vals; + pf_type::values_container m_values; state_var<pf_type> m_compiled; state_var<nl_fptype> m_last; @@ -347,22 +357,22 @@ namespace devices , m_I(*this, "I", NETLIB_DELEGATE(input)) , m_last_state(*this, "m_last_state", 0) { - register_subalias("1", "_R.1"); - register_subalias("2", "_R.2"); + register_sub_alias("1", "_R.1"); + register_sub_alias("2", "_R.2"); } NETLIB_RESETI() { m_last_state = 0; - m_R.set_R(m_ROFF()); + m_R().set_R(m_ROFF()); } //NETLIB_UPDATE_PARAMI(); //FIXME: used by 74123 - const terminal_t &P() const noexcept { return m_R.P(); } - const terminal_t &N() const noexcept { return m_R.N(); } + const terminal_t &P() const noexcept { return m_R().P(); } + const terminal_t &N() const noexcept { return m_R().N(); } const logic_input_t &I() const noexcept { return m_I; } param_fp_t m_RON; @@ -377,14 +387,14 @@ namespace devices m_last_state = state; const nl_fptype R = (state != 0) ? m_RON() : m_ROFF(); - m_R.change_state([this, &R]() + m_R().change_state([this, &R]() { - m_R.set_R(R); + m_R().set_R(R); }); } } - analog::NETLIB_SUB(R_base) m_R; + NETLIB_SUB_NS(analog, R_base) m_R; logic_input_t m_I; state_var<netlist_sig_t> m_last_state; @@ -405,17 +415,17 @@ namespace devices , m_power_pins(*this) { // connect and register pins - register_subalias("1", "_R1.1"); - register_subalias("2", "_R1.2"); - register_subalias("3", "_R2.2"); + register_sub_alias("1", "_R1.1"); + register_sub_alias("2", "_R1.2"); + register_sub_alias("3", "_R2.2"); connect("_R1.2", "_R2.1"); } private: NETLIB_RESETI() { - m_R1.set_G(m_GOFF()); - m_R2.set_G(m_GON()); + m_R1().set_G(m_GOFF()); + m_R2().set_G(m_GON()); } //NETLIB_UPDATE_PARAMI(); @@ -427,29 +437,29 @@ namespace devices //printf("Here %d\n", state); const nl_fptype G1 = (state != 0) ? m_GON() : m_GOFF(); const nl_fptype G2 = (state != 0) ? m_GOFF() : m_GON(); - if (m_R1.solver() == m_R2.solver()) + if (m_R1().solver() == m_R2().solver()) { - m_R1.change_state([this, &G1, &G2]() + m_R1().change_state([this, &G1, &G2]() { - m_R1.set_G(G1); - m_R2.set_G(G2); + m_R1().set_G(G1); + m_R2().set_G(G2); }); } else { - m_R1.change_state([this, &G1]() + m_R1().change_state([this, &G1]() { - m_R1.set_G(G1); + m_R1().set_G(G1); }); - m_R2.change_state([this, &G2]() + m_R2().change_state([this, &G2]() { - m_R2.set_G(G2); + m_R2().set_G(G2); }); } } - analog::NETLIB_SUB(R_base) m_R1; - analog::NETLIB_SUB(R_base) m_R2; + NETLIB_SUB_NS(analog, R_base) m_R1; + NETLIB_SUB_NS(analog, R_base) m_R2; logic_input_t m_I; param_fp_t m_GON; param_fp_t m_GOFF; @@ -552,26 +562,26 @@ namespace devices , m_dis(*this, "m_dis",m_sigma()) { - register_subalias("1", "m_T.1"); - register_subalias("2", "m_T.2"); + register_sub_alias("1", "m_T.1"); + register_sub_alias("2", "m_T.2"); } private: NETLIB_HANDLERI(input) { nl_fptype val = m_dis()(m_mt()); - m_T.change_state([this, val]() + m_T().change_state([this, val]() { - m_T.set_G_V_I(plib::reciprocal(m_RI()), val, nlconst::zero()); + m_T().set_G_V_I(plib::reciprocal(m_RI()), val, nlconst::zero()); }); } NETLIB_RESETI() { - m_T.set_G_V_I(plib::reciprocal(m_RI()), nlconst::zero(), nlconst::zero()); + m_T().set_G_V_I(plib::reciprocal(m_RI()), nlconst::zero(), nlconst::zero()); } - analog::NETLIB_SUB(twoterm) m_T; + NETLIB_SUB_NS(analog, two_terminal) m_T; logic_input_t m_I; param_fp_t m_RI; param_fp_t m_sigma; @@ -579,7 +589,6 @@ namespace devices state_var<distribution> m_dis; }; -} // namespace devices -} // namespace netlist +} // namespace netlist::devices #endif // NLD_SYSTEM_H_ |