From 9f2b5cd9b73b6e7f9d612770ecbef1892d30be1d Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Wed, 12 Nov 2008 20:59:10 -0800 Subject: [PATCH] Make the associative sum constant elimination more resilient to size details. The NetEBAdd::eval_tree method is able to use the associative property of addition to reduce some constants, but it is picky about widths. Make it a little bit more resilient to expression widths. --- eval_tree.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/eval_tree.cc b/eval_tree.cc index 40cdf517a..07b337970 100644 --- a/eval_tree.cc +++ b/eval_tree.cc @@ -133,7 +133,18 @@ 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()); + if (lval.len() < expr_width()) + lval = pad_to_width(lval, expr_width()); + if (rval.len() < expr_width()) + rval = pad_to_width(rval, expr_width()); + + if (se->expr_width() > this->expr_width()) { + cerr << get_fileline() << ": internal error: " + << "expr_width()=" << expr_width() + << ", sub expr_width()=" << se->expr_width() + << ", sub expression=" << *se << endl; + } + ivl_assert(*this, se->expr_width() <= this->expr_width()); verinum val; if (op_ == se->op_) { @@ -146,7 +157,9 @@ NetExpr* NetEBAdd::eval_tree(int prune_to_width) val = rval - lval; } - val = pad_to_width(val, expr_width()); + // Since we padded the operands above to be the minimum + // width, the val should also be at least expr_width(). + ivl_assert(*this, val.len() >= expr_width()); if (val.len() > expr_width()) { verinum tmp (val, expr_width()); tmp.has_sign(val.has_sign());