Skip to content

Commit

Permalink
add shortcut to espresso and qmc.
Browse files Browse the repository at this point in the history
  • Loading branch information
sequencer committed Jun 16, 2021
1 parent 4755345 commit 07e7c25
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/main/scala/chisel3/util/experimental/decode/decoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import firrtl.annotations.Annotation
import logger.LazyLogging

object decoder extends LazyLogging {
/** Use a specific [[Minimizer]] to generated decoded signals.
*
* @param minimizer specific [[Minimizer]], can be [[QMCMinimizer]] or [[EspressoMinimizer]].
* @param input input signal that contains decode table input
* @param truthTable [[TruthTable]] to decode user input.
* @return decode table output.
*/
def apply(minimizer: Minimizer, input: UInt, truthTable: TruthTable): UInt = {
val minimizedTable = getAnnotations().collect {
case DecodeTableAnnotation(_, in, out) => TruthTable(in) -> TruthTable(out)
Expand All @@ -31,4 +38,38 @@ object decoder extends LazyLogging {
plaOutput
}
}

/** Use [[EspressoMinimizer]] to generated decoded signals.
*
* @param input input signal that contains decode table input
* @param truthTable [[TruthTable]] to decode user input.
* @return decode table output.
*/
def espresso(input: UInt, truthTable: TruthTable): UInt = apply(EspressoMinimizer, input, truthTable)

/** Use [[QMCMinimizer]] to generated decoded signals.
*
* @param input input signal that contains decode table input
* @param truthTable [[TruthTable]] to decode user input.
* @return decode table output.
*/
def qmc(input: UInt, truthTable: TruthTable): UInt = apply(QMCMinimizer, input, truthTable)

/** try to use [[EspressoMinimizer]] to decode `input` by `truthTable`
* if `espresso` not exist in your PATH environment it will fall back to [[QMCMinimizer]], and print a warning.
*
* @param input input signal that contains decode table input
* @param truthTable [[TruthTable]] to decode user input.
* @return decode table output.
*/
def apply(input: UInt, truthTable: TruthTable): UInt = try espresso(input, truthTable) catch {
case java.io.IOException =>
logger.error(
"""espresso is not found in your PATH, fall back to QMC.
|Quine-McCluskey is a NP complete algorithm, may run forever or run out of memory in large decode tables.
|To get rid of this warning, please use `decoder.qmc` directly, or add espresso to your PATH.
|""".stripMargin
)
qmc(input, truthTable)
}
}

0 comments on commit 07e7c25

Please # to comment.