Skip to content

Commit

Permalink
remove simdfield impl in gf0_128
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfloatersu committed Nov 11, 2024
1 parent 10e2afc commit 4fd26ab
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 88 deletions.
4 changes: 2 additions & 2 deletions arith/gf2/src/gf2x128/avx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Field for AVXGF2x128 {
};

const ONE: Self = AVXGF2x128 {
v: unsafe { transmute([!0u64, !0u64]) },
v: unsafe { transmute::<[u64; 2], __m128i>([!0u64, !0u64]) },
};

const INV_2: Self = AVXGF2x128 {
Expand All @@ -76,7 +76,7 @@ impl Field for AVXGF2x128 {
#[inline(always)]
fn one() -> Self {
AVXGF2x128 {
v: unsafe { transmute([!0u64, !0u64]) },
v: unsafe { transmute::<[u64; 2], __m128i>([!0u64, !0u64]) },
}
}

Expand Down
2 changes: 0 additions & 2 deletions arith/gf2/src/gf2x128/neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,6 @@ impl From<GF2> for NeonGF2x128 {
}
}

// TODO: SimdField

impl SimdField for NeonGF2x128 {
type Scalar = GF2;

Expand Down
8 changes: 6 additions & 2 deletions arith/gf2/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use arith::{
random_field_tests, random_inversion_tests, random_simd_field_tests, Field, FieldSerde,
};

use crate::{GF2x64, GF2x8, GF2};
use crate::{GF2x128, GF2x64, GF2x8, GF2};

#[test]
fn test_field() {
Expand All @@ -22,6 +22,9 @@ fn test_simd_field() {

random_field_tests::<GF2x64>("Vectorized GF2 len 64".to_string());
random_simd_field_tests::<GF2x64>("Vectorized GF2 len 64".to_string());

random_field_tests::<GF2x128>("Vectorized GF2 len 128".to_string());
random_simd_field_tests::<GF2x128>("Vectorized GF2 len 128".to_string());
}

fn custom_serde_vectorize_gf2<F: Field + FieldSerde>() {
Expand All @@ -38,5 +41,6 @@ fn custom_serde_vectorize_gf2<F: Field + FieldSerde>() {
#[test]
fn test_custom_serde_vectorize_gf2() {
custom_serde_vectorize_gf2::<GF2x8>();
custom_serde_vectorize_gf2::<GF2x64>()
custom_serde_vectorize_gf2::<GF2x64>();
custom_serde_vectorize_gf2::<GF2x128>()
}
42 changes: 2 additions & 40 deletions arith/gf2_128/src/gf2_ext128/avx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::{
ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign},
};

use arith::{field_common, ExtensionField, Field, FieldSerde, FieldSerdeResult, SimdField};
use gf2::{GF2x64, GF2};
use arith::{field_common, ExtensionField, Field, FieldSerde, FieldSerdeResult};
use gf2::GF2;

#[derive(Debug, Clone, Copy)]
pub struct AVXGF2_128 {
Expand Down Expand Up @@ -328,41 +328,3 @@ fn mul_internal(a: &AVXGF2_128, b: &AVXGF2_128) -> AVXGF2_128 {
v: unsafe { gfmul(a.v, b.v) },
}
}

impl SimdField for AVXGF2_128 {
type Scalar = GF2;

const PACK_SIZE: usize = 128;

#[inline(always)]
fn scale(&self, challenge: &Self::Scalar) -> Self {
if challenge.v == 0 {
Self::ZERO
} else {
*self
}
}

#[inline(always)]
fn pack(base_vec: &[Self::Scalar]) -> Self {
assert_eq!(base_vec.len(), Self::PACK_SIZE);
let mut packed_to_gf2x64 = [GF2x64::ZERO; Self::PACK_SIZE / GF2x64::PACK_SIZE];
packed_to_gf2x64
.iter_mut()
.zip(base_vec.chunks(GF2x64::PACK_SIZE))
.for_each(|(gf2x64, pack)| *gf2x64 = GF2x64::pack(pack));

unsafe { transmute(packed_to_gf2x64) }
}

#[inline(always)]
fn unpack(&self) -> Vec<Self::Scalar> {
let packed_to_gf2x64: [GF2x64; Self::PACK_SIZE / GF2x64::PACK_SIZE] =
unsafe { transmute(*self) };

packed_to_gf2x64
.iter()
.flat_map(|packed| packed.unpack())
.collect()
}
}
42 changes: 2 additions & 40 deletions arith/gf2_128/src/gf2_ext128/neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::iter::{Product, Sum};
use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use std::{arch::aarch64::*, mem::transmute};

use arith::{field_common, ExtensionField, Field, FieldSerde, FieldSerdeResult, SimdField};
use gf2::{GF2x64, GF2};
use arith::{field_common, ExtensionField, Field, FieldSerde, FieldSerdeResult};
use gf2::GF2;

#[derive(Clone, Copy, Debug)]
pub struct NeonGF2_128 {
Expand Down Expand Up @@ -403,41 +403,3 @@ pub(crate) fn mul_by_x_internal(a: &uint32x4_t) -> uint32x4_t {
vreinterpretq_u32_u64(res)
}
}

impl SimdField for NeonGF2_128 {
type Scalar = GF2;

const PACK_SIZE: usize = 128;

#[inline(always)]
fn scale(&self, challenge: &Self::Scalar) -> Self {
if challenge.v == 0 {
Self::ZERO
} else {
*self
}
}

#[inline(always)]
fn pack(base_vec: &[Self::Scalar]) -> Self {
assert_eq!(base_vec.len(), Self::PACK_SIZE);
let mut packed_to_gf2x64 = [GF2x64::ZERO; Self::PACK_SIZE / GF2x64::PACK_SIZE];
packed_to_gf2x64
.iter_mut()
.zip(base_vec.chunks(GF2x64::PACK_SIZE))
.for_each(|(gf2x64, pack)| *gf2x64 = GF2x64::pack(pack));

unsafe { transmute(packed_to_gf2x64) }
}

#[inline(always)]
fn unpack(&self) -> Vec<Self::Scalar> {
let packed_to_gf2x64: [GF2x64; Self::PACK_SIZE / GF2x64::PACK_SIZE] =
unsafe { transmute(*self) };

packed_to_gf2x64
.iter()
.flat_map(|packed| packed.unpack())
.collect()
}
}
3 changes: 1 addition & 2 deletions arith/gf2_128/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use crate::{GF2_128x8, GF2_128};

#[test]
fn test_simd_field() {
random_simd_field_tests::<GF2_128>("Simd for GF2 over GF2Ext128".to_string());
random_simd_field_tests::<GF2_128x8>("Simd for GF2Ext128 over GF2Ext128x8".to_string());
random_simd_field_tests::<GF2_128x8>("Simd GF2 Ext128".to_string());
}

#[test]
Expand Down

0 comments on commit 4fd26ab

Please sign in to comment.