use crate::{Level, arch_types::ArchTypes, prelude::*, seal::Seal};
use crate::{
f32x4, f32x8, f32x16, f64x2, f64x4, f64x8, i8x16, i8x32, i8x64, i16x8, i16x16, i16x32, i32x4,
i32x8, i32x16, i64x2, i64x4, i64x8, mask8x16, mask8x32, mask8x64, mask16x8, mask16x16,
mask16x32, mask32x4, mask32x8, mask32x16, mask64x2, mask64x4, mask64x8, u8x16, u8x32, u8x64,
u16x8, u16x16, u16x32, u32x4, u32x8, u32x16, u64x2, u64x4, u64x8,
};
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;
use core::ops::*;
#[cfg(all(feature = "libm", not(feature = "std")))]
#[allow(
dead_code,
reason = "Generated backends use different subsets of these helpers"
)]
trait FloatExt {
fn floor(self) -> Self;
fn ceil(self) -> Self;
fn round_ties_even(self) -> Self;
fn fract(self) -> Self;
fn sqrt(self) -> Self;
fn trunc(self) -> Self;
}
#[cfg(all(feature = "libm", not(feature = "std")))]
impl FloatExt for f32 {
#[inline(always)]
fn floor(self) -> f32 {
libm::floorf(self)
}
#[inline(always)]
fn ceil(self) -> f32 {
libm::ceilf(self)
}
#[inline(always)]
fn round_ties_even(self) -> f32 {
libm::rintf(self)
}
#[inline(always)]
fn sqrt(self) -> f32 {
libm::sqrtf(self)
}
#[inline(always)]
fn fract(self) -> f32 {
self - self.trunc()
}
#[inline(always)]
fn trunc(self) -> f32 {
libm::truncf(self)
}
}
#[cfg(all(feature = "libm", not(feature = "std")))]
impl FloatExt for f64 {
#[inline(always)]
fn floor(self) -> f64 {
libm::floor(self)
}
#[inline(always)]
fn ceil(self) -> f64 {
libm::ceil(self)
}
#[inline(always)]
fn round_ties_even(self) -> f64 {
libm::rint(self)
}
#[inline(always)]
fn sqrt(self) -> f64 {
libm::sqrt(self)
}
#[inline(always)]
fn fract(self) -> f64 {
self - self.trunc()
}
#[inline(always)]
fn trunc(self) -> f64 {
libm::trunc(self)
}
}
#[doc = "A token for SSE2 intrinsics on `x86` and `x86_64`, representing the x86-64 baseline."]
#[doc = "# Browsing the documentation"]
#[doc = "The method list on this struct is very verbose."]
#[doc = "A better way to browse the docs is by looking at vector types such as [`u32x4`], [`f32x4`] or [`mask32x4`]."]
#[doc = "They include all the operations listed here, and also provide some additional convenience methods."]
#[derive(Clone, Copy, Debug)]
pub struct Sse2 {
_private: (),
}
impl Sse2 {
#[doc = "Create a SIMD token proving that SSE2 is available.\n\nThis is the baseline on x86-64 and i686 targets. On i586 it needs runtime detection."]
#[doc = r""]
#[doc = r" Most users should safely obtain the token from [`Level::new`] instead of calling this function."]
#[doc = r""]
#[doc = r" This function can be called without an `unsafe` block from a function"]
#[doc = r" with all the required target features enabled via the `#[target_feature]` annotation."]
#[doc = r""]
#[doc = r" # Safety"]
#[doc = r""]
#[doc = "When invoking this function through an `unsafe` block, the caller must ensure that the current CPU supports `fxsr`, `sse`, `sse2`."]
#[inline]
#[target_feature(enable = "fxsr,sse,sse2")]
pub const fn assume_supported() -> Self {
Self { _private: () }
}
}
impl Seal for Sse2 {}
impl ArchTypes for Sse2 {
type f32x4 = crate::support::Aligned128<__m128>;
type i8x16 = crate::support::Aligned128<__m128i>;
type u8x16 = crate::support::Aligned128<__m128i>;
type mask8x16 = crate::support::Aligned128<__m128i>;
type i16x8 = crate::support::Aligned128<__m128i>;
type u16x8 = crate::support::Aligned128<__m128i>;
type mask16x8 = crate::support::Aligned128<__m128i>;
type i32x4 = crate::support::Aligned128<__m128i>;
type u32x4 = crate::support::Aligned128<__m128i>;
type mask32x4 = crate::support::Aligned128<__m128i>;
type f64x2 = crate::support::Aligned128<__m128d>;
type i64x2 = crate::support::Aligned128<__m128i>;
type u64x2 = crate::support::Aligned128<__m128i>;
type mask64x2 = crate::support::Aligned128<__m128i>;
type f32x8 = crate::support::Aligned256<[__m128; 2usize]>;
type i8x32 = crate::support::Aligned256<[__m128i; 2usize]>;
type u8x32 = crate::support::Aligned256<[__m128i; 2usize]>;
type mask8x32 = crate::support::Aligned256<[__m128i; 2usize]>;
type i16x16 = crate::support::Aligned256<[__m128i; 2usize]>;
type u16x16 = crate::support::Aligned256<[__m128i; 2usize]>;
type mask16x16 = crate::support::Aligned256<[__m128i; 2usize]>;
type i32x8 = crate::support::Aligned256<[__m128i; 2usize]>;
type u32x8 = crate::support::Aligned256<[__m128i; 2usize]>;
type mask32x8 = crate::support::Aligned256<[__m128i; 2usize]>;
type f64x4 = crate::support::Aligned256<[__m128d; 2usize]>;
type i64x4 = crate::support::Aligned256<[__m128i; 2usize]>;
type u64x4 = crate::support::Aligned256<[__m128i; 2usize]>;
type mask64x4 = crate::support::Aligned256<[__m128i; 2usize]>;
type f32x16 = crate::support::Aligned512<[__m128; 4usize]>;
type i8x64 = crate::support::Aligned512<[__m128i; 4usize]>;
type u8x64 = crate::support::Aligned512<[__m128i; 4usize]>;
type mask8x64 = crate::support::Aligned512<[__m128i; 4usize]>;
type i16x32 = crate::support::Aligned512<[__m128i; 4usize]>;
type u16x32 = crate::support::Aligned512<[__m128i; 4usize]>;
type mask16x32 = crate::support::Aligned512<[__m128i; 4usize]>;
type i32x16 = crate::support::Aligned512<[__m128i; 4usize]>;
type u32x16 = crate::support::Aligned512<[__m128i; 4usize]>;
type mask32x16 = crate::support::Aligned512<[__m128i; 4usize]>;
type f64x8 = crate::support::Aligned512<[__m128d; 4usize]>;
type i64x8 = crate::support::Aligned512<[__m128i; 4usize]>;
type u64x8 = crate::support::Aligned512<[__m128i; 4usize]>;
type mask64x8 = crate::support::Aligned512<[__m128i; 4usize]>;
}
impl Simd for Sse2 {
type f32s = f32x4<Self>;
type f64s = f64x2<Self>;
type u8s = u8x16<Self>;
type i8s = i8x16<Self>;
type u16s = u16x8<Self>;
type i16s = i16x8<Self>;
type u32s = u32x4<Self>;
type i32s = i32x4<Self>;
type u64s = u64x2<Self>;
type i64s = i64x2<Self>;
type mask8s = mask8x16<Self>;
type mask16s = mask16x8<Self>;
type mask32s = mask32x4<Self>;
type mask64s = mask64x2<Self>;
#[inline(always)]
fn level(self) -> Level {
Level::Sse2(self)
}
#[inline]
fn vectorize<F: FnOnce() -> R, R>(self, f: F) -> R {
#[target_feature(enable = "fxsr,sse,sse2")]
fn vectorize_sse2<F: FnOnce() -> R, R>(f: F) -> R {
f()
}
unsafe { vectorize_sse2(f) }
}
#[inline(always)]
fn splat_f32x4(self, val: f32) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, val: f32) -> f32x4<Sse2> {
_mm_set1_ps(val).simd_into(token)
}
);
kernel(self, val)
}
#[inline(always)]
fn slide_f32x4<const SHIFT: usize>(self, a: f32x4<Self>, b: f32x4<Self>) -> f32x4<Self> {
if SHIFT >= 4usize {
return b;
}
let result = dyn_alignr_128(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 4usize,
);
Bytes::from_bytes(u8x16 {
val: crate::support::Aligned128(result),
simd: self,
})
}
#[inline(always)]
fn abs_f32x4(self, a: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>) -> f32x4<Sse2> {
_mm_andnot_ps(_mm_set1_ps(-0.0), a.into()).simd_into(token)
}
);
kernel(self, a)
}
#[inline(always)]
fn neg_f32x4(self, a: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>) -> f32x4<Sse2> {
_mm_xor_ps(a.into(), _mm_set1_ps(-0.0)).simd_into(token)
}
);
kernel(self, a)
}
#[inline(always)]
fn sqrt_f32x4(self, a: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>) -> f32x4<Sse2> {
_mm_sqrt_ps(a.into()).simd_into(token)
}
);
kernel(self, a)
}
#[inline(always)]
fn approximate_recip_f32x4(self, a: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>) -> f32x4<Sse2> {
_mm_rcp_ps(a.into()).simd_into(token)
}
);
kernel(self, a)
}
#[inline(always)]
fn add_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>, b: f32x4<Sse2>) -> f32x4<Sse2> {
_mm_add_ps(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn sub_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>, b: f32x4<Sse2>) -> f32x4<Sse2> {
_mm_sub_ps(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn mul_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>, b: f32x4<Sse2>) -> f32x4<Sse2> {
_mm_mul_ps(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn div_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>, b: f32x4<Sse2>) -> f32x4<Sse2> {
_mm_div_ps(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn copysign_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>, b: f32x4<Sse2>) -> f32x4<Sse2> {
let mask = _mm_set1_ps(-0.0);
_mm_or_ps(_mm_and_ps(mask, b.into()), _mm_andnot_ps(mask, a.into()))
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn max_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>, b: f32x4<Sse2>) -> f32x4<Sse2> {
_mm_max_ps(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn min_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>, b: f32x4<Sse2>) -> f32x4<Sse2> {
_mm_min_ps(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn max_precise_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>, b: f32x4<Sse2>) -> f32x4<Sse2> {
let a = a.into();
let b = b.into();
let intermediate = _mm_max_ps(a, b);
let b_is_nan = _mm_cmpunord_ps(b, b);
_mm_or_ps(
_mm_and_ps(b_is_nan, a),
_mm_andnot_ps(b_is_nan, intermediate),
)
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn min_precise_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>, b: f32x4<Sse2>) -> f32x4<Sse2> {
let a = a.into();
let b = b.into();
let intermediate = _mm_min_ps(a, b);
let b_is_nan = _mm_cmpunord_ps(b, b);
_mm_or_ps(
_mm_and_ps(b_is_nan, a),
_mm_andnot_ps(b_is_nan, intermediate),
)
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_eq_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> mask32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>, b: f32x4<Sse2>) -> mask32x4<Sse2> {
_mm_castps_si128(_mm_cmpeq_ps(a.into(), b.into())).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_lt_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> mask32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>, b: f32x4<Sse2>) -> mask32x4<Sse2> {
_mm_castps_si128(_mm_cmplt_ps(a.into(), b.into())).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_le_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> mask32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>, b: f32x4<Sse2>) -> mask32x4<Sse2> {
_mm_castps_si128(_mm_cmple_ps(a.into(), b.into())).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_low_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>, b: f32x4<Sse2>) -> f32x4<Sse2> {
_mm_unpacklo_ps(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_high_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>, b: f32x4<Sse2>) -> f32x4<Sse2> {
_mm_unpackhi_ps(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn unzip_low_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>, b: f32x4<Sse2>) -> f32x4<Sse2> {
_mm_shuffle_ps::<0b10_00_10_00>(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn unzip_high_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>, b: f32x4<Sse2>) -> f32x4<Sse2> {
_mm_shuffle_ps::<0b11_01_11_01>(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn interleave_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> (f32x4<Self>, f32x4<Self>) {
(self.zip_low_f32x4(a, b), self.zip_high_f32x4(a, b))
}
#[inline(always)]
fn deinterleave_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> (f32x4<Self>, f32x4<Self>) {
(self.unzip_low_f32x4(a, b), self.unzip_high_f32x4(a, b))
}
#[inline(always)]
fn mul_add_f32x4(self, a: f32x4<Self>, b: f32x4<Self>, c: f32x4<Self>) -> f32x4<Self> {
a * b + c
}
#[inline(always)]
fn mul_sub_f32x4(self, a: f32x4<Self>, b: f32x4<Self>, c: f32x4<Self>) -> f32x4<Self> {
a * b - c
}
#[inline(always)]
fn floor_f32x4(self, a: f32x4<Self>) -> f32x4<Self> {
[
f32::floor(a[0usize]),
f32::floor(a[1usize]),
f32::floor(a[2usize]),
f32::floor(a[3usize]),
]
.simd_into(self)
}
#[inline(always)]
fn ceil_f32x4(self, a: f32x4<Self>) -> f32x4<Self> {
[
f32::ceil(a[0usize]),
f32::ceil(a[1usize]),
f32::ceil(a[2usize]),
f32::ceil(a[3usize]),
]
.simd_into(self)
}
#[inline(always)]
fn round_ties_even_f32x4(self, a: f32x4<Self>) -> f32x4<Self> {
[
f32::round_ties_even(a[0usize]),
f32::round_ties_even(a[1usize]),
f32::round_ties_even(a[2usize]),
f32::round_ties_even(a[3usize]),
]
.simd_into(self)
}
#[inline(always)]
fn fract_f32x4(self, a: f32x4<Self>) -> f32x4<Self> {
a - self.trunc_f32x4(a)
}
#[inline(always)]
fn trunc_f32x4(self, a: f32x4<Self>) -> f32x4<Self> {
[
f32::trunc(a[0usize]),
f32::trunc(a[1usize]),
f32::trunc(a[2usize]),
f32::trunc(a[3usize]),
]
.simd_into(self)
}
#[inline(always)]
fn select_f32x4(self, a: mask32x4<Self>, b: f32x4<Self>, c: f32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
a: mask32x4<Sse2>,
b: f32x4<Sse2>,
c: f32x4<Sse2>,
) -> f32x4<Sse2> {
_mm_or_ps(
_mm_and_ps(_mm_castsi128_ps(a.into()), b.into()),
_mm_andnot_ps(_mm_castsi128_ps(a.into()), c.into()),
)
.simd_into(token)
}
);
kernel(self, a, b, c)
}
#[inline(always)]
fn combine_f32x4(self, a: f32x4<Self>, b: f32x4<Self>) -> f32x8<Self> {
f32x8 {
val: crate::support::Aligned256([a.val.0, b.val.0]),
simd: self,
}
}
#[inline(always)]
fn load_four_interleaved_f32x4(self, src: &[f32; 16usize]) -> [f32x4<Self>; 4usize] {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, src: &[f32; 16usize]) -> [f32x4<Sse2>; 4usize] {
let (chunks, []) = src.as_chunks::<4usize>() else {
unreachable!()
};
let v0: __m128 =
crate::transmute::checked_transmute_copy::<[f32; 4usize], __m128>(&chunks[0]);
let v1: __m128 =
crate::transmute::checked_transmute_copy::<[f32; 4usize], __m128>(&chunks[1]);
let v2: __m128 =
crate::transmute::checked_transmute_copy::<[f32; 4usize], __m128>(&chunks[2]);
let v3: __m128 =
crate::transmute::checked_transmute_copy::<[f32; 4usize], __m128>(&chunks[3]);
let tmp0 = _mm_unpacklo_ps(v0, v1);
let tmp1 = _mm_unpackhi_ps(v0, v1);
let tmp2 = _mm_unpacklo_ps(v2, v3);
let tmp3 = _mm_unpackhi_ps(v2, v3);
let out0 = _mm_castpd_ps(_mm_unpacklo_pd(_mm_castps_pd(tmp0), _mm_castps_pd(tmp2)));
let out1 = _mm_castpd_ps(_mm_unpackhi_pd(_mm_castps_pd(tmp0), _mm_castps_pd(tmp2)));
let out2 = _mm_castpd_ps(_mm_unpacklo_pd(_mm_castps_pd(tmp1), _mm_castps_pd(tmp3)));
let out3 = _mm_castpd_ps(_mm_unpackhi_pd(_mm_castps_pd(tmp1), _mm_castps_pd(tmp3)));
[
out0.simd_into(token),
out1.simd_into(token),
out2.simd_into(token),
out3.simd_into(token),
]
}
);
kernel(self, src)
}
#[inline(always)]
fn store_four_interleaved_f32x4(
self,
vectors: [f32x4<Self>; 4usize],
dest: &mut [f32; 16usize],
) -> () {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
vectors: [f32x4<Sse2>; 4usize],
dest: &mut [f32; 16usize],
) -> () {
let _ = token;
let v0: __m128 = vectors[0].into();
let v1: __m128 = vectors[1].into();
let v2: __m128 = vectors[2].into();
let v3: __m128 = vectors[3].into();
let tmp0 = _mm_unpacklo_ps(v0, v1);
let tmp1 = _mm_unpackhi_ps(v0, v1);
let tmp2 = _mm_unpacklo_ps(v2, v3);
let tmp3 = _mm_unpackhi_ps(v2, v3);
let out0 = _mm_castpd_ps(_mm_unpacklo_pd(_mm_castps_pd(tmp0), _mm_castps_pd(tmp2)));
let out1 = _mm_castpd_ps(_mm_unpackhi_pd(_mm_castps_pd(tmp0), _mm_castps_pd(tmp2)));
let out2 = _mm_castpd_ps(_mm_unpacklo_pd(_mm_castps_pd(tmp1), _mm_castps_pd(tmp3)));
let out3 = _mm_castpd_ps(_mm_unpackhi_pd(_mm_castps_pd(tmp1), _mm_castps_pd(tmp3)));
let (chunks, []) = dest.as_chunks_mut::<4usize>() else {
unreachable!()
};
crate::transmute::checked_transmute_store::<__m128, [f32; 4usize]>(
out0,
&mut chunks[0],
);
crate::transmute::checked_transmute_store::<__m128, [f32; 4usize]>(
out1,
&mut chunks[1],
);
crate::transmute::checked_transmute_store::<__m128, [f32; 4usize]>(
out2,
&mut chunks[2],
);
crate::transmute::checked_transmute_store::<__m128, [f32; 4usize]>(
out3,
&mut chunks[3],
);
}
);
kernel(self, vectors, dest);
}
#[inline(always)]
fn widen_f32x4(self, a: f32x4<Self>) -> (f64x2<Self>, f64x2<Self>) {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>) -> (f64x2<Sse2>, f64x2<Sse2>) {
let raw = a.into();
(
_mm_cvtps_pd(raw).simd_into(token),
_mm_cvtps_pd(_mm_movehl_ps(raw, raw)).simd_into(token),
)
}
);
kernel(self, a)
}
#[inline(always)]
fn cvt_u32_f32x4(self, a: f32x4<Self>) -> u32x4<Self> {
[
a[0usize] as u32,
a[1usize] as u32,
a[2usize] as u32,
a[3usize] as u32,
]
.simd_into(self)
}
#[inline(always)]
fn cvt_u32_precise_f32x4(self, a: f32x4<Self>) -> u32x4<Self> {
[
a[0usize] as u32,
a[1usize] as u32,
a[2usize] as u32,
a[3usize] as u32,
]
.simd_into(self)
}
#[inline(always)]
fn cvt_i32_f32x4(self, a: f32x4<Self>) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f32x4<Sse2>) -> i32x4<Sse2> {
_mm_cvttps_epi32(a.into()).simd_into(token)
}
);
kernel(self, a)
}
#[inline(always)]
fn cvt_i32_precise_f32x4(self, a: f32x4<Self>) -> i32x4<Self> {
[
a[0usize] as i32,
a[1usize] as i32,
a[2usize] as i32,
a[3usize] as i32,
]
.simd_into(self)
}
#[inline(always)]
fn splat_i8x16(self, val: i8) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, val: i8) -> i8x16<Sse2> {
_mm_set1_epi8(val).simd_into(token)
}
);
kernel(self, val)
}
#[inline(always)]
fn slide_i8x16<const SHIFT: usize>(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
if SHIFT >= 16usize {
return b;
}
let result = dyn_alignr_128(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT,
);
Bytes::from_bytes(u8x16 {
val: crate::support::Aligned128(result),
simd: self,
})
}
#[inline(always)]
fn add_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>, b: i8x16<Sse2>) -> i8x16<Sse2> {
_mm_add_epi8(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn sub_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>, b: i8x16<Sse2>) -> i8x16<Sse2> {
_mm_sub_epi8(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn mul_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>, b: i8x16<Sse2>) -> i8x16<Sse2> {
let dst_even = _mm_mullo_epi16(a.into(), b.into());
let dst_odd =
_mm_mullo_epi16(_mm_srli_epi16::<8>(a.into()), _mm_srli_epi16::<8>(b.into()));
_mm_or_si128(
_mm_slli_epi16(dst_odd, 8),
_mm_and_si128(dst_even, _mm_set1_epi16(0xFF)),
)
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn and_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>, b: i8x16<Sse2>) -> i8x16<Sse2> {
_mm_and_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn or_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>, b: i8x16<Sse2>) -> i8x16<Sse2> {
_mm_or_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn xor_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>, b: i8x16<Sse2>) -> i8x16<Sse2> {
_mm_xor_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn not_i8x16(self, a: i8x16<Self>) -> i8x16<Self> {
a ^ !0
}
#[inline(always)]
fn shl_i8x16(self, a: i8x16<Self>, shift: u32) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>, shift: u32) -> i8x16<Sse2> {
let val = a.into();
let shift_count = _mm_cvtsi32_si128(shift.cast_signed());
let mask_byte = 0xff_u32.wrapping_shr(shift) as i8;
let byte_mask = _mm_set1_epi8(mask_byte);
_mm_sll_epi16(_mm_and_si128(val, byte_mask), shift_count).simd_into(token)
}
);
kernel(self, a, shift)
}
#[inline(always)]
fn shlv_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
[
i8::wrapping_shl(a[0usize], b[0usize] as u32),
i8::wrapping_shl(a[1usize], b[1usize] as u32),
i8::wrapping_shl(a[2usize], b[2usize] as u32),
i8::wrapping_shl(a[3usize], b[3usize] as u32),
i8::wrapping_shl(a[4usize], b[4usize] as u32),
i8::wrapping_shl(a[5usize], b[5usize] as u32),
i8::wrapping_shl(a[6usize], b[6usize] as u32),
i8::wrapping_shl(a[7usize], b[7usize] as u32),
i8::wrapping_shl(a[8usize], b[8usize] as u32),
i8::wrapping_shl(a[9usize], b[9usize] as u32),
i8::wrapping_shl(a[10usize], b[10usize] as u32),
i8::wrapping_shl(a[11usize], b[11usize] as u32),
i8::wrapping_shl(a[12usize], b[12usize] as u32),
i8::wrapping_shl(a[13usize], b[13usize] as u32),
i8::wrapping_shl(a[14usize], b[14usize] as u32),
i8::wrapping_shl(a[15usize], b[15usize] as u32),
]
.simd_into(self)
}
#[inline(always)]
fn shr_i8x16(self, a: i8x16<Self>, shift: u32) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>, shift: u32) -> i8x16<Sse2> {
let val = a.into();
let shift_count = _mm_cvtsi32_si128(shift.cast_signed());
let mask_byte = 0xff_u32.wrapping_shr(shift) as i8;
let byte_mask = _mm_set1_epi8(mask_byte);
let shifted = _mm_srl_epi16(val, shift_count);
let result = {
let sign = _mm_cmpgt_epi8(_mm_setzero_si128(), val);
_mm_or_si128(
_mm_and_si128(shifted, byte_mask),
_mm_andnot_si128(byte_mask, sign),
)
};
result.simd_into(token)
}
);
kernel(self, a, shift)
}
#[inline(always)]
fn shrv_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
[
i8::wrapping_shr(a[0usize], b[0usize] as u32),
i8::wrapping_shr(a[1usize], b[1usize] as u32),
i8::wrapping_shr(a[2usize], b[2usize] as u32),
i8::wrapping_shr(a[3usize], b[3usize] as u32),
i8::wrapping_shr(a[4usize], b[4usize] as u32),
i8::wrapping_shr(a[5usize], b[5usize] as u32),
i8::wrapping_shr(a[6usize], b[6usize] as u32),
i8::wrapping_shr(a[7usize], b[7usize] as u32),
i8::wrapping_shr(a[8usize], b[8usize] as u32),
i8::wrapping_shr(a[9usize], b[9usize] as u32),
i8::wrapping_shr(a[10usize], b[10usize] as u32),
i8::wrapping_shr(a[11usize], b[11usize] as u32),
i8::wrapping_shr(a[12usize], b[12usize] as u32),
i8::wrapping_shr(a[13usize], b[13usize] as u32),
i8::wrapping_shr(a[14usize], b[14usize] as u32),
i8::wrapping_shr(a[15usize], b[15usize] as u32),
]
.simd_into(self)
}
#[inline(always)]
fn max_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>, b: i8x16<Sse2>) -> i8x16<Sse2> {
{
let a = a.into();
let b = b.into();
let gt = _mm_cmpgt_epi8(a, b);
_mm_or_si128(_mm_and_si128(gt, a), _mm_andnot_si128(gt, b))
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn min_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>, b: i8x16<Sse2>) -> i8x16<Sse2> {
{
let a = a.into();
let b = b.into();
let gt = _mm_cmpgt_epi8(a, b);
_mm_or_si128(_mm_and_si128(gt, b), _mm_andnot_si128(gt, a))
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_eq_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> mask8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>, b: i8x16<Sse2>) -> mask8x16<Sse2> {
_mm_cmpeq_epi8(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_lt_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> mask8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>, b: i8x16<Sse2>) -> mask8x16<Sse2> {
_mm_cmpgt_epi8(b.into(), a.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_le_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> mask8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>, b: i8x16<Sse2>) -> mask8x16<Sse2> {
{
let all_ones = _mm_set1_epi8(-1);
_mm_xor_si128(_mm_cmpgt_epi8(a.into(), b.into()), all_ones)
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_low_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>, b: i8x16<Sse2>) -> i8x16<Sse2> {
_mm_unpacklo_epi8(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_high_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>, b: i8x16<Sse2>) -> i8x16<Sse2> {
_mm_unpackhi_epi8(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn unzip_low_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
[
a[0usize], a[2usize], a[4usize], a[6usize], a[8usize], a[10usize], a[12usize],
a[14usize], b[0usize], b[2usize], b[4usize], b[6usize], b[8usize], b[10usize],
b[12usize], b[14usize],
]
.simd_into(self)
}
#[inline(always)]
fn unzip_high_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
[
a[1usize], a[3usize], a[5usize], a[7usize], a[9usize], a[11usize], a[13usize],
a[15usize], b[1usize], b[3usize], b[5usize], b[7usize], b[9usize], b[11usize],
b[13usize], b[15usize],
]
.simd_into(self)
}
#[inline(always)]
fn interleave_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> (i8x16<Self>, i8x16<Self>) {
(self.zip_low_i8x16(a, b), self.zip_high_i8x16(a, b))
}
#[inline(always)]
fn deinterleave_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> (i8x16<Self>, i8x16<Self>) {
(self.unzip_low_i8x16(a, b), self.unzip_high_i8x16(a, b))
}
#[inline(always)]
fn select_i8x16(self, a: mask8x16<Self>, b: i8x16<Self>, c: i8x16<Self>) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
a: mask8x16<Sse2>,
b: i8x16<Sse2>,
c: i8x16<Sse2>,
) -> i8x16<Sse2> {
_mm_or_si128(
_mm_and_si128(a.into(), b.into()),
_mm_andnot_si128(a.into(), c.into()),
)
.simd_into(token)
}
);
kernel(self, a, b, c)
}
#[inline(always)]
fn combine_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x32<Self> {
i8x32 {
val: crate::support::Aligned256([a.val.0, b.val.0]),
simd: self,
}
}
#[inline(always)]
fn neg_i8x16(self, a: i8x16<Self>) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>) -> i8x16<Sse2> {
_mm_sub_epi8(_mm_setzero_si128(), a.into()).simd_into(token)
}
);
kernel(self, a)
}
#[inline(always)]
fn load_four_interleaved_i8x16(self, src: &[i8; 64usize]) -> [i8x16<Self>; 4usize] {
[
[
src[0usize],
src[4usize],
src[8usize],
src[12usize],
src[16usize],
src[20usize],
src[24usize],
src[28usize],
src[32usize],
src[36usize],
src[40usize],
src[44usize],
src[48usize],
src[52usize],
src[56usize],
src[60usize],
]
.simd_into(self),
[
src[1usize],
src[5usize],
src[9usize],
src[13usize],
src[17usize],
src[21usize],
src[25usize],
src[29usize],
src[33usize],
src[37usize],
src[41usize],
src[45usize],
src[49usize],
src[53usize],
src[57usize],
src[61usize],
]
.simd_into(self),
[
src[2usize],
src[6usize],
src[10usize],
src[14usize],
src[18usize],
src[22usize],
src[26usize],
src[30usize],
src[34usize],
src[38usize],
src[42usize],
src[46usize],
src[50usize],
src[54usize],
src[58usize],
src[62usize],
]
.simd_into(self),
[
src[3usize],
src[7usize],
src[11usize],
src[15usize],
src[19usize],
src[23usize],
src[27usize],
src[31usize],
src[35usize],
src[39usize],
src[43usize],
src[47usize],
src[51usize],
src[55usize],
src[59usize],
src[63usize],
]
.simd_into(self),
]
}
#[inline(always)]
fn store_four_interleaved_i8x16(
self,
vectors: [i8x16<Self>; 4usize],
dest: &mut [i8; 64usize],
) -> () {
*dest = [
vectors[0usize][0usize],
vectors[1usize][0usize],
vectors[2usize][0usize],
vectors[3usize][0usize],
vectors[0usize][1usize],
vectors[1usize][1usize],
vectors[2usize][1usize],
vectors[3usize][1usize],
vectors[0usize][2usize],
vectors[1usize][2usize],
vectors[2usize][2usize],
vectors[3usize][2usize],
vectors[0usize][3usize],
vectors[1usize][3usize],
vectors[2usize][3usize],
vectors[3usize][3usize],
vectors[0usize][4usize],
vectors[1usize][4usize],
vectors[2usize][4usize],
vectors[3usize][4usize],
vectors[0usize][5usize],
vectors[1usize][5usize],
vectors[2usize][5usize],
vectors[3usize][5usize],
vectors[0usize][6usize],
vectors[1usize][6usize],
vectors[2usize][6usize],
vectors[3usize][6usize],
vectors[0usize][7usize],
vectors[1usize][7usize],
vectors[2usize][7usize],
vectors[3usize][7usize],
vectors[0usize][8usize],
vectors[1usize][8usize],
vectors[2usize][8usize],
vectors[3usize][8usize],
vectors[0usize][9usize],
vectors[1usize][9usize],
vectors[2usize][9usize],
vectors[3usize][9usize],
vectors[0usize][10usize],
vectors[1usize][10usize],
vectors[2usize][10usize],
vectors[3usize][10usize],
vectors[0usize][11usize],
vectors[1usize][11usize],
vectors[2usize][11usize],
vectors[3usize][11usize],
vectors[0usize][12usize],
vectors[1usize][12usize],
vectors[2usize][12usize],
vectors[3usize][12usize],
vectors[0usize][13usize],
vectors[1usize][13usize],
vectors[2usize][13usize],
vectors[3usize][13usize],
vectors[0usize][14usize],
vectors[1usize][14usize],
vectors[2usize][14usize],
vectors[3usize][14usize],
vectors[0usize][15usize],
vectors[1usize][15usize],
vectors[2usize][15usize],
vectors[3usize][15usize],
];
}
#[inline(always)]
fn widen_i8x16(self, a: i8x16<Self>) -> (i16x8<Self>, i16x8<Self>) {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i8x16<Sse2>) -> (i16x8<Sse2>, i16x8<Sse2>) {
let raw = a.into();
let sign = _mm_cmpgt_epi8(_mm_setzero_si128(), raw);
(
_mm_unpacklo_epi8(raw, sign).simd_into(token),
_mm_unpackhi_epi8(raw, sign).simd_into(token),
)
}
);
kernel(self, a)
}
#[inline(always)]
fn splat_u8x16(self, val: u8) -> u8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, val: u8) -> u8x16<Sse2> {
_mm_set1_epi8(val.cast_signed()).simd_into(token)
}
);
kernel(self, val)
}
#[inline(always)]
fn slide_u8x16<const SHIFT: usize>(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
if SHIFT >= 16usize {
return b;
}
let result = dyn_alignr_128(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT,
);
Bytes::from_bytes(u8x16 {
val: crate::support::Aligned128(result),
simd: self,
})
}
#[inline(always)]
fn swizzle_dyn_within_blocks_u8x16(self, a: u8x16<Self>, indices: u8x16<Self>) -> u8x16<Self> {
let bytes = Bytes::to_bytes(a);
let result: u8x16<Self> = [
{
let index = indices[0usize] as usize;
bytes[index % 16usize]
},
{
let index = indices[1usize] as usize;
bytes[index % 16usize]
},
{
let index = indices[2usize] as usize;
bytes[index % 16usize]
},
{
let index = indices[3usize] as usize;
bytes[index % 16usize]
},
{
let index = indices[4usize] as usize;
bytes[index % 16usize]
},
{
let index = indices[5usize] as usize;
bytes[index % 16usize]
},
{
let index = indices[6usize] as usize;
bytes[index % 16usize]
},
{
let index = indices[7usize] as usize;
bytes[index % 16usize]
},
{
let index = indices[8usize] as usize;
bytes[index % 16usize]
},
{
let index = indices[9usize] as usize;
bytes[index % 16usize]
},
{
let index = indices[10usize] as usize;
bytes[index % 16usize]
},
{
let index = indices[11usize] as usize;
bytes[index % 16usize]
},
{
let index = indices[12usize] as usize;
bytes[index % 16usize]
},
{
let index = indices[13usize] as usize;
bytes[index % 16usize]
},
{
let index = indices[14usize] as usize;
bytes[index % 16usize]
},
{
let index = indices[15usize] as usize;
bytes[index % 16usize]
},
]
.simd_into(self);
Bytes::from_bytes(result)
}
#[inline(always)]
fn swizzle_dyn_u8x16(self, a: u8x16<Self>, indices: u8x16<Self>) -> u8x16<Self> {
let bytes = Bytes::to_bytes(a);
let mut output = [0u8; 16usize];
for lane in 0..16usize {
let index = indices[lane] as usize;
output[lane] = bytes[index % 16usize];
}
let result: u8x16<Self> = output.simd_into(self);
Bytes::from_bytes(result)
}
#[inline(always)]
fn swizzle_dyn_precise_u8x16(self, a: u8x16<Self>, indices: u8x16<Self>) -> u8x16<Self> {
let bytes = Bytes::to_bytes(a);
let mut output = [0u8; 16usize];
for lane in 0..16usize {
let index = indices[lane] as usize;
let value = bytes[index % 16usize];
output[lane] = if index < 16usize { value } else { 0 };
}
let result: u8x16<Self> = output.simd_into(self);
Bytes::from_bytes(result)
}
#[inline(always)]
fn add_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u8x16<Sse2>, b: u8x16<Sse2>) -> u8x16<Sse2> {
_mm_add_epi8(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn sub_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u8x16<Sse2>, b: u8x16<Sse2>) -> u8x16<Sse2> {
_mm_sub_epi8(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn mul_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u8x16<Sse2>, b: u8x16<Sse2>) -> u8x16<Sse2> {
let dst_even = _mm_mullo_epi16(a.into(), b.into());
let dst_odd =
_mm_mullo_epi16(_mm_srli_epi16::<8>(a.into()), _mm_srli_epi16::<8>(b.into()));
_mm_or_si128(
_mm_slli_epi16(dst_odd, 8),
_mm_and_si128(dst_even, _mm_set1_epi16(0xFF)),
)
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn and_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u8x16<Sse2>, b: u8x16<Sse2>) -> u8x16<Sse2> {
_mm_and_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn or_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u8x16<Sse2>, b: u8x16<Sse2>) -> u8x16<Sse2> {
_mm_or_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn xor_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u8x16<Sse2>, b: u8x16<Sse2>) -> u8x16<Sse2> {
_mm_xor_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn not_u8x16(self, a: u8x16<Self>) -> u8x16<Self> {
a ^ !0
}
#[inline(always)]
fn shl_u8x16(self, a: u8x16<Self>, shift: u32) -> u8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u8x16<Sse2>, shift: u32) -> u8x16<Sse2> {
let val = a.into();
let shift_count = _mm_cvtsi32_si128(shift.cast_signed());
let mask_byte = 0xff_u32.wrapping_shr(shift) as i8;
let byte_mask = _mm_set1_epi8(mask_byte);
_mm_sll_epi16(_mm_and_si128(val, byte_mask), shift_count).simd_into(token)
}
);
kernel(self, a, shift)
}
#[inline(always)]
fn shlv_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
[
u8::wrapping_shl(a[0usize], b[0usize] as u32),
u8::wrapping_shl(a[1usize], b[1usize] as u32),
u8::wrapping_shl(a[2usize], b[2usize] as u32),
u8::wrapping_shl(a[3usize], b[3usize] as u32),
u8::wrapping_shl(a[4usize], b[4usize] as u32),
u8::wrapping_shl(a[5usize], b[5usize] as u32),
u8::wrapping_shl(a[6usize], b[6usize] as u32),
u8::wrapping_shl(a[7usize], b[7usize] as u32),
u8::wrapping_shl(a[8usize], b[8usize] as u32),
u8::wrapping_shl(a[9usize], b[9usize] as u32),
u8::wrapping_shl(a[10usize], b[10usize] as u32),
u8::wrapping_shl(a[11usize], b[11usize] as u32),
u8::wrapping_shl(a[12usize], b[12usize] as u32),
u8::wrapping_shl(a[13usize], b[13usize] as u32),
u8::wrapping_shl(a[14usize], b[14usize] as u32),
u8::wrapping_shl(a[15usize], b[15usize] as u32),
]
.simd_into(self)
}
#[inline(always)]
fn shr_u8x16(self, a: u8x16<Self>, shift: u32) -> u8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u8x16<Sse2>, shift: u32) -> u8x16<Sse2> {
let val = a.into();
let shift_count = _mm_cvtsi32_si128(shift.cast_signed());
let mask_byte = 0xff_u32.wrapping_shr(shift) as i8;
let byte_mask = _mm_set1_epi8(mask_byte);
let shifted = _mm_srl_epi16(val, shift_count);
let result = { _mm_and_si128(shifted, byte_mask) };
result.simd_into(token)
}
);
kernel(self, a, shift)
}
#[inline(always)]
fn shrv_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
[
u8::wrapping_shr(a[0usize], b[0usize] as u32),
u8::wrapping_shr(a[1usize], b[1usize] as u32),
u8::wrapping_shr(a[2usize], b[2usize] as u32),
u8::wrapping_shr(a[3usize], b[3usize] as u32),
u8::wrapping_shr(a[4usize], b[4usize] as u32),
u8::wrapping_shr(a[5usize], b[5usize] as u32),
u8::wrapping_shr(a[6usize], b[6usize] as u32),
u8::wrapping_shr(a[7usize], b[7usize] as u32),
u8::wrapping_shr(a[8usize], b[8usize] as u32),
u8::wrapping_shr(a[9usize], b[9usize] as u32),
u8::wrapping_shr(a[10usize], b[10usize] as u32),
u8::wrapping_shr(a[11usize], b[11usize] as u32),
u8::wrapping_shr(a[12usize], b[12usize] as u32),
u8::wrapping_shr(a[13usize], b[13usize] as u32),
u8::wrapping_shr(a[14usize], b[14usize] as u32),
u8::wrapping_shr(a[15usize], b[15usize] as u32),
]
.simd_into(self)
}
#[inline(always)]
fn max_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u8x16<Sse2>, b: u8x16<Sse2>) -> u8x16<Sse2> {
_mm_max_epu8(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn min_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u8x16<Sse2>, b: u8x16<Sse2>) -> u8x16<Sse2> {
_mm_min_epu8(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_eq_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> mask8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u8x16<Sse2>, b: u8x16<Sse2>) -> mask8x16<Sse2> {
_mm_cmpeq_epi8(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_lt_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> mask8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u8x16<Sse2>, b: u8x16<Sse2>) -> mask8x16<Sse2> {
{
let sign_bit = _mm_set1_epi8(0x80u8.cast_signed());
let lhs_signed = _mm_xor_si128(b.into(), sign_bit);
let rhs_signed = _mm_xor_si128(a.into(), sign_bit);
_mm_cmpgt_epi8(lhs_signed, rhs_signed)
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_le_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> mask8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u8x16<Sse2>, b: u8x16<Sse2>) -> mask8x16<Sse2> {
{
let all_ones = _mm_set1_epi8(-1);
_mm_xor_si128(
{
let sign_bit = _mm_set1_epi8(0x80u8.cast_signed());
let lhs_signed = _mm_xor_si128(a.into(), sign_bit);
let rhs_signed = _mm_xor_si128(b.into(), sign_bit);
_mm_cmpgt_epi8(lhs_signed, rhs_signed)
},
all_ones,
)
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_low_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u8x16<Sse2>, b: u8x16<Sse2>) -> u8x16<Sse2> {
_mm_unpacklo_epi8(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_high_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u8x16<Sse2>, b: u8x16<Sse2>) -> u8x16<Sse2> {
_mm_unpackhi_epi8(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn unzip_low_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
[
a[0usize], a[2usize], a[4usize], a[6usize], a[8usize], a[10usize], a[12usize],
a[14usize], b[0usize], b[2usize], b[4usize], b[6usize], b[8usize], b[10usize],
b[12usize], b[14usize],
]
.simd_into(self)
}
#[inline(always)]
fn unzip_high_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
[
a[1usize], a[3usize], a[5usize], a[7usize], a[9usize], a[11usize], a[13usize],
a[15usize], b[1usize], b[3usize], b[5usize], b[7usize], b[9usize], b[11usize],
b[13usize], b[15usize],
]
.simd_into(self)
}
#[inline(always)]
fn interleave_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> (u8x16<Self>, u8x16<Self>) {
(self.zip_low_u8x16(a, b), self.zip_high_u8x16(a, b))
}
#[inline(always)]
fn deinterleave_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> (u8x16<Self>, u8x16<Self>) {
(self.unzip_low_u8x16(a, b), self.unzip_high_u8x16(a, b))
}
#[inline(always)]
fn select_u8x16(self, a: mask8x16<Self>, b: u8x16<Self>, c: u8x16<Self>) -> u8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
a: mask8x16<Sse2>,
b: u8x16<Sse2>,
c: u8x16<Sse2>,
) -> u8x16<Sse2> {
_mm_or_si128(
_mm_and_si128(a.into(), b.into()),
_mm_andnot_si128(a.into(), c.into()),
)
.simd_into(token)
}
);
kernel(self, a, b, c)
}
#[inline(always)]
fn combine_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x32<Self> {
u8x32 {
val: crate::support::Aligned256([a.val.0, b.val.0]),
simd: self,
}
}
#[inline(always)]
fn load_four_interleaved_u8x16(self, src: &[u8; 64usize]) -> [u8x16<Self>; 4usize] {
[
[
src[0usize],
src[4usize],
src[8usize],
src[12usize],
src[16usize],
src[20usize],
src[24usize],
src[28usize],
src[32usize],
src[36usize],
src[40usize],
src[44usize],
src[48usize],
src[52usize],
src[56usize],
src[60usize],
]
.simd_into(self),
[
src[1usize],
src[5usize],
src[9usize],
src[13usize],
src[17usize],
src[21usize],
src[25usize],
src[29usize],
src[33usize],
src[37usize],
src[41usize],
src[45usize],
src[49usize],
src[53usize],
src[57usize],
src[61usize],
]
.simd_into(self),
[
src[2usize],
src[6usize],
src[10usize],
src[14usize],
src[18usize],
src[22usize],
src[26usize],
src[30usize],
src[34usize],
src[38usize],
src[42usize],
src[46usize],
src[50usize],
src[54usize],
src[58usize],
src[62usize],
]
.simd_into(self),
[
src[3usize],
src[7usize],
src[11usize],
src[15usize],
src[19usize],
src[23usize],
src[27usize],
src[31usize],
src[35usize],
src[39usize],
src[43usize],
src[47usize],
src[51usize],
src[55usize],
src[59usize],
src[63usize],
]
.simd_into(self),
]
}
#[inline(always)]
fn store_four_interleaved_u8x16(
self,
vectors: [u8x16<Self>; 4usize],
dest: &mut [u8; 64usize],
) -> () {
*dest = [
vectors[0usize][0usize],
vectors[1usize][0usize],
vectors[2usize][0usize],
vectors[3usize][0usize],
vectors[0usize][1usize],
vectors[1usize][1usize],
vectors[2usize][1usize],
vectors[3usize][1usize],
vectors[0usize][2usize],
vectors[1usize][2usize],
vectors[2usize][2usize],
vectors[3usize][2usize],
vectors[0usize][3usize],
vectors[1usize][3usize],
vectors[2usize][3usize],
vectors[3usize][3usize],
vectors[0usize][4usize],
vectors[1usize][4usize],
vectors[2usize][4usize],
vectors[3usize][4usize],
vectors[0usize][5usize],
vectors[1usize][5usize],
vectors[2usize][5usize],
vectors[3usize][5usize],
vectors[0usize][6usize],
vectors[1usize][6usize],
vectors[2usize][6usize],
vectors[3usize][6usize],
vectors[0usize][7usize],
vectors[1usize][7usize],
vectors[2usize][7usize],
vectors[3usize][7usize],
vectors[0usize][8usize],
vectors[1usize][8usize],
vectors[2usize][8usize],
vectors[3usize][8usize],
vectors[0usize][9usize],
vectors[1usize][9usize],
vectors[2usize][9usize],
vectors[3usize][9usize],
vectors[0usize][10usize],
vectors[1usize][10usize],
vectors[2usize][10usize],
vectors[3usize][10usize],
vectors[0usize][11usize],
vectors[1usize][11usize],
vectors[2usize][11usize],
vectors[3usize][11usize],
vectors[0usize][12usize],
vectors[1usize][12usize],
vectors[2usize][12usize],
vectors[3usize][12usize],
vectors[0usize][13usize],
vectors[1usize][13usize],
vectors[2usize][13usize],
vectors[3usize][13usize],
vectors[0usize][14usize],
vectors[1usize][14usize],
vectors[2usize][14usize],
vectors[3usize][14usize],
vectors[0usize][15usize],
vectors[1usize][15usize],
vectors[2usize][15usize],
vectors[3usize][15usize],
];
}
#[inline(always)]
fn widen_u8x16(self, a: u8x16<Self>) -> (u16x8<Self>, u16x8<Self>) {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u8x16<Sse2>) -> (u16x8<Sse2>, u16x8<Sse2>) {
let raw = a.into();
let sign = _mm_setzero_si128();
(
_mm_unpacklo_epi8(raw, sign).simd_into(token),
_mm_unpackhi_epi8(raw, sign).simd_into(token),
)
}
);
kernel(self, a)
}
#[inline(always)]
fn splat_mask8x16(self, val: bool) -> mask8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, val: bool) -> mask8x16<Sse2> {
let val: i8 = if val { !0 } else { 0 };
_mm_set1_epi8(val).simd_into(token)
}
);
kernel(self, val)
}
#[inline(always)]
fn from_bitmask_mask8x16(self, bits: u64) -> mask8x16<Self> {
let lanes: [i8; 16usize] = [
if bits & 1 != 0 { !0 } else { 0 },
if (bits >> 1usize) & 1 != 0 { !0 } else { 0 },
if (bits >> 2usize) & 1 != 0 { !0 } else { 0 },
if (bits >> 3usize) & 1 != 0 { !0 } else { 0 },
if (bits >> 4usize) & 1 != 0 { !0 } else { 0 },
if (bits >> 5usize) & 1 != 0 { !0 } else { 0 },
if (bits >> 6usize) & 1 != 0 { !0 } else { 0 },
if (bits >> 7usize) & 1 != 0 { !0 } else { 0 },
if (bits >> 8usize) & 1 != 0 { !0 } else { 0 },
if (bits >> 9usize) & 1 != 0 { !0 } else { 0 },
if (bits >> 10usize) & 1 != 0 { !0 } else { 0 },
if (bits >> 11usize) & 1 != 0 { !0 } else { 0 },
if (bits >> 12usize) & 1 != 0 { !0 } else { 0 },
if (bits >> 13usize) & 1 != 0 { !0 } else { 0 },
if (bits >> 14usize) & 1 != 0 { !0 } else { 0 },
if (bits >> 15usize) & 1 != 0 { !0 } else { 0 },
];
lanes.simd_into(self)
}
#[inline(always)]
fn to_bitmask_mask8x16(self, a: mask8x16<Self>) -> u64 {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask8x16<Sse2>) -> u64 {
_mm_movemask_epi8(a.into()) as u32 as u64
}
);
kernel(self, a)
}
#[inline(always)]
fn set_mask8x16(self, a: &mut mask8x16<Self>, index: usize, value: bool) -> () {
assert!(
index < 16usize,
"mask lane index {index} is out of bounds for {} lanes",
16usize
);
let mut lanes: [i8; 16usize] = (*a).into();
lanes[index] = if value { !0 } else { 0 };
*a = lanes.simd_into(self);
}
#[inline(always)]
fn and_mask8x16(self, a: mask8x16<Self>, b: mask8x16<Self>) -> mask8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask8x16<Sse2>, b: mask8x16<Sse2>) -> mask8x16<Sse2> {
_mm_and_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn or_mask8x16(self, a: mask8x16<Self>, b: mask8x16<Self>) -> mask8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask8x16<Sse2>, b: mask8x16<Sse2>) -> mask8x16<Sse2> {
_mm_or_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn xor_mask8x16(self, a: mask8x16<Self>, b: mask8x16<Self>) -> mask8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask8x16<Sse2>, b: mask8x16<Sse2>) -> mask8x16<Sse2> {
_mm_xor_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn not_mask8x16(self, a: mask8x16<Self>) -> mask8x16<Self> {
self.xor_mask8x16(a, self.splat_mask8x16(true))
}
#[inline(always)]
fn select_mask8x16(
self,
a: mask8x16<Self>,
b: mask8x16<Self>,
c: mask8x16<Self>,
) -> mask8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
a: mask8x16<Sse2>,
b: mask8x16<Sse2>,
c: mask8x16<Sse2>,
) -> mask8x16<Sse2> {
_mm_or_si128(
_mm_and_si128(a.into(), b.into()),
_mm_andnot_si128(a.into(), c.into()),
)
.simd_into(token)
}
);
kernel(self, a, b, c)
}
#[inline(always)]
fn simd_eq_mask8x16(self, a: mask8x16<Self>, b: mask8x16<Self>) -> mask8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask8x16<Sse2>, b: mask8x16<Sse2>) -> mask8x16<Sse2> {
_mm_cmpeq_epi8(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn any_true_mask8x16(self, a: mask8x16<Self>) -> bool {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask8x16<Sse2>) -> bool {
_mm_movemask_epi8(a.into()) as u32 != 0
}
);
kernel(self, a)
}
#[inline(always)]
fn all_true_mask8x16(self, a: mask8x16<Self>) -> bool {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask8x16<Sse2>) -> bool {
_mm_movemask_epi8(a.into()) as u32 == 0xffff
}
);
kernel(self, a)
}
#[inline(always)]
fn any_false_mask8x16(self, a: mask8x16<Self>) -> bool {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask8x16<Sse2>) -> bool {
_mm_movemask_epi8(a.into()) as u32 != 0xffff
}
);
kernel(self, a)
}
#[inline(always)]
fn all_false_mask8x16(self, a: mask8x16<Self>) -> bool {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask8x16<Sse2>) -> bool {
_mm_movemask_epi8(a.into()) as u32 == 0
}
);
kernel(self, a)
}
#[inline(always)]
fn combine_mask8x16(self, a: mask8x16<Self>, b: mask8x16<Self>) -> mask8x32<Self> {
mask8x32 {
val: crate::support::Aligned256([a.val.0, b.val.0]),
simd: self,
}
}
#[inline(always)]
fn splat_i16x8(self, val: i16) -> i16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, val: i16) -> i16x8<Sse2> {
_mm_set1_epi16(val).simd_into(token)
}
);
kernel(self, val)
}
#[inline(always)]
fn slide_i16x8<const SHIFT: usize>(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
if SHIFT >= 8usize {
return b;
}
let result = dyn_alignr_128(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 2usize,
);
Bytes::from_bytes(u8x16 {
val: crate::support::Aligned128(result),
simd: self,
})
}
#[inline(always)]
fn add_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, b: i16x8<Sse2>) -> i16x8<Sse2> {
_mm_add_epi16(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn sub_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, b: i16x8<Sse2>) -> i16x8<Sse2> {
_mm_sub_epi16(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn mul_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, b: i16x8<Sse2>) -> i16x8<Sse2> {
_mm_mullo_epi16(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn and_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, b: i16x8<Sse2>) -> i16x8<Sse2> {
_mm_and_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn or_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, b: i16x8<Sse2>) -> i16x8<Sse2> {
_mm_or_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn xor_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, b: i16x8<Sse2>) -> i16x8<Sse2> {
_mm_xor_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn not_i16x8(self, a: i16x8<Self>) -> i16x8<Self> {
a ^ !0
}
#[inline(always)]
fn shl_i16x8(self, a: i16x8<Self>, shift: u32) -> i16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, shift: u32) -> i16x8<Sse2> {
_mm_sll_epi16(a.into(), _mm_cvtsi32_si128(shift.cast_signed())).simd_into(token)
}
);
kernel(self, a, shift)
}
#[inline(always)]
fn shlv_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
[
i16::wrapping_shl(a[0usize], b[0usize] as u32),
i16::wrapping_shl(a[1usize], b[1usize] as u32),
i16::wrapping_shl(a[2usize], b[2usize] as u32),
i16::wrapping_shl(a[3usize], b[3usize] as u32),
i16::wrapping_shl(a[4usize], b[4usize] as u32),
i16::wrapping_shl(a[5usize], b[5usize] as u32),
i16::wrapping_shl(a[6usize], b[6usize] as u32),
i16::wrapping_shl(a[7usize], b[7usize] as u32),
]
.simd_into(self)
}
#[inline(always)]
fn shr_i16x8(self, a: i16x8<Self>, shift: u32) -> i16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, shift: u32) -> i16x8<Sse2> {
_mm_sra_epi16(a.into(), _mm_cvtsi32_si128(shift.cast_signed())).simd_into(token)
}
);
kernel(self, a, shift)
}
#[inline(always)]
fn shrv_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
[
i16::wrapping_shr(a[0usize], b[0usize] as u32),
i16::wrapping_shr(a[1usize], b[1usize] as u32),
i16::wrapping_shr(a[2usize], b[2usize] as u32),
i16::wrapping_shr(a[3usize], b[3usize] as u32),
i16::wrapping_shr(a[4usize], b[4usize] as u32),
i16::wrapping_shr(a[5usize], b[5usize] as u32),
i16::wrapping_shr(a[6usize], b[6usize] as u32),
i16::wrapping_shr(a[7usize], b[7usize] as u32),
]
.simd_into(self)
}
#[inline(always)]
fn max_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, b: i16x8<Sse2>) -> i16x8<Sse2> {
_mm_max_epi16(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn min_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, b: i16x8<Sse2>) -> i16x8<Sse2> {
_mm_min_epi16(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_eq_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> mask16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, b: i16x8<Sse2>) -> mask16x8<Sse2> {
_mm_cmpeq_epi16(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_lt_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> mask16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, b: i16x8<Sse2>) -> mask16x8<Sse2> {
_mm_cmpgt_epi16(b.into(), a.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_le_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> mask16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, b: i16x8<Sse2>) -> mask16x8<Sse2> {
{
let all_ones = _mm_set1_epi8(-1);
_mm_xor_si128(_mm_cmpgt_epi16(a.into(), b.into()), all_ones)
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_low_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, b: i16x8<Sse2>) -> i16x8<Sse2> {
_mm_unpacklo_epi16(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_high_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, b: i16x8<Sse2>) -> i16x8<Sse2> {
_mm_unpackhi_epi16(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn unzip_low_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
[
a[0usize], a[2usize], a[4usize], a[6usize], b[0usize], b[2usize], b[4usize], b[6usize],
]
.simd_into(self)
}
#[inline(always)]
fn unzip_high_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
[
a[1usize], a[3usize], a[5usize], a[7usize], b[1usize], b[3usize], b[5usize], b[7usize],
]
.simd_into(self)
}
#[inline(always)]
fn interleave_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> (i16x8<Self>, i16x8<Self>) {
(self.zip_low_i16x8(a, b), self.zip_high_i16x8(a, b))
}
#[inline(always)]
fn deinterleave_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> (i16x8<Self>, i16x8<Self>) {
(self.unzip_low_i16x8(a, b), self.unzip_high_i16x8(a, b))
}
#[inline(always)]
fn select_i16x8(self, a: mask16x8<Self>, b: i16x8<Self>, c: i16x8<Self>) -> i16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
a: mask16x8<Sse2>,
b: i16x8<Sse2>,
c: i16x8<Sse2>,
) -> i16x8<Sse2> {
_mm_or_si128(
_mm_and_si128(a.into(), b.into()),
_mm_andnot_si128(a.into(), c.into()),
)
.simd_into(token)
}
);
kernel(self, a, b, c)
}
#[inline(always)]
fn combine_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x16<Self> {
i16x16 {
val: crate::support::Aligned256([a.val.0, b.val.0]),
simd: self,
}
}
#[inline(always)]
fn neg_i16x8(self, a: i16x8<Self>) -> i16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>) -> i16x8<Sse2> {
_mm_sub_epi16(_mm_setzero_si128(), a.into()).simd_into(token)
}
);
kernel(self, a)
}
#[inline(always)]
fn load_four_interleaved_i16x8(self, src: &[i16; 32usize]) -> [i16x8<Self>; 4usize] {
[
[
src[0usize],
src[4usize],
src[8usize],
src[12usize],
src[16usize],
src[20usize],
src[24usize],
src[28usize],
]
.simd_into(self),
[
src[1usize],
src[5usize],
src[9usize],
src[13usize],
src[17usize],
src[21usize],
src[25usize],
src[29usize],
]
.simd_into(self),
[
src[2usize],
src[6usize],
src[10usize],
src[14usize],
src[18usize],
src[22usize],
src[26usize],
src[30usize],
]
.simd_into(self),
[
src[3usize],
src[7usize],
src[11usize],
src[15usize],
src[19usize],
src[23usize],
src[27usize],
src[31usize],
]
.simd_into(self),
]
}
#[inline(always)]
fn store_four_interleaved_i16x8(
self,
vectors: [i16x8<Self>; 4usize],
dest: &mut [i16; 32usize],
) -> () {
*dest = [
vectors[0usize][0usize],
vectors[1usize][0usize],
vectors[2usize][0usize],
vectors[3usize][0usize],
vectors[0usize][1usize],
vectors[1usize][1usize],
vectors[2usize][1usize],
vectors[3usize][1usize],
vectors[0usize][2usize],
vectors[1usize][2usize],
vectors[2usize][2usize],
vectors[3usize][2usize],
vectors[0usize][3usize],
vectors[1usize][3usize],
vectors[2usize][3usize],
vectors[3usize][3usize],
vectors[0usize][4usize],
vectors[1usize][4usize],
vectors[2usize][4usize],
vectors[3usize][4usize],
vectors[0usize][5usize],
vectors[1usize][5usize],
vectors[2usize][5usize],
vectors[3usize][5usize],
vectors[0usize][6usize],
vectors[1usize][6usize],
vectors[2usize][6usize],
vectors[3usize][6usize],
vectors[0usize][7usize],
vectors[1usize][7usize],
vectors[2usize][7usize],
vectors[3usize][7usize],
];
}
#[inline(always)]
fn widen_i16x8(self, a: i16x8<Self>) -> (i32x4<Self>, i32x4<Self>) {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>) -> (i32x4<Sse2>, i32x4<Sse2>) {
let raw = a.into();
let sign = _mm_srai_epi16::<15>(raw);
(
_mm_unpacklo_epi16(raw, sign).simd_into(token),
_mm_unpackhi_epi16(raw, sign).simd_into(token),
)
}
);
kernel(self, a)
}
#[inline(always)]
fn narrow_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, b: i16x8<Sse2>) -> i8x16<Sse2> {
let mask = _mm_set1_epi16(0xff);
_mm_packus_epi16(_mm_and_si128(a.into(), mask), _mm_and_si128(b.into(), mask))
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn saturating_narrow_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i16x8<Sse2>, b: i16x8<Sse2>) -> i8x16<Sse2> {
_mm_packs_epi16(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn relaxed_narrow_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i8x16<Self> {
debug_assert!(
a.as_slice()
.iter()
.chain(b.as_slice())
.all(|&value| { value >= i8::MIN as i16 && value <= i8::MAX as i16 }),
"relaxed_narrow inputs must fit in the destination type",
);
self.saturating_narrow_i16x8(a, b)
}
#[inline(always)]
fn splat_u16x8(self, val: u16) -> u16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, val: u16) -> u16x8<Sse2> {
_mm_set1_epi16(val.cast_signed()).simd_into(token)
}
);
kernel(self, val)
}
#[inline(always)]
fn slide_u16x8<const SHIFT: usize>(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
if SHIFT >= 8usize {
return b;
}
let result = dyn_alignr_128(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 2usize,
);
Bytes::from_bytes(u8x16 {
val: crate::support::Aligned128(result),
simd: self,
})
}
#[inline(always)]
fn add_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, b: u16x8<Sse2>) -> u16x8<Sse2> {
_mm_add_epi16(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn sub_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, b: u16x8<Sse2>) -> u16x8<Sse2> {
_mm_sub_epi16(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn mul_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, b: u16x8<Sse2>) -> u16x8<Sse2> {
_mm_mullo_epi16(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn and_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, b: u16x8<Sse2>) -> u16x8<Sse2> {
_mm_and_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn or_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, b: u16x8<Sse2>) -> u16x8<Sse2> {
_mm_or_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn xor_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, b: u16x8<Sse2>) -> u16x8<Sse2> {
_mm_xor_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn not_u16x8(self, a: u16x8<Self>) -> u16x8<Self> {
a ^ !0
}
#[inline(always)]
fn shl_u16x8(self, a: u16x8<Self>, shift: u32) -> u16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, shift: u32) -> u16x8<Sse2> {
_mm_sll_epi16(a.into(), _mm_cvtsi32_si128(shift.cast_signed())).simd_into(token)
}
);
kernel(self, a, shift)
}
#[inline(always)]
fn shlv_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
[
u16::wrapping_shl(a[0usize], b[0usize] as u32),
u16::wrapping_shl(a[1usize], b[1usize] as u32),
u16::wrapping_shl(a[2usize], b[2usize] as u32),
u16::wrapping_shl(a[3usize], b[3usize] as u32),
u16::wrapping_shl(a[4usize], b[4usize] as u32),
u16::wrapping_shl(a[5usize], b[5usize] as u32),
u16::wrapping_shl(a[6usize], b[6usize] as u32),
u16::wrapping_shl(a[7usize], b[7usize] as u32),
]
.simd_into(self)
}
#[inline(always)]
fn shr_u16x8(self, a: u16x8<Self>, shift: u32) -> u16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, shift: u32) -> u16x8<Sse2> {
_mm_srl_epi16(a.into(), _mm_cvtsi32_si128(shift.cast_signed())).simd_into(token)
}
);
kernel(self, a, shift)
}
#[inline(always)]
fn shrv_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
[
u16::wrapping_shr(a[0usize], b[0usize] as u32),
u16::wrapping_shr(a[1usize], b[1usize] as u32),
u16::wrapping_shr(a[2usize], b[2usize] as u32),
u16::wrapping_shr(a[3usize], b[3usize] as u32),
u16::wrapping_shr(a[4usize], b[4usize] as u32),
u16::wrapping_shr(a[5usize], b[5usize] as u32),
u16::wrapping_shr(a[6usize], b[6usize] as u32),
u16::wrapping_shr(a[7usize], b[7usize] as u32),
]
.simd_into(self)
}
#[inline(always)]
fn max_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, b: u16x8<Sse2>) -> u16x8<Sse2> {
{
let a = a.into();
let b = b.into();
let gt = {
let sign_bit = _mm_set1_epi16(0x8000u16.cast_signed());
let lhs_signed = _mm_xor_si128(a, sign_bit);
let rhs_signed = _mm_xor_si128(b, sign_bit);
_mm_cmpgt_epi16(lhs_signed, rhs_signed)
};
_mm_or_si128(_mm_and_si128(gt, a), _mm_andnot_si128(gt, b))
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn min_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, b: u16x8<Sse2>) -> u16x8<Sse2> {
{
let a = a.into();
let b = b.into();
let gt = {
let sign_bit = _mm_set1_epi16(0x8000u16.cast_signed());
let lhs_signed = _mm_xor_si128(a, sign_bit);
let rhs_signed = _mm_xor_si128(b, sign_bit);
_mm_cmpgt_epi16(lhs_signed, rhs_signed)
};
_mm_or_si128(_mm_and_si128(gt, b), _mm_andnot_si128(gt, a))
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_eq_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> mask16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, b: u16x8<Sse2>) -> mask16x8<Sse2> {
_mm_cmpeq_epi16(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_lt_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> mask16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, b: u16x8<Sse2>) -> mask16x8<Sse2> {
{
let sign_bit = _mm_set1_epi16(0x8000u16.cast_signed());
let lhs_signed = _mm_xor_si128(b.into(), sign_bit);
let rhs_signed = _mm_xor_si128(a.into(), sign_bit);
_mm_cmpgt_epi16(lhs_signed, rhs_signed)
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_le_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> mask16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, b: u16x8<Sse2>) -> mask16x8<Sse2> {
{
let all_ones = _mm_set1_epi8(-1);
_mm_xor_si128(
{
let sign_bit = _mm_set1_epi16(0x8000u16.cast_signed());
let lhs_signed = _mm_xor_si128(a.into(), sign_bit);
let rhs_signed = _mm_xor_si128(b.into(), sign_bit);
_mm_cmpgt_epi16(lhs_signed, rhs_signed)
},
all_ones,
)
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_low_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, b: u16x8<Sse2>) -> u16x8<Sse2> {
_mm_unpacklo_epi16(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_high_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, b: u16x8<Sse2>) -> u16x8<Sse2> {
_mm_unpackhi_epi16(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn unzip_low_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
[
a[0usize], a[2usize], a[4usize], a[6usize], b[0usize], b[2usize], b[4usize], b[6usize],
]
.simd_into(self)
}
#[inline(always)]
fn unzip_high_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
[
a[1usize], a[3usize], a[5usize], a[7usize], b[1usize], b[3usize], b[5usize], b[7usize],
]
.simd_into(self)
}
#[inline(always)]
fn interleave_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> (u16x8<Self>, u16x8<Self>) {
(self.zip_low_u16x8(a, b), self.zip_high_u16x8(a, b))
}
#[inline(always)]
fn deinterleave_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> (u16x8<Self>, u16x8<Self>) {
(self.unzip_low_u16x8(a, b), self.unzip_high_u16x8(a, b))
}
#[inline(always)]
fn select_u16x8(self, a: mask16x8<Self>, b: u16x8<Self>, c: u16x8<Self>) -> u16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
a: mask16x8<Sse2>,
b: u16x8<Sse2>,
c: u16x8<Sse2>,
) -> u16x8<Sse2> {
_mm_or_si128(
_mm_and_si128(a.into(), b.into()),
_mm_andnot_si128(a.into(), c.into()),
)
.simd_into(token)
}
);
kernel(self, a, b, c)
}
#[inline(always)]
fn combine_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x16<Self> {
u16x16 {
val: crate::support::Aligned256([a.val.0, b.val.0]),
simd: self,
}
}
#[inline(always)]
fn load_four_interleaved_u16x8(self, src: &[u16; 32usize]) -> [u16x8<Self>; 4usize] {
[
[
src[0usize],
src[4usize],
src[8usize],
src[12usize],
src[16usize],
src[20usize],
src[24usize],
src[28usize],
]
.simd_into(self),
[
src[1usize],
src[5usize],
src[9usize],
src[13usize],
src[17usize],
src[21usize],
src[25usize],
src[29usize],
]
.simd_into(self),
[
src[2usize],
src[6usize],
src[10usize],
src[14usize],
src[18usize],
src[22usize],
src[26usize],
src[30usize],
]
.simd_into(self),
[
src[3usize],
src[7usize],
src[11usize],
src[15usize],
src[19usize],
src[23usize],
src[27usize],
src[31usize],
]
.simd_into(self),
]
}
#[inline(always)]
fn store_four_interleaved_u16x8(
self,
vectors: [u16x8<Self>; 4usize],
dest: &mut [u16; 32usize],
) -> () {
*dest = [
vectors[0usize][0usize],
vectors[1usize][0usize],
vectors[2usize][0usize],
vectors[3usize][0usize],
vectors[0usize][1usize],
vectors[1usize][1usize],
vectors[2usize][1usize],
vectors[3usize][1usize],
vectors[0usize][2usize],
vectors[1usize][2usize],
vectors[2usize][2usize],
vectors[3usize][2usize],
vectors[0usize][3usize],
vectors[1usize][3usize],
vectors[2usize][3usize],
vectors[3usize][3usize],
vectors[0usize][4usize],
vectors[1usize][4usize],
vectors[2usize][4usize],
vectors[3usize][4usize],
vectors[0usize][5usize],
vectors[1usize][5usize],
vectors[2usize][5usize],
vectors[3usize][5usize],
vectors[0usize][6usize],
vectors[1usize][6usize],
vectors[2usize][6usize],
vectors[3usize][6usize],
vectors[0usize][7usize],
vectors[1usize][7usize],
vectors[2usize][7usize],
vectors[3usize][7usize],
];
}
#[inline(always)]
fn widen_u16x8(self, a: u16x8<Self>) -> (u32x4<Self>, u32x4<Self>) {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>) -> (u32x4<Sse2>, u32x4<Sse2>) {
let raw = a.into();
let sign = _mm_setzero_si128();
(
_mm_unpacklo_epi16(raw, sign).simd_into(token),
_mm_unpackhi_epi16(raw, sign).simd_into(token),
)
}
);
kernel(self, a)
}
#[inline(always)]
fn narrow_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, b: u16x8<Sse2>) -> u8x16<Sse2> {
let mask = _mm_set1_epi16(0xff);
_mm_packus_epi16(_mm_and_si128(a.into(), mask), _mm_and_si128(b.into(), mask))
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn saturating_narrow_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u8x16<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u16x8<Sse2>, b: u16x8<Sse2>) -> u8x16<Sse2> {
let max = _mm_set1_epi16(u8::MAX as i16);
let a = a.into();
let b = b.into();
let a = _mm_sub_epi16(a, _mm_subs_epu16(a, max));
let b = _mm_sub_epi16(b, _mm_subs_epu16(b, max));
_mm_packus_epi16(a, b).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn relaxed_narrow_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u8x16<Self> {
debug_assert!(
a.as_slice()
.iter()
.chain(b.as_slice())
.all(|&value| { value >= u8::MIN as u16 && value <= u8::MAX as u16 }),
"relaxed_narrow inputs must fit in the destination type",
);
self.narrow_u16x8(a, b)
}
#[inline(always)]
fn splat_mask16x8(self, val: bool) -> mask16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, val: bool) -> mask16x8<Sse2> {
let val: i16 = if val { !0 } else { 0 };
_mm_set1_epi16(val).simd_into(token)
}
);
kernel(self, val)
}
#[inline(always)]
fn from_bitmask_mask16x8(self, bits: u64) -> mask16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, bits: u64) -> mask16x8<Sse2> {
{
let bit_lanes = _mm_set1_epi16(bits as i16);
let bit_mask = _mm_setr_epi16(1, 2, 4, 8, 16, 32, 64, 128);
_mm_cmpeq_epi16(_mm_and_si128(bit_lanes, bit_mask), bit_mask)
}
.simd_into(token)
}
);
kernel(self, bits)
}
#[inline(always)]
fn to_bitmask_mask16x8(self, a: mask16x8<Self>) -> u64 {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask16x8<Sse2>) -> u64 {
{
let packed = _mm_packs_epi16(a.into(), a.into());
_mm_movemask_epi8(packed) as u8 as u64
}
}
);
kernel(self, a)
}
#[inline(always)]
fn set_mask16x8(self, a: &mut mask16x8<Self>, index: usize, value: bool) -> () {
assert!(
index < 8usize,
"mask lane index {index} is out of bounds for {} lanes",
8usize
);
let mut lanes: [i16; 8usize] = (*a).into();
lanes[index] = if value { !0 } else { 0 };
*a = lanes.simd_into(self);
}
#[inline(always)]
fn and_mask16x8(self, a: mask16x8<Self>, b: mask16x8<Self>) -> mask16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask16x8<Sse2>, b: mask16x8<Sse2>) -> mask16x8<Sse2> {
_mm_and_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn or_mask16x8(self, a: mask16x8<Self>, b: mask16x8<Self>) -> mask16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask16x8<Sse2>, b: mask16x8<Sse2>) -> mask16x8<Sse2> {
_mm_or_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn xor_mask16x8(self, a: mask16x8<Self>, b: mask16x8<Self>) -> mask16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask16x8<Sse2>, b: mask16x8<Sse2>) -> mask16x8<Sse2> {
_mm_xor_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn not_mask16x8(self, a: mask16x8<Self>) -> mask16x8<Self> {
self.xor_mask16x8(a, self.splat_mask16x8(true))
}
#[inline(always)]
fn select_mask16x8(
self,
a: mask16x8<Self>,
b: mask16x8<Self>,
c: mask16x8<Self>,
) -> mask16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
a: mask16x8<Sse2>,
b: mask16x8<Sse2>,
c: mask16x8<Sse2>,
) -> mask16x8<Sse2> {
_mm_or_si128(
_mm_and_si128(a.into(), b.into()),
_mm_andnot_si128(a.into(), c.into()),
)
.simd_into(token)
}
);
kernel(self, a, b, c)
}
#[inline(always)]
fn simd_eq_mask16x8(self, a: mask16x8<Self>, b: mask16x8<Self>) -> mask16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask16x8<Sse2>, b: mask16x8<Sse2>) -> mask16x8<Sse2> {
_mm_cmpeq_epi16(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn any_true_mask16x8(self, a: mask16x8<Self>) -> bool {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask16x8<Sse2>) -> bool {
_mm_movemask_epi8(a.into()) as u32 != 0
}
);
kernel(self, a)
}
#[inline(always)]
fn all_true_mask16x8(self, a: mask16x8<Self>) -> bool {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask16x8<Sse2>) -> bool {
_mm_movemask_epi8(a.into()) as u32 == 0xffff
}
);
kernel(self, a)
}
#[inline(always)]
fn any_false_mask16x8(self, a: mask16x8<Self>) -> bool {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask16x8<Sse2>) -> bool {
_mm_movemask_epi8(a.into()) as u32 != 0xffff
}
);
kernel(self, a)
}
#[inline(always)]
fn all_false_mask16x8(self, a: mask16x8<Self>) -> bool {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask16x8<Sse2>) -> bool {
_mm_movemask_epi8(a.into()) as u32 == 0
}
);
kernel(self, a)
}
#[inline(always)]
fn combine_mask16x8(self, a: mask16x8<Self>, b: mask16x8<Self>) -> mask16x16<Self> {
mask16x16 {
val: crate::support::Aligned256([a.val.0, b.val.0]),
simd: self,
}
}
#[inline(always)]
fn splat_i32x4(self, val: i32) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, val: i32) -> i32x4<Sse2> {
_mm_set1_epi32(val).simd_into(token)
}
);
kernel(self, val)
}
#[inline(always)]
fn slide_i32x4<const SHIFT: usize>(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
if SHIFT >= 4usize {
return b;
}
let result = dyn_alignr_128(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 4usize,
);
Bytes::from_bytes(u8x16 {
val: crate::support::Aligned128(result),
simd: self,
})
}
#[inline(always)]
fn add_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, b: i32x4<Sse2>) -> i32x4<Sse2> {
_mm_add_epi32(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn sub_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, b: i32x4<Sse2>) -> i32x4<Sse2> {
_mm_sub_epi32(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn mul_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
[
i32::wrapping_mul(a[0usize], b[0usize]),
i32::wrapping_mul(a[1usize], b[1usize]),
i32::wrapping_mul(a[2usize], b[2usize]),
i32::wrapping_mul(a[3usize], b[3usize]),
]
.simd_into(self)
}
#[inline(always)]
fn and_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, b: i32x4<Sse2>) -> i32x4<Sse2> {
_mm_and_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn or_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, b: i32x4<Sse2>) -> i32x4<Sse2> {
_mm_or_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn xor_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, b: i32x4<Sse2>) -> i32x4<Sse2> {
_mm_xor_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn not_i32x4(self, a: i32x4<Self>) -> i32x4<Self> {
a ^ !0
}
#[inline(always)]
fn shl_i32x4(self, a: i32x4<Self>, shift: u32) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, shift: u32) -> i32x4<Sse2> {
_mm_sll_epi32(a.into(), _mm_cvtsi32_si128(shift.cast_signed())).simd_into(token)
}
);
kernel(self, a, shift)
}
#[inline(always)]
fn shlv_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
[
i32::wrapping_shl(a[0usize], b[0usize] as u32),
i32::wrapping_shl(a[1usize], b[1usize] as u32),
i32::wrapping_shl(a[2usize], b[2usize] as u32),
i32::wrapping_shl(a[3usize], b[3usize] as u32),
]
.simd_into(self)
}
#[inline(always)]
fn shr_i32x4(self, a: i32x4<Self>, shift: u32) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, shift: u32) -> i32x4<Sse2> {
_mm_sra_epi32(a.into(), _mm_cvtsi32_si128(shift.cast_signed())).simd_into(token)
}
);
kernel(self, a, shift)
}
#[inline(always)]
fn shrv_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
[
i32::wrapping_shr(a[0usize], b[0usize] as u32),
i32::wrapping_shr(a[1usize], b[1usize] as u32),
i32::wrapping_shr(a[2usize], b[2usize] as u32),
i32::wrapping_shr(a[3usize], b[3usize] as u32),
]
.simd_into(self)
}
#[inline(always)]
fn max_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, b: i32x4<Sse2>) -> i32x4<Sse2> {
{
let a = a.into();
let b = b.into();
let gt = _mm_cmpgt_epi32(a, b);
_mm_or_si128(_mm_and_si128(gt, a), _mm_andnot_si128(gt, b))
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn min_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, b: i32x4<Sse2>) -> i32x4<Sse2> {
{
let a = a.into();
let b = b.into();
let gt = _mm_cmpgt_epi32(a, b);
_mm_or_si128(_mm_and_si128(gt, b), _mm_andnot_si128(gt, a))
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_eq_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> mask32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, b: i32x4<Sse2>) -> mask32x4<Sse2> {
_mm_cmpeq_epi32(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_lt_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> mask32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, b: i32x4<Sse2>) -> mask32x4<Sse2> {
_mm_cmpgt_epi32(b.into(), a.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_le_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> mask32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, b: i32x4<Sse2>) -> mask32x4<Sse2> {
{
let all_ones = _mm_set1_epi8(-1);
_mm_xor_si128(_mm_cmpgt_epi32(a.into(), b.into()), all_ones)
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_low_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, b: i32x4<Sse2>) -> i32x4<Sse2> {
_mm_unpacklo_epi32(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_high_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, b: i32x4<Sse2>) -> i32x4<Sse2> {
_mm_unpackhi_epi32(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn unzip_low_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, b: i32x4<Sse2>) -> i32x4<Sse2> {
let t1 = _mm_shuffle_epi32::<0b11_01_10_00>(a.into());
let t2 = _mm_shuffle_epi32::<0b11_01_10_00>(b.into());
_mm_unpacklo_epi64(t1, t2).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn unzip_high_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, b: i32x4<Sse2>) -> i32x4<Sse2> {
let t1 = _mm_shuffle_epi32::<0b11_01_10_00>(a.into());
let t2 = _mm_shuffle_epi32::<0b11_01_10_00>(b.into());
_mm_unpackhi_epi64(t1, t2).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn interleave_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> (i32x4<Self>, i32x4<Self>) {
(self.zip_low_i32x4(a, b), self.zip_high_i32x4(a, b))
}
#[inline(always)]
fn deinterleave_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> (i32x4<Self>, i32x4<Self>) {
(self.unzip_low_i32x4(a, b), self.unzip_high_i32x4(a, b))
}
#[inline(always)]
fn select_i32x4(self, a: mask32x4<Self>, b: i32x4<Self>, c: i32x4<Self>) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
a: mask32x4<Sse2>,
b: i32x4<Sse2>,
c: i32x4<Sse2>,
) -> i32x4<Sse2> {
_mm_or_si128(
_mm_and_si128(a.into(), b.into()),
_mm_andnot_si128(a.into(), c.into()),
)
.simd_into(token)
}
);
kernel(self, a, b, c)
}
#[inline(always)]
fn combine_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x8<Self> {
i32x8 {
val: crate::support::Aligned256([a.val.0, b.val.0]),
simd: self,
}
}
#[inline(always)]
fn neg_i32x4(self, a: i32x4<Self>) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>) -> i32x4<Sse2> {
_mm_sub_epi32(_mm_setzero_si128(), a.into()).simd_into(token)
}
);
kernel(self, a)
}
#[inline(always)]
fn load_four_interleaved_i32x4(self, src: &[i32; 16usize]) -> [i32x4<Self>; 4usize] {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, src: &[i32; 16usize]) -> [i32x4<Sse2>; 4usize] {
let (chunks, []) = src.as_chunks::<4usize>() else {
unreachable!()
};
let v0: __m128i =
crate::transmute::checked_transmute_copy::<[i32; 4usize], __m128i>(&chunks[0]);
let v1: __m128i =
crate::transmute::checked_transmute_copy::<[i32; 4usize], __m128i>(&chunks[1]);
let v2: __m128i =
crate::transmute::checked_transmute_copy::<[i32; 4usize], __m128i>(&chunks[2]);
let v3: __m128i =
crate::transmute::checked_transmute_copy::<[i32; 4usize], __m128i>(&chunks[3]);
let tmp0 = _mm_unpacklo_epi32(v0, v1);
let tmp1 = _mm_unpackhi_epi32(v0, v1);
let tmp2 = _mm_unpacklo_epi32(v2, v3);
let tmp3 = _mm_unpackhi_epi32(v2, v3);
let out0 = _mm_unpacklo_epi64(tmp0, tmp2);
let out1 = _mm_unpackhi_epi64(tmp0, tmp2);
let out2 = _mm_unpacklo_epi64(tmp1, tmp3);
let out3 = _mm_unpackhi_epi64(tmp1, tmp3);
[
out0.simd_into(token),
out1.simd_into(token),
out2.simd_into(token),
out3.simd_into(token),
]
}
);
kernel(self, src)
}
#[inline(always)]
fn store_four_interleaved_i32x4(
self,
vectors: [i32x4<Self>; 4usize],
dest: &mut [i32; 16usize],
) -> () {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
vectors: [i32x4<Sse2>; 4usize],
dest: &mut [i32; 16usize],
) -> () {
let _ = token;
let v0: __m128i = vectors[0].into();
let v1: __m128i = vectors[1].into();
let v2: __m128i = vectors[2].into();
let v3: __m128i = vectors[3].into();
let tmp0 = _mm_unpacklo_epi32(v0, v1);
let tmp1 = _mm_unpackhi_epi32(v0, v1);
let tmp2 = _mm_unpacklo_epi32(v2, v3);
let tmp3 = _mm_unpackhi_epi32(v2, v3);
let out0 = _mm_unpacklo_epi64(tmp0, tmp2);
let out1 = _mm_unpackhi_epi64(tmp0, tmp2);
let out2 = _mm_unpacklo_epi64(tmp1, tmp3);
let out3 = _mm_unpackhi_epi64(tmp1, tmp3);
let (chunks, []) = dest.as_chunks_mut::<4usize>() else {
unreachable!()
};
crate::transmute::checked_transmute_store::<__m128i, [i32; 4usize]>(
out0,
&mut chunks[0],
);
crate::transmute::checked_transmute_store::<__m128i, [i32; 4usize]>(
out1,
&mut chunks[1],
);
crate::transmute::checked_transmute_store::<__m128i, [i32; 4usize]>(
out2,
&mut chunks[2],
);
crate::transmute::checked_transmute_store::<__m128i, [i32; 4usize]>(
out3,
&mut chunks[3],
);
}
);
kernel(self, vectors, dest);
}
#[inline(always)]
fn widen_i32x4(self, a: i32x4<Self>) -> (i64x2<Self>, i64x2<Self>) {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>) -> (i64x2<Sse2>, i64x2<Sse2>) {
let raw = a.into();
let sign = _mm_srai_epi32::<31>(raw);
(
_mm_unpacklo_epi32(raw, sign).simd_into(token),
_mm_unpackhi_epi32(raw, sign).simd_into(token),
)
}
);
kernel(self, a)
}
#[inline(always)]
fn narrow_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i16x8<Self> {
[
a[0usize] as i16,
a[1usize] as i16,
a[2usize] as i16,
a[3usize] as i16,
b[0usize] as i16,
b[1usize] as i16,
b[2usize] as i16,
b[3usize] as i16,
]
.simd_into(self)
}
#[inline(always)]
fn saturating_narrow_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i16x8<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>, b: i32x4<Sse2>) -> i16x8<Sse2> {
_mm_packs_epi32(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn relaxed_narrow_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i16x8<Self> {
debug_assert!(
a.as_slice()
.iter()
.chain(b.as_slice())
.all(|&value| { value >= i16::MIN as i32 && value <= i16::MAX as i32 }),
"relaxed_narrow inputs must fit in the destination type",
);
self.saturating_narrow_i32x4(a, b)
}
#[inline(always)]
fn cvt_f32_i32x4(self, a: i32x4<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i32x4<Sse2>) -> f32x4<Sse2> {
_mm_cvtepi32_ps(a.into()).simd_into(token)
}
);
kernel(self, a)
}
#[inline(always)]
fn splat_u32x4(self, val: u32) -> u32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, val: u32) -> u32x4<Sse2> {
_mm_set1_epi32(val.cast_signed()).simd_into(token)
}
);
kernel(self, val)
}
#[inline(always)]
fn slide_u32x4<const SHIFT: usize>(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
if SHIFT >= 4usize {
return b;
}
let result = dyn_alignr_128(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 4usize,
);
Bytes::from_bytes(u8x16 {
val: crate::support::Aligned128(result),
simd: self,
})
}
#[inline(always)]
fn add_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>, b: u32x4<Sse2>) -> u32x4<Sse2> {
_mm_add_epi32(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn sub_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>, b: u32x4<Sse2>) -> u32x4<Sse2> {
_mm_sub_epi32(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn mul_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
[
u32::wrapping_mul(a[0usize], b[0usize]),
u32::wrapping_mul(a[1usize], b[1usize]),
u32::wrapping_mul(a[2usize], b[2usize]),
u32::wrapping_mul(a[3usize], b[3usize]),
]
.simd_into(self)
}
#[inline(always)]
fn and_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>, b: u32x4<Sse2>) -> u32x4<Sse2> {
_mm_and_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn or_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>, b: u32x4<Sse2>) -> u32x4<Sse2> {
_mm_or_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn xor_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>, b: u32x4<Sse2>) -> u32x4<Sse2> {
_mm_xor_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn not_u32x4(self, a: u32x4<Self>) -> u32x4<Self> {
a ^ !0
}
#[inline(always)]
fn shl_u32x4(self, a: u32x4<Self>, shift: u32) -> u32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>, shift: u32) -> u32x4<Sse2> {
_mm_sll_epi32(a.into(), _mm_cvtsi32_si128(shift.cast_signed())).simd_into(token)
}
);
kernel(self, a, shift)
}
#[inline(always)]
fn shlv_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
[
u32::wrapping_shl(a[0usize], b[0usize] as u32),
u32::wrapping_shl(a[1usize], b[1usize] as u32),
u32::wrapping_shl(a[2usize], b[2usize] as u32),
u32::wrapping_shl(a[3usize], b[3usize] as u32),
]
.simd_into(self)
}
#[inline(always)]
fn shr_u32x4(self, a: u32x4<Self>, shift: u32) -> u32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>, shift: u32) -> u32x4<Sse2> {
_mm_srl_epi32(a.into(), _mm_cvtsi32_si128(shift.cast_signed())).simd_into(token)
}
);
kernel(self, a, shift)
}
#[inline(always)]
fn shrv_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
[
u32::wrapping_shr(a[0usize], b[0usize] as u32),
u32::wrapping_shr(a[1usize], b[1usize] as u32),
u32::wrapping_shr(a[2usize], b[2usize] as u32),
u32::wrapping_shr(a[3usize], b[3usize] as u32),
]
.simd_into(self)
}
#[inline(always)]
fn max_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>, b: u32x4<Sse2>) -> u32x4<Sse2> {
{
let a = a.into();
let b = b.into();
let gt = {
let sign_bit = _mm_set1_epi32(0x80000000u32.cast_signed());
let lhs_signed = _mm_xor_si128(a, sign_bit);
let rhs_signed = _mm_xor_si128(b, sign_bit);
_mm_cmpgt_epi32(lhs_signed, rhs_signed)
};
_mm_or_si128(_mm_and_si128(gt, a), _mm_andnot_si128(gt, b))
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn min_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>, b: u32x4<Sse2>) -> u32x4<Sse2> {
{
let a = a.into();
let b = b.into();
let gt = {
let sign_bit = _mm_set1_epi32(0x80000000u32.cast_signed());
let lhs_signed = _mm_xor_si128(a, sign_bit);
let rhs_signed = _mm_xor_si128(b, sign_bit);
_mm_cmpgt_epi32(lhs_signed, rhs_signed)
};
_mm_or_si128(_mm_and_si128(gt, b), _mm_andnot_si128(gt, a))
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_eq_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> mask32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>, b: u32x4<Sse2>) -> mask32x4<Sse2> {
_mm_cmpeq_epi32(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_lt_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> mask32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>, b: u32x4<Sse2>) -> mask32x4<Sse2> {
{
let sign_bit = _mm_set1_epi32(0x80000000u32.cast_signed());
let lhs_signed = _mm_xor_si128(b.into(), sign_bit);
let rhs_signed = _mm_xor_si128(a.into(), sign_bit);
_mm_cmpgt_epi32(lhs_signed, rhs_signed)
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_le_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> mask32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>, b: u32x4<Sse2>) -> mask32x4<Sse2> {
{
let all_ones = _mm_set1_epi8(-1);
_mm_xor_si128(
{
let sign_bit = _mm_set1_epi32(0x80000000u32.cast_signed());
let lhs_signed = _mm_xor_si128(a.into(), sign_bit);
let rhs_signed = _mm_xor_si128(b.into(), sign_bit);
_mm_cmpgt_epi32(lhs_signed, rhs_signed)
},
all_ones,
)
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_low_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>, b: u32x4<Sse2>) -> u32x4<Sse2> {
_mm_unpacklo_epi32(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_high_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>, b: u32x4<Sse2>) -> u32x4<Sse2> {
_mm_unpackhi_epi32(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn unzip_low_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>, b: u32x4<Sse2>) -> u32x4<Sse2> {
let t1 = _mm_shuffle_epi32::<0b11_01_10_00>(a.into());
let t2 = _mm_shuffle_epi32::<0b11_01_10_00>(b.into());
_mm_unpacklo_epi64(t1, t2).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn unzip_high_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>, b: u32x4<Sse2>) -> u32x4<Sse2> {
let t1 = _mm_shuffle_epi32::<0b11_01_10_00>(a.into());
let t2 = _mm_shuffle_epi32::<0b11_01_10_00>(b.into());
_mm_unpackhi_epi64(t1, t2).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn interleave_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> (u32x4<Self>, u32x4<Self>) {
(self.zip_low_u32x4(a, b), self.zip_high_u32x4(a, b))
}
#[inline(always)]
fn deinterleave_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> (u32x4<Self>, u32x4<Self>) {
(self.unzip_low_u32x4(a, b), self.unzip_high_u32x4(a, b))
}
#[inline(always)]
fn select_u32x4(self, a: mask32x4<Self>, b: u32x4<Self>, c: u32x4<Self>) -> u32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
a: mask32x4<Sse2>,
b: u32x4<Sse2>,
c: u32x4<Sse2>,
) -> u32x4<Sse2> {
_mm_or_si128(
_mm_and_si128(a.into(), b.into()),
_mm_andnot_si128(a.into(), c.into()),
)
.simd_into(token)
}
);
kernel(self, a, b, c)
}
#[inline(always)]
fn combine_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x8<Self> {
u32x8 {
val: crate::support::Aligned256([a.val.0, b.val.0]),
simd: self,
}
}
#[inline(always)]
fn load_four_interleaved_u32x4(self, src: &[u32; 16usize]) -> [u32x4<Self>; 4usize] {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, src: &[u32; 16usize]) -> [u32x4<Sse2>; 4usize] {
let (chunks, []) = src.as_chunks::<4usize>() else {
unreachable!()
};
let v0: __m128i =
crate::transmute::checked_transmute_copy::<[u32; 4usize], __m128i>(&chunks[0]);
let v1: __m128i =
crate::transmute::checked_transmute_copy::<[u32; 4usize], __m128i>(&chunks[1]);
let v2: __m128i =
crate::transmute::checked_transmute_copy::<[u32; 4usize], __m128i>(&chunks[2]);
let v3: __m128i =
crate::transmute::checked_transmute_copy::<[u32; 4usize], __m128i>(&chunks[3]);
let tmp0 = _mm_unpacklo_epi32(v0, v1);
let tmp1 = _mm_unpackhi_epi32(v0, v1);
let tmp2 = _mm_unpacklo_epi32(v2, v3);
let tmp3 = _mm_unpackhi_epi32(v2, v3);
let out0 = _mm_unpacklo_epi64(tmp0, tmp2);
let out1 = _mm_unpackhi_epi64(tmp0, tmp2);
let out2 = _mm_unpacklo_epi64(tmp1, tmp3);
let out3 = _mm_unpackhi_epi64(tmp1, tmp3);
[
out0.simd_into(token),
out1.simd_into(token),
out2.simd_into(token),
out3.simd_into(token),
]
}
);
kernel(self, src)
}
#[inline(always)]
fn store_four_interleaved_u32x4(
self,
vectors: [u32x4<Self>; 4usize],
dest: &mut [u32; 16usize],
) -> () {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
vectors: [u32x4<Sse2>; 4usize],
dest: &mut [u32; 16usize],
) -> () {
let _ = token;
let v0: __m128i = vectors[0].into();
let v1: __m128i = vectors[1].into();
let v2: __m128i = vectors[2].into();
let v3: __m128i = vectors[3].into();
let tmp0 = _mm_unpacklo_epi32(v0, v1);
let tmp1 = _mm_unpackhi_epi32(v0, v1);
let tmp2 = _mm_unpacklo_epi32(v2, v3);
let tmp3 = _mm_unpackhi_epi32(v2, v3);
let out0 = _mm_unpacklo_epi64(tmp0, tmp2);
let out1 = _mm_unpackhi_epi64(tmp0, tmp2);
let out2 = _mm_unpacklo_epi64(tmp1, tmp3);
let out3 = _mm_unpackhi_epi64(tmp1, tmp3);
let (chunks, []) = dest.as_chunks_mut::<4usize>() else {
unreachable!()
};
crate::transmute::checked_transmute_store::<__m128i, [u32; 4usize]>(
out0,
&mut chunks[0],
);
crate::transmute::checked_transmute_store::<__m128i, [u32; 4usize]>(
out1,
&mut chunks[1],
);
crate::transmute::checked_transmute_store::<__m128i, [u32; 4usize]>(
out2,
&mut chunks[2],
);
crate::transmute::checked_transmute_store::<__m128i, [u32; 4usize]>(
out3,
&mut chunks[3],
);
}
);
kernel(self, vectors, dest);
}
#[inline(always)]
fn widen_u32x4(self, a: u32x4<Self>) -> (u64x2<Self>, u64x2<Self>) {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u32x4<Sse2>) -> (u64x2<Sse2>, u64x2<Sse2>) {
let raw = a.into();
let sign = _mm_setzero_si128();
(
_mm_unpacklo_epi32(raw, sign).simd_into(token),
_mm_unpackhi_epi32(raw, sign).simd_into(token),
)
}
);
kernel(self, a)
}
#[inline(always)]
fn narrow_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u16x8<Self> {
[
a[0usize] as u16,
a[1usize] as u16,
a[2usize] as u16,
a[3usize] as u16,
b[0usize] as u16,
b[1usize] as u16,
b[2usize] as u16,
b[3usize] as u16,
]
.simd_into(self)
}
#[inline(always)]
fn saturating_narrow_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u16x8<Self> {
[
a[0usize].clamp(u16::MIN as u32, u16::MAX as u32) as u16,
a[1usize].clamp(u16::MIN as u32, u16::MAX as u32) as u16,
a[2usize].clamp(u16::MIN as u32, u16::MAX as u32) as u16,
a[3usize].clamp(u16::MIN as u32, u16::MAX as u32) as u16,
b[0usize].clamp(u16::MIN as u32, u16::MAX as u32) as u16,
b[1usize].clamp(u16::MIN as u32, u16::MAX as u32) as u16,
b[2usize].clamp(u16::MIN as u32, u16::MAX as u32) as u16,
b[3usize].clamp(u16::MIN as u32, u16::MAX as u32) as u16,
]
.simd_into(self)
}
#[inline(always)]
fn relaxed_narrow_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u16x8<Self> {
debug_assert!(
a.as_slice()
.iter()
.chain(b.as_slice())
.all(|&value| { value >= u16::MIN as u32 && value <= u16::MAX as u32 }),
"relaxed_narrow inputs must fit in the destination type",
);
self.narrow_u32x4(a, b)
}
#[inline(always)]
fn cvt_f32_u32x4(self, a: u32x4<Self>) -> f32x4<Self> {
[
a[0usize] as f32,
a[1usize] as f32,
a[2usize] as f32,
a[3usize] as f32,
]
.simd_into(self)
}
#[inline(always)]
fn splat_mask32x4(self, val: bool) -> mask32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, val: bool) -> mask32x4<Sse2> {
let val: i32 = if val { !0 } else { 0 };
_mm_set1_epi32(val).simd_into(token)
}
);
kernel(self, val)
}
#[inline(always)]
fn from_bitmask_mask32x4(self, bits: u64) -> mask32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, bits: u64) -> mask32x4<Sse2> {
{
let bit_lanes = _mm_set1_epi32(bits as i32);
let bit_mask = _mm_setr_epi32(1, 2, 4, 8);
_mm_cmpeq_epi32(_mm_and_si128(bit_lanes, bit_mask), bit_mask)
}
.simd_into(token)
}
);
kernel(self, bits)
}
#[inline(always)]
fn to_bitmask_mask32x4(self, a: mask32x4<Self>) -> u64 {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask32x4<Sse2>) -> u64 {
_mm_movemask_ps(_mm_castsi128_ps(a.into())) as u32 as u64
}
);
kernel(self, a)
}
#[inline(always)]
fn set_mask32x4(self, a: &mut mask32x4<Self>, index: usize, value: bool) -> () {
assert!(
index < 4usize,
"mask lane index {index} is out of bounds for {} lanes",
4usize
);
let mut lanes: [i32; 4usize] = (*a).into();
lanes[index] = if value { !0 } else { 0 };
*a = lanes.simd_into(self);
}
#[inline(always)]
fn and_mask32x4(self, a: mask32x4<Self>, b: mask32x4<Self>) -> mask32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask32x4<Sse2>, b: mask32x4<Sse2>) -> mask32x4<Sse2> {
_mm_and_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn or_mask32x4(self, a: mask32x4<Self>, b: mask32x4<Self>) -> mask32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask32x4<Sse2>, b: mask32x4<Sse2>) -> mask32x4<Sse2> {
_mm_or_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn xor_mask32x4(self, a: mask32x4<Self>, b: mask32x4<Self>) -> mask32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask32x4<Sse2>, b: mask32x4<Sse2>) -> mask32x4<Sse2> {
_mm_xor_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn not_mask32x4(self, a: mask32x4<Self>) -> mask32x4<Self> {
self.xor_mask32x4(a, self.splat_mask32x4(true))
}
#[inline(always)]
fn select_mask32x4(
self,
a: mask32x4<Self>,
b: mask32x4<Self>,
c: mask32x4<Self>,
) -> mask32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
a: mask32x4<Sse2>,
b: mask32x4<Sse2>,
c: mask32x4<Sse2>,
) -> mask32x4<Sse2> {
_mm_or_si128(
_mm_and_si128(a.into(), b.into()),
_mm_andnot_si128(a.into(), c.into()),
)
.simd_into(token)
}
);
kernel(self, a, b, c)
}
#[inline(always)]
fn simd_eq_mask32x4(self, a: mask32x4<Self>, b: mask32x4<Self>) -> mask32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask32x4<Sse2>, b: mask32x4<Sse2>) -> mask32x4<Sse2> {
_mm_cmpeq_epi32(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn any_true_mask32x4(self, a: mask32x4<Self>) -> bool {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask32x4<Sse2>) -> bool {
_mm_movemask_ps(_mm_castsi128_ps(a.into())) as u32 != 0
}
);
kernel(self, a)
}
#[inline(always)]
fn all_true_mask32x4(self, a: mask32x4<Self>) -> bool {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask32x4<Sse2>) -> bool {
_mm_movemask_ps(_mm_castsi128_ps(a.into())) as u32 == 0b1111
}
);
kernel(self, a)
}
#[inline(always)]
fn any_false_mask32x4(self, a: mask32x4<Self>) -> bool {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask32x4<Sse2>) -> bool {
_mm_movemask_ps(_mm_castsi128_ps(a.into())) as u32 != 0b1111
}
);
kernel(self, a)
}
#[inline(always)]
fn all_false_mask32x4(self, a: mask32x4<Self>) -> bool {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask32x4<Sse2>) -> bool {
_mm_movemask_ps(_mm_castsi128_ps(a.into())) as u32 == 0
}
);
kernel(self, a)
}
#[inline(always)]
fn combine_mask32x4(self, a: mask32x4<Self>, b: mask32x4<Self>) -> mask32x8<Self> {
mask32x8 {
val: crate::support::Aligned256([a.val.0, b.val.0]),
simd: self,
}
}
#[inline(always)]
fn splat_f64x2(self, val: f64) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, val: f64) -> f64x2<Sse2> {
_mm_set1_pd(val).simd_into(token)
}
);
kernel(self, val)
}
#[inline(always)]
fn slide_f64x2<const SHIFT: usize>(self, a: f64x2<Self>, b: f64x2<Self>) -> f64x2<Self> {
if SHIFT >= 2usize {
return b;
}
let result = dyn_alignr_128(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 8usize,
);
Bytes::from_bytes(u8x16 {
val: crate::support::Aligned128(result),
simd: self,
})
}
#[inline(always)]
fn abs_f64x2(self, a: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>) -> f64x2<Sse2> {
_mm_andnot_pd(_mm_set1_pd(-0.0), a.into()).simd_into(token)
}
);
kernel(self, a)
}
#[inline(always)]
fn neg_f64x2(self, a: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>) -> f64x2<Sse2> {
_mm_xor_pd(a.into(), _mm_set1_pd(-0.0)).simd_into(token)
}
);
kernel(self, a)
}
#[inline(always)]
fn sqrt_f64x2(self, a: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>) -> f64x2<Sse2> {
_mm_sqrt_pd(a.into()).simd_into(token)
}
);
kernel(self, a)
}
#[inline(always)]
fn approximate_recip_f64x2(self, a: f64x2<Self>) -> f64x2<Self> {
1.0 / a
}
#[inline(always)]
fn add_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> f64x2<Sse2> {
_mm_add_pd(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn sub_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> f64x2<Sse2> {
_mm_sub_pd(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn mul_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> f64x2<Sse2> {
_mm_mul_pd(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn div_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> f64x2<Sse2> {
_mm_div_pd(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn copysign_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> f64x2<Sse2> {
let mask = _mm_set1_pd(-0.0);
_mm_or_pd(_mm_and_pd(mask, b.into()), _mm_andnot_pd(mask, a.into()))
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn max_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> f64x2<Sse2> {
_mm_max_pd(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn min_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> f64x2<Sse2> {
_mm_min_pd(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn max_precise_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> f64x2<Sse2> {
let a = a.into();
let b = b.into();
let intermediate = _mm_max_pd(a, b);
let b_is_nan = _mm_cmpunord_pd(b, b);
_mm_or_pd(
_mm_and_pd(b_is_nan, a),
_mm_andnot_pd(b_is_nan, intermediate),
)
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn min_precise_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> f64x2<Sse2> {
let a = a.into();
let b = b.into();
let intermediate = _mm_min_pd(a, b);
let b_is_nan = _mm_cmpunord_pd(b, b);
_mm_or_pd(
_mm_and_pd(b_is_nan, a),
_mm_andnot_pd(b_is_nan, intermediate),
)
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_eq_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> mask64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> mask64x2<Sse2> {
_mm_castpd_si128(_mm_cmpeq_pd(a.into(), b.into())).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_lt_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> mask64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> mask64x2<Sse2> {
_mm_castpd_si128(_mm_cmplt_pd(a.into(), b.into())).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_le_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> mask64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> mask64x2<Sse2> {
_mm_castpd_si128(_mm_cmple_pd(a.into(), b.into())).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_low_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> f64x2<Sse2> {
_mm_unpacklo_pd(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_high_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> f64x2<Sse2> {
_mm_unpackhi_pd(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn unzip_low_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> f64x2<Sse2> {
_mm_shuffle_pd::<0b00>(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn unzip_high_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> f64x2<Sse2> {
_mm_shuffle_pd::<0b11>(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn interleave_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> (f64x2<Self>, f64x2<Self>) {
(self.zip_low_f64x2(a, b), self.zip_high_f64x2(a, b))
}
#[inline(always)]
fn deinterleave_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> (f64x2<Self>, f64x2<Self>) {
(self.unzip_low_f64x2(a, b), self.unzip_high_f64x2(a, b))
}
#[inline(always)]
fn mul_add_f64x2(self, a: f64x2<Self>, b: f64x2<Self>, c: f64x2<Self>) -> f64x2<Self> {
a * b + c
}
#[inline(always)]
fn mul_sub_f64x2(self, a: f64x2<Self>, b: f64x2<Self>, c: f64x2<Self>) -> f64x2<Self> {
a * b - c
}
#[inline(always)]
fn floor_f64x2(self, a: f64x2<Self>) -> f64x2<Self> {
[f64::floor(a[0usize]), f64::floor(a[1usize])].simd_into(self)
}
#[inline(always)]
fn ceil_f64x2(self, a: f64x2<Self>) -> f64x2<Self> {
[f64::ceil(a[0usize]), f64::ceil(a[1usize])].simd_into(self)
}
#[inline(always)]
fn round_ties_even_f64x2(self, a: f64x2<Self>) -> f64x2<Self> {
[
f64::round_ties_even(a[0usize]),
f64::round_ties_even(a[1usize]),
]
.simd_into(self)
}
#[inline(always)]
fn fract_f64x2(self, a: f64x2<Self>) -> f64x2<Self> {
a - self.trunc_f64x2(a)
}
#[inline(always)]
fn trunc_f64x2(self, a: f64x2<Self>) -> f64x2<Self> {
[f64::trunc(a[0usize]), f64::trunc(a[1usize])].simd_into(self)
}
#[inline(always)]
fn select_f64x2(self, a: mask64x2<Self>, b: f64x2<Self>, c: f64x2<Self>) -> f64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
a: mask64x2<Sse2>,
b: f64x2<Sse2>,
c: f64x2<Sse2>,
) -> f64x2<Sse2> {
_mm_or_pd(
_mm_and_pd(_mm_castsi128_pd(a.into()), b.into()),
_mm_andnot_pd(_mm_castsi128_pd(a.into()), c.into()),
)
.simd_into(token)
}
);
kernel(self, a, b, c)
}
#[inline(always)]
fn combine_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f64x4<Self> {
f64x4 {
val: crate::support::Aligned256([a.val.0, b.val.0]),
simd: self,
}
}
#[inline(always)]
fn load_four_interleaved_f64x2(self, src: &[f64; 8usize]) -> [f64x2<Self>; 4usize] {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, src: &[f64; 8usize]) -> [f64x2<Sse2>; 4usize] {
let (chunks, []) = src.as_chunks::<2usize>() else {
unreachable!()
};
let v0: __m128d =
crate::transmute::checked_transmute_copy::<[f64; 2usize], __m128d>(&chunks[0]);
let v1: __m128d =
crate::transmute::checked_transmute_copy::<[f64; 2usize], __m128d>(&chunks[1]);
let v2: __m128d =
crate::transmute::checked_transmute_copy::<[f64; 2usize], __m128d>(&chunks[2]);
let v3: __m128d =
crate::transmute::checked_transmute_copy::<[f64; 2usize], __m128d>(&chunks[3]);
let out0 = _mm_unpacklo_pd(v0, v2);
let out1 = _mm_unpackhi_pd(v0, v2);
let out2 = _mm_unpacklo_pd(v1, v3);
let out3 = _mm_unpackhi_pd(v1, v3);
[
out0.simd_into(token),
out1.simd_into(token),
out2.simd_into(token),
out3.simd_into(token),
]
}
);
kernel(self, src)
}
#[inline(always)]
fn store_four_interleaved_f64x2(
self,
vectors: [f64x2<Self>; 4usize],
dest: &mut [f64; 8usize],
) -> () {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, vectors: [f64x2<Sse2>; 4usize], dest: &mut [f64; 8usize]) -> () {
let _ = token;
let v0: __m128d = vectors[0].into();
let v1: __m128d = vectors[1].into();
let v2: __m128d = vectors[2].into();
let v3: __m128d = vectors[3].into();
let out0 = _mm_unpacklo_pd(v0, v1);
let out1 = _mm_unpacklo_pd(v2, v3);
let out2 = _mm_unpackhi_pd(v0, v1);
let out3 = _mm_unpackhi_pd(v2, v3);
let (chunks, []) = dest.as_chunks_mut::<2usize>() else {
unreachable!()
};
crate::transmute::checked_transmute_store::<__m128d, [f64; 2usize]>(
out0,
&mut chunks[0],
);
crate::transmute::checked_transmute_store::<__m128d, [f64; 2usize]>(
out1,
&mut chunks[1],
);
crate::transmute::checked_transmute_store::<__m128d, [f64; 2usize]>(
out2,
&mut chunks[2],
);
crate::transmute::checked_transmute_store::<__m128d, [f64; 2usize]>(
out3,
&mut chunks[3],
);
}
);
kernel(self, vectors, dest);
}
#[inline(always)]
fn narrow_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: f64x2<Sse2>, b: f64x2<Sse2>) -> f32x4<Sse2> {
let low = _mm_cvtpd_ps(a.into());
let high = _mm_cvtpd_ps(b.into());
_mm_movelh_ps(low, high).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn saturating_narrow_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f32x4<Self> {
self.narrow_f64x2(a, b)
}
#[inline(always)]
fn relaxed_narrow_f64x2(self, a: f64x2<Self>, b: f64x2<Self>) -> f32x4<Self> {
self.narrow_f64x2(a, b)
}
#[inline(always)]
fn cvt_u64_f64x2(self, a: f64x2<Self>) -> u64x2<Self> {
[a[0usize] as u64, a[1usize] as u64].simd_into(self)
}
#[inline(always)]
fn cvt_u64_precise_f64x2(self, a: f64x2<Self>) -> u64x2<Self> {
[a[0usize] as u64, a[1usize] as u64].simd_into(self)
}
#[inline(always)]
fn cvt_i64_f64x2(self, a: f64x2<Self>) -> i64x2<Self> {
[a[0usize] as i64, a[1usize] as i64].simd_into(self)
}
#[inline(always)]
fn cvt_i64_precise_f64x2(self, a: f64x2<Self>) -> i64x2<Self> {
[a[0usize] as i64, a[1usize] as i64].simd_into(self)
}
#[inline(always)]
fn splat_i64x2(self, val: i64) -> i64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, val: i64) -> i64x2<Sse2> {
_mm_set1_epi64x(val).simd_into(token)
}
);
kernel(self, val)
}
#[inline(always)]
fn slide_i64x2<const SHIFT: usize>(self, a: i64x2<Self>, b: i64x2<Self>) -> i64x2<Self> {
if SHIFT >= 2usize {
return b;
}
let result = dyn_alignr_128(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 8usize,
);
Bytes::from_bytes(u8x16 {
val: crate::support::Aligned128(result),
simd: self,
})
}
#[inline(always)]
fn add_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i64x2<Sse2>, b: i64x2<Sse2>) -> i64x2<Sse2> {
_mm_add_epi64(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn sub_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i64x2<Sse2>, b: i64x2<Sse2>) -> i64x2<Sse2> {
_mm_sub_epi64(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn mul_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i64x2<Self> {
[
i64::wrapping_mul(a[0usize], b[0usize]),
i64::wrapping_mul(a[1usize], b[1usize]),
]
.simd_into(self)
}
#[inline(always)]
fn and_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i64x2<Sse2>, b: i64x2<Sse2>) -> i64x2<Sse2> {
_mm_and_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn or_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i64x2<Sse2>, b: i64x2<Sse2>) -> i64x2<Sse2> {
_mm_or_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn xor_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i64x2<Sse2>, b: i64x2<Sse2>) -> i64x2<Sse2> {
_mm_xor_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn not_i64x2(self, a: i64x2<Self>) -> i64x2<Self> {
a ^ !0
}
#[inline(always)]
fn shl_i64x2(self, a: i64x2<Self>, shift: u32) -> i64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i64x2<Sse2>, shift: u32) -> i64x2<Sse2> {
_mm_sll_epi64(a.into(), _mm_cvtsi32_si128(shift.cast_signed())).simd_into(token)
}
);
kernel(self, a, shift)
}
#[inline(always)]
fn shlv_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i64x2<Self> {
[
i64::wrapping_shl(a[0usize], b[0usize] as u32),
i64::wrapping_shl(a[1usize], b[1usize] as u32),
]
.simd_into(self)
}
#[inline(always)]
fn shr_i64x2(self, a: i64x2<Self>, shift: u32) -> i64x2<Self> {
[
i64::wrapping_shr(a[0usize], shift),
i64::wrapping_shr(a[1usize], shift),
]
.simd_into(self)
}
#[inline(always)]
fn shrv_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i64x2<Self> {
[
i64::wrapping_shr(a[0usize], b[0usize] as u32),
i64::wrapping_shr(a[1usize], b[1usize] as u32),
]
.simd_into(self)
}
#[inline(always)]
fn max_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i64x2<Self> {
[
i64::max(a[0usize], b[0usize]),
i64::max(a[1usize], b[1usize]),
]
.simd_into(self)
}
#[inline(always)]
fn min_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i64x2<Self> {
[
i64::min(a[0usize], b[0usize]),
i64::min(a[1usize], b[1usize]),
]
.simd_into(self)
}
#[inline(always)]
fn simd_eq_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> mask64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i64x2<Sse2>, b: i64x2<Sse2>) -> mask64x2<Sse2> {
{
let eq32 = _mm_cmpeq_epi32(a.into(), b.into());
let swapped = _mm_shuffle_epi32::<0b10_11_00_01>(eq32);
_mm_and_si128(eq32, swapped)
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_lt_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> mask64x2<Self> {
[
-(i64::lt(&a[0usize], &b[0usize]) as i64),
-(i64::lt(&a[1usize], &b[1usize]) as i64),
]
.simd_into(self)
}
#[inline(always)]
fn simd_le_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> mask64x2<Self> {
[
-(i64::le(&a[0usize], &b[0usize]) as i64),
-(i64::le(&a[1usize], &b[1usize]) as i64),
]
.simd_into(self)
}
#[inline(always)]
fn zip_low_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i64x2<Sse2>, b: i64x2<Sse2>) -> i64x2<Sse2> {
_mm_unpacklo_epi64(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_high_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i64x2<Sse2>, b: i64x2<Sse2>) -> i64x2<Sse2> {
_mm_unpackhi_epi64(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn unzip_low_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i64x2<Sse2>, b: i64x2<Sse2>) -> i64x2<Sse2> {
_mm_unpacklo_epi64(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn unzip_high_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i64x2<Sse2>, b: i64x2<Sse2>) -> i64x2<Sse2> {
_mm_unpackhi_epi64(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn interleave_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> (i64x2<Self>, i64x2<Self>) {
(self.zip_low_i64x2(a, b), self.zip_high_i64x2(a, b))
}
#[inline(always)]
fn deinterleave_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> (i64x2<Self>, i64x2<Self>) {
(self.unzip_low_i64x2(a, b), self.unzip_high_i64x2(a, b))
}
#[inline(always)]
fn select_i64x2(self, a: mask64x2<Self>, b: i64x2<Self>, c: i64x2<Self>) -> i64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
a: mask64x2<Sse2>,
b: i64x2<Sse2>,
c: i64x2<Sse2>,
) -> i64x2<Sse2> {
_mm_or_si128(
_mm_and_si128(a.into(), b.into()),
_mm_andnot_si128(a.into(), c.into()),
)
.simd_into(token)
}
);
kernel(self, a, b, c)
}
#[inline(always)]
fn combine_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i64x4<Self> {
i64x4 {
val: crate::support::Aligned256([a.val.0, b.val.0]),
simd: self,
}
}
#[inline(always)]
fn neg_i64x2(self, a: i64x2<Self>) -> i64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i64x2<Sse2>) -> i64x2<Sse2> {
_mm_sub_epi64(_mm_setzero_si128(), a.into()).simd_into(token)
}
);
kernel(self, a)
}
#[inline(always)]
fn load_four_interleaved_i64x2(self, src: &[i64; 8usize]) -> [i64x2<Self>; 4usize] {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, src: &[i64; 8usize]) -> [i64x2<Sse2>; 4usize] {
let (chunks, []) = src.as_chunks::<2usize>() else {
unreachable!()
};
let v0: __m128i =
crate::transmute::checked_transmute_copy::<[i64; 2usize], __m128i>(&chunks[0]);
let v1: __m128i =
crate::transmute::checked_transmute_copy::<[i64; 2usize], __m128i>(&chunks[1]);
let v2: __m128i =
crate::transmute::checked_transmute_copy::<[i64; 2usize], __m128i>(&chunks[2]);
let v3: __m128i =
crate::transmute::checked_transmute_copy::<[i64; 2usize], __m128i>(&chunks[3]);
let out0 = _mm_unpacklo_epi64(v0, v2);
let out1 = _mm_unpackhi_epi64(v0, v2);
let out2 = _mm_unpacklo_epi64(v1, v3);
let out3 = _mm_unpackhi_epi64(v1, v3);
[
out0.simd_into(token),
out1.simd_into(token),
out2.simd_into(token),
out3.simd_into(token),
]
}
);
kernel(self, src)
}
#[inline(always)]
fn store_four_interleaved_i64x2(
self,
vectors: [i64x2<Self>; 4usize],
dest: &mut [i64; 8usize],
) -> () {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, vectors: [i64x2<Sse2>; 4usize], dest: &mut [i64; 8usize]) -> () {
let _ = token;
let v0: __m128i = vectors[0].into();
let v1: __m128i = vectors[1].into();
let v2: __m128i = vectors[2].into();
let v3: __m128i = vectors[3].into();
let out0 = _mm_unpacklo_epi64(v0, v1);
let out1 = _mm_unpacklo_epi64(v2, v3);
let out2 = _mm_unpackhi_epi64(v0, v1);
let out3 = _mm_unpackhi_epi64(v2, v3);
let (chunks, []) = dest.as_chunks_mut::<2usize>() else {
unreachable!()
};
crate::transmute::checked_transmute_store::<__m128i, [i64; 2usize]>(
out0,
&mut chunks[0],
);
crate::transmute::checked_transmute_store::<__m128i, [i64; 2usize]>(
out1,
&mut chunks[1],
);
crate::transmute::checked_transmute_store::<__m128i, [i64; 2usize]>(
out2,
&mut chunks[2],
);
crate::transmute::checked_transmute_store::<__m128i, [i64; 2usize]>(
out3,
&mut chunks[3],
);
}
);
kernel(self, vectors, dest);
}
#[inline(always)]
fn narrow_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: i64x2<Sse2>, b: i64x2<Sse2>) -> i32x4<Sse2> {
_mm_castps_si128(_mm_shuffle_ps::<0x88>(
_mm_castsi128_ps(a.into()),
_mm_castsi128_ps(b.into()),
))
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn saturating_narrow_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i32x4<Self> {
[
a[0usize].clamp(i32::MIN as i64, i32::MAX as i64) as i32,
a[1usize].clamp(i32::MIN as i64, i32::MAX as i64) as i32,
b[0usize].clamp(i32::MIN as i64, i32::MAX as i64) as i32,
b[1usize].clamp(i32::MIN as i64, i32::MAX as i64) as i32,
]
.simd_into(self)
}
#[inline(always)]
fn relaxed_narrow_i64x2(self, a: i64x2<Self>, b: i64x2<Self>) -> i32x4<Self> {
debug_assert!(
a.as_slice()
.iter()
.chain(b.as_slice())
.all(|&value| { value >= i32::MIN as i64 && value <= i32::MAX as i64 }),
"relaxed_narrow inputs must fit in the destination type",
);
self.narrow_i64x2(a, b)
}
#[inline(always)]
fn cvt_f64_i64x2(self, a: i64x2<Self>) -> f64x2<Self> {
[a[0usize] as f64, a[1usize] as f64].simd_into(self)
}
#[inline(always)]
fn splat_u64x2(self, val: u64) -> u64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, val: u64) -> u64x2<Sse2> {
_mm_set1_epi64x(val.cast_signed()).simd_into(token)
}
);
kernel(self, val)
}
#[inline(always)]
fn slide_u64x2<const SHIFT: usize>(self, a: u64x2<Self>, b: u64x2<Self>) -> u64x2<Self> {
if SHIFT >= 2usize {
return b;
}
let result = dyn_alignr_128(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 8usize,
);
Bytes::from_bytes(u8x16 {
val: crate::support::Aligned128(result),
simd: self,
})
}
#[inline(always)]
fn add_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u64x2<Sse2>, b: u64x2<Sse2>) -> u64x2<Sse2> {
_mm_add_epi64(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn sub_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u64x2<Sse2>, b: u64x2<Sse2>) -> u64x2<Sse2> {
_mm_sub_epi64(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn mul_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u64x2<Self> {
[
u64::wrapping_mul(a[0usize], b[0usize]),
u64::wrapping_mul(a[1usize], b[1usize]),
]
.simd_into(self)
}
#[inline(always)]
fn and_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u64x2<Sse2>, b: u64x2<Sse2>) -> u64x2<Sse2> {
_mm_and_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn or_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u64x2<Sse2>, b: u64x2<Sse2>) -> u64x2<Sse2> {
_mm_or_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn xor_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u64x2<Sse2>, b: u64x2<Sse2>) -> u64x2<Sse2> {
_mm_xor_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn not_u64x2(self, a: u64x2<Self>) -> u64x2<Self> {
a ^ !0
}
#[inline(always)]
fn shl_u64x2(self, a: u64x2<Self>, shift: u32) -> u64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u64x2<Sse2>, shift: u32) -> u64x2<Sse2> {
_mm_sll_epi64(a.into(), _mm_cvtsi32_si128(shift.cast_signed())).simd_into(token)
}
);
kernel(self, a, shift)
}
#[inline(always)]
fn shlv_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u64x2<Self> {
[
u64::wrapping_shl(a[0usize], b[0usize] as u32),
u64::wrapping_shl(a[1usize], b[1usize] as u32),
]
.simd_into(self)
}
#[inline(always)]
fn shr_u64x2(self, a: u64x2<Self>, shift: u32) -> u64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u64x2<Sse2>, shift: u32) -> u64x2<Sse2> {
_mm_srl_epi64(a.into(), _mm_cvtsi32_si128(shift.cast_signed())).simd_into(token)
}
);
kernel(self, a, shift)
}
#[inline(always)]
fn shrv_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u64x2<Self> {
[
u64::wrapping_shr(a[0usize], b[0usize] as u32),
u64::wrapping_shr(a[1usize], b[1usize] as u32),
]
.simd_into(self)
}
#[inline(always)]
fn max_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u64x2<Self> {
[
u64::max(a[0usize], b[0usize]),
u64::max(a[1usize], b[1usize]),
]
.simd_into(self)
}
#[inline(always)]
fn min_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u64x2<Self> {
[
u64::min(a[0usize], b[0usize]),
u64::min(a[1usize], b[1usize]),
]
.simd_into(self)
}
#[inline(always)]
fn simd_eq_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> mask64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u64x2<Sse2>, b: u64x2<Sse2>) -> mask64x2<Sse2> {
{
let eq32 = _mm_cmpeq_epi32(a.into(), b.into());
let swapped = _mm_shuffle_epi32::<0b10_11_00_01>(eq32);
_mm_and_si128(eq32, swapped)
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn simd_lt_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> mask64x2<Self> {
[
-(u64::lt(&a[0usize], &b[0usize]) as i64),
-(u64::lt(&a[1usize], &b[1usize]) as i64),
]
.simd_into(self)
}
#[inline(always)]
fn simd_le_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> mask64x2<Self> {
[
-(u64::le(&a[0usize], &b[0usize]) as i64),
-(u64::le(&a[1usize], &b[1usize]) as i64),
]
.simd_into(self)
}
#[inline(always)]
fn zip_low_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u64x2<Sse2>, b: u64x2<Sse2>) -> u64x2<Sse2> {
_mm_unpacklo_epi64(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn zip_high_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u64x2<Sse2>, b: u64x2<Sse2>) -> u64x2<Sse2> {
_mm_unpackhi_epi64(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn unzip_low_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u64x2<Sse2>, b: u64x2<Sse2>) -> u64x2<Sse2> {
_mm_unpacklo_epi64(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn unzip_high_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u64x2<Sse2>, b: u64x2<Sse2>) -> u64x2<Sse2> {
_mm_unpackhi_epi64(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn interleave_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> (u64x2<Self>, u64x2<Self>) {
(self.zip_low_u64x2(a, b), self.zip_high_u64x2(a, b))
}
#[inline(always)]
fn deinterleave_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> (u64x2<Self>, u64x2<Self>) {
(self.unzip_low_u64x2(a, b), self.unzip_high_u64x2(a, b))
}
#[inline(always)]
fn select_u64x2(self, a: mask64x2<Self>, b: u64x2<Self>, c: u64x2<Self>) -> u64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
a: mask64x2<Sse2>,
b: u64x2<Sse2>,
c: u64x2<Sse2>,
) -> u64x2<Sse2> {
_mm_or_si128(
_mm_and_si128(a.into(), b.into()),
_mm_andnot_si128(a.into(), c.into()),
)
.simd_into(token)
}
);
kernel(self, a, b, c)
}
#[inline(always)]
fn combine_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u64x4<Self> {
u64x4 {
val: crate::support::Aligned256([a.val.0, b.val.0]),
simd: self,
}
}
#[inline(always)]
fn load_four_interleaved_u64x2(self, src: &[u64; 8usize]) -> [u64x2<Self>; 4usize] {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, src: &[u64; 8usize]) -> [u64x2<Sse2>; 4usize] {
let (chunks, []) = src.as_chunks::<2usize>() else {
unreachable!()
};
let v0: __m128i =
crate::transmute::checked_transmute_copy::<[u64; 2usize], __m128i>(&chunks[0]);
let v1: __m128i =
crate::transmute::checked_transmute_copy::<[u64; 2usize], __m128i>(&chunks[1]);
let v2: __m128i =
crate::transmute::checked_transmute_copy::<[u64; 2usize], __m128i>(&chunks[2]);
let v3: __m128i =
crate::transmute::checked_transmute_copy::<[u64; 2usize], __m128i>(&chunks[3]);
let out0 = _mm_unpacklo_epi64(v0, v2);
let out1 = _mm_unpackhi_epi64(v0, v2);
let out2 = _mm_unpacklo_epi64(v1, v3);
let out3 = _mm_unpackhi_epi64(v1, v3);
[
out0.simd_into(token),
out1.simd_into(token),
out2.simd_into(token),
out3.simd_into(token),
]
}
);
kernel(self, src)
}
#[inline(always)]
fn store_four_interleaved_u64x2(
self,
vectors: [u64x2<Self>; 4usize],
dest: &mut [u64; 8usize],
) -> () {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, vectors: [u64x2<Sse2>; 4usize], dest: &mut [u64; 8usize]) -> () {
let _ = token;
let v0: __m128i = vectors[0].into();
let v1: __m128i = vectors[1].into();
let v2: __m128i = vectors[2].into();
let v3: __m128i = vectors[3].into();
let out0 = _mm_unpacklo_epi64(v0, v1);
let out1 = _mm_unpacklo_epi64(v2, v3);
let out2 = _mm_unpackhi_epi64(v0, v1);
let out3 = _mm_unpackhi_epi64(v2, v3);
let (chunks, []) = dest.as_chunks_mut::<2usize>() else {
unreachable!()
};
crate::transmute::checked_transmute_store::<__m128i, [u64; 2usize]>(
out0,
&mut chunks[0],
);
crate::transmute::checked_transmute_store::<__m128i, [u64; 2usize]>(
out1,
&mut chunks[1],
);
crate::transmute::checked_transmute_store::<__m128i, [u64; 2usize]>(
out2,
&mut chunks[2],
);
crate::transmute::checked_transmute_store::<__m128i, [u64; 2usize]>(
out3,
&mut chunks[3],
);
}
);
kernel(self, vectors, dest);
}
#[inline(always)]
fn narrow_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u32x4<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: u64x2<Sse2>, b: u64x2<Sse2>) -> u32x4<Sse2> {
_mm_castps_si128(_mm_shuffle_ps::<0x88>(
_mm_castsi128_ps(a.into()),
_mm_castsi128_ps(b.into()),
))
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn saturating_narrow_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u32x4<Self> {
[
a[0usize].clamp(u32::MIN as u64, u32::MAX as u64) as u32,
a[1usize].clamp(u32::MIN as u64, u32::MAX as u64) as u32,
b[0usize].clamp(u32::MIN as u64, u32::MAX as u64) as u32,
b[1usize].clamp(u32::MIN as u64, u32::MAX as u64) as u32,
]
.simd_into(self)
}
#[inline(always)]
fn relaxed_narrow_u64x2(self, a: u64x2<Self>, b: u64x2<Self>) -> u32x4<Self> {
debug_assert!(
a.as_slice()
.iter()
.chain(b.as_slice())
.all(|&value| { value >= u32::MIN as u64 && value <= u32::MAX as u64 }),
"relaxed_narrow inputs must fit in the destination type",
);
self.narrow_u64x2(a, b)
}
#[inline(always)]
fn cvt_f64_u64x2(self, a: u64x2<Self>) -> f64x2<Self> {
[a[0usize] as f64, a[1usize] as f64].simd_into(self)
}
#[inline(always)]
fn splat_mask64x2(self, val: bool) -> mask64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, val: bool) -> mask64x2<Sse2> {
let val: i64 = if val { !0 } else { 0 };
_mm_set1_epi64x(val).simd_into(token)
}
);
kernel(self, val)
}
#[inline(always)]
fn from_bitmask_mask64x2(self, bits: u64) -> mask64x2<Self> {
let lanes: [i64; 2usize] = [
if bits & 1 != 0 { !0 } else { 0 },
if (bits >> 1usize) & 1 != 0 { !0 } else { 0 },
];
lanes.simd_into(self)
}
#[inline(always)]
fn to_bitmask_mask64x2(self, a: mask64x2<Self>) -> u64 {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask64x2<Sse2>) -> u64 {
_mm_movemask_pd(_mm_castsi128_pd(a.into())) as u32 as u64
}
);
kernel(self, a)
}
#[inline(always)]
fn set_mask64x2(self, a: &mut mask64x2<Self>, index: usize, value: bool) -> () {
assert!(
index < 2usize,
"mask lane index {index} is out of bounds for {} lanes",
2usize
);
let mut lanes: [i64; 2usize] = (*a).into();
lanes[index] = if value { !0 } else { 0 };
*a = lanes.simd_into(self);
}
#[inline(always)]
fn and_mask64x2(self, a: mask64x2<Self>, b: mask64x2<Self>) -> mask64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask64x2<Sse2>, b: mask64x2<Sse2>) -> mask64x2<Sse2> {
_mm_and_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn or_mask64x2(self, a: mask64x2<Self>, b: mask64x2<Self>) -> mask64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask64x2<Sse2>, b: mask64x2<Sse2>) -> mask64x2<Sse2> {
_mm_or_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn xor_mask64x2(self, a: mask64x2<Self>, b: mask64x2<Self>) -> mask64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask64x2<Sse2>, b: mask64x2<Sse2>) -> mask64x2<Sse2> {
_mm_xor_si128(a.into(), b.into()).simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn not_mask64x2(self, a: mask64x2<Self>) -> mask64x2<Self> {
self.xor_mask64x2(a, self.splat_mask64x2(true))
}
#[inline(always)]
fn select_mask64x2(
self,
a: mask64x2<Self>,
b: mask64x2<Self>,
c: mask64x2<Self>,
) -> mask64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(
token: Sse2,
a: mask64x2<Sse2>,
b: mask64x2<Sse2>,
c: mask64x2<Sse2>,
) -> mask64x2<Sse2> {
_mm_or_si128(
_mm_and_si128(a.into(), b.into()),
_mm_andnot_si128(a.into(), c.into()),
)
.simd_into(token)
}
);
kernel(self, a, b, c)
}
#[inline(always)]
fn simd_eq_mask64x2(self, a: mask64x2<Self>, b: mask64x2<Self>) -> mask64x2<Self> {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask64x2<Sse2>, b: mask64x2<Sse2>) -> mask64x2<Sse2> {
{
let eq32 = _mm_cmpeq_epi32(a.into(), b.into());
let swapped = _mm_shuffle_epi32::<0b10_11_00_01>(eq32);
_mm_and_si128(eq32, swapped)
}
.simd_into(token)
}
);
kernel(self, a, b)
}
#[inline(always)]
fn any_true_mask64x2(self, a: mask64x2<Self>) -> bool {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask64x2<Sse2>) -> bool {
_mm_movemask_pd(_mm_castsi128_pd(a.into())) as u32 != 0
}
);
kernel(self, a)
}
#[inline(always)]
fn all_true_mask64x2(self, a: mask64x2<Self>) -> bool {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask64x2<Sse2>) -> bool {
_mm_movemask_pd(_mm_castsi128_pd(a.into())) as u32 == 0b11
}
);
kernel(self, a)
}
#[inline(always)]
fn any_false_mask64x2(self, a: mask64x2<Self>) -> bool {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask64x2<Sse2>) -> bool {
_mm_movemask_pd(_mm_castsi128_pd(a.into())) as u32 != 0b11
}
);
kernel(self, a)
}
#[inline(always)]
fn all_false_mask64x2(self, a: mask64x2<Self>) -> bool {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask64x2<Sse2>) -> bool {
_mm_movemask_pd(_mm_castsi128_pd(a.into())) as u32 == 0
}
);
kernel(self, a)
}
#[inline(always)]
fn combine_mask64x2(self, a: mask64x2<Self>, b: mask64x2<Self>) -> mask64x4<Self> {
mask64x4 {
val: crate::support::Aligned256([a.val.0, b.val.0]),
simd: self,
}
}
#[inline(always)]
fn slide_f32x8<const SHIFT: usize>(self, a: f32x8<Self>, b: f32x8<Self>) -> f32x8<Self> {
if SHIFT >= 8usize {
return b;
}
let result = cross_block_alignr_128x2(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 4usize,
);
Bytes::from_bytes(u8x32 {
val: crate::support::Aligned256(result),
simd: self,
})
}
#[inline(always)]
fn combine_f32x8(self, a: f32x8<Self>, b: f32x8<Self>) -> f32x16<Self> {
f32x16 {
val: crate::support::Aligned512([a.val.0[0], a.val.0[1], b.val.0[0], b.val.0[1]]),
simd: self,
}
}
#[inline(always)]
fn split_f32x8(self, a: f32x8<Self>) -> (f32x4<Self>, f32x4<Self>) {
(
f32x4 {
val: crate::support::Aligned128(a.val.0[0]),
simd: self,
},
f32x4 {
val: crate::support::Aligned128(a.val.0[1]),
simd: self,
},
)
}
#[inline(always)]
fn slide_i8x32<const SHIFT: usize>(self, a: i8x32<Self>, b: i8x32<Self>) -> i8x32<Self> {
if SHIFT >= 32usize {
return b;
}
let result = cross_block_alignr_128x2(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT,
);
Bytes::from_bytes(u8x32 {
val: crate::support::Aligned256(result),
simd: self,
})
}
#[inline(always)]
fn combine_i8x32(self, a: i8x32<Self>, b: i8x32<Self>) -> i8x64<Self> {
i8x64 {
val: crate::support::Aligned512([a.val.0[0], a.val.0[1], b.val.0[0], b.val.0[1]]),
simd: self,
}
}
#[inline(always)]
fn split_i8x32(self, a: i8x32<Self>) -> (i8x16<Self>, i8x16<Self>) {
(
i8x16 {
val: crate::support::Aligned128(a.val.0[0]),
simd: self,
},
i8x16 {
val: crate::support::Aligned128(a.val.0[1]),
simd: self,
},
)
}
#[inline(always)]
fn slide_u8x32<const SHIFT: usize>(self, a: u8x32<Self>, b: u8x32<Self>) -> u8x32<Self> {
if SHIFT >= 32usize {
return b;
}
let result = cross_block_alignr_128x2(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT,
);
Bytes::from_bytes(u8x32 {
val: crate::support::Aligned256(result),
simd: self,
})
}
#[inline(always)]
fn swizzle_dyn_u8x32(self, a: u8x32<Self>, indices: u8x32<Self>) -> u8x32<Self> {
let bytes = Bytes::to_bytes(a);
let mut output = [0u8; 32usize];
for lane in 0..32usize {
let index = indices[lane] as usize;
output[lane] = bytes[index % 32usize];
}
let result: u8x32<Self> = output.simd_into(self);
Bytes::from_bytes(result)
}
#[inline(always)]
fn swizzle_dyn_precise_u8x32(self, a: u8x32<Self>, indices: u8x32<Self>) -> u8x32<Self> {
let bytes = Bytes::to_bytes(a);
let mut output = [0u8; 32usize];
for lane in 0..32usize {
let index = indices[lane] as usize;
let value = bytes[index % 32usize];
output[lane] = if index < 32usize { value } else { 0 };
}
let result: u8x32<Self> = output.simd_into(self);
Bytes::from_bytes(result)
}
#[inline(always)]
fn combine_u8x32(self, a: u8x32<Self>, b: u8x32<Self>) -> u8x64<Self> {
u8x64 {
val: crate::support::Aligned512([a.val.0[0], a.val.0[1], b.val.0[0], b.val.0[1]]),
simd: self,
}
}
#[inline(always)]
fn split_u8x32(self, a: u8x32<Self>) -> (u8x16<Self>, u8x16<Self>) {
(
u8x16 {
val: crate::support::Aligned128(a.val.0[0]),
simd: self,
},
u8x16 {
val: crate::support::Aligned128(a.val.0[1]),
simd: self,
},
)
}
#[inline(always)]
fn set_mask8x32(self, a: &mut mask8x32<Self>, index: usize, value: bool) -> () {
assert!(
index < 32usize,
"mask lane index {index} is out of bounds for {} lanes",
32usize
);
let mut lanes: [i8; 32usize] = (*a).into();
lanes[index] = if value { !0 } else { 0 };
*a = lanes.simd_into(self);
}
#[inline(always)]
fn combine_mask8x32(self, a: mask8x32<Self>, b: mask8x32<Self>) -> mask8x64<Self> {
mask8x64 {
val: crate::support::Aligned512([a.val.0[0], a.val.0[1], b.val.0[0], b.val.0[1]]),
simd: self,
}
}
#[inline(always)]
fn split_mask8x32(self, a: mask8x32<Self>) -> (mask8x16<Self>, mask8x16<Self>) {
(
mask8x16 {
val: crate::support::Aligned128(a.val.0[0]),
simd: self,
},
mask8x16 {
val: crate::support::Aligned128(a.val.0[1]),
simd: self,
},
)
}
#[inline(always)]
fn slide_i16x16<const SHIFT: usize>(self, a: i16x16<Self>, b: i16x16<Self>) -> i16x16<Self> {
if SHIFT >= 16usize {
return b;
}
let result = cross_block_alignr_128x2(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 2usize,
);
Bytes::from_bytes(u8x32 {
val: crate::support::Aligned256(result),
simd: self,
})
}
#[inline(always)]
fn combine_i16x16(self, a: i16x16<Self>, b: i16x16<Self>) -> i16x32<Self> {
i16x32 {
val: crate::support::Aligned512([a.val.0[0], a.val.0[1], b.val.0[0], b.val.0[1]]),
simd: self,
}
}
#[inline(always)]
fn split_i16x16(self, a: i16x16<Self>) -> (i16x8<Self>, i16x8<Self>) {
(
i16x8 {
val: crate::support::Aligned128(a.val.0[0]),
simd: self,
},
i16x8 {
val: crate::support::Aligned128(a.val.0[1]),
simd: self,
},
)
}
#[inline(always)]
fn slide_u16x16<const SHIFT: usize>(self, a: u16x16<Self>, b: u16x16<Self>) -> u16x16<Self> {
if SHIFT >= 16usize {
return b;
}
let result = cross_block_alignr_128x2(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 2usize,
);
Bytes::from_bytes(u8x32 {
val: crate::support::Aligned256(result),
simd: self,
})
}
#[inline(always)]
fn combine_u16x16(self, a: u16x16<Self>, b: u16x16<Self>) -> u16x32<Self> {
u16x32 {
val: crate::support::Aligned512([a.val.0[0], a.val.0[1], b.val.0[0], b.val.0[1]]),
simd: self,
}
}
#[inline(always)]
fn split_u16x16(self, a: u16x16<Self>) -> (u16x8<Self>, u16x8<Self>) {
(
u16x8 {
val: crate::support::Aligned128(a.val.0[0]),
simd: self,
},
u16x8 {
val: crate::support::Aligned128(a.val.0[1]),
simd: self,
},
)
}
#[inline(always)]
fn to_bitmask_mask16x16(self, a: mask16x16<Self>) -> u64 {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask16x16<Sse2>) -> u64 {
{
let packed = _mm_packs_epi16(a.val.0[0], a.val.0[1]);
_mm_movemask_epi8(packed) as u32 as u64
}
}
);
kernel(self, a)
}
#[inline(always)]
fn set_mask16x16(self, a: &mut mask16x16<Self>, index: usize, value: bool) -> () {
assert!(
index < 16usize,
"mask lane index {index} is out of bounds for {} lanes",
16usize
);
let mut lanes: [i16; 16usize] = (*a).into();
lanes[index] = if value { !0 } else { 0 };
*a = lanes.simd_into(self);
}
#[inline(always)]
fn combine_mask16x16(self, a: mask16x16<Self>, b: mask16x16<Self>) -> mask16x32<Self> {
mask16x32 {
val: crate::support::Aligned512([a.val.0[0], a.val.0[1], b.val.0[0], b.val.0[1]]),
simd: self,
}
}
#[inline(always)]
fn split_mask16x16(self, a: mask16x16<Self>) -> (mask16x8<Self>, mask16x8<Self>) {
(
mask16x8 {
val: crate::support::Aligned128(a.val.0[0]),
simd: self,
},
mask16x8 {
val: crate::support::Aligned128(a.val.0[1]),
simd: self,
},
)
}
#[inline(always)]
fn slide_i32x8<const SHIFT: usize>(self, a: i32x8<Self>, b: i32x8<Self>) -> i32x8<Self> {
if SHIFT >= 8usize {
return b;
}
let result = cross_block_alignr_128x2(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 4usize,
);
Bytes::from_bytes(u8x32 {
val: crate::support::Aligned256(result),
simd: self,
})
}
#[inline(always)]
fn combine_i32x8(self, a: i32x8<Self>, b: i32x8<Self>) -> i32x16<Self> {
i32x16 {
val: crate::support::Aligned512([a.val.0[0], a.val.0[1], b.val.0[0], b.val.0[1]]),
simd: self,
}
}
#[inline(always)]
fn split_i32x8(self, a: i32x8<Self>) -> (i32x4<Self>, i32x4<Self>) {
(
i32x4 {
val: crate::support::Aligned128(a.val.0[0]),
simd: self,
},
i32x4 {
val: crate::support::Aligned128(a.val.0[1]),
simd: self,
},
)
}
#[inline(always)]
fn slide_u32x8<const SHIFT: usize>(self, a: u32x8<Self>, b: u32x8<Self>) -> u32x8<Self> {
if SHIFT >= 8usize {
return b;
}
let result = cross_block_alignr_128x2(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 4usize,
);
Bytes::from_bytes(u8x32 {
val: crate::support::Aligned256(result),
simd: self,
})
}
#[inline(always)]
fn combine_u32x8(self, a: u32x8<Self>, b: u32x8<Self>) -> u32x16<Self> {
u32x16 {
val: crate::support::Aligned512([a.val.0[0], a.val.0[1], b.val.0[0], b.val.0[1]]),
simd: self,
}
}
#[inline(always)]
fn split_u32x8(self, a: u32x8<Self>) -> (u32x4<Self>, u32x4<Self>) {
(
u32x4 {
val: crate::support::Aligned128(a.val.0[0]),
simd: self,
},
u32x4 {
val: crate::support::Aligned128(a.val.0[1]),
simd: self,
},
)
}
#[inline(always)]
fn set_mask32x8(self, a: &mut mask32x8<Self>, index: usize, value: bool) -> () {
assert!(
index < 8usize,
"mask lane index {index} is out of bounds for {} lanes",
8usize
);
let mut lanes: [i32; 8usize] = (*a).into();
lanes[index] = if value { !0 } else { 0 };
*a = lanes.simd_into(self);
}
#[inline(always)]
fn combine_mask32x8(self, a: mask32x8<Self>, b: mask32x8<Self>) -> mask32x16<Self> {
mask32x16 {
val: crate::support::Aligned512([a.val.0[0], a.val.0[1], b.val.0[0], b.val.0[1]]),
simd: self,
}
}
#[inline(always)]
fn split_mask32x8(self, a: mask32x8<Self>) -> (mask32x4<Self>, mask32x4<Self>) {
(
mask32x4 {
val: crate::support::Aligned128(a.val.0[0]),
simd: self,
},
mask32x4 {
val: crate::support::Aligned128(a.val.0[1]),
simd: self,
},
)
}
#[inline(always)]
fn slide_f64x4<const SHIFT: usize>(self, a: f64x4<Self>, b: f64x4<Self>) -> f64x4<Self> {
if SHIFT >= 4usize {
return b;
}
let result = cross_block_alignr_128x2(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 8usize,
);
Bytes::from_bytes(u8x32 {
val: crate::support::Aligned256(result),
simd: self,
})
}
#[inline(always)]
fn combine_f64x4(self, a: f64x4<Self>, b: f64x4<Self>) -> f64x8<Self> {
f64x8 {
val: crate::support::Aligned512([a.val.0[0], a.val.0[1], b.val.0[0], b.val.0[1]]),
simd: self,
}
}
#[inline(always)]
fn split_f64x4(self, a: f64x4<Self>) -> (f64x2<Self>, f64x2<Self>) {
(
f64x2 {
val: crate::support::Aligned128(a.val.0[0]),
simd: self,
},
f64x2 {
val: crate::support::Aligned128(a.val.0[1]),
simd: self,
},
)
}
#[inline(always)]
fn slide_i64x4<const SHIFT: usize>(self, a: i64x4<Self>, b: i64x4<Self>) -> i64x4<Self> {
if SHIFT >= 4usize {
return b;
}
let result = cross_block_alignr_128x2(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 8usize,
);
Bytes::from_bytes(u8x32 {
val: crate::support::Aligned256(result),
simd: self,
})
}
#[inline(always)]
fn combine_i64x4(self, a: i64x4<Self>, b: i64x4<Self>) -> i64x8<Self> {
i64x8 {
val: crate::support::Aligned512([a.val.0[0], a.val.0[1], b.val.0[0], b.val.0[1]]),
simd: self,
}
}
#[inline(always)]
fn split_i64x4(self, a: i64x4<Self>) -> (i64x2<Self>, i64x2<Self>) {
(
i64x2 {
val: crate::support::Aligned128(a.val.0[0]),
simd: self,
},
i64x2 {
val: crate::support::Aligned128(a.val.0[1]),
simd: self,
},
)
}
#[inline(always)]
fn slide_u64x4<const SHIFT: usize>(self, a: u64x4<Self>, b: u64x4<Self>) -> u64x4<Self> {
if SHIFT >= 4usize {
return b;
}
let result = cross_block_alignr_128x2(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 8usize,
);
Bytes::from_bytes(u8x32 {
val: crate::support::Aligned256(result),
simd: self,
})
}
#[inline(always)]
fn combine_u64x4(self, a: u64x4<Self>, b: u64x4<Self>) -> u64x8<Self> {
u64x8 {
val: crate::support::Aligned512([a.val.0[0], a.val.0[1], b.val.0[0], b.val.0[1]]),
simd: self,
}
}
#[inline(always)]
fn split_u64x4(self, a: u64x4<Self>) -> (u64x2<Self>, u64x2<Self>) {
(
u64x2 {
val: crate::support::Aligned128(a.val.0[0]),
simd: self,
},
u64x2 {
val: crate::support::Aligned128(a.val.0[1]),
simd: self,
},
)
}
#[inline(always)]
fn set_mask64x4(self, a: &mut mask64x4<Self>, index: usize, value: bool) -> () {
assert!(
index < 4usize,
"mask lane index {index} is out of bounds for {} lanes",
4usize
);
let mut lanes: [i64; 4usize] = (*a).into();
lanes[index] = if value { !0 } else { 0 };
*a = lanes.simd_into(self);
}
#[inline(always)]
fn combine_mask64x4(self, a: mask64x4<Self>, b: mask64x4<Self>) -> mask64x8<Self> {
mask64x8 {
val: crate::support::Aligned512([a.val.0[0], a.val.0[1], b.val.0[0], b.val.0[1]]),
simd: self,
}
}
#[inline(always)]
fn split_mask64x4(self, a: mask64x4<Self>) -> (mask64x2<Self>, mask64x2<Self>) {
(
mask64x2 {
val: crate::support::Aligned128(a.val.0[0]),
simd: self,
},
mask64x2 {
val: crate::support::Aligned128(a.val.0[1]),
simd: self,
},
)
}
#[inline(always)]
fn slide_f32x16<const SHIFT: usize>(self, a: f32x16<Self>, b: f32x16<Self>) -> f32x16<Self> {
if SHIFT >= 16usize {
return b;
}
let result = cross_block_alignr_128x4(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 4usize,
);
Bytes::from_bytes(u8x64 {
val: crate::support::Aligned512(result),
simd: self,
})
}
#[inline(always)]
fn split_f32x16(self, a: f32x16<Self>) -> (f32x8<Self>, f32x8<Self>) {
(
f32x8 {
val: crate::support::Aligned256([a.val.0[0], a.val.0[1]]),
simd: self,
},
f32x8 {
val: crate::support::Aligned256([a.val.0[2], a.val.0[3]]),
simd: self,
},
)
}
#[inline(always)]
fn slide_i8x64<const SHIFT: usize>(self, a: i8x64<Self>, b: i8x64<Self>) -> i8x64<Self> {
if SHIFT >= 64usize {
return b;
}
let result = cross_block_alignr_128x4(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT,
);
Bytes::from_bytes(u8x64 {
val: crate::support::Aligned512(result),
simd: self,
})
}
#[inline(always)]
fn split_i8x64(self, a: i8x64<Self>) -> (i8x32<Self>, i8x32<Self>) {
(
i8x32 {
val: crate::support::Aligned256([a.val.0[0], a.val.0[1]]),
simd: self,
},
i8x32 {
val: crate::support::Aligned256([a.val.0[2], a.val.0[3]]),
simd: self,
},
)
}
#[inline(always)]
fn slide_u8x64<const SHIFT: usize>(self, a: u8x64<Self>, b: u8x64<Self>) -> u8x64<Self> {
if SHIFT >= 64usize {
return b;
}
let result = cross_block_alignr_128x4(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT,
);
Bytes::from_bytes(u8x64 {
val: crate::support::Aligned512(result),
simd: self,
})
}
#[inline(always)]
fn swizzle_dyn_u8x64(self, a: u8x64<Self>, indices: u8x64<Self>) -> u8x64<Self> {
let bytes = Bytes::to_bytes(a);
let mut output = [0u8; 64usize];
for lane in 0..64usize {
let index = indices[lane] as usize;
output[lane] = bytes[index % 64usize];
}
let result: u8x64<Self> = output.simd_into(self);
Bytes::from_bytes(result)
}
#[inline(always)]
fn swizzle_dyn_precise_u8x64(self, a: u8x64<Self>, indices: u8x64<Self>) -> u8x64<Self> {
let bytes = Bytes::to_bytes(a);
let mut output = [0u8; 64usize];
for lane in 0..64usize {
let index = indices[lane] as usize;
let value = bytes[index % 64usize];
output[lane] = if index < 64usize { value } else { 0 };
}
let result: u8x64<Self> = output.simd_into(self);
Bytes::from_bytes(result)
}
#[inline(always)]
fn split_u8x64(self, a: u8x64<Self>) -> (u8x32<Self>, u8x32<Self>) {
(
u8x32 {
val: crate::support::Aligned256([a.val.0[0], a.val.0[1]]),
simd: self,
},
u8x32 {
val: crate::support::Aligned256([a.val.0[2], a.val.0[3]]),
simd: self,
},
)
}
#[inline(always)]
fn set_mask8x64(self, a: &mut mask8x64<Self>, index: usize, value: bool) -> () {
assert!(
index < 64usize,
"mask lane index {index} is out of bounds for {} lanes",
64usize
);
let mut lanes: [i8; 64usize] = (*a).into();
lanes[index] = if value { !0 } else { 0 };
*a = lanes.simd_into(self);
}
#[inline(always)]
fn split_mask8x64(self, a: mask8x64<Self>) -> (mask8x32<Self>, mask8x32<Self>) {
(
mask8x32 {
val: crate::support::Aligned256([a.val.0[0], a.val.0[1]]),
simd: self,
},
mask8x32 {
val: crate::support::Aligned256([a.val.0[2], a.val.0[3]]),
simd: self,
},
)
}
#[inline(always)]
fn slide_i16x32<const SHIFT: usize>(self, a: i16x32<Self>, b: i16x32<Self>) -> i16x32<Self> {
if SHIFT >= 32usize {
return b;
}
let result = cross_block_alignr_128x4(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 2usize,
);
Bytes::from_bytes(u8x64 {
val: crate::support::Aligned512(result),
simd: self,
})
}
#[inline(always)]
fn split_i16x32(self, a: i16x32<Self>) -> (i16x16<Self>, i16x16<Self>) {
(
i16x16 {
val: crate::support::Aligned256([a.val.0[0], a.val.0[1]]),
simd: self,
},
i16x16 {
val: crate::support::Aligned256([a.val.0[2], a.val.0[3]]),
simd: self,
},
)
}
#[inline(always)]
fn slide_u16x32<const SHIFT: usize>(self, a: u16x32<Self>, b: u16x32<Self>) -> u16x32<Self> {
if SHIFT >= 32usize {
return b;
}
let result = cross_block_alignr_128x4(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 2usize,
);
Bytes::from_bytes(u8x64 {
val: crate::support::Aligned512(result),
simd: self,
})
}
#[inline(always)]
fn split_u16x32(self, a: u16x32<Self>) -> (u16x16<Self>, u16x16<Self>) {
(
u16x16 {
val: crate::support::Aligned256([a.val.0[0], a.val.0[1]]),
simd: self,
},
u16x16 {
val: crate::support::Aligned256([a.val.0[2], a.val.0[3]]),
simd: self,
},
)
}
#[inline(always)]
fn to_bitmask_mask16x32(self, a: mask16x32<Self>) -> u64 {
crate::kernel!(
#[inline(always)]
fn kernel(token: Sse2, a: mask16x32<Sse2>) -> u64 {
{
let lo = _mm_packs_epi16(a.val.0[0], a.val.0[1]);
let hi = _mm_packs_epi16(a.val.0[2], a.val.0[3]);
let lo = _mm_movemask_epi8(lo) as u32 as u64;
let hi = _mm_movemask_epi8(hi) as u32 as u64;
lo | (hi << 16usize)
}
}
);
kernel(self, a)
}
#[inline(always)]
fn set_mask16x32(self, a: &mut mask16x32<Self>, index: usize, value: bool) -> () {
assert!(
index < 32usize,
"mask lane index {index} is out of bounds for {} lanes",
32usize
);
let mut lanes: [i16; 32usize] = (*a).into();
lanes[index] = if value { !0 } else { 0 };
*a = lanes.simd_into(self);
}
#[inline(always)]
fn split_mask16x32(self, a: mask16x32<Self>) -> (mask16x16<Self>, mask16x16<Self>) {
(
mask16x16 {
val: crate::support::Aligned256([a.val.0[0], a.val.0[1]]),
simd: self,
},
mask16x16 {
val: crate::support::Aligned256([a.val.0[2], a.val.0[3]]),
simd: self,
},
)
}
#[inline(always)]
fn slide_i32x16<const SHIFT: usize>(self, a: i32x16<Self>, b: i32x16<Self>) -> i32x16<Self> {
if SHIFT >= 16usize {
return b;
}
let result = cross_block_alignr_128x4(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 4usize,
);
Bytes::from_bytes(u8x64 {
val: crate::support::Aligned512(result),
simd: self,
})
}
#[inline(always)]
fn split_i32x16(self, a: i32x16<Self>) -> (i32x8<Self>, i32x8<Self>) {
(
i32x8 {
val: crate::support::Aligned256([a.val.0[0], a.val.0[1]]),
simd: self,
},
i32x8 {
val: crate::support::Aligned256([a.val.0[2], a.val.0[3]]),
simd: self,
},
)
}
#[inline(always)]
fn slide_u32x16<const SHIFT: usize>(self, a: u32x16<Self>, b: u32x16<Self>) -> u32x16<Self> {
if SHIFT >= 16usize {
return b;
}
let result = cross_block_alignr_128x4(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 4usize,
);
Bytes::from_bytes(u8x64 {
val: crate::support::Aligned512(result),
simd: self,
})
}
#[inline(always)]
fn split_u32x16(self, a: u32x16<Self>) -> (u32x8<Self>, u32x8<Self>) {
(
u32x8 {
val: crate::support::Aligned256([a.val.0[0], a.val.0[1]]),
simd: self,
},
u32x8 {
val: crate::support::Aligned256([a.val.0[2], a.val.0[3]]),
simd: self,
},
)
}
#[inline(always)]
fn set_mask32x16(self, a: &mut mask32x16<Self>, index: usize, value: bool) -> () {
assert!(
index < 16usize,
"mask lane index {index} is out of bounds for {} lanes",
16usize
);
let mut lanes: [i32; 16usize] = (*a).into();
lanes[index] = if value { !0 } else { 0 };
*a = lanes.simd_into(self);
}
#[inline(always)]
fn split_mask32x16(self, a: mask32x16<Self>) -> (mask32x8<Self>, mask32x8<Self>) {
(
mask32x8 {
val: crate::support::Aligned256([a.val.0[0], a.val.0[1]]),
simd: self,
},
mask32x8 {
val: crate::support::Aligned256([a.val.0[2], a.val.0[3]]),
simd: self,
},
)
}
#[inline(always)]
fn slide_f64x8<const SHIFT: usize>(self, a: f64x8<Self>, b: f64x8<Self>) -> f64x8<Self> {
if SHIFT >= 8usize {
return b;
}
let result = cross_block_alignr_128x4(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 8usize,
);
Bytes::from_bytes(u8x64 {
val: crate::support::Aligned512(result),
simd: self,
})
}
#[inline(always)]
fn split_f64x8(self, a: f64x8<Self>) -> (f64x4<Self>, f64x4<Self>) {
(
f64x4 {
val: crate::support::Aligned256([a.val.0[0], a.val.0[1]]),
simd: self,
},
f64x4 {
val: crate::support::Aligned256([a.val.0[2], a.val.0[3]]),
simd: self,
},
)
}
#[inline(always)]
fn slide_i64x8<const SHIFT: usize>(self, a: i64x8<Self>, b: i64x8<Self>) -> i64x8<Self> {
if SHIFT >= 8usize {
return b;
}
let result = cross_block_alignr_128x4(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 8usize,
);
Bytes::from_bytes(u8x64 {
val: crate::support::Aligned512(result),
simd: self,
})
}
#[inline(always)]
fn split_i64x8(self, a: i64x8<Self>) -> (i64x4<Self>, i64x4<Self>) {
(
i64x4 {
val: crate::support::Aligned256([a.val.0[0], a.val.0[1]]),
simd: self,
},
i64x4 {
val: crate::support::Aligned256([a.val.0[2], a.val.0[3]]),
simd: self,
},
)
}
#[inline(always)]
fn slide_u64x8<const SHIFT: usize>(self, a: u64x8<Self>, b: u64x8<Self>) -> u64x8<Self> {
if SHIFT >= 8usize {
return b;
}
let result = cross_block_alignr_128x4(
self,
Bytes::to_bytes(b).val.0,
Bytes::to_bytes(a).val.0,
SHIFT * 8usize,
);
Bytes::from_bytes(u8x64 {
val: crate::support::Aligned512(result),
simd: self,
})
}
#[inline(always)]
fn split_u64x8(self, a: u64x8<Self>) -> (u64x4<Self>, u64x4<Self>) {
(
u64x4 {
val: crate::support::Aligned256([a.val.0[0], a.val.0[1]]),
simd: self,
},
u64x4 {
val: crate::support::Aligned256([a.val.0[2], a.val.0[3]]),
simd: self,
},
)
}
#[inline(always)]
fn set_mask64x8(self, a: &mut mask64x8<Self>, index: usize, value: bool) -> () {
assert!(
index < 8usize,
"mask lane index {index} is out of bounds for {} lanes",
8usize
);
let mut lanes: [i64; 8usize] = (*a).into();
lanes[index] = if value { !0 } else { 0 };
*a = lanes.simd_into(self);
}
#[inline(always)]
fn split_mask64x8(self, a: mask64x8<Self>) -> (mask64x4<Self>, mask64x4<Self>) {
(
mask64x4 {
val: crate::support::Aligned256([a.val.0[0], a.val.0[1]]),
simd: self,
},
mask64x4 {
val: crate::support::Aligned256([a.val.0[2], a.val.0[3]]),
simd: self,
},
)
}
}
impl<S: Simd> SimdFrom<__m128, S> for f32x4<S> {
#[inline(always)]
fn simd_from(simd: S, arch: __m128) -> Self {
Self {
val: crate::transmute::checked_transmute_copy(&arch),
simd,
}
}
}
impl<S: Simd> From<f32x4<S>> for __m128 {
#[inline(always)]
fn from(value: f32x4<S>) -> Self {
crate::transmute::checked_transmute_copy(&value.val)
}
}
impl<S: Simd> SimdFrom<__m128i, S> for i8x16<S> {
#[inline(always)]
fn simd_from(simd: S, arch: __m128i) -> Self {
Self {
val: crate::transmute::checked_transmute_copy(&arch),
simd,
}
}
}
impl<S: Simd> From<i8x16<S>> for __m128i {
#[inline(always)]
fn from(value: i8x16<S>) -> Self {
crate::transmute::checked_transmute_copy(&value.val)
}
}
impl<S: Simd> SimdFrom<__m128i, S> for u8x16<S> {
#[inline(always)]
fn simd_from(simd: S, arch: __m128i) -> Self {
Self {
val: crate::transmute::checked_transmute_copy(&arch),
simd,
}
}
}
impl<S: Simd> From<u8x16<S>> for __m128i {
#[inline(always)]
fn from(value: u8x16<S>) -> Self {
crate::transmute::checked_transmute_copy(&value.val)
}
}
impl<S: Simd> SimdFrom<__m128i, S> for mask8x16<S> {
#[inline(always)]
fn simd_from(simd: S, arch: __m128i) -> Self {
let lanes: [i8; 16usize] = crate::transmute::checked_transmute_copy(&arch);
lanes.simd_into(simd)
}
}
impl<S: Simd> From<mask8x16<S>> for __m128i {
#[inline(always)]
fn from(value: mask8x16<S>) -> Self {
let lanes: [i8; 16usize] = value.into();
crate::transmute::checked_transmute_copy(&lanes)
}
}
impl<S: Simd> SimdFrom<__m128i, S> for i16x8<S> {
#[inline(always)]
fn simd_from(simd: S, arch: __m128i) -> Self {
Self {
val: crate::transmute::checked_transmute_copy(&arch),
simd,
}
}
}
impl<S: Simd> From<i16x8<S>> for __m128i {
#[inline(always)]
fn from(value: i16x8<S>) -> Self {
crate::transmute::checked_transmute_copy(&value.val)
}
}
impl<S: Simd> SimdFrom<__m128i, S> for u16x8<S> {
#[inline(always)]
fn simd_from(simd: S, arch: __m128i) -> Self {
Self {
val: crate::transmute::checked_transmute_copy(&arch),
simd,
}
}
}
impl<S: Simd> From<u16x8<S>> for __m128i {
#[inline(always)]
fn from(value: u16x8<S>) -> Self {
crate::transmute::checked_transmute_copy(&value.val)
}
}
impl<S: Simd> SimdFrom<__m128i, S> for mask16x8<S> {
#[inline(always)]
fn simd_from(simd: S, arch: __m128i) -> Self {
let lanes: [i16; 8usize] = crate::transmute::checked_transmute_copy(&arch);
lanes.simd_into(simd)
}
}
impl<S: Simd> From<mask16x8<S>> for __m128i {
#[inline(always)]
fn from(value: mask16x8<S>) -> Self {
let lanes: [i16; 8usize] = value.into();
crate::transmute::checked_transmute_copy(&lanes)
}
}
impl<S: Simd> SimdFrom<__m128i, S> for i32x4<S> {
#[inline(always)]
fn simd_from(simd: S, arch: __m128i) -> Self {
Self {
val: crate::transmute::checked_transmute_copy(&arch),
simd,
}
}
}
impl<S: Simd> From<i32x4<S>> for __m128i {
#[inline(always)]
fn from(value: i32x4<S>) -> Self {
crate::transmute::checked_transmute_copy(&value.val)
}
}
impl<S: Simd> SimdFrom<__m128i, S> for u32x4<S> {
#[inline(always)]
fn simd_from(simd: S, arch: __m128i) -> Self {
Self {
val: crate::transmute::checked_transmute_copy(&arch),
simd,
}
}
}
impl<S: Simd> From<u32x4<S>> for __m128i {
#[inline(always)]
fn from(value: u32x4<S>) -> Self {
crate::transmute::checked_transmute_copy(&value.val)
}
}
impl<S: Simd> SimdFrom<__m128i, S> for mask32x4<S> {
#[inline(always)]
fn simd_from(simd: S, arch: __m128i) -> Self {
let lanes: [i32; 4usize] = crate::transmute::checked_transmute_copy(&arch);
lanes.simd_into(simd)
}
}
impl<S: Simd> From<mask32x4<S>> for __m128i {
#[inline(always)]
fn from(value: mask32x4<S>) -> Self {
let lanes: [i32; 4usize] = value.into();
crate::transmute::checked_transmute_copy(&lanes)
}
}
impl<S: Simd> SimdFrom<__m128d, S> for f64x2<S> {
#[inline(always)]
fn simd_from(simd: S, arch: __m128d) -> Self {
Self {
val: crate::transmute::checked_transmute_copy(&arch),
simd,
}
}
}
impl<S: Simd> From<f64x2<S>> for __m128d {
#[inline(always)]
fn from(value: f64x2<S>) -> Self {
crate::transmute::checked_transmute_copy(&value.val)
}
}
impl<S: Simd> SimdFrom<__m128i, S> for i64x2<S> {
#[inline(always)]
fn simd_from(simd: S, arch: __m128i) -> Self {
Self {
val: crate::transmute::checked_transmute_copy(&arch),
simd,
}
}
}
impl<S: Simd> From<i64x2<S>> for __m128i {
#[inline(always)]
fn from(value: i64x2<S>) -> Self {
crate::transmute::checked_transmute_copy(&value.val)
}
}
impl<S: Simd> SimdFrom<__m128i, S> for u64x2<S> {
#[inline(always)]
fn simd_from(simd: S, arch: __m128i) -> Self {
Self {
val: crate::transmute::checked_transmute_copy(&arch),
simd,
}
}
}
impl<S: Simd> From<u64x2<S>> for __m128i {
#[inline(always)]
fn from(value: u64x2<S>) -> Self {
crate::transmute::checked_transmute_copy(&value.val)
}
}
impl<S: Simd> SimdFrom<__m128i, S> for mask64x2<S> {
#[inline(always)]
fn simd_from(simd: S, arch: __m128i) -> Self {
let lanes: [i64; 2usize] = crate::transmute::checked_transmute_copy(&arch);
lanes.simd_into(simd)
}
}
impl<S: Simd> From<mask64x2<S>> for __m128i {
#[inline(always)]
fn from(value: mask64x2<S>) -> Self {
let lanes: [i64; 2usize] = value.into();
crate::transmute::checked_transmute_copy(&lanes)
}
}
crate::kernel!(
#[doc = r" This is a version of the `alignr` intrinsic that takes a non-const shift argument. The shift is still"]
#[doc = r" expected to be constant in practice, so the match statement will be optimized out. This exists because"]
#[doc = r" Rust doesn't currently let you do math on const generics."]
#[inline(always)]
fn dyn_alignr_128(token: Sse2, a: __m128i, b: __m128i, shift: usize) -> __m128i {
match shift {
0usize => {
let lo = _mm_srli_si128::<0i32>(b);
let hi = _mm_slli_si128::<16i32>(a);
_mm_or_si128(lo, hi)
}
1usize => {
let lo = _mm_srli_si128::<1i32>(b);
let hi = _mm_slli_si128::<15i32>(a);
_mm_or_si128(lo, hi)
}
2usize => {
let lo = _mm_srli_si128::<2i32>(b);
let hi = _mm_slli_si128::<14i32>(a);
_mm_or_si128(lo, hi)
}
3usize => {
let lo = _mm_srli_si128::<3i32>(b);
let hi = _mm_slli_si128::<13i32>(a);
_mm_or_si128(lo, hi)
}
4usize => {
let lo = _mm_srli_si128::<4i32>(b);
let hi = _mm_slli_si128::<12i32>(a);
_mm_or_si128(lo, hi)
}
5usize => {
let lo = _mm_srli_si128::<5i32>(b);
let hi = _mm_slli_si128::<11i32>(a);
_mm_or_si128(lo, hi)
}
6usize => {
let lo = _mm_srli_si128::<6i32>(b);
let hi = _mm_slli_si128::<10i32>(a);
_mm_or_si128(lo, hi)
}
7usize => {
let lo = _mm_srli_si128::<7i32>(b);
let hi = _mm_slli_si128::<9i32>(a);
_mm_or_si128(lo, hi)
}
8usize => {
let lo = _mm_srli_si128::<8i32>(b);
let hi = _mm_slli_si128::<8i32>(a);
_mm_or_si128(lo, hi)
}
9usize => {
let lo = _mm_srli_si128::<9i32>(b);
let hi = _mm_slli_si128::<7i32>(a);
_mm_or_si128(lo, hi)
}
10usize => {
let lo = _mm_srli_si128::<10i32>(b);
let hi = _mm_slli_si128::<6i32>(a);
_mm_or_si128(lo, hi)
}
11usize => {
let lo = _mm_srli_si128::<11i32>(b);
let hi = _mm_slli_si128::<5i32>(a);
_mm_or_si128(lo, hi)
}
12usize => {
let lo = _mm_srli_si128::<12i32>(b);
let hi = _mm_slli_si128::<4i32>(a);
_mm_or_si128(lo, hi)
}
13usize => {
let lo = _mm_srli_si128::<13i32>(b);
let hi = _mm_slli_si128::<3i32>(a);
_mm_or_si128(lo, hi)
}
14usize => {
let lo = _mm_srli_si128::<14i32>(b);
let hi = _mm_slli_si128::<2i32>(a);
_mm_or_si128(lo, hi)
}
15usize => {
let lo = _mm_srli_si128::<15i32>(b);
let hi = _mm_slli_si128::<1i32>(a);
_mm_or_si128(lo, hi)
}
_ => unreachable!(),
}
}
);
crate::kernel!(
#[doc = r" Concatenates `b` and `a` (each N blocks) and extracts N blocks starting at byte offset `shift_bytes`."]
#[doc = r" Extracts from [b : a] (b in low bytes, a in high bytes), matching `alignr` semantics."]
#[inline(always)]
fn cross_block_alignr_128x2(
token: Sse2,
a: [__m128i; 2usize],
b: [__m128i; 2usize],
shift_bytes: usize,
) -> [__m128i; 2usize] {
[
{
let [lo, hi] =
crate::support::cross_block_slide_blocks_at(&b, &a, 0usize, shift_bytes);
dyn_alignr_128(token, hi, lo, shift_bytes % 16)
},
{
let [lo, hi] =
crate::support::cross_block_slide_blocks_at(&b, &a, 1usize, shift_bytes);
dyn_alignr_128(token, hi, lo, shift_bytes % 16)
},
]
}
);
crate::kernel!(
#[doc = r" Concatenates `b` and `a` (each N blocks) and extracts N blocks starting at byte offset `shift_bytes`."]
#[doc = r" Extracts from [b : a] (b in low bytes, a in high bytes), matching `alignr` semantics."]
#[inline(always)]
fn cross_block_alignr_128x4(
token: Sse2,
a: [__m128i; 4usize],
b: [__m128i; 4usize],
shift_bytes: usize,
) -> [__m128i; 4usize] {
[
{
let [lo, hi] =
crate::support::cross_block_slide_blocks_at(&b, &a, 0usize, shift_bytes);
dyn_alignr_128(token, hi, lo, shift_bytes % 16)
},
{
let [lo, hi] =
crate::support::cross_block_slide_blocks_at(&b, &a, 1usize, shift_bytes);
dyn_alignr_128(token, hi, lo, shift_bytes % 16)
},
{
let [lo, hi] =
crate::support::cross_block_slide_blocks_at(&b, &a, 2usize, shift_bytes);
dyn_alignr_128(token, hi, lo, shift_bytes % 16)
},
{
let [lo, hi] =
crate::support::cross_block_slide_blocks_at(&b, &a, 3usize, shift_bytes);
dyn_alignr_128(token, hi, lo, shift_bytes % 16)
},
]
}
);