vpp_plugin/vppinfra/cache.rs
1//! Cache utilities and definitions
2//!
3//! This module provides functions for prefetching memory locations into CPU caches.
4
5/// Prefetches a memory location into L1 cache for reading
6// Instead of std::intrinsics::prefetch_read_data which is nightly-only
7#[inline(always)]
8pub fn prefetch_load<T>(p: *const T) {
9 // Suppress unused variable warning on other platforms
10 let _ = p;
11
12 #[cfg(target_arch = "x86_64")]
13 // SAFETY: it's not clear why this is marked as unsafe, as prefetching a pointer
14 // doesn't dereference it or read from it.
15 unsafe {
16 std::arch::x86_64::_mm_prefetch::<{ std::arch::x86_64::_MM_HINT_T0 }>(p as *const i8);
17 }
18}
19
20/// Prefetches a memory location into L1 cache for writing
21// Instead of std::intrinsics::prefetch_write_data which is nightly-only
22#[inline(always)]
23pub fn prefetch_store<T>(p: *const T) {
24 // Suppress unused variable warning on other platforms
25 let _ = p;
26
27 #[cfg(target_arch = "x86_64")]
28 // SAFETY: it's not clear why this is marked as unsafe, as prefetching a pointer
29 // doesn't dereference it or write to it.
30 unsafe {
31 std::arch::x86_64::_mm_prefetch::<{ std::arch::x86_64::_MM_HINT_ET0 }>(p as *const i8);
32 }
33}