Skip to content

Commit

Permalink
PackedFelt252Packed27
Browse files Browse the repository at this point in the history
  • Loading branch information
Gali-StarkWare committed Feb 13, 2025
1 parent 562aa60 commit 04c2ab8
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion stwo_cairo_prover/crates/prover_types/src/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use stwo_prover::core::backend::simd::m31::PackedM31;
use stwo_prover::core::fields::FieldExpOps;

use super::cpu::{UInt16, UInt32, UInt64, PRIME};
use crate::cpu::{BigUInt, CasmState, Felt252};
use crate::cpu::{BigUInt, CasmState, Felt252, Felt252Packed27};

pub const LOG_N_LANES: u32 = 4;

Expand Down Expand Up @@ -373,6 +373,10 @@ impl PackedFelt252 {
let limbs = arr.map(|felt| std::array::from_fn(|i| felt.get_m31(i)));
Self::from_limbs(<_ as Pack>::pack(limbs))
}

pub fn from_packed_felt252_packed27(packed27: PackedFelt252Packed27) -> Self {
Self::from_array(&std::array::from_fn(|i| Felt252::from(packed27.value[i])))
}
}

// TODO(Ohad): These are very slow, optimize.
Expand Down Expand Up @@ -447,6 +451,26 @@ impl DivExtend for PackedM31 {
}
}

#[derive(Clone, Copy)]
pub struct PackedFelt252Packed27 {
value: [Felt252Packed27; N_LANES],
}
impl PackedFelt252Packed27 {
pub fn from_packed_felt252packed27(other: PackedFelt252Packed27) -> Self {
Self { value: other.value }
}
pub fn get_m31(&self, index: usize) -> PackedM31 {
PackedM31::from_array(std::array::from_fn(|i| self.value[i].get_m31(index)))
}
}
impl Pack for Felt252Packed27 {
type SimdType = PackedFelt252Packed27;

fn pack(inputs: [Self; N_LANES]) -> Self::SimdType {
PackedFelt252Packed27 { value: inputs }
}
}

// TODO(Gali): Change to an efficient implementation.
#[derive(Copy, Clone, Debug)]
pub struct PackedBigUInt<const B: usize, const L: usize, const F: usize> {
Expand Down

0 comments on commit 04c2ab8

Please sign in to comment.