diff options
| -rw-r--r-- | src/main/scala/chisel3/util/experimental/decode/TruthTable.scala | 14 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/util/experimental/TruthTableSpec.scala | 4 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/main/scala/chisel3/util/experimental/decode/TruthTable.scala b/src/main/scala/chisel3/util/experimental/decode/TruthTable.scala index 2720e690..8259564f 100644 --- a/src/main/scala/chisel3/util/experimental/decode/TruthTable.scala +++ b/src/main/scala/chisel3/util/experimental/decode/TruthTable.scala @@ -3,13 +3,17 @@ package chisel3.util.experimental.decode import chisel3.util.BitPat +import scala.util.hashing.MurmurHash3 import scala.collection.mutable -sealed class TruthTable private (val table: Seq[(BitPat, BitPat)], val default: BitPat, val sort: Boolean) { +sealed class TruthTable private (val table: Seq[(BitPat, BitPat)], val default: BitPat, _sort: Boolean) { def inputWidth = table.head._1.getWidth def outputWidth = table.head._2.getWidth + @deprecated("This field is unused and will be removed.", "Chisel 3.5") + def sort: Boolean = _sort + override def toString: String = { def writeRow(map: (BitPat, BitPat)): String = s"${map._1.rawString}->${map._2.rawString}" @@ -17,15 +21,17 @@ sealed class TruthTable private (val table: Seq[(BitPat, BitPat)], val default: (table.map(writeRow) ++ Seq(s"${" " * (inputWidth + 2)}${default.rawString}")).mkString("\n") } - def copy(table: Seq[(BitPat, BitPat)] = this.table, default: BitPat = this.default, sort: Boolean = this.sort) = - TruthTable(table, default, sort) + def copy(table: Seq[(BitPat, BitPat)] = this.table, default: BitPat = this.default, sort: Boolean = _sort) = + TruthTable(table, default) override def equals(y: Any): Boolean = { y match { - case y: TruthTable => toString == y.toString + case that: TruthTable => this.table == that.table && this.default == that.default case _ => false } } + + override lazy val hashCode: Int = MurmurHash3.productHash((table, default)) } object TruthTable { diff --git a/src/test/scala/chiselTests/util/experimental/TruthTableSpec.scala b/src/test/scala/chiselTests/util/experimental/TruthTableSpec.scala index 9b2dd600..b5dcee6b 100644 --- a/src/test/scala/chiselTests/util/experimental/TruthTableSpec.scala +++ b/src/test/scala/chiselTests/util/experimental/TruthTableSpec.scala @@ -35,7 +35,9 @@ class TruthTableSpec extends AnyFlatSpec { assert(table.toString contains " 0") } "TruthTable" should "deserialize" in { - assert(TruthTable.fromString(str) == table) + val table2 = TruthTable.fromString(str) + assert(table2 === table) + assert(table2.hashCode === table.hashCode) } "TruthTable" should "merge same key" in { assert( |
