Repository navigation
fix(sim)!: wake processes on value changes that are undone in the same time slot - #1764
Conversation
…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
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. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Change-Id: Ieb4eecbfe1dd50186a513da2a12cd3147ad7d428
Merge Queue Status
This pull request spent 54 minutes 42 seconds in the queue, including 52 minutes 47 seconds running CI. ReasonThe merge conditions cannot be satisfied due to failing checks
Failing checks: HintYou may have to fix your CI before adding the pull request to the queue again. Waiting for
All conditions
Requeued — the merge queue status continues in this comment ↓. |
Change-Id: I6b69b80ad0a864ffc3a07bf10c20e6f64797d78c # Conflicts: # crates/celox-frontend-core/src/symbolic/assembly.rs # crates/celox-frontend-core/src/watch.rs
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
|
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:
a = 1; a = 0;always_comb(immediate assertion,$display)a <= 1; a <= 0;always_combalways_ff:a <= 1; a <= 0;(or blocking)always_combalways_ffpulse, in a design without processesa#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.
always_combactivation group a counter (CombObserver::sensitivity_counters).RuntimeSchema::occurrence_probes).ProbeRefs, once per counter per write.RuntimeCombObserver::occurrence_counters).Batch path. A design with counted signals but no processes now stays on the batch step (
ScheduleModel::timedis!processes.is_empty()).batch_roundchecks 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::ObserverReadsresolves the reads once. A range of a signal of at most 64 bits is read as au64(with its mask plane in four-state), and only wider signals useBigUint. Groups are numbered densely, so the activation check is O(observers). The old check read every range asBigUint.Perf
callgrind instructions inside
SimulationState::step_until, native backend (cranelift matches). Each design has 64always_ffregisters, 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%.always_combimmediate assertionsBefore the merge, against 4babe90: +0.19%, +7.0% and −84%.
BigUintsnapshots. WithBigUintcounter reads this design was +50%.Validation
crates/celox/tests/sv_update_events.rs: 9 cases on the interpreter, cranelift, native and wasm backends (36 tests). They cover:always_combagain;@(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);cargo nextest runon 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.conformance/sv-tests/run.py): unchanged fromexpected.tsv.cargo clippy --workspace --all-targetswith CI's features and-D warnings, clippy ofceloxwithout default features,cargo fmt --check.Not covered:
NbaStage) are not instrumented for observers. fix(sv): count intermediate writes of combinational and flip-flop units #1726 counts them for waits.BREAKING CHANGE
New public fields:
celox_slt::CombObserver::sensitivity_counterscelox_design::RuntimeCombObserver::occurrence_counters(serde default: empty)celox_design::RuntimeSchema::occurrence_probescelox_design::schedule::ScheduleModel::probesScheduleModel::timedno longer counts counted signals.