diff options
| author | Josh Bassett | 2020-07-30 15:11:33 +1000 |
|---|---|---|
| committer | GitHub | 2020-07-30 05:11:33 +0000 |
| commit | fca89f6c8544a1e0b42e1cec34207f74bf238e8a (patch) | |
| tree | b6b6ed8c10bb11364ffca807ee41241ca1dbc697 /src/test/scala/chiselTests/ChiselSpec.scala | |
| parent | 164490c8fbf132ca65644d05d6ff8d0d7a3beb20 (diff) | |
Allow a counter to be instantiated using a Scala range (#1515)
* Add positive range generator
* Allow the Counter module to be instantiated with a Scala range
* Use head/last to determine counter width
Co-authored-by: Jack Koenig <jack.koenig3@gmail.com>
* Let counter overflow naturally when appropriate
We only need to explicitly wrap counters that don't start at zero, or end on a power of two. Otherwise we just let the counter overflow naturally to avoid wasting an extra mux.
* Require counter range to be non-empty
Co-authored-by: Jack Koenig <jack.koenig3@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Diffstat (limited to 'src/test/scala/chiselTests/ChiselSpec.scala')
| -rw-r--r-- | src/test/scala/chiselTests/ChiselSpec.scala | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/ChiselSpec.scala b/src/test/scala/chiselTests/ChiselSpec.scala index 7980e772..9518fb5c 100644 --- a/src/test/scala/chiselTests/ChiselSpec.scala +++ b/src/test/scala/chiselTests/ChiselSpec.scala @@ -150,6 +150,20 @@ class ChiselPropSpec extends PropSpec with ChiselRunners with ScalaCheckProperty // Generator for small positive integers. val smallPosInts = Gen.choose(1, 4) + // Generator for positive (ascending or descending) ranges. + def posRange: Gen[Range] = for { + dir <- Gen.oneOf(true, false) + step <- Gen.choose(1, 3) + m <- Gen.choose(1, 10) + n <- Gen.choose(1, 10) + } yield { + if (dir) { + Range(m, (m+n)*step, step) + } else { + Range((m+n)*step, m, -step) + } + } + // Generator for widths considered "safe". val safeUIntWidth = Gen.choose(1, 30) |
