Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions conformance/sv-tests/expected.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -349,30 +349,30 @@ chapter-16/16.17--expect.sv 2state fail
chapter-16/16.17--expect.sv 4state fail
chapter-16/16.2--assert-final-uvm.sv 2state fail
chapter-16/16.2--assert-final-uvm.sv 4state fail
chapter-16/16.2--assert-final.sv 2state fail
chapter-16/16.2--assert-final.sv 4state fail
chapter-16/16.2--assert-final.sv 2state pass
chapter-16/16.2--assert-final.sv 4state pass
chapter-16/16.2--assert-uvm.sv 2state fail
chapter-16/16.2--assert-uvm.sv 4state fail
chapter-16/16.2--assert.sv 2state pass
chapter-16/16.2--assert.sv 4state pass
chapter-16/16.2--assert0-uvm.sv 2state fail
chapter-16/16.2--assert0-uvm.sv 4state fail
chapter-16/16.2--assert0.sv 2state fail
chapter-16/16.2--assert0.sv 4state fail
chapter-16/16.2--assume-final.sv 2state fail
chapter-16/16.2--assume-final.sv 4state fail
chapter-16/16.2--assert0.sv 2state pass
chapter-16/16.2--assert0.sv 4state pass
chapter-16/16.2--assume-final.sv 2state pass
chapter-16/16.2--assume-final.sv 4state pass
chapter-16/16.2--assume-uvm.sv 2state fail
chapter-16/16.2--assume-uvm.sv 4state fail
chapter-16/16.2--assume.sv 2state pass
chapter-16/16.2--assume.sv 4state pass
chapter-16/16.2--assume0.sv 2state fail
chapter-16/16.2--assume0.sv 4state fail
chapter-16/16.2--cover-final.sv 2state fail
chapter-16/16.2--cover-final.sv 4state fail
chapter-16/16.2--assume0.sv 2state pass
chapter-16/16.2--assume0.sv 4state pass
chapter-16/16.2--cover-final.sv 2state pass
chapter-16/16.2--cover-final.sv 4state pass
chapter-16/16.2--cover.sv 2state pass
chapter-16/16.2--cover.sv 4state pass
chapter-16/16.2--cover0.sv 2state fail
chapter-16/16.2--cover0.sv 4state fail
chapter-16/16.2--cover0.sv 2state pass
chapter-16/16.2--cover0.sv 4state pass
chapter-16/16.7--sequence-and-range-uvm.sv 2state fail
chapter-16/16.7--sequence-and-range-uvm.sv 4state fail
chapter-16/16.7--sequence-and-uvm.sv 2state fail
Expand Down
16 changes: 8 additions & 8 deletions crates/celox-frontend-core/src/symbolic/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4393,10 +4393,10 @@ fn build_comb_observer_capture_paths(
| RuntimeEventKind::Finish
| RuntimeEventKind::Stop
);
let fatal_error_code = sites[observer.site_id as usize]
.kind
.is_fatal()
.then_some(observer.site_id as i64);
// A deferred `$fatal` ends the simulation when it matures.
let fatal_error_code = (sites[observer.site_id as usize].kind.is_fatal()
&& sites[observer.site_id as usize].deferred.is_none())
.then_some(observer.site_id as i64);
let pre_lower_nodes = observer_pre_lower_nodes(observer, arena);
for idx in &order_after {
comb_blocks[idx.0]
Expand Down Expand Up @@ -4449,10 +4449,10 @@ fn build_comb_observer_capture_paths(
| RuntimeEventKind::Finish
| RuntimeEventKind::Stop
);
let member_fatal_error_code = sites[member.site_id as usize]
.kind
.is_fatal()
.then_some(member.site_id as i64);
// A deferred `$fatal` ends the simulation when it matures.
let member_fatal_error_code = (sites[member.site_id as usize].kind.is_fatal()
&& sites[member.site_id as usize].deferred.is_none())
.then_some(member.site_id as i64);
let member_expr = match member
.loop_runner
.or(member.guard)
Expand Down
15 changes: 14 additions & 1 deletion crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4561,7 +4561,14 @@ pub(crate) fn attach_instance_glue(
observer.activation_group += site_base;
module.comb_observers.push(observer);
}
module.runtime_event_sites.extend(comb_sites);
module
.runtime_event_sites
.extend(comb_sites.into_iter().map(|mut site| {
if let Some(celox_design::DeferredSite::Action { queue, .. }) = &mut site.deferred {
*queue += site_base;
}
site
}));
for id in created {
module
.variables
Expand Down Expand Up @@ -5276,6 +5283,12 @@ fn lower_comb_processes(
.expect("a counter for every sensitivity atom")
})
.collect();
// A deferred action waits in the queue of its process.
if let Some(celox_design::DeferredSite::Action { queue, .. }) =
&mut comb.sites[(observer.site_id - base) as usize].deferred
{
*queue = base;
}
observers.push(observer);
}
sites.append(&mut comb.sites);
Expand Down
13 changes: 11 additions & 2 deletions crates/celox-frontend-sv/src/lowering/comb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3581,6 +3581,15 @@ impl<'p, 'a> Comb<'p, 'a> {
}
self.effect_sensitivity.extend(observed.iter().copied());
let site_id = self.site_base + self.sites.len() as u32;
// The action of a deferred assertion waits in the queue of its
// process, which lowering names by the process's activation group
// (IEEE 1800-2023 16.4). A deferred `$fatal` ends the simulation
// when it matures, not while combinational logic settles.
let deferred = assertion_site
.map(|assertion| assertion.deferral)
.filter(|&region| region != celox_design::AssertionDeferral::None)
.map(|region| celox_design::DeferredSite::Action { queue: 0, region });
let fatal = kind.is_fatal() && deferred.is_none();
// Inside a run-time loop the event is emitted once per iteration by
// the loop's runner (see `fold_loop`).
let captured_in_loop = if let Some(effects) = &mut self.loop_effects {
Expand All @@ -3592,7 +3601,7 @@ impl<'p, 'a> Comb<'p, 'a> {
SystemTaskKind::Print(..) | SystemTaskKind::Control(_)
),
args: captured.clone(),
fatal_error_code: kind.is_fatal().then_some(i64::from(site_id)),
fatal_error_code: fatal.then_some(i64::from(site_id)),
});
true
} else {
Expand All @@ -3605,7 +3614,7 @@ impl<'p, 'a> Comb<'p, 'a> {
scope: None,
location: report_location(site),
assertion: assertion_site.cloned(),
deferred: None,
deferred,
arg_widths,
arg_signed,
arg_is_string,
Expand Down
44 changes: 29 additions & 15 deletions crates/celox-frontend-sv/src/lowering/ff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,27 @@ impl<'p, 'a> Ff<'p, 'a> {
let Some(id) = self.m.id(lvalue.name()) else {
return;
};
let variable = self.m.var(id);
let constant = match lvalue {
sv::ir::LValue::Ident(_) => None,
sv::ir::LValue::Select { msb, lsb, .. } => sv::typecheck::eval_const_expr_with_types(
msb,
self.m.constants,
self.m.parameter_types,
)
.zip(sv::typecheck::eval_const_expr_with_types(
lsb,
self.m.constants,
self.m.parameter_types,
))
.and_then(|(msb, lsb)| constant_select_write(variable, msb, lsb)),
};
// An empty constant write is not a dynamic write of the whole
// variable. Keep it out of publication and latch-coverage targets.
if matches!(constant, Some((None, _))) {
return;
}
let constant = constant.and_then(|(access, _)| access);
if blocking {
self.working.insert(id);
} else {
Expand All @@ -305,7 +326,6 @@ impl<'p, 'a> Ff<'p, 'a> {
if self.m.is_hidden(id) {
return;
}
let variable = self.m.var(id);
// A run-time bit select within one array element writes only that
// element (see `write`); a run-time element may be any of them.
let element_write = dynamic_array_element_lvalue(
Expand All @@ -329,20 +349,6 @@ impl<'p, 'a> Ff<'p, 'a> {
.flatten()
.and_then(|write| write.window)
.unwrap_or(BitAccess::new(0, variable.width - 1));
let constant = match lvalue {
sv::ir::LValue::Ident(_) => None,
sv::ir::LValue::Select { msb, lsb, .. } => sv::typecheck::eval_const_expr_with_types(
msb,
self.m.constants,
self.m.parameter_types,
)
.zip(sv::typecheck::eval_const_expr_with_types(
lsb,
self.m.constants,
self.m.parameter_types,
))
.and_then(|(msb, lsb)| constant_select_write(variable, msb, lsb)?.0),
};
if constant.is_none() {
// `write` takes the same order: a constant range, then one
// run-time element, then a read-modify-write of the variable.
Expand Down Expand Up @@ -3970,6 +3976,7 @@ impl<'p, 'a> Ff<'p, 'a> {
let width = self.m.var(id).width;
self.targets.push((id, BitAccess::new(0, width - 1)));
}
let flush_site = self.deferred_flush_site(body);
if self.exec_block(body)? {
self.b.seal_block(SIRTerminator::Return);
}
Expand Down Expand Up @@ -4131,6 +4138,13 @@ impl<'p, 'a> Ff<'p, 'a> {
false_block: (done, vec![]),
});
self.b.switch_to_block(execute);
// Each run is a resume of the process (IEEE 1800-2023 16.4.2).
if let Some(site_id) = flush_site {
self.b.emit(SIRInstruction::RuntimeEvent {
site_id,
args: Vec::new(),
});
}
self.b.inline_execution_unit(&body_unit);
if !always_comb {
// @* is not waiting during its body. Its own writes cannot wake
Expand Down
6 changes: 6 additions & 0 deletions crates/celox-runtime/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ pub trait SimBackend {
None
}
fn set_comb_capture_event_enabled(&mut self, _active_sites: &[bool]) {}
/// Which runtime event sites are enabled for combinational capture, by
/// the host before an evaluation or by the evaluation for observers
/// whose inputs it changed. Empty for a backend without capture.
fn comb_capture_event_enabled(&self) -> Vec<bool> {
Vec::new()
}
fn stable_region_size(&self) -> usize;
fn layout(&self) -> &MemoryLayout;
/// The heap that handle slots in this backend's state refer to.
Expand Down
10 changes: 1 addition & 9 deletions crates/celox-sv-analyzer/src/ast/procedural/assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ impl BodyBuilder<'_, '_, '_> {
keyword: &str,
header: &AssertionHeader,
) -> Result<Expr, AnalyzerError> {
let AssertionHeader::Immediate {
condition,
deferred,
..
} = header
else {
let AssertionHeader::Immediate { condition, .. } = header else {
return Err(unsupported("concurrent assertion"));
};
if keyword == "cover" && deferred.is_some() {
return Err(unsupported("deferred immediate cover"));
}
if !matches!(keyword, "assert" | "assume" | "cover") {
return Err(unsupported("immediate assertion keyword"));
}
Expand Down
60 changes: 44 additions & 16 deletions crates/celox-sv-analyzer/src/ast/selects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub(super) fn lvalue_from_indices(
packed_dimensions: &PackedDimensions,
) -> Converted<LValue> {
if let Some((array_offset, packed_indices)) =
flatten_variable_select(state, &name, &indices, packed_dimensions)
flatten_variable_select(&name, &indices, packed_dimensions)
{
if !packed_indices.is_empty() {
if let Some((msb, lsb)) =
Expand Down Expand Up @@ -186,6 +186,43 @@ pub(super) fn lvalue_from_indices(
Ok(LValue::Ident(name))
}

/// Fold the invalid-element sentinel emitted by `flatten_variable_select`.
/// Keep the selected integral type even in an unselected conditional arm:
/// both operands determine the conditional width and signedness (11.4.11).
pub(super) fn invalid_unpacked_read(
state: &AnalysisState,
lhs: &LValue,
dimensions: &PackedDimensions,
) -> Option<Expr> {
let LValue::Select {
name,
msb,
lsb,
signed,
..
} = lhs
else {
return None;
};
let variable = dimensions.get(name)?;
if variable.unpacked.is_empty() || variable.real || variable.string || variable.class.is_some()
{
return None;
}
let full_width = lvalue_expr_type(state, &LValue::Ident(name.clone()), dimensions)?.width;
let msb = eval_ast_const_expr(state, msb, &dimensions.const_env)?;
let lsb = eval_ast_const_expr(state, lsb, &dimensions.const_env)?;
if msb < lsb || lsb < i128::try_from(full_width).ok()? {
return None;
}
let width = usize::try_from(msb.checked_sub(lsb)?)
.ok()?
.checked_add(1)?;
let signing = if *signed { "s" } else { "" };
let digit = if variable.is_2state { "0" } else { "x" };
Some(Expr::Literal(format!("{width}'{signing}b{digit}")))
}

/// Shared syntax-independent assignment range flattening and array metadata.
pub(super) fn lvalue_from_range(
state: &AnalysisState,
Expand Down Expand Up @@ -348,7 +385,6 @@ pub(super) fn indexed_range_values(
}

fn flatten_variable_select(
state: &AnalysisState,
name: &str,
indices: &[ConstExpr],
packed_dimensions: &PackedDimensions,
Expand All @@ -360,15 +396,9 @@ fn flatten_variable_select(
let mut offset = ConstExpr::Literal("0".to_string());
let mut valid = None;
for (index, value) in indices[..selected_unpacked_count].iter().enumerate() {
if const_expr_is_out_of_range(
state,
value,
&dimensions.unpacked[index].left,
&dimensions.unpacked[index].right,
&packed_dimensions.const_env,
) {
return None;
}
// Constant and runtime invalid indices have the same semantics:
// read the element type's default value and ignore writes (7.4.5).
// Route both through the guard below instead of rejecting constants.
let dimension = &dimensions.unpacked[index];
let descending = ConstExpr::Binary {
left: Box::new(dimension.left.clone()),
Expand Down Expand Up @@ -483,7 +513,7 @@ fn unpacked_select_range_metadata(
) {
return None;
}
let (_, packed_indices) = flatten_variable_select(state, name, indices, packed_dimensions)?;
let (_, packed_indices) = flatten_variable_select(name, indices, packed_dimensions)?;
if !packed_indices.is_empty() {
return None;
}
Expand Down Expand Up @@ -554,8 +584,7 @@ fn flatten_unpacked_select_range(
) {
return None;
}
let (array_offset, packed_indices) =
flatten_variable_select(state, name, indices, packed_dimensions)?;
let (array_offset, packed_indices) = flatten_variable_select(name, indices, packed_dimensions)?;
if !packed_indices.is_empty() {
return None;
}
Expand Down Expand Up @@ -642,8 +671,7 @@ fn flatten_select_range(
packed_dimensions,
);
}
let (array_offset, packed_indices) =
flatten_variable_select(state, name, indices, packed_dimensions)?;
let (array_offset, packed_indices) = flatten_variable_select(name, indices, packed_dimensions)?;
let dimension = dimensions.packed.get(packed_indices.len())?;
if const_expr_is_out_of_range(
state,
Expand Down
3 changes: 3 additions & 0 deletions crates/celox-sv-analyzer/src/ast/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ pub(super) fn expr_from_lvalue(
lhs: &LValue,
packed_dimensions: &PackedDimensions,
) -> Expr {
if let Some(value) = selects::invalid_unpacked_read(state, lhs, packed_dimensions) {
return value;
}
let (base, array_slice_width, array_slice_reversed, signed) = match lhs {
LValue::Ident(name) => return Expr::Ident(name.clone()),
LValue::Select {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn native_assertion_action_scopes_and_unsupported_classes_keep_existing_behavior
};
assert_ne!(pass, fail);
for (statement, diagnostic) in [
("cover #0(a);", "deferred immediate cover"),
("cover #0(a) y=1;", "deferred assertion action"),
("assert property(a);", "concurrent assertion"),
] {
let tree = parsed(statement);
Expand Down
Loading
Loading