Fix trimming of unsigned verinum values.

Incorrect trimming of unsigned verinum values was causing the
compilers unsigned constant verinum pow function to give
incorrect results. This patch restores the pow compile time
optimization and fixes the trimming to always leave a single
zero in the MSB.
This commit is contained in:
Cary R 2008-02-05 15:05:02 -08:00 committed by Stephen Williams
parent e82293c981
commit 4cf8920e48
2 changed files with 10 additions and 12 deletions

View File

@ -979,12 +979,7 @@ NetExpr* NetEBPow::eval_tree(int prune_to_width)
verinum lval = lc->value();
verinum rval = rc->value();
if (lc->has_sign() || rc->has_sign()) {
return new NetEConst( pow(lval,rval) );
} else {
return 0; // For now force this to the runtime.
}
return new NetEConst( pow(lval,rval) );
}
/*

View File

@ -496,11 +496,15 @@ verinum trim_vnum(const verinum&that)
} else {
/* If the result is unsigned and has an indefinite
length, then trim off leading zeros. */
tlen = 1;
for (unsigned idx = tlen ; idx < that.len() ; idx += 1)
if (that.get(idx) != verinum::V0)
tlen = idx+1;
length, then trim off all but one leading zero. */
unsigned top = that.len()-1;
while ((top > 0) && (that.get(top) == verinum::V0))
top -= 1;
tlen = top+2;
/* This can only happen when the verinum is all zeros,
so make it a single bit wide. */
if (that.get(top) == verinum::V0) tlen -= 1;
}
@ -1211,4 +1215,3 @@ verinum::V operator ^ (verinum::V l, verinum::V r)
return verinum::Vx;
}