summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pchrono.h
diff options
context:
space:
mode:
author couriersud <couriersud@gmx.org>2019-10-17 10:21:00 +0200
committer couriersud <couriersud@gmx.org>2019-10-17 10:21:00 +0200
commitdb318046c4ed54fa7822b6aec55bec6d427e1e95 (patch)
tree1636e304db0c44da12d192ef8cd17837d4975b86 /src/lib/netlist/plib/pchrono.h
parentda35541e842fe09869d24f2dda23162194c369ce (diff)
Netlist: code maintenance and bug fixes. (nw)
- solver now uses dynamic allocation on systems larger than 512x512 - fixed osx build - moved nl_lists.h classes to plists.h - fixed netlist makefile clint section - readability and typos
Diffstat (limited to 'src/lib/netlist/plib/pchrono.h')
-rw-r--r--src/lib/netlist/plib/pchrono.h424
1 files changed, 216 insertions, 208 deletions
diff --git a/src/lib/netlist/plib/pchrono.h b/src/lib/netlist/plib/pchrono.h
index d6e98134f47..4e0bb071431 100644
--- a/src/lib/netlist/plib/pchrono.h
+++ b/src/lib/netlist/plib/pchrono.h
@@ -15,245 +15,253 @@
//#include <cstdint>
namespace plib {
-namespace chrono {
- template <typename T>
- struct sys_ticks
- {
- using type = typename T::rep;
- static inline type start() { return T::now().time_since_epoch().count(); }
- static inline type stop() { return T::now().time_since_epoch().count(); }
- static inline constexpr type per_second() { return T::period::den / T::period::num; }
- };
-
- using hires_ticks = sys_ticks<std::chrono::high_resolution_clock>;
- using steady_ticks = sys_ticks<std::chrono::steady_clock>;
- using system_ticks = sys_ticks<std::chrono::system_clock>;
-
- #if defined(__x86_64__) && !defined(_clang__) && !defined(_MSC_VER) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6))
-
- template <typename T, typename R>
- struct base_ticks
- {
- using ret_type = R;
- static ret_type per_second()
+ namespace chrono {
+ template <typename T>
+ struct sys_ticks
{
- static ret_type persec = 0;
- if (persec == 0)
+ 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; }
+ };
+
+ using hires_ticks = sys_ticks<std::chrono::high_resolution_clock>;
+ using steady_ticks = sys_ticks<std::chrono::steady_clock>;
+ using system_ticks = sys_ticks<std::chrono::system_clock>;
+
+ #if defined(__x86_64__) && !defined(_clang__) && !defined(_MSC_VER) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6))
+
+ template <typename T, typename R>
+ struct base_ticks
+ {
+ using ret_type = R;
+ static ret_type per_second()
{
- ret_type x = 0;
- system_ticks::type t = system_ticks::start();
- system_ticks::type e;
- x = - T :: start();
- do {
- e = system_ticks::stop();
- } while (e - t < system_ticks::per_second() / 100 );
- x += T :: stop();
- persec = (ret_type)(double)((double) x * (double) system_ticks::per_second() / double (e - t));
+ static ret_type persec = 0;
+ if (persec == 0)
+ {
+ ret_type x = 0;
+ system_ticks::type t = system_ticks::start();
+ system_ticks::type e;
+ x = - T :: start();
+ do {
+ e = system_ticks::stop();
+ } while (e - t < system_ticks::per_second() / 100 );
+ x += T :: stop();
+ persec = (ret_type)(double)((double) x * (double) system_ticks::per_second() / double (e - t));
+ }
+ return persec;
}
- return persec;
- }
- };
+ };
- #if PHAS_RDTSCP
- struct fast_ticks : public base_ticks<fast_ticks, int64_t>
- {
- typedef int64_t type;
- static inline type start()
+ #if PHAS_RDTSCP
+ struct fast_ticks : public base_ticks<fast_ticks, int64_t>
{
- int64_t v;
- __asm__ __volatile__ (
- "rdtscp;"
- "shl $32, %%rdx;"
- "or %%rdx, %%rax;"
- : "=a"(v) /* outputs */
- : /* inputs */
- : "%rcx", "%rdx" /* clobbers */
- );
- return v;
- }
- static inline type stop()
- {
- return start();
- }
- };
-
- #else
- struct fast_ticks : public base_ticks<fast_ticks, int64_t>
- {
- typedef int64_t type;
- static inline type start()
- {
- int64_t v;
- __asm__ __volatile__ (
- "rdtsc;"
- "shl $32, %%rdx;"
- "or %%rdx, %%rax;"
- : "=a"(v) /* outputs */
- : /* inputs */
- : "%rdx" /* clobbers */
- );
- return v;
- }
- static inline type stop()
+ typedef int64_t type;
+ static inline type start() noexcept
+ {
+ int64_t v;
+ __asm__ __volatile__ (
+ "rdtscp;"
+ "shl $32, %%rdx;"
+ "or %%rdx, %%rax;"
+ : "=a"(v) /* outputs */
+ : /* inputs */
+ : "%rcx", "%rdx" /* clobbers */
+ );
+ return v;
+ }
+ static inline type stop() noexcept
+ {
+ return start();
+ }
+ };
+
+ #else
+ struct fast_ticks : public base_ticks<fast_ticks, int64_t>
{
- return start();
- }
- };
+ typedef int64_t type;
+ static inline type start() noexcept
+ {
+ int64_t v;
+ __asm__ __volatile__ (
+ "rdtsc;"
+ "shl $32, %%rdx;"
+ "or %%rdx, %%rax;"
+ : "=a"(v) /* outputs */
+ : /* inputs */
+ : "%rdx" /* clobbers */
+ );
+ return v;
+ }
+ static inline type stop() noexcept
+ {
+ return start();
+ }
+ };
- #endif
+ #endif
- /* Based on "How to Benchmark Code Execution Times on Intel?? IA-32 and IA-64
- * Instruction Set Architectures", Intel, 2010
- *
- */
- #if PUSE_ACCURATE_STATS && PHAS_RDTSCP
- /*
- * kills performance completely, but is accurate
- * cpuid serializes, but clobbers ebx and ecx
- *
- */
+ /* Based on "How to Benchmark Code Execution Times on Intel?? IA-32 and IA-64
+ * Instruction Set Architectures", Intel, 2010
+ *
+ */
+ #if PUSE_ACCURATE_STATS && PHAS_RDTSCP
+ /*
+ * kills performance completely, but is accurate
+ * cpuid serializes, but clobbers ebx and ecx
+ *
+ */
- struct exact_ticks : public base_ticks<exact_ticks, int64_t>
- {
- typedef int64_t type;
+ struct exact_ticks : public base_ticks<exact_ticks, int64_t>
+ {
+ typedef int64_t type;
- static inline type start()
+ static inline type start() noexcept
+ {
+ int64_t v;
+ __asm__ __volatile__ (
+ "cpuid;"
+ //"xor %%eax, %%eax\n\t"
+ "rdtsc;"
+ "shl $32, %%rdx;"
+ "or %%rdx, %%rax;"
+ : "=a"(v) /* outputs */
+ : "a"(0x0) /* inputs */
+ : "%ebx", "%ecx", "%rdx" /* clobbers*/
+ );
+ return v;
+ }
+ static inline type stop() noexcept
+ {
+ int64_t v;
+ __asm__ __volatile__ (
+ "rdtscp;"
+ "shl $32, %%rdx;"
+ "or %%rax, %%rdx;"
+ "mov %%rdx, %%r10;"
+ "xor %%eax, %%eax\n\t"
+ "cpuid;"
+ "mov %%r10, %%rax;"
+ : "=a" (v)
+ :
+ : "%ebx", "%ecx", "%rdx", "%r10"
+ );
+ return v;
+ }
+ };
+ #else
+ using exact_ticks = fast_ticks;
+ #endif
+
+
+ #else
+ using fast_ticks = hires_ticks;
+ using exact_ticks = fast_ticks;
+ #endif
+
+ template<bool enabled_>
+ struct counter
{
- int64_t v;
- __asm__ __volatile__ (
- "cpuid;"
- //"xor %%eax, %%eax\n\t"
- "rdtsc;"
- "shl $32, %%rdx;"
- "or %%rdx, %%rax;"
- : "=a"(v) /* outputs */
- : "a"(0x0) /* inputs */
- : "%ebx", "%ecx", "%rdx" /* clobbers*/
- );
- return v;
- }
- static inline type stop()
+ counter() : m_count(0) { }
+ using type = uint_least64_t;
+ type operator()() const noexcept { return m_count; }
+ void inc() noexcept { ++m_count; }
+ void reset() noexcept { m_count = 0; }
+ constexpr static bool enabled = enabled_;
+ private:
+ type m_count;
+ };
+
+ template<>
+ struct counter<false>
{
- int64_t v;
- __asm__ __volatile__ (
- "rdtscp;"
- "shl $32, %%rdx;"
- "or %%rax, %%rdx;"
- "mov %%rdx, %%r10;"
- "xor %%eax, %%eax\n\t"
- "cpuid;"
- "mov %%r10, %%rax;"
- : "=a" (v)
- :
- : "%ebx", "%ecx", "%rdx", "%r10"
- );
- return v;
- }
- };
- #else
- using exact_ticks = fast_ticks;
- #endif
-
-
- #else
- using fast_ticks = hires_ticks;
- using exact_ticks = fast_ticks;
- #endif
+ using type = uint_least64_t;
+ constexpr type operator()() const { return 0; }
+ void inc() const { }
+ void reset() const { }
+ constexpr static bool enabled = false;
+ };
- template<bool enabled_>
- struct counter
- {
- counter() : m_count(0) { }
- using type = uint_least64_t;
- type operator()() const { return m_count; }
- void inc() { ++m_count; }
- void reset() { m_count = 0; }
- constexpr static bool enabled = enabled_;
- private:
- type m_count;
- };
-
- template<>
- struct counter<false>
- {
- using type = uint_least64_t;
- constexpr type operator()() const { return 0; }
- void inc() const { }
- void reset() const { }
- constexpr static bool enabled = false;
- };
-
-
- template< typename T, bool enabled_ = true>
- struct timer
- {
- using type = typename T::type;
- using ctype = uint_least64_t;
- constexpr static bool enabled = enabled_;
-
- struct guard_t
+
+ template< typename T, bool enabled_ = true>
+ struct timer
{
- guard_t() = delete;
- guard_t(timer &m) noexcept : m_m(m) { m_m.m_time -= T::start(); }
- ~guard_t() { m_m.m_time += T::stop(); ++m_m.m_count; }
+ using type = typename T::type;
+ using ctype = uint_least64_t;
+ constexpr static bool enabled = enabled_;
- COPYASSIGNMOVE(guard_t, default)
+ struct guard_t
+ {
+ guard_t() = delete;
+ guard_t(timer &m) noexcept : m_m(m) { m_m.m_time -= T::start(); }
+ ~guard_t() { m_m.m_time += T::stop(); ++m_m.m_count; }
- private:
- timer &m_m;
- };
+ COPYASSIGNMOVE(guard_t, default)
- friend struct guard_t;
+ private:
+ timer &m_m;
+ };
- timer() : m_time(0), m_count(0) { }
+ friend struct guard_t;
- type operator()() const { return m_time; }
+ timer() : m_time(0), m_count(0) { }
- void reset() { m_time = 0; m_count = 0; }
- type average() const { return (m_count == 0) ? 0 : m_time / m_count; }
- type total() const { return m_time; }
- ctype count() const { return m_count; }
+ type operator()() const { return m_time; }
- double as_seconds() const { return static_cast<double>(total())
- / static_cast<double>(T::per_second()); }
+ void reset() { m_time = 0; m_count = 0; }
+ type average() const { return (m_count == 0) ? 0 : m_time / m_count; }
+ type total() const { return m_time; }
+ ctype count() const { return m_count; }
- guard_t guard() { return guard_t(*this); }
- private:
- type m_time;
- ctype m_count;
- };
+ double as_seconds() const { return static_cast<double>(total())
+ / static_cast<double>(T::per_second()); }
- template<typename T>
- struct timer<T, false>
- {
- using type = typename T::type;
- using ctype = uint_least64_t;
+ guard_t guard() { return guard_t(*this); }
+ private:
+ type m_time;
+ ctype m_count;
+ };
- struct guard_t
+ template<typename T>
+ struct timer<T, false>
{
- guard_t() = default;
- COPYASSIGNMOVE(guard_t, default)
- /* using default constructor will trigger warning on
- * unused local variable.
- */
- // NOLINTNEXTLINE(modernize-use-equals-default)
- ~guard_t() { }
+ using type = typename T::type;
+ using ctype = uint_least64_t;
+
+ struct guard_t
+ {
+ guard_t() = default;
+ COPYASSIGNMOVE(guard_t, default)
+ /* using default constructor will trigger warning on
+ * unused local variable.
+ */
+ // NOLINTNEXTLINE(modernize-use-equals-default)
+ ~guard_t() { }
+ };
+
+ constexpr type operator()() const { return 0; }
+ void reset() const { }
+ constexpr type average() const { return 0; }
+ constexpr type total() const { return 0; }
+ constexpr ctype count() const { return 0; }
+ constexpr double as_seconds() const { return 0.0; }
+ constexpr static bool enabled = false;
+ guard_t guard() { return guard_t(); }
};
- constexpr type operator()() const { return 0; }
- void reset() const { }
- constexpr type average() const { return 0; }
- constexpr type total() const { return 0; }
- constexpr ctype count() const { return 0; }
- constexpr double as_seconds() const { return 0.0; }
- constexpr static bool enabled = false;
- guard_t guard() { return guard_t(); }
- };
+ } // namespace chrono
+ //============================================================
+ // Performance tracking
+ //============================================================
+ template<bool enabled_>
+ using pperftime_t = plib::chrono::timer<plib::chrono::exact_ticks, enabled_>;
- } // namespace chrono
+ template<bool enabled_>
+ using pperfcount_t = plib::chrono::counter<enabled_>;
} // namespace plib
#endif /* PCHRONO_H_ */