diff options
Diffstat (limited to 'src/test/scala/ChiselTests/GCD.scala')
| -rw-r--r-- | src/test/scala/ChiselTests/GCD.scala | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/scala/ChiselTests/GCD.scala b/src/test/scala/ChiselTests/GCD.scala new file mode 100644 index 00000000..2702aaec --- /dev/null +++ b/src/test/scala/ChiselTests/GCD.scala @@ -0,0 +1,31 @@ +package ChiselTests +import Chisel._ + +class GCD extends Module { + val io = new Bundle { + val a = Bits(INPUT, 16) + val b = Bits(INPUT, 16) + val e = Bool(INPUT) + val z = Bits(OUTPUT, 16) + val v = Bool(OUTPUT) + } + val x = Reg(Bits(width = 16)) + val y = Reg(Bits(width = 16)) + when (x > y) { x := x -% y } + .otherwise { y := y -% x } + when (io.e) { x := io.a; y := io.b } + io.z := x + io.v := y === Bits(0) +} + +class GCDTester(c: GCD) extends Tester(c) { + val (a, b, z) = (64, 48, 16) + do { + val first = if (t == 0) 1 else 0; + poke(c.io.a, a) + poke(c.io.b, b) + poke(c.io.e, first) + step(1) + } while (t <= 1 || peek(c.io.v) == 0) + expect(c.io.z, z) +} |
