Skip to content

fix(sim)!: wake processes on value changes that are undone in the same time slot - #1764

Merged
mergify[bot] merged 3 commits into
masterfrom
fix/sim-update-events
Oct 23, 2026
Merged

mergify[bot] merged 3 commits into
masterfrom
fix/sim-update-events

Conversation

@tignear

@tignear tignear commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

IEEE 1800-2023 4.3, 4.5 and 10.4.2 make every change of a variable's value an update event, which schedules the processes sensitive to it, even when a later write in the same time slot restores the old value. Celox compared values only at the end of an evaluation, so it missed these changes in four cases:

Writer Reader Before Now
process: a = 1; a = 0; always_comb (immediate assertion, $display) not run again runs again
process: a <= 1; a <= 0; always_comb not run again runs again
always_ff: a <= 1; a <= 0; (or blocking) always_comb not run again runs again
the same always_ff pulse, in a design without processes another FF domain clocked by a domain does not fire fires

#1726 has since fixed the same pulse for @(a) and @(posedge a) waiters, with pending slots in designs that have a wait. This branch merges master and keeps that mechanism for those signals. What remains here is the always_comb observers ($display, immediate assertions), which #1726 leaves symbolic, and counted signals in designs without waits.

Icarus 13.0 gives the same results on an equivalent design. A glitch between two combinational processes is still allowed, since that ordering is legal.

Occurrence counters.

  • The SV frontend gives each sensitivity atom of an always_comb activation group a counter (CombObserver::sensitivity_counters).
  • Assembly turns these, and the existing counted signals, into probes (RuntimeSchema::occurrence_probes).
  • An FF evaluation unit that stores to a probed signal more than once bumps its counter at each store that changes the value. So does one that stores a counted signal more than once, when the signal has no pending slots of fix(sv): count intermediate writes of combinational and flip-flop units #1726 (a design without waits).
  • Kernel blocking writes and published nonblocking updates bump the counters through ProbeRefs, once per counter per write.
  • An observer is active when its values or its counters differ from the last snapshot (RuntimeCombObserver::occurrence_counters).

Batch path. A design with counted signals but no processes now stays on the batch step (ScheduleModel::timed is !processes.is_empty()). batch_round checks the counters after each evaluation and adds their domains to the approved edges. The first version moved such designs to the timed path, which cost 17.8% on the divided-clock design below; this costs 7.0%.

Observer snapshots. comb_activation::ObserverReads resolves the reads once. A range of a signal of at most 64 bits is read as a u64 (with its mask plane in four-state), and only wider signals use BigUint. Groups are numbered densely, so the activation check is O(observers). The old check read every range as BigUint.

Perf

callgrind instructions inside SimulationState::step_until, native backend (cranelift matches). Each design has 64 always_ff registers, each writing a default and then overriding it. Base is master a5aa1f2, built in another worktree, which alone moves the count by about 0.2%.

design base this PR change
plain 117.02M 117.32M +0.26%
divider: an FF writes a derived clock twice per edge, a second FF counts on it 156.85M 168.78M +7.6%
assert: plus 64 always_comb immediate assertions 321.57M 51.03M −84%

Before the merge, against 4babe90: +0.19%, +7.0% and −84%.

  • plain: the JIT code's cost was identical (9,100,455 in both) before the merge. The difference comes from inlining in the Rust runtime. A const-generic split and an out-of-line counter check both measured worse (+0.67%, +0.33%).
  • divider: the counter check that correctness requires. Setting trigger bits from the JIT would remove most of it, but that is a larger change.
  • assert: the word reads replace BigUint snapshots. With BigUint counter reads this design was +50%.

Validation

  • New crates/celox/tests/sv_update_events.rs: 9 cases on the interpreter, cranelift, native and wasm backends (36 tests). They cover:
    • blocking, process-NBA and FF-NBA restores running always_comb again;
    • assertions reporting again;
    • FF NBA and blocking pulses waking @(a) and @(posedge a) (these and the next two also pass on master since fix(sv): count intermediate writes of combinational and flip-flop units #1726);
    • no event when the value is kept;
    • exclusive branches as one event;
    • an FF pulse firing a domain in a design without processes.
  • Cross-checked the expected values against Icarus 13.0.
  • cargo nextest run on celox, celox-frontend-{core,sv,veryl}, celox-runtime, celox-design, celox-slt, celox-test-suite, celox-vpi and celox-napi with CI's features (celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus), after merging master a5aa1f2: 14,386 passed, 330 skipped. This includes the timing cases of fix(sv): count intermediate writes of combinational and flip-flop units #1726.
  • sv-tests conformance (conformance/sv-tests/run.py): unchanged from expected.tsv.
  • cargo clippy --workspace --all-targets with CI's features and -D warnings, clippy of celox without default features, cargo fmt --check.

Not covered:

BREAKING CHANGE

New public fields:

  • celox_slt::CombObserver::sensitivity_counters
  • celox_design::RuntimeCombObserver::occurrence_counters (serde default: empty)
  • celox_design::RuntimeSchema::occurrence_probes
  • celox_design::schedule::ScheduleModel::probes

ScheduleModel::timed no longer counts counted signals.

…e time slot

## Summary

IEEE 1800-2023 4.3, 4.5 and 10.4.2 make every change of a variable's value an update event, which schedules the processes sensitive to it, even when a later write in the same time slot restores the old value. Celox compared values only at the end of an evaluation, so it missed these changes in four cases:

| Writer | Reader | Before | Now |
|---|---|---|---|
| process: `a = 1; a = 0;` | `always_comb` (immediate assertion, `$display`) | not run again | runs again |
| process: `a <= 1; a <= 0;` | `always_comb` | not run again | runs again |
| `always_ff`: `a <= 1; a <= 0;` (or blocking) | `@(a)`, `@(posedge a)`, `always_comb` | no event | event |
| the same `always_ff` pulse, in a design without processes | another FF domain clocked by `a` | domain does not fire | fires |

Icarus 13.0 gives the same results on an equivalent design. A glitch between two combinational processes is still allowed, since that ordering is legal.

**Occurrence counters.**
- The SV frontend gives each sensitivity atom of an `always_comb` activation group a counter (`CombObserver::sensitivity_counters`).
- Assembly turns these, and the existing counted signals, into probes (`RuntimeSchema::occurrence_probes`).
- An FF evaluation unit that stores to a probed or counted signal more than once bumps its counter at each store that changes the value.
- Kernel blocking writes and published nonblocking updates bump the counters through `ProbeRefs`, once per counter per write.
- An observer is active when its values or its counters differ from the last snapshot (`RuntimeCombObserver::occurrence_counters`).

**Batch path.** A design with counted signals but no processes now stays on the batch step (`ScheduleModel::timed` is `!processes.is_empty()`). `batch_round` checks the counters after each evaluation and adds their domains to the approved edges. The first version moved such designs to the timed path, which cost 17.8% on the divided-clock design below; this costs 7.0%.

**Observer snapshots.** `comb_activation::ObserverReads` resolves the reads once. A range of a signal of at most 64 bits is read as a `u64` (with its mask plane in four-state), and only wider signals use `BigUint`. Groups are numbered densely, so the activation check is O(observers). The old check read every range as `BigUint`.

## Perf

callgrind instructions inside `SimulationState::step_until`, native backend (cranelift matches). Each design has 64 `always_ff` registers, each writing a default and then overriding it.

| design | base | this PR | change |
|---|---|---|---|
| plain | 115.60M | 115.82M | +0.19% |
| divider: an FF writes a derived clock twice per edge, a second FF counts on it | 155.24M | 166.06M | +7.0% |
| assert: plus 64 `always_comb` immediate assertions | 319.35M | 51.24M | −84% |

- **plain:** the JIT code's cost is identical (9,100,455 in both). The difference comes from inlining in the Rust runtime. A const-generic split and an out-of-line counter check both measured worse (+0.67%, +0.33%).
- **divider:** the counter check that correctness requires. Setting trigger bits from the JIT would remove most of it, but that is a larger change.
- **assert:** the word reads replace `BigUint` snapshots. With `BigUint` counter reads this design was +50%.

## Validation

- New `crates/celox/tests/sv_update_events.rs`: 9 cases on the interpreter, cranelift, native and wasm backends (36 tests). They cover:
  - blocking, process-NBA and FF-NBA restores running `always_comb` again;
  - assertions reporting again;
  - FF NBA and blocking pulses waking `@(a)` and `@(posedge a)`;
  - no event when the value is kept;
  - exclusive branches as one event;
  - an FF pulse firing a domain in a design without processes.
- Cross-checked the expected values against Icarus 13.0.
- `cargo nextest run` on celox, celox-frontend-{core,sv,veryl}, celox-runtime, celox-design, celox-slt, celox-test-suite, celox-vpi and celox-napi with CI's features (`celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus`): 14,020 passed, 330 skipped.
- sv-tests conformance (`conformance/sv-tests/run.py`): unchanged from `expected.tsv`.
- `cargo clippy --workspace --all-targets` with CI's features and `-D warnings`, `cargo fmt --check`.

Not covered:
- Veryl observers get no sensitivity counters.
- Targets with both blocking and nonblocking writers (`NbaStage`) are not instrumented.
- Host writes do not bump counters.

## BREAKING CHANGE

New public fields:
- `celox_slt::CombObserver::sensitivity_counters`
- `celox_design::RuntimeCombObserver::occurrence_counters` (serde default: empty)
- `celox_design::RuntimeSchema::occurrence_probes`
- `celox_design::schedule::ScheduleModel::probes`

`ScheduleModel::timed` no longer counts counted signals.

Change-Id: I3c9de5c5bc7e26c31765c9a6d45a9e04287eabaf
@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-22T17:00:37.534518Z
We couldn’t complete this review. Comment @codex review to try again.
665d523 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.

Change-Id: Ieb4eecbfe1dd50186a513da2a12cd3147ad7d428
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 22, 2026
@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

  • ✅ Entered queue — 2026-10-22 18:15 UTC · Rule: changes · triggered by rule Queue explicitly requested merges
  • ❌ Checks failed · on draft merge queue: checking #1764 on master (d5a1eff) #1768
  • 🚫 Left the queue — 2026-10-22 19:10 UTC · at 7fa8749dfe77265b546501e6c1e5422b5d78f150

This pull request spent 54 minutes 42 seconds in the queue, including 52 minutes 47 seconds running CI.

Reason

The merge conditions cannot be satisfied due to failing checks

  • Queue validation

Failing checks:

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for
  • check-success = Queue validation
All conditions
  • check-success = Queue validation
  • check-success = Conventional Commit title
  • 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

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

@mergify mergify Bot added dequeued Mergify stopped this queue entry; investigate before retrying and removed queued Mergify queue entry labels Oct 22, 2026
Change-Id: I6b69b80ad0a864ffc3a07bf10c20e6f64797d78c

# Conflicts:
#	crates/celox-frontend-core/src/symbolic/assembly.rs
#	crates/celox-frontend-core/src/watch.rs
@mergify mergify Bot added queued Mergify queue entry and removed dequeued Mergify stopped this queue entry; investigate before retrying labels Oct 23, 2026
@mergify

mergify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 1 hour 26 minutes in the queue, including 1 hour 23 minutes 28 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 a470c9e into master Oct 23, 2026
32 checks passed
@mergify
mergify Bot deleted the fix/sim-update-events branch October 23, 2026 10:01
@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