Skip to content

Commit

Permalink
Support === on empty Aggregate (chipsalliance#3747)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkoenig authored and SpriteOvO committed Jan 20, 2024
1 parent 97e2222 commit d9e2c2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
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

0 comments on commit d9e2c2a

Please sign in to comment.