Skip to content

Commit

Permalink
Uses static target detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Tpt committed Feb 2, 2023
1 parent f8df837 commit 28ed988
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,22 +235,14 @@ impl IndexTable {
Ok(try_io!(Ok(&map[offset..offset + CHUNK_LEN])))
}

#[cfg(target_feature = "sse2")]
fn find_entry(&self, key_prefix: u64, sub_index: usize, chunk: &[u8]) -> (Entry, usize) {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
if is_x86_feature_detected!("sse2") {
return self.find_entry_sse2(key_prefix, sub_index, chunk)
}
self.find_entry_regular(key_prefix, sub_index, chunk)
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn find_entry_sse2(&self, key_prefix: u64, sub_index: usize, chunk: &[u8]) -> (Entry, usize) {
assert!(chunk.len() >= CHUNK_ENTRIES * 8); // Bound checking (not done by SIMD instructions)
debug_assert!(
Entry::address_bits(self.id.index_bits()) <= 32,
"To be sure we can use all high 32 bits as key prefix"
);
debug_assert_eq!(
const _: () = assert_eq!(
CHUNK_ENTRIES % 4,
0,
"We assume here we got buffer with a number of elements that is a multiple of 4"
Expand Down Expand Up @@ -283,12 +275,8 @@ impl IndexTable {
(Entry::empty(), 0)
}

fn find_entry_regular(
&self,
key_prefix: u64,
sub_index: usize,
chunk: &[u8],
) -> (Entry, usize) {
#[cfg(not(target_feature = "sse2"))]
fn find_entry(&self, key_prefix: u64, sub_index: usize, chunk: &[u8]) -> (Entry, usize) {
assert!(chunk.len() >= CHUNK_ENTRIES * 8);
let partial_key = Entry::extract_key(key_prefix, self.id.index_bits());
for i in sub_index..CHUNK_ENTRIES {
Expand Down

0 comments on commit 28ed988

Please sign in to comment.