Skip to content

fix(sv): keep other processes' writes made before an edge's NBA region - #1884

Merged
mergify[bot] merged 1 commit into
masterfrom
stack/tignear/feature/fix/1855-nba-array-commit/keep-other-processes-writes-made-edge-s-nba-region--8356911e
Oct 24, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
stack/tignear/feature/fix/1855-nba-array-commit/keep-other-processes-writes-made-edge-s-nba-region--8356911e

Conversation

@tignear

@tignear tignear commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

An edge process evaluates into a next state seeded from stable state, and
its NBA commit copies the whole written range back. A process kernel that
writes the same variable after the evaluation and before the NBA region,
such as a #0 resumption or a process the edge's blocking result wakes,
lost its write, even in bits no nonblocking assignment touched and when
no nonblocking assignment executed (#1864). An NBA update changes only the
bits its lvalue names (IEEE 1800-2023 10.4.2), and the NBA region follows
the active and inactive regions (4.4.2.4).

Such a variable now goes through the exact staging that variables written
both by blocking and nonblocking assignments already use: the nonblocking
assignments write a staging value and mark a written-bit mask, and the NBA
region merges stable = (stable & ~mask) | (value & mask). The variable
has no seed or whole-range commit. An unpacked array merges element by
element in a loop, and its mask is cleared by a commit from its zero
stable copy.

The change is per signal. kernel_window_writes() (lowering.rs) collects
the variables a process kernel of the module may write after it first
suspends. Code before the first timing control of an initial runs at
time zero before any domain evaluates, so memory initialization by
initial loops or $readmemh does not count. A process stages only
those of its nonblocking targets it does not also write by blocking
assignments or in called subroutines. Every other signal keeps today's
code, and #1855's sparse array publication still applies to arrays
without such a writer. Writers from other modules (hierarchical
references, #1856) have to be added to kernel_window_writes(). A staged
array costs O(array size) per edge, as before #1855.

Not covered, keeping the previous behavior: nonblocking assignments in
subroutines the edge process calls, and host writes while a $stop
suspends a round after a domain evaluated.

Repros from #1864 (plain always @(posedge clk); with always_ff a second
writer is illegal, 9.2.2.4 → 9.2.2.2), celox run --top <m> --unlimited
on cranelift, interpreter, native O0 and wasm, two- and four-state, all
now match Icarus 13.0:

Case Expected (Icarus) Before After
win_c_al m0=00001122 m0=00001100 expected
win_d_al m0=00000011 m1=00000022 m5=00000033 m1=00000000 m5=00000000 expected
win_e_al q=00000022 r=00100008 q=00000000 r=00000008 expected
active-region wake q=22 p=44 q=00 p=44 expected

Performance (callgrind, heliodor-dev, this vs #1855): no signal of these
workloads is staged, and their JIT code executes the same instruction
counts (b2_vm_dispatch_bit 411.55 M, Veryl 64K-word memory workload
15.19 M, b3_mem_sweep_14 0.43 M per run). Whole program: b2 46.686 G ->
46.683 G, Veryl 217.23 M -> 217.26 M, b3_mem_sweep_14 139.07 M -> 139.16 M
(within 0.07%).

Validation:

  • New shared cases timing::edge_nonblocking_updates_keep_later_writes_of_other_bits,
    timing::edge_nonblocking_updates_follow_writes_their_blocking_results_wake
    and timing::edge_blocking_results_precede_later_process_writes on
    cranelift, native, wasm and parallel variants. The first two fail
    without this change. All three pass on Verilator 5.052 and Icarus 13.0.
  • cargo test -p celox --features systemverilog --test systemverilog:
    4462 passed. cargo test -p celox-frontend-sv.
  • cargo clippy -p celox-frontend-sv -p celox --features celox/systemverilog --tests, cargo fmt --check.

Closes #1864

Depends-On: #1869

An edge process evaluates into a next state seeded from stable state, and
its NBA commit copies the whole written range back. A process kernel that
writes the same variable after the evaluation and before the NBA region,
such as a `#0` resumption or a process the edge's blocking result wakes,
lost its write, even in bits no nonblocking assignment touched and when
no nonblocking assignment executed (#1864). An NBA update changes only the
bits its lvalue names (IEEE 1800-2023 10.4.2), and the NBA region follows
the active and inactive regions (4.4.2.4).

Such a variable now goes through the exact staging that variables written
both by blocking and nonblocking assignments already use: the nonblocking
assignments write a staging value and mark a written-bit mask, and the NBA
region merges `stable = (stable & ~mask) | (value & mask)`. The variable
has no seed or whole-range commit. An unpacked array merges element by
element in a loop, and its mask is cleared by a commit from its zero
stable copy.

The change is per signal. `kernel_window_writes()` (lowering.rs) collects
the variables a process kernel of the module may write after it first
suspends. Code before the first timing control of an `initial` runs at
time zero before any domain evaluates, so memory initialization by
`initial` loops or `$readmemh` does not count. A process stages only
those of its nonblocking targets it does not also write by blocking
assignments or in called subroutines. Every other signal keeps today's
code, and #1855's sparse array publication still applies to arrays
without such a writer. Writers from other modules (hierarchical
references, #1856) have to be added to `kernel_window_writes()`. A staged
array costs O(array size) per edge, as before #1855.

Not covered, keeping the previous behavior: nonblocking assignments in
subroutines the edge process calls, and host writes while a `$stop`
suspends a round after a domain evaluated.

Repros from #1864 (plain `always @(posedge clk)`; with `always_ff` a second
writer is illegal, 9.2.2.4 → 9.2.2.2), `celox run --top <m> --unlimited`
on cranelift, interpreter, native O0 and wasm, two- and four-state, all
now match Icarus 13.0:

| Case | Expected (Icarus) | Before | After |
|---|---|---|---|
| win_c_al | `m0=00001122` | `m0=00001100` | expected |
| win_d_al | `m0=00000011 m1=00000022 m5=00000033` | `m1=00000000 m5=00000000` | expected |
| win_e_al | `q=00000022 r=00100008` | `q=00000000 r=00000008` | expected |
| active-region wake | `q=22 p=44` | `q=00 p=44` | expected |

Performance (callgrind, heliodor-dev, this vs #1855): no signal of these
workloads is staged, and their JIT code executes the same instruction
counts (b2_vm_dispatch_bit 411.55 M, Veryl 64K-word memory workload
15.19 M, b3_mem_sweep_14 0.43 M per run). Whole program: b2 46.686 G ->
46.683 G, Veryl 217.23 M -> 217.26 M, b3_mem_sweep_14 139.07 M -> 139.16 M
(within 0.07%).

Validation:
- New shared cases `timing::edge_nonblocking_updates_keep_later_writes_of_other_bits`,
  `timing::edge_nonblocking_updates_follow_writes_their_blocking_results_wake`
  and `timing::edge_blocking_results_precede_later_process_writes` on
  cranelift, native, wasm and parallel variants. The first two fail
  without this change. All three pass on Verilator 5.052 and Icarus 13.0.
- `cargo test -p celox --features systemverilog --test systemverilog`:
  4462 passed. `cargo test -p celox-frontend-sv`.
- `cargo clippy -p celox-frontend-sv -p celox --features
  celox/systemverilog --tests`, `cargo fmt --check`.

Closes #1864

Change-Id: I8356911ef0608ae6eb0175147ca64ddc8881f7b9
@tignear

tignear commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

This pull request is part of a Mergify stack:

# Pull Request Link
1 perf(sv): publish only written elements of nonblocking array writes #1869
2 fix(sv): keep other processes' writes made before an edge's NBA region #1884 👈

@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 🔄 Running since 2026-10-24T09:19:38.537867Z 3c4944a 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 24, 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 24, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 24, 2026
@mergify

mergify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 2 hours 19 minutes 17 seconds in the queue, including 1 hour 52 seconds running CI.

Required conditions to merge

Base automatically changed from stack/tignear/feature/fix/1855-nba-array-commit/publish-only-written-elements-nonblocking-array--04824191 to master October 24, 2026 15:24
@mergify
mergify Bot merged commit ab37d11 into master Oct 24, 2026
31 checks passed
@mergify
mergify Bot deleted the stack/tignear/feature/fix/1855-nba-array-commit/keep-other-processes-writes-made-edge-s-nba-region--8356911e branch October 24, 2026 16:19
@mergify mergify Bot removed the queued Mergify queue entry label Oct 24, 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.

NBA commit clobbers writes by other processes between FF eval and NBA commit

1 participant