Repository navigation
Description
Design note: schedule the synthesizable part as reg' = ff(comb(reg))
Goal. Every process and construct that fits the cycle model, combinational logic followed by registers that sample it, is scheduled statically, so each clock edge costs one combinational settle. Event-driven rounds remain only for what that shape cannot express. This note covers no implementation; it records the classification, the target, the semantic rule, and a staged plan, with numbers from rtlmeter C906 hello.
Measurement basis. C906 hello, probe3.v testbench, native backend, four-state, heliodor-dev, 3,325 cycles. Build: master 91c70d2 + #2073 + #2082 + the #2079 level-list change (#2087), with temporary per-function instrumentation. Numbers marked estimate are not measured.
- Combinational settles: 34,844, i.e. 10.5 per cycle (5.2 per clock edge).
eval_combis 94.5% of JIT time: 4.12 s of a 4.8 s simulation phase. - Settle call sites per cycle: start-of-slot round 2.0, later rounds of the slot 2.0, process-pass settle (after process kernels ran) 6.0, NBA-publish settle 2.5. That is 12.5 entries per cycle; some find nothing to settle.
1. Classification
Elaborated C906 has 74,562 combinational paths and 15 static event domains (FF evaluate and apply units). 77 processes still run as event-driven kernels:
| Class | Fits the cycle model? | C906 count | Runs per cycle | Why it is dynamic today |
|---|---|---|---|---|
Continuous assigns, always_comb, always @*, level lists covering their reads (#2079) |
yes, static today | ~720 level-list processes plus all assigns, in 74,562 comb paths | 10.5 settles | — |
| Edge-triggered FFs on clock, derived and gated clocks (#2073 bit-level clock aliases) | yes, static today | 15 domains | domain 0: 1.0, domain 14: 0.5, others ≤ 0.5 | — |
FFs writing disjoint bits of one vector from different clocks (always @(posedge mst_sel_clk[j] or negedge prst_b) mst_psel_flop[j] <= … in generate loops: PLIC and APB 1-to-x matrices) |
yes | 35 (processes 40–74) | 0.5–2.5 each | a variable driven from several clock domains is not split per bit into domains |
NBA latch clock gate (BUFGCE: always @(I or CE) if (!I) l <= CE; then always @(l) en <= l;, O = I && en) |
yes, under the rule in §3 | 2 (processes 75, 76) | 4.0 and 2.0 | NBA in level-sensitive blocks gives LRM delta cycles |
Level lists that store a variable twice (default assignment then a partial one or a case: GPIO APB interface, IDU decoder and split, APB bridge, UART) |
yes, under the rule in §3 | 32 (processes 8–39) | ≤ 0.1 each | intermediate values could pulse waiters (#2079 keeps them as processes) |
tb FF-shaped blocks with system tasks (always @(posedge clk …) counters, $display checker) |
partly (§3, item 4) | 2 (processes 6, 7) | 1.0 each | system task side effects |
tb clock generators (always #(P/2) clk = ~clk) |
no, timing control | 2 (processes 0, 1) | 2.0 and 0.5 | must stay dynamic |
tb initial with delays, $readmemh, $finish |
no | 4 (processes 2–5) | startup only | must stay dynamic |
The clock-gate cells in the core (gated_clk_cell) are pass-throughs (assign clk_out = clk_in;), so every gated APB and PLIC clock is the BUFGCE output or an alias of it. Everything clocked from it waits for the BUFGCE delta chain.
2. Target: settles per edge
Today, one cycle (both edges): about 10.5 settles. At each edge: the clock generator's process pass, the edge round of the static domains and its NBA publish, and the tb FF processes' pass. The BUFGCE latch adds rounds on top: the latch NBA, the follower NBA, and its second wake. So do the 35 dynamic FFs on the gated clock, with their own process passes and NBA publish.
After stages 1–2 (the classes marked yes become static): per edge,
- before-domain settle: the clock generator wrote
clk; derived and gated clocks and anything readingclkas data must settle before the domains sample. One per edge. - after-domain settle: the domains' commits propagate. One per edge.
- tb processes 6 and 7, if they stay dynamic, add a process pass at the posedge unless they run inside the edge round (stage 3).
That gives about 4 settles per cycle (2 per edge) instead of 10.5, assuming nothing else wakes in between (estimate; the reset phase is excluded).
Ideal, 1 settle per edge (2 per cycle, about 1 per cycle in practice):
- No separate before-domain settle. It is needed only for logic that reads
clkas data. Whenclkreaches nothing but the clock tree (gates, aliases, the static latch), the derived-edge units already judge gated clocks from the clock's new value. The edge kernel can then run the domains directly from the generator's write, and the settle merges into the after-domain one. This needs a compile-time proof thatclk's comb fan-out is clock-tree only. - The negedge does no work. No FF samples on the main clock's negedge in C906 (only two JTAG FFs use the JTAG clock's negedge), and the
BUFGCElatch opens on it. With the latch static (§3), a negedge changes onlyclkand the latch's enable. Under perf: settle only the combinational partitions whose inputs changed #2013 the settle then finds only the clock-tree partitions dirty, so it costs almost nothing. - The tb clock generator stays a dynamic process (timing control). Its one wake per edge is the only event-driven work left in the steady state.
3. Semantics: when static scheduling is unobservable
Rule (both state modes): the static schedule may only apply transformations that are unobservable per the LRM. Where a static form would be observable, the construct stays dynamic, or a narrowly scoped exception is proposed for the user to decide. Verilator's behavior is a reference for what designs tolerate, not a mode default. Two-state mode follows the LRM like four-state. #2078, the time-zero settle of sensitivity-list blocks, is a deliberate narrow exception and not a precedent for mode-wide deviations.
What the LRM fixes and what it leaves open:
- Statements in a begin-end block run in source order, and NBAs are performed in execution order (4.6).
- Active events run in any order, and a procedural statement without a time control may be interleaved with other processes at any point (4.7).
- An event control or edge fires on a value change of its expression (9.4.2, Table 9-2).
- NBAs update in the NBA region, which can start new active events in the same time step (10.4.2).
So a static schedule is unobservable exactly when no process (or VPI callback) can see a different set or order of value changes than some legal LRM execution would produce. End-of-time-step values alone are not enough: a waiter counts changes.
-
NBA latch clock gate (
BUFGCE). In LRM order:- At
Irising, the latch process wakes,if (!I)is false, nothing changes, andO = I && enrises with theenheld since the falling edge. - At
Ifalling, the latch NBA takesCE, the follower's NBA takes it one delta later, andOstays 0 becauseIis 0.
The static form evaluates the latch and the follower as level-sensitive comb (
if (!I) l = CE; en = l;) in the settle. Comparing the two:Ois identical.enchanges only whileIis 0, soO = I && ennever glitches, in either order. This is the gate's design intent.- The intermediate deltas are different. In LRM order,
landenchange one and two deltas afterIfalls; in the static form, in the same settle. IfCEchanges in the same time step as the falling edge (for example from a negedge FF), the LRM order can pulsel(oldCE, then new), and an@(l)waiter would count two changes. - Condition for the static form: the latch's outputs (
l,en) have no readers outside the gate structure. That means no event control on them, no level-list process reading them, no VPI value-change callback on them, and the only reader ofenis the AND withI. Under that condition no process can observe the intermediate deltas, so the transformation is LRM-unobservable in both modes. C906 meets it. Otherwise the gate stays dynamic. - Edge counting on
Oitself is unaffected, becauseOchanges at the same edges in both forms.
- At
-
Level lists that store a variable twice (processes 8–39). Running such a block statically is observable only through a waiter on the stored variable, which would see the intermediate value. Condition: the stored variables have no event-control waiters and no VPI callbacks, and their readers are static comb or FF. Then the intermediate value is invisible, and the block can be simulated like
always @*with its final values. Otherwise it stays a process (perf(runtime): waking processes compares every waiter's watched signals on every round #2079's rule). -
FFs on per-bit clocks of a shared vector (processes 40–74). These are ordinary edge-triggered blocks. Splitting the variable's bits by driving domain is a representation change with no semantic effect: each bit keeps its own clock and NBA semantics. No exception is needed.
-
tb FF-shaped blocks with system tasks (6, 7). An
always @(posedge clk)that calls$displayreads pre-NBA values in the active region. A static FF domain evaluates in the same region, so the values match. What could differ is the order of its output relative to other processes' output in the same active region, and 4.7 already leaves that order open. Moving them into the edge round is therefore LRM-unobservable if their effects keep the order one legal execution would produce. Proposed, for confirmation; keep them dynamic until then. -
Clock generators,
#delays,wait,@inside procedural code,$finish/$stopand other side-effecting tasks outside FF shape stay dynamic.
Exception candidates flagged for the user: none needed for C906. If a design has an NBA latch gate whose en is also read elsewhere, for example by a tb monitor with @(en), the honest options are to keep that gate dynamic (cost: C906-style delta rounds for that clock only), or to adopt a scoped exception: "a recognized clock-gate latch drops its intra-time-step pulses". The second option is not proposed; it would need an explicit decision.
4. Relation to #1123 and #2013, and the staged plan
- feat(sir): compile timing-controlled processes into resumable state-machine kernels #1123 (hybrid). The dynamic path stays complete and LRM-conformant, and static scheduling is the fast path. This note widens what the fast path covers: classification is per process, and anything that fails a condition falls back to the dynamic path for that process or clock only, never the whole design. The kernels stay fused into the JIT tick.
- perf: settle only the combinational partitions whose inputs changed #2013 (partitioned settle). This note cuts the number of settles; perf: settle only the combinational partitions whose inputs changed #2013 cuts the cost of each settle. They multiply on the settle cost:
- perf: settle only the combinational partitions whose inputs changed #2013 prototype on this build:
eval_comb4.12 s → 0.74 s (21 µs per settle instead of 118 µs, 12 of 248 partitions dirty on average). - After perf: settle only the combinational partitions whose inputs changed #2013, a settle with nothing dirty costs only its guards. Fewer settles then mainly save runtime work: process dispatch, NBA publish, round bookkeeping, and the guard scan per settle. That runtime work is a large part of the remaining ~0.9 s.
- perf: settle only the combinational partitions whose inputs changed #2013 prototype on this build:
Staged plan and expected C906 gains (simulation phase, native, heliodor-dev; baseline 4.8 s; estimates unless marked):
| Stage | Change | Settles per cycle | Sim phase without #2013 | Sim phase with #2013 |
|---|---|---|---|---|
| 0 | today / #2013 change-detected marks | 10.5 | 4.8 s (measured) | 1.65 s (prototype, measured) |
| 1 | split shared-vector FFs by clock domain; static NBA-latch clock gate under §3.1; multi-store level lists without waiters under §3.2 | ~5 | ~2.5 s | ~1.1 s |
| 2 | merge the before-domain settle when the clock reaches only the clock tree; edge kernel runs the domains directly | ~2–3 | ~1.4 s | ~0.8 s |
| 3 | tb FF-shaped processes in the edge round (§3.4, after confirmation) | ~2 | ~1.2 s | ~0.7 s |
Each stage ships with the same equivalence harness as #2013: dynamic versus static on the shared test suite in both state modes, plus targeted cases for each §3 condition:
- a waiter on the latch output keeps the gate dynamic;
- a waiter on a multi-store variable keeps the block a process;
CEchanging at the falling edge.
Every stage also reports C906 numbers.
Not covered: multi-clock designs whose clocks are generated with unrelated periods (each edge is still one settle, but edges do not merge), and designs where the clock is read as data by large comb cones (the before-domain settle stays).
Activity