diff --git a/crates/celox-design/src/lib.rs b/crates/celox-design/src/lib.rs index e85b91d5cc7..56f9142a095 100644 --- a/crates/celox-design/src/lib.rs +++ b/crates/celox-design/src/lib.rs @@ -646,9 +646,9 @@ pub struct NbaSite { /// Staging object of `width` bits holding the assigned value, with the /// target's state representation. pub value: A, - /// Two-state staging object holding a bit offset added to `lsb`, for an - /// assignment whose position is computed at run time. - pub offset: Option, + /// For an assignment whose position is computed at run time, the + /// staging objects of the position. + pub position: Option>, /// One-bit flag of a site whose destination has no other writer in the /// design (no other nonblocking site, no store of any unit, not a /// top-level port) and whose update order nothing observes (no wait, @@ -672,12 +672,32 @@ impl NbaSite { lsb: self.lsb, width: self.width, value: map(self.value), - offset: self.offset.map(&mut map), + position: self.position.map(|position| position.map(&mut map)), pending: self.pending.map(&mut map), } } } +/// The run-time position of a nonblocking assignment: two-state staging +/// objects holding a bit offset added to the site's `lsb` and the number of +/// bits written there, the low bits of the value and at most the site's +/// `width`. Zero bits write nothing, as for a position outside the target +/// or one with an unknown bit (IEEE 1800-2023 7.4.6, 11.5.1). +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct NbaPosition { + pub offset: A, + pub width: A, +} + +impl NbaPosition { + pub fn map(&self, mut map: impl FnMut(A) -> B) -> NbaPosition { + NbaPosition { + offset: map(self.offset), + width: map(self.width), + } + } +} + /// Controls which combinational stores dead store elimination preserves. /// /// The policy is part of the runtime contract: host-side handles resolve diff --git a/crates/celox-frontend-core/src/process.rs b/crates/celox-frontend-core/src/process.rs index 8f8c1373831..1931a26203b 100644 --- a/crates/celox-frontend-core/src/process.rs +++ b/crates/celox-frontend-core/src/process.rs @@ -21,7 +21,7 @@ //! [`WaitSite`]: celox_design::WaitSite use celox_design::{ - HostRequestKind, NbaSite, PROCESS_DELAY_WIDTH, PROCESS_STATUS_WIDTH, ProcessSlots, + HostRequestKind, NbaPosition, NbaSite, PROCESS_DELAY_WIDTH, PROCESS_STATUS_WIDTH, ProcessSlots, ProcessStatus, RegionedVarAddrBase, STABLE_REGION, }; use celox_sir::{ @@ -50,9 +50,9 @@ pub enum ProcessKernelError { TooManySuspensions, } -/// Width of the bit offset staged by a nonblocking assignment whose position -/// is computed at run time ([`NbaSite::offset`]). -pub const NBA_OFFSET_WIDTH: usize = 64; +/// Width of the bit offset and of the bit count staged by a nonblocking +/// assignment whose position is computed at run time ([`NbaPosition`]). +pub const NBA_POSITION_WIDTH: usize = 64; /// Builder of one process kernel. pub struct ProcessKernelBuilder { @@ -259,9 +259,9 @@ impl ProcessKernelBuilder { /// process, described by `site`: schedule a value for the NBA region of /// the current time (IEEE 1800-2023 10.4.2). `lower` lowers the /// right-hand side at the open block and returns the value, a register - /// of `site.width` bits, and for a site with a run-time position the - /// bit offset, an unsigned two-state register of [`NBA_OFFSET_WIDTH`] - /// bits. + /// of `site.width` bits, and for a site with a run-time position the bit + /// offset and the number of bits written, unsigned two-state registers + /// of [`NBA_POSITION_WIDTH`] bits. /// /// A site with a `pending` flag stages the value without returning. If /// the flag is still set from an earlier execution in the same time @@ -274,7 +274,7 @@ impl ProcessKernelBuilder { site: &NbaSite, lower: impl FnOnce( &mut SIRBuilder, - ) -> Result<(RegisterId, Option), E>, + ) -> Result<(RegisterId, Option>), E>, ) -> Result<(), E> { if let Some(pending) = site.pending { let flag = self.builder.alloc_bit(1, false); @@ -298,10 +298,11 @@ impl ProcessKernelBuilder { .seal_block(SIRTerminator::Jump(stage, Vec::new())); self.builder.switch_to_block(stage); } - let (value, offset) = lower(&mut self.builder)?; + let (value, position) = lower(&mut self.builder)?; self.store(site.value, site.width, value); - if let (Some(slot), Some(offset)) = (site.offset, offset) { - self.store(slot, NBA_OFFSET_WIDTH, offset); + if let (Some(slots), Some(position)) = (site.position, position) { + self.store(slots.offset, NBA_POSITION_WIDTH, position.offset); + self.store(slots.width, NBA_POSITION_WIDTH, position.width); } if let Some(pending) = site.pending { self.store_constant(pending, 1, 1); @@ -327,7 +328,7 @@ impl ProcessKernelBuilder { switch: SourceVarId, lower: impl FnOnce( &mut SIRBuilder, - ) -> Result<(RegisterId, Option), E>, + ) -> Result<(RegisterId, Option>), E>, ) -> Result<(), E> { assert!( site.pending.is_some(), diff --git a/crates/celox-frontend-core/src/sdk.rs b/crates/celox-frontend-core/src/sdk.rs index 88633549f9f..f74172ab2a4 100644 --- a/crates/celox-frontend-core/src/sdk.rs +++ b/crates/celox-frontend-core/src/sdk.rs @@ -1425,7 +1425,7 @@ fn lower_statements( lsb: target.lsb(), width: target.width(), value: staged, - offset: None, + position: None, pending, }; kernel.nonblocking(index, &site, |builder| { diff --git a/crates/celox-frontend-core/src/symbolic/artifact.rs b/crates/celox-frontend-core/src/symbolic/artifact.rs index cf8d54a5bba..ec42afd1a4a 100644 --- a/crates/celox-frontend-core/src/symbolic/artifact.rs +++ b/crates/celox-frontend-core/src/symbolic/artifact.rs @@ -1,7 +1,7 @@ use std::{collections::BTreeSet, fmt}; use celox_design::{ - CounterSlots, ExternFunction, InitialStateValue, ModuleId, NbaSite, ProcessSlots, + CounterSlots, ExternFunction, InitialStateValue, ModuleId, NbaPosition, NbaSite, ProcessSlots, RegionedAbsoluteAddrBase, RegionedVarAddrBase, RuntimeErrorInfo, RuntimeEventSite, TriggerSet, VarAtomBase, VariableMetadata, WaitSite, }; @@ -162,7 +162,8 @@ pub struct SimModule { /// queued path leaves the value in `queued` and returns to the runtime. /// Assembly keeps one path: the staged one only if nothing else writes the /// site's target and nothing can observe when the target is updated. For the -/// queued path it makes `queued` the site's value and drops the flag. +/// queued path it makes `queued` the site's value and `queued_position` its +/// position, and drops the flag. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct NbaSwitch { /// The site's `value` object, which identifies the site. @@ -172,14 +173,20 @@ pub struct NbaSwitch { pub switch: A, /// The value object of the queued path. pub queued: A, + /// The position objects of the queued path, for a site with a run-time + /// position. + pub queued_position: Option>, } -impl NbaSwitch { +impl NbaSwitch { pub fn map(&self, mut map: impl FnMut(&A) -> B) -> NbaSwitch { NbaSwitch { value: map(&self.value), switch: map(&self.switch), queued: map(&self.queued), + queued_position: self + .queued_position + .map(|position| position.map(|var| map(&var))), } } } diff --git a/crates/celox-frontend-core/src/symbolic/assembly.rs b/crates/celox-frontend-core/src/symbolic/assembly.rs index 1fe600a2173..93bbcbc0acf 100644 --- a/crates/celox-frontend-core/src/symbolic/assembly.rs +++ b/crates/celox-frontend-core/src/symbolic/assembly.rs @@ -2090,7 +2090,14 @@ pub fn schedule_symbolic_rtl_reporting_loops( .chain( nba_sites .iter() - .flat_map(|site| [Some(site.value), site.offset, site.pending]) + .flat_map(|site| { + [ + Some(site.value), + site.position.map(|position| position.offset), + site.position.map(|position| position.width), + site.pending, + ] + }) .flatten(), ) .chain(host_request_sites.iter().flat_map(|site| site.slots())) @@ -3645,6 +3652,7 @@ fn select_nba_paths( }; if !staged.contains(&switch.switch) { site.value = switch.queued; + site.position = switch.queued_position; site.pending = None; } } diff --git a/crates/celox-frontend-sv/src/lowering/ff.rs b/crates/celox-frontend-sv/src/lowering/ff.rs index 9e44351660d..2784a824630 100644 --- a/crates/celox-frontend-sv/src/lowering/ff.rs +++ b/crates/celox-frontend-sv/src/lowering/ff.rs @@ -17,8 +17,8 @@ mod strings; use super::procedural::*; use super::*; -use celox_design::{CounterKind, NbaSite, SPARSE_WORKING_REGION, WaitSite}; -use celox_frontend_core::process::{ProcessKernelBuilder, ProcessKernelError}; +use celox_design::{CounterKind, NbaPosition, NbaSite, SPARSE_WORKING_REGION, WaitSite}; +use celox_frontend_core::process::{NBA_POSITION_WIDTH, ProcessKernelBuilder, ProcessKernelError}; use celox_sir::{RegisterId, RegisterType}; use celox_slt::SLTToSIRLowerer; use num_traits::{ToPrimitive, Zero}; @@ -4101,6 +4101,36 @@ pub(super) struct FfProcessUnits { pub staged: Vec<(SourceVarId, SourceVarId, SourceVarId)>, } +/// A part of a nonblocking assignment in a process: it takes `width` bits +/// of the right-hand side and writes them into `id` as `place` says. +struct NbaTarget { + id: SourceVarId, + width: usize, + /// For a slice of an unpacked array whose range runs against the + /// array's, the element width: the part's elements are written in + /// reverse order. + reversed: Option, + place: NbaPlace, +} + +enum NbaPlace { + /// A constant position: the part's bits from `drop` up, `width` of them, + /// are written at bit `lsb`. A position outside the target writes none. + Static { + lsb: usize, + width: usize, + drop: usize, + }, + /// A position evaluated at run time into the variables of `position`, + /// an offset from bit `lsb`. The part is shifted down first by the + /// value of the variable `drop`, the bits that fall below the target. + Dynamic { + lsb: usize, + position: NbaPosition, + drop: Option, + }, +} + /// 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. @@ -4329,8 +4359,9 @@ impl Ff<'_, '_> { } /// A nonblocking assignment in a process (IEEE 1800-2023 10.4.2): the - /// right-hand side is evaluated now, once, and each target part becomes - /// an update the runtime queues for the NBA region. + /// positions of the targets and the right-hand side are evaluated now, + /// once, and each target part becomes an update the runtime queues for + /// the NBA region. fn nonblocking( &mut self, parts: &[sv::ir::LValue], @@ -4338,61 +4369,120 @@ impl Ff<'_, '_> { ) -> Result<(), sv::AnalyzerError> { let mut targets = Vec::with_capacity(parts.len()); for part in parts { - targets.push(self.nba_target(part)?); + let part = self.propagate_lvalue(part); + let part = self.hoist_lvalue(&part)?; + targets.push(self.nba_target(&part)?); } - let total: usize = targets.iter().map(|(_, _, width)| width).sum(); - let four_state = targets.iter().any(|(id, _, _)| self.m.var(*id).is_4state); + let total: usize = targets.iter().map(|target| target.width).sum(); + let four_state = targets.iter().any(|target| self.m.var(target.id).is_4state); let (_, value_name) = self.m.temp("nba", total, false, four_state); self.assign(&sv::ir::LValue::Ident(value_name.clone()), rhs)?; // The parts, most significant first, take consecutive bits of the // value. let mut high = total; - for (id, lsb, width) in targets { - let low = high - width; + for target in targets { + let low = high - target.width; + high = low; + let id = target.id; + let select = |name: &str, msb: usize, lsb: usize| sv::ir::Expr::Select { + expr: Box::new(sv::ir::Expr::Ident(name.to_string())), + msb: sv::ir::ConstExpr::Literal(msb.to_string()), + lsb: sv::ir::ConstExpr::Literal(lsb.to_string()), + signed: false, + }; + let (source, low) = match target.reversed { + Some(element_width) => { + let (_, name) = self.m.temp("nba_order", target.width, false, four_state); + let elements = (0..target.width / element_width) + .map(|element| { + let bottom = low + element * element_width; + select(&value_name, bottom + element_width - 1, bottom) + }) + .collect(); + self.assign( + &sv::ir::LValue::Ident(name.clone()), + &sv::ir::Expr::Concat(elements), + )?; + (name, 0) + } + None => (value_name.clone(), low), + }; + let part = |msb: usize, lsb: usize| select(&source, msb, lsb); + let (lsb, width, value, position) = match target.place { + NbaPlace::Static { lsb, width, drop } => { + if width == 0 { + continue; + } + let from = low + drop; + (lsb, width, part(from + width - 1, from), None) + } + NbaPlace::Dynamic { + lsb, + position, + drop, + } => { + let value = part(low + target.width - 1, low); + let value = match drop { + Some(drop) => sv::ir::Expr::Binary { + left: Box::new(value), + op: sv::ir::BinaryOp::Shr, + right: Box::new(sv::ir::Expr::Ident(drop)), + }, + None => value, + }; + (lsb, target.width, value, Some(position)) + } + }; let (staged, staged_name) = self.m .temp("nba_part", width, false, self.m.var(id).is_4state); - self.assign( - &sv::ir::LValue::Ident(staged_name), - &sv::ir::Expr::Select { - expr: Box::new(sv::ir::Expr::Ident(value_name.clone())), - msb: sv::ir::ConstExpr::Literal((high - 1).to_string()), - lsb: sv::ir::ConstExpr::Literal(low.to_string()), - signed: false, - }, - )?; - high = low; - // The staged value has an object of its own: a value still - // staged from earlier in the time slot is queued before it is - // replaced. Assembly keeps the staged or the queued path. + self.assign(&sv::ir::LValue::Ident(staged_name), &value)?; + // The staged value and position have objects of their own: a + // value still staged from earlier in the time slot is queued + // before they are replaced. Assembly keeps the staged or the + // queued path. let staged_four_state = self.m.var(staged).is_4state; let (value, _) = self.m.temp("nba_value", width, false, staged_four_state); let (pending, _) = self.m.temp("nba_pending", 1, false, false); let (switch, _) = self.m.temp("nba_staged", 1, false, false); + let slots = position.map(|_| NbaPosition { + offset: self + .m + .temp("nba_offset", NBA_POSITION_WIDTH, false, false) + .0, + width: self.m.temp("nba_width", NBA_POSITION_WIDTH, false, false).0, + }); let site = NbaSite { process: self.process, target: id, lsb, width, value, - offset: None, + position: slots, pending: Some(pending), }; let index = self.nba_sites.len() as u32; self.with_kernel(|kernel| { kernel.nonblocking_switched(index, &site, switch, |builder| { - let value = if staged_four_state { - builder.alloc_logic(width) - } else { - builder.alloc_bit(width, false) + let load = |builder: &mut SIRBuilder<_>, var, width, four_state| { + let register = if four_state { + builder.alloc_logic(width) + } else { + builder.alloc_bit(width, false) + }; + builder.emit(SIRInstruction::Load( + register, + stable(var), + SIROffset::Static(0), + width, + )); + register }; - builder.emit(SIRInstruction::Load( - value, - stable(staged), - SIROffset::Static(0), - width, - )); - Ok::<_, ProcessKernelError>((value, None)) + let value = load(builder, staged, width, staged_four_state); + let position = position.map(|position: NbaPosition| { + position.map(|var| load(builder, var, NBA_POSITION_WIDTH, false)) + }); + Ok::<_, ProcessKernelError>((value, position)) }) }) .map_err(kernel_error)?; @@ -4400,57 +4490,268 @@ impl Ff<'_, '_> { value, switch, queued: staged, + queued_position: position, }); self.nba_sites.push(site); } Ok(()) } - /// The variable and the constant bit range a nonblocking assignment in - /// a process writes. - fn nba_target( - &self, - lvalue: &sv::ir::LValue, - ) -> Result<(SourceVarId, usize, usize), sv::AnalyzerError> { + /// The variable a part of a nonblocking assignment in a process writes + /// and where. A position is evaluated now; bits outside the target, and + /// a position with an unknown bit, write nothing (IEEE 1800-2023 7.4.6, + /// 11.5.1). + fn nba_target(&mut self, lvalue: &sv::ir::LValue) -> Result { let id = self .m .id(lvalue.name()) .ok_or_else(|| unsupported(format!("assignment target `{}`", lvalue.name())))?; let variable = self.m.var(id); - if !variable.array_dims.is_empty() { + let var_width = variable.width; + let (msb, lsb) = match lvalue { + sv::ir::LValue::Ident(_) => { + return Ok(NbaTarget { + id, + width: var_width, + reversed: None, + place: NbaPlace::Static { + lsb: 0, + width: var_width, + drop: 0, + }, + }); + } + sv::ir::LValue::Select { msb, lsb, .. } => (msb, lsb), + }; + let constants = self.m.constants; + let parameter_types = self.m.parameter_types; + let constant = + |expr| sv::typecheck::eval_const_expr_with_types(expr, constants, parameter_types); + // A slice of an unpacked array whose range runs against the array's + // takes the elements of the value in reverse order. + let reversed = match lvalue { + sv::ir::LValue::Select { + array_slice_width: Some(element_width), + array_slice_reversed: true, + .. + } => Some( + constant(element_width) + .and_then(|width| usize::try_from(width).ok()) + .filter(|width| *width != 0) + .ok_or_else(|| unsupported("assignment lvalue order"))?, + ), + _ => None, + }; + if let (Some(msb), Some(lsb)) = (constant(msb), constant(lsb)) { + let (Some(msb), Some(lsb)) = ( + packed_index_position(variable, msb), + packed_index_position(variable, lsb), + ) else { + return Err(unsupported("nonblocking assignment position")); + }; + if msb < lsb { + return Err(unsupported( + "nonblocking assignment to a reversed part select in a process", + )); + } + let width = usize::try_from(msb - lsb + 1) + .map_err(|_| unsupported("nonblocking assignment position"))?; + let top = i128::try_from(var_width).unwrap_or(i128::MAX); + let start = lsb.clamp(0, top); + let end = (msb + 1).clamp(0, top); + let (start, written) = if start < end { + (start, end - start) + } else { + (0, 0) + }; + if reversed.is_some_and(|element_width| !width.is_multiple_of(element_width)) { + return Err(unsupported("assignment lvalue order")); + } + return Ok(NbaTarget { + id, + width, + reversed, + place: NbaPlace::Static { + lsb: start as usize, + width: written as usize, + drop: if written == 0 { + 0 + } else { + (start - lsb) as usize + }, + }, + }); + } + if reversed.is_some() { return Err(unsupported( - "nonblocking assignment to an unpacked array in a process", + "nonblocking assignment to a reversed array slice at a run-time position", )); } - match lvalue { - sv::ir::LValue::Ident(_) => Ok((id, 0, variable.width)), - sv::ir::LValue::Select { msb, lsb, .. } => { - let constant = |expr| { - sv::typecheck::eval_const_expr_with_types( - expr, - self.m.constants, - self.m.parameter_types, - ) - }; - let (Some(msb), Some(lsb)) = (constant(msb), constant(lsb)) else { - return Err(unsupported( - "nonblocking assignment with a run-time position in a process", - )); - }; - let (Some(msb), Some(lsb)) = ( - packed_index_offset(variable, msb), - packed_index_offset(variable, lsb), - ) else { - return Err(unsupported("nonblocking assignment outside its target")); - }; - if msb < lsb { - return Err(unsupported( - "nonblocking assignment to a reversed part select in a process", - )); - } - Ok((id, lsb, msb - lsb + 1)) + let mut arena = SLTNodeArena::new(); + if let Some((_, element_width, offset, access)) = dynamic_array_element_lvalue( + lvalue, + self.m.variables, + self.m.name_to_id, + constants, + parameter_types, + ) { + // A run-time element: its whole selected part or nothing. + let width = access.msb - access.lsb + 1; + let offset = expr_from_const_expr(&offset) + .ok_or_else(|| unsupported("dynamic assignment index"))?; + let offset = self.propagate(&offset); + let (bit_offset, _) = lower_expr_with_context( + &offset, + self.m.variables, + self.m.name_to_id, + constants, + parameter_types, + &mut arena, + None, + None, + ) + .ok_or_else(|| unsupported("dynamic assignment index"))?; + let bit_offset = + coerce_node_width(&mut arena, bit_offset, Some(NBA_POSITION_WIDTH), false) + .map_err(slt_error)?; + let stride = slt_constant(&mut arena, BigUint::from(element_width), 64, false)?; + let index = arena + .alloc(SLTNode::Binary(bit_offset, BinaryOp::DivU, stride)) + .map_err(slt_error)?; + let (index, valid) = + dynamic_array_index_guard_slt(&mut arena, index, var_width / element_width.max(1)) + .ok_or_else(|| unsupported("dynamic assignment index"))?; + let offset = arena + .alloc(SLTNode::Binary(index, BinaryOp::Mul, stride)) + .map_err(slt_error)?; + let full = slt_constant(&mut arena, BigUint::from(width), 64, false)?; + let zero = slt_constant(&mut arena, BigUint::zero(), 64, false)?; + let written = arena + .alloc(SLTNode::Mux { + cond: valid, + then_expr: full, + else_expr: zero, + }) + .map_err(slt_error)?; + let position = NbaPosition { + offset: self.nba_position_temp("nba_at", &arena, offset)?, + width: self.nba_position_temp("nba_bits", &arena, written)?, + }; + return Ok(NbaTarget { + id, + width, + reversed: None, + place: NbaPlace::Dynamic { + lsb: access.lsb, + position, + drop: None, + }, + }); + } + let write = dynamic_packed_write( + lvalue, + self.m.variables, + self.m.name_to_id, + constants, + parameter_types, + ) + .ok_or_else(|| unsupported(format!("assignment target `{}`", lvalue.name())))?; + // A run-time part select: the bits of it inside the target, or + // inside the array element it stays within. + let shift = |expr: &sv::ir::Expr, arena: &mut SLTNodeArena| { + let (node, _) = lower_expr_with_context( + &self.propagate(expr), + self.m.variables, + self.m.name_to_id, + constants, + parameter_types, + arena, + None, + Some(false), + ) + .ok_or_else(|| unsupported("dynamic assignment position"))?; + coerce_node_width(arena, node, Some(NBA_POSITION_WIDTH), false).map_err(slt_error) + }; + let up = shift(&write.up, &mut arena)?; + let down = shift(&write.down, &mut arena)?; + let window = write + .window + .unwrap_or_else(|| BitAccess::new(0, var_width - 1)); + let binary = |arena: &mut SLTNodeArena, left, op, right| { + arena + .alloc(SLTNode::Binary(left, op, right)) + .map_err(slt_error) + }; + let mux = |arena: &mut SLTNodeArena, cond, then_expr, else_expr| { + arena + .alloc(SLTNode::Mux { + cond, + then_expr, + else_expr, + }) + .map_err(slt_error) + }; + let constant = |arena: &mut SLTNodeArena, value: usize| { + slt_constant(arena, BigUint::from(value), NBA_POSITION_WIDTH, false) + }; + // The select's bit 0 sits at `up - down`, which may be below the + // bottom of the window; the comparisons are signed. + let at = binary(&mut arena, up, BinaryOp::Sub, down)?; + let bottom = constant(&mut arena, window.lsb)?; + let top = constant(&mut arena, window.msb + 1)?; + let select_width = constant(&mut arena, write.select_width)?; + let below = binary(&mut arena, at, BinaryOp::LtS, bottom)?; + let start = mux(&mut arena, below, bottom, at)?; + let reach = binary(&mut arena, at, BinaryOp::Add, select_width)?; + let above = binary(&mut arena, reach, BinaryOp::GtS, top)?; + let end = mux(&mut arena, above, top, reach)?; + let mut valid = binary(&mut arena, start, BinaryOp::LtS, end)?; + if self.m.four_state { + for position in [up, down] { + let two_state = arena + .alloc(SLTNode::Unary(UnaryOp::ToTwoState, position)) + .map_err(slt_error)?; + let known = binary(&mut arena, position, BinaryOp::EqCase, two_state)?; + valid = slt_and(&mut arena, &mut ConstCache::default(), valid, known)?; } } + let zero = constant(&mut arena, 0)?; + let span = binary(&mut arena, end, BinaryOp::Sub, start)?; + let written = mux(&mut arena, valid, span, zero)?; + let offset = mux(&mut arena, valid, start, zero)?; + let skipped = binary(&mut arena, start, BinaryOp::Sub, at)?; + let skipped = mux(&mut arena, valid, skipped, zero)?; + let position = NbaPosition { + offset: self.nba_position_temp("nba_at", &arena, offset)?, + width: self.nba_position_temp("nba_bits", &arena, written)?, + }; + let (drop, drop_name) = self.m.temp("nba_drop", NBA_POSITION_WIDTH, false, false); + let skipped = self.lower_slt(&arena, skipped)?; + self.store(drop, SIROffset::Static(0), NBA_POSITION_WIDTH, skipped); + Ok(NbaTarget { + id, + width: write.select_width, + reversed: None, + place: NbaPlace::Dynamic { + lsb: 0, + position, + drop: Some(drop_name), + }, + }) + } + + /// A new two-state variable of [`NBA_POSITION_WIDTH`] bits holding the + /// value of `node`, evaluated now. + fn nba_position_temp( + &mut self, + purpose: &str, + arena: &SLTNodeArena, + node: NodeId, + ) -> Result { + let (temp, _) = self.m.temp(purpose, NBA_POSITION_WIDTH, false, false); + let value = self.lower_slt(arena, node)?; + self.store(temp, SIROffset::Static(0), NBA_POSITION_WIDTH, value); + Ok(temp) } /// `#amount` (IEEE 1800-2023 9.4.1). The amount is self-determined and diff --git a/crates/celox-runtime/src/schedule.rs b/crates/celox-runtime/src/schedule.rs index 4085f6d7977..e7d4af37815 100644 --- a/crates/celox-runtime/src/schedule.rs +++ b/crates/celox-runtime/src/schedule.rs @@ -188,7 +188,9 @@ impl ResolvedSchedule { lsb: site.lsb, width: site.width, value: resolve(&site.value), - offset: site.offset.as_ref().map(resolve), + position: site + .position + .map(|position| position.map(|id| resolve(&id))), pending: site.pending.as_ref().map(resolve), }) .collect(), diff --git a/crates/celox-runtime/src/simulation/nba.rs b/crates/celox-runtime/src/simulation/nba.rs index 7110263524e..f2395e208c7 100644 --- a/crates/celox-runtime/src/simulation/nba.rs +++ b/crates/celox-runtime/src/simulation/nba.rs @@ -8,7 +8,7 @@ use super::round::Round; use crate::{ SignalRef, backend::SimBackend, - timing::{Halt, Value, read}, + timing::{Halt, NbaSiteRefs, Value, read}, }; impl SimulationState { @@ -20,7 +20,7 @@ impl SimulationState { process: usize, site: usize, ) -> Result<(), Halt> { - let refs = *self.model.processes[process] + let refs = self.model.processes[process] .nba_sites .get(site) .ok_or_else(|| Self::site_error(process, site))?; @@ -29,13 +29,13 @@ impl SimulationState { // NBA region and returned before staging over the earlier value. backend.set(pending, 0u8); } - let offset = refs - .offset - .map_or(0, |offset| backend.get_as::(offset) as usize); + let Some((lsb, width)) = refs.range(backend) else { + return Ok(()); + }; self.process_state.nba_queue.push(NbaUpdate { target: refs.target, - lsb: refs.lsb + offset, - width: refs.width, + lsb, + width, value: read(backend, refs.value), }); Ok(()) @@ -76,37 +76,40 @@ impl SimulationState { self.event_values(executor.backend(), &mut round.before); round.transitions.clear(); } - for update in queued.drain(..) { + for update in &queued { let new = NbaValue::Queued(&update.value); - self.publish_update(executor.backend_mut(), &update, new); + self.publish_update(executor.backend_mut(), update, new); if several { self.record_transitions(executor.backend(), round); } } // Keep the queue's storage for the next time slot. + queued.clear(); self.process_state.nba_queue = queued; if flagged > 0 { for process in 0..self.model.processes.len() { for site in 0..self.model.processes[process].nba_sites.len() { - let site = self.model.processes[process].nba_sites[site]; let backend = executor.backend_mut(); - let Some(pending) = site.pending else { + let Some(pending) = self.model.processes[process].nba_sites[site].pending + else { continue; }; if backend.get_as::(pending) == 0 { continue; } backend.set(pending, 0u8); - let offset = site - .offset - .map_or(0, |offset| backend.get_as::(offset) as usize); + let site = &self.model.processes[process].nba_sites[site]; + let Some((lsb, width)) = site.range(backend) else { + continue; + }; + let (target, value) = (site.target, site.value); let update = NbaUpdate { - target: site.target, - lsb: site.lsb + offset, - width: site.width, + target, + lsb, + width, value: Value::default(), }; - self.publish_update(backend, &update, NbaValue::Staged(site.value)); + self.publish_update(backend, &update, NbaValue::Staged(value)); if several { self.record_transitions(executor.backend(), round); } @@ -161,6 +164,19 @@ impl SimulationState { } } +impl NbaSiteRefs { + /// The bit position and the number of bits the site writes now, or + /// `None` when it writes nothing. + fn range(&self, backend: &B) -> Option<(usize, usize)> { + let Some(position) = self.position else { + return Some((self.lsb, self.width)); + }; + let width = backend.get_as::(position.width) as usize; + let offset = backend.get_as::(position.offset) as usize; + (width != 0).then(|| (self.lsb + offset, width.min(self.width))) + } +} + /// The value of a nonblocking update: queued, or staged in a site's value /// object. enum NbaValue<'a> { diff --git a/crates/celox-runtime/src/timing.rs b/crates/celox-runtime/src/timing.rs index 7c1144c404a..113a88a9975 100644 --- a/crates/celox-runtime/src/timing.rs +++ b/crates/celox-runtime/src/timing.rs @@ -9,7 +9,7 @@ //! that writes it counts each occurrence, and a wait on it compares //! counters instead. -use celox_design::CounterKind; +use celox_design::{CounterKind, NbaPosition}; use num_bigint::BigUint; pub use crate::simulation::{Baseline, HostWatch, NbaUpdate, Waiter, Waiters}; @@ -146,7 +146,7 @@ pub struct NbaSiteRefs { pub lsb: usize, pub width: usize, pub value: SignalRef, - pub offset: Option, + pub position: Option>, pub pending: Option, } diff --git a/crates/celox-sv-analyzer/src/ast/procedural.rs b/crates/celox-sv-analyzer/src/ast/procedural.rs index f749276459d..925eb96cc2b 100644 --- a/crates/celox-sv-analyzer/src/ast/procedural.rs +++ b/crates/celox-sv-analyzer/src/ast/procedural.rs @@ -887,7 +887,23 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { StatementKind::ProceduralAssign(_) | StatementKind::ProceduralRelease(_) => { Err(unsupported("procedural continuous assignment")) } - StatementKind::Disable(_) => Err(unsupported("disable statement")), + StatementKind::Disable(tokens) => { + let disables_fork = self + .tree + .declarations() + .tokens + .get(tokens.start..tokens.end) + .into_iter() + .flatten() + .filter(|token| !token.is_trivia()) + .find(|token| token.text != "disable") + .is_some_and(|token| token.text == "fork"); + Err(unsupported(if disables_fork { + "disable fork statement" + } else { + "disable statement" + })) + } StatementKind::Parallel { .. } => Err(unsupported("fork-join block")), _ => Err(unsupported("procedural statement")), } @@ -904,9 +920,12 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { context: "an always_comb or always_ff body", }), system_functions::Body::Subroutine if self.task_timing => Ok(()), - system_functions::Body::Subroutine => { - Err(unsupported(format!("{construct} in a subroutine"))) - } + // IEEE 1800-2023 13.4: a function shall not contain a timing + // control. + system_functions::Body::Subroutine => Err(AnalyzerError::TimingControlOutsideProcess { + construct, + context: "a function", + }), } } diff --git a/crates/celox-sv-analyzer/src/ast/type_binding.rs b/crates/celox-sv-analyzer/src/ast/type_binding.rs index 192d121b65c..419dad7b2bd 100644 --- a/crates/celox-sv-analyzer/src/ast/type_binding.rs +++ b/crates/celox-sv-analyzer/src/ast/type_binding.rs @@ -87,6 +87,13 @@ pub(super) fn local_signals( ) -> Converted> { let context = PackedDimensions::new(HashMap::default(), env, aliases); let Some(base) = bind(declaration.data_type, tree, &context)? else { + // A named event (IEEE 1800-2023 6.17) is a data type of its own. + if matches!( + &tree.declarations().data_type(declaration.data_type).kind, + celox_sv_syntax::DataTypeKind::Builtin(name) if name == "event" + ) { + return Err(unsupported("named event")); + } return Err(unsupported("unsupported internal data type")); }; let mut signals = Vec::new(); diff --git a/crates/celox-sv-analyzer/src/tests.rs b/crates/celox-sv-analyzer/src/tests.rs index c08bf462526..cd2978e2577 100644 --- a/crates/celox-sv-analyzer/src/tests.rs +++ b/crates/celox-sv-analyzer/src/tests.rs @@ -3493,9 +3493,9 @@ fn rejects_unimplemented_timing_constructs() { for (body, construct) in [ ("initial begin fork #1; join end", "fork-join block"), ("initial wait fork;", "wait fork statement"), - // The `event` data type is rejected before its uses. - ("event e; initial @e;", "unsupported internal data type"), - ("event e; initial ->e;", "unsupported internal data type"), + // The `event` data type is rejected by name before its uses. + ("event e; initial @e;", "named event"), + ("event e; initial ->e;", "named event"), ( "logic clk, en; initial @(posedge clk iff en);", "iff-qualified event", @@ -3509,14 +3509,11 @@ fn rejects_unimplemented_timing_constructs() { "intra-assignment timing control", ), ("initial begin : b disable b; end", "disable statement"), + ("initial disable fork;", "disable fork statement"), ( "logic a, y; always_latch y <= a;", "nonblocking assignment inside always_latch", ), - ( - "function void t(); #1; endfunction", - "delay control in a subroutine", - ), ] { let code = format!("module Top; {body} endmodule"); let error = analyze_source(&code, Path::new("timing.sv")) @@ -6113,7 +6110,17 @@ fn functions_still_reject_direct_timing_controls() { ); let error = analyze_source(&source, Path::new("function_timing.sv")) .expect_err("functions cannot suspend"); - assert!(error.to_string().contains("in a subroutine"), "{error}"); + // IEEE 1800-2023 13.4 makes it illegal, not unimplemented. + assert!( + matches!( + error, + AnalyzerError::TimingControlOutsideProcess { + context: "a function", + .. + } + ), + "{error:?}" + ); } } diff --git a/crates/celox-test-suite/LIMITATIONS.md b/crates/celox-test-suite/LIMITATIONS.md index 62c13e0dfb4..99270bee0a2 100644 --- a/crates/celox-test-suite/LIMITATIONS.md +++ b/crates/celox-test-suite/LIMITATIONS.md @@ -394,6 +394,19 @@ fails its startup assertion in Verilator and passes in Icarus 13.0, which also passes the unchanged shared assertions. The [retained observation](verification/repros/event_list_declaration_startup_verilator.json) records both failures; `--include-ignored` retains their assertions. +Verilator 5.052 keeps only the last of the nonblocking updates that an inner +loop issues to overlapping part-selects at run-time positions when an outer loop +delays between iterations, in +`timing::process_nonblocking_assignments_at_run_time_positions`, and writes a +nonblocking update of `q[8]` of `logic [7:0] q` into bit 0, in +`timing::process_nonblocking_assignments_outside_their_target`. Each +nonblocking assignment is its own update in issue order (IEEE 1800-2023 10.4.2), +and bits outside the target are not written (11.5.1, 7.4.6). The +[adapter-free reproduction](verification/repros/process_nba_positions.sv) fails +both checks in Verilator and passes in Icarus 13.0, which also passes the +unchanged shared assertions. The [retained observation](verification/repros/process_nba_positions_verilator.json) +records both failures; `--include-ignored` retains their assertions. + Verilator 5.052 repeats activation of the self-reading latch in `latch::guarded_activation`, producing 3 where one `seed`/`en` change should produce 1. The [adapter-free reproduction](verification/repros/latch_activation.sv) diff --git a/crates/celox-test-suite/src/sv/cases/timing.vtest b/crates/celox-test-suite/src/sv/cases/timing.vtest index 1b446580399..6700235ed25 100644 --- a/crates/celox-test-suite/src/sv/cases/timing.vtest +++ b/crates/celox-test-suite/src/sv/cases/timing.vtest @@ -2159,3 +2159,184 @@ module Top(input bit clk,output bit[7:0]seen);bit q;Child c(clk,q);initial forev (assert_eq count 2) (run_until 4) (assert_eq count 3)) + +; A nonblocking assignment in a process to an element of an unpacked array +; or at a run-time position evaluates the position when it executes and +; updates those bits in the NBA region (IEEE 1800-2023 10.4.2). +(case process_nonblocking_assignments_to_array_elements + (source "process_nba_elements.sv" #" + module Top(output logic [7:0] m0, m1, m2, m3, e, d1, d2, output logic [3:0] lo, hi, + output logic [7:0] early); + logic [7:0] m [0:3]; + logic [7:0] grid [4][2]; + logic [3:0] mem [3:0]; + int i, j; + initial begin + for (i = 0; i < 4; i++) begin + m[i] = 8'd0; + mem[i] = 4'd0; + for (j = 0; j < 2; j++) grid[i][j] = 8'd0; + end + #1; + m[1] <= 8'h11; + i = 2; + m[i] <= 8'h22; + i = 3; + #0 early = m[2]; + #1; + for (i = 0; i < 4; i++) m[i] <= m[i] + 8'h40; + i = 1; + m[i][3:0] <= 4'h9; + m[i][7:4] <= 4'hc; + i = 2; + j = 1; + grid[i][j] <= 8'hab; + grid[3][0] <= 8'hcd; + mem[i] <= 4'h5; + mem[0] <= 4'h7; + #1; + i = 0; + m[i] <= 8'h01; + m[i] <= 8'h02; + {m[3], mem[i]} <= 12'hfe3; + end + assign m0 = m[0]; + assign m1 = m[1]; + assign m2 = m[2]; + assign m3 = m[3]; + assign e = grid[2][1]; + assign d1 = grid[3][0]; + assign d2 = grid[2][0]; + assign lo = mem[0]; + assign hi = mem[2]; + endmodule"#) + (top Top) + (run_until 1) + (assert_eq early 0 "the update lands after the inactive region") + (assert_eq m1 0x11) + (assert_eq m2 0x22 "the index is read when the assignment executes") + (assert_eq m3 0) + (run_until 2) + (assert_eq m0 0x40) + (assert_eq m1 0xc9 "a part of a run-time element keeps its other bits") + (assert_eq m2 0x62) + (assert_eq m3 0x40) + (assert_eq e 0xab) + (assert_eq d1 0xcd) + (assert_eq d2 0) + (assert_eq hi 5) + (assert_eq lo 7) + (run_until 3) + (assert_eq m0 0x02 "the last update of a time slot wins") + (assert_eq m3 0xfe) + (assert_eq lo 3)) + +(case process_nonblocking_assignments_at_run_time_positions + (source "process_nba_positions.sv" #" + module Top(output logic [7:0] q, a, output logic [15:0] staged, output logic [14:0] packed_bits); + logic [0:7] up; + logic [7:0] r [0:3]; + int i, n; + initial begin + q = 8'd0; + up = 8'd0; + #1; + i = 2; + q[i] <= 1'b1; + up[i] <= 1'b1; + i = 4; + q[i +: 3] <= 3'b101; + up[i -: 2] <= 2'b11; + i = 7; + end + // The only writer of `r` and `p`: their updates are staged. + logic [13:0] p = 14'd0; + int j; + initial begin + for (n = 0; n < 2; n++) begin + for (j = n; j < n + 6; j++) begin + r[j % 4] <= 8'h10 * n + j; + p[2 * j +: 3] <= j; + end + #1; + end + end + assign a = up; + assign staged = {r[3], r[0]}; + // Extended, so that `p` does not become a port. + assign packed_bits = {1'b0, p}; + endmodule"#) + (top Top) + (run_until 0) + (assert_eq staged 0x0304 "one site several times in a time slot: the last update wins") + (assert_eq packed_bits 0x14e4 "bits past the top are not written") + (run_until 1) + (assert_eq q 0x54) + (assert_eq a 0x38 "an ascending vector counts its bits from the left") + (assert_eq staged 0x1314) + (assert_eq packed_bits 0x24e4)) + +; Bits outside the target are not written: a nonblocking assignment wholly +; outside has no effect, and one partly outside writes the bits inside +; (IEEE 1800-2023 7.4.6, 11.5.1). +(case process_nonblocking_assignments_outside_their_target + (source "process_nba_outside.sv" #" + module Top(output logic [7:0] q, p, m0, m1, m2, m3); + logic [7:0] m [0:3]; + int i, k; + initial begin + q = 8'd0; + p = 8'd0; + for (i = 0; i < 4; i++) m[i] = 8'd0; + #1; + q[8] <= 1'b1; + q[9:6] <= 4'b1111; + i = 4; + m[i] <= 8'hff; + i = -1; + m[i] <= 8'hee; + k = 6; + p[k +: 4] <= 4'b0101; + k = -2; + p[k +: 4] <= 4'b1010; + end + assign m0 = m[0]; + assign m1 = m[1]; + assign m2 = m[2]; + assign m3 = m[3]; + endmodule"#) + (top Top) + (run_until 1) + (assert_eq q 0xc0) + (assert_eq p 0x42) + (assert_eq m0 0) + (assert_eq m1 0) + (assert_eq m2 0) + (assert_eq m3 0)) + +; A position with an unknown bit writes nothing (IEEE 1800-2023 7.4.6, +; 11.5.1). +(case process_nonblocking_assignments_at_unknown_positions + (source "process_nba_unknown.sv" #" + module Top(output logic [7:0] q, m0, m1); + logic [7:0] m [0:1]; + logic [2:0] i = 3'bx; + initial begin + q = 8'd0; + m[0] = 8'd0; + m[1] = 8'd0; + #1; + m[i] <= 8'hff; + q[i] <= 1'b1; + q[i +: 2] <= 2'b11; + i = 3'd1; + end + assign m0 = m[0]; + assign m1 = m[1]; + endmodule"#) + (top Top) + (four_state) + (run_until 1) + (assert_eq q 0) + (assert_eq m0 0) + (assert_eq m1 0)) diff --git a/crates/celox-test-suite/verification/repros/process_nba_positions.sv b/crates/celox-test-suite/verification/repros/process_nba_positions.sv new file mode 100644 index 00000000000..3f9ddbb8761 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/process_nba_positions.sv @@ -0,0 +1,16 @@ +module Top; + logic [7:0] q = 8'd0; + logic [13:0] p = 14'd0; + int n, j; + initial begin + for (n = 0; n < 2; n++) begin + for (j = n; j < n + 6; j++) p[2 * j +: 3] <= j; + #1 $display("p=%h", p); + end + if (p !== 14'h24e4) $fatal(1, "nonblocking updates in issue order give 24e4, not %h", p); + q[8] <= 1'b1; + #1 $display("q=%h", q); + if (q !== 8'h00) $fatal(1, "an update outside the target changed q to %h", q); + $finish; + end +endmodule diff --git a/crates/celox-test-suite/verification/repros/process_nba_positions_verilator.json b/crates/celox-test-suite/verification/repros/process_nba_positions_verilator.json new file mode 100644 index 00000000000..b71214ec7c7 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/process_nba_positions_verilator.json @@ -0,0 +1,40 @@ +{ + "schema_version": 3, + "suite_version": "0.11.0", + "tool": "verilator", + "version": "Verilator 5.052 2026-09-05 rev v5.052", + "cases": [ + { + "category": "Sequential", + "detail": "timing::process_nonblocking_assignments_at_run_time_positions at 1816:3: assert_eq packed_bits: expected 0x14e4, got 0x1400 (bits past the top are not written)", + "expectation": "Simulation", + "name": "timing::process_nonblocking_assignments_at_run_time_positions", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "timing::process_nonblocking_assignments_outside_their_target at 1854:3: assert_eq q: expected 0xc0, got 0xc1", + "expectation": "Simulation", + "name": "timing::process_nonblocking_assignments_outside_their_target", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + } + ], + "standard": "IEEE 1800-2023 10.4.2 schedules each nonblocking assignment as its own update event in the NBA region, in the order the assignments execute, so every update of a part-select at a run-time position lands. 11.5.1 and 7.4.6 make a write outside the target, wholly or in part, have no effect on the bits outside: q[8] of logic [7:0] q writes nothing.", + "adapter_free": { + "source": "verification/repros/process_nba_positions.sv", + "verilator_command": "verilator --binary --timing -Wno-fatal --top-module Top --Mdir process_nba_positions.sv", + "verilator_output": "p=1400\np=2400\n[2] %Fatal: process_nba_positions.sv:10: Assertion failed in Top: nonblocking updates in issue order give 24e4, not 2400", + "verilator_output_without_the_p_check": "p=1400\np=2400\nq=01\n[3] %Fatal: process_nba_positions.sv:13: Assertion failed in Top: an update outside the target changed q to 01", + "icarus_command": "iverilog -g2012 -s Top -o process_nba_positions.sv; vvp ", + "icarus_version": "Icarus Verilog version 13.0", + "icarus_output": "p=14e4\np=24e4\nq=00\nprocess_nba_positions.sv:14: $finish called at 3 (1s)" + } +} diff --git a/crates/celox-test-suite/verification/sv/icarus/timing.json b/crates/celox-test-suite/verification/sv/icarus/timing.json index b6998ae9588..ebe8418ed61 100644 --- a/crates/celox-test-suite/verification/sv/icarus/timing.json +++ b/crates/celox-test-suite/verification/sv/icarus/timing.json @@ -33,6 +33,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::asynchronous_reset_driven_by_a_delay_process", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -232,6 +243,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::delay_process_nonblocking_updates_reach_later_edges", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -265,6 +287,28 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::edge_waits_count_generated_clock_edges_in_any_declaration_order", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::edge_waits_on_script_inputs_next_to_a_generated_clock", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -332,6 +376,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::explicit_list_of_every_read_waits_for_a_change", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -354,6 +409,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::finish_from_a_delay_process_between_clock_edges", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -409,6 +475,28 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::four_state_nonblocking_updates_keep_unknown_bits", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::generated_clocks_with_a_common_edge_sample_each_other", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -552,6 +640,61 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::list_in_a_loop_through_always_comb_converges", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::list_missing_a_read_does_not_wake_on_it", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::list_of_every_read_with_a_nonblocking_body_runs", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::list_outside_a_loop_keeps_its_value", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::list_with_an_extra_signal_wakes_on_it", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -585,6 +728,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::narrow_nonblocking_updates_keep_the_other_bits", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -717,6 +871,50 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::process_nonblocking_assignments_at_run_time_positions", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::process_nonblocking_assignments_at_unknown_positions", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::process_nonblocking_assignments_outside_their_target", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::process_nonblocking_assignments_to_array_elements", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -816,6 +1014,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::script_writes_between_runs_reach_generated_clock_domains", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -849,6 +1058,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::staged_nonblocking_updates_keep_their_order", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -1048,6 +1268,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::variable_delay_clock_changes_its_period", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -1081,6 +1312,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::zero_delay_process_ends_a_pulse_after_its_edge_triggers", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", diff --git a/crates/celox-test-suite/verification/sv/limitations.json b/crates/celox-test-suite/verification/sv/limitations.json index 97556438bd9..70b36e60f7c 100644 --- a/crates/celox-test-suite/verification/sv/limitations.json +++ b/crates/celox-test-suite/verification/sv/limitations.json @@ -2049,5 +2049,24 @@ "timing::blocking_write_waiters_rearm_before_nonblocking_updates" ] } + }, + { + "id": "sv_verilator_process_nba_positions", + "category": "simulator_disagreement", + "phase": "execute", + "observed_version": "Verilator 5.052 2026-09-05 rev v5.052; Icarus 13.0", + "reason": "Verilator keeps only the last of the nonblocking updates that an inner loop issues to overlapping part-selects at run-time positions when an outer loop delays between iterations (p is 1400 instead of 14e4), and writes a nonblocking update of q[8] of logic [7:0] q into bit 0. IEEE 1800-2023 10.4.2 schedules every nonblocking assignment as its own update in issue order; 11.5.1 and 7.4.6 make bits outside the target unwritten. Icarus passes the unchanged shared assertions; the adapter-free source reproduces both Verilator failures.", + "upstream": [], + "evidence": [ + "verification/repros/process_nba_positions_verilator.json", + "verification/repros/process_nba_positions.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "cases": { + "verilator": [ + "timing::process_nonblocking_assignments_at_run_time_positions", + "timing::process_nonblocking_assignments_outside_their_target" + ] + } } ] diff --git a/crates/celox-test-suite/verification/sv/verilator/timing.json b/crates/celox-test-suite/verification/sv/verilator/timing.json index 7a14137d3b9..35f824e434c 100644 --- a/crates/celox-test-suite/verification/sv/verilator/timing.json +++ b/crates/celox-test-suite/verification/sv/verilator/timing.json @@ -33,6 +33,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::asynchronous_reset_driven_by_a_delay_process", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -220,6 +231,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::delay_process_nonblocking_updates_reach_later_edges", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -253,6 +275,28 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::edge_waits_count_generated_clock_edges_in_any_declaration_order", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::edge_waits_on_script_inputs_next_to_a_generated_clock", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -354,6 +398,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::finish_from_a_delay_process_between_clock_edges", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -409,6 +464,28 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "four-state expectations", + "expectation": "Simulation", + "name": "timing::four_state_nonblocking_updates_keep_unknown_bits", + "phase": "compile", + "status": "unsupported", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::generated_clocks_with_a_common_edge_sample_each_other", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -624,6 +701,50 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::list_in_a_loop_through_always_comb_converges", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::list_missing_a_read_does_not_wake_on_it", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::list_of_every_read_with_a_nonblocking_body_runs", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::list_outside_a_loop_keeps_its_value", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "Verilator executes an always procedure whose event control lists variables without edges at time zero, before any listed variable changes: y loses the value its initial procedure wrote, and a $display body prints once more. IEEE 1800-2023 6.8 initializes static declarations before initial/always processes start, and 9.4.2 makes the event control wait for a value change. Icarus passes the unchanged shared assertions; the adapter-free source reproduces the Verilator failure.", @@ -681,6 +802,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::narrow_nonblocking_updates_keep_the_other_bits", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -825,6 +957,76 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "Verilator keeps only the last of the nonblocking updates that an inner loop issues to overlapping part-selects at run-time positions when an outer loop delays between iterations (p is 1400 instead of 14e4), and writes a nonblocking update of q[8] of logic [7:0] q into bit 0. IEEE 1800-2023 10.4.2 schedules every nonblocking assignment as its own update in issue order; 11.5.1 and 7.4.6 make bits outside the target unwritten. Icarus passes the unchanged shared assertions; the adapter-free source reproduces both Verilator failures.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_disagreement", + "evidence": [ + "verification/repros/process_nba_positions_verilator.json", + "verification/repros/process_nba_positions.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_verilator_process_nba_positions", + "observed_version": "Verilator 5.052 2026-09-05 rev v5.052; Icarus 13.0", + "phase": "execute", + "reason": "Verilator keeps only the last of the nonblocking updates that an inner loop issues to overlapping part-selects at run-time positions when an outer loop delays between iterations (p is 1400 instead of 14e4), and writes a nonblocking update of q[8] of logic [7:0] q into bit 0. IEEE 1800-2023 10.4.2 schedules every nonblocking assignment as its own update in issue order; 11.5.1 and 7.4.6 make bits outside the target unwritten. Icarus passes the unchanged shared assertions; the adapter-free source reproduces both Verilator failures.", + "upstream": [] + }, + "name": "timing::process_nonblocking_assignments_at_run_time_positions", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "four-state expectations", + "expectation": "Simulation", + "name": "timing::process_nonblocking_assignments_at_unknown_positions", + "phase": "compile", + "status": "unsupported", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "Verilator keeps only the last of the nonblocking updates that an inner loop issues to overlapping part-selects at run-time positions when an outer loop delays between iterations (p is 1400 instead of 14e4), and writes a nonblocking update of q[8] of logic [7:0] q into bit 0. IEEE 1800-2023 10.4.2 schedules every nonblocking assignment as its own update in issue order; 11.5.1 and 7.4.6 make bits outside the target unwritten. Icarus passes the unchanged shared assertions; the adapter-free source reproduces both Verilator failures.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_disagreement", + "evidence": [ + "verification/repros/process_nba_positions_verilator.json", + "verification/repros/process_nba_positions.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_verilator_process_nba_positions", + "observed_version": "Verilator 5.052 2026-09-05 rev v5.052; Icarus 13.0", + "phase": "execute", + "reason": "Verilator keeps only the last of the nonblocking updates that an inner loop issues to overlapping part-selects at run-time positions when an outer loop delays between iterations (p is 1400 instead of 14e4), and writes a nonblocking update of q[8] of logic [7:0] q into bit 0. IEEE 1800-2023 10.4.2 schedules every nonblocking assignment as its own update in issue order; 11.5.1 and 7.4.6 make bits outside the target unwritten. Icarus passes the unchanged shared assertions; the adapter-free source reproduces both Verilator failures.", + "upstream": [] + }, + "name": "timing::process_nonblocking_assignments_outside_their_target", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::process_nonblocking_assignments_to_array_elements", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -924,6 +1126,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::script_writes_between_runs_reach_generated_clock_domains", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -1003,6 +1216,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::staged_nonblocking_updates_keep_their_order", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -1180,6 +1404,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::variable_delay_clock_changes_its_period", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", @@ -1213,6 +1448,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Sequential", + "detail": "", + "expectation": "Simulation", + "name": "timing::zero_delay_process_ends_a_pulse_after_its_edge_triggers", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Sequential", "detail": "", diff --git a/crates/celox/tests/frontends/systemverilog/review_regressions.rs b/crates/celox/tests/frontends/systemverilog/review_regressions.rs index 9684113cba3..286bcb3b487 100644 --- a/crates/celox/tests/frontends/systemverilog/review_regressions.rs +++ b/crates/celox/tests/frontends/systemverilog/review_regressions.rs @@ -899,26 +899,6 @@ fn applies_unsigned_coercion_to_typed_parameter_comparisons() { assert_eq!(sim.get(sim.signal("all_ones")), 1u8.into()); } -/// Nonblocking assignments in processes whose target bits are not known at -/// compile time are not lowered yet; they are rejected by name. -#[test] -fn rejects_process_nonblocking_assignments_without_a_constant_target() { - for (body, construct) in [ - ( - "logic [7:0] q; logic [2:0] i; initial #1 q[i] <= 1'b1;", - "nonblocking assignment with a run-time position in a process", - ), - ( - "logic [7:0] mem [4]; initial #1 mem[1] <= 8'd1;", - "nonblocking assignment to an unpacked array in a process", - ), - ] { - let source = format!("module Top; {body} endmodule"); - let error = cranelift_build_error(&source); - assert!(error.contains(construct), "`{body}`: {error}"); - } -} - #[test] fn compile_sv_to_sir_forwards_parameter_overrides() { let source = r#" diff --git a/crates/celox/tests/frontends/systemverilog/timing.rs b/crates/celox/tests/frontends/systemverilog/timing.rs index 95b9a964de4..b3916379346 100644 --- a/crates/celox/tests/frontends/systemverilog/timing.rs +++ b/crates/celox/tests/frontends/systemverilog/timing.rs @@ -94,6 +94,10 @@ timed_cases! { fn blocking_ff_clock_edges_trigger_their_domains_before_inactive_work = "timing::blocking_ff_clock_edges_trigger_their_domains_before_inactive_work"; fn nonblocking_assignments_in_processes_update_in_the_nba_region = "timing::nonblocking_assignments_in_processes_update_in_the_nba_region"; fn staged_nonblocking_updates_keep_their_order = "timing::staged_nonblocking_updates_keep_their_order"; + fn process_nonblocking_assignments_to_array_elements = "timing::process_nonblocking_assignments_to_array_elements"; + fn process_nonblocking_assignments_at_run_time_positions = "timing::process_nonblocking_assignments_at_run_time_positions"; + fn process_nonblocking_assignments_outside_their_target = "timing::process_nonblocking_assignments_outside_their_target"; + fn process_nonblocking_assignments_at_unknown_positions = "timing::process_nonblocking_assignments_at_unknown_positions"; fn narrow_nonblocking_updates_keep_the_other_bits = "timing::narrow_nonblocking_updates_keep_the_other_bits"; fn four_state_nonblocking_updates_keep_unknown_bits = "timing::four_state_nonblocking_updates_keep_unknown_bits"; fn nonblocking_ff_stores_remain_pending_during_inactive_work = "timing::nonblocking_ff_stores_remain_pending_during_inactive_work"; @@ -428,12 +432,7 @@ fn unimplemented_timing_features_are_rejected() { ("bit a; initial @(a iff a);", "iff-qualified event", 1444), ("initial fork #1; join", "fork-join block", 88), ("initial fork #1; join_none", "fork-join block", 88), - // #1711 names the construct. - ( - "event e; initial -> e;", - "unsupported internal data type", - 88, - ), + ("event e; initial -> e;", "named event", 88), ( "bit a, b; initial a = #1 b;", "intra-assignment timing control", @@ -450,8 +449,7 @@ fn unimplemented_timing_features_are_rejected() { 88, ), ("initial wait fork;", "wait fork statement", 88), - // #1711 names the construct. - ("initial disable fork;", "disable statement", 88), + ("initial disable fork;", "disable fork statement", 88), ( "bit a; task t(input bit x); wait (a ^ x); endtask initial t(0);", "wait condition reading a static task argument", @@ -493,22 +491,6 @@ fn unimplemented_timing_features_are_rejected() { "always_ff event control", 88, ), - // #1709 - ( - "bit [7:0] m[4]; initial #1 m[1] <= 5;", - "nonblocking assignment to an unpacked array in a process", - 88, - ), - ( - "bit [3:0] q; int i = 2; initial #1 q[i] <= 1;", - "nonblocking assignment with a run-time position in a process", - 88, - ), - ( - "bit [3:0] q; initial #1 q[5] <= 1;", - "nonblocking assignment outside its target", - 88, - ), // #1710 ( "bit q; task t(); #1 q = 1; endtask always @* t();", @@ -585,10 +567,9 @@ fn timing_controls_outside_suspendable_processes_are_rejected() { "bit clk, a, q; always_ff @(posedge clk) begin @(a); q <= a; end", "event control in an always_comb or always_ff body", ), - // #1711 reports this as illegal rather than unsupported. ( "bit a; function automatic bit f(); #1; return a; endfunction", - "delay control in a subroutine", + "delay control in a function", ), ] { let source = format!("module Top; {body} endmodule"); @@ -869,3 +850,92 @@ fn counted_wait_baselines_survive_a_state_file() { assert_eq!(counts(&mut loaded), expected, "four_state={four_state}"); } } + +/// The run-time position cases cover staged and queued sites alike. +#[test] +fn run_time_nonblocking_positions_cover_staged_and_queued_sites() { + for (case, staged, queued) in [ + ( + "timing::process_nonblocking_assignments_at_run_time_positions", + &["r", "p"][..], + &["q"][..], + ), + ( + "timing::process_nonblocking_assignments_to_array_elements", + &[][..], + &["m", "grid", "mem"][..], + ), + ] { + let design = celox_test_suite::sv::cases() + .find(|candidate| candidate.name == case) + .unwrap() + .design(); + let sources = design + .sources + .iter() + .map(|source| (source.text.as_str(), source.path.as_path())) + .collect::>(); + let simulation = celox::Simulation::from_sv_sources(sources, &design.top) + .build() + .unwrap(); + let program = simulation.program(); + let sites = |name: &str| { + let target = program.get_addr(&[], &[name]).unwrap(); + let sites = program + .runtime_schema + .nba_sites + .iter() + .filter(|site| site.target == target) + .collect::>(); + assert!( + sites.iter().any(|site| site.position.is_some()), + "{name} has a run-time position" + ); + sites + }; + for name in staged { + assert!( + sites(name).iter().all(|site| site.pending.is_some()), + "{name} stages its updates" + ); + } + for name in queued { + assert!( + sites(name).iter().all(|site| site.pending.is_none()), + "{name} queues its updates" + ); + } + } +} + +/// A nonblocking assignment to a slice of an unpacked array whose range +/// runs against the array's takes the elements in reverse order, as a +/// blocking one does (IEEE 1800-2023 7.6). Neither Icarus nor Verilator +/// compiles the slice. +#[test] +fn nonblocking_assignments_to_reversed_array_slices_reverse_the_elements() { + let source = r#" + module Top(output logic [31:0] elements); + timeunit 1ps / 1ps; + logic [7:0] m [4]; + logic [7:0] w [2]; + assign elements = {m[3], m[2], m[1], m[0]}; + initial begin + m[0] = 8'd1; m[1] = 8'd2; m[2] = 8'd3; m[3] = 8'd4; + w[0] = 8'haa; w[1] = 8'hbb; + #1; + m[1:0] <= w; + m[3:2] = w; + end + endmodule + "#; + let mut sim = celox::Simulation::from_sv_sources( + vec![(source, std::path::Path::new("reversed_slice.sv"))], + "Top", + ) + .build() + .unwrap(); + sim.run_until(2).unwrap(); + // m[1:0] <= w writes w[0] to m[1], as m[3:2] = w writes w[0] to m[3]. + assert_eq!(sim.get(sim.signal("elements")), 0xaabb_aabbu32.into()); +} diff --git a/docs/guide/systemverilog-reference.md b/docs/guide/systemverilog-reference.md index 6cf5838e16b..2722e799c75 100644 --- a/docs/guide/systemverilog-reference.md +++ b/docs/guide/systemverilog-reference.md @@ -53,7 +53,7 @@ In a timed `Simulation`, `initial` and plain `always` processes can suspend: | `#delay` | integral and real delays, `#(min:typ:max)` (the typical value) and [time literals](#time-literal-delays); an X or Z delay counts as zero | | `@(...)` | variables, `posedge` / `negedge` / `edge`, items joined by `or` or `,`, bit, part and run-time index selects, any expression including calls of pure functions, and `@*` / `@(*)`, which waits on the variables its statement reads | | `wait (condition)` | any condition; an X or Z condition counts as false | -| Assignments | blocking and nonblocking; nonblocking updates take effect in the NBA region of the time slot | +| Assignments | blocking and nonblocking, to any target a blocking assignment takes, including unpacked array elements and run-time positions; nonblocking updates take effect in the NBA region of the time slot, at the position evaluated when the assignment executes, and bits outside the target or at a position with an X or Z bit are not written | An `always` whose sensitivity list names exactly the variables its statement reads, as `@*` would (IEEE 1800-2023 9.4.2.2), simulates like `always @*` in @@ -141,10 +141,7 @@ constructs without a dedicated issue point to the frontend roadmap, [#88](https: - Timing controls in processes: `iff` qualifiers ([#1444](https://github.com/celox-sim/celox/issues/1444)), package-scoped delay values ([#1710](https://github.com/celox-sim/celox/issues/1710)), impure function calls in event expressions, and - `wait` or event expressions reading a static task argument. Nonblocking - assignments in a process cannot yet target an unpacked array element, a - run-time position or a constant position outside the target - ([#1709](https://github.com/celox-sim/celox/issues/1709)). + `wait` or event expressions reading a static task argument. - Nonblocking assignments inside `always_latch` ([#431](https://github.com/celox-sim/celox/issues/431)); use blocking assignments for the supported latch subset. - Inferred latches inside `always_comb` are rejected by default. Set `inferred_latch = "warn"` or `"allow"` in `celox.toml` under `[diagnostics]` to permit retained blocking assignments. Ordinary `always @*` and explicit `always_latch` do not require this option. - Ports and instances: non-ANSI port declarations ([#426](https://github.com/celox-sim/celox/issues/426)), `ref` ports diff --git a/docs/ja/guide/systemverilog-reference.md b/docs/ja/guide/systemverilog-reference.md index 4d357524ae6..2662f0b5f7b 100644 --- a/docs/ja/guide/systemverilog-reference.md +++ b/docs/ja/guide/systemverilog-reference.md @@ -52,7 +52,7 @@ outline: [2, 3] | `#delay` | 整数と実数の遅延、`#(min:typ:max)`(typ の値)、[時間リテラル](#time-literal-delays)。X / Z の遅延は 0 として扱う | | `@(...)` | 変数、`posedge` / `negedge` / `edge`、`or` または `,` で並べた項目、ビット選択・部分選択・実行時添字の選択、pure な関数呼び出しを含む任意の式、文が読む変数を待つ `@*` / `@(*)` | | `wait (condition)` | 任意の条件。X / Z の条件は偽として扱う | -| 代入 | ブロッキング代入とノンブロッキング代入。ノンブロッキング代入はそのタイムスロットの NBA 領域で反映 | +| 代入 | ブロッキング代入とノンブロッキング代入。代入先はブロッキング代入と同じで、unpacked 配列の要素や実行時に決まる位置も使えます。ノンブロッキング代入は代入を実行した時点で評価した位置に、そのタイムスロットの NBA 領域で反映します。代入先の範囲外のビットと、X や Z のビットを含む位置には書き込みません | 文が読む変数をちょうど並べたセンシティビティリスト(`@*` が求めるもの、IEEE 1800-2023 9.4.2.2)を持つ `always` は、`always @(a or b) y = a + b;` や `always @(b, a) y = a + b;` のように、 @@ -131,9 +131,7 @@ SystemVerilog に対しても、共有の Veryl 適合性スイートを実行 - プロセス内のタイミング制御:`iff` 修飾([#1444](https://github.com/celox-sim/celox/issues/1444))、 package スコープの遅延値 ([#1710](https://github.com/celox-sim/celox/issues/1710))、イベント式内の impure な関数呼び出し、 - static task 引数を読む `wait` 条件とイベント式。プロセス内のノンブロッキング代入は、 - unpacked 配列の要素、実行時に決まる位置、代入先の範囲外の定数位置をまだ代入先にできません - ([#1709](https://github.com/celox-sim/celox/issues/1709))。 + static task 引数を読む `wait` 条件とイベント式。 - `always_latch` 内のノンブロッキング代入([#431](https://github.com/celox-sim/celox/issues/431))。対応するラッチではブロッキング代入を使用してください。 - `always_comb` の暗黙のラッチ推論はデフォルトで拒否します。`celox.toml` の `[diagnostics]` で `inferred_latch = "warn"` または `"allow"` を指定すると許可できます。通常の `always @*` と明示的な `always_latch` にはこの設定は不要です。 - ポートとインスタンス:non-ANSI 形式のポート宣言([#426](https://github.com/celox-sim/celox/issues/426))、`ref` ポート([#427](https://github.com/celox-sim/celox/issues/427))、