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
44 changes: 22 additions & 22 deletions conformance/sv-tests/expected.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ chapter-10/10.6.1--assign-deassign.sv 2state fail
chapter-10/10.6.1--assign-deassign.sv 4state fail
chapter-10/10.6.2--force-release.sv 2state fail
chapter-10/10.6.2--force-release.sv 4state fail
chapter-11/11.10--string_bit_array-sim.sv 2state fail
chapter-11/11.10--string_bit_array-sim.sv 4state fail
chapter-11/11.10--string_bit_array.sv 2state fail
chapter-11/11.10--string_bit_array.sv 4state fail
chapter-11/11.10.1--string_compare.sv 2state fail
chapter-11/11.10.1--string_compare.sv 4state fail
chapter-11/11.10--string_bit_array-sim.sv 2state pass
chapter-11/11.10--string_bit_array-sim.sv 4state pass
chapter-11/11.10--string_bit_array.sv 2state pass
chapter-11/11.10--string_bit_array.sv 4state pass
chapter-11/11.10.1--string_compare.sv 2state pass
chapter-11/11.10.1--string_compare.sv 4state pass
chapter-11/11.10.1--string_concat.sv 2state fail
chapter-11/11.10.1--string_concat.sv 4state fail
chapter-11/11.10.1--string_copy.sv 2state fail
chapter-11/11.10.1--string_copy.sv 4state fail
chapter-11/11.10.3--empty_string-sim.sv 2state fail
chapter-11/11.10.3--empty_string-sim.sv 4state fail
chapter-11/11.10.3--empty_string.sv 2state fail
chapter-11/11.10.3--empty_string.sv 4state fail
chapter-11/11.10.1--string_copy.sv 2state pass
chapter-11/11.10.1--string_copy.sv 4state pass
chapter-11/11.10.3--empty_string-sim.sv 2state pass
chapter-11/11.10.3--empty_string-sim.sv 4state pass
chapter-11/11.10.3--empty_string.sv 2state pass
chapter-11/11.10.3--empty_string.sv 4state pass
chapter-11/11.11--min_max_avg_delay.sv 2state pass
chapter-11/11.11--min_max_avg_delay.sv 4state pass
chapter-11/11.12--let_construct.sv 2state fail
Expand Down Expand Up @@ -693,8 +693,8 @@ chapter-20/20.15--dist_poisson.sv 2state fail
chapter-20/20.15--dist_poisson.sv 4state fail
chapter-20/20.15--dist_t.sv 2state fail
chapter-20/20.15--dist_t.sv 4state fail
chapter-20/20.15--dist_uniform.sv 2state fail
chapter-20/20.15--dist_uniform.sv 4state fail
chapter-20/20.15--dist_uniform.sv 2state pass
chapter-20/20.15--dist_uniform.sv 4state pass
chapter-20/20.15--random.sv 2state pass
chapter-20/20.15--random.sv 4state pass
chapter-20/20.2--exit.sv 2state pass
Expand Down Expand Up @@ -815,10 +815,10 @@ chapter-21/21.4--readmemb.sv 2state pass
chapter-21/21.4--readmemb.sv 4state pass
chapter-21/21.4--readmemh.sv 2state pass
chapter-21/21.4--readmemh.sv 4state pass
chapter-21/21.6--test.sv 2state fail
chapter-21/21.6--test.sv 4state fail
chapter-21/21.6--value.sv 2state fail
chapter-21/21.6--value.sv 4state fail
chapter-21/21.6--test.sv 2state pass
chapter-21/21.6--test.sv 4state pass
chapter-21/21.6--value.sv 2state pass
chapter-21/21.6--value.sv 4state pass
chapter-21/21.7--dumpfile.sv 2state fail
chapter-21/21.7--dumpfile.sv 4state fail
chapter-21/21.7--dumpports.sv 2state fail
Expand Down Expand Up @@ -1077,14 +1077,14 @@ chapter-5/5.7.2-real-token.sv 2state fail
chapter-5/5.7.2-real-token.sv 4state fail
chapter-5/5.8-time-literals.sv 2state fail
chapter-5/5.8-time-literals.sv 4state fail
chapter-5/5.9-string-assignment.sv 2state fail
chapter-5/5.9-string-assignment.sv 4state fail
chapter-5/5.9-string-assignment.sv 2state pass
chapter-5/5.9-string-assignment.sv 4state pass
chapter-5/5.9-string-basics.sv 2state pass
chapter-5/5.9-string-basics.sv 4state pass
chapter-5/5.9-string-broken-line.sv 2state pass
chapter-5/5.9-string-broken-line.sv 4state pass
chapter-5/5.9-string-word-assignment.sv 2state fail
chapter-5/5.9-string-word-assignment.sv 4state fail
chapter-5/5.9-string-word-assignment.sv 2state pass
chapter-5/5.9-string-word-assignment.sv 4state pass
chapter-5/5.9.1-string-special-chars.sv 2state pass
chapter-5/5.9.1-string-special-chars.sv 4state pass
chapter-6/6.10--implicit_continuous_assignment.sv 2state fail
Expand Down
147 changes: 147 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ pub enum ProcessStatus {
/// It resumes at the point stored in [`ProcessSlots::resume`] when the
/// simulation continues.
Stop,
/// A synchronous host operation. The delay slot holds its family and
/// local site index; the same process resumes after the host responds.
HostRequest,
}

impl ProcessStatus {
Expand All @@ -266,6 +269,7 @@ impl ProcessStatus {
Self::Nba => 7,
Self::Yield => 8,
Self::Stop => 9,
Self::HostRequest => 10,
}
}

Expand All @@ -280,11 +284,103 @@ impl ProcessStatus {
7 => Some(Self::Nba),
8 => Some(Self::Yield),
9 => Some(Self::Stop),
10 => Some(Self::HostRequest),
_ => None,
}
}
}

/// Family of a synchronous host operation performed by a process kernel.
/// Each family numbers its request sites independently.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum HostRequestKind {
Plusargs,
FileIo,
Vcd,
}

impl HostRequestKind {
/// Encode a request in the process's existing 64-bit delay slot.
pub const fn encode(self, site: u32) -> u64 {
let family = match self {
Self::Plusargs => 1u64,
Self::FileIo => 2,
Self::Vcd => 3,
};
(family << 32) | site as u64
}

/// Decode a request, rejecting unknown families and reserved bits.
pub const fn decode(request: u64) -> Option<(Self, u32)> {
let family = match request >> 32 {
1 => Self::Plusargs,
2 => Self::FileIo,
3 => Self::Vcd,
_ => return None,
};
Some((family, request as u32))
}
}

/// A state slot exchanged with a synchronous host operation.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct HostRequestValue<A> {
pub id: A,
pub width: usize,
pub signed: bool,
pub is_string: bool,
}

impl<A: Copy> HostRequestValue<A> {
pub fn map<B>(&self, map: &mut impl FnMut(A) -> B) -> HostRequestValue<B> {
HostRequestValue {
id: map(self.id),
width: self.width,
signed: self.signed,
is_string: self.is_string,
}
}
}

/// One synchronous host request of a process. Sites are numbered within
/// each process and family in their declaration order. Argument slots are
/// evaluated by the kernel before it suspends; result slots are written by
/// the host before the kernel resumes. `operation` and `strings` are the
/// operation family's stable, backend-independent descriptor.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct HostRequestSite<A> {
pub process: usize,
/// This request belongs to an edge procedure lowered to a scheduled kernel.
pub requires_timed_simulation: bool,
pub kind: HostRequestKind,
pub operation: u32,
pub args: Vec<HostRequestValue<A>>,
pub results: Vec<HostRequestValue<A>>,
pub strings: Vec<String>,
}

impl<A: Copy> HostRequestSite<A> {
pub fn map<B>(&self, mut map: impl FnMut(A) -> B) -> HostRequestSite<B> {
HostRequestSite {
process: self.process,
requires_timed_simulation: self.requires_timed_simulation,
kind: self.kind,
operation: self.operation,
args: self.args.iter().map(|value| value.map(&mut map)).collect(),
results: self
.results
.iter()
.map(|value| value.map(&mut map))
.collect(),
strings: self.strings.clone(),
}
}

pub fn slots(&self) -> impl Iterator<Item = A> + '_ {
self.args.iter().chain(&self.results).map(|value| value.id)
}
}

/// State through which one process kernel exchanges control with the runtime.
///
/// A process kernel is a resumable function. On entry it reads `resume` to
Expand Down Expand Up @@ -602,6 +698,8 @@ pub struct RuntimeSchema<A> {
/// Nonblocking assignment sites of the process kernels, ordered like
/// `wait_sites`.
pub nba_sites: Vec<NbaSite<A>>,
/// Synchronous host operations of the process kernels.
pub host_request_sites: Vec<HostRequestSite<A>>,
/// Canonical event domains whose evaluation commits the results of
/// their blocking assignments, in the active region; their apply units
/// commit only the nonblocking results.
Expand Down Expand Up @@ -632,6 +730,7 @@ impl<A> Default for RuntimeSchema<A> {
watches: Vec::new(),
wait_sites: Vec::new(),
nba_sites: Vec::new(),
host_request_sites: Vec::new(),
active_commits: Vec::new(),
time_slots: Vec::new(),
}
Expand Down Expand Up @@ -1217,6 +1316,54 @@ impl<V: fmt::Display> fmt::Display for RegionedAbsoluteAddrBase<V> {
mod tests {
use super::*;

#[test]
fn host_request_encoding_keeps_families_and_full_site_indices_distinct() {
for kind in [
HostRequestKind::Plusargs,
HostRequestKind::FileIo,
HostRequestKind::Vcd,
] {
for site in [0, 1, u32::MAX] {
assert_eq!(
HostRequestKind::decode(kind.encode(site)),
Some((kind, site))
);
}
}
for invalid in [0, u32::MAX as u64, 4u64 << 32, 1u64 << 63] {
assert_eq!(HostRequestKind::decode(invalid), None);
}
assert_eq!(
ProcessStatus::from_code(10),
Some(ProcessStatus::HostRequest)
);
}

#[test]
fn host_request_mapping_relocates_operands_and_results() {
let value = |id| HostRequestValue {
id,
width: 17,
signed: true,
is_string: false,
};
let site = HostRequestSite {
process: 2,
kind: HostRequestKind::Plusargs,
requires_timed_simulation: false,
operation: 1,
args: vec![value(3u32)],
results: vec![value(5)],
strings: vec!["COUNT=%d".into()],
};
let relocated = site.map(|id| id + 10);
assert_eq!(relocated.slots().collect::<Vec<_>>(), vec![13, 15]);
assert_eq!(relocated.process, 2);
assert_eq!(relocated.args[0].width, 17);
assert!(relocated.results[0].signed);
assert_eq!(relocated.strings, site.strings);
}

#[test]
fn bit_access_splits_only_at_internal_boundaries() {
let access = BitAccess::new(4, 11);
Expand Down
5 changes: 5 additions & 0 deletions crates/celox-design/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub struct ProcessModel<A> {
pub slots: ProcessSlots<A>,
pub waits: Vec<Vec<TermModel<A>>>,
pub nbas: Vec<NbaSite<A>>,
pub host_requests: Vec<crate::HostRequestSite<A>>,
}

/// One term of a wait site.
Expand Down Expand Up @@ -98,6 +99,7 @@ impl<A: Copy + Eq + std::hash::Hash> ScheduleModel<A> {
slots: *slots,
waits: Vec::new(),
nbas: Vec::new(),
host_requests: Vec::new(),
})
.collect();
for site in &schema.wait_sites {
Expand All @@ -115,6 +117,9 @@ impl<A: Copy + Eq + std::hash::Hash> ScheduleModel<A> {
for site in &schema.nba_sites {
processes[site.process].nbas.push(site.clone());
}
for site in &schema.host_request_sites {
processes[site.process].host_requests.push(site.clone());
}
let waited = schema
.wait_sites
.iter()
Expand Down
15 changes: 13 additions & 2 deletions crates/celox-frontend-core/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
//! [`WaitSite`]: celox_design::WaitSite

use celox_design::{
NbaSite, PROCESS_DELAY_WIDTH, PROCESS_STATUS_WIDTH, ProcessSlots, ProcessStatus,
RegionedVarAddrBase, STABLE_REGION,
HostRequestKind, NbaSite, PROCESS_DELAY_WIDTH, PROCESS_STATUS_WIDTH, ProcessSlots,
ProcessStatus, RegionedVarAddrBase, STABLE_REGION,
};
use celox_sir::{
BlockId, ExecutionUnit, RegisterId, SIRBuilder, SIRInstruction, SIROffset, SIRSwitchCase,
Expand Down Expand Up @@ -162,6 +162,17 @@ impl ProcessKernelBuilder {
self.suspend(ProcessStatus::Stop)
}

/// Perform a synchronous host operation, then continue at a new resume
/// point. Arguments and results live in the request site's state slots.
pub fn host_request(
&mut self,
kind: HostRequestKind,
site: u32,
) -> Result<(), ProcessKernelError> {
self.store_delay_constant(kind.encode(site));
self.suspend(ProcessStatus::HostRequest)
}

/// Suspend at wait site `site` of this process. The open block
/// afterwards is the site's resume point: the caller lowers the wait's
/// condition there and ends it with [`Self::wake_if`].
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 @@ -1924,6 +1924,7 @@ pub fn lower_frontend_artifact(
counter_slots,
wait_sites,
nba_sites,
host_request_sites: Vec::new(),
time_slot: None,
};
let symbolic = SymbolicRtl {
Expand Down
2 changes: 2 additions & 0 deletions crates/celox-frontend-core/src/symbolic/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ pub struct SimModule {
/// Nonblocking sites of the module's processes; `process` indexes
/// [`Self::processes`].
pub nba_sites: Vec<NbaSite<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>,
Expand Down
Loading
Loading