diff options
| author | Jack | 2023-01-08 04:47:27 +0000 |
|---|---|---|
| committer | Jack | 2023-01-08 04:47:27 +0000 |
| commit | 5aa60ecda6bd2b02dfc7253a47e53c7647981a5c (patch) | |
| tree | 53ea2570c4af7824d6203e0c0cd7953c1ba4910c /src/test/scala/chiselTests/util | |
| parent | a50a5a287a23ba6b833b13d8cec84dd5dfe0fc61 (diff) | |
| parent | 116210ff806ccdda91b4c3343f78bad66783d0e6 (diff) | |
Merge branch '3.5.x' into 3.5-release
Diffstat (limited to 'src/test/scala/chiselTests/util')
| -rw-r--r-- | src/test/scala/chiselTests/util/BitSetSpec.scala | 29 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/util/PriorityMuxSpec.scala | 60 |
2 files changed, 88 insertions, 1 deletions
diff --git a/src/test/scala/chiselTests/util/BitSetSpec.scala b/src/test/scala/chiselTests/util/BitSetSpec.scala index dd66ba40..cf5f54cf 100644 --- a/src/test/scala/chiselTests/util/BitSetSpec.scala +++ b/src/test/scala/chiselTests/util/BitSetSpec.scala @@ -110,9 +110,36 @@ class BitSetSpec extends AnyFlatSpec with Matchers { "b11??????" ) ), - true + errorBit = true ) }) } + it should "be decoded with DontCare error" in { + import chisel3._ + import chisel3.util.experimental.decode.decoder + // [0 - 256] part into: [0 - 31], [32 - 47, 64 - 127], [192 - 255] + // "0011????" "10??????" is empty to error + chisel3.stage.ChiselStage.emitSystemVerilog(new Module { + val in = IO(Input(UInt(8.W))) + val out = IO(Output(UInt(4.W))) + out := decoder.bitset( + in, + Seq( + BitSet.fromString( + "b000?????" + ), + BitSet.fromString( + """b0010???? + |b01?????? + |""".stripMargin + ), + BitSet.fromString( + "b11??????" + ) + ), + errorBit = false + ) + }) + } } diff --git a/src/test/scala/chiselTests/util/PriorityMuxSpec.scala b/src/test/scala/chiselTests/util/PriorityMuxSpec.scala new file mode 100644 index 00000000..32cf2431 --- /dev/null +++ b/src/test/scala/chiselTests/util/PriorityMuxSpec.scala @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: Apache-2.0 + +package chiselTests.util + +import chisel3._ +import chisel3.util.{is, switch, Counter, PriorityMux} +import chisel3.testers.BasicTester +import chisel3.stage.ChiselStage.emitChirrtl + +import chiselTests.ChiselFlatSpec + +class PriorityMuxTester extends BasicTester { + + val sel = Wire(UInt(3.W)) + sel := 0.U // default + + val elts = Seq(5.U, 6.U, 7.U) + val muxed = PriorityMux(sel, elts) + + // Priority is given to lowest order bit + val tests = Seq( + 1.U -> elts(0), + 2.U -> elts(1), + 3.U -> elts(0), + 4.U -> elts(2), + 5.U -> elts(0), + 6.U -> elts(1), + 7.U -> elts(0) + ) + val (cycle, done) = Counter(0 until tests.size + 1) + + for (((in, out), idx) <- tests.zipWithIndex) { + when(cycle === idx.U) { + sel := in + assert(muxed === out) + } + } + + when(done) { + stop() + } +} + +class PriorityMuxSpec extends ChiselFlatSpec { + behavior.of("PriorityMux") + + it should "be functionally correct" in { + assertTesterPasses(new PriorityMuxTester) + } + + it should "be stack safe" in { + emitChirrtl(new RawModule { + val n = 1 << 15 + val in = IO(Input(Vec(n, UInt(8.W)))) + val sel = IO(Input(UInt(n.W))) + val out = IO(Output(UInt(8.W))) + out := PriorityMux(sel, in) + }) + } +} |
