diff options
| author | Chick Markley | 2019-10-18 19:44:08 -0700 |
|---|---|---|
| committer | Adam Izraelevitz | 2019-10-18 19:44:08 -0700 |
| commit | 7b93b0f8c48e39cc9730cf9f91340cf733dadafe (patch) | |
| tree | 3e9666c29d6c9901f221fed4728d05b9fd75067e /src/test/scala/chiselTests/ScalaIntervalSimulatorTest.scala | |
| parent | fafd984a923591841917cd4c3a1f4c823dc485b4 (diff) | |
Interval Data Type Support for Chisel (#1210)
Plan to be released with 3.3.
Breaks experimental Range API.
Adds new Interval type and associated support.
This commit adds the following:
- Renamed Range to IntervalRange to avoid name collision with scala Range
- Changed RangeTransform macro to Return an IntervalRange
- Improved error messages on missing comma or decimal
- Added notational support for binary point
- Some formatting cleanup also
- SIntFactory
- Change to use IntervalRange API
- UIntFactory
- UInt from range has custom width computation
- It does not need to deal with lowerbound extending bit requirements
- Code to handle special case of range"[0,0]" to have a width of 1
- IR.scala
- Removed Bound and other constraint code that was duplicating firrtl stuff
- Added new RangeType
- Added IntervalRange class and object
- RangeSpec
- modified just a bit to handle notational differences
- previous range interpolator returned tuple now returns IntervalRange
- Add IntervalType to emitter
- Added IntervalSpec with many tests
- Added ScalaIntervalSimulatorSpec which tests golden model for Interval
- Added ScalaIntervalSimulator which is a golden model for Interval
- This gold may not have been polished to a high sheen
- Add IntervalLit cases to Converter
- Add Interval PrimOps to IR
- asInterval, wrap, squz, clip, setp, decp, incp
- Add IntervalLit class to IR
- Add Interval to MonoConnect
- Add Interval Type to Bits (in experimental package)
- add conversions to Interval from other types
- Add Interval clone stuff to Data
- Add Literal creation helpers to chisel3 package
- these may move to experimental if I can figure that out
Diffstat (limited to 'src/test/scala/chiselTests/ScalaIntervalSimulatorTest.scala')
| -rw-r--r-- | src/test/scala/chiselTests/ScalaIntervalSimulatorTest.scala | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/ScalaIntervalSimulatorTest.scala b/src/test/scala/chiselTests/ScalaIntervalSimulatorTest.scala new file mode 100644 index 00000000..0bf8741e --- /dev/null +++ b/src/test/scala/chiselTests/ScalaIntervalSimulatorTest.scala @@ -0,0 +1,96 @@ +// See README.md for license details. + +package chiselTests + +import chisel3._ +import chisel3.experimental._ +import org.scalatest.{FreeSpec, Matchers} + +class ScalaIntervalSimulatorSpec extends FreeSpec with Matchers { + "clip tests" - { + "Should work for closed ranges" in { + val sim = ScalaIntervalSimulator(range"[2,4]") + sim.clip(BigDecimal(1.0)) should be (2.0) + sim.clip(BigDecimal(2.0)) should be (2.0) + sim.clip(BigDecimal(3.0)) should be (3.0) + sim.clip(BigDecimal(4.0)) should be (4.0) + sim.clip(BigDecimal(5.0)) should be (4.0) + } + "Should work for closed ranges with binary point" in { + val sim = ScalaIntervalSimulator(range"[2,6].2") + sim.clip(BigDecimal(1.75)) should be (2.0) + sim.clip(BigDecimal(2.0)) should be (2.0) + sim.clip(BigDecimal(2.25)) should be (2.25) + sim.clip(BigDecimal(2.5)) should be (2.5) + sim.clip(BigDecimal(5.75)) should be (5.75) + sim.clip(BigDecimal(6.0)) should be (6.0) + sim.clip(BigDecimal(6.25)) should be (6.0) + sim.clip(BigDecimal(6.5)) should be (6.0) + sim.clip(BigDecimal(8.5)) should be (6.0) + } + "Should work for open ranges" in { + val sim = ScalaIntervalSimulator(range"(2,4)") + sim.clip(BigDecimal(1.0)) should be (3.0) + sim.clip(BigDecimal(2.0)) should be (3.0) + sim.clip(BigDecimal(3.0)) should be (3.0) + sim.clip(BigDecimal(4.0)) should be (3.0) + sim.clip(BigDecimal(5.0)) should be (3.0) + } + "Should work for open ranges with binary point" in { + val sim = ScalaIntervalSimulator(range"(2,6).2") + sim.clip(BigDecimal(1.75)) should be (2.25) + sim.clip(BigDecimal(2.0)) should be (2.25) + sim.clip(BigDecimal(2.25)) should be (2.25) + sim.clip(BigDecimal(2.5)) should be (2.5) + sim.clip(BigDecimal(5.75)) should be (5.75) + sim.clip(BigDecimal(6.0)) should be (5.75) + sim.clip(BigDecimal(6.25)) should be (5.75) + sim.clip(BigDecimal(6.5)) should be (5.75) + sim.clip(BigDecimal(8.5)) should be (5.75) + } + } + "wrap tests" - { + "Should work for closed ranges" in { + val sim = ScalaIntervalSimulator(range"[2,6]") + sim.wrap(BigDecimal(1.0)) should be (6.0) + sim.wrap(BigDecimal(2.0)) should be (2.0) + sim.wrap(BigDecimal(3.0)) should be (3.0) + sim.wrap(BigDecimal(4.0)) should be (4.0) + sim.wrap(BigDecimal(5.0)) should be (5.0) + sim.wrap(BigDecimal(6.0)) should be (6.0) + sim.wrap(BigDecimal(7.0)) should be (2.0) + } + "Should work for closed ranges with binary point" in { + val sim = ScalaIntervalSimulator(range"[2,6].2") + sim.wrap(BigDecimal(1.75)) should be (6.0) + sim.wrap(BigDecimal(2.0)) should be (2.0) + sim.wrap(BigDecimal(2.25)) should be (2.25) + sim.wrap(BigDecimal(2.5)) should be (2.5) + sim.wrap(BigDecimal(5.75)) should be (5.75) + sim.wrap(BigDecimal(6.0)) should be (6.0) + sim.wrap(BigDecimal(6.25)) should be (2.0) + sim.wrap(BigDecimal(6.5)) should be (2.25) + } + "Should work for open ranges" in { + val sim = ScalaIntervalSimulator(range"(2,6)") + sim.wrap(BigDecimal(1.0)) should be (4.0) + sim.wrap(BigDecimal(2.0)) should be (5.0) + sim.wrap(BigDecimal(3.0)) should be (3.0) + sim.wrap(BigDecimal(4.0)) should be (4.0) + sim.wrap(BigDecimal(5.0)) should be (5.0) + sim.wrap(BigDecimal(6.0)) should be (3.0) + sim.wrap(BigDecimal(7.0)) should be (4.0) + } + "Should work for open ranges with binary point" in { + val sim = ScalaIntervalSimulator(range"(2,6).2") + sim.wrap(BigDecimal(1.75)) should be (5.5) + sim.wrap(BigDecimal(2.0)) should be (5.75) + sim.wrap(BigDecimal(2.25)) should be (2.25) + sim.wrap(BigDecimal(2.5)) should be (2.5) + sim.wrap(BigDecimal(5.75)) should be (5.75) + sim.wrap(BigDecimal(6.0)) should be (2.25) + sim.wrap(BigDecimal(6.25)) should be (2.5) + sim.wrap(BigDecimal(7.0)) should be (3.25) + } + } +} |
