Repository navigation
feat(sim): add explicit clock edges to the simulator - #1391
Merged
Merged
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. |
Contributor
|
Queued — the merge queue status continues in this comment ↓. |
tignear
force-pushed
the
feat/simulator-edge-api
branch
from
October 17, 2026 04:21
439b3ae to
193197f
Compare
tignear
force-pushed
the
feat/simulator-edge-api
branch
from
October 17, 2026 20:49
193197f to
2679010
Compare
Simulator::edge, posedge, negedge, active_edge, inactive_edge, cycle and the coincident edges move an event signal's level and run every domain sensitive to the transition, as a timed step does: the event's own domain on its active edge, gated clocks judged from the pre-edge state, gates the commit moves and state-derived cascades. tick keeps its behaviour: the active edge without moving the signal. Change-Id: I21a0510f1955ce1a3f9f047c9f55c4f1344b3e81
An edge that moves an event signal without running a domain marked combinational logic stale, so a cycle's falling edge forced a full settle before the next rising edge even when only flip-flops see the clock. Report such moves as Stored when combinational logic does not read the signal and keep the pending state as it was, in the simulator, the N-API handle (which now takes the caller's dirty flag) and the WASM edge runner.
An edge of an event without derived domains now moves the signal and runs the event's domain through tick itself. The bench binary's generic edge path ran the same flip-flop kernel about 1.8 times slower per cycle than tick did, with equal instruction counts; going through tick keeps cycle within a few percent of tick and records tick timing diagnostics for edges too.
CI builds the N-API addon for wasm32-wasip1-threads; the dev shell's toolchain only had wasm32-unknown-unknown, so the same build could not run locally. With the target and WASI SDK clang as CC_wasm32_wasip1_threads, the CI napi-wasm job runs as is.
The wasm32 handle listed only events with flip-flops of their own, so a clock that only drives a gated clock was no event in the browser and its edges never reached the gated domain. Events, their kernels and the edge plans now follow the native event order (celox::event_addresses), and kernels are found through the canonical event.
The runner has no other imports, so browser hosts that instantiate the kernels themselves can use it without the addon loader. cachedEdgeKernels holds the kernel lookup both hosts need, and the runner and bridge accept events without a kernel of their own.
…unner The playground's simulators now expose posedge, negedge, activeEdge, inactiveEdge, cycle and edges, and their ticks and timed steps fire derived and gated clocks as the native simulator does: the worker passes the edge plans and split-phase kernels, and the runtime moved from main.ts into playground-simulator.ts around the package's WASM edge runner. Monaco now gets every declaration file of the package, so the new methods and subpaths resolve in testbenches.
… $finish Since the timed runtime wakes processes on host writes (#1361), an edge's move of its clock signal is such a write: it now goes through the host watch, as IOContext writes do, so waits and counters a timed simulation keeps see it. The edge runtime takes the write as a callback (SignalWrite; set_level for hosts that observe nothing). Edges on a simulation a $finish froze change nothing, and a $finish during an edge is left to the host, as a tick does. Change-Id: If100c01610ac1c9d5169c0e64d37f7cc62b08390
After the rebase onto the process-waking runtime, a cycle on the plain overhead bench cost 1.75 ticks with the same instructions as before: loads of host tables in the edge path right after the flip-flop kernel waited behind the kernel's stores (4 KiB aliasing; which loads alias depends on the heap layout). cycle() now reads everything before the domain runs, then stores the inactive level, and an inactive edge of a known-polarity event stores its level without reading it first, as it can run nothing. cycle is 1.09 ticks again on the bench. Change-Id: I672bb62499cbecdc7fce913ad48ff7d08053a637
tignear
force-pushed
the
feat/simulator-edge-api
branch
from
October 17, 2026 21:33
2679010 to
b32c10b
Compare
Contributor
Merge Queue Status
This pull request spent 52 minutes 18 seconds in the queue, including 50 minutes 37 seconds running CI. Required conditions to merge
|
39 of 70 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Simulator::tick(event)runs only the event's active edge and never moves the signal. There was no way to drive a falling edge, a cycle, or several coincident edges on the event-based simulator. This adds explicit edges in Rust, N-API, TypeScript and the browser/WASI bridge.API
Simulator::posedge,negedge,edge(event, Edge),active_edge,inactive_edge,cycle(active then inactive edge), andedges(&[(event, Edge)])for coincident edges.active_edgefollows the event'sDomainKind. Veryl's abstractclockfollows the build'sclock_type.tickkeeps its current behavior: the active edge, without moving the signal. Making it an alias ofactive_edgewould leave clocks and resets at their active level, which would be a breaking change.edges(ids, rising, dirty?)andactiveEdgeIsRising(id).posedge,negedge,activeEdge,inactiveEdge,cycleandedgesonSimulator, and theClockEdgetype.edgePlansJson()) with split-phase kernels (eventPhaseWasmBytes(name, phase)). Derived clocks therefore also work in the browser/WASI runtime.@celox-sim/celox/wasm-edges. The playground now uses it:Simulatorhasposedge,negedge,activeEdge,inactiveEdge,cycleandedges;Simulationsteps fire derived and gated clocks as the native simulator does;always_ffof its own) was no event in the browser.Performance
tickpath. The inactive edge of a clock that combinational logic does not read leaves combinational logic settled, so the next active edge does not settle again.cycle()reads everything it needs before the domain runs, then stores the inactive level. An inactive edge of a known-polarity event stores its level without reading it, since it can run nothing.taskset, tick and cycle paired per round, 6 rounds, load 1–2.5:clk & en)clk, so its falling edge really has to evaluate the gate.posedge()/negedge()calls right after a kernel can still hit the aliasing stall in some builds (up to about +0.5 tick).cycle()avoids it.Runtime events (#1361)
IOContextwrites do, so a timed simulation's waits and counters see it.SignalWrite;set_levelfor hosts that observe nothing).$finishfroze change nothing. A$finishduring an edge is left to the host, as a tick does.Phase::Activedid, and an inactive edge uses the inactive level.Tests
crates/celox/tests/edge_api.rscovers polarity, coincident edges, derived and gated clocks, X levels, and the dirty flag after an inactive edge.~clkcase on every Celox backend.simulator-edges-addon.test.ts,wasm-edges.test.ts).playground-simulator-wasm.test.tsdrives the playground runtime over modules from the wasm32 addon (expected counts are the native simulator's), andplayground-dts.test.tschecks the Monaco declarations against the builtdist.cargo nextest run --workspace --features celox/systemverilog: 13811 passed. CI's clippy (--all-targets) and fmt are clean.pnpm test:jspasses (celox: 410 tests), and typecheck and biome are clean.--features celox/systemverilog: 11850 tests;cargo fmt --check;pnpm test:js,pnpm typecheckandpnpm lint;test:wasm(15 tests).--features celox/systemverilog: 11778 tests;cargo fmt --check;pnpm test:js,pnpm typecheckandpnpm lint;test:wasm(15 tests).Not covered
wasm32-wasip1-threadstarget; the flake adds it.zstd-sysneeds WASI SDK clang asCC_wasm32_wasip1_threads, as CI sets it.test:wasm) passes locally.Follow-up: #1384 (both edges of one SystemVerilog clock) gets
Simulatortests that drive the falling edge directly once this lands.