#[derive(Clone, Copy)]
pub(crate) struct U32x4(
pub(crate) u32,
pub(crate) u32,
pub(crate) u32,
pub(crate) u32,
);
impl core::ops::BitXor for U32x4 {
type Output = Self;
fn bitxor(self, _rhs: Self) -> Self::Output {
Self(
self.0 ^ _rhs.0,
self.1 ^ _rhs.1,
self.2 ^ _rhs.2,
self.3 ^ _rhs.3,
)
}
}
#[cfg(feature = "zeroize")]
impl zeroize::Zeroize for U32x4 {
fn zeroize(&mut self) {
self.0.zeroize();
self.1.zeroize();
self.2.zeroize();
self.3.zeroize();
}
}
impl U32x4 {
#[must_use]
pub(crate) const fn wrapping_add(self, _rhs: Self) -> Self {
Self(
self.0.wrapping_add(_rhs.0),
self.1.wrapping_add(_rhs.1),
self.2.wrapping_add(_rhs.2),
self.3.wrapping_add(_rhs.3),
)
}
#[must_use]
pub(crate) const fn shl_1(self) -> Self {
Self(self.1, self.2, self.3, self.0)
}
#[must_use]
pub(crate) const fn shl_2(self) -> Self {
Self(self.2, self.3, self.0, self.1)
}
#[must_use]
pub(crate) const fn shl_3(self) -> Self {
Self(self.3, self.0, self.1, self.2)
}
#[must_use]
pub(crate) const fn rotate_left(self, n: u32) -> Self {
Self(
self.0.rotate_left(n),
self.1.rotate_left(n),
self.2.rotate_left(n),
self.3.rotate_left(n),
)
}
pub(crate) fn store_into_le(&self, slice_in: &mut [u8]) {
debug_assert_eq!(slice_in.len(), size_of::<u32>() * 4);
let mut iter = slice_in.chunks_exact_mut(size_of::<u32>());
iter.next().unwrap().copy_from_slice(&self.0.to_le_bytes());
iter.next().unwrap().copy_from_slice(&self.1.to_le_bytes());
iter.next().unwrap().copy_from_slice(&self.2.to_le_bytes());
iter.next().unwrap().copy_from_slice(&self.3.to_le_bytes());
}
}