Repository navigation
perf(sim): keep the inactive edge of a tick cheap when nothing can fire on it - #1789
Conversation
…re on it A tick of an event with derived clocks ran its inactive edge through the derived plan, which settles combinational logic although no domain fires on that edge for a gated (`clk & en`) or divided clock. Decide per event at build time whether the inactive edge can run a domain: the event's own, or one of a clock computed combinationally from the signal that the edge can move to its active edge, judged from how the gate program depends on the signal (positive, negative, independent or mixed). With nothing able to fire on that edge nothing commits, so no state-derived domain runs either. `EventEdge::inactive_runs` records it. `tick`, `tick_events` and the native testbench's `clk.next(n)` use it: when the inactive edge runs nothing they take the active edge and then only store the inactive level, marking combinational logic dirty when it reads the signal. If the active edge left combinational logic unsettled, the inactive edge still runs in full. Gated and divided designs keep the batched `clk.next(n)` path. Change-Id: Id9d21afbe418767912aa2adf08d018ec5899162e
…re unobservable A plain tick stores the active level, runs the domain and stores the inactive level. When the signal already is at its known inactive level, no combinational logic and no flip-flop of the event's own domain reads it, and no comb observer or host watch is active, both stores are unobservable: the level is the inactive one before and after the call and nothing but the domain runs in between. `tick` then is exactly the domain run, as before ticks became clock periods. The frontend records at build time which event domains never read their own signal (`EventTopology::level_unread_by_domain`; a load or commit source of the signal or an external call counts as a read, and an absent entry means the level may be read). `EventEdge::level_read` combines it with `comb_read`. A first tick from an unknown or active level still moves the signal. Change-Id: I0ec005eafbfc07f8f8ff246be3e7f381436178a3
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. |
|
@Mergifyio queue |
Merge Queue Status
This pull request spent 2 hours 43 minutes 57 seconds in the queue, including 1 hour 55 minutes 27 seconds running CI. Required conditions to merge
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b49c5a495e
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| pub(crate) fn period_runs_only_active_edge(&self, event: B::Event) -> bool { | ||
| !self.event_edges[event.id()].inactive_runs && self.host_watch.is_empty() |
There was a problem hiding this comment.
Preserve the clock level in derived
clk.next periods
When a native-testbench clock has an active-edge-only derived plan (for example, gclk = clk & en) and a flip-flop in the source clock's own domain samples clk as data, this predicate returns true even though EventEdge::level_read is true. clock_periods then uses tick_deferred_comb_many; its derived-plan path reaches fire/tick_derived, which models the derived transitions without moving the source signal, so the source-domain flip-flop sees the inactive level instead of the active level. Before this change, the presence of a derived plan forced the explicit rising/falling edge path. Either exclude level-reading events here or make the derived deferred path expose the active source level while evaluating domains.
Useful? React with 👍 / 👎.
| /// Canonical events whose own domain reads no level of their signal: its | ||
| /// flip-flops do not sample the signal as data. With | ||
| /// [`Self::combinationally_read`] it says whether a run of the domain | ||
| /// observes the signal's level. Absent means it may. | ||
| #[serde(default)] | ||
| pub level_unread_by_domain: BTreeSet<A>, |
There was a problem hiding this comment.
Declare the public struct expansion as breaking
Adding this required public field breaks downstream exhaustive struct literals and destructuring for the published celox-design crate; the same commit also adds required fields to the exported celox_runtime::EventEdge. Because the perf(sim) subject drives release automation without a breaking marker, these source-incompatible changes can be shipped as a patch release rather than receiving the required breaking-version treatment. Avoid changing the public struct shape or mark the change with !.
AGENTS.md reference: AGENTS.md:L116-L118
Useful? React with 👍 / 👎.
Stacked on #1776.
A tick of an event with derived clocks ran its inactive edge through the derived plan, which settles combinational logic although no domain fires on that edge for a gated (
clk & en) or divided clock.Change
EventEdge::inactive_runs(celox-runtimebuild_event_edges): decided per event at build time. The inactive edge can run a domain when it fires the event's own domain, or a clock computed combinationally from the signal that the edge can move to its active edge. A gate program's dependence on its source is classified as positive, negative, independent or mixed. Gates without a program count as able to fire, and so do clocks of unknown kind. With nothing able to fire, nothing commits, so state-derived domains (dividers) can't run either.tick,tick_events: when the inactive edge runs nothing, take the active edge and then only store the inactive level. Combinational logic is marked dirty when it reads the signal, as the plain path already did. If the active edge left combinational logic unsettled, the inactive edge still runs in full.Plain tick fast path (second commit): a plain tick stores the active level, runs the domain and stores the inactive level. When the signal is already at its known inactive level, both stores are unobservable, so the tick is one run of the domain, as
tickwas before feat(sim)!: make a tick one clock period and run every clock generator #1776. The conditions are:The frontend records
EventTopology::level_unread_by_domainat build time: a load or commit source of the signal, or an external call, counts as a read, and an absent entry means the level may be read.EventEdge::level_readcombines it withcomb_read. A first tick from an unknown or active level still moves the signal. VCD and checkpoints only see state at the end of a host call, where the level is the same either way.tick_eventsis unchanged.period_runs_only_own_domain→period_runs_only_active_edge: native testbenchclk.next(n)keeps its batched path for gated and divided designs.Observable behaviour is unchanged (see
docs/guide/execution-semantics.md).Tests
New
tests/tick_inactive_edge.rscompares against the timedSimulationrunning the equivalent SV statements, in two-state and four-state, unknown bits included. It covers:clk/gclk(must be low after a tick), including coincidenttick_events;negedge gclkdomain (runs on every tick);~clkdomain;enis low.It also asserts the computed
inactive_runsfor each design.Plain fast path:
a_plain_tick_skips_only_unobservable_level_stores: a differential test againstSimulation, with one clock nothing reads (fast path) and one a flip-flop samples as data (stores kept). Mutation-checked: dropping the flip-flop read fromlevel_readmakes it fail.vcd::test_vcd_of_ticks_matches_stored_periods: the VCD ofticks equals the VCD of explicitactive_edge+inactive_edgeperiods, in two-state and four-state.New native testbench test:
clk.next(n)on gated and divided clocks.Unit tests for the gate dependence analysis.
Passed: celox lib plus 25 tick/edge/testbench/VCD/checkpoint/state-file test binaries and the
systemverilogsuite with--features systemverilog, celox-runtime, celox-design and celox-frontend-core tests, workspace clippy with the CI features,cargo fmt --check.Bench
overhead, best median per 10000 periods over 3 interleaved rounds on one pinned core. Each run started with the 1-minute load below 4.The parent session's quiet-machine run of the first commit:
With the plain fast path (b49c5a4), same procedure:
Plain now matches master's
tick, and the other variants are equal or better than e673910. Divider 4-state is bimodal across runs in both builds (7.3 / 9.6 ms for b49c5a4, 7.6 / 10.3 ms for e673910), so it is layout-sensitive; the table gives the best median.