Skip to content

perf(runtime): handle element-strided unpacked arrays per element - #2048

Merged
mergify[bot] merged 1 commit into
masterfrom
feature/perf/2029-unpacked-per-element
Oct 25, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
feature/perf/2029-unpacked-per-element

Conversation

@tignear

@tignear tignear commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2029

What

Whole element-strided unpacked arrays were materialized as one BigUint by shifting every element into or out of an array-sized value. That is quadratic in the array size. rtlmeter C906's 2^19-element SRAM banks made the tiered start run out of memory (apply_initial_values → get_four_state/set_four_state → gather_strided/scatter_strided). The native backend spent minutes in read_signal_plane/write_signal_plane after compiling.

  • Initial values: InitialStateData::Packed for an element-strided array becomes write runs (InitialStateData::packed_write_runs, linear). They go through the existing per-element apply_initial_memory_writes, so the array is never read and written back whole. This covers all three sites: Simulator::apply_initial_values, declaration records, and the native backend's initial state. Two-state targets still get unknown bits as 0.
  • Array-to-array commits (interpreter, whole-object NBA commit): element bytes are copied directly (SignalArrayLayout::copy) instead of gather + scatter.
  • Host API boundary (get_four_state/set_four_state/get_wide/set_wide of a whole array): interpreter gather_strided/scatter_strided and native read_signal_plane/write_signal_plane now share linear SignalArrayLayout::gather/scatter. They build the packed byte image in one pass, so a whole-array BigUint exists only when a caller asks for the whole value.

Cranelift and WASM never use element-strided storage (array_layout: None), so they had no such path.

Validation

  • New: backend::tiered::tests::strided_sv_arrays_initialize_commit_and_read_like_packed_ones. An SV four-state 13-bit × 8 array starts as X through packed initial values, then takes element writes and whole-array NBA commits. The element-strided interpreter (gated tiered, never promotes), the packed interpreter and native (both asserted strided where expected) agree on every element and on the whole-array read.
  • New: celox-runtime strided_planes_round_trip_like_element_shifts checks gather/scatter/copy against per-element BigUint shifts for element widths 1–70, including padding and bits past the array.
  • New: celox-design packed_write_runs_match_the_packed_merge checks that applying the runs equals the packed merge, in two- and four-state, for empty, full, sparse and over-wide written masks.
  • cargo nextest run -p celox -p celox-runtime -p celox-design -p celox-test-suite -p celox-vpi --features celox/systemverilog,celox/cranelift,celox/wasm-runtime,celox/wasm-component,celox-vpi/cranelift,celox-vpi/wasm-runtime,celox-test-suite/runtime-cases: 14255 passed, 207 skipped. (The first CI run caught a VPI regression: handles on part of an array keep the whole plane size, and native write_signal_plane cleared it whole; plane accesses now cover only the handle's elements, SignalArrayLayout::element_extent.)
  • cargo clippy (touched crates, all targets, same features) and cargo fmt --check: clean.

This is a complexity fix (quadratic → linear), so no benchmark per the issue.

@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-25T17:43:05.988481Z a686342 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
Whole element-strided arrays were materialized as one BigUint by shifting
every element into or out of an array-sized value, which is quadratic in
the array size. rtlmeter C906's 2^19-element SRAM banks made the tiered
start run out of memory in apply_initial_values, and the native backend
spent minutes in read_signal_plane/write_signal_plane.

Packed initial values of an element-strided array become write runs
(`InitialStateData::packed_write_runs`) applied element by element.
Whole-array commits in the interpreter copy element bytes directly. The
host-boundary gather/scatter of the interpreter and the native backend
share linear `SignalArrayLayout::gather`/`scatter`, so a whole-array
BigUint exists only when a caller asks for the whole value.

Closes #2029

Change-Id: I5e80207ab292701da28aa9de019ebe3c87ddfcbc
@tignear
tignear force-pushed the feature/perf/2029-unpacked-per-element branch from 1149564 to a686342 Compare October 25, 2026 17:41
@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 18:14 UTC · Rule: changes · triggered by rule Queue explicitly requested merges
  • ✅ Checks passed · on draft merge queue: checking #2048 on master (9f87847) #2056
  • ✅ Merged — 2026-10-25 18:48 UTC · at 28d4c0b2ceaa4ad074d2a781661fbc0fa79f04e2 · merge

This pull request spent 33 minutes 59 seconds in the queue, including 31 minutes 42 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 mentioned this pull request Oct 25, 2026
40 of 71 tasks
@mergify
mergify Bot merged commit 28d4c0b into master Oct 25, 2026
23 checks passed
@mergify
mergify Bot deleted the feature/perf/2029-unpacked-per-element branch October 25, 2026 18:48
@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(runtime): handle unpacked arrays per element instead of as one BigUint

1 participant