Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d586dd6
feat(sv)!: analyze delays, event controls and waits in initial blocks
tignear Oct 18, 2026
bae11e1
feat(sv): lower delays and waits in initial processes
tignear Oct 18, 2026
6851e73
test(sv): run the timing cases of initial processes
tignear Oct 18, 2026
d7a4005
test(sv): expect the sv-tests delay and wait cases to pass
tignear Oct 18, 2026
ebfd107
test(sv): exclude the four-state flip-flop edge case under #1472
tignear Oct 18, 2026
02ef771
fix(sim)!: preserve global precision in VCD and VPI
tignear Oct 18, 2026
8cc8302
fix(sim): judge four-state edges of internal clocks by Table 9-2
tignear Oct 16, 2026
d208b85
test(suite): cover Table 9-2 edges of internally driven clocks
tignear Oct 16, 2026
b3a09ce
fix(js): count rising edges through x and z in waitForCycles
tignear Oct 16, 2026
bc0a593
test(suite): count the new four-state edge cases in the catalogue
tignear Oct 16, 2026
10a48ac
test(bench): measure four-state derived clocks in the overhead benchmark
tignear Oct 17, 2026
0a0dbb0
test(sim): expect Table 9-2 edges from an initial unknown reset
tignear Oct 17, 2026
98e9dc0
test(sim): cover explicit edges of four-state clocks from x and z
tignear Oct 17, 2026
147bd20
fix(js): judge WASM-runner edges of four-state clocks by Table 9-2
tignear Oct 17, 2026
b4519bc
refactor(sv)!: bind assignment patterns without rewriting source
tignear Oct 18, 2026
ae6151d
Merge of #1471
mergify[bot] Oct 18, 2026
6d19306
Merge of #1459
mergify[bot] Oct 18, 2026
b45fc81
Merge of #1467
mergify[bot] Oct 18, 2026
2bc06fc
Merge of #1414
mergify[bot] Oct 18, 2026
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
100 changes: 80 additions & 20 deletions crates/celox-design/src/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,58 @@ pub const fn polarity(kind: DomainKind) -> Option<bool> {
}
}

/// Whether a level change from `was` to `is` that the scheduler applies to
/// an event signal, or that a process drives, is an active edge of a domain
/// of `kind`. A domain of unknown kind reacts to a rising edge.
/// The bit of an edge level that marks an unknown (x or z) value; the value
/// bit then tells x (1) from z (0), as in the state image. An edge level is
/// 0, 1, x (`LEVEL_UNKNOWN | 1`) or z (`LEVEL_UNKNOWN`).
pub const LEVEL_UNKNOWN: u8 = 2;

/// Whether a change between the edge levels `was` and `is` is a rising
/// (`rising`) or a falling edge (IEEE 1800-2023 9.4.2, Table 9-2): a posedge
/// leaves 0 or reaches 1, a negedge leaves 1 or reaches 0, and a change
/// between x and z is neither. With `FOUR_STATE` false the levels are 0 or
/// 1 and this is a rise or a fall.
#[inline]
pub const fn level_edge<const FOUR_STATE: bool>(rising: bool, was: u8, is: u8) -> bool {
let between_unknowns = FOUR_STATE && was & is & LEVEL_UNKNOWN != 0;
let (from, to) = if rising { (0, 1) } else { (1, 0) };
was != to && is != from && !between_unknowns
}

/// Whether a change from edge level `was` to `is` that the scheduler
/// applies to an event signal, or that a process drives, is an active edge
/// of a domain of `kind`. A domain of unknown kind reacts to a rising edge.
///
/// This differs from [`settled_edge`] for domains of unknown kind; the two
/// rules stay separate.
pub const fn scheduled_edge(kind: Option<DomainKind>, was: bool, is: bool) -> bool {
#[inline]
pub const fn scheduled_edge<const FOUR_STATE: bool>(
kind: Option<DomainKind>,
was: u8,
is: u8,
) -> bool {
match kind {
Some(DomainKind::ClockPosedge | DomainKind::ResetAsyncHigh) => !was && is,
Some(DomainKind::ClockNegedge | DomainKind::ResetAsyncLow) => was && !is,
_ => !was && is,
Some(DomainKind::ClockNegedge | DomainKind::ResetAsyncLow) => {
level_edge::<FOUR_STATE>(false, was, is)
}
_ => level_edge::<FOUR_STATE>(true, was, is),
}
}

/// Whether a settled level change from `was` to `is` is an active edge of a
/// domain of `kind`. A domain of unknown kind reacts to any change.
pub const fn settled_edge(kind: Option<DomainKind>, was: bool, is: bool) -> bool {
/// Whether a settled change from edge level `was` to `is` is an active edge
/// of a domain of `kind`. A domain of unknown kind reacts to any change.
#[inline]
pub const fn settled_edge<const FOUR_STATE: bool>(
kind: Option<DomainKind>,
was: u8,
is: u8,
) -> bool {
match kind {
Some(DomainKind::ClockPosedge | DomainKind::ResetAsyncHigh) => !was && is,
Some(DomainKind::ClockNegedge | DomainKind::ResetAsyncLow) => was && !is,
Some(DomainKind::ClockPosedge | DomainKind::ResetAsyncHigh) => {
level_edge::<FOUR_STATE>(true, was, is)
}
Some(DomainKind::ClockNegedge | DomainKind::ResetAsyncLow) => {
level_edge::<FOUR_STATE>(false, was, is)
}
_ => was != is,
}
}
Expand All @@ -54,10 +86,32 @@ mod tests {
#[test]
fn domains_of_unknown_kind_differ_between_the_rules() {
for kind in [None, Some(DomainKind::Other)] {
assert!(scheduled_edge(kind, false, true));
assert!(!scheduled_edge(kind, true, false));
assert!(settled_edge(kind, false, true));
assert!(settled_edge(kind, true, false));
assert!(scheduled_edge::<false>(kind, 0, 1));
assert!(!scheduled_edge::<false>(kind, 1, 0));
assert!(settled_edge::<false>(kind, 0, 1));
assert!(settled_edge::<false>(kind, 1, 0));
}
}

/// IEEE 1800-2023 Table 9-2, rows `from` and columns `to` in the order
/// 0, 1, x, z: `P` posedge, `N` negedge, `-` no edge.
#[test]
fn four_state_levels_follow_table_9_2() {
const LEVELS: [u8; 4] = [0, 1, LEVEL_UNKNOWN | 1, LEVEL_UNKNOWN];
const TABLE: [&str; 4] = ["-PPP", "N-NN", "NP--", "NP--"];
for (from, row) in LEVELS.iter().zip(TABLE) {
for (to, cell) in LEVELS.iter().zip(row.chars()) {
for (kind, mark) in [
(DomainKind::ClockPosedge, 'P'),
(DomainKind::ResetAsyncHigh, 'P'),
(DomainKind::ClockNegedge, 'N'),
(DomainKind::ResetAsyncLow, 'N'),
] {
let edge = cell == mark;
assert_eq!(settled_edge::<true>(Some(kind), *from, *to), edge);
assert_eq!(scheduled_edge::<true>(Some(kind), *from, *to), edge);
}
}
}
}

Expand All @@ -70,10 +124,16 @@ mod tests {
DomainKind::ResetAsyncLow,
] {
let rising = polarity(kind) == Some(true);
for (was, is) in [(false, true), (true, false), (false, false), (true, true)] {
let edge = if rising { !was && is } else { was && !is };
assert_eq!(scheduled_edge(Some(kind), was, is), edge);
assert_eq!(settled_edge(Some(kind), was, is), edge);
for (was, is) in [(0, 1), (1, 0), (0, 0), (1, 1)] {
let edge = if rising {
was == 0 && is == 1
} else {
was == 1 && is == 0
};
assert_eq!(scheduled_edge::<false>(Some(kind), was, is), edge);
assert_eq!(settled_edge::<false>(Some(kind), was, is), edge);
assert_eq!(scheduled_edge::<true>(Some(kind), was, is), edge);
assert_eq!(settled_edge::<true>(Some(kind), was, is), edge);
}
assert_eq!(active_level(Some(kind)), u8::from(rising));
}
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