From 3b899b86e67e3a5cc093d2dd9c0dcaeed197c806 Mon Sep 17 00:00:00 2001 From: couriersud Date: Wed, 6 Feb 2019 10:24:34 +0100 Subject: netlist: Refactoring after adding clang-tidy support to netlist makefile - convert macros to c++ code. - order of device creation should not depend on std lib. - some state saving cleanup. - added support for clang-tidy to makefile. - modifications triggered by clang-tidy-9. --- src/lib/netlist/plib/pfmtlog.h | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'src/lib/netlist/plib/pfmtlog.h') diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h index 9b7a85d8d8d..bf9d45fadd2 100644 --- a/src/lib/netlist/plib/pfmtlog.h +++ b/src/lib/netlist/plib/pfmtlog.h @@ -136,7 +136,6 @@ struct ptype_traits : ptype_traits_base static char32_t fmt_spec() { return 'f'; } }; - template<> struct ptype_traits : ptype_traits_base { @@ -144,6 +143,13 @@ struct ptype_traits : ptype_traits_base static char32_t fmt_spec() { return 's'; } }; +template<> +struct ptype_traits : ptype_traits_base +{ + static const char *cast(const std::string &x) { return x.c_str(); } + static char32_t fmt_spec() { return 's'; } +}; + class pfmt { public: @@ -151,44 +157,50 @@ public: : m_str(fmt), m_arg(0) { } - - pfmt(const pfmt &rhs) : m_str(rhs.m_str), m_arg(rhs.m_arg) { } - - ~pfmt() - { - } + pfmt(const pfmt &rhs) = default; + ~pfmt() = default; operator pstring() const { return m_str; } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) pfmt & e(const double &x) {return format_element("", 'e', x); } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) pfmt & g(const double &x) {return format_element("", 'g', x); } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) pfmt & e(const float &x) {return format_element("", 'e', static_cast(x)); } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) pfmt & g(const float &x) {return format_element("", 'g', static_cast(x)); } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) pfmt &operator ()(const void *x) {return format_element("", 'p', x); } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) pfmt &operator ()(const pstring &x) {return format_element("", 's', x.c_str() ); } template pfmt &operator ()(const T &x) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) return format_element(ptype_traits::size_spec(), ptype_traits::fmt_spec(), ptype_traits::cast(x)); } template pfmt &operator ()(const T *x) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) return format_element(ptype_traits::size_spec(), ptype_traits::fmt_spec(), ptype_traits::cast(x)); } template pfmt &x(const T &x) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) return format_element(ptype_traits::size_spec(), 'x', x); } template pfmt &o(const T &x) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) return format_element(ptype_traits::size_spec(), 'o', x); } @@ -237,7 +249,7 @@ public: bool is_enabled() const { return m_enabled; } protected: - ~pfmt_writer_t() { } + ~pfmt_writer_t() = default; private: pfmt &xlog(pfmt &fmt) const { return fmt; } @@ -258,7 +270,7 @@ class plog_channel : public pfmt_writer_t, bui friend class pfmt_writer_t, build_enabled>; public: explicit plog_channel(T &b) : pfmt_writer_t(), m_base(b) { } - ~plog_channel() { } + ~plog_channel() = default; protected: void vdowrite(const pstring &ls) const @@ -283,7 +295,7 @@ public: error(proxy), fatal(proxy) {} - virtual ~plog_base() {} + virtual ~plog_base() = default; plog_channel debug; plog_channel info; @@ -293,7 +305,7 @@ public: plog_channel fatal; }; -} +} // namespace plib template plib::pfmt& operator<<(plib::pfmt &p, T&& val) { return p(std::forward(val)); } -- cgit v1.2.3-70-g09d2 From a905dffd08abdabad3d3e0cfd1c56eb1d91376cf Mon Sep 17 00:00:00 2001 From: couriersud Date: Mon, 11 Feb 2019 22:18:30 +0100 Subject: netlist: More cpp core guidelines alignment. (nw) --- src/lib/netlist/build/makefile | 11 ++-- src/lib/netlist/devices/nld_7448.cpp | 4 +- src/lib/netlist/devices/nld_7450.cpp | 12 ++-- src/lib/netlist/devices/nld_7490.cpp | 2 +- src/lib/netlist/devices/nld_am2847.cpp | 2 +- src/lib/netlist/devices/nlid_proxy.h | 8 --- src/lib/netlist/devices/nlid_system.h | 2 +- src/lib/netlist/devices/nlid_truthtable.h | 2 - src/lib/netlist/netlist_types.h | 8 +++ src/lib/netlist/nl_base.cpp | 6 +- src/lib/netlist/nl_base.h | 53 +++++++++++++---- src/lib/netlist/nl_factory.cpp | 5 -- src/lib/netlist/nl_factory.h | 8 ++- src/lib/netlist/nl_setup.cpp | 4 +- src/lib/netlist/nl_setup.h | 10 +++- src/lib/netlist/nl_time.h | 2 + src/lib/netlist/plib/mat_cr.h | 3 + src/lib/netlist/plib/palloc.cpp | 3 +- src/lib/netlist/plib/palloc.h | 13 +++++ src/lib/netlist/plib/pchrono.h | 9 +-- src/lib/netlist/plib/pdynlib.h | 5 +- src/lib/netlist/plib/pexception.h | 5 +- src/lib/netlist/plib/pfmtlog.h | 20 +++++-- src/lib/netlist/plib/plists.h | 16 +++-- src/lib/netlist/plib/pmain.h | 3 + src/lib/netlist/plib/poptions.cpp | 5 -- src/lib/netlist/plib/poptions.h | 6 +- src/lib/netlist/plib/pparser.h | 8 ++- src/lib/netlist/plib/pstate.h | 9 ++- src/lib/netlist/plib/pstream.h | 94 +++++++++++++++++++++++++++--- src/lib/netlist/plib/pstring.h | 8 +-- src/lib/netlist/plib/ptypes.h | 10 ++++ src/lib/netlist/prg/nltool.cpp | 2 - src/lib/netlist/prg/nlwav.cpp | 3 + src/lib/netlist/solver/nld_matrix_solver.h | 3 - src/lib/netlist/solver/nld_ms_direct.h | 2 - src/lib/netlist/solver/nld_ms_gcr.h | 5 +- src/lib/netlist/solver/nld_ms_gmres.h | 2 - src/lib/netlist/solver/nld_ms_sm.h | 2 - src/lib/netlist/solver/nld_ms_sor.h | 2 - src/lib/netlist/solver/nld_ms_sor_mat.h | 2 - src/lib/netlist/solver/nld_ms_w.h | 6 +- src/lib/netlist/solver/nld_solver.cpp | 29 ++++----- src/lib/netlist/solver/nld_solver.h | 9 +-- src/lib/netlist/tools/nl_convert.cpp | 10 ++-- src/lib/netlist/tools/nl_convert.h | 6 +- 46 files changed, 288 insertions(+), 151 deletions(-) (limited to 'src/lib/netlist/plib/pfmtlog.h') diff --git a/src/lib/netlist/build/makefile b/src/lib/netlist/build/makefile index 45512d2beca..75aaed13889 100644 --- a/src/lib/netlist/build/makefile +++ b/src/lib/netlist/build/makefile @@ -14,14 +14,14 @@ VSBUILD = $(SRC)/buildVS DOC = $(SRC)/documentation TIDY_DB = ../compile_commands.json -TIDY_FLAGSX = -checks=*,-google*,-hicpp*,-readability*,-fuchsia*,-cert-*, +TIDY_FLAGSX = -checks=*,-google*,-hicpp*,-readability*,-fuchsia*,-cert-*,-android-*, TIDY_FLAGSX += -llvm-header-guard,-cppcoreguidelines-pro-type-reinterpret-cast, TIDY_FLAGSX += -cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-owning-memory, TIDY_FLAGSX += -modernize-use-default-member-init,-cppcoreguidelines-pro-bounds-constant-array-index, 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,-android-*,-cppcoreguidelines-avoid-magic-numbers, +#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 += -cppcoreguidelines-macro-usage, 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, @@ -33,6 +33,7 @@ space := space += TIDY_FLAGS = $(subst $(space),,$(TIDY_FLAGSX)) +#TIDY_FLAGS = -checks=llvm-include-order,llvm-namespace-comment,modernize-use-override,modernize-use-using -fix #TIDY_FLAGS = -checks=llvm-include-order -fix #TIDY_FLAGS = -checks=llvm-namespace-comment -fix #TIDY_FLAGS = -checks=modernize-use-override -fix @@ -235,7 +236,7 @@ native: $(MAKE) CEXTRAFLAGS="-march=native -Wall -Wpedantic -Wsign-compare -Wextra -Wno-unused-parameter" clang: - $(MAKE) CC=clang++-9 LD=clang++-9 CEXTRAFLAGS="-march=native -Wno-unused-parameter -Weverything -Werror -Wno-unreachable-code -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wconversion -Wno-c++98-compat -Wno-float-equal -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wweak-template-vtables -Wno-exit-time-destructors" + $(MAKE) CC=clang++-9 LD=clang++-9 CEXTRAFLAGS="-march=native -Wno-unused-parameter -Weverything -Werror -Wno-non-virtual-dtor -Wno-unreachable-code -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wconversion -Wno-c++98-compat -Wno-float-equal -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wweak-template-vtables -Wno-exit-time-destructors" clang-5: $(MAKE) CC=clang++-5.0 LD=clang++-5.0 CEXTRAFLAGS="-march=native -Weverything -Werror -Wno-inconsistent-missing-destructor-override -Wno-unreachable-code -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wconversion -Wno-c++98-compat -Wno-float-equal -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wno-weak-template-vtables -Wno-exit-time-destructors" diff --git a/src/lib/netlist/devices/nld_7448.cpp b/src/lib/netlist/devices/nld_7448.cpp index f14714de17c..14a1f12bfcc 100644 --- a/src/lib/netlist/devices/nld_7448.cpp +++ b/src/lib/netlist/devices/nld_7448.cpp @@ -5,6 +5,8 @@ * */ +#include + #include "nlid_truthtable.h" #include "nld_7448.h" @@ -135,7 +137,7 @@ namespace netlist #define BITS7(b6,b5,b4,b3,b2,b1,b0) ((b6)<<6) | ((b5)<<5) | ((b4)<<4) | ((b3)<<3) | ((b2)<<2) | ((b1)<<1) | ((b0)<<0) - static constexpr uint8_t tab7448[16] = + static constexpr std::array tab7448 = { BITS7( 1, 1, 1, 1, 1, 1, 0 ), /* 00 - not blanked ! */ BITS7( 0, 1, 1, 0, 0, 0, 0 ), /* 01 */ diff --git a/src/lib/netlist/devices/nld_7450.cpp b/src/lib/netlist/devices/nld_7450.cpp index 791ead0139f..a3e7e8d99cc 100644 --- a/src/lib/netlist/devices/nld_7450.cpp +++ b/src/lib/netlist/devices/nld_7450.cpp @@ -68,10 +68,10 @@ namespace netlist m_B.activate(); m_C.activate(); m_D.activate(); - unsigned t1 = m_A() & m_B(); - unsigned t2 = m_C() & m_D(); + auto t1 = m_A() & m_B(); + auto t2 = m_C() & m_D(); - const netlist_time times[2] = { NLTIME_FROM_NS(22), NLTIME_FROM_NS(15) }; + const netlist_time times[2] = { NLTIME_FROM_NS(15), NLTIME_FROM_NS(22) }; uint_fast8_t res = 0; if (t1 ^ 1) @@ -85,14 +85,16 @@ namespace netlist m_A.inactivate(); m_B.inactivate(); } - } else { + } + else + { if (t2 ^ 1) { m_C.inactivate(); m_D.inactivate(); } } - m_Q.push(res, times[1 - res]);// ? 22000 : 15000); + m_Q.push(res, times[res]);// ? 22000 : 15000); } NETLIB_DEVICE_IMPL(7450, "TTL_7450_ANDORINVERT", "+A,+B,+C,+D") diff --git a/src/lib/netlist/devices/nld_7490.cpp b/src/lib/netlist/devices/nld_7490.cpp index 7c710a8b941..585d8503777 100644 --- a/src/lib/netlist/devices/nld_7490.cpp +++ b/src/lib/netlist/devices/nld_7490.cpp @@ -120,7 +120,7 @@ namespace netlist m_last_B = new_B; } - NETLIB_FUNC_VOID(7490, update_outputs, (void)) + NETLIB_FUNC_VOID(7490, update_outputs, ()) { for (std::size_t i=0; i<4; i++) m_Q[i].push((m_cnt >> i) & 1, delay[i]); diff --git a/src/lib/netlist/devices/nld_am2847.cpp b/src/lib/netlist/devices/nld_am2847.cpp index 71e46e316f1..4ebc9ed27dc 100644 --- a/src/lib/netlist/devices/nld_am2847.cpp +++ b/src/lib/netlist/devices/nld_am2847.cpp @@ -116,7 +116,7 @@ namespace netlist /* do nothing */ } - NETLIB_FUNC_VOID(Am2847_shifter, shift, (void)) + NETLIB_FUNC_VOID(Am2847_shifter, shift, ()) { uint32_t out = m_buffer[0] & 1; uint32_t in = (m_RC() ? out : m_IN()); diff --git a/src/lib/netlist/devices/nlid_proxy.h b/src/lib/netlist/devices/nlid_proxy.h index f7eb2d7baa3..09a5da48c25 100644 --- a/src/lib/netlist/devices/nlid_proxy.h +++ b/src/lib/netlist/devices/nlid_proxy.h @@ -29,8 +29,6 @@ namespace netlist nld_base_proxy(netlist_state_t &anetlist, const pstring &name, logic_t *inout_proxied, detail::core_terminal_t *proxy_inout); - ~nld_base_proxy() override = default; - logic_t &term_proxied() const { return *m_term_proxied; } detail::core_terminal_t &proxy_term() const { return *m_proxy_term; } @@ -49,8 +47,6 @@ namespace netlist { public: - ~nld_base_a_to_d_proxy() override = default; - virtual logic_output_t &out() { return m_Q; } protected: @@ -69,8 +65,6 @@ namespace netlist public: nld_a_to_d_proxy(netlist_state_t &anetlist, const pstring &name, logic_input_t *in_proxied); - ~nld_a_to_d_proxy() override = default; - analog_input_t m_I; protected: @@ -88,7 +82,6 @@ namespace netlist NETLIB_OBJECT_DERIVED(base_d_to_a_proxy, base_proxy) { public: - ~nld_base_d_to_a_proxy() override = default; virtual logic_input_t &in() { return m_I; } @@ -105,7 +98,6 @@ namespace netlist { public: nld_d_to_a_proxy(netlist_state_t &anetlist, const pstring &name, logic_output_t *out_proxied); - ~nld_d_to_a_proxy() override = default; protected: diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index 2a1e4b3e66c..1c2c166dff4 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -28,7 +28,7 @@ namespace netlist { NETLIB_CONSTRUCTOR(netlistparams) , m_use_deactivate(*this, "USE_DEACTIVATE", false) - , m_startup_strategy(*this, "STARTUP_STRATEGY", 1) + , m_startup_strategy(*this, "STARTUP_STRATEGY", 0) { } NETLIB_UPDATEI() { } diff --git a/src/lib/netlist/devices/nlid_truthtable.h b/src/lib/netlist/devices/nlid_truthtable.h index af0fbcf329a..857f35d9bc0 100644 --- a/src/lib/netlist/devices/nlid_truthtable.h +++ b/src/lib/netlist/devices/nlid_truthtable.h @@ -219,8 +219,6 @@ namespace devices netlist_base_factory_truthtable_t(const pstring &name, const pstring &classname, const pstring &def_param, const pstring &sourcefile); - ~netlist_base_factory_truthtable_t() override = default; - std::vector m_desc; const logic_family_desc_t *m_family; }; diff --git a/src/lib/netlist/netlist_types.h b/src/lib/netlist/netlist_types.h index 9edd19e0ace..3aa7f3436ee 100644 --- a/src/lib/netlist/netlist_types.h +++ b/src/lib/netlist/netlist_types.h @@ -27,6 +27,7 @@ namespace netlist */ using netlist_sig_t = std::uint32_t; + /* FIXME: belongs into nl_base.h to nlstate */ /** * @brief Interface definition for netlist callbacks into calling code * @@ -38,10 +39,17 @@ namespace netlist class callbacks_t { public: + + callbacks_t() = default; + /* what is done before this is passed as a unique_ptr to netlist + * we should not limit. + */ virtual ~callbacks_t() = default; + COPYASSIGNMOVE(callbacks_t, default) /* logging callback */ virtual void vlog(const plib::plog_level &l, const pstring &ls) const = 0; + }; using log_type = plib::plog_base; diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 246077788d9..53ee4e83a8a 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -141,17 +141,13 @@ const logic_family_desc_t *family_CD4XXX() detail::queue_t::queue_t(netlist_state_t &nl) : timed_queue, false, NL_KEEP_STATISTICS>(512) , netlist_ref(nl) - , plib::state_manager_t::callback_t() +// , plib::state_manager_t::callback_t() , m_qsize(0) , m_times(512) , m_net_ids(512) { } -detail::queue_t::~queue_t() -{ -} - void detail::queue_t::register_state(plib::state_manager_t &manager, const pstring &module) { //state().log().debug("register_state\n"); diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 69ace67d9d7..62a5104a021 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -227,8 +227,6 @@ namespace netlist explicit nl_exception(const pstring &text //!< text to be passed ) : plib::pexception(text) { } - /*! Copy constructor. */ - nl_exception(const nl_exception &e) = default; }; /*! Logic families descriptors are used to create proxy devices. @@ -239,7 +237,10 @@ namespace netlist { public: logic_family_desc_t(); - virtual ~logic_family_desc_t() = default; + + COPYASSIGNMOVE(logic_family_desc_t, delete) + + virtual ~logic_family_desc_t() noexcept = default; virtual plib::owned_ptr create_d_a_proxy(netlist_state_t &anetlist, const pstring &name, logic_output_t *proxied) const = 0; @@ -279,12 +280,14 @@ namespace netlist public: logic_family_t() : m_logic_family(nullptr) {} + COPYASSIGNMOVE(logic_family_t, delete) + const logic_family_desc_t *logic_family() const { return m_logic_family; } void set_logic_family(const logic_family_desc_t *fam) { m_logic_family = fam; } protected: - ~logic_family_t() = default; // prohibit polymorphic destruction + ~logic_family_t() noexcept = default; // prohibit polymorphic destruction const logic_family_desc_t *m_logic_family; }; @@ -314,6 +317,9 @@ namespace netlist const pstring &name, //!< identifier/name for this state variable const T &value //!< Initial value after construction ); + + //! Destructor. + ~state_var() noexcept = default; //! Copy Constructor. constexpr state_var(const state_var &rhs) = default; //! Move Constructor. @@ -353,9 +359,13 @@ namespace netlist ); //! Copy Constructor. state_array(const state_array &rhs) NL_NOEXCEPT = default; + //! Destructor. + ~state_array() noexcept = default; //! Move Constructor. state_array(state_array &&rhs) NL_NOEXCEPT = default; state_array &operator=(const state_array &rhs) NL_NOEXCEPT = default; + state_array &operator=(state_array &&rhs) NL_NOEXCEPT = default; + state_array &operator=(const T &rhs) NL_NOEXCEPT { m_value = rhs; return *this; } T & operator[](const std::size_t i) NL_NOEXCEPT { return m_value[i]; } constexpr const T & operator[](const std::size_t i) const NL_NOEXCEPT { return m_value[i]; } @@ -390,7 +400,7 @@ namespace netlist * memory allocation to enhance locality. Please refer to \ref USE_MEMPOOL as * well. */ - class detail::object_t : public plib::nocopyassignmove + class detail::object_t { public: @@ -400,6 +410,7 @@ namespace netlist */ explicit object_t(const pstring &aname /*!< string containing name of the object */); + COPYASSIGNMOVE(object_t, delete) /*! return name of the object * * \returns name of the object. @@ -411,7 +422,7 @@ namespace netlist void * operator new (size_t size); void operator delete (void * mem); protected: - ~object_t() = default; // only childs should be destructible + ~object_t() noexcept = default; // only childs should be destructible private: //pstring m_name; @@ -426,6 +437,8 @@ namespace netlist { explicit netlist_ref(netlist_state_t &nl); + COPYASSIGNMOVE(netlist_ref, delete) + netlist_state_t & state() noexcept; const netlist_state_t & state() const noexcept; @@ -512,7 +525,9 @@ namespace netlist core_terminal_t(core_device_t &dev, const pstring &aname, const state_e state, nldelegate delegate = nldelegate()); - virtual ~core_terminal_t() = default; + virtual ~core_terminal_t() noexcept = default; + + COPYASSIGNMOVE(core_terminal_t, delete) /*! The object type. * \returns type of the object @@ -713,7 +728,10 @@ namespace netlist }; net_t(netlist_state_t &nl, const pstring &aname, core_terminal_t *mr = nullptr); - virtual ~net_t() = default; + + COPYASSIGNMOVE(net_t, delete) + + virtual ~net_t() noexcept = default; void reset(); @@ -916,6 +934,8 @@ namespace netlist param_t(device_t &device, const pstring &name); + COPYASSIGNMOVE(param_t, delete) + param_type_t param_type() const; protected: @@ -946,6 +966,7 @@ namespace netlist { public: param_num_t(device_t &device, const pstring &name, const T val); + const T operator()() const NL_NOEXCEPT { return m_param; } void setTo(const T ¶m) { set(m_param, param); } private: @@ -1086,7 +1107,9 @@ namespace netlist core_device_t(netlist_state_t &owner, const pstring &name); core_device_t(core_device_t &owner, const pstring &name); - virtual ~core_device_t() = default; + COPYASSIGNMOVE(core_device_t, delete) + + virtual ~core_device_t() noexcept = default; void do_inc_active() NL_NOEXCEPT { @@ -1155,6 +1178,8 @@ namespace netlist device_t(netlist_state_t &owner, const pstring &name); device_t(core_device_t &owner, const pstring &name); + COPYASSIGNMOVE(device_t, delete) + ~device_t() override = default; setup_t &setup(); @@ -1221,7 +1246,6 @@ namespace netlist public: using entry_t = pqentry_t; explicit queue_t(netlist_state_t &nl); - ~queue_t(); protected: @@ -1250,7 +1274,9 @@ namespace netlist std::unique_ptr &&callbacks, std::unique_ptr &&setup); - ~netlist_state_t() = default; + COPYASSIGNMOVE(netlist_state_t, delete) + + ~netlist_state_t() noexcept = default; friend class netlist_t; // allow access to private members @@ -1378,7 +1404,10 @@ namespace netlist public: explicit netlist_t(const pstring &aname, std::unique_ptr callbacks); - ~netlist_t() = default; + + COPYASSIGNMOVE(netlist_t, delete) + + ~netlist_t() noexcept = default; /* run functions */ diff --git a/src/lib/netlist/nl_factory.cpp b/src/lib/netlist/nl_factory.cpp index d66b61d5154..10fb54bdec0 100644 --- a/src/lib/netlist/nl_factory.cpp +++ b/src/lib/netlist/nl_factory.cpp @@ -52,11 +52,6 @@ namespace netlist { namespace factory { } - list_t::~list_t() - { - clear(); - } - void list_t::register_device(std::unique_ptr &&factory) { for (auto & e : *this) diff --git a/src/lib/netlist/nl_factory.h b/src/lib/netlist/nl_factory.h index ca0c266739e..6314c46d3fa 100644 --- a/src/lib/netlist/nl_factory.h +++ b/src/lib/netlist/nl_factory.h @@ -42,7 +42,7 @@ namespace factory { // net_dev class factory // ----------------------------------------------------------------------------- - class element_t : plib::nocopyassignmove + class element_t { public: element_t(const pstring &name, const pstring &classname, @@ -51,6 +51,8 @@ namespace factory { const pstring &def_param, const pstring &sourcefile); virtual ~element_t() = default; + COPYASSIGNMOVE(element_t, default) + virtual plib::owned_ptr Create(netlist_state_t &anetlist, const pstring &name) = 0; virtual void macro_actions(netlist_state_t &anetlist, const pstring &name) { @@ -91,7 +93,9 @@ namespace factory { { public: explicit list_t(setup_t &m_setup); - ~list_t(); + ~list_t() = default; + + COPYASSIGNMOVE(list_t, delete) template void register_device(const pstring &name, const pstring &classname, diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index cfc9a7eb484..282b49697b9 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -34,14 +34,14 @@ setup_t::setup_t(netlist_t &netlist) { } -setup_t::~setup_t() +setup_t::~setup_t() noexcept { + // FIXME: can't see a need any longer m_links.clear(); m_alias.clear(); m_params.clear(); m_terminals.clear(); m_param_values.clear(); - m_sources.clear(); } diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 971f8d2e91d..07dbdb887e6 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -140,6 +140,7 @@ namespace netlist struct tt_desc { + tt_desc() : ni(0), no(0) { } pstring name; pstring classname; unsigned long ni; @@ -187,7 +188,9 @@ namespace netlist : m_setup(setup), m_type(type) {} - virtual ~source_t() = default; + COPYASSIGNMOVE(source_t, delete) + + virtual ~source_t() noexcept = default; virtual bool parse(const pstring &name); setup_t &setup() { return m_setup; } @@ -206,15 +209,16 @@ namespace netlist // ---------------------------------------------------------------------------------------- - class setup_t : plib::nocopyassignmove + class setup_t { public: using link_t = std::pair; explicit setup_t(netlist_t &netlist); - ~setup_t(); + ~setup_t() noexcept; + COPYASSIGNMOVE(setup_t, delete) netlist_state_t &netlist(); const netlist_state_t &netlist() const; diff --git a/src/lib/netlist/nl_time.h b/src/lib/netlist/nl_time.h index 76e572a4772..6bd61a3f68e 100644 --- a/src/lib/netlist/nl_time.h +++ b/src/lib/netlist/nl_time.h @@ -30,6 +30,8 @@ namespace netlist constexpr ptime() noexcept : m_time(0) {} + ~ptime() noexcept = default; + constexpr ptime(const ptime &rhs) noexcept = default; constexpr ptime(ptime &&rhs) noexcept = default; constexpr explicit ptime(const internal_type &time) noexcept : m_time(time) {} diff --git a/src/lib/netlist/plib/mat_cr.h b/src/lib/netlist/plib/mat_cr.h index ff08ce9413d..827f9a6c270 100644 --- a/src/lib/netlist/plib/mat_cr.h +++ b/src/lib/netlist/plib/mat_cr.h @@ -22,6 +22,7 @@ #include "pconfig.h" #include "pomp.h" #include "pstate.h" +#include "ptypes.h" #include "putil.h" namespace plib @@ -33,6 +34,8 @@ namespace plib using index_type = C; using value_type = T; + COPYASSIGNMOVE(matrix_compressed_rows_t, default) + enum constants_e { FILL_INFINITY = 9999999 diff --git a/src/lib/netlist/plib/palloc.cpp b/src/lib/netlist/plib/palloc.cpp index ab5b14d0618..4115a450a40 100644 --- a/src/lib/netlist/plib/palloc.cpp +++ b/src/lib/netlist/plib/palloc.cpp @@ -9,6 +9,7 @@ #include "palloc.h" #include "pexception.h" #include "pfmtlog.h" +#include "pstream.h" #include @@ -28,7 +29,7 @@ mempool::~mempool() { if (b->m_num_alloc != 0) { - fprintf(stderr, "Found block with %d dangling allocations\n", static_cast(b->m_num_alloc)); + perrlogger("Found block with {} dangling allocations\n", b->m_num_alloc); } ::operator delete(b->data); } diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h index e8d82277ed9..b837455095c 100644 --- a/src/lib/netlist/plib/palloc.h +++ b/src/lib/netlist/plib/palloc.h @@ -9,6 +9,7 @@ #define PALLOC_H_ #include "pstring.h" +#include "ptypes.h" #include #include @@ -92,6 +93,15 @@ public: r.m_ptr = nullptr; } + owned_ptr &operator=(owned_ptr &&r) noexcept + { + m_is_owned = r.m_is_owned; + m_ptr = r.m_ptr; + r.m_is_owned = false; + r.m_ptr = nullptr; + return *this; + } + template owned_ptr(owned_ptr &&r) noexcept { @@ -169,6 +179,9 @@ private: public: mempool(size_t min_alloc, size_t min_align); + + COPYASSIGNMOVE(mempool, delete) + ~mempool(); void *alloc(size_t size); diff --git a/src/lib/netlist/plib/pchrono.h b/src/lib/netlist/plib/pchrono.h index e982dec535b..8ce0eca23b3 100644 --- a/src/lib/netlist/plib/pchrono.h +++ b/src/lib/netlist/plib/pchrono.h @@ -9,6 +9,7 @@ #define PCHRONO_H_ #include "pconfig.h" +#include "ptypes.h" #include #include @@ -175,10 +176,11 @@ namespace chrono { struct guard_t { guard_t() = delete; - guard_t(const guard_t &g) noexcept = default; - guard_t(guard_t &&g) noexcept = default; guard_t(timer &m) noexcept : m_m(m) { m_m.m_time -= T::start(); } ~guard_t() { m_m.m_time += T::stop(); ++m_m.m_count; } + + COPYASSIGNMOVE(guard_t, default) + private: timer &m_m; }; @@ -212,8 +214,7 @@ namespace chrono { struct guard_t { guard_t() = default; - guard_t(const guard_t &g) noexcept = default; - guard_t(guard_t &&g) noexcept = default; + COPYASSIGNMOVE(guard_t, default) /* using default constructor will trigger warning on * unused local variable. */ diff --git a/src/lib/netlist/plib/pdynlib.h b/src/lib/netlist/plib/pdynlib.h index 0ab498436b3..fe9db58d6f2 100644 --- a/src/lib/netlist/plib/pdynlib.h +++ b/src/lib/netlist/plib/pdynlib.h @@ -8,18 +8,21 @@ #define PDYNLIB_H_ #include "pstring.h" +#include "ptypes.h" namespace plib { // ---------------------------------------------------------------------------------------- // pdynlib: dynamic loading of libraries ... // ---------------------------------------------------------------------------------------- -class dynlib +class dynlib : public nocopyassignmove { public: explicit dynlib(const pstring libname); dynlib(const pstring path, const pstring libname); + ~dynlib(); + COPYASSIGNMOVE(dynlib, delete) bool isLoaded() const; diff --git a/src/lib/netlist/plib/pexception.h b/src/lib/netlist/plib/pexception.h index 7c798112c69..ed0d14f5747 100644 --- a/src/lib/netlist/plib/pexception.h +++ b/src/lib/netlist/plib/pexception.h @@ -87,10 +87,13 @@ static constexpr unsigned FP_ALL = 0x0001f; * Catch SIGFPE on linux for debugging purposes. */ -class fpsignalenabler : public nocopyassignmove +class fpsignalenabler { public: explicit fpsignalenabler(unsigned fpexceptions); + + COPYASSIGNMOVE(fpsignalenabler, delete) + ~fpsignalenabler(); /* is the functionality supported ? */ diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h index bf9d45fadd2..4c01f96dba7 100644 --- a/src/lib/netlist/plib/pfmtlog.h +++ b/src/lib/netlist/plib/pfmtlog.h @@ -157,8 +157,9 @@ public: : m_str(fmt), m_arg(0) { } - pfmt(const pfmt &rhs) = default; - ~pfmt() = default; + COPYASSIGNMOVE(pfmt, default) + + ~pfmt() noexcept = default; operator pstring() const { return m_str; } // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) @@ -215,11 +216,13 @@ private: }; template -class pfmt_writer_t : plib::nocopyassignmove +class pfmt_writer_t { public: explicit pfmt_writer_t() : m_enabled(true) { } + COPYASSIGNMOVE(pfmt_writer_t, delete) + /* runtime enable */ template void log(const pstring & fmt, Args&&... args) const @@ -249,7 +252,7 @@ public: bool is_enabled() const { return m_enabled; } protected: - ~pfmt_writer_t() = default; + ~pfmt_writer_t() noexcept = default; private: pfmt &xlog(pfmt &fmt) const { return fmt; } @@ -270,7 +273,10 @@ class plog_channel : public pfmt_writer_t, bui friend class pfmt_writer_t, build_enabled>; public: explicit plog_channel(T &b) : pfmt_writer_t(), m_base(b) { } - ~plog_channel() = default; + + COPYASSIGNMOVE(plog_channel, delete) + + ~plog_channel() noexcept = default; protected: void vdowrite(const pstring &ls) const @@ -295,7 +301,9 @@ public: error(proxy), fatal(proxy) {} - virtual ~plog_base() = default; + + COPYASSIGNMOVE(plog_base, default) + virtual ~plog_base() noexcept = default; plog_channel debug; plog_channel info; diff --git a/src/lib/netlist/plib/plists.h b/src/lib/netlist/plib/plists.h index 9cdca8813a0..46a679cc81b 100644 --- a/src/lib/netlist/plib/plists.h +++ b/src/lib/netlist/plib/plists.h @@ -12,6 +12,8 @@ #include "pstring.h" +#include +#include #include namespace plib { @@ -34,6 +36,7 @@ public: uninitialised_array_t() = default; + COPYASSIGNMOVE(uninitialised_array_t, delete) ~uninitialised_array_t() { for (std::size_t i=0; i::type m_buf[N]; + std::array::type, N> m_buf; }; // ---------------------------------------------------------------------------------------- @@ -180,14 +183,12 @@ public: friend class linkedlist_t; constexpr element_t() : m_next(nullptr), m_prev(nullptr) {} - constexpr element_t(const element_t &rhs) = delete; - constexpr element_t(element_t &&rhs) = delete; + ~element_t() noexcept = default; + + COPYASSIGNMOVE(element_t, delete) constexpr LC *next() const noexcept { return m_next; } constexpr LC *prev() const noexcept { return m_prev; } - - protected: - ~element_t() = default; private: LC * m_next; LC * m_prev; @@ -205,6 +206,9 @@ public: 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 {iter_t tmp(*this); operator++(); return tmp;} + + ~iter_t() = default; + constexpr bool operator==(const iter_t& rhs) const noexcept {return p == rhs.p;} constexpr bool operator!=(const iter_t& rhs) const noexcept {return p != rhs.p;} /* constexpr */ LC& operator*() noexcept {return *p;} diff --git a/src/lib/netlist/plib/pmain.h b/src/lib/netlist/plib/pmain.h index 04a8dd0bc53..e6fb0bd60d5 100644 --- a/src/lib/netlist/plib/pmain.h +++ b/src/lib/netlist/plib/pmain.h @@ -36,6 +36,9 @@ namespace plib { { public: app(); + + COPYASSIGNMOVE(app, delete) + virtual ~app() = default; virtual pstring usage() = 0; diff --git a/src/lib/netlist/plib/poptions.cpp b/src/lib/netlist/plib/poptions.cpp index cd40c5d5492..2a58eaab0f4 100644 --- a/src/lib/netlist/plib/poptions.cpp +++ b/src/lib/netlist/plib/poptions.cpp @@ -62,11 +62,6 @@ namespace plib { } } - options::~options() - { - m_opts.clear(); - } - void options::register_option(option_base *opt) { m_opts.push_back(opt); diff --git a/src/lib/netlist/plib/poptions.h b/src/lib/netlist/plib/poptions.h index 091adfb6d8f..23319604052 100644 --- a/src/lib/netlist/plib/poptions.h +++ b/src/lib/netlist/plib/poptions.h @@ -27,6 +27,8 @@ public: option_base(options &parent, pstring help); virtual ~option_base() = default; + COPYASSIGNMOVE(option_base, delete) + pstring help() const { return m_help; } private: pstring m_help; @@ -217,15 +219,13 @@ public: {} }; -class options +class options : public nocopyassignmove { public: options(); explicit options(option **o); - ~options(); - void register_option(option_base *opt); int parse(int argc, char **argv); diff --git a/src/lib/netlist/plib/pparser.h b/src/lib/netlist/plib/pparser.h index 9b68a5524f1..9803fae9cb8 100644 --- a/src/lib/netlist/plib/pparser.h +++ b/src/lib/netlist/plib/pparser.h @@ -17,7 +17,7 @@ namespace plib { -class ptokenizer : public nocopyassignmove +class ptokenizer { public: template @@ -26,6 +26,8 @@ public: { } + COPYASSIGNMOVE(ptokenizer, delete) + virtual ~ptokenizer() = default; enum token_type @@ -183,6 +185,10 @@ public: return *this; } + COPYASSIGN(ppreprocessor, delete) + ppreprocessor &operator=(ppreprocessor &&src) = delete; + + ppreprocessor(ppreprocessor &&s) noexcept : m_defines(std::move(s.m_defines)) , m_expr_sep(std::move(s.m_expr_sep)) diff --git a/src/lib/netlist/plib/pstate.h b/src/lib/netlist/plib/pstate.h index 290333bf87d..cdb6ea94dc8 100644 --- a/src/lib/netlist/plib/pstate.h +++ b/src/lib/netlist/plib/pstate.h @@ -47,7 +47,7 @@ public: std::is_floating_point::value); } - class callback_t : nocopyassignmove + class callback_t { public: using list_t = std::vector; @@ -56,7 +56,9 @@ public: virtual void on_pre_save(state_manager_t &manager) = 0; virtual void on_post_load(state_manager_t &manager) = 0; protected: - virtual ~callback_t() = default; + callback_t() = default; + ~callback_t() = default; + COPYASSIGNMOVE(callback_t, default) }; struct entry_t @@ -70,8 +72,6 @@ public: entry_t(const pstring &stname, const void *owner, callback_t *callback) : m_name(stname), m_dt(datatype_t(true)), m_owner(owner), m_callback(callback), m_count(0), m_ptr(nullptr) { } - ~entry_t() = default; - pstring m_name; const datatype_t m_dt; const void * m_owner; @@ -81,7 +81,6 @@ public: }; state_manager_t() = default; - ~state_manager_t() = default; template void save_item(const void *owner, C &state, const pstring &stname) diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h index 2492d01d141..17a5f2702a4 100644 --- a/src/lib/netlist/plib/pstream.h +++ b/src/lib/netlist/plib/pstream.h @@ -41,7 +41,7 @@ typedef std::ostringstream pomemstream; // pstream: things common to all streams // ----------------------------------------------------------------------------- -class pstream : public nocopyassign +class pstream { public: @@ -50,6 +50,9 @@ public: static constexpr pos_type SEEK_EOF = static_cast(-1); + COPYASSIGN(pstream, delete) + pstream &operator=(pstream &&) noexcept = delete; + bool seekable() const { return ((m_flags & FLAG_SEEKABLE) != 0); } void seekp(const pos_type n) @@ -69,9 +72,8 @@ protected: explicit pstream(const unsigned flags) : m_flags(flags) { } - pstream(pstream &&src) noexcept : m_flags(src.m_flags) - { - } + pstream(pstream &&src) noexcept = default; + virtual ~pstream() = default; virtual void vseek(const pos_type n) = 0; @@ -105,6 +107,11 @@ public: using value_type = T; + ~pistream_base() noexcept override = default; + + COPYASSIGN(pistream_base, delete) + pistream_base &operator=(pistream_base &&src) noexcept = delete; + bool eof() const { return ((flags() & FLAG_EOF) != 0); } pos_type read(T *buf, const pos_type n) @@ -116,6 +123,7 @@ protected: pistream_base() : pstream(0) {} explicit pistream_base(const unsigned flags) : pstream(flags) {} pistream_base(pistream_base &&src) noexcept : pstream(std::move(src)) {} + /* read up to n bytes from stream */ virtual size_type vread(T *buf, const size_type n) = 0; }; @@ -134,6 +142,12 @@ public: using value_type = T; + postream_base() = default; + ~postream_base() noexcept override = default; + + COPYASSIGN(postream_base, delete) + postream_base &operator=(postream_base &&src) noexcept = delete; + void write(const T *buf, const size_type n) { vwrite(buf, n); @@ -142,6 +156,7 @@ public: protected: explicit postream_base(unsigned flags) : pstream(flags) {} postream_base(postream_base &&src) noexcept : pstream(std::move(src)) {} + /* write n bytes to stream */ virtual void vwrite(const T *buf, const size_type n) = 0; @@ -160,6 +175,8 @@ public: pomemstream(); + COPYASSIGN(pomemstream, delete) + pomemstream(pomemstream &&src) noexcept : postream(std::move(src)) , m_pos(src.m_pos) @@ -169,6 +186,7 @@ public: { src.m_mem = nullptr; } + pomemstream &operator=(pomemstream &&src) = delete; ~pomemstream() override; @@ -198,6 +216,9 @@ public: , m_buf(std::move(src.m_buf)) { src.m_buf = ""; } + COPYASSIGN(postringstream, delete) + postringstream &operator=(postringstream &&src) = delete; + ~postringstream() override = default; const pstring &str() { return m_buf; } @@ -234,6 +255,8 @@ public: src.m_file = nullptr; src.m_actually_close = false; } + COPYASSIGN(pofilestream, delete) + pofilestream &operator=(pofilestream &&src) = delete; ~pofilestream() override; @@ -262,6 +285,11 @@ class pstderr : public pofilestream { public: pstderr(); + pstderr(pstderr &&src) noexcept = default; + pstderr &operator=(pstderr &&src) = delete; + COPYASSIGN(pstderr, delete) + + ~pstderr() noexcept override= default; }; // ----------------------------------------------------------------------------- @@ -272,6 +300,11 @@ class pstdout : public pofilestream { public: pstdout(); + pstdout(pstdout &&src) noexcept = default; + pstdout &operator=(pstdout &&src) = delete; + COPYASSIGN(pstdout, delete) + + ~pstdout() noexcept override = default; }; // ----------------------------------------------------------------------------- @@ -295,6 +328,8 @@ public: src.m_actually_close = false; src.m_file = nullptr; } + COPYASSIGN(pifilestream, delete) + pifilestream &operator=(pifilestream &&src) = delete; protected: pifilestream(void *file, const pstring &name, const bool do_close); @@ -322,6 +357,9 @@ class pstdin : public pifilestream public: pstdin(); + pstdin(pstdin &&src) noexcept = default; + pstdin &operator=(pstdin &&src) = delete; + COPYASSIGN(pstdin, delete) ~pstdin() override = default; }; @@ -344,6 +382,8 @@ public: { src.m_mem = nullptr; } + COPYASSIGN(pimemstream, delete) + pimemstream &operator=(pimemstream &&src) = delete; explicit pimemstream(const pomemstream &ostrm); @@ -387,6 +427,9 @@ public: { set_mem(m_str.c_str(), std::strlen(m_str.c_str())); } + COPYASSIGN(pistringstream, delete) + pistringstream &operator=(pistringstream &&src) = delete; + ~pistringstream() override = default; private: @@ -407,17 +450,20 @@ struct constructor_helper std::unique_ptr operator()(T &&s) { return std::move(plib::make_unique(std::move(s))); } }; -class putf8_reader : plib::nocopyassign +// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) +class putf8_reader { public: + COPYASSIGN(putf8_reader, delete) + putf8_reader &operator=(putf8_reader &&src) = delete; virtual ~putf8_reader() = default; template friend struct constructor_helper; template - putf8_reader(T &&strm) // NOLINT(misc-forwarding-reference-overload, bugprone-forwarding-reference-overload) + putf8_reader(T &&strm) // NOLINT(cppcoreguidelines-special-member-functions, misc-forwarding-reference-overload, bugprone-forwarding-reference-overload) : m_strm(std::move(constructor_helper()(std::move(strm)))) // NOLINT(bugprone-move-forwarding-reference) {} @@ -464,12 +510,16 @@ struct constructor_helper> // putf8writer_t: writer on top of ostream // ----------------------------------------------------------------------------- -class putf8_writer : plib::nocopyassign +class putf8_writer { public: explicit putf8_writer(postream *strm) : m_strm(strm) {} putf8_writer(putf8_writer &&src) noexcept : m_strm(src.m_strm) {} + + COPYASSIGN(putf8_writer, delete) + putf8_writer &operator=(putf8_writer &&src) = delete; + virtual ~putf8_writer() = default; void writeline(const pstring &line) const @@ -504,6 +554,8 @@ public: { } + COPYASSIGNMOVE(putf8_fmt_writer, delete) + ~putf8_fmt_writer() override = default; //protected: @@ -516,11 +568,15 @@ private: // pbinary_writer_t: writer on top of ostream // ----------------------------------------------------------------------------- -class pbinary_writer : public plib::nocopyassign +class pbinary_writer { public: explicit pbinary_writer(postream &strm) : m_strm(strm) {} pbinary_writer(pbinary_writer &&src) noexcept : m_strm(src.m_strm) {} + + COPYASSIGN(pbinary_writer, delete) + postringstream &operator=(pbinary_writer &&src) = delete; + virtual ~pbinary_writer() = default; template @@ -549,11 +605,15 @@ private: postream &m_strm; }; -class pbinary_reader : public plib::nocopyassign +class pbinary_reader { public: explicit pbinary_reader(pistream &strm) : m_strm(strm) {} pbinary_reader(pbinary_reader &&src) noexcept : m_strm(src.m_strm) { } + + COPYASSIGN(pbinary_reader, delete) + pbinary_reader &operator=(pbinary_reader &&src) = delete; + virtual ~pbinary_reader() = default; template @@ -594,6 +654,22 @@ inline void copystream(postream &dest, pistream &src) dest.write(buf.data(), r); } +struct perrlogger +{ + template + perrlogger(Args&& ... args) + { + h()(std::forward(args)...); + } +private: + static putf8_fmt_writer &h() + { + static plib::pstderr perr_strm; + static plib::putf8_fmt_writer perr(&perr_strm); + return perr; + } +}; + } // namespace plib diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h index 6625ddb11f9..c490ffa019e 100644 --- a/src/lib/netlist/plib/pstring.h +++ b/src/lib/netlist/plib/pstring.h @@ -92,7 +92,7 @@ public: // simple construction/destruction pstring_t() = default; - ~pstring_t() = default; + ~pstring_t() noexcept = default; // FIXME: Do something with encoding pstring_t(const mem_t *string) @@ -115,13 +115,15 @@ public: m_str.assign(string, N - 1); } - pstring_t(const pstring_t &string) = default; explicit pstring_t(const string_type &string) : m_str(string) { } + pstring_t(const pstring_t &string) = default; pstring_t(pstring_t &&string) noexcept = default; + pstring_t &operator=(const pstring_t &string) = default; + pstring_t &operator=(pstring_t &&string) noexcept = default; explicit pstring_t(code_t code) { @@ -139,8 +141,6 @@ public: operator string_type () const { return m_str; } - pstring_t &operator=(const pstring_t &string) = default; - pstring_t &operator=(pstring_t &&string) noexcept = default; template ::value>::type> diff --git a/src/lib/netlist/plib/ptypes.h b/src/lib/netlist/plib/ptypes.h index 07a48b03b93..5e0f8d49fe3 100644 --- a/src/lib/netlist/plib/ptypes.h +++ b/src/lib/netlist/plib/ptypes.h @@ -14,6 +14,16 @@ #include "pconfig.h" +#define COPYASSIGNMOVE(name, def) \ + name(const name &) = def; \ + name(name &&) noexcept = def; \ + name &operator=(const name &) = def; \ + name &operator=(name &&) noexcept = def; + +#define COPYASSIGN(name, def) \ + name(const name &) = def; \ + name &operator=(const name &) = def; \ + namespace plib { template struct is_integral : public std::is_integral { }; diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index e9011b698a4..81ef785daee 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -172,8 +172,6 @@ public: { } - ~netlist_tool_t() = default; - void init() { } diff --git a/src/lib/netlist/prg/nlwav.cpp b/src/lib/netlist/prg/nlwav.cpp index d48294b6aa9..96cf9342058 100644 --- a/src/lib/netlist/prg/nlwav.cpp +++ b/src/lib/netlist/prg/nlwav.cpp @@ -34,6 +34,9 @@ public: write(m_fmt); write(m_data); } + + COPYASSIGNMOVE(wav_t, delete) + ~wav_t() { if (m_f.seekable()) diff --git a/src/lib/netlist/solver/nld_matrix_solver.h b/src/lib/netlist/solver/nld_matrix_solver.h index a57ea029140..63be2d4892a 100644 --- a/src/lib/netlist/solver/nld_matrix_solver.h +++ b/src/lib/netlist/solver/nld_matrix_solver.h @@ -114,7 +114,6 @@ public: : analog_output_t(dev, aname) , m_proxied_net(pnet) { } - ~proxied_analog_output_t() override = default; analog_net_t *proxied_net() const { return m_proxied_net;} private: @@ -136,8 +135,6 @@ public: PREFER_BAND_MATRIX }; - ~matrix_solver_t() override = default; - void setup(analog_net_t::list_t &nets) { vsetup(nets); diff --git a/src/lib/netlist/solver/nld_ms_direct.h b/src/lib/netlist/solver/nld_ms_direct.h index fe4a4e6aada..13f187f41b5 100644 --- a/src/lib/netlist/solver/nld_ms_direct.h +++ b/src/lib/netlist/solver/nld_ms_direct.h @@ -32,8 +32,6 @@ public: matrix_solver_direct_t(netlist_state_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size); matrix_solver_direct_t(netlist_state_t &anetlist, const pstring &name, const eSortType sort, const solver_parameters_t *params, const std::size_t size); - ~matrix_solver_direct_t() override = default; - void vsetup(analog_net_t::list_t &nets) override; void reset() override { matrix_solver_t::reset(); } diff --git a/src/lib/netlist/solver/nld_ms_gcr.h b/src/lib/netlist/solver/nld_ms_gcr.h index 8c9d40e9618..8d1351435c8 100644 --- a/src/lib/netlist/solver/nld_ms_gcr.h +++ b/src/lib/netlist/solver/nld_ms_gcr.h @@ -44,8 +44,6 @@ public: { } - ~matrix_solver_GCR_t() override = default; - constexpr std::size_t N() const { return m_dim; } void vsetup(analog_net_t::list_t &nets) override; @@ -55,8 +53,7 @@ public: private: - //typedef typename mat_cr_t::type mattype; - typedef typename plib::matrix_compressed_rows_t::index_type mat_index_type; + using mat_index_type = typename plib::matrix_compressed_rows_t::index_type; void csc_private(plib::putf8_fmt_writer &strm); diff --git a/src/lib/netlist/solver/nld_ms_gmres.h b/src/lib/netlist/solver/nld_ms_gmres.h index 28087b6b0a5..3cd88dea429 100644 --- a/src/lib/netlist/solver/nld_ms_gmres.h +++ b/src/lib/netlist/solver/nld_ms_gmres.h @@ -44,8 +44,6 @@ namespace devices { } - ~matrix_solver_GMRES_t() override = default; - void vsetup(analog_net_t::list_t &nets) override; unsigned vsolve_non_dynamic(const bool newton_raphson) override; diff --git a/src/lib/netlist/solver/nld_ms_sm.h b/src/lib/netlist/solver/nld_ms_sm.h index 52546210cad..c473b6131e7 100644 --- a/src/lib/netlist/solver/nld_ms_sm.h +++ b/src/lib/netlist/solver/nld_ms_sm.h @@ -59,8 +59,6 @@ public: matrix_solver_sm_t(netlist_state_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size); - ~matrix_solver_sm_t() override = default; - void vsetup(analog_net_t::list_t &nets) override; void reset() override { matrix_solver_t::reset(); } diff --git a/src/lib/netlist/solver/nld_ms_sor.h b/src/lib/netlist/solver/nld_ms_sor.h index dd2372dd48f..5261524cba1 100644 --- a/src/lib/netlist/solver/nld_ms_sor.h +++ b/src/lib/netlist/solver/nld_ms_sor.h @@ -39,8 +39,6 @@ public: { } - ~matrix_solver_SOR_t() override = default; - void vsetup(analog_net_t::list_t &nets) override; unsigned vsolve_non_dynamic(const bool newton_raphson) override; diff --git a/src/lib/netlist/solver/nld_ms_sor_mat.h b/src/lib/netlist/solver/nld_ms_sor_mat.h index 38ce84dfb93..0bb756c05f5 100644 --- a/src/lib/netlist/solver/nld_ms_sor_mat.h +++ b/src/lib/netlist/solver/nld_ms_sor_mat.h @@ -40,8 +40,6 @@ public: { } - ~matrix_solver_SOR_mat_t() override = default; - void vsetup(analog_net_t::list_t &nets) override; unsigned vsolve_non_dynamic(const bool newton_raphson) override; diff --git a/src/lib/netlist/solver/nld_ms_w.h b/src/lib/netlist/solver/nld_ms_w.h index cdfcaf3000f..e5935462f03 100644 --- a/src/lib/netlist/solver/nld_ms_w.h +++ b/src/lib/netlist/solver/nld_ms_w.h @@ -65,8 +65,6 @@ public: matrix_solver_w_t(netlist_state_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size); - ~matrix_solver_w_t() override = default; - void vsetup(analog_net_t::list_t &nets) override; void reset() override { matrix_solver_t::reset(); } @@ -293,7 +291,7 @@ unsigned matrix_solver_w_t::solve_non_dynamic(const bool newton_raphso for (unsigned i = 0; i < rowcount; i++) { if (H[i][i] == 0.0) - printf("%s H singular\n", this->name().c_str()); + plib::perrlogger("{} H singular\n", this->name()); const float_type f = 1.0 / H[i][i]; for (unsigned j = i+1; j < rowcount; j++) { @@ -348,7 +346,7 @@ unsigned matrix_solver_w_t::solve_non_dynamic(const bool newton_raphso tmp += A(i,j) * new_V[j]; } if (std::abs(tmp-RHS(i)) > 1e-6) - printf("%s failed on row %d: %f RHS: %f\n", this->name().c_str(), i, std::abs(tmp-RHS(i)), RHS(i)); + plib::perrlogger("{} failed on row {}: {} RHS: {}\n", this->name(), i, std::abs(tmp-RHS(i)), RHS(i)); } const float_type err = (newton_raphson ? delta(new_V) : 0.0); diff --git a/src/lib/netlist/solver/nld_solver.cpp b/src/lib/netlist/solver/nld_solver.cpp index 45643d88ea5..5d17056637a 100644 --- a/src/lib/netlist/solver/nld_solver.cpp +++ b/src/lib/netlist/solver/nld_solver.cpp @@ -33,6 +33,7 @@ #include #include // <<= needed by windows build +#include #include "../nl_lists.h" @@ -80,14 +81,6 @@ void NETLIB_NAME(solver)::stop() s->log_stats(); } -NETLIB_NAME(solver)::~NETLIB_NAME(solver)() -{ - for (auto &s : m_mat_solvers) - { - plib::pfree(s); - } -} - NETLIB_UPDATE(solver) { if (m_params.m_dynamic_ts) @@ -100,7 +93,7 @@ NETLIB_UPDATE(solver) std::size_t nthreads = std::min(static_cast(m_parallel()), plib::omp::get_max_threads()); - std::vector &solvers = (force_solve ? m_mat_solvers : m_mat_solvers_timestepping); + std::vector &solvers = (force_solve ? m_mat_solvers_all : m_mat_solvers_timestepping); if (nthreads > 1 && solvers.size() > 1) { @@ -129,13 +122,13 @@ NETLIB_UPDATE(solver) } template -matrix_solver_t * create_it(netlist_state_t &nl, pstring name, solver_parameters_t ¶ms, std::size_t size) +std::unique_ptr create_it(netlist_state_t &nl, pstring name, solver_parameters_t ¶ms, std::size_t size) { - return plib::palloc(nl, name, ¶ms, size); + return plib::make_unique(nl, name, ¶ms, size); } template -matrix_solver_t * NETLIB_NAME(solver)::create_solver(std::size_t size, const pstring &solvername) +std::unique_ptr NETLIB_NAME(solver)::create_solver(std::size_t size, const pstring &solvername) { if (m_method() == "SOR_MAT") { @@ -283,7 +276,7 @@ void NETLIB_NAME(solver)::post_start() log().verbose("Found {1} net groups in {2} nets\n", splitter.groups.size(), state().nets().size()); for (auto & grp : splitter.groups) { - matrix_solver_t *ms; + std::unique_ptr ms; std::size_t net_count = grp.size(); pstring sname = plib::pfmt("Solver_{1}")(m_mat_solvers.size()); @@ -292,13 +285,13 @@ void NETLIB_NAME(solver)::post_start() #if 1 case 1: if (use_specific) - ms = plib::palloc>(state(), sname, &m_params); + ms = plib::make_unique>(state(), sname, &m_params); else ms = create_solver(1, sname); break; case 2: if (use_specific) - ms = plib::palloc>(state(), sname, &m_params); + ms = plib::make_unique>(state(), sname, &m_params); else ms = create_solver(2, sname); break; @@ -403,9 +396,11 @@ void NETLIB_NAME(solver)::post_start() } } - m_mat_solvers.push_back(ms); + m_mat_solvers_all.push_back(ms.get()); if (ms->has_timestep_devices()) - m_mat_solvers_timestepping.push_back(ms); + m_mat_solvers_timestepping.push_back(ms.get()); + + m_mat_solvers.emplace_back(std::move(ms)); } } diff --git a/src/lib/netlist/solver/nld_solver.h b/src/lib/netlist/solver/nld_solver.h index f9156c4441f..4bc4aea3d60 100644 --- a/src/lib/netlist/solver/nld_solver.h +++ b/src/lib/netlist/solver/nld_solver.h @@ -9,6 +9,8 @@ #define NLD_SOLVER_H_ #include +#include +#include #include "../nl_base.h" #include "../plib/pstream.h" @@ -63,8 +65,6 @@ NETLIB_OBJECT(solver) connect(m_fb_step, m_Q_step); } - ~NETLIB_NAME(solver)() override; - void post_start(); void stop(); @@ -97,13 +97,14 @@ protected: param_logic_t m_log_stats; private: - std::vector m_mat_solvers; + std::vector> m_mat_solvers; + std::vector m_mat_solvers_all; std::vector m_mat_solvers_timestepping; solver_parameters_t m_params; template - matrix_solver_t * create_solver(std::size_t size, const pstring &solvername); + std::unique_ptr create_solver(std::size_t size, const pstring &solvername); }; } //namespace devices diff --git a/src/lib/netlist/tools/nl_convert.cpp b/src/lib/netlist/tools/nl_convert.cpp index fccab6e6df2..68880e379a3 100644 --- a/src/lib/netlist/tools/nl_convert.cpp +++ b/src/lib/netlist/tools/nl_convert.cpp @@ -201,7 +201,7 @@ double nl_convert_base_t::get_sp_unit(const pstring &unit) return m_units[i].m_mult; i++; } - fprintf(stderr, "Unit %s unknown\n", unit.c_str()); + plib::perrlogger("Unit {} unknown\n", unit); return 0.0; } @@ -250,10 +250,10 @@ void nl_convert_spice_t::convert(const pstring &contents) pstring line = ""; - for (std::size_t i=0; i < spnl.size(); i++) + for (const auto &i : spnl) { // Basic preprocessing - pstring inl = plib::ucase(plib::trim(spnl[i])); + pstring inl = plib::ucase(plib::trim(i)); if (plib::startsWith(inl, "+")) line = line + inl.substr(1); else @@ -316,7 +316,7 @@ void nl_convert_spice_t::process_line(const pstring &line) if (m.size() == 2) { if (m[1].length() != 4) - fprintf(stderr, "error with model desc %s\n", model.c_str()); + plib::perrlogger("error with model desc {}\n", model); pins = plib::left(m[1], 3); } add_device("QBJT_EB", tt[0], m[0]); @@ -358,7 +358,7 @@ void nl_convert_spice_t::process_line(const pstring &line) //add_term(tt[2], tt[0] + ".2"); } else - fprintf(stderr, "Voltage Source %s not connected to GND\n", tt[0].c_str()); + plib::perrlogger("Voltage Source {} not connected to GND\n", tt[0]); break; case 'I': // Input pin special notation { diff --git a/src/lib/netlist/tools/nl_convert.h b/src/lib/netlist/tools/nl_convert.h index 366249343c9..2c7393bc82e 100644 --- a/src/lib/netlist/tools/nl_convert.h +++ b/src/lib/netlist/tools/nl_convert.h @@ -10,6 +10,7 @@ #ifndef NL_CONVERT_H_ #define NL_CONVERT_H_ +#include "../plib/ptypes.h" #include "../plib/plists.h" #include "../plib/pparser.h" #include "../plib/pstring.h" @@ -23,6 +24,8 @@ class nl_convert_base_t { public: + COPYASSIGNMOVE(nl_convert_base_t, delete) + virtual ~nl_convert_base_t(); const pstring &result() { return m_buf.str(); } @@ -140,7 +143,6 @@ class nl_convert_spice_t : public nl_convert_base_t public: nl_convert_spice_t() : nl_convert_base_t() {} - ~nl_convert_spice_t() override = default; void convert(const pstring &contents) override; @@ -157,7 +159,6 @@ class nl_convert_eagle_t : public nl_convert_base_t public: nl_convert_eagle_t() : nl_convert_base_t() {} - ~nl_convert_eagle_t() override = default; class tokenizer : public plib::ptokenizer { @@ -191,7 +192,6 @@ class nl_convert_rinf_t : public nl_convert_base_t public: nl_convert_rinf_t() : nl_convert_base_t() {} - ~nl_convert_rinf_t() override = default; class tokenizer : public plib::ptokenizer { -- cgit v1.2.3-70-g09d2 From 0e07f9ac34ec82066792fb9fdaaf04546b582fab Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 24 Feb 2019 13:58:47 +0100 Subject: netlist: more alignment related refactoring. (nw) --- src/lib/netlist/build/makefile | 2 +- src/lib/netlist/devices/nlid_system.h | 5 +- src/lib/netlist/nl_config.h | 2 +- src/lib/netlist/plib/palloc.h | 124 ++++++++++++++++++--------- src/lib/netlist/plib/parray.h | 2 +- src/lib/netlist/plib/pconfig.h | 2 + src/lib/netlist/plib/pfmtlog.h | 1 + src/lib/netlist/plib/pmatrix2d.h | 82 ++++++++++++++++++ src/lib/netlist/plib/ptypes.h | 43 +++------- src/lib/netlist/plib/putil.h | 31 +++++++ src/lib/netlist/solver/nld_matrix_solver.cpp | 24 ++---- src/lib/netlist/solver/nld_matrix_solver.h | 72 ++++++++++++---- src/lib/netlist/solver/nld_ms_sor.h | 10 +-- src/lib/netlist/solver/nld_solver.cpp | 2 +- 14 files changed, 283 insertions(+), 119 deletions(-) create mode 100644 src/lib/netlist/plib/pmatrix2d.h (limited to 'src/lib/netlist/plib/pfmtlog.h') diff --git a/src/lib/netlist/build/makefile b/src/lib/netlist/build/makefile index f628e9eaed6..17dfe2f8edc 100644 --- a/src/lib/netlist/build/makefile +++ b/src/lib/netlist/build/makefile @@ -232,7 +232,7 @@ maketree: $(sort $(OBJDIRS)) .PHONY: clang clang-5 mingw doc native native: - $(MAKE) CEXTRAFLAGS="-march=native -Wall -Wpedantic -Wsign-compare -Wextra " + $(MAKE) CEXTRAFLAGS="-march=native -msse4.2 -Wall -Wpedantic -Wsign-compare -Wextra " clang: $(MAKE) CC=clang++-9 LD=clang++-9 CEXTRAFLAGS="-march=native -Weverything -Werror -Wno-unused-template -Wno-non-virtual-dtor -Wno-unreachable-code -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wconversion -Wno-c++98-compat -Wno-float-equal -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wweak-template-vtables -Wno-exit-time-destructors" diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index bc77f7ffd13..b5febc6ae3b 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -139,12 +139,13 @@ namespace netlist total += pati[i]; } netlist_time ttotal = netlist_time::zero(); - for (unsigned i=0; i(m_size - 1); + for (unsigned i=0; i < sm1; i++) { m_inc[i] = base * pati[i]; ttotal += m_inc[i]; } - m_inc[m_size - 1] = base * total - ttotal; + m_inc[sm1] = base * total - ttotal; } } NETLIB_UPDATEI(); diff --git a/src/lib/netlist/nl_config.h b/src/lib/netlist/nl_config.h index d5d195367ec..faa5008ff56 100644 --- a/src/lib/netlist/nl_config.h +++ b/src/lib/netlist/nl_config.h @@ -28,7 +28,7 @@ * Your mileage may vary. * */ -#define USE_MEMPOOL (0) +#define USE_MEMPOOL (1) /*! Store input values in logic_terminal_t. * diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h index 44f3bdb395e..c7aad9372d3 100644 --- a/src/lib/netlist/plib/palloc.h +++ b/src/lib/netlist/plib/palloc.h @@ -28,19 +28,21 @@ namespace plib { // Memory allocation //============================================================ -#if (USE_ALIGNED_OPTIMIZATIONS) + static constexpr bool is_pow2(std::size_t v) noexcept { return !(v & (v-1)); } + +#if (USE_ALIGNED_ALLOCATION) static inline void *paligned_alloc( size_t alignment, size_t size ) { #if defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER) return _aligned_malloc(size, alignment); #elif defined(__APPLE__) - void* p; - if (::posix_memalign(&p, alignment, size) != 0) { - p = nullptr; - } - return p; + void* p; + if (::posix_memalign(&p, alignment, size) != 0) { + p = nullptr; + } + return p; #else - return aligned_alloc(alignment, size); + return aligned_alloc(alignment, size); #endif } @@ -79,19 +81,35 @@ namespace plib { { ::operator delete(ptr); } +#endif 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!"); +#if (USE_ALIGNED_HINTS) + return reinterpret_cast(__builtin_assume_aligned(p, ALIGN)); +#else return p; +#endif } template inline C14CONSTEXPR const T *assume_aligned_ptr(const 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"); +#if (USE_ALIGNED_HINTS) + return reinterpret_cast(__builtin_assume_aligned(p, ALIGN)); +#else return p; - } #endif + } + template inline T *pnew(Args&&... args) { @@ -124,8 +142,8 @@ namespace plib { constexpr pdefault_deleter() noexcept = default; template::value>::type> - pdefault_deleter(const pdefault_deleter&) noexcept { } + std::enable_if::value>::type> + pdefault_deleter(const pdefault_deleter&) noexcept { } void operator()(T *p) const { @@ -245,33 +263,38 @@ namespace plib { return std::move(a); } + //============================================================ + // Aligned allocator for use with containers + //============================================================ + template class aligned_allocator { public: - using value_type = T; + using value_type = T; + static constexpr const std::size_t align_size = (USE_ALIGNED_ALLOCATION) ? ALIGN : alignof(std::max_align_t); - static_assert(ALIGN >= alignof(T) && (ALIGN % alignof(T)) == 0, - "ALIGN must be greater than alignof(T) and a multiple"); + static_assert(align_size >= alignof(T) && (align_size % alignof(T)) == 0, + "ALIGN must be greater than alignof(T) and a multiple"); - aligned_allocator() noexcept = default; - ~aligned_allocator() noexcept = default; + aligned_allocator() noexcept = default; + ~aligned_allocator() noexcept = default; - aligned_allocator(const aligned_allocator&) noexcept = default; - aligned_allocator& operator=(const aligned_allocator&) noexcept = 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; + aligned_allocator(aligned_allocator&&) noexcept = default; + aligned_allocator& operator=(aligned_allocator&&) = delete; - template - aligned_allocator(const aligned_allocator& rhs) noexcept - { - unused_var(rhs); - } + template + aligned_allocator(const aligned_allocator& rhs) noexcept + { + unused_var(rhs); + } - template struct rebind + template struct rebind { - using other = aligned_allocator; + using other = aligned_allocator; }; T* allocate(std::size_t n) @@ -306,12 +329,38 @@ namespace plib { return !(lhs == rhs); } - // FIXME: needs to be somewhere else -#if 0 - template - using aligned_vector = std::vector>; - //using aligned_vector = std::vector>; -#else + //============================================================ + // traits to determine alignment size and stride size + // from types supporting alignment + //============================================================ + + PDEFINE_HAS_MEMBER(has_align, align_size); + + template + struct align_traits + { + static constexpr const std::size_t align_size = alignof(std::max_align_t); + static constexpr const std::size_t stride_size = + (sizeof(T) % align_size == 0 ? 1 //T is a multiple of align_size + : (align_size % sizeof(T) != 0 ? align_size // align_size is not a multiple of T + : align_size / sizeof(T))); + }; + + template + struct align_traits::value, void>::type> + { + static constexpr const std::size_t align_size = T::align_size; + static constexpr const std::size_t stride_size = + (sizeof(T) % align_size == 0 ? 1 //T is a multiple of align_size + : (align_size % sizeof(T) != 0 ? align_size // align_size is not a multiple of T + : align_size / sizeof(T))); + }; + + //============================================================ + // Aligned vector + //============================================================ + + // FIXME: needs a separate file template class aligned_vector : public std::vector> { @@ -326,13 +375,13 @@ namespace plib { using base::base; - reference operator[](size_type i) noexcept + C14CONSTEXPR reference operator[](size_type i) noexcept { - return assume_aligned_ptr(this->data())[i]; + return assume_aligned_ptr(&((*this)[0]))[i]; } constexpr const_reference operator[](size_type i) const noexcept { - return assume_aligned_ptr(this->data())[i]; + return assume_aligned_ptr(&((*this)[0]))[i]; } pointer data() noexcept { return assume_aligned_ptr(base::data()); } @@ -340,11 +389,6 @@ namespace plib { }; - -#endif - - - } // namespace plib #endif /* PALLOC_H_ */ diff --git a/src/lib/netlist/plib/parray.h b/src/lib/netlist/plib/parray.h index 9b64f5343d2..1be37b908cd 100644 --- a/src/lib/netlist/plib/parray.h +++ b/src/lib/netlist/plib/parray.h @@ -104,7 +104,7 @@ namespace plib { return m_a[i]; } #else - reference operator[](size_type i) noexcept + C14CONSTEXPR reference operator[](size_type i) noexcept { return assume_aligned_ptr(&m_a[0])[i]; } diff --git a/src/lib/netlist/plib/pconfig.h b/src/lib/netlist/plib/pconfig.h index 1a411fe1aad..ecb9cc3511b 100644 --- a/src/lib/netlist/plib/pconfig.h +++ b/src/lib/netlist/plib/pconfig.h @@ -41,6 +41,8 @@ #define USE_ALIGNED_OPTIMIZATIONS (0) #endif +#define USE_ALIGNED_ALLOCATION (USE_ALIGNED_OPTIMIZATIONS) +#define USE_ALIGNED_HINTS (USE_ALIGNED_OPTIMIZATIONS) /* * Standard alignment macros */ diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h index 4c01f96dba7..50acf457114 100644 --- a/src/lib/netlist/plib/pfmtlog.h +++ b/src/lib/netlist/plib/pfmtlog.h @@ -9,6 +9,7 @@ #include "pstring.h" #include "ptypes.h" +#include "putil.h" #include diff --git a/src/lib/netlist/plib/pmatrix2d.h b/src/lib/netlist/plib/pmatrix2d.h new file mode 100644 index 00000000000..f0439105e5c --- /dev/null +++ b/src/lib/netlist/plib/pmatrix2d.h @@ -0,0 +1,82 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * pmatrix2d.h + * + * NxM regular matrix + * + */ + +#ifndef PMATRIX2D_H_ +#define PMATRIX2D_H_ + +#include "palloc.h" + +#include +#include +#include +#include +#include + +namespace plib +{ + + + template> + class pmatrix2d + { + public: + using value_type = T; + + static constexpr const std::size_t align_size = align_traits::align_size; + static constexpr const std::size_t stride_size = align_traits::stride_size; + pmatrix2d() + : m_N(0), m_M(0), m_stride(8) + { + } + + pmatrix2d(std::size_t N, std::size_t M) + : m_N(N), m_M(M), m_stride((M+stride_size-1) & ~(stride_size-1)), m_v(N * m_stride) + { + } + + void resize(std::size_t N, std::size_t M) + { + m_N = N; + m_M = M; + m_stride = (M+stride_size-1) & ~(stride_size-1); + m_v.resize(N * m_stride); + } + + C14CONSTEXPR T * operator[] (std::size_t row) noexcept + { + return assume_aligned_ptr(&m_v[m_stride * row]); + } + + constexpr const T * operator[] (std::size_t row) const noexcept + { + return assume_aligned_ptr(&m_v[m_stride * row]); + } + + T & operator()(std::size_t r, std::size_t c) noexcept + { + return (*this)[r][c]; + } + + const T & operator()(std::size_t r, std::size_t c) const noexcept + { + return (*this)[r][c]; + } + + private: + + std::size_t m_N; + std::size_t m_M; + std::size_t m_stride; + + std::vector m_v; + }; + +} // namespace plib + +#endif /* MAT_CR_H_ */ diff --git a/src/lib/netlist/plib/ptypes.h b/src/lib/netlist/plib/ptypes.h index a3b11b65e74..84f6453e8f2 100644 --- a/src/lib/netlist/plib/ptypes.h +++ b/src/lib/netlist/plib/ptypes.h @@ -81,38 +81,19 @@ namespace plib template inline void unused_var(Ts&&...) {} - - - //============================================================ - // penum - strongly typed enumeration - //============================================================ - - struct penum_base - { - protected: - static int from_string_int(const char *str, const char *x); - static std::string nthstr(int n, const char *str); - }; - } // namespace plib -#define P_ENUM(ename, ...) \ - struct ename : public plib::penum_base { \ - enum E { __VA_ARGS__ }; \ - ename (E v) : m_v(v) { } \ - bool set_from_string (const std::string &s) { \ - static char const *const strings = # __VA_ARGS__; \ - int f = from_string_int(strings, s.c_str()); \ - if (f>=0) { m_v = static_cast(f); return true; } else { return false; } \ - } \ - operator E() const {return m_v;} \ - bool operator==(const ename &rhs) const {return m_v == rhs.m_v;} \ - bool operator==(const E &rhs) const {return m_v == rhs;} \ - std::string name() const { \ - static char const *const strings = # __VA_ARGS__; \ - return nthstr(static_cast(m_v), strings); \ - } \ - private: E m_v; }; - +//============================================================ +// Define a "has member" trait. +//============================================================ + +#define PDEFINE_HAS_MEMBER(name, member) \ + template class name \ + { \ + template static long test(decltype(&U:: member)); \ + template static char test(...); \ + public: \ + static constexpr const bool value = sizeof(test(nullptr)) == sizeof(long); \ + } #endif /* PTYPES_H_ */ diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h index cd55be63185..fbf6f2af26d 100644 --- a/src/lib/netlist/plib/putil.h +++ b/src/lib/netlist/plib/putil.h @@ -93,6 +93,37 @@ namespace plib const std::string &token, const std::size_t maxsplit); + + //============================================================ + // penum - strongly typed enumeration + //============================================================ + + struct penum_base + { + protected: + static int from_string_int(const char *str, const char *x); + static std::string nthstr(int n, const char *str); + }; + } // namespace plib +#define P_ENUM(ename, ...) \ + struct ename : public plib::penum_base { \ + enum E { __VA_ARGS__ }; \ + ename (E v) : m_v(v) { } \ + bool set_from_string (const std::string &s) { \ + static char const *const strings = # __VA_ARGS__; \ + int f = from_string_int(strings, s.c_str()); \ + if (f>=0) { m_v = static_cast(f); return true; } else { return false; } \ + } \ + operator E() const {return m_v;} \ + bool operator==(const ename &rhs) const {return m_v == rhs.m_v;} \ + bool operator==(const E &rhs) const {return m_v == rhs;} \ + std::string name() const { \ + static char const *const strings = # __VA_ARGS__; \ + return nthstr(static_cast(m_v), strings); \ + } \ + private: E m_v; }; + + #endif /* PUTIL_H_ */ diff --git a/src/lib/netlist/solver/nld_matrix_solver.cpp b/src/lib/netlist/solver/nld_matrix_solver.cpp index cb905251df3..3fcdd591e83 100644 --- a/src/lib/netlist/solver/nld_matrix_solver.cpp +++ b/src/lib/netlist/solver/nld_matrix_solver.cpp @@ -39,20 +39,6 @@ namespace devices m_connected_net_idx.push_back(net_other); } - void terms_for_net_t::set_pointers() - { - m_gt.resize(count(), 0.0); - m_go.resize(count(), 0.0); - m_Idr.resize(count(), 0.0); - m_connected_net_V.resize(count(), nullptr); - - for (std::size_t i = 0; i < count(); i++) - { - m_terms[i]->set_ptrs(&m_gt[i], &m_go[i], &m_Idr[i]); - m_connected_net_V[i] = m_terms[i]->otherterm()->net().Q_Analog_state_ptr(); - } - } - // ---------------------------------------------------------------------------------------- // matrix_solver // ---------------------------------------------------------------------------------------- @@ -254,8 +240,6 @@ namespace devices m_terms[k]->m_railstart = m_terms[k]->count(); for (std::size_t i = 0; i < m_rails_temp[k]->count(); i++) this->m_terms[k]->add(m_rails_temp[k]->terms()[i], m_rails_temp[k]->m_connected_net_idx.data()[i], false); - - m_terms[k]->set_pointers(); } // free all - no longer needed @@ -263,6 +247,8 @@ namespace devices sort_terms(m_sort); + this->set_pointers(); + /* create a list of non zero elements. */ for (unsigned k = 0; k < iN; k++) { @@ -371,9 +357,9 @@ namespace devices state().save(*this, m_terms[k]->m_h_n_m_1, this->name(), "m_h_n_m_1." + num); // FIXME: This shouldn't be necessary, recalculate on each entry ... - state().save(*this, m_terms[k]->m_go.data(),"GO" + num, this->name(), m_terms[k]->count()); - state().save(*this, m_terms[k]->m_gt.data(),"GT" + num, this->name(), m_terms[k]->count()); - state().save(*this, m_terms[k]->m_Idr.data(),"IDR" + num, this->name(), m_terms[k]->count()); + state().save(*this, m_gon[k],"GO" + num, this->name(), m_terms[k]->count()); + state().save(*this, m_gtn[k],"GT" + num, this->name(), m_terms[k]->count()); + state().save(*this, m_Idrn[k],"IDR" + num, this->name(), m_terms[k]->count()); } } diff --git a/src/lib/netlist/solver/nld_matrix_solver.h b/src/lib/netlist/solver/nld_matrix_solver.h index 903c39257d0..ac5a2a464f7 100644 --- a/src/lib/netlist/solver/nld_matrix_solver.h +++ b/src/lib/netlist/solver/nld_matrix_solver.h @@ -10,9 +10,12 @@ #include "netlist/nl_base.h" #include "netlist/nl_errstr.h" -#include "netlist/plib/palloc.h" -#include "netlist/plib/putil.h" -#include "netlist/plib/vector_ops.h" +#include "plib/palloc.h" +#include "plib/putil.h" +#include "plib/vector_ops.h" +#include "plib/pmatrix2d.h" + +#include namespace netlist { @@ -51,8 +54,6 @@ namespace devices terminal_t **terms() { return m_terms.data(); } - void set_pointers(); - std::size_t m_railstart; std::vector m_nz; /* all non zero for multiplication */ @@ -65,10 +66,6 @@ namespace devices nl_double m_h_n_m_1; std::vector m_connected_net_idx; - plib::aligned_vector m_go; - plib::aligned_vector m_gt; - plib::aligned_vector m_Idr; - plib::aligned_vector m_connected_net_V; private: std::vector m_terms; @@ -171,6 +168,31 @@ namespace devices template void build_LE_RHS(T &child); + void set_pointers() + { + const std::size_t iN = this->m_nets.size(); + + std::size_t max_col = 0; + for (std::size_t k = 0; k < iN; k++) + max_col = std::max(max_col, m_terms[k]->count()); + + m_gtn.resize(iN, max_col); + m_gon.resize(iN, max_col); + m_Idrn.resize(iN, max_col); + m_connected_net_Vn.resize(iN, max_col); + + for (std::size_t k = 0; k < iN; k++) + { + auto count = m_terms[k]->count(); + + for (std::size_t i = 0; i < count; i++) + { + m_terms[k]->terms()[i]->set_ptrs(&m_gtn[k][i], &m_gon[k][i], &m_Idrn[k][i]); + m_connected_net_Vn[k][i] = m_terms[k]->terms()[i]->otherterm()->net().Q_Analog_state_ptr(); + } + } + } + template void fill_matrix(std::size_t N, AP &tcr, FT &RHS) { @@ -181,17 +203,21 @@ namespace devices const std::size_t term_count = net->count(); const std::size_t railstart = net->m_railstart; + const auto &go = m_gon[k]; + const auto > = m_gtn[k]; + const auto &Idr = m_Idrn[k]; + const auto &cnV = m_connected_net_Vn[k]; for (std::size_t i = 0; i < railstart; i++) - *tcr_r[i] -= net->m_go[i]; + *tcr_r[i] -= go[i]; typename FT::value_type gtot_t = 0.0; typename FT::value_type RHS_t = 0.0; for (std::size_t i = 0; i < term_count; i++) { - gtot_t += net->m_gt[i]; - RHS_t += net->m_Idr[i]; + gtot_t += gt[i]; + RHS_t += Idr[i]; } // FIXME: Code above is faster than vec_sum - Check this #if 0 @@ -201,7 +227,7 @@ namespace devices for (std::size_t i = railstart; i < term_count; i++) { - RHS_t += (/*m_Idr[i]*/ + net->m_go[i] * *net->m_connected_net_V[i]); + RHS_t += (/*m_Idr[i]*/ + go[i] * *cnV[i]); } RHS[k] = RHS_t; @@ -211,6 +237,16 @@ namespace devices } + template + using aligned_alloc = plib::aligned_allocator; + + plib::pmatrix2d> m_gon; + plib::pmatrix2d> m_gtn; + plib::pmatrix2d> m_Idrn; + plib::pmatrix2d> m_connected_net_Vn; + + plib::pmatrix2d m_test; + std::vector> m_terms; std::vector m_nets; std::vector> m_inps; @@ -283,7 +319,7 @@ namespace devices const std::size_t terms_count = terms->count(); const std::size_t railstart = terms->m_railstart; - const float_type * const gt = terms->m_gt.data(); + const float_type * const gt = m_gtn[k]; { float_type akk = 0.0; @@ -293,7 +329,7 @@ namespace devices Ak[k] = akk; } - const float_type * const go = terms->m_go.data(); + const float_type * const go = m_gon[k]; int * net_other = terms->m_connected_net_idx.data(); for (std::size_t i = 0; i < railstart; i++) @@ -314,9 +350,9 @@ namespace devices float_type rhsk_b = 0.0; const std::size_t terms_count = m_terms[k]->count(); - const float_type * const go = m_terms[k]->m_go.data(); - const float_type * const Idr = m_terms[k]->m_Idr.data(); - const float_type * const * other_cur_analog = m_terms[k]->m_connected_net_V.data(); + const float_type * const go = m_gon[k]; + const float_type * const Idr = m_Idrn[k]; + const float_type * const * other_cur_analog = m_connected_net_Vn[k]; for (std::size_t i = 0; i < terms_count; i++) rhsk_a = rhsk_a + Idr[i]; diff --git a/src/lib/netlist/solver/nld_ms_sor.h b/src/lib/netlist/solver/nld_ms_sor.h index 450803e25d8..9e11cb67d75 100644 --- a/src/lib/netlist/solver/nld_ms_sor.h +++ b/src/lib/netlist/solver/nld_ms_sor.h @@ -85,10 +85,10 @@ unsigned matrix_solver_SOR_t::vsolve_non_dynamic(const bool newton_rap float_type RHS_t = 0.0; const std::size_t term_count = this->m_terms[k]->count(); - const float_type * const gt = this->m_terms[k]->m_gt.data(); - const float_type * const go = this->m_terms[k]->m_go.data(); - const float_type * const Idr = this->m_terms[k]->m_Idr.data(); - auto other_cur_analog = this->m_terms[k]->m_connected_net_V.data(); + const float_type * const gt = this->m_gtn[k]; + const float_type * const go = this->m_gon[k]; + const float_type * const Idr = this->m_Idrn[k]; + auto other_cur_analog = this->m_connected_net_Vn[k]; this->m_new_V[k] = this->m_nets[k]->Q_Analog(); @@ -136,7 +136,7 @@ unsigned matrix_solver_SOR_t::vsolve_non_dynamic(const bool newton_rap { const int * net_other = this->m_terms[k]->m_connected_net_idx.data(); const std::size_t railstart = this->m_terms[k]->m_railstart; - const float_type * go = this->m_terms[k]->m_go.data(); + const float_type * go = this->m_gon[k]; float_type Idrive = 0.0; for (std::size_t i = 0; i < railstart; i++) diff --git a/src/lib/netlist/solver/nld_solver.cpp b/src/lib/netlist/solver/nld_solver.cpp index 77bf710c9c9..d9685f24ae0 100644 --- a/src/lib/netlist/solver/nld_solver.cpp +++ b/src/lib/netlist/solver/nld_solver.cpp @@ -192,7 +192,7 @@ poolptr NETLIB_NAME(solver)::create_solver_x(std::size_t size, else return this->create_solver_x(size, solvername); } -}; +} struct net_splitter { -- cgit v1.2.3-70-g09d2 From 2e055aa97b9b60c79985f8b5c5d16cbf5391f887 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 24 Feb 2019 17:55:28 +0100 Subject: netlist: tidy changes and better constexpr support for ptime class. (nw) --- src/lib/netlist/analog/nlid_twoterm.h | 2 +- src/lib/netlist/build/makefile | 8 +++- src/lib/netlist/devices/nld_4020.cpp | 2 +- src/lib/netlist/devices/nld_74107.cpp | 4 +- src/lib/netlist/devices/nld_74161.cpp | 2 +- src/lib/netlist/devices/nld_74192.cpp | 2 +- src/lib/netlist/devices/nld_74193.cpp | 2 +- src/lib/netlist/devices/nld_7448.cpp | 2 +- src/lib/netlist/devices/nld_7490.cpp | 2 +- src/lib/netlist/devices/nld_7497.cpp | 4 +- src/lib/netlist/devices/nld_log.cpp | 2 +- src/lib/netlist/devices/nlid_truthtable.cpp | 4 +- src/lib/netlist/nl_base.h | 12 ++++-- src/lib/netlist/nltypes.h | 10 ++--- src/lib/netlist/plib/palloc.h | 64 ++++++++++++++--------------- src/lib/netlist/plib/pconfig.h | 4 +- src/lib/netlist/plib/pfmtlog.h | 1 - src/lib/netlist/plib/plists.h | 4 +- src/lib/netlist/plib/pstream.h | 2 +- src/lib/netlist/plib/ptime.h | 12 +++--- src/lib/netlist/plib/ptypes.h | 16 ++++---- src/lib/netlist/plib/putil.h | 2 +- src/lib/netlist/solver/nld_matrix_solver.h | 12 +++--- src/lib/netlist/solver/nld_ms_direct.h | 4 +- src/lib/netlist/solver/nld_ms_gcr.h | 6 +-- src/lib/netlist/solver/nld_ms_gmres.h | 4 +- src/lib/netlist/solver/nld_ms_sm.h | 2 +- src/lib/netlist/solver/nld_ms_w.h | 2 +- src/lib/netlist/solver/nld_solver.h | 2 +- src/lib/netlist/tools/nl_convert.cpp | 2 +- 30 files changed, 103 insertions(+), 94 deletions(-) (limited to 'src/lib/netlist/plib/pfmtlog.h') diff --git a/src/lib/netlist/analog/nlid_twoterm.h b/src/lib/netlist/analog/nlid_twoterm.h index 67939f32645..06c278d58a3 100644 --- a/src/lib/netlist/analog/nlid_twoterm.h +++ b/src/lib/netlist/analog/nlid_twoterm.h @@ -33,9 +33,9 @@ #ifndef NLID_TWOTERM_H_ #define NLID_TWOTERM_H_ -#include "plib/pfunction.h" #include "netlist/nl_base.h" #include "netlist/nl_setup.h" +#include "plib/pfunction.h" // ----------------------------------------------------------------------------- // Implementation diff --git a/src/lib/netlist/build/makefile b/src/lib/netlist/build/makefile index 17dfe2f8edc..79c51b54bec 100644 --- a/src/lib/netlist/build/makefile +++ b/src/lib/netlist/build/makefile @@ -14,7 +14,7 @@ VSBUILD = $(SRC)/buildVS DOC = $(SRC)/documentation TIDY_DB = ../compile_commands.json -TIDY_FLAGSX = -checks=*,google*,-hicpp*,-readability*,-fuchsia*,cert-*,-android-*, +TIDY_FLAGSX = -checks=*,-google*,-hicpp*,-readability*,-fuchsia*,cert-*,-android-*, TIDY_FLAGSX += -llvm-header-guard,-cppcoreguidelines-pro-type-reinterpret-cast, TIDY_FLAGSX += -cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-owning-memory, TIDY_FLAGSX += -modernize-use-default-member-init,-cppcoreguidelines-pro-bounds-constant-array-index, @@ -235,7 +235,7 @@ native: $(MAKE) CEXTRAFLAGS="-march=native -msse4.2 -Wall -Wpedantic -Wsign-compare -Wextra " clang: - $(MAKE) CC=clang++-9 LD=clang++-9 CEXTRAFLAGS="-march=native -Weverything -Werror -Wno-unused-template -Wno-non-virtual-dtor -Wno-unreachable-code -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wconversion -Wno-c++98-compat -Wno-float-equal -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wweak-template-vtables -Wno-exit-time-destructors" + $(MAKE) CC=clang++-9 LD=clang++-9 CEXTRAFLAGS="-march=native -Weverything -Werror -Wno-padded -Wno-weak-vtables -Wno-unused-template -Wno-missing-variable-declarations -Wno-float-equal -Wconversion -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wno-exit-time-destructors" clang-5: $(MAKE) CC=clang++-5.0 LD=clang++-5.0 CEXTRAFLAGS="-march=native -Weverything -Werror -Wno-inconsistent-missing-destructor-override -Wno-unreachable-code -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wconversion -Wno-c++98-compat -Wno-float-equal -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wno-weak-template-vtables -Wno-exit-time-destructors" @@ -252,6 +252,10 @@ tidy_db: compile_commands_prefix $(ALL_TIDY_FILES) compile_commands_postfix # FIXME: -Wno-weak-vtables -Wno-missing-variable-declarations -Wno-conversion -Wno-exit-time-destructors # FIXME: -Winconsistent-missing-destructor-override : c++ community has diverging opinions on this https://github.com/isocpp/CppCoreGuidelines/issues/721 # FIXME: -Wunreachable-code : False warnings, this a documented clang bug: https://llvm.org/bugs/show_bug.cgi?id=28994 +# -Wweak-template-vtables +# +# These have to be given: +# -Wno-missing-variable-declarations : Device factory code, on purpose mingw: $(MAKE) CEXTRAFLAGS="-DUNICODE -D_UNICODE -D_WIN32_WINNT=0x0501 -DWIN32_LEAN_AND_MEAN" \ diff --git a/src/lib/netlist/devices/nld_4020.cpp b/src/lib/netlist/devices/nld_4020.cpp index 88cc05ada8f..13518f9d3cb 100644 --- a/src/lib/netlist/devices/nld_4020.cpp +++ b/src/lib/netlist/devices/nld_4020.cpp @@ -98,7 +98,7 @@ namespace netlist NETLIB_FUNC_VOID(CD4020_sub, update_outputs, (const unsigned cnt)) { - static const std::array out_delayQn = { + static constexpr const std::array out_delayQn = { NLTIME_FROM_NS(180), NLTIME_FROM_NS(280), NLTIME_FROM_NS(380), NLTIME_FROM_NS(480), NLTIME_FROM_NS(580), NLTIME_FROM_NS(680), diff --git a/src/lib/netlist/devices/nld_74107.cpp b/src/lib/netlist/devices/nld_74107.cpp index 6939a5d6db6..763760e2c6a 100644 --- a/src/lib/netlist/devices/nld_74107.cpp +++ b/src/lib/netlist/devices/nld_74107.cpp @@ -13,8 +13,8 @@ namespace netlist namespace devices { - static constexpr netlist_time delay_107[2] = { NLTIME_FROM_NS(16), NLTIME_FROM_NS(25) }; - static constexpr netlist_time delay_107A[2] = { NLTIME_FROM_NS(15), NLTIME_FROM_NS(15) }; + static constexpr const netlist_time delay_107[2] = { NLTIME_FROM_NS(16), NLTIME_FROM_NS(25) }; + static constexpr const netlist_time delay_107A[2] = { NLTIME_FROM_NS(15), NLTIME_FROM_NS(15) }; NETLIB_OBJECT(74107A) { diff --git a/src/lib/netlist/devices/nld_74161.cpp b/src/lib/netlist/devices/nld_74161.cpp index e75eaf10c88..7a3b54d6368 100644 --- a/src/lib/netlist/devices/nld_74161.cpp +++ b/src/lib/netlist/devices/nld_74161.cpp @@ -85,7 +85,7 @@ namespace netlist } // FIXME: Timing - static constexpr netlist_time delay[4] = + static constexpr const netlist_time delay[4] = { NLTIME_FROM_NS(40), NLTIME_FROM_NS(40), diff --git a/src/lib/netlist/devices/nld_74192.cpp b/src/lib/netlist/devices/nld_74192.cpp index a256f89451e..954fc351179 100644 --- a/src/lib/netlist/devices/nld_74192.cpp +++ b/src/lib/netlist/devices/nld_74192.cpp @@ -110,7 +110,7 @@ namespace netlist } // FIXME: Timing - static constexpr netlist_time delay[4] = + static constexpr const netlist_time delay[4] = { NLTIME_FROM_NS(40), NLTIME_FROM_NS(40), diff --git a/src/lib/netlist/devices/nld_74193.cpp b/src/lib/netlist/devices/nld_74193.cpp index 73b1d697b7b..16d7438d799 100644 --- a/src/lib/netlist/devices/nld_74193.cpp +++ b/src/lib/netlist/devices/nld_74193.cpp @@ -87,7 +87,7 @@ namespace netlist } // FIXME: Timing - static constexpr netlist_time delay[4] = + static constexpr const netlist_time delay[4] = { NLTIME_FROM_NS(40), NLTIME_FROM_NS(40), diff --git a/src/lib/netlist/devices/nld_7448.cpp b/src/lib/netlist/devices/nld_7448.cpp index 25d3ba5d108..4500229a1c5 100644 --- a/src/lib/netlist/devices/nld_7448.cpp +++ b/src/lib/netlist/devices/nld_7448.cpp @@ -137,7 +137,7 @@ namespace netlist #define BITS7(b6,b5,b4,b3,b2,b1,b0) ((b6)<<6) | ((b5)<<5) | ((b4)<<4) | ((b3)<<3) | ((b2)<<2) | ((b1)<<1) | ((b0)<<0) - static constexpr std::array tab7448 = + static constexpr const std::array tab7448 = { BITS7( 1, 1, 1, 1, 1, 1, 0 ), /* 00 - not blanked ! */ BITS7( 0, 1, 1, 0, 0, 0, 0 ), /* 01 */ diff --git a/src/lib/netlist/devices/nld_7490.cpp b/src/lib/netlist/devices/nld_7490.cpp index 3dabd026cd7..bde02e25edb 100644 --- a/src/lib/netlist/devices/nld_7490.cpp +++ b/src/lib/netlist/devices/nld_7490.cpp @@ -78,7 +78,7 @@ namespace netlist m_last_B = 0; } - static C14CONSTEXPR const netlist_time delay[4] = + static constexpr const netlist_time delay[4] = { NLTIME_FROM_NS(18), NLTIME_FROM_NS(36) - NLTIME_FROM_NS(18), diff --git a/src/lib/netlist/devices/nld_7497.cpp b/src/lib/netlist/devices/nld_7497.cpp index f74e386faac..1432884b8dd 100644 --- a/src/lib/netlist/devices/nld_7497.cpp +++ b/src/lib/netlist/devices/nld_7497.cpp @@ -17,8 +17,8 @@ namespace netlist namespace devices { - static constexpr netlist_time out_delay_CLK_Y[2] = { NLTIME_FROM_NS(20), NLTIME_FROM_NS(26) }; // tPHL, tPLH - static constexpr netlist_time out_delay_CLK_Z[2] = { NLTIME_FROM_NS(17), NLTIME_FROM_NS(12) }; + static constexpr const netlist_time out_delay_CLK_Y[2] = { NLTIME_FROM_NS(20), NLTIME_FROM_NS(26) }; // tPHL, tPLH + static constexpr const netlist_time out_delay_CLK_Z[2] = { NLTIME_FROM_NS(17), NLTIME_FROM_NS(12) }; NETLIB_OBJECT(7497) { diff --git a/src/lib/netlist/devices/nld_log.cpp b/src/lib/netlist/devices/nld_log.cpp index 3ecfe65f40c..6b1b3d8efc1 100644 --- a/src/lib/netlist/devices/nld_log.cpp +++ b/src/lib/netlist/devices/nld_log.cpp @@ -6,9 +6,9 @@ */ #include "netlist/nl_base.h" +#include "nld_log.h" #include "plib/pfmtlog.h" #include "plib/pstream.h" -#include "nld_log.h" //#include "sound/wavwrite.h" namespace netlist diff --git a/src/lib/netlist/devices/nlid_truthtable.cpp b/src/lib/netlist/devices/nlid_truthtable.cpp index 1e9cc8b1ec1..622aee0e0c7 100644 --- a/src/lib/netlist/devices/nlid_truthtable.cpp +++ b/src/lib/netlist/devices/nlid_truthtable.cpp @@ -77,8 +77,8 @@ namespace netlist return ret; } - static constexpr sbitset all_bits() { return sbitset(~static_cast(0)); } - static constexpr sbitset no_bits() { return sbitset(static_cast(0)); } + static constexpr const sbitset all_bits() noexcept { return sbitset(~static_cast(0)); } + static constexpr const sbitset no_bits() noexcept{ return sbitset(static_cast(0)); } private: T m_bs; }; diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 22bd9848565..e54d3b1abae 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -24,9 +24,9 @@ #include "plib/pstate.h" #include "plib/pstream.h" -#include "nltypes.h" #include "nl_errstr.h" #include "nl_lists.h" +#include "nltypes.h" #include "plib/ptime.h" //============================================================ @@ -1034,8 +1034,8 @@ namespace netlist : m_value(param.model_value(name)) { } - const double &operator()() const NL_NOEXCEPT { return m_value; } - operator const double&() const NL_NOEXCEPT { return m_value; } + const double &operator()() const noexcept { return m_value; } + operator const double&() const noexcept { return m_value; } private: const double m_value; }; @@ -1248,6 +1248,12 @@ namespace netlist public: using entry_t = pqentry_t; explicit queue_t(netlist_state_t &nl); + virtual ~queue_t() noexcept = default; + + queue_t(const queue_t &) = delete; + queue_t(queue_t &&) = delete; + queue_t &operator=(const queue_t &) = delete; + queue_t &operator=(queue_t &&) = delete; protected: diff --git a/src/lib/netlist/nltypes.h b/src/lib/netlist/nltypes.h index ca1972ee527..1ddc29adfae 100644 --- a/src/lib/netlist/nltypes.h +++ b/src/lib/netlist/nltypes.h @@ -14,12 +14,12 @@ #define NLTYPES_H_ #include "nl_config.h" -#include "plib/ptime.h" #include "plib/pchrono.h" #include "plib/pfmtlog.h" #include "plib/pmempool.h" -#include "plib/pstring.h" #include "plib/pstate.h" +#include "plib/pstring.h" +#include "plib/ptime.h" #include #include @@ -126,9 +126,9 @@ namespace netlist // MACROS //============================================================ - template inline constexpr netlist_time NLTIME_FROM_NS(T &&t) noexcept { return netlist_time::from_nsec(t); } - template inline constexpr netlist_time NLTIME_FROM_US(T &&t) noexcept { return netlist_time::from_usec(t); } - template inline constexpr netlist_time NLTIME_FROM_MS(T &&t) noexcept { return netlist_time::from_msec(t); } + template inline constexpr const netlist_time NLTIME_FROM_NS(T &&t) noexcept { return netlist_time::from_nsec(t); } + template inline constexpr const netlist_time NLTIME_FROM_US(T &&t) noexcept { return netlist_time::from_usec(t); } + template inline constexpr const netlist_time NLTIME_FROM_MS(T &&t) noexcept { return netlist_time::from_msec(t); } } // namespace netlist diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h index c7aad9372d3..d8e4ffbb5d7 100644 --- a/src/lib/netlist/plib/palloc.h +++ b/src/lib/netlist/plib/palloc.h @@ -36,13 +36,13 @@ namespace plib { #if defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER) return _aligned_malloc(size, alignment); #elif defined(__APPLE__) - void* p; - if (::posix_memalign(&p, alignment, size) != 0) { - p = nullptr; - } - return p; + void* p; + if (::posix_memalign(&p, alignment, size) != 0) { + p = nullptr; + } + return p; #else - return aligned_alloc(alignment, size); + return aligned_alloc(alignment, size); #endif } @@ -90,7 +90,7 @@ namespace plib { static_assert(is_pow2(ALIGN), "Alignment must be a power of 2"); //auto t = reinterpret_cast(p); //if (t & (ALIGN-1)) - // printf("alignment error!"); + // printf("alignment error!"); #if (USE_ALIGNED_HINTS) return reinterpret_cast(__builtin_assume_aligned(p, ALIGN)); #else @@ -142,8 +142,8 @@ namespace plib { constexpr pdefault_deleter() noexcept = default; template::value>::type> - pdefault_deleter(const pdefault_deleter&) noexcept { } + std::enable_if::value>::type> + pdefault_deleter(const pdefault_deleter&) noexcept { } void operator()(T *p) const { @@ -271,30 +271,30 @@ namespace plib { class aligned_allocator { public: - using value_type = T; - static constexpr const std::size_t align_size = (USE_ALIGNED_ALLOCATION) ? ALIGN : alignof(std::max_align_t); + using value_type = T; + static constexpr const std::size_t align_size = (USE_ALIGNED_ALLOCATION) ? ALIGN : alignof(std::max_align_t); - static_assert(align_size >= alignof(T) && (align_size % alignof(T)) == 0, - "ALIGN must be greater than alignof(T) and a multiple"); + static_assert(align_size >= alignof(T) && (align_size % alignof(T)) == 0, + "ALIGN must be greater than alignof(T) and a multiple"); - aligned_allocator() noexcept = default; - ~aligned_allocator() noexcept = default; + aligned_allocator() noexcept = default; + ~aligned_allocator() noexcept = default; - aligned_allocator(const aligned_allocator&) noexcept = default; - aligned_allocator& operator=(const aligned_allocator&) noexcept = 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; + aligned_allocator(aligned_allocator&&) noexcept = default; + aligned_allocator& operator=(aligned_allocator&&) = delete; - template - aligned_allocator(const aligned_allocator& rhs) noexcept - { - unused_var(rhs); - } + template + aligned_allocator(const aligned_allocator& rhs) noexcept + { + unused_var(rhs); + } - template struct rebind + template struct rebind { - using other = aligned_allocator; + using other = aligned_allocator; }; T* allocate(std::size_t n) @@ -331,22 +331,22 @@ namespace plib { //============================================================ // traits to determine alignment size and stride size - // from types supporting alignment + // from types supporting alignment //============================================================ PDEFINE_HAS_MEMBER(has_align, align_size); - template - struct align_traits + template + struct align_traits { - static constexpr const std::size_t align_size = alignof(std::max_align_t); + static constexpr const std::size_t align_size = alignof(std::max_align_t); static constexpr const std::size_t stride_size = (sizeof(T) % align_size == 0 ? 1 //T is a multiple of align_size : (align_size % sizeof(T) != 0 ? align_size // align_size is not a multiple of T : align_size / sizeof(T))); }; - template + template struct align_traits::value, void>::type> { static constexpr const std::size_t align_size = T::align_size; @@ -360,7 +360,7 @@ namespace plib { // Aligned vector //============================================================ - // FIXME: needs a separate file + // FIXME: needs a separate file template class aligned_vector : public std::vector> { diff --git a/src/lib/netlist/plib/pconfig.h b/src/lib/netlist/plib/pconfig.h index ecb9cc3511b..158fb3faae7 100644 --- a/src/lib/netlist/plib/pconfig.h +++ b/src/lib/netlist/plib/pconfig.h @@ -42,13 +42,13 @@ #endif #define USE_ALIGNED_ALLOCATION (USE_ALIGNED_OPTIMIZATIONS) -#define USE_ALIGNED_HINTS (USE_ALIGNED_OPTIMIZATIONS) +#define USE_ALIGNED_HINTS (USE_ALIGNED_OPTIMIZATIONS) /* * Standard alignment macros */ #define PALIGN_CACHELINE (64) -#define PALIGN_VECTOROPT (32) +#define PALIGN_VECTOROPT (8) #define PALIGNAS_CACHELINE() PALIGNAS(PALIGN_CACHELINE) #define PALIGNAS_VECTOROPT() PALIGNAS(PALIGN_VECTOROPT) diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h index 50acf457114..4d13fa3424b 100644 --- a/src/lib/netlist/plib/pfmtlog.h +++ b/src/lib/netlist/plib/pfmtlog.h @@ -35,7 +35,6 @@ struct ptype_traits_base template <> struct ptype_traits_base { - static unsigned int cast(bool &x) { return static_cast(x); } static unsigned int cast(const bool &x) { return static_cast(x); } static const bool is_signed = std::numeric_limits::is_signed; static const char *size_spec() { return ""; } diff --git a/src/lib/netlist/plib/plists.h b/src/lib/netlist/plib/plists.h index 0a1345d5e1f..2a0fd3a6c3c 100644 --- a/src/lib/netlist/plib/plists.h +++ b/src/lib/netlist/plib/plists.h @@ -200,9 +200,9 @@ public: LC* p; public: explicit constexpr iter_t(LC* x) noexcept : p(x) { } - explicit constexpr iter_t(iter_t &rhs) noexcept : p(rhs.p) { } + constexpr iter_t(iter_t &rhs) noexcept : p(rhs.p) { } iter_t(iter_t &&rhs) noexcept { std::swap(*this, rhs); } - iter_t& operator=(const iter_t &rhs) { iter_t t(rhs); std::swap(*this, t); return *this; } + iter_t& operator=(const iter_t &rhs) noexcept { 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;} // NOLINTNEXTLINE(cert-dcl21-cpp) diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h index 29f79e0dd4a..aaccf577c4d 100644 --- a/src/lib/netlist/plib/pstream.h +++ b/src/lib/netlist/plib/pstream.h @@ -658,7 +658,7 @@ inline void copystream(postream &dest, pistream &src) struct perrlogger { template - perrlogger(Args&& ... args) + explicit perrlogger(Args&& ... args) { h()(std::forward(args)...); } diff --git a/src/lib/netlist/plib/ptime.h b/src/lib/netlist/plib/ptime.h index 4767a197342..32ccc4f7b0d 100644 --- a/src/lib/netlist/plib/ptime.h +++ b/src/lib/netlist/plib/ptime.h @@ -47,19 +47,19 @@ namespace plib C14CONSTEXPR ptime &operator-=(const ptime rhs) noexcept { m_time -= rhs.m_time; return *this; } C14CONSTEXPR ptime &operator*=(const mult_type factor) noexcept { m_time *= static_cast(factor); return *this; } - friend C14CONSTEXPR ptime operator-(ptime lhs, const ptime rhs) noexcept + friend constexpr const ptime operator-(ptime lhs, const ptime rhs) noexcept { - return lhs -= rhs; + return ptime(lhs.m_time - rhs.m_time); } - friend C14CONSTEXPR ptime operator+(ptime lhs, const ptime rhs) noexcept + friend constexpr const ptime operator+(ptime lhs, const ptime rhs) noexcept { - return lhs += rhs; + return ptime(lhs.m_time + rhs.m_time); } - friend C14CONSTEXPR ptime operator*(ptime lhs, const mult_type &factor) noexcept + friend constexpr const ptime operator*(ptime lhs, const mult_type &factor) noexcept { - return lhs *= factor; + return ptime(lhs.m_time * factor); } friend constexpr mult_type operator/(const ptime lhs, const ptime rhs) noexcept diff --git a/src/lib/netlist/plib/ptypes.h b/src/lib/netlist/plib/ptypes.h index 84f6453e8f2..99bc5715a05 100644 --- a/src/lib/netlist/plib/ptypes.h +++ b/src/lib/netlist/plib/ptypes.h @@ -87,13 +87,13 @@ namespace plib // Define a "has member" trait. //============================================================ -#define PDEFINE_HAS_MEMBER(name, member) \ - template class name \ - { \ - template static long test(decltype(&U:: member)); \ - template static char test(...); \ - public: \ - static constexpr const bool value = sizeof(test(nullptr)) == sizeof(long); \ - } +#define PDEFINE_HAS_MEMBER(name, member) \ + template class name \ + { \ + template static long test(decltype(&U:: member)); \ + template static char test(...); \ + public: \ + static constexpr const bool value = sizeof(test(nullptr)) == sizeof(long); \ + } #endif /* PTYPES_H_ */ diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h index fbf6f2af26d..0db2ae28ffb 100644 --- a/src/lib/netlist/plib/putil.h +++ b/src/lib/netlist/plib/putil.h @@ -12,7 +12,7 @@ #include #include -#include // <<= needed by windows build +#include #define PSTRINGIFY_HELP(y) # y #define PSTRINGIFY(x) PSTRINGIFY_HELP(x) diff --git a/src/lib/netlist/solver/nld_matrix_solver.h b/src/lib/netlist/solver/nld_matrix_solver.h index ac5a2a464f7..88d4dbb4bb0 100644 --- a/src/lib/netlist/solver/nld_matrix_solver.h +++ b/src/lib/netlist/solver/nld_matrix_solver.h @@ -11,9 +11,9 @@ #include "netlist/nl_base.h" #include "netlist/nl_errstr.h" #include "plib/palloc.h" +#include "plib/pmatrix2d.h" #include "plib/putil.h" #include "plib/vector_ops.h" -#include "plib/pmatrix2d.h" #include @@ -240,12 +240,12 @@ namespace devices template using aligned_alloc = plib::aligned_allocator; - plib::pmatrix2d> m_gon; - plib::pmatrix2d> m_gtn; - plib::pmatrix2d> m_Idrn; - plib::pmatrix2d> m_connected_net_Vn; + plib::pmatrix2d> m_gon; + plib::pmatrix2d> m_gtn; + plib::pmatrix2d> m_Idrn; + plib::pmatrix2d> m_connected_net_Vn; - plib::pmatrix2d m_test; + plib::pmatrix2d m_test; std::vector> m_terms; std::vector m_nets; diff --git a/src/lib/netlist/solver/nld_ms_direct.h b/src/lib/netlist/solver/nld_ms_direct.h index c0995d99e54..0e3cd677ef7 100644 --- a/src/lib/netlist/solver/nld_ms_direct.h +++ b/src/lib/netlist/solver/nld_ms_direct.h @@ -8,10 +8,10 @@ #ifndef NLD_MS_DIRECT_H_ #define NLD_MS_DIRECT_H_ -#include -#include #include "plib/mat_cr.h" #include "plib/vector_ops.h" +#include +#include #include "nld_matrix_solver.h" #include "nld_solver.h" diff --git a/src/lib/netlist/solver/nld_ms_gcr.h b/src/lib/netlist/solver/nld_ms_gcr.h index fce7b5bae2c..c9ab4a535a9 100644 --- a/src/lib/netlist/solver/nld_ms_gcr.h +++ b/src/lib/netlist/solver/nld_ms_gcr.h @@ -12,11 +12,11 @@ #include "plib/mat_cr.h" +#include "nld_ms_direct.h" +#include "nld_solver.h" #include "plib/pdynlib.h" #include "plib/pstream.h" #include "plib/vector_ops.h" -#include "nld_ms_direct.h" -#include "nld_solver.h" #include @@ -67,7 +67,7 @@ private: plib::parray new_V; std::array, storage_N> m_term_cr; - // std::array, storage_N> m_term_cr; + // std::array, storage_N> m_term_cr; mat_type mat; diff --git a/src/lib/netlist/solver/nld_ms_gmres.h b/src/lib/netlist/solver/nld_ms_gmres.h index 95de1bbae31..f3d894881e2 100644 --- a/src/lib/netlist/solver/nld_ms_gmres.h +++ b/src/lib/netlist/solver/nld_ms_gmres.h @@ -8,12 +8,12 @@ #ifndef NLD_MS_GMRES_H_ #define NLD_MS_GMRES_H_ +#include "nld_ms_direct.h" +#include "nld_solver.h" #include "plib/gmres.h" #include "plib/mat_cr.h" #include "plib/parray.h" #include "plib/vector_ops.h" -#include "nld_ms_direct.h" -#include "nld_solver.h" #include #include diff --git a/src/lib/netlist/solver/nld_ms_sm.h b/src/lib/netlist/solver/nld_ms_sm.h index 6c0f610e3f2..9d5b4e0843a 100644 --- a/src/lib/netlist/solver/nld_ms_sm.h +++ b/src/lib/netlist/solver/nld_ms_sm.h @@ -35,9 +35,9 @@ #include -#include "plib/vector_ops.h" #include "nld_matrix_solver.h" #include "nld_solver.h" +#include "plib/vector_ops.h" namespace netlist { diff --git a/src/lib/netlist/solver/nld_ms_w.h b/src/lib/netlist/solver/nld_ms_w.h index 584d50fdb15..76225724a21 100644 --- a/src/lib/netlist/solver/nld_ms_w.h +++ b/src/lib/netlist/solver/nld_ms_w.h @@ -42,9 +42,9 @@ #include -#include "plib/vector_ops.h" #include "nld_matrix_solver.h" #include "nld_solver.h" +#include "plib/vector_ops.h" namespace netlist { diff --git a/src/lib/netlist/solver/nld_solver.h b/src/lib/netlist/solver/nld_solver.h index fb6d05fbbcb..8b1f1f0b96d 100644 --- a/src/lib/netlist/solver/nld_solver.h +++ b/src/lib/netlist/solver/nld_solver.h @@ -9,8 +9,8 @@ #define NLD_SOLVER_H_ #include "netlist/nl_base.h" -#include "plib/pstream.h" #include "nld_matrix_solver.h" +#include "plib/pstream.h" #include #include diff --git a/src/lib/netlist/tools/nl_convert.cpp b/src/lib/netlist/tools/nl_convert.cpp index a9e17d56120..d6d5f3e2e01 100644 --- a/src/lib/netlist/tools/nl_convert.cpp +++ b/src/lib/netlist/tools/nl_convert.cpp @@ -6,8 +6,8 @@ */ #include "plib/palloc.h" -#include "plib/putil.h" #include "nl_convert.h" +#include "plib/putil.h" #include #include #include -- cgit v1.2.3-70-g09d2 From deacff7ffa214098257f0ea53c247d9aeebecd9f Mon Sep 17 00:00:00 2001 From: couriersud Date: Mon, 18 Mar 2019 22:12:14 +0100 Subject: netlist: refactor model code. (nw) --- src/lib/netlist/analog/nld_bjt.cpp | 1 - src/lib/netlist/nl_base.cpp | 16 ++----- src/lib/netlist/nl_base.h | 15 ++++--- src/lib/netlist/nl_setup.cpp | 88 +++++++++++++++++++++----------------- src/lib/netlist/nl_setup.h | 55 ++++++++++++++++++------ src/lib/netlist/nltypes.h | 5 --- src/lib/netlist/plib/pfmtlog.h | 6 +++ src/mame/machine/nl_breakout.cpp | 8 ++-- 8 files changed, 114 insertions(+), 80 deletions(-) (limited to 'src/lib/netlist/plib/pfmtlog.h') diff --git a/src/lib/netlist/analog/nld_bjt.cpp b/src/lib/netlist/analog/nld_bjt.cpp index df9b3bcb161..6050bdb6f37 100644 --- a/src/lib/netlist/analog/nld_bjt.cpp +++ b/src/lib/netlist/analog/nld_bjt.cpp @@ -291,7 +291,6 @@ namespace analog NETLIB_SUBXX(analog, C) m_CJE; NETLIB_SUBXX(analog, C) m_CJC; - }; diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 166703c25af..ad048e899bf 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -988,12 +988,9 @@ pstring param_t::get_initial(const device_t &dev, bool *found) return res; } - const pstring param_model_t::model_type() { - if (m_map.size() == 0) - state().setup().model_parse(this->Value(), m_map); - return m_map["COREMODEL"]; + return state().setup().models().model_type(value()); } param_str_t::param_str_t(device_t &device, const pstring &name, const pstring &val) @@ -1016,27 +1013,22 @@ param_ptr_t::param_ptr_t(device_t &device, const pstring &name, uint8_t * val) void param_model_t::changed() { state().log().fatal(MF_1_MODEL_1_CAN_NOT_BE_CHANGED_AT_RUNTIME, name()); - m_map.clear(); } const pstring param_model_t::model_value_str(const pstring &entity) { - if (m_map.size() == 0) - state().setup().model_parse(this->Value(), m_map); - return state().setup().model_value_str(m_map, entity); + return state().setup().models().model_value_str(value(), entity); } nl_double param_model_t::model_value(const pstring &entity) { - if (m_map.size() == 0) - state().setup().model_parse(this->Value(), m_map); - return state().setup().model_value(m_map, entity); + return state().setup().models().model_value(value(), entity); } plib::unique_ptr param_data_t::stream() { - return device().setup().get_data_stream(Value()); + return device().setup().get_data_stream(value()); } bool detail::core_terminal_t::is_logic() const NL_NOEXCEPT diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 389b1178f71..f217007e1a7 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -162,7 +162,7 @@ class NETLIB_NAME(name) : public device_t #define nl_assert(x) do { if (0) if (!(x)) { /*throw nl_exception(plib::pfmt("assert: {1}:{2}: {3}")(__FILE__)(__LINE__)(#x) ); */} } while (0) #define NL_NOEXCEPT noexcept #endif -#define nl_assert_always(x, msg) do { if (!(x)) throw nl_exception(plib::pfmt("Fatal error: {1}\nCaused by assert: {2}:{3}: {4}")(msg)(__FILE__)(__LINE__)(#x)); } while (0) +#define nl_assert_always(x, msg) do { if (!(x)) throw nl_exception("Fatal error: {1}\nCaused by assert: {2}:{3}: {4}", msg, __FILE__, __LINE__, #x); } while (0) //============================================================ // Namespace starts @@ -223,6 +223,12 @@ namespace netlist explicit nl_exception(const pstring &text //!< text to be passed ) : plib::pexception(text) { } + + template + explicit nl_exception(const pstring &fmt //!< format to be used + , Args&&... args //!< arguments to be passed + ) + : plib::pexception(plib::pfmt(fmt)(std::forward(args)...)) { } }; /*! Logic families descriptors are used to create proxy devices. @@ -1004,7 +1010,7 @@ namespace netlist public: param_str_t(device_t &device, const pstring &name, const pstring &val); - const pstring &operator()() const NL_NOEXCEPT { return Value(); } + const pstring &operator()() const NL_NOEXCEPT { return value(); } void setTo(const pstring ¶m) NL_NOEXCEPT { if (m_param != param) @@ -1016,7 +1022,7 @@ namespace netlist } protected: virtual void changed(); - const pstring &Value() const NL_NOEXCEPT { return m_param; } + const pstring &value() const NL_NOEXCEPT { return m_param; } private: pstring m_param; }; @@ -1055,7 +1061,6 @@ namespace netlist void changed() override; nl_double model_value(const pstring &entity) /*const*/; private: - detail::model_map_t m_map; }; // ----------------------------------------------------------------------------- @@ -1552,7 +1557,7 @@ namespace netlist if (f != nullptr) f->read(reinterpret_cast(&m_data[0]),1<second; } pstring xmodel = plib::left(model, pos); @@ -857,12 +848,12 @@ void setup_t::model_parse(const pstring &model_in, detail::model_map_t &map) if (i != m_models.end()) model_parse(xmodel, map); else - log().fatal(MF_1_MODEL_NOT_FOUND, model_in); + throw nl_exception(MF_1_MODEL_NOT_FOUND, model_in); } pstring remainder = plib::trim(model.substr(pos + 1)); if (!plib::endsWith(remainder, ")")) - log().fatal(MF_1_MODEL_ERROR_1, model); + throw nl_exception(MF_1_MODEL_ERROR_1, model); // FIMXE: Not optimal remainder = plib::left(remainder, remainder.size() - 1); @@ -871,29 +862,48 @@ void setup_t::model_parse(const pstring &model_in, detail::model_map_t &map) { auto pose = pe.find("="); if (pose == pstring::npos) - log().fatal(MF_1_MODEL_ERROR_ON_PAIR_1, model); + throw nl_exception(MF_1_MODEL_ERROR_ON_PAIR_1, model); map[plib::ucase(plib::left(pe, pose))] = pe.substr(pose + 1); } } -const pstring setup_t::model_value_str(detail::model_map_t &map, const pstring &entity) +pstring models_t::model_string(model_map_t &map) +{ + pstring ret = map["COREMODEL"] + "("; + for (auto & i : map) + ret = ret + i.first + "=" + i.second + " "; + + return ret + ")"; +} + +pstring models_t::model_value_str(pstring model, pstring entity) { + model_map_t &map = m_cache[model]; + + if (map.size() == 0) + model_parse(model , map); + pstring ret; if (entity != plib::ucase(entity)) - log().fatal(MF_2_MODEL_PARAMETERS_NOT_UPPERCASE_1_2, entity, + throw nl_exception(MF_2_MODEL_PARAMETERS_NOT_UPPERCASE_1_2, entity, model_string(map)); if (map.find(entity) == map.end()) - log().fatal(MF_2_ENTITY_1_NOT_FOUND_IN_MODEL_2, entity, model_string(map)); + throw nl_exception(MF_2_ENTITY_1_NOT_FOUND_IN_MODEL_2, entity, model_string(map)); else ret = map[entity]; return ret; } -nl_double setup_t::model_value(detail::model_map_t &map, const pstring &entity) +nl_double models_t::model_value(pstring model, pstring entity) { - pstring tmp = model_value_str(map, entity); + model_map_t &map = m_cache[model]; + + if (map.size() == 0) + model_parse(model , map); + + pstring tmp = model_value_str(model, entity); nl_double factor = plib::constants::one(); auto p = std::next(tmp.begin(), static_cast(tmp.size() - 1)); @@ -909,7 +919,7 @@ nl_double setup_t::model_value(detail::model_map_t &map, const pstring &entity) case 'a': factor = 1e-18; break; default: if (*p < '0' || *p > '9') - log().fatal(MF_1_UNKNOWN_NUMBER_FACTOR_IN_1, entity); + throw nl_exception(MF_1_UNKNOWN_NUMBER_FACTOR_IN_1, entity); } if (factor != plib::constants::one()) tmp = plib::left(tmp, tmp.size() - 1); @@ -940,12 +950,10 @@ pool_owned_ptr logic_family_std_proxy_t::create_ const logic_family_desc_t *setup_t::family_from_model(const pstring &model) { - detail::model_map_t map; - model_parse(model, map); - if (model_value_str(map, "TYPE") == "TTL") + if (m_models.model_value_str(model, "TYPE") == "TTL") return family_TTL(); - if (model_value_str(map, "TYPE") == "CD4XXX") + if (m_models.model_value_str(model, "TYPE") == "CD4XXX") return family_CD4XXX(); for (auto & e : m_nlstate.m_family_cache) @@ -954,13 +962,13 @@ const logic_family_desc_t *setup_t::family_from_model(const pstring &model) auto ret = plib::make_unique(); - ret->m_fixed_V = model_value(map, "FV"); - ret->m_low_thresh_PCNT = model_value(map, "IVL"); - ret->m_high_thresh_PCNT = model_value(map, "IVH"); - ret->m_low_VO = model_value(map, "OVL"); - ret->m_high_VO = model_value(map, "OVH"); - ret->m_R_low = model_value(map, "ORL"); - ret->m_R_high = model_value(map, "ORH"); + ret->m_fixed_V = m_models.model_value(model, "FV"); + ret->m_low_thresh_PCNT = m_models.model_value(model, "IVL"); + ret->m_high_thresh_PCNT = m_models.model_value(model, "IVH"); + ret->m_low_VO = m_models.model_value(model, "OVL"); + ret->m_high_VO = m_models. model_value(model, "OVH"); + ret->m_R_low = m_models.model_value(model, "ORL"); + ret->m_R_high = m_models.model_value(model, "ORH"); auto retp = ret.get(); diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 2a6c19fdbc9..50036212020 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -202,8 +202,35 @@ namespace netlist const type_t m_type; }; + // ---------------------------------------------------------------------------------------- - // setup_t + // Collection of models + // ---------------------------------------------------------------------------------------- + + class models_t + { + public: + void register_model(pstring model_in); + /* model / family related */ + + pstring model_value_str(pstring model, pstring entity); + + double model_value(pstring model, pstring entity); + + pstring model_type(pstring model) { return model_value_str(model, "COREMODEL"); } + + private: + using model_map_t = std::unordered_map; + + void model_parse(const pstring &model, model_map_t &map); + pstring model_string(model_map_t &map); + + std::unordered_map m_models; + std::unordered_map m_cache; + }; + + // ---------------------------------------------------------------------------------------- + // nlparse_t // ---------------------------------------------------------------------------------------- class nlparse_t @@ -213,7 +240,7 @@ namespace netlist nlparse_t(setup_t &netlist, log_type &log); - void register_model(const pstring &model_in); + void register_model(const pstring &model_in) { m_models.register_model(model_in); } void register_alias(const pstring &alias, const pstring &out); void register_dippins_arr(const pstring &terms); void register_dev(const pstring &classname, const pstring &name); @@ -240,7 +267,6 @@ namespace netlist /* include other files */ void include(const pstring &netlist_name); - /* parse a source */ pstring build_fqn(const pstring &obj_name) const; void register_alias_nofqn(const pstring &alias, const pstring &out); @@ -276,8 +302,12 @@ namespace netlist */ setup_t &setup() { return m_setup; } const setup_t &setup() const { return m_setup; } + + models_t &models() { return m_models; } + const models_t &models() const { return m_models; } + protected: - std::unordered_map m_models; + models_t m_models; std::stack m_namespace_stack; std::unordered_map m_alias; std::vector m_links; @@ -299,6 +329,10 @@ namespace netlist unsigned m_frontier_cnt; }; + // ---------------------------------------------------------------------------------------- + // setup_t + // ---------------------------------------------------------------------------------------- + class setup_t : public nlparse_t { public: @@ -323,24 +357,17 @@ namespace netlist param_t *find_param(const pstring ¶m_in, bool required = true) const; + /* get family */ + const logic_family_desc_t *family_from_model(const pstring &model); + void register_dynamic_log_devices(); void resolve_inputs(); plib::unique_ptr get_data_stream(const pstring &name); - factory::list_t &factory() { return m_factory; } const factory::list_t &factory() const { return m_factory; } - /* model / family related */ - - const pstring model_value_str(detail::model_map_t &map, const pstring &entity); - double model_value(detail::model_map_t &map, const pstring &entity); - - void model_parse(const pstring &model, detail::model_map_t &map); - - const logic_family_desc_t *family_from_model(const pstring &model); - /* helper - also used by nltool */ const pstring resolve_alias(const pstring &name) const; diff --git a/src/lib/netlist/nltypes.h b/src/lib/netlist/nltypes.h index 9abe8beebef..f6980af5fcf 100644 --- a/src/lib/netlist/nltypes.h +++ b/src/lib/netlist/nltypes.h @@ -108,11 +108,6 @@ namespace netlist OUTPUT = 2, /*!< object is an output */ }; - /*! Type of the model map used. - * This is used to hold all #Models in an unordered map - */ - using model_map_t = std::unordered_map; - } // namespace detail #if (PHAS_INT128) diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h index 4d13fa3424b..cb9b59c01ce 100644 --- a/src/lib/netlist/plib/pfmtlog.h +++ b/src/lib/netlist/plib/pfmtlog.h @@ -191,6 +191,12 @@ public: return format_element(ptype_traits::size_spec(), ptype_traits::fmt_spec(), ptype_traits::cast(x)); } + template + pfmt &operator()(X&& x, Y && y, Args&&... args) + { + return ((*this)(std::forward(x)))(std::forward(y), std::forward(args)...); + } + template pfmt &x(const T &x) { diff --git a/src/mame/machine/nl_breakout.cpp b/src/mame/machine/nl_breakout.cpp index 94bd228723a..1a19b119b61 100644 --- a/src/mame/machine/nl_breakout.cpp +++ b/src/mame/machine/nl_breakout.cpp @@ -181,9 +181,11 @@ CIRCUIT_LAYOUT( breakout ) DIODE(CR5, "1N914") DIODE(CR7, "1N914") - QBJT_EB(Q1, "2N3644") - QBJT_EB(Q2, "2N3643") - QBJT_EB(Q3, "2N3643") + // No need to model capacitance + QBJT_EB(Q1, "2N3644(CJC=0 CJE=0)") + QBJT_EB(Q2, "2N3643(CJC=0 CJE=0)") + QBJT_EB(Q3, "2N3643(CJC=0 CJE=0)") + CAP(C19, CAP_U(0.1)) CAP(C16, CAP_U(0.1)) -- cgit v1.2.3-70-g09d2