You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf: settle only the combinational partitions whose inputs changed #2013
Every settle runs the whole combinational program. eval_comb is one topologically sorted pass that runs once per wave (batch.rsbatch_round, round.rscontinue_round, the compiled scheduler's shared settle). The only skips are all-or-nothing (the scheduler's dirty flag, Simulator.dirty) and the per-process sensitivity guard of SV always @* processes, which still sits inside the full pass. Pure always_comb and assign logic runs on every settle.
On large designs where one clock edge touches a small part of the logic, or where a step has several waves (gated and derived clocks, NBA re-settles), most of each settle recomputes unchanged values. Event-driven simulators (Icarus, xezim) and partitioned compiled simulators (ESSENT-style activity tracking) only evaluate the affected cones.
Proposal (to be refined in a design note before implementation)
Partition eval_comb into partitions along its topological order, each with an input set (state words read from outside the partition).
Track per-partition dirty bits: stores, commits and host writes to a partition's inputs set its bit. That reuses the existing trigger/store instrumentation, and the bits can be computed per committed word range.
A settle runs only dirty partitions in topological order, and a partition whose outputs changed marks its dependents.
Partition granularity is chosen at compile time (cost model: partition size vs. check overhead). Small designs keep the single pass, so single-clock benchmarks don't regress (b2 callgrind gate).
It must hold for all backends (native, Cranelift, WASM, interpreter) and for the compiled scheduler.
Design constraint to keep: the current single pass is the right choice for designs whose combinational logic is active almost every settle (Heliodor, the b2 benchmarks), where dirty checks would be pure overhead. Partitioned settling must therefore be adaptive: decide per partition (or per design) from a compile-time cost model, and ideally from measured activity, so high-activity designs keep the single pass and low-activity designs (C906: many idle gated domains, a testbench-driven SoC) skip unchanged cones.
Build: master 91c70d2 + #2073 + #2082 + feature/perf/2079-level-lists-as-comb. Temporary instrumentation, not in any PR.
eval_comb is 94.5% of JIT time: 34,844 full settles at about 137 µs each over 3,325 cycles, i.e. 10.5 settles per cycle. The settles come from four places, each with its own share per cycle: the process-pass settle after a time slot's processes ran (6.0), the NBA-publish settle (2.5), the second round of a time slot (2.0), and the clock-edge round (2.0). The extra rounds are LRM delta cycles (the BUFGCE latch's NBA chain), so they stay.
Cone sizes: every 100th settle, I diffed the state against a snapshot taken after the previous settle, mapped the changed bytes to state objects, and took the transitive comb fan-out over the 74,562 comb paths. Each path is weighted by its SLT node count, and the result is an upper bound because every reached path counts as changing.
settle site
samples
settles with no changed state
cone mean
cone median
cone max
process-pass settle (process.rssettle_pass)
198
60
0.6%
0.0%
1.6%
NBA-publish settle (round.rs publish loop; carries the FF commits)
83
0
1.7%
0.4%
21.4%
direct eval_comb in continue_round / evaluate_before_inactive
67
49
0.0%
0.0%
0.0%
So 31% of the settles recompute a program whose inputs did not change at all, and the rest touch about 1% of it on average (p90: 36 changed objects).
Model
eval_comb is already one topologically ordered pass. The scheduler (celox-sltsort) lowers SCCs in order, one LogicPath at a time, and cuts units at EU_BLOCK_LIMIT. A comb path is a pure function of the state it reads, except for capture events and process activation guards, which are already change-driven (see Exactness). So a path whose inputs have not changed since it last ran writes exactly the values that are already stored.
Partitions
At lowering time, cut the topological order into partitions: contiguous ranges of SCC nodes. An SCC (a combinational loop or a fold group) and a process unit (LogicPathTarget::Process) are never split.
Because a partition is a contiguous topological range, the partition graph is acyclic by construction, and a single forward pass over partitions is enough.
Granularity comes from a cost target, using SIR instructions emitted per partition, initially a few hundred paths. A later refinement can reorder within topological freedom to cluster each output's cone, as ESSENT does, but contiguous ranges come first.
Every partition P gets a one-byte dirty flag: a synthetic two-state state object like the scheduler's slots.dirty. Every backend (native, Cranelift, WASM, interpreter) and the compiled scheduler then read and write it as ordinary state, with no backend-specific mechanism.
The settle becomes: for each P in order, if dirty[P], clear it and run P's paths; otherwise skip to the next partition.
Dirty tracking
The readers table readers(R) lists the partitions that read range R, at object granularity, or at bit ranges where an object is wide and read in disjoint parts. It is computed at compile time from the paths' sources and address_sources.
Comb to comb. When a partition runs, each store to a comb target that another partition reads compares the new value with the stored one, both planes in four-state. On a change it sets dirty[Q] for every Q in readers(target). Those Q come later in the order, so the same pass picks them up. Targets read only inside their own partition need no compare.
Generated non-comb writers: FF evaluation, apply and commit units, process kernels, derived-edge units, and the fused comb+FF tick's FF part. Every Store or Commit to the stable region of an object in readers gets the same compare-and-mark. The occurrence-probe instrumentation (watch::instrument_unit, RuntimeSchema::occurrence_probes) already does exactly this shape, "a store that changes a probed range bumps a counter", so it is the pattern to reuse. Commits compare working against stable before copying, which costs one load and compare per committed word. Dynamic-index stores into arrays mark every reader of the array.
Runtime writers: NBA publish of process assignments, host set and modify, VPI put_value, testbench writes, $readmem, deposit and force, initial values, checkpoint restore. The runtime gets the readers table, keyed by state object, in the runtime schema and marks through it when it writes a signal. Bulk or unknown writers (restore, memory images, raw writes through memory_as_ptr) mark all partitions, which is the conservative fallback.
Startup. Every flag starts set, so the first settle is the full pass.
Exactness
Invariant: after a settle, every comb target equals its path's function of the current state.
Induction: a partition is skipped only when none of its inputs changed since it last ran. Every change to an input sets its flag: a comb writer by rule 1, a generated writer by rule 2, a runtime writer by rule 3. So its stored outputs already equal the function of the current inputs. Downstream partitions see the same values as in the full pass, because the order is unchanged.
Change-driven parts behave identically when skipped. Trigger bits come from comb stores only when a value changes. Process activation guards (sensitivity_counters, CombStartup) run a process only on change. Comb capture events and assertions are evaluated by a path whose inputs did not change, so they would have produced the same activation as last time.
Partitions holding paths with non-idempotent effects stay always-run ("pinned"), to stay identical without arguing per construct: capture events that fire on every evaluation, runtime error checks with fatal_error_code, and anything the lowering cannot prove pure. The first version pins them.
Four-state compares both planes, so an X to 0 change marks readers.
No region or order changes. The runtime still calls eval_comb at exactly the same points with the same rounds and deltas; each call only does less work. The LRM-required delta cycles stay.
Verification: the full test suite with partitioning forced on for every design, every backend, two- and four-state. A debug mode runs both the partial and the full settle and asserts equal state after every settle, used in tests and once over C906 hello.
Adaptivity, and the b2 gate
Compile time. Partitioning is on only when it can pay: the comb program is large (cost threshold), and the design's comb inputs are not all written by one always-firing domain. Single-clock, comb-active designs (b2_vm_dispatch_bit, Heliodor) get one partition and no guards, so their generated code is bit-identical to master. The b2 callgrind gate checks this. A SirPass toggle (-sir:partitioned_settle) forces it off, and a test-only option forces it on.
Per partition. A partition whose inputs come mostly from a domain that fires on every edge would be dirty almost every settle. It is merged with its neighbours rather than guarded, which bounds guard overhead to the partitions that can actually go idle.
Later: measured activity. The flags double as activity counters, so the tiered backend's optimizing compile can re-partition from observed dirty rates. Not in the first step.
Unchanged for now. Lane-partitioned comb (parallel.eval_comb) keeps the single pass when lanes > 1. The interpreter follows the same SIR, so no special path is needed.
Expected C906 effect
eval_comb drops from 94.5% of JIT time to roughly the dirty-cone cost plus the guards. Measured cones average under 1%. Contiguous partitions are coarser than exact cones, so assume about 5% of the full settle per settle. That takes JIT time from about 5.1 s to about 0.5 s, and the sim phase from about 6.3 s to about 1.5 s on this host: about 4×, from 312 to roughly 1,200 cycles/s. After that, the runtime overhead (17% today, spread thin) dominates.
Plan
Partition analysis and dirty flags in the comb lowering, with comb-to-comb marking (rule 1) and runtime marking for all writers via the readers table (rules 3 and 4). Non-comb generated writers start conservatively: a store marks without comparing. That alone is exact, and it already skips the 31% of settles with no changes.
Compare-and-mark in FF commits, process kernels and derived-edge units (rule 2), reusing the occurrence-probe instrumentation. This is where most of the C906 win comes from.
Adaptivity heuristic, the b2 gate, the debug cross-check mode, then C906 numbers.
Later: cone-clustered ordering, and tiered re-partitioning from measured activity.
Partitioned settle prototype: C906 result (negative)
Prototype: the combinational settle is cut into contiguous ranges of the topological schedule (~2000 expression nodes each). Each range is guarded by a dirty flag. A partition that runs sets the flags of the partitions that read what it writes. Every writer outside the settle sets the flags of the partitions that read its target: FF commits, process units, host writes, state loads. The prototype is correct: the full workspace suite passes, and with partitioning forced on everywhere the backends match the single pass. Single-clock designs are not partitioned (b2_vm_dispatch_bit callgrind unchanged).
C906 (probe3.v testbench, native backend, 34,844 settles over 3,325 cycles):
eval_comb avg
eval_comb total
sim phase
single pass (baseline)
118 µs
4.12 s
4.8 s
partitioned, 237 partitions
162 µs
5.63 s
6.4 s
partitioned, every partition forced to run
166 µs
5.77 s
–
Selectivity: on average 35.8 partitions are dirty at entry (24 on every settle). Following the marks through the plan, 232/237 partitions, 98% of the settle's cost, run on every settle.
Boundary overhead: a full partitioned pass costs about 40% more than the single pass. Store/load forwarding, GVN and the merged comb/apply units no longer work across partition boundaries, and the expression cache restarts at each one.
Root cause
The marks are structural and unconditional. A partition that runs marks every reader of everything it writes, and every FF commit marks every reader of its target, whether the value changed or not. In a CPU almost all combinational logic reads clocked state, so the structural fan-out of any contiguous range covers nearly the whole settle. The cone estimate above (0.6–1.7% of nodes per settle) counted changed values, which this design does not track.
What a win would need
Change-detected marks: compare old and new values at stores that cross partitions and at FF commits and process stores, and mark readers only on a change.
Partitions shaped by cones rather than contiguous schedule ranges.
A much smaller boundary overhead.
Next: a bounded experiment with (1) on an integration branch, no PR. Go only if C906 eval_comb drops by at least 2x against the single pass, with a clear path to cutting the overhead; otherwise this is shelved with these numbers.
Correction, and the change-detected marking experiment
Correction: the selectivity figures in my previous comment (35.8 partitions dirty at entry; 98% of the settle's cost runs on every settle) came from a bug in my instrumentation: it read the 1-byte flags as 8-byte words. The eval_comb timings in that comment are valid.
Experiment (integration branch only, env-gated prototype). Readers are marked only on a change:
Each partition compares the old and new values of the objects other partitions read (case inequality, in chunks) and sets their flags without branching.
FF commits and process stores do the same compare per store.
Whole-variable copies run as guarded work inside their partition instead of unguarded in the middle of it.
Stores from outside the settle to settle-written state are marked too.
C906, same testbench; trace identical to the baseline, 34,844 settles:
eval_comb total
per settle
sim phase
compile
single pass
4.12 s
118 µs
4.8 s
32 s
change-detected, 248 partitions
0.74 s
21 µs
1.65 s
46 s
On average 12.2 of 248 partitions are dirty at entry.
A settle where every partition runs costs 239 µs (2x the single pass).
An offline bound with ideal change detection is 1.9% of the settle's cost.
Open before this can become a PR:
Guarding one specific copy in C906 breaks the trace; it is not yet root-caused, and the measurement excludes that copy.
One timing case with intermediate combinational writes fails under forced partitioning.
The full-pass and compile-time overhead still has to come down.
Measured on #2124's branch (master + the full mode), heliodor-dev, native backend; runs one at a time. Estimated partitions when a design has more than 4 events and its comb cost is at least 20,000 SLT nodes.
design
events
comb cost (paths)
Estimated
single pass
partitioned
rtlmeter C906 hello (4-state)
15
543,660 (74,562)
partition, 248 partitions
sim phase 5.3–5.7 s
1.3–1.7 s (~4x faster)
Heliodor test_soc_linux_boot (full boot, O2)
2
155,107 (10,329)
single pass
execute 121.0 s
forced (gate removed, 73 partitions): 211.7 s (1.75x slower)
rtlmeter Servant (4-state)
1
33,169 (791)
single pass
0.82 s
forced (16 partitions): 0.71 s (too short to matter)
No misjudgments among the designs that run. However, the event count is only a proxy for activity:
C906 has 15 event domains and touches about 1% of its comb per settle.
Heliodor's 2 domains drive most of its comb every cycle.
The gate separates them by event count, but what decides the outcome is the fraction of the settle that changes. A many-clock design with high activity would be partitioned and lose, bounded at 1.6x by #2124's full mode. A low-activity design with 2–4 clocks would miss the win.
Partitioning makes activity measurable at runtime: the flags give the dirty count per settle. So re-partitioning from measured activity (in the tiered backend's optimizing compile) removes the proxy. A compiled single-pass twin would only bound the loss.
The sample is small because other rtlmeter designs do not run on Celox yet: E902/E906, C910 (#88), VeeR-EL2/EH1 and E203. Follow-ups are filed separately.
Activity
tignear commentedon Oct 25, 2026
Design constraint to keep: the current single pass is the right choice for designs whose combinational logic is active almost every settle (Heliodor, the b2 benchmarks), where dirty checks would be pure overhead. Partitioned settling must therefore be adaptive: decide per partition (or per design) from a compile-time cost model, and ideally from measured activity, so high-activity designs keep the single pass and low-activity designs (C906: many idle gated domains, a testbench-driven SoC) skip unchanged cones.
tignear commentedon Oct 25, 2026
Design note: settle only the comb cones reachable from state written since the last settle
Measurements (rtlmeter C906 hello, native, four-state)
Build: master 91c70d2 + #2073 + #2082 +
feature/perf/2079-level-lists-as-comb. Temporary instrumentation, not in any PR.eval_combis 94.5% of JIT time: 34,844 full settles at about 137 µs each over 3,325 cycles, i.e. 10.5 settles per cycle. The settles come from four places, each with its own share per cycle: the process-pass settle after a time slot's processes ran (6.0), the NBA-publish settle (2.5), the second round of a time slot (2.0), and the clock-edge round (2.0). The extra rounds are LRM delta cycles (theBUFGCElatch's NBA chain), so they stay.process.rssettle_pass)round.rspublish loop; carries the FF commits)eval_combincontinue_round/evaluate_before_inactiveSo 31% of the settles recompute a program whose inputs did not change at all, and the rest touch about 1% of it on average (p90: 36 changed objects).
Model
eval_combis already one topologically ordered pass. The scheduler (celox-sltsort) lowers SCCs in order, one LogicPath at a time, and cuts units atEU_BLOCK_LIMIT. A comb path is a pure function of the state it reads, except for capture events and process activation guards, which are already change-driven (see Exactness). So a path whose inputs have not changed since it last ran writes exactly the values that are already stored.Partitions
LogicPathTarget::Process) are never split.Pgets a one-byte dirty flag: a synthetic two-state state object like the scheduler'sslots.dirty. Every backend (native, Cranelift, WASM, interpreter) and the compiled scheduler then read and write it as ordinary state, with no backend-specific mechanism.Pin order, ifdirty[P], clear it and runP's paths; otherwise skip to the next partition.Dirty tracking
The readers table
readers(R)lists the partitions that read rangeR, at object granularity, or at bit ranges where an object is wide and read in disjoint parts. It is computed at compile time from the paths'sourcesandaddress_sources.dirty[Q]for everyQinreaders(target). ThoseQcome later in the order, so the same pass picks them up. Targets read only inside their own partition need no compare.StoreorCommitto the stable region of an object inreadersgets the same compare-and-mark. The occurrence-probe instrumentation (watch::instrument_unit,RuntimeSchema::occurrence_probes) already does exactly this shape, "a store that changes a probed range bumps a counter", so it is the pattern to reuse. Commits compare working against stable before copying, which costs one load and compare per committed word. Dynamic-index stores into arrays mark every reader of the array.setandmodify, VPIput_value, testbench writes,$readmem, deposit and force, initial values, checkpoint restore. The runtime gets thereaderstable, keyed by state object, in the runtime schema and marks through it when it writes a signal. Bulk or unknown writers (restore, memory images, raw writes throughmemory_as_ptr) mark all partitions, which is the conservative fallback.Exactness
sensitivity_counters,CombStartup) run a process only on change. Comb capture events and assertions are evaluated by a path whose inputs did not change, so they would have produced the same activation as last time.fatal_error_code, and anything the lowering cannot prove pure. The first version pins them.eval_combat exactly the same points with the same rounds and deltas; each call only does less work. The LRM-required delta cycles stay.Adaptivity, and the b2 gate
SirPasstoggle (-sir:partitioned_settle) forces it off, and a test-only option forces it on.parallel.eval_comb) keeps the single pass when lanes > 1. The interpreter follows the same SIR, so no special path is needed.Expected C906 effect
eval_combdrops from 94.5% of JIT time to roughly the dirty-cone cost plus the guards. Measured cones average under 1%. Contiguous partitions are coarser than exact cones, so assume about 5% of the full settle per settle. That takes JIT time from about 5.1 s to about 0.5 s, and the sim phase from about 6.3 s to about 1.5 s on this host: about 4×, from 312 to roughly 1,200 cycles/s. After that, the runtime overhead (17% today, spread thin) dominates.Plan
tignear commentedon Oct 26, 2026
Partitioned settle prototype: C906 result (negative)
Prototype: the combinational settle is cut into contiguous ranges of the topological schedule (~2000 expression nodes each). Each range is guarded by a dirty flag. A partition that runs sets the flags of the partitions that read what it writes. Every writer outside the settle sets the flags of the partitions that read its target: FF commits, process units, host writes, state loads. The prototype is correct: the full workspace suite passes, and with partitioning forced on everywhere the backends match the single pass. Single-clock designs are not partitioned (b2_vm_dispatch_bit callgrind unchanged).
C906 (
probe3.vtestbench, native backend, 34,844 settles over 3,325 cycles):Root cause
The marks are structural and unconditional. A partition that runs marks every reader of everything it writes, and every FF commit marks every reader of its target, whether the value changed or not. In a CPU almost all combinational logic reads clocked state, so the structural fan-out of any contiguous range covers nearly the whole settle. The cone estimate above (0.6–1.7% of nodes per settle) counted changed values, which this design does not track.
What a win would need
Next: a bounded experiment with (1) on an integration branch, no PR. Go only if C906 eval_comb drops by at least 2x against the single pass, with a clear path to cutting the overhead; otherwise this is shelved with these numbers.
tignear commentedon Oct 26, 2026
Correction, and the change-detected marking experiment
Correction: the selectivity figures in my previous comment (35.8 partitions dirty at entry; 98% of the settle's cost runs on every settle) came from a bug in my instrumentation: it read the 1-byte flags as 8-byte words. The eval_comb timings in that comment are valid.
Experiment (integration branch only, env-gated prototype). Readers are marked only on a change:
C906, same testbench; trace identical to the baseline, 34,844 settles:
Open before this can become a PR:
feat(runtime)!: opt-in partitioned combinational settle
feat(runtime)!: opt-in partitioned combinational settle
perf(runtime): mark settle partitions only when their inputs change
perf(runtime): run every partition of a busy settle without comparing
tignear commentedon Oct 26, 2026
Which designs
EstimatedpartitionsMeasured on #2124's branch (master + the full mode), heliodor-dev, native backend; runs one at a time.
Estimatedpartitions when a design has more than 4 events and its comb cost is at least 20,000 SLT nodes.EstimatedNo misjudgments among the designs that run. However, the event count is only a proxy for activity:
The gate separates them by event count, but what decides the outcome is the fraction of the settle that changes. A many-clock design with high activity would be partitioned and lose, bounded at 1.6x by #2124's full mode. A low-activity design with 2–4 clocks would miss the win.
Partitioning makes activity measurable at runtime: the flags give the dirty count per settle. So re-partitioning from measured activity (in the tiered backend's optimizing compile) removes the proxy. A compiled single-pass twin would only bound the loss.
The sample is small because other rtlmeter designs do not run on Celox yet: E902/E906, C910 (#88), VeeR-EL2/EH1 and E203. Follow-ups are filed separately.