Fix width calculation for bit/part selects of multi-dimensioned packed arrays.

If we have a bit/part select that is selecting one or more sub-arrays, e.g.

  wire [3:0][3:0] foo;
  assign foo[1] = 4'd1;

we need to take into account the bit width of the sub-array when calculating
the bit width of the select.
This commit is contained in:
Martin Whitaker 2021-04-20 21:02:04 +01:00
parent 3167b2ed24
commit 7c024d6cab
1 changed files with 9 additions and 0 deletions

View File

@ -4071,6 +4071,15 @@ unsigned PEIdent::test_width(Design*des, NetScope*scope, width_mode_t&mode)
}
if (use_width != UINT_MAX) {
// We have a bit/part select. Account for any remaining dimensions
// beyond the indexed dimension.
size_t use_depth = name_tail.index.size();
if (net) {
if (use_depth >= net->unpacked_dimensions())
use_depth -= net->unpacked_dimensions();
use_width *= net->slice_width(use_depth);
}
expr_type_ = IVL_VT_LOGIC; // Assume bit/parts selects are logic
expr_width_ = use_width;
min_width_ = use_width;