Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/celox-runtime/src/simulation/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,16 @@ impl<B: SimBackend> SimulationState<B> {
continue;
}
if self.process_state.inactive.is_empty() {
// A domain whose blocking results are observed commits them
// in the active region: the processes they wake run before
// the NBA region publishes its nonblocking results (IEEE
// 1800-2023 4.5).
if self.active_commit_triggered(executor.backend(), round)
&& self.evaluate_before_inactive(executor, current_time, round)?
{
self.observe_driven(executor.backend());
continue;
}
return Ok(());
}
// The active region is empty: the domains it triggered evaluate
Expand Down
19 changes: 19 additions & 0 deletions crates/celox-runtime/src/simulation/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,25 @@ impl<B: SimBackend> SimulationState<B> {
}
}

/// A marked trigger evaluates a domain that commits its blocking
/// results in the active region (the filter of
/// [`Self::evaluate_before_inactive`]).
pub(super) fn active_commit_triggered(&self, backend: &B, round: &Round) -> bool {
if self.model.active_commits.is_empty() {
return false;
}
backend.get_triggered_bits().iter().any(|id| {
let info = self.model.event_info[id];
info.canonical_id != usize::MAX
&& info.eval_only_event.is_some()
&& self.model.active_commits.contains(info.canonical_id)
&& (!info.is_cascaded
|| round.counted_triggered.contains(id)
|| round.edge_approved.contains(id)
|| self.stable_edge_triggered(backend, id))
})
}

/// Evaluate the triggered domains before an inactive region runs. Their
/// nonblocking assignments stay in the working state until the NBA
/// region. A domain that commits its blocking results does so now, in
Expand Down
1 change: 1 addition & 0 deletions crates/celox-test-suite/LIMITATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ four-state expectations; the assertions remain enabled on all Celox variants.
| `sv_verilator_time_in_combinational_logic` | execute | verilator | 1 | Verilator 5.052 evaluates an always_comb that reads $time again when the clocking event of the suite testbench fires, although no variable it reads has changed: at 3 ns y is 3 instead of 0. IEEE 1800-2023 9.2.2.2.1 makes always_comb sensitive to the variables it reads, and $time (20.3.1) is none. A standalone probe prints y=0 in Icarus 13.0 and Verilator without a clocking block, and y=3 in Verilator with one. |
| `sv_verilator_intermediate_writes` | execute | verilator | 6 | Verilator 5.052 wakes a process waiting on a variable only for the value an evaluation leaves: an always_comb or edge-triggered body that rewrites a variable 1 -> 0 -> 1, and nonblocking updates `y <= 0; y <= 1;` from 1, wake no waiter, nor does a pulse that one always_ff writes to some bits of a variable while other processes write its other bits, or a nonblocking update that rises from the final blocking value. IEEE 1800-2023 4.3 and 9.4.2 make every store an update event that triggers the waiter, and 10.4.2 applies nonblocking updates in issue order, each its own update. [Standalone probes](verification/repros/sv_intermediate_writes_verilator.json) print the spec counts in Icarus 13.0 and 1 or 0 in Verilator. |
| `sv_icarus_port_pulses` | execute | icarus | 1 | Icarus 13.0 collapses a child's output port with the parent's net, so a waiter in the parent sees each value the child's always_comb writes inside one evaluation and counts 3 instead of 1. Both are conforming: the port is a continuous assignment (IEEE 1800-2023 23.3.3), evaluated after the child's process yields, and 4.7 leaves that order open. The case asserts the settled count, which Verilator 5.052 and Celox give. The [standalone probe](verification/repros/sv_port_pulses_icarus.json) retains both outputs. |
| `sv_verilator_active_region_waiters` | execute | verilator | 2 | Verilator 5.052 resumes a process woken by a blocking write of an edge-triggered process only after the same edge's nonblocking updates: with `y = ~y; q <= q + 1;` a waiter on `@(y)` reads the updated q, and with `y = 1; y <= 0; y <= 1;` from 0 it does not wait again before the nonblocking updates and counts 1 instead of 3. IEEE 1800-2023 4.5 makes the blocking write an update event of the active region and enters the NBA region only when the active and inactive regions are empty, so the waiter runs first (9.4.2). [Standalone probes](verification/repros/sv_active_region_waiters_verilator.json) print the spec values in Icarus 13.0 and the post-NBA values in Verilator. |

The [system-function edge-case evidence](verification/repros/system_function_edge_cases.json)
retains the failed Icarus runs and minimal sources. Cover comparisons enable
Expand Down
68 changes: 68 additions & 0 deletions crates/celox-test-suite/src/sv/cases/timing.vtest
Original file line number Diff line number Diff line change
Expand Up @@ -2014,3 +2014,71 @@ module Top(input bit clk,output bit[7:0]seen);bit q;Child c(clk,q);initial forev
(top Top)
(run_to_finish)
(expect_output "y=1001 n=3\np=10 q=01\n"))

; A blocking write of an edge process is an update of the active region:
; the process waiting on it runs there, before the NBA region applies the
; same edge's nonblocking update (IEEE 1800-2023 4.5, 9.4.2).
(case blocking_write_waiters_run_before_nonblocking_updates
(source "active.sv" #"
module Top;
bit clk, y;
int q;
always @(posedge clk) begin y = ~y; q <= q + 1; end
initial forever begin @(y); $display("y=%0d q=%0d", y, q); end
initial begin
#1 clk = 1;
#1 clk = 0;
#1 clk = 1;
#1 $finish;
end
endmodule
"#)
(top Top)
(run_to_finish)
(expect_output "y=1 q=0\ny=0 q=1\n"))

; The waiter the blocking write wakes waits again before the nonblocking
; updates, so they wake it once more.
(case blocking_write_waiters_rearm_before_nonblocking_updates
(source "rearm.sv" #"
module Top;
bit clk, y;
int n, r;
always @(posedge clk) begin y = 1; y <= 0; y <= 1; end
initial forever begin @(y); n++; end
initial forever begin @(posedge y); r++; end
initial begin
#1 clk = 1;
#1 clk = 0;
#1 clk = 1;
#1 $display("n=%0d r=%0d", n, r);
$finish;
end
endmodule
"#)
(top Top)
(run_to_finish)
(expect_output "n=3 r=3\n"))

; Processes and edge processes woken by the blocking write read the
; variables the same edge updates nonblocking before the update.
(case blocking_write_edges_read_values_before_nonblocking_updates
(source "derived.sv" #"
module Top;
bit clk, g;
int q, r, s;
always @(posedge clk) begin g = ~g; q <= q + 1; end
always @(g) r <= q;
initial forever begin @(g); s = q; end
initial begin
#1 clk = 1;
#1 clk = 0;
#1 clk = 1;
#1 $display("q=%0d r=%0d s=%0d", q, r, s);
$finish;
end
endmodule
"#)
(top Top)
(run_to_finish)
(expect_output "q=2 r=1 s=1\n"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"standard": "IEEE 1800-2023 4.5 and 9.4.2",
"expected": "A blocking write of an edge-triggered process is an update event of the active region; the process waiting on it is resumed in the active region, and the NBA region is entered only when the active and inactive regions are empty. The waiter therefore reads the values before the same edge's nonblocking updates, and waits again before those updates.",
"probes": [
{
"name": "active_waiter",
"note": "The suite case blocking_write_waiters_run_before_nonblocking_updates.",
"source": "module Top;\n bit clk, y;\n int q;\n always @(posedge clk) begin y = ~y; q <= q + 1; end\n initial forever begin @(y); $display(\"y=%0d q=%0d\", y, q); end\n initial begin #1 clk = 1; #1 clk = 0; #1 clk = 1; #1 $finish; end\nendmodule\n",
"verilator_compile": {
"command": "verilator --binary --timing -Wno-fatal --top-module Top --Mdir <repro>/obj <repro>/probe.sv",
"exit_code": 0
},
"verilator_run": {
"command": "<repro>/obj/VTop",
"exit_code": 0,
"output": "y=1 q=1\ny=0 q=2\n- <repro>/probe.sv:6: Verilog $finish\n- S i m u l a t i o n R e p o r t: Verilator 5.052 2026-09-05\n- Verilator: $finish at 4ps; walltime 0.000 s; speed 44.186 ns/s\n- Verilator: cpu 0.000 s on 1 threads; allocated 4 MB\n"
},
"icarus_compile": {
"command": "iverilog -g2012 -s Top -o <repro>/probe.vvp <repro>/probe.sv",
"exit_code": 0
},
"icarus_run": {
"command": "vvp <repro>/probe.vvp",
"exit_code": 0,
"output": "y=1 q=0\ny=0 q=1\n<repro>/probe.sv:6: $finish called at 4 (1s)\n"
}
},
{
"name": "rearm",
"note": "The suite case blocking_write_waiters_rearm_before_nonblocking_updates.",
"source": "module Top;\n bit clk, y;\n int n, r;\n always @(posedge clk) begin y = 1; y <= 0; y <= 1; end\n initial forever begin @(y); n++; end\n initial forever begin @(posedge y); r++; end\n initial begin #1 clk = 1; #1 clk = 0; #1 clk = 1; #1 $display(\"n=%0d r=%0d\", n, r); $finish; end\nendmodule\n",
"verilator_compile": {
"command": "verilator --binary --timing -Wno-fatal --top-module Top --Mdir <repro>/obj <repro>/probe.sv",
"exit_code": 0
},
"verilator_run": {
"command": "<repro>/obj/VTop",
"exit_code": 0,
"output": "n=1 r=1\n- <repro>/probe.sv:7: Verilog $finish\n- S i m u l a t i o n R e p o r t: Verilator 5.052 2026-09-05\n- Verilator: $finish at 4ps; walltime 0.000 s; speed 143.266 ns/s\n- Verilator: cpu 0.000 s on 1 threads; allocated 4 MB\n"
},
"icarus_compile": {
"command": "iverilog -g2012 -s Top -o <repro>/probe.vvp <repro>/probe.sv",
"exit_code": 0
},
"icarus_run": {
"command": "vvp <repro>/probe.vvp",
"exit_code": 0,
"output": "n=3 r=3\n<repro>/probe.sv:7: $finish called at 4 (1s)\n"
}
}
]
}
33 changes: 33 additions & 0 deletions crates/celox-test-suite/verification/sv/icarus/timing.json
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,39 @@
"tag_reasons": {},
"tags": []
},
{
"category": "Sequential",
"detail": "",
"expectation": "Simulation",
"name": "timing::blocking_write_waiters_run_before_nonblocking_updates",
"phase": "execute",
"status": "passed",
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
},
{
"category": "Sequential",
"detail": "",
"expectation": "Simulation",
"name": "timing::blocking_write_waiters_rearm_before_nonblocking_updates",
"phase": "execute",
"status": "passed",
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
},
{
"category": "Sequential",
"detail": "",
"expectation": "Simulation",
"name": "timing::blocking_write_edges_read_values_before_nonblocking_updates",
"phase": "execute",
"status": "passed",
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
},
{
"category": "Sequential",
"detail": "",
Expand Down
18 changes: 18 additions & 0 deletions crates/celox-test-suite/verification/sv/limitations.json
Original file line number Diff line number Diff line change
Expand Up @@ -1973,5 +1973,23 @@
"timing::child_port_pulses_reach_waiters_settled"
]
}
},
{
"id": "sv_verilator_active_region_waiters",
"category": "simulator_disagreement",
"phase": "execute",
"observed_version": "Verilator 5.052",
"reason": "Verilator 5.052 resumes a process woken by a blocking write of an edge-triggered process only after the same edge's nonblocking updates: with `y = ~y; q <= q + 1;` a waiter on `@(y)` reads the updated q, and with `y = 1; y <= 0; y <= 1;` from 0 it does not wait again before the nonblocking updates and counts 1 instead of 3. IEEE 1800-2023 4.5 makes the blocking write an update event of the active region and enters the NBA region only when the active and inactive regions are empty, so the waiter runs first (9.4.2). Standalone probes print the spec values in Icarus 13.0.",
"upstream": [],
"evidence": [
"verification/repros/sv_active_region_waiters_verilator.json",
"LIMITATIONS.md#systemverilog-suite"
],
"cases": {
"verilator": [
"timing::blocking_write_waiters_run_before_nonblocking_updates",
"timing::blocking_write_waiters_rearm_before_nonblocking_updates"
]
}
}
]
57 changes: 57 additions & 0 deletions crates/celox-test-suite/verification/sv/verilator/timing.json
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,63 @@
"tag_reasons": {},
"tags": []
},
{
"category": "Sequential",
"detail": "Verilator 5.052 resumes a process woken by a blocking write of an edge-triggered process only after the same edge's nonblocking updates: with `y = ~y; q <= q + 1;` a waiter on `@(y)` reads the updated q, and with `y = 1; y <= 0; y <= 1;` from 0 it does not wait again before the nonblocking updates and counts 1 instead of 3. IEEE 1800-2023 4.5 makes the blocking write an update event of the active region and enters the NBA region only when the active and inactive regions are empty, so the waiter runs first (9.4.2). Standalone probes print the spec values in Icarus 13.0.",
"expectation": "Simulation",
"known_issue": {
"category": "simulator_disagreement",
"evidence": [
"verification/repros/sv_active_region_waiters_verilator.json",
"LIMITATIONS.md#systemverilog-suite"
],
"id": "sv_verilator_active_region_waiters",
"observed_version": "Verilator 5.052",
"phase": "execute",
"reason": "Verilator 5.052 resumes a process woken by a blocking write of an edge-triggered process only after the same edge's nonblocking updates: with `y = ~y; q <= q + 1;` a waiter on `@(y)` reads the updated q, and with `y = 1; y <= 0; y <= 1;` from 0 it does not wait again before the nonblocking updates and counts 1 instead of 3. IEEE 1800-2023 4.5 makes the blocking write an update event of the active region and enters the NBA region only when the active and inactive regions are empty, so the waiter runs first (9.4.2). Standalone probes print the spec values in Icarus 13.0.",
"upstream": []
},
"name": "timing::blocking_write_waiters_run_before_nonblocking_updates",
"phase": "skip",
"status": "ignored",
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
},
{
"category": "Sequential",
"detail": "Verilator 5.052 resumes a process woken by a blocking write of an edge-triggered process only after the same edge's nonblocking updates: with `y = ~y; q <= q + 1;` a waiter on `@(y)` reads the updated q, and with `y = 1; y <= 0; y <= 1;` from 0 it does not wait again before the nonblocking updates and counts 1 instead of 3. IEEE 1800-2023 4.5 makes the blocking write an update event of the active region and enters the NBA region only when the active and inactive regions are empty, so the waiter runs first (9.4.2). Standalone probes print the spec values in Icarus 13.0.",
"expectation": "Simulation",
"known_issue": {
"category": "simulator_disagreement",
"evidence": [
"verification/repros/sv_active_region_waiters_verilator.json",
"LIMITATIONS.md#systemverilog-suite"
],
"id": "sv_verilator_active_region_waiters",
"observed_version": "Verilator 5.052",
"phase": "execute",
"reason": "Verilator 5.052 resumes a process woken by a blocking write of an edge-triggered process only after the same edge's nonblocking updates: with `y = ~y; q <= q + 1;` a waiter on `@(y)` reads the updated q, and with `y = 1; y <= 0; y <= 1;` from 0 it does not wait again before the nonblocking updates and counts 1 instead of 3. IEEE 1800-2023 4.5 makes the blocking write an update event of the active region and enters the NBA region only when the active and inactive regions are empty, so the waiter runs first (9.4.2). Standalone probes print the spec values in Icarus 13.0.",
"upstream": []
},
"name": "timing::blocking_write_waiters_rearm_before_nonblocking_updates",
"phase": "skip",
"status": "ignored",
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
},
{
"category": "Sequential",
"detail": "",
"expectation": "Simulation",
"name": "timing::blocking_write_edges_read_values_before_nonblocking_updates",
"phase": "execute",
"status": "passed",
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
},
{
"category": "Sequential",
"detail": "",
Expand Down
3 changes: 3 additions & 0 deletions crates/celox/tests/frontends/systemverilog/timing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ timed_cases! {
fn staged_nonblocking_writes_follow_later_blocking_writes = "timing::staged_nonblocking_writes_follow_later_blocking_writes";
fn intermediate_combinational_writes_replace_split_definitions = "timing::intermediate_combinational_writes_replace_split_definitions";
fn intermediate_combinational_writes_reach_concatenated_ports = "timing::intermediate_combinational_writes_reach_concatenated_ports";
fn blocking_write_waiters_run_before_nonblocking_updates = "timing::blocking_write_waiters_run_before_nonblocking_updates";
fn blocking_write_waiters_rearm_before_nonblocking_updates = "timing::blocking_write_waiters_rearm_before_nonblocking_updates";
fn blocking_write_edges_read_values_before_nonblocking_updates = "timing::blocking_write_edges_read_values_before_nonblocking_updates";
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions docs/guide/external-frontends.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ declaration order. A time slot follows the regions of IEEE 1800-2023 4.5:
processes, including those an edge wakes, run in the active region before the
registers of that edge publish their nonblocking assignments, so a process
woken by `@(posedge clk)` reads the register outputs from before the edge.
A process woken by a register domain's blocking write also runs in the
active region, before that domain's nonblocking assignments publish.
Zero-delay `InactiveDelay` processes run after the active region, and
nonblocking assignments publish only when both are empty. A process that
drives a register's input at the same edge races with the register, as in
Expand Down
6 changes: 6 additions & 0 deletions docs/guide/systemverilog-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ unsupported, including when the inference option is enabled.
in the parent sees only the settled value, as in the previous item.
Verilator 5.052 sees only the final value of an evaluation; Icarus 13.0
also sees the pulse through the port.
- A blocking write of an edge-triggered `always` is an update of the active
region: the processes it wakes run before the same edge's nonblocking
updates. With `y = ~y; q <= q + 1;`, a waiter on `@(y)` reads `q` from
before the edge and waits again before the nonblocking updates
(IEEE 1800-2023 4.5). Icarus 13.0 gives the same values; Verilator 5.052
resumes the waiter after the nonblocking updates.

### Variable lifetimes

Expand Down
Loading