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: 2 additions & 2 deletions conformance/sv-tests/expected.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -1625,8 +1625,8 @@ chapter-9/9.4.2.1--event_or_op.sv 2state pass
chapter-9/9.4.2.1--event_or_op.sv 4state pass
chapter-9/9.4.2.2--event_implicit.sv 2state pass
chapter-9/9.4.2.2--event_implicit.sv 4state pass
chapter-9/9.4.2.3--event_conditional.sv 2state fail
chapter-9/9.4.2.3--event_conditional.sv 4state fail
chapter-9/9.4.2.3--event_conditional.sv 2state pass
chapter-9/9.4.2.3--event_conditional.sv 4state pass
chapter-9/9.4.2.4--event_sequence.sv 2state fail
chapter-9/9.4.2.4--event_sequence.sv 4state fail
chapter-9/9.4.3--event_sequence_controls.sv 2state pass
Expand Down
71 changes: 71 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,58 @@ pub struct WaitSite<A> {
/// checks a condition at its resume point decides itself whether it
/// continues.
pub terms: Vec<(A, CounterKind)>,
/// The `iff` condition of each term, or empty when no term has one. An
/// occurrence of a term with a gate satisfies the wait only if the gate
/// is a known 1 when the occurrence happens (IEEE 1800-2023 9.4.2.3).
#[serde(default = "Vec::new")]
pub gates: Vec<Option<WaitGate<A>>>,
}

/// The `iff` condition of a wait term: a signal whose least significant bit
/// holds it.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct WaitGate<A> {
pub signal: A,
/// Both operands are plain variables whose values can be read at an
/// assignment boundary, including activation-local variables without counters.
pub at_write: bool,
/// Counters that the writes of the term's signal bump at the write
/// itself, judging the gate there. Activation-local variables instead use
/// runtime assignment boundaries. Expressions and continuous/flip-flop
/// drivers clear `at_write` and require a settled observation.
pub counters: Option<GateCounters<A>>,
}

/// The occurrences of a gated term's kind that writes caused: `gated` those
/// while the gate was a known 1, `all` every one. A change of the signal
/// that neither counted, such as a raw host write, is judged with the gate
/// when it is detected.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct GateCounters<A> {
pub gated: A,
pub all: A,
}

impl<A: Copy> WaitGate<A> {
pub fn map<B>(&self, mut map: impl FnMut(A) -> B) -> WaitGate<B> {
WaitGate {
signal: map(self.signal),
at_write: self.at_write,
counters: self.counters.map(|counters| GateCounters {
gated: map(counters.gated),
all: map(counters.all),
}),
}
}

/// The gate's signal and counters.
pub fn reads(&self) -> impl Iterator<Item = A> {
std::iter::once(self.signal).chain(
self.counters
.into_iter()
.flat_map(|counters| [counters.gated, counters.all]),
)
}
}

impl<A: Copy> WaitSite<A> {
Expand All @@ -893,8 +945,27 @@ impl<A: Copy> WaitSite<A> {
.iter()
.map(|&(signal, kind)| (map(signal), kind))
.collect(),
gates: self
.gates
.iter()
.map(|gate| gate.as_ref().map(|gate| gate.map(&mut map)))
.collect(),
}
}

/// The gate of term `index`.
pub fn gate(&self, index: usize) -> Option<WaitGate<A>> {
self.gates.get(index).copied().flatten()
}

/// The signals the runtime reads to judge the wait: its terms' signals,
/// gates and gate counters.
pub fn reads(&self) -> impl Iterator<Item = A> + '_ {
self.terms
.iter()
.map(|&(signal, _)| signal)
.chain(self.gates.iter().flatten().flat_map(WaitGate::reads))
}
}

/// A nonblocking assignment of a process kernel. A kernel that returns
Expand Down
18 changes: 14 additions & 4 deletions crates/celox-design/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ pub struct TermModel<A> {
/// Design code may write the signal. Otherwise only the host and the
/// scheduler do.
pub driven: bool,
/// The term's `iff` condition ([`crate::WaitSite::gates`]).
pub gate: Option<crate::WaitGate<A>>,
}

impl<A: Copy + Eq + std::hash::Hash> ScheduleModel<A> {
Expand Down Expand Up @@ -118,10 +120,18 @@ impl<A: Copy + Eq + std::hash::Hash> ScheduleModel<A> {
let terms = site
.terms
.iter()
.map(|&(signal, kind)| TermModel {
signal,
kind,
driven: driven.contains(&signal),
.enumerate()
.map(|(index, &(signal, kind))| {
let gate = site.gate(index);
TermModel {
signal,
kind,
// A gate without counters is judged at checks
// after settling, which only check driven terms.
driven: driven.contains(&signal)
|| gate.is_some_and(|gate| gate.counters.is_none()),
gate,
}
})
.collect();
processes[site.process].waits.push(terms);
Expand Down
2 changes: 2 additions & 0 deletions crates/celox-frontend-core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,7 @@ fn lower_statements(
(source_id(term.signal), kind)
})
.collect(),
gates: Vec::new(),
});
// The runtime resumes the process at the first occurrence
// after the wait began; no condition is left to check.
Expand All @@ -1390,6 +1391,7 @@ fn lower_statements(
.into_iter()
.map(|signal| (signal, CounterKind::Changes))
.collect(),
gates: Vec::new(),
});
let mut error = None;
kernel.wait_level(index, |builder| {
Expand Down
Loading
Loading