use super::super::{BitMask, Tag};
use core::mem;
use core::num::NonZeroU16;
use core::arch::loongarch64::*;
pub(crate) type BitMaskWord = u16;
pub(crate) type NonZeroBitMaskWord = NonZeroU16;
pub(crate) const BITMASK_STRIDE: usize = 1;
pub(crate) const BITMASK_MASK: BitMaskWord = 0xffff;
pub(crate) const BITMASK_ITER_MASK: BitMaskWord = !0;
#[derive(Copy, Clone)]
pub(crate) struct Group(m128i);
#[allow(clippy::use_self)]
impl Group {
pub(crate) const WIDTH: usize = mem::size_of::<Self>();
#[inline]
#[allow(clippy::items_after_statements)]
pub(crate) const fn static_empty() -> &'static [Tag; Group::WIDTH] {
#[repr(C)]
struct AlignedTags {
_align: [Group; 0],
tags: [Tag; Group::WIDTH],
}
const ALIGNED_TAGS: AlignedTags = AlignedTags {
_align: [],
tags: [Tag::EMPTY; Group::WIDTH],
};
&ALIGNED_TAGS.tags
}
#[inline]
#[allow(clippy::cast_ptr_alignment)] pub(crate) unsafe fn load(ptr: *const Tag) -> Self {
Group(lsx_vld::<0>(ptr.cast()))
}
#[inline]
#[allow(clippy::cast_ptr_alignment)]
pub(crate) unsafe fn load_aligned(ptr: *const Tag) -> Self {
debug_assert_eq!(ptr.align_offset(mem::align_of::<Self>()), 0);
Group(lsx_vld::<0>(ptr.cast()))
}
#[inline]
#[allow(clippy::cast_ptr_alignment)]
pub(crate) unsafe fn store_aligned(self, ptr: *mut Tag) {
debug_assert_eq!(ptr.align_offset(mem::align_of::<Self>()), 0);
lsx_vst::<0>(self.0, ptr.cast());
}
#[inline]
pub(crate) fn match_tag(self, tag: Tag) -> BitMask {
unsafe {
let cmp = lsx_vseq_b(self.0, lsx_vreplgr2vr_b(tag.0 as i32));
BitMask(lsx_vpickve2gr_hu::<0>(lsx_vmskltz_b(cmp)) as u16)
}
}
#[inline]
pub(crate) fn match_empty(self) -> BitMask {
unsafe {
let cmp = lsx_vseqi_b::<{ Tag::EMPTY.0 as i8 as i32 }>(self.0);
BitMask(lsx_vpickve2gr_hu::<0>(lsx_vmskltz_b(cmp)) as u16)
}
}
#[inline]
pub(crate) fn match_empty_or_deleted(self) -> BitMask {
unsafe {
BitMask(lsx_vpickve2gr_hu::<0>(lsx_vmskltz_b(self.0)) as u16)
}
}
#[inline]
pub(crate) fn match_full(&self) -> BitMask {
unsafe {
BitMask(lsx_vpickve2gr_hu::<0>(lsx_vmskgez_b(self.0)) as u16)
}
}
#[inline]
pub(crate) fn convert_special_to_empty_and_full_to_deleted(self) -> Self {
unsafe {
let zero = lsx_vreplgr2vr_b(0);
let special = lsx_vslt_b(self.0, zero);
Group(lsx_vor_v(special, lsx_vreplgr2vr_b(Tag::DELETED.0 as i32)))
}
}
}