From 506d2aefd5ed4310d1dcc7c34fe3f8a47e588549 Mon Sep 17 00:00:00 2001 From: tignear Date: Sun, 18 Oct 2026 12:26:18 +0900 Subject: [PATCH 1/2] fix(sim)!: commit blocking flip-flop stores in the active region An edge-triggered `always` committed its blocking and nonblocking results together when its domain applied. IEEE 1800-2023 (4.5, 10.4) executes the blocking stores in the active region and the nonblocking updates in the NBA region (#1470): - A variable one block writes both ways now stages its nonblocking writes in a hidden value and a mask of the bits they wrote; the commit merges them after the blocking value. `q <= 7; q = 2;` ends with 7 and a read after `q <= 7` sees the old `q`, on every path. - In a design with process kernels, a domain whose blocking results are observed (read through combinational logic by a kernel or another domain's evaluation, a wait term, or another domain's event signal) commits them with its evaluation and only the nonblocking ones in the NBA region. The reference loop settles combinational logic and wakes waits after such a domain evaluates before the inactive region, so their processes run in the active region. Other domains and the fused units commit as before. The runtime schema lists those domains, so the native image container moves to version 14; older images are rejected. BREAKING CHANGE: `RuntimeSchema` and `ScheduleModel` have the new field `active_commits`, and native images of container version 13 are rejected. Change-Id: I2c5a64fed1e96648f3c3b7419f39acb5f576bb32 --- crates/celox-design/src/lib.rs | 5 + crates/celox-design/src/schedule.rs | 4 + crates/celox-frontend-core/src/sdk.rs | 1 + .../src/symbolic/artifact.rs | 14 + .../src/symbolic/assembly.rs | 207 ++++++++++++- crates/celox-frontend-sv/src/lowering.rs | 34 ++- crates/celox-frontend-sv/src/lowering/ff.rs | 279 +++++++++++++++++- .../src/lowering/procedural.rs | 25 ++ crates/celox-frontend-veryl/src/artifact.rs | 1 + crates/celox-runtime/src/schedule.rs | 10 + .../celox-runtime/src/simulation/process.rs | 11 +- crates/celox-runtime/src/simulation/round.rs | 8 +- .../src/sv/cases/procedural.vtest | 24 ++ crates/celox/src/backend/native/backend.rs | 3 + .../src/simulation/runtime_core_tests.rs | 19 ++ ...aces__trace_sv_active_commits_default.snap | 76 +++++ ...__trace_sv_active_commits_interpreter.snap | 76 +++++ .../frontends/systemverilog/procedural.rs | 4 + .../systemverilog/review_regressions.rs | 6 +- .../tests/frontends/systemverilog/timing.rs | 2 - crates/celox/tests/shared_jit_cache.rs | 28 ++ 21 files changed, 815 insertions(+), 22 deletions(-) create mode 100644 crates/celox/src/simulation/snapshots/celox__simulation__runtime_core_tests__sv_traces__trace_sv_active_commits_default.snap create mode 100644 crates/celox/src/simulation/snapshots/celox__simulation__runtime_core_tests__sv_traces__trace_sv_active_commits_interpreter.snap diff --git a/crates/celox-design/src/lib.rs b/crates/celox-design/src/lib.rs index c3ff7ae31c5..802d454df37 100644 --- a/crates/celox-design/src/lib.rs +++ b/crates/celox-design/src/lib.rs @@ -602,6 +602,10 @@ pub struct RuntimeSchema { /// Nonblocking assignment sites of the process kernels, ordered like /// `wait_sites`. pub nba_sites: Vec>, + /// Canonical event domains whose evaluation commits the results of + /// their blocking assignments, in the active region; their apply units + /// commit only the nonblocking results. + pub active_commits: Vec, } impl Default for RuntimeSchema { @@ -621,6 +625,7 @@ impl Default for RuntimeSchema { watches: Vec::new(), wait_sites: Vec::new(), nba_sites: Vec::new(), + active_commits: Vec::new(), } } } diff --git a/crates/celox-design/src/schedule.rs b/crates/celox-design/src/schedule.rs index fd8175aa5b7..27d344ee7a5 100644 --- a/crates/celox-design/src/schedule.rs +++ b/crates/celox-design/src/schedule.rs @@ -37,6 +37,9 @@ pub struct ScheduleModel { pub has_pending_nba_sites: bool, /// The design can execute `$finish`. pub finish_sites: bool, + /// Canonical event domains whose evaluation commits their blocking + /// results ([`RuntimeSchema::active_commits`]). + pub active_commits: Vec, } /// A counted signal and the canonical domains its counters trigger. @@ -129,6 +132,7 @@ impl ScheduleModel { .runtime_event_sites .iter() .any(|site| matches!(site.kind, RuntimeEventKind::Finish)), + active_commits: schema.active_commits.clone(), } } diff --git a/crates/celox-frontend-core/src/sdk.rs b/crates/celox-frontend-core/src/sdk.rs index aa42635fc38..4781f488367 100644 --- a/crates/celox-frontend-core/src/sdk.rs +++ b/crates/celox-frontend-core/src/sdk.rs @@ -1905,6 +1905,7 @@ pub fn lower_frontend_artifact( eval_only_ff_blocks, apply_ff_blocks, eval_apply_ff_blocks, + split_commit_ff_blocks: HashMap::default(), parallel_ff_parts: HashMap::default(), glue_blocks: HashMap::default(), indexed_instance_names: HashSet::default(), diff --git a/crates/celox-frontend-core/src/symbolic/artifact.rs b/crates/celox-frontend-core/src/symbolic/artifact.rs index 2baccec6144..aceb112eff9 100644 --- a/crates/celox-frontend-core/src/symbolic/artifact.rs +++ b/crates/celox-frontend-core/src/symbolic/artifact.rs @@ -54,6 +54,15 @@ pub struct SymbolicProcess { pub slots: ProcessSlots, } +/// The commit of a trigger group's results, split by region. +#[derive(Clone, Debug)] +pub struct SplitCommit { + /// Commits of the results of blocking assignments. + pub active: ExecutionUnit, + /// Commits of the results of nonblocking assignments. + pub nba: ExecutionUnit, +} + #[derive(Clone)] pub struct SimModule { /// A frontend's global tick precision; absent for scale-free frontends. @@ -67,6 +76,11 @@ pub struct SimModule { pub eval_only_ff_blocks: HashMap, ExecutionUnit>, pub apply_ff_blocks: HashMap, ExecutionUnit>, pub eval_apply_ff_blocks: HashMap, ExecutionUnit>, + /// `apply_ff_blocks` split into the commit of the blocking results (the + /// active region) and that of the nonblocking ones (the NBA region), for + /// a domain whose blocking results another unit observes before the NBA + /// region. Empty when the frontend does not distinguish them. + pub split_commit_ff_blocks: HashMap, SplitCommit>, /// Lane-partitioning alternative of `eval_only_ff_blocks` and /// `apply_ff_blocks`: a trigger group split into parts which may be /// evaluated concurrently. Empty unless several lanes were requested. diff --git a/crates/celox-frontend-core/src/symbolic/assembly.rs b/crates/celox-frontend-core/src/symbolic/assembly.rs index 7581c99d08f..1357ee3d5e0 100644 --- a/crates/celox-frontend-core/src/symbolic/assembly.rs +++ b/crates/celox-frontend-core/src/symbolic/assembly.rs @@ -1,7 +1,7 @@ use std::collections::{BTreeMap, BTreeSet}; use crate::symbolic::artifact::{ - FfPart, RelocationModule, SimModule, SymbolicGlueAddr as GlueAddr, SymbolicRtl, + FfPart, RelocationModule, SimModule, SplitCommit, SymbolicGlueAddr as GlueAddr, SymbolicRtl, }; use crate::{ FrontendLookup, FrontendTrace, FrontendTraceOptions, FusedSirOptimizationHints, HashMap, @@ -26,6 +26,10 @@ use celox_slt::{ type AbsoluteAddr = SourceAddr; type RegionedAbsoluteAddr = RegionedAbsoluteAddrBase; + +/// Per canonical event, the split commit of each of its apply units, in +/// their order; `None` for a unit whose frontend does not split it. +type SplitCommits = HashMap>>>; type RegionedVarAddr = celox_design::RegionedVarAddrBase; /// Runtime IDs assigned while a module instance is relocated into the global @@ -641,6 +645,7 @@ pub fn schedule_symbolic_rtl( unify_clock_domains(bindings, &expanded, &instance_modules, &modules) ); let mut parallel_ff_units = HashMap::default(); + let mut split_commits = SplitCommits::default(); let ( mut global_arena, mut eval_apply_ffs, @@ -668,6 +673,7 @@ pub fn schedule_symbolic_rtl( &unpacked_element_widths, &clock_domains, parallel.enabled().then_some(&mut parallel_ff_units), + &mut split_commits, trace_opts, &mut trace, ) @@ -705,6 +711,8 @@ pub fn schedule_symbolic_rtl( &mut comb_blocks, ) }; + // Combinational values and the variables they are computed from. + let comb_sources = comb_sources(&comb_blocks, &global_arena); check_package_variable_drivers( bindings, &instance_modules, @@ -1228,6 +1236,31 @@ pub fn schedule_symbolic_rtl( eval_apply_ffs, } }); + // With process kernels, a domain whose blocking results another unit + // observes commits them with its evaluation, in the active region, and + // only its nonblocking results in the NBA region (IEEE 1800-2023 4.5, + // 10.4). Every other domain commits both together, as before. + let mut active_commits = Vec::new(); + if !processes.is_empty() { + let events: HashSet = eval_apply_ffs + .keys() + .copied() + .chain(clock_domains.keys().copied()) + .collect(); + active_commits = split_observed_commits( + &mut eval_only_ffs, + &mut apply_ffs, + split_commits, + &comb_sources, + processes.iter().map(|process| &process.kernel), + timing + .wait_sites + .iter() + .flat_map(|site| site.terms.iter().map(|(signal, _)| *signal)), + &events, + &clock_domains, + ); + } let (eval_only_ffs, apply_ffs) = if needs_split_path { (eval_only_ffs, apply_ffs) } else { @@ -1523,6 +1556,7 @@ pub fn schedule_symbolic_rtl( wait_sites.iter().map(|site| site.map(project)).collect(); let nba_sites: Vec> = nba_sites.iter().map(|site| site.map(project)).collect(); + let active_commits: Vec = active_commits.into_iter().map(project).collect(); // The runtime reads counters, the signals waits watch and staged // nonblocking values directly; no unit loads a wait's signal. let timing_read_roots = watches @@ -1590,6 +1624,7 @@ pub fn schedule_symbolic_rtl( watches, wait_sites, nba_sites, + active_commits, }, }; @@ -2291,6 +2326,7 @@ fn relocate_units( parallel_ff_units: Option< &mut HashMap)>>, >, + split_commits: &mut SplitCommits, trace_opts: &crate::FrontendTraceOptions, trace: &mut Option<&mut crate::FrontendTrace>, ) -> Result< @@ -2640,6 +2676,42 @@ fn relocate_units( .get(&clock_addr) .copied() .unwrap_or(clock_addr); + // The split commit of each apply unit, in the same order. + let split = sim_module + .split_commit_ff_blocks + .get(trigger_set) + .map(|split| SplitCommit { + active: relocate_executation_unit_with_errors( + &split.active, + &|addr| bindings.locate_regioned(addr.region, *id, addr.var_id), + &runtime_error_codes, + &runtime_event_site_map, + &extern_function_map, + ), + nba: relocate_executation_unit_with_errors( + &split.nba, + &|addr| bindings.locate_regioned(addr.region, *id, addr.var_id), + &runtime_error_codes, + &runtime_event_site_map, + &extern_function_map, + ), + }); + // Pushed like the apply units below: the clock, then each reset. + split_commits + .entry(canonical_addr) + .or_default() + .push(split.clone()); + for &reset in &trigger_set.resets { + let reset_addr = bindings.locate(*id, reset); + let canonical_addr = clock_domains + .get(&reset_addr) + .copied() + .unwrap_or(reset_addr); + split_commits + .entry(canonical_addr) + .or_default() + .push(split.clone()); + } apply_ffs.entry(canonical_addr).or_default().push( relocate_executation_unit_with_errors( eu, @@ -2731,6 +2803,139 @@ struct TimingMetadata { nba_sites: Vec>, } +/// For every combinational value, the variables it is computed from. +fn comb_sources( + comb_blocks: &[celox_slt::LogicPath], + arena: &SLTNodeArena, +) -> HashMap> { + let mut sources: HashMap> = HashMap::default(); + for path in comb_blocks { + let Some(target) = path.target.var() else { + continue; + }; + let mut inputs = HashSet::default(); + if matches!(path.target, celox_slt::LogicPathTarget::Process { .. }) { + inputs.extend(path.sources.iter().cloned()); + } else { + crate::flattening::collect_inputs(path.expr, arena, &mut inputs); + } + sources + .entry(target.id) + .or_default() + .extend(inputs.into_iter().map(|atom| atom.id)); + } + sources +} + +/// The variables `unit` loads. +fn unit_loads(unit: &ExecutionUnit, loads: &mut HashSet) { + for block in unit.blocks.values() { + for instruction in &block.instructions { + if let SIRInstruction::Load(_, addr, ..) = instruction { + loads.insert(addr.absolute_addr()); + } + } + } +} + +/// `reads` closed over combinational logic: with a value, the variables it +/// is computed from. +fn through_comb( + mut reads: HashSet, + comb_sources: &HashMap>, +) -> HashSet { + let mut pending: Vec = reads.iter().copied().collect(); + while let Some(read) = pending.pop() { + for source in comb_sources.get(&read).into_iter().flatten() { + if reads.insert(*source) { + pending.push(*source); + } + } + } + reads +} + +/// Move the commits of the blocking results of every observed domain from +/// its apply units to its evaluation: a blocking result is observed when +/// it, or a combinational value computed from it, is read by a process +/// kernel or by another domain's evaluation, is a wait term, or is another +/// domain's event signal. Domains whose apply units the frontend did not +/// split keep them. +#[allow(clippy::too_many_arguments)] +fn split_observed_commits<'k>( + eval_only_ffs: &mut HashMap>>, + apply_ffs: &mut HashMap>>, + split_commits: SplitCommits, + comb_sources: &HashMap>, + kernels: impl Iterator>, + wait_terms: impl Iterator, + events: &HashSet, + clock_domains: &HashMap, +) -> Vec { + let mut split = Vec::new(); + let mut shared: HashSet = wait_terms.collect(); + for kernel in kernels { + unit_loads(kernel, &mut shared); + } + let evaluation_loads: HashMap> = eval_only_ffs + .iter() + .map(|(event, units)| { + let mut loads = HashSet::default(); + for unit in units { + unit_loads(unit, &mut loads); + } + (*event, loads) + }) + .collect(); + let canonical = |event: &AbsoluteAddr| clock_domains.get(event).copied().unwrap_or(*event); + for (domain, splits) in split_commits { + let Some(splits) = splits.into_iter().collect::>>() else { + continue; + }; + if apply_ffs.get(&domain).map_or(0, Vec::len) != splits.len() { + continue; + } + let mut blocking = HashSet::default(); + for split in &splits { + for block in split.active.blocks.values() { + for instruction in &block.instructions { + if let SIRInstruction::Commit(_, dst, ..) = instruction { + blocking.insert(dst.absolute_addr()); + } + } + } + } + if blocking.is_empty() { + continue; + } + let mut reads = shared.clone(); + reads.extend( + events + .iter() + .filter(|event| canonical(event) != domain) + .copied(), + ); + for (event, loads) in &evaluation_loads { + if *event != domain { + reads.extend(loads.iter().copied()); + } + } + let reads = through_comb(reads, comb_sources); + if blocking.is_disjoint(&reads) { + continue; + } + let (active, nba): (Vec<_>, Vec<_>) = splits + .into_iter() + .map(|split| (split.active, split.nba)) + .unzip(); + eval_only_ffs.entry(domain).or_default().extend(active); + apply_ffs.insert(domain, nba); + split.push(domain); + } + split.sort_unstable(); + split +} + /// Place the timing metadata of every instance. Sites name the global index /// of their process; a kernel numbers its sites in the order they appear /// here, which is the module's order. diff --git a/crates/celox-frontend-sv/src/lowering.rs b/crates/celox-frontend-sv/src/lowering.rs index 80cb127432b..339d3836e6b 100644 --- a/crates/celox-frontend-sv/src/lowering.rs +++ b/crates/celox-frontend-sv/src/lowering.rs @@ -1978,6 +1978,7 @@ fn lower_module_with_overrides( eval_only_ff_blocks, apply_ff_blocks, eval_apply_ff_blocks, + split_commit_ff_blocks, reset_clock_map, parallel_ff_parts, event_vars, @@ -2094,6 +2095,7 @@ fn lower_module_with_overrides( eval_only_ff_blocks, apply_ff_blocks, eval_apply_ff_blocks, + split_commit_ff_blocks, parallel_ff_parts, glue_blocks: HashMap::default(), indexed_instance_names: HashSet::default(), @@ -6294,6 +6296,10 @@ type SvFfBlocks = ( HashMap, ExecutionUnit>, HashMap, ExecutionUnit>, HashMap, ExecutionUnit>, + HashMap< + TriggerSet, + celox_frontend_core::symbolic::artifact::SplitCommit, + >, HashMap, HashMap< TriggerSet, @@ -6390,6 +6396,8 @@ fn lower_ff_processes( let mut parallel_ff_parts = HashMap::<_, Vec<_>>::default(); let mut eval_only_ff_blocks = HashMap::default(); let mut apply_ff_blocks = HashMap::default(); + let mut active_ff_blocks = HashMap::default(); + let mut nba_ff_blocks: HashMap<_, ExecutionUnit> = HashMap::default(); let mut eval_apply_ff_blocks = HashMap::default(); let mut reset_clock_map = HashMap::default(); @@ -6451,8 +6459,13 @@ fn lower_ff_processes( } let sites_before = pm.runtime_event_sites.len(); let extern_calls_before = pm.extern_calls; - let (eval_only, apply, targets) = - ff::Ff::new(pm, random_seeds[&(0, index)]).lower_process(process.body())?; + let ff::FfProcessUnits { + eval: eval_only, + apply, + active, + nba, + targets, + } = ff::Ff::new(pm, random_seeds[&(0, index)]).lower_process(process.body())?; // A process without writes still runs for its runtime events and // extern calls. let has_effects = @@ -6470,7 +6483,9 @@ fn lower_ff_processes( }); } insert_or_merge_ff_unit(&mut eval_only_ff_blocks, trigger_set.clone(), eval_only); - insert_or_merge_ff_unit(&mut apply_ff_blocks, trigger_set, apply); + insert_or_merge_ff_unit(&mut apply_ff_blocks, trigger_set.clone(), apply); + insert_or_merge_ff_unit(&mut active_ff_blocks, trigger_set.clone(), active); + insert_or_merge_ff_unit(&mut nba_ff_blocks, trigger_set, nba); } // Every process of a trigger evaluates against the pre-edge state before // any of them commits (IEEE 1800-2023 10.4.2), so the combined unit runs @@ -6484,10 +6499,23 @@ fn lower_ff_processes( // One process is the whole trigger group. parallel_ff_parts.retain(|_, parts| parts.len() > 1); + let split_commit_ff_blocks = active_ff_blocks + .into_iter() + .map(|(trigger_set, active)| { + let nba = nba_ff_blocks + .remove(&trigger_set) + .expect("every trigger group has both commits"); + ( + trigger_set, + celox_frontend_core::symbolic::artifact::SplitCommit { active, nba }, + ) + }) + .collect(); Ok(( eval_only_ff_blocks, apply_ff_blocks, eval_apply_ff_blocks, + split_commit_ff_blocks, reset_clock_map, parallel_ff_parts, event_vars, diff --git a/crates/celox-frontend-sv/src/lowering/ff.rs b/crates/celox-frontend-sv/src/lowering/ff.rs index 3c8947420e5..431ca8eea0f 100644 --- a/crates/celox-frontend-sv/src/lowering/ff.rs +++ b/crates/celox-frontend-sv/src/lowering/ff.rs @@ -35,6 +35,8 @@ pub(super) struct Ff<'p, 'a> { b: SIRBuilder, /// Variables read from the working region. working: HashSet, + /// Variables a nonblocking assignment writes. + nonblocking: HashSet, /// The bits whose working value is the process result. targets: Vec<(SourceVarId, BitAccess)>, loops: Vec, @@ -92,6 +94,7 @@ impl<'p, 'a> Ff<'p, 'a> { m, b: SIRBuilder::new(), working: HashSet::default(), + nonblocking: HashSet::default(), targets: Vec::new(), loops: Vec::new(), functions: Vec::new(), @@ -138,6 +141,8 @@ impl<'p, 'a> Ff<'p, 'a> { }; if blocking { self.working.insert(id); + } else { + self.nonblocking.insert(id); } if self.m.is_hidden(id) { return; @@ -2860,14 +2865,7 @@ impl<'p, 'a> Ff<'p, 'a> { pub fn lower_process( mut self, body: &[sv::ir::Stmt], - ) -> Result< - ( - ExecutionUnit, - ExecutionUnit, - Vec>, - ), - sv::AnalyzerError, - > { + ) -> Result { let mut visited = HashSet::default(); self.scan(body, &mut visited); // Merge the written ranges of each variable. @@ -2894,14 +2892,275 @@ impl<'p, 'a> Ff<'p, 'a> { .map(|access| VarAtomBase::new(id, access.lsb, access.msb)), ); } + // A variable the process writes both ways keeps its nonblocking + // values apart: blocking reads see the blocking value, and the + // nonblocking update lands after it (IEEE 1800-2023 10.4). + let mut mixed: Vec = self + .nonblocking + .intersection(&self.working) + .copied() + .filter(|&id| !self.m.is_hidden(id) && self.m.var(id).array_dims.is_empty()) + .collect(); + mixed.sort_by_key(|id| id.0); + let staged: Vec = mixed + .into_iter() + .map(|id| { + let (value, value_name) = self.m.shadow(id, "nba_value", false); + let (mask, mask_name) = self.m.shadow(id, "nba_mask", true); + NbaStage { + id, + name: self.m.var(id).path.join("."), + value, + value_name, + mask, + mask_name, + } + }) + .collect(); + let body = if staged.is_empty() { + body.to_vec() + } else { + stage_nonblocking(body, &staged, self.m) + }; emit_ff_seeds(&mut self.b, &targets); - if self.exec_block(body)? { + for stage in &staged { + let width = self.m.var(stage.mask).width; + let zero = self.b.alloc_bit(width, false); + self.b.emit(SIRInstruction::Imm(zero, SIRValue::new(0u8))); + self.store(stage.mask, SIROffset::Static(0), width, zero); + } + if self.exec_block(&body)? { self.b.seal_block(SIRTerminator::Return); } let eval = seal_drained(self.b); + let (active_targets, nba_targets): (Vec<_>, Vec<_>) = targets + .iter() + .copied() + .partition(|target| self.working.contains(&target.id)); let mut apply = SIRBuilder::new(); emit_ff_commits(&mut apply, &targets); - Ok((eval, seal_builder(apply), targets)) + emit_nba_merges(&mut apply, &staged, self.m); + let mut active = SIRBuilder::new(); + emit_ff_commits(&mut active, &active_targets); + let mut nba = SIRBuilder::new(); + emit_ff_commits(&mut nba, &nba_targets); + emit_nba_merges(&mut nba, &staged, self.m); + Ok(FfProcessUnits { + eval, + apply: seal_builder(apply), + active: seal_builder(active), + nba: seal_builder(nba), + targets, + }) + } +} + +/// The units of an edge-triggered process: its evaluation, the commit of +/// all its results, and that commit split into the blocking results (the +/// active region) and the nonblocking ones (the NBA region). +pub(super) struct FfProcessUnits { + pub eval: ExecutionUnit, + pub apply: ExecutionUnit, + pub active: ExecutionUnit, + pub nba: ExecutionUnit, + pub targets: Vec>, +} + +/// The staging of a variable a process writes both by blocking and by +/// nonblocking assignments: the nonblocking value and a mask of the bits +/// the nonblocking assignments wrote. +struct NbaStage { + id: SourceVarId, + name: String, + value: SourceVarId, + value_name: String, + mask: SourceVarId, + mask_name: String, +} + +/// `stmts` with every nonblocking assignment to a staged variable writing +/// its staging value instead, and marking the written bits in its mask. +fn stage_nonblocking( + stmts: &[sv::ir::Stmt], + staged: &[NbaStage], + pm: &ProcModule<'_>, +) -> Vec { + let stage_of = |lvalue: &sv::ir::LValue| { + staged + .iter() + .find(|stage| pm.id(lvalue.name()) == Some(stage.id)) + }; + let renamed = |lvalue: &sv::ir::LValue, name: &str| match lvalue { + sv::ir::LValue::Ident(_) => sv::ir::LValue::Ident(name.to_string()), + sv::ir::LValue::Select { + msb, + lsb, + array_slice_width, + array_slice_reversed, + .. + } => sv::ir::LValue::Select { + name: name.to_string(), + msb: msb.clone(), + lsb: lsb.clone(), + array_slice_width: array_slice_width.clone(), + array_slice_reversed: *array_slice_reversed, + }, + }; + let mark = |lvalue: &sv::ir::LValue, stage: &NbaStage| sv::ir::Stmt::Assign { + lhs: renamed(lvalue, &stage.mask_name), + rhs: sv::ir::Expr::Literal("'1".to_string()), + nonblocking: true, + }; + let mut out = Vec::with_capacity(stmts.len()); + for stmt in stmts { + match stmt { + sv::ir::Stmt::Assign { + lhs, + rhs, + nonblocking: true, + } if stage_of(lhs).is_some() => { + let stage = stage_of(lhs).unwrap(); + out.push(sv::ir::Stmt::Assign { + lhs: renamed(lhs, &stage.value_name), + rhs: rhs.clone(), + nonblocking: true, + }); + out.push(mark(lhs, stage)); + } + sv::ir::Stmt::AssignConcat { + parts, + rhs, + nonblocking: true, + } if parts.iter().any(|part| stage_of(part).is_some()) => { + out.push(sv::ir::Stmt::AssignConcat { + parts: parts + .iter() + .map(|part| match stage_of(part) { + Some(stage) => renamed(part, &stage.value_name), + None => part.clone(), + }) + .collect(), + rhs: rhs.clone(), + nonblocking: true, + }); + for part in parts { + if let Some(stage) = stage_of(part) { + out.push(mark(part, stage)); + } + } + } + sv::ir::Stmt::If { + condition, + then_body, + else_body, + } => out.push(sv::ir::Stmt::If { + condition: condition.clone(), + then_body: stage_nonblocking(then_body, staged, pm), + else_body: stage_nonblocking(else_body, staged, pm), + }), + sv::ir::Stmt::Case { + kind, + selector, + items, + default, + } => out.push(sv::ir::Stmt::Case { + kind: *kind, + selector: selector.clone(), + items: items + .iter() + .map(|item| sv::ir::CaseItem { + labels: item.labels.clone(), + body: stage_nonblocking(&item.body, staged, pm), + }) + .collect(), + default: default + .as_ref() + .map(|body| stage_nonblocking(body, staged, pm)), + }), + sv::ir::Stmt::Loop { + kind, + init, + condition, + step, + body, + } => out.push(sv::ir::Stmt::Loop { + kind: kind.clone(), + init: init.clone(), + condition: condition.clone(), + step: step.clone(), + body: stage_nonblocking(body, staged, pm), + }), + other => out.push(other.clone()), + } + } + out +} + +/// Publish the staged nonblocking values: each variable takes its staging +/// value in the bits the mask marks, after its blocking value was +/// committed. +fn emit_nba_merges(builder: &mut SIRBuilder, staged: &[NbaStage], pm: &ProcModule<'_>) { + for stage in staged { + let _ = &stage.name; + let variable = pm.var(stage.id); + let width = variable.width; + let current = if variable.is_4state { + builder.alloc_logic(width) + } else { + builder.alloc_bit(width, false) + }; + builder.emit(SIRInstruction::Load( + current, + stable(stage.id), + SIROffset::Static(0), + width, + )); + let value = if variable.is_4state { + builder.alloc_logic(width) + } else { + builder.alloc_bit(width, false) + }; + builder.emit(SIRInstruction::Load( + value, + working(stage.value), + SIROffset::Static(0), + width, + )); + let mask = builder.alloc_bit(width, false); + builder.emit(SIRInstruction::Load( + mask, + working(stage.mask), + SIROffset::Static(0), + width, + )); + let keep = builder.alloc_bit(width, false); + builder.emit(SIRInstruction::Unary(keep, UnaryOp::BitNot, mask)); + let kept = if variable.is_4state { + builder.alloc_logic(width) + } else { + builder.alloc_bit(width, false) + }; + builder.emit(SIRInstruction::Binary(kept, current, BinaryOp::And, keep)); + let taken = if variable.is_4state { + builder.alloc_logic(width) + } else { + builder.alloc_bit(width, false) + }; + builder.emit(SIRInstruction::Binary(taken, value, BinaryOp::And, mask)); + let merged = if variable.is_4state { + builder.alloc_logic(width) + } else { + builder.alloc_bit(width, false) + }; + builder.emit(SIRInstruction::Binary(merged, kept, BinaryOp::Or, taken)); + builder.emit(SIRInstruction::Store( + stable(stage.id), + SIROffset::Static(0), + width, + merged, + Vec::new(), + Vec::new(), + )); } } diff --git a/crates/celox-frontend-sv/src/lowering/procedural.rs b/crates/celox-frontend-sv/src/lowering/procedural.rs index b87fd7840c6..443c823aede 100644 --- a/crates/celox-frontend-sv/src/lowering/procedural.rs +++ b/crates/celox-frontend-sv/src/lowering/procedural.rs @@ -523,6 +523,31 @@ impl<'a> ProcModule<'a> { (id, name) } + /// A hidden variable with the shape of `id`, two-state when `two_state`. + pub fn shadow( + &mut self, + id: SourceVarId, + purpose: &str, + two_state: bool, + ) -> (SourceVarId, String) { + let name = format!("{purpose}@t{}", self.temp_counter); + self.temp_counter += 1; + let mut variable = self.variables[&id].clone(); + variable.path = vec![name.clone()]; + variable.source = None; + variable.hidden = true; + variable.domain_kind = DomainKind::Other; + if two_state { + variable.is_4state = false; + variable.type_kind = PortTypeKind::Bit; + } + let shadow = next_var_id(&mut self.next_id); + self.variables.insert(shadow, variable); + self.name_to_id.insert(name.clone(), shadow); + self.created.push(shadow); + (shadow, name) + } + /// A hidden one-bit copy of the event signal `signal`, sensed as `kind`. /// It has no name a SystemVerilog identifier can denote, and is not /// addressable by path. diff --git a/crates/celox-frontend-veryl/src/artifact.rs b/crates/celox-frontend-veryl/src/artifact.rs index 728194843a8..0a22ef077fb 100644 --- a/crates/celox-frontend-veryl/src/artifact.rs +++ b/crates/celox-frontend-veryl/src/artifact.rs @@ -494,6 +494,7 @@ pub(crate) fn project_module_with_ids( eval_only_ff_blocks: map_units(&module.eval_only_ff_blocks), apply_ff_blocks: map_units(&module.apply_ff_blocks), eval_apply_ff_blocks: map_units(&module.eval_apply_ff_blocks), + split_commit_ff_blocks: HashMap::default(), parallel_ff_parts: module .parallel_ff_parts .iter() diff --git a/crates/celox-runtime/src/schedule.rs b/crates/celox-runtime/src/schedule.rs index 65117fe6f3f..60ffe7a7db4 100644 --- a/crates/celox-runtime/src/schedule.rs +++ b/crates/celox-runtime/src/schedule.rs @@ -32,6 +32,8 @@ pub struct ResolvedSchedule { /// The design has process kernels or counted signals. Without either, a /// round is exactly the batch step and skips every process check. pub(crate) timed: bool, + /// Canonical event IDs whose evaluation commits their blocking results. + pub(crate) active_commits: bit_set::BitSet, } impl ResolvedSchedule { @@ -174,6 +176,13 @@ impl ResolvedSchedule { .collect() }; + let mut active_commits = bit_set::BitSet::new(); + for address in &model.active_commits { + if let Some(event) = backend.resolve_event_opt(address) { + active_commits.insert(event.id()); + } + } + let counted_by_offset = counted .iter() .enumerate() @@ -191,6 +200,7 @@ impl ResolvedSchedule { has_pending_nba_sites: model.has_pending_nba_sites, combinational_derived, timed: model.timed, + active_commits, } } } diff --git a/crates/celox-runtime/src/simulation/process.rs b/crates/celox-runtime/src/simulation/process.rs index 2fcc709482f..8fe00cce48d 100644 --- a/crates/celox-runtime/src/simulation/process.rs +++ b/crates/celox-runtime/src/simulation/process.rs @@ -182,7 +182,16 @@ impl SimulationState { } // The active region is empty: the domains it triggered evaluate // before the inactive region's processes resume. - self.evaluate_before_inactive(executor, current_time, round)?; + if self.evaluate_before_inactive(executor, current_time, round)? { + // Their blocking results are updates of the active region: + // continuous assignments follow them and the waits they wake + // run before the inactive region (IEEE 1800-2023 4.5). + executor.eval_comb()?; + self.observe_driven(executor.backend()); + if !self.process_state.ready.is_empty() { + continue; + } + } let inactive = std::mem::take(&mut self.process_state.inactive); self.process_state.ready.extend(inactive); } diff --git a/crates/celox-runtime/src/simulation/round.rs b/crates/celox-runtime/src/simulation/round.rs index 6ffae56c3a8..af1ce6c4676 100644 --- a/crates/celox-runtime/src/simulation/round.rs +++ b/crates/celox-runtime/src/simulation/round.rs @@ -175,19 +175,20 @@ impl SimulationState { /// Evaluate the triggered domains before an inactive region runs. Their /// nonblocking assignments stay in the working state until the NBA - /// region. + /// region. Returns whether a domain committed its blocking results. pub(super) fn evaluate_before_inactive( &mut self, executor: &mut E, current_time: u64, round: &mut Round, - ) -> Result<(), Halt> + ) -> Result where E: SimulationExecutor, { let marked = executor.backend().get_triggered_bits(); executor.backend_mut().clear_triggered_bits(); let mut evaluated = BitSet::new(); + let mut committed = false; let mut unsplit = Vec::new(); for id in marked.iter() { let info = self.model.event_info[id]; @@ -209,6 +210,7 @@ impl SimulationState { continue; } round.edge_approved.remove(id); + committed |= self.model.active_commits.contains(info.canonical_id); self.evaluate_deferred(executor, current_time, round, info)?; } // The edges are consumed: later rounds compare against the values @@ -223,7 +225,7 @@ impl SimulationState { round.scheduled_trigger_ids.insert(id); round.edge_approved.insert(id); } - Ok(()) + Ok(committed) } fn evaluate_deferred( diff --git a/crates/celox-test-suite/src/sv/cases/procedural.vtest b/crates/celox-test-suite/src/sv/cases/procedural.vtest index 0107c47f135..12890845ac2 100644 --- a/crates/celox-test-suite/src/sv/cases/procedural.vtest +++ b/crates/celox-test-suite/src/sv/cases/procedural.vtest @@ -46,6 +46,30 @@ (assert_eq shifted (trunc 8 (<< data count))) (assert_eq q data))) +(case mixed_blocking_and_nonblocking_writes_keep_their_regions + (source "mixed_writes.sv" #" + module Top(input logic clk, input logic [7:0] d, + output logic [7:0] q, output logic [7:0] x, output logic [7:0] r); + always @(posedge clk) begin + q <= d; + x = q; + q = 8'd2; + r = q; + end + endmodule + "#) + (top Top) + (modify (set d 7)) + (tick clk) + (assert_eq q 7 "the nonblocking update lands after the blocking one") + (assert_eq x 0 "a read after a nonblocking assignment sees the old value") + (assert_eq r 2) + (modify (set d 9)) + (tick clk) + (assert_eq q 9) + (assert_eq x 7) + (assert_eq r 2)) + (case constant_functions_size_parameters_and_ports (source "constant_functions.sv" #" module Child #(parameter int unsigned ENTRIES = 2, diff --git a/crates/celox/src/backend/native/backend.rs b/crates/celox/src/backend/native/backend.rs index e336bfe84e9..2e4c629acb6 100644 --- a/crates/celox/src/backend/native/backend.rs +++ b/crates/celox/src/backend/native/backend.rs @@ -395,6 +395,7 @@ pub(crate) struct NativeRuntimeSchema { pub(crate) watches: Vec>, pub(crate) wait_sites: Vec>, pub(crate) nba_sites: Vec>, + pub(crate) active_commits: Vec, } /// Pointer-free native compiler artifact which can be attached to the @@ -504,6 +505,7 @@ impl NativeProgramImage { watches: self.runtime_schema.watches.clone(), wait_sites: self.runtime_schema.wait_sites.clone(), nba_sites: self.runtime_schema.nba_sites.clone(), + active_commits: self.runtime_schema.active_commits.clone(), }, testbench: self.testbench.clone(), } @@ -2283,6 +2285,7 @@ fn compile_program( watches: sir.runtime().runtime_schema.watches.clone(), wait_sites: sir.runtime().runtime_schema.wait_sites.clone(), nba_sites: sir.runtime().runtime_schema.nba_sites.clone(), + active_commits: sir.runtime().runtime_schema.active_commits.clone(), }, layout: layout.clone(), native_memory_size, diff --git a/crates/celox/src/simulation/runtime_core_tests.rs b/crates/celox/src/simulation/runtime_core_tests.rs index 34ae5750e20..5a49f637753 100644 --- a/crates/celox/src/simulation/runtime_core_tests.rs +++ b/crates/celox/src/simulation/runtime_core_tests.rs @@ -2297,6 +2297,25 @@ mod sv_traces { /// divided clock, both edges of one clock, and the timing suite's cases /// that Celox runs. const DESIGNS: &[(&str, &str, &[&str], &[&str])] = &[ + ( + // A domain whose blocking result a process reads after `#0` + // commits it in the active region and its nonblocking update in + // the NBA region (#1470). + "sv_active_commits", + "module Top(input logic clk, output logic [7:0] q, output logic [7:0] observed, + output logic [7:0] derived_seen); + wire [7:0] derived = q + 8'd1; + always @(posedge clk) begin q <= q + 8'd7; q = 8'd2; end + initial forever begin + @(posedge clk); + #0; + observed = q; + derived_seen = derived; + end + endmodule", + &["clk"], + &["q", "observed", "derived_seen"], + ), ( "sv_buffered_clock", "module Top(input logic clk, output logic [31:0] up, output logic [31:0] down); diff --git a/crates/celox/src/simulation/snapshots/celox__simulation__runtime_core_tests__sv_traces__trace_sv_active_commits_default.snap b/crates/celox/src/simulation/snapshots/celox__simulation__runtime_core_tests__sv_traces__trace_sv_active_commits_default.snap new file mode 100644 index 00000000000..ece66b1e8a1 --- /dev/null +++ b/crates/celox/src/simulation/snapshots/celox__simulation__runtime_core_tests__sv_traces__trace_sv_active_commits_default.snap @@ -0,0 +1,76 @@ +--- +source: crates/celox/src/simulation/runtime_core_tests.rs +expression: "trace(Simulation::from_sv_sources(sources(), \"Top\").build().unwrap(), &ops,\nobserve)" +--- +modify [("clk", 0)] +run_until 0 + step -> Some(0): host_writes(0) process(0) comb finish_step(0) + time 0 finished false: q=0 observed=0 derived_seen=0 +modify [("clk", 37)] +run_until 2 + step -> Some(0): host_writes(1) process(0) comb stage(e0@0) eval_only(e0) comb process(0) comb apply(e0) fire(e0@0) comb finish_step(0) + time 2 finished false: q=7 observed=2 derived_seen=3 +modify [("clk", 74)] +run_until 4 + step -> Some(2): host_writes(1) comb finish_step(2) + time 4 finished false: q=7 observed=2 derived_seen=3 +modify [("clk", 111)] +run_until 6 + step -> Some(4): host_writes(1) process(0) comb stage(e0@4) eval_only(e0) comb process(0) comb apply(e0) fire(e0@4) comb finish_step(4) + time 6 finished false: q=14 observed=2 derived_seen=3 +modify [("clk", 148)] +run_until 8 + step -> Some(6): host_writes(1) comb finish_step(6) + time 8 finished false: q=14 observed=2 derived_seen=3 +modify [("clk", 185)] +run_until 10 + step -> Some(8): host_writes(1) process(0) comb stage(e0@8) eval_only(e0) comb process(0) comb apply(e0) fire(e0@8) comb finish_step(8) + time 10 finished false: q=21 observed=2 derived_seen=3 +modify [("clk", 222)] +run_until 12 + step -> Some(10): host_writes(1) comb finish_step(10) + time 12 finished false: q=21 observed=2 derived_seen=3 +modify [("clk", 1), ("clk", 0)] +run_until 14 + step -> Some(12): host_writes(2) process(0) comb process(0) comb finish_step(12) + time 14 finished false: q=21 observed=21 derived_seen=22 +schedule clk @15 = 1 +schedule clk @16 = 0 +schedule clk @17 = 1 +schedule clk @17 = 0 +schedule clk @18 = 1 +schedule clk @19 = 0 +run_until 20 + step -> Some(15): host_writes(0) process(0) comb stage(e0@15) eval_only(e0) comb process(0) comb apply(e0) fire(e0@15) comb finish_step(15) + step -> Some(16): host_writes(0) comb finish_step(16) + step -> Some(17): host_writes(0) process(0) comb stage(e0@17) eval_only(e0) comb process(0) comb apply(e0) fire(e0@17) comb finish_step(17) + step -> Some(18): host_writes(0) comb finish_step(18) + step -> Some(19): host_writes(0) comb finish_step(19) + time 20 finished false: q=35 observed=2 derived_seen=3 +clock clk period 4 delay 21 +run_until 40 + step -> Some(21): host_writes(0) process(0) comb stage(e0@21) eval_only(e0) comb process(0) comb apply(e0) fire(e0@21) comb finish_step(21) + step -> Some(23): host_writes(0) comb finish_step(23) + step -> Some(25): host_writes(0) process(0) comb stage(e0@25) eval_only(e0) comb process(0) comb apply(e0) fire(e0@25) comb finish_step(25) + step -> Some(27): host_writes(0) comb finish_step(27) + step -> Some(29): host_writes(0) process(0) comb stage(e0@29) eval_only(e0) comb process(0) comb apply(e0) fire(e0@29) comb finish_step(29) + step -> Some(31): host_writes(0) comb finish_step(31) + step -> Some(33): host_writes(0) process(0) comb stage(e0@33) eval_only(e0) comb process(0) comb apply(e0) fire(e0@33) comb finish_step(33) + step -> Some(35): host_writes(0) comb finish_step(35) + step -> Some(37): host_writes(0) process(0) comb stage(e0@37) eval_only(e0) comb process(0) comb apply(e0) fire(e0@37) comb finish_step(37) + step -> Some(39): host_writes(0) comb finish_step(39) + time 40 finished false: q=70 observed=2 derived_seen=3 +steps 12 + step -> Some(41): host_writes(0) process(0) comb stage(e0@41) eval_only(e0) comb process(0) comb apply(e0) fire(e0@41) comb finish_step(41) + step -> Some(43): host_writes(0) comb finish_step(43) + step -> Some(45): host_writes(0) process(0) comb stage(e0@45) eval_only(e0) comb process(0) comb apply(e0) fire(e0@45) comb finish_step(45) + step -> Some(47): host_writes(0) comb finish_step(47) + step -> Some(49): host_writes(0) process(0) comb stage(e0@49) eval_only(e0) comb process(0) comb apply(e0) fire(e0@49) comb finish_step(49) + step -> Some(51): host_writes(0) comb finish_step(51) + step -> Some(53): host_writes(0) process(0) comb stage(e0@53) eval_only(e0) comb process(0) comb apply(e0) fire(e0@53) comb finish_step(53) + step -> Some(55): host_writes(0) comb finish_step(55) + step -> Some(57): host_writes(0) process(0) comb stage(e0@57) eval_only(e0) comb process(0) comb apply(e0) fire(e0@57) comb finish_step(57) + step -> Some(59): host_writes(0) comb finish_step(59) + step -> Some(61): host_writes(0) process(0) comb stage(e0@61) eval_only(e0) comb process(0) comb apply(e0) fire(e0@61) comb finish_step(61) + step -> Some(63): host_writes(0) comb finish_step(63) + time 63 finished false: q=112 observed=2 derived_seen=3 diff --git a/crates/celox/src/simulation/snapshots/celox__simulation__runtime_core_tests__sv_traces__trace_sv_active_commits_interpreter.snap b/crates/celox/src/simulation/snapshots/celox__simulation__runtime_core_tests__sv_traces__trace_sv_active_commits_interpreter.snap new file mode 100644 index 00000000000..bcd65cd0db1 --- /dev/null +++ b/crates/celox/src/simulation/snapshots/celox__simulation__runtime_core_tests__sv_traces__trace_sv_active_commits_interpreter.snap @@ -0,0 +1,76 @@ +--- +source: crates/celox/src/simulation/runtime_core_tests.rs +expression: "trace(Simulation::new(Simulator::from_sv_sources(sources(),\n\"Top\").emit_triggers().build_interpreter().unwrap()), &ops, observe)" +--- +modify [("clk", 0)] +run_until 0 + step -> Some(0): host_writes(0) process(0) comb finish_step(0) + time 0 finished false: q=0 observed=0 derived_seen=0 +modify [("clk", 37)] +run_until 2 + step -> Some(0): host_writes(1) process(0) comb stage(e0@0) eval_only(e0) comb process(0) comb apply(e0) fire(e0@0) comb finish_step(0) + time 2 finished false: q=7 observed=2 derived_seen=3 +modify [("clk", 74)] +run_until 4 + step -> Some(2): host_writes(1) comb finish_step(2) + time 4 finished false: q=7 observed=2 derived_seen=3 +modify [("clk", 111)] +run_until 6 + step -> Some(4): host_writes(1) process(0) comb stage(e0@4) eval_only(e0) comb process(0) comb apply(e0) fire(e0@4) comb finish_step(4) + time 6 finished false: q=14 observed=2 derived_seen=3 +modify [("clk", 148)] +run_until 8 + step -> Some(6): host_writes(1) comb finish_step(6) + time 8 finished false: q=14 observed=2 derived_seen=3 +modify [("clk", 185)] +run_until 10 + step -> Some(8): host_writes(1) process(0) comb stage(e0@8) eval_only(e0) comb process(0) comb apply(e0) fire(e0@8) comb finish_step(8) + time 10 finished false: q=21 observed=2 derived_seen=3 +modify [("clk", 222)] +run_until 12 + step -> Some(10): host_writes(1) comb finish_step(10) + time 12 finished false: q=21 observed=2 derived_seen=3 +modify [("clk", 1), ("clk", 0)] +run_until 14 + step -> Some(12): host_writes(2) process(0) comb process(0) comb finish_step(12) + time 14 finished false: q=21 observed=21 derived_seen=22 +schedule clk @15 = 1 +schedule clk @16 = 0 +schedule clk @17 = 1 +schedule clk @17 = 0 +schedule clk @18 = 1 +schedule clk @19 = 0 +run_until 20 + step -> Some(15): host_writes(0) process(0) comb stage(e0@15) eval_only(e0) comb process(0) comb apply(e0) fire(e0@15) comb finish_step(15) + step -> Some(16): host_writes(0) comb finish_step(16) + step -> Some(17): host_writes(0) process(0) comb stage(e0@17) eval_only(e0) comb process(0) comb apply(e0) fire(e0@17) comb finish_step(17) + step -> Some(18): host_writes(0) comb finish_step(18) + step -> Some(19): host_writes(0) comb finish_step(19) + time 20 finished false: q=35 observed=2 derived_seen=3 +clock clk period 4 delay 21 +run_until 40 + step -> Some(21): host_writes(0) process(0) comb stage(e0@21) eval_only(e0) comb process(0) comb apply(e0) fire(e0@21) comb finish_step(21) + step -> Some(23): host_writes(0) comb finish_step(23) + step -> Some(25): host_writes(0) process(0) comb stage(e0@25) eval_only(e0) comb process(0) comb apply(e0) fire(e0@25) comb finish_step(25) + step -> Some(27): host_writes(0) comb finish_step(27) + step -> Some(29): host_writes(0) process(0) comb stage(e0@29) eval_only(e0) comb process(0) comb apply(e0) fire(e0@29) comb finish_step(29) + step -> Some(31): host_writes(0) comb finish_step(31) + step -> Some(33): host_writes(0) process(0) comb stage(e0@33) eval_only(e0) comb process(0) comb apply(e0) fire(e0@33) comb finish_step(33) + step -> Some(35): host_writes(0) comb finish_step(35) + step -> Some(37): host_writes(0) process(0) comb stage(e0@37) eval_only(e0) comb process(0) comb apply(e0) fire(e0@37) comb finish_step(37) + step -> Some(39): host_writes(0) comb finish_step(39) + time 40 finished false: q=70 observed=2 derived_seen=3 +steps 12 + step -> Some(41): host_writes(0) process(0) comb stage(e0@41) eval_only(e0) comb process(0) comb apply(e0) fire(e0@41) comb finish_step(41) + step -> Some(43): host_writes(0) comb finish_step(43) + step -> Some(45): host_writes(0) process(0) comb stage(e0@45) eval_only(e0) comb process(0) comb apply(e0) fire(e0@45) comb finish_step(45) + step -> Some(47): host_writes(0) comb finish_step(47) + step -> Some(49): host_writes(0) process(0) comb stage(e0@49) eval_only(e0) comb process(0) comb apply(e0) fire(e0@49) comb finish_step(49) + step -> Some(51): host_writes(0) comb finish_step(51) + step -> Some(53): host_writes(0) process(0) comb stage(e0@53) eval_only(e0) comb process(0) comb apply(e0) fire(e0@53) comb finish_step(53) + step -> Some(55): host_writes(0) comb finish_step(55) + step -> Some(57): host_writes(0) process(0) comb stage(e0@57) eval_only(e0) comb process(0) comb apply(e0) fire(e0@57) comb finish_step(57) + step -> Some(59): host_writes(0) comb finish_step(59) + step -> Some(61): host_writes(0) process(0) comb stage(e0@61) eval_only(e0) comb process(0) comb apply(e0) fire(e0@61) comb finish_step(61) + step -> Some(63): host_writes(0) comb finish_step(63) + time 63 finished false: q=112 observed=2 derived_seen=3 diff --git a/crates/celox/tests/frontends/systemverilog/procedural.rs b/crates/celox/tests/frontends/systemverilog/procedural.rs index 7dbc198f978..6dbb86aa139 100644 --- a/crates/celox/tests/frontends/systemverilog/procedural.rs +++ b/crates/celox/tests/frontends/systemverilog/procedural.rs @@ -19,6 +19,10 @@ sv_backends! { @case "procedural::always_ff_blocking_assignments_and_run_time_loops"; } + fn mixed_blocking_and_nonblocking_writes_keep_their_regions(sim) { + @case "procedural::mixed_blocking_and_nonblocking_writes_keep_their_regions"; + } + fn constant_functions_size_parameters_and_ports(sim) { @case "procedural::constant_functions_size_parameters_and_ports"; } diff --git a/crates/celox/tests/frontends/systemverilog/review_regressions.rs b/crates/celox/tests/frontends/systemverilog/review_regressions.rs index b6e5dfe0c0c..9421f957be7 100644 --- a/crates/celox/tests/frontends/systemverilog/review_regressions.rs +++ b/crates/celox/tests/frontends/systemverilog/review_regressions.rs @@ -8418,7 +8418,9 @@ fn reemits_run_time_loop_events_when_only_the_bound_changes() { #[test] fn commits_ff_output_actuals_whose_index_calls_a_function() { // `outer` writes `state[inner(k)]` from an always_ff select index; the - // write is committed with the process. + // write is committed with the process. `state` is cleared by a blocking + // assignment: a nonblocking clear would land after the call's write + // (IEEE 1800-2023 10.4) and hide it. let source = r#" module Top(input bit clk, input logic [1:0] k, output logic [3:0] st, output logic [3:0] bits); @@ -8431,7 +8433,7 @@ fn commits_ff_output_actuals_whose_index_calls_a_function() { endfunction logic [3:0] state; always_ff @(posedge clk) begin - state <= 4'd0; + state = 4'd0; bits[outer(state[inner(k)])] <= 1'b1; end assign st = state; diff --git a/crates/celox/tests/frontends/systemverilog/timing.rs b/crates/celox/tests/frontends/systemverilog/timing.rs index c328084f97b..1cb41dade0a 100644 --- a/crates/celox/tests/frontends/systemverilog/timing.rs +++ b/crates/celox/tests/frontends/systemverilog/timing.rs @@ -68,10 +68,8 @@ timed_cases! { fn run_until_drains_target_time_before_later_writes = "timing::run_until_drains_target_time_before_later_writes"; fn repeated_settles_do_not_advance_design_time = "timing::repeated_settles_do_not_advance_design_time"; fn run_to_finish_has_no_simulated_time_deadline = "timing::run_to_finish_has_no_simulated_time_deadline"; - #[ignore = "blocking stores of an edge-triggered always are committed with its nonblocking ones, not in the active region (#1470)"] fn blocking_ff_stores_are_visible_before_inactive_work = "timing::blocking_ff_stores_are_visible_before_inactive_work"; fn nonblocking_ff_stores_remain_pending_during_inactive_work = "timing::nonblocking_ff_stores_remain_pending_during_inactive_work"; - #[ignore = "blocking stores of an edge-triggered always are committed with its nonblocking ones, not in the active region (#1470)"] fn mixed_ff_stores_keep_their_active_and_nba_values = "timing::mixed_ff_stores_keep_their_active_and_nba_values"; fn printed_finish_notice_is_design_output = "timing::printed_finish_notice_is_design_output"; fn combinational_finish_ends_timed_execution = "timing::combinational_finish_ends_timed_execution"; diff --git a/crates/celox/tests/shared_jit_cache.rs b/crates/celox/tests/shared_jit_cache.rs index df1cf51d34d..04445164739 100644 --- a/crates/celox/tests/shared_jit_cache.rs +++ b/crates/celox/tests/shared_jit_cache.rs @@ -674,6 +674,34 @@ fn native_program_image_rejects_v3_before_decoding_changed_schema() { )); } +/// Version 14 added the domains that commit their blocking results with +/// their evaluation; a version 13 image lacks them and is rejected. +#[test] +fn native_program_image_rejects_v13_before_decoding_changed_schema() { + let sim = Simulator::builder(ADDER, "Top").build().unwrap(); + let mut encoded = sim + .shared_code() + .program_image() + .to_container_bytes() + .unwrap(); + let trailer_start = encoded.len() - NATIVE_IMAGE_TRAILER_SIZE; + encoded[trailer_start + NATIVE_IMAGE_VERSION_OFFSET + ..trailer_start + NATIVE_IMAGE_VERSION_OFFSET + 2] + .copy_from_slice(&13u16.to_le_bytes()); + + let Err(error) = celox::NativeProgramImage::discover_appended(&encoded) else { + panic!("a version 13 image must be rejected"); + }; + assert!( + matches!(error, NativeImageContainerError::UnsupportedVersion(13)), + "{error}" + ); + assert_eq!( + error.to_string(), + "native image container version 13 is unsupported" + ); +} + #[test] fn native_program_image_writes_an_executable_runtime_file() { let sim = Simulator::builder(ADDER, "Top").build().unwrap(); From 547ccf3e422d424a5368029d3378002af4c122da Mon Sep 17 00:00:00 2001 From: tignear Date: Sun, 18 Oct 2026 18:30:00 +0900 Subject: [PATCH 2/2] fix(sim): trigger the domains a blocking flip-flop commit gives an edge A domain that commits its blocking results before the inactive region changed event signals of other domains, directly or through combinational logic, but the new levels became the edge baseline without an edge. The reference loop now takes the levels before the commits, settles, marks the domains the committed changes trigger, and evaluates them in the same active region before resuming the inactive processes. Change-Id: Ifef70072f1fd3b703438669d1d0524d76e619a4c --- .../celox-runtime/src/simulation/process.rs | 9 ++- crates/celox-runtime/src/simulation/round.rs | 32 +++++++- .../src/sv/cases/timing.vtest | 20 +++++ .../src/simulation/runtime_core_tests.rs | 17 +++++ ..._trace_sv_active_commit_edges_default.snap | 76 +++++++++++++++++++ ...ce_sv_active_commit_edges_interpreter.snap | 76 +++++++++++++++++++ .../tests/frontends/systemverilog/timing.rs | 1 + 7 files changed, 225 insertions(+), 6 deletions(-) create mode 100644 crates/celox/src/simulation/snapshots/celox__simulation__runtime_core_tests__sv_traces__trace_sv_active_commit_edges_default.snap create mode 100644 crates/celox/src/simulation/snapshots/celox__simulation__runtime_core_tests__sv_traces__trace_sv_active_commit_edges_interpreter.snap diff --git a/crates/celox-runtime/src/simulation/process.rs b/crates/celox-runtime/src/simulation/process.rs index 8fe00cce48d..6ae53e48b4e 100644 --- a/crates/celox-runtime/src/simulation/process.rs +++ b/crates/celox-runtime/src/simulation/process.rs @@ -184,11 +184,12 @@ impl SimulationState { // before the inactive region's processes resume. if self.evaluate_before_inactive(executor, current_time, round)? { // Their blocking results are updates of the active region: - // continuous assignments follow them and the waits they wake - // run before the inactive region (IEEE 1800-2023 4.5). - executor.eval_comb()?; + // the waits they wake and the domains their edges trigger run + // before the inactive region (IEEE 1800-2023 4.5). self.observe_driven(executor.backend()); - if !self.process_state.ready.is_empty() { + if !self.process_state.ready.is_empty() + || !executor.backend().get_triggered_bits().is_empty() + { continue; } } diff --git a/crates/celox-runtime/src/simulation/round.rs b/crates/celox-runtime/src/simulation/round.rs index af1ce6c4676..ec667827171 100644 --- a/crates/celox-runtime/src/simulation/round.rs +++ b/crates/celox-runtime/src/simulation/round.rs @@ -175,7 +175,10 @@ impl SimulationState { /// Evaluate the triggered domains before an inactive region runs. Their /// nonblocking assignments stay in the working state until the NBA - /// region. Returns whether a domain committed its blocking results. + /// region. A domain that commits its blocking results does so now, in + /// the active region: combinational logic follows them and the domains + /// their edges trigger are marked. Returns whether a domain committed + /// its blocking results. pub(super) fn evaluate_before_inactive( &mut self, executor: &mut E, @@ -187,6 +190,10 @@ impl SimulationState { { let marked = executor.backend().get_triggered_bits(); executor.backend_mut().clear_triggered_bits(); + if !self.model.active_commits.is_empty() { + // The levels before any blocking result is committed. + self.event_values(executor.backend(), &mut round.before); + } let mut evaluated = BitSet::new(); let mut committed = false; let mut unsplit = Vec::new(); @@ -213,13 +220,34 @@ impl SimulationState { committed |= self.model.active_commits.contains(info.canonical_id); self.evaluate_deferred(executor, current_time, round, info)?; } + // Edges the committed blocking results give, directly or through + // combinational logic, are occurrences of this active region. + let mut occurred = Vec::new(); + if committed { + let pending = executor.backend().get_triggered_bits(); + executor.eval_comb()?; + // The settle's own trigger marks are replaced by the edges judged + // against the levels before the commits. + executor.backend_mut().clear_triggered_bits(); + self.record_transitions(executor.backend(), round); + let transitions = std::mem::take(&mut round.transitions); + round.begin_scan(self.model.domain_kinds.len()); + self.mark_occurrences(executor.backend_mut(), round, &transitions); + occurred.extend(executor.backend().get_triggered_bits().iter()); + executor.backend_mut().clear_triggered_bits(); + for id in pending.iter() { + executor.backend_mut().mark_triggered_bit(id); + } + round.transitions = transitions; + round.transitions.clear(); + } // The edges are consumed: later rounds compare against the values // they were evaluated at. self.synchronize_event_values(executor.backend()); round.begin_scan(self.model.domain_kinds.len()); round.scheduled_trigger_ids.make_empty(); round.counted_triggered.make_empty(); - for id in unsplit { + for id in unsplit.into_iter().chain(occurred) { // The edge stays approved: the new baseline no longer shows it. executor.backend_mut().mark_triggered_bit(id); round.scheduled_trigger_ids.insert(id); diff --git a/crates/celox-test-suite/src/sv/cases/timing.vtest b/crates/celox-test-suite/src/sv/cases/timing.vtest index a4a71ae644b..305f45fabc3 100644 --- a/crates/celox-test-suite/src/sv/cases/timing.vtest +++ b/crates/celox-test-suite/src/sv/cases/timing.vtest @@ -409,6 +409,26 @@ endmodule"#) (top Top) (run_until 1) (assert_eq observed 1) (assert_eq derived_seen 2) (assert_eq q 9)) +(case blocking_ff_clock_edges_trigger_their_domains_before_inactive_work + (source "blocking_clocks.sv" #" + module Top(output bit [7:0] cnt, cnt_gated, cnt_derived, seen); + bit clk, clk2, en = 1'b1, q = 1'b1; + wire gated = clk2 & en; + wire derived = ~q; + always #5 clk = ~clk; + always @(posedge clk) begin clk2 = ~clk2; q = ~q; end + always_ff @(posedge clk2) cnt <= cnt + 8'd1; + always_ff @(posedge gated) cnt_gated <= cnt_gated + 8'd1; + always_ff @(posedge derived) cnt_derived <= cnt_derived + 8'd1; + initial forever begin @(posedge clk); #0; seen = seen + 8'd1; end + endmodule"#) + (top Top) + (run_until 50) + (assert_eq seen 5) + (assert_eq cnt 3 "a blocking clock edge triggers its domain") + (assert_eq cnt_gated 3 "so does a clock computed from it") + (assert_eq cnt_derived 3 "and a falling one through an inverter")) + (case nonblocking_ff_stores_remain_pending_during_inactive_work (source "nonblocking.sv" #"module Top(output bit [7:0] q, observed, derived_seen); bit clk; wire [7:0] derived=q+1; diff --git a/crates/celox/src/simulation/runtime_core_tests.rs b/crates/celox/src/simulation/runtime_core_tests.rs index 5a49f637753..53ebd726cde 100644 --- a/crates/celox/src/simulation/runtime_core_tests.rs +++ b/crates/celox/src/simulation/runtime_core_tests.rs @@ -2316,6 +2316,23 @@ mod sv_traces { &["clk"], &["q", "observed", "derived_seen"], ), + ( + // A blocking store of a domain committed in the active region + // clocks other domains, directly and through combinational + // logic, before the inactive region. + "sv_active_commit_edges", + "module Top(input logic clk, output logic [7:0] cnt, output logic [7:0] cnt_gated, + output logic [7:0] seen); + logic clk2 = 1'b0, en = 1'b1; + wire gated = clk2 & en; + always @(posedge clk) clk2 = ~clk2; + always_ff @(posedge clk2) cnt <= cnt + 8'd1; + always_ff @(posedge gated) cnt_gated <= cnt_gated + 8'd1; + initial forever begin @(posedge clk); #0; seen = seen + 8'd1; end + endmodule", + &["clk"], + &["cnt", "cnt_gated", "seen"], + ), ( "sv_buffered_clock", "module Top(input logic clk, output logic [31:0] up, output logic [31:0] down); diff --git a/crates/celox/src/simulation/snapshots/celox__simulation__runtime_core_tests__sv_traces__trace_sv_active_commit_edges_default.snap b/crates/celox/src/simulation/snapshots/celox__simulation__runtime_core_tests__sv_traces__trace_sv_active_commit_edges_default.snap new file mode 100644 index 00000000000..175e27df84a --- /dev/null +++ b/crates/celox/src/simulation/snapshots/celox__simulation__runtime_core_tests__sv_traces__trace_sv_active_commit_edges_default.snap @@ -0,0 +1,76 @@ +--- +source: crates/celox/src/simulation/runtime_core_tests.rs +expression: "trace(Simulation::from_sv_sources(sources(), \"Top\").build().unwrap(), &ops,\nobserve)" +--- +modify [("clk", 0)] +run_until 0 + step -> Some(0): host_writes(0) process(0) comb finish_step(0) + time 0 finished false: cnt=0 cnt_gated=0 seen=0 +modify [("clk", 37)] +run_until 2 + step -> Some(0): host_writes(1) process(0) comb stage(e0@0) eval_only(e0) comb stage(e1@0) eval_only(e1) stage(e2@0) eval_only(e2) process(0) comb apply(e0) apply(e1) apply(e2) fire(e0@0) fire(e1@0) fire(e2@0) comb finish_step(0) + time 2 finished false: cnt=1 cnt_gated=1 seen=1 +modify [("clk", 74)] +run_until 4 + step -> Some(2): host_writes(1) comb finish_step(2) + time 4 finished false: cnt=1 cnt_gated=1 seen=1 +modify [("clk", 111)] +run_until 6 + step -> Some(4): host_writes(1) process(0) comb stage(e0@4) eval_only(e0) comb process(0) comb apply(e0) fire(e0@4) comb finish_step(4) + time 6 finished false: cnt=1 cnt_gated=1 seen=2 +modify [("clk", 148)] +run_until 8 + step -> Some(6): host_writes(1) comb finish_step(6) + time 8 finished false: cnt=1 cnt_gated=1 seen=2 +modify [("clk", 185)] +run_until 10 + step -> Some(8): host_writes(1) process(0) comb stage(e0@8) eval_only(e0) comb stage(e1@8) eval_only(e1) stage(e2@8) eval_only(e2) process(0) comb apply(e0) apply(e1) apply(e2) fire(e0@8) fire(e1@8) fire(e2@8) comb finish_step(8) + time 10 finished false: cnt=2 cnt_gated=2 seen=3 +modify [("clk", 222)] +run_until 12 + step -> Some(10): host_writes(1) comb finish_step(10) + time 12 finished false: cnt=2 cnt_gated=2 seen=3 +modify [("clk", 1), ("clk", 0)] +run_until 14 + step -> Some(12): host_writes(2) process(0) comb process(0) comb finish_step(12) + time 14 finished false: cnt=2 cnt_gated=2 seen=4 +schedule clk @15 = 1 +schedule clk @16 = 0 +schedule clk @17 = 1 +schedule clk @17 = 0 +schedule clk @18 = 1 +schedule clk @19 = 0 +run_until 20 + step -> Some(15): host_writes(0) process(0) comb stage(e0@15) eval_only(e0) comb process(0) comb apply(e0) fire(e0@15) comb finish_step(15) + step -> Some(16): host_writes(0) comb finish_step(16) + step -> Some(17): host_writes(0) process(0) comb stage(e0@17) eval_only(e0) comb stage(e1@17) eval_only(e1) stage(e2@17) eval_only(e2) process(0) comb apply(e0) apply(e1) apply(e2) fire(e0@17) fire(e1@17) fire(e2@17) comb finish_step(17) + step -> Some(18): host_writes(0) comb finish_step(18) + step -> Some(19): host_writes(0) comb finish_step(19) + time 20 finished false: cnt=3 cnt_gated=3 seen=6 +clock clk period 4 delay 21 +run_until 40 + step -> Some(21): host_writes(0) process(0) comb stage(e0@21) eval_only(e0) comb process(0) comb apply(e0) fire(e0@21) comb finish_step(21) + step -> Some(23): host_writes(0) comb finish_step(23) + step -> Some(25): host_writes(0) process(0) comb stage(e0@25) eval_only(e0) comb stage(e1@25) eval_only(e1) stage(e2@25) eval_only(e2) process(0) comb apply(e0) apply(e1) apply(e2) fire(e0@25) fire(e1@25) fire(e2@25) comb finish_step(25) + step -> Some(27): host_writes(0) comb finish_step(27) + step -> Some(29): host_writes(0) process(0) comb stage(e0@29) eval_only(e0) comb process(0) comb apply(e0) fire(e0@29) comb finish_step(29) + step -> Some(31): host_writes(0) comb finish_step(31) + step -> Some(33): host_writes(0) process(0) comb stage(e0@33) eval_only(e0) comb stage(e1@33) eval_only(e1) stage(e2@33) eval_only(e2) process(0) comb apply(e0) apply(e1) apply(e2) fire(e0@33) fire(e1@33) fire(e2@33) comb finish_step(33) + step -> Some(35): host_writes(0) comb finish_step(35) + step -> Some(37): host_writes(0) process(0) comb stage(e0@37) eval_only(e0) comb process(0) comb apply(e0) fire(e0@37) comb finish_step(37) + step -> Some(39): host_writes(0) comb finish_step(39) + time 40 finished false: cnt=5 cnt_gated=5 seen=11 +steps 12 + step -> Some(41): host_writes(0) process(0) comb stage(e0@41) eval_only(e0) comb stage(e1@41) eval_only(e1) stage(e2@41) eval_only(e2) process(0) comb apply(e0) apply(e1) apply(e2) fire(e0@41) fire(e1@41) fire(e2@41) comb finish_step(41) + step -> Some(43): host_writes(0) comb finish_step(43) + step -> Some(45): host_writes(0) process(0) comb stage(e0@45) eval_only(e0) comb process(0) comb apply(e0) fire(e0@45) comb finish_step(45) + step -> Some(47): host_writes(0) comb finish_step(47) + step -> Some(49): host_writes(0) process(0) comb stage(e0@49) eval_only(e0) comb stage(e1@49) eval_only(e1) stage(e2@49) eval_only(e2) process(0) comb apply(e0) apply(e1) apply(e2) fire(e0@49) fire(e1@49) fire(e2@49) comb finish_step(49) + step -> Some(51): host_writes(0) comb finish_step(51) + step -> Some(53): host_writes(0) process(0) comb stage(e0@53) eval_only(e0) comb process(0) comb apply(e0) fire(e0@53) comb finish_step(53) + step -> Some(55): host_writes(0) comb finish_step(55) + step -> Some(57): host_writes(0) process(0) comb stage(e0@57) eval_only(e0) comb stage(e1@57) eval_only(e1) stage(e2@57) eval_only(e2) process(0) comb apply(e0) apply(e1) apply(e2) fire(e0@57) fire(e1@57) fire(e2@57) comb finish_step(57) + step -> Some(59): host_writes(0) comb finish_step(59) + step -> Some(61): host_writes(0) process(0) comb stage(e0@61) eval_only(e0) comb process(0) comb apply(e0) fire(e0@61) comb finish_step(61) + step -> Some(63): host_writes(0) comb finish_step(63) + time 63 finished false: cnt=8 cnt_gated=8 seen=17 diff --git a/crates/celox/src/simulation/snapshots/celox__simulation__runtime_core_tests__sv_traces__trace_sv_active_commit_edges_interpreter.snap b/crates/celox/src/simulation/snapshots/celox__simulation__runtime_core_tests__sv_traces__trace_sv_active_commit_edges_interpreter.snap new file mode 100644 index 00000000000..ba0e908c9be --- /dev/null +++ b/crates/celox/src/simulation/snapshots/celox__simulation__runtime_core_tests__sv_traces__trace_sv_active_commit_edges_interpreter.snap @@ -0,0 +1,76 @@ +--- +source: crates/celox/src/simulation/runtime_core_tests.rs +expression: "trace(Simulation::new(Simulator::from_sv_sources(sources(),\n\"Top\").emit_triggers().build_interpreter().unwrap()), &ops, observe)" +--- +modify [("clk", 0)] +run_until 0 + step -> Some(0): host_writes(0) process(0) comb finish_step(0) + time 0 finished false: cnt=0 cnt_gated=0 seen=0 +modify [("clk", 37)] +run_until 2 + step -> Some(0): host_writes(1) process(0) comb stage(e0@0) eval_only(e0) comb stage(e1@0) eval_only(e1) stage(e2@0) eval_only(e2) process(0) comb apply(e0) apply(e1) apply(e2) fire(e0@0) fire(e1@0) fire(e2@0) comb finish_step(0) + time 2 finished false: cnt=1 cnt_gated=1 seen=1 +modify [("clk", 74)] +run_until 4 + step -> Some(2): host_writes(1) comb finish_step(2) + time 4 finished false: cnt=1 cnt_gated=1 seen=1 +modify [("clk", 111)] +run_until 6 + step -> Some(4): host_writes(1) process(0) comb stage(e0@4) eval_only(e0) comb process(0) comb apply(e0) fire(e0@4) comb finish_step(4) + time 6 finished false: cnt=1 cnt_gated=1 seen=2 +modify [("clk", 148)] +run_until 8 + step -> Some(6): host_writes(1) comb finish_step(6) + time 8 finished false: cnt=1 cnt_gated=1 seen=2 +modify [("clk", 185)] +run_until 10 + step -> Some(8): host_writes(1) process(0) comb stage(e0@8) eval_only(e0) comb stage(e1@8) eval_only(e1) stage(e2@8) eval_only(e2) process(0) comb apply(e0) apply(e1) apply(e2) fire(e0@8) fire(e1@8) fire(e2@8) comb finish_step(8) + time 10 finished false: cnt=2 cnt_gated=2 seen=3 +modify [("clk", 222)] +run_until 12 + step -> Some(10): host_writes(1) comb finish_step(10) + time 12 finished false: cnt=2 cnt_gated=2 seen=3 +modify [("clk", 1), ("clk", 0)] +run_until 14 + step -> Some(12): host_writes(2) process(0) comb process(0) comb finish_step(12) + time 14 finished false: cnt=2 cnt_gated=2 seen=4 +schedule clk @15 = 1 +schedule clk @16 = 0 +schedule clk @17 = 1 +schedule clk @17 = 0 +schedule clk @18 = 1 +schedule clk @19 = 0 +run_until 20 + step -> Some(15): host_writes(0) process(0) comb stage(e0@15) eval_only(e0) comb process(0) comb apply(e0) fire(e0@15) comb finish_step(15) + step -> Some(16): host_writes(0) comb finish_step(16) + step -> Some(17): host_writes(0) process(0) comb stage(e0@17) eval_only(e0) comb stage(e1@17) eval_only(e1) stage(e2@17) eval_only(e2) process(0) comb apply(e0) apply(e1) apply(e2) fire(e0@17) fire(e1@17) fire(e2@17) comb finish_step(17) + step -> Some(18): host_writes(0) comb finish_step(18) + step -> Some(19): host_writes(0) comb finish_step(19) + time 20 finished false: cnt=3 cnt_gated=3 seen=6 +clock clk period 4 delay 21 +run_until 40 + step -> Some(21): host_writes(0) process(0) comb stage(e0@21) eval_only(e0) comb process(0) comb apply(e0) fire(e0@21) comb finish_step(21) + step -> Some(23): host_writes(0) comb finish_step(23) + step -> Some(25): host_writes(0) process(0) comb stage(e0@25) eval_only(e0) comb stage(e1@25) eval_only(e1) stage(e2@25) eval_only(e2) process(0) comb apply(e0) apply(e1) apply(e2) fire(e0@25) fire(e1@25) fire(e2@25) comb finish_step(25) + step -> Some(27): host_writes(0) comb finish_step(27) + step -> Some(29): host_writes(0) process(0) comb stage(e0@29) eval_only(e0) comb process(0) comb apply(e0) fire(e0@29) comb finish_step(29) + step -> Some(31): host_writes(0) comb finish_step(31) + step -> Some(33): host_writes(0) process(0) comb stage(e0@33) eval_only(e0) comb stage(e1@33) eval_only(e1) stage(e2@33) eval_only(e2) process(0) comb apply(e0) apply(e1) apply(e2) fire(e0@33) fire(e1@33) fire(e2@33) comb finish_step(33) + step -> Some(35): host_writes(0) comb finish_step(35) + step -> Some(37): host_writes(0) process(0) comb stage(e0@37) eval_only(e0) comb process(0) comb apply(e0) fire(e0@37) comb finish_step(37) + step -> Some(39): host_writes(0) comb finish_step(39) + time 40 finished false: cnt=5 cnt_gated=5 seen=11 +steps 12 + step -> Some(41): host_writes(0) process(0) comb stage(e0@41) eval_only(e0) comb stage(e1@41) eval_only(e1) stage(e2@41) eval_only(e2) process(0) comb apply(e0) apply(e1) apply(e2) fire(e0@41) fire(e1@41) fire(e2@41) comb finish_step(41) + step -> Some(43): host_writes(0) comb finish_step(43) + step -> Some(45): host_writes(0) process(0) comb stage(e0@45) eval_only(e0) comb process(0) comb apply(e0) fire(e0@45) comb finish_step(45) + step -> Some(47): host_writes(0) comb finish_step(47) + step -> Some(49): host_writes(0) process(0) comb stage(e0@49) eval_only(e0) comb stage(e1@49) eval_only(e1) stage(e2@49) eval_only(e2) process(0) comb apply(e0) apply(e1) apply(e2) fire(e0@49) fire(e1@49) fire(e2@49) comb finish_step(49) + step -> Some(51): host_writes(0) comb finish_step(51) + step -> Some(53): host_writes(0) process(0) comb stage(e0@53) eval_only(e0) comb process(0) comb apply(e0) fire(e0@53) comb finish_step(53) + step -> Some(55): host_writes(0) comb finish_step(55) + step -> Some(57): host_writes(0) process(0) comb stage(e0@57) eval_only(e0) comb stage(e1@57) eval_only(e1) stage(e2@57) eval_only(e2) process(0) comb apply(e0) apply(e1) apply(e2) fire(e0@57) fire(e1@57) fire(e2@57) comb finish_step(57) + step -> Some(59): host_writes(0) comb finish_step(59) + step -> Some(61): host_writes(0) process(0) comb stage(e0@61) eval_only(e0) comb process(0) comb apply(e0) fire(e0@61) comb finish_step(61) + step -> Some(63): host_writes(0) comb finish_step(63) + time 63 finished false: cnt=8 cnt_gated=8 seen=17 diff --git a/crates/celox/tests/frontends/systemverilog/timing.rs b/crates/celox/tests/frontends/systemverilog/timing.rs index 1cb41dade0a..8832b5aca5b 100644 --- a/crates/celox/tests/frontends/systemverilog/timing.rs +++ b/crates/celox/tests/frontends/systemverilog/timing.rs @@ -69,6 +69,7 @@ timed_cases! { fn repeated_settles_do_not_advance_design_time = "timing::repeated_settles_do_not_advance_design_time"; fn run_to_finish_has_no_simulated_time_deadline = "timing::run_to_finish_has_no_simulated_time_deadline"; fn blocking_ff_stores_are_visible_before_inactive_work = "timing::blocking_ff_stores_are_visible_before_inactive_work"; + fn blocking_ff_clock_edges_trigger_their_domains_before_inactive_work = "timing::blocking_ff_clock_edges_trigger_their_domains_before_inactive_work"; fn nonblocking_ff_stores_remain_pending_during_inactive_work = "timing::nonblocking_ff_stores_remain_pending_during_inactive_work"; fn mixed_ff_stores_keep_their_active_and_nba_values = "timing::mixed_ff_stores_keep_their_active_and_nba_values"; fn printed_finish_notice_is_design_output = "timing::printed_finish_notice_is_design_output";