Skip to content

feat(sim)!: make a tick one clock period and run every clock generator - #1776

Merged
mergify[bot] merged 3 commits into
masterfrom
feature/simulator-tick-andveryl-tb-clock-next-semantics
Oct 23, 2026
Merged

mergify[bot] merged 3 commits into
masterfrom
feature/simulator-tick-andveryl-tb-clock-next-semantics

Conversation

@tignear

@tignear tignear commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • A tick is one clock period. Simulator::tick was the event's active edge only, with the signal left unchanged, so domains of the opposite edge (~clk, a falling clk & en) never ran on a tick. A tick is now the SystemVerilog s <= 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_events makes 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_gen runs 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 its next(). next(n) runs n periods.
  • Docs. A new execution semantics guide (en/ja) describes the host API as a whole; writing-tests and cascade-limitations are updated to match.

Breaking changes

  • After tick, the event's signal is at its inactive level, and opposite-edge domains have run.
  • A negative-edge clock that starts at 0 takes no edge on its first tick. Set the clock high first.
  • Simulator::cycle is removed; use tick.
  • In Veryl testbenches, counters on other clocks keep counting while one clock is being waited on. For example, in test_dual_clock, cnt_b counts during clk_a.next(10).

Existing tests updated for the new semantics

  • component_method::child_initial_resolves_its_component_method_instance: the child's own clock_gen now runs, and its on_clock loads d into q. The child now holds d at the driven value.
  • native_testbench::test_dual_clock: the expectations now account for both clocks running throughout, plus the 3 periods of rst_b's assertion.
  • review_regressions::uses_the_first_always_ff_event_as_a_negedge_clock: the clock idles high before the tick.
  • celox-napi native_handle_dumps_consume_activity_until_memory_is_exposed: a tick also marks clk'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.
  • After rebasing onto master (refactor(runtime)!: run timed slots from SimulationState with a differential scheduler harness #1756 changed the runtime scheduler): 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.
  • New tests: tick_semantics, a tick against the timed Simulation in SystemVerilog, and clock_gen_semantics, clock generators that run with and without waiting processes. Also edge_api, both_clock_edges, derived_register_clock and four_state_explicit_edges.
  • cargo clippy --workspace --all-targets with CI features: clean. cargo fmt --check: clean.
  • JS: pnpm -r test (celox 432, playground 184) and pnpm --filter @celox-sim/playground test:wasm (18) against a local wasm32-wasip1-threads napi build with wasi-sdk 25. Also pnpm typecheck and pnpm lint.
  • Not run: lydite conformance gates (lydite-checks.yml), which may depend on clock-generator timing.

`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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T00:59:14.447789Z ca7fa8e New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 22, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +2428 to +2429
if sim.period_runs_only_own_domain(event) {
return sim.tick_deferred_comb_many(event, count);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +397 to +400
.filter_map(|clock| {
Some(TestbenchClock {
event: backend.resolve_event_opt(&clock.event)?,
period: clock.period,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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>>,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@tignear

tignear commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify mergify Bot added the queued Mergify queue entry label Oct 22, 2026
@mergify

mergify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 6 minutes 10 seconds in the queue, with no time running CI.

Reason

Pull request #1776 has been dequeued by @tignear with a dequeue command

Waiting for
  • check-success = Queue validation
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
    • check-success = @github-actions/Lint & Format
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
    • check-success = @github-actions/NAPI Build (Windows)
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
    • check-success = @github-actions/Rust Test & NAPI Build
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
    • check-success = @github-actions/JS Test (Ubuntu)
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
    • check-success = @github-actions/JS Test (Windows)
All conditions

Requeued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

queue

☑️ This pull request is already queued

@tignear

tignear commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

@mergify dequeue

@mergify mergify Bot added dequeued Mergify stopped this queue entry; investigate before retrying and removed queued Mergify queue entry labels Oct 22, 2026
@tignear tignear removed the merge-ready Request merging through Mergify after required checks label Oct 22, 2026
@tignear

tignear commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio dequeue

@mergify

mergify Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

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
@mergify mergify Bot removed the dequeued Mergify stopped this queue entry; investigate before retrying label Oct 23, 2026
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
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 23, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 23, 2026
@mergify

mergify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

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
  • check-success = Conventional Commit title
  • check-success = Queue validation
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Lint & Format
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Windows)
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Rust Test & NAPI Build
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Ubuntu)
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Windows)
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Conventional Commit title
    • check-neutral = @github-actions/Conventional Commit title
    • check-skipped = @github-actions/Conventional Commit title

@mergify
mergify Bot deleted the feature/simulator-tick-andveryl-tb-clock-next-semantics branch October 23, 2026 03:40
@mergify mergify Bot removed the queued Mergify queue entry label Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-ready Request merging through Mergify after required checks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant