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

[FIRRTLUtils] Fix walkDrivers subfield id calculation #7536

Merged
merged 2 commits into from
Sep 3, 2024

Conversation

uenoku
Copy link
Member

@uenoku uenoku commented Aug 20, 2024

This fixes an overflow in walkDrivers when field ID is zero.

Fix chipsalliance/chisel#4354 and #7423.

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.

LGTM

Comment on lines 54 to 69
%foo = firrtl.wire : !firrtl.vector<uint<1>, 1>
%0 = firrtl.subindex %foo[0] : !firrtl.vector<uint<1>, 1>
%c1_ui1 = firrtl.constant 1 : !firrtl.uint<1>
firrtl.matchingconnect %0, %c1_ui1 : !firrtl.uint<1>
%bar = firrtl.wire : !firrtl.vector<vector<uint<1>, 1>, 1>
%1 = firrtl.subindex %bar[0] : !firrtl.vector<vector<uint<1>, 1>, 1>
%2 = firrtl.subindex %foo[0] : !firrtl.vector<uint<1>, 1>
%3 = firrtl.subindex %1[0] : !firrtl.vector<uint<1>, 1>
firrtl.matchingconnect %3, %2 : !firrtl.uint<1>
// Check that firrtl.regreset is not transformed into reg op if wire is not invalid
// CHECK: firrtl.regreset
%x = firrtl.regreset %clock, %reset, %bar : !firrtl.clock, !firrtl.uint<1>, !firrtl.vector<vector<uint<1>, 1>, 1>, !firrtl.vector<vector<uint<1>, 1>, 1>
%4 = firrtl.subindex %x[0] : !firrtl.vector<vector<uint<1>, 1>, 1>
%5 = firrtl.subindex %4[0] : !firrtl.vector<uint<1>, 1>
firrtl.matchingconnect %5, %5 : !firrtl.uint<1>
}
Copy link
Member

Choose a reason for hiding this comment

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

Mega-nit: this test is a bit verbose and could be worth golfing down for maintainability.

Comment on lines +460 to +466
// If fieldID is zero, this points to entire subfields.
if (fieldID == 0)
workStack.emplace_back(subOriginal, subRef, value, 0);
else {
assert(fieldID >= subID);
workStack.emplace_back(subOriginal, subRef, value, fieldID - subID);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

There might be the case that fieldID < subID so this fix may not work too.. :) Thank you @dtzWill for pointing it out!

@youngar
Copy link
Member

youngar commented Aug 29, 2024

Trying to refresh my memory on how this code works - still pretty hazy but I think your fix makes sense. Once the fieldID hits 0 we have found the field we are "interested in" and we should examine/include all further subfields.

@dtzSiFive
Copy link
Contributor

I was not sure and the test case from the issue IIRC didn't run into a case where either was true (the >= assertion). Poking at it some more, I think this is right, especially if @youngar thinks so too.
The other direction is handled by chasing to the root of the source, AFAICT.

Thanks!

@uenoku
Copy link
Member Author

uenoku commented Sep 3, 2024

Thank you for review!

@uenoku uenoku merged commit ac008b1 into main Sep 3, 2024
4 checks passed
@uenoku uenoku deleted the dev/hidetou/fix-sfccompat branch September 3, 2024 15:50
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.

2D-Vec RegInit doesn't initialize
4 participants