From 995fc380e8c75b53f343b784f8fb5d9b30c2df6f Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Sat, 11 Oct 2008 09:20:49 -0700 Subject: [PATCH] Get padding of signed comparison operands. The results of comparisons are unsigned, but the arguments may be signed and the calculation performed may be signed. Handle the padding properly for comparisons so that the math is properly signed. --- elab_expr.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/elab_expr.cc b/elab_expr.cc index ab3785657..09af31374 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -224,6 +224,13 @@ NetExpr* PEBinary::elaborate_expr(Design*des, NetScope*scope, void PEBinary::suppress_operand_sign_if_needed_(NetExpr*lp, NetExpr*rp) { + // If an argument is a non-vector type, then this type + // suppression does not apply. + if (! type_is_vectorable(lp->expr_type())) + return; + if (! type_is_vectorable(rp->expr_type())) + return; + // If either operand is unsigned, then treat the whole // expression as unsigned. This test needs to be done here // instead of in *_expr_base_ because it needs to be done @@ -759,6 +766,14 @@ NetExpr* PEBComp::elaborate_expr(Design*des, NetScope*scope, suppress_operand_sign_if_needed_(lp, rp); + // The arguments of a compare need to have matching widths, so + // pad the width here. This matters because if the arguments + // are signed, then this padding will do sign extension. + if (type_is_vectorable(lp->expr_type())) + lp = pad_to_width(lp, use_wid); + if (type_is_vectorable(rp->expr_type())) + rp = pad_to_width(rp, use_wid); + return elaborate_eval_expr_base_(des, lp, rp, use_wid); }