#[inline(always)]
pub(crate) fn load_u32_le(data: &[u8], off: usize) -> u32 {
#[cfg(feature = "unchecked")]
{
debug_assert!(off + 4 <= data.len());
unsafe { u32::from_le_bytes(*(data.as_ptr().add(off) as *const [u8; 4])) }
}
#[cfg(not(feature = "unchecked"))]
{
u32::from_le_bytes(data[off..off + 4].try_into().unwrap())
}
}
#[inline(always)]
pub(crate) fn load_u64_le(data: &[u8], off: usize) -> u64 {
#[cfg(feature = "unchecked")]
{
debug_assert!(off + 8 <= data.len());
unsafe { u64::from_le_bytes(*(data.as_ptr().add(off) as *const [u8; 8])) }
}
#[cfg(not(feature = "unchecked"))]
{
u64::from_le_bytes(data[off..off + 8].try_into().unwrap())
}
}
#[inline(always)]
pub(crate) fn store_u64_le(data: &mut [u8], off: usize, val: u64) {
#[cfg(feature = "unchecked")]
{
debug_assert!(off + 8 <= data.len());
unsafe {
*(data.as_mut_ptr().add(off) as *mut [u8; 8]) = val.to_le_bytes();
}
}
#[cfg(not(feature = "unchecked"))]
{
data[off..off + 8].copy_from_slice(&val.to_le_bytes());
}
}
#[inline(always)]
pub(crate) fn get_byte(data: &[u8], idx: usize) -> u8 {
#[cfg(feature = "unchecked")]
{
debug_assert!(idx < data.len());
unsafe { *data.get_unchecked(idx) }
}
#[cfg(not(feature = "unchecked"))]
{
data[idx]
}
}
#[cfg(feature = "unchecked")]
#[inline(always)]
pub(crate) unsafe fn load_u32_le_ptr(ptr: *const u8, off: usize) -> u32 {
unsafe { u32::from_le_bytes(*(ptr.add(off) as *const [u8; 4])) }
}
#[cfg(all(feature = "unchecked", target_arch = "x86_64"))]
#[inline(always)]
pub(crate) unsafe fn prefetch_ptr(ptr: *const u8) {
unsafe {
core::arch::x86_64::_mm_prefetch::<{ core::arch::x86_64::_MM_HINT_T0 }>(ptr as *const i8);
}
}
#[cfg(all(feature = "unchecked", not(target_arch = "x86_64")))]
#[inline(always)]
pub(crate) unsafe fn prefetch_ptr(_ptr: *const u8) {}
#[inline(always)]
pub(crate) fn prefetch<T>(_r: &T) {
#[cfg(all(feature = "unchecked", target_arch = "x86_64"))]
{
unsafe {
core::arch::x86_64::_mm_prefetch::<{ core::arch::x86_64::_MM_HINT_T0 }>(
(_r as *const T) as *const i8,
);
}
}
}