Skip to content

Commit

Permalink
fix_pack (#89)
Browse files Browse the repository at this point in the history
* fix_pack

* fmt
  • Loading branch information
niconiconi authored Sep 10, 2024
1 parent 50b5faa commit 9c00ff9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions arith/src/extension_field/gf2_128x8/avx256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,17 @@ impl SimdField for AVX256GF2_128x8 {
fn pack_size() -> usize {
8
}

fn pack(base_vec: &[Self::Scalar]) -> Self {
debug_assert!(base_vec.len() == 8);
let base_vec_array: [Self::Scalar; 8] = base_vec.try_into().unwrap();
unsafe { transmute(base_vec_array) }
}

fn unpack(&self) -> Vec<Self::Scalar> {
let ret = unsafe { transmute::<[__m256i; 4], [Self::Scalar; 8]>(self.data) };
ret.to_vec()
}
}

#[inline(always)]
Expand Down
11 changes: 11 additions & 0 deletions arith/src/field/m31/m31_avx256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,17 @@ impl SimdField for AVXM31 {
fn pack_size() -> usize {
M31_PACK_SIZE
}

fn pack(base_vec: &[Self::Scalar]) -> Self {
debug_assert_eq!(base_vec.len(), M31_PACK_SIZE);
let ret: [Self::Scalar; M31_PACK_SIZE] = base_vec.try_into().unwrap();
unsafe { transmute(ret) }
}

fn unpack(&self) -> Vec<Self::Scalar> {
let ret = unsafe { transmute::<[__m256i; 2], [Self::Scalar; M31_PACK_SIZE]>(self.v) };
ret.to_vec()
}
}

impl From<M31> for AVXM31 {
Expand Down

0 comments on commit 9c00ff9

Please sign in to comment.