Repository navigation
fix(sv)!: settle two-state sensitivity-list processes at time zero, like Verilator - #2078
Conversation
…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
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@Mergifyio queue |
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
|
|
Post-merge b2_vm_dispatch_bit callgrind gate (release builds,
The simulation is unchanged; the difference is compile-side. The native backend is used because the tiered default is not reproducible under callgrind. |
always @*andalways @(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_slave128computesmem_cen/mem_weninalways @(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 asalways @*), run on their first activation likealways_comb: no startup snapshot, and ordered after the initial blocks (Ff::lower_comb_process).always @(list) statementlowers 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.
always_comb::two_state_sensitivity_lists_run_at_time_zero(C906's write-enable block and analways @*) andalways_comb::two_state_other_sensitivity_lists_run_at_time_zero(an over-complete and an incomplete list) match Verilator. They carry the new oracle tagtwo_state_time_zero_settle, since SV has the processes wait. Icarus simulates them in four-state SV and prints X, which the new reviewed exclusionsv_icarus_two_state_time_zero_settlerecords, with standalone probes inverification/repros/sv_two_state_time_zero_settle.json.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 ofsv_declaration_startup. The$urandomsensitivity test expectsalways @*draws at time zero.Verification
--binary --timing): the C906 block andalways @*give1 ffff 1, the over-complete and incomplete lists give1 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-svwith CI's features (celox/systemverilog,celox/cranelift,celox/wasm-runtime,celox/wasm-component,celox/veryl-reference,celox-test-suite/runtime-cases): 14809 passed.--all-targets -D warnings): clean.retained_reports: passed.verify-sv-icarus/verify-sv-verilatoron thealways_comb,latch,timing,programandsystem_functionsgroups: no mismatches or errors; Icarus ignores the two tagged cases through the new exclusion.conformance/sv-tests/expected.tsv.--backend interpreter --two-state, instructions until "Init Program"): 336.6 G / 339.3 G vs 330.2 G / 329.6 G before.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.