aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/firrtlTests/NegSpec.scala
blob: c60294e3bcf8e408fd7dc944a7ee2de7082e2cbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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))
  }
}