Collapse adjacent bit selects in swizzles to ranges#674
Open
mkorbel1 wants to merge 1 commit into
Open
Conversation
desmonddak
reviewed
Jul 1, 2026
desmonddak
reviewed
Jul 1, 2026
| operands.add((expression: expression, width: input.width)); | ||
| } else { | ||
| operands.add(( | ||
| expression: '${selectedBit.source}[${selectedBit.index}:$lowerIndex]', |
Contributor
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
are those safe with all tools? generally have been trying to keep things minimal fanciness to maximize tool compatibility
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 asa[7:5]{arr[0][1], arr[0][0]}can now emit asarr[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
No
Documentation
No