Reorder calls to test_width() on binary operands for efficiency.
It is more common to find an unsized number on the right hand side of a binary operator than on the left hand side, particularly for comparison operations (e.g. x < 10 rather than 10 > x), so testing the width of the right operand first is less likely to result in the width needing to be retested. Counting the number of times an operand width is retested when running the test suite confirms this; before this change an operand width was retested 4869 times, after the change an operand width was retested 99 times.
This commit is contained in:
parent
4625e7e2b6
commit
be2595085f
16
elab_expr.cc
16
elab_expr.cc
|
|
@ -258,16 +258,16 @@ unsigned PEBinary::test_width(Design*des, NetScope*scope, width_mode_t&mode)
|
|||
ivl_assert(*this, left_);
|
||||
ivl_assert(*this, right_);
|
||||
|
||||
unsigned l_width = left_->test_width(des, scope, mode);
|
||||
unsigned r_width = right_->test_width(des, scope, mode);
|
||||
|
||||
width_mode_t saved_mode = mode;
|
||||
|
||||
unsigned r_width = right_->test_width(des, scope, mode);
|
||||
unsigned l_width = left_->test_width(des, scope, mode);
|
||||
|
||||
// If the width mode changed, retest the left operand, as it
|
||||
// If the width mode changed, retest the right operand, as it
|
||||
// may choose a different width if it is in a lossless context.
|
||||
if ((mode >= LOSSLESS) && (saved_mode < LOSSLESS))
|
||||
l_width = left_->test_width(des, scope, mode);
|
||||
r_width = right_->test_width(des, scope, mode);
|
||||
|
||||
ivl_variable_type_t l_type = left_->expr_type();
|
||||
ivl_variable_type_t r_type = right_->expr_type();
|
||||
|
|
@ -568,16 +568,16 @@ unsigned PEBComp::test_width(Design*des, NetScope*scope, width_mode_t&)
|
|||
// affect each other, but not the result.
|
||||
width_mode_t mode = SIZED;
|
||||
|
||||
unsigned l_width = left_->test_width(des, scope, mode);
|
||||
unsigned r_width = right_->test_width(des, scope, mode);
|
||||
|
||||
width_mode_t saved_mode = mode;
|
||||
|
||||
unsigned r_width = right_->test_width(des, scope, mode);
|
||||
unsigned l_width = left_->test_width(des, scope, mode);
|
||||
|
||||
// If the width mode changed, retest the left operand, as it
|
||||
// If the width mode changed, retest the right operand, as it
|
||||
// may choose a different width if it is in a lossless context.
|
||||
if ((mode >= LOSSLESS) && (saved_mode < LOSSLESS))
|
||||
l_width = left_->test_width(des, scope, mode);
|
||||
r_width = right_->test_width(des, scope, mode);
|
||||
|
||||
ivl_variable_type_t l_type = left_->expr_type();
|
||||
ivl_variable_type_t r_type = right_->expr_type();
|
||||
|
|
|
|||
Loading…
Reference in New Issue