summaryrefslogtreecommitdiff
path: root/src/test/scala
diff options
context:
space:
mode:
authorSchuyler Eldridge2019-05-07 02:21:50 -0400
committerSchuyler Eldridge2019-05-09 12:47:32 -0400
commitaaee64deb9c4990d0e38043a2b6a4ce747bb6935 (patch)
tree5ce84e585188bf1a934f6b404dc26e1d4175b83d /src/test/scala
parentf35f2a2784d8df7c079ee46eb33eeffd805edb44 (diff)
Deprecate LFSR16, use FibonacciLFSR internally
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Diffstat (limited to 'src/test/scala')
-rw-r--r--src/test/scala/chiselTests/LFSR16.scala31
-rw-r--r--src/test/scala/chiselTests/QueueSpec.scala13
2 files changed, 37 insertions, 7 deletions
diff --git a/src/test/scala/chiselTests/LFSR16.scala b/src/test/scala/chiselTests/LFSR16.scala
index c3c9dfad..992bb4bf 100644
--- a/src/test/scala/chiselTests/LFSR16.scala
+++ b/src/test/scala/chiselTests/LFSR16.scala
@@ -5,6 +5,7 @@ package chiselTests
import chisel3._
import chisel3.testers.BasicTester
import chisel3.util._
+import chisel3.util.random.{PRNG, LFSR}
/**
* This test creates two 4 sided dice.
@@ -56,12 +57,40 @@ class LFSRMaxPeriod(gen: => UInt) extends BasicTester {
}
}
+/** Check that the output of the new LFSR is the same asthe old LFSR */
+class MeetTheNewLFSR16SameAsTheOldLFSR16 extends BasicTester {
+
+ /** This is the exact implementation of the old LFSR16 algorithm */
+ val oldLfsr = {
+ val width = 16
+ val lfsr = RegInit(1.U(width.W))
+ lfsr := Cat(lfsr(0)^lfsr(2)^lfsr(3)^lfsr(5), lfsr(width-1,1))
+ lfsr
+ }
+
+ /** The new LFSR16 uses equivalent taps and a reverse so that it can use LFSR(16) under the hood. */
+ val newLfsr = LFSR16()
+
+ val (_, done) = Counter(true.B, 16)
+
+ assert(oldLfsr === newLfsr)
+
+ when (done) {
+ stop()
+ }
+
+}
+
class LFSRSpec extends ChiselPropSpec {
property("LFSR16 can be used to produce pseudo-random numbers, this tests the distribution") {
assertTesterPasses{ new LFSRDistribution(LFSR16()) }
}
property("LFSR16 period tester, Period should 2^16 - 1") {
- assertTesterPasses { new LFSRMaxPeriod(LFSR16()) }
+ assertTesterPasses{ new LFSRMaxPeriod(LFSR16()) }
+ }
+
+ property("New LFSR16 is the same as the old LFSR16") {
+ assertTesterPasses{ new MeetTheNewLFSR16SameAsTheOldLFSR16 }
}
}
diff --git a/src/test/scala/chiselTests/QueueSpec.scala b/src/test/scala/chiselTests/QueueSpec.scala
index 3f723ecf..994f3e6d 100644
--- a/src/test/scala/chiselTests/QueueSpec.scala
+++ b/src/test/scala/chiselTests/QueueSpec.scala
@@ -9,6 +9,7 @@ import org.scalacheck._
import chisel3._
import chisel3.testers.BasicTester
import chisel3.util._
+import chisel3.util.random.LFSR
class ThingsPassThroughTester(elements: Seq[Int], queueDepth: Int, bitWidth: Int, tap: Int) extends BasicTester {
val q = Module(new Queue(UInt(bitWidth.W), queueDepth))
@@ -19,7 +20,7 @@ class ThingsPassThroughTester(elements: Seq[Int], queueDepth: Int, bitWidth: Int
val outCnt = Counter(elements.length + 1)
q.io.enq.valid := (inCnt.value < elements.length.U)
- q.io.deq.ready := LFSR16()(tap)
+ q.io.deq.ready := LFSR(16)(tap)
q.io.enq.bits := elems(inCnt.value)
when(q.io.enq.fire()) {
@@ -47,7 +48,7 @@ class QueueReasonableReadyValid(elements: Seq[Int], queueDepth: Int, bitWidth: I
//Queue should be full or ready
assert(q.io.enq.ready || q.io.count === queueDepth.U)
- q.io.deq.ready := LFSR16()(tap)
+ q.io.deq.ready := LFSR(16)(tap)
//Queue should be empty or valid
assert(q.io.deq.valid || q.io.count === 0.U)
@@ -72,7 +73,7 @@ class CountIsCorrectTester(elements: Seq[Int], queueDepth: Int, bitWidth: Int, t
val outCnt = Counter(elements.length + 1)
q.io.enq.valid := (inCnt.value < elements.length.U)
- q.io.deq.ready := LFSR16()(tap)
+ q.io.deq.ready := LFSR(16)(tap)
q.io.enq.bits := elems(inCnt.value)
when(q.io.enq.fire()) {
@@ -99,7 +100,7 @@ class QueueSinglePipeTester(elements: Seq[Int], bitWidth: Int, tap: Int) extends
val outCnt = Counter(elements.length + 1)
q.io.enq.valid := (inCnt.value < elements.length.U)
- q.io.deq.ready := LFSR16()(tap)
+ q.io.deq.ready := LFSR(16)(tap)
assert(q.io.enq.ready || (q.io.count === 1.U && !q.io.deq.ready))
@@ -125,7 +126,7 @@ class QueuePipeTester(elements: Seq[Int], queueDepth: Int, bitWidth: Int, tap: I
val outCnt = Counter(elements.length + 1)
q.io.enq.valid := (inCnt.value < elements.length.U)
- q.io.deq.ready := LFSR16()(tap)
+ q.io.deq.ready := LFSR(16)(tap)
assert(q.io.enq.ready || (q.io.count === queueDepth.U && !q.io.deq.ready))
@@ -154,7 +155,7 @@ class QueueFlowTester(elements: Seq[Int], queueDepth: Int, bitWidth: Int, tap: I
//Queue should be full or ready
assert(q.io.enq.ready || q.io.count === queueDepth.U)
- q.io.deq.ready := LFSR16()(tap)
+ q.io.deq.ready := LFSR(16)(tap)
//Queue should be empty or valid
assert(q.io.deq.valid || (q.io.count === 0.U && !q.io.enq.fire()))