Repository navigation
perf(sv): fold constants without big-integer parsing or needless copies - #2066
Merged
Merged
Conversation
Constant folding passes values through literal strings: typed constants are substituted as sized literals and every literal is parsed again with big-integer arithmetic. On rtlmeter C906, evaluating constant expressions took about a tenth of the frontend. Literals of plain digits whose value fits in 128 bits, the form constant substitution writes, are now parsed with machine integers; other literals keep the general parser. Evaluating with types copies and substitutes the expression only when it names a typed constant, since substitution changes nothing else. Refs #1993 Change-Id: Ia0b236b14e15e4077bba958ce05f230504f70ab3
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
Merge Queue Status
This pull request spent 33 minutes 37 seconds in the queue, including 31 minutes 54 seconds running CI. Required conditions to merge
|
40 of 71 tasks
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.
What
Constant folding passes values through literal strings (#1993):
eval_const_expr_with_typesclones the expression and substitutes each typed constant as a sized literal (32'sd5), and the evaluator parses every literal again withBigUintarithmetic (str::replace, radix conversion, shifts and masks).parse_integral_literalfirst triesparse_small_literal: unsized decimals and sized'b/'o/'d/'hliterals (optionally signed) of plain digits, without_, x/z or whitespace, whose value fits inu128, parsed with machine integers. Everything else, and anything that does not fit, goes to the unchanged general parser.eval_const_expr_with_typesevaluates the expression in place unless it names a typed constant (has_typed_constant), the only nodes substitution replaces.Results are identical; the generated SIR is unchanged (frontend-only).
Refs #1993 (first step; the evaluator still round-trips through literal strings for typed constants).
Why
On rtlmeter C906 the typecheck evaluator (
eval_const_expr_with_types) was about 8-10% of the run up to the first testbench output, mostly literal parsing and copies. User-mode instructions to the first testbench output (C906,--backend interpreter --two-state, integration base + #2043): 327.4 G → 309.4 G (−5.5%) with the literal fast path alone; deterministic across repeats.Validation
typecheck::literal_tests::small_literals_parse_like_any_literal: 20 000 generated literals (all bases and cases, signed and unsigned, sizes 0..200, leading zeros, values beyond 128 bits, and x/z/_digits that must fall back) compared with the general parser; over 5 000 take the fast path. Dropping the 32-bit minimum width of unsized decimals makes it fail.typecheck::literal_tests::typed_evaluation_substitutes_only_typed_constants: expressions without typed constants evaluate as their substituted copies; a typed 8-bit constant still wraps in its width.cargo fmt --all -- --check,cargo clippy -p celox-sv-analyzer --all-targets -- -D warnings: clean.cargo nextest run -p celox -p celox-sv-analyzer -p celox-frontend-sv -p celox-test-suite --features celox/systemverilog,celox/cranelift,celox/wasm-runtime,celox/wasm-component,celox/veryl-reference,celox-test-suite/runtime-cases: 15608 passed, 316 skipped.