Skip to content

fix(sv): run waiters of blocking edge writes before the NBA region - #1783

Merged
mergify[bot] merged 2 commits into
masterfrom
feature/fix/sv-active-before-nba
Oct 23, 2026
Merged

mergify[bot] merged 2 commits into
masterfrom
feature/fix/sv-active-before-nba

Conversation

@tignear

@tignear tignear commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1721. Part of #1123.

Problem

A process woken by a blocking write of an edge-triggered process ran only after that edge's nonblocking updates:

always @(posedge clk) begin y = ~y; q <= q + 1; end
initial forever begin @(y); $display("y=%0d q=%0d", y, q); end

Icarus 13.0 prints y=1 q=0, y=0 q=1. Celox printed q=1, q=2, as Verilator 5.052 does. IEEE 1800-2023 4.5 says the blocking write is an update event of the active region, and the NBA region starts only once the active and inactive regions are empty. So the waiter runs first and reads q from before the edge. The same ordering explains another symptom: with y = 1; y <= 0; y <= 1; from 0, the waiter did not wait again before the nonblocking updates and woke once per edge instead of the spec count.

Cause

#1480 already splits a domain whose blocking results are observed (active_commits: read by a process kernel, a wait term, another domain's evaluation, or used as an event signal). Its evaluation commits the blocking results, and its apply unit holds only the nonblocking ones. The runtime used that split only through evaluate_before_inactive, and process_phase called it only when a #0 process was pending. In an ordinary round the process phase returned as soon as the active region was empty. continue_round then published the domain's blocking and nonblocking results together, and the woken processes ran in the next round.

Fix

In process_phase, when no process is ready and none is inactive, and a marked trigger evaluates a domain in active_commits, the domain is now evaluated before the NBA region. This is the same evaluation that already happens before an inactive region:

  • its blocking results commit;
  • the waits they wake run in the active region, and any edges they cause are marked;
  • continue_round publishes the deferred nonblocking results with the NBA region (apply_deferred).

The trigger test (active_commit_triggered) uses the same filter as evaluate_before_inactive, so a stale trigger hint of a cascaded domain does not start an early evaluation. No SIR changes: the runtime only changes one condition.

Tests

New timing.vtest cases run on every backend: native, cranelift, both parallel variants and wasm.

Case Expected Icarus 13.0 Verilator 5.052
blocking_write_waiters_run_before_nonblocking_updates y=1 q=0 / y=0 q=1 passes excluded (q=1 / q=2)
blocking_write_waiters_rearm_before_nonblocking_updates n=3 r=3 passes excluded (n=1 r=1)
blocking_write_edges_read_values_before_nonblocking_updates q=2 r=1 s=1 passes passes
  • Without the fix (base runtime): the first case printed q=1/q=2, the second n=2 r=2 and the third r=2 s=2.
  • Verilator exclusion: the two Verilator cases are in a new group, sv_verilator_active_region_waiters. Its evidence is the standalone probes in verification/repros/sv_active_region_waiters_verilator.json; the LIMITATIONS.md row and the retained shard rows are added too.
  • Earlier Icarus differences: the probes from fix(sv): count intermediate writes of combinational and flip-flop units #1726 that differed because of this ordering (mixed, mixedgap, md2, order) now match Icarus.

The docs (systemverilog-reference.md, external-frontends.md) now state the order.

Performance

Runtime Ir measured with callgrind (200k-cycle minus 20k-cycle runs, taskset, two runs each, identical results), base origin/master vs this branch:

Gate active_commits base branch Δ
(a) 64 always_ff lanes empty 1,180,620,062 1,173,240,107 -0.63%
(b1) + blocking stimulus kernel empty 1,569,420,030 1,551,600,037 -1.14%
(b5) + nonblocking stimulus kernel empty 1,702,260,026 1,683,360,033 -1.11%
(c) + watched always_comb pulse empty 3,173,940,040 3,171,036,556 -0.09%
(cs) + watched always @* pulse empty 3,175,560,030 3,172,680,037 -0.09%
(w) worst case: the lanes' clock domain has a blocking write a waiter observes [clk domain] 2,389,140,020 2,837,880,006 +18.78%
  • Gates (a)–(cs): none of them has an observed blocking result, so the only new work on their path is one is_empty() check. The small improvements are code layout.
  • Worst case (w): every edge now does what the spec requires: evaluate, commit the blocking results, settle, check the waits, then publish the nonblocking results. Before, one fused call did it all. That costs about 2,490 Ir more per cycle, the same as today's #0 path.
  • Where the extra cost goes: the evaluation-only call, the extra combinational settle, one more wait check, the level snapshot and a few more trigger-bit copies. No single hot spot.
  • Compile time: unchanged, since there is no SIR change.

Validation

  • cargo test -p celox --features systemverilog --lib --test systemverilog: 4290 passed, 0 failed.
  • cargo test -p celox-runtime: 76 passed, 0 failed.
  • CELOX_SCHEDULER=differential on timing:: (refactor(runtime)!: run timed slots from SimulationState with a differential scheduler harness #1756 harness): 575 passed, 0 failed (the timing:: set also passes with the default scheduler).
  • celox-test-suite --features external --test retained_reports: 3 passed.
  • sv-tests matches expected.tsv: 2state 543/394/90, 4state 545/392/90 (pass/fail/skip).
  • cargo fmt --check and clippy -D warnings are clean.

A domain whose blocking results are observed (active_commits) committed
them in the active region only when a zero delay was pending. In an
ordinary round the process phase returned once the active region was
empty and the domain published its blocking and nonblocking results
together, so a process the blocking write woke ran after the edge's
nonblocking updates (IEEE 1800-2023 4.5).

When nothing is ready or inactive and a marked trigger evaluates such a
domain, the process phase now evaluates it before the NBA region as it
does before an inactive region: the processes its blocking results wake
run in the active region, and the nonblocking results publish with the
NBA region. Fixes #1721.

Change-Id: I620f6bf29af4d7d5cba5e1782aa6ef7fb6d3eb1b
…dates

Change-Id: I076b9f122c74f6ba75e8e635c8643c981cb88b2b
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T01:01:46.951782Z 51942d8 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@mergify

mergify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 23, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 23, 2026
@mergify

mergify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 1 hour 40 minutes 37 seconds in the queue, including 57 minutes running CI.

Required conditions to merge
  • check-success = Conventional Commit title
  • check-success = Queue validation
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Lint & Format
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Windows)
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Rust Test & NAPI Build
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Ubuntu)
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Windows)
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Conventional Commit title
    • check-neutral = @github-actions/Conventional Commit title
    • check-skipped = @github-actions/Conventional Commit title

@mergify
mergify Bot merged commit 928385a into master Oct 23, 2026
31 checks passed
@mergify
mergify Bot deleted the feature/fix/sv-active-before-nba branch October 23, 2026 03:40
@mergify mergify Bot removed the queued Mergify queue entry label Oct 23, 2026
tignear added a commit that referenced this pull request Oct 24, 2026
An event control item `expr iff condition` in a process (IEEE 1800-2023
9.4.2.3) is an event only if the condition holds when the occurrence of
`expr` is detected. The item's terms are lowered as before; the condition
becomes the term's gate: a one-bit module variable itself, or the hidden
`$event[k]` assignment of its truth value, with copies of process-local
operands sampled before the process suspends. The wait does not watch the
gate's operands.

The runtime judges a gated term only at checks after combinational
logic settled, leaving its baseline untouched before then, and wakes the
process only if the gate's least significant bit is a known 1; the
occurrence is consumed either way. Designs without iff keep the
ungated check loop.

A plain `always` whose event has `iff` now runs as a process;
`always_ff` keeps rejecting `iff` (#452). The Japanese guide also gets
the active-region waiter order of #1783.

Closes #1444.

BREAKING CHANGE: celox_design::WaitSite has a new public field `gates`,
and celox_design::schedule::TermModel a new field `gate`; struct
literals of them must set it (`gates: Vec::new()`, `gate: None`).

Change-Id: I59402e1356cac2aaf254082d1feef6348380447a
tignear added a commit that referenced this pull request Oct 24, 2026
An event control item `expr iff condition` in a process (IEEE 1800-2023
9.4.2.3) is an event only if the condition holds when the occurrence of
`expr` is detected. The item's terms are lowered as before; the condition
becomes the term's gate: a one-bit module variable itself, or the hidden
`$event[k]` assignment of its truth value, with copies of process-local
operands sampled before the process suspends. The wait does not watch the
gate's operands.

The runtime judges a gated term only at checks after combinational
logic settled, leaving its baseline untouched before then, and wakes the
process only if the gate's least significant bit is a known 1; the
occurrence is consumed either way. Designs without iff keep the
ungated check loop.

A plain `always` whose event has `iff` now runs as a process;
`always_ff` keeps rejecting `iff` (#452). The Japanese guide also gets
the active-region waiter order of #1783.

Closes #1444.

BREAKING CHANGE: celox_design::WaitSite has a new public field `gates`,
and celox_design::schedule::TermModel a new field `gate`; struct
literals of them must set it (`gates: Vec::new()`, `gate: None`).

Change-Id: I59402e1356cac2aaf254082d1feef6348380447a
tignear added a commit that referenced this pull request Oct 24, 2026
An event control item `expr iff condition` in a process (IEEE 1800-2023
9.4.2.3) is an event only if the condition holds when the occurrence of
`expr` is detected. The item's terms are lowered as before; the condition
becomes the term's gate: a one-bit module variable itself, or the hidden
`$event[k]` assignment of its truth value, with copies of process-local
operands sampled before the process suspends. The wait does not watch the
gate's operands.

The runtime judges a gated term only at checks after combinational
logic settled, leaving its baseline untouched before then, and wakes the
process only if the gate's least significant bit is a known 1; the
occurrence is consumed either way. Designs without iff keep the
ungated check loop.

A plain `always` whose event has `iff` now runs as a process;
`always_ff` keeps rejecting `iff` (#452). The Japanese guide also gets
the active-region waiter order of #1783.

Closes #1444.

BREAKING CHANGE: celox_design::WaitSite has a new public field `gates`,
and celox_design::schedule::TermModel a new field `gate`; struct
literals of them must set it (`gates: Vec::new()`, `gate: None`).

Change-Id: I59402e1356cac2aaf254082d1feef6348380447a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-ready Request merging through Mergify after required checks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SV: a waiter woken by an edge process's blocking write runs after that edge's NBA updates

1 participant