summaryrefslogtreecommitdiff
path: root/integration-tests/src
diff options
context:
space:
mode:
authorJack2022-02-08 02:11:51 +0000
committerJack2022-02-08 02:11:51 +0000
commit4da4f252c3d7c834e13bb8e91a69cfe772996452 (patch)
tree5acc86ebf6c429efc051954c6977ed2394498dbc /integration-tests/src
parent93d17165cc5339de3e2dc7cd9e10dd3634b49bac (diff)
parent9d1e2082df4ecb2942a28b7039eb2ff36953380c (diff)
Merge branch '3.5.x' into 3.5-release
Diffstat (limited to 'integration-tests/src')
-rw-r--r--integration-tests/src/test/scala/chiselTests/util/GrayCodeTests.scala42
-rw-r--r--integration-tests/src/test/scala/chiselTests/util/experimental/minimizer/MinimizerSpec.scala35
2 files changed, 77 insertions, 0 deletions
diff --git a/integration-tests/src/test/scala/chiselTests/util/GrayCodeTests.scala b/integration-tests/src/test/scala/chiselTests/util/GrayCodeTests.scala
new file mode 100644
index 00000000..9562abb4
--- /dev/null
+++ b/integration-tests/src/test/scala/chiselTests/util/GrayCodeTests.scala
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package chiselTests.util
+
+import chisel3._
+import chisel3.util._
+import chiseltest._
+import chiseltest.formal._
+import org.scalatest.flatspec.AnyFlatSpec
+
+class GrayCodeTests extends AnyFlatSpec with ChiselScalatestTester with Formal {
+ behavior.of("GrayCode")
+
+ val Widths = Seq(1, 2, 3, 5, 8, 17, 65)
+ Widths.foreach { w =>
+ it should s"maintain identity (width=$w)" in {
+ verify(new GrayCodeIdentityCheck(w), Seq(BoundedCheck(1)))
+ }
+
+ it should s"ensure hamming distance of one (width=$w)" in {
+ verify(new GrayCodeHammingCheck(w), Seq(BoundedCheck(1)))
+ }
+ }
+}
+
+/** Checks that when we go from binary -> gray -> binary the result is always the same as the input. */
+private class GrayCodeIdentityCheck(width: Int) extends Module {
+ val in = IO(Input(UInt(width.W)))
+ val gray = BinaryToGray(in)
+ val out = GrayToBinary(gray)
+ assert(in === out, "%b -> %b -> %b", in, gray, out)
+}
+
+/** Checks that if we increment the binary number, the gray code equivalent only changes by one bit. */
+private class GrayCodeHammingCheck(width: Int) extends Module {
+ val a = IO(Input(UInt(width.W)))
+ val b = a + 1.U
+ val aGray = BinaryToGray(a)
+ val bGray = BinaryToGray(b)
+ val hamming = PopCount(aGray ^ bGray)
+ assert(hamming === 1.U, "%b ^ %b = %b", aGray, bGray, hamming)
+}
diff --git a/integration-tests/src/test/scala/chiselTests/util/experimental/minimizer/MinimizerSpec.scala b/integration-tests/src/test/scala/chiselTests/util/experimental/minimizer/MinimizerSpec.scala
index 07afd074..2d3e073c 100644
--- a/integration-tests/src/test/scala/chiselTests/util/experimental/minimizer/MinimizerSpec.scala
+++ b/integration-tests/src/test/scala/chiselTests/util/experimental/minimizer/MinimizerSpec.scala
@@ -272,4 +272,39 @@ trait MinimizerSpec extends AnyFlatSpec with ChiselScalatestTester with Formal {
BitPat(s"b${Seq(N, X, X, X, X, X, X, X, X, A2_X, A1_X, IMM_X, DW_X, FN_X, N, M_X, X, X, X, X, X, X, X, CSR_X, X, X, X, X).reduce(_ + _)}")
))
}
+
+ "output is 0" should "pass" in {
+ minimizerTest(TruthTable.fromString(
+ """00->0
+ |01->?
+ |10->0
+ |11->0
+ | ?
+ |""".stripMargin
+
+ ))
+ }
+ "output is 1" should "pass" in {
+ minimizerTest(TruthTable.fromString(
+ """00->1
+ |01->?
+ |10->1
+ |11->1
+ | ?
+ |""".stripMargin
+
+ ))
+ }
+ // I know this seems to be crazy, but if user is crazy as well...
+ "output is dont care" should "pass" in {
+ minimizerTest(TruthTable.fromString(
+ """00->?
+ |01->?
+ |10->?
+ |11->?
+ | ?
+ |""".stripMargin
+
+ ))
+ }
}