Skip to content

Enhance AUTO_TEMPLATE for unpacked array connections and merging - #1908

Open
anythingelse0 wants to merge 7 commits into
veripool:masterfrom
anythingelse0:master
Open

Enhance AUTO_TEMPLATE for unpacked array connections and merging#1908
anythingelse0 wants to merge 7 commits into
veripool:masterfrom
anythingelse0:master

Conversation

@anythingelse0

Copy link
Copy Markdown

Summary

Add support for connecting one element of an unpacked array per instance
in an AUTO_TEMPLATE, and have AUTOWIRE/AUTOINPUT declare the net as an
unpacked array covering all connected indexes.

module InstModule
  (
   output [3:0] ptl_mapvalidx
   );
endmodule

module top ();
   /*AUTOWIRE*/
   /*
    InstModule AUTO_TEMPLATE
    (
    .ptl_mapvalidx (ptl_mapvalid[].[@]),
    );
    */
   InstModule ms2m
     (/*AUTOINST*/);
   InstModule ms0m
     (/*AUTOINST*/);
endmodule

expands it to:

module top ();
   /*AUTOWIRE*/
   // Beginning of automatic wires (for undeclared instantiated-module outputs)
   wire [3:0] ptl_mapvalid [0:2];   // From ms2m of InstModule.v, ...
   // End of automatics
   /*
    InstModule AUTO_TEMPLATE
    (
    .ptl_mapvalidx (ptl_mapvalid[].[@]),
    );
    */
   InstModule ms2m
     (/*AUTOINST*/
      // Outputs
      .ptl_mapvalidx                (ptl_mapvalid[2]/*[3:0].[2]*/)); // Templated
   InstModule ms0m
     (/*AUTOINST*/
      // Outputs
      .ptl_mapvalidx                (ptl_mapvalid[0]/*[3:0].[0]*/)); // Templated
endmodule

Implementation

  • verilog-auto-inst-port: rewrite sig[].[idx] so only the unpacked
    index stays executable; the port ranges go into a /*[bits].[idx]*/
    comment (extending the existing comment convention used for memory
    ports), keeping the connection legal Verilog.
  • verilog-read-sub-decls-expr: canonicalize the comment back into an
    unpacked range so AUTOWIRE and friends can parse it; numeric indexes
    become single-element ranges ([2:2]), non-numeric indexes pass
    through unchanged.
  • verilog-signals-combine-bus: merge ascending numeric unpacked ranges
    via min/max into one covering range, the same way packed bits are
    merged. Overlapping or duplicate ranges merge silently — an
    unpacked-array net fanned out to several instances must not warn.
    ", Couldn't Merge" is kept only when a numeric range mixes with an
    unmergeable form (descending like [3:0], or symbolic like [IDX]),
    in which case the first unmergeable form wins so existing declarations
    keep their direction/expression.
  • [].[@] on an instance whose name provides no value for @ now
    raises an error instead of silently emitting a nonsense connection.

Tests

  • tests/autoinst_tpl_array_index.v: basic expansion, duplicate element
    index (merges to a single-element range), non-numeric index.
  • tests/tpl_arr_edge.v: non-consecutive indexes, descending packed +
    ascending unpacked, multiple ports per template, mixed
    mergeable/unmergeable forms, hard-coded index gaps, single instance,
    descending instance order, overlapping ranges, signed ranges,
    descending-vs-numeric and symbolic-vs-numeric conflicts, negative
    single index, escaped identifiers, and a fanout regression test
    (unpacked-array input feeding two instances stays warning-free in
    AUTOINPUT).

  - preserve unmergeable unpacked ranges when mixed with numeric ranges
  - merge compatible ascending numeric unpacked ranges without expanding indexes
  - support signed single indexes and escaped identifiers in generated connections
  - add tpl_arr_edge regressions for mixed, signed, and escaped array cases
  - update tpl_arr_edge golden whitespace to match generated output
  - preserve unmergeable unpacked ranges when mixed with numeric ranges
  - merge compatible ascending numeric unpacked ranges without expanding indexes
  - support signed single indexes and escaped identifiers in generated connections
  - add tpl_arr_edge regressions for mixed, signed, and escaped array cases
  - update tpl_arr_edge golden whitespace to match generated output
"[].[index]" connections previously warned "Couldn't Merge" even when
the merged declaration was correct, e.g. an unpacked-array input feeding
two instances made AUTOINPUT emit a spurious warning.  Merge such ranges
silently via min/max, the same way packed bits are merged; keep the
warning only for mixes with unmergeable forms (descending or symbolic
ranges).  This also removes the O(n^2) overlap scan.

Also report an error when "[].[@]" expands to an empty "[].[]" index
because the instance name provides no value for @, instead of silently
emitting a nonsense connection.

Add a fanout regression test (unpacked-array input into two instances),
and update goldens for the no-longer-warning cases.
Comment thread tests/autologic_bracket.v
Comment thread verilog-mode.el Outdated
Comment thread verilog-mode.el Outdated
Comment thread verilog-mode.el Outdated
anythingelse0 and others added 3 commits July 22, 2026 11:12
Remove lines about unpacked array connections from the AUTOWIRE
limitations section as they are not applicable there.
Co-authored-by: Wilson Snyder <wsnyder@wsnyder.org>
Co-authored-by: Wilson Snyder <wsnyder@wsnyder.org>

@anythingelse0 anythingelse0 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Remove inapplicable documentation about unpacked arrays in AUTOWIRE
  • Apply formatting suggestion to unpacked array documentation
  • Improve comment clarity for unpacked declaration handling"

@wsnyder

wsnyder commented Jul 22, 2026

Copy link
Copy Markdown
Member

Looks good, I pushed some minor indent cleanups. As these changes are non-trival you need to email assign@fsf.org and complete a copyright assignment. Let me know when done and the name to commit under; Emacs does not allow anonymous commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants