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
2 changes: 1 addition & 1 deletion .release-please-aplite-manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{"crates/aplite":"0.1.0"}
24 changes: 24 additions & 0 deletions crates/aplite/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Changelog

## 0.1.0 (2026-10-26)


### Features

* **aplite:** add reproducible seeded scalar model search ([3c53fe3](https://github.com/celox-sim/celox/commit/3c53fe3845528ef9e2958ab3abed71a2dd028691))
* **aplite:** add reproducible seeded scalar model search ([#2168](https://github.com/celox-sim/celox/issues/2168)) ([ad322c5](https://github.com/celox-sim/celox/commit/ad322c5002250f98ca1959458b112f93eba85f6d))
* **aplite:** extract an independently versioned finite solver ([e65a817](https://github.com/celox-sim/celox/commit/e65a817efad0815a93f50e723b4d67217f74f365))
* **aplite:** extract an independently versioned finite solver ([#2167](https://github.com/celox-sim/celox/issues/2167)) ([6b3e8b4](https://github.com/celox-sim/celox/commit/6b3e8b4e1a3b5745c1418c9c7fe6cd747dd4dad0))
* **aplite:** generate approximate projected sample batches ([7c9ef1c](https://github.com/celox-sim/celox/commit/7c9ef1c2556121c02ed2431b0849d4f71cb9fc86))
* **aplite:** generate approximate projected sample batches ([#2184](https://github.com/celox-sim/celox/issues/2184)) ([5bcd11f](https://github.com/celox-sim/celox/commit/5bcd11f0a70f5060a96e5c006974a9068d202000))
* **aplite:** query bounded projected XOR cells ([c2a33b9](https://github.com/celox-sim/celox/commit/c2a33b9581709847768eb5ad13811d2959fe7e5b))
* **aplite:** query bounded projected XOR cells ([#2177](https://github.com/celox-sim/celox/issues/2177)) ([8a57393](https://github.com/celox-sim/celox/commit/8a57393985b9d3a5b2ab262d313d9764b32823df))
* **aplite:** reuse compiled queries with temporary assumptions ([e8aec71](https://github.com/celox-sim/celox/commit/e8aec711eeb131c130b068520c3d0f3e1c9ee9cf))
* **aplite:** reuse compiled queries with temporary assumptions ([#2175](https://github.com/celox-sim/celox/issues/2175)) ([8bb3cd8](https://github.com/celox-sim/celox/commit/8bb3cd816a7323dc0a29b165a759e8f9d904c25d))


### Performance Improvements

* **aplite:** reduce affine XOR rows before bit blasting ([52daeac](https://github.com/celox-sim/celox/commit/52daeacbb6a769b368415f114f7b16857ddc6efd))
* **aplite:** reduce affine XOR rows before bit blasting ([#2183](https://github.com/celox-sim/celox/issues/2183)) ([bf99b03](https://github.com/celox-sim/celox/commit/bf99b03bb77e53688d14433eb75d91048c79c002))

## Changelog

## Unreleased

- Extract the existing finite solver and expression IR from lydite without changing its algorithms.
39 changes: 39 additions & 0 deletions crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10686,6 +10686,45 @@ fn inferred_clock(
mod tests {
use super::*;

#[test]
fn stateless_function_scratch_loops_do_not_become_runtime_loops() {
let source = r#"module Top(input wire [255:0] d, output wire [255:0] q);
function [15:0][15:0] pattern();
logic [15:0] words [15:0];
for (int i=0; i<16; i++) words[i] = 16'b1 << i;
for (int i=0; i<16; i++) for (int j=0; j<16; j++) pattern[i][j] = words[i][j];
endfunction
assign q = d ^ pattern();
endmodule"#;
for four_state in [false, true] {
let output = schedule_sources(
&[(source, Path::new("top.sv"))],
"Top",
&[],
&[],
&[],
four_state,
&celox_frontend_core::ParallelScheduleOptions::default(),
&FrontendTraceOptions::default(),
None,
&mut Vec::new(),
)
.unwrap();
let instructions: usize = output
.scheduled
.sir
.eval_comb
.iter()
.flat_map(|unit| unit.blocks.values())
.map(|block| block.instructions.len())
.sum();
assert!(
instructions < 32,
"constant scratch loops produced {instructions} runtime instructions"
);
}
}

#[test]
fn bit_select_width_does_not_evaluate_a_runtime_zero_sample() {
let index = sv::ir::ConstExpr::Ident("index".into());
Expand Down
106 changes: 105 additions & 1 deletion crates/celox-frontend-sv/src/lowering/comb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2564,8 +2564,77 @@ impl<'p, 'a> Comb<'p, 'a> {
}
}

/// Possible values of one selector bit, as a set of 0, 1, Z, X.
/// Follow only wiring operations: other expressions retain the original
/// conservative domain. Bound work even for a slice of a large/deep DAG.
fn case_bit_values(&self, mut node: NodeId, mut bit: usize, four_state: bool) -> u8 {
let fallback = if four_state { 0b1111 } else { 0b0011 };
let mut budget = 256usize;
while budget > 0 {
budget -= 1;
if bit >= self.width(node) {
return fallback;
}
match self.arena.get(node) {
SLTNode::Constant(value, mask, _, _) => {
let digit =
u8::from(value.bit(bit as u64)) | (u8::from(mask.bit(bit as u64)) << 1);
return 1 << digit;
}
SLTNode::Input {
variable, index, ..
} => {
return if !self.m.four_state
|| (index.is_empty()
&& self
.m
.variables
.get(variable)
.is_some_and(|var| !var.is_4state))
{
0b0011
} else {
fallback
};
}
SLTNode::Unary(UnaryOp::ToTwoState, _) => return 0b0011,
SLTNode::Unary(UnaryOp::Ident, inner) | SLTNode::Capture { expr: inner, .. } => {
node = *inner
}
SLTNode::Slice { expr, access } => {
let Some(offset) = bit.checked_add(access.lsb) else {
return fallback;
};
bit = offset;
node = *expr;
}
SLTNode::Concat(parts) => {
let mut selected = None;
// SLT concatenations store their most significant part first.
for (part, width) in parts.iter().rev() {
if budget == 0 {
return fallback;
}
budget -= 1;
if bit < *width {
selected = Some(*part);
break;
}
bit -= width;
}
let Some(part) = selected else {
return fallback;
};
node = part;
}
_ => return fallback,
}
}
fallback
}

/// For each item, whether it and the items before it cover every
/// two-state value of the selector with constant labels.
/// possible selector value with constant labels.
fn case_coverage(
&mut self,
store: &mut Store,
Expand Down Expand Up @@ -2682,9 +2751,32 @@ impl<'p, 'a> Comb<'p, 'a> {
}
return Ok(coverage);
}
// A concatenated fixed X/Z bit is not a free four-state input.
// Restrict enumeration to each bit's possible values; correlations
// between nonconstant bits remain conservatively unconstrained.
let digit_width = if four_state_selector { 2 } else { 1 };
let digit_mask = (1u64 << digit_width) - 1;
let mut fixed_bits = 0u64;
let mut required_bits = 0u64;
for bit in 0..selector_width {
let values = self.case_bit_values(selector_node, bit, four_state_selector);
let shift = digit_width * bit;
if values.is_power_of_two() {
let digit = u64::from(values.trailing_zeros());
if !four_state_selector && digit > 1 {
return Ok(none);
}
fixed_bits |= digit_mask << shift;
required_bits |= digit << shift;
} else if four_state_selector && values == 0b0011 {
// A two-state variable bit has a free payload and a zero mask.
fixed_bits |= 2 << shift;
}
}
let mut remaining: Vec<(BigUint, BigUint)> = if four_state_selector {
// Each bit is 0, 1, Z (payload 0, mask 1), or X (payload 1, mask 1).
(0u64..(1u64 << (2 * selector_width)))
.filter(|raw| raw & fixed_bits == required_bits)
.map(|raw| {
let mut value = BigUint::zero();
let mut mask = BigUint::zero();
Expand All @@ -2705,6 +2797,7 @@ impl<'p, 'a> Comb<'p, 'a> {
.collect()
} else {
(0u64..(1u64 << selector_width))
.filter(|raw| raw & fixed_bits == required_bits)
.map(|raw| (extend(&BigUint::from(raw), selector_width), BigUint::zero()))
.collect()
};
Expand Down Expand Up @@ -3288,6 +3381,17 @@ impl<'p, 'a> Comb<'p, 'a> {
args: &[Option<sv::ir::Expr>],
arg_order: &[usize],
) -> Result<Option<Value>, sv::AnalyzerError> {
if args.is_empty()
&& let Some(literal) = self.m.constant_functions.value(name)
{
let node = self.alloc(SLTNode::Constant(
literal.value,
literal.mask,
literal.width,
literal.signed,
))?;
return Ok(Some((node, Sources::default())));
}
let subroutine = self
.m
.subroutine(name)
Expand Down
2 changes: 2 additions & 0 deletions crates/celox-frontend-sv/src/lowering/procedural.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub(super) struct ProcModule<'a> {
pub constants: &'a HashMap<String, i128>,
pub parameter_types: &'a HashMap<String, (usize, bool)>,
pub subroutines: HashMap<String, sv::ir::Subroutine>,
pub constant_functions: sv::RuntimeConstantFunctions<'a>,
/// DPI-C imports of the module, by SystemVerilog name.
pub dpi_imports: HashMap<String, sv::ir::DpiImport>,
/// Extern functions the module calls, by local index.
Expand Down Expand Up @@ -246,6 +247,7 @@ impl<'a> ProcModule<'a> {
constants,
parameter_types,
subroutines,
constant_functions: sv::RuntimeConstantFunctions::new(module, constants, four_state),
dpi_imports,
extern_functions: Vec::new(),
extern_calls: 0,
Expand Down
Loading
Loading