diff options
| author | Jim Lawson | 2015-05-11 13:02:03 -0700 |
|---|---|---|
| committer | Jim Lawson | 2015-07-24 15:50:53 -0700 |
| commit | 2ae50411cbc5e2cd5fdc9ca4069b9c5f64919bc4 (patch) | |
| tree | a656e44d86a68a7c53b159fe6c74d328a126126d /src/test/scala/ChiselTests/ComplexAssign.scala | |
| parent | b208bfb5691c7b5921dd47d0b599726872acd1cd (diff) | |
Incorporate chisel3-tests; update Makefile.
Diffstat (limited to 'src/test/scala/ChiselTests/ComplexAssign.scala')
| -rw-r--r-- | src/test/scala/ChiselTests/ComplexAssign.scala | 40 |
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..ee0cd0d3 --- /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 cloneType: 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) + } +} |
