From a7a5030d9af1b504fd373e5060f66a859cb972dc Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Thu, 1 Oct 2020 19:47:12 -0700 Subject: Fix "fix" for negative literals > 32 bits Overflow of 32-bit Int would cause any negative literal value equal to -(2^(width % 32 - 1)) where width >= 32 to be incorrectly inverted --- src/test/scala/firrtlTests/VerilogEmitterTests.scala | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/test') diff --git a/src/test/scala/firrtlTests/VerilogEmitterTests.scala b/src/test/scala/firrtlTests/VerilogEmitterTests.scala index 7001a724..4a3686fa 100644 --- a/src/test/scala/firrtlTests/VerilogEmitterTests.scala +++ b/src/test/scala/firrtlTests/VerilogEmitterTests.scala @@ -735,6 +735,26 @@ class VerilogEmitterSpec extends FirrtlFlatSpec { result should containLine("assign z = _GEN_0[1:0];") } + it should "correctly emit addition with a negative literal with width > 32" in { + val result = compileBody( + """input x : SInt<34> + |output z : SInt<34> + |z <= asSInt(tail(add(x, SInt<34>(-2)), 1)) + |""".stripMargin + ) + result should containLine("assign z = $signed(x) - 34'sh2;") + } + + it should "correctly emit conjunction with a negative literal with width > 32" in { + val result = compileBody( + """input x : SInt<34> + |output z : SInt<34> + |z <= asSInt(and(x, SInt<34>(-2))) + |""".stripMargin + ) + result should containLine("assign z = $signed(x) & -34'sh2;") + } + it should "emit FileInfo as Verilog comment" in { def result(info: String): CircuitState = compileBody( s"""input x : UInt<2> -- cgit v1.2.3