From f9fa6b1c81b99303d3448bcb355bc6e3f4d3c44a Mon Sep 17 00:00:00 2001 From: couriersud Date: Mon, 8 Jun 2020 02:52:39 +0200 Subject: netlist: code maintenance. (nw) - more c++14, use enable_if_t instead of enable_if - cleaned up the use of memory allocation arenas - reduce MACRO usage, use std::conditional where possible --- src/devices/machine/netlist.cpp | 37 ++++++++-------- src/devices/machine/netlist.h | 2 +- src/lib/netlist/devices/nld_74125.cpp | 10 ++--- src/lib/netlist/devices/nlid_system.h | 2 +- src/lib/netlist/devices/nlid_truthtable.cpp | 10 ++--- src/lib/netlist/devices/nlid_truthtable.h | 2 +- src/lib/netlist/nl_base.cpp | 22 +++++----- src/lib/netlist/nl_base.h | 68 ++++++++++++++--------------- src/lib/netlist/nl_factory.cpp | 4 +- src/lib/netlist/nl_factory.h | 21 +++++---- src/lib/netlist/nl_setup.cpp | 20 ++++----- src/lib/netlist/nl_setup.h | 16 +++---- src/lib/netlist/nltypes.h | 37 ++++++---------- src/lib/netlist/plib/palloc.h | 34 ++++++--------- src/lib/netlist/plib/parray.h | 8 ++-- src/lib/netlist/plib/pfmtlog.h | 10 ++--- src/lib/netlist/plib/pfunction.cpp | 4 +- src/lib/netlist/plib/pmath.h | 30 ++++++------- src/lib/netlist/plib/pmempool.h | 12 ++--- src/lib/netlist/plib/ppreprocessor.cpp | 4 +- src/lib/netlist/plib/pstate.h | 8 ++-- src/lib/netlist/plib/pstonum.h | 6 +-- src/lib/netlist/plib/pstream.h | 4 +- src/lib/netlist/plib/pstring.h | 8 ++-- src/lib/netlist/plib/ptime.h | 4 +- src/lib/netlist/plib/putil.h | 26 +++++------ src/lib/netlist/prg/nltool.cpp | 26 +++++------ src/lib/netlist/prg/nlwav.cpp | 24 +++++----- src/lib/netlist/solver/nld_matrix_solver.h | 2 +- src/lib/netlist/solver/nld_solver.cpp | 60 +++++++------------------ src/lib/netlist/solver/nld_solver.h | 7 +-- src/lib/netlist/tools/nl_convert.cpp | 27 ++++++++---- src/lib/netlist/tools/nl_convert.h | 20 +++++++-- 33 files changed, 277 insertions(+), 298 deletions(-) diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index 9fd71f0bc3c..1e290a2d29e 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -124,10 +124,10 @@ protected: } } - plib::unique_ptr static_solver_lib() const noexcept override + netlist::host_arena::unique_ptr static_solver_lib() const noexcept override { //return plib::make_unique(nullptr); - return plib::make_unique(nl_static_solver_syms); + return netlist::host_arena::make_unique(nl_static_solver_syms); } private: @@ -167,9 +167,9 @@ protected: } } - plib::unique_ptr static_solver_lib() const noexcept override + netlist::host_arena::unique_ptr static_solver_lib() const noexcept override { - return plib::make_unique(nullptr); + return netlist::host_arena::make_unique(nullptr); } private: @@ -181,12 +181,12 @@ class netlist_mame_device::netlist_mame_t : public netlist::netlist_state_t public: netlist_mame_t(netlist_mame_device &parent, const pstring &name) - : netlist::netlist_state_t(name, plib::make_unique(parent)) + : netlist::netlist_state_t(name, netlist::host_arena::make_unique(parent)) , m_parent(parent) { } - netlist_mame_t(netlist_mame_device &parent, const pstring &name, plib::unique_ptr cbs) + netlist_mame_t(netlist_mame_device &parent, const pstring &name, netlist::host_arena::unique_ptr cbs) : netlist::netlist_state_t(name, std::move(cbs)) , m_parent(parent) { @@ -234,13 +234,12 @@ class netlist_source_memregion_t : public netlist::source_netlist_t { public: - netlist_source_memregion_t(device_t &dev, pstring name) : netlist::source_netlist_t(), m_dev(dev), m_name(name) { } - virtual plib::unique_ptr stream(const pstring &name) override; + virtual stream_ptr stream(const pstring &name) override; private: device_t &m_dev; pstring m_name; @@ -251,7 +250,7 @@ class netlist_data_memregions_t : public netlist::source_data_t public: netlist_data_memregions_t(const device_t &dev); - virtual plib::unique_ptr stream(const pstring &name) override; + virtual stream_ptr stream(const pstring &name) override; private: const device_t &m_dev; @@ -262,12 +261,12 @@ private: // memregion source support // ---------------------------------------------------------------------------------------- -plib::unique_ptr netlist_source_memregion_t::stream(const pstring &name) +netlist_source_memregion_t::stream_ptr netlist_source_memregion_t::stream(const pstring &name) { if (m_dev.has_running_machine()) { memory_region *mem = m_dev.memregion(m_name.c_str()); - auto ret(plib::make_unique(pstring(reinterpret_cast(mem->base()), mem->bytes()))); + auto ret(std::make_unique(pstring(reinterpret_cast(mem->base()), mem->bytes()))); ret->imbue(std::locale::classic()); return MOVE_UNIQUE_PTR(ret); } @@ -300,7 +299,7 @@ static bool rom_exists(device_t &root, pstring name) return false; } -plib::unique_ptr netlist_data_memregions_t::stream(const pstring &name) +netlist_data_memregions_t::stream_ptr netlist_data_memregions_t::stream(const pstring &name) { //memory_region *mem = static_cast(setup().setup().exec()).parent().memregion(name.c_str()); if (m_dev.has_running_machine()) @@ -308,12 +307,12 @@ plib::unique_ptr netlist_data_memregions_t::stream(const pstring & memory_region *mem = m_dev.memregion(name.c_str()); if (mem != nullptr) { - auto ret(plib::make_unique(std::string(reinterpret_cast(mem->base()), mem->bytes()), std::ios_base::binary)); + auto ret(std::make_unique(std::string(reinterpret_cast(mem->base()), mem->bytes()), std::ios_base::binary)); ret->imbue(std::locale::classic()); return MOVE_UNIQUE_PTR(ret); } else - return plib::unique_ptr(nullptr); + return stream_ptr(nullptr); } else { @@ -321,12 +320,12 @@ plib::unique_ptr netlist_data_memregions_t::stream(const pstring & if (rom_exists(m_dev.mconfig().root_device(), pstring(m_dev.tag()) + ":" + name)) { // Create an empty stream. - auto ret(plib::make_unique(std::ios_base::binary)); + auto ret(std::make_unique(std::ios_base::binary)); ret->imbue(std::locale::classic()); return MOVE_UNIQUE_PTR(ret); } else - return plib::unique_ptr(nullptr); + return stream_ptr(nullptr); } } @@ -973,11 +972,11 @@ void netlist_mame_device::common_dev_start(netlist::netlist_state_t *lnetlist) c } } -plib::unique_ptr netlist_mame_device::base_validity_check(validity_checker &valid) const +netlist::host_arena::unique_ptr netlist_mame_device::base_validity_check(validity_checker &valid) const { try { - auto lnetlist = plib::make_unique("netlist", plib::make_unique()); + auto lnetlist = netlist::host_arena::make_unique("netlist", netlist::host_arena::make_unique()); // enable validation mode lnetlist->set_extended_validation(true); common_dev_start(lnetlist.get()); @@ -1008,7 +1007,7 @@ plib::unique_ptr netlist_mame_device::base_validity_ch { osd_printf_error("%s\n", err.what()); } - return plib::unique_ptr(nullptr); + return netlist::host_arena::unique_ptr(nullptr); } void netlist_mame_device::device_validity_check(validity_checker &valid) const diff --git a/src/devices/machine/netlist.h b/src/devices/machine/netlist.h index 0ac6753ea52..c5111e5c80e 100644 --- a/src/devices/machine/netlist.h +++ b/src/devices/machine/netlist.h @@ -111,7 +111,7 @@ protected: virtual void device_pre_save() override; virtual void device_clock_changed() override; - plib::unique_ptr base_validity_check(validity_checker &valid) const; + netlist::host_arena::unique_ptr base_validity_check(validity_checker &valid) const; attotime m_cur_time; attotime m_attotime_per_clock; diff --git a/src/lib/netlist/devices/nld_74125.cpp b/src/lib/netlist/devices/nld_74125.cpp index d803b80d984..d2c873a0e17 100644 --- a/src/lib/netlist/devices/nld_74125.cpp +++ b/src/lib/netlist/devices/nld_74125.cpp @@ -13,19 +13,19 @@ namespace netlist { template - struct uptr : public unique_pool_ptr + struct uptr : public device_arena::unique_ptr { uptr() = default; - using base_type = unique_pool_ptr; + using base_type = device_arena::unique_ptr; template uptr(O &owner, const pstring &name, Args&&... args) - : unique_pool_ptr(owner.template make_pool_object(owner, name, std::forward(args)...)) + : device_arena::unique_ptr(owner.template make_pool_object(owner, name, std::forward(args)...)) { } - constexpr auto operator ()() noexcept -> decltype((*unique_pool_ptr::get())()) { return (*this->get())(); } - constexpr auto operator ()() const noexcept -> const decltype((*unique_pool_ptr::get())()) { return (*this->get())(); } + constexpr auto operator ()() noexcept -> decltype((*device_arena::unique_ptr::get())()) { return (*this->get())(); } + constexpr auto operator ()() const noexcept -> const decltype((*device_arena::unique_ptr::get())()) { return (*this->get())(); } }; namespace devices diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index 97a3c68e2b8..fc1bfefd84b 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -380,7 +380,7 @@ namespace devices param_int_t m_N; param_str_t m_func; analog_output_t m_Q; - std::vector> m_I; + std::vector> m_I; pf_type::values_container m_vals; state_var m_compiled; diff --git a/src/lib/netlist/devices/nlid_truthtable.cpp b/src/lib/netlist/devices/nlid_truthtable.cpp index ea29be363ce..1718f53560d 100644 --- a/src/lib/netlist/devices/nlid_truthtable.cpp +++ b/src/lib/netlist/devices/nlid_truthtable.cpp @@ -434,7 +434,7 @@ namespace devices : truthtable_base_element_t(name, std::move(props)) { } - unique_pool_ptr make_device(nlmempool &pool, netlist_state_t &anetlist, const pstring &name) override + device_arena::unique_ptr make_device(device_arena &pool, netlist_state_t &anetlist, const pstring &name) override { using tt_type = nld_truthtable_t; @@ -451,7 +451,7 @@ namespace devices return pool.make_unique(anetlist, name, m_family_name, *m_ttbl, m_desc); } private: - unique_pool_ptr::truthtable_t> m_ttbl; + device_arena::unique_ptr::truthtable_t> m_ttbl; }; tt_bitset truthtable_parser::calculate_ignored_inputs(tt_bitset state) const @@ -670,16 +670,16 @@ namespace factory #define ENTRYY(n, m, s) case (n * 100 + m): \ { using xtype = devices::netlist_factory_truthtable_t; \ auto cs=s; \ - ret = plib::make_unique(desc.name, std::move(cs)); } \ + ret = host_arena::make_unique(desc.name, std::move(cs)); } \ break #define ENTRY(n, s) ENTRYY(n, 1, s); ENTRYY(n, 2, s); ENTRYY(n, 3, s); \ ENTRYY(n, 4, s); ENTRYY(n, 5, s); ENTRYY(n, 6, s); \ ENTRYY(n, 7, s); ENTRYY(n, 8, s) - plib::unique_ptr truthtable_create(tt_desc &desc, properties &&props) + host_arena::unique_ptr truthtable_create(tt_desc &desc, properties &&props) { - plib::unique_ptr ret; + host_arena::unique_ptr ret; switch (desc.ni * 100 + desc.no) { diff --git a/src/lib/netlist/devices/nlid_truthtable.h b/src/lib/netlist/devices/nlid_truthtable.h index 14ee3d00624..e9daa32e47d 100644 --- a/src/lib/netlist/devices/nlid_truthtable.h +++ b/src/lib/netlist/devices/nlid_truthtable.h @@ -26,7 +26,7 @@ namespace netlist pstring m_family_name; }; - plib::unique_ptr truthtable_create(tt_desc &desc, + host_arena::unique_ptr truthtable_create(tt_desc &desc, properties &&props); } // namespace factory diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 87f692c1b29..532e23149c3 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -29,9 +29,9 @@ namespace netlist // callbacks_t // ---------------------------------------------------------------------------------------- - plib::unique_ptr callbacks_t:: static_solver_lib() const + host_arena::unique_ptr callbacks_t:: static_solver_lib() const { - return plib::make_unique(nullptr); + return host_arena::make_unique(nullptr); } // ---------------------------------------------------------------------------------------- @@ -124,7 +124,7 @@ namespace netlist // ---------------------------------------------------------------------------------------- netlist_state_t::netlist_state_t(const pstring &name, - plib::unique_ptr &&callbacks) + host_arena::unique_ptr &&callbacks) : m_callbacks(std::move(callbacks)) // Order is important here , m_log(*m_callbacks) , m_extended_validation(false) @@ -133,7 +133,7 @@ namespace netlist m_lib = m_callbacks->static_solver_lib(); - m_setup = plib::make_unique(*this); + m_setup = host_arena::make_unique(*this); // create the run interface m_netlist = m_pool.make_unique(*this, name); @@ -145,7 +145,7 @@ namespace netlist devices::initialize_factory(m_setup->parser().factory()); // Add default include file - using a = plib::psource_str_t; + using a = plib::psource_str_t; const pstring content = "#define RES_R(res) (res) \n" "#define RES_K(res) ((res) * 1e3) \n" @@ -498,7 +498,7 @@ namespace netlist , m_active_outputs(*this, "m_active_outputs", 1) { //printf("owned device: %s\n", this->name().c_str()); - owner.state().register_device(this->name(), owned_pool_ptr(this, false)); + owner.state().register_device(this->name(), device_arena::owned_ptr(this, false)); if (exec().stats_enabled()) m_stats = owner.state().make_pool_object(); } @@ -778,7 +778,7 @@ namespace netlist { plib::unused_var(dummy); this->set_net(&m_my_net); - state().register_net(owned_pool_ptr(&m_my_net, false)); + state().register_net(device_arena::owned_ptr(&m_my_net, false)); state().setup().register_term(*this); } @@ -807,7 +807,7 @@ namespace netlist : analog_t(dev, aname, STATE_OUT) , m_my_net(dev.state(), name() + ".net", this) { - state().register_net(owned_pool_ptr(&m_my_net, false)); + state().register_net(device_arena::owned_ptr(&m_my_net, false)); this->set_net(&m_my_net); //net().m_cur_Analog = NL_FCONST(0.0); @@ -869,7 +869,7 @@ namespace netlist param_str_t::param_str_t(core_device_t &device, const pstring &name, const pstring &val) : param_t(device, name) { - m_param = plib::make_unique(val); + m_param = host_arena::make_unique(val); *m_param = device.state().setup().get_initial_param_val(this->name(),val); } @@ -877,7 +877,7 @@ namespace netlist : param_t(name) { // deviceless parameter, no registration, owner is responsible - m_param = plib::make_unique(val); + m_param = host_arena::make_unique(val); *m_param = state.setup().get_initial_param_val(this->name(),val); } @@ -912,7 +912,7 @@ namespace netlist } - plib::unique_ptr param_data_t::stream() + std::unique_ptr param_data_t::stream() { return device().state().parser().get_data_stream(str()); } diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 9bccb152c67..f5ac1c4408b 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -186,7 +186,7 @@ class NETLIB_NAME(name) : public delegator_t #define NETLIB_RESETI() virtual void reset() override #define NETLIB_SUB(chip) nld_ ## chip -#define NETLIB_SUB_UPTR(ns, chip) unique_pool_ptr< ns :: nld_ ## chip > +#define NETLIB_SUB_UPTR(ns, chip) device_arena::unique_ptr< ns :: nld_ ## chip > #define NETLIB_HANDLER(chip, name) void NETLIB_NAME(chip) :: name() noexcept #define NETLIB_UPDATE(chip) NETLIB_HANDLER(chip, update) @@ -296,9 +296,9 @@ namespace netlist virtual ~logic_family_desc_t() noexcept = default; - virtual unique_pool_ptr create_d_a_proxy(netlist_state_t &anetlist, const pstring &name, + virtual device_arena::unique_ptr create_d_a_proxy(netlist_state_t &anetlist, const pstring &name, const logic_output_t *proxied) const = 0; - virtual unique_pool_ptr create_a_d_proxy(netlist_state_t &anetlist, const pstring &name, + virtual device_arena::unique_ptr create_a_d_proxy(netlist_state_t &anetlist, const pstring &name, const logic_input_t *proxied) const = 0; nl_fptype low_thresh_V(nl_fptype VN, nl_fptype VP) const noexcept{ return VN + (VP - VN) * m_low_thresh_PCNT; } @@ -576,7 +576,7 @@ namespace netlist // to ease template design template - unique_pool_ptr make_pool_object(Args&&... args); + device_arena::unique_ptr make_pool_object(Args&&... args); private: netlist_t & m_netlist; @@ -1288,7 +1288,7 @@ namespace netlist virtual void changed() noexcept; pstring str() const noexcept { pstring ret = *m_param; return ret;} private: - plib::unique_ptr m_param; + host_arena::unique_ptr m_param; }; // ----------------------------------------------------------------------------- @@ -1303,12 +1303,12 @@ namespace netlist class value_base_t { public: - template ::value>::type> + template ::value>> value_base_t(P ¶m, const pstring &name) : m_value(static_cast(param.value(name))) { } - template ::value, int>::type = 0> + template ::value, int> = 0> value_base_t(P ¶m, const pstring &name) : m_value(static_cast(param.value_str(name))) { @@ -1349,7 +1349,7 @@ namespace netlist { } - plib::unique_ptr stream(); + std::unique_ptr stream(); protected: void changed() noexcept override { } }; @@ -1452,7 +1452,7 @@ namespace netlist private: bool m_hint_deactivate; state_var_s32 m_active_outputs; - unique_pool_ptr m_stats; + device_arena::unique_ptr m_stats; }; // ----------------------------------------------------------------------------- @@ -1470,7 +1470,7 @@ namespace netlist ~base_device_t() noexcept override = default; template - void create_and_register_subdevice(O& owner, const pstring &name, unique_pool_ptr &dev, Args&&... args); + void create_and_register_subdevice(O& owner, const pstring &name, device_arena::unique_ptr &dev, Args&&... args); void register_subalias(const pstring &name, const detail::core_terminal_t &term); void register_subalias(const pstring &name, const pstring &aliased); @@ -1574,12 +1574,12 @@ namespace netlist { public: - using nets_collection_type = std::vector>; - using family_collection_type = std::unordered_map>; + using nets_collection_type = std::vector>; + using family_collection_type = std::unordered_map>; // need to preserve order of device creation ... - using devices_collection_type = std::vector>>; - netlist_state_t(const pstring &name, plib::unique_ptr &&callbacks); + using devices_collection_type = std::vector>>; + netlist_state_t(const pstring &name, host_arena::unique_ptr &&callbacks); PCOPYASSIGNMOVE(netlist_state_t, delete) @@ -1659,7 +1659,7 @@ namespace netlist std::size_t find_net_id(const detail::net_t *net) const; template - void register_net(owned_pool_ptr &&net) { m_nets.push_back(std::move(net)); } + void register_net(device_arena::owned_ptr &&net) { m_nets.push_back(std::move(net)); } /// \brief Get device pointer by name /// @@ -1685,7 +1685,7 @@ namespace netlist /// \param dev Device to be registered template - void register_device(const pstring &name, owned_pool_ptr &&dev) noexcept(false) + void register_device(const pstring &name, device_arena::owned_ptr &&dev) noexcept(false) { for (auto & d : m_devices) if (d.first == name) @@ -1706,9 +1706,9 @@ namespace netlist /// \param dev Device to be registered template - void register_device(const pstring &name, unique_pool_ptr &&dev) + void register_device(const pstring &name, device_arena::unique_ptr &&dev) { - register_device(name, owned_pool_ptr(dev.release(), true, dev.get_deleter())); + register_device(name, device_arena::owned_ptr(dev.release(), true, dev.get_deleter())); } /// \brief Remove device @@ -1751,13 +1751,13 @@ namespace netlist family_collection_type &family_cache() { return m_family_cache; } template - unique_pool_ptr make_pool_object(Args&&... args) + device_arena::unique_ptr make_pool_object(Args&&... args) { return m_pool.make_unique(std::forward(args)...); } // memory pool - still needed in some places - nlmempool &pool() noexcept { return m_pool; } - const nlmempool &pool() const noexcept { return m_pool; } + device_arena &pool() noexcept { return m_pool; } + const device_arena &pool() const noexcept { return m_pool; } /// \brief set extended validation mode. /// @@ -1792,26 +1792,26 @@ namespace netlist private: - nlmempool m_pool; // must be deleted last! + device_arena m_pool; // must be deleted last! - unique_pool_ptr m_netlist; - plib::unique_ptr m_lib; + device_arena::unique_ptr m_netlist; + host_arena::unique_ptr m_lib; plib::state_manager_t m_state; - plib::unique_ptr m_callbacks; - log_type m_log; + host_arena::unique_ptr m_callbacks; + log_type m_log; // FIXME: should only be available during device construcion - plib::unique_ptr m_setup; + host_arena::unique_ptr m_setup; - nets_collection_type m_nets; + nets_collection_type m_nets; // sole use is to manage lifetime of net objects - devices_collection_type m_devices; + devices_collection_type m_devices; // sole use is to manage lifetime of family objects - family_collection_type m_family_cache; - bool m_extended_validation; + family_collection_type m_family_cache; + bool m_extended_validation; // dummy version - int m_dummy_version; + int m_dummy_version; }; namespace devices @@ -2476,7 +2476,7 @@ namespace netlist } template - inline unique_pool_ptr detail::netlist_object_t::make_pool_object(Args&&... args) + inline device_arena::unique_ptr detail::netlist_object_t::make_pool_object(Args&&... args) { return state().make_pool_object(std::forward(args)...); } @@ -2544,7 +2544,7 @@ namespace netlist } template - void base_device_t::create_and_register_subdevice(O &owner, const pstring &name, unique_pool_ptr &dev, Args&&... args) + void base_device_t::create_and_register_subdevice(O &owner, const pstring &name, device_arena::unique_ptr &dev, Args&&... args) { dev = state().make_pool_object(owner, name, std::forward(args)...); } diff --git a/src/lib/netlist/nl_factory.cpp b/src/lib/netlist/nl_factory.cpp index 601f6f3951d..8ef9799101a 100644 --- a/src/lib/netlist/nl_factory.cpp +++ b/src/lib/netlist/nl_factory.cpp @@ -42,7 +42,7 @@ namespace factory { { } - void list_t::add(plib::unique_ptr &&factory) + void list_t::add(host_arena::unique_ptr &&factory) { for (auto & e : *this) if (e->name() == factory->name()) @@ -74,7 +74,7 @@ namespace factory { { } - unique_pool_ptr library_element_t::make_device(nlmempool &pool, netlist_state_t &anetlist, const pstring &name) + device_arena::unique_ptr library_element_t::make_device(device_arena &pool, netlist_state_t &anetlist, const pstring &name) { return pool.make_unique(anetlist, name); } diff --git a/src/lib/netlist/nl_factory.h b/src/lib/netlist/nl_factory.h index ca9fd93b7ab..4c9a47cc749 100644 --- a/src/lib/netlist/nl_factory.h +++ b/src/lib/netlist/nl_factory.h @@ -27,8 +27,7 @@ NETLIB_DEVICE_IMPL_BASE(ns, chip, chip, p_name, p_def_param) \ #define NETLIB_DEVICE_IMPL_BASE(ns, p_alias, chip, p_name, p_def_param) \ - static plib::unique_ptr NETLIB_NAME(p_alias ## _c) \ - () \ + static factory::element_t::uptr NETLIB_NAME(p_alias ## _c) () \ { \ using devtype = factory::device_element_t; \ factory::properties sl(p_def_param, PSOURCELOC()); \ @@ -92,8 +91,8 @@ namespace factory { { public: - using dev_uptr = unique_pool_ptr; - using uptr = plib::unique_ptr; + using dev_uptr = device_arena::unique_ptr; + using uptr = host_arena::unique_ptr; using pointer = element_t *; element_t(const pstring &name, properties &&props); @@ -101,7 +100,7 @@ namespace factory { PCOPYASSIGNMOVE(element_t, default) - virtual dev_uptr make_device(nlmempool &pool, + virtual dev_uptr make_device(device_arena &pool, netlist_state_t &anetlist, const pstring &name) = 0; @@ -126,21 +125,21 @@ namespace factory { template - dev_uptr make_device(nlmempool &pool, + dev_uptr make_device(device_arena &pool, netlist_state_t &anetlist, const pstring &name, std::tuple& args, std::index_sequence) { return pool.make_unique(anetlist, name, std::forward(std::get(args))...); } - dev_uptr make_device(nlmempool &pool, + dev_uptr make_device(device_arena &pool, netlist_state_t &anetlist, const pstring &name, std::tuple& args) { return make_device(pool, anetlist, name, args, std::index_sequence_for{}); } - dev_uptr make_device(nlmempool &pool, + dev_uptr make_device(device_arena &pool, netlist_state_t &anetlist, const pstring &name) override { @@ -150,7 +149,7 @@ namespace factory { static uptr create(const pstring &name, properties &&props, Args&&... args) { - return plib::make_unique>(name, + return host_arena::make_unique>(name, std::move(props), std::forward(args)...); } private: @@ -195,7 +194,7 @@ namespace factory { template element_t::uptr constructor_t(const pstring &name, properties &&props) { - return plib::make_unique>(name, std::move(props)); + return host_arena::make_unique>(name, std::move(props)); } // ----------------------------------------------------------------------------- @@ -208,7 +207,7 @@ namespace factory { library_element_t(const pstring &name, properties &&props); - dev_uptr make_device(nlmempool &pool, + dev_uptr make_device(device_arena &pool, netlist_state_t &anetlist, const pstring &name) override; }; diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 10c70b109a1..1b63b002492 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -248,7 +248,7 @@ namespace netlist void nlparse_t::register_lib_entry(const pstring &name, factory::properties &&props) { - m_factory.add(plib::make_unique(name, std::move(props))); + m_factory.add(host_arena::make_unique(name, std::move(props))); } void nlparse_t::register_frontier(const pstring &attach, const pstring &r_IN, @@ -327,7 +327,7 @@ namespace netlist bool nlparse_t::parse_stream(plib::psource_t::stream_ptr &&istrm, const pstring &name) { - auto y = plib::make_unique(m_includes, &m_defines); + auto y = std::make_unique(m_includes, &m_defines); y->process(std::move(istrm)); return parser_t(std::move(y), *this).parse(name); //return parser_t(std::move(plib::ppreprocessor(&m_defines).process(std::move(istrm))), *this).parse(name); @@ -1302,7 +1302,7 @@ public: } // FIXME: create proxies based on family type (far future) - unique_pool_ptr create_d_a_proxy(netlist_state_t &anetlist, + device_arena::unique_ptr create_d_a_proxy(netlist_state_t &anetlist, const pstring &name, const logic_output_t *proxied) const override { switch(m_family_type) @@ -1318,7 +1318,7 @@ public: return anetlist.make_pool_object(anetlist, name, proxied); } - unique_pool_ptr create_a_d_proxy(netlist_state_t &anetlist, const pstring &name, const logic_input_t *proxied) const override + device_arena::unique_ptr create_a_d_proxy(netlist_state_t &anetlist, const pstring &name, const logic_input_t *proxied) const override { switch(m_family_type) { @@ -1390,7 +1390,7 @@ const logic_family_desc_t *setup_t::family_from_model(const pstring &model) if (it != m_nlstate.family_cache().end()) return it->second.get(); - auto ret = plib::make_unique(ft); + auto ret = host_arena::make_unique(ft); ret->m_low_thresh_PCNT = modv.m_IVL(); ret->m_high_thresh_PCNT = modv.m_IVH(); @@ -1414,7 +1414,7 @@ void setup_t::delete_empty_nets() { m_nlstate.nets().erase( std::remove_if(m_nlstate.nets().begin(), m_nlstate.nets().end(), - [](owned_pool_ptr &net) + [](device_arena::owned_ptr &net) { if (!net->has_connections()) { @@ -1444,7 +1444,7 @@ void setup_t::prepare_to_run() for (auto & e : m_abstract.m_defparams) { - auto param(plib::make_unique(nlstate(), e.first, e.second)); + auto param(host_arena::make_unique(nlstate(), e.first, e.second)); register_param_t(*param); m_defparam_lifetime.push_back(std::move(param)); } @@ -1595,7 +1595,7 @@ bool source_netlist_t::parse(nlparse_t &setup, const pstring &name) source_string_t::stream_ptr source_string_t::stream(const pstring &name) { plib::unused_var(name); - auto ret(plib::make_unique(m_str)); + auto ret(std::make_unique(m_str)); ret->imbue(std::locale::classic()); return std::move(ret); // FIXME: for c++11 clang builds } @@ -1603,7 +1603,7 @@ source_string_t::stream_ptr source_string_t::stream(const pstring &name) source_mem_t::stream_ptr source_mem_t::stream(const pstring &name) { plib::unused_var(name); - auto ret(plib::make_unique(m_str, std::ios_base::binary)); + auto ret(std::make_unique(m_str, std::ios_base::binary)); ret->imbue(std::locale::classic()); return std::move(ret); // FIXME: for c++11 clang builds } @@ -1611,7 +1611,7 @@ source_mem_t::stream_ptr source_mem_t::stream(const pstring &name) source_file_t::stream_ptr source_file_t::stream(const pstring &name) { plib::unused_var(name); - auto ret(plib::make_unique(plib::filesystem::u8path(m_filename))); + auto ret(std::make_unique(plib::filesystem::u8path(m_filename))); return (ret->is_open()) ? std::move(ret) : stream_ptr(nullptr); } diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 5ca6233e8fa..9e6714007f0 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -307,7 +307,7 @@ namespace netlist void register_param(const pstring ¶m, nl_fptype value); template - typename std::enable_if::value || plib::is_integral::value>::type + std::enable_if_t::value || plib::is_integral::value> register_param_val(const pstring ¶m, T value) { register_param(param, static_cast(value)); @@ -323,7 +323,7 @@ namespace netlist { static_assert(std::is_base_of::value, "S must inherit from plib::psource_t"); - auto src(plib::make_unique(std::forward(args)...)); + auto src(std::make_unique(std::forward(args)...)); m_sources.add_source(std::move(src)); } @@ -351,7 +351,7 @@ namespace netlist { static_assert(std::is_base_of::value, "S must inherit from plib::psource_t"); - auto src(plib::make_unique(std::forward(args)...)); + auto src(std::make_unique(std::forward(args)...)); m_includes.add_source(std::move(src)); } @@ -486,15 +486,15 @@ namespace netlist models_t m_models; // FIXME: currently only used during setup - devices::nld_netlistparams *m_netlist_params; + devices::nld_netlistparams * m_netlist_params; // FIXME: can be cleared before run std::unordered_map m_terminals; - std::unordered_map m_connected_terminals; - std::unordered_map m_params; + std::unordered_map m_connected_terminals; + std::unordered_map m_params; std::unordered_map m_proxies; - std::vector> m_defparam_lifetime; + devices::nld_base_proxy *> m_proxies; + std::vector> m_defparam_lifetime; unsigned m_proxy_cnt; }; diff --git a/src/lib/netlist/nltypes.h b/src/lib/netlist/nltypes.h index f7ccb9b53ec..0d34186bdc1 100644 --- a/src/lib/netlist/nltypes.h +++ b/src/lib/netlist/nltypes.h @@ -73,6 +73,19 @@ namespace netlist /// using netlist_sig_t = std::uint32_t; + /// \brief The memory pool for netlist objects + /// + /// \note This is not the right location yet. + /// + + using device_arena = std::conditional::type; + + using host_arena = plib::aligned_arena; + +#if 0 + template + using host_unique_ptr = host_arena::unique_ptr; +#endif /// \brief Interface definition for netlist callbacks into calling code /// /// A class inheriting from netlist_callbacks_t has to be passed to the netlist_t @@ -99,7 +112,7 @@ namespace netlist /// of a callbacks_t implementation to optionally provide such a collection /// of symbols. /// - virtual plib::unique_ptr static_solver_lib() const; + virtual host_arena::unique_ptr static_solver_lib() const; }; using log_type = plib::plog_base; @@ -108,28 +121,6 @@ namespace netlist // Types needed by various includes //============================================================ - /// \brief The memory pool for netlist objects - /// - /// \note This is not the right location yet. - /// - -#if (NL_USE_MEMPOOL) - using nlmempool = plib::mempool_arena; -#else - using nlmempool = plib::aligned_arena; -#endif - - /// \brief Owned pointer type for pooled allocations. - /// - template - using owned_pool_ptr = nlmempool::owned_pool_ptr; - - /// \brief Unique pointer type for pooled allocations. - /// - - template - using unique_pool_ptr = nlmempool::unique_pool_ptr; - namespace detail { /// \brief Enum specifying the type of object diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h index ae8f29dec13..3d52e3af737 100644 --- a/src/lib/netlist/plib/palloc.h +++ b/src/lib/netlist/plib/palloc.h @@ -38,15 +38,15 @@ namespace plib { template - struct arena_deleter::type> + struct arena_deleter> { using arena_storage_type = P; constexpr arena_deleter(arena_storage_type *a = nullptr) noexcept : m_a(a) { } - template::value>::type> + template::value>> arena_deleter(const arena_deleter &rhs) noexcept : m_a(rhs.m_a) { } @@ -61,7 +61,7 @@ namespace plib { }; template - struct arena_deleter::type> + struct arena_deleter> { using arena_storage_type = P; @@ -296,11 +296,14 @@ namespace plib { template using allocator_type = arena_allocator; + template + using deleter_type = arena_deleter; + template - using unique_pool_ptr = std::unique_ptr>; + using unique_ptr = std::unique_ptr>; template - using owned_pool_ptr = plib::owned_ptr>; + using owned_ptr = plib::owned_ptr>; static inline aligned_arena &instance() noexcept { @@ -345,14 +348,14 @@ namespace plib { } template - unique_pool_ptr make_unique(Args&&... args) + static inline unique_ptr make_unique(Args&&... args) { auto *mem = allocate(alignof(T), sizeof(T)); try { // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) auto *mema = new (mem) T(std::forward(args)...); - return unique_pool_ptr(mema, arena_deleter(this)); + return unique_ptr(mema, deleter_type()); } catch (...) { @@ -362,14 +365,14 @@ namespace plib { } template - owned_pool_ptr make_owned(Args&&... args) + static inline owned_ptr make_owned(Args&&... args) { auto *mem = allocate(alignof(T), sizeof(T)); try { // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) auto *mema = new (mem) T(std::forward(args)...); - return owned_pool_ptr(mema, true, arena_deleter(*this)); + return owned_ptr(mema, true, deleter_type()); } catch (...) { @@ -432,15 +435,6 @@ namespace plib { #endif } - template - using unique_ptr = aligned_arena::unique_pool_ptr; - - template - plib::unique_ptr make_unique(Args&&... args) - { - return aligned_arena::instance().make_unique(std::forward(args)...); - } - template using aligned_allocator = aligned_arena::allocator_type; @@ -460,7 +454,7 @@ namespace plib { }; template - struct align_traits::value, void>::type> + struct align_traits::value, void>> { static constexpr const std::size_t align_size = T::align_size; static constexpr const std::size_t value_size = sizeof(typename T::value_type); diff --git a/src/lib/netlist/plib/parray.h b/src/lib/netlist/plib/parray.h index 50ee97bc0a5..0d89a56195c 100644 --- a/src/lib/netlist/plib/parray.h +++ b/src/lib/netlist/plib/parray.h @@ -64,19 +64,19 @@ namespace plib { using value_type = typename base_type::value_type; template - parray(size_type size, typename std::enable_if<(X==0), int>::type = 0) + parray(size_type size, std::enable_if_t<(X==0), int> = 0) : m_a(size), m_size(size) { } template - parray(size_type size, FT val, typename std::enable_if<(X==0), int>::type = 0) + parray(size_type size, FT val, std::enable_if_t<(X==0), int> = 0) : m_a(size, val), m_size(size) { } template - parray(size_type size, typename std::enable_if<(X != 0), int>::type = 0) noexcept(false) + parray(size_type size, std::enable_if_t<(X != 0), int> = 0) noexcept(false) : m_size(size) { if ((SIZE < 0 && size > SIZEABS()) @@ -85,7 +85,7 @@ namespace plib { } template - parray(size_type size, FT val, typename std::enable_if<(X != 0), int>::type = 0) noexcept(false) + parray(size_type size, FT val, std::enable_if_t<(X != 0), int> = 0) noexcept(false) : m_size(size) { if ((SIZE < 0 && size > SIZEABS()) diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h index 6710beba6c4..793c59bf954 100644 --- a/src/lib/netlist/plib/pfmtlog.h +++ b/src/lib/netlist/plib/pfmtlog.h @@ -203,15 +203,15 @@ namespace plib { operator pstring() const { return m_str; } template - typename std::enable_if::value, pfmt &>::type + std::enable_if_t::value, pfmt &> f(const T &x) {return format_element('f', x); } template - typename std::enable_if::value, pfmt &>::type + std::enable_if_t::value, pfmt &> e(const T &x) {return format_element('e', x); } template - typename std::enable_if::value, pfmt &>::type + std::enable_if_t::value, pfmt &> g(const T &x) {return format_element('g', x); } pfmt &operator ()(const void *x) {return format_element('p', x); } @@ -241,14 +241,14 @@ namespace plib { } template - typename std::enable_if::value, pfmt &>::type + std::enable_if_t::value, pfmt &> x(const T &x) { return format_element('x', x); } template - typename std::enable_if::value, pfmt &>::type + std::enable_if_t::value, pfmt &> o(const T &x) { return format_element('o', x); diff --git a/src/lib/netlist/plib/pfunction.cpp b/src/lib/netlist/plib/pfunction.cpp index b424aae7e2d..c5e011dfbb9 100644 --- a/src/lib/netlist/plib/pfunction.cpp +++ b/src/lib/netlist/plib/pfunction.cpp @@ -279,7 +279,7 @@ namespace plib { } template - static inline typename std::enable_if::value, NT>::type + static inline std::enable_if_t::value, NT> lfsr_random(std::uint16_t &lfsr) noexcept { std::uint16_t lsb = lfsr & 1; @@ -290,7 +290,7 @@ namespace plib { } template - static inline typename std::enable_if::value, NT>::type + static inline std::enable_if_t::value, NT> lfsr_random(std::uint16_t &lfsr) noexcept { std::uint16_t lsb = lfsr & 1; diff --git a/src/lib/netlist/plib/pmath.h b/src/lib/netlist/plib/pmath.h index 5c5f8704716..652cff059d2 100644 --- a/src/lib/netlist/plib/pmath.h +++ b/src/lib/netlist/plib/pmath.h @@ -97,7 +97,7 @@ namespace plib /// \return reciprocal of argument /// template - static inline constexpr typename std::enable_if::value, T>::type + static inline constexpr std::enable_if_t::value, T> reciprocal(T v) noexcept { return constants::one() / v; @@ -110,7 +110,7 @@ namespace plib /// \return absolute value of argument /// template - static inline constexpr typename std::enable_if::value, T>::type + static inline constexpr std::enable_if_t::value, T> abs(T v) noexcept { return std::abs(v); @@ -123,7 +123,7 @@ namespace plib /// \return absolute value of argument /// template - static inline constexpr typename std::enable_if::value, T>::type + static inline constexpr std::enable_if_t::value, T> sqrt(T v) noexcept { return std::sqrt(v); @@ -137,7 +137,7 @@ namespace plib /// \return sqrt(v1*v1+v2*v2) /// template - static inline constexpr typename std::enable_if::value, T>::type + static inline constexpr std::enable_if_t::value, T> hypot(T v1, T v2) noexcept { return std::hypot(v1, v2); @@ -150,7 +150,7 @@ namespace plib /// \return exp(v) /// template - static inline constexpr typename std::enable_if::value, T>::type + static inline constexpr std::enable_if_t::value, T> exp(T v) noexcept { return std::exp(v); @@ -163,7 +163,7 @@ namespace plib /// \return log(v) /// template - static inline constexpr typename std::enable_if::value, T>::type + static inline constexpr std::enable_if_t::value, T> log(T v) noexcept { return std::log(v); @@ -176,7 +176,7 @@ namespace plib /// \return tanh(v) /// template - static inline constexpr typename std::enable_if::value, T>::type + static inline constexpr std::enable_if_t::value, T> tanh(T v) noexcept { return std::tanh(v); @@ -189,7 +189,7 @@ namespace plib /// \return floor(v) /// template - static inline constexpr typename std::enable_if::value, T>::type + static inline constexpr std::enable_if_t::value, T> floor(T v) noexcept { return std::floor(v); @@ -202,7 +202,7 @@ namespace plib /// \return log(1 + v) /// template - static inline constexpr typename std::enable_if::value, T>::type + static inline constexpr std::enable_if_t::value, T> log1p(T v) noexcept { return std::log1p(v); @@ -215,7 +215,7 @@ namespace plib /// \return sin(v) /// template - static inline constexpr typename std::enable_if::value, T>::type + static inline constexpr std::enable_if_t::value, T> sin(T v) noexcept { return std::sin(v); @@ -228,7 +228,7 @@ namespace plib /// \return cos(v) /// template - static inline constexpr typename std::enable_if::value, T>::type + static inline constexpr std::enable_if_t::value, T> cos(T v) noexcept { return std::cos(v); @@ -241,7 +241,7 @@ namespace plib /// \return trunc(v) /// template - static inline constexpr typename std::enable_if::value, T>::type + static inline constexpr std::enable_if_t::value, T> trunc(T v) noexcept { return std::trunc(v); @@ -255,7 +255,7 @@ namespace plib /// \return signum(v) /// template - static inline constexpr typename std::enable_if::value, T>::type + static inline constexpr std::enable_if_t::value, T> signum(T v, T r = static_cast(1)) { constexpr const auto z(static_cast(0)); @@ -377,7 +377,7 @@ namespace plib /// template constexpr - typename std::enable_if::value && plib::is_signed::value, T>::type + std::enable_if_t::value && plib::is_signed::value, T> abs(T v) noexcept { return v < 0 ? -v : v; @@ -391,7 +391,7 @@ namespace plib /// template constexpr - typename std::enable_if::value && plib::is_unsigned::value, T>::type + std::enable_if_t::value && plib::is_unsigned::value, T> abs(T v) noexcept { return v; diff --git a/src/lib/netlist/plib/pmempool.h b/src/lib/netlist/plib/pmempool.h index 10c1fe58f53..fca4988b639 100644 --- a/src/lib/netlist/plib/pmempool.h +++ b/src/lib/netlist/plib/pmempool.h @@ -39,10 +39,10 @@ namespace plib { using allocator_type = arena_allocator; template - using owned_pool_ptr = plib::owned_ptr>; + using owned_ptr = plib::owned_ptr>; template - using unique_pool_ptr = std::unique_ptr>; + using unique_ptr = std::unique_ptr>; mempool_arena(size_t min_alloc = (1<<21), size_t min_align = PALIGN_CACHELINE) : m_min_alloc(min_alloc) @@ -137,14 +137,14 @@ namespace plib { } template - owned_pool_ptr make_owned(Args&&... args) + owned_ptr make_owned(Args&&... args) { auto *mem = this->allocate(alignof(T), sizeof(T)); try { // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) auto *mema = new (mem) T(std::forward(args)...); - return owned_pool_ptr(mema, true, arena_deleter(this)); + return owned_ptr(mema, true, arena_deleter(this)); } catch (...) { @@ -154,14 +154,14 @@ namespace plib { } template - unique_pool_ptr make_unique(Args&&... args) + unique_ptr make_unique(Args&&... args) { auto *mem = this->allocate(alignof(T), sizeof(T)); try { // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) auto *mema = new (mem) T(std::forward(args)...); - return unique_pool_ptr(mema, arena_deleter(this)); + return unique_ptr(mema, arena_deleter(this)); } catch (...) { diff --git a/src/lib/netlist/plib/ppreprocessor.cpp b/src/lib/netlist/plib/ppreprocessor.cpp index d8909449403..f13d3aeef43 100644 --- a/src/lib/netlist/plib/ppreprocessor.cpp +++ b/src/lib/netlist/plib/ppreprocessor.cpp @@ -516,14 +516,14 @@ namespace plib { arg = arg.substr(1, arg.length() - 2); // first try local context auto l(plib::util::buildpath({m_stack.back().m_local_path, arg})); - auto lstrm(m_sources.get_stream<>(l)); + auto lstrm(m_sources.get_stream(l)); if (lstrm) { m_stack.emplace_back(input_context(std::move(lstrm), plib::util::path(l), l)); } else { - auto strm(m_sources.get_stream<>(arg)); + auto strm(m_sources.get_stream(arg)); if (strm) { m_stack.emplace_back(input_context(std::move(strm), plib::util::path(arg), arg)); diff --git a/src/lib/netlist/plib/pstate.h b/src/lib/netlist/plib/pstate.h index 59e7d5006f1..d4d98c20785 100644 --- a/src/lib/netlist/plib/pstate.h +++ b/src/lib/netlist/plib/pstate.h @@ -194,8 +194,8 @@ protected: private: template - typename std::enable_if::value || std::is_enum::value - || plib::is_floating_point::value>::type + std::enable_if_t::value || std::is_enum::value + || plib::is_floating_point::value> save_item_dispatch(const void *owner, C &state, const pstring &stname) { save_state_ptr( owner, stname, dtype(), 1, &state); @@ -203,8 +203,8 @@ private: template - typename std::enable_if::value || std::is_enum::value - || plib::is_floating_point::value)>::type + std::enable_if_t::value || std::is_enum::value + || plib::is_floating_point::value)> save_item_dispatch(const void *owner, C &state, const pstring &stname) { saver_t sav(*this, owner, stname); diff --git a/src/lib/netlist/plib/pstonum.h b/src/lib/netlist/plib/pstonum.h index 7336558d01a..630dee68422 100644 --- a/src/lib/netlist/plib/pstonum.h +++ b/src/lib/netlist/plib/pstonum.h @@ -49,7 +49,7 @@ namespace plib struct pstonum_helper; template - struct pstonum_helper::value && plib::is_signed::value>::type> + struct pstonum_helper::value && plib::is_signed::value>> { template long long operator()(std::locale loc, const S &arg, std::size_t *idx) @@ -60,7 +60,7 @@ namespace plib }; template - struct pstonum_helper::value && !plib::is_signed::value>::type> + struct pstonum_helper::value && !plib::is_signed::value>> { template unsigned long long operator()(std::locale loc, const S &arg, std::size_t *idx) @@ -71,7 +71,7 @@ namespace plib }; template - struct pstonum_helper::value>::type> + struct pstonum_helper::value>> { template long double operator()(std::locale loc, const S &arg, std::size_t *idx) diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h index 8c8eb70ef76..45aa8b18e83 100644 --- a/src/lib/netlist/plib/pstream.h +++ b/src/lib/netlist/plib/pstream.h @@ -46,7 +46,7 @@ public: { } - putf8_reader(plib::unique_ptr &&rhs) noexcept + putf8_reader(std::unique_ptr &&rhs) noexcept : m_strm(std::move(rhs)) { } @@ -104,7 +104,7 @@ public: std::istream &stream() { return *m_strm; } private: - plib::unique_ptr m_strm; + std::unique_ptr m_strm; putf8string m_linebuf; }; diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h index 57e575fdefa..622d8548bd1 100644 --- a/src/lib/netlist/plib/pstring.h +++ b/src/lib/netlist/plib/pstring.h @@ -103,14 +103,14 @@ public: // mingw treats string constants as char* instead of char[N] template::value>::type> + class = std::enable_if_t::value>> pstring_t(const C *string) : m_str(string) { } template::value>::type> + class = std::enable_if_t::value>> pstring_t(C (&string)[N]) noexcept(false) // NOLINT(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays) { static_assert(N > 0,"pstring from array of length 0"); @@ -136,7 +136,7 @@ public: } template ::value>::type> + class = std::enable_if_t::value>> explicit pstring_t(const pstring_t &string) { m_str.clear(); @@ -148,7 +148,7 @@ public: template ::value>::type> + class = std::enable_if_t::value>> pstring_t &operator=(const pstring_t &string) { m_str.clear(); diff --git a/src/lib/netlist/plib/ptime.h b/src/lib/netlist/plib/ptime.h index 58c94641cfc..9bbd1e35671 100644 --- a/src/lib/netlist/plib/ptime.h +++ b/src/lib/netlist/plib/ptime.h @@ -111,7 +111,7 @@ namespace plib } template - constexpr typename std::enable_if::value, ptime>::type + constexpr std::enable_if_t::value, ptime> operator/(const T &rhs) const noexcept { return ptime(m_time / rhs); @@ -190,7 +190,7 @@ namespace plib static constexpr ptime from_raw(internal_type raw) noexcept { return ptime(raw); } template - static constexpr typename std::enable_if::value, ptime>::type + static constexpr std::enable_if_t::value, ptime> from_fp(FT t) noexcept { return ptime(static_cast(plib::floor(t * static_cast(RES) + static_cast(0.5))), RES); } static constexpr ptime from_double(double t) noexcept diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h index 401cc35e262..20ea01e890e 100644 --- a/src/lib/netlist/plib/putil.h +++ b/src/lib/netlist/plib/putil.h @@ -15,6 +15,7 @@ #include #include #include +#include #define PSTRINGIFY_HELP(y) # y #define PSTRINGIFY(x) PSTRINGIFY_HELP(x) @@ -153,7 +154,7 @@ namespace plib { public: - using stream_ptr = plib::unique_ptr; + using stream_ptr = std::unique_ptr; psource_t() noexcept = default; @@ -170,10 +171,7 @@ namespace plib /// Will return the given string when name matches. /// Is used in preprocessor code to eliminate inclusion of certain files. /// - /// \tparam TS base stream class. Default is psource_t - /// - template - class psource_str_t : public TS + class psource_str_t : public psource_t { public: psource_str_t(pstring name, pstring str) @@ -183,10 +181,12 @@ namespace plib PCOPYASSIGNMOVE(psource_str_t, delete) ~psource_str_t() noexcept override = default; - typename TS::stream_ptr stream(const pstring &name) override + typename psource_t::stream_ptr stream(const pstring &name) override { - return (name == m_name) ? - plib::make_unique(m_str) : typename TS::stream_ptr(nullptr); + if (name == m_name) + return std::make_unique(m_str); + + return psource_t::stream_ptr(nullptr); } private: pstring m_name; @@ -195,13 +195,13 @@ namespace plib /// \brief Generic sources collection. /// - /// \tparam TS base stream class. Default is psource_t + /// \tparam ARENA memory arena, defaults to aligned_arena /// - template + template class psource_collection_t { public: - using source_type = plib::unique_ptr; + using source_type = std::unique_ptr; using list_t = std::vector; psource_collection_t() noexcept = default; @@ -214,8 +214,8 @@ namespace plib m_collection.push_back(std::move(src)); } - template - typename S::stream_ptr get_stream(pstring name) + template + typename psource_t::stream_ptr get_stream(pstring name) { for (auto &s : m_collection) { diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index 938fe4b32ed..e267a19c60d 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -201,7 +201,7 @@ public: stream_ptr stream(const pstring &file) override { pstring name = m_folder + "/" + file; - auto strm(plib::make_unique(plib::filesystem::u8path(name))); + auto strm(std::make_unique(plib::filesystem::u8path(name))); if (strm->fail()) return stream_ptr(nullptr); @@ -222,17 +222,17 @@ public: void vlog(const plib::plog_level &l, const pstring &ls) const noexcept override; - plib::unique_ptr static_solver_lib() const override + netlist::host_arena::unique_ptr static_solver_lib() const override { if (m_boostlib == "builtin") - return plib::make_unique(nl_static_solver_syms); + return netlist::host_arena::make_unique(nl_static_solver_syms); if (m_boostlib == "generic") - return plib::make_unique(nullptr); + return netlist::host_arena::make_unique(nullptr); if (NL_DISABLE_DYNAMIC_LOAD) throw netlist::nl_exception("Dynamic library loading not supported due to project security concerns."); //pstring libpath = plib::util::environment("NL_BOOSTLIB", plib::util::buildpath({".", "nlboost.so"})); - return plib::make_unique(m_boostlib); + return netlist::host_arena::make_unique(m_boostlib); } private: @@ -245,7 +245,7 @@ class netlist_tool_t : public netlist::netlist_state_t public: netlist_tool_t(tool_app_t &app, const pstring &name, const pstring &boostlib) - : netlist::netlist_state_t(name, plib::make_unique(app, boostlib)) + : netlist::netlist_state_t(name, netlist::host_arena::make_unique(app, boostlib)) { } @@ -385,7 +385,7 @@ static std::vector read_input(const netlist::setup_t &setup, const pstr std::vector ret; if (fname != "") { - plib::putf8_reader r = plib::putf8_reader(plib::make_unique(plib::filesystem::u8path(fname))); + plib::putf8_reader r = plib::putf8_reader(std::make_unique(plib::filesystem::u8path(fname))); if (r.stream().fail()) throw netlist::nl_exception(netlist::MF_FILE_OPEN_ERROR(fname)); r.stream().imbue(std::locale::classic()); @@ -626,7 +626,7 @@ void tool_app_t::static_compile() names.push_back(opt_name()); else { - plib::putf8_reader r = plib::putf8_reader(plib::make_unique(plib::filesystem::u8path(f))); + plib::putf8_reader r = plib::putf8_reader(std::make_unique(plib::filesystem::u8path(f))); if (r.stream().fail()) throw netlist::nl_exception(netlist::MF_FILE_OPEN_ERROR(f)); r.stream().imbue(std::locale::classic()); @@ -706,7 +706,7 @@ struct doc_ext static doc_ext read_docsrc(const pstring &fname, const pstring &id) { - plib::putf8_reader r = plib::putf8_reader(plib::make_unique(plib::filesystem::u8path(fname))); + plib::putf8_reader r = plib::putf8_reader(std::make_unique(plib::filesystem::u8path(fname))); if (r.stream().fail()) throw netlist::nl_exception(netlist::MF_FILE_OPEN_ERROR(fname)); r.stream().imbue(std::locale::classic()); @@ -1057,7 +1057,7 @@ void tool_app_t::listdevices() nt.parser().include("dummy"); nt.setup().prepare_to_run(); - std::vector> devs; + std::vector> devs; for (auto & fl : list) { @@ -1123,19 +1123,19 @@ void tool_app_t::convert() pstring result; if (opt_type.as_string() == "spice") { - nl_convert_spice_t c; + netlist::convert::nl_convert_spice_t c; c.convert(contents); result = c.result(); } else if (opt_type.as_string() == "eagle") { - nl_convert_eagle_t c; + netlist::convert::nl_convert_eagle_t c; c.convert(contents); result = c.result(); } else if (opt_type.as_string() == "rinf") { - nl_convert_rinf_t c; + netlist::convert::nl_convert_rinf_t c; c.convert(contents); result = c.result(); } diff --git a/src/lib/netlist/prg/nlwav.cpp b/src/lib/netlist/prg/nlwav.cpp index 291aa5b2ff7..9e3ba795554 100755 --- a/src/lib/netlist/prg/nlwav.cpp +++ b/src/lib/netlist/prg/nlwav.cpp @@ -27,6 +27,8 @@ // http://de.wikipedia.org/wiki/RIFF_WAVE // +using arena = plib::aligned_arena; + class wav_t { public: @@ -216,7 +218,7 @@ public: return success; } - void process(std::vector> &is) + void process(std::vector> &is) { std::vector readers; for (auto &i : is) @@ -644,7 +646,7 @@ private: plib::option_example opt_ex1; plib::option_example opt_ex2; plib::option_example opt_ex3; - std::vector> m_instrms; + std::vector> m_instrms; }; void nlwav_app::convert_wav(std::ostream &ostrm, wav_t::format fmt) @@ -653,10 +655,10 @@ void nlwav_app::convert_wav(std::ostream &ostrm, wav_t::format fmt) double dt = plib::reciprocal(static_cast(opt_rate())); auto nchan = m_instrms.size(); - auto wo = plib::make_unique(ostrm, opt_out() != "-", fmt, nchan, opt_rate(), opt_amp()); - auto ago = plib::make_unique(nchan, dt, aggregator::callback_type(&wavwriter::process, wo.get())); - auto fgo_hp = plib::make_unique(opt_highpass(), opt_hpboost(), nchan, filter_hp::callback_type(&aggregator::process, ago.get())); - auto fgo_lp = plib::make_unique(opt_lowpass(), nchan, filter_lp::callback_type(&filter_hp::process, fgo_hp.get())); + auto wo = arena::make_unique(ostrm, opt_out() != "-", fmt, nchan, opt_rate(), opt_amp()); + auto ago = arena::make_unique(nchan, dt, aggregator::callback_type(&wavwriter::process, wo.get())); + auto fgo_hp = arena::make_unique(opt_highpass(), opt_hpboost(), nchan, filter_hp::callback_type(&aggregator::process, ago.get())); + auto fgo_lp = arena::make_unique(opt_lowpass(), nchan, filter_lp::callback_type(&filter_hp::process, fgo_hp.get())); auto topcb = log_processor::callback_type(&filter_lp::process, fgo_lp.get()); @@ -678,7 +680,7 @@ void nlwav_app::convert_wav(std::ostream &ostrm, wav_t::format fmt) void nlwav_app::convert_vcd(std::ostream &ostrm, vcdwriter::format_e format) { - plib::unique_ptr wo = plib::make_unique(ostrm, opt_args(), + arena::unique_ptr wo = arena::make_unique(ostrm, opt_args(), format, opt_high(), opt_low()); log_processor::callback_type agcb = log_processor::callback_type(&vcdwriter::process, wo.get()); @@ -700,7 +702,7 @@ void nlwav_app::convert_vcd(std::ostream &ostrm, vcdwriter::format_e format) void nlwav_app::convert_tab(std::ostream &ostrm) { - auto wo = plib::make_unique(ostrm, opt_args(), + auto wo = arena::make_unique(ostrm, opt_args(), opt_start(), opt_inc(), opt_samples()); log_processor::callback_type agcb = log_processor::callback_type(&tabwriter::process, wo.get()); @@ -793,16 +795,16 @@ int nlwav_app::execute() { for (const auto &oi: opt_args()) { - plib::unique_ptr fin; + std::unique_ptr fin; if (oi == "-") { - auto temp(plib::make_unique()); + auto temp(std::make_unique()); plib::copystream(*temp, std::cin); fin = std::move(temp); } else { - fin = plib::make_unique(plib::filesystem::u8path(oi), std::ios::in); + fin = std::make_unique(plib::filesystem::u8path(oi), std::ios::in); if (fin->fail()) throw plib::file_open_e(oi); } diff --git a/src/lib/netlist/solver/nld_matrix_solver.h b/src/lib/netlist/solver/nld_matrix_solver.h index 09d210fcf55..fef3ec4a29b 100644 --- a/src/lib/netlist/solver/nld_matrix_solver.h +++ b/src/lib/netlist/solver/nld_matrix_solver.h @@ -289,7 +289,7 @@ namespace solver private: plib::aligned_vector m_rails_temp; - std::vector> m_inps; + std::vector> m_inps; state_var m_stat_calculations; state_var m_stat_newton_raphson; diff --git a/src/lib/netlist/solver/nld_solver.cpp b/src/lib/netlist/solver/nld_solver.cpp index 2cd092cdbdd..c7e8242d83a 100644 --- a/src/lib/netlist/solver/nld_solver.cpp +++ b/src/lib/netlist/solver/nld_solver.cpp @@ -1,30 +1,6 @@ // license:GPL-2.0+ // copyright-holders:Couriersud -// Commented out for now. Relatively low number of terminals / nets make -// the vectorizations fast-math enables pretty expensive -// -#if 0 -#pragma GCC optimize "-ftree-vectorize" -#pragma GCC optimize "-ffast-math" -#pragma GCC optimize "-funsafe-math-optimizations" -#pragma GCC optimize "-funroll-loops" -#pragma GCC optimize "-funswitch-loops" -#pragma GCC optimize "-fstrict-aliasing" -#pragma GCC optimize "tree-vectorizer-verbose=7" -#pragma GCC optimize "opt-info-vec" -#pragma GCC optimize "opt-info-vec-missed" -//#pragma GCC optimize "tree-parallelize-loops=4" -#pragma GCC optimize "variable-expansion-in-unroller" -#pragma GCC optimize "unsafe-loop-optimizations" -#pragma GCC optimize "vect-cost-model" -#pragma GCC optimize "variable-expansion-in-unroller" -#pragma GCC optimize "tree-loop-if-convert-stores" -#pragma GCC optimize "tree-loop-distribution" -#pragma GCC optimize "tree-loop-im" -#pragma GCC optimize "tree-loop-ivcanon" -#pragma GCC optimize "ivopts" -#endif #include "netlist/nl_factory.h" #include "netlist/nl_setup.h" // FIXME: only needed for splitter code @@ -42,6 +18,7 @@ #include "plib/pomp.h" #include +#include namespace netlist { @@ -104,16 +81,17 @@ namespace devices } } + // FIXME: should be created in device space template - plib::unique_ptr create_it(netlist_state_t &nl, pstring name, + host_arena::unique_ptr create_it(netlist_state_t &nl, pstring name, analog_net_t::list_t &nets, solver::solver_parameters_t ¶ms, std::size_t size) { - return plib::make_unique(nl, name, nets, ¶ms, size); + return host_arena::make_unique(nl, name, nets, ¶ms, size); } template - plib::unique_ptr NETLIB_NAME(solver)::create_solver(std::size_t size, + host_arena::unique_ptr NETLIB_NAME(solver)::create_solver(std::size_t size, const pstring &solvername, analog_net_t::list_t &nets) { @@ -146,11 +124,11 @@ namespace devices return create_it>(state(), solvername, nets, m_params, size); #endif } - return plib::unique_ptr(); + return host_arena::unique_ptr(); } template - plib::unique_ptr NETLIB_NAME(solver)::create_solvers( + host_arena::unique_ptr NETLIB_NAME(solver)::create_solvers( const pstring &sname, analog_net_t::list_t &nets) { @@ -158,10 +136,10 @@ namespace devices switch (net_count) { case 1: - return plib::make_unique>(state(), sname, nets, &m_params); + return host_arena::make_unique>(state(), sname, nets, &m_params); break; case 2: - return plib::make_unique>(state(), sname, nets, &m_params); + return host_arena::make_unique>(state(), sname, nets, &m_params); break; case 3: return create_solver(3, sname, nets); @@ -322,29 +300,23 @@ namespace devices log().verbose("Found {1} net groups in {2} nets\n", splitter.groups.size(), state().nets().size()); for (auto & grp : splitter.groups) { - plib::unique_ptr ms; + host_arena::unique_ptr ms; pstring sname = plib::pfmt("Solver_{1}")(m_mat_solvers.size()); switch (m_params.m_fp_type()) { case solver::matrix_fp_type_e::FLOAT: -#if (NL_USE_FLOAT_MATRIX) - ms = create_solvers(sname, grp); -#else - log().info("FPTYPE {1} not supported. Using DOUBLE", m_params.m_fp_type().name()); - ms = create_solvers(sname, grp); -#endif + if (NL_USE_FLOAT_MATRIX) + log().info("FPTYPE {1} not supported. Using DOUBLE", m_params.m_fp_type().name()); + ms = create_solvers>(sname, grp); break; case solver::matrix_fp_type_e::DOUBLE: ms = create_solvers(sname, grp); break; case solver::matrix_fp_type_e::LONGDOUBLE: -#if (NL_USE_LONG_DOUBLE_MATRIX) - ms = create_solvers(sname, grp); -#else - log().info("FPTYPE {1} not supported. Using DOUBLE", m_params.m_fp_type().name()); - ms = create_solvers(sname, grp); -#endif + if (NL_USE_LONG_DOUBLE_MATRIX) + log().info("FPTYPE {1} not supported. Using DOUBLE", m_params.m_fp_type().name()); + ms = create_solvers>(sname, grp); break; case solver::matrix_fp_type_e::FLOATQ128: #if (NL_USE_FLOAT128) diff --git a/src/lib/netlist/solver/nld_solver.h b/src/lib/netlist/solver/nld_solver.h index 46c335804f4..a0c28e6b302 100644 --- a/src/lib/netlist/solver/nld_solver.h +++ b/src/lib/netlist/solver/nld_solver.h @@ -51,18 +51,19 @@ namespace devices logic_input_t m_fb_step; logic_output_t m_Q_step; - std::vector> m_mat_solvers; + // FIXME: these should be created in device space + std::vector> m_mat_solvers; std::vector m_mat_solvers_all; std::vector m_mat_solvers_timestepping; solver::solver_parameters_t m_params; template - plib::unique_ptr create_solver(std::size_t size, + host_arena::unique_ptr create_solver(std::size_t size, const pstring &solvername, analog_net_t::list_t &nets); template - plib::unique_ptr create_solvers( + host_arena::unique_ptr create_solvers( const pstring &sname, analog_net_t::list_t &nets); }; diff --git a/src/lib/netlist/tools/nl_convert.cpp b/src/lib/netlist/tools/nl_convert.cpp index 9ccd56301f4..393456a67f2 100644 --- a/src/lib/netlist/tools/nl_convert.cpp +++ b/src/lib/netlist/tools/nl_convert.cpp @@ -11,6 +11,12 @@ #include #include +namespace netlist +{ + +namespace convert +{ + // FIXME: temporarily defined here - should be in a file // FIXME: family logic in netlist is convoluted, create // define a model param on core device @@ -43,7 +49,7 @@ using lib_map_t = std::unordered_map; static lib_map_t read_lib_map(const pstring &lm) { - auto reader = plib::putf8_reader(plib::make_unique(lm)); + auto reader = plib::putf8_reader(std::make_unique(lm)); reader.stream().imbue(std::locale::classic()); lib_map_t m; pstring line; @@ -106,7 +112,7 @@ nl_convert_base_t::~nl_convert_base_t() void nl_convert_base_t::add_pin_alias(const pstring &devname, const pstring &name, const pstring &alias) { pstring pname = devname + "." + name; - m_pins.emplace(pname, plib::make_unique(pname, devname + "." + alias)); + m_pins.emplace(pname, arena::make_unique(pname, devname + "." + alias)); } void nl_convert_base_t::add_ext_alias(const pstring &alias) @@ -119,7 +125,7 @@ void nl_convert_base_t::add_ext_alias(const pstring &alias, const pstring &net) m_ext_alias.emplace_back(alias, net); } -void nl_convert_base_t::add_device(plib::unique_ptr dev) +void nl_convert_base_t::add_device(arena::unique_ptr dev) { for (auto & d : m_devs) if (d->name() == dev->name()) @@ -132,15 +138,15 @@ void nl_convert_base_t::add_device(plib::unique_ptr dev) void nl_convert_base_t::add_device(const pstring &atype, const pstring &aname, const pstring &amodel) { - add_device(plib::make_unique(atype, aname, amodel)); + add_device(arena::make_unique(atype, aname, amodel)); } void nl_convert_base_t::add_device(const pstring &atype, const pstring &aname, double aval) { - add_device(plib::make_unique(atype, aname, aval)); + add_device(arena::make_unique(atype, aname, aval)); } void nl_convert_base_t::add_device(const pstring &atype, const pstring &aname) { - add_device(plib::make_unique(atype, aname)); + add_device(arena::make_unique(atype, aname)); } void nl_convert_base_t::add_term(const pstring &netname, const pstring &termname) @@ -155,7 +161,7 @@ void nl_convert_base_t::add_term(const pstring &netname, const pstring &termname net = m_nets[netname].get(); else { - auto nets = plib::make_unique(netname); + auto nets = arena::make_unique(netname); net = nets.get(); m_nets.emplace(netname, std::move(nets)); } @@ -751,7 +757,7 @@ void nl_convert_eagle_t::tokenizer::verror(const pstring &msg) void nl_convert_eagle_t::convert(const pstring &contents) { - tokenizer tok(*this, plib::putf8_reader(plib::make_unique(contents))); + tokenizer tok(*this, plib::putf8_reader(std::make_unique(contents))); tok.stream().stream().imbue(std::locale::classic()); out("NETLIST_START(dummy)\n"); @@ -898,7 +904,7 @@ void nl_convert_rinf_t::tokenizer::verror(const pstring &msg) void nl_convert_rinf_t::convert(const pstring &contents) { - tokenizer tok(*this, plib::putf8_reader(plib::make_unique(contents))); + tokenizer tok(*this, plib::putf8_reader(std::make_unique(contents))); tok.stream().stream().imbue(std::locale::classic()); auto lm = read_lib_map(s_lib_map); @@ -1092,3 +1098,6 @@ void nl_convert_rinf_t::convert(const pstring &contents) } } + +} // namespace convert +} // namespace netlist diff --git a/src/lib/netlist/tools/nl_convert.h b/src/lib/netlist/tools/nl_convert.h index fec745b5c5e..a62a23b403f 100755 --- a/src/lib/netlist/tools/nl_convert.h +++ b/src/lib/netlist/tools/nl_convert.h @@ -8,6 +8,7 @@ /// \file nl_convert.h /// +#include "plib/palloc.h" #include "plib/pstring.h" #include "plib/ptokenizer.h" #include "plib/ptypes.h" @@ -18,6 +19,14 @@ // convert - convert a spice netlist // ------------------------------------------------- +namespace netlist +{ + +namespace convert +{ + +using arena = plib::aligned_arena; + class nl_convert_base_t { public: @@ -155,7 +164,7 @@ private: pstring m_alias; }; - void add_device(plib::unique_ptr dev); + void add_device(arena::unique_ptr dev); dev_t *get_device(const pstring &name) { for (auto &e : m_devs) @@ -166,10 +175,10 @@ private: std::stringstream m_buf; - std::vector> m_devs; - std::unordered_map > m_nets; + std::vector> m_devs; + std::unordered_map > m_nets; std::vector> m_ext_alias; - std::unordered_map> m_pins; + std::unordered_map> m_pins; std::vector m_units; pstring m_numberchars; @@ -266,4 +275,7 @@ private: }; +} // namespace convert +} // namespace netlist + #endif // NL_CONVERT_H_ -- cgit v1.2.3