diff options
| author | Jack Koenig | 2021-03-19 13:59:52 -0700 |
|---|---|---|
| committer | GitHub | 2021-03-19 13:59:52 -0700 |
| commit | 49b823244732e8d3a4b0fe91d0f10625fea34eec (patch) | |
| tree | f47edb75d158b9654b5ea60c8aa95176caf7dd70 /src/test/scala/firrtlTests | |
| parent | b274b319d4a4014c154f06bfc174beba461d6fce (diff) | |
Legalize neg: -x becomes 0 - x (#2128)
This fixes an error with negating a negative SInt literal and a
[debatable] lint warning in Verilator when negating any value.
This behavior matches that of Chisel (which directly emits the 0 - x
already).
Diffstat (limited to 'src/test/scala/firrtlTests')
| -rw-r--r-- | src/test/scala/firrtlTests/LegalizeSpec.scala | 4 | ||||
| -rw-r--r-- | src/test/scala/firrtlTests/NegSpec.scala | 46 |
2 files changed, 49 insertions, 1 deletions
diff --git a/src/test/scala/firrtlTests/LegalizeSpec.scala b/src/test/scala/firrtlTests/LegalizeSpec.scala index 905d578e..ad85668e 100644 --- a/src/test/scala/firrtlTests/LegalizeSpec.scala +++ b/src/test/scala/firrtlTests/LegalizeSpec.scala @@ -2,6 +2,8 @@ package firrtlTests -import firrtl.testutils.ExecutionTest +import firrtl.testutils.{ExecutionTest, ExecutionTestNoOpt} class LegalizeExecutionTest extends ExecutionTest("Legalize", "/passes/Legalize") +// Legalize also needs to work when optimizations are turned off +class LegalizeExecutionTestNoOpt extends ExecutionTestNoOpt("Legalize", "/passes/Legalize") diff --git a/src/test/scala/firrtlTests/NegSpec.scala b/src/test/scala/firrtlTests/NegSpec.scala new file mode 100644 index 00000000..c60294e3 --- /dev/null +++ b/src/test/scala/firrtlTests/NegSpec.scala @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: Apache-2.0 + +package firrtlTests + +import firrtl.testutils._ + +class NegSpec extends FirrtlFlatSpec { + "unsigned neg" should "be correct and lint-clean" in { + val input = + """|circuit UnsignedNeg : + | module UnsignedNeg : + | input in : UInt<8> + | output out : SInt + | out <= neg(in) + |""".stripMargin + val expected = + """|module UnsignedNegRef( + | input [7:0] in, + | output [8:0] out + |); + | assign out = 8'd0 - in; + |endmodule""".stripMargin + firrtlEquivalenceWithVerilog(input, expected) + lintVerilog(compileToVerilog(input)) + } + + "signed neg" should "be correct and lint-clean" in { + val input = + """|circuit SignedNeg : + | module SignedNeg : + | input in : SInt<8> + | output out : SInt + | out <= neg(in) + |""".stripMargin + // -$signed(in) is a lint warning in Verilator but is functionally correct + val expected = + """|module SignedNegRef( + | input [7:0] in, + | output [8:0] out + |); + | assign out = -$signed(in); + |endmodule""".stripMargin + firrtlEquivalenceWithVerilog(input, expected) + lintVerilog(compileToVerilog(input)) + } +} |
