aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorAlbert Magyar2020-02-13 10:57:12 -0700
committerGitHub2020-02-13 10:57:12 -0700
commitd0791c567aceb7ef7d78e6563b3322a9969895c9 (patch)
tree8b1d307fe1db309fd39f603157c8798b6b584315 /src/test
parent8ef2ab50411642f9eaa2c1aac7147658fbab8368 (diff)
parent555d1e4397f9e750b186f4c07ef3172b7ee39c0d (diff)
Merge pull request #1361 from freechipsproject/const-prop-eq
Constant prop binary PrimOps with matching arguments
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/firrtlTests/ConstantPropagationTests.scala44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/test/scala/firrtlTests/ConstantPropagationTests.scala b/src/test/scala/firrtlTests/ConstantPropagationTests.scala
index ef52507f..cc7a5e32 100644
--- a/src/test/scala/firrtlTests/ConstantPropagationTests.scala
+++ b/src/test/scala/firrtlTests/ConstantPropagationTests.scala
@@ -1393,6 +1393,50 @@ class ConstantPropagationIntegrationSpec extends LowTransformSpec {
""".stripMargin
execute(input, check, Seq.empty)
}
+
+ private def matchingArgs(op: String, iType: String, oType: String, result: String): Unit = {
+ val input =
+ s"""circuit Top :
+ | module Top :
+ | input i : ${iType}
+ | output o : ${oType}
+ | o <= ${op}(i, i)
+ """.stripMargin
+ val check =
+ s"""circuit Top :
+ | module Top :
+ | input i : ${iType}
+ | output o : ${oType}
+ | o <= ${result}
+ """.stripMargin
+ execute(input, check, Seq.empty)
+ }
+
+ it should "optimize some binary operations when arguments match" in {
+ // Signedness matters
+ matchingArgs("sub", "UInt<8>", "UInt<8>", """ UInt<8>("h0") """ )
+ matchingArgs("sub", "SInt<8>", "SInt<8>", """ SInt<8>("h0") """ )
+ matchingArgs("div", "UInt<8>", "UInt<8>", """ UInt<8>("h1") """ )
+ matchingArgs("div", "SInt<8>", "SInt<8>", """ SInt<8>("h1") """ )
+ matchingArgs("rem", "UInt<8>", "UInt<8>", """ UInt<8>("h0") """ )
+ matchingArgs("rem", "SInt<8>", "SInt<8>", """ SInt<8>("h0") """ )
+ matchingArgs("and", "UInt<8>", "UInt<8>", """ i """ )
+ matchingArgs("and", "SInt<8>", "UInt<8>", """ asUInt(i) """ )
+ // Signedness doesn't matter
+ matchingArgs("or", "UInt<8>", "UInt<8>", """ i """ )
+ matchingArgs("or", "SInt<8>", "UInt<8>", """ asUInt(i) """ )
+ matchingArgs("xor", "UInt<8>", "UInt<8>", """ UInt<8>("h0") """ )
+ matchingArgs("xor", "SInt<8>", "UInt<8>", """ UInt<8>("h0") """ )
+ // Always true
+ matchingArgs("eq", "UInt<8>", "UInt<1>", """ UInt<1>("h1") """ )
+ matchingArgs("leq", "UInt<8>", "UInt<1>", """ UInt<1>("h1") """ )
+ matchingArgs("geq", "UInt<8>", "UInt<1>", """ UInt<1>("h1") """ )
+ // Never true
+ matchingArgs("neq", "UInt<8>", "UInt<1>", """ UInt<1>("h0") """ )
+ matchingArgs("lt", "UInt<8>", "UInt<1>", """ UInt<1>("h0") """ )
+ matchingArgs("gt", "UInt<8>", "UInt<1>", """ UInt<1>("h0") """ )
+ }
+
}