summaryrefslogtreecommitdiff
path: root/src/main/scala
diff options
context:
space:
mode:
authormergify[bot]2022-01-28 00:20:24 +0000
committerGitHub2022-01-28 00:20:24 +0000
commit91ad2312cab72442fcfec9c28576b5464669f8fd (patch)
tree467b2d81ac658b3bb1c1260c34486eb56d49b006 /src/main/scala
parentdb0fe3fb23c3f50be0aeb859b19cb96967e15186 (diff)
Fix Decoder bug for constant 0 and DC (#2363) (#2371)
* Fix the QMC bug for constant and dontcare output. * Fix the Espresso bug for constant and dontcare output. (cherry picked from commit 46b53320e9ec09fc26d63259f1821f4234640839) Co-authored-by: Jiuyang Liu <liu@jiuyang.me>
Diffstat (limited to 'src/main/scala')
-rw-r--r--src/main/scala/chisel3/util/experimental/decode/EspressoMinimizer.scala11
-rw-r--r--src/main/scala/chisel3/util/experimental/decode/QMCMinimizer.scala49
2 files changed, 41 insertions, 19 deletions
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)
+ }
+ }
}
}