blob: b3c98e88ef43173e93b08e43f38c3fe75e06049e (
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// See LICENSE for license details.
package firrtlTests
import firrtl._
import firrtl.testutils._
import firrtl.testutils.FirrtlCheckers._
class ReplaceTruncatingArithmeticSpec extends FirrtlFlatSpec {
def compile(input: String): CircuitState =
(new VerilogCompiler).compileAndEmit(CircuitState(parse(input), ChirrtlForm), List.empty)
def compileBody(body: String) = {
val str = """
|circuit Test :
| module Test :
|""".stripMargin + body.split("\n").mkString(" ", "\n ", "")
compile(str)
}
"Truncting addition" should "be inferred and emitted in Verilog" in {
val result = compileBody(s"""
|input x : UInt<8>
|input y : UInt<8>
|output z : UInt<8>
|z <= tail(add(x, y), 1)""".stripMargin
)
result should containLine (s"assign z = x + y;")
}
it should "be inferred and emitted in Verilog even with an intermediate node" in {
val result = compileBody(s"""
|input x : UInt<8>
|input y : UInt<8>
|output z : UInt<8>
|node n = add(x, y)
|z <= tail(n, 1)""".stripMargin
)
result should containLine (s"assign z = x + y;")
}
"Truncting subtraction" should "be inferred and emitted in Verilog" in {
val result = compileBody(s"""
|input x : UInt<8>
|input y : UInt<8>
|output z : UInt<8>
|z <= tail(sub(x, y), 1)""".stripMargin
)
result should containLine (s"assign z = x - y;")
}
"Tailing more than 1" should "not result in a truncating operator" in {
val result = compileBody(s"""
|input x : UInt<8>
|input y : UInt<8>
|output z : UInt<7>
|node n = sub(x, y)
|z <= tail(n, 2)""".stripMargin
)
result should containLine (s"assign n = x - y;")
result should containLine (s"assign z = n[6:0];")
}
}
|