Repository navigation
feat(sv)!: run delays, event and level waits in initial processes - #1459
Conversation
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: 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".
| 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)) |
There was a problem hiding this comment.
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 👍 / 👎.
| /// 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(_))) |
There was a problem hiding this comment.
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 👍 / 👎.
| for param in &subroutine.params { | ||
| if let Some(default) = ¶m.default { | ||
| expr_idents(default, names); | ||
| } |
There was a problem hiding this comment.
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 👍 / 👎.
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
284fddf to
ebfd107
Compare
There was a problem hiding this comment.
💡 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".
| 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()), |
There was a problem hiding this comment.
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 👍 / 👎.
| let header = if self.kernel.is_some() && !always_suspends(body) { | ||
| self.yielding_back_edge(header)? | ||
| } else { | ||
| header |
There was a problem hiding this comment.
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 |_| {}, |
There was a problem hiding this comment.
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 👍 / 👎.
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
|
Part of #1123, step 4, PR 1 of 6 (design: delays, event and level waits, and
$finishininitialprocesses). SVinitialblocks 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)andwait (condition)ininitialbodies become statements,Delay,WaitEventandWait, instead ofunsupported("procedural timing control").edgeand any change, joined byoror,.min:typ:maxdelay 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;edgegives both Rises and Falls. Counting stays assembly's existing rule.wait (cond)→wait_level, withChangesterms on the variables the condition reads.repeatcount runs a kernel loop zero times (12.7.2).Still rejected under their own names:
wait fork,wait order;eventtype and->;iff(feat(sv): support iff-qualified event controls in processes #1444), cycle delays, intra-assignment timing,disable, real delays;@*in a process;alwaysbodies (PR 2) and in subroutines (PR 5);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
timing.vtest: 29 more cases run, so 31 of the 55 now run, each on all five backends (native, Cranelift, both parallel variants, wasm; feat(sim): build timed simulations on explicit backends #1455).unknown_delays_and_conditions_count_as_zero_and_falseruns too, now that timed simulations read four-state values (feat(sim): expose four-state reads in timed simulations #1454). The remaining 24 exclusions name their actual reason:alwaysprocessesalwaysare committed with its nonblocking onesThe one fix(sim): flip-flop domains miss edges to and from z on a four-state clock #1472 case also checks process waits through x and z. Run on its own, that part gives Icarus's counts (pos 3, neg 3, any 7).
New cases:
edgewaits,min:typ:maxdelays and a 200,000-iteration loop in a process. All three pass on Icarus 13.0 and Verilator 5.052 (verify-sv-icarus/verify-sv-verilator --fresh --filter).Analyzer unit tests: every construct that stays rejected, and the IR of the lowered ones.
Scoped runs, all passing:
cargo test -p celox --features systemverilog --test systemverilog: 2713 passed;--lib: 152 passed; golden call traces unchanged, no snapshot changes;11.11--min_max_avg_delay,9.4.1--delay_control,9.4.3--event_sequence_controls). Simulated, each produces the expected output and times.expected.tsvis updated.cargo test -p celox-sv-analyzer -p celox-frontend-sv -p celox-test-suite.Lint: clippy with
-D warningsandfmt --checkare clean.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_ffaccumulators.initial forever @(posedge clk)stimulus kernelinitial forever #5 clk = ~clkBREAKING CHANGE
celox_sv_analyzer::procedural::StmtBase(andir::Stmt) has the new variantsDelay,WaitEventandWait, and the new typesEventItemBaseandEventEdge.