blob: 26ee4e033341bd7dc3613e5a83032ff8bf9084e5 (
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
|
// See LICENSE for license details.
package chiselTests
import chisel3._
import org.scalatest._
import org.scalatest.prop._
import chisel3.testers.BasicTester
class MulLookup(val w: Int) extends Module {
val io = IO(new Bundle {
val x = Input(UInt.width(w))
val y = Input(UInt.width(w))
val z = Output(UInt.width(2 * w))
})
val tbl = Vec(
for {
i <- 0 until 1 << w
j <- 0 until 1 << w
} yield UInt(i * j, 2 * w)
)
io.z := tbl(((io.x << w) | io.y))
}
class MulLookupTester(w: Int, x: Int, y: Int) extends BasicTester {
val dut = Module(new MulLookup(w))
dut.io.x := UInt(x)
dut.io.y := UInt(y)
assert(dut.io.z === UInt(x * y))
stop()
}
class MulLookupSpec extends ChiselPropSpec {
property("Mul lookup table should return the correct result") {
forAll(smallPosInts, smallPosInts) { (x: Int, y: Int) =>
assertTesterPasses{ new MulLookupTester(3, x, y) }
}
}
}
|