Skip to content

Commit

Permalink
Move Preprocessed Columns Struct to Preprocessed File
Browse files Browse the repository at this point in the history
  • Loading branch information
Gali-StarkWare committed Jan 16, 2025
1 parent 535753b commit 32d6c02
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 45 deletions.
38 changes: 35 additions & 3 deletions stwo_cairo_prover/crates/prover/src/cairo_air/preprocessed.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use itertools::{chain, Itertools};
use prover_types::simd::LOG_N_LANES;
use stwo_prover::constraint_framework::preprocessed_columns::{IsFirst, PreProcessedColumnId};
use stwo_prover::core::backend::simd::m31::{PackedM31, N_LANES};
use stwo_prover::core::backend::simd::SimdBackend;
use stwo_prover::core::fields::m31::BaseField;
use stwo_prover::core::poly::circle::CircleEvaluation;
use stwo_prover::core::backend::Col;
use stwo_prover::core::fields::m31::{BaseField, M31};
use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation};
use stwo_prover::core::poly::BitReversedOrder;

use super::LOG_MAX_ROWS;
use crate::components::memory::Seq;
use crate::components::range_check_vector::SIMD_ENUMERATION_0;

const N_PREPROCESSED_COLUMN_SIZES: usize = (LOG_MAX_ROWS - LOG_N_LANES) as usize + 1;

Expand Down Expand Up @@ -63,6 +65,36 @@ pub fn preprocessed_trace_columns() -> Vec<PreProcessedColumn> {
.collect_vec()
}

/// A column with the numbers [0..(2^log_size)-1].
#[derive(Debug, Clone)]
pub struct Seq {
pub log_size: u32,
}
impl Seq {
pub const fn new(log_size: u32) -> Self {
Self { log_size }
}

pub fn packed_at(&self, vec_row: usize) -> PackedM31 {
assert!(vec_row < (1 << self.log_size) / N_LANES);
PackedM31::broadcast(M31::from(vec_row * N_LANES))
+ unsafe { PackedM31::from_simd_unchecked(SIMD_ENUMERATION_0) }
}

pub fn gen_column_simd(&self) -> CircleEvaluation<SimdBackend, BaseField, BitReversedOrder> {
let col = Col::<SimdBackend, BaseField>::from_iter(
(0..(1 << self.log_size)).map(BaseField::from),
);
CircleEvaluation::new(CanonicCoset::new(self.log_size).circle_domain(), col)
}

pub fn id(&self) -> PreProcessedColumnId {
PreProcessedColumnId {
id: format!("preprocessed_seq_{}", self.log_size).to_string(),
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use stwo_prover::core::fields::qm31::SecureField;
use stwo_prover::core::fields::secure_column::SECURE_EXTENSION_DEGREE;
use stwo_prover::core::pcs::TreeVec;

use crate::components::memory::Seq;
use crate::cairo_air::preprocessed::Seq;
use crate::relations;

/// Split the (ID , Multiplicity) columns to shorter chunks. This is done to improve the performance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation};
use stwo_prover::core::poly::BitReversedOrder;

use super::component::{Claim, InteractionClaim, N_SPLIT_CHUNKS};
use crate::components::memory::Seq;
use crate::cairo_air::preprocessed::Seq;
use crate::components::memory_address_to_id::component::{
N_ID_AND_MULT_COLUMNS_PER_CHUNK, N_TRACE_COLUMNS,
};
Expand Down
40 changes: 0 additions & 40 deletions stwo_cairo_prover/crates/prover/src/components/memory/mod.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,6 @@
use stwo_prover::constraint_framework::preprocessed_columns::PreProcessedColumnId;
use stwo_prover::core::backend::simd::m31::{PackedM31, N_LANES};
use stwo_prover::core::backend::simd::SimdBackend;
use stwo_prover::core::backend::Col;
use stwo_prover::core::fields::m31::{BaseField, M31};
use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation};
use stwo_prover::core::poly::BitReversedOrder;

use crate::components::range_check_vector::SIMD_ENUMERATION_0;

pub mod memory_address_to_id;
pub mod memory_id_to_big;

/// Used for sanity checks and assertions.
pub const LOG_MEMORY_ADDRESS_BOUND: u32 = 27;
pub const MEMORY_ADDRESS_BOUND: usize = 1 << LOG_MEMORY_ADDRESS_BOUND;

/// A column with the numbers [0..(2^log_size)-1].
#[derive(Debug, Clone)]
pub struct Seq {
pub log_size: u32,
}
impl Seq {
pub const fn new(log_size: u32) -> Self {
Self { log_size }
}

pub fn packed_at(&self, vec_row: usize) -> PackedM31 {
assert!(vec_row < (1 << self.log_size) / N_LANES);
PackedM31::broadcast(M31::from(vec_row * N_LANES))
+ unsafe { PackedM31::from_simd_unchecked(SIMD_ENUMERATION_0) }
}

pub fn gen_column_simd(&self) -> CircleEvaluation<SimdBackend, BaseField, BitReversedOrder> {
let col = Col::<SimdBackend, BaseField>::from_iter(
(0..(1 << self.log_size)).map(BaseField::from),
);
CircleEvaluation::new(CanonicCoset::new(self.log_size).circle_domain(), col)
}

pub fn id(&self) -> PreProcessedColumnId {
PreProcessedColumnId {
id: format!("preprocessed_seq_{}", self.log_size).to_string(),
}
}
}

0 comments on commit 32d6c02

Please sign in to comment.