From 4fd26abc44b17fa828b34d4bccf3a2eba86029d4 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Mon, 11 Nov 2024 16:04:39 -0500 Subject: [PATCH] remove simdfield impl in gf0_128 --- arith/gf2/src/gf2x128/avx.rs | 4 +-- arith/gf2/src/gf2x128/neon.rs | 2 -- arith/gf2/src/tests.rs | 8 ++++-- arith/gf2_128/src/gf2_ext128/avx.rs | 42 ++-------------------------- arith/gf2_128/src/gf2_ext128/neon.rs | 42 ++-------------------------- arith/gf2_128/src/tests.rs | 3 +- 6 files changed, 13 insertions(+), 88 deletions(-) diff --git a/arith/gf2/src/gf2x128/avx.rs b/arith/gf2/src/gf2x128/avx.rs index c3d06ef3..566c7532 100644 --- a/arith/gf2/src/gf2x128/avx.rs +++ b/arith/gf2/src/gf2x128/avx.rs @@ -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 { @@ -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]) }, } } diff --git a/arith/gf2/src/gf2x128/neon.rs b/arith/gf2/src/gf2x128/neon.rs index 19403405..c3f7b3be 100644 --- a/arith/gf2/src/gf2x128/neon.rs +++ b/arith/gf2/src/gf2x128/neon.rs @@ -319,8 +319,6 @@ impl From for NeonGF2x128 { } } -// TODO: SimdField - impl SimdField for NeonGF2x128 { type Scalar = GF2; diff --git a/arith/gf2/src/tests.rs b/arith/gf2/src/tests.rs index f3364700..b6700b24 100644 --- a/arith/gf2/src/tests.rs +++ b/arith/gf2/src/tests.rs @@ -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() { @@ -22,6 +22,9 @@ fn test_simd_field() { random_field_tests::("Vectorized GF2 len 64".to_string()); random_simd_field_tests::("Vectorized GF2 len 64".to_string()); + + random_field_tests::("Vectorized GF2 len 128".to_string()); + random_simd_field_tests::("Vectorized GF2 len 128".to_string()); } fn custom_serde_vectorize_gf2() { @@ -38,5 +41,6 @@ fn custom_serde_vectorize_gf2() { #[test] fn test_custom_serde_vectorize_gf2() { custom_serde_vectorize_gf2::(); - custom_serde_vectorize_gf2::() + custom_serde_vectorize_gf2::(); + custom_serde_vectorize_gf2::() } diff --git a/arith/gf2_128/src/gf2_ext128/avx.rs b/arith/gf2_128/src/gf2_ext128/avx.rs index 97403998..03990aa2 100644 --- a/arith/gf2_128/src/gf2_ext128/avx.rs +++ b/arith/gf2_128/src/gf2_ext128/avx.rs @@ -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 { @@ -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 { - let packed_to_gf2x64: [GF2x64; Self::PACK_SIZE / GF2x64::PACK_SIZE] = - unsafe { transmute(*self) }; - - packed_to_gf2x64 - .iter() - .flat_map(|packed| packed.unpack()) - .collect() - } -} diff --git a/arith/gf2_128/src/gf2_ext128/neon.rs b/arith/gf2_128/src/gf2_ext128/neon.rs index 792e7ad3..ea1b528b 100644 --- a/arith/gf2_128/src/gf2_ext128/neon.rs +++ b/arith/gf2_128/src/gf2_ext128/neon.rs @@ -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 { @@ -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 { - let packed_to_gf2x64: [GF2x64; Self::PACK_SIZE / GF2x64::PACK_SIZE] = - unsafe { transmute(*self) }; - - packed_to_gf2x64 - .iter() - .flat_map(|packed| packed.unpack()) - .collect() - } -} diff --git a/arith/gf2_128/src/tests.rs b/arith/gf2_128/src/tests.rs index 653a7604..43be77ff 100644 --- a/arith/gf2_128/src/tests.rs +++ b/arith/gf2_128/src/tests.rs @@ -13,8 +13,7 @@ use crate::{GF2_128x8, GF2_128}; #[test] fn test_simd_field() { - random_simd_field_tests::("Simd for GF2 over GF2Ext128".to_string()); - random_simd_field_tests::("Simd for GF2Ext128 over GF2Ext128x8".to_string()); + random_simd_field_tests::("Simd GF2 Ext128".to_string()); } #[test]