Internals: Cleanup some inlines, use constexpr. No functional change intended.

This commit is contained in:
Wilson Snyder 2020-12-01 18:49:03 -05:00
parent 014e43f0ef
commit 212e8fb14b
18 changed files with 54 additions and 57 deletions

View File

@ -457,7 +457,7 @@ public:
static inline int debug() VL_MT_SAFE { return s_s.s_debug; }
#else
/// Return constant 0 debug level, so C++'s optimizer rips up
static inline int debug() VL_PURE { return 0; }
static constexpr int debug() VL_PURE { return 0; }
#endif
/// Enable calculation of unused signals
static void calcUnusedSigs(bool flag) VL_MT_SAFE;
@ -572,8 +572,8 @@ public:
static int dpiLineno() VL_MT_SAFE { return t_s.t_dpiLineno; }
static int exportFuncNum(const char* namep) VL_MT_SAFE;
static size_t serialized1Size() VL_PURE { return sizeof(s_s); }
static void* serialized1Ptr() VL_MT_UNSAFE { return &s_s; } // Unsafe, for Serialize only
static constexpr size_t serialized1Size() VL_PURE { return sizeof(s_s); }
static constexpr void* serialized1Ptr() VL_MT_UNSAFE { return &s_s; } // For Serialize only
static size_t serialized2Size() VL_PURE;
static void* serialized2Ptr() VL_MT_UNSAFE;
#ifdef VL_THREADED

View File

@ -38,8 +38,8 @@ protected:
std::string m_filename; ///< Filename, for error messages
VerilatedAssertOneThread m_assertOne; ///< Assert only called from single thread
inline static size_t bufferSize() { return 256 * 1024; } // See below for slack calculation
inline static size_t bufferInsertSize() { return 16 * 1024; }
static constexpr size_t bufferSize() { return 256 * 1024; } // See below for slack calculation
static constexpr size_t bufferInsertSize() { return 16 * 1024; }
void header() VL_MT_UNSAFE_ONE;
void trailer() VL_MT_UNSAFE_ONE;
@ -98,8 +98,8 @@ protected:
std::string m_filename; ///< Filename, for error messages
VerilatedAssertOneThread m_assertOne; ///< Assert only called from single thread
inline static size_t bufferSize() { return 256 * 1024; } // See below for slack calculation
inline static size_t bufferInsertSize() { return 16 * 1024; }
static constexpr size_t bufferSize() { return 256 * 1024; } // See below for slack calculation
static constexpr size_t bufferInsertSize() { return 16 * 1024; }
virtual void fill() = 0;
void header() VL_MT_UNSAFE_ONE;

View File

@ -559,7 +559,7 @@ template <> void VerilatedTrace<VL_DERIVED_T>::fullDouble(vluint32_t* oldp, doub
// All of these take a destination pointer where the string will be emitted,
// and a value to convert. There are a couple of variants for efficiency.
inline static void cvtCDataToStr(char* dstp, CData value) {
static inline void cvtCDataToStr(char* dstp, CData value) {
#ifdef VL_HAVE_SSE2
// Similar to cvtSDataToStr but only the bottom 8 byte lanes are used
const __m128i a = _mm_cvtsi32_si128(value);
@ -581,7 +581,7 @@ inline static void cvtCDataToStr(char* dstp, CData value) {
#endif
}
inline static void cvtSDataToStr(char* dstp, SData value) {
static inline void cvtSDataToStr(char* dstp, SData value) {
#ifdef VL_HAVE_SSE2
// We want each bit in the 16-bit input value to end up in a byte lane
// within the 128-bit XMM register. Note that x86 is little-endian and we
@ -617,7 +617,7 @@ inline static void cvtSDataToStr(char* dstp, SData value) {
#endif
}
inline static void cvtIDataToStr(char* dstp, IData value) {
static inline void cvtIDataToStr(char* dstp, IData value) {
#ifdef VL_HAVE_AVX2
// Similar to cvtSDataToStr but the bottom 16-bits are processed in the
// top half of the YMM registerss
@ -636,7 +636,7 @@ inline static void cvtIDataToStr(char* dstp, IData value) {
#endif
}
inline static void cvtQDataToStr(char* dstp, QData value) {
static inline void cvtQDataToStr(char* dstp, QData value) {
cvtIDataToStr(dstp, value >> 32);
cvtIDataToStr(dstp + 32, value);
}

View File

@ -63,7 +63,7 @@ public:
// CONSTRUCTORS
VerilatedVpio() = default;
virtual ~VerilatedVpio() = default;
inline static void* operator new(size_t size) VL_MT_SAFE {
static void* operator new(size_t size) VL_MT_SAFE {
// We new and delete tons of vpi structures, so keep them around
// To simplify our free list, we use a size large enough for all derived types
// We reserve word zero for the next pointer, as that's safer in case a
@ -79,13 +79,13 @@ public:
vluint8_t* newp = reinterpret_cast<vluint8_t*>(::operator new(chunk + 8));
return newp + 8;
}
inline static void operator delete(void* obj, size_t /*size*/)VL_MT_SAFE {
static void operator delete(void* obj, size_t /*size*/)VL_MT_SAFE {
vluint8_t* oldp = (static_cast<vluint8_t*>(obj)) - 8;
*(reinterpret_cast<void**>(oldp)) = t_freeHead;
t_freeHead = oldp;
}
// MEMBERS
static inline VerilatedVpio* castp(vpiHandle h) {
static VerilatedVpio* castp(vpiHandle h) {
return dynamic_cast<VerilatedVpio*>(reinterpret_cast<VerilatedVpio*>(h));
}
inline vpiHandle castVpiHandle() { return reinterpret_cast<vpiHandle>(this); }
@ -115,7 +115,7 @@ public:
m_cbData.value = &m_value;
}
virtual ~VerilatedVpioCb() override = default;
static inline VerilatedVpioCb* castp(vpiHandle h) {
static VerilatedVpioCb* castp(vpiHandle h) {
return dynamic_cast<VerilatedVpioCb*>(reinterpret_cast<VerilatedVpio*>(h));
}
virtual vluint32_t type() const override { return vpiCallback; }
@ -132,7 +132,7 @@ public:
explicit VerilatedVpioConst(vlsint32_t num)
: m_num{num} {}
virtual ~VerilatedVpioConst() override = default;
static inline VerilatedVpioConst* castp(vpiHandle h) {
static VerilatedVpioConst* castp(vpiHandle h) {
return dynamic_cast<VerilatedVpioConst*>(reinterpret_cast<VerilatedVpio*>(h));
}
virtual vluint32_t type() const override { return vpiConstant; }
@ -150,7 +150,7 @@ public:
virtual ~VerilatedVpioParam() override = default;
static inline VerilatedVpioParam* castp(vpiHandle h) {
static VerilatedVpioParam* castp(vpiHandle h) {
return dynamic_cast<VerilatedVpioParam*>(reinterpret_cast<VerilatedVpio*>(h));
}
virtual vluint32_t type() const override { return vpiParameter; }
@ -173,7 +173,7 @@ public:
explicit VerilatedVpioRange(const VerilatedRange* range)
: m_range{range} {}
virtual ~VerilatedVpioRange() override = default;
static inline VerilatedVpioRange* castp(vpiHandle h) {
static VerilatedVpioRange* castp(vpiHandle h) {
return dynamic_cast<VerilatedVpioRange*>(reinterpret_cast<VerilatedVpio*>(h));
}
virtual vluint32_t type() const override { return vpiRange; }
@ -199,7 +199,7 @@ public:
explicit VerilatedVpioScope(const VerilatedScope* scopep)
: m_scopep{scopep} {}
virtual ~VerilatedVpioScope() override = default;
static inline VerilatedVpioScope* castp(vpiHandle h) {
static VerilatedVpioScope* castp(vpiHandle h) {
return dynamic_cast<VerilatedVpioScope*>(reinterpret_cast<VerilatedVpio*>(h));
}
virtual vluint32_t type() const override { return vpiScope; }
@ -236,7 +236,7 @@ public:
virtual ~VerilatedVpioVar() override {
if (m_prevDatap) VL_DO_CLEAR(delete[] m_prevDatap, m_prevDatap = nullptr);
}
static inline VerilatedVpioVar* castp(vpiHandle h) {
static VerilatedVpioVar* castp(vpiHandle h) {
return dynamic_cast<VerilatedVpioVar*>(reinterpret_cast<VerilatedVpio*>(h));
}
const VerilatedVar* varp() const { return m_varp; }
@ -275,7 +275,7 @@ public:
m_varDatap = (static_cast<vluint8_t*>(varp->datap())) + entSize() * offset;
}
virtual ~VerilatedVpioMemoryWord() override = default;
static inline VerilatedVpioMemoryWord* castp(vpiHandle h) {
static VerilatedVpioMemoryWord* castp(vpiHandle h) {
return dynamic_cast<VerilatedVpioMemoryWord*>(reinterpret_cast<VerilatedVpio*>(h));
}
virtual vluint32_t type() const override { return vpiMemoryWord; }
@ -299,7 +299,7 @@ public:
explicit VerilatedVpioVarIter(const VerilatedScope* scopep)
: m_scopep{scopep} {}
virtual ~VerilatedVpioVarIter() override = default;
static inline VerilatedVpioVarIter* castp(vpiHandle h) {
static VerilatedVpioVarIter* castp(vpiHandle h) {
return dynamic_cast<VerilatedVpioVarIter*>(reinterpret_cast<VerilatedVpio*>(h));
}
virtual vluint32_t type() const override { return vpiIterator; }
@ -335,7 +335,7 @@ public:
, m_iteration{varp->unpacked().right()}
, m_direction{VL_LIKELY(varp->unpacked().left() > varp->unpacked().right()) ? 1 : -1} {}
virtual ~VerilatedVpioMemoryWordIter() override = default;
static inline VerilatedVpioMemoryWordIter* castp(vpiHandle h) {
static VerilatedVpioMemoryWordIter* castp(vpiHandle h) {
return dynamic_cast<VerilatedVpioMemoryWordIter*>(reinterpret_cast<VerilatedVpio*>(h));
}
virtual vluint32_t type() const override { return vpiIterator; }
@ -362,7 +362,7 @@ public:
if (strncmp(m_fullname, "TOP.", 4) == 0) m_fullname += 4;
m_name = m_scopep->identifier();
}
static inline VerilatedVpioModule* castp(vpiHandle h) {
static VerilatedVpioModule* castp(vpiHandle h) {
return dynamic_cast<VerilatedVpioModule*>(reinterpret_cast<VerilatedVpio*>(h));
}
virtual vluint32_t type() const override { return vpiModule; }
@ -380,7 +380,7 @@ public:
m_it = m_vec->begin();
}
virtual ~VerilatedVpioModuleIter() override = default;
static inline VerilatedVpioModuleIter* castp(vpiHandle h) {
static VerilatedVpioModuleIter* castp(vpiHandle h) {
return dynamic_cast<VerilatedVpioModuleIter*>(reinterpret_cast<VerilatedVpio*>(h));
}
virtual vluint32_t type() const override { return vpiIterator; }
@ -410,10 +410,6 @@ class VerilatedVpiImp final {
typedef std::list<VerilatedVpioCb*> VpioCbList;
typedef std::set<std::pair<QData, VerilatedVpioCb*>, VerilatedVpiTimedCbsCmp> VpioTimedCbs;
struct product_info {
PLI_BYTE8* product;
};
VpioCbList m_cbObjLists[CB_ENUM_MAX_VALUE]; // Callbacks for each supported reason
VpioTimedCbs m_timedCbs; // Time based callbacks
VerilatedVpiError* m_errorInfop = nullptr; // Container for vpi error info

View File

@ -989,10 +989,10 @@ public:
bool m_littleEndian : 1; // Bit vector is little endian
};
};
inline bool operator==(const VNumRange& rhs) const {
bool operator==(const VNumRange& rhs) const {
return m_hi == rhs.m_hi && m_lo == rhs.m_lo && mu_flags == rhs.mu_flags;
}
inline bool operator<(const VNumRange& rhs) const {
bool operator<(const VNumRange& rhs) const {
if ((m_hi < rhs.m_hi)) return true;
if (!(m_hi == rhs.m_hi)) return false; // lhs > rhs
if ((m_lo < rhs.m_lo)) return true;
@ -1091,11 +1091,11 @@ public:
VSigning m_numeric; // From AstNodeDType: Node is signed
AstBasicDTypeKwd m_keyword; // From AstBasicDType: What keyword created basic type
VNumRange m_nrange; // From AstBasicDType: Numeric msb/lsb (if non-opaque keyword)
inline bool operator==(const VBasicTypeKey& rhs) const {
bool operator==(const VBasicTypeKey& rhs) const {
return m_width == rhs.m_width && m_widthMin == rhs.m_widthMin && m_numeric == rhs.m_numeric
&& m_keyword == rhs.m_keyword && m_nrange == rhs.m_nrange;
}
inline bool operator<(const VBasicTypeKey& rhs) const {
bool operator<(const VBasicTypeKey& rhs) const {
if ((m_width < rhs.m_width)) return true;
if (!(m_width == rhs.m_width)) return false; // lhs > rhs
if ((m_widthMin < rhs.m_widthMin)) return true;
@ -1148,7 +1148,7 @@ public:
AstNode* toNodep() const { return reinterpret_cast<AstNode*>(m_u.up); }
V3GraphVertex* toGraphVertex() const { return reinterpret_cast<V3GraphVertex*>(m_u.up); }
int toInt() const { return m_u.ui; }
static inline VNUser fromInt(int i) { return VNUser(i); }
static VNUser fromInt(int i) { return VNUser(i); }
};
//######################################################################
@ -1350,9 +1350,9 @@ public:
uint32_t depth() const { return (m_both >> 24) & 255; }
uint32_t hshval() const { return m_both & M24; }
// OPERATORS
inline bool operator==(const V3Hash& rh) const { return m_both == rh.m_both; }
inline bool operator!=(const V3Hash& rh) const { return m_both != rh.m_both; }
inline bool operator<(const V3Hash& rh) const { return m_both < rh.m_both; }
bool operator==(const V3Hash& rh) const { return m_both == rh.m_both; }
bool operator!=(const V3Hash& rh) const { return m_both != rh.m_both; }
bool operator<(const V3Hash& rh) const { return m_both < rh.m_both; }
// CONSTRUCTORS
class Illegal {}; // for creator type-overload selection
class FullValue {}; // for creator type-overload selection

View File

@ -234,7 +234,7 @@ public:
, m_code{code}
, m_on{on} {}
~V3ConfigIgnoresLine() = default;
inline bool operator<(const V3ConfigIgnoresLine& rh) const {
bool operator<(const V3ConfigIgnoresLine& rh) const {
if (m_lineno < rh.m_lineno) return true;
if (m_lineno > rh.m_lineno) return false;
if (m_code < rh.m_code) return true;
@ -356,7 +356,7 @@ class V3ConfigResolver final {
~V3ConfigResolver() = default;
public:
inline static V3ConfigResolver& s() { return s_singleton; }
static V3ConfigResolver& s() { return s_singleton; }
V3ConfigModuleResolver& modules() { return m_modules; }
V3ConfigFileResolver& files() { return m_files; }

View File

@ -1730,7 +1730,7 @@ private:
}
struct SenItemCmp {
inline bool operator()(const AstSenItem* lhsp, const AstSenItem* rhsp) const {
bool operator()(const AstSenItem* lhsp, const AstSenItem* rhsp) const {
if (lhsp->type() < rhsp->type()) return true;
if (lhsp->type() > rhsp->type()) return false;
// Looks visually better if we keep sorted by name

View File

@ -216,7 +216,7 @@ public:
}
struct CmpName {
inline bool operator()(const AstNode* lhsp, const AstNode* rhsp) const {
bool operator()(const AstNode* lhsp, const AstNode* rhsp) const {
return lhsp->name() < rhsp->name();
}
};

View File

@ -79,12 +79,12 @@ class EmitCSyms final : EmitCBaseVisitor {
typedef std::vector<string> ScopeNameList;
typedef std::map<const string, ScopeNameList> ScopeNameHierarchy;
struct CmpName {
inline bool operator()(const ScopeModPair& lhsp, const ScopeModPair& rhsp) const {
bool operator()(const ScopeModPair& lhsp, const ScopeModPair& rhsp) const {
return lhsp.first->name() < rhsp.first->name();
}
};
struct CmpDpi {
inline bool operator()(const AstCFunc* lhsp, const AstCFunc* rhsp) const {
bool operator()(const AstCFunc* lhsp, const AstCFunc* rhsp) const {
if (lhsp->dpiImport() != rhsp->dpiImport()) {
// cppcheck-suppress comparisonOfFuncReturningBoolError
return lhsp->dpiImport() < rhsp->dpiImport();

View File

@ -65,12 +65,12 @@ class VWidthMinUsage final {
public:
enum en : uint8_t { LINT_WIDTH, MATCHES_WIDTH, VERILOG_WIDTH };
enum en m_e;
inline VWidthMinUsage()
VWidthMinUsage()
: m_e{LINT_WIDTH} {}
// cppcheck-suppress noExplicitConstructor
inline VWidthMinUsage(en _e)
VWidthMinUsage(en _e)
: m_e{_e} {}
explicit inline VWidthMinUsage(int _e)
explicit VWidthMinUsage(int _e)
: m_e(static_cast<en>(_e)) {} // Need () or GCC 4.8 false warning
operator en() const { return m_e; }
};

View File

@ -77,7 +77,7 @@ public:
//--------------------------------------------------------------------
struct GraphAcycEdgeCmp {
inline bool operator()(const V3GraphEdge* lhsp, const V3GraphEdge* rhsp) const {
bool operator()(const V3GraphEdge* lhsp, const V3GraphEdge* rhsp) const {
if (lhsp->weight() > rhsp->weight()) return true; // LHS goes first
if (lhsp->weight() < rhsp->weight()) return false; // RHS goes first
return false;

View File

@ -469,12 +469,12 @@ void V3Graph::makeEdgesNonCutable(V3EdgeFuncP edgeFuncp) {
// Algorithms - sorting
struct GraphSortVertexCmp {
inline bool operator()(const V3GraphVertex* lhsp, const V3GraphVertex* rhsp) const {
bool operator()(const V3GraphVertex* lhsp, const V3GraphVertex* rhsp) const {
return lhsp->sortCmp(rhsp) < 0;
}
};
struct GraphSortEdgeCmp {
inline bool operator()(const V3GraphEdge* lhsp, const V3GraphEdge* rhsp) const {
bool operator()(const V3GraphEdge* lhsp, const V3GraphEdge* rhsp) const {
return lhsp->sortCmp(rhsp) < 0;
}
};

View File

@ -34,7 +34,7 @@
// Levelizing class functions
struct CmpLevel {
inline bool operator()(const AstNodeModule* lhsp, const AstNodeModule* rhsp) const {
bool operator()(const AstNodeModule* lhsp, const AstNodeModule* rhsp) const {
return lhsp->level() < rhsp->level();
}
};

View File

@ -307,7 +307,7 @@ uint64_t VHashSha256::digestUInt64() {
}
string VHashSha256::digestHex() {
static const char* digits = "0123456789abcdef";
static const char* const digits = "0123456789abcdef";
const string& binhash = digestBinary();
string out;
out.reserve(70);
@ -323,7 +323,8 @@ string VHashSha256::digestSymbol() {
// has + and / for last two digits, but need C symbol, and we also
// avoid conflicts with use of _, so use "AB" at the end.
// Thus this function is non-reversible.
static const char* digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB";
static const char* const digits
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB";
const string& binhash = digestBinary();
string out;
out.reserve(28);

View File

@ -57,7 +57,7 @@ class VSymEnt final {
return level;
}
#else
static inline int debug() { return 0; } // NOT runtime, too hot of a function
static constexpr int debug() { return 0; } // NOT runtime, too hot of a function
#endif
public:
typedef IdNameMap::const_iterator const_iterator;

View File

@ -1671,7 +1671,7 @@ bool V3Task::dpiToInternalFrStmt(AstVar* portp, const string& frName, string& fr
}
const char* V3Task::dpiTemporaryVarSuffix() {
static const char* suffix = "__Vcvt";
static const char* const suffix = "__Vcvt";
return suffix;
}

View File

@ -32,8 +32,8 @@ private:
vluint64_t m_dataSize = 0; ///< Current entries in m_datap
vluint64_t m_bucketsCovered = 0; ///< Num buckets with sufficient coverage
static inline vluint64_t covBit(vluint64_t point) { return 1ULL << (point & 63); }
inline vluint64_t allocSize() const { return sizeof(vluint64_t) * m_dataSize / 64; }
static vluint64_t covBit(vluint64_t point) { return 1ULL << (point & 63); }
vluint64_t allocSize() const { return sizeof(vluint64_t) * m_dataSize / 64; }
void allocate(vluint64_t point) {
vluint64_t oldsize = m_dataSize;
if (m_dataSize < point) m_dataSize = (point + 64) & ~63ULL; // Keep power of two

View File

@ -134,7 +134,7 @@ void VlcTop::writeInfo(const string& filename) {
//********************************************************************
struct CmpComputrons {
inline bool operator()(const VlcTest* lhsp, const VlcTest* rhsp) const {
bool operator()(const VlcTest* lhsp, const VlcTest* rhsp) const {
if (lhsp->computrons() != rhsp->computrons()) {
return lhsp->computrons() < rhsp->computrons();
}