Skip to content

perf(runtime)!: run batches of derived clock periods in one generated unit - #1984

Closed
tignear wants to merge 1 commit into
masterfrom
feature/derived-edge-sir-c
Closed

tignear wants to merge 1 commit into
masterfrom
feature/derived-edge-sir-c

Conversation

@tignear

@tignear tignear commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1123, step 3b-2: #1786 PR C (batched clk.next(n) on derived clock events), after #1844 and #1888. Rebased on master as of #2710.

Periods of an event with derived clock domains that the host runs ran each period as two host edges, each a call of a generated edge unit (#1888), while a plain clock's periods run in one call of its fused tick loop. They now run in one call too: a period of a gated or divided clock costs about half of what it did on that path.

Where the batching applies now

Since #2484, a compiled Veryl testbench runs clk.next(n) and rst.assert in the generated testbench scheduler, which runs derived domains itself (#1967) and reaches neither clock_periods nor the derived-edge units. The batches of this PR apply where the host still runs the periods: testbench::clock_periods, reached when the testbench has no generated scheduler entry, e.g. SchedulerMode::Reference. The single-edge part of the unit serves Simulator::edge / tick (Rust API, NAPI), as #1888's units did.

BREAKING CHANGE

  • celox_design::DerivedEdgeUnits (public) has one unit instead of rising and falling, and DERIVED_EDGE_RISING, DERIVED_EDGE_FALLING and DERIVED_EDGE_MOVED are new.
  • SimBackend (public) has a new method, run_process_many, with a default that runs the unit once.
  • Native images use container format 57.

What changes

  • One unit per event. It runs the edges its mode selects (SchedulerSlots::cont): the rising, the falling, or both, a period, in that order. Each edge is perf(runtime)!: run the derived clock edges of ticks in generated units #1888's edge code. Master's deferred expansion (DeferredEdge, now one per event, with size estimates for both edges) and the outlined combinational settle (outline_comb, four comb copies per unit replaced by calls) apply to it as they did to the rising and falling units.
  • Single edges. Simulator::edge moves the signal through the host watch, judges whether logic reading it must settle (clock_move_needs_settle, which may evaluate the clock's aliases instead) and puts that in the flag, and passes its edge with DERIVED_EDGE_MOVED; comb observers and the host slot end (end_host_slot) as before.
  • Periods. A batch passes a period and lets the unit move the signal, skipping an edge whose level the signal already has, as move_signal does; logic reading the signal then settles first. Only without a host watch, per-slot host work (deferred assertions, sampled values) or comb observers, since each edge is a time slot the host ends; otherwise the periods run as edges.
  • State of combinational logic. The unit reads and writes the scheduler's dirty flag as the host keeps dirty across edges: an edge settles first when it is set (or logic reads a signal the unit moved), an edge that ran domains leaves logic settled, one that ran nothing leaves the flag as it found it.
  • Loop. The x86 and arm64 backends compile the unit in the tick loop that eval_comb_apply_ff uses (celox_backend_common::loops_ticks, label derived_edge), which runs up to n periods and returns after one that records a runtime event; SimBackend::run_process_many reports how many ran. A single native process run sets the count to one, so a count left by a batch that returned early cannot make a unit run several times. The Cranelift, interpreter and wasm backends run one period per call.

Validation

  • derived_edge tests: periods_run_in_generated_units_as_the_plan_walk (batches of 1–7 periods against the plan walk, with host writes of the enable and single rising edges in between, on the gated, inverted, divided, divided-with-a-host-enable, commit-raised-enable and independent designs; at least one batch must run several periods in one call), periods_return_after_a_runtime_event, deferred_assertions_of_derived_domains_mature (ticks, edges and periods, native and Cranelift, failing at the walk's period), single_edges_after_a_batch_returned_early_run_once, perf(runtime)!: run the derived clock edges of ticks in generated units #1888's tests and master's an_edge_reaching_60_gated_domains_runs_as_the_plan_walk: pass.
  • deferred_edges_preserve_expanded_ir_and_reserve_only_small_entries (master) now also runs batches of 3 periods on the deferred and the outlined-comb images and compares them; the outlined image runs each batch in one call (checked locally).
  • Full suite: cargo nextest run -p celox -p celox-frontend-veryl --features celox/systemverilog,celox/cranelift,celox/wasm-runtime,celox/wasm-component,celox/veryl-reference: 17896 passed. celox-runtime, celox-design, celox-backend-common, -x86, -arm64: 811 passed.
  • clippy --all-targets -D warnings (celox, celox-frontend-veryl, celox-runtime, celox-design, the backends, celox-napi; CI features), cargo fmt --check: clean.

Perf

A Veryl testbench running clk.next(n) on 64 registers clocked by clk (plain: no derived clocks in the design), clk & en (gated) or a divider of clk (divided); local probe, not committed. callgrind, Ir per period = (Ir at 20,000 periods − Ir at 2,000) / 18,000, median over 3×3 runs, release, native backend, on master aac2423c73 and this PR.

Host-run periods (SchedulerMode::Reference), where the batches apply:

design master this PR change
plain 221.2 225.7 same (run spread 215–228)
gated clk & en 2,280.6 1,151.8 −49.5%
divided 2,168.7 1,045.6 −51.8%

Default (generated testbench scheduler), which does not run the units:

design master this PR
plain 930.8 932.6 (same, spread ±6)
gated 1,740.2 1,755.3 (spreads 1,726–1,744 / 1,741–1,760)
divided 1,694.3 1,687.1
  • Build cost: designs with derived clocks +7.7M to +9.7M Ir in total at 2,000 periods (+1.1–1.3%), the tick loop's frame and registers in the unit; plain designs: same (348.9M vs 348.8M).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-31T15:32:38.885529Z 74104e4 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: 5e2e6802c4

ℹ️ 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 thread crates/celox/src/simulator.rs Resolved
Comment thread crates/celox/src/simulator.rs Resolved
@mergify

mergify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

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

@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 25, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 25, 2026
@mergify

mergify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue

20 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Sun 25 Oct, 11:04 · rule changes · triggered by rule Queue explicitly requested merges
  • 🚫 Left the queue 11:24 · 6973dba

Reason

Pull request #1984 has been dequeued

Queue conditions are not satisfied:

  • -conflict

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

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

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added dequeued Mergify stopped this queue entry; investigate before retrying and removed queued Mergify queue entry labels Oct 25, 2026
@tignear
tignear force-pushed the feature/derived-edge-sir-c branch from 6973dba to e995f10 Compare October 31, 2026 11:55
@tignear tignear removed the merge-ready Request merging through Mergify after required checks label Oct 31, 2026
@mergify mergify Bot removed the dequeued Mergify stopped this queue entry; investigate before retrying label Oct 31, 2026
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 31, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 31, 2026
@mergify

mergify Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

❌ Left the queue · Lint & Format failed

18 min in the queue, 8 min of it CI.

So far

Not proven to be this pull request's failure. It failed in a batch with #2084, on top of the pull requests ahead of it, and was not tested alone.

Reason

The merge conditions cannot be satisfied due to failing checks

  • Lint & Format

Failing checks:

To get back in the queue

  • Push a fix: the pull request is queued again once its queue conditions match.
  • If the failure is a flake, comment @mergifyio queue to queue it again as it is.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added dequeued Mergify stopped this queue entry; investigate before retrying and removed queued Mergify queue entry labels Oct 31, 2026
@tignear tignear removed the merge-ready Request merging through Mergify after required checks label Oct 31, 2026
@tignear
tignear force-pushed the feature/derived-edge-sir-c branch from e995f10 to 750f605 Compare October 31, 2026 14:19
@mergify mergify Bot removed the dequeued Mergify stopped this queue entry; investigate before retrying label Oct 31, 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: 750f605d59

ℹ️ 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".

… unit

Periods of an event with derived clock domains that a host runs, as a
Veryl testbench's `clk.next(n)` does where the generated testbench
scheduler does not (`SchedulerMode::Reference`), ran every period as two
host edges, each a call of a generated edge unit (#1888), while a plain
clock's periods run in one call of its fused tick loop.

Each event now has one generated unit that runs the edges its mode
selects, the rising, the falling or both, a period, in that order. A
single edge of `Simulator::edge` passes its edge with the host having
moved the signal and judged whether logic reading it must settle, as
before; a batch of periods lets the unit move the signal, and the native
backends compile the unit in the tick loop, which runs up to n periods
and returns after one that records a runtime event
(`SimBackend::run_process_many`; other backends run one period per call).
The unit keeps whether combinational logic has pending changes in the
scheduler's dirty flag across its edges and periods, as the host does
across edges. Hosts with per-slot work (deferred assertions, sampled
values), comb observers or a host watch run edges instead. A single
native process run sets the tick loop's count to one, so a count left by
a batch that returned early cannot make a unit run several times. One
unit per event replaces the rising and falling ones; deferred expansion
and the outlined combinational settle apply to it as to them.

BREAKING CHANGE: celox_design::DerivedEdgeUnits has one `unit` instead of
`rising` and `falling`; SimBackend has a new method, run_process_many, with
a default. Native images use container format 57.

Change-Id: I3f9f794d224c59eae9b5036a5ca57c342ccba653
@tignear
tignear force-pushed the feature/derived-edge-sir-c branch from 750f605 to 74104e4 Compare October 31, 2026 15:30
@tignear tignear closed this Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant