Repository navigation
fix(sv): count intermediate writes of combinational and flip-flop units - #1726
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Queued — the merge queue status continues in this comment ↓. |
b750326 to
7300779
Compare
7300779 to
e182d7e
Compare
a3d7365 to
37be913
Compare
Merge Queue Status
This pull request spent 1 hour 37 minutes 24 seconds in the queue, with no time running CI. ReasonThe pull request conflicts with the base branch The pull request was held in the queue, conflicting with at least one of 2 pull requests ahead of it. The conflict became a base branch one after #1737, #1766 merged. HintYou should update or rebase your pull request. If you want to requeue this pull request, you can post a Requeued — the merge queue status continues in this comment ↓. |
A process waiting on a variable missed a value that one evaluation of an always_comb, a blocking edge-triggered always or an always_ff writes and then overwrites (`y = 0; if (a) y = 1;`). Each store is an update event (IEEE 1800-2023 4.3, 9.4.2), and nonblocking updates apply in the NBA region in issue order, each its own update (10.4.2). In a design with a wait: - An always_comb that may store a variable twice is lowered both symbolically and as a gated imperative unit. Assembly keeps the unit for an instance in which such a variable is counted, and the symbolic definitions otherwise. - A flip-flop evaluation that may write a signal twice keeps its first written value and counts the occurrences between later writes as pending; the commit adds the occurrence from the published value to the first one, and the pending ones. Staged nonblocking writes of a variable also written by blocking assignments are counted on the value the NBA merge publishes. - Commits of a counted signal written once are counted at the commit. Units that write no counted signal are unchanged, and a design without a wait lowers exactly as before. Fixes #1706 Change-Id: I6096fe2d13f0205b53fd8342c9057801a71c2465
Add timing cases for intermediate writes of always_comb, always @*, blocking edge-triggered always and always_ff bodies, for staged nonblocking writes, and for a pulse behind a child's output port. Verilator 5.052 sees only settled values, so the first three are excluded for it. Icarus 13.0 collapses the output port and counts the child's pulse, which 4.7 and 23.3.3 leave open; the port case asserts the settled count and is excluded for Icarus. Both exclusions keep standalone repros. Change-Id: Id2eb6d5daaefaa8604216f8cc543269a5716e59f
Replace the #1706 limitation in 'Event and level waits' with the behavior: every write of one evaluation is an update a waiter sees, nonblocking updates apply in issue order, and a child's output port shows only the settled value. Change-Id: Id7909b9972b7574eeabd8d5f1910df4ba47eb75b
Change-Id: Ie0a71ea46beca39a738c17cc203f752ea8173e2b
A flip-flop stream now applies each write to a private copy and marks the bits written so far. A write that changes covered bits is an occurrence; a write of uncovered bits compares at the commit with the value the commit publishes over, so a staged nonblocking update is judged against the final blocking value. Each commit releases only the bits it publishes and no unit clears the stream on entry, so the parts of a parallel build no longer wipe each other's held writes. An instance that keeps the imperative alternative of an always_comb removes only the symbolic paths of that process's target ranges, so other drivers of the same variables keep theirs. Change-Id: I93f3569cb5edb5ed981fda8bf33fdf3401e19d17
Three timing cases for the review findings on intermediate writes, verified with Icarus 13.0. Verilator 5.052 sees only final values and joins the existing sv_verilator_intermediate_writes exclusion, with standalone probes. Change-Id: I795ddad81bf28d02100c45a6c7d25fe358160fe3
Flattening may split the symbolic definition of a counted always_comb at the boundaries of its readers, so an instance that keeps the imperative unit now removes every path overlapping one of the process's target ranges, not only exact ones. Overlapping drivers are rejected earlier, so no other driver loses a path. A flip-flop unit starts the bits of a held stream that it seeds empty, or a whole staging value, which one process writes. An evaluation that a runtime error ended before its commit, and that the host continues, no longer leaves held writes for the next one, while the other parts of an evaluation keep theirs. Change-Id: If3d08166804161c395482b6534e6aa8238c0d971
A reader of some bits of a counted always_comb variable, and a counted output port connected to a concatenation. Icarus 13.0 and Verilator 5.052 both pass them. Change-Id: I5fb7bf6c32594eb3403a1a2eff64ec98257f1d35
A $fatal ends an always_ff evaluation after it wrote a watched variable and before its commit; the host continues, and later edges that rewrite the bit to its own value wake no waiter on every backend. Change-Id: Ia88c8150faf478de68e42a7a270684b3e881d240
37be913 to
4f4d93a
Compare
Merge Queue Status
This pull request spent 1 hour 13 minutes 35 seconds in the queue, including 1 hour 11 minutes 32 seconds running CI. Required conditions to merge
|
Fixes #1706. Part of #1123 (dynamic primitive: occurrence counters at store time).
Problem
A process waiting on
@(y)missed a value that one evaluation of analways_comb, a blocking edge-triggeredalwaysor analways_ffwrites and then overwrites (y = 0; if (a) y = 1;,y <= 0; if (a) y <= 1;). Every store is an update event that triggers the waiter (IEEE 1800-2023 4.3, 4.5, 9.4.2), and nonblocking updates apply in the NBA region in issue order, each its own update (10.4.2).always @*already counted them.Why only
always @*worked:always @*is lowered to a gated imperative unit, whose repeated stores get counter slots and are instrumented in assembly.always_combis lowered symbolically.y = 0; if (a) y = 1;becomes one expression, so the intermediate store no longer exists when assembly runs (O0 and O1 alike).Change
Everything below applies only in a design with at least one wait. A design without one, such as pure RTL, lowers exactly as before.
always_comb: a process that may store a variable twice is lowered both ways: symbolically, as today, and as a gated imperative unit.ProcModule::checkpoint/rollback), so nothing of the attempt remains.$display, assertions) keeps only its symbolic form.watch::PendingSlots): an evaluation that may write a signal twice holds the occurrences back until the commit that publishes them. So a waiter wakes when the update is applied (the active region for blocking writes, the NBA region for nonblocking ones), and each update counts in issue order.$fatal, a non-progressing loop, a runtime limit) that ended an evaluation before its commit, and the next evaluation then starts clean. Other parts of the same evaluation keep what they hold.timing::runtime_error_before_a_commit_leaves_no_held_writes(a Rust test, since the vtest DSL cannot express a resumed runtime error) hits a$fatalbetween two writes of a watchedy, runs on, and asserts no waiter wakes, on native, cranelift and both parallel backends. Without the entry clear it fails withn=1.counter != seen), so a commit adds one change for all the changes it releases. Rises and falls are counted exactly.always_combalternative paths: an instance that keeps the imperative unit removes only the symbolic paths that process produced: any path that overlaps one of its target ranges. Flattening may have split a definition at the boundaries of its readers (assign w = y[1:0]), so a piece of a range counts. No other driver can write those bits, sincevalidate_variable_driver_rangesrejects overlapping drivers. A continuous assignment or anotheralways_combdriving other bits of the same variable keeps its paths.Every unit that writes no counted address is unchanged.
Semantics checked
The cases were verified with verify-sv-icarus and verify-sv-verilator
--fresh, and Celox agrees with Icarus on all of them except the port case:intermediate_combinational_writes_wake_waiters:always_combandalways @*,comb=3 star=3.intermediate_edge_process_writes_wake_waiters: blocking edgealways,always_ffNBA, a constanty = 0; y = 1;, plus@(posedge y)and@(negedge y)counts:blk=3 nba=3 const=3 rise=3 fall=2. The processes share one clock, so the parallel backends run them as separate evaluate/apply parts.staged_nonblocking_writes_wake_waiters: mixed blocking + NBA staging, whole-variable and partial (z[0] <= …),y=3 z=3.intermediate_combinational_writes_keep_other_drivers: the countedalways_combdrivesy[3:0],assign y[7:4]and anotheralways_combdrive the rest:y=a1 z=f1 n=2 m=3.parallel_flip_flop_parts_keep_pulses: onealways_ffpulsesy[0]back to its value, two others writey[2]/y[1]unchanged, plus independent work so the parallel build splits the processes into parts in one lane:y=001 n=2 f=2on all four backends.staged_nonblocking_writes_follow_later_blocking_writes:y[1] <= 0; y[0] <= 1; y = 2'b00;. The NBA update ofy[0]rises from the final blocking value 0, which a@(posedge y)waiter sees:r=2.intermediate_combinational_writes_replace_split_definitions:assign w = y[1:0]splits the counted variable's symbolic definition; every piece is replaced by the unit:y=0111 w=11 n=3(before the fix: a multiple-driver build error).intermediate_combinational_writes_reach_concatenated_ports: the counted variable is an output port connected to{p, q}:y=1001 n=3,p=10 q=01.child_port_pulses_reach_waiters_settled: a pulse behind a child's output port. The port is a continuous assignment (23.3.3) evaluated after the child yields, so missing the pulse is legal (4.7). Celox and Verilator give 1; Icarus collapses the port and gives 3.Exclusions, each with a standalone repro:
sv_verilator_intermediate_writes: the six cases on intermediate writes (all above except the split-definition and the two port cases) for Verilator 5.052, which sees only final values (comb=1 star=1,blk=1 nba=1 const=1 rise=1 fall=0,y=0 z=0,n=1 m=2,n=0 f=0,r=0).sv_icarus_port_pulses: the port case for Icarus 13.0.Writers of one trigger
Pending streams are chosen per process, before the processes of one trigger are merged. So two processes that each write disjoint bits of
yonce get no stream, and each process's commit is counted on its own (emit_watchedaround eachCommit). No result can be wrong:y, the single writes and commits of the other processes join it (see above).Not in scope, as the issue says: a pulse that reaches a waiter only through comb logic evaluated after the writer yields (
assign y = awitha = 1; a = 0;). Thepulse/pulse2probes are unchanged.Found on the way and filed as #1721 (P1, separate PR): a kernel woken by an edge process's blocking write runs after that edge's NBA updates (master too). The staged case starts
y/zat their blocking values so it does not depend on that.Perf
Base and branch binaries are both built from e06cf24. The branch was later rebased onto 3430315 (#1716 docs and #1679).
SIR: for all 538 SV suite designs (437 untimed, 101 timed), a dump of the post-optimized SIR plus the runtime schema is byte-identical between base and branch. The base dumps were stable across two runs. Only the 4 new cases differ, and they are new.
Review fixes: a dump of the post-optimized SIR plus the runtime schema of every suite design, before (7300779) and after the review fixes, differs only in this PR's own cases: the two earlier ones whose flip-flops write a watched variable twice, and the three new ones. Every other design (576) is byte-identical.
State layout: designs with a wait and a flip-flop or
always_combstream that may be written twice can get hidden pending/counter objects even when nothing watches that variable, so their state layout is not byte-identical. Their SIR behavior is unchanged: no unit is instrumented unless the variable is counted.Runtime, callgrind: local gate, not committed. It is 64 lanes of
always_ffaccumulators with an XOR-reductionalways_comb, driven byadd_clock. Method: whole program at 200,000 cycles minus at 20,000, five runs, median.initial forever @(posedge clk) stim = stim + 3<=always_comb(w = 0; if (stim[0]) w = 1;,@(w))always @*(existing path)sumalways_comband keep its symbolic form; in an earlier pair of binaries (both from 144bbcc) their per-function JIT-code Ir was identical to base.always @*on master: the existing imperative path. The cost is not in the RTL or the new SIR. It is in the runtime's check of a counter-baseline wait, which reads the signal into aValue(BigUint) at every observation:check_waits,read_signal_planeand BigUint conversions. A follow-up perf PR can compare counter baselines on raw planes, asBaseline::Rawalready does, foralways @*too. That changes the publiccelox_runtime::timing::Baseline, so I left it out of this fix.Compile time (callgrind Ir of building the gate design, 0 cycles):
always @*+ thesumalways_combThe increase is the second lowering of the 64-iteration
sumalways_comb(Ff::lower_comb_process, 188M Ir); the candidate analysis is negligible. The whole SV suite (538 designs, built and dumped): user CPU 3.46–3.52 s on base vs 3.47–3.56 s on branch over three runs each, equal within noise (the branch also builds the 4 new cases).Validation
systemverilogfeature: 5676 passed, 0 failed.celox-frontend-coreandcelox-frontend-svunit tests.celox --lib, including the golden call traces:executor_call_traces_are_unchanged,…_of_veryl_clock_domains_…andsv_traces::…_of_sv_designs_…pass unchanged, so there is nothing to explain.--test systemverilog, including every timing case on native, cranelift, native-parallel, cranelift-parallel and wasm.celox-test-suite --features external --test retained_reports.run.py --state-mode both --expected conformance/sv-tests/expected.tsv): verdicts identical, soexpected.tsvis unchanged.cargo fmt --checkand clippy (--all-targetson the touched crates with CI's features,-D warnings) are clean.pnpm docs:buildpasses.Docs
docs/guide/systemverilog-reference.mdand its Japanese counterpart replace the #1706 bullet in "Event and level waits" with the behavior described above.