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

verilog: indirect AST_CONCAT and AST_TO_UNSIGNED port connections #4201

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zachjs
Copy link
Collaborator

@zachjs zachjs commented Feb 11, 2024

  • AST_CONCAT and AST_TO_UNSIGNED are always unsigned, but may generate RTLIL that exclusively reference a signed wire.
  • AST_CONCAT may also contain a memory write.

Fixes #4158.

@zachjs zachjs requested a review from povik February 11, 2024 19:43
lookup_suggested = true;
else if (value->type == AST_CONCAT && value->children.size() == 1)
// concat of a single expression is equivalent to $unsigned
lookup_suggested = true;
Copy link
Member

Choose a reason for hiding this comment

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

OK, so suggesting a lookup here will make us indirect all port connections that are not connections to a plain identifier.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct. Is this problematic? Should I clarify the surrounding code?

Copy link
Member

Choose a reason for hiding this comment

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

Well, the intent wasn't really obvious the first moment I looked at this if (type == AST_CELL) { branch, so any clarification would be nice. Though I wouldn't consider it required for the PR.

else
// unless this instantiation depends on module
// information that isn't available yet
if (!attributes.count(ID::reprocess_after))
log_assert(arg->is_signed == sig.as_wire()->is_signed);
Copy link
Member

Choose a reason for hiding this comment

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

So what we are checking here is: does the wire we are connecting have an is_signed flag matching the signedness of the expression in the connection?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's correct. Should I clarify this comment?

Copy link
Member

Choose a reason for hiding this comment

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

No need I think, I am primarily checking my understanding of what happens here, and maybe leaving some notes for anyone else who would look at the PR.

assign out = v[0];
logic [3:0] v[1:0];
producer p0(v[0]);
producer p1({v[1]});
Copy link
Member

Choose a reason for hiding this comment

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

I am not clear on how the code change interacts with this example. We seem to be addressing signedness mismatches, but there's not a signed variable in sight here.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I think this has to do with the fact that memory writes need to be indirected, for reasons unrelated to signedness, but if wrapped in an AST_CONCAT they did not trigger the indirection previously.

Copy link
Member

Choose a reason for hiding this comment

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

But if that's the case, shouldn't we trigger the indirection in all cases of AST_CONCAT, not only those with children.size() == 1?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right! I'll address this.

zachjs added 2 commits April 14, 2024 11:56
- AST_CONCAT and AST_TO_UNSIGNED are always unsigned, but may generate
  RTLIL that exclusively reference a signed wire.
- AST_CONCAT may also contain a memory write.
@zachjs zachjs requested a review from povik April 14, 2024 18:03
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.

Assert `arg->is_signed == sig.as_wire()->is_signed' failed
2 participants