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

[ImportVerilog] Support assignment patterns with integer type #7646

Merged
merged 2 commits into from
Sep 28, 2024

Conversation

fabianschuiki
Copy link
Contributor

Allow '{...} assignment patterns to be used to assign integer values. Slang already computes the value for each element in the resulting type. All that's needed is a concat with the right operand order.

Add a `moore.builtin.clog2` op and use it to convert `$clog2` calls in
ImportVerilog.
Allow `'{...}` assignment patterns to be used to assign integer values.
Slang already computes the value for each element in the resulting type.
All that's needed is a concat with the right operand order.
Copy link
Member

@maerhart maerhart left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -655,6 +655,8 @@ module Expressions;
bit [1:0][31:0] arrayInt;
// CHECK: %uarrayInt = moore.variable : <uarray<2 x i32>>
bit [31:0] uarrayInt [2];
// CHECK: %m = moore.variable : <l4>
logic [3:0] m;
Copy link
Member

Choose a reason for hiding this comment

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

If you change this to logic [0:3] the concat element order reverses as well, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm good point. I'm not sure what the expected bit order would be in that case 🤔. Intuitively that would make sense. But I also remember the standard mentioning that the array direction doesn't really matter -- e.g. you can't reverse bits by assigning a [0:3] array to a [3:0] array, people usually resort to the streaming operators for that. Time to look through the standard some more 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I just realized that the assignment patterns talk about element indices explicitly: '{3: 'x} will assign bit index 3, regardless of whether the array was declared as [3:0] or [0:3]. And since the Moore dialect removes array directionality (if it becomes important we'll just emit flip ops in the right places), the concat should work as it is now (bit index 3 is always in the same location in the Moore dialect).

Base automatically changed from fschuiki/moore-clog2 to main September 28, 2024 01:40
@fabianschuiki fabianschuiki merged commit a7f1773 into main Sep 28, 2024
4 checks passed
@fabianschuiki fabianschuiki deleted the fschuiki/moore-int-patterns branch September 28, 2024 19:48
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