From 18de6980ffac75b5a714ca4187efff62fcf75ae6 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Fri, 3 Oct 2008 19:52:26 -0700 Subject: [PATCH] Fix associative add tree to get result width correct. When evaluating A+1+2 in eval_tree, the (1+2) needs to have the correct result width, or the elaborated expression with will be lost. --- eval_tree.cc | 9 +++++++++ expr_synth.cc | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/eval_tree.cc b/eval_tree.cc index 78d1e5b28..06b660df6 100644 --- a/eval_tree.cc +++ b/eval_tree.cc @@ -133,6 +133,8 @@ NetExpr* NetEBAdd::eval_tree(int prune_to_width) verinum lval = lc->value(); verinum rval = rc->value(); + ivl_assert(*this, se->expr_width() == this->expr_width()); + verinum val; if (op_ == se->op_) { /* (a + lval) + rval --> a + (rval+lval) */ @@ -144,6 +146,13 @@ NetExpr* NetEBAdd::eval_tree(int prune_to_width) val = rval - lval; } + val = pad_to_width(val, expr_width()); + if (val.len() > expr_width()) { + verinum tmp (val, expr_width()); + tmp.has_sign(val.has_sign()); + val = tmp; + } + NetEConst*tmp = new NetEConst(val); left_ = se->left_->dup_expr(); delete se; diff --git a/expr_synth.cc b/expr_synth.cc index 2845877c9..9fe178fe1 100644 --- a/expr_synth.cc +++ b/expr_synth.cc @@ -99,8 +99,8 @@ NetNet* NetEBAdd::synthesize(Design*des, NetScope*scope) return 0; } - assert(expr_width() >= lsig->vector_width()); - assert(expr_width() >= rsig->vector_width()); + ivl_assert(*this, expr_width() >= lsig->vector_width()); + ivl_assert(*this, expr_width() >= rsig->vector_width()); unsigned width; if (expr_type() == IVL_VT_REAL) { @@ -752,7 +752,7 @@ NetNet* NetEConst::synthesize(Design*des, NetScope*scope) perm_string path = scope->local_symbol(); unsigned width=expr_width(); - NetNet*osig = new NetNet(scope, path, NetNet::IMPLICIT, width-1,0); + NetNet*osig = new NetNet(scope, path, NetNet::IMPLICIT, width); osig->local_flag(true); osig->data_type(expr_type()); osig->set_signed(has_sign());