-
Notifications
You must be signed in to change notification settings - Fork 631
Add support for zero-width bit extraction #3352
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
Conversation
} | ||
val w = x - y + 1 | ||
val resultWidth = x - y + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed this because there is variable name shadowing going on inside that getOrElse
(hit expand to see it) and it confused me.
68e812e
to
f2ea702
Compare
f2ea702
to
726c06d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I endorse the API and from experience know that not having this special case results in large amounts of boilerplate--which is itself likely to introduce additional bugs, sometimes as a result of code clutter.
(cherry picked from commit b910bf9) # Conflicts: # core/src/main/scala/chisel3/Bits.scala
(cherry picked from commit b910bf9)
(cherry picked from commit b910bf9) Co-authored-by: Jack Koenig <[email protected]>
For my entire 7-year chisel career, this has been a thorn in my side. Thank you. Thank you so much. |
Why doesn't 😡 |
Also awful is that the work-around method ( Relatedly, 0.U really ought to have 0.W by default, not 1.W. This is the root cause of that |
IMO, we should change Chisel to allow e.g. |
With #3321, it becomes very important that users can extract zero bits. While the
(-1, 0)
looks a little funny, it is the correct API for parameterized code.Motivating example:
(Scastie link: https://scastie.scala-lang.org/d6prKTmSRgeo2wOJErImTQ)
This change makes the extraction from
(-1, 0)
legal. We could make the extraction for anyhi = lo - 1
legal, but I am concerned about users accidentally writing things likemyUInt(5, 6)
when they meantmyUInt(6, 5)
. So instead, Chisel will give a specific suggestion in that case:The user should instead write:
We will soon also add
.take
which will make it possible to write(myUInt >> y).take(x - y)
Note all of this is static so there is no hardware overhead to the shift.
Contributor Checklist
docs/src
?Type of Improvement
Desired Merge Strategy
Release Notes
Reviewer Checklist (only modified by reviewer)
3.5.x
or3.6.x
depending on impact, API modification or big change:5.0.0
)?Enable auto-merge (squash)
, clean up the commit message, and label withPlease Merge
.Create a merge commit
.