summaryrefslogtreecommitdiff
path: root/src/main/scala/chisel3/util
diff options
context:
space:
mode:
authorJack2022-02-08 02:11:51 +0000
committerJack2022-02-08 02:11:51 +0000
commit4da4f252c3d7c834e13bb8e91a69cfe772996452 (patch)
tree5acc86ebf6c429efc051954c6977ed2394498dbc /src/main/scala/chisel3/util
parent93d17165cc5339de3e2dc7cd9e10dd3634b49bac (diff)
parent9d1e2082df4ecb2942a28b7039eb2ff36953380c (diff)
Merge branch '3.5.x' into 3.5-release
Diffstat (limited to 'src/main/scala/chisel3/util')
-rw-r--r--src/main/scala/chisel3/util/Bitwise.scala2
-rw-r--r--src/main/scala/chisel3/util/GrayCode.scala24
-rw-r--r--src/main/scala/chisel3/util/experimental/decode/EspressoMinimizer.scala11
-rw-r--r--src/main/scala/chisel3/util/experimental/decode/QMCMinimizer.scala49
4 files changed, 66 insertions, 20 deletions
diff --git a/src/main/scala/chisel3/util/Bitwise.scala b/src/main/scala/chisel3/util/Bitwise.scala
index 0d8318bf..8abe3645 100644
--- a/src/main/scala/chisel3/util/Bitwise.scala
+++ b/src/main/scala/chisel3/util/Bitwise.scala
@@ -14,7 +14,7 @@ import chisel3._
* FillInterleaved(2, "b1 0 0 1".U) // equivalent to "b11 00 00 11".U
* FillInterleaved(2, myUIntWire) // dynamic interleaved fill
*
- * FillInterleaved(2, Seq(true.B, false.B, false.B, false.B)) // equivalent to "b11 00 00 00".U
+ * FillInterleaved(2, Seq(false.B, false.B, false.B, true.B)) // equivalent to "b11 00 00 00".U
* FillInterleaved(2, Seq(true.B, false.B, false.B, true.B)) // equivalent to "b11 00 00 11".U
* }}}
*/
diff --git a/src/main/scala/chisel3/util/GrayCode.scala b/src/main/scala/chisel3/util/GrayCode.scala
new file mode 100644
index 00000000..ef310ee9
--- /dev/null
+++ b/src/main/scala/chisel3/util/GrayCode.scala
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package chisel3.util
+
+import chisel3._
+
+object BinaryToGray {
+
+ /** Turns a binary number into gray code. */
+ def apply(in: UInt): UInt = in ^ (in >> 1)
+}
+
+object GrayToBinary {
+
+ /** Inverts the [[BinaryToGray]] operation. */
+ def apply(in: UInt, width: Int): UInt = apply(in(width - 1, 0))
+
+ /** Inverts the [[BinaryToGray]] operation. */
+ def apply(in: UInt): UInt = if (in.getWidth < 2) { in }
+ else {
+ val bits = in.getWidth - 2 to 0 by -1
+ Cat(bits.scanLeft(in.head(1)) { case (prev, ii) => prev ^ in(ii) })
+ }
+}
diff --git a/src/main/scala/chisel3/util/experimental/decode/EspressoMinimizer.scala b/src/main/scala/chisel3/util/experimental/decode/EspressoMinimizer.scala
index de2f207b..86973e5b 100644
--- a/src/main/scala/chisel3/util/experimental/decode/EspressoMinimizer.scala
+++ b/src/main/scala/chisel3/util/experimental/decode/EspressoMinimizer.scala
@@ -57,11 +57,20 @@ object EspressoMinimizer extends Minimizer with LazyLogging {
def readTable(espressoTable: String) = {
def bitPat(espresso: String): BitPat = BitPat("b" + espresso.replace('-', '?'))
- espressoTable
+ val out = espressoTable
.split("\n")
.filterNot(_.startsWith("."))
.map(_.split(' '))
.map(row => bitPat(row(0)) -> bitPat(row(1)))
+ // special case for 0 and DontCare, if output is not couple to input
+ if (out.isEmpty)
+ Array(
+ (
+ BitPat(s"b${"?" * table.inputWidth}"),
+ BitPat(s"b${"0" * table.outputWidth}")
+ )
+ )
+ else out
}
val input = writeTable(table)
diff --git a/src/main/scala/chisel3/util/experimental/decode/QMCMinimizer.scala b/src/main/scala/chisel3/util/experimental/decode/QMCMinimizer.scala
index a3481869..26a072f1 100644
--- a/src/main/scala/chisel3/util/experimental/decode/QMCMinimizer.scala
+++ b/src/main/scala/chisel3/util/experimental/decode/QMCMinimizer.scala
@@ -304,24 +304,37 @@ object QMCMinimizer extends Minimizer {
)
})
- minimized.tail.foldLeft(table.copy(table = Seq(minimized.head))) {
- case (tb, t) =>
- if (tb.table.exists(x => x._1 == t._1)) {
- tb.copy(table = tb.table.map {
- case (k, v) =>
- if (k == t._1) {
- def ones(bitPat: BitPat) = bitPat.rawString.zipWithIndex.collect { case ('1', x) => x }
- (
- k,
- BitPat(
- "b" + (0 until v.getWidth).map(i => if ((ones(v) ++ ones(t._2)).contains(i)) "1" else "?").mkString
+ // special case for 0 and DontCare, if output is not couple to input
+ if (minimized.isEmpty)
+ table.copy(
+ Seq(
+ (
+ BitPat(s"b${"?" * table.inputWidth}"),
+ BitPat(s"b${"0" * table.outputWidth}")
+ )
+ )
+ )
+ else
+ minimized.tail.foldLeft(table.copy(table = Seq(minimized.head))) {
+ case (tb, t) =>
+ if (tb.table.exists(x => x._1 == t._1)) {
+ tb.copy(table = tb.table.map {
+ case (k, v) =>
+ if (k == t._1) {
+ def ones(bitPat: BitPat) = bitPat.rawString.zipWithIndex.collect { case ('1', x) => x }
+ (
+ k,
+ BitPat(
+ "b" + (0 until v.getWidth)
+ .map(i => if ((ones(v) ++ ones(t._2)).contains(i)) "1" else "?")
+ .mkString
+ )
)
- )
- } else (k, v)
- })
- } else {
- tb.copy(table = tb.table :+ t)
- }
- }
+ } else (k, v)
+ })
+ } else {
+ tb.copy(table = tb.table :+ t)
+ }
+ }
}
}