summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormergify[bot]2023-01-12 00:04:06 +0000
committerGitHub2023-01-12 00:04:06 +0000
commit6a63353f2a6c3311e61b9a7b5b899d8ad904a86d (patch)
treeb34e0dbe0bc1719a144586728cafd9ed59a31e1d /src
parentd4570fb9d29371c35641ba79b76662f99677f192 (diff)
TruthTable improvements: structural equality and delete sort (backport #2935) (#2936)
* TruthTable improvements: structural equality and delete sort (#2935) We had implemented equals, but not hashCode. This commit also changes the implemental of equals to just use the underlying values instead of wasting the compute calling .toString. Delete TruthTable.sort, it is unused. (cherry picked from commit b5d9c08b2d0994b94df2380425282206fe1f25bc) * Restore and deprecate TruthTable.sort Co-authored-by: Jack Koenig <koenig@sifive.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/chisel3/util/experimental/decode/TruthTable.scala14
-rw-r--r--src/test/scala/chiselTests/util/experimental/TruthTableSpec.scala4
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(