Skip to content

Commit

Permalink
Access to nonconstant fixed columns. (#2368)
Browse files Browse the repository at this point in the history
Some machines need non-constant fixed column values even outside of
fixed lookups. An example for that is the `STEP` column in a riscv VM.

This PR introduces variables for those columns and implements access in
the compiled code.
  • Loading branch information
chriseth authored Jan 23, 2025
1 parent c06ee6c commit 229272f
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 98 deletions.
20 changes: 11 additions & 9 deletions executor/src/witgen/jit/block_machine_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use std::collections::HashSet;

use bit_vec::BitVec;
use itertools::Itertools;
use powdr_ast::analyzed::AlgebraicReference;
use powdr_ast::analyzed::{PolyID, PolynomialType};
use powdr_number::FieldElement;

use crate::witgen::{jit::processor::Processor, machines::MachineParts, FixedData};

use super::{
effect::Effect,
variable::Variable,
variable::{Cell, Variable},
witgen_inference::{CanProcessCall, FixedEvaluator, WitgenInference},
};

Expand Down Expand Up @@ -123,17 +123,19 @@ impl<'a, T: FieldElement> BlockMachineProcessor<'a, T> {
}

impl<T: FieldElement> FixedEvaluator<T> for &BlockMachineProcessor<'_, T> {
fn evaluate(&self, var: &AlgebraicReference, row_offset: i32) -> Option<T> {
assert!(var.is_fixed());
let values = self.fixed_data.fixed_cols[&var.poly_id].values_max_size();
fn evaluate(&self, fixed_cell: &Cell) -> Option<T> {
let poly_id = PolyID {
id: fixed_cell.id,
ptype: PolynomialType::Constant,
};
let values = self.fixed_data.fixed_cols[&poly_id].values_max_size();

// By assumption of the block machine, all fixed columns are cyclic with a period of <block_size>.
// An exception might be the first and last row.
assert!(row_offset >= -1);
assert!(fixed_cell.row_offset >= -1);
assert!(self.block_size >= 1);
// The current row is guaranteed to be at least 1.
let current_row = (2 * self.block_size as i32 + row_offset) as usize;
let row = current_row + var.next as usize;
// The row is guaranteed to be at least 1.
let row = (2 * self.block_size as i32 + fixed_cell.row_offset) as usize;

assert!(values.len() >= self.block_size * 4);

Expand Down
Loading

1 comment on commit 229272f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 229272f Previous: 6619c62 Ratio
executor-benchmark/keccak 13543459187 ns/iter (± 152333763) 8210169589 ns/iter (± 30435634) 1.65

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.