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

Fix width inferencing issue #952

Merged
merged 10 commits into from
Dec 19, 2018
Merged

Fix width inferencing issue #952

merged 10 commits into from
Dec 19, 2018

Conversation

jackkoenig
Copy link
Contributor

As part of the Bundle literals framework PR, (#820) it appears a minor code refactor accidentally changed the width inference semantics of WireInit and RegInit.

For example

val wire1 = Wire(UInt(8.W))
val wire2 = WireInit(wire1)

prior to #820, wire2 would have it's width inferred. After #820, wire2 gets its width set to 8.

This PR restores the previous behavior and adds some tests that pass prior to #820, fail on current master, and pass on this branch

I noticed this issue while trying to bump Chisel because it changed the functionality of the output FIRRTL ever so slightly but enough to make simulations fail.

Future work is to make similar tests that show and check the width inferencing semantics for other constructors (eg. RegNext, RegEnable), as well as for aggregates (rather than just UInt).

Related issue:

Type of change: bug report & fix

Impact: Undo API modification

Development Phase: implementation

Release Notes
Restore use of width inference to set width of RegInit and WireInit when initialized with a non-literal Bits

@jackkoenig jackkoenig requested a review from ducky64 November 29, 2018 01:57
@jackkoenig jackkoenig requested a review from a team as a code owner November 29, 2018 01:57
@jackkoenig
Copy link
Contributor Author

This passes the tests locally and on CircleCI
@ucbjrl do you know why this is failing?
Maybe same problem with #950?

@@ -507,8 +507,8 @@ object Wire extends WireFactory
object WireInit {
def apply[T <: Data](init: T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T = {
val model = (init match {
// For e.g. Wire(init=0.U(k.W)), fix the Reg's width to k
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 updating the comment. One reason this was able to regress is that I only wrote the comment to cover the special case, and didn't explain the intended semantics for the other cases.

@ducky64
Copy link
Contributor

ducky64 commented Nov 29, 2018

Can you write ScalaDoc that has a summary of the width inference rules for each function?

Off the top of my head I don't see strong reasons for one being more intuitive than the other, so it makes sense to keep compatible behavior, but I also think that being able to express the logic succinctly and intuitively is a good sniff test and benchmark.

@ucbjrl
Copy link
Contributor

ucbjrl commented Nov 29, 2018

This PR (and anything after chipsalliance/firrtl#952) will fail Jenkins build due to the new methods required for the FIRRTL Expression abstract class which currently aren't implemented in the firrtl-interpreter which is built as part of Jenkins chisel3 builds.

@jackkoenig
Copy link
Contributor Author

@ducky64 ScalaDoc and more tests (namely for Reg and Wire) added

Copy link
Contributor

@ducky64 ducky64 left a comment

Choose a reason for hiding this comment

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

Looks good. As for ScalaDoc, would be it be simpler (and equivalent) to say that widths are inferred except when the intializer is a literal with explicit width?

@jackkoenig
Copy link
Contributor Author

jackkoenig commented Dec 17, 2018

I'm open to better wording but AFAICT there really are the 3 cases. Literal Bits (set if width forced), Bits (inferred), and Aggregates (cloned from the Aggregate).

I clarified the ScalaDoc a little bit, and added some to the actual apply methods, including the neat @usecase tag which lets us hide the implicits! Assuming all is okay I'm going to merge this afternoon

@jackkoenig
Copy link
Contributor Author

Oh wait, I think I misunderstood. The "two cases" of Literals with defined width vs. other Bits could be collapsed into one and made more concise

@jackkoenig jackkoenig added this to the 3.2.0 milestone Dec 17, 2018
@ducky64
Copy link
Contributor

ducky64 commented Dec 18, 2018

Yeah, I think it's nicer to have a very concise version, which you can always elaborate (eg edge cases) with illustrative examples. I'm more thinking of what gets a fixed width (only literals with defined width) or not (everything else it seems?).

Should something on bundle literals also be included in the inference rules?

@jackkoenig
Copy link
Contributor Author

I added a shorter summary for single-argument WireInit and RegInit.

We should probably talk about bundle literals, but I'm thinking that can be follow on. I need this bug fix to bump chisel3 in rocket-chip so I would like to merge as soon as possible

Copy link
Contributor

@ducky64 ducky64 left a comment

Choose a reason for hiding this comment

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

Scaladoc looks good, it's pretty clear to me what the rules are.

I still have doubts on whether these are the semantics that should be - it seems like a code smell to have a unique special-case for non-literal-with-explicit-width Bits. But discussing later in the more general context of Bundle literals might be more useful.

@aswaterman
Copy link
Member

Well, the time to reconsider those semantics was probably 2011 or 2012.

@jackkoenig jackkoenig merged commit 416b9d9 into master Dec 19, 2018
@aswaterman aswaterman deleted the fix-width branch January 18, 2019 01:31
jackkoenig pushed a commit that referenced this pull request Feb 28, 2023
* Added Foreachers

* Changed CheckTypes to use foreach

* Check widths now uses foreach

* Finished merge, added foreachers to added stmts

* Address reviewer feedback
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.

4 participants