diff --git a/encodings/fastlanes/src/bitpacking/compute/search_sorted.rs b/encodings/fastlanes/src/bitpacking/compute/search_sorted.rs index 3f72cc273c..85b7dd3daf 100644 --- a/encodings/fastlanes/src/bitpacking/compute/search_sorted.rs +++ b/encodings/fastlanes/src/bitpacking/compute/search_sorted.rs @@ -16,11 +16,10 @@ use crate::{unpack_single_primitive, BitPackedArray}; impl SearchSortedFn for BitPackedArray { fn search_sorted(&self, value: &Scalar, side: SearchSortedSide) -> VortexResult { - let ptype = self.ptype(); - match_each_unsigned_integer_ptype!(ptype, |$P| { + match_each_unsigned_integer_ptype!(self.ptype(), |$P| { let unwrapped_value: $P = value.cast(self.dtype())?.try_into().unwrap(); - if let Some(patches_array) = self.patches() { - if (unwrapped_value.leading_zeros() as usize) < ptype.bit_width() - self.bit_width() { + if let Some(patches_array) = self.patches() { + if unwrapped_value as usize >= self.max_packed_value() { search_sorted(&patches_array, value.clone(), side) } else { Ok(SearchSorted::search_sorted(&BitPackedSearch::new(self), &unwrapped_value, side)) diff --git a/encodings/fastlanes/src/bitpacking/mod.rs b/encodings/fastlanes/src/bitpacking/mod.rs index b76927c46d..5bcee29017 100644 --- a/encodings/fastlanes/src/bitpacking/mod.rs +++ b/encodings/fastlanes/src/bitpacking/mod.rs @@ -127,6 +127,11 @@ impl BitPackedArray { pub fn ptype(&self) -> PType { self.dtype().try_into().unwrap() } + + #[inline] + pub fn max_packed_value(&self) -> usize { + 1 << self.bit_width() + } } impl IntoCanonical for BitPackedArray {