Skip to content

Commit e62cf3d

Browse files
committed
Remove final cfg gating where preloading can also benefit from CPU prefetching
1 parent ade110b commit e62cf3d

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

sa-index/src/array/mod.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,30 @@ impl SuffixArray {
8585
}
8686

8787
/// Issues a non-blocking hardware prefetch hint for the cache line holding SA entry `index`.
88-
#[cfg(feature = "mmap")]
8988
#[inline]
9089
pub fn prefetch_sa_index(&self, index: usize) {
91-
if let SuffixArray::MmapBacked { mmap, data_offset, bits_per_value, .. } = self {
92-
let byte_offset = data_offset + (index * bits_per_value) / 8;
93-
if byte_offset < mmap.len() {
94-
let ptr: *const u8 = &mmap[byte_offset];
95-
prefetch::prefetch_read(ptr);
90+
match self {
91+
SuffixArray::Original(sa, _) => {
92+
if index < sa.len() {
93+
prefetch::prefetch_read(unsafe { sa.as_ptr().add(index) as *const u8 });
94+
}
95+
}
96+
SuffixArray::Compressed(ba, _) => {
97+
let bpv = ba.bits_per_value();
98+
let word_idx = (index * bpv) / 64;
99+
let total_words = (ba.len() * bpv + 63) / 64;
100+
if word_idx < total_words {
101+
let ptr = ba.get_data_slice(word_idx, word_idx + 1).as_ptr() as *const u8;
102+
prefetch::prefetch_read(ptr);
103+
}
104+
}
105+
#[cfg(feature = "mmap")]
106+
SuffixArray::MmapBacked { mmap, data_offset, bits_per_value, .. } => {
107+
let byte_offset = data_offset + (index * bits_per_value) / 8;
108+
if byte_offset < mmap.len() {
109+
let ptr: *const u8 = &mmap[byte_offset];
110+
prefetch::prefetch_read(ptr);
111+
}
96112
}
97113
}
98114
}

sa-index/src/sa_searcher.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,11 +597,8 @@ impl Searcher {
597597
/// call. One fetch will be wasted; both are free (single non-blocking CPU instruction).
598598
/// From iteration 2 onward the needed SA entry is already in L1/L2 cache.
599599
#[inline]
600-
#[cfg_attr(not(feature = "mmap"), allow(unused_variables))]
601600
fn prefetch_binary_search_pivots(&self, lo: usize, center: usize, hi: usize) {
602-
#[cfg(feature = "mmap")]
603601
self.sa.prefetch_sa_index((lo + center) / 2);
604-
#[cfg(feature = "mmap")]
605602
self.sa.prefetch_sa_index((center + hi) / 2);
606603
}
607604

0 commit comments

Comments
 (0)