diff options
author | 2020-09-24 07:53:11 +0200 | |
---|---|---|
committer | 2020-09-24 15:22:22 +0200 | |
commit | 1bb99466bcfa188bca00855f80bd6098b0882419 (patch) | |
tree | 57b4b8d68d6efdeb18d424e4ef4a353a011d6fe8 /src/lib/netlist/plib | |
parent | 2fb9f38b83270cac34428738313cd2eee79f421e (diff) |
netlist: code refactoring
* use default move and copy constructors
* various minor edits like adding noexcept
* removed a lot of inline keywords - you can't beat the compiler
Diffstat (limited to 'src/lib/netlist/plib')
-rw-r--r-- | src/lib/netlist/plib/gmres.h | 2 | ||||
-rw-r--r-- | src/lib/netlist/plib/parray.h | 2 | ||||
-rw-r--r-- | src/lib/netlist/plib/pchrono.h | 6 | ||||
-rw-r--r-- | src/lib/netlist/plib/pconfig.h | 2 | ||||
-rw-r--r-- | src/lib/netlist/plib/pfmtlog.h | 10 | ||||
-rwxr-xr-x | src/lib/netlist/plib/plists.h | 28 | ||||
-rw-r--r-- | src/lib/netlist/plib/pmath.h | 106 | ||||
-rw-r--r-- | src/lib/netlist/plib/pmulti_threading.h | 13 | ||||
-rw-r--r-- | src/lib/netlist/plib/ppmf.h | 2 | ||||
-rw-r--r-- | src/lib/netlist/plib/pstream.h | 4 | ||||
-rw-r--r-- | src/lib/netlist/plib/ptime.h | 19 |
11 files changed, 98 insertions, 96 deletions
diff --git a/src/lib/netlist/plib/gmres.h b/src/lib/netlist/plib/gmres.h index 465f12021e3..16fcd1b3f4b 100644 --- a/src/lib/netlist/plib/gmres.h +++ b/src/lib/netlist/plib/gmres.h @@ -335,7 +335,7 @@ namespace plib private: - static inline void givens_mult(FT c, FT s, FT & g0, FT & g1 ) + static void givens_mult(FT c, FT s, FT & g0, FT & g1 ) { const FT g0_last(g0); diff --git a/src/lib/netlist/plib/parray.h b/src/lib/netlist/plib/parray.h index 514c231025b..61220366775 100644 --- a/src/lib/netlist/plib/parray.h +++ b/src/lib/netlist/plib/parray.h @@ -127,7 +127,7 @@ namespace plib { base_type &as_base() noexcept { return m_a; } - inline size_type size() const noexcept { return SIZE <= 0 ? m_size : SIZEABS(); } + constexpr size_type size() const noexcept { return SIZE <= 0 ? m_size : SIZEABS(); } constexpr size_type max_size() const noexcept { return base_type::max_size(); } diff --git a/src/lib/netlist/plib/pchrono.h b/src/lib/netlist/plib/pchrono.h index 6695f238290..3cde7cf8649 100644 --- a/src/lib/netlist/plib/pchrono.h +++ b/src/lib/netlist/plib/pchrono.h @@ -20,9 +20,9 @@ namespace plib { struct sys_ticks { using type = typename T::rep; - static inline constexpr type start() noexcept { return T::now().time_since_epoch().count(); } - static inline constexpr type stop() noexcept { return T::now().time_since_epoch().count(); } - static inline constexpr type per_second() noexcept { return T::period::den / T::period::num; } + static constexpr type start() noexcept { return T::now().time_since_epoch().count(); } + static constexpr type stop() noexcept { return T::now().time_since_epoch().count(); } + static constexpr type per_second() noexcept { return T::period::den / T::period::num; } }; using hires_ticks = sys_ticks<std::chrono::high_resolution_clock>; diff --git a/src/lib/netlist/plib/pconfig.h b/src/lib/netlist/plib/pconfig.h index c80f1bbadd6..8e34b01a3b8 100644 --- a/src/lib/netlist/plib/pconfig.h +++ b/src/lib/netlist/plib/pconfig.h @@ -8,7 +8,7 @@ /// \file pconfig.h /// -/// \brief More accurate measurements if you processor supports RDTSCP. +/// \brief More accurate measurements the processor supports RDTSCP. /// #ifndef PHAS_RDTSCP #define PHAS_RDTSCP (0) diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h index 45f7d3e4fc1..ae8998b9dee 100644 --- a/src/lib/netlist/plib/pfmtlog.h +++ b/src/lib/netlist/plib/pfmtlog.h @@ -40,7 +40,7 @@ namespace plib { { static constexpr const bool is_signed = std::numeric_limits<T>::is_signed; static char32_t fmt_spec() { return 'u'; } - static inline void streamify(std::ostream &s, const T &v) + static void streamify(std::ostream &s, const T &v) { s << v; } @@ -53,7 +53,7 @@ namespace plib { // FIXME: need native support at some time static constexpr const bool is_signed = true; static char32_t fmt_spec() { return 'f'; } - static inline void streamify(std::ostream &s, const FLOAT128 &v) + static void streamify(std::ostream &s, const FLOAT128 &v) { s << narrow_cast<long double>(v); } @@ -176,7 +176,7 @@ namespace plib { struct ptype_traits<const char16_t *> : ptype_traits_base<const char16_t *> { static char32_t fmt_spec() { return 's'; } - static inline void streamify(std::ostream &s, const char16_t *v) + static void streamify(std::ostream &s, const char16_t *v) { const putf16string su16(v); s << putf8string(su16).c_str(); @@ -187,7 +187,7 @@ namespace plib { struct ptype_traits<const char32_t *> : ptype_traits_base<const char32_t *> { static char32_t fmt_spec() { return 's'; } - static inline void streamify(std::ostream &s, const char32_t *v) + static void streamify(std::ostream &s, const char32_t *v) { const putf32string su32(v); s << putf8string(su32).c_str(); @@ -210,7 +210,7 @@ namespace plib { struct ptype_traits<putf16string> : ptype_traits_base<putf16string> { static char32_t fmt_spec() { return 's'; } - static inline void streamify(std::ostream &s, const putf16string &v) + static void streamify(std::ostream &s, const putf16string &v) { s << putf8string(v).c_str(); } diff --git a/src/lib/netlist/plib/plists.h b/src/lib/netlist/plib/plists.h index 328f0b1ad23..19c34717126 100755 --- a/src/lib/netlist/plib/plists.h +++ b/src/lib/netlist/plib/plists.h @@ -172,7 +172,7 @@ namespace plib { /// \brief a simple linked list. /// - /// The list allows insertions deletions whilst being processed. + /// The list allows insertions and deletions whilst being processed. /// template <class LC> class linkedlist_t @@ -187,10 +187,10 @@ namespace plib { constexpr element_t() : m_next(nullptr), m_prev(nullptr) {} ~element_t() noexcept = default; - PCOPYASSIGNMOVE(element_t, delete) + PCOPYASSIGNMOVE(element_t, default) - constexpr LC *next() const noexcept { return m_next; } - constexpr LC *prev() const noexcept { return m_prev; } + constexpr LC * &next() noexcept { return m_next; } + constexpr LC * &prev() noexcept { return m_prev; } private: LC * m_next; LC * m_prev; @@ -202,22 +202,14 @@ namespace plib { LC* p; public: explicit constexpr iter_t(LC* x) noexcept : p(x) { } - constexpr iter_t(iter_t &rhs) noexcept : p(rhs.p) { } - iter_t(iter_t &&rhs) noexcept { std::swap(*this, rhs); } + constexpr iter_t(const iter_t &rhs) noexcept = default; + iter_t(iter_t &&rhs) noexcept = default; - iter_t& operator=(const iter_t &rhs) noexcept // NOLINT(bugprone-unhandled-self-assignment, cert-oop54-cpp) - { - if (this == &rhs) - return *this; - - p = rhs.p; - return *this; - } - - iter_t& operator=(iter_t &&rhs) noexcept { std::swap(*this, rhs); return *this; } - ~iter_t() = default; + iter_t& operator=(const iter_t &rhs) noexcept = default; + iter_t& operator=(iter_t &&rhs) noexcept = default; + ~iter_t() noexcept = default; - iter_t& operator++() noexcept { p = p->next();return *this; } + iter_t& operator++() noexcept { p = p->next(); return *this; } // NOLINTNEXTLINE(cert-dcl21-cpp) iter_t operator++(int) & noexcept { const iter_t tmp(*this); operator++(); return tmp; } diff --git a/src/lib/netlist/plib/pmath.h b/src/lib/netlist/plib/pmath.h index 02d634529a0..01912dd2183 100644 --- a/src/lib/netlist/plib/pmath.h +++ b/src/lib/netlist/plib/pmath.h @@ -30,50 +30,50 @@ namespace plib template <typename T> struct constants { - static inline constexpr T zero() noexcept { return static_cast<T>(0); } // NOLINT - static inline constexpr T half() noexcept { return static_cast<T>(0.5); } // NOLINT - static inline constexpr T one() noexcept { return static_cast<T>(1); } // NOLINT - static inline constexpr T two() noexcept { return static_cast<T>(2); } // NOLINT - static inline constexpr T three() noexcept { return static_cast<T>(3); } // NOLINT - static inline constexpr T four() noexcept { return static_cast<T>(4); } // NOLINT - static inline constexpr T hundred()noexcept { return static_cast<T>(100); } // NOLINT - - static inline constexpr T one_thirds() noexcept { return fraction(one(), three()); } - static inline constexpr T two_thirds() noexcept { return fraction(two(), three()); } - - static inline constexpr T ln2() noexcept { return static_cast<T>(0.6931471805599453094172321214581766L); } // NOLINT - static inline constexpr T sqrt2() noexcept { return static_cast<T>(1.4142135623730950488016887242096982L); } // NOLINT - static inline constexpr T sqrt3() noexcept { return static_cast<T>(1.7320508075688772935274463415058723L); } // NOLINT - static inline constexpr T sqrt3_2() noexcept { return static_cast<T>(0.8660254037844386467637231707529362L); } // NOLINT - static inline constexpr T pi() noexcept { return static_cast<T>(3.1415926535897932384626433832795029L); } // NOLINT + static constexpr T zero() noexcept { return static_cast<T>(0); } // NOLINT + static constexpr T half() noexcept { return static_cast<T>(0.5); } // NOLINT + static constexpr T one() noexcept { return static_cast<T>(1); } // NOLINT + static constexpr T two() noexcept { return static_cast<T>(2); } // NOLINT + static constexpr T three() noexcept { return static_cast<T>(3); } // NOLINT + static constexpr T four() noexcept { return static_cast<T>(4); } // NOLINT + static constexpr T hundred()noexcept { return static_cast<T>(100); } // NOLINT + + static constexpr T one_thirds() noexcept { return fraction(one(), three()); } + static constexpr T two_thirds() noexcept { return fraction(two(), three()); } + + static constexpr T ln2() noexcept { return static_cast<T>(0.6931471805599453094172321214581766L); } // NOLINT + static constexpr T sqrt2() noexcept { return static_cast<T>(1.4142135623730950488016887242096982L); } // NOLINT + static constexpr T sqrt3() noexcept { return static_cast<T>(1.7320508075688772935274463415058723L); } // NOLINT + static constexpr T sqrt3_2() noexcept { return static_cast<T>(0.8660254037844386467637231707529362L); } // NOLINT + static constexpr T pi() noexcept { return static_cast<T>(3.1415926535897932384626433832795029L); } // NOLINT /// \brief Electric constant of vacuum /// - static inline constexpr T eps_0() noexcept { return static_cast<T>(8.854187817e-12); } // NOLINT + static constexpr T eps_0() noexcept { return static_cast<T>(8.854187817e-12); } // NOLINT // \brief Relative permittivity of Silicon dioxide /// - static inline constexpr T eps_SiO2() noexcept { return static_cast<T>(3.9); } // NOLINT + static constexpr T eps_SiO2() noexcept { return static_cast<T>(3.9); } // NOLINT /// \brief Relative permittivity of Silicon /// - static inline constexpr T eps_Si() noexcept { return static_cast<T>(11.7); } // NOLINT + static constexpr T eps_Si() noexcept { return static_cast<T>(11.7); } // NOLINT /// \brief Boltzmann constant /// - static inline constexpr T k_b() noexcept { return static_cast<T>(1.38064852e-23); } // NOLINT + static constexpr T k_b() noexcept { return static_cast<T>(1.38064852e-23); } // NOLINT /// \brief room temperature (gives VT = 0.02585 at T=300) /// - static inline constexpr T T0() noexcept { return static_cast<T>(300); } // NOLINT + static constexpr T T0() noexcept { return static_cast<T>(300); } // NOLINT /// \brief Elementary charge /// - static inline constexpr T Q_e() noexcept { return static_cast<T>(1.6021765314e-19); } // NOLINT + static constexpr T Q_e() noexcept { return static_cast<T>(1.6021765314e-19); } // NOLINT /// \brief Intrinsic carrier concentration in 1/m^3 of Silicon /// - static inline constexpr T NiSi() noexcept { return static_cast<T>(1.45e16); } // NOLINT + static constexpr T NiSi() noexcept { return static_cast<T>(1.45e16); } // NOLINT /// \brief clearly identify magic numbers in code /// @@ -82,10 +82,10 @@ namespace plib /// later. /// template <typename V> - static inline constexpr T magic(V &&v) noexcept { return static_cast<T>(v); } + static constexpr T magic(V &&v) noexcept { return static_cast<T>(v); } template <typename V> - static inline constexpr T fraction(V &&v1, V &&v2) noexcept { return static_cast<T>(v1 / v2); } + static constexpr T fraction(V &&v1, V &&v2) noexcept { return static_cast<T>(v1 / v2); } }; /// \brief typesafe reciprocal function @@ -95,7 +95,7 @@ namespace plib /// \return reciprocal of argument /// template <typename T> - static inline constexpr std::enable_if_t<std::is_floating_point<T>::value, T> + static constexpr std::enable_if_t<std::is_floating_point<T>::value, T> reciprocal(T v) noexcept { return constants<T>::one() / v; @@ -108,7 +108,7 @@ namespace plib /// \return absolute value of argument /// template <typename T> - static inline constexpr std::enable_if_t<std::is_floating_point<T>::value, T> + static constexpr std::enable_if_t<std::is_floating_point<T>::value, T> abs(T v) noexcept { return std::abs(v); @@ -121,7 +121,7 @@ namespace plib /// \return absolute value of argument /// template <typename T> - static inline constexpr std::enable_if_t<std::is_floating_point<T>::value, T> + static constexpr std::enable_if_t<std::is_floating_point<T>::value, T> sqrt(T v) noexcept { return std::sqrt(v); @@ -135,7 +135,7 @@ namespace plib /// \return sqrt(v1*v1+v2*v2) /// template <typename T> - static inline constexpr std::enable_if_t<std::is_floating_point<T>::value, T> + static constexpr std::enable_if_t<std::is_floating_point<T>::value, T> hypot(T v1, T v2) noexcept { return std::hypot(v1, v2); @@ -148,7 +148,7 @@ namespace plib /// \return exp(v) /// template <typename T> - static inline constexpr std::enable_if_t<std::is_floating_point<T>::value, T> + static constexpr std::enable_if_t<std::is_floating_point<T>::value, T> exp(T v) noexcept { return std::exp(v); @@ -161,7 +161,7 @@ namespace plib /// \return log(v) /// template <typename T> - static inline constexpr std::enable_if_t<std::is_floating_point<T>::value, T> + static constexpr std::enable_if_t<std::is_floating_point<T>::value, T> log(T v) noexcept { return std::log(v); @@ -174,7 +174,7 @@ namespace plib /// \return tanh(v) /// template <typename T> - static inline constexpr std::enable_if_t<std::is_floating_point<T>::value, T> + static constexpr std::enable_if_t<std::is_floating_point<T>::value, T> tanh(T v) noexcept { return std::tanh(v); @@ -187,7 +187,7 @@ namespace plib /// \return floor(v) /// template <typename T> - static inline constexpr std::enable_if_t<std::is_floating_point<T>::value, T> + static constexpr std::enable_if_t<std::is_floating_point<T>::value, T> floor(T v) noexcept { return std::floor(v); @@ -200,7 +200,7 @@ namespace plib /// \return log(1 + v) /// template <typename T> - static inline constexpr std::enable_if_t<std::is_floating_point<T>::value, T> + static constexpr std::enable_if_t<std::is_floating_point<T>::value, T> log1p(T v) noexcept { return std::log1p(v); @@ -213,7 +213,7 @@ namespace plib /// \return sin(v) /// template <typename T> - static inline constexpr std::enable_if_t<std::is_floating_point<T>::value, T> + static constexpr std::enable_if_t<std::is_floating_point<T>::value, T> sin(T v) noexcept { return std::sin(v); @@ -226,7 +226,7 @@ namespace plib /// \return cos(v) /// template <typename T> - static inline constexpr std::enable_if_t<std::is_floating_point<T>::value, T> + static constexpr std::enable_if_t<std::is_floating_point<T>::value, T> cos(T v) noexcept { return std::cos(v); @@ -239,7 +239,7 @@ namespace plib /// \return trunc(v) /// template <typename T> - static inline constexpr std::enable_if_t<std::is_floating_point<T>::value, T> + static constexpr std::enable_if_t<std::is_floating_point<T>::value, T> trunc(T v) noexcept { return std::trunc(v); @@ -253,7 +253,7 @@ namespace plib /// \return signum(v) /// template <typename T> - static inline constexpr std::enable_if_t<std::is_floating_point<T>::value, T> + static constexpr std::enable_if_t<std::is_floating_point<T>::value, T> signum(T v, T r = static_cast<T>(1)) { constexpr const auto z(static_cast<T>(0)); @@ -271,80 +271,80 @@ namespace plib /// FIXME: limited implementation /// template <typename T1, typename T2> - static inline + static auto pow(T1 v, T2 p) noexcept -> decltype(std::pow(v, p)) { return std::pow(v, p); } #if (PUSE_FLOAT128) - static inline constexpr FLOAT128 reciprocal(FLOAT128 v) noexcept + static constexpr FLOAT128 reciprocal(FLOAT128 v) noexcept { return constants<FLOAT128>::one() / v; } - static inline FLOAT128 abs(FLOAT128 v) noexcept + static FLOAT128 abs(FLOAT128 v) noexcept { return fabsq(v); } - static inline FLOAT128 sqrt(FLOAT128 v) noexcept + static FLOAT128 sqrt(FLOAT128 v) noexcept { return sqrtq(v); } - static inline FLOAT128 hypot(FLOAT128 v1, FLOAT128 v2) noexcept + static FLOAT128 hypot(FLOAT128 v1, FLOAT128 v2) noexcept { return hypotq(v1, v2); } - static inline FLOAT128 exp(FLOAT128 v) noexcept + static FLOAT128 exp(FLOAT128 v) noexcept { return expq(v); } - static inline FLOAT128 log(FLOAT128 v) noexcept + static FLOAT128 log(FLOAT128 v) noexcept { return logq(v); } - static inline FLOAT128 tanh(FLOAT128 v) noexcept + static FLOAT128 tanh(FLOAT128 v) noexcept { return tanhq(v); } - static inline FLOAT128 floor(FLOAT128 v) noexcept + static FLOAT128 floor(FLOAT128 v) noexcept { return floorq(v); } - static inline FLOAT128 log1p(FLOAT128 v) noexcept + static FLOAT128 log1p(FLOAT128 v) noexcept { return log1pq(v); } - static inline FLOAT128 sin(FLOAT128 v) noexcept + static FLOAT128 sin(FLOAT128 v) noexcept { return sinq(v); } - static inline FLOAT128 cos(FLOAT128 v) noexcept + static FLOAT128 cos(FLOAT128 v) noexcept { return cosq(v); } - static inline FLOAT128 trunc(FLOAT128 v) noexcept + static FLOAT128 trunc(FLOAT128 v) noexcept { return truncq(v); } template <typename T> - static inline FLOAT128 pow(FLOAT128 v, T p) noexcept + static FLOAT128 pow(FLOAT128 v, T p) noexcept { return powq(v, static_cast<FLOAT128>(p)); } - static inline FLOAT128 pow(FLOAT128 v, int p) noexcept + static FLOAT128 pow(FLOAT128 v, int p) noexcept { if (p==2) return v*v; diff --git a/src/lib/netlist/plib/pmulti_threading.h b/src/lib/netlist/plib/pmulti_threading.h index 9f470054e2d..c844086313c 100644 --- a/src/lib/netlist/plib/pmulti_threading.h +++ b/src/lib/netlist/plib/pmulti_threading.h @@ -23,9 +23,10 @@ namespace plib { struct pspin_mutex { public: - pspin_mutex() noexcept = default; - void lock() noexcept{ while (m_lock.test_and_set(std::memory_order_acquire)) { } } - void unlock() noexcept { m_lock.clear(std::memory_order_release); } + inline pspin_mutex() noexcept = default; + inline ~pspin_mutex() noexcept = default; + inline void lock() noexcept{ while (m_lock.test_and_set(std::memory_order_acquire)) { } } + inline void unlock() noexcept { m_lock.clear(std::memory_order_release); } private: PALIGNAS_CACHELINE() std::atomic_flag m_lock = ATOMIC_FLAG_INIT; @@ -35,8 +36,10 @@ namespace plib { struct pspin_mutex<false> { public: - void lock() const noexcept { } - void unlock() const noexcept { } + inline pspin_mutex() noexcept = default; + inline ~pspin_mutex() noexcept = default; + static inline void lock() /*const*/ noexcept { } + static inline void unlock() /*const*/ noexcept { } }; class psemaphore diff --git a/src/lib/netlist/plib/ppmf.h b/src/lib/netlist/plib/ppmf.h index e86c94ff4c9..e37f970cc05 100644 --- a/src/lib/netlist/plib/ppmf.h +++ b/src/lib/netlist/plib/ppmf.h @@ -377,7 +377,7 @@ namespace plib { bind<specific_member_function<O>>(object, &mftp); } - inline R operator()(Targs... args) const noexcept(true) + R operator()(Targs... args) const noexcept(true) { return this->call(std::forward<Targs>(args)...); } diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h index 65d95293298..bc0c7cfc31e 100644 --- a/src/lib/netlist/plib/pstream.h +++ b/src/lib/netlist/plib/pstream.h @@ -28,7 +28,7 @@ namespace plib { /// \brief wrapper around isteam read /// template <typename S, typename T> - static inline S & istream_read(S &is, T * data, size_t len) + static S & istream_read(S &is, T * data, size_t len) { using ct = typename S::char_type; static_assert((sizeof(T) % sizeof(ct)) == 0, "istream_read sizeof issue"); @@ -39,7 +39,7 @@ namespace plib { /// \brief wrapper around osteam write /// template <typename S, typename T> - static inline S & ostream_write(S &os, const T * data, size_t len) + static S & ostream_write(S &os, const T * data, size_t len) { using ct = typename S::char_type; static_assert((sizeof(T) % sizeof(ct)) == 0, "ostream_write sizeof issue"); diff --git a/src/lib/netlist/plib/ptime.h b/src/lib/netlist/plib/ptime.h index 0f88449500b..9274467d0c2 100644 --- a/src/lib/netlist/plib/ptime.h +++ b/src/lib/netlist/plib/ptime.h @@ -82,18 +82,27 @@ namespace plib return *this; } +#if 1 template <typename O> constexpr ptime operator-(const ptime<O, RES> &rhs) const noexcept { static_assert(ptime_le<ptime<O, RES>, ptime>::value, "Invalid ptime type"); return ptime(m_time - rhs.m_time); } - +#else + template <typename O> + constexpr ptime operator-(ptime<O, RES> rhs) const noexcept + { + static_assert(ptime_le<ptime<O, RES>, ptime>::value, "Invalid ptime type"); + return (rhs -= (*this)); // causes a crash - FIXME + } +#endif template <typename O> - constexpr ptime operator+(const ptime<O, RES> &rhs) const noexcept + constexpr ptime operator+(ptime<O, RES> rhs) const noexcept { static_assert(ptime_le<ptime<O, RES>, ptime>::value, "Invalid ptime type"); - return ptime(m_time + rhs.m_time); + return (rhs += *this); + //return ptime(m_time + rhs.m_time); } template <typename M> @@ -173,9 +182,7 @@ namespace plib constexpr ptime shr(unsigned shift) const noexcept { return ptime(m_time >> shift); } // for save states .... -#if 0 - constexpr internal_type *get_internaltype_ptr() noexcept { return &m_time; } -#endif + template <typename ST> void save_state(ST &&st) { |