Skip to content

Collapse adjacent bit selects in swizzles to ranges - #674

Merged
mkorbel1 merged 3 commits into
intel:mainfrom
mkorbel1:bits_to_slice_collapse2
Jul 6, 2026
Merged

Collapse adjacent bit selects in swizzles to ranges#674
mkorbel1 merged 3 commits into
intel:mainfrom
mkorbel1:bits_to_slice_collapse2

Conversation

@mkorbel1

@mkorbel1 mkorbel1 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Description & Motivation

This improves generated SystemVerilog for swizzles by compacting descending contiguous single-bit selections into legal slice expressions.

Examples:

  • {a[7], a[6], a[5]} can now emit as a[7:5]
  • {arr[0][1], arr[0][0]} can now emit as arr[0][1:0]

The collapse is intentionally conservative. It only applies to descending contiguous bit selects from the same packed source, and leaves unsupported cases expanded, including ascending selections, adjacent pre-existing range operands, expression-based selects, nested swizzle boundaries, and unpacked array sources.

Related Issue(s)

N/A

Testing

Added new tests, updated some other tests

Backwards-compatibility

Is this a breaking change that will not be backwards-compatible? If yes, how so?

No

Documentation

Does the change require any updates to documentation? If so, where? Are they included?

No

Comment thread lib/src/modules/bus.dart
Comment thread lib/src/modules/bus.dart
@desmonddak

Copy link
Copy Markdown
Contributor

I think this PR makes sense right now to get SV much cleaner. I could see pushing some of the optimizations into the base and leaving here some SV-specific conventions like [:7]. Otherwise, the collapse could be structural, and then the strings would come out from there unless we are avoiding structural change in the synth layer for this case.

@mkorbel1

mkorbel1 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

I agree, makes SV a lot cleaner and is pretty elegant and limited, we can look for additional opportunities for reuse when the situation actually presents itself

@mkorbel1
mkorbel1 merged commit 009fb27 into intel:main Jul 6, 2026
3 checks passed
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