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
28 changes: 24 additions & 4 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,9 @@ pub struct NbaSite<A> {
/// 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<A>,
/// For an assignment whose position is computed at run time, the
/// staging objects of the position.
pub position: Option<NbaPosition<A>>,
/// 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,
Expand All @@ -667,12 +667,32 @@ impl<A: Copy> NbaSite<A> {
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<A> {
pub offset: A,
pub width: A,
}

impl<A: Copy> NbaPosition<A> {
pub fn map<B>(&self, mut map: impl FnMut(A) -> B) -> NbaPosition<B> {
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
Expand Down
25 changes: 13 additions & 12 deletions crates/celox-frontend-core/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -274,7 +274,7 @@ impl ProcessKernelBuilder {
site: &NbaSite<SourceVarId>,
lower: impl FnOnce(
&mut SIRBuilder<RegionedSourceAddr>,
) -> Result<(RegisterId, Option<RegisterId>), E>,
) -> Result<(RegisterId, Option<NbaPosition<RegisterId>>), E>,
) -> Result<(), E> {
if let Some(pending) = site.pending {
let flag = self.builder.alloc_bit(1, false);
Expand All @@ -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);
Expand All @@ -327,7 +328,7 @@ impl ProcessKernelBuilder {
switch: SourceVarId,
lower: impl FnOnce(
&mut SIRBuilder<RegionedSourceAddr>,
) -> Result<(RegisterId, Option<RegisterId>), E>,
) -> Result<(RegisterId, Option<NbaPosition<RegisterId>>), E>,
) -> Result<(), E> {
assert!(
site.pending.is_some(),
Expand Down
2 changes: 1 addition & 1 deletion crates/celox-frontend-core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
13 changes: 10 additions & 3 deletions crates/celox-frontend-core/src/symbolic/artifact.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down Expand Up @@ -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<A> {
/// The site's `value` object, which identifies the site.
Expand All @@ -172,14 +173,20 @@ pub struct NbaSwitch<A> {
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<NbaPosition<A>>,
}

impl<A> NbaSwitch<A> {
impl<A: Copy> NbaSwitch<A> {
pub fn map<B>(&self, mut map: impl FnMut(&A) -> B) -> NbaSwitch<B> {
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))),
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion crates/celox-frontend-core/src/symbolic/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,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()))
Expand Down Expand Up @@ -3542,6 +3549,7 @@ fn select_nba_paths(
};
if !staged.contains(&switch.switch) {
site.value = switch.queued;
site.position = switch.queued_position;
site.pending = None;
}
}
Expand Down
Loading
Loading