Fix compile time evaluation of < operator.
This commit is contained in:
parent
82808d8b5d
commit
07daee9438
11
eval_tree.cc
11
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.
|
||||
*
|
||||
|
|
|
|||
31
verinum.cc
31
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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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 <string>
|
||||
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue