Skip to content

Conversation

fabianschuiki
Copy link
Contributor

Extend the PrepareForEmission part of ExportVerilog to lower hw.array_inject into a bit of procedural Verilog code that overwrites the injected array index:

// %b = hw.array_inject %a[%i], %v
logic [N-1:0] b;
always_comb begin
  b = a;
  b[i] = v;
end

Unfortunately assignment patterns like '{0: x, 1: y, 2: z} only support constant expressions for the array indices. The only options to mutate a single array entry that I am aware of are the procedural style implement in this commit, and creating a separate mux/ternary op for each index separately, which feels like total overkill.

Copy link
Member

@uenoku uenoku left a comment

Choose a reason for hiding this comment

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

Could you add a few test cases especially legalization in procedural region with disallowLocalVariable lowering option?

Extend the PrepareForEmission part of ExportVerilog to lower
`hw.array_inject` into a bit of procedural Verilog code that overwrites
the injected array index:

```systemverilog
// %b = hw.array_inject %a[%i], %v
logic [N-1:0] b;
always_comb begin
  b = a;
  b[i] = v;
end
```

Unfortunately assignment patterns like `'{0: x, 1: y, 2: z}` only
support constant expressions for the array indices. The only options to
mutate a single array entry that I am aware of are the procedural style
implement in this commit, and creating a separate mux/ternary op for
each index separately, which feels like total overkill.
@fabianschuiki fabianschuiki force-pushed the fschuiki/export-array-inject branch from 137f786 to dbcf4f7 Compare July 3, 2025 18:24
@fabianschuiki
Copy link
Contributor Author

Excellent point @uenoku! I've added a few tests to make sure the expressions get pulled out of procedural regions as expected when local variables are disallowed, and that the lowering works within procedural regions as well.

@fabianschuiki fabianschuiki requested a review from uenoku July 3, 2025 18:25
Copy link
Member

@uenoku uenoku left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for adding tests.

@fabianschuiki fabianschuiki merged commit 27fc297 into main Jul 3, 2025
7 checks passed
@fabianschuiki fabianschuiki deleted the fschuiki/export-array-inject branch July 3, 2025 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants