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
13 changes: 7 additions & 6 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,13 @@ pub struct NbaSite<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>,
/// One-bit flag of a site whose destination receives no other
/// nonblocking assignment: a variable of the module with no other
/// nonblocking site in the module and no writer outside it (not a port,
/// not bound to a package variable, not the target of a hierarchical
/// reference). A frontend that cannot tell leaves it `None`, so the
/// assignment goes through the ordered queue.
/// 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,
/// counter, event domain or combinational observer reads it, directly
/// or through combinational logic): publication places flagged updates
/// after the queued ones. Without the flag the assignment goes through
/// the ordered queue.
///
/// The kernel stages the value and sets the flag without returning;
/// publication commits flagged sites and clears the flags. A kernel
Expand Down
49 changes: 49 additions & 0 deletions crates/celox-frontend-core/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,55 @@ impl ProcessKernelBuilder {
Ok(())
}

/// A nonblocking update of `site` with two paths that a load of the
/// one-bit variable `switch` selects. With the switch set, the value
/// `lower` computes is staged as [`Self::nonblocking`] does for a site
/// with a `pending` flag. Otherwise the kernel returns
/// [`ProcessStatus::Nba`] at once, for a site whose value object already
/// holds the value. A frontend emits both before the whole design shows
/// which one may be used; assembly keeps one
/// (`crate::symbolic::artifact::NbaSwitch`).
pub fn nonblocking_switched<E: From<ProcessKernelError>>(
&mut self,
index: u32,
site: &NbaSite<SourceVarId>,
switch: SourceVarId,
lower: impl FnOnce(
&mut SIRBuilder<RegionedSourceAddr>,
) -> Result<(RegisterId, Option<RegisterId>), E>,
) -> Result<(), E> {
assert!(
site.pending.is_some(),
"a switched nonblocking site has a pending flag"
);
let on = self.builder.alloc_bit(1, false);
self.builder.emit(SIRInstruction::Load(
on,
stable(switch),
SIROffset::Static(0),
1,
));
let staged = self.builder.new_block();
let queued = self.builder.new_block();
let join = self.builder.new_block();
self.builder.seal_block(SIRTerminator::Branch {
cond: on,
true_block: (staged, Vec::new()),
false_block: (queued, Vec::new()),
});
self.builder.switch_to_block(staged);
self.nonblocking(index, site, lower)?;
self.builder
.seal_block(SIRTerminator::Jump(join, Vec::new()));
self.builder.switch_to_block(queued);
self.store_delay_constant(u64::from(index));
self.suspend(ProcessStatus::Nba)?;
self.builder
.seal_block(SIRTerminator::Jump(join, Vec::new()));
self.builder.switch_to_block(join);
Ok(())
}

/// 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 @@ -1936,6 +1936,7 @@ pub fn lower_frontend_artifact(
counter_slots,
wait_sites,
nba_sites,
nba_switches: Vec::new(),
host_request_sites: Vec::new(),
time_slot: None,
};
Expand Down
30 changes: 30 additions & 0 deletions crates/celox-frontend-core/src/symbolic/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,43 @@ pub struct SimModule {
/// Nonblocking sites of the module's processes; `process` indexes
/// [`Self::processes`].
pub nba_sites: Vec<NbaSite<SourceVarId>>,
/// Nonblocking sites whose kernel has both a staged and a queued path.
pub nba_switches: Vec<NbaSwitch<SourceVarId>>,
/// Synchronous host operations of the module processes.
pub host_request_sites: Vec<celox_design::HostRequestSite<SourceVarId>>,
/// The variable through which the module's code reads the simulation
/// time; see `RuntimeSchema::time_slots`.
pub time_slot: Option<SourceVarId>,
}

/// A nonblocking site whose kernel has two paths, as
/// `ProcessKernelBuilder::nonblocking_switched` builds them. The staged path
/// stages the value in the site's `value` and sets its `pending` flag; the
/// 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.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct NbaSwitch<A> {
/// The site's `value` object, which identifies the site.
pub value: A,
/// The one-bit variable whose load selects the path. It holds no state:
/// assembly replaces the selection by a jump.
pub switch: A,
/// The value object of the queued path.
pub queued: A,
}

impl<A> 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),
}
}
}

/// The package variable a module variable denotes.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct PackageBinding {
Expand Down
Loading
Loading