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
4 changes: 4 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ pub struct ProcessSlots<A> {
pub is_initializer: bool,
/// This kernel originated from an edge procedure and must execute in Simulation.
pub requires_timed_simulation: bool,
/// Every delay the kernel suspends for is a constant of at least one
/// time unit.
pub const_delays: bool,
pub resume: A,
pub status: A,
pub delay: A,
Expand All @@ -465,6 +468,7 @@ impl<A> ProcessSlots<A> {
ProcessSlots {
is_initializer: self.is_initializer,
requires_timed_simulation: self.requires_timed_simulation,
const_delays: self.const_delays,
resume: map(self.resume),
status: map(self.status),
delay: map(self.delay),
Expand Down
33 changes: 29 additions & 4 deletions crates/celox-frontend-core/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,21 @@ impl ProcessKernelBuilder {
let start = builder.current_block();
Self {
builder,
slots,
slots: ProcessSlots {
const_delays: true,
..slots
},
resume_blocks: vec![start],
wait_site: None,
}
}

/// The kernel's control slots, with [`ProcessSlots::const_delays`] set
/// for the delays lowered so far.
pub fn slots(&self) -> ProcessSlots<SourceVarId> {
self.slots
}

/// The SIR builder positioned where the process continues. After
/// [`Self::finish`] no block is open until the caller switches to one.
pub fn builder(&mut self) -> &mut SIRBuilder<RegionedSourceAddr> {
Expand Down Expand Up @@ -135,20 +144,36 @@ impl ProcessKernelBuilder {
/// Suspend for the number of time units in `amount`, an unsigned
/// two-state register of [`PROCESS_DELAY_WIDTH`] bits, and continue at
/// a new resume point. A zero delay resumes after the nonblocking
/// assignments of the time are published.
pub fn delay(&mut self, amount: RegisterId) -> Result<(), ProcessKernelError> {
/// assignments of the time are published. `constant` is the amount's
/// value when the frontend knows it, which it records in
/// [`ProcessSlots::const_delays`].
pub fn delay(
&mut self,
amount: RegisterId,
constant: Option<u64>,
) -> Result<(), ProcessKernelError> {
self.note_delay(constant);
self.store(self.slots.delay, PROCESS_DELAY_WIDTH, amount);
self.suspend(ProcessStatus::Delay)
}

/// A delay with the scheduling of IEEE 1800-2023: a zero delay resumes
/// in the inactive region of the same time (4.4.2.3), before
/// nonblocking assignments are published.
pub fn inactive_delay(&mut self, amount: RegisterId) -> Result<(), ProcessKernelError> {
pub fn inactive_delay(
&mut self,
amount: RegisterId,
constant: Option<u64>,
) -> Result<(), ProcessKernelError> {
self.note_delay(constant);
self.store(self.slots.delay, PROCESS_DELAY_WIDTH, amount);
self.suspend(ProcessStatus::InactiveDelay)
}

fn note_delay(&mut self, constant: Option<u64>) {
self.slots.const_delays &= constant.is_some_and(|amount| amount > 0);
}

/// Return to the runtime, which charges its time-slot budget and
/// resumes the process at once. Frontends place this in loops without
/// timing controls so that a runaway process is reported, not hung in.
Expand Down
24 changes: 22 additions & 2 deletions crates/celox-frontend-core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,23 @@ fn coerce_sir_register(
Ok(current)
}

/// The value of expression `id` as a delay amount, if it is a two-state
/// constant whose coercion to [`PROCESS_DELAY_WIDTH`] bits keeps its value.
fn constant_delay(artifact: &FrontendArtifact, id: ExprId) -> Option<u64> {
let expression = artifact.expression(id)?;
let ExprNode::Constant(value) = expression.node() else {
return None;
};
let value_type = expression.value_type();
let negative = value_type.is_signed()
&& value_type.width() > 0
&& value.payload().bit(value_type.width() as u64 - 1);
if value.mask().bits() != 0 || negative {
return None;
}
u64::try_from(value.payload()).ok()
}

fn coerce_sir_expression(
artifact: &FrontendArtifact,
id: ExprId,
Expand Down Expand Up @@ -1319,6 +1336,7 @@ fn lower_statements(
return Ok(false);
}
Statement::Delay { amount } | Statement::InactiveDelay { amount } => {
let constant = constant_delay(artifact, *amount);
let amount = coerce_sir_expression(
artifact,
*amount,
Expand All @@ -1327,9 +1345,9 @@ fn lower_statements(
&mut cache,
)?;
if matches!(statement, Statement::Delay { .. }) {
kernel.delay(amount)?;
kernel.delay(amount, constant)?;
} else {
kernel.inactive_delay(amount)?;
kernel.inactive_delay(amount, constant)?;
}
}
Statement::WaitEvent { terms } => {
Expand Down Expand Up @@ -1713,6 +1731,7 @@ fn lower_processes(
let slots = ProcessSlots {
is_initializer: false,
requires_timed_simulation: false,
const_delays: false,
resume: lowering
.hidden
.declare(name("resume"), PROCESS_RESUME_WIDTH, false),
Expand All @@ -1728,6 +1747,7 @@ fn lower_processes(
lowering.process_nba_sites = 0;
let mut kernel = ProcessKernelBuilder::new(slots);
lower_statements(&mut lowering, &mut kernel, process.body())?;
let slots = kernel.slots();
let kernel = kernel.build();
candidates.extend(crate::watch::multi_store_candidates(&kernel, |address| {
stable_signal(address, artifact.signals().len())
Expand Down
3 changes: 2 additions & 1 deletion crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4083,6 +4083,7 @@ fn lower_initial_processes(
ProcessSlots {
is_initializer: process.is_initializer(),
requires_timed_simulation: process.is_scheduled_edge(),
const_delays: false,
resume: declare("resume", PROCESS_RESUME_WIDTH),
status: declare("status", PROCESS_STATUS_WIDTH),
delay: declare("delay", PROCESS_DELAY_WIDTH),
Expand Down Expand Up @@ -4127,7 +4128,7 @@ fn lower_initial_processes(
}));
Ok(SymbolicProcess {
kernel: kernel.unit,
slots,
slots: kernel.slots,
origin: process_origin(process),
})
})
Expand Down
15 changes: 14 additions & 1 deletion crates/celox-frontend-sv/src/lowering/ff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4276,10 +4276,12 @@ impl Ff<'_, '_> {
self.exec_block(body)?;
let mut kernel = self.kernel.take().expect("lowering a process kernel");
std::mem::swap(&mut self.b, kernel.builder());
let slots = kernel.slots();
let mut unit = kernel.build();
prune_unreachable_blocks(&mut unit);
Ok(KernelUnit {
unit,
slots,
wait_sites: self.wait_sites,
nba_sites: self.nba_sites,
host_request_sites: self.host_request_sites,
Expand Down Expand Up @@ -4422,13 +4424,23 @@ impl Ff<'_, '_> {
ticks_per_unit: u64,
ticks_per_precision: u64,
) -> Result<(), sv::AnalyzerError> {
// Only integral constants are recorded; a real delay counts as
// variable.
let mut constant = None;
let (mut delay, ticks_per_step) = match self.m.expr_float_precision(amount) {
Some(precision) => (
self.real_delay(amount, precision, ticks_per_unit / ticks_per_precision)?,
ticks_per_precision,
),
None => {
let signed = self.expr_signed(amount);
constant = self
.eval_const(amount)?
.filter(|(value, width)| {
!(signed && *width > 0 && value.bit(*width as u64 - 1))
})
.and_then(|(value, _)| u64::try_from(&value).ok())
.and_then(|value| value.checked_mul(ticks_per_unit));
let mut arena = SLTNodeArena::new();
let node = self.expr_slt(amount, None, &mut arena)?;
let original = self.lower_slt(&arena, node)?;
Expand Down Expand Up @@ -4477,7 +4489,7 @@ impl Ff<'_, '_> {
));
delay = product;
}
self.with_kernel(|kernel| kernel.inactive_delay(delay))
self.with_kernel(|kernel| kernel.inactive_delay(delay, constant))
.map_err(kernel_error)
}

Expand Down Expand Up @@ -4837,6 +4849,7 @@ impl Ff<'_, '_> {
/// The kernel of a process and its wait and nonblocking assignment sites.
pub(super) struct KernelUnit {
pub unit: ExecutionUnit<Addr>,
pub slots: ProcessSlots<SourceVarId>,
pub wait_sites: Vec<WaitSite<SourceVarId>>,
pub nba_sites: Vec<NbaSite<SourceVarId>>,
pub host_request_sites: Vec<celox_design::HostRequestSite<SourceVarId>>,
Expand Down
10 changes: 10 additions & 0 deletions crates/celox-heap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ impl Heap {
self.strings.contains_key(&handle)
}

/// Whether `other` holds the same strings under the same handles, the
/// same strings under construction, and names new strings alike.
pub fn same_contents(&self, other: &Heap) -> bool {
self.strings == other.strings
&& self.next == other.next
&& self.buffers == other.buffers
&& self.free_buffers == other.free_buffers
&& self.pinned == other.pinned
}

/// The number of live strings, including `""`.
pub fn len(&self) -> usize {
self.strings.len()
Expand Down
5 changes: 3 additions & 2 deletions crates/celox-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ pub use reflection::{
};
pub use schedule::{ResolvedSchedule, host_watch};
pub use simulation::{
EventInfo, HostBoundary, ScheduleParts, SimulationExecutor, SimulationSnapshot,
SimulationState, UnitExecutor,
EventInfo, HostBoundary, KernelSchedule, ScheduleKey, ScheduleParts, SchedulerMode,
SchedulerStats, SimulationExecutor, SimulationSnapshot, SimulationState, StepObserver,
UnitExecutor,
};
pub use state_file::{
BaselineRecord, NbaRecord, ProcessRecord, ScheduleRecord, ScheduledEvent, StateDifference,
Expand Down
Loading
Loading