Repository navigation
perf(sv): fold zero-argument functions whose kept result is never read - #2704
Merged
Merged
Conversation
Taxi's LFSR builds its 122x122-bit mask in `wire mask = lfsr_mask();`, a static zero-argument function that assigns its result bit by bit. The analyzer cannot prove that every call assigns all of it, so the result stays static storage kept between calls (IEEE 1800-2023 13.4.2). That excluded the function from the evaluate-once constant path, and the call made its process count as reading simulation state. The function body was then generated as runtime logic of 1.8M machine instructions, which spent most of the compile in register allocation. Without arguments and without any read of that result, every call performs the same assignments, so the bits no call assigns keep their initial value and each call returns what the first does. Accept such functions for constant evaluation, and do not treat a call that lowers to its constant as reading state. A read of the result, including through an assignment target index, keeps the call. Single-CPU `celox vpi build`: lfsr64 125 s -> 18 s with a peak RSS of 1.7 GiB -> 243 MiB, and phy64 281 s -> 50 s with 2.1 GiB -> 288 MiB. The Taxi cocotb tests of both configurations pass with the same simulated durations as Verilator. Change-Id: I740502a83e35de07efdaf2e88e8dcd12ccee6cd4
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. |
Contributor
✅ Merged into
|
This was referenced Oct 31, 2026
Merged
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Taxi's LFSR builds its 122x122-bit mask in
wire mask = lfsr_mask();, a static zero-argument function that assigns its result bit by bit (lfsr_mask[i][j] = ...withREVERSE=1). The analyzer cannot prove that every call assigns all of the result, so it stays static storage kept between calls (IEEE 1800-2023 13.4.2). Two things followed:RuntimeConstantFunctionsrejected the function because it has persistent storage, so the call was not evaluated once as a constant.ProcModule::reads_simulation_statecounted the call as reading state, so the continuous assignment went through the FF lowering path and the function body became runtime logic: 11k comb blocks and 1.8M MIR instructions, with most of the compile spent in register allocation and spill planning.Without arguments, and without any read of that result, every call performs the same assignments. The bits no call assigns keep their initial value (0 in two-state, X in four-state), so each call returns what the first does. This PR accepts such functions for constant evaluation and stops treating a call that lowers to its constant as reading state. A read of the result, including through the index of an assignment target, keeps the call.
Effect (
celox vpi build, one pinned CPU, heliodor-dev build)The latest published CI values are 171 s (lfsr64) and 342 s (phy64) for Celox, against 24 s and 42 s for Verilator. The companion PR that parses wide literals in linear time brings these further down to 10 s and 24 s.
Validation
celox-sv-analyzerlib tests (933) andcelox-frontend-svlib tests (11) pass. New tests: a partially assigned static result folds to its initial-value bits in both state modes, and results read directly or through an assignment-target index stay calls. The frontend runtime-loop test gains a variant whose result keeps bits between calls.procedural::static_function_unread_partial_result_{is_constant,keeps_unknown_bits}: pass on every Celox backend. Verilator passes the two-state case and reports the four-state case as unsupported (expected). Icarus passes both.systemverilogvtest filterprocedural:: | operators:: | constant_function | static_function: 688 passed.run-taxi-bench.py run {lfsr64,phy64} --samples 1: all tests pass, with simulated durations equal to Verilator's and no change in test-body time.