From f6a7a6fe8822e0c86c521f8a8ea7b3923f923ab6 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sat, 18 Jan 2020 16:39:49 +0100 Subject: netlist: Code maintenance. (nw) Checked and fixed conditional compile paths. Simplified memory allocation. Generalized signal handling. --- src/lib/netlist/nl_base.h | 28 +++++++++++++++---------- src/lib/netlist/nl_config.h | 6 +++--- src/lib/netlist/plib/palloc.h | 46 ++++++++++++++++++++++++----------------- src/lib/netlist/plib/pconfig.h | 2 +- src/lib/netlist/plib/pmempool.h | 8 +++---- src/lib/netlist/plib/ppmf.h | 4 ++-- 6 files changed, 53 insertions(+), 41 deletions(-) diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 625696ddf93..d2ec68800bf 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -569,17 +569,24 @@ namespace netlist public plib::linkedlist_t::element_t { public: + /// \brief Number of signal bits + /// + /// Going forward setting this to 8 will allow 8-bit signal + /// busses to be used in netlist, e.g. for more complex memory + /// arrangements. + static constexpr const unsigned int INP_BITS = 1; + static constexpr const unsigned int INP_MASK = (1 << INP_BITS) - 1; static constexpr const unsigned int INP_HL_SHIFT = 0; - static constexpr const unsigned int INP_LH_SHIFT = 1; + static constexpr const unsigned int INP_LH_SHIFT = INP_BITS; enum state_e { STATE_INP_PASSIVE = 0, - STATE_INP_HL = (1 << INP_HL_SHIFT), - STATE_INP_LH = (1 << INP_LH_SHIFT), + STATE_INP_HL = (INP_MASK << INP_HL_SHIFT), + STATE_INP_LH = (INP_MASK << INP_LH_SHIFT), STATE_INP_ACTIVE = STATE_INP_HL | STATE_INP_LH, - STATE_OUT = 128, - STATE_BIDIR = 256 + STATE_OUT = (1 << (2*INP_BITS)), + STATE_BIDIR = (1 << (2*INP_BITS + 1)) }; core_terminal_t(core_device_t &dev, const pstring &aname, @@ -590,12 +597,11 @@ namespace netlist /// \brief The object type. /// \returns type of the object - terminal_type type() const noexcept(false); + /// \brief Checks if object is of specified type. /// \param atype type to check object against. /// \returns true if object is of specified type else false. - bool is_type(const terminal_type atype) const noexcept(false) { return (type() == atype); } void set_net(net_t *anet) noexcept { m_net = anet; } @@ -632,7 +638,7 @@ namespace netlist void set_delegate(const nldelegate &delegate) noexcept { m_delegate = delegate; } nldelegate &delegate() noexcept { return m_delegate; } const nldelegate &delegate() const noexcept { return m_delegate; } - void run_delegate() noexcept { m_delegate(); } + inline void run_delegate() noexcept { m_delegate(); } private: nldelegate m_delegate; net_t * m_net; @@ -762,7 +768,7 @@ namespace netlist private: state_var m_new_Q; state_var m_cur_Q; - state_var m_in_queue; // 0: not in queue, 1: in queue, 2: last was taken + state_var m_in_queue; state_var m_next_scheduled_time; core_terminal_t * m_railterminal; @@ -1858,7 +1864,7 @@ namespace netlist { m_next_scheduled_time = exec().time() + delay; - if (is_queued()) + if (!!is_queued()) exec().qremove(this); if (!m_list_active.empty()) @@ -2028,7 +2034,7 @@ namespace netlist // ----------------------------------------------------------------------------- template - inline void detail::net_t::process(const T mask, netlist_sig_t sig) noexcept + inline void detail::net_t::process(T mask, netlist_sig_t sig) noexcept { m_cur_Q = sig; diff --git a/src/lib/netlist/nl_config.h b/src/lib/netlist/nl_config.h index a918db4d590..0fc82ae4f79 100644 --- a/src/lib/netlist/nl_config.h +++ b/src/lib/netlist/nl_config.h @@ -17,11 +17,11 @@ /// /// \brief Version - Minor. /// -#define NL_VERSION_MINOR 6 +#define NL_VERSION_MINOR 7 /// /// \brief Version - Patch level. /// -#define NL_VERSION_PATCHLEVEL 0 +#define NL_VERSION_PATCHLEVEL 1 /// /// \addtogroup compiledefine @@ -61,7 +61,7 @@ /// This approach is stricter and should identify bugs in /// the netlist core faster. /// By default it is disabled since it is not as fast as -/// the default approach. It is up to 10% slower. +/// the default approach. It is up to 20% slower. /// #ifndef NL_USE_COPY_INSTEAD_OF_REFERENCE diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h index a21fe1b6932..1aa23682ca6 100644 --- a/src/lib/netlist/plib/palloc.h +++ b/src/lib/netlist/plib/palloc.h @@ -282,6 +282,9 @@ namespace plib { static inline void *allocate( size_t alignment, size_t size ) { + m_stat_cur_alloc() += size; + m_stat_max_alloc() = std::max(m_stat_max_alloc(), m_stat_cur_alloc()); + #if (PUSE_ALIGNED_ALLOCATION) #if defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER) return _aligned_malloc(size, alignment); @@ -302,7 +305,8 @@ namespace plib { static inline void deallocate( void *ptr, size_t size ) noexcept { - unused_var(size); + //unused_var(size); + m_stat_cur_alloc() -= size; #if (PUSE_ALIGNED_ALLOCATION) // NOLINTNEXTLINE(cppcoreguidelines-no-malloc) free(ptr); @@ -343,12 +347,32 @@ namespace plib { } } + template + static T *alloc(Args&&... args) + { + auto *p = allocate(alignof(T), sizeof(T)); + return new(p) T(std::forward(args)...); + } + + template + static void free(T *ptr) noexcept + { + ptr->~T(); + aligned_arena::deallocate(ptr, sizeof(T)); + } + bool operator ==(const aligned_arena &rhs) const noexcept { plib::unused_var(rhs); return true; } + size_type cur_alloc() const noexcept { return m_stat_cur_alloc(); } + size_type max_alloc() const noexcept { return m_stat_max_alloc(); } + private: + static size_t &m_stat_cur_alloc() noexcept { static size_t val = 0; return val; } + static size_t &m_stat_max_alloc() noexcept { static size_t val = 0; return val; } + }; template @@ -378,29 +402,13 @@ namespace plib { #endif } - // FIXME: remove - template - inline T *pnew(Args&&... args) - { - auto *p = aligned_arena::allocate(alignof(T), sizeof(T)); - return new(p) T(std::forward(args)...); - } - - template - inline void pdelete(T *ptr) noexcept - { - ptr->~T(); - aligned_arena::deallocate(ptr, sizeof(T)); - } - - template - using unique_ptr = std::unique_ptr>; + using unique_ptr = aligned_arena::unique_pool_ptr; template plib::unique_ptr make_unique(Args&&... args) { - return plib::unique_ptr(pnew(std::forward(args)...)); + return aligned_arena::instance().make_unique(std::forward(args)...); } template diff --git a/src/lib/netlist/plib/pconfig.h b/src/lib/netlist/plib/pconfig.h index 0870d8c59d5..115eafd2196 100644 --- a/src/lib/netlist/plib/pconfig.h +++ b/src/lib/netlist/plib/pconfig.h @@ -25,7 +25,7 @@ /// \brief System supports INT128 /// /// Set this to one if you want to use 128 bit int for ptime. -/// This is about 15% slower on a kaby lake processor for pongf. +/// This is about 10% slower on a skylake processor for pongf. /// #ifndef PHAS_INT128 #define PHAS_INT128 (0) diff --git a/src/lib/netlist/plib/pmempool.h b/src/lib/netlist/plib/pmempool.h index 1e197fdfc82..a06c67acd8e 100644 --- a/src/lib/netlist/plib/pmempool.h +++ b/src/lib/netlist/plib/pmempool.h @@ -59,7 +59,7 @@ namespace plib { plib::perrlogger("Found {} info blocks\n", sinfo().size()); plib::perrlogger("Found block with {} dangling allocations\n", b->m_num_alloc); } - plib::pdelete(b); + aligned_arena::free(b); //::operator delete(b->m_data); } } @@ -126,7 +126,7 @@ namespace plib { plib::terminate("mempool::free - block not found"); mp.m_blocks.erase(itb); - plib::pdelete(b); + aligned_arena::free(b); } sinfo().erase(it); } @@ -222,15 +222,13 @@ namespace plib { size_type m_pos; }; - block * new_block(size_type min_bytes) { - auto *b = plib::pnew(*this, min_bytes); + auto *b = aligned_arena::alloc(*this, min_bytes); m_blocks.push_back(b); return b; } - static std::unordered_map &sinfo() { static std::unordered_map spinfo; diff --git a/src/lib/netlist/plib/ppmf.h b/src/lib/netlist/plib/ppmf.h index bbbe95ded05..a9df2f6b4aa 100644 --- a/src/lib/netlist/plib/ppmf.h +++ b/src/lib/netlist/plib/ppmf.h @@ -273,7 +273,7 @@ namespace plib { #endif } template - R call(O *obj, Targs... args) const noexcept(true) + R call(O *obj, Targs&&... args) const noexcept(true) { using function_ptr = MEMBER_ABI R (*)(O *obj, Targs... args); return (reinterpret_cast(m_func))(obj, std::forward(args)...); @@ -311,7 +311,7 @@ namespace plib { m_obj = reinterpret_cast(object); } - inline R operator()(Targs ... args) const noexcept(true) + inline R operator()(Targs... args) const noexcept(true) { return this->call(m_obj, std::forward(args)...); } -- cgit v1.2.3