The signedness of a ternary expression comes from its operands.
If either of the operands of a ternary expression are unsigned, then both are treated as unsigned. It works just like a binary expression in that regard.
This commit is contained in:
parent
864a86f7ee
commit
62f518c205
4
PExpr.h
4
PExpr.h
|
|
@ -144,6 +144,8 @@ class PExpr : public LineInfo {
|
|||
ivl_variable_type_t expr_type_;
|
||||
unsigned expr_width_;
|
||||
|
||||
static void suppress_binary_operand_sign_if_needed_(NetExpr*lp, NetExpr*rp);
|
||||
|
||||
private: // not implemented
|
||||
PExpr(const PExpr&);
|
||||
PExpr& operator= (const PExpr&);
|
||||
|
|
@ -484,8 +486,6 @@ class PEBinary : public PExpr {
|
|||
NetExpr*elaborate_expr_base_mult_(Design*, NetExpr*lp, NetExpr*rp, int use_wid) const;
|
||||
NetExpr*elaborate_expr_base_add_(Design*, NetExpr*lp, NetExpr*rp, int use_wid) const;
|
||||
|
||||
static void suppress_operand_sign_if_needed_(NetExpr*lp, NetExpr*rp);
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
|||
10
elab_expr.cc
10
elab_expr.cc
|
|
@ -222,7 +222,7 @@ NetExpr* PEBinary::elaborate_expr(Design*des, NetScope*scope,
|
|||
return tmp;
|
||||
}
|
||||
|
||||
void PEBinary::suppress_operand_sign_if_needed_(NetExpr*lp, NetExpr*rp)
|
||||
void PExpr::suppress_binary_operand_sign_if_needed_(NetExpr*lp, NetExpr*rp)
|
||||
{
|
||||
// If an argument is a non-vector type, then this type
|
||||
// suppression does not apply.
|
||||
|
|
@ -672,7 +672,7 @@ NetExpr* PEBinary::elaborate_expr_base_mult_(Design*des,
|
|||
// If this expression is unsigned, then make sure the
|
||||
// arguments are unsigned so that the padding below doesn't
|
||||
// cause any sign extension to happen.
|
||||
suppress_operand_sign_if_needed_(lp, rp);
|
||||
suppress_binary_operand_sign_if_needed_(lp, rp);
|
||||
|
||||
|
||||
// Multiply will guess a width that is the sum of the
|
||||
|
|
@ -709,7 +709,7 @@ NetExpr* PEBinary::elaborate_expr_base_add_(Design*des,
|
|||
// If the expression is unsigned, then force the operands to
|
||||
// unsigned so taht the set_width below doesn't cause them to
|
||||
// be sign-extended.
|
||||
suppress_operand_sign_if_needed_(lp, rp);
|
||||
suppress_binary_operand_sign_if_needed_(lp, rp);
|
||||
|
||||
tmp = new NetEBAdd(op_, lp, rp, use_lossless_flag);
|
||||
if (expr_wid > 0 && type_is_vectorable(tmp->expr_type()))
|
||||
|
|
@ -764,7 +764,7 @@ NetExpr* PEBComp::elaborate_expr(Design*des, NetScope*scope,
|
|||
return 0;
|
||||
}
|
||||
|
||||
suppress_operand_sign_if_needed_(lp, rp);
|
||||
suppress_binary_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
|
||||
|
|
@ -2679,6 +2679,8 @@ NetExpr*PETernary::elaborate_expr(Design*des, NetScope*scope,
|
|||
return 0;
|
||||
}
|
||||
|
||||
suppress_binary_operand_sign_if_needed_(tru, fal);
|
||||
|
||||
/* Whatever the width we choose for the ternary operator, we
|
||||
need to make sure the operands match. */
|
||||
tru = pad_to_width(tru, use_wid);
|
||||
|
|
|
|||
Loading…
Reference in New Issue