Skip to content

Commit 229272f

Browse files
authored
Access to nonconstant fixed columns. (#2368)
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.
1 parent c06ee6c commit 229272f

10 files changed

+289
-98
lines changed

executor/src/witgen/jit/block_machine_processor.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ use std::collections::HashSet;
22

33
use bit_vec::BitVec;
44
use itertools::Itertools;
5-
use powdr_ast::analyzed::AlgebraicReference;
5+
use powdr_ast::analyzed::{PolyID, PolynomialType};
66
use powdr_number::FieldElement;
77

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

1010
use super::{
1111
effect::Effect,
12-
variable::Variable,
12+
variable::{Cell, Variable},
1313
witgen_inference::{CanProcessCall, FixedEvaluator, WitgenInference},
1414
};
1515

@@ -123,17 +123,19 @@ impl<'a, T: FieldElement> BlockMachineProcessor<'a, T> {
123123
}
124124

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

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

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

0 commit comments

Comments
 (0)