Skip to content

Commit 91821eb

Browse files
authored
Merge pull request #20 from pulp-platform/michaero/fix_l0_tb
Fix L0 testbench
2 parents 27fe3ee + d9285b2 commit 91821eb

3 files changed

Lines changed: 25 additions & 10 deletions

File tree

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88
## Unreleased
99
### Fixed
1010
- lookup_serial: Make `write_ready_o` independent of `write_valid_i`.
11+
- Fix L0 testbench.
1112

1213
### Changed
1314
- Rename `SET_COUNT` to `WAY_COUNT` to correct terminology, as it reflects the number of ways in a set.

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ compile.tcl: .bender
1919
$(BENDER) script vsim -t test \
2020
--vlog-arg="$(VLOG_FLAGS)" \
2121
> compile.tcl
22+
echo "return 0" >> compile.tcl
2223

2324
.PHONY: build test_l0 test_ro test_l0_nogui test_ro_nogui
2425

2526
build: compile.tcl
26-
$(VSIM) -c -do 'source compile.tcl; quit'
27+
$(VSIM) -c -do 'quit -code [source compile.tcl]'
2728

2829
test_l0: build
2930
$(VSIM) snitch_icache_l0_tb -coverage -voptargs='+acc +cover=sbecft' -do "log -r /*; run -all"

test/snitch_icache_l0_tb.sv

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ module snitch_icache_l0_tb #(
105105
PENDING_IW: $clog2(2)
106106
};
107107

108-
localparam int unsigned IdWidthReq = $clog2(NR_FETCH_PORTS) + 1;
109-
localparam int unsigned IdWidthResp = 2*NR_FETCH_PORTS;
108+
localparam int unsigned IdWidth = 2*NR_FETCH_PORTS;
110109

111110
logic clk, rst;
112111
logic dut_flush_valid;
@@ -119,12 +118,12 @@ module snitch_icache_l0_tb #(
119118
typedef struct packed {
120119
logic [LINE_WIDTH-1:0] data;
121120
logic error;
122-
logic [IdWidthResp-1:0] id;
121+
logic [IdWidth-1:0] id;
123122
} dut_in_t;
124123

125124
typedef struct packed {
126125
addr_t addr;
127-
logic [IdWidthReq-1:0] id;
126+
logic [IdWidth-1:0] id;
128127
} dut_out_t;
129128

130129
typedef stream_test::stream_driver #(
@@ -283,22 +282,36 @@ module snitch_icache_l0_tb #(
283282
`ASSERT(RequestProgress, dut_valid |-> ##[0:RequestTimeout] dut_ready, clk, rst)
284283

285284
// Response Drivers
286-
mailbox #(dut_out_t) addr_mbx [2];
285+
mailbox #(dut_out_t) addr_mbx [IdWidth];
287286
semaphore response_lock = new (1);
288287

288+
function automatic logic [$clog2(IdWidth)-1:0] onehot2bin (input logic [IdWidth-1:0] onehot);
289+
logic [$clog2(IdWidth)-1:0] bin;
290+
for (int i = 0; i < IdWidth; i++) begin
291+
logic [IdWidth-1:0] tmp_mask;
292+
for (int j = 0; j < IdWidth; j++) begin
293+
logic [IdWidth-1:0] tmp_i;
294+
tmp_i = j;
295+
tmp_mask[j] = tmp_i[i];
296+
end
297+
bin[i] = |(tmp_mask & onehot);
298+
end
299+
return bin;
300+
endfunction
301+
289302
initial begin
290303
automatic int unsigned stall_cycles;
291-
automatic dut_out_t dut_out;
292-
for (int i = 0; i < 2**IdWidthReq; i++)
304+
automatic dut_out_t dut_out_loc;
305+
for (int i = 0; i < IdWidth; i++)
293306
addr_mbx [i] = new();
294307
out_driver.reset_out();
295308
@(negedge rst);
296309
repeat (5) @(posedge clk);
297310
forever begin
298311
stall_cycles = $urandom_range(0, 5);
299312
repeat (stall_cycles) @(posedge clk);
300-
out_driver.recv(dut_out);
301-
addr_mbx[dut_out.id].put(dut_out);
313+
out_driver.recv(dut_out_loc);
314+
addr_mbx[onehot2bin(dut_out_loc.id)].put(dut_out_loc);
302315
// $info("Requesting from Address: %h, ID: %d", dut_out.addr, dut_out.id);
303316
end
304317
end

0 commit comments

Comments
 (0)