netlist: tidy changes and better constexpr support for ptime class. (nw)

This commit is contained in:
couriersud 2019-02-24 17:55:28 +01:00
parent 0e07f9ac34
commit 2e055aa97b
30 changed files with 104 additions and 95 deletions

View File

@ -33,9 +33,9 @@
#ifndef NLID_TWOTERM_H_
#define NLID_TWOTERM_H_
#include "plib/pfunction.h"
#include "netlist/nl_base.h"
#include "netlist/nl_setup.h"
#include "plib/pfunction.h"
// -----------------------------------------------------------------------------
// Implementation

View File

@ -14,7 +14,7 @@ VSBUILD = $(SRC)/buildVS
DOC = $(SRC)/documentation
TIDY_DB = ../compile_commands.json
TIDY_FLAGSX = -checks=*,google*,-hicpp*,-readability*,-fuchsia*,cert-*,-android-*,
TIDY_FLAGSX = -checks=*,-google*,-hicpp*,-readability*,-fuchsia*,cert-*,-android-*,
TIDY_FLAGSX += -llvm-header-guard,-cppcoreguidelines-pro-type-reinterpret-cast,
TIDY_FLAGSX += -cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-owning-memory,
TIDY_FLAGSX += -modernize-use-default-member-init,-cppcoreguidelines-pro-bounds-constant-array-index,
@ -235,7 +235,7 @@ native:
$(MAKE) CEXTRAFLAGS="-march=native -msse4.2 -Wall -Wpedantic -Wsign-compare -Wextra "
clang:
$(MAKE) CC=clang++-9 LD=clang++-9 CEXTRAFLAGS="-march=native -Weverything -Werror -Wno-unused-template -Wno-non-virtual-dtor -Wno-unreachable-code -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wconversion -Wno-c++98-compat -Wno-float-equal -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wweak-template-vtables -Wno-exit-time-destructors"
$(MAKE) CC=clang++-9 LD=clang++-9 CEXTRAFLAGS="-march=native -Weverything -Werror -Wno-padded -Wno-weak-vtables -Wno-unused-template -Wno-missing-variable-declarations -Wno-float-equal -Wconversion -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wno-exit-time-destructors"
clang-5:
$(MAKE) CC=clang++-5.0 LD=clang++-5.0 CEXTRAFLAGS="-march=native -Weverything -Werror -Wno-inconsistent-missing-destructor-override -Wno-unreachable-code -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wconversion -Wno-c++98-compat -Wno-float-equal -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wno-weak-template-vtables -Wno-exit-time-destructors"
@ -252,6 +252,10 @@ tidy_db: compile_commands_prefix $(ALL_TIDY_FILES) compile_commands_postfix
# FIXME: -Wno-weak-vtables -Wno-missing-variable-declarations -Wno-conversion -Wno-exit-time-destructors
# FIXME: -Winconsistent-missing-destructor-override : c++ community has diverging opinions on this https://github.com/isocpp/CppCoreGuidelines/issues/721
# FIXME: -Wunreachable-code : False warnings, this a documented clang bug: https://llvm.org/bugs/show_bug.cgi?id=28994
# -Wweak-template-vtables
#
# These have to be given:
# -Wno-missing-variable-declarations : Device factory code, on purpose
mingw:
$(MAKE) CEXTRAFLAGS="-DUNICODE -D_UNICODE -D_WIN32_WINNT=0x0501 -DWIN32_LEAN_AND_MEAN" \

View File

@ -98,7 +98,7 @@ namespace netlist
NETLIB_FUNC_VOID(CD4020_sub, update_outputs, (const unsigned cnt))
{
static const std::array<netlist_time, 14> out_delayQn = {
static constexpr const std::array<netlist_time, 14> out_delayQn = {
NLTIME_FROM_NS(180), NLTIME_FROM_NS(280),
NLTIME_FROM_NS(380), NLTIME_FROM_NS(480),
NLTIME_FROM_NS(580), NLTIME_FROM_NS(680),

View File

@ -13,8 +13,8 @@ namespace netlist
namespace devices
{
static constexpr netlist_time delay_107[2] = { NLTIME_FROM_NS(16), NLTIME_FROM_NS(25) };
static constexpr netlist_time delay_107A[2] = { NLTIME_FROM_NS(15), NLTIME_FROM_NS(15) };
static constexpr const netlist_time delay_107[2] = { NLTIME_FROM_NS(16), NLTIME_FROM_NS(25) };
static constexpr const netlist_time delay_107A[2] = { NLTIME_FROM_NS(15), NLTIME_FROM_NS(15) };
NETLIB_OBJECT(74107A)
{

View File

@ -85,7 +85,7 @@ namespace netlist
}
// FIXME: Timing
static constexpr netlist_time delay[4] =
static constexpr const netlist_time delay[4] =
{
NLTIME_FROM_NS(40),
NLTIME_FROM_NS(40),

View File

@ -110,7 +110,7 @@ namespace netlist
}
// FIXME: Timing
static constexpr netlist_time delay[4] =
static constexpr const netlist_time delay[4] =
{
NLTIME_FROM_NS(40),
NLTIME_FROM_NS(40),

View File

@ -87,7 +87,7 @@ namespace netlist
}
// FIXME: Timing
static constexpr netlist_time delay[4] =
static constexpr const netlist_time delay[4] =
{
NLTIME_FROM_NS(40),
NLTIME_FROM_NS(40),

View File

@ -137,7 +137,7 @@ namespace netlist
#define BITS7(b6,b5,b4,b3,b2,b1,b0) ((b6)<<6) | ((b5)<<5) | ((b4)<<4) | ((b3)<<3) | ((b2)<<2) | ((b1)<<1) | ((b0)<<0)
static constexpr std::array<uint8_t, 16> tab7448 =
static constexpr const std::array<uint8_t, 16> tab7448 =
{
BITS7( 1, 1, 1, 1, 1, 1, 0 ), /* 00 - not blanked ! */
BITS7( 0, 1, 1, 0, 0, 0, 0 ), /* 01 */

View File

@ -78,7 +78,7 @@ namespace netlist
m_last_B = 0;
}
static C14CONSTEXPR const netlist_time delay[4] =
static constexpr const netlist_time delay[4] =
{
NLTIME_FROM_NS(18),
NLTIME_FROM_NS(36) - NLTIME_FROM_NS(18),

View File

@ -17,8 +17,8 @@ namespace netlist
namespace devices
{
static constexpr netlist_time out_delay_CLK_Y[2] = { NLTIME_FROM_NS(20), NLTIME_FROM_NS(26) }; // tPHL, tPLH
static constexpr netlist_time out_delay_CLK_Z[2] = { NLTIME_FROM_NS(17), NLTIME_FROM_NS(12) };
static constexpr const netlist_time out_delay_CLK_Y[2] = { NLTIME_FROM_NS(20), NLTIME_FROM_NS(26) }; // tPHL, tPLH
static constexpr const netlist_time out_delay_CLK_Z[2] = { NLTIME_FROM_NS(17), NLTIME_FROM_NS(12) };
NETLIB_OBJECT(7497)
{

View File

@ -6,9 +6,9 @@
*/
#include "netlist/nl_base.h"
#include "nld_log.h"
#include "plib/pfmtlog.h"
#include "plib/pstream.h"
#include "nld_log.h"
//#include "sound/wavwrite.h"
namespace netlist

View File

@ -77,8 +77,8 @@ namespace netlist
return ret;
}
static constexpr sbitset all_bits() { return sbitset(~static_cast<T>(0)); }
static constexpr sbitset no_bits() { return sbitset(static_cast<T>(0)); }
static constexpr const sbitset all_bits() noexcept { return sbitset(~static_cast<T>(0)); }
static constexpr const sbitset no_bits() noexcept{ return sbitset(static_cast<T>(0)); }
private:
T m_bs;
};

View File

@ -24,9 +24,9 @@
#include "plib/pstate.h"
#include "plib/pstream.h"
#include "nltypes.h"
#include "nl_errstr.h"
#include "nl_lists.h"
#include "nltypes.h"
#include "plib/ptime.h"
//============================================================
@ -1034,8 +1034,8 @@ namespace netlist
: m_value(param.model_value(name))
{
}
const double &operator()() const NL_NOEXCEPT { return m_value; }
operator const double&() const NL_NOEXCEPT { return m_value; }
const double &operator()() const noexcept { return m_value; }
operator const double&() const noexcept { return m_value; }
private:
const double m_value;
};
@ -1248,6 +1248,12 @@ namespace netlist
public:
using entry_t = pqentry_t<net_t *, netlist_time>;
explicit queue_t(netlist_state_t &nl);
virtual ~queue_t() noexcept = default;
queue_t(const queue_t &) = delete;
queue_t(queue_t &&) = delete;
queue_t &operator=(const queue_t &) = delete;
queue_t &operator=(queue_t &&) = delete;
protected:

View File

@ -14,12 +14,12 @@
#define NLTYPES_H_
#include "nl_config.h"
#include "plib/ptime.h"
#include "plib/pchrono.h"
#include "plib/pfmtlog.h"
#include "plib/pmempool.h"
#include "plib/pstring.h"
#include "plib/pstate.h"
#include "plib/pstring.h"
#include "plib/ptime.h"
#include <cstdint>
#include <unordered_map>
@ -126,9 +126,9 @@ namespace netlist
// MACROS
//============================================================
template <typename T> inline constexpr netlist_time NLTIME_FROM_NS(T &&t) noexcept { return netlist_time::from_nsec(t); }
template <typename T> inline constexpr netlist_time NLTIME_FROM_US(T &&t) noexcept { return netlist_time::from_usec(t); }
template <typename T> inline constexpr netlist_time NLTIME_FROM_MS(T &&t) noexcept { return netlist_time::from_msec(t); }
template <typename T> inline constexpr const netlist_time NLTIME_FROM_NS(T &&t) noexcept { return netlist_time::from_nsec(t); }
template <typename T> inline constexpr const netlist_time NLTIME_FROM_US(T &&t) noexcept { return netlist_time::from_usec(t); }
template <typename T> inline constexpr const netlist_time NLTIME_FROM_MS(T &&t) noexcept { return netlist_time::from_msec(t); }
} // namespace netlist

View File

@ -36,13 +36,13 @@ namespace plib {
#if defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)
return _aligned_malloc(size, alignment);
#elif defined(__APPLE__)
void* p;
if (::posix_memalign(&p, alignment, size) != 0) {
p = nullptr;
}
return p;
void* p;
if (::posix_memalign(&p, alignment, size) != 0) {
p = nullptr;
}
return p;
#else
return aligned_alloc(alignment, size);
return aligned_alloc(alignment, size);
#endif
}
@ -90,7 +90,7 @@ namespace plib {
static_assert(is_pow2(ALIGN), "Alignment must be a power of 2");
//auto t = reinterpret_cast<std::uintptr_t>(p);
//if (t & (ALIGN-1))
// printf("alignment error!");
// printf("alignment error!");
#if (USE_ALIGNED_HINTS)
return reinterpret_cast<T *>(__builtin_assume_aligned(p, ALIGN));
#else
@ -142,8 +142,8 @@ namespace plib {
constexpr pdefault_deleter() noexcept = default;
template<typename U, typename = typename
std::enable_if<std::is_convertible< U*, T*>::value>::type>
pdefault_deleter(const pdefault_deleter<U>&) noexcept { }
std::enable_if<std::is_convertible< U*, T*>::value>::type>
pdefault_deleter(const pdefault_deleter<U>&) noexcept { }
void operator()(T *p) const
{
@ -271,30 +271,30 @@ namespace plib {
class aligned_allocator
{
public:
using value_type = T;
static constexpr const std::size_t align_size = (USE_ALIGNED_ALLOCATION) ? ALIGN : alignof(std::max_align_t);
using value_type = T;
static constexpr const std::size_t align_size = (USE_ALIGNED_ALLOCATION) ? ALIGN : alignof(std::max_align_t);
static_assert(align_size >= alignof(T) && (align_size % alignof(T)) == 0,
"ALIGN must be greater than alignof(T) and a multiple");
static_assert(align_size >= alignof(T) && (align_size % alignof(T)) == 0,
"ALIGN must be greater than alignof(T) and a multiple");
aligned_allocator() noexcept = default;
~aligned_allocator() noexcept = default;
aligned_allocator() noexcept = default;
~aligned_allocator() noexcept = default;
aligned_allocator(const aligned_allocator&) noexcept = default;
aligned_allocator& operator=(const aligned_allocator&) noexcept = delete;
aligned_allocator(const aligned_allocator&) noexcept = default;
aligned_allocator& operator=(const aligned_allocator&) noexcept = delete;
aligned_allocator(aligned_allocator&&) noexcept = default;
aligned_allocator& operator=(aligned_allocator&&) = delete;
aligned_allocator(aligned_allocator&&) noexcept = default;
aligned_allocator& operator=(aligned_allocator&&) = delete;
template <class U>
aligned_allocator(const aligned_allocator<U, ALIGN>& rhs) noexcept
{
unused_var(rhs);
}
template <class U> struct rebind
template <class U>
aligned_allocator(const aligned_allocator<U, ALIGN>& rhs) noexcept
{
using other = aligned_allocator<U, ALIGN>;
unused_var(rhs);
}
template <class U> struct rebind
{
using other = aligned_allocator<U, ALIGN>;
};
T* allocate(std::size_t n)
@ -331,22 +331,22 @@ namespace plib {
//============================================================
// traits to determine alignment size and stride size
// from types supporting alignment
// from types supporting alignment
//============================================================
PDEFINE_HAS_MEMBER(has_align, align_size);
template <typename T, typename X = void>
struct align_traits
template <typename T, typename X = void>
struct align_traits
{
static constexpr const std::size_t align_size = alignof(std::max_align_t);
static constexpr const std::size_t align_size = alignof(std::max_align_t);
static constexpr const std::size_t stride_size =
(sizeof(T) % align_size == 0 ? 1 //T is a multiple of align_size
: (align_size % sizeof(T) != 0 ? align_size // align_size is not a multiple of T
: align_size / sizeof(T)));
};
template <typename T>
template <typename T>
struct align_traits<T, typename std::enable_if<has_align<T>::value, void>::type>
{
static constexpr const std::size_t align_size = T::align_size;
@ -360,7 +360,7 @@ namespace plib {
// Aligned vector
//============================================================
// FIXME: needs a separate file
// FIXME: needs a separate file
template <class T, std::size_t ALIGN = alignof(T)>
class aligned_vector : public std::vector<T, aligned_allocator<T, ALIGN>>
{

View File

@ -42,13 +42,13 @@
#endif
#define USE_ALIGNED_ALLOCATION (USE_ALIGNED_OPTIMIZATIONS)
#define USE_ALIGNED_HINTS (USE_ALIGNED_OPTIMIZATIONS)
#define USE_ALIGNED_HINTS (USE_ALIGNED_OPTIMIZATIONS)
/*
* Standard alignment macros
*/
#define PALIGN_CACHELINE (64)
#define PALIGN_VECTOROPT (32)
#define PALIGN_VECTOROPT (8)
#define PALIGNAS_CACHELINE() PALIGNAS(PALIGN_CACHELINE)
#define PALIGNAS_VECTOROPT() PALIGNAS(PALIGN_VECTOROPT)

View File

@ -35,7 +35,6 @@ struct ptype_traits_base
template <>
struct ptype_traits_base<bool>
{
static unsigned int cast(bool &x) { return static_cast<unsigned int>(x); }
static unsigned int cast(const bool &x) { return static_cast<unsigned int>(x); }
static const bool is_signed = std::numeric_limits<bool>::is_signed;
static const char *size_spec() { return ""; }

View File

@ -200,9 +200,9 @@ public:
LC* p;
public:
explicit constexpr iter_t(LC* x) noexcept : p(x) { }
explicit constexpr iter_t(iter_t &rhs) noexcept : p(rhs.p) { }
constexpr iter_t(iter_t &rhs) noexcept : p(rhs.p) { }
iter_t(iter_t &&rhs) noexcept { std::swap(*this, rhs); }
iter_t& operator=(const iter_t &rhs) { iter_t t(rhs); std::swap(*this, t); return *this; }
iter_t& operator=(const iter_t &rhs) noexcept { iter_t t(rhs); std::swap(*this, t); return *this; }
iter_t& operator=(iter_t &&rhs) noexcept { std::swap(*this, rhs); return *this; }
iter_t& operator++() noexcept {p = p->next();return *this;}
// NOLINTNEXTLINE(cert-dcl21-cpp)

View File

@ -658,7 +658,7 @@ inline void copystream(postream &dest, pistream &src)
struct perrlogger
{
template <typename ... Args>
perrlogger(Args&& ... args)
explicit perrlogger(Args&& ... args)
{
h()(std::forward<Args>(args)...);
}

View File

@ -47,19 +47,19 @@ namespace plib
C14CONSTEXPR ptime &operator-=(const ptime rhs) noexcept { m_time -= rhs.m_time; return *this; }
C14CONSTEXPR ptime &operator*=(const mult_type factor) noexcept { m_time *= static_cast<internal_type>(factor); return *this; }
friend C14CONSTEXPR ptime operator-(ptime lhs, const ptime rhs) noexcept
friend constexpr const ptime operator-(ptime lhs, const ptime rhs) noexcept
{
return lhs -= rhs;
return ptime(lhs.m_time - rhs.m_time);
}
friend C14CONSTEXPR ptime operator+(ptime lhs, const ptime rhs) noexcept
friend constexpr const ptime operator+(ptime lhs, const ptime rhs) noexcept
{
return lhs += rhs;
return ptime(lhs.m_time + rhs.m_time);
}
friend C14CONSTEXPR ptime operator*(ptime lhs, const mult_type &factor) noexcept
friend constexpr const ptime operator*(ptime lhs, const mult_type &factor) noexcept
{
return lhs *= factor;
return ptime(lhs.m_time * factor);
}
friend constexpr mult_type operator/(const ptime lhs, const ptime rhs) noexcept

View File

@ -87,13 +87,13 @@ namespace plib
// Define a "has member" trait.
//============================================================
#define PDEFINE_HAS_MEMBER(name, member) \
template <typename T> class name \
{ \
template <typename U> static long test(decltype(&U:: member)); \
template <typename U> static char test(...); \
public: \
static constexpr const bool value = sizeof(test<T>(nullptr)) == sizeof(long); \
}
#define PDEFINE_HAS_MEMBER(name, member) \
template <typename T> class name \
{ \
template <typename U> static long test(decltype(&U:: member)); \
template <typename U> static char test(...); \
public: \
static constexpr const bool value = sizeof(test<T>(nullptr)) == sizeof(long); \
}
#endif /* PTYPES_H_ */

View File

@ -12,7 +12,7 @@
#include <algorithm>
#include <initializer_list>
#include <vector> // <<= needed by windows build
#include <vector>
#define PSTRINGIFY_HELP(y) # y
#define PSTRINGIFY(x) PSTRINGIFY_HELP(x)

View File

@ -11,9 +11,9 @@
#include "netlist/nl_base.h"
#include "netlist/nl_errstr.h"
#include "plib/palloc.h"
#include "plib/pmatrix2d.h"
#include "plib/putil.h"
#include "plib/vector_ops.h"
#include "plib/pmatrix2d.h"
#include <cmath>
@ -240,12 +240,12 @@ namespace devices
template <typename T>
using aligned_alloc = plib::aligned_allocator<T, PALIGN_VECTOROPT>;
plib::pmatrix2d<nl_double, aligned_alloc<nl_double>> m_gon;
plib::pmatrix2d<nl_double, aligned_alloc<nl_double>> m_gtn;
plib::pmatrix2d<nl_double, aligned_alloc<nl_double>> m_Idrn;
plib::pmatrix2d<nl_double *, aligned_alloc<nl_double *>> m_connected_net_Vn;
plib::pmatrix2d<nl_double, aligned_alloc<nl_double>> m_gon;
plib::pmatrix2d<nl_double, aligned_alloc<nl_double>> m_gtn;
plib::pmatrix2d<nl_double, aligned_alloc<nl_double>> m_Idrn;
plib::pmatrix2d<nl_double *, aligned_alloc<nl_double *>> m_connected_net_Vn;
plib::pmatrix2d<nl_double> m_test;
plib::pmatrix2d<nl_double> m_test;
std::vector<plib::unique_ptr<terms_for_net_t>> m_terms;
std::vector<analog_net_t *> m_nets;

View File

@ -8,10 +8,10 @@
#ifndef NLD_MS_DIRECT_H_
#define NLD_MS_DIRECT_H_
#include <algorithm>
#include <cmath>
#include "plib/mat_cr.h"
#include "plib/vector_ops.h"
#include <algorithm>
#include <cmath>
#include "nld_matrix_solver.h"
#include "nld_solver.h"

View File

@ -12,11 +12,11 @@
#include "plib/mat_cr.h"
#include "nld_ms_direct.h"
#include "nld_solver.h"
#include "plib/pdynlib.h"
#include "plib/pstream.h"
#include "plib/vector_ops.h"
#include "nld_ms_direct.h"
#include "nld_solver.h"
#include <algorithm>
@ -67,7 +67,7 @@ private:
plib::parray<FT, SIZE> new_V;
std::array<plib::aligned_vector<FT *, PALIGN_VECTOROPT>, storage_N> m_term_cr;
// std::array<std::vector<FT *>, storage_N> m_term_cr;
// std::array<std::vector<FT *>, storage_N> m_term_cr;
mat_type mat;

View File

@ -8,12 +8,12 @@
#ifndef NLD_MS_GMRES_H_
#define NLD_MS_GMRES_H_
#include "nld_ms_direct.h"
#include "nld_solver.h"
#include "plib/gmres.h"
#include "plib/mat_cr.h"
#include "plib/parray.h"
#include "plib/vector_ops.h"
#include "nld_ms_direct.h"
#include "nld_solver.h"
#include <algorithm>
#include <cmath>

View File

@ -35,9 +35,9 @@
#include <algorithm>
#include "plib/vector_ops.h"
#include "nld_matrix_solver.h"
#include "nld_solver.h"
#include "plib/vector_ops.h"
namespace netlist
{

View File

@ -42,9 +42,9 @@
#include <algorithm>
#include "plib/vector_ops.h"
#include "nld_matrix_solver.h"
#include "nld_solver.h"
#include "plib/vector_ops.h"
namespace netlist
{

View File

@ -9,8 +9,8 @@
#define NLD_SOLVER_H_
#include "netlist/nl_base.h"
#include "plib/pstream.h"
#include "nld_matrix_solver.h"
#include "plib/pstream.h"
#include <map>
#include <memory>

View File

@ -6,8 +6,8 @@
*/
#include "plib/palloc.h"
#include "plib/putil.h"
#include "nl_convert.h"
#include "plib/putil.h"
#include <algorithm>
#include <cmath>
#include <unordered_map>