Skip to content

perf(sv)!: stage nonblocking updates of a target with one writer - #1684

Merged
mergify[bot] merged 4 commits into
masterfrom
feature/sv-nba-fast-path
Oct 22, 2026
Merged

mergify[bot] merged 4 commits into
masterfrom
feature/sv-nba-fast-path

Conversation

@tignear

@tignear tignear commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1123 (step 4) and #1492: the first half of #1492, the pending fast path. Run-time targets (variable index, unpacked elements, reversed selects) stay in #1492.

Summary

Staging instead of queueing. A nonblocking assignment in an SV process used to return to the runtime, which queued the value for the NBA region. A site whose target has one writer now stages the value in the site's object and sets its pending flag (NbaSite::pending, from #1361), and the kernel keeps running. A site issued again in the same slot queues the staged value first, so the last update still wins.

Assembly picks one path at compile time. The SV frontend emits both paths for each site, selected by a load of a switch variable. Assembly, which sees the whole design, then:

  • keeps one path;
  • replaces the selection with a jump;
  • removes the other path.

No branch and no switch state remain at run time. A site stages only if its target meets all of these (a simple syntactic check, no reachability or constant proofs):

The second condition is needed because publication places staged updates after the queued ones. IEEE 1800-2023 10.4.2 performs NBA updates in issue order, so the reordering is only allowed where nothing can see the order. Every other site keeps the ordered queue. A queued site keeps its value in the frontend's staging variable, so it no longer copies it into a second object.

u64 publication. The NBA region used to read each update and its target as BigUint values and merge them with BigUint masks. An update inside a target of at most 64 bits with one state plane is now merged as u64, for queued and staged updates alike. Order and masks are unchanged, and nothing new is allocated. Four-state targets, targets over 64 bits and array signals keep the BigUint merge. The queue also keeps its storage between time slots.

Perf

Local SV gate (not committed), the method of #1459/#1501:

  • design: 64 lanes of always_ff accumulators reading stim, with an XOR reduction;
  • (b1) adds initial forever @(posedge clk) stim = stim + 3; (b5) is the same stimulus with <=;
  • whole program at 200,000 cycles minus at 20,000 cycles, callgrind, five runs, medians;
  • both binaries are built from the same base, master 8b0f2b1 (this branch has since been rebased onto b811bbc).
base this PR
(a) pure RTL 1160640046, 1160665875, 1160699814, 1160646667, 1160699073 (median 1,160,665,875) 1155234883, 1155245646, 1155173832, 1155227313, 1155214532 (median 1,155,227,313)
(b1) blocking stimulus median 1,546,615,941 median 1,545,589,662
(b5) stimulus with <= median 2,108,399,649 median 1,677,319,174
  • (a): for all 412 untimed suite designs, the optimized SIR and runtime schema are byte-identical to master. Only one of the 472 designs differs at all: the existing process-NBA case. Its queued path lost the self-copy, and no site there stages. The base digests were stable across two runs. Callgrind is 0.5% lower, consistent across all five runs, and no run is worse.
  • (b1): equal.
  • (b5): −20%, and now 8.5% above (b1), down from 36%. Staging alone, before the u64 merge, gave only −2% (2,066,203,662). The cost was in the Rust publication, not the kernel's return.
  • Remaining (b5) gap: the comb settle after the NBA region, which the semantics require (stim changes there), plus the Rust publication itself. Step 3b removes both when it compiles the scheduler and the NBA region into SIR.

Validation

  • New timing::staged_nonblocking_updates_keep_their_order. It checks:
    • a site issued three times in a slot: the last value wins;
    • n <= n + 1 issued twice gives 1;
    • two sites of one target issued in the reverse of their textual order: the last issued wins, so that target stays on the queue;
    • a register samples the stimulus value from before the edge.
  • New timing::narrow_nonblocking_updates_keep_the_other_bits. A staged and a queued site each update:
    • a part select across a byte boundary ([11:4] of 16 bits);
    • a 64-bit target;
    • a 65-bit target (BigUint merge).
      The other bits are kept.
  • New timing::four_state_nonblocking_updates_keep_unknown_bits: the X/Z bits around a staged and a queued update survive, and also around a 65-bit one.
  • Oracles and backends: all three pass on Icarus 13.0 and Verilator 5.052 (--fresh). Verilator reports the four-state case as unsupported, being two-state. All three run on all five backends. The retained reports are not regenerated, per CONTRIBUTING (new passing cases need no baseline refresh).
  • Schema tests:
    • nonblocking_sites_stage_only_unobserved_targets_with_one_writer checks that only the stimulus target stages. These stay queued: a target read by wait (a && !b); one read through wire c = d & ~e by @(posedge c); one read by the expression event @(posedge (s & en)) (feat(sv): lower expression events and @* in processes #1681), through its $event variable; one with two sites; one with a blocking writer; a top-level port. It also checks that their behaviour is the same as on master.
    • narrow_nonblocking_updates_cover_staged_and_queued_sites checks that the narrow case exercises both paths.
  • Unit test narrow_merges_match_wide_merges compares the u64 merge with the BigUint merge over widths 1–64, every position and several bit patterns.
  • Oracle disagreement:
    • On the a/b and comb probes (at Support static partial assignments in function body lowering #2, a <= 1; b <= 1; with b having a second writer), Icarus 13.0 sees wait (a && !b) = 0, @(posedge (a & ~b)) = 1 and @(posedge c) = 1. Verilator 5.052 sees 0, 0, 0.
    • These are races between evaluation events in the active region, which IEEE leaves unordered. So the shared case holds only assertions both accept, and the probes are Celox tests.
    • Celox gives 0/0, the same as Verilator, on master and on this branch.
  • Scoped runs, all passing:
    • cargo test -p celox --features systemverilog: lib with golden traces unchanged (174), the SV suite (3299), and the SV-gated binaries plus checkpoint, state_file, processes and simulation_step;
    • cargo test -p celox-runtime -p celox-design -p celox-frontend-core -p celox-frontend-sv -p celox-test-suite;
    • sv-tests conformance (conformance/sv-tests/run.py, both state modes) on b811bbc plus this branch: unchanged from expected.tsv;
    • clippy -D warnings on the affected crates and the SV test target, and fmt --check.

BREAKING CHANGE

celox_frontend_core::symbolic::artifact::SimModule has the new field nba_switches, of the new type NbaSwitch.

@chatgpt-codex-connector

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 ⚠️ Failed 2026-10-21T04:12:33.610486Z
We couldn’t complete this review. Comment @codex review to try again.
9769ade 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@mergify

mergify Bot commented Oct 21, 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 22, 2026
@tignear
tignear force-pushed the feature/sv-nba-fast-path branch from 9769ade to cfc6a79 Compare October 22, 2026 02:26
@mergify mergify Bot added the queued Mergify queue entry label Oct 22, 2026
@mergify

mergify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-22 03:43 UTC · Rule: changes · triggered by rule Queue explicitly requested merges
  • 🚫 Left the queue — 2026-10-22 03:55 UTC · at cfc6a79a720309e6f828b3b03bee99cf5a8a4329

This pull request spent 11 minutes 16 seconds in the queue, with no time running CI.

Reason

The 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 #1679, #1716 merged.

Automatic conflict resolution can merge a conflict like this one instead of stopping on it, but only in a queue using the merge-batch or fast-forward merge method.

Hint

You should update or rebase your pull request.

If you want to requeue this pull request, you can post a @mergifyio queue comment.

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

@mergify mergify Bot added dequeued Mergify stopped this queue entry; investigate before retrying and removed queued Mergify queue entry labels Oct 22, 2026
@tignear tignear removed the dequeued Mergify stopped this queue entry; investigate before retrying label Oct 22, 2026
A nonblocking assignment in a process returned to the runtime, which
queued its value for the NBA region. A site whose target nothing else
writes now stages the value and sets its pending flag instead, and the
kernel keeps running.

The SV frontend emits both paths for each site, selected by a load of a
switch variable. Assembly sees the whole design and keeps one path,
replacing the selection by a jump and removing the other path, so no
branch remains at run time. A site stages only if its target:
- has no other nonblocking site, no store or commit in any unit, and is
  not a top-level port;
- is read by no wait, counted signal, event domain or comb observer,
  directly or through combinational logic.
Publication places staged updates after the queued ones, so the
update order of a staged target must be unobservable. A queued site
keeps its value in the frontend's staging variable, so the queued path
no longer copies it.

BREAKING CHANGE: `celox_frontend_core::symbolic::artifact::SimModule` has
the new field `nba_switches`, of the new type `NbaSwitch`.

Change-Id: I258ddca80817a101f75ae249011b7f894c7dae9f
The new timing case checks that the last update of a site in a time slot
wins, that `n <= n + 1` issued twice gives 1, that updates of two sites
of one target land in the order they were issued, and that a register
samples the stimulus value from before the edge. It passes on Icarus
13.0 and Verilator 5.052.

A Celox test checks which sites stage: only a target with one writer
that no wait reads, directly or through combinational logic.

Change-Id: I7d56dd4826aa8cfee3ad65e464fbc4f81dc718cc
The NBA region read each update and its target as BigUint values and
merged them with BigUint masks. An update inside a target of at most
64 bits with one state plane is now merged as u64, queued and staged
updates alike. The order of the updates and the masks are unchanged.
Four-state targets, targets over 64 bits and array signals keep the
BigUint merge.

Staged sites are read from their value objects only when they are
published, and the queue keeps its storage between time slots.

Change-Id: I77dbee6f9b77624cc15cbbcba2fda5ad25d54c67
A part select across a byte boundary, a 64-bit target and a 65-bit
target each take an update from a staged and from a queued site, and
keep their other bits. A four-state variant checks that the unknown
bits around an update stay unknown. Both pass on Icarus 13.0; Verilator
5.052 runs the two-state one.

Change-Id: I591e062179d07de305b3f5a5fc288de1bedc328e
@mergify mergify Bot added the dequeued Mergify stopped this queue entry; investigate before retrying label Oct 22, 2026
@tignear
tignear force-pushed the feature/sv-nba-fast-path branch from cfc6a79 to 4f17e00 Compare October 22, 2026 04:12
@mergify mergify Bot removed the dequeued Mergify stopped this queue entry; investigate before retrying label Oct 22, 2026
@tignear tignear added merge-ready Request merging through Mergify after required checks and removed merge-ready Request merging through Mergify after required checks labels Oct 22, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 22, 2026
@mergify

mergify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 1 hour 7 minutes 9 seconds in the queue, including 1 hour 5 minutes 24 seconds 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 86a2c20 into master Oct 22, 2026
30 checks passed
@mergify
mergify Bot deleted the feature/sv-nba-fast-path branch October 22, 2026 06:11
@mergify mergify Bot removed the queued Mergify queue entry label Oct 22, 2026
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.

1 participant