Skip to content

feat(runtime): compile derived clock domains in the compiled scheduler (3b-2) #1786

Open

Description

@tignear

Part of #1123, step 3b-2 (compiled waits). Follows #1777.

Problem

The compiled scheduler of #1777 qualifies only designs with "no cascaded, state-derived or combinationally derived clocks". Gated clocks (clk & en) and register dividers are ordinary RTL, so the designs that need the scheduler most fall back to the Rust reference loop for every slot.

The exclusion is not a missing proof. Derived-clock edge detection already runs from a structural plan built at compile time (celox-runtime DerivedTickPlan, run_edge): which source edges reach which derived domains, the gate's expression, and the chain of state-derived clocks. Only the code that walks the plan is Rust.

Proposal

Treat a derived clock domain as a compiled wait site in 3b-2, with the plan generated as SIR:

  • Combinationally derived (clk & en, ~clk): in the slot of the source edge, after the settle, compare the derived clock's expression with its baseline in state and, on an edge, run the derived domain's unit. This is the same code as 3b-2's event waits: static watched signals, compare after each settle, set a ready bit, dispatch.
  • State-derived (a register divider, a gate whose enable the commit raises): compare again after the commit and chain, bounded by the plan's depth, as the post-commit loop of 3b-2 does.

No new static analysis: the plan is the existing structural data (per the #1123 review policy, fast paths stay syntactic).

Gate

cargo bench -p celox --bench overhead, 10000 periods, median, two-state. On master cycle is what tick is after #1776:

design tick (active edge only) cycle (one period)
plain 2.05 ms 2.05 ms
gated clk & en 3.50 ms 5.07 ms
register divider 3.26 ms 3.68 ms

With compiled derived domains, gated and divided should cost about plain plus the derived domain's body. A Veryl native testbench's clk.next(n) on these designs must keep a batched path.

Related: #1776 (a tick is one period), and the interim fast-path relaxation for the inactive edge on branch feature/tick-inactive-edge-fast-path, which stays useful for designs the scheduler does not take.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions