Skip to content
Closed
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
32 changes: 16 additions & 16 deletions conformance/sv-tests/expected.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -1583,24 +1583,24 @@ chapter-9/9.2.3--final.sv 2state pass
chapter-9/9.2.3--final.sv 4state pass
chapter-9/9.3.1--sequential_block.sv 2state pass
chapter-9/9.3.1--sequential_block.sv 4state pass
chapter-9/9.3.2--parallel_block_join.sv 2state fail
chapter-9/9.3.2--parallel_block_join.sv 4state fail
chapter-9/9.3.2--parallel_block_join_any.sv 2state fail
chapter-9/9.3.2--parallel_block_join_any.sv 4state fail
chapter-9/9.3.2--parallel_block_join_none.sv 2state fail
chapter-9/9.3.2--parallel_block_join_none.sv 4state fail
chapter-9/9.3.3--block_start_finish.sv 2state fail
chapter-9/9.3.3--block_start_finish.sv 4state fail
chapter-9/9.3.2--parallel_block_join.sv 2state pass
chapter-9/9.3.2--parallel_block_join.sv 4state pass
chapter-9/9.3.2--parallel_block_join_any.sv 2state pass
chapter-9/9.3.2--parallel_block_join_any.sv 4state pass
chapter-9/9.3.2--parallel_block_join_none.sv 2state pass
chapter-9/9.3.2--parallel_block_join_none.sv 4state pass
chapter-9/9.3.3--block_start_finish.sv 2state pass
chapter-9/9.3.3--block_start_finish.sv 4state pass
chapter-9/9.3.3--event.sv 2state fail
chapter-9/9.3.3--event.sv 4state fail
chapter-9/9.3.3--fork_return.sv 2state pass
chapter-9/9.3.3--fork_return.sv 4state pass
chapter-9/9.3.4--block_names_par.sv 2state fail
chapter-9/9.3.4--block_names_par.sv 4state fail
chapter-9/9.3.4--block_names_par.sv 2state pass
chapter-9/9.3.4--block_names_par.sv 4state pass
chapter-9/9.3.4--block_names_seq.sv 2state pass
chapter-9/9.3.4--block_names_seq.sv 4state pass
chapter-9/9.3.5--statement_labels_par.sv 2state fail
chapter-9/9.3.5--statement_labels_par.sv 4state fail
chapter-9/9.3.5--statement_labels_par.sv 2state pass
chapter-9/9.3.5--statement_labels_par.sv 4state pass
chapter-9/9.3.5--statement_labels_seq.sv 2state pass
chapter-9/9.3.5--statement_labels_seq.sv 4state pass
chapter-9/9.4.1--delay_control-sim.sv 2state pass
Expand Down Expand Up @@ -1645,14 +1645,14 @@ chapter-9/9.4.5--event_nonblocking_assignment_repeat_int_neg.sv 2state fail
chapter-9/9.4.5--event_nonblocking_assignment_repeat_int_neg.sv 4state fail
chapter-9/9.4.5--event_nonblocking_assignment_repeat_neg.sv 2state fail
chapter-9/9.4.5--event_nonblocking_assignment_repeat_neg.sv 4state fail
chapter-9/9.6.1--wait_fork.sv 2state fail
chapter-9/9.6.1--wait_fork.sv 4state fail
chapter-9/9.6.1--wait_fork.sv 2state pass
chapter-9/9.6.1--wait_fork.sv 4state pass
chapter-9/9.6.2--disable.sv 2state fail
chapter-9/9.6.2--disable.sv 4state fail
chapter-9/9.6.2--disable_other.sv 2state fail
chapter-9/9.6.2--disable_other.sv 4state fail
chapter-9/9.6.3--disable_fork.sv 2state fail
chapter-9/9.6.3--disable_fork.sv 4state fail
chapter-9/9.6.3--disable_fork.sv 2state pass
chapter-9/9.6.3--disable_fork.sv 4state pass
chapter-9/9.7--process_cls_await.sv 2state fail
chapter-9/9.7--process_cls_await.sv 4state fail
chapter-9/9.7--process_cls_kill.sv 2state fail
Expand Down
49 changes: 49 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,14 @@ pub struct RuntimeErrorInfo<A> {
pub signals: Vec<A>,
}

/// When a parent resumes after creating concurrent children (IEEE 1800-2023 9.3.2).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ForkJoin {
All,
Any,
None,
}

/// How a process kernel returned control to the runtime, as stored in its
/// [`ProcessSlots::status`] slot.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
Expand Down Expand Up @@ -452,6 +460,14 @@ pub enum ProcessStatus {
/// A program kernel called `$exit` (IEEE 1800-2023 24.7): it and every
/// other kernel of its program instance ([`ProcessSlots::program`]) end.
Exit,
/// Create child activations. The delay slot encodes their entry points and join mode.
Fork,
/// Allocate a fresh automatic local cell before its declaration initializer.
Local,
/// Wait for all live immediate child activations.
WaitFork,
/// Terminate all descendants of the calling activation.
DisableFork,
}

impl ProcessStatus {
Expand All @@ -470,6 +486,10 @@ impl ProcessStatus {
Self::Stop => 9,
Self::HostRequest => 10,
Self::Exit => 11,
Self::Fork => 12,
Self::Local => 13,
Self::WaitFork => 14,
Self::DisableFork => 15,
}
}

Expand All @@ -486,6 +506,10 @@ impl ProcessStatus {
9 => Some(Self::Stop),
10 => Some(Self::HostRequest),
11 => Some(Self::Exit),
12 => Some(Self::Fork),
13 => Some(Self::Local),
14 => Some(Self::WaitFork),
15 => Some(Self::DisableFork),
_ => None,
}
}
Expand Down Expand Up @@ -627,6 +651,29 @@ pub enum ProcessKind {
Final,
}

/// Storage switched when several activations execute the same kernel.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ProcessFrame<A> {
/// Compiler temporaries and control slots private to each activation.
pub private: Vec<A>,
/// Automatic locals shared with children until the declaration is re-entered.
pub locals: Vec<A>,
pub random: A,
pub seed: u32,
pub starts_with_event_wait: bool,
}
impl<A> ProcessFrame<A> {
pub fn map<B>(self, mut map: impl FnMut(A) -> B) -> ProcessFrame<B> {
ProcessFrame {
private: self.private.into_iter().map(&mut map).collect(),
locals: self.locals.into_iter().map(&mut map).collect(),
random: map(self.random),
seed: self.seed,
starts_with_event_wait: self.starts_with_event_wait,
}
}
}

/// State through which one process kernel exchanges control with the runtime.
///
/// A process kernel is a resumable function. On entry it reads `resume` to
Expand Down Expand Up @@ -1034,6 +1081,7 @@ pub struct RuntimeSchema<A> {
pub processes: Vec<ProcessSlots<A>>,
/// Source procedures of the process kernels, in kernel order.
pub process_origins: Vec<ProcessOrigin>,
pub process_frames: Vec<Option<ProcessFrame<A>>>,
/// Counted signals and their occurrence counters.
pub watches: Vec<EventWatch<A>>,
/// Bit ranges whose changes bump an occurrence counter: the sensitivity
Expand Down Expand Up @@ -1302,6 +1350,7 @@ impl<A> Default for RuntimeSchema<A> {
live_signals: HashSet::default(),
processes: Vec::new(),
process_origins: Vec::new(),
process_frames: Vec::new(),
watches: Vec::new(),
occurrence_probes: Vec::new(),
wait_sites: Vec::new(),
Expand Down
5 changes: 4 additions & 1 deletion crates/celox-design/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct CountedModel<A> {
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ProcessModel<A> {
pub slots: ProcessSlots<A>,
pub frame: Option<crate::ProcessFrame<A>>,
pub waits: Vec<Vec<TermModel<A>>>,
pub nbas: Vec<NbaSite<A>>,
pub host_requests: Vec<crate::HostRequestSite<A>>,
Expand Down Expand Up @@ -101,7 +102,9 @@ impl<A: Copy + Eq + std::hash::Hash> ScheduleModel<A> {
let mut processes: Vec<ProcessModel<A>> = schema
.processes
.iter()
.map(|slots| ProcessModel {
.enumerate()
.map(|(index, slots)| ProcessModel {
frame: schema.process_frames.get(index).cloned().flatten(),
slots: *slots,
waits: Vec::new(),
nbas: Vec::new(),
Expand Down
59 changes: 55 additions & 4 deletions crates/celox-frontend-core/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ pub struct ProcessKernelBuilder {
slots: ProcessSlots<SourceVarId>,
/// The block each resume point continues in; point 0 is the start.
resume_blocks: Vec<BlockId>,
/// The wait site whose resume point is being lowered.
wait_site: Option<u32>,
/// The wait site and predicate entry resume point being lowered.
wait_site: Option<(u32, usize)>,
/// The runtime event site the process reports at its flush points
/// (see [`Self::flush_deferred_at`]).
flush_site: Option<u32>,
Expand Down Expand Up @@ -192,6 +192,49 @@ impl ProcessKernelBuilder {
self.suspend(ProcessStatus::Yield)
}

/// Reserve one entry point for each child, then return to the runtime to spawn them.
/// The caller lowers each child into its entry block and ends it with `complete`.
pub fn fork(
&mut self,
count: usize,
join: celox_design::ForkJoin,
) -> Result<(Vec<BlockId>, BlockId), ProcessKernelError> {
let first = self.resume_blocks.len();
if first + count > MAX_PROCESS_SUSPENSIONS {
return Err(ProcessKernelError::TooManySuspensions);
}
let children: Vec<_> = (0..count).map(|_| self.builder.new_block()).collect();
self.resume_blocks.extend(children.iter().copied());
let mode = match join {
celox_design::ForkJoin::All => 0u64,
celox_design::ForkJoin::Any => 1,
celox_design::ForkJoin::None => 2,
};
self.store_delay_constant(first as u64 | ((count as u64) << 16) | (mode << 32));
self.slots.const_delays = false;
self.slots.requires_timed_simulation = true;
self.suspend(ProcessStatus::Fork)?;
Ok((children, self.builder.current_block()))
}

/// Wait for the calling process's immediate children (IEEE 1800-2023 9.6.1).
pub fn wait_fork(&mut self) -> Result<(), ProcessKernelError> {
self.slots.const_delays = false;
self.slots.requires_timed_simulation = true;
self.suspend(ProcessStatus::WaitFork)
}

/// Cancel descendants without suspending HDL execution (9.6.3).
pub fn disable_fork(&mut self) -> Result<(), ProcessKernelError> {
self.slots.const_delays = false;
self.suspend(ProcessStatus::DisableFork)
}

pub fn local(&mut self, slot: usize) -> Result<(), ProcessKernelError> {
self.store_delay_constant(slot as u64);
self.suspend(ProcessStatus::Local)
}

/// Suspend the simulation (`$stop`), and continue at a new resume point
/// when it continues.
pub fn stop(&mut self) -> Result<(), ProcessKernelError> {
Expand All @@ -215,7 +258,7 @@ impl ProcessKernelBuilder {
pub fn suspend_wait(&mut self, site: u32) -> Result<(), ProcessKernelError> {
self.store_delay_constant(u64::from(site));
self.suspend(ProcessStatus::Wait)?;
self.wait_site = Some(site);
self.wait_site = Some((site, self.resume_blocks.len() - 1));
Ok(())
}

Expand All @@ -224,7 +267,7 @@ impl ProcessKernelBuilder {
/// that the wait is still pending and return to the same resume point.
/// The continuation block is open afterwards.
pub fn wake_if(&mut self, condition: RegisterId) {
let site = self.wait_site.take().expect("wake_if follows suspend_wait");
let (site, resume) = self.wait_site.take().expect("wake_if follows suspend_wait");
let woken = self.builder.new_block();
let pending = self.builder.new_block();
self.builder.seal_block(SIRTerminator::Branch {
Expand All @@ -233,6 +276,9 @@ impl ProcessKernelBuilder {
false_block: (pending, Vec::new()),
});
self.builder.switch_to_block(pending);
// Predicate evaluation may itself yield to the runtime (for example,
// disable fork). A later wakeup must evaluate the whole predicate.
self.store_constant(self.slots.resume, PROCESS_RESUME_WIDTH, resume as u64);
self.store_delay_constant(u64::from(site));
self.end(ProcessStatus::Pending);
self.builder.switch_to_block(woken);
Expand Down Expand Up @@ -379,6 +425,11 @@ impl ProcessKernelBuilder {
Ok(())
}

/// End only this activation, notifying a waiting fork parent.
pub fn complete(&mut self) {
self.end(ProcessStatus::Done);
}

/// End the simulation. No block is open afterwards.
pub fn finish(&mut self) {
self.wait_site = None;
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 @@ -1754,6 +1754,7 @@ fn lower_processes(
stable_signal(address, artifact.signals().len())
}));
processes.push(SymbolicProcess {
frame: None,
kernel,
slots,
origin: celox_design::ProcessOrigin {
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-core/src/symbolic/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl<A> FfPart<A> {
pub struct SymbolicProcess {
pub kernel: ExecutionUnit<SymbolicRegionedAddr>,
pub slots: ProcessSlots<SourceVarId>,
pub frame: Option<celox_design::ProcessFrame<SourceVarId>>,
pub origin: celox_design::ProcessOrigin,
}

Expand Down
31 changes: 31 additions & 0 deletions crates/celox-frontend-core/src/symbolic/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2122,10 +2122,12 @@ pub fn schedule_symbolic_rtl_reporting_loops(
}
let mut process_kernels = Vec::with_capacity(processes.len());
let mut process_slots = Vec::with_capacity(processes.len());
let mut process_frames = Vec::with_capacity(processes.len());
let mut process_origins = Vec::with_capacity(processes.len());
for process in processes {
process_kernels.push(process.kernel);
process_slots.push(process.slots);
process_frames.push(process.frame);
process_origins.push(process.origin);
}
let TimingMetadata {
Expand Down Expand Up @@ -2333,6 +2335,10 @@ pub fn schedule_symbolic_rtl_reporting_loops(
}
}

let process_frames: Vec<_> = process_frames
.into_iter()
.map(|frame| frame.map(|frame| frame.map(project)))
.collect();
let process_slots = process_slots
.into_iter()
.map(|slots| slots.map(project))
Expand Down Expand Up @@ -2464,6 +2470,13 @@ pub fn schedule_symbolic_rtl_reporting_loops(
})
.collect();
// The runtime counts the occurrences its own writes cause.
timing_read_roots.extend(
process_frames
.iter()
.flatten()
.flat_map(|frame| frame.private.iter().chain(&frame.locals))
.copied(),
);
timing_read_roots.extend(
occurrence_probes
.iter()
Expand Down Expand Up @@ -2538,6 +2551,7 @@ pub fn schedule_symbolic_rtl_reporting_loops(
declaration_startup,
dead_store_policy: Default::default(),
live_signals: Default::default(),
process_frames,
processes: process_slots,
process_origins,
watches,
Expand Down Expand Up @@ -3948,6 +3962,10 @@ fn relocate_units(
&extern_function_map,
),
slots: process.slots.map(|var_id| bindings.locate(*id, var_id)),
frame: process
.frame
.clone()
.map(|frame| frame.map(|var_id| bindings.locate(*id, var_id))),
origin: celox_design::ProcessOrigin {
scope: Some(scope.clone()),
..process.origin.clone()
Expand Down Expand Up @@ -4079,6 +4097,7 @@ fn relocate_units(
struct RelocatedProcess {
kernel: ExecutionUnit<RegionedAbsoluteAddr>,
slots: ProcessSlots<AbsoluteAddr>,
frame: Option<celox_design::ProcessFrame<AbsoluteAddr>>,
origin: celox_design::ProcessOrigin,
/// The instance and the module-local index of the process.
key: (InstanceId, usize),
Expand Down Expand Up @@ -4284,6 +4303,18 @@ fn select_nba_paths(
staged: &HashSet<AbsoluteAddr>,
processes: &mut [RelocatedProcess],
) {
let mut staged = staged.clone();
// Fork activations can reach one NBA site concurrently. Always queue its
// captured value, rather than leaving one shared pending slot per kernel.
for site in &timing.nba_sites {
if processes[site.process].frame.is_some() {
for switch in &timing.nba_switches {
if switch.value == site.value {
staged.remove(&switch.switch);
}
}
}
}
let switches: HashMap<AbsoluteAddr, NbaSwitch<AbsoluteAddr>> = timing
.nba_switches
.iter()
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 @@ -5230,6 +5230,7 @@ fn lower_initial_processes(
}));
Ok(SymbolicProcess {
kernel: kernel.unit,
frame: kernel.frame,
slots: kernel.slots,
origin: process_origin(process),
})
Expand Down
4 changes: 4 additions & 0 deletions crates/celox-frontend-sv/src/lowering/comb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2026,6 +2026,10 @@ impl<'p, 'a> Comb<'p, 'a> {
stmt: &sv::ir::Stmt,
) -> Result<Store, sv::AnalyzerError> {
match stmt {
sv::ir::Stmt::DisableFork => Ok(store),
sv::ir::Stmt::Fork { .. } | sv::ir::Stmt::WaitFork => {
Err(unsupported("fork control outside a timed process"))
}
sv::ir::Stmt::Assign {
lhs,
rhs,
Expand Down
Loading
Loading