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
22 changes: 22 additions & 0 deletions conformance/sv-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ the initial 28 upstream checks passed. Arity and void-result rejection remain ch
Queue slices, queue operands in concatenations, element-reference persistence,
warning diagnostics, and queries on nonintegral pop results remain outside
this change's support contract.
Logical equivalence (`<->`) now passes six generated cases in both state modes.
The binary-operator case passes elaboration; the five logical-operator cases
execute simulations and pass their assertions. A full run before the container
method changes above changed only these twelve verdicts, with no passing case
regressing: 1,208 cases pass in 2state and 1,219 in 4state. Shared tests cover unknown operands and
evaluate both operands exactly once (IEEE 1800-2023 11.4.7).

Logical implication (`->`) now passes six generated cases in both state modes.
The binary-operator case passes elaboration; the five logical-operator cases
Expand All @@ -172,6 +178,22 @@ method changes above changed only these twelve verdicts, with no passing case
regressing: 1,208 cases pass in 2state and 1,219 in 4state. Shared tests also cover short-circuiting and
unknown operands (IEEE 1800-2023 11.4.7).

Integral array reductions (7.12.3) support `sum`, `product`, `and`, `or` and
`xor`, with or without empty parentheses. The five unmodified
`chapter-7/arrays/unpacked/reduction-methods` simulation cases pass the
official runner in both state modes at the pinned revision. Only those ten
reviewed expectations change from `fail` to `pass`; this is a focused run,
not a new full-corpus measurement. Shared regressions also exercise fixed
arrays, queues, integral- and string-indexed associative arrays, element-width
overflow, signed results, packed type queries and four-state propagation.
Empty reductions use the operation identity (`product`: one, `and`: all ones,
`sum` / `or` / `xor`: zero). An explicit `legacy_empty_reductions` build option
selects zero for all empty reductions. These empty-input cases are covered by
shared and simulator API regressions; the five upstream cases use nonempty
arrays and do not distinguish these modes.
`with` expressions, iterator arguments and
multidimensional unpacked receivers remain unsupported.

## Running locally

Use the locked development shell and install the pinned [`requirements.txt`](requirements.txt) in a Python environment.
Expand Down
44 changes: 22 additions & 22 deletions conformance/sv-tests/expected.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -1383,16 +1383,16 @@ chapter-7/arrays/unpacked/ordering-methods/shuffle.sv 2state fail
chapter-7/arrays/unpacked/ordering-methods/shuffle.sv 4state fail
chapter-7/arrays/unpacked/ordering-methods/sort.sv 2state fail
chapter-7/arrays/unpacked/ordering-methods/sort.sv 4state fail
chapter-7/arrays/unpacked/reduction-methods/and.sv 2state fail
chapter-7/arrays/unpacked/reduction-methods/and.sv 4state fail
chapter-7/arrays/unpacked/reduction-methods/or.sv 2state fail
chapter-7/arrays/unpacked/reduction-methods/or.sv 4state fail
chapter-7/arrays/unpacked/reduction-methods/product.sv 2state fail
chapter-7/arrays/unpacked/reduction-methods/product.sv 4state fail
chapter-7/arrays/unpacked/reduction-methods/sum.sv 2state fail
chapter-7/arrays/unpacked/reduction-methods/sum.sv 4state fail
chapter-7/arrays/unpacked/reduction-methods/xor.sv 2state fail
chapter-7/arrays/unpacked/reduction-methods/xor.sv 4state fail
chapter-7/arrays/unpacked/reduction-methods/and.sv 2state pass
chapter-7/arrays/unpacked/reduction-methods/and.sv 4state pass
chapter-7/arrays/unpacked/reduction-methods/or.sv 2state pass
chapter-7/arrays/unpacked/reduction-methods/or.sv 4state pass
chapter-7/arrays/unpacked/reduction-methods/product.sv 2state pass
chapter-7/arrays/unpacked/reduction-methods/product.sv 4state pass
chapter-7/arrays/unpacked/reduction-methods/sum.sv 2state pass
chapter-7/arrays/unpacked/reduction-methods/sum.sv 4state pass
chapter-7/arrays/unpacked/reduction-methods/xor.sv 2state pass
chapter-7/arrays/unpacked/reduction-methods/xor.sv 4state pass
chapter-7/arrays/unpacked/slice-equality.sv 2state pass
chapter-7/arrays/unpacked/slice-equality.sv 4state pass
chapter-7/arrays/unpacked/slice.sv 2state pass
Expand Down Expand Up @@ -1817,8 +1817,8 @@ generated/binary_op/11.4.6--binary_op_wild_neq.sv 2state pass
generated/binary_op/11.4.6--binary_op_wild_neq.sv 4state pass
generated/binary_op/11.4.7--binary_op_log_and.sv 2state pass
generated/binary_op/11.4.7--binary_op_log_and.sv 4state pass
generated/binary_op/11.4.7--binary_op_log_equiv.sv 2state fail
generated/binary_op/11.4.7--binary_op_log_equiv.sv 4state fail
generated/binary_op/11.4.7--binary_op_log_equiv.sv 2state pass
generated/binary_op/11.4.7--binary_op_log_equiv.sv 4state pass
generated/binary_op/11.4.7--binary_op_log_imp.sv 2state pass
generated/binary_op/11.4.7--binary_op_log_imp.sv 4state pass
generated/binary_op/11.4.7--binary_op_log_or.sv 2state pass
Expand Down Expand Up @@ -2451,14 +2451,14 @@ generated/keywords/5.6.2--keyword_xnor.sv 2state pass
generated/keywords/5.6.2--keyword_xnor.sv 4state pass
generated/keywords/5.6.2--keyword_xor.sv 2state pass
generated/keywords/5.6.2--keyword_xor.sv 4state pass
generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_0.sv 2state fail
generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_0.sv 4state fail
generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_1.sv 2state fail
generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_1.sv 4state fail
generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_2.sv 2state fail
generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_2.sv 4state fail
generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_3.sv 2state fail
generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_3.sv 4state fail
generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_0.sv 2state pass
generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_0.sv 4state pass
generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_1.sv 2state pass
generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_1.sv 4state pass
generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_2.sv 2state pass
generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_2.sv 4state pass
generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_3.sv 2state pass
generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_3.sv 4state pass
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_0.sv 2state pass
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_0.sv 4state pass
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_1.sv 2state pass
Expand Down Expand Up @@ -2647,8 +2647,8 @@ generated/sampled_functions/20.13--steady_gclk.sv 2state fail
generated/sampled_functions/20.13--steady_gclk.sv 4state fail
generated/simple_logical_operators_sim/11.4.7--simple_and_logical_operator.sv 2state pass
generated/simple_logical_operators_sim/11.4.7--simple_and_logical_operator.sv 4state pass
generated/simple_logical_operators_sim/11.4.7--simple_equiv_logical_operator.sv 2state fail
generated/simple_logical_operators_sim/11.4.7--simple_equiv_logical_operator.sv 4state fail
generated/simple_logical_operators_sim/11.4.7--simple_equiv_logical_operator.sv 2state pass
generated/simple_logical_operators_sim/11.4.7--simple_equiv_logical_operator.sv 4state pass
generated/simple_logical_operators_sim/11.4.7--simple_impl_logical_operator.sv 2state pass
generated/simple_logical_operators_sim/11.4.7--simple_impl_logical_operator.sv 4state pass
generated/simple_logical_operators_sim/11.4.7--simple_or_logical_operator.sv 2state pass
Expand Down
5 changes: 0 additions & 5 deletions crates/celox-frontend-sv/src/lowering/ff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5944,11 +5944,6 @@ impl Ff<'_, '_> {
self.urandom_state();
}
let mut kernel = ProcessKernelBuilder::new(slots);
if self.forked && self.has_deferred_assertions(body, &mut HashSet::default()) {
return Err(unsupported(
"deferred assertions in a process with fork-join",
));
}
if let Some(site) = self.deferred_flush_site(body) {
kernel.flush_deferred_at(site);
}
Expand Down
118 changes: 118 additions & 0 deletions crates/celox-frontend-sv/src/lowering/ff/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ impl Ff<'_, '_> {
string_key,
);
let code = |opcode| encode(opcode, parameter);
if op.reduction().is_some() {
return self.container_reduction(op, layout, &args[0], parameter);
}
let zero = self.constant64(0);
let (width, signed) = op.result_type(layout);
let element_result = matches!(op, Get | PopFront | PopBack);
Expand Down Expand Up @@ -298,6 +301,121 @@ impl Ff<'_, '_> {
Ok(sv::ir::Expr::Ident(name))
}

fn container_reduction(
&mut self,
op: ContainerOp,
layout: ContainerLayout,
receiver: &sv::ir::Expr,
parameter: u64,
) -> Result<sv::ir::Expr, sv::AnalyzerError> {
let width = layout.width as usize;
let four_state = !layout.two_state && self.m.four_state;
let alloc = |b: &mut SIRBuilder<Addr>| {
if four_state {
b.alloc_logic(width)
} else {
b.alloc_bit(width, layout.signed)
}
};
let code = |opcode| encode(opcode, parameter);
// Keep one immutable snapshot of the receiver throughout the traversal.
let handle = self.handle(receiver)?;
let zero = self.constant64(0);
let one = self.constant64(1);
let length = self.heap_call(code(heap::LEN), &[handle]);
let associative = matches!(layout.kind, ContainerKind::Associative { .. });
let first = if associative {
self.heap_call(code(heap::FIRST), &[handle, zero])
} else {
zero
};
let seed = alloc(&mut self.b);
let identity = match op {
ContainerOp::ReduceProduct | ContainerOp::LegacyReduceProduct => BigUint::from(1u8),
ContainerOp::ReduceAnd | ContainerOp::LegacyReduceAnd => {
(BigUint::from(1u8) << width) - BigUint::from(1u8)
}
_ => BigUint::zero(),
};
self.b
.emit(SIRInstruction::Imm(seed, SIRValue::new(identity)));
let remaining = self.b.alloc_bit(64, false);
let key = self.b.alloc_bit(64, false);
let accumulator = alloc(&mut self.b);
let header = self.b.new_block_with(vec![remaining, key, accumulator]);
let body = self.b.new_block();
let result = alloc(&mut self.b);
let exit = self.b.new_block_with(vec![result]);
self.b
.seal_block(SIRTerminator::Jump(header, vec![length, first, seed]));
self.b.switch_to_block(header);
let more = self.b.alloc_bit(1, false);
self.b
.emit(SIRInstruction::Binary(more, remaining, BinaryOp::Ne, zero));
self.b.seal_block(SIRTerminator::Branch {
cond: more,
true_block: (body, Vec::new()),
false_block: (exit, vec![accumulator]),
});
self.b.switch_to_block(body);
let raw = self.heap_call(code(heap::GET), &[handle, key, zero]);
let mask = self.heap_call(code(heap::GET_MASK), &[handle, key, zero]);
let element = self.container_join(raw, mask, width, four_state);
let combined = alloc(&mut self.b);
let binary = match op {
ContainerOp::ReduceSum => BinaryOp::Add,
ContainerOp::ReduceProduct | ContainerOp::LegacyReduceProduct => BinaryOp::Mul,
ContainerOp::ReduceAnd | ContainerOp::LegacyReduceAnd => BinaryOp::And,
ContainerOp::ReduceOr => BinaryOp::Or,
ContainerOp::ReduceXor => BinaryOp::Xor,
_ => unreachable!("reduction method"),
};
self.b.emit(SIRInstruction::Binary(
combined,
accumulator,
binary,
element,
));
let next = if associative {
self.heap_call(code(heap::NEXT), &[handle, key])
} else {
let next = self.b.alloc_bit(64, false);
self.b
.emit(SIRInstruction::Binary(next, key, BinaryOp::Add, one));
next
};
let fewer = self.b.alloc_bit(64, false);
self.b
.emit(SIRInstruction::Binary(fewer, remaining, BinaryOp::Sub, one));
self.b
.seal_block(SIRTerminator::Jump(header, vec![fewer, next, combined]));
self.b.switch_to_block(exit);
// The accumulator starts at the operation's identity. Only explicit
// legacy compatibility replaces an empty product/AND with zero.
let value = if matches!(
op,
ContainerOp::LegacyReduceProduct | ContainerOp::LegacyReduceAnd
) {
let empty = self.b.alloc_bit(1, false);
self.b
.emit(SIRInstruction::Binary(empty, length, BinaryOp::Eq, zero));
let empty_value = alloc(&mut self.b);
self.b
.emit(SIRInstruction::Imm(empty_value, SIRValue::new(0u8)));
let value = alloc(&mut self.b);
self.b
.emit(SIRInstruction::Mux(value, empty, empty_value, result));
value
} else {
result
};
let (temp, name) = self
.m
.temp("array_reduction", width, layout.signed, four_state);
self.store(temp, SIROffset::Static(0), width, value);
Ok(sv::ir::Expr::Ident(name))
}

fn container_element(
&mut self,
expr: &sv::ir::Expr,
Expand Down
12 changes: 10 additions & 2 deletions crates/celox-runtime/src/simulation/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ impl<B: SimBackend> SimulationState<B> {

/// Follow ancestry through completed parents too (IEEE 1800-2023 9.6.3).
/// Remove scheduler entries before releasing IDs for reuse.
pub(super) fn disable_children(&mut self, process: usize) {
pub(super) fn disable_children(&mut self, process: usize) -> Vec<usize> {
if self.process_state.activations.is_empty() {
return;
return Vec::new();
}
let mut cancelled = vec![false; self.process_state.activations.len()];
let mut pending = vec![process];
Expand All @@ -231,6 +231,13 @@ impl<B: SimBackend> SimulationState<B> {
}
}
}
let live_cancelled = cancelled
.iter()
.enumerate()
.filter_map(|(id, &cancelled)| {
(cancelled && self.process_state.activations[id].live).then_some(id)
})
.collect();
let state = &mut self.process_state;
for (id, activation) in state.activations.iter_mut().enumerate() {
activation.pending.retain(|&child| !cancelled[child]);
Expand All @@ -252,6 +259,7 @@ impl<B: SimBackend> SimulationState<B> {
self.retire_activation(id);
}
}
live_cancelled
}

pub(super) fn end_activation(&mut self, process: usize) {
Expand Down
15 changes: 15 additions & 0 deletions crates/celox-runtime/src/simulation/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ pub trait UnitExecutor {
Ok(self.backend_mut().run_process(index)?)
}

/// Attribute deferred assertion records to this dynamic process execution.
fn enter_deferred_assertion_process(&mut self, _process: usize) {}
/// Consume this invocation's records before another execution context runs.
fn leave_deferred_assertion_process(&mut self) {}
/// A naturally completed process retains its pending assertion reports.
fn finish_deferred_assertion_process(&mut self, _process: usize) {}
/// Disabling a live process flushes its deferred assertion reports (16.4.4).
fn cancel_deferred_assertion_process(&mut self, _process: usize) {}

/// Prepare the declaration-only state before runtime static initializers.
fn reset_declaration_startup(&mut self) -> Result<(), Halt> {
Ok(())
Expand Down Expand Up @@ -138,6 +147,12 @@ pub trait HostBoundary: UnitExecutor {
Ok(())
}

/// Active-region work has drained. Mature Observed deferred assertions
/// before entering Reactive, so a later wakeup cannot flush them (16.4.1).
fn try_observed_deferred_assertions(&mut self, _timestamp: u64) -> Result<(), Halt> {
Ok(())
}

/// Called after [`Self::try_finish_timed_step`] when the time slot
/// `timestamp` is over: no more work is due at that time. A step ends
/// before its slot does when a process waits for zero time. The
Expand Down
21 changes: 18 additions & 3 deletions crates/celox-runtime/src/simulation/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ impl<B: SimBackend> SimulationState<B> {
E: SimulationExecutor<Backend = B>,
{
{
executor.run_process(kernel)?;
executor.enter_deferred_assertion_process(process);
let result = executor.run_process(kernel);
executor.leave_deferred_assertion_process();
result?;
let status: u8 = executor
.backend()
.get_as(self.model.processes[process].status);
Expand Down Expand Up @@ -177,12 +180,19 @@ impl<B: SimBackend> SimulationState<B> {
}
Some(ProcessStatus::Done) => {
self.end_activation(process);
executor.finish_deferred_assertion_process(process);
if self.model.processes[process].program.is_some() {
self.program_kernel_ended(executor.backend())?;
}
}
Some(ProcessStatus::Exit) => {
self.exit_program(executor.backend_mut(), process)?;
let program = self.model.processes[process].program;
for (index, candidate) in self.model.processes.iter().enumerate() {
if candidate.program == program {
executor.finish_deferred_assertion_process(index);
}
}
self.program_kernel_ended(executor.backend())?;
}
Some(ProcessStatus::Finish) => return Err(Halt::Finish),
Expand All @@ -198,7 +208,9 @@ impl<B: SimBackend> SimulationState<B> {
}
Some(ProcessStatus::WaitFork) => return Ok(self.wait_for_children(process)),
Some(ProcessStatus::DisableFork) => {
self.disable_children(process);
for child in self.disable_children(process) {
executor.cancel_deferred_assertion_process(child);
}
return Ok(true);
}
Some(ProcessStatus::Local) => {
Expand All @@ -222,7 +234,10 @@ impl<B: SimBackend> SimulationState<B> {
.filter(|site| site.kind == kind)
.nth(index as usize)
.ok_or(SimulatorErrorCode::InternalError)?;
executor.host_request(request, current_time)?;
executor.enter_deferred_assertion_process(process);
let result = executor.host_request(request, current_time);
executor.leave_deferred_assertion_process();
result?;
*returns += 1;
self.charge(*returns, Some(process))?;
return Ok(true);
Expand Down
4 changes: 4 additions & 0 deletions crates/celox-runtime/src/simulation/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ impl<B: SimBackend> SimulationState<B> {
loop {
let ready = self.take_ready_processes(current_time);
if ready.is_empty() && self.process_state.ready.is_empty() {
executor.try_observed_deferred_assertions(current_time)?;
// The active region set is empty: the reactive region set
// runs, and the design activity it creates runs in the active
// region set again (IEEE 1800-2023 4.5).
Expand Down Expand Up @@ -241,6 +242,9 @@ impl<B: SimBackend> SimulationState<B> {
where
E: SimulationExecutor<Backend = B>,
{
// Compiled slots without Reactive work reach this boundary directly.
// In the ordinary loop the Observed queue is already empty here.
executor.try_observed_deferred_assertions(current_time)?;
executor.try_end_time_slot(current_time)
}

Expand Down
Loading
Loading