Internals: Move roundUpToMultipleOf into vlstd::
This commit is contained in:
parent
cc910fa4c4
commit
da7dd1fa16
|
|
@ -186,15 +186,6 @@ struct VlIsCustomStruct : public std::false_type {};
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct VlContainsCustomStruct : VlIsCustomStruct<T> {};
|
struct VlContainsCustomStruct : VlIsCustomStruct<T> {};
|
||||||
|
|
||||||
//=============================================================================
|
|
||||||
// Utility functions
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
inline constexpr size_t roundUpToMultipleOf(size_t value) {
|
|
||||||
static_assert((N & (N - 1)) == 0, "'N' must be a power of 2");
|
|
||||||
return (value + N - 1) & ~(N - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
//=========================================================================
|
//=========================================================================
|
||||||
// Mutex and threading support
|
// Mutex and threading support
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ class VlTriggerVec final {
|
||||||
// TODO: static assert N_Size > 0, and don't generate when empty
|
// TODO: static assert N_Size > 0, and don't generate when empty
|
||||||
|
|
||||||
// MEMBERS
|
// MEMBERS
|
||||||
alignas(16) std::array<uint64_t, roundUpToMultipleOf<64>(N_Size) / 64> m_flags; // The flags
|
alignas(16) std::array<uint64_t, vlstd::roundUpToMultipleOf<64>(N_Size) / 64> m_flags;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// CONSTRUCTOR
|
// CONSTRUCTOR
|
||||||
|
|
|
||||||
|
|
@ -264,7 +264,7 @@ void VerilatedVcd::bufferResize(size_t minsize) {
|
||||||
// writing when we are 3/4 full (with thus 2*minsize remaining free)
|
// writing when we are 3/4 full (with thus 2*minsize remaining free)
|
||||||
if (VL_UNLIKELY(minsize > m_wrChunkSize)) {
|
if (VL_UNLIKELY(minsize > m_wrChunkSize)) {
|
||||||
const char* oldbufp = m_wrBufp;
|
const char* oldbufp = m_wrBufp;
|
||||||
m_wrChunkSize = roundUpToMultipleOf<1024>(minsize * 2);
|
m_wrChunkSize = vlstd::roundUpToMultipleOf<1024>(minsize * 2);
|
||||||
m_wrBufp = new char[m_wrChunkSize * 8];
|
m_wrBufp = new char[m_wrChunkSize * 8];
|
||||||
std::memcpy(m_wrBufp, oldbufp, m_writep - oldbufp);
|
std::memcpy(m_wrBufp, oldbufp, m_writep - oldbufp);
|
||||||
m_writep = m_wrBufp + (m_writep - oldbufp);
|
m_writep = m_wrBufp + (m_writep - oldbufp);
|
||||||
|
|
@ -493,7 +493,7 @@ VerilatedVcd::Buffer* VerilatedVcd::getTraceBuffer(uint32_t fidx) {
|
||||||
// cppcheck-suppress unreadVariable // cppcheck bug, used below
|
// cppcheck-suppress unreadVariable // cppcheck bug, used below
|
||||||
constexpr size_t pageSize = 4096;
|
constexpr size_t pageSize = 4096;
|
||||||
// 4 * m_maxSignalBytes, so we can reserve 2 * m_maxSignalBytes at the end for safety
|
// 4 * m_maxSignalBytes, so we can reserve 2 * m_maxSignalBytes at the end for safety
|
||||||
size_t startingSize = roundUpToMultipleOf<pageSize>(4 * m_maxSignalBytes);
|
size_t startingSize = vlstd::roundUpToMultipleOf<pageSize>(4 * m_maxSignalBytes);
|
||||||
m_freeBuffers.emplace_back(new char[startingSize], startingSize);
|
m_freeBuffers.emplace_back(new char[startingSize], startingSize);
|
||||||
++m_numBuffers;
|
++m_numBuffers;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -729,6 +729,13 @@ T const& as_const(T& v) VL_MT_SAFE {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Utility function
|
||||||
|
template <size_t N>
|
||||||
|
inline constexpr size_t roundUpToMultipleOf(size_t value) {
|
||||||
|
static_assert((N & (N - 1)) == 0, "'N' must be a power of 2");
|
||||||
|
return (value + N - 1) & ~(N - 1);
|
||||||
|
}
|
||||||
|
|
||||||
}; // namespace vlstd
|
}; // namespace vlstd
|
||||||
|
|
||||||
//=========================================================================
|
//=========================================================================
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue