diff options
| author | Albert Magyar | 2020-02-06 04:05:16 -0800 |
|---|---|---|
| committer | Albert Magyar | 2020-02-13 09:25:53 -0800 |
| commit | 6e94ecb8b5da29e3a07d0117d27bb5fa58271678 (patch) | |
| tree | 7a78e8e3ae0ff66b61ee9a3c16574550609f34d3 /src/test | |
| parent | 8ef2ab50411642f9eaa2c1aac7147658fbab8368 (diff) | |
Constant prop binary PrimOps with matching arguments
* Add SimplifyBinaryOp trait
* Add extra functionality to comparison folding
* Add tests
* Fix comments from review
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/scala/firrtlTests/ConstantPropagationTests.scala | 44 |
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") """ ) + } + } |
