diff --git a/include/verilated.cpp b/include/verilated.cpp index 0885d9505..01d31413f 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -215,7 +215,7 @@ std::string _vl_string_vprintf(const char* formatp, va_list ap) VL_MT_SAFE { char* bufp = new char[len + 1]; VL_VSNPRINTF(bufp, len + 1, formatp, ap); - std::string out = std::string(bufp, len); + const std::string out = std::string(bufp, len); delete[] bufp; return out; } @@ -246,7 +246,7 @@ void VL_DBG_MSGF(const char* formatp, ...) VL_MT_SAFE { // includes that otherwise would be required in every Verilated module va_list ap; va_start(ap, formatp); - std::string out = _vl_string_vprintf(formatp, ap); + const std::string out = _vl_string_vprintf(formatp, ap); va_end(ap); // printf("-imm-V{t%d,%" VL_PRI64 "d}%s", VL_THREAD_ID(), _vl_dbg_sequence_number(), // out.c_str()); @@ -261,7 +261,7 @@ void VL_DBG_MSGF(const char* formatp, ...) VL_MT_SAFE { void VL_PRINTF_MT(const char* formatp, ...) VL_MT_SAFE { va_list ap; va_start(ap, formatp); - std::string out = _vl_string_vprintf(formatp, ap); + const std::string out = _vl_string_vprintf(formatp, ap); va_end(ap); VerilatedThreadMsgQueue::post(VerilatedMsg([=]() { // VL_PRINTF("%s", out.c_str()); @@ -301,7 +301,7 @@ vluint64_t vl_rand64() VL_MT_SAFE { if (VL_COUNTONES_I(t_state[1]) < 10) t_state[1] = ~t_state[1]; } // Xoroshiro128+ algorithm - vluint64_t result = t_state[0] + t_state[1]; + const vluint64_t result = t_state[0] + t_state[1]; t_state[1] ^= t_state[0]; t_state[0] = (((t_state[0] << 55) | (t_state[0] >> 9)) ^ t_state[1] ^ (t_state[1] << 14)); t_state[1] = (t_state[1] << 36) | (t_state[1] >> 28); @@ -356,7 +356,7 @@ WDataOutP VL_ZERO_RESET_W(int obits, WDataOutP outwp) VL_MT_SAFE { //=========================================================================== // Debug -void _vl_debug_print_w(int lbits, WDataInP iwp) VL_MT_SAFE { +void _vl_debug_print_w(int lbits, const WDataInP iwp) VL_MT_SAFE { VL_PRINTF_MT(" Data: w%d: ", lbits); for (int i = VL_WORDS_I(lbits) - 1; i >= 0; --i) VL_PRINTF_MT("%08x ", iwp[i]); VL_PRINTF_MT("\n"); @@ -365,24 +365,24 @@ void _vl_debug_print_w(int lbits, WDataInP iwp) VL_MT_SAFE { //=========================================================================== // Slow math -WDataOutP _vl_moddiv_w(int lbits, WDataOutP owp, WDataInP lwp, WDataInP rwp, +WDataOutP _vl_moddiv_w(int lbits, WDataOutP owp, const WDataInP lwp, const WDataInP rwp, bool is_modulus) VL_MT_SAFE { // See Knuth Algorithm D. Computes u/v = q.r // This isn't massively tuned, as wide division is rare // for debug see V3Number version // Requires clean input - int words = VL_WORDS_I(lbits); + const int words = VL_WORDS_I(lbits); for (int i = 0; i < words; ++i) owp[i] = 0; // Find MSB and check for zero. - int umsbp1 = VL_MOSTSETBITP1_W(words, lwp); // dividend - int vmsbp1 = VL_MOSTSETBITP1_W(words, rwp); // divisor + const int umsbp1 = VL_MOSTSETBITP1_W(words, lwp); // dividend + const int vmsbp1 = VL_MOSTSETBITP1_W(words, rwp); // divisor if (VL_UNLIKELY(vmsbp1 == 0) // rwp==0 so division by zero. Return 0. || VL_UNLIKELY(umsbp1 == 0)) { // 0/x so short circuit and return 0 return owp; } - int uw = VL_WORDS_I(umsbp1); // aka "m" in the algorithm - int vw = VL_WORDS_I(vmsbp1); // aka "n" in the algorithm + const int uw = VL_WORDS_I(umsbp1); // aka "m" in the algorithm + const int vw = VL_WORDS_I(vmsbp1); // aka "n" in the algorithm if (vw == 1) { // Single divisor word breaks rest of algorithm vluint64_t k = 0; @@ -408,8 +408,8 @@ WDataOutP _vl_moddiv_w(int lbits, WDataOutP owp, WDataInP lwp, WDataInP rwp, // Algorithm requires divisor MSB to be set // Copy and shift to normalize divisor so MSB of vn[vw-1] is set - int s = 31 - VL_BITBIT_I(vmsbp1 - 1); // shift amount (0...31) - vluint32_t shift_mask = s ? 0xffffffff : 0; // otherwise >> 32 won't mask the value + const int s = 31 - VL_BITBIT_I(vmsbp1 - 1); // shift amount (0...31) + const vluint32_t shift_mask = s ? 0xffffffff : 0; // otherwise >> 32 won't mask the value for (int i = vw - 1; i > 0; --i) { vn[i] = (rwp[i] << s) | (shift_mask & (rwp[i - 1] >> (32 - s))); } @@ -429,8 +429,8 @@ WDataOutP _vl_moddiv_w(int lbits, WDataOutP owp, WDataInP lwp, WDataInP rwp, // Main loop for (int j = uw - vw; j >= 0; --j) { // Estimate - vluint64_t unw64 = (static_cast(un[j + vw]) << 32ULL - | static_cast(un[j + vw - 1])); + const vluint64_t unw64 = (static_cast(un[j + vw]) << 32ULL + | static_cast(un[j + vw - 1])); vluint64_t qhat = unw64 / static_cast(vn[vw - 1]); vluint64_t rhat = unw64 - qhat * static_cast(vn[vw - 1]); @@ -478,8 +478,8 @@ WDataOutP _vl_moddiv_w(int lbits, WDataOutP owp, WDataInP lwp, WDataInP rwp, } } -WDataOutP VL_POW_WWW(int obits, int, int rbits, WDataOutP owp, WDataInP lwp, - WDataInP rwp) VL_MT_SAFE { +WDataOutP VL_POW_WWW(int obits, int, int rbits, WDataOutP owp, const WDataInP lwp, + const WDataInP rwp) VL_MT_SAFE { // obits==lbits, rbits can be different owp[0] = 1; for (int i = 1; i < VL_WORDS_I(obits); i++) owp[i] = 0; @@ -501,13 +501,13 @@ WDataOutP VL_POW_WWW(int obits, int, int rbits, WDataOutP owp, WDataInP lwp, } return owp; } -WDataOutP VL_POW_WWQ(int obits, int lbits, int rbits, WDataOutP owp, WDataInP lwp, +WDataOutP VL_POW_WWQ(int obits, int lbits, int rbits, WDataOutP owp, const WDataInP lwp, QData rhs) VL_MT_SAFE { VlWide rhsw; VL_SET_WQ(rhsw, rhs); return VL_POW_WWW(obits, lbits, rbits, owp, lwp, rhsw); } -QData VL_POW_QQW(int, int, int rbits, QData lhs, WDataInP rwp) VL_MT_SAFE { +QData VL_POW_QQW(int, int, int rbits, QData lhs, const WDataInP rwp) VL_MT_SAFE { // Skip check for rhs == 0, as short-circuit doesn't save time if (VL_UNLIKELY(lhs == 0)) return 0; QData power = lhs; @@ -519,11 +519,11 @@ QData VL_POW_QQW(int, int, int rbits, QData lhs, WDataInP rwp) VL_MT_SAFE { return out; } -WDataOutP VL_POWSS_WWW(int obits, int, int rbits, WDataOutP owp, WDataInP lwp, WDataInP rwp, - bool lsign, bool rsign) VL_MT_SAFE { +WDataOutP VL_POWSS_WWW(int obits, int, int rbits, WDataOutP owp, const WDataInP lwp, + const WDataInP rwp, bool lsign, bool rsign) VL_MT_SAFE { // obits==lbits, rbits can be different if (rsign && VL_SIGN_W(rbits, rwp)) { - int words = VL_WORDS_I(obits); + const int words = VL_WORDS_I(obits); VL_ZERO_W(obits, owp); EData lor = 0; // 0=all zeros, ~0=all ones, else mix for (int i = 1; i < (words - 1); ++i) { lor |= lwp[i]; } @@ -545,13 +545,13 @@ WDataOutP VL_POWSS_WWW(int obits, int, int rbits, WDataOutP owp, WDataInP lwp, W } return VL_POW_WWW(obits, rbits, rbits, owp, lwp, rwp); } -WDataOutP VL_POWSS_WWQ(int obits, int lbits, int rbits, WDataOutP owp, WDataInP lwp, QData rhs, - bool lsign, bool rsign) VL_MT_SAFE { +WDataOutP VL_POWSS_WWQ(int obits, int lbits, int rbits, WDataOutP owp, const WDataInP lwp, + QData rhs, bool lsign, bool rsign) VL_MT_SAFE { VlWide rhsw; VL_SET_WQ(rhsw, rhs); return VL_POWSS_WWW(obits, lbits, rbits, owp, lwp, rhsw, lsign, rsign); } -QData VL_POWSS_QQW(int obits, int, int rbits, QData lhs, WDataInP rwp, bool lsign, +QData VL_POWSS_QQW(int obits, int, int rbits, QData lhs, const WDataInP rwp, bool lsign, bool rsign) VL_MT_SAFE { // Skip check for rhs == 0, as short-circuit doesn't save time if (rsign && VL_SIGN_W(rbits, rwp)) { @@ -571,23 +571,23 @@ QData VL_POWSS_QQW(int obits, int, int rbits, QData lhs, WDataInP rwp, bool lsig return VL_POW_QQW(obits, rbits, rbits, lhs, rwp); } -double VL_ITOR_D_W(int lbits, WDataInP lwp) VL_PURE { +double VL_ITOR_D_W(int lbits, const WDataInP lwp) VL_PURE { int ms_word = VL_WORDS_I(lbits) - 1; for (; !lwp[ms_word] && ms_word > 0;) --ms_word; if (ms_word == 0) return static_cast(lwp[0]); if (ms_word == 1) return static_cast(VL_SET_QW(lwp)); // We need 53 bits of mantissa, which might mean looking at 3 words // namely ms_word, ms_word-1 and ms_word-2 - EData ihi = lwp[ms_word]; - EData imid = lwp[ms_word - 1]; - EData ilo = lwp[ms_word - 2]; - double hi = static_cast(ihi) * std::exp2(2 * VL_EDATASIZE); - double mid = static_cast(imid) * std::exp2(VL_EDATASIZE); - double lo = static_cast(ilo); - double d = (hi + mid + lo) * std::exp2(VL_EDATASIZE * (ms_word - 2)); + const EData ihi = lwp[ms_word]; + const EData imid = lwp[ms_word - 1]; + const EData ilo = lwp[ms_word - 2]; + const double hi = static_cast(ihi) * std::exp2(2 * VL_EDATASIZE); + const double mid = static_cast(imid) * std::exp2(VL_EDATASIZE); + const double lo = static_cast(ilo); + const double d = (hi + mid + lo) * std::exp2(VL_EDATASIZE * (ms_word - 2)); return d; } -double VL_ISTOR_D_W(int lbits, WDataInP lwp) VL_PURE { +double VL_ISTOR_D_W(int lbits, const WDataInP lwp) VL_PURE { if (!VL_SIGN_W(lbits, lwp)) return VL_ITOR_D_W(lbits, lwp); vluint32_t pos[VL_MULS_MAX_WORDS + 1]; // Fixed size, as MSVC++ doesn't allow [words] here VL_NEGATE_W(VL_WORDS_I(lbits), pos, lwp); @@ -599,8 +599,8 @@ double VL_ISTOR_D_W(int lbits, WDataInP lwp) VL_PURE { // Formatting // Output a string representation of a wide number -std::string VL_DECIMAL_NW(int width, WDataInP lwp) VL_MT_SAFE { - int maxdecwidth = (width + 3) * 4 / 3; +std::string VL_DECIMAL_NW(int width, const WDataInP lwp) VL_MT_SAFE { + const int maxdecwidth = (width + 3) * 4 / 3; // Or (maxdecwidth+7)/8], but can't have more than 4 BCD bits per word VlWide bcd; VL_ZERO_RESET_W(maxdecwidth, bcd); @@ -652,17 +652,17 @@ std::string _vl_vsformat_time(char* tmp, T ld, int timeunit, bool left, size_t w WDataInP shifted = VL_EXTEND_WQ(b, 0, tmp0, static_cast(ld)); if (shift < 0) { - WDataInP pow10 = VL_EXTEND_WQ(b, 0, tmp1, vl_time_pow10(-shift)); + const WDataInP pow10 = VL_EXTEND_WQ(b, 0, tmp1, vl_time_pow10(-shift)); shifted = VL_DIV_WWW(b, tmp2, shifted, pow10); } else { - WDataInP pow10 = VL_EXTEND_WQ(b, 0, tmp1, vl_time_pow10(shift)); + const WDataInP pow10 = VL_EXTEND_WQ(b, 0, tmp1, vl_time_pow10(shift)); shifted = VL_MUL_W(w, tmp2, shifted, pow10); } - WDataInP fracDigitsPow10 = VL_EXTEND_WQ(b, 0, tmp3, vl_time_pow10(fracDigits)); - WDataInP integer = VL_DIV_WWW(b, tmp0, shifted, fracDigitsPow10); - WDataInP frac = VL_MODDIV_WWW(b, tmp1, shifted, fracDigitsPow10); - WDataInP max64Bit + const WDataInP fracDigitsPow10 = VL_EXTEND_WQ(b, 0, tmp3, vl_time_pow10(fracDigits)); + const WDataInP integer = VL_DIV_WWW(b, tmp0, shifted, fracDigitsPow10); + const WDataInP frac = VL_MODDIV_WWW(b, tmp1, shifted, fracDigitsPow10); + const WDataInP max64Bit = VL_EXTEND_WQ(b, 0, tmp2, std::numeric_limits::max()); // breaks shifted if (VL_GT_W(w, integer, max64Bit)) { WDataOutP v = VL_ASSIGN_W(b, tmp3, integer); // breaks fracDigitsPow10 @@ -674,7 +674,7 @@ std::string _vl_vsformat_time(char* tmp, T ld, int timeunit, bool left, size_t w *ptr = '\0'; while (VL_GT_W(w, v, zero)) { --ptr; - WDataInP mod = VL_MODDIV_WWW(b, tmp2, v, ten); // breaks max64Bit + const WDataInP mod = VL_MODDIV_WWW(b, tmp2, v, ten); // breaks max64Bit *ptr = "0123456789"[VL_SET_QW(mod)]; VlWide divided; VL_DIV_WWW(b, divided, v, ten); @@ -801,7 +801,7 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) VL_MT_SA case 'g': case '^': { // Realtime const int lbits = va_arg(ap, int); - double d = va_arg(ap, double); + const double d = va_arg(ap, double); if (lbits) {} // UNUSED - always 64 if (fmt == '^') { // Realtime if (!widthSet) width = Verilated::threadContextp()->impp()->timeFormatWidth(); @@ -834,7 +834,7 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) VL_MT_SA } switch (fmt) { case 'c': { - IData charval = ld & 0xff; + const IData charval = ld & 0xff; output += static_cast(charval); break; } @@ -842,7 +842,7 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) VL_MT_SA std::string field; for (; lsb >= 0; --lsb) { lsb = (lsb / 8) * 8; // Next digit - IData charval = VL_BITRSHIFT_W(lwp, lsb) & 0xff; + const IData charval = VL_BITRSHIFT_W(lwp, lsb) & 0xff; field += (charval == 0) ? ' ' : charval; } std::string padding; @@ -957,7 +957,7 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) VL_MT_SA } break; default: { // LCOV_EXCL_START - std::string msg = std::string("Unknown _vl_vsformat code: ") + pos[0]; + const std::string msg = std::string("Unknown _vl_vsformat code: ") + pos[0]; VL_FATAL_MT(__FILE__, __LINE__, "", msg.c_str()); break; } // LCOV_EXCL_STOP @@ -982,11 +982,11 @@ static inline void _vl_vsss_advance(FILE* fp, int& floc) VL_MT_SAFE { floc -= 8; } } -static inline int _vl_vsss_peek(FILE* fp, int& floc, WDataInP fromp, +static inline int _vl_vsss_peek(FILE* fp, int& floc, const WDataInP fromp, const std::string& fstr) VL_MT_SAFE { // Get a character without advancing if (fp) { - int data = std::fgetc(fp); + const int data = std::fgetc(fp); if (data == EOF) return EOF; ungetc(data, fp); return data; @@ -1000,16 +1000,17 @@ static inline int _vl_vsss_peek(FILE* fp, int& floc, WDataInP fromp, } } } -static inline void _vl_vsss_skipspace(FILE* fp, int& floc, WDataInP fromp, +static inline void _vl_vsss_skipspace(FILE* fp, int& floc, const WDataInP fromp, const std::string& fstr) VL_MT_SAFE { while (true) { - int c = _vl_vsss_peek(fp, floc, fromp, fstr); + const int c = _vl_vsss_peek(fp, floc, fromp, fstr); if (c == EOF || !std::isspace(c)) return; _vl_vsss_advance(fp, floc); } } -static inline void _vl_vsss_read_str(FILE* fp, int& floc, WDataInP fromp, const std::string& fstr, - char* tmpp, const char* acceptp) VL_MT_SAFE { +static inline void _vl_vsss_read_str(FILE* fp, int& floc, const WDataInP fromp, + const std::string& fstr, char* tmpp, + const char* acceptp) VL_MT_SAFE { // Read into tmp, consisting of characters from acceptp list char* cp = tmpp; while (true) { @@ -1023,8 +1024,9 @@ static inline void _vl_vsss_read_str(FILE* fp, int& floc, WDataInP fromp, const *cp++ = '\0'; // VL_DBG_MSGF(" _read got='"<impp()->fdToFp(lhs); } -void _vl_vint_to_string(int obits, char* destoutp, WDataInP sourcep) VL_MT_SAFE { +void _vl_vint_to_string(int obits, char* destoutp, const WDataInP sourcep) VL_MT_SAFE { // See also VL_DATA_TO_STRING_NW int lsb = obits - 1; bool start = true; @@ -1303,7 +1305,7 @@ void _vl_vint_to_string(int obits, char* destoutp, WDataInP sourcep) VL_MT_SAFE void _vl_string_to_vint(int obits, void* destp, size_t srclen, const char* srcp) VL_MT_SAFE { // Convert C string to Verilog format - size_t bytes = VL_BYTES_I(obits); + const size_t bytes = VL_BYTES_I(obits); char* op = reinterpret_cast(destp); if (srclen > bytes) srclen = bytes; // Don't overflow destination size_t i = 0; @@ -1315,7 +1317,7 @@ static IData getLine(std::string& str, IData fpi, size_t maxLen) VL_MT_SAFE { str.clear(); // While threadsafe, each thread can only access different file handles - FILE* fp = VL_CVT_I_FP(fpi); + FILE* const fp = VL_CVT_I_FP(fpi); if (VL_UNLIKELY(!fp)) return 0; // We don't use fgets, as we must read \0s. @@ -1331,7 +1333,7 @@ static IData getLine(std::string& str, IData fpi, size_t maxLen) VL_MT_SAFE { IData VL_FGETS_IXI(int obits, void* destp, IData fpi) VL_MT_SAFE { std::string str; const IData bytes = VL_BYTES_I(obits); - IData got = getLine(str, fpi, bytes); + const IData got = getLine(str, fpi, bytes); if (VL_UNLIKELY(str.empty())) return 0; @@ -1351,7 +1353,7 @@ IData VL_FGETS_NI(std::string& dest, IData fpi) VL_MT_SAFE { IData VL_FERROR_IN(IData, std::string& outputr) VL_MT_SAFE { // We ignore lhs/fpi - IEEE says "most recent error" so probably good enough - IData ret = errno; + const IData ret = errno; outputr = std::string(::std::strerror(ret)); return ret; } @@ -1474,12 +1476,12 @@ void VL_FWRITEF(IData fpi, const char* formatp, ...) VL_MT_SAFE { IData VL_FSCANF_IX(IData fpi, const char* formatp, ...) VL_MT_SAFE { // While threadsafe, each thread can only access different file handles - FILE* fp = VL_CVT_I_FP(fpi); + FILE* const fp = VL_CVT_I_FP(fpi); if (VL_UNLIKELY(!fp)) return 0; va_list ap; va_start(ap, formatp); - IData got = _vl_vsscanf(fp, 0, nullptr, "", formatp, ap); + const IData got = _vl_vsscanf(fp, 0, nullptr, "", formatp, ap); va_end(ap); return got; } @@ -1490,7 +1492,7 @@ IData VL_SSCANF_IIX(int lbits, IData ld, const char* formatp, ...) VL_MT_SAFE { va_list ap; va_start(ap, formatp); - IData got = _vl_vsscanf(nullptr, lbits, fnw, "", formatp, ap); + const IData got = _vl_vsscanf(nullptr, lbits, fnw, "", formatp, ap); va_end(ap); return got; } @@ -1500,21 +1502,21 @@ IData VL_SSCANF_IQX(int lbits, QData ld, const char* formatp, ...) VL_MT_SAFE { va_list ap; va_start(ap, formatp); - IData got = _vl_vsscanf(nullptr, lbits, fnw, "", formatp, ap); + const IData got = _vl_vsscanf(nullptr, lbits, fnw, "", formatp, ap); va_end(ap); return got; } -IData VL_SSCANF_IWX(int lbits, WDataInP lwp, const char* formatp, ...) VL_MT_SAFE { +IData VL_SSCANF_IWX(int lbits, const WDataInP lwp, const char* formatp, ...) VL_MT_SAFE { va_list ap; va_start(ap, formatp); - IData got = _vl_vsscanf(nullptr, lbits, lwp, "", formatp, ap); + const IData got = _vl_vsscanf(nullptr, lbits, lwp, "", formatp, ap); va_end(ap); return got; } IData VL_SSCANF_INX(int, const std::string& ld, const char* formatp, ...) VL_MT_SAFE { va_list ap; va_start(ap, formatp); - IData got = _vl_vsscanf(nullptr, ld.length() * 8, nullptr, ld, formatp, ap); + const IData got = _vl_vsscanf(nullptr, ld.length() * 8, nullptr, ld, formatp, ap); va_end(ap); return got; } @@ -1522,7 +1524,7 @@ IData VL_SSCANF_INX(int, const std::string& ld, const char* formatp, ...) VL_MT_ IData VL_FREAD_I(int width, int array_lsb, int array_size, void* memp, IData fpi, IData start, IData count) VL_MT_SAFE { // While threadsafe, each thread can only access different file handles - FILE* fp = VL_CVT_I_FP(fpi); + FILE* const fp = VL_CVT_I_FP(fpi); if (VL_UNLIKELY(!fp)) return 0; if (count > (array_size - (start - array_lsb))) count = array_size - (start - array_lsb); // Prep for reading @@ -1576,10 +1578,10 @@ IData VL_SYSTEM_IQ(QData lhs) VL_MT_SAFE { VL_SET_WQ(lhsw, lhs); return VL_SYSTEM_IW(VL_WQ_WORDS_E, lhsw); } -IData VL_SYSTEM_IW(int lhswords, WDataInP lhsp) VL_MT_SAFE { +IData VL_SYSTEM_IW(int lhswords, const WDataInP lhsp) VL_MT_SAFE { char filenamez[VL_TO_STRING_MAX_WORDS * VL_EDATASIZE + 1]; _vl_vint_to_string(lhswords * VL_EDATASIZE, filenamez, lhsp); - int code = std::system(filenamez); // Yes, std::system() is threadsafe + const int code = std::system(filenamez); // Yes, std::system() is threadsafe return code >> 8; // Want exit status } @@ -1707,7 +1709,7 @@ std::string VL_TO_STRING(CData lhs) { return VL_SFORMATF_NX("'h%0x", 8, lhs); } std::string VL_TO_STRING(SData lhs) { return VL_SFORMATF_NX("'h%0x", 16, lhs); } std::string VL_TO_STRING(IData lhs) { return VL_SFORMATF_NX("'h%0x", 32, lhs); } std::string VL_TO_STRING(QData lhs) { return VL_SFORMATF_NX("'h%0x", 64, lhs); } -std::string VL_TO_STRING_W(int words, WDataInP obj) { +std::string VL_TO_STRING_W(int words, const WDataInP obj) { return VL_SFORMATF_NX("'h%0x", words * VL_EDATASIZE, obj); } @@ -1722,7 +1724,7 @@ std::string VL_TOUPPER_NN(const std::string& ld) VL_MT_SAFE { return out; } -std::string VL_CVT_PACK_STR_NW(int lwords, WDataInP lwp) VL_MT_SAFE { +std::string VL_CVT_PACK_STR_NW(int lwords, const WDataInP lwp) VL_MT_SAFE { // See also _vl_vint_to_string char destout[VL_TO_STRING_MAX_WORDS * VL_EDATASIZE + 1]; int obits = lwords * VL_EDATASIZE; @@ -1804,7 +1806,7 @@ static const char* formatBinary(int nBits, vluint32_t bits) { static VL_THREAD_LOCAL char t_buf[64]; for (int i = 0; i < nBits; i++) { - bool isOne = bits & (1 << (nBits - 1 - i)); + const bool isOne = bits & (1 << (nBits - 1 - i)); t_buf[i] = (isOne ? '1' : '0'); } t_buf[nBits] = '\0'; @@ -1885,7 +1887,7 @@ bool VlReadMem::get(QData& addrr, std::string& valuer) { // Check for hex or binary digits as file format requests else if (std::isxdigit(c) || (!reading_addr && (c == 'x' || c == 'X'))) { c = std::tolower(c); - int value + const int value = (c >= 'a' ? (c == 'x' ? VL_RAND_RESET_I(4) : (c - 'a' + 10)) : (c - '0')); if (reading_addr) { // Decode @ addresses @@ -1914,12 +1916,13 @@ bool VlReadMem::get(QData& addrr, std::string& valuer) { return false; // EOF } void VlReadMem::setData(void* valuep, const std::string& rhs) { - QData shift = m_hex ? 4ULL : 1ULL; + const QData shift = m_hex ? 4ULL : 1ULL; bool innum = false; // Shift value in for (const auto& i : rhs) { - char c = std::tolower(i); - int value = (c >= 'a' ? (c == 'x' ? VL_RAND_RESET_I(4) : (c - 'a' + 10)) : (c - '0')); + const char c = std::tolower(i); + const int value + = (c >= 'a' ? (c == 'x' ? VL_RAND_RESET_I(4) : (c - 'a' + 10)) : (c - '0')); if (m_bits <= 8) { CData* datap = reinterpret_cast(valuep); if (!innum) *datap = 0; @@ -2001,9 +2004,9 @@ void VlWriteMem::print(QData addr, bool addrstamp, const void* valuep) { } } else if (m_bits <= 64) { const QData* datap = reinterpret_cast(valuep); - vluint64_t value = VL_MASK_Q(m_bits) & *datap; - vluint32_t lo = value & 0xffffffff; - vluint32_t hi = value >> 32; + const vluint64_t value = VL_MASK_Q(m_bits) & *datap; + const vluint32_t lo = value & 0xffffffff; + const vluint32_t hi = value >> 32; if (m_hex) { fprintf(m_fp, memhFormat(m_bits - 32), hi); fprintf(m_fp, "%08x\n", lo); @@ -2012,7 +2015,7 @@ void VlWriteMem::print(QData addr, bool addrstamp, const void* valuep) { fprintf(m_fp, "%s\n", formatBinary(32, lo)); } } else { - WDataInP datap = reinterpret_cast(valuep); + const WDataInP datap = reinterpret_cast(valuep); // output as a sequence of VL_EDATASIZE'd words // from MSB to LSB. Mask off the MSB word which could // contain junk above the top of valid data. @@ -2022,7 +2025,7 @@ void VlWriteMem::print(QData addr, bool addrstamp, const void* valuep) { EData data = datap[word_idx]; if (first) { data &= VL_MASK_E(m_bits); - int top_word_nbits = VL_BITBIT_E(m_bits - 1) + 1; + const int top_word_nbits = VL_BITBIT_E(m_bits - 1) + 1; if (m_hex) { fprintf(m_fp, memhFormat(top_word_nbits), data); } else { @@ -2108,7 +2111,7 @@ void VL_WRITEMEM_N(bool hex, // Hex format, else binary if (VL_UNLIKELY(!wmem.isOpen())) return; for (QData addr = start; addr <= end; ++addr) { - QData row_offset = addr - array_lsb; + const QData row_offset = addr - array_lsb; if (bits <= 8) { const CData* datap = &(reinterpret_cast(memp))[row_offset]; wmem.print(addr, false, datap); @@ -2122,8 +2125,8 @@ void VL_WRITEMEM_N(bool hex, // Hex format, else binary const QData* datap = &(reinterpret_cast(memp))[row_offset]; wmem.print(addr, false, datap); } else { - WDataInP memDatap = reinterpret_cast(memp); - WDataInP datap = &memDatap[row_offset * VL_WORDS_I(bits)]; + const WDataInP memDatap = reinterpret_cast(memp); + const WDataInP datap = &memDatap[row_offset * VL_WORDS_I(bits)]; wmem.print(addr, false, datap); } } @@ -2351,7 +2354,7 @@ void VerilatedContext::timeprecision(int value) VL_MT_SAFE { const VerilatedLockGuard lock(m_mutex); m_s.m_timeprecision = value; #ifdef SYSTEMC_VERSION - sc_time sc_res = sc_get_time_resolution(); + const sc_time sc_res = sc_get_time_resolution(); int sc_prec = 99; if (sc_res == sc_time(1, SC_SEC)) { sc_prec = 0; @@ -2373,7 +2376,7 @@ void VerilatedContext::timeprecision(int value) VL_MT_SAFE { << ". Suggest use 'sc_set_time_resolution(" << vl_time_str(value) << ")', or Verilator '--timescale-override " << vl_time_str(sc_prec) << "/" << vl_time_str(sc_prec) << "'"; - std::string msgs = msg.str(); + const std::string msgs = msg.str(); VL_FATAL_MT("", 0, "", msgs.c_str()); } #endif @@ -2434,7 +2437,7 @@ std::string VerilatedContextImp::argPlusMatch(const char* prefixp) VL_MT_SAFE_EXCLUDES(m_argMutex) { const VerilatedLockGuard lock(m_argMutex); // Note prefixp does not include the leading "+" - size_t len = std::strlen(prefixp); + const size_t len = std::strlen(prefixp); if (VL_UNLIKELY(!m_args.m_argVecLoaded)) { m_args.m_argVecLoaded = true; // Complain only once VL_FATAL_MT("unknown", 0, "", @@ -2511,7 +2514,7 @@ void VerilatedContextImp::commandArgVl(const std::string& arg) { } bool VerilatedContextImp::commandArgVlValue(const std::string& arg, const std::string& prefix, std::string& valuer) { - size_t len = prefix.length(); + const size_t len = prefix.length(); if (0 == std::strncmp(prefix.c_str(), arg.c_str(), len)) { valuer = arg.substr(len); return true; @@ -2528,7 +2531,7 @@ void VerilatedContext::randSeed(int val) VL_MT_SAFE { // and so the rand seed's mutex must also be static const VerilatedLockGuard lock(VerilatedContextImp::s().s_randMutex); m_s.m_randSeed = val; - vluint64_t newEpoch = VerilatedContextImp::s().s_randSeedEpoch + 1; + const vluint64_t newEpoch = VerilatedContextImp::s().s_randSeedEpoch + 1; // Obververs must see new epoch AFTER seed updated #ifdef VL_THREADED std::atomic_signal_fence(std::memory_order_release); @@ -2623,7 +2626,7 @@ const char* Verilated::catName(const char* n1, const char* n2, int scopet, // Used by symbol table creation to make module names static VL_THREAD_LOCAL char* t_strp = nullptr; static VL_THREAD_LOCAL size_t t_len = 0; - size_t newlen + const size_t newlen = std::strlen(n1) + std::strlen(n2) + std::strlen(delimiter) + (scopet > 0 ? 2 : 1); if (VL_UNLIKELY(!t_strp || newlen > t_len)) { if (t_strp) delete[] t_strp; @@ -2726,8 +2729,8 @@ void Verilated::nullPointerError(const char* filename, int linenum) VL_MT_SAFE { void Verilated::overWidthError(const char* signame) VL_MT_SAFE { // Slowpath - Called only when signal sets too high of a bit - std::string msg = (std::string("Testbench C set input '") + signame - + "' to value that overflows what the signal's width can fit"); + const std::string msg = (std::string("Testbench C set input '") + signame + + "' to value that overflows what the signal's width can fit"); VL_FATAL_MT("unknown", 0, "", msg.c_str()); VL_UNREACHABLE } @@ -2889,8 +2892,8 @@ void VerilatedScope::varInsert(int finalize, const char* namep, void* datap, boo va_list ap; va_start(ap, dims); for (int i = 0; i < dims; ++i) { - int msb = va_arg(ap, int); - int lsb = va_arg(ap, int); + const int msb = va_arg(ap, int); + const int lsb = va_arg(ap, int); if (i == 0) { var.m_packed.m_left = msb; var.m_packed.m_right = lsb; @@ -2921,18 +2924,20 @@ VerilatedVar* VerilatedScope::varFind(const char* namep) const VL_MT_SAFE_POSTIN void* VerilatedScope::exportFindNullError(int funcnum) VL_MT_SAFE { // Slowpath - Called only when find has failed - std::string msg = (std::string("Testbench C called '") + VerilatedImp::exportName(funcnum) - + "' but scope wasn't set, perhaps due to dpi import call without " - + "'context', or missing svSetScope. See IEEE 1800-2017 35.5.3."); + const std::string msg + = (std::string("Testbench C called '") + VerilatedImp::exportName(funcnum) + + "' but scope wasn't set, perhaps due to dpi import call without " + + "'context', or missing svSetScope. See IEEE 1800-2017 35.5.3."); VL_FATAL_MT("unknown", 0, "", msg.c_str()); return nullptr; } void* VerilatedScope::exportFindError(int funcnum) const { // Slowpath - Called only when find has failed - std::string msg = (std::string("Testbench C called '") + VerilatedImp::exportName(funcnum) - + "' but this DPI export function exists only in other scopes, not scope '" - + name() + "'"); + const std::string msg + = (std::string("Testbench C called '") + VerilatedImp::exportName(funcnum) + + "' but this DPI export function exists only in other scopes, not scope '" + name() + + "'"); VL_FATAL_MT("unknown", 0, "", msg.c_str()); return nullptr; } diff --git a/include/verilated.h b/include/verilated.h index fcd87fb8d..107f217de 100644 --- a/include/verilated.h +++ b/include/verilated.h @@ -972,7 +972,7 @@ inline QData VL_RDTSC_Q() { extern void VL_PRINTTIMESCALE(const char* namep, const char* timeunitp, const VerilatedContext* contextp) VL_MT_SAFE; -extern WDataOutP _vl_moddiv_w(int lbits, WDataOutP owp, WDataInP lwp, WDataInP rwp, +extern WDataOutP _vl_moddiv_w(int lbits, WDataOutP owp, WDataInP const lwp, WDataInP const rwp, bool is_modulus); extern IData VL_FGETS_IXI(int obits, void* destp, IData fpi); @@ -991,7 +991,7 @@ extern void VL_FWRITEF(IData fpi, const char* formatp, ...); extern IData VL_FSCANF_IX(IData fpi, const char* formatp, ...); extern IData VL_SSCANF_IIX(int lbits, IData ld, const char* formatp, ...); extern IData VL_SSCANF_IQX(int lbits, QData ld, const char* formatp, ...); -extern IData VL_SSCANF_IWX(int lbits, WDataInP lwp, const char* formatp, ...); +extern IData VL_SSCANF_IWX(int lbits, WDataInP const lwp, const char* formatp, ...); extern void VL_SFORMAT_X(int obits, CData& destr, const char* formatp, ...); extern void VL_SFORMAT_X(int obits, SData& destr, const char* formatp, ...); @@ -999,7 +999,7 @@ extern void VL_SFORMAT_X(int obits, IData& destr, const char* formatp, ...); extern void VL_SFORMAT_X(int obits, QData& destr, const char* formatp, ...); extern void VL_SFORMAT_X(int obits, void* destp, const char* formatp, ...); -extern IData VL_SYSTEM_IW(int lhswords, WDataInP lhsp); +extern IData VL_SYSTEM_IW(int lhswords, WDataInP const lhsp); extern IData VL_SYSTEM_IQ(QData lhs); inline IData VL_SYSTEM_II(IData lhs) VL_MT_SAFE { return VL_SYSTEM_IQ(lhs); } @@ -1069,7 +1069,7 @@ static inline QData VL_CVT_Q_D(double lhs) VL_PURE { // clang-format on // Return double from lhs (numeric) unsigned -double VL_ITOR_D_W(int lbits, WDataInP lwp) VL_PURE; +double VL_ITOR_D_W(int lbits, WDataInP const lwp) VL_PURE; static inline double VL_ITOR_D_I(int, IData lhs) VL_PURE { return static_cast(static_cast(lhs)); } @@ -1077,7 +1077,7 @@ static inline double VL_ITOR_D_Q(int, QData lhs) VL_PURE { return static_cast(static_cast(lhs)); } // Return double from lhs (numeric) signed -double VL_ISTOR_D_W(int lbits, WDataInP lwp) VL_PURE; +double VL_ISTOR_D_W(int lbits, WDataInP const lwp) VL_PURE; static inline double VL_ISTOR_D_I(int lbits, IData lhs) VL_PURE { if (lbits == 32) return static_cast(static_cast(lhs)); WData lwp[VL_WQ_WORDS_E]; @@ -1114,7 +1114,7 @@ static inline QData VL_EXTENDSIGN_Q(int lbits, QData lhs) VL_PURE { } // Debugging prints -extern void _vl_debug_print_w(int lbits, WDataInP iwp); +extern void _vl_debug_print_w(int lbits, WDataInP const iwp); //========================================================================= // Pli macros @@ -1223,23 +1223,23 @@ vluint64_t vl_time_pow10(int n) VL_PURE; // EMIT_RULE: VL_ASSIGNCLEAN: oclean=clean; obits==lbits; #define VL_ASSIGNCLEAN_W(obits, owp, lwp) VL_CLEAN_WW((obits), (obits), (owp), (lwp)) static inline WDataOutP _vl_clean_inplace_w(int obits, WDataOutP owp) VL_MT_SAFE { - int words = VL_WORDS_I(obits); + const int words = VL_WORDS_I(obits); owp[words - 1] &= VL_MASK_E(obits); return owp; } -static inline WDataOutP VL_CLEAN_WW(int obits, int, WDataOutP owp, WDataInP lwp) VL_MT_SAFE { - int words = VL_WORDS_I(obits); +static inline WDataOutP VL_CLEAN_WW(int obits, int, WDataOutP owp, WDataInP const lwp) VL_MT_SAFE { + const int words = VL_WORDS_I(obits); for (int i = 0; (i < (words - 1)); ++i) owp[i] = lwp[i]; owp[words - 1] = lwp[words - 1] & VL_MASK_E(obits); return owp; } static inline WDataOutP VL_ZERO_W(int obits, WDataOutP owp) VL_MT_SAFE { - int words = VL_WORDS_I(obits); + const int words = VL_WORDS_I(obits); for (int i = 0; i < words; ++i) owp[i] = 0; return owp; } static inline WDataOutP VL_ALLONES_W(int obits, WDataOutP owp) VL_MT_SAFE { - int words = VL_WORDS_I(obits); + const int words = VL_WORDS_I(obits); for (int i = 0; i < (words - 1); ++i) owp[i] = ~VL_EUL(0); owp[words - 1] = VL_MASK_E(obits); return owp; @@ -1248,8 +1248,8 @@ static inline WDataOutP VL_ALLONES_W(int obits, WDataOutP owp) VL_MT_SAFE { // EMIT_RULE: VL_ASSIGN: oclean=rclean; obits==lbits; // For now, we always have a clean rhs. // Note: If a ASSIGN isn't clean, use VL_ASSIGNCLEAN instead to do the same thing. -static inline WDataOutP VL_ASSIGN_W(int obits, WDataOutP owp, WDataInP lwp) VL_MT_SAFE { - int words = VL_WORDS_I(obits); +static inline WDataOutP VL_ASSIGN_W(int obits, WDataOutP owp, WDataInP const lwp) VL_MT_SAFE { + const int words = VL_WORDS_I(obits); for (int i = 0; i < words; ++i) owp[i] = lwp[i]; return owp; } @@ -1286,7 +1286,7 @@ static inline void VL_ASSIGNBIT_QO(int, int bit, QData& lhsr, IData) VL_PURE { lhsr = (lhsr | (1ULL << VL_BITBIT_Q(bit))); } static inline void VL_ASSIGNBIT_WO(int, int bit, WDataOutP owp, IData) VL_MT_SAFE { - EData orig = owp[VL_BITWORD_E(bit)]; + const EData orig = owp[VL_BITWORD_E(bit)]; owp[VL_BITWORD_E(bit)] = (orig | (VL_EUL(1) << VL_BITBIT_E(bit))); } @@ -1310,7 +1310,7 @@ static inline void VL_ASSIGNBIT_WO(int, int bit, WDataOutP owp, IData) VL_MT_SAF } #define VL_ASSIGN_WSW(obits, owp, svar) \ { \ - int words = VL_WORDS_I(obits); \ + const int words = VL_WORDS_I(obits); \ for (int i = 0; i < words; ++i) (owp)[i] = (svar).read().get_word(i); \ (owp)[words - 1] &= VL_MASK_E(obits); \ } @@ -1321,7 +1321,7 @@ static inline void VL_ASSIGNBIT_WO(int, int bit, WDataOutP owp, IData) VL_MT_SAF { (vvar) = VL_CLEAN_QQ((obits), (obits), (svar).read().to_uint64()); } #define VL_ASSIGN_WSB(obits, owp, svar) \ { \ - int words = VL_WORDS_I(obits); \ + const int words = VL_WORDS_I(obits); \ sc_biguint<(obits)> _butemp = (svar).read(); \ for (int i = 0; i < words; ++i) { \ int msb = ((i + 1) * VL_IDATASIZE) - 1; \ @@ -1401,7 +1401,7 @@ static inline WDataOutP VL_EXTEND_WQ(int obits, int, WDataOutP owp, QData ld) VL return owp; } static inline WDataOutP VL_EXTEND_WW(int obits, int lbits, WDataOutP owp, - WDataInP lwp) VL_MT_SAFE { + WDataInP const lwp) VL_MT_SAFE { for (int i = 0; i < VL_WORDS_I(lbits); ++i) owp[i] = lwp[i]; for (int i = VL_WORDS_I(lbits); i < VL_WORDS_I(obits); ++i) owp[i] = 0; return owp; @@ -1420,23 +1420,23 @@ static inline QData VL_EXTENDS_QQ(int, int lbits, QData lhs) VL_PURE { } static inline WDataOutP VL_EXTENDS_WI(int obits, int lbits, WDataOutP owp, IData ld) VL_MT_SAFE { - EData sign = VL_SIGNONES_E(lbits, static_cast(ld)); + const EData sign = VL_SIGNONES_E(lbits, static_cast(ld)); owp[0] = ld | (sign & ~VL_MASK_E(lbits)); for (int i = 1; i < VL_WORDS_I(obits); ++i) owp[i] = sign; return owp; } static inline WDataOutP VL_EXTENDS_WQ(int obits, int lbits, WDataOutP owp, QData ld) VL_MT_SAFE { VL_SET_WQ(owp, ld); - EData sign = VL_SIGNONES_E(lbits, owp[1]); + const EData sign = VL_SIGNONES_E(lbits, owp[1]); owp[1] |= sign & ~VL_MASK_E(lbits); for (int i = VL_WQ_WORDS_E; i < VL_WORDS_I(obits); ++i) owp[i] = sign; return owp; } static inline WDataOutP VL_EXTENDS_WW(int obits, int lbits, WDataOutP owp, - WDataInP lwp) VL_MT_SAFE { + WDataInP const lwp) VL_MT_SAFE { for (int i = 0; i < VL_WORDS_I(lbits) - 1; ++i) owp[i] = lwp[i]; - int lmsw = VL_WORDS_I(lbits) - 1; - EData sign = VL_SIGNONES_E(lbits, lwp[lmsw]); + const int lmsw = VL_WORDS_I(lbits) - 1; + const EData sign = VL_SIGNONES_E(lbits, lwp[lmsw]); owp[lmsw] = lwp[lmsw] | (sign & ~VL_MASK_E(lbits)); for (int i = VL_WORDS_I(lbits); i < VL_WORDS_I(obits); ++i) owp[i] = sign; return owp; @@ -1448,8 +1448,8 @@ static inline WDataOutP VL_EXTENDS_WW(int obits, int lbits, WDataOutP owp, // EMIT_RULE: VL_REDAND: oclean=clean; lclean==clean; obits=1; #define VL_REDAND_II(obits, lbits, lhs) ((lhs) == VL_MASK_I(lbits)) #define VL_REDAND_IQ(obits, lbits, lhs) ((lhs) == VL_MASK_Q(lbits)) -static inline IData VL_REDAND_IW(int, int lbits, WDataInP lwp) VL_MT_SAFE { - int words = VL_WORDS_I(lbits); +static inline IData VL_REDAND_IW(int, int lbits, WDataInP const lwp) VL_MT_SAFE { + const int words = VL_WORDS_I(lbits); EData combine = lwp[0]; for (int i = 1; i < words - 1; ++i) combine &= lwp[i]; combine &= ~VL_MASK_E(lbits) | lwp[words - 1]; @@ -1459,7 +1459,7 @@ static inline IData VL_REDAND_IW(int, int lbits, WDataInP lwp) VL_MT_SAFE { // EMIT_RULE: VL_REDOR: oclean=clean; lclean==clean; obits=1; #define VL_REDOR_I(lhs) ((lhs) != 0) #define VL_REDOR_Q(lhs) ((lhs) != 0) -static inline IData VL_REDOR_W(int words, WDataInP lwp) VL_MT_SAFE { +static inline IData VL_REDOR_W(int words, WDataInP const lwp) VL_MT_SAFE { EData equal = 0; for (int i = 0; i < words; ++i) equal |= lwp[i]; return (equal != 0); @@ -1526,7 +1526,7 @@ static inline IData VL_REDXOR_64(QData r) VL_PURE { return static_cast(r); #endif } -static inline IData VL_REDXOR_W(int words, WDataInP lwp) VL_MT_SAFE { +static inline IData VL_REDXOR_W(int words, WDataInP const lwp) VL_MT_SAFE { EData r = lwp[0]; for (int i = 1; i < words; ++i) r ^= lwp[i]; return VL_REDXOR_32(r); @@ -1545,7 +1545,7 @@ static inline IData VL_COUNTONES_Q(QData lhs) VL_PURE { return VL_COUNTONES_I(static_cast(lhs)) + VL_COUNTONES_I(static_cast(lhs >> 32)); } #define VL_COUNTONES_E VL_COUNTONES_I -static inline IData VL_COUNTONES_W(int words, WDataInP lwp) VL_MT_SAFE { +static inline IData VL_COUNTONES_W(int words, WDataInP const lwp) VL_MT_SAFE { EData r = 0; for (int i = 0; i < words; ++i) r += VL_COUNTONES_E(lwp[i]); return r; @@ -1570,8 +1570,8 @@ static inline IData VL_COUNTBITS_Q(int lbits, QData lhs, IData ctrl0, IData ctrl + VL_COUNTBITS_I(lbits - 32, static_cast(lhs >> 32), ctrl0, ctrl1, ctrl2); } #define VL_COUNTBITS_E VL_COUNTBITS_I -static inline IData VL_COUNTBITS_W(int lbits, int words, WDataInP lwp, IData ctrl0, IData ctrl1, - IData ctrl2) VL_MT_SAFE { +static inline IData VL_COUNTBITS_W(int lbits, int words, WDataInP const lwp, IData ctrl0, + IData ctrl1, IData ctrl2) VL_MT_SAFE { EData r = 0; IData wordLbits = 32; for (int i = 0; i < words; ++i) { @@ -1587,7 +1587,7 @@ static inline IData VL_ONEHOT_I(IData lhs) VL_PURE { static inline IData VL_ONEHOT_Q(QData lhs) VL_PURE { return (((lhs & (lhs - 1)) == 0) & (lhs != 0)); } -static inline IData VL_ONEHOT_W(int words, WDataInP lwp) VL_MT_SAFE { +static inline IData VL_ONEHOT_W(int words, WDataInP const lwp) VL_MT_SAFE { EData one = 0; for (int i = 0; (i < words); ++i) { if (lwp[i]) { @@ -1601,7 +1601,7 @@ static inline IData VL_ONEHOT_W(int words, WDataInP lwp) VL_MT_SAFE { static inline IData VL_ONEHOT0_I(IData lhs) VL_PURE { return ((lhs & (lhs - 1)) == 0); } static inline IData VL_ONEHOT0_Q(QData lhs) VL_PURE { return ((lhs & (lhs - 1)) == 0); } -static inline IData VL_ONEHOT0_W(int words, WDataInP lwp) VL_MT_SAFE { +static inline IData VL_ONEHOT0_W(int words, WDataInP const lwp) VL_MT_SAFE { bool one = false; for (int i = 0; (i < words); ++i) { if (lwp[i]) { @@ -1628,7 +1628,7 @@ static inline IData VL_CLOG2_Q(QData lhs) VL_PURE { for (; lhs != 0; ++shifts) lhs = lhs >> 1ULL; return shifts; } -static inline IData VL_CLOG2_W(int words, WDataInP lwp) VL_MT_SAFE { +static inline IData VL_CLOG2_W(int words, WDataInP const lwp) VL_MT_SAFE { EData adjust = (VL_COUNTONES_W(words, lwp) == 1) ? 0 : 1; for (int i = words - 1; i >= 0; --i) { if (VL_UNLIKELY(lwp[i])) { // Shorter worst case if predict not taken @@ -1643,7 +1643,7 @@ static inline IData VL_CLOG2_W(int words, WDataInP lwp) VL_MT_SAFE { return 0; } -static inline IData VL_MOSTSETBITP1_W(int words, WDataInP lwp) VL_MT_SAFE { +static inline IData VL_MOSTSETBITP1_W(int words, WDataInP const lwp) VL_MT_SAFE { // MSB set bit plus one; similar to FLS. 0=value is zero for (int i = words - 1; i >= 0; --i) { if (VL_UNLIKELY(lwp[i])) { // Shorter worst case if predict not taken @@ -1660,28 +1660,31 @@ static inline IData VL_MOSTSETBITP1_W(int words, WDataInP lwp) VL_MT_SAFE { // SIMPLE LOGICAL OPERATORS // EMIT_RULE: VL_AND: oclean=lclean||rclean; obits=lbits; lbits==rbits; -static inline WDataOutP VL_AND_W(int words, WDataOutP owp, WDataInP lwp, WDataInP rwp) VL_MT_SAFE { +static inline WDataOutP VL_AND_W(int words, WDataOutP owp, WDataInP const lwp, + WDataInP const rwp) VL_MT_SAFE { for (int i = 0; (i < words); ++i) owp[i] = (lwp[i] & rwp[i]); return owp; } // EMIT_RULE: VL_OR: oclean=lclean&&rclean; obits=lbits; lbits==rbits; -static inline WDataOutP VL_OR_W(int words, WDataOutP owp, WDataInP lwp, WDataInP rwp) VL_MT_SAFE { +static inline WDataOutP VL_OR_W(int words, WDataOutP owp, WDataInP const lwp, + WDataInP const rwp) VL_MT_SAFE { for (int i = 0; (i < words); ++i) owp[i] = (lwp[i] | rwp[i]); return owp; } // EMIT_RULE: VL_CHANGEXOR: oclean=1; obits=32; lbits==rbits; -static inline IData VL_CHANGEXOR_W(int words, WDataInP lwp, WDataInP rwp) VL_MT_SAFE { +static inline IData VL_CHANGEXOR_W(int words, WDataInP const lwp, WDataInP const rwp) VL_MT_SAFE { IData od = 0; for (int i = 0; (i < words); ++i) od |= (lwp[i] ^ rwp[i]); return od; } // EMIT_RULE: VL_XOR: oclean=lclean&&rclean; obits=lbits; lbits==rbits; -static inline WDataOutP VL_XOR_W(int words, WDataOutP owp, WDataInP lwp, WDataInP rwp) VL_MT_SAFE { +static inline WDataOutP VL_XOR_W(int words, WDataOutP owp, WDataInP const lwp, + WDataInP const rwp) VL_MT_SAFE { for (int i = 0; (i < words); ++i) owp[i] = (lwp[i] ^ rwp[i]); return owp; } // EMIT_RULE: VL_NOT: oclean=dirty; obits=lbits; -static inline WDataOutP VL_NOT_W(int words, WDataOutP owp, WDataInP lwp) VL_MT_SAFE { +static inline WDataOutP VL_NOT_W(int words, WDataOutP owp, WDataInP const lwp) VL_MT_SAFE { for (int i = 0; i < words; ++i) owp[i] = ~(lwp[i]); return owp; } @@ -1702,14 +1705,14 @@ static inline WDataOutP VL_NOT_W(int words, WDataOutP owp, WDataInP lwp) VL_MT_S #define VL_GTE_W(words, lwp, rwp) (_vl_cmp_w(words, lwp, rwp) >= 0) // Output clean, AND MUST BE CLEAN -static inline IData VL_EQ_W(int words, WDataInP lwp, WDataInP rwp) VL_MT_SAFE { +static inline IData VL_EQ_W(int words, WDataInP const lwp, WDataInP const rwp) VL_MT_SAFE { EData nequal = 0; for (int i = 0; (i < words); ++i) nequal |= (lwp[i] ^ rwp[i]); return (nequal == 0); } // Internal usage -static inline int _vl_cmp_w(int words, WDataInP lwp, WDataInP rwp) VL_MT_SAFE { +static inline int _vl_cmp_w(int words, WDataInP const lwp, WDataInP const rwp) VL_MT_SAFE { for (int i = words - 1; i >= 0; --i) { if (lwp[i] > rwp[i]) return 1; if (lwp[i] < rwp[i]) return -1; @@ -1725,55 +1728,55 @@ static inline int _vl_cmp_w(int words, WDataInP lwp, WDataInP rwp) VL_MT_SAFE { static inline IData VL_GTS_III(int, int lbits, int, IData lhs, IData rhs) VL_PURE { // For lbits==32, this becomes just a single instruction, otherwise ~5. // GCC 3.3.4 sign extension bugs on AMD64 architecture force us to use quad logic - vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); // Q for gcc - vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); // Q for gcc + const vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); // Q for gcc + const vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); // Q for gcc return lhs_signed > rhs_signed; } static inline IData VL_GTS_IQQ(int, int lbits, int, QData lhs, QData rhs) VL_PURE { - vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); - vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); + const vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); + const vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); return lhs_signed > rhs_signed; } static inline IData VL_GTES_III(int, int lbits, int, IData lhs, IData rhs) VL_PURE { - vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); // Q for gcc - vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); // Q for gcc + const vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); // Q for gcc + const vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); // Q for gcc return lhs_signed >= rhs_signed; } static inline IData VL_GTES_IQQ(int, int lbits, int, QData lhs, QData rhs) VL_PURE { - vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); - vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); + const vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); + const vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); return lhs_signed >= rhs_signed; } static inline IData VL_LTS_III(int, int lbits, int, IData lhs, IData rhs) VL_PURE { - vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); // Q for gcc - vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); // Q for gcc + const vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); // Q for gcc + const vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); // Q for gcc return lhs_signed < rhs_signed; } static inline IData VL_LTS_IQQ(int, int lbits, int, QData lhs, QData rhs) VL_PURE { - vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); - vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); + const vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); + const vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); return lhs_signed < rhs_signed; } static inline IData VL_LTES_III(int, int lbits, int, IData lhs, IData rhs) VL_PURE { - vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); // Q for gcc - vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); // Q for gcc + const vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); // Q for gcc + const vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); // Q for gcc return lhs_signed <= rhs_signed; } static inline IData VL_LTES_IQQ(int, int lbits, int, QData lhs, QData rhs) VL_PURE { - vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); - vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); + const vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); + const vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); return lhs_signed <= rhs_signed; } -static inline int _vl_cmps_w(int lbits, WDataInP lwp, WDataInP rwp) VL_MT_SAFE { - int words = VL_WORDS_I(lbits); +static inline int _vl_cmps_w(int lbits, WDataInP const lwp, WDataInP const rwp) VL_MT_SAFE { + const int words = VL_WORDS_I(lbits); int i = words - 1; // We need to flip sense if negative comparison - EData lsign = VL_SIGN_E(lbits, lwp[i]); - EData rsign = VL_SIGN_E(lbits, rwp[i]); + const EData lsign = VL_SIGN_E(lbits, lwp[i]); + const EData rsign = VL_SIGN_E(lbits, rwp[i]); if (!lsign && rsign) return 1; // + > - if (lsign && !rsign) return -1; // - < + for (; i >= 0; --i) { @@ -1787,7 +1790,7 @@ static inline int _vl_cmps_w(int lbits, WDataInP lwp, WDataInP rwp) VL_MT_SAFE { // Math // Output NOT clean -static inline WDataOutP VL_NEGATE_W(int words, WDataOutP owp, WDataInP lwp) VL_MT_SAFE { +static inline WDataOutP VL_NEGATE_W(int words, WDataOutP owp, WDataInP const lwp) VL_MT_SAFE { EData carry = 1; for (int i = 0; i < words; ++i) { owp[i] = ~lwp[i] + carry; @@ -1814,7 +1817,8 @@ static inline void VL_NEGATE_INPLACE_W(int words, WDataOutP owp_lwp) VL_MT_SAFE #define VL_MODDIV_QQQ(lbits, lhs, rhs) (((rhs) == 0) ? 0 : (lhs) % (rhs)) #define VL_MODDIV_WWW(lbits, owp, lwp, rwp) (_vl_moddiv_w(lbits, owp, lwp, rwp, 1)) -static inline WDataOutP VL_ADD_W(int words, WDataOutP owp, WDataInP lwp, WDataInP rwp) VL_MT_SAFE { +static inline WDataOutP VL_ADD_W(int words, WDataOutP owp, WDataInP const lwp, + WDataInP const rwp) VL_MT_SAFE { QData carry = 0; for (int i = 0; i < words; ++i) { carry = carry + static_cast(lwp[i]) + static_cast(rwp[i]); @@ -1825,7 +1829,8 @@ static inline WDataOutP VL_ADD_W(int words, WDataOutP owp, WDataInP lwp, WDataIn return owp; } -static inline WDataOutP VL_SUB_W(int words, WDataOutP owp, WDataInP lwp, WDataInP rwp) VL_MT_SAFE { +static inline WDataOutP VL_SUB_W(int words, WDataOutP owp, WDataInP const lwp, + WDataInP const rwp) VL_MT_SAFE { QData carry = 0; for (int i = 0; i < words; ++i) { carry = (carry + static_cast(lwp[i]) @@ -1838,7 +1843,8 @@ static inline WDataOutP VL_SUB_W(int words, WDataOutP owp, WDataInP lwp, WDataIn return owp; } -static inline WDataOutP VL_MUL_W(int words, WDataOutP owp, WDataInP lwp, WDataInP rwp) VL_MT_SAFE { +static inline WDataOutP VL_MUL_W(int words, WDataOutP owp, WDataInP const lwp, + WDataInP const rwp) VL_MT_SAFE { for (int i = 0; i < words; ++i) owp[i] = 0; for (int lword = 0; lword < words; ++lword) { for (int rword = 0; rword < words; ++rword) { @@ -1855,19 +1861,19 @@ static inline WDataOutP VL_MUL_W(int words, WDataOutP owp, WDataInP lwp, WDataIn } static inline IData VL_MULS_III(int, int lbits, int, IData lhs, IData rhs) VL_PURE { - vlsint32_t lhs_signed = VL_EXTENDS_II(32, lbits, lhs); - vlsint32_t rhs_signed = VL_EXTENDS_II(32, lbits, rhs); + const vlsint32_t lhs_signed = VL_EXTENDS_II(32, lbits, lhs); + const vlsint32_t rhs_signed = VL_EXTENDS_II(32, lbits, rhs); return lhs_signed * rhs_signed; } static inline QData VL_MULS_QQQ(int, int lbits, int, QData lhs, QData rhs) VL_PURE { - vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); - vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); + const vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); + const vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); return lhs_signed * rhs_signed; } -static inline WDataOutP VL_MULS_WWW(int, int lbits, int, WDataOutP owp, WDataInP lwp, - WDataInP rwp) VL_MT_SAFE { - int words = VL_WORDS_I(lbits); +static inline WDataOutP VL_MULS_WWW(int, int lbits, int, WDataOutP owp, WDataInP const lwp, + WDataInP const rwp) VL_MT_SAFE { + const int words = VL_WORDS_I(lbits); // cppcheck-suppress variableScope WData lwstore[VL_MULS_MAX_WORDS]; // Fixed size, as MSVC++ doesn't allow [words] here // cppcheck-suppress variableScope @@ -1907,38 +1913,38 @@ static inline IData VL_DIVS_III(int lbits, IData lhs, IData rhs) VL_PURE { if (VL_UNLIKELY(rhs == 0)) return 0; // -MAX / -1 cannot be represented in twos complement, and will cause SIGFPE if (VL_UNLIKELY(lhs == 0x80000000 && rhs == 0xffffffff)) return 0; - vlsint32_t lhs_signed = VL_EXTENDS_II(VL_IDATASIZE, lbits, lhs); - vlsint32_t rhs_signed = VL_EXTENDS_II(VL_IDATASIZE, lbits, rhs); + const vlsint32_t lhs_signed = VL_EXTENDS_II(VL_IDATASIZE, lbits, lhs); + const vlsint32_t rhs_signed = VL_EXTENDS_II(VL_IDATASIZE, lbits, rhs); return lhs_signed / rhs_signed; } static inline QData VL_DIVS_QQQ(int lbits, QData lhs, QData rhs) VL_PURE { if (VL_UNLIKELY(rhs == 0)) return 0; // -MAX / -1 cannot be represented in twos complement, and will cause SIGFPE if (VL_UNLIKELY(lhs == 0x8000000000000000ULL && rhs == 0xffffffffffffffffULL)) return 0; - vlsint64_t lhs_signed = VL_EXTENDS_QQ(VL_QUADSIZE, lbits, lhs); - vlsint64_t rhs_signed = VL_EXTENDS_QQ(VL_QUADSIZE, lbits, rhs); + const vlsint64_t lhs_signed = VL_EXTENDS_QQ(VL_QUADSIZE, lbits, lhs); + const vlsint64_t rhs_signed = VL_EXTENDS_QQ(VL_QUADSIZE, lbits, rhs); return lhs_signed / rhs_signed; } static inline IData VL_MODDIVS_III(int lbits, IData lhs, IData rhs) VL_PURE { if (VL_UNLIKELY(rhs == 0)) return 0; if (VL_UNLIKELY(lhs == 0x80000000 && rhs == 0xffffffff)) return 0; - vlsint32_t lhs_signed = VL_EXTENDS_II(VL_IDATASIZE, lbits, lhs); - vlsint32_t rhs_signed = VL_EXTENDS_II(VL_IDATASIZE, lbits, rhs); + const vlsint32_t lhs_signed = VL_EXTENDS_II(VL_IDATASIZE, lbits, lhs); + const vlsint32_t rhs_signed = VL_EXTENDS_II(VL_IDATASIZE, lbits, rhs); return lhs_signed % rhs_signed; } static inline QData VL_MODDIVS_QQQ(int lbits, QData lhs, QData rhs) VL_PURE { if (VL_UNLIKELY(rhs == 0)) return 0; if (VL_UNLIKELY(lhs == 0x8000000000000000ULL && rhs == 0xffffffffffffffffULL)) return 0; - vlsint64_t lhs_signed = VL_EXTENDS_QQ(VL_QUADSIZE, lbits, lhs); - vlsint64_t rhs_signed = VL_EXTENDS_QQ(VL_QUADSIZE, lbits, rhs); + const vlsint64_t lhs_signed = VL_EXTENDS_QQ(VL_QUADSIZE, lbits, lhs); + const vlsint64_t rhs_signed = VL_EXTENDS_QQ(VL_QUADSIZE, lbits, rhs); return lhs_signed % rhs_signed; } -static inline WDataOutP VL_DIVS_WWW(int lbits, WDataOutP owp, WDataInP lwp, - WDataInP rwp) VL_MT_SAFE { - int words = VL_WORDS_I(lbits); - EData lsign = VL_SIGN_E(lbits, lwp[words - 1]); - EData rsign = VL_SIGN_E(lbits, rwp[words - 1]); +static inline WDataOutP VL_DIVS_WWW(int lbits, WDataOutP owp, WDataInP const lwp, + WDataInP const rwp) VL_MT_SAFE { + const int words = VL_WORDS_I(lbits); + const EData lsign = VL_SIGN_E(lbits, lwp[words - 1]); + const EData rsign = VL_SIGN_E(lbits, rwp[words - 1]); // cppcheck-suppress variableScope WData lwstore[VL_MULS_MAX_WORDS]; // Fixed size, as MSVC++ doesn't allow [words] here // cppcheck-suppress variableScope @@ -1956,11 +1962,11 @@ static inline WDataOutP VL_DIVS_WWW(int lbits, WDataOutP owp, WDataInP lwp, return VL_DIV_WWW(lbits, owp, ltup, rtup); } } -static inline WDataOutP VL_MODDIVS_WWW(int lbits, WDataOutP owp, WDataInP lwp, - WDataInP rwp) VL_MT_SAFE { - int words = VL_WORDS_I(lbits); - EData lsign = VL_SIGN_E(lbits, lwp[words - 1]); - EData rsign = VL_SIGN_E(lbits, rwp[words - 1]); +static inline WDataOutP VL_MODDIVS_WWW(int lbits, WDataOutP owp, WDataInP const lwp, + WDataInP const rwp) VL_MT_SAFE { + const int words = VL_WORDS_I(lbits); + const EData lsign = VL_SIGN_E(lbits, lwp[words - 1]); + const EData rsign = VL_SIGN_E(lbits, rwp[words - 1]); // cppcheck-suppress variableScope WData lwstore[VL_MULS_MAX_WORDS]; // Fixed size, as MSVC++ doesn't allow [words] here // cppcheck-suppress variableScope @@ -2007,9 +2013,10 @@ static inline QData VL_POW_QQQ(int, int, int rbits, QData lhs, QData rhs) VL_PUR } return out; } -WDataOutP VL_POW_WWW(int obits, int, int rbits, WDataOutP owp, WDataInP lwp, WDataInP rwp); -WDataOutP VL_POW_WWQ(int obits, int, int rbits, WDataOutP owp, WDataInP lwp, QData rhs); -QData VL_POW_QQW(int obits, int, int rbits, QData lhs, WDataInP rwp); +WDataOutP VL_POW_WWW(int obits, int, int rbits, WDataOutP owp, WDataInP const lwp, + WDataInP const rwp); +WDataOutP VL_POW_WWQ(int obits, int, int rbits, WDataOutP owp, WDataInP const lwp, QData rhs); +QData VL_POW_QQW(int obits, int, int rbits, QData lhs, WDataInP const rwp); #define VL_POWSS_IIQ(obits, lbits, rbits, lhs, rhs, lsign, rsign) \ VL_POWSS_QQQ(obits, lbits, rbits, lhs, rhs, lsign, rsign) @@ -2060,11 +2067,12 @@ static inline QData VL_POWSS_QQQ(int obits, int, int rbits, QData lhs, QData rhs } return VL_POW_QQQ(obits, rbits, rbits, lhs, rhs); } -WDataOutP VL_POWSS_WWW(int obits, int, int rbits, WDataOutP owp, WDataInP lwp, WDataInP rwp, +WDataOutP VL_POWSS_WWW(int obits, int, int rbits, WDataOutP owp, WDataInP const lwp, + WDataInP const rwp, bool lsign, bool rsign); +WDataOutP VL_POWSS_WWQ(int obits, int, int rbits, WDataOutP owp, WDataInP const lwp, QData rhs, bool lsign, bool rsign); -WDataOutP VL_POWSS_WWQ(int obits, int, int rbits, WDataOutP owp, WDataInP lwp, QData rhs, - bool lsign, bool rsign); -QData VL_POWSS_QQW(int obits, int, int rbits, QData lhs, WDataInP rwp, bool lsign, bool rsign); +QData VL_POWSS_QQW(int obits, int, int rbits, QData lhs, WDataInP const rwp, bool lsign, + bool rsign); //=================================================================== // Concat/replication @@ -2073,52 +2081,52 @@ QData VL_POWSS_QQW(int obits, int, int rbits, QData lhs, WDataInP rwp, bool lsig // ld may be "dirty", output is clean static inline void _vl_insert_II(int, CData& lhsr, IData ld, int hbit, int lbit, int rbits) VL_PURE { - IData cleanmask = VL_MASK_I(rbits); - IData insmask = (VL_MASK_I(hbit - lbit + 1)) << lbit; + const IData cleanmask = VL_MASK_I(rbits); + const IData insmask = (VL_MASK_I(hbit - lbit + 1)) << lbit; lhsr = (lhsr & ~insmask) | ((ld << lbit) & (insmask & cleanmask)); } static inline void _vl_insert_II(int, SData& lhsr, IData ld, int hbit, int lbit, int rbits) VL_PURE { - IData cleanmask = VL_MASK_I(rbits); - IData insmask = (VL_MASK_I(hbit - lbit + 1)) << lbit; + const IData cleanmask = VL_MASK_I(rbits); + const IData insmask = (VL_MASK_I(hbit - lbit + 1)) << lbit; lhsr = (lhsr & ~insmask) | ((ld << lbit) & (insmask & cleanmask)); } static inline void _vl_insert_II(int, IData& lhsr, IData ld, int hbit, int lbit, int rbits) VL_PURE { - IData cleanmask = VL_MASK_I(rbits); - IData insmask = (VL_MASK_I(hbit - lbit + 1)) << lbit; + const IData cleanmask = VL_MASK_I(rbits); + const IData insmask = (VL_MASK_I(hbit - lbit + 1)) << lbit; lhsr = (lhsr & ~insmask) | ((ld << lbit) & (insmask & cleanmask)); } static inline void _vl_insert_QQ(int, QData& lhsr, QData ld, int hbit, int lbit, int rbits) VL_PURE { - QData cleanmask = VL_MASK_Q(rbits); - QData insmask = (VL_MASK_Q(hbit - lbit + 1)) << lbit; + const QData cleanmask = VL_MASK_Q(rbits); + const QData insmask = (VL_MASK_Q(hbit - lbit + 1)) << lbit; lhsr = (lhsr & ~insmask) | ((ld << lbit) & (insmask & cleanmask)); } static inline void _vl_insert_WI(int, WDataOutP owp, IData ld, int hbit, int lbit, int rbits = 0) VL_MT_SAFE { - int hoffset = VL_BITBIT_E(hbit); - int loffset = VL_BITBIT_E(lbit); - int roffset = VL_BITBIT_E(rbits); - int hword = VL_BITWORD_E(hbit); - int lword = VL_BITWORD_E(lbit); - int rword = VL_BITWORD_E(rbits); - EData cleanmask = hword == rword ? VL_MASK_E(roffset) : VL_MASK_E(0); + const int hoffset = VL_BITBIT_E(hbit); + const int loffset = VL_BITBIT_E(lbit); + const int roffset = VL_BITBIT_E(rbits); + const int hword = VL_BITWORD_E(hbit); + const int lword = VL_BITWORD_E(lbit); + const int rword = VL_BITWORD_E(rbits); + const EData cleanmask = hword == rword ? VL_MASK_E(roffset) : VL_MASK_E(0); if (hoffset == VL_SIZEBITS_E && loffset == 0) { // Fast and common case, word based insertion owp[VL_BITWORD_E(lbit)] = ld & cleanmask; } else { - EData lde = static_cast(ld); + const EData lde = static_cast(ld); if (hword == lword) { // know < EData bits because above checks it // Assignment is contained within one word of destination - EData insmask = (VL_MASK_E(hoffset - loffset + 1)) << loffset; + const EData insmask = (VL_MASK_E(hoffset - loffset + 1)) << loffset; owp[lword] = (owp[lword] & ~insmask) | ((lde << loffset) & (insmask & cleanmask)); } else { // Assignment crosses a word boundary in destination - EData hinsmask = (VL_MASK_E(hoffset - 0 + 1)) << 0; - EData linsmask = (VL_MASK_E((VL_EDATASIZE - 1) - loffset + 1)) << loffset; - int nbitsonright = VL_EDATASIZE - loffset; // bits that end up in lword + const EData hinsmask = (VL_MASK_E(hoffset - 0 + 1)) << 0; + const EData linsmask = (VL_MASK_E((VL_EDATASIZE - 1) - loffset + 1)) << loffset; + const int nbitsonright = VL_EDATASIZE - loffset; // bits that end up in lword owp[lword] = (owp[lword] & ~linsmask) | ((lde << loffset) & linsmask); owp[hword] = (owp[hword] & ~hinsmask) | ((lde >> nbitsonright) & (hinsmask & cleanmask)); @@ -2128,18 +2136,18 @@ static inline void _vl_insert_WI(int, WDataOutP owp, IData ld, int hbit, int lbi // INTERNAL: Stuff large LHS bit 0++ into OUTPUT at specified offset // lwp may be "dirty" -static inline void _vl_insert_WW(int, WDataOutP owp, WDataInP lwp, int hbit, int lbit, +static inline void _vl_insert_WW(int, WDataOutP owp, WDataInP const lwp, int hbit, int lbit, int rbits = 0) VL_MT_SAFE { - int hoffset = VL_BITBIT_E(hbit); - int loffset = VL_BITBIT_E(lbit); - int roffset = VL_BITBIT_E(rbits); - int lword = VL_BITWORD_E(lbit); - int hword = VL_BITWORD_E(hbit); - int rword = VL_BITWORD_E(rbits); - int words = VL_WORDS_I(hbit - lbit + 1); + const int hoffset = VL_BITBIT_E(hbit); + const int loffset = VL_BITBIT_E(lbit); + const int roffset = VL_BITBIT_E(rbits); + const int lword = VL_BITWORD_E(lbit); + const int hword = VL_BITWORD_E(hbit); + const int rword = VL_BITWORD_E(rbits); + const int words = VL_WORDS_I(hbit - lbit + 1); // Cleaning mask, only applied to top word of the assignment. Is a no-op // if we don't assign to the top word of the destination. - EData cleanmask = hword == rword ? VL_MASK_E(roffset) : VL_MASK_E(0); + const EData cleanmask = hword == rword ? VL_MASK_E(roffset) : VL_MASK_E(0); if (hoffset == VL_SIZEBITS_E && loffset == 0) { // Fast and common case, word based insertion @@ -2149,18 +2157,19 @@ static inline void _vl_insert_WW(int, WDataOutP owp, WDataInP lwp, int hbit, int // Non-32bit, but nicely aligned, so stuff all but the last word for (int i = 0; i < (words - 1); ++i) owp[lword + i] = lwp[i]; // Know it's not a full word as above fast case handled it - EData hinsmask = (VL_MASK_E(hoffset - 0 + 1)); + const EData hinsmask = (VL_MASK_E(hoffset - 0 + 1)); owp[hword] = (owp[hword] & ~hinsmask) | (lwp[words - 1] & (hinsmask & cleanmask)); } else { - EData hinsmask = (VL_MASK_E(hoffset - 0 + 1)) << 0; - EData linsmask = (VL_MASK_E((VL_EDATASIZE - 1) - loffset + 1)) << loffset; - int nbitsonright = VL_EDATASIZE - loffset; // bits that end up in lword (know loffset!=0) + const EData hinsmask = (VL_MASK_E(hoffset - 0 + 1)) << 0; + const EData linsmask = (VL_MASK_E((VL_EDATASIZE - 1) - loffset + 1)) << loffset; + const int nbitsonright + = VL_EDATASIZE - loffset; // bits that end up in lword (know loffset!=0) // Middle words for (int i = 0; i < words; ++i) { { // Lower word - int oword = lword + i; - EData d = lwp[i] << loffset; - EData od = (owp[oword] & ~linsmask) | (d & linsmask); + const int oword = lword + i; + const EData d = lwp[i] << loffset; + const EData od = (owp[oword] & ~linsmask) | (d & linsmask); if (oword == hword) { owp[oword] = (owp[oword] & ~hinsmask) | (od & (hinsmask & cleanmask)); } else { @@ -2168,10 +2177,10 @@ static inline void _vl_insert_WW(int, WDataOutP owp, WDataInP lwp, int hbit, int } } { // Upper word - int oword = lword + i + 1; + const int oword = lword + i + 1; if (oword <= hword) { - EData d = lwp[i] >> nbitsonright; - EData od = (d & ~linsmask) | (owp[oword] & linsmask); + const EData d = lwp[i] >> nbitsonright; + const EData od = (d & ~linsmask) | (owp[oword] & linsmask); if (oword == hword) { owp[oword] = (owp[oword] & ~hinsmask) | (od & (hinsmask & cleanmask)); } else { @@ -2227,8 +2236,8 @@ static inline WDataOutP VL_REPLICATE_WQI(int obits, int lbits, int, WDataOutP ow } return owp; } -static inline WDataOutP VL_REPLICATE_WWI(int obits, int lbits, int, WDataOutP owp, WDataInP lwp, - IData rep) VL_MT_SAFE { +static inline WDataOutP VL_REPLICATE_WWI(int obits, int lbits, int, WDataOutP owp, + WDataInP const lwp, IData rep) VL_MT_SAFE { for (int i = 0; i < VL_WORDS_I(lbits); ++i) owp[i] = lwp[i]; for (unsigned i = 1; i < rep; ++i) { _vl_insert_WW(obits, owp, lwp, i * lbits + lbits - 1, i * lbits); @@ -2262,9 +2271,9 @@ static inline IData VL_STREAML_FAST_III(int, int lbits, int, IData ld, IData rd_ // ret = 10324--- IData ret = ld; if (rd_log2) { - vluint32_t lbitsFloor = lbits & ~VL_MASK_I(rd_log2); // max multiple of rd <= lbits - vluint32_t lbitsRem = lbits - lbitsFloor; // number of bits in most-sig slice (MSS) - IData msbMask = VL_MASK_I(lbitsRem) << lbitsFloor; // mask to sel only bits in MSS + const vluint32_t lbitsFloor = lbits & ~VL_MASK_I(rd_log2); // max multiple of rd <= lbits + const vluint32_t lbitsRem = lbits - lbitsFloor; // number of bits in most-sig slice (MSS) + const IData msbMask = VL_MASK_I(lbitsRem) << lbitsFloor; // mask to sel only bits in MSS ret = (ret & ~msbMask) | ((ret & msbMask) << ((VL_UL(1) << rd_log2) - lbitsRem)); } switch (rd_log2) { @@ -2282,9 +2291,9 @@ static inline QData VL_STREAML_FAST_QQI(int, int lbits, int, QData ld, IData rd_ // Pre-shift bits in most-significant slice (see comment in VL_STREAML_FAST_III) QData ret = ld; if (rd_log2) { - vluint32_t lbitsFloor = lbits & ~VL_MASK_I(rd_log2); - vluint32_t lbitsRem = lbits - lbitsFloor; - QData msbMask = VL_MASK_Q(lbitsRem) << lbitsFloor; + const vluint32_t lbitsFloor = lbits & ~VL_MASK_I(rd_log2); + const vluint32_t lbitsRem = lbits - lbitsFloor; + const QData msbMask = VL_MASK_Q(lbitsRem) << lbitsFloor; ret = (ret & ~msbMask) | ((ret & msbMask) << ((1ULL << rd_log2) - lbitsRem)); } switch (rd_log2) { @@ -2313,7 +2322,7 @@ static inline QData VL_STREAML_FAST_QQI(int, int lbits, int, QData ld, IData rd_ static inline IData VL_STREAML_III(int, int lbits, int, IData ld, IData rd) VL_PURE { IData ret = 0; // Slice size should never exceed the lhs width - IData mask = VL_MASK_I(rd); + const IData mask = VL_MASK_I(rd); for (int istart = 0; istart < lbits; istart += rd) { int ostart = lbits - rd - istart; ostart = ostart > 0 ? ostart : 0; @@ -2325,7 +2334,7 @@ static inline IData VL_STREAML_III(int, int lbits, int, IData ld, IData rd) VL_P static inline QData VL_STREAML_QQI(int, int lbits, int, QData ld, IData rd) VL_PURE { QData ret = 0; // Slice size should never exceed the lhs width - QData mask = VL_MASK_Q(rd); + const QData mask = VL_MASK_Q(rd); for (int istart = 0; istart < lbits; istart += rd) { int ostart = lbits - rd - istart; ostart = ostart > 0 ? ostart : 0; @@ -2334,11 +2343,11 @@ static inline QData VL_STREAML_QQI(int, int lbits, int, QData ld, IData rd) VL_P return ret; } -static inline WDataOutP VL_STREAML_WWI(int, int lbits, int, WDataOutP owp, WDataInP lwp, +static inline WDataOutP VL_STREAML_WWI(int, int lbits, int, WDataOutP owp, WDataInP const lwp, IData rd) VL_MT_SAFE { VL_ZERO_W(lbits, owp); // Slice size should never exceed the lhs width - int ssize = (rd < static_cast(lbits)) ? rd : (static_cast(lbits)); + const int ssize = (rd < static_cast(lbits)) ? rd : (static_cast(lbits)); for (int istart = 0; istart < lbits; istart += rd) { int ostart = lbits - rd - istart; ostart = ostart > 0 ? ostart : 0; @@ -2374,15 +2383,15 @@ static inline WDataOutP VL_CONCAT_WII(int obits, int lbits, int rbits, WDataOutP _vl_insert_WI(obits, owp, ld, rbits + lbits - 1, rbits); return owp; } -static inline WDataOutP VL_CONCAT_WWI(int obits, int lbits, int rbits, WDataOutP owp, WDataInP lwp, - IData rd) VL_MT_SAFE { +static inline WDataOutP VL_CONCAT_WWI(int obits, int lbits, int rbits, WDataOutP owp, + WDataInP const lwp, IData rd) VL_MT_SAFE { owp[0] = rd; for (int i = 1; i < VL_WORDS_I(obits); ++i) owp[i] = 0; _vl_insert_WW(obits, owp, lwp, rbits + lbits - 1, rbits); return owp; } static inline WDataOutP VL_CONCAT_WIW(int obits, int lbits, int rbits, WDataOutP owp, IData ld, - WDataInP rwp) VL_MT_SAFE { + WDataInP const rwp) VL_MT_SAFE { for (int i = 0; i < VL_WORDS_I(rbits); ++i) owp[i] = rwp[i]; for (int i = VL_WORDS_I(rbits); i < VL_WORDS_I(obits); ++i) owp[i] = 0; _vl_insert_WI(obits, owp, ld, rbits + lbits - 1, rbits); @@ -2409,22 +2418,22 @@ static inline WDataOutP VL_CONCAT_WQQ(int obits, int lbits, int rbits, WDataOutP _vl_insert_WQ(obits, owp, ld, rbits + lbits - 1, rbits); return owp; } -static inline WDataOutP VL_CONCAT_WWQ(int obits, int lbits, int rbits, WDataOutP owp, WDataInP lwp, - QData rd) VL_MT_SAFE { +static inline WDataOutP VL_CONCAT_WWQ(int obits, int lbits, int rbits, WDataOutP owp, + WDataInP const lwp, QData rd) VL_MT_SAFE { VL_SET_WQ(owp, rd); for (int i = VL_WQ_WORDS_E; i < VL_WORDS_I(obits); ++i) owp[i] = 0; _vl_insert_WW(obits, owp, lwp, rbits + lbits - 1, rbits); return owp; } static inline WDataOutP VL_CONCAT_WQW(int obits, int lbits, int rbits, WDataOutP owp, QData ld, - WDataInP rwp) VL_MT_SAFE { + WDataInP const rwp) VL_MT_SAFE { for (int i = 0; i < VL_WORDS_I(rbits); ++i) owp[i] = rwp[i]; for (int i = VL_WORDS_I(rbits); i < VL_WORDS_I(obits); ++i) owp[i] = 0; _vl_insert_WQ(obits, owp, ld, rbits + lbits - 1, rbits); return owp; } -static inline WDataOutP VL_CONCAT_WWW(int obits, int lbits, int rbits, WDataOutP owp, WDataInP lwp, - WDataInP rwp) VL_MT_SAFE { +static inline WDataOutP VL_CONCAT_WWW(int obits, int lbits, int rbits, WDataOutP owp, + WDataInP const lwp, WDataInP const rwp) VL_MT_SAFE { for (int i = 0; i < VL_WORDS_I(rbits); ++i) owp[i] = rwp[i]; for (int i = VL_WORDS_I(rbits); i < VL_WORDS_I(obits); ++i) owp[i] = 0; _vl_insert_WW(obits, owp, lwp, rbits + lbits - 1, rbits); @@ -2438,8 +2447,8 @@ static inline WDataOutP VL_CONCAT_WWW(int obits, int lbits, int rbits, WDataOutP // The output is the same as the input - it overlaps! static inline void _vl_shiftl_inplace_w(int obits, WDataOutP iowp, IData rd /*1 or 4*/) VL_MT_SAFE { - int words = VL_WORDS_I(obits); - EData linsmask = VL_MASK_E(rd); + const int words = VL_WORDS_I(obits); + const EData linsmask = VL_MASK_E(rd); for (int i = words - 1; i >= 1; --i) { iowp[i] = ((iowp[i] << rd) & ~linsmask) | ((iowp[i - 1] >> (VL_EDATASIZE - rd)) & linsmask); @@ -2451,10 +2460,10 @@ static inline void _vl_shiftl_inplace_w(int obits, WDataOutP iowp, // EMIT_RULE: VL_SHIFTL: oclean=lclean; rclean==clean; // Important: Unlike most other funcs, the shift might well be a computed // expression. Thus consider this when optimizing. (And perhaps have 2 funcs?) -static inline WDataOutP VL_SHIFTL_WWI(int obits, int, int, WDataOutP owp, WDataInP lwp, +static inline WDataOutP VL_SHIFTL_WWI(int obits, int, int, WDataOutP owp, WDataInP const lwp, IData rd) VL_MT_SAFE { - int word_shift = VL_BITWORD_E(rd); - int bit_shift = VL_BITBIT_E(rd); + const int word_shift = VL_BITWORD_E(rd); + const int bit_shift = VL_BITBIT_E(rd); if (rd >= static_cast(obits)) { // rd may be huge with MSB set for (int i = 0; i < VL_WORDS_I(obits); ++i) owp[i] = 0; } else if (bit_shift == 0) { // Aligned word shift (<<0,<<32,<<64 etc) @@ -2466,8 +2475,8 @@ static inline WDataOutP VL_SHIFTL_WWI(int obits, int, int, WDataOutP owp, WDataI } return owp; } -static inline WDataOutP VL_SHIFTL_WWW(int obits, int lbits, int rbits, WDataOutP owp, WDataInP lwp, - WDataInP rwp) VL_MT_SAFE { +static inline WDataOutP VL_SHIFTL_WWW(int obits, int lbits, int rbits, WDataOutP owp, + WDataInP const lwp, WDataInP const rwp) VL_MT_SAFE { for (int i = 1; i < VL_WORDS_I(rbits); ++i) { if (VL_UNLIKELY(rwp[i])) { // Huge shift 1>>32 or more return VL_ZERO_W(obits, owp); @@ -2475,13 +2484,14 @@ static inline WDataOutP VL_SHIFTL_WWW(int obits, int lbits, int rbits, WDataOutP } return VL_SHIFTL_WWI(obits, lbits, 32, owp, lwp, rwp[0]); } -static inline WDataOutP VL_SHIFTL_WWQ(int obits, int lbits, int rbits, WDataOutP owp, WDataInP lwp, - QData rd) VL_MT_SAFE { +static inline WDataOutP VL_SHIFTL_WWQ(int obits, int lbits, int rbits, WDataOutP owp, + WDataInP const lwp, QData rd) VL_MT_SAFE { WData rwp[VL_WQ_WORDS_E]; VL_SET_WQ(rwp, rd); return VL_SHIFTL_WWW(obits, lbits, rbits, owp, lwp, rwp); } -static inline IData VL_SHIFTL_IIW(int obits, int, int rbits, IData lhs, WDataInP rwp) VL_MT_SAFE { +static inline IData VL_SHIFTL_IIW(int obits, int, int rbits, IData lhs, + WDataInP const rwp) VL_MT_SAFE { for (int i = 1; i < VL_WORDS_I(rbits); ++i) { if (VL_UNLIKELY(rwp[i])) { // Huge shift 1>>32 or more return 0; @@ -2493,7 +2503,8 @@ static inline IData VL_SHIFTL_IIQ(int obits, int, int, IData lhs, QData rhs) VL_ if (VL_UNLIKELY(rhs >= VL_IDATASIZE)) return 0; return VL_CLEAN_II(obits, obits, lhs << rhs); } -static inline QData VL_SHIFTL_QQW(int obits, int, int rbits, QData lhs, WDataInP rwp) VL_MT_SAFE { +static inline QData VL_SHIFTL_QQW(int obits, int, int rbits, QData lhs, + WDataInP const rwp) VL_MT_SAFE { for (int i = 1; i < VL_WORDS_I(rbits); ++i) { if (VL_UNLIKELY(rwp[i])) { // Huge shift 1>>32 or more return 0; @@ -2510,32 +2521,32 @@ static inline QData VL_SHIFTL_QQQ(int obits, int, int, QData lhs, QData rhs) VL_ // EMIT_RULE: VL_SHIFTR: oclean=lclean; rclean==clean; // Important: Unlike most other funcs, the shift might well be a computed // expression. Thus consider this when optimizing. (And perhaps have 2 funcs?) -static inline WDataOutP VL_SHIFTR_WWI(int obits, int, int, WDataOutP owp, WDataInP lwp, +static inline WDataOutP VL_SHIFTR_WWI(int obits, int, int, WDataOutP owp, WDataInP const lwp, IData rd) VL_MT_SAFE { - int word_shift = VL_BITWORD_E(rd); // Maybe 0 - int bit_shift = VL_BITBIT_E(rd); + const int word_shift = VL_BITWORD_E(rd); // Maybe 0 + const int bit_shift = VL_BITBIT_E(rd); if (rd >= static_cast(obits)) { // rd may be huge with MSB set for (int i = 0; i < VL_WORDS_I(obits); ++i) owp[i] = 0; } else if (bit_shift == 0) { // Aligned word shift (>>0,>>32,>>64 etc) - int copy_words = (VL_WORDS_I(obits) - word_shift); + const int copy_words = (VL_WORDS_I(obits) - word_shift); for (int i = 0; i < copy_words; ++i) owp[i] = lwp[i + word_shift]; for (int i = copy_words; i < VL_WORDS_I(obits); ++i) owp[i] = 0; } else { - int loffset = rd & VL_SIZEBITS_E; - int nbitsonright = VL_EDATASIZE - loffset; // bits that end up in lword (know loffset!=0) - // Middle words - int words = VL_WORDS_I(obits - rd); + const int loffset = rd & VL_SIZEBITS_E; + const int nbitsonright = VL_EDATASIZE - loffset; // bits that end up in lword (know + // loffset!=0) Middle words + const int words = VL_WORDS_I(obits - rd); for (int i = 0; i < words; ++i) { owp[i] = lwp[i + word_shift] >> loffset; - int upperword = i + word_shift + 1; + const int upperword = i + word_shift + 1; if (upperword < VL_WORDS_I(obits)) owp[i] |= lwp[upperword] << nbitsonright; } for (int i = words; i < VL_WORDS_I(obits); ++i) owp[i] = 0; } return owp; } -static inline WDataOutP VL_SHIFTR_WWW(int obits, int lbits, int rbits, WDataOutP owp, WDataInP lwp, - WDataInP rwp) VL_MT_SAFE { +static inline WDataOutP VL_SHIFTR_WWW(int obits, int lbits, int rbits, WDataOutP owp, + WDataInP const lwp, WDataInP const rwp) VL_MT_SAFE { for (int i = 1; i < VL_WORDS_I(rbits); ++i) { if (VL_UNLIKELY(rwp[i])) { // Huge shift 1>>32 or more return VL_ZERO_W(obits, owp); @@ -2543,14 +2554,15 @@ static inline WDataOutP VL_SHIFTR_WWW(int obits, int lbits, int rbits, WDataOutP } return VL_SHIFTR_WWI(obits, lbits, 32, owp, lwp, rwp[0]); } -static inline WDataOutP VL_SHIFTR_WWQ(int obits, int lbits, int rbits, WDataOutP owp, WDataInP lwp, - QData rd) VL_MT_SAFE { +static inline WDataOutP VL_SHIFTR_WWQ(int obits, int lbits, int rbits, WDataOutP owp, + WDataInP const lwp, QData rd) VL_MT_SAFE { WData rwp[VL_WQ_WORDS_E]; VL_SET_WQ(rwp, rd); return VL_SHIFTR_WWW(obits, lbits, rbits, owp, lwp, rwp); } -static inline IData VL_SHIFTR_IIW(int obits, int, int rbits, IData lhs, WDataInP rwp) VL_MT_SAFE { +static inline IData VL_SHIFTR_IIW(int obits, int, int rbits, IData lhs, + WDataInP const rwp) VL_MT_SAFE { for (int i = 1; i < VL_WORDS_I(rbits); ++i) { if (VL_UNLIKELY(rwp[i])) { // Huge shift 1>>32 or more return 0; @@ -2558,7 +2570,8 @@ static inline IData VL_SHIFTR_IIW(int obits, int, int rbits, IData lhs, WDataInP } return VL_CLEAN_II(obits, obits, lhs >> rwp[0]); } -static inline QData VL_SHIFTR_QQW(int obits, int, int rbits, QData lhs, WDataInP rwp) VL_MT_SAFE { +static inline QData VL_SHIFTR_QQW(int obits, int, int rbits, QData lhs, + WDataInP const rwp) VL_MT_SAFE { for (int i = 1; i < VL_WORDS_I(rbits); ++i) { if (VL_UNLIKELY(rwp[i])) { // Huge shift 1>>32 or more return 0; @@ -2582,41 +2595,41 @@ static inline IData VL_SHIFTRS_III(int obits, int lbits, int, IData lhs, IData r // IEEE says signed if output signed, but bit position from lbits; // must use lbits for sign; lbits might != obits, // an EXTEND(SHIFTRS(...)) can became a SHIFTRS(...) within same 32/64 bit word length - IData sign = -(lhs >> (lbits - 1)); // ffff_ffff if negative - IData signext = ~(VL_MASK_I(lbits) >> rhs); // One with bits where we've shifted "past" + const IData sign = -(lhs >> (lbits - 1)); // ffff_ffff if negative + const IData signext = ~(VL_MASK_I(lbits) >> rhs); // One with bits where we've shifted "past" return (lhs >> rhs) | (sign & VL_CLEAN_II(obits, obits, signext)); } static inline QData VL_SHIFTRS_QQI(int obits, int lbits, int, QData lhs, IData rhs) VL_PURE { - QData sign = -(lhs >> (lbits - 1)); - QData signext = ~(VL_MASK_Q(lbits) >> rhs); + const QData sign = -(lhs >> (lbits - 1)); + const QData signext = ~(VL_MASK_Q(lbits) >> rhs); return (lhs >> rhs) | (sign & VL_CLEAN_QQ(obits, obits, signext)); } static inline IData VL_SHIFTRS_IQI(int obits, int lbits, int rbits, QData lhs, IData rhs) VL_PURE { return static_cast(VL_SHIFTRS_QQI(obits, lbits, rbits, lhs, rhs)); } -static inline WDataOutP VL_SHIFTRS_WWI(int obits, int lbits, int, WDataOutP owp, WDataInP lwp, - IData rd) VL_MT_SAFE { - int word_shift = VL_BITWORD_E(rd); - int bit_shift = VL_BITBIT_E(rd); - int lmsw = VL_WORDS_I(obits) - 1; - EData sign = VL_SIGNONES_E(lbits, lwp[lmsw]); +static inline WDataOutP VL_SHIFTRS_WWI(int obits, int lbits, int, WDataOutP owp, + WDataInP const lwp, IData rd) VL_MT_SAFE { + const int word_shift = VL_BITWORD_E(rd); + const int bit_shift = VL_BITBIT_E(rd); + const int lmsw = VL_WORDS_I(obits) - 1; + const EData sign = VL_SIGNONES_E(lbits, lwp[lmsw]); if (rd >= static_cast(obits)) { // Shifting past end, sign in all of lbits for (int i = 0; i <= lmsw; ++i) owp[i] = sign; owp[lmsw] &= VL_MASK_E(lbits); } else if (bit_shift == 0) { // Aligned word shift (>>0,>>32,>>64 etc) - int copy_words = (VL_WORDS_I(obits) - word_shift); + const int copy_words = (VL_WORDS_I(obits) - word_shift); for (int i = 0; i < copy_words; ++i) owp[i] = lwp[i + word_shift]; if (copy_words >= 0) owp[copy_words - 1] |= ~VL_MASK_E(obits) & sign; for (int i = copy_words; i < VL_WORDS_I(obits); ++i) owp[i] = sign; owp[lmsw] &= VL_MASK_E(lbits); } else { - int loffset = rd & VL_SIZEBITS_E; + const int loffset = rd & VL_SIZEBITS_E; int nbitsonright = VL_EDATASIZE - loffset; // bits that end up in lword (know loffset!=0) // Middle words - int words = VL_WORDS_I(obits - rd); + const int words = VL_WORDS_I(obits - rd); for (int i = 0; i < words; ++i) { owp[i] = lwp[i + word_shift] >> loffset; - int upperword = i + word_shift + 1; + const int upperword = i + word_shift + 1; if (upperword < VL_WORDS_I(obits)) owp[i] |= lwp[upperword] << nbitsonright; } if (words) owp[words - 1] |= sign & ~VL_MASK_E(obits - loffset); @@ -2626,12 +2639,12 @@ static inline WDataOutP VL_SHIFTRS_WWI(int obits, int lbits, int, WDataOutP owp, return owp; } static inline WDataOutP VL_SHIFTRS_WWW(int obits, int lbits, int rbits, WDataOutP owp, - WDataInP lwp, WDataInP rwp) VL_MT_SAFE { + WDataInP const lwp, WDataInP const rwp) VL_MT_SAFE { EData overshift = 0; // Huge shift 1>>32 or more for (int i = 1; i < VL_WORDS_I(rbits); ++i) overshift |= rwp[i]; if (VL_UNLIKELY(overshift || rwp[0] >= obits)) { - int lmsw = VL_WORDS_I(obits) - 1; - EData sign = VL_SIGNONES_E(lbits, lwp[lmsw]); + const int lmsw = VL_WORDS_I(obits) - 1; + const EData sign = VL_SIGNONES_E(lbits, lwp[lmsw]); for (int j = 0; j <= lmsw; ++j) owp[j] = sign; owp[lmsw] &= VL_MASK_E(lbits); return owp; @@ -2639,27 +2652,27 @@ static inline WDataOutP VL_SHIFTRS_WWW(int obits, int lbits, int rbits, WDataOut return VL_SHIFTRS_WWI(obits, lbits, 32, owp, lwp, rwp[0]); } static inline WDataOutP VL_SHIFTRS_WWQ(int obits, int lbits, int rbits, WDataOutP owp, - WDataInP lwp, QData rd) VL_MT_SAFE { + WDataInP const lwp, QData rd) VL_MT_SAFE { WData rwp[VL_WQ_WORDS_E]; VL_SET_WQ(rwp, rd); return VL_SHIFTRS_WWW(obits, lbits, rbits, owp, lwp, rwp); } static inline IData VL_SHIFTRS_IIW(int obits, int lbits, int rbits, IData lhs, - WDataInP rwp) VL_MT_SAFE { + WDataInP const rwp) VL_MT_SAFE { EData overshift = 0; // Huge shift 1>>32 or more for (int i = 1; i < VL_WORDS_I(rbits); ++i) overshift |= rwp[i]; if (VL_UNLIKELY(overshift || rwp[0] >= obits)) { - IData sign = -(lhs >> (lbits - 1)); // ffff_ffff if negative + const IData sign = -(lhs >> (lbits - 1)); // ffff_ffff if negative return VL_CLEAN_II(obits, obits, sign); } return VL_SHIFTRS_III(obits, lbits, 32, lhs, rwp[0]); } static inline QData VL_SHIFTRS_QQW(int obits, int lbits, int rbits, QData lhs, - WDataInP rwp) VL_MT_SAFE { + WDataInP const rwp) VL_MT_SAFE { EData overshift = 0; // Huge shift 1>>32 or more for (int i = 1; i < VL_WORDS_I(rbits); ++i) overshift |= rwp[i]; if (VL_UNLIKELY(overshift || rwp[0] >= obits)) { - QData sign = -(lhs >> (lbits - 1)); // ffff_ffff if negative + const QData sign = -(lhs >> (lbits - 1)); // ffff_ffff if negative return VL_CLEAN_QQ(obits, obits, sign); } return VL_SHIFTRS_QQI(obits, lbits, 32, lhs, rwp[0]); @@ -2685,7 +2698,8 @@ static inline QData VL_SHIFTRS_QQQ(int obits, int lbits, int rbits, QData lhs, Q #define VL_BITSEL_QQII(obits, lbits, rbits, zbits, lhs, rhs) ((lhs) >> (rhs)) #define VL_BITSEL_IQII(obits, lbits, rbits, zbits, lhs, rhs) (static_cast((lhs) >> (rhs))) -static inline IData VL_BITSEL_IWII(int, int lbits, int, int, WDataInP lwp, IData rd) VL_MT_SAFE { +static inline IData VL_BITSEL_IWII(int, int lbits, int, int, WDataInP const lwp, + IData rd) VL_MT_SAFE { int word = VL_BITWORD_E(rd); if (VL_UNLIKELY(rd > static_cast(lbits))) { return ~0; // Spec says you can go outside the range of a array. Don't coredump if so. @@ -2702,7 +2716,7 @@ static inline IData VL_BITSEL_IWII(int, int lbits, int, int, WDataInP lwp, IData #define VL_SEL_IQII(obits, lbits, rbits, tbits, lhs, lsb, width) \ (static_cast((lhs) >> (lsb))) -static inline IData VL_SEL_IWII(int, int lbits, int, int, WDataInP lwp, IData lsb, +static inline IData VL_SEL_IWII(int, int lbits, int, int, WDataInP const lwp, IData lsb, IData width) VL_MT_SAFE { int msb = lsb + width - 1; if (VL_UNLIKELY(msb >= lbits)) { @@ -2716,32 +2730,32 @@ static inline IData VL_SEL_IWII(int, int lbits, int, int, WDataInP lwp, IData ls } } -static inline QData VL_SEL_QWII(int, int lbits, int, int, WDataInP lwp, IData lsb, +static inline QData VL_SEL_QWII(int, int lbits, int, int, WDataInP const lwp, IData lsb, IData width) VL_MT_SAFE { - int msb = lsb + width - 1; + const int msb = lsb + width - 1; if (VL_UNLIKELY(msb > lbits)) { return ~0; // Spec says you can go outside the range of a array. Don't coredump if so. } else if (VL_BITWORD_E(msb) == VL_BITWORD_E(static_cast(lsb))) { return VL_BITRSHIFT_W(lwp, lsb); } else if (VL_BITWORD_E(msb) == 1 + VL_BITWORD_E(static_cast(lsb))) { - int nbitsfromlow = VL_EDATASIZE - VL_BITBIT_E(lsb); - QData hi = (lwp[VL_BITWORD_E(msb)]); - QData lo = VL_BITRSHIFT_W(lwp, lsb); + const int nbitsfromlow = VL_EDATASIZE - VL_BITBIT_E(lsb); + const QData hi = (lwp[VL_BITWORD_E(msb)]); + const QData lo = VL_BITRSHIFT_W(lwp, lsb); return (hi << nbitsfromlow) | lo; } else { // 64 bit extraction may span three words int nbitsfromlow = VL_EDATASIZE - VL_BITBIT_E(lsb); - QData hi = (lwp[VL_BITWORD_E(msb)]); - QData mid = (lwp[VL_BITWORD_E(lsb) + 1]); - QData lo = VL_BITRSHIFT_W(lwp, lsb); + const QData hi = (lwp[VL_BITWORD_E(msb)]); + const QData mid = (lwp[VL_BITWORD_E(lsb) + 1]); + const QData lo = VL_BITRSHIFT_W(lwp, lsb); return (hi << (nbitsfromlow + VL_EDATASIZE)) | (mid << nbitsfromlow) | lo; } } -static inline WDataOutP VL_SEL_WWII(int obits, int lbits, int, int, WDataOutP owp, WDataInP lwp, - IData lsb, IData width) VL_MT_SAFE { - int msb = lsb + width - 1; - int word_shift = VL_BITWORD_E(lsb); +static inline WDataOutP VL_SEL_WWII(int obits, int lbits, int, int, WDataOutP owp, + WDataInP const lwp, IData lsb, IData width) VL_MT_SAFE { + const int msb = lsb + width - 1; + const int word_shift = VL_BITWORD_E(lsb); if (VL_UNLIKELY(msb > lbits)) { // Outside bounds, for (int i = 0; i < VL_WORDS_I(obits) - 1; ++i) owp[i] = ~0; owp[VL_WORDS_I(obits) - 1] = VL_MASK_E(obits); @@ -2750,13 +2764,13 @@ static inline WDataOutP VL_SEL_WWII(int obits, int lbits, int, int, WDataOutP ow for (int i = 0; i < VL_WORDS_I(obits); ++i) owp[i] = lwp[i + word_shift]; } else { // Not a _vl_insert because the bits come from any bit number and goto bit 0 - int loffset = lsb & VL_SIZEBITS_E; - int nbitsfromlow = VL_EDATASIZE - loffset; // bits that end up in lword (know loffset!=0) - // Middle words - int words = VL_WORDS_I(msb - lsb + 1); + const int loffset = lsb & VL_SIZEBITS_E; + const int nbitsfromlow = VL_EDATASIZE - loffset; // bits that end up in lword (know + // loffset!=0) Middle words + const int words = VL_WORDS_I(msb - lsb + 1); for (int i = 0; i < words; ++i) { owp[i] = lwp[i + word_shift] >> loffset; - int upperword = i + word_shift + 1; + const int upperword = i + word_shift + 1; if (upperword <= static_cast(VL_BITWORD_E(msb))) { owp[i] |= lwp[upperword] << nbitsfromlow; } @@ -2776,9 +2790,9 @@ static inline QData VL_RTOIROUND_Q_D(int, double lhs) VL_PURE { // This does not need to support subnormals as they are sub-integral lhs = VL_ROUND(lhs); if (lhs == 0.0) return 0; - QData q = VL_CVT_Q_D(lhs); - int lsb = static_cast((q >> 52ULL) & VL_MASK_Q(11)) - 1023 - 52; - vluint64_t mantissa = (q & VL_MASK_Q(52)) | (1ULL << 52); + const QData q = VL_CVT_Q_D(lhs); + const int lsb = static_cast((q >> 52ULL) & VL_MASK_Q(11)) - 1023 - 52; + const vluint64_t mantissa = (q & VL_MASK_Q(52)) | (1ULL << 52); vluint64_t out = 0; if (lsb < 0) { out = mantissa >> -lsb; @@ -2797,9 +2811,9 @@ static inline WDataOutP VL_RTOIROUND_W_D(int obits, WDataOutP owp, double lhs) V lhs = VL_ROUND(lhs); VL_ZERO_W(obits, owp); if (lhs == 0.0) return owp; - QData q = VL_CVT_Q_D(lhs); - int lsb = static_cast((q >> 52ULL) & VL_MASK_Q(11)) - 1023 - 52; - vluint64_t mantissa = (q & VL_MASK_Q(52)) | (1ULL << 52); + const QData q = VL_CVT_Q_D(lhs); + const int lsb = static_cast((q >> 52ULL) & VL_MASK_Q(11)) - 1023 - 52; + const vluint64_t mantissa = (q & VL_MASK_Q(52)) | (1ULL << 52); if (lsb < 0) { VL_SET_WQ(owp, mantissa >> -lsb); } else if (lsb < obits) { @@ -2837,8 +2851,8 @@ static inline void VL_ASSIGNSEL_QIIQ(int rbits, int obits, int lsb, QData& lhsr, QData rhs) VL_PURE { _vl_insert_QQ(obits, lhsr, rhs, lsb + obits - 1, lsb, rbits); } -// static inline void VL_ASSIGNSEL_IIIW(int obits, int lsb, IData& lhsr, WDataInP rwp) VL_MT_SAFE { -// Illegal, as lhs width >= rhs width +// static inline void VL_ASSIGNSEL_IIIW(int obits, int lsb, IData& lhsr, WDataInP const rwp) +// VL_MT_SAFE { Illegal, as lhs width >= rhs width static inline void VL_ASSIGNSEL_WIII(int rbits, int obits, int lsb, WDataOutP owp, IData rhs) VL_MT_SAFE { _vl_insert_WI(obits, owp, rhs, lsb + obits - 1, lsb, rbits); @@ -2848,7 +2862,7 @@ static inline void VL_ASSIGNSEL_WIIQ(int rbits, int obits, int lsb, WDataOutP ow _vl_insert_WQ(obits, owp, rhs, lsb + obits - 1, lsb, rbits); } static inline void VL_ASSIGNSEL_WIIW(int rbits, int obits, int lsb, WDataOutP owp, - WDataInP rwp) VL_MT_SAFE { + WDataInP const rwp) VL_MT_SAFE { _vl_insert_WW(obits, owp, rwp, lsb + obits - 1, lsb, rbits); } @@ -2856,8 +2870,8 @@ static inline void VL_ASSIGNSEL_WIIW(int rbits, int obits, int lsb, WDataOutP ow // Triops static inline WDataOutP VL_COND_WIWW(int obits, int, int, int, WDataOutP owp, int cond, - WDataInP w1p, WDataInP w2p) VL_MT_SAFE { - int words = VL_WORDS_I(obits); + WDataInP const w1p, WDataInP const w2p) VL_MT_SAFE { + const int words = VL_WORDS_I(obits); for (int i = 0; i < words; ++i) owp[i] = cond ? w1p[i] : w2p[i]; return owp; } diff --git a/include/verilated_cov.cpp b/include/verilated_cov.cpp index 3cc223236..1fe14ba8d 100644 --- a/include/verilated_cov.cpp +++ b/include/verilated_cov.cpp @@ -193,7 +193,7 @@ private: // We used to backup and split on only .'s but it seems better to be verbose // and not assume . is the separator - std::string prefix = std::string(a, apre - a); + const std::string prefix = std::string(a, apre - a); // Scan backward to last mismatch const char* apost = a + std::strlen(a) - 1; @@ -251,7 +251,7 @@ private: public: // PUBLIC METHODS - void forcePerInstance(bool flag) VL_MT_SAFE_EXCLUDES(m_mutex) { + void forcePerInstance(const bool flag) VL_MT_SAFE_EXCLUDES(m_mutex) { Verilated::quiesce(); const VerilatedLockGuard lock(m_mutex); m_forcePerInstance = flag; @@ -261,7 +261,7 @@ public: const VerilatedLockGuard lock(m_mutex); clearGuts(); } - void clearNonMatch(const char* matchp) VL_MT_SAFE_EXCLUDES(m_mutex) { + void clearNonMatch(const char* const matchp) VL_MT_SAFE_EXCLUDES(m_mutex) { Verilated::quiesce(); const VerilatedLockGuard lock(m_mutex); if (matchp && matchp[0]) { @@ -288,7 +288,7 @@ public: assert(!m_insertp); m_insertp = itemp; } - void insertf(const char* filenamep, int lineno) VL_MT_SAFE_EXCLUDES(m_mutex) { + void insertf(const char* const filenamep, const int lineno) VL_MT_SAFE_EXCLUDES(m_mutex) { const VerilatedLockGuard lock(m_mutex); m_insertFilenamep = filenamep; m_insertLineno = lineno; diff --git a/include/verilated_dpi.cpp b/include/verilated_dpi.cpp index c40ec5c9a..8ec3fc457 100644 --- a/include/verilated_dpi.cpp +++ b/include/verilated_dpi.cpp @@ -79,19 +79,19 @@ void svPutBitselLogic(svLogicVecVal* dp, int bit, svLogic s) { void svGetPartselBit(svBitVecVal* dp, const svBitVecVal* sp, int lsb, int width) { // See also VL_SEL_WWI - int msb = lsb + width - 1; - int word_shift = VL_BITWORD_I(lsb); + const int msb = lsb + width - 1; + const int word_shift = VL_BITWORD_I(lsb); if (VL_BITBIT_I(lsb) == 0) { // Just a word extract for (int i = 0; i < VL_WORDS_I(width); ++i) dp[i] = sp[i + word_shift]; } else { - int loffset = lsb & VL_SIZEBITS_I; - int nbitsfromlow = 32 - loffset; // bits that end up in lword (know loffset!=0) + const int loffset = lsb & VL_SIZEBITS_I; + const int nbitsfromlow = 32 - loffset; // bits that end up in lword (know loffset!=0) // Middle words - int words = VL_WORDS_I(msb - lsb + 1); + const int words = VL_WORDS_I(msb - lsb + 1); for (int i = 0; i < words; ++i) { dp[i] = sp[i + word_shift] >> loffset; - int upperword = i + word_shift + 1; + const int upperword = i + word_shift + 1; if (upperword <= static_cast(VL_BITWORD_I(msb))) { dp[i] |= sp[upperword] << nbitsfromlow; } @@ -101,20 +101,20 @@ void svGetPartselBit(svBitVecVal* dp, const svBitVecVal* sp, int lsb, int width) dp[VL_WORDS_I(width) - 1] &= VL_MASK_I(width); } void svGetPartselLogic(svLogicVecVal* dp, const svLogicVecVal* sp, int lsb, int width) { - int msb = lsb + width - 1; - int word_shift = VL_BITWORD_I(lsb); + const int msb = lsb + width - 1; + const int word_shift = VL_BITWORD_I(lsb); if (VL_BITBIT_I(lsb) == 0) { // Just a word extract for (int i = 0; i < VL_WORDS_I(width); ++i) dp[i] = sp[i + word_shift]; } else { - int loffset = lsb & VL_SIZEBITS_I; - int nbitsfromlow = 32 - loffset; // bits that end up in lword (know loffset!=0) + const int loffset = lsb & VL_SIZEBITS_I; + const int nbitsfromlow = 32 - loffset; // bits that end up in lword (know loffset!=0) // Middle words - int words = VL_WORDS_I(msb - lsb + 1); + const int words = VL_WORDS_I(msb - lsb + 1); for (int i = 0; i < words; ++i) { dp[i].aval = sp[i + word_shift].aval >> loffset; dp[i].bval = sp[i + word_shift].bval >> loffset; - int upperword = i + word_shift + 1; + const int upperword = i + word_shift + 1; if (upperword <= static_cast(VL_BITWORD_I(msb))) { dp[i].aval |= sp[upperword].aval << nbitsfromlow; dp[i].bval |= sp[upperword].bval << nbitsfromlow; @@ -127,22 +127,22 @@ void svGetPartselLogic(svLogicVecVal* dp, const svLogicVecVal* sp, int lsb, int } void svPutPartselBit(svBitVecVal* dp, const svBitVecVal s, int lbit, int width) { // See also _vl_insert_WI - int hbit = lbit + width - 1; - int hoffset = VL_BITBIT_I(hbit); - int loffset = VL_BITBIT_I(lbit); + const int hbit = lbit + width - 1; + const int hoffset = VL_BITBIT_I(hbit); + const int loffset = VL_BITBIT_I(lbit); if (hoffset == VL_SIZEBITS_I && loffset == 0) { // Fast and common case, word based insertion dp[VL_BITWORD_I(lbit)] = s; } else { - int hword = VL_BITWORD_I(hbit); - int lword = VL_BITWORD_I(lbit); + const int hword = VL_BITWORD_I(hbit); + const int lword = VL_BITWORD_I(lbit); if (hword == lword) { // know < 32 bits because above checks it - IData insmask = (VL_MASK_I(hoffset - loffset + 1)) << loffset; + const IData insmask = (VL_MASK_I(hoffset - loffset + 1)) << loffset; dp[lword] = (dp[lword] & ~insmask) | ((s << loffset) & insmask); } else { - IData hinsmask = (VL_MASK_I(hoffset - 0 + 1)) << 0; - IData linsmask = (VL_MASK_I(31 - loffset + 1)) << loffset; - int nbitsonright = 32 - loffset; // bits that end up in lword + const IData hinsmask = (VL_MASK_I(hoffset - 0 + 1)) << 0; + const IData linsmask = (VL_MASK_I(31 - loffset + 1)) << loffset; + const int nbitsonright = 32 - loffset; // bits that end up in lword dp[lword] = (dp[lword] & ~linsmask) | ((s << loffset) & linsmask); dp[hword] = (dp[hword] & ~hinsmask) | ((s >> nbitsonright) & hinsmask); } @@ -150,24 +150,24 @@ void svPutPartselBit(svBitVecVal* dp, const svBitVecVal s, int lbit, int width) } // cppcheck-suppress passedByValue void svPutPartselLogic(svLogicVecVal* dp, const svLogicVecVal s, int lbit, int width) { - int hbit = lbit + width - 1; - int hoffset = VL_BITBIT_I(hbit); - int loffset = VL_BITBIT_I(lbit); + const int hbit = lbit + width - 1; + const int hoffset = VL_BITBIT_I(hbit); + const int loffset = VL_BITBIT_I(lbit); if (hoffset == VL_SIZEBITS_I && loffset == 0) { // Fast and common case, word based insertion dp[VL_BITWORD_I(lbit)].aval = s.aval; dp[VL_BITWORD_I(lbit)].bval = s.bval; } else { - int hword = VL_BITWORD_I(hbit); - int lword = VL_BITWORD_I(lbit); + const int hword = VL_BITWORD_I(hbit); + const int lword = VL_BITWORD_I(lbit); if (hword == lword) { // know < 32 bits because above checks it - IData insmask = (VL_MASK_I(hoffset - loffset + 1)) << loffset; + const IData insmask = (VL_MASK_I(hoffset - loffset + 1)) << loffset; dp[lword].aval = (dp[lword].aval & ~insmask) | ((s.aval << loffset) & insmask); dp[lword].bval = (dp[lword].bval & ~insmask) | ((s.bval << loffset) & insmask); } else { - IData hinsmask = (VL_MASK_I(hoffset - 0 + 1)) << 0; - IData linsmask = (VL_MASK_I(31 - loffset + 1)) << loffset; - int nbitsonright = 32 - loffset; // bits that end up in lword + const IData hinsmask = (VL_MASK_I(hoffset - 0 + 1)) << 0; + const IData linsmask = (VL_MASK_I(31 - loffset + 1)) << loffset; + const int nbitsonright = 32 - loffset; // bits that end up in lword dp[lword].aval = (dp[lword].aval & ~linsmask) | ((s.aval << loffset) & linsmask); dp[lword].bval = (dp[lword].bval & ~linsmask) | ((s.bval << loffset) & linsmask); dp[hword].aval = (dp[hword].aval & ~hinsmask) | ((s.aval >> nbitsonright) & hinsmask); @@ -460,13 +460,13 @@ void svPutBitArrElemVecVal(const svOpenArrayHandle d, const svBitVecVal* s, int switch (varp->udims()) { case 1: _vl_svPutBitArrElemVecVal(d, s, 1, indx1, 0, 0); break; case 2: { - int indx2 = va_arg(ap, int); + const int indx2 = va_arg(ap, int); _vl_svPutBitArrElemVecVal(d, s, 2, indx1, indx2, 0); break; } case 3: { - int indx2 = va_arg(ap, int); - int indx3 = va_arg(ap, int); + const int indx2 = va_arg(ap, int); + const int indx3 = va_arg(ap, int); _vl_svPutBitArrElemVecVal(d, s, 3, indx1, indx2, indx3); break; } @@ -492,13 +492,13 @@ void svPutLogicArrElemVecVal(const svOpenArrayHandle d, const svLogicVecVal* s, switch (varp->udims()) { case 1: _vl_svPutLogicArrElemVecVal(d, s, 1, indx1, 0, 0); break; case 2: { - int indx2 = va_arg(ap, int); + const int indx2 = va_arg(ap, int); _vl_svPutLogicArrElemVecVal(d, s, 2, indx1, indx2, 0); break; } case 3: { - int indx2 = va_arg(ap, int); - int indx3 = va_arg(ap, int); + const int indx2 = va_arg(ap, int); + const int indx3 = va_arg(ap, int); _vl_svPutLogicArrElemVecVal(d, s, 3, indx1, indx2, indx3); break; } @@ -528,13 +528,13 @@ void svGetBitArrElemVecVal(svBitVecVal* d, const svOpenArrayHandle s, int indx1, switch (varp->udims()) { case 1: _vl_svGetBitArrElemVecVal(d, s, 1, indx1, 0, 0); break; case 2: { - int indx2 = va_arg(ap, int); + const int indx2 = va_arg(ap, int); _vl_svGetBitArrElemVecVal(d, s, 2, indx1, indx2, 0); break; } case 3: { - int indx2 = va_arg(ap, int); - int indx3 = va_arg(ap, int); + const int indx2 = va_arg(ap, int); + const int indx3 = va_arg(ap, int); _vl_svGetBitArrElemVecVal(d, s, 3, indx1, indx2, indx3); break; } @@ -559,13 +559,13 @@ void svGetLogicArrElemVecVal(svLogicVecVal* d, const svOpenArrayHandle s, int in switch (varp->udims()) { case 1: _vl_svGetLogicArrElemVecVal(d, s, 1, indx1, 0, 0); break; case 2: { - int indx2 = va_arg(ap, int); + const int indx2 = va_arg(ap, int); _vl_svGetLogicArrElemVecVal(d, s, 2, indx1, indx2, 0); break; } case 3: { - int indx2 = va_arg(ap, int); - int indx3 = va_arg(ap, int); + const int indx2 = va_arg(ap, int); + const int indx3 = va_arg(ap, int); _vl_svGetLogicArrElemVecVal(d, s, 3, indx1, indx2, indx3); break; } @@ -592,13 +592,13 @@ svBit svGetBitArrElem(const svOpenArrayHandle s, int indx1, ...) { switch (varp->udims()) { case 1: out = _vl_svGetBitArrElem(s, 1, indx1, 0, 0, 0); break; case 2: { - int indx2 = va_arg(ap, int); + const int indx2 = va_arg(ap, int); out = _vl_svGetBitArrElem(s, 2, indx1, indx2, 0, 0); break; } case 3: { - int indx2 = va_arg(ap, int); - int indx3 = va_arg(ap, int); + const int indx2 = va_arg(ap, int); + const int indx3 = va_arg(ap, int); out = _vl_svGetBitArrElem(s, 3, indx1, indx2, indx3, 0); break; } @@ -625,13 +625,13 @@ svLogic svGetLogicArrElem(const svOpenArrayHandle s, int indx1, ...) { switch (varp->udims()) { case 1: out = _vl_svGetBitArrElem(s, 1, indx1, 0, 0, 0); break; case 2: { - int indx2 = va_arg(ap, int); + const int indx2 = va_arg(ap, int); out = _vl_svGetBitArrElem(s, 2, indx1, indx2, 0, 0); break; } case 3: { - int indx2 = va_arg(ap, int); - int indx3 = va_arg(ap, int); + const int indx2 = va_arg(ap, int); + const int indx3 = va_arg(ap, int); out = _vl_svGetBitArrElem(s, 3, indx1, indx2, indx3, 0); break; } @@ -660,13 +660,13 @@ void svPutBitArrElem(const svOpenArrayHandle d, svBit value, int indx1, ...) { switch (varp->udims()) { case 1: _vl_svPutBitArrElem(d, value, 1, indx1, 0, 0, 0); break; case 2: { - int indx2 = va_arg(ap, int); + const int indx2 = va_arg(ap, int); _vl_svPutBitArrElem(d, value, 2, indx1, indx2, 0, 0); break; } case 3: { - int indx2 = va_arg(ap, int); - int indx3 = va_arg(ap, int); + const int indx2 = va_arg(ap, int); + const int indx3 = va_arg(ap, int); _vl_svPutBitArrElem(d, value, 3, indx1, indx2, indx3, 0); break; } @@ -691,13 +691,13 @@ void svPutLogicArrElem(const svOpenArrayHandle d, svLogic value, int indx1, ...) switch (varp->udims()) { case 1: _vl_svPutBitArrElem(d, value, 1, indx1, 0, 0, 0); break; case 2: { - int indx2 = va_arg(ap, int); + const int indx2 = va_arg(ap, int); _vl_svPutBitArrElem(d, value, 2, indx1, indx2, 0, 0); break; } case 3: { - int indx2 = va_arg(ap, int); - int indx3 = va_arg(ap, int); + const int indx2 = va_arg(ap, int); + const int indx3 = va_arg(ap, int); _vl_svPutBitArrElem(d, value, 3, indx1, indx2, indx3, 0); break; } diff --git a/include/verilated_dpi.h b/include/verilated_dpi.h index 8834342b9..d86e741fa 100644 --- a/include/verilated_dpi.h +++ b/include/verilated_dpi.h @@ -38,7 +38,7 @@ // Convert svBitVecVal to Verilator internal data static inline void VL_SET_W_SVBV(int obits, WDataOutP owp, const svBitVecVal* lwp) VL_MT_SAFE { - int words = VL_WORDS_I(obits); + const int words = VL_WORDS_I(obits); for (int i = 0; i < words - 1; ++i) owp[i] = lwp[i]; owp[words - 1] = lwp[words - 1] & VL_MASK_I(obits); } @@ -48,20 +48,20 @@ static inline QData VL_SET_Q_SVBV(const svBitVecVal* lwp) VL_MT_SAFE { static inline IData VL_SET_I_SVBV(const svBitVecVal* lwp) VL_MT_SAFE { return lwp[0]; } // Convert Verilator internal data to svBitVecVal -static inline void VL_SET_SVBV_W(int obits, svBitVecVal* owp, WDataInP lwp) VL_MT_SAFE { - int words = VL_WORDS_I(obits); +static inline void VL_SET_SVBV_W(int obits, svBitVecVal* owp, const WDataInP lwp) VL_MT_SAFE { + const int words = VL_WORDS_I(obits); for (int i = 0; i < words - 1; ++i) owp[i] = lwp[i]; owp[words - 1] = lwp[words - 1] & VL_MASK_I(obits); } -static inline void VL_SET_SVBV_I(int, svBitVecVal* owp, IData ld) VL_MT_SAFE { owp[0] = ld; } -static inline void VL_SET_SVBV_Q(int, svBitVecVal* owp, QData ld) VL_MT_SAFE { +static inline void VL_SET_SVBV_I(int, svBitVecVal* owp, const IData ld) VL_MT_SAFE { owp[0] = ld; } +static inline void VL_SET_SVBV_Q(int, svBitVecVal* owp, const QData ld) VL_MT_SAFE { VL_SET_WQ(owp, ld); } // Convert svLogicVecVal to Verilator internal data // Note these functions ignore X/Z in svLogicVecVal static inline void VL_SET_W_SVLV(int obits, WDataOutP owp, const svLogicVecVal* lwp) VL_MT_SAFE { - int words = VL_WORDS_I(obits); + const int words = VL_WORDS_I(obits); for (int i = 0; i < words - 1; ++i) owp[i] = lwp[i].aval; owp[words - 1] = lwp[words - 1].aval & VL_MASK_I(obits); } @@ -72,17 +72,17 @@ static inline IData VL_SET_I_SVLV(const svLogicVecVal* lwp) VL_MT_SAFE { return // Convert Verilator internal data to svLogicVecVal // Note these functions never create X/Z in svLogicVecVal -static inline void VL_SET_SVLV_W(int obits, svLogicVecVal* owp, WDataInP lwp) VL_MT_SAFE { - int words = VL_WORDS_I(obits); +static inline void VL_SET_SVLV_W(int obits, svLogicVecVal* owp, const WDataInP lwp) VL_MT_SAFE { + const int words = VL_WORDS_I(obits); for (int i = 0; i < words; ++i) owp[i].bval = 0; for (int i = 0; i < words - 1; ++i) owp[i].aval = lwp[i]; owp[words - 1].aval = lwp[words - 1] & VL_MASK_I(obits); } -static inline void VL_SET_SVLV_I(int, svLogicVecVal* owp, IData ld) VL_MT_SAFE { +static inline void VL_SET_SVLV_I(int, svLogicVecVal* owp, const IData ld) VL_MT_SAFE { owp[0].aval = ld; owp[0].bval = 0; } -static inline void VL_SET_SVLV_Q(int, svLogicVecVal* owp, QData ld) VL_MT_SAFE { +static inline void VL_SET_SVLV_Q(int, svLogicVecVal* owp, const QData ld) VL_MT_SAFE { VlWide<2> lwp; VL_SET_WQ(lwp, ld); owp[0].aval = lwp[0]; diff --git a/include/verilated_fst_c.cpp b/include/verilated_fst_c.cpp index 0fccee988..9d91029de 100644 --- a/include/verilated_fst_c.cpp +++ b/include/verilated_fst_c.cpp @@ -150,7 +150,7 @@ void VerilatedFst::emitTimeChange(vluint64_t timeui) { fstWriterEmitTimeChange(m void VerilatedFst::declDTypeEnum(int dtypenum, const char* name, vluint32_t elements, unsigned int minValbits, const char** itemNamesp, const char** itemValuesp) { - fstEnumHandle enumNum + const fstEnumHandle enumNum = fstWriterCreateEnumTable(m_fst, name, elements, minValbits, itemNamesp, itemValuesp); m_local2fstdtype[dtypenum] = enumNum; } @@ -206,7 +206,7 @@ void VerilatedFst::declare(vluint32_t code, const char* name, int dtypenum, fstV std::string name_str = name_ss.str(); if (dtypenum > 0) { - fstEnumHandle enumNum = m_local2fstdtype[dtypenum]; + const fstEnumHandle enumNum = m_local2fstdtype[dtypenum]; fstWriterEmitEnumTableRef(m_fst, enumNum); } diff --git a/include/verilated_fst_sc.h b/include/verilated_fst_sc.h index b58e98fe7..c9ad874d7 100644 --- a/include/verilated_fst_sc.h +++ b/include/verilated_fst_sc.h @@ -42,9 +42,9 @@ public: // We want to avoid a depreciated warning, but still be back compatible. // Turning off the message just for this still results in an // annoying "to turn off" message. - sc_time t1sec(1, SC_SEC); + const sc_time t1sec(1, SC_SEC); if (t1sec.to_default_time_units() != 0) { - sc_time tunits(1.0 / t1sec.to_default_time_units(), SC_SEC); + const sc_time tunits(1.0 / t1sec.to_default_time_units(), SC_SEC); spTrace()->set_time_unit(tunits.to_string()); } spTrace()->set_time_resolution(sc_get_time_resolution().to_string()); diff --git a/include/verilated_heavy.h b/include/verilated_heavy.h index 7b9218ff1..a0f8107bd 100644 --- a/include/verilated_heavy.h +++ b/include/verilated_heavy.h @@ -43,7 +43,7 @@ extern std::string VL_TO_STRING(SData lhs); extern std::string VL_TO_STRING(IData lhs); extern std::string VL_TO_STRING(QData lhs); inline std::string VL_TO_STRING(const std::string& obj) { return "\"" + obj + "\""; } -extern std::string VL_TO_STRING_W(int words, WDataInP obj); +extern std::string VL_TO_STRING_W(int words, const WDataInP obj); //=================================================================== // Shuffle RNG @@ -131,7 +131,8 @@ template struct VlWide final { // Convert a C array to std::array reference by pointer magic, without copy. // Data type (second argument) is so the function template can automatically generate. -template VlWide& VL_CVT_W_A(WDataInP inp, const VlWide&) { +template +VlWide& VL_CVT_W_A(const WDataInP inp, const VlWide&) { return *((VlWide*)inp); } @@ -795,7 +796,7 @@ void VL_WRITEMEM_N(bool hex, int bits, const std::string& filename, VlWriteMem wmem(hex, bits, filename, start, end); if (VL_UNLIKELY(!wmem.isOpen())) return; for (const auto& i : obj) { - QData addr = i.first; + const QData addr = i.first; if (addr >= start && addr <= end) wmem.print(addr, true, &(i.second)); } } @@ -876,7 +877,7 @@ static inline bool VL_CAST_DYNAMIC(VlClassRef in, VlClassRef& outr) { //====================================================================== // Conversion functions -extern std::string VL_CVT_PACK_STR_NW(int lwords, WDataInP lwp) VL_MT_SAFE; +extern std::string VL_CVT_PACK_STR_NW(int lwords, const WDataInP lwp) VL_MT_SAFE; inline std::string VL_CVT_PACK_STR_NQ(QData lhs) VL_PURE { VlWide lw; VL_SET_WQ(lw, lhs); diff --git a/include/verilated_save.cpp b/include/verilated_save.cpp index df5ada28c..0c07022ea 100644 --- a/include/verilated_save.cpp +++ b/include/verilated_save.cpp @@ -72,9 +72,10 @@ bool VerilatedDeserialize::readDiffers(const void* __restrict datap, VerilatedDeserialize& VerilatedDeserialize::readAssert(const void* __restrict datap, size_t size) VL_MT_UNSAFE_ONE { if (VL_UNLIKELY(readDiffers(datap, size))) { - std::string fn = filename(); - std::string msg = "Can't deserialize save-restore file as was made from different model: " - + filename(); + const std::string fn = filename(); + const std::string msg + = "Can't deserialize save-restore file as was made from different model: " + + filename(); VL_FATAL_MT(fn.c_str(), 0, "", msg.c_str()); // Die before we close() as close would infinite loop } @@ -90,8 +91,8 @@ void VerilatedSerialize::header() VL_MT_UNSAFE_ONE { void VerilatedDeserialize::header() VL_MT_UNSAFE_ONE { VerilatedDeserialize& os = *this; // So can cut and paste standard >> code below if (VL_UNLIKELY(os.readDiffers(VLTSAVE_HEADER_STR, std::strlen(VLTSAVE_HEADER_STR)))) { - std::string fn = filename(); - std::string msg + const std::string fn = filename(); + const std::string msg = std::string( "Can't deserialize; file has wrong header signature, or file not found: ") + filename(); @@ -109,9 +110,10 @@ void VerilatedSerialize::trailer() VL_MT_UNSAFE_ONE { void VerilatedDeserialize::trailer() VL_MT_UNSAFE_ONE { VerilatedDeserialize& os = *this; // So can cut and paste standard >> code below if (VL_UNLIKELY(os.readDiffers(VLTSAVE_TRAILER_STR, std::strlen(VLTSAVE_TRAILER_STR)))) { - std::string fn = filename(); - std::string msg = std::string("Can't deserialize; file has wrong end-of-file signature: ") - + filename(); + const std::string fn = filename(); + const std::string msg + = std::string("Can't deserialize; file has wrong end-of-file signature: ") + + filename(); VL_FATAL_MT(fn.c_str(), 0, "", msg.c_str()); // Die before we close() as close would infinite loop } @@ -192,10 +194,10 @@ void VerilatedSave::flush() VL_MT_UNSAFE_ONE { if (VL_UNLIKELY(!isOpen())) return; vluint8_t* wp = m_bufp; while (true) { - ssize_t remaining = (m_cp - wp); + const ssize_t remaining = (m_cp - wp); if (remaining == 0) break; errno = 0; - ssize_t got = ::write(m_fd, wp, remaining); + const ssize_t got = ::write(m_fd, wp, remaining); if (got > 0) { wp += got; } else if (VL_UNCOVERABLE(got < 0)) { @@ -223,17 +225,17 @@ void VerilatedRestore::fill() VL_MT_UNSAFE_ONE { m_cp = m_bufp; // Reset buffer // Read into buffer starting at m_endp while (true) { - ssize_t remaining = (m_bufp + bufferSize() - m_endp); + const ssize_t remaining = (m_bufp + bufferSize() - m_endp); if (remaining == 0) break; errno = 0; - ssize_t got = ::read(m_fd, m_endp, remaining); + const ssize_t got = ::read(m_fd, m_endp, remaining); if (got > 0) { m_endp += got; } else if (VL_UNCOVERABLE(got < 0)) { if (VL_UNCOVERABLE(errno != EAGAIN && errno != EINTR)) { // LCOV_EXCL_START // write failed, presume error (perhaps out of disk space) - std::string msg = std::string(__FUNCTION__) + ": " + std::strerror(errno); + const std::string msg = std::string(__FUNCTION__) + ": " + std::strerror(errno); VL_FATAL_MT("", 0, "", msg.c_str()); close(); break; diff --git a/include/verilated_save.h b/include/verilated_save.h index 937e59524..1a6c14e13 100644 --- a/include/verilated_save.h +++ b/include/verilated_save.h @@ -236,43 +236,43 @@ public: //============================================================================= -inline VerilatedSerialize& operator<<(VerilatedSerialize& os, vluint64_t& rhs) { +inline VerilatedSerialize& operator<<(VerilatedSerialize& os, const vluint64_t& rhs) { return os.write(&rhs, sizeof(rhs)); } inline VerilatedDeserialize& operator>>(VerilatedDeserialize& os, vluint64_t& rhs) { return os.read(&rhs, sizeof(rhs)); } -inline VerilatedSerialize& operator<<(VerilatedSerialize& os, vluint32_t& rhs) { +inline VerilatedSerialize& operator<<(VerilatedSerialize& os, const vluint32_t& rhs) { return os.write(&rhs, sizeof(rhs)); } inline VerilatedDeserialize& operator>>(VerilatedDeserialize& os, vluint32_t& rhs) { return os.read(&rhs, sizeof(rhs)); } -inline VerilatedSerialize& operator<<(VerilatedSerialize& os, vluint16_t& rhs) { +inline VerilatedSerialize& operator<<(VerilatedSerialize& os, const vluint16_t& rhs) { return os.write(&rhs, sizeof(rhs)); } inline VerilatedDeserialize& operator>>(VerilatedDeserialize& os, vluint16_t& rhs) { return os.read(&rhs, sizeof(rhs)); } -inline VerilatedSerialize& operator<<(VerilatedSerialize& os, vluint8_t& rhs) { +inline VerilatedSerialize& operator<<(VerilatedSerialize& os, const vluint8_t& rhs) { return os.write(&rhs, sizeof(rhs)); } inline VerilatedDeserialize& operator>>(VerilatedDeserialize& os, vluint8_t& rhs) { return os.read(&rhs, sizeof(rhs)); } -inline VerilatedSerialize& operator<<(VerilatedSerialize& os, bool& rhs) { +inline VerilatedSerialize& operator<<(VerilatedSerialize& os, const bool& rhs) { return os.write(&rhs, sizeof(rhs)); } inline VerilatedDeserialize& operator>>(VerilatedDeserialize& os, bool& rhs) { return os.read(&rhs, sizeof(rhs)); } -inline VerilatedSerialize& operator<<(VerilatedSerialize& os, double& rhs) { +inline VerilatedSerialize& operator<<(VerilatedSerialize& os, const double& rhs) { return os.write(&rhs, sizeof(rhs)); } inline VerilatedDeserialize& operator>>(VerilatedDeserialize& os, double& rhs) { return os.read(&rhs, sizeof(rhs)); } -inline VerilatedSerialize& operator<<(VerilatedSerialize& os, float& rhs) { +inline VerilatedSerialize& operator<<(VerilatedSerialize& os, const float& rhs) { return os.write(&rhs, sizeof(rhs)); } inline VerilatedDeserialize& operator>>(VerilatedDeserialize& os, float& rhs) { @@ -295,11 +295,11 @@ VerilatedDeserialize& operator>>(VerilatedDeserialize& os, VerilatedContext* rhs template VerilatedSerialize& operator<<(VerilatedSerialize& os, VlAssocArray& rhs) { os << rhs.atDefault(); - vluint32_t len = rhs.size(); + const vluint32_t len = rhs.size(); os << len; for (const auto& i : rhs) { - T_Key index = i.first; // Copy to get around const_iterator - T_Value value = i.second; + const T_Key index = i.first; // Copy to get around const_iterator + const T_Value value = i.second; os << index << value; } return os; diff --git a/include/verilated_threads.cpp b/include/verilated_threads.cpp index a4e2bfb73..8d3480540 100644 --- a/include/verilated_threads.cpp +++ b/include/verilated_threads.cpp @@ -93,7 +93,7 @@ void VlWorkerThread::startWorker(VlWorkerThread* workerp) { VlThreadPool::VlThreadPool(VerilatedContext* contextp, int nThreads, bool profiling) : m_profiling{profiling} { // --threads N passes nThreads=N-1, as the "main" threads counts as 1 - unsigned cpus = std::thread::hardware_concurrency(); + const unsigned cpus = std::thread::hardware_concurrency(); if (cpus < nThreads + 1) { static int warnedOnce = 0; if (!warnedOnce++) { @@ -149,7 +149,7 @@ void VlThreadPool::profileDump(const char* filenamep, vluint64_t ticksElapsed) const VerilatedLockGuard lk(m_mutex); VL_DEBUG_IF(VL_DBG_MSGF("+prof+threads writing to '%s'\n", filenamep);); - FILE* fp = std::fopen(filenamep, "w"); + FILE* const fp = std::fopen(filenamep, "w"); if (VL_UNLIKELY(!fp)) { VL_FATAL_MT(filenamep, 0, "", "+prof+threads+file file not writable"); // cppcheck-suppress resourceLeak // bug, doesn't realize fp is nullptr diff --git a/include/verilated_threads.h b/include/verilated_threads.h index e01315646..b6163477b 100644 --- a/include/verilated_threads.h +++ b/include/verilated_threads.h @@ -99,19 +99,19 @@ public: // false while it's still waiting on more dependencies. inline bool signalUpstreamDone(bool evenCycle) { if (evenCycle) { - vluint32_t upstreamDepsDone + const vluint32_t upstreamDepsDone = 1 + m_upstreamDepsDone.fetch_add(1, std::memory_order_release); assert(upstreamDepsDone <= m_upstreamDepCount); return (upstreamDepsDone == m_upstreamDepCount); } else { - vluint32_t upstreamDepsDone_prev + const vluint32_t upstreamDepsDone_prev = m_upstreamDepsDone.fetch_sub(1, std::memory_order_release); assert(upstreamDepsDone_prev > 0); return (upstreamDepsDone_prev == 1); } } inline bool areUpstreamDepsDone(bool evenCycle) const { - vluint32_t target = evenCycle ? m_upstreamDepCount : 0; + const vluint32_t target = evenCycle ? m_upstreamDepCount : 0; return m_upstreamDepsDone.load(std::memory_order_acquire) == target; } inline void waitUntilUpstreamDone(bool evenCycle) const { diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index ccbccde8e..798618643 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -129,7 +129,7 @@ void VerilatedVcd::openNextImp(bool incFilename) { if (incFilename) { // Find _0000.{ext} in filename std::string name = m_filename; - size_t pos = name.rfind('.'); + const size_t pos = name.rfind('.'); if (pos > 8 && 0 == std::strncmp("_cat", name.c_str() + pos - 8, 4) && std::isdigit(name.c_str()[pos - 4]) && std::isdigit(name.c_str()[pos - 3]) && std::isdigit(name.c_str()[pos - 2]) && std::isdigit(name.c_str()[pos - 1])) { @@ -299,10 +299,10 @@ void VerilatedVcd::bufferFlush() VL_MT_UNSAFE_ONE { if (VL_UNLIKELY(!isOpen())) return; char* wp = m_wrBufp; while (true) { - ssize_t remaining = (m_writep - wp); + const ssize_t remaining = (m_writep - wp); if (remaining == 0) break; errno = 0; - ssize_t got = m_filep->write(wp, remaining); + const ssize_t got = m_filep->write(wp, remaining); if (got > 0) { wp += got; m_wroteBytes += got; @@ -352,7 +352,7 @@ void VerilatedVcd::dumpHeader() { printStr("$version Generated by VerilatedVcd $end\n"); printStr("$date "); { - time_t tick = time(nullptr); + const time_t tick = time(nullptr); tm ticktm; VL_LOCALTIME_R(&tick, &ticktm); constexpr int bufsize = 50; diff --git a/include/verilated_vcd_c.h b/include/verilated_vcd_c.h index d167d3977..6eb3f1d6b 100644 --- a/include/verilated_vcd_c.h +++ b/include/verilated_vcd_c.h @@ -233,11 +233,11 @@ public: // Inside dumping routines, dump one signal if it has changed. // We do want to inline these to avoid calls when the value did not change. inline void chgBit(vluint32_t code, const vluint32_t newval) { - vluint32_t diff = oldp(code)[0] ^ newval; + const vluint32_t diff = oldp(code)[0] ^ newval; if (VL_UNLIKELY(diff)) fullBit(code, newval); } inline void chgBus(vluint32_t code, const vluint32_t newval, int bits) { - vluint32_t diff = oldp(code)[0] ^ newval; + const vluint32_t diff = oldp(code)[0] ^ newval; if (VL_UNLIKELY(diff)) { if (VL_UNLIKELY(bits == 32 || (diff & ((1U << bits) - 1)))) { fullBus(code, newval, bits); @@ -245,7 +245,7 @@ public: } } inline void chgQuad(vluint32_t code, const vluint64_t newval, int bits) { - vluint64_t diff = (*(reinterpret_cast(oldp(code)))) ^ newval; + const vluint64_t diff = (*(reinterpret_cast(oldp(code)))) ^ newval; if (VL_UNLIKELY(diff)) { if (VL_UNLIKELY(bits == 64 || (diff & ((1ULL << bits) - 1)))) { fullQuad(code, newval, bits); @@ -270,7 +270,7 @@ public: } } inline void chgTriBit(vluint32_t code, const vluint32_t newval, const vluint32_t newtri) { - vluint32_t diff = ((oldp(code)[0] ^ newval) | (oldp(code)[1] ^ newtri)); + const vluint32_t diff = ((oldp(code)[0] ^ newval) | (oldp(code)[1] ^ newtri)); if (VL_UNLIKELY(diff)) { // Verilator 3.510 and newer provide clean input, so the below // is only for back compatibility @@ -281,7 +281,7 @@ public: } inline void chgTriBus(vluint32_t code, const vluint32_t newval, const vluint32_t newtri, int bits) { - vluint32_t diff = ((oldp(code)[0] ^ newval) | (oldp(code)[1] ^ newtri)); + const vluint32_t diff = ((oldp(code)[0] ^ newval) | (oldp(code)[1] ^ newtri)); if (VL_UNLIKELY(diff)) { if (VL_UNLIKELY(bits == 32 || (diff & ((1U << bits) - 1)))) { fullTriBus(code, newval, newtri, bits); @@ -290,8 +290,8 @@ public: } inline void chgTriQuad(vluint32_t code, const vluint64_t newval, const vluint64_t newtri, int bits) { - vluint64_t diff = (((*(reinterpret_cast(oldp(code)))) ^ newval) - | ((*(reinterpret_cast(oldp(code + 1)))) ^ newtri)); + const vluint64_t diff = (((*(reinterpret_cast(oldp(code)))) ^ newval) + | ((*(reinterpret_cast(oldp(code + 1)))) ^ newtri)); if (VL_UNLIKELY(diff)) { if (VL_UNLIKELY(bits == 64 || (diff & ((1ULL << bits) - 1)))) { fullTriQuad(code, newval, newtri, bits); diff --git a/include/verilated_vcd_sc.h b/include/verilated_vcd_sc.h index 415f1911c..de6e6d943 100644 --- a/include/verilated_vcd_sc.h +++ b/include/verilated_vcd_sc.h @@ -44,9 +44,9 @@ public: // We want to avoid a depreciated warning, but still be back compatible. // Turning off the message just for this still results in an // annoying "to turn off" message. - sc_time t1sec(1, SC_SEC); + const sc_time t1sec(1, SC_SEC); if (t1sec.to_default_time_units() != 0) { - sc_time tunits(1.0 / t1sec.to_default_time_units(), SC_SEC); + const sc_time tunits(1.0 / t1sec.to_default_time_units(), SC_SEC); spTrace()->set_time_unit(tunits.to_string()); } spTrace()->set_time_resolution(sc_get_time_resolution().to_string()); diff --git a/include/verilated_vpi.cpp b/include/verilated_vpi.cpp index d0f1178b5..eb9e254a3 100644 --- a/include/verilated_vpi.cpp +++ b/include/verilated_vpi.cpp @@ -310,7 +310,7 @@ public: return dynamic_cast(reinterpret_cast(h)); } vluint32_t mask() const { return m_mask.u32; } - vluint8_t mask_byte(int idx) { return m_mask.u8[idx & 3]; } + vluint8_t mask_byte(int idx) const { return m_mask.u8[idx & 3]; } vluint32_t entSize() const { return m_entSize; } vluint32_t index() const { return m_index; } virtual vluint32_t type() const override { @@ -365,7 +365,7 @@ public: virtual vluint32_t type() const override { return vpiIterator; } virtual vpiHandle dovpi_scan() override { if (VL_LIKELY(m_scopep->varsp())) { - VerilatedVarNameMap* varsp = m_scopep->varsp(); + const VerilatedVarNameMap* const varsp = m_scopep->varsp(); if (VL_UNLIKELY(!m_started)) { m_it = varsp->begin(); m_started = true; @@ -564,7 +564,7 @@ public: } static void callTimedCbs() VL_MT_UNSAFE_ONE { assertOneCheck(); - QData time = VL_TIME_Q(); + const QData time = VL_TIME_Q(); for (auto it = s().m_timedCbs.begin(); it != s().m_timedCbs.end();) { if (VL_UNLIKELY(it->first.first <= time)) { VerilatedVpiCbHolder& ho = it->second; @@ -587,7 +587,7 @@ public: if (VL_LIKELY(it != s().m_timedCbs.cend())) return it->first.first; return ~0ULL; // maxquad } - static bool callCbs(vluint32_t reason) VL_MT_UNSAFE_ONE { + static bool callCbs(const vluint32_t reason) VL_MT_UNSAFE_ONE { VpioCbList& cbObjList = s().m_cbObjLists[reason]; bool called = false; if (cbObjList.empty()) return called; @@ -619,7 +619,7 @@ public: const auto last = std::prev(cbObjList.end()); // prevent looping over newly added elements for (auto it = cbObjList.begin(); true;) { // cbReasonRemove sets to nullptr, so we know on removal the old end() will still exist - bool was_last = it == last; + const bool was_last = it == last; if (VL_UNLIKELY(it->invalid())) { // Deleted earlier, cleanup it = cbObjList.erase(it); if (was_last) break; @@ -715,7 +715,7 @@ public: void resetError() { m_flag = false; } static void vpi_unsupported() { // Not supported yet - p_vpi_error_info error_info_p = VerilatedVpiImp::error_info()->getError(); + const p_vpi_error_info error_info_p = VerilatedVpiImp::error_info()->getError(); if (error_info_p) { VL_FATAL_MT(error_info_p->file, error_info_p->line, "", error_info_p->message); return; @@ -1300,9 +1300,9 @@ vpiHandle vpi_register_cb(p_cb_data cb_data_p) { case cbAfterDelay: { QData time = 0; if (cb_data_p->time) time = VL_SET_QII(cb_data_p->time->high, cb_data_p->time->low); - QData abstime = VL_TIME_Q() + time; + const QData abstime = VL_TIME_Q() + time; vluint64_t id = VerilatedVpiImp::nextCallbackId(); - VerilatedVpioTimedCb* vop = new VerilatedVpioTimedCb{id, abstime}; + VerilatedVpioTimedCb* const vop = new VerilatedVpioTimedCb{id, abstime}; VerilatedVpiImp::cbTimedAdd(id, cb_data_p, abstime); return vop->castVpiHandle(); } @@ -1316,8 +1316,8 @@ vpiHandle vpi_register_cb(p_cb_data cb_data_p) { case cbEnterInteractive: // FALLTHRU // NOP, but need to return handle, so make object case cbExitInteractive: // FALLTHRU // NOP, but need to return handle, so make object case cbInteractiveScopeChange: { // FALLTHRU // NOP, but need to return handle, so make object - vluint64_t id = VerilatedVpiImp::nextCallbackId(); - VerilatedVpioReasonCb* vop = new VerilatedVpioReasonCb{id, cb_data_p->reason}; + const vluint64_t id = VerilatedVpiImp::nextCallbackId(); + VerilatedVpioReasonCb* const vop = new VerilatedVpioReasonCb{id, cb_data_p->reason}; VerilatedVpiImp::cbReasonAdd(id, cb_data_p); return vop->castVpiHandle(); } @@ -1332,7 +1332,7 @@ PLI_INT32 vpi_remove_cb(vpiHandle cb_obj) { VL_DEBUG_IF_PLI(VL_DBG_MSGF("- vpi: vpi_remove_cb %p\n", cb_obj);); VerilatedVpiImp::assertOneCheck(); VL_VPI_ERROR_RESET_(); - VerilatedVpio* vop = VerilatedVpio::castp(cb_obj); + VerilatedVpio* const vop = VerilatedVpio::castp(cb_obj); if (VL_UNLIKELY(!vop)) return 0; return vop->dovpi_remove_cb(); } @@ -1355,7 +1355,7 @@ vpiHandle vpi_handle_by_name(PLI_BYTE8* namep, vpiHandle scope) { VL_DEBUG_IF_PLI(VL_DBG_MSGF("- vpi: vpi_handle_by_name %s %p\n", namep, scope);); const VerilatedVar* varp = nullptr; const VerilatedScope* scopep; - VerilatedVpioScope* voScopep = VerilatedVpioScope::castp(scope); + const VerilatedVpioScope* const voScopep = VerilatedVpioScope::castp(scope); std::string scopeAndName = namep; if (voScopep) { scopeAndName = std::string(voScopep->fullname()) + "." + namep; @@ -1373,7 +1373,7 @@ vpiHandle vpi_handle_by_name(PLI_BYTE8* namep, vpiHandle scope) { } const char* baseNamep = scopeAndName.c_str(); std::string scopename; - const char* dotp = std::strrchr(namep, '.'); + const char* const dotp = std::strrchr(namep, '.'); if (VL_LIKELY(dotp)) { baseNamep = dotp + 1; scopename = std::string(namep, dotp - namep); @@ -1407,7 +1407,7 @@ vpiHandle vpi_handle_by_index(vpiHandle object, PLI_INT32 indx) { // Memory words are not indexable VerilatedVpioMemoryWord* vop = VerilatedVpioMemoryWord::castp(object); if (VL_UNLIKELY(vop)) return nullptr; - VerilatedVpioVar* varop = VerilatedVpioVar::castp(object); + const VerilatedVpioVar* const varop = VerilatedVpioVar::castp(object); if (VL_LIKELY(varop)) { if (varop->varp()->dims() < 2) return nullptr; if (VL_LIKELY(varop->varp()->unpacked().left() >= varop->varp()->unpacked().right())) { @@ -1496,7 +1496,7 @@ vpiHandle vpi_iterate(PLI_INT32 type, vpiHandle object) { VL_VPI_ERROR_RESET_(); switch (type) { case vpiMemoryWord: { - VerilatedVpioVar* vop = VerilatedVpioVar::castp(object); + const VerilatedVpioVar* const vop = VerilatedVpioVar::castp(object); if (VL_UNLIKELY(!vop)) return nullptr; if (vop->varp()->dims() < 2) return nullptr; if (vop->varp()->dims() > 2) { @@ -1508,7 +1508,7 @@ vpiHandle vpi_iterate(PLI_INT32 type, vpiHandle object) { return (new VerilatedVpioMemoryWordIter(object, vop->varp()))->castVpiHandle(); } case vpiRange: { - VerilatedVpioVar* vop = VerilatedVpioVar::castp(object); + const VerilatedVpioVar* const vop = VerilatedVpioVar::castp(object); if (VL_UNLIKELY(!vop)) return nullptr; if (vop->varp()->dims() < 2) return nullptr; // Unsupported is multidim list @@ -1521,15 +1521,15 @@ vpiHandle vpi_iterate(PLI_INT32 type, vpiHandle object) { return ((new VerilatedVpioRangeIter(vop->rangep()))->castVpiHandle()); } case vpiReg: { - VerilatedVpioScope* vop = VerilatedVpioScope::castp(object); + const VerilatedVpioScope* const vop = VerilatedVpioScope::castp(object); if (VL_UNLIKELY(!vop)) return nullptr; return ((new VerilatedVpioVarIter(vop->scopep()))->castVpiHandle()); } case vpiModule: { - VerilatedVpioModule* vop = VerilatedVpioModule::castp(object); - const VerilatedHierarchyMap* map = VerilatedImp::hierarchyMap(); - const VerilatedScope* mod = vop ? vop->scopep() : nullptr; - const auto it = vlstd::as_const(map)->find(const_cast(mod)); + const VerilatedVpioModule* const vop = VerilatedVpioModule::castp(object); + const VerilatedHierarchyMap* const map = VerilatedImp::hierarchyMap(); + const VerilatedScope* const modp = vop ? vop->scopep() : nullptr; + const auto it = vlstd::as_const(map)->find(const_cast(modp)); if (it == map->end()) return nullptr; return ((new VerilatedVpioModuleIter(it->second))->castVpiHandle()); } @@ -1560,30 +1560,30 @@ PLI_INT32 vpi_get(PLI_INT32 property, vpiHandle object) { return Verilated::threadContextp()->timeprecision(); } case vpiTimeUnit: { - VerilatedVpioScope* vop = VerilatedVpioScope::castp(object); + const VerilatedVpioScope* const vop = VerilatedVpioScope::castp(object); if (!vop) return Verilated::threadContextp()->timeunit(); // Null asks for global, not unlikely return vop->scopep()->timeunit(); } case vpiType: { - VerilatedVpio* vop = VerilatedVpio::castp(object); + const VerilatedVpio* const vop = VerilatedVpio::castp(object); if (VL_UNLIKELY(!vop)) return 0; return vop->type(); } case vpiDirection: { // By forthought, the directions already are vpi enumerated - VerilatedVpioVarBase* vop = VerilatedVpioVarBase::castp(object); + const VerilatedVpioVarBase* const vop = VerilatedVpioVarBase::castp(object); if (VL_UNLIKELY(!vop)) return 0; return vop->varp()->vldir(); } case vpiScalar: // FALLTHRU case vpiVector: { - VerilatedVpioVarBase* vop = VerilatedVpioVarBase::castp(object); + const VerilatedVpioVarBase* const vop = VerilatedVpioVarBase::castp(object); if (VL_UNLIKELY(!vop)) return 0; return (property == vpiVector) ^ (vop->varp()->dims() == 0); } case vpiSize: { - VerilatedVpioVarBase* vop = VerilatedVpioVarBase::castp(object); + const VerilatedVpioVarBase* const vop = VerilatedVpioVarBase::castp(object); if (VL_UNLIKELY(!vop)) return 0; return vop->size(); } @@ -1602,7 +1602,7 @@ PLI_INT64 vpi_get64(PLI_INT32 /*property*/, vpiHandle /*object*/) { PLI_BYTE8* vpi_get_str(PLI_INT32 property, vpiHandle object) { VL_DEBUG_IF_PLI(VL_DBG_MSGF("- vpi: vpi_get_str %d %p\n", property, object);); VerilatedVpiImp::assertOneCheck(); - VerilatedVpio* vop = VerilatedVpio::castp(object); + const VerilatedVpio* const vop = VerilatedVpio::castp(object); VL_VPI_ERROR_RESET_(); if (VL_UNLIKELY(!vop)) return nullptr; switch (property) { @@ -1725,7 +1725,7 @@ void vl_get_value(const VerilatedVar* varp, void* varDatap, p_vpi_value valuep, __FILE__, __LINE__, "", "vpi_get_value with more than VL_MULS_MAX_WORDS; increase and recompile"); } - WDataInP datap = (reinterpret_cast(varDatap)); + const WDataInP datap = (reinterpret_cast(varDatap)); for (int i = 0; i < words; ++i) { t_out[i].aval = datap[i]; t_out[i].bval = 0; @@ -1756,7 +1756,7 @@ void vl_get_value(const VerilatedVar* varp, void* varDatap, p_vpi_value valuep, } else if (valuep->format == vpiOctStrVal) { valuep->value.str = t_outStr; int chars = (varp->packed().elements() + 2) / 3; - int bytes = VL_BYTES_I(varp->packed().elements()); + const int bytes = VL_BYTES_I(varp->packed().elements()); CData* datap = (reinterpret_cast(varDatap)); int i; if (chars > t_outStrSz) { @@ -1770,7 +1770,7 @@ void vl_get_value(const VerilatedVar* varp, void* varDatap, p_vpi_value valuep, chars = t_outStrSz; } for (i = 0; i < chars; ++i) { - div_t idx = div(i * 3, 8); + const div_t idx = div(i * 3, 8); int val = datap[idx.quot]; if ((idx.quot + 1) < bytes) { // if the next byte is valid or that in @@ -1832,7 +1832,7 @@ void vl_get_value(const VerilatedVar* varp, void* varDatap, p_vpi_value valuep, if (i == (chars - 1)) { // most signifcant char, mask off non existant bits when vector // size is not a multiple of 4 - unsigned int rem = varp->packed().elements() & 3; + const unsigned int rem = varp->packed().elements() & 3; if (rem) { // generate bit mask & zero non existant bits val &= (1 << rem) - 1; @@ -1862,7 +1862,7 @@ void vl_get_value(const VerilatedVar* varp, void* varDatap, p_vpi_value valuep, bytes = t_outStrSz; } for (i = 0; i < bytes; ++i) { - char val = datap[bytes - i - 1]; + const char val = datap[bytes - i - 1]; // other simulators replace [leading?] zero chars with spaces, replicate here. t_outStr[i] = val ? val : ' '; } @@ -1896,7 +1896,7 @@ void vpi_get_value(vpiHandle object, p_vpi_value valuep) { if (VerilatedVpioVar* vop = VerilatedVpioVar::castp(object)) { vl_get_value(vop->varp(), vop->varDatap(), valuep, vop->fullname()); return; - } else if (VerilatedVpioParam* vop = VerilatedVpioParam::castp(object)) { + } else if (const VerilatedVpioParam* const vop = VerilatedVpioParam::castp(object)) { vl_get_value(vop->varp(), vop->varDatap(), valuep, vop->fullname()); return; } else if (VerilatedVpioConst* vop = VerilatedVpioConst::castp(object)) { @@ -1920,7 +1920,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_ VL_VPI_WARNING_(__FILE__, __LINE__, "Ignoring vpi_put_value with nullptr value pointer"); return nullptr; } - if (VerilatedVpioVar* vop = VerilatedVpioVar::castp(object)) { + if (const VerilatedVpioVar* const vop = VerilatedVpioVar::castp(object)) { VL_DEBUG_IF_PLI( VL_DBG_MSGF("- vpi: vpi_put_value name=%s fmt=%d vali=%d\n", vop->fullname(), valuep->format, valuep->value.integer); @@ -1953,7 +1953,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_ valuep->value.vector[1].aval & vop->mask(), valuep->value.vector[0].aval); return object; } else if (vop->varp()->vltype() == VLVT_WDATA) { - int words = VL_WORDS_I(vop->varp()->packed().elements()); + const int words = VL_WORDS_I(vop->varp()->packed().elements()); WDataOutP datap = (reinterpret_cast(vop->varDatap())); for (int i = 0; i < words; ++i) { datap[i] = valuep->value.vector[i].aval; @@ -1962,8 +1962,8 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_ return object; } } else if (valuep->format == vpiBinStrVal) { - int bits = vop->varp()->packed().elements(); - int len = std::strlen(valuep->value.str); + const int bits = vop->varp()->packed().elements(); + const int len = std::strlen(valuep->value.str); CData* datap = (reinterpret_cast(vop->varDatap())); for (int i = 0; i < bits; ++i) { char set = (i < len) ? (valuep->value.str[len - i - 1] == '1') : 0; @@ -1977,9 +1977,9 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_ } return object; } else if (valuep->format == vpiOctStrVal) { - int chars = (vop->varp()->packed().elements() + 2) / 3; - int bytes = VL_BYTES_I(vop->varp()->packed().elements()); - int len = std::strlen(valuep->value.str); + const int chars = (vop->varp()->packed().elements() + 2) / 3; + const int bytes = VL_BYTES_I(vop->varp()->packed().elements()); + const int len = std::strlen(valuep->value.str); CData* datap = (reinterpret_cast(vop->varDatap())); div_t idx; datap[0] = 0; // reset zero'th byte @@ -2029,7 +2029,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_ } else if (valuep->format == vpiDecStrVal) { char remainder[16]; unsigned long long val; - int success = std::sscanf(valuep->value.str, "%30llu%15s", &val, remainder); + const int success = std::sscanf(valuep->value.str, "%30llu%15s", &val, remainder); if (success < 1) { VL_VPI_ERROR_(__FILE__, __LINE__, "%s: Parsing failed for '%s' as value %s for %s", __func__, valuep->value.str, @@ -2057,12 +2057,12 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_ return object; } } else if (valuep->format == vpiHexStrVal) { - int chars = (vop->varp()->packed().elements() + 3) >> 2; + const int chars = (vop->varp()->packed().elements() + 3) >> 2; CData* datap = (reinterpret_cast(vop->varDatap())); char* val = valuep->value.str; // skip hex ident if one is detected at the start of the string if (val[0] == '0' && (val[1] == 'x' || val[1] == 'X')) val += 2; - int len = std::strlen(val); + const int len = std::strlen(val); for (int i = 0; i < chars; ++i) { char hex; // compute hex digit value @@ -2097,8 +2097,8 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_ datap[(chars - 1) >> 1] &= vop->mask_byte((chars - 1) >> 1); return object; } else if (valuep->format == vpiStringVal) { - int bytes = VL_BYTES_I(vop->varp()->packed().elements()); - int len = std::strlen(valuep->value.str); + const int bytes = VL_BYTES_I(vop->varp()->packed().elements()); + const int len = std::strlen(valuep->value.str); CData* datap = (reinterpret_cast(vop->varDatap())); for (int i = 0; i < bytes; ++i) { // prepend with 0 values before placing string the least significant bytes @@ -2120,11 +2120,11 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_ VL_VPI_ERROR_(__FILE__, __LINE__, "%s: Unsupported format (%s) as requested for %s", __func__, VerilatedVpiError::strFromVpiVal(valuep->format), vop->fullname()); return nullptr; - } else if (VerilatedVpioParam* vop = VerilatedVpioParam::castp(object)) { + } else if (const VerilatedVpioParam* const vop = VerilatedVpioParam::castp(object)) { VL_VPI_WARNING_(__FILE__, __LINE__, "%s: Ignoring vpi_put_value to vpiParameter: %s", __func__, vop->fullname()); return nullptr; - } else if (VerilatedVpioConst* vop = VerilatedVpioConst::castp(object)) { + } else if (const VerilatedVpioConst* const vop = VerilatedVpioConst::castp(object)) { VL_VPI_WARNING_(__FILE__, __LINE__, "%s: Ignoring vpi_put_value to vpiConstant: %s", __func__, vop->fullname()); return nullptr; @@ -2153,7 +2153,7 @@ void vpi_get_time(vpiHandle object, p_vpi_time time_p) { return; } if (time_p->type == vpiSimTime) { - QData qtime = VL_TIME_Q(); + const QData qtime = VL_TIME_Q(); VlWide<2> itime; VL_SET_WQ(itime, qtime); time_p->low = itime[0]; @@ -2162,9 +2162,9 @@ void vpi_get_time(vpiHandle object, p_vpi_time time_p) { } else if (time_p->type == vpiScaledRealTime) { double dtime = VL_TIME_D(); if (VerilatedVpioScope* vop = VerilatedVpioScope::castp(object)) { - int scalePow10 + const int scalePow10 = Verilated::threadContextp()->timeprecision() - vop->scopep()->timeunit(); - double scale = vl_time_multiplier(scalePow10); // e.g. 0.0001 + const double scale = vl_time_multiplier(scalePow10); // e.g. 0.0001 dtime *= scale; } time_p->real = dtime; @@ -2198,7 +2198,7 @@ PLI_INT32 vpi_mcd_printf(PLI_UINT32 mcd, PLI_BYTE8* formatp, ...) { VL_VPI_ERROR_RESET_(); va_list ap; va_start(ap, formatp); - int chars = vpi_mcd_vprintf(mcd, formatp, ap); + const int chars = vpi_mcd_vprintf(mcd, formatp, ap); va_end(ap); return chars; } @@ -2208,7 +2208,7 @@ PLI_INT32 vpi_printf(PLI_BYTE8* formatp, ...) { VL_VPI_ERROR_RESET_(); va_list ap; va_start(ap, formatp); - int chars = vpi_vprintf(formatp, ap); + const int chars = vpi_vprintf(formatp, ap); va_end(ap); return chars; } @@ -2221,11 +2221,11 @@ PLI_INT32 vpi_vprintf(PLI_BYTE8* formatp, va_list ap) { PLI_INT32 vpi_mcd_vprintf(PLI_UINT32 mcd, PLI_BYTE8* format, va_list ap) { VerilatedVpiImp::assertOneCheck(); - FILE* fp = VL_CVT_I_FP(mcd); + FILE* const fp = VL_CVT_I_FP(mcd); VL_VPI_ERROR_RESET_(); // cppcheck-suppress nullPointer if (VL_UNLIKELY(!fp)) return 0; - int chars = vfprintf(fp, format, ap); + const int chars = vfprintf(fp, format, ap); return chars; } @@ -2238,7 +2238,7 @@ PLI_INT32 vpi_flush(void) { PLI_INT32 vpi_mcd_flush(PLI_UINT32 mcd) { VerilatedVpiImp::assertOneCheck(); - FILE* fp = VL_CVT_I_FP(mcd); + FILE* const fp = VL_CVT_I_FP(mcd); VL_VPI_ERROR_RESET_(); if (VL_UNLIKELY(!fp)) return 1; std::fflush(fp); @@ -2255,7 +2255,7 @@ PLI_INT32 vpi_chk_error(p_vpi_error_info error_info_p) { // executing vpi_chk_error does not reset error // error_info_p can be nullptr, so only return level in that case VerilatedVpiImp::assertOneCheck(); - p_vpi_error_info _error_info_p = VerilatedVpiImp::error_info()->getError(); + p_vpi_error_info const _error_info_p = VerilatedVpiImp::error_info()->getError(); if (error_info_p && _error_info_p) *error_info_p = *_error_info_p; if (!_error_info_p) return 0; // no error occured return _error_info_p->level; // return error severity level diff --git a/include/verilated_vpi.h b/include/verilated_vpi.h index 1d1e9d4ce..9f8f8f90d 100644 --- a/include/verilated_vpi.h +++ b/include/verilated_vpi.h @@ -47,7 +47,7 @@ public: static bool callValueCbs() VL_MT_UNSAFE_ONE; /// Call callbacks of arbitrary types. /// User wrapper code should call this from their main loops. - static bool callCbs(vluint32_t reason) VL_MT_UNSAFE_ONE; + static bool callCbs(const vluint32_t reason) VL_MT_UNSAFE_ONE; /// Returns time of the next registered VPI callback, or /// ~(0ULL) if none are registered static QData cbNextDeadline() VL_MT_UNSAFE_ONE;