Skip to content

Commit

Permalink
fixup! Add type ascription to implicits from instantiable (#3615)
Browse files Browse the repository at this point in the history
  • Loading branch information
seldridge committed Nov 4, 2023
1 parent 3a8d7a9 commit 35c1182
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/test/scala/chiselTests/util/SparseVecSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SparseVecTest(addrWidth: Int) extends BasicTester {
val mapping = Seq(
0 -> a,
1 -> b,
15 -> c
2 -> c
)

val size = BigInt(2).pow(addrWidth).toInt
Expand All @@ -45,8 +45,10 @@ class SparseVecTest(addrWidth: Int) extends BasicTester {

sparseVecs.foreach {
case (name, vec) =>
printf(s"$name:\n")
(0 until size).foreach {
case i =>
printf(s" $i: %x =? %x\n", vec(i.U), reference(i.U))
assert(vec(i.U) === reference(i.U), s"failed index $i")
}
}
Expand All @@ -55,8 +57,35 @@ class SparseVecTest(addrWidth: Int) extends BasicTester {

}

class Old extends RawModule {
val addr = IO(Input(UInt(1.W)))
val a = IO(Input(Vec(1, Bool())))
val b = IO(Output(Bool()))

b := a(addr)
}

class New extends RawModule {
val addr = IO(Input(UInt(1.W)))
val a = IO(Input(Vec(1, Bool())))
val b = IO(Output(Bool()))

private val vec = SparseVec.onehot(
2,
Seq(
0 -> a(0)
)
)

b := vec(addr)
}

class SparseVecSpec extends ChiselFlatSpec with Utils {
"SparseVec" should "work" in {
assertTesterPasses(new SparseVecTest(4))
}
it should "be exactly equivalent to a dynamic index" in {
ChiselStage.emitSystemVerilog(new Old) should include("assign b = a_0")
ChiselStage.emitSystemVerilog(new New) should include("assign b = a_0")
}
}

0 comments on commit 35c1182

Please sign in to comment.