Skip to content

perf(runtime)!: run the derived clock edges of ticks in generated units - #1888

Merged
mergify[bot] merged 1 commit into
masterfrom
feature/derived-edge-sir-b
Oct 24, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
feature/derived-edge-sir-b

Conversation

@tignear

@tignear tignear commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1123, step 3b-2: #1786 (derived clock domains), PR B of four (A → B → D → C). Stacked on #1844 (review the last commit).

Simulator::tick (and edge, posedge, negedge) of an event with derived clock domains now runs each edge as one generated unit instead of walking DerivedTickPlan in Rust: on the overhead bench's designs (1,000 registers on clk), a tick of the gated clock drops by 16–19% and of the divided clock by 10–11% in Ir. Plain clocks run exactly today's code. The units cost build time (+15% to +30% on these designs, see Build cost); they are on by default and -sir:derived_edge_units turns them off.

BREAKING CHANGE

  • celox_design::RuntimeSchema (public) has a new field, derived_edges, and DerivedEdgeUnits is new.
  • SirPass (public) has a new variant, DerivedEdgeUnits.
  • Native images use container format 34; images written by earlier versions must be rebuilt.

What changes

  • Generation. At build, every event whose plan the derived-edge generator of refactor(runtime): generate the edges of derived clock domains as SIR #1844 emits (two-state, gated clocks with gate programs) gets two process units, its rising and its falling edge, recorded in RuntimeSchema::derived_edges. Whether the event's own domain fires is fixed per edge direction; an edge that never fires it leaves its units out. Designs without such a plan generate nothing.
  • The tick path. Simulator::edge moves the signal as before (through the host watch), sets the scheduler's dirty flag to say whether combinational logic must settle first (dirty || comb_read, as run_edge passes settle), and runs the unit of the edge. feat(sim)!: make a tick one clock period and run every clock generator #1776's tick definition and perf(sim): keep the inactive edge of a tick cheap when nothing can fire on it #1789's quiet inactive edge are unchanged: a tick whose inactive edge runs nothing still only stores the level.
  • Kept on the walk: coincident edges (edges, tick_events), fire's plan tick, four-state designs, gates without programs, a timed simulation with $finish sites (the walk stops after the unit that emits one), designs with comb observers or fatal comb assertions.
  • Generator layout. Each domain's units now appear once per path they can take: the independent gated domains reuse the one-domain path one at a time, and only domains that can fire with another get the several-domain path. Inlining a 1,000-register domain four times made the native code ~30% slower per register than the domain's own function; once, it costs the same.
  • Opt-out. A new selector, SirPass::DerivedEdgeUnits (derived_edge_units), next to TailCallSplit: not a SIR transform, the builder consumes it. On by default from O1 up, off at O0 like every pass. disable_pass(SirPass::DerivedEdgeUnits) in Rust, passOverrides: ["-sir:derived_edge_units"] in TS/NAPI, --pass -sir:derived_edge_units in the CLIs (they parse SirPass names). It is the reference of the tests too. Documented in CLAUDE.md's pass table, the TS option docs and the internals optimization page.
  • Tiered backend. Its baseline native image is compiled from the program without the units and walks the plans; the optimizing image has them, and SimBackend::runs_derived_edge_units (new, true by default) tells the host when they are live. So on the tiered backend the build cost lands in the background optimizing tier.

Validation

  • derived_edge tests: the generator against run_edge per edge (refactor(runtime): generate the edges of derived clock domains as SIR #1844), and now Simulator ticks, single and repeated edges and host writes through the generated units against the walk, comparing every named signal after each operation, on gated (with a register reading a comb value of the gate's enable, so a missing settle fails it), inverted, falling-edge gated, divider-cascade, commit-raised-enable and independent designs. Always telling the unit not to settle fails it.
  • tick_semantics: every host operation now runs both ways against the timed Simulation running the equivalent SV, with a divider and a gate whose enable the clock's own domain raises added to the DUT. The coincident case of that gate is checked against Icarus 13.0 (e = 0 0 1 2 3) in an ignored test: the timed reference misses that edge (Simulation misses a gated-clock edge when the NBA batch has several updates #1860); both Simulator paths agree with Icarus.
  • --lib: 214 passed. cargo test -p celox --features systemverilog --test systemverilog: 4,351 passed, 20 ignored, in the default and differential scheduler modes (untimed cases tick through Simulator).
  • tiered: a gated-and-divided design ticks on the tiered backend against the walk on every tick, through interpretation, the baseline image and the optimizing image, until the units have run 32 ticks.
  • derived_register_clock, cascade_race, ff_comb_clock, clock_alias_edges, tick_inactive_edge, tick_semantics, native_testbench (clk.next(n)), edge_api, shared_jit_cache and native_float_image (image format 34), flip_flop, checkpoint, state_file, vcd: all passed.
  • clippy -D warnings (tests, examples), the default-feature lib test build without warnings, cargo fmt --check: clean. wasm32 NAPI build: builds.

Perf

Callgrind, Ir per tick = (Ir at 20,000 ticks − Ir at 2,000) / 18,000, on the overhead bench's designs (simulator_tick*: 1,000 registers on clk), the same binary with the units and with -sir:derived_edge_units; two measurement sessions:

design walk generated change
plain 4,013 / 4,017 3,904 / 3,957 same code
gated clk & en 5,213 / 5,177 4,202 / 4,323 −19.4% / −16.5%
register divider 4,736 / 4,709 4,217 / 4,258 −11.0% / −9.6%
gated clock on 10% of the design (900 + 100 registers) 5,035 4,309 −14.4%
plain, four-state 11,235 10,958 same code
gated, four-state 12,869 12,880 walk in both
divided, four-state 11,928 12,312 walk in both

Rows marked "same code" or "walk in both" run the same code in both columns; their differences (up to 3%) are run-to-run variation. A domain's own work is ~3,520 Ir per tick; gated and divided are now ~300–400 Ir above plain, most of it the Rust edge path (moving the signal, the flag, the call).

Criterion wall time on this machine was not usable: the unchanged plain tick moved by +40% between runs.

Build cost

The generated units compile the domain of the clock the derived clocks come from once more (the edge unit inlines it, so each domain's code appears once in the unit; inlining it several times made the native code slower per register). Build-dominated totals at 2,000 ticks (user-space Ir, the same binary), walk → generated:

design walk generated build cost
plain 2.11G 2.11G 0
gated (the whole design on the gated clock's source) 2.12G 2.76G +30% (upper bound)
register divider 3.89G 4.49G +15%
gated clock on 10% of the design 3.93G 4.57G +16% (typical)

The cost follows the size of the source clock's domain, not of the derived part: in the typical case the gated clock drives 10% of the registers, but the source clock (clk, the other 90%) is what the unit inlines. On the tiered backend that cost goes to the background optimizing tier; on the other backends -sir:derived_edge_units trades it back for the plan walk.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 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-24T10:59:02.953181Z 981aaa4 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.

An edge of an event whose derived clock domains have a plan the
derived-edge generator emits (two-state, gated clocks with gate
programs) now runs as one generated unit per edge direction instead of
the Rust walk of DerivedTickPlan: Simulator::edge, and so tick, posedge
and negedge, move the signal, set the scheduler's dirty flag to tell
the unit whether to settle first, and run the unit. Coincident edges
(edges, tick_events) and other plans keep the walk, as do timed
simulations with $finish sites, designs with comb observers or fatal
comb assertions.

The units are on by default from O1 up. A new selector,
SirPass::DerivedEdgeUnits ("derived_edge_units", -sir:derived_edge_units
in pass overrides), turns them off, trading tick speed for build time:
they compile the clock's domain once more. The tiered backend's baseline
image leaves them out and walks the plans until the optimizing image,
which has them, is adopted (SimBackend::runs_derived_edge_units).

tick_semantics now runs every host operation both ways against the
timed reference, with a divider and a gate whose enable the clock's own
domain raises. The coincident case of that gate is checked against
Icarus and ignored until the timed reference sees its edge (#1860).

BREAKING CHANGE: RuntimeSchema has a new field, derived_edges, and
DerivedEdgeUnits is new; SirPass has a new variant, DerivedEdgeUnits. Native images use container format 34; images
written by earlier versions must be rebuilt.

Change-Id: I3436fa1ddc580c66794b40a26866c297ef9cde98
@tignear
tignear force-pushed the feature/derived-edge-sir-b branch from 9ba72e6 to 981aaa4 Compare October 24, 2026 10:56
@mergify

mergify Bot commented Oct 24, 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 24, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 24, 2026
@mergify

mergify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 2 hours 49 minutes 18 seconds in the queue, including 2 hours 4 minutes 11 seconds running CI.

Required conditions to merge
  • check-success = Conventional Commit title
  • check-success = Queue validation
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Lint & Format
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Windows)
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Rust Test & NAPI Build
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Ubuntu)
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Windows)
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Conventional Commit title
    • check-neutral = @github-actions/Conventional Commit title
    • check-skipped = @github-actions/Conventional Commit title

@mergify
mergify Bot merged commit bd4fb45 into master Oct 24, 2026
31 checks passed
@mergify
mergify Bot deleted the feature/derived-edge-sir-b branch October 24, 2026 15:24
@mergify mergify Bot removed the queued Mergify queue entry label Oct 24, 2026
tignear added a commit that referenced this pull request Oct 31, 2026
… 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 added a commit that referenced this pull request Oct 31, 2026
… 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 added a commit that referenced this pull request Oct 31, 2026
… 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
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