#![allow(unsafe_code)]
#[cfg(target_arch = "aarch64")]
#[inline(always)]
pub(crate) unsafe fn prefetch_read_l1(ptr: *const u8) {
unsafe {
core::arch::asm!(
"prfm pldl1keep, [{ptr}]",
ptr = in(reg) ptr,
options(nostack, preserves_flags)
);
}
}
#[cfg(all(test, target_arch = "aarch64"))]
mod tests {
use super::*;
#[test]
#[cfg_attr(miri, ignore)] fn prefetch_does_not_crash_on_null() {
unsafe {
prefetch_read_l1(core::ptr::null());
}
}
#[test]
#[cfg_attr(miri, ignore)] fn prefetch_does_not_crash_on_unaligned() {
let data = [0u8; 256];
unsafe {
prefetch_read_l1(data.as_ptr().add(1));
prefetch_read_l1(data.as_ptr().add(7));
prefetch_read_l1(data.as_ptr().add(63));
}
}
#[test]
#[cfg_attr(miri, ignore)] fn prefetch_does_not_crash_on_out_of_bounds() {
let data = [0u8; 64];
unsafe {
prefetch_read_l1(data.as_ptr().wrapping_add(8192));
}
}
}