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
|
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)
}
}
|