Skip to content
Closed
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
12 changes: 12 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ pub struct RuntimeCombObserver<A> {
pub site_id: u32,
pub activation_group: u32,
pub sensitivity: Vec<VarAtomBase<A>>,
/// Occurrence counters of the sensitivity: a counter that moved since
/// the last check activates the observer even when the settled value
/// equals the last one.
#[serde(default = "Vec::new")]
pub occurrence_counters: Vec<A>,
pub written_inputs: Vec<A>,
}

Expand Down Expand Up @@ -822,6 +827,11 @@ pub struct RuntimeSchema<A> {
pub process_origins: Vec<ProcessOrigin>,
/// Counted signals and their occurrence counters.
pub watches: Vec<EventWatch<A>>,
/// Bit ranges whose changes bump an occurrence counter: the sensitivity
/// of change-gated combinational processes and comb observers. Design
/// code counts its own writes; the runtime counts the writes it makes,
/// such as the nonblocking updates it publishes.
pub occurrence_probes: Vec<(VarAtomBase<A>, A)>,
/// Wait sites of the process kernels. A process's sites appear in the
/// order of its local site indices.
pub wait_sites: Vec<WaitSite<A>>,
Expand Down Expand Up @@ -860,6 +870,7 @@ impl<A> Default for RuntimeSchema<A> {
processes: Vec::new(),
process_origins: Vec::new(),
watches: Vec::new(),
occurrence_probes: Vec::new(),
wait_sites: Vec::new(),
nba_sites: Vec::new(),
host_request_sites: Vec::new(),
Expand Down Expand Up @@ -1657,6 +1668,7 @@ mod tests {
id: initial.address,
access: BitAccess { lsb: 3, msb: 7 },
}],
occurrence_counters: Vec::new(),
written_inputs: vec![initial.address],
});
runtime.testbench_read_roots.insert(initial.address);
Expand Down
10 changes: 7 additions & 3 deletions crates/celox-design/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ pub struct ScheduleModel<A> {
/// Counted signals with all their counters, and the canonical domains
/// each counter triggers, in [`RuntimeSchema::watches`] order.
pub counted: Vec<CountedModel<A>>,
/// Bit ranges whose changes bump an occurrence counter
/// ([`RuntimeSchema::occurrence_probes`]).
pub probes: Vec<(crate::VarAtomBase<A>, A)>,
/// Process kernels in kernel order.
pub processes: Vec<ProcessModel<A>>,
/// Signals a wait watches, which the host's writes must be logged for.
pub waited: Vec<A>,
/// The design has process kernels or counted signals. Without either,
/// a round of the scheduler is the batch step.
/// The design has process kernels. Without them, a round of the
/// scheduler is the batch step, which also checks counted signals.
pub timed: bool,
/// Some nonblocking site has a pending flag.
pub has_pending_nba_sites: bool,
Expand Down Expand Up @@ -131,8 +134,9 @@ impl<A: Copy + Eq + std::hash::Hash> ScheduleModel<A> {
Self {
events: design.events.clone(),
kinds: design.event_kinds(),
timed: !processes.is_empty() || !counted.is_empty(),
timed: !processes.is_empty(),
counted,
probes: schema.occurrence_probes.clone(),
processes,
waited,
has_pending_nba_sites,
Expand Down
145 changes: 142 additions & 3 deletions crates/celox-frontend-core/src/symbolic/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use celox_design::{
InitialStateValue, InstanceId, ModuleId, NbaSite, ProcessSlots, RegionedAbsoluteAddrBase,
RegionedStateAddr, RuntimeCombObserver, RuntimeErrorInfo, RuntimeEventKind, RuntimeEventSite,
RuntimeSchema, STABLE_REGION, StateAddr, StateObjectId, TriggerSet, VarAtomBase,
VariableMetadata, WaitSite,
VariableMetadata, WORKING_REGION, WaitSite,
};
use celox_sir::{
BasicBlock, ExecutionUnit, LaneUnit, ParallelSirProgram, SIRInstruction, SIROffset,
Expand Down Expand Up @@ -733,6 +733,7 @@ pub fn schedule_symbolic_rtl_reporting_loops(
})
.collect();
let declaration_probes;
let occurrence_probes: Vec<(VarAtomBase<AbsoluteAddr>, AbsoluteAddr)>;
let counted = {
// Flip-flop event domains and the aliases that resolve to them.
let event_addresses: HashSet<AbsoluteAddr> = eval_apply_ffs
Expand Down Expand Up @@ -761,6 +762,13 @@ pub fn schedule_symbolic_rtl_reporting_loops(
}
}
}
for observer in &comb_observers {
for &(source, counter) in &observer.sensitivity_counters {
if !probes.contains(&(source, counter)) {
probes.push((source, counter));
}
}
}
// A direct wire/port connection carries occurrences as well as its
// settled value. Preserve them when a kernel writes the upstream
// object twice before the copy path is evaluated. Only equal-width,
Expand Down Expand Up @@ -808,6 +816,13 @@ pub fn schedule_symbolic_rtl_reporting_loops(
}
}
declaration_probes = probes.clone();
occurrence_probes = probes.clone();
// Signals a flip-flop evaluation may store twice in its working
// state. Each store is an update event (IEEE 1800-2023 4.3, 10.4.2)
// that the commit of the final value alone would not show; the
// working state is seeded with the stable value first, so a store
// compares with the value its update replaces.
let ff_multi_stored = ff_multi_stored(&eval_apply_ffs, &eval_only_ffs, &parallel_ff_units);
for (source, counter) in probes {
let width = source.access.msb - source.access.lsb + 1;
let four_state = four_state && variables[&source.id].1;
Expand Down Expand Up @@ -854,6 +869,27 @@ pub fn schedule_symbolic_rtl_reporting_loops(
crate::watch::instrument_unit(&mut part.apply, code);
}
}
if ff_multi_stored.contains(&source.id) {
let working =
|address| RegionedAbsoluteAddr::from_absolute_addr(WORKING_REGION, address);
let code = |address: &RegionedAbsoluteAddr| {
(address.region == WORKING_REGION && address.absolute_addr() == source.id).then(
|| crate::watch::WatchCode {
signal: working(source.id),
width,
offset: offset.clone(),
four_state,
counters: vec![(CounterKind::Changes, stable(counter))],
},
)
};
for_each_ff_evaluation(
&mut eval_apply_ffs,
&mut eval_only_ffs,
&mut parallel_ff_units,
|unit| crate::watch::instrument_stores(unit, code),
);
}
for path in &mut comb_blocks {
if let LogicPathTarget::Process { unit, .. } = &mut path.target {
crate::watch::instrument_unit(unit, |address| {
Expand All @@ -868,14 +904,42 @@ pub fn schedule_symbolic_rtl_reporting_loops(
}
}
}
instrument_counted_signals(
let counted = instrument_counted_signals(
&timing,
&event_addresses,
&variables,
four_state,
&mut processes,
&mut comb_blocks,
)
);
for (signal, slots) in &counted {
if !ff_multi_stored.contains(signal) {
continue;
}
let (width, is_4state) = variables[signal];
let regioned = RegionedAbsoluteAddr::from_absolute_addr;
let code = |address: &RegionedAbsoluteAddr| {
(address.region == WORKING_REGION && address.absolute_addr() == *signal).then(
|| crate::watch::WatchCode {
signal: regioned(WORKING_REGION, *signal),
offset: celox_sir::SIROffset::Static(0),
width,
four_state: four_state && is_4state,
counters: CounterKind::ALL
.into_iter()
.map(|kind| (kind, regioned(STABLE_REGION, slots.counter(kind))))
.collect(),
},
)
};
for_each_ff_evaluation(
&mut eval_apply_ffs,
&mut eval_only_ffs,
&mut parallel_ff_units,
|unit| crate::watch::instrument_stores(unit, code),
);
}
counted
};
// Combinational values and the variables they are computed from.
let comb_sources = comb_sources(&comb_blocks, &global_arena);
Expand Down Expand Up @@ -1621,6 +1685,11 @@ pub fn schedule_symbolic_rtl_reporting_loops(
site_id: observer.site_id,
activation_group: observer.activation_group,
sensitivity: observer.sensitivity.clone(),
occurrence_counters: observer
.sensitivity_counters
.iter()
.map(|&(_, counter)| counter)
.collect(),
written_inputs: observer.written_inputs.clone(),
})
.collect();
Expand Down Expand Up @@ -1835,6 +1904,11 @@ pub fn schedule_symbolic_rtl_reporting_loops(
access: atom.access,
})
.collect(),
occurrence_counters: observer
.occurrence_counters
.into_iter()
.map(project)
.collect(),
written_inputs: observer.written_inputs.into_iter().map(project).collect(),
})
.collect();
Expand Down Expand Up @@ -1968,6 +2042,24 @@ pub fn schedule_symbolic_rtl_reporting_loops(
.chain(host_request_sites.iter().flat_map(|site| site.slots()))
.collect();
let declaration_startup = declaration_startup.map(|startup| startup.map(project));
let occurrence_probes: Vec<(VarAtomBase<StateAddr>, StateAddr)> = occurrence_probes
.into_iter()
.map(|(source, counter)| {
(
VarAtomBase {
id: project(source.id),
access: source.access,
},
project(counter),
)
})
.collect();
// The runtime counts the occurrences its own writes cause.
timing_read_roots.extend(
occurrence_probes
.iter()
.flat_map(|(source, counter)| [source.id, *counter]),
);
if let Some(startup) = &declaration_startup {
timing_read_roots.extend(
startup
Expand Down Expand Up @@ -2040,6 +2132,7 @@ pub fn schedule_symbolic_rtl_reporting_loops(
processes: process_slots,
process_origins,
watches,
occurrence_probes,
wait_sites,
nba_sites,
host_request_sites,
Expand Down Expand Up @@ -3586,6 +3679,52 @@ fn relocate_timing(
metadata
}

type FfUnits = HashMap<AbsoluteAddr, Vec<ExecutionUnit<RegionedAbsoluteAddr>>>;
type FfParts = HashMap<AbsoluteAddr, Vec<(InstanceId, FfPart<RegionedAbsoluteAddr>)>>;

/// The signals some flip-flop evaluation may store twice in its working
/// state in one execution.
fn ff_multi_stored(
eval_apply_ffs: &FfUnits,
eval_only_ffs: &FfUnits,
parallel_ff_units: &FfParts,
) -> HashSet<AbsoluteAddr> {
let working = |address: &RegionedAbsoluteAddr| {
(address.region == WORKING_REGION).then(|| address.absolute_addr())
};
eval_apply_ffs
.values()
.chain(eval_only_ffs.values())
.flatten()
.chain(
parallel_ff_units
.values()
.flatten()
.map(|(_, part)| &part.evaluate),
)
.flat_map(|unit| crate::watch::multi_store_only_candidates(unit, working))
.collect()
}

/// Run `f` on every flip-flop evaluation.
fn for_each_ff_evaluation(
eval_apply_ffs: &mut FfUnits,
eval_only_ffs: &mut FfUnits,
parallel_ff_units: &mut FfParts,
mut f: impl FnMut(&mut ExecutionUnit<RegionedAbsoluteAddr>),
) {
for unit in eval_apply_ffs
.values_mut()
.chain(eval_only_ffs.values_mut())
.flatten()
{
f(unit);
}
for (_, part) in parallel_ff_units.values_mut().flatten() {
f(&mut part.evaluate);
}
}

/// Counted signals: those a unit may store twice between two runtime checks
/// (a frontend declared counters for them) and that a flip-flop domain or a
/// wait watches. Returns their counters by signal and instruments the
Expand Down
10 changes: 10 additions & 0 deletions crates/celox-frontend-core/src/symbolic/flattening.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,16 @@ fn convert_comb_observer<
.iter()
.map(|v| VarAtomBase::new(f(&v.id), v.access.lsb, v.access.msb))
.collect(),
sensitivity_counters: observer
.sensitivity_counters
.iter()
.map(|(v, counter)| {
(
VarAtomBase::new(f(&v.id), v.access.lsb, v.access.msb),
f(counter),
)
})
.collect(),
local_inputs: observer
.local_inputs
.iter()
Expand Down
Loading
Loading