From 55f1dfafc2a1aa55e53e83eac2415c76218e15b4 Mon Sep 17 00:00:00 2001 From: couriersud Date: Wed, 16 Oct 2019 13:57:54 +0200 Subject: Netlist: pongf update and code maintenance. [Couriersud] After the recent string of updates pongf performance increased again. Also includes code maintenance and some fixes for the aligned memory operations. --- src/lib/netlist/nl_lists.h | 41 ++++-------------------------------- src/lib/netlist/nl_setup.cpp | 5 ++++- src/lib/netlist/plib/palloc.h | 27 +++++++++++++++++++----- src/lib/netlist/plib/parray.h | 31 ++++----------------------- src/lib/netlist/plib/pconfig.h | 47 ----------------------------------------- src/lib/netlist/plib/ppmf.h | 48 ++++++++++++++++++++++++++++++++++++++++++ src/lib/netlist/plib/ptypes.h | 5 +++-- 7 files changed, 85 insertions(+), 119 deletions(-) (limited to 'src/lib') diff --git a/src/lib/netlist/nl_lists.h b/src/lib/netlist/nl_lists.h index 27db664cc05..30c73062fd0 100644 --- a/src/lib/netlist/nl_lists.h +++ b/src/lib/netlist/nl_lists.h @@ -13,6 +13,7 @@ #include "plib/pchrono.h" #include "plib/plists.h" #include "plib/ptypes.h" +#include "plib/parray.h" #include "nl_config.h" #include "nltypes.h" @@ -128,28 +129,6 @@ namespace netlist m_prof_call.inc(); } - void push_nostatsx(T && e) noexcept - { - /* Lock */ - lock_guard_type lck(m_lock); -#if 1 - T * i(m_end-1); - for (; *i < e; --i) - { - *(i+1) = *(i); - } - *(i+1) = std::move(e); - ++m_end; -#else - T * i(m_end++); - while (QueueOp::less(*(--i), e)) - { - *(i+1) = *(i); - } - *(i+1) = std::move(e); -#endif - } - T pop() noexcept { return *(--m_end); } const T &top() const noexcept { return *(m_end-1); } @@ -160,7 +139,6 @@ namespace netlist lock_guard_type lck(m_lock); if (KEEPSTAT) m_prof_remove.inc(); -#if 1 for (T * i = m_end - 1; i > &m_list[0]; --i) { // == operator ignores time! @@ -170,16 +148,6 @@ namespace netlist return; } } -#else - for (T * i = &m_list[1]; i < m_end; ++i) - { - if (QueueOp::equal(*i, elem)) - { - std::copy(i+1, m_end--, i); - return; - } - } -#endif } template @@ -231,11 +199,10 @@ namespace netlist using mutex_type = pspin_mutex; using lock_guard_type = std::lock_guard; - mutex_type m_lock; + mutex_type m_lock; PALIGNAS_CACHELINE() - T * m_end; - //std::vector m_list; - plib::aligned_vector m_list; + T * m_end; + plib::aligned_vector m_list; public: // profiling diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index bb942fdaab1..e0a696c226a 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -1219,7 +1219,10 @@ plib::unique_ptr source_file_t::stream(const pstring &name) { plib::unused_var(name); auto ret(plib::make_unique(plib::filesystem::u8path(m_filename))); - return std::move(ret); + if (ret->is_open()) + return std::move(ret); + else + return plib::unique_ptr(nullptr); } bool source_proc_t::parse(nlparse_t &setup, const pstring &name) diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h index a9b03353b37..ad42d14c690 100644 --- a/src/lib/netlist/plib/palloc.h +++ b/src/lib/netlist/plib/palloc.h @@ -261,6 +261,9 @@ namespace plib { template using allocator_type = arena_allocator; + template + using unique_pool_ptr = std::unique_ptr>; + template using owned_pool_ptr = plib::owned_ptr>; @@ -300,16 +303,24 @@ namespace plib { #endif } -#if 0 template - owned_pool_ptr make_poolptr(Args&&... args) + unique_pool_ptr make_unique(Args&&... args) { auto *mem = allocate(alignof(T), sizeof(T)); - return owned_pool_ptr(new (mem) T(std::forward(args)...), true, arena_deleter(*this)); + try + { + auto *mema = new (mem) T(std::forward(args)...); + return unique_pool_ptr(mema, arena_deleter(*this)); + } + catch (...) + { + deallocate(mem); + throw; + } } -#endif + template - owned_pool_ptr make_poolptr(Args&&... args) + owned_pool_ptr make_owned(Args&&... args) { auto *mem = allocate(alignof(T), sizeof(T)); try @@ -324,6 +335,12 @@ namespace plib { } } + bool operator ==(const aligned_arena &rhs) const + { + plib::unused_var(rhs); + return true; + } + }; template diff --git a/src/lib/netlist/plib/parray.h b/src/lib/netlist/plib/parray.h index b385da56eab..65251a02002 100644 --- a/src/lib/netlist/plib/parray.h +++ b/src/lib/netlist/plib/parray.h @@ -11,6 +11,7 @@ #include "palloc.h" #include "pconfig.h" #include "pexception.h" +#include "pstrutil.h" #include #include @@ -31,8 +32,7 @@ namespace plib { struct sizeabs { static constexpr std::size_t ABS() { return 0; } - //using container = typename std::vector>; - using container = typename std::vector; + using container = typename std::vector>; }; /** @@ -69,23 +69,12 @@ namespace plib { { } -#if 1 -#if 0 - struct tag {}; - /* allow construction in fixed size arrays */ - template - parray(tag A = tag(), typename std::enable_if<(X >= 0), int>::type = 0) - : m_size(X) - { - } -#else /* allow construction in fixed size arrays */ parray() : m_size(SIZEABS()) { } -#endif -#endif + template parray(size_type size, typename std::enable_if<(X != 0), int>::type = 0) : m_size(size) @@ -101,18 +90,6 @@ namespace plib { bool empty() const noexcept { return size() == 0; } -#if 0 - reference operator[](size_type i) /*noexcept*/ - { - if (i >= m_size) throw plib::pexception("limits error " + to_string(i) + ">=" + to_string(m_size)); - return m_a[i]; - } - const_reference operator[](size_type i) const /*noexcept*/ - { - if (i >= m_size) throw plib::pexception("limits error " + to_string(i) + ">=" + to_string(m_size)); - return m_a[i]; - } -#else C14CONSTEXPR reference operator[](size_type i) noexcept { return assume_aligned_ptr(&m_a[0])[i]; @@ -121,7 +98,7 @@ namespace plib { { return assume_aligned_ptr(&m_a[0])[i]; } -#endif + FT * data() noexcept { return assume_aligned_ptr(m_a.data()); } const FT * data() const noexcept { return assume_aligned_ptr(m_a.data()); } diff --git a/src/lib/netlist/plib/pconfig.h b/src/lib/netlist/plib/pconfig.h index 4ce5aea4cdb..3e20170a752 100644 --- a/src/lib/netlist/plib/pconfig.h +++ b/src/lib/netlist/plib/pconfig.h @@ -121,53 +121,6 @@ typedef __int128_t INT128; #define HAS_OPENMP (0) #endif -//============================================================ -// Pointer to Member Function -//============================================================ - -// This will be autodetected -//#define PPMF_TYPE 0 - -#define PPMF_TYPE_PMF 0 -#define PPMF_TYPE_GNUC_PMF_CONV 1 -#define PPMF_TYPE_INTERNAL 2 - -#if defined(__GNUC__) - /* does not work in versions over 4.7.x of 32bit MINGW */ - #if defined(__MINGW32__) && !defined(__x86_64) && defined(__i386__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7))) - #define PHAS_PMF_INTERNAL 0 - #elif defined(__MINGW32__) && !defined(__x86_64) && defined(__i386__) - #define PHAS_PMF_INTERNAL 1 - #define MEMBER_ABI _thiscall - #elif defined(__clang__) && defined(__i386__) && defined(_WIN32) - #define PHAS_PMF_INTERNAL 0 - #elif defined(__arm__) || defined(__ARMEL__) || defined(__aarch64__) || defined(__MIPSEL__) || defined(__mips_isa_rev) || defined(__mips64) || defined(__EMSCRIPTEN__) - #define PHAS_PMF_INTERNAL 2 - #else - #define PHAS_PMF_INTERNAL 1 - #endif -#elif defined(_MSC_VER) && defined (_M_X64) - #define PHAS_PMF_INTERNAL 3 -#else - #define PHAS_PMF_INTERNAL 0 -#endif - -#ifndef MEMBER_ABI - #define MEMBER_ABI -#endif - -#ifndef PPMF_TYPE - #if (PHAS_PMF_INTERNAL > 0) - #define PPMF_TYPE PPMF_TYPE_INTERNAL - #else - #define PPMF_TYPE PPMF_TYPE_PMF - #endif -#else - #undef PHAS_PMF_INTERNAL - #define PHAS_PMF_INTERNAL 0 - #undef MEMBER_ABI - #define MEMBER_ABI -#endif //============================================================ // WARNINGS diff --git a/src/lib/netlist/plib/ppmf.h b/src/lib/netlist/plib/ppmf.h index 8c8c6582579..4ff49911d63 100644 --- a/src/lib/netlist/plib/ppmf.h +++ b/src/lib/netlist/plib/ppmf.h @@ -41,6 +41,54 @@ * */ +//============================================================ +// Macro magic +//============================================================ + +//#define PPMF_TYPE 0 + +#define PPMF_TYPE_PMF 0 +#define PPMF_TYPE_GNUC_PMF_CONV 1 +#define PPMF_TYPE_INTERNAL 2 + +#if defined(__GNUC__) + /* does not work in versions over 4.7.x of 32bit MINGW */ + #if defined(__MINGW32__) && !defined(__x86_64) && defined(__i386__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7))) + #define PHAS_PMF_INTERNAL 0 + #elif defined(__MINGW32__) && !defined(__x86_64) && defined(__i386__) + #define PHAS_PMF_INTERNAL 1 + #define MEMBER_ABI _thiscall + #elif defined(__clang__) && defined(__i386__) && defined(_WIN32) + #define PHAS_PMF_INTERNAL 0 + #elif defined(__arm__) || defined(__ARMEL__) || defined(__aarch64__) || defined(__MIPSEL__) || defined(__mips_isa_rev) || defined(__mips64) || defined(__EMSCRIPTEN__) + #define PHAS_PMF_INTERNAL 2 + #else + #define PHAS_PMF_INTERNAL 1 + #endif +#elif defined(_MSC_VER) && defined (_M_X64) + #define PHAS_PMF_INTERNAL 3 +#else + #define PHAS_PMF_INTERNAL 0 +#endif + +#ifndef MEMBER_ABI + #define MEMBER_ABI +#endif + +#ifndef PPMF_TYPE + #if (PHAS_PMF_INTERNAL > 0) + #define PPMF_TYPE PPMF_TYPE_INTERNAL + #else + #define PPMF_TYPE PPMF_TYPE_PMF + #endif +#else + #undef PHAS_PMF_INTERNAL + #define PHAS_PMF_INTERNAL 0 + #undef MEMBER_ABI + #define MEMBER_ABI +#endif + + #if (PPMF_TYPE == PPMF_TYPE_GNUC_PMF_CONV) #pragma GCC diagnostic ignored "-Wpmf-conversions" #endif diff --git a/src/lib/netlist/plib/ptypes.h b/src/lib/netlist/plib/ptypes.h index bda62099150..c3c1c5fc7c6 100644 --- a/src/lib/netlist/plib/ptypes.h +++ b/src/lib/netlist/plib/ptypes.h @@ -14,11 +14,12 @@ #include #include +// noexcept on move operator -> issue with macosx clang #define COPYASSIGNMOVE(name, def) \ name(const name &) = def; \ - name(name &&) noexcept = def; \ + name(name &&) /*noexcept*/ = def; \ name &operator=(const name &) = def; \ - name &operator=(name &&) noexcept = def; + name &operator=(name &&) /*noexcept*/ = def; #define COPYASSIGN(name, def) \ name(const name &) = def; \ -- cgit v1.2.3