use core::ops::{Add, Mul, Neg, Sub};
use zvidlib_core::simd::vector::I32x;
#[derive(Clone, Copy)]
pub(crate) struct W<V>(pub(crate) V);
impl<V: I32x> W<V> {
#[inline(always)]
pub(crate) unsafe fn zero() -> Self {
unsafe { Self(V::zero()) }
}
#[inline(always)]
pub(crate) fn t16(self) -> Self {
unsafe { Self(self.0.sll::<16>().sra::<16>()) }
}
}
impl<V: I32x> Add for W<V> {
type Output = Self;
#[inline(always)]
fn add(self, other: Self) -> Self {
unsafe { Self(self.0.add(other.0)) }
}
}
impl<V: I32x> Sub for W<V> {
type Output = Self;
#[inline(always)]
fn sub(self, other: Self) -> Self {
unsafe { Self(self.0.sub(other.0)) }
}
}
impl<V: I32x> Neg for W<V> {
type Output = Self;
#[inline(always)]
fn neg(self) -> Self {
unsafe { Self(V::zero().sub(self.0)) }
}
}
impl<V: I32x> Mul<i64> for W<V> {
type Output = Self;
#[inline(always)]
fn mul(self, constant: i64) -> Self {
unsafe { Self(self.0.mul(V::splat(constant as i32))) }
}
}
impl<V: I32x> Mul<W<V>> for i64 {
type Output = W<V>;
#[inline(always)]
fn mul(self, vector: W<V>) -> W<V> {
vector * self
}
}
#[inline(always)]
pub(crate) fn wraplow<V: I32x>(x: W<V>) -> W<V> {
x
}
#[inline(always)]
pub(crate) fn wrap32<V: I32x>(x: W<V>) -> W<V> {
x
}
#[inline(always)]
pub(crate) fn round_shift<V: I32x>(x: W<V>) -> W<V> {
unsafe { W(x.0.add(V::splat(1 << 13)).sra::<14>()) }
}