Repository navigation
fix(sim): judge four-state edges of internally driven clocks by IEEE 1800 Table 9-2 - #1414
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. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Merge Queue Status
This pull request spent 3 minutes 49 seconds in the queue, with no time running CI. ReasonThe pull request conflicts with the base branch HintYou should update or rebase your pull request. If you want to requeue this pull request, you can post a Requeued — the merge queue status continues in this comment ↓. |
1db09d9 to
5102458
Compare
3ed0159 to
66c9b62
Compare
Merge Queue Status
This pull request spent 9 minutes 30 seconds in the queue, with no time running CI. ReasonThe pull request conflicts with the base branch The pull request was held in the queue, conflicting with at least one of 2 pull requests ahead of it. The conflict became a base branch one after #1402 merged. Automatic conflict resolution can merge a conflict like this one instead of stopping on it, but only in a queue using the HintYou should update or rebase your pull request. If you want to requeue this pull request, you can post a Requeued — the merge queue status continues in this comment ↓. |
Edges of clocks and asynchronous resets driven inside a four-state design were judged on the value bit alone, so 1 -> x, z -> 0, 0 -> z and x -> 1 did not fire, while x -> 0, 0 -> x and z -> 1 did only by the accident of the x and z encodings. IEEE 1800-2023 9.4.2, Table 9-2 makes a posedge any change that leaves 0 or reaches 1 and a negedge any change that leaves 1 or reaches 0, with no edge between x and z. The edge rules of celox_design::edges now take edge levels (0, 1, x, z) and follow the table; the VPI layer's write edges use the same rule. The timed scheduler keeps an unknown bit next to each event's high bit and judges scheduled, process-driven, published, cascaded and gated edges from both. Derived tick plans keep the same level in their round flags, and the settled gate path moves an x or z lever to its inactive level before the edge. Explicit edges read the moved signal's level with its mask, so a gated clock is judged from the lever's real level, x or z included, rather than from the level opposite to the edge's. Checkpoints and state files carry the unknown baselines; a state file records them under a new flag only when there are any, so other files keep their encoding. The edge loops are instantiated per state mode and the four-state paths stay out of line: two-state designs read only value bits, with the code and inlining they had before, and four-state designs read the mask only of edge-sensed signals.
Shared Veryl and SystemVerilog cases walk a register clock, a clock computed from a register and register-driven asynchronous resets through all twelve changes between 0, 1, x and z, and tick a gated clock from x and z levels. Icarus agrees with every case; Verilator runs the two-state variant only. Veryl's simulator misses edges through x and z, so its reference runs are ignored.
A four-state clock that starts at x now counts its first rise to 1, and rises from 0 to x or z count too (IEEE 1800-2023 Table 9-2). Two-state clocks read only their value bit as before.
Add four-state variants of the derived-clock tick benchmarks and of Simulation::step, and a Simulation::step benchmark with a register-driven divider, so the cost of four-state edge detection is tracked. Existing benchmark names and designs are unchanged.
In four-state simulation a reset that rises from its initial unknown level gives a posedge but no negedge, so a register on its negedge keeps its initial value until the first clock edge.
Posedges and negedges of plain events, gated clocks and register clocks that start at x or z follow IEEE 1800-2023 Table 9-2 on every backend and through the native addon: a gated clock is judged from the clock's real level, so `x & x` rising to `1 & x` is no edge.
The WASM edge runner read event levels from the value bit and moved a lever from x or z as if from the opposite level, so a gated clock rising from `x & x` to `1 & x` fired. Levels are now 0, 1, x and z, with the edge rules of IEEE 1800-2023 Table 9-2, and a lever is moved to its real level before the edge. Edge plans say per signal whether it keeps an unknown mask.
7005b8b to
147bd20
Compare
Merge Queue Status
This pull request spent 43 minutes 26 seconds in the queue, including 24 minutes 17 seconds running CI. Required conditions to merge
|
Change-Id: I7f47a736828bf84dec906eca161314b39fcd1760
Bug
In four-state designs, edges of clocks and asynchronous resets that the design drives itself (a register, combinational logic, a process) were judged on the value bit only. So
1 -> x,z -> 0,0 -> zandx -> 1never fired.x -> 0,0 -> xandz -> 1fired only because of how x (value 1) and z (value 0) are encoded. The same applied to a clock or reset that starts at x/z and is first driven throughSimulation::schedule.IEEE 1800-2023 9.4.2, Table 9-2:
0->1,0->x,0->z,x->1,z->11->0,1->x,1->z,x->0,z->0Process event-control waits (
timing.rs) andcelox-vpi(external writes) already followed the table.Fix
celox_design::edges, introduced by refactor(runtime)!: derive the schedule model once per program #1417):scheduled_edgeandsettled_edgenow take edge levels (0, 1, x, z) and follow Table 9-2, with a unit test of every cell. The VPI layer's write-edge check now usessettled_edgeinstead of its own copy of the table.celox-runtime/src/simulation/after refactor(runtime)!: split the simulation scheduler into modules #1408 and refactor(runtime)!: derive the schedule model once per program #1417:batch.rs,edges.rs,round.rs,persist.rs,mod.rs): each event's edge baseline is now an edge level: 0, 1, or unknown plus the value bit. The baseline is kept in two bitsets, high and unknown.stable_edgefollows Table 9-2. This covers every place the scheduler compares levels: scheduled values, process-driven transitions, publication pulses, cascaded and gated (clk & en) clocks, host-write detection, and both the batch round and the process round.derived_tick.rs): the round flags keep the same level. The settled gate path moves an x or z lever to its inactive level before the edge.FOUR_STATEconst generic), so two-state designs run value-bit comparisons only. The four-state branches are out of line, so two-state callers keep their previous size and inlining. Four-state designs read the mask plane of edge-sensed signals only.celox-runtime/src/edge.rs): the level a moved signal had is its edge level, mask included. Plain events already treated an x or z start as "not at the level". Gated clocks were judged from the level opposite to the edge's, sox & xrising to1 & xfired; they are now judged from the lever's real level. The settled gate path moves an x or z lever back to that level before the edge.packages/celox/src/wasm-edges.ts, also used by the playground): levels are 0, 1, x and z with the Table 9-2 rules, and levers move to their real level. Edge plans now say per signal whether it has a mask (fourState).waitForCyclescounts rising edges through x and z: a clock starting at x counts its first rise.Tests
four_state.vtest): a register clock, a clock computed from a register (e ? a & b : 'z), and register-driven async resets of both polarities. Each walks all 12 changes between 0/1/x/z. They run on every backend throughall_backends!(native, parallel, cranelift, wasm, interp, SV emission).edgesgroup): the same three designs, a gated clock ticked from x/z levels, and a two-state variant.Simulationtests on every backend (interp, cranelift, wasm, tiered, native) incrates/celox/src/simulation.rs:@(posedge c)/@(negedge c)waits on a register clock that walks through x/z, checked alongside flip-flop domains on the same clockposedge/negedge/cycle/edgesof four-state clocks starting at x or z, on plain events, gated clocks and register clocks: on every backend (tests/four_state_explicit_edges.rs), through the native addon (simulator-edges-addon.test.ts), the WASM edge runner (wasm-edges.test.ts) and the playground's WASM build (playground-simulator-wasm.test.ts).both_clock_edges::a_reset_at_both_edges: in four-state,rstrises from its initial unknown level. That is a posedge but no negedge, solowkeeps its initial value until the first clock edge, matching Icarus. The test previously expected the negedge-reset register to run.packages/celox: newwaitForCyclesx->1 test.Performance (callgrind, measured loop of
benches/overhead.rs)Instruction counts of one benchmark iteration (10,000 ticks or 20,000 steps), native backend, Rust 1.99.1 from
nix develop. The before build uses the runtime,celox_design::edgesand the edge plans fromorigin/masterafter #1391 and #1431. Wall-clock runs were not usable on the shared host: a load average of 20-50 moved even unchanged code by ±30%.Four-state cost: these numbers were measured before the rebases onto #1361, #1408, #1417, #1391 and #1431; the two-state numbers above were remeasured after them.
The four-state cost is the mask read on edge-sensed signals. The
_4statevariants andsimulation_step_dividedare new inbenches/overhead.rs; existing benchmark names and designs are unchanged.Validation
cargo fmt --all -- --checkcargo clippy --locked -p celox-test-suite -p celox … --all-targets --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus --no-deps, plus celox-runtimeRUSTDOCFLAGS=-D warnings cargo doc -p celox-runtime -p celox-design -p celox --no-depscargo nextest run -p celox-design -p celox-runtime -p celox -p celox-test-suite -p celox-vpi -p celox-napi -p lydite-celox --features celox/systemverilogwith Rust 1.99.1: 11,668 passed. This includes refactor(runtime)!: split the simulation scheduler into modules #1408's golden executor call-trace tests, whose traces are unchanged.packages/celox: vitest (415 tests);pnpm run typecheckandpnpm run lintfor packages/celox and the playground; the playground'stest:wasmon the WASI build (16 tests)