-
Notifications
You must be signed in to change notification settings - Fork 603
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
Add scanLeftOr and scanRightOr utilies #2407
Conversation
79cd50d
to
5b3576c
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.
Generally LGTM, name of this: LSBOr
or lsbOr
or LsbOr
should have an alignment to chisel standard library.
integration-tests/src/test/scala/chiselTests/util/experimental/algorithm/Bitwise.scala
Show resolved
Hide resolved
integration-tests/src/test/scala/chiselTests/util/experimental/algorithm/Bitwise.scala
Show resolved
Hide resolved
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
287cf00
to
a07fb8f
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.
LGTM.
I think we need to discuss the package name on dev-meeting, hold it till next Monday |
integration-tests/src/test/scala/chiselTests/util/experimental/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
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.
feedback form dev-meeting.
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
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.
Okay, done bike shedding. We should
- Name them
scanLeftOr
andscanRightOr
to use consistent terminology with sequence traversals. - As far as the implementation, we should use the original from rocket-chip which is
O(lg(n))
in node count vs.O(n^2)
for this current implementation (note my implementation usingscanLeft
isO(n)
)[1].
Per QoR concerns, if someone provides compelling physical design results we can revisit. That being said, SiFive has been building high performance designs using the rocket-chip utility so I doubt there's an issue in proprietary ASIC tools but I will grant that there may be problems using open-source.
[1] Table of node count:
Implementation | Width | Chirrtl Lines | Verilog Lines |
---|---|---|---|
rocket-chip | 8 | 18 | 13 |
16 | 21 | 15 | |
32 | 24 | 17 | |
64 | 27 | 19 | |
this | 8 | 168 | 25 |
16 | 584 | 41 | |
32 | 2184 | 89 | |
64 | 8456 | 241 | |
scanLeft | 8 | 40 | 17 |
16 | 72 | 29 | |
32 | 136 | 52 | |
64 | 264 | 104 |
integration-tests/src/test/scala/chiselTests/util/experimental/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
integration-tests/src/test/scala/chiselTests/util/experimental/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
Ok coming in just at the end of this, I'm confused by:
So is the "Left" relative to a UInt w/ value 0xA written out in binary: Reading the above I think we're saying it's the second one. Can we just make it you can't actually call this on a UInt, only on a Vec[Bool]? Then the confusion basically goes away. And I liked the suggestion of calling it scanUpOr when applied to a UInt. Anyway, I'm late to the bikeshed painting party so feel free to ignore my input :) |
"Left" means low index to high index in sequences (in every language with traversals, think Thus my argument is to stick with Left/Right and just explain it. It's consistent and we're not making up new terminology.
No, the whole purpose of this API is that it's useful on *I want to note that this sort of ambiguity exists in basically every language. The main difference here is that most languages don't have iteration on bits or digits of numbers. This does suggest that it would be reasonable to invent new terminology (and I think Up/Down is pretty good). The main counterargument is consistency between UInts and Vecs (given that a hypothetical |
SGTM. Let me know when I can review the scaladoc :) |
ebe21a3
to
e6fab50
Compare
Actually that's a great way to explain the usage or "left" and "right" here. I've added it to the documentation. |
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
e6fab50
to
abe65fc
Compare
Co-authored-by: Jiuyang Liu <liu@jiuyang.me>
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
Co-authored-by: Megan Wachs <megan@sifive.com> Co-authored-by: Jack Koenig <jack.koenig3@gmail.com>
I do think we need a CI to reformat on pulls:( |
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.
can we update the title of this PR to match the new names?
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
integration-tests/src/test/scala/chiselTests/util/experimental/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
integration-tests/src/test/scala/chiselTests/util/experimental/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
integration-tests/src/test/scala/chiselTests/util/experimental/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
integration-tests/src/test/scala/chiselTests/util/experimental/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
src/main/scala/chisel3/experimental/util/algorithm/Bitwise.scala
Outdated
Show resolved
Hide resolved
I removed the comparison to shift left because I didn't love the phrasing. I think we should revisit in another PR. Also run scalafmt.
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.
LGTM. I deleted the comparison to "shift left" because I think it's more confusing than helpful. I would argue that one could think about "shift left" as shifting from left to right where left is low-order bits, but no one actually does.
I also changed the package to chisel3.util
. I'm confident enough in this API that there's no need for experimental.
Thank you @CircuitCoder for your contribution and perseverance at getting this very useful API merged! |
Co-authored-by: Jiuyang Liu <liu@jiuyang.me> Co-authored-by: Megan Wachs <megan@sifive.com> Co-authored-by: Jack Koenig <koenig@sifive.com> (cherry picked from commit 73d3c26)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Contributor Checklist
docs/src
?Type of Improvement
new feature/API
API Impact
Add utility
LSBOr
andMSBOr
similar to rocket-chip'sleftOr
andrightOr
. These functions are generally very useful and can be used to implementing other useful utilities such as bitfield arbitrationBackend Code Generation Impact
N/A
Desired Merge Strategy
Rebase
Release Notes
Add experimental utility
LSBOr
andMSBOr
.Reviewer Checklist (only modified by reviewer)
3.4.x
, [small] API extension:3.5.x
, API modification or big change:3.6.0
)?Please Merge
?