From a9497e9c6afa9c029d97ddb16e0e390ac025e137 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Fri, 10 Oct 2008 20:45:11 -0700 Subject: [PATCH] Less agressive padding of unsized lossless addition. When doing lossless addition to an unsized constant, we make the size be width of an integer, only to be consistent with other tools. In fact, don't go overboard if we don't have to. --- net_expr.cc | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/net_expr.cc b/net_expr.cc index 6b1a9fccd..09d2ce116 100644 --- a/net_expr.cc +++ b/net_expr.cc @@ -56,42 +56,54 @@ NetEBAdd::NetEBAdd(char op, NetExpr*l, NetExpr*r, bool lossless_flag) && (! tmp->has_width()) && (tmp->expr_width() > l->expr_width() || integer_width > l->expr_width()) ) { - unsigned target_width = l->expr_width() + 1; + verinum tmp_v = trim_vnum(tmp->value()); + unsigned target_width = l->expr_width(); + if (target_width < tmp_v.len()) + target_width = tmp_v.len(); + if (lossless_flag) + target_width += 1; if (target_width < integer_width) target_width = integer_width; + r->set_width(target_width); /* Note: This constant value will not gain a defined width from this. Make sure. */ assert(! r->has_width() ); + expr_width(target_width); + } else if ( (tmp = dynamic_cast(l)) && (! tmp->has_width()) && (tmp->expr_width() > r->expr_width() || integer_width > r->expr_width()) ) { - unsigned target_width = r->expr_width() + 1; + verinum tmp_v = trim_vnum(tmp->value()); + unsigned target_width = r->expr_width(); + if (target_width < tmp_v.len()) + target_width = tmp_v.len(); + if (lossless_flag) + target_width += 1; if (target_width < integer_width) target_width = integer_width; + l->set_width(target_width); /* Note: This constant value will not gain a defined width from this. Make sure. */ assert(! l->has_width() ); - } + expr_width(target_width); - unsigned pad_width = lossless_flag? 1 : 0; - cast_signed(l->has_sign() && r->has_sign()); - - /* Now that we have the operand sizes the way we like, or as - good as we are going to get them, set the size of myself. */ - if (r->expr_width() > l->expr_width()) { - - expr_width(r->expr_width() + pad_width); + } else if (r->expr_width() > l->expr_width()) { + unsigned loss_pad = lossless_flag? 1 : 0; + expr_width(r->expr_width() + loss_pad); } else { - expr_width(l->expr_width() + pad_width); + unsigned loss_pad = lossless_flag? 1 : 0; + expr_width(l->expr_width() + loss_pad); } + + cast_signed(l->has_sign() && r->has_sign()); } NetEBAdd::~NetEBAdd()