Skip to content

feat(sv): support both edges of one clock or reset - #1384

Merged
mergify[bot] merged 5 commits into
masterfrom
feat/sv-both-clock-edges
Oct 17, 2026
Merged

mergify[bot] merged 5 commits into
masterfrom
feat/sv-both-clock-edges

Conversation

@tignear

@tignear tignear commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Closes #443. Closes #471.

The SystemVerilog frontend rejected a signal sensed at both edges in different always_ff processes, a reset sensed at both edges, and a signal used as a clock in one process and an asynchronous reset in another. It now accepts all of them.

How

A variable carries one domain kind, so lower_ff_processes keeps one edge and role on the signal itself. The order is fixed: rising clock, falling clock, active-high reset, active-low reset. Every other combination is sensed on a hidden 1-bit copy (clk@negedge, rst@reset_high, …) driven by copy = signal. Since #1373, a whole-variable copy sensed at the opposite edge is cut from its source's domain and becomes a derived clock, which fires at the signal's other edge.

  • @ cannot appear in an SystemVerilog identifier, and the copy is not module-scoped. It stays out of signal(), named signals, the hierarchy, VCD, VPI and the NAPI layout.
  • named_events() listed every event address. It now lists only events that a path names (fix(sim): list only named events).
  • Because the order is fixed, a clock port stays in its parent's rising domain whatever the process order.

Limitations

  • On the event-based Simulator, tick(clk) is the rising edge only, so there is no way to drive a falling edge until the explicit edge API lands. Processes on the falling edge run on the timed Simulation. On the Simulator they run only where a derived clock that a tick reaches drives them. A follow-up after the edge API adds Simulator tests and shared-suite cases that drive the falling edge directly.
  • @(posedge clk or negedge clk) inside one process is still rejected; it needs edge-typed triggers.
  • Four-state edges of a clock driven by a register or by logic are judged on the value bit only (1→x, z→0, 0→z and x→1 do not fire, contrary to IEEE 1800-2023 Table 9-2). This predates this PR; master behaves the same, and it will be fixed separately.

Tests

  • crates/celox/tests/both_clock_edges.rs (timed Simulation):
    • both edges on one clock, in both source orders, at O0/O1/O2, two- and four-state
    • a child clock port
    • edges reached through assign copies
    • a reset at both edges
    • a reset that is also a clock
    • x/z transitions
    • the copy staying hidden
  • Shared suite: 3 cases in sv/cases/procedural.vtest, 0 mismatches against Verilator and Icarus.
  • review_regressions.rs: the rejection cases are replaced by a run of the accepted designs.
  • cargo nextest run --workspace --features celox/systemverilog: 13818 passed. fmt and clippy are clean.

Performance

The before and after builds were run alternately, pinned with taskset, on a noisy machine (ms).

bench before after
simulator_tick_x10000 (Veryl) 1.65 1.77
tick, gated clock 3.25 3.48
tick, divided clock 3.10 3.11
simulation_step_x20000 4.15 4.22
SV posedge only 9.96 9.69
SV hand-written assign c = clk + negedge c 17.12 16.35
SV posedge clk + negedge clk rejected 16.17

A design that senses each signal at one edge lowers exactly as before. The Veryl benches do not reach the changed code, so their differences are noise. A design that uses both edges costs the same as the hand-written copy: only the derived falling-edge domain pays.

An event domain whose variable no path names, such as a hidden copy of a
clock, has no name to list in named_events, as named_signals, the
hierarchy, and VCD descriptions already omit such variables.
A variable carries one domain kind, so always_ff processes sensing one
signal at both edges, or as a clock and as an asynchronous reset, were
rejected. The frontend now senses the signal on itself at one kind
(rising clock first) and at every other kind on a hidden one-bit
whole-variable copy, which clock-domain unification keeps in the signal's
domain when the edges agree and otherwise runs as a clock derived from
the signal. Designs that sense one kind per signal are unchanged.

Closes #443. Closes #471.
Both edges of a divided clock, of a child clock port, and one register
as an asynchronous reset at both edges and as a clock at both edges.
Verified against Verilator and Icarus with no mismatches.
Simulation::step of counters at the rising edge only, half at each edge
of one clock, and half at the falling edge of a whole copy of the clock.
@chatgpt-codex-connector

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 ⚠️ Failed 2026-10-16T22:55:34.786814Z 346fa15 PR opened
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 16, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 17, 2026
@mergify

mergify Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 39 minutes 53 seconds in the queue, including 35 minutes 52 seconds 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 merged commit f48e9c6 into master Oct 17, 2026
21 checks passed
@mergify
mergify Bot deleted the feat/sv-both-clock-edges branch October 17, 2026 00:48
@mergify mergify Bot removed the queued Mergify queue entry label Oct 17, 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.

feat(sv): represent reset polarity per trigger feat(sv): support both clock edges of one signal

1 participant