Skip to content

feat(sv): accept loop temporaries shared by plain edge always blocks - #1950

Merged
mergify[bot] merged 1 commit into
masterfrom
feature/fix/1945-shared-loop-temporaries
Oct 25, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
feature/fix/1945-shared-loop-temporaries

Conversation

@tignear

@tignear tignear commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

What

Several plain edge-triggered always processes may now write the same variable, such as the integer i that C906's aq_biu_req_arbiter uses as the index of two always @(posedge clk) loops. Before this change Celox rejected the design with "multiple variable drivers for i".

Only always_comb, always_latch and always_ff restrict a variable to one process (IEEE 1800-2023 9.2.2.2, 9.2.2.4). Otherwise a variable may have several procedural writers, and the last write determines its value (6.5).

How it lowers (per variable)

shared_edge_variables finds variables that are not unpacked arrays and that only plain edge processes write, all by blocking assignments. The edge lowering (Ff::with_shared_variables) then reads and writes their stable state directly, without a per-process working seed or commit. A blocking assignment updates the variable at once (10.4.1). So:

  • a process's reads see its own earlier blocking writes, e.g. the index read after the loop;
  • a read before the process's own write sees the value already committed; a later edge sees the other process's writes;
  • the last write stays, even when a coincident process (same clock or a different clock) does not write the variable.

The ordinary seed/commit protocol could not provide that last point. Each process seeds its working copy from the pre-edge value and commits it back, so a process that conditionally skips the write would commit the stale value over the other process's write.

Still rejected: overlap that involves always_ff (#1865 covers diagnostics), and nonblocking writes to the variable from several processes. Designs without such variables lower exactly as before.

Validation

  • New shared cases in procedural.vtest: same-clock loops with a read after the loop, a read before the write and a conditional writer; two clocks with a coincident edge; and the C906 async-reset arbiter pattern. They pass on all five Celox backends and on Icarus 13.0, Verilator 5.052 and xezim (verify-sv-{icarus,verilator,xezim} --filter procedural::). They also give the same per-tick trace as Verilator in both state modes, and in a variant where one writer calls $display (scheduled kernel path).
  • New rejection test rejects_loop_indices_shared_with_always_ff (always_ff/always_ff, always_ff/always, always/always_ff, and a nonblocking + blocking pair).
  • cargo nextest run -p celox --features systemverilog --test systemverilog --test diagnostic_policy --test sv_scheduled_host_requests: 4777 passed (after rebasing on the current master).
  • cargo nextest run -p celox-test-suite --features verilator,icarus,xezim (retained reports): 81 passed; -p celox-frontend-sv: passed.
  • sv-tests (conformance/sv-tests/run.py --state-mode both --expected conformance/sv-tests/expected.tsv): matches the expectations, no change.
  • cargo fmt --check, cargo clippy -p celox-frontend-sv -p celox --all-targets --features celox/systemverilog: clean.

Performance

Unaffected designs generate identical code. b2_vm_dispatch_bit (no shared writers), native backend, callgrind scoped to SimulationState::step_until, base d9e44c9221 vs this change:

base branch
JIT code (4 functions, per function identical) 2,777,200,097 Ir 2,777,200,097 Ir
total 4,340,404,517 Ir 4,290,204,440 Ir

The rest of the gap is in Rust host functions (settle_pass, get_as, ...). Their source is unchanged; they differ only because the two binaries were built separately. For the target workload, C906's arbiter is now accepted; it was rejected before, so there is no before/after timing to compare.

Closes #1945

@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-25T00:21:20.911717Z
We couldn’t complete this review. Comment @codex review to try again.
b04fc57 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 25, 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 25, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 25, 2026
@mergify

mergify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-25 03:53 UTC · Rule: changes · triggered by rule Queue explicitly requested merges
  • 🚫 Left the queue — 2026-10-25 04:30 UTC · at b04fc57f94623d590ab60f0e942700fa2064fe93

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

Reason

Pull request #1950 has been dequeued

Queue conditions are not satisfied:

  • -conflict

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting 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 25, 2026
Several plain edge-triggered `always` processes may write one variable,
such as the `integer i` that C906's aq_biu_req_arbiter uses as the index
of two `always @(posedge clk)` loops. Only always_comb, always_latch and
always_ff restrict a variable to one process (IEEE 1800-2023 9.2.2.2,
9.2.2.4); otherwise the last write determines the value (6.5). Celox
rejected the design with "multiple variable drivers for `i`".

A variable other than an unpacked array that only plain edge processes
write, and only by blocking assignments, is now accepted. Those processes
read and write its stable state directly, as a blocking assignment
updates the variable at once (10.4.1): a process reads its own preceding
writes, a later edge sees the other process's writes, and the last write
stays even when a coincident process does not write the variable. The
usual per-process working seed and commit would let such a process
commit the pre-edge value over another process's write.

The handling is per variable; designs without such variables lower as
before. always_ff overlap and nonblocking writes from several processes
stay rejected.

Closes #1945

Change-Id: I2bcf163f2ca3ebc3b62c1e6c8fad0c4720f54958
@tignear
tignear force-pushed the feature/fix/1945-shared-loop-temporaries branch from b04fc57 to 7c97e18 Compare October 25, 2026 09:52
@mergify mergify Bot added queued Mergify queue entry and removed dequeued Mergify stopped this queue entry; investigate before retrying labels Oct 25, 2026
@mergify

mergify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 52 minutes 34 seconds in the queue, including 45 minutes 47 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 041f4d9 into master Oct 25, 2026
23 checks passed
@mergify
mergify Bot deleted the feature/fix/1945-shared-loop-temporaries branch October 25, 2026 11:23
@mergify mergify Bot removed the queued Mergify queue entry label Oct 25, 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.

feat(sv): accept loop temporaries shared by plain edge always blocks

1 participant