Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIRRTL] Fix unpacked array ordering in GCT and ExportVerilog #2049

Merged
merged 1 commit into from
Oct 28, 2021

Conversation

fabianschuiki
Copy link
Contributor

@fabianschuiki fabianschuiki commented Oct 28, 2021

The FIRRTL Grand Central pass and ExportVerilog currently order unpacked arrays in reverse upon emission. A nested array like uarray<2 x uarray<3 x i1>> has the shape [[a,b,c], [d,e,f]] and should produce the following verilog:

logic foo [2][3]; // non-range indices used for clarity

Generally the following SV declaration:

logic [2:0][1:0] bar [4:0][3:0];

Reads its dimensions from outer- to innermost as:

[4:0], [3:0], [2:0], [1:0]

Currently, ExportVerilog will emit the above foo example as foo[3][2], which is incorrect. Fixing ExportVerilog also provides a fix for an issue @seldridge tackled earlier in ca5bfac. This change reverts parts of that older fix since the updated declaration order now makes the original Grand Central index order correct.

The output now matches what the Scala FIRRTL compiler produces.

The FIRRTL Grand Central pass and ExportVerilog currently order unpacked
arrays in reverse upon emission. A nested array like
`uarray<2 x uarray<3 x i1>>` has the shape `[[a,b,c], [d,e,f]]` and
should produce the following verilog:

  logic foo [2][3]; // non-range indices used for clarity

Generally the following SV declaration:

  logic [2:0][1:0] bar [4:0][3:0];

Reads its dimensions from outer- to innermost as:

  [4:0], [3:0], [2:0], [1:0]

Currently, ExportVerilog will emit the above `foo` example as
`foo[3][2]`, which is incorrect. Fixing ExportVerilog also provides a
fix for an issue @seldridge tackled earlier in ca5bfac. This change
reverts parts of that older fix since the updated declaration order now
makes the original Grand Central index order correct.

The output now matches what the Scala FIRRTL compiler produces.
@fabianschuiki fabianschuiki added FIRRTL Involving the `firrtl` dialect HW Involving the `hw` dialect ExportVerilog labels Oct 28, 2021
Copy link
Member

@seldridge seldridge left a comment

Choose a reason for hiding this comment

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

Nice fix! Thanks for sorting out these tedious Verilog semantics.

@@ -54,7 +54,7 @@ struct VerbatimType {
SmallString<64> stringType(str);
stringType.append(" ");
stringType.append(name);
for (auto d : dimensions) {
for (auto d : llvm::reverse(dimensions)) {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for fixing this!

test/Dialect/FIRRTL/grand-central.mlir Show resolved Hide resolved
@seldridge seldridge merged commit 027e6ef into llvm:main Oct 28, 2021
@fabianschuiki
Copy link
Contributor Author

Awesome, thanks for hitting merge on this!

@fabianschuiki fabianschuiki deleted the gct-vector-order branch October 29, 2021 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExportVerilog FIRRTL Involving the `firrtl` dialect HW Involving the `hw` dialect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants