Verilated: Add missing VL_UNLIKELYs

This commit is contained in:
Wilson Snyder 2010-02-03 06:52:02 -05:00
parent 56a03e1a10
commit e40fbf1470
4 changed files with 20 additions and 20 deletions

View File

@ -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; }

View File

@ -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; i<rbits; i++) {
@ -1053,7 +1053,7 @@ static inline IData VL_POW_III(int, int, int rbits, IData lhs, IData rhs) {
#define VL_POW_QQI(obits,lbits,rbits,lhs,rhs) VL_POW_QQQ(obits,lbits,rbits,lhs,rhs)
static inline QData VL_POW_QQQ(int, int, int rbits, QData lhs, QData rhs) {
if (lhs==0) return 0;
if (VL_UNLIKELY(lhs==0)) return 0;
QData power = lhs;
QData out = VL_ULL(1);
for (int i=0; i<rbits; i++) {
@ -1383,7 +1383,7 @@ static inline WDataOutP VL_SHIFTRS_WWI(int obits,int,int,WDataOutP owp,WDataInP
static inline IData VL_BITSEL_IWII(int, int lbits, int, int, WDataInP lwp, IData rd) {
int word = VL_BITWORD_I(rd);
if ((int)rd>lbits) {
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<VL_WORDS_I(obits)-1; i++) owp[i] = ~0;
owp[VL_WORDS_I(obits)-1] = VL_MASK_I(obits);
} else if (VL_BITBIT_I(lsb)==0) {

View File

@ -203,7 +203,7 @@ void VerilatedVcd::printQuad (vluint64_t n) {
void VerilatedVcd::printTime (vluint64_t timeui) {
// VCD file format specification does not allow non-integers for timestamps
// Dinotrace doesn't mind, but Cadence vvision seems to choke
if (timeui < m_timeLastDump) {
if (VL_UNLIKELY(timeui < m_timeLastDump)) {
timeui = m_timeLastDump;
static bool backTime = false;
if (!backTime) {
@ -219,7 +219,7 @@ void VerilatedVcd::bufferFlush () {
// We add output data to m_writep.
// When it gets nearly full we dump it using this routine which calls write()
// This is much faster than using buffered I/O
if (!isOpen()) return;
if (VL_UNLIKELY(!isOpen())) return;
char* wp = m_wrBufp;
while (1) {
size_t remaining = (m_writep - wp);
@ -502,7 +502,7 @@ void VerilatedVcd::addCallback (
VerilatedVcdCallback_t initcb, VerilatedVcdCallback_t fullcb, VerilatedVcdCallback_t changecb,
void* userthis)
{
if (isOpen()) {
if (VL_UNLIKELY(isOpen())) {
string msg = (string)"Internal: "+__FILE__+"::"+__FUNCTION__+" called with already open file";
vl_fatal(__FILE__,__LINE__,"",msg.c_str());
}
@ -524,12 +524,12 @@ void VerilatedVcd::dumpFull (vluint64_t timeui) {
void VerilatedVcd::dump (vluint64_t timeui) {
if (!isOpen()) return;
if (m_fullDump) {
if (VL_UNLIKELY(m_fullDump)) {
m_fullDump = false; // No need for more full dumps
dumpFull(timeui);
return;
}
if (m_rolloverMB && m_wroteBytes > this->m_rolloverMB) {
if (VL_UNLIKELY(m_rolloverMB && m_wroteBytes > this->m_rolloverMB)) {
openNext(true);
if (!isOpen()) return;
}

View File

@ -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();
}
}