Skip to content

fix(sv): write the bits inside a part-select partly outside its vector - #1782

Merged
mergify[bot] merged 2 commits into
masterfrom
fix/sv-partial-out-of-range-selects
Oct 23, 2026
Merged

mergify[bot] merged 2 commits into
masterfrom
fix/sv-partial-out-of-range-selects

Conversation

@tignear

@tignear tignear commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Part of #1123. Fixes #1778.

IEEE 1800-2023 11.5.1: a write to a part-select partly outside the vector writes the bits inside, and a write wholly outside has no effect.

Form Before Now
q[9:6] = v on logic [7:0] q, in always_comb, a process, always_ff (blocking or nonblocking) nothing written q[7:6] = v[1:0]
up[6:9] = v on logic [0:7] up nothing written up[6:7] = v[3:2]
assign q[9:6] = v; nothing driven q[7:6] driven
assign q[11:8] = v; rejected as "at a run-time position" no effect
a[1][k +: 4] = v with k known at compile time (time-zero initial, unrolled loop) wrote into a[0] / a[2] stays within a[1]

Fix

  • New constant_select_write: clips a constant select to the variable. It returns the bits inside and how many low value bits fall below the variable.
    • Used by the comb write target (Target::Static now carries the select width and the dropped bits), by the always_ff and process write, and by the write-target scans of both.
    • A select fully inside gives the same access as before, so its SIR is unchanged.
  • The array-element bleed: a run-time select within a constant array element is confined to that element by its window (dynamic_packed_write). Comb's store propagation and the always_ff loop overlay replaced its position with a constant, which counts from bit 0 of the whole array.
    • New keep_element_window: keeps the fold only while the folded range stays within the element, and otherwise falls back to the run-time form.
    • Only selects whose fold would leave the element change.
  • packed_index_position is identical to the one in feat(sv): run nonblocking assignments in processes to array elements and run-time positions #1773, at the same place, so the two merge cleanly.

Not in this PR (unchanged, rejected with a clear error)

  • Reading a constant part-select partly outside its vector, e.g. r = q[9:6], is rejected ("always_ff expression"); 11.5.1 reads x for the missing bits.
  • The analyzer rejects a constant part-select of an array element or inner packed dimension that leaves its declared range, e.g. m[1][9:6] ("part-select of m outside its declared range").

Both are candidates for a follow-up.

Perf

Optimized SIR (TraceOptions::post_optimized_sir, hashed Debug text) is byte-identical between base d7bb5a3 and this branch for 626 of the 629 SV suite cases, timed and untimed. The three that differ are the new cases.

Since #1720, a Simulator build of a timed design fails, but its trace still holds the SIR produced before that error. The digest now reads the trace, so timed designs are compared as real SIR rather than as build errors.

Tests

  • New vtests in indexed_select:
    • constant_part_selects_partly_outside_write_the_bits_inside
    • ascending_part_selects_partly_outside_write_the_bits_inside
    • known_run_time_selects_stay_within_their_element (timed)
  • Icarus passes all three.
  • Verilator 5.052 writes the out-of-range bits (0x5f for the wholly outside write, the wrong end for the ascending one, and 0x80 for the element). The three cases join the existing sv_verilator_part_select_write_overhang exclusion; its pre-exclusion records and the LIMITATIONS table are updated.
  • The retained indexed_select.json reports gain only the three new records.
  • New Rust test continuous_part_selects_partly_outside_drive_the_bits_inside covers the continuous assignment. Icarus 13.0 aborts on it (vvp set_vec assertion), so it can't be a suite case.
  • sv-tests: no change against expected.tsv.
  • Docs: EN and JA, "Out-of-range selects".

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 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 🔄 Running since 2026-10-23T03:37:10.542991Z 1358eba 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 merge-ready Request merging through Mergify after required checks and removed merge-ready Request merging through Mergify after required checks labels Oct 23, 2026
@tignear
tignear force-pushed the fix/sv-partial-out-of-range-selects branch from de340eb to f6997d8 Compare October 23, 2026 01:40
@tignear tignear added merge-ready Request merging through Mergify after required checks and removed merge-ready Request merging through Mergify after required checks labels Oct 23, 2026
@tignear
tignear force-pushed the fix/sv-partial-out-of-range-selects branch from f6997d8 to c32f6db Compare October 23, 2026 02:22
A blocking, comb, always_ff or continuous write to a constant part-select
partly outside the vector wrote nothing; it now writes the bits inside,
taking the matching bits of the value (IEEE 1800-2023 11.5.1). A write
wholly outside still has no effect, and a continuous one is no longer
rejected as a run-time position.

A run-time select within one array element whose position is known while
the design is compiled, from a time-zero initial block or an unrolled
loop, was folded to a constant position of the whole array and wrote into
the neighbouring elements. Such a fold is kept only while it stays within
the element.

Verilator 5.052 writes these out-of-range bits; the three new cases join
the existing part-select overhang exclusion. Icarus passes them.

Fixes #1778

Change-Id: I85269ba41a9587ee1e8f159dde592f0ddb2061b6
Change-Id: I479256f5f43fad0f27b36f979226b3abed2cd284

@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: c32f6db59d

ℹ️ 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 +219 to +220
.and_then(|(msb, lsb)| constant_select_write(variable, msb, lsb)?.0)
.unwrap_or(whole),

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 Skip wholly out-of-range targets in the process scan

When an always_comb body only contains a now-supported no-op such as q[11:8] = v for an 8-bit q, constant_select_write returns Some((None, _)), but this and_then converts it to None and unwrap_or(whole) records all of q as written. The generated body contains no store, so retention analysis can report an inferred latch for a statement that writes no bits; edge-process metadata likewise contains a phantom whole-variable target. Handle the wholly-outside result separately and avoid adding a target.

Useful? React with 👍 / 👎.

Comment on lines +7383 to +7384
if start > end {
return Some((None, 0));

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 Exclude no-op slices from driver overlap analysis

For two assignments to the same wholly out-of-range slice, such as two continuous assignments to q[11:8] when q is 8 bits, this helper makes both writes no-ops during lowering, but continuous_driver_ranges and local_driver_ranges still collect the raw [8:11] ranges through net_lvalue_range. Their overlap check therefore rejects the module as having multiple drivers before lowering reaches this return. The driver scans need to clip ranges to the destination and omit ranges with no in-bounds bits.

Useful? React with 👍 / 👎.

@tignear
tignear force-pushed the fix/sv-partial-out-of-range-selects branch from c32f6db to 1358eba Compare October 23, 2026 03:37
@mergify

mergify Bot commented Oct 23, 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 23, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 23, 2026
@mergify

mergify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 1 hour 13 minutes 10 seconds in the queue, including 1 hour 11 minutes 33 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 a5aa1f2 into master Oct 23, 2026
30 checks passed
@mergify
mergify Bot deleted the fix/sv-partial-out-of-range-selects branch October 23, 2026 05:37
@mergify mergify Bot removed the queued Mergify queue entry label Oct 23, 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.

SV: constant part-select partly out of range writes nothing

1 participant