summaryrefslogtreecommitdiff
path: root/src/test/scala/ChiselTests/ComplexAssign.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/ComplexAssign.scala
parent94893bad972ded686a2c68dd334aa40b92e3b85d (diff)
parent3976145bb8c7595ad0f0a7fbb4ccbbd3030d8873 (diff)
Merge pull request #1 from ucb-bar/packagedir
Packagedir
Diffstat (limited to 'src/test/scala/ChiselTests/ComplexAssign.scala')
-rw-r--r--src/test/scala/ChiselTests/ComplexAssign.scala40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/test/scala/ChiselTests/ComplexAssign.scala b/src/test/scala/ChiselTests/ComplexAssign.scala
new file mode 100644
index 00000000..fb335aed
--- /dev/null
+++ b/src/test/scala/ChiselTests/ComplexAssign.scala
@@ -0,0 +1,40 @@
+package ChiselTests
+import Chisel._
+
+class Complex[T <: Data](val re: T, val im: T, dir: Direction = OUTPUT)
+ extends Bundle(dir) {
+ override def doCloneType: this.type =
+ new Complex(re.cloneType, im.cloneType, dir).asInstanceOf[this.type]
+}
+
+class ComplexAssign(W: Int) extends Module {
+ val io = new Bundle {
+ val e = new Bool(INPUT)
+ val in = new Complex(Bits(width = W), Bits(width = W), INPUT)
+ val out = new Complex(Bits(width = W), Bits(width = W), OUTPUT)
+ }
+ when (io.e) {
+ val w = Wire(new Complex(Bits(width = W), Bits(width = W)))
+ w := io.in
+ io.out.re := w.re
+ io.out.im := w.im
+ } .otherwise {
+ io.out.re := Bits(0)
+ io.out.im := Bits(0)
+ }
+}
+
+class ComplexAssignTester(c: ComplexAssign) extends Tester(c) {
+ for (t <- 0 until 4) {
+ val test_e = rnd.nextInt(2)
+ val test_in_re = rnd.nextInt(256)
+ val test_in_im = rnd.nextInt(256)
+
+ poke(c.io.e, test_e)
+ poke(c.io.in.re, test_in_re)
+ poke(c.io.in.im, test_in_im)
+ step(1)
+ expect(c.io.out.re, if (test_e == 1) test_in_re else 0)
+ expect(c.io.out.im, if (test_e == 1) test_in_im else 0)
+ }
+}