Skip to content

feat(sv)!: run delays, event and level waits in initial processes - #1459

Merged
mergify[bot] merged 5 commits into
masterfrom
feature/sv-process-timing
Oct 18, 2026
Merged

mergify[bot] merged 5 commits into
masterfrom
feature/sv-process-timing

Conversation

@tignear

@tignear tignear commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1123, step 4, PR 1 of 6 (design: delays, event and level waits, and $finish in initial processes). SV initial blocks with timing controls now run as process kernels on the timed runtime of #1361. No static proof machinery is involved: none of it exists on master, and none is ported from #1158.

What is lowered

Analyzer. #delay, @(event list) and wait (condition) in initial bodies become statements, Delay, WaitEvent and Wait, instead of unsupported("procedural timing control").

  • Event items keep their edge: posedge, negedge, edge and any change, joined by or or ,.
  • A min:typ:max delay uses the typical value, as Icarus and Verilator do by default.

Kernel lowering.

  • #d → inactive_delay. The amount is read as an unsigned 64-bit time, and as zero when it has an unknown bit (IEEE 1800-2023 9.4.1).
  • @(...) on whole variables → a wait site with (variable, Rises | Falls | Changes) terms; edge gives both Rises and Falls. Counting stays assembly's existing rule.
  • wait (cond) → wait_level, with Changes terms on the variables the condition reads.
  • A kernel loop that may not suspend yields every 2^16 iterations, so a process that never suspends ends with the slot budget error.
  • A negative or unknown repeat count runs a kernel loop zero times (12.7.2).

Still rejected under their own names:

Timed suite backend. It settles the current time before a read, an eval and output collection, as the old oracle harness and the reference adapters do.

Tests

Perf

SIR is byte-identical for designs without process timing. For all 360 untimed SV suite designs, a digest of the optimized SIR and runtime schema is identical between master 75fa930 and this branch. Master's digests are also stable across runs.

Callgrind on a local SV gate (not committed): 64 lanes of always_ff accumulators.

  • Method: whole program at 200,000 cycles minus at 20,000 cycles, five runs, medians.
  • Both binaries are built from the same base, master 75fa930.
runs median
(a) pure RTL, master 1135033912, 1123560873, 1135823991, 1123087641, 1015141488 1,123,560,873
(a) pure RTL, this PR 999965939, 1012244905, 1120639492, 1012541550, 1000144490 1,012,244,905
(b1) + initial forever @(posedge clk) stimulus kernel 1356244764, 1354944412, 1356020162, 1355344496, 1355282473 1,355,344,496
(b2) clock from initial forever #5 clk = ~clk 1166021639, 1167237903, 1165479782, 1166809158, 1165915312 1,166,021,639
  • (a) is equal. Both sides are bimodal, with runs at about 1.00–1.02G and about 1.12–1.14G. The medians differ only by how many runs fell in each group, and the SIR is byte-identical. I did not investigate the cause of the two groups.
  • (b1) and (b2) are reported with no target. (b1) pays the Rust timed round for a kernel that runs every cycle; step 3b fuses such kernels.

BREAKING CHANGE

celox_sv_analyzer::procedural::StmtBase (and ir::Stmt) has the new variants Delay, WaitEvent and Wait, and the new types EventItemBase and EventEdge.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 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-18T02:07:06.643916Z ebfd107 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.

@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: a2fe174f0f

ℹ️ 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".

Comment on lines +2947 to +2951
let node = coerce_node_width(&mut arena, node, Some(PROCESS_DELAY_WIDTH), signed)
.map_err(slt_error)?;
let delay = self.lower_slt(&arena, node)?;
let delay = self.zero_if_unknown(delay, original);
self.with_kernel(|kernel| kernel.inactive_delay(delay))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Scale delays to a common simulation time unit

When instantiated modules have different timeunit declarations, the raw delay operand is passed directly to the scheduler without any scope-dependent scaling or precision rounding. For example, children using timeunit 1ns and timeunit 1us will both execute #1 after one scheduler tick, even though the latter must resume 1000 times later. Because the analyzer already accepts these time declarations, valid designs silently produce incorrect timing; carry the module's time scale into lowering and convert the amount before calling inactive_delay.

Useful? React with 👍 / 👎.

Comment on lines +3136 to +3140
/// Whether every pass through `stmts` suspends the process.
fn always_suspends(stmts: &[sv::ir::Stmt]) -> bool {
stmts
.iter()
.any(|stmt| matches!(stmt, sv::ir::Stmt::Delay(_) | sv::ir::Stmt::WaitEvent(_)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve loop yields when timing controls are bypassed

A loop is classified as always suspending merely because its top-level body contains a delay or event wait, even if control flow can bypass that statement. For example, forever begin continue; #1; end takes the continue backedge without ever suspending, but always_suspends suppresses the periodic yield, so the generated kernel spins indefinitely in one invocation and bypasses the runtime time-slot budget. This needs control-flow-aware analysis, or the conservative behavior should retain the yield whenever any backedge can avoid suspension.

Useful? React with 👍 / 👎.

Comment on lines +3156 to +3159
for param in &subroutine.params {
if let Some(default) = &param.default {
expr_idents(default, names);
}

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 Traverse calls in default arguments for wait sensitivity

When a wait condition calls a function whose omitted default argument calls another function, this loop records identifiers in the default expression but never queues its callees. For example, if f(input bit x = g()) is used as wait(f()) and g() reads go, the wait site contains no dependency on go, so changing go never wakes the process. Collect nested call names from each applicable default expression as well as its direct identifiers.

Useful? React with 👍 / 👎.

@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 18, 2026
The analyzer keeps `#delay`, `@(event list)` and `wait (condition)` in
`initial` bodies as statements (`Delay`, `WaitEvent`, `Wait`) instead of
rejecting every procedural timing control. Event items keep their edge
(posedge, negedge, `edge`, any change); a `min:typ:max` delay uses its
typical value.

Fork-join, `wait fork`/`wait order`, named events and `->`, `iff`,
cycle delays, intra-assignment timing, `disable` and real delays stay
rejected under their own names; timing in `always` bodies and in
subroutines is rejected until those are lowered.

BREAKING CHANGE: `StmtBase` has the new variants `Delay`, `WaitEvent` and
`Wait`.

Change-Id: I030365a80c056b46e5768a1aa59b131031e5a970
An `initial` block with timing controls runs as a process kernel on the
timed runtime:

- `#d` suspends with an inactive delay: the amount is read as an
  unsigned 64-bit time, and as zero when it has an unknown bit.
- `@(...)` on whole variables declares a wait site whose terms are the
  variables with their edge kind; the runtime resumes the process at
  the first occurrence.
- `wait (condition)` checks the condition and waits on the variables it
  reads, including those read by the functions it calls.
- A kernel loop that may not suspend yields every 2^16 iterations, so a
  process that never suspends ends the step with the slot budget error.
- A `repeat` count that is negative or unknown runs a kernel loop zero
  times.

Event expressions other than whole variables are rejected for now.

Change-Id: Ic219e74bf093953bd4ded797946f343bc5e57dd3
Enable the 28 timing cases that initial processes now pass, give each
remaining exclusion its actual reason, and add cases for `edge` waits,
`min:typ:max` delays and long process loops, checked against Icarus and
Verilator.

The timed suite backend settles the current time before a read, an eval
and output collection, as the reference simulators' script adapters do.

Change-Id: Idabc095b34aefc665610c336d5a2f26632c8df5f
`11.11--min_max_avg_delay`, `9.4.1--delay_control` and
`9.4.3--event_sequence_controls` now elaborate. Simulated, they print
"Done" at time 200, set `a` to 1..4 at 10..40, and copy `b` into `a` at
20 after `enable` rises at 10.

Change-Id: I606c4785f3ea31ac2c640184e48ff43e50f48233
Change-Id: Ie8a00910036fd1305b3aea0c4e5b8aa2c0b1a14f
@tignear
tignear force-pushed the feature/sv-process-timing branch from 284fddf to ebfd107 Compare October 18, 2026 01:59

@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: ebfd1078fd

ℹ️ 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".

Comment on lines +2380 to +2386
condition: Box::new(sv::ir::Expr::Binary {
left: Box::new(count.clone()),
op: sv::ir::BinaryOp::Lt,
right: Box::new(sv::ir::Expr::Literal("0".to_string())),
}),
then_expr: Box::new(sv::ir::Expr::Literal("0".to_string())),
else_expr: Box::new(count.clone()),

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 Evaluate signed repeat counts only once

When a signed repeat count contains a side-effecting call and evaluates nonnegative, this synthesized mux places the original expression in both the comparison and the else arm. Expression hoisting therefore executes the call once to test < 0 and again to obtain the count; for example, repeat(next_count()) increments state twice even though SystemVerilog evaluates the repeat expression once. Store the evaluated count first, then test that stored value for negativity and unknown bits.

Useful? React with 👍 / 👎.

Comment on lines +2459 to +2462
let header = if self.kernel.is_some() && !always_suspends(body) {
self.yielding_back_edge(header)?
} else {
header

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 Allow suspending for loops whose step makes no progress

When a canonical for loop suspends on every iteration but its step leaves the control variable unchanged, the legacy progress check below still raises a runtime error after the first resume. For example, for (i = 0; i < 1; i *= 1) #1; is a valid infinite process that advances simulation time, so it neither spins in the kernel nor needs the non-progress guard. Restrict that guard to loop paths that can execute without suspension.

Useful? React with 👍 / 👎.

expr_idents(expr, names);
collect_call_names(expr, &mut pending);
},
&mut |_| {},

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 Include lvalue-index reads in wait sensitivity

When a wait condition calls a function whose result depends on a variable used only in an assignment target's dynamic index, this no-op lvalue visitor omits that variable from the wait site. For example, a function that clears scratch, assigns scratch[index] = 1, and returns scratch[0] will not cause wait(f()) to be reevaluated when index changes, leaving the process blocked even when the function would become true. Traverse lvalue select bounds and any calls they contain while collecting subroutine reads.

Useful? React with 👍 / 👎.

@mergify

mergify Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 51 minutes 27 seconds in the queue, including 47 minutes 41 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 53fdbb6 into master Oct 18, 2026
31 checks passed
@mergify
mergify Bot deleted the feature/sv-process-timing branch October 18, 2026 03:30
@mergify mergify Bot removed the queued Mergify queue entry label Oct 18, 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