summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/MulLookup.scala
diff options
context:
space:
mode:
authorHenry Cook2015-08-14 00:53:57 -0700
committerHenry Cook2015-08-14 00:53:57 -0700
commit5e9be183f98d32164332fa0548fe80686f50c851 (patch)
tree03fd0f52b35e6c194077a0b94d03fa3a6ddc26d9 /src/test/scala/chiselTests/MulLookup.scala
parentcaf993c89ba07a65d05b0e17d109a60f96330136 (diff)
added MulLookup and Tbl tests
Diffstat (limited to 'src/test/scala/chiselTests/MulLookup.scala')
-rw-r--r--src/test/scala/chiselTests/MulLookup.scala38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/MulLookup.scala b/src/test/scala/chiselTests/MulLookup.scala
new file mode 100644
index 00000000..1fe77a93
--- /dev/null
+++ b/src/test/scala/chiselTests/MulLookup.scala
@@ -0,0 +1,38 @@
+package chiselTests
+
+import Chisel._
+import org.scalatest._
+import org.scalatest.prop._
+import Chisel.testers.BasicTester
+
+class MulLookup(val w: Int) extends Module {
+ val io = new Bundle {
+ val x = UInt(INPUT, w)
+ val y = UInt(INPUT, w)
+ val z = UInt(OUTPUT, 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 MulLookupSpec extends ChiselPropSpec {
+
+ 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)
+ io.done := Bool(true)
+ io.error := dut.io.z != UInt(x * y)
+ }
+
+ property("Mul lookup table should return the correct result") {
+ forAll(smallPosInts, smallPosInts) { (x: Int, y: Int) =>
+ assert(execute{ new MulLookupTester(3, x, y) })
+ }
+ }
+}