-
Notifications
You must be signed in to change notification settings - Fork 639
Unify Chisel2 and chisel3 directionality #2634
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
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 looks good but I would like to see more examples showing what is now possible.
Also should there be something in docs/
for this?
… and how Input/Output can interoperate with Flipped
So I could write docs, but I kind of want to wait until we actually add the new operators/primitives, then its easier to describe it. As is, all the docs are still technically correct, and this interoperability doesn't need to be advertised yet. |
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.
Overall LGTM, 1 suggested improvement to a comment and 1 nit
Co-authored-by: Jack Koenig <koenig@sifive.com>
Can you fill out the release notes? What is THIS PR actually doing? |
I thought I did?
|
@azidar Since there seem to be many ways of doing things, would you mind documenting, what the recommended style is? Maybe at least update the examples in our readme which should probably be updated anyways to take advantage of the Would the Blinky example now be?: class Blinky(freq: Int, startOn: Boolean = false) extends Module {
val led0 = Outgoing(Bool())
// Blink LED every second using Chisel built-in util.Counter
val led = RegInit(startOn.B)
val (_, counterWrap) = Counter(true.B, freq / 2)
when(counterWrap) {
led := ~led
}
led0 := led
} |
I believe your Blinky example is correct, but we haven't actually added Perhaps what would help is if I wrote up an actual proposal that we can discuss? |
Yep release notes look good now |
That's why I copied all the good write up above into its own issue :) #2643 |
Did we consider backporting this to 3.5? I know it's strictly a change in behavior, but its a more-things-work-instead-of-being errors which might help in upgrading. |
assigning this to 3.5.x milestone to attempt opening a backport there |
Co-authored-by: Jack Koenig <koenig@sifive.com> (cherry picked from commit 1aea4ef) # Conflicts: # core/src/main/scala/chisel3/Aggregate.scala # core/src/main/scala/chisel3/Module.scala # src/test/scala/chiselTests/Direction.scala
* Unify Chisel2 and chisel3 directionality (#2634) Co-authored-by: Jack Koenig <koenig@sifive.com> (cherry picked from commit 1aea4ef) # Conflicts: # core/src/main/scala/chisel3/Aggregate.scala # core/src/main/scala/chisel3/Module.scala # src/test/scala/chiselTests/Direction.scala * fix up backport * fix up backport * clean up diff * make test order like it was on master Co-authored-by: Adam Izraelevitz <adam.izraelevitz@sifive.com> Co-authored-by: Megan Wachs <megan@sifive.com>
Background:
Chisel._
vschisel3._
directionalityIn
Chisel._
,IO
has an implicit output direction, andFlipped
is used for two things:You can declare an input port using the (2) kind of Flipped:
In
chisel3
,IO
does not have an implicit direction, butInput
andOutput
are specified on types, which coerce all subfields of the type to the same direction.Flipped
inverts the absolute direction soInput -> Output
andOutput -> Input
.You can switch directions with
Flipped
:Unifying directionality with new primitives
Both mechanisms of describing field directions can be unified with the following (conceptual) primitives:
Flipped
: a field's relative direction is reversed with respect to its parent bundleAligned
: a field's relative direction is the same with respect to its parent bundle (is implicit)Outgoing
: an IO whose implicit direction is outputIncoming
: an IO whose implicit direction is inputstripFlipsOf
: a type-generator that aligns all subfields, recursivelyreverseFlipsOf
: a type-generator that flips all subfields, recursivelyExpressing Chisel._ semantics:
IO(new Bundle))
becomesOutgoing(new Bundle)
IO(Flipped(new Bundle))
becomesIncoming(new Bundle)
; note thatOutgoing(reverseFlipsOf(new Bundle))
is the same, but I think it makes sense to haveIncoming
as well.new Bundle { val x = UInt() }
isnew Bundle { val x = Aligned(UInt()) }
, or unchanged asAligned
is implicitnew Bundle { val x = Flipped(UInt()) }
is unchangedExpressing chisel3._ semantics:
IO(new Bundle))
becomesOutgoing(new Bundle)
IO(Flipped(new Bundle))
becomesIncoming(new Bundle)
new Bundle { val x = Output(UInt()) }
isnew Bundle { val x = Aligned(stripFlipsOf(UInt())) }
new Bundle { val x = Input(UInt()) }
isnew Bundle { val x = Flipped(stripFlipsOf(UInt())) }
How this PR unifies these things
Just like we can express Chisel/chisel3 with new primitives, we can represent the new primitives with Chisel/chisel3 APIs. The only thing that was missing was (1) ALWAYS apply the implicit output from IO (or implicit input if a flip is there), and (2) enable mixing Input/Output with Flipped. This means that effectively,
Input
becomesFlipped(stripsFlipsOf(..))
andOutput
becomesAligned(stripsFlipsOf(..))
, and now the semantics can coexist. Basically, this change defines howChisel._
's relative directions resolve inchisel3
. This should not break any code, because previously it was an error.Future work will be to add the new primitives as they are, and refactor Input/Output etc to just call the new primitives. In the meantime, we can change the semantics so that this change is easier, and we can get rid of compatibility mode.
Contributor Checklist
docs/src
? Will do this later when we add more primitivesType of Improvement
API Impact
Adds an API, where you can now declare bundles that have both Flipped and Input/Output.
Backend Code Generation Impact
None
Desired Merge Strategy
Release Notes
Remove restriction that Bundles have to only declare fields with absolute directions (Input/Output) or relative directions (Flipped).
Reviewer Checklist (only modified by reviewer)
3.4.x
, [small] API extension:3.5.x
, API modification or big change:3.6.0
)?Enable auto-merge (squash)
, clean up the commit message, and label withPlease Merge
.Create a merge commit
.