From 2c774bfe75624d0c69aaebbcc204b9df43eab73b Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 22 Oct 1999 23:57:53 +0000 Subject: [PATCH] do the <= in bits, not numbers. --- eval_tree.cc | 10 +++++++--- verinum.cc | 36 +++++++++++++++++++++++++++++++----- verinum.h | 8 ++++++-- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/eval_tree.cc b/eval_tree.cc index bcb5a6d03..1cb9426b3 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 */ #if !defined(WINNT) -#ident "$Id: eval_tree.cc,v 1.5 1999/10/10 23:29:37 steve Exp $" +#ident "$Id: eval_tree.cc,v 1.6 1999/10/22 23:57:53 steve Exp $" #endif # include "netlist.h" @@ -105,8 +105,9 @@ NetEConst* NetEBComp::eval_leeq_() /* Detect the case where the right side is greater that or equal to the largest value the left side can possibly have. */ - unsigned long lv = (1 << left_->expr_width()) - 1; - if (lv <= rv.as_ulong()) { + assert(left_->expr_width() > 0); + verinum lv (verinum::V1, left_->expr_width()); + if (lv <= rv) { verinum result(verinum::V1, 1); return new NetEConst(result); } @@ -261,6 +262,9 @@ NetExpr* NetEParam::eval_tree() /* * $Log: eval_tree.cc,v $ + * Revision 1.6 1999/10/22 23:57:53 steve + * do the <= in bits, not numbers. + * * Revision 1.5 1999/10/10 23:29:37 steve * Support evaluating + operator at compile time. * diff --git a/verinum.cc b/verinum.cc index 678ba333a..1322b5fae 100644 --- a/verinum.cc +++ b/verinum.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: verinum.cc,v 1.10 1999/10/10 23:29:37 steve Exp $" +#ident "$Id: verinum.cc,v 1.11 1999/10/22 23:57:53 steve Exp $" #endif # include "verinum.h" @@ -296,16 +296,39 @@ ostream& operator<< (ostream&o, const verinum&v) return o; } -bool operator == (const verinum&left, const verinum&right) +verinum::V operator == (const verinum&left, const verinum&right) { if (left.len() != right.len()) - return false; + return verinum::V0; for (unsigned idx = 0 ; idx < left.len() ; idx += 1) if (left[idx] != right[idx]) - return false; + return verinum::V0; - return true; + return verinum::V1; +} + +verinum::V operator <= (const verinum&left, const verinum&right) +{ + unsigned idx; + for (idx = left.len() ; idx > right.len() ; idx -= 1) { + if (left[idx-1] != verinum::V0) return verinum::V0; + } + + for (idx = right.len() ; idx > left.len() ; idx -= 1) { + if (right[idx-1] != verinum::V0) return verinum::V0; + } + + while (idx > 0) { + if (left[idx-1] == verinum::Vx) return verinum::Vx; + if (left[idx-1] == verinum::Vz) return verinum::Vx; + if (right[idx-1] == verinum::Vx) return verinum::Vx; + if (right[idx-1] == verinum::Vz) return verinum::Vx; + if (left[idx-1] > right[idx-1]) return verinum::V0; + idx -= 1; + } + + return verinum::V1; } static verinum::V add_with_carry(verinum::V l, verinum::V r, verinum::V&c) @@ -432,6 +455,9 @@ verinum operator - (const verinum&left, const verinum&r) /* * $Log: verinum.cc,v $ + * Revision 1.11 1999/10/22 23:57:53 steve + * do the <= in bits, not numbers. + * * Revision 1.10 1999/10/10 23:29:37 steve * Support evaluating + operator at compile time. * diff --git a/verinum.h b/verinum.h index 3785414a3..e28a686f8 100644 --- a/verinum.h +++ b/verinum.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: verinum.h,v 1.6 1999/10/10 23:29:37 steve Exp $" +#ident "$Id: verinum.h,v 1.7 1999/10/22 23:57:53 steve Exp $" #endif # include @@ -90,12 +90,16 @@ class ostream; extern ostream& operator<< (ostream&, const verinum&); extern ostream& operator<< (ostream&, verinum::V); -extern bool operator == (const verinum&left, const verinum&right); +extern verinum::V operator == (const verinum&left, const verinum&right); +extern verinum::V operator <= (const verinum&left, const verinum&right); extern verinum operator + (const verinum&left, const verinum&right); extern verinum operator - (const verinum&left, const verinum&right); /* * $Log: verinum.h,v $ + * Revision 1.7 1999/10/22 23:57:53 steve + * do the <= in bits, not numbers. + * * Revision 1.6 1999/10/10 23:29:37 steve * Support evaluating + operator at compile time. *