diff --git a/crates/celox-design/src/lib.rs b/crates/celox-design/src/lib.rs
index e85b91d5cc7..62994649eaa 100644
--- a/crates/celox-design/src/lib.rs
+++ b/crates/celox-design/src/lib.rs
@@ -646,9 +646,9 @@ pub struct NbaSite {
/// 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,
+ /// For an assignment whose position is computed at run time, the
+ /// staging objects of the position.
+ pub position: Option>,
/// One-bit flag of a site whose destination has no other writer in the
/// design (no other nonblocking site, no store of any unit, not a
/// top-level port) and whose update order nothing observes (no wait,
@@ -672,12 +672,32 @@ impl NbaSite {
lsb: self.lsb,
width: self.width,
value: map(self.value),
- offset: self.offset.map(&mut map),
+ position: self.position.map(|position| position.map(&mut map)),
pending: self.pending.map(&mut map),
}
}
}
+/// The run-time position of a nonblocking assignment: two-state staging
+/// objects holding a bit offset added to the site's `lsb` and the number of
+/// bits written there, the low bits of the value and at most the site's
+/// `width`. Zero bits write nothing, as for a position outside the target
+/// or one with an unknown bit (IEEE 1800-2023 7.4.6, 11.5.1).
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
+pub struct NbaPosition {
+ pub offset: A,
+ pub width: A,
+}
+
+impl NbaPosition {
+ pub fn map(&self, mut map: impl FnMut(A) -> B) -> NbaPosition {
+ NbaPosition {
+ offset: map(self.offset),
+ width: map(self.width),
+ }
+ }
+}
+
/// Controls which combinational stores dead store elimination preserves.
///
/// The policy is part of the runtime contract: host-side handles resolve
@@ -860,10 +880,12 @@ pub struct RuntimeSchema {
/// Width of [`SchedulerSlots::limit`], [`SchedulerSlots::now`],
/// [`SchedulerSlots::exit_arg`], [`SchedulerSlots::count`],
-/// [`SchedulerSlots::current`], [`SchedulerSlots::levels`] and every [`SchedulerSlots::wake`] object.
+/// [`SchedulerSlots::current`], [`SchedulerSlots::levels`],
+/// [`SchedulerSlots::ready`] and every [`SchedulerSlots::wake`] object.
pub const SCHEDULER_TIME_WIDTH: usize = 64;
/// Width of [`SchedulerSlots::exit`], [`SchedulerSlots::finish`],
-/// [`SchedulerSlots::cont`] and every [`SchedulerSlots::waiting`] object.
+/// [`SchedulerSlots::cont`] and every [`SchedulerSlots::waiting`] and
+/// [`SchedulerSlots::baseline`] object.
pub const SCHEDULER_FLAG_WIDTH: usize = 8;
/// Hidden state objects through which a compiled scheduler and the runtime
@@ -891,11 +913,16 @@ pub struct SchedulerSlots {
/// The levels of the event signals at the start of the last slot, one
/// bit per event in event order.
pub levels: A,
+ /// The kernels ready to run in the current slot, one bit per kernel in
+ /// kernel order.
+ pub ready: A,
/// The time each process kernel resumes at, in kernel order, valid
/// where [`Self::waiting`] is set.
pub wake: Vec,
- /// Whether each process kernel waits for its wake time.
+ /// Whether each process kernel waits for its wake time or event.
pub waiting: Vec,
+ /// The level a kernel waiting for an event last saw its signal at.
+ pub baseline: Vec,
}
impl SchedulerSlots {
@@ -910,8 +937,10 @@ impl SchedulerSlots {
count: map(self.count),
current: map(self.current),
levels: map(self.levels),
+ ready: map(self.ready),
wake: self.wake.into_iter().map(&mut map).collect(),
- waiting: self.waiting.into_iter().map(map).collect(),
+ waiting: self.waiting.into_iter().map(&mut map).collect(),
+ baseline: self.baseline.into_iter().map(map).collect(),
}
}
@@ -927,10 +956,12 @@ impl SchedulerSlots {
&self.count,
&self.current,
&self.levels,
+ &self.ready,
]
.into_iter()
.chain(&self.wake)
.chain(&self.waiting)
+ .chain(&self.baseline)
}
}
diff --git a/crates/celox-frontend-core/src/process.rs b/crates/celox-frontend-core/src/process.rs
index 8f8c1373831..1931a26203b 100644
--- a/crates/celox-frontend-core/src/process.rs
+++ b/crates/celox-frontend-core/src/process.rs
@@ -21,7 +21,7 @@
//! [`WaitSite`]: celox_design::WaitSite
use celox_design::{
- HostRequestKind, NbaSite, PROCESS_DELAY_WIDTH, PROCESS_STATUS_WIDTH, ProcessSlots,
+ HostRequestKind, NbaPosition, NbaSite, PROCESS_DELAY_WIDTH, PROCESS_STATUS_WIDTH, ProcessSlots,
ProcessStatus, RegionedVarAddrBase, STABLE_REGION,
};
use celox_sir::{
@@ -50,9 +50,9 @@ pub enum ProcessKernelError {
TooManySuspensions,
}
-/// Width of the bit offset staged by a nonblocking assignment whose position
-/// is computed at run time ([`NbaSite::offset`]).
-pub const NBA_OFFSET_WIDTH: usize = 64;
+/// Width of the bit offset and of the bit count staged by a nonblocking
+/// assignment whose position is computed at run time ([`NbaPosition`]).
+pub const NBA_POSITION_WIDTH: usize = 64;
/// Builder of one process kernel.
pub struct ProcessKernelBuilder {
@@ -259,9 +259,9 @@ impl ProcessKernelBuilder {
/// process, described by `site`: schedule a value for the NBA region of
/// the current time (IEEE 1800-2023 10.4.2). `lower` lowers the
/// right-hand side at the open block and returns the value, a register
- /// of `site.width` bits, and for a site with a run-time position the
- /// bit offset, an unsigned two-state register of [`NBA_OFFSET_WIDTH`]
- /// bits.
+ /// of `site.width` bits, and for a site with a run-time position the bit
+ /// offset and the number of bits written, unsigned two-state registers
+ /// of [`NBA_POSITION_WIDTH`] bits.
///
/// A site with a `pending` flag stages the value without returning. If
/// the flag is still set from an earlier execution in the same time
@@ -274,7 +274,7 @@ impl ProcessKernelBuilder {
site: &NbaSite,
lower: impl FnOnce(
&mut SIRBuilder,
- ) -> Result<(RegisterId, Option), E>,
+ ) -> Result<(RegisterId, Option>), E>,
) -> Result<(), E> {
if let Some(pending) = site.pending {
let flag = self.builder.alloc_bit(1, false);
@@ -298,10 +298,11 @@ impl ProcessKernelBuilder {
.seal_block(SIRTerminator::Jump(stage, Vec::new()));
self.builder.switch_to_block(stage);
}
- let (value, offset) = lower(&mut self.builder)?;
+ let (value, position) = lower(&mut self.builder)?;
self.store(site.value, site.width, value);
- if let (Some(slot), Some(offset)) = (site.offset, offset) {
- self.store(slot, NBA_OFFSET_WIDTH, offset);
+ if let (Some(slots), Some(position)) = (site.position, position) {
+ self.store(slots.offset, NBA_POSITION_WIDTH, position.offset);
+ self.store(slots.width, NBA_POSITION_WIDTH, position.width);
}
if let Some(pending) = site.pending {
self.store_constant(pending, 1, 1);
@@ -327,7 +328,7 @@ impl ProcessKernelBuilder {
switch: SourceVarId,
lower: impl FnOnce(
&mut SIRBuilder,
- ) -> Result<(RegisterId, Option), E>,
+ ) -> Result<(RegisterId, Option>), E>,
) -> Result<(), E> {
assert!(
site.pending.is_some(),
diff --git a/crates/celox-frontend-core/src/sdk.rs b/crates/celox-frontend-core/src/sdk.rs
index 88633549f9f..f74172ab2a4 100644
--- a/crates/celox-frontend-core/src/sdk.rs
+++ b/crates/celox-frontend-core/src/sdk.rs
@@ -1425,7 +1425,7 @@ fn lower_statements(
lsb: target.lsb(),
width: target.width(),
value: staged,
- offset: None,
+ position: None,
pending,
};
kernel.nonblocking(index, &site, |builder| {
diff --git a/crates/celox-frontend-core/src/symbolic/artifact.rs b/crates/celox-frontend-core/src/symbolic/artifact.rs
index cf8d54a5bba..ec42afd1a4a 100644
--- a/crates/celox-frontend-core/src/symbolic/artifact.rs
+++ b/crates/celox-frontend-core/src/symbolic/artifact.rs
@@ -1,7 +1,7 @@
use std::{collections::BTreeSet, fmt};
use celox_design::{
- CounterSlots, ExternFunction, InitialStateValue, ModuleId, NbaSite, ProcessSlots,
+ CounterSlots, ExternFunction, InitialStateValue, ModuleId, NbaPosition, NbaSite, ProcessSlots,
RegionedAbsoluteAddrBase, RegionedVarAddrBase, RuntimeErrorInfo, RuntimeEventSite, TriggerSet,
VarAtomBase, VariableMetadata, WaitSite,
};
@@ -162,7 +162,8 @@ pub struct SimModule {
/// queued path leaves the value in `queued` and returns to the runtime.
/// Assembly keeps one path: the staged one only if nothing else writes the
/// site's target and nothing can observe when the target is updated. For the
-/// queued path it makes `queued` the site's value and drops the flag.
+/// queued path it makes `queued` the site's value and `queued_position` its
+/// position, and drops the flag.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct NbaSwitch {
/// The site's `value` object, which identifies the site.
@@ -172,14 +173,20 @@ pub struct NbaSwitch {
pub switch: A,
/// The value object of the queued path.
pub queued: A,
+ /// The position objects of the queued path, for a site with a run-time
+ /// position.
+ pub queued_position: Option>,
}
-impl NbaSwitch {
+impl NbaSwitch {
pub fn map(&self, mut map: impl FnMut(&A) -> B) -> NbaSwitch {
NbaSwitch {
value: map(&self.value),
switch: map(&self.switch),
queued: map(&self.queued),
+ queued_position: self
+ .queued_position
+ .map(|position| position.map(|var| map(&var))),
}
}
}
diff --git a/crates/celox-frontend-core/src/symbolic/assembly.rs b/crates/celox-frontend-core/src/symbolic/assembly.rs
index 1fe600a2173..8022c93abd2 100644
--- a/crates/celox-frontend-core/src/symbolic/assembly.rs
+++ b/crates/celox-frontend-core/src/symbolic/assembly.rs
@@ -2090,7 +2090,14 @@ pub fn schedule_symbolic_rtl_reporting_loops(
.chain(
nba_sites
.iter()
- .flat_map(|site| [Some(site.value), site.offset, site.pending])
+ .flat_map(|site| {
+ [
+ Some(site.value),
+ site.position.map(|position| position.offset),
+ site.position.map(|position| position.width),
+ site.pending,
+ ]
+ })
.flatten(),
)
.chain(host_request_sites.iter().flat_map(|site| site.slots()))
@@ -2259,12 +2266,16 @@ fn declare_scheduler_slots(
count: declare("count".into(), TIME),
current: declare("current".into(), TIME),
levels: declare("levels".into(), TIME),
+ ready: declare("ready".into(), TIME),
wake: (0..process_count)
.map(|index| declare(format!("wake[{index}]"), TIME))
.collect(),
waiting: (0..process_count)
.map(|index| declare(format!("waiting[{index}]"), FLAG))
.collect(),
+ baseline: (0..process_count)
+ .map(|index| declare(format!("baseline[{index}]"), FLAG))
+ .collect(),
})
}
@@ -3645,6 +3656,7 @@ fn select_nba_paths(
};
if !staged.contains(&switch.switch) {
site.value = switch.queued;
+ site.position = switch.queued_position;
site.pending = None;
}
}
diff --git a/crates/celox-frontend-sv/src/lowering/ff.rs b/crates/celox-frontend-sv/src/lowering/ff.rs
index 9e44351660d..2784a824630 100644
--- a/crates/celox-frontend-sv/src/lowering/ff.rs
+++ b/crates/celox-frontend-sv/src/lowering/ff.rs
@@ -17,8 +17,8 @@ mod strings;
use super::procedural::*;
use super::*;
-use celox_design::{CounterKind, NbaSite, SPARSE_WORKING_REGION, WaitSite};
-use celox_frontend_core::process::{ProcessKernelBuilder, ProcessKernelError};
+use celox_design::{CounterKind, 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;
use num_traits::{ToPrimitive, Zero};
@@ -4101,6 +4101,36 @@ pub(super) struct FfProcessUnits {
pub staged: Vec<(SourceVarId, SourceVarId, SourceVarId)>,
}
+/// A part of a nonblocking assignment in a process: it takes `width` bits
+/// of the right-hand side and writes them into `id` as `place` says.
+struct NbaTarget {
+ id: SourceVarId,
+ width: usize,
+ /// For a slice of an unpacked array whose range runs against the
+ /// array's, the element width: the part's elements are written in
+ /// reverse order.
+ reversed: Option,
+ place: NbaPlace,
+}
+
+enum NbaPlace {
+ /// A constant position: the part's bits from `drop` up, `width` of them,
+ /// are written at bit `lsb`. A position outside the target writes none.
+ Static {
+ lsb: usize,
+ width: usize,
+ drop: usize,
+ },
+ /// A position evaluated at run time into the variables of `position`,
+ /// an offset from bit `lsb`. The part is shifted down first by the
+ /// value of the variable `drop`, the bits that fall below the target.
+ Dynamic {
+ lsb: usize,
+ position: NbaPosition,
+ drop: Option,
+ },
+}
+
/// The staging of a variable a process writes both by blocking and by
/// nonblocking assignments: the nonblocking value and a mask of the bits
/// the nonblocking assignments wrote.
@@ -4329,8 +4359,9 @@ impl Ff<'_, '_> {
}
/// A nonblocking assignment in a process (IEEE 1800-2023 10.4.2): the
- /// right-hand side is evaluated now, once, and each target part becomes
- /// an update the runtime queues for the NBA region.
+ /// positions of the targets and the right-hand side are evaluated now,
+ /// once, and each target part becomes an update the runtime queues for
+ /// the NBA region.
fn nonblocking(
&mut self,
parts: &[sv::ir::LValue],
@@ -4338,61 +4369,120 @@ impl Ff<'_, '_> {
) -> Result<(), sv::AnalyzerError> {
let mut targets = Vec::with_capacity(parts.len());
for part in parts {
- targets.push(self.nba_target(part)?);
+ let part = self.propagate_lvalue(part);
+ let part = self.hoist_lvalue(&part)?;
+ targets.push(self.nba_target(&part)?);
}
- let total: usize = targets.iter().map(|(_, _, width)| width).sum();
- let four_state = targets.iter().any(|(id, _, _)| self.m.var(*id).is_4state);
+ let total: usize = targets.iter().map(|target| target.width).sum();
+ let four_state = targets.iter().any(|target| self.m.var(target.id).is_4state);
let (_, value_name) = self.m.temp("nba", total, false, four_state);
self.assign(&sv::ir::LValue::Ident(value_name.clone()), rhs)?;
// The parts, most significant first, take consecutive bits of the
// value.
let mut high = total;
- for (id, lsb, width) in targets {
- let low = high - width;
+ for target in targets {
+ let low = high - target.width;
+ high = low;
+ let id = target.id;
+ let select = |name: &str, msb: usize, lsb: usize| sv::ir::Expr::Select {
+ expr: Box::new(sv::ir::Expr::Ident(name.to_string())),
+ msb: sv::ir::ConstExpr::Literal(msb.to_string()),
+ lsb: sv::ir::ConstExpr::Literal(lsb.to_string()),
+ signed: false,
+ };
+ let (source, low) = match target.reversed {
+ Some(element_width) => {
+ let (_, name) = self.m.temp("nba_order", target.width, false, four_state);
+ let elements = (0..target.width / element_width)
+ .map(|element| {
+ let bottom = low + element * element_width;
+ select(&value_name, bottom + element_width - 1, bottom)
+ })
+ .collect();
+ self.assign(
+ &sv::ir::LValue::Ident(name.clone()),
+ &sv::ir::Expr::Concat(elements),
+ )?;
+ (name, 0)
+ }
+ None => (value_name.clone(), low),
+ };
+ let part = |msb: usize, lsb: usize| select(&source, msb, lsb);
+ let (lsb, width, value, position) = match target.place {
+ NbaPlace::Static { lsb, width, drop } => {
+ if width == 0 {
+ continue;
+ }
+ let from = low + drop;
+ (lsb, width, part(from + width - 1, from), None)
+ }
+ NbaPlace::Dynamic {
+ lsb,
+ position,
+ drop,
+ } => {
+ let value = part(low + target.width - 1, low);
+ let value = match drop {
+ Some(drop) => sv::ir::Expr::Binary {
+ left: Box::new(value),
+ op: sv::ir::BinaryOp::Shr,
+ right: Box::new(sv::ir::Expr::Ident(drop)),
+ },
+ None => value,
+ };
+ (lsb, target.width, value, Some(position))
+ }
+ };
let (staged, staged_name) =
self.m
.temp("nba_part", width, false, self.m.var(id).is_4state);
- self.assign(
- &sv::ir::LValue::Ident(staged_name),
- &sv::ir::Expr::Select {
- expr: Box::new(sv::ir::Expr::Ident(value_name.clone())),
- msb: sv::ir::ConstExpr::Literal((high - 1).to_string()),
- lsb: sv::ir::ConstExpr::Literal(low.to_string()),
- signed: false,
- },
- )?;
- high = low;
- // The staged value has an object of its own: a value still
- // staged from earlier in the time slot is queued before it is
- // replaced. Assembly keeps the staged or the queued path.
+ self.assign(&sv::ir::LValue::Ident(staged_name), &value)?;
+ // The staged value and position have objects of their own: a
+ // value still staged from earlier in the time slot is queued
+ // before they are replaced. Assembly keeps the staged or the
+ // queued path.
let staged_four_state = self.m.var(staged).is_4state;
let (value, _) = self.m.temp("nba_value", width, false, staged_four_state);
let (pending, _) = self.m.temp("nba_pending", 1, false, false);
let (switch, _) = self.m.temp("nba_staged", 1, false, false);
+ let slots = position.map(|_| NbaPosition {
+ offset: self
+ .m
+ .temp("nba_offset", NBA_POSITION_WIDTH, false, false)
+ .0,
+ width: self.m.temp("nba_width", NBA_POSITION_WIDTH, false, false).0,
+ });
let site = NbaSite {
process: self.process,
target: id,
lsb,
width,
value,
- offset: None,
+ position: slots,
pending: Some(pending),
};
let index = self.nba_sites.len() as u32;
self.with_kernel(|kernel| {
kernel.nonblocking_switched(index, &site, switch, |builder| {
- let value = if staged_four_state {
- builder.alloc_logic(width)
- } else {
- builder.alloc_bit(width, false)
+ let load = |builder: &mut SIRBuilder<_>, var, width, four_state| {
+ let register = if four_state {
+ builder.alloc_logic(width)
+ } else {
+ builder.alloc_bit(width, false)
+ };
+ builder.emit(SIRInstruction::Load(
+ register,
+ stable(var),
+ SIROffset::Static(0),
+ width,
+ ));
+ register
};
- builder.emit(SIRInstruction::Load(
- value,
- stable(staged),
- SIROffset::Static(0),
- width,
- ));
- Ok::<_, ProcessKernelError>((value, None))
+ let value = load(builder, staged, width, staged_four_state);
+ let position = position.map(|position: NbaPosition| {
+ position.map(|var| load(builder, var, NBA_POSITION_WIDTH, false))
+ });
+ Ok::<_, ProcessKernelError>((value, position))
})
})
.map_err(kernel_error)?;
@@ -4400,57 +4490,268 @@ impl Ff<'_, '_> {
value,
switch,
queued: staged,
+ queued_position: position,
});
self.nba_sites.push(site);
}
Ok(())
}
- /// The variable and the constant bit range a nonblocking assignment in
- /// a process writes.
- fn nba_target(
- &self,
- lvalue: &sv::ir::LValue,
- ) -> Result<(SourceVarId, usize, usize), sv::AnalyzerError> {
+ /// The variable a part of a nonblocking assignment in a process writes
+ /// and where. A position is evaluated now; bits outside the target, and
+ /// a position with an unknown bit, write nothing (IEEE 1800-2023 7.4.6,
+ /// 11.5.1).
+ fn nba_target(&mut self, lvalue: &sv::ir::LValue) -> Result {
let id = self
.m
.id(lvalue.name())
.ok_or_else(|| unsupported(format!("assignment target `{}`", lvalue.name())))?;
let variable = self.m.var(id);
- if !variable.array_dims.is_empty() {
+ let var_width = variable.width;
+ let (msb, lsb) = match lvalue {
+ sv::ir::LValue::Ident(_) => {
+ return Ok(NbaTarget {
+ id,
+ width: var_width,
+ reversed: None,
+ place: NbaPlace::Static {
+ lsb: 0,
+ width: var_width,
+ drop: 0,
+ },
+ });
+ }
+ sv::ir::LValue::Select { msb, lsb, .. } => (msb, lsb),
+ };
+ let constants = self.m.constants;
+ let parameter_types = self.m.parameter_types;
+ let constant =
+ |expr| sv::typecheck::eval_const_expr_with_types(expr, constants, parameter_types);
+ // A slice of an unpacked array whose range runs against the array's
+ // takes the elements of the value in reverse order.
+ let reversed = match lvalue {
+ sv::ir::LValue::Select {
+ array_slice_width: Some(element_width),
+ array_slice_reversed: true,
+ ..
+ } => Some(
+ constant(element_width)
+ .and_then(|width| usize::try_from(width).ok())
+ .filter(|width| *width != 0)
+ .ok_or_else(|| unsupported("assignment lvalue order"))?,
+ ),
+ _ => None,
+ };
+ if let (Some(msb), Some(lsb)) = (constant(msb), constant(lsb)) {
+ let (Some(msb), Some(lsb)) = (
+ packed_index_position(variable, msb),
+ packed_index_position(variable, lsb),
+ ) else {
+ return Err(unsupported("nonblocking assignment position"));
+ };
+ if msb < lsb {
+ return Err(unsupported(
+ "nonblocking assignment to a reversed part select in a process",
+ ));
+ }
+ let width = usize::try_from(msb - lsb + 1)
+ .map_err(|_| unsupported("nonblocking assignment position"))?;
+ let top = i128::try_from(var_width).unwrap_or(i128::MAX);
+ let start = lsb.clamp(0, top);
+ let end = (msb + 1).clamp(0, top);
+ let (start, written) = if start < end {
+ (start, end - start)
+ } else {
+ (0, 0)
+ };
+ if reversed.is_some_and(|element_width| !width.is_multiple_of(element_width)) {
+ return Err(unsupported("assignment lvalue order"));
+ }
+ return Ok(NbaTarget {
+ id,
+ width,
+ reversed,
+ place: NbaPlace::Static {
+ lsb: start as usize,
+ width: written as usize,
+ drop: if written == 0 {
+ 0
+ } else {
+ (start - lsb) as usize
+ },
+ },
+ });
+ }
+ if reversed.is_some() {
return Err(unsupported(
- "nonblocking assignment to an unpacked array in a process",
+ "nonblocking assignment to a reversed array slice at a run-time position",
));
}
- match lvalue {
- sv::ir::LValue::Ident(_) => Ok((id, 0, variable.width)),
- sv::ir::LValue::Select { msb, lsb, .. } => {
- let constant = |expr| {
- sv::typecheck::eval_const_expr_with_types(
- expr,
- self.m.constants,
- self.m.parameter_types,
- )
- };
- let (Some(msb), Some(lsb)) = (constant(msb), constant(lsb)) else {
- return Err(unsupported(
- "nonblocking assignment with a run-time position in a process",
- ));
- };
- let (Some(msb), Some(lsb)) = (
- packed_index_offset(variable, msb),
- packed_index_offset(variable, lsb),
- ) else {
- return Err(unsupported("nonblocking assignment outside its target"));
- };
- if msb < lsb {
- return Err(unsupported(
- "nonblocking assignment to a reversed part select in a process",
- ));
- }
- Ok((id, lsb, msb - lsb + 1))
+ let mut arena = SLTNodeArena::new();
+ if let Some((_, element_width, offset, access)) = dynamic_array_element_lvalue(
+ lvalue,
+ self.m.variables,
+ self.m.name_to_id,
+ constants,
+ parameter_types,
+ ) {
+ // A run-time element: its whole selected part or nothing.
+ let width = access.msb - access.lsb + 1;
+ let offset = expr_from_const_expr(&offset)
+ .ok_or_else(|| unsupported("dynamic assignment index"))?;
+ let offset = self.propagate(&offset);
+ let (bit_offset, _) = lower_expr_with_context(
+ &offset,
+ self.m.variables,
+ self.m.name_to_id,
+ constants,
+ parameter_types,
+ &mut arena,
+ None,
+ None,
+ )
+ .ok_or_else(|| unsupported("dynamic assignment index"))?;
+ let bit_offset =
+ coerce_node_width(&mut arena, bit_offset, Some(NBA_POSITION_WIDTH), false)
+ .map_err(slt_error)?;
+ let stride = slt_constant(&mut arena, BigUint::from(element_width), 64, false)?;
+ let index = arena
+ .alloc(SLTNode::Binary(bit_offset, BinaryOp::DivU, stride))
+ .map_err(slt_error)?;
+ let (index, valid) =
+ dynamic_array_index_guard_slt(&mut arena, index, var_width / element_width.max(1))
+ .ok_or_else(|| unsupported("dynamic assignment index"))?;
+ let offset = arena
+ .alloc(SLTNode::Binary(index, BinaryOp::Mul, stride))
+ .map_err(slt_error)?;
+ let full = slt_constant(&mut arena, BigUint::from(width), 64, false)?;
+ let zero = slt_constant(&mut arena, BigUint::zero(), 64, false)?;
+ let written = arena
+ .alloc(SLTNode::Mux {
+ cond: valid,
+ then_expr: full,
+ else_expr: zero,
+ })
+ .map_err(slt_error)?;
+ let position = NbaPosition {
+ offset: self.nba_position_temp("nba_at", &arena, offset)?,
+ width: self.nba_position_temp("nba_bits", &arena, written)?,
+ };
+ return Ok(NbaTarget {
+ id,
+ width,
+ reversed: None,
+ place: NbaPlace::Dynamic {
+ lsb: access.lsb,
+ position,
+ drop: None,
+ },
+ });
+ }
+ let write = dynamic_packed_write(
+ lvalue,
+ self.m.variables,
+ self.m.name_to_id,
+ constants,
+ parameter_types,
+ )
+ .ok_or_else(|| unsupported(format!("assignment target `{}`", lvalue.name())))?;
+ // A run-time part select: the bits of it inside the target, or
+ // inside the array element it stays within.
+ let shift = |expr: &sv::ir::Expr, arena: &mut SLTNodeArena| {
+ let (node, _) = lower_expr_with_context(
+ &self.propagate(expr),
+ self.m.variables,
+ self.m.name_to_id,
+ constants,
+ parameter_types,
+ arena,
+ None,
+ Some(false),
+ )
+ .ok_or_else(|| unsupported("dynamic assignment position"))?;
+ coerce_node_width(arena, node, Some(NBA_POSITION_WIDTH), false).map_err(slt_error)
+ };
+ let up = shift(&write.up, &mut arena)?;
+ let down = shift(&write.down, &mut arena)?;
+ let window = write
+ .window
+ .unwrap_or_else(|| BitAccess::new(0, var_width - 1));
+ let binary = |arena: &mut SLTNodeArena, left, op, right| {
+ arena
+ .alloc(SLTNode::Binary(left, op, right))
+ .map_err(slt_error)
+ };
+ let mux = |arena: &mut SLTNodeArena, cond, then_expr, else_expr| {
+ arena
+ .alloc(SLTNode::Mux {
+ cond,
+ then_expr,
+ else_expr,
+ })
+ .map_err(slt_error)
+ };
+ let constant = |arena: &mut SLTNodeArena, value: usize| {
+ slt_constant(arena, BigUint::from(value), NBA_POSITION_WIDTH, false)
+ };
+ // The select's bit 0 sits at `up - down`, which may be below the
+ // bottom of the window; the comparisons are signed.
+ let at = binary(&mut arena, up, BinaryOp::Sub, down)?;
+ let bottom = constant(&mut arena, window.lsb)?;
+ let top = constant(&mut arena, window.msb + 1)?;
+ let select_width = constant(&mut arena, write.select_width)?;
+ let below = binary(&mut arena, at, BinaryOp::LtS, bottom)?;
+ let start = mux(&mut arena, below, bottom, at)?;
+ let reach = binary(&mut arena, at, BinaryOp::Add, select_width)?;
+ let above = binary(&mut arena, reach, BinaryOp::GtS, top)?;
+ let end = mux(&mut arena, above, top, reach)?;
+ let mut valid = binary(&mut arena, start, BinaryOp::LtS, end)?;
+ if self.m.four_state {
+ for position in [up, down] {
+ let two_state = arena
+ .alloc(SLTNode::Unary(UnaryOp::ToTwoState, position))
+ .map_err(slt_error)?;
+ let known = binary(&mut arena, position, BinaryOp::EqCase, two_state)?;
+ valid = slt_and(&mut arena, &mut ConstCache::default(), valid, known)?;
}
}
+ let zero = constant(&mut arena, 0)?;
+ let span = binary(&mut arena, end, BinaryOp::Sub, start)?;
+ let written = mux(&mut arena, valid, span, zero)?;
+ let offset = mux(&mut arena, valid, start, zero)?;
+ let skipped = binary(&mut arena, start, BinaryOp::Sub, at)?;
+ let skipped = mux(&mut arena, valid, skipped, zero)?;
+ let position = NbaPosition {
+ offset: self.nba_position_temp("nba_at", &arena, offset)?,
+ width: self.nba_position_temp("nba_bits", &arena, written)?,
+ };
+ let (drop, drop_name) = self.m.temp("nba_drop", NBA_POSITION_WIDTH, false, false);
+ let skipped = self.lower_slt(&arena, skipped)?;
+ self.store(drop, SIROffset::Static(0), NBA_POSITION_WIDTH, skipped);
+ Ok(NbaTarget {
+ id,
+ width: write.select_width,
+ reversed: None,
+ place: NbaPlace::Dynamic {
+ lsb: 0,
+ position,
+ drop: Some(drop_name),
+ },
+ })
+ }
+
+ /// A new two-state variable of [`NBA_POSITION_WIDTH`] bits holding the
+ /// value of `node`, evaluated now.
+ fn nba_position_temp(
+ &mut self,
+ purpose: &str,
+ arena: &SLTNodeArena,
+ node: NodeId,
+ ) -> Result {
+ let (temp, _) = self.m.temp(purpose, NBA_POSITION_WIDTH, false, false);
+ let value = self.lower_slt(arena, node)?;
+ self.store(temp, SIROffset::Static(0), NBA_POSITION_WIDTH, value);
+ Ok(temp)
}
/// `#amount` (IEEE 1800-2023 9.4.1). The amount is self-determined and
diff --git a/crates/celox-runtime/src/schedule.rs b/crates/celox-runtime/src/schedule.rs
index 4085f6d7977..73f9bf955f7 100644
--- a/crates/celox-runtime/src/schedule.rs
+++ b/crates/celox-runtime/src/schedule.rs
@@ -59,9 +59,18 @@ pub(crate) struct SchedulerRefs {
pub(crate) count: SignalRef,
pub(crate) current: SignalRef,
pub(crate) levels: SignalRef,
- /// The wake and waiting slots of each kernel the scheduler runs, by
- /// process index.
+ pub(crate) ready: SignalRef,
+ /// The wake and waiting slots of each kernel the scheduler runs that
+ /// only delays, by process index.
pub(crate) wake: Vec