Skip to content

Commit a4aa392

Browse files
authored
Fix SyncReadMem.read; add test (#796)
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.
1 parent 9169381 commit a4aa392

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

chiselFrontend/src/main/scala/chisel3/core/Mem.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ sealed class SyncReadMem[T <: Data](t: T, n: Int) extends MemBase[T](t, n) {
156156

157157
def do_read(addr: UInt, enable: Bool)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T = {
158158
val a = Wire(UInt())
159+
a := DontCare
159160
var port: Option[T] = None
160161
when (enable) {
161162
a := addr

src/test/scala/chiselTests/Mem.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,26 @@ class MemVecTester extends BasicTester {
1919
}
2020
}
2121

22+
class SyncReadMemTester extends BasicTester {
23+
val (cnt, _) = Counter(true.B, 5)
24+
val mem = SyncReadMem(2, UInt(2.W))
25+
val rdata = mem.read(cnt - 1.U, cnt =/= 0.U)
26+
27+
switch (cnt) {
28+
is (0.U) { mem.write(cnt, 3.U) }
29+
is (1.U) { mem.write(cnt, 2.U) }
30+
is (2.U) { assert(rdata === 3.U) }
31+
is (3.U) { assert(rdata === 2.U) }
32+
is (4.U) { stop() }
33+
}
34+
}
35+
2236
class MemorySpec extends ChiselPropSpec {
2337
property("Mem of Vec should work") {
2438
assertTesterPasses { new MemVecTester }
2539
}
40+
41+
property("SyncReadMem should work") {
42+
assertTesterPasses { new SyncReadMemTester }
43+
}
2644
}

0 commit comments

Comments
 (0)