Repository navigation
perf(runtime)!: run the derived clock edges of ticks in generated units - #1888
Merged
Merged
Conversation
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. |
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
force-pushed
the
feature/derived-edge-sir-b
branch
from
October 24, 2026 10:56
9ba72e6 to
981aaa4
Compare
Contributor
|
Queued — the merge queue status continues in this comment ↓. |
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
|
40 of 71 tasks
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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(andedge,posedge,negedge) of an event with derived clock domains now runs each edge as one generated unit instead of walkingDerivedTickPlanin Rust: on the overhead bench's designs (1,000 registers onclk), 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_unitsturns them off.BREAKING CHANGE
celox_design::RuntimeSchema(public) has a new field,derived_edges, andDerivedEdgeUnitsis new.SirPass(public) has a new variant,DerivedEdgeUnits.What changes
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.Simulator::edgemoves the signal as before (through the host watch), sets the scheduler'sdirtyflag to say whether combinational logic must settle first (dirty || comb_read, asrun_edgepassessettle), 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.edges,tick_events),fire's plan tick, four-state designs, gates without programs, a timed simulation with$finishsites (the walk stops after the unit that emits one), designs with comb observers or fatal comb assertions.SirPass::DerivedEdgeUnits(derived_edge_units), next toTailCallSplit: 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_unitsin the CLIs (they parseSirPassnames). It is the reference of the tests too. Documented in CLAUDE.md's pass table, the TS option docs and the internals optimization page.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_edgetests: the generator againstrun_edgeper edge (refactor(runtime): generate the edges of derived clock domains as SIR #1844), and nowSimulatorticks, 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 timedSimulationrunning 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); bothSimulatorpaths 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 throughSimulator).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_cacheandnative_float_image(image format 34),flip_flop,checkpoint,state_file,vcd: all passed.-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 onclk), the same binary with the units and with-sir:derived_edge_units; two measurement sessions:clk & enRows 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:
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_unitstrades it back for the plan walk.