summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/MemorySearch.scala
blob: befbf01093b2c97e9c81f261bd296c08853c2d67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// See LICENSE for license details.

package chiselTests

import chisel3._
import chisel3.testers.BasicTester

class MemorySearch extends Module {
  val io = IO(new Bundle {
    val target  = Input(UInt(4.W))
    val en      = Input(Bool())
    val done    = Output(Bool())
    val address = Output(UInt(3.W))
  })
  val vals  = Array(0, 4, 15, 14, 2, 5, 13)
  val index = Reg(init = 0.U(3.W))
  val elts  = Vec(vals.map(UInt(_,4)))
  // val elts  = Mem(UInt(32.W), 8) TODO ????
  val elt  = elts(index)
  val end  = !io.en && ((elt === io.target) || (index === 7.U))
  when (io.en) {
    index := 0.U
  } .elsewhen (!end) {
    index := index +% 1.U
  }
  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)
  }
}
*/

class MemorySearchSpec extends ChiselPropSpec {

  property("MemorySearch should elaborate") {
    elaborate { new EnableShiftRegister }
  }

  ignore("MemorySearch should return the correct result") { }
}