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
9 changes: 8 additions & 1 deletion .github/RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# Release policy

Celox is released as one lockstep distribution. `VERSION`,
`.release-please-manifest.json`, the npm packages, and all Rust workspace crates
`.release-please-manifest.json`, the npm packages, and all Celox Rust workspace crates
must always carry the same version. The public Rust entry points are `celox`,
`celox-frontend-sdk`, `celox-test-suite`, and the Rust adapter API in `celox-napi`; the remaining
published `celox-*` crates satisfy their Cargo dependency graph and remain
implementation details.

Aplite has its own version and release train (`release-aplite.yml` and
`publish-aplite.yml`). Publish the Aplite version required by the workspace
before releasing Celox: `celox-heap` depends on it, and Cargo resolves the
published Aplite crate when packaging Celox crates. A bootstrap `0.0.0` release
does not satisfy this dependency. Aplite is deliberately absent from Celox's
lockstep publication list.

## Versioning before 1.0

Pull request titles are the input to release automation after GitHub copies the
Expand Down
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ description = "Celox HDL Simulator"
rust-version = "1.99.1"

[workspace.dependencies]
# Aplite has its own release version; these consumers are unpublished.
aplite = { path = "crates/aplite" }
# Aplite has an independent release version.
aplite = { version = "0.1.0", path = "crates/aplite" }
celox = { version = "=0.11.0", path = "crates/celox", default-features = false } # x-release-please-version
celox-analysis = { version = "=0.11.0", path = "crates/celox-analysis" } # x-release-please-version
celox-backend-arm64 = { version = "=0.11.0", path = "crates/celox-backend-arm64" } # x-release-please-version
Expand Down
7 changes: 7 additions & 0 deletions conformance/sv-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ 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 implication (`->`) 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 also cover short-circuiting and
unknown operands (IEEE 1800-2023 11.4.7).

## Running locally

Use the locked development shell and install the pinned [`requirements.txt`](requirements.txt) in a Python environment.
Expand Down
24 changes: 12 additions & 12 deletions conformance/sv-tests/expected.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -1819,8 +1819,8 @@ 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_imp.sv 2state fail
generated/binary_op/11.4.7--binary_op_log_imp.sv 4state fail
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
generated/binary_op/11.4.7--binary_op_log_or.sv 4state pass
generated/binary_op/11.4.8--binary_op_bit_and.sv 2state pass
Expand Down Expand Up @@ -2459,14 +2459,14 @@ generated/logical_equivalence_operator_sim/11.4.7--logical_equiv_operator_2.sv 2
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_implication_operator_sim/11.4.7--logical_impl_operator_0.sv 2state fail
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_0.sv 4state fail
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_1.sv 2state fail
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_1.sv 4state fail
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_2.sv 2state fail
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_2.sv 4state fail
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_3.sv 2state fail
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_3.sv 4state fail
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
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_1.sv 4state pass
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_2.sv 2state pass
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_2.sv 4state pass
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_3.sv 2state pass
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_3.sv 4state pass
generated/logical_operators_sim/11.4.7--logical_operator_0.sv 2state pass
generated/logical_operators_sim/11.4.7--logical_operator_0.sv 4state pass
generated/logical_operators_sim/11.4.7--logical_operator_1.sv 2state pass
Expand Down Expand Up @@ -2649,8 +2649,8 @@ generated/simple_logical_operators_sim/11.4.7--simple_and_logical_operator.sv 2s
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_impl_logical_operator.sv 2state fail
generated/simple_logical_operators_sim/11.4.7--simple_impl_logical_operator.sv 4state fail
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
generated/simple_logical_operators_sim/11.4.7--simple_or_logical_operator.sv 4state pass
generated/trig_functions/20.8--acos.sv 2state pass
Expand Down
64 changes: 40 additions & 24 deletions crates/celox-backend-x86/src/backend/native/isel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1480,10 +1480,6 @@ pub fn lower_execution_unit_with_diagnostics(
sparse_write_states.metadata_action(sir_block_id, inst_idx),
);
}
if cfg!(debug_assertions) {
ctx.verify_wide_values();
}

// Track known bit width for redundant mask elimination.
let dst_reg = inst.defined_register();
if let Some(dr) = dst_reg {
Expand Down Expand Up @@ -1563,6 +1559,12 @@ pub fn lower_execution_unit_with_diagnostics(

// Extract mask_map for phi node construction (ctx borrows func fields)
let saved_mask_map = std::mem::replace(&mut ctx.mask_map, RegMap::new(0));
// Each mutation validates its own entry. Scan the whole map once at
// the boundary rather than once per instruction, which is quadratic in
// large functions with many wide values.
if cfg!(debug_assertions) {
ctx.verify_wide_values();
}
let saved_wide_regs = std::mem::take(&mut ctx.wide_regs);
let saved_wide_masks = std::mem::take(&mut ctx.wide_masks);
drop(ctx); // Release borrows on func
Expand Down Expand Up @@ -1758,6 +1760,11 @@ type WideMaskMap = crate::HashMap<RegisterId, Vec<(VReg, usize)>>;
/// Tracks known constant values for SIR registers (for constant folding in ISel).
type ConstMap = crate::HashMap<RegisterId, u64>;

#[cfg(test)]
thread_local! {
static WIDE_VALUE_VERIFICATIONS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
}

struct ISelContext<'a> {
vregs: &'a mut VRegAllocator,
spill_descs: &'a mut Vec<SpillDesc>,
Expand Down Expand Up @@ -2193,6 +2200,9 @@ impl<'a> ISelContext<'a> {
if width <= 64 {
self.wide_regs.remove(&reg);
} else {
if cfg!(debug_assertions) {
self.verify_wide_value(&reg, &chunks);
}
self.wide_regs.replace(reg, chunks);
}
}
Expand Down Expand Up @@ -2244,28 +2254,34 @@ impl<'a> ISelContext<'a> {
/// this map through a direct insertion.
fn verify_wide_values(&self) {
for (reg, chunks) in self.wide_regs.iter() {
let width = self.sir_width(reg);
assert!(
width > 64,
"narrow SIR register r{} has a wide native representation (width={width})",
reg.0
);
let expected_chunks = Self::num_chunks(width);
self.verify_wide_value(reg, chunks);
}
}

fn verify_wide_value(&self, reg: &RegisterId, chunks: &[(VReg, usize)]) {
#[cfg(test)]
WIDE_VALUE_VERIFICATIONS.with(|count| count.set(count.get() + 1));
let width = self.sir_width(reg);
assert!(
width > 64,
"narrow SIR register r{} has a wide native representation (width={width})",
reg.0
);
let expected_chunks = Self::num_chunks(width);
assert_eq!(
chunks.len(),
expected_chunks,
"wide SIR register r{} has {} chunks, expected {expected_chunks}",
reg.0,
chunks.len()
);
for (index, (_, chunk_width)) in chunks.iter().enumerate() {
let expected_width = width.saturating_sub(index * 64).min(64);
assert_eq!(
chunks.len(),
expected_chunks,
"wide SIR register r{} has {} chunks, expected {expected_chunks}",
reg.0,
chunks.len()
*chunk_width, expected_width,
"wide SIR register r{} chunk {index} has width {chunk_width}, expected {expected_width}",
reg.0
);
for (index, (_, chunk_width)) in chunks.iter().enumerate() {
let expected_width = width.saturating_sub(index * 64).min(64);
assert_eq!(
*chunk_width, expected_width,
"wide SIR register r{} chunk {index} has width {chunk_width}, expected {expected_width}",
reg.0
);
}
}
}

Expand Down
41 changes: 41 additions & 0 deletions crates/celox-backend-x86/src/backend/native/isel/tests/wide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,3 +1463,44 @@ fn widened_zero_compares_equal_to_a_zero_wide_load() {
assert_eq!(state[output_offset] & 1, 1, "four_state={four_state}");
}
}

#[cfg(debug_assertions)]
#[test]
fn wide_value_invariant_validation_scales_with_values() {
const COUNT: usize = 128;
let unit = ExecutionUnit {
entry_block_id: SirBlockId(0),
blocks: [(
SirBlockId(0),
BasicBlock {
id: SirBlockId(0),
params: vec![],
instructions: (0..COUNT)
.map(|i| {
SIRInstruction::Imm(
RegisterId(i),
SIRValue::new_four_state(BigUint::from(i), BigUint::default()),
)
})
.collect(),
terminator: SIRTerminator::Return,
},
)]
.into_iter()
.collect(),
register_map: (0..COUNT)
.map(|i| (RegisterId(i), RegisterType::Logic { width: 65 }))
.collect(),
};
WIDE_VALUE_VERIFICATIONS.with(|count| count.set(0));
let _ = lower_execution_unit(&unit, &empty_layout(), false);
let checks = WIDE_VALUE_VERIFICATIONS.with(|count| count.get());
assert!(
checks >= COUNT,
"the invariant must still be checked: {checks}"
);
assert!(
checks <= 2 * COUNT,
"repeated whole-map validation: {checks}"
);
}
2 changes: 2 additions & 0 deletions crates/celox-frontend-sv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ edition.workspace = true
rust-version.workspace = true

[dependencies]
serde_json = { workspace = true }

celox-design = { workspace = true }
celox-frontend-core = { workspace = true }
celox-heap = { workspace = true }
Expand Down
19 changes: 18 additions & 1 deletion crates/celox-frontend-sv/src/lowering/ff/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ impl Ff<'_, '_> {
})
.collect::<Result<Vec<_>, _>>()?;
let result = match op {
ObjectOp::Randomize(program) => {
let object = self.handle(&args[0])?;
let check = self.integer_of_width(&args[1], 1, false)?;
let bytes = serde_json::to_vec(program).expect("constraint program serialization");
let mut buffer = self.heap_call(ops::NEW, &[]);
for chunk in bytes.chunks(8) {
let value = chunk
.iter()
.fold(0u64, |value, byte| (value << 8) | u64::from(*byte));
let value = self.constant64(value);
let count = self.constant64(chunk.len() as u64);
buffer = self.heap_call(ops::APPEND_BYTES, &[buffer, value, count]);
}
let program = self.heap_call(ops::FREEZE, &[buffer]);
self.heap_call(ops::OBJECT_RANDOMIZE, &[object, program, check])
}
ObjectOp::Container { .. } => unreachable!("handled by container_call"),
ObjectOp::New {
class,
Expand Down Expand Up @@ -132,7 +148,8 @@ impl Ff<'_, '_> {
HandleProperty::String => celox_design::ValueKind::StrRef,
HandleProperty::Object => celox_design::ValueKind::ObjRef,
}),
ObjectOp::Store(_)
ObjectOp::Randomize(_)
| ObjectOp::Store(_)
| ObjectOp::ClassOf
| ObjectOp::Random
| ObjectOp::RandomCyclic { .. }
Expand Down
19 changes: 19 additions & 0 deletions crates/celox-frontend-sv/src/warning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ pub enum FrontendWarningKind {
MixedTimescale,
#[error("`$size` on an interface array is a language extension")]
InterfaceArrayQuery,
#[error(
"unindexed interface array parameter `{path}` uses the first declared element `{element}`"
)]
InterfaceArrayParameter { path: String, element: String },
/// IEEE 1800-2023 9.2.2.4 restricts writes by other processes.
#[error("multiple variable drivers for `{signal}` in `{module}` include an always_ff process")]
MultipleAlwaysFfDrivers { module: String, signal: String },
Expand Down Expand Up @@ -101,6 +105,17 @@ pub(crate) fn analyzer_warnings(
celox_sv_analyzer::ir::AnalyzerWarning::InterfaceArrayQuery { site } => {
(FrontendWarningKind::InterfaceArrayQuery, site.clone())
}
celox_sv_analyzer::ir::AnalyzerWarning::InterfaceArrayParameter {
path,
element,
site,
} => (
FrontendWarningKind::InterfaceArrayParameter {
path: path.clone(),
element: element.clone(),
},
site.clone(),
),
celox_sv_analyzer::ir::AnalyzerWarning::MixedTimescale => {
(FrontendWarningKind::MixedTimescale, None)
}
Expand Down Expand Up @@ -155,6 +170,7 @@ impl miette::Diagnostic for FrontendWarning {
Some(Box::new(match self.kind {
FrontendWarningKind::MixedTimescale => "mixed_timescale",
FrontendWarningKind::InterfaceArrayQuery => "interface_array_query",
FrontendWarningKind::InterfaceArrayParameter { .. } => "interface_array_parameter",
FrontendWarningKind::MultipleAlwaysFfDrivers { .. } => "multiple_always_ff_drivers",
FrontendWarningKind::UnpackedPortDefault { .. } => "unpacked_port_default",
FrontendWarningKind::InferredLatch => "inferred_latch",
Expand All @@ -175,6 +191,9 @@ impl miette::Diagnostic for FrontendWarning {
FrontendWarningKind::InterfaceArrayQuery => {
"interface arrays are not data arrays in IEEE 1800-2023 20.7; set interface_array_query=warn or allow for compatibility"
}
FrontendWarningKind::InterfaceArrayParameter { .. } => {
"IEEE 1800-2023 23.6 requires an instance select before a member; set interface_array_parameter=warn or allow to use the first declared element"
}
FrontendWarningKind::MixedTimescale => {
"declare timeunit/timeprecision consistently; undeclared scopes use 1ns/1ps when this check is relaxed"
}
Expand Down
3 changes: 3 additions & 0 deletions crates/celox-heap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ edition.workspace = true
rust-version.workspace = true

[dependencies]
aplite = { workspace = true }
serde_json = { workspace = true }

serde = { workspace = true, features = ["rc"] }
fxhash = { workspace = true }

Expand Down
1 change: 1 addition & 0 deletions crates/celox-heap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use fxhash::{FxHashMap as HashMap, FxHashSet as HashSet};
pub mod containers;
mod objects;
pub mod ops;
pub mod randomization;

pub use objects::{Fault, NULL};

Expand Down
4 changes: 4 additions & 0 deletions crates/celox-heap/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl Object {
/// reports once control returns to it.
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum Fault {
ConstraintRandomization(String),
NegativeArraySize,
ContainerAllocationLimit,
/// A property access or method call through `null` or a handle of no
Expand All @@ -61,6 +62,9 @@ pub enum Fault {
impl std::fmt::Display for Fault {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::ConstraintRandomization(reason) => {
write!(f, "constraint randomization failed: {reason}")
}
Self::NegativeArraySize => f.write_str("negative dynamic array size"),
Self::ContainerAllocationLimit => {
f.write_str("dynamic container allocation limit exceeded")
Expand Down
Loading
Loading