summaryrefslogtreecommitdiff
path: root/src/test/scala/ChiselTests/Tbl.scala
blob: 390f58827df1443a5a24778d198036ebd689f83c (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
package ChiselTests
import Chisel._

class Tbl extends Module {
  val io = new Bundle {
    val  i  = Bits(INPUT,  16)
    val we  = Bool(INPUT)
    val  d  = Bits(INPUT,  16)
    val  o  = Bits(OUTPUT, 16)
  }
  val m = Mem(Bits(width = 10), 256)
  io.o := Bits(0)
  when (io.we) { m(io.i) := io.d(9, 0) }
  .otherwise   { io.o := m(io.i) }
}

class TblTester(c: Tbl) extends Tester(c) {
  val m = Array.fill(1 << 16){ 0 }
  for (t <- 0 until 16) {
    val i  = rnd.nextInt(1 << 16)
    val d  = rnd.nextInt(1 << 16)
    val we = rnd.nextInt(2)
    poke(c.io.i,   i)
    poke(c.io.we, we)
    poke(c.io.d,   d)
    step(1)
    expect(c.io.o, if (we == 1) 0 else m(i))
    if (we == 1)
      m(i) = d
  }
}