Skip to content

perf(sv): publish only written elements of nonblocking array writes - #1869

Merged
mergify[bot] merged 1 commit into
masterfrom
stack/tignear/feature/fix/1855-nba-array-commit/publish-only-written-elements-nonblocking-array--04824191
Oct 24, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
stack/tignear/feature/fix/1855-nba-array-commit/publish-only-written-elements-nonblocking-array--04824191

Conversation

@tignear

@tignear tignear commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

An edge process that writes an unpacked array by a nonblocking assignment
at a run-time element seeded the whole array into its next state and
committed all of it back on every edge. Each edge cost O(array size), and
the generated code and compile time grew with the array (#1855).

Such an array now uses the sparse next-state protocol that shared edge
memories (and Veryl's dynamic writes) already use: element stores mark
dirty 64-bit chunks, and the commit copies only those.

Precondition, decided in edge_only_memories() (lowering.rs):

  • all local drivers of the array are edge processes of its module, and
  • the process writes it only by nonblocking constant-range or element
    writes, at least one at a run-time element (no blocking, whole-array or
    read-modify-write assignment).
    Every other array keeps the full next state. The function's doc comment is
    the hook for writers outside the module (hierarchical references, feat(sv): hierarchical references (reads and procedural writes across instances) #1856).

A write by another process between the evaluation and the NBA region
(e.g. a #0 resumption of an initial) is clobbered by the commit. This
is pre-existing for every edge-process target, not only arrays, and is
tracked and fixed separately in #1864. This change only narrows it: the
sparse commit rewrites the dirty chunks, where the old one rewrote the
whole array.

Performance (100,000 cycles, celox run --two-state --unlimited --backend cranelift, release build, user time, taskset -c 8-11):

b3_mem_sweep master this
2^10 0.12 s 0.07 s
2^12 0.20 s 0.07 s
2^14 0.64 s 0.07 s
2^16 4.26 s 0.09 s
2^22 (heliodor-dev) 2-cycle startup alone 86.8 s user, 3.7 GB full run 0.50 s, 125 MB
2^22 four-state (heliodor-dev) - full run 0.44 s

Startup of the 2-cycle variants (heliodor-dev): 2^16 0.88 s -> 0.01 s
user; 2^22 110 s wall / 3.7 GB -> 0.36 s / 125 MB. Compile time and
memory had the same cause.

Unaffected workloads (callgrind, release): b2_vm_dispatch_bit.sv generates
identical JIT code; whole-program 44.51 G -> 44.57 G instructions (+0.12%),
all in compile-time functions this change does not touch, with identical
call counts (e.g. DriverScan::body 56,773,692 calls in both). A Veryl
64K-word dynamic-index memory workload: identical JIT code, 188.40 M ->
188.80 M (+0.2%, about 4 host instructions per cycle in
testbench::clock_periods and two runtime-event helpers this change does
not touch). Both are code-layout differences of the LTO build.

Validation:

  • cargo test -p celox --features systemverilog --test systemverilog:
    4372 passed.
  • New shared case procedural::nonblocking_runtime_element_writes_apply_in_order
    (cranelift, native, wasm, parallel variants), passes on Verilator 5.052
    and Icarus 13.0 (verify-sv-verilator, verify-sv-icarus).
  • New IR test nonblocking_runtime_element_writes_use_sparse_next_state
    (sparse for NBA element writes; full next state with a blocking or
    whole-array write).
  • A semantics stress design (multiple NBAs to one element, reads of old
    values, part-select merge, constant elements, X index) gives identical
    results to master on cranelift, interpreter, native O0 and wasm, two-
    and four-state; four-state matches xezim.
  • cargo clippy -p celox-frontend-sv -p celox --features celox/systemverilog --tests, cargo fmt --check.

Closes #1855

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 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-24T09:21:09.706527Z 31eedff New commits
ℹ️ 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.

@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 24, 2026
An edge process that writes an unpacked array by a nonblocking assignment
at a run-time element seeded the whole array into its next state and
committed all of it back on every edge. Each edge cost O(array size), and
the generated code and compile time grew with the array (#1855).

Such an array now uses the sparse next-state protocol that shared edge
memories (and Veryl's dynamic writes) already use: element stores mark
dirty 64-bit chunks, and the commit copies only those.

Precondition, decided in `edge_only_memories()` (lowering.rs):
- all local drivers of the array are edge processes of its module, and
- the process writes it only by nonblocking constant-range or element
  writes, at least one at a run-time element (no blocking, whole-array or
  read-modify-write assignment).
Every other array keeps the full next state. The function's doc comment is
the hook for writers outside the module (hierarchical references, #1856).

A write by another process between the evaluation and the NBA region
(e.g. a `#0` resumption of an `initial`) is clobbered by the commit. This
is pre-existing for every edge-process target, not only arrays, and is
tracked and fixed separately in #1864. This change only narrows it: the
sparse commit rewrites the dirty chunks, where the old one rewrote the
whole array.

Performance (100,000 cycles, `celox run --two-state --unlimited --backend
cranelift`, release build, user time, `taskset -c 8-11`):

| b3_mem_sweep | master | this |
|---|---:|---:|
| 2^10 | 0.12 s | 0.07 s |
| 2^12 | 0.20 s | 0.07 s |
| 2^14 | 0.64 s | 0.07 s |
| 2^16 | 4.26 s | 0.09 s |
| 2^22 (heliodor-dev) | 2-cycle startup alone 86.8 s user, 3.7 GB | full run 0.50 s, 125 MB |
| 2^22 four-state (heliodor-dev) | - | full run 0.44 s |

Startup of the 2-cycle variants (heliodor-dev): 2^16 0.88 s -> 0.01 s
user; 2^22 110 s wall / 3.7 GB -> 0.36 s / 125 MB. Compile time and
memory had the same cause.

Unaffected workloads (callgrind, release): b2_vm_dispatch_bit.sv generates
identical JIT code; whole-program 44.51 G -> 44.57 G instructions (+0.12%),
all in compile-time functions this change does not touch, with identical
call counts (e.g. `DriverScan::body` 56,773,692 calls in both). A Veryl
64K-word dynamic-index memory workload: identical JIT code, 188.40 M ->
188.80 M (+0.2%, about 4 host instructions per cycle in
`testbench::clock_periods` and two runtime-event helpers this change does
not touch). Both are code-layout differences of the LTO build.

Validation:
- `cargo test -p celox --features systemverilog --test systemverilog`:
  4372 passed.
- New shared case `procedural::nonblocking_runtime_element_writes_apply_in_order`
  (cranelift, native, wasm, parallel variants), passes on Verilator 5.052
  and Icarus 13.0 (`verify-sv-verilator`, `verify-sv-icarus`).
- New IR test `nonblocking_runtime_element_writes_use_sparse_next_state`
  (sparse for NBA element writes; full next state with a blocking or
  whole-array write).
- A semantics stress design (multiple NBAs to one element, reads of old
  values, part-select merge, constant elements, X index) gives identical
  results to master on cranelift, interpreter, native O0 and wasm, two-
  and four-state; four-state matches xezim.
- `cargo clippy -p celox-frontend-sv -p celox --features
  celox/systemverilog --tests`, `cargo fmt --check`.

Closes #1855

Change-Id: I04824191d94b708b96866eab3e40f39eea515417
@tignear
tignear force-pushed the stack/tignear/feature/fix/1855-nba-array-commit/publish-only-written-elements-nonblocking-array--04824191 branch from 974373e to 31eedff Compare October 24, 2026 09:19
@tignear

tignear commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Revision history

# Type Changes Reason Date
1 initial 974373e 2026-10-24 09:19 UTC
2 rebase 974373e → 31eedff (rebase only) 2026-10-24 09:19 UTC

@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

@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 4 hours 19 minutes 43 seconds in the queue, including 2 hours 11 minutes 20 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 41426c2 into master Oct 24, 2026
30 checks passed
@mergify
mergify Bot deleted the stack/tignear/feature/fix/1855-nba-array-commit/publish-only-written-elements-nonblocking-array--04824191 branch October 24, 2026 15:24
@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.

perf: dynamic-index NBA into an unpacked array costs O(array size) per edge

1 participant