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

Support === on empty Aggregates #3747

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions core/src/main/scala/chisel3/Data.scala
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,8 @@ object Data {
thiz.elementsIterator
.zip(that.elementsIterator)
.map { case (thisData, thatData) => thisData === thatData }
.reduce(_ && _)
.reduceOption(_ && _) // forall but that isn't defined for Bool on Seq
.getOrElse(true.B)
}
case (thiz: Record, that: Record) =>
if (thiz._elements.size != that._elements.size) {
Expand All @@ -932,7 +933,8 @@ object Data {
)
}
}
.reduce(_ && _)
.reduceOption(_ && _) // forall but that isn't defined for Bool on Seq
.getOrElse(true.B)
}
// This should be matching to (DontCare, DontCare) but the compiler wasn't happy with that
case (_: DontCare.type, _: DontCare.type) => true.B
Expand Down
19 changes: 19 additions & 0 deletions src/test/scala/chiselTests/DataEqualitySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class DataEqualitySpec extends ChiselFlatSpec with Utils {
val a = UInt(8.W)
val b: Bundle = gen
}
class MaybeEmptyBundle(x: Boolean) extends Bundle {
val a = Option.when(x)(UInt(8.W))
}

behavior.of("UInt === UInt")
it should "pass with equal values" in {
Expand Down Expand Up @@ -140,6 +143,14 @@ class DataEqualitySpec extends ChiselFlatSpec with Utils {
)
}
}
it should "support empty Vecs" in {
assertTesterPasses {
new EqualityTester(
Wire(Vec(0, UInt(8.W))),
Wire(Vec(0, UInt(8.W)))
)
}
}
it should "fail with equal sizes, differing values" in {
assertTesterFails {
new EqualityTester(
Expand Down Expand Up @@ -168,6 +179,14 @@ class DataEqualitySpec extends ChiselFlatSpec with Utils {
)
}
}
it should "support empty Bundles" in {
assertTesterPasses {
new EqualityTester(
(new MaybeEmptyBundle(false)).Lit(),
(new MaybeEmptyBundle(false)).Lit()
)
}
}
it should "fail with equal type, differing values" in {
assertTesterFails {
new EqualityTester(
Expand Down
Loading