Skip to content

Commit a272e7c

Browse files
committed
[ESI] Getting ESI primitives run in iverilog
Modify both the primitive file itself and the testbench to run in Icarus Verilog. Also, pull the location into lit via a substitution.
1 parent 09fc391 commit a272e7c

File tree

6 files changed

+67
-51
lines changed

6 files changed

+67
-51
lines changed

integration_test/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ if (ESI_RUNTIME)
4646
endif()
4747
endif()
4848

49+
get_target_property(ESI_PrimsDir ESIPrimitives SOURCE_DIR)
50+
set(ESI_Prims "${ESI_PrimsDir}/ESIPrimitives.sv")
51+
4952
set(CIRCT_INTEGRATION_TIMEOUT 60) # Set a 60s timeout on individual tests.
5053
configure_lit_site_cfg(
5154
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// REQUIRES: ieee-sim
2-
// UNSUPPORTED: ieee-sim-iverilog
3-
// RUN: circt-rtl-sim.py --sim %ieee-sim %CIRCT_SOURCE%/lib/Dialect/ESI/ESIPrimitives.sv %s
2+
// RUN: circt-rtl-sim.py --sim %ieee-sim %esi_prims %s
43

54
//===- primitive_tb.sv - tests for ESI primitives -----------*- verilog -*-===//
65
//
@@ -10,6 +9,10 @@
109
//
1110
//===----------------------------------------------------------------------===//
1211

12+
`define assert_fatal(pred) \
13+
if (!(pred)) \
14+
$fatal();
15+
1316
module top (
1417
input logic clk,
1518
input logic rst
@@ -25,13 +28,21 @@ module top (
2528

2629

2730
ESI_PipelineStage s1 (
28-
.*
31+
.clk(clk),
32+
.rst(rst),
33+
.a_valid(a_valid),
34+
.a(a),
35+
.a_ready(a_ready),
36+
.x_valid(x_valid),
37+
.x(x),
38+
.x_ready(x_ready)
2939
);
3040

3141
// Increment the input every cycle.
3242
always begin
3343
@(posedge clk) #1;
34-
a++;
44+
if (~rst)
45+
a++;
3546
end
3647

3748
// Track the number of tokens currently in the stage for debugging.
@@ -44,98 +55,97 @@ module top (
4455
end
4556

4657
initial begin
47-
// Wait until rstn is deasserted.
48-
while (rst) begin
49-
@(posedge clk);
50-
end
58+
// Wait until rst is deasserted.
59+
@(negedge rst);
60+
@(posedge clk);
5161

5262
a_valid = 1;
53-
assert (a_ready);
63+
`assert_fatal (a_ready);
5464
@(posedge clk) #1;
55-
assert (x_valid);
56-
assert (x == 8'h05);
57-
assert (a_ready);
65+
`assert_fatal (x_valid);
66+
`assert_fatal (x == 8'h02);
67+
`assert_fatal (a_ready);
5868

5969
a_valid = 1;
6070
@(posedge clk) #1;
61-
assert (x_valid);
62-
assert (x == 8'h05);
63-
assert (~a_ready);
71+
`assert_fatal (x_valid);
72+
`assert_fatal (x == 8'h02);
73+
`assert_fatal (~a_ready);
6474
a_valid = 1;
6575

6676
@(posedge clk) #1;
67-
assert (x_valid);
68-
assert (x == 8'h05);
69-
assert (~a_ready);
77+
`assert_fatal (x_valid);
78+
`assert_fatal (x == 8'h02);
79+
`assert_fatal (~a_ready);
7080
x_ready = 1;
7181

7282
@(posedge clk) #1;
73-
assert (x_valid);
74-
assert (x == 8'h06);
75-
assert (a_ready);
83+
`assert_fatal (x_valid);
84+
`assert_fatal (x == 8'h03);
85+
`assert_fatal (a_ready);
7686
x_ready = 1;
7787

7888
@(posedge clk) #1;
79-
assert (x_valid);
80-
assert (x == 8'h09);
81-
assert (a_ready);
89+
`assert_fatal (x_valid);
90+
`assert_fatal (x == 8'h06);
91+
`assert_fatal (a_ready);
8292
x_ready = 0;
8393

8494
@(posedge clk) #1;
85-
assert (x_valid);
86-
assert (x == 8'h09);
87-
assert (~a_ready);
95+
`assert_fatal (x_valid);
96+
`assert_fatal (x == 8'h06);
97+
`assert_fatal (~a_ready);
8898
x_ready = 1;
8999

90100
@(posedge clk) #1;
91-
assert (x_valid);
92-
assert (x == 8'h0A);
93-
assert (a_ready);
101+
`assert_fatal (x_valid);
102+
`assert_fatal (x == 8'h07);
103+
`assert_fatal (a_ready);
94104
x_ready = 1;
95105
a_valid = 0;
96106

97107
@(posedge clk) #1;
98-
assert (~x_valid);
99-
assert (a_ready);
108+
`assert_fatal (~x_valid);
109+
`assert_fatal (a_ready);
100110
x_ready = 1;
101111
a_valid = 0;
102112

103113
@(posedge clk) #1;
104-
assert (~x_valid);
105-
assert (a_ready);
114+
`assert_fatal (~x_valid);
115+
`assert_fatal (a_ready);
106116
x_ready = 1;
107117
a_valid = 0;
108118

109119
@(posedge clk) #1;
110-
assert (~x_valid);
111-
assert (a_ready);
120+
`assert_fatal (~x_valid);
121+
`assert_fatal (a_ready);
112122
x_ready = 1;
113123
a_valid = 0;
114124

115125
@(posedge clk) #1;
116-
assert (~x_valid);
117-
assert (a_ready);
126+
`assert_fatal (~x_valid);
127+
`assert_fatal (a_ready);
118128
x_ready = 1;
119129
a_valid = 1;
120130

121131
@(posedge clk) #1;
122-
assert (x_valid);
123-
assert (x == 8'h10);
124-
assert (a_ready);
132+
`assert_fatal (x_valid);
133+
`assert_fatal (x == 8'h0D);
134+
`assert_fatal (a_ready);
125135
x_ready = 1;
126136
a_valid = 1;
127137

128138
@(posedge clk) #1;
129-
assert (x_valid);
130-
assert (x == 8'h11);
131-
assert (a_ready);
139+
`assert_fatal (x_valid);
140+
`assert_fatal (x == 8'h0E);
141+
`assert_fatal (a_ready);
132142
x_ready = 1;
133143
a_valid = 1;
134144

135145
@(posedge clk) #1;
136-
assert (x_valid);
137-
assert (x == 8'h12);
138-
assert (a_ready);
146+
`assert_fatal (x_valid);
147+
`assert_fatal (x == 8'h0F);
148+
`assert_fatal (a_ready);
139149
x_ready = 1;
140150
a_valid = 1;
141151

@@ -145,7 +155,7 @@ module top (
145155
@(posedge clk) #1;
146156
@(posedge clk) #1;
147157
@(posedge clk) #1;
148-
$stop();
158+
$finish();
149159
end
150160

151161
endmodule

integration_test/lit.cfg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@
169169
if ieee_sims and ieee_sims[-1][1] == config.iverilog_path:
170170
config.available_features.add('ieee-sim-iverilog')
171171

172+
config.substitutions.append(("%esi_prims", config.esi_prims))
173+
172174
# Enable ESI runtime tests.
173175
if config.esi_runtime == "1":
174176
config.available_features.add('esi-runtime')

integration_test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ config.clang_tidy_path = "@CLANG_TIDY_PATH@"
5050
config.have_systemc = "@HAVE_SYSTEMC@"
5151
config.esi_runtime = "@ESI_RUNTIME@"
5252
config.esi_runtime_path = "@ESIRuntimePath@"
53+
config.esi_prims = "@ESI_Prims@"
5354
config.bindings_python_enabled = @CIRCT_BINDINGS_PYTHON_ENABLED@
5455
config.bindings_tcl_enabled = @CIRCT_BINDINGS_TCL_ENABLED@
5556
config.lec_enabled = "@CIRCT_LEC_ENABLED@"

lib/Dialect/ESI/ESIPrimitives.sv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
/// | --- | ----- | --------- | ------- | ------ | ------------------ |
3737
///
3838
module ESI_PipelineStage # (
39-
int WIDTH = 8
39+
parameter WIDTH = 8
4040
) (
4141
input logic clk,
4242
input logic rst,
@@ -80,7 +80,7 @@ module ESI_PipelineStage # (
8080
// Did we accept a token this cycle?
8181
wire a_rcv = a_ready && a_valid;
8282

83-
always_ff @(posedge clk) begin
83+
always @(posedge clk) begin
8484
if (rst) begin
8585
l_valid <= 1'b0;
8686
x_valid_reg <= 1'b0;

tools/circt-rtl-sim/circt-rtl-sim.py.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def __main__(args):
326326
if not args.no_compile:
327327
rc = sim.compile(args.sources, args.compileargs)
328328
if rc.returncode != 0:
329-
return rc
329+
return rc.returncode
330330
if not args.no_run:
331331
try:
332332
rc = sim.run(args.cycles, args.simargs)

0 commit comments

Comments
 (0)