Repository navigation
perf(sv): publish only the written elements of an array another process writes - #2024
Conversation
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. |
There was a problem hiding this comment.
💡 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".
| out.push(record( | ||
| &site.lsb_name, | ||
| expr_from_const_expr(lsb).expect("a staged site's bounds are expressions"), | ||
| )); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 👍 / 👎.
Merge Queue Status
This pull request spent 5 minutes 21 seconds in the queue, with no time running CI. ReasonThe pull request #2024 has been manually updated Waiting for
All conditions
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
764aee7 to
6db33ad
Compare
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
|
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 bymem[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:
stage_nonblockingalso records, per write site, the bit range the write covers (itslsbandmsb) and that it ran, in hidden variables.emit_array_site_merge) publishes the elements the range covers and clears their mask bits.Why the values stay the same:
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
hierarchical_referencescasenonblocking_element_writes_keep_hierarchical_writes_of_the_same_step. It uses a descendingmem [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.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.celox/{systemverilog,cranelift,wasm-runtime,wasm-component,veryl-reference},celox-test-suite/{verilator,icarus,xezim,runtime-cases}) overcelox,celox-frontend-svandcelox-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 91hierarchical_referencestests.--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