aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
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") """ )
+ }
+
}