From 07daee94386985ee3bff02789cae1695a77a72c4 Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 23 Mar 2007 20:59:25 +0000 Subject: [PATCH] Fix compile time evaluation of < operator. --- eval_tree.cc | 11 ++++++++--- verinum.cc | 31 ++++++++++++++++++++++++++++++- verinum.h | 6 +++++- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/eval_tree.cc b/eval_tree.cc index a12965bac..670d17940 100644 --- a/eval_tree.cc +++ b/eval_tree.cc @@ -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.3 2005/09/09 02:17:08 steve Exp $" +#ident "$Id: eval_tree.cc,v 1.62.2.4 2007/03/23 20:59:25 steve Exp $" #endif # include "config.h" @@ -243,8 +243,10 @@ NetEConst* NetEBComp::eval_less_() equal to the largest value the left side can possibly have. */ assert(left_->expr_width() > 0); - verinum lv (verinum::V1, left_->expr_width()); - if (lv < rv) { + 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::V1) { verinum result(verinum::V1, 1); return new NetEConst(result); } @@ -1549,6 +1551,9 @@ NetEConst* NetEUReduce::eval_tree() /* * $Log: eval_tree.cc,v $ + * Revision 1.62.2.4 2007/03/23 20:59:25 steve + * Fix compile time evaluation of < operator. + * * Revision 1.62.2.3 2005/09/09 02:17:08 steve * Evaluate magnitude compare with real operands. * diff --git a/verinum.cc b/verinum.cc index 262875183..043010ed5 100644 --- a/verinum.cc +++ b/verinum.cc @@ -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.2 2005/12/07 03:28:44 steve Exp $" +#ident "$Id: verinum.cc,v 1.43.2.3 2007/03/23 20:59:26 steve Exp $" #endif # include "config.h" @@ -317,6 +317,20 @@ bool verinum::is_zero() const return true; } +bool verinum::is_negative() const +{ + if (! has_sign_) + return false; + + if (nbits_ == 0) + return false; + + if (bits_[nbits_-1] == verinum::V1) + return true; + + return false; +} + /* * This function returns a version of the verinum that has only as * many bits as are needed to accurately represent the value. It takes @@ -501,6 +515,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; @@ -960,6 +986,9 @@ verinum::V operator ^ (verinum::V l, verinum::V r) /* * $Log: verinum.cc,v $ + * Revision 1.43.2.3 2007/03/23 20:59:26 steve + * Fix compile time evaluation of < operator. + * * Revision 1.43.2.2 2005/12/07 03:28:44 steve * Support constant concatenation of constants. * diff --git a/verinum.h b/verinum.h index 40b095ced..274377a2f 100644 --- a/verinum.h +++ b/verinum.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: verinum.h,v 1.26.2.3 2005/12/07 03:28:45 steve Exp $" +#ident "$Id: verinum.h,v 1.26.2.4 2007/03/23 20:59:26 steve Exp $" #endif # include @@ -74,6 +74,7 @@ class verinum { // A number is "defined" if there are no x or z bits in its value. bool is_defined() const; bool is_zero() const; + bool is_negative() const; // A number is "a string" if its value came directly from // an ASCII description instead of a number value. @@ -151,6 +152,9 @@ extern verinum v_not(const verinum&left); /* * $Log: verinum.h,v $ + * Revision 1.26.2.4 2007/03/23 20:59:26 steve + * Fix compile time evaluation of < operator. + * * Revision 1.26.2.3 2005/12/07 03:28:45 steve * Support constant concatenation of constants. *