From 55a15d604dc23e69566a898ce73634728d272a83 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Tue, 30 Sep 2008 21:35:09 -0700 Subject: [PATCH] Pad operands of bitwise operators. When elaborating bitwise operators width context determined width, pad the operands. --- PExpr.h | 1 + elab_expr.cc | 20 ++++++++++++++++++-- expr_synth.cc | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/PExpr.h b/PExpr.h index 5b319d98b..a3da795a3 100644 --- a/PExpr.h +++ b/PExpr.h @@ -467,6 +467,7 @@ class PEBinary : public PExpr { NetExpr*elaborate_expr_base_(Design*, NetExpr*lp, NetExpr*rp, int use_wid) const; NetExpr*elaborate_eval_expr_base_(Design*, NetExpr*lp, NetExpr*rp, int use_wid) const; + NetExpr*elaborate_expr_base_bits_(Design*, NetExpr*lp, NetExpr*rp, int use_wid) const; NetExpr*elaborate_expr_base_div_(Design*, NetExpr*lp, NetExpr*rp, int use_wid) const; NetExpr*elaborate_expr_base_lshift_(Design*, NetExpr*lp, NetExpr*rp, int use_wid) const; NetExpr*elaborate_expr_base_rshift_(Design*, NetExpr*lp, NetExpr*rp, int use_wid) const; diff --git a/elab_expr.cc b/elab_expr.cc index dbed27030..2c786ec99 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -298,8 +298,7 @@ NetExpr* PEBinary::elaborate_expr_base_(Design*des, case 'O': // NOR (~|) case 'A': // NAND (~&) case 'X': - tmp = new NetEBBits(op_, lp, rp); - tmp->set_line(*this); + tmp = elaborate_expr_base_bits_(des, lp, rp, expr_wid); break; case '+': @@ -352,6 +351,23 @@ NetExpr* PEBinary::elaborate_expr_base_(Design*des, return tmp; } +NetExpr* PEBinary::elaborate_expr_base_bits_(Design*des, + NetExpr*lp, NetExpr*rp, + int expr_wid) const +{ + if (expr_wid > 0) { + if (type_is_vectorable(lp->expr_type())) + lp = pad_to_width(lp, expr_wid); + if (type_is_vectorable(rp->expr_type())) + rp = pad_to_width(rp, expr_wid); + } + + NetEBBits*tmp = new NetEBBits(op_, lp, rp); + tmp->set_line(*this); + + return tmp; +} + NetExpr* PEBinary::elaborate_expr_base_div_(Design*des, NetExpr*lp, NetExpr*rp, int expr_wid) const diff --git a/expr_synth.cc b/expr_synth.cc index defc18dbf..340341b8b 100644 --- a/expr_synth.cc +++ b/expr_synth.cc @@ -164,7 +164,7 @@ NetNet* NetEBBits::synthesize(Design*des, NetScope*scope) return 0; } - unsigned width = lsig->vector_width(); + unsigned width = expr_width(); if (rsig->vector_width() > width) width = rsig->vector_width(); lsig = pad_to_width(des, lsig, width);