Repository navigation
feat(sim)!: make a tick one clock period and run every clock generator - #1776
mergify[bot] merged 3 commits into
Conversation
`Simulator::tick` was the event's active edge only, with the signal left unchanged, so domains of the opposite edge and clocks derived from it never ran on a tick. A tick is now one clock period of the event's signal, the SystemVerilog `s <= A; #H; s <= I; #L;`: the active edge, then the inactive edge, running every domain sensitive to either and leaving the signal at its inactive level. A signal already at the active level takes no active edge. `tick_events` makes the edges of several events together, the N-API and WASM ticks follow the same definition, and `Simulator::cycle`, which did this already, is removed. `$tb::clock_gen` instances in Veryl testbenches now run from time 0 whether or not a process waits on them, as the generated SystemVerilog does. Before, a clock advanced only while some process was in its `next()`. `next(n)` runs n periods of the clock. The new execution semantics guide describes the host API as a whole. BREAKING CHANGE: `Simulator::tick` and `tick_events` also take the inactive edge, so domains of the opposite edge now run and the event's signal ends at its inactive level. A negative-edge clock that starts at 0 takes no edge on its first tick. `Simulator::cycle` is removed; use `Simulator::tick`. Every `$tb::clock_gen` in a Veryl testbench runs all the time, so counters on clocks other than the one being waited on keep counting. Change-Id: I90587af4533d71983b1b43a06fde072de10446a8
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3ade32a4c9
ℹ️ 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".
| let mut builder = SemanticTestbenchBuilder::new(lookup, source, site_end); | ||
| builder.prepared_readmem = super::readmem::prepare_testbench_memories(lookup, source)?; | ||
| builder.build_event_map(initial_stmts); | ||
| clocks.extend(builder.clock_generators()); |
There was a problem hiding this comment.
Collect clocks from modules without initial blocks
When a clock generator belongs to a module with no initial block, it is excluded here because sources was filtered by initial_statements.is_some() above (and child sources without initial blocks may not be retained at all). If another process advances simulation time, that generator never enters ExecutableTestbench::clocks, so its signal and clocked domains remain idle despite the new guarantee that every $tb::clock_gen runs from time 0. Collect generators independently from the sources used to compile initial processes.
Useful? React with 👍 / 👎.
| if sim.period_runs_only_own_domain(event) { | ||
| return sim.tick_deferred_comb_many(event, count); |
There was a problem hiding this comment.
Drive the active level before the deferred clock kernel
For a domain-only positive-edge clock, this fast path invokes the sequential kernel while the clock signal remains at the initialized low level. Consequently, legal logic such as always_ff (clk) { sampled = clk; } records 0 during clk.next(), whereas the defined clk <= 1; ... clk <= 0 period records 1 at the rising edge. The batching optimization must pulse the signal or be restricted when the sequential domain reads its event signal.
Useful? React with 👍 / 👎.
| .filter_map(|clock| { | ||
| Some(TestbenchClock { | ||
| event: backend.resolve_event_opt(&clock.event)?, | ||
| period: clock.period, |
There was a problem hiding this comment.
Keep clock generators that have no event domain
Dropping a generator when resolve_event_opt returns None also prevents its signal from toggling, even though the signal can still be observed by testbench expressions. For example, while a domain-bearing period: 2 clock advances time, a second otherwise-unused period: 6 clock should be high at time 2; this filter leaves it permanently low, so assertions or conditions that sample it disagree with the documented SystemVerilog generator. Clocks without domains still need their signal transitions scheduled.
Useful? React with 👍 / 👎.
| pub struct TestbenchProgram<A> { | ||
| statements: Vec<SemanticStatement<A>>, | ||
| process_lengths: Vec<usize>, | ||
| clocks: Vec<TestbenchClock<A>>, |
There was a problem hiding this comment.
Bump the native image container version
Adding clocks changes the postcard layout of TestbenchProgram, which is embedded directly in serialized NativeProgramImage, but CONTAINER_VERSION remains 28. A current runtime loading a version-28 image containing a testbench from before this commit therefore passes the version check and then misdecodes or rejects the shifted payload, and older runtimes likewise treat new images as the same format. Increment the native image container version with this schema change.
Useful? React with 👍 / 👎.
|
@Mergifyio queue |
Merge Queue Status
This pull request spent 6 minutes 10 seconds in the queue, with no time running CI. ReasonPull request #1776 has been dequeued by @tignear with a Waiting for
All conditions
Requeued — the merge queue status continues in this comment ↓. |
☑️ This pull request is already queued |
|
@mergify dequeue |
|
@Mergifyio dequeue |
☑️ The pull request is not queued |
Drop the rule for testbench reads after a process's own writes and the note on rst.assert: this page defines only `$tb::clock_gen` and `clk.next`. Change-Id: I53597f755035ab02363ba24b8d3e5f6c2f15aa8d
The `Simulator` table no longer carries `#1` delays. Each host call is one time slot of the IEEE 1800 simulation, the table gives the statement of that slot, and a tick is two slots. A note keeps the single-process form with one precision unit of delay for running the sequence on a SystemVerilog simulator. Add the host reset idiom, a section on clocks with a frequency ratio (`edges` or the timed `Simulation`; a tick cannot express the phase), and the definitions of `$tb::reset_gen` and `rst.assert(n)`: the net starts deasserted, the assertion is a blocking write, the level is held for `n` periods and released at the phase at which `next` resumes. Change-Id: Iae8d1d32a0b11453e6ce4a4e19a06c5a0e70742a
Merge Queue Status
This pull request spent 1 hour 35 minutes 15 seconds in the queue, including 57 minutes running CI. Required conditions to merge
|
Summary
Simulator::tickwas the event's active edge only, with the signal left unchanged, so domains of the opposite edge (~clk, a fallingclk & en) never ran on a tick. A tick is now the SystemVerilogs <= A; #H; s <= I; #L;: the active edge, then the inactive edge. It runs every domain sensitive to either edge and leaves the signal at its inactive level. A signal already at the active level takes no active edge.tick_eventsmakes the edges of several events together. The N-API (run_tick) and WASM ticks follow the same definition.Simulator::cycle, which already did this, is removed.$tb::clock_genruns from time 0. Every clock generator of a Veryl testbench now runs whether or not a process waits on it, as the generated SystemVerilog does. Before, a clock advanced only while a process was in itsnext().next(n)runs n periods.writing-testsandcascade-limitationsare updated to match.Breaking changes
tick, the event's signal is at its inactive level, and opposite-edge domains have run.Simulator::cycleis removed; usetick.test_dual_clock,cnt_bcounts duringclk_a.next(10).Existing tests updated for the new semantics
component_method::child_initial_resolves_its_component_method_instance: the child's ownclock_gennow runs, and itson_clockloadsdintoq. The child now holdsdat the driven value.native_testbench::test_dual_clock: the expectations now account for both clocks running throughout, plus the 3 periods ofrst_b's assertion.review_regressions::uses_the_first_always_ff_event_as_a_negedge_clock: the clock idles high before the tick.celox-napinative_handle_dumps_consume_activity_until_memory_is_exposed: a tick also marksclk's trace group. The 4-group test design reached the dense threshold (half the groups), where a dump scans every signal, so two more wide inputs keep it sparse.Validation
cargo nextest run --workspace --exclude 'lydite*' --profile ci --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus(16,340 tests): the only failures were the 4 tests above, which were fixed and rerun individually.cargo nextest run --profile ci -p celox -p celox-runtime -p celox-napi -p celox-testbench -p celox-frontend-veryl --features celox/systemverilog, 13,695 passed.tick_semantics, a tick against the timedSimulationin SystemVerilog, andclock_gen_semantics, clock generators that run with and without waiting processes. Alsoedge_api,both_clock_edges,derived_register_clockandfour_state_explicit_edges.cargo clippy --workspace --all-targetswith CI features: clean.cargo fmt --check: clean.pnpm -r test(celox 432, playground 184) andpnpm --filter @celox-sim/playground test:wasm(18) against a localwasm32-wasip1-threadsnapi build with wasi-sdk 25. Alsopnpm typecheckandpnpm lint.lydite-checks.yml), which may depend on clock-generator timing.