Skip to content

perf(testbench)!: compile Veryl testbenches through the HDL backends - #2445

Closed
tignear wants to merge 1 commit into
masterfrom
stack/tignear/perf/veryl-testbench-execution/compile-resumable-veryl-testbench-processes--2711e90c
Closed

tignear wants to merge 1 commit into
masterfrom
stack/tignear/perf/veryl-testbench-execution/compile-resumable-veryl-testbench-processes--2711e90c

Conversation

@tignear

@tignear tignear commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Lower Veryl testbench expressions and resumable processes into shared SIR before optimization and state layout. Use the SystemVerilog process builder and existing native, interpreter, Cranelift and Wasm backends, so tiered execution promotes DUT and TB kernels together. Remove the separate TB VM, Cranelift compiler, scalar assembler and runtime loop evaluator.

Wide integer operations use normal backend instruction selection. Strings use the shared 32-bit heap handles and floating-point operations use the shared numeric ABI. Keep function-local state, conditional stores, indexed accesses, four-state component payloads, clock/reset ordering, VCD, snapshots and native-image loading. Advance the native-image schema for the compiled kernel metadata.

Avoid redundant settlement requests between consecutive RTL reads, invalidate that fact at writes and control-flow boundaries, and fold constant clock-only loops using shared SIR constant evaluation. Keep output, assertions and component services at suspension boundaries.

Validation: shared crate unit tests; native TB, string, component, completion, floating-point, checkpoint, image, tiered and SV process regressions across enabled backends; CLI tests; compiler-only, WASI and ARM64 code-generation checks; formatting, Clippy and the default-dependency guard. SHA-256, FFT and LZ77 pass both positive and deliberately broken oracle qualification. Rica completes all 16 replays with identical cycle and retirement counts.

Whole-invocation Rica measurements still show a gap to Veryl simulator; this change does not claim that the overall performance target is met. The remaining runtime and DUT code-generation costs are being investigated separately. No large Heliodor workload was run.

BREAKING CHANGE: CompiledExpr no longer evaluates expressions against a raw memory pointer. Compile testbenches with the simulator pipeline and invoke their bound backend kernels; existing native image containers must be rebuilt.

@tignear

tignear commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

This pull request is part of a Mergify stack:

# Pull Request Link
1 perf(testbench)!: compile Veryl testbenches through the HDL backends #2445 👈
2 fix(bench): compare tiered simulators by total completion time #2462
3 fix(trace): include native process kernels in codegen traces #2482
4 perf(testbench)!: compile concurrent Veryl scheduling through SIR #2483

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 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-28T19:45:38.954305Z a26c0a4 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.

@tignear tignear added merge-ready Request merging through Mergify after required checks and removed merge-ready Request merging through Mergify after required checks labels Oct 28, 2026
@tignear
tignear force-pushed the stack/tignear/perf/veryl-testbench-execution/replace-expression-vm-native-code--32c778a1 branch from 54d947d to 7a7a029 Compare October 28, 2026 16:12
@tignear tignear changed the title perf(testbench): compile resumable Veryl testbench processes perf(testbench): compile Veryl testbenches through the HDL backends Oct 28, 2026
@tignear
tignear force-pushed the stack/tignear/perf/veryl-testbench-execution/compile-resumable-veryl-testbench-processes--2711e90c branch from 70b9986 to 5b44073 Compare October 28, 2026 16:12
@tignear

tignear commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Revision history

# Type Changes Reason Date
1 initial 70b9986 2026-10-28 16:12 UTC
2 content 70b9986 → 5b44073 2026-10-28 16:12 UTC
3 rebase 5b44073 → 90ee7b5 (rebase only) 2026-10-28 16:13 UTC
4 content 90ee7b5 → f078fc6 2026-10-28 16:19 UTC
5 rebase f078fc6 → 3982ee7 (rebase only) 2026-10-28 16:35 UTC
6 rebase 3982ee7 → a26c0a4 (rebase only) 2026-10-28 19:32 UTC

@tignear
tignear force-pushed the stack/tignear/perf/veryl-testbench-execution/compile-resumable-veryl-testbench-processes--2711e90c branch from 5b44073 to 90ee7b5 Compare October 28, 2026 16:14
@tignear tignear changed the title perf(testbench): compile Veryl testbenches through the HDL backends perf(testbench)!: compile Veryl testbenches through the HDL backends Oct 28, 2026
@tignear
tignear force-pushed the stack/tignear/perf/veryl-testbench-execution/replace-expression-vm-native-code--32c778a1 branch from 7a7a029 to 44f5ddd Compare October 28, 2026 16:14
@tignear
tignear force-pushed the stack/tignear/perf/veryl-testbench-execution/compile-resumable-veryl-testbench-processes--2711e90c branch from 90ee7b5 to f078fc6 Compare October 28, 2026 16:20

@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: f078fc67f6

ℹ️ 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 +248 to +249
let offset = if let Some(selection) = &dst.selection {
SIROffset::Dynamic(self.expression(&selection.offset)?.register)

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 Settle hardware before evaluating assignment indices

When a selected assignment has a hardware-dependent index but a constant or TB-private RHS, only the RHS goes through settled_expression; the index is evaluated here without settling. In an ordinary combinational design without external observers, a sequence such as updating a DUT input and then assigning values[dut.index] = 1 therefore uses the previous index and writes the wrong element. The previous assignment runner explicitly called settle_testbench whenever dst.selection was present. Preserve that settlement before evaluating the selected target.

Useful? React with 👍 / 👎.

Comment on lines +389 to +392
let valid = self.kernel.builder().new_block();
let invalid = self.kernel.builder().new_block();
self.kernel.builder().seal_block(Term::Branch {
cond: fits,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check for empty wide ranges before rejecting their bounds

For dynamic bounds wider than the induction variable, this validation rejects even ranges that require no iterations. For example, with a 128-bit variable bound = 128'd1 << 100, for _i in bound..bound { ... } now reports a non-progressing loop because the bounds do not fit, although the exclusive range is empty. The previous wide-bound runner returned successfully for start >= end before rejecting unrepresentable nonempty ranges. Determine whether the range is empty before applying the representability failure.

Useful? React with 👍 / 👎.

}
self.kernel.builder().switch_to_block(advance);
let current = self.load(current_slot, width, signed);
let step = self.imm(width, step as u64);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the full shift count when lowering loop steps

For shift-stepped loops, allocating the step at the induction variable's width truncates the shift count before executing the shift. With a 32-bit induction variable, step <<<= 4294967297 becomes a shift by one, so a dynamic loop from 1 to 4 can complete successfully instead of producing zero and reporting non-progress as the previous runner did. Shift counts must retain their full value; only the resulting induction value should be truncated to the loop width.

Useful? React with 👍 / 👎.

@tignear
tignear force-pushed the stack/tignear/perf/veryl-testbench-execution/replace-expression-vm-native-code--32c778a1 branch from 44f5ddd to a3c57be Compare October 28, 2026 16:36
@tignear
tignear force-pushed the stack/tignear/perf/veryl-testbench-execution/compile-resumable-veryl-testbench-processes--2711e90c branch from f078fc6 to 3982ee7 Compare October 28, 2026 16:36

@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: 3982ee734a

ℹ️ 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 +386 to +387
let last_fits = self.bound_fits(last, width, signed, !inclusive);
let fits = self.binary(BinaryOp::And, first_fits, last_fits, 1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Allow early exits before rejecting an out-of-range endpoint

For a dynamic signed endpoint outside the induction variable's range, this check rejects the loop before its body can execute, even when the body safely exits immediately. For example, setting an i64 variable limit to 64'sd2147483649 and executing for i in 0..limit { $assert(i == 0); break; } previously succeeded but now reports a non-progressing loop. An unrepresentable endpoint does not imply non-progress when break or $finish prevents reaching it; preserve those early exits and diagnose overflow when advancement actually fails.

Useful? React with 👍 / 👎.

@mergify

mergify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

Base automatically changed from stack/tignear/perf/veryl-testbench-execution/replace-expression-vm-native-code--32c778a1 to master October 28, 2026 18:01
Lower Veryl testbench expressions and resumable processes into shared SIR before optimization and state layout. Use the SystemVerilog process builder and existing native, interpreter, Cranelift and Wasm backends, so tiered execution promotes DUT and TB kernels together. Remove the separate TB VM, Cranelift compiler, scalar assembler and runtime loop evaluator.

Wide integer operations use normal backend instruction selection. Strings use the shared 32-bit heap handles and floating-point operations use the shared numeric ABI. Keep function-local state, conditional stores, indexed accesses, four-state component payloads, clock/reset ordering, VCD, snapshots and native-image loading. Advance the native-image schema for the compiled kernel metadata.

Avoid redundant settlement requests between consecutive RTL reads, invalidate that fact at writes and control-flow boundaries, and fold constant clock-only loops using shared SIR constant evaluation. Keep output, assertions and component services at suspension boundaries.

Validation: shared crate unit tests; native TB, string, component, completion, floating-point, checkpoint, image, tiered and SV process regressions across enabled backends; CLI tests; compiler-only, WASI and ARM64 code-generation checks; formatting, Clippy and the default-dependency guard. SHA-256, FFT and LZ77 pass both positive and deliberately broken oracle qualification. Rica completes all 16 replays with identical cycle and retirement counts.

Whole-invocation Rica measurements still show a gap to Veryl simulator; this change does not claim that the overall performance target is met. The remaining runtime and DUT code-generation costs are being investigated separately. No large Heliodor workload was run.

BREAKING CHANGE: CompiledExpr no longer evaluates expressions against a raw memory pointer. Compile testbenches with the simulator pipeline and invoke their bound backend kernels; existing native image containers must be rebuilt.

Change-Id: I2711e90cfd86ec662d5078e674ae9718576eaf54
@tignear
tignear force-pushed the stack/tignear/perf/veryl-testbench-execution/compile-resumable-veryl-testbench-processes--2711e90c branch from 3982ee7 to a26c0a4 Compare October 28, 2026 19:33
@tignear tignear added the release:hold Prevent the release pull request from merging label Oct 28, 2026

@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: a26c0a41f6

ℹ️ 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 +254 to +258
self.kernel.builder().emit(Inst::Store(
stable(dst.signal.address),
offset,
dst.width,
value,

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 Bound selected assignments before emitting a memory store

When a testbench assignment uses an out-of-range runtime index, this unconditional store writes beyond the destination object instead of ignoring the assignment. The frontend's resolve_target_parts constructs an offset without a bounds check, and the native backend lowers dynamic stores to register-indexed memory accesses without adding one. For example, assigning bits[index] = 1 with an index beyond bits can corrupt another state object or crash the simulator. Previously, sim_set_target clipped the selected width to the remaining destination width and returned without writing when the offset was outside the object. Preserve that bounds handling, including clipping partially overlapping selections, before emitting this store.

Useful? React with 👍 / 👎.

Comment on lines +409 to +410
let one = self.imm(lw, 1u8);
self.binary(BinaryOp::Sub, last, one, lw)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Widen reverse-loop endpoints before subtracting one

When a dynamic endpoint is narrower than the induction variable, subtracting at lw bits wraps before the result is converted to the counter width. For example, an unsigned 8-bit endpoint containing zero makes for i in rev 0..end start at 255 instead of skipping the empty range: the subtraction produces 8'hff, and binary marks that result unsigned, so the subsequent cast zero-extends it to the 32-bit counter. The previous runner performed the subtraction in its host-width counter representation and started at -1 for this mixed static/dynamic range. Widen the endpoint into the counter's arithmetic representation before decrementing it.

Useful? React with 👍 / 👎.

tignear added a commit that referenced this pull request Oct 28, 2026
Land the Veryl testbench execution stack as one queue entry; its members are
not merged into master individually.

Lower Veryl testbench expressions and resumable processes into shared SIR
before optimization and state layout, and run them through the native,
interpreter, Cranelift and Wasm backends, so tiered execution promotes DUT
and TB kernels together. The separate TB VM, Cranelift compiler, scalar
assembler and runtime loop evaluator are removed. Concurrent TB continuation
dispatch, clock waits and multi-clock time progression are generated as
ordinary SIR composed with the shared compiled clock-domain scheduler, so
process arithmetic, settlement and eligible clock slots execute together
between host services and tiering safe points. The shared scheduler no longer
invalidates clean combinational state for unchanged clocks and internal
clock-alias notifications.

Native SIR/MIR traces now include process entries, including compiled
testbench and scheduler code. Tiered circuit and Heliodor comparisons publish
only total workload time; startup and execution intervals stay in diagnostic
reports.

The tree is identical to #2483 at the SHA below. The source PRs are held with
release:hold while this rollup is active. Their changes are squashed here;
they close automatically when this PR lands on master. If a source head
changes, rebuild the rollup before queueing it. Removing this rollup requires
releasing those holds before resuming individual stack merges.

Source PRs and pinned heads:
- #2445: a26c0a4 — perf(testbench)!: compile Veryl testbenches through the HDL backends
- #2462: 544ca13 — fix(bench): compare tiered simulators by total completion time
- #2482: 7a0ee19 — fix(trace): include native process kernels in codegen traces
- #2483: 387fb86 — perf(testbench)!: compile concurrent Veryl scheduling through SIR

Validation (from the source PRs, same tree as #2483):
- 281 Celox library tests; 98 native TB tests (1 existing ignored); 9 native MIR tests including a native testbench process trace; 8 native image tests; 5 completion tests; 8 slot-observer tests; 6 tiered tests.
- 81 runtime and 28 testbench library tests; affected-crate all-target Clippy with systemverilog, cranelift, veryl-reference and wasm-runtime; compiler-only, WASI and ARM64 code-generation checks; formatting and the default-dependency guard.
- SHA-256, FFT and LZ77 pass both positive and deliberately broken oracle qualification. Rica completes all 16 replays with identical cycle and retirement counts.
- Benchmark publication and runner tests, Heliodor conversion fixtures, and the VitePress production build.

Performance status: no end-to-end speedup over Veryl simulator has been
established; this rollup makes no performance claim. No large Heliodor
workload was run.

BREAKING CHANGE: CompiledExpr no longer evaluates expressions against a raw
memory pointer; compile testbenches with the simulator pipeline and invoke
their bound backend kernels. Serialized testbench metadata gains scheduler
state, and appended native images use container version 55 and must be
regenerated.

Change-Id: If61ef7bfc9c47ddc0c3bf3e81cf6bdbce4d62a28
@tignear

tignear commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Landed on master as part of the rollup #2484.

@tignear tignear closed this Oct 29, 2026
@tignear
tignear deleted the stack/tignear/perf/veryl-testbench-execution/compile-resumable-veryl-testbench-processes--2711e90c branch November 8, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:hold Prevent the release pull request from merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant