aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorJack Koenig2020-10-01 19:47:12 -0700
committerJack Koenig2020-10-01 19:47:12 -0700
commita7a5030d9af1b504fd373e5060f66a859cb972dc (patch)
tree9256ba6d3323eb49ac54b1f608aa28ec5a763074 /src/test
parentc1c2fb99b0bbbaedcd4138e7dfdd04e3910167f0 (diff)
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
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/firrtlTests/VerilogEmitterTests.scala20
1 files changed, 20 insertions, 0 deletions
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>