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/Pads.scala | |
| parent | b208bfb5691c7b5921dd47d0b599726872acd1cd (diff) | |
Incorporate chisel3-tests; update Makefile.
Diffstat (limited to 'src/test/scala/ChiselTests/Pads.scala')
| -rw-r--r-- | src/test/scala/ChiselTests/Pads.scala | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/scala/ChiselTests/Pads.scala b/src/test/scala/ChiselTests/Pads.scala new file mode 100644 index 00000000..a5c03d0b --- /dev/null +++ b/src/test/scala/ChiselTests/Pads.scala @@ -0,0 +1,28 @@ +package ChiselTests +import Chisel._ + +class Pads extends Module { + val io = new Bundle { + val a = Bits(INPUT, 4) + val asp = Bits(OUTPUT, 8) + val aup = Bits(OUTPUT, 8) + } + io.asp := io.a.toSInt + io.aup := io.a.toUInt +} + +class PadsTester(c: Pads) extends Tester(c) { + def pads(x: BigInt, s: Int, w: Int) = { + val sign = (x & (1 << (s-1))) + val wmask = (1 << w) - 1 + val bmask = (1 << s) - 1 + if (sign == 0) x else ((~bmask | x) & wmask) + } + for (t <- 0 until 16) { + val test_a = rnd.nextInt(1 << 4) + poke(c.io.a, test_a) + step(1) + expect(c.io.asp, pads(test_a, 4, 8)) + expect(c.io.aup, test_a) + } +} |
