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
21 changes: 21 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ pub enum AssertionDeferral {
Final,
}

/// How the host defers the events of a site (IEEE 1800-2023 16.4).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum DeferredSite {
/// A flush point of a process with deferred assertions (16.4.2): the
/// actions its queue holds are discarded. The events of this site are
/// not shown.
FlushPoint,
/// The action of a deferred assertion: its event waits in the queue of
/// the flush-point site `queue` of the same instance, numbered like the
/// sites of its module, until `region` of the time slot.
Action {
queue: u32,
region: AssertionDeferral,
},
}

/// Which action block of an assertion issues a report.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum AssertionOutcome {
Expand Down Expand Up @@ -191,6 +207,10 @@ pub struct RuntimeEventSite {
/// The assertion whose action issues this report.
#[serde(default)]
pub assertion: Option<AssertionSite>,
/// How the host defers the events of this site, for the processes of
/// deferred assertions.
#[serde(default)]
pub deferred: Option<DeferredSite>,
pub arg_widths: Vec<usize>,
pub arg_signed: Vec<bool>,
pub arg_is_string: Vec<bool>,
Expand Down Expand Up @@ -1979,6 +1999,7 @@ mod tests {
scope: None,
location: None,
assertion: None,
deferred: None,
arg_widths: Vec::new(),
arg_signed: Vec::new(),
arg_is_string: Vec::new(),
Expand Down
17 changes: 17 additions & 0 deletions crates/celox-frontend-core/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ pub struct ProcessKernelBuilder {
resume_blocks: Vec<BlockId>,
/// The wait site whose resume point is being lowered.
wait_site: Option<u32>,
/// The runtime event site the process reports at its flush points
/// (see [`Self::flush_deferred_at`]).
flush_site: Option<u32>,
}

impl ProcessKernelBuilder {
Expand All @@ -78,9 +81,17 @@ impl ProcessKernelBuilder {
},
resume_blocks: vec![start],
wait_site: None,
flush_site: None,
}
}

/// Report runtime event site `site` whenever the process resumes from
/// an event control or a wait: a flush point of its deferred
/// assertions (IEEE 1800-2023 16.4.2). A resume after a delay is not.
pub fn flush_deferred_at(&mut self, site: u32) {
self.flush_site = Some(site);
}

/// The kernel's control slots, with [`ProcessSlots::const_delays`] set
/// for the delays lowered so far.
pub fn slots(&self) -> ProcessSlots<SourceVarId> {
Expand Down Expand Up @@ -225,6 +236,12 @@ impl ProcessKernelBuilder {
self.store_delay_constant(u64::from(site));
self.end(ProcessStatus::Pending);
self.builder.switch_to_block(woken);
if let Some(site_id) = self.flush_site {
self.builder.emit(SIRInstruction::RuntimeEvent {
site_id,
args: Vec::new(),
});
}
}

/// `wait (condition)` (IEEE 1800-2023 9.4.3) at wait site `site`:
Expand Down
6 changes: 6 additions & 0 deletions crates/celox-frontend-core/src/symbolic/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3257,11 +3257,17 @@ fn relocate_units(
}
let mut runtime_event_site_map = HashMap::default();
let scope = elaborated_scope_name(root_name, path, expanded, indexed_instances);
let site_base = runtime_event_sites.len() as u32;
for (local_site, site) in sim_module.runtime_event_sites.iter().enumerate() {
let global_site = runtime_event_sites.len() as u32;
runtime_event_site_map.insert(local_site as u32, global_site);
let mut site = site.clone();
site.scope = Some(scope.clone());
// A deferred action names the flush point of its process in the
// same instance.
if let Some(celox_design::DeferredSite::Action { queue, .. }) = &mut site.deferred {
*queue += site_base;
}
runtime_event_sites.push(site);
}

Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-sv/src/lowering/comb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3605,6 +3605,7 @@ impl<'p, 'a> Comb<'p, 'a> {
scope: None,
location: report_location(site),
assertion: assertion_site.cloned(),
deferred: None,
arg_widths,
arg_signed,
arg_is_string,
Expand Down
105 changes: 103 additions & 2 deletions crates/celox-frontend-sv/src/lowering/ff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ mod strings;

use super::procedural::*;
use super::*;
use celox_design::{CounterKind, NbaPosition, NbaSite, SPARSE_WORKING_REGION, WaitSite};
use celox_design::{
CounterKind, DeferredSite, NbaPosition, NbaSite, SPARSE_WORKING_REGION, WaitSite,
};
use celox_frontend_core::process::{NBA_POSITION_WIDTH, ProcessKernelBuilder, ProcessKernelError};
use celox_sir::{RegisterId, RegisterType};
use celox_slt::SLTToSIRLowerer;
Expand Down Expand Up @@ -92,6 +94,9 @@ pub(super) struct Ff<'p, 'a> {
/// Whether a combinational process also reruns for occurrences of its
/// inputs that left their value unchanged.
input_occurrences: bool,
/// The flush-point site of a process with deferred assertions, whose
/// queue their actions wait in.
flush_site: Option<u32>,
}

fn stable(var_id: SourceVarId) -> Addr {
Expand Down Expand Up @@ -147,9 +152,86 @@ impl<'p, 'a> Ff<'p, 'a> {
nba_sites: Vec::new(),
host_request_sites: Vec::new(),
nba_switches: Vec::new(),
flush_site: None,
}
}

/// Whether `stmts`, or a subroutine they call, including in timing
/// controls and the defaults of omitted arguments, hold a deferred
/// assertion.
fn has_deferred_assertions(
&self,
stmts: &[sv::ir::Stmt],
visited: &mut HashSet<String>,
) -> bool {
let mut found = false;
let mut calls = Vec::new();
for stmt in stmts {
stmt.walk(&mut |stmt| {
if let sv::ir::Stmt::SystemTask {
assertion: Some(assertion),
..
} = stmt
&& assertion.deferral != celox_design::AssertionDeferral::None
{
found = true;
}
stmt_calls(stmt, &mut calls);
Comment thread
tignear marked this conversation as resolved.
Resolved
// Timing controls evaluate their expressions too.
match stmt {
sv::ir::Stmt::Wait(condition) => collect_calls(condition, &mut calls),
sv::ir::Stmt::WaitEvent(items) => {
for item in items {
collect_calls(&item.expr, &mut calls);
}
}
sv::ir::Stmt::Delay { amount, .. } => collect_calls(amount, &mut calls),
_ => {}
}
});
}
if found {
return true;
}
while let Some((callee, args)) = calls.pop() {
let sv::ir::Callee::Subroutine(name) = callee else {
continue;
};
let Some(subroutine) = self.m.subroutine(&name).cloned() else {
continue;
};
default_calls(&subroutine, &args, &mut calls);
if visited.insert(name) && self.has_deferred_assertions(&subroutine.body, visited) {
return true;
}
}
false
}

/// For a process with deferred assertions, its flush-point site (IEEE
/// 1800-2023 16.4.2), whose queue their actions wait in.
fn deferred_flush_site(&mut self, body: &[sv::ir::Stmt]) -> Option<u32> {
if !self.has_deferred_assertions(body, &mut HashSet::default()) {
return None;
}
let site = self.m.event_site(RuntimeEventSite {
kind: RuntimeEventKind::Write,
template: None,
sizing: DisplaySizing::Ieee,
scope: None,
location: None,
assertion: None,
deferred: Some(DeferredSite::FlushPoint),
arg_widths: Vec::new(),
arg_signed: Vec::new(),
arg_is_string: Vec::new(),
arg_float_precision: Vec::new(),
arg_is_handle: Vec::new(),
});
self.flush_site = Some(site);
Some(site)
}

/// Lower a combinational process that reruns only when an input value
/// changed. Its inputs then need no occurrence counters, so the units
/// that write them stay unchanged.
Expand Down Expand Up @@ -3173,13 +3255,21 @@ impl<'p, 'a> Ff<'p, 'a> {
_ => None,
};
let event_kind = kind.event_kind();
// The action of a deferred assertion waits in its process's queue
// until the assertion matures (IEEE 1800-2023 16.4.1).
let deferred = assertion_site
.map(|assertion| assertion.deferral)
.filter(|&region| region != celox_design::AssertionDeferral::None)
.zip(self.flush_site)
.map(|(region, queue)| DeferredSite::Action { queue, region });
let site_id = self.m.event_site(RuntimeEventSite {
kind: event_kind,
template: template.clone(),
sizing: DisplaySizing::Ieee,
scope: None,
location: report_location(site),
assertion: assertion_site.cloned(),
deferred,
arg_widths,
arg_signed,
arg_is_string,
Expand All @@ -3190,7 +3280,8 @@ impl<'p, 'a> Ff<'p, 'a> {
site_id,
args: regs,
});
if kind.is_fatal() {
// A deferred `$fatal` ends the simulation when it matures.
if kind.is_fatal() && deferred.is_none() {
let code = self
.m
.runtime_error(template.unwrap_or_else(|| sv::ir::SystemTask::Fatal.to_string()));
Expand Down Expand Up @@ -4272,6 +4363,13 @@ impl<'p, 'a> Ff<'p, 'a> {
));
}
}
// Each evaluation resumes the process from its event control.
if let Some(site_id) = self.deferred_flush_site(&body) {
self.b.emit(SIRInstruction::RuntimeEvent {
site_id,
args: Vec::new(),
});
}
if self.exec_block(&body)? {
self.b.seal_block(SIRTerminator::Return);
}
Expand Down Expand Up @@ -4710,6 +4808,9 @@ impl Ff<'_, '_> {
) -> Result<KernelUnit, sv::AnalyzerError> {
self.process = process;
let mut kernel = ProcessKernelBuilder::new(slots);
if let Some(site) = self.deferred_flush_site(body) {
kernel.flush_deferred_at(site);
}
std::mem::swap(&mut self.b, kernel.builder());
self.kernel = Some(kernel);
self.exec_block(body)?;
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-veryl/src/lowering/ff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ impl<'a> FfParser<'a> {
scope: None,
location: None,
assertion: None,
deferred: None,
arg_widths: value_args
.iter()
.map(|arg| self.get_expression_width(&arg.0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ fn register_comb_runtime_event_site<'a>(
scope: None,
location: None,
assertion: None,
deferred: None,
arg_widths: value_args
.iter()
.map(|arg| arg.0.comptime().r#type.total_width().unwrap_or(1))
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-veryl/src/testbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ fn runtime_event_site_for_assert(
scope: None,
location: None,
assertion: None,
deferred: None,
arg_widths: value_args.iter().map(assert_arg_width).collect(),
arg_signed: value_args
.iter()
Expand Down
9 changes: 9 additions & 0 deletions crates/celox-runtime/src/simulation/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ pub trait HostBoundary: UnitExecutor {
self.finish_timed_step(timestamp);
Ok(())
}

/// Called after [`Self::try_finish_timed_step`] when the time slot
/// `timestamp` is over: no more work is due at that time. A step ends
/// before its slot does when a process waits for zero time. The
/// runtime's loop calls it; a host that has work here returns
/// [`CompiledSlots::None`] from [`Self::compiled_slots`].
fn try_end_time_slot(&mut self, _timestamp: u64) -> Result<(), Halt> {
Ok(())
}
}

/// How many time slots a compiled scheduler may run at once (see
Expand Down
5 changes: 5 additions & 0 deletions crates/celox-runtime/src/simulation/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ impl<B: SimBackend> SimulationState<B> {
if executor.take_slot_writes() {
self.host_pending = true;
}
// The slot is over when nothing more is due at its time, host
// writes included.
if !self.host_pending && self.next_work_time() != Some(current_time) {
executor.try_end_time_slot(current_time)?;
}
Ok(())
}

Expand Down
35 changes: 31 additions & 4 deletions crates/celox-sv-analyzer/src/ast/procedural.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1623,21 +1623,48 @@ fn assertion_failure(keyword: &str, site: Option<crate::procedural::SourceSpan>)
}]
}

/// Attribute the severity tasks of an assertion's action block to it. Tasks
/// in subroutines the block calls are not attributed, and the tasks of a
/// nested assertion keep its own attribution.
/// Check the action of a deferred assertion: one subroutine call (IEEE
/// 1800-2023 16.4). Only display and severity tasks are supported, since
/// a user subroutine would run in the Reactive region and could wake
/// processes there.
fn deferred_action(body: &[Stmt]) -> Result<(), AnalyzerError> {
match body {
[] => Ok(()),
[
Stmt::SystemTask {
task:
SystemTask::Display(_)
| SystemTask::Write(_)
| SystemTask::Severity(_)
| SystemTask::Fatal,
..
},
] => Ok(()),
_ => Err(unsupported(
"deferred assertion action other than one display or severity task call",
)),
}
}

/// Attribute the severity tasks of an assertion's action block to it, and
/// for a deferred assertion its display tasks, which wait in the same
/// queue. Tasks in subroutines the block calls are not attributed, and the
/// tasks of a nested assertion keep its own attribution.
fn attribute_reports(
body: &mut [Stmt],
assertion: &celox_design::AssertionSite,
outcome: celox_design::AssertionOutcome,
) {
for stmt in body {
stmt.walk_mut(&mut |stmt| {
let deferred = assertion.deferral != celox_design::AssertionDeferral::None;
if let Stmt::SystemTask {
task: SystemTask::Severity(_) | SystemTask::Fatal,
task,
assertion: attributed @ None,
..
} = stmt
&& (matches!(task, SystemTask::Severity(_) | SystemTask::Fatal)
|| deferred && matches!(task, SystemTask::Display(_) | SystemTask::Write(_)))
{
*attributed = Some(celox_design::AssertionSite {
outcome,
Expand Down
Loading
Loading