Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ pub enum ProcessStatus {
/// A synchronous host operation. The delay slot holds its family and
/// local site index; the same process resumes after the host responds.
HostRequest,
/// A program kernel called `$exit` (IEEE 1800-2023 24.7): it and every
/// other kernel of its program instance ([`ProcessSlots::program`]) end.
Exit,
}

impl ProcessStatus {
Expand All @@ -308,6 +311,7 @@ impl ProcessStatus {
Self::Yield => 8,
Self::Stop => 9,
Self::HostRequest => 10,
Self::Exit => 11,
}
}

Expand All @@ -323,6 +327,7 @@ impl ProcessStatus {
8 => Some(Self::Yield),
9 => Some(Self::Stop),
10 => Some(Self::HostRequest),
11 => Some(Self::Exit),
_ => None,
}
}
Expand Down Expand Up @@ -465,6 +470,12 @@ pub struct ProcessSlots<A> {
/// Every delay the kernel suspends for is a constant of at least one
/// time unit.
pub const_delays: bool,
/// For an `initial` procedure of a program instance (IEEE 1800-2023
/// 24.3), the status slot of that instance's first such kernel, which
/// every kernel of the instance names: the kernel runs in the reactive
/// region set (24.3.1), and `$exit` and the end of the instance's
/// kernels act on them together (24.7). `None` for design code.
pub program: Option<A>,
pub resume: A,
pub status: A,
pub delay: A,
Expand All @@ -476,6 +487,7 @@ impl<A> ProcessSlots<A> {
is_initializer: self.is_initializer,
requires_timed_simulation: self.requires_timed_simulation,
const_delays: self.const_delays,
program: self.program.map(&mut map),
resume: map(self.resume),
status: map(self.status),
delay: map(self.delay),
Expand Down Expand Up @@ -1791,6 +1803,7 @@ mod tests {
ProcessStatus::from_code(10),
Some(ProcessStatus::HostRequest)
);
assert_eq!(ProcessStatus::from_code(11), Some(ProcessStatus::Exit));
}

#[test]
Expand Down
7 changes: 7 additions & 0 deletions crates/celox-frontend-core/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@ impl ProcessKernelBuilder {
self.end(ProcessStatus::Finish);
}

/// End the kernel and the other kernels of its program instance
/// (`$exit`, IEEE 1800-2023 24.7). No block is open afterwards.
pub fn exit(&mut self) {
self.wait_site = None;
self.end(ProcessStatus::Exit);
}

/// Complete the kernel. If a block is still open, the process ends there.
pub fn build(mut self) -> ExecutionUnit<RegionedSourceAddr> {
if self.builder.has_open_block() {
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,7 @@ fn lower_processes(
is_initializer: false,
requires_timed_simulation: false,
const_delays: false,
program: None,
resume: lowering
.hidden
.declare(name("resume"), PROCESS_RESUME_WIDTH, false),
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4451,6 +4451,7 @@ fn lower_initial_processes(
is_initializer: process.is_initializer(),
requires_timed_simulation: process.is_scheduled_edge(),
const_delays: false,
program: None,
resume: declare("resume", PROCESS_RESUME_WIDTH),
status: declare("status", PROCESS_STATUS_WIDTH),
delay: declare("delay", PROCESS_DELAY_WIDTH),
Expand Down
9 changes: 9 additions & 0 deletions crates/celox-runtime/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub struct ResolvedSchedule<B: SimBackend> {
pub(crate) signal_to_id: FxHashMap<SignalRef, usize>,
pub(crate) signal_index_by_id: Vec<usize>,
pub(crate) processes: Vec<ProcessRefs>,
/// The kernels of program instances, in declaration order.
pub(crate) program_processes: Vec<usize>,
/// Counted signals and the domains their counters trigger.
pub(crate) counted: Vec<CountedDomainRefs>,
pub(crate) counted_by_offset: FxHashMap<usize, usize>,
Expand Down Expand Up @@ -190,6 +192,7 @@ impl<B: SimBackend> ResolvedSchedule<B> {
.iter()
.map(|process| ProcessRefs {
is_initializer: process.slots.is_initializer,
program: process.slots.program.as_ref().map(resolve),
resume: resolve(&process.slots.resume),
starts_with_event_wait: process.slots.requires_timed_simulation,
status: resolve(&process.slots.status),
Expand Down Expand Up @@ -299,6 +302,12 @@ impl<B: SimBackend> ResolvedSchedule<B> {
event_info,
signal_to_id,
signal_index_by_id,
program_processes: processes
.iter()
.enumerate()
.filter(|(_, process)| process.program.is_some())
.map(|(index, _)| index)
.collect(),
processes,
counted,
counted_by_offset,
Expand Down
2 changes: 1 addition & 1 deletion crates/celox-runtime/src/simulation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ impl<B: SimBackend> SimulationState<B> {
E: SimulationExecutor<Backend = B>,
{
self.slot_passes = 0;
match self.step_round(executor, time, Vec::new(), Vec::new(), true) {
match self.step_round(executor, time, Vec::new(), Vec::new(), true, false) {
Ok(()) => {
self.finish_timed_boundary(executor, time)?;
Ok(Some(time))
Expand Down
144 changes: 108 additions & 36 deletions crates/celox-runtime/src/simulation/nba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ impl<B: SimBackend> SimulationState<B> {
let Some((lsb, width)) = refs.range(backend) else {
return Ok(());
};
self.process_state.nba_queue.push(NbaUpdate {
// A program process's update waits for the Re-NBA region (IEEE
// 1800-2023 24.3.1).
let queue = if self.model.processes[process].program.is_some() {
&mut self.process_state.re_nba_queue
} else {
&mut self.process_state.nba_queue
};
queue.push(NbaUpdate {
target: refs.target,
lsb,
width,
Expand All @@ -57,6 +64,7 @@ impl<B: SimBackend> SimulationState<B> {
self.model
.processes
.iter()
.filter(|process| process.program.is_none())
.flat_map(|process| &process.nba_sites)
.filter_map(|site| site.pending)
.filter(|&pending| backend.get_as::<u8>(pending) != 0)
Expand All @@ -76,45 +84,12 @@ impl<B: SimBackend> SimulationState<B> {
self.event_values(executor.backend(), &mut round.before);
round.transitions.clear();
}
for update in &queued {
let new = NbaValue::Queued(&update.value);
self.publish_update(executor.backend_mut(), update, new);
if several {
self.record_transitions(executor.backend(), round);
}
}
self.publish_queued(executor, round, &queued, several);
// Keep the queue's storage for the next time slot.
queued.clear();
self.process_state.nba_queue = queued;
if flagged > 0 {
for process in 0..self.model.processes.len() {
for site in 0..self.model.processes[process].nba_sites.len() {
let backend = executor.backend_mut();
let Some(pending) = self.model.processes[process].nba_sites[site].pending
else {
continue;
};
if backend.get_as::<u8>(pending) == 0 {
continue;
}
backend.set(pending, 0u8);
let site = &self.model.processes[process].nba_sites[site];
let Some((lsb, width)) = site.range(backend) else {
continue;
};
let (target, value) = (site.target, site.value);
let update = NbaUpdate {
target,
lsb,
width,
value: Value::default(),
};
self.publish_update(backend, &update, NbaValue::Staged(value));
if several {
self.record_transitions(executor.backend(), round);
}
}
}
self.publish_flagged(executor, round, false, several);
}
if several {
let transitions = std::mem::take(&mut round.transitions);
Expand All @@ -126,6 +101,103 @@ impl<B: SimBackend> SimulationState<B> {
true
}

/// Publish the nonblocking assignments of program processes (the Re-NBA
/// region, IEEE 1800-2023 4.4.2.8): the queued ones in issue order, then
/// the flagged ones. Like the writes of a process run, each is recorded
/// in `round.transitions` for the caller to settle. Returns whether any
/// was published.
pub(super) fn publish_re_nba<E>(&mut self, executor: &mut E, round: &mut Round) -> bool
where
E: SimulationExecutor<Backend = B>,
{
let any_flagged = self.model.has_pending_nba_sites && {
let backend = executor.backend();
self.model
.program_processes
.iter()
.flat_map(|&process| &self.model.processes[process].nba_sites)
.filter_map(|site| site.pending)
.any(|pending| backend.get_as::<u8>(pending) != 0)
};
if self.process_state.re_nba_queue.is_empty() && !any_flagged {
return false;
}
self.event_values(executor.backend(), &mut round.before);
let mut queued = std::mem::take(&mut self.process_state.re_nba_queue);
self.publish_queued(executor, round, &queued, true);
// Keep the queue's storage for the next time slot.
queued.clear();
self.process_state.re_nba_queue = queued;
if any_flagged {
self.publish_flagged(executor, round, true, true);
}
true
}

/// Publish `queued` in issue order, recording the transitions of each in
/// `round.transitions` if `record`.
fn publish_queued<E>(
&mut self,
executor: &mut E,
round: &mut Round,
queued: &[NbaUpdate],
record: bool,
) where
E: SimulationExecutor<Backend = B>,
{
for update in queued {
let new = NbaValue::Queued(&update.value);
self.publish_update(executor.backend_mut(), update, new);
if record {
self.record_transitions(executor.backend(), round);
}
}
}

/// Publish the flagged nonblocking sites of the program processes if
/// `program`, otherwise of the design's, in declaration order, recording
/// the transitions of each in `round.transitions` if `record`.
fn publish_flagged<E>(
&mut self,
executor: &mut E,
round: &mut Round,
program: bool,
record: bool,
) where
E: SimulationExecutor<Backend = B>,
{
for process in 0..self.model.processes.len() {
if self.model.processes[process].program.is_some() != program {
continue;
}
for site in 0..self.model.processes[process].nba_sites.len() {
let backend = executor.backend_mut();
let Some(pending) = self.model.processes[process].nba_sites[site].pending else {
continue;
};
if backend.get_as::<u8>(pending) == 0 {
continue;
}
backend.set(pending, 0u8);
let site = &self.model.processes[process].nba_sites[site];
let Some((lsb, width)) = site.range(backend) else {
continue;
};
let (target, value) = (site.target, site.value);
let update = NbaUpdate {
target,
lsb,
width,
value: Value::default(),
};
self.publish_update(backend, &update, NbaValue::Staged(value));
if record {
self.record_transitions(executor.backend(), round);
}
}
}
}

/// Write `update`, whose value is `new`, into its target. An update
/// inside a target of at most 64 bits with one state plane is merged as
/// `u64`; any other as [`Value`].
Expand Down
6 changes: 6 additions & 0 deletions crates/celox-runtime/src/simulation/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ impl<B: SimBackend> SimulationState<B> {
ready: state.ready.iter().copied().collect(),
inactive: state.inactive.iter().copied().collect(),
nba_queue: state.nba_queue.clone(),
reactive: state.reactive.iter().copied().collect(),
re_inactive: state.re_inactive.iter().copied().collect(),
re_nba_queue: state.re_nba_queue.clone(),
domain_counters: state.domain_counters.clone(),
declarations_pending: self.declarations_pending,
host_pending: self.host_pending,
Expand All @@ -319,6 +322,9 @@ pub struct ScheduleKey {
pub ready: Vec<usize>,
pub inactive: Vec<usize>,
pub nba_queue: Vec<super::NbaUpdate>,
pub reactive: Vec<usize>,
pub re_inactive: Vec<usize>,
pub re_nba_queue: Vec<super::NbaUpdate>,
pub domain_counters: Vec<[u32; 3]>,
pub declarations_pending: bool,
pub host_pending: bool,
Expand Down
Loading
Loading