From e40fbf14700bc7f9e031c54c6a32572585471b78 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 3 Feb 2010 06:52:02 -0500 Subject: [PATCH] Verilated: Add missing VL_UNLIKELYs --- include/verilated.cpp | 4 ++-- include/verilated.h | 24 ++++++++++++------------ include/verilated_vcd_c.cpp | 10 +++++----- include/verilated_vcd_c.h | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/include/verilated.cpp b/include/verilated.cpp index 79a5691f3..d55ae1de6 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -775,7 +775,7 @@ void VL_READMEM_W(bool hex, int width, int depth, int array_lsb, int fnwords, char ofilenamez[VL_TO_STRING_MAX_WORDS*VL_WORDSIZE+1]; _VL_VINT_TO_STRING(fnwords*VL_WORDSIZE, ofilenamez, ofilenamep); FILE* fp = fopen(ofilenamez, "r"); - if (!fp) { + if (VL_UNLIKELY(!fp)) { // We don't report the Verilog source filename as it slow to have to pass it down vl_fatal (ofilenamez, 0, "", "$readmem file not found"); return; @@ -794,7 +794,7 @@ void VL_READMEM_W(bool hex, int width, int depth, int array_lsb, int fnwords, // with changing buffer sizes dynamically, etc. while (1) { int c = fgetc(fp); - if (c==EOF) break; + if (VL_UNLIKELY(c==EOF)) break; //printf("%d: Got '%c' Addr%x IN%d IgE%d IgC%d ninc%d\n", linenum, c, addr, innum, ignore_to_eol, ignore_to_cmt, needinc); if (c=='\n') { linenum++; ignore_to_eol=false; if (innum) reading_addr=false; innum=false; } else if (c=='\t' || c==' ' || c=='\r' || c=='\f') { if (innum) reading_addr=false; innum=false; } diff --git a/include/verilated.h b/include/verilated.h index 803c09305..5db146d20 100644 --- a/include/verilated.h +++ b/include/verilated.h @@ -685,14 +685,14 @@ static inline IData VL_ONEHOT0_W(int words, WDataInP lwp) { static inline IData VL_CLOG2_I(IData lhs) { // There are faster algorithms, or fls GCC4 builtins, but rarely used - if (!lhs) return 0; + if (VL_UNLIKELY(!lhs)) return 0; lhs--; int shifts=0; for (; lhs!=0; shifts++) lhs = lhs >> 1; return shifts; } static inline IData VL_CLOG2_Q(QData lhs) { - if (!lhs) return 0; + if (VL_UNLIKELY(!lhs)) return 0; lhs--; int shifts=0; for (; lhs!=0; shifts++) lhs = lhs >> VL_ULL(1); @@ -976,25 +976,25 @@ static inline WDataOutP VL_MULS_WWW(int,int lbits,int, WDataOutP owp,WDataInP lw } static inline IData VL_DIVS_III(int lbits, IData lhs,IData rhs) { - if (rhs==0) return 0; + if (VL_UNLIKELY(rhs==0)) return 0; vlsint32_t lhs_signed = VL_EXTENDS_II(32, lbits, lhs); vlsint32_t rhs_signed = VL_EXTENDS_II(32, lbits, rhs); return lhs_signed / rhs_signed; } static inline QData VL_DIVS_QQQ(int lbits, QData lhs,QData rhs) { - if (rhs==0) return 0; + if (VL_UNLIKELY(rhs==0)) return 0; vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); return lhs_signed / rhs_signed; } static inline IData VL_MODDIVS_III(int lbits, IData lhs,IData rhs) { - if (rhs==0) return 0; + if (VL_UNLIKELY(rhs==0)) return 0; vlsint32_t lhs_signed = VL_EXTENDS_II(32, lbits, lhs); vlsint32_t rhs_signed = VL_EXTENDS_II(32, lbits, rhs); return lhs_signed % rhs_signed; } static inline QData VL_MODDIVS_QQQ(int lbits, QData lhs,QData rhs) { - if (rhs==0) return 0; + if (VL_UNLIKELY(rhs==0)) return 0; vlsint64_t lhs_signed = VL_EXTENDS_QQ(64, lbits, lhs); vlsint64_t rhs_signed = VL_EXTENDS_QQ(64, lbits, rhs); return lhs_signed % rhs_signed; @@ -1040,7 +1040,7 @@ static inline WDataOutP VL_MODDIVS_WWW(int lbits, WDataOutP owp,WDataInP lwp,WDa } static inline IData VL_POW_III(int, int, int rbits, IData lhs, IData rhs) { - if (lhs==0) return 0; + if (VL_UNLIKELY(lhs==0)) return 0; IData power = lhs; IData out = 1; for (int i=0; ilbits) { + if (VL_UNLIKELY((int)rd>lbits)) { return ~0; // Spec says you can go outside the range of a array. Don't coredump if so. // We return all 1's as that's more likely to find bugs (?) than 0's. } else { @@ -1399,7 +1399,7 @@ static inline IData VL_BITSEL_IWII(int, int lbits, int, int, WDataInP lwp, IData static inline IData VL_SEL_IWII(int, int lbits, int, int, WDataInP lwp, IData lsb, IData width) { int msb = lsb+width-1; - if (msb>lbits) { + 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_I(msb)==VL_BITWORD_I((int)lsb)) { return (lwp[VL_BITWORD_I(lsb)]>>VL_BITBIT_I(lsb)); @@ -1413,7 +1413,7 @@ 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, IData width) { int msb = lsb+width-1; - if (msb>lbits) { + 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_I(msb)==VL_BITWORD_I((int)lsb)) { return (lwp[VL_BITWORD_I(lsb)]>>VL_BITBIT_I(lsb)); @@ -1435,7 +1435,7 @@ static inline QData VL_SEL_QWII(int, int lbits, int, int, WDataInP lwp, IData ls static inline WDataOutP VL_SEL_WWII(int obits,int lbits,int,int,WDataOutP owp,WDataInP lwp, IData lsb, IData width) { int msb = lsb+width-1; int word_shift = VL_BITWORD_I(lsb); - if (msb>lbits) { // Outside bounds, + if (VL_UNLIKELY(msb>lbits)) { // Outside bounds, for (int i=0; i this->m_rolloverMB) { + if (VL_UNLIKELY(m_rolloverMB && m_wroteBytes > this->m_rolloverMB)) { openNext(true); if (!isOpen()) return; } diff --git a/include/verilated_vcd_c.h b/include/verilated_vcd_c.h index a552dbe39..60c3aa3a0 100644 --- a/include/verilated_vcd_c.h +++ b/include/verilated_vcd_c.h @@ -92,7 +92,7 @@ private: void bufferCheck() { // Flush the write buffer if there's not enough space left for new information // We only call this once per vector, so we need enough slop for a very wide "b###" line - if (m_writep > (m_wrBufp+(bufferSize()-bufferInsertSize()))) { + if (VL_UNLIKELY(m_writep > (m_wrBufp+(bufferSize()-bufferInsertSize())))) { bufferFlush(); } }