V0.8: do signed comparisons and fix verinum < and <=

This patch fixes the verinum < and <= operators to directly
compare the long result not the difference. Because of overflow
the difference can give an incorrect value. Using a long value
is technically wrong, but that will need to be a different
patch. It also fixes the eval_leeq_() routine to correctly build
the largest value in a signed comparison.
This commit is contained in:
Cary R 2008-08-22 17:31:16 -07:00 committed by Stephen Williams
parent e89bce48ed
commit 5e401055e8
2 changed files with 7 additions and 5 deletions

View File

@ -363,11 +363,15 @@ NetEConst* NetEBComp::eval_leeq_()
cerr << get_line() << ": : " << *this << endl;
}
/* Detect the case where the right side is greater that or
/* Detect the case where the right side is greater than or
equal to the largest value the left side can possibly
have. */
assert(left_->expr_width() > 0);
verinum lv (verinum::V1, left_->expr_width() + 1);
if (left_->has_sign() && rv.has_sign()) {
lv.set(lv.len()-1, verinum::V0);
lv.has_sign(true);
}
lv.set(left_->expr_width(), verinum::V0);
lv.has_sign( left_->has_sign() );
if (lv <= rv) {

View File

@ -493,8 +493,7 @@ verinum::V operator <= (const verinum&left, const verinum&right)
return verinum::Vx;
if (!right.is_defined())
return verinum::Vx;
long diff = left.as_long() - right.as_long();
if (diff <= 0)
if (left.as_long() <= right.as_long())
return verinum::V1;
else
return verinum::V0;
@ -532,8 +531,7 @@ verinum::V operator < (const verinum&left, const verinum&right)
return verinum::Vx;
if (!right.is_defined())
return verinum::Vx;
long diff = left.as_long() - right.as_long();
if (diff < 0)
if (left.as_long() < right.as_long())
return verinum::V1;
else
return verinum::V0;