Fix sign extension of evaluated constants. (PR#91)
This commit is contained in:
parent
88a2ca2168
commit
6c4b5cf2c2
18
eval.cc
18
eval.cc
|
|
@ -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) && !defined(macintosh)
|
#if !defined(WINNT) && !defined(macintosh)
|
||||||
#ident "$Id: eval.cc,v 1.18 2001/01/14 23:04:56 steve Exp $"
|
#ident "$Id: eval.cc,v 1.19 2001/01/27 05:41:48 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# include "PExpr.h"
|
# include "PExpr.h"
|
||||||
|
|
@ -173,9 +173,18 @@ verinum* PEUnary::eval_const(const Design*des, const string&path) const
|
||||||
case '+':
|
case '+':
|
||||||
return val;
|
return val;
|
||||||
|
|
||||||
case '-':
|
case '-': {
|
||||||
*val = v_not(*val) + verinum(verinum::V1, 1);
|
/* We need to expand the value a bit if we are
|
||||||
|
taking the 2's complement so that we are
|
||||||
|
guaranteed to not overflow. */
|
||||||
|
verinum tmp (0UL, val->len()+1);
|
||||||
|
for (unsigned idx = 0 ; idx < val->len() ; idx += 1)
|
||||||
|
tmp.set(idx, val->get(idx));
|
||||||
|
|
||||||
|
*val = v_not(tmp) + verinum(verinum::V1, 1);
|
||||||
|
val->has_sign(true);
|
||||||
return val;
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
delete val;
|
delete val;
|
||||||
|
|
@ -185,6 +194,9 @@ verinum* PEUnary::eval_const(const Design*des, const string&path) const
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: eval.cc,v $
|
* $Log: eval.cc,v $
|
||||||
|
* Revision 1.19 2001/01/27 05:41:48 steve
|
||||||
|
* Fix sign extension of evaluated constants. (PR#91)
|
||||||
|
*
|
||||||
* Revision 1.18 2001/01/14 23:04:56 steve
|
* Revision 1.18 2001/01/14 23:04:56 steve
|
||||||
* Generalize the evaluation of floating point delays, and
|
* Generalize the evaluation of floating point delays, and
|
||||||
* get it working with delay assignment statements.
|
* get it working with delay assignment statements.
|
||||||
|
|
|
||||||
11
set_width.cc
11
set_width.cc
|
|
@ -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) && !defined(macintosh)
|
#if !defined(WINNT) && !defined(macintosh)
|
||||||
#ident "$Id: set_width.cc,v 1.14 2000/06/18 03:29:52 steve Exp $"
|
#ident "$Id: set_width.cc,v 1.15 2001/01/27 05:41:48 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -201,9 +201,15 @@ bool NetEConcat::set_width(unsigned w)
|
||||||
bool NetEConst::set_width(unsigned w)
|
bool NetEConst::set_width(unsigned w)
|
||||||
{
|
{
|
||||||
if (w > value_.len()) {
|
if (w > value_.len()) {
|
||||||
|
verinum::V pad = verinum::V0;
|
||||||
|
if (value_.has_sign())
|
||||||
|
pad = value_.get(value_.len()-1);
|
||||||
|
|
||||||
verinum tmp (verinum::V0, w);
|
verinum tmp (verinum::V0, w);
|
||||||
for (unsigned idx = 0 ; idx < value_.len() ; idx += 1)
|
for (unsigned idx = 0 ; idx < value_.len() ; idx += 1)
|
||||||
tmp.set(idx, value_[idx]);
|
tmp.set(idx, value_[idx]);
|
||||||
|
for (unsigned idx = value_.len() ; idx < w ; idx += 1)
|
||||||
|
tmp.set(idx, pad);
|
||||||
|
|
||||||
value_ = tmp;
|
value_ = tmp;
|
||||||
|
|
||||||
|
|
@ -307,6 +313,9 @@ bool NetEUnary::set_width(unsigned w)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: set_width.cc,v $
|
* $Log: set_width.cc,v $
|
||||||
|
* Revision 1.15 2001/01/27 05:41:48 steve
|
||||||
|
* Fix sign extension of evaluated constants. (PR#91)
|
||||||
|
*
|
||||||
* Revision 1.14 2000/06/18 03:29:52 steve
|
* Revision 1.14 2000/06/18 03:29:52 steve
|
||||||
* Handle width expansion of shift operators.
|
* Handle width expansion of shift operators.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue