Skip to content

perf(sv): evaluate stateless constant functions once - #2235

Merged
mergify[bot] merged 1 commit into
masterfrom
stack/tignear/perf/taxi-memory-runtime/evaluate-stateless-constant-funcs-once--268b61b8
Oct 27, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
stack/tignear/perf/taxi-memory-runtime/evaluate-stateless-constant-funcs-once--268b61b8

Conversation

@tignear

@tignear tignear commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

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.

@tignear

tignear commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

This pull request is part of a Mergify stack:

# Pull Request Link
1 refactor(native): support state-aware outlined kernel calls #2231
2 perf(native): share large comb kernels and bound compilation memory #2232
3 fix(vpi): expose interface parameters and lexical generate scopes #2233
4 perf(settle): bound estimated partitions and preserve sparse updates #2234
5 perf(sv): evaluate stateless constant functions once #2235 👈

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T13:14:32.971300Z 445fb1f New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +3237 to +3238
if args.is_empty()
&& let Some(literal) = self.m.constant_functions.value(name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@tignear
tignear force-pushed the stack/tignear/perf/taxi-memory-runtime/bound-estimated-partitions-preserve-sparse-updates--9e4342b5 branch from 1ee9abc to cbca758 Compare October 27, 2026 06:19
@tignear
tignear force-pushed the stack/tignear/perf/taxi-memory-runtime/evaluate-stateless-constant-funcs-once--268b61b8 branch from 4058575 to 62e7a5f Compare October 27, 2026 06:19
@tignear

tignear commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Revision history

# Type Changes Reason Date
1 initial 4058575 2026-10-27 06:18 UTC
2 rebase 4058575 → 62e7a5f (rebase only) Refresh validation after the generated-kernel arena review fix: all623 x86 units,239 native library tests,41 APIs and3511 affected native shared executions pass. No source changes in this top member. 2026-10-27 06:18 UTC
3 rebase 62e7a5f → e6d188b (rebase only) Replay after #2233 CI fix and master sync. Final stack passes 848 analyzer units, frontend units, the exact full-feature CI regression and no-host SV checking; lower #2233 also passes 372 class integ… 2026-10-27 09:51 UTC
4 content e6d188b → 7388b67 Fix review 5663030403 after syncing merged #2231-#2234: normalize case-wide types, preserve membership X, and verify constant/local initialization and default-stack recursion. 2026-10-27 12:27 UTC
5 content 7388b67 → 445fb1f Keep both appended operator suites when rebasing onto master4616658b13; analyzer858, frontend11, SV5964 and suite54 tests pass, with clippy and fmt. 2026-10-27 13:11 UTC

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +3237 to +3238
if args.is_empty()
&& let Some(literal) = self.m.constant_functions.value(name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@tignear
tignear force-pushed the stack/tignear/perf/taxi-memory-runtime/bound-estimated-partitions-preserve-sparse-updates--9e4342b5 branch from cbca758 to a3a7832 Compare October 27, 2026 09:52
@tignear
tignear force-pushed the stack/tignear/perf/taxi-memory-runtime/evaluate-stateless-constant-funcs-once--268b61b8 branch from 62e7a5f to e6d188b Compare October 27, 2026 09:52
@mergify

mergify Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

Base automatically changed from stack/tignear/perf/taxi-memory-runtime/bound-estimated-partitions-preserve-sparse-updates--9e4342b5 to master October 27, 2026 12:08
@tignear
tignear force-pushed the stack/tignear/perf/taxi-memory-runtime/evaluate-stateless-constant-funcs-once--268b61b8 branch from e6d188b to 7388b67 Compare October 27, 2026 12:28
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
@tignear
tignear force-pushed the stack/tignear/perf/taxi-memory-runtime/evaluate-stateless-constant-funcs-once--268b61b8 branch from 7388b67 to 445fb1f Compare October 27, 2026 13:11
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 27, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 27, 2026
@mergify

mergify Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into master as a510d16 at 13:46 UTC

Merged together with #2180. 10 min in the queue, 8 min of it CI.

So far

Merge conditions: 7 of 7 met

The batch, tested on draft #2281

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

@mergify
mergify Bot merged commit a510d16 into master Oct 27, 2026
25 checks passed
@mergify
mergify Bot deleted the stack/tignear/perf/taxi-memory-runtime/evaluate-stateless-constant-funcs-once--268b61b8 branch October 27, 2026 13:46
@mergify mergify Bot removed the queued Mergify queue entry label Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-ready Request merging through Mergify after required checks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant