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/SIntOps.scala | |
| parent | b208bfb5691c7b5921dd47d0b599726872acd1cd (diff) | |
Incorporate chisel3-tests; update Makefile.
Diffstat (limited to 'src/test/scala/ChiselTests/SIntOps.scala')
| -rw-r--r-- | src/test/scala/ChiselTests/SIntOps.scala | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/test/scala/ChiselTests/SIntOps.scala b/src/test/scala/ChiselTests/SIntOps.scala new file mode 100644 index 00000000..5fd02c37 --- /dev/null +++ b/src/test/scala/ChiselTests/SIntOps.scala @@ -0,0 +1,81 @@ +package ChiselTests +import Chisel._ + +class SIntOps extends Module { + val io = new Bundle { + val a = SInt(INPUT, 16) + val b = SInt(INPUT, 16) + val addout = SInt(OUTPUT, 16) + val subout = SInt(OUTPUT, 16) + val timesout = SInt(OUTPUT, 16) + val divout = SInt(OUTPUT, 16) + val modout = SInt(OUTPUT, 16) + val lshiftout = SInt(OUTPUT, 16) + val rshiftout = SInt(OUTPUT, 16) + val lessout = Bool(OUTPUT) + val greatout = Bool(OUTPUT) + val eqout = Bool(OUTPUT) + val noteqout = Bool(OUTPUT) + val lesseqout = Bool(OUTPUT) + val greateqout = Bool(OUTPUT) + val negout = SInt(OUTPUT, 16) + } + + val a = io.a + val b = io.b + val ub = b.toUInt + + io.addout := a +% b + io.subout := a -% b + io.timesout := (a * b)(15, 0) + // TODO: + // io.divout := a / Mux(b === SInt(0), SInt(1), b) + io.divout := (a * b)(15, 0) + // io.divout := (a / b)(15, 0) + io.modout := UInt(0) + io.lshiftout := (a << 12)(15, 0) // (a << ub(3, 0))(15, 0).toSInt + io.rshiftout := (a >> 8) // (a >> ub).toSInt + io.lessout := a < b + io.greatout := a > b + io.eqout := a === b + io.noteqout := (a != b) + io.lesseqout := a <= b + io.greateqout := a >= b + // io.negout := -a(15, 0).toSInt + io.negout := (SInt(0) -% a) +} + +class SIntOpsTester(c: SIntOps) extends Tester(c) { + def sintExpect(d: Bits, x: BigInt) { + val mask = (1 << 16) - 1 + val sbit = (1 << 15) + val y = x & mask + val r = if ((y & sbit) == 0) y else (-(~y)-1) + expect(d, r) + } + for (t <- 0 until 16) { + val test_a = (1 << 15) - rnd.nextInt(1 << 16) + val test_b = (1 << 15) - rnd.nextInt(1 << 16) + poke(c.io.a, test_a) + poke(c.io.b, test_b) + step(1) + sintExpect(c.io.addout, test_a + test_b) + sintExpect(c.io.subout, test_a - test_b) + sintExpect(c.io.timesout, test_a * test_b) + // sintExpect(c.io.divout, if (test_b == 0) 0 else test_a / test_b) + sintExpect(c.io.divout, test_a * test_b) + // sintExpect(c.io.modout, test_a % test_b) + // sintExpect(c.io.lshiftout, test_a << (test_b&15)) + // sintExpect(c.io.rshiftout, test_a >> test_b) + sintExpect(c.io.lshiftout, test_a << 12) + sintExpect(c.io.rshiftout, test_a >> 8) + sintExpect(c.io.negout, -test_a) + expect(c.io.lessout, int(test_a < test_b)) + expect(c.io.greatout, int(test_a > test_b)) + expect(c.io.eqout, int(test_a == test_b)) + expect(c.io.noteqout, int(test_a != test_b)) + expect(c.io.lessout, int(test_a <= test_b)) + expect(c.io.greateqout, int(test_a >= test_b)) + } +} + |
