Skip to content

Commit

Permalink
Fix SyncReadMem.read; add test (#796)
Browse files Browse the repository at this point in the history
SyncReadMem.read with an enable signal currently only works in
compatibility mode, where Wires are implicitly initialized to
DontCare.  Fix by explicitly assigning DontCare to the Wire.

This might fix #775.
  • Loading branch information
aswaterman committed Mar 7, 2018
1 parent 9169381 commit a4aa392
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions chiselFrontend/src/main/scala/chisel3/core/Mem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ sealed class SyncReadMem[T <: Data](t: T, n: Int) extends MemBase[T](t, n) {

def do_read(addr: UInt, enable: Bool)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T = {
val a = Wire(UInt())
a := DontCare
var port: Option[T] = None
when (enable) {
a := addr
Expand Down
18 changes: 18 additions & 0 deletions src/test/scala/chiselTests/Mem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,26 @@ class MemVecTester extends BasicTester {
}
}

class SyncReadMemTester extends BasicTester {
val (cnt, _) = Counter(true.B, 5)
val mem = SyncReadMem(2, UInt(2.W))
val rdata = mem.read(cnt - 1.U, cnt =/= 0.U)

switch (cnt) {
is (0.U) { mem.write(cnt, 3.U) }
is (1.U) { mem.write(cnt, 2.U) }
is (2.U) { assert(rdata === 3.U) }
is (3.U) { assert(rdata === 2.U) }
is (4.U) { stop() }
}
}

class MemorySpec extends ChiselPropSpec {
property("Mem of Vec should work") {
assertTesterPasses { new MemVecTester }
}

property("SyncReadMem should work") {
assertTesterPasses { new SyncReadMemTester }
}
}

0 comments on commit a4aa392

Please sign in to comment.