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
11 changes: 11 additions & 0 deletions crates/celox-runtime/src/simulation/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,17 @@ impl<B: SimBackend> SimulationState<B> {
) {
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::<true>(kind, was, is)
Expand Down
2 changes: 1 addition & 1 deletion crates/celox-test-suite/LIMITATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

Expand Down
70 changes: 70 additions & 0 deletions crates/celox-test-suite/src/sv/cases/timing.vtest
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
3 changes: 2 additions & 1 deletion crates/celox-test-suite/verification/sv/limitations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
},
Expand Down
23 changes: 23 additions & 0 deletions crates/celox-test-suite/verification/sv/verilator/timing.json
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,29 @@
"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": []
}
]
}
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 @@ -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]
Expand Down
Loading