Skip to content

perf(sv): publish only the written elements of an array another process writes - #2024

Merged
mergify[bot] merged 1 commit into
masterfrom
feature/perf/sv-nba-site-merge
Oct 25, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
feature/perf/sv-nba-site-merge

Conversation

@tignear

@tignear tignear commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Sometimes a process's nonblocking writes go to an unpacked array that another process also writes, for example a testbench loading a RAM through hierarchical references. Such an array is staged for an exact publication (IEEE 1800-2023 10.4.2): its nonblocking writes go to a value plane and a mask plane, so the other process's writes between the evaluation and the NBA region survive. The merge (emit_array_nba_merge) looped over every element on every edge, and every evaluation also reset the whole mask plane, so an edge cost the whole array whether or not anything was written.

On rtlmeter C906, the SRAM model is 16 banks of reg [7:0] mem [2**19-1:0] written by mem[PortAAddr] <= PortADataIn, and the testbench loads them hierarchically. Every clock edge ran 16 × 524288 element merges: 4.6 s per edge on the interpreter, where the run stalled after "Load program to memory". The native backend runs the same loops compiled.

Change

The new path applies when each nonblocking write of such an array is a select that runs at most once an evaluation: none is in a loop, a concatenation, a whole-array write or a slice. Then:

  • Recording. stage_nonblocking also records, per write site, the bit range the write covers (its lsb and msb) and that it ran, in hidden variables.
  • Merge. For each site that ran, in order, the merge (emit_array_site_merge) publishes the elements the range covers and clears their mask bits.
  • Reset. The whole-array mask reset at evaluation is gone; the merge leaves the mask clear.

Why the values stay the same:

  • An element merged by an earlier site finds its mask clear, so a later merge does nothing.
  • An out-of-range or unknown index wrote no mask bits (7.4.5), so its merge does nothing either.
  • Only masked bits change, so the other process's writes to the same element in the same step stay in the bits the nonblocking write did not write, and a nonblocking write to the same bits lands after them.

Any other staged array merges every element as before, and its element merge emits the same instructions.

On the C906 interpreter run, the stall is gone: the probe reaches cycle 500 at 82 s, which used to take more than 5 minutes. A 2^19 × 8 RAM loaded hierarchically runs 80 cycles in 0.10 s, against 6.25 s before.

Tests

  • New hierarchical_references case nonblocking_element_writes_keep_hierarchical_writes_of_the_same_step. It uses a descending mem [15:0] with two nonblocking write sites (a whole element and a part-select), a hierarchical load of all elements, and hierarchical writes in the same step as a nonblocking write, both to another element and to the same bits. It also includes an out-of-range write. The expected output is from Icarus Verilog 13; xezim gives the same.
  • The C906 SRAM mini repro (mem.v, memC2.v: the C906 SRAM modules with the testbench's load) gives the same words as Icarus and xezim with and without this change, on the interpreter and native backends.
  • Affected tests with CI features (celox/{systemverilog,cranelift,wasm-runtime,wasm-component,veryl-reference}, celox-test-suite/{verilator,icarus,xezim,runtime-cases}) over celox, celox-frontend-sv and celox-test-suite: 14810 passed, 330 skipped. The run predates the new case's registration; the new case then passed on all five backend variants (cranelift, cranelift_parallel, wasm, native, native_parallel), as did the other 91 hierarchical_references tests.
  • b2_vm_dispatch_bit callgrind (release, native, --toggle-collect='*SimulationState*step_until*'), master 23411b0 against this branch: JIT code 2,761,200,000 Ir on both (identical); totals 4,195,604,063 and 4,191,404,060 Ir.

Closes #2020

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-25T14:12:58.472875Z 6db33ad 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 25, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 764aee7971

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +4723 to +4726
out.push(record(
&site.lsb_name,
expr_from_const_expr(lsb).expect("a staged site's bounds are expressions"),
));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the bounds' evaluation width before recording them

For an externally written array with an NBA such as mem[addr + 32'd1] <= d, where addr is a 32-bit unsigned input equal to 32'hffffffff, these assignments evaluate the flattened bounds in the hidden destination's 64-bit context. The actual element write evaluates its offset without that context (write_element calls lower_expr_with_context with no width), so its arithmetic wraps at 32 bits and writes the valid element selected by index zero. The recorded bounds instead retain the overflow, causing emit_array_site_merge to skip publication and leave the mask uncleared. Evaluate each bound at its original width before extending it, or record the actual normalized write position.

Useful? React with 👍 / 👎.

; nonblocking write did not write, and a nonblocking write to the same bits
; lands after them; an out-of-range write writes nothing (IEEE 1800-2023
; 7.4.5, 10.4.2).
(case nonblocking_element_writes_keep_hierarchical_writes_of_the_same_step

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Register the new regression in Celox's backend harness

The new case is not registered in crates/celox/tests/frontends/systemverilog/hierarchical_references.rs; a repository-wide search for its name finds only this declaration. Celox's backend tests execute explicitly registered @case entries, so the added expectations are not exercised by the normal SystemVerilog regression tests. Add the corresponding sv_backends! entry. This also violates AGENTS.md's requirement to “Wire shared cases into Celox's backend test harness.”

AGENTS.md reference: AGENTS.md:L102-L104

Useful? React with 👍 / 👎.

@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

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

Reason

The pull request #2024 has been manually updated

Waiting for
  • check-success = Queue validation
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
    • check-success = @github-actions/Lint & Format
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
    • check-success = @github-actions/NAPI Build (Windows)
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
    • check-success = @github-actions/Rust Test & NAPI Build
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
    • check-success = @github-actions/JS Test (Ubuntu)
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
    • check-success = @github-actions/JS Test (Windows)
All conditions
  • check-success = Queue validation
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
    • check-success = @github-actions/Lint & Format
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
    • check-success = @github-actions/NAPI Build (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
    • check-success = @github-actions/Rust Test & NAPI Build
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
    • check-success = @github-actions/JS Test (Ubuntu)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
    • check-success = @github-actions/JS Test (Windows)
  • check-success = Conventional Commit title
  • 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

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

…ss writes

A process's nonblocking writes to an unpacked array that another process
also writes, such as a testbench loading a RAM through hierarchical
references, are staged in a value and a mask plane so that the other
process's writes in between survive (IEEE 1800-2023 10.4.2). Their merge
looped over every element on every edge, and every evaluation reset the
whole mask plane. On rtlmeter C906 that is 16 x 524288 element merges per
clock edge, 4.6 s per edge on the interpreter.

When each nonblocking write of such an array is a select that runs at
most once an evaluation (none is in a loop, a concatenation, a whole-array
or a slice write), each write now also records the bit range it wrote and
that it ran. The merge publishes only the elements those ranges cover and
clears their mask bits, so an edge costs its writes. Elements another
write already merged find their mask clear, and an out-of-range write
marked no mask bits. Other arrays merge every element as before.

Closes #2020

Change-Id: Iaa55fbe4ea0ab9588872ac23384812d151dba56a
@tignear
tignear force-pushed the feature/perf/sv-nba-site-merge branch from 764aee7 to 6db33ad Compare October 25, 2026 14:10
@mergify mergify Bot added queued Mergify queue entry and removed queued Mergify queue entry labels Oct 25, 2026
@mergify

mergify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 36 minutes 53 seconds in the queue, including 34 minutes 34 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 ff45fc8 into master Oct 25, 2026
25 checks passed
@mergify
mergify Bot deleted the feature/perf/sv-nba-site-merge branch October 25, 2026 15:15
@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.

perf(sv): nonblocking writes to an array another process writes merge every element on every edge

1 participant