From 51b3703ee040460a555f8b880e8dda5ed434f27b Mon Sep 17 00:00:00 2001 From: tignear Date: Sat, 24 Oct 2026 19:20:09 +0900 Subject: [PATCH 1/3] fix(sim): judge derived clocks after several nonblocking updates When several updates publish in one NBA region, or a domain commits its blocking results in the active region, or publishes several evaluations, the runtime marks the edges among the updates as occurrences. It did not register their signals as sources of combinationally derived clocks, so the settle that followed kept only the marked occurrences and dropped the edge of a clock such as clk & ren. The derived clocks of a source that changed are now judged at that settle, as for the processes' writes. Fixes #1860. Change-Id: I5d30a1832ead72125172cfa3425a809cfafdb147 --- crates/celox-runtime/src/simulation/edges.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/celox-runtime/src/simulation/edges.rs b/crates/celox-runtime/src/simulation/edges.rs index d39c37cb958..e6218c47e53 100644 --- a/crates/celox-runtime/src/simulation/edges.rs +++ b/crates/celox-runtime/src/simulation/edges.rs @@ -242,6 +242,17 @@ impl SimulationState { ) { for &(id, is) in transitions { let was = round.previous(id, is, || self.last_level(id)); + // Clocks computed from the signal are judged at the settle that + // follows, as for the processes' writes (`mark_scheduled_edges`). + if was != is + && self + .model + .combinational_derived + .get(id) + .is_some_and(|derived| !derived.is_empty()) + { + round.gating_sources.push(id); + } let kind = self.model.domain_kinds[id]; let triggered = if self.four_state { settled_edge::(kind, was, is) From 618be45e8ec003b2a7a0e1da2c9523a3c6e7e192 Mon Sep 17 00:00:00 2001 From: tignear Date: Sat, 24 Oct 2026 19:20:10 +0900 Subject: [PATCH 2/3] test(sv): cover derived clocks after several nonblocking updates and commits Change-Id: Idb4448de658b44a14d031190bbd61bc5a5a2e596 --- crates/celox-test-suite/LIMITATIONS.md | 2 +- .../src/sv/cases/timing.vtest | 70 +++++++++++++++++++ .../verification/sv/icarus/timing.json | 33 +++++++++ .../verification/sv/limitations.json | 3 +- .../verification/sv/verilator/timing.json | 45 ++++++++++++ .../tests/frontends/systemverilog/timing.rs | 3 + 6 files changed, 154 insertions(+), 2 deletions(-) diff --git a/crates/celox-test-suite/LIMITATIONS.md b/crates/celox-test-suite/LIMITATIONS.md index 97530f68a62..f1a5c10df98 100644 --- a/crates/celox-test-suite/LIMITATIONS.md +++ b/crates/celox-test-suite/LIMITATIONS.md @@ -584,7 +584,7 @@ four-state expectations; the assertions remain enabled on all Celox variants. | `sv_icarus_urandom_narrow_seed` | execute | icarus | 1 | Icarus 13.0 terminates for an 8-bit $urandom seed variable with 'seed variable is less than 32 bits (8)'. IEEE 1800-2023 18.13.1 accepts any integral expression, converted to the int seed formal. A standalone signed/unsigned 8-bit seed probe compiles, then vvp exits with this width error; Verilator passes the same nonzero-seed extension checks. | | `sv_verilator_random_algorithm` | execute | verilator | 2 | Verilator 5.052 does not compute $random with the Annex N algorithm: seeding with 0 returns 1631467331 instead of 303379748, and an unseeded $random draws from its own RNG. IEEE 1800-2023 20.14.1 and Annex N define $random as rtl_dist_uniform(seed, LONG_MIN, LONG_MAX) so that implementations repeat the same values. A standalone probe prints the Annex N sequence in Icarus 13.0 and different values in Verilator. | | `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_verilator_intermediate_writes` | execute | verilator | 7 | 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. | diff --git a/crates/celox-test-suite/src/sv/cases/timing.vtest b/crates/celox-test-suite/src/sv/cases/timing.vtest index 9391d4b7673..5caddf8ce96 100644 --- a/crates/celox-test-suite/src/sv/cases/timing.vtest +++ b/crates/celox-test-suite/src/sv/cases/timing.vtest @@ -2565,3 +2565,73 @@ module Top(input bit clk,output bit[7:0]seen);bit q;Child c(clk,q);initial forev (top Top) (run_until 6) (assert_eq t 0x22)) + +; A clock computed from a clock that one of several nonblocking updates +; changes has its edge in that NBA region (IEEE 1800-2023 4.5, 10.4.2): +; `rclk = clk & ren` rises with `clk` while `ren` is 1. +(case derived_clocks_follow_several_nonblocking_updates + (source "derived_nba.sv" #" + module Top; + bit clk, clk2; bit ren = 0; bit rclk; bit [7:0] e = 0; + assign rclk = clk & ren; + always_ff @(posedge clk) ren <= ~ren; + always_ff @(posedge rclk) e <= e + 8'd1; + initial begin + #9 clk <= 1; #1; clk <= 0; + #3 clk <= 1; clk2 <= 1; #1; clk <= 0; clk2 <= 0; + #3 clk <= 1; #1; clk <= 0; + end + initial begin #12 $display("t12 e=%0d", e); #4 $display("t16 e=%0d", e); #4 $display("t20 e=%0d", e); $finish; end + endmodule + "#) + (top Top) + (run_to_finish) + (expect_output "t12 e=1\nt16 e=2\nt20 e=3\n")) + +; A clock computed from a blocking result that a domain commits in the +; active region (#1783) has its edges there. +(case derived_clocks_follow_active_region_commits + (source "derived_active.sv" #" + module Top; + bit clk, clk2, c2, en = 1; + wire g = c2 & en; + int cnt, w; + always @(posedge clk) c2 = ~c2; + initial forever begin @(c2); w++; end + always_ff @(posedge g) cnt <= cnt + 1; + initial begin + repeat (4) begin #1 clk <= 1; clk2 <= 1; #1 clk <= 0; clk2 <= 0; end + #1 $display("cnt=%0d w=%0d", cnt, w); + $finish; + end + endmodule + "#) + (top Top) + (run_to_finish) + (expect_output "cnt=2 w=4\n")) + +; A domain evaluated twice before one NBA region publishes both +; evaluations; the continuous assignment of the clock computed from its +; output sees the final value (IEEE 1800-2023 4.7). +(case derived_clocks_follow_superseded_publications + (source "derived_superseded.sv" #" + module Top; + bit clk, c, q, en = 1; + wire gq = q & en; + int cnt, n; + always_ff @(posedge clk) q <= c; + always_ff @(posedge gq) cnt <= cnt + 1; + initial forever begin @(q); n++; end + initial begin + #1 c = 1; clk = 1; + #0 clk = 0; c = 0; + #0 clk = 1; + #1 clk = 0; + #1 $display("cnt=%0d n=%0d q=%0d", cnt, n, q); + $finish; + end + endmodule + "#) + (top Top) + (run_to_finish) + (expect_output "cnt=0 n=1 q=0\n")) diff --git a/crates/celox-test-suite/verification/sv/icarus/timing.json b/crates/celox-test-suite/verification/sv/icarus/timing.json index 0a0b6efdeb2..c852b7b7933 100644 --- a/crates/celox-test-suite/verification/sv/icarus/timing.json +++ b/crates/celox-test-suite/verification/sv/icarus/timing.json @@ -1412,6 +1412,39 @@ "stronger_than_sv": false, "tag_reasons": {}, "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::derived_clocks_follow_several_nonblocking_updates", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::derived_clocks_follow_active_region_commits", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::derived_clocks_follow_superseded_publications", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] } ] } diff --git a/crates/celox-test-suite/verification/sv/limitations.json b/crates/celox-test-suite/verification/sv/limitations.json index 76dc9455d36..49b8c9e86d6 100644 --- a/crates/celox-test-suite/verification/sv/limitations.json +++ b/crates/celox-test-suite/verification/sv/limitations.json @@ -2011,7 +2011,8 @@ "timing::staged_nonblocking_writes_wake_waiters", "timing::intermediate_combinational_writes_keep_other_drivers", "timing::parallel_flip_flop_parts_keep_pulses", - "timing::staged_nonblocking_writes_follow_later_blocking_writes" + "timing::staged_nonblocking_writes_follow_later_blocking_writes", + "timing::derived_clocks_follow_superseded_publications" ] } }, diff --git a/crates/celox-test-suite/verification/sv/verilator/timing.json b/crates/celox-test-suite/verification/sv/verilator/timing.json index 7c115851699..6ee3604ca45 100644 --- a/crates/celox-test-suite/verification/sv/verilator/timing.json +++ b/crates/celox-test-suite/verification/sv/verilator/timing.json @@ -1572,6 +1572,51 @@ "stronger_than_sv": false, "tag_reasons": {}, "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::derived_clocks_follow_several_nonblocking_updates", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::derived_clocks_follow_active_region_commits", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "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 print the spec counts in Icarus 13.0 and 1 or 0 in Verilator.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_disagreement", + "evidence": [ + "verification/repros/sv_intermediate_writes_verilator.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_verilator_intermediate_writes", + "observed_version": "Verilator 5.052", + "phase": "execute", + "reason": "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 print the spec counts in Icarus 13.0 and 1 or 0 in Verilator.", + "upstream": [] + }, + "name": "timing::derived_clocks_follow_superseded_publications", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] } ] } diff --git a/crates/celox/tests/frontends/systemverilog/timing.rs b/crates/celox/tests/frontends/systemverilog/timing.rs index 2ab8a3bccde..b617d74cc48 100644 --- a/crates/celox/tests/frontends/systemverilog/timing.rs +++ b/crates/celox/tests/frontends/systemverilog/timing.rs @@ -172,6 +172,9 @@ timed_cases! { fn plain_always_expression_edges_run_as_processes = "timing::plain_always_expression_edges_run_as_processes"; fn plain_always_multi_bit_edges_follow_the_lsb = "timing::plain_always_multi_bit_edges_follow_the_lsb"; fn plain_always_edges_without_a_reset_run_as_processes = "timing::plain_always_edges_without_a_reset_run_as_processes"; + fn derived_clocks_follow_several_nonblocking_updates = "timing::derived_clocks_follow_several_nonblocking_updates"; + fn derived_clocks_follow_active_region_commits = "timing::derived_clocks_follow_active_region_commits"; + fn derived_clocks_follow_superseded_publications = "timing::derived_clocks_follow_superseded_publications"; } #[test] From badea1a26bde967340013db7a26fc665e6a29e63 Mon Sep 17 00:00:00 2001 From: tignear Date: Sun, 25 Oct 2026 02:43:59 +0900 Subject: [PATCH 3/3] test(sv): keep retained rows only for the excluded derived-clock case Change-Id: I0d371af10f284bee80cf83580dccb19c6ce29825 --- .../verification/sv/icarus/timing.json | 33 ------------------- .../verification/sv/verilator/timing.json | 22 ------------- 2 files changed, 55 deletions(-) diff --git a/crates/celox-test-suite/verification/sv/icarus/timing.json b/crates/celox-test-suite/verification/sv/icarus/timing.json index c852b7b7933..0a0b6efdeb2 100644 --- a/crates/celox-test-suite/verification/sv/icarus/timing.json +++ b/crates/celox-test-suite/verification/sv/icarus/timing.json @@ -1412,39 +1412,6 @@ "stronger_than_sv": false, "tag_reasons": {}, "tags": [] - }, - { - "category": "Sequential", - "detail": "", - "expectation": "Simulation", - "name": "timing::derived_clocks_follow_several_nonblocking_updates", - "phase": "execute", - "status": "passed", - "stronger_than_sv": false, - "tag_reasons": {}, - "tags": [] - }, - { - "category": "Sequential", - "detail": "", - "expectation": "Simulation", - "name": "timing::derived_clocks_follow_active_region_commits", - "phase": "execute", - "status": "passed", - "stronger_than_sv": false, - "tag_reasons": {}, - "tags": [] - }, - { - "category": "Sequential", - "detail": "", - "expectation": "Simulation", - "name": "timing::derived_clocks_follow_superseded_publications", - "phase": "execute", - "status": "passed", - "stronger_than_sv": false, - "tag_reasons": {}, - "tags": [] } ] } diff --git a/crates/celox-test-suite/verification/sv/verilator/timing.json b/crates/celox-test-suite/verification/sv/verilator/timing.json index 6ee3604ca45..b9969462312 100644 --- a/crates/celox-test-suite/verification/sv/verilator/timing.json +++ b/crates/celox-test-suite/verification/sv/verilator/timing.json @@ -1573,28 +1573,6 @@ "tag_reasons": {}, "tags": [] }, - { - "category": "Sequential", - "detail": "", - "expectation": "Simulation", - "name": "timing::derived_clocks_follow_several_nonblocking_updates", - "phase": "execute", - "status": "passed", - "stronger_than_sv": false, - "tag_reasons": {}, - "tags": [] - }, - { - "category": "Sequential", - "detail": "", - "expectation": "Simulation", - "name": "timing::derived_clocks_follow_active_region_commits", - "phase": "execute", - "status": "passed", - "stronger_than_sv": false, - "tag_reasons": {}, - "tags": [] - }, { "category": "Sequential", "detail": "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 print the spec counts in Icarus 13.0 and 1 or 0 in Verilator.",