Skip to content

fix(sv)!: settle two-state sensitivity-list processes at time zero, like Verilator - #2078

Merged
mergify[bot] merged 1 commit into
masterfrom
feature/fix/2021-two-state-comb-time-zero
Oct 25, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
feature/fix/2021-two-state-comb-time-zero

Conversation

@tignear

@tignear tignear commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

always @* and always @(list) wait for a change before their first run (IEEE 1800-2023 9.2.2.2, 9.4.2). In four-state mode their outputs start as X, so the wait rarely shows. In two-state mode the outputs start as a real 0 that drives logic. In rtlmeter's C906, axi_slave128 computes mem_cen / mem_wen in always @(cur_state or wdata_s0[127:0] or wvalid_s0 or wready or wstrb_s0[15:0]). Until an input changed, the 0s read as a write enable: at cycle 2 every SRAM bank wrote 0 over the reset vector the testbench had loaded, and the CPU never started. Verilator 5.052 (two-state) evaluates these blocks once at time zero, after the initial blocks.

Two-state mode now does the same; four-state mode keeps the LRM behavior:

  • always @*, and a list that names exactly the reads of its statement (which the frontend already lowers as always @*), run on their first activation like always_comb: no startup snapshot, and ordered after the initial blocks (Ff::lower_comb_process).
  • Any other level-sensitive always @(list) statement lowers as #0; forever begin statement; @(list); end. It runs once at time zero after the time-zero statements of the initial blocks, then waits. This covers C906's list, whose full-width part-selects do not count as naming the variables, and incomplete or over-complete lists.

Treating a full-width part-select in a list as naming the variable would have turned C906's blocks into combinational processes. That cost about 10% more instructions before the testbench starts, so those blocks stay processes. With this change, C906 (interpreter, two-state) runs 2-3% more instructions up to "Init Program", spread over the frontend.

BREAKING CHANGE: in two-state mode, always @* and sensitivity-list processes run once at time zero, so their outputs and $displays appear at time zero. Use four-state mode for the LRM's wait.

Closes #2021. Closes #2026.

  • Shared cases always_comb::two_state_sensitivity_lists_run_at_time_zero (C906's write-enable block and an always @*) and always_comb::two_state_other_sensitivity_lists_run_at_time_zero (an over-complete and an incomplete list) match Verilator. They carry the new oracle tag two_state_time_zero_settle, since SV has the processes wait. Icarus simulates them in four-state SV and prints X, which the new reviewed exclusion sv_icarus_two_state_time_zero_settle records, with standalone probes in verification/repros/sv_two_state_time_zero_settle.json.
  • Cases and tests whose subject is the LRM wait or the startup guard now run in four-state mode: the latch always @* startup and change-return cases, timing::explicit_list_of_every_read_waits_for_a_change, timing::list_with_an_extra_signal_wakes_on_it, program::program_nonblocking_updates_follow_design_updates, and the startup-guard tests of sv_declaration_startup. The $urandom sensitivity test expects always @* draws at time zero.

Verification

  • Verilator 5.052 reference (--binary --timing): the C906 block and always @* give 1 ffff 1, the over-complete and incomplete lists give 1 7, displays included; Icarus 13.0 gives X. Celox two-state now matches Verilator, and four-state matches Icarus (unchanged).
  • cargo nextest run -p celox -p celox-test-suite -p celox-frontend-sv with CI's features (celox/systemverilog,celox/cranelift,celox/wasm-runtime,celox/wasm-component,celox/veryl-reference,celox-test-suite/runtime-cases): 14809 passed.
  • clippy (workspace minus lydite, same features, --all-targets -D warnings): clean. retained_reports: passed.
  • verify-sv-icarus / verify-sv-verilator on the always_comb, latch, timing, program and system_functions groups: no mismatches or errors; Icarus ignores the two tagged cases through the new exclusion.
  • sv-tests (2- and 4-state): identical to conformance/sv-tests/expected.tsv.
  • C906 (--backend interpreter --two-state, instructions until "Init Program"): 336.6 G / 339.3 G vs 330.2 G / 329.6 G before.
  • b2_vm_dispatch_bit callgrind gate: running; result to follow in a comment.

The earlier version of this change hit a native register-allocation verification failure (#2041) on the C906 block lowered as always @*; the block now stays a process, and the native variants pass.

…ike Verilator

`always @*` and `always @(list)` wait for a change before their first run (IEEE 1800-2023 9.2.2.2, 9.4.2). In four-state mode their outputs start as X, so the wait rarely shows. In two-state mode the outputs start as a real 0 that drives logic. In rtlmeter's C906, `axi_slave128` computes `mem_cen` / `mem_wen` in `always @(cur_state or wdata_s0[127:0] or wvalid_s0 or wready or wstrb_s0[15:0])`. Until an input changed, the 0s read as a write enable: at cycle 2 every SRAM bank wrote 0 over the reset vector the testbench had loaded, and the CPU never started. Verilator 5.052 (two-state) evaluates these blocks once at time zero, after the initial blocks.

Two-state mode now does the same; four-state mode keeps the LRM behavior:
- `always @*`, and a list that names exactly the reads of its statement (which the frontend already lowers as `always @*`), run on their first activation like `always_comb`: no startup snapshot, and ordered after the initial blocks (`Ff::lower_comb_process`).
- Any other level-sensitive `always @(list) statement` lowers as `#0; forever begin statement; @(list); end`. It runs once at time zero after the time-zero statements of the initial blocks, then waits. This covers C906's list, whose full-width part-selects do not count as naming the variables, and incomplete or over-complete lists.

Treating a full-width part-select in a list as naming the variable would have turned C906's blocks into combinational processes. That cost about 10% more instructions before the testbench starts, so those blocks stay processes. With this change, C906 (interpreter, two-state) runs 2-3% more instructions up to "Init Program", spread over the frontend.

BREAKING CHANGE: in two-state mode, `always @*` and sensitivity-list processes run once at time zero, so their outputs and `$display`s appear at time zero. Use four-state mode for the LRM's wait.

Closes #2021. Closes #2026.

- Shared cases `always_comb::two_state_sensitivity_lists_run_at_time_zero` (C906's write-enable block and an `always @*`) and `always_comb::two_state_other_sensitivity_lists_run_at_time_zero` (an over-complete and an incomplete list) match Verilator. They carry the new oracle tag `two_state_time_zero_settle`, since SV has the processes wait. Icarus simulates them in four-state SV and prints X, which the new reviewed exclusion `sv_icarus_two_state_time_zero_settle` records, with standalone probes in `verification/repros/sv_two_state_time_zero_settle.json`.
- Cases and tests whose subject is the LRM wait or the startup guard now run in four-state mode: the latch `always @*` startup and change-return cases, `timing::explicit_list_of_every_read_waits_for_a_change`, `timing::list_with_an_extra_signal_wakes_on_it`, `program::program_nonblocking_updates_follow_design_updates`, and the startup-guard tests of `sv_declaration_startup`. The `$urandom` sensitivity test expects `always @*` draws at time zero.

Change-Id: I73580672abd3acfb040c78cfd4daae2f7df786e2
@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-25T20:23:47.914591Z 2c391c4 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.

@tignear

tignear commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 25, 2026
@mergify

mergify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 49 minutes 28 seconds in the queue, including 32 minutes 43 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 added the queued Mergify queue entry label Oct 25, 2026
@mergify
mergify Bot merged commit 91c70d2 into master Oct 25, 2026
23 checks passed
@mergify
mergify Bot deleted the feature/fix/2021-two-state-comb-time-zero branch October 25, 2026 21:38
@mergify mergify Bot removed the queued Mergify queue entry label Oct 25, 2026
@tignear

tignear commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Post-merge b2_vm_dispatch_bit callgrind gate (release builds, taskset -c 8-11, run --backend native --top bench_vm_dispatch --two-state --unlimited, two runs each), comparing the merge commit with its first parent:

e984aaf (parent) 91c70d2 (this PR)
output BENCH_DONE cycles=200000 checksum=136 same
step_until (inclusive) 4,204,004,002 / 4,204,004,002 4,204,004,002 / 4,204,004,002
PROGRAM TOTALS 20,864,968,598 / 20,865,021,323 20,867,533,717 / 20,867,533,933 (+0.01%)

The simulation is unchanged; the difference is compile-side. The native backend is used because the tiered default is not reproducible under callgrind.

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

1 participant