From 7c024d6cab164acd12a202eecc85475fe3bd16e2 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Tue, 20 Apr 2021 21:02:04 +0100 Subject: [PATCH] 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. --- elab_expr.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/elab_expr.cc b/elab_expr.cc index 0b2bf86b1..f40e0a887 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -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;