Repository navigation
fix(sim)!: commit blocking flip-flop stores in the active region - #1480
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. |
There was a problem hiding this comment.
💡 Codex Review
celox/crates/celox-frontend-core/src/symbolic/assembly.rs
Lines 699 to 701 in 268eaa5
This dependency map is computed before build_comb_observer_capture_paths, and its helper skips every path without a variable target, so runtime observers such as combinational $display, $finish, and assertions never contribute read roots to split_observed_commits. A clocked block that performs q = 1; q <= 2 can therefore remain unified when only an always_comb assertion observes q, causing settling to see only 2 and skip an assertion or fatal condition that should run on the active-region value 1. Include observer sensitivities/arguments as shared reads and allow them to require a split even when they are the only observer.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| step: step.clone(), | ||
| body: stage_nonblocking(body, staged, pm), | ||
| }), | ||
| other => out.push(other.clone()), |
There was a problem hiding this comment.
Stage mixed writes made inside called tasks
When an edge-triggered block calls an untimed task whose body contains q <= value while the caller also writes q with a blocking assignment, scan correctly classifies q as mixed, but this fallback leaves the Call unchanged. The inlined task therefore writes the original working value instead of the NBA staging shadow; for a domain split because a #0 process observes q, that nonblocking value is committed in the active region and no corresponding NBA update remains. Transform called subroutine bodies as well, or perform the staging while lowering assignments rather than only rewriting the top-level statement tree.
Useful? React with 👍 / 👎.
| let mut mixed: Vec<SourceVarId> = self | ||
| .nonblocking | ||
| .intersection(&self.working) | ||
| .copied() | ||
| .filter(|&id| !self.m.is_hidden(id) && self.m.var(id).array_dims.is_empty()) | ||
| .collect(); |
There was a problem hiding this comment.
Preserve NBA staging for mixed unpacked-array writes
When an observed clock domain writes an unpacked-array element with both blocking and nonblocking assignments, this filter excludes the array from staging even though the whole variable is still classified as a blocking target. All of its target ranges consequently enter the active commit and none enter the NBA commit, so a #0 waiter can see the nonblocking value early and a subsequent inactive-region write is not overwritten in the NBA region. Mixed array elements need equivalent value/mask staging, or such domains must not use the split commit path.
Useful? React with 👍 / 👎.
| } | ||
| // The active region is empty: the domains it triggered evaluate | ||
| // before the inactive region's processes resume. |
There was a problem hiding this comment.
Defer NBA publication for directly woken processes
When no process is already waiting in the inactive queue, this early return means evaluate_before_inactive is never called, so the normal round path can use the combined eval/apply unit and publish both blocking and nonblocking FF results before waking a process that waits on the blocking-written signal. For example, a waiter on posedge go from always @(posedge clk) begin go = 1; q <= 7; end resumes only after q has become 7, although it should run in the active region and sample the old q. Active-commit domains must be evaluated and their newly ready processes drained before their NBA apply even when there was no pre-existing #0 work.
Useful? React with 👍 / 👎.
| if self.evaluate_before_inactive(executor, current_time, round)? { | ||
| // Their blocking results are updates of the active region: | ||
| // continuous assignments follow them and the waits they wake | ||
| // run before the inactive region (IEEE 1800-2023 4.5). | ||
| executor.eval_comb()?; | ||
| self.observe_driven(executor.backend()); | ||
| if !self.process_state.ready.is_empty() { | ||
| continue; |
There was a problem hiding this comment.
Drain cascaded active domains before inactive work
If this active commit changes another event signal, eval_comb marks the cascaded domain, but the code only checks for newly ready processes and then resumes the inactive queue. Thus a clocked blocking assignment such as clk2 = 1 can trigger a second domain whose blocking q = 1 is not evaluated until after a pending #0 process has already sampled the old q. Re-run active-domain evaluation after settling until both triggered domains and ready processes are quiescent before moving inactive work to ready.
Useful? React with 👍 / 👎.
| out.push(sv::ir::Stmt::Assign { | ||
| lhs: renamed(lhs, &stage.value_name), | ||
| rhs: rhs.clone(), | ||
| nonblocking: true, | ||
| }); | ||
| out.push(mark(lhs, stage)); |
There was a problem hiding this comment.
Evaluate staged NBA selectors only once
For a mixed variable with a selected nonblocking target, the transformed value assignment and this mask assignment each retain their own clone of the selector expression. A target such as q[next_index()] <= d therefore calls next_index() twice; if it has side effects or returns a different index on the second call, the staged value and mask refer to different bits, so the NBA merge drops the intended update or updates the wrong bit. Hoist and reuse the evaluated lvalue position when generating the value and mask writes.
Useful? React with 👍 / 👎.
1eafa18 to
8439073
Compare
268eaa5 to
050ba19
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 050ba193df
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // only its nonblocking results in the NBA region (IEEE 1800-2023 4.5, | ||
| // 10.4). Every other domain commits both together, as before. | ||
| let mut active_commits = Vec::new(); | ||
| if !processes.is_empty() { |
There was a problem hiding this comment.
Split active commits even without process kernels
In a process-free RTL design, this guard skips splitting even when one domain's blocking output is another domain's event signal or input. For example, if a posedge clk block does q <= 1; clk2 = 1; and a posedge clk2 block samples q, batch_round publishes both first-domain writes together before evaluating the second domain, so it samples the new q rather than the pre-NBA value. Run the observed-domain split for these cascaded FF consumers even when there are no resumable process kernels.
Useful? React with 👍 / 👎.
| pub(crate) watches: Vec<celox_design::EventWatch<AbsoluteAddr>>, | ||
| pub(crate) wait_sites: Vec<celox_design::WaitSite<AbsoluteAddr>>, | ||
| pub(crate) nba_sites: Vec<celox_design::NbaSite<AbsoluteAddr>>, | ||
| pub(crate) active_commits: Vec<AbsoluteAddr>, |
There was a problem hiding this comment.
Bump the native image version for the schema change
Adding this serialized field changes the native image payload, but image_file.rs remains at container version 14, which was already the version in the parent commit. Consequently, existing version-14 images pass the header check and are decoded using the incompatible new schema, potentially consuming subsequent payload bytes as active_commits or returning an opaque invalid-payload error instead of being rejected as an old version. Advance the container version and test rejection of the parent's version 14.
Useful? React with 👍 / 👎.
|
Queued — the merge queue status continues in this comment ↓. |
An edge-triggered `always` committed its blocking and nonblocking results together when its domain applied. IEEE 1800-2023 (4.5, 10.4) executes the blocking stores in the active region and the nonblocking updates in the NBA region (#1470): - A variable one block writes both ways now stages its nonblocking writes in a hidden value and a mask of the bits they wrote; the commit merges them after the blocking value. `q <= 7; q = 2;` ends with 7 and a read after `q <= 7` sees the old `q`, on every path. - In a design with process kernels, a domain whose blocking results are observed (read through combinational logic by a kernel or another domain's evaluation, a wait term, or another domain's event signal) commits them with its evaluation and only the nonblocking ones in the NBA region. The reference loop settles combinational logic and wakes waits after such a domain evaluates before the inactive region, so their processes run in the active region. Other domains and the fused units commit as before. The runtime schema lists those domains, so the native image container moves to version 14; older images are rejected. BREAKING CHANGE: `RuntimeSchema` and `ScheduleModel` have the new field `active_commits`, and native images of container version 13 are rejected. Change-Id: I2c5a64fed1e96648f3c3b7419f39acb5f576bb32
A domain that commits its blocking results before the inactive region changed event signals of other domains, directly or through combinational logic, but the new levels became the edge baseline without an edge. The reference loop now takes the levels before the commits, settles, marks the domains the committed changes trigger, and evaluates them in the same active region before resuming the inactive processes. Change-Id: Ifef70072f1fd3b703438669d1d0524d76e619a4c
050ba19 to
547ccf3
Compare
Merge Queue Status
This pull request spent 43 minutes 44 seconds in the queue, including 36 minutes 45 seconds running CI. Required conditions to merge
|
Fixes #1470. Part of #1123, step 4, PR 2b. Follows #1475 (merged).
Problem
An edge-triggered
alwayscommitted its blocking and nonblocking results together when its domain applied. IEEE 1800-2023 (4.5, 10.4) runs blocking stores in the active region and nonblocking updates in the NBA region. That caused two bugs:q <= 7; q = 2;ended with q=2 instead of 7, with or without processes.#0didn't see the edge's blocking stores (timing cases 19 and 21).Changes
Mixed-write staging (SV FF lowering). A variable that one block writes both ways stages its nonblocking writes in a hidden value and a mask of the bits they wrote. The commit merges them after the blocking value.
q <= 7; q = 2;now ends at 7.q <= 7; x = q;reads the old q.Active and NBA commits, assembly. Only in designs with process kernels. A domain splits its commit when one of its blocking results is observed. Observed means it, or a combinational value computed from it, is any of:
Such a domain commits its blocking results at the end of its eval-only unit (the active region), and its apply unit then holds only the NBA commits. Every other domain, and the fused
eval_apply/eval_comb_applyunits, keep today's single commit.Reference loop. The runtime schema lists the split domains (
active_commits). After one of them evaluates before the inactive region, the loop settles combinational logic and wakes waits. Processes those stores woke then run in the active region, before the inactive ones. Domains that aren't split take exactly today's path, so the existing golden traces are unchanged.Edges from the active commits. Some blocking results change another domain's event signal, directly or through combinational logic, and some change a domain's own derived clock. The reference loop takes the event levels before the split domains evaluate. After the active commits it settles, then marks the domains whose edges those changes give, judged against those earlier levels. They evaluate in the same active region before the inactive processes resume. Without this, the new levels became the edge baseline and the edge was lost (review of this PR).
Native image. The container moves to version 14. A version-13 image is rejected with the existing
UnsupportedVersionerror, covered by a new test.Tests
timing::blocking_ff_clock_edges_trigger_their_domains_before_inactive_work(new): a blocking clock divider, a clock gated from it, and a clock inverted from a blocking store, next to a#0process in the same slot. Each counts 3 edges by t=50. Before the fix Celox gave 0. It passes on Icarus 13.0 and Verilator 5.052 and runs on all five backends. A reference-loop golden,sv_active_commit_edges, records the same behaviour with a host-driven clock.blocking_ff_stores_are_visible_before_inactive_work,mixed_ff_stores_keep_their_active_and_nba_values) run on all five backends.procedural::mixed_blocking_and_nonblocking_writes_keep_their_regionscoversq <= d; x = q; q = 2; r = q;with no processes. Expected: q=d, x = old q, r = 2. It passes on Icarus 13.0 and Verilator 5.052 and runs on every backend.sv_active_commits(interpreter and default backend): after#0the process reads the blocking value 2 andq + 1= 3, and the NBA lands afterwards.modifythat pulsesclk1→0 in zero time wakes the waiting process, but the flip-flop domain judges edges by level and misses the pulse.native_program_image_rejects_v13_before_decoding_changed_schema: the version-13 rejection.review_regressions::commits_ff_output_actuals_whose_index_calls_a_function: its expectation relied on the old last-write-wins result,state <= 0;followed by a blocking write ofstate[k]. Under 10.4 the NBA clear lands last, and Verilator gives state=0 too. The test now clears with a blocking assignment, so it still checks the commit of the output actual.cargo test -p celox --features systemverilog: lib with golden traces, the SV suite (2806, rebased on master), and the checkpoint, flip_flop, processes, state_file, simulation_step, simulation_limits, clock_alias_edges, both_clock_edges, derived_register_clock, ff_comb_clock, multi_clock, reset_edge_cases, native_testbench(_completion), std_edge_detector and shared_jit_cache suites;cargo test -p celox-runtime -p celox-design -p celox-frontend-core -p celox-frontend-sv -p celox-frontend-veryl -p celox-sv-analyzer -p celox-test-suite;-D warningson the affected crates, andfmt --check.Perf
SIR. For all 368 untimed SV suite designs, the SIR and runtime schema are byte-identical to #1475, except for the new, empty
active_commitsfield.Callgrind. Same SV gate and method as #1459 and #1475: 200,000 minus 20,000 cycles, five runs.
@(posedge clk)stimulus kernelalways #5 clk = ~clkEqual or slightly better. (a) has the same SIR, and #1475's 1.12G run is the bimodal group seen before.
BREAKING CHANGE
celox_design::RuntimeSchemaandcelox_design::schedule::ScheduleModelhave the new fieldactive_commits. Native images of container version 13 are rejected.