do the <= in bits, not numbers.

This commit is contained in:
steve 1999-10-22 23:57:53 +00:00
parent 2e40152ff2
commit 2c774bfe75
3 changed files with 44 additions and 10 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) #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 #endif
# include "netlist.h" # include "netlist.h"
@ -105,8 +105,9 @@ NetEConst* NetEBComp::eval_leeq_()
/* Detect the case where the right side is greater that or /* Detect the case where the right side is greater that or
equal to the largest value the left side can possibly equal to the largest value the left side can possibly
have. */ have. */
unsigned long lv = (1 << left_->expr_width()) - 1; assert(left_->expr_width() > 0);
if (lv <= rv.as_ulong()) { verinum lv (verinum::V1, left_->expr_width());
if (lv <= rv) {
verinum result(verinum::V1, 1); verinum result(verinum::V1, 1);
return new NetEConst(result); return new NetEConst(result);
} }
@ -261,6 +262,9 @@ NetExpr* NetEParam::eval_tree()
/* /*
* $Log: eval_tree.cc,v $ * $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 * Revision 1.5 1999/10/10 23:29:37 steve
* Support evaluating + operator at compile time. * Support evaluating + operator at compile time.
* *

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) #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 #endif
# include "verinum.h" # include "verinum.h"
@ -296,16 +296,39 @@ ostream& operator<< (ostream&o, const verinum&v)
return o; return o;
} }
bool operator == (const verinum&left, const verinum&right) verinum::V operator == (const verinum&left, const verinum&right)
{ {
if (left.len() != right.len()) if (left.len() != right.len())
return false; return verinum::V0;
for (unsigned idx = 0 ; idx < left.len() ; idx += 1) for (unsigned idx = 0 ; idx < left.len() ; idx += 1)
if (left[idx] != right[idx]) 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) 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 $ * $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 * Revision 1.10 1999/10/10 23:29:37 steve
* Support evaluating + operator at compile time. * Support evaluating + operator at compile time.
* *

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) #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 #endif
# include <string> # include <string>
@ -90,12 +90,16 @@ class ostream;
extern ostream& operator<< (ostream&, const verinum&); extern ostream& operator<< (ostream&, const verinum&);
extern ostream& operator<< (ostream&, verinum::V); 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);
extern verinum operator - (const verinum&left, const verinum&right); extern verinum operator - (const verinum&left, const verinum&right);
/* /*
* $Log: verinum.h,v $ * $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 * Revision 1.6 1999/10/10 23:29:37 steve
* Support evaluating + operator at compile time. * Support evaluating + operator at compile time.
* *