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
6 changes: 3 additions & 3 deletions conformance/sv-tests/expected.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ chapter-11/11.10.1--string_concat.sv fail
chapter-11/11.10.1--string_copy.sv fail
chapter-11/11.10.3--empty_string-sim.sv fail
chapter-11/11.10.3--empty_string.sv fail
chapter-11/11.11--min_max_avg_delay.sv fail
chapter-11/11.11--min_max_avg_delay.sv pass
chapter-11/11.12--let_construct.sv fail
chapter-11/11.3.5--expr_short_circuit.sv pass
chapter-11/11.3.6--assign_in_exp-sim.sv fail
Expand Down Expand Up @@ -726,7 +726,7 @@ chapter-9/9.3.5--statement_labels_par.sv fail
chapter-9/9.3.5--statement_labels_seq.sv pass
chapter-9/9.4.1--delay_control-sim.sv fail
chapter-9/9.4.1--delay_control-two-blocks-sim.sv fail
chapter-9/9.4.1--delay_control.sv fail
chapter-9/9.4.1--delay_control.sv pass
chapter-9/9.4.2--event_control_edge.sv fail
chapter-9/9.4.2--event_control_negedge.sv pass
chapter-9/9.4.2--event_control_posedge.sv pass
Expand All @@ -737,7 +737,7 @@ chapter-9/9.4.2.1--event_or_op.sv fail
chapter-9/9.4.2.2--event_implicit.sv pass
chapter-9/9.4.2.3--event_conditional.sv fail
chapter-9/9.4.2.4--event_sequence.sv fail
chapter-9/9.4.3--event_sequence_controls.sv fail
chapter-9/9.4.3--event_sequence_controls.sv pass
chapter-9/9.4.5--event_blocking_assignment_delay.sv fail
chapter-9/9.4.5--event_nonblocking_assignment_delay.sv fail
chapter-9/9.4.5--event_nonblocking_assignment_event.sv fail
Expand Down
57 changes: 57 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,49 @@ pub enum DeadStorePolicy {
PreserveAllPorts,
}

/// One simulation tick, expressed as a power of ten seconds.
/// Valid SystemVerilog/VCD scales range from 1 fs (-15) to 100 s (2).
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(try_from = "i32", into = "i32")]
pub struct TimePrecision(i32);

impl TimePrecision {
pub fn exponent(self) -> i32 {
self.0
}

/// The magnitude and physical unit used by a VCD `$timescale` header.
pub fn vcd_timescale(self) -> (u8, &'static str) {
let magnitude = 10u8.pow(self.0.rem_euclid(3) as u32);
let unit = ["s", "ms", "us", "ns", "ps", "fs"][(-self.0.div_euclid(3)) as usize];
(magnitude, unit)
}
}

impl Default for TimePrecision {
/// Scale-free frontends use the same 1ps tick as the SV implementation default.
fn default() -> Self {
Self(-12)
}
}

impl TryFrom<i32> for TimePrecision {
type Error = &'static str;
fn try_from(exponent: i32) -> Result<Self, Self::Error> {
if (-15..=2).contains(&exponent) {
Ok(Self(exponent))
} else {
Err("time precision must be between 1fs and 100s")
}
}
}

impl From<TimePrecision> for i32 {
fn from(precision: TimePrecision) -> Self {
precision.0
}
}

/// Source-independent runtime diagnostics and observable event descriptions.
#[derive(Clone, Debug)]
pub struct RuntimeSchema<A> {
Expand Down Expand Up @@ -740,6 +783,13 @@ impl<A: Copy + Eq + std::hash::Hash> EventTopology<A> {
}
}

/// Time unit and rounding precision of one source scope, in powers of ten seconds.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct TimeScale {
pub unit: TimePrecision,
pub precision: TimePrecision,
}

/// Backend-neutral semantic design data after hierarchy flattening.
///
/// This is intentionally not a frontend lookup table: every state object is
Expand All @@ -751,6 +801,11 @@ impl<A: Copy + Eq + std::hash::Hash> EventTopology<A> {
deserialize = "A: Deserialize<'de> + Eq + std::hash::Hash + Ord"
))]
pub struct ElaboratedDesign<A> {
/// Physical duration of one global simulation tick.
#[serde(default)]
pub time_precision: TimePrecision,
/// Local time units and precisions retained for reflected instance queries.
pub instance_time_scales: HashMap<InstanceId, TimeScale>,
pub state_objects: HashMap<A, VariableMetadata>,
pub events: EventTopology<A>,
pub initial_state: Vec<InitialStateValue<A>>,
Expand All @@ -759,6 +814,8 @@ pub struct ElaboratedDesign<A> {
impl<A> Default for ElaboratedDesign<A> {
fn default() -> Self {
Self {
time_precision: TimePrecision::default(),
instance_time_scales: HashMap::default(),
state_objects: HashMap::default(),
events: EventTopology::default(),
initial_state: Vec::new(),
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 @@ -1897,6 +1897,8 @@ pub fn lower_frontend_artifact(

let module_id = ModuleId(0);
let sim_module = SimModule {
time_precision: None,
time_scale: celox_design::TimeScale::default(),
name: artifact.module_name().to_string(),
variables,
ff_access_summaries: HashMap::default(),
Expand Down
4 changes: 4 additions & 0 deletions crates/celox-frontend-core/src/symbolic/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ pub struct SymbolicProcess {

#[derive(Clone)]
pub struct SimModule {
/// A frontend's global tick precision; absent for scale-free frontends.
pub time_precision: Option<celox_design::TimePrecision>,
/// Local unit and precision; scale-free frontends use the 1ps default.
pub time_scale: celox_design::TimeScale,
pub name: String,
pub variables: HashMap<SourceVarId, SymbolicVariable>,
pub ff_access_summaries:
Expand Down
13 changes: 13 additions & 0 deletions crates/celox-frontend-core/src/symbolic/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ pub fn schedule_symbolic_rtl(
root_id,
packages,
} = symbolic;
let time_precision = modules
.values()
.filter_map(|module| module.time_precision)
.min()
.unwrap_or_default();
let flatten_timing = trace_opts.phase_timing;
macro_rules! timed_sub {
($label:expr, $body:expr) => {{
Expand Down Expand Up @@ -603,6 +608,10 @@ pub fn schedule_symbolic_rtl(
instance_modules.insert(id, *module_id);
package_instances.insert(*module_id, id);
}
let instance_time_scales = instance_modules
.iter()
.map(|(&instance, module)| (instance, modules[module].time_scale))
.collect::<HashMap<_, _>>();
let bindings = &PackageBindings::new(&instance_modules, &modules, &package_instances)?;
let global_boundaries = timed_sub!(
"propagate_boundaries",
Expand Down Expand Up @@ -1479,6 +1488,8 @@ pub fn schedule_symbolic_rtl(
.collect();
let watches: Vec<EventWatch<StateAddr>> = {
let event_kinds = ElaboratedDesign {
time_precision,
instance_time_scales: HashMap::default(),
state_objects: state_objects.clone(),
events: events.clone(),
initial_state: Vec::new(),
Expand Down Expand Up @@ -1546,6 +1557,8 @@ pub fn schedule_symbolic_rtl(
let scheduled = ScheduledRtl {
sir,
design: ElaboratedDesign {
time_precision,
instance_time_scales,
state_objects,
events,
initial_state,
Expand Down
Loading
Loading