Skip to content

Collapse adjacent bit selects in swizzles to ranges#674

Open
mkorbel1 wants to merge 1 commit into
intel:mainfrom
mkorbel1:bits_to_slice_collapse2
Open

Collapse adjacent bit selects in swizzles to ranges#674
mkorbel1 wants to merge 1 commit 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
operands.add((expression: expression, width: input.width));
} else {
operands.add((
expression: '${selectedBit.source}[${selectedBit.index}:$lowerIndex]',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IT would be kinda fun to add the SV shorthands for when you are selecting up to the end of the array, or reverse-indexing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

are those safe with all tools? generally have been trying to keep things minimal fanciness to maximize tool compatibility

@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.

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