diff --git a/src/lib/netlist/analog/nld_bjt.cpp b/src/lib/netlist/analog/nld_bjt.cpp index 7f8e57a8511..fb8aeafda1c 100644 --- a/src/lib/netlist/analog/nld_bjt.cpp +++ b/src/lib/netlist/analog/nld_bjt.cpp @@ -209,6 +209,7 @@ NETLIB_OBJECT_DERIVED(QBJT_switch, QBJT) NETLIB_UPDATE_PARAMI(); NETLIB_UPDATE_TERMINALSI(); +private: nld_twoterm m_RB; nld_twoterm m_RC; @@ -216,9 +217,6 @@ NETLIB_OBJECT_DERIVED(QBJT_switch, QBJT) nld_twoterm m_BC_dummy; -protected: - - nl_double m_gB; // base conductance / switch on nl_double m_gC; // collector conductance / switch on nl_double m_V; // internal voltage source @@ -261,10 +259,10 @@ protected: NETLIB_UPDATE_PARAMI(); NETLIB_UPDATE_TERMINALSI(); +private: generic_diode m_gD_BC; generic_diode m_gD_BE; -private: nld_twoterm m_D_CB; // gcc, gce - gcc, gec - gcc, gcc - gce | Ic nld_twoterm m_D_EB; // gee, gec - gee, gce - gee, gee - gec | Ie nld_twoterm m_D_EC; // 0, -gec, -gcc, 0 | 0 diff --git a/src/lib/netlist/analog/nlid_fourterm.h b/src/lib/netlist/analog/nlid_fourterm.h index 46ee7d6e54a..2d0d1ec174f 100644 --- a/src/lib/netlist/analog/nlid_fourterm.h +++ b/src/lib/netlist/analog/nlid_fourterm.h @@ -66,6 +66,7 @@ namespace netlist { NETLIB_NAME(VCCS)::reset(); } + terminal_t m_OP; terminal_t m_ON; @@ -91,14 +92,14 @@ namespace netlist { NETLIB_IS_DYNAMIC(true) - param_double_t m_cur_limit; /* current limit */ - protected: //NETLIB_UPDATEI(); NETLIB_RESETI(); NETLIB_UPDATE_PARAMI(); NETLIB_UPDATE_TERMINALSI(); + private: + param_double_t m_cur_limit; /* current limit */ nl_double m_vi; }; @@ -185,13 +186,14 @@ namespace netlist { param_double_t m_RO; - protected: + private: //NETLIB_UPDATEI(); //NETLIB_UPDATE_PARAMI(); terminal_t m_OP2; terminal_t m_ON2; + }; } // namespace analog diff --git a/src/lib/netlist/analog/nlid_twoterm.cpp b/src/lib/netlist/analog/nlid_twoterm.cpp index 84cf5ed7b53..832b343ac15 100644 --- a/src/lib/netlist/analog/nlid_twoterm.cpp +++ b/src/lib/netlist/analog/nlid_twoterm.cpp @@ -20,7 +20,7 @@ namespace netlist // generic_diode // ---------------------------------------------------------------------------------------- -generic_diode::generic_diode(device_t &dev, pstring name) +generic_diode::generic_diode(device_t &dev, const pstring &name) : m_Vd(dev, name + ".m_Vd", 0.7) , m_Id(dev, name + ".m_Id", 0.0) , m_G(dev, name + ".m_G", 1e-15) diff --git a/src/lib/netlist/analog/nlid_twoterm.h b/src/lib/netlist/analog/nlid_twoterm.h index 65451a03c6c..546e8193734 100644 --- a/src/lib/netlist/analog/nlid_twoterm.h +++ b/src/lib/netlist/analog/nlid_twoterm.h @@ -141,7 +141,6 @@ NETLIB_OBJECT_DERIVED(R, R_base) { } - param_double_t m_R; protected: @@ -150,6 +149,7 @@ protected: NETLIB_UPDATE_PARAMI(); private: + param_double_t m_R; /* protect set_R ... it's a recipe to desaster when used to bypass the parameter */ using NETLIB_NAME(R_base)::set_R; }; @@ -267,13 +267,13 @@ public: NETLIB_TIMESTEPI(); NETLIB_RESETI(); - param_double_t m_L; - protected: //NETLIB_UPDATEI(); NETLIB_UPDATE_PARAMI(); private: + param_double_t m_L; + nl_double m_GParallel; nl_double m_G; nl_double m_I; @@ -286,7 +286,7 @@ private: class generic_diode { public: - generic_diode(device_t &dev, pstring name); + generic_diode(device_t &dev, const pstring &name); void update_diode(const double nVd); @@ -383,12 +383,12 @@ public: NETLIB_UPDATE_TERMINALSI(); NETLIB_RESETI(); - diode_model_t m_model; - protected: //NETLIB_UPDATEI(); NETLIB_UPDATE_PARAMI(); +private: + diode_model_t m_model; generic_diode m_D; }; diff --git a/src/lib/netlist/build/makefile b/src/lib/netlist/build/makefile index 289f7a906a2..40d75f32fd8 100644 --- a/src/lib/netlist/build/makefile +++ b/src/lib/netlist/build/makefile @@ -21,12 +21,12 @@ TIDY_FLAGSX += -modernize-use-default-member-init,-cppcoreguidelines-pro-bounds- TIDY_FLAGSX += -modernize-pass-by-value,-cppcoreguidelines-pro-type-static-cast-downcast, #TIDY_FLAGSX += -cppcoreguidelines-special-member-functions, #TIDY_FLAGSX += -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -TIDY_FLAGSX += -performance-unnecessary-value-param,-cppcoreguidelines-avoid-magic-numbers, +TIDY_FLAGSX += performance-unnecessary-value-param,-cppcoreguidelines-avoid-magic-numbers, TIDY_FLAGSX += -cppcoreguidelines-macro-usage, -TIDY_FLAGSX += -cppcoreguidelines-non-private-member-variables-in-classes,-misc-non-private-member-variables-in-classes, +TIDY_FLAGSX += cppcoreguidelines-non-private-member-variables-in-classes,-misc-non-private-member-variables-in-classes, #TIDY_FLAGSX += -cppcoreguidelines-avoid-c-arrays,-modernize-avoid-c-arrays, #TIDY_FLAGSX += -modernize-use-using, -TIDY_FLAGSX += -performance-unnecessary-copy-initialization, +TIDY_FLAGSX += performance-unnecessary-copy-initialization, TIDY_FLAGSX += -bugprone-macro-parentheses,-misc-macro-parentheses space := diff --git a/src/lib/netlist/devices/nld_4066.cpp b/src/lib/netlist/devices/nld_4066.cpp index 9b7672e00c2..0c7511ca438 100644 --- a/src/lib/netlist/devices/nld_4066.cpp +++ b/src/lib/netlist/devices/nld_4066.cpp @@ -29,7 +29,7 @@ namespace netlist NETLIB_RESETI(); NETLIB_UPDATEI(); - public: + private: NETLIB_SUB(vdd_vss) m_supply; analog::NETLIB_SUB(R_base) m_R; diff --git a/src/lib/netlist/devices/nld_7493.cpp b/src/lib/netlist/devices/nld_7493.cpp index 261fe4ff927..f9eca065dc6 100644 --- a/src/lib/netlist/devices/nld_7493.cpp +++ b/src/lib/netlist/devices/nld_7493.cpp @@ -119,10 +119,10 @@ namespace netlist { m_CLKA.inactivate(); m_CLKB.inactivate(); - m_QA.push_force(0, NLTIME_FROM_NS(40)); - m_QB.push_force(0, NLTIME_FROM_NS(40)); - m_QC.push_force(0, NLTIME_FROM_NS(40)); - m_QD.push_force(0, NLTIME_FROM_NS(40)); + m_QA.push(0, NLTIME_FROM_NS(40)); + m_QB.push(0, NLTIME_FROM_NS(40)); + m_QC.push(0, NLTIME_FROM_NS(40)); + m_QD.push(0, NLTIME_FROM_NS(40)); m_a = m_bcd = 0; } } diff --git a/src/lib/netlist/devices/nld_legacy.cpp b/src/lib/netlist/devices/nld_legacy.cpp index df0bbc111cb..ed695a91417 100644 --- a/src/lib/netlist/devices/nld_legacy.cpp +++ b/src/lib/netlist/devices/nld_legacy.cpp @@ -25,7 +25,7 @@ namespace netlist NETLIB_RESETI(); NETLIB_UPDATEI(); - protected: + private: logic_input_t m_S; logic_input_t m_R; @@ -49,7 +49,7 @@ namespace netlist NETLIB_RESETI(); NETLIB_UPDATEI(); - protected: + private: logic_input_t m_I; logic_output_t m_Q; diff --git a/src/lib/netlist/devices/nlid_proxy.h b/src/lib/netlist/devices/nlid_proxy.h index 09a5da48c25..a6967a87a9f 100644 --- a/src/lib/netlist/devices/nlid_proxy.h +++ b/src/lib/netlist/devices/nlid_proxy.h @@ -90,8 +90,6 @@ namespace netlist logic_output_t *out_proxied, detail::core_terminal_t &proxy_out); logic_input_t m_I; - - private: }; NETLIB_OBJECT_DERIVED(d_to_a_proxy, base_d_to_a_proxy) diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index e58b15ed03b..02e8453c6e7 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -72,9 +72,9 @@ namespace netlist public: logic_output_t m_Q; - - param_double_t m_freq; netlist_time m_inc; + private: + param_double_t m_freq; }; // ----------------------------------------------------------------------------- @@ -96,7 +96,7 @@ namespace netlist //NETLIB_RESETI(); NETLIB_UPDATE_PARAMI(); - protected: + private: logic_input_t m_feedback; logic_output_t m_Q; @@ -154,7 +154,7 @@ namespace netlist NETLIB_HANDLERI(clk2); NETLIB_HANDLERI(clk2_pow2); - protected: + private: param_double_t m_freq; param_str_t m_pattern; @@ -187,7 +187,7 @@ namespace netlist NETLIB_RESETI() { m_Q.initial(0); } NETLIB_UPDATE_PARAMI() { m_Q.push(m_IN() & 1, netlist_time::from_nsec(1)); } - protected: + private: logic_output_t m_Q; param_logic_t m_IN; @@ -206,7 +206,7 @@ namespace netlist NETLIB_RESETI() { m_Q.initial(0.0); } NETLIB_UPDATE_PARAMI() { m_Q.push(m_IN()); } - protected: + private: analog_output_t m_Q; param_double_t m_IN; }; @@ -358,16 +358,17 @@ namespace netlist register_subalias("2", m_R.m_N); } + NETLIB_RESETI(); + //NETLIB_UPDATE_PARAMI(); + NETLIB_UPDATEI(); + analog::NETLIB_SUB(R_base) m_R; logic_input_t m_I; param_double_t m_RON; param_double_t m_ROFF; - NETLIB_RESETI(); - //NETLIB_UPDATE_PARAMI(); - NETLIB_UPDATEI(); - private: + state_var m_last_state; }; diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 3d6a8cf04b0..8ba7ad7b5f8 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -361,7 +361,7 @@ void netlist_state_t::reset() std::vector t; log().verbose("Using default startup strategy"); for (auto &n : m_nets) - for (auto & term : n->m_core_terms) + for (auto & term : n->core_terms()) if (term->m_delegate.has_object()) { if (!plib::container::contains(t, &term->m_delegate)) diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 7f65a33e6bf..dccfb32f896 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -773,7 +773,7 @@ namespace netlist void rebuild_list(); /* rebuild m_list after a load */ void move_connections(net_t &dest_net); - std::vector m_core_terms; // save post-start m_list ... + std::vector &core_terms() { return m_core_terms; } #if USE_COPY_INSTEAD_OF_REFERENCE void update_inputs() { @@ -786,34 +786,20 @@ namespace netlist /* nothing needs to be done */ } #endif + protected: - state_var m_new_Q; - state_var m_cur_Q; - state_var m_in_queue; /* 0: not in queue, 1: in queue, 2: last was taken */ - - state_var m_next_scheduled_time; - - private: - plib::linkedlist_t m_list_active; - core_terminal_t * m_railterminal; - - template - void process(const T mask, netlist_sig_t sig); - }; - - class logic_net_t : public detail::net_t - { - public: - - logic_net_t(netlist_state_t &nl, const pstring &aname, detail::core_terminal_t *mr = nullptr); + /* only used for logic nets */ netlist_sig_t Q() const noexcept { return m_cur_Q; } + + /* only used for logic nets */ void initial(const netlist_sig_t val) noexcept { m_cur_Q = m_new_Q = val; update_inputs(); } + /* only used for logic nets */ void set_Q_and_push(const netlist_sig_t newQ, const netlist_time delay) NL_NOEXCEPT { if (newQ != m_new_Q) @@ -822,15 +808,8 @@ namespace netlist push_to_queue(delay); } } - void set_Q_and_push_force(const netlist_sig_t newQ, const netlist_time delay) NL_NOEXCEPT - { - if (newQ != m_new_Q || is_queued()) - { - m_new_Q = newQ; - push_to_queue(delay); - } - } + /* only used for logic nets */ void set_Q_time(const netlist_sig_t newQ, const netlist_time at) NL_NOEXCEPT { if (newQ != m_new_Q) @@ -845,10 +824,34 @@ namespace netlist /* internal state support * FIXME: get rid of this and implement export/import in MAME */ + /* only used for logic nets */ netlist_sig_t *Q_state_ptr() { return m_cur_Q.ptr(); } - protected: private: + state_var m_new_Q; + state_var m_cur_Q; + state_var m_in_queue; /* 0: not in queue, 1: in queue, 2: last was taken */ + state_var m_next_scheduled_time; + + core_terminal_t * m_railterminal; + plib::linkedlist_t m_list_active; + std::vector m_core_terms; // save post-start m_list ... + + template + void process(const T mask, netlist_sig_t sig); + }; + + class logic_net_t : public detail::net_t + { + public: + + logic_net_t(netlist_state_t &nl, const pstring &aname, detail::core_terminal_t *mr = nullptr); + + using detail::net_t::Q; + using detail::net_t::initial; + using detail::net_t::set_Q_and_push; + using detail::net_t::set_Q_time; + using detail::net_t::Q_state_ptr; }; @@ -892,11 +895,6 @@ namespace netlist m_my_net.set_Q_and_push(newQ, delay); // take the shortcut } - void push_force(const netlist_sig_t newQ, const netlist_time delay) NL_NOEXCEPT - { - m_my_net.set_Q_and_push_force(newQ, delay); // take the shortcut - } - void set_Q_time(const netlist_sig_t newQ, const netlist_time at) NL_NOEXCEPT { m_my_net.set_Q_time(newQ, at); // take the shortcut @@ -1462,6 +1460,7 @@ namespace netlist netlist_time m_time; devices::NETLIB_NAME(mainclock) * m_mainclock; + PALIGNAS_CACHELINE() detail::queue_t m_queue; // performance diff --git a/src/lib/netlist/nl_lists.h b/src/lib/netlist/nl_lists.h index 39f4343be30..5443cd86c86 100644 --- a/src/lib/netlist/nl_lists.h +++ b/src/lib/netlist/nl_lists.h @@ -54,6 +54,7 @@ namespace netlist { constexpr pqentry_t() noexcept : m_exec_time(), m_object(nullptr) { } constexpr pqentry_t(const Time t, const Element o) noexcept : m_exec_time(t), m_object(o) { } +#if 0 ~pqentry_t() = default; constexpr pqentry_t(const pqentry_t &e) noexcept = default; constexpr pqentry_t(pqentry_t &&e) noexcept = default; @@ -65,7 +66,7 @@ namespace netlist std::swap(m_exec_time, other.m_exec_time); std::swap(m_object, other.m_object); } - +#endif struct QueueOp { inline static constexpr bool less(const pqentry_t &lhs, const pqentry_t &rhs) noexcept @@ -110,7 +111,7 @@ namespace netlist std::size_t capacity() const noexcept { return m_list.capacity() - 1; } bool empty() const noexcept { return (m_end == &m_list[1]); } - void push(T e) noexcept + void push(T && e) noexcept { /* Lock */ lock_guard_type lck(m_lock); @@ -120,7 +121,7 @@ namespace netlist *(i+1) = *(i); m_prof_sortmove.inc(); } - *(i+1) = e; + *(i+1) = std::move(e); ++m_end; m_prof_call.inc(); } @@ -129,7 +130,7 @@ namespace netlist const T &top() const noexcept { return *(m_end-1); } template - void remove(const R elem) noexcept + void remove(const R &elem) noexcept { /* Lock */ lock_guard_type lck(m_lock); @@ -145,7 +146,7 @@ namespace netlist } } - void retime(T elem) noexcept + void retime(T && elem) noexcept { /* Lock */ lock_guard_type lck(m_lock); @@ -155,7 +156,7 @@ namespace netlist { if (QueueOp::equal(*i, elem)) // partial equal! { - *i = elem; + *i = std::move(elem); while (QueueOp::less(*(i-1), *i)) { std::swap(*(i-1), *i); diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index b892fb4571c..3ac1b604bc4 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -462,14 +462,14 @@ devices::nld_base_proxy *setup_t::get_d_a_proxy(detail::core_terminal_t &out) m_proxy_cnt++; /* connect all existing terminals to new net */ - for (auto & p : out.net().m_core_terms) + for (auto & p : out.net().core_terms()) { p->clear_net(); // de-link from all nets ... if (!connect(new_proxy->proxy_term(), *p)) log().fatal(MF_2_CONNECTING_1_TO_2, new_proxy->proxy_term().name(), (*p).name()); } - out.net().m_core_terms.clear(); // clear the list + out.net().core_terms().clear(); // clear the list out.net().add_terminal(new_proxy->in()); out_cast.set_proxy(proxy); @@ -505,14 +505,14 @@ devices::nld_base_proxy *setup_t::get_a_d_proxy(detail::core_terminal_t &inp) if (inp.has_net()) { - for (auto & p : inp.net().m_core_terms) + for (auto & p : inp.net().core_terms()) { p->clear_net(); // de-link from all nets ... if (!connect(ret->proxy_term(), *p)) log().fatal(MF_2_CONNECTING_1_TO_2, ret->proxy_term().name(), (*p).name()); } - inp.net().m_core_terms.clear(); // clear the list + inp.net().core_terms().clear(); // clear the list } ret->out().net().add_terminal(inp); m_netlist.nlstate().add_dev(new_proxy->name(), std::move(new_proxy)); @@ -667,7 +667,7 @@ bool setup_t::connect_input_input(detail::core_terminal_t &t1, detail::core_term ret = connect(t2, t1.net().railterminal()); if (!ret) { - for (auto & t : t1.net().m_core_terms) + for (auto & t : t1.net().core_terms()) { if (t->is_type(detail::terminal_type::TERMINAL)) ret = connect(t2, *t); @@ -682,7 +682,7 @@ bool setup_t::connect_input_input(detail::core_terminal_t &t1, detail::core_term ret = connect(t1, t2.net().railterminal()); if (!ret) { - for (auto & t : t2.net().m_core_terms) + for (auto & t : t2.net().core_terms()) { if (t->is_type(detail::terminal_type::TERMINAL)) ret = connect(t1, *t); @@ -1123,7 +1123,7 @@ void setup_t::prepare_to_run() solver->post_start(); for (auto &n : netlist().nets()) - for (auto & term : n->m_core_terms) + for (auto & term : n->core_terms()) { //core_device_t *dev = reinterpret_cast(term->m_delegate.object()); core_device_t *dev = &term->device(); diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 5e445fc6a32..50536d9da3b 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -253,7 +253,7 @@ namespace netlist /* FIXME: used by source_t - need a different approach at some time */ bool parse_stream(plib::unique_ptr &&istrm, const pstring &name); - void add_define(pstring def, pstring val) + void add_define(const pstring &def, const pstring &val) { m_defines.insert({ def, plib::ppreprocessor::define_t(def, val)}); } @@ -444,7 +444,7 @@ namespace netlist class source_proc_t : public source_t { public: - source_proc_t(pstring name, void (*setup_func)(nlparse_t &)) + source_proc_t(const pstring &name, void (*setup_func)(nlparse_t &)) : source_t(), m_setup_func(setup_func), m_setup_func_name(name) diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h index 45c19ef7b3a..6380a4cef07 100644 --- a/src/lib/netlist/plib/palloc.h +++ b/src/lib/netlist/plib/palloc.h @@ -40,18 +40,26 @@ namespace plib { } return p; #else - return aligned_alloc(alignment, size); + return aligned_alloc(alignment, size); #endif } static inline void pfree( void *ptr ) { + // NOLINTNEXTLINE(cppcoreguidelines-no-malloc) free(ptr); } + static constexpr bool is_pow2(std::size_t v) noexcept { return !(v & (v-1)); } + template inline C14CONSTEXPR T *assume_aligned_ptr(T *p) noexcept { + static_assert(ALIGN >= alignof(T), "Alignment must be greater or equal to alignof(T)"); + static_assert(is_pow2(ALIGN), "Alignment must be a power of 2"); + //auto t = reinterpret_cast(p); + //if (t & (ALIGN-1)) + // printf("alignment error!"); return reinterpret_cast(__builtin_assume_aligned(p, ALIGN)); } @@ -246,10 +254,14 @@ namespace plib { static_assert(ALIGN >= alignof(T) && (ALIGN % alignof(T)) == 0, "ALIGN must be greater than alignof(T) and a multiple"); - aligned_allocator() = default; + aligned_allocator() noexcept = default; + ~aligned_allocator() noexcept = default; - aligned_allocator(const aligned_allocator&) = default; - aligned_allocator& operator=(const aligned_allocator&) = delete; + aligned_allocator(const aligned_allocator&) noexcept = default; + aligned_allocator& operator=(const aligned_allocator&) noexcept = delete; + + aligned_allocator(aligned_allocator&&) noexcept = default; + aligned_allocator& operator=(aligned_allocator&&) = delete; template aligned_allocator(const aligned_allocator& rhs) noexcept @@ -308,6 +320,8 @@ namespace plib { using reference = typename base::reference; using const_reference = typename base::const_reference; + using pointer = typename base::pointer; + using const_pointer = typename base::const_pointer; using size_type = typename base::size_type; using base::base; @@ -321,6 +335,9 @@ namespace plib { return assume_aligned_ptr(this->data())[i]; } + pointer data() noexcept { return assume_aligned_ptr(base::data()); } + const_pointer data() const noexcept { return assume_aligned_ptr(base::data()); } + }; diff --git a/src/lib/netlist/plib/parray.h b/src/lib/netlist/plib/parray.h index e09639163f0..9fe4ab972eb 100644 --- a/src/lib/netlist/plib/parray.h +++ b/src/lib/netlist/plib/parray.h @@ -8,9 +8,9 @@ #ifndef PARRAY_H_ #define PARRAY_H_ +#include "palloc.h" #include "pconfig.h" #include "pexception.h" -#include "palloc.h" #include #include diff --git a/src/lib/netlist/plib/pconfig.h b/src/lib/netlist/plib/pconfig.h index 9f61fc0b01f..9754643678a 100644 --- a/src/lib/netlist/plib/pconfig.h +++ b/src/lib/netlist/plib/pconfig.h @@ -46,7 +46,7 @@ */ #define PALIGN_CACHELINE (64) -#define PALIGN_VECTOROPT (16) +#define PALIGN_VECTOROPT (32) #define PALIGNAS_CACHELINE() PALIGNAS(PALIGN_CACHELINE) #define PALIGNAS_VECTOROPT() PALIGNAS(PALIGN_VECTOROPT) diff --git a/src/lib/netlist/plib/pdynlib.cpp b/src/lib/netlist/plib/pdynlib.cpp index c0c89de208d..91e1b5cf73a 100644 --- a/src/lib/netlist/plib/pdynlib.cpp +++ b/src/lib/netlist/plib/pdynlib.cpp @@ -58,7 +58,7 @@ WCHAR *wstring_from_utf8(const char *utf8string) #endif namespace plib { -dynlib::dynlib(const pstring libname) +dynlib::dynlib(const pstring &libname) : m_isLoaded(false), m_lib(nullptr) { #ifdef _WIN32 @@ -88,7 +88,7 @@ dynlib::dynlib(const pstring libname) #endif } -dynlib::dynlib(const pstring path, const pstring libname) +dynlib::dynlib(const pstring &path, const pstring &libname) : m_isLoaded(false), m_lib(nullptr) { // FIXME: implement path search @@ -141,7 +141,7 @@ bool dynlib::isLoaded() const return m_isLoaded; } -void *dynlib::getsym_p(const pstring name) +void *dynlib::getsym_p(const pstring &name) { #ifdef _WIN32 return (void *) GetProcAddress((HMODULE) m_lib, name.c_str()); diff --git a/src/lib/netlist/plib/pdynlib.h b/src/lib/netlist/plib/pdynlib.h index fe9db58d6f2..1454c053298 100644 --- a/src/lib/netlist/plib/pdynlib.h +++ b/src/lib/netlist/plib/pdynlib.h @@ -18,8 +18,8 @@ namespace plib { class dynlib : public nocopyassignmove { public: - explicit dynlib(const pstring libname); - dynlib(const pstring path, const pstring libname); + explicit dynlib(const pstring &libname); + dynlib(const pstring &path, const pstring &libname); ~dynlib(); COPYASSIGNMOVE(dynlib, delete) @@ -27,12 +27,12 @@ public: bool isLoaded() const; template - T getsym(const pstring name) + T getsym(const pstring &name) { return reinterpret_cast(getsym_p(name)); } private: - void *getsym_p(const pstring name); + void *getsym_p(const pstring &name); bool m_isLoaded; void *m_lib; diff --git a/src/lib/netlist/plib/pexception.cpp b/src/lib/netlist/plib/pexception.cpp index 93f1c24c08c..8d6907d66f2 100644 --- a/src/lib/netlist/plib/pexception.cpp +++ b/src/lib/netlist/plib/pexception.cpp @@ -23,7 +23,7 @@ namespace plib { // terminate //============================================================ - void terminate(pstring msg) noexcept + void terminate(const pstring &msg) noexcept { std::cerr << msg.c_str() << "\n"; std::terminate(); diff --git a/src/lib/netlist/plib/pexception.h b/src/lib/netlist/plib/pexception.h index 98d993d689b..44daf53d591 100644 --- a/src/lib/netlist/plib/pexception.h +++ b/src/lib/netlist/plib/pexception.h @@ -23,7 +23,7 @@ namespace plib { * * \note could be enhanced by setting a termination handler */ - [[noreturn]] void terminate(pstring msg) noexcept; + [[noreturn]] void terminate(const pstring &msg) noexcept; //============================================================ // exception base diff --git a/src/lib/netlist/plib/pfmtlog.cpp b/src/lib/netlist/plib/pfmtlog.cpp index e4e7c3d1c5c..0d911800247 100644 --- a/src/lib/netlist/plib/pfmtlog.cpp +++ b/src/lib/netlist/plib/pfmtlog.cpp @@ -9,13 +9,13 @@ #include "palloc.h" #include +#include #include -#include #include +#include #include #include #include -#include namespace plib { @@ -28,6 +28,8 @@ pfmt &pfmt::format_element(const char *l, const unsigned cfmt_spec, ...) std::array buf; std::size_t sl; + buf[0] = 0; + m_arg++; pstring search("{"); diff --git a/src/lib/netlist/plib/pfunction.cpp b/src/lib/netlist/plib/pfunction.cpp index c6a6287a8aa..6a2179e0e6f 100644 --- a/src/lib/netlist/plib/pfunction.cpp +++ b/src/lib/netlist/plib/pfunction.cpp @@ -84,7 +84,7 @@ void pfunction::compile_postfix(const std::vector &inputs, throw plib::pexception(plib::pfmt("nld_function: stack count different to one on <{2}>")(expr)); } -static int get_prio(pstring v) +static int get_prio(const pstring &v) { if (v == "(" || v == ")") return 1; diff --git a/src/lib/netlist/plib/plists.h b/src/lib/netlist/plib/plists.h index c11ee6fabdc..0a1345d5e1f 100644 --- a/src/lib/netlist/plib/plists.h +++ b/src/lib/netlist/plib/plists.h @@ -205,7 +205,8 @@ public: iter_t& operator=(const iter_t &rhs) { iter_t t(rhs); std::swap(*this, t); return *this; } iter_t& operator=(iter_t &&rhs) noexcept { std::swap(*this, rhs); return *this; } iter_t& operator++() noexcept {p = p->next();return *this;} - iter_t operator++(int) noexcept {const iter_t tmp(*this); operator++(); return tmp;} + // NOLINTNEXTLINE(cert-dcl21-cpp) + iter_t operator++(int) & noexcept {const iter_t tmp(*this); operator++(); return tmp;} ~iter_t() = default; diff --git a/src/lib/netlist/plib/pmempool.h b/src/lib/netlist/plib/pmempool.h index c55d66d8847..166c6f3d483 100644 --- a/src/lib/netlist/plib/pmempool.h +++ b/src/lib/netlist/plib/pmempool.h @@ -139,8 +139,8 @@ namespace plib { auto *ret = reinterpret_cast(b->m_data + b->m_cur); auto capacity(rs); ret = std::align(align, size, ret, capacity); - if (ret == nullptr) - printf("Oh no\n"); + // FIXME: if (ret == nullptr) + // printf("Oh no\n"); sinfo().insert({ ret, info(b, b->m_cur)}); rs -= (capacity - size); b->m_cur += rs; @@ -155,8 +155,8 @@ namespace plib { auto *ret = reinterpret_cast(b->m_data + b->m_cur); auto capacity(rs); ret = std::align(align, size, ret, capacity); - if (ret == nullptr) - printf("Oh no\n"); + // FIXME: if (ret == nullptr) + // printf("Oh no\n"); sinfo().insert({ ret, info(b, b->m_cur)}); rs -= (capacity - size); b->m_cur += rs; diff --git a/src/lib/netlist/plib/poptions.cpp b/src/lib/netlist/plib/poptions.cpp index 2a58eaab0f4..4a3d32c4723 100644 --- a/src/lib/netlist/plib/poptions.cpp +++ b/src/lib/netlist/plib/poptions.cpp @@ -14,13 +14,13 @@ namespace plib { Options ***************************************************************************/ - option_base::option_base(options &parent, pstring help) + option_base::option_base(options &parent, const pstring &help) : m_help(help) { parent.register_option(this); } - option::option(options &parent, pstring ashort, pstring along, pstring help, bool has_argument) + option::option(options &parent, const pstring &ashort, const pstring &along, const pstring &help, bool has_argument) : option_base(parent, help), m_short(ashort), m_long(along), m_has_argument(has_argument), m_specified(false) { @@ -174,7 +174,7 @@ namespace plib { return argc; } - pstring options::split_paragraphs(pstring text, unsigned width, unsigned indent, + pstring options::split_paragraphs(const pstring &text, unsigned width, unsigned indent, unsigned firstline_indent) { auto paragraphs = psplit(text,"\n"); @@ -197,7 +197,7 @@ namespace plib { return ret; } - pstring options::help(pstring description, pstring usage, + pstring options::help(const pstring &description, const pstring &usage, unsigned width, unsigned indent) const { pstring ret; @@ -272,7 +272,7 @@ namespace plib { return ret; } - option *options::getopt_short(pstring arg) const + option *options::getopt_short(const pstring &arg) const { for (auto & optbase : m_opts) { @@ -282,7 +282,7 @@ namespace plib { } return nullptr; } - option *options::getopt_long(pstring arg) const + option *options::getopt_long(const pstring &arg) const { for (auto & optbase : m_opts) { diff --git a/src/lib/netlist/plib/poptions.h b/src/lib/netlist/plib/poptions.h index 23319604052..086fe32fc8a 100644 --- a/src/lib/netlist/plib/poptions.h +++ b/src/lib/netlist/plib/poptions.h @@ -24,7 +24,7 @@ class options; class option_base { public: - option_base(options &parent, pstring help); + option_base(options &parent, const pstring &help); virtual ~option_base() = default; COPYASSIGNMOVE(option_base, delete) @@ -37,7 +37,7 @@ private: class option_group : public option_base { public: - option_group(options &parent, pstring group, pstring help) + option_group(options &parent, const pstring &group, const pstring &help) : option_base(parent, help), m_group(group) { } pstring group() const { return m_group; } @@ -48,7 +48,7 @@ private: class option_example : public option_base { public: - option_example(options &parent, pstring group, pstring help) + option_example(options &parent, const pstring &group, const pstring &help) : option_base(parent, help), m_example(group) { } pstring example() const { return m_example; } @@ -60,7 +60,7 @@ private: class option : public option_base { public: - option(options &parent, pstring ashort, pstring along, pstring help, bool has_argument); + option(options &parent, const pstring &ashort, const pstring &along, const pstring &help, bool has_argument); /* no_argument options will be called with "" argument */ @@ -88,7 +88,7 @@ private: class option_str : public option { public: - option_str(options &parent, pstring ashort, pstring along, pstring defval, pstring help) + option_str(options &parent, const pstring &ashort, const pstring &along, const pstring &defval, const pstring &help) : option(parent, ashort, along, help, true), m_val(defval) {} @@ -104,7 +104,7 @@ private: class option_str_limit_base : public option { public: - option_str_limit_base(options &parent, pstring ashort, pstring along, std::vector &&limit, pstring help) + option_str_limit_base(options &parent, const pstring &ashort, const pstring &along, std::vector &&limit, const pstring &help) : option(parent, ashort, along, help, true) , m_limit(limit) { @@ -122,7 +122,7 @@ template class option_str_limit : public option_str_limit_base { public: - option_str_limit(options &parent, pstring ashort, pstring along, const T &defval, std::vector &&limit, pstring help) + option_str_limit(options &parent, const pstring &ashort, const pstring &along, const T &defval, std::vector &&limit, const pstring &help) : option_str_limit_base(parent, ashort, along, std::move(limit), help), m_val(defval) { } @@ -152,7 +152,7 @@ private: class option_bool : public option { public: - option_bool(options &parent, pstring ashort, pstring along, pstring help) + option_bool(options &parent, const pstring &ashort, const pstring &along, const pstring &help) : option(parent, ashort, along, help, false), m_val(false) {} @@ -169,8 +169,8 @@ template class option_num : public option { public: - option_num(options &parent, pstring ashort, pstring along, T defval, - pstring help, + option_num(options &parent, const pstring &ashort, const pstring &along, T defval, + const pstring &help, T minval = std::numeric_limits::min(), T maxval = std::numeric_limits::max() ) : option(parent, ashort, along, help, true) @@ -198,7 +198,7 @@ private: class option_vec : public option { public: - option_vec(options &parent, pstring ashort, pstring along, pstring help) + option_vec(options &parent, const pstring &ashort, const pstring &along, const pstring &help) : option(parent, ashort, along, help, true) {} @@ -214,7 +214,7 @@ private: class option_args : public option_vec { public: - option_args(options &parent, pstring help) + option_args(options &parent, const pstring &help) : option_vec(parent, "", "", help) {} }; @@ -229,13 +229,13 @@ public: void register_option(option_base *opt); int parse(int argc, char **argv); - pstring help(pstring description, pstring usage, + pstring help(const pstring &description, const pstring &usage, unsigned width = 72, unsigned indent = 20) const; pstring app() const { return m_app; } private: - static pstring split_paragraphs(pstring text, unsigned width, unsigned indent, + static pstring split_paragraphs(const pstring &text, unsigned width, unsigned indent, unsigned firstline_indent); void check_consistency(); @@ -251,8 +251,8 @@ private: return nullptr; } - option *getopt_short(pstring arg) const; - option *getopt_long(pstring arg) const; + option *getopt_short(const pstring &arg) const; + option *getopt_long(const pstring &arg) const; std::vector m_opts; pstring m_app; diff --git a/src/lib/netlist/plib/pparser.h b/src/lib/netlist/plib/pparser.h index 9803fae9cb8..24b096519bf 100644 --- a/src/lib/netlist/plib/pparser.h +++ b/src/lib/netlist/plib/pparser.h @@ -98,18 +98,18 @@ public: void require_token(const token_id_t &token_num); void require_token(const token_t &tok, const token_id_t &token_num); - token_id_t register_token(pstring token) + token_id_t register_token(const pstring &token) { token_id_t ret(m_tokens.size()); m_tokens.emplace(token, ret); return ret; } - ptokenizer & identifier_chars(pstring s) { m_identifier_chars = s; return *this; } - ptokenizer & number_chars(pstring st, pstring rem) { m_number_chars_start = st; m_number_chars = rem; return *this; } + ptokenizer & identifier_chars(pstring s) { m_identifier_chars = std::move(s); return *this; } + ptokenizer & number_chars(pstring st, pstring rem) { m_number_chars_start = std::move(st); m_number_chars = std::move(rem); return *this; } ptokenizer & string_char(pstring::value_type c) { m_string = c; return *this; } - ptokenizer & whitespace(pstring s) { m_whitespace = s; return *this; } - ptokenizer & comment(pstring start, pstring end, pstring line) + ptokenizer & whitespace(pstring s) { m_whitespace = std::move(s); return *this; } + ptokenizer & comment(const pstring &start, const pstring &end, const pstring &line) { m_tok_comment_start = register_token(start); m_tok_comment_end = register_token(end); diff --git a/src/lib/netlist/plib/ppmf.h b/src/lib/netlist/plib/ppmf.h index 4dcceee454f..32b151b357b 100644 --- a/src/lib/netlist/plib/ppmf.h +++ b/src/lib/netlist/plib/ppmf.h @@ -95,6 +95,7 @@ namespace plib { if (PHAS_PMF_INTERNAL == 1) { // apply the "this" delta to the object first + // NOLINTNEXTLINE(clang-analyzer-core.UndefinedBinaryOperatorResult) auto o_p_delta = reinterpret_cast(reinterpret_cast(object) + m_this_delta); // if the low bit of the vtable index is clear, then it is just a raw function pointer diff --git a/src/lib/netlist/plib/pstate.h b/src/lib/netlist/plib/pstate.h index d837a6d2931..ac75ca6b69e 100644 --- a/src/lib/netlist/plib/pstate.h +++ b/src/lib/netlist/plib/pstate.h @@ -8,9 +8,9 @@ #ifndef PSTATE_H_ #define PSTATE_H_ +#include "palloc.h" #include "pstring.h" #include "ptypes.h" -#include "palloc.h" #include #include diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h index d5b2bfa4809..29f79e0dd4a 100644 --- a/src/lib/netlist/plib/pstream.h +++ b/src/lib/netlist/plib/pstream.h @@ -530,7 +530,8 @@ public: void write(const pstring &text) const { - putf8string conv_utf8(text); + // NOLINTNEXTLINE(performance-unnecessary-copy-initialization) + const putf8string conv_utf8(text); m_strm->write(reinterpret_cast(conv_utf8.c_str()), conv_utf8.mem_t_size()); } diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h index bc056424531..76ad11b0f91 100644 --- a/src/lib/netlist/plib/pstring.h +++ b/src/lib/netlist/plib/pstring.h @@ -46,7 +46,8 @@ public: explicit constexpr pstring_const_iterator(const typename string_type::const_iterator &x) noexcept : p(x) { } pstring_const_iterator& operator++() noexcept { p += static_cast(traits_type::codelen(&(*p))); return *this; } - pstring_const_iterator operator++(int) noexcept { pstring_const_iterator tmp(*this); operator++(); return tmp; } + // NOLINTNEXTLINE(cert-dcl21-cpp) + pstring_const_iterator operator++(int) & noexcept { pstring_const_iterator tmp(*this); operator++(); return tmp; } constexpr bool operator==(const pstring_const_iterator& rhs) const noexcept { return p == rhs.p; } constexpr bool operator!=(const pstring_const_iterator& rhs) const noexcept { return p != rhs.p; } @@ -207,10 +208,8 @@ public: static const size_type npos = static_cast(-1); -protected: - string_type m_str; - private: + string_type m_str; }; struct pu8_traits diff --git a/src/lib/netlist/plib/vector_ops.h b/src/lib/netlist/plib/vector_ops.h index f5a9e336d0d..0de931b40da 100644 --- a/src/lib/netlist/plib/vector_ops.h +++ b/src/lib/netlist/plib/vector_ops.h @@ -43,7 +43,8 @@ namespace plib template T vec_mult (const std::size_t n, const V1 & v1, const V2 & v2 ) { - PALIGNAS_VECTOROPT() T value[8] = {0}; + using b8 = T[8]; + PALIGNAS_VECTOROPT() b8 value = {0}; for (std::size_t i = 0; i < n ; i++ ) { value[i & 7] += v1[i] * v2[i]; @@ -54,7 +55,8 @@ namespace plib template T vec_mult2 (const std::size_t n, const VT &v) { - PALIGNAS_VECTOROPT() T value[8] = {0}; + using b8 = T[8]; + PALIGNAS_VECTOROPT() b8 value = {0}; for (std::size_t i = 0; i < n ; i++ ) { value[i & 7] += v[i] * v[i]; @@ -67,7 +69,7 @@ namespace plib { if (n<8) { - PALIGNAS_VECTOROPT() T value(0); + T value(0); for (std::size_t i = 0; i < n ; i++ ) value += v[i]; @@ -75,7 +77,8 @@ namespace plib } else { - PALIGNAS_VECTOROPT() T value[8] = {0}; + using b8 = T[8]; + PALIGNAS_VECTOROPT() b8 value = {0}; for (std::size_t i = 0; i < n ; i++ ) value[i & 7] += v[i]; diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index 076d004528c..a751bbd2965 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -120,7 +120,7 @@ NETLIST_END() class netlist_data_folder_t : public netlist::source_t { public: - netlist_data_folder_t(pstring folder) + netlist_data_folder_t(const pstring &folder) : netlist::source_t(netlist::source_t::DATA) , m_folder(folder) { @@ -311,7 +311,7 @@ struct input_t double m_value; }; -static std::vector read_input(const netlist::setup_t &setup, pstring fname) +static std::vector read_input(const netlist::setup_t &setup, const pstring &fname) { std::vector ret; if (fname != "") diff --git a/src/lib/netlist/prg/nlwav.cpp b/src/lib/netlist/prg/nlwav.cpp index 24c84c73739..bd30e93d7e6 100644 --- a/src/lib/netlist/prg/nlwav.cpp +++ b/src/lib/netlist/prg/nlwav.cpp @@ -363,17 +363,17 @@ public: } } - std::size_t m_channels; - double m_last_time; - private: - void write(pstring line) + void write(const pstring &line) { auto p = static_cast(line.c_str()); std::size_t len = std::strlen(p); m_fo.write(p, len); } + std::size_t m_channels; + double m_last_time; + plib::postream &m_fo; std::vector m_ids; pstring m_buf; @@ -410,6 +410,14 @@ public: "convert all files starting with \"log_V\" into a multichannel wav file"), m_outstrm(nullptr) {} + + int execute() override; + pstring usage() override; + +private: + void convert_wav(); + void convert_vcd(vcdwriter::format_e format); + plib::option_str_limit opt_fmt; plib::option_str opt_out; plib::option_num opt_rate; @@ -423,14 +431,8 @@ public: plib::option_bool opt_help; plib::option_example opt_ex1; plib::option_example opt_ex2; - - int execute() override; - pstring usage() override; - plib::pstdin pin_strm; -private: - void convert_wav(); - void convert_vcd(vcdwriter::format_e format); + std::vector> m_instrms; plib::postream *m_outstrm; }; diff --git a/src/lib/netlist/solver/nld_matrix_solver.cpp b/src/lib/netlist/solver/nld_matrix_solver.cpp index 951733874fd..dc03255a056 100644 --- a/src/lib/netlist/solver/nld_matrix_solver.cpp +++ b/src/lib/netlist/solver/nld_matrix_solver.cpp @@ -111,7 +111,7 @@ void matrix_solver_t::setup_base(analog_net_t::list_t &nets) net->set_solver(this); - for (auto &p : net->m_core_terms) + for (auto &p : net->core_terms()) { log().debug("{1} {2} {3}\n", p->name(), net->name(), net->isRailNet()); switch (p->type()) @@ -159,7 +159,7 @@ void matrix_solver_t::setup_base(analog_net_t::list_t &nets) break; } } - log().debug("added net with {1} populated connections\n", net->m_core_terms.size()); + log().debug("added net with {1} populated connections\n", net->core_terms().size()); } /* now setup the matrix */ @@ -336,9 +336,7 @@ void matrix_solver_t::setup_matrix() * This should reduce cache misses ... */ - auto **touched = plib::pnew_array(iN); - for (std::size_t k=0; k(iN); + std::vector> touched(iN, std::vector(iN)); for (std::size_t k = 0; k < iN; k++) { @@ -395,10 +393,6 @@ void matrix_solver_t::setup_matrix() state().save(*this, m_terms[k]->gt(),"GT" + num, this->name(), m_terms[k]->count()); state().save(*this, m_terms[k]->Idr(),"IDR" + num, this->name(), m_terms[k]->count()); } - - for (std::size_t k=0; km_core_terms) + for (auto &p : n->core_terms()) { if (p->is_type(detail::terminal_type::TERMINAL)) { @@ -399,7 +399,7 @@ void NETLIB_NAME(solver)::post_start() for (auto &n : grp) { log().verbose("Net {1}", n->name()); - for (const auto &pcore : n->m_core_terms) + for (const auto &pcore : n->core_terms()) { log().verbose(" {1}", pcore->name()); } diff --git a/src/lib/netlist/solver/nld_solver.h b/src/lib/netlist/solver/nld_solver.h index c4a9eba6971..164b7663f98 100644 --- a/src/lib/netlist/solver/nld_solver.h +++ b/src/lib/netlist/solver/nld_solver.h @@ -76,7 +76,7 @@ NETLIB_OBJECT(solver) NETLIB_RESETI(); // NETLIB_UPDATE_PARAMI(); -protected: +private: logic_input_t m_fb_step; logic_output_t m_Q_step; @@ -96,7 +96,6 @@ protected: param_logic_t m_log_stats; -private: std::vector> m_mat_solvers; std::vector m_mat_solvers_all; std::vector m_mat_solvers_timestepping; diff --git a/src/lib/netlist/tools/nl_convert.cpp b/src/lib/netlist/tools/nl_convert.cpp index f4616cb7774..16a3cfd6960 100644 --- a/src/lib/netlist/tools/nl_convert.cpp +++ b/src/lib/netlist/tools/nl_convert.cpp @@ -105,7 +105,7 @@ void nl_convert_base_t::add_device(const pstring &atype, const pstring &aname) add_device(plib::make_unique(atype, aname)); } -void nl_convert_base_t::add_term(pstring netname, pstring termname) +void nl_convert_base_t::add_term(const pstring &netname, const pstring &termname) { net_t * net = nullptr; auto idx = m_nets.find(netname); diff --git a/src/lib/netlist/tools/nl_convert.h b/src/lib/netlist/tools/nl_convert.h index 73c98301af5..b031ef72618 100644 --- a/src/lib/netlist/tools/nl_convert.h +++ b/src/lib/netlist/tools/nl_convert.h @@ -43,7 +43,7 @@ protected: void add_device(const pstring &atype, const pstring &aname, double aval); void add_device(const pstring &atype, const pstring &aname); - void add_term(pstring netname, pstring termname); + void add_term(const pstring &netname, const pstring &termname); void dump_nl();