-
Notifications
You must be signed in to change notification settings - Fork 579
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 ActualDirection calculation from SpecifiedDirection #4205
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,10 +103,13 @@ object ActualDirection { | |
|
||
case class Bidirectional(dir: BidirectionalDirection) extends ActualDirection | ||
|
||
/** Converts a `SpecifiedDirection` to an `ActualDirection` | ||
* | ||
* Implements the Chisel convention that Flip is Input and unspecified is Output. | ||
*/ | ||
def fromSpecified(direction: SpecifiedDirection): ActualDirection = direction match { | ||
case SpecifiedDirection.Unspecified | SpecifiedDirection.Flip => ActualDirection.Unspecified | ||
case SpecifiedDirection.Output => ActualDirection.Output | ||
case SpecifiedDirection.Input => ActualDirection.Input | ||
case SpecifiedDirection.Output | SpecifiedDirection.Unspecified => ActualDirection.Output | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this actually sound ...? Output is coercing all leaf members while Unspecified is not. I dont think this is equivalent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's unstated in the ScalaDoc but this function is only ever used to determine the |
||
case SpecifiedDirection.Input | SpecifiedDirection.Flip => ActualDirection.Input | ||
} | ||
|
||
/** Determine the actual binding of a container given directions of its children. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -493,6 +493,45 @@ class DirectionSpec extends ChiselPropSpec with Matchers with Utils { | |
assert(emitted.contains("connect io.monitor.valid, io.driver.valid")) | ||
assert(emitted.contains("connect io.monitor.ready, io.driver.ready")) | ||
} | ||
|
||
property("Output mixed with unspecified directions should report Output") { | ||
class MyBundle extends Bundle { | ||
val foo = UInt(8.W) | ||
val bar = Output(UInt(8.W)) | ||
} | ||
class MyModule extends RawModule { | ||
val w = Wire(new MyBundle) | ||
assert(DataMirror.specifiedDirectionOf(w) == SpecifiedDirection.Unspecified) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i agree with the tests tho |
||
assert(DataMirror.specifiedDirectionOf(w.foo) == SpecifiedDirection.Unspecified) | ||
assert(DataMirror.specifiedDirectionOf(w.bar) == SpecifiedDirection.Output) | ||
assert(DataMirror.directionOf(w) == Direction.Output) | ||
assert(DataMirror.directionOf(w.foo) == Direction.Output) | ||
assert(DataMirror.directionOf(w.bar) == Direction.Output) | ||
|
||
} | ||
val chirrtl = ChiselStage.emitCHIRRTL(new MyModule) | ||
assert(chirrtl.contains("wire w : { foo : UInt<8>, bar : UInt<8>}")) | ||
} | ||
|
||
property("Input mixed with Flipped directions should report Input") { | ||
class MyBundle extends Bundle { | ||
val foo = Flipped(UInt(8.W)) | ||
val bar = Input(UInt(8.W)) | ||
} | ||
class MyModule extends RawModule { | ||
val w = Wire(new MyBundle) | ||
assert(DataMirror.specifiedDirectionOf(w) == SpecifiedDirection.Unspecified) | ||
assert(DataMirror.specifiedDirectionOf(w.foo) == SpecifiedDirection.Flip) | ||
assert(DataMirror.specifiedDirectionOf(w.bar) == SpecifiedDirection.Input) | ||
assert(DataMirror.directionOf(w) == Direction.Input) | ||
assert(DataMirror.directionOf(w.foo) == Direction.Input) | ||
assert(DataMirror.directionOf(w.bar) == Direction.Input) | ||
|
||
} | ||
val chirrtl = ChiselStage.emitCHIRRTL(new MyModule) | ||
assert(chirrtl.contains("wire w : { flip foo : UInt<8>, flip bar : UInt<8>}")) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is |
||
property("Bugfix: marking Vec fields with mixed directionality as Output/Input clears inner directions") { | ||
class Decoupled extends Bundle { | ||
val bits = UInt(3.W) | ||
|
@@ -559,4 +598,5 @@ class DirectionSpec extends ChiselPropSpec with Matchers with Utils { | |
val emitted: String = ChiselStage.emitCHIRRTL(new MyModule) | ||
assert(emitted.contains("Probe<const UInt<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.
Please add a test to cover this.