Skip to content

Commit

Permalink
Clean up var_count implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter committed May 25, 2024
1 parent a91452e commit fda50ba
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 19 deletions.
4 changes: 1 addition & 3 deletions fidget/src/core/compiler/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl<const N: usize> RegisterAllocator<N> {
#[inline(always)]
pub fn op(&mut self, op: SsaOp) {
match op {
SsaOp::Input(out, i) => self.op_input(out, i.try_into().unwrap()),
SsaOp::Input(out, i) => self.op_input(out, i),
SsaOp::CopyImm(out, imm) => self.op_copy_imm(out, imm),

SsaOp::NegReg(..)
Expand Down Expand Up @@ -674,8 +674,6 @@ impl<const N: usize> RegisterAllocator<N> {
/// Pushes an [`Input`](crate::compiler::RegOp::Input) operation to the tape
#[inline(always)]
fn op_input(&mut self, out: u32, i: u32) {
// TODO: tightly pack variables (which may be sparse) into slots
self.out.var_count = self.out.var_count.max(i as u32 + 1);
self.op_out_only(out, |out| RegOp::Input(out, i));
}
}
9 changes: 0 additions & 9 deletions fidget/src/core/compiler/reg_tape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ pub struct RegTape {

/// Total allocated slots
pub(super) slot_count: u32,

/// Number of variables
pub(super) var_count: u32,
}

impl RegTape {
Expand All @@ -35,7 +32,6 @@ impl RegTape {
Self {
tape: vec![],
slot_count: 1,
var_count: 0,
}
}

Expand All @@ -50,11 +46,6 @@ impl RegTape {
pub fn slot_count(&self) -> usize {
self.slot_count as usize
}
/// Returns the number of variables (inputs) used in this tape
#[inline]
pub fn var_count(&self) -> usize {
self.var_count as usize
}
/// Returns the number of elements in the tape
#[inline]
pub fn len(&self) -> usize {
Expand Down
4 changes: 1 addition & 3 deletions fidget/src/core/eval/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ pub trait TracingEvaluator: Default {
vars: &[Self::Data],
var_count: usize,
) -> Result<(), Error> {
// It's fine if the caller has given us extra variables (e.g. due to
// tape simplification), but it must have given us enough.
if vars.len() < var_count {
if vars.len() != var_count {
Err(Error::BadVarSlice(vars.len(), var_count))
} else {
Ok(())
Expand Down
7 changes: 5 additions & 2 deletions fidget/src/core/vm/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ impl<const N: usize> VmData<N> {
self.asm.slot_count()
}

/// Returns the number of variables (inputs) in the inner VM tape
/// Returns the number of variables that may be used
///
/// Note that this can sometimes be an overestimate, if the inner tape has
/// been simplified.
pub fn var_count(&self) -> usize {
self.asm.var_count()
self.vars.len()
}

/// Simplifies both inner tapes, using the provided choice array
Expand Down
2 changes: 0 additions & 2 deletions fidget/src/jit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,6 @@ impl JitTracingEval {
) -> (T, Option<&VmTrace>) {
let mut simplify = 0;
self.choices.resize(tape.choice_count, Choice::Unknown);
assert!(tape.var_count <= 3);
self.choices.fill(Choice::Unknown);
let out = unsafe {
(tape.fn_trace)(
Expand Down Expand Up @@ -1114,7 +1113,6 @@ unsafe impl<T> Sync for JitBulkFn<T> {}
impl<T: From<f32> + Copy + SimdSize> JitBulkEval<T> {
/// Evaluate multiple points
fn eval(&mut self, tape: &JitBulkFn<T>, vars: &[&[T]]) -> &[T] {
assert!(tape.var_count <= 3);
let n = vars.first().map(|v| v.len()).unwrap_or(0);
self.out.resize(n, f32::NAN.into());
self.out.fill(f32::NAN.into());
Expand Down

0 comments on commit fda50ba

Please sign in to comment.