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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
// SPDX-License-Identifier: Apache-2.0
package firrtlTests
import firrtl.testutils._
class VerilogEquivalenceSpec extends FirrtlFlatSpec {
"mul followed by cat" should "be correct" in {
val header = s"""
|circuit Multiply :
| module Multiply :
| input x : UInt<4>
| input y : UInt<2>
| input z : UInt<2>
| output out : UInt<8>
|""".stripMargin
val input1 = header + """
| out <= cat(z, mul(x, y))""".stripMargin
val input2 = header + """
| node n = mul(x, y)
| node m = cat(z, n)
| out <= m""".stripMargin
val expected = s"""
|module MultiplyRef(
| input [3:0] x,
| input [1:0] y,
| input [1:0] z,
| output [7:0] out
|);
| wire [5:0] w = x * y;
| assign out = {z, w};
|endmodule""".stripMargin
firrtlEquivalenceWithVerilog(input1, expected)
firrtlEquivalenceWithVerilog(input2, expected)
}
"div followed by cat" should "be correct" in {
val header = s"""
|circuit Divide :
| module Divide :
| input x : UInt<4>
| input y : UInt<2>
| input z : UInt<2>
| output out : UInt<6>
|""".stripMargin
val input1 = header + """
| out <= cat(z, div(x, y))""".stripMargin
val input2 = header + """
| node n = div(x, y)
| node m = cat(z, n)
| out <= m""".stripMargin
val expected = s"""
|module DivideRef(
| input [3:0] x,
| input [1:0] y,
| input [1:0] z,
| output [5:0] out
|);
| wire [3:0] w = x / y;
| assign out = {z, w};
|endmodule""".stripMargin
firrtlEquivalenceWithVerilog(input1, expected)
firrtlEquivalenceWithVerilog(input2, expected)
}
"signed mul followed by cat" should "be correct" in {
val header = s"""
|circuit SignedMultiply :
| module SignedMultiply :
| input x : SInt<4>
| input y : SInt<2>
| input z : SInt<2>
| output out : UInt<8>
|""".stripMargin
val input1 = header + """
| out <= cat(z, mul(x, y))""".stripMargin
val input2 = header + """
| node n = mul(x, y)
| node m = cat(z, n)
| out <= m""".stripMargin
val expected = s"""
|module SignedMultiplyRef(
| input signed [3:0] x,
| input signed [1:0] y,
| input signed [1:0] z,
| output [7:0] out
|);
| wire [5:0] w = x * y;
| assign out = {z, w};
|endmodule""".stripMargin
firrtlEquivalenceWithVerilog(input1, expected)
firrtlEquivalenceWithVerilog(input2, expected)
}
"signed div followed by cat" should "be correct" in {
val header = s"""
|circuit SignedDivide :
| module SignedDivide :
| input x : SInt<4>
| input y : SInt<2>
| input z : SInt<2>
| output out : UInt<7>
|""".stripMargin
val input1 = header + """
| out <= cat(z, div(x, y))""".stripMargin
val input2 = header + """
| node n = div(x, y)
| node m = cat(z, n)
| out <= m""".stripMargin
val expected = s"""
|module SignedDivideRef(
| input signed [3:0] x,
| input signed [1:0] y,
| input signed [1:0] z,
| output [6:0] out
|);
| wire [4:0] w = x / y;
| assign out = {z, w};
|endmodule""".stripMargin
firrtlEquivalenceWithVerilog(input1, expected)
firrtlEquivalenceWithVerilog(input2, expected)
}
}
|