Fix compile time eval of <= comparison.

This commit is contained in:
steve 2007-03-23 23:02:31 +00:00
parent 07daee9438
commit 9e9d5ccfdd
2 changed files with 23 additions and 3 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: eval_tree.cc,v 1.62.2.4 2007/03/23 20:59:25 steve Exp $"
#ident "$Id: eval_tree.cc,v 1.62.2.5 2007/03/23 23:02:31 steve Exp $"
#endif
# include "config.h"
@ -367,7 +367,9 @@ NetEConst* NetEBComp::eval_leeq_()
equal to the largest value the left side can possibly
have. */
assert(left_->expr_width() > 0);
verinum lv (verinum::V1, left_->expr_width());
verinum lv (verinum::V1, left_->expr_width() + 1);
lv.set(left_->expr_width(), verinum::V0);
lv.has_sign( left_->has_sign() );
if (lv <= rv) {
verinum result(verinum::V1, 1);
return new NetEConst(result);
@ -1551,6 +1553,9 @@ NetEConst* NetEUReduce::eval_tree()
/*
* $Log: eval_tree.cc,v $
* Revision 1.62.2.5 2007/03/23 23:02:31 steve
* Fix compile time eval of <= comparison.
*
* Revision 1.62.2.4 2007/03/23 20:59:25 steve
* Fix compile time evaluation of < operator.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: verinum.cc,v 1.43.2.3 2007/03/23 20:59:26 steve Exp $"
#ident "$Id: verinum.cc,v 1.43.2.4 2007/03/23 23:02:31 steve Exp $"
#endif
# include "config.h"
@ -488,6 +488,18 @@ verinum::V operator == (const verinum&left, const verinum&right)
verinum::V operator <= (const verinum&left, const verinum&right)
{
if (left.has_sign() && right.has_sign()) {
if (!left.is_defined())
return verinum::Vx;
if (!right.is_defined())
return verinum::Vx;
long diff = left.as_long() - right.as_long();
if (diff <= 0)
return verinum::V1;
else
return verinum::V0;
}
unsigned idx;
for (idx = left.len() ; idx > right.len() ; idx -= 1) {
if (left[idx-1] != verinum::V0) return verinum::V0;
@ -986,6 +998,9 @@ verinum::V operator ^ (verinum::V l, verinum::V r)
/*
* $Log: verinum.cc,v $
* Revision 1.43.2.4 2007/03/23 23:02:31 steve
* Fix compile time eval of <= comparison.
*
* Revision 1.43.2.3 2007/03/23 20:59:26 steve
* Fix compile time evaluation of < operator.
*