Skip to content

Commit c57e9f4

Browse files
committed
Coding style change for Verilator compatibility (fixes #21)
The boundary_conditions process in hazard3_frontend needs to be scheduled at least twice to resolve to the correct values. There are multiple possible interleavings, which should all result in the same result. However Verilator schedules the process only once. Work around this by moving the tie-off of the problematic variable into the synchronous update process.
1 parent 8272910 commit c57e9f4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

hdl/hazard3_frontend.v

+5-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ always @ (*) begin: boundary_conditions
135135
fifo_mem[FIFO_DEPTH] = mem_data;
136136
fifo_predbranch[FIFO_DEPTH] = 2'b00;
137137
fifo_err[FIFO_DEPTH] = 1'b0;
138-
fifo_valid_hw[FIFO_DEPTH] = 2'b00;
139138
for (i = 0; i < FIFO_DEPTH; i = i + 1) begin
140139
fifo_valid[i] = |EXTENSION_C ? |fifo_valid_hw[i] : fifo_valid_hw[i][0];
141140
// valid-to-right condition: i == 0 || fifo_valid[i - 1], but without
@@ -158,6 +157,10 @@ always @ (posedge clk or negedge rst_n) begin: fifo_update
158157
fifo_err[i] <= 1'b0;
159158
fifo_predbranch[i] <= 2'b00;
160159
end
160+
// This exists only for loop boundary conditions, but is tied off in
161+
// this synchronous process to work around a Verilator scheduling
162+
// issue (see issue #21)
163+
fifo_valid_hw[FIFO_DEPTH] <= 2'b00;
161164
end else begin
162165
for (i = 0; i < FIFO_DEPTH; i = i + 1) begin
163166
if (fifo_pop || (fifo_push && !fifo_valid[i])) begin
@@ -183,6 +186,7 @@ always @ (posedge clk or negedge rst_n) begin: fifo_update
183186
fifo_predbranch[0] <= 2'b00;
184187
fifo_valid_hw[0] <= jump_now ? 2'b00 : 2'b11;
185188
end
189+
fifo_valid_hw[FIFO_DEPTH] <= 2'b00;
186190
`ifdef HAZARD3_ASSERTIONS
187191
// FIFO validity must be compact, so we can always consume from the end
188192
if (!fifo_valid[0]) begin

0 commit comments

Comments
 (0)