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
256 changes: 149 additions & 107 deletions crates/celox-frontend-core/src/symbolic/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,85 +936,126 @@ pub fn schedule_symbolic_rtl_reporting_loops(
// 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;
let offset = match unpacked_element_widths.get(&source.id) {
Some(&element_width)
if width > element_width
&& source.access.lsb.is_multiple_of(element_width)
&& width.is_multiple_of(element_width) =>
{
celox_sir::SIROffset::PackedElements {
bit_offset: source.access.lsb,
element_width,
// Each unit is instrumented once for all probes. Probe `p` is pass
// `2p` over the stable state and pass `2p + 1` over a flip-flop
// evaluation's working state, the order of instrumenting probe by
// probe.
let probe_codes: Vec<_> = probes
.iter()
.map(|&(source, counter)| {
let width = source.access.msb - source.access.lsb + 1;
let four_state = four_state && variables[&source.id].1;
let offset = match unpacked_element_widths.get(&source.id) {
Some(&element_width)
if width > element_width
&& source.access.lsb.is_multiple_of(element_width)
&& width.is_multiple_of(element_width) =>
{
celox_sir::SIROffset::PackedElements {
bit_offset: source.access.lsb,
element_width,
}
}
}
_ => celox_sir::SIROffset::Static(source.access.lsb),
};
let stable = |address| RegionedAbsoluteAddr::from_absolute_addr(STABLE_REGION, address);
let code = |address: &RegionedAbsoluteAddr| {
(address.region == STABLE_REGION && address.absolute_addr() == source.id).then(
|| crate::watch::WatchCode {
signal: stable(source.id),
width,
offset: offset.clone(),
four_state,
counters: vec![(CounterKind::Changes, stable(counter))],
},
)
};
for process in &mut processes {
crate::watch::instrument_unit(&mut process.kernel, code);
_ => celox_sir::SIROffset::Static(source.access.lsb),
};
(counter, width, four_state, offset)
})
.collect();
let mut probes_of: HashMap<AbsoluteAddr, Vec<usize>> = HashMap::default();
for (index, (source, _)) in probes.iter().enumerate() {
probes_of.entry(source.id).or_default().push(index);
}
// The first probe of `signal` whose `pass` is `after` or later.
let first_probe = |signal: AbsoluteAddr, pass: fn(usize) -> usize, after: usize| {
let indices = probes_of.get(&signal)?;
indices
.get(indices.partition_point(|&index| pass(index) < after))
.copied()
};
fn probe_code<A>(
probe: &(AbsoluteAddr, usize, bool, celox_sir::SIROffset),
signal: A,
counter: A,
) -> crate::watch::WatchCode<A> {
let &(_, width, four_state, ref offset) = probe;
crate::watch::WatchCode {
signal,
width,
offset: offset.clone(),
four_state,
counters: vec![(CounterKind::Changes, counter)],
}
for units in eval_apply_ffs
.values_mut()
.chain(eval_only_ffs.values_mut())
.chain(apply_ffs.values_mut())
}
let stable = |address| RegionedAbsoluteAddr::from_absolute_addr(STABLE_REGION, address);
let working = |address| RegionedAbsoluteAddr::from_absolute_addr(WORKING_REGION, address);
let stable_code = |instruction: &SIRInstruction<RegionedAbsoluteAddr>, after: usize| {
let address = crate::watch::write_destination(instruction)?;
if address.region != STABLE_REGION {
return None;
}
let index = first_probe(address.absolute_addr(), |index| 2 * index, after)?;
Some((
2 * index,
probe_code(
&probe_codes[index],
stable(address.absolute_addr()),
stable(probe_codes[index].0),
),
))
};
// A flip-flop evaluation's stores to a signal of `ff_multi_stored`;
// the commits that seed its working state are not writes of the
// process.
let evaluation_code = |instruction: &SIRInstruction<RegionedAbsoluteAddr>, after: usize| {
if let SIRInstruction::Store(address, ..) = instruction
&& address.region == WORKING_REGION
&& ff_multi_stored.contains(&address.absolute_addr())
&& let Some(index) =
first_probe(address.absolute_addr(), |index| 2 * index + 1, after)
{
for unit in units {
crate::watch::instrument_unit(unit, code);
}
return Some((
2 * index + 1,
probe_code(
&probe_codes[index],
working(address.absolute_addr()),
stable(probe_codes[index].0),
),
));
}
for parts in parallel_ff_units.values_mut() {
for (_, part) in parts {
crate::watch::instrument_unit(&mut part.evaluate, code);
crate::watch::instrument_unit(&mut part.apply, code);
}
stable_code(instruction, after)
};
for process in &mut processes {
crate::watch::instrument_writes_in_passes(&mut process.kernel, stable_code);
}
for units in eval_apply_ffs
.values_mut()
.chain(eval_only_ffs.values_mut())
{
for unit in units {
crate::watch::instrument_writes_in_passes(unit, evaluation_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| instrument_stores(unit, code),
);
}
for units in apply_ffs.values_mut() {
for unit in units {
crate::watch::instrument_writes_in_passes(unit, stable_code);
}
for path in &mut comb_blocks {
if let LogicPathTarget::Process { unit, .. } = &mut path.target {
crate::watch::instrument_unit(unit, |address| {
(*address == source.id).then(|| crate::watch::WatchCode {
signal: source.id,
width,
offset: offset.clone(),
four_state,
counters: vec![(CounterKind::Changes, counter)],
})
});
}
}
for parts in parallel_ff_units.values_mut() {
for (_, part) in parts {
crate::watch::instrument_writes_in_passes(&mut part.evaluate, evaluation_code);
crate::watch::instrument_writes_in_passes(&mut part.apply, stable_code);
}
}
for path in &mut comb_blocks {
if let LogicPathTarget::Process { unit, .. } = &mut path.target {
crate::watch::instrument_writes_in_passes(unit, |instruction, after| {
let &address = crate::watch::write_destination(instruction)?;
let index = first_probe(address, |index| index, after)?;
Some((
index,
probe_code(&probe_codes[index], address, probe_codes[index].0),
))
});
}
}
let ff_units = eval_apply_ffs
Expand Down Expand Up @@ -1052,31 +1093,45 @@ pub fn schedule_symbolic_rtl_reporting_loops(
.iter()
.map(|slots| slots.signal)
.collect();
for (signal, slots) in &counted {
if !ff_multi_stored.contains(signal) || pending.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(),
},
)
};
// One pass per signal, in signal order; each pass watches only its
// own signal.
let regioned = RegionedAbsoluteAddr::from_absolute_addr;
let multi_stored: HashMap<AbsoluteAddr, (usize, crate::watch::WatchCode<_>)> = counted
.iter()
.filter(|(signal, _)| ff_multi_stored.contains(signal) && !pending.contains(signal))
.enumerate()
.map(|(pass, (&signal, slots))| {
let (width, is_4state) = variables[&signal];
let code = 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(),
};
(signal, (pass, code))
})
.collect();
if !multi_stored.is_empty() {
for_each_ff_evaluation(
&mut eval_apply_ffs,
&mut eval_only_ffs,
&mut parallel_ff_units,
|unit| instrument_stores(unit, code),
|unit| {
crate::watch::instrument_writes_in_passes(unit, |instruction, after| {
let SIRInstruction::Store(address, ..) = instruction else {
return None;
};
if address.region != WORKING_REGION {
return None;
}
let (pass, code) = multi_stored.get(&address.absolute_addr())?;
(*pass >= after).then(|| (*pass, code.clone()))
})
},
);
}
counted
Expand Down Expand Up @@ -4012,19 +4067,6 @@ fn ff_multi_stored(
.collect()
}

/// [`crate::watch::instrument_unit`] for the stores alone: the commits that
/// seed a flip-flop evaluation's working state are not writes of the
/// process.
fn instrument_stores(
unit: &mut ExecutionUnit<RegionedAbsoluteAddr>,
watch_for: impl Fn(&RegionedAbsoluteAddr) -> Option<crate::watch::WatchCode<RegionedAbsoluteAddr>>,
) {
crate::watch::instrument_writes(unit, |instruction| match instruction {
SIRInstruction::Store(address, ..) => watch_for(address),
_ => None,
});
}

/// Run `f` on every flip-flop evaluation.
fn for_each_ff_evaluation(
eval_apply_ffs: &mut FfUnits,
Expand Down
Loading
Loading