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
6 changes: 6 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,11 @@ pub struct RuntimeSchema<A> {
/// most one per module instance. Before each round a timed scheduler
/// stores the current time into each, as [`TIME_SLOT_WIDTH`] bits.
pub time_slots: Vec<A>,
/// Variables of `$sampled` operands and their copies, which hold the
/// value of the variable in the Preponed region (IEEE 1800-2023
/// 16.5.1): a host copies each variable into its copy when a time slot
/// is over, and once before the first.
pub sample_shadows: Vec<(A, A)>,
/// The state a compiled scheduler exchanges with the runtime, and the
/// scheduler itself once one is generated. Present when the design has
/// process kernels.
Expand Down Expand Up @@ -1359,6 +1364,7 @@ impl<A> Default for RuntimeSchema<A> {
host_request_sites: Vec::new(),
active_commits: Vec::new(),
time_slots: Vec::new(),
sample_shadows: Vec::new(),
scheduler: None,
derived_edges: Vec::new(),
settle_partitions: None,
Expand Down
4 changes: 4 additions & 0 deletions crates/celox-design/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pub struct ScheduleModel<A> {
/// Objects the scheduler stores the current time into
/// ([`RuntimeSchema::time_slots`]).
pub time_slots: Vec<A>,
/// Sampled variables and their copies
/// ([`RuntimeSchema::sample_shadows`]).
pub sample_shadows: Vec<(A, A)>,
/// The compiled scheduler, if one was generated
/// ([`RuntimeSchema::scheduler`]).
pub scheduler: Option<crate::SchedulerSchema<A>>,
Expand Down Expand Up @@ -152,6 +155,7 @@ impl<A: Copy + Eq + std::hash::Hash> ScheduleModel<A> {
.any(|site| matches!(site.kind, RuntimeEventKind::Finish)),
active_commits: schema.active_commits.clone(),
time_slots: schema.time_slots.clone(),
sample_shadows: schema.sample_shadows.clone(),
scheduler: schema.scheduler.clone(),
}
}
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 @@ -1972,6 +1972,7 @@ pub fn lower_frontend_artifact(
nba_switches: Vec::new(),
host_request_sites: Vec::new(),
time_slot: None,
sample_shadows: Vec::new(),
};
let symbolic = SymbolicRtl {
modules: [(module_id, sim_module.clone())].into_iter().collect(),
Expand Down
3 changes: 3 additions & 0 deletions crates/celox-frontend-core/src/symbolic/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ pub struct SimModule {
/// The variable through which the module's code reads the simulation
/// time; see `RuntimeSchema::time_slots`.
pub time_slot: Option<SourceVarId>,
/// Variables and their sampled copies; see
/// `RuntimeSchema::sample_shadows`.
pub sample_shadows: Vec<(SourceVarId, SourceVarId)>,
}

/// A nonblocking site whose kernel has two paths, as
Expand Down
20 changes: 20 additions & 0 deletions crates/celox-frontend-core/src/symbolic/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,7 @@ pub fn schedule_symbolic_rtl_reporting_loops(
nba_sites,
host_request_sites,
time_slots,
sample_shadows,
..
} = timing;
let source_sir = SirProgram {
Expand Down Expand Up @@ -2386,6 +2387,10 @@ pub fn schedule_symbolic_rtl_reporting_loops(
.collect();
let active_commits: Vec<StateAddr> = active_commits.into_iter().map(project).collect();
let time_slots: Vec<StateAddr> = time_slots.into_iter().map(project).collect();
let sample_shadows: Vec<(StateAddr, StateAddr)> = sample_shadows
.into_iter()
.map(|(variable, copy)| (project(variable), project(copy)))
.collect();
let root_instance = expanded[&InstancePath(Vec::new())];
let settle_partitions = settle_flags.map(|settle| {
let mut marks: HashMap<StateAddr, BTreeSet<u32>> = HashMap::default();
Expand Down Expand Up @@ -2509,6 +2514,12 @@ pub fn schedule_symbolic_rtl_reporting_loops(
.flat_map(|(source, counter)| [source.id, *counter]),
);
}
// The host copies each sampled variable into its copy.
timing_read_roots.extend(
sample_shadows
.iter()
.flat_map(|&(variable, copy)| [variable, copy]),
);
// A package variable's state object maps back to the package's own
// variable, not to one of its aliases.
let state_to_source = source_to_state
Expand Down Expand Up @@ -2561,6 +2572,7 @@ pub fn schedule_symbolic_rtl_reporting_loops(
host_request_sites,
active_commits,
time_slots,
sample_shadows,
scheduler,
derived_edges: Vec::new(),
settle_partitions,
Expand Down Expand Up @@ -4113,6 +4125,7 @@ struct TimingMetadata {
nba_sites: Vec<NbaSite<AbsoluteAddr>>,
host_request_sites: Vec<HostRequestSite<AbsoluteAddr>>,
time_slots: Vec<AbsoluteAddr>,
sample_shadows: Vec<(AbsoluteAddr, AbsoluteAddr)>,
nba_switches: Vec<NbaSwitch<AbsoluteAddr>>,
}

Expand Down Expand Up @@ -4435,6 +4448,7 @@ fn relocate_timing(
nba_sites: Vec::new(),
host_request_sites: Vec::new(),
time_slots: Vec::new(),
sample_shadows: Vec::new(),
nba_switches: Vec::new(),
};
for (&instance, module) in instances {
Expand Down Expand Up @@ -4470,6 +4484,12 @@ fn relocate_timing(
}),
);
metadata.time_slots.extend(module.time_slot.map(locate));
metadata.sample_shadows.extend(
module
.sample_shadows
.iter()
.map(|&(variable, copy)| (locate(variable), locate(copy))),
);
metadata.nba_switches.extend(
module
.nba_switches
Expand Down
59 changes: 47 additions & 12 deletions crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ struct SvVariable {
hidden: bool,
/// Compiler-generated external override slot: (target, is_enable).
force_control: Option<(SourceVarId, bool)>,
/// The variable whose sampled value this hidden copy holds
/// (`SimModule::sample_shadows`).
sampled_from: Option<SourceVarId>,
}

/// Whether `expr` reads a string variable: after its calls are hoisted, a
Expand Down Expand Up @@ -126,13 +129,14 @@ impl SvVariable {
}

/// A hidden variable other than the time slot, whose value the lowered
/// code computes. The time slot is state the scheduler writes, and an
/// event expression's variables are state its process and its
/// continuous assignment share.
/// code computes. The time slot and the sampled copies are state the
/// scheduler writes, and an event expression's variables are state its
/// process and its continuous assignment share.
fn is_scratch(&self) -> bool {
self.hidden
&& self.path != [TIME_SLOT]
&& self.force_control.is_none()
&& self.sampled_from.is_none()
&& !self.path[0].starts_with(EVENT_PREFIX)
}
}
Expand Down Expand Up @@ -2198,6 +2202,7 @@ fn prepare_external_hierarchy_collecting(
source: variable.source.clone(),
hidden: !variable.module_affiliated,
force_control: None,
sampled_from: None,
},
)
})
Expand Down Expand Up @@ -3629,6 +3634,7 @@ fn lower_module_with_overrides(
source: None,
hidden: false,
force_control: None,
sampled_from: None,
};
name_to_id.insert(port.name().to_string(), id);
port_order.push(id);
Expand Down Expand Up @@ -3713,6 +3719,7 @@ fn lower_module_with_overrides(
source: None,
hidden: false,
force_control: None,
sampled_from: None,
};
name_to_id.insert(signal.name().to_string(), id);
// The package's object, or the other instance's, has its own
Expand Down Expand Up @@ -3793,6 +3800,7 @@ fn lower_module_with_overrides(
source: None,
hidden: false,
force_control: None,
sampled_from: None,
},
);
}
Expand Down Expand Up @@ -4005,6 +4013,7 @@ fn lower_module_with_overrides(
nba_switches,
host_request_sites,
time_slot: name_to_id.get(TIME_SLOT).copied(),
sample_shadows: Vec::new(),
},
variables,
port_order,
Expand Down Expand Up @@ -4793,6 +4802,12 @@ pub(crate) fn attach_instance_glue(
}
// Combinational processes may read the time too.
module.time_slot = signal_names.get(TIME_SLOT).copied();
let mut sample_shadows: Vec<_> = parent_variables
.iter()
.filter_map(|(&copy, variable)| variable.sampled_from.map(|variable| (variable, copy)))
.collect();
sample_shadows.sort_by_key(|&(variable, copy)| (variable.0, copy.0));
module.sample_shadows = sample_shadows;
for (instance, child_id, child, connections) in resolved_instances {
let glue = build_instance_glue(
&parent_variables,
Expand Down Expand Up @@ -5187,6 +5202,7 @@ fn lower_initial_processes(
// Control slots are not signals of the design.
hidden: true,
force_control: None,
sampled_from: None,
},
);
id
Expand Down Expand Up @@ -5831,6 +5847,7 @@ fn ensure_parent_output_signals(
source: None,
hidden: false,
force_control: None,
sampled_from: None,
};
parent
.variables
Expand Down Expand Up @@ -7713,6 +7730,7 @@ fn lower_bit_vector_function_slt<A: std::hash::Hash + Eq + Clone>(
| SystemFunction::Isunbounded
| SystemFunction::Signed
| SystemFunction::Unsigned
| SystemFunction::Sampled
| SystemFunction::Bits
| SystemFunction::Size
| SystemFunction::Dimensions
Expand Down Expand Up @@ -9077,6 +9095,15 @@ fn runtime_select_as_shift(
}

fn expr_from_const_expr(expr: &sv::ir::ConstExpr) -> Option<sv::ir::Expr> {
expr_from_const_expr_with_calls(expr, false)
}

/// Reconstruct a select operand, optionally retaining nested runtime calls.
fn expr_from_const_expr_with_calls(
expr: &sv::ir::ConstExpr,
allow_calls: bool,
) -> Option<sv::ir::Expr> {
let convert = |expr| expr_from_const_expr_with_calls(expr, allow_calls);
Some(match expr {
sv::ir::ConstExpr::Literal(value) => sv::ir::Expr::Literal(value.clone()),
sv::ir::ConstExpr::Ident(name) => sv::ir::Expr::Ident(name.clone()),
Expand All @@ -9086,13 +9113,13 @@ fn expr_from_const_expr(expr: &sv::ir::ConstExpr) -> Option<sv::ir::Expr> {
lsb,
signed,
} => sv::ir::Expr::Select {
expr: Box::new(expr_from_const_expr(expr)?),
expr: Box::new(convert(expr)?),
msb: (**msb).clone(),
lsb: (**lsb).clone(),
signed: *signed,
},
sv::ir::ConstExpr::Select { expr, bit } => sv::ir::Expr::Select {
expr: Box::new(expr_from_const_expr(expr)?),
expr: Box::new(convert(expr)?),
msb: (**bit).clone(),
lsb: (**bit).clone(),
signed: false,
Expand All @@ -9102,28 +9129,36 @@ fn expr_from_const_expr(expr: &sv::ir::ConstExpr) -> Option<sv::ir::Expr> {
width,
signed,
} => sv::ir::Expr::Resize {
expr: Box::new(expr_from_const_expr(expr)?),
expr: Box::new(convert(expr)?),
width: *width,
signed: *signed,
},
sv::ir::ConstExpr::Function { callee, args, .. } if allow_calls => sv::ir::Expr::Call {
callee: callee.clone(),
arg_order: Vec::new(),
args: args
.iter()
.map(|arg| convert(arg).map(Some))
.collect::<Option<_>>()?,
},
sv::ir::ConstExpr::Function { .. } => return None,
sv::ir::ConstExpr::Unary { op, expr } => sv::ir::Expr::Unary {
op: *op,
expr: Box::new(expr_from_const_expr(expr)?),
expr: Box::new(convert(expr)?),
},
sv::ir::ConstExpr::Binary { left, op, right } => sv::ir::Expr::Binary {
left: Box::new(expr_from_const_expr(left)?),
left: Box::new(convert(left)?),
op: *op,
right: Box::new(expr_from_const_expr(right)?),
right: Box::new(convert(right)?),
},
sv::ir::ConstExpr::Mux {
condition,
then_expr,
else_expr,
} => sv::ir::Expr::Mux {
condition: Box::new(expr_from_const_expr(condition)?),
then_expr: Box::new(expr_from_const_expr(then_expr)?),
else_expr: Box::new(expr_from_const_expr(else_expr)?),
condition: Box::new(convert(condition)?),
then_expr: Box::new(convert(then_expr)?),
else_expr: Box::new(convert(else_expr)?),
},
})
}
Expand Down
Loading
Loading