Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7b52556
feat(runtime)!: wake processes on events in front of the batch step
tignear Oct 16, 2026
71f103d
feat(js): bound runUntil steps in the Rust scheduler
tignear Oct 16, 2026
3390969
docs: describe the process phase, waits and counted signals
tignear Oct 16, 2026
2a89e30
fix(runtime): observe every update of a waited or event signal
tignear Oct 16, 2026
ba54de9
fix(runtime): mark edges across all publications of a slot
tignear Oct 16, 2026
0108a9a
fix(runtime): see every write of an event signal within a slot
tignear Oct 16, 2026
005d31b
perf(runtime): run the batch step unchanged without processes
tignear Oct 16, 2026
657b51a
fix(frontend): keep signals that only a wait watches through DSE
tignear Oct 16, 2026
c58b416
fix(runtime): keep nonblocking pulses after a single-domain evaluation
tignear Oct 16, 2026
35e4b69
fix(runtime): compare event signals across the waves of a slot
tignear Oct 16, 2026
6480eea
fix(runtime): bound zero-time process loops within a slot
tignear Oct 16, 2026
9d037a0
fix(js): report DUT input writes to the timed scheduler
tignear Oct 16, 2026
30bd77f
fix(frontend): gate SDK combinational processes on the bits they read
tignear Oct 16, 2026
9268d54
perf(backend): read triggered bits a word at a time
tignear Oct 16, 2026
1dec92c
fix(sim): export the process records of state files
tignear Oct 16, 2026
93aa888
fix(runtime): keep derived-clock edges until their domain evaluates
tignear Oct 16, 2026
a6594fa
fix(runtime): let host writes settle and advance in one step
tignear Oct 16, 2026
da88fc6
fix(runtime): see writes a counter misses in waits on counted signals
tignear Oct 16, 2026
76e26ff
fix(runtime): show waits the values between waves of flip-flop domains
tignear Oct 16, 2026
32fb4a8
fix(frontend): yield in SDK loops that may not suspend
tignear Oct 16, 2026
4695d6a
fix(frontend): keep ports out of single-site nonblocking flags
tignear Oct 16, 2026
a740353
fix(js): settle host writes in a bounded run at the current time
tignear Oct 16, 2026
da37d93
fix(runtime): write state files without process state as version 1
tignear Oct 16, 2026
35619d7
fix(frontend): yield every 2^16 iterations of SDK loops that may not …
tignear Oct 16, 2026
c60f8d5
fix(runtime): keep the value baseline of counted waits in state files
tignear Oct 16, 2026
6c3d395
fix(runtime): check step_until's limit before every pass
tignear Oct 16, 2026
5c19415
ci: select PR checks from the merge base, not the base tip
tignear Oct 17, 2026
96af1fd
Merge of #1361
mergify[bot] Oct 17, 2026
f50cbd1
Merge of #1393
mergify[bot] Oct 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 226 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,31 @@ pub struct RuntimeErrorInfo<A> {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ProcessStatus {
/// Resume after the number of time units stored in [`ProcessSlots::delay`].
/// A zero delay resumes at the same time after the nonblocking
/// assignments of that time are published.
Delay,
/// The process ran to the end of its body.
Done,
/// The process requested the end of the simulation.
Finish,
/// Like [`Self::Delay`], but a zero delay resumes in the inactive region
/// of the same time, before nonblocking assignments are published (IEEE
/// 1800-2023 4.4.2.3).
InactiveDelay,
/// The process suspended at an event or level wait. The delay slot holds
/// the index of its [`WaitSite`]. The runtime resumes the process when a
/// counter of that site moves; the kernel then checks the wait itself.
Wait,
/// The process was resumed at a wait whose condition does not hold. It
/// ran no statement and waits at the same site.
Pending,
/// The process staged one nonblocking assignment. The delay slot holds
/// the index of its [`NbaSite`]. The runtime queues the staged value and
/// resumes the process at once.
Nba,
/// The process returned so the runtime can charge its time-slot budget.
/// It resumes at once.
Yield,
}

impl ProcessStatus {
Expand All @@ -231,6 +251,11 @@ impl ProcessStatus {
Self::Delay => 1,
Self::Done => 2,
Self::Finish => 3,
Self::InactiveDelay => 4,
Self::Wait => 5,
Self::Pending => 6,
Self::Nba => 7,
Self::Yield => 8,
}
}

Expand All @@ -239,6 +264,11 @@ impl ProcessStatus {
1 => Some(Self::Delay),
2 => Some(Self::Done),
3 => Some(Self::Finish),
4 => Some(Self::InactiveDelay),
5 => Some(Self::Wait),
6 => Some(Self::Pending),
7 => Some(Self::Nba),
8 => Some(Self::Yield),
_ => None,
}
}
Expand Down Expand Up @@ -277,6 +307,191 @@ pub const PROCESS_STATUS_WIDTH: usize = 8;
/// Width of [`ProcessSlots::delay`].
pub const PROCESS_DELAY_WIDTH: usize = 64;

/// Width of every occurrence counter of an [`EventWatch`]. Counters wrap;
/// only their inequality is meaningful.
pub const EVENT_COUNTER_WIDTH: usize = 32;

/// The occurrences an event counter counts on its watched signal (IEEE
/// 1800-2023 9.4.2, Table 9-2).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub enum CounterKind {
/// Any change of the value, including the unknown bits.
Changes,
/// A positive edge of the least significant bit.
Rises,
/// A negative edge of the least significant bit.
Falls,
}

impl CounterKind {
pub const ALL: [Self; 3] = [Self::Changes, Self::Rises, Self::Falls];

/// The counter kind that wakes an event domain of `kind`.
pub const fn for_domain(kind: DomainKind) -> Self {
match kind {
DomainKind::ClockPosedge | DomainKind::ResetAsyncHigh => Self::Rises,
DomainKind::ClockNegedge | DomainKind::ResetAsyncLow => Self::Falls,
DomainKind::Other => Self::Changes,
}
}
}

/// A counted signal: a signal that an event control or flip-flop domain
/// watches and that one unit may store twice without the runtime checking
/// in between. Its occurrences are counted in two-state counter objects.
///
/// Generated code bumps the counters around each such store (see
/// `celox_frontend_core::watch`) and the host and the scheduler bump them on
/// their writes. Every other watched signal is checked by value. The
/// counters are ordinary state.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct EventWatch<A> {
pub signal: A,
pub width: usize,
pub four_state: bool,
pub changes: Option<A>,
pub rises: Option<A>,
pub falls: Option<A>,
/// Canonical event domains that the counter of the given kind triggers
/// instead of edge detection by value.
pub domains: Vec<(A, CounterKind)>,
}

impl<A: Copy> EventWatch<A> {
pub fn counter(&self, kind: CounterKind) -> Option<A> {
match kind {
CounterKind::Changes => self.changes,
CounterKind::Rises => self.rises,
CounterKind::Falls => self.falls,
}
}

/// The present counters and their kinds.
pub fn counters(&self) -> impl Iterator<Item = (CounterKind, A)> + '_ {
CounterKind::ALL
.into_iter()
.filter_map(|kind| Some((kind, self.counter(kind)?)))
}

pub fn map<B>(&self, mut map: impl FnMut(A) -> B) -> EventWatch<B> {
EventWatch {
signal: map(self.signal),
width: self.width,
four_state: self.four_state,
changes: self.changes.map(&mut map),
rises: self.rises.map(&mut map),
falls: self.falls.map(&mut map),
domains: self
.domains
.iter()
.map(|&(event, kind)| (map(event), kind))
.collect(),
}
}
}

/// Counter objects a frontend declares for a signal that one of its units
/// may store twice between two runtime checks. Assembly turns them into an
/// [`EventWatch`] only if something watches the signal.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct CounterSlots<A> {
pub signal: A,
pub changes: A,
pub rises: A,
pub falls: A,
}

impl<A: Copy> CounterSlots<A> {
pub fn counter(&self, kind: CounterKind) -> A {
match kind {
CounterKind::Changes => self.changes,
CounterKind::Rises => self.rises,
CounterKind::Falls => self.falls,
}
}

pub fn map<B>(self, mut map: impl FnMut(A) -> B) -> CounterSlots<B> {
CounterSlots {
signal: map(self.signal),
changes: map(self.changes),
rises: map(self.rises),
falls: map(self.falls),
}
}
}

/// An event or level wait of a process kernel. A kernel suspended with
/// [`ProcessStatus::Wait`] stores the index of the site among its process's
/// sites in its delay slot.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct WaitSite<A> {
/// Index of the process in [`RuntimeSchema::processes`].
pub process: usize,
/// Occurrences that may satisfy the wait. The runtime resumes the
/// process at the first one after the wait began; a site whose kernel
/// checks a condition at its resume point decides itself whether it
/// continues.
pub terms: Vec<(A, CounterKind)>,
}

impl<A: Copy> WaitSite<A> {
pub fn map<B>(&self, mut map: impl FnMut(A) -> B) -> WaitSite<B> {
WaitSite {
process: self.process,
terms: self
.terms
.iter()
.map(|&(signal, kind)| (map(signal), kind))
.collect(),
}
}
}

/// A nonblocking assignment of a process kernel. A kernel that returns
/// [`ProcessStatus::Nba`] stores the index of the site among its process's
/// sites in its delay slot.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct NbaSite<A> {
/// Index of the process in [`RuntimeSchema::processes`].
pub process: usize,
/// The assigned object and the static part of the assigned bit range.
pub target: A,
pub lsb: usize,
pub width: usize,
/// Staging object of `width` bits holding the assigned value, with the
/// target's state representation.
pub value: A,
/// Two-state staging object holding a bit offset added to `lsb`, for an
/// assignment whose position is computed at run time.
pub offset: Option<A>,
/// One-bit flag of a site whose destination receives no other
/// nonblocking assignment: a variable of the module with no other
/// nonblocking site in the module and no writer outside it (not a port,
/// not bound to a package variable, not the target of a hierarchical
/// reference). A frontend that cannot tell leaves it `None`, so the
/// assignment goes through the ordered queue.
///
/// The kernel stages the value and sets the flag without returning;
/// publication commits flagged sites and clears the flags. A kernel
/// reaching the site again while the flag is set returns
/// [`ProcessStatus::Nba`] first, so the runtime queues the staged value.
pub pending: Option<A>,
}

impl<A: Copy> NbaSite<A> {
pub fn map<B>(&self, mut map: impl FnMut(A) -> B) -> NbaSite<B> {
NbaSite {
process: self.process,
target: map(self.target),
lsb: self.lsb,
width: self.width,
value: map(self.value),
offset: self.offset.map(&mut map),
pending: self.pending.map(&mut map),
}
}
}

/// Controls which combinational stores dead store elimination preserves.
///
/// The policy is part of the runtime contract: host-side handles resolve
Expand Down Expand Up @@ -325,6 +540,14 @@ pub struct RuntimeSchema<A> {
pub live_signals: HashSet<A>,
/// Control slots of the process kernels, in kernel order.
pub processes: Vec<ProcessSlots<A>>,
/// Counted signals and their occurrence counters.
pub watches: Vec<EventWatch<A>>,
/// Wait sites of the process kernels. A process's sites appear in the
/// order of its local site indices.
pub wait_sites: Vec<WaitSite<A>>,
/// Nonblocking assignment sites of the process kernels, ordered like
/// `wait_sites`.
pub nba_sites: Vec<NbaSite<A>>,
}

impl<A> Default for RuntimeSchema<A> {
Expand All @@ -341,6 +564,9 @@ impl<A> Default for RuntimeSchema<A> {
dead_store_policy: DeadStorePolicy::Off,
live_signals: HashSet::default(),
processes: Vec::new(),
watches: Vec::new(),
wait_sites: Vec::new(),
nba_sites: Vec::new(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod sdk;
pub mod shared;
pub mod symbolic;
mod trace;
pub mod watch;

pub use error::{LoweringPhase, ParserError, SourceLocation};
pub use sdk::{FrontendArtifactError, LoweredFrontendArtifact, lower_frontend_artifact};
Expand Down
Loading
Loading