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

handle simple assignments patterns on left-hand-side (lhs) #47

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

anders-code
Copy link
Contributor

logic [31:0]data[4], a, b, c, d;
assign '{ a, b, c, d } = data;

    logic [31:0]data[4], a, b, c, d;
    assign '{ a, b, c, d } = data;
@anders-code anders-code marked this pull request as draft September 7, 2024 02:03
@anders-code
Copy link
Contributor Author

This seems to work OK for simple cases. I'm not sure it's the right way to implement it. It appears the SimpleAssignmentPattern AST node usually contains an embedded Assignment expression, but it can contain a few other things on the LHS, including an unpacked concatenation.

What should happen is when an array is on the RHS, each array element should map to one of the top level items in the pattern expression. But since it appears that the existing logic simply flattens all the packed and unpacked dimensions out, if the LHS item is a different size than RHS, the lengths no longer match.

Is there a better way to do this? Perhaps create multiple assignments in RTLIL?

@povik
Copy link
Owner

povik commented Sep 11, 2024

I'm not sure it's the right way to implement it. It appears the SimpleAssignmentPattern AST node usually contains an embedded Assignment expression, but it can contain a few other things on the LHS, including an unpacked concatenation.

FWIW the constant evaluation code in slang can be used as a reference https://github.com/MikePopoloski/slang/blob/d077ed831335f9c6f3020861eb68c18ab476a44e/source/ast/expressions/AssignmentExpressions.cpp#L1628 but it needs some digging into to understand.

I can look into this more when I find time.

Is there a better way to do this? Perhaps create multiple assignments in RTLIL?

To keep the complexity low we should keep describing the entirety of the LHS with a single SigSpec, possibly introducing dummy wires for padding. That should always be possible.

@anders-code
Copy link
Contributor Author

To keep the complexity low we should keep describing the entirety of the LHS with a single SigSpec, possibly introducing dummy wires for padding. That should always be possible.

will look into this idea. it might be tricky to determine without visiting both halves. ugh, this area of SV is tricky.

@povik
Copy link
Owner

povik commented Sep 15, 2024

To keep the complexity low we should keep describing the entirety of the LHS with a single SigSpec, possibly introducing dummy wires for padding. That should always be possible.

OK, so this isn't always possible thanks to sign extension. Take the following:

logic signed [3:0] data[1];
logic signed [5:0] a;
assign '{ a } = data;

We cannot describe the LHS with a SigSpec which would match the bit length of the RHS since the top bit needs to be assigned to all of a[5:3].

@povik
Copy link
Owner

povik commented Sep 20, 2024

I've started work on this feature in 79c1616. The expr.sv test happened to have found a bug in slang's constant evaluator: MikePopoloski/slang#1123

TODO:

  • fill in the testing for mismatched size (pending the slang issue is fixed)
  • support non-procedural LHS

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