Repository navigation
perf(sv): evaluate stateless constant functions once - #2235
Conversation
|
This pull request is part of a Mergify stack:
|
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: 4058575a67
ℹ️ 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".
| if args.is_empty() | ||
| && let Some(literal) = self.m.constant_functions.value(name) |
There was a problem hiding this comment.
Preserve four-state case matching when folding runtime calls
In four-state mode, a zero-argument function containing an ordinary case can now be replaced with the wrong constant. For example, function automatic int f(); logic x; case (x) 1'bx: return 1; default: return 0; endcase endfunction should return 1, but the reused interpreter compares case labels with BinaryOp::Eq in Frame::stmt, then treats the unknown comparison as false, producing 0. Ordinary runtime lowering correctly uses BinaryOp::EqCase for CaseKind::Exact in Comb::case. Use the same case-equality semantics in the interpreter, or decline this optimization for unknown-sensitive case comparisons.
Useful? React with 👍 / 👎.
| constants: self.constants, | ||
| functions: &self.state, | ||
| }; | ||
| let value = call_value(name, &[], &env).map(Value::into_literal); |
There was a problem hiding this comment.
Preserve ternary result types before folding runtime calls
In either state mode, this newly enabled interpreter path can change a ternary expression's signedness because Frame::lower replaces a known-condition mux with its selected arm before determining the combined expression type. For example, function automatic int f(); return 1'b1 ? 8'shff : 8'h00; endfunction must return 255: the unsigned alternative makes the ternary unsigned. The interpreter instead keeps only signed 8'shff, sign-extends it to the return width, and caches -1. Preserve the width and signedness contributed by both arms when selecting a constant branch, or leave these calls to ordinary runtime lowering.
Useful? React with 👍 / 👎.
1ee9abc to
cbca758
Compare
4058575 to
62e7a5f
Compare
Revision history
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 62e7a5fc23
ℹ️ 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".
| if args.is_empty() | ||
| && let Some(literal) = self.m.constant_functions.value(name) |
There was a problem hiding this comment.
Apply case-wide type normalization before folding calls
In either state mode, the newly reused interpreter compares each case label independently instead of using the common width and signedness of the selector and all labels. For example, an automatic function containing logic signed [7:0] x = 8'hff; case (x) 16'shffff: return 1; 16'h0000: return 2; default: return 0; endcase is folded to 1, although it should return 0: the unsigned second label makes every comparison unsigned, so the selector must zero-extend to 16'h00ff. Ordinary runtime lowering already implements this normalization in Comb::case_conditions. Apply that normalization in the interpreter too, or decline folding these cases.
Useful? React with 👍 / 👎.
| constants: self.constants, | ||
| functions: &self.state, | ||
| }; | ||
| let value = call_value(name, &[], &env).map(Value::into_literal); |
There was a problem hiding this comment.
Preserve unknown results of inside expressions
In four-state mode, this evaluation path incorrectly folds unknown-valued inside expressions to zero. For example, function automatic logic f(); logic x; return x inside {1'b1}; endfunction should return X, but Frame::lower handles Expr::Inside by passing each comparison through self.truth, which converts X to false, and then creates a known Boolean literal. Ordinary runtime lowering instead retains the four-state wildcard comparisons through inside_as_comparisons. Preserve the unknown result when combining membership comparisons, or leave such functions to runtime lowering.
Useful? React with 👍 / 👎.
cbca758 to
a3a7832
Compare
62e7a5f to
e6d188b
Compare
|
Queued — the merge queue status continues in this comment ↓. |
e6d188b to
7388b67
Compare
Zero-argument functions that construct constant masks with unpacked scratch arrays were lowered into runtime loops and wide dynamic shifts. Reuse the bounded constant interpreter and cache each result after excluding persistent state, global writes, simulation-state reads and effectful or missing callees. Preserve the runtime state mode and fall back when evaluation is unsupported or exceeds the shared budget. Use all case labels to determine the comparison width and signedness before evaluating the selector once and labels in source order (IEEE 1800-2023 12.5). Propagate that context into arithmetic, retain fill-literal sizing and compare X/Z exactly. Preserve unknown inside results when combining wildcard comparisons and ranges (11.4.13), and initialize four-state constant-function locals and returns to X. Keep the added case and membership work off the recursive interpreter frame so the existing recursion guard works on the default stack. Regressions cover both runtime state modes, later unsigned/wider labels, context-sized arithmetic, skipped labels, exact X/Z cases, unknown membership, ranges and partially assigned returns. The existing 8100-bit mask/cache and frontend instruction-bound regressions continue to pass. Shared case tests use explicit automatic-local assignments because Icarus 13.0 aborts on their declaration initializers; analyzer regressions retain the original form. Validated on master 4616658: 858 analyzer and 11 frontend unit tests, 5964 SystemVerilog integration tests across the compiled backend variants, 54 suite tests, affected-crate clippy and formatting. Existing ignored tests remain unchanged. Wide-mask cache reuse and frontend instruction-bound tests continue to pass in both state modes. Icarus evidence for the unchanged shared cases is two passes; Verilator passes the two-state case and reports its existing four-state capability limit for the other. No exclusions or retained verification baselines were changed. Change-Id: I268b61b85e35aef99179cb8ca5e7139d787c1924
7388b67 to
445fb1f
Compare
✅ Merged into
|
| Condition | Required by | |
|---|---|---|
| ✅ | check-success = Conventional Commit title |
— |
| ✅ | check-success = Queue validation |
— |
| ✅ | any of: check-success = @github-actions/Lint & Format, check-neutral = @github-actions/Lint & Format, check-skipped = @github-actions/Lint & Format |
GitHub repository ruleset rule master |
| ✅ | any of: check-success = @github-actions/Rust Test & NAPI Build, check-neutral = @github-actions/Rust Test & NAPI Build, check-skipped = @github-actions/Rust Test & NAPI Build |
GitHub repository ruleset rule master |
| ✅ | any of: check-success = @github-actions/JS Test (Ubuntu), check-neutral = @github-actions/JS Test (Ubuntu), check-skipped = @github-actions/JS Test (Ubuntu) |
GitHub repository ruleset rule master |
| ✅ | any of: check-success = @github-actions/Conventional Commit title, check-neutral = @github-actions/Conventional Commit title, check-skipped = @github-actions/Conventional Commit title |
GitHub repository ruleset rule master |
| ✅ | any of: check-success = @github-actions/Queue validation, check-neutral = @github-actions/Queue validation, check-skipped = @github-actions/Queue validation |
GitHub repository ruleset rule master |
Times in UTC · dashboard · how the merge queue works
Zero-argument functions that construct constant masks with unpacked scratch arrays
were lowered into runtime loops and wide dynamic shifts. Reuse the bounded
constant interpreter and cache each result after excluding persistent state,
global writes, simulation-state reads and effectful or missing callees. Preserve
the runtime state mode and fall back when evaluation is unsupported or exceeds
the shared budget.
Use all case labels to determine the comparison width and signedness before
evaluating the selector once and labels in source order (IEEE 1800-2023 12.5).
Propagate that context into arithmetic, retain fill-literal sizing and compare
X/Z exactly. Preserve unknown inside results when combining wildcard comparisons
and ranges (11.4.13), and initialize four-state constant-function locals and
returns to X. Keep the added case and membership work off the recursive
interpreter frame so the existing recursion guard works on the default stack.
Regressions cover both runtime state modes, later unsigned/wider labels,
context-sized arithmetic, skipped labels, exact X/Z cases, unknown membership,
ranges and partially assigned returns. The existing 8100-bit mask/cache and
frontend instruction-bound regressions continue to pass. Shared case tests use
explicit automatic-local assignments because Icarus 13.0 aborts on their
declaration initializers; analyzer regressions retain the original form.
Validated on master 4616658: 858 analyzer and 11 frontend unit tests,
5964 SystemVerilog integration tests across the compiled backend variants,
54 suite tests, affected-crate clippy and formatting. Existing ignored tests
remain unchanged. Wide-mask cache reuse and frontend instruction-bound tests
continue to pass in both state modes. Icarus evidence for the unchanged shared
cases is two passes; Verilator passes the two-state case and reports its
existing four-state capability limit for the other. No exclusions or retained
verification baselines were changed.