summaryrefslogtreecommitdiff
path: root/src/test/scala/ChiselTests/MemorySearch.scala
diff options
context:
space:
mode:
authorJim Lawson2015-07-24 17:17:01 -0700
committerJim Lawson2015-07-24 17:17:01 -0700
commite73450165c59d68b524689a7169e03140a41a1c5 (patch)
treeb7236f80d9abf60775ecbcefe6f7ca25557dce73 /src/test/scala/ChiselTests/MemorySearch.scala
parent94893bad972ded686a2c68dd334aa40b92e3b85d (diff)
parent3976145bb8c7595ad0f0a7fbb4ccbbd3030d8873 (diff)
Merge pull request #1 from ucb-bar/packagedir
Packagedir
Diffstat (limited to 'src/test/scala/ChiselTests/MemorySearch.scala')
-rw-r--r--src/test/scala/ChiselTests/MemorySearch.scala43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/test/scala/ChiselTests/MemorySearch.scala b/src/test/scala/ChiselTests/MemorySearch.scala
new file mode 100644
index 00000000..e58005c2
--- /dev/null
+++ b/src/test/scala/ChiselTests/MemorySearch.scala
@@ -0,0 +1,43 @@
+package ChiselTests
+import Chisel._
+
+class MemorySearch extends Module {
+ val io = new Bundle {
+ val target = UInt(INPUT, 4)
+ val en = Bool(INPUT)
+ val done = Bool(OUTPUT)
+ val address = UInt(OUTPUT, 3)
+ }
+ val vals = Array(0, 4, 15, 14, 2, 5, 13)
+ val index = Reg(init = UInt(0, width = 3))
+ val elts = Vec(vals.map(UInt(_,4)))
+ // val elts = Mem(UInt(width = 32), 8)
+ val elt = elts(index)
+ val end = !io.en && ((elt === io.target) || (index === UInt(7)))
+ when (io.en) {
+ index := UInt(0)
+ } .elsewhen (!end) {
+ index := index +% UInt(1)
+ }
+ io.done := end
+ io.address := index
+}
+
+class MemorySearchTester(c: MemorySearch) extends Tester(c) {
+ val list = c.vals
+ val n = 8
+ val maxT = n * (list.length + 3)
+ for (k <- 0 until n) {
+ val target = rnd.nextInt(16)
+ poke(c.io.en, 1)
+ poke(c.io.target, target)
+ step(1)
+ poke(c.io.en, 0)
+ do {
+ step(1)
+ } while (peek(c.io.done) == 0 && t < maxT)
+ val addr = peek(c.io.address).toInt
+ expect(addr == list.length || list(addr) == target,
+ "LOOKING FOR " + target + " FOUND " + addr)
+ }
+}